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 Vector<GeometryMapperClipCache::ClipCacheEntry>* | |
21 GeometryMapperClipCache::getClipCacheEntries() { | |
22 if (m_cacheGeneration != s_clipCacheGeneration || !m_clipCache) { | |
23 m_clipCache.reset(new Vector<ClipCacheEntry>); | |
24 m_cacheGeneration = s_clipCacheGeneration; | |
25 } | |
26 | |
27 return m_clipCache.get(); | |
28 } | |
29 | |
30 const FloatClipRect* GeometryMapperClipCache::getCachedClip( | |
31 const ClipAndTransform& clipAndTransform) { | |
32 auto* clipCacheEntries = | |
33 const_cast<GeometryMapperClipCache*>(this)->getClipCacheEntries(); | |
34 for (const auto& entry : *clipCacheEntries) { | |
35 if (entry.clipAndTransform == clipAndTransform) { | |
36 return &entry.clipRect; | |
37 } | |
38 } | |
39 return nullptr; | |
40 } | |
41 | |
42 void GeometryMapperClipCache::setCachedClip( | |
43 const ClipAndTransform& clipAndTransform, | |
44 const FloatClipRect& clip) { | |
45 auto* clipCacheEntries = | |
46 const_cast<GeometryMapperClipCache*>(this)->getClipCacheEntries(); | |
47 #if DCHECK_IS_ON | |
pdr.
2017/03/08 02:34:55
DCHECK_IS_ON()
chrishtr
2017/03/08 02:59:28
Done.
| |
48 for (const auto& entry : clipCachEntries) { | |
49 if (entry.clipAndTransform == clipAndTransform) | |
50 DCHECK(false); // There should be no existing entry. | |
51 } | |
52 #endif | |
53 clipCacheEntries->push_back(ClipCacheEntry(clipAndTransform, clip)); | |
54 } | |
55 | |
56 } // namespace blink | |
OLD | NEW |