Bug 1322474 - Implement ClearCachedResources() in WebRenderLayer r=nical?
authorSotaro Ikeda <sotaro.ikeda.g@gmail.com>
Thu, 08 Dec 2016 09:12:38 -0800
changeset 459872 ed2fa5b96829ae548df302f29920f47a39a80234
parent 459871 93e34dbcba38f666c211d20e91d7361125b29f1f
child 459873 73bdd29461aef3297b099ba25e8b317a18a0a4b9
push id41343
push userkgupta@mozilla.com
push dateThu, 12 Jan 2017 20:13:44 +0000
reviewersnical
bugs1322474
milestone53.0a1
Bug 1322474 - Implement ClearCachedResources() in WebRenderLayer r=nical?
gfx/layers/Layers.h
gfx/layers/client/ClientLayerManager.cpp
gfx/layers/client/ClientLayerManager.h
gfx/layers/wr/WebRenderImageLayer.cpp
gfx/layers/wr/WebRenderImageLayer.h
gfx/layers/wr/WebRenderLayerManager.cpp
gfx/layers/wr/WebRenderLayerManager.h
--- a/gfx/layers/Layers.h
+++ b/gfx/layers/Layers.h
@@ -1802,16 +1802,18 @@ public:
   // and can be used anytime.
   // A layer has an APZC at index aIndex only-if GetFrameMetrics(aIndex).IsScrollable();
   // attempting to get an APZC for a non-scrollable metrics will return null.
   // The aIndex for these functions must be less than GetScrollMetadataCount().
   void SetAsyncPanZoomController(uint32_t aIndex, AsyncPanZoomController *controller);
   AsyncPanZoomController* GetAsyncPanZoomController(uint32_t aIndex) const;
   // The ScrollMetadataChanged function is used internally to ensure the APZC array length
   // matches the frame metrics array length.
+
+  virtual void ClearCachedResources() {}
 private:
   void ScrollMetadataChanged();
 public:
 
   void ApplyPendingUpdatesForThisTransaction();
 
 #ifdef DEBUG
   void SetDebugColorIndex(uint32_t aIndex) { mDebugColorIndex = aIndex; }
--- a/gfx/layers/client/ClientLayerManager.cpp
+++ b/gfx/layers/client/ClientLayerManager.cpp
@@ -790,17 +790,17 @@ ClientLayerManager::HandleMemoryPressure
   if (GetCompositorBridgeChild()) {
     GetCompositorBridgeChild()->HandleMemoryPressure();
   }
 }
 
 void
 ClientLayerManager::ClearLayer(Layer* aLayer)
 {
-  ClientLayer::ToClientLayer(aLayer)->ClearCachedResources();
+  aLayer->ClearCachedResources();
   for (Layer* child = aLayer->GetFirstChild(); child;
        child = child->GetNextSibling()) {
     ClearLayer(child);
   }
 }
 
 void
 ClientLayerManager::HandleMemoryPressureLayer(Layer* aLayer)
--- a/gfx/layers/client/ClientLayerManager.h
+++ b/gfx/layers/client/ClientLayerManager.h
@@ -365,18 +365,16 @@ public:
     // This is an "emergency Disconnect()", called when the compositing
     // process has died.  |mShadow| and our Shmem buffers are
     // automatically managed by IPDL, so we don't need to explicitly
     // free them here (it's hard to get that right on emergency
     // shutdown anyway).
     mShadow = nullptr;
   }
 
-  virtual void ClearCachedResources() { }
-
   // Shrink memory usage.
   // Called when "memory-pressure" is observed.
   virtual void HandleMemoryPressure() { }
 
   virtual void RenderLayer() = 0;
   virtual void RenderLayerWithReadback(ReadbackProcessor *aReadback) { RenderLayer(); }
 
   virtual ClientPaintedLayer* AsThebes() { return nullptr; }
--- a/gfx/layers/wr/WebRenderImageLayer.cpp
+++ b/gfx/layers/wr/WebRenderImageLayer.cpp
@@ -42,16 +42,24 @@ WebRenderImageLayer::GetAsSourceSurface(
   RefPtr<gfx::SourceSurface> surface = image->GetAsSourceSurface();
   if (!surface || !surface->IsValid()) {
     return nullptr;
   }
   return surface.forget();
 }
 
 void
+WebRenderImageLayer::ClearCachedResources()
+{
+  if (mImageClient) {
+    mImageClient->ClearCachedResources();
+  }
+}
+
+void
 WebRenderImageLayer::RenderLayer()
 {
   RefPtr<gfx::SourceSurface> surface = GetAsSourceSurface();
   if (!surface) {
     return;
   }
 
   if (!mImageContainerForWR) {
--- a/gfx/layers/wr/WebRenderImageLayer.h
+++ b/gfx/layers/wr/WebRenderImageLayer.h
@@ -15,16 +15,18 @@ namespace layers {
 class ImageClient;
 
 class WebRenderImageLayer : public WebRenderLayer,
                             public ImageLayer {
 public:
   explicit WebRenderImageLayer(WebRenderLayerManager* aLayerManager);
 
   virtual already_AddRefed<gfx::SourceSurface> GetAsSourceSurface() override;
+
+  virtual void ClearCachedResources() override;
 protected:
   virtual ~WebRenderImageLayer();
 
   WebRenderLayerManager* Manager()
   {
     return static_cast<WebRenderLayerManager*>(mManager);
   }
 
--- a/gfx/layers/wr/WebRenderLayerManager.cpp
+++ b/gfx/layers/wr/WebRenderLayerManager.cpp
@@ -365,19 +365,34 @@ WebRenderLayerManager::DidComposite(uint
 
   // These observers fire whether or not we were in a transaction.
   for (size_t i = 0; i < mDidCompositeObservers.Length(); i++) {
     mDidCompositeObservers[i]->DidComposite();
   }
 }
 
 void
+WebRenderLayerManager::ClearLayer(Layer* aLayer)
+{
+  aLayer->ClearCachedResources();
+  for (Layer* child = aLayer->GetFirstChild(); child;
+       child = child->GetNextSibling()) {
+    ClearLayer(child);
+  }
+}
+
+void
 WebRenderLayerManager::ClearCachedResources(Layer* aSubtree)
 {
   WRBridge()->SendClearCachedResources();
+  if (aSubtree) {
+    ClearLayer(aSubtree);
+  } else if (mRoot) {
+    ClearLayer(mRoot);
+  }
 }
 
 void
 WebRenderLayerManager::UpdateTextureFactoryIdentifier(const TextureFactoryIdentifier& aNewIdentifier)
 {
   WRBridge()->IdentifyTextureHost(aNewIdentifier);
 }
 
--- a/gfx/layers/wr/WebRenderLayerManager.h
+++ b/gfx/layers/wr/WebRenderLayerManager.h
@@ -141,21 +141,23 @@ public:
   // adds an imagekey to a list of keys that will be discarded on the next
   // transaction or destruction
   void AddImageKeyForDiscard(WRImageKey);
   void DiscardImages();
 
   WebRenderBridgeChild* WRBridge() const { return mWRChild; }
 
 private:
- /**
-  * Take a snapshot of the parent context, and copy
-  * it into mTarget.
-  */
- void MakeSnapshotIfRequired(LayoutDeviceIntSize aSize);
+  /**
+   * Take a snapshot of the parent context, and copy
+   * it into mTarget.
+   */
+  void MakeSnapshotIfRequired(LayoutDeviceIntSize aSize);
+
+  void ClearLayer(Layer* aLayer);
 
 private:
   nsIWidget* MOZ_NON_OWNING_REF mWidget;
   std::vector<WRImageKey> mImageKeys;
 
   /* PaintedLayer callbacks; valid at the end of a transaciton,
    * while rendering */
   DrawPaintedLayerCallback mPaintedLayerCallback;