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

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

Issue 1423523002: Add support for (de)serializing cc::Layer properties. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@serialize-layer-hierarchy
Patch Set: Addressed comments about raw pointers and new test. Created 5 years, 1 month 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/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
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) {
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.get(),
142 &layer_update);
143
144 // All flags for pushing properties should have been cleared.
145 EXPECT_FALSE(layer_src_root->needs_push_properties());
146 EXPECT_FALSE(layer_src_root->descendant_needs_push_properties());
147 EXPECT_FALSE(layer_src_a->needs_push_properties());
148 EXPECT_FALSE(layer_src_a->descendant_needs_push_properties());
149 EXPECT_FALSE(layer_src_b->needs_push_properties());
150 EXPECT_FALSE(layer_src_b->descendant_needs_push_properties());
151 EXPECT_FALSE(layer_src_b_mask->needs_push_properties());
152 EXPECT_FALSE(layer_src_b_mask->descendant_needs_push_properties());
153 EXPECT_FALSE(layer_src_b_replica->needs_push_properties());
154 EXPECT_FALSE(layer_src_b_replica->descendant_needs_push_properties());
155 EXPECT_FALSE(layer_src_c->needs_push_properties());
156 EXPECT_FALSE(layer_src_c->descendant_needs_push_properties());
157 EXPECT_FALSE(layer_src_d->needs_push_properties());
158 EXPECT_FALSE(layer_src_d->descendant_needs_push_properties());
159
160 // Only 5 of the layers should have been serialized.
161 ASSERT_EQ(5, layer_update.layers_size());
162 EXPECT_EQ(layer_src_root->id(), layer_update.layers(0).id());
163 proto::LayerProperties dest_root = layer_update.layers(0);
164 EXPECT_EQ(layer_src_a->id(), layer_update.layers(1).id());
165 proto::LayerProperties dest_a = layer_update.layers(1);
166 EXPECT_EQ(layer_src_b->id(), layer_update.layers(2).id());
167 proto::LayerProperties dest_b = layer_update.layers(2);
168 EXPECT_EQ(layer_src_d->id(), layer_update.layers(3).id());
169 proto::LayerProperties dest_d = layer_update.layers(3);
170 EXPECT_EQ(layer_src_b_mask->id(), layer_update.layers(4).id());
171 proto::LayerProperties dest_b_mask = layer_update.layers(4);
172
173 // Ensure the properties and dependants metadata is correctly serialized.
174 EXPECT_FALSE(dest_root.needs_push_properties());
175 EXPECT_EQ(2, dest_root.num_dependents_need_push_properties());
176 EXPECT_FALSE(dest_root.has_base());
177
178 EXPECT_TRUE(dest_a.needs_push_properties());
179 EXPECT_EQ(0, dest_a.num_dependents_need_push_properties());
180 EXPECT_TRUE(dest_a.has_base());
181
182 EXPECT_TRUE(dest_b.needs_push_properties());
183 EXPECT_EQ(2, dest_b.num_dependents_need_push_properties());
184 EXPECT_TRUE(dest_b.has_base());
185
186 EXPECT_TRUE(dest_d.needs_push_properties());
187 EXPECT_EQ(0, dest_d.num_dependents_need_push_properties());
188 EXPECT_TRUE(dest_d.has_base());
189
190 EXPECT_TRUE(dest_b_mask.needs_push_properties());
191 EXPECT_EQ(0, dest_b_mask.num_dependents_need_push_properties());
192 EXPECT_TRUE(dest_b_mask.has_base());
193 }
194
195 TEST(LayerProtoConverterTest, RecursivePropertiesSerializationSingleChild) {
196 /* Testing serialization of properties for a tree that looks like this:
197 root+
198 \
199 b*+[mask:*]
200 \
201 c
202 Layers marked with * have changed properties.
203 Layers marked with + have descendants with changed properties.
204 Layer b also has a mask layer.
205 */
206 scoped_refptr<Layer> layer_src_root = Layer::Create(LayerSettings());
207 scoped_refptr<Layer> layer_src_b = Layer::Create(LayerSettings());
208 scoped_refptr<Layer> layer_src_b_mask = Layer::Create(LayerSettings());
209 scoped_refptr<Layer> layer_src_c = Layer::Create(LayerSettings());
210 layer_src_root->AddChild(layer_src_b);
211 layer_src_b->AddChild(layer_src_c);
212 layer_src_b->SetMaskLayer(layer_src_b_mask.get());
213
214 layer_src_b->SetNeedsPushProperties();
215 layer_src_b_mask->SetNeedsPushProperties();
216
217 proto::LayerUpdate layer_update;
218 LayerProtoConverter::SerializeLayerProperties(layer_src_root.get(),
219 &layer_update);
220
221 // All flags for pushing properties should have been cleared.
222 EXPECT_FALSE(layer_src_root->needs_push_properties());
223 EXPECT_FALSE(layer_src_root->descendant_needs_push_properties());
224 EXPECT_FALSE(layer_src_b->needs_push_properties());
225 EXPECT_FALSE(layer_src_b->descendant_needs_push_properties());
226 EXPECT_FALSE(layer_src_b_mask->needs_push_properties());
227 EXPECT_FALSE(layer_src_b_mask->descendant_needs_push_properties());
228 EXPECT_FALSE(layer_src_c->needs_push_properties());
229 EXPECT_FALSE(layer_src_c->descendant_needs_push_properties());
230
231 // Only 3 of the layers should have been serialized.
232 ASSERT_EQ(3, layer_update.layers_size());
233 EXPECT_EQ(layer_src_root->id(), layer_update.layers(0).id());
234 proto::LayerProperties dest_root = layer_update.layers(0);
235 EXPECT_EQ(layer_src_b->id(), layer_update.layers(1).id());
236 proto::LayerProperties dest_b = layer_update.layers(1);
237 EXPECT_EQ(layer_src_b_mask->id(), layer_update.layers(2).id());
238 proto::LayerProperties dest_b_mask = layer_update.layers(2);
239
240 // Ensure the properties and dependants metadata is correctly serialized.
241 EXPECT_FALSE(dest_root.needs_push_properties());
242 EXPECT_EQ(1, dest_root.num_dependents_need_push_properties());
243 EXPECT_FALSE(dest_root.has_base());
244
245 EXPECT_TRUE(dest_b.needs_push_properties());
246 EXPECT_EQ(1, dest_b.num_dependents_need_push_properties());
247 EXPECT_TRUE(dest_b.has_base());
248
249 EXPECT_TRUE(dest_b_mask.needs_push_properties());
250 EXPECT_EQ(0, dest_b_mask.num_dependents_need_push_properties());
251 EXPECT_TRUE(dest_b_mask.has_base());
252 }
253
254 TEST(LayerProtoConverterTest, DeserializeLayerProperties) {
255 /* Testing deserialization of properties for a tree that looks like this:
256 root*+
257 / \
258 a b+
259 \
260 c*
261 Layers marked with * have changed properties.
262 Layers marked with + have descendants with changed properties.
263 */
264 proto::LayerUpdate updates;
265
266 scoped_refptr<Layer> root = Layer::Create(LayerSettings());
267 proto::LayerProperties* root_props = updates.add_layers();
268 root_props->set_id(root->id());
269 root_props->set_needs_push_properties(true);
270 root_props->set_num_dependents_need_push_properties(1);
271 root_props->mutable_base();
272
273 scoped_refptr<Layer> a = Layer::Create(LayerSettings());
274 proto::LayerProperties* a_props = updates.add_layers();
275 a_props->set_id(a->id());
276 a_props->set_needs_push_properties(false);
277 a_props->set_num_dependents_need_push_properties(0);
278 root->AddChild(a);
279
280 scoped_refptr<Layer> b = Layer::Create(LayerSettings());
281 proto::LayerProperties* b_props = updates.add_layers();
282 b_props->set_id(b->id());
283 b_props->set_needs_push_properties(false);
284 b_props->set_num_dependents_need_push_properties(1);
285 root->AddChild(b);
286
287 scoped_refptr<Layer> c = Layer::Create(LayerSettings());
288 proto::LayerProperties* c_props = updates.add_layers();
289 c_props->set_id(c->id());
290 c_props->set_needs_push_properties(true);
291 c_props->set_num_dependents_need_push_properties(0);
292 c_props->mutable_base();
293 b->AddChild(c);
294
295 LayerProtoConverter::DeserializeLayerProperties(root.get(), updates);
296
297 EXPECT_TRUE(root->needs_push_properties());
298 EXPECT_TRUE(root->descendant_needs_push_properties());
299
300 EXPECT_FALSE(a->needs_push_properties());
301 EXPECT_FALSE(a->descendant_needs_push_properties());
302
303 EXPECT_FALSE(b->needs_push_properties());
304 EXPECT_TRUE(b->descendant_needs_push_properties());
305
306 EXPECT_TRUE(c->needs_push_properties());
307 EXPECT_FALSE(c->descendant_needs_push_properties());
308 }
309
110 } // namespace cc 310 } // 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