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

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

Issue 1070133002: Only allow change-of-basis between transform nodes on the same ancestor chain (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 2nd DCHECK added Created 5 years, 8 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
« no previous file with comments | « cc/trees/property_tree.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/test/geometry_test_utils.h" 7 #include "cc/test/geometry_test_utils.h"
8 #include "cc/trees/draw_property_utils.h" 8 #include "cc/trees/draw_property_utils.h"
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 10
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 EXPECT_TRANSFORMATION_MATRIX_EQ(expected, transform); 74 EXPECT_TRANSFORMATION_MATRIX_EQ(expected, transform);
75 75
76 transform.MakeIdentity(); 76 transform.MakeIdentity();
77 expected.MakeIdentity(); 77 expected.MakeIdentity();
78 expected.Translate(-5, -5); 78 expected.Translate(-5, -5);
79 success = tree.ComputeTransform(-1, 1, &transform); 79 success = tree.ComputeTransform(-1, 1, &transform);
80 EXPECT_TRUE(success); 80 EXPECT_TRUE(success);
81 EXPECT_TRANSFORMATION_MATRIX_EQ(expected, transform); 81 EXPECT_TRANSFORMATION_MATRIX_EQ(expected, transform);
82 } 82 }
83 83
84 TEST(PropertyTreeTest, ComputeTransformSibling) {
85 TransformTree tree;
86 TransformNode& root = *tree.Node(0);
87 root.data.local.Translate(2, 2);
88 root.data.target_id = 0;
89 tree.UpdateTransforms(0);
90
91 TransformNode child;
92 child.data.local.Translate(3, 3);
93 child.data.target_id = 0;
94
95 TransformNode sibling;
96 sibling.data.local.Translate(7, 7);
97 sibling.data.target_id = 0;
98
99 tree.Insert(child, 0);
100 tree.Insert(sibling, 0);
101
102 tree.UpdateTransforms(1);
103 tree.UpdateTransforms(2);
104
105 gfx::Transform expected;
106 gfx::Transform transform;
107
108 expected.Translate(4, 4);
109 bool success = tree.ComputeTransform(2, 1, &transform);
110 EXPECT_TRUE(success);
111 EXPECT_TRANSFORMATION_MATRIX_EQ(expected, transform);
112
113 transform.MakeIdentity();
114 expected.MakeIdentity();
115 expected.Translate(-4, -4);
116 success = tree.ComputeTransform(1, 2, &transform);
117 EXPECT_TRUE(success);
118 EXPECT_TRANSFORMATION_MATRIX_EQ(expected, transform);
119 }
120
121 TEST(PropertyTreeTest, ComputeTransformSiblingSingularAncestor) {
122 // In this test, we have the following tree:
123 // root
124 // + singular
125 // + child
126 // + sibling
127 // Now singular has a singular transform, so we cannot use screen space
128 // transforms to compute change of basis transforms between |child| and
129 // |sibling|.
130 TransformTree tree;
131 TransformNode& root = *tree.Node(0);
132 root.data.local.Translate(2, 2);
133 root.data.target_id = 0;
134 tree.UpdateTransforms(0);
135
136 TransformNode singular;
137 singular.data.local.matrix().set(2, 2, 0.0);
138 singular.data.target_id = 0;
139
140 TransformNode child;
141 child.data.local.Translate(3, 3);
142 child.data.target_id = 0;
143
144 TransformNode sibling;
145 sibling.data.local.Translate(7, 7);
146 sibling.data.target_id = 0;
147
148 tree.Insert(singular, 0);
149 tree.Insert(child, 1);
150 tree.Insert(sibling, 1);
151
152 tree.UpdateTransforms(1);
153 tree.UpdateTransforms(2);
154 tree.UpdateTransforms(3);
155
156 gfx::Transform expected;
157 gfx::Transform transform;
158
159 expected.Translate(4, 4);
160 bool success = tree.ComputeTransform(3, 2, &transform);
161 EXPECT_TRUE(success);
162 EXPECT_TRANSFORMATION_MATRIX_EQ(expected, transform);
163
164 transform.MakeIdentity();
165 expected.MakeIdentity();
166 expected.Translate(-4, -4);
167 success = tree.ComputeTransform(2, 3, &transform);
168 EXPECT_TRUE(success);
169 EXPECT_TRANSFORMATION_MATRIX_EQ(expected, transform);
170 }
171
172 TEST(PropertyTreeTest, TransformsWithFlattening) { 84 TEST(PropertyTreeTest, TransformsWithFlattening) {
173 TransformTree tree; 85 TransformTree tree;
174 86
175 int grand_parent = tree.Insert(TransformNode(), 0); 87 int grand_parent = tree.Insert(TransformNode(), 0);
176 tree.Node(grand_parent)->data.content_target_id = grand_parent; 88 tree.Node(grand_parent)->data.content_target_id = grand_parent;
177 tree.Node(grand_parent)->data.target_id = grand_parent; 89 tree.Node(grand_parent)->data.target_id = grand_parent;
178 90
179 gfx::Transform rotation_about_x; 91 gfx::Transform rotation_about_x;
180 rotation_about_x.RotateAboutXAxis(15); 92 rotation_about_x.RotateAboutXAxis(15);
181 93
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 EXPECT_TRUE(success); 206 EXPECT_TRUE(success);
295 EXPECT_TRANSFORMATION_MATRIX_EQ(expected, transform); 207 EXPECT_TRANSFORMATION_MATRIX_EQ(expected, transform);
296 208
297 // To compute this would require inverting the 0 matrix, so we cannot 209 // To compute this would require inverting the 0 matrix, so we cannot
298 // succeed. 210 // succeed.
299 success = tree.ComputeTransform(0, 1, &inverse); 211 success = tree.ComputeTransform(0, 1, &inverse);
300 EXPECT_FALSE(success); 212 EXPECT_FALSE(success);
301 } 213 }
302 214
303 } // namespace cc 215 } // namespace cc
OLDNEW
« no previous file with comments | « cc/trees/property_tree.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698