Bug 1443187 - Avoid crashing if a previously-uncomposited layer tree gets adopted. r?botond draft
authorKartikaya Gupta <kgupta@mozilla.com>
Wed, 07 Mar 2018 16:41:44 -0500
changeset 764536 22949d4ef4307c9dbeb4a686dc03990ae7c574b3
parent 764272 493e45400842b6ccfffb63b58b40b33a0b8154ab
push id101782
push userkgupta@mozilla.com
push dateWed, 07 Mar 2018 21:42:13 +0000
reviewersbotond
bugs1443187
milestone60.0a1
Bug 1443187 - Avoid crashing if a previously-uncomposited layer tree gets adopted. r?botond MozReview-Commit-ID: FZYwS7IwdKq
gfx/layers/apz/src/APZCTreeManager.cpp
gfx/layers/apz/src/APZSampler.cpp
gfx/layers/ipc/CompositorBridgeParent.cpp
--- a/gfx/layers/apz/src/APZCTreeManager.cpp
+++ b/gfx/layers/apz/src/APZCTreeManager.cpp
@@ -249,24 +249,25 @@ APZCTreeManager::~APZCTreeManager()
 }
 
 void
 APZCTreeManager::NotifyLayerTreeAdopted(uint64_t aLayersId,
                                         const RefPtr<APZCTreeManager>& aOldApzcTreeManager)
 {
   APZThreadUtils::AssertOnSamplerThread();
 
-  MOZ_ASSERT(aOldApzcTreeManager);
-  aOldApzcTreeManager->mFocusState.RemoveFocusTarget(aLayersId);
-  // While we could move the focus target information from the old APZC tree
-  // manager into this one, it's safer to not do that, as we'll probably have
-  // that information repopulated soon anyway (on the next layers update).
+  if (aOldApzcTreeManager) {
+    aOldApzcTreeManager->mFocusState.RemoveFocusTarget(aLayersId);
+    // While we could move the focus target information from the old APZC tree
+    // manager into this one, it's safer to not do that, as we'll probably have
+    // that information repopulated soon anyway (on the next layers update).
+  }
 
   UniquePtr<APZTestData> adoptedData;
-  { // scope lock for removal on oldApzcTreeManager
+  if (aOldApzcTreeManager) {
     MutexAutoLock lock(aOldApzcTreeManager->mTestDataLock);
     auto it = aOldApzcTreeManager->mTestData.find(aLayersId);
     if (it != aOldApzcTreeManager->mTestData.end()) {
       adoptedData = Move(it->second);
       aOldApzcTreeManager->mTestData.erase(it);
     }
   }
   if (adoptedData) {
--- a/gfx/layers/apz/src/APZSampler.cpp
+++ b/gfx/layers/apz/src/APZSampler.cpp
@@ -61,18 +61,17 @@ APZSampler::UpdateHitTestingTree(uint64_
       aOriginatingLayersId, aPaintSequenceNumber);
 }
 
 void
 APZSampler::NotifyLayerTreeAdopted(uint64_t aLayersId,
                                    const RefPtr<APZSampler>& aOldSampler)
 {
   MOZ_ASSERT(CompositorThreadHolder::IsInCompositorThread());
-  MOZ_ASSERT(aOldSampler);
-  mApz->NotifyLayerTreeAdopted(aLayersId, aOldSampler->mApz);
+  mApz->NotifyLayerTreeAdopted(aLayersId, aOldSampler ? aOldSampler->mApz : nullptr);
 }
 
 void
 APZSampler::NotifyLayerTreeRemoved(uint64_t aLayersId)
 {
   MOZ_ASSERT(CompositorThreadHolder::IsInCompositorThread());
   mApz->NotifyLayerTreeRemoved(aLayersId);
 }
--- a/gfx/layers/ipc/CompositorBridgeParent.cpp
+++ b/gfx/layers/ipc/CompositorBridgeParent.cpp
@@ -1738,20 +1738,25 @@ CompositorBridgeParent::RecvAdoptChild(c
       if (cpcp) {
         TimeStamp now = TimeStamp::Now();
         cpcp->DidCompositeLocked(child, now, now);
       }
     }
     parent = sIndirectLayerTrees[child].mApzcTreeManagerParent;
   }
 
-  // We don't support moving a child from a APZ-enabled compositor to a
-  // APZ-disabled compostior. The mOptions assertion above should already
-  // ensure this, since APZ-ness is one of the things in mOptions.
-  MOZ_ASSERT((oldApzSampler != nullptr) == (mApzSampler != nullptr));
+  if (oldApzSampler) {
+    // We don't support moving a child from an APZ-enabled compositor to a
+    // APZ-disabled compositor. The mOptions assertion above should already
+    // ensure this, since APZ-ness is one of the things in mOptions. Note
+    // however it is possible for mApzSampler to be non-null here with
+    // oldApzSampler null, because the child may not have been previously
+    // composited.
+    MOZ_ASSERT(mApzSampler);
+  }
   if (mApzSampler) {
     if (parent) {
       MOZ_ASSERT(mApzcTreeManager);
       parent->ChildAdopted(mApzcTreeManager);
     }
     mApzSampler->NotifyLayerTreeAdopted(child, oldApzSampler);
   }
   return IPC_OK();