Bug 1384181 - Build WebRenderLayerScrollData instances for remote layer trees. r? draft
authorKartikaya Gupta <kgupta@mozilla.com>
Wed, 26 Jul 2017 14:47:48 -0400
changeset 616163 fc3f4457f3b38e2a8d1f40394e024d0e5b1532da
parent 616162 4865a295a312ed83cb2ff92a22bfc277680d0ec3
child 616164 ca1ca995587cc98de334e2e897cc666e3a8ad077
push id70614
push userkgupta@mozilla.com
push dateWed, 26 Jul 2017 20:00:48 +0000
bugs1384181
milestone56.0a1
Bug 1384181 - Build WebRenderLayerScrollData instances for remote layer trees. r? This adds handling for nsDisplayRemote frames, so that we create a WebRenderLayerScrollData item for each nsDisplayRemote frame that we encounter. This is the equivalent of a "ref layer" in a normal layer tree, and allows the APZ side to glue together the scroll data from different processes into a full tree. MozReview-Commit-ID: 3lgsqtCKQya
gfx/layers/wr/WebRenderLayerManager.cpp
gfx/layers/wr/WebRenderScrollData.cpp
layout/ipc/RenderFrameParent.cpp
layout/ipc/RenderFrameParent.h
--- a/gfx/layers/wr/WebRenderLayerManager.cpp
+++ b/gfx/layers/wr/WebRenderLayerManager.cpp
@@ -240,16 +240,17 @@ WebRenderLayerManager::CreateWebRenderCo
     if (apzEnabled) {
       bool forceNewLayerData = false;
 
       // For some types of display items we want to force a new
       // WebRenderLayerScrollData object, to ensure we preserve the APZ-relevant
       // data that is in the display item.
       switch (itemType) {
       case nsDisplayItem::TYPE_SCROLL_INFO_LAYER:
+      case nsDisplayItem::TYPE_REMOTE:
         forceNewLayerData = true;
         break;
       default:
         break;
       }
 
       // Anytime the ASR changes we also want to force a new layer data because
       // the stack of scroll metadata is going to be different for this
--- a/gfx/layers/wr/WebRenderScrollData.cpp
+++ b/gfx/layers/wr/WebRenderScrollData.cpp
@@ -1,18 +1,18 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  * 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/WebRenderScrollData.h"
 
 #include "Layers.h"
+#include "mozilla/layout/RenderFrameParent.h"
 #include "mozilla/Unused.h"
-#include "Layers.h"
 #include "nsTArray.h"
 #include "UnitTransforms.h"
 
 namespace mozilla {
 namespace layers {
 
 WebRenderLayerScrollData::WebRenderLayerScrollData()
   : mDescendantCount(-1)
@@ -68,23 +68,33 @@ WebRenderLayerScrollData::InitializeRoot
 
 void
 WebRenderLayerScrollData::Initialize(WebRenderScrollData& aOwner,
                                      nsDisplayItem* aItem)
 {
   mDescendantCount = 0;
 
   MOZ_ASSERT(aItem);
-  if (aItem->GetType() == nsDisplayItem::TYPE_SCROLL_INFO_LAYER) {
+  switch (aItem->GetType()) {
+  case nsDisplayItem::TYPE_SCROLL_INFO_LAYER: {
     nsDisplayScrollInfoLayer* info = static_cast<nsDisplayScrollInfoLayer*>(aItem);
     UniquePtr<ScrollMetadata> metadata = info->ComputeScrollMetadata(
         nullptr, ContainerLayerParameters());
     MOZ_ASSERT(metadata);
     MOZ_ASSERT(metadata->GetMetrics().IsScrollInfoLayer());
     mScrollIds.AppendElement(aOwner.AddMetadata(*metadata));
+    break;
+  }
+  case nsDisplayItem::TYPE_REMOTE: {
+    nsDisplayRemote* remote = static_cast<nsDisplayRemote*>(aItem);
+    mReferentId = Some(remote->GetRemoteLayersId());
+    break;
+  }
+  default:
+    break;
   }
   for (const ActiveScrolledRoot* asr = aItem->GetActiveScrolledRoot();
        asr;
        asr = asr->mParent) {
     Maybe<ScrollMetadata> metadata = asr->mScrollableFrame->ComputeScrollMetadata(
         nullptr, aItem->ReferenceFrame(), ContainerLayerParameters(), nullptr);
     MOZ_ASSERT(metadata);
     mScrollIds.AppendElement(aOwner.AddMetadata(metadata.ref()));
--- a/layout/ipc/RenderFrameParent.cpp
+++ b/layout/ipc/RenderFrameParent.cpp
@@ -390,12 +390,18 @@ nsDisplayRemote::CreateWebRenderCommands
 {
   MOZ_ASSERT(aManager->IsLayersFreeTransaction());
 
   mozilla::LayoutDeviceRect visible = mozilla::LayoutDeviceRect::FromAppUnits(
       GetVisibleRect(), mFrame->PresContext()->AppUnitsPerDevPixel());
   visible += mozilla::layout::GetContentRectLayerOffset(mFrame, aDisplayListBuilder);
 
   aBuilder.PushIFrame(aSc.ToRelativeLayoutRect(visible),
-      mozilla::wr::AsPipelineId(mRemoteFrame->GetLayersId()));
+      mozilla::wr::AsPipelineId(GetRemoteLayersId()));
 
   return true;
 }
+
+uint64_t
+nsDisplayRemote::GetRemoteLayersId() const
+{
+  return mRemoteFrame->GetLayersId();
+}
--- a/layout/ipc/RenderFrameParent.h
+++ b/layout/ipc/RenderFrameParent.h
@@ -162,16 +162,17 @@ public:
   BuildLayer(nsDisplayListBuilder* aBuilder, LayerManager* aManager,
              const ContainerLayerParameters& aContainerParameters) override;
 
   virtual bool CreateWebRenderCommands(mozilla::wr::DisplayListBuilder& aBuilder,
                                        const StackingContextHelper& aSc,
                                        nsTArray<WebRenderParentCommand>& aParentCommands,
                                        mozilla::layers::WebRenderLayerManager* aManager,
                                        nsDisplayListBuilder* aDisplayListBuilder) override;
+  uint64_t GetRemoteLayersId() const;
 
   NS_DISPLAY_DECL_NAME("Remote", TYPE_REMOTE)
 
 private:
   RenderFrameParent* mRemoteFrame;
   mozilla::layers::EventRegionsOverride mEventRegionsOverride;
 };