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 GeometryMapperClipCache::GeometryMapperClipCache() |
| 17 : m_cacheGeneration(s_clipCacheGeneration) {} |
| 18 |
| 19 void GeometryMapperClipCache::clearCache() { |
| 20 s_clipCacheGeneration++; |
| 21 } |
| 22 |
| 23 void GeometryMapperClipCache::invalidateCacheIfNeeded() { |
| 24 if (m_cacheGeneration != s_clipCacheGeneration) { |
| 25 m_clipCache.clear(); |
| 26 m_cacheGeneration = s_clipCacheGeneration; |
| 27 } |
| 28 } |
| 29 |
| 30 const FloatClipRect* GeometryMapperClipCache::getCachedClip( |
| 31 const ClipAndTransform& clipAndTransform) { |
| 32 invalidateCacheIfNeeded(); |
| 33 for (const auto& entry : m_clipCache) { |
| 34 if (entry.clipAndTransform == clipAndTransform) { |
| 35 return &entry.clipRect; |
| 36 } |
| 37 } |
| 38 return nullptr; |
| 39 } |
| 40 |
| 41 void GeometryMapperClipCache::setCachedClip( |
| 42 const ClipAndTransform& clipAndTransform, |
| 43 const FloatClipRect& clip) { |
| 44 invalidateCacheIfNeeded(); |
| 45 #if DCHECK_IS_ON() |
| 46 for (const auto& entry : m_clipCache) { |
| 47 if (entry.clipAndTransform == clipAndTransform) |
| 48 DCHECK(false); // There should be no existing entry. |
| 49 } |
| 50 #endif |
| 51 m_clipCache.push_back(ClipCacheEntry(clipAndTransform, clip)); |
| 52 } |
| 53 |
| 54 } // namespace blink |
OLD | NEW |