Bug 1200595 - EGLImage TextureData implementation. r=mattwoodrow

This commit is contained in:
Nicolas Silva 2015-11-20 14:24:49 +01:00
parent 28748f8e2d
commit 0bb3cc2e42
3 changed files with 39 additions and 61 deletions

View File

@ -203,10 +203,8 @@ ImageClientSingle::UpdateImage(ImageContainer* aContainer, uint32_t aContentFlag
if (image->GetFormat() == ImageFormat::EGLIMAGE) {
EGLImageImage* typedImage = image->AsEGLImageImage();
texture = new EGLImageTextureClient(GetForwarder(),
mTextureFlags,
typedImage,
size);
texture = EGLImageTextureData::CreateTextureClient(
typedImage, size, GetForwarder(), mTextureFlags);
#ifdef MOZ_WIDGET_ANDROID
} else if (image->GetFormat() == ImageFormat::SURFACE_TEXTURE) {
SurfaceTextureImage* typedImage = image->AsSurfaceTextureImage();

View File

@ -18,33 +18,42 @@ namespace layers {
class CompositableForwarder;
////////////////////////////////////////////////////////////////////////
// EGLImageTextureClient
// EGLImage
EGLImageTextureClient::EGLImageTextureClient(ISurfaceAllocator* aAllocator,
TextureFlags aFlags,
EGLImageImage* aImage,
gfx::IntSize aSize)
: TextureClient(aAllocator, aFlags)
, mImage(aImage)
, mSize(aSize)
, mIsLocked(false)
EGLImageTextureData::EGLImageTextureData(EGLImageImage* aImage, gfx::IntSize aSize)
: mImage(aImage)
, mSize(aSize)
{
MOZ_ASSERT(aImage);
}
already_AddRefed<TextureClient>
EGLImageTextureData::CreateTextureClient(EGLImageImage* aImage, gfx::IntSize aSize,
ISurfaceAllocator* aAllocator, TextureFlags aFlags)
{
MOZ_ASSERT(XRE_IsParentProcess(),
"Can't pass an `EGLImage` between processes.");
AddFlags(TextureFlags::DEALLOCATE_CLIENT);
if (!aImage || !XRE_IsParentProcess()) {
return nullptr;
}
// XXX - This is quite sad and slow.
aFlags |= TextureFlags::DEALLOCATE_CLIENT;
if (aImage->GetOriginPos() == gl::OriginPos::BottomLeft) {
AddFlags(TextureFlags::ORIGIN_BOTTOM_LEFT);
aFlags |= TextureFlags::ORIGIN_BOTTOM_LEFT;
}
return TextureClient::CreateWithData(
new EGLImageTextureData(aImage, aSize),
aFlags, aAllocator
);
}
bool
EGLImageTextureClient::ToSurfaceDescriptor(SurfaceDescriptor& aOutDescriptor)
EGLImageTextureData::Serialize(SurfaceDescriptor& aOutDescriptor)
{
MOZ_ASSERT(IsValid());
MOZ_ASSERT(IsAllocated());
const bool hasAlpha = true;
aOutDescriptor =
EGLImageDescriptor((uintptr_t)mImage->GetImage(),
@ -53,24 +62,6 @@ EGLImageTextureClient::ToSurfaceDescriptor(SurfaceDescriptor& aOutDescriptor)
return true;
}
bool
EGLImageTextureClient::Lock(OpenMode mode)
{
MOZ_ASSERT(!mIsLocked);
if (!IsValid() || !IsAllocated()) {
return false;
}
mIsLocked = true;
return true;
}
void
EGLImageTextureClient::Unlock()
{
MOZ_ASSERT(mIsLocked);
mIsLocked = false;
}
////////////////////////////////////////////////////////////////////////
// SurfaceTextureClient

View File

@ -20,50 +20,39 @@ namespace mozilla {
namespace layers {
class EGLImageTextureClient : public TextureClient
class EGLImageTextureData : public TextureData
{
public:
EGLImageTextureClient(ISurfaceAllocator* aAllocator,
TextureFlags aFlags,
EGLImageImage* aImage,
gfx::IntSize aSize);
virtual bool IsAllocated() const override { return true; }
static already_AddRefed<TextureClient>
CreateTextureClient(EGLImageImage* aImage, gfx::IntSize aSize,
ISurfaceAllocator* aAllocator, TextureFlags aFlags);
virtual bool HasInternalBuffer() const override { return false; }
virtual gfx::IntSize GetSize() const override { return mSize; }
virtual bool ToSurfaceDescriptor(SurfaceDescriptor& aOutDescriptor) override;
virtual bool Serialize(SurfaceDescriptor& aOutDescriptor) override;
// Useless functions.
virtual bool Lock(OpenMode mode) override;
virtual void Deallocate(ISurfaceAllocator*) override { mImage = nullptr; }
virtual void Unlock() override;
virtual void Forget(ISurfaceAllocator*) override { mImage = nullptr; }
virtual bool IsLocked() const override { return mIsLocked; }
// Unused functions.
virtual bool Lock(OpenMode, FenceHandle*) override { return true; }
virtual void Unlock() override {}
virtual gfx::SurfaceFormat GetFormat() const override
{
return gfx::SurfaceFormat::UNKNOWN;
}
virtual already_AddRefed<TextureClient>
CreateSimilar(TextureFlags aFlags = TextureFlags::DEFAULT,
TextureAllocationFlags aAllocFlags = ALLOC_DEFAULT) const override
{
return nullptr;
}
virtual bool AllocateForSurface(gfx::IntSize aSize, TextureAllocationFlags aFlags) override
{
return false;
}
protected:
EGLImageTextureData(EGLImageImage* aImage, gfx::IntSize aSize);
RefPtr<EGLImageImage> mImage;
const gfx::IntSize mSize;
bool mIsLocked;
};
#ifdef MOZ_WIDGET_ANDROID