Bug 1418791 - Explicit free the resource of PersistentBufferProviderBasic, r=sotaro
authorpeter chang <pchang@mozilla.com>
Thu, 23 Nov 2017 16:31:55 +0800
changeset 393530 4fc4a6a0520b5d48891a5b182ae1441206c0a1a2
parent 393529 6cd9206792f9f0cdb4828fba6d6f9dd0745d550b
child 393531 2255f156d675ef5725afd12d53476a66e390a046
push id55957
push userpchang@mozilla.com
push dateFri, 24 Nov 2017 06:25:59 +0000
treeherderautoland@4fc4a6a0520b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssotaro
bugs1418791
milestone59.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 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;
 };