From 67c80db4e7bb7cf654ad9d4afffc62622e08a75e Mon Sep 17 00:00:00 2001 From: Andrew Osmond Date: Thu, 18 May 2017 06:50:03 -0400 Subject: [PATCH] Bug 1363347 - Allow multiple external image IDs to be bound to the same image host if owned by the same WRBridge. r=sotaro --- gfx/layers/wr/WebRenderBridgeParent.cpp | 4 ++-- gfx/layers/wr/WebRenderImageHost.cpp | 20 +++++++++++++++++++- gfx/layers/wr/WebRenderImageHost.h | 4 ++++ 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/gfx/layers/wr/WebRenderBridgeParent.cpp b/gfx/layers/wr/WebRenderBridgeParent.cpp index 528b701f7c60..ffdae5171fa2 100644 --- a/gfx/layers/wr/WebRenderBridgeParent.cpp +++ b/gfx/layers/wr/WebRenderBridgeParent.cpp @@ -661,7 +661,7 @@ WebRenderBridgeParent::RecvRemoveExternalImageId(const ExternalImageId& aImageId MOZ_ASSERT(mExternalImageIds.Get(wr::AsUint64(aImageId)).get()); WebRenderImageHost* wrHost = mExternalImageIds.Get(wr::AsUint64(aImageId)).get(); if (wrHost) { - wrHost->SetWrBridge(nullptr); + wrHost->ClearWrBridge(); } mExternalImageIds.Remove(wr::AsUint64(aImageId)); @@ -875,7 +875,7 @@ WebRenderBridgeParent::ClearResources() } DeleteOldImages(); for (auto iter = mExternalImageIds.Iter(); !iter.Done(); iter.Next()) { - iter.Data()->SetWrBridge(nullptr); + iter.Data()->ClearWrBridge(); } mExternalImageIds.Clear(); mCompositableHolder->RemovePipeline(mPipelineId, wr::NewEpoch(mWrEpoch)); diff --git a/gfx/layers/wr/WebRenderImageHost.cpp b/gfx/layers/wr/WebRenderImageHost.cpp index a2c0ace5a7bc..86c66edfdd59 100644 --- a/gfx/layers/wr/WebRenderImageHost.cpp +++ b/gfx/layers/wr/WebRenderImageHost.cpp @@ -28,6 +28,7 @@ WebRenderImageHost::WebRenderImageHost(const TextureInfo& aTextureInfo) : CompositableHost(aTextureInfo) , ImageComposite() , mWrBridge(nullptr) + , mWrBridgeBindings(0) {} WebRenderImageHost::~WebRenderImageHost() @@ -279,8 +280,25 @@ WebRenderImageHost::GetImageSize() const void WebRenderImageHost::SetWrBridge(WebRenderBridgeParent* aWrBridge) { - SetCurrentTextureHost(nullptr); + // For image hosts created through ImageBridgeParent, there may be multiple + // references to it due to the order of creation and freeing of layers by + // the layer tree. However this should be limited to things such as video + // which will not be reused across different WebRenderBridgeParent objects. + MOZ_ASSERT(aWrBridge); + MOZ_ASSERT(!mWrBridge || mWrBridge == aWrBridge); mWrBridge = aWrBridge; + ++mWrBridgeBindings; +} + +void +WebRenderImageHost::ClearWrBridge() +{ + MOZ_ASSERT(mWrBridgeBindings > 0); + --mWrBridgeBindings; + if (mWrBridgeBindings == 0) { + SetCurrentTextureHost(nullptr); + mWrBridge = nullptr; + } } } // namespace layers diff --git a/gfx/layers/wr/WebRenderImageHost.h b/gfx/layers/wr/WebRenderImageHost.h index 3afa2aaf0d4b..04461d194d3c 100644 --- a/gfx/layers/wr/WebRenderImageHost.h +++ b/gfx/layers/wr/WebRenderImageHost.h @@ -71,6 +71,8 @@ public: void SetWrBridge(WebRenderBridgeParent* aWrBridge); + void ClearWrBridge(); + protected: // ImageComposite virtual TimeStamp GetCompositionTime() const override; @@ -79,6 +81,8 @@ protected: WebRenderBridgeParent* MOZ_NON_OWNING_REF mWrBridge; + uint32_t mWrBridgeBindings; + CompositableTextureHostRef mCurrentTextureHost; };