Bug 1800133 - Minor perf improvements to DefineClipChain. r=gfx-reviewers,nical

This removes a redundant hashmap lookup.

Depends on D161888

Differential Revision: https://phabricator.services.mozilla.com/D161889
This commit is contained in:
Emilio Cobos Álvarez 2022-11-14 13:20:26 +00:00
Родитель e683cac799
Коммит c1afe63a38
2 изменённых файлов: 13 добавлений и 14 удалений

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

@ -394,22 +394,25 @@ Maybe<wr::WrSpatialId> ClipManager::DefineScrollLayers(
Maybe<wr::WrClipChainId> ClipManager::DefineClipChain(
const DisplayItemClipChain* aChain, int32_t aAppUnitsPerDevPixel) {
MOZ_ASSERT(!mCacheStack.empty());
AutoTArray<wr::WrClipId, 6> allClipIds;
ClipIdMap& cache = mCacheStack.top();
// Iterate through the clips in the current item's clip chain, define them
// in WR, and put their IDs into |clipIds|.
for (const DisplayItemClipChain* chain = aChain; chain;
chain = chain->mParent) {
ClipIdMap& cache = mCacheStack.top();
auto it = cache.find(chain);
if (it != cache.end()) {
if (!chain->mClip.HasClip()) {
// This item in the chain is a no-op, skip over it
continue;
}
auto emplaceResult = cache.try_emplace(chain);
auto& chainClipIds = emplaceResult.first->second;
if (!emplaceResult.second) {
// Found it in the currently-active cache, so just use the id we have for
// it.
CLIP_LOG("cache[%p] => hit\n", chain);
allClipIds.AppendElements(it->second);
continue;
}
if (!chain->mClip.HasClip()) {
// This item in the chain is a no-op, skip over it
allClipIds.AppendElements(chainClipIds);
continue;
}
@ -426,8 +429,6 @@ Maybe<wr::WrClipChainId> ClipManager::DefineClipChain(
// Define the clip
*space = SpatialIdAfterOverride(*space);
AutoTArray<wr::WrClipId, 4> chainClipIds;
auto rectClipId = mBuilder->DefineRectClip(space, wr::ToLayoutRect(clip));
CLIP_LOG("cache[%p] <= %zu\n", chain, rectClipId.id);
chainClipIds.AppendElement(rectClipId);
@ -438,7 +439,6 @@ Maybe<wr::WrClipChainId> ClipManager::DefineClipChain(
chainClipIds.AppendElement(complexClipId);
}
cache[chain] = chainClipIds.Clone();
allClipIds.AppendElements(chainClipIds);
}

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

@ -93,9 +93,8 @@ class ClipManager {
// general we need to do this anytime PushOverrideForASR is called, as that is
// called for the same set of conditions for which we cannot deduplicate
// clips.
typedef std::unordered_map<const DisplayItemClipChain*,
AutoTArray<wr::WrClipId, 4>>
ClipIdMap;
using ClipIdMap = std::unordered_map<const DisplayItemClipChain*,
AutoTArray<wr::WrClipId, 4>>;
std::stack<ClipIdMap> mCacheStack;
// A map that holds the cache overrides created by (a) "out of band" clips,