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