Bug 1289650 - Use PAPZCTreeManager in content process instead of PAPZ. r?kats draft
authorRyan Hunt <rhunt@mozilla.com>
Sun, 31 Jul 2016 12:39:00 -0700
changeset 404715 1cad201678a8f78fd95753154d86f8cf4984f668
parent 404714 8c0ed3ea37ba7ee91f16fea42bca4819b82f5d2e
child 404716 33a1f7476d96d2b09be71d1c776b1e3103c7967f
push id27272
push userbmo:rhunt@mozilla.com
push dateTue, 23 Aug 2016 22:55:33 +0000
reviewerskats
bugs1289650
milestone51.0a1
Bug 1289650 - Use PAPZCTreeManager in content process instead of PAPZ. r?kats MozReview-Commit-ID: LRhvZlNqli
dom/ipc/TabChild.cpp
dom/ipc/TabChild.h
gfx/layers/apz/public/GeckoContentController.h
gfx/layers/ipc/APZCTreeManagerParent.cpp
gfx/layers/ipc/APZCTreeManagerParent.h
gfx/layers/ipc/APZChild.cpp
gfx/layers/ipc/APZChild.h
gfx/layers/ipc/CompositorBridgeParent.cpp
gfx/layers/ipc/CompositorBridgeParent.h
gfx/layers/ipc/PAPZ.ipdl
gfx/layers/ipc/PAPZCTreeManager.ipdl
gfx/layers/ipc/RemoteContentController.cpp
gfx/layers/ipc/RemoteContentController.h
layout/base/nsLayoutUtils.cpp
layout/ipc/RenderFrameParent.h
--- a/dom/ipc/TabChild.cpp
+++ b/dom/ipc/TabChild.cpp
@@ -665,58 +665,59 @@ TabChild::Observe(nsISupports *aSubject,
   return NS_OK;
 }
 
 void
 TabChild::ContentReceivedInputBlock(const ScrollableLayerGuid& aGuid,
                                     uint64_t aInputBlockId,
                                     bool aPreventDefault) const
 {
-  if (mAPZChild) {
-    mAPZChild->SendContentReceivedInputBlock(aGuid, aInputBlockId,
-                                             aPreventDefault);
+  if (mApzcTreeManager) {
+    mApzcTreeManager->ContentReceivedInputBlock(aInputBlockId, aPreventDefault);
   }
 }
 
 void
 TabChild::SetTargetAPZC(uint64_t aInputBlockId,
                         const nsTArray<ScrollableLayerGuid>& aTargets) const
 {
-  if (mAPZChild) {
-    mAPZChild->SendSetTargetAPZC(aInputBlockId, aTargets);
+  if (mApzcTreeManager) {
+    mApzcTreeManager->SetTargetAPZC(aInputBlockId, aTargets);
   }
 }
 
 void
 TabChild::SetAllowedTouchBehavior(uint64_t aInputBlockId,
                                   const nsTArray<TouchBehaviorFlags>& aTargets) const
 {
-  if (mAPZChild) {
-    mAPZChild->SendSetAllowedTouchBehavior(aInputBlockId, aTargets);
+  if (mApzcTreeManager) {
+    mApzcTreeManager->SetAllowedTouchBehavior(aInputBlockId, aTargets);
   }
 }
 
 bool
 TabChild::DoUpdateZoomConstraints(const uint32_t& aPresShellId,
                                   const ViewID& aViewId,
                                   const Maybe<ZoomConstraints>& aConstraints)
 {
   if (sPreallocatedTab == this) {
     // If we're the preallocated tab, bail out because doing IPC will crash.
     // Once we get used for something we'll get another zoom constraints update
     // and all will be well.
     return true;
   }
 
-  if (!mAPZChild) {
+  if (!mApzcTreeManager) {
     return false;
   }
 
-  return mAPZChild->SendUpdateZoomConstraints(aPresShellId, aViewId,
-                                              aConstraints);
+  ScrollableLayerGuid guid = ScrollableLayerGuid(mLayersId, aPresShellId, aViewId);
+
+  mApzcTreeManager->UpdateZoomConstraints(guid, aConstraints);
+  return true;
 }
 
 nsresult
 TabChild::Init()
 {
   nsCOMPtr<nsIWebBrowser> webBrowser = do_CreateInstance(NS_WEBBROWSER_CONTRACTID);
   if (!webBrowser) {
     NS_ERROR("Couldn't create a nsWebBrowser?");
@@ -1699,20 +1700,20 @@ TabChild::HandleDoubleTap(const CSSPoint
   CSSRect zoomToRect = CalculateRectToZoomTo(document, aPoint);
   // The double-tap can be dispatched by any scroll frame (so |aGuid| could be
   // the guid of any scroll frame), but the zoom-to-rect operation must be
   // performed by the root content scroll frame, so query its identifiers
   // for the SendZoomToRect() call rather than using the ones from |aGuid|.
   uint32_t presShellId;
   ViewID viewId;
   if (APZCCallbackHelper::GetOrCreateScrollIdentifiers(
-      document->GetDocumentElement(), &presShellId, &viewId) &&
-      mAPZChild) {
-    mAPZChild->SendZoomToRect(presShellId, viewId, zoomToRect,
-                              DEFAULT_BEHAVIOR);
+      document->GetDocumentElement(), &presShellId, &viewId) && mApzcTreeManager) {
+    ScrollableLayerGuid guid(mLayersId, presShellId, viewId);
+
+    mApzcTreeManager->ZoomToRect(guid, zoomToRect, DEFAULT_BEHAVIOR);
   }
 }
 
 void
 TabChild::HandleTap(GeckoContentController::TapType aType,
                     const LayoutDevicePoint& aPoint, const Modifiers& aModifiers,
                     const ScrollableLayerGuid& aGuid, const uint64_t& aInputBlockId,
                     bool aCallTakeFocusForClickFromTap)
@@ -1771,29 +1772,34 @@ TabChild::NotifyAPZStateChange(const Vie
     observerService->NotifyObservers(nullptr, "APZ:TransformEnd", nullptr);
   }
   return true;
 }
 
 void
 TabChild::StartScrollbarDrag(const layers::AsyncDragMetrics& aDragMetrics)
 {
-  if (mAPZChild) {
-    mAPZChild->SendStartScrollbarDrag(aDragMetrics);
+  ScrollableLayerGuid guid(mLayersId, aDragMetrics.mPresShellId,
+                           aDragMetrics.mViewId);
+
+  if (mApzcTreeManager) {
+    mApzcTreeManager->StartScrollbarDrag(guid, aDragMetrics);
   }
 }
 
 void
 TabChild::ZoomToRect(const uint32_t& aPresShellId,
                      const FrameMetrics::ViewID& aViewId,
                      const CSSRect& aRect,
                      const uint32_t& aFlags)
 {
-  if (mAPZChild) {
-    mAPZChild->SendZoomToRect(aPresShellId, aViewId, aRect, aFlags);
+  ScrollableLayerGuid guid(mLayersId, aPresShellId, aViewId);
+
+  if (mApzcTreeManager) {
+    mApzcTreeManager->ZoomToRect(guid, aRect, aFlags);
   }
 }
 
 bool
 TabChild::RecvActivate()
 {
   nsCOMPtr<nsIWebBrowserFocus> browser = do_QueryInterface(WebNavigation());
   browser->Activate();
@@ -2747,16 +2753,18 @@ TabChild::InitRenderingState(const Textu
       if (!sTabChildren) {
         sTabChildren = new TabChildMap;
       }
       MOZ_ASSERT(!sTabChildren->Get(aLayersId));
       sTabChildren->Put(aLayersId, this);
       mLayersId = aLayersId;
     }
 
+    mApzcTreeManager = CompositorBridgeChild::Get()->GetAPZCTreeManager(mLayersId);
+
     nsCOMPtr<nsIObserverService> observerService =
         mozilla::services::GetObserverService();
 
     if (observerService) {
         observerService->AddObserver(this,
                                      BEFORE_FIRST_PAINT,
                                      false);
     }
--- a/dom/ipc/TabChild.h
+++ b/dom/ipc/TabChild.h
@@ -46,16 +46,17 @@ namespace mozilla {
 namespace layout {
 class RenderFrameChild;
 } // namespace layout
 
 namespace layers {
 class APZChild;
 class APZEventState;
 class AsyncDragMetrics;
+class IAPZCTreeManager;
 class ImageCompositeNotification;
 } // namespace layers
 
 namespace widget {
 struct AutoCacheNativeKeyCommands;
 } // namespace widget
 
 namespace plugins {
@@ -769,16 +770,17 @@ private:
   bool mParentIsActive;
   bool mAsyncPanZoomEnabled;
   CSSSize mUnscaledInnerSize;
   bool mDidSetRealShowInfo;
   bool mDidLoadURLInit;
 
   AutoTArray<bool, NUMBER_OF_AUDIO_CHANNELS> mAudioChannelsActive;
 
+  RefPtr<layers::IAPZCTreeManager> mApzcTreeManager;
   // APZChild clears this pointer from its destructor, so it shouldn't be a
   // dangling pointer.
   layers::APZChild* mAPZChild;
 
   DISALLOW_EVIL_CONSTRUCTORS(TabChild);
 };
 
 } // namespace dom
--- a/gfx/layers/apz/public/GeckoContentController.h
+++ b/gfx/layers/apz/public/GeckoContentController.h
@@ -138,17 +138,17 @@ public:
    */
   virtual void NotifyFlushComplete() = 0;
 
   virtual void UpdateOverscrollVelocity(float aX, float aY, bool aIsRootContent) {}
   virtual void UpdateOverscrollOffset(float aX, float aY, bool aIsRootContent) {}
   virtual void SetScrollingRootContent(bool isRootContent) {}
 
   GeckoContentController() {}
-  virtual void ChildAdopted() {}
+
   /**
    * Needs to be called on the main thread.
    */
   virtual void Destroy() {}
 
 protected:
   // Protected destructor, to discourage deletion outside of Release():
   virtual ~GeckoContentController() {}
--- a/gfx/layers/ipc/APZCTreeManagerParent.cpp
+++ b/gfx/layers/ipc/APZCTreeManagerParent.cpp
@@ -14,16 +14,23 @@ namespace layers {
 
 APZCTreeManagerParent::APZCTreeManagerParent(uint64_t aLayersId, RefPtr<APZCTreeManager> aAPZCTreeManager)
   : mLayersId(aLayersId)
   , mTreeManager(aAPZCTreeManager)
 {
   MOZ_ASSERT(aAPZCTreeManager != nullptr);
 }
 
+void
+APZCTreeManagerParent::ChildAdopted(RefPtr<APZCTreeManager> aAPZCTreeManager)
+{
+  MOZ_ASSERT(aAPZCTreeManager != nullptr);
+  mTreeManager = aAPZCTreeManager;
+}
+
 bool
 APZCTreeManagerParent::RecvReceiveMultiTouchInputEvent(
     const MultiTouchInput& aEvent,
     nsEventStatus* aOutStatus,
     MultiTouchInput* aOutEvent,
     ScrollableLayerGuid* aOutTargetGuid,
     uint64_t* aOutInputBlockId)
 {
@@ -149,34 +156,46 @@ APZCTreeManagerParent::RecvZoomToRect(
   return true;
 }
 
 bool
 APZCTreeManagerParent::RecvContentReceivedInputBlock(
     const uint64_t& aInputBlockId,
     const bool& aPreventDefault)
 {
-  mTreeManager->ContentReceivedInputBlock(aInputBlockId, aPreventDefault);
+  APZThreadUtils::RunOnControllerThread(
+    NewRunnableMethod<uint64_t, bool>(mTreeManager,
+      &IAPZCTreeManager::ContentReceivedInputBlock,
+      aInputBlockId,
+      aPreventDefault));
+
   return true;
 }
 
 bool
 APZCTreeManagerParent::RecvSetTargetAPZC(
     const uint64_t& aInputBlockId,
     nsTArray<ScrollableLayerGuid>&& aTargets)
 {
   for (size_t i = 0; i < aTargets.Length(); i++) {
     if (aTargets[i].mLayersId != mLayersId) {
       // Guard against bad data from hijacked child processes
       NS_ERROR("Unexpected layers id in RecvSetTargetAPZC; dropping message...");
       return false;
     }
   }
 
-  mTreeManager->SetTargetAPZC(aInputBlockId, aTargets);
+  void (IAPZCTreeManager::*setTargetApzcFunc)(uint64_t, const nsTArray<ScrollableLayerGuid>&)
+      = &IAPZCTreeManager::SetTargetAPZC;
+
+  APZThreadUtils::RunOnControllerThread(NewRunnableMethod
+                                        <uint64_t,
+                                         StoreCopyPassByRRef<nsTArray<ScrollableLayerGuid>>>
+                                        (mTreeManager, setTargetApzcFunc, aInputBlockId, aTargets));
+
   return true;
 }
 
 bool
 APZCTreeManagerParent::RecvUpdateZoomConstraints(
     const ScrollableLayerGuid& aGuid,
     const MaybeZoomConstraints& aConstraints)
 {
@@ -217,32 +236,43 @@ APZCTreeManagerParent::RecvSetDPI(const 
   return true;
 }
 
 bool
 APZCTreeManagerParent::RecvSetAllowedTouchBehavior(
     const uint64_t& aInputBlockId,
     nsTArray<TouchBehaviorFlags>&& aValues)
 {
-  mTreeManager->SetAllowedTouchBehavior(aInputBlockId, aValues);
+  APZThreadUtils::RunOnControllerThread(NewRunnableMethod
+                                        <uint64_t,
+                                         StoreCopyPassByRRef<nsTArray<TouchBehaviorFlags>>>
+                                        (mTreeManager,
+                                         &IAPZCTreeManager::SetAllowedTouchBehavior,
+                                         aInputBlockId, Move(aValues)));
+
   return true;
 }
 
 bool
 APZCTreeManagerParent::RecvStartScrollbarDrag(
     const ScrollableLayerGuid& aGuid,
     const AsyncDragMetrics& aDragMetrics)
 {
   if (aGuid.mLayersId != mLayersId) {
     // Guard against bad data from hijacked child processes
     NS_ERROR("Unexpected layers id in RecvStartScrollbarDrag; dropping message...");
     return false;
   }
 
-  mTreeManager->StartScrollbarDrag(aGuid, aDragMetrics);
+    APZThreadUtils::RunOnControllerThread(
+        NewRunnableMethod<ScrollableLayerGuid, AsyncDragMetrics>(
+          mTreeManager,
+          &IAPZCTreeManager::StartScrollbarDrag,
+          aGuid, aDragMetrics));
+
   return true;
 }
 
 bool
 APZCTreeManagerParent::RecvSetLongTapEnabled(const bool& aTapGestureEnabled)
 {
   mTreeManager->SetLongTapEnabled(aTapGestureEnabled);
   return true;
--- a/gfx/layers/ipc/APZCTreeManagerParent.h
+++ b/gfx/layers/ipc/APZCTreeManagerParent.h
@@ -17,16 +17,24 @@ class APZCTreeManager;
 class APZCTreeManagerParent
     : public PAPZCTreeManagerParent
 {
 public:
 
   explicit APZCTreeManagerParent(uint64_t aLayersId, RefPtr<APZCTreeManager> aAPZCTreeManager);
   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);
+
   bool
   RecvReceiveMultiTouchInputEvent(
           const MultiTouchInput& aEvent,
           nsEventStatus* aOutStatus,
           MultiTouchInput* aOutEvent,
           ScrollableLayerGuid* aOutTargetGuid,
           uint64_t* aOutInputBlockId) override;
 
--- a/gfx/layers/ipc/APZChild.cpp
+++ b/gfx/layers/ipc/APZChild.cpp
@@ -89,17 +89,17 @@ APZChild::~APZChild()
     nsCOMPtr<nsIObserverService> os = services::GetObserverService();
     os->RemoveObserver(mObserver, "tab-child-created");
   } else if (mBrowser) {
     mBrowser->SetAPZChild(nullptr);
   }
 }
 
 bool
-APZChild::RecvUpdateFrame(const FrameMetrics& aFrameMetrics)
+APZChild::RecvRequestContentRepaint(const FrameMetrics& aFrameMetrics)
 {
   return mBrowser->UpdateFrame(aFrameMetrics);
 }
 
 bool
 APZChild::RecvHandleTap(const TapType& aType,
                         const LayoutDevicePoint& aPoint,
                         const Modifiers& aModifiers,
--- a/gfx/layers/ipc/APZChild.h
+++ b/gfx/layers/ipc/APZChild.h
@@ -21,34 +21,34 @@ namespace layers {
 
 class APZChild final : public PAPZChild
 {
 public:
   static APZChild* Create(const dom::TabId& aTabId);
 
   ~APZChild();
 
-  virtual bool RecvUpdateFrame(const FrameMetrics& frame) override;
+  void SetBrowser(dom::TabChild* aBrowser);
 
-  virtual bool RecvHandleTap(const TapType& aType,
-                             const LayoutDevicePoint& aPoint,
-                             const Modifiers& aModifiers,
-                             const ScrollableLayerGuid& aGuid,
-                             const uint64_t& aInputBlockId,
-                             const bool& aCallTakeFocusForClickFromTap) override;
+  bool RecvRequestContentRepaint(const FrameMetrics& frame) override;
 
-  virtual bool RecvNotifyAPZStateChange(const ViewID& aViewId,
-                                        const APZStateChange& aChange,
-                                        const int& aArg) override;
+  bool RecvHandleTap(const TapType& aType,
+                     const LayoutDevicePoint& aPoint,
+                     const Modifiers& aModifiers,
+                     const ScrollableLayerGuid& aGuid,
+                     const uint64_t& aInputBlockId,
+                     const bool& aCallTakeFocusForClickFromTap) override;
 
-  virtual bool RecvNotifyFlushComplete() override;
+  bool RecvNotifyAPZStateChange(const ViewID& aViewId,
+                                const APZStateChange& aChange,
+                                const int& aArg) override;
 
-  virtual bool RecvDestroy() override;
+  bool RecvNotifyFlushComplete() override;
 
-  void SetBrowser(dom::TabChild* aBrowser);
+  bool RecvDestroy() override;
 
 private:
   APZChild();
 
   void SetObserver(nsIObserver* aObserver);
 
   RefPtr<dom::TabChild> mBrowser;
   RefPtr<nsIObserver> mObserver;
--- a/gfx/layers/ipc/CompositorBridgeParent.cpp
+++ b/gfx/layers/ipc/CompositorBridgeParent.cpp
@@ -99,17 +99,18 @@ namespace layers {
 using namespace mozilla::ipc;
 using namespace mozilla::gfx;
 using namespace std;
 
 using base::ProcessId;
 using base::Thread;
 
 CompositorBridgeParent::LayerTreeState::LayerTreeState()
-  : mParent(nullptr)
+  : mApzcTreeManagerParent(nullptr)
+  , mParent(nullptr)
   , mLayerManager(nullptr)
   , mCrossProcessParent(nullptr)
   , mLayerTree(nullptr)
   , mUpdatedPluginDataAvailable(false)
   , mPendingCompositorUpdates(0)
 {
 }
 
@@ -1788,34 +1789,31 @@ CompositorBridgeParent::UpdateRemoteCont
   }
   state.mController = controller;
   return true;
 }
 
 bool
 CompositorBridgeParent::RecvAdoptChild(const uint64_t& child)
 {
-  RefPtr<GeckoContentController> controller;
+  APZCTreeManagerParent* parent;
   {
     MonitorAutoLock lock(*sIndirectLayerTreesLock);
     NotifyChildCreated(child);
     if (sIndirectLayerTrees[child].mLayerTree) {
       sIndirectLayerTrees[child].mLayerTree->mLayerManager = mLayerManager;
     }
     if (sIndirectLayerTrees[child].mRoot) {
       sIndirectLayerTrees[child].mRoot->AsLayerComposite()->SetLayerManager(mLayerManager);
     }
-    controller = sIndirectLayerTrees[child].mController;
+    parent = sIndirectLayerTrees[child].mApzcTreeManagerParent;
   }
 
-  // Calling ChildAdopted on controller will acquire a lock, to avoid a
-  // potential deadlock between that lock and sIndirectLayerTreesLock we
-  // release sIndirectLayerTreesLock first before calling ChildAdopted.
-  if (mApzcTreeManager && controller) {
-    controller->ChildAdopted();
+  if (mApzcTreeManager && parent) {
+    parent->ChildAdopted(mApzcTreeManager);
   }
   return true;
 }
 
 static void
 EraseLayerState(uint64_t aId)
 {
   MonitorAutoLock lock(*sIndirectLayerTreesLock);
@@ -2528,24 +2526,37 @@ CrossProcessCompositorBridgeParent::Allo
   // Check to see if this child process has access to this layer tree.
   if (!LayerTreeOwnerTracker::Get()->IsMapped(aLayersId, OtherPid())) {
     NS_ERROR("Unexpected layers id in AllocPAPZCTreeManagerParent; dropping message...");
     return nullptr;
   }
 
   MonitorAutoLock lock(*sIndirectLayerTreesLock);
   CompositorBridgeParent::LayerTreeState& state = sIndirectLayerTrees[aLayersId];
-
   MOZ_ASSERT(state.mParent);
-  return new APZCTreeManagerParent(aLayersId, state.mParent->GetAPZCTreeManager());
+  MOZ_ASSERT(!state.mApzcTreeManagerParent);
+  state.mApzcTreeManagerParent = new APZCTreeManagerParent(aLayersId, state.mParent->GetAPZCTreeManager());
+
+  return state.mApzcTreeManagerParent;
 }
 bool
 CrossProcessCompositorBridgeParent::DeallocPAPZCTreeManagerParent(PAPZCTreeManagerParent* aActor)
 {
-  delete aActor;
+  APZCTreeManagerParent* parent = static_cast<APZCTreeManagerParent*>(aActor);
+
+  MonitorAutoLock lock(*sIndirectLayerTreesLock);
+  auto iter = sIndirectLayerTrees.find(parent->LayersId());
+  if (iter != sIndirectLayerTrees.end()) {
+    CompositorBridgeParent::LayerTreeState& state = iter->second;
+    MOZ_ASSERT(state.mApzcTreeManagerParent == parent);
+    state.mApzcTreeManagerParent = nullptr;
+  }
+
+  delete parent;
+
   return true;
 }
 
 bool
 CrossProcessCompositorBridgeParent::RecvNotifyChildCreated(const uint64_t& child)
 {
   MonitorAutoLock lock(*sIndirectLayerTreesLock);
   for (LayerTreeMap::iterator it = sIndirectLayerTrees.begin();
--- a/gfx/layers/ipc/CompositorBridgeParent.h
+++ b/gfx/layers/ipc/CompositorBridgeParent.h
@@ -53,16 +53,17 @@ class GPUParent;
 
 namespace ipc {
 class Shmem;
 } // namespace ipc
 
 namespace layers {
 
 class APZCTreeManager;
+class APZCTreeManagerParent;
 class AsyncCompositionManager;
 class Compositor;
 class CompositorBridgeParent;
 class LayerManagerComposite;
 class LayerTransactionParent;
 class PAPZParent;
 class CrossProcessCompositorBridgeParent;
 class CompositorThreadHolder;
@@ -424,16 +425,17 @@ public:
   static bool
   CreateForContent(Endpoint<PCompositorBridgeParent>&& aEndpoint);
 
   struct LayerTreeState {
     LayerTreeState();
     ~LayerTreeState();
     RefPtr<Layer> mRoot;
     RefPtr<GeckoContentController> mController;
+    APZCTreeManagerParent* mApzcTreeManagerParent;
     CompositorBridgeParent* mParent;
     LayerManagerComposite* mLayerManager;
     // Pointer to the CrossProcessCompositorBridgeParent. Used by APZCs to share
     // their FrameMetrics with the corresponding child process that holds
     // the PCompositorBridgeChild
     CrossProcessCompositorBridgeParent* mCrossProcessParent;
     TargetConfig mTargetConfig;
     APZTestData mApzTestData;
--- a/gfx/layers/ipc/PAPZ.ipdl
+++ b/gfx/layers/ipc/PAPZ.ipdl
@@ -37,72 +37,32 @@ namespace layers {
  *
  * Opened through PContent and runs on the main thread in both parent and child.
  */
 sync protocol PAPZ
 {
   manager PContent;
 
 parent:
+
   async UpdateHitRegion(nsRegion aRegion);
 
-  /**
-   * Instructs the TabParent to forward a request to zoom to a rect given in
-   * CSS pixels. This rect is relative to the document.
-   */
-  async ZoomToRect(uint32_t aPresShellId, ViewID aViewId, CSSRect aRect, uint32_t aFlags);
-
-  /**
-   * We know for sure that content has either preventDefaulted or not
-   * preventDefaulted. This applies to an entire batch of touch events. It is
-   * expected that, if there are any DOM touch listeners, touch events will be
-   * batched and only processed for panning and zooming if content does not
-   * preventDefault.
-   */
-  async ContentReceivedInputBlock(ScrollableLayerGuid aGuid, uint64_t aInputBlockId, bool aPreventDefault);
-
-  /**
-   * Notifies the APZ code of the results of the gecko hit-test for a
-   * particular input block. Each target corresponds to one touch point in the
-   * touch event.
-   */
-  async SetTargetAPZC(uint64_t aInputBlockId, ScrollableLayerGuid[] aTargets);
-
-  // Start an APZ drag on a scrollbar
-  async StartScrollbarDrag(AsyncDragMetrics aDragMetrics);
-
-  /**
-   * Notifies the APZ code of the allowed touch-behaviours for a particular
-   * input block. Each item in the aFlags array corresponds to one touch point
-   * in the touch event.
-   */
-  async SetAllowedTouchBehavior(uint64_t aInputBlockId, TouchBehaviorFlags[] aFlags);
-
-  /**
-   * Updates the zoom constraints for a scrollable frame in this tab.
-   * The zoom controller code lives on the parent side and so this allows it to
-   * have up-to-date zoom constraints.
-   */
-  async UpdateZoomConstraints(uint32_t aPresShellId, ViewID aViewId,
-                              MaybeZoomConstraints aConstraints);
-
   async __delete__();
 
 child:
-  async UpdateFrame(FrameMetrics frame);
+  async RequestContentRepaint(FrameMetrics frame);
 
-  // The following methods correspond to functions on the GeckoContentController
-  // interface in gfx/layers/apz/public/GeckoContentController.h. Refer to documentation
-  // in that file for these functions.
   // The aCallTakeFocusForClickFromTap argument is used for eSingleTap types,
   // to request that the child take focus before dispatching the mouse events
   // for the tap (otherwise the resulting focus behaviour is incorrect).
   async HandleTap(TapType aType, LayoutDevicePoint point, Modifiers aModifiers,
                   ScrollableLayerGuid aGuid, uint64_t aInputBlockId,
                   bool aCallTakeFocusForClickFromTap);
+
   async NotifyAPZStateChange(ViewID aViewId, APZStateChange aChange, int aArg);
+
   async NotifyFlushComplete();
 
   async Destroy();
 };
 
 } // layers
 } // mozilla
--- a/gfx/layers/ipc/PAPZCTreeManager.ipdl
+++ b/gfx/layers/ipc/PAPZCTreeManager.ipdl
@@ -35,16 +35,44 @@ namespace mozilla {
 namespace layers {
 
 sync protocol PAPZCTreeManager
 {
 manager PCompositorBridge;
 
 parent:
 
+  // These messages correspond to the methods
+  // on the IAPZCTreeManager interface
+
+  async ZoomToRect(ScrollableLayerGuid aGuid, CSSRect aRect, uint32_t Flags);
+
+  async ContentReceivedInputBlock(uint64_t aInputBlockId, bool PreventDefault);
+
+  async SetTargetAPZC(uint64_t aInputBlockId, ScrollableLayerGuid[] Targets);
+
+  async UpdateZoomConstraints(ScrollableLayerGuid aGuid, MaybeZoomConstraints aConstraints);
+
+  async CancelAnimation(ScrollableLayerGuid aGuid);
+
+  async AdjustScrollForSurfaceShift(ScreenPoint aShift);
+
+  async SetDPI(float aDpiValue);
+
+  async SetAllowedTouchBehavior(uint64_t aInputBlockId, TouchBehaviorFlags[] aValues);
+
+  async StartScrollbarDrag(ScrollableLayerGuid aGuid, AsyncDragMetrics aDragMetrics);
+
+  async SetLongTapEnabled(bool aTapGestureEnabled);
+
+  async ProcessTouchVelocity(uint32_t aTimestampMs, float aSpeedY);
+
+  // The following messages are used to
+  // implement the ReceiveInputEvent methods
+
   sync ReceiveMultiTouchInputEvent(MultiTouchInput aEvent)
     returns (nsEventStatus       aOutStatus,
              MultiTouchInput     aOutEvent,
              ScrollableLayerGuid aOutTargetGuid,
              uint64_t            aOutInputBlockId);
 
   sync ReceiveMouseInputEvent(MouseInput aEvent)
     returns (nsEventStatus       aOutStatus,
@@ -71,38 +99,16 @@ parent:
              uint64_t            aOutInputBlockId);
 
   sync ReceiveScrollWheelInputEvent(ScrollWheelInput aEvent)
     returns (nsEventStatus       aOutStatus,
              ScrollWheelInput    aOutEvent,
              ScrollableLayerGuid aOutTargetGuid,
              uint64_t            aOutInputBlockId);
 
-  async ZoomToRect(ScrollableLayerGuid aGuid, CSSRect aRect, uint32_t Flags);
-
-  async ContentReceivedInputBlock(uint64_t aInputBlockId, bool PreventDefault);
-
-  async SetTargetAPZC(uint64_t aInputBlockId, ScrollableLayerGuid[] Targets);
-
-  async UpdateZoomConstraints(ScrollableLayerGuid aGuid, MaybeZoomConstraints aConstraints);
-
-  async CancelAnimation(ScrollableLayerGuid aGuid);
-
-  async AdjustScrollForSurfaceShift(ScreenPoint aShift);
-
-  async SetDPI(float aDpiValue);
-
-  async SetAllowedTouchBehavior(uint64_t aInputBlockId, TouchBehaviorFlags[] aValues);
-
-  async StartScrollbarDrag(ScrollableLayerGuid aGuid, AsyncDragMetrics aDragMetrics);
-
-  async SetLongTapEnabled(bool aTapGestureEnabled);
-
-  async ProcessTouchVelocity(uint32_t aTimestampMs, float aSpeedY);
-
   async UpdateWheelTransaction(LayoutDeviceIntPoint aRefPoint, EventMessage aEventMessage);
 
   sync TransformEventRefPoint(LayoutDeviceIntPoint aRefPoint)
     returns (LayoutDeviceIntPoint   aOutRefPoint,
              ScrollableLayerGuid    aOutTargetGuid);
 
   async __delete__();
 };
--- a/gfx/layers/ipc/RemoteContentController.cpp
+++ b/gfx/layers/ipc/RemoteContentController.cpp
@@ -7,17 +7,16 @@
 
 #include "mozilla/layers/RemoteContentController.h"
 
 #include "base/message_loop.h"
 #include "base/task.h"
 #include "MainThreadUtils.h"
 #include "mozilla/dom/ContentParent.h"
 #include "mozilla/dom/TabParent.h"
-#include "mozilla/layers/IAPZCTreeManager.h"
 #include "mozilla/layers/APZThreadUtils.h"
 #include "mozilla/layout/RenderFrameParent.h"
 #include "mozilla/gfx/GPUProcessManager.h"
 #include "mozilla/unused.h"
 #include "Units.h"
 #ifdef MOZ_WIDGET_ANDROID
 #include "AndroidBridge.h"
 #endif
@@ -43,17 +42,17 @@ RemoteContentController::~RemoteContentC
 {
 }
 
 void
 RemoteContentController::RequestContentRepaint(const FrameMetrics& aFrameMetrics)
 {
   MOZ_ASSERT(NS_IsMainThread());
   if (CanSend()) {
-    Unused << SendUpdateFrame(aFrameMetrics);
+    Unused << SendRequestContentRepaint(aFrameMetrics);
   }
 }
 
 void
 RemoteContentController::HandleTap(TapType aTapType,
                                    const LayoutDevicePoint& aPoint,
                                    Modifiers aModifiers,
                                    const ScrollableLayerGuid& aGuid,
@@ -157,123 +156,19 @@ RemoteContentController::NotifyFlushComp
 bool
 RemoteContentController::RecvUpdateHitRegion(const nsRegion& aRegion)
 {
   MutexAutoLock lock(mMutex);
   mTouchSensitiveRegion = aRegion;
   return true;
 }
 
-bool
-RemoteContentController::RecvZoomToRect(const uint32_t& aPresShellId,
-                                        const ViewID& aViewId,
-                                        const CSSRect& aRect,
-                                        const uint32_t& aFlags)
-{
-  if (RefPtr<IAPZCTreeManager> apzcTreeManager = GetApzcTreeManager()) {
-    apzcTreeManager->ZoomToRect(ScrollableLayerGuid(mLayersId, aPresShellId, aViewId),
-                                aRect, aFlags);
-  }
-  return true;
-}
-
-bool
-RemoteContentController::RecvContentReceivedInputBlock(const ScrollableLayerGuid& aGuid,
-                                                       const uint64_t& aInputBlockId,
-                                                       const bool& aPreventDefault)
-{
-  if (aGuid.mLayersId != mLayersId) {
-    // Guard against bad data from hijacked child processes
-    NS_ERROR("Unexpected layers id in RecvContentReceivedInputBlock; dropping message...");
-    return false;
-  }
-  if (RefPtr<IAPZCTreeManager> apzcTreeManager = GetApzcTreeManager()) {
-    APZThreadUtils::RunOnControllerThread(NewRunnableMethod<uint64_t,
-                                                            bool>(apzcTreeManager,
-                                                                  &IAPZCTreeManager::ContentReceivedInputBlock,
-                                                                  aInputBlockId, aPreventDefault));
-
-  }
-  return true;
-}
-
-bool
-RemoteContentController::RecvStartScrollbarDrag(const AsyncDragMetrics& aDragMetrics)
-{
-  if (RefPtr<IAPZCTreeManager> apzcTreeManager = GetApzcTreeManager()) {
-    ScrollableLayerGuid guid(mLayersId, aDragMetrics.mPresShellId,
-                             aDragMetrics.mViewId);
-
-    APZThreadUtils::RunOnControllerThread(NewRunnableMethod
-                                          <ScrollableLayerGuid,
-                                           AsyncDragMetrics>(apzcTreeManager,
-                                                             &IAPZCTreeManager::StartScrollbarDrag,
-                                                             guid, aDragMetrics));
-  }
-  return true;
-}
-
-bool
-RemoteContentController::RecvSetTargetAPZC(const uint64_t& aInputBlockId,
-                                           nsTArray<ScrollableLayerGuid>&& aTargets)
-{
-  for (size_t i = 0; i < aTargets.Length(); i++) {
-    if (aTargets[i].mLayersId != mLayersId) {
-      // Guard against bad data from hijacked child processes
-      NS_ERROR("Unexpected layers id in SetTargetAPZC; dropping message...");
-      return false;
-    }
-  }
-  if (RefPtr<IAPZCTreeManager> apzcTreeManager = GetApzcTreeManager()) {
-    // need a local var to disambiguate between the SetTargetAPZC overloads.
-    void (IAPZCTreeManager::*setTargetApzcFunc)(uint64_t, const nsTArray<ScrollableLayerGuid>&)
-        = &IAPZCTreeManager::SetTargetAPZC;
-    APZThreadUtils::RunOnControllerThread(NewRunnableMethod
-                                          <uint64_t,
-                                           StoreCopyPassByRRef<nsTArray<ScrollableLayerGuid>>>
-                                          (apzcTreeManager, setTargetApzcFunc, aInputBlockId, aTargets));
-
-  }
-  return true;
-}
-
-bool
-RemoteContentController::RecvSetAllowedTouchBehavior(const uint64_t& aInputBlockId,
-                                                     nsTArray<TouchBehaviorFlags>&& aFlags)
-{
-  if (RefPtr<IAPZCTreeManager> apzcTreeManager = GetApzcTreeManager()) {
-    APZThreadUtils::RunOnControllerThread(NewRunnableMethod
-                                          <uint64_t,
-                                           StoreCopyPassByRRef<nsTArray<TouchBehaviorFlags>>>
-                                          (apzcTreeManager,
-                                           &IAPZCTreeManager::SetAllowedTouchBehavior,
-                                           aInputBlockId, Move(aFlags)));
-  }
-  return true;
-}
-
-bool
-RemoteContentController::RecvUpdateZoomConstraints(const uint32_t& aPresShellId,
-                                                   const ViewID& aViewId,
-                                                   const MaybeZoomConstraints& aConstraints)
-{
-  if (RefPtr<IAPZCTreeManager> apzcTreeManager = GetApzcTreeManager()) {
-    apzcTreeManager->UpdateZoomConstraints(ScrollableLayerGuid(mLayersId, aPresShellId, aViewId),
-                                           aConstraints);
-  }
-  return true;
-}
-
 void
 RemoteContentController::ActorDestroy(ActorDestroyReason aWhy)
 {
-  {
-    MutexAutoLock lock(mMutex);
-    mApzcTreeManager = nullptr;
-  }
   mBrowserParent = nullptr;
 
   uint64_t key = mLayersId;
   NS_DispatchToMainThread(NS_NewRunnableFunction([key]() {
     // sDestroyedControllers may or may not contain the key, depending on
     // whether or not SendDestroy() was successfully sent out or not.
     sDestroyedControllers.erase(key);
   }));
@@ -293,33 +188,10 @@ RemoteContentController::Destroy()
       uint64_t key = controller->mLayersId;
       MOZ_ASSERT(sDestroyedControllers.find(key) == sDestroyedControllers.end());
       sDestroyedControllers[key] = controller;
       Unused << controller->SendDestroy();
     }
   }));
 }
 
-void
-RemoteContentController::ChildAdopted()
-{
-  // Clear the cached APZCTreeManager.
-  MutexAutoLock lock(mMutex);
-  mApzcTreeManager = nullptr;
-}
-
-already_AddRefed<IAPZCTreeManager>
-RemoteContentController::GetApzcTreeManager()
-{
-  // We can't get a ref to the APZCTreeManager until after the child is
-  // created and the static getter knows which CompositorBridgeParent is
-  // instantiated with this layers ID. That's why try to fetch it when
-  // we first need it and cache the result.
-  MutexAutoLock lock(mMutex);
-  if (!mApzcTreeManager) {
-    mApzcTreeManager = GPUProcessManager::Get()->GetAPZCTreeManagerForLayers(mLayersId);
-  }
-  RefPtr<IAPZCTreeManager> apzcTreeManager(mApzcTreeManager);
-  return apzcTreeManager.forget();
-}
-
 } // namespace layers
 } // namespace mozilla
--- a/gfx/layers/ipc/RemoteContentController.h
+++ b/gfx/layers/ipc/RemoteContentController.h
@@ -14,18 +14,16 @@
 namespace mozilla {
 
 namespace dom {
 class TabParent;
 }
 
 namespace layers {
 
-class IAPZCTreeManager;
-
 /**
  * RemoteContentController uses the PAPZ protocol to implement a
  * GeckoContentController for a browser living in a remote process.
  * Most of the member functions can be called on any thread, exceptions are
  * annotated in comments. The PAPZ protocol runs on the main thread (so all the
  * Recv* member functions do too).
  */
 class RemoteContentController : public GeckoContentController
@@ -60,59 +58,33 @@ public:
   virtual void NotifyMozMouseScrollEvent(const FrameMetrics::ViewID& aScrollId,
                                          const nsString& aEvent) override;
 
   // Needs to be called on the main thread.
   virtual void NotifyFlushComplete() override;
 
   virtual bool RecvUpdateHitRegion(const nsRegion& aRegion) override;
 
-  virtual bool RecvZoomToRect(const uint32_t& aPresShellId,
-                              const ViewID& aViewId,
-                              const CSSRect& aRect,
-                              const uint32_t& aFlags) override;
-
-  virtual bool RecvContentReceivedInputBlock(const ScrollableLayerGuid& aGuid,
-                                             const uint64_t& aInputBlockId,
-                                             const bool& aPreventDefault) override;
-
-  virtual bool RecvStartScrollbarDrag(const AsyncDragMetrics& aDragMetrics) override;
-
-  virtual bool RecvSetTargetAPZC(const uint64_t& aInputBlockId,
-                                 nsTArray<ScrollableLayerGuid>&& aTargets) override;
-
-  virtual bool RecvSetAllowedTouchBehavior(const uint64_t& aInputBlockId,
-                                           nsTArray<TouchBehaviorFlags>&& aFlags) override;
-
-  virtual bool RecvUpdateZoomConstraints(const uint32_t& aPresShellId,
-                                         const ViewID& aViewId,
-                                         const MaybeZoomConstraints& aConstraints) override;
-
   virtual void ActorDestroy(ActorDestroyReason aWhy) override;
 
   virtual void Destroy() override;
 
-  virtual void ChildAdopted() override;
-
 private:
   bool CanSend()
   {
     MOZ_ASSERT(NS_IsMainThread());
     return !!mBrowserParent;
   }
-  already_AddRefed<IAPZCTreeManager> GetApzcTreeManager();
 
   MessageLoop* mUILoop;
   uint64_t mLayersId;
   RefPtr<dom::TabParent> mBrowserParent;
 
   // Mutex protecting members below accessed from multiple threads.
   mozilla::Mutex mMutex;
-
-  RefPtr<IAPZCTreeManager> mApzcTreeManager;
   nsRegion mTouchSensitiveRegion;
 };
 
 } // namespace layers
 
 } // namespace mozilla
 
 #endif // mozilla_layers_RemoteContentController_h
--- a/layout/base/nsLayoutUtils.cpp
+++ b/layout/base/nsLayoutUtils.cpp
@@ -9275,17 +9275,17 @@ static void UpdateDisplayPortMarginsForP
 }
 
 /* static */ void
 nsLayoutUtils::UpdateDisplayPortMarginsFromPendingMessages() {
   if (mozilla::dom::ContentChild::GetSingleton() &&
       mozilla::dom::ContentChild::GetSingleton()->GetIPCChannel()) {
     mozilla::dom::ContentChild::GetSingleton()->GetIPCChannel()->PeekMessages(
       [](const IPC::Message& aMsg) -> bool {
-        if (aMsg.type() == mozilla::layers::PAPZ::Msg_UpdateFrame__ID) {
+        if (aMsg.type() == mozilla::layers::PAPZ::Msg_RequestContentRepaint__ID) {
           PickleIterator iter(aMsg);
           FrameMetrics frame;
           if (!IPC::ReadParam(&aMsg, &iter, &frame)) {
             MOZ_ASSERT(false);
             return true;
           }
 
           UpdateDisplayPortMarginsForPendingMetrics(frame);
--- a/layout/ipc/RenderFrameParent.h
+++ b/layout/ipc/RenderFrameParent.h
@@ -19,17 +19,16 @@
 class nsFrameLoader;
 class nsSubDocumentFrame;
 
 namespace mozilla {
 
 class InputEvent;
 
 namespace layers {
-class APZCTreeManager;
 class AsyncDragMetrics;
 class TargetConfig;
 struct TextureFactoryIdentifier;
 struct ScrollableLayerGuid;
 } // namespace layers
 
 namespace layout {