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

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

Issue 1783613004: CC Animation: Erase cc::LayerSettings everywhere. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@eraseandroid
Patch Set: Rebase. 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_settings.h » ('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/layer_settings.h"
11 #include "cc/layers/picture_layer.h" 10 #include "cc/layers/picture_layer.h"
12 #include "cc/proto/layer.pb.h" 11 #include "cc/proto/layer.pb.h"
13 #include "cc/test/fake_layer_tree_host.h" 12 #include "cc/test/fake_layer_tree_host.h"
14 #include "cc/test/fake_layer_tree_host_client.h" 13 #include "cc/test/fake_layer_tree_host_client.h"
15 #include "cc/test/test_task_graph_runner.h" 14 #include "cc/test/test_task_graph_runner.h"
16 #include "cc/trees/layer_tree_settings.h" 15 #include "cc/trees/layer_tree_settings.h"
17 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
18 17
19 namespace cc { 18 namespace cc {
20 namespace { 19 namespace {
(...skipping 20 matching lines...) Expand all
41 40
42 TEST_F(LayerProtoConverterTest, TestKeepingRoot) { 41 TEST_F(LayerProtoConverterTest, TestKeepingRoot) {
43 /* Test deserialization of a tree that looks like: 42 /* Test deserialization of a tree that looks like:
44 root 43 root
45 / \ 44 / \
46 a b 45 a b
47 \ 46 \
48 c 47 c
49 The old root node will be reused during deserialization. 48 The old root node will be reused during deserialization.
50 */ 49 */
51 scoped_refptr<Layer> old_root = Layer::Create(LayerSettings()); 50 scoped_refptr<Layer> old_root = Layer::Create();
52 proto::LayerNode root_node; 51 proto::LayerNode root_node;
53 root_node.set_id(old_root->id()); 52 root_node.set_id(old_root->id());
54 root_node.set_type(proto::LayerNode::LAYER); 53 root_node.set_type(proto::LayerNode::LAYER);
55 54
56 proto::LayerNode* child_a_node = root_node.add_children(); 55 proto::LayerNode* child_a_node = root_node.add_children();
57 child_a_node->set_id(442); 56 child_a_node->set_id(442);
58 child_a_node->set_type(proto::LayerNode::LAYER); 57 child_a_node->set_type(proto::LayerNode::LAYER);
59 child_a_node->set_parent_id(old_root->id()); // root_node 58 child_a_node->set_parent_id(old_root->id()); // root_node
60 59
61 proto::LayerNode* child_b_node = root_node.add_children(); 60 proto::LayerNode* child_b_node = root_node.add_children();
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 proto::LayerNode* child_b_node = root_node.add_children(); 136 proto::LayerNode* child_b_node = root_node.add_children();
138 child_b_node->set_id(443); 137 child_b_node->set_id(443);
139 child_b_node->set_type(proto::LayerNode::LAYER); 138 child_b_node->set_type(proto::LayerNode::LAYER);
140 child_b_node->set_parent_id(root_node.id()); 139 child_b_node->set_parent_id(root_node.id());
141 140
142 proto::LayerNode* child_c_node = child_b_node->add_children(); 141 proto::LayerNode* child_c_node = child_b_node->add_children();
143 child_c_node->set_id(444); 142 child_c_node->set_id(444);
144 child_c_node->set_type(proto::LayerNode::LAYER); 143 child_c_node->set_type(proto::LayerNode::LAYER);
145 child_c_node->set_parent_id(child_b_node->id()); 144 child_c_node->set_parent_id(child_b_node->id());
146 145
147 scoped_refptr<Layer> old_root = Layer::Create(LayerSettings()); 146 scoped_refptr<Layer> old_root = Layer::Create();
148 scoped_refptr<Layer> new_root = 147 scoped_refptr<Layer> new_root =
149 LayerProtoConverter::DeserializeLayerHierarchy(old_root, root_node); 148 LayerProtoConverter::DeserializeLayerHierarchy(old_root, root_node);
150 149
151 // The new root should not be the same as the old root. 150 // The new root should not be the same as the old root.
152 EXPECT_EQ(root_node.id(), new_root->id()); 151 EXPECT_EQ(root_node.id(), new_root->id());
153 ASSERT_EQ(2u, new_root->children().size()); 152 ASSERT_EQ(2u, new_root->children().size());
154 scoped_refptr<Layer> child_a = new_root->children()[0]; 153 scoped_refptr<Layer> child_a = new_root->children()[0];
155 scoped_refptr<Layer> child_b = new_root->children()[1]; 154 scoped_refptr<Layer> child_b = new_root->children()[1];
156 155
157 EXPECT_EQ(child_a_node->id(), child_a->id()); 156 EXPECT_EQ(child_a_node->id(), child_a->id());
(...skipping 10 matching lines...) Expand all
168 /* Testing serialization of properties for a tree that looks like this: 167 /* Testing serialization of properties for a tree that looks like this:
169 root+ 168 root+
170 / \ 169 / \
171 a* b*+[mask:*,replica] 170 a* b*+[mask:*,replica]
172 / \ 171 / \
173 c d* 172 c d*
174 Layers marked with * have changed properties. 173 Layers marked with * have changed properties.
175 Layers marked with + have descendants with changed properties. 174 Layers marked with + have descendants with changed properties.
176 Layer b also has a mask layer and a replica layer. 175 Layer b also has a mask layer and a replica layer.
177 */ 176 */
178 scoped_refptr<Layer> layer_src_root = Layer::Create(LayerSettings()); 177 scoped_refptr<Layer> layer_src_root = Layer::Create();
179 scoped_refptr<Layer> layer_src_a = Layer::Create(LayerSettings()); 178 scoped_refptr<Layer> layer_src_a = Layer::Create();
180 scoped_refptr<Layer> layer_src_b = Layer::Create(LayerSettings()); 179 scoped_refptr<Layer> layer_src_b = Layer::Create();
181 scoped_refptr<Layer> layer_src_b_mask = Layer::Create(LayerSettings()); 180 scoped_refptr<Layer> layer_src_b_mask = Layer::Create();
182 scoped_refptr<Layer> layer_src_b_replica = Layer::Create(LayerSettings()); 181 scoped_refptr<Layer> layer_src_b_replica = Layer::Create();
183 scoped_refptr<Layer> layer_src_c = Layer::Create(LayerSettings()); 182 scoped_refptr<Layer> layer_src_c = Layer::Create();
184 scoped_refptr<Layer> layer_src_d = Layer::Create(LayerSettings()); 183 scoped_refptr<Layer> layer_src_d = Layer::Create();
185 layer_src_root->AddChild(layer_src_a); 184 layer_src_root->AddChild(layer_src_a);
186 layer_src_root->AddChild(layer_src_b); 185 layer_src_root->AddChild(layer_src_b);
187 layer_src_a->AddChild(layer_src_c); 186 layer_src_a->AddChild(layer_src_c);
188 layer_src_b->AddChild(layer_src_d); 187 layer_src_b->AddChild(layer_src_d);
189 layer_src_b->SetMaskLayer(layer_src_b_mask.get()); 188 layer_src_b->SetMaskLayer(layer_src_b_mask.get());
190 layer_src_b->SetReplicaLayer(layer_src_b_replica.get()); 189 layer_src_b->SetReplicaLayer(layer_src_b_replica.get());
191 190
192 proto::LayerUpdate layer_update; 191 proto::LayerUpdate layer_update;
193 LayerProtoConverter::SerializeLayerProperties(layer_src_root.get(), 192 LayerProtoConverter::SerializeLayerProperties(layer_src_root.get(),
194 &layer_update); 193 &layer_update);
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 /* Testing serialization of properties for a tree that looks like this: 286 /* Testing serialization of properties for a tree that looks like this:
288 root+ 287 root+
289 \ 288 \
290 b*+[mask:*] 289 b*+[mask:*]
291 \ 290 \
292 c 291 c
293 Layers marked with * have changed properties. 292 Layers marked with * have changed properties.
294 Layers marked with + have descendants with changed properties. 293 Layers marked with + have descendants with changed properties.
295 Layer b also has a mask layer. 294 Layer b also has a mask layer.
296 */ 295 */
297 scoped_refptr<Layer> layer_src_root = Layer::Create(LayerSettings()); 296 scoped_refptr<Layer> layer_src_root = Layer::Create();
298 scoped_refptr<Layer> layer_src_b = Layer::Create(LayerSettings()); 297 scoped_refptr<Layer> layer_src_b = Layer::Create();
299 scoped_refptr<Layer> layer_src_b_mask = Layer::Create(LayerSettings()); 298 scoped_refptr<Layer> layer_src_b_mask = Layer::Create();
300 scoped_refptr<Layer> layer_src_c = Layer::Create(LayerSettings()); 299 scoped_refptr<Layer> layer_src_c = Layer::Create();
301 layer_src_root->AddChild(layer_src_b); 300 layer_src_root->AddChild(layer_src_b);
302 layer_src_b->AddChild(layer_src_c); 301 layer_src_b->AddChild(layer_src_c);
303 layer_src_b->SetMaskLayer(layer_src_b_mask.get()); 302 layer_src_b->SetMaskLayer(layer_src_b_mask.get());
304 303
305 proto::LayerUpdate layer_update; 304 proto::LayerUpdate layer_update;
306 LayerProtoConverter::SerializeLayerProperties(layer_src_root.get(), 305 LayerProtoConverter::SerializeLayerProperties(layer_src_root.get(),
307 &layer_update); 306 &layer_update);
308 // AddChild changes stacking order of child and we need to push proeprties of 307 // AddChild changes stacking order of child and we need to push proeprties of
309 // child. 308 // child.
310 ASSERT_EQ(3, layer_update.layers_size()); 309 ASSERT_EQ(3, layer_update.layers_size());
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
354 root*+ 353 root*+
355 / \ 354 / \
356 a b+ 355 a b+
357 \ 356 \
358 c* 357 c*
359 Layers marked with * have changed properties. 358 Layers marked with * have changed properties.
360 Layers marked with + have descendants with changed properties. 359 Layers marked with + have descendants with changed properties.
361 */ 360 */
362 proto::LayerUpdate updates; 361 proto::LayerUpdate updates;
363 362
364 scoped_refptr<Layer> root = Layer::Create(LayerSettings()); 363 scoped_refptr<Layer> root = Layer::Create();
365 root->SetLayerTreeHost(layer_tree_host_.get()); 364 root->SetLayerTreeHost(layer_tree_host_.get());
366 proto::LayerProperties* root_props = updates.add_layers(); 365 proto::LayerProperties* root_props = updates.add_layers();
367 root_props->set_id(root->id()); 366 root_props->set_id(root->id());
368 root_props->set_needs_push_properties(true); 367 root_props->set_needs_push_properties(true);
369 root_props->set_num_dependents_need_push_properties(1); 368 root_props->set_num_dependents_need_push_properties(1);
370 root_props->mutable_base(); 369 root_props->mutable_base();
371 370
372 scoped_refptr<Layer> a = Layer::Create(LayerSettings()); 371 scoped_refptr<Layer> a = Layer::Create();
373 a->SetLayerTreeHost(layer_tree_host_.get()); 372 a->SetLayerTreeHost(layer_tree_host_.get());
374 proto::LayerProperties* a_props = updates.add_layers(); 373 proto::LayerProperties* a_props = updates.add_layers();
375 a_props->set_id(a->id()); 374 a_props->set_id(a->id());
376 a_props->set_needs_push_properties(false); 375 a_props->set_needs_push_properties(false);
377 a_props->set_num_dependents_need_push_properties(0); 376 a_props->set_num_dependents_need_push_properties(0);
378 root->AddChild(a); 377 root->AddChild(a);
379 378
380 scoped_refptr<Layer> b = Layer::Create(LayerSettings()); 379 scoped_refptr<Layer> b = Layer::Create();
381 b->SetLayerTreeHost(layer_tree_host_.get()); 380 b->SetLayerTreeHost(layer_tree_host_.get());
382 proto::LayerProperties* b_props = updates.add_layers(); 381 proto::LayerProperties* b_props = updates.add_layers();
383 b_props->set_id(b->id()); 382 b_props->set_id(b->id());
384 b_props->set_needs_push_properties(false); 383 b_props->set_needs_push_properties(false);
385 b_props->set_num_dependents_need_push_properties(1); 384 b_props->set_num_dependents_need_push_properties(1);
386 root->AddChild(b); 385 root->AddChild(b);
387 386
388 scoped_refptr<Layer> c = Layer::Create(LayerSettings()); 387 scoped_refptr<Layer> c = Layer::Create();
389 c->SetLayerTreeHost(layer_tree_host_.get()); 388 c->SetLayerTreeHost(layer_tree_host_.get());
390 proto::LayerProperties* c_props = updates.add_layers(); 389 proto::LayerProperties* c_props = updates.add_layers();
391 c_props->set_id(c->id()); 390 c_props->set_id(c->id());
392 c_props->set_needs_push_properties(true); 391 c_props->set_needs_push_properties(true);
393 c_props->set_num_dependents_need_push_properties(0); 392 c_props->set_num_dependents_need_push_properties(0);
394 c_props->mutable_base(); 393 c_props->mutable_base();
395 b->AddChild(c); 394 b->AddChild(c);
396 395
397 LayerProtoConverter::DeserializeLayerProperties(root.get(), updates); 396 LayerProtoConverter::DeserializeLayerProperties(root.get(), updates);
398 397
399 EXPECT_TRUE(root->needs_push_properties()); 398 EXPECT_TRUE(root->needs_push_properties());
400 EXPECT_TRUE(root->descendant_needs_push_properties()); 399 EXPECT_TRUE(root->descendant_needs_push_properties());
401 400
402 EXPECT_FALSE(a->needs_push_properties()); 401 EXPECT_FALSE(a->needs_push_properties());
403 EXPECT_FALSE(a->descendant_needs_push_properties()); 402 EXPECT_FALSE(a->descendant_needs_push_properties());
404 403
405 EXPECT_FALSE(b->needs_push_properties()); 404 EXPECT_FALSE(b->needs_push_properties());
406 EXPECT_TRUE(b->descendant_needs_push_properties()); 405 EXPECT_TRUE(b->descendant_needs_push_properties());
407 406
408 EXPECT_TRUE(c->needs_push_properties()); 407 EXPECT_TRUE(c->needs_push_properties());
409 EXPECT_FALSE(c->descendant_needs_push_properties()); 408 EXPECT_FALSE(c->descendant_needs_push_properties());
410 409
411 // Recursively clear out LayerTreeHost. 410 // Recursively clear out LayerTreeHost.
412 root->SetLayerTreeHost(nullptr); 411 root->SetLayerTreeHost(nullptr);
413 } 412 }
414 413
415 TEST_F(LayerProtoConverterTest, PictureLayerTypeSerialization) { 414 TEST_F(LayerProtoConverterTest, PictureLayerTypeSerialization) {
416 // Make sure that PictureLayers serialize to the 415 // Make sure that PictureLayers serialize to the
417 // proto::LayerType::PICTURE_LAYER type. 416 // proto::LayerType::PICTURE_LAYER type.
418 scoped_refptr<PictureLayer> layer = PictureLayer::Create( 417 scoped_refptr<PictureLayer> layer =
419 LayerSettings(), EmptyContentLayerClient::GetInstance()); 418 PictureLayer::Create(EmptyContentLayerClient::GetInstance());
420 419
421 proto::LayerNode layer_hierarchy; 420 proto::LayerNode layer_hierarchy;
422 LayerProtoConverter::SerializeLayerHierarchy(layer.get(), &layer_hierarchy); 421 LayerProtoConverter::SerializeLayerHierarchy(layer.get(), &layer_hierarchy);
423 EXPECT_EQ(proto::LayerNode::PICTURE_LAYER, layer_hierarchy.type()); 422 EXPECT_EQ(proto::LayerNode::PICTURE_LAYER, layer_hierarchy.type());
424 } 423 }
425 424
426 TEST_F(LayerProtoConverterTest, PictureLayerTypeDeserialization) { 425 TEST_F(LayerProtoConverterTest, PictureLayerTypeDeserialization) {
427 // Make sure that proto::LayerType::PICTURE_LAYER ends up building a 426 // Make sure that proto::LayerType::PICTURE_LAYER ends up building a
428 // PictureLayer. 427 // PictureLayer.
429 scoped_refptr<Layer> old_root = PictureLayer::Create( 428 scoped_refptr<Layer> old_root =
430 LayerSettings(), EmptyContentLayerClient::GetInstance()); 429 PictureLayer::Create(EmptyContentLayerClient::GetInstance());
431 proto::LayerNode root_node; 430 proto::LayerNode root_node;
432 root_node.set_id(old_root->id()); 431 root_node.set_id(old_root->id());
433 root_node.set_type(proto::LayerNode::PICTURE_LAYER); 432 root_node.set_type(proto::LayerNode::PICTURE_LAYER);
434 433
435 scoped_refptr<Layer> new_root = 434 scoped_refptr<Layer> new_root =
436 LayerProtoConverter::DeserializeLayerHierarchy(old_root, root_node); 435 LayerProtoConverter::DeserializeLayerHierarchy(old_root, root_node);
437 436
438 // Validate that the ids are equal. 437 // Validate that the ids are equal.
439 EXPECT_EQ(old_root->id(), new_root->id()); 438 EXPECT_EQ(old_root->id(), new_root->id());
440 439
441 // Check that the layer type is equal by using the type this layer would 440 // Check that the layer type is equal by using the type this layer would
442 // serialize to. 441 // serialize to.
443 proto::LayerNode layer_node; 442 proto::LayerNode layer_node;
444 new_root->SetTypeForProtoSerialization(&layer_node); 443 new_root->SetTypeForProtoSerialization(&layer_node);
445 EXPECT_EQ(proto::LayerNode::PICTURE_LAYER, layer_node.type()); 444 EXPECT_EQ(proto::LayerNode::PICTURE_LAYER, layer_node.type());
446 } 445 }
447 446
448 TEST_F(LayerProtoConverterTest, HudLayerTypeSerialization) { 447 TEST_F(LayerProtoConverterTest, HudLayerTypeSerialization) {
449 // Make sure that PictureLayers serialize to the 448 // Make sure that PictureLayers serialize to the
450 // proto::LayerType::HEADS_UP_DISPLAY_LAYER type. 449 // proto::LayerType::HEADS_UP_DISPLAY_LAYER type.
451 scoped_refptr<HeadsUpDisplayLayer> layer = 450 scoped_refptr<HeadsUpDisplayLayer> layer = HeadsUpDisplayLayer::Create();
452 HeadsUpDisplayLayer::Create(LayerSettings());
453 451
454 proto::LayerNode layer_hierarchy; 452 proto::LayerNode layer_hierarchy;
455 LayerProtoConverter::SerializeLayerHierarchy(layer.get(), &layer_hierarchy); 453 LayerProtoConverter::SerializeLayerHierarchy(layer.get(), &layer_hierarchy);
456 EXPECT_EQ(proto::LayerNode::HEADS_UP_DISPLAY_LAYER, layer_hierarchy.type()); 454 EXPECT_EQ(proto::LayerNode::HEADS_UP_DISPLAY_LAYER, layer_hierarchy.type());
457 } 455 }
458 456
459 TEST_F(LayerProtoConverterTest, HudLayerTypeDeserialization) { 457 TEST_F(LayerProtoConverterTest, HudLayerTypeDeserialization) {
460 // Make sure that proto::LayerType::HEADS_UP_DISPLAY_LAYER ends up building a 458 // Make sure that proto::LayerType::HEADS_UP_DISPLAY_LAYER ends up building a
461 // HeadsUpDisplayLayer. 459 // HeadsUpDisplayLayer.
462 scoped_refptr<Layer> old_root = HeadsUpDisplayLayer::Create(LayerSettings()); 460 scoped_refptr<Layer> old_root = HeadsUpDisplayLayer::Create();
463 proto::LayerNode root_node; 461 proto::LayerNode root_node;
464 root_node.set_id(old_root->id()); 462 root_node.set_id(old_root->id());
465 root_node.set_type(proto::LayerNode::HEADS_UP_DISPLAY_LAYER); 463 root_node.set_type(proto::LayerNode::HEADS_UP_DISPLAY_LAYER);
466 464
467 scoped_refptr<Layer> new_root = 465 scoped_refptr<Layer> new_root =
468 LayerProtoConverter::DeserializeLayerHierarchy(old_root, root_node); 466 LayerProtoConverter::DeserializeLayerHierarchy(old_root, root_node);
469 467
470 // Validate that the ids are equal. 468 // Validate that the ids are equal.
471 EXPECT_EQ(old_root->id(), new_root->id()); 469 EXPECT_EQ(old_root->id(), new_root->id());
472 470
473 // Check that the layer type is equal by using the type this layer would 471 // Check that the layer type is equal by using the type this layer would
474 // serialize to. 472 // serialize to.
475 proto::LayerNode layer_node; 473 proto::LayerNode layer_node;
476 new_root->SetTypeForProtoSerialization(&layer_node); 474 new_root->SetTypeForProtoSerialization(&layer_node);
477 EXPECT_EQ(proto::LayerNode::HEADS_UP_DISPLAY_LAYER, layer_node.type()); 475 EXPECT_EQ(proto::LayerNode::HEADS_UP_DISPLAY_LAYER, layer_node.type());
478 } 476 }
479 477
480 } // namespace 478 } // namespace
481 } // namespace cc 479 } // namespace cc
OLDNEW
« no previous file with comments | « cc/layers/layer_proto_converter.cc ('k') | cc/layers/layer_settings.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698