| 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/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 29 matching lines...) Expand all Loading... |
| 40 TEST(PropertyTreeTest, ComputeTransformChild) { | 40 TEST(PropertyTreeTest, ComputeTransformChild) { |
| 41 TransformTree tree; | 41 TransformTree tree; |
| 42 TransformNode& root = *tree.Node(0); | 42 TransformNode& root = *tree.Node(0); |
| 43 root.data.local.Translate(2, 2); | 43 root.data.local.Translate(2, 2); |
| 44 root.data.target_id = 0; | 44 root.data.target_id = 0; |
| 45 tree.UpdateTransforms(0); | 45 tree.UpdateTransforms(0); |
| 46 | 46 |
| 47 TransformNode child; | 47 TransformNode child; |
| 48 child.data.local.Translate(3, 3); | 48 child.data.local.Translate(3, 3); |
| 49 child.data.target_id = 0; | 49 child.data.target_id = 0; |
| 50 child.data.source_node_id = 0; |
| 50 | 51 |
| 51 tree.Insert(child, 0); | 52 tree.Insert(child, 0); |
| 52 tree.UpdateTransforms(1); | 53 tree.UpdateTransforms(1); |
| 53 | 54 |
| 54 gfx::Transform expected; | 55 gfx::Transform expected; |
| 55 gfx::Transform transform; | 56 gfx::Transform transform; |
| 56 | 57 |
| 57 expected.Translate(3, 3); | 58 expected.Translate(3, 3); |
| 58 bool success = tree.ComputeTransform(1, 0, &transform); | 59 bool success = tree.ComputeTransform(1, 0, &transform); |
| 59 EXPECT_TRUE(success); | 60 EXPECT_TRUE(success); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 80 EXPECT_TRUE(success); | 81 EXPECT_TRUE(success); |
| 81 EXPECT_TRANSFORMATION_MATRIX_EQ(expected, transform); | 82 EXPECT_TRANSFORMATION_MATRIX_EQ(expected, transform); |
| 82 } | 83 } |
| 83 | 84 |
| 84 TEST(PropertyTreeTest, TransformsWithFlattening) { | 85 TEST(PropertyTreeTest, TransformsWithFlattening) { |
| 85 TransformTree tree; | 86 TransformTree tree; |
| 86 | 87 |
| 87 int grand_parent = tree.Insert(TransformNode(), 0); | 88 int grand_parent = tree.Insert(TransformNode(), 0); |
| 88 tree.Node(grand_parent)->data.content_target_id = grand_parent; | 89 tree.Node(grand_parent)->data.content_target_id = grand_parent; |
| 89 tree.Node(grand_parent)->data.target_id = grand_parent; | 90 tree.Node(grand_parent)->data.target_id = grand_parent; |
| 91 tree.Node(grand_parent)->data.source_node_id = 0; |
| 90 | 92 |
| 91 gfx::Transform rotation_about_x; | 93 gfx::Transform rotation_about_x; |
| 92 rotation_about_x.RotateAboutXAxis(15); | 94 rotation_about_x.RotateAboutXAxis(15); |
| 93 | 95 |
| 94 int parent = tree.Insert(TransformNode(), grand_parent); | 96 int parent = tree.Insert(TransformNode(), grand_parent); |
| 95 tree.Node(parent)->data.needs_sublayer_scale = true; | 97 tree.Node(parent)->data.needs_sublayer_scale = true; |
| 96 tree.Node(parent)->data.target_id = grand_parent; | 98 tree.Node(parent)->data.target_id = grand_parent; |
| 97 tree.Node(parent)->data.content_target_id = parent; | 99 tree.Node(parent)->data.content_target_id = parent; |
| 100 tree.Node(parent)->data.source_node_id = grand_parent; |
| 98 tree.Node(parent)->data.local = rotation_about_x; | 101 tree.Node(parent)->data.local = rotation_about_x; |
| 99 | 102 |
| 100 int child = tree.Insert(TransformNode(), parent); | 103 int child = tree.Insert(TransformNode(), parent); |
| 101 tree.Node(child)->data.target_id = parent; | 104 tree.Node(child)->data.target_id = parent; |
| 102 tree.Node(child)->data.content_target_id = parent; | 105 tree.Node(child)->data.content_target_id = parent; |
| 106 tree.Node(child)->data.source_node_id = parent; |
| 103 tree.Node(child)->data.flattens_inherited_transform = true; | 107 tree.Node(child)->data.flattens_inherited_transform = true; |
| 104 tree.Node(child)->data.local = rotation_about_x; | 108 tree.Node(child)->data.local = rotation_about_x; |
| 105 | 109 |
| 106 int grand_child = tree.Insert(TransformNode(), child); | 110 int grand_child = tree.Insert(TransformNode(), child); |
| 107 tree.Node(grand_child)->data.target_id = parent; | 111 tree.Node(grand_child)->data.target_id = parent; |
| 108 tree.Node(grand_child)->data.content_target_id = parent; | 112 tree.Node(grand_child)->data.content_target_id = parent; |
| 113 tree.Node(grand_child)->data.source_node_id = child; |
| 109 tree.Node(grand_child)->data.flattens_inherited_transform = true; | 114 tree.Node(grand_child)->data.flattens_inherited_transform = true; |
| 110 tree.Node(grand_child)->data.local = rotation_about_x; | 115 tree.Node(grand_child)->data.local = rotation_about_x; |
| 111 | 116 |
| 112 tree.set_needs_update(true); | 117 tree.set_needs_update(true); |
| 113 ComputeTransforms(&tree); | 118 ComputeTransforms(&tree); |
| 114 | 119 |
| 115 gfx::Transform flattened_rotation_about_x = rotation_about_x; | 120 gfx::Transform flattened_rotation_about_x = rotation_about_x; |
| 116 flattened_rotation_about_x.FlattenTo2d(); | 121 flattened_rotation_about_x.FlattenTo2d(); |
| 117 | 122 |
| 118 EXPECT_TRANSFORMATION_MATRIX_EQ(rotation_about_x, | 123 EXPECT_TRANSFORMATION_MATRIX_EQ(rotation_about_x, |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 TEST(PropertyTreeTest, MultiplicationOrder) { | 160 TEST(PropertyTreeTest, MultiplicationOrder) { |
| 156 TransformTree tree; | 161 TransformTree tree; |
| 157 TransformNode& root = *tree.Node(0); | 162 TransformNode& root = *tree.Node(0); |
| 158 root.data.local.Translate(2, 2); | 163 root.data.local.Translate(2, 2); |
| 159 root.data.target_id = 0; | 164 root.data.target_id = 0; |
| 160 tree.UpdateTransforms(0); | 165 tree.UpdateTransforms(0); |
| 161 | 166 |
| 162 TransformNode child; | 167 TransformNode child; |
| 163 child.data.local.Scale(2, 2); | 168 child.data.local.Scale(2, 2); |
| 164 child.data.target_id = 0; | 169 child.data.target_id = 0; |
| 170 child.data.source_node_id = 0; |
| 165 | 171 |
| 166 tree.Insert(child, 0); | 172 tree.Insert(child, 0); |
| 167 tree.UpdateTransforms(1); | 173 tree.UpdateTransforms(1); |
| 168 | 174 |
| 169 gfx::Transform expected; | 175 gfx::Transform expected; |
| 170 expected.Translate(2, 2); | 176 expected.Translate(2, 2); |
| 171 expected.Scale(2, 2); | 177 expected.Scale(2, 2); |
| 172 | 178 |
| 173 gfx::Transform transform; | 179 gfx::Transform transform; |
| 174 gfx::Transform inverse; | 180 gfx::Transform inverse; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 187 | 193 |
| 188 TEST(PropertyTreeTest, ComputeTransformWithUninvertibleTransform) { | 194 TEST(PropertyTreeTest, ComputeTransformWithUninvertibleTransform) { |
| 189 TransformTree tree; | 195 TransformTree tree; |
| 190 TransformNode& root = *tree.Node(0); | 196 TransformNode& root = *tree.Node(0); |
| 191 root.data.target_id = 0; | 197 root.data.target_id = 0; |
| 192 tree.UpdateTransforms(0); | 198 tree.UpdateTransforms(0); |
| 193 | 199 |
| 194 TransformNode child; | 200 TransformNode child; |
| 195 child.data.local.Scale(0, 0); | 201 child.data.local.Scale(0, 0); |
| 196 child.data.target_id = 0; | 202 child.data.target_id = 0; |
| 203 child.data.source_node_id = 0; |
| 197 | 204 |
| 198 tree.Insert(child, 0); | 205 tree.Insert(child, 0); |
| 199 tree.UpdateTransforms(1); | 206 tree.UpdateTransforms(1); |
| 200 | 207 |
| 201 gfx::Transform expected; | 208 gfx::Transform expected; |
| 202 expected.Scale(0, 0); | 209 expected.Scale(0, 0); |
| 203 | 210 |
| 204 gfx::Transform transform; | 211 gfx::Transform transform; |
| 205 gfx::Transform inverse; | 212 gfx::Transform inverse; |
| 206 | 213 |
| 207 bool success = tree.ComputeTransform(1, 0, &transform); | 214 bool success = tree.ComputeTransform(1, 0, &transform); |
| 208 EXPECT_TRUE(success); | 215 EXPECT_TRUE(success); |
| 209 EXPECT_TRANSFORMATION_MATRIX_EQ(expected, transform); | 216 EXPECT_TRANSFORMATION_MATRIX_EQ(expected, transform); |
| 210 | 217 |
| 211 // To compute this would require inverting the 0 matrix, so we cannot | 218 // To compute this would require inverting the 0 matrix, so we cannot |
| 212 // succeed. | 219 // succeed. |
| 213 success = tree.ComputeTransform(0, 1, &inverse); | 220 success = tree.ComputeTransform(0, 1, &inverse); |
| 214 EXPECT_FALSE(success); | 221 EXPECT_FALSE(success); |
| 215 } | 222 } |
| 216 | 223 |
| 217 TEST(PropertyTreeTest, ComputeTransformWithSublayerScale) { | 224 TEST(PropertyTreeTest, ComputeTransformWithSublayerScale) { |
| 218 TransformTree tree; | 225 TransformTree tree; |
| 219 TransformNode& root = *tree.Node(0); | 226 TransformNode& root = *tree.Node(0); |
| 220 root.data.target_id = 0; | 227 root.data.target_id = 0; |
| 221 tree.UpdateTransforms(0); | 228 tree.UpdateTransforms(0); |
| 222 | 229 |
| 223 TransformNode grand_parent; | 230 TransformNode grand_parent; |
| 224 grand_parent.data.local.Scale(2.f, 2.f); | 231 grand_parent.data.local.Scale(2.f, 2.f); |
| 225 grand_parent.data.target_id = 0; | 232 grand_parent.data.target_id = 0; |
| 233 grand_parent.data.source_node_id = 0; |
| 226 grand_parent.data.needs_sublayer_scale = true; | 234 grand_parent.data.needs_sublayer_scale = true; |
| 227 int grand_parent_id = tree.Insert(grand_parent, 0); | 235 int grand_parent_id = tree.Insert(grand_parent, 0); |
| 228 tree.UpdateTransforms(grand_parent_id); | 236 tree.UpdateTransforms(grand_parent_id); |
| 229 | 237 |
| 230 TransformNode parent; | 238 TransformNode parent; |
| 231 parent.data.local.Translate(15.f, 15.f); | 239 parent.data.local.Translate(15.f, 15.f); |
| 232 parent.data.target_id = grand_parent_id; | 240 parent.data.target_id = grand_parent_id; |
| 241 parent.data.source_node_id = grand_parent_id; |
| 233 int parent_id = tree.Insert(parent, grand_parent_id); | 242 int parent_id = tree.Insert(parent, grand_parent_id); |
| 234 tree.UpdateTransforms(parent_id); | 243 tree.UpdateTransforms(parent_id); |
| 235 | 244 |
| 236 TransformNode child; | 245 TransformNode child; |
| 237 child.data.local.Scale(3.f, 3.f); | 246 child.data.local.Scale(3.f, 3.f); |
| 238 child.data.target_id = grand_parent_id; | 247 child.data.target_id = grand_parent_id; |
| 248 child.data.source_node_id = parent_id; |
| 239 int child_id = tree.Insert(child, parent_id); | 249 int child_id = tree.Insert(child, parent_id); |
| 240 tree.UpdateTransforms(child_id); | 250 tree.UpdateTransforms(child_id); |
| 241 | 251 |
| 242 TransformNode grand_child; | 252 TransformNode grand_child; |
| 243 grand_child.data.local.Scale(5.f, 5.f); | 253 grand_child.data.local.Scale(5.f, 5.f); |
| 244 grand_child.data.target_id = grand_parent_id; | 254 grand_child.data.target_id = grand_parent_id; |
| 255 grand_child.data.source_node_id = child_id; |
| 245 grand_child.data.needs_sublayer_scale = true; | 256 grand_child.data.needs_sublayer_scale = true; |
| 246 int grand_child_id = tree.Insert(grand_child, child_id); | 257 int grand_child_id = tree.Insert(grand_child, child_id); |
| 247 tree.UpdateTransforms(grand_child_id); | 258 tree.UpdateTransforms(grand_child_id); |
| 248 | 259 |
| 249 EXPECT_EQ(gfx::Vector2dF(2.f, 2.f), | 260 EXPECT_EQ(gfx::Vector2dF(2.f, 2.f), |
| 250 tree.Node(grand_parent_id)->data.sublayer_scale); | 261 tree.Node(grand_parent_id)->data.sublayer_scale); |
| 251 EXPECT_EQ(gfx::Vector2dF(30.f, 30.f), | 262 EXPECT_EQ(gfx::Vector2dF(30.f, 30.f), |
| 252 tree.Node(grand_child_id)->data.sublayer_scale); | 263 tree.Node(grand_child_id)->data.sublayer_scale); |
| 253 | 264 |
| 254 // Compute transform from grand_parent to grand_child. | 265 // Compute transform from grand_parent to grand_child. |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 320 | 331 |
| 321 TEST(PropertyTreeTest, FlatteningWhenDestinationHasOnlyFlatAncestors) { | 332 TEST(PropertyTreeTest, FlatteningWhenDestinationHasOnlyFlatAncestors) { |
| 322 // This tests that flattening is performed correctly when | 333 // This tests that flattening is performed correctly when |
| 323 // destination and its ancestors are flat, but there are 3d transforms | 334 // destination and its ancestors are flat, but there are 3d transforms |
| 324 // and flattening between the source and destination. | 335 // and flattening between the source and destination. |
| 325 TransformTree tree; | 336 TransformTree tree; |
| 326 | 337 |
| 327 int parent = tree.Insert(TransformNode(), 0); | 338 int parent = tree.Insert(TransformNode(), 0); |
| 328 tree.Node(parent)->data.content_target_id = parent; | 339 tree.Node(parent)->data.content_target_id = parent; |
| 329 tree.Node(parent)->data.target_id = parent; | 340 tree.Node(parent)->data.target_id = parent; |
| 341 tree.Node(parent)->data.source_node_id = 0; |
| 330 tree.Node(parent)->data.local.Translate(2, 2); | 342 tree.Node(parent)->data.local.Translate(2, 2); |
| 331 | 343 |
| 332 gfx::Transform rotation_about_x; | 344 gfx::Transform rotation_about_x; |
| 333 rotation_about_x.RotateAboutXAxis(15); | 345 rotation_about_x.RotateAboutXAxis(15); |
| 334 | 346 |
| 335 int child = tree.Insert(TransformNode(), parent); | 347 int child = tree.Insert(TransformNode(), parent); |
| 336 tree.Node(child)->data.content_target_id = child; | 348 tree.Node(child)->data.content_target_id = child; |
| 337 tree.Node(child)->data.target_id = child; | 349 tree.Node(child)->data.target_id = child; |
| 350 tree.Node(child)->data.source_node_id = parent; |
| 338 tree.Node(child)->data.local = rotation_about_x; | 351 tree.Node(child)->data.local = rotation_about_x; |
| 339 | 352 |
| 340 | 353 |
| 341 int grand_child = tree.Insert(TransformNode(), child); | 354 int grand_child = tree.Insert(TransformNode(), child); |
| 342 tree.Node(grand_child)->data.content_target_id = grand_child; | 355 tree.Node(grand_child)->data.content_target_id = grand_child; |
| 343 tree.Node(grand_child)->data.target_id = grand_child; | 356 tree.Node(grand_child)->data.target_id = grand_child; |
| 357 tree.Node(grand_child)->data.source_node_id = child; |
| 344 tree.Node(grand_child)->data.flattens_inherited_transform = true; | 358 tree.Node(grand_child)->data.flattens_inherited_transform = true; |
| 345 | 359 |
| 346 tree.set_needs_update(true); | 360 tree.set_needs_update(true); |
| 347 ComputeTransforms(&tree); | 361 ComputeTransforms(&tree); |
| 348 | 362 |
| 349 gfx::Transform flattened_rotation_about_x = rotation_about_x; | 363 gfx::Transform flattened_rotation_about_x = rotation_about_x; |
| 350 flattened_rotation_about_x.FlattenTo2d(); | 364 flattened_rotation_about_x.FlattenTo2d(); |
| 351 | 365 |
| 352 gfx::Transform grand_child_to_parent; | 366 gfx::Transform grand_child_to_parent; |
| 353 bool success = | 367 bool success = |
| 354 tree.ComputeTransform(grand_child, parent, &grand_child_to_parent); | 368 tree.ComputeTransform(grand_child, parent, &grand_child_to_parent); |
| 355 EXPECT_TRUE(success); | 369 EXPECT_TRUE(success); |
| 356 EXPECT_TRANSFORMATION_MATRIX_EQ(flattened_rotation_about_x, | 370 EXPECT_TRANSFORMATION_MATRIX_EQ(flattened_rotation_about_x, |
| 357 grand_child_to_parent); | 371 grand_child_to_parent); |
| 358 } | 372 } |
| 359 | 373 |
| 360 } // namespace cc | 374 } // namespace cc |
| OLD | NEW |