Bug 1412112 - Cache the view id on the ASR to speed up the ViewIDForASR operation. r=mstange

This also moves the function from nsLayoutUtils to be a function on the
ASR itself, which seems more appropriate.

MozReview-Commit-ID: 88lUmYi80P0

--HG--
extra : rebase_source : 3f7e4f875c3267f9f4c5c67e720912ceedb25719
This commit is contained in:
Kartikaya Gupta 2017-11-23 12:22:22 -05:00
Родитель f3a3381969
Коммит 86ac46d3f7
7 изменённых файлов: 25 добавлений и 20 удалений

Просмотреть файл

@ -109,7 +109,7 @@ ScrollingLayersHelper::BeginItem(nsDisplayItem* aItem,
FrameMetrics::ViewID leafmostId = ids.first.valueOr(FrameMetrics::NULL_SCROLL_ID);
FrameMetrics::ViewID scrollId = aItem->GetActiveScrolledRoot()
? nsLayoutUtils::ViewIDForASR(aItem->GetActiveScrolledRoot())
? aItem->GetActiveScrolledRoot()->GetViewId()
: FrameMetrics::NULL_SCROLL_ID;
// If the leafmost ASR is not the same as the item's ASR then we are dealing
// with a case where the item's clip chain is scrolled by something other than
@ -237,7 +237,7 @@ ScrollingLayersHelper::RecurseAndDefineClip(nsDisplayItem* aItem,
if (ids.second) {
// If we've already got an id for this clip, we can early-exit
if (aAsr) {
FrameMetrics::ViewID scrollId = nsLayoutUtils::ViewIDForASR(aAsr);
FrameMetrics::ViewID scrollId = aAsr->GetViewId();
MOZ_ASSERT(mBuilder->IsScrollLayerDefined(scrollId));
ids.first = Some(scrollId);
}
@ -276,7 +276,7 @@ ScrollingLayersHelper::RecurseAndDefineClip(nsDisplayItem* aItem,
}
} else {
MOZ_ASSERT(!ancestorIds.second);
FrameMetrics::ViewID scrollId = aChain->mASR ? nsLayoutUtils::ViewIDForASR(aChain->mASR) : FrameMetrics::NULL_SCROLL_ID;
FrameMetrics::ViewID scrollId = aChain->mASR ? aChain->mASR->GetViewId() : FrameMetrics::NULL_SCROLL_ID;
if (mBuilder->TopmostScrollId() == scrollId) {
if (mBuilder->TopmostIsClip()) {
// If aChain->mASR is already the topmost scroll layer on the stack, but
@ -344,7 +344,7 @@ ScrollingLayersHelper::RecurseAndDefineAsr(nsDisplayItem* aItem,
// This will hold our return value
std::pair<Maybe<FrameMetrics::ViewID>, Maybe<wr::WrClipId>> ids;
FrameMetrics::ViewID scrollId = nsLayoutUtils::ViewIDForASR(aAsr);
FrameMetrics::ViewID scrollId = aAsr->GetViewId();
if (mBuilder->IsScrollLayerDefined(scrollId)) {
// If we've already defined this scroll layer before, we can early-exit
ids.first = Some(scrollId);

Просмотреть файл

@ -54,7 +54,7 @@ WebRenderLayerScrollData::Initialize(WebRenderScrollData& aOwner,
asr && asr != aStopAtAsr;
asr = asr->mParent) {
MOZ_ASSERT(aOwner.GetManager());
FrameMetrics::ViewID scrollId = nsLayoutUtils::ViewIDForASR(asr);
FrameMetrics::ViewID scrollId = asr->GetViewId();
if (Maybe<size_t> index = aOwner.HasMetadataFor(scrollId)) {
mScrollIds.AppendElement(index.ref());
} else {

Просмотреть файл

@ -868,13 +868,6 @@ nsLayoutUtils::FindContentFor(ViewID aId)
}
}
ViewID
nsLayoutUtils::ViewIDForASR(const mozilla::ActiveScrolledRoot* aASR)
{
nsIContent* content = aASR->mScrollableFrame->GetScrolledFrame()->GetContent();
return nsLayoutUtils::FindOrCreateIDFor(content);
}
nsIFrame*
GetScrollFrameFromContent(nsIContent* aContent)
{

Просмотреть файл

@ -186,12 +186,6 @@ public:
*/
static nsIContent* FindContentFor(ViewID aId);
/**
* Find the view ID (or generate a new one) for the content element
* corresponding to the ASR.
*/
static ViewID ViewIDForASR(const mozilla::ActiveScrolledRoot* aASR);
/**
* Find the scrollable frame for a given ID.
*/

Просмотреть файл

@ -5037,7 +5037,7 @@ FixUpFixedPositionLayer(Layer* aLayer,
if (compositorASR && aTargetASR != compositorASR) {
// Mark this layer as fixed with respect to the child scroll frame of aTargetASR.
aLayer->SetFixedPositionData(
nsLayoutUtils::ViewIDForASR(FindDirectChildASR(aTargetASR, compositorASR)),
FindDirectChildASR(aTargetASR, compositorASR)->GetViewId(),
aLayer->GetFixedPositionAnchor(),
aLayer->GetFixedPositionSides());
} else {

Просмотреть файл

@ -4905,7 +4905,7 @@ nsDisplayCompositorHitTestInfo::CreateWebRenderCommands(mozilla::wr::DisplayList
// this display item).
FrameMetrics::ViewID scrollId = FrameMetrics::NULL_SCROLL_ID;
if (const ActiveScrolledRoot* asr = GetActiveScrolledRoot()) {
scrollId = nsLayoutUtils::ViewIDForASR(asr);
scrollId = asr->GetViewId();
}
// Insert a transparent rectangle with the hit-test info

Просмотреть файл

@ -262,6 +262,7 @@ struct ActiveScrolledRoot {
}
asr->mParent = aParent;
asr->mScrollableFrame = aScrollableFrame;
asr->mViewId = Nothing();
asr->mDepth = aParent ? aParent->mDepth + 1 : 1;
asr->mRetained = aIsRetained;
@ -290,6 +291,18 @@ struct ActiveScrolledRoot {
// Call this when inserting an ancestor.
void IncrementDepth() { mDepth++; }
/**
* Find the view ID (or generate a new one) for the content element
* corresponding to the ASR.
*/
mozilla::layers::FrameMetrics::ViewID GetViewId() const {
if (!mViewId.isSome()) {
nsIContent* content = mScrollableFrame->GetScrolledFrame()->GetContent();
mViewId = Some(nsLayoutUtils::FindOrCreateIDFor(content));
}
return *mViewId;
}
RefPtr<const ActiveScrolledRoot> mParent;
nsIScrollableFrame* mScrollableFrame;
@ -319,6 +332,11 @@ private:
return aActiveScrolledRoot ? aActiveScrolledRoot->mDepth : 0;
}
// This field is lazily populated in GetViewId(). We don't want to do the
// work of populating if webrender is disabled, because it is often not
// needed.
mutable Maybe<mozilla::layers::FrameMetrics::ViewID> mViewId;
uint32_t mDepth;
bool mRetained;
};