OLD | NEW |
| (Empty) |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "platform/graphics/paint/GeometryMapperClipCache.h" | |
6 | |
7 #include "platform/graphics/paint/FloatClipRect.h" | |
8 | |
9 namespace blink { | |
10 | |
11 // All clip caches invalidate themselves by tracking a local cache generation, | |
12 // and invalidating their cache if their cache generation disagrees with | |
13 // s_clipCacheGeneration. | |
14 static unsigned s_clipCacheGeneration = 0; | |
15 | |
16 void GeometryMapperClipCache::clearCache() { | |
17 s_clipCacheGeneration++; | |
18 } | |
19 | |
20 void GeometryMapperClipCache::invalidateCacheIfNeeded() { | |
21 if (m_cacheGeneration != s_clipCacheGeneration) { | |
22 m_clipCache.clear(); | |
23 m_cacheGeneration = s_clipCacheGeneration; | |
24 } | |
25 } | |
26 | |
27 const FloatClipRect* GeometryMapperClipCache::getCachedClip( | |
28 const ClipAndTransform& clipAndTransform) { | |
29 invalidateCacheIfNeeded(); | |
30 for (const auto& entry : m_clipCache) { | |
31 if (entry.clipAndTransform == clipAndTransform) { | |
32 return &entry.clipRect; | |
33 } | |
34 } | |
35 return nullptr; | |
36 } | |
37 | |
38 void GeometryMapperClipCache::setCachedClip( | |
39 const ClipAndTransform& clipAndTransform, | |
40 const FloatClipRect& clip) { | |
41 invalidateCacheIfNeeded(); | |
42 #if DCHECK_IS_ON() | |
43 for (const auto& entry : m_clipCache) { | |
44 if (entry.clipAndTransform == clipAndTransform) | |
45 DCHECK(false); // There should be no existing entry. | |
46 } | |
47 #endif | |
48 m_clipCache.push_back(ClipCacheEntry(clipAndTransform, clip)); | |
49 } | |
50 | |
51 } // namespace blink | |
OLD | NEW |