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

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
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" 10 #include "cc/layers/layer_settings.h"
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 Layers marked with + have descendants with changed properties. 175 Layers marked with + have descendants with changed properties.
176 Layer b also has a mask layer and a replica layer. 176 Layer b also has a mask layer and a replica layer.
177 */ 177 */
178 scoped_refptr<Layer> layer_src_root = Layer::Create(LayerSettings()); 178 scoped_refptr<Layer> layer_src_root = Layer::Create(LayerSettings());
179 scoped_refptr<Layer> layer_src_a = Layer::Create(LayerSettings()); 179 scoped_refptr<Layer> layer_src_a = Layer::Create(LayerSettings());
180 scoped_refptr<Layer> layer_src_b = Layer::Create(LayerSettings()); 180 scoped_refptr<Layer> layer_src_b = Layer::Create(LayerSettings());
181 scoped_refptr<Layer> layer_src_b_mask = Layer::Create(LayerSettings()); 181 scoped_refptr<Layer> layer_src_b_mask = Layer::Create(LayerSettings());
182 scoped_refptr<Layer> layer_src_b_replica = Layer::Create(LayerSettings()); 182 scoped_refptr<Layer> layer_src_b_replica = Layer::Create(LayerSettings());
183 scoped_refptr<Layer> layer_src_c = Layer::Create(LayerSettings()); 183 scoped_refptr<Layer> layer_src_c = Layer::Create(LayerSettings());
184 scoped_refptr<Layer> layer_src_d = Layer::Create(LayerSettings()); 184 scoped_refptr<Layer> layer_src_d = Layer::Create(LayerSettings());
185 layer_src_root->SetLayerTreeHost(layer_tree_host_.get());
185 layer_src_root->AddChild(layer_src_a); 186 layer_src_root->AddChild(layer_src_a);
186 layer_src_root->AddChild(layer_src_b); 187 layer_src_root->AddChild(layer_src_b);
187 layer_src_a->AddChild(layer_src_c); 188 layer_src_a->AddChild(layer_src_c);
188 layer_src_b->AddChild(layer_src_d); 189 layer_src_b->AddChild(layer_src_d);
189 layer_src_b->SetMaskLayer(layer_src_b_mask.get()); 190 layer_src_b->SetMaskLayer(layer_src_b_mask.get());
190 layer_src_b->SetReplicaLayer(layer_src_b_replica.get()); 191 layer_src_b->SetReplicaLayer(layer_src_b_replica.get());
191 192
192 proto::LayerUpdate layer_update; 193 proto::LayerUpdate layer_update;
193 LayerProtoConverter::SerializeLayerProperties(layer_src_root.get(), 194 LayerProtoConverter::SerializeLayerProperties(
194 &layer_update); 195 layer_src_root->layer_tree_host(), &layer_update);
195 196
196 // All flags for pushing properties should have been cleared. 197 // All flags for pushing properties should have been cleared.
197 EXPECT_FALSE(layer_src_root->needs_push_properties()); 198 EXPECT_FALSE(
198 EXPECT_FALSE(layer_src_root->descendant_needs_push_properties()); 199 layer_src_root->layer_tree_host()->LayerNeedsPushPropertiesForTesting(
199 EXPECT_FALSE(layer_src_a->needs_push_properties()); 200 layer_src_root.get()));
200 EXPECT_FALSE(layer_src_a->descendant_needs_push_properties()); 201 EXPECT_FALSE(
201 EXPECT_FALSE(layer_src_b->needs_push_properties()); 202 layer_src_a->layer_tree_host()->LayerNeedsPushPropertiesForTesting(
202 EXPECT_FALSE(layer_src_b->descendant_needs_push_properties()); 203 layer_src_a.get()));
203 EXPECT_FALSE(layer_src_b_mask->needs_push_properties()); 204 EXPECT_FALSE(
204 EXPECT_FALSE(layer_src_b_mask->descendant_needs_push_properties()); 205 layer_src_b->layer_tree_host()->LayerNeedsPushPropertiesForTesting(
205 EXPECT_FALSE(layer_src_b_replica->needs_push_properties()); 206 layer_src_b.get()));
206 EXPECT_FALSE(layer_src_b_replica->descendant_needs_push_properties()); 207 EXPECT_FALSE(
207 EXPECT_FALSE(layer_src_c->needs_push_properties()); 208 layer_src_b_mask->layer_tree_host()->LayerNeedsPushPropertiesForTesting(
208 EXPECT_FALSE(layer_src_c->descendant_needs_push_properties()); 209 layer_src_b_mask.get()));
209 EXPECT_FALSE(layer_src_d->needs_push_properties()); 210 EXPECT_FALSE(
210 EXPECT_FALSE(layer_src_d->descendant_needs_push_properties()); 211 layer_src_b_replica->layer_tree_host()
212 ->LayerNeedsPushPropertiesForTesting(layer_src_b_replica.get()));
213 EXPECT_FALSE(
214 layer_src_c->layer_tree_host()->LayerNeedsPushPropertiesForTesting(
215 layer_src_c.get()));
216 EXPECT_FALSE(
217 layer_src_d->layer_tree_host()->LayerNeedsPushPropertiesForTesting(
218 layer_src_d.get()));
211 219
212 // AddChild changes the stacking order of child and it needs to push 220 // All layers needs to push properties as their layer tree host changed.
213 // properties. 221 ASSERT_EQ(7, layer_update.layers_size());
214 ASSERT_EQ(5, layer_update.layers_size());
215 EXPECT_EQ(layer_src_root->id(), layer_update.layers(0).id());
216 proto::LayerProperties dest_root = layer_update.layers(0);
217 EXPECT_EQ(layer_src_a->id(), layer_update.layers(1).id());
218 proto::LayerProperties dest_a = layer_update.layers(1);
219 EXPECT_EQ(layer_src_c->id(), layer_update.layers(2).id());
220 proto::LayerProperties dest_c = layer_update.layers(2);
221 EXPECT_EQ(layer_src_b->id(), layer_update.layers(3).id());
222 proto::LayerProperties dest_b = layer_update.layers(3);
223 EXPECT_EQ(layer_src_d->id(), layer_update.layers(4).id());
224 proto::LayerProperties dest_d = layer_update.layers(4);
225 layer_update.Clear(); 222 layer_update.Clear();
226 223
224 std::unordered_set<int> dirty_layer_ids;
227 layer_src_a->SetNeedsPushProperties(); 225 layer_src_a->SetNeedsPushProperties();
226 dirty_layer_ids.insert(layer_src_a->id());
228 layer_src_b->SetNeedsPushProperties(); 227 layer_src_b->SetNeedsPushProperties();
228 dirty_layer_ids.insert(layer_src_b->id());
229 layer_src_b_mask->SetNeedsPushProperties(); 229 layer_src_b_mask->SetNeedsPushProperties();
230 dirty_layer_ids.insert(layer_src_b_mask->id());
230 layer_src_d->SetNeedsPushProperties(); 231 layer_src_d->SetNeedsPushProperties();
232 dirty_layer_ids.insert(layer_src_d->id());
231 233
232 LayerProtoConverter::SerializeLayerProperties(layer_src_root.get(), 234 LayerProtoConverter::SerializeLayerProperties(
233 &layer_update); 235 layer_src_root->layer_tree_host(), &layer_update);
234 236
235 // All flags for pushing properties should have been cleared. 237 // All flags for pushing properties should have been cleared.
236 EXPECT_FALSE(layer_src_root->needs_push_properties()); 238 EXPECT_FALSE(
237 EXPECT_FALSE(layer_src_root->descendant_needs_push_properties()); 239 layer_src_root->layer_tree_host()->LayerNeedsPushPropertiesForTesting(
238 EXPECT_FALSE(layer_src_a->needs_push_properties()); 240 layer_src_root.get()));
239 EXPECT_FALSE(layer_src_a->descendant_needs_push_properties()); 241 EXPECT_FALSE(
240 EXPECT_FALSE(layer_src_b->needs_push_properties()); 242 layer_src_a->layer_tree_host()->LayerNeedsPushPropertiesForTesting(
241 EXPECT_FALSE(layer_src_b->descendant_needs_push_properties()); 243 layer_src_a.get()));
242 EXPECT_FALSE(layer_src_b_mask->needs_push_properties()); 244 EXPECT_FALSE(
243 EXPECT_FALSE(layer_src_b_mask->descendant_needs_push_properties()); 245 layer_src_b->layer_tree_host()->LayerNeedsPushPropertiesForTesting(
244 EXPECT_FALSE(layer_src_b_replica->needs_push_properties()); 246 layer_src_b.get()));
245 EXPECT_FALSE(layer_src_b_replica->descendant_needs_push_properties()); 247 EXPECT_FALSE(
246 EXPECT_FALSE(layer_src_c->needs_push_properties()); 248 layer_src_b_mask->layer_tree_host()->LayerNeedsPushPropertiesForTesting(
247 EXPECT_FALSE(layer_src_c->descendant_needs_push_properties()); 249 layer_src_b_mask.get()));
248 EXPECT_FALSE(layer_src_d->needs_push_properties()); 250 EXPECT_FALSE(
249 EXPECT_FALSE(layer_src_d->descendant_needs_push_properties()); 251 layer_src_b_replica->layer_tree_host()
252 ->LayerNeedsPushPropertiesForTesting(layer_src_b_replica.get()));
253 EXPECT_FALSE(
254 layer_src_c->layer_tree_host()->LayerNeedsPushPropertiesForTesting(
255 layer_src_c.get()));
256 EXPECT_FALSE(
257 layer_src_d->layer_tree_host()->LayerNeedsPushPropertiesForTesting(
258 layer_src_d.get()));
250 259
251 // Only 5 of the layers should have been serialized. 260 // Only 4 of the layers should have been serialized.
252 ASSERT_EQ(5, layer_update.layers_size()); 261 ASSERT_EQ(4, layer_update.layers_size());
253 EXPECT_EQ(layer_src_root->id(), layer_update.layers(0).id()); 262 for (int index = 0; index < layer_update.layers_size(); index++)
254 dest_root = layer_update.layers(0); 263 EXPECT_NE(dirty_layer_ids.find(layer_update.layers(index).id()),
255 EXPECT_EQ(layer_src_a->id(), layer_update.layers(1).id()); 264 dirty_layer_ids.end());
256 dest_a = layer_update.layers(1); 265 layer_src_root->SetLayerTreeHost(nullptr);
257 EXPECT_EQ(layer_src_b->id(), layer_update.layers(2).id());
258 dest_b = layer_update.layers(2);
259 EXPECT_EQ(layer_src_d->id(), layer_update.layers(3).id());
260 dest_d = layer_update.layers(3);
261 EXPECT_EQ(layer_src_b_mask->id(), layer_update.layers(4).id());
262 proto::LayerProperties dest_b_mask = layer_update.layers(4);
263
264 // Ensure the properties and dependants metadata is correctly serialized.
265 EXPECT_FALSE(dest_root.needs_push_properties());
266 EXPECT_EQ(2, dest_root.num_dependents_need_push_properties());
267 EXPECT_FALSE(dest_root.has_base());
268
269 EXPECT_TRUE(dest_a.needs_push_properties());
270 EXPECT_EQ(0, dest_a.num_dependents_need_push_properties());
271 EXPECT_TRUE(dest_a.has_base());
272
273 EXPECT_TRUE(dest_b.needs_push_properties());
274 EXPECT_EQ(2, dest_b.num_dependents_need_push_properties());
275 EXPECT_TRUE(dest_b.has_base());
276
277 EXPECT_TRUE(dest_d.needs_push_properties());
278 EXPECT_EQ(0, dest_d.num_dependents_need_push_properties());
279 EXPECT_TRUE(dest_d.has_base());
280
281 EXPECT_TRUE(dest_b_mask.needs_push_properties());
282 EXPECT_EQ(0, dest_b_mask.num_dependents_need_push_properties());
283 EXPECT_TRUE(dest_b_mask.has_base());
284 } 266 }
285 267
286 TEST_F(LayerProtoConverterTest, RecursivePropertiesSerializationSingleChild) { 268 TEST_F(LayerProtoConverterTest, RecursivePropertiesSerializationSingleChild) {
287 /* Testing serialization of properties for a tree that looks like this: 269 /* Testing serialization of properties for a tree that looks like this:
288 root+ 270 root+
289 \ 271 \
290 b*+[mask:*] 272 b*+[mask:*]
291 \ 273 \
292 c 274 c
293 Layers marked with * have changed properties. 275 Layers marked with * have changed properties.
294 Layers marked with + have descendants with changed properties. 276 Layers marked with + have descendants with changed properties.
295 Layer b also has a mask layer. 277 Layer b also has a mask layer.
296 */ 278 */
297 scoped_refptr<Layer> layer_src_root = Layer::Create(LayerSettings()); 279 scoped_refptr<Layer> layer_src_root = Layer::Create(LayerSettings());
298 scoped_refptr<Layer> layer_src_b = Layer::Create(LayerSettings()); 280 scoped_refptr<Layer> layer_src_b = Layer::Create(LayerSettings());
299 scoped_refptr<Layer> layer_src_b_mask = Layer::Create(LayerSettings()); 281 scoped_refptr<Layer> layer_src_b_mask = Layer::Create(LayerSettings());
300 scoped_refptr<Layer> layer_src_c = Layer::Create(LayerSettings()); 282 scoped_refptr<Layer> layer_src_c = Layer::Create(LayerSettings());
301 layer_src_root->AddChild(layer_src_b); 283 layer_src_root->AddChild(layer_src_b);
302 layer_src_b->AddChild(layer_src_c); 284 layer_src_b->AddChild(layer_src_c);
303 layer_src_b->SetMaskLayer(layer_src_b_mask.get()); 285 layer_src_b->SetMaskLayer(layer_src_b_mask.get());
286 layer_src_root->SetLayerTreeHost(layer_tree_host_.get());
304 287
305 proto::LayerUpdate layer_update; 288 proto::LayerUpdate layer_update;
306 LayerProtoConverter::SerializeLayerProperties(layer_src_root.get(), 289 LayerProtoConverter::SerializeLayerProperties(
307 &layer_update); 290 layer_src_root->layer_tree_host(), &layer_update);
308 // AddChild changes stacking order of child and we need to push proeprties of 291 // All layers need to push properties as their layer tree host changed.
309 // child. 292 ASSERT_EQ(4, layer_update.layers_size());
310 ASSERT_EQ(3, layer_update.layers_size());
311 layer_update.Clear(); 293 layer_update.Clear();
312 294
295 std::unordered_set<int> dirty_layer_ids;
313 layer_src_b->SetNeedsPushProperties(); 296 layer_src_b->SetNeedsPushProperties();
297 dirty_layer_ids.insert(layer_src_b->id());
314 layer_src_b_mask->SetNeedsPushProperties(); 298 layer_src_b_mask->SetNeedsPushProperties();
299 dirty_layer_ids.insert(layer_src_b_mask->id());
315 300
316 LayerProtoConverter::SerializeLayerProperties(layer_src_root.get(), 301 LayerProtoConverter::SerializeLayerProperties(
317 &layer_update); 302 layer_src_root->layer_tree_host(), &layer_update);
318 303
319 // All flags for pushing properties should have been cleared. 304 // All flags for pushing properties should have been cleared.
320 EXPECT_FALSE(layer_src_root->needs_push_properties()); 305 EXPECT_FALSE(
321 EXPECT_FALSE(layer_src_root->descendant_needs_push_properties()); 306 layer_src_root->layer_tree_host()->LayerNeedsPushPropertiesForTesting(
322 EXPECT_FALSE(layer_src_b->needs_push_properties()); 307 layer_src_root.get()));
323 EXPECT_FALSE(layer_src_b->descendant_needs_push_properties()); 308 EXPECT_FALSE(
324 EXPECT_FALSE(layer_src_b_mask->needs_push_properties()); 309 layer_src_b->layer_tree_host()->LayerNeedsPushPropertiesForTesting(
325 EXPECT_FALSE(layer_src_b_mask->descendant_needs_push_properties()); 310 layer_src_b.get()));
326 EXPECT_FALSE(layer_src_c->needs_push_properties()); 311 EXPECT_FALSE(
327 EXPECT_FALSE(layer_src_c->descendant_needs_push_properties()); 312 layer_src_b_mask->layer_tree_host()->LayerNeedsPushPropertiesForTesting(
313 layer_src_b_mask.get()));
314 EXPECT_FALSE(
315 layer_src_c->layer_tree_host()->LayerNeedsPushPropertiesForTesting(
316 layer_src_c.get()));
328 317
329 // Only 3 of the layers should have been serialized. 318 // Only 2 of the layers should have been serialized.
330 ASSERT_EQ(3, layer_update.layers_size()); 319 ASSERT_EQ(2, layer_update.layers_size());
331 EXPECT_EQ(layer_src_root->id(), layer_update.layers(0).id()); 320 for (int index = 0; index < layer_update.layers_size(); index++)
332 proto::LayerProperties dest_root = layer_update.layers(0); 321 EXPECT_NE(dirty_layer_ids.find(layer_update.layers(index).id()),
333 EXPECT_EQ(layer_src_b->id(), layer_update.layers(1).id()); 322 dirty_layer_ids.end());
334 proto::LayerProperties dest_b = layer_update.layers(1); 323 layer_src_root->SetLayerTreeHost(nullptr);
335 EXPECT_EQ(layer_src_b_mask->id(), layer_update.layers(2).id());
336 proto::LayerProperties dest_b_mask = layer_update.layers(2);
337
338 // Ensure the properties and dependants metadata is correctly serialized.
339 EXPECT_FALSE(dest_root.needs_push_properties());
340 EXPECT_EQ(1, dest_root.num_dependents_need_push_properties());
341 EXPECT_FALSE(dest_root.has_base());
342
343 EXPECT_TRUE(dest_b.needs_push_properties());
344 EXPECT_EQ(1, dest_b.num_dependents_need_push_properties());
345 EXPECT_TRUE(dest_b.has_base());
346
347 EXPECT_TRUE(dest_b_mask.needs_push_properties());
348 EXPECT_EQ(0, dest_b_mask.num_dependents_need_push_properties());
349 EXPECT_TRUE(dest_b_mask.has_base());
350 }
351
352 TEST_F(LayerProtoConverterTest, DeserializeLayerProperties) {
353 /* Testing deserialization of properties for a tree that looks like this:
jaydasika 2016/03/17 23:38:37 this test changes needs_push_properties directly o
ajuma 2016/03/18 14:33:15 Is there an equivalent test somewhere that after d
jaydasika 2016/03/19 02:17:58 Added one.
354 root*+
355 / \
356 a b+
357 \
358 c*
359 Layers marked with * have changed properties.
360 Layers marked with + have descendants with changed properties.
361 */
362 proto::LayerUpdate updates;
363
364 scoped_refptr<Layer> root = Layer::Create(LayerSettings());
365 root->SetLayerTreeHost(layer_tree_host_.get());
366 proto::LayerProperties* root_props = updates.add_layers();
367 root_props->set_id(root->id());
368 root_props->set_needs_push_properties(true);
369 root_props->set_num_dependents_need_push_properties(1);
370 root_props->mutable_base();
371
372 scoped_refptr<Layer> a = Layer::Create(LayerSettings());
373 a->SetLayerTreeHost(layer_tree_host_.get());
374 proto::LayerProperties* a_props = updates.add_layers();
375 a_props->set_id(a->id());
376 a_props->set_needs_push_properties(false);
377 a_props->set_num_dependents_need_push_properties(0);
378 root->AddChild(a);
379
380 scoped_refptr<Layer> b = Layer::Create(LayerSettings());
381 b->SetLayerTreeHost(layer_tree_host_.get());
382 proto::LayerProperties* b_props = updates.add_layers();
383 b_props->set_id(b->id());
384 b_props->set_needs_push_properties(false);
385 b_props->set_num_dependents_need_push_properties(1);
386 root->AddChild(b);
387
388 scoped_refptr<Layer> c = Layer::Create(LayerSettings());
389 c->SetLayerTreeHost(layer_tree_host_.get());
390 proto::LayerProperties* c_props = updates.add_layers();
391 c_props->set_id(c->id());
392 c_props->set_needs_push_properties(true);
393 c_props->set_num_dependents_need_push_properties(0);
394 c_props->mutable_base();
395 b->AddChild(c);
396
397 LayerProtoConverter::DeserializeLayerProperties(root.get(), updates);
398
399 EXPECT_TRUE(root->needs_push_properties());
400 EXPECT_TRUE(root->descendant_needs_push_properties());
401
402 EXPECT_FALSE(a->needs_push_properties());
403 EXPECT_FALSE(a->descendant_needs_push_properties());
404
405 EXPECT_FALSE(b->needs_push_properties());
406 EXPECT_TRUE(b->descendant_needs_push_properties());
407
408 EXPECT_TRUE(c->needs_push_properties());
409 EXPECT_FALSE(c->descendant_needs_push_properties());
410
411 // Recursively clear out LayerTreeHost.
412 root->SetLayerTreeHost(nullptr);
413 } 324 }
414 325
415 TEST_F(LayerProtoConverterTest, PictureLayerTypeSerialization) { 326 TEST_F(LayerProtoConverterTest, PictureLayerTypeSerialization) {
416 // Make sure that PictureLayers serialize to the 327 // Make sure that PictureLayers serialize to the
417 // proto::LayerType::PICTURE_LAYER type. 328 // proto::LayerType::PICTURE_LAYER type.
418 scoped_refptr<PictureLayer> layer = PictureLayer::Create( 329 scoped_refptr<PictureLayer> layer = PictureLayer::Create(
419 LayerSettings(), EmptyContentLayerClient::GetInstance()); 330 LayerSettings(), EmptyContentLayerClient::GetInstance());
420 331
421 proto::LayerNode layer_hierarchy; 332 proto::LayerNode layer_hierarchy;
422 LayerProtoConverter::SerializeLayerHierarchy(layer.get(), &layer_hierarchy); 333 LayerProtoConverter::SerializeLayerHierarchy(layer.get(), &layer_hierarchy);
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
472 383
473 // Check that the layer type is equal by using the type this layer would 384 // Check that the layer type is equal by using the type this layer would
474 // serialize to. 385 // serialize to.
475 proto::LayerNode layer_node; 386 proto::LayerNode layer_node;
476 new_root->SetTypeForProtoSerialization(&layer_node); 387 new_root->SetTypeForProtoSerialization(&layer_node);
477 EXPECT_EQ(proto::LayerNode::HEADS_UP_DISPLAY_LAYER, layer_node.type()); 388 EXPECT_EQ(proto::LayerNode::HEADS_UP_DISPLAY_LAYER, layer_node.type());
478 } 389 }
479 390
480 } // namespace 391 } // namespace
481 } // namespace cc 392 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698