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/PropertyTreeState.h" | 9 #include "platform/graphics/paint/PropertyTreeState.h" |
10 #include "platform/transforms/TransformationMatrix.h" | 10 #include "platform/transforms/TransformationMatrix.h" |
(...skipping 27 matching lines...) Expand all Loading... | |
38 // NOTE: A GeometryMapper object is only valid for property trees that do not | 38 // NOTE: A GeometryMapper object is only valid for property trees that do not |
39 // change. If any mutation occurs, a new GeometryMapper object must be allocated | 39 // change. If any mutation occurs, a new GeometryMapper object must be allocated |
40 // corresponding to the new state. | 40 // corresponding to the new state. |
41 // | 41 // |
42 // Design document: http://bit.ly/28P4FDA | 42 // Design document: http://bit.ly/28P4FDA |
43 // | 43 // |
44 // TODO(chrishtr): take effect tree into account. | 44 // TODO(chrishtr): take effect tree into account. |
45 class PLATFORM_EXPORT GeometryMapper { | 45 class PLATFORM_EXPORT GeometryMapper { |
46 public: | 46 public: |
47 GeometryMapper() {} | 47 GeometryMapper() {} |
48 // The runtime of m calls among localToVisualRectInAncestorSpace, | 48 // The runtime of m calls among localToAncestorVisualRect, localToAncestorRect |
49 // localToAncestorRect or ancestorToLocalRect with the same |ancestorState| | 49 // or ancestorToLocalRect with the same |ancestorState| parameter is |
50 // parameter is guaranteed to be O(n + m), where n is the number of transform | 50 // guaranteed to be O(n + m), where n is the number of transform and clip |
51 // and clip nodes in their respective property trees. | 51 // nodes in their respective property trees. |
52 | 52 |
53 // If the clips and transforms of |sourceState| are equal to or descendants of | 53 // If the clips and transforms of |sourceState| are equal to or descendants of |
54 // those of |destinationState|, returns the same value as | 54 // those of |destinationState|, returns the same value as |
55 // localToVisualRectInAncestorSpace. Otherwise, maps the input rect to the | 55 // localToAncestorVisualRect. Otherwise, maps the input rect to the |
56 // transform state which is the least common ancestor of | 56 // transform state which is the least common ancestor of |
57 // |sourceState.transform| and |destinationState.transform|, then multiplies | 57 // |sourceState.transform| and |destinationState.transform|, then multiplies |
58 // it by the the inverse transform mapping from the least common ancestor to | 58 // it by the the inverse transform mapping from the least common ancestor to |
59 // |destinationState.transform|. | 59 // |destinationState.transform|. |
60 // | 60 // |
61 // Sets |success| to whether that inverse transform is invertible. If it is | 61 // Sets |success| to whether that inverse transform is invertible. If it is |
62 // not, returns the input rect. | 62 // not, returns the input rect. |
63 FloatRect mapToVisualRectInDestinationSpace( | 63 FloatRect sourceToDestinationVisualRect( |
64 const FloatRect&, | 64 const FloatRect&, |
65 const PropertyTreeState& sourceState, | 65 const PropertyTreeState& sourceState, |
66 const PropertyTreeState& destinationState, | 66 const PropertyTreeState& destinationState, |
67 bool& success); | 67 bool& success); |
68 | 68 |
69 // Same as mapToVisualRectInDestinationSpace() except that *no* clip is | 69 // Same as sourceToDestinationVisualRect() except that only transforms are |
70 // applied. | 70 // applied. |
71 FloatRect mapRectToDestinationSpace(const FloatRect&, | 71 FloatRect sourceToDestinationRect( |
72 const PropertyTreeState& sourceState, | 72 const FloatRect&, |
73 const PropertyTreeState& destinationState, | 73 const TransformPaintPropertyNode* sourceTransformNode, |
chrishtr
2017/01/11 22:23:08
Curious: what is the new call site you're planning
Xianzhu
2017/01/11 22:51:32
I will use this for handle geometry effects of fil
| |
74 bool& success); | 74 const TransformPaintPropertyNode* destinationTransformNode, |
75 bool& success); | |
75 | 76 |
76 // Maps from a rect in |localTransformSpace| to its visual rect in | 77 // Maps from a rect in |localTransformSpace| to its visual rect in |
77 // |ancestorState|. This is computed by multiplying the rect by its combined | 78 // |ancestorState|. This is computed by multiplying the rect by its combined |
78 // transform between |localTransformSpace| and |ancestorSpace|, then | 79 // transform between |localTransformSpace| and |ancestorSpace|, then |
79 // flattening into 2D space, then intersecting by the "clip visual rect" for | 80 // flattening into 2D space, then intersecting by the "clip visual rect" for |
80 // |localTransformState|'s clips. See above for the definition of "clip visual | 81 // |localTransformState|'s clips. See above for the definition of "clip visual |
81 // rect". | 82 // rect". |
82 // | 83 // |
83 // Note that the clip of |ancestorState| is *not* applied. | 84 // Note that the clip of |ancestorState| is *not* applied. |
84 // | 85 // |
85 // If any of the paint property tree nodes in |localTransformState| are not | 86 // If any of the paint property tree nodes in |localTransformState| are not |
86 // equal to or a descendant of that in |ancestorState|, returns the passed-in | 87 // equal to or a descendant of that in |ancestorState|, returns the passed-in |
87 // rect and sets |success| to false. Otherwise, sets |success| to true. | 88 // rect and sets |success| to false. Otherwise, sets |success| to true. |
88 FloatRect localToVisualRectInAncestorSpace( | 89 FloatRect localToAncestorVisualRect( |
89 const FloatRect&, | 90 const FloatRect&, |
90 const PropertyTreeState& localTransformState, | 91 const PropertyTreeState& localTransformState, |
91 const PropertyTreeState& ancestorState, | 92 const PropertyTreeState& ancestorState, |
92 bool& success); | 93 bool& success); |
93 | 94 |
94 // Maps from a rect in |localTransformSpace| to its transformed rect in | 95 // Maps from a rect in |localTransformNode| space to its transformed rect in |
95 // |ancestorSpace|. This is computed by multiplying the rect by the combined | 96 // |ancestorTransformNode| space. This is computed by multiplying the rect by |
96 // transform between |localTransformState| and |ancestorState|, then | 97 // the combined transform between |localTransformNode| and |
97 // flattening into 2D space. | 98 // |ancestorTransformNode|, then flattening into 2D space. |
98 // | 99 // |
99 // If any of the paint property tree nodes in |localTransformState| are not | 100 // If |localTransformNode| is not equal to or a descendant of |
100 // equal to or a descendant of that in |ancestorState|, returns the passed-in | 101 // |ancestorTransformNode|, returns the passed-in rec and sets |success| to |
101 // rec and sets |success| to false. Otherwise, sets |success| to true. | 102 // false. Otherwise, sets |success| to true. |
102 FloatRect localToAncestorRect(const FloatRect&, | 103 FloatRect localToAncestorRect( |
103 const PropertyTreeState& localTransformState, | 104 const FloatRect&, |
104 const PropertyTreeState& ancestorState, | 105 const TransformPaintPropertyNode* localTransformNode, |
105 bool& success); | 106 const TransformPaintPropertyNode* ancestorTransformNode, |
107 bool& success); | |
106 | 108 |
107 // Maps from a rect in |ancestorSpace| to its transformed rect in | 109 // Maps from a rect in |ancestorTransformNode| space to its transformed rect |
108 // |localTransformSpace|. This is computed by multiplying the rect by the | 110 // in |localTransformNode| space. This is computed by multiplying the rect by |
109 // inverse combined transform between |localTransformState| and | 111 // the inverse combined transform between |localTransformNode| and |
110 // |ancestorState|, if the transform is invertible. | 112 // |ancestorTransformNode|, if the transform is invertible. |
111 // | 113 // |
112 // If any of the paint property tree nodes in |localTransformState| are not | 114 // If the combined transform is not invertible, or |localTransformNode| is not |
113 // equal to or a descendant of that in |ancestorState|, returns the passed-in | 115 // equal to or a descendant of |ancestorTransformNode|, returns the passed-in |
114 // rect and sets |success| to false. Otherwise, sets |success| to true. | 116 // rect and sets |success| to false. Otherwise, sets |success| to true. |
115 FloatRect ancestorToLocalRect(const FloatRect&, | 117 FloatRect ancestorToLocalRect( |
116 const PropertyTreeState& localTransformState, | 118 const FloatRect&, |
117 const PropertyTreeState& ancestorState, | 119 const TransformPaintPropertyNode* ancestorTransformNode, |
118 bool& success); | 120 const TransformPaintPropertyNode* localTransformNode, |
121 bool& success); | |
119 | 122 |
120 // Returns the matrix used in |LocalToAncestorRect|. Sets |success| to false | 123 // Returns the matrix used in |LocalToAncestorRect|. Sets |success| to false |
121 // iff |localTransformNode| is not equal to or a descendant of | 124 // iff |localTransformNode| is not equal to or a descendant of |
122 // |ancestorState.transform|. | 125 // |ancestorTransformNode|. |
123 const TransformationMatrix& localToAncestorMatrix( | 126 const TransformationMatrix& localToAncestorMatrix( |
124 const TransformPaintPropertyNode* localTransformNode, | 127 const TransformPaintPropertyNode* localTransformNode, |
125 const PropertyTreeState& ancestorState, | 128 const TransformPaintPropertyNode* ancestorTransformNode, |
126 bool& success); | 129 bool& success); |
127 | 130 |
128 // Returns the "clip visual rect" between |localTransformState| and | 131 // Returns the "clip visual rect" between |localTransformState| and |
129 // |ancestorState|. See above for the definition of "clip visual rect". | 132 // |ancestorState|. See above for the definition of "clip visual rect". |
130 FloatRect localToAncestorClipRect( | 133 FloatRect localToAncestorClipRect( |
131 const PropertyTreeState& localTransformState, | 134 const PropertyTreeState& localTransformState, |
132 const PropertyTreeState& ancestorState, | 135 const PropertyTreeState& ancestorState, |
133 bool& success); | 136 bool& success); |
134 | 137 |
135 private: | 138 private: |
136 // Used by mapToVisualRectInDestinationSpace() after fast mapping (assuming | 139 // Used by sourceToDestinationVisualRect() after fast mapping (assuming |
137 // destination is an ancestor of source) failed. | 140 // destination is an ancestor of source) failed. |
138 FloatRect slowMapToVisualRectInDestinationSpace( | 141 FloatRect slowSourceToDestinationVisualRect( |
139 const FloatRect&, | 142 const FloatRect&, |
140 const PropertyTreeState& sourceState, | 143 const PropertyTreeState& sourceState, |
141 const PropertyTreeState& destinationState, | 144 const PropertyTreeState& destinationState, |
142 bool& success); | 145 bool& success); |
143 | 146 |
144 // Used by mapRectToDestinationSpace() after fast mapping (assuming | 147 // Used by sourceToDestinationRect() after fast mapping (assuming destination |
145 // destination is an ancestor of source) failed. | 148 // is an ancestor of source) failed. |
146 FloatRect slowMapRectToDestinationSpace( | 149 FloatRect slowSourceToDestinationRect( |
147 const FloatRect&, | 150 const FloatRect&, |
148 const PropertyTreeState& sourceState, | 151 const TransformPaintPropertyNode* sourceTransformNode, |
149 const PropertyTreeState& destinationState, | 152 const TransformPaintPropertyNode* destinationTransformNode, |
150 bool& success); | 153 bool& success); |
151 | 154 |
152 // Returns the precomputed data if already set, or adds and memoizes a new | 155 // Returns the precomputed data if already set, or adds and memoizes a new |
153 // PrecomputedDataForAncestor otherwise. | 156 // PrecomputedDataForAncestor otherwise. |
154 PrecomputedDataForAncestor& getPrecomputedDataForAncestor( | 157 PrecomputedDataForAncestor& getPrecomputedDataForAncestor( |
155 const PropertyTreeState&); | 158 const TransformPaintPropertyNode*); |
156 | 159 |
157 // Returns the least common ancestor in the transform tree. | 160 // Returns the least common ancestor in the transform tree. |
158 static const TransformPaintPropertyNode* leastCommonAncestor( | 161 static const TransformPaintPropertyNode* leastCommonAncestor( |
159 const TransformPaintPropertyNode*, | 162 const TransformPaintPropertyNode*, |
160 const TransformPaintPropertyNode*); | 163 const TransformPaintPropertyNode*); |
161 | 164 |
162 friend class GeometryMapperTest; | 165 friend class GeometryMapperTest; |
163 | 166 |
164 HashMap<const TransformPaintPropertyNode*, | 167 HashMap<const TransformPaintPropertyNode*, |
165 std::unique_ptr<PrecomputedDataForAncestor>> | 168 std::unique_ptr<PrecomputedDataForAncestor>> |
166 m_data; | 169 m_data; |
167 | 170 |
168 const TransformationMatrix m_identity; | 171 const TransformationMatrix m_identity; |
169 | 172 |
170 DISALLOW_COPY_AND_ASSIGN(GeometryMapper); | 173 DISALLOW_COPY_AND_ASSIGN(GeometryMapper); |
171 }; | 174 }; |
172 | 175 |
173 } // namespace blink | 176 } // namespace blink |
174 | 177 |
175 #endif // GeometryMapper_h | 178 #endif // GeometryMapper_h |
OLD | NEW |