Bug 1418791 - Explicit free the resource of PersistentBufferProviderBasic, r=sotaro
authorpeter chang <pchang@mozilla.com>
Thu, 23 Nov 2017 16:31:55 +0800
changeset 438078 4fc4a6a0520b5d48891a5b182ae1441206c0a1a2
parent 438077 6cd9206792f9f0cdb4828fba6d6f9dd0745d550b
child 438079 2255f156d675ef5725afd12d53476a66e390a046
push id117
push userfmarier@mozilla.com
push dateTue, 28 Nov 2017 20:17:16 +0000
reviewerssotaro
bugs1418791
milestone59.0a1
Bug 1418791 - Explicit free the resource of PersistentBufferProviderBasic, r=sotaro MozReview-Commit-ID: JJXYkF5PR5K
gfx/layers/CopyableCanvasRenderer.cpp
gfx/layers/PersistentBufferProvider.cpp
gfx/layers/PersistentBufferProvider.h
--- a/gfx/layers/CopyableCanvasRenderer.cpp
+++ b/gfx/layers/CopyableCanvasRenderer.cpp
@@ -100,16 +100,17 @@ CopyableCanvasRenderer::ClearCachedResou
 
 void
 CopyableCanvasRenderer::Destroy()
 {
   if (mBufferProvider) {
     mBufferProvider->ClearCachedResources();
   }
 
+  mBufferProvider = nullptr;
   mCachedTempSurface = nullptr;
 }
 
 already_AddRefed<SourceSurface>
 CopyableCanvasRenderer::ReadbackSurface()
 {
   struct ScopedFireTransactionCallback {
     explicit ScopedFireTransactionCallback(CopyableCanvasRenderer* aRenderer)
--- a/gfx/layers/PersistentBufferProvider.cpp
+++ b/gfx/layers/PersistentBufferProvider.cpp
@@ -23,16 +23,17 @@ PersistentBufferProviderBasic::Persisten
 : mDrawTarget(aDt)
 {
   MOZ_COUNT_CTOR(PersistentBufferProviderBasic);
 }
 
 PersistentBufferProviderBasic::~PersistentBufferProviderBasic()
 {
   MOZ_COUNT_DTOR(PersistentBufferProviderBasic);
+  Destroy();
 }
 
 already_AddRefed<gfx::DrawTarget>
 PersistentBufferProviderBasic::BorrowDrawTarget(const gfx::IntRect& aPersistedRect)
 {
   MOZ_ASSERT(!mSnapshot);
   RefPtr<gfx::DrawTarget> dt(mDrawTarget);
   return dt.forget();
@@ -62,16 +63,23 @@ PersistentBufferProviderBasic::BorrowSna
 void
 PersistentBufferProviderBasic::ReturnSnapshot(already_AddRefed<gfx::SourceSurface> aSnapshot)
 {
   RefPtr<SourceSurface> snapshot = aSnapshot;
   MOZ_ASSERT(!snapshot || snapshot == mSnapshot);
   mSnapshot = nullptr;
 }
 
+void
+PersistentBufferProviderBasic::Destroy()
+{
+  mSnapshot = nullptr;
+  mDrawTarget = nullptr;
+}
+
 //static
 already_AddRefed<PersistentBufferProviderBasic>
 PersistentBufferProviderBasic::Create(gfx::IntSize aSize, gfx::SurfaceFormat aFormat,
                                       gfx::BackendType aBackend)
 {
   RefPtr<DrawTarget> dt = gfxPlatform::GetPlatform()->CreateDrawTargetForBackend(aBackend, aSize, aFormat);
 
   if (!dt) {
--- a/gfx/layers/PersistentBufferProvider.h
+++ b/gfx/layers/PersistentBufferProvider.h
@@ -97,16 +97,22 @@ public:
 
   virtual bool ReturnDrawTarget(already_AddRefed<gfx::DrawTarget> aDT) override;
 
   virtual already_AddRefed<gfx::SourceSurface> BorrowSnapshot() override;
 
   virtual void ReturnSnapshot(already_AddRefed<gfx::SourceSurface> aSnapshot) override;
 
   virtual bool PreservesDrawingState() const override { return true; }
+
+  virtual void OnShutdown() override { Destroy(); }
+
+protected:
+  void Destroy();
+
 private:
   ~PersistentBufferProviderBasic();
 
   RefPtr<gfx::DrawTarget> mDrawTarget;
   RefPtr<gfx::SourceSurface> mSnapshot;
 };