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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 // 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 // localToAncestorVisualRect. 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 // DCHECK fails if the clip of |destinationState| is not an ancestor of the |
62 // not, returns the input rect. | 62 // clip of |sourceState|, or the inverse transform is not invertible. |
63 FloatRect sourceToDestinationVisualRect( | 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); | |
68 | 67 |
69 // Same as sourceToDestinationVisualRect() except that only transforms are | 68 // Same as sourceToDestinationVisualRect() except that only transforms are |
70 // applied. | 69 // applied. |
71 FloatRect sourceToDestinationRect( | 70 FloatRect sourceToDestinationRect( |
72 const FloatRect&, | 71 const FloatRect&, |
73 const TransformPaintPropertyNode* sourceTransformNode, | 72 const TransformPaintPropertyNode* sourceTransformNode, |
74 const TransformPaintPropertyNode* destinationTransformNode, | 73 const TransformPaintPropertyNode* destinationTransformNode); |
75 bool& success); | |
76 | 74 |
77 // Maps from a rect in |localTransformSpace| to its visual rect in | 75 // Maps from a rect in |localTransformSpace| to its visual rect in |
78 // |ancestorState|. This is computed by multiplying the rect by its combined | 76 // |ancestorState|. This is computed by multiplying the rect by its combined |
79 // transform between |localTransformSpace| and |ancestorSpace|, then | 77 // transform between |localTransformSpace| and |ancestorSpace|, then |
80 // flattening into 2D space, then intersecting by the "clip visual rect" for | 78 // flattening into 2D space, then intersecting by the "clip visual rect" for |
81 // |localTransformState|'s clips. See above for the definition of "clip visual | 79 // |localTransformState|'s clips. See above for the definition of "clip visual |
82 // rect". | 80 // rect". |
83 // | 81 // |
84 // Note that the clip of |ancestorState| is *not* applied. | 82 // Note that the clip of |ancestorState| is *not* applied. |
85 // | 83 // |
86 // If any of the paint property tree nodes in |localTransformState| are not | 84 // DCHECK fails if any of the paint property tree nodes in |
87 // equal to or a descendant of that in |ancestorState|, returns the passed-in | 85 // |localTransformState| are not equal to or a descendant of that in |
88 // rect and sets |success| to false. Otherwise, sets |success| to true. | 86 // |ancestorState|. |
89 FloatRect localToAncestorVisualRect( | 87 FloatRect localToAncestorVisualRect( |
90 const FloatRect&, | 88 const FloatRect&, |
91 const PropertyTreeState& localTransformState, | 89 const PropertyTreeState& localTransformState, |
92 const PropertyTreeState& ancestorState, | 90 const PropertyTreeState& ancestorState); |
93 bool& success); | |
94 | 91 |
95 // Maps from a rect in |localTransformNode| space to its transformed rect in | 92 // Maps from a rect in |localTransformNode| space to its transformed rect in |
96 // |ancestorTransformNode| space. This is computed by multiplying the rect by | 93 // |ancestorTransformNode| space. This is computed by multiplying the rect by |
97 // the combined transform between |localTransformNode| and | 94 // the combined transform between |localTransformNode| and |
98 // |ancestorTransformNode|, then flattening into 2D space. | 95 // |ancestorTransformNode|, then flattening into 2D space. |
99 // | 96 // |
100 // If |localTransformNode| is not equal to or a descendant of | 97 // DCHECK fails if |localTransformNode| is not equal to or a descendant of |
101 // |ancestorTransformNode|, returns the passed-in rec and sets |success| to | 98 // |ancestorTransformNode|. |
102 // false. Otherwise, sets |success| to true. | |
103 FloatRect localToAncestorRect( | 99 FloatRect localToAncestorRect( |
104 const FloatRect&, | 100 const FloatRect&, |
105 const TransformPaintPropertyNode* localTransformNode, | 101 const TransformPaintPropertyNode* localTransformNode, |
106 const TransformPaintPropertyNode* ancestorTransformNode, | 102 const TransformPaintPropertyNode* ancestorTransformNode); |
107 bool& success); | |
108 | 103 |
109 // Maps from a rect in |ancestorTransformNode| space to its transformed rect | 104 // Maps from a rect in |ancestorTransformNode| space to its transformed rect |
110 // in |localTransformNode| space. This is computed by multiplying the rect by | 105 // in |localTransformNode| space. This is computed by multiplying the rect by |
111 // the inverse combined transform between |localTransformNode| and | 106 // the inverse combined transform between |localTransformNode| and |
112 // |ancestorTransformNode|, if the transform is invertible. | 107 // |ancestorTransformNode|, if the transform is invertible. |
113 // | 108 // |
114 // If the combined transform is not invertible, or |localTransformNode| is not | 109 // DCHECK fails if the combined transform is not invertible, or |
115 // equal to or a descendant of |ancestorTransformNode|, returns the passed-in | 110 // |localTransformNode| is not equal to or a descendant of |
116 // rect and sets |success| to false. Otherwise, sets |success| to true. | 111 // |ancestorTransformNode|. |
117 FloatRect ancestorToLocalRect( | 112 FloatRect ancestorToLocalRect( |
118 const FloatRect&, | 113 const FloatRect&, |
119 const TransformPaintPropertyNode* ancestorTransformNode, | 114 const TransformPaintPropertyNode* ancestorTransformNode, |
120 const TransformPaintPropertyNode* localTransformNode, | 115 const TransformPaintPropertyNode* localTransformNode); |
121 bool& success); | |
122 | 116 |
123 // Returns the matrix used in |LocalToAncestorRect|. Sets |success| to false | 117 // Returns the matrix used in |LocalToAncestorRect|. DCHECK fails iff |
124 // iff |localTransformNode| is not equal to or a descendant of | 118 // |localTransformNode| is not equal to or a descendant of |
125 // |ancestorTransformNode|. | 119 // |ancestorTransformNode|. |
126 const TransformationMatrix& localToAncestorMatrix( | 120 const TransformationMatrix& localToAncestorMatrix( |
127 const TransformPaintPropertyNode* localTransformNode, | 121 const TransformPaintPropertyNode* localTransformNode, |
128 const TransformPaintPropertyNode* ancestorTransformNode, | 122 const TransformPaintPropertyNode* ancestorTransformNode); |
129 bool& success); | |
130 | 123 |
131 // Returns the "clip visual rect" between |localTransformState| and | 124 // Returns the "clip visual rect" between |localTransformState| and |
132 // |ancestorState|. See above for the definition of "clip visual rect". | 125 // |ancestorState|. See above for the definition of "clip visual rect". |
133 FloatRect localToAncestorClipRect( | 126 FloatRect localToAncestorClipRect( |
134 const PropertyTreeState& localTransformState, | 127 const PropertyTreeState& localTransformState, |
135 const PropertyTreeState& ancestorState, | 128 const PropertyTreeState& ancestorState); |
136 bool& success); | |
137 | 129 |
138 private: | 130 private: |
139 // Used by sourceToDestinationVisualRect() after fast mapping (assuming | 131 // The internal methods do the same things as their public counterparts, but |
140 // destination is an ancestor of source) failed. | 132 // take an extra |success| parameter which indicates if the function is |
141 FloatRect slowSourceToDestinationVisualRect( | 133 // successful on return. See comments of the public functions for failure |
| 134 // conditions. |
| 135 |
| 136 FloatRect sourceToDestinationVisualRectInternal( |
142 const FloatRect&, | 137 const FloatRect&, |
143 const PropertyTreeState& sourceState, | 138 const PropertyTreeState& sourceState, |
144 const PropertyTreeState& destinationState, | 139 const PropertyTreeState& destinationState, |
145 bool& success); | 140 bool& success); |
146 | 141 |
147 // Used by sourceToDestinationRect() after fast mapping (assuming destination | 142 FloatRect localToAncestorVisualRectInternal( |
148 // is an ancestor of source) failed. | |
149 FloatRect slowSourceToDestinationRect( | |
150 const FloatRect&, | 143 const FloatRect&, |
151 const TransformPaintPropertyNode* sourceTransformNode, | 144 const PropertyTreeState& localTransformState, |
152 const TransformPaintPropertyNode* destinationTransformNode, | 145 const PropertyTreeState& ancestorState, |
| 146 bool& success); |
| 147 |
| 148 FloatRect localToAncestorRectInternal( |
| 149 const FloatRect&, |
| 150 const TransformPaintPropertyNode* localTransformNode, |
| 151 const TransformPaintPropertyNode* ancestorTransformNode, |
| 152 bool& success); |
| 153 |
| 154 const TransformationMatrix& localToAncestorMatrixInternal( |
| 155 const TransformPaintPropertyNode* localTransformNode, |
| 156 const TransformPaintPropertyNode* ancestorTransformNode, |
| 157 bool& success); |
| 158 |
| 159 FloatRect localToAncestorClipRectInternal( |
| 160 const PropertyTreeState& localTransformState, |
| 161 const PropertyTreeState& ancestorState, |
153 bool& success); | 162 bool& success); |
154 | 163 |
155 // Returns the precomputed data if already set, or adds and memoizes a new | 164 // Returns the precomputed data if already set, or adds and memoizes a new |
156 // PrecomputedDataForAncestor otherwise. | 165 // PrecomputedDataForAncestor otherwise. |
157 PrecomputedDataForAncestor& getPrecomputedDataForAncestor( | 166 PrecomputedDataForAncestor& getPrecomputedDataForAncestor( |
158 const TransformPaintPropertyNode*); | 167 const TransformPaintPropertyNode*); |
159 | 168 |
160 // Returns the least common ancestor in the transform tree. | 169 // Returns the least common ancestor in the transform tree. |
161 static const TransformPaintPropertyNode* leastCommonAncestor( | 170 static const TransformPaintPropertyNode* leastCommonAncestor( |
162 const TransformPaintPropertyNode*, | 171 const TransformPaintPropertyNode*, |
163 const TransformPaintPropertyNode*); | 172 const TransformPaintPropertyNode*); |
164 | 173 |
165 friend class GeometryMapperTest; | 174 friend class GeometryMapperTest; |
166 | 175 |
167 HashMap<const TransformPaintPropertyNode*, | 176 HashMap<const TransformPaintPropertyNode*, |
168 std::unique_ptr<PrecomputedDataForAncestor>> | 177 std::unique_ptr<PrecomputedDataForAncestor>> |
169 m_data; | 178 m_data; |
170 | 179 |
171 const TransformationMatrix m_identity; | 180 const TransformationMatrix m_identity; |
172 | 181 |
173 DISALLOW_COPY_AND_ASSIGN(GeometryMapper); | 182 DISALLOW_COPY_AND_ASSIGN(GeometryMapper); |
174 }; | 183 }; |
175 | 184 |
176 } // namespace blink | 185 } // namespace blink |
177 | 186 |
178 #endif // GeometryMapper_h | 187 #endif // GeometryMapper_h |
OLD | NEW |