Bug 1538736 - Make extra sure Compositables don't refer back to layers after reassignment. r=sotaro, a=pascalc DEVEDITION_67_0b15_BUILD1 DEVEDITION_67_0b15_RELEASE FENNEC_67_0b15_BUILD1 FIREFOX_67_0b15_BUILD1 FIREFOX_67_0b15_BUILD2 FIREFOX_67_0b15_RELEASE
authorNicolas Silva <nsilva@mozilla.com>
Fri, 19 Apr 2019 18:26:04 +0000
changeset 526409 2be09493d405efb2fa4661ee50796e5312ac4c95
parent 526408 ea1286c1f2bb5bec7b922e405091ae0763bdb732
child 526410 30992921bd19eae7adf34fbed815799c29733a65
push id2032
push userffxbld-merge
push dateMon, 13 May 2019 09:36:57 +0000
treeherdermozilla-release@455c1065dcbe [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssotaro, pascalc
bugs1538736
milestone67.0
Bug 1538736 - Make extra sure Compositables don't refer back to layers after reassignment. r=sotaro, a=pascalc 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; }