From 4fa43ed7feac1f9929dfb96846828642074d9de3 Mon Sep 17 00:00:00 2001 From: Botond Ballo Date: Fri, 6 Sep 2019 08:39:52 +0000 Subject: [PATCH] Bug 1576524 - Clean up APZCTreeManager::mDetachedLayersIds in UpdateHitTestingTree. r=tnikkel This ensures that mDetachedLayersIds doesn't grow indefinitely. Differential Revision: https://phabricator.services.mozilla.com/D44741 --HG-- extra : moz-landing-system : lando --- gfx/layers/apz/src/APZCTreeManager.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/gfx/layers/apz/src/APZCTreeManager.cpp b/gfx/layers/apz/src/APZCTreeManager.cpp index 392f922673d1..cb22b77bbb9a 100644 --- a/gfx/layers/apz/src/APZCTreeManager.cpp +++ b/gfx/layers/apz/src/APZCTreeManager.cpp @@ -407,11 +407,13 @@ APZCTreeManager::UpdateHitTestingTreeImpl(const ScrollNode& aRoot, bool haveRootContentOutsideAsyncZoomContainer = false; if (aRoot) { + std::unordered_set seenLayersIds; std::stack> indents; std::stack ancestorTransforms; HitTestingTreeNode* parent = nullptr; HitTestingTreeNode* next = nullptr; LayersId layersId = mRootLayersId; + seenLayersIds.insert(mRootLayersId); std::stack renderRoots; renderRoots.push(wr::RenderRoot::Default); ancestorTransforms.push(AncestorTransform()); @@ -489,6 +491,7 @@ APZCTreeManager::UpdateHitTestingTreeImpl(const ScrollNode& aRoot, // Update the layersId or renderroot if we have a new one if (Maybe newLayersId = aLayerMetrics.GetReferentId()) { layersId = *newLayersId; + seenLayersIds.insert(layersId); } if (Maybe newRenderRoot = aLayerMetrics.GetReferentRenderRoot()) { @@ -558,6 +561,19 @@ APZCTreeManager::UpdateHitTestingTreeImpl(const ScrollNode& aRoot, } }); } + + // Remove any layers ids for which we no longer have content from + // mDetachedLayersIds. + for (auto iter = mDetachedLayersIds.begin(); + iter != mDetachedLayersIds.end();) { + // unordered_set::erase() invalidates the iterator pointing to the + // element being erased, but returns an iterator to the next element. + if (seenLayersIds.find(*iter) == seenLayersIds.end()) { + iter = mDetachedLayersIds.erase(iter); + } else { + ++iter; + } + } } // We do not support tree structures where the root node has siblings.