From 424ec279d90bfd418077d022363cb29f3e4a33a6 Mon Sep 17 00:00:00 2001 From: Nicolas Silva Date: Fri, 20 Nov 2015 14:24:46 +0100 Subject: [PATCH] Bug 1200595 - MacIOSurface TextureData implementation. r=mattwoodrow --- gfx/layers/MacIOSurfaceImage.cpp | 8 +- .../opengl/MacIOSurfaceTextureClientOGL.cpp | 81 +++++++------------ .../opengl/MacIOSurfaceTextureClientOGL.h | 47 +++++------ 3 files changed, 53 insertions(+), 83 deletions(-) diff --git a/gfx/layers/MacIOSurfaceImage.cpp b/gfx/layers/MacIOSurfaceImage.cpp index 4587e1845019..e8817f163458 100644 --- a/gfx/layers/MacIOSurfaceImage.cpp +++ b/gfx/layers/MacIOSurfaceImage.cpp @@ -18,9 +18,11 @@ TextureClient* MacIOSurfaceImage::GetTextureClient(CompositableClient* aClient) { if (!mTextureClient) { - mTextureClient = MacIOSurfaceTextureClientOGL::Create(aClient->GetForwarder(), - TextureFlags::DEFAULT, - mSurface); + mTextureClient = TextureClient::CreateWithData( + MacIOSurfaceTextureData::Create(mSurface), + TextureFlags::DEFAULT, + aClient->GetForwarder() + ); } return mTextureClient; } diff --git a/gfx/layers/opengl/MacIOSurfaceTextureClientOGL.cpp b/gfx/layers/opengl/MacIOSurfaceTextureClientOGL.cpp index fbefd06c8f65..29f01f299efe 100644 --- a/gfx/layers/opengl/MacIOSurfaceTextureClientOGL.cpp +++ b/gfx/layers/opengl/MacIOSurfaceTextureClientOGL.cpp @@ -4,71 +4,42 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "MacIOSurfaceTextureClientOGL.h" -#include "mozilla/gfx/MacIOSurface.h" +#include "mozilla/gfx/MacIOSurface.h" namespace mozilla { namespace layers { -MacIOSurfaceTextureClientOGL::MacIOSurfaceTextureClientOGL(ISurfaceAllocator* aAllcator, - TextureFlags aFlags) - : TextureClient(aAllcator, aFlags) - , mIsLocked(false) -{} - -MacIOSurfaceTextureClientOGL::~MacIOSurfaceTextureClientOGL() +MacIOSurfaceTextureData::MacIOSurfaceTextureData(MacIOSurface* aSurface) +: mSurface(aSurface) { + MOZ_ASSERT(mSurface); } +MacIOSurfaceTextureData::~MacIOSurfaceTextureData() +{} + void -MacIOSurfaceTextureClientOGL::FinalizeOnIPDLThread() +MacIOSurfaceTextureData::FinalizeOnIPDLThread(TextureClient* aWrapper) { - if (mActor && mSurface) { - KeepUntilFullDeallocation(MakeUnique>(mSurface)); + if (mSurface) { + aWrapper->KeepUntilFullDeallocation(MakeUnique>(mSurface)); } } // static -already_AddRefed -MacIOSurfaceTextureClientOGL::Create(ISurfaceAllocator* aAllocator, - TextureFlags aFlags, - MacIOSurface* aSurface) +MacIOSurfaceTextureData* +MacIOSurfaceTextureData::Create(MacIOSurface* aSurface) { - RefPtr texture = - new MacIOSurfaceTextureClientOGL(aAllocator, aFlags); - MOZ_ASSERT(texture->IsValid()); - MOZ_ASSERT(!texture->IsAllocated()); - texture->mSurface = aSurface; - return texture.forget(); -} - -bool -MacIOSurfaceTextureClientOGL::Lock(OpenMode aMode) -{ - MOZ_ASSERT(!mIsLocked); - mIsLocked = true; - return IsValid() && IsAllocated(); -} - -void -MacIOSurfaceTextureClientOGL::Unlock() -{ - MOZ_ASSERT(mIsLocked); - mIsLocked = false; -} - -bool -MacIOSurfaceTextureClientOGL::IsLocked() const -{ - return mIsLocked; -} - -bool -MacIOSurfaceTextureClientOGL::ToSurfaceDescriptor(SurfaceDescriptor& aOutDescriptor) -{ - MOZ_ASSERT(IsValid()); - if (!IsAllocated()) { - return false; + MOZ_ASSERT(aSurface); + if (!aSurface) { + return nullptr; } + return new MacIOSurfaceTextureData(aSurface); +} + +bool +MacIOSurfaceTextureData::Serialize(SurfaceDescriptor& aOutDescriptor) +{ aOutDescriptor = SurfaceDescriptorMacIOSurface(mSurface->GetIOSurfaceID(), mSurface->GetContentsScaleFactor(), !mSurface->HasAlpha()); @@ -76,13 +47,19 @@ MacIOSurfaceTextureClientOGL::ToSurfaceDescriptor(SurfaceDescriptor& aOutDescrip } gfx::IntSize -MacIOSurfaceTextureClientOGL::GetSize() const +MacIOSurfaceTextureData::GetSize() const { return gfx::IntSize(mSurface->GetDevicePixelWidth(), mSurface->GetDevicePixelHeight()); } +gfx::SurfaceFormat +MacIOSurfaceTextureData::GetFormat() const +{ + return mSurface->GetFormat(); +} + already_AddRefed -MacIOSurfaceTextureClientOGL::GetAsSurface() +MacIOSurfaceTextureData::GetAsSurface() { RefPtr surf = mSurface->GetAsSurface(); return surf->GetDataSurface(); diff --git a/gfx/layers/opengl/MacIOSurfaceTextureClientOGL.h b/gfx/layers/opengl/MacIOSurfaceTextureClientOGL.h index 7548beeafdc7..cc6fec4d700d 100644 --- a/gfx/layers/opengl/MacIOSurfaceTextureClientOGL.h +++ b/gfx/layers/opengl/MacIOSurfaceTextureClientOGL.h @@ -13,47 +13,38 @@ class MacIOSurface; namespace mozilla { namespace layers { -class MacIOSurfaceTextureClientOGL : public TextureClient +class MacIOSurfaceTextureData : public TextureData { public: - explicit MacIOSurfaceTextureClientOGL(ISurfaceAllocator* aAllcator, - TextureFlags aFlags); + static MacIOSurfaceTextureData* Create(MacIOSurface* aSurface); - virtual ~MacIOSurfaceTextureClientOGL(); - - // Creates a TextureClient and init width. - static already_AddRefed - Create(ISurfaceAllocator* aAllocator, - TextureFlags aFlags, - MacIOSurface* aSurface); - - virtual bool Lock(OpenMode aMode) override; - - virtual void Unlock() override; - - virtual bool IsLocked() const override; - - virtual bool IsAllocated() const override { return !!mSurface; } - - virtual bool ToSurfaceDescriptor(SurfaceDescriptor& aOutDescriptor) override; + ~MacIOSurfaceTextureData(); virtual gfx::IntSize GetSize() const override; + virtual gfx::SurfaceFormat GetFormat() const override; + + virtual bool Lock(OpenMode, FenceHandle*) override { return true; } + + virtual void Unlock() override {} + + virtual bool Serialize(SurfaceDescriptor& aOutDescriptor) override; + virtual bool HasInternalBuffer() const override { return false; } - virtual already_AddRefed GetAsSurface() override; + virtual void Deallocate(ISurfaceAllocator* aAllocator) override { mSurface = nullptr; } - // This TextureClient should not be used in a context where we use CreateSimilar - // (ex. component alpha) because the underlying texture data is always created by - // an external producer. - virtual already_AddRefed - CreateSimilar(TextureFlags, TextureAllocationFlags) const override { return nullptr; } + virtual void Forget(ISurfaceAllocator* aAllocator) override { mSurface = nullptr; } + + // For debugging purposes only. + already_AddRefed GetAsSurface(); protected: - virtual void FinalizeOnIPDLThread() override; + explicit MacIOSurfaceTextureData(MacIOSurface* aSurface); + + virtual void FinalizeOnIPDLThread(TextureClient* aWrapper) override; RefPtr mSurface; - bool mIsLocked; }; } // namespace layers