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 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
189 PropertyTreeState localState = rootPropertyTreeState(); | 189 PropertyTreeState localState = rootPropertyTreeState(); |
190 localState.setTransform(transform.get()); | 190 localState.setTransform(transform.get()); |
191 | 191 |
192 FloatRect input(0, 0, 100, 100); | 192 FloatRect input(0, 0, 100, 100); |
193 FloatRect output = transformMatrix.mapRect(input); | 193 FloatRect output = transformMatrix.mapRect(input); |
194 | 194 |
195 bool hasRadius = false; | 195 bool hasRadius = false; |
196 CHECK_MAPPINGS(input, output, output, transform->matrix(), FloatClipRect(), | 196 CHECK_MAPPINGS(input, output, output, transform->matrix(), FloatClipRect(), |
197 localState, rootPropertyTreeState(), hasRadius); | 197 localState, rootPropertyTreeState(), hasRadius); |
198 | 198 |
199 EXPECT_RECT_EQ(input, geometryMapper->ancestorToLocalRect( | 199 EXPECT_RECT_EQ( |
200 output, rootPropertyTreeState().transform(), | 200 input, |
201 localState.transform())); | 201 geometryMapper->ancestorToLocalRect( |
| 202 output, rootPropertyTreeState().transform(), localState.transform())); |
202 } | 203 } |
203 | 204 |
204 TEST_F(GeometryMapperTest, RotationAndScaleTransform) { | 205 TEST_F(GeometryMapperTest, RotationAndScaleTransform) { |
205 TransformationMatrix transformMatrix; | 206 TransformationMatrix transformMatrix; |
206 transformMatrix.rotate(45); | 207 transformMatrix.rotate(45); |
207 transformMatrix.scale(2); | 208 transformMatrix.scale(2); |
208 RefPtr<TransformPaintPropertyNode> transform = | 209 RefPtr<TransformPaintPropertyNode> transform = |
209 TransformPaintPropertyNode::create(rootPropertyTreeState().transform(), | 210 TransformPaintPropertyNode::create(rootPropertyTreeState().transform(), |
210 transformMatrix, | 211 transformMatrix, |
211 FloatPoint3D(0, 0, 0)); | 212 FloatPoint3D(0, 0, 0)); |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
289 // Note: unlike NestedTransforms, the order of these transforms matters. This | 290 // Note: unlike NestedTransforms, the order of these transforms matters. This |
290 // tests correct order of matrix multiplication. | 291 // tests correct order of matrix multiplication. |
291 TransformationMatrix final = scaleTransform * translateTransform; | 292 TransformationMatrix final = scaleTransform * translateTransform; |
292 FloatRect output = final.mapRect(input); | 293 FloatRect output = final.mapRect(input); |
293 | 294 |
294 bool hasRadius = false; | 295 bool hasRadius = false; |
295 CHECK_MAPPINGS(input, output, output, final, FloatClipRect(), localState, | 296 CHECK_MAPPINGS(input, output, output, final, FloatClipRect(), localState, |
296 rootPropertyTreeState(), hasRadius); | 297 rootPropertyTreeState(), hasRadius); |
297 | 298 |
298 // Check the cached matrix for the intermediate transform. | 299 // Check the cached matrix for the intermediate transform. |
299 EXPECT_EQ(scaleTransform, getTransformCache(rootPropertyTreeState()) | 300 EXPECT_EQ(scaleTransform, |
| 301 getTransformCache(rootPropertyTreeState()) |
300 | 302 |
301 .get(transform1.get())); | 303 .get(transform1.get())); |
302 } | 304 } |
303 | 305 |
304 TEST_F(GeometryMapperTest, NestedTransformsIntermediateDestination) { | 306 TEST_F(GeometryMapperTest, NestedTransformsIntermediateDestination) { |
305 TransformationMatrix rotateTransform; | 307 TransformationMatrix rotateTransform; |
306 rotateTransform.rotate(45); | 308 rotateTransform.rotate(45); |
307 RefPtr<TransformPaintPropertyNode> transform1 = | 309 RefPtr<TransformPaintPropertyNode> transform1 = |
308 TransformPaintPropertyNode::create(rootPropertyTreeState().transform(), | 310 TransformPaintPropertyNode::create(rootPropertyTreeState().transform(), |
309 rotateTransform, FloatPoint3D()); | 311 rotateTransform, FloatPoint3D()); |
310 | 312 |
311 TransformationMatrix scaleTransform; | 313 TransformationMatrix scaleTransform; |
(...skipping 28 matching lines...) Expand all Loading... |
340 FloatRect output(10, 10, 50, 50); | 342 FloatRect output(10, 10, 50, 50); |
341 | 343 |
342 bool hasRadius = false; | 344 bool hasRadius = false; |
343 CHECK_MAPPINGS(input, // Input | 345 CHECK_MAPPINGS(input, // Input |
344 output, // Visual rect | 346 output, // Visual rect |
345 input, // Transformed rect (not clipped). | 347 input, // Transformed rect (not clipped). |
346 TransformPaintPropertyNode::root() | 348 TransformPaintPropertyNode::root() |
347 ->matrix(), // Transform matrix to ancestor space | 349 ->matrix(), // Transform matrix to ancestor space |
348 FloatClipRect(clip->clipRect().rect()), // Clip rect in | 350 FloatClipRect(clip->clipRect().rect()), // Clip rect in |
349 // ancestor space | 351 // ancestor space |
350 localState, | 352 localState, rootPropertyTreeState(), hasRadius); |
351 rootPropertyTreeState(), hasRadius); | |
352 } | 353 } |
353 | 354 |
354 TEST_F(GeometryMapperTest, RoundedClip) { | 355 TEST_F(GeometryMapperTest, RoundedClip) { |
355 FloatRoundedRect rect(FloatRect(10, 10, 50, 50), | 356 FloatRoundedRect rect(FloatRect(10, 10, 50, 50), |
356 FloatRoundedRect::Radii(FloatSize(1, 1), FloatSize(), | 357 FloatRoundedRect::Radii(FloatSize(1, 1), FloatSize(), |
357 FloatSize(), FloatSize())); | 358 FloatSize(), FloatSize())); |
358 RefPtr<ClipPaintPropertyNode> clip = ClipPaintPropertyNode::create( | 359 RefPtr<ClipPaintPropertyNode> clip = ClipPaintPropertyNode::create( |
359 ClipPaintPropertyNode::root(), TransformPaintPropertyNode::root(), rect); | 360 ClipPaintPropertyNode::root(), TransformPaintPropertyNode::root(), rect); |
360 | 361 |
361 PropertyTreeState localState = rootPropertyTreeState(); | 362 PropertyTreeState localState = rootPropertyTreeState(); |
362 localState.setClip(clip.get()); | 363 localState.setClip(clip.get()); |
363 | 364 |
364 FloatRect input(0, 0, 100, 100); | 365 FloatRect input(0, 0, 100, 100); |
365 FloatRect output(10, 10, 50, 50); | 366 FloatRect output(10, 10, 50, 50); |
366 | 367 |
367 FloatClipRect expectedClip(clip->clipRect().rect()); | 368 FloatClipRect expectedClip(clip->clipRect().rect()); |
368 expectedClip.setHasRadius(); | 369 expectedClip.setHasRadius(); |
369 | 370 |
370 bool hasRadius = true; | 371 bool hasRadius = true; |
371 CHECK_MAPPINGS(input, // Input | 372 CHECK_MAPPINGS(input, // Input |
372 output, // Visual rect | 373 output, // Visual rect |
373 input, // Transformed rect (not clipped). | 374 input, // Transformed rect (not clipped). |
374 TransformPaintPropertyNode::root() | 375 TransformPaintPropertyNode::root() |
375 ->matrix(), // Transform matrix to ancestor space | 376 ->matrix(), // Transform matrix to ancestor space |
376 expectedClip, // Clip rect in ancestor space | 377 expectedClip, // Clip rect in ancestor space |
377 localState, | 378 localState, rootPropertyTreeState(), hasRadius); |
378 rootPropertyTreeState(), hasRadius); | |
379 } | 379 } |
380 | 380 |
381 TEST_F(GeometryMapperTest, TwoClips) { | 381 TEST_F(GeometryMapperTest, TwoClips) { |
382 FloatRoundedRect clipRect1( | 382 FloatRoundedRect clipRect1( |
383 FloatRect(10, 10, 30, 40), | 383 FloatRect(10, 10, 30, 40), |
384 FloatRoundedRect::Radii(FloatSize(1, 1), FloatSize(), FloatSize(), | 384 FloatRoundedRect::Radii(FloatSize(1, 1), FloatSize(), FloatSize(), |
385 FloatSize())); | 385 FloatSize())); |
386 | 386 |
387 RefPtr<ClipPaintPropertyNode> clip1 = ClipPaintPropertyNode::create( | 387 RefPtr<ClipPaintPropertyNode> clip1 = ClipPaintPropertyNode::create( |
388 ClipPaintPropertyNode::root(), TransformPaintPropertyNode::root(), | 388 ClipPaintPropertyNode::root(), TransformPaintPropertyNode::root(), |
(...skipping 13 matching lines...) Expand all Loading... |
402 FloatClipRect clipRect(clip1->clipRect().rect()); | 402 FloatClipRect clipRect(clip1->clipRect().rect()); |
403 clipRect.setHasRadius(); | 403 clipRect.setHasRadius(); |
404 | 404 |
405 bool hasRadius = true; | 405 bool hasRadius = true; |
406 CHECK_MAPPINGS(input, // Input | 406 CHECK_MAPPINGS(input, // Input |
407 output1, // Visual rect | 407 output1, // Visual rect |
408 input, // Transformed rect (not clipped). | 408 input, // Transformed rect (not clipped). |
409 TransformPaintPropertyNode::root() | 409 TransformPaintPropertyNode::root() |
410 ->matrix(), // Transform matrix to ancestor space | 410 ->matrix(), // Transform matrix to ancestor space |
411 clipRect, // Clip rect in ancestor space | 411 clipRect, // Clip rect in ancestor space |
412 localState, | 412 localState, ancestorState, hasRadius); |
413 ancestorState, hasRadius); | |
414 | 413 |
415 ancestorState.setClip(clip1.get()); | 414 ancestorState.setClip(clip1.get()); |
416 FloatRect output2(10, 10, 50, 50); | 415 FloatRect output2(10, 10, 50, 50); |
417 | 416 |
418 clipRect.setRect(clip2->clipRect().rect()); | 417 clipRect.setRect(clip2->clipRect().rect()); |
419 | 418 |
420 hasRadius = false; | 419 hasRadius = false; |
421 CHECK_MAPPINGS(input, // Input | 420 CHECK_MAPPINGS(input, // Input |
422 output2, // Visual rect | 421 output2, // Visual rect |
423 input, // Transformed rect (not clipped). | 422 input, // Transformed rect (not clipped). |
424 TransformPaintPropertyNode::root() | 423 TransformPaintPropertyNode::root() |
425 ->matrix(), // Transform matrix to ancestor space | 424 ->matrix(), // Transform matrix to ancestor space |
426 clipRect, // Clip rect in ancestor space | 425 clipRect, // Clip rect in ancestor space |
427 localState, | 426 localState, ancestorState, hasRadius); |
428 ancestorState, hasRadius); | |
429 } | 427 } |
430 | 428 |
431 TEST_F(GeometryMapperTest, TwoClipsTransformAbove) { | 429 TEST_F(GeometryMapperTest, TwoClipsTransformAbove) { |
432 RefPtr<TransformPaintPropertyNode> transform = | 430 RefPtr<TransformPaintPropertyNode> transform = |
433 TransformPaintPropertyNode::create(rootPropertyTreeState().transform(), | 431 TransformPaintPropertyNode::create(rootPropertyTreeState().transform(), |
434 TransformationMatrix(), | 432 TransformationMatrix(), |
435 FloatPoint3D()); | 433 FloatPoint3D()); |
436 | 434 |
437 FloatRoundedRect clipRect1( | 435 FloatRoundedRect clipRect1( |
438 FloatRect(10, 10, 50, 50), | 436 FloatRect(10, 10, 50, 50), |
(...skipping 16 matching lines...) Expand all Loading... |
455 FloatClipRect expectedClip(clip2->clipRect().rect()); | 453 FloatClipRect expectedClip(clip2->clipRect().rect()); |
456 expectedClip.setHasRadius(); | 454 expectedClip.setHasRadius(); |
457 | 455 |
458 bool hasRadius = true; | 456 bool hasRadius = true; |
459 CHECK_MAPPINGS(input, // Input | 457 CHECK_MAPPINGS(input, // Input |
460 output1, // Visual rect | 458 output1, // Visual rect |
461 input, // Transformed rect (not clipped). | 459 input, // Transformed rect (not clipped). |
462 TransformPaintPropertyNode::root() | 460 TransformPaintPropertyNode::root() |
463 ->matrix(), // Transform matrix to ancestor space | 461 ->matrix(), // Transform matrix to ancestor space |
464 expectedClip, // Clip rect in ancestor space | 462 expectedClip, // Clip rect in ancestor space |
465 localState, | 463 localState, ancestorState, hasRadius); |
466 ancestorState, hasRadius); | |
467 | 464 |
468 expectedClip.setRect(clip1->clipRect().rect()); | 465 expectedClip.setRect(clip1->clipRect().rect()); |
469 localState.setClip(clip1.get()); | 466 localState.setClip(clip1.get()); |
470 FloatRect output2(10, 10, 50, 50); | 467 FloatRect output2(10, 10, 50, 50); |
471 CHECK_MAPPINGS(input, // Input | 468 CHECK_MAPPINGS(input, // Input |
472 output2, // Visual rect | 469 output2, // Visual rect |
473 input, // Transformed rect (not clipped). | 470 input, // Transformed rect (not clipped). |
474 TransformPaintPropertyNode::root() | 471 TransformPaintPropertyNode::root() |
475 ->matrix(), // Transform matrix to ancestor space | 472 ->matrix(), // Transform matrix to ancestor space |
476 expectedClip, // Clip rect in ancestor space | 473 expectedClip, // Clip rect in ancestor space |
477 localState, | 474 localState, ancestorState, hasRadius); |
478 ancestorState, hasRadius); | |
479 } | 475 } |
480 | 476 |
481 TEST_F(GeometryMapperTest, ClipBeforeTransform) { | 477 TEST_F(GeometryMapperTest, ClipBeforeTransform) { |
482 TransformationMatrix rotateTransform; | 478 TransformationMatrix rotateTransform; |
483 rotateTransform.rotate(45); | 479 rotateTransform.rotate(45); |
484 RefPtr<TransformPaintPropertyNode> transform = | 480 RefPtr<TransformPaintPropertyNode> transform = |
485 TransformPaintPropertyNode::create(rootPropertyTreeState().transform(), | 481 TransformPaintPropertyNode::create(rootPropertyTreeState().transform(), |
486 rotateTransform, FloatPoint3D()); | 482 rotateTransform, FloatPoint3D()); |
487 | 483 |
488 RefPtr<ClipPaintPropertyNode> clip = ClipPaintPropertyNode::create( | 484 RefPtr<ClipPaintPropertyNode> clip = ClipPaintPropertyNode::create( |
(...skipping 10 matching lines...) Expand all Loading... |
499 output = rotateTransform.mapRect(output); | 495 output = rotateTransform.mapRect(output); |
500 | 496 |
501 bool hasRadius = false; | 497 bool hasRadius = false; |
502 CHECK_MAPPINGS( | 498 CHECK_MAPPINGS( |
503 input, // Input | 499 input, // Input |
504 output, // Visual rect | 500 output, // Visual rect |
505 rotateTransform.mapRect(input), // Transformed rect (not clipped). | 501 rotateTransform.mapRect(input), // Transformed rect (not clipped). |
506 rotateTransform, // Transform matrix to ancestor space | 502 rotateTransform, // Transform matrix to ancestor space |
507 FloatClipRect(rotateTransform.mapRect( | 503 FloatClipRect(rotateTransform.mapRect( |
508 clip->clipRect().rect())), // Clip rect in ancestor space | 504 clip->clipRect().rect())), // Clip rect in ancestor space |
509 localState, | 505 localState, rootPropertyTreeState(), hasRadius); |
510 rootPropertyTreeState(), hasRadius); | |
511 } | 506 } |
512 | 507 |
513 TEST_F(GeometryMapperTest, ClipAfterTransform) { | 508 TEST_F(GeometryMapperTest, ClipAfterTransform) { |
514 TransformationMatrix rotateTransform; | 509 TransformationMatrix rotateTransform; |
515 rotateTransform.rotate(45); | 510 rotateTransform.rotate(45); |
516 RefPtr<TransformPaintPropertyNode> transform = | 511 RefPtr<TransformPaintPropertyNode> transform = |
517 TransformPaintPropertyNode::create(rootPropertyTreeState().transform(), | 512 TransformPaintPropertyNode::create(rootPropertyTreeState().transform(), |
518 rotateTransform, FloatPoint3D()); | 513 rotateTransform, FloatPoint3D()); |
519 | 514 |
520 RefPtr<ClipPaintPropertyNode> clip = ClipPaintPropertyNode::create( | 515 RefPtr<ClipPaintPropertyNode> clip = ClipPaintPropertyNode::create( |
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
829 FloatRect input(100, 100, 50, 50); | 824 FloatRect input(100, 100, 50, 50); |
830 // Reflection is at (50, 100, 50, 50). | 825 // Reflection is at (50, 100, 50, 50). |
831 FloatRect output(50, 100, 100, 50); | 826 FloatRect output(50, 100, 100, 50); |
832 | 827 |
833 bool hasRadius = false; | 828 bool hasRadius = false; |
834 CHECK_MAPPINGS(input, output, input, TransformationMatrix(), FloatClipRect(), | 829 CHECK_MAPPINGS(input, output, input, TransformationMatrix(), FloatClipRect(), |
835 localState, rootPropertyTreeState(), hasRadius); | 830 localState, rootPropertyTreeState(), hasRadius); |
836 } | 831 } |
837 | 832 |
838 } // namespace blink | 833 } // namespace blink |
OLD | NEW |