From b69fad7cc7e17ea98b1283c0b3ca0188fc52616e Mon Sep 17 00:00:00 2001 From: Nicolas Silva Date: Fri, 20 Nov 2015 14:24:52 +0100 Subject: [PATCH] Bug 1200595 - AndroidSurface TextureData implementation. r=mattwoodrow --- gfx/layers/client/ImageClient.cpp | 7 +-- gfx/layers/opengl/TextureClientOGL.cpp | 69 +++++++++++--------------- gfx/layers/opengl/TextureClientOGL.h | 44 +++++++--------- 3 files changed, 50 insertions(+), 70 deletions(-) diff --git a/gfx/layers/client/ImageClient.cpp b/gfx/layers/client/ImageClient.cpp index 11a2c4c05eb..4761303743f 100644 --- a/gfx/layers/client/ImageClient.cpp +++ b/gfx/layers/client/ImageClient.cpp @@ -208,9 +208,10 @@ ImageClientSingle::UpdateImage(ImageContainer* aContainer, uint32_t aContentFlag #ifdef MOZ_WIDGET_ANDROID } else if (image->GetFormat() == ImageFormat::SURFACE_TEXTURE) { SurfaceTextureImage* typedImage = image->AsSurfaceTextureImage(); - texture = new SurfaceTextureClient(GetForwarder(), mTextureFlags, - typedImage->GetSurfaceTexture(), size, - typedImage->GetOriginPos()); + texture = AndroidSurfaceTextureData::CreateTextureClient( + typedImage->GetSurfaceTexture(), size, typedImage->GetOriginPos(), + GetForwarder(), mTextureFlags + ); #endif } else { MOZ_ASSERT(false, "Bad ImageFormat."); diff --git a/gfx/layers/opengl/TextureClientOGL.cpp b/gfx/layers/opengl/TextureClientOGL.cpp index 6c23d607edd..ebda6feb3ce 100644 --- a/gfx/layers/opengl/TextureClientOGL.cpp +++ b/gfx/layers/opengl/TextureClientOGL.cpp @@ -63,65 +63,54 @@ EGLImageTextureData::Serialize(SurfaceDescriptor& aOutDescriptor) } //////////////////////////////////////////////////////////////////////// -// SurfaceTextureClient +// AndroidSurface #ifdef MOZ_WIDGET_ANDROID -SurfaceTextureClient::SurfaceTextureClient(ISurfaceAllocator* aAllocator, - TextureFlags aFlags, - AndroidSurfaceTexture* aSurfTex, - gfx::IntSize aSize, - gl::OriginPos aOriginPos) - : TextureClient(aAllocator, aFlags) - , mSurfTex(aSurfTex) - , mSize(aSize) - , mIsLocked(false) +already_AddRefed +AndroidSurfaceTextureData::CreateTextureClient(AndroidSurfaceTexture* aSurfTex, + gfx::IntSize aSize, + gl::OriginPos aOriginPos, + ISurfaceAllocator* aAllocator, + TextureFlags aFlags) { MOZ_ASSERT(XRE_IsParentProcess(), - "Can't pass pointers between processes."); + "Can't pass an android surfaces between processes."); - // Our data is always owned externally. - AddFlags(TextureFlags::DEALLOCATE_CLIENT); + if (!aSurfTex || !XRE_IsParentProcess()) { + return nullptr; + } + + // XXX - This is quite sad and slow. + aFlags |= TextureFlags::DEALLOCATE_CLIENT; if (aOriginPos == gl::OriginPos::BottomLeft) { - AddFlags(TextureFlags::ORIGIN_BOTTOM_LEFT); + aFlags |= TextureFlags::ORIGIN_BOTTOM_LEFT; } + + return TextureClient::CreateWithData( + new AndroidSurfaceTextureData(aSurfTex, aSize), + aFlags, aAllocator + ); } -SurfaceTextureClient::~SurfaceTextureClient() -{ - // Our data is always owned externally. -} +AndroidSurfaceTextureData::AndroidSurfaceTextureData(AndroidSurfaceTexture* aSurfTex, + gfx::IntSize aSize) + : mSurfTex(aSurfTex) + , mSize(aSize) +{} + +AndroidSurfaceTextureData::~AndroidSurfaceTextureData() +{} bool -SurfaceTextureClient::ToSurfaceDescriptor(SurfaceDescriptor& aOutDescriptor) +AndroidSurfaceTextureData::Serialize(SurfaceDescriptor& aOutDescriptor) { - MOZ_ASSERT(IsValid()); - MOZ_ASSERT(IsAllocated()); - aOutDescriptor = SurfaceTextureDescriptor((uintptr_t)mSurfTex.get(), mSize); return true; } -bool -SurfaceTextureClient::Lock(OpenMode mode) -{ - MOZ_ASSERT(!mIsLocked); - if (!IsValid() || !IsAllocated()) { - return false; - } - mIsLocked = true; - return true; -} - -void -SurfaceTextureClient::Unlock() -{ - MOZ_ASSERT(mIsLocked); - mIsLocked = false; -} - #endif // MOZ_WIDGET_ANDROID } // namespace layers diff --git a/gfx/layers/opengl/TextureClientOGL.h b/gfx/layers/opengl/TextureClientOGL.h index 0fb492ab7a3..002eb418aeb 100644 --- a/gfx/layers/opengl/TextureClientOGL.h +++ b/gfx/layers/opengl/TextureClientOGL.h @@ -57,53 +57,43 @@ protected: #ifdef MOZ_WIDGET_ANDROID -class SurfaceTextureClient : public TextureClient +class AndroidSurfaceTextureData : public TextureData { public: - SurfaceTextureClient(ISurfaceAllocator* aAllocator, - TextureFlags aFlags, - gl::AndroidSurfaceTexture* aSurfTex, - gfx::IntSize aSize, - gl::OriginPos aOriginPos); + static already_AddRefed + CreateTextureClient(gl::AndroidSurfaceTexture* aSurfTex, + gfx::IntSize aSize, + gl::OriginPos aOriginPos, + ISurfaceAllocator* aAllocator, + TextureFlags aFlags); - ~SurfaceTextureClient(); - - virtual bool IsAllocated() const override { return true; } + ~AndroidSurfaceTextureData(); virtual bool HasInternalBuffer() const override { return false; } - virtual gfx::IntSize GetSize() const { return mSize; } + 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 bool Lock(OpenMode, FenceHandle*) override { return true; } - virtual void Unlock() override; - - virtual bool IsLocked() const override { return mIsLocked; } + virtual void Unlock() override {} virtual gfx::SurfaceFormat GetFormat() const override { return gfx::SurfaceFormat::UNKNOWN; } - virtual already_AddRefed - CreateSimilar(TextureFlags aFlags = TextureFlags::DEFAULT, - TextureAllocationFlags aAllocFlags = ALLOC_DEFAULT) const override - { - return nullptr; - } - - virtual bool AllocateForSurface(gfx::IntSize aSize, TextureAllocationFlags aFlags) override - { - return false; - } + // Our data is always owned externally. + virtual void Deallocate(ISurfaceAllocator*) override {} protected: + AndroidSurfaceTextureData(gl::AndroidSurfaceTexture* aSurfTex, + gfx::IntSize aSize); + const RefPtr mSurfTex; const gfx::IntSize mSize; - bool mIsLocked; }; #endif // MOZ_WIDGET_ANDROID