Bug 1200595 - SharedSurface TextureData implementation. r=jgilbert
authorNicolas Silva <nsilva@mozilla.com>
Fri, 20 Nov 2015 14:24:55 +0100
changeset 308851 ca5f63ec86ecc1fde3fdaf2f5ead835167f88687
parent 308850 cccfd06730e92ddf7b0cc50fc57ccfa2f0310554
child 308852 94e3e5bfbeb314fcdbb54dc89d04346014763898
push id5513
push userraliiev@mozilla.com
push dateMon, 25 Jan 2016 13:55:34 +0000
treeherdermozilla-beta@5ee97dd05b5c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjgilbert
bugs1200595
milestone45.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1200595 - SharedSurface TextureData implementation. r=jgilbert
gfx/gl/SharedSurface.cpp
gfx/layers/client/TextureClient.h
gfx/layers/client/TextureClientSharedSurface.cpp
gfx/layers/client/TextureClientSharedSurface.h
--- a/gfx/gl/SharedSurface.cpp
+++ b/gfx/gl/SharedSurface.cpp
@@ -350,17 +350,17 @@ SurfaceFactory::NewTexClient(const gfx::
         StopRecycling(cur);
     }
 
     UniquePtr<SharedSurface> surf = Move(CreateShared(size));
     if (!surf)
         return nullptr;
 
     RefPtr<layers::SharedSurfaceTextureClient> ret;
-    ret = new layers::SharedSurfaceTextureClient(mAllocator, mFlags, Move(surf), this);
+    ret = layers::SharedSurfaceTextureClient::Create(Move(surf), this, mAllocator, mFlags);
 
     StartRecycling(ret);
 
     return ret.forget();
 }
 
 void
 SurfaceFactory::StartRecycling(layers::SharedSurfaceTextureClient* tc)
@@ -386,17 +386,17 @@ SurfaceFactory::StopRecycling(layers::Sh
 
 /*static*/ void
 SurfaceFactory::RecycleCallback(layers::TextureClient* rawTC, void* rawFactory)
 {
     RefPtr<layers::SharedSurfaceTextureClient> tc;
     tc = static_cast<layers::SharedSurfaceTextureClient*>(rawTC);
     SurfaceFactory* factory = static_cast<SurfaceFactory*>(rawFactory);
 
-    if (tc->mSurf->mCanRecycle) {
+    if (tc->Surf()->mCanRecycle) {
         if (factory->Recycle(tc))
             return;
     }
 
     // Did not recover the tex client. End the (re)cycle!
     factory->StopRecycling(tc);
 }
 
--- a/gfx/layers/client/TextureClient.h
+++ b/gfx/layers/client/TextureClient.h
@@ -530,16 +530,17 @@ public:
     return mAllocator;
   }
 
    TextureClientRecycleAllocator* GetRecycleAllocator() { return mRecycleAllocator; }
    void SetRecycleAllocator(TextureClientRecycleAllocator* aAllocator);
 
   /// If you add new code that uses this funtion, you are probably doing something wrong.
   virtual TextureData* GetInternalData() { return nullptr; }
+  virtual const TextureData* GetInternalData() const { return nullptr; }
 
 private:
   static void TextureClientRecycleCallback(TextureClient* aClient, void* aClosure);
 
   /**
    * Called once, during the destruction of the Texture, on the thread in which
    * texture's reference count reaches 0 (could be any thread).
    *
@@ -699,16 +700,17 @@ public:
 
   virtual void SyncWithObject(SyncObject* aFence) override { mData->SyncWithObject(aFence); }
 
   // by construction, ClientTexture cannot be created without successful allocation.
   virtual bool IsAllocated() const override { return true; }
 
   /// If you add new code that uses this method, you are probably doing something wrong.
   virtual TextureData* GetInternalData() override { return mData; }
+  virtual const TextureData* GetInternalData() const override { return mData; }
 
   virtual void FinalizeOnIPDLThread() override;
 
 protected:
   TextureData* mData;
   RefPtr<gfx::DrawTarget> mBorrowedDrawTarget;
   RefPtr<TextureReadbackSink> mReadbackSink;
 
--- a/gfx/layers/client/TextureClientSharedSurface.cpp
+++ b/gfx/layers/client/TextureClientSharedSurface.cpp
@@ -18,96 +18,112 @@
 #include "SharedSurfaceGralloc.h"
 #endif
 
 using namespace mozilla::gl;
 
 namespace mozilla {
 namespace layers {
 
-SharedSurfaceTextureClient::SharedSurfaceTextureClient(ISurfaceAllocator* aAllocator,
-                                                       TextureFlags aFlags,
-                                                       UniquePtr<gl::SharedSurface> surf,
-                                                       gl::SurfaceFactory* factory)
-  : TextureClient(aAllocator,
-                  aFlags | TextureFlags::RECYCLE | surf->GetTextureFlags())
-  , mSurf(Move(surf))
-{
-}
+
+SharedSurfaceTextureData::SharedSurfaceTextureData(UniquePtr<gl::SharedSurface> surf)
+  : mSurf(Move(surf))
+{}
 
-SharedSurfaceTextureClient::~SharedSurfaceTextureClient()
-{
-  // Free the ShSurf implicitly.
-}
+SharedSurfaceTextureData::~SharedSurfaceTextureData()
+{}
+
+void
+SharedSurfaceTextureData::Deallocate(ISurfaceAllocator*)
+{}
 
 gfx::IntSize
-SharedSurfaceTextureClient::GetSize() const
+SharedSurfaceTextureData::GetSize() const
 {
   return mSurf->mSize;
 }
 
 bool
-SharedSurfaceTextureClient::ToSurfaceDescriptor(SurfaceDescriptor& aOutDescriptor)
+SharedSurfaceTextureData::Serialize(SurfaceDescriptor& aOutDescriptor)
 {
   return mSurf->ToSurfaceDescriptor(&aOutDescriptor);
 }
 
+
+SharedSurfaceTextureClient::SharedSurfaceTextureClient(SharedSurfaceTextureData* aData,
+                                                       TextureFlags aFlags,
+                                                       ISurfaceAllocator* aAllocator)
+: ClientTexture(aData, aFlags, aAllocator)
+{}
+
+already_AddRefed<SharedSurfaceTextureClient>
+SharedSurfaceTextureClient::Create(UniquePtr<gl::SharedSurface> surf, gl::SurfaceFactory* factory,
+                                   ISurfaceAllocator* aAllocator, TextureFlags aFlags)
+{
+  if (!surf) {
+    return nullptr;
+  }
+  TextureFlags flags = aFlags | TextureFlags::RECYCLE | surf->GetTextureFlags();
+  SharedSurfaceTextureData* data = new SharedSurfaceTextureData(Move(surf));
+  return MakeAndAddRef<SharedSurfaceTextureClient>(data, flags, aAllocator);
+}
+
 void
 SharedSurfaceTextureClient::SetReleaseFenceHandle(const FenceHandle& aReleaseFenceHandle)
 {
 #ifdef MOZ_WIDGET_GONK
   gl::SharedSurface_Gralloc* surf = nullptr;
-  if (mSurf->mType == gl::SharedSurfaceType::Gralloc) {
-    surf = gl::SharedSurface_Gralloc::Cast(mSurf.get());
+  if (Surf()->mType == gl::SharedSurfaceType::Gralloc) {
+    surf = gl::SharedSurface_Gralloc::Cast(Surf());
   }
   if (surf && surf->GetTextureClient()) {
     surf->GetTextureClient()->SetReleaseFenceHandle(aReleaseFenceHandle);
     return;
   }
 #endif
   TextureClient::SetReleaseFenceHandle(aReleaseFenceHandle);
 }
 
 FenceHandle
 SharedSurfaceTextureClient::GetAndResetReleaseFenceHandle()
 {
 #ifdef MOZ_WIDGET_GONK
   gl::SharedSurface_Gralloc* surf = nullptr;
-  if (mSurf->mType == gl::SharedSurfaceType::Gralloc) {
-    surf = gl::SharedSurface_Gralloc::Cast(mSurf.get());
+  if (Surf()->mType == gl::SharedSurfaceType::Gralloc) {
+    surf = gl::SharedSurface_Gralloc::Cast(Surf());
   }
   if (surf && surf->GetTextureClient()) {
     return surf->GetTextureClient()->GetAndResetReleaseFenceHandle();
   }
 #endif
   return TextureClient::GetAndResetReleaseFenceHandle();
 }
 
 void
 SharedSurfaceTextureClient::SetAcquireFenceHandle(const FenceHandle& aAcquireFenceHandle)
 {
 #ifdef MOZ_WIDGET_GONK
   gl::SharedSurface_Gralloc* surf = nullptr;
-  if (mSurf->mType == gl::SharedSurfaceType::Gralloc) {
-    surf = gl::SharedSurface_Gralloc::Cast(mSurf.get());
+  if (Surf()->mType == gl::SharedSurfaceType::Gralloc) {
+    surf = gl::SharedSurface_Gralloc::Cast(Surf());
   }
   if (surf && surf->GetTextureClient()) {
     return surf->GetTextureClient()->SetAcquireFenceHandle(aAcquireFenceHandle);
   }
 #endif
   TextureClient::SetAcquireFenceHandle(aAcquireFenceHandle);
 }
 
 const FenceHandle&
 SharedSurfaceTextureClient::GetAcquireFenceHandle() const
 {
 #ifdef MOZ_WIDGET_GONK
   gl::SharedSurface_Gralloc* surf = nullptr;
-  if (mSurf->mType == gl::SharedSurfaceType::Gralloc) {
-    surf = gl::SharedSurface_Gralloc::Cast(mSurf.get());
+  if (Surf()->mType == gl::SharedSurfaceType::Gralloc) {
+    surf = gl::SharedSurface_Gralloc::Cast(Surf());
   }
   if (surf && surf->GetTextureClient()) {
     return surf->GetTextureClient()->GetAcquireFenceHandle();
   }
 #endif
   return TextureClient::GetAcquireFenceHandle();
 }
 
--- a/gfx/layers/client/TextureClientSharedSurface.h
+++ b/gfx/layers/client/TextureClientSharedSurface.h
@@ -21,60 +21,69 @@ namespace mozilla {
 namespace gl {
 class GLContext;
 class SharedSurface;
 class SurfaceFactory;
 } // namespace gl
 
 namespace layers {
 
-class SharedSurfaceTextureClient : public TextureClient
+class SharedSurfaceTextureClient;
+
+class SharedSurfaceTextureData : public TextureData
 {
 protected:
   const UniquePtr<gl::SharedSurface> mSurf;
 
-  friend class gl::SurfaceFactory;
+  friend class SharedSurfaceTextureClient;
 
-  SharedSurfaceTextureClient(ISurfaceAllocator* aAllocator, TextureFlags aFlags,
-                             UniquePtr<gl::SharedSurface> surf,
-                             gl::SurfaceFactory* factory);
+  explicit SharedSurfaceTextureData(UniquePtr<gl::SharedSurface> surf);
+public:
 
-  ~SharedSurfaceTextureClient();
+  ~SharedSurfaceTextureData();
 
-public:
-  virtual bool IsAllocated() const override { return true; }
-  virtual bool Lock(OpenMode) override { return false; }
-  virtual bool IsLocked() const override { return false; }
+  virtual bool Lock(OpenMode, FenceHandle*) override { return false; }
+
+  virtual void Unlock() override {}
+
   virtual bool HasInternalBuffer() const override { return false; }
 
   virtual gfx::SurfaceFormat GetFormat() const override {
     return gfx::SurfaceFormat::UNKNOWN;
   }
 
-  virtual already_AddRefed<TextureClient>
-  CreateSimilar(TextureFlags, TextureAllocationFlags) const override {
-    return nullptr;
-  }
-
-  virtual bool AllocateForSurface(gfx::IntSize,
-                                  TextureAllocationFlags) override {
-    MOZ_CRASH("Should never hit this.");
-    return false;
-  }
-
   virtual gfx::IntSize GetSize() const override;
 
-  virtual bool ToSurfaceDescriptor(SurfaceDescriptor& aOutDescriptor) override;
+  virtual bool Serialize(SurfaceDescriptor& aOutDescriptor) override;
+
+  virtual void Deallocate(ISurfaceAllocator*) override;
+
+  gl::SharedSurface* Surf() const { return mSurf.get(); }
+};
+
+class SharedSurfaceTextureClient : public ClientTexture
+{
+public:
+  SharedSurfaceTextureClient(SharedSurfaceTextureData* aData,
+                             TextureFlags aFlags,
+                             ISurfaceAllocator* aAllocator);
+
+  static already_AddRefed<SharedSurfaceTextureClient>
+  Create(UniquePtr<gl::SharedSurface> surf, gl::SurfaceFactory* factory,
+         ISurfaceAllocator* aAllocator, TextureFlags aFlags);
 
   virtual void SetReleaseFenceHandle(const FenceHandle& aReleaseFenceHandle) override;
+
   virtual FenceHandle GetAndResetReleaseFenceHandle() override;
+
   virtual void SetAcquireFenceHandle(const FenceHandle& aAcquireFenceHandle) override;
+
   virtual const FenceHandle& GetAcquireFenceHandle() const override;
 
   gl::SharedSurface* Surf() const {
-    return mSurf.get();
+    return static_cast<const SharedSurfaceTextureData*>(GetInternalData())->Surf();
   }
 };
 
 } // namespace layers
 } // namespace mozilla
 
 #endif // MOZILLA_GFX_TEXTURECLIENT_SHAREDSURFACE_H