Bug 1447299 - Have the APZCTreeManagerParent store a reference to the APZSampler. r?botond draft
authorKartikaya Gupta <kgupta@mozilla.com>
Thu, 22 Mar 2018 16:35:23 -0400
changeset 771267 deb84fcbd209072b009aaa13f96d7e79cdea78c4
parent 771266 82138e76aa6e8e716e60886fe9fa9e0b6c588b7f
child 771268 71c22c316850825ad91c32f21c16c42dea9700f8
push id103646
push userkgupta@mozilla.com
push dateThu, 22 Mar 2018 21:38:36 +0000
reviewersbotond
bugs1447299
milestone61.0a1
Bug 1447299 - Have the APZCTreeManagerParent store a reference to the APZSampler. r?botond MozReview-Commit-ID: LAahjAK9BxT
gfx/layers/apz/public/APZSampler.h
gfx/layers/apz/src/APZSampler.cpp
gfx/layers/ipc/APZCTreeManagerParent.cpp
gfx/layers/ipc/APZCTreeManagerParent.h
gfx/layers/ipc/CompositorBridgeParent.cpp
gfx/layers/ipc/CrossProcessCompositorBridgeParent.cpp
--- a/gfx/layers/apz/public/APZSampler.h
+++ b/gfx/layers/apz/public/APZSampler.h
@@ -38,16 +38,18 @@ class WebRenderScrollData;
  * in the case where the two threads are not the same.
  */
 class APZSampler {
   NS_INLINE_DECL_THREADSAFE_REFCOUNTING(APZSampler)
 
 public:
   explicit APZSampler(const RefPtr<APZCTreeManager>& aApz);
 
+  bool HasTreeManager(const RefPtr<APZCTreeManager>& aApz);
+
   void ClearTree();
   void UpdateFocusState(uint64_t aRootLayerTreeId,
                         uint64_t aOriginatingLayersId,
                         const FocusTarget& aFocusTarget);
   void UpdateHitTestingTree(uint64_t aRootLayerTreeId,
                             Layer* aRoot,
                             bool aIsFirstPaint,
                             uint64_t aOriginatingLayersId,
--- a/gfx/layers/apz/src/APZSampler.cpp
+++ b/gfx/layers/apz/src/APZSampler.cpp
@@ -22,16 +22,22 @@ APZSampler::APZSampler(const RefPtr<APZC
   MOZ_ASSERT(aApz);
   mApz->SetSampler(this);
 }
 
 APZSampler::~APZSampler()
 {
 }
 
+bool
+APZSampler::HasTreeManager(const RefPtr<APZCTreeManager>& aApz)
+{
+  return aApz.get() == mApz.get();
+}
+
 void
 APZSampler::ClearTree()
 {
   MOZ_ASSERT(CompositorThreadHolder::IsInCompositorThread());
   mApz->ClearTree();
 }
 
 void
--- a/gfx/layers/ipc/APZCTreeManagerParent.cpp
+++ b/gfx/layers/ipc/APZCTreeManagerParent.cpp
@@ -2,37 +2,47 @@
 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #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(uint64_t aLayersId, RefPtr<APZCTreeManager> aAPZCTreeManager)
+APZCTreeManagerParent::APZCTreeManagerParent(uint64_t aLayersId,
+                                             RefPtr<APZCTreeManager> aAPZCTreeManager,
+                                             RefPtr<APZSampler> aAPZSampler)
   : mLayersId(aLayersId)
   , mTreeManager(aAPZCTreeManager)
+  , mSampler(aAPZSampler)
 {
   MOZ_ASSERT(aAPZCTreeManager != nullptr);
+  MOZ_ASSERT(aAPZSampler != nullptr);
+  MOZ_ASSERT(aAPZSampler->HasTreeManager(aAPZCTreeManager));
 }
 
 APZCTreeManagerParent::~APZCTreeManagerParent()
 {
 }
 
 void
-APZCTreeManagerParent::ChildAdopted(RefPtr<APZCTreeManager> aAPZCTreeManager)
+APZCTreeManagerParent::ChildAdopted(RefPtr<APZCTreeManager> aAPZCTreeManager,
+                                    RefPtr<APZSampler> aAPZSampler)
 {
   MOZ_ASSERT(aAPZCTreeManager != nullptr);
+  MOZ_ASSERT(aAPZSampler != nullptr);
+  MOZ_ASSERT(aAPZSampler->HasTreeManager(aAPZCTreeManager));
   mTreeManager = aAPZCTreeManager;
+  mSampler = aAPZSampler;
 }
 
 mozilla::ipc::IPCResult
 APZCTreeManagerParent::RecvSetKeyboardMap(const KeyboardMap& aKeyboardMap)
 {
   APZThreadUtils::RunOnControllerThread(NewRunnableMethod<KeyboardMap>(
     "layers::IAPZCTreeManager::SetKeyboardMap",
     mTreeManager,
--- a/gfx/layers/ipc/APZCTreeManagerParent.h
+++ b/gfx/layers/ipc/APZCTreeManagerParent.h
@@ -8,32 +8,36 @@
 #define mozilla_layers_APZCTreeManagerParent_h
 
 #include "mozilla/layers/PAPZCTreeManagerParent.h"
 
 namespace mozilla {
 namespace layers {
 
 class APZCTreeManager;
+class APZSampler;
 
 class APZCTreeManagerParent
     : public PAPZCTreeManagerParent
 {
 public:
 
-  explicit APZCTreeManagerParent(uint64_t aLayersId, RefPtr<APZCTreeManager> aAPZCTreeManager);
+  APZCTreeManagerParent(uint64_t aLayersId,
+                        RefPtr<APZCTreeManager> aAPZCTreeManager,
+                        RefPtr<APZSampler> mAPZSampler);
   virtual ~APZCTreeManagerParent();
 
   uint64_t LayersId() const { return mLayersId; }
 
   /**
    * 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<APZCTreeManager> aAPZCTreeManager);
+  void ChildAdopted(RefPtr<APZCTreeManager> aAPZCTreeManager,
+                    RefPtr<APZSampler> aAPZSampler);
 
   mozilla::ipc::IPCResult
   RecvSetKeyboardMap(const KeyboardMap& aKeyboardMap) override;
 
   mozilla::ipc::IPCResult
   RecvZoomToRect(
           const ScrollableLayerGuid& aGuid,
           const CSSRect& aRect,
@@ -79,14 +83,15 @@ public:
   RecvSetLongTapEnabled(const bool& aTapGestureEnabled) override;
 
   void
   ActorDestroy(ActorDestroyReason aWhy) override { }
 
 private:
   uint64_t mLayersId;
   RefPtr<APZCTreeManager> mTreeManager;
+  RefPtr<APZSampler> mSampler;
 };
 
 } // namespace layers
 } // namespace mozilla
 
 #endif // mozilla_layers_APZCTreeManagerParent_h
--- a/gfx/layers/ipc/CompositorBridgeParent.cpp
+++ b/gfx/layers/ipc/CompositorBridgeParent.cpp
@@ -1091,26 +1091,27 @@ CompositorBridgeParent::ForceComposeToTa
 
 PAPZCTreeManagerParent*
 CompositorBridgeParent::AllocPAPZCTreeManagerParent(const uint64_t& aLayersId)
 {
   // This should only ever get called in the GPU process.
   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 == 0);
 
   MonitorAutoLock lock(*sIndirectLayerTreesLock);
   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;
 }
 
 bool
 CompositorBridgeParent::DeallocPAPZCTreeManagerParent(PAPZCTreeManagerParent* aActor)
 {
   delete aActor;
@@ -1119,18 +1120,19 @@ CompositorBridgeParent::DeallocPAPZCTree
 
 void
 CompositorBridgeParent::AllocateAPZCTreeManagerParent(const MonitorAutoLock& aProofOfLayerTreeStateLock,
                                                       const uint64_t& aLayersId,
                                                       LayerTreeState& aState)
 {
   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*
 CompositorBridgeParent::AllocPAPZParent(const uint64_t& aLayersId)
 {
   // The main process should pass in 0 because we assume mRootLayerTreeID
   MOZ_ASSERT(aLayersId == 0);
 
@@ -1722,17 +1724,17 @@ CompositorBridgeParent::RecvAdoptChild(c
     // 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);
+      parent->ChildAdopted(mApzcTreeManager, mApzSampler);
     }
     mApzSampler->NotifyLayerTreeAdopted(child, oldApzSampler);
   }
   return IPC_OK();
 }
 
 PWebRenderBridgeParent*
 CompositorBridgeParent::AllocPWebRenderBridgeParent(const wr::PipelineId& aPipelineId,
--- a/gfx/layers/ipc/CrossProcessCompositorBridgeParent.cpp
+++ b/gfx/layers/ipc/CrossProcessCompositorBridgeParent.cpp
@@ -14,16 +14,17 @@
 #include "base/task.h"                  // for CancelableTask, etc
 #include "base/thread.h"                // for Thread
 #ifdef XP_WIN
 #include "mozilla/gfx/DeviceManagerDx.h" // for DeviceManagerDx
 #endif
 #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"
 #include "mozilla/layers/LayerManagerComposite.h"
 #include "mozilla/layers/LayerTreeOwnerTracker.h"
 #include "mozilla/layers/PLayerTransactionParent.h"
 #include "mozilla/layers/RemoteContentController.h"
 #include "mozilla/layers/WebRenderBridgeParent.h"
@@ -128,18 +129,19 @@ CrossProcessCompositorBridgeParent::Allo
 
   // If the widget has shutdown its compositor, we may not have had a chance yet
   // to unmap our layers id, and we could get here without a parent compositor.
   // In this case return an empty APZCTM.
   if (!state.mParent) {
     // Note: we immediately call ClearTree since otherwise the APZCTM will
     // retain a reference to itself, through the checkerboard observer.
     RefPtr<APZCTreeManager> temp = new APZCTreeManager(0);
-    temp->ClearTree();
-    return new APZCTreeManagerParent(aLayersId, temp);
+    RefPtr<APZSampler> tempSampler = new APZSampler(temp);
+    tempSampler->ClearTree();
+    return new APZCTreeManagerParent(aLayersId, temp, tempSampler);
   }
 
   state.mParent->AllocateAPZCTreeManagerParent(lock, aLayersId, state);
   return state.mApzcTreeManagerParent;
 }
 bool
 CrossProcessCompositorBridgeParent::DeallocPAPZCTreeManagerParent(PAPZCTreeManagerParent* aActor)
 {