| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "cc/trees/property_tree.h" | 5 #include "cc/trees/property_tree.h" |
| 6 | 6 |
| 7 #include "cc/input/main_thread_scrolling_reason.h" | 7 #include "cc/input/main_thread_scrolling_reason.h" |
| 8 #include "cc/proto/property_tree.pb.h" | 8 #include "cc/proto/property_tree.pb.h" |
| 9 #include "cc/test/geometry_test_utils.h" | 9 #include "cc/test/geometry_test_utils.h" |
| 10 #include "cc/trees/clip_node.h" | 10 #include "cc/trees/clip_node.h" |
| (...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 384 #define DIRECT_PROPERTY_TREE_TEST_F(TEST_FIXTURE_NAME) \ | 384 #define DIRECT_PROPERTY_TREE_TEST_F(TEST_FIXTURE_NAME) \ |
| 385 TEST_F(TEST_FIXTURE_NAME, RunDirect) { RunTest(false); } | 385 TEST_F(TEST_FIXTURE_NAME, RunDirect) { RunTest(false); } |
| 386 | 386 |
| 387 #define SERIALIZED_PROPERTY_TREE_TEST_F(TEST_FIXTURE_NAME) \ | 387 #define SERIALIZED_PROPERTY_TREE_TEST_F(TEST_FIXTURE_NAME) \ |
| 388 TEST_F(TEST_FIXTURE_NAME, RunSerialized) { RunTest(true); } | 388 TEST_F(TEST_FIXTURE_NAME, RunSerialized) { RunTest(true); } |
| 389 | 389 |
| 390 #define DIRECT_AND_SERIALIZED_PROPERTY_TREE_TEST_F(TEST_FIXTURE_NAME) \ | 390 #define DIRECT_AND_SERIALIZED_PROPERTY_TREE_TEST_F(TEST_FIXTURE_NAME) \ |
| 391 DIRECT_PROPERTY_TREE_TEST_F(TEST_FIXTURE_NAME); \ | 391 DIRECT_PROPERTY_TREE_TEST_F(TEST_FIXTURE_NAME); \ |
| 392 SERIALIZED_PROPERTY_TREE_TEST_F(TEST_FIXTURE_NAME) | 392 SERIALIZED_PROPERTY_TREE_TEST_F(TEST_FIXTURE_NAME) |
| 393 | 393 |
| 394 class PropertyTreeTestComputeTransformRoot : public PropertyTreeTest { | 394 class PropertyTreeTestGetDrawTransformsTest : public PropertyTreeTest { |
| 395 protected: | 395 protected: |
| 396 void StartTest() override { | 396 void StartTest() override { |
| 397 PropertyTrees property_trees; | 397 // TODO(sunxd): Add GetDrawTransforms tests. |
| 398 TransformTree& tree = property_trees.transform_tree; | |
| 399 TransformNode& root = *tree.Node(0); | |
| 400 root.id = 0; | |
| 401 root.local.Translate(2, 2); | |
| 402 tree.SetTargetId(root.id, 0); | |
| 403 SetupTransformTreeForTest(&tree); | |
| 404 tree.UpdateTransforms(0); | |
| 405 | |
| 406 gfx::Transform expected; | |
| 407 gfx::Transform transform; | |
| 408 bool success = tree.ComputeTransform(0, 0, &transform); | |
| 409 EXPECT_TRUE(success); | |
| 410 EXPECT_TRANSFORMATION_MATRIX_EQ(expected, transform); | |
| 411 | |
| 412 transform.MakeIdentity(); | |
| 413 expected.Translate(2, 2); | |
| 414 success = tree.ComputeTransform(0, -1, &transform); | |
| 415 EXPECT_TRUE(success); | |
| 416 EXPECT_TRANSFORMATION_MATRIX_EQ(expected, transform); | |
| 417 | |
| 418 transform.MakeIdentity(); | |
| 419 expected.MakeIdentity(); | |
| 420 expected.Translate(-2, -2); | |
| 421 success = tree.ComputeTransform(-1, 0, &transform); | |
| 422 EXPECT_TRUE(success); | |
| 423 EXPECT_TRANSFORMATION_MATRIX_EQ(expected, transform); | |
| 424 } | 398 } |
| 425 }; | 399 }; |
| 426 | 400 |
| 427 DIRECT_AND_SERIALIZED_PROPERTY_TREE_TEST_F( | 401 DIRECT_AND_SERIALIZED_PROPERTY_TREE_TEST_F( |
| 428 PropertyTreeTestComputeTransformRoot); | 402 PropertyTreeTestGetDrawTransformsTest); |
| 429 | |
| 430 class PropertyTreeTestComputeTransformChild : public PropertyTreeTest { | |
| 431 protected: | |
| 432 void StartTest() override { | |
| 433 PropertyTrees property_trees; | |
| 434 TransformTree& tree = property_trees.transform_tree; | |
| 435 TransformNode& root = *tree.Node(0); | |
| 436 root.local.Translate(2, 2); | |
| 437 tree.SetTargetId(root.id, 0); | |
| 438 tree.UpdateTransforms(0); | |
| 439 | |
| 440 TransformNode child; | |
| 441 child.local.Translate(3, 3); | |
| 442 child.source_node_id = 0; | |
| 443 child.id = tree.Insert(child, 0); | |
| 444 tree.SetTargetId(child.id, 0); | |
| 445 | |
| 446 SetupTransformTreeForTest(&tree); | |
| 447 tree.UpdateTransforms(1); | |
| 448 | |
| 449 gfx::Transform expected; | |
| 450 gfx::Transform transform; | |
| 451 | |
| 452 expected.Translate(3, 3); | |
| 453 bool success = tree.ComputeTransform(1, 0, &transform); | |
| 454 EXPECT_TRUE(success); | |
| 455 EXPECT_TRANSFORMATION_MATRIX_EQ(expected, transform); | |
| 456 | |
| 457 transform.MakeIdentity(); | |
| 458 expected.MakeIdentity(); | |
| 459 expected.Translate(-3, -3); | |
| 460 success = tree.ComputeTransform(0, 1, &transform); | |
| 461 EXPECT_TRUE(success); | |
| 462 EXPECT_TRANSFORMATION_MATRIX_EQ(expected, transform); | |
| 463 | |
| 464 transform.MakeIdentity(); | |
| 465 expected.MakeIdentity(); | |
| 466 expected.Translate(5, 5); | |
| 467 success = tree.ComputeTransform(1, -1, &transform); | |
| 468 EXPECT_TRUE(success); | |
| 469 EXPECT_TRANSFORMATION_MATRIX_EQ(expected, transform); | |
| 470 | |
| 471 transform.MakeIdentity(); | |
| 472 expected.MakeIdentity(); | |
| 473 expected.Translate(-5, -5); | |
| 474 success = tree.ComputeTransform(-1, 1, &transform); | |
| 475 EXPECT_TRUE(success); | |
| 476 EXPECT_TRANSFORMATION_MATRIX_EQ(expected, transform); | |
| 477 } | |
| 478 }; | |
| 479 | |
| 480 DIRECT_AND_SERIALIZED_PROPERTY_TREE_TEST_F( | |
| 481 PropertyTreeTestComputeTransformChild); | |
| 482 | |
| 483 class PropertyTreeTestComputeTransformSibling : public PropertyTreeTest { | |
| 484 protected: | |
| 485 void StartTest() override { | |
| 486 PropertyTrees property_trees; | |
| 487 TransformTree& tree = property_trees.transform_tree; | |
| 488 TransformNode& root = *tree.Node(0); | |
| 489 root.local.Translate(2, 2); | |
| 490 tree.SetTargetId(root.id, 0); | |
| 491 tree.UpdateTransforms(0); | |
| 492 | |
| 493 TransformNode child; | |
| 494 child.local.Translate(3, 3); | |
| 495 child.source_node_id = 0; | |
| 496 child.id = tree.Insert(child, 0); | |
| 497 tree.SetTargetId(child.id, 0); | |
| 498 | |
| 499 TransformNode sibling; | |
| 500 sibling.local.Translate(7, 7); | |
| 501 sibling.source_node_id = 0; | |
| 502 sibling.id = tree.Insert(sibling, 0); | |
| 503 tree.SetTargetId(sibling.id, 0); | |
| 504 | |
| 505 SetupTransformTreeForTest(&tree); | |
| 506 | |
| 507 tree.UpdateTransforms(1); | |
| 508 tree.UpdateTransforms(2); | |
| 509 | |
| 510 gfx::Transform expected; | |
| 511 gfx::Transform transform; | |
| 512 | |
| 513 expected.Translate(4, 4); | |
| 514 bool success = tree.ComputeTransform(2, 1, &transform); | |
| 515 EXPECT_TRUE(success); | |
| 516 EXPECT_TRANSFORMATION_MATRIX_EQ(expected, transform); | |
| 517 | |
| 518 transform.MakeIdentity(); | |
| 519 expected.MakeIdentity(); | |
| 520 expected.Translate(-4, -4); | |
| 521 success = tree.ComputeTransform(1, 2, &transform); | |
| 522 EXPECT_TRUE(success); | |
| 523 EXPECT_TRANSFORMATION_MATRIX_EQ(expected, transform); | |
| 524 } | |
| 525 }; | |
| 526 | |
| 527 DIRECT_AND_SERIALIZED_PROPERTY_TREE_TEST_F( | |
| 528 PropertyTreeTestComputeTransformSibling); | |
| 529 | |
| 530 class PropertyTreeTestComputeTransformSiblingSingularAncestor | |
| 531 : public PropertyTreeTest { | |
| 532 protected: | |
| 533 void StartTest() override { | |
| 534 // In this test, we have the following tree: | |
| 535 // root | |
| 536 // + singular | |
| 537 // + child | |
| 538 // + sibling | |
| 539 // Since the lowest common ancestor of |child| and |sibling| has a singular | |
| 540 // transform, we cannot use screen space transforms to compute change of | |
| 541 // basis | |
| 542 // transforms between these nodes. | |
| 543 PropertyTrees property_trees; | |
| 544 TransformTree& tree = property_trees.transform_tree; | |
| 545 TransformNode& root = *tree.Node(0); | |
| 546 root.local.Translate(2, 2); | |
| 547 tree.SetTargetId(root.id, 0); | |
| 548 tree.UpdateTransforms(0); | |
| 549 | |
| 550 TransformNode singular; | |
| 551 singular.local.matrix().set(2, 2, 0.0); | |
| 552 singular.source_node_id = 0; | |
| 553 singular.id = tree.Insert(singular, 0); | |
| 554 tree.SetTargetId(singular.id, 0); | |
| 555 | |
| 556 TransformNode child; | |
| 557 child.local.Translate(3, 3); | |
| 558 child.source_node_id = 1; | |
| 559 child.id = tree.Insert(child, 1); | |
| 560 tree.SetTargetId(child.id, 0); | |
| 561 | |
| 562 TransformNode sibling; | |
| 563 sibling.local.Translate(7, 7); | |
| 564 sibling.source_node_id = 1; | |
| 565 sibling.id = tree.Insert(sibling, 1); | |
| 566 tree.SetTargetId(sibling.id, 0); | |
| 567 | |
| 568 SetupTransformTreeForTest(&tree); | |
| 569 | |
| 570 tree.UpdateTransforms(1); | |
| 571 tree.UpdateTransforms(2); | |
| 572 tree.UpdateTransforms(3); | |
| 573 | |
| 574 gfx::Transform expected; | |
| 575 gfx::Transform transform; | |
| 576 | |
| 577 expected.Translate(4, 4); | |
| 578 bool success = tree.ComputeTransform(3, 2, &transform); | |
| 579 EXPECT_TRUE(success); | |
| 580 EXPECT_TRANSFORMATION_MATRIX_EQ(expected, transform); | |
| 581 | |
| 582 transform.MakeIdentity(); | |
| 583 expected.MakeIdentity(); | |
| 584 expected.Translate(-4, -4); | |
| 585 success = tree.ComputeTransform(2, 3, &transform); | |
| 586 EXPECT_TRUE(success); | |
| 587 EXPECT_TRANSFORMATION_MATRIX_EQ(expected, transform); | |
| 588 } | |
| 589 }; | |
| 590 | |
| 591 DIRECT_AND_SERIALIZED_PROPERTY_TREE_TEST_F( | |
| 592 PropertyTreeTestComputeTransformSiblingSingularAncestor); | |
| 593 | |
| 594 class PropertyTreeTestTransformsWithFlattening : public PropertyTreeTest { | |
| 595 protected: | |
| 596 void StartTest() override { | |
| 597 PropertyTrees property_trees; | |
| 598 property_trees.verify_transform_tree_calculations = true; | |
| 599 TransformTree& tree = property_trees.transform_tree; | |
| 600 EffectTree& effect_tree = property_trees.effect_tree; | |
| 601 | |
| 602 int grand_parent = tree.Insert(TransformNode(), 0); | |
| 603 int effect_grand_parent = effect_tree.Insert(EffectNode(), 0); | |
| 604 effect_tree.Node(effect_grand_parent)->has_render_surface = true; | |
| 605 effect_tree.Node(effect_grand_parent)->transform_id = grand_parent; | |
| 606 effect_tree.Node(effect_grand_parent)->surface_contents_scale = | |
| 607 gfx::Vector2dF(1.f, 1.f); | |
| 608 tree.SetContentTargetId(grand_parent, grand_parent); | |
| 609 tree.SetTargetId(grand_parent, grand_parent); | |
| 610 tree.Node(grand_parent)->source_node_id = 0; | |
| 611 | |
| 612 gfx::Transform rotation_about_x; | |
| 613 rotation_about_x.RotateAboutXAxis(15); | |
| 614 | |
| 615 int parent = tree.Insert(TransformNode(), grand_parent); | |
| 616 int effect_parent = effect_tree.Insert(EffectNode(), effect_grand_parent); | |
| 617 effect_tree.Node(effect_parent)->transform_id = parent; | |
| 618 effect_tree.Node(effect_parent)->has_render_surface = true; | |
| 619 effect_tree.Node(effect_parent)->surface_contents_scale = | |
| 620 gfx::Vector2dF(1.f, 1.f); | |
| 621 tree.Node(parent)->needs_surface_contents_scale = true; | |
| 622 tree.SetTargetId(parent, grand_parent); | |
| 623 tree.SetContentTargetId(parent, parent); | |
| 624 tree.Node(parent)->source_node_id = grand_parent; | |
| 625 tree.Node(parent)->local = rotation_about_x; | |
| 626 | |
| 627 int child = tree.Insert(TransformNode(), parent); | |
| 628 tree.SetTargetId(child, parent); | |
| 629 tree.SetContentTargetId(child, parent); | |
| 630 tree.Node(child)->source_node_id = parent; | |
| 631 tree.Node(child)->flattens_inherited_transform = true; | |
| 632 tree.Node(child)->local = rotation_about_x; | |
| 633 | |
| 634 int grand_child = tree.Insert(TransformNode(), child); | |
| 635 tree.SetTargetId(grand_child, parent); | |
| 636 tree.SetContentTargetId(grand_child, parent); | |
| 637 tree.Node(grand_child)->source_node_id = child; | |
| 638 tree.Node(grand_child)->flattens_inherited_transform = true; | |
| 639 tree.Node(grand_child)->local = rotation_about_x; | |
| 640 | |
| 641 tree.set_needs_update(true); | |
| 642 SetupTransformTreeForTest(&tree); | |
| 643 draw_property_utils::ComputeTransforms(&tree); | |
| 644 property_trees.ResetCachedData(); | |
| 645 | |
| 646 gfx::Transform flattened_rotation_about_x = rotation_about_x; | |
| 647 flattened_rotation_about_x.FlattenTo2d(); | |
| 648 | |
| 649 EXPECT_TRANSFORMATION_MATRIX_EQ(rotation_about_x, | |
| 650 tree.ToTarget(child, effect_parent)); | |
| 651 | |
| 652 EXPECT_TRANSFORMATION_MATRIX_EQ( | |
| 653 flattened_rotation_about_x * rotation_about_x, tree.ToScreen(child)); | |
| 654 | |
| 655 EXPECT_TRANSFORMATION_MATRIX_EQ( | |
| 656 flattened_rotation_about_x * rotation_about_x, | |
| 657 tree.ToTarget(grand_child, effect_parent)); | |
| 658 | |
| 659 EXPECT_TRANSFORMATION_MATRIX_EQ(flattened_rotation_about_x * | |
| 660 flattened_rotation_about_x * | |
| 661 rotation_about_x, | |
| 662 tree.ToScreen(grand_child)); | |
| 663 | |
| 664 gfx::Transform grand_child_to_child; | |
| 665 bool success = | |
| 666 tree.ComputeTransform(grand_child, child, &grand_child_to_child); | |
| 667 EXPECT_TRUE(success); | |
| 668 EXPECT_TRANSFORMATION_MATRIX_EQ(rotation_about_x, grand_child_to_child); | |
| 669 | |
| 670 // Remove flattening at grand_child, and recompute transforms. | |
| 671 tree.Node(grand_child)->flattens_inherited_transform = false; | |
| 672 tree.set_needs_update(true); | |
| 673 SetupTransformTreeForTest(&tree); | |
| 674 draw_property_utils::ComputeTransforms(&tree); | |
| 675 | |
| 676 EXPECT_TRANSFORMATION_MATRIX_EQ(rotation_about_x * rotation_about_x, | |
| 677 tree.ToTarget(grand_child, effect_parent)); | |
| 678 | |
| 679 EXPECT_TRANSFORMATION_MATRIX_EQ( | |
| 680 flattened_rotation_about_x * rotation_about_x * rotation_about_x, | |
| 681 tree.ToScreen(grand_child)); | |
| 682 | |
| 683 success = tree.ComputeTransform(grand_child, child, &grand_child_to_child); | |
| 684 EXPECT_TRUE(success); | |
| 685 EXPECT_TRANSFORMATION_MATRIX_EQ(rotation_about_x, grand_child_to_child); | |
| 686 } | |
| 687 }; | |
| 688 | |
| 689 DIRECT_AND_SERIALIZED_PROPERTY_TREE_TEST_F( | |
| 690 PropertyTreeTestTransformsWithFlattening); | |
| 691 | |
| 692 class PropertyTreeTestMultiplicationOrder : public PropertyTreeTest { | |
| 693 protected: | |
| 694 void StartTest() override { | |
| 695 PropertyTrees property_trees; | |
| 696 TransformTree& tree = property_trees.transform_tree; | |
| 697 TransformNode& root = *tree.Node(0); | |
| 698 root.local.Translate(2, 2); | |
| 699 tree.SetTargetId(root.id, 0); | |
| 700 tree.UpdateTransforms(0); | |
| 701 | |
| 702 TransformNode child; | |
| 703 child.local.Scale(2, 2); | |
| 704 child.source_node_id = 0; | |
| 705 child.id = tree.Insert(child, 0); | |
| 706 tree.SetTargetId(child.id, 0); | |
| 707 | |
| 708 SetupTransformTreeForTest(&tree); | |
| 709 tree.UpdateTransforms(1); | |
| 710 | |
| 711 gfx::Transform expected; | |
| 712 expected.Translate(2, 2); | |
| 713 expected.Scale(2, 2); | |
| 714 | |
| 715 gfx::Transform transform; | |
| 716 gfx::Transform inverse; | |
| 717 | |
| 718 bool success = tree.ComputeTransform(1, -1, &transform); | |
| 719 EXPECT_TRUE(success); | |
| 720 EXPECT_TRANSFORMATION_MATRIX_EQ(expected, transform); | |
| 721 | |
| 722 success = tree.ComputeTransform(-1, 1, &inverse); | |
| 723 EXPECT_TRUE(success); | |
| 724 | |
| 725 transform = transform * inverse; | |
| 726 expected.MakeIdentity(); | |
| 727 EXPECT_TRANSFORMATION_MATRIX_EQ(expected, transform); | |
| 728 } | |
| 729 }; | |
| 730 | |
| 731 DIRECT_AND_SERIALIZED_PROPERTY_TREE_TEST_F(PropertyTreeTestMultiplicationOrder); | |
| 732 | |
| 733 class PropertyTreeTestComputeTransformWithUninvertibleTransform | |
| 734 : public PropertyTreeTest { | |
| 735 protected: | |
| 736 void StartTest() override { | |
| 737 PropertyTrees property_trees; | |
| 738 TransformTree& tree = property_trees.transform_tree; | |
| 739 TransformNode& root = *tree.Node(0); | |
| 740 tree.SetTargetId(root.id, 0); | |
| 741 tree.UpdateTransforms(0); | |
| 742 | |
| 743 TransformNode child; | |
| 744 child.local.Scale(0, 0); | |
| 745 child.source_node_id = 0; | |
| 746 child.id = tree.Insert(child, 0); | |
| 747 tree.SetTargetId(child.id, 0); | |
| 748 | |
| 749 SetupTransformTreeForTest(&tree); | |
| 750 tree.UpdateTransforms(1); | |
| 751 | |
| 752 gfx::Transform expected; | |
| 753 expected.Scale(0, 0); | |
| 754 | |
| 755 gfx::Transform transform; | |
| 756 gfx::Transform inverse; | |
| 757 | |
| 758 bool success = tree.ComputeTransform(1, 0, &transform); | |
| 759 EXPECT_TRUE(success); | |
| 760 EXPECT_TRANSFORMATION_MATRIX_EQ(expected, transform); | |
| 761 | |
| 762 // To compute this would require inverting the 0 matrix, so we cannot | |
| 763 // succeed. | |
| 764 success = tree.ComputeTransform(0, 1, &inverse); | |
| 765 EXPECT_FALSE(success); | |
| 766 } | |
| 767 }; | |
| 768 | |
| 769 DIRECT_AND_SERIALIZED_PROPERTY_TREE_TEST_F( | |
| 770 PropertyTreeTestComputeTransformWithUninvertibleTransform); | |
| 771 | |
| 772 class PropertyTreeTestComputeTransformWithSurfaceContentsScale | |
| 773 : public PropertyTreeTest { | |
| 774 protected: | |
| 775 void StartTest() override { | |
| 776 PropertyTrees property_trees; | |
| 777 TransformTree& tree = property_trees.transform_tree; | |
| 778 TransformNode& root = *tree.Node(0); | |
| 779 root.id = 0; | |
| 780 tree.SetTargetId(root.id, 0); | |
| 781 tree.UpdateTransforms(0); | |
| 782 | |
| 783 TransformNode grand_parent; | |
| 784 grand_parent.local.Scale(2.f, 2.f); | |
| 785 grand_parent.source_node_id = 0; | |
| 786 grand_parent.needs_surface_contents_scale = true; | |
| 787 int grand_parent_id = tree.Insert(grand_parent, 0); | |
| 788 tree.SetTargetId(grand_parent_id, 0); | |
| 789 tree.UpdateTransforms(grand_parent_id); | |
| 790 | |
| 791 TransformNode parent; | |
| 792 parent.local.Translate(15.f, 15.f); | |
| 793 parent.source_node_id = grand_parent_id; | |
| 794 int parent_id = tree.Insert(parent, grand_parent_id); | |
| 795 tree.SetTargetId(parent_id, grand_parent_id); | |
| 796 tree.UpdateTransforms(parent_id); | |
| 797 | |
| 798 TransformNode child; | |
| 799 child.local.Scale(3.f, 3.f); | |
| 800 child.source_node_id = parent_id; | |
| 801 int child_id = tree.Insert(child, parent_id); | |
| 802 tree.SetTargetId(child_id, grand_parent_id); | |
| 803 tree.UpdateTransforms(child_id); | |
| 804 | |
| 805 TransformNode grand_child; | |
| 806 grand_child.local.Scale(5.f, 5.f); | |
| 807 grand_child.source_node_id = child_id; | |
| 808 grand_child.needs_surface_contents_scale = true; | |
| 809 int grand_child_id = tree.Insert(grand_child, child_id); | |
| 810 tree.SetTargetId(grand_child_id, grand_parent_id); | |
| 811 SetupTransformTreeForTest(&tree); | |
| 812 tree.UpdateTransforms(grand_child_id); | |
| 813 | |
| 814 EXPECT_EQ(gfx::Vector2dF(2.f, 2.f), | |
| 815 tree.Node(grand_parent_id)->surface_contents_scale); | |
| 816 EXPECT_EQ(gfx::Vector2dF(30.f, 30.f), | |
| 817 tree.Node(grand_child_id)->surface_contents_scale); | |
| 818 | |
| 819 // Compute transform from grand_parent to grand_child. | |
| 820 gfx::Transform expected_transform_without_surface_contents_scale; | |
| 821 expected_transform_without_surface_contents_scale.Scale(1.f / 15.f, | |
| 822 1.f / 15.f); | |
| 823 expected_transform_without_surface_contents_scale.Translate(-15.f, -15.f); | |
| 824 | |
| 825 gfx::Transform expected_transform_with_dest_surface_contents_scale; | |
| 826 expected_transform_with_dest_surface_contents_scale.Scale(30.f, 30.f); | |
| 827 expected_transform_with_dest_surface_contents_scale.Scale(1.f / 15.f, | |
| 828 1.f / 15.f); | |
| 829 expected_transform_with_dest_surface_contents_scale.Translate(-15.f, -15.f); | |
| 830 | |
| 831 gfx::Transform expected_transform_with_source_surface_contents_scale; | |
| 832 expected_transform_with_source_surface_contents_scale.Scale(1.f / 15.f, | |
| 833 1.f / 15.f); | |
| 834 expected_transform_with_source_surface_contents_scale.Translate(-15.f, | |
| 835 -15.f); | |
| 836 expected_transform_with_source_surface_contents_scale.Scale(0.5f, 0.5f); | |
| 837 | |
| 838 gfx::Transform transform; | |
| 839 bool success = | |
| 840 tree.ComputeTransform(grand_parent_id, grand_child_id, &transform); | |
| 841 EXPECT_TRUE(success); | |
| 842 EXPECT_TRANSFORMATION_MATRIX_EQ( | |
| 843 expected_transform_without_surface_contents_scale, transform); | |
| 844 | |
| 845 success = | |
| 846 tree.ComputeTransform(grand_parent_id, grand_child_id, &transform); | |
| 847 const TransformNode* grand_child_node = tree.Node(grand_child_id); | |
| 848 transform.matrix().postScale(grand_child_node->surface_contents_scale.x(), | |
| 849 grand_child_node->surface_contents_scale.y(), | |
| 850 1.f); | |
| 851 EXPECT_TRUE(success); | |
| 852 EXPECT_TRANSFORMATION_MATRIX_EQ( | |
| 853 expected_transform_with_dest_surface_contents_scale, transform); | |
| 854 | |
| 855 success = | |
| 856 tree.ComputeTransform(grand_parent_id, grand_child_id, &transform); | |
| 857 const TransformNode* grand_parent_node = tree.Node(grand_parent_id); | |
| 858 EXPECT_NE(grand_parent_node->surface_contents_scale.x(), 0.f); | |
| 859 EXPECT_NE(grand_parent_node->surface_contents_scale.y(), 0.f); | |
| 860 transform.Scale(1.0 / grand_parent_node->surface_contents_scale.x(), | |
| 861 1.0 / grand_parent_node->surface_contents_scale.y()); | |
| 862 EXPECT_TRUE(success); | |
| 863 EXPECT_TRANSFORMATION_MATRIX_EQ( | |
| 864 expected_transform_with_source_surface_contents_scale, transform); | |
| 865 | |
| 866 // Now compute transform from grand_child to grand_parent. | |
| 867 expected_transform_without_surface_contents_scale.MakeIdentity(); | |
| 868 expected_transform_without_surface_contents_scale.Translate(15.f, 15.f); | |
| 869 expected_transform_without_surface_contents_scale.Scale(15.f, 15.f); | |
| 870 | |
| 871 expected_transform_with_dest_surface_contents_scale.MakeIdentity(); | |
| 872 expected_transform_with_dest_surface_contents_scale.Scale(2.f, 2.f); | |
| 873 expected_transform_with_dest_surface_contents_scale.Translate(15.f, 15.f); | |
| 874 expected_transform_with_dest_surface_contents_scale.Scale(15.f, 15.f); | |
| 875 | |
| 876 expected_transform_with_source_surface_contents_scale.MakeIdentity(); | |
| 877 expected_transform_with_source_surface_contents_scale.Translate(15.f, 15.f); | |
| 878 expected_transform_with_source_surface_contents_scale.Scale(15.f, 15.f); | |
| 879 expected_transform_with_source_surface_contents_scale.Scale(1.f / 30.f, | |
| 880 1.f / 30.f); | |
| 881 | |
| 882 success = | |
| 883 tree.ComputeTransform(grand_child_id, grand_parent_id, &transform); | |
| 884 EXPECT_TRUE(success); | |
| 885 EXPECT_TRANSFORMATION_MATRIX_EQ( | |
| 886 expected_transform_without_surface_contents_scale, transform); | |
| 887 | |
| 888 success = | |
| 889 tree.ComputeTransform(grand_child_id, grand_parent_id, &transform); | |
| 890 transform.matrix().postScale(grand_parent_node->surface_contents_scale.x(), | |
| 891 grand_parent_node->surface_contents_scale.y(), | |
| 892 1.f); | |
| 893 EXPECT_TRUE(success); | |
| 894 EXPECT_TRANSFORMATION_MATRIX_EQ( | |
| 895 expected_transform_with_dest_surface_contents_scale, transform); | |
| 896 | |
| 897 success = | |
| 898 tree.ComputeTransform(grand_child_id, grand_parent_id, &transform); | |
| 899 EXPECT_NE(grand_child_node->surface_contents_scale.x(), 0.f); | |
| 900 EXPECT_NE(grand_child_node->surface_contents_scale.y(), 0.f); | |
| 901 transform.Scale(1.0 / grand_child_node->surface_contents_scale.x(), | |
| 902 1.0 / grand_child_node->surface_contents_scale.y()); | |
| 903 EXPECT_TRUE(success); | |
| 904 EXPECT_TRANSFORMATION_MATRIX_EQ( | |
| 905 expected_transform_with_source_surface_contents_scale, transform); | |
| 906 } | |
| 907 }; | |
| 908 | |
| 909 DIRECT_AND_SERIALIZED_PROPERTY_TREE_TEST_F( | |
| 910 PropertyTreeTestComputeTransformWithSurfaceContentsScale); | |
| 911 | |
| 912 class PropertyTreeTestComputeTransformToTargetWithZeroSurfaceContentsScale | |
| 913 : public PropertyTreeTest { | |
| 914 protected: | |
| 915 void StartTest() override { | |
| 916 PropertyTrees property_trees; | |
| 917 TransformTree& tree = property_trees.transform_tree; | |
| 918 TransformNode& root = *tree.Node(0); | |
| 919 tree.SetTargetId(root.id, 0); | |
| 920 tree.UpdateTransforms(0); | |
| 921 | |
| 922 TransformNode grand_parent; | |
| 923 grand_parent.local.Scale(2.f, 0.f); | |
| 924 grand_parent.source_node_id = 0; | |
| 925 grand_parent.needs_surface_contents_scale = true; | |
| 926 int grand_parent_id = tree.Insert(grand_parent, 0); | |
| 927 tree.SetTargetId(grand_parent_id, 0); | |
| 928 tree.SetContentTargetId(grand_parent_id, grand_parent_id); | |
| 929 tree.UpdateTransforms(grand_parent_id); | |
| 930 | |
| 931 TransformNode parent; | |
| 932 parent.local.Translate(1.f, 1.f); | |
| 933 parent.source_node_id = grand_parent_id; | |
| 934 int parent_id = tree.Insert(parent, grand_parent_id); | |
| 935 tree.SetTargetId(parent_id, grand_parent_id); | |
| 936 tree.SetContentTargetId(parent_id, grand_parent_id); | |
| 937 tree.UpdateTransforms(parent_id); | |
| 938 | |
| 939 TransformNode child; | |
| 940 child.local.Translate(3.f, 4.f); | |
| 941 child.source_node_id = parent_id; | |
| 942 int child_id = tree.Insert(child, parent_id); | |
| 943 tree.SetTargetId(child_id, grand_parent_id); | |
| 944 tree.SetContentTargetId(child_id, grand_parent_id); | |
| 945 SetupTransformTreeForTest(&tree); | |
| 946 tree.UpdateTransforms(child_id); | |
| 947 | |
| 948 gfx::Transform expected_transform; | |
| 949 expected_transform.Translate(4.f, 5.f); | |
| 950 | |
| 951 gfx::Transform transform; | |
| 952 bool success = tree.ComputeTransform(child_id, grand_parent_id, &transform); | |
| 953 EXPECT_TRUE(success); | |
| 954 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform, transform); | |
| 955 | |
| 956 tree.Node(grand_parent_id)->local.MakeIdentity(); | |
| 957 tree.Node(grand_parent_id)->local.Scale(0.f, 2.f); | |
| 958 tree.Node(grand_parent_id)->needs_local_transform_update = true; | |
| 959 tree.set_needs_update(true); | |
| 960 SetupTransformTreeForTest(&tree); | |
| 961 | |
| 962 draw_property_utils::ComputeTransforms(&tree); | |
| 963 | |
| 964 success = tree.ComputeTransform(child_id, grand_parent_id, &transform); | |
| 965 EXPECT_TRUE(success); | |
| 966 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform, transform); | |
| 967 | |
| 968 tree.Node(grand_parent_id)->local.MakeIdentity(); | |
| 969 tree.Node(grand_parent_id)->local.Scale(0.f, 0.f); | |
| 970 tree.Node(grand_parent_id)->needs_local_transform_update = true; | |
| 971 tree.set_needs_update(true); | |
| 972 SetupTransformTreeForTest(&tree); | |
| 973 | |
| 974 draw_property_utils::ComputeTransforms(&tree); | |
| 975 | |
| 976 success = tree.ComputeTransform(child_id, grand_parent_id, &transform); | |
| 977 EXPECT_TRUE(success); | |
| 978 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform, transform); | |
| 979 } | |
| 980 }; | |
| 981 | |
| 982 DIRECT_AND_SERIALIZED_PROPERTY_TREE_TEST_F( | |
| 983 PropertyTreeTestComputeTransformToTargetWithZeroSurfaceContentsScale); | |
| 984 | |
| 985 class PropertyTreeTestFlatteningWhenDestinationHasOnlyFlatAncestors | |
| 986 : public PropertyTreeTest { | |
| 987 protected: | |
| 988 void StartTest() override { | |
| 989 // This tests that flattening is performed correctly when | |
| 990 // destination and its ancestors are flat, but there are 3d transforms | |
| 991 // and flattening between the source and destination. | |
| 992 PropertyTrees property_trees; | |
| 993 TransformTree& tree = property_trees.transform_tree; | |
| 994 | |
| 995 int parent = tree.Insert(TransformNode(), 0); | |
| 996 tree.SetContentTargetId(parent, parent); | |
| 997 tree.SetTargetId(parent, parent); | |
| 998 tree.Node(parent)->source_node_id = 0; | |
| 999 tree.Node(parent)->local.Translate(2, 2); | |
| 1000 | |
| 1001 gfx::Transform rotation_about_x; | |
| 1002 rotation_about_x.RotateAboutXAxis(15); | |
| 1003 | |
| 1004 int child = tree.Insert(TransformNode(), parent); | |
| 1005 tree.SetContentTargetId(child, child); | |
| 1006 tree.SetTargetId(child, child); | |
| 1007 tree.Node(child)->source_node_id = parent; | |
| 1008 tree.Node(child)->local = rotation_about_x; | |
| 1009 | |
| 1010 int grand_child = tree.Insert(TransformNode(), child); | |
| 1011 tree.SetContentTargetId(grand_child, grand_child); | |
| 1012 tree.SetTargetId(grand_child, grand_child); | |
| 1013 tree.Node(grand_child)->source_node_id = child; | |
| 1014 tree.Node(grand_child)->flattens_inherited_transform = true; | |
| 1015 | |
| 1016 tree.set_needs_update(true); | |
| 1017 SetupTransformTreeForTest(&tree); | |
| 1018 draw_property_utils::ComputeTransforms(&tree); | |
| 1019 | |
| 1020 gfx::Transform flattened_rotation_about_x = rotation_about_x; | |
| 1021 flattened_rotation_about_x.FlattenTo2d(); | |
| 1022 | |
| 1023 gfx::Transform grand_child_to_parent; | |
| 1024 bool success = | |
| 1025 tree.ComputeTransform(grand_child, parent, &grand_child_to_parent); | |
| 1026 EXPECT_TRUE(success); | |
| 1027 EXPECT_TRANSFORMATION_MATRIX_EQ(flattened_rotation_about_x, | |
| 1028 grand_child_to_parent); | |
| 1029 } | |
| 1030 }; | |
| 1031 | |
| 1032 DIRECT_AND_SERIALIZED_PROPERTY_TREE_TEST_F( | |
| 1033 PropertyTreeTestFlatteningWhenDestinationHasOnlyFlatAncestors); | |
| 1034 | 403 |
| 1035 class PropertyTreeTestScreenSpaceOpacityUpdateTest : public PropertyTreeTest { | 404 class PropertyTreeTestScreenSpaceOpacityUpdateTest : public PropertyTreeTest { |
| 1036 protected: | 405 protected: |
| 1037 void StartTest() override { | 406 void StartTest() override { |
| 1038 // This tests that screen space opacity is updated for the subtree when | 407 // This tests that screen space opacity is updated for the subtree when |
| 1039 // opacity of a node changes. | 408 // opacity of a node changes. |
| 1040 EffectTree tree; | 409 EffectTree tree; |
| 1041 | 410 |
| 1042 int parent = tree.Insert(EffectNode(), 0); | 411 int parent = tree.Insert(EffectNode(), 0); |
| 1043 int child = tree.Insert(EffectNode(), parent); | 412 int child = tree.Insert(EffectNode(), parent); |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1113 | 482 |
| 1114 DIRECT_AND_SERIALIZED_PROPERTY_TREE_TEST_F( | 483 DIRECT_AND_SERIALIZED_PROPERTY_TREE_TEST_F( |
| 1115 PropertyTreeTestNonIntegerTranslationTest); | 484 PropertyTreeTestNonIntegerTranslationTest); |
| 1116 | 485 |
| 1117 class PropertyTreeTestSingularTransformSnapTest : public PropertyTreeTest { | 486 class PropertyTreeTestSingularTransformSnapTest : public PropertyTreeTest { |
| 1118 protected: | 487 protected: |
| 1119 void StartTest() override { | 488 void StartTest() override { |
| 1120 // This tests that to_target transform is not snapped when it has a singular | 489 // This tests that to_target transform is not snapped when it has a singular |
| 1121 // transform. | 490 // transform. |
| 1122 PropertyTrees property_trees; | 491 PropertyTrees property_trees; |
| 1123 property_trees.verify_transform_tree_calculations = true; | |
| 1124 TransformTree& tree = property_trees.transform_tree; | 492 TransformTree& tree = property_trees.transform_tree; |
| 1125 EffectTree& effect_tree = property_trees.effect_tree; | 493 EffectTree& effect_tree = property_trees.effect_tree; |
| 1126 | 494 |
| 1127 int parent = tree.Insert(TransformNode(), 0); | 495 int parent = tree.Insert(TransformNode(), 0); |
| 1128 int effect_parent = effect_tree.Insert(EffectNode(), 0); | 496 int effect_parent = effect_tree.Insert(EffectNode(), 0); |
| 1129 effect_tree.Node(effect_parent)->has_render_surface = true; | 497 effect_tree.Node(effect_parent)->has_render_surface = true; |
| 1130 tree.SetTargetId(parent, parent); | 498 tree.SetTargetId(parent, parent); |
| 1131 tree.Node(parent)->scrolls = true; | 499 tree.Node(parent)->scrolls = true; |
| 1132 tree.Node(parent)->source_node_id = 0; | 500 tree.Node(parent)->source_node_id = 0; |
| 1133 | 501 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 1162 | 530 |
| 1163 DIRECT_AND_SERIALIZED_PROPERTY_TREE_TEST_F( | 531 DIRECT_AND_SERIALIZED_PROPERTY_TREE_TEST_F( |
| 1164 PropertyTreeTestSingularTransformSnapTest); | 532 PropertyTreeTestSingularTransformSnapTest); |
| 1165 | 533 |
| 1166 #undef DIRECT_AND_SERIALIZED_PROPERTY_TREE_TEST_F | 534 #undef DIRECT_AND_SERIALIZED_PROPERTY_TREE_TEST_F |
| 1167 #undef SERIALIZED_PROPERTY_TREE_TEST_F | 535 #undef SERIALIZED_PROPERTY_TREE_TEST_F |
| 1168 #undef DIRECT_PROPERTY_TREE_TEST_F | 536 #undef DIRECT_PROPERTY_TREE_TEST_F |
| 1169 | 537 |
| 1170 } // namespace | 538 } // namespace |
| 1171 } // namespace cc | 539 } // namespace cc |
| OLD | NEW |