Bug 1384181 - Build WebRenderLayerScrollData instances for remote layer trees. r?jrmuizel draft
authorKartikaya Gupta <kgupta@mozilla.com>
Wed, 26 Jul 2017 11:30:47 -0400
changeset 615938 37ca9caaedd781742c1f44433a4177e9b6ea76a7
parent 615937 05305d753f91f82ebc70b88d5cd73baef3c51a14
child 615939 c049f5b410101e59dd9f0d8f98bd4078db0a3a79
push id70530
push userkgupta@mozilla.com
push dateWed, 26 Jul 2017 15:31:11 +0000
reviewersjrmuizel
bugs1384181
milestone56.0a1
Bug 1384181 - Build WebRenderLayerScrollData instances for remote layer trees. r?jrmuizel 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: DXuWR2w90kg
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;
 };