Bug 976766 - Clear layer's buffers when ClearCachedResources() r=nical
authorSotaro Ikeda <sikeda@mozilla.com>
Wed, 26 Feb 2014 13:41:17 -0800
changeset 171196 5dd6bbb01616c430ec259b692a4df4b613c5ad72
parent 171195 4e8a51fc68b02404681212a5f1d8fd5b9cfbfc62
child 171197 75f877dc06037c2527fac9d92fd53f9d95a27c44
push id270
push userpvanderbeken@mozilla.com
push dateThu, 06 Mar 2014 09:24:21 +0000
reviewersnical
bugs976766
milestone30.0a1
Bug 976766 - Clear layer's buffers when ClearCachedResources() r=nical
gfx/layers/client/CanvasClient.h
gfx/layers/client/ClientCanvasLayer.h
gfx/layers/client/ContentClient.h
--- a/gfx/layers/client/CanvasClient.h
+++ b/gfx/layers/client/CanvasClient.h
@@ -52,16 +52,18 @@ public:
   CanvasClient(CompositableForwarder* aFwd, TextureFlags aFlags)
     : CompositableClient(aFwd)
   {
     mTextureInfo.mTextureFlags = aFlags;
   }
 
   virtual ~CanvasClient() {}
 
+  virtual void Clear() {};
+
   virtual void Update(gfx::IntSize aSize, ClientCanvasLayer* aLayer) = 0;
 
   virtual void Updated() { }
 
 protected:
   TextureInfo mTextureInfo;
 };
 
@@ -75,16 +77,21 @@ public:
   {
   }
 
   TextureInfo GetTextureInfo() const
   {
     return TextureInfo(COMPOSITABLE_IMAGE);
   }
 
+  virtual void Clear() MOZ_OVERRIDE
+  {
+    mBuffer = nullptr;
+  }
+
   virtual void Update(gfx::IntSize aSize, ClientCanvasLayer* aLayer) MOZ_OVERRIDE;
 
   virtual bool AddTextureClient(TextureClient* aTexture) MOZ_OVERRIDE
   {
     MOZ_ASSERT((mTextureInfo.mTextureFlags & aTexture->GetFlags()) == mTextureInfo.mTextureFlags);
     return CompositableClient::AddTextureClient(aTexture);
   }
 
@@ -108,16 +115,21 @@ class CanvasClientSurfaceStream : public
 public:
   CanvasClientSurfaceStream(CompositableForwarder* aLayerForwarder, TextureFlags aFlags);
 
   TextureInfo GetTextureInfo() const
   {
     return TextureInfo(COMPOSITABLE_IMAGE);
   }
 
+  virtual void Clear() MOZ_OVERRIDE
+  {
+    mBuffer = nullptr;
+  }
+
   virtual void Update(gfx::IntSize aSize, ClientCanvasLayer* aLayer) MOZ_OVERRIDE;
 
   virtual void OnDetach() MOZ_OVERRIDE
   {
     mBuffer = nullptr;
   }
 
 private:
--- a/gfx/layers/client/ClientCanvasLayer.h
+++ b/gfx/layers/client/ClientCanvasLayer.h
@@ -51,16 +51,23 @@ public:
                  "Can only set properties in construction phase");
     CanvasLayer::SetVisibleRegion(aRegion);
   }
 
   virtual void Initialize(const Data& aData);
 
   virtual void RenderLayer();
 
+  virtual void ClearCachedResources()
+  {
+    if (mCanvasClient) {
+      mCanvasClient->Clear();
+    }
+  }
+
   virtual void FillSpecificAttributes(SpecificLayerAttributes& aAttrs)
   {
     aAttrs = CanvasLayerAttributes(mFilter, mBounds);
   }
 
   virtual Layer* AsLayer() { return this; }
   virtual ShadowableLayer* AsShadowableLayer() { return this; }
 
--- a/gfx/layers/client/ContentClient.h
+++ b/gfx/layers/client/ContentClient.h
@@ -201,17 +201,22 @@ public:
     , mIsNewBuffer(false)
     , mFrontAndBackBufferDiffer(false)
     , mSurfaceFormat(gfx::SurfaceFormat::B8G8R8A8)
   {}
 
   typedef RotatedContentBuffer::PaintState PaintState;
   typedef RotatedContentBuffer::ContentType ContentType;
 
-  virtual void Clear() { RotatedContentBuffer::Clear(); }
+  virtual void Clear()
+  {
+    RotatedContentBuffer::Clear();
+    mTextureClient = nullptr;
+    mTextureClientOnWhite = nullptr;
+  }
 
   virtual PaintState BeginPaintBuffer(ThebesLayer* aLayer,
                                       uint32_t aFlags) MOZ_OVERRIDE
   {
     return RotatedContentBuffer::BeginPaint(aLayer, aFlags);
   }
   virtual gfx::DrawTarget* BorrowDrawTargetForPainting(ThebesLayer* aLayer,
                                                        const PaintState& aPaintState) MOZ_OVERRIDE
@@ -419,16 +424,23 @@ class ContentClientDoubleBuffered : publ
 public:
   ContentClientDoubleBuffered(CompositableForwarder* aFwd)
     : ContentClientRemoteBuffer(aFwd)
   {
     mTextureInfo.mCompositableType = COMPOSITABLE_CONTENT_DOUBLE;
   }
   virtual ~ContentClientDoubleBuffered() {}
 
+  virtual void Clear() MOZ_OVERRIDE
+  {
+    ContentClientRemoteBuffer::Clear();
+    mFrontClient = nullptr;
+    mFrontClientOnWhite = nullptr;
+  }
+
   virtual void SwapBuffers(const nsIntRegion& aFrontUpdatedRegion) MOZ_OVERRIDE;
 
   virtual void PrepareFrame() MOZ_OVERRIDE;
 
   virtual void FinalizeFrame(const nsIntRegion& aRegionToDraw) MOZ_OVERRIDE;
 
 protected:
   virtual void CreateFrontBuffer(const nsIntRect& aBufferRect) MOZ_OVERRIDE;