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

Unified Diff: third_party/WebKit/Source/platform/graphics/paint/GeometryMapperClipCache.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/GeometryMapperClipCache.cpp
diff --git a/third_party/WebKit/Source/platform/graphics/paint/GeometryMapperClipCache.cpp b/third_party/WebKit/Source/platform/graphics/paint/GeometryMapperClipCache.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..5dd8982781fbfb34038b7f1f2a716afafc92277a
--- /dev/null
+++ b/third_party/WebKit/Source/platform/graphics/paint/GeometryMapperClipCache.cpp
@@ -0,0 +1,54 @@
+// 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/GeometryMapperClipCache.h"
+
+#include "platform/graphics/paint/FloatClipRect.h"
+
+namespace blink {
+
+// All clip caches invalidate themselves by tracking a local cache generation,
+// and invalidating their cache if their cache generation disagrees with
+// s_clipCacheGeneration.
+static unsigned s_clipCacheGeneration = 0;
+
+GeometryMapperClipCache::GeometryMapperClipCache()
+ : m_cacheGeneration(s_clipCacheGeneration) {}
+
+void GeometryMapperClipCache::clearCache() {
+ s_clipCacheGeneration++;
+}
+
+void GeometryMapperClipCache::invalidateCacheIfNeeded() {
+ if (m_cacheGeneration != s_clipCacheGeneration) {
+ m_clipCache.clear();
+ m_cacheGeneration = s_clipCacheGeneration;
+ }
+}
+
+const FloatClipRect* GeometryMapperClipCache::getCachedClip(
+ const ClipAndTransform& clipAndTransform) {
+ invalidateCacheIfNeeded();
+ for (const auto& entry : m_clipCache) {
+ if (entry.clipAndTransform == clipAndTransform) {
+ return &entry.clipRect;
+ }
+ }
+ return nullptr;
+}
+
+void GeometryMapperClipCache::setCachedClip(
+ const ClipAndTransform& clipAndTransform,
+ const FloatClipRect& clip) {
+ invalidateCacheIfNeeded();
+#if DCHECK_IS_ON()
+ for (const auto& entry : m_clipCache) {
+ if (entry.clipAndTransform == clipAndTransform)
+ DCHECK(false); // There should be no existing entry.
+ }
+#endif
+ m_clipCache.push_back(ClipCacheEntry(clipAndTransform, clip));
+}
+
+} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698