Bug 1503498 - Simplify ForwardingExternalImage handling in AsyncImagePipelineManager r=aosmond
authorsotaro <sotaro.ikeda.g@gmail.com>
Wed, 14 Nov 2018 11:40:31 +0900
changeset 502586 5dd599d4a437e3eef7ea9f3a95439fa1f1f4581f
parent 502585 d6eaed759f7d5359b82564f1998a6cce5e28e072
child 502587 93f58abf5d47c32c98db9ff98b7091e2805639b9
push id10290
push userffxbld-merge
push dateMon, 03 Dec 2018 16:23:23 +0000
treeherdermozilla-beta@700bed2445e6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersaosmond
bugs1503498
milestone65.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1503498 - Simplify ForwardingExternalImage handling in AsyncImagePipelineManager r=aosmond
gfx/layers/wr/AsyncImagePipelineManager.cpp
gfx/layers/wr/AsyncImagePipelineManager.h
--- a/gfx/layers/wr/AsyncImagePipelineManager.cpp
+++ b/gfx/layers/wr/AsyncImagePipelineManager.cpp
@@ -15,16 +15,23 @@
 #include "mozilla/layers/WebRenderTextureHost.h"
 #include "mozilla/webrender/RenderThread.h"
 #include "mozilla/webrender/WebRenderAPI.h"
 #include "mozilla/webrender/WebRenderTypes.h"
 
 namespace mozilla {
 namespace layers {
 
+AsyncImagePipelineManager::ForwardingExternalImage::~ForwardingExternalImage()
+{
+  DebugOnly<bool> released =
+    SharedSurfacesParent::Release(mImageId);
+    MOZ_ASSERT(released);
+}
+
 AsyncImagePipelineManager::AsyncImagePipeline::AsyncImagePipeline()
  : mInitialised(false)
  , mIsChanged(false)
  , mUseExternalImage(false)
  , mFilter(wr::ImageRendering::Auto)
  , mMixBlendMode(wr::MixBlendMode::Normal)
 {}
 
@@ -47,16 +54,17 @@ AsyncImagePipelineManager::~AsyncImagePi
   MOZ_COUNT_DTOR(AsyncImagePipelineManager);
 }
 
 void
 AsyncImagePipelineManager::Destroy()
 {
   MOZ_ASSERT(!mDestroyed);
   mApi = nullptr;
+  mPipelineTexturesHolders.Clear();
   mDestroyed = true;
 }
 
 void
 AsyncImagePipelineManager::SetWillGenerateFrame()
 {
   MOZ_ASSERT(CompositorThreadHolder::IsInCompositorThread());
 
@@ -535,17 +543,18 @@ AsyncImagePipelineManager::HoldExternalI
 
   PipelineTexturesHolder* holder = mPipelineTexturesHolders.Get(wr::AsUint64(aPipelineId));
   MOZ_ASSERT(holder);
   if (!holder) {
     SharedSurfacesParent::Release(aImageId);
     return;
   }
 
-  holder->mExternalImages.push(ForwardingExternalImage(aEpoch, aImageId));
+  auto image = MakeUnique<ForwardingExternalImage>(aEpoch, aImageId);
+  holder->mExternalImages.push(std::move(image));
 }
 
 void
 AsyncImagePipelineManager::NotifyPipelinesUpdated(const wr::WrPipelineInfo& aInfo, bool aRender)
 {
   // This is called on the render thread, so we just stash the data into
   // UpdatesQueue and process it later on the compositor thread.
   MOZ_ASSERT(wr::RenderThread::IsInRenderThread());
@@ -653,22 +662,19 @@ AsyncImagePipelineManager::ProcessPipeli
     }
     while (!holder->mTextureHostWrappers.empty()) {
       if (aEpoch <= holder->mTextureHostWrappers.front().mEpoch) {
         break;
       }
       holder->mTextureHostWrappers.pop();
     }
     while (!holder->mExternalImages.empty()) {
-      if (aEpoch <= holder->mExternalImages.front().mEpoch) {
+      if (aEpoch <= holder->mExternalImages.front()->mEpoch) {
         break;
       }
-      DebugOnly<bool> released =
-        SharedSurfacesParent::Release(holder->mExternalImages.front().mImageId);
-      MOZ_ASSERT(released);
       holder->mExternalImages.pop();
     }
   }
 }
 
 void
 AsyncImagePipelineManager::ProcessPipelineRemoved(const wr::PipelineId& aPipelineId, const uint64_t aUpdatesCount)
 {
@@ -678,24 +684,16 @@ AsyncImagePipelineManager::ProcessPipeli
   if (auto entry = mPipelineTexturesHolders.Lookup(wr::AsUint64(aPipelineId))) {
     PipelineTexturesHolder* holder = entry.Data();
     if (holder->mDestroyedEpoch.isSome()) {
       while (!holder->mTextureHosts.empty()) {
         // Need to extend holding TextureHost if it is direct bounded texture.
         HoldUntilNotUsedByGPU(holder->mTextureHosts.front().mTexture, aUpdatesCount);
         holder->mTextureHosts.pop();
       }
-      // Explicitly release all of the shared surfaces.
-      while (!holder->mExternalImages.empty()) {
-        DebugOnly<bool> released =
-          SharedSurfacesParent::Release(holder->mExternalImages.front().mImageId);
-        MOZ_ASSERT(released);
-        holder->mExternalImages.pop();
-      }
-
       // Remove Pipeline
       entry.Remove();
     }
     // If mDestroyedEpoch contains nothing it means we reused the same pipeline id (probably because
     // we moved the tab to another window). In this case we need to keep the holder.
   }
 }
 
--- a/gfx/layers/wr/AsyncImagePipelineManager.h
+++ b/gfx/layers/wr/AsyncImagePipelineManager.h
@@ -147,25 +147,26 @@ private:
     RefPtr<WebRenderTextureHostWrapper> mWrTextureWrapper;
   };
 
   struct ForwardingExternalImage {
     ForwardingExternalImage(const wr::Epoch& aEpoch, const wr::ExternalImageId& aImageId)
       : mEpoch(aEpoch)
       , mImageId(aImageId)
     {}
+    ~ForwardingExternalImage();
     wr::Epoch mEpoch;
     wr::ExternalImageId mImageId;
   };
 
   struct PipelineTexturesHolder {
     // Holds forwarding WebRenderTextureHosts.
     std::queue<ForwardingTextureHost> mTextureHosts;
     std::queue<ForwardingTextureHostWrapper> mTextureHostWrappers;
-    std::queue<ForwardingExternalImage> mExternalImages;
+    std::queue<UniquePtr<ForwardingExternalImage>> mExternalImages;
     Maybe<wr::Epoch> mDestroyedEpoch;
   };
 
   struct AsyncImagePipeline {
     AsyncImagePipeline();
     void Update(const LayoutDeviceRect& aScBounds,
                 const gfx::Matrix4x4& aScTransform,
                 const gfx::MaybeIntSize& aScaleToSize,