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

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

Issue 2385123003: Rewrap comments to 80 columns in Source/platform/graphics/paint/. (Closed)
Patch Set: Resync Created 4 years, 2 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 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 TransformationMatrix translateTransform; 235 TransformationMatrix translateTransform;
236 translateTransform.translate(100, 0); 236 translateTransform.translate(100, 0);
237 RefPtr<TransformPaintPropertyNode> transform2 = 237 RefPtr<TransformPaintPropertyNode> transform2 =
238 TransformPaintPropertyNode::create(transform1, translateTransform, 238 TransformPaintPropertyNode::create(transform1, translateTransform,
239 FloatPoint3D()); 239 FloatPoint3D());
240 240
241 PropertyTreeState localState = rootPropertyTreeState(); 241 PropertyTreeState localState = rootPropertyTreeState();
242 localState.setTransform(transform2.get()); 242 localState.setTransform(transform2.get());
243 243
244 FloatRect input(0, 0, 100, 100); 244 FloatRect input(0, 0, 100, 100);
245 // Note: unlike NestedTransforms, the order of these transforms matters. This tests correct order of matrix multiplication. 245 // Note: unlike NestedTransforms, the order of these transforms matters. This
246 // tests correct order of matrix multiplication.
246 TransformationMatrix final = scaleTransform * translateTransform; 247 TransformationMatrix final = scaleTransform * translateTransform;
247 FloatRect output = final.mapRect(input); 248 FloatRect output = final.mapRect(input);
248 249
249 CHECK_MAPPINGS(input, output, output, final, rootClipNode->clipRect().rect(), 250 CHECK_MAPPINGS(input, output, output, final, rootClipNode->clipRect().rect(),
250 localState, rootPropertyTreeState()); 251 localState, rootPropertyTreeState());
251 252
252 // Check the cached matrix for the intermediate transform. 253 // Check the cached matrix for the intermediate transform.
253 EXPECT_EQ(scaleTransform, 254 EXPECT_EQ(scaleTransform,
254 getPrecomputedDataForAncestor(rootPropertyTreeState()) 255 getPrecomputedDataForAncestor(rootPropertyTreeState())
255 .toAncestorTransforms.get(transform1.get())); 256 .toAncestorTransforms.get(transform1.get()));
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
395 } 396 }
396 397
397 { 398 {
398 PropertyTreeState localState = rootPropertyTreeState(); 399 PropertyTreeState localState = rootPropertyTreeState();
399 localState.setClip(clip2.get()); 400 localState.setClip(clip2.get());
400 localState.setTransform(transform.get()); 401 localState.setTransform(transform.get());
401 402
402 FloatRect mappedClip = rotateTransform.mapRect(clip2->clipRect().rect()); 403 FloatRect mappedClip = rotateTransform.mapRect(clip2->clipRect().rect());
403 mappedClip.intersect(clip1->clipRect().rect()); 404 mappedClip.intersect(clip1->clipRect().rect());
404 405
405 // All clips are performed in the space of the ancestor. In cases such as th is, this means the 406 // All clips are performed in the space of the ancestor. In cases such as
406 // clip is a bit lossy. 407 // this, this means the clip is a bit lossy.
407 FloatRect output(input); 408 FloatRect output(input);
408 // Map to transformed rect in ancestor space. 409 // Map to transformed rect in ancestor space.
409 output = rotateTransform.mapRect(output); 410 output = rotateTransform.mapRect(output);
410 // Intersect with all clips between local and ancestor, independently mapped to ancestor space. 411 // Intersect with all clips between local and ancestor, independently mapped
412 // to ancestor space.
411 output.intersect(mappedClip); 413 output.intersect(mappedClip);
412 414
413 CHECK_MAPPINGS( 415 CHECK_MAPPINGS(
414 input, // Input 416 input, // Input
415 output, // Visual rect 417 output, // Visual rect
416 rotateTransform.mapRect(input), // Transformed rect (not clipped) 418 rotateTransform.mapRect(input), // Transformed rect (not clipped)
417 rotateTransform, // Transform matrix to ancestor space 419 rotateTransform, // Transform matrix to ancestor space
418 mappedClip, // Clip rect in ancestor space 420 mappedClip, // Clip rect in ancestor space
419 localState, rootPropertyTreeState()); 421 localState, rootPropertyTreeState());
420 } 422 }
421 } 423 }
422 424
423 TEST_F(GeometryMapperTest, SiblingTransforms) { 425 TEST_F(GeometryMapperTest, SiblingTransforms) {
424 // These transforms are siblings. Thus mapping from one to the other requires going through the root. 426 // These transforms are siblings. Thus mapping from one to the other requires
427 // going through the root.
425 TransformationMatrix rotateTransform1; 428 TransformationMatrix rotateTransform1;
426 rotateTransform1.rotate(45); 429 rotateTransform1.rotate(45);
427 RefPtr<TransformPaintPropertyNode> transform1 = 430 RefPtr<TransformPaintPropertyNode> transform1 =
428 TransformPaintPropertyNode::create(rootPropertyTreeState().transform(), 431 TransformPaintPropertyNode::create(rootPropertyTreeState().transform(),
429 rotateTransform1, FloatPoint3D()); 432 rotateTransform1, FloatPoint3D());
430 433
431 TransformationMatrix rotateTransform2; 434 TransformationMatrix rotateTransform2;
432 rotateTransform2.rotate(-45); 435 rotateTransform2.rotate(-45);
433 RefPtr<TransformPaintPropertyNode> transform2 = 436 RefPtr<TransformPaintPropertyNode> transform2 =
434 TransformPaintPropertyNode::create(rootPropertyTreeState().transform(), 437 TransformPaintPropertyNode::create(rootPropertyTreeState().transform(),
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
472 EXPECT_TRUE(success); 475 EXPECT_TRUE(success);
473 EXPECT_RECT_EQ(expected, result); 476 EXPECT_RECT_EQ(expected, result);
474 477
475 result = geometryMapper->mapRectToDestinationSpace(input, transform1State, 478 result = geometryMapper->mapRectToDestinationSpace(input, transform1State,
476 transform2State, success); 479 transform2State, success);
477 EXPECT_TRUE(success); 480 EXPECT_TRUE(success);
478 EXPECT_RECT_EQ(expected, result); 481 EXPECT_RECT_EQ(expected, result);
479 } 482 }
480 483
481 TEST_F(GeometryMapperTest, SiblingTransformsWithClip) { 484 TEST_F(GeometryMapperTest, SiblingTransformsWithClip) {
482 // These transforms are siblings. Thus mapping from one to the other requires going through the root. 485 // These transforms are siblings. Thus mapping from one to the other requires
486 // going through the root.
483 TransformationMatrix rotateTransform1; 487 TransformationMatrix rotateTransform1;
484 rotateTransform1.rotate(45); 488 rotateTransform1.rotate(45);
485 RefPtr<TransformPaintPropertyNode> transform1 = 489 RefPtr<TransformPaintPropertyNode> transform1 =
486 TransformPaintPropertyNode::create(rootPropertyTreeState().transform(), 490 TransformPaintPropertyNode::create(rootPropertyTreeState().transform(),
487 rotateTransform1, FloatPoint3D()); 491 rotateTransform1, FloatPoint3D());
488 492
489 TransformationMatrix rotateTransform2; 493 TransformationMatrix rotateTransform2;
490 rotateTransform2.rotate(-45); 494 rotateTransform2.rotate(-45);
491 RefPtr<TransformPaintPropertyNode> transform2 = 495 RefPtr<TransformPaintPropertyNode> transform2 =
492 TransformPaintPropertyNode::create(rootPropertyTreeState().transform(), 496 TransformPaintPropertyNode::create(rootPropertyTreeState().transform(),
493 rotateTransform2, FloatPoint3D()); 497 rotateTransform2, FloatPoint3D());
494 498
495 RefPtr<ClipPaintPropertyNode> clip = ClipPaintPropertyNode::create( 499 RefPtr<ClipPaintPropertyNode> clip = ClipPaintPropertyNode::create(
496 rootPropertyTreeState().clip(), transform2.get(), 500 rootPropertyTreeState().clip(), transform2.get(),
497 FloatRoundedRect(10, 10, 70, 70)); 501 FloatRoundedRect(10, 10, 70, 70));
498 502
499 PropertyTreeState transform1State = rootPropertyTreeState(); 503 PropertyTreeState transform1State = rootPropertyTreeState();
500 transform1State.setTransform(transform1.get()); 504 transform1State.setTransform(transform1.get());
501 PropertyTreeState transform2AndClipState = rootPropertyTreeState(); 505 PropertyTreeState transform2AndClipState = rootPropertyTreeState();
502 transform2AndClipState.setTransform(transform2.get()); 506 transform2AndClipState.setTransform(transform2.get());
503 transform2AndClipState.setClip(clip.get()); 507 transform2AndClipState.setClip(clip.get());
504 508
505 bool success; 509 bool success;
506 FloatRect input(0, 0, 100, 100); 510 FloatRect input(0, 0, 100, 100);
507 511
508 // Test map from transform1State to transform2AndClipState. 512 // Test map from transform1State to transform2AndClipState.
509 FloatRect expected = 513 FloatRect expected =
510 rotateTransform2.inverse().mapRect(rotateTransform1.mapRect(input)); 514 rotateTransform2.inverse().mapRect(rotateTransform1.mapRect(input));
511 515
512 // mapToVisualRectInDestinationSpace ignores clip from the common ancestor to destination. 516 // mapToVisualRectInDestinationSpace ignores clip from the common ancestor to
517 // destination.
513 FloatRect result = geometryMapper->mapToVisualRectInDestinationSpace( 518 FloatRect result = geometryMapper->mapToVisualRectInDestinationSpace(
514 input, transform1State, transform2AndClipState, success); 519 input, transform1State, transform2AndClipState, success);
515 // Fails, because the clip of the destination state is not an ancestor of the clip of the source state. 520 // Fails, because the clip of the destination state is not an ancestor of the
521 // clip of the source state.
516 EXPECT_FALSE(success); 522 EXPECT_FALSE(success);
517 523
518 // mapRectToDestinationSpace ignores clip. 524 // mapRectToDestinationSpace ignores clip.
519 result = geometryMapper->mapRectToDestinationSpace( 525 result = geometryMapper->mapRectToDestinationSpace(
520 input, transform1State, transform2AndClipState, success); 526 input, transform1State, transform2AndClipState, success);
521 EXPECT_TRUE(success); 527 EXPECT_TRUE(success);
522 EXPECT_RECT_EQ(expected, result); 528 EXPECT_RECT_EQ(expected, result);
523 529
524 // Test map from transform2AndClipState to transform1State. 530 // Test map from transform2AndClipState to transform1State.
525 FloatRect expectedUnclipped = 531 FloatRect expectedUnclipped =
526 rotateTransform1.inverse().mapRect(rotateTransform2.mapRect(input)); 532 rotateTransform1.inverse().mapRect(rotateTransform2.mapRect(input));
527 FloatRect expectedClipped = rotateTransform1.inverse().mapRect( 533 FloatRect expectedClipped = rotateTransform1.inverse().mapRect(
528 rotateTransform2.mapRect(FloatRect(10, 10, 70, 70))); 534 rotateTransform2.mapRect(FloatRect(10, 10, 70, 70)));
529 535
530 // mapToVisualRectInDestinationSpace ignores clip from the common ancestor to destination. 536 // mapToVisualRectInDestinationSpace ignores clip from the common ancestor to
537 // destination.
531 result = geometryMapper->mapToVisualRectInDestinationSpace( 538 result = geometryMapper->mapToVisualRectInDestinationSpace(
532 input, transform2AndClipState, transform1State, success); 539 input, transform2AndClipState, transform1State, success);
533 EXPECT_TRUE(success); 540 EXPECT_TRUE(success);
534 EXPECT_RECT_EQ(expectedClipped, result); 541 EXPECT_RECT_EQ(expectedClipped, result);
535 542
536 // mapRectToDestinationSpace ignores clip. 543 // mapRectToDestinationSpace ignores clip.
537 result = geometryMapper->mapRectToDestinationSpace( 544 result = geometryMapper->mapRectToDestinationSpace(
538 input, transform2AndClipState, transform1State, success); 545 input, transform2AndClipState, transform1State, success);
539 EXPECT_TRUE(success); 546 EXPECT_TRUE(success);
540 EXPECT_RECT_EQ(expectedUnclipped, result); 547 EXPECT_RECT_EQ(expectedUnclipped, result);
(...skipping 29 matching lines...) Expand all
570 EXPECT_EQ(rootPropertyTreeState().transform(), 577 EXPECT_EQ(rootPropertyTreeState().transform(),
571 leastCommonAncestor(childOfChild2.get(), 578 leastCommonAncestor(childOfChild2.get(),
572 rootPropertyTreeState().transform())); 579 rootPropertyTreeState().transform()));
573 EXPECT_EQ(child2, leastCommonAncestor(childOfChild2.get(), child2.get())); 580 EXPECT_EQ(child2, leastCommonAncestor(childOfChild2.get(), child2.get()));
574 581
575 EXPECT_EQ(rootPropertyTreeState().transform(), 582 EXPECT_EQ(rootPropertyTreeState().transform(),
576 leastCommonAncestor(child1.get(), child2.get())); 583 leastCommonAncestor(child1.get(), child2.get()));
577 } 584 }
578 585
579 } // namespace blink 586 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698