OLD | NEW |
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/layer.h" | 8 #include "cc/layers/layer.h" |
8 #include "cc/layers/layer_settings.h" | 9 #include "cc/layers/layer_settings.h" |
| 10 #include "cc/layers/picture_layer.h" |
9 #include "cc/proto/layer.pb.h" | 11 #include "cc/proto/layer.pb.h" |
10 #include "cc/test/fake_layer_tree_host.h" | 12 #include "cc/test/fake_layer_tree_host.h" |
11 #include "cc/test/fake_layer_tree_host_client.h" | 13 #include "cc/test/fake_layer_tree_host_client.h" |
12 #include "cc/test/test_task_graph_runner.h" | 14 #include "cc/test/test_task_graph_runner.h" |
13 #include "cc/trees/layer_tree_settings.h" | 15 #include "cc/trees/layer_tree_settings.h" |
14 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
15 | 17 |
16 namespace cc { | 18 namespace cc { |
17 namespace { | 19 namespace { |
18 class LayerProtoConverterTest : public testing::Test { | 20 class LayerProtoConverterTest : public testing::Test { |
(...skipping 22 matching lines...) Expand all Loading... |
41 root | 43 root |
42 / \ | 44 / \ |
43 a b | 45 a b |
44 \ | 46 \ |
45 c | 47 c |
46 The old root node will be reused during deserialization. | 48 The old root node will be reused during deserialization. |
47 */ | 49 */ |
48 scoped_refptr<Layer> old_root = Layer::Create(LayerSettings()); | 50 scoped_refptr<Layer> old_root = Layer::Create(LayerSettings()); |
49 proto::LayerNode root_node; | 51 proto::LayerNode root_node; |
50 root_node.set_id(old_root->id()); | 52 root_node.set_id(old_root->id()); |
51 root_node.set_type(proto::LayerType::Base); | 53 root_node.set_type(proto::LayerType::LAYER); |
52 | 54 |
53 proto::LayerNode* child_a_node = root_node.add_children(); | 55 proto::LayerNode* child_a_node = root_node.add_children(); |
54 child_a_node->set_id(442); | 56 child_a_node->set_id(442); |
55 child_a_node->set_type(proto::LayerType::Base); | 57 child_a_node->set_type(proto::LayerType::LAYER); |
56 child_a_node->set_parent_id(old_root->id()); // root_node | 58 child_a_node->set_parent_id(old_root->id()); // root_node |
57 | 59 |
58 proto::LayerNode* child_b_node = root_node.add_children(); | 60 proto::LayerNode* child_b_node = root_node.add_children(); |
59 child_b_node->set_id(443); | 61 child_b_node->set_id(443); |
60 child_b_node->set_type(proto::LayerType::Base); | 62 child_b_node->set_type(proto::LayerType::LAYER); |
61 child_b_node->set_parent_id(old_root->id()); // root_node | 63 child_b_node->set_parent_id(old_root->id()); // root_node |
62 | 64 |
63 proto::LayerNode* child_c_node = child_b_node->add_children(); | 65 proto::LayerNode* child_c_node = child_b_node->add_children(); |
64 child_c_node->set_id(444); | 66 child_c_node->set_id(444); |
65 child_c_node->set_type(proto::LayerType::Base); | 67 child_c_node->set_type(proto::LayerType::LAYER); |
66 child_c_node->set_parent_id(child_b_node->id()); | 68 child_c_node->set_parent_id(child_b_node->id()); |
67 | 69 |
68 scoped_refptr<Layer> new_root = | 70 scoped_refptr<Layer> new_root = |
69 LayerProtoConverter::DeserializeLayerHierarchy(old_root, root_node); | 71 LayerProtoConverter::DeserializeLayerHierarchy(old_root, root_node); |
70 | 72 |
71 // The new root should not be the same as the old root. | 73 // The new root should not be the same as the old root. |
72 EXPECT_EQ(old_root->id(), new_root->id()); | 74 EXPECT_EQ(old_root->id(), new_root->id()); |
73 ASSERT_EQ(2u, new_root->children().size()); | 75 ASSERT_EQ(2u, new_root->children().size()); |
74 scoped_refptr<Layer> child_a = new_root->children()[0]; | 76 scoped_refptr<Layer> child_a = new_root->children()[0]; |
75 scoped_refptr<Layer> child_b = new_root->children()[1]; | 77 scoped_refptr<Layer> child_b = new_root->children()[1]; |
(...skipping 12 matching lines...) Expand all Loading... |
88 /* Test deserialization of a tree that looks like: | 90 /* Test deserialization of a tree that looks like: |
89 root | 91 root |
90 / \ | 92 / \ |
91 a b | 93 a b |
92 \ | 94 \ |
93 c | 95 c |
94 The old root node will be swapped out during deserialization. | 96 The old root node will be swapped out during deserialization. |
95 */ | 97 */ |
96 proto::LayerNode root_node; | 98 proto::LayerNode root_node; |
97 root_node.set_id(441); | 99 root_node.set_id(441); |
98 root_node.set_type(proto::LayerType::Base); | 100 root_node.set_type(proto::LayerType::LAYER); |
99 | 101 |
100 proto::LayerNode* child_a_node = root_node.add_children(); | 102 proto::LayerNode* child_a_node = root_node.add_children(); |
101 child_a_node->set_id(442); | 103 child_a_node->set_id(442); |
102 child_a_node->set_type(proto::LayerType::Base); | 104 child_a_node->set_type(proto::LayerType::LAYER); |
103 child_a_node->set_parent_id(root_node.id()); | 105 child_a_node->set_parent_id(root_node.id()); |
104 | 106 |
105 proto::LayerNode* child_b_node = root_node.add_children(); | 107 proto::LayerNode* child_b_node = root_node.add_children(); |
106 child_b_node->set_id(443); | 108 child_b_node->set_id(443); |
107 child_b_node->set_type(proto::LayerType::Base); | 109 child_b_node->set_type(proto::LayerType::LAYER); |
108 child_b_node->set_parent_id(root_node.id()); | 110 child_b_node->set_parent_id(root_node.id()); |
109 | 111 |
110 proto::LayerNode* child_c_node = child_b_node->add_children(); | 112 proto::LayerNode* child_c_node = child_b_node->add_children(); |
111 child_c_node->set_id(444); | 113 child_c_node->set_id(444); |
112 child_c_node->set_type(proto::LayerType::Base); | 114 child_c_node->set_type(proto::LayerType::LAYER); |
113 child_c_node->set_parent_id(child_b_node->id()); | 115 child_c_node->set_parent_id(child_b_node->id()); |
114 | 116 |
115 scoped_refptr<Layer> old_root = Layer::Create(LayerSettings()); | 117 scoped_refptr<Layer> old_root = Layer::Create(LayerSettings()); |
116 scoped_refptr<Layer> new_root = | 118 scoped_refptr<Layer> new_root = |
117 LayerProtoConverter::DeserializeLayerHierarchy(old_root, root_node); | 119 LayerProtoConverter::DeserializeLayerHierarchy(old_root, root_node); |
118 | 120 |
119 // The new root should not be the same as the old root. | 121 // The new root should not be the same as the old root. |
120 EXPECT_EQ(root_node.id(), new_root->id()); | 122 EXPECT_EQ(root_node.id(), new_root->id()); |
121 ASSERT_EQ(2u, new_root->children().size()); | 123 ASSERT_EQ(2u, new_root->children().size()); |
122 scoped_refptr<Layer> child_a = new_root->children()[0]; | 124 scoped_refptr<Layer> child_a = new_root->children()[0]; |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
332 EXPECT_FALSE(b->needs_push_properties()); | 334 EXPECT_FALSE(b->needs_push_properties()); |
333 EXPECT_TRUE(b->descendant_needs_push_properties()); | 335 EXPECT_TRUE(b->descendant_needs_push_properties()); |
334 | 336 |
335 EXPECT_TRUE(c->needs_push_properties()); | 337 EXPECT_TRUE(c->needs_push_properties()); |
336 EXPECT_FALSE(c->descendant_needs_push_properties()); | 338 EXPECT_FALSE(c->descendant_needs_push_properties()); |
337 | 339 |
338 // Recursively clear out LayerTreeHost. | 340 // Recursively clear out LayerTreeHost. |
339 root->SetLayerTreeHost(nullptr); | 341 root->SetLayerTreeHost(nullptr); |
340 } | 342 } |
341 | 343 |
| 344 TEST_F(LayerProtoConverterTest, PictureLayerTypeSerialization) { |
| 345 // Make sure that PictureLayers serialize to the |
| 346 // proto::LayerType::PICTURE_LAYER type. |
| 347 scoped_refptr<PictureLayer> layer = PictureLayer::Create( |
| 348 LayerSettings(), EmptyContentLayerClient::GetInstance()); |
| 349 |
| 350 proto::LayerNode layer_hierarchy; |
| 351 LayerProtoConverter::SerializeLayerHierarchy(layer.get(), &layer_hierarchy); |
| 352 EXPECT_EQ(proto::LayerType::PICTURE_LAYER, layer_hierarchy.type()); |
| 353 } |
| 354 |
| 355 TEST_F(LayerProtoConverterTest, PictureLayerTypeDeserialization) { |
| 356 // Make sure that proto::LayerType::PICTURE_LAYER ends up building a |
| 357 // PictureLayer. |
| 358 scoped_refptr<Layer> old_root = PictureLayer::Create( |
| 359 LayerSettings(), EmptyContentLayerClient::GetInstance()); |
| 360 proto::LayerNode root_node; |
| 361 root_node.set_id(old_root->id()); |
| 362 root_node.set_type(proto::LayerType::PICTURE_LAYER); |
| 363 |
| 364 scoped_refptr<Layer> new_root = |
| 365 LayerProtoConverter::DeserializeLayerHierarchy(old_root, root_node); |
| 366 |
| 367 // Validate that the ids are equal. |
| 368 EXPECT_EQ(old_root->id(), new_root->id()); |
| 369 |
| 370 // Check that the layer type is equal by using the type this layer would |
| 371 // serialize to. |
| 372 proto::LayerNode layer_node; |
| 373 new_root->SetTypeForProtoSerialization(&layer_node); |
| 374 EXPECT_EQ(proto::LayerType::PICTURE_LAYER, layer_node.type()); |
| 375 } |
| 376 |
342 } // namespace | 377 } // namespace |
343 } // namespace cc | 378 } // namespace cc |
OLD | NEW |