Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(770)

Unified Diff: third_party/WebKit/Source/platform/graphics/paint/GeometryMapper.cpp

Issue 2738113003: Revert of Improve performance of GeometryMapper cache. (Closed)
Patch Set: Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/platform/graphics/paint/GeometryMapper.cpp
diff --git a/third_party/WebKit/Source/platform/graphics/paint/GeometryMapper.cpp b/third_party/WebKit/Source/platform/graphics/paint/GeometryMapper.cpp
index 733cd67c26aeb10382b9a7bc3fe6202527124a5d..00d8f6f89aefaff65351bbac09b79cef93242cba 100644
--- a/third_party/WebKit/Source/platform/graphics/paint/GeometryMapper.cpp
+++ b/third_party/WebKit/Source/platform/graphics/paint/GeometryMapper.cpp
@@ -214,6 +214,31 @@
return transformMatrix.inverse().mapRect(rect);
}
+GeometryMapper::TransformCache& GeometryMapper::getTransformCache(
+ const TransformPaintPropertyNode* ancestor) {
+ auto addResult = m_transformCache.insert(ancestor, nullptr);
+ if (addResult.isNewEntry)
+ addResult.storedValue->value = WTF::wrapUnique(new TransformCache);
+ return *addResult.storedValue->value;
+}
+
+GeometryMapper::ClipCache& GeometryMapper::getClipCache(
+ const ClipPaintPropertyNode* ancestorClip,
+ const TransformPaintPropertyNode* ancestorTransform) {
+ auto addResultTransform = m_clipCache.insert(ancestorClip, nullptr);
+ if (addResultTransform.isNewEntry) {
+ addResultTransform.storedValue->value =
+ WTF::wrapUnique(new TransformToClip);
+ }
+
+ auto addResultClip =
+ addResultTransform.storedValue->value->insert(ancestorTransform, nullptr);
+ if (addResultClip.isNewEntry)
+ addResultClip.storedValue->value = WTF::wrapUnique(new ClipCache);
+
+ return *addResultClip.storedValue->value;
+}
+
FloatClipRect GeometryMapper::localToAncestorClipRect(
const PropertyTreeState& localState,
const PropertyTreeState& ancestorState) {
@@ -249,8 +274,7 @@
if (success)
return result;
- // Otherwise first map to the lowest common ancestor, then map to
- // destination.
+ // Otherwise first map to the lowest common ancestor, then map to destination.
const TransformPaintPropertyNode* lcaTransform = lowestCommonAncestor(
sourceState.transform(), destinationState.transform());
DCHECK(lcaTransform);
@@ -267,9 +291,9 @@
if (!RuntimeEnabledFeatures::slimmingPaintV2Enabled()) {
// On SPv1 we may fail when the paint invalidation container creates an
// overflow clip (in ancestorState) which is not in localState of an
- // out-of-flow positioned descendant. See crbug.com/513108 and layout
- // test compositing/overflow/handle-non-ancestor-clip-parent.html (run
- // with --enable-prefer-compositing-to-lcd-text) for details.
+ // out-of-flow positioned descendant. See crbug.com/513108 and layout test
+ // compositing/overflow/handle-non-ancestor-clip-parent.html (run with
+ // --enable-prefer-compositing-to-lcd-text) for details.
// Ignore it for SPv1 for now.
success = true;
}
@@ -283,7 +307,7 @@
return result;
}
-const FloatClipRect& GeometryMapper::localToAncestorClipRectInternal(
+FloatClipRect GeometryMapper::localToAncestorClipRectInternal(
const ClipPaintPropertyNode* descendant,
const ClipPaintPropertyNode* ancestorClip,
const TransformPaintPropertyNode* ancestorTransform,
@@ -291,29 +315,28 @@
FloatClipRect clip;
if (descendant == ancestorClip) {
success = true;
- return m_infiniteClip;
- }
-
+ // Return an infinite clip.
+ return clip;
+ }
+
+ ClipCache& clipCache = getClipCache(ancestorClip, ancestorTransform);
const ClipPaintPropertyNode* clipNode = descendant;
Vector<const ClipPaintPropertyNode*> intermediateNodes;
- GeometryMapperClipCache::ClipAndTransform clipAndTransform(ancestorClip,
- ancestorTransform);
// Iterate over the path from localState.clip to ancestorState.clip. Stop if
// we've found a memoized (precomputed) clip for any particular node.
while (clipNode && clipNode != ancestorClip) {
- if (const FloatClipRect* cachedClip =
- clipNode->getClipCache().getCachedClip(clipAndTransform)) {
- clip = *cachedClip;
+ auto it = clipCache.find(clipNode);
+ if (it != clipCache.end()) {
+ clip = it->value;
break;
}
-
intermediateNodes.push_back(clipNode);
clipNode = clipNode->parent();
}
if (!clipNode) {
success = false;
- return m_infiniteClip;
+ return clip;
}
// Iterate down from the top intermediate node found in the previous loop,
@@ -324,20 +347,16 @@
const TransformationMatrix& transformMatrix = localToAncestorMatrixInternal(
(*it)->localTransformSpace(), ancestorTransform, success);
if (!success)
- return m_infiniteClip;
+ return clip;
FloatRect mappedRect = transformMatrix.mapRect((*it)->clipRect().rect());
clip.intersect(mappedRect);
if ((*it)->clipRect().isRounded())
clip.setHasRadius();
- (*it)->getClipCache().setCachedClip(clipAndTransform, clip);
+ clipCache.set(*it, clip);
}
success = true;
-
- const FloatClipRect* cachedClip =
- descendant->getClipCache().getCachedClip(clipAndTransform);
- DCHECK(cachedClip);
- return *cachedClip;
+ return clipCache.find(descendant)->value;
}
const TransformationMatrix& GeometryMapper::localToAncestorMatrix(
@@ -358,6 +377,8 @@
success = true;
return m_identity;
}
+
+ TransformCache& transformCache = getTransformCache(ancestorTransformNode);
const TransformPaintPropertyNode* transformNode = localTransformNode;
Vector<const TransformPaintPropertyNode*> intermediateNodes;
@@ -367,13 +388,11 @@
// Stop if we've found a memoized (precomputed) transform for any particular
// node.
while (transformNode && transformNode != ancestorTransformNode) {
- if (const TransformationMatrix* cachedMatrix =
- transformNode->getTransformCache().getCachedTransform(
- ancestorTransformNode)) {
- transformMatrix = *cachedMatrix;
+ auto it = transformCache.find(transformNode);
+ if (it != transformCache.end()) {
+ transformMatrix = it->value;
break;
}
-
intermediateNodes.push_back(transformNode);
transformNode = transformNode->parent();
}
@@ -389,20 +408,15 @@
TransformationMatrix localTransformMatrix = (*it)->matrix();
localTransformMatrix.applyTransformOrigin((*it)->origin());
transformMatrix = transformMatrix * localTransformMatrix;
- (*it)->getTransformCache().setCachedTransform(ancestorTransformNode,
- transformMatrix);
+ transformCache.set(*it, transformMatrix);
}
success = true;
- const TransformationMatrix* cachedMatrix =
- localTransformNode->getTransformCache().getCachedTransform(
- ancestorTransformNode);
- DCHECK(cachedMatrix);
- return *cachedMatrix;
+ return transformCache.find(localTransformNode)->value;
}
void GeometryMapper::clearCache() {
- GeometryMapperTransformCache::clearCache();
- GeometryMapperClipCache::clearCache();
+ m_transformCache.clear();
+ m_clipCache.clear();
}
namespace {

Powered by Google App Engine
This is Rietveld 408576698