Bug 897452 - Part 0.1 - Make it possible for TextureClient to call virtual methods just before its destructor. r=bjacob

This commit is contained in:
Nicolas Silva 2013-12-11 13:05:05 -05:00
parent d7114d0408
commit fc2a2730d2
2 changed files with 33 additions and 2 deletions

View File

@ -111,7 +111,8 @@ ShmemTextureClient::DropTextureData()
} }
TextureClient::TextureClient(TextureFlags aFlags) TextureClient::TextureClient(TextureFlags aFlags)
: mID(0) : mRefCount(0)
, mID(0)
, mFlags(aFlags) , mFlags(aFlags)
, mShared(false) , mShared(false)
, mValid(true) , mValid(true)

View File

@ -149,12 +149,28 @@ public:
* In order to send several different buffers to the compositor side, use * In order to send several different buffers to the compositor side, use
* several TextureClients. * several TextureClients.
*/ */
class TextureClient : public AtomicRefCounted<TextureClient> class TextureClient
{ {
public: public:
TextureClient(TextureFlags aFlags = TEXTURE_FLAGS_DEFAULT); TextureClient(TextureFlags aFlags = TEXTURE_FLAGS_DEFAULT);
virtual ~TextureClient(); 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 TextureClientSurface* AsTextureClientSurface() { return nullptr; }
virtual TextureClientDrawTarget* AsTextureClientDrawTarget() { return nullptr; } virtual TextureClientDrawTarget* AsTextureClientDrawTarget() { return nullptr; }
virtual TextureClientYCbCr* AsTextureClientYCbCr() { return nullptr; } virtual TextureClientYCbCr* AsTextureClientYCbCr() { return nullptr; }
@ -253,6 +269,20 @@ public:
// method to forget about the shmem _without_ releasing it. // method to forget about the shmem _without_ releasing it.
virtual void OnActorDestroy() {} 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: protected:
void AddFlags(TextureFlags aFlags) void AddFlags(TextureFlags aFlags)
{ {