| 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/draw_property_utils.h" | 10 #include "cc/trees/draw_property_utils.h" |
| (...skipping 617 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 628 DIRECT_AND_SERIALIZED_PROPERTY_TREE_TEST_F( | 628 DIRECT_AND_SERIALIZED_PROPERTY_TREE_TEST_F( |
| 629 PropertyTreeTestComputeTransformSiblingSingularAncestor); | 629 PropertyTreeTestComputeTransformSiblingSingularAncestor); |
| 630 | 630 |
| 631 class PropertyTreeTestTransformsWithFlattening : public PropertyTreeTest { | 631 class PropertyTreeTestTransformsWithFlattening : public PropertyTreeTest { |
| 632 protected: | 632 protected: |
| 633 void StartTest() override { | 633 void StartTest() override { |
| 634 PropertyTrees property_trees; | 634 PropertyTrees property_trees; |
| 635 TransformTree& tree = property_trees.transform_tree; | 635 TransformTree& tree = property_trees.transform_tree; |
| 636 | 636 |
| 637 int grand_parent = tree.Insert(TransformNode(), 0); | 637 int grand_parent = tree.Insert(TransformNode(), 0); |
| 638 tree.Node(grand_parent)->data.content_target_id = grand_parent; | 638 tree.SetContentTargetId(grand_parent, grand_parent); |
| 639 tree.Node(grand_parent)->data.target_id = grand_parent; | 639 tree.SetTargetId(grand_parent, grand_parent); |
| 640 tree.Node(grand_parent)->data.source_node_id = 0; | 640 tree.Node(grand_parent)->data.source_node_id = 0; |
| 641 | 641 |
| 642 gfx::Transform rotation_about_x; | 642 gfx::Transform rotation_about_x; |
| 643 rotation_about_x.RotateAboutXAxis(15); | 643 rotation_about_x.RotateAboutXAxis(15); |
| 644 | 644 |
| 645 int parent = tree.Insert(TransformNode(), grand_parent); | 645 int parent = tree.Insert(TransformNode(), grand_parent); |
| 646 tree.Node(parent)->data.needs_sublayer_scale = true; | 646 tree.Node(parent)->data.needs_sublayer_scale = true; |
| 647 tree.Node(parent)->data.target_id = grand_parent; | 647 tree.SetTargetId(parent, grand_parent); |
| 648 tree.Node(parent)->data.content_target_id = parent; | 648 tree.SetContentTargetId(parent, parent); |
| 649 tree.Node(parent)->data.source_node_id = grand_parent; | 649 tree.Node(parent)->data.source_node_id = grand_parent; |
| 650 tree.Node(parent)->data.local = rotation_about_x; | 650 tree.Node(parent)->data.local = rotation_about_x; |
| 651 | 651 |
| 652 int child = tree.Insert(TransformNode(), parent); | 652 int child = tree.Insert(TransformNode(), parent); |
| 653 tree.Node(child)->data.target_id = parent; | 653 tree.SetTargetId(child, parent); |
| 654 tree.Node(child)->data.content_target_id = parent; | 654 tree.SetContentTargetId(child, parent); |
| 655 tree.Node(child)->data.source_node_id = parent; | 655 tree.Node(child)->data.source_node_id = parent; |
| 656 tree.Node(child)->data.flattens_inherited_transform = true; | 656 tree.Node(child)->data.flattens_inherited_transform = true; |
| 657 tree.Node(child)->data.local = rotation_about_x; | 657 tree.Node(child)->data.local = rotation_about_x; |
| 658 | 658 |
| 659 int grand_child = tree.Insert(TransformNode(), child); | 659 int grand_child = tree.Insert(TransformNode(), child); |
| 660 tree.Node(grand_child)->data.target_id = parent; | 660 tree.SetTargetId(grand_child, parent); |
| 661 tree.Node(grand_child)->data.content_target_id = parent; | 661 tree.SetContentTargetId(grand_child, parent); |
| 662 tree.Node(grand_child)->data.source_node_id = child; | 662 tree.Node(grand_child)->data.source_node_id = child; |
| 663 tree.Node(grand_child)->data.flattens_inherited_transform = true; | 663 tree.Node(grand_child)->data.flattens_inherited_transform = true; |
| 664 tree.Node(grand_child)->data.local = rotation_about_x; | 664 tree.Node(grand_child)->data.local = rotation_about_x; |
| 665 | 665 |
| 666 tree.set_needs_update(true); | 666 tree.set_needs_update(true); |
| 667 SetupTransformTreeForTest(&tree); | 667 SetupTransformTreeForTest(&tree); |
| 668 draw_property_utils::ComputeTransforms(&tree); | 668 draw_property_utils::ComputeTransforms(&tree); |
| 669 | 669 |
| 670 gfx::Transform flattened_rotation_about_x = rotation_about_x; | 670 gfx::Transform flattened_rotation_about_x = rotation_about_x; |
| 671 flattened_rotation_about_x.FlattenTo2d(); | 671 flattened_rotation_about_x.FlattenTo2d(); |
| 672 | 672 |
| 673 EXPECT_TRANSFORMATION_MATRIX_EQ(rotation_about_x, | 673 EXPECT_TRANSFORMATION_MATRIX_EQ(rotation_about_x, tree.ToTarget(child)); |
| 674 tree.Node(child)->data.to_target); | 674 |
| 675 EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 676 flattened_rotation_about_x * rotation_about_x, tree.ToScreen(child)); |
| 675 | 677 |
| 676 EXPECT_TRANSFORMATION_MATRIX_EQ( | 678 EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 677 flattened_rotation_about_x * rotation_about_x, | 679 flattened_rotation_about_x * rotation_about_x, |
| 678 tree.Node(child)->data.to_screen); | 680 tree.ToTarget(grand_child)); |
| 679 | |
| 680 EXPECT_TRANSFORMATION_MATRIX_EQ( | |
| 681 flattened_rotation_about_x * rotation_about_x, | |
| 682 tree.Node(grand_child)->data.to_target); | |
| 683 | 681 |
| 684 EXPECT_TRANSFORMATION_MATRIX_EQ(flattened_rotation_about_x * | 682 EXPECT_TRANSFORMATION_MATRIX_EQ(flattened_rotation_about_x * |
| 685 flattened_rotation_about_x * | 683 flattened_rotation_about_x * |
| 686 rotation_about_x, | 684 rotation_about_x, |
| 687 tree.Node(grand_child)->data.to_screen); | 685 tree.ToScreen(grand_child)); |
| 688 | 686 |
| 689 gfx::Transform grand_child_to_child; | 687 gfx::Transform grand_child_to_child; |
| 690 bool success = | 688 bool success = |
| 691 tree.ComputeTransform(grand_child, child, &grand_child_to_child); | 689 tree.ComputeTransform(grand_child, child, &grand_child_to_child); |
| 692 EXPECT_TRUE(success); | 690 EXPECT_TRUE(success); |
| 693 EXPECT_TRANSFORMATION_MATRIX_EQ(rotation_about_x, grand_child_to_child); | 691 EXPECT_TRANSFORMATION_MATRIX_EQ(rotation_about_x, grand_child_to_child); |
| 694 | 692 |
| 695 // Remove flattening at grand_child, and recompute transforms. | 693 // Remove flattening at grand_child, and recompute transforms. |
| 696 tree.Node(grand_child)->data.flattens_inherited_transform = false; | 694 tree.Node(grand_child)->data.flattens_inherited_transform = false; |
| 697 tree.set_needs_update(true); | 695 tree.set_needs_update(true); |
| 698 SetupTransformTreeForTest(&tree); | 696 SetupTransformTreeForTest(&tree); |
| 699 draw_property_utils::ComputeTransforms(&tree); | 697 draw_property_utils::ComputeTransforms(&tree); |
| 700 | 698 |
| 701 EXPECT_TRANSFORMATION_MATRIX_EQ(rotation_about_x * rotation_about_x, | 699 EXPECT_TRANSFORMATION_MATRIX_EQ(rotation_about_x * rotation_about_x, |
| 702 tree.Node(grand_child)->data.to_target); | 700 tree.ToTarget(grand_child)); |
| 703 | 701 |
| 704 EXPECT_TRANSFORMATION_MATRIX_EQ( | 702 EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 705 flattened_rotation_about_x * rotation_about_x * rotation_about_x, | 703 flattened_rotation_about_x * rotation_about_x * rotation_about_x, |
| 706 tree.Node(grand_child)->data.to_screen); | 704 tree.ToScreen(grand_child)); |
| 707 | 705 |
| 708 success = tree.ComputeTransform(grand_child, child, &grand_child_to_child); | 706 success = tree.ComputeTransform(grand_child, child, &grand_child_to_child); |
| 709 EXPECT_TRUE(success); | 707 EXPECT_TRUE(success); |
| 710 EXPECT_TRANSFORMATION_MATRIX_EQ(rotation_about_x, grand_child_to_child); | 708 EXPECT_TRANSFORMATION_MATRIX_EQ(rotation_about_x, grand_child_to_child); |
| 711 } | 709 } |
| 712 }; | 710 }; |
| 713 | 711 |
| 714 DIRECT_AND_SERIALIZED_PROPERTY_TREE_TEST_F( | 712 DIRECT_AND_SERIALIZED_PROPERTY_TREE_TEST_F( |
| 715 PropertyTreeTestTransformsWithFlattening); | 713 PropertyTreeTestTransformsWithFlattening); |
| 716 | 714 |
| (...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 989 : public PropertyTreeTest { | 987 : public PropertyTreeTest { |
| 990 protected: | 988 protected: |
| 991 void StartTest() override { | 989 void StartTest() override { |
| 992 // This tests that flattening is performed correctly when | 990 // This tests that flattening is performed correctly when |
| 993 // destination and its ancestors are flat, but there are 3d transforms | 991 // destination and its ancestors are flat, but there are 3d transforms |
| 994 // and flattening between the source and destination. | 992 // and flattening between the source and destination. |
| 995 PropertyTrees property_trees; | 993 PropertyTrees property_trees; |
| 996 TransformTree& tree = property_trees.transform_tree; | 994 TransformTree& tree = property_trees.transform_tree; |
| 997 | 995 |
| 998 int parent = tree.Insert(TransformNode(), 0); | 996 int parent = tree.Insert(TransformNode(), 0); |
| 999 tree.Node(parent)->data.content_target_id = parent; | 997 tree.SetContentTargetId(parent, parent); |
| 1000 tree.Node(parent)->data.target_id = parent; | 998 tree.SetTargetId(parent, parent); |
| 1001 tree.Node(parent)->data.source_node_id = 0; | 999 tree.Node(parent)->data.source_node_id = 0; |
| 1002 tree.Node(parent)->data.local.Translate(2, 2); | 1000 tree.Node(parent)->data.local.Translate(2, 2); |
| 1003 | 1001 |
| 1004 gfx::Transform rotation_about_x; | 1002 gfx::Transform rotation_about_x; |
| 1005 rotation_about_x.RotateAboutXAxis(15); | 1003 rotation_about_x.RotateAboutXAxis(15); |
| 1006 | 1004 |
| 1007 int child = tree.Insert(TransformNode(), parent); | 1005 int child = tree.Insert(TransformNode(), parent); |
| 1008 tree.Node(child)->data.content_target_id = child; | 1006 tree.SetContentTargetId(child, child); |
| 1009 tree.Node(child)->data.target_id = child; | 1007 tree.SetTargetId(child, child); |
| 1010 tree.Node(child)->data.source_node_id = parent; | 1008 tree.Node(child)->data.source_node_id = parent; |
| 1011 tree.Node(child)->data.local = rotation_about_x; | 1009 tree.Node(child)->data.local = rotation_about_x; |
| 1012 | 1010 |
| 1013 int grand_child = tree.Insert(TransformNode(), child); | 1011 int grand_child = tree.Insert(TransformNode(), child); |
| 1014 tree.Node(grand_child)->data.content_target_id = grand_child; | 1012 tree.SetContentTargetId(grand_child, grand_child); |
| 1015 tree.Node(grand_child)->data.target_id = grand_child; | 1013 tree.SetTargetId(grand_child, grand_child); |
| 1016 tree.Node(grand_child)->data.source_node_id = child; | 1014 tree.Node(grand_child)->data.source_node_id = child; |
| 1017 tree.Node(grand_child)->data.flattens_inherited_transform = true; | 1015 tree.Node(grand_child)->data.flattens_inherited_transform = true; |
| 1018 | 1016 |
| 1019 tree.set_needs_update(true); | 1017 tree.set_needs_update(true); |
| 1020 SetupTransformTreeForTest(&tree); | 1018 SetupTransformTreeForTest(&tree); |
| 1021 draw_property_utils::ComputeTransforms(&tree); | 1019 draw_property_utils::ComputeTransforms(&tree); |
| 1022 | 1020 |
| 1023 gfx::Transform flattened_rotation_about_x = rotation_about_x; | 1021 gfx::Transform flattened_rotation_about_x = rotation_about_x; |
| 1024 flattened_rotation_about_x.FlattenTo2d(); | 1022 flattened_rotation_about_x.FlattenTo2d(); |
| 1025 | 1023 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1066 | 1064 |
| 1067 class PropertyTreeTestNonIntegerTranslationTest : public PropertyTreeTest { | 1065 class PropertyTreeTestNonIntegerTranslationTest : public PropertyTreeTest { |
| 1068 protected: | 1066 protected: |
| 1069 void StartTest() override { | 1067 void StartTest() override { |
| 1070 // This tests that when a node has non-integer translation, the information | 1068 // This tests that when a node has non-integer translation, the information |
| 1071 // is propagated to the subtree. | 1069 // is propagated to the subtree. |
| 1072 PropertyTrees property_trees; | 1070 PropertyTrees property_trees; |
| 1073 TransformTree& tree = property_trees.transform_tree; | 1071 TransformTree& tree = property_trees.transform_tree; |
| 1074 | 1072 |
| 1075 int parent = tree.Insert(TransformNode(), 0); | 1073 int parent = tree.Insert(TransformNode(), 0); |
| 1076 tree.Node(parent)->data.target_id = parent; | 1074 tree.SetTargetId(parent, parent); |
| 1077 tree.Node(parent)->data.local.Translate(1.5f, 1.5f); | 1075 tree.Node(parent)->data.local.Translate(1.5f, 1.5f); |
| 1078 | 1076 |
| 1079 int child = tree.Insert(TransformNode(), parent); | 1077 int child = tree.Insert(TransformNode(), parent); |
| 1080 tree.Node(child)->data.target_id = parent; | 1078 tree.SetTargetId(child, parent); |
| 1081 tree.Node(child)->data.local.Translate(1, 1); | 1079 tree.Node(child)->data.local.Translate(1, 1); |
| 1082 tree.set_needs_update(true); | 1080 tree.set_needs_update(true); |
| 1083 SetupTransformTreeForTest(&tree); | 1081 SetupTransformTreeForTest(&tree); |
| 1084 draw_property_utils::ComputeTransforms(&tree); | 1082 draw_property_utils::ComputeTransforms(&tree); |
| 1085 EXPECT_FALSE(tree.Node(parent) | 1083 EXPECT_FALSE(tree.Node(parent) |
| 1086 ->data.node_and_ancestors_have_only_integer_translation); | 1084 ->data.node_and_ancestors_have_only_integer_translation); |
| 1087 EXPECT_FALSE(tree.Node(child) | 1085 EXPECT_FALSE(tree.Node(child) |
| 1088 ->data.node_and_ancestors_have_only_integer_translation); | 1086 ->data.node_and_ancestors_have_only_integer_translation); |
| 1089 | 1087 |
| 1090 tree.Node(parent)->data.local.Translate(0.5f, 0.5f); | 1088 tree.Node(parent)->data.local.Translate(0.5f, 0.5f); |
| 1091 tree.Node(child)->data.local.Translate(0.5f, 0.5f); | 1089 tree.Node(child)->data.local.Translate(0.5f, 0.5f); |
| 1092 tree.set_needs_update(true); | 1090 tree.set_needs_update(true); |
| 1093 SetupTransformTreeForTest(&tree); | 1091 SetupTransformTreeForTest(&tree); |
| 1094 draw_property_utils::ComputeTransforms(&tree); | 1092 draw_property_utils::ComputeTransforms(&tree); |
| 1095 EXPECT_TRUE(tree.Node(parent) | 1093 EXPECT_TRUE(tree.Node(parent) |
| 1096 ->data.node_and_ancestors_have_only_integer_translation); | 1094 ->data.node_and_ancestors_have_only_integer_translation); |
| 1097 EXPECT_FALSE(tree.Node(child) | 1095 EXPECT_FALSE(tree.Node(child) |
| 1098 ->data.node_and_ancestors_have_only_integer_translation); | 1096 ->data.node_and_ancestors_have_only_integer_translation); |
| 1099 | 1097 |
| 1100 tree.Node(child)->data.local.Translate(0.5f, 0.5f); | 1098 tree.Node(child)->data.local.Translate(0.5f, 0.5f); |
| 1101 tree.Node(child)->data.target_id = child; | 1099 tree.SetTargetId(child, child); |
| 1102 tree.set_needs_update(true); | 1100 tree.set_needs_update(true); |
| 1103 SetupTransformTreeForTest(&tree); | 1101 SetupTransformTreeForTest(&tree); |
| 1104 draw_property_utils::ComputeTransforms(&tree); | 1102 draw_property_utils::ComputeTransforms(&tree); |
| 1105 EXPECT_TRUE(tree.Node(parent) | 1103 EXPECT_TRUE(tree.Node(parent) |
| 1106 ->data.node_and_ancestors_have_only_integer_translation); | 1104 ->data.node_and_ancestors_have_only_integer_translation); |
| 1107 EXPECT_TRUE(tree.Node(child) | 1105 EXPECT_TRUE(tree.Node(child) |
| 1108 ->data.node_and_ancestors_have_only_integer_translation); | 1106 ->data.node_and_ancestors_have_only_integer_translation); |
| 1109 } | 1107 } |
| 1110 }; | 1108 }; |
| 1111 | 1109 |
| 1112 DIRECT_AND_SERIALIZED_PROPERTY_TREE_TEST_F( | 1110 DIRECT_AND_SERIALIZED_PROPERTY_TREE_TEST_F( |
| 1113 PropertyTreeTestNonIntegerTranslationTest); | 1111 PropertyTreeTestNonIntegerTranslationTest); |
| 1114 | 1112 |
| 1115 class PropertyTreeTestSingularTransformSnapTest : public PropertyTreeTest { | 1113 class PropertyTreeTestSingularTransformSnapTest : public PropertyTreeTest { |
| 1116 protected: | 1114 protected: |
| 1117 void StartTest() override { | 1115 void StartTest() override { |
| 1118 // This tests that to_target transform is not snapped when it has a singular | 1116 // This tests that to_target transform is not snapped when it has a singular |
| 1119 // transform. | 1117 // transform. |
| 1120 PropertyTrees property_trees; | 1118 PropertyTrees property_trees; |
| 1121 TransformTree& tree = property_trees.transform_tree; | 1119 TransformTree& tree = property_trees.transform_tree; |
| 1122 | 1120 |
| 1123 int parent = tree.Insert(TransformNode(), 0); | 1121 int parent = tree.Insert(TransformNode(), 0); |
| 1124 tree.Node(parent)->data.target_id = parent; | 1122 tree.SetTargetId(parent, parent); |
| 1125 tree.Node(parent)->data.scrolls = true; | 1123 tree.Node(parent)->data.scrolls = true; |
| 1126 | 1124 |
| 1127 int child = tree.Insert(TransformNode(), parent); | 1125 int child = tree.Insert(TransformNode(), parent); |
| 1128 TransformNode* child_node = tree.Node(child); | 1126 TransformNode* child_node = tree.Node(child); |
| 1129 child_node->data.target_id = parent; | 1127 tree.SetTargetId(child, parent); |
| 1130 child_node->data.scrolls = true; | 1128 child_node->data.scrolls = true; |
| 1131 child_node->data.local.Scale3d(6.0f, 6.0f, 0.0f); | 1129 child_node->data.local.Scale3d(6.0f, 6.0f, 0.0f); |
| 1132 child_node->data.local.Translate(1.3f, 1.3f); | 1130 child_node->data.local.Translate(1.3f, 1.3f); |
| 1133 tree.set_needs_update(true); | 1131 tree.set_needs_update(true); |
| 1134 | 1132 |
| 1135 SetupTransformTreeForTest(&tree); | 1133 SetupTransformTreeForTest(&tree); |
| 1136 draw_property_utils::ComputeTransforms(&tree); | 1134 draw_property_utils::ComputeTransforms(&tree); |
| 1137 | 1135 |
| 1138 gfx::Transform from_target; | 1136 gfx::Transform from_target; |
| 1139 EXPECT_FALSE(child_node->data.to_target.GetInverse(&from_target)); | 1137 EXPECT_FALSE(tree.ToTarget(child).GetInverse(&from_target)); |
| 1140 // The following checks are to ensure that snapping is skipped because of | 1138 // The following checks are to ensure that snapping is skipped because of |
| 1141 // singular transform (and not because of other reasons which also cause | 1139 // singular transform (and not because of other reasons which also cause |
| 1142 // snapping to be skipped). | 1140 // snapping to be skipped). |
| 1143 EXPECT_TRUE(child_node->data.scrolls); | 1141 EXPECT_TRUE(child_node->data.scrolls); |
| 1144 EXPECT_TRUE(child_node->data.to_target.IsScaleOrTranslation()); | 1142 EXPECT_TRUE(tree.ToTarget(child).IsScaleOrTranslation()); |
| 1145 EXPECT_FALSE(child_node->data.to_screen_is_potentially_animated); | 1143 EXPECT_FALSE(child_node->data.to_screen_is_potentially_animated); |
| 1146 EXPECT_FALSE(child_node->data.ancestors_are_invertible); | 1144 EXPECT_FALSE(child_node->data.ancestors_are_invertible); |
| 1147 | 1145 |
| 1148 gfx::Transform rounded = child_node->data.to_target; | 1146 gfx::Transform rounded = tree.ToTarget(child); |
| 1149 rounded.RoundTranslationComponents(); | 1147 rounded.RoundTranslationComponents(); |
| 1150 EXPECT_NE(child_node->data.to_target, rounded); | 1148 EXPECT_NE(tree.ToTarget(child), rounded); |
| 1151 } | 1149 } |
| 1152 }; | 1150 }; |
| 1153 | 1151 |
| 1154 DIRECT_AND_SERIALIZED_PROPERTY_TREE_TEST_F( | 1152 DIRECT_AND_SERIALIZED_PROPERTY_TREE_TEST_F( |
| 1155 PropertyTreeTestSingularTransformSnapTest); | 1153 PropertyTreeTestSingularTransformSnapTest); |
| 1156 | 1154 |
| 1157 #undef DIRECT_AND_SERIALIZED_PROPERTY_TREE_TEST_F | 1155 #undef DIRECT_AND_SERIALIZED_PROPERTY_TREE_TEST_F |
| 1158 #undef SERIALIZED_PROPERTY_TREE_TEST_F | 1156 #undef SERIALIZED_PROPERTY_TREE_TEST_F |
| 1159 #undef DIRECT_PROPERTY_TREE_TEST_F | 1157 #undef DIRECT_PROPERTY_TREE_TEST_F |
| 1160 | 1158 |
| 1161 } // namespace | 1159 } // namespace |
| 1162 } // namespace cc | 1160 } // namespace cc |
| OLD | NEW |