| 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 #ifndef PropertyTreeState_h | 5 #ifndef PropertyTreeState_h |
| 6 #define PropertyTreeState_h | 6 #define PropertyTreeState_h |
| 7 | 7 |
| 8 #include "platform/graphics/paint/ClipPaintPropertyNode.h" | 8 #include "platform/graphics/paint/ClipPaintPropertyNode.h" |
| 9 #include "platform/graphics/paint/EffectPaintPropertyNode.h" | 9 #include "platform/graphics/paint/EffectPaintPropertyNode.h" |
| 10 #include "platform/graphics/paint/ScrollPaintPropertyNode.h" | 10 #include "platform/graphics/paint/ScrollPaintPropertyNode.h" |
| 11 #include "platform/graphics/paint/TransformPaintPropertyNode.h" | 11 #include "platform/graphics/paint/TransformPaintPropertyNode.h" |
| 12 #include "wtf/HashFunctions.h" | 12 #include "wtf/HashFunctions.h" |
| 13 #include "wtf/HashTraits.h" | 13 #include "wtf/HashTraits.h" |
| 14 #include "wtf/text/StringBuilder.h" |
| 14 | 15 |
| 15 namespace blink { | 16 namespace blink { |
| 16 | 17 |
| 17 // A complete set of paint properties including those that are inherited from | 18 // A complete set of paint properties including those that are inherited from |
| 18 // other objects. RefPtrs are used to guard against use-after-free bugs and | 19 // other objects. RefPtrs are used to guard against use-after-free bugs and |
| 19 // DCHECKs ensure PropertyTreeState never retains the last reference to a | 20 // DCHECKs ensure PropertyTreeState never retains the last reference to a |
| 20 // property tree node. | 21 // property tree node. |
| 21 class PLATFORM_EXPORT PropertyTreeState { | 22 class PLATFORM_EXPORT PropertyTreeState { |
| 22 public: | 23 public: |
| 23 PropertyTreeState(const TransformPaintPropertyNode* transform, | 24 PropertyTreeState(const TransformPaintPropertyNode* transform, |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 // | 106 // |
| 106 // The PropertyTreeStateIterator will behave like this: | 107 // The PropertyTreeStateIterator will behave like this: |
| 107 // | 108 // |
| 108 // PropertyTreeStateIterator iterator(PropertyTreeState(T, C, E)); | 109 // PropertyTreeStateIterator iterator(PropertyTreeState(T, C, E)); |
| 109 // DCHECK(iterator.innermostNode() == Effect); | 110 // DCHECK(iterator.innermostNode() == Effect); |
| 110 // DCHECK(iterator.next()->innermostNode() == Clip); | 111 // DCHECK(iterator.next()->innermostNode() == Clip); |
| 111 // DCHECK(iterator.next()->innermostNode() == Transform); | 112 // DCHECK(iterator.next()->innermostNode() == Transform); |
| 112 // DCHECK(iterator.next()->innermostNode() == None); | 113 // DCHECK(iterator.next()->innermostNode() == None); |
| 113 InnermostNode innermostNode() const; | 114 InnermostNode innermostNode() const; |
| 114 | 115 |
| 116 #if DCHECK_IS_ON() |
| 117 // Dumps the tree from this state up to the root as a string. |
| 118 String toTreeString() const; |
| 119 #endif |
| 120 |
| 115 private: | 121 private: |
| 116 RefPtr<const TransformPaintPropertyNode> m_transform; | 122 RefPtr<const TransformPaintPropertyNode> m_transform; |
| 117 RefPtr<const ClipPaintPropertyNode> m_clip; | 123 RefPtr<const ClipPaintPropertyNode> m_clip; |
| 118 RefPtr<const EffectPaintPropertyNode> m_effect; | 124 RefPtr<const EffectPaintPropertyNode> m_effect; |
| 119 RefPtr<const ScrollPaintPropertyNode> m_scroll; | 125 RefPtr<const ScrollPaintPropertyNode> m_scroll; |
| 120 }; | 126 }; |
| 121 | 127 |
| 122 inline bool operator==(const PropertyTreeState& a, const PropertyTreeState& b) { | 128 inline bool operator==(const PropertyTreeState& a, const PropertyTreeState& b) { |
| 123 return a.transform() == b.transform() && a.clip() == b.clip() && | 129 return a.transform() == b.transform() && a.clip() == b.clip() && |
| 124 a.effect() == b.effect() && a.scroll() == b.scroll(); | 130 a.effect() == b.effect() && a.scroll() == b.scroll(); |
| 125 } | 131 } |
| 126 | 132 |
| 127 // Iterates over the sequence transforms, clips and effects for a | 133 // Iterates over the sequence transforms, clips and effects for a |
| 128 // PropertyTreeState between that state and the "root" state (all nodes equal | 134 // PropertyTreeState between that state and the "root" state (all nodes equal |
| 129 // to *::Root()), in the order that they apply. | 135 // to *::Root()), in the order that they apply. |
| 130 // | 136 // |
| 131 // See also PropertyTreeState::innermostNode for a more detailed example. | 137 // See also PropertyTreeState::innermostNode for a more detailed example. |
| 132 class PLATFORM_EXPORT PropertyTreeStateIterator { | 138 class PLATFORM_EXPORT PropertyTreeStateIterator { |
| 133 public: | 139 public: |
| 134 PropertyTreeStateIterator(const PropertyTreeState& properties) | 140 PropertyTreeStateIterator(const PropertyTreeState& properties) |
| 135 : m_properties(properties) {} | 141 : m_properties(properties) {} |
| 136 const PropertyTreeState* next(); | 142 const PropertyTreeState* next(); |
| 137 | 143 |
| 138 private: | 144 private: |
| 139 PropertyTreeState m_properties; | 145 PropertyTreeState m_properties; |
| 140 }; | 146 }; |
| 141 | 147 |
| 148 #if DCHECK_IS_ON() |
| 149 |
| 150 template <typename PropertyTreeNode> |
| 151 class PropertyTreeStatePrinter { |
| 152 public: |
| 153 String pathAsString(const PropertyTreeNode* lastNode) { |
| 154 const PropertyTreeNode* node = lastNode; |
| 155 while (!node->isRoot()) { |
| 156 addPropertyNode(node, ""); |
| 157 node = node->parent(); |
| 158 } |
| 159 addPropertyNode(node, "root"); |
| 160 |
| 161 StringBuilder stringBuilder; |
| 162 addAllPropertyNodes(stringBuilder, node); |
| 163 return stringBuilder.toString(); |
| 164 } |
| 165 |
| 166 void addPropertyNode(const PropertyTreeNode* node, String debugInfo) { |
| 167 m_nodeToDebugString.set(node, debugInfo); |
| 168 } |
| 169 |
| 170 void addAllPropertyNodes(StringBuilder& stringBuilder, |
| 171 const PropertyTreeNode* node, |
| 172 unsigned indent = 0) { |
| 173 DCHECK(node); |
| 174 for (unsigned i = 0; i < indent; i++) |
| 175 stringBuilder.append(' '); |
| 176 if (m_nodeToDebugString.contains(node)) |
| 177 stringBuilder.append(m_nodeToDebugString.get(node)); |
| 178 stringBuilder.append(String::format(" %p ", node)); |
| 179 stringBuilder.append(node->toString()); |
| 180 stringBuilder.append("\n"); |
| 181 |
| 182 for (const auto* childNode : m_nodeToDebugString.keys()) { |
| 183 if (childNode->parent() == node) |
| 184 addAllPropertyNodes(stringBuilder, childNode, indent + 2); |
| 185 } |
| 186 } |
| 187 |
| 188 HashMap<const PropertyTreeNode*, String> m_nodeToDebugString; |
| 189 }; |
| 190 |
| 191 #endif |
| 192 |
| 142 } // namespace blink | 193 } // namespace blink |
| 143 | 194 |
| 144 #endif // PropertyTreeState_h | 195 #endif // PropertyTreeState_h |
| OLD | NEW |