diff --git a/gfx/layers/wr/ScrollingLayersHelper.cpp b/gfx/layers/wr/ScrollingLayersHelper.cpp index 3859b0cabc29..5bcb2f3b3765 100644 --- a/gfx/layers/wr/ScrollingLayersHelper.cpp +++ b/gfx/layers/wr/ScrollingLayersHelper.cpp @@ -403,8 +403,10 @@ ScrollingLayersHelper::RecurseAndDefineAsr(nsDisplayItem* aItem, aItem, aAsr->mParent, aChain, aAppUnitsPerDevPixel, aSc); ids = ancestorIds; + // Ok to pass nullptr for aLayer here (first arg) because aClip (last arg) is + // also nullptr. Maybe metadata = aAsr->mScrollableFrame->ComputeScrollMetadata( - mManager, aItem->ReferenceFrame(), ContainerLayerParameters(), nullptr); + nullptr, mManager, aItem->ReferenceFrame(), ContainerLayerParameters(), nullptr); MOZ_ASSERT(metadata); FrameMetrics& metrics = metadata->GetMetrics(); diff --git a/gfx/layers/wr/WebRenderScrollData.cpp b/gfx/layers/wr/WebRenderScrollData.cpp index c02e7183ef5a..3f07a6c5571d 100644 --- a/gfx/layers/wr/WebRenderScrollData.cpp +++ b/gfx/layers/wr/WebRenderScrollData.cpp @@ -64,7 +64,7 @@ WebRenderLayerScrollData::Initialize(WebRenderScrollData& aOwner, mScrollIds.AppendElement(index.ref()); } else { Maybe metadata = asr->mScrollableFrame->ComputeScrollMetadata( - aOwner.GetManager(), aItem->ReferenceFrame(), + nullptr, aOwner.GetManager(), aItem->ReferenceFrame(), ContainerLayerParameters(), nullptr); MOZ_ASSERT(metadata); MOZ_ASSERT(metadata->GetMetrics().GetScrollId() == scrollId); diff --git a/layout/generic/nsGfxScrollFrame.cpp b/layout/generic/nsGfxScrollFrame.cpp index 6ab55223faa8..8bd6e6e47995 100644 --- a/layout/generic/nsGfxScrollFrame.cpp +++ b/layout/generic/nsGfxScrollFrame.cpp @@ -3898,7 +3898,8 @@ ScrollFrameHelper::DecideScrollableLayer(nsDisplayListBuilder* aBuilder, Maybe -ScrollFrameHelper::ComputeScrollMetadata(LayerManager* aLayerManager, +ScrollFrameHelper::ComputeScrollMetadata(Layer* aLayer, + LayerManager* aLayerManager, const nsIFrame* aContainerReferenceFrame, const ContainerLayerParameters& aParameters, const DisplayItemClip* aClip) const @@ -3907,11 +3908,6 @@ ScrollFrameHelper::ComputeScrollMetadata(LayerManager* aLayerManager, return Nothing(); } - if (!nsLayoutUtils::UsesAsyncScrolling(mOuter)) { - // Return early, since if we don't use APZ we don't need FrameMetrics. - return Nothing(); - } - nsPoint toReferenceFrame = mOuter->GetOffsetToCrossDoc(aContainerReferenceFrame); Maybe parentLayerClip; @@ -3922,33 +3918,11 @@ ScrollFrameHelper::ComputeScrollMetadata(LayerManager* aLayerManager, } bool isRootContent = mIsRoot && mOuter->PresContext()->IsRootContentDocument(); - - MOZ_ASSERT(mScrolledFrame->GetContent()); - - nsRect scrollport = mScrollPort + toReferenceFrame; - - return Some(nsLayoutUtils::ComputeScrollMetadata( - mScrolledFrame, mOuter, mOuter->GetContent(), - aContainerReferenceFrame, aLayerManager, mScrollParentID, - scrollport, parentLayerClip, isRootContent, aParameters)); -} - -void -ScrollFrameHelper::ClipLayerToDisplayPort(Layer* aLayer, - const DisplayItemClip* aClip, - const ContainerLayerParameters& aParameters) const -{ - // If APZ is not enabled, we still need the displayport to be clipped - // in the compositor. - if (!nsLayoutUtils::UsesAsyncScrolling(mOuter)) { - Maybe parentLayerClip; - // For containerful frames, the clip is on the container layer. - if (aClip && - (!gfxPrefs::LayoutUseContainersForRootFrames() || mAddClipRectToLayer)) { - parentLayerClip = Some(aClip->GetClipRect()); - } - + bool thisScrollFrameUsesAsyncScrolling = nsLayoutUtils::UsesAsyncScrolling(mOuter); + if (!thisScrollFrameUsesAsyncScrolling) { if (parentLayerClip) { + // If APZ is not enabled, we still need the displayport to be clipped + // in the compositor. ParentLayerIntRect displayportClip = ViewAs( parentLayerClip->ScaleToNearestPixels( @@ -3964,7 +3938,19 @@ ScrollFrameHelper::ClipLayerToDisplayPort(Layer* aLayer, } aLayer->SetClipRect(Some(layerClip)); } + + // Return early, since if we don't use APZ we don't need FrameMetrics. + return Nothing(); } + + MOZ_ASSERT(mScrolledFrame->GetContent()); + + nsRect scrollport = mScrollPort + toReferenceFrame; + + return Some(nsLayoutUtils::ComputeScrollMetadata( + mScrolledFrame, mOuter, mOuter->GetContent(), + aContainerReferenceFrame, aLayerManager, mScrollParentID, + scrollport, parentLayerClip, isRootContent, aParameters)); } bool diff --git a/layout/generic/nsGfxScrollFrame.h b/layout/generic/nsGfxScrollFrame.h index 96da3fa632b7..b9161c2e584a 100644 --- a/layout/generic/nsGfxScrollFrame.h +++ b/layout/generic/nsGfxScrollFrame.h @@ -464,13 +464,11 @@ public: } bool WantAsyncScroll() const; Maybe ComputeScrollMetadata( + Layer* aLayer, LayerManager* aLayerManager, const nsIFrame* aContainerReferenceFrame, const ContainerLayerParameters& aParameters, const mozilla::DisplayItemClip* aClip) const; - void ClipLayerToDisplayPort(Layer* aLayer, - const mozilla::DisplayItemClip* aClip, - const ContainerLayerParameters& aParameters) const; // nsIScrollbarMediator void ScrollByPage(nsScrollbarFrame* aScrollbar, int32_t aDirection, @@ -616,7 +614,7 @@ public: // will already have the necessary frame metrics. bool mIsScrollableLayerInRootContainer:1; - // If true, add clipping in ScrollFrameHelper::ClipLayerToDisplayPort. + // If true, add clipping in ScrollFrameHelper::ComputeFrameMetrics. bool mAddClipRectToLayer:1; // True if this frame has been scrolled at least once @@ -972,21 +970,16 @@ public: return mHelper.WantAsyncScroll(); } virtual mozilla::Maybe ComputeScrollMetadata( + Layer* aLayer, LayerManager* aLayerManager, const nsIFrame* aContainerReferenceFrame, const ContainerLayerParameters& aParameters, const mozilla::DisplayItemClip* aClip) const override { - return mHelper.ComputeScrollMetadata(aLayerManager, aContainerReferenceFrame, aParameters, aClip); + return mHelper.ComputeScrollMetadata(aLayer, aLayerManager, aContainerReferenceFrame, aParameters, aClip); } - virtual void ClipLayerToDisplayPort(Layer* aLayer, - const mozilla::DisplayItemClip* aClip, - const ContainerLayerParameters& aParameters) const override - { - mHelper.ClipLayerToDisplayPort(aLayer, aClip, aParameters); - } -virtual bool IsIgnoringViewportClipping() const override { -return mHelper.IsIgnoringViewportClipping(); + virtual bool IsIgnoringViewportClipping() const override { + return mHelper.IsIgnoringViewportClipping(); } virtual void MarkScrollbarsDirtyForReflow() const override { mHelper.MarkScrollbarsDirtyForReflow(); @@ -1420,20 +1413,16 @@ public: return mHelper.WantAsyncScroll(); } virtual mozilla::Maybe ComputeScrollMetadata( + Layer* aLayer, LayerManager* aLayerManager, const nsIFrame* aContainerReferenceFrame, const ContainerLayerParameters& aParameters, const mozilla::DisplayItemClip* aClip) const override { - return mHelper.ComputeScrollMetadata(aLayerManager, aContainerReferenceFrame, aParameters, aClip); + return mHelper.ComputeScrollMetadata(aLayer, aLayerManager, aContainerReferenceFrame, aParameters, aClip); } - virtual void ClipLayerToDisplayPort(Layer* aLayer, - const mozilla::DisplayItemClip* aClip, - const ContainerLayerParameters& aParameters) const override { - mHelper.ClipLayerToDisplayPort(aLayer, aClip, aParameters); - } -virtual bool IsIgnoringViewportClipping() const override { -return mHelper.IsIgnoringViewportClipping(); + virtual bool IsIgnoringViewportClipping() const override { + return mHelper.IsIgnoringViewportClipping(); } virtual void MarkScrollbarsDirtyForReflow() const override { mHelper.MarkScrollbarsDirtyForReflow(); diff --git a/layout/generic/nsIScrollableFrame.h b/layout/generic/nsIScrollableFrame.h index 76b6863c7ad8..75bc7b7381b2 100644 --- a/layout/generic/nsIScrollableFrame.h +++ b/layout/generic/nsIScrollableFrame.h @@ -411,19 +411,16 @@ public: */ virtual bool WantAsyncScroll() const = 0; /** - * Returns the ScrollMetadata contributed by this frame, if there is one. + * aLayer's animated geometry root is this frame. Returns the ScrollMetadata + * contributed by this frame, if there is one. + * If aClip is non-null, then aLayer must also be non-null. */ virtual mozilla::Maybe ComputeScrollMetadata( + mozilla::layers::Layer* aLayer, mozilla::layers::LayerManager* aLayerManager, const nsIFrame* aContainerReferenceFrame, const ContainerLayerParameters& aParameters, const mozilla::DisplayItemClip* aClip) const = 0; - /** - * Ensure's aLayer is clipped to the display port. - */ - virtual void ClipLayerToDisplayPort(mozilla::layers::Layer* aLayer, - const mozilla::DisplayItemClip* aClip, - const ContainerLayerParameters& aParameters) const; /** * If this scroll frame is ignoring viewporting clipping diff --git a/layout/painting/FrameLayerBuilder.cpp b/layout/painting/FrameLayerBuilder.cpp index 490858627503..bdc7b05c8273 100644 --- a/layout/painting/FrameLayerBuilder.cpp +++ b/layout/painting/FrameLayerBuilder.cpp @@ -1574,19 +1574,6 @@ protected: // thing repeatly. AnimatedGeometryRoot* mLastDisplayPortAGR; nsRect mLastDisplayPortRect; - - // Cache ScrollMetadata so it doesn't need recomputed if the ASR and clip are unchanged. - // If mASR == nullptr then mMetadata is not valid. - struct CachedScrollMetadata { - const ActiveScrolledRoot* mASR; - const DisplayItemClip* mClip; - Maybe mMetadata; - - CachedScrollMetadata() - : mASR(nullptr), mClip(nullptr) - {} - }; - CachedScrollMetadata mCachedScrollMetadata; }; bool @@ -5462,20 +5449,9 @@ ContainerState::SetupScrollingMetadata(NewLayerEntry* aEntry) const DisplayItemClip* clip = (clipChain && clipChain->mASR == asr->mParent) ? &clipChain->mClip : nullptr; - scrollFrame->ClipLayerToDisplayPort(aEntry->mLayer, clip, mParameters); - - Maybe metadata; - if (mCachedScrollMetadata.mASR == asr && - mCachedScrollMetadata.mClip == clip) { - metadata = mCachedScrollMetadata.mMetadata; - } else { - metadata = scrollFrame->ComputeScrollMetadata(aEntry->mLayer->Manager(), + Maybe metadata = + scrollFrame->ComputeScrollMetadata(aEntry->mLayer, aEntry->mLayer->Manager(), mContainerReferenceFrame, mParameters, clip); - mCachedScrollMetadata.mASR = asr; - mCachedScrollMetadata.mClip = clip; - mCachedScrollMetadata.mMetadata = metadata; - } - if (!metadata) { continue; }