Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(253)

Side by Side Diff: cc/layers/layer_proto_converter_unittest.cc

Issue 1808373002: cc : Make tree synchronization independent of layer tree hierarchy (2) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « cc/layers/layer_proto_converter.cc ('k') | cc/layers/layer_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/layers/layer_proto_converter.h" 5 #include "cc/layers/layer_proto_converter.h"
6 6
7 #include "cc/layers/empty_content_layer_client.h" 7 #include "cc/layers/empty_content_layer_client.h"
8 #include "cc/layers/heads_up_display_layer.h" 8 #include "cc/layers/heads_up_display_layer.h"
9 #include "cc/layers/layer.h" 9 #include "cc/layers/layer.h"
10 #include "cc/layers/picture_layer.h" 10 #include "cc/layers/picture_layer.h"
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 Layers marked with + have descendants with changed properties. 174 Layers marked with + have descendants with changed properties.
175 Layer b also has a mask layer and a replica layer. 175 Layer b also has a mask layer and a replica layer.
176 */ 176 */
177 scoped_refptr<Layer> layer_src_root = Layer::Create(); 177 scoped_refptr<Layer> layer_src_root = Layer::Create();
178 scoped_refptr<Layer> layer_src_a = Layer::Create(); 178 scoped_refptr<Layer> layer_src_a = Layer::Create();
179 scoped_refptr<Layer> layer_src_b = Layer::Create(); 179 scoped_refptr<Layer> layer_src_b = Layer::Create();
180 scoped_refptr<Layer> layer_src_b_mask = Layer::Create(); 180 scoped_refptr<Layer> layer_src_b_mask = Layer::Create();
181 scoped_refptr<Layer> layer_src_b_replica = Layer::Create(); 181 scoped_refptr<Layer> layer_src_b_replica = Layer::Create();
182 scoped_refptr<Layer> layer_src_c = Layer::Create(); 182 scoped_refptr<Layer> layer_src_c = Layer::Create();
183 scoped_refptr<Layer> layer_src_d = Layer::Create(); 183 scoped_refptr<Layer> layer_src_d = Layer::Create();
184 layer_src_root->SetLayerTreeHost(layer_tree_host_.get());
184 layer_src_root->AddChild(layer_src_a); 185 layer_src_root->AddChild(layer_src_a);
185 layer_src_root->AddChild(layer_src_b); 186 layer_src_root->AddChild(layer_src_b);
186 layer_src_a->AddChild(layer_src_c); 187 layer_src_a->AddChild(layer_src_c);
187 layer_src_b->AddChild(layer_src_d); 188 layer_src_b->AddChild(layer_src_d);
188 layer_src_b->SetMaskLayer(layer_src_b_mask.get()); 189 layer_src_b->SetMaskLayer(layer_src_b_mask.get());
189 layer_src_b->SetReplicaLayer(layer_src_b_replica.get()); 190 layer_src_b->SetReplicaLayer(layer_src_b_replica.get());
190 191
191 proto::LayerUpdate layer_update; 192 proto::LayerUpdate layer_update;
192 LayerProtoConverter::SerializeLayerProperties(layer_src_root.get(), 193 LayerProtoConverter::SerializeLayerProperties(
193 &layer_update); 194 layer_src_root->layer_tree_host(), &layer_update);
194 195
195 // All flags for pushing properties should have been cleared. 196 // All flags for pushing properties should have been cleared.
196 EXPECT_FALSE(layer_src_root->needs_push_properties()); 197 EXPECT_FALSE(
197 EXPECT_FALSE(layer_src_root->descendant_needs_push_properties()); 198 layer_src_root->layer_tree_host()->LayerNeedsPushPropertiesForTesting(
198 EXPECT_FALSE(layer_src_a->needs_push_properties()); 199 layer_src_root.get()));
199 EXPECT_FALSE(layer_src_a->descendant_needs_push_properties()); 200 EXPECT_FALSE(
200 EXPECT_FALSE(layer_src_b->needs_push_properties()); 201 layer_src_a->layer_tree_host()->LayerNeedsPushPropertiesForTesting(
201 EXPECT_FALSE(layer_src_b->descendant_needs_push_properties()); 202 layer_src_a.get()));
202 EXPECT_FALSE(layer_src_b_mask->needs_push_properties()); 203 EXPECT_FALSE(
203 EXPECT_FALSE(layer_src_b_mask->descendant_needs_push_properties()); 204 layer_src_b->layer_tree_host()->LayerNeedsPushPropertiesForTesting(
204 EXPECT_FALSE(layer_src_b_replica->needs_push_properties()); 205 layer_src_b.get()));
205 EXPECT_FALSE(layer_src_b_replica->descendant_needs_push_properties()); 206 EXPECT_FALSE(
206 EXPECT_FALSE(layer_src_c->needs_push_properties()); 207 layer_src_b_mask->layer_tree_host()->LayerNeedsPushPropertiesForTesting(
207 EXPECT_FALSE(layer_src_c->descendant_needs_push_properties()); 208 layer_src_b_mask.get()));
208 EXPECT_FALSE(layer_src_d->needs_push_properties()); 209 EXPECT_FALSE(
209 EXPECT_FALSE(layer_src_d->descendant_needs_push_properties()); 210 layer_src_b_replica->layer_tree_host()
211 ->LayerNeedsPushPropertiesForTesting(layer_src_b_replica.get()));
212 EXPECT_FALSE(
213 layer_src_c->layer_tree_host()->LayerNeedsPushPropertiesForTesting(
214 layer_src_c.get()));
215 EXPECT_FALSE(
216 layer_src_d->layer_tree_host()->LayerNeedsPushPropertiesForTesting(
217 layer_src_d.get()));
210 218
211 // AddChild changes the stacking order of child and it needs to push 219 // All layers needs to push properties as their layer tree host changed.
212 // properties. 220 ASSERT_EQ(7, layer_update.layers_size());
213 ASSERT_EQ(5, layer_update.layers_size());
214 EXPECT_EQ(layer_src_root->id(), layer_update.layers(0).id());
215 proto::LayerProperties dest_root = layer_update.layers(0);
216 EXPECT_EQ(layer_src_a->id(), layer_update.layers(1).id());
217 proto::LayerProperties dest_a = layer_update.layers(1);
218 EXPECT_EQ(layer_src_c->id(), layer_update.layers(2).id());
219 proto::LayerProperties dest_c = layer_update.layers(2);
220 EXPECT_EQ(layer_src_b->id(), layer_update.layers(3).id());
221 proto::LayerProperties dest_b = layer_update.layers(3);
222 EXPECT_EQ(layer_src_d->id(), layer_update.layers(4).id());
223 proto::LayerProperties dest_d = layer_update.layers(4);
224 layer_update.Clear(); 221 layer_update.Clear();
225 222
223 std::unordered_set<int> dirty_layer_ids;
226 layer_src_a->SetNeedsPushProperties(); 224 layer_src_a->SetNeedsPushProperties();
225 dirty_layer_ids.insert(layer_src_a->id());
227 layer_src_b->SetNeedsPushProperties(); 226 layer_src_b->SetNeedsPushProperties();
227 dirty_layer_ids.insert(layer_src_b->id());
228 layer_src_b_mask->SetNeedsPushProperties(); 228 layer_src_b_mask->SetNeedsPushProperties();
229 dirty_layer_ids.insert(layer_src_b_mask->id());
229 layer_src_d->SetNeedsPushProperties(); 230 layer_src_d->SetNeedsPushProperties();
231 dirty_layer_ids.insert(layer_src_d->id());
230 232
231 LayerProtoConverter::SerializeLayerProperties(layer_src_root.get(), 233 LayerProtoConverter::SerializeLayerProperties(
232 &layer_update); 234 layer_src_root->layer_tree_host(), &layer_update);
233 235
234 // All flags for pushing properties should have been cleared. 236 // All flags for pushing properties should have been cleared.
235 EXPECT_FALSE(layer_src_root->needs_push_properties()); 237 EXPECT_FALSE(
236 EXPECT_FALSE(layer_src_root->descendant_needs_push_properties()); 238 layer_src_root->layer_tree_host()->LayerNeedsPushPropertiesForTesting(
237 EXPECT_FALSE(layer_src_a->needs_push_properties()); 239 layer_src_root.get()));
238 EXPECT_FALSE(layer_src_a->descendant_needs_push_properties()); 240 EXPECT_FALSE(
239 EXPECT_FALSE(layer_src_b->needs_push_properties()); 241 layer_src_a->layer_tree_host()->LayerNeedsPushPropertiesForTesting(
240 EXPECT_FALSE(layer_src_b->descendant_needs_push_properties()); 242 layer_src_a.get()));
241 EXPECT_FALSE(layer_src_b_mask->needs_push_properties()); 243 EXPECT_FALSE(
242 EXPECT_FALSE(layer_src_b_mask->descendant_needs_push_properties()); 244 layer_src_b->layer_tree_host()->LayerNeedsPushPropertiesForTesting(
243 EXPECT_FALSE(layer_src_b_replica->needs_push_properties()); 245 layer_src_b.get()));
244 EXPECT_FALSE(layer_src_b_replica->descendant_needs_push_properties()); 246 EXPECT_FALSE(
245 EXPECT_FALSE(layer_src_c->needs_push_properties()); 247 layer_src_b_mask->layer_tree_host()->LayerNeedsPushPropertiesForTesting(
246 EXPECT_FALSE(layer_src_c->descendant_needs_push_properties()); 248 layer_src_b_mask.get()));
247 EXPECT_FALSE(layer_src_d->needs_push_properties()); 249 EXPECT_FALSE(
248 EXPECT_FALSE(layer_src_d->descendant_needs_push_properties()); 250 layer_src_b_replica->layer_tree_host()
251 ->LayerNeedsPushPropertiesForTesting(layer_src_b_replica.get()));
252 EXPECT_FALSE(
253 layer_src_c->layer_tree_host()->LayerNeedsPushPropertiesForTesting(
254 layer_src_c.get()));
255 EXPECT_FALSE(
256 layer_src_d->layer_tree_host()->LayerNeedsPushPropertiesForTesting(
257 layer_src_d.get()));
249 258
250 // Only 5 of the layers should have been serialized. 259 // Only 4 of the layers should have been serialized.
251 ASSERT_EQ(5, layer_update.layers_size()); 260 ASSERT_EQ(4, layer_update.layers_size());
252 EXPECT_EQ(layer_src_root->id(), layer_update.layers(0).id()); 261 for (int index = 0; index < layer_update.layers_size(); index++)
253 dest_root = layer_update.layers(0); 262 EXPECT_NE(dirty_layer_ids.find(layer_update.layers(index).id()),
254 EXPECT_EQ(layer_src_a->id(), layer_update.layers(1).id()); 263 dirty_layer_ids.end());
255 dest_a = layer_update.layers(1); 264 layer_src_root->SetLayerTreeHost(nullptr);
256 EXPECT_EQ(layer_src_b->id(), layer_update.layers(2).id());
257 dest_b = layer_update.layers(2);
258 EXPECT_EQ(layer_src_d->id(), layer_update.layers(3).id());
259 dest_d = layer_update.layers(3);
260 EXPECT_EQ(layer_src_b_mask->id(), layer_update.layers(4).id());
261 proto::LayerProperties dest_b_mask = layer_update.layers(4);
262
263 // Ensure the properties and dependants metadata is correctly serialized.
264 EXPECT_FALSE(dest_root.needs_push_properties());
265 EXPECT_EQ(2, dest_root.num_dependents_need_push_properties());
266 EXPECT_FALSE(dest_root.has_base());
267
268 EXPECT_TRUE(dest_a.needs_push_properties());
269 EXPECT_EQ(0, dest_a.num_dependents_need_push_properties());
270 EXPECT_TRUE(dest_a.has_base());
271
272 EXPECT_TRUE(dest_b.needs_push_properties());
273 EXPECT_EQ(2, dest_b.num_dependents_need_push_properties());
274 EXPECT_TRUE(dest_b.has_base());
275
276 EXPECT_TRUE(dest_d.needs_push_properties());
277 EXPECT_EQ(0, dest_d.num_dependents_need_push_properties());
278 EXPECT_TRUE(dest_d.has_base());
279
280 EXPECT_TRUE(dest_b_mask.needs_push_properties());
281 EXPECT_EQ(0, dest_b_mask.num_dependents_need_push_properties());
282 EXPECT_TRUE(dest_b_mask.has_base());
283 } 265 }
284 266
285 TEST_F(LayerProtoConverterTest, RecursivePropertiesSerializationSingleChild) { 267 TEST_F(LayerProtoConverterTest, RecursivePropertiesSerializationSingleChild) {
286 /* Testing serialization of properties for a tree that looks like this: 268 /* Testing serialization of properties for a tree that looks like this:
287 root+ 269 root+
288 \ 270 \
289 b*+[mask:*] 271 b*+[mask:*]
290 \ 272 \
291 c 273 c
292 Layers marked with * have changed properties. 274 Layers marked with * have changed properties.
293 Layers marked with + have descendants with changed properties. 275 Layers marked with + have descendants with changed properties.
294 Layer b also has a mask layer. 276 Layer b also has a mask layer.
295 */ 277 */
296 scoped_refptr<Layer> layer_src_root = Layer::Create(); 278 scoped_refptr<Layer> layer_src_root = Layer::Create();
297 scoped_refptr<Layer> layer_src_b = Layer::Create(); 279 scoped_refptr<Layer> layer_src_b = Layer::Create();
298 scoped_refptr<Layer> layer_src_b_mask = Layer::Create(); 280 scoped_refptr<Layer> layer_src_b_mask = Layer::Create();
299 scoped_refptr<Layer> layer_src_c = Layer::Create(); 281 scoped_refptr<Layer> layer_src_c = Layer::Create();
300 layer_src_root->AddChild(layer_src_b); 282 layer_src_root->AddChild(layer_src_b);
301 layer_src_b->AddChild(layer_src_c); 283 layer_src_b->AddChild(layer_src_c);
302 layer_src_b->SetMaskLayer(layer_src_b_mask.get()); 284 layer_src_b->SetMaskLayer(layer_src_b_mask.get());
285 layer_src_root->SetLayerTreeHost(layer_tree_host_.get());
303 286
304 proto::LayerUpdate layer_update; 287 proto::LayerUpdate layer_update;
305 LayerProtoConverter::SerializeLayerProperties(layer_src_root.get(), 288 LayerProtoConverter::SerializeLayerProperties(
306 &layer_update); 289 layer_src_root->layer_tree_host(), &layer_update);
307 // AddChild changes stacking order of child and we need to push proeprties of 290 // All layers need to push properties as their layer tree host changed.
308 // child. 291 ASSERT_EQ(4, layer_update.layers_size());
309 ASSERT_EQ(3, layer_update.layers_size());
310 layer_update.Clear(); 292 layer_update.Clear();
311 293
294 std::unordered_set<int> dirty_layer_ids;
312 layer_src_b->SetNeedsPushProperties(); 295 layer_src_b->SetNeedsPushProperties();
296 dirty_layer_ids.insert(layer_src_b->id());
313 layer_src_b_mask->SetNeedsPushProperties(); 297 layer_src_b_mask->SetNeedsPushProperties();
298 dirty_layer_ids.insert(layer_src_b_mask->id());
314 299
315 LayerProtoConverter::SerializeLayerProperties(layer_src_root.get(), 300 LayerProtoConverter::SerializeLayerProperties(
316 &layer_update); 301 layer_src_root->layer_tree_host(), &layer_update);
317 302
318 // All flags for pushing properties should have been cleared. 303 // All flags for pushing properties should have been cleared.
319 EXPECT_FALSE(layer_src_root->needs_push_properties()); 304 EXPECT_FALSE(
320 EXPECT_FALSE(layer_src_root->descendant_needs_push_properties()); 305 layer_src_root->layer_tree_host()->LayerNeedsPushPropertiesForTesting(
321 EXPECT_FALSE(layer_src_b->needs_push_properties()); 306 layer_src_root.get()));
322 EXPECT_FALSE(layer_src_b->descendant_needs_push_properties()); 307 EXPECT_FALSE(
323 EXPECT_FALSE(layer_src_b_mask->needs_push_properties()); 308 layer_src_b->layer_tree_host()->LayerNeedsPushPropertiesForTesting(
324 EXPECT_FALSE(layer_src_b_mask->descendant_needs_push_properties()); 309 layer_src_b.get()));
325 EXPECT_FALSE(layer_src_c->needs_push_properties()); 310 EXPECT_FALSE(
326 EXPECT_FALSE(layer_src_c->descendant_needs_push_properties()); 311 layer_src_b_mask->layer_tree_host()->LayerNeedsPushPropertiesForTesting(
312 layer_src_b_mask.get()));
313 EXPECT_FALSE(
314 layer_src_c->layer_tree_host()->LayerNeedsPushPropertiesForTesting(
315 layer_src_c.get()));
327 316
328 // Only 3 of the layers should have been serialized. 317 // Only 2 of the layers should have been serialized.
329 ASSERT_EQ(3, layer_update.layers_size()); 318 ASSERT_EQ(2, layer_update.layers_size());
330 EXPECT_EQ(layer_src_root->id(), layer_update.layers(0).id()); 319 for (int index = 0; index < layer_update.layers_size(); index++)
331 proto::LayerProperties dest_root = layer_update.layers(0); 320 EXPECT_NE(dirty_layer_ids.find(layer_update.layers(index).id()),
332 EXPECT_EQ(layer_src_b->id(), layer_update.layers(1).id()); 321 dirty_layer_ids.end());
333 proto::LayerProperties dest_b = layer_update.layers(1); 322 layer_src_root->SetLayerTreeHost(nullptr);
334 EXPECT_EQ(layer_src_b_mask->id(), layer_update.layers(2).id());
335 proto::LayerProperties dest_b_mask = layer_update.layers(2);
336
337 // Ensure the properties and dependants metadata is correctly serialized.
338 EXPECT_FALSE(dest_root.needs_push_properties());
339 EXPECT_EQ(1, dest_root.num_dependents_need_push_properties());
340 EXPECT_FALSE(dest_root.has_base());
341
342 EXPECT_TRUE(dest_b.needs_push_properties());
343 EXPECT_EQ(1, dest_b.num_dependents_need_push_properties());
344 EXPECT_TRUE(dest_b.has_base());
345
346 EXPECT_TRUE(dest_b_mask.needs_push_properties());
347 EXPECT_EQ(0, dest_b_mask.num_dependents_need_push_properties());
348 EXPECT_TRUE(dest_b_mask.has_base());
349 }
350
351 TEST_F(LayerProtoConverterTest, DeserializeLayerProperties) {
352 /* Testing deserialization of properties for a tree that looks like this:
353 root*+
354 / \
355 a b+
356 \
357 c*
358 Layers marked with * have changed properties.
359 Layers marked with + have descendants with changed properties.
360 */
361 proto::LayerUpdate updates;
362
363 scoped_refptr<Layer> root = Layer::Create();
364 root->SetLayerTreeHost(layer_tree_host_.get());
365 proto::LayerProperties* root_props = updates.add_layers();
366 root_props->set_id(root->id());
367 root_props->set_needs_push_properties(true);
368 root_props->set_num_dependents_need_push_properties(1);
369 root_props->mutable_base();
370
371 scoped_refptr<Layer> a = Layer::Create();
372 a->SetLayerTreeHost(layer_tree_host_.get());
373 proto::LayerProperties* a_props = updates.add_layers();
374 a_props->set_id(a->id());
375 a_props->set_needs_push_properties(false);
376 a_props->set_num_dependents_need_push_properties(0);
377 root->AddChild(a);
378
379 scoped_refptr<Layer> b = Layer::Create();
380 b->SetLayerTreeHost(layer_tree_host_.get());
381 proto::LayerProperties* b_props = updates.add_layers();
382 b_props->set_id(b->id());
383 b_props->set_needs_push_properties(false);
384 b_props->set_num_dependents_need_push_properties(1);
385 root->AddChild(b);
386
387 scoped_refptr<Layer> c = Layer::Create();
388 c->SetLayerTreeHost(layer_tree_host_.get());
389 proto::LayerProperties* c_props = updates.add_layers();
390 c_props->set_id(c->id());
391 c_props->set_needs_push_properties(true);
392 c_props->set_num_dependents_need_push_properties(0);
393 c_props->mutable_base();
394 b->AddChild(c);
395
396 LayerProtoConverter::DeserializeLayerProperties(root.get(), updates);
397
398 EXPECT_TRUE(root->needs_push_properties());
399 EXPECT_TRUE(root->descendant_needs_push_properties());
400
401 EXPECT_FALSE(a->needs_push_properties());
402 EXPECT_FALSE(a->descendant_needs_push_properties());
403
404 EXPECT_FALSE(b->needs_push_properties());
405 EXPECT_TRUE(b->descendant_needs_push_properties());
406
407 EXPECT_TRUE(c->needs_push_properties());
408 EXPECT_FALSE(c->descendant_needs_push_properties());
409
410 // Recursively clear out LayerTreeHost.
411 root->SetLayerTreeHost(nullptr);
412 } 323 }
413 324
414 TEST_F(LayerProtoConverterTest, PictureLayerTypeSerialization) { 325 TEST_F(LayerProtoConverterTest, PictureLayerTypeSerialization) {
415 // Make sure that PictureLayers serialize to the 326 // Make sure that PictureLayers serialize to the
416 // proto::LayerType::PICTURE_LAYER type. 327 // proto::LayerType::PICTURE_LAYER type.
417 scoped_refptr<PictureLayer> layer = 328 scoped_refptr<PictureLayer> layer =
418 PictureLayer::Create(EmptyContentLayerClient::GetInstance()); 329 PictureLayer::Create(EmptyContentLayerClient::GetInstance());
419 330
420 proto::LayerNode layer_hierarchy; 331 proto::LayerNode layer_hierarchy;
421 LayerProtoConverter::SerializeLayerHierarchy(layer.get(), &layer_hierarchy); 332 LayerProtoConverter::SerializeLayerHierarchy(layer.get(), &layer_hierarchy);
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
470 381
471 // Check that the layer type is equal by using the type this layer would 382 // Check that the layer type is equal by using the type this layer would
472 // serialize to. 383 // serialize to.
473 proto::LayerNode layer_node; 384 proto::LayerNode layer_node;
474 new_root->SetTypeForProtoSerialization(&layer_node); 385 new_root->SetTypeForProtoSerialization(&layer_node);
475 EXPECT_EQ(proto::LayerNode::HEADS_UP_DISPLAY_LAYER, layer_node.type()); 386 EXPECT_EQ(proto::LayerNode::HEADS_UP_DISPLAY_LAYER, layer_node.type());
476 } 387 }
477 388
478 } // namespace 389 } // namespace
479 } // namespace cc 390 } // namespace cc
OLDNEW
« no previous file with comments | « cc/layers/layer_proto_converter.cc ('k') | cc/layers/layer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698