Chromium Code Reviews| 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/layer.h" | 7 #include "cc/layers/layer.h" |
| 8 #include "cc/proto/layer.pb.h" | 8 #include "cc/proto/layer.pb.h" |
| 9 #include "cc/trees/layer_tree_settings.h" | 9 #include "cc/trees/layer_tree_settings.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 100 EXPECT_EQ(child_a_node->id(), child_a->id()); | 100 EXPECT_EQ(child_a_node->id(), child_a->id()); |
| 101 EXPECT_EQ(child_b_node->id(), child_b->id()); | 101 EXPECT_EQ(child_b_node->id(), child_b->id()); |
| 102 | 102 |
| 103 EXPECT_EQ(0u, child_a->children().size()); | 103 EXPECT_EQ(0u, child_a->children().size()); |
| 104 ASSERT_EQ(1u, child_b->children().size()); | 104 ASSERT_EQ(1u, child_b->children().size()); |
| 105 | 105 |
| 106 scoped_refptr<Layer> child_c = child_b->children()[0]; | 106 scoped_refptr<Layer> child_c = child_b->children()[0]; |
| 107 EXPECT_EQ(child_c_node->id(), child_c->id()); | 107 EXPECT_EQ(child_c_node->id(), child_c->id()); |
| 108 } | 108 } |
| 109 | 109 |
| 110 TEST(LayerProtoConverterTest, RecursivePropertiesSerialization) { | |
|
vmpstr
2015/11/18 04:05:25
Can you add a test for
root+ ----- b* [mask:*] --
nyquist
2015/11/18 07:15:59
Yeah, but from what I understand, for the b-node,
| |
| 111 /* Testing serialization of properties for a tree that looks like this: | |
| 112 root+ | |
| 113 / \ | |
| 114 a* b*+[mask:*,replica] | |
| 115 / \ | |
| 116 c d* | |
| 117 Layers marked with * have changed properties. | |
| 118 Layers marked with + have descendants with changed properties. | |
| 119 Layer b also has a mask layer and a replica layer. | |
| 120 */ | |
| 121 scoped_refptr<Layer> layer_src_root = Layer::Create(LayerSettings()); | |
| 122 scoped_refptr<Layer> layer_src_a = Layer::Create(LayerSettings()); | |
| 123 scoped_refptr<Layer> layer_src_b = Layer::Create(LayerSettings()); | |
| 124 scoped_refptr<Layer> layer_src_b_mask = Layer::Create(LayerSettings()); | |
| 125 scoped_refptr<Layer> layer_src_b_replica = Layer::Create(LayerSettings()); | |
| 126 scoped_refptr<Layer> layer_src_c = Layer::Create(LayerSettings()); | |
| 127 scoped_refptr<Layer> layer_src_d = Layer::Create(LayerSettings()); | |
| 128 layer_src_root->AddChild(layer_src_a); | |
| 129 layer_src_root->AddChild(layer_src_b); | |
| 130 layer_src_a->AddChild(layer_src_c); | |
| 131 layer_src_b->AddChild(layer_src_d); | |
| 132 layer_src_b->SetMaskLayer(layer_src_b_mask.get()); | |
| 133 layer_src_b->SetReplicaLayer(layer_src_b_replica.get()); | |
| 134 | |
| 135 layer_src_a->SetNeedsPushProperties(); | |
| 136 layer_src_b->SetNeedsPushProperties(); | |
| 137 layer_src_b_mask->SetNeedsPushProperties(); | |
| 138 layer_src_d->SetNeedsPushProperties(); | |
| 139 | |
| 140 proto::LayerUpdate layer_update; | |
| 141 LayerProtoConverter::SerializeLayerProperties(layer_src_root, &layer_update); | |
|
nyquist
2015/11/18 00:24:34
This test is literally the same as LayerTest::Recu
| |
| 142 | |
| 143 // All flags for pushing properties should have been cleared. | |
| 144 EXPECT_FALSE(layer_src_root->needs_push_properties()); | |
| 145 EXPECT_FALSE(layer_src_root->descendant_needs_push_properties()); | |
| 146 EXPECT_FALSE(layer_src_a->needs_push_properties()); | |
| 147 EXPECT_FALSE(layer_src_a->descendant_needs_push_properties()); | |
| 148 EXPECT_FALSE(layer_src_b->needs_push_properties()); | |
| 149 EXPECT_FALSE(layer_src_b->descendant_needs_push_properties()); | |
| 150 EXPECT_FALSE(layer_src_b_mask->needs_push_properties()); | |
| 151 EXPECT_FALSE(layer_src_b_mask->descendant_needs_push_properties()); | |
| 152 EXPECT_FALSE(layer_src_b_replica->needs_push_properties()); | |
| 153 EXPECT_FALSE(layer_src_b_replica->descendant_needs_push_properties()); | |
| 154 EXPECT_FALSE(layer_src_c->needs_push_properties()); | |
| 155 EXPECT_FALSE(layer_src_c->descendant_needs_push_properties()); | |
| 156 EXPECT_FALSE(layer_src_d->needs_push_properties()); | |
| 157 EXPECT_FALSE(layer_src_d->descendant_needs_push_properties()); | |
| 158 | |
| 159 // Only 5 of the layers should have been serialized. | |
| 160 ASSERT_EQ(5, layer_update.layers_size()); | |
| 161 EXPECT_EQ(layer_src_root->id(), layer_update.layers(0).id()); | |
| 162 proto::LayerProperties dest_root = layer_update.layers(0); | |
| 163 EXPECT_EQ(layer_src_a->id(), layer_update.layers(1).id()); | |
| 164 proto::LayerProperties dest_a = layer_update.layers(1); | |
| 165 EXPECT_EQ(layer_src_b->id(), layer_update.layers(2).id()); | |
| 166 proto::LayerProperties dest_b = layer_update.layers(2); | |
| 167 EXPECT_EQ(layer_src_d->id(), layer_update.layers(3).id()); | |
| 168 proto::LayerProperties dest_d = layer_update.layers(3); | |
| 169 EXPECT_EQ(layer_src_b_mask->id(), layer_update.layers(4).id()); | |
| 170 proto::LayerProperties dest_b_mask = layer_update.layers(4); | |
| 171 | |
| 172 // Ensure the properties and dependants metadata is correctly serialized. | |
| 173 EXPECT_FALSE(dest_root.needs_push_properties()); | |
| 174 EXPECT_EQ(2, dest_root.num_dependents_need_push_properties()); | |
| 175 EXPECT_FALSE(dest_root.has_base()); | |
| 176 | |
| 177 EXPECT_TRUE(dest_a.needs_push_properties()); | |
| 178 EXPECT_EQ(0, dest_a.num_dependents_need_push_properties()); | |
| 179 EXPECT_TRUE(dest_a.has_base()); | |
| 180 | |
| 181 EXPECT_TRUE(dest_b.needs_push_properties()); | |
| 182 EXPECT_EQ(2, dest_b.num_dependents_need_push_properties()); | |
| 183 EXPECT_TRUE(dest_b.has_base()); | |
| 184 | |
| 185 EXPECT_TRUE(dest_d.needs_push_properties()); | |
| 186 EXPECT_EQ(0, dest_d.num_dependents_need_push_properties()); | |
| 187 EXPECT_TRUE(dest_d.has_base()); | |
| 188 | |
| 189 EXPECT_TRUE(dest_b_mask.needs_push_properties()); | |
| 190 EXPECT_EQ(0, dest_b_mask.num_dependents_need_push_properties()); | |
| 191 EXPECT_TRUE(dest_b_mask.has_base()); | |
| 192 } | |
| 193 | |
| 194 TEST(LayerProtoConverterTest, DeserializeLayerProperties) { | |
| 195 /* Testing deserialization of properties for a tree that looks like this: | |
| 196 root*+ | |
| 197 / \ | |
| 198 a b+ | |
| 199 \ | |
| 200 c* | |
| 201 Layers marked with * have changed properties. | |
| 202 Layers marked with + have descendants with changed properties. | |
| 203 */ | |
| 204 proto::LayerUpdate updates; | |
| 205 | |
| 206 scoped_refptr<Layer> root = Layer::Create(LayerSettings()); | |
| 207 proto::LayerProperties* root_props = updates.add_layers(); | |
| 208 root_props->set_id(root->id()); | |
| 209 root_props->set_needs_push_properties(true); | |
| 210 root_props->set_num_dependents_need_push_properties(1); | |
| 211 root_props->mutable_base(); | |
| 212 | |
| 213 scoped_refptr<Layer> a = Layer::Create(LayerSettings()); | |
| 214 proto::LayerProperties* a_props = updates.add_layers(); | |
| 215 a_props->set_id(a->id()); | |
| 216 a_props->set_needs_push_properties(false); | |
| 217 a_props->set_num_dependents_need_push_properties(0); | |
| 218 root->AddChild(a); | |
| 219 | |
| 220 scoped_refptr<Layer> b = Layer::Create(LayerSettings()); | |
| 221 proto::LayerProperties* b_props = updates.add_layers(); | |
| 222 b_props->set_id(b->id()); | |
| 223 b_props->set_needs_push_properties(false); | |
| 224 b_props->set_num_dependents_need_push_properties(1); | |
| 225 root->AddChild(b); | |
| 226 | |
| 227 scoped_refptr<Layer> c = Layer::Create(LayerSettings()); | |
| 228 proto::LayerProperties* c_props = updates.add_layers(); | |
| 229 c_props->set_id(c->id()); | |
| 230 c_props->set_needs_push_properties(true); | |
| 231 c_props->set_num_dependents_need_push_properties(0); | |
| 232 c_props->mutable_base(); | |
| 233 b->AddChild(c); | |
| 234 | |
| 235 LayerProtoConverter::DeserializeLayerProperties(root, updates); | |
| 236 | |
| 237 EXPECT_TRUE(root->needs_push_properties()); | |
| 238 EXPECT_TRUE(root->descendant_needs_push_properties()); | |
| 239 | |
| 240 EXPECT_FALSE(a->needs_push_properties()); | |
| 241 EXPECT_FALSE(a->descendant_needs_push_properties()); | |
| 242 | |
| 243 EXPECT_FALSE(b->needs_push_properties()); | |
| 244 EXPECT_TRUE(b->descendant_needs_push_properties()); | |
| 245 | |
| 246 EXPECT_TRUE(c->needs_push_properties()); | |
| 247 EXPECT_FALSE(c->descendant_needs_push_properties()); | |
| 248 } | |
| 249 | |
| 110 } // namespace cc | 250 } // namespace cc |
| OLD | NEW |