Bug 949347 - reference-count TextureChild and have TextureClient hold on to it - r=nical,sotaro

This commit is contained in:
Benoit Jacob 2013-12-20 16:44:30 -05:00
parent b15efdadba
commit 01ed72bcab
2 changed files with 34 additions and 8 deletions

View File

@ -52,12 +52,14 @@ namespace layers {
* deallocte or recycle the it.
*/
class TextureChild : public PTextureChild
, public AtomicRefCounted<TextureChild>
{
public:
TextureChild()
: mForwarder(nullptr)
, mTextureData(nullptr)
, mTextureClient(nullptr)
, mIPCOpen(false)
{
MOZ_COUNT_CTOR(TextureChild);
}
@ -87,11 +89,29 @@ public:
void ActorDestroy(ActorDestroyReason why) MOZ_OVERRIDE;
bool IPCOpen() const { return mIPCOpen; }
private:
// AddIPDLReference and ReleaseIPDLReference are only to be called by CreateIPDLActor
// and DestroyIPDLActor, respectively. We intentionally make them private to prevent misuse.
// The purpose of these methods is to be aware of when the IPC system around this
// actor goes down: mIPCOpen is then set to false.
void AddIPDLReference() {
MOZ_ASSERT(mIPCOpen == false);
mIPCOpen = true;
AddRef();
}
void ReleaseIPDLReference() {
MOZ_ASSERT(mIPCOpen == true);
mIPCOpen = false;
Release();
}
CompositableForwarder* mForwarder;
TextureClientData* mTextureData;
TextureClient* mTextureClient;
bool mIPCOpen;
friend class TextureClient;
};
@ -125,14 +145,16 @@ TextureChild::ActorDestroy(ActorDestroyReason why)
PTextureChild*
TextureClient::CreateIPDLActor()
{
return new TextureChild();
TextureChild* c = new TextureChild();
c->AddIPDLReference();
return c;
}
// static
bool
TextureClient::DestroyIPDLActor(PTextureChild* actor)
{
delete actor;
static_cast<TextureChild*>(actor)->ReleaseIPDLReference();
return true;
}
@ -151,7 +173,8 @@ TextureClient::InitIPDLActor(CompositableForwarder* aForwarder)
mActor->mForwarder = aForwarder;
mActor->mTextureClient = this;
mShared = true;
return mActor->SendInit(desc, GetFlags());
return mActor->IPCOpen() &&
mActor->SendInit(desc, GetFlags());
}
PTextureChild*
@ -234,8 +257,7 @@ ShmemTextureClient::DropTextureData()
}
TextureClient::TextureClient(TextureFlags aFlags)
: mActor(nullptr)
, mFlags(aFlags)
: mFlags(aFlags)
, mShared(false)
, mValid(true)
{}
@ -251,10 +273,14 @@ void TextureClient::ForceRemove()
if (mValid && mActor) {
if (GetFlags() & TEXTURE_DEALLOCATE_CLIENT) {
mActor->SetTextureData(DropTextureData());
mActor->SendRemoveTextureSync();
if (mActor->IPCOpen()) {
mActor->SendRemoveTextureSync();
}
mActor->DeleteTextureData();
} else {
mActor->SendRemoveTexture();
if (mActor->IPCOpen()) {
mActor->SendRemoveTexture();
}
}
}
MarkInvalid();

View File

@ -277,7 +277,7 @@ protected:
mFlags |= aFlags;
}
TextureChild* mActor;
RefPtr<TextureChild> mActor;
TextureFlags mFlags;
bool mShared;
bool mValid;