Bug 1357754 - Hook up chaining layer trees. r=botond,jrmuizel draft
authorKartikaya Gupta <kgupta@mozilla.com>
Thu, 20 Apr 2017 10:04:49 -0400
changeset 565813 ae5389d3271c78fb1679a1efcf5cee0dda16583e
parent 565812 ab360eb919545287ce817359d373f2a55042efd0
child 565814 670bf41150a51f4d5bfb6b1a945247855fabdb18
push id55024
push userkgupta@mozilla.com
push dateThu, 20 Apr 2017 14:05:27 +0000
reviewersbotond, jrmuizel
bugs1357754
milestone55.0a1
Bug 1357754 - Hook up chaining layer trees. r=botond,jrmuizel When APZ traverses a tree using LayerMetricsWrapper, the layer tree already has its RefLayers connected because of the in-scope AutoResolveRefLayers. When traversing using the WebRenderScrollDataWrapper though, this is not the case, and we need to explicitly jump from one layer tree to another during the walk. Thankfully we don't require upwards traversal in the tree or this would be much more complicated. MozReview-Commit-ID: 8gbvUlzghLx
gfx/layers/wr/WebRenderBridgeParent.cpp
gfx/layers/wr/WebRenderBridgeParent.h
gfx/layers/wr/WebRenderScrollDataWrapper.h
--- a/gfx/layers/wr/WebRenderBridgeParent.cpp
+++ b/gfx/layers/wr/WebRenderBridgeParent.cpp
@@ -302,20 +302,28 @@ WebRenderBridgeParent::HandleDPEnd(const
   // to early-return from RecvDPEnd without doing so.
   AutoWebRenderBridgeParentAsyncMessageSender autoAsyncMessageSender(this, &aToDestroy);
 
   ++mWrEpoch; // Update webrender epoch
   ProcessWebRenderCommands(aSize, aCommands, wr::NewEpoch(mWrEpoch),
                            dl, dlDesc, aux, auxDesc);
   HoldPendingTransactionId(mWrEpoch, aTransactionId);
 
+  mScrollData = aScrollData;
   // TODO: pass the WebRenderScrollData to APZ (this will happen in a future
   // patch)
 }
 
+const WebRenderScrollData&
+WebRenderBridgeParent::GetScrollData() const
+{
+  MOZ_ASSERT(mozilla::layers::CompositorThreadHolder::IsInCompositorThread());
+  return mScrollData;
+}
+
 mozilla::ipc::IPCResult
 WebRenderBridgeParent::RecvDPEnd(const gfx::IntSize& aSize,
                                  InfallibleTArray<WebRenderParentCommand>&& aCommands,
                                  InfallibleTArray<OpDestroy>&& aToDestroy,
                                  const uint64_t& aFwdTransactionId,
                                  const uint64_t& aTransactionId,
                                  const ByteBuffer& dl,
                                  const WrBuiltDisplayListDescriptor& dlDesc,
--- a/gfx/layers/wr/WebRenderBridgeParent.h
+++ b/gfx/layers/wr/WebRenderBridgeParent.h
@@ -155,16 +155,18 @@ public:
     aNotifications->AppendElements(Move(mImageCompositeNotifications));
   }
 
   uint32_t GetIdNameSpace()
   {
     return mIdNameSpace;
   }
 
+  const WebRenderScrollData& GetScrollData() const;
+
 private:
   virtual ~WebRenderBridgeParent();
 
   void DeleteOldImages();
   void ProcessWebRenderCommands(const gfx::IntSize &aSize, InfallibleTArray<WebRenderParentCommand>& commands, const wr::Epoch& aEpoch,
                                     const ByteBuffer& dl,
                                     const WrBuiltDisplayListDescriptor& dlDesc,
                                     const ByteBuffer& aux,
@@ -218,15 +220,18 @@ private:
 
   std::queue<PendingTransactionId> mPendingTransactionIds;
   uint32_t mWrEpoch;
   uint32_t mIdNameSpace;
 
   bool mPaused;
   bool mDestroyed;
 
+  // Can only be accessed on the compositor thread.
+  WebRenderScrollData mScrollData;
+
   static uint32_t sIdNameSpace;
 };
 
 } // namespace layers
 } // namespace mozilla
 
 #endif // mozilla_layers_WebRenderBridgeParent_h
--- a/gfx/layers/wr/WebRenderScrollDataWrapper.h
+++ b/gfx/layers/wr/WebRenderScrollDataWrapper.h
@@ -2,16 +2,18 @@
  * 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/. */
 
 #ifndef GFX_WEBRENDERSCROLLDATAWRAPPER_H
 #define GFX_WEBRENDERSCROLLDATAWRAPPER_H
 
 #include "FrameMetrics.h"
+#include "mozilla/layers/CompositorBridgeParent.h"
+#include "mozilla/layers/WebRenderBridgeParent.h"
 #include "mozilla/layers/WebRenderScrollData.h"
 
 namespace mozilla {
 namespace layers {
 
 /*
  * This class is a wrapper to walk through a WebRenderScrollData object, with
  * an exposed API that is template-compatible to LayerMetricsWrapper. This allows
@@ -152,16 +154,29 @@ public:
     // we compute the first index outside the subtree rooted at this node
     // (in |subtreeLastIndex|) and pass that in to the child wrapper to use as
     // its mContainingSubtreeLastIndex.
     if (mLayer->GetDescendantCount() > 0) {
       size_t prevSiblingIndex = mLayerIndex + 1 + mLayer->GetDescendantCount();
       size_t subtreeLastIndex = std::min(mContainingSubtreeLastIndex, prevSiblingIndex);
       return WebRenderScrollDataWrapper(mData, mLayerIndex + 1, subtreeLastIndex);
     }
+
+    // We've run out of descendants. But! If the original layer was a RefLayer,
+    // then it connects to another layer tree and we need to traverse that too.
+    // So return a WebRenderScrollDataWrapper for the root of the child layer
+    // tree.
+    if (mLayer->GetReferentId()) {
+      CompositorBridgeParent::LayerTreeState* lts =
+          CompositorBridgeParent::GetIndirectShadowTree(mLayer->GetReferentId().value());
+      if (lts && lts->mWrBridge) {
+        return WebRenderScrollDataWrapper(&(lts->mWrBridge->GetScrollData()));
+      }
+    }
+
     return WebRenderScrollDataWrapper();
   }
 
   WebRenderScrollDataWrapper GetPrevSibling() const
   {
     MOZ_ASSERT(IsValid());
 
     if (!AtTopLayer()) {