From cf0569e64ef6e968f755c8a6b4f448517911c699 Mon Sep 17 00:00:00 2001 From: Kartikaya Gupta Date: Wed, 28 Mar 2018 14:56:55 -0400 Subject: [PATCH] Bug 1447299 - Have the APZCTreeManagerParent store a reference to the APZSampler. r=botond MozReview-Commit-ID: BNhkhFAmYP8 --HG-- extra : rebase_source : 43ff9d5f74add3b8b8b0cf651d06a14d8ec82885 --- gfx/layers/apz/public/APZSampler.h | 2 ++ gfx/layers/apz/src/APZSampler.cpp | 6 ++++++ gfx/layers/ipc/APZCTreeManagerParent.cpp | 20 ++++++++++++++----- gfx/layers/ipc/APZCTreeManagerParent.h | 9 +++++++-- gfx/layers/ipc/CompositorBridgeParent.cpp | 10 ++++++---- .../CrossProcessCompositorBridgeParent.cpp | 6 ++++-- 6 files changed, 40 insertions(+), 13 deletions(-) diff --git a/gfx/layers/apz/public/APZSampler.h b/gfx/layers/apz/public/APZSampler.h index 03ccb0995b59..f06f3fadc511 100644 --- a/gfx/layers/apz/public/APZSampler.h +++ b/gfx/layers/apz/public/APZSampler.h @@ -43,6 +43,8 @@ class APZSampler { public: explicit APZSampler(const RefPtr& aApz); + bool HasTreeManager(const RefPtr& aApz); + void ClearTree(); void UpdateFocusState(LayersId aRootLayerTreeId, LayersId aOriginatingLayersId, diff --git a/gfx/layers/apz/src/APZSampler.cpp b/gfx/layers/apz/src/APZSampler.cpp index 07d8df14feab..7d5282504cff 100644 --- a/gfx/layers/apz/src/APZSampler.cpp +++ b/gfx/layers/apz/src/APZSampler.cpp @@ -28,6 +28,12 @@ APZSampler::~APZSampler() mApz->SetSampler(nullptr); } +bool +APZSampler::HasTreeManager(const RefPtr& aApz) +{ + return aApz.get() == mApz.get(); +} + void APZSampler::ClearTree() { diff --git a/gfx/layers/ipc/APZCTreeManagerParent.cpp b/gfx/layers/ipc/APZCTreeManagerParent.cpp index 015e0af84541..4aa528b4e391 100644 --- a/gfx/layers/ipc/APZCTreeManagerParent.cpp +++ b/gfx/layers/ipc/APZCTreeManagerParent.cpp @@ -7,16 +7,22 @@ #include "mozilla/layers/APZCTreeManagerParent.h" #include "apz/src/APZCTreeManager.h" +#include "mozilla/layers/APZSampler.h" #include "mozilla/layers/APZThreadUtils.h" namespace mozilla { namespace layers { -APZCTreeManagerParent::APZCTreeManagerParent(LayersId aLayersId, RefPtr aAPZCTreeManager) +APZCTreeManagerParent::APZCTreeManagerParent(LayersId aLayersId, + RefPtr aAPZCTreeManager, + RefPtr aAPZSampler) : mLayersId(aLayersId) - , mTreeManager(aAPZCTreeManager) + , mTreeManager(Move(aAPZCTreeManager)) + , mSampler(Move(aAPZSampler)) { - MOZ_ASSERT(aAPZCTreeManager != nullptr); + MOZ_ASSERT(mTreeManager != nullptr); + MOZ_ASSERT(mSampler != nullptr); + MOZ_ASSERT(mSampler->HasTreeManager(mTreeManager)); } APZCTreeManagerParent::~APZCTreeManagerParent() @@ -24,10 +30,14 @@ APZCTreeManagerParent::~APZCTreeManagerParent() } void -APZCTreeManagerParent::ChildAdopted(RefPtr aAPZCTreeManager) +APZCTreeManagerParent::ChildAdopted(RefPtr aAPZCTreeManager, + RefPtr aAPZSampler) { MOZ_ASSERT(aAPZCTreeManager != nullptr); - mTreeManager = aAPZCTreeManager; + MOZ_ASSERT(aAPZSampler != nullptr); + MOZ_ASSERT(aAPZSampler->HasTreeManager(aAPZCTreeManager)); + mTreeManager = Move(aAPZCTreeManager); + mSampler = Move(aAPZSampler); } mozilla::ipc::IPCResult diff --git a/gfx/layers/ipc/APZCTreeManagerParent.h b/gfx/layers/ipc/APZCTreeManagerParent.h index d263400373e2..6ce062c625fc 100644 --- a/gfx/layers/ipc/APZCTreeManagerParent.h +++ b/gfx/layers/ipc/APZCTreeManagerParent.h @@ -13,13 +13,16 @@ namespace mozilla { namespace layers { class APZCTreeManager; +class APZSampler; class APZCTreeManagerParent : public PAPZCTreeManagerParent { public: - explicit APZCTreeManagerParent(LayersId aLayersId, RefPtr aAPZCTreeManager); + APZCTreeManagerParent(LayersId aLayersId, + RefPtr aAPZCTreeManager, + RefPtr mAPZSampler); virtual ~APZCTreeManagerParent(); LayersId GetLayersId() const { return mLayersId; } @@ -28,7 +31,8 @@ public: * Called when the layer tree that this protocol is connected to * is adopted by another compositor, and we need to switch APZCTreeManagers. */ - void ChildAdopted(RefPtr aAPZCTreeManager); + void ChildAdopted(RefPtr aAPZCTreeManager, + RefPtr aAPZSampler); mozilla::ipc::IPCResult RecvSetKeyboardMap(const KeyboardMap& aKeyboardMap) override; @@ -84,6 +88,7 @@ public: private: LayersId mLayersId; RefPtr mTreeManager; + RefPtr mSampler; }; } // namespace layers diff --git a/gfx/layers/ipc/CompositorBridgeParent.cpp b/gfx/layers/ipc/CompositorBridgeParent.cpp index b1f7d7fb3c16..07a3f29da82d 100644 --- a/gfx/layers/ipc/CompositorBridgeParent.cpp +++ b/gfx/layers/ipc/CompositorBridgeParent.cpp @@ -1096,8 +1096,9 @@ CompositorBridgeParent::AllocPAPZCTreeManagerParent(const LayersId& aLayersId) MOZ_ASSERT(XRE_IsGPUProcess()); // We should only ever get this if APZ is enabled in this compositor. MOZ_ASSERT(mOptions.UseAPZ()); - // The mApzcTreeManager should have been created via RecvInitialize() + // The mApzcTreeManager and mApzSampler should have been created via RecvInitialize() MOZ_ASSERT(mApzcTreeManager); + MOZ_ASSERT(mApzSampler); // The main process should pass in 0 because we assume mRootLayerTreeID MOZ_ASSERT(!aLayersId.IsValid()); @@ -1105,7 +1106,7 @@ CompositorBridgeParent::AllocPAPZCTreeManagerParent(const LayersId& aLayersId) CompositorBridgeParent::LayerTreeState& state = sIndirectLayerTrees[mRootLayerTreeID]; MOZ_ASSERT(state.mParent.get() == this); MOZ_ASSERT(!state.mApzcTreeManagerParent); - state.mApzcTreeManagerParent = new APZCTreeManagerParent(mRootLayerTreeID, mApzcTreeManager); + state.mApzcTreeManagerParent = new APZCTreeManagerParent(mRootLayerTreeID, mApzcTreeManager, mApzSampler); return state.mApzcTreeManagerParent; } @@ -1124,8 +1125,9 @@ CompositorBridgeParent::AllocateAPZCTreeManagerParent(const MonitorAutoLock& aPr { MOZ_ASSERT(aState.mParent == this); MOZ_ASSERT(mApzcTreeManager); + MOZ_ASSERT(mApzSampler); MOZ_ASSERT(!aState.mApzcTreeManagerParent); - aState.mApzcTreeManagerParent = new APZCTreeManagerParent(aLayersId, mApzcTreeManager); + aState.mApzcTreeManagerParent = new APZCTreeManagerParent(aLayersId, mApzcTreeManager, mApzSampler); } PAPZParent* @@ -1727,7 +1729,7 @@ CompositorBridgeParent::RecvAdoptChild(const LayersId& child) if (mApzSampler) { if (parent) { MOZ_ASSERT(mApzcTreeManager); - parent->ChildAdopted(mApzcTreeManager); + parent->ChildAdopted(mApzcTreeManager, mApzSampler); } mApzSampler->NotifyLayerTreeAdopted(child, oldApzSampler); } diff --git a/gfx/layers/ipc/CrossProcessCompositorBridgeParent.cpp b/gfx/layers/ipc/CrossProcessCompositorBridgeParent.cpp index 9788c1aa3f69..e44068c71168 100644 --- a/gfx/layers/ipc/CrossProcessCompositorBridgeParent.cpp +++ b/gfx/layers/ipc/CrossProcessCompositorBridgeParent.cpp @@ -19,6 +19,7 @@ #include "mozilla/ipc/Transport.h" // for Transport #include "mozilla/layers/AnimationHelper.h" // for CompositorAnimationStorage #include "mozilla/layers/APZCTreeManagerParent.h" // for APZCTreeManagerParent +#include "mozilla/layers/APZSampler.h" // for APZSampler #include "mozilla/layers/AsyncCompositionManager.h" #include "mozilla/layers/CompositorOptions.h" #include "mozilla/layers/CompositorThread.h" @@ -133,8 +134,9 @@ CrossProcessCompositorBridgeParent::AllocPAPZCTreeManagerParent(const LayersId& // Note: we immediately call ClearTree since otherwise the APZCTM will // retain a reference to itself, through the checkerboard observer. RefPtr temp = new APZCTreeManager(LayersId{0}); - temp->ClearTree(); - return new APZCTreeManagerParent(aLayersId, temp); + RefPtr tempSampler = new APZSampler(temp); + tempSampler->ClearTree(); + return new APZCTreeManagerParent(aLayersId, temp, tempSampler); } state.mParent->AllocateAPZCTreeManagerParent(lock, aLayersId, state);