| 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 GeometryMapper_h | 5 #ifndef GeometryMapper_h |
| 6 #define GeometryMapper_h | 6 #define GeometryMapper_h |
| 7 | 7 |
| 8 #include "platform/geometry/FloatRect.h" | 8 #include "platform/geometry/FloatRect.h" |
| 9 #include "platform/graphics/paint/GeometryPropertyTreeState.h" | 9 #include "platform/graphics/paint/PropertyTreeState.h" |
| 10 #include "platform/transforms/TransformationMatrix.h" | 10 #include "platform/transforms/TransformationMatrix.h" |
| 11 #include "wtf/HashMap.h" | 11 #include "wtf/HashMap.h" |
| 12 | 12 |
| 13 namespace blink { | 13 namespace blink { |
| 14 | 14 |
| 15 struct PrecomputedDataForAncestor { | 15 struct PrecomputedDataForAncestor { |
| 16 // Maps from a transform node that is a descendant of the ancestor to the comb
ined | 16 // Maps from a transform node that is a descendant of the ancestor to the comb
ined |
| 17 // transform between the descendant's and the ancestor's coordinate space. | 17 // transform between the descendant's and the ancestor's coordinate space. |
| 18 HashMap<const TransformPaintPropertyNode*, TransformationMatrix> | 18 HashMap<const TransformPaintPropertyNode*, TransformationMatrix> |
| 19 toAncestorTransforms; | 19 toAncestorTransforms; |
| 20 | 20 |
| 21 // Maps from a descendant clip node to its equivalent "clip visual rect" in th
e space of the ancestor. | 21 // Maps from a descendant clip node to its equivalent "clip visual rect" in th
e space of the ancestor. |
| 22 // The clip visual rect is defined as the intersection of all clips between th
e descendant | 22 // The clip visual rect is defined as the intersection of all clips between th
e descendant |
| 23 // and the ancestor (*not* including the ancestor) in the clip tree, individua
lly transformed from their | 23 // and the ancestor (*not* including the ancestor) in the clip tree, individua
lly transformed from their |
| 24 // localTransformSpace into the ancestor's localTransformSpace. | 24 // localTransformSpace into the ancestor's localTransformSpace. |
| 25 HashMap<const ClipPaintPropertyNode*, FloatRect> toAncestorClipRects; | 25 HashMap<const ClipPaintPropertyNode*, FloatRect> toAncestorClipRects; |
| 26 | 26 |
| 27 static std::unique_ptr<PrecomputedDataForAncestor> create() { | 27 static std::unique_ptr<PrecomputedDataForAncestor> create() { |
| 28 return wrapUnique(new PrecomputedDataForAncestor()); | 28 return wrapUnique(new PrecomputedDataForAncestor()); |
| 29 } | 29 } |
| 30 }; | 30 }; |
| 31 | 31 |
| 32 // GeometryMapper is a helper class for fast computations of transformed and vis
ual rects in | 32 // GeometryMapper is a helper class for fast computations of transformed and vis
ual rects in |
| 33 // different GeometryPropertyTreeStates. The design document has a number of det
ails on use cases, | 33 // different PropertyTreeStates. The design document has a number of details on
use cases, |
| 34 // algorithmic definitions, and running times. | 34 // algorithmic definitions, and running times. |
| 35 // | 35 // |
| 36 // NOTE: A GeometryMapper object is only valid for property trees that do not ch
ange. If any | 36 // NOTE: A GeometryMapper object is only valid for property trees that do not ch
ange. If any |
| 37 // mutation occurs, a new GeometryMapper object must be allocated corresponding
to the new state. | 37 // mutation occurs, a new GeometryMapper object must be allocated corresponding
to the new state. |
| 38 // | 38 // |
| 39 // Design document: http://bit.ly/28P4FDA | 39 // Design document: http://bit.ly/28P4FDA |
| 40 // | 40 // |
| 41 // TODO(chrishtr): take effect tree into account. | 41 // TODO(chrishtr): take effect tree into account. |
| 42 class PLATFORM_EXPORT GeometryMapper { | 42 class PLATFORM_EXPORT GeometryMapper { |
| 43 public: | 43 public: |
| 44 GeometryMapper() {} | 44 GeometryMapper() {} |
| 45 // The runtime of m calls among localToVisualRectInAncestorSpace, localToAnces
torRect or ancestorToLocalRect | 45 // The runtime of m calls among localToVisualRectInAncestorSpace, localToAnces
torRect or ancestorToLocalRect |
| 46 // with the same |ancestorState| parameter is guaranteed to be O(n + m), wher
e n is the number of transform and clip | 46 // with the same |ancestorState| parameter is guaranteed to be O(n + m), wher
e n is the number of transform and clip |
| 47 // nodes in their respective property trees. | 47 // nodes in their respective property trees. |
| 48 | 48 |
| 49 // If the clips and transforms of |sourceState| are equal to or descendants of
those of |destinationState|, returns | 49 // If the clips and transforms of |sourceState| are equal to or descendants of
those of |destinationState|, returns |
| 50 // the same value as localToVisualRectInAncestorSpace. Otherwise, maps the inp
ut rect to the transform state which is | 50 // the same value as localToVisualRectInAncestorSpace. Otherwise, maps the inp
ut rect to the transform state which is |
| 51 // the least common ancestor of |sourceState.transform| and |destinationState.
transform|, then multiplies it by | 51 // the least common ancestor of |sourceState.transform| and |destinationState.
transform|, then multiplies it by |
| 52 // the the inverse transform mapping from the least common ancestor to |destin
ationState.transform|. | 52 // the the inverse transform mapping from the least common ancestor to |destin
ationState.transform|. |
| 53 // | 53 // |
| 54 // If that inverse transform is not invertible, sets |success| to false and re
turns the input rect. Otherwise, sets | 54 // If that inverse transform is not invertible, sets |success| to false and re
turns the input rect. Otherwise, sets |
| 55 // |success| to true. | 55 // |success| to true. |
| 56 FloatRect mapToVisualRectInDestinationSpace( | 56 FloatRect mapToVisualRectInDestinationSpace( |
| 57 const FloatRect&, | 57 const FloatRect&, |
| 58 const GeometryPropertyTreeState& sourceState, | 58 const PropertyTreeState& sourceState, |
| 59 const GeometryPropertyTreeState& destinationState, | 59 const PropertyTreeState& destinationState, |
| 60 bool& success); | 60 bool& success); |
| 61 | 61 |
| 62 // Same as mapToVisualRectInDestinationSpace() except that *no* clip is applie
d. | 62 // Same as mapToVisualRectInDestinationSpace() except that *no* clip is applie
d. |
| 63 FloatRect mapRectToDestinationSpace( | 63 FloatRect mapRectToDestinationSpace(const FloatRect&, |
| 64 const FloatRect&, | 64 const PropertyTreeState& sourceState, |
| 65 const GeometryPropertyTreeState& sourceState, | 65 const PropertyTreeState& destinationState, |
| 66 const GeometryPropertyTreeState& destinationState, | 66 bool& success); |
| 67 bool& success); | |
| 68 | 67 |
| 69 // Maps from a rect in |localTransformSpace| to its visual rect in |ancestorSt
ate|. This is computed | 68 // Maps from a rect in |localTransformSpace| to its visual rect in |ancestorSt
ate|. This is computed |
| 70 // by multiplying the rect by its combined transform between |localTransformSp
ace| and |ancestorSpace|, | 69 // by multiplying the rect by its combined transform between |localTransformSp
ace| and |ancestorSpace|, |
| 71 // then flattening into 2D space, then intersecting by the "clip visual rect"
for |localTransformState|'s clips. | 70 // then flattening into 2D space, then intersecting by the "clip visual rect"
for |localTransformState|'s clips. |
| 72 // See above for the definition of "clip visual rect". | 71 // See above for the definition of "clip visual rect". |
| 73 // | 72 // |
| 74 // Note that the clip of |ancestorState| is *not* applied. | 73 // Note that the clip of |ancestorState| is *not* applied. |
| 75 // | 74 // |
| 76 // If any of the paint property tree nodes in |localTransformState| are not eq
ual | 75 // If any of the paint property tree nodes in |localTransformState| are not eq
ual |
| 77 // to or a descendant of that in |ancestorState|, returns the passed-in rect a
nd sets |success| to false. Otherwise, | 76 // to or a descendant of that in |ancestorState|, returns the passed-in rect a
nd sets |success| to false. Otherwise, |
| 78 // sets |success| to true. | 77 // sets |success| to true. |
| 79 FloatRect localToVisualRectInAncestorSpace( | 78 FloatRect localToVisualRectInAncestorSpace( |
| 80 const FloatRect&, | 79 const FloatRect&, |
| 81 const GeometryPropertyTreeState& localTransformState, | 80 const PropertyTreeState& localTransformState, |
| 82 const GeometryPropertyTreeState& ancestorState, | 81 const PropertyTreeState& ancestorState, |
| 83 bool& success); | 82 bool& success); |
| 84 | 83 |
| 85 // Maps from a rect in |localTransformSpace| to its transformed rect in |ances
torSpace|. This is computed | 84 // Maps from a rect in |localTransformSpace| to its transformed rect in |ances
torSpace|. This is computed |
| 86 // by multiplying the rect by the combined transform between |localTransformSt
ate| and |ancestorState|, | 85 // by multiplying the rect by the combined transform between |localTransformSt
ate| and |ancestorState|, |
| 87 // then flattening into 2D space. | 86 // then flattening into 2D space. |
| 88 // | 87 // |
| 89 // If any of the paint property tree nodes in |localTransformState| are not eq
ual | 88 // If any of the paint property tree nodes in |localTransformState| are not eq
ual |
| 90 // to or a descendant of that in |ancestorState|, returns the passed-in rec an
d sets |success| to false. Otherwise, | 89 // to or a descendant of that in |ancestorState|, returns the passed-in rec an
d sets |success| to false. Otherwise, |
| 91 // sets |success| to true. | 90 // sets |success| to true. |
| 92 // | 91 // |
| 93 // If any of the paint property tree nodes in |localTransformState| are not eq
ual | 92 // If any of the paint property tree nodes in |localTransformState| are not eq
ual |
| 94 // to or a descendant of that in |ancestorState|, returns the passed-in rect a
nd sets |success| to false. Otherwise, | 93 // to or a descendant of that in |ancestorState|, returns the passed-in rect a
nd sets |success| to false. Otherwise, |
| 95 // sets |success| to true. | 94 // sets |success| to true. |
| 96 FloatRect localToAncestorRect( | 95 FloatRect localToAncestorRect(const FloatRect&, |
| 97 const FloatRect&, | 96 const PropertyTreeState& localTransformState, |
| 98 const GeometryPropertyTreeState& localTransformState, | 97 const PropertyTreeState& ancestorState, |
| 99 const GeometryPropertyTreeState& ancestorState, | 98 bool& success); |
| 100 bool& success); | |
| 101 | 99 |
| 102 // Maps from a rect in |ancestorSpace| to its transformed rect in |localTransf
ormSpace|. This is computed | 100 // Maps from a rect in |ancestorSpace| to its transformed rect in |localTransf
ormSpace|. This is computed |
| 103 // by multiplying the rect by the inverse combined transform between |localTra
nsformState| and |ancestorState|, | 101 // by multiplying the rect by the inverse combined transform between |localTra
nsformState| and |ancestorState|, |
| 104 // if the transform is invertible. | 102 // if the transform is invertible. |
| 105 // | 103 // |
| 106 // If any of the paint property tree nodes in |localTransformState| are not eq
ual | 104 // If any of the paint property tree nodes in |localTransformState| are not eq
ual |
| 107 // to or a descendant of that in |ancestorState|, returns the passed-in rect a
nd sets |success| to false. Otherwise, | 105 // to or a descendant of that in |ancestorState|, returns the passed-in rect a
nd sets |success| to false. Otherwise, |
| 108 // sets |success| to true. | 106 // sets |success| to true. |
| 109 FloatRect ancestorToLocalRect( | 107 FloatRect ancestorToLocalRect(const FloatRect&, |
| 110 const FloatRect&, | 108 const PropertyTreeState& localTransformState, |
| 111 const GeometryPropertyTreeState& localTransformState, | 109 const PropertyTreeState& ancestorState, |
| 112 const GeometryPropertyTreeState& ancestorState, | 110 bool& success); |
| 113 bool& success); | |
| 114 | 111 |
| 115 private: | 112 private: |
| 116 // Used by mapToVisualRectInDestinationSpace() after fast mapping (assuming de
stination is an ancestor of source) failed. | 113 // Used by mapToVisualRectInDestinationSpace() after fast mapping (assuming de
stination is an ancestor of source) failed. |
| 117 FloatRect slowMapToVisualRectInDestinationSpace( | 114 FloatRect slowMapToVisualRectInDestinationSpace( |
| 118 const FloatRect&, | 115 const FloatRect&, |
| 119 const GeometryPropertyTreeState& sourceState, | 116 const PropertyTreeState& sourceState, |
| 120 const GeometryPropertyTreeState& destinationState, | 117 const PropertyTreeState& destinationState, |
| 121 bool& success); | 118 bool& success); |
| 122 | 119 |
| 123 // Used by mapRectToDestinationSpace() after fast mapping (assuming destinatio
n is an ancestor of source) failed. | 120 // Used by mapRectToDestinationSpace() after fast mapping (assuming destinatio
n is an ancestor of source) failed. |
| 124 FloatRect slowMapRectToDestinationSpace( | 121 FloatRect slowMapRectToDestinationSpace( |
| 125 const FloatRect&, | 122 const FloatRect&, |
| 126 const GeometryPropertyTreeState& sourceState, | 123 const PropertyTreeState& sourceState, |
| 127 const GeometryPropertyTreeState& destinationState, | 124 const PropertyTreeState& destinationState, |
| 128 bool& success); | 125 bool& success); |
| 129 | 126 |
| 130 // Returns the matrix used in |LocalToAncestorRect|. Sets |success| to failse
iff |localTransformNode| is not | 127 // Returns the matrix used in |LocalToAncestorRect|. Sets |success| to failse
iff |localTransformNode| is not |
| 131 // equal to or a descendant of |ancestorState.transform|. | 128 // equal to or a descendant of |ancestorState.transform|. |
| 132 const TransformationMatrix& localToAncestorMatrix( | 129 const TransformationMatrix& localToAncestorMatrix( |
| 133 const TransformPaintPropertyNode* localTransformNode, | 130 const TransformPaintPropertyNode* localTransformNode, |
| 134 const GeometryPropertyTreeState& ancestorState, | 131 const PropertyTreeState& ancestorState, |
| 135 bool& success); | 132 bool& success); |
| 136 | 133 |
| 137 // Returns the "clip visual rect" between |localTransformState| and |ancestorS
tate|. See above for the definition | 134 // Returns the "clip visual rect" between |localTransformState| and |ancestorS
tate|. See above for the definition |
| 138 // of "clip visual rect". | 135 // of "clip visual rect". |
| 139 FloatRect localToAncestorClipRect( | 136 FloatRect localToAncestorClipRect( |
| 140 const GeometryPropertyTreeState& localTransformState, | 137 const PropertyTreeState& localTransformState, |
| 141 const GeometryPropertyTreeState& ancestorState, | 138 const PropertyTreeState& ancestorState, |
| 142 bool& success); | 139 bool& success); |
| 143 | 140 |
| 144 // Returns the precomputed data if already set, or adds and memoizes a new Pre
computedDataForAncestor otherwise. | 141 // Returns the precomputed data if already set, or adds and memoizes a new Pre
computedDataForAncestor otherwise. |
| 145 PrecomputedDataForAncestor& getPrecomputedDataForAncestor( | 142 PrecomputedDataForAncestor& getPrecomputedDataForAncestor( |
| 146 const GeometryPropertyTreeState&); | 143 const PropertyTreeState&); |
| 147 | 144 |
| 148 // Returns the least common ancestor in the transform tree. | 145 // Returns the least common ancestor in the transform tree. |
| 149 static const TransformPaintPropertyNode* leastCommonAncestor( | 146 static const TransformPaintPropertyNode* leastCommonAncestor( |
| 150 const TransformPaintPropertyNode*, | 147 const TransformPaintPropertyNode*, |
| 151 const TransformPaintPropertyNode*); | 148 const TransformPaintPropertyNode*); |
| 152 | 149 |
| 153 friend class GeometryMapperTest; | 150 friend class GeometryMapperTest; |
| 154 | 151 |
| 155 HashMap<const TransformPaintPropertyNode*, | 152 HashMap<const TransformPaintPropertyNode*, |
| 156 std::unique_ptr<PrecomputedDataForAncestor>> | 153 std::unique_ptr<PrecomputedDataForAncestor>> |
| 157 m_data; | 154 m_data; |
| 158 | 155 |
| 159 const TransformationMatrix m_identity; | 156 const TransformationMatrix m_identity; |
| 160 | 157 |
| 161 DISALLOW_COPY_AND_ASSIGN(GeometryMapper); | 158 DISALLOW_COPY_AND_ASSIGN(GeometryMapper); |
| 162 }; | 159 }; |
| 163 | 160 |
| 164 } // namespace blink | 161 } // namespace blink |
| 165 | 162 |
| 166 #endif // GeometryMapper_h | 163 #endif // GeometryMapper_h |
| OLD | NEW |