From 4002af5009c524b954b7bc86dc4f7380cd156490 Mon Sep 17 00:00:00 2001 From: Benoit Jacob Date: Wed, 11 Dec 2013 20:45:01 -0500 Subject: [PATCH] Bug 897452 - Part 10 - adapt post landing of bug 893301 - r=nical,nrc --- gfx/layers/client/CompositableClient.cpp | 12 ---- gfx/layers/client/CompositableClient.h | 3 - gfx/layers/client/ContentClient.cpp | 15 ----- gfx/layers/composite/CompositableHost.cpp | 17 ------ gfx/layers/composite/CompositableHost.h | 1 - gfx/layers/composite/ContentHost.cpp | 68 ----------------------- gfx/layers/composite/ContentHost.h | 2 - gfx/layers/composite/ImageHost.h | 7 +-- gfx/layers/composite/TextureHost.cpp | 25 ++++++--- gfx/layers/composite/TextureHost.h | 34 ++++++++++-- gfx/layers/composite/TiledContentHost.h | 10 +--- 11 files changed, 50 insertions(+), 144 deletions(-) diff --git a/gfx/layers/client/CompositableClient.cpp b/gfx/layers/client/CompositableClient.cpp index 0e6b132a5c4..f02535f40a0 100644 --- a/gfx/layers/client/CompositableClient.cpp +++ b/gfx/layers/client/CompositableClient.cpp @@ -233,18 +233,6 @@ CompositableClient::CreateTextureClientForDrawing(SurfaceFormat aFormat, return result; } -uint64_t -CompositableClient::NextTextureID() -{ - ++mNextTextureID; - // 0 is always an invalid ID - if (mNextTextureID == 0) { - ++mNextTextureID; - } - - return mNextTextureID; -} - bool CompositableClient::AddTextureClient(TextureClient* aClient) { diff --git a/gfx/layers/client/CompositableClient.h b/gfx/layers/client/CompositableClient.h index 8c92c1882d4..bcccbe1802c 100644 --- a/gfx/layers/client/CompositableClient.h +++ b/gfx/layers/client/CompositableClient.h @@ -148,9 +148,6 @@ public: virtual void OnActorDestroy() = 0; protected: - // return the next texture ID - uint64_t NextTextureID(); - CompositableChild* mCompositableChild; CompositableForwarder* mForwarder; }; diff --git a/gfx/layers/client/ContentClient.cpp b/gfx/layers/client/ContentClient.cpp index 37e09bda027..55285b65393 100644 --- a/gfx/layers/client/ContentClient.cpp +++ b/gfx/layers/client/ContentClient.cpp @@ -148,9 +148,6 @@ ContentClientRemoteBuffer::EndPaint() // decided we didn't need one yet because the region to draw was empty. SetBufferProvider(nullptr); SetBufferProviderOnWhite(nullptr); - for (size_t i = 0; i < mOldTextures.Length(); ++i) { - RemoveTextureClient(mOldTextures[i]); - } mOldTextures.Clear(); if (mTextureClient) { @@ -307,9 +304,6 @@ ContentClientRemoteBuffer::OnActorDestroy() if (mTextureClientOnWhite) { mTextureClientOnWhite->OnActorDestroy(); } - for (size_t i = 0; i < mOldTextures.Length(); ++i) { - mOldTextures[i]->OnActorDestroy(); - } } void @@ -507,9 +501,6 @@ DeprecatedContentClientRemoteBuffer::OnActorDestroy() if (mDeprecatedTextureClientOnWhite) { mDeprecatedTextureClientOnWhite->OnActorDestroy(); } - for (size_t i = 0; i < mOldTextures.Length(); ++i) { - mOldTextures[i]->OnActorDestroy(); - } } void @@ -675,9 +666,6 @@ ContentClientDoubleBuffered::OnActorDestroy() if (mTextureClientOnWhite) { mTextureClientOnWhite->OnActorDestroy(); } - for (size_t i = 0; i < mOldTextures.Length(); ++i) { - mOldTextures[i]->OnActorDestroy(); - } if (mFrontClient) { mFrontClient->OnActorDestroy(); } @@ -795,9 +783,6 @@ DeprecatedContentClientDoubleBuffered::OnActorDestroy() if (mDeprecatedTextureClientOnWhite) { mDeprecatedTextureClientOnWhite->OnActorDestroy(); } - for (size_t i = 0; i < mOldTextures.Length(); ++i) { - mOldTextures[i]->OnActorDestroy(); - } if (mFrontClient) { mFrontClient->OnActorDestroy(); } diff --git a/gfx/layers/composite/CompositableHost.cpp b/gfx/layers/composite/CompositableHost.cpp index 74247fd9f42..67b91ac2e08 100644 --- a/gfx/layers/composite/CompositableHost.cpp +++ b/gfx/layers/composite/CompositableHost.cpp @@ -48,16 +48,6 @@ CompositableHost::UseTextureHost(TextureHost* aTexture) aTexture->SetCompositableBackendSpecificData(GetCompositableBackendSpecificData()); } -void -CompositableHost::OnActorDestroy() -{ - TextureHost* it = mFirstTexture; - while (it) { - it->OnActorDestroy(); - it = it->GetNextSibling(); - } -} - void CompositableHost::SetCompositor(Compositor* aCompositor) { @@ -214,13 +204,6 @@ void CompositableParent::ActorDestroy(ActorDestroyReason why) { if (mHost) { - // XXX: sadness warning. We should be able to do this whenever we get ActorDestroy, - // not just for abnormal shutdowns (which is the only case we _need_ to - so that - // we don't double release our shmems). But, for some reason, that causes a - // crash, we don't know why. (Bug 925773). - if (why == AbnormalShutdown) { - mHost->OnActorDestroy(); - } mHost->Detach(nullptr, CompositableHost::FORCE_DETACH); } } diff --git a/gfx/layers/composite/CompositableHost.h b/gfx/layers/composite/CompositableHost.h index 8f6c8d51411..35425f0550f 100644 --- a/gfx/layers/composite/CompositableHost.h +++ b/gfx/layers/composite/CompositableHost.h @@ -301,7 +301,6 @@ protected: Compositor* mCompositor; Layer* mLayer; RefPtr mBackendData; - RefPtr mFirstTexture; bool mAttached; bool mKeepAttached; }; diff --git a/gfx/layers/composite/ContentHost.cpp b/gfx/layers/composite/ContentHost.cpp index 116ac028f9f..7b0ee6d1616 100644 --- a/gfx/layers/composite/ContentHost.cpp +++ b/gfx/layers/composite/ContentHost.cpp @@ -45,47 +45,15 @@ ContentHostBase::GetAsTextureHost() void ContentHostBase::DestroyTextureHost() { - // The third clause in the if statement checks that we are in fact done with - // this texture. We don't want to prematurely deallocate a texture we might - // use again or double deallocate. Deallocation will happen in - // RemoveTextureHost. - // Note that GetTextureHost is linear in the number of texture hosts, but as - // long as that number is small (I expect a maximum of 6 for now) then it - // should be ok. - if (mTextureHost && - mTextureHost->GetFlags() & TEXTURE_DEALLOCATE_DEFERRED && - !GetTextureHost(mTextureHost->GetID())) { - MOZ_ASSERT(!(mTextureHost->GetFlags() & TEXTURE_DEALLOCATE_CLIENT)); - mTextureHost->DeallocateSharedData(); - } mTextureHost = nullptr; } void ContentHostBase::DestroyTextureHostOnWhite() { - if (mTextureHostOnWhite && - mTextureHostOnWhite->GetFlags() & TEXTURE_DEALLOCATE_DEFERRED && - !GetTextureHost(mTextureHostOnWhite->GetID())) { - MOZ_ASSERT(!(mTextureHostOnWhite->GetFlags() & TEXTURE_DEALLOCATE_CLIENT)); - mTextureHostOnWhite->DeallocateSharedData(); - } mTextureHostOnWhite = nullptr; } -void -ContentHostBase::RemoveTextureHost(TextureHost* aTexture) -{ - if ((aTexture->GetFlags() & TEXTURE_DEALLOCATE_DEFERRED) && - !(mTextureHost && mTextureHost == aTexture) && - !(mTextureHostOnWhite && mTextureHostOnWhite == aTexture)) { - MOZ_ASSERT(!(aTexture->GetFlags() & TEXTURE_DEALLOCATE_CLIENT)); - aTexture->DeallocateSharedData(); - } - - CompositableHost::RemoveTextureHost(aTexture); -} - class MOZ_STACK_CLASS AutoLockTextureHost { public: @@ -338,12 +306,6 @@ ContentHostBase::Dump(FILE* aFile, void ContentHostBase::OnActorDestroy() { - if (mTextureHost) { - mTextureHost->OnActorDestroy(); - } - if (mTextureHostOnWhite) { - mTextureHostOnWhite->OnActorDestroy(); - } CompositableHost::OnActorDestroy(); } @@ -376,18 +338,6 @@ DeprecatedContentHostBase::DestroyFrontHost() void DeprecatedContentHostBase::OnActorDestroy() { - if (mDeprecatedTextureHost) { - mDeprecatedTextureHost->OnActorDestroy(); - } - if (mDeprecatedTextureHostOnWhite) { - mDeprecatedTextureHostOnWhite->OnActorDestroy(); - } - if (mNewFrontHost) { - mNewFrontHost->OnActorDestroy(); - } - if (mNewFrontHostOnWhite) { - mNewFrontHostOnWhite->OnActorDestroy(); - } } void @@ -851,24 +801,6 @@ DeprecatedContentHostDoubleBuffered::DestroyTextures() void DeprecatedContentHostDoubleBuffered::OnActorDestroy() { - if (mDeprecatedTextureHost) { - mDeprecatedTextureHost->OnActorDestroy(); - } - if (mDeprecatedTextureHostOnWhite) { - mDeprecatedTextureHostOnWhite->OnActorDestroy(); - } - if (mNewFrontHost) { - mNewFrontHost->OnActorDestroy(); - } - if (mNewFrontHostOnWhite) { - mNewFrontHostOnWhite->OnActorDestroy(); - } - if (mBackHost) { - mBackHost->OnActorDestroy(); - } - if (mBackHostOnWhite) { - mBackHostOnWhite->OnActorDestroy(); - } } void diff --git a/gfx/layers/composite/ContentHost.h b/gfx/layers/composite/ContentHost.h index 52e54098070..62679c32c11 100644 --- a/gfx/layers/composite/ContentHost.h +++ b/gfx/layers/composite/ContentHost.h @@ -117,8 +117,6 @@ public: virtual void UseTextureHost(TextureHost* aTexture) MOZ_OVERRIDE; - virtual void RemoveTextureHost(TextureHost* aTexture) MOZ_OVERRIDE; - virtual void SetPaintWillResample(bool aResample) { mPaintWillResample = aResample; } virtual void OnActorDestroy() MOZ_OVERRIDE; diff --git a/gfx/layers/composite/ImageHost.h b/gfx/layers/composite/ImageHost.h index 7f68cb03239..e8bfb62dee2 100644 --- a/gfx/layers/composite/ImageHost.h +++ b/gfx/layers/composite/ImageHost.h @@ -127,12 +127,7 @@ public: virtual void SetCompositor(Compositor* aCompositor) MOZ_OVERRIDE; - virtual void OnActorDestroy() MOZ_OVERRIDE - { - if (mDeprecatedTextureHost) { - mDeprecatedTextureHost->OnActorDestroy(); - } - } + virtual void OnActorDestroy() MOZ_OVERRIDE {} virtual void PrintInfo(nsACString& aTo, const char* aPrefix); diff --git a/gfx/layers/composite/TextureHost.cpp b/gfx/layers/composite/TextureHost.cpp index 27f1145dd73..d48fdd08464 100644 --- a/gfx/layers/composite/TextureHost.cpp +++ b/gfx/layers/composite/TextureHost.cpp @@ -43,10 +43,10 @@ public: virtual bool RecvRemoveTextureSync() MOZ_OVERRIDE; - virtual void ActorDestroy(ActorDestroyReason why) MOZ_OVERRIDE; - TextureHost* GetTextureHost() { return mTextureHost; } + void ActorDestroy(ActorDestroyReason why); + ISurfaceAllocator* mAllocator; RefPtr mTextureHost; }; @@ -212,13 +212,23 @@ TextureHost::SetCompositableBackendSpecificData(CompositableBackendSpecificData* TextureHost::TextureHost(TextureFlags aFlags) - : mFlags(aFlags) + : mRefCount(0) + , mFlags(aFlags) {} TextureHost::~TextureHost() { } +void TextureHost::Finalize() +{ + if (GetFlags() & TEXTURE_DEALLOCATE_DEFERRED) { + MOZ_ASSERT(!(GetFlags() & TEXTURE_DEALLOCATE_CLIENT)); + DeallocateSharedData(); + DeallocateDeviceData(); + } +} + void TextureHost::PrintInfo(nsACString& aTo, const char* aPrefix) { @@ -300,7 +310,7 @@ DeprecatedTextureHost::SwapTextures(const SurfaceDescriptor& aImage, } void -DeprecatedTextureHost::OnActorDestroy() +DeprecatedTextureHost::OnShutdown() { if (ISurfaceAllocator::IsShmem(mBuffer)) { *mBuffer = SurfaceDescriptor(); @@ -593,7 +603,7 @@ ShmemTextureHost::ForgetSharedData() } void -ShmemTextureHost::OnActorDestroy() +ShmemTextureHost::OnShutdown() { delete mShmem; mShmem = nullptr; @@ -690,14 +700,15 @@ TextureParent::ActorDestroy(ActorDestroyReason why) NS_WARNING("PTexture deleted after ancestor"); // fall-through to deletion path case Deletion: - if (!(mTextureHost->GetFlags() & TEXTURE_DEALLOCATE_CLIENT)) { + if (!(mTextureHost->GetFlags() & TEXTURE_DEALLOCATE_CLIENT) && + !(mTextureHost->GetFlags() & TEXTURE_DEALLOCATE_DEFERRED)) { mTextureHost->DeallocateSharedData(); } break; case NormalShutdown: case AbnormalShutdown: - mTextureHost->OnActorDestroy(); + mTextureHost->OnShutdown(); break; case FailedConstructor: diff --git a/gfx/layers/composite/TextureHost.h b/gfx/layers/composite/TextureHost.h index c8654748a73..99ce9575266 100644 --- a/gfx/layers/composite/TextureHost.h +++ b/gfx/layers/composite/TextureHost.h @@ -258,13 +258,39 @@ private: * The Lock/Unlock mecanism here mirrors Lock/Unlock in TextureClient. * */ -class TextureHost : public RefCounted +class TextureHost { + Atomic 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(); + public: TextureHost(TextureFlags aFlags); virtual ~TextureHost(); + 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; + } + } + /** * Factory method. */ @@ -394,7 +420,7 @@ public: // If a texture host holds a reference to shmem, it should override this method // to forget about the shmem _without_ releasing it. - virtual void OnActorDestroy() {} + virtual void OnShutdown() {} virtual const char *Name() { return "TextureHost"; } virtual void PrintInfo(nsACString& aTo, const char* aPrefix); @@ -490,7 +516,7 @@ public: virtual const char *Name() MOZ_OVERRIDE { return "ShmemTextureHost"; } - virtual void OnActorDestroy() MOZ_OVERRIDE; + virtual void OnShutdown() MOZ_OVERRIDE; protected: mozilla::ipc::Shmem* mShmem; @@ -718,7 +744,7 @@ public: // see bug 865908 about fixing this. virtual void ForgetBuffer() {} - void OnActorDestroy(); + void OnShutdown(); protected: /** diff --git a/gfx/layers/composite/TiledContentHost.h b/gfx/layers/composite/TiledContentHost.h index d281a89500e..aab7f2b540a 100644 --- a/gfx/layers/composite/TiledContentHost.h +++ b/gfx/layers/composite/TiledContentHost.h @@ -119,15 +119,7 @@ public: mCompositor = aCompositor; } - void OnActorDestroy() - { - Iterator end = TilesEnd(); - for (Iterator it = TilesBegin(); it != end; ++it) { - if (it->mDeprecatedTextureHost) { - it->mDeprecatedTextureHost->OnActorDestroy(); - } - } - } + void OnActorDestroy() {} protected: TiledTexture ValidateTile(TiledTexture aTile,