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

Side by Side Diff: cc/trees/property_tree_unittest.cc

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

Powered by Google App Engine
This is Rietveld 408576698