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