2013-10-31 18:54:14 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#ifndef GFX_MACIOSURFACEIMAGE_H
|
|
|
|
#define GFX_MACIOSURFACEIMAGE_H
|
|
|
|
|
2013-10-31 18:54:14 -07:00
|
|
|
#include "ImageContainer.h"
|
2013-10-31 18:54:14 -07:00
|
|
|
#include "mozilla/gfx/MacIOSurface.h"
|
2013-12-13 09:32:02 -08:00
|
|
|
#include "mozilla/gfx/Point.h"
|
2013-10-31 18:54:14 -07:00
|
|
|
#include "mozilla/layers/TextureClient.h"
|
2013-10-31 18:54:14 -07:00
|
|
|
#include "gfxImageSurface.h"
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
|
|
|
namespace layers {
|
|
|
|
|
2013-10-31 18:54:14 -07:00
|
|
|
class MacIOSurfaceImage : public Image,
|
|
|
|
public ISharedImage {
|
2013-10-31 18:54:14 -07:00
|
|
|
public:
|
|
|
|
void SetSurface(MacIOSurface* aSurface) { mSurface = aSurface; }
|
|
|
|
MacIOSurface* GetSurface() { return mSurface; }
|
|
|
|
|
2013-12-13 09:32:02 -08:00
|
|
|
gfx::IntSize GetSize() {
|
2013-12-20 08:46:29 -08:00
|
|
|
return gfx::IntSize(mSurface->GetDevicePixelWidth(), mSurface->GetDevicePixelHeight());
|
2013-10-31 18:54:14 -07:00
|
|
|
}
|
|
|
|
|
2013-10-31 18:54:14 -07:00
|
|
|
virtual ISharedImage* AsSharedImage() MOZ_OVERRIDE { return this; }
|
|
|
|
|
2014-01-15 07:06:43 -08:00
|
|
|
virtual already_AddRefed<gfxASurface> DeprecatedGetAsSurface() {
|
2013-10-31 18:54:14 -07:00
|
|
|
mSurface->Lock();
|
|
|
|
size_t bytesPerRow = mSurface->GetBytesPerRow();
|
|
|
|
size_t ioWidth = mSurface->GetDevicePixelWidth();
|
|
|
|
size_t ioHeight = mSurface->GetDevicePixelHeight();
|
|
|
|
|
|
|
|
unsigned char* ioData = (unsigned char*)mSurface->GetBaseAddress();
|
|
|
|
|
|
|
|
nsRefPtr<gfxImageSurface> imgSurface =
|
2014-01-23 10:26:40 -08:00
|
|
|
new gfxImageSurface(gfxIntSize(ioWidth, ioHeight), gfxImageFormat::ARGB32);
|
2013-10-31 18:54:14 -07:00
|
|
|
|
|
|
|
for (size_t i = 0; i < ioHeight; i++) {
|
|
|
|
memcpy(imgSurface->Data() + i * imgSurface->Stride(),
|
|
|
|
ioData + i * bytesPerRow, ioWidth * 4);
|
|
|
|
}
|
|
|
|
|
|
|
|
mSurface->Unlock();
|
|
|
|
|
|
|
|
return imgSurface.forget();
|
|
|
|
}
|
|
|
|
|
2014-01-27 05:25:50 -08:00
|
|
|
virtual TemporaryRef<gfx::SourceSurface> GetAsSourceSurface();
|
|
|
|
|
2013-10-31 18:54:14 -07:00
|
|
|
virtual TextureClient* GetTextureClient() MOZ_OVERRIDE;
|
|
|
|
virtual uint8_t* GetBuffer() MOZ_OVERRIDE { return nullptr; }
|
|
|
|
|
2013-10-31 18:54:14 -07:00
|
|
|
MacIOSurfaceImage() : Image(nullptr, MAC_IOSURFACE) {}
|
|
|
|
|
|
|
|
private:
|
|
|
|
RefPtr<MacIOSurface> mSurface;
|
2013-10-31 18:54:14 -07:00
|
|
|
RefPtr<TextureClient> mTextureClient;
|
2013-10-31 18:54:14 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
} // layers
|
|
|
|
} // mozilla
|
|
|
|
|
|
|
|
#endif // GFX_SHAREDTEXTUREIMAGE_H
|