Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(22)

Side by Side Diff: third_party/WebKit/Source/platform/graphics/paint/GeometryMapperTest.cpp

Issue 2672993004: Fix clip caching bug in GeometryMapper. (Closed)
Patch Set: Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/paint/ClipPaintPropertyNode.h" 9 #include "platform/graphics/paint/ClipPaintPropertyNode.h"
10 #include "platform/graphics/paint/EffectPaintPropertyNode.h" 10 #include "platform/graphics/paint/EffectPaintPropertyNode.h"
(...skipping 11 matching lines...) Expand all
22 22
23 std::unique_ptr<GeometryMapper> geometryMapper; 23 std::unique_ptr<GeometryMapper> geometryMapper;
24 24
25 PropertyTreeState rootPropertyTreeState() { 25 PropertyTreeState rootPropertyTreeState() {
26 PropertyTreeState state(TransformPaintPropertyNode::root(), 26 PropertyTreeState state(TransformPaintPropertyNode::root(),
27 ClipPaintPropertyNode::root(), 27 ClipPaintPropertyNode::root(),
28 EffectPaintPropertyNode::root()); 28 EffectPaintPropertyNode::root());
29 return state; 29 return state;
30 } 30 }
31 31
32 PrecomputedDataForAncestor& getPrecomputedDataForAncestor( 32 TransformCache& getTransformCache(
33 const PropertyTreeState& propertyTreeState) { 33 const PropertyTreeState& propertyTreeState) {
34 return geometryMapper->getPrecomputedDataForAncestor( 34 return geometryMapper->getTransformCache(propertyTreeState.transform());
35 propertyTreeState.transform()); 35 }
36
37 ClipCache& getClipCache(const PropertyTreeState& propertyTreeState) {
38 return geometryMapper->getClipCache(propertyTreeState.transform(),
39 propertyTreeState.clip());
36 } 40 }
37 41
38 const TransformPaintPropertyNode* lowestCommonAncestor( 42 const TransformPaintPropertyNode* lowestCommonAncestor(
39 const TransformPaintPropertyNode* a, 43 const TransformPaintPropertyNode* a,
40 const TransformPaintPropertyNode* b) { 44 const TransformPaintPropertyNode* b) {
41 return GeometryMapper::lowestCommonAncestor(a, b); 45 return GeometryMapper::lowestCommonAncestor(a, b);
42 } 46 }
43 47
44 FloatRect sourceToDestinationVisualRectInternal( 48 FloatRect sourceToDestinationVisualRectInternal(
45 const FloatRect& rect, 49 const FloatRect& rect,
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 EXPECT_RECT_EQ(expectedTransformedRect, \ 120 EXPECT_RECT_EQ(expectedTransformedRect, \
117 geometryMapper->localToAncestorRect( \ 121 geometryMapper->localToAncestorRect( \
118 inputRect, localPropertyTreeState.transform(), \ 122 inputRect, localPropertyTreeState.transform(), \
119 ancestorPropertyTreeState.transform())); \ 123 ancestorPropertyTreeState.transform())); \
120 EXPECT_RECT_EQ(expectedTransformedRect, \ 124 EXPECT_RECT_EQ(expectedTransformedRect, \
121 geometryMapper->sourceToDestinationRect( \ 125 geometryMapper->sourceToDestinationRect( \
122 inputRect, localPropertyTreeState.transform(), \ 126 inputRect, localPropertyTreeState.transform(), \
123 ancestorPropertyTreeState.transform())); \ 127 ancestorPropertyTreeState.transform())); \
124 if (ancestorPropertyTreeState.transform() != \ 128 if (ancestorPropertyTreeState.transform() != \
125 localPropertyTreeState.transform()) { \ 129 localPropertyTreeState.transform()) { \
126 EXPECT_EQ( \ 130 EXPECT_EQ(expectedTransformToAncestor, \
127 expectedTransformToAncestor, \ 131 getTransformCache(ancestorPropertyTreeState) \
128 getPrecomputedDataForAncestor(ancestorPropertyTreeState) \ 132 .get(localPropertyTreeState.transform())); \
129 .toAncestorTransforms.get(localPropertyTreeState.transform())); \
130 } \ 133 } \
131 if (ancestorPropertyTreeState.clip() != localPropertyTreeState.clip()) { \ 134 if (ancestorPropertyTreeState.clip() != localPropertyTreeState.clip()) { \
132 EXPECT_EQ(expectedClipInAncestorSpace, \ 135 EXPECT_EQ(expectedClipInAncestorSpace, \
133 getPrecomputedDataForAncestor(ancestorPropertyTreeState) \ 136 getClipCache(ancestorPropertyTreeState) \
134 .toAncestorClipRects.get(localPropertyTreeState.clip())); \ 137 .get(localPropertyTreeState.clip())); \
135 } \ 138 } \
136 } while (false) 139 } while (false)
137 140
138 TEST_F(GeometryMapperTest, Root) { 141 TEST_F(GeometryMapperTest, Root) {
139 FloatRect input(0, 0, 100, 100); 142 FloatRect input(0, 0, 100, 100);
140 143
141 CHECK_MAPPINGS(input, input, input, 144 CHECK_MAPPINGS(input, input, input,
142 TransformPaintPropertyNode::root()->matrix(), 145 TransformPaintPropertyNode::root()->matrix(),
143 ClipPaintPropertyNode::root()->clipRect().rect(), 146 ClipPaintPropertyNode::root()->clipRect().rect(),
144 rootPropertyTreeState(), rootPropertyTreeState()); 147 rootPropertyTreeState(), rootPropertyTreeState());
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 FloatRect input(0, 0, 100, 100); 241 FloatRect input(0, 0, 100, 100);
239 TransformationMatrix final = rotateTransform * scaleTransform; 242 TransformationMatrix final = rotateTransform * scaleTransform;
240 FloatRect output = final.mapRect(input); 243 FloatRect output = final.mapRect(input);
241 244
242 CHECK_MAPPINGS(input, output, output, final, 245 CHECK_MAPPINGS(input, output, output, final,
243 ClipPaintPropertyNode::root()->clipRect().rect(), localState, 246 ClipPaintPropertyNode::root()->clipRect().rect(), localState,
244 rootPropertyTreeState()); 247 rootPropertyTreeState());
245 248
246 // Check the cached matrix for the intermediate transform. 249 // Check the cached matrix for the intermediate transform.
247 EXPECT_EQ(rotateTransform, 250 EXPECT_EQ(rotateTransform,
248 getPrecomputedDataForAncestor(rootPropertyTreeState()) 251 getTransformCache(rootPropertyTreeState()).get(transform1.get()));
249 .toAncestorTransforms.get(transform1.get()));
250 } 252 }
251 253
252 TEST_F(GeometryMapperTest, NestedTransformsScaleAndTranslation) { 254 TEST_F(GeometryMapperTest, NestedTransformsScaleAndTranslation) {
253 TransformationMatrix scaleTransform; 255 TransformationMatrix scaleTransform;
254 scaleTransform.scale(2); 256 scaleTransform.scale(2);
255 RefPtr<TransformPaintPropertyNode> transform1 = 257 RefPtr<TransformPaintPropertyNode> transform1 =
256 TransformPaintPropertyNode::create(rootPropertyTreeState().transform(), 258 TransformPaintPropertyNode::create(rootPropertyTreeState().transform(),
257 scaleTransform, FloatPoint3D()); 259 scaleTransform, FloatPoint3D());
258 260
259 TransformationMatrix translateTransform; 261 TransformationMatrix translateTransform;
260 translateTransform.translate(100, 0); 262 translateTransform.translate(100, 0);
261 RefPtr<TransformPaintPropertyNode> transform2 = 263 RefPtr<TransformPaintPropertyNode> transform2 =
262 TransformPaintPropertyNode::create(transform1, translateTransform, 264 TransformPaintPropertyNode::create(transform1, translateTransform,
263 FloatPoint3D()); 265 FloatPoint3D());
264 266
265 PropertyTreeState localState = rootPropertyTreeState(); 267 PropertyTreeState localState = rootPropertyTreeState();
266 localState.setTransform(transform2.get()); 268 localState.setTransform(transform2.get());
267 269
268 FloatRect input(0, 0, 100, 100); 270 FloatRect input(0, 0, 100, 100);
269 // Note: unlike NestedTransforms, the order of these transforms matters. This 271 // Note: unlike NestedTransforms, the order of these transforms matters. This
270 // tests correct order of matrix multiplication. 272 // tests correct order of matrix multiplication.
271 TransformationMatrix final = scaleTransform * translateTransform; 273 TransformationMatrix final = scaleTransform * translateTransform;
272 FloatRect output = final.mapRect(input); 274 FloatRect output = final.mapRect(input);
273 275
274 CHECK_MAPPINGS(input, output, output, final, 276 CHECK_MAPPINGS(input, output, output, final,
275 ClipPaintPropertyNode::root()->clipRect().rect(), localState, 277 ClipPaintPropertyNode::root()->clipRect().rect(), localState,
276 rootPropertyTreeState()); 278 rootPropertyTreeState());
277 279
278 // Check the cached matrix for the intermediate transform. 280 // Check the cached matrix for the intermediate transform.
279 EXPECT_EQ(scaleTransform, 281 EXPECT_EQ(scaleTransform, getTransformCache(rootPropertyTreeState())
280 getPrecomputedDataForAncestor(rootPropertyTreeState()) 282
281 .toAncestorTransforms.get(transform1.get())); 283 .get(transform1.get()));
282 } 284 }
283 285
284 TEST_F(GeometryMapperTest, NestedTransformsIntermediateDestination) { 286 TEST_F(GeometryMapperTest, NestedTransformsIntermediateDestination) {
285 TransformationMatrix rotateTransform; 287 TransformationMatrix rotateTransform;
286 rotateTransform.rotate(45); 288 rotateTransform.rotate(45);
287 RefPtr<TransformPaintPropertyNode> transform1 = 289 RefPtr<TransformPaintPropertyNode> transform1 =
288 TransformPaintPropertyNode::create(rootPropertyTreeState().transform(), 290 TransformPaintPropertyNode::create(rootPropertyTreeState().transform(),
289 rotateTransform, FloatPoint3D()); 291 rotateTransform, FloatPoint3D());
290 292
291 TransformationMatrix scaleTransform; 293 TransformationMatrix scaleTransform;
(...skipping 30 matching lines...) Expand all
322 CHECK_MAPPINGS(input, // Input 324 CHECK_MAPPINGS(input, // Input
323 output, // Visual rect 325 output, // Visual rect
324 input, // Transformed rect (not clipped). 326 input, // Transformed rect (not clipped).
325 TransformPaintPropertyNode::root() 327 TransformPaintPropertyNode::root()
326 ->matrix(), // Transform matrix to ancestor space 328 ->matrix(), // Transform matrix to ancestor space
327 clip->clipRect().rect(), // Clip rect in ancestor space 329 clip->clipRect().rect(), // Clip rect in ancestor space
328 localState, 330 localState,
329 rootPropertyTreeState()); 331 rootPropertyTreeState());
330 } 332 }
331 333
334 TEST_F(GeometryMapperTest, TwoClips) {
335 RefPtr<ClipPaintPropertyNode> clip1 = ClipPaintPropertyNode::create(
336 ClipPaintPropertyNode::root(), TransformPaintPropertyNode::root(),
337 FloatRoundedRect(10, 10, 30, 40));
338
339 RefPtr<ClipPaintPropertyNode> clip2 =
340 ClipPaintPropertyNode::create(clip1, TransformPaintPropertyNode::root(),
341 FloatRoundedRect(10, 10, 50, 50));
342
343 PropertyTreeState localState = rootPropertyTreeState();
344 PropertyTreeState ancestorState = rootPropertyTreeState();
345 localState.setClip(clip2.get());
346
347 FloatRect input(0, 0, 100, 100);
348 FloatRect output1(10, 10, 30, 40);
349
350 CHECK_MAPPINGS(input, // Input
351 output1, // Visual rect
352 input, // Transformed rect (not clipped).
353 TransformPaintPropertyNode::root()
354 ->matrix(), // Transform matrix to ancestor space
355 clip1->clipRect().rect(), // Clip rect in ancestor space
356 localState,
357 ancestorState);
358
359 ancestorState.setClip(clip1.get());
360 FloatRect output2(10, 10, 50, 50);
361
362 CHECK_MAPPINGS(input, // Input
363 output2, // Visual rect
364 input, // Transformed rect (not clipped).
365 TransformPaintPropertyNode::root()
366 ->matrix(), // Transform matrix to ancestor space
367 clip2->clipRect().rect(), // Clip rect in ancestor space
368 localState,
369 ancestorState);
370 }
371
332 TEST_F(GeometryMapperTest, ClipBeforeTransform) { 372 TEST_F(GeometryMapperTest, ClipBeforeTransform) {
333 TransformationMatrix rotateTransform; 373 TransformationMatrix rotateTransform;
334 rotateTransform.rotate(45); 374 rotateTransform.rotate(45);
335 RefPtr<TransformPaintPropertyNode> transform = 375 RefPtr<TransformPaintPropertyNode> transform =
336 TransformPaintPropertyNode::create(rootPropertyTreeState().transform(), 376 TransformPaintPropertyNode::create(rootPropertyTreeState().transform(),
337 rotateTransform, FloatPoint3D()); 377 rotateTransform, FloatPoint3D());
338 378
339 RefPtr<ClipPaintPropertyNode> clip = ClipPaintPropertyNode::create( 379 RefPtr<ClipPaintPropertyNode> clip = ClipPaintPropertyNode::create(
340 ClipPaintPropertyNode::root(), transform.get(), 380 ClipPaintPropertyNode::root(), transform.get(),
341 FloatRoundedRect(10, 10, 50, 50)); 381 FloatRoundedRect(10, 10, 50, 50));
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after
600 EXPECT_EQ(rootPropertyTreeState().transform(), 640 EXPECT_EQ(rootPropertyTreeState().transform(),
601 lowestCommonAncestor(childOfChild2.get(), 641 lowestCommonAncestor(childOfChild2.get(),
602 rootPropertyTreeState().transform())); 642 rootPropertyTreeState().transform()));
603 EXPECT_EQ(child2, lowestCommonAncestor(childOfChild2.get(), child2.get())); 643 EXPECT_EQ(child2, lowestCommonAncestor(childOfChild2.get(), child2.get()));
604 644
605 EXPECT_EQ(rootPropertyTreeState().transform(), 645 EXPECT_EQ(rootPropertyTreeState().transform(),
606 lowestCommonAncestor(child1.get(), child2.get())); 646 lowestCommonAncestor(child1.get(), child2.get()));
607 } 647 }
608 648
609 } // namespace blink 649 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698