diff --git a/gfx/layers/composite/CanvasLayerComposite.cpp b/gfx/layers/composite/CanvasLayerComposite.cpp index ee39f8dd61f..7115e84cb38 100644 --- a/gfx/layers/composite/CanvasLayerComposite.cpp +++ b/gfx/layers/composite/CanvasLayerComposite.cpp @@ -33,7 +33,8 @@ CanvasLayerComposite::~CanvasLayerComposite() CleanupResources(); } -void CanvasLayerComposite::SetCompositableHost(CompositableHost* aHost) { +void +CanvasLayerComposite::SetCompositableHost(CompositableHost* aHost) { mImageHost = aHost; } @@ -46,7 +47,7 @@ CanvasLayerComposite::GetLayer() LayerRenderState CanvasLayerComposite::GetRenderState() { - if (mDestroyed || !mImageHost) { + if (mDestroyed || !mImageHost || !mImageHost->IsAttached()) { return LayerRenderState(); } return mImageHost->GetRenderState(); @@ -56,7 +57,7 @@ void CanvasLayerComposite::RenderLayer(const nsIntPoint& aOffset, const nsIntRect& aClipRect) { - if (!mImageHost) { + if (!mImageHost || !mImageHost->IsAttached()) { return; } @@ -96,8 +97,12 @@ CanvasLayerComposite::RenderLayer(const nsIntPoint& aOffset, } CompositableHost* -CanvasLayerComposite::GetCompositableHost() { - return mImageHost.get(); +CanvasLayerComposite::GetCompositableHost() +{ + if (mImageHost->IsAttached()) + return mImageHost.get(); + + return nullptr; } void @@ -115,7 +120,7 @@ CanvasLayerComposite::PrintInfo(nsACString& aTo, const char* aPrefix) { CanvasLayer::PrintInfo(aTo, aPrefix); aTo += "\n"; - if (mImageHost) { + if (mImageHost && mImageHost->IsAttached()) { nsAutoCString pfx(aPrefix); pfx += " "; mImageHost->PrintInfo(aTo, pfx.get()); diff --git a/gfx/layers/composite/CompositableHost.cpp b/gfx/layers/composite/CompositableHost.cpp index c1157037ee2..b1547372311 100644 --- a/gfx/layers/composite/CompositableHost.cpp +++ b/gfx/layers/composite/CompositableHost.cpp @@ -18,6 +18,7 @@ CompositableHost::CompositableHost(const TextureInfo& aTextureInfo) : mTextureInfo(aTextureInfo) , mCompositor(nullptr) , mLayer(nullptr) + , mAttached(false) { MOZ_COUNT_CTOR(CompositableHost); } diff --git a/gfx/layers/composite/CompositableHost.h b/gfx/layers/composite/CompositableHost.h index 6da7891c8a5..553e0f48f6f 100644 --- a/gfx/layers/composite/CompositableHost.h +++ b/gfx/layers/composite/CompositableHost.h @@ -185,13 +185,18 @@ public: virtual void Attach(Layer* aLayer, Compositor* aCompositor) { MOZ_ASSERT(aCompositor, "Compositor is required"); + MOZ_ASSERT(!IsAttached()); SetCompositor(aCompositor); SetLayer(aLayer); + mAttached = true; } - void Detach() { + void Detach() + { SetLayer(nullptr); SetCompositor(nullptr); + mAttached = false; } + bool IsAttached() { return mAttached; } virtual void Dump(FILE* aFile=nullptr, const char* aPrefix="", @@ -217,6 +222,7 @@ protected: Compositor* mCompositor; Layer* mLayer; RefPtr mFirstTexture; + bool mAttached; }; class CompositableParentManager; diff --git a/gfx/layers/composite/ImageLayerComposite.cpp b/gfx/layers/composite/ImageLayerComposite.cpp index 159b7293a31..468cdc78367 100644 --- a/gfx/layers/composite/ImageLayerComposite.cpp +++ b/gfx/layers/composite/ImageLayerComposite.cpp @@ -54,7 +54,7 @@ ImageLayerComposite::Disconnect() LayerRenderState ImageLayerComposite::GetRenderState() { - if (mImageHost) { + if (mImageHost && mImageHost->IsAttached()) { return mImageHost->GetRenderState(); } return LayerRenderState(); @@ -70,7 +70,7 @@ void ImageLayerComposite::RenderLayer(const nsIntPoint& aOffset, const nsIntRect& aClipRect) { - if (!mImageHost) { + if (!mImageHost || !mImageHost->IsAttached()) { return; } @@ -106,7 +106,8 @@ ImageLayerComposite::ComputeEffectiveTransforms(const gfx3DMatrix& aTransformToS // Snap image edges to pixel boundaries gfxRect sourceRect(0, 0, 0, 0); if (mImageHost && - (mImageHost->GetDeprecatedTextureHost() || mImageHost->GetTextureHost())) { + mImageHost->IsAttached() && + (mImageHost->GetDeprecatedTextureHost() || mImageHost->GetTextureHost())) { IntSize size = mImageHost->GetTextureHost() ? mImageHost->GetTextureHost()->GetSize() : mImageHost->GetDeprecatedTextureHost()->GetSize(); @@ -130,8 +131,12 @@ ImageLayerComposite::ComputeEffectiveTransforms(const gfx3DMatrix& aTransformToS } CompositableHost* -ImageLayerComposite::GetCompositableHost() { - return mImageHost.get(); +ImageLayerComposite::GetCompositableHost() +{ + if (mImageHost->IsAttached()) + return mImageHost.get(); + + return nullptr; } void @@ -149,7 +154,7 @@ ImageLayerComposite::PrintInfo(nsACString& aTo, const char* aPrefix) { ImageLayer::PrintInfo(aTo, aPrefix); aTo += "\n"; - if (mImageHost) { + if (mImageHost && mImageHost->IsAttached()) { nsAutoCString pfx(aPrefix); pfx += " "; mImageHost->PrintInfo(aTo, pfx.get()); diff --git a/gfx/layers/composite/ThebesLayerComposite.cpp b/gfx/layers/composite/ThebesLayerComposite.cpp index 1f92ae61218..a8db8b958fa 100644 --- a/gfx/layers/composite/ThebesLayerComposite.cpp +++ b/gfx/layers/composite/ThebesLayerComposite.cpp @@ -37,15 +37,13 @@ ThebesLayerComposite::ThebesLayerComposite(LayerManagerComposite *aManager) ThebesLayerComposite::~ThebesLayerComposite() { MOZ_COUNT_DTOR(ThebesLayerComposite); - if (mBuffer) { - mBuffer->Detach(); - } + CleanupResources(); } void ThebesLayerComposite::SetCompositableHost(CompositableHost* aHost) { - mBuffer= static_cast(aHost); + mBuffer = static_cast(aHost); } void @@ -58,10 +56,7 @@ void ThebesLayerComposite::Destroy() { if (!mDestroyed) { - if (mBuffer) { - mBuffer->Detach(); - } - mBuffer = nullptr; + CleanupResources(); mDestroyed = true; } } @@ -75,13 +70,14 @@ ThebesLayerComposite::GetLayer() TiledLayerComposer* ThebesLayerComposite::GetTiledLayerComposer() { + MOZ_ASSERT(mBuffer && mBuffer->IsAttached()); return mBuffer->AsTiledLayerComposer(); } LayerRenderState ThebesLayerComposite::GetRenderState() { - if (!mBuffer || mDestroyed) { + if (!mBuffer || !mBuffer->IsAttached() || mDestroyed) { return LayerRenderState(); } return mBuffer->GetRenderState(); @@ -91,10 +87,14 @@ void ThebesLayerComposite::RenderLayer(const nsIntPoint& aOffset, const nsIntRect& aClipRect) { - if (!mBuffer) { + if (!mBuffer || !mBuffer->IsAttached()) { return; } + MOZ_ASSERT(mBuffer->GetCompositor() == mCompositeManager->GetCompositor() && + mBuffer->GetLayer() == this, + "buffer is corrupted"); + gfx::Matrix4x4 transform; ToMatrix4x4(GetEffectiveTransform(), transform); gfx::Rect clipRect(aClipRect.x, aClipRect.y, aClipRect.width, aClipRect.height); @@ -144,14 +144,19 @@ ThebesLayerComposite::RenderLayer(const nsIntPoint& aOffset, } CompositableHost* -ThebesLayerComposite::GetCompositableHost() { - return mBuffer.get(); +ThebesLayerComposite::GetCompositableHost() +{ + if (mBuffer->IsAttached()) { + return mBuffer.get(); + } + + return nullptr; } void ThebesLayerComposite::CleanupResources() { - if (mBuffer) { + if (mBuffer) { mBuffer->Detach(); } mBuffer = nullptr; @@ -282,7 +287,7 @@ ThebesLayerComposite::PrintInfo(nsACString& aTo, const char* aPrefix) { ThebesLayer::PrintInfo(aTo, aPrefix); aTo += "\n"; - if (mBuffer) { + if (mBuffer && mBuffer->IsAttached()) { nsAutoCString pfx(aPrefix); pfx += " "; mBuffer->PrintInfo(aTo, pfx.get());