From 51b371636c46b8f0156e81e048c51f81fc92f790 Mon Sep 17 00:00:00 2001 From: Matt Woodrow Date: Mon, 6 Sep 2021 23:12:04 +0000 Subject: [PATCH] Bug 1728251 - Remove mClip and compute it when we need it. r=miko Differential Revision: https://phabricator.services.mozilla.com/D124008 --- layout/painting/nsDisplayList.cpp | 24 +++++++----------------- layout/painting/nsDisplayList.h | 13 +++++-------- 2 files changed, 12 insertions(+), 25 deletions(-) diff --git a/layout/painting/nsDisplayList.cpp b/layout/painting/nsDisplayList.cpp index 6cd1ccb84719..3324dfb77254 100644 --- a/layout/painting/nsDisplayList.cpp +++ b/layout/painting/nsDisplayList.cpp @@ -2771,8 +2771,7 @@ nsDisplayItem::nsDisplayItem(nsDisplayListBuilder* aBuilder, nsIFrame* aFrame, aBuilder->GetVisibleRect().width >= 0 || !aBuilder->IsForPainting(), "visible rect not set"); - nsDisplayItem::SetClipChain( - aBuilder->ClipState().GetCurrentCombinedClipChain(aBuilder), true); + mClipChain = aBuilder->ClipState().GetCurrentCombinedClipChain(aBuilder); // The visible rect is for mCurrentFrame, so we have to use // mCurrentOffsetToReferenceFrame @@ -2809,7 +2808,6 @@ int32_t nsDisplayItem::ZIndex() const { return mFrame->ZIndex().valueOr(0); } void nsDisplayItem::SetClipChain(const DisplayItemClipChain* aClipChain, bool aStore) { mClipChain = aClipChain; - mClip = DisplayItemClipChain::ClipForASR(aClipChain, mActiveScrolledRoot); } Maybe nsDisplayItem::GetClipWithRespectToASR( @@ -2824,6 +2822,12 @@ Maybe nsDisplayItem::GetClipWithRespectToASR( return Nothing(); } +const DisplayItemClip& nsDisplayItem::GetClip() const { + const DisplayItemClip* clip = + DisplayItemClipChain::ClipForASR(mClipChain, mActiveScrolledRoot); + return clip ? *clip : DisplayItemClip::NoClip(); +} + void nsDisplayItem::IntersectClip(nsDisplayListBuilder* aBuilder, const DisplayItemClipChain* aOther, bool aStore) { @@ -5819,20 +5823,6 @@ nsDisplayStickyPosition::nsDisplayStickyPosition( MOZ_COUNT_CTOR(nsDisplayStickyPosition); } -void nsDisplayStickyPosition::SetClipChain( - const DisplayItemClipChain* aClipChain, bool aStore) { - mClipChain = aClipChain; - mClip = nullptr; - - MOZ_ASSERT(!mClip, - "There should never be a clip on this item because no clip moves " - "with it."); - - if (aStore) { - mOriginalClipChain = aClipChain; - } -} - // Returns the smallest distance from "0" to the range [min, max] where // min <= max. Despite the name, the return value is actually a 1-D vector, // and so may be negative if max < 0. diff --git a/layout/painting/nsDisplayList.h b/layout/painting/nsDisplayList.h index 23d98839cfc4..4a8051e77dfb 100644 --- a/layout/painting/nsDisplayList.h +++ b/layout/painting/nsDisplayList.h @@ -2387,8 +2387,7 @@ class nsDisplayItem : public nsDisplayItemLink { mToReferenceFrame(aOther.mToReferenceFrame), mAnimatedGeometryRoot(aOther.mAnimatedGeometryRoot), mActiveScrolledRoot(aOther.mActiveScrolledRoot), - mClipChain(aOther.mClipChain), - mClip(aOther.mClip) { + mClipChain(aOther.mClipChain) { MOZ_COUNT_CTOR(nsDisplayItem); // TODO: It might be better to remove the flags that aren't copied. if (aOther.ForceNotVisible()) { @@ -2841,9 +2840,7 @@ class nsDisplayItem : public nsDisplayItemLink { virtual bool SupportsOptimizingToImage() const { return false; } - const DisplayItemClip& GetClip() const { - return mClip ? *mClip : DisplayItemClip::NoClip(); - } + virtual const DisplayItemClip& GetClip() const; void IntersectClip(nsDisplayListBuilder* aBuilder, const DisplayItemClipChain* aOther, bool aStore); @@ -2962,7 +2959,6 @@ class nsDisplayItem : public nsDisplayItemLink { RefPtr mAnimatedGeometryRoot; RefPtr mActiveScrolledRoot; RefPtr mClipChain; - const DisplayItemClip* mClip = nullptr; #ifdef MOZ_DIAGNOSTIC_ASSERT_ENABLED public: @@ -5609,8 +5605,9 @@ class nsDisplayStickyPosition : public nsDisplayOwnLayer { MOZ_COUNTED_DTOR_OVERRIDE(nsDisplayStickyPosition) - void SetClipChain(const DisplayItemClipChain* aClipChain, - bool aStore) override; + const DisplayItemClip& GetClip() const override { + return DisplayItemClip::NoClip(); + } bool IsClippedToDisplayPort() const { return mClippedToDisplayPort; } NS_DISPLAY_DECL_NAME("StickyPosition", TYPE_STICKY_POSITION)