tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

commit 24a6bb46e8d7b3562b70d5e440b8a29ccdf41e3e
parent 99bf25deccb497e9f19d768adf74cf6b3ea16c91
Author: Botond Ballo <botond@mozilla.com>
Date:   Thu, 13 Nov 2025 04:59:05 +0000

Bug 1730749 - Maintain a mapping of sticky ASRs to spatial ids inside DisplayListBuilder. r=mstange

This is conceptually similar to the existing mapping of ViewIDs to spatial ids
for scroll ASRs, and the two could be unified in the future.

The patch also generalizes ClipManager::GetScrollLayer into GetSpatialId.

In nsDisplayStickyPosition::CreateWebRenderCommands, we use the new mapping,
in preparation for moving the DefineStickyFrame call out of there.

Differential Revision: https://phabricator.services.mozilla.com/D254151

Diffstat:
Mgfx/layers/wr/ClipManager.cpp | 18+++++++++++-------
Mgfx/layers/wr/ClipManager.h | 2+-
Mgfx/webrender_bindings/WebRenderAPI.cpp | 16++++++++++++++++
Mgfx/webrender_bindings/WebRenderAPI.h | 10++++++++++
Mlayout/painting/nsDisplayList.cpp | 21+++++++++++++--------
5 files changed, 51 insertions(+), 16 deletions(-)

diff --git a/gfx/layers/wr/ClipManager.cpp b/gfx/layers/wr/ClipManager.cpp @@ -101,7 +101,7 @@ void ClipManager::EndList(const StackingContextHelper& aStackingContext) { void ClipManager::PushOverrideForASR(const ActiveScrolledRoot* aASR, const wr::WrSpatialId& aSpatialId) { - wr::WrSpatialId space = GetScrollLayer(aASR); + wr::WrSpatialId space = GetSpatialId(aASR); CLIP_LOG("Pushing %p override %zu -> %zu\n", aASR, space.id, aSpatialId.id); auto it = mASROverride.insert({space, std::stack<wr::WrSpatialId>()}); @@ -127,7 +127,7 @@ void ClipManager::PopOverrideForASR(const ActiveScrolledRoot* aASR) { MOZ_ASSERT(!mCacheStack.empty()); mCacheStack.pop(); - wr::WrSpatialId space = GetScrollLayer(aASR); + wr::WrSpatialId space = GetSpatialId(aASR); auto it = mASROverride.find(space); if (it == mASROverride.end()) { MOZ_ASSERT_UNREACHABLE("Push/PopOverrideForASR should be balanced"); @@ -265,7 +265,7 @@ wr::WrSpaceAndClipChain ClipManager::SwitchItem(nsDisplayListBuilder* aBuilder, // for it. clips.mClipChainId = DefineClipChain(clip, auPerDevPixel); - wr::WrSpatialId space = GetScrollLayer(asr); + wr::WrSpatialId space = GetSpatialId(asr); clips.mScrollId = SpatialIdAfterOverride(space); CLIP_LOG("\tassigning %d -> %d\n", (int)space.id, (int)clips.mScrollId.id); @@ -285,10 +285,14 @@ wr::WrSpaceAndClipChain ClipManager::SwitchItem(nsDisplayListBuilder* aBuilder, return spaceAndClipChain; } -wr::WrSpatialId ClipManager::GetScrollLayer(const ActiveScrolledRoot* aASR) { +wr::WrSpatialId ClipManager::GetSpatialId(const ActiveScrolledRoot* aASR) { for (const ActiveScrolledRoot* asr = aASR; asr; asr = asr->mParent) { - Maybe<wr::WrSpatialId> space = - mBuilder->GetScrollIdForDefinedScrollLayer(asr->GetViewId()); + Maybe<wr::WrSpatialId> space = Nothing(); + if (asr->mKind == ActiveScrolledRoot::ASRKind::Sticky) { + space = mBuilder->GetSpatialIdForDefinedStickyLayer(asr); + } else { + space = mBuilder->GetScrollIdForDefinedScrollLayer(asr->GetViewId()); + } if (space) { return *space; } @@ -436,7 +440,7 @@ Maybe<wr::WrClipChainId> ClipManager::DefineClipChain( AutoTArray<wr::ComplexClipRegion, 6> wrRoundedRects; chain->mClip.ToComplexClipRegions(aAppUnitsPerDevPixel, wrRoundedRects); - wr::WrSpatialId space = GetScrollLayer(chain->mASR); + wr::WrSpatialId space = GetSpatialId(chain->mASR); // Define the clip space = SpatialIdAfterOverride(space); diff --git a/gfx/layers/wr/ClipManager.h b/gfx/layers/wr/ClipManager.h @@ -69,7 +69,7 @@ class ClipManager { private: wr::WrSpatialId SpatialIdAfterOverride(const wr::WrSpatialId& aSpatialId); - wr::WrSpatialId GetScrollLayer(const ActiveScrolledRoot* aASR); + wr::WrSpatialId GetSpatialId(const ActiveScrolledRoot* aASR); Maybe<wr::WrSpatialId> DefineScrollLayers(const ActiveScrolledRoot* aASR, nsDisplayItem* aItem); diff --git a/gfx/webrender_bindings/WebRenderAPI.cpp b/gfx/webrender_bindings/WebRenderAPI.cpp @@ -18,6 +18,7 @@ #include "mozilla/webrender/RenderCompositor.h" #include "mozilla/widget/CompositorWidget.h" #include "mozilla/layers/SynchronousTask.h" +#include "nsDisplayList.h" #include "nsThreadUtils.h" #include "TextDrawTarget.h" #include "malloc_decls.h" @@ -1205,6 +1206,7 @@ void DisplayListBuilder::Begin(layers::DisplayItemCache* aCache) { wr_api_begin_builder(mWrState); mScrollIds.clear(); + mASRToSpatialIdMap.clear(); mCurrentSpaceAndClipChain = wr::RootScrollNodeWithChain(); mClipChainLeaf = Nothing(); mSuspendedSpaceAndClipChain = Nothing(); @@ -1341,6 +1343,7 @@ wr::WrClipId DisplayListBuilder::DefineRectClip(Maybe<wr::WrSpatialId> aSpace, } wr::WrSpatialId DisplayListBuilder::DefineStickyFrame( + const ActiveScrolledRoot* aStickyAsr, Maybe<wr::WrSpatialId> aParentSpatialId, const wr::LayoutRect& aContentRect, const float* aTopMargin, const float* aRightMargin, const float* aBottomMargin, const float* aLeftMargin, @@ -1353,6 +1356,8 @@ wr::WrSpatialId DisplayListBuilder::DefineStickyFrame( aContentRect, aTopMargin, aRightMargin, aBottomMargin, aLeftMargin, aVerticalBounds, aHorizontalBounds, aAppliedOffset, aKey, aAnimation); + mASRToSpatialIdMap.emplace(aStickyAsr, spatialId); + WRDL_LOG("DefineSticky id=%zu c=%s t=%s r=%s b=%s l=%s v=%s h=%s a=%s\n", mWrState, spatialId.id, ToString(aContentRect).c_str(), aTopMargin ? ToString(*aTopMargin).c_str() : "none", @@ -1380,6 +1385,17 @@ Maybe<wr::WrSpatialId> DisplayListBuilder::GetScrollIdForDefinedScrollLayer( return Some(it->second); } +Maybe<wr::WrSpatialId> DisplayListBuilder::GetSpatialIdForDefinedStickyLayer( + const ActiveScrolledRoot* aASR) const { + MOZ_ASSERT(aASR->mKind == ActiveScrolledRoot::ASRKind::Sticky); + auto it = mASRToSpatialIdMap.find(aASR); + if (it == mASRToSpatialIdMap.end()) { + return Nothing(); + } + + return Some(it->second); +} + wr::WrSpatialId DisplayListBuilder::DefineScrollLayer( const layers::ScrollableLayerGuid::ViewID& aViewId, const Maybe<wr::WrSpatialId>& aParent, const wr::LayoutRect& aContentRect, diff --git a/gfx/webrender_bindings/WebRenderAPI.h b/gfx/webrender_bindings/WebRenderAPI.h @@ -615,6 +615,7 @@ class DisplayListBuilder final { wr::LayoutRect aClipRect); wr::WrSpatialId DefineStickyFrame( + const ActiveScrolledRoot* aStickyAsr, Maybe<wr::WrSpatialId> aParentSpatialId, const wr::LayoutRect& aContentRect, const float* aTopMargin, const float* aRightMargin, const float* aBottomMargin, @@ -625,6 +626,8 @@ class DisplayListBuilder final { Maybe<wr::WrSpatialId> GetScrollIdForDefinedScrollLayer( layers::ScrollableLayerGuid::ViewID aViewId) const; + Maybe<wr::WrSpatialId> GetSpatialIdForDefinedStickyLayer( + const ActiveScrolledRoot* aASR) const; wr::WrSpatialId DefineScrollLayer( const layers::ScrollableLayerGuid::ViewID& aViewId, const Maybe<wr::WrSpatialId>& aParent, const wr::LayoutRect& aContentRect, @@ -918,6 +921,13 @@ class DisplayListBuilder final { std::unordered_map<layers::ScrollableLayerGuid::ViewID, wr::WrSpatialId> mScrollIds; + // Track spatial ids that we've created corresponding to ActiveScrolledRoot + // objects. Currently only used for sticky ASRs. + // FIXME(follow-up to bug 1730749): Use this for scroll ASRs as well, + // replacing mScrollIds. + std::unordered_map<const ActiveScrolledRoot*, wr::WrSpatialId> + mASRToSpatialIdMap; + wr::WrSpaceAndClipChain mCurrentSpaceAndClipChain; // Contains the current leaf of the clip chain to be merged with the diff --git a/layout/painting/nsDisplayList.cpp b/layout/painting/nsDisplayList.cpp @@ -6043,14 +6043,19 @@ bool nsDisplayStickyPosition::CreateWebRenderCommands( prop->key = spatialKey; prop->effect_type = wr::WrAnimationType::Transform; } - wr::WrSpatialId spatialId = aBuilder.DefineStickyFrame( - Nothing(), wr::ToLayoutRect(bounds), topMargin.ptrOr(nullptr), - rightMargin.ptrOr(nullptr), bottomMargin.ptrOr(nullptr), - leftMargin.ptrOr(nullptr), vBounds, hBounds, applied, spatialKey, - prop.ptrOr(nullptr)); - - saccHelper.emplace(aBuilder, spatialId); - aManager->CommandBuilder().PushOverrideForASR(mContainerASR, spatialId); + aBuilder.DefineStickyFrame( + mStickyASR, Nothing(), wr::ToLayoutRect(bounds), + topMargin.ptrOr(nullptr), rightMargin.ptrOr(nullptr), + bottomMargin.ptrOr(nullptr), leftMargin.ptrOr(nullptr), vBounds, + hBounds, applied, spatialKey, prop.ptrOr(nullptr)); + + const ActiveScrolledRoot* stickyAsr = + ActiveScrolledRoot::GetStickyASRFromFrame(mFrame); + MOZ_ASSERT(stickyAsr); + auto spatialId = aBuilder.GetSpatialIdForDefinedStickyLayer(stickyAsr); + MOZ_ASSERT(spatialId.isSome()); + saccHelper.emplace(aBuilder, *spatialId); + aManager->CommandBuilder().PushOverrideForASR(mContainerASR, *spatialId); } {