| 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 577 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 588 } | 588 } |
| 589 }; | 589 }; |
| 590 | 590 |
| 591 DIRECT_AND_SERIALIZED_PROPERTY_TREE_TEST_F( | 591 DIRECT_AND_SERIALIZED_PROPERTY_TREE_TEST_F( |
| 592 PropertyTreeTestComputeTransformSiblingSingularAncestor); | 592 PropertyTreeTestComputeTransformSiblingSingularAncestor); |
| 593 | 593 |
| 594 class PropertyTreeTestTransformsWithFlattening : public PropertyTreeTest { | 594 class PropertyTreeTestTransformsWithFlattening : public PropertyTreeTest { |
| 595 protected: | 595 protected: |
| 596 void StartTest() override { | 596 void StartTest() override { |
| 597 PropertyTrees property_trees; | 597 PropertyTrees property_trees; |
| 598 property_trees.verify_transform_tree_calculations = true; |
| 598 TransformTree& tree = property_trees.transform_tree; | 599 TransformTree& tree = property_trees.transform_tree; |
| 600 EffectTree& effect_tree = property_trees.effect_tree; |
| 599 | 601 |
| 600 int grand_parent = tree.Insert(TransformNode(), 0); | 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); |
| 601 tree.SetContentTargetId(grand_parent, grand_parent); | 608 tree.SetContentTargetId(grand_parent, grand_parent); |
| 602 tree.SetTargetId(grand_parent, grand_parent); | 609 tree.SetTargetId(grand_parent, grand_parent); |
| 603 tree.Node(grand_parent)->source_node_id = 0; | 610 tree.Node(grand_parent)->source_node_id = 0; |
| 604 | 611 |
| 605 gfx::Transform rotation_about_x; | 612 gfx::Transform rotation_about_x; |
| 606 rotation_about_x.RotateAboutXAxis(15); | 613 rotation_about_x.RotateAboutXAxis(15); |
| 607 | 614 |
| 608 int parent = tree.Insert(TransformNode(), grand_parent); | 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); |
| 609 tree.Node(parent)->needs_surface_contents_scale = true; | 621 tree.Node(parent)->needs_surface_contents_scale = true; |
| 610 tree.SetTargetId(parent, grand_parent); | 622 tree.SetTargetId(parent, grand_parent); |
| 611 tree.SetContentTargetId(parent, parent); | 623 tree.SetContentTargetId(parent, parent); |
| 612 tree.Node(parent)->source_node_id = grand_parent; | 624 tree.Node(parent)->source_node_id = grand_parent; |
| 613 tree.Node(parent)->local = rotation_about_x; | 625 tree.Node(parent)->local = rotation_about_x; |
| 614 | 626 |
| 615 int child = tree.Insert(TransformNode(), parent); | 627 int child = tree.Insert(TransformNode(), parent); |
| 616 tree.SetTargetId(child, parent); | 628 tree.SetTargetId(child, parent); |
| 617 tree.SetContentTargetId(child, parent); | 629 tree.SetContentTargetId(child, parent); |
| 618 tree.Node(child)->source_node_id = parent; | 630 tree.Node(child)->source_node_id = parent; |
| 619 tree.Node(child)->flattens_inherited_transform = true; | 631 tree.Node(child)->flattens_inherited_transform = true; |
| 620 tree.Node(child)->local = rotation_about_x; | 632 tree.Node(child)->local = rotation_about_x; |
| 621 | 633 |
| 622 int grand_child = tree.Insert(TransformNode(), child); | 634 int grand_child = tree.Insert(TransformNode(), child); |
| 623 tree.SetTargetId(grand_child, parent); | 635 tree.SetTargetId(grand_child, parent); |
| 624 tree.SetContentTargetId(grand_child, parent); | 636 tree.SetContentTargetId(grand_child, parent); |
| 625 tree.Node(grand_child)->source_node_id = child; | 637 tree.Node(grand_child)->source_node_id = child; |
| 626 tree.Node(grand_child)->flattens_inherited_transform = true; | 638 tree.Node(grand_child)->flattens_inherited_transform = true; |
| 627 tree.Node(grand_child)->local = rotation_about_x; | 639 tree.Node(grand_child)->local = rotation_about_x; |
| 628 | 640 |
| 629 tree.set_needs_update(true); | 641 tree.set_needs_update(true); |
| 630 SetupTransformTreeForTest(&tree); | 642 SetupTransformTreeForTest(&tree); |
| 631 draw_property_utils::ComputeTransforms(&tree); | 643 draw_property_utils::ComputeTransforms(&tree); |
| 644 property_trees.ResetCachedData(); |
| 632 | 645 |
| 633 gfx::Transform flattened_rotation_about_x = rotation_about_x; | 646 gfx::Transform flattened_rotation_about_x = rotation_about_x; |
| 634 flattened_rotation_about_x.FlattenTo2d(); | 647 flattened_rotation_about_x.FlattenTo2d(); |
| 635 | 648 |
| 636 EXPECT_TRANSFORMATION_MATRIX_EQ(rotation_about_x, tree.ToTarget(child)); | 649 EXPECT_TRANSFORMATION_MATRIX_EQ(rotation_about_x, |
| 650 tree.ToTarget(child, effect_parent)); |
| 637 | 651 |
| 638 EXPECT_TRANSFORMATION_MATRIX_EQ( | 652 EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 639 flattened_rotation_about_x * rotation_about_x, tree.ToScreen(child)); | 653 flattened_rotation_about_x * rotation_about_x, tree.ToScreen(child)); |
| 640 | 654 |
| 641 EXPECT_TRANSFORMATION_MATRIX_EQ( | 655 EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 642 flattened_rotation_about_x * rotation_about_x, | 656 flattened_rotation_about_x * rotation_about_x, |
| 643 tree.ToTarget(grand_child)); | 657 tree.ToTarget(grand_child, effect_parent)); |
| 644 | 658 |
| 645 EXPECT_TRANSFORMATION_MATRIX_EQ(flattened_rotation_about_x * | 659 EXPECT_TRANSFORMATION_MATRIX_EQ(flattened_rotation_about_x * |
| 646 flattened_rotation_about_x * | 660 flattened_rotation_about_x * |
| 647 rotation_about_x, | 661 rotation_about_x, |
| 648 tree.ToScreen(grand_child)); | 662 tree.ToScreen(grand_child)); |
| 649 | 663 |
| 650 gfx::Transform grand_child_to_child; | 664 gfx::Transform grand_child_to_child; |
| 651 bool success = | 665 bool success = |
| 652 tree.ComputeTransform(grand_child, child, &grand_child_to_child); | 666 tree.ComputeTransform(grand_child, child, &grand_child_to_child); |
| 653 EXPECT_TRUE(success); | 667 EXPECT_TRUE(success); |
| 654 EXPECT_TRANSFORMATION_MATRIX_EQ(rotation_about_x, grand_child_to_child); | 668 EXPECT_TRANSFORMATION_MATRIX_EQ(rotation_about_x, grand_child_to_child); |
| 655 | 669 |
| 656 // Remove flattening at grand_child, and recompute transforms. | 670 // Remove flattening at grand_child, and recompute transforms. |
| 657 tree.Node(grand_child)->flattens_inherited_transform = false; | 671 tree.Node(grand_child)->flattens_inherited_transform = false; |
| 658 tree.set_needs_update(true); | 672 tree.set_needs_update(true); |
| 659 SetupTransformTreeForTest(&tree); | 673 SetupTransformTreeForTest(&tree); |
| 660 draw_property_utils::ComputeTransforms(&tree); | 674 draw_property_utils::ComputeTransforms(&tree); |
| 661 | 675 |
| 662 EXPECT_TRANSFORMATION_MATRIX_EQ(rotation_about_x * rotation_about_x, | 676 EXPECT_TRANSFORMATION_MATRIX_EQ(rotation_about_x * rotation_about_x, |
| 663 tree.ToTarget(grand_child)); | 677 tree.ToTarget(grand_child, effect_parent)); |
| 664 | 678 |
| 665 EXPECT_TRANSFORMATION_MATRIX_EQ( | 679 EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 666 flattened_rotation_about_x * rotation_about_x * rotation_about_x, | 680 flattened_rotation_about_x * rotation_about_x * rotation_about_x, |
| 667 tree.ToScreen(grand_child)); | 681 tree.ToScreen(grand_child)); |
| 668 | 682 |
| 669 success = tree.ComputeTransform(grand_child, child, &grand_child_to_child); | 683 success = tree.ComputeTransform(grand_child, child, &grand_child_to_child); |
| 670 EXPECT_TRUE(success); | 684 EXPECT_TRUE(success); |
| 671 EXPECT_TRANSFORMATION_MATRIX_EQ(rotation_about_x, grand_child_to_child); | 685 EXPECT_TRANSFORMATION_MATRIX_EQ(rotation_about_x, grand_child_to_child); |
| 672 } | 686 } |
| 673 }; | 687 }; |
| (...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1094 | 1108 |
| 1095 DIRECT_AND_SERIALIZED_PROPERTY_TREE_TEST_F( | 1109 DIRECT_AND_SERIALIZED_PROPERTY_TREE_TEST_F( |
| 1096 PropertyTreeTestNonIntegerTranslationTest); | 1110 PropertyTreeTestNonIntegerTranslationTest); |
| 1097 | 1111 |
| 1098 class PropertyTreeTestSingularTransformSnapTest : public PropertyTreeTest { | 1112 class PropertyTreeTestSingularTransformSnapTest : public PropertyTreeTest { |
| 1099 protected: | 1113 protected: |
| 1100 void StartTest() override { | 1114 void StartTest() override { |
| 1101 // This tests that to_target transform is not snapped when it has a singular | 1115 // This tests that to_target transform is not snapped when it has a singular |
| 1102 // transform. | 1116 // transform. |
| 1103 PropertyTrees property_trees; | 1117 PropertyTrees property_trees; |
| 1118 property_trees.verify_transform_tree_calculations = true; |
| 1104 TransformTree& tree = property_trees.transform_tree; | 1119 TransformTree& tree = property_trees.transform_tree; |
| 1120 EffectTree& effect_tree = property_trees.effect_tree; |
| 1105 | 1121 |
| 1106 int parent = tree.Insert(TransformNode(), 0); | 1122 int parent = tree.Insert(TransformNode(), 0); |
| 1123 int effect_parent = effect_tree.Insert(EffectNode(), 0); |
| 1124 effect_tree.Node(effect_parent)->has_render_surface = true; |
| 1107 tree.SetTargetId(parent, parent); | 1125 tree.SetTargetId(parent, parent); |
| 1108 tree.Node(parent)->scrolls = true; | 1126 tree.Node(parent)->scrolls = true; |
| 1109 | 1127 |
| 1110 int child = tree.Insert(TransformNode(), parent); | 1128 int child = tree.Insert(TransformNode(), parent); |
| 1111 TransformNode* child_node = tree.Node(child); | 1129 TransformNode* child_node = tree.Node(child); |
| 1112 tree.SetTargetId(child, parent); | 1130 tree.SetTargetId(child, parent); |
| 1113 child_node->scrolls = true; | 1131 child_node->scrolls = true; |
| 1114 child_node->local.Scale3d(6.0f, 6.0f, 0.0f); | 1132 child_node->local.Scale3d(6.0f, 6.0f, 0.0f); |
| 1115 child_node->local.Translate(1.3f, 1.3f); | 1133 child_node->local.Translate(1.3f, 1.3f); |
| 1116 tree.set_needs_update(true); | 1134 tree.set_needs_update(true); |
| 1117 | 1135 |
| 1118 SetupTransformTreeForTest(&tree); | 1136 SetupTransformTreeForTest(&tree); |
| 1119 draw_property_utils::ComputeTransforms(&tree); | 1137 draw_property_utils::ComputeTransforms(&tree); |
| 1138 property_trees.ResetCachedData(); |
| 1120 | 1139 |
| 1121 gfx::Transform from_target; | 1140 gfx::Transform from_target; |
| 1122 EXPECT_FALSE(tree.ToTarget(child).GetInverse(&from_target)); | 1141 EXPECT_FALSE(tree.ToTarget(child, effect_parent).GetInverse(&from_target)); |
| 1123 // The following checks are to ensure that snapping is skipped because of | 1142 // The following checks are to ensure that snapping is skipped because of |
| 1124 // singular transform (and not because of other reasons which also cause | 1143 // singular transform (and not because of other reasons which also cause |
| 1125 // snapping to be skipped). | 1144 // snapping to be skipped). |
| 1126 EXPECT_TRUE(child_node->scrolls); | 1145 EXPECT_TRUE(child_node->scrolls); |
| 1127 EXPECT_TRUE(tree.ToTarget(child).IsScaleOrTranslation()); | 1146 EXPECT_TRUE(tree.ToTarget(child, effect_parent).IsScaleOrTranslation()); |
| 1128 EXPECT_FALSE(child_node->to_screen_is_potentially_animated); | 1147 EXPECT_FALSE(child_node->to_screen_is_potentially_animated); |
| 1129 EXPECT_FALSE(child_node->ancestors_are_invertible); | 1148 EXPECT_FALSE(child_node->ancestors_are_invertible); |
| 1130 | 1149 |
| 1131 gfx::Transform rounded = tree.ToTarget(child); | 1150 gfx::Transform rounded = tree.ToTarget(child, effect_parent); |
| 1132 rounded.RoundTranslationComponents(); | 1151 rounded.RoundTranslationComponents(); |
| 1133 EXPECT_NE(tree.ToTarget(child), rounded); | 1152 EXPECT_NE(tree.ToTarget(child, effect_parent), rounded); |
| 1134 } | 1153 } |
| 1135 }; | 1154 }; |
| 1136 | 1155 |
| 1137 DIRECT_AND_SERIALIZED_PROPERTY_TREE_TEST_F( | 1156 DIRECT_AND_SERIALIZED_PROPERTY_TREE_TEST_F( |
| 1138 PropertyTreeTestSingularTransformSnapTest); | 1157 PropertyTreeTestSingularTransformSnapTest); |
| 1139 | 1158 |
| 1140 #undef DIRECT_AND_SERIALIZED_PROPERTY_TREE_TEST_F | 1159 #undef DIRECT_AND_SERIALIZED_PROPERTY_TREE_TEST_F |
| 1141 #undef SERIALIZED_PROPERTY_TREE_TEST_F | 1160 #undef SERIALIZED_PROPERTY_TREE_TEST_F |
| 1142 #undef DIRECT_PROPERTY_TREE_TEST_F | 1161 #undef DIRECT_PROPERTY_TREE_TEST_F |
| 1143 | 1162 |
| 1144 } // namespace | 1163 } // namespace |
| 1145 } // namespace cc | 1164 } // namespace cc |
| OLD | NEW |