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

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

Powered by Google App Engine
This is Rietveld 408576698