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 #include "platform/graphics/paint/GeometryMapper.h" | 5 #include "platform/graphics/paint/GeometryMapper.h" |
6 | 6 |
7 #include "platform/geometry/GeometryTestHelpers.h" | 7 #include "platform/geometry/GeometryTestHelpers.h" |
8 #include "platform/geometry/LayoutRect.h" | 8 #include "platform/geometry/LayoutRect.h" |
9 #include "platform/graphics/BoxReflection.h" | 9 #include "platform/graphics/BoxReflection.h" |
10 #include "platform/graphics/filters/SkiaImageFilterBuilder.h" | 10 #include "platform/graphics/filters/SkiaImageFilterBuilder.h" |
(...skipping 13 matching lines...) Expand all Loading... |
24 | 24 |
25 std::unique_ptr<GeometryMapper> geometryMapper; | 25 std::unique_ptr<GeometryMapper> geometryMapper; |
26 | 26 |
27 PropertyTreeState rootPropertyTreeState() { | 27 PropertyTreeState rootPropertyTreeState() { |
28 PropertyTreeState state(TransformPaintPropertyNode::root(), | 28 PropertyTreeState state(TransformPaintPropertyNode::root(), |
29 ClipPaintPropertyNode::root(), | 29 ClipPaintPropertyNode::root(), |
30 EffectPaintPropertyNode::root()); | 30 EffectPaintPropertyNode::root()); |
31 return state; | 31 return state; |
32 } | 32 } |
33 | 33 |
34 GeometryMapper::TransformCache& getTransformCache( | 34 const TransformationMatrix* getTransform( |
35 const PropertyTreeState& propertyTreeState) { | 35 const TransformPaintPropertyNode* descendantTransform, |
36 return geometryMapper->getTransformCache(propertyTreeState.transform()); | 36 const TransformPaintPropertyNode* ancestorTransform) { |
| 37 return geometryMapper->getTransform(descendantTransform, ancestorTransform); |
37 } | 38 } |
38 | 39 |
39 GeometryMapper::ClipCache& getClipCache( | 40 const FloatClipRect* getClip( |
40 const PropertyTreeState& propertyTreeState) { | 41 const ClipPaintPropertyNode* descendantClip, |
41 return geometryMapper->getClipCache(propertyTreeState.clip(), | 42 const PropertyTreeState& ancestorPropertyTreeState) { |
42 propertyTreeState.transform()); | 43 GeometryMapper::ClipAndTransform clipAndTransform( |
| 44 ancestorPropertyTreeState.clip(), |
| 45 ancestorPropertyTreeState.transform()); |
| 46 return geometryMapper->getClip(descendantClip, clipAndTransform); |
43 } | 47 } |
44 | 48 |
45 const TransformPaintPropertyNode* lowestCommonAncestor( | 49 const TransformPaintPropertyNode* lowestCommonAncestor( |
46 const TransformPaintPropertyNode* a, | 50 const TransformPaintPropertyNode* a, |
47 const TransformPaintPropertyNode* b) { | 51 const TransformPaintPropertyNode* b) { |
48 return GeometryMapper::lowestCommonAncestor(a, b); | 52 return GeometryMapper::lowestCommonAncestor(a, b); |
49 } | 53 } |
50 | 54 |
51 FloatRect sourceToDestinationVisualRectInternal( | 55 FloatRect sourceToDestinationVisualRectInternal( |
52 const FloatRect& rect, | 56 const FloatRect& rect, |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 EXPECT_RECT_EQ(expectedTransformedRect, \ | 137 EXPECT_RECT_EQ(expectedTransformedRect, \ |
134 geometryMapper->localToAncestorRect( \ | 138 geometryMapper->localToAncestorRect( \ |
135 inputRect, localPropertyTreeState.transform(), \ | 139 inputRect, localPropertyTreeState.transform(), \ |
136 ancestorPropertyTreeState.transform())); \ | 140 ancestorPropertyTreeState.transform())); \ |
137 EXPECT_RECT_EQ(expectedTransformedRect, \ | 141 EXPECT_RECT_EQ(expectedTransformedRect, \ |
138 geometryMapper->sourceToDestinationRect( \ | 142 geometryMapper->sourceToDestinationRect( \ |
139 inputRect, localPropertyTreeState.transform(), \ | 143 inputRect, localPropertyTreeState.transform(), \ |
140 ancestorPropertyTreeState.transform())); \ | 144 ancestorPropertyTreeState.transform())); \ |
141 if (ancestorPropertyTreeState.transform() != \ | 145 if (ancestorPropertyTreeState.transform() != \ |
142 localPropertyTreeState.transform()) { \ | 146 localPropertyTreeState.transform()) { \ |
143 EXPECT_EQ(expectedTransformToAncestor, \ | 147 const TransformationMatrix* transformForTesting = \ |
144 getTransformCache(ancestorPropertyTreeState) \ | 148 getTransform(localPropertyTreeState.transform(), \ |
145 .at(localPropertyTreeState.transform())); \ | 149 ancestorPropertyTreeState.transform()); \ |
| 150 CHECK(transformForTesting); \ |
| 151 EXPECT_EQ(expectedTransformToAncestor, *transformForTesting); \ |
146 } \ | 152 } \ |
147 if (ancestorPropertyTreeState.clip() != localPropertyTreeState.clip()) { \ | 153 if (ancestorPropertyTreeState.clip() != localPropertyTreeState.clip()) { \ |
148 EXPECT_EQ(expectedClipInAncestorSpace, \ | 154 const FloatClipRect* outputClipForTesting = \ |
149 getClipCache(ancestorPropertyTreeState) \ | 155 getClip(localPropertyTreeState.clip(), ancestorPropertyTreeState); \ |
150 .at(localPropertyTreeState.clip())) \ | 156 DCHECK(outputClipForTesting); \ |
| 157 EXPECT_EQ(expectedClipInAncestorSpace, *outputClipForTesting) \ |
151 << expectedClipInAncestorSpace.rect().toString() << " " \ | 158 << expectedClipInAncestorSpace.rect().toString() << " " \ |
152 << getClipCache(ancestorPropertyTreeState) \ | 159 << outputClipForTesting->rect().toString(); \ |
153 .at(localPropertyTreeState.clip()) \ | |
154 .rect() \ | |
155 .toString(); \ | |
156 } \ | 160 } \ |
157 } while (false) | 161 } while (false) |
158 | 162 |
159 TEST_F(GeometryMapperTest, Root) { | 163 TEST_F(GeometryMapperTest, Root) { |
160 FloatRect input(0, 0, 100, 100); | 164 FloatRect input(0, 0, 100, 100); |
161 | 165 |
162 bool hasRadius = false; | 166 bool hasRadius = false; |
163 CHECK_MAPPINGS(input, input, input, | 167 CHECK_MAPPINGS(input, input, input, |
164 TransformPaintPropertyNode::root()->matrix(), FloatClipRect(), | 168 TransformPaintPropertyNode::root()->matrix(), FloatClipRect(), |
165 rootPropertyTreeState(), rootPropertyTreeState(), hasRadius); | 169 rootPropertyTreeState(), rootPropertyTreeState(), hasRadius); |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
258 | 262 |
259 FloatRect input(0, 0, 100, 100); | 263 FloatRect input(0, 0, 100, 100); |
260 TransformationMatrix final = rotateTransform * scaleTransform; | 264 TransformationMatrix final = rotateTransform * scaleTransform; |
261 FloatRect output = final.mapRect(input); | 265 FloatRect output = final.mapRect(input); |
262 | 266 |
263 bool hasRadius = false; | 267 bool hasRadius = false; |
264 CHECK_MAPPINGS(input, output, output, final, FloatClipRect(), localState, | 268 CHECK_MAPPINGS(input, output, output, final, FloatClipRect(), localState, |
265 rootPropertyTreeState(), hasRadius); | 269 rootPropertyTreeState(), hasRadius); |
266 | 270 |
267 // Check the cached matrix for the intermediate transform. | 271 // Check the cached matrix for the intermediate transform. |
268 EXPECT_EQ(rotateTransform, | 272 EXPECT_EQ( |
269 getTransformCache(rootPropertyTreeState()).at(transform1.get())); | 273 rotateTransform, |
| 274 *getTransform(transform1.get(), rootPropertyTreeState().transform())); |
270 } | 275 } |
271 | 276 |
272 TEST_F(GeometryMapperTest, NestedTransformsScaleAndTranslation) { | 277 TEST_F(GeometryMapperTest, NestedTransformsScaleAndTranslation) { |
273 TransformationMatrix scaleTransform; | 278 TransformationMatrix scaleTransform; |
274 scaleTransform.scale(2); | 279 scaleTransform.scale(2); |
275 RefPtr<TransformPaintPropertyNode> transform1 = | 280 RefPtr<TransformPaintPropertyNode> transform1 = |
276 TransformPaintPropertyNode::create(rootPropertyTreeState().transform(), | 281 TransformPaintPropertyNode::create(rootPropertyTreeState().transform(), |
277 scaleTransform, FloatPoint3D()); | 282 scaleTransform, FloatPoint3D()); |
278 | 283 |
279 TransformationMatrix translateTransform; | 284 TransformationMatrix translateTransform; |
280 translateTransform.translate(100, 0); | 285 translateTransform.translate(100, 0); |
281 RefPtr<TransformPaintPropertyNode> transform2 = | 286 RefPtr<TransformPaintPropertyNode> transform2 = |
282 TransformPaintPropertyNode::create(transform1, translateTransform, | 287 TransformPaintPropertyNode::create(transform1, translateTransform, |
283 FloatPoint3D()); | 288 FloatPoint3D()); |
284 | 289 |
285 PropertyTreeState localState = rootPropertyTreeState(); | 290 PropertyTreeState localState = rootPropertyTreeState(); |
286 localState.setTransform(transform2.get()); | 291 localState.setTransform(transform2.get()); |
287 | 292 |
288 FloatRect input(0, 0, 100, 100); | 293 FloatRect input(0, 0, 100, 100); |
289 // Note: unlike NestedTransforms, the order of these transforms matters. This | 294 // Note: unlike NestedTransforms, the order of these transforms matters. This |
290 // tests correct order of matrix multiplication. | 295 // tests correct order of matrix multiplication. |
291 TransformationMatrix final = scaleTransform * translateTransform; | 296 TransformationMatrix final = scaleTransform * translateTransform; |
292 FloatRect output = final.mapRect(input); | 297 FloatRect output = final.mapRect(input); |
293 | 298 |
294 bool hasRadius = false; | 299 bool hasRadius = false; |
295 CHECK_MAPPINGS(input, output, output, final, FloatClipRect(), localState, | 300 CHECK_MAPPINGS(input, output, output, final, FloatClipRect(), localState, |
296 rootPropertyTreeState(), hasRadius); | 301 rootPropertyTreeState(), hasRadius); |
297 | 302 |
298 // Check the cached matrix for the intermediate transform. | 303 // Check the cached matrix for the intermediate transform. |
299 EXPECT_EQ(scaleTransform, | 304 EXPECT_EQ(scaleTransform, *getTransform(transform1.get(), |
300 getTransformCache(rootPropertyTreeState()) | 305 rootPropertyTreeState().transform())); |
301 | |
302 .at(transform1.get())); | |
303 } | 306 } |
304 | 307 |
305 TEST_F(GeometryMapperTest, NestedTransformsIntermediateDestination) { | 308 TEST_F(GeometryMapperTest, NestedTransformsIntermediateDestination) { |
306 TransformationMatrix rotateTransform; | 309 TransformationMatrix rotateTransform; |
307 rotateTransform.rotate(45); | 310 rotateTransform.rotate(45); |
308 RefPtr<TransformPaintPropertyNode> transform1 = | 311 RefPtr<TransformPaintPropertyNode> transform1 = |
309 TransformPaintPropertyNode::create(rootPropertyTreeState().transform(), | 312 TransformPaintPropertyNode::create(rootPropertyTreeState().transform(), |
310 rotateTransform, FloatPoint3D()); | 313 rotateTransform, FloatPoint3D()); |
311 | 314 |
312 TransformationMatrix scaleTransform; | 315 TransformationMatrix scaleTransform; |
(...skipping 518 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
831 FloatRect input(100, 100, 50, 50); | 834 FloatRect input(100, 100, 50, 50); |
832 // Reflection is at (50, 100, 50, 50). | 835 // Reflection is at (50, 100, 50, 50). |
833 FloatRect output(50, 100, 100, 50); | 836 FloatRect output(50, 100, 100, 50); |
834 | 837 |
835 bool hasRadius = false; | 838 bool hasRadius = false; |
836 CHECK_MAPPINGS(input, output, input, TransformationMatrix(), FloatClipRect(), | 839 CHECK_MAPPINGS(input, output, input, TransformationMatrix(), FloatClipRect(), |
837 localState, rootPropertyTreeState(), hasRadius); | 840 localState, rootPropertyTreeState(), hasRadius); |
838 } | 841 } |
839 | 842 |
840 } // namespace blink | 843 } // namespace blink |
OLD | NEW |