Index: third_party/WebKit/Source/platform/graphics/paint/ClipPaintPropertyNode.cpp |
diff --git a/third_party/WebKit/Source/platform/graphics/paint/ClipPaintPropertyNode.cpp b/third_party/WebKit/Source/platform/graphics/paint/ClipPaintPropertyNode.cpp |
index 0a718c46c57d4c9b666cbfe9bc246b3a99e812fe..7b7ce34a41c2f11fa22f4c7fd5606f99d02016bf 100644 |
--- a/third_party/WebKit/Source/platform/graphics/paint/ClipPaintPropertyNode.cpp |
+++ b/third_party/WebKit/Source/platform/graphics/paint/ClipPaintPropertyNode.cpp |
@@ -9,6 +9,22 @@ |
namespace blink { |
+// All clip caches invalidate themselves by tracking a local cache generation, |
+// and invalidating their cache if their cache generation disagrees with |
+// s_clipCacheGeneration. |
+static unsigned s_clipCacheGeneration = 0; |
+ |
+ClipPaintPropertyNode::ClipPaintPropertyNode( |
+ PassRefPtr<const ClipPaintPropertyNode> parent, |
+ PassRefPtr<const TransformPaintPropertyNode> localTransformSpace, |
+ const FloatRoundedRect& clipRect, |
+ CompositingReasons directCompositingReasons) |
+ : m_parent(parent), |
+ m_localTransformSpace(localTransformSpace), |
+ m_clipRect(clipRect), |
+ m_directCompositingReasons(directCompositingReasons), |
+ m_cacheGeneration(s_clipCacheGeneration) {} |
+ |
ClipPaintPropertyNode* ClipPaintPropertyNode::root() { |
DEFINE_STATIC_REF(ClipPaintPropertyNode, root, |
(ClipPaintPropertyNode::create( |
@@ -34,4 +50,45 @@ String ClipPaintPropertyNode::toTreeString() const { |
#endif |
+void ClipPaintPropertyNode::clearCache() { |
+ s_clipCacheGeneration++; |
+} |
+ |
+Vector<ClipPaintPropertyNode::ClipCacheEntry>* |
+ClipPaintPropertyNode::getClipCacheEntries() { |
+ if (m_cacheGeneration != s_clipCacheGeneration || !m_clipCache) { |
+ m_clipCache.reset(new Vector<ClipCacheEntry>); |
+ m_cacheGeneration = s_clipCacheGeneration; |
+ } |
+ |
+ return m_clipCache.get(); |
+} |
+ |
+const FloatClipRect* ClipPaintPropertyNode::getCachedClip( |
+ const ClipAndTransform& clipAndTransform) const { |
+ auto* clipCacheEntries = |
+ const_cast<ClipPaintPropertyNode*>(this)->getClipCacheEntries(); |
+ for (const auto& entry : *clipCacheEntries) { |
+ if (entry.clipAndTransform == clipAndTransform) { |
+ return &entry.clipRect; |
+ } |
+ } |
+ return nullptr; |
+} |
+ |
+void ClipPaintPropertyNode::setCachedClip( |
+ const ClipAndTransform& clipAndTransform, |
+ const FloatClipRect& clip) const { |
+ auto* clipCacheEntries = |
+ const_cast<ClipPaintPropertyNode*>(this)->getClipCacheEntries(); |
+#if DCHECK_IS_ON |
+ for (const auto& entry : clipCachEntries) { |
+ if (entry.clipAndTransform == clipAndTransform) |
+ DCHECK(false); // There should be no existing entry. |
+ } |
+#endif |
+ clipCacheEntries->push_back(ClipCacheEntry(clipAndTransform, clip)); |
+ CHECK(getCachedClip(clipAndTransform)); |
Xianzhu
2017/03/07 23:19:06
Should this be DCHECK?
chrishtr
2017/03/07 23:21:25
Oh good catch!
Actually deleted this, it was duri
|
+} |
+ |
} // namespace blink |