OLD | NEW |
1 // Copyright 2011 The Chromium Authors. All rights reserved. | 1 // Copyright 2011 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.h" | 5 #include "cc/layers/layer.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include "base/thread_task_runner_handle.h" | 9 #include "base/thread_task_runner_handle.h" |
10 #include "cc/animation/animation_host.h" | 10 #include "cc/animation/animation_host.h" |
11 #include "cc/animation/animation_id_provider.h" | 11 #include "cc/animation/animation_id_provider.h" |
12 #include "cc/animation/keyframed_animation_curve.h" | 12 #include "cc/animation/keyframed_animation_curve.h" |
13 #include "cc/animation/mutable_properties.h" | 13 #include "cc/animation/mutable_properties.h" |
14 #include "cc/base/math_util.h" | 14 #include "cc/base/math_util.h" |
15 #include "cc/input/main_thread_scrolling_reason.h" | 15 #include "cc/input/main_thread_scrolling_reason.h" |
16 #include "cc/layers/layer_impl.h" | 16 #include "cc/layers/layer_impl.h" |
17 #include "cc/layers/layer_settings.h" | |
18 #include "cc/output/copy_output_request.h" | 17 #include "cc/output/copy_output_request.h" |
19 #include "cc/output/copy_output_result.h" | 18 #include "cc/output/copy_output_result.h" |
20 #include "cc/proto/layer.pb.h" | 19 #include "cc/proto/layer.pb.h" |
21 #include "cc/test/animation_test_common.h" | 20 #include "cc/test/animation_test_common.h" |
22 #include "cc/test/fake_impl_task_runner_provider.h" | 21 #include "cc/test/fake_impl_task_runner_provider.h" |
23 #include "cc/test/fake_layer_tree_host.h" | 22 #include "cc/test/fake_layer_tree_host.h" |
24 #include "cc/test/fake_layer_tree_host_client.h" | 23 #include "cc/test/fake_layer_tree_host_client.h" |
25 #include "cc/test/fake_layer_tree_host_impl.h" | 24 #include "cc/test/fake_layer_tree_host_impl.h" |
26 #include "cc/test/geometry_test_utils.h" | 25 #include "cc/test/geometry_test_utils.h" |
27 #include "cc/test/layer_test_common.h" | 26 #include "cc/test/layer_test_common.h" |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 if (src->clip_parent_) | 123 if (src->clip_parent_) |
125 layer_tree_host_->RegisterLayer(src->clip_parent_); | 124 layer_tree_host_->RegisterLayer(src->clip_parent_); |
126 if (src->clip_children_) { | 125 if (src->clip_children_) { |
127 for (auto* child : *(src->clip_children_)) | 126 for (auto* child : *(src->clip_children_)) |
128 layer_tree_host_->RegisterLayer(child); | 127 layer_tree_host_->RegisterLayer(child); |
129 } | 128 } |
130 // Reset the LayerTreeHost registration for the |src| layer so | 129 // Reset the LayerTreeHost registration for the |src| layer so |
131 // it can be re-used for the |dest| layer. | 130 // it can be re-used for the |dest| layer. |
132 src->SetLayerTreeHost(nullptr); | 131 src->SetLayerTreeHost(nullptr); |
133 | 132 |
134 scoped_refptr<Layer> dest = Layer::Create(LayerSettings()); | 133 scoped_refptr<Layer> dest = Layer::Create(); |
135 dest->layer_id_ = src->layer_id_; | 134 dest->layer_id_ = src->layer_id_; |
136 dest->SetLayerTreeHost(layer_tree_host_.get()); | 135 dest->SetLayerTreeHost(layer_tree_host_.get()); |
137 dest->FromLayerPropertiesProto(props); | 136 dest->FromLayerPropertiesProto(props); |
138 | 137 |
139 // Verify that both layers are equal. | 138 // Verify that both layers are equal. |
140 EXPECT_EQ(src->transform_origin_, dest->transform_origin_); | 139 EXPECT_EQ(src->transform_origin_, dest->transform_origin_); |
141 EXPECT_EQ(src->background_color_, dest->background_color_); | 140 EXPECT_EQ(src->background_color_, dest->background_color_); |
142 EXPECT_EQ(src->bounds_, dest->bounds_); | 141 EXPECT_EQ(src->bounds_, dest->bounds_); |
143 EXPECT_EQ(src->transform_tree_index_, dest->transform_tree_index_); | 142 EXPECT_EQ(src->transform_tree_index_, dest->transform_tree_index_); |
144 EXPECT_EQ(src->effect_tree_index_, dest->effect_tree_index_); | 143 EXPECT_EQ(src->effect_tree_index_, dest->effect_tree_index_); |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
236 dest->clip_parent_ = nullptr; | 235 dest->clip_parent_ = nullptr; |
237 if (src->clip_children_) { | 236 if (src->clip_children_) { |
238 for (auto* child : *(src->clip_children_)) | 237 for (auto* child : *(src->clip_children_)) |
239 layer_tree_host_->UnregisterLayer(child); | 238 layer_tree_host_->UnregisterLayer(child); |
240 src->clip_children_.reset(); | 239 src->clip_children_.reset(); |
241 dest->clip_children_.reset(); | 240 dest->clip_children_.reset(); |
242 } | 241 } |
243 } | 242 } |
244 | 243 |
245 void RunNoMembersChangedTest() { | 244 void RunNoMembersChangedTest() { |
246 scoped_refptr<Layer> layer = Layer::Create(LayerSettings()); | 245 scoped_refptr<Layer> layer = Layer::Create(); |
247 VerifyBaseLayerPropertiesSerializationAndDeserialization(layer.get()); | 246 VerifyBaseLayerPropertiesSerializationAndDeserialization(layer.get()); |
248 } | 247 } |
249 | 248 |
250 void RunArbitraryMembersChangedTest() { | 249 void RunArbitraryMembersChangedTest() { |
251 scoped_refptr<Layer> layer = Layer::Create(LayerSettings()); | 250 scoped_refptr<Layer> layer = Layer::Create(); |
252 layer->transform_origin_ = gfx::Point3F(3.0f, 1.0f, 4.0f); | 251 layer->transform_origin_ = gfx::Point3F(3.0f, 1.0f, 4.0f); |
253 layer->background_color_ = SK_ColorRED; | 252 layer->background_color_ = SK_ColorRED; |
254 layer->bounds_ = gfx::Size(3, 14); | 253 layer->bounds_ = gfx::Size(3, 14); |
255 layer->transform_tree_index_ = -1; | 254 layer->transform_tree_index_ = -1; |
256 layer->effect_tree_index_ = -1; | 255 layer->effect_tree_index_ = -1; |
257 layer->clip_tree_index_ = 71; | 256 layer->clip_tree_index_ = 71; |
258 layer->offset_to_transform_parent_ = gfx::Vector2dF(3.14f, 1.618f); | 257 layer->offset_to_transform_parent_ = gfx::Vector2dF(3.14f, 1.618f); |
259 layer->double_sided_ = true; | 258 layer->double_sided_ = true; |
260 layer->draws_content_ = true; | 259 layer->draws_content_ = true; |
261 layer->hide_layer_and_subtree_ = false; | 260 layer->hide_layer_and_subtree_ = false; |
(...skipping 26 matching lines...) Expand all Loading... |
288 layer->user_scrollable_horizontal_ = false; | 287 layer->user_scrollable_horizontal_ = false; |
289 layer->user_scrollable_vertical_ = true; | 288 layer->user_scrollable_vertical_ = true; |
290 layer->scroll_offset_ = gfx::ScrollOffset(3, 14); | 289 layer->scroll_offset_ = gfx::ScrollOffset(3, 14); |
291 layer->scroll_compensation_adjustment_ = gfx::Vector2dF(6.28f, 3.14f); | 290 layer->scroll_compensation_adjustment_ = gfx::Vector2dF(6.28f, 3.14f); |
292 layer->update_rect_ = gfx::Rect(14, 15); | 291 layer->update_rect_ = gfx::Rect(14, 15); |
293 | 292 |
294 VerifyBaseLayerPropertiesSerializationAndDeserialization(layer.get()); | 293 VerifyBaseLayerPropertiesSerializationAndDeserialization(layer.get()); |
295 } | 294 } |
296 | 295 |
297 void RunAllMembersChangedTest() { | 296 void RunAllMembersChangedTest() { |
298 scoped_refptr<Layer> layer = Layer::Create(LayerSettings()); | 297 scoped_refptr<Layer> layer = Layer::Create(); |
299 layer->transform_origin_ = gfx::Point3F(3.0f, 1.0f, 4.0f); | 298 layer->transform_origin_ = gfx::Point3F(3.0f, 1.0f, 4.0f); |
300 layer->background_color_ = SK_ColorRED; | 299 layer->background_color_ = SK_ColorRED; |
301 layer->bounds_ = gfx::Size(3, 14); | 300 layer->bounds_ = gfx::Size(3, 14); |
302 layer->transform_tree_index_ = 39; | 301 layer->transform_tree_index_ = 39; |
303 layer->effect_tree_index_ = 17; | 302 layer->effect_tree_index_ = 17; |
304 layer->clip_tree_index_ = 71; | 303 layer->clip_tree_index_ = 71; |
305 layer->offset_to_transform_parent_ = gfx::Vector2dF(3.14f, 1.618f); | 304 layer->offset_to_transform_parent_ = gfx::Vector2dF(3.14f, 1.618f); |
306 layer->double_sided_ = !layer->double_sided_; | 305 layer->double_sided_ = !layer->double_sided_; |
307 layer->draws_content_ = !layer->draws_content_; | 306 layer->draws_content_ = !layer->draws_content_; |
308 layer->hide_layer_and_subtree_ = !layer->hide_layer_and_subtree_; | 307 layer->hide_layer_and_subtree_ = !layer->hide_layer_and_subtree_; |
(...skipping 29 matching lines...) Expand all Loading... |
338 layer->user_scrollable_horizontal_ = !layer->user_scrollable_horizontal_; | 337 layer->user_scrollable_horizontal_ = !layer->user_scrollable_horizontal_; |
339 layer->user_scrollable_vertical_ = !layer->user_scrollable_vertical_; | 338 layer->user_scrollable_vertical_ = !layer->user_scrollable_vertical_; |
340 layer->scroll_offset_ = gfx::ScrollOffset(3, 14); | 339 layer->scroll_offset_ = gfx::ScrollOffset(3, 14); |
341 layer->scroll_compensation_adjustment_ = gfx::Vector2dF(6.28f, 3.14f); | 340 layer->scroll_compensation_adjustment_ = gfx::Vector2dF(6.28f, 3.14f); |
342 layer->update_rect_ = gfx::Rect(14, 15); | 341 layer->update_rect_ = gfx::Rect(14, 15); |
343 | 342 |
344 VerifyBaseLayerPropertiesSerializationAndDeserialization(layer.get()); | 343 VerifyBaseLayerPropertiesSerializationAndDeserialization(layer.get()); |
345 } | 344 } |
346 | 345 |
347 void RunScrollAndClipLayersTest() { | 346 void RunScrollAndClipLayersTest() { |
348 scoped_refptr<Layer> layer = Layer::Create(LayerSettings()); | 347 scoped_refptr<Layer> layer = Layer::Create(); |
349 | 348 |
350 scoped_refptr<Layer> scroll_parent = Layer::Create(LayerSettings()); | 349 scoped_refptr<Layer> scroll_parent = Layer::Create(); |
351 layer->scroll_parent_ = scroll_parent.get(); | 350 layer->scroll_parent_ = scroll_parent.get(); |
352 scoped_refptr<Layer> scroll_child = Layer::Create(LayerSettings()); | 351 scoped_refptr<Layer> scroll_child = Layer::Create(); |
353 layer->scroll_children_.reset(new std::set<Layer*>); | 352 layer->scroll_children_.reset(new std::set<Layer*>); |
354 layer->scroll_children_->insert(scroll_child.get()); | 353 layer->scroll_children_->insert(scroll_child.get()); |
355 | 354 |
356 scoped_refptr<Layer> clip_parent = Layer::Create(LayerSettings()); | 355 scoped_refptr<Layer> clip_parent = Layer::Create(); |
357 layer->clip_parent_ = clip_parent.get(); | 356 layer->clip_parent_ = clip_parent.get(); |
358 layer->clip_children_.reset(new std::set<Layer*>); | 357 layer->clip_children_.reset(new std::set<Layer*>); |
359 scoped_refptr<Layer> clip_child1 = Layer::Create(LayerSettings()); | 358 scoped_refptr<Layer> clip_child1 = Layer::Create(); |
360 layer->clip_children_->insert(clip_child1.get()); | 359 layer->clip_children_->insert(clip_child1.get()); |
361 scoped_refptr<Layer> clip_child2 = Layer::Create(LayerSettings()); | 360 scoped_refptr<Layer> clip_child2 = Layer::Create(); |
362 layer->clip_children_->insert(clip_child2.get()); | 361 layer->clip_children_->insert(clip_child2.get()); |
363 | 362 |
364 VerifyBaseLayerPropertiesSerializationAndDeserialization(layer.get()); | 363 VerifyBaseLayerPropertiesSerializationAndDeserialization(layer.get()); |
365 } | 364 } |
366 | 365 |
367 void RunHierarchyDeserializationWithLayerTreeHostTest() { | 366 void RunHierarchyDeserializationWithLayerTreeHostTest() { |
368 /* Testing serialization and deserialization of a tree that looks like this: | 367 /* Testing serialization and deserialization of a tree that looks like this: |
369 root | 368 root |
370 \ | 369 \ |
371 a | 370 a |
372 \ | 371 \ |
373 b | 372 b |
374 \ | 373 \ |
375 c | 374 c |
376 The root layer has a LayerTreeHost, and it should propagate to all the | 375 The root layer has a LayerTreeHost, and it should propagate to all the |
377 children. | 376 children. |
378 */ | 377 */ |
379 scoped_refptr<Layer> layer_src_root = Layer::Create(LayerSettings()); | 378 scoped_refptr<Layer> layer_src_root = Layer::Create(); |
380 scoped_refptr<Layer> layer_src_a = Layer::Create(LayerSettings()); | 379 scoped_refptr<Layer> layer_src_a = Layer::Create(); |
381 scoped_refptr<Layer> layer_src_b = Layer::Create(LayerSettings()); | 380 scoped_refptr<Layer> layer_src_b = Layer::Create(); |
382 scoped_refptr<Layer> layer_src_c = Layer::Create(LayerSettings()); | 381 scoped_refptr<Layer> layer_src_c = Layer::Create(); |
383 layer_src_root->AddChild(layer_src_a); | 382 layer_src_root->AddChild(layer_src_a); |
384 layer_src_a->AddChild(layer_src_b); | 383 layer_src_a->AddChild(layer_src_b); |
385 layer_src_b->AddChild(layer_src_c); | 384 layer_src_b->AddChild(layer_src_c); |
386 | 385 |
387 proto::LayerNode proto; | 386 proto::LayerNode proto; |
388 layer_src_root->ToLayerNodeProto(&proto); | 387 layer_src_root->ToLayerNodeProto(&proto); |
389 | 388 |
390 Layer::LayerIdMap empty_dest_layer_map; | 389 Layer::LayerIdMap empty_dest_layer_map; |
391 scoped_refptr<Layer> layer_dest_root = Layer::Create(LayerSettings()); | 390 scoped_refptr<Layer> layer_dest_root = Layer::Create(); |
392 | 391 |
393 // Forcefully set the layer tree host for the root layer, which should cause | 392 // Forcefully set the layer tree host for the root layer, which should cause |
394 // it to propagate to all the children. | 393 // it to propagate to all the children. |
395 layer_dest_root->layer_tree_host_ = layer_tree_host_.get(); | 394 layer_dest_root->layer_tree_host_ = layer_tree_host_.get(); |
396 | 395 |
397 layer_dest_root->FromLayerNodeProto(proto, empty_dest_layer_map); | 396 layer_dest_root->FromLayerNodeProto(proto, empty_dest_layer_map); |
398 | 397 |
399 EXPECT_EQ(layer_src_root->id(), layer_dest_root->id()); | 398 EXPECT_EQ(layer_src_root->id(), layer_dest_root->id()); |
400 EXPECT_EQ(nullptr, layer_dest_root->parent()); | 399 EXPECT_EQ(nullptr, layer_dest_root->parent()); |
401 ASSERT_EQ(1u, layer_dest_root->children().size()); | 400 ASSERT_EQ(1u, layer_dest_root->children().size()); |
(...skipping 29 matching lines...) Expand all Loading... |
431 /* Testing serialization and deserialization of a tree that initially looks | 430 /* Testing serialization and deserialization of a tree that initially looks |
432 like this: | 431 like this: |
433 root | 432 root |
434 / | 433 / |
435 a | 434 a |
436 The source tree is then deserialized from the same structure which should | 435 The source tree is then deserialized from the same structure which should |
437 re-use the Layers from last deserialization and importantly it should | 436 re-use the Layers from last deserialization and importantly it should |
438 not have called InvalidatePropertyTreesIndices() for any of the layers, | 437 not have called InvalidatePropertyTreesIndices() for any of the layers, |
439 which would happen in for example SetLayerTreeHost(...) calls. | 438 which would happen in for example SetLayerTreeHost(...) calls. |
440 */ | 439 */ |
441 scoped_refptr<Layer> layer_root = Layer::Create(LayerSettings()); | 440 scoped_refptr<Layer> layer_root = Layer::Create(); |
442 scoped_refptr<Layer> layer_src_a = Layer::Create(LayerSettings()); | 441 scoped_refptr<Layer> layer_src_a = Layer::Create(); |
443 layer_root->AddChild(layer_src_a); | 442 layer_root->AddChild(layer_src_a); |
444 layer_root->transform_tree_index_ = 33; | 443 layer_root->transform_tree_index_ = 33; |
445 layer_src_a->transform_tree_index_ = 42; | 444 layer_src_a->transform_tree_index_ = 42; |
446 | 445 |
447 proto::LayerNode root_proto; | 446 proto::LayerNode root_proto; |
448 layer_root->ToLayerNodeProto(&root_proto); | 447 layer_root->ToLayerNodeProto(&root_proto); |
449 | 448 |
450 Layer::LayerIdMap dest_layer_map; | 449 Layer::LayerIdMap dest_layer_map; |
451 dest_layer_map[layer_root->id()] = layer_root; | 450 dest_layer_map[layer_root->id()] = layer_root; |
452 dest_layer_map[layer_src_a->id()] = layer_src_a; | 451 dest_layer_map[layer_src_a->id()] = layer_src_a; |
(...skipping 14 matching lines...) Expand all Loading... |
467 a b | 466 a b |
468 The children are then re-ordered to: | 467 The children are then re-ordered to: |
469 root | 468 root |
470 / \ | 469 / \ |
471 b a | 470 b a |
472 The tree is then serialized and deserialized again, and the the end | 471 The tree is then serialized and deserialized again, and the the end |
473 result should have the same structure and importantly it should | 472 result should have the same structure and importantly it should |
474 not have called InvalidatePropertyTreesIndices() for any of the layers, | 473 not have called InvalidatePropertyTreesIndices() for any of the layers, |
475 which would happen in for example SetLayerTreeHost(...) calls. | 474 which would happen in for example SetLayerTreeHost(...) calls. |
476 */ | 475 */ |
477 scoped_refptr<Layer> layer_src_root = Layer::Create(LayerSettings()); | 476 scoped_refptr<Layer> layer_src_root = Layer::Create(); |
478 scoped_refptr<Layer> layer_src_a = Layer::Create(LayerSettings()); | 477 scoped_refptr<Layer> layer_src_a = Layer::Create(); |
479 scoped_refptr<Layer> layer_src_b = Layer::Create(LayerSettings()); | 478 scoped_refptr<Layer> layer_src_b = Layer::Create(); |
480 layer_src_root->AddChild(layer_src_a); | 479 layer_src_root->AddChild(layer_src_a); |
481 layer_src_root->AddChild(layer_src_b); | 480 layer_src_root->AddChild(layer_src_b); |
482 | 481 |
483 // Copy tree-structure to new root. | 482 // Copy tree-structure to new root. |
484 proto::LayerNode root_proto_1; | 483 proto::LayerNode root_proto_1; |
485 layer_src_root->ToLayerNodeProto(&root_proto_1); | 484 layer_src_root->ToLayerNodeProto(&root_proto_1); |
486 Layer::LayerIdMap dest_layer_map; | 485 Layer::LayerIdMap dest_layer_map; |
487 scoped_refptr<Layer> layer_dest_root = Layer::Create(LayerSettings()); | 486 scoped_refptr<Layer> layer_dest_root = Layer::Create(); |
488 layer_dest_root->FromLayerNodeProto(root_proto_1, dest_layer_map); | 487 layer_dest_root->FromLayerNodeProto(root_proto_1, dest_layer_map); |
489 | 488 |
490 // Ensure initial copy is correct. | 489 // Ensure initial copy is correct. |
491 ASSERT_EQ(2u, layer_dest_root->children().size()); | 490 ASSERT_EQ(2u, layer_dest_root->children().size()); |
492 scoped_refptr<Layer> layer_dest_a = layer_dest_root->children()[0]; | 491 scoped_refptr<Layer> layer_dest_a = layer_dest_root->children()[0]; |
493 EXPECT_EQ(layer_src_a->id(), layer_dest_a->id()); | 492 EXPECT_EQ(layer_src_a->id(), layer_dest_a->id()); |
494 scoped_refptr<Layer> layer_dest_b = layer_dest_root->children()[1]; | 493 scoped_refptr<Layer> layer_dest_b = layer_dest_root->children()[1]; |
495 EXPECT_EQ(layer_src_b->id(), layer_dest_b->id()); | 494 EXPECT_EQ(layer_src_b->id(), layer_dest_b->id()); |
496 | 495 |
497 // Swap order of the children. | 496 // Swap order of the children. |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
531 a | 530 a |
532 A child is then added to the root: | 531 A child is then added to the root: |
533 root | 532 root |
534 / \ | 533 / \ |
535 b a | 534 b a |
536 The tree is then serialized and deserialized again, and the the end | 535 The tree is then serialized and deserialized again, and the the end |
537 result should have the same structure and importantly it should | 536 result should have the same structure and importantly it should |
538 not have called InvalidatePropertyTreesIndices() for any of the layers, | 537 not have called InvalidatePropertyTreesIndices() for any of the layers, |
539 which would happen in for example SetLayerTreeHost(...) calls. | 538 which would happen in for example SetLayerTreeHost(...) calls. |
540 */ | 539 */ |
541 scoped_refptr<Layer> layer_src_root = Layer::Create(LayerSettings()); | 540 scoped_refptr<Layer> layer_src_root = Layer::Create(); |
542 scoped_refptr<Layer> layer_src_a = Layer::Create(LayerSettings()); | 541 scoped_refptr<Layer> layer_src_a = Layer::Create(); |
543 layer_src_root->AddChild(layer_src_a); | 542 layer_src_root->AddChild(layer_src_a); |
544 | 543 |
545 // Copy tree-structure to new root. | 544 // Copy tree-structure to new root. |
546 proto::LayerNode root_proto_1; | 545 proto::LayerNode root_proto_1; |
547 layer_src_root->ToLayerNodeProto(&root_proto_1); | 546 layer_src_root->ToLayerNodeProto(&root_proto_1); |
548 Layer::LayerIdMap dest_layer_map; | 547 Layer::LayerIdMap dest_layer_map; |
549 scoped_refptr<Layer> layer_dest_root = Layer::Create(LayerSettings()); | 548 scoped_refptr<Layer> layer_dest_root = Layer::Create(); |
550 layer_dest_root->FromLayerNodeProto(root_proto_1, dest_layer_map); | 549 layer_dest_root->FromLayerNodeProto(root_proto_1, dest_layer_map); |
551 | 550 |
552 // Ensure initial copy is correct. | 551 // Ensure initial copy is correct. |
553 ASSERT_EQ(1u, layer_dest_root->children().size()); | 552 ASSERT_EQ(1u, layer_dest_root->children().size()); |
554 scoped_refptr<Layer> layer_dest_a = layer_dest_root->children()[0]; | 553 scoped_refptr<Layer> layer_dest_a = layer_dest_root->children()[0]; |
555 EXPECT_EQ(layer_src_a->id(), layer_dest_a->id()); | 554 EXPECT_EQ(layer_src_a->id(), layer_dest_a->id()); |
556 | 555 |
557 // Fake the fact that the destination layer |a| now has a valid index. | 556 // Fake the fact that the destination layer |a| now has a valid index. |
558 layer_dest_root->transform_tree_index_ = 33; | 557 layer_dest_root->transform_tree_index_ = 33; |
559 layer_dest_a->transform_tree_index_ = 42; | 558 layer_dest_a->transform_tree_index_ = 42; |
560 | 559 |
561 // Add another child. | 560 // Add another child. |
562 scoped_refptr<Layer> layer_src_b = Layer::Create(LayerSettings()); | 561 scoped_refptr<Layer> layer_src_b = Layer::Create(); |
563 layer_src_root->AddChild(layer_src_b); | 562 layer_src_root->AddChild(layer_src_b); |
564 | 563 |
565 // Now serialize and deserialize again. | 564 // Now serialize and deserialize again. |
566 proto::LayerNode root_proto_2; | 565 proto::LayerNode root_proto_2; |
567 layer_src_root->ToLayerNodeProto(&root_proto_2); | 566 layer_src_root->ToLayerNodeProto(&root_proto_2); |
568 dest_layer_map[layer_dest_root->id()] = layer_dest_root; | 567 dest_layer_map[layer_dest_root->id()] = layer_dest_root; |
569 dest_layer_map[layer_dest_a->id()] = layer_dest_a; | 568 dest_layer_map[layer_dest_a->id()] = layer_dest_a; |
570 layer_dest_root->FromLayerNodeProto(root_proto_2, dest_layer_map); | 569 layer_dest_root->FromLayerNodeProto(root_proto_2, dest_layer_map); |
571 | 570 |
572 // Ensure second copy is correct. | 571 // Ensure second copy is correct. |
(...skipping 14 matching lines...) Expand all Loading... |
587 a b | 586 a b |
588 The |b| child is the removed from the root: | 587 The |b| child is the removed from the root: |
589 root | 588 root |
590 / | 589 / |
591 b | 590 b |
592 The tree is then serialized and deserialized again, and the the end | 591 The tree is then serialized and deserialized again, and the the end |
593 result should have the same structure and importantly it should | 592 result should have the same structure and importantly it should |
594 not have called InvalidatePropertyTreesIndices() for any of the layers, | 593 not have called InvalidatePropertyTreesIndices() for any of the layers, |
595 which would happen in for example SetLayerTreeHost(...) calls. | 594 which would happen in for example SetLayerTreeHost(...) calls. |
596 */ | 595 */ |
597 scoped_refptr<Layer> layer_src_root = Layer::Create(LayerSettings()); | 596 scoped_refptr<Layer> layer_src_root = Layer::Create(); |
598 scoped_refptr<Layer> layer_src_a = Layer::Create(LayerSettings()); | 597 scoped_refptr<Layer> layer_src_a = Layer::Create(); |
599 scoped_refptr<Layer> layer_src_b = Layer::Create(LayerSettings()); | 598 scoped_refptr<Layer> layer_src_b = Layer::Create(); |
600 layer_src_root->AddChild(layer_src_a); | 599 layer_src_root->AddChild(layer_src_a); |
601 layer_src_root->AddChild(layer_src_b); | 600 layer_src_root->AddChild(layer_src_b); |
602 | 601 |
603 // Copy tree-structure to new root. | 602 // Copy tree-structure to new root. |
604 proto::LayerNode root_proto_1; | 603 proto::LayerNode root_proto_1; |
605 layer_src_root->ToLayerNodeProto(&root_proto_1); | 604 layer_src_root->ToLayerNodeProto(&root_proto_1); |
606 Layer::LayerIdMap dest_layer_map; | 605 Layer::LayerIdMap dest_layer_map; |
607 scoped_refptr<Layer> layer_dest_root = Layer::Create(LayerSettings()); | 606 scoped_refptr<Layer> layer_dest_root = Layer::Create(); |
608 layer_dest_root->FromLayerNodeProto(root_proto_1, dest_layer_map); | 607 layer_dest_root->FromLayerNodeProto(root_proto_1, dest_layer_map); |
609 | 608 |
610 // Ensure initial copy is correct. | 609 // Ensure initial copy is correct. |
611 ASSERT_EQ(2u, layer_dest_root->children().size()); | 610 ASSERT_EQ(2u, layer_dest_root->children().size()); |
612 scoped_refptr<Layer> layer_dest_a = layer_dest_root->children()[0]; | 611 scoped_refptr<Layer> layer_dest_a = layer_dest_root->children()[0]; |
613 EXPECT_EQ(layer_src_a->id(), layer_dest_a->id()); | 612 EXPECT_EQ(layer_src_a->id(), layer_dest_a->id()); |
614 scoped_refptr<Layer> layer_dest_b = layer_dest_root->children()[1]; | 613 scoped_refptr<Layer> layer_dest_b = layer_dest_root->children()[1]; |
615 EXPECT_EQ(layer_src_b->id(), layer_dest_b->id()); | 614 EXPECT_EQ(layer_src_b->id(), layer_dest_b->id()); |
616 | 615 |
617 // Remove one child. | 616 // Remove one child. |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
650 root | 649 root |
651 / \ | 650 / \ |
652 a b | 651 a b |
653 / | 652 / |
654 c | 653 c |
655 The tree is then serialized and deserialized again, and the the end | 654 The tree is then serialized and deserialized again, and the the end |
656 result should have the same structure and importantly it should | 655 result should have the same structure and importantly it should |
657 not have called InvalidatePropertyTreesIndices() for any of the layers, | 656 not have called InvalidatePropertyTreesIndices() for any of the layers, |
658 which would happen in for example SetLayerTreeHost(...) calls. | 657 which would happen in for example SetLayerTreeHost(...) calls. |
659 */ | 658 */ |
660 scoped_refptr<Layer> layer_src_root = Layer::Create(LayerSettings()); | 659 scoped_refptr<Layer> layer_src_root = Layer::Create(); |
661 scoped_refptr<Layer> layer_src_a = Layer::Create(LayerSettings()); | 660 scoped_refptr<Layer> layer_src_a = Layer::Create(); |
662 scoped_refptr<Layer> layer_src_b = Layer::Create(LayerSettings()); | 661 scoped_refptr<Layer> layer_src_b = Layer::Create(); |
663 scoped_refptr<Layer> layer_src_c = Layer::Create(LayerSettings()); | 662 scoped_refptr<Layer> layer_src_c = Layer::Create(); |
664 layer_src_root->AddChild(layer_src_a); | 663 layer_src_root->AddChild(layer_src_a); |
665 layer_src_root->AddChild(layer_src_b); | 664 layer_src_root->AddChild(layer_src_b); |
666 layer_src_b->AddChild(layer_src_c); | 665 layer_src_b->AddChild(layer_src_c); |
667 | 666 |
668 // Copy tree-structure to new root. | 667 // Copy tree-structure to new root. |
669 proto::LayerNode root_proto_1; | 668 proto::LayerNode root_proto_1; |
670 layer_src_root->ToLayerNodeProto(&root_proto_1); | 669 layer_src_root->ToLayerNodeProto(&root_proto_1); |
671 Layer::LayerIdMap dest_layer_map; | 670 Layer::LayerIdMap dest_layer_map; |
672 scoped_refptr<Layer> layer_dest_root = Layer::Create(LayerSettings()); | 671 scoped_refptr<Layer> layer_dest_root = Layer::Create(); |
673 layer_dest_root->FromLayerNodeProto(root_proto_1, dest_layer_map); | 672 layer_dest_root->FromLayerNodeProto(root_proto_1, dest_layer_map); |
674 | 673 |
675 // Ensure initial copy is correct. | 674 // Ensure initial copy is correct. |
676 ASSERT_EQ(2u, layer_dest_root->children().size()); | 675 ASSERT_EQ(2u, layer_dest_root->children().size()); |
677 scoped_refptr<Layer> layer_dest_a = layer_dest_root->children()[0]; | 676 scoped_refptr<Layer> layer_dest_a = layer_dest_root->children()[0]; |
678 scoped_refptr<Layer> layer_dest_b = layer_dest_root->children()[1]; | 677 scoped_refptr<Layer> layer_dest_b = layer_dest_root->children()[1]; |
679 EXPECT_EQ(layer_src_a->id(), layer_dest_a->id()); | 678 EXPECT_EQ(layer_src_a->id(), layer_dest_a->id()); |
680 EXPECT_EQ(layer_src_b->id(), layer_dest_b->id()); | 679 EXPECT_EQ(layer_src_b->id(), layer_dest_b->id()); |
681 ASSERT_EQ(1u, layer_dest_b->children().size()); | 680 ASSERT_EQ(1u, layer_dest_b->children().size()); |
682 scoped_refptr<Layer> layer_dest_c = layer_dest_b->children()[0]; | 681 scoped_refptr<Layer> layer_dest_c = layer_dest_b->children()[0]; |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
729 root | 728 root |
730 / \ | 729 / \ |
731 a b | 730 a b |
732 \ | 731 \ |
733 c | 732 c |
734 The tree is then serialized and deserialized again, and the the end | 733 The tree is then serialized and deserialized again, and the the end |
735 result should have the same structure and importantly it should | 734 result should have the same structure and importantly it should |
736 not have called InvalidatePropertyTreesIndices() for any of the layers, | 735 not have called InvalidatePropertyTreesIndices() for any of the layers, |
737 which would happen in for example SetLayerTreeHost(...) calls. | 736 which would happen in for example SetLayerTreeHost(...) calls. |
738 */ | 737 */ |
739 scoped_refptr<Layer> layer_src_root = Layer::Create(LayerSettings()); | 738 scoped_refptr<Layer> layer_src_root = Layer::Create(); |
740 scoped_refptr<Layer> layer_src_a = Layer::Create(LayerSettings()); | 739 scoped_refptr<Layer> layer_src_a = Layer::Create(); |
741 scoped_refptr<Layer> layer_src_b = Layer::Create(LayerSettings()); | 740 scoped_refptr<Layer> layer_src_b = Layer::Create(); |
742 scoped_refptr<Layer> layer_src_c = Layer::Create(LayerSettings()); | 741 scoped_refptr<Layer> layer_src_c = Layer::Create(); |
743 layer_src_root->AddChild(layer_src_a); | 742 layer_src_root->AddChild(layer_src_a); |
744 layer_src_root->AddChild(layer_src_b); | 743 layer_src_root->AddChild(layer_src_b); |
745 layer_src_a->AddChild(layer_src_c); | 744 layer_src_a->AddChild(layer_src_c); |
746 | 745 |
747 // Copy tree-structure to new root. | 746 // Copy tree-structure to new root. |
748 proto::LayerNode root_proto_1; | 747 proto::LayerNode root_proto_1; |
749 layer_src_root->ToLayerNodeProto(&root_proto_1); | 748 layer_src_root->ToLayerNodeProto(&root_proto_1); |
750 Layer::LayerIdMap dest_layer_map; | 749 Layer::LayerIdMap dest_layer_map; |
751 scoped_refptr<Layer> layer_dest_root = Layer::Create(LayerSettings()); | 750 scoped_refptr<Layer> layer_dest_root = Layer::Create(); |
752 layer_dest_root->FromLayerNodeProto(root_proto_1, dest_layer_map); | 751 layer_dest_root->FromLayerNodeProto(root_proto_1, dest_layer_map); |
753 | 752 |
754 // Ensure initial copy is correct. | 753 // Ensure initial copy is correct. |
755 ASSERT_EQ(2u, layer_dest_root->children().size()); | 754 ASSERT_EQ(2u, layer_dest_root->children().size()); |
756 scoped_refptr<Layer> layer_dest_a = layer_dest_root->children()[0]; | 755 scoped_refptr<Layer> layer_dest_a = layer_dest_root->children()[0]; |
757 scoped_refptr<Layer> layer_dest_b = layer_dest_root->children()[1]; | 756 scoped_refptr<Layer> layer_dest_b = layer_dest_root->children()[1]; |
758 EXPECT_EQ(layer_src_a->id(), layer_dest_a->id()); | 757 EXPECT_EQ(layer_src_a->id(), layer_dest_a->id()); |
759 EXPECT_EQ(layer_src_b->id(), layer_dest_b->id()); | 758 EXPECT_EQ(layer_src_b->id(), layer_dest_b->id()); |
760 ASSERT_EQ(1u, layer_dest_a->children().size()); | 759 ASSERT_EQ(1u, layer_dest_a->children().size()); |
761 scoped_refptr<Layer> layer_dest_c = layer_dest_a->children()[0]; | 760 scoped_refptr<Layer> layer_dest_c = layer_dest_a->children()[0]; |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
810 : LayerTreeHost(params, CompositorMode::SINGLE_THREADED) { | 809 : LayerTreeHost(params, CompositorMode::SINGLE_THREADED) { |
811 InitializeSingleThreaded(single_thread_client, | 810 InitializeSingleThreaded(single_thread_client, |
812 base::ThreadTaskRunnerHandle::Get(), nullptr); | 811 base::ThreadTaskRunnerHandle::Get(), nullptr); |
813 } | 812 } |
814 | 813 |
815 MOCK_METHOD0(SetNeedsCommit, void()); | 814 MOCK_METHOD0(SetNeedsCommit, void()); |
816 MOCK_METHOD0(SetNeedsUpdateLayers, void()); | 815 MOCK_METHOD0(SetNeedsUpdateLayers, void()); |
817 MOCK_METHOD0(SetNeedsFullTreeSync, void()); | 816 MOCK_METHOD0(SetNeedsFullTreeSync, void()); |
818 }; | 817 }; |
819 | 818 |
820 class LayerTreeSettingsForLayerTest : public LayerTreeSettings { | |
821 public: | |
822 LayerTreeSettingsForLayerTest() { use_compositor_animation_timelines = true; } | |
823 }; | |
824 | |
825 class LayerTest : public testing::Test { | 819 class LayerTest : public testing::Test { |
826 public: | 820 public: |
827 LayerTest() | 821 LayerTest() |
828 : host_impl_(LayerTreeSettingsForLayerTest(), | 822 : host_impl_(LayerTreeSettings(), |
829 &task_runner_provider_, | 823 &task_runner_provider_, |
830 &shared_bitmap_manager_, | 824 &shared_bitmap_manager_, |
831 &task_graph_runner_), | 825 &task_graph_runner_), |
832 fake_client_(FakeLayerTreeHostClient::DIRECT_3D) { | 826 fake_client_(FakeLayerTreeHostClient::DIRECT_3D) { |
833 layer_settings_.use_compositor_animation_timelines = | 827 timeline_impl_ = |
834 settings().use_compositor_animation_timelines; | 828 AnimationTimeline::Create(AnimationIdProvider::NextTimelineId()); |
835 if (settings().use_compositor_animation_timelines) { | 829 timeline_impl_->set_is_impl_only(true); |
836 timeline_impl_ = | 830 host_impl_.animation_host()->AddAnimationTimeline(timeline_impl_); |
837 AnimationTimeline::Create(AnimationIdProvider::NextTimelineId()); | |
838 timeline_impl_->set_is_impl_only(true); | |
839 host_impl_.animation_host()->AddAnimationTimeline(timeline_impl_); | |
840 } | |
841 } | 831 } |
842 | 832 |
843 const LayerTreeSettings& settings() { return settings_; } | 833 const LayerTreeSettings& settings() { return settings_; } |
844 scoped_refptr<AnimationTimeline> timeline_impl() { return timeline_impl_; } | 834 scoped_refptr<AnimationTimeline> timeline_impl() { return timeline_impl_; } |
845 | 835 |
846 protected: | 836 protected: |
847 void SetUp() override { | 837 void SetUp() override { |
848 LayerTreeHost::InitParams params; | 838 LayerTreeHost::InitParams params; |
849 params.client = &fake_client_; | 839 params.client = &fake_client_; |
850 params.settings = &settings_; | 840 params.settings = &settings_; |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
884 EXPECT_EQ(child1_.get(), grand_child2_->parent()); | 874 EXPECT_EQ(child1_.get(), grand_child2_->parent()); |
885 | 875 |
886 ASSERT_EQ(1U, child2_->children().size()); | 876 ASSERT_EQ(1U, child2_->children().size()); |
887 EXPECT_EQ(grand_child3_, child2_->children()[0]); | 877 EXPECT_EQ(grand_child3_, child2_->children()[0]); |
888 EXPECT_EQ(child2_.get(), grand_child3_->parent()); | 878 EXPECT_EQ(child2_.get(), grand_child3_->parent()); |
889 | 879 |
890 ASSERT_EQ(0U, child3_->children().size()); | 880 ASSERT_EQ(0U, child3_->children().size()); |
891 } | 881 } |
892 | 882 |
893 void CreateSimpleTestTree() { | 883 void CreateSimpleTestTree() { |
894 parent_ = Layer::Create(layer_settings_); | 884 parent_ = Layer::Create(); |
895 child1_ = Layer::Create(layer_settings_); | 885 child1_ = Layer::Create(); |
896 child2_ = Layer::Create(layer_settings_); | 886 child2_ = Layer::Create(); |
897 child3_ = Layer::Create(layer_settings_); | 887 child3_ = Layer::Create(); |
898 grand_child1_ = Layer::Create(layer_settings_); | 888 grand_child1_ = Layer::Create(); |
899 grand_child2_ = Layer::Create(layer_settings_); | 889 grand_child2_ = Layer::Create(); |
900 grand_child3_ = Layer::Create(layer_settings_); | 890 grand_child3_ = Layer::Create(); |
901 | 891 |
902 EXPECT_CALL(*layer_tree_host_, SetNeedsFullTreeSync()).Times(AnyNumber()); | 892 EXPECT_CALL(*layer_tree_host_, SetNeedsFullTreeSync()).Times(AnyNumber()); |
903 layer_tree_host_->SetRootLayer(parent_); | 893 layer_tree_host_->SetRootLayer(parent_); |
904 | 894 |
905 parent_->AddChild(child1_); | 895 parent_->AddChild(child1_); |
906 parent_->AddChild(child2_); | 896 parent_->AddChild(child2_); |
907 parent_->AddChild(child3_); | 897 parent_->AddChild(child3_); |
908 child1_->AddChild(grand_child1_); | 898 child1_->AddChild(grand_child1_); |
909 child1_->AddChild(grand_child2_); | 899 child1_->AddChild(grand_child2_); |
910 child2_->AddChild(grand_child3_); | 900 child2_->AddChild(grand_child3_); |
(...skipping 13 matching lines...) Expand all Loading... |
924 scoped_refptr<Layer> parent_; | 914 scoped_refptr<Layer> parent_; |
925 scoped_refptr<Layer> child1_; | 915 scoped_refptr<Layer> child1_; |
926 scoped_refptr<Layer> child2_; | 916 scoped_refptr<Layer> child2_; |
927 scoped_refptr<Layer> child3_; | 917 scoped_refptr<Layer> child3_; |
928 scoped_refptr<Layer> grand_child1_; | 918 scoped_refptr<Layer> grand_child1_; |
929 scoped_refptr<Layer> grand_child2_; | 919 scoped_refptr<Layer> grand_child2_; |
930 scoped_refptr<Layer> grand_child3_; | 920 scoped_refptr<Layer> grand_child3_; |
931 | 921 |
932 scoped_refptr<AnimationTimeline> timeline_impl_; | 922 scoped_refptr<AnimationTimeline> timeline_impl_; |
933 | 923 |
934 LayerTreeSettingsForLayerTest settings_; | 924 LayerTreeSettings settings_; |
935 LayerSettings layer_settings_; | |
936 }; | 925 }; |
937 | 926 |
938 TEST_F(LayerTest, BasicCreateAndDestroy) { | 927 TEST_F(LayerTest, BasicCreateAndDestroy) { |
939 scoped_refptr<Layer> test_layer = Layer::Create(layer_settings_); | 928 scoped_refptr<Layer> test_layer = Layer::Create(); |
940 ASSERT_TRUE(test_layer.get()); | 929 ASSERT_TRUE(test_layer.get()); |
941 | 930 |
942 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(0); | 931 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(0); |
943 test_layer->SetLayerTreeHost(layer_tree_host_.get()); | 932 test_layer->SetLayerTreeHost(layer_tree_host_.get()); |
944 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); | 933 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); |
945 | 934 |
946 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(0); | 935 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(0); |
947 test_layer->SetLayerTreeHost(nullptr); | 936 test_layer->SetLayerTreeHost(nullptr); |
948 } | 937 } |
949 | 938 |
950 TEST_F(LayerTest, LayerPropertyChangedForSubtree) { | 939 TEST_F(LayerTest, LayerPropertyChangedForSubtree) { |
951 EXPECT_CALL(*layer_tree_host_, SetNeedsFullTreeSync()).Times(AtLeast(1)); | 940 EXPECT_CALL(*layer_tree_host_, SetNeedsFullTreeSync()).Times(AtLeast(1)); |
952 scoped_refptr<Layer> root = Layer::Create(layer_settings_); | 941 scoped_refptr<Layer> root = Layer::Create(); |
953 scoped_refptr<Layer> child = Layer::Create(layer_settings_); | 942 scoped_refptr<Layer> child = Layer::Create(); |
954 scoped_refptr<Layer> child2 = Layer::Create(layer_settings_); | 943 scoped_refptr<Layer> child2 = Layer::Create(); |
955 scoped_refptr<Layer> grand_child = Layer::Create(layer_settings_); | 944 scoped_refptr<Layer> grand_child = Layer::Create(); |
956 scoped_refptr<Layer> dummy_layer1 = Layer::Create(layer_settings_); | 945 scoped_refptr<Layer> dummy_layer1 = Layer::Create(); |
957 scoped_refptr<Layer> dummy_layer2 = Layer::Create(layer_settings_); | 946 scoped_refptr<Layer> dummy_layer2 = Layer::Create(); |
958 | 947 |
959 layer_tree_host_->SetRootLayer(root); | 948 layer_tree_host_->SetRootLayer(root); |
960 root->AddChild(child); | 949 root->AddChild(child); |
961 root->AddChild(child2); | 950 root->AddChild(child2); |
962 child->AddChild(grand_child); | 951 child->AddChild(grand_child); |
963 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1)); | 952 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1)); |
964 child->SetForceRenderSurface(true); | 953 child->SetForceRenderSurface(true); |
965 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1)); | 954 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1)); |
966 child2->SetScrollParent(grand_child.get()); | 955 child2->SetScrollParent(grand_child.get()); |
967 SkXfermode::Mode arbitrary_blend_mode = SkXfermode::kMultiply_Mode; | 956 SkXfermode::Mode arbitrary_blend_mode = SkXfermode::kMultiply_Mode; |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1127 gfx::Transform arbitrary_transform; | 1116 gfx::Transform arbitrary_transform; |
1128 arbitrary_transform.Scale3d(0.1f, 0.2f, 0.3f); | 1117 arbitrary_transform.Scale3d(0.1f, 0.2f, 0.3f); |
1129 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(1); | 1118 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(1); |
1130 root->SetTransform(arbitrary_transform); | 1119 root->SetTransform(arbitrary_transform); |
1131 node = layer_tree_host_->property_trees()->transform_tree.Node( | 1120 node = layer_tree_host_->property_trees()->transform_tree.Node( |
1132 root->transform_tree_index()); | 1121 root->transform_tree_index()); |
1133 EXPECT_TRUE(node->data.transform_changed); | 1122 EXPECT_TRUE(node->data.transform_changed); |
1134 } | 1123 } |
1135 | 1124 |
1136 TEST_F(LayerTest, AddAndRemoveChild) { | 1125 TEST_F(LayerTest, AddAndRemoveChild) { |
1137 scoped_refptr<Layer> parent = Layer::Create(layer_settings_); | 1126 scoped_refptr<Layer> parent = Layer::Create(); |
1138 scoped_refptr<Layer> child = Layer::Create(layer_settings_); | 1127 scoped_refptr<Layer> child = Layer::Create(); |
1139 | 1128 |
1140 // Upon creation, layers should not have children or parent. | 1129 // Upon creation, layers should not have children or parent. |
1141 ASSERT_EQ(0U, parent->children().size()); | 1130 ASSERT_EQ(0U, parent->children().size()); |
1142 EXPECT_FALSE(child->parent()); | 1131 EXPECT_FALSE(child->parent()); |
1143 | 1132 |
1144 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, layer_tree_host_->SetRootLayer(parent)); | 1133 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, layer_tree_host_->SetRootLayer(parent)); |
1145 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, parent->AddChild(child)); | 1134 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, parent->AddChild(child)); |
1146 | 1135 |
1147 ASSERT_EQ(1U, parent->children().size()); | 1136 ASSERT_EQ(1U, parent->children().size()); |
1148 EXPECT_EQ(child.get(), parent->children()[0].get()); | 1137 EXPECT_EQ(child.get(), parent->children()[0].get()); |
1149 EXPECT_EQ(parent.get(), child->parent()); | 1138 EXPECT_EQ(parent.get(), child->parent()); |
1150 EXPECT_EQ(parent.get(), child->RootLayer()); | 1139 EXPECT_EQ(parent.get(), child->RootLayer()); |
1151 | 1140 |
1152 EXPECT_SET_NEEDS_FULL_TREE_SYNC(AtLeast(1), child->RemoveFromParent()); | 1141 EXPECT_SET_NEEDS_FULL_TREE_SYNC(AtLeast(1), child->RemoveFromParent()); |
1153 } | 1142 } |
1154 | 1143 |
1155 TEST_F(LayerTest, AddSameChildTwice) { | 1144 TEST_F(LayerTest, AddSameChildTwice) { |
1156 EXPECT_CALL(*layer_tree_host_, SetNeedsFullTreeSync()).Times(AtLeast(1)); | 1145 EXPECT_CALL(*layer_tree_host_, SetNeedsFullTreeSync()).Times(AtLeast(1)); |
1157 | 1146 |
1158 scoped_refptr<Layer> parent = Layer::Create(layer_settings_); | 1147 scoped_refptr<Layer> parent = Layer::Create(); |
1159 scoped_refptr<Layer> child = Layer::Create(layer_settings_); | 1148 scoped_refptr<Layer> child = Layer::Create(); |
1160 | 1149 |
1161 layer_tree_host_->SetRootLayer(parent); | 1150 layer_tree_host_->SetRootLayer(parent); |
1162 | 1151 |
1163 ASSERT_EQ(0u, parent->children().size()); | 1152 ASSERT_EQ(0u, parent->children().size()); |
1164 | 1153 |
1165 parent->AddChild(child); | 1154 parent->AddChild(child); |
1166 ASSERT_EQ(1u, parent->children().size()); | 1155 ASSERT_EQ(1u, parent->children().size()); |
1167 EXPECT_EQ(parent.get(), child->parent()); | 1156 EXPECT_EQ(parent.get(), child->parent()); |
1168 | 1157 |
1169 parent->AddChild(child); | 1158 parent->AddChild(child); |
1170 ASSERT_EQ(1u, parent->children().size()); | 1159 ASSERT_EQ(1u, parent->children().size()); |
1171 EXPECT_EQ(parent.get(), child->parent()); | 1160 EXPECT_EQ(parent.get(), child->parent()); |
1172 } | 1161 } |
1173 | 1162 |
1174 TEST_F(LayerTest, InsertChild) { | 1163 TEST_F(LayerTest, InsertChild) { |
1175 scoped_refptr<Layer> parent = Layer::Create(layer_settings_); | 1164 scoped_refptr<Layer> parent = Layer::Create(); |
1176 scoped_refptr<Layer> child1 = Layer::Create(layer_settings_); | 1165 scoped_refptr<Layer> child1 = Layer::Create(); |
1177 scoped_refptr<Layer> child2 = Layer::Create(layer_settings_); | 1166 scoped_refptr<Layer> child2 = Layer::Create(); |
1178 scoped_refptr<Layer> child3 = Layer::Create(layer_settings_); | 1167 scoped_refptr<Layer> child3 = Layer::Create(); |
1179 scoped_refptr<Layer> child4 = Layer::Create(layer_settings_); | 1168 scoped_refptr<Layer> child4 = Layer::Create(); |
1180 | 1169 |
1181 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, layer_tree_host_->SetRootLayer(parent)); | 1170 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, layer_tree_host_->SetRootLayer(parent)); |
1182 | 1171 |
1183 ASSERT_EQ(0U, parent->children().size()); | 1172 ASSERT_EQ(0U, parent->children().size()); |
1184 | 1173 |
1185 // Case 1: inserting to empty list. | 1174 // Case 1: inserting to empty list. |
1186 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, parent->InsertChild(child3, 0)); | 1175 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, parent->InsertChild(child3, 0)); |
1187 ASSERT_EQ(1U, parent->children().size()); | 1176 ASSERT_EQ(1U, parent->children().size()); |
1188 EXPECT_EQ(child3, parent->children()[0]); | 1177 EXPECT_EQ(child3, parent->children()[0]); |
1189 EXPECT_EQ(parent.get(), child3->parent()); | 1178 EXPECT_EQ(parent.get(), child3->parent()); |
(...skipping 20 matching lines...) Expand all Loading... |
1210 EXPECT_EQ(child1, parent->children()[0]); | 1199 EXPECT_EQ(child1, parent->children()[0]); |
1211 EXPECT_EQ(child2, parent->children()[1]); | 1200 EXPECT_EQ(child2, parent->children()[1]); |
1212 EXPECT_EQ(child3, parent->children()[2]); | 1201 EXPECT_EQ(child3, parent->children()[2]); |
1213 EXPECT_EQ(child4, parent->children()[3]); | 1202 EXPECT_EQ(child4, parent->children()[3]); |
1214 EXPECT_EQ(parent.get(), child4->parent()); | 1203 EXPECT_EQ(parent.get(), child4->parent()); |
1215 | 1204 |
1216 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, layer_tree_host_->SetRootLayer(nullptr)); | 1205 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, layer_tree_host_->SetRootLayer(nullptr)); |
1217 } | 1206 } |
1218 | 1207 |
1219 TEST_F(LayerTest, InsertChildPastEndOfList) { | 1208 TEST_F(LayerTest, InsertChildPastEndOfList) { |
1220 scoped_refptr<Layer> parent = Layer::Create(layer_settings_); | 1209 scoped_refptr<Layer> parent = Layer::Create(); |
1221 scoped_refptr<Layer> child1 = Layer::Create(layer_settings_); | 1210 scoped_refptr<Layer> child1 = Layer::Create(); |
1222 scoped_refptr<Layer> child2 = Layer::Create(layer_settings_); | 1211 scoped_refptr<Layer> child2 = Layer::Create(); |
1223 | 1212 |
1224 ASSERT_EQ(0U, parent->children().size()); | 1213 ASSERT_EQ(0U, parent->children().size()); |
1225 | 1214 |
1226 // insert to an out-of-bounds index | 1215 // insert to an out-of-bounds index |
1227 parent->InsertChild(child1, 53); | 1216 parent->InsertChild(child1, 53); |
1228 | 1217 |
1229 ASSERT_EQ(1U, parent->children().size()); | 1218 ASSERT_EQ(1U, parent->children().size()); |
1230 EXPECT_EQ(child1, parent->children()[0]); | 1219 EXPECT_EQ(child1, parent->children()[0]); |
1231 | 1220 |
1232 // insert another child to out-of-bounds, when list is not already empty. | 1221 // insert another child to out-of-bounds, when list is not already empty. |
1233 parent->InsertChild(child2, 2459); | 1222 parent->InsertChild(child2, 2459); |
1234 | 1223 |
1235 ASSERT_EQ(2U, parent->children().size()); | 1224 ASSERT_EQ(2U, parent->children().size()); |
1236 EXPECT_EQ(child1, parent->children()[0]); | 1225 EXPECT_EQ(child1, parent->children()[0]); |
1237 EXPECT_EQ(child2, parent->children()[1]); | 1226 EXPECT_EQ(child2, parent->children()[1]); |
1238 } | 1227 } |
1239 | 1228 |
1240 TEST_F(LayerTest, InsertSameChildTwice) { | 1229 TEST_F(LayerTest, InsertSameChildTwice) { |
1241 scoped_refptr<Layer> parent = Layer::Create(layer_settings_); | 1230 scoped_refptr<Layer> parent = Layer::Create(); |
1242 scoped_refptr<Layer> child1 = Layer::Create(layer_settings_); | 1231 scoped_refptr<Layer> child1 = Layer::Create(); |
1243 scoped_refptr<Layer> child2 = Layer::Create(layer_settings_); | 1232 scoped_refptr<Layer> child2 = Layer::Create(); |
1244 | 1233 |
1245 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, layer_tree_host_->SetRootLayer(parent)); | 1234 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, layer_tree_host_->SetRootLayer(parent)); |
1246 | 1235 |
1247 ASSERT_EQ(0U, parent->children().size()); | 1236 ASSERT_EQ(0U, parent->children().size()); |
1248 | 1237 |
1249 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, parent->InsertChild(child1, 0)); | 1238 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, parent->InsertChild(child1, 0)); |
1250 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, parent->InsertChild(child2, 1)); | 1239 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, parent->InsertChild(child2, 1)); |
1251 | 1240 |
1252 ASSERT_EQ(2U, parent->children().size()); | 1241 ASSERT_EQ(2U, parent->children().size()); |
1253 EXPECT_EQ(child1, parent->children()[0]); | 1242 EXPECT_EQ(child1, parent->children()[0]); |
1254 EXPECT_EQ(child2, parent->children()[1]); | 1243 EXPECT_EQ(child2, parent->children()[1]); |
1255 | 1244 |
1256 // Inserting the same child again should cause the child to be removed and | 1245 // Inserting the same child again should cause the child to be removed and |
1257 // re-inserted at the new location. | 1246 // re-inserted at the new location. |
1258 EXPECT_SET_NEEDS_FULL_TREE_SYNC(AtLeast(1), parent->InsertChild(child1, 1)); | 1247 EXPECT_SET_NEEDS_FULL_TREE_SYNC(AtLeast(1), parent->InsertChild(child1, 1)); |
1259 | 1248 |
1260 // child1 should now be at the end of the list. | 1249 // child1 should now be at the end of the list. |
1261 ASSERT_EQ(2U, parent->children().size()); | 1250 ASSERT_EQ(2U, parent->children().size()); |
1262 EXPECT_EQ(child2, parent->children()[0]); | 1251 EXPECT_EQ(child2, parent->children()[0]); |
1263 EXPECT_EQ(child1, parent->children()[1]); | 1252 EXPECT_EQ(child1, parent->children()[1]); |
1264 | 1253 |
1265 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, layer_tree_host_->SetRootLayer(nullptr)); | 1254 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, layer_tree_host_->SetRootLayer(nullptr)); |
1266 } | 1255 } |
1267 | 1256 |
1268 TEST_F(LayerTest, ReplaceChildWithNewChild) { | 1257 TEST_F(LayerTest, ReplaceChildWithNewChild) { |
1269 CreateSimpleTestTree(); | 1258 CreateSimpleTestTree(); |
1270 scoped_refptr<Layer> child4 = Layer::Create(layer_settings_); | 1259 scoped_refptr<Layer> child4 = Layer::Create(); |
1271 | 1260 |
1272 EXPECT_FALSE(child4->parent()); | 1261 EXPECT_FALSE(child4->parent()); |
1273 | 1262 |
1274 EXPECT_SET_NEEDS_FULL_TREE_SYNC( | 1263 EXPECT_SET_NEEDS_FULL_TREE_SYNC( |
1275 AtLeast(1), parent_->ReplaceChild(child2_.get(), child4)); | 1264 AtLeast(1), parent_->ReplaceChild(child2_.get(), child4)); |
1276 EXPECT_FALSE(parent_->NeedsDisplayForTesting()); | 1265 EXPECT_FALSE(parent_->NeedsDisplayForTesting()); |
1277 EXPECT_FALSE(child1_->NeedsDisplayForTesting()); | 1266 EXPECT_FALSE(child1_->NeedsDisplayForTesting()); |
1278 EXPECT_FALSE(child2_->NeedsDisplayForTesting()); | 1267 EXPECT_FALSE(child2_->NeedsDisplayForTesting()); |
1279 EXPECT_FALSE(child3_->NeedsDisplayForTesting()); | 1268 EXPECT_FALSE(child3_->NeedsDisplayForTesting()); |
1280 EXPECT_FALSE(child4->NeedsDisplayForTesting()); | 1269 EXPECT_FALSE(child4->NeedsDisplayForTesting()); |
1281 | 1270 |
1282 ASSERT_EQ(static_cast<size_t>(3), parent_->children().size()); | 1271 ASSERT_EQ(static_cast<size_t>(3), parent_->children().size()); |
1283 EXPECT_EQ(child1_, parent_->children()[0]); | 1272 EXPECT_EQ(child1_, parent_->children()[0]); |
1284 EXPECT_EQ(child4, parent_->children()[1]); | 1273 EXPECT_EQ(child4, parent_->children()[1]); |
1285 EXPECT_EQ(child3_, parent_->children()[2]); | 1274 EXPECT_EQ(child3_, parent_->children()[2]); |
1286 EXPECT_EQ(parent_.get(), child4->parent()); | 1275 EXPECT_EQ(parent_.get(), child4->parent()); |
1287 | 1276 |
1288 EXPECT_FALSE(child2_->parent()); | 1277 EXPECT_FALSE(child2_->parent()); |
1289 } | 1278 } |
1290 | 1279 |
1291 TEST_F(LayerTest, ReplaceChildWithNewChildThatHasOtherParent) { | 1280 TEST_F(LayerTest, ReplaceChildWithNewChildThatHasOtherParent) { |
1292 CreateSimpleTestTree(); | 1281 CreateSimpleTestTree(); |
1293 | 1282 |
1294 // create another simple tree with test_layer and child4. | 1283 // create another simple tree with test_layer and child4. |
1295 scoped_refptr<Layer> test_layer = Layer::Create(layer_settings_); | 1284 scoped_refptr<Layer> test_layer = Layer::Create(); |
1296 scoped_refptr<Layer> child4 = Layer::Create(layer_settings_); | 1285 scoped_refptr<Layer> child4 = Layer::Create(); |
1297 test_layer->AddChild(child4); | 1286 test_layer->AddChild(child4); |
1298 ASSERT_EQ(1U, test_layer->children().size()); | 1287 ASSERT_EQ(1U, test_layer->children().size()); |
1299 EXPECT_EQ(child4, test_layer->children()[0]); | 1288 EXPECT_EQ(child4, test_layer->children()[0]); |
1300 EXPECT_EQ(test_layer.get(), child4->parent()); | 1289 EXPECT_EQ(test_layer.get(), child4->parent()); |
1301 | 1290 |
1302 EXPECT_SET_NEEDS_FULL_TREE_SYNC( | 1291 EXPECT_SET_NEEDS_FULL_TREE_SYNC( |
1303 AtLeast(1), parent_->ReplaceChild(child2_.get(), child4)); | 1292 AtLeast(1), parent_->ReplaceChild(child2_.get(), child4)); |
1304 | 1293 |
1305 ASSERT_EQ(3U, parent_->children().size()); | 1294 ASSERT_EQ(3U, parent_->children().size()); |
1306 EXPECT_EQ(child1_, parent_->children()[0]); | 1295 EXPECT_EQ(child1_, parent_->children()[0]); |
1307 EXPECT_EQ(child4, parent_->children()[1]); | 1296 EXPECT_EQ(child4, parent_->children()[1]); |
1308 EXPECT_EQ(child3_, parent_->children()[2]); | 1297 EXPECT_EQ(child3_, parent_->children()[2]); |
1309 EXPECT_EQ(parent_.get(), child4->parent()); | 1298 EXPECT_EQ(parent_.get(), child4->parent()); |
1310 | 1299 |
1311 // test_layer should no longer have child4, | 1300 // test_layer should no longer have child4, |
1312 // and child2 should no longer have a parent. | 1301 // and child2 should no longer have a parent. |
1313 ASSERT_EQ(0U, test_layer->children().size()); | 1302 ASSERT_EQ(0U, test_layer->children().size()); |
1314 EXPECT_FALSE(child2_->parent()); | 1303 EXPECT_FALSE(child2_->parent()); |
1315 } | 1304 } |
1316 | 1305 |
1317 TEST_F(LayerTest, DeleteRemovedScrollParent) { | 1306 TEST_F(LayerTest, DeleteRemovedScrollParent) { |
1318 scoped_refptr<Layer> parent = Layer::Create(layer_settings_); | 1307 scoped_refptr<Layer> parent = Layer::Create(); |
1319 scoped_refptr<Layer> child1 = Layer::Create(layer_settings_); | 1308 scoped_refptr<Layer> child1 = Layer::Create(); |
1320 scoped_refptr<Layer> child2 = Layer::Create(layer_settings_); | 1309 scoped_refptr<Layer> child2 = Layer::Create(); |
1321 | 1310 |
1322 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, layer_tree_host_->SetRootLayer(parent)); | 1311 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, layer_tree_host_->SetRootLayer(parent)); |
1323 | 1312 |
1324 ASSERT_EQ(0U, parent->children().size()); | 1313 ASSERT_EQ(0U, parent->children().size()); |
1325 | 1314 |
1326 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, parent->InsertChild(child1, 0)); | 1315 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, parent->InsertChild(child1, 0)); |
1327 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, parent->InsertChild(child2, 1)); | 1316 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, parent->InsertChild(child2, 1)); |
1328 | 1317 |
1329 ASSERT_EQ(2U, parent->children().size()); | 1318 ASSERT_EQ(2U, parent->children().size()); |
1330 EXPECT_EQ(child1, parent->children()[0]); | 1319 EXPECT_EQ(child1, parent->children()[0]); |
1331 EXPECT_EQ(child2, parent->children()[1]); | 1320 EXPECT_EQ(child2, parent->children()[1]); |
1332 | 1321 |
1333 EXPECT_SET_NEEDS_COMMIT(2, child1->SetScrollParent(child2.get())); | 1322 EXPECT_SET_NEEDS_COMMIT(2, child1->SetScrollParent(child2.get())); |
1334 | 1323 |
1335 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, child2->RemoveFromParent()); | 1324 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, child2->RemoveFromParent()); |
1336 | 1325 |
1337 child1->reset_needs_push_properties_for_testing(); | 1326 child1->reset_needs_push_properties_for_testing(); |
1338 | 1327 |
1339 EXPECT_SET_NEEDS_COMMIT(1, child2 = nullptr); | 1328 EXPECT_SET_NEEDS_COMMIT(1, child2 = nullptr); |
1340 | 1329 |
1341 EXPECT_TRUE(child1->needs_push_properties()); | 1330 EXPECT_TRUE(child1->needs_push_properties()); |
1342 | 1331 |
1343 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, layer_tree_host_->SetRootLayer(nullptr)); | 1332 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, layer_tree_host_->SetRootLayer(nullptr)); |
1344 } | 1333 } |
1345 | 1334 |
1346 TEST_F(LayerTest, DeleteRemovedScrollChild) { | 1335 TEST_F(LayerTest, DeleteRemovedScrollChild) { |
1347 scoped_refptr<Layer> parent = Layer::Create(layer_settings_); | 1336 scoped_refptr<Layer> parent = Layer::Create(); |
1348 scoped_refptr<Layer> child1 = Layer::Create(layer_settings_); | 1337 scoped_refptr<Layer> child1 = Layer::Create(); |
1349 scoped_refptr<Layer> child2 = Layer::Create(layer_settings_); | 1338 scoped_refptr<Layer> child2 = Layer::Create(); |
1350 | 1339 |
1351 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, layer_tree_host_->SetRootLayer(parent)); | 1340 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, layer_tree_host_->SetRootLayer(parent)); |
1352 | 1341 |
1353 ASSERT_EQ(0U, parent->children().size()); | 1342 ASSERT_EQ(0U, parent->children().size()); |
1354 | 1343 |
1355 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, parent->InsertChild(child1, 0)); | 1344 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, parent->InsertChild(child1, 0)); |
1356 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, parent->InsertChild(child2, 1)); | 1345 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, parent->InsertChild(child2, 1)); |
1357 | 1346 |
1358 ASSERT_EQ(2U, parent->children().size()); | 1347 ASSERT_EQ(2U, parent->children().size()); |
1359 EXPECT_EQ(child1, parent->children()[0]); | 1348 EXPECT_EQ(child1, parent->children()[0]); |
(...skipping 29 matching lines...) Expand all Loading... |
1389 | 1378 |
1390 EXPECT_SET_NEEDS_FULL_TREE_SYNC(AtLeast(3), parent_->RemoveAllChildren()); | 1379 EXPECT_SET_NEEDS_FULL_TREE_SYNC(AtLeast(3), parent_->RemoveAllChildren()); |
1391 | 1380 |
1392 ASSERT_EQ(0U, parent_->children().size()); | 1381 ASSERT_EQ(0U, parent_->children().size()); |
1393 EXPECT_FALSE(child1_->parent()); | 1382 EXPECT_FALSE(child1_->parent()); |
1394 EXPECT_FALSE(child2_->parent()); | 1383 EXPECT_FALSE(child2_->parent()); |
1395 EXPECT_FALSE(child3_->parent()); | 1384 EXPECT_FALSE(child3_->parent()); |
1396 } | 1385 } |
1397 | 1386 |
1398 TEST_F(LayerTest, SetChildren) { | 1387 TEST_F(LayerTest, SetChildren) { |
1399 scoped_refptr<Layer> old_parent = Layer::Create(layer_settings_); | 1388 scoped_refptr<Layer> old_parent = Layer::Create(); |
1400 scoped_refptr<Layer> new_parent = Layer::Create(layer_settings_); | 1389 scoped_refptr<Layer> new_parent = Layer::Create(); |
1401 | 1390 |
1402 scoped_refptr<Layer> child1 = Layer::Create(layer_settings_); | 1391 scoped_refptr<Layer> child1 = Layer::Create(); |
1403 scoped_refptr<Layer> child2 = Layer::Create(layer_settings_); | 1392 scoped_refptr<Layer> child2 = Layer::Create(); |
1404 | 1393 |
1405 LayerList new_children; | 1394 LayerList new_children; |
1406 new_children.push_back(child1); | 1395 new_children.push_back(child1); |
1407 new_children.push_back(child2); | 1396 new_children.push_back(child2); |
1408 | 1397 |
1409 // Set up and verify initial test conditions: child1 has a parent, child2 has | 1398 // Set up and verify initial test conditions: child1 has a parent, child2 has |
1410 // no parent. | 1399 // no parent. |
1411 old_parent->AddChild(child1); | 1400 old_parent->AddChild(child1); |
1412 ASSERT_EQ(0U, new_parent->children().size()); | 1401 ASSERT_EQ(0U, new_parent->children().size()); |
1413 EXPECT_EQ(old_parent.get(), child1->parent()); | 1402 EXPECT_EQ(old_parent.get(), child1->parent()); |
1414 EXPECT_FALSE(child2->parent()); | 1403 EXPECT_FALSE(child2->parent()); |
1415 | 1404 |
1416 EXPECT_SET_NEEDS_FULL_TREE_SYNC( | 1405 EXPECT_SET_NEEDS_FULL_TREE_SYNC( |
1417 1, layer_tree_host_->SetRootLayer(new_parent)); | 1406 1, layer_tree_host_->SetRootLayer(new_parent)); |
1418 | 1407 |
1419 EXPECT_SET_NEEDS_FULL_TREE_SYNC( | 1408 EXPECT_SET_NEEDS_FULL_TREE_SYNC( |
1420 AtLeast(1), new_parent->SetChildren(new_children)); | 1409 AtLeast(1), new_parent->SetChildren(new_children)); |
1421 | 1410 |
1422 ASSERT_EQ(2U, new_parent->children().size()); | 1411 ASSERT_EQ(2U, new_parent->children().size()); |
1423 EXPECT_EQ(new_parent.get(), child1->parent()); | 1412 EXPECT_EQ(new_parent.get(), child1->parent()); |
1424 EXPECT_EQ(new_parent.get(), child2->parent()); | 1413 EXPECT_EQ(new_parent.get(), child2->parent()); |
1425 | 1414 |
1426 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, layer_tree_host_->SetRootLayer(nullptr)); | 1415 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, layer_tree_host_->SetRootLayer(nullptr)); |
1427 } | 1416 } |
1428 | 1417 |
1429 TEST_F(LayerTest, HasAncestor) { | 1418 TEST_F(LayerTest, HasAncestor) { |
1430 scoped_refptr<Layer> parent = Layer::Create(layer_settings_); | 1419 scoped_refptr<Layer> parent = Layer::Create(); |
1431 EXPECT_FALSE(parent->HasAncestor(parent.get())); | 1420 EXPECT_FALSE(parent->HasAncestor(parent.get())); |
1432 | 1421 |
1433 scoped_refptr<Layer> child = Layer::Create(layer_settings_); | 1422 scoped_refptr<Layer> child = Layer::Create(); |
1434 parent->AddChild(child); | 1423 parent->AddChild(child); |
1435 | 1424 |
1436 EXPECT_FALSE(child->HasAncestor(child.get())); | 1425 EXPECT_FALSE(child->HasAncestor(child.get())); |
1437 EXPECT_TRUE(child->HasAncestor(parent.get())); | 1426 EXPECT_TRUE(child->HasAncestor(parent.get())); |
1438 EXPECT_FALSE(parent->HasAncestor(child.get())); | 1427 EXPECT_FALSE(parent->HasAncestor(child.get())); |
1439 | 1428 |
1440 scoped_refptr<Layer> child_child = Layer::Create(layer_settings_); | 1429 scoped_refptr<Layer> child_child = Layer::Create(); |
1441 child->AddChild(child_child); | 1430 child->AddChild(child_child); |
1442 | 1431 |
1443 EXPECT_FALSE(child_child->HasAncestor(child_child.get())); | 1432 EXPECT_FALSE(child_child->HasAncestor(child_child.get())); |
1444 EXPECT_TRUE(child_child->HasAncestor(parent.get())); | 1433 EXPECT_TRUE(child_child->HasAncestor(parent.get())); |
1445 EXPECT_TRUE(child_child->HasAncestor(child.get())); | 1434 EXPECT_TRUE(child_child->HasAncestor(child.get())); |
1446 EXPECT_FALSE(parent->HasAncestor(child.get())); | 1435 EXPECT_FALSE(parent->HasAncestor(child.get())); |
1447 EXPECT_FALSE(parent->HasAncestor(child_child.get())); | 1436 EXPECT_FALSE(parent->HasAncestor(child_child.get())); |
1448 } | 1437 } |
1449 | 1438 |
1450 TEST_F(LayerTest, GetRootLayerAfterTreeManipulations) { | 1439 TEST_F(LayerTest, GetRootLayerAfterTreeManipulations) { |
1451 CreateSimpleTestTree(); | 1440 CreateSimpleTestTree(); |
1452 | 1441 |
1453 // For this test we don't care about SetNeedsFullTreeSync calls. | 1442 // For this test we don't care about SetNeedsFullTreeSync calls. |
1454 EXPECT_CALL(*layer_tree_host_, SetNeedsFullTreeSync()).Times(AnyNumber()); | 1443 EXPECT_CALL(*layer_tree_host_, SetNeedsFullTreeSync()).Times(AnyNumber()); |
1455 | 1444 |
1456 scoped_refptr<Layer> child4 = Layer::Create(layer_settings_); | 1445 scoped_refptr<Layer> child4 = Layer::Create(); |
1457 | 1446 |
1458 EXPECT_EQ(parent_.get(), parent_->RootLayer()); | 1447 EXPECT_EQ(parent_.get(), parent_->RootLayer()); |
1459 EXPECT_EQ(parent_.get(), child1_->RootLayer()); | 1448 EXPECT_EQ(parent_.get(), child1_->RootLayer()); |
1460 EXPECT_EQ(parent_.get(), child2_->RootLayer()); | 1449 EXPECT_EQ(parent_.get(), child2_->RootLayer()); |
1461 EXPECT_EQ(parent_.get(), child3_->RootLayer()); | 1450 EXPECT_EQ(parent_.get(), child3_->RootLayer()); |
1462 EXPECT_EQ(child4.get(), child4->RootLayer()); | 1451 EXPECT_EQ(child4.get(), child4->RootLayer()); |
1463 EXPECT_EQ(parent_.get(), grand_child1_->RootLayer()); | 1452 EXPECT_EQ(parent_.get(), grand_child1_->RootLayer()); |
1464 EXPECT_EQ(parent_.get(), grand_child2_->RootLayer()); | 1453 EXPECT_EQ(parent_.get(), grand_child2_->RootLayer()); |
1465 EXPECT_EQ(parent_.get(), grand_child3_->RootLayer()); | 1454 EXPECT_EQ(parent_.get(), grand_child3_->RootLayer()); |
1466 | 1455 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1501 EXPECT_EQ(parent_.get(), grand_child2_->RootLayer()); | 1490 EXPECT_EQ(parent_.get(), grand_child2_->RootLayer()); |
1502 EXPECT_EQ(grand_child3_.get(), grand_child3_->RootLayer()); | 1491 EXPECT_EQ(grand_child3_.get(), grand_child3_->RootLayer()); |
1503 } | 1492 } |
1504 | 1493 |
1505 TEST_F(LayerTest, CheckSetNeedsDisplayCausesCorrectBehavior) { | 1494 TEST_F(LayerTest, CheckSetNeedsDisplayCausesCorrectBehavior) { |
1506 // The semantics for SetNeedsDisplay which are tested here: | 1495 // The semantics for SetNeedsDisplay which are tested here: |
1507 // 1. sets NeedsDisplay flag appropriately. | 1496 // 1. sets NeedsDisplay flag appropriately. |
1508 // 2. indirectly calls SetNeedsUpdate, exactly once for each call to | 1497 // 2. indirectly calls SetNeedsUpdate, exactly once for each call to |
1509 // SetNeedsDisplay. | 1498 // SetNeedsDisplay. |
1510 | 1499 |
1511 scoped_refptr<Layer> test_layer = Layer::Create(layer_settings_); | 1500 scoped_refptr<Layer> test_layer = Layer::Create(); |
1512 EXPECT_SET_NEEDS_FULL_TREE_SYNC( | 1501 EXPECT_SET_NEEDS_FULL_TREE_SYNC( |
1513 1, layer_tree_host_->SetRootLayer(test_layer)); | 1502 1, layer_tree_host_->SetRootLayer(test_layer)); |
1514 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetIsDrawable(true)); | 1503 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetIsDrawable(true)); |
1515 | 1504 |
1516 gfx::Size test_bounds = gfx::Size(501, 508); | 1505 gfx::Size test_bounds = gfx::Size(501, 508); |
1517 | 1506 |
1518 gfx::Rect dirty1 = gfx::Rect(10, 15, 1, 2); | 1507 gfx::Rect dirty1 = gfx::Rect(10, 15, 1, 2); |
1519 gfx::Rect dirty2 = gfx::Rect(20, 25, 3, 4); | 1508 gfx::Rect dirty2 = gfx::Rect(20, 25, 3, 4); |
1520 gfx::Rect out_of_bounds_dirty_rect = gfx::Rect(400, 405, 500, 502); | 1509 gfx::Rect out_of_bounds_dirty_rect = gfx::Rect(400, 405, 500, 502); |
1521 | 1510 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1554 | 1543 |
1555 // Case 4: SetNeedsDisplay() with a non-drawable layer | 1544 // Case 4: SetNeedsDisplay() with a non-drawable layer |
1556 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetIsDrawable(false)); | 1545 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetIsDrawable(false)); |
1557 test_layer->ResetNeedsDisplayForTesting(); | 1546 test_layer->ResetNeedsDisplayForTesting(); |
1558 EXPECT_FALSE(test_layer->NeedsDisplayForTesting()); | 1547 EXPECT_FALSE(test_layer->NeedsDisplayForTesting()); |
1559 EXPECT_SET_NEEDS_UPDATE(0, test_layer->SetNeedsDisplayRect(dirty1)); | 1548 EXPECT_SET_NEEDS_UPDATE(0, test_layer->SetNeedsDisplayRect(dirty1)); |
1560 EXPECT_TRUE(test_layer->NeedsDisplayForTesting()); | 1549 EXPECT_TRUE(test_layer->NeedsDisplayForTesting()); |
1561 } | 1550 } |
1562 | 1551 |
1563 TEST_F(LayerTest, TestSettingMainThreadScrollingReason) { | 1552 TEST_F(LayerTest, TestSettingMainThreadScrollingReason) { |
1564 scoped_refptr<Layer> test_layer = Layer::Create(layer_settings_); | 1553 scoped_refptr<Layer> test_layer = Layer::Create(); |
1565 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, | 1554 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, |
1566 layer_tree_host_->SetRootLayer(test_layer)); | 1555 layer_tree_host_->SetRootLayer(test_layer)); |
1567 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetIsDrawable(true)); | 1556 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetIsDrawable(true)); |
1568 | 1557 |
1569 // sanity check of initial test condition | 1558 // sanity check of initial test condition |
1570 EXPECT_FALSE(test_layer->NeedsDisplayForTesting()); | 1559 EXPECT_FALSE(test_layer->NeedsDisplayForTesting()); |
1571 | 1560 |
1572 uint32_t reasons = 0, reasons_to_clear = 0, reasons_after_clearing = 0; | 1561 uint32_t reasons = 0, reasons_to_clear = 0, reasons_after_clearing = 0; |
1573 reasons |= MainThreadScrollingReason::kEventHandlers; | 1562 reasons |= MainThreadScrollingReason::kEventHandlers; |
1574 reasons |= MainThreadScrollingReason::kContinuingMainThreadScroll; | 1563 reasons |= MainThreadScrollingReason::kContinuingMainThreadScroll; |
(...skipping 30 matching lines...) Expand all Loading... |
1605 0, test_layer->ClearMainThreadScrollingReasons(reasons_to_clear)); | 1594 0, test_layer->ClearMainThreadScrollingReasons(reasons_to_clear)); |
1606 EXPECT_EQ(reasons_after_clearing, | 1595 EXPECT_EQ(reasons_after_clearing, |
1607 test_layer->main_thread_scrolling_reasons()); | 1596 test_layer->main_thread_scrolling_reasons()); |
1608 | 1597 |
1609 // Check that adding an existing condition doesn't set needs commit. | 1598 // Check that adding an existing condition doesn't set needs commit. |
1610 EXPECT_SET_NEEDS_COMMIT(0, test_layer->AddMainThreadScrollingReasons( | 1599 EXPECT_SET_NEEDS_COMMIT(0, test_layer->AddMainThreadScrollingReasons( |
1611 MainThreadScrollingReason::kEventHandlers)); | 1600 MainThreadScrollingReason::kEventHandlers)); |
1612 } | 1601 } |
1613 | 1602 |
1614 TEST_F(LayerTest, CheckPropertyChangeCausesCorrectBehavior) { | 1603 TEST_F(LayerTest, CheckPropertyChangeCausesCorrectBehavior) { |
1615 scoped_refptr<Layer> test_layer = Layer::Create(layer_settings_); | 1604 scoped_refptr<Layer> test_layer = Layer::Create(); |
1616 EXPECT_SET_NEEDS_FULL_TREE_SYNC( | 1605 EXPECT_SET_NEEDS_FULL_TREE_SYNC( |
1617 1, layer_tree_host_->SetRootLayer(test_layer)); | 1606 1, layer_tree_host_->SetRootLayer(test_layer)); |
1618 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetIsDrawable(true)); | 1607 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetIsDrawable(true)); |
1619 | 1608 |
1620 scoped_refptr<Layer> dummy_layer1 = Layer::Create(layer_settings_); | 1609 scoped_refptr<Layer> dummy_layer1 = Layer::Create(); |
1621 scoped_refptr<Layer> dummy_layer2 = Layer::Create(layer_settings_); | 1610 scoped_refptr<Layer> dummy_layer2 = Layer::Create(); |
1622 | 1611 |
1623 // sanity check of initial test condition | 1612 // sanity check of initial test condition |
1624 EXPECT_FALSE(test_layer->NeedsDisplayForTesting()); | 1613 EXPECT_FALSE(test_layer->NeedsDisplayForTesting()); |
1625 | 1614 |
1626 // Next, test properties that should call SetNeedsCommit (but not | 1615 // Next, test properties that should call SetNeedsCommit (but not |
1627 // SetNeedsDisplay). All properties need to be set to new values in order for | 1616 // SetNeedsDisplay). All properties need to be set to new values in order for |
1628 // SetNeedsCommit to be called. | 1617 // SetNeedsCommit to be called. |
1629 EXPECT_SET_NEEDS_COMMIT( | 1618 EXPECT_SET_NEEDS_COMMIT( |
1630 1, test_layer->SetTransformOrigin(gfx::Point3F(1.23f, 4.56f, 0.f))); | 1619 1, test_layer->SetTransformOrigin(gfx::Point3F(1.23f, 4.56f, 0.f))); |
1631 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetBackgroundColor(SK_ColorLTGRAY)); | 1620 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetBackgroundColor(SK_ColorLTGRAY)); |
(...skipping 30 matching lines...) Expand all Loading... |
1662 dummy_layer2.get())); | 1651 dummy_layer2.get())); |
1663 | 1652 |
1664 // The above tests should not have caused a change to the needs_display flag. | 1653 // The above tests should not have caused a change to the needs_display flag. |
1665 EXPECT_FALSE(test_layer->NeedsDisplayForTesting()); | 1654 EXPECT_FALSE(test_layer->NeedsDisplayForTesting()); |
1666 | 1655 |
1667 // As layers are removed from the tree, they will cause a tree sync. | 1656 // As layers are removed from the tree, they will cause a tree sync. |
1668 EXPECT_CALL(*layer_tree_host_, SetNeedsFullTreeSync()).Times((AnyNumber())); | 1657 EXPECT_CALL(*layer_tree_host_, SetNeedsFullTreeSync()).Times((AnyNumber())); |
1669 } | 1658 } |
1670 | 1659 |
1671 TEST_F(LayerTest, PushPropertiesAccumulatesUpdateRect) { | 1660 TEST_F(LayerTest, PushPropertiesAccumulatesUpdateRect) { |
1672 scoped_refptr<Layer> test_layer = Layer::Create(layer_settings_); | 1661 scoped_refptr<Layer> test_layer = Layer::Create(); |
1673 scoped_ptr<LayerImpl> impl_layer = | 1662 scoped_ptr<LayerImpl> impl_layer = |
1674 LayerImpl::Create(host_impl_.active_tree(), 1); | 1663 LayerImpl::Create(host_impl_.active_tree(), 1); |
1675 | 1664 |
1676 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, | 1665 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, |
1677 layer_tree_host_->SetRootLayer(test_layer)); | 1666 layer_tree_host_->SetRootLayer(test_layer)); |
1678 | 1667 |
1679 host_impl_.active_tree()->SetRootLayer(std::move(impl_layer)); | 1668 host_impl_.active_tree()->SetRootLayer(std::move(impl_layer)); |
1680 LayerImpl* impl_layer_ptr = host_impl_.active_tree()->LayerById(1); | 1669 LayerImpl* impl_layer_ptr = host_impl_.active_tree()->LayerById(1); |
1681 test_layer->SetNeedsDisplayRect(gfx::Rect(5, 5)); | 1670 test_layer->SetNeedsDisplayRect(gfx::Rect(5, 5)); |
1682 test_layer->PushPropertiesTo(impl_layer_ptr); | 1671 test_layer->PushPropertiesTo(impl_layer_ptr); |
(...skipping 11 matching lines...) Expand all Loading... |
1694 // fresh without accumulation. | 1683 // fresh without accumulation. |
1695 host_impl_.active_tree()->ResetAllChangeTracking( | 1684 host_impl_.active_tree()->ResetAllChangeTracking( |
1696 PropertyTrees::ResetFlags::ALL_TREES); | 1685 PropertyTrees::ResetFlags::ALL_TREES); |
1697 test_layer->SetNeedsDisplayRect(gfx::Rect(10, 10, 5, 5)); | 1686 test_layer->SetNeedsDisplayRect(gfx::Rect(10, 10, 5, 5)); |
1698 test_layer->PushPropertiesTo(impl_layer_ptr); | 1687 test_layer->PushPropertiesTo(impl_layer_ptr); |
1699 EXPECT_FLOAT_RECT_EQ(gfx::RectF(10.f, 10.f, 5.f, 5.f), | 1688 EXPECT_FLOAT_RECT_EQ(gfx::RectF(10.f, 10.f, 5.f, 5.f), |
1700 impl_layer_ptr->update_rect()); | 1689 impl_layer_ptr->update_rect()); |
1701 } | 1690 } |
1702 | 1691 |
1703 TEST_F(LayerTest, PushPropertiesCausesLayerPropertyChangedForTransform) { | 1692 TEST_F(LayerTest, PushPropertiesCausesLayerPropertyChangedForTransform) { |
1704 scoped_refptr<Layer> test_layer = Layer::Create(layer_settings_); | 1693 scoped_refptr<Layer> test_layer = Layer::Create(); |
1705 scoped_ptr<LayerImpl> impl_layer = | 1694 scoped_ptr<LayerImpl> impl_layer = |
1706 LayerImpl::Create(host_impl_.active_tree(), 1); | 1695 LayerImpl::Create(host_impl_.active_tree(), 1); |
1707 | 1696 |
1708 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, | 1697 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, |
1709 layer_tree_host_->SetRootLayer(test_layer)); | 1698 layer_tree_host_->SetRootLayer(test_layer)); |
1710 | 1699 |
1711 gfx::Transform transform; | 1700 gfx::Transform transform; |
1712 transform.Rotate(45.0); | 1701 transform.Rotate(45.0); |
1713 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetTransform(transform)); | 1702 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetTransform(transform)); |
1714 | 1703 |
1715 EXPECT_FALSE(impl_layer->LayerPropertyChanged()); | 1704 EXPECT_FALSE(impl_layer->LayerPropertyChanged()); |
1716 | 1705 |
1717 test_layer->PushPropertiesTo(impl_layer.get()); | 1706 test_layer->PushPropertiesTo(impl_layer.get()); |
1718 | 1707 |
1719 EXPECT_TRUE(impl_layer->LayerPropertyChanged()); | 1708 EXPECT_TRUE(impl_layer->LayerPropertyChanged()); |
1720 } | 1709 } |
1721 | 1710 |
1722 TEST_F(LayerTest, PushPropertiesCausesLayerPropertyChangedForOpacity) { | 1711 TEST_F(LayerTest, PushPropertiesCausesLayerPropertyChangedForOpacity) { |
1723 scoped_refptr<Layer> test_layer = Layer::Create(layer_settings_); | 1712 scoped_refptr<Layer> test_layer = Layer::Create(); |
1724 scoped_ptr<LayerImpl> impl_layer = | 1713 scoped_ptr<LayerImpl> impl_layer = |
1725 LayerImpl::Create(host_impl_.active_tree(), 1); | 1714 LayerImpl::Create(host_impl_.active_tree(), 1); |
1726 | 1715 |
1727 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, | 1716 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, |
1728 layer_tree_host_->SetRootLayer(test_layer)); | 1717 layer_tree_host_->SetRootLayer(test_layer)); |
1729 | 1718 |
1730 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetOpacity(0.5f)); | 1719 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetOpacity(0.5f)); |
1731 | 1720 |
1732 EXPECT_FALSE(impl_layer->LayerPropertyChanged()); | 1721 EXPECT_FALSE(impl_layer->LayerPropertyChanged()); |
1733 | 1722 |
1734 test_layer->PushPropertiesTo(impl_layer.get()); | 1723 test_layer->PushPropertiesTo(impl_layer.get()); |
1735 | 1724 |
1736 EXPECT_TRUE(impl_layer->LayerPropertyChanged()); | 1725 EXPECT_TRUE(impl_layer->LayerPropertyChanged()); |
1737 } | 1726 } |
1738 | 1727 |
1739 TEST_F(LayerTest, MaskAndReplicaHasParent) { | 1728 TEST_F(LayerTest, MaskAndReplicaHasParent) { |
1740 scoped_refptr<Layer> parent = Layer::Create(layer_settings_); | 1729 scoped_refptr<Layer> parent = Layer::Create(); |
1741 scoped_refptr<Layer> child = Layer::Create(layer_settings_); | 1730 scoped_refptr<Layer> child = Layer::Create(); |
1742 scoped_refptr<Layer> mask = Layer::Create(layer_settings_); | 1731 scoped_refptr<Layer> mask = Layer::Create(); |
1743 scoped_refptr<Layer> replica = Layer::Create(layer_settings_); | 1732 scoped_refptr<Layer> replica = Layer::Create(); |
1744 scoped_refptr<Layer> replica_mask = Layer::Create(layer_settings_); | 1733 scoped_refptr<Layer> replica_mask = Layer::Create(); |
1745 scoped_refptr<Layer> mask_replacement = Layer::Create(layer_settings_); | 1734 scoped_refptr<Layer> mask_replacement = Layer::Create(); |
1746 scoped_refptr<Layer> replica_replacement = Layer::Create(layer_settings_); | 1735 scoped_refptr<Layer> replica_replacement = Layer::Create(); |
1747 scoped_refptr<Layer> replica_mask_replacement = | 1736 scoped_refptr<Layer> replica_mask_replacement = Layer::Create(); |
1748 Layer::Create(layer_settings_); | |
1749 | 1737 |
1750 parent->AddChild(child); | 1738 parent->AddChild(child); |
1751 child->SetMaskLayer(mask.get()); | 1739 child->SetMaskLayer(mask.get()); |
1752 child->SetReplicaLayer(replica.get()); | 1740 child->SetReplicaLayer(replica.get()); |
1753 replica->SetMaskLayer(replica_mask.get()); | 1741 replica->SetMaskLayer(replica_mask.get()); |
1754 | 1742 |
1755 EXPECT_EQ(parent.get(), child->parent()); | 1743 EXPECT_EQ(parent.get(), child->parent()); |
1756 EXPECT_EQ(child.get(), mask->parent()); | 1744 EXPECT_EQ(child.get(), mask->parent()); |
1757 EXPECT_EQ(child.get(), replica->parent()); | 1745 EXPECT_EQ(child.get(), replica->parent()); |
1758 EXPECT_EQ(replica.get(), replica_mask->parent()); | 1746 EXPECT_EQ(replica.get(), replica_mask->parent()); |
1759 | 1747 |
1760 replica->SetMaskLayer(replica_mask_replacement.get()); | 1748 replica->SetMaskLayer(replica_mask_replacement.get()); |
1761 EXPECT_EQ(nullptr, replica_mask->parent()); | 1749 EXPECT_EQ(nullptr, replica_mask->parent()); |
1762 EXPECT_EQ(replica.get(), replica_mask_replacement->parent()); | 1750 EXPECT_EQ(replica.get(), replica_mask_replacement->parent()); |
1763 | 1751 |
1764 child->SetMaskLayer(mask_replacement.get()); | 1752 child->SetMaskLayer(mask_replacement.get()); |
1765 EXPECT_EQ(nullptr, mask->parent()); | 1753 EXPECT_EQ(nullptr, mask->parent()); |
1766 EXPECT_EQ(child.get(), mask_replacement->parent()); | 1754 EXPECT_EQ(child.get(), mask_replacement->parent()); |
1767 | 1755 |
1768 child->SetReplicaLayer(replica_replacement.get()); | 1756 child->SetReplicaLayer(replica_replacement.get()); |
1769 EXPECT_EQ(nullptr, replica->parent()); | 1757 EXPECT_EQ(nullptr, replica->parent()); |
1770 EXPECT_EQ(child.get(), replica_replacement->parent()); | 1758 EXPECT_EQ(child.get(), replica_replacement->parent()); |
1771 | 1759 |
1772 EXPECT_EQ(replica.get(), replica->mask_layer()->parent()); | 1760 EXPECT_EQ(replica.get(), replica->mask_layer()->parent()); |
1773 } | 1761 } |
1774 | 1762 |
1775 TEST_F(LayerTest, CheckTransformIsInvertible) { | 1763 TEST_F(LayerTest, CheckTransformIsInvertible) { |
1776 scoped_refptr<Layer> layer = Layer::Create(layer_settings_); | 1764 scoped_refptr<Layer> layer = Layer::Create(); |
1777 scoped_ptr<LayerImpl> impl_layer = | 1765 scoped_ptr<LayerImpl> impl_layer = |
1778 LayerImpl::Create(host_impl_.active_tree(), 1); | 1766 LayerImpl::Create(host_impl_.active_tree(), 1); |
1779 EXPECT_CALL(*layer_tree_host_, SetNeedsFullTreeSync()).Times(1); | 1767 EXPECT_CALL(*layer_tree_host_, SetNeedsFullTreeSync()).Times(1); |
1780 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AnyNumber()); | 1768 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AnyNumber()); |
1781 layer_tree_host_->SetRootLayer(layer); | 1769 layer_tree_host_->SetRootLayer(layer); |
1782 | 1770 |
1783 EXPECT_TRUE(layer->transform_is_invertible()); | 1771 EXPECT_TRUE(layer->transform_is_invertible()); |
1784 | 1772 |
1785 gfx::Transform singular_transform; | 1773 gfx::Transform singular_transform; |
1786 singular_transform.Scale3d( | 1774 singular_transform.Scale3d( |
(...skipping 10 matching lines...) Expand all Loading... |
1797 | 1785 |
1798 layer->SetTransform(rotation_transform); | 1786 layer->SetTransform(rotation_transform); |
1799 layer->PushPropertiesTo(impl_layer.get()); | 1787 layer->PushPropertiesTo(impl_layer.get()); |
1800 EXPECT_TRUE(layer->transform_is_invertible()); | 1788 EXPECT_TRUE(layer->transform_is_invertible()); |
1801 EXPECT_TRUE(impl_layer->transform_is_invertible()); | 1789 EXPECT_TRUE(impl_layer->transform_is_invertible()); |
1802 | 1790 |
1803 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); | 1791 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); |
1804 } | 1792 } |
1805 | 1793 |
1806 TEST_F(LayerTest, TransformIsInvertibleAnimation) { | 1794 TEST_F(LayerTest, TransformIsInvertibleAnimation) { |
1807 scoped_refptr<Layer> layer = Layer::Create(layer_settings_); | 1795 scoped_refptr<Layer> layer = Layer::Create(); |
1808 scoped_ptr<LayerImpl> impl_layer = | 1796 scoped_ptr<LayerImpl> impl_layer = |
1809 LayerImpl::Create(host_impl_.active_tree(), 1); | 1797 LayerImpl::Create(host_impl_.active_tree(), 1); |
1810 EXPECT_CALL(*layer_tree_host_, SetNeedsFullTreeSync()).Times(1); | 1798 EXPECT_CALL(*layer_tree_host_, SetNeedsFullTreeSync()).Times(1); |
1811 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AnyNumber()); | 1799 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AnyNumber()); |
1812 layer_tree_host_->SetRootLayer(layer); | 1800 layer_tree_host_->SetRootLayer(layer); |
1813 | 1801 |
1814 EXPECT_TRUE(layer->transform_is_invertible()); | 1802 EXPECT_TRUE(layer->transform_is_invertible()); |
1815 | 1803 |
1816 gfx::Transform singular_transform; | 1804 gfx::Transform singular_transform; |
1817 singular_transform.Scale3d( | 1805 singular_transform.Scale3d( |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1865 for (size_t i = 0; i < layer->children().size(); ++i) | 1853 for (size_t i = 0; i < layer->children().size(); ++i) |
1866 AssertLayerTreeHostMatchesForSubtree(layer->children()[i].get(), host); | 1854 AssertLayerTreeHostMatchesForSubtree(layer->children()[i].get(), host); |
1867 | 1855 |
1868 if (layer->mask_layer()) | 1856 if (layer->mask_layer()) |
1869 AssertLayerTreeHostMatchesForSubtree(layer->mask_layer(), host); | 1857 AssertLayerTreeHostMatchesForSubtree(layer->mask_layer(), host); |
1870 | 1858 |
1871 if (layer->replica_layer()) | 1859 if (layer->replica_layer()) |
1872 AssertLayerTreeHostMatchesForSubtree(layer->replica_layer(), host); | 1860 AssertLayerTreeHostMatchesForSubtree(layer->replica_layer(), host); |
1873 } | 1861 } |
1874 | 1862 |
1875 class LayerLayerTreeHostTest : public testing::Test { | 1863 class LayerLayerTreeHostTest : public testing::Test {}; |
1876 public: | |
1877 LayerLayerTreeHostTest() { | |
1878 layer_settings_.use_compositor_animation_timelines = true; | |
1879 } | |
1880 | |
1881 protected: | |
1882 LayerSettings layer_settings_; | |
1883 }; | |
1884 | 1864 |
1885 TEST_F(LayerLayerTreeHostTest, EnteringTree) { | 1865 TEST_F(LayerLayerTreeHostTest, EnteringTree) { |
1886 scoped_refptr<Layer> parent = Layer::Create(layer_settings_); | 1866 scoped_refptr<Layer> parent = Layer::Create(); |
1887 scoped_refptr<Layer> child = Layer::Create(layer_settings_); | 1867 scoped_refptr<Layer> child = Layer::Create(); |
1888 scoped_refptr<Layer> mask = Layer::Create(layer_settings_); | 1868 scoped_refptr<Layer> mask = Layer::Create(); |
1889 scoped_refptr<Layer> replica = Layer::Create(layer_settings_); | 1869 scoped_refptr<Layer> replica = Layer::Create(); |
1890 scoped_refptr<Layer> replica_mask = Layer::Create(layer_settings_); | 1870 scoped_refptr<Layer> replica_mask = Layer::Create(); |
1891 | 1871 |
1892 // Set up a detached tree of layers. The host pointer should be nil for these | 1872 // Set up a detached tree of layers. The host pointer should be nil for these |
1893 // layers. | 1873 // layers. |
1894 parent->AddChild(child); | 1874 parent->AddChild(child); |
1895 child->SetMaskLayer(mask.get()); | 1875 child->SetMaskLayer(mask.get()); |
1896 child->SetReplicaLayer(replica.get()); | 1876 child->SetReplicaLayer(replica.get()); |
1897 replica->SetMaskLayer(replica_mask.get()); | 1877 replica->SetMaskLayer(replica_mask.get()); |
1898 | 1878 |
1899 AssertLayerTreeHostMatchesForSubtree(parent.get(), nullptr); | 1879 AssertLayerTreeHostMatchesForSubtree(parent.get(), nullptr); |
1900 | 1880 |
1901 LayerTreeHostFactory factory; | 1881 LayerTreeHostFactory factory; |
1902 scoped_ptr<LayerTreeHost> layer_tree_host = factory.Create(); | 1882 scoped_ptr<LayerTreeHost> layer_tree_host = factory.Create(); |
1903 // Setting the root layer should set the host pointer for all layers in the | 1883 // Setting the root layer should set the host pointer for all layers in the |
1904 // tree. | 1884 // tree. |
1905 layer_tree_host->SetRootLayer(parent.get()); | 1885 layer_tree_host->SetRootLayer(parent.get()); |
1906 | 1886 |
1907 AssertLayerTreeHostMatchesForSubtree(parent.get(), layer_tree_host.get()); | 1887 AssertLayerTreeHostMatchesForSubtree(parent.get(), layer_tree_host.get()); |
1908 | 1888 |
1909 // Clearing the root layer should also clear out the host pointers for all | 1889 // Clearing the root layer should also clear out the host pointers for all |
1910 // layers in the tree. | 1890 // layers in the tree. |
1911 layer_tree_host->SetRootLayer(nullptr); | 1891 layer_tree_host->SetRootLayer(nullptr); |
1912 | 1892 |
1913 AssertLayerTreeHostMatchesForSubtree(parent.get(), nullptr); | 1893 AssertLayerTreeHostMatchesForSubtree(parent.get(), nullptr); |
1914 } | 1894 } |
1915 | 1895 |
1916 TEST_F(LayerLayerTreeHostTest, AddingLayerSubtree) { | 1896 TEST_F(LayerLayerTreeHostTest, AddingLayerSubtree) { |
1917 scoped_refptr<Layer> parent = Layer::Create(layer_settings_); | 1897 scoped_refptr<Layer> parent = Layer::Create(); |
1918 LayerTreeHostFactory factory; | 1898 LayerTreeHostFactory factory; |
1919 scoped_ptr<LayerTreeHost> layer_tree_host = factory.Create(); | 1899 scoped_ptr<LayerTreeHost> layer_tree_host = factory.Create(); |
1920 | 1900 |
1921 layer_tree_host->SetRootLayer(parent.get()); | 1901 layer_tree_host->SetRootLayer(parent.get()); |
1922 | 1902 |
1923 EXPECT_EQ(parent->layer_tree_host(), layer_tree_host.get()); | 1903 EXPECT_EQ(parent->layer_tree_host(), layer_tree_host.get()); |
1924 | 1904 |
1925 // Adding a subtree to a layer already associated with a host should set the | 1905 // Adding a subtree to a layer already associated with a host should set the |
1926 // host pointer on all layers in that subtree. | 1906 // host pointer on all layers in that subtree. |
1927 scoped_refptr<Layer> child = Layer::Create(layer_settings_); | 1907 scoped_refptr<Layer> child = Layer::Create(); |
1928 scoped_refptr<Layer> grand_child = Layer::Create(layer_settings_); | 1908 scoped_refptr<Layer> grand_child = Layer::Create(); |
1929 child->AddChild(grand_child); | 1909 child->AddChild(grand_child); |
1930 | 1910 |
1931 // Masks, replicas, and replica masks should pick up the new host too. | 1911 // Masks, replicas, and replica masks should pick up the new host too. |
1932 scoped_refptr<Layer> child_mask = Layer::Create(layer_settings_); | 1912 scoped_refptr<Layer> child_mask = Layer::Create(); |
1933 child->SetMaskLayer(child_mask.get()); | 1913 child->SetMaskLayer(child_mask.get()); |
1934 scoped_refptr<Layer> child_replica = Layer::Create(layer_settings_); | 1914 scoped_refptr<Layer> child_replica = Layer::Create(); |
1935 child->SetReplicaLayer(child_replica.get()); | 1915 child->SetReplicaLayer(child_replica.get()); |
1936 scoped_refptr<Layer> child_replica_mask = Layer::Create(layer_settings_); | 1916 scoped_refptr<Layer> child_replica_mask = Layer::Create(); |
1937 child_replica->SetMaskLayer(child_replica_mask.get()); | 1917 child_replica->SetMaskLayer(child_replica_mask.get()); |
1938 | 1918 |
1939 parent->AddChild(child); | 1919 parent->AddChild(child); |
1940 AssertLayerTreeHostMatchesForSubtree(parent.get(), layer_tree_host.get()); | 1920 AssertLayerTreeHostMatchesForSubtree(parent.get(), layer_tree_host.get()); |
1941 | 1921 |
1942 layer_tree_host->SetRootLayer(nullptr); | 1922 layer_tree_host->SetRootLayer(nullptr); |
1943 } | 1923 } |
1944 | 1924 |
1945 TEST_F(LayerLayerTreeHostTest, ChangeHost) { | 1925 TEST_F(LayerLayerTreeHostTest, ChangeHost) { |
1946 scoped_refptr<Layer> parent = Layer::Create(layer_settings_); | 1926 scoped_refptr<Layer> parent = Layer::Create(); |
1947 scoped_refptr<Layer> child = Layer::Create(layer_settings_); | 1927 scoped_refptr<Layer> child = Layer::Create(); |
1948 scoped_refptr<Layer> mask = Layer::Create(layer_settings_); | 1928 scoped_refptr<Layer> mask = Layer::Create(); |
1949 scoped_refptr<Layer> replica = Layer::Create(layer_settings_); | 1929 scoped_refptr<Layer> replica = Layer::Create(); |
1950 scoped_refptr<Layer> replica_mask = Layer::Create(layer_settings_); | 1930 scoped_refptr<Layer> replica_mask = Layer::Create(); |
1951 | 1931 |
1952 // Same setup as the previous test. | 1932 // Same setup as the previous test. |
1953 parent->AddChild(child); | 1933 parent->AddChild(child); |
1954 child->SetMaskLayer(mask.get()); | 1934 child->SetMaskLayer(mask.get()); |
1955 child->SetReplicaLayer(replica.get()); | 1935 child->SetReplicaLayer(replica.get()); |
1956 replica->SetMaskLayer(replica_mask.get()); | 1936 replica->SetMaskLayer(replica_mask.get()); |
1957 | 1937 |
1958 LayerTreeHostFactory factory; | 1938 LayerTreeHostFactory factory; |
1959 scoped_ptr<LayerTreeHost> first_layer_tree_host = factory.Create(); | 1939 scoped_ptr<LayerTreeHost> first_layer_tree_host = factory.Create(); |
1960 first_layer_tree_host->SetRootLayer(parent.get()); | 1940 first_layer_tree_host->SetRootLayer(parent.get()); |
1961 | 1941 |
1962 AssertLayerTreeHostMatchesForSubtree(parent.get(), | 1942 AssertLayerTreeHostMatchesForSubtree(parent.get(), |
1963 first_layer_tree_host.get()); | 1943 first_layer_tree_host.get()); |
1964 | 1944 |
1965 // Now re-root the tree to a new host (simulating what we do on a context lost | 1945 // Now re-root the tree to a new host (simulating what we do on a context lost |
1966 // event). This should update the host pointers for all layers in the tree. | 1946 // event). This should update the host pointers for all layers in the tree. |
1967 scoped_ptr<LayerTreeHost> second_layer_tree_host = factory.Create(); | 1947 scoped_ptr<LayerTreeHost> second_layer_tree_host = factory.Create(); |
1968 second_layer_tree_host->SetRootLayer(parent.get()); | 1948 second_layer_tree_host->SetRootLayer(parent.get()); |
1969 | 1949 |
1970 AssertLayerTreeHostMatchesForSubtree(parent.get(), | 1950 AssertLayerTreeHostMatchesForSubtree(parent.get(), |
1971 second_layer_tree_host.get()); | 1951 second_layer_tree_host.get()); |
1972 | 1952 |
1973 second_layer_tree_host->SetRootLayer(nullptr); | 1953 second_layer_tree_host->SetRootLayer(nullptr); |
1974 } | 1954 } |
1975 | 1955 |
1976 TEST_F(LayerLayerTreeHostTest, ChangeHostInSubtree) { | 1956 TEST_F(LayerLayerTreeHostTest, ChangeHostInSubtree) { |
1977 scoped_refptr<Layer> first_parent = Layer::Create(layer_settings_); | 1957 scoped_refptr<Layer> first_parent = Layer::Create(); |
1978 scoped_refptr<Layer> first_child = Layer::Create(layer_settings_); | 1958 scoped_refptr<Layer> first_child = Layer::Create(); |
1979 scoped_refptr<Layer> second_parent = Layer::Create(layer_settings_); | 1959 scoped_refptr<Layer> second_parent = Layer::Create(); |
1980 scoped_refptr<Layer> second_child = Layer::Create(layer_settings_); | 1960 scoped_refptr<Layer> second_child = Layer::Create(); |
1981 scoped_refptr<Layer> second_grand_child = Layer::Create(layer_settings_); | 1961 scoped_refptr<Layer> second_grand_child = Layer::Create(); |
1982 | 1962 |
1983 // First put all children under the first parent and set the first host. | 1963 // First put all children under the first parent and set the first host. |
1984 first_parent->AddChild(first_child); | 1964 first_parent->AddChild(first_child); |
1985 second_child->AddChild(second_grand_child); | 1965 second_child->AddChild(second_grand_child); |
1986 first_parent->AddChild(second_child); | 1966 first_parent->AddChild(second_child); |
1987 | 1967 |
1988 LayerTreeHostFactory factory; | 1968 LayerTreeHostFactory factory; |
1989 scoped_ptr<LayerTreeHost> first_layer_tree_host = factory.Create(); | 1969 scoped_ptr<LayerTreeHost> first_layer_tree_host = factory.Create(); |
1990 first_layer_tree_host->SetRootLayer(first_parent.get()); | 1970 first_layer_tree_host->SetRootLayer(first_parent.get()); |
1991 | 1971 |
(...skipping 11 matching lines...) Expand all Loading... |
2003 EXPECT_EQ(second_layer_tree_host.get(), second_child->layer_tree_host()); | 1983 EXPECT_EQ(second_layer_tree_host.get(), second_child->layer_tree_host()); |
2004 EXPECT_EQ(second_layer_tree_host.get(), | 1984 EXPECT_EQ(second_layer_tree_host.get(), |
2005 second_grand_child->layer_tree_host()); | 1985 second_grand_child->layer_tree_host()); |
2006 | 1986 |
2007 // Test over, cleanup time. | 1987 // Test over, cleanup time. |
2008 first_layer_tree_host->SetRootLayer(nullptr); | 1988 first_layer_tree_host->SetRootLayer(nullptr); |
2009 second_layer_tree_host->SetRootLayer(nullptr); | 1989 second_layer_tree_host->SetRootLayer(nullptr); |
2010 } | 1990 } |
2011 | 1991 |
2012 TEST_F(LayerLayerTreeHostTest, ReplaceMaskAndReplicaLayer) { | 1992 TEST_F(LayerLayerTreeHostTest, ReplaceMaskAndReplicaLayer) { |
2013 scoped_refptr<Layer> parent = Layer::Create(layer_settings_); | 1993 scoped_refptr<Layer> parent = Layer::Create(); |
2014 scoped_refptr<Layer> mask = Layer::Create(layer_settings_); | 1994 scoped_refptr<Layer> mask = Layer::Create(); |
2015 scoped_refptr<Layer> replica = Layer::Create(layer_settings_); | 1995 scoped_refptr<Layer> replica = Layer::Create(); |
2016 scoped_refptr<Layer> mask_child = Layer::Create(layer_settings_); | 1996 scoped_refptr<Layer> mask_child = Layer::Create(); |
2017 scoped_refptr<Layer> replica_child = Layer::Create(layer_settings_); | 1997 scoped_refptr<Layer> replica_child = Layer::Create(); |
2018 scoped_refptr<Layer> mask_replacement = Layer::Create(layer_settings_); | 1998 scoped_refptr<Layer> mask_replacement = Layer::Create(); |
2019 scoped_refptr<Layer> replica_replacement = Layer::Create(layer_settings_); | 1999 scoped_refptr<Layer> replica_replacement = Layer::Create(); |
2020 | 2000 |
2021 parent->SetMaskLayer(mask.get()); | 2001 parent->SetMaskLayer(mask.get()); |
2022 parent->SetReplicaLayer(replica.get()); | 2002 parent->SetReplicaLayer(replica.get()); |
2023 mask->AddChild(mask_child); | 2003 mask->AddChild(mask_child); |
2024 replica->AddChild(replica_child); | 2004 replica->AddChild(replica_child); |
2025 | 2005 |
2026 LayerTreeHostFactory factory; | 2006 LayerTreeHostFactory factory; |
2027 scoped_ptr<LayerTreeHost> layer_tree_host = factory.Create(); | 2007 scoped_ptr<LayerTreeHost> layer_tree_host = factory.Create(); |
2028 layer_tree_host->SetRootLayer(parent.get()); | 2008 layer_tree_host->SetRootLayer(parent.get()); |
2029 | 2009 |
2030 AssertLayerTreeHostMatchesForSubtree(parent.get(), layer_tree_host.get()); | 2010 AssertLayerTreeHostMatchesForSubtree(parent.get(), layer_tree_host.get()); |
2031 | 2011 |
2032 // Replacing the mask should clear out the old mask's subtree's host pointers. | 2012 // Replacing the mask should clear out the old mask's subtree's host pointers. |
2033 parent->SetMaskLayer(mask_replacement.get()); | 2013 parent->SetMaskLayer(mask_replacement.get()); |
2034 EXPECT_EQ(nullptr, mask->layer_tree_host()); | 2014 EXPECT_EQ(nullptr, mask->layer_tree_host()); |
2035 EXPECT_EQ(nullptr, mask_child->layer_tree_host()); | 2015 EXPECT_EQ(nullptr, mask_child->layer_tree_host()); |
2036 | 2016 |
2037 // Same for replacing a replica layer. | 2017 // Same for replacing a replica layer. |
2038 parent->SetReplicaLayer(replica_replacement.get()); | 2018 parent->SetReplicaLayer(replica_replacement.get()); |
2039 EXPECT_EQ(nullptr, replica->layer_tree_host()); | 2019 EXPECT_EQ(nullptr, replica->layer_tree_host()); |
2040 EXPECT_EQ(nullptr, replica_child->layer_tree_host()); | 2020 EXPECT_EQ(nullptr, replica_child->layer_tree_host()); |
2041 | 2021 |
2042 // Test over, cleanup time. | 2022 // Test over, cleanup time. |
2043 layer_tree_host->SetRootLayer(nullptr); | 2023 layer_tree_host->SetRootLayer(nullptr); |
2044 } | 2024 } |
2045 | 2025 |
2046 TEST_F(LayerLayerTreeHostTest, DestroyHostWithNonNullRootLayer) { | 2026 TEST_F(LayerLayerTreeHostTest, DestroyHostWithNonNullRootLayer) { |
2047 scoped_refptr<Layer> root = Layer::Create(layer_settings_); | 2027 scoped_refptr<Layer> root = Layer::Create(); |
2048 scoped_refptr<Layer> child = Layer::Create(layer_settings_); | 2028 scoped_refptr<Layer> child = Layer::Create(); |
2049 root->AddChild(child); | 2029 root->AddChild(child); |
2050 LayerTreeHostFactory factory; | 2030 LayerTreeHostFactory factory; |
2051 scoped_ptr<LayerTreeHost> layer_tree_host = factory.Create(); | 2031 scoped_ptr<LayerTreeHost> layer_tree_host = factory.Create(); |
2052 layer_tree_host->SetRootLayer(root); | 2032 layer_tree_host->SetRootLayer(root); |
2053 } | 2033 } |
2054 | 2034 |
2055 TEST_F(LayerTest, SafeOpaqueBackgroundColor) { | 2035 TEST_F(LayerTest, SafeOpaqueBackgroundColor) { |
2056 LayerTreeHostFactory factory; | 2036 LayerTreeHostFactory factory; |
2057 scoped_ptr<LayerTreeHost> layer_tree_host = factory.Create(); | 2037 scoped_ptr<LayerTreeHost> layer_tree_host = factory.Create(); |
2058 | 2038 |
2059 scoped_refptr<Layer> layer = Layer::Create(layer_settings_); | 2039 scoped_refptr<Layer> layer = Layer::Create(); |
2060 layer_tree_host->SetRootLayer(layer); | 2040 layer_tree_host->SetRootLayer(layer); |
2061 | 2041 |
2062 for (int contents_opaque = 0; contents_opaque < 2; ++contents_opaque) { | 2042 for (int contents_opaque = 0; contents_opaque < 2; ++contents_opaque) { |
2063 for (int layer_opaque = 0; layer_opaque < 2; ++layer_opaque) { | 2043 for (int layer_opaque = 0; layer_opaque < 2; ++layer_opaque) { |
2064 for (int host_opaque = 0; host_opaque < 2; ++host_opaque) { | 2044 for (int host_opaque = 0; host_opaque < 2; ++host_opaque) { |
2065 layer->SetContentsOpaque(!!contents_opaque); | 2045 layer->SetContentsOpaque(!!contents_opaque); |
2066 layer->SetBackgroundColor(layer_opaque ? SK_ColorRED | 2046 layer->SetBackgroundColor(layer_opaque ? SK_ColorRED |
2067 : SK_ColorTRANSPARENT); | 2047 : SK_ColorTRANSPARENT); |
2068 layer_tree_host->set_background_color( | 2048 layer_tree_host->set_background_color( |
2069 host_opaque ? SK_ColorRED : SK_ColorTRANSPARENT); | 2049 host_opaque ? SK_ColorRED : SK_ColorTRANSPARENT); |
(...skipping 10 matching lines...) Expand all Loading... |
2080 << "Flags: " << contents_opaque << ", " << layer_opaque << ", " | 2060 << "Flags: " << contents_opaque << ", " << layer_opaque << ", " |
2081 << host_opaque << "\n"; | 2061 << host_opaque << "\n"; |
2082 } | 2062 } |
2083 } | 2063 } |
2084 } | 2064 } |
2085 } | 2065 } |
2086 } | 2066 } |
2087 | 2067 |
2088 class DrawsContentChangeLayer : public Layer { | 2068 class DrawsContentChangeLayer : public Layer { |
2089 public: | 2069 public: |
2090 static scoped_refptr<DrawsContentChangeLayer> Create( | 2070 static scoped_refptr<DrawsContentChangeLayer> Create() { |
2091 const LayerSettings& settings) { | 2071 return make_scoped_refptr(new DrawsContentChangeLayer()); |
2092 return make_scoped_refptr(new DrawsContentChangeLayer(settings)); | |
2093 } | 2072 } |
2094 | 2073 |
2095 void SetLayerTreeHost(LayerTreeHost* host) override { | 2074 void SetLayerTreeHost(LayerTreeHost* host) override { |
2096 Layer::SetLayerTreeHost(host); | 2075 Layer::SetLayerTreeHost(host); |
2097 SetFakeDrawsContent(!fake_draws_content_); | 2076 SetFakeDrawsContent(!fake_draws_content_); |
2098 } | 2077 } |
2099 | 2078 |
2100 bool HasDrawableContent() const override { | 2079 bool HasDrawableContent() const override { |
2101 return fake_draws_content_ && Layer::HasDrawableContent(); | 2080 return fake_draws_content_ && Layer::HasDrawableContent(); |
2102 } | 2081 } |
2103 | 2082 |
2104 void SetFakeDrawsContent(bool fake_draws_content) { | 2083 void SetFakeDrawsContent(bool fake_draws_content) { |
2105 fake_draws_content_ = fake_draws_content; | 2084 fake_draws_content_ = fake_draws_content; |
2106 UpdateDrawsContent(HasDrawableContent()); | 2085 UpdateDrawsContent(HasDrawableContent()); |
2107 } | 2086 } |
2108 | 2087 |
2109 private: | 2088 private: |
2110 explicit DrawsContentChangeLayer(const LayerSettings& settings) | 2089 DrawsContentChangeLayer() : fake_draws_content_(false) {} |
2111 : Layer(settings), fake_draws_content_(false) {} | |
2112 ~DrawsContentChangeLayer() override {} | 2090 ~DrawsContentChangeLayer() override {} |
2113 | 2091 |
2114 bool fake_draws_content_; | 2092 bool fake_draws_content_; |
2115 }; | 2093 }; |
2116 | 2094 |
2117 TEST_F(LayerTest, DrawsContentChangedInSetLayerTreeHost) { | 2095 TEST_F(LayerTest, DrawsContentChangedInSetLayerTreeHost) { |
2118 scoped_refptr<Layer> root_layer = Layer::Create(layer_settings_); | 2096 scoped_refptr<Layer> root_layer = Layer::Create(); |
2119 scoped_refptr<DrawsContentChangeLayer> becomes_not_draws_content = | 2097 scoped_refptr<DrawsContentChangeLayer> becomes_not_draws_content = |
2120 DrawsContentChangeLayer::Create(layer_settings_); | 2098 DrawsContentChangeLayer::Create(); |
2121 scoped_refptr<DrawsContentChangeLayer> becomes_draws_content = | 2099 scoped_refptr<DrawsContentChangeLayer> becomes_draws_content = |
2122 DrawsContentChangeLayer::Create(layer_settings_); | 2100 DrawsContentChangeLayer::Create(); |
2123 root_layer->SetIsDrawable(true); | 2101 root_layer->SetIsDrawable(true); |
2124 becomes_not_draws_content->SetIsDrawable(true); | 2102 becomes_not_draws_content->SetIsDrawable(true); |
2125 becomes_not_draws_content->SetFakeDrawsContent(true); | 2103 becomes_not_draws_content->SetFakeDrawsContent(true); |
2126 EXPECT_EQ(0, root_layer->NumDescendantsThatDrawContent()); | 2104 EXPECT_EQ(0, root_layer->NumDescendantsThatDrawContent()); |
2127 root_layer->AddChild(becomes_not_draws_content); | 2105 root_layer->AddChild(becomes_not_draws_content); |
2128 EXPECT_EQ(0, root_layer->NumDescendantsThatDrawContent()); | 2106 EXPECT_EQ(0, root_layer->NumDescendantsThatDrawContent()); |
2129 | 2107 |
2130 becomes_draws_content->SetIsDrawable(true); | 2108 becomes_draws_content->SetIsDrawable(true); |
2131 root_layer->AddChild(becomes_draws_content); | 2109 root_layer->AddChild(becomes_draws_content); |
2132 EXPECT_EQ(1, root_layer->NumDescendantsThatDrawContent()); | 2110 EXPECT_EQ(1, root_layer->NumDescendantsThatDrawContent()); |
2133 } | 2111 } |
2134 | 2112 |
2135 void ReceiveCopyOutputResult(int* result_count, | 2113 void ReceiveCopyOutputResult(int* result_count, |
2136 scoped_ptr<CopyOutputResult> result) { | 2114 scoped_ptr<CopyOutputResult> result) { |
2137 ++(*result_count); | 2115 ++(*result_count); |
2138 } | 2116 } |
2139 | 2117 |
2140 TEST_F(LayerTest, DedupesCopyOutputRequestsBySource) { | 2118 TEST_F(LayerTest, DedupesCopyOutputRequestsBySource) { |
2141 scoped_refptr<Layer> layer = Layer::Create(layer_settings_); | 2119 scoped_refptr<Layer> layer = Layer::Create(); |
2142 int result_count = 0; | 2120 int result_count = 0; |
2143 | 2121 |
2144 // Create identical requests without the source being set, and expect the | 2122 // Create identical requests without the source being set, and expect the |
2145 // layer does not abort either one. | 2123 // layer does not abort either one. |
2146 scoped_ptr<CopyOutputRequest> request = CopyOutputRequest::CreateRequest( | 2124 scoped_ptr<CopyOutputRequest> request = CopyOutputRequest::CreateRequest( |
2147 base::Bind(&ReceiveCopyOutputResult, &result_count)); | 2125 base::Bind(&ReceiveCopyOutputResult, &result_count)); |
2148 layer->RequestCopyOfOutput(std::move(request)); | 2126 layer->RequestCopyOfOutput(std::move(request)); |
2149 EXPECT_EQ(0, result_count); | 2127 EXPECT_EQ(0, result_count); |
2150 request = CopyOutputRequest::CreateRequest( | 2128 request = CopyOutputRequest::CreateRequest( |
2151 base::Bind(&ReceiveCopyOutputResult, &result_count)); | 2129 base::Bind(&ReceiveCopyOutputResult, &result_count)); |
2152 layer->RequestCopyOfOutput(std::move(request)); | 2130 layer->RequestCopyOfOutput(std::move(request)); |
2153 EXPECT_EQ(0, result_count); | 2131 EXPECT_EQ(0, result_count); |
2154 | 2132 |
2155 // When the layer is destroyed, expect both requests to be aborted. | 2133 // When the layer is destroyed, expect both requests to be aborted. |
2156 layer = nullptr; | 2134 layer = nullptr; |
2157 EXPECT_EQ(2, result_count); | 2135 EXPECT_EQ(2, result_count); |
2158 | 2136 |
2159 layer = Layer::Create(layer_settings_); | 2137 layer = Layer::Create(); |
2160 result_count = 0; | 2138 result_count = 0; |
2161 | 2139 |
2162 // Create identical requests, but this time the source is being set. Expect | 2140 // Create identical requests, but this time the source is being set. Expect |
2163 // the first request from |this| source aborts immediately when the second | 2141 // the first request from |this| source aborts immediately when the second |
2164 // request from |this| source is made. | 2142 // request from |this| source is made. |
2165 int did_receive_first_result_from_this_source = 0; | 2143 int did_receive_first_result_from_this_source = 0; |
2166 request = CopyOutputRequest::CreateRequest(base::Bind( | 2144 request = CopyOutputRequest::CreateRequest(base::Bind( |
2167 &ReceiveCopyOutputResult, &did_receive_first_result_from_this_source)); | 2145 &ReceiveCopyOutputResult, &did_receive_first_result_from_this_source)); |
2168 request->set_source(this); | 2146 request->set_source(this); |
2169 layer->RequestCopyOfOutput(std::move(request)); | 2147 layer->RequestCopyOfOutput(std::move(request)); |
(...skipping 25 matching lines...) Expand all Loading... |
2195 | 2173 |
2196 // When the layer is destroyed, the other three requests should be aborted. | 2174 // When the layer is destroyed, the other three requests should be aborted. |
2197 layer = nullptr; | 2175 layer = nullptr; |
2198 EXPECT_EQ(1, did_receive_first_result_from_this_source); | 2176 EXPECT_EQ(1, did_receive_first_result_from_this_source); |
2199 EXPECT_EQ(1, did_receive_result_from_different_source); | 2177 EXPECT_EQ(1, did_receive_result_from_different_source); |
2200 EXPECT_EQ(1, did_receive_result_from_anonymous_source); | 2178 EXPECT_EQ(1, did_receive_result_from_anonymous_source); |
2201 EXPECT_EQ(1, did_receive_second_result_from_this_source); | 2179 EXPECT_EQ(1, did_receive_second_result_from_this_source); |
2202 } | 2180 } |
2203 | 2181 |
2204 TEST_F(LayerTest, AnimationSchedulesLayerUpdate) { | 2182 TEST_F(LayerTest, AnimationSchedulesLayerUpdate) { |
2205 scoped_refptr<Layer> layer = Layer::Create(layer_settings_); | 2183 scoped_refptr<Layer> layer = Layer::Create(); |
2206 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, layer_tree_host_->SetRootLayer(layer)); | 2184 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, layer_tree_host_->SetRootLayer(layer)); |
2207 | 2185 |
2208 EXPECT_CALL(*layer_tree_host_, SetNeedsUpdateLayers()).Times(1); | 2186 EXPECT_CALL(*layer_tree_host_, SetNeedsUpdateLayers()).Times(1); |
2209 layer->OnOpacityAnimated(0.5f); | 2187 layer->OnOpacityAnimated(0.5f); |
2210 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); | 2188 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); |
2211 | 2189 |
2212 EXPECT_CALL(*layer_tree_host_, SetNeedsUpdateLayers()).Times(1); | 2190 EXPECT_CALL(*layer_tree_host_, SetNeedsUpdateLayers()).Times(1); |
2213 gfx::Transform transform; | 2191 gfx::Transform transform; |
2214 transform.Rotate(45.0); | 2192 transform.Rotate(45.0); |
2215 layer->OnTransformAnimated(transform); | 2193 layer->OnTransformAnimated(transform); |
2216 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); | 2194 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); |
2217 | 2195 |
2218 // Scroll offset animation should not schedule a layer update since it is | 2196 // Scroll offset animation should not schedule a layer update since it is |
2219 // handled similarly to normal compositor scroll updates. | 2197 // handled similarly to normal compositor scroll updates. |
2220 EXPECT_CALL(*layer_tree_host_, SetNeedsUpdateLayers()).Times(0); | 2198 EXPECT_CALL(*layer_tree_host_, SetNeedsUpdateLayers()).Times(0); |
2221 layer->OnScrollOffsetAnimated(gfx::ScrollOffset(10, 10)); | 2199 layer->OnScrollOffsetAnimated(gfx::ScrollOffset(10, 10)); |
2222 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); | 2200 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); |
2223 } | 2201 } |
2224 | 2202 |
2225 TEST_F(LayerTest, RecursiveHierarchySerialization) { | 2203 TEST_F(LayerTest, RecursiveHierarchySerialization) { |
2226 /* Testing serialization and deserialization of a tree that looks like this: | 2204 /* Testing serialization and deserialization of a tree that looks like this: |
2227 root | 2205 root |
2228 / \ | 2206 / \ |
2229 a b | 2207 a b |
2230 \ | 2208 \ |
2231 c | 2209 c |
2232 Layer c also has a mask layer and a replica layer. | 2210 Layer c also has a mask layer and a replica layer. |
2233 */ | 2211 */ |
2234 scoped_refptr<Layer> layer_src_root = Layer::Create(LayerSettings()); | 2212 scoped_refptr<Layer> layer_src_root = Layer::Create(); |
2235 scoped_refptr<Layer> layer_src_a = Layer::Create(LayerSettings()); | 2213 scoped_refptr<Layer> layer_src_a = Layer::Create(); |
2236 scoped_refptr<Layer> layer_src_b = Layer::Create(LayerSettings()); | 2214 scoped_refptr<Layer> layer_src_b = Layer::Create(); |
2237 scoped_refptr<Layer> layer_src_c = Layer::Create(LayerSettings()); | 2215 scoped_refptr<Layer> layer_src_c = Layer::Create(); |
2238 scoped_refptr<Layer> layer_src_c_mask = Layer::Create(LayerSettings()); | 2216 scoped_refptr<Layer> layer_src_c_mask = Layer::Create(); |
2239 scoped_refptr<Layer> layer_src_c_replica = Layer::Create(LayerSettings()); | 2217 scoped_refptr<Layer> layer_src_c_replica = Layer::Create(); |
2240 layer_src_root->AddChild(layer_src_a); | 2218 layer_src_root->AddChild(layer_src_a); |
2241 layer_src_root->AddChild(layer_src_b); | 2219 layer_src_root->AddChild(layer_src_b); |
2242 layer_src_b->AddChild(layer_src_c); | 2220 layer_src_b->AddChild(layer_src_c); |
2243 layer_src_c->SetMaskLayer(layer_src_c_mask.get()); | 2221 layer_src_c->SetMaskLayer(layer_src_c_mask.get()); |
2244 layer_src_c->SetReplicaLayer(layer_src_c_replica.get()); | 2222 layer_src_c->SetReplicaLayer(layer_src_c_replica.get()); |
2245 | 2223 |
2246 proto::LayerNode proto; | 2224 proto::LayerNode proto; |
2247 layer_src_root->ToLayerNodeProto(&proto); | 2225 layer_src_root->ToLayerNodeProto(&proto); |
2248 | 2226 |
2249 Layer::LayerIdMap empty_dest_layer_map; | 2227 Layer::LayerIdMap empty_dest_layer_map; |
2250 scoped_refptr<Layer> layer_dest_root = Layer::Create(LayerSettings()); | 2228 scoped_refptr<Layer> layer_dest_root = Layer::Create(); |
2251 layer_dest_root->FromLayerNodeProto(proto, empty_dest_layer_map); | 2229 layer_dest_root->FromLayerNodeProto(proto, empty_dest_layer_map); |
2252 | 2230 |
2253 EXPECT_EQ(layer_src_root->id(), layer_dest_root->id()); | 2231 EXPECT_EQ(layer_src_root->id(), layer_dest_root->id()); |
2254 EXPECT_EQ(nullptr, layer_dest_root->parent()); | 2232 EXPECT_EQ(nullptr, layer_dest_root->parent()); |
2255 ASSERT_EQ(2u, layer_dest_root->children().size()); | 2233 ASSERT_EQ(2u, layer_dest_root->children().size()); |
2256 | 2234 |
2257 scoped_refptr<Layer> layer_dest_a = layer_dest_root->children()[0]; | 2235 scoped_refptr<Layer> layer_dest_a = layer_dest_root->children()[0]; |
2258 EXPECT_EQ(layer_src_a->id(), layer_dest_a->id()); | 2236 EXPECT_EQ(layer_src_a->id(), layer_dest_a->id()); |
2259 EXPECT_EQ(layer_src_root->id(), layer_dest_a->parent()->id()); | 2237 EXPECT_EQ(layer_src_root->id(), layer_dest_a->parent()->id()); |
2260 EXPECT_EQ(0u, layer_dest_a->children().size()); | 2238 EXPECT_EQ(0u, layer_dest_a->children().size()); |
(...skipping 17 matching lines...) Expand all Loading... |
2278 root | 2256 root |
2279 / | 2257 / |
2280 a | 2258 a |
2281 The source tree is then updated by adding layer |b|: | 2259 The source tree is then updated by adding layer |b|: |
2282 root | 2260 root |
2283 / \ | 2261 / \ |
2284 a b | 2262 a b |
2285 The deserialization should then re-use the Layers from last | 2263 The deserialization should then re-use the Layers from last |
2286 deserialization. | 2264 deserialization. |
2287 */ | 2265 */ |
2288 scoped_refptr<Layer> layer_src_root = Layer::Create(LayerSettings()); | 2266 scoped_refptr<Layer> layer_src_root = Layer::Create(); |
2289 scoped_refptr<Layer> layer_src_a = Layer::Create(LayerSettings()); | 2267 scoped_refptr<Layer> layer_src_a = Layer::Create(); |
2290 layer_src_root->AddChild(layer_src_a); | 2268 layer_src_root->AddChild(layer_src_a); |
2291 | 2269 |
2292 proto::LayerNode root_proto_1; | 2270 proto::LayerNode root_proto_1; |
2293 layer_src_root->ToLayerNodeProto(&root_proto_1); | 2271 layer_src_root->ToLayerNodeProto(&root_proto_1); |
2294 | 2272 |
2295 Layer::LayerIdMap dest_layer_map_1; | 2273 Layer::LayerIdMap dest_layer_map_1; |
2296 scoped_refptr<Layer> layer_dest_root = Layer::Create(LayerSettings()); | 2274 scoped_refptr<Layer> layer_dest_root = Layer::Create(); |
2297 layer_dest_root->FromLayerNodeProto(root_proto_1, dest_layer_map_1); | 2275 layer_dest_root->FromLayerNodeProto(root_proto_1, dest_layer_map_1); |
2298 | 2276 |
2299 EXPECT_EQ(layer_src_root->id(), layer_dest_root->id()); | 2277 EXPECT_EQ(layer_src_root->id(), layer_dest_root->id()); |
2300 ASSERT_EQ(1u, layer_dest_root->children().size()); | 2278 ASSERT_EQ(1u, layer_dest_root->children().size()); |
2301 scoped_refptr<Layer> layer_dest_a_1 = layer_dest_root->children()[0]; | 2279 scoped_refptr<Layer> layer_dest_a_1 = layer_dest_root->children()[0]; |
2302 EXPECT_EQ(layer_src_a->id(), layer_dest_a_1->id()); | 2280 EXPECT_EQ(layer_src_a->id(), layer_dest_a_1->id()); |
2303 | 2281 |
2304 // Setup new destination layer map. | 2282 // Setup new destination layer map. |
2305 Layer::LayerIdMap dest_layer_map_2; | 2283 Layer::LayerIdMap dest_layer_map_2; |
2306 dest_layer_map_2[layer_dest_root->id()] = layer_dest_root; | 2284 dest_layer_map_2[layer_dest_root->id()] = layer_dest_root; |
2307 dest_layer_map_2[layer_dest_a_1->id()] = layer_dest_a_1; | 2285 dest_layer_map_2[layer_dest_a_1->id()] = layer_dest_a_1; |
2308 | 2286 |
2309 // Add Layer |b|. | 2287 // Add Layer |b|. |
2310 scoped_refptr<Layer> layer_src_b = Layer::Create(LayerSettings()); | 2288 scoped_refptr<Layer> layer_src_b = Layer::Create(); |
2311 layer_src_root->AddChild(layer_src_b); | 2289 layer_src_root->AddChild(layer_src_b); |
2312 | 2290 |
2313 // Second serialization. | 2291 // Second serialization. |
2314 proto::LayerNode root_proto_2; | 2292 proto::LayerNode root_proto_2; |
2315 layer_src_root->ToLayerNodeProto(&root_proto_2); | 2293 layer_src_root->ToLayerNodeProto(&root_proto_2); |
2316 | 2294 |
2317 // Second deserialization. | 2295 // Second deserialization. |
2318 layer_dest_root->FromLayerNodeProto(root_proto_2, dest_layer_map_2); | 2296 layer_dest_root->FromLayerNodeProto(root_proto_2, dest_layer_map_2); |
2319 | 2297 |
2320 EXPECT_EQ(layer_src_root->id(), layer_dest_root->id()); | 2298 EXPECT_EQ(layer_src_root->id(), layer_dest_root->id()); |
(...skipping 18 matching lines...) Expand all Loading... |
2339 looks like this: | 2317 looks like this: |
2340 root | 2318 root |
2341 / \ | 2319 / \ |
2342 a b | 2320 a b |
2343 \ | 2321 \ |
2344 c | 2322 c |
2345 \ | 2323 \ |
2346 d | 2324 d |
2347 Then the subtree rooted at node |b| is deleted in the next update. | 2325 Then the subtree rooted at node |b| is deleted in the next update. |
2348 */ | 2326 */ |
2349 scoped_refptr<Layer> layer_src_root = Layer::Create(LayerSettings()); | 2327 scoped_refptr<Layer> layer_src_root = Layer::Create(); |
2350 scoped_refptr<Layer> layer_src_a = Layer::Create(LayerSettings()); | 2328 scoped_refptr<Layer> layer_src_a = Layer::Create(); |
2351 scoped_refptr<Layer> layer_src_b = Layer::Create(LayerSettings()); | 2329 scoped_refptr<Layer> layer_src_b = Layer::Create(); |
2352 scoped_refptr<Layer> layer_src_c = Layer::Create(LayerSettings()); | 2330 scoped_refptr<Layer> layer_src_c = Layer::Create(); |
2353 scoped_refptr<Layer> layer_src_d = Layer::Create(LayerSettings()); | 2331 scoped_refptr<Layer> layer_src_d = Layer::Create(); |
2354 layer_src_root->AddChild(layer_src_a); | 2332 layer_src_root->AddChild(layer_src_a); |
2355 layer_src_root->AddChild(layer_src_b); | 2333 layer_src_root->AddChild(layer_src_b); |
2356 layer_src_b->AddChild(layer_src_c); | 2334 layer_src_b->AddChild(layer_src_c); |
2357 layer_src_c->AddChild(layer_src_d); | 2335 layer_src_c->AddChild(layer_src_d); |
2358 | 2336 |
2359 // Serialization 1. | 2337 // Serialization 1. |
2360 proto::LayerNode proto1; | 2338 proto::LayerNode proto1; |
2361 layer_src_root->ToLayerNodeProto(&proto1); | 2339 layer_src_root->ToLayerNodeProto(&proto1); |
2362 | 2340 |
2363 // Deserialization 1. | 2341 // Deserialization 1. |
2364 Layer::LayerIdMap empty_dest_layer_map; | 2342 Layer::LayerIdMap empty_dest_layer_map; |
2365 scoped_refptr<Layer> layer_dest_root = Layer::Create(LayerSettings()); | 2343 scoped_refptr<Layer> layer_dest_root = Layer::Create(); |
2366 layer_dest_root->FromLayerNodeProto(proto1, empty_dest_layer_map); | 2344 layer_dest_root->FromLayerNodeProto(proto1, empty_dest_layer_map); |
2367 | 2345 |
2368 EXPECT_EQ(layer_src_root->id(), layer_dest_root->id()); | 2346 EXPECT_EQ(layer_src_root->id(), layer_dest_root->id()); |
2369 ASSERT_EQ(2u, layer_dest_root->children().size()); | 2347 ASSERT_EQ(2u, layer_dest_root->children().size()); |
2370 scoped_refptr<Layer> layer_dest_a = layer_dest_root->children()[0]; | 2348 scoped_refptr<Layer> layer_dest_a = layer_dest_root->children()[0]; |
2371 scoped_refptr<Layer> layer_dest_b = layer_dest_root->children()[1]; | 2349 scoped_refptr<Layer> layer_dest_b = layer_dest_root->children()[1]; |
2372 ASSERT_EQ(1u, layer_dest_b->children().size()); | 2350 ASSERT_EQ(1u, layer_dest_b->children().size()); |
2373 scoped_refptr<Layer> layer_dest_c = layer_dest_b->children()[0]; | 2351 scoped_refptr<Layer> layer_dest_c = layer_dest_b->children()[0]; |
2374 ASSERT_EQ(1u, layer_dest_c->children().size()); | 2352 ASSERT_EQ(1u, layer_dest_c->children().size()); |
2375 scoped_refptr<Layer> layer_dest_d = layer_dest_c->children()[0]; | 2353 scoped_refptr<Layer> layer_dest_d = layer_dest_c->children()[0]; |
(...skipping 10 matching lines...) Expand all Loading... |
2386 dest_layer_map_2[layer_dest_root->id()] = layer_dest_root; | 2364 dest_layer_map_2[layer_dest_root->id()] = layer_dest_root; |
2387 dest_layer_map_2[layer_dest_a->id()] = layer_dest_a; | 2365 dest_layer_map_2[layer_dest_a->id()] = layer_dest_a; |
2388 dest_layer_map_2[layer_dest_b->id()] = layer_dest_b; | 2366 dest_layer_map_2[layer_dest_b->id()] = layer_dest_b; |
2389 layer_dest_root->FromLayerNodeProto(proto2, dest_layer_map_2); | 2367 layer_dest_root->FromLayerNodeProto(proto2, dest_layer_map_2); |
2390 | 2368 |
2391 EXPECT_EQ(0u, layer_dest_a->children().size()); | 2369 EXPECT_EQ(0u, layer_dest_a->children().size()); |
2392 EXPECT_EQ(0u, layer_dest_b->children().size()); | 2370 EXPECT_EQ(0u, layer_dest_b->children().size()); |
2393 } | 2371 } |
2394 | 2372 |
2395 TEST_F(LayerTest, DeleteMaskAndReplicaLayer) { | 2373 TEST_F(LayerTest, DeleteMaskAndReplicaLayer) { |
2396 scoped_refptr<Layer> layer_src_root = Layer::Create(LayerSettings()); | 2374 scoped_refptr<Layer> layer_src_root = Layer::Create(); |
2397 scoped_refptr<Layer> layer_src_mask = Layer::Create(LayerSettings()); | 2375 scoped_refptr<Layer> layer_src_mask = Layer::Create(); |
2398 scoped_refptr<Layer> layer_src_replica = Layer::Create(LayerSettings()); | 2376 scoped_refptr<Layer> layer_src_replica = Layer::Create(); |
2399 layer_src_root->SetMaskLayer(layer_src_mask.get()); | 2377 layer_src_root->SetMaskLayer(layer_src_mask.get()); |
2400 layer_src_root->SetReplicaLayer(layer_src_replica.get()); | 2378 layer_src_root->SetReplicaLayer(layer_src_replica.get()); |
2401 | 2379 |
2402 // Serialization 1. | 2380 // Serialization 1. |
2403 proto::LayerNode proto1; | 2381 proto::LayerNode proto1; |
2404 layer_src_root->ToLayerNodeProto(&proto1); | 2382 layer_src_root->ToLayerNodeProto(&proto1); |
2405 | 2383 |
2406 // Deserialization 1. | 2384 // Deserialization 1. |
2407 Layer::LayerIdMap dest_layer_map; | 2385 Layer::LayerIdMap dest_layer_map; |
2408 scoped_refptr<Layer> layer_dest_root = Layer::Create(LayerSettings()); | 2386 scoped_refptr<Layer> layer_dest_root = Layer::Create(); |
2409 layer_dest_root->FromLayerNodeProto(proto1, dest_layer_map); | 2387 layer_dest_root->FromLayerNodeProto(proto1, dest_layer_map); |
2410 | 2388 |
2411 EXPECT_EQ(layer_src_root->id(), layer_dest_root->id()); | 2389 EXPECT_EQ(layer_src_root->id(), layer_dest_root->id()); |
2412 ASSERT_TRUE(layer_dest_root->mask_layer()); | 2390 ASSERT_TRUE(layer_dest_root->mask_layer()); |
2413 ASSERT_TRUE(layer_dest_root->replica_layer()); | 2391 ASSERT_TRUE(layer_dest_root->replica_layer()); |
2414 EXPECT_EQ(layer_src_root->mask_layer()->id(), | 2392 EXPECT_EQ(layer_src_root->mask_layer()->id(), |
2415 layer_dest_root->mask_layer()->id()); | 2393 layer_dest_root->mask_layer()->id()); |
2416 // TODO(nyquist): Add test for is_mask_ when PictureLayer is supported. | 2394 // TODO(nyquist): Add test for is_mask_ when PictureLayer is supported. |
2417 EXPECT_EQ(layer_src_root->replica_layer()->id(), | 2395 EXPECT_EQ(layer_src_root->replica_layer()->id(), |
2418 layer_dest_root->replica_layer()->id()); | 2396 layer_dest_root->replica_layer()->id()); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2473 /* Testing serialization of properties for a tree that looks like this: | 2451 /* Testing serialization of properties for a tree that looks like this: |
2474 root+ | 2452 root+ |
2475 / \ | 2453 / \ |
2476 a* b*+[mask:*,replica] | 2454 a* b*+[mask:*,replica] |
2477 / \ | 2455 / \ |
2478 c d* | 2456 c d* |
2479 Layers marked with * have changed properties. | 2457 Layers marked with * have changed properties. |
2480 Layers marked with + have descendants with changed properties. | 2458 Layers marked with + have descendants with changed properties. |
2481 Layer b also has a mask layer and a replica layer. | 2459 Layer b also has a mask layer and a replica layer. |
2482 */ | 2460 */ |
2483 scoped_refptr<Layer> layer_src_root = Layer::Create(LayerSettings()); | 2461 scoped_refptr<Layer> layer_src_root = Layer::Create(); |
2484 scoped_refptr<Layer> layer_src_a = Layer::Create(LayerSettings()); | 2462 scoped_refptr<Layer> layer_src_a = Layer::Create(); |
2485 scoped_refptr<Layer> layer_src_b = Layer::Create(LayerSettings()); | 2463 scoped_refptr<Layer> layer_src_b = Layer::Create(); |
2486 scoped_refptr<Layer> layer_src_b_mask = Layer::Create(LayerSettings()); | 2464 scoped_refptr<Layer> layer_src_b_mask = Layer::Create(); |
2487 scoped_refptr<Layer> layer_src_b_replica = Layer::Create(LayerSettings()); | 2465 scoped_refptr<Layer> layer_src_b_replica = Layer::Create(); |
2488 scoped_refptr<Layer> layer_src_c = Layer::Create(LayerSettings()); | 2466 scoped_refptr<Layer> layer_src_c = Layer::Create(); |
2489 scoped_refptr<Layer> layer_src_d = Layer::Create(LayerSettings()); | 2467 scoped_refptr<Layer> layer_src_d = Layer::Create(); |
2490 layer_src_root->AddChild(layer_src_a); | 2468 layer_src_root->AddChild(layer_src_a); |
2491 layer_src_root->AddChild(layer_src_b); | 2469 layer_src_root->AddChild(layer_src_b); |
2492 layer_src_a->AddChild(layer_src_c); | 2470 layer_src_a->AddChild(layer_src_c); |
2493 layer_src_b->AddChild(layer_src_d); | 2471 layer_src_b->AddChild(layer_src_d); |
2494 layer_src_b->SetMaskLayer(layer_src_b_mask.get()); | 2472 layer_src_b->SetMaskLayer(layer_src_b_mask.get()); |
2495 layer_src_b->SetReplicaLayer(layer_src_b_replica.get()); | 2473 layer_src_b->SetReplicaLayer(layer_src_b_replica.get()); |
2496 | 2474 |
2497 proto::LayerUpdate layer_update_root; | 2475 proto::LayerUpdate layer_update_root; |
2498 // Only layers with descendants that require pushing properties will | 2476 // Only layers with descendants that require pushing properties will |
2499 // return true from ToLayerPropertiesProto and AddChild will change the | 2477 // return true from ToLayerPropertiesProto and AddChild will change the |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2582 EXPECT_TRUE(dest_d.needs_push_properties()); | 2560 EXPECT_TRUE(dest_d.needs_push_properties()); |
2583 EXPECT_EQ(0, dest_d.num_dependents_need_push_properties()); | 2561 EXPECT_EQ(0, dest_d.num_dependents_need_push_properties()); |
2584 EXPECT_TRUE(dest_d.has_base()); | 2562 EXPECT_TRUE(dest_d.has_base()); |
2585 | 2563 |
2586 EXPECT_TRUE(dest_b_mask.needs_push_properties()); | 2564 EXPECT_TRUE(dest_b_mask.needs_push_properties()); |
2587 EXPECT_EQ(0, dest_b_mask.num_dependents_need_push_properties()); | 2565 EXPECT_EQ(0, dest_b_mask.num_dependents_need_push_properties()); |
2588 EXPECT_TRUE(dest_b_mask.has_base()); | 2566 EXPECT_TRUE(dest_b_mask.has_base()); |
2589 } | 2567 } |
2590 | 2568 |
2591 TEST_F(LayerSerializationTest, SimplePropertiesDeserialization) { | 2569 TEST_F(LayerSerializationTest, SimplePropertiesDeserialization) { |
2592 scoped_refptr<Layer> layer = Layer::Create(LayerSettings()); | 2570 scoped_refptr<Layer> layer = Layer::Create(); |
2593 layer->SetLayerTreeHost(layer_tree_host_.get()); | 2571 layer->SetLayerTreeHost(layer_tree_host_.get()); |
2594 proto::LayerProperties properties; | 2572 proto::LayerProperties properties; |
2595 properties.set_id(layer->id()); | 2573 properties.set_id(layer->id()); |
2596 | 2574 |
2597 properties.set_needs_push_properties(true); | 2575 properties.set_needs_push_properties(true); |
2598 properties.set_num_dependents_need_push_properties(2); | 2576 properties.set_num_dependents_need_push_properties(2); |
2599 properties.mutable_base(); | 2577 properties.mutable_base(); |
2600 layer->FromLayerPropertiesProto(properties); | 2578 layer->FromLayerPropertiesProto(properties); |
2601 EXPECT_TRUE(layer->needs_push_properties()); | 2579 EXPECT_TRUE(layer->needs_push_properties()); |
2602 EXPECT_TRUE(layer->descendant_needs_push_properties()); | 2580 EXPECT_TRUE(layer->descendant_needs_push_properties()); |
(...skipping 28 matching lines...) Expand all Loading... |
2631 | 2609 |
2632 TEST_F(LayerSerializationTest, AllMembersChanged) { | 2610 TEST_F(LayerSerializationTest, AllMembersChanged) { |
2633 RunAllMembersChangedTest(); | 2611 RunAllMembersChangedTest(); |
2634 } | 2612 } |
2635 | 2613 |
2636 TEST_F(LayerSerializationTest, ScrollAndClipLayers) { | 2614 TEST_F(LayerSerializationTest, ScrollAndClipLayers) { |
2637 RunScrollAndClipLayersTest(); | 2615 RunScrollAndClipLayersTest(); |
2638 } | 2616 } |
2639 | 2617 |
2640 TEST_F(LayerTest, ElementIdAndMutablePropertiesArePushed) { | 2618 TEST_F(LayerTest, ElementIdAndMutablePropertiesArePushed) { |
2641 scoped_refptr<Layer> test_layer = Layer::Create(layer_settings_); | 2619 scoped_refptr<Layer> test_layer = Layer::Create(); |
2642 scoped_ptr<LayerImpl> impl_layer = | 2620 scoped_ptr<LayerImpl> impl_layer = |
2643 LayerImpl::Create(host_impl_.active_tree(), 1); | 2621 LayerImpl::Create(host_impl_.active_tree(), 1); |
2644 | 2622 |
2645 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, | 2623 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, |
2646 layer_tree_host_->SetRootLayer(test_layer)); | 2624 layer_tree_host_->SetRootLayer(test_layer)); |
2647 | 2625 |
2648 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(2); | 2626 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(2); |
2649 | 2627 |
2650 test_layer->SetElementId(2); | 2628 test_layer->SetElementId(2); |
2651 test_layer->SetMutableProperties(MutableProperty::kTransform); | 2629 test_layer->SetMutableProperties(MutableProperty::kTransform); |
2652 | 2630 |
2653 EXPECT_EQ(0lu, impl_layer->element_id()); | 2631 EXPECT_EQ(0lu, impl_layer->element_id()); |
2654 EXPECT_EQ(MutableProperty::kNone, impl_layer->mutable_properties()); | 2632 EXPECT_EQ(MutableProperty::kNone, impl_layer->mutable_properties()); |
2655 | 2633 |
2656 test_layer->PushPropertiesTo(impl_layer.get()); | 2634 test_layer->PushPropertiesTo(impl_layer.get()); |
2657 | 2635 |
2658 EXPECT_EQ(2lu, impl_layer->element_id()); | 2636 EXPECT_EQ(2lu, impl_layer->element_id()); |
2659 EXPECT_EQ(MutableProperty::kTransform, impl_layer->mutable_properties()); | 2637 EXPECT_EQ(MutableProperty::kTransform, impl_layer->mutable_properties()); |
2660 } | 2638 } |
2661 | 2639 |
2662 } // namespace | 2640 } // namespace |
2663 } // namespace cc | 2641 } // namespace cc |
OLD | NEW |