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

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

Issue 2729243002: Improve performance of GeometryMapper cache. (Closed)
Patch Set: none 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/GeometryMapperTransformCache.cpp
diff --git a/third_party/WebKit/Source/platform/graphics/paint/GeometryMapperTransformCache.cpp b/third_party/WebKit/Source/platform/graphics/paint/GeometryMapperTransformCache.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..f05db6f5d27a228224033f4615096ebd2710ec47
--- /dev/null
+++ b/third_party/WebKit/Source/platform/graphics/paint/GeometryMapperTransformCache.cpp
@@ -0,0 +1,52 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "platform/graphics/paint/GeometryMapperTransformCache.h"
+
+namespace blink {
+
+// All transform caches invalidate themselves by tracking a local cache
+// generation, and invalidating their cache if their cache generation disagrees
+// with s_transformCacheGeneration.
+static unsigned s_transformCacheGeneration = 0;
+
+GeometryMapperTransformCache::GeometryMapperTransformCache()
+ : m_cacheGeneration(s_transformCacheGeneration) {}
+
+void GeometryMapperTransformCache::clearCache() {
+ s_transformCacheGeneration++;
+}
+
+void GeometryMapperTransformCache::invalidateCacheIfNeeded() {
+ if (m_cacheGeneration != s_transformCacheGeneration) {
+ m_transformCache.clear();
+ m_cacheGeneration = s_transformCacheGeneration;
+ }
+}
+
+const TransformationMatrix* GeometryMapperTransformCache::getCachedTransform(
+ const TransformPaintPropertyNode* ancestorTransform) {
+ invalidateCacheIfNeeded();
+ for (const auto& entry : m_transformCache) {
+ if (entry.ancestorNode == ancestorTransform) {
+ return &entry.toAncestor;
+ }
+ }
+ return nullptr;
+}
+
+void GeometryMapperTransformCache::setCachedTransform(
+ const TransformPaintPropertyNode* ancestorTransform,
+ const TransformationMatrix& matrix) {
+ invalidateCacheIfNeeded();
+#if DCHECK_IS_ON()
+ for (const auto& entry : m_transformCache) {
+ if (entry.ancestorNode == ancestorTransform)
+ DCHECK(false); // There should be no existing entry.
+ }
+#endif
+ m_transformCache.push_back(TransformCacheEntry(ancestorTransform, matrix));
+}
+
+} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698