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/proto/property_tree.pb.h" | 8 #include "cc/proto/property_tree.pb.h" |
9 #include "cc/test/geometry_test_utils.h" | 9 #include "cc/test/geometry_test_utils.h" |
| 10 #include "cc/trees/clip_node.h" |
10 #include "cc/trees/draw_property_utils.h" | 11 #include "cc/trees/draw_property_utils.h" |
| 12 #include "cc/trees/effect_node.h" |
| 13 #include "cc/trees/scroll_node.h" |
| 14 #include "cc/trees/transform_node.h" |
11 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
12 | 16 |
13 namespace cc { | 17 namespace cc { |
14 namespace { | 18 namespace { |
15 | 19 |
16 TEST(PropertyTreeSerializationTest, TransformNodeDataSerialization) { | 20 TEST(PropertyTreeSerializationTest, TransformNodeSerialization) { |
17 TransformNodeData original; | 21 TransformNode original; |
| 22 original.id = 3; |
| 23 original.parent_id = 2; |
| 24 original.owner_id = 4; |
18 original.pre_local.Translate3d(1.f, 2.f, 3.f); | 25 original.pre_local.Translate3d(1.f, 2.f, 3.f); |
19 original.local.Translate3d(3.f, 1.f, 5.f); | 26 original.local.Translate3d(3.f, 1.f, 5.f); |
20 original.post_local.Translate3d(1.f, 8.f, 3.f); | 27 original.post_local.Translate3d(1.f, 8.f, 3.f); |
21 original.to_parent.Translate3d(3.2f, 2.f, 3.f); | 28 original.to_parent.Translate3d(3.2f, 2.f, 3.f); |
22 original.source_node_id = 5; | 29 original.source_node_id = 5; |
23 original.needs_local_transform_update = false; | 30 original.needs_local_transform_update = false; |
24 original.is_invertible = false; | 31 original.is_invertible = false; |
25 original.ancestors_are_invertible = false; | 32 original.ancestors_are_invertible = false; |
26 original.has_potential_animation = false; | 33 original.has_potential_animation = false; |
27 original.to_screen_is_potentially_animated = false; | 34 original.to_screen_is_potentially_animated = false; |
(...skipping 10 matching lines...) Expand all Loading... |
38 original.in_subtree_of_page_scale_layer = false; | 45 original.in_subtree_of_page_scale_layer = false; |
39 original.post_local_scale_factor = 0.5f; | 46 original.post_local_scale_factor = 0.5f; |
40 original.sublayer_scale = gfx::Vector2dF(0.5f, 0.5f); | 47 original.sublayer_scale = gfx::Vector2dF(0.5f, 0.5f); |
41 original.scroll_offset = gfx::ScrollOffset(1.5f, 1.5f); | 48 original.scroll_offset = gfx::ScrollOffset(1.5f, 1.5f); |
42 original.scroll_snap = gfx::Vector2dF(0.4f, 0.4f); | 49 original.scroll_snap = gfx::Vector2dF(0.4f, 0.4f); |
43 original.source_offset = gfx::Vector2dF(2.5f, 2.4f); | 50 original.source_offset = gfx::Vector2dF(2.5f, 2.4f); |
44 original.source_to_parent = gfx::Vector2dF(3.2f, 3.2f); | 51 original.source_to_parent = gfx::Vector2dF(3.2f, 3.2f); |
45 | 52 |
46 proto::TreeNode proto; | 53 proto::TreeNode proto; |
47 original.ToProtobuf(&proto); | 54 original.ToProtobuf(&proto); |
48 TransformNodeData result; | |
49 result.FromProtobuf(proto); | |
50 | |
51 EXPECT_EQ(original, result); | |
52 } | |
53 | |
54 TEST(PropertyTreeSerializationTest, TransformNodeSerialization) { | |
55 TransformNode original; | |
56 original.id = 3; | |
57 original.parent_id = 2; | |
58 original.owner_id = 4; | |
59 | |
60 proto::TreeNode proto; | |
61 original.ToProtobuf(&proto); | |
62 TransformNode result; | 55 TransformNode result; |
63 result.FromProtobuf(proto); | 56 result.FromProtobuf(proto); |
64 | 57 |
65 EXPECT_EQ(original, result); | 58 EXPECT_EQ(original, result); |
66 } | 59 } |
67 | 60 |
68 TEST(PropertyTreeSerializationTest, TransformTreeSerialization) { | 61 TEST(PropertyTreeSerializationTest, TransformTreeSerialization) { |
69 PropertyTrees property_trees; | 62 PropertyTrees property_trees; |
70 TransformTree& original = property_trees.transform_tree; | 63 TransformTree& original = property_trees.transform_tree; |
71 TransformNode& root = *original.Node(0); | 64 TransformNode& root = *original.Node(0); |
72 root.id = 0; | 65 root.id = 0; |
73 root.owner_id = 1; | 66 root.owner_id = 1; |
74 original.SetTargetId(root.id, 3); | 67 original.SetTargetId(root.id, 3); |
75 original.SetContentTargetId(root.id, 4); | 68 original.SetContentTargetId(root.id, 4); |
76 TransformNode second; | 69 TransformNode second; |
77 second.owner_id = 2; | 70 second.owner_id = 2; |
78 second.data.local.Translate3d(2.f, 2.f, 0.f); | 71 second.local.Translate3d(2.f, 2.f, 0.f); |
79 second.data.source_node_id = 0; | 72 second.source_node_id = 0; |
80 second.id = original.Insert(second, 0); | 73 second.id = original.Insert(second, 0); |
81 original.SetTargetId(second.id, 0); | 74 original.SetTargetId(second.id, 0); |
82 TransformNode third; | 75 TransformNode third; |
83 third.owner_id = 3; | 76 third.owner_id = 3; |
84 third.data.scrolls = true; | 77 third.scrolls = true; |
85 third.data.source_node_id = 1; | 78 third.source_node_id = 1; |
86 third.id = original.Insert(third, 1); | 79 third.id = original.Insert(third, 1); |
87 original.SetTargetId(third.id, 0); | 80 original.SetTargetId(third.id, 0); |
88 | 81 |
89 original.set_needs_update(true); | 82 original.set_needs_update(true); |
90 | 83 |
91 original.set_page_scale_factor(0.5f); | 84 original.set_page_scale_factor(0.5f); |
92 original.set_device_scale_factor(0.6f); | 85 original.set_device_scale_factor(0.6f); |
93 gfx::Transform transform = | 86 gfx::Transform transform = |
94 gfx::Transform(1.05f, 2.15f, 3.14f, 4.13f, 5.12f, 6.11f, 7.1f, 8.9f, 9.8f, | 87 gfx::Transform(1.05f, 2.15f, 3.14f, 4.13f, 5.12f, 6.11f, 7.1f, 8.9f, 9.8f, |
95 10.7f, 11.6f, 12.5f, 13.4f, 14.3f, 15.2f, 16.1f); | 88 10.7f, 11.6f, 12.5f, 13.4f, 14.3f, 15.2f, 16.1f); |
96 original.SetDeviceTransformScaleFactor(transform); | 89 original.SetDeviceTransformScaleFactor(transform); |
97 original.AddNodeAffectedByInnerViewportBoundsDelta(0); | 90 original.AddNodeAffectedByInnerViewportBoundsDelta(0); |
98 original.AddNodeAffectedByOuterViewportBoundsDelta(1); | 91 original.AddNodeAffectedByOuterViewportBoundsDelta(1); |
99 | 92 |
100 proto::PropertyTree proto; | 93 proto::PropertyTree proto; |
101 original.ToProtobuf(&proto); | 94 original.ToProtobuf(&proto); |
102 TransformTree result; | 95 TransformTree result; |
103 std::unordered_map<int, int> transform_id_to_index_map; | 96 std::unordered_map<int, int> transform_id_to_index_map; |
104 result.FromProtobuf(proto, &transform_id_to_index_map); | 97 result.FromProtobuf(proto, &transform_id_to_index_map); |
105 | 98 |
106 EXPECT_EQ(transform_id_to_index_map[1], 0); | 99 EXPECT_EQ(transform_id_to_index_map[1], 0); |
107 EXPECT_EQ(transform_id_to_index_map[2], 1); | 100 EXPECT_EQ(transform_id_to_index_map[2], 1); |
108 EXPECT_EQ(transform_id_to_index_map[3], 2); | 101 EXPECT_EQ(transform_id_to_index_map[3], 2); |
109 EXPECT_EQ(original, result); | 102 EXPECT_EQ(original, result); |
110 } | 103 } |
111 | 104 |
112 TEST(PropertyTreeSerializationTest, ClipNodeDataSerialization) { | 105 TEST(PropertyTreeSerializationTest, ClipNodeSerialization) { |
113 ClipNodeData original; | 106 ClipNode original; |
| 107 original.id = 3; |
| 108 original.parent_id = 2; |
| 109 original.owner_id = 4; |
114 original.clip = gfx::RectF(0.5f, 0.5f); | 110 original.clip = gfx::RectF(0.5f, 0.5f); |
115 original.combined_clip_in_target_space = gfx::RectF(0.6f, 0.6f); | 111 original.combined_clip_in_target_space = gfx::RectF(0.6f, 0.6f); |
116 original.clip_in_target_space = gfx::RectF(0.7f, 0.7f); | 112 original.clip_in_target_space = gfx::RectF(0.7f, 0.7f); |
117 original.transform_id = 2; | 113 original.transform_id = 2; |
118 original.target_id = 3; | 114 original.target_id = 3; |
119 original.applies_local_clip = false; | 115 original.applies_local_clip = false; |
120 original.layer_clipping_uses_only_local_clip = false; | 116 original.layer_clipping_uses_only_local_clip = false; |
121 original.target_is_clipped = false; | 117 original.target_is_clipped = false; |
122 original.layers_are_clipped = false; | 118 original.layers_are_clipped = false; |
123 original.layers_are_clipped_when_surfaces_disabled = false; | 119 original.layers_are_clipped_when_surfaces_disabled = false; |
124 original.resets_clip = false; | 120 original.resets_clip = false; |
125 | 121 |
126 proto::TreeNode proto; | 122 proto::TreeNode proto; |
127 original.ToProtobuf(&proto); | 123 original.ToProtobuf(&proto); |
128 ClipNodeData result; | |
129 result.FromProtobuf(proto); | |
130 | |
131 EXPECT_EQ(original, result); | |
132 } | |
133 | |
134 TEST(PropertyTreeSerializationTest, ClipNodeSerialization) { | |
135 ClipNode original; | |
136 original.id = 3; | |
137 original.parent_id = 2; | |
138 original.owner_id = 4; | |
139 | |
140 proto::TreeNode proto; | |
141 original.ToProtobuf(&proto); | |
142 ClipNode result; | 124 ClipNode result; |
143 result.FromProtobuf(proto); | 125 result.FromProtobuf(proto); |
144 | 126 |
145 EXPECT_EQ(original, result); | 127 EXPECT_EQ(original, result); |
146 } | 128 } |
147 | 129 |
148 TEST(PropertyTreeSerializationTest, ClipTreeSerialization) { | 130 TEST(PropertyTreeSerializationTest, ClipTreeSerialization) { |
149 ClipTree original; | 131 ClipTree original; |
150 ClipNode& root = *original.Node(0); | 132 ClipNode& root = *original.Node(0); |
151 root.owner_id = 1; | 133 root.owner_id = 1; |
152 root.data.transform_id = 2; | 134 root.transform_id = 2; |
153 root.data.target_id = 1; | 135 root.target_id = 1; |
154 ClipNode second; | 136 ClipNode second; |
155 second.owner_id = 2; | 137 second.owner_id = 2; |
156 second.data.transform_id = 4; | 138 second.transform_id = 4; |
157 second.data.applies_local_clip = true; | 139 second.applies_local_clip = true; |
158 ClipNode third; | 140 ClipNode third; |
159 third.owner_id = 3; | 141 third.owner_id = 3; |
160 third.data.target_id = 3; | 142 third.target_id = 3; |
161 third.data.target_is_clipped = false; | 143 third.target_is_clipped = false; |
162 | 144 |
163 original.Insert(second, 0); | 145 original.Insert(second, 0); |
164 original.Insert(third, 1); | 146 original.Insert(third, 1); |
165 original.set_needs_update(true); | 147 original.set_needs_update(true); |
166 | 148 |
167 proto::PropertyTree proto; | 149 proto::PropertyTree proto; |
168 original.ToProtobuf(&proto); | 150 original.ToProtobuf(&proto); |
169 ClipTree result; | 151 ClipTree result; |
170 std::unordered_map<int, int> clip_id_to_index_map; | 152 std::unordered_map<int, int> clip_id_to_index_map; |
171 result.FromProtobuf(proto, &clip_id_to_index_map); | 153 result.FromProtobuf(proto, &clip_id_to_index_map); |
172 | 154 |
173 EXPECT_EQ(clip_id_to_index_map[1], 0); | 155 EXPECT_EQ(clip_id_to_index_map[1], 0); |
174 EXPECT_EQ(clip_id_to_index_map[2], 1); | 156 EXPECT_EQ(clip_id_to_index_map[2], 1); |
175 EXPECT_EQ(clip_id_to_index_map[3], 2); | 157 EXPECT_EQ(clip_id_to_index_map[3], 2); |
176 EXPECT_EQ(original, result); | 158 EXPECT_EQ(original, result); |
177 } | 159 } |
178 | 160 |
179 TEST(PropertyTreeSerializationTest, EffectNodeDataSerialization) { | 161 TEST(PropertyTreeSerializationTest, EffectNodeSerialization) { |
180 EffectNodeData original; | 162 EffectNode original; |
| 163 original.id = 3; |
| 164 original.parent_id = 2; |
| 165 original.owner_id = 4; |
181 original.opacity = 0.5f; | 166 original.opacity = 0.5f; |
182 original.screen_space_opacity = 0.6f; | 167 original.screen_space_opacity = 0.6f; |
183 original.has_render_surface = false; | 168 original.has_render_surface = false; |
184 original.transform_id = 2; | 169 original.transform_id = 2; |
185 original.clip_id = 3; | 170 original.clip_id = 3; |
186 original.mask_layer_id = 6; | 171 original.mask_layer_id = 6; |
187 original.replica_layer_id = 10; | 172 original.replica_layer_id = 10; |
188 original.replica_mask_layer_id = 9; | 173 original.replica_mask_layer_id = 9; |
189 original.sublayer_scale = gfx::Vector2dF(0.5f, 0.5f); | 174 original.sublayer_scale = gfx::Vector2dF(0.5f, 0.5f); |
190 | 175 |
191 proto::TreeNode proto; | 176 proto::TreeNode proto; |
192 original.ToProtobuf(&proto); | 177 original.ToProtobuf(&proto); |
193 EffectNodeData result; | |
194 result.FromProtobuf(proto); | |
195 | |
196 EXPECT_EQ(original, result); | |
197 } | |
198 | |
199 TEST(PropertyTreeSerializationTest, EffectNodeSerialization) { | |
200 EffectNode original; | |
201 original.id = 3; | |
202 original.parent_id = 2; | |
203 original.owner_id = 4; | |
204 | |
205 proto::TreeNode proto; | |
206 original.ToProtobuf(&proto); | |
207 EffectNode result; | 178 EffectNode result; |
208 result.FromProtobuf(proto); | 179 result.FromProtobuf(proto); |
209 | 180 |
210 EXPECT_EQ(original, result); | 181 EXPECT_EQ(original, result); |
211 } | 182 } |
212 | 183 |
213 TEST(PropertyTreeSerializationTest, EffectTreeSerialization) { | 184 TEST(PropertyTreeSerializationTest, EffectTreeSerialization) { |
214 EffectTree original; | 185 EffectTree original; |
215 EffectNode& root = *original.Node(0); | 186 EffectNode& root = *original.Node(0); |
216 root.owner_id = 5; | 187 root.owner_id = 5; |
217 root.data.transform_id = 2; | 188 root.transform_id = 2; |
218 root.data.clip_id = 1; | 189 root.clip_id = 1; |
219 EffectNode second; | 190 EffectNode second; |
220 second.owner_id = 6; | 191 second.owner_id = 6; |
221 second.data.transform_id = 4; | 192 second.transform_id = 4; |
222 second.data.opacity = true; | 193 second.opacity = true; |
223 second.data.mask_layer_id = 32; | 194 second.mask_layer_id = 32; |
224 EffectNode third; | 195 EffectNode third; |
225 third.owner_id = 7; | 196 third.owner_id = 7; |
226 third.data.clip_id = 3; | 197 third.clip_id = 3; |
227 third.data.replica_layer_id = 44; | 198 third.replica_layer_id = 44; |
228 third.data.replica_mask_layer_id = 45; | 199 third.replica_mask_layer_id = 45; |
229 third.data.has_render_surface = false; | 200 third.has_render_surface = false; |
230 | 201 |
231 original.Insert(second, 0); | 202 original.Insert(second, 0); |
232 original.Insert(third, 1); | 203 original.Insert(third, 1); |
233 original.AddMaskOrReplicaLayerId(32); | 204 original.AddMaskOrReplicaLayerId(32); |
234 original.AddMaskOrReplicaLayerId(44); | 205 original.AddMaskOrReplicaLayerId(44); |
235 original.AddMaskOrReplicaLayerId(45); | 206 original.AddMaskOrReplicaLayerId(45); |
236 original.set_needs_update(true); | 207 original.set_needs_update(true); |
237 | 208 |
238 proto::PropertyTree proto; | 209 proto::PropertyTree proto; |
239 original.ToProtobuf(&proto); | 210 original.ToProtobuf(&proto); |
240 EffectTree result; | 211 EffectTree result; |
241 std::unordered_map<int, int> effect_id_to_index_map; | 212 std::unordered_map<int, int> effect_id_to_index_map; |
242 result.FromProtobuf(proto, &effect_id_to_index_map); | 213 result.FromProtobuf(proto, &effect_id_to_index_map); |
243 | 214 |
244 EXPECT_EQ(effect_id_to_index_map[5], 0); | 215 EXPECT_EQ(effect_id_to_index_map[5], 0); |
245 EXPECT_EQ(effect_id_to_index_map[6], 1); | 216 EXPECT_EQ(effect_id_to_index_map[6], 1); |
246 EXPECT_EQ(effect_id_to_index_map[7], 2); | 217 EXPECT_EQ(effect_id_to_index_map[7], 2); |
247 EXPECT_EQ(original, result); | 218 EXPECT_EQ(original, result); |
248 } | 219 } |
249 | 220 |
250 TEST(PropertyTreeSerializationTest, ScrollNodeDataSerialization) { | 221 TEST(PropertyTreeSerializationTest, ScrollNodeSerialization) { |
251 ScrollNodeData original; | 222 ScrollNode original; |
| 223 original.id = 3; |
| 224 original.parent_id = 2; |
| 225 original.owner_id = 4; |
252 original.scrollable = true; | 226 original.scrollable = true; |
253 original.main_thread_scrolling_reasons = | 227 original.main_thread_scrolling_reasons = |
254 MainThreadScrollingReason::kScrollbarScrolling; | 228 MainThreadScrollingReason::kScrollbarScrolling; |
255 original.contains_non_fast_scrollable_region = false; | 229 original.contains_non_fast_scrollable_region = false; |
256 original.scroll_clip_layer_bounds = gfx::Size(10, 10); | 230 original.scroll_clip_layer_bounds = gfx::Size(10, 10); |
257 original.bounds = gfx::Size(15, 15); | 231 original.bounds = gfx::Size(15, 15); |
258 original.max_scroll_offset_affected_by_page_scale = true; | 232 original.max_scroll_offset_affected_by_page_scale = true; |
259 original.is_inner_viewport_scroll_layer = true; | 233 original.is_inner_viewport_scroll_layer = true; |
260 original.is_outer_viewport_scroll_layer = false; | 234 original.is_outer_viewport_scroll_layer = false; |
261 | 235 |
262 proto::TreeNode proto; | 236 proto::TreeNode proto; |
263 original.ToProtobuf(&proto); | 237 original.ToProtobuf(&proto); |
264 ScrollNodeData result; | |
265 result.FromProtobuf(proto); | |
266 | |
267 EXPECT_EQ(original, result); | |
268 } | |
269 | |
270 TEST(PropertyTreeSerializationTest, ScrollNodeSerialization) { | |
271 ScrollNode original; | |
272 original.id = 3; | |
273 original.parent_id = 2; | |
274 original.owner_id = 4; | |
275 | |
276 proto::TreeNode proto; | |
277 original.ToProtobuf(&proto); | |
278 ScrollNode result; | 238 ScrollNode result; |
279 result.FromProtobuf(proto); | 239 result.FromProtobuf(proto); |
280 | 240 |
281 EXPECT_EQ(original, result); | 241 EXPECT_EQ(original, result); |
282 } | 242 } |
283 | 243 |
284 TEST(PropertyTreeSerializationTest, ScrollTreeSerialization) { | 244 TEST(PropertyTreeSerializationTest, ScrollTreeSerialization) { |
285 PropertyTrees property_trees; | 245 PropertyTrees property_trees; |
286 property_trees.is_main_thread = true; | 246 property_trees.is_main_thread = true; |
287 ScrollTree& original = property_trees.scroll_tree; | 247 ScrollTree& original = property_trees.scroll_tree; |
288 ScrollNode second; | 248 ScrollNode second; |
289 second.owner_id = 10; | 249 second.owner_id = 10; |
290 second.data.scrollable = true; | 250 second.scrollable = true; |
291 second.data.bounds = gfx::Size(15, 15); | 251 second.bounds = gfx::Size(15, 15); |
292 ScrollNode third; | 252 ScrollNode third; |
293 third.owner_id = 20; | 253 third.owner_id = 20; |
294 third.data.contains_non_fast_scrollable_region = true; | 254 third.contains_non_fast_scrollable_region = true; |
295 | 255 |
296 original.Insert(second, 0); | 256 original.Insert(second, 0); |
297 original.Insert(third, 1); | 257 original.Insert(third, 1); |
298 | 258 |
299 original.set_currently_scrolling_node(1); | 259 original.set_currently_scrolling_node(1); |
300 original.SetScrollOffset(1, gfx::ScrollOffset(1, 2)); | 260 original.SetScrollOffset(1, gfx::ScrollOffset(1, 2)); |
301 | 261 |
302 proto::PropertyTree proto; | 262 proto::PropertyTree proto; |
303 original.ToProtobuf(&proto); | 263 original.ToProtobuf(&proto); |
304 ScrollTree result; | 264 ScrollTree result; |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
428 DIRECT_PROPERTY_TREE_TEST_F(TEST_FIXTURE_NAME); \ | 388 DIRECT_PROPERTY_TREE_TEST_F(TEST_FIXTURE_NAME); \ |
429 SERIALIZED_PROPERTY_TREE_TEST_F(TEST_FIXTURE_NAME) | 389 SERIALIZED_PROPERTY_TREE_TEST_F(TEST_FIXTURE_NAME) |
430 | 390 |
431 class PropertyTreeTestComputeTransformRoot : public PropertyTreeTest { | 391 class PropertyTreeTestComputeTransformRoot : public PropertyTreeTest { |
432 protected: | 392 protected: |
433 void StartTest() override { | 393 void StartTest() override { |
434 PropertyTrees property_trees; | 394 PropertyTrees property_trees; |
435 TransformTree& tree = property_trees.transform_tree; | 395 TransformTree& tree = property_trees.transform_tree; |
436 TransformNode& root = *tree.Node(0); | 396 TransformNode& root = *tree.Node(0); |
437 root.id = 0; | 397 root.id = 0; |
438 root.data.local.Translate(2, 2); | 398 root.local.Translate(2, 2); |
439 tree.SetTargetId(root.id, 0); | 399 tree.SetTargetId(root.id, 0); |
440 SetupTransformTreeForTest(&tree); | 400 SetupTransformTreeForTest(&tree); |
441 tree.UpdateTransforms(0); | 401 tree.UpdateTransforms(0); |
442 | 402 |
443 gfx::Transform expected; | 403 gfx::Transform expected; |
444 gfx::Transform transform; | 404 gfx::Transform transform; |
445 bool success = tree.ComputeTransform(0, 0, &transform); | 405 bool success = tree.ComputeTransform(0, 0, &transform); |
446 EXPECT_TRUE(success); | 406 EXPECT_TRUE(success); |
447 EXPECT_TRANSFORMATION_MATRIX_EQ(expected, transform); | 407 EXPECT_TRANSFORMATION_MATRIX_EQ(expected, transform); |
448 | 408 |
(...skipping 14 matching lines...) Expand all Loading... |
463 | 423 |
464 DIRECT_AND_SERIALIZED_PROPERTY_TREE_TEST_F( | 424 DIRECT_AND_SERIALIZED_PROPERTY_TREE_TEST_F( |
465 PropertyTreeTestComputeTransformRoot); | 425 PropertyTreeTestComputeTransformRoot); |
466 | 426 |
467 class PropertyTreeTestComputeTransformChild : public PropertyTreeTest { | 427 class PropertyTreeTestComputeTransformChild : public PropertyTreeTest { |
468 protected: | 428 protected: |
469 void StartTest() override { | 429 void StartTest() override { |
470 PropertyTrees property_trees; | 430 PropertyTrees property_trees; |
471 TransformTree& tree = property_trees.transform_tree; | 431 TransformTree& tree = property_trees.transform_tree; |
472 TransformNode& root = *tree.Node(0); | 432 TransformNode& root = *tree.Node(0); |
473 root.data.local.Translate(2, 2); | 433 root.local.Translate(2, 2); |
474 tree.SetTargetId(root.id, 0); | 434 tree.SetTargetId(root.id, 0); |
475 tree.UpdateTransforms(0); | 435 tree.UpdateTransforms(0); |
476 | 436 |
477 TransformNode child; | 437 TransformNode child; |
478 child.data.local.Translate(3, 3); | 438 child.local.Translate(3, 3); |
479 child.data.source_node_id = 0; | 439 child.source_node_id = 0; |
480 child.id = tree.Insert(child, 0); | 440 child.id = tree.Insert(child, 0); |
481 tree.SetTargetId(child.id, 0); | 441 tree.SetTargetId(child.id, 0); |
482 | 442 |
483 SetupTransformTreeForTest(&tree); | 443 SetupTransformTreeForTest(&tree); |
484 tree.UpdateTransforms(1); | 444 tree.UpdateTransforms(1); |
485 | 445 |
486 gfx::Transform expected; | 446 gfx::Transform expected; |
487 gfx::Transform transform; | 447 gfx::Transform transform; |
488 | 448 |
489 expected.Translate(3, 3); | 449 expected.Translate(3, 3); |
(...skipping 26 matching lines...) Expand all Loading... |
516 | 476 |
517 DIRECT_AND_SERIALIZED_PROPERTY_TREE_TEST_F( | 477 DIRECT_AND_SERIALIZED_PROPERTY_TREE_TEST_F( |
518 PropertyTreeTestComputeTransformChild); | 478 PropertyTreeTestComputeTransformChild); |
519 | 479 |
520 class PropertyTreeTestComputeTransformSibling : public PropertyTreeTest { | 480 class PropertyTreeTestComputeTransformSibling : public PropertyTreeTest { |
521 protected: | 481 protected: |
522 void StartTest() override { | 482 void StartTest() override { |
523 PropertyTrees property_trees; | 483 PropertyTrees property_trees; |
524 TransformTree& tree = property_trees.transform_tree; | 484 TransformTree& tree = property_trees.transform_tree; |
525 TransformNode& root = *tree.Node(0); | 485 TransformNode& root = *tree.Node(0); |
526 root.data.local.Translate(2, 2); | 486 root.local.Translate(2, 2); |
527 tree.SetTargetId(root.id, 0); | 487 tree.SetTargetId(root.id, 0); |
528 tree.UpdateTransforms(0); | 488 tree.UpdateTransforms(0); |
529 | 489 |
530 TransformNode child; | 490 TransformNode child; |
531 child.data.local.Translate(3, 3); | 491 child.local.Translate(3, 3); |
532 child.data.source_node_id = 0; | 492 child.source_node_id = 0; |
533 child.id = tree.Insert(child, 0); | 493 child.id = tree.Insert(child, 0); |
534 tree.SetTargetId(child.id, 0); | 494 tree.SetTargetId(child.id, 0); |
535 | 495 |
536 TransformNode sibling; | 496 TransformNode sibling; |
537 sibling.data.local.Translate(7, 7); | 497 sibling.local.Translate(7, 7); |
538 sibling.data.source_node_id = 0; | 498 sibling.source_node_id = 0; |
539 sibling.id = tree.Insert(sibling, 0); | 499 sibling.id = tree.Insert(sibling, 0); |
540 tree.SetTargetId(sibling.id, 0); | 500 tree.SetTargetId(sibling.id, 0); |
541 | 501 |
542 SetupTransformTreeForTest(&tree); | 502 SetupTransformTreeForTest(&tree); |
543 | 503 |
544 tree.UpdateTransforms(1); | 504 tree.UpdateTransforms(1); |
545 tree.UpdateTransforms(2); | 505 tree.UpdateTransforms(2); |
546 | 506 |
547 gfx::Transform expected; | 507 gfx::Transform expected; |
548 gfx::Transform transform; | 508 gfx::Transform transform; |
(...skipping 24 matching lines...) Expand all Loading... |
573 // + singular | 533 // + singular |
574 // + child | 534 // + child |
575 // + sibling | 535 // + sibling |
576 // Since the lowest common ancestor of |child| and |sibling| has a singular | 536 // Since the lowest common ancestor of |child| and |sibling| has a singular |
577 // transform, we cannot use screen space transforms to compute change of | 537 // transform, we cannot use screen space transforms to compute change of |
578 // basis | 538 // basis |
579 // transforms between these nodes. | 539 // transforms between these nodes. |
580 PropertyTrees property_trees; | 540 PropertyTrees property_trees; |
581 TransformTree& tree = property_trees.transform_tree; | 541 TransformTree& tree = property_trees.transform_tree; |
582 TransformNode& root = *tree.Node(0); | 542 TransformNode& root = *tree.Node(0); |
583 root.data.local.Translate(2, 2); | 543 root.local.Translate(2, 2); |
584 tree.SetTargetId(root.id, 0); | 544 tree.SetTargetId(root.id, 0); |
585 tree.UpdateTransforms(0); | 545 tree.UpdateTransforms(0); |
586 | 546 |
587 TransformNode singular; | 547 TransformNode singular; |
588 singular.data.local.matrix().set(2, 2, 0.0); | 548 singular.local.matrix().set(2, 2, 0.0); |
589 singular.data.source_node_id = 0; | 549 singular.source_node_id = 0; |
590 singular.id = tree.Insert(singular, 0); | 550 singular.id = tree.Insert(singular, 0); |
591 tree.SetTargetId(singular.id, 0); | 551 tree.SetTargetId(singular.id, 0); |
592 | 552 |
593 TransformNode child; | 553 TransformNode child; |
594 child.data.local.Translate(3, 3); | 554 child.local.Translate(3, 3); |
595 child.data.source_node_id = 1; | 555 child.source_node_id = 1; |
596 child.id = tree.Insert(child, 1); | 556 child.id = tree.Insert(child, 1); |
597 tree.SetTargetId(child.id, 0); | 557 tree.SetTargetId(child.id, 0); |
598 | 558 |
599 TransformNode sibling; | 559 TransformNode sibling; |
600 sibling.data.local.Translate(7, 7); | 560 sibling.local.Translate(7, 7); |
601 sibling.data.source_node_id = 1; | 561 sibling.source_node_id = 1; |
602 sibling.id = tree.Insert(sibling, 1); | 562 sibling.id = tree.Insert(sibling, 1); |
603 tree.SetTargetId(sibling.id, 0); | 563 tree.SetTargetId(sibling.id, 0); |
604 | 564 |
605 SetupTransformTreeForTest(&tree); | 565 SetupTransformTreeForTest(&tree); |
606 | 566 |
607 tree.UpdateTransforms(1); | 567 tree.UpdateTransforms(1); |
608 tree.UpdateTransforms(2); | 568 tree.UpdateTransforms(2); |
609 tree.UpdateTransforms(3); | 569 tree.UpdateTransforms(3); |
610 | 570 |
611 gfx::Transform expected; | 571 gfx::Transform expected; |
(...skipping 18 matching lines...) Expand all Loading... |
630 | 590 |
631 class PropertyTreeTestTransformsWithFlattening : public PropertyTreeTest { | 591 class PropertyTreeTestTransformsWithFlattening : public PropertyTreeTest { |
632 protected: | 592 protected: |
633 void StartTest() override { | 593 void StartTest() override { |
634 PropertyTrees property_trees; | 594 PropertyTrees property_trees; |
635 TransformTree& tree = property_trees.transform_tree; | 595 TransformTree& tree = property_trees.transform_tree; |
636 | 596 |
637 int grand_parent = tree.Insert(TransformNode(), 0); | 597 int grand_parent = tree.Insert(TransformNode(), 0); |
638 tree.SetContentTargetId(grand_parent, grand_parent); | 598 tree.SetContentTargetId(grand_parent, grand_parent); |
639 tree.SetTargetId(grand_parent, grand_parent); | 599 tree.SetTargetId(grand_parent, grand_parent); |
640 tree.Node(grand_parent)->data.source_node_id = 0; | 600 tree.Node(grand_parent)->source_node_id = 0; |
641 | 601 |
642 gfx::Transform rotation_about_x; | 602 gfx::Transform rotation_about_x; |
643 rotation_about_x.RotateAboutXAxis(15); | 603 rotation_about_x.RotateAboutXAxis(15); |
644 | 604 |
645 int parent = tree.Insert(TransformNode(), grand_parent); | 605 int parent = tree.Insert(TransformNode(), grand_parent); |
646 tree.Node(parent)->data.needs_sublayer_scale = true; | 606 tree.Node(parent)->needs_sublayer_scale = true; |
647 tree.SetTargetId(parent, grand_parent); | 607 tree.SetTargetId(parent, grand_parent); |
648 tree.SetContentTargetId(parent, parent); | 608 tree.SetContentTargetId(parent, parent); |
649 tree.Node(parent)->data.source_node_id = grand_parent; | 609 tree.Node(parent)->source_node_id = grand_parent; |
650 tree.Node(parent)->data.local = rotation_about_x; | 610 tree.Node(parent)->local = rotation_about_x; |
651 | 611 |
652 int child = tree.Insert(TransformNode(), parent); | 612 int child = tree.Insert(TransformNode(), parent); |
653 tree.SetTargetId(child, parent); | 613 tree.SetTargetId(child, parent); |
654 tree.SetContentTargetId(child, parent); | 614 tree.SetContentTargetId(child, parent); |
655 tree.Node(child)->data.source_node_id = parent; | 615 tree.Node(child)->source_node_id = parent; |
656 tree.Node(child)->data.flattens_inherited_transform = true; | 616 tree.Node(child)->flattens_inherited_transform = true; |
657 tree.Node(child)->data.local = rotation_about_x; | 617 tree.Node(child)->local = rotation_about_x; |
658 | 618 |
659 int grand_child = tree.Insert(TransformNode(), child); | 619 int grand_child = tree.Insert(TransformNode(), child); |
660 tree.SetTargetId(grand_child, parent); | 620 tree.SetTargetId(grand_child, parent); |
661 tree.SetContentTargetId(grand_child, parent); | 621 tree.SetContentTargetId(grand_child, parent); |
662 tree.Node(grand_child)->data.source_node_id = child; | 622 tree.Node(grand_child)->source_node_id = child; |
663 tree.Node(grand_child)->data.flattens_inherited_transform = true; | 623 tree.Node(grand_child)->flattens_inherited_transform = true; |
664 tree.Node(grand_child)->data.local = rotation_about_x; | 624 tree.Node(grand_child)->local = rotation_about_x; |
665 | 625 |
666 tree.set_needs_update(true); | 626 tree.set_needs_update(true); |
667 SetupTransformTreeForTest(&tree); | 627 SetupTransformTreeForTest(&tree); |
668 draw_property_utils::ComputeTransforms(&tree); | 628 draw_property_utils::ComputeTransforms(&tree); |
669 | 629 |
670 gfx::Transform flattened_rotation_about_x = rotation_about_x; | 630 gfx::Transform flattened_rotation_about_x = rotation_about_x; |
671 flattened_rotation_about_x.FlattenTo2d(); | 631 flattened_rotation_about_x.FlattenTo2d(); |
672 | 632 |
673 EXPECT_TRANSFORMATION_MATRIX_EQ(rotation_about_x, tree.ToTarget(child)); | 633 EXPECT_TRANSFORMATION_MATRIX_EQ(rotation_about_x, tree.ToTarget(child)); |
674 | 634 |
675 EXPECT_TRANSFORMATION_MATRIX_EQ( | 635 EXPECT_TRANSFORMATION_MATRIX_EQ( |
676 flattened_rotation_about_x * rotation_about_x, tree.ToScreen(child)); | 636 flattened_rotation_about_x * rotation_about_x, tree.ToScreen(child)); |
677 | 637 |
678 EXPECT_TRANSFORMATION_MATRIX_EQ( | 638 EXPECT_TRANSFORMATION_MATRIX_EQ( |
679 flattened_rotation_about_x * rotation_about_x, | 639 flattened_rotation_about_x * rotation_about_x, |
680 tree.ToTarget(grand_child)); | 640 tree.ToTarget(grand_child)); |
681 | 641 |
682 EXPECT_TRANSFORMATION_MATRIX_EQ(flattened_rotation_about_x * | 642 EXPECT_TRANSFORMATION_MATRIX_EQ(flattened_rotation_about_x * |
683 flattened_rotation_about_x * | 643 flattened_rotation_about_x * |
684 rotation_about_x, | 644 rotation_about_x, |
685 tree.ToScreen(grand_child)); | 645 tree.ToScreen(grand_child)); |
686 | 646 |
687 gfx::Transform grand_child_to_child; | 647 gfx::Transform grand_child_to_child; |
688 bool success = | 648 bool success = |
689 tree.ComputeTransform(grand_child, child, &grand_child_to_child); | 649 tree.ComputeTransform(grand_child, child, &grand_child_to_child); |
690 EXPECT_TRUE(success); | 650 EXPECT_TRUE(success); |
691 EXPECT_TRANSFORMATION_MATRIX_EQ(rotation_about_x, grand_child_to_child); | 651 EXPECT_TRANSFORMATION_MATRIX_EQ(rotation_about_x, grand_child_to_child); |
692 | 652 |
693 // Remove flattening at grand_child, and recompute transforms. | 653 // Remove flattening at grand_child, and recompute transforms. |
694 tree.Node(grand_child)->data.flattens_inherited_transform = false; | 654 tree.Node(grand_child)->flattens_inherited_transform = false; |
695 tree.set_needs_update(true); | 655 tree.set_needs_update(true); |
696 SetupTransformTreeForTest(&tree); | 656 SetupTransformTreeForTest(&tree); |
697 draw_property_utils::ComputeTransforms(&tree); | 657 draw_property_utils::ComputeTransforms(&tree); |
698 | 658 |
699 EXPECT_TRANSFORMATION_MATRIX_EQ(rotation_about_x * rotation_about_x, | 659 EXPECT_TRANSFORMATION_MATRIX_EQ(rotation_about_x * rotation_about_x, |
700 tree.ToTarget(grand_child)); | 660 tree.ToTarget(grand_child)); |
701 | 661 |
702 EXPECT_TRANSFORMATION_MATRIX_EQ( | 662 EXPECT_TRANSFORMATION_MATRIX_EQ( |
703 flattened_rotation_about_x * rotation_about_x * rotation_about_x, | 663 flattened_rotation_about_x * rotation_about_x * rotation_about_x, |
704 tree.ToScreen(grand_child)); | 664 tree.ToScreen(grand_child)); |
705 | 665 |
706 success = tree.ComputeTransform(grand_child, child, &grand_child_to_child); | 666 success = tree.ComputeTransform(grand_child, child, &grand_child_to_child); |
707 EXPECT_TRUE(success); | 667 EXPECT_TRUE(success); |
708 EXPECT_TRANSFORMATION_MATRIX_EQ(rotation_about_x, grand_child_to_child); | 668 EXPECT_TRANSFORMATION_MATRIX_EQ(rotation_about_x, grand_child_to_child); |
709 } | 669 } |
710 }; | 670 }; |
711 | 671 |
712 DIRECT_AND_SERIALIZED_PROPERTY_TREE_TEST_F( | 672 DIRECT_AND_SERIALIZED_PROPERTY_TREE_TEST_F( |
713 PropertyTreeTestTransformsWithFlattening); | 673 PropertyTreeTestTransformsWithFlattening); |
714 | 674 |
715 class PropertyTreeTestMultiplicationOrder : public PropertyTreeTest { | 675 class PropertyTreeTestMultiplicationOrder : public PropertyTreeTest { |
716 protected: | 676 protected: |
717 void StartTest() override { | 677 void StartTest() override { |
718 PropertyTrees property_trees; | 678 PropertyTrees property_trees; |
719 TransformTree& tree = property_trees.transform_tree; | 679 TransformTree& tree = property_trees.transform_tree; |
720 TransformNode& root = *tree.Node(0); | 680 TransformNode& root = *tree.Node(0); |
721 root.data.local.Translate(2, 2); | 681 root.local.Translate(2, 2); |
722 tree.SetTargetId(root.id, 0); | 682 tree.SetTargetId(root.id, 0); |
723 tree.UpdateTransforms(0); | 683 tree.UpdateTransforms(0); |
724 | 684 |
725 TransformNode child; | 685 TransformNode child; |
726 child.data.local.Scale(2, 2); | 686 child.local.Scale(2, 2); |
727 child.data.source_node_id = 0; | 687 child.source_node_id = 0; |
728 child.id = tree.Insert(child, 0); | 688 child.id = tree.Insert(child, 0); |
729 tree.SetTargetId(child.id, 0); | 689 tree.SetTargetId(child.id, 0); |
730 | 690 |
731 SetupTransformTreeForTest(&tree); | 691 SetupTransformTreeForTest(&tree); |
732 tree.UpdateTransforms(1); | 692 tree.UpdateTransforms(1); |
733 | 693 |
734 gfx::Transform expected; | 694 gfx::Transform expected; |
735 expected.Translate(2, 2); | 695 expected.Translate(2, 2); |
736 expected.Scale(2, 2); | 696 expected.Scale(2, 2); |
737 | 697 |
(...skipping 19 matching lines...) Expand all Loading... |
757 : public PropertyTreeTest { | 717 : public PropertyTreeTest { |
758 protected: | 718 protected: |
759 void StartTest() override { | 719 void StartTest() override { |
760 PropertyTrees property_trees; | 720 PropertyTrees property_trees; |
761 TransformTree& tree = property_trees.transform_tree; | 721 TransformTree& tree = property_trees.transform_tree; |
762 TransformNode& root = *tree.Node(0); | 722 TransformNode& root = *tree.Node(0); |
763 tree.SetTargetId(root.id, 0); | 723 tree.SetTargetId(root.id, 0); |
764 tree.UpdateTransforms(0); | 724 tree.UpdateTransforms(0); |
765 | 725 |
766 TransformNode child; | 726 TransformNode child; |
767 child.data.local.Scale(0, 0); | 727 child.local.Scale(0, 0); |
768 child.data.source_node_id = 0; | 728 child.source_node_id = 0; |
769 child.id = tree.Insert(child, 0); | 729 child.id = tree.Insert(child, 0); |
770 tree.SetTargetId(child.id, 0); | 730 tree.SetTargetId(child.id, 0); |
771 | 731 |
772 SetupTransformTreeForTest(&tree); | 732 SetupTransformTreeForTest(&tree); |
773 tree.UpdateTransforms(1); | 733 tree.UpdateTransforms(1); |
774 | 734 |
775 gfx::Transform expected; | 735 gfx::Transform expected; |
776 expected.Scale(0, 0); | 736 expected.Scale(0, 0); |
777 | 737 |
778 gfx::Transform transform; | 738 gfx::Transform transform; |
(...skipping 18 matching lines...) Expand all Loading... |
797 protected: | 757 protected: |
798 void StartTest() override { | 758 void StartTest() override { |
799 PropertyTrees property_trees; | 759 PropertyTrees property_trees; |
800 TransformTree& tree = property_trees.transform_tree; | 760 TransformTree& tree = property_trees.transform_tree; |
801 TransformNode& root = *tree.Node(0); | 761 TransformNode& root = *tree.Node(0); |
802 root.id = 0; | 762 root.id = 0; |
803 tree.SetTargetId(root.id, 0); | 763 tree.SetTargetId(root.id, 0); |
804 tree.UpdateTransforms(0); | 764 tree.UpdateTransforms(0); |
805 | 765 |
806 TransformNode grand_parent; | 766 TransformNode grand_parent; |
807 grand_parent.data.local.Scale(2.f, 2.f); | 767 grand_parent.local.Scale(2.f, 2.f); |
808 grand_parent.data.source_node_id = 0; | 768 grand_parent.source_node_id = 0; |
809 grand_parent.data.needs_sublayer_scale = true; | 769 grand_parent.needs_sublayer_scale = true; |
810 int grand_parent_id = tree.Insert(grand_parent, 0); | 770 int grand_parent_id = tree.Insert(grand_parent, 0); |
811 tree.SetTargetId(grand_parent_id, 0); | 771 tree.SetTargetId(grand_parent_id, 0); |
812 tree.UpdateTransforms(grand_parent_id); | 772 tree.UpdateTransforms(grand_parent_id); |
813 | 773 |
814 TransformNode parent; | 774 TransformNode parent; |
815 parent.data.local.Translate(15.f, 15.f); | 775 parent.local.Translate(15.f, 15.f); |
816 parent.data.source_node_id = grand_parent_id; | 776 parent.source_node_id = grand_parent_id; |
817 int parent_id = tree.Insert(parent, grand_parent_id); | 777 int parent_id = tree.Insert(parent, grand_parent_id); |
818 tree.SetTargetId(parent_id, grand_parent_id); | 778 tree.SetTargetId(parent_id, grand_parent_id); |
819 tree.UpdateTransforms(parent_id); | 779 tree.UpdateTransforms(parent_id); |
820 | 780 |
821 TransformNode child; | 781 TransformNode child; |
822 child.data.local.Scale(3.f, 3.f); | 782 child.local.Scale(3.f, 3.f); |
823 child.data.source_node_id = parent_id; | 783 child.source_node_id = parent_id; |
824 int child_id = tree.Insert(child, parent_id); | 784 int child_id = tree.Insert(child, parent_id); |
825 tree.SetTargetId(child_id, grand_parent_id); | 785 tree.SetTargetId(child_id, grand_parent_id); |
826 tree.UpdateTransforms(child_id); | 786 tree.UpdateTransforms(child_id); |
827 | 787 |
828 TransformNode grand_child; | 788 TransformNode grand_child; |
829 grand_child.data.local.Scale(5.f, 5.f); | 789 grand_child.local.Scale(5.f, 5.f); |
830 grand_child.data.source_node_id = child_id; | 790 grand_child.source_node_id = child_id; |
831 grand_child.data.needs_sublayer_scale = true; | 791 grand_child.needs_sublayer_scale = true; |
832 int grand_child_id = tree.Insert(grand_child, child_id); | 792 int grand_child_id = tree.Insert(grand_child, child_id); |
833 tree.SetTargetId(grand_child_id, grand_parent_id); | 793 tree.SetTargetId(grand_child_id, grand_parent_id); |
834 SetupTransformTreeForTest(&tree); | 794 SetupTransformTreeForTest(&tree); |
835 tree.UpdateTransforms(grand_child_id); | 795 tree.UpdateTransforms(grand_child_id); |
836 | 796 |
837 EXPECT_EQ(gfx::Vector2dF(2.f, 2.f), | 797 EXPECT_EQ(gfx::Vector2dF(2.f, 2.f), |
838 tree.Node(grand_parent_id)->data.sublayer_scale); | 798 tree.Node(grand_parent_id)->sublayer_scale); |
839 EXPECT_EQ(gfx::Vector2dF(30.f, 30.f), | 799 EXPECT_EQ(gfx::Vector2dF(30.f, 30.f), |
840 tree.Node(grand_child_id)->data.sublayer_scale); | 800 tree.Node(grand_child_id)->sublayer_scale); |
841 | 801 |
842 // Compute transform from grand_parent to grand_child. | 802 // Compute transform from grand_parent to grand_child. |
843 gfx::Transform expected_transform_without_sublayer_scale; | 803 gfx::Transform expected_transform_without_sublayer_scale; |
844 expected_transform_without_sublayer_scale.Scale(1.f / 15.f, 1.f / 15.f); | 804 expected_transform_without_sublayer_scale.Scale(1.f / 15.f, 1.f / 15.f); |
845 expected_transform_without_sublayer_scale.Translate(-15.f, -15.f); | 805 expected_transform_without_sublayer_scale.Translate(-15.f, -15.f); |
846 | 806 |
847 gfx::Transform expected_transform_with_dest_sublayer_scale; | 807 gfx::Transform expected_transform_with_dest_sublayer_scale; |
848 expected_transform_with_dest_sublayer_scale.Scale(30.f, 30.f); | 808 expected_transform_with_dest_sublayer_scale.Scale(30.f, 30.f); |
849 expected_transform_with_dest_sublayer_scale.Scale(1.f / 15.f, 1.f / 15.f); | 809 expected_transform_with_dest_sublayer_scale.Scale(1.f / 15.f, 1.f / 15.f); |
850 expected_transform_with_dest_sublayer_scale.Translate(-15.f, -15.f); | 810 expected_transform_with_dest_sublayer_scale.Translate(-15.f, -15.f); |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
915 : public PropertyTreeTest { | 875 : public PropertyTreeTest { |
916 protected: | 876 protected: |
917 void StartTest() override { | 877 void StartTest() override { |
918 PropertyTrees property_trees; | 878 PropertyTrees property_trees; |
919 TransformTree& tree = property_trees.transform_tree; | 879 TransformTree& tree = property_trees.transform_tree; |
920 TransformNode& root = *tree.Node(0); | 880 TransformNode& root = *tree.Node(0); |
921 tree.SetTargetId(root.id, 0); | 881 tree.SetTargetId(root.id, 0); |
922 tree.UpdateTransforms(0); | 882 tree.UpdateTransforms(0); |
923 | 883 |
924 TransformNode grand_parent; | 884 TransformNode grand_parent; |
925 grand_parent.data.local.Scale(2.f, 0.f); | 885 grand_parent.local.Scale(2.f, 0.f); |
926 grand_parent.data.source_node_id = 0; | 886 grand_parent.source_node_id = 0; |
927 grand_parent.data.needs_sublayer_scale = true; | 887 grand_parent.needs_sublayer_scale = true; |
928 int grand_parent_id = tree.Insert(grand_parent, 0); | 888 int grand_parent_id = tree.Insert(grand_parent, 0); |
929 tree.SetTargetId(grand_parent_id, 0); | 889 tree.SetTargetId(grand_parent_id, 0); |
930 tree.SetContentTargetId(grand_parent_id, grand_parent_id); | 890 tree.SetContentTargetId(grand_parent_id, grand_parent_id); |
931 tree.UpdateTransforms(grand_parent_id); | 891 tree.UpdateTransforms(grand_parent_id); |
932 | 892 |
933 TransformNode parent; | 893 TransformNode parent; |
934 parent.data.local.Translate(1.f, 1.f); | 894 parent.local.Translate(1.f, 1.f); |
935 parent.data.source_node_id = grand_parent_id; | 895 parent.source_node_id = grand_parent_id; |
936 int parent_id = tree.Insert(parent, grand_parent_id); | 896 int parent_id = tree.Insert(parent, grand_parent_id); |
937 tree.SetTargetId(parent_id, grand_parent_id); | 897 tree.SetTargetId(parent_id, grand_parent_id); |
938 tree.SetContentTargetId(parent_id, grand_parent_id); | 898 tree.SetContentTargetId(parent_id, grand_parent_id); |
939 tree.UpdateTransforms(parent_id); | 899 tree.UpdateTransforms(parent_id); |
940 | 900 |
941 TransformNode child; | 901 TransformNode child; |
942 child.data.local.Translate(3.f, 4.f); | 902 child.local.Translate(3.f, 4.f); |
943 child.data.source_node_id = parent_id; | 903 child.source_node_id = parent_id; |
944 int child_id = tree.Insert(child, parent_id); | 904 int child_id = tree.Insert(child, parent_id); |
945 tree.SetTargetId(child_id, grand_parent_id); | 905 tree.SetTargetId(child_id, grand_parent_id); |
946 tree.SetContentTargetId(child_id, grand_parent_id); | 906 tree.SetContentTargetId(child_id, grand_parent_id); |
947 SetupTransformTreeForTest(&tree); | 907 SetupTransformTreeForTest(&tree); |
948 tree.UpdateTransforms(child_id); | 908 tree.UpdateTransforms(child_id); |
949 | 909 |
950 gfx::Transform expected_transform; | 910 gfx::Transform expected_transform; |
951 expected_transform.Translate(4.f, 5.f); | 911 expected_transform.Translate(4.f, 5.f); |
952 | 912 |
953 gfx::Transform transform; | 913 gfx::Transform transform; |
954 bool success = tree.ComputeTransform(child_id, grand_parent_id, &transform); | 914 bool success = tree.ComputeTransform(child_id, grand_parent_id, &transform); |
955 EXPECT_TRUE(success); | 915 EXPECT_TRUE(success); |
956 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform, transform); | 916 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform, transform); |
957 | 917 |
958 tree.Node(grand_parent_id)->data.local.MakeIdentity(); | 918 tree.Node(grand_parent_id)->local.MakeIdentity(); |
959 tree.Node(grand_parent_id)->data.local.Scale(0.f, 2.f); | 919 tree.Node(grand_parent_id)->local.Scale(0.f, 2.f); |
960 tree.Node(grand_parent_id)->data.needs_local_transform_update = true; | 920 tree.Node(grand_parent_id)->needs_local_transform_update = true; |
961 tree.set_needs_update(true); | 921 tree.set_needs_update(true); |
962 SetupTransformTreeForTest(&tree); | 922 SetupTransformTreeForTest(&tree); |
963 | 923 |
964 draw_property_utils::ComputeTransforms(&tree); | 924 draw_property_utils::ComputeTransforms(&tree); |
965 | 925 |
966 success = tree.ComputeTransform(child_id, grand_parent_id, &transform); | 926 success = tree.ComputeTransform(child_id, grand_parent_id, &transform); |
967 EXPECT_TRUE(success); | 927 EXPECT_TRUE(success); |
968 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform, transform); | 928 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform, transform); |
969 | 929 |
970 tree.Node(grand_parent_id)->data.local.MakeIdentity(); | 930 tree.Node(grand_parent_id)->local.MakeIdentity(); |
971 tree.Node(grand_parent_id)->data.local.Scale(0.f, 0.f); | 931 tree.Node(grand_parent_id)->local.Scale(0.f, 0.f); |
972 tree.Node(grand_parent_id)->data.needs_local_transform_update = true; | 932 tree.Node(grand_parent_id)->needs_local_transform_update = true; |
973 tree.set_needs_update(true); | 933 tree.set_needs_update(true); |
974 SetupTransformTreeForTest(&tree); | 934 SetupTransformTreeForTest(&tree); |
975 | 935 |
976 draw_property_utils::ComputeTransforms(&tree); | 936 draw_property_utils::ComputeTransforms(&tree); |
977 | 937 |
978 success = tree.ComputeTransform(child_id, grand_parent_id, &transform); | 938 success = tree.ComputeTransform(child_id, grand_parent_id, &transform); |
979 EXPECT_TRUE(success); | 939 EXPECT_TRUE(success); |
980 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform, transform); | 940 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform, transform); |
981 } | 941 } |
982 }; | 942 }; |
983 | 943 |
984 DIRECT_AND_SERIALIZED_PROPERTY_TREE_TEST_F( | 944 DIRECT_AND_SERIALIZED_PROPERTY_TREE_TEST_F( |
985 PropertyTreeTestComputeTransformToTargetWithZeroSublayerScale); | 945 PropertyTreeTestComputeTransformToTargetWithZeroSublayerScale); |
986 | 946 |
987 class PropertyTreeTestFlatteningWhenDestinationHasOnlyFlatAncestors | 947 class PropertyTreeTestFlatteningWhenDestinationHasOnlyFlatAncestors |
988 : public PropertyTreeTest { | 948 : public PropertyTreeTest { |
989 protected: | 949 protected: |
990 void StartTest() override { | 950 void StartTest() override { |
991 // This tests that flattening is performed correctly when | 951 // This tests that flattening is performed correctly when |
992 // destination and its ancestors are flat, but there are 3d transforms | 952 // destination and its ancestors are flat, but there are 3d transforms |
993 // and flattening between the source and destination. | 953 // and flattening between the source and destination. |
994 PropertyTrees property_trees; | 954 PropertyTrees property_trees; |
995 TransformTree& tree = property_trees.transform_tree; | 955 TransformTree& tree = property_trees.transform_tree; |
996 | 956 |
997 int parent = tree.Insert(TransformNode(), 0); | 957 int parent = tree.Insert(TransformNode(), 0); |
998 tree.SetContentTargetId(parent, parent); | 958 tree.SetContentTargetId(parent, parent); |
999 tree.SetTargetId(parent, parent); | 959 tree.SetTargetId(parent, parent); |
1000 tree.Node(parent)->data.source_node_id = 0; | 960 tree.Node(parent)->source_node_id = 0; |
1001 tree.Node(parent)->data.local.Translate(2, 2); | 961 tree.Node(parent)->local.Translate(2, 2); |
1002 | 962 |
1003 gfx::Transform rotation_about_x; | 963 gfx::Transform rotation_about_x; |
1004 rotation_about_x.RotateAboutXAxis(15); | 964 rotation_about_x.RotateAboutXAxis(15); |
1005 | 965 |
1006 int child = tree.Insert(TransformNode(), parent); | 966 int child = tree.Insert(TransformNode(), parent); |
1007 tree.SetContentTargetId(child, child); | 967 tree.SetContentTargetId(child, child); |
1008 tree.SetTargetId(child, child); | 968 tree.SetTargetId(child, child); |
1009 tree.Node(child)->data.source_node_id = parent; | 969 tree.Node(child)->source_node_id = parent; |
1010 tree.Node(child)->data.local = rotation_about_x; | 970 tree.Node(child)->local = rotation_about_x; |
1011 | 971 |
1012 int grand_child = tree.Insert(TransformNode(), child); | 972 int grand_child = tree.Insert(TransformNode(), child); |
1013 tree.SetContentTargetId(grand_child, grand_child); | 973 tree.SetContentTargetId(grand_child, grand_child); |
1014 tree.SetTargetId(grand_child, grand_child); | 974 tree.SetTargetId(grand_child, grand_child); |
1015 tree.Node(grand_child)->data.source_node_id = child; | 975 tree.Node(grand_child)->source_node_id = child; |
1016 tree.Node(grand_child)->data.flattens_inherited_transform = true; | 976 tree.Node(grand_child)->flattens_inherited_transform = true; |
1017 | 977 |
1018 tree.set_needs_update(true); | 978 tree.set_needs_update(true); |
1019 SetupTransformTreeForTest(&tree); | 979 SetupTransformTreeForTest(&tree); |
1020 draw_property_utils::ComputeTransforms(&tree); | 980 draw_property_utils::ComputeTransforms(&tree); |
1021 | 981 |
1022 gfx::Transform flattened_rotation_about_x = rotation_about_x; | 982 gfx::Transform flattened_rotation_about_x = rotation_about_x; |
1023 flattened_rotation_about_x.FlattenTo2d(); | 983 flattened_rotation_about_x.FlattenTo2d(); |
1024 | 984 |
1025 gfx::Transform grand_child_to_parent; | 985 gfx::Transform grand_child_to_parent; |
1026 bool success = | 986 bool success = |
(...skipping 11 matching lines...) Expand all Loading... |
1038 protected: | 998 protected: |
1039 void StartTest() override { | 999 void StartTest() override { |
1040 // This tests that screen space opacity is updated for the subtree when | 1000 // This tests that screen space opacity is updated for the subtree when |
1041 // opacity of a node changes. | 1001 // opacity of a node changes. |
1042 EffectTree tree; | 1002 EffectTree tree; |
1043 | 1003 |
1044 int parent = tree.Insert(EffectNode(), 0); | 1004 int parent = tree.Insert(EffectNode(), 0); |
1045 int child = tree.Insert(EffectNode(), parent); | 1005 int child = tree.Insert(EffectNode(), parent); |
1046 SetupEffectTreeForTest(&tree); | 1006 SetupEffectTreeForTest(&tree); |
1047 | 1007 |
1048 EXPECT_EQ(tree.Node(child)->data.screen_space_opacity, 1.f); | 1008 EXPECT_EQ(tree.Node(child)->screen_space_opacity, 1.f); |
1049 tree.Node(parent)->data.opacity = 0.5f; | 1009 tree.Node(parent)->opacity = 0.5f; |
1050 tree.set_needs_update(true); | 1010 tree.set_needs_update(true); |
1051 SetupEffectTreeForTest(&tree); | 1011 SetupEffectTreeForTest(&tree); |
1052 draw_property_utils::ComputeEffects(&tree); | 1012 draw_property_utils::ComputeEffects(&tree); |
1053 EXPECT_EQ(tree.Node(child)->data.screen_space_opacity, 0.5f); | 1013 EXPECT_EQ(tree.Node(child)->screen_space_opacity, 0.5f); |
1054 | 1014 |
1055 tree.Node(child)->data.opacity = 0.5f; | 1015 tree.Node(child)->opacity = 0.5f; |
1056 tree.set_needs_update(true); | 1016 tree.set_needs_update(true); |
1057 SetupEffectTreeForTest(&tree); | 1017 SetupEffectTreeForTest(&tree); |
1058 draw_property_utils::ComputeEffects(&tree); | 1018 draw_property_utils::ComputeEffects(&tree); |
1059 EXPECT_EQ(tree.Node(child)->data.screen_space_opacity, 0.25f); | 1019 EXPECT_EQ(tree.Node(child)->screen_space_opacity, 0.25f); |
1060 } | 1020 } |
1061 }; | 1021 }; |
1062 | 1022 |
1063 DIRECT_AND_SERIALIZED_PROPERTY_TREE_TEST_F( | 1023 DIRECT_AND_SERIALIZED_PROPERTY_TREE_TEST_F( |
1064 PropertyTreeTestScreenSpaceOpacityUpdateTest); | 1024 PropertyTreeTestScreenSpaceOpacityUpdateTest); |
1065 | 1025 |
1066 class PropertyTreeTestNonIntegerTranslationTest : public PropertyTreeTest { | 1026 class PropertyTreeTestNonIntegerTranslationTest : public PropertyTreeTest { |
1067 protected: | 1027 protected: |
1068 void StartTest() override { | 1028 void StartTest() override { |
1069 // This tests that when a node has non-integer translation, the information | 1029 // This tests that when a node has non-integer translation, the information |
1070 // is propagated to the subtree. | 1030 // is propagated to the subtree. |
1071 PropertyTrees property_trees; | 1031 PropertyTrees property_trees; |
1072 TransformTree& tree = property_trees.transform_tree; | 1032 TransformTree& tree = property_trees.transform_tree; |
1073 | 1033 |
1074 int parent = tree.Insert(TransformNode(), 0); | 1034 int parent = tree.Insert(TransformNode(), 0); |
1075 tree.SetTargetId(parent, parent); | 1035 tree.SetTargetId(parent, parent); |
1076 tree.Node(parent)->data.local.Translate(1.5f, 1.5f); | 1036 tree.Node(parent)->local.Translate(1.5f, 1.5f); |
1077 | 1037 |
1078 int child = tree.Insert(TransformNode(), parent); | 1038 int child = tree.Insert(TransformNode(), parent); |
1079 tree.SetTargetId(child, parent); | 1039 tree.SetTargetId(child, parent); |
1080 tree.Node(child)->data.local.Translate(1, 1); | 1040 tree.Node(child)->local.Translate(1, 1); |
1081 tree.set_needs_update(true); | 1041 tree.set_needs_update(true); |
1082 SetupTransformTreeForTest(&tree); | 1042 SetupTransformTreeForTest(&tree); |
1083 draw_property_utils::ComputeTransforms(&tree); | 1043 draw_property_utils::ComputeTransforms(&tree); |
1084 EXPECT_FALSE(tree.Node(parent) | 1044 EXPECT_FALSE( |
1085 ->data.node_and_ancestors_have_only_integer_translation); | 1045 tree.Node(parent)->node_and_ancestors_have_only_integer_translation); |
1086 EXPECT_FALSE(tree.Node(child) | 1046 EXPECT_FALSE( |
1087 ->data.node_and_ancestors_have_only_integer_translation); | 1047 tree.Node(child)->node_and_ancestors_have_only_integer_translation); |
1088 | 1048 |
1089 tree.Node(parent)->data.local.Translate(0.5f, 0.5f); | 1049 tree.Node(parent)->local.Translate(0.5f, 0.5f); |
1090 tree.Node(child)->data.local.Translate(0.5f, 0.5f); | 1050 tree.Node(child)->local.Translate(0.5f, 0.5f); |
1091 tree.set_needs_update(true); | 1051 tree.set_needs_update(true); |
1092 SetupTransformTreeForTest(&tree); | 1052 SetupTransformTreeForTest(&tree); |
1093 draw_property_utils::ComputeTransforms(&tree); | 1053 draw_property_utils::ComputeTransforms(&tree); |
1094 EXPECT_TRUE(tree.Node(parent) | 1054 EXPECT_TRUE( |
1095 ->data.node_and_ancestors_have_only_integer_translation); | 1055 tree.Node(parent)->node_and_ancestors_have_only_integer_translation); |
1096 EXPECT_FALSE(tree.Node(child) | 1056 EXPECT_FALSE( |
1097 ->data.node_and_ancestors_have_only_integer_translation); | 1057 tree.Node(child)->node_and_ancestors_have_only_integer_translation); |
1098 | 1058 |
1099 tree.Node(child)->data.local.Translate(0.5f, 0.5f); | 1059 tree.Node(child)->local.Translate(0.5f, 0.5f); |
1100 tree.SetTargetId(child, child); | 1060 tree.SetTargetId(child, child); |
1101 tree.set_needs_update(true); | 1061 tree.set_needs_update(true); |
1102 SetupTransformTreeForTest(&tree); | 1062 SetupTransformTreeForTest(&tree); |
1103 draw_property_utils::ComputeTransforms(&tree); | 1063 draw_property_utils::ComputeTransforms(&tree); |
1104 EXPECT_TRUE(tree.Node(parent) | 1064 EXPECT_TRUE( |
1105 ->data.node_and_ancestors_have_only_integer_translation); | 1065 tree.Node(parent)->node_and_ancestors_have_only_integer_translation); |
1106 EXPECT_TRUE(tree.Node(child) | 1066 EXPECT_TRUE( |
1107 ->data.node_and_ancestors_have_only_integer_translation); | 1067 tree.Node(child)->node_and_ancestors_have_only_integer_translation); |
1108 } | 1068 } |
1109 }; | 1069 }; |
1110 | 1070 |
1111 DIRECT_AND_SERIALIZED_PROPERTY_TREE_TEST_F( | 1071 DIRECT_AND_SERIALIZED_PROPERTY_TREE_TEST_F( |
1112 PropertyTreeTestNonIntegerTranslationTest); | 1072 PropertyTreeTestNonIntegerTranslationTest); |
1113 | 1073 |
1114 class PropertyTreeTestSingularTransformSnapTest : public PropertyTreeTest { | 1074 class PropertyTreeTestSingularTransformSnapTest : public PropertyTreeTest { |
1115 protected: | 1075 protected: |
1116 void StartTest() override { | 1076 void StartTest() override { |
1117 // This tests that to_target transform is not snapped when it has a singular | 1077 // This tests that to_target transform is not snapped when it has a singular |
1118 // transform. | 1078 // transform. |
1119 PropertyTrees property_trees; | 1079 PropertyTrees property_trees; |
1120 TransformTree& tree = property_trees.transform_tree; | 1080 TransformTree& tree = property_trees.transform_tree; |
1121 | 1081 |
1122 int parent = tree.Insert(TransformNode(), 0); | 1082 int parent = tree.Insert(TransformNode(), 0); |
1123 tree.SetTargetId(parent, parent); | 1083 tree.SetTargetId(parent, parent); |
1124 tree.Node(parent)->data.scrolls = true; | 1084 tree.Node(parent)->scrolls = true; |
1125 | 1085 |
1126 int child = tree.Insert(TransformNode(), parent); | 1086 int child = tree.Insert(TransformNode(), parent); |
1127 TransformNode* child_node = tree.Node(child); | 1087 TransformNode* child_node = tree.Node(child); |
1128 tree.SetTargetId(child, parent); | 1088 tree.SetTargetId(child, parent); |
1129 child_node->data.scrolls = true; | 1089 child_node->scrolls = true; |
1130 child_node->data.local.Scale3d(6.0f, 6.0f, 0.0f); | 1090 child_node->local.Scale3d(6.0f, 6.0f, 0.0f); |
1131 child_node->data.local.Translate(1.3f, 1.3f); | 1091 child_node->local.Translate(1.3f, 1.3f); |
1132 tree.set_needs_update(true); | 1092 tree.set_needs_update(true); |
1133 | 1093 |
1134 SetupTransformTreeForTest(&tree); | 1094 SetupTransformTreeForTest(&tree); |
1135 draw_property_utils::ComputeTransforms(&tree); | 1095 draw_property_utils::ComputeTransforms(&tree); |
1136 | 1096 |
1137 gfx::Transform from_target; | 1097 gfx::Transform from_target; |
1138 EXPECT_FALSE(tree.ToTarget(child).GetInverse(&from_target)); | 1098 EXPECT_FALSE(tree.ToTarget(child).GetInverse(&from_target)); |
1139 // The following checks are to ensure that snapping is skipped because of | 1099 // The following checks are to ensure that snapping is skipped because of |
1140 // singular transform (and not because of other reasons which also cause | 1100 // singular transform (and not because of other reasons which also cause |
1141 // snapping to be skipped). | 1101 // snapping to be skipped). |
1142 EXPECT_TRUE(child_node->data.scrolls); | 1102 EXPECT_TRUE(child_node->scrolls); |
1143 EXPECT_TRUE(tree.ToTarget(child).IsScaleOrTranslation()); | 1103 EXPECT_TRUE(tree.ToTarget(child).IsScaleOrTranslation()); |
1144 EXPECT_FALSE(child_node->data.to_screen_is_potentially_animated); | 1104 EXPECT_FALSE(child_node->to_screen_is_potentially_animated); |
1145 EXPECT_FALSE(child_node->data.ancestors_are_invertible); | 1105 EXPECT_FALSE(child_node->ancestors_are_invertible); |
1146 | 1106 |
1147 gfx::Transform rounded = tree.ToTarget(child); | 1107 gfx::Transform rounded = tree.ToTarget(child); |
1148 rounded.RoundTranslationComponents(); | 1108 rounded.RoundTranslationComponents(); |
1149 EXPECT_NE(tree.ToTarget(child), rounded); | 1109 EXPECT_NE(tree.ToTarget(child), rounded); |
1150 } | 1110 } |
1151 }; | 1111 }; |
1152 | 1112 |
1153 DIRECT_AND_SERIALIZED_PROPERTY_TREE_TEST_F( | 1113 DIRECT_AND_SERIALIZED_PROPERTY_TREE_TEST_F( |
1154 PropertyTreeTestSingularTransformSnapTest); | 1114 PropertyTreeTestSingularTransformSnapTest); |
1155 | 1115 |
1156 #undef DIRECT_AND_SERIALIZED_PROPERTY_TREE_TEST_F | 1116 #undef DIRECT_AND_SERIALIZED_PROPERTY_TREE_TEST_F |
1157 #undef SERIALIZED_PROPERTY_TREE_TEST_F | 1117 #undef SERIALIZED_PROPERTY_TREE_TEST_F |
1158 #undef DIRECT_PROPERTY_TREE_TEST_F | 1118 #undef DIRECT_PROPERTY_TREE_TEST_F |
1159 | 1119 |
1160 } // namespace | 1120 } // namespace |
1161 } // namespace cc | 1121 } // namespace cc |
OLD | NEW |