Bug 897452 - Part 0.1 - Make it possible for TextureClient to call virtual methods just before its destructor. r=bjacob
authorNicolas Silva <nical@mozilla.com>
Wed, 11 Dec 2013 20:44:40 -0500
changeset 177016 6f89d41fec228cb8eae38ab6525541970bfa7e95
parent 177015 7027a7afab3c5f5626070c864f4b969f9a8a6d90
child 177017 30f02ad6864d2fc1d9aeb125b40f736b7603081c
push id462
push userraliiev@mozilla.com
push dateTue, 22 Apr 2014 00:22:30 +0000
treeherdermozilla-release@ac5db8c74ac0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbjacob
bugs897452
milestone29.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 897452 - Part 0.1 - Make it possible for TextureClient to call virtual methods just before its destructor. r=bjacob
gfx/layers/client/TextureClient.cpp
gfx/layers/client/TextureClient.h
--- a/gfx/layers/client/TextureClient.cpp
+++ b/gfx/layers/client/TextureClient.cpp
@@ -106,17 +106,18 @@ ShmemTextureClient::DropTextureData()
   }
   TextureClientData* result = new ShmemTextureClientData(mShmem);
   MarkInvalid();
   mShmem = ipc::Shmem();
   return result;
 }
 
 TextureClient::TextureClient(TextureFlags aFlags)
-  : mID(0)
+  : mRefCount(0)
+  , mID(0)
   , mFlags(aFlags)
   , mShared(false)
   , mValid(true)
 {}
 
 TextureClient::~TextureClient()
 {}
 
--- a/gfx/layers/client/TextureClient.h
+++ b/gfx/layers/client/TextureClient.h
@@ -144,22 +144,38 @@ public:
  * TextureClient/Host pair only owns one buffer of image data through its
  * lifetime. This means that the lifetime of the underlying shared data
  * matches the lifetime of the TextureClient/Host pair. It also means
  * TextureClient/Host do not implement double buffering, which is the
  * responsibility of the compositable (which would use two Texture pairs).
  * In order to send several different buffers to the compositor side, use
  * several TextureClients.
  */
-class TextureClient : public AtomicRefCounted<TextureClient>
+class TextureClient
 {
 public:
   TextureClient(TextureFlags aFlags = TEXTURE_FLAGS_DEFAULT);
   virtual ~TextureClient();
 
+  void AddRef() {
+    MOZ_ASSERT(mRefCount >= 0);
+    ++mRefCount;
+  }
+
+  void Release() {
+    MOZ_ASSERT(mRefCount > 0);
+    if (0 == --mRefCount) {
+#ifdef DEBUG
+      mRefCount = detail::DEAD;
+#endif
+      Finalize();
+      delete this;
+    }
+  }
+
   virtual TextureClientSurface* AsTextureClientSurface() { return nullptr; }
   virtual TextureClientDrawTarget* AsTextureClientDrawTarget() { return nullptr; }
   virtual TextureClientYCbCr* AsTextureClientYCbCr() { return nullptr; }
 
   /**
    * Locks the shared data, allowing the caller to get access to it.
    *
    * Please always lock/unlock when accessing the shared data.
@@ -248,16 +264,30 @@ public:
    * anymore. This usually means it will soon be destroyed.
    */
   void MarkInvalid() { mValid = false; }
 
   // If a texture client holds a reference to shmem, it should override this
   // method to forget about the shmem _without_ releasing it.
   virtual void OnActorDestroy() {}
 
+private:
+  Atomic<int> mRefCount;
+
+  /**
+   * Called once, just before the destructor.
+   *
+   * Here goes the shut-down code that uses virtual methods.
+   * Must only be called by Release().
+   */
+  void Finalize()
+  {
+    // XXX Bug 897452 - Coming soon
+  }
+
 protected:
   void AddFlags(TextureFlags  aFlags)
   {
     MOZ_ASSERT(!IsSharedWithCompositor());
     mFlags |= aFlags;
   }
 
   uint64_t mID;