OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "platform/graphics/paint/ClipPaintPropertyNode.h" | 5 #include "platform/graphics/paint/ClipPaintPropertyNode.h" |
6 | 6 |
7 #include "platform/geometry/LayoutRect.h" | 7 #include "platform/geometry/LayoutRect.h" |
8 #include "platform/graphics/paint/PropertyTreeState.h" | 8 #include "platform/graphics/paint/PropertyTreeState.h" |
9 | 9 |
10 namespace blink { | 10 namespace blink { |
11 | 11 |
| 12 // All clip caches invalidate themselves by tracking a local cache generation, |
| 13 // and invalidating their cache if their cache generation disagrees with |
| 14 // s_clipCacheGeneration. |
| 15 static unsigned s_clipCacheGeneration = 0; |
| 16 |
| 17 ClipPaintPropertyNode::ClipPaintPropertyNode( |
| 18 PassRefPtr<const ClipPaintPropertyNode> parent, |
| 19 PassRefPtr<const TransformPaintPropertyNode> localTransformSpace, |
| 20 const FloatRoundedRect& clipRect, |
| 21 CompositingReasons directCompositingReasons) |
| 22 : m_parent(parent), |
| 23 m_localTransformSpace(localTransformSpace), |
| 24 m_clipRect(clipRect), |
| 25 m_directCompositingReasons(directCompositingReasons), |
| 26 m_cacheGeneration(s_clipCacheGeneration) {} |
| 27 |
12 ClipPaintPropertyNode* ClipPaintPropertyNode::root() { | 28 ClipPaintPropertyNode* ClipPaintPropertyNode::root() { |
13 DEFINE_STATIC_REF(ClipPaintPropertyNode, root, | 29 DEFINE_STATIC_REF(ClipPaintPropertyNode, root, |
14 (ClipPaintPropertyNode::create( | 30 (ClipPaintPropertyNode::create( |
15 nullptr, TransformPaintPropertyNode::root(), | 31 nullptr, TransformPaintPropertyNode::root(), |
16 FloatRoundedRect(LayoutRect::infiniteIntRect())))); | 32 FloatRoundedRect(LayoutRect::infiniteIntRect())))); |
17 return root; | 33 return root; |
18 } | 34 } |
19 | 35 |
20 String ClipPaintPropertyNode::toString() const { | 36 String ClipPaintPropertyNode::toString() const { |
21 return String::format( | 37 return String::format( |
22 "parent=%p localTransformSpace=%p rect=%s directCompositingReasons=%s", | 38 "parent=%p localTransformSpace=%p rect=%s directCompositingReasons=%s", |
23 m_parent.get(), m_localTransformSpace.get(), | 39 m_parent.get(), m_localTransformSpace.get(), |
24 m_clipRect.toString().ascii().data(), | 40 m_clipRect.toString().ascii().data(), |
25 compositingReasonsAsString(m_directCompositingReasons).ascii().data()); | 41 compositingReasonsAsString(m_directCompositingReasons).ascii().data()); |
26 } | 42 } |
27 | 43 |
28 #if DCHECK_IS_ON() | 44 #if DCHECK_IS_ON() |
29 | 45 |
30 String ClipPaintPropertyNode::toTreeString() const { | 46 String ClipPaintPropertyNode::toTreeString() const { |
31 return blink::PropertyTreeStatePrinter<blink::ClipPaintPropertyNode>() | 47 return blink::PropertyTreeStatePrinter<blink::ClipPaintPropertyNode>() |
32 .pathAsString(this); | 48 .pathAsString(this); |
33 } | 49 } |
34 | 50 |
35 #endif | 51 #endif |
36 | 52 |
| 53 void ClipPaintPropertyNode::clearCache() { |
| 54 s_clipCacheGeneration++; |
| 55 } |
| 56 |
| 57 Vector<ClipPaintPropertyNode::ClipCacheEntry>* |
| 58 ClipPaintPropertyNode::getClipCacheEntries() { |
| 59 if (m_cacheGeneration != s_clipCacheGeneration || !m_clipCache) { |
| 60 m_clipCache.reset(new Vector<ClipCacheEntry>); |
| 61 m_cacheGeneration = s_clipCacheGeneration; |
| 62 } |
| 63 |
| 64 return m_clipCache.get(); |
| 65 } |
| 66 |
| 67 const FloatClipRect* ClipPaintPropertyNode::getCachedClip( |
| 68 const ClipAndTransform& clipAndTransform) const { |
| 69 auto* clipCacheEntries = |
| 70 const_cast<ClipPaintPropertyNode*>(this)->getClipCacheEntries(); |
| 71 for (const auto& entry : *clipCacheEntries) { |
| 72 if (entry.clipAndTransform == clipAndTransform) { |
| 73 return &entry.clipRect; |
| 74 } |
| 75 } |
| 76 return nullptr; |
| 77 } |
| 78 |
| 79 void ClipPaintPropertyNode::setCachedClip( |
| 80 const ClipAndTransform& clipAndTransform, |
| 81 const FloatClipRect& clip) const { |
| 82 auto* clipCacheEntries = |
| 83 const_cast<ClipPaintPropertyNode*>(this)->getClipCacheEntries(); |
| 84 #if DCHECK_IS_ON |
| 85 for (const auto& entry : clipCachEntries) { |
| 86 if (entry.clipAndTransform == clipAndTransform) |
| 87 DCHECK(false); // There should be no existing entry. |
| 88 } |
| 89 #endif |
| 90 clipCacheEntries->push_back(ClipCacheEntry(clipAndTransform, clip)); |
| 91 } |
| 92 |
37 } // namespace blink | 93 } // namespace blink |
OLD | NEW |