Bug 1538736 - Make extra sure Compositables don't refer back to layers after reassignment. r=sotaro
authorNicolas Silva <nsilva@mozilla.com>
Fri, 19 Apr 2019 18:26:04 +0000
changeset 470353 d3b41d3190e54ded4fb5c3894042e4d067865c82
parent 470352 32e046bfdeab2df91e89a584c718346c1a09712c
child 470354 47d1596a579ff86f45311cb5eb25e18b99b14b78
push id35903
push useropoprus@mozilla.com
push dateMon, 22 Apr 2019 21:46:44 +0000
treeherdermozilla-central@a11bd690638f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssotaro
bugs1538736
milestone68.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 1538736 - Make extra sure Compositables don't refer back to layers after reassignment. r=sotaro Differential Revision: https://phabricator.services.mozilla.com/D27930
gfx/layers/composite/CanvasLayerComposite.cpp
gfx/layers/composite/ImageLayerComposite.cpp
gfx/layers/composite/PaintedLayerComposite.cpp
gfx/layers/mlgpu/PaintedLayerMLGPU.cpp
--- a/gfx/layers/composite/CanvasLayerComposite.cpp
+++ b/gfx/layers/composite/CanvasLayerComposite.cpp
@@ -35,19 +35,23 @@ CanvasLayerComposite::CanvasLayerComposi
 CanvasLayerComposite::~CanvasLayerComposite() {
   MOZ_COUNT_DTOR(CanvasLayerComposite);
 
   CleanupResources();
 }
 
 bool CanvasLayerComposite::SetCompositableHost(CompositableHost* aHost) {
   switch (aHost->GetType()) {
-    case CompositableType::IMAGE:
+    case CompositableType::IMAGE: {
+      if (mCompositableHost && aHost != mCompositableHost) {
+        mCompositableHost->Detach(this);
+      }
       mCompositableHost = aHost;
       return true;
+    }
     default:
       return false;
   }
 }
 
 Layer* CanvasLayerComposite::GetLayer() { return this; }
 
 void CanvasLayerComposite::SetLayerManager(HostLayerManager* aManager) {
--- a/gfx/layers/composite/ImageLayerComposite.cpp
+++ b/gfx/layers/composite/ImageLayerComposite.cpp
@@ -42,19 +42,24 @@ ImageLayerComposite::~ImageLayerComposit
   MOZ_COUNT_DTOR(ImageLayerComposite);
   MOZ_ASSERT(mDestroyed);
 
   CleanupResources();
 }
 
 bool ImageLayerComposite::SetCompositableHost(CompositableHost* aHost) {
   switch (aHost->GetType()) {
-    case CompositableType::IMAGE:
-      mImageHost = static_cast<ImageHost*>(aHost);
+    case CompositableType::IMAGE: {
+      ImageHost* newImageHost = static_cast<ImageHost*>(aHost);
+      if (mImageHost && newImageHost != mImageHost) {
+        mImageHost->Detach(this);
+      }
+      mImageHost = newImageHost;
       return true;
+    }
     default:
       return false;
   }
 }
 
 void ImageLayerComposite::Disconnect() { Destroy(); }
 
 Layer* ImageLayerComposite::GetLayer() { return this; }
--- a/gfx/layers/composite/PaintedLayerComposite.cpp
+++ b/gfx/layers/composite/PaintedLayerComposite.cpp
@@ -42,19 +42,24 @@ PaintedLayerComposite::~PaintedLayerComp
   MOZ_COUNT_DTOR(PaintedLayerComposite);
   CleanupResources();
 }
 
 bool PaintedLayerComposite::SetCompositableHost(CompositableHost* aHost) {
   switch (aHost->GetType()) {
     case CompositableType::CONTENT_TILED:
     case CompositableType::CONTENT_SINGLE:
-    case CompositableType::CONTENT_DOUBLE:
-      mBuffer = static_cast<ContentHost*>(aHost);
+    case CompositableType::CONTENT_DOUBLE: {
+      ContentHost* newBuffer = static_cast<ContentHost*>(aHost);
+      if (mBuffer && newBuffer != mBuffer) {
+        mBuffer->Detach(this);
+      }
+      mBuffer = newBuffer;
       return true;
+    }
     default:
       return false;
   }
 }
 
 void PaintedLayerComposite::Disconnect() { Destroy(); }
 
 void PaintedLayerComposite::Destroy() {
--- a/gfx/layers/mlgpu/PaintedLayerMLGPU.cpp
+++ b/gfx/layers/mlgpu/PaintedLayerMLGPU.cpp
@@ -60,22 +60,26 @@ const LayerIntRegion& PaintedLayerMLGPU:
 #endif
   return mRenderRegion;
 }
 
 bool PaintedLayerMLGPU::SetCompositableHost(CompositableHost* aHost) {
   switch (aHost->GetType()) {
     case CompositableType::CONTENT_TILED:
     case CompositableType::CONTENT_SINGLE:
-    case CompositableType::CONTENT_DOUBLE:
+    case CompositableType::CONTENT_DOUBLE: {
+      if (mHost && mHost != aHost->AsContentHost()) {
+        mHost->Detach(this);
+      }
       mHost = aHost->AsContentHost();
       if (!mHost) {
         gfxWarning() << "ContentHostBase is not a ContentHostTexture";
       }
       return true;
+    }
     default:
       return false;
   }
 }
 
 CompositableHost* PaintedLayerMLGPU::GetCompositableHost() { return mHost; }
 
 gfx::Point PaintedLayerMLGPU::GetDestOrigin() const { return mDestOrigin; }