| 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 "wtf/HashFunctions.h" | 8 #include "wtf/HashFunctions.h" |
| 9 #include "wtf/HashTraits.h" | 9 #include "wtf/HashTraits.h" |
| 10 | 10 |
| 11 namespace blink { | 11 namespace blink { |
| 12 | 12 |
| 13 class TransformPaintPropertyNode; | 13 class TransformPaintPropertyNode; |
| 14 class ClipPaintPropertyNode; | 14 class ClipPaintPropertyNode; |
| 15 class EffectPaintPropertyNode; | 15 class EffectPaintPropertyNode; |
| 16 | 16 |
| 17 // Represents the combination of transform, clip and effect nodes for a particul
ar coordinate space. | 17 // Represents the combination of transform, clip and effect nodes for a particul
ar coordinate space. |
| 18 // See GeometryMapper. | 18 // See GeometryMapper. |
| 19 struct PropertyTreeState { | 19 struct PropertyTreeState { |
| 20 PropertyTreeState() : PropertyTreeState(nullptr, nullptr, nullptr) {} |
| 21 |
| 20 PropertyTreeState( | 22 PropertyTreeState( |
| 21 TransformPaintPropertyNode* transform, | 23 TransformPaintPropertyNode* transform, |
| 22 ClipPaintPropertyNode* clip, | 24 ClipPaintPropertyNode* clip, |
| 23 EffectPaintPropertyNode* effect) | 25 EffectPaintPropertyNode* effect) |
| 24 : transform(transform), clip(clip), effect(effect) {} | 26 : transform(transform), clip(clip), effect(effect) {} |
| 25 | 27 |
| 26 TransformPaintPropertyNode* transform; | 28 RefPtr<TransformPaintPropertyNode> transform; |
| 27 ClipPaintPropertyNode* clip; | 29 RefPtr<ClipPaintPropertyNode> clip; |
| 28 EffectPaintPropertyNode* effect; | 30 RefPtr<EffectPaintPropertyNode> effect; |
| 29 }; | 31 }; |
| 30 | 32 |
| 33 template <class A> |
| 34 unsigned propertyTreeNodeDepth(const A* node) |
| 35 { |
| 36 unsigned depth = 0; |
| 37 while (node) { |
| 38 depth++; |
| 39 node = node->parent(); |
| 40 } |
| 41 return depth; |
| 42 } |
| 43 |
| 44 template <class A> |
| 45 const A* propertyTreeNearestCommonAncestor(const A* a, const A* b) |
| 46 { |
| 47 // Measure both depths. |
| 48 unsigned depthA = propertyTreeNodeDepth<A>(a); |
| 49 unsigned depthB = propertyTreeNodeDepth<A>(b); |
| 50 |
| 51 // Make it so depthA >= depthB. |
| 52 if (depthA < depthB) { |
| 53 std::swap(a, b); |
| 54 std::swap(depthA, depthB); |
| 55 } |
| 56 |
| 57 // Make it so depthA == depthB. |
| 58 while (depthA > depthB) { |
| 59 a = a->parent(); |
| 60 depthA--; |
| 61 } |
| 62 |
| 63 // Walk up until we find the ancestor. |
| 64 while (a != b) { |
| 65 a = a->parent(); |
| 66 b = b->parent(); |
| 67 } |
| 68 return a; |
| 69 } |
| 70 |
| 31 } // namespace blink | 71 } // namespace blink |
| 32 | 72 |
| 33 #endif // PropertyTreeState_h | 73 #endif // PropertyTreeState_h |
| OLD | NEW |