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