From f1dc235e14cf343a41a9f8971f7f02decadddd71 Mon Sep 17 00:00:00 2001 From: Ryan Hunt Date: Mon, 24 Sep 2018 21:45:54 -0500 Subject: [PATCH] Bug 1475139 part 9 - Use DrawDependentSurface in nsDisplayRemote when painting to a temp layer manager with a recording. r=mattwoodrow Differential Revision: https://phabricator.services.mozilla.com/D6788 --HG-- extra : rebase_source : be90e03c9db768ecbc1b7f419f5ab9eda36e9ae4 --- layout/generic/nsSubDocumentFrame.cpp | 11 +++++- layout/ipc/RenderFrameParent.cpp | 52 ++++++++++++++++++--------- layout/ipc/RenderFrameParent.h | 17 +++++---- 3 files changed, 55 insertions(+), 25 deletions(-) diff --git a/layout/generic/nsSubDocumentFrame.cpp b/layout/generic/nsSubDocumentFrame.cpp index f053408e4390..f0f8ea846cba 100644 --- a/layout/generic/nsSubDocumentFrame.cpp +++ b/layout/generic/nsSubDocumentFrame.cpp @@ -367,7 +367,16 @@ nsSubDocumentFrame::BuildDisplayList(nsDisplayListBuilder* aBuilder, } if (rfp) { - rfp->BuildDisplayList(aBuilder, this, aLists); + // We're the subdoc for and it has + // painted content. Display its shadow layer tree. + DisplayListClipState::AutoSaveRestore clipState(aBuilder); + + nsPoint offset = aBuilder->ToReferenceFrame(this); + nsRect bounds = this->EnsureInnerView()->GetBounds() + offset; + clipState.ClipContentDescendants(bounds); + + aLists.Content()->AppendToTop( + MakeDisplayItem(aBuilder, this)); return; } diff --git a/layout/ipc/RenderFrameParent.cpp b/layout/ipc/RenderFrameParent.cpp index 0d27e2ae08b3..2dbe0199effd 100644 --- a/layout/ipc/RenderFrameParent.cpp +++ b/layout/ipc/RenderFrameParent.cpp @@ -274,23 +274,6 @@ RenderFrameParent::TriggerRepaint() docFrame->InvalidateLayer(DisplayItemType::TYPE_REMOTE); } -void -RenderFrameParent::BuildDisplayList(nsDisplayListBuilder* aBuilder, - nsSubDocumentFrame* aFrame, - const nsDisplayListSet& aLists) -{ - // We're the subdoc for and it has - // painted content. Display its shadow layer tree. - DisplayListClipState::AutoSaveRestore clipState(aBuilder); - - nsPoint offset = aBuilder->ToReferenceFrame(aFrame); - nsRect bounds = aFrame->EnsureInnerView()->GetBounds() + offset; - clipState.ClipContentDescendants(bounds); - - aLists.Content()->AppendToTop( - MakeDisplayItem(aBuilder, aFrame)); -} - void RenderFrameParent::GetTextureFactoryIdentifier(TextureFactoryIdentifier* aTextureFactoryIdentifier) { @@ -341,6 +324,7 @@ RenderFrameParent::EnsureLayersConnected(CompositorOptions* aCompositorOptions) nsDisplayRemote::nsDisplayRemote(nsDisplayListBuilder* aBuilder, nsSubDocumentFrame* aFrame) : nsDisplayItem(aBuilder, aFrame) + , mTabId{0} , mEventRegionsOverride(EventRegionsOverride::NoOverride) { bool frameIsPointerEventsNone = @@ -352,6 +336,25 @@ nsDisplayRemote::nsDisplayRemote(nsDisplayListBuilder* aBuilder, if (nsLayoutUtils::HasDocumentLevelListenersForApzAwareEvents(aFrame->PresShell())) { mEventRegionsOverride |= EventRegionsOverride::ForceDispatchToContent; } + + nsFrameLoader* frameLoader = GetRenderFrameParent()->FrameLoader(); + if (frameLoader) { + TabParent* browser = TabParent::GetFrom(frameLoader); + if (browser) { + mTabId = browser->GetTabId(); + } + } +} + +mozilla::LayerState +nsDisplayRemote::GetLayerState(nsDisplayListBuilder* aBuilder, + LayerManager* aManager, + const ContainerLayerParameters& aParameters) +{ + if (mozilla::layout::IsTempLayerManager(aManager)) { + return mozilla::LAYER_NONE; + } + return mozilla::LAYER_ACTIVE_FORCE; } bool @@ -378,6 +381,21 @@ nsDisplayRemote::BuildLayer(nsDisplayListBuilder* aBuilder, return layer.forget(); } +void +nsDisplayRemote::Paint(nsDisplayListBuilder* aBuilder, gfxContext* aCtx) +{ + DrawTarget* target = aCtx->GetDrawTarget(); + if (!target->IsRecording() || mTabId == 0) { + NS_WARNING("Remote iframe not rendered"); + return; + } + + int32_t appUnitsPerDevPixel = mFrame->PresContext()->AppUnitsPerDevPixel(); + Rect destRect = + mozilla::NSRectToSnappedRect(GetContentRect(), appUnitsPerDevPixel, *target); + target->DrawDependentSurface(mTabId, destRect); +} + bool nsDisplayRemote::CreateWebRenderCommands(mozilla::wr::DisplayListBuilder& aBuilder, mozilla::wr::IpcResourceUpdateQueue& aResources, diff --git a/layout/ipc/RenderFrameParent.h b/layout/ipc/RenderFrameParent.h index 681d0eaa22c9..9ad2d0031918 100644 --- a/layout/ipc/RenderFrameParent.h +++ b/layout/ipc/RenderFrameParent.h @@ -10,6 +10,7 @@ #include "mozilla/Attributes.h" #include +#include "mozilla/dom/ipc/IdType.h" #include "mozilla/layers/APZUtils.h" #include "mozilla/layers/CompositorOptions.h" #include "mozilla/layers/LayersTypes.h" @@ -64,9 +65,6 @@ public: bool IsInitted(); void Destroy(); - void BuildDisplayList(nsDisplayListBuilder* aBuilder, - nsSubDocumentFrame* aFrame, - const nsDisplayListSet& aLists); already_AddRefed BuildLayer(nsDisplayListBuilder* aBuilder, nsIFrame* aFrame, @@ -90,6 +88,11 @@ public: LayerManager* AttachLayerManager(); + nsFrameLoader* FrameLoader() const + { + return mFrameLoader; + } + protected: void ActorDestroy(ActorDestroyReason why) override; @@ -155,15 +158,14 @@ public: LayerState GetLayerState(nsDisplayListBuilder* aBuilder, LayerManager* aManager, - const ContainerLayerParameters& aParameters) override - { - return mozilla::LAYER_ACTIVE_FORCE; - } + const ContainerLayerParameters& aParameters) override; already_AddRefed BuildLayer(nsDisplayListBuilder* aBuilder, LayerManager* aManager, const ContainerLayerParameters& aContainerParameters) override; + void Paint(nsDisplayListBuilder* aBuilder, gfxContext* aCtx) override; + bool CreateWebRenderCommands(mozilla::wr::DisplayListBuilder& aBuilder, mozilla::wr::IpcResourceUpdateQueue& aResources, const StackingContextHelper& aSc, @@ -178,6 +180,7 @@ private: mozilla::layers::LayersId GetRemoteLayersId() const; RenderFrameParent* GetRenderFrameParent() const; + mozilla::dom::TabId mTabId; mozilla::LayoutDeviceIntPoint mOffset; mozilla::layers::EventRegionsOverride mEventRegionsOverride; };