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/GeometryMapperTransformCache.h" | |
6 | |
7 namespace blink { | |
8 | |
9 // All transform caches invalidate themselves by tracking a local cache | |
10 // generation, and invalidating their cache if their cache generation disagrees | |
11 // with s_transformCacheGeneration. | |
12 static unsigned s_transformCacheGeneration = 0; | |
13 | |
14 void GeometryMapperTransformCache::clearCache() { | |
15 s_transformCacheGeneration++; | |
16 } | |
17 | |
18 void GeometryMapperTransformCache::invalidateCacheIfNeeded() { | |
19 if (m_cacheGeneration != s_transformCacheGeneration) { | |
20 m_transformCache.clear(); | |
21 m_cacheGeneration = s_transformCacheGeneration; | |
22 } | |
23 } | |
24 | |
25 const TransformationMatrix* GeometryMapperTransformCache::getCachedTransform( | |
26 const TransformPaintPropertyNode* ancestorTransform) { | |
27 invalidateCacheIfNeeded(); | |
28 for (const auto& entry : m_transformCache) { | |
29 if (entry.ancestorNode == ancestorTransform) { | |
30 return &entry.toAncestor; | |
31 } | |
32 } | |
33 return nullptr; | |
34 } | |
35 | |
36 void GeometryMapperTransformCache::setCachedTransform( | |
37 const TransformPaintPropertyNode* ancestorTransform, | |
38 const TransformationMatrix& matrix) { | |
39 invalidateCacheIfNeeded(); | |
40 #if DCHECK_IS_ON() | |
41 for (const auto& entry : m_transformCache) { | |
42 if (entry.ancestorNode == ancestorTransform) | |
43 DCHECK(false); // There should be no existing entry. | |
44 } | |
45 #endif | |
46 m_transformCache.push_back(TransformCacheEntry(ancestorTransform, matrix)); | |
47 } | |
48 | |
49 } // namespace blink | |
OLD | NEW |