diff --git a/gfx/layers/ipc/CompositorParent.cpp b/gfx/layers/ipc/CompositorParent.cpp index b1b4b4c30bb5..5877d1b76f52 100644 --- a/gfx/layers/ipc/CompositorParent.cpp +++ b/gfx/layers/ipc/CompositorParent.cpp @@ -1015,6 +1015,9 @@ EraseLayerState(uint64_t aId) CompositorParent::DeallocateLayerTreeId(uint64_t aId) { MOZ_ASSERT(NS_IsMainThread()); + // Here main thread notifies compositor to remove an element from + // sIndirectLayerTrees. This removed element might be queried soon. + // Checking the elements of sIndirectLayerTrees exist or not before using. CompositorLoop()->PostTask(FROM_HERE, NewRunnableFunction(&EraseLayerState, aId)); } @@ -1236,9 +1239,15 @@ CrossProcessCompositorParent::AllocPLayerTransactionParent(const nsTArraysecond; + } + + if (state && state->mLayerManager) { + state->mCrossProcessParent = this; + LayerManagerComposite* lm = state->mLayerManager; *aTextureFactoryIdentifier = lm->GetCompositor()->GetTextureFactoryIdentifier(); *aSuccess = true; LayerTransactionParent* p = new LayerTransactionParent(lm, this, aId); @@ -1267,7 +1276,13 @@ CrossProcessCompositorParent::DeallocPLayerTransactionParent(PLayerTransactionPa bool CrossProcessCompositorParent::RecvNotifyChildCreated(const uint64_t& child) { - sIndirectLayerTrees[child].mParent->NotifyChildCreated(child); + const CompositorParent::LayerTreeState* state = CompositorParent::GetIndirectShadowTree(child); + if (!state) { + return false; + } + + MOZ_ASSERT(state->mParent); + state->mParent->NotifyChildCreated(child); return true; } @@ -1281,9 +1296,13 @@ CrossProcessCompositorParent::ShadowLayersUpdated( uint64_t id = aLayerTree->GetId(); MOZ_ASSERT(id != 0); - MOZ_ASSERT(sIndirectLayerTrees[id].mParent); - sIndirectLayerTrees[id].mParent->ScheduleRotationOnCompositorThread(aTargetConfig, aIsFirstPaint); + const CompositorParent::LayerTreeState* state = CompositorParent::GetIndirectShadowTree(id); + if (!state) { + return; + } + MOZ_ASSERT(state->mParent); + state->mParent->ScheduleRotationOnCompositorThread(aTargetConfig, aIsFirstPaint); Layer* shadowRoot = aLayerTree->GetRoot(); if (shadowRoot) { @@ -1291,7 +1310,7 @@ CrossProcessCompositorParent::ShadowLayersUpdated( } UpdateIndirectTree(id, shadowRoot, aTargetConfig); - sIndirectLayerTrees[id].mParent->NotifyShadowTreeTransaction(id, aIsFirstPaint, aScheduleComposite); + state->mParent->NotifyShadowTreeTransaction(id, aIsFirstPaint, aScheduleComposite); } void @@ -1308,7 +1327,13 @@ CrossProcessCompositorParent::SetTestSampleTime( { uint64_t id = aLayerTree->GetId(); MOZ_ASSERT(id != 0); - return sIndirectLayerTrees[id].mParent->SetTestSampleTime(aLayerTree, aTime); + const CompositorParent::LayerTreeState* state = CompositorParent::GetIndirectShadowTree(id); + if (!state) { + return false; + } + + MOZ_ASSERT(state->mParent); + return state->mParent->SetTestSampleTime(aLayerTree, aTime); } void @@ -1316,14 +1341,26 @@ CrossProcessCompositorParent::LeaveTestMode(LayerTransactionParent* aLayerTree) { uint64_t id = aLayerTree->GetId(); MOZ_ASSERT(id != 0); - sIndirectLayerTrees[id].mParent->LeaveTestMode(aLayerTree); + const CompositorParent::LayerTreeState* state = CompositorParent::GetIndirectShadowTree(id); + if (!state) { + return; + } + + MOZ_ASSERT(state->mParent); + state->mParent->LeaveTestMode(aLayerTree); } AsyncCompositionManager* CrossProcessCompositorParent::GetCompositionManager(LayerTransactionParent* aLayerTree) { uint64_t id = aLayerTree->GetId(); - return sIndirectLayerTrees[id].mParent->GetCompositionManager(aLayerTree); + const CompositorParent::LayerTreeState* state = CompositorParent::GetIndirectShadowTree(id); + if (!state) { + return nullptr; + } + + MOZ_ASSERT(state->mParent); + return state->mParent->GetCompositionManager(aLayerTree); } void