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 GeometryMapperTransformCache::GeometryMapperTransformCache() |
| 15 : m_cacheGeneration(s_transformCacheGeneration) {} |
| 16 |
| 17 void GeometryMapperTransformCache::clearCache() { |
| 18 s_transformCacheGeneration++; |
| 19 } |
| 20 |
| 21 void GeometryMapperTransformCache::invalidateCacheIfNeeded() { |
| 22 if (m_cacheGeneration != s_transformCacheGeneration) { |
| 23 m_transformCache.clear(); |
| 24 m_cacheGeneration = s_transformCacheGeneration; |
| 25 } |
| 26 } |
| 27 |
| 28 const TransformationMatrix* GeometryMapperTransformCache::getCachedTransform( |
| 29 const TransformPaintPropertyNode* ancestorTransform) { |
| 30 invalidateCacheIfNeeded(); |
| 31 for (const auto& entry : m_transformCache) { |
| 32 if (entry.ancestorNode == ancestorTransform) { |
| 33 return &entry.toAncestor; |
| 34 } |
| 35 } |
| 36 return nullptr; |
| 37 } |
| 38 |
| 39 void GeometryMapperTransformCache::setCachedTransform( |
| 40 const TransformPaintPropertyNode* ancestorTransform, |
| 41 const TransformationMatrix& matrix) { |
| 42 invalidateCacheIfNeeded(); |
| 43 #if DCHECK_IS_ON() |
| 44 for (const auto& entry : m_transformCache) { |
| 45 if (entry.ancestorNode == ancestorTransform) |
| 46 DCHECK(false); // There should be no existing entry. |
| 47 } |
| 48 #endif |
| 49 m_transformCache.push_back(TransformCacheEntry(ancestorTransform, matrix)); |
| 50 } |
| 51 |
| 52 } // namespace blink |
OLD | NEW |