| 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/test/geometry_test_utils.h" | 8 #include "cc/test/geometry_test_utils.h" |
| 9 #include "cc/trees/clip_node.h" | 9 #include "cc/trees/clip_node.h" |
| 10 #include "cc/trees/draw_property_utils.h" | 10 #include "cc/trees/draw_property_utils.h" |
| 11 #include "cc/trees/effect_node.h" | 11 #include "cc/trees/effect_node.h" |
| 12 #include "cc/trees/scroll_node.h" | 12 #include "cc/trees/scroll_node.h" |
| 13 #include "cc/trees/transform_node.h" | 13 #include "cc/trees/transform_node.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 15 | 15 |
| 16 namespace cc { | 16 namespace cc { |
| 17 namespace { | 17 namespace { |
| 18 | 18 |
| 19 TEST(PropertyTreeTest, ComputeTransformRoot) { | 19 TEST(PropertyTreeTest, ComputeTransformRoot) { |
| 20 PropertyTrees property_trees; | 20 PropertyTrees property_trees; |
| 21 TransformTree& tree = property_trees.transform_tree; | 21 TransformTree& tree = property_trees.transform_tree; |
| 22 TransformNode contents_root; | 22 TransformNode contents_root; |
| 23 contents_root.local.Translate(2, 2); | 23 contents_root.local.Translate(2, 2); |
| 24 contents_root.source_node_id = 0; | 24 contents_root.source_node_id = 0; |
| 25 contents_root.id = tree.Insert(contents_root, 0); | 25 contents_root.id = tree.Insert(contents_root, 0); |
| 26 tree.SetTargetId(contents_root.id, 0); | |
| 27 tree.UpdateTransforms(1); | 26 tree.UpdateTransforms(1); |
| 28 | 27 |
| 29 gfx::Transform expected; | 28 gfx::Transform expected; |
| 30 gfx::Transform transform; | 29 gfx::Transform transform; |
| 31 expected.Translate(2, 2); | 30 expected.Translate(2, 2); |
| 32 tree.CombineTransformsBetween(1, 0, &transform); | 31 tree.CombineTransformsBetween(1, 0, &transform); |
| 33 EXPECT_TRANSFORMATION_MATRIX_EQ(expected, transform); | 32 EXPECT_TRANSFORMATION_MATRIX_EQ(expected, transform); |
| 34 | 33 |
| 35 transform.MakeIdentity(); | 34 transform.MakeIdentity(); |
| 36 expected.MakeIdentity(); | 35 expected.MakeIdentity(); |
| 37 expected.Translate(-2, -2); | 36 expected.Translate(-2, -2); |
| 38 bool success = tree.CombineInversesBetween(0, 1, &transform); | 37 bool success = tree.CombineInversesBetween(0, 1, &transform); |
| 39 EXPECT_TRUE(success); | 38 EXPECT_TRUE(success); |
| 40 EXPECT_TRANSFORMATION_MATRIX_EQ(expected, transform); | 39 EXPECT_TRANSFORMATION_MATRIX_EQ(expected, transform); |
| 41 } | 40 } |
| 42 | 41 |
| 43 TEST(PropertyTreeTest, SetNeedsUpdate) { | 42 TEST(PropertyTreeTest, SetNeedsUpdate) { |
| 44 PropertyTrees property_trees; | 43 PropertyTrees property_trees; |
| 45 TransformTree& tree = property_trees.transform_tree; | 44 TransformTree& tree = property_trees.transform_tree; |
| 46 TransformNode contents_root; | 45 TransformNode contents_root; |
| 47 contents_root.source_node_id = 0; | 46 contents_root.source_node_id = 0; |
| 48 contents_root.id = tree.Insert(contents_root, 0); | 47 contents_root.id = tree.Insert(contents_root, 0); |
| 49 tree.SetTargetId(contents_root.id, 0); | |
| 50 | 48 |
| 51 EXPECT_FALSE(tree.needs_update()); | 49 EXPECT_FALSE(tree.needs_update()); |
| 52 tree.SetRootTransformsAndScales(0.6f, 1.f, gfx::Transform(), gfx::PointF()); | 50 tree.SetRootTransformsAndScales(0.6f, 1.f, gfx::Transform(), gfx::PointF()); |
| 53 EXPECT_TRUE(tree.needs_update()); | 51 EXPECT_TRUE(tree.needs_update()); |
| 54 tree.set_needs_update(false); | 52 tree.set_needs_update(false); |
| 55 tree.SetRootTransformsAndScales(0.6f, 1.f, gfx::Transform(), gfx::PointF()); | 53 tree.SetRootTransformsAndScales(0.6f, 1.f, gfx::Transform(), gfx::PointF()); |
| 56 EXPECT_FALSE(tree.needs_update()); | 54 EXPECT_FALSE(tree.needs_update()); |
| 57 } | 55 } |
| 58 | 56 |
| 59 TEST(PropertyTreeTest, ComputeTransformChild) { | 57 TEST(PropertyTreeTest, ComputeTransformChild) { |
| 60 PropertyTrees property_trees; | 58 PropertyTrees property_trees; |
| 61 TransformTree& tree = property_trees.transform_tree; | 59 TransformTree& tree = property_trees.transform_tree; |
| 62 TransformNode contents_root; | 60 TransformNode contents_root; |
| 63 contents_root.local.Translate(2, 2); | 61 contents_root.local.Translate(2, 2); |
| 64 contents_root.source_node_id = 0; | 62 contents_root.source_node_id = 0; |
| 65 contents_root.id = tree.Insert(contents_root, 0); | 63 contents_root.id = tree.Insert(contents_root, 0); |
| 66 tree.SetTargetId(contents_root.id, 0); | |
| 67 tree.UpdateTransforms(contents_root.id); | 64 tree.UpdateTransforms(contents_root.id); |
| 68 | 65 |
| 69 TransformNode child; | 66 TransformNode child; |
| 70 child.local.Translate(3, 3); | 67 child.local.Translate(3, 3); |
| 71 child.source_node_id = 1; | 68 child.source_node_id = 1; |
| 72 child.id = tree.Insert(child, contents_root.id); | 69 child.id = tree.Insert(child, contents_root.id); |
| 73 tree.SetTargetId(child.id, 0); | |
| 74 | 70 |
| 75 tree.UpdateTransforms(child.id); | 71 tree.UpdateTransforms(child.id); |
| 76 | 72 |
| 77 gfx::Transform expected; | 73 gfx::Transform expected; |
| 78 gfx::Transform transform; | 74 gfx::Transform transform; |
| 79 | 75 |
| 80 expected.Translate(3, 3); | 76 expected.Translate(3, 3); |
| 81 tree.CombineTransformsBetween(2, 1, &transform); | 77 tree.CombineTransformsBetween(2, 1, &transform); |
| 82 EXPECT_TRANSFORMATION_MATRIX_EQ(expected, transform); | 78 EXPECT_TRANSFORMATION_MATRIX_EQ(expected, transform); |
| 83 | 79 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 102 EXPECT_TRANSFORMATION_MATRIX_EQ(expected, transform); | 98 EXPECT_TRANSFORMATION_MATRIX_EQ(expected, transform); |
| 103 } | 99 } |
| 104 | 100 |
| 105 TEST(PropertyTreeTest, ComputeTransformSibling) { | 101 TEST(PropertyTreeTest, ComputeTransformSibling) { |
| 106 PropertyTrees property_trees; | 102 PropertyTrees property_trees; |
| 107 TransformTree& tree = property_trees.transform_tree; | 103 TransformTree& tree = property_trees.transform_tree; |
| 108 TransformNode contents_root; | 104 TransformNode contents_root; |
| 109 contents_root.source_node_id = 0; | 105 contents_root.source_node_id = 0; |
| 110 contents_root.local.Translate(2, 2); | 106 contents_root.local.Translate(2, 2); |
| 111 contents_root.id = tree.Insert(contents_root, 0); | 107 contents_root.id = tree.Insert(contents_root, 0); |
| 112 tree.SetTargetId(contents_root.id, 0); | |
| 113 tree.UpdateTransforms(1); | 108 tree.UpdateTransforms(1); |
| 114 | 109 |
| 115 TransformNode child; | 110 TransformNode child; |
| 116 child.local.Translate(3, 3); | 111 child.local.Translate(3, 3); |
| 117 child.source_node_id = 1; | 112 child.source_node_id = 1; |
| 118 child.id = tree.Insert(child, 1); | 113 child.id = tree.Insert(child, 1); |
| 119 tree.SetTargetId(child.id, 0); | |
| 120 | 114 |
| 121 TransformNode sibling; | 115 TransformNode sibling; |
| 122 sibling.local.Translate(7, 7); | 116 sibling.local.Translate(7, 7); |
| 123 sibling.source_node_id = 1; | 117 sibling.source_node_id = 1; |
| 124 sibling.id = tree.Insert(sibling, 1); | 118 sibling.id = tree.Insert(sibling, 1); |
| 125 tree.SetTargetId(sibling.id, 0); | |
| 126 | 119 |
| 127 tree.UpdateTransforms(2); | 120 tree.UpdateTransforms(2); |
| 128 tree.UpdateTransforms(3); | 121 tree.UpdateTransforms(3); |
| 129 | 122 |
| 130 gfx::Transform expected; | 123 gfx::Transform expected; |
| 131 gfx::Transform transform; | 124 gfx::Transform transform; |
| 132 | 125 |
| 133 expected.Translate(4, 4); | 126 expected.Translate(4, 4); |
| 134 tree.CombineTransformsBetween(3, 2, &transform); | 127 tree.CombineTransformsBetween(3, 2, &transform); |
| 135 EXPECT_TRANSFORMATION_MATRIX_EQ(expected, transform); | 128 EXPECT_TRANSFORMATION_MATRIX_EQ(expected, transform); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 151 // Since the lowest common ancestor of |child| and |sibling| has a singular | 144 // Since the lowest common ancestor of |child| and |sibling| has a singular |
| 152 // transform, we cannot use screen space transforms to compute change of | 145 // transform, we cannot use screen space transforms to compute change of |
| 153 // basis | 146 // basis |
| 154 // transforms between these nodes. | 147 // transforms between these nodes. |
| 155 PropertyTrees property_trees; | 148 PropertyTrees property_trees; |
| 156 TransformTree& tree = property_trees.transform_tree; | 149 TransformTree& tree = property_trees.transform_tree; |
| 157 TransformNode contents_root; | 150 TransformNode contents_root; |
| 158 contents_root.local.Translate(2, 2); | 151 contents_root.local.Translate(2, 2); |
| 159 contents_root.source_node_id = 0; | 152 contents_root.source_node_id = 0; |
| 160 contents_root.id = tree.Insert(contents_root, 0); | 153 contents_root.id = tree.Insert(contents_root, 0); |
| 161 tree.SetTargetId(contents_root.id, 0); | |
| 162 tree.UpdateTransforms(1); | 154 tree.UpdateTransforms(1); |
| 163 | 155 |
| 164 TransformNode singular; | 156 TransformNode singular; |
| 165 singular.local.matrix().set(2, 2, 0.0); | 157 singular.local.matrix().set(2, 2, 0.0); |
| 166 singular.source_node_id = 1; | 158 singular.source_node_id = 1; |
| 167 singular.id = tree.Insert(singular, 1); | 159 singular.id = tree.Insert(singular, 1); |
| 168 tree.SetTargetId(singular.id, 0); | |
| 169 | 160 |
| 170 TransformNode child; | 161 TransformNode child; |
| 171 child.local.Translate(3, 3); | 162 child.local.Translate(3, 3); |
| 172 child.source_node_id = 2; | 163 child.source_node_id = 2; |
| 173 child.id = tree.Insert(child, 2); | 164 child.id = tree.Insert(child, 2); |
| 174 tree.SetTargetId(child.id, 0); | |
| 175 | 165 |
| 176 TransformNode sibling; | 166 TransformNode sibling; |
| 177 sibling.local.Translate(7, 7); | 167 sibling.local.Translate(7, 7); |
| 178 sibling.source_node_id = 2; | 168 sibling.source_node_id = 2; |
| 179 sibling.id = tree.Insert(sibling, 2); | 169 sibling.id = tree.Insert(sibling, 2); |
| 180 tree.SetTargetId(sibling.id, 0); | |
| 181 | 170 |
| 182 tree.UpdateTransforms(2); | 171 tree.UpdateTransforms(2); |
| 183 tree.UpdateTransforms(3); | 172 tree.UpdateTransforms(3); |
| 184 tree.UpdateTransforms(4); | 173 tree.UpdateTransforms(4); |
| 185 | 174 |
| 186 gfx::Transform expected; | 175 gfx::Transform expected; |
| 187 gfx::Transform transform; | 176 gfx::Transform transform; |
| 188 | 177 |
| 189 expected.Translate(4, 4); | 178 expected.Translate(4, 4); |
| 190 tree.CombineTransformsBetween(4, 3, &transform); | 179 tree.CombineTransformsBetween(4, 3, &transform); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 202 PropertyTrees property_trees; | 191 PropertyTrees property_trees; |
| 203 TransformTree& tree = property_trees.transform_tree; | 192 TransformTree& tree = property_trees.transform_tree; |
| 204 EffectTree& effect_tree = property_trees.effect_tree; | 193 EffectTree& effect_tree = property_trees.effect_tree; |
| 205 | 194 |
| 206 int grand_parent = tree.Insert(TransformNode(), 0); | 195 int grand_parent = tree.Insert(TransformNode(), 0); |
| 207 int effect_grand_parent = effect_tree.Insert(EffectNode(), 0); | 196 int effect_grand_parent = effect_tree.Insert(EffectNode(), 0); |
| 208 effect_tree.Node(effect_grand_parent)->has_render_surface = true; | 197 effect_tree.Node(effect_grand_parent)->has_render_surface = true; |
| 209 effect_tree.Node(effect_grand_parent)->transform_id = grand_parent; | 198 effect_tree.Node(effect_grand_parent)->transform_id = grand_parent; |
| 210 effect_tree.Node(effect_grand_parent)->surface_contents_scale = | 199 effect_tree.Node(effect_grand_parent)->surface_contents_scale = |
| 211 gfx::Vector2dF(1.f, 1.f); | 200 gfx::Vector2dF(1.f, 1.f); |
| 212 tree.SetContentTargetId(grand_parent, grand_parent); | |
| 213 tree.SetTargetId(grand_parent, grand_parent); | |
| 214 tree.Node(grand_parent)->source_node_id = 0; | 201 tree.Node(grand_parent)->source_node_id = 0; |
| 215 | 202 |
| 216 gfx::Transform rotation_about_x; | 203 gfx::Transform rotation_about_x; |
| 217 rotation_about_x.RotateAboutXAxis(15); | 204 rotation_about_x.RotateAboutXAxis(15); |
| 218 | 205 |
| 219 int parent = tree.Insert(TransformNode(), grand_parent); | 206 int parent = tree.Insert(TransformNode(), grand_parent); |
| 220 int effect_parent = effect_tree.Insert(EffectNode(), effect_grand_parent); | 207 int effect_parent = effect_tree.Insert(EffectNode(), effect_grand_parent); |
| 221 effect_tree.Node(effect_parent)->transform_id = parent; | 208 effect_tree.Node(effect_parent)->transform_id = parent; |
| 222 effect_tree.Node(effect_parent)->has_render_surface = true; | 209 effect_tree.Node(effect_parent)->has_render_surface = true; |
| 223 effect_tree.Node(effect_parent)->surface_contents_scale = | 210 effect_tree.Node(effect_parent)->surface_contents_scale = |
| 224 gfx::Vector2dF(1.f, 1.f); | 211 gfx::Vector2dF(1.f, 1.f); |
| 225 tree.SetTargetId(parent, grand_parent); | |
| 226 tree.SetContentTargetId(parent, parent); | |
| 227 tree.Node(parent)->source_node_id = grand_parent; | 212 tree.Node(parent)->source_node_id = grand_parent; |
| 228 tree.Node(parent)->local = rotation_about_x; | 213 tree.Node(parent)->local = rotation_about_x; |
| 229 | 214 |
| 230 int child = tree.Insert(TransformNode(), parent); | 215 int child = tree.Insert(TransformNode(), parent); |
| 231 tree.SetTargetId(child, parent); | |
| 232 tree.SetContentTargetId(child, parent); | |
| 233 tree.Node(child)->source_node_id = parent; | 216 tree.Node(child)->source_node_id = parent; |
| 234 tree.Node(child)->flattens_inherited_transform = true; | 217 tree.Node(child)->flattens_inherited_transform = true; |
| 235 tree.Node(child)->local = rotation_about_x; | 218 tree.Node(child)->local = rotation_about_x; |
| 236 | 219 |
| 237 int grand_child = tree.Insert(TransformNode(), child); | 220 int grand_child = tree.Insert(TransformNode(), child); |
| 238 tree.SetTargetId(grand_child, parent); | |
| 239 tree.SetContentTargetId(grand_child, parent); | |
| 240 tree.Node(grand_child)->source_node_id = child; | 221 tree.Node(grand_child)->source_node_id = child; |
| 241 tree.Node(grand_child)->flattens_inherited_transform = true; | 222 tree.Node(grand_child)->flattens_inherited_transform = true; |
| 242 tree.Node(grand_child)->local = rotation_about_x; | 223 tree.Node(grand_child)->local = rotation_about_x; |
| 243 | 224 |
| 244 tree.set_needs_update(true); | 225 tree.set_needs_update(true); |
| 245 draw_property_utils::ComputeTransforms(&tree); | 226 draw_property_utils::ComputeTransforms(&tree); |
| 246 property_trees.ResetCachedData(); | 227 property_trees.ResetCachedData(); |
| 247 | 228 |
| 248 gfx::Transform flattened_rotation_about_x = rotation_about_x; | 229 gfx::Transform flattened_rotation_about_x = rotation_about_x; |
| 249 flattened_rotation_about_x.FlattenTo2d(); | 230 flattened_rotation_about_x.FlattenTo2d(); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 286 EXPECT_TRANSFORMATION_MATRIX_EQ(rotation_about_x, grand_child_to_child); | 267 EXPECT_TRANSFORMATION_MATRIX_EQ(rotation_about_x, grand_child_to_child); |
| 287 } | 268 } |
| 288 | 269 |
| 289 TEST(PropertyTreeTest, MultiplicationOrder) { | 270 TEST(PropertyTreeTest, MultiplicationOrder) { |
| 290 PropertyTrees property_trees; | 271 PropertyTrees property_trees; |
| 291 TransformTree& tree = property_trees.transform_tree; | 272 TransformTree& tree = property_trees.transform_tree; |
| 292 TransformNode contents_root; | 273 TransformNode contents_root; |
| 293 contents_root.local.Translate(2, 2); | 274 contents_root.local.Translate(2, 2); |
| 294 contents_root.source_node_id = 0; | 275 contents_root.source_node_id = 0; |
| 295 contents_root.id = tree.Insert(contents_root, 0); | 276 contents_root.id = tree.Insert(contents_root, 0); |
| 296 tree.SetTargetId(contents_root.id, 0); | |
| 297 tree.UpdateTransforms(1); | 277 tree.UpdateTransforms(1); |
| 298 | 278 |
| 299 TransformNode child; | 279 TransformNode child; |
| 300 child.local.Scale(2, 2); | 280 child.local.Scale(2, 2); |
| 301 child.source_node_id = 1; | 281 child.source_node_id = 1; |
| 302 child.id = tree.Insert(child, 1); | 282 child.id = tree.Insert(child, 1); |
| 303 tree.SetTargetId(child.id, 0); | |
| 304 | 283 |
| 305 tree.UpdateTransforms(2); | 284 tree.UpdateTransforms(2); |
| 306 | 285 |
| 307 gfx::Transform expected; | 286 gfx::Transform expected; |
| 308 expected.Translate(2, 2); | 287 expected.Translate(2, 2); |
| 309 expected.Scale(2, 2); | 288 expected.Scale(2, 2); |
| 310 | 289 |
| 311 gfx::Transform transform; | 290 gfx::Transform transform; |
| 312 gfx::Transform inverse; | 291 gfx::Transform inverse; |
| 313 | 292 |
| 314 tree.CombineTransformsBetween(2, 0, &transform); | 293 tree.CombineTransformsBetween(2, 0, &transform); |
| 315 EXPECT_TRANSFORMATION_MATRIX_EQ(expected, transform); | 294 EXPECT_TRANSFORMATION_MATRIX_EQ(expected, transform); |
| 316 | 295 |
| 317 bool success = tree.CombineInversesBetween(0, 2, &inverse); | 296 bool success = tree.CombineInversesBetween(0, 2, &inverse); |
| 318 EXPECT_TRUE(success); | 297 EXPECT_TRUE(success); |
| 319 | 298 |
| 320 transform = transform * inverse; | 299 transform = transform * inverse; |
| 321 expected.MakeIdentity(); | 300 expected.MakeIdentity(); |
| 322 EXPECT_TRANSFORMATION_MATRIX_EQ(expected, transform); | 301 EXPECT_TRANSFORMATION_MATRIX_EQ(expected, transform); |
| 323 } | 302 } |
| 324 | 303 |
| 325 TEST(PropertyTreeTest, ComputeTransformWithUninvertibleTransform) { | 304 TEST(PropertyTreeTest, ComputeTransformWithUninvertibleTransform) { |
| 326 PropertyTrees property_trees; | 305 PropertyTrees property_trees; |
| 327 TransformTree& tree = property_trees.transform_tree; | 306 TransformTree& tree = property_trees.transform_tree; |
| 328 TransformNode contents_root; | 307 TransformNode contents_root; |
| 329 contents_root.source_node_id = 0; | 308 contents_root.source_node_id = 0; |
| 330 contents_root.id = tree.Insert(contents_root, 0); | 309 contents_root.id = tree.Insert(contents_root, 0); |
| 331 tree.SetTargetId(contents_root.id, 0); | |
| 332 tree.UpdateTransforms(1); | 310 tree.UpdateTransforms(1); |
| 333 | 311 |
| 334 TransformNode child; | 312 TransformNode child; |
| 335 child.local.Scale(0, 0); | 313 child.local.Scale(0, 0); |
| 336 child.source_node_id = 1; | 314 child.source_node_id = 1; |
| 337 child.id = tree.Insert(child, 1); | 315 child.id = tree.Insert(child, 1); |
| 338 tree.SetTargetId(child.id, 0); | |
| 339 | 316 |
| 340 tree.UpdateTransforms(2); | 317 tree.UpdateTransforms(2); |
| 341 | 318 |
| 342 gfx::Transform expected; | 319 gfx::Transform expected; |
| 343 expected.Scale(0, 0); | 320 expected.Scale(0, 0); |
| 344 | 321 |
| 345 gfx::Transform transform; | 322 gfx::Transform transform; |
| 346 gfx::Transform inverse; | 323 gfx::Transform inverse; |
| 347 | 324 |
| 348 tree.CombineTransformsBetween(2, 1, &transform); | 325 tree.CombineTransformsBetween(2, 1, &transform); |
| 349 EXPECT_TRANSFORMATION_MATRIX_EQ(expected, transform); | 326 EXPECT_TRANSFORMATION_MATRIX_EQ(expected, transform); |
| 350 | 327 |
| 351 // To compute this would require inverting the 0 matrix, so we cannot | 328 // To compute this would require inverting the 0 matrix, so we cannot |
| 352 // succeed. | 329 // succeed. |
| 353 bool success = tree.CombineInversesBetween(1, 2, &inverse); | 330 bool success = tree.CombineInversesBetween(1, 2, &inverse); |
| 354 EXPECT_FALSE(success); | 331 EXPECT_FALSE(success); |
| 355 } | 332 } |
| 356 | 333 |
| 357 TEST(PropertyTreeTest, ComputeTransformToTargetWithZeroSurfaceContentsScale) { | 334 TEST(PropertyTreeTest, ComputeTransformToTargetWithZeroSurfaceContentsScale) { |
| 358 PropertyTrees property_trees; | 335 PropertyTrees property_trees; |
| 359 TransformTree& tree = property_trees.transform_tree; | 336 TransformTree& tree = property_trees.transform_tree; |
| 360 TransformNode contents_root; | 337 TransformNode contents_root; |
| 361 contents_root.source_node_id = 0; | 338 contents_root.source_node_id = 0; |
| 362 contents_root.id = tree.Insert(contents_root, 0); | 339 contents_root.id = tree.Insert(contents_root, 0); |
| 363 tree.SetTargetId(contents_root.id, 0); | |
| 364 tree.UpdateTransforms(1); | 340 tree.UpdateTransforms(1); |
| 365 | 341 |
| 366 TransformNode grand_parent; | 342 TransformNode grand_parent; |
| 367 grand_parent.local.Scale(2.f, 0.f); | 343 grand_parent.local.Scale(2.f, 0.f); |
| 368 grand_parent.source_node_id = 1; | 344 grand_parent.source_node_id = 1; |
| 369 int grand_parent_id = tree.Insert(grand_parent, 1); | 345 int grand_parent_id = tree.Insert(grand_parent, 1); |
| 370 tree.SetTargetId(grand_parent_id, 0); | |
| 371 tree.SetContentTargetId(grand_parent_id, grand_parent_id); | |
| 372 tree.UpdateTransforms(grand_parent_id); | 346 tree.UpdateTransforms(grand_parent_id); |
| 373 | 347 |
| 374 TransformNode parent; | 348 TransformNode parent; |
| 375 parent.local.Translate(1.f, 1.f); | 349 parent.local.Translate(1.f, 1.f); |
| 376 parent.source_node_id = grand_parent_id; | 350 parent.source_node_id = grand_parent_id; |
| 377 int parent_id = tree.Insert(parent, grand_parent_id); | 351 int parent_id = tree.Insert(parent, grand_parent_id); |
| 378 tree.SetTargetId(parent_id, grand_parent_id); | |
| 379 tree.SetContentTargetId(parent_id, grand_parent_id); | |
| 380 tree.UpdateTransforms(parent_id); | 352 tree.UpdateTransforms(parent_id); |
| 381 | 353 |
| 382 TransformNode child; | 354 TransformNode child; |
| 383 child.local.Translate(3.f, 4.f); | 355 child.local.Translate(3.f, 4.f); |
| 384 child.source_node_id = parent_id; | 356 child.source_node_id = parent_id; |
| 385 int child_id = tree.Insert(child, parent_id); | 357 int child_id = tree.Insert(child, parent_id); |
| 386 tree.SetTargetId(child_id, grand_parent_id); | |
| 387 tree.SetContentTargetId(child_id, grand_parent_id); | |
| 388 tree.UpdateTransforms(child_id); | 358 tree.UpdateTransforms(child_id); |
| 389 | 359 |
| 390 gfx::Transform expected_transform; | 360 gfx::Transform expected_transform; |
| 391 expected_transform.Translate(4.f, 5.f); | 361 expected_transform.Translate(4.f, 5.f); |
| 392 | 362 |
| 393 gfx::Transform transform; | 363 gfx::Transform transform; |
| 394 tree.CombineTransformsBetween(child_id, grand_parent_id, &transform); | 364 tree.CombineTransformsBetween(child_id, grand_parent_id, &transform); |
| 395 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform, transform); | 365 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform, transform); |
| 396 | 366 |
| 397 tree.Node(grand_parent_id)->local.MakeIdentity(); | 367 tree.Node(grand_parent_id)->local.MakeIdentity(); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 418 } | 388 } |
| 419 | 389 |
| 420 TEST(PropertyTreeTest, FlatteningWhenDestinationHasOnlyFlatAncestors) { | 390 TEST(PropertyTreeTest, FlatteningWhenDestinationHasOnlyFlatAncestors) { |
| 421 // This tests that flattening is performed correctly when | 391 // This tests that flattening is performed correctly when |
| 422 // destination and its ancestors are flat, but there are 3d transforms | 392 // destination and its ancestors are flat, but there are 3d transforms |
| 423 // and flattening between the source and destination. | 393 // and flattening between the source and destination. |
| 424 PropertyTrees property_trees; | 394 PropertyTrees property_trees; |
| 425 TransformTree& tree = property_trees.transform_tree; | 395 TransformTree& tree = property_trees.transform_tree; |
| 426 | 396 |
| 427 int parent = tree.Insert(TransformNode(), 0); | 397 int parent = tree.Insert(TransformNode(), 0); |
| 428 tree.SetContentTargetId(parent, parent); | |
| 429 tree.SetTargetId(parent, parent); | |
| 430 tree.Node(parent)->source_node_id = 0; | 398 tree.Node(parent)->source_node_id = 0; |
| 431 tree.Node(parent)->local.Translate(2, 2); | 399 tree.Node(parent)->local.Translate(2, 2); |
| 432 | 400 |
| 433 gfx::Transform rotation_about_x; | 401 gfx::Transform rotation_about_x; |
| 434 rotation_about_x.RotateAboutXAxis(15); | 402 rotation_about_x.RotateAboutXAxis(15); |
| 435 | 403 |
| 436 int child = tree.Insert(TransformNode(), parent); | 404 int child = tree.Insert(TransformNode(), parent); |
| 437 tree.SetContentTargetId(child, child); | |
| 438 tree.SetTargetId(child, child); | |
| 439 tree.Node(child)->source_node_id = parent; | 405 tree.Node(child)->source_node_id = parent; |
| 440 tree.Node(child)->local = rotation_about_x; | 406 tree.Node(child)->local = rotation_about_x; |
| 441 | 407 |
| 442 int grand_child = tree.Insert(TransformNode(), child); | 408 int grand_child = tree.Insert(TransformNode(), child); |
| 443 tree.SetContentTargetId(grand_child, grand_child); | |
| 444 tree.SetTargetId(grand_child, grand_child); | |
| 445 tree.Node(grand_child)->source_node_id = child; | 409 tree.Node(grand_child)->source_node_id = child; |
| 446 tree.Node(grand_child)->flattens_inherited_transform = true; | 410 tree.Node(grand_child)->flattens_inherited_transform = true; |
| 447 | 411 |
| 448 tree.set_needs_update(true); | 412 tree.set_needs_update(true); |
| 449 draw_property_utils::ComputeTransforms(&tree); | 413 draw_property_utils::ComputeTransforms(&tree); |
| 450 | 414 |
| 451 gfx::Transform flattened_rotation_about_x = rotation_about_x; | 415 gfx::Transform flattened_rotation_about_x = rotation_about_x; |
| 452 flattened_rotation_about_x.FlattenTo2d(); | 416 flattened_rotation_about_x.FlattenTo2d(); |
| 453 | 417 |
| 454 gfx::Transform grand_child_to_parent; | 418 gfx::Transform grand_child_to_parent; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 478 EXPECT_EQ(tree.Node(child)->screen_space_opacity, 0.25f); | 442 EXPECT_EQ(tree.Node(child)->screen_space_opacity, 0.25f); |
| 479 } | 443 } |
| 480 | 444 |
| 481 TEST(PropertyTreeTest, NonIntegerTranslationTest) { | 445 TEST(PropertyTreeTest, NonIntegerTranslationTest) { |
| 482 // This tests that when a node has non-integer translation, the information | 446 // This tests that when a node has non-integer translation, the information |
| 483 // is propagated to the subtree. | 447 // is propagated to the subtree. |
| 484 PropertyTrees property_trees; | 448 PropertyTrees property_trees; |
| 485 TransformTree& tree = property_trees.transform_tree; | 449 TransformTree& tree = property_trees.transform_tree; |
| 486 | 450 |
| 487 int parent = tree.Insert(TransformNode(), 0); | 451 int parent = tree.Insert(TransformNode(), 0); |
| 488 tree.SetTargetId(parent, parent); | |
| 489 tree.Node(parent)->source_node_id = 0; | 452 tree.Node(parent)->source_node_id = 0; |
| 490 tree.Node(parent)->local.Translate(1.5f, 1.5f); | 453 tree.Node(parent)->local.Translate(1.5f, 1.5f); |
| 491 | 454 |
| 492 int child = tree.Insert(TransformNode(), parent); | 455 int child = tree.Insert(TransformNode(), parent); |
| 493 tree.SetTargetId(child, parent); | |
| 494 tree.Node(child)->local.Translate(1, 1); | 456 tree.Node(child)->local.Translate(1, 1); |
| 495 tree.Node(child)->source_node_id = parent; | 457 tree.Node(child)->source_node_id = parent; |
| 496 tree.set_needs_update(true); | 458 tree.set_needs_update(true); |
| 497 draw_property_utils::ComputeTransforms(&tree); | 459 draw_property_utils::ComputeTransforms(&tree); |
| 498 EXPECT_FALSE( | 460 EXPECT_FALSE( |
| 499 tree.Node(parent)->node_and_ancestors_have_only_integer_translation); | 461 tree.Node(parent)->node_and_ancestors_have_only_integer_translation); |
| 500 EXPECT_FALSE( | 462 EXPECT_FALSE( |
| 501 tree.Node(child)->node_and_ancestors_have_only_integer_translation); | 463 tree.Node(child)->node_and_ancestors_have_only_integer_translation); |
| 502 | 464 |
| 503 tree.Node(parent)->local.Translate(0.5f, 0.5f); | 465 tree.Node(parent)->local.Translate(0.5f, 0.5f); |
| 504 tree.Node(child)->local.Translate(0.5f, 0.5f); | 466 tree.Node(child)->local.Translate(0.5f, 0.5f); |
| 505 tree.Node(parent)->needs_local_transform_update = true; | 467 tree.Node(parent)->needs_local_transform_update = true; |
| 506 tree.Node(child)->needs_local_transform_update = true; | 468 tree.Node(child)->needs_local_transform_update = true; |
| 507 tree.set_needs_update(true); | 469 tree.set_needs_update(true); |
| 508 draw_property_utils::ComputeTransforms(&tree); | 470 draw_property_utils::ComputeTransforms(&tree); |
| 509 EXPECT_TRUE( | 471 EXPECT_TRUE( |
| 510 tree.Node(parent)->node_and_ancestors_have_only_integer_translation); | 472 tree.Node(parent)->node_and_ancestors_have_only_integer_translation); |
| 511 EXPECT_FALSE( | 473 EXPECT_FALSE( |
| 512 tree.Node(child)->node_and_ancestors_have_only_integer_translation); | 474 tree.Node(child)->node_and_ancestors_have_only_integer_translation); |
| 513 | 475 |
| 514 tree.Node(child)->local.Translate(0.5f, 0.5f); | 476 tree.Node(child)->local.Translate(0.5f, 0.5f); |
| 515 tree.Node(child)->needs_local_transform_update = true; | 477 tree.Node(child)->needs_local_transform_update = true; |
| 516 tree.SetTargetId(child, child); | |
| 517 tree.set_needs_update(true); | 478 tree.set_needs_update(true); |
| 518 draw_property_utils::ComputeTransforms(&tree); | 479 draw_property_utils::ComputeTransforms(&tree); |
| 519 EXPECT_TRUE( | 480 EXPECT_TRUE( |
| 520 tree.Node(parent)->node_and_ancestors_have_only_integer_translation); | 481 tree.Node(parent)->node_and_ancestors_have_only_integer_translation); |
| 521 EXPECT_TRUE( | 482 EXPECT_TRUE( |
| 522 tree.Node(child)->node_and_ancestors_have_only_integer_translation); | 483 tree.Node(child)->node_and_ancestors_have_only_integer_translation); |
| 523 } | 484 } |
| 524 | 485 |
| 525 TEST(PropertyTreeTest, SingularTransformSnapTest) { | 486 TEST(PropertyTreeTest, SingularTransformSnapTest) { |
| 526 // This tests that to_target transform is not snapped when it has a singular | 487 // This tests that to_target transform is not snapped when it has a singular |
| 527 // transform. | 488 // transform. |
| 528 PropertyTrees property_trees; | 489 PropertyTrees property_trees; |
| 529 TransformTree& tree = property_trees.transform_tree; | 490 TransformTree& tree = property_trees.transform_tree; |
| 530 EffectTree& effect_tree = property_trees.effect_tree; | 491 EffectTree& effect_tree = property_trees.effect_tree; |
| 531 | 492 |
| 532 int parent = tree.Insert(TransformNode(), 0); | 493 int parent = tree.Insert(TransformNode(), 0); |
| 533 int effect_parent = effect_tree.Insert(EffectNode(), 0); | 494 int effect_parent = effect_tree.Insert(EffectNode(), 0); |
| 534 effect_tree.Node(effect_parent)->has_render_surface = true; | 495 effect_tree.Node(effect_parent)->has_render_surface = true; |
| 535 effect_tree.Node(effect_parent)->surface_contents_scale = | 496 effect_tree.Node(effect_parent)->surface_contents_scale = |
| 536 gfx::Vector2dF(1.f, 1.f); | 497 gfx::Vector2dF(1.f, 1.f); |
| 537 tree.SetTargetId(parent, parent); | |
| 538 tree.Node(parent)->scrolls = true; | 498 tree.Node(parent)->scrolls = true; |
| 539 tree.Node(parent)->source_node_id = 0; | 499 tree.Node(parent)->source_node_id = 0; |
| 540 | 500 |
| 541 int child = tree.Insert(TransformNode(), parent); | 501 int child = tree.Insert(TransformNode(), parent); |
| 542 TransformNode* child_node = tree.Node(child); | 502 TransformNode* child_node = tree.Node(child); |
| 543 tree.SetTargetId(child, parent); | |
| 544 child_node->scrolls = true; | 503 child_node->scrolls = true; |
| 545 child_node->local.Scale3d(6.0f, 6.0f, 0.0f); | 504 child_node->local.Scale3d(6.0f, 6.0f, 0.0f); |
| 546 child_node->local.Translate(1.3f, 1.3f); | 505 child_node->local.Translate(1.3f, 1.3f); |
| 547 child_node->source_node_id = parent; | 506 child_node->source_node_id = parent; |
| 548 tree.set_needs_update(true); | 507 tree.set_needs_update(true); |
| 549 | 508 |
| 550 draw_property_utils::ComputeTransforms(&tree); | 509 draw_property_utils::ComputeTransforms(&tree); |
| 551 property_trees.ResetCachedData(); | 510 property_trees.ResetCachedData(); |
| 552 | 511 |
| 553 gfx::Transform from_target; | 512 gfx::Transform from_target; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 565 | 524 |
| 566 gfx::Transform rounded; | 525 gfx::Transform rounded; |
| 567 property_trees.GetToTarget(child, effect_parent, &rounded); | 526 property_trees.GetToTarget(child, effect_parent, &rounded); |
| 568 rounded.RoundTranslationComponents(); | 527 rounded.RoundTranslationComponents(); |
| 569 property_trees.GetToTarget(child, effect_parent, &to_target); | 528 property_trees.GetToTarget(child, effect_parent, &to_target); |
| 570 EXPECT_NE(to_target, rounded); | 529 EXPECT_NE(to_target, rounded); |
| 571 } | 530 } |
| 572 | 531 |
| 573 } // namespace | 532 } // namespace |
| 574 } // namespace cc | 533 } // namespace cc |
| OLD | NEW |