| 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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 { | 819 class LayerTreeSettingsForLayerTest : public LayerTreeSettings { |
| 821 public: | 820 public: |
| 822 LayerTreeSettingsForLayerTest() { use_compositor_animation_timelines = true; } | 821 LayerTreeSettingsForLayerTest() {} |
| 823 }; | 822 }; |
| 824 | 823 |
| 825 class LayerTest : public testing::Test { | 824 class LayerTest : public testing::Test { |
| 826 public: | 825 public: |
| 827 LayerTest() | 826 LayerTest() |
| 828 : host_impl_(LayerTreeSettingsForLayerTest(), | 827 : host_impl_(LayerTreeSettingsForLayerTest(), |
| 829 &task_runner_provider_, | 828 &task_runner_provider_, |
| 830 &shared_bitmap_manager_, | 829 &shared_bitmap_manager_, |
| 831 &task_graph_runner_), | 830 &task_graph_runner_), |
| 832 fake_client_(FakeLayerTreeHostClient::DIRECT_3D) { | 831 fake_client_(FakeLayerTreeHostClient::DIRECT_3D) { |
| 833 layer_settings_.use_compositor_animation_timelines = | 832 timeline_impl_ = |
| 834 settings().use_compositor_animation_timelines; | 833 AnimationTimeline::Create(AnimationIdProvider::NextTimelineId()); |
| 835 if (settings().use_compositor_animation_timelines) { | 834 timeline_impl_->set_is_impl_only(true); |
| 836 timeline_impl_ = | 835 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 } | 836 } |
| 842 | 837 |
| 843 const LayerTreeSettings& settings() { return settings_; } | 838 const LayerTreeSettings& settings() { return settings_; } |
| 844 scoped_refptr<AnimationTimeline> timeline_impl() { return timeline_impl_; } | 839 scoped_refptr<AnimationTimeline> timeline_impl() { return timeline_impl_; } |
| 845 | 840 |
| 846 protected: | 841 protected: |
| 847 void SetUp() override { | 842 void SetUp() override { |
| 848 LayerTreeHost::InitParams params; | 843 LayerTreeHost::InitParams params; |
| 849 params.client = &fake_client_; | 844 params.client = &fake_client_; |
| 850 params.settings = &settings_; | 845 params.settings = &settings_; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 884 EXPECT_EQ(child1_.get(), grand_child2_->parent()); | 879 EXPECT_EQ(child1_.get(), grand_child2_->parent()); |
| 885 | 880 |
| 886 ASSERT_EQ(1U, child2_->children().size()); | 881 ASSERT_EQ(1U, child2_->children().size()); |
| 887 EXPECT_EQ(grand_child3_, child2_->children()[0]); | 882 EXPECT_EQ(grand_child3_, child2_->children()[0]); |
| 888 EXPECT_EQ(child2_.get(), grand_child3_->parent()); | 883 EXPECT_EQ(child2_.get(), grand_child3_->parent()); |
| 889 | 884 |
| 890 ASSERT_EQ(0U, child3_->children().size()); | 885 ASSERT_EQ(0U, child3_->children().size()); |
| 891 } | 886 } |
| 892 | 887 |
| 893 void CreateSimpleTestTree() { | 888 void CreateSimpleTestTree() { |
| 894 parent_ = Layer::Create(layer_settings_); | 889 parent_ = Layer::Create(); |
| 895 child1_ = Layer::Create(layer_settings_); | 890 child1_ = Layer::Create(); |
| 896 child2_ = Layer::Create(layer_settings_); | 891 child2_ = Layer::Create(); |
| 897 child3_ = Layer::Create(layer_settings_); | 892 child3_ = Layer::Create(); |
| 898 grand_child1_ = Layer::Create(layer_settings_); | 893 grand_child1_ = Layer::Create(); |
| 899 grand_child2_ = Layer::Create(layer_settings_); | 894 grand_child2_ = Layer::Create(); |
| 900 grand_child3_ = Layer::Create(layer_settings_); | 895 grand_child3_ = Layer::Create(); |
| 901 | 896 |
| 902 EXPECT_CALL(*layer_tree_host_, SetNeedsFullTreeSync()).Times(AnyNumber()); | 897 EXPECT_CALL(*layer_tree_host_, SetNeedsFullTreeSync()).Times(AnyNumber()); |
| 903 layer_tree_host_->SetRootLayer(parent_); | 898 layer_tree_host_->SetRootLayer(parent_); |
| 904 | 899 |
| 905 parent_->AddChild(child1_); | 900 parent_->AddChild(child1_); |
| 906 parent_->AddChild(child2_); | 901 parent_->AddChild(child2_); |
| 907 parent_->AddChild(child3_); | 902 parent_->AddChild(child3_); |
| 908 child1_->AddChild(grand_child1_); | 903 child1_->AddChild(grand_child1_); |
| 909 child1_->AddChild(grand_child2_); | 904 child1_->AddChild(grand_child2_); |
| 910 child2_->AddChild(grand_child3_); | 905 child2_->AddChild(grand_child3_); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 925 scoped_refptr<Layer> child1_; | 920 scoped_refptr<Layer> child1_; |
| 926 scoped_refptr<Layer> child2_; | 921 scoped_refptr<Layer> child2_; |
| 927 scoped_refptr<Layer> child3_; | 922 scoped_refptr<Layer> child3_; |
| 928 scoped_refptr<Layer> grand_child1_; | 923 scoped_refptr<Layer> grand_child1_; |
| 929 scoped_refptr<Layer> grand_child2_; | 924 scoped_refptr<Layer> grand_child2_; |
| 930 scoped_refptr<Layer> grand_child3_; | 925 scoped_refptr<Layer> grand_child3_; |
| 931 | 926 |
| 932 scoped_refptr<AnimationTimeline> timeline_impl_; | 927 scoped_refptr<AnimationTimeline> timeline_impl_; |
| 933 | 928 |
| 934 LayerTreeSettingsForLayerTest settings_; | 929 LayerTreeSettingsForLayerTest settings_; |
| 935 LayerSettings layer_settings_; | |
| 936 }; | 930 }; |
| 937 | 931 |
| 938 TEST_F(LayerTest, BasicCreateAndDestroy) { | 932 TEST_F(LayerTest, BasicCreateAndDestroy) { |
| 939 scoped_refptr<Layer> test_layer = Layer::Create(layer_settings_); | 933 scoped_refptr<Layer> test_layer = Layer::Create(); |
| 940 ASSERT_TRUE(test_layer.get()); | 934 ASSERT_TRUE(test_layer.get()); |
| 941 | 935 |
| 942 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(0); | 936 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(0); |
| 943 test_layer->SetLayerTreeHost(layer_tree_host_.get()); | 937 test_layer->SetLayerTreeHost(layer_tree_host_.get()); |
| 944 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); | 938 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); |
| 945 | 939 |
| 946 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(0); | 940 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(0); |
| 947 test_layer->SetLayerTreeHost(nullptr); | 941 test_layer->SetLayerTreeHost(nullptr); |
| 948 } | 942 } |
| 949 | 943 |
| 950 TEST_F(LayerTest, LayerPropertyChangedForSubtree) { | 944 TEST_F(LayerTest, LayerPropertyChangedForSubtree) { |
| 951 EXPECT_CALL(*layer_tree_host_, SetNeedsFullTreeSync()).Times(AtLeast(1)); | 945 EXPECT_CALL(*layer_tree_host_, SetNeedsFullTreeSync()).Times(AtLeast(1)); |
| 952 scoped_refptr<Layer> root = Layer::Create(layer_settings_); | 946 scoped_refptr<Layer> root = Layer::Create(); |
| 953 scoped_refptr<Layer> child = Layer::Create(layer_settings_); | 947 scoped_refptr<Layer> child = Layer::Create(); |
| 954 scoped_refptr<Layer> child2 = Layer::Create(layer_settings_); | 948 scoped_refptr<Layer> child2 = Layer::Create(); |
| 955 scoped_refptr<Layer> grand_child = Layer::Create(layer_settings_); | 949 scoped_refptr<Layer> grand_child = Layer::Create(); |
| 956 scoped_refptr<Layer> dummy_layer1 = Layer::Create(layer_settings_); | 950 scoped_refptr<Layer> dummy_layer1 = Layer::Create(); |
| 957 scoped_refptr<Layer> dummy_layer2 = Layer::Create(layer_settings_); | 951 scoped_refptr<Layer> dummy_layer2 = Layer::Create(); |
| 958 | 952 |
| 959 layer_tree_host_->SetRootLayer(root); | 953 layer_tree_host_->SetRootLayer(root); |
| 960 root->AddChild(child); | 954 root->AddChild(child); |
| 961 root->AddChild(child2); | 955 root->AddChild(child2); |
| 962 child->AddChild(grand_child); | 956 child->AddChild(grand_child); |
| 963 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1)); | 957 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1)); |
| 964 child->SetForceRenderSurface(true); | 958 child->SetForceRenderSurface(true); |
| 965 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1)); | 959 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1)); |
| 966 child2->SetScrollParent(grand_child.get()); | 960 child2->SetScrollParent(grand_child.get()); |
| 967 SkXfermode::Mode arbitrary_blend_mode = SkXfermode::kMultiply_Mode; | 961 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; | 1121 gfx::Transform arbitrary_transform; |
| 1128 arbitrary_transform.Scale3d(0.1f, 0.2f, 0.3f); | 1122 arbitrary_transform.Scale3d(0.1f, 0.2f, 0.3f); |
| 1129 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(1); | 1123 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(1); |
| 1130 root->SetTransform(arbitrary_transform); | 1124 root->SetTransform(arbitrary_transform); |
| 1131 node = layer_tree_host_->property_trees()->transform_tree.Node( | 1125 node = layer_tree_host_->property_trees()->transform_tree.Node( |
| 1132 root->transform_tree_index()); | 1126 root->transform_tree_index()); |
| 1133 EXPECT_TRUE(node->data.transform_changed); | 1127 EXPECT_TRUE(node->data.transform_changed); |
| 1134 } | 1128 } |
| 1135 | 1129 |
| 1136 TEST_F(LayerTest, AddAndRemoveChild) { | 1130 TEST_F(LayerTest, AddAndRemoveChild) { |
| 1137 scoped_refptr<Layer> parent = Layer::Create(layer_settings_); | 1131 scoped_refptr<Layer> parent = Layer::Create(); |
| 1138 scoped_refptr<Layer> child = Layer::Create(layer_settings_); | 1132 scoped_refptr<Layer> child = Layer::Create(); |
| 1139 | 1133 |
| 1140 // Upon creation, layers should not have children or parent. | 1134 // Upon creation, layers should not have children or parent. |
| 1141 ASSERT_EQ(0U, parent->children().size()); | 1135 ASSERT_EQ(0U, parent->children().size()); |
| 1142 EXPECT_FALSE(child->parent()); | 1136 EXPECT_FALSE(child->parent()); |
| 1143 | 1137 |
| 1144 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, layer_tree_host_->SetRootLayer(parent)); | 1138 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, layer_tree_host_->SetRootLayer(parent)); |
| 1145 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, parent->AddChild(child)); | 1139 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, parent->AddChild(child)); |
| 1146 | 1140 |
| 1147 ASSERT_EQ(1U, parent->children().size()); | 1141 ASSERT_EQ(1U, parent->children().size()); |
| 1148 EXPECT_EQ(child.get(), parent->children()[0].get()); | 1142 EXPECT_EQ(child.get(), parent->children()[0].get()); |
| 1149 EXPECT_EQ(parent.get(), child->parent()); | 1143 EXPECT_EQ(parent.get(), child->parent()); |
| 1150 EXPECT_EQ(parent.get(), child->RootLayer()); | 1144 EXPECT_EQ(parent.get(), child->RootLayer()); |
| 1151 | 1145 |
| 1152 EXPECT_SET_NEEDS_FULL_TREE_SYNC(AtLeast(1), child->RemoveFromParent()); | 1146 EXPECT_SET_NEEDS_FULL_TREE_SYNC(AtLeast(1), child->RemoveFromParent()); |
| 1153 } | 1147 } |
| 1154 | 1148 |
| 1155 TEST_F(LayerTest, AddSameChildTwice) { | 1149 TEST_F(LayerTest, AddSameChildTwice) { |
| 1156 EXPECT_CALL(*layer_tree_host_, SetNeedsFullTreeSync()).Times(AtLeast(1)); | 1150 EXPECT_CALL(*layer_tree_host_, SetNeedsFullTreeSync()).Times(AtLeast(1)); |
| 1157 | 1151 |
| 1158 scoped_refptr<Layer> parent = Layer::Create(layer_settings_); | 1152 scoped_refptr<Layer> parent = Layer::Create(); |
| 1159 scoped_refptr<Layer> child = Layer::Create(layer_settings_); | 1153 scoped_refptr<Layer> child = Layer::Create(); |
| 1160 | 1154 |
| 1161 layer_tree_host_->SetRootLayer(parent); | 1155 layer_tree_host_->SetRootLayer(parent); |
| 1162 | 1156 |
| 1163 ASSERT_EQ(0u, parent->children().size()); | 1157 ASSERT_EQ(0u, parent->children().size()); |
| 1164 | 1158 |
| 1165 parent->AddChild(child); | 1159 parent->AddChild(child); |
| 1166 ASSERT_EQ(1u, parent->children().size()); | 1160 ASSERT_EQ(1u, parent->children().size()); |
| 1167 EXPECT_EQ(parent.get(), child->parent()); | 1161 EXPECT_EQ(parent.get(), child->parent()); |
| 1168 | 1162 |
| 1169 parent->AddChild(child); | 1163 parent->AddChild(child); |
| 1170 ASSERT_EQ(1u, parent->children().size()); | 1164 ASSERT_EQ(1u, parent->children().size()); |
| 1171 EXPECT_EQ(parent.get(), child->parent()); | 1165 EXPECT_EQ(parent.get(), child->parent()); |
| 1172 } | 1166 } |
| 1173 | 1167 |
| 1174 TEST_F(LayerTest, InsertChild) { | 1168 TEST_F(LayerTest, InsertChild) { |
| 1175 scoped_refptr<Layer> parent = Layer::Create(layer_settings_); | 1169 scoped_refptr<Layer> parent = Layer::Create(); |
| 1176 scoped_refptr<Layer> child1 = Layer::Create(layer_settings_); | 1170 scoped_refptr<Layer> child1 = Layer::Create(); |
| 1177 scoped_refptr<Layer> child2 = Layer::Create(layer_settings_); | 1171 scoped_refptr<Layer> child2 = Layer::Create(); |
| 1178 scoped_refptr<Layer> child3 = Layer::Create(layer_settings_); | 1172 scoped_refptr<Layer> child3 = Layer::Create(); |
| 1179 scoped_refptr<Layer> child4 = Layer::Create(layer_settings_); | 1173 scoped_refptr<Layer> child4 = Layer::Create(); |
| 1180 | 1174 |
| 1181 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, layer_tree_host_->SetRootLayer(parent)); | 1175 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, layer_tree_host_->SetRootLayer(parent)); |
| 1182 | 1176 |
| 1183 ASSERT_EQ(0U, parent->children().size()); | 1177 ASSERT_EQ(0U, parent->children().size()); |
| 1184 | 1178 |
| 1185 // Case 1: inserting to empty list. | 1179 // Case 1: inserting to empty list. |
| 1186 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, parent->InsertChild(child3, 0)); | 1180 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, parent->InsertChild(child3, 0)); |
| 1187 ASSERT_EQ(1U, parent->children().size()); | 1181 ASSERT_EQ(1U, parent->children().size()); |
| 1188 EXPECT_EQ(child3, parent->children()[0]); | 1182 EXPECT_EQ(child3, parent->children()[0]); |
| 1189 EXPECT_EQ(parent.get(), child3->parent()); | 1183 EXPECT_EQ(parent.get(), child3->parent()); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 1210 EXPECT_EQ(child1, parent->children()[0]); | 1204 EXPECT_EQ(child1, parent->children()[0]); |
| 1211 EXPECT_EQ(child2, parent->children()[1]); | 1205 EXPECT_EQ(child2, parent->children()[1]); |
| 1212 EXPECT_EQ(child3, parent->children()[2]); | 1206 EXPECT_EQ(child3, parent->children()[2]); |
| 1213 EXPECT_EQ(child4, parent->children()[3]); | 1207 EXPECT_EQ(child4, parent->children()[3]); |
| 1214 EXPECT_EQ(parent.get(), child4->parent()); | 1208 EXPECT_EQ(parent.get(), child4->parent()); |
| 1215 | 1209 |
| 1216 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, layer_tree_host_->SetRootLayer(nullptr)); | 1210 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, layer_tree_host_->SetRootLayer(nullptr)); |
| 1217 } | 1211 } |
| 1218 | 1212 |
| 1219 TEST_F(LayerTest, InsertChildPastEndOfList) { | 1213 TEST_F(LayerTest, InsertChildPastEndOfList) { |
| 1220 scoped_refptr<Layer> parent = Layer::Create(layer_settings_); | 1214 scoped_refptr<Layer> parent = Layer::Create(); |
| 1221 scoped_refptr<Layer> child1 = Layer::Create(layer_settings_); | 1215 scoped_refptr<Layer> child1 = Layer::Create(); |
| 1222 scoped_refptr<Layer> child2 = Layer::Create(layer_settings_); | 1216 scoped_refptr<Layer> child2 = Layer::Create(); |
| 1223 | 1217 |
| 1224 ASSERT_EQ(0U, parent->children().size()); | 1218 ASSERT_EQ(0U, parent->children().size()); |
| 1225 | 1219 |
| 1226 // insert to an out-of-bounds index | 1220 // insert to an out-of-bounds index |
| 1227 parent->InsertChild(child1, 53); | 1221 parent->InsertChild(child1, 53); |
| 1228 | 1222 |
| 1229 ASSERT_EQ(1U, parent->children().size()); | 1223 ASSERT_EQ(1U, parent->children().size()); |
| 1230 EXPECT_EQ(child1, parent->children()[0]); | 1224 EXPECT_EQ(child1, parent->children()[0]); |
| 1231 | 1225 |
| 1232 // insert another child to out-of-bounds, when list is not already empty. | 1226 // insert another child to out-of-bounds, when list is not already empty. |
| 1233 parent->InsertChild(child2, 2459); | 1227 parent->InsertChild(child2, 2459); |
| 1234 | 1228 |
| 1235 ASSERT_EQ(2U, parent->children().size()); | 1229 ASSERT_EQ(2U, parent->children().size()); |
| 1236 EXPECT_EQ(child1, parent->children()[0]); | 1230 EXPECT_EQ(child1, parent->children()[0]); |
| 1237 EXPECT_EQ(child2, parent->children()[1]); | 1231 EXPECT_EQ(child2, parent->children()[1]); |
| 1238 } | 1232 } |
| 1239 | 1233 |
| 1240 TEST_F(LayerTest, InsertSameChildTwice) { | 1234 TEST_F(LayerTest, InsertSameChildTwice) { |
| 1241 scoped_refptr<Layer> parent = Layer::Create(layer_settings_); | 1235 scoped_refptr<Layer> parent = Layer::Create(); |
| 1242 scoped_refptr<Layer> child1 = Layer::Create(layer_settings_); | 1236 scoped_refptr<Layer> child1 = Layer::Create(); |
| 1243 scoped_refptr<Layer> child2 = Layer::Create(layer_settings_); | 1237 scoped_refptr<Layer> child2 = Layer::Create(); |
| 1244 | 1238 |
| 1245 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, layer_tree_host_->SetRootLayer(parent)); | 1239 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, layer_tree_host_->SetRootLayer(parent)); |
| 1246 | 1240 |
| 1247 ASSERT_EQ(0U, parent->children().size()); | 1241 ASSERT_EQ(0U, parent->children().size()); |
| 1248 | 1242 |
| 1249 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, parent->InsertChild(child1, 0)); | 1243 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, parent->InsertChild(child1, 0)); |
| 1250 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, parent->InsertChild(child2, 1)); | 1244 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, parent->InsertChild(child2, 1)); |
| 1251 | 1245 |
| 1252 ASSERT_EQ(2U, parent->children().size()); | 1246 ASSERT_EQ(2U, parent->children().size()); |
| 1253 EXPECT_EQ(child1, parent->children()[0]); | 1247 EXPECT_EQ(child1, parent->children()[0]); |
| 1254 EXPECT_EQ(child2, parent->children()[1]); | 1248 EXPECT_EQ(child2, parent->children()[1]); |
| 1255 | 1249 |
| 1256 // Inserting the same child again should cause the child to be removed and | 1250 // Inserting the same child again should cause the child to be removed and |
| 1257 // re-inserted at the new location. | 1251 // re-inserted at the new location. |
| 1258 EXPECT_SET_NEEDS_FULL_TREE_SYNC(AtLeast(1), parent->InsertChild(child1, 1)); | 1252 EXPECT_SET_NEEDS_FULL_TREE_SYNC(AtLeast(1), parent->InsertChild(child1, 1)); |
| 1259 | 1253 |
| 1260 // child1 should now be at the end of the list. | 1254 // child1 should now be at the end of the list. |
| 1261 ASSERT_EQ(2U, parent->children().size()); | 1255 ASSERT_EQ(2U, parent->children().size()); |
| 1262 EXPECT_EQ(child2, parent->children()[0]); | 1256 EXPECT_EQ(child2, parent->children()[0]); |
| 1263 EXPECT_EQ(child1, parent->children()[1]); | 1257 EXPECT_EQ(child1, parent->children()[1]); |
| 1264 | 1258 |
| 1265 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, layer_tree_host_->SetRootLayer(nullptr)); | 1259 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, layer_tree_host_->SetRootLayer(nullptr)); |
| 1266 } | 1260 } |
| 1267 | 1261 |
| 1268 TEST_F(LayerTest, ReplaceChildWithNewChild) { | 1262 TEST_F(LayerTest, ReplaceChildWithNewChild) { |
| 1269 CreateSimpleTestTree(); | 1263 CreateSimpleTestTree(); |
| 1270 scoped_refptr<Layer> child4 = Layer::Create(layer_settings_); | 1264 scoped_refptr<Layer> child4 = Layer::Create(); |
| 1271 | 1265 |
| 1272 EXPECT_FALSE(child4->parent()); | 1266 EXPECT_FALSE(child4->parent()); |
| 1273 | 1267 |
| 1274 EXPECT_SET_NEEDS_FULL_TREE_SYNC( | 1268 EXPECT_SET_NEEDS_FULL_TREE_SYNC( |
| 1275 AtLeast(1), parent_->ReplaceChild(child2_.get(), child4)); | 1269 AtLeast(1), parent_->ReplaceChild(child2_.get(), child4)); |
| 1276 EXPECT_FALSE(parent_->NeedsDisplayForTesting()); | 1270 EXPECT_FALSE(parent_->NeedsDisplayForTesting()); |
| 1277 EXPECT_FALSE(child1_->NeedsDisplayForTesting()); | 1271 EXPECT_FALSE(child1_->NeedsDisplayForTesting()); |
| 1278 EXPECT_FALSE(child2_->NeedsDisplayForTesting()); | 1272 EXPECT_FALSE(child2_->NeedsDisplayForTesting()); |
| 1279 EXPECT_FALSE(child3_->NeedsDisplayForTesting()); | 1273 EXPECT_FALSE(child3_->NeedsDisplayForTesting()); |
| 1280 EXPECT_FALSE(child4->NeedsDisplayForTesting()); | 1274 EXPECT_FALSE(child4->NeedsDisplayForTesting()); |
| 1281 | 1275 |
| 1282 ASSERT_EQ(static_cast<size_t>(3), parent_->children().size()); | 1276 ASSERT_EQ(static_cast<size_t>(3), parent_->children().size()); |
| 1283 EXPECT_EQ(child1_, parent_->children()[0]); | 1277 EXPECT_EQ(child1_, parent_->children()[0]); |
| 1284 EXPECT_EQ(child4, parent_->children()[1]); | 1278 EXPECT_EQ(child4, parent_->children()[1]); |
| 1285 EXPECT_EQ(child3_, parent_->children()[2]); | 1279 EXPECT_EQ(child3_, parent_->children()[2]); |
| 1286 EXPECT_EQ(parent_.get(), child4->parent()); | 1280 EXPECT_EQ(parent_.get(), child4->parent()); |
| 1287 | 1281 |
| 1288 EXPECT_FALSE(child2_->parent()); | 1282 EXPECT_FALSE(child2_->parent()); |
| 1289 } | 1283 } |
| 1290 | 1284 |
| 1291 TEST_F(LayerTest, ReplaceChildWithNewChildThatHasOtherParent) { | 1285 TEST_F(LayerTest, ReplaceChildWithNewChildThatHasOtherParent) { |
| 1292 CreateSimpleTestTree(); | 1286 CreateSimpleTestTree(); |
| 1293 | 1287 |
| 1294 // create another simple tree with test_layer and child4. | 1288 // create another simple tree with test_layer and child4. |
| 1295 scoped_refptr<Layer> test_layer = Layer::Create(layer_settings_); | 1289 scoped_refptr<Layer> test_layer = Layer::Create(); |
| 1296 scoped_refptr<Layer> child4 = Layer::Create(layer_settings_); | 1290 scoped_refptr<Layer> child4 = Layer::Create(); |
| 1297 test_layer->AddChild(child4); | 1291 test_layer->AddChild(child4); |
| 1298 ASSERT_EQ(1U, test_layer->children().size()); | 1292 ASSERT_EQ(1U, test_layer->children().size()); |
| 1299 EXPECT_EQ(child4, test_layer->children()[0]); | 1293 EXPECT_EQ(child4, test_layer->children()[0]); |
| 1300 EXPECT_EQ(test_layer.get(), child4->parent()); | 1294 EXPECT_EQ(test_layer.get(), child4->parent()); |
| 1301 | 1295 |
| 1302 EXPECT_SET_NEEDS_FULL_TREE_SYNC( | 1296 EXPECT_SET_NEEDS_FULL_TREE_SYNC( |
| 1303 AtLeast(1), parent_->ReplaceChild(child2_.get(), child4)); | 1297 AtLeast(1), parent_->ReplaceChild(child2_.get(), child4)); |
| 1304 | 1298 |
| 1305 ASSERT_EQ(3U, parent_->children().size()); | 1299 ASSERT_EQ(3U, parent_->children().size()); |
| 1306 EXPECT_EQ(child1_, parent_->children()[0]); | 1300 EXPECT_EQ(child1_, parent_->children()[0]); |
| 1307 EXPECT_EQ(child4, parent_->children()[1]); | 1301 EXPECT_EQ(child4, parent_->children()[1]); |
| 1308 EXPECT_EQ(child3_, parent_->children()[2]); | 1302 EXPECT_EQ(child3_, parent_->children()[2]); |
| 1309 EXPECT_EQ(parent_.get(), child4->parent()); | 1303 EXPECT_EQ(parent_.get(), child4->parent()); |
| 1310 | 1304 |
| 1311 // test_layer should no longer have child4, | 1305 // test_layer should no longer have child4, |
| 1312 // and child2 should no longer have a parent. | 1306 // and child2 should no longer have a parent. |
| 1313 ASSERT_EQ(0U, test_layer->children().size()); | 1307 ASSERT_EQ(0U, test_layer->children().size()); |
| 1314 EXPECT_FALSE(child2_->parent()); | 1308 EXPECT_FALSE(child2_->parent()); |
| 1315 } | 1309 } |
| 1316 | 1310 |
| 1317 TEST_F(LayerTest, DeleteRemovedScrollParent) { | 1311 TEST_F(LayerTest, DeleteRemovedScrollParent) { |
| 1318 scoped_refptr<Layer> parent = Layer::Create(layer_settings_); | 1312 scoped_refptr<Layer> parent = Layer::Create(); |
| 1319 scoped_refptr<Layer> child1 = Layer::Create(layer_settings_); | 1313 scoped_refptr<Layer> child1 = Layer::Create(); |
| 1320 scoped_refptr<Layer> child2 = Layer::Create(layer_settings_); | 1314 scoped_refptr<Layer> child2 = Layer::Create(); |
| 1321 | 1315 |
| 1322 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, layer_tree_host_->SetRootLayer(parent)); | 1316 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, layer_tree_host_->SetRootLayer(parent)); |
| 1323 | 1317 |
| 1324 ASSERT_EQ(0U, parent->children().size()); | 1318 ASSERT_EQ(0U, parent->children().size()); |
| 1325 | 1319 |
| 1326 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, parent->InsertChild(child1, 0)); | 1320 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, parent->InsertChild(child1, 0)); |
| 1327 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, parent->InsertChild(child2, 1)); | 1321 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, parent->InsertChild(child2, 1)); |
| 1328 | 1322 |
| 1329 ASSERT_EQ(2U, parent->children().size()); | 1323 ASSERT_EQ(2U, parent->children().size()); |
| 1330 EXPECT_EQ(child1, parent->children()[0]); | 1324 EXPECT_EQ(child1, parent->children()[0]); |
| 1331 EXPECT_EQ(child2, parent->children()[1]); | 1325 EXPECT_EQ(child2, parent->children()[1]); |
| 1332 | 1326 |
| 1333 EXPECT_SET_NEEDS_COMMIT(2, child1->SetScrollParent(child2.get())); | 1327 EXPECT_SET_NEEDS_COMMIT(2, child1->SetScrollParent(child2.get())); |
| 1334 | 1328 |
| 1335 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, child2->RemoveFromParent()); | 1329 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, child2->RemoveFromParent()); |
| 1336 | 1330 |
| 1337 child1->reset_needs_push_properties_for_testing(); | 1331 child1->reset_needs_push_properties_for_testing(); |
| 1338 | 1332 |
| 1339 EXPECT_SET_NEEDS_COMMIT(1, child2 = nullptr); | 1333 EXPECT_SET_NEEDS_COMMIT(1, child2 = nullptr); |
| 1340 | 1334 |
| 1341 EXPECT_TRUE(child1->needs_push_properties()); | 1335 EXPECT_TRUE(child1->needs_push_properties()); |
| 1342 | 1336 |
| 1343 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, layer_tree_host_->SetRootLayer(nullptr)); | 1337 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, layer_tree_host_->SetRootLayer(nullptr)); |
| 1344 } | 1338 } |
| 1345 | 1339 |
| 1346 TEST_F(LayerTest, DeleteRemovedScrollChild) { | 1340 TEST_F(LayerTest, DeleteRemovedScrollChild) { |
| 1347 scoped_refptr<Layer> parent = Layer::Create(layer_settings_); | 1341 scoped_refptr<Layer> parent = Layer::Create(); |
| 1348 scoped_refptr<Layer> child1 = Layer::Create(layer_settings_); | 1342 scoped_refptr<Layer> child1 = Layer::Create(); |
| 1349 scoped_refptr<Layer> child2 = Layer::Create(layer_settings_); | 1343 scoped_refptr<Layer> child2 = Layer::Create(); |
| 1350 | 1344 |
| 1351 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, layer_tree_host_->SetRootLayer(parent)); | 1345 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, layer_tree_host_->SetRootLayer(parent)); |
| 1352 | 1346 |
| 1353 ASSERT_EQ(0U, parent->children().size()); | 1347 ASSERT_EQ(0U, parent->children().size()); |
| 1354 | 1348 |
| 1355 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, parent->InsertChild(child1, 0)); | 1349 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, parent->InsertChild(child1, 0)); |
| 1356 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, parent->InsertChild(child2, 1)); | 1350 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, parent->InsertChild(child2, 1)); |
| 1357 | 1351 |
| 1358 ASSERT_EQ(2U, parent->children().size()); | 1352 ASSERT_EQ(2U, parent->children().size()); |
| 1359 EXPECT_EQ(child1, parent->children()[0]); | 1353 EXPECT_EQ(child1, parent->children()[0]); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 1389 | 1383 |
| 1390 EXPECT_SET_NEEDS_FULL_TREE_SYNC(AtLeast(3), parent_->RemoveAllChildren()); | 1384 EXPECT_SET_NEEDS_FULL_TREE_SYNC(AtLeast(3), parent_->RemoveAllChildren()); |
| 1391 | 1385 |
| 1392 ASSERT_EQ(0U, parent_->children().size()); | 1386 ASSERT_EQ(0U, parent_->children().size()); |
| 1393 EXPECT_FALSE(child1_->parent()); | 1387 EXPECT_FALSE(child1_->parent()); |
| 1394 EXPECT_FALSE(child2_->parent()); | 1388 EXPECT_FALSE(child2_->parent()); |
| 1395 EXPECT_FALSE(child3_->parent()); | 1389 EXPECT_FALSE(child3_->parent()); |
| 1396 } | 1390 } |
| 1397 | 1391 |
| 1398 TEST_F(LayerTest, SetChildren) { | 1392 TEST_F(LayerTest, SetChildren) { |
| 1399 scoped_refptr<Layer> old_parent = Layer::Create(layer_settings_); | 1393 scoped_refptr<Layer> old_parent = Layer::Create(); |
| 1400 scoped_refptr<Layer> new_parent = Layer::Create(layer_settings_); | 1394 scoped_refptr<Layer> new_parent = Layer::Create(); |
| 1401 | 1395 |
| 1402 scoped_refptr<Layer> child1 = Layer::Create(layer_settings_); | 1396 scoped_refptr<Layer> child1 = Layer::Create(); |
| 1403 scoped_refptr<Layer> child2 = Layer::Create(layer_settings_); | 1397 scoped_refptr<Layer> child2 = Layer::Create(); |
| 1404 | 1398 |
| 1405 LayerList new_children; | 1399 LayerList new_children; |
| 1406 new_children.push_back(child1); | 1400 new_children.push_back(child1); |
| 1407 new_children.push_back(child2); | 1401 new_children.push_back(child2); |
| 1408 | 1402 |
| 1409 // Set up and verify initial test conditions: child1 has a parent, child2 has | 1403 // Set up and verify initial test conditions: child1 has a parent, child2 has |
| 1410 // no parent. | 1404 // no parent. |
| 1411 old_parent->AddChild(child1); | 1405 old_parent->AddChild(child1); |
| 1412 ASSERT_EQ(0U, new_parent->children().size()); | 1406 ASSERT_EQ(0U, new_parent->children().size()); |
| 1413 EXPECT_EQ(old_parent.get(), child1->parent()); | 1407 EXPECT_EQ(old_parent.get(), child1->parent()); |
| 1414 EXPECT_FALSE(child2->parent()); | 1408 EXPECT_FALSE(child2->parent()); |
| 1415 | 1409 |
| 1416 EXPECT_SET_NEEDS_FULL_TREE_SYNC( | 1410 EXPECT_SET_NEEDS_FULL_TREE_SYNC( |
| 1417 1, layer_tree_host_->SetRootLayer(new_parent)); | 1411 1, layer_tree_host_->SetRootLayer(new_parent)); |
| 1418 | 1412 |
| 1419 EXPECT_SET_NEEDS_FULL_TREE_SYNC( | 1413 EXPECT_SET_NEEDS_FULL_TREE_SYNC( |
| 1420 AtLeast(1), new_parent->SetChildren(new_children)); | 1414 AtLeast(1), new_parent->SetChildren(new_children)); |
| 1421 | 1415 |
| 1422 ASSERT_EQ(2U, new_parent->children().size()); | 1416 ASSERT_EQ(2U, new_parent->children().size()); |
| 1423 EXPECT_EQ(new_parent.get(), child1->parent()); | 1417 EXPECT_EQ(new_parent.get(), child1->parent()); |
| 1424 EXPECT_EQ(new_parent.get(), child2->parent()); | 1418 EXPECT_EQ(new_parent.get(), child2->parent()); |
| 1425 | 1419 |
| 1426 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, layer_tree_host_->SetRootLayer(nullptr)); | 1420 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, layer_tree_host_->SetRootLayer(nullptr)); |
| 1427 } | 1421 } |
| 1428 | 1422 |
| 1429 TEST_F(LayerTest, HasAncestor) { | 1423 TEST_F(LayerTest, HasAncestor) { |
| 1430 scoped_refptr<Layer> parent = Layer::Create(layer_settings_); | 1424 scoped_refptr<Layer> parent = Layer::Create(); |
| 1431 EXPECT_FALSE(parent->HasAncestor(parent.get())); | 1425 EXPECT_FALSE(parent->HasAncestor(parent.get())); |
| 1432 | 1426 |
| 1433 scoped_refptr<Layer> child = Layer::Create(layer_settings_); | 1427 scoped_refptr<Layer> child = Layer::Create(); |
| 1434 parent->AddChild(child); | 1428 parent->AddChild(child); |
| 1435 | 1429 |
| 1436 EXPECT_FALSE(child->HasAncestor(child.get())); | 1430 EXPECT_FALSE(child->HasAncestor(child.get())); |
| 1437 EXPECT_TRUE(child->HasAncestor(parent.get())); | 1431 EXPECT_TRUE(child->HasAncestor(parent.get())); |
| 1438 EXPECT_FALSE(parent->HasAncestor(child.get())); | 1432 EXPECT_FALSE(parent->HasAncestor(child.get())); |
| 1439 | 1433 |
| 1440 scoped_refptr<Layer> child_child = Layer::Create(layer_settings_); | 1434 scoped_refptr<Layer> child_child = Layer::Create(); |
| 1441 child->AddChild(child_child); | 1435 child->AddChild(child_child); |
| 1442 | 1436 |
| 1443 EXPECT_FALSE(child_child->HasAncestor(child_child.get())); | 1437 EXPECT_FALSE(child_child->HasAncestor(child_child.get())); |
| 1444 EXPECT_TRUE(child_child->HasAncestor(parent.get())); | 1438 EXPECT_TRUE(child_child->HasAncestor(parent.get())); |
| 1445 EXPECT_TRUE(child_child->HasAncestor(child.get())); | 1439 EXPECT_TRUE(child_child->HasAncestor(child.get())); |
| 1446 EXPECT_FALSE(parent->HasAncestor(child.get())); | 1440 EXPECT_FALSE(parent->HasAncestor(child.get())); |
| 1447 EXPECT_FALSE(parent->HasAncestor(child_child.get())); | 1441 EXPECT_FALSE(parent->HasAncestor(child_child.get())); |
| 1448 } | 1442 } |
| 1449 | 1443 |
| 1450 TEST_F(LayerTest, GetRootLayerAfterTreeManipulations) { | 1444 TEST_F(LayerTest, GetRootLayerAfterTreeManipulations) { |
| 1451 CreateSimpleTestTree(); | 1445 CreateSimpleTestTree(); |
| 1452 | 1446 |
| 1453 // For this test we don't care about SetNeedsFullTreeSync calls. | 1447 // For this test we don't care about SetNeedsFullTreeSync calls. |
| 1454 EXPECT_CALL(*layer_tree_host_, SetNeedsFullTreeSync()).Times(AnyNumber()); | 1448 EXPECT_CALL(*layer_tree_host_, SetNeedsFullTreeSync()).Times(AnyNumber()); |
| 1455 | 1449 |
| 1456 scoped_refptr<Layer> child4 = Layer::Create(layer_settings_); | 1450 scoped_refptr<Layer> child4 = Layer::Create(); |
| 1457 | 1451 |
| 1458 EXPECT_EQ(parent_.get(), parent_->RootLayer()); | 1452 EXPECT_EQ(parent_.get(), parent_->RootLayer()); |
| 1459 EXPECT_EQ(parent_.get(), child1_->RootLayer()); | 1453 EXPECT_EQ(parent_.get(), child1_->RootLayer()); |
| 1460 EXPECT_EQ(parent_.get(), child2_->RootLayer()); | 1454 EXPECT_EQ(parent_.get(), child2_->RootLayer()); |
| 1461 EXPECT_EQ(parent_.get(), child3_->RootLayer()); | 1455 EXPECT_EQ(parent_.get(), child3_->RootLayer()); |
| 1462 EXPECT_EQ(child4.get(), child4->RootLayer()); | 1456 EXPECT_EQ(child4.get(), child4->RootLayer()); |
| 1463 EXPECT_EQ(parent_.get(), grand_child1_->RootLayer()); | 1457 EXPECT_EQ(parent_.get(), grand_child1_->RootLayer()); |
| 1464 EXPECT_EQ(parent_.get(), grand_child2_->RootLayer()); | 1458 EXPECT_EQ(parent_.get(), grand_child2_->RootLayer()); |
| 1465 EXPECT_EQ(parent_.get(), grand_child3_->RootLayer()); | 1459 EXPECT_EQ(parent_.get(), grand_child3_->RootLayer()); |
| 1466 | 1460 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1501 EXPECT_EQ(parent_.get(), grand_child2_->RootLayer()); | 1495 EXPECT_EQ(parent_.get(), grand_child2_->RootLayer()); |
| 1502 EXPECT_EQ(grand_child3_.get(), grand_child3_->RootLayer()); | 1496 EXPECT_EQ(grand_child3_.get(), grand_child3_->RootLayer()); |
| 1503 } | 1497 } |
| 1504 | 1498 |
| 1505 TEST_F(LayerTest, CheckSetNeedsDisplayCausesCorrectBehavior) { | 1499 TEST_F(LayerTest, CheckSetNeedsDisplayCausesCorrectBehavior) { |
| 1506 // The semantics for SetNeedsDisplay which are tested here: | 1500 // The semantics for SetNeedsDisplay which are tested here: |
| 1507 // 1. sets NeedsDisplay flag appropriately. | 1501 // 1. sets NeedsDisplay flag appropriately. |
| 1508 // 2. indirectly calls SetNeedsUpdate, exactly once for each call to | 1502 // 2. indirectly calls SetNeedsUpdate, exactly once for each call to |
| 1509 // SetNeedsDisplay. | 1503 // SetNeedsDisplay. |
| 1510 | 1504 |
| 1511 scoped_refptr<Layer> test_layer = Layer::Create(layer_settings_); | 1505 scoped_refptr<Layer> test_layer = Layer::Create(); |
| 1512 EXPECT_SET_NEEDS_FULL_TREE_SYNC( | 1506 EXPECT_SET_NEEDS_FULL_TREE_SYNC( |
| 1513 1, layer_tree_host_->SetRootLayer(test_layer)); | 1507 1, layer_tree_host_->SetRootLayer(test_layer)); |
| 1514 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetIsDrawable(true)); | 1508 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetIsDrawable(true)); |
| 1515 | 1509 |
| 1516 gfx::Size test_bounds = gfx::Size(501, 508); | 1510 gfx::Size test_bounds = gfx::Size(501, 508); |
| 1517 | 1511 |
| 1518 gfx::Rect dirty1 = gfx::Rect(10, 15, 1, 2); | 1512 gfx::Rect dirty1 = gfx::Rect(10, 15, 1, 2); |
| 1519 gfx::Rect dirty2 = gfx::Rect(20, 25, 3, 4); | 1513 gfx::Rect dirty2 = gfx::Rect(20, 25, 3, 4); |
| 1520 gfx::Rect out_of_bounds_dirty_rect = gfx::Rect(400, 405, 500, 502); | 1514 gfx::Rect out_of_bounds_dirty_rect = gfx::Rect(400, 405, 500, 502); |
| 1521 | 1515 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1554 | 1548 |
| 1555 // Case 4: SetNeedsDisplay() with a non-drawable layer | 1549 // Case 4: SetNeedsDisplay() with a non-drawable layer |
| 1556 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetIsDrawable(false)); | 1550 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetIsDrawable(false)); |
| 1557 test_layer->ResetNeedsDisplayForTesting(); | 1551 test_layer->ResetNeedsDisplayForTesting(); |
| 1558 EXPECT_FALSE(test_layer->NeedsDisplayForTesting()); | 1552 EXPECT_FALSE(test_layer->NeedsDisplayForTesting()); |
| 1559 EXPECT_SET_NEEDS_UPDATE(0, test_layer->SetNeedsDisplayRect(dirty1)); | 1553 EXPECT_SET_NEEDS_UPDATE(0, test_layer->SetNeedsDisplayRect(dirty1)); |
| 1560 EXPECT_TRUE(test_layer->NeedsDisplayForTesting()); | 1554 EXPECT_TRUE(test_layer->NeedsDisplayForTesting()); |
| 1561 } | 1555 } |
| 1562 | 1556 |
| 1563 TEST_F(LayerTest, TestSettingMainThreadScrollingReason) { | 1557 TEST_F(LayerTest, TestSettingMainThreadScrollingReason) { |
| 1564 scoped_refptr<Layer> test_layer = Layer::Create(layer_settings_); | 1558 scoped_refptr<Layer> test_layer = Layer::Create(); |
| 1565 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, | 1559 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, |
| 1566 layer_tree_host_->SetRootLayer(test_layer)); | 1560 layer_tree_host_->SetRootLayer(test_layer)); |
| 1567 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetIsDrawable(true)); | 1561 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetIsDrawable(true)); |
| 1568 | 1562 |
| 1569 // sanity check of initial test condition | 1563 // sanity check of initial test condition |
| 1570 EXPECT_FALSE(test_layer->NeedsDisplayForTesting()); | 1564 EXPECT_FALSE(test_layer->NeedsDisplayForTesting()); |
| 1571 | 1565 |
| 1572 uint32_t reasons = 0, reasons_to_clear = 0, reasons_after_clearing = 0; | 1566 uint32_t reasons = 0, reasons_to_clear = 0, reasons_after_clearing = 0; |
| 1573 reasons |= MainThreadScrollingReason::kEventHandlers; | 1567 reasons |= MainThreadScrollingReason::kEventHandlers; |
| 1574 reasons |= MainThreadScrollingReason::kContinuingMainThreadScroll; | 1568 reasons |= MainThreadScrollingReason::kContinuingMainThreadScroll; |
| (...skipping 30 matching lines...) Expand all Loading... |
| 1605 0, test_layer->ClearMainThreadScrollingReasons(reasons_to_clear)); | 1599 0, test_layer->ClearMainThreadScrollingReasons(reasons_to_clear)); |
| 1606 EXPECT_EQ(reasons_after_clearing, | 1600 EXPECT_EQ(reasons_after_clearing, |
| 1607 test_layer->main_thread_scrolling_reasons()); | 1601 test_layer->main_thread_scrolling_reasons()); |
| 1608 | 1602 |
| 1609 // Check that adding an existing condition doesn't set needs commit. | 1603 // Check that adding an existing condition doesn't set needs commit. |
| 1610 EXPECT_SET_NEEDS_COMMIT(0, test_layer->AddMainThreadScrollingReasons( | 1604 EXPECT_SET_NEEDS_COMMIT(0, test_layer->AddMainThreadScrollingReasons( |
| 1611 MainThreadScrollingReason::kEventHandlers)); | 1605 MainThreadScrollingReason::kEventHandlers)); |
| 1612 } | 1606 } |
| 1613 | 1607 |
| 1614 TEST_F(LayerTest, CheckPropertyChangeCausesCorrectBehavior) { | 1608 TEST_F(LayerTest, CheckPropertyChangeCausesCorrectBehavior) { |
| 1615 scoped_refptr<Layer> test_layer = Layer::Create(layer_settings_); | 1609 scoped_refptr<Layer> test_layer = Layer::Create(); |
| 1616 EXPECT_SET_NEEDS_FULL_TREE_SYNC( | 1610 EXPECT_SET_NEEDS_FULL_TREE_SYNC( |
| 1617 1, layer_tree_host_->SetRootLayer(test_layer)); | 1611 1, layer_tree_host_->SetRootLayer(test_layer)); |
| 1618 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetIsDrawable(true)); | 1612 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetIsDrawable(true)); |
| 1619 | 1613 |
| 1620 scoped_refptr<Layer> dummy_layer1 = Layer::Create(layer_settings_); | 1614 scoped_refptr<Layer> dummy_layer1 = Layer::Create(); |
| 1621 scoped_refptr<Layer> dummy_layer2 = Layer::Create(layer_settings_); | 1615 scoped_refptr<Layer> dummy_layer2 = Layer::Create(); |
| 1622 | 1616 |
| 1623 // sanity check of initial test condition | 1617 // sanity check of initial test condition |
| 1624 EXPECT_FALSE(test_layer->NeedsDisplayForTesting()); | 1618 EXPECT_FALSE(test_layer->NeedsDisplayForTesting()); |
| 1625 | 1619 |
| 1626 // Next, test properties that should call SetNeedsCommit (but not | 1620 // Next, test properties that should call SetNeedsCommit (but not |
| 1627 // SetNeedsDisplay). All properties need to be set to new values in order for | 1621 // SetNeedsDisplay). All properties need to be set to new values in order for |
| 1628 // SetNeedsCommit to be called. | 1622 // SetNeedsCommit to be called. |
| 1629 EXPECT_SET_NEEDS_COMMIT( | 1623 EXPECT_SET_NEEDS_COMMIT( |
| 1630 1, test_layer->SetTransformOrigin(gfx::Point3F(1.23f, 4.56f, 0.f))); | 1624 1, test_layer->SetTransformOrigin(gfx::Point3F(1.23f, 4.56f, 0.f))); |
| 1631 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetBackgroundColor(SK_ColorLTGRAY)); | 1625 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetBackgroundColor(SK_ColorLTGRAY)); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 1662 dummy_layer2.get())); | 1656 dummy_layer2.get())); |
| 1663 | 1657 |
| 1664 // The above tests should not have caused a change to the needs_display flag. | 1658 // The above tests should not have caused a change to the needs_display flag. |
| 1665 EXPECT_FALSE(test_layer->NeedsDisplayForTesting()); | 1659 EXPECT_FALSE(test_layer->NeedsDisplayForTesting()); |
| 1666 | 1660 |
| 1667 // As layers are removed from the tree, they will cause a tree sync. | 1661 // As layers are removed from the tree, they will cause a tree sync. |
| 1668 EXPECT_CALL(*layer_tree_host_, SetNeedsFullTreeSync()).Times((AnyNumber())); | 1662 EXPECT_CALL(*layer_tree_host_, SetNeedsFullTreeSync()).Times((AnyNumber())); |
| 1669 } | 1663 } |
| 1670 | 1664 |
| 1671 TEST_F(LayerTest, PushPropertiesAccumulatesUpdateRect) { | 1665 TEST_F(LayerTest, PushPropertiesAccumulatesUpdateRect) { |
| 1672 scoped_refptr<Layer> test_layer = Layer::Create(layer_settings_); | 1666 scoped_refptr<Layer> test_layer = Layer::Create(); |
| 1673 scoped_ptr<LayerImpl> impl_layer = | 1667 scoped_ptr<LayerImpl> impl_layer = |
| 1674 LayerImpl::Create(host_impl_.active_tree(), 1); | 1668 LayerImpl::Create(host_impl_.active_tree(), 1); |
| 1675 | 1669 |
| 1676 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, | 1670 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, |
| 1677 layer_tree_host_->SetRootLayer(test_layer)); | 1671 layer_tree_host_->SetRootLayer(test_layer)); |
| 1678 | 1672 |
| 1679 test_layer->SetNeedsDisplayRect(gfx::Rect(5, 5)); | 1673 test_layer->SetNeedsDisplayRect(gfx::Rect(5, 5)); |
| 1680 test_layer->PushPropertiesTo(impl_layer.get()); | 1674 test_layer->PushPropertiesTo(impl_layer.get()); |
| 1681 EXPECT_FLOAT_RECT_EQ(gfx::RectF(0.f, 0.f, 5.f, 5.f), | 1675 EXPECT_FLOAT_RECT_EQ(gfx::RectF(0.f, 0.f, 5.f, 5.f), |
| 1682 impl_layer->update_rect()); | 1676 impl_layer->update_rect()); |
| 1683 | 1677 |
| 1684 // The LayerImpl's update_rect() should be accumulated here, since we did not | 1678 // The LayerImpl's update_rect() should be accumulated here, since we did not |
| 1685 // do anything to clear it. | 1679 // do anything to clear it. |
| 1686 test_layer->SetNeedsDisplayRect(gfx::Rect(10, 10, 5, 5)); | 1680 test_layer->SetNeedsDisplayRect(gfx::Rect(10, 10, 5, 5)); |
| 1687 test_layer->PushPropertiesTo(impl_layer.get()); | 1681 test_layer->PushPropertiesTo(impl_layer.get()); |
| 1688 EXPECT_FLOAT_RECT_EQ(gfx::RectF(0.f, 0.f, 15.f, 15.f), | 1682 EXPECT_FLOAT_RECT_EQ(gfx::RectF(0.f, 0.f, 15.f, 15.f), |
| 1689 impl_layer->update_rect()); | 1683 impl_layer->update_rect()); |
| 1690 | 1684 |
| 1691 // If we do clear the LayerImpl side, then the next update_rect() should be | 1685 // If we do clear the LayerImpl side, then the next update_rect() should be |
| 1692 // fresh without accumulation. | 1686 // fresh without accumulation. |
| 1693 impl_layer->ResetAllChangeTrackingForSubtree(); | 1687 impl_layer->ResetAllChangeTrackingForSubtree(); |
| 1694 test_layer->SetNeedsDisplayRect(gfx::Rect(10, 10, 5, 5)); | 1688 test_layer->SetNeedsDisplayRect(gfx::Rect(10, 10, 5, 5)); |
| 1695 test_layer->PushPropertiesTo(impl_layer.get()); | 1689 test_layer->PushPropertiesTo(impl_layer.get()); |
| 1696 EXPECT_FLOAT_RECT_EQ(gfx::RectF(10.f, 10.f, 5.f, 5.f), | 1690 EXPECT_FLOAT_RECT_EQ(gfx::RectF(10.f, 10.f, 5.f, 5.f), |
| 1697 impl_layer->update_rect()); | 1691 impl_layer->update_rect()); |
| 1698 } | 1692 } |
| 1699 | 1693 |
| 1700 TEST_F(LayerTest, PushPropertiesCausesLayerPropertyChangedForTransform) { | 1694 TEST_F(LayerTest, PushPropertiesCausesLayerPropertyChangedForTransform) { |
| 1701 scoped_refptr<Layer> test_layer = Layer::Create(layer_settings_); | 1695 scoped_refptr<Layer> test_layer = Layer::Create(); |
| 1702 scoped_ptr<LayerImpl> impl_layer = | 1696 scoped_ptr<LayerImpl> impl_layer = |
| 1703 LayerImpl::Create(host_impl_.active_tree(), 1); | 1697 LayerImpl::Create(host_impl_.active_tree(), 1); |
| 1704 | 1698 |
| 1705 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, | 1699 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, |
| 1706 layer_tree_host_->SetRootLayer(test_layer)); | 1700 layer_tree_host_->SetRootLayer(test_layer)); |
| 1707 | 1701 |
| 1708 gfx::Transform transform; | 1702 gfx::Transform transform; |
| 1709 transform.Rotate(45.0); | 1703 transform.Rotate(45.0); |
| 1710 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetTransform(transform)); | 1704 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetTransform(transform)); |
| 1711 | 1705 |
| 1712 EXPECT_FALSE(impl_layer->LayerPropertyChanged()); | 1706 EXPECT_FALSE(impl_layer->LayerPropertyChanged()); |
| 1713 | 1707 |
| 1714 test_layer->PushPropertiesTo(impl_layer.get()); | 1708 test_layer->PushPropertiesTo(impl_layer.get()); |
| 1715 | 1709 |
| 1716 EXPECT_TRUE(impl_layer->LayerPropertyChanged()); | 1710 EXPECT_TRUE(impl_layer->LayerPropertyChanged()); |
| 1717 } | 1711 } |
| 1718 | 1712 |
| 1719 TEST_F(LayerTest, PushPropertiesCausesLayerPropertyChangedForOpacity) { | 1713 TEST_F(LayerTest, PushPropertiesCausesLayerPropertyChangedForOpacity) { |
| 1720 scoped_refptr<Layer> test_layer = Layer::Create(layer_settings_); | 1714 scoped_refptr<Layer> test_layer = Layer::Create(); |
| 1721 scoped_ptr<LayerImpl> impl_layer = | 1715 scoped_ptr<LayerImpl> impl_layer = |
| 1722 LayerImpl::Create(host_impl_.active_tree(), 1); | 1716 LayerImpl::Create(host_impl_.active_tree(), 1); |
| 1723 | 1717 |
| 1724 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, | 1718 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, |
| 1725 layer_tree_host_->SetRootLayer(test_layer)); | 1719 layer_tree_host_->SetRootLayer(test_layer)); |
| 1726 | 1720 |
| 1727 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetOpacity(0.5f)); | 1721 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetOpacity(0.5f)); |
| 1728 | 1722 |
| 1729 EXPECT_FALSE(impl_layer->LayerPropertyChanged()); | 1723 EXPECT_FALSE(impl_layer->LayerPropertyChanged()); |
| 1730 | 1724 |
| 1731 test_layer->PushPropertiesTo(impl_layer.get()); | 1725 test_layer->PushPropertiesTo(impl_layer.get()); |
| 1732 | 1726 |
| 1733 EXPECT_TRUE(impl_layer->LayerPropertyChanged()); | 1727 EXPECT_TRUE(impl_layer->LayerPropertyChanged()); |
| 1734 } | 1728 } |
| 1735 | 1729 |
| 1736 TEST_F(LayerTest, MaskAndReplicaHasParent) { | 1730 TEST_F(LayerTest, MaskAndReplicaHasParent) { |
| 1737 scoped_refptr<Layer> parent = Layer::Create(layer_settings_); | 1731 scoped_refptr<Layer> parent = Layer::Create(); |
| 1738 scoped_refptr<Layer> child = Layer::Create(layer_settings_); | 1732 scoped_refptr<Layer> child = Layer::Create(); |
| 1739 scoped_refptr<Layer> mask = Layer::Create(layer_settings_); | 1733 scoped_refptr<Layer> mask = Layer::Create(); |
| 1740 scoped_refptr<Layer> replica = Layer::Create(layer_settings_); | 1734 scoped_refptr<Layer> replica = Layer::Create(); |
| 1741 scoped_refptr<Layer> replica_mask = Layer::Create(layer_settings_); | 1735 scoped_refptr<Layer> replica_mask = Layer::Create(); |
| 1742 scoped_refptr<Layer> mask_replacement = Layer::Create(layer_settings_); | 1736 scoped_refptr<Layer> mask_replacement = Layer::Create(); |
| 1743 scoped_refptr<Layer> replica_replacement = Layer::Create(layer_settings_); | 1737 scoped_refptr<Layer> replica_replacement = Layer::Create(); |
| 1744 scoped_refptr<Layer> replica_mask_replacement = | 1738 scoped_refptr<Layer> replica_mask_replacement = Layer::Create(); |
| 1745 Layer::Create(layer_settings_); | |
| 1746 | 1739 |
| 1747 parent->AddChild(child); | 1740 parent->AddChild(child); |
| 1748 child->SetMaskLayer(mask.get()); | 1741 child->SetMaskLayer(mask.get()); |
| 1749 child->SetReplicaLayer(replica.get()); | 1742 child->SetReplicaLayer(replica.get()); |
| 1750 replica->SetMaskLayer(replica_mask.get()); | 1743 replica->SetMaskLayer(replica_mask.get()); |
| 1751 | 1744 |
| 1752 EXPECT_EQ(parent.get(), child->parent()); | 1745 EXPECT_EQ(parent.get(), child->parent()); |
| 1753 EXPECT_EQ(child.get(), mask->parent()); | 1746 EXPECT_EQ(child.get(), mask->parent()); |
| 1754 EXPECT_EQ(child.get(), replica->parent()); | 1747 EXPECT_EQ(child.get(), replica->parent()); |
| 1755 EXPECT_EQ(replica.get(), replica_mask->parent()); | 1748 EXPECT_EQ(replica.get(), replica_mask->parent()); |
| 1756 | 1749 |
| 1757 replica->SetMaskLayer(replica_mask_replacement.get()); | 1750 replica->SetMaskLayer(replica_mask_replacement.get()); |
| 1758 EXPECT_EQ(nullptr, replica_mask->parent()); | 1751 EXPECT_EQ(nullptr, replica_mask->parent()); |
| 1759 EXPECT_EQ(replica.get(), replica_mask_replacement->parent()); | 1752 EXPECT_EQ(replica.get(), replica_mask_replacement->parent()); |
| 1760 | 1753 |
| 1761 child->SetMaskLayer(mask_replacement.get()); | 1754 child->SetMaskLayer(mask_replacement.get()); |
| 1762 EXPECT_EQ(nullptr, mask->parent()); | 1755 EXPECT_EQ(nullptr, mask->parent()); |
| 1763 EXPECT_EQ(child.get(), mask_replacement->parent()); | 1756 EXPECT_EQ(child.get(), mask_replacement->parent()); |
| 1764 | 1757 |
| 1765 child->SetReplicaLayer(replica_replacement.get()); | 1758 child->SetReplicaLayer(replica_replacement.get()); |
| 1766 EXPECT_EQ(nullptr, replica->parent()); | 1759 EXPECT_EQ(nullptr, replica->parent()); |
| 1767 EXPECT_EQ(child.get(), replica_replacement->parent()); | 1760 EXPECT_EQ(child.get(), replica_replacement->parent()); |
| 1768 | 1761 |
| 1769 EXPECT_EQ(replica.get(), replica->mask_layer()->parent()); | 1762 EXPECT_EQ(replica.get(), replica->mask_layer()->parent()); |
| 1770 } | 1763 } |
| 1771 | 1764 |
| 1772 TEST_F(LayerTest, CheckTransformIsInvertible) { | 1765 TEST_F(LayerTest, CheckTransformIsInvertible) { |
| 1773 scoped_refptr<Layer> layer = Layer::Create(layer_settings_); | 1766 scoped_refptr<Layer> layer = Layer::Create(); |
| 1774 scoped_ptr<LayerImpl> impl_layer = | 1767 scoped_ptr<LayerImpl> impl_layer = |
| 1775 LayerImpl::Create(host_impl_.active_tree(), 1); | 1768 LayerImpl::Create(host_impl_.active_tree(), 1); |
| 1776 EXPECT_CALL(*layer_tree_host_, SetNeedsFullTreeSync()).Times(1); | 1769 EXPECT_CALL(*layer_tree_host_, SetNeedsFullTreeSync()).Times(1); |
| 1777 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AnyNumber()); | 1770 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AnyNumber()); |
| 1778 layer_tree_host_->SetRootLayer(layer); | 1771 layer_tree_host_->SetRootLayer(layer); |
| 1779 | 1772 |
| 1780 EXPECT_TRUE(layer->transform_is_invertible()); | 1773 EXPECT_TRUE(layer->transform_is_invertible()); |
| 1781 | 1774 |
| 1782 gfx::Transform singular_transform; | 1775 gfx::Transform singular_transform; |
| 1783 singular_transform.Scale3d( | 1776 singular_transform.Scale3d( |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1794 | 1787 |
| 1795 layer->SetTransform(rotation_transform); | 1788 layer->SetTransform(rotation_transform); |
| 1796 layer->PushPropertiesTo(impl_layer.get()); | 1789 layer->PushPropertiesTo(impl_layer.get()); |
| 1797 EXPECT_TRUE(layer->transform_is_invertible()); | 1790 EXPECT_TRUE(layer->transform_is_invertible()); |
| 1798 EXPECT_TRUE(impl_layer->transform_is_invertible()); | 1791 EXPECT_TRUE(impl_layer->transform_is_invertible()); |
| 1799 | 1792 |
| 1800 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); | 1793 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); |
| 1801 } | 1794 } |
| 1802 | 1795 |
| 1803 TEST_F(LayerTest, TransformIsInvertibleAnimation) { | 1796 TEST_F(LayerTest, TransformIsInvertibleAnimation) { |
| 1804 scoped_refptr<Layer> layer = Layer::Create(layer_settings_); | 1797 scoped_refptr<Layer> layer = Layer::Create(); |
| 1805 scoped_ptr<LayerImpl> impl_layer = | 1798 scoped_ptr<LayerImpl> impl_layer = |
| 1806 LayerImpl::Create(host_impl_.active_tree(), 1); | 1799 LayerImpl::Create(host_impl_.active_tree(), 1); |
| 1807 EXPECT_CALL(*layer_tree_host_, SetNeedsFullTreeSync()).Times(1); | 1800 EXPECT_CALL(*layer_tree_host_, SetNeedsFullTreeSync()).Times(1); |
| 1808 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AnyNumber()); | 1801 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AnyNumber()); |
| 1809 layer_tree_host_->SetRootLayer(layer); | 1802 layer_tree_host_->SetRootLayer(layer); |
| 1810 | 1803 |
| 1811 EXPECT_TRUE(layer->transform_is_invertible()); | 1804 EXPECT_TRUE(layer->transform_is_invertible()); |
| 1812 | 1805 |
| 1813 gfx::Transform singular_transform; | 1806 gfx::Transform singular_transform; |
| 1814 singular_transform.Scale3d( | 1807 singular_transform.Scale3d( |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1862 for (size_t i = 0; i < layer->children().size(); ++i) | 1855 for (size_t i = 0; i < layer->children().size(); ++i) |
| 1863 AssertLayerTreeHostMatchesForSubtree(layer->children()[i].get(), host); | 1856 AssertLayerTreeHostMatchesForSubtree(layer->children()[i].get(), host); |
| 1864 | 1857 |
| 1865 if (layer->mask_layer()) | 1858 if (layer->mask_layer()) |
| 1866 AssertLayerTreeHostMatchesForSubtree(layer->mask_layer(), host); | 1859 AssertLayerTreeHostMatchesForSubtree(layer->mask_layer(), host); |
| 1867 | 1860 |
| 1868 if (layer->replica_layer()) | 1861 if (layer->replica_layer()) |
| 1869 AssertLayerTreeHostMatchesForSubtree(layer->replica_layer(), host); | 1862 AssertLayerTreeHostMatchesForSubtree(layer->replica_layer(), host); |
| 1870 } | 1863 } |
| 1871 | 1864 |
| 1872 class LayerLayerTreeHostTest : public testing::Test { | 1865 class LayerLayerTreeHostTest : public testing::Test {}; |
| 1873 public: | |
| 1874 LayerLayerTreeHostTest() { | |
| 1875 layer_settings_.use_compositor_animation_timelines = true; | |
| 1876 } | |
| 1877 | |
| 1878 protected: | |
| 1879 LayerSettings layer_settings_; | |
| 1880 }; | |
| 1881 | 1866 |
| 1882 TEST_F(LayerLayerTreeHostTest, EnteringTree) { | 1867 TEST_F(LayerLayerTreeHostTest, EnteringTree) { |
| 1883 scoped_refptr<Layer> parent = Layer::Create(layer_settings_); | 1868 scoped_refptr<Layer> parent = Layer::Create(); |
| 1884 scoped_refptr<Layer> child = Layer::Create(layer_settings_); | 1869 scoped_refptr<Layer> child = Layer::Create(); |
| 1885 scoped_refptr<Layer> mask = Layer::Create(layer_settings_); | 1870 scoped_refptr<Layer> mask = Layer::Create(); |
| 1886 scoped_refptr<Layer> replica = Layer::Create(layer_settings_); | 1871 scoped_refptr<Layer> replica = Layer::Create(); |
| 1887 scoped_refptr<Layer> replica_mask = Layer::Create(layer_settings_); | 1872 scoped_refptr<Layer> replica_mask = Layer::Create(); |
| 1888 | 1873 |
| 1889 // Set up a detached tree of layers. The host pointer should be nil for these | 1874 // Set up a detached tree of layers. The host pointer should be nil for these |
| 1890 // layers. | 1875 // layers. |
| 1891 parent->AddChild(child); | 1876 parent->AddChild(child); |
| 1892 child->SetMaskLayer(mask.get()); | 1877 child->SetMaskLayer(mask.get()); |
| 1893 child->SetReplicaLayer(replica.get()); | 1878 child->SetReplicaLayer(replica.get()); |
| 1894 replica->SetMaskLayer(replica_mask.get()); | 1879 replica->SetMaskLayer(replica_mask.get()); |
| 1895 | 1880 |
| 1896 AssertLayerTreeHostMatchesForSubtree(parent.get(), nullptr); | 1881 AssertLayerTreeHostMatchesForSubtree(parent.get(), nullptr); |
| 1897 | 1882 |
| 1898 LayerTreeHostFactory factory; | 1883 LayerTreeHostFactory factory; |
| 1899 scoped_ptr<LayerTreeHost> layer_tree_host = factory.Create(); | 1884 scoped_ptr<LayerTreeHost> layer_tree_host = factory.Create(); |
| 1900 // Setting the root layer should set the host pointer for all layers in the | 1885 // Setting the root layer should set the host pointer for all layers in the |
| 1901 // tree. | 1886 // tree. |
| 1902 layer_tree_host->SetRootLayer(parent.get()); | 1887 layer_tree_host->SetRootLayer(parent.get()); |
| 1903 | 1888 |
| 1904 AssertLayerTreeHostMatchesForSubtree(parent.get(), layer_tree_host.get()); | 1889 AssertLayerTreeHostMatchesForSubtree(parent.get(), layer_tree_host.get()); |
| 1905 | 1890 |
| 1906 // Clearing the root layer should also clear out the host pointers for all | 1891 // Clearing the root layer should also clear out the host pointers for all |
| 1907 // layers in the tree. | 1892 // layers in the tree. |
| 1908 layer_tree_host->SetRootLayer(nullptr); | 1893 layer_tree_host->SetRootLayer(nullptr); |
| 1909 | 1894 |
| 1910 AssertLayerTreeHostMatchesForSubtree(parent.get(), nullptr); | 1895 AssertLayerTreeHostMatchesForSubtree(parent.get(), nullptr); |
| 1911 } | 1896 } |
| 1912 | 1897 |
| 1913 TEST_F(LayerLayerTreeHostTest, AddingLayerSubtree) { | 1898 TEST_F(LayerLayerTreeHostTest, AddingLayerSubtree) { |
| 1914 scoped_refptr<Layer> parent = Layer::Create(layer_settings_); | 1899 scoped_refptr<Layer> parent = Layer::Create(); |
| 1915 LayerTreeHostFactory factory; | 1900 LayerTreeHostFactory factory; |
| 1916 scoped_ptr<LayerTreeHost> layer_tree_host = factory.Create(); | 1901 scoped_ptr<LayerTreeHost> layer_tree_host = factory.Create(); |
| 1917 | 1902 |
| 1918 layer_tree_host->SetRootLayer(parent.get()); | 1903 layer_tree_host->SetRootLayer(parent.get()); |
| 1919 | 1904 |
| 1920 EXPECT_EQ(parent->layer_tree_host(), layer_tree_host.get()); | 1905 EXPECT_EQ(parent->layer_tree_host(), layer_tree_host.get()); |
| 1921 | 1906 |
| 1922 // Adding a subtree to a layer already associated with a host should set the | 1907 // Adding a subtree to a layer already associated with a host should set the |
| 1923 // host pointer on all layers in that subtree. | 1908 // host pointer on all layers in that subtree. |
| 1924 scoped_refptr<Layer> child = Layer::Create(layer_settings_); | 1909 scoped_refptr<Layer> child = Layer::Create(); |
| 1925 scoped_refptr<Layer> grand_child = Layer::Create(layer_settings_); | 1910 scoped_refptr<Layer> grand_child = Layer::Create(); |
| 1926 child->AddChild(grand_child); | 1911 child->AddChild(grand_child); |
| 1927 | 1912 |
| 1928 // Masks, replicas, and replica masks should pick up the new host too. | 1913 // Masks, replicas, and replica masks should pick up the new host too. |
| 1929 scoped_refptr<Layer> child_mask = Layer::Create(layer_settings_); | 1914 scoped_refptr<Layer> child_mask = Layer::Create(); |
| 1930 child->SetMaskLayer(child_mask.get()); | 1915 child->SetMaskLayer(child_mask.get()); |
| 1931 scoped_refptr<Layer> child_replica = Layer::Create(layer_settings_); | 1916 scoped_refptr<Layer> child_replica = Layer::Create(); |
| 1932 child->SetReplicaLayer(child_replica.get()); | 1917 child->SetReplicaLayer(child_replica.get()); |
| 1933 scoped_refptr<Layer> child_replica_mask = Layer::Create(layer_settings_); | 1918 scoped_refptr<Layer> child_replica_mask = Layer::Create(); |
| 1934 child_replica->SetMaskLayer(child_replica_mask.get()); | 1919 child_replica->SetMaskLayer(child_replica_mask.get()); |
| 1935 | 1920 |
| 1936 parent->AddChild(child); | 1921 parent->AddChild(child); |
| 1937 AssertLayerTreeHostMatchesForSubtree(parent.get(), layer_tree_host.get()); | 1922 AssertLayerTreeHostMatchesForSubtree(parent.get(), layer_tree_host.get()); |
| 1938 | 1923 |
| 1939 layer_tree_host->SetRootLayer(nullptr); | 1924 layer_tree_host->SetRootLayer(nullptr); |
| 1940 } | 1925 } |
| 1941 | 1926 |
| 1942 TEST_F(LayerLayerTreeHostTest, ChangeHost) { | 1927 TEST_F(LayerLayerTreeHostTest, ChangeHost) { |
| 1943 scoped_refptr<Layer> parent = Layer::Create(layer_settings_); | 1928 scoped_refptr<Layer> parent = Layer::Create(); |
| 1944 scoped_refptr<Layer> child = Layer::Create(layer_settings_); | 1929 scoped_refptr<Layer> child = Layer::Create(); |
| 1945 scoped_refptr<Layer> mask = Layer::Create(layer_settings_); | 1930 scoped_refptr<Layer> mask = Layer::Create(); |
| 1946 scoped_refptr<Layer> replica = Layer::Create(layer_settings_); | 1931 scoped_refptr<Layer> replica = Layer::Create(); |
| 1947 scoped_refptr<Layer> replica_mask = Layer::Create(layer_settings_); | 1932 scoped_refptr<Layer> replica_mask = Layer::Create(); |
| 1948 | 1933 |
| 1949 // Same setup as the previous test. | 1934 // Same setup as the previous test. |
| 1950 parent->AddChild(child); | 1935 parent->AddChild(child); |
| 1951 child->SetMaskLayer(mask.get()); | 1936 child->SetMaskLayer(mask.get()); |
| 1952 child->SetReplicaLayer(replica.get()); | 1937 child->SetReplicaLayer(replica.get()); |
| 1953 replica->SetMaskLayer(replica_mask.get()); | 1938 replica->SetMaskLayer(replica_mask.get()); |
| 1954 | 1939 |
| 1955 LayerTreeHostFactory factory; | 1940 LayerTreeHostFactory factory; |
| 1956 scoped_ptr<LayerTreeHost> first_layer_tree_host = factory.Create(); | 1941 scoped_ptr<LayerTreeHost> first_layer_tree_host = factory.Create(); |
| 1957 first_layer_tree_host->SetRootLayer(parent.get()); | 1942 first_layer_tree_host->SetRootLayer(parent.get()); |
| 1958 | 1943 |
| 1959 AssertLayerTreeHostMatchesForSubtree(parent.get(), | 1944 AssertLayerTreeHostMatchesForSubtree(parent.get(), |
| 1960 first_layer_tree_host.get()); | 1945 first_layer_tree_host.get()); |
| 1961 | 1946 |
| 1962 // Now re-root the tree to a new host (simulating what we do on a context lost | 1947 // Now re-root the tree to a new host (simulating what we do on a context lost |
| 1963 // event). This should update the host pointers for all layers in the tree. | 1948 // event). This should update the host pointers for all layers in the tree. |
| 1964 scoped_ptr<LayerTreeHost> second_layer_tree_host = factory.Create(); | 1949 scoped_ptr<LayerTreeHost> second_layer_tree_host = factory.Create(); |
| 1965 second_layer_tree_host->SetRootLayer(parent.get()); | 1950 second_layer_tree_host->SetRootLayer(parent.get()); |
| 1966 | 1951 |
| 1967 AssertLayerTreeHostMatchesForSubtree(parent.get(), | 1952 AssertLayerTreeHostMatchesForSubtree(parent.get(), |
| 1968 second_layer_tree_host.get()); | 1953 second_layer_tree_host.get()); |
| 1969 | 1954 |
| 1970 second_layer_tree_host->SetRootLayer(nullptr); | 1955 second_layer_tree_host->SetRootLayer(nullptr); |
| 1971 } | 1956 } |
| 1972 | 1957 |
| 1973 TEST_F(LayerLayerTreeHostTest, ChangeHostInSubtree) { | 1958 TEST_F(LayerLayerTreeHostTest, ChangeHostInSubtree) { |
| 1974 scoped_refptr<Layer> first_parent = Layer::Create(layer_settings_); | 1959 scoped_refptr<Layer> first_parent = Layer::Create(); |
| 1975 scoped_refptr<Layer> first_child = Layer::Create(layer_settings_); | 1960 scoped_refptr<Layer> first_child = Layer::Create(); |
| 1976 scoped_refptr<Layer> second_parent = Layer::Create(layer_settings_); | 1961 scoped_refptr<Layer> second_parent = Layer::Create(); |
| 1977 scoped_refptr<Layer> second_child = Layer::Create(layer_settings_); | 1962 scoped_refptr<Layer> second_child = Layer::Create(); |
| 1978 scoped_refptr<Layer> second_grand_child = Layer::Create(layer_settings_); | 1963 scoped_refptr<Layer> second_grand_child = Layer::Create(); |
| 1979 | 1964 |
| 1980 // First put all children under the first parent and set the first host. | 1965 // First put all children under the first parent and set the first host. |
| 1981 first_parent->AddChild(first_child); | 1966 first_parent->AddChild(first_child); |
| 1982 second_child->AddChild(second_grand_child); | 1967 second_child->AddChild(second_grand_child); |
| 1983 first_parent->AddChild(second_child); | 1968 first_parent->AddChild(second_child); |
| 1984 | 1969 |
| 1985 LayerTreeHostFactory factory; | 1970 LayerTreeHostFactory factory; |
| 1986 scoped_ptr<LayerTreeHost> first_layer_tree_host = factory.Create(); | 1971 scoped_ptr<LayerTreeHost> first_layer_tree_host = factory.Create(); |
| 1987 first_layer_tree_host->SetRootLayer(first_parent.get()); | 1972 first_layer_tree_host->SetRootLayer(first_parent.get()); |
| 1988 | 1973 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 2000 EXPECT_EQ(second_layer_tree_host.get(), second_child->layer_tree_host()); | 1985 EXPECT_EQ(second_layer_tree_host.get(), second_child->layer_tree_host()); |
| 2001 EXPECT_EQ(second_layer_tree_host.get(), | 1986 EXPECT_EQ(second_layer_tree_host.get(), |
| 2002 second_grand_child->layer_tree_host()); | 1987 second_grand_child->layer_tree_host()); |
| 2003 | 1988 |
| 2004 // Test over, cleanup time. | 1989 // Test over, cleanup time. |
| 2005 first_layer_tree_host->SetRootLayer(nullptr); | 1990 first_layer_tree_host->SetRootLayer(nullptr); |
| 2006 second_layer_tree_host->SetRootLayer(nullptr); | 1991 second_layer_tree_host->SetRootLayer(nullptr); |
| 2007 } | 1992 } |
| 2008 | 1993 |
| 2009 TEST_F(LayerLayerTreeHostTest, ReplaceMaskAndReplicaLayer) { | 1994 TEST_F(LayerLayerTreeHostTest, ReplaceMaskAndReplicaLayer) { |
| 2010 scoped_refptr<Layer> parent = Layer::Create(layer_settings_); | 1995 scoped_refptr<Layer> parent = Layer::Create(); |
| 2011 scoped_refptr<Layer> mask = Layer::Create(layer_settings_); | 1996 scoped_refptr<Layer> mask = Layer::Create(); |
| 2012 scoped_refptr<Layer> replica = Layer::Create(layer_settings_); | 1997 scoped_refptr<Layer> replica = Layer::Create(); |
| 2013 scoped_refptr<Layer> mask_child = Layer::Create(layer_settings_); | 1998 scoped_refptr<Layer> mask_child = Layer::Create(); |
| 2014 scoped_refptr<Layer> replica_child = Layer::Create(layer_settings_); | 1999 scoped_refptr<Layer> replica_child = Layer::Create(); |
| 2015 scoped_refptr<Layer> mask_replacement = Layer::Create(layer_settings_); | 2000 scoped_refptr<Layer> mask_replacement = Layer::Create(); |
| 2016 scoped_refptr<Layer> replica_replacement = Layer::Create(layer_settings_); | 2001 scoped_refptr<Layer> replica_replacement = Layer::Create(); |
| 2017 | 2002 |
| 2018 parent->SetMaskLayer(mask.get()); | 2003 parent->SetMaskLayer(mask.get()); |
| 2019 parent->SetReplicaLayer(replica.get()); | 2004 parent->SetReplicaLayer(replica.get()); |
| 2020 mask->AddChild(mask_child); | 2005 mask->AddChild(mask_child); |
| 2021 replica->AddChild(replica_child); | 2006 replica->AddChild(replica_child); |
| 2022 | 2007 |
| 2023 LayerTreeHostFactory factory; | 2008 LayerTreeHostFactory factory; |
| 2024 scoped_ptr<LayerTreeHost> layer_tree_host = factory.Create(); | 2009 scoped_ptr<LayerTreeHost> layer_tree_host = factory.Create(); |
| 2025 layer_tree_host->SetRootLayer(parent.get()); | 2010 layer_tree_host->SetRootLayer(parent.get()); |
| 2026 | 2011 |
| 2027 AssertLayerTreeHostMatchesForSubtree(parent.get(), layer_tree_host.get()); | 2012 AssertLayerTreeHostMatchesForSubtree(parent.get(), layer_tree_host.get()); |
| 2028 | 2013 |
| 2029 // Replacing the mask should clear out the old mask's subtree's host pointers. | 2014 // Replacing the mask should clear out the old mask's subtree's host pointers. |
| 2030 parent->SetMaskLayer(mask_replacement.get()); | 2015 parent->SetMaskLayer(mask_replacement.get()); |
| 2031 EXPECT_EQ(nullptr, mask->layer_tree_host()); | 2016 EXPECT_EQ(nullptr, mask->layer_tree_host()); |
| 2032 EXPECT_EQ(nullptr, mask_child->layer_tree_host()); | 2017 EXPECT_EQ(nullptr, mask_child->layer_tree_host()); |
| 2033 | 2018 |
| 2034 // Same for replacing a replica layer. | 2019 // Same for replacing a replica layer. |
| 2035 parent->SetReplicaLayer(replica_replacement.get()); | 2020 parent->SetReplicaLayer(replica_replacement.get()); |
| 2036 EXPECT_EQ(nullptr, replica->layer_tree_host()); | 2021 EXPECT_EQ(nullptr, replica->layer_tree_host()); |
| 2037 EXPECT_EQ(nullptr, replica_child->layer_tree_host()); | 2022 EXPECT_EQ(nullptr, replica_child->layer_tree_host()); |
| 2038 | 2023 |
| 2039 // Test over, cleanup time. | 2024 // Test over, cleanup time. |
| 2040 layer_tree_host->SetRootLayer(nullptr); | 2025 layer_tree_host->SetRootLayer(nullptr); |
| 2041 } | 2026 } |
| 2042 | 2027 |
| 2043 TEST_F(LayerLayerTreeHostTest, DestroyHostWithNonNullRootLayer) { | 2028 TEST_F(LayerLayerTreeHostTest, DestroyHostWithNonNullRootLayer) { |
| 2044 scoped_refptr<Layer> root = Layer::Create(layer_settings_); | 2029 scoped_refptr<Layer> root = Layer::Create(); |
| 2045 scoped_refptr<Layer> child = Layer::Create(layer_settings_); | 2030 scoped_refptr<Layer> child = Layer::Create(); |
| 2046 root->AddChild(child); | 2031 root->AddChild(child); |
| 2047 LayerTreeHostFactory factory; | 2032 LayerTreeHostFactory factory; |
| 2048 scoped_ptr<LayerTreeHost> layer_tree_host = factory.Create(); | 2033 scoped_ptr<LayerTreeHost> layer_tree_host = factory.Create(); |
| 2049 layer_tree_host->SetRootLayer(root); | 2034 layer_tree_host->SetRootLayer(root); |
| 2050 } | 2035 } |
| 2051 | 2036 |
| 2052 TEST_F(LayerTest, SafeOpaqueBackgroundColor) { | 2037 TEST_F(LayerTest, SafeOpaqueBackgroundColor) { |
| 2053 LayerTreeHostFactory factory; | 2038 LayerTreeHostFactory factory; |
| 2054 scoped_ptr<LayerTreeHost> layer_tree_host = factory.Create(); | 2039 scoped_ptr<LayerTreeHost> layer_tree_host = factory.Create(); |
| 2055 | 2040 |
| 2056 scoped_refptr<Layer> layer = Layer::Create(layer_settings_); | 2041 scoped_refptr<Layer> layer = Layer::Create(); |
| 2057 layer_tree_host->SetRootLayer(layer); | 2042 layer_tree_host->SetRootLayer(layer); |
| 2058 | 2043 |
| 2059 for (int contents_opaque = 0; contents_opaque < 2; ++contents_opaque) { | 2044 for (int contents_opaque = 0; contents_opaque < 2; ++contents_opaque) { |
| 2060 for (int layer_opaque = 0; layer_opaque < 2; ++layer_opaque) { | 2045 for (int layer_opaque = 0; layer_opaque < 2; ++layer_opaque) { |
| 2061 for (int host_opaque = 0; host_opaque < 2; ++host_opaque) { | 2046 for (int host_opaque = 0; host_opaque < 2; ++host_opaque) { |
| 2062 layer->SetContentsOpaque(!!contents_opaque); | 2047 layer->SetContentsOpaque(!!contents_opaque); |
| 2063 layer->SetBackgroundColor(layer_opaque ? SK_ColorRED | 2048 layer->SetBackgroundColor(layer_opaque ? SK_ColorRED |
| 2064 : SK_ColorTRANSPARENT); | 2049 : SK_ColorTRANSPARENT); |
| 2065 layer_tree_host->set_background_color( | 2050 layer_tree_host->set_background_color( |
| 2066 host_opaque ? SK_ColorRED : SK_ColorTRANSPARENT); | 2051 host_opaque ? SK_ColorRED : SK_ColorTRANSPARENT); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 2077 << "Flags: " << contents_opaque << ", " << layer_opaque << ", " | 2062 << "Flags: " << contents_opaque << ", " << layer_opaque << ", " |
| 2078 << host_opaque << "\n"; | 2063 << host_opaque << "\n"; |
| 2079 } | 2064 } |
| 2080 } | 2065 } |
| 2081 } | 2066 } |
| 2082 } | 2067 } |
| 2083 } | 2068 } |
| 2084 | 2069 |
| 2085 class DrawsContentChangeLayer : public Layer { | 2070 class DrawsContentChangeLayer : public Layer { |
| 2086 public: | 2071 public: |
| 2087 static scoped_refptr<DrawsContentChangeLayer> Create( | 2072 static scoped_refptr<DrawsContentChangeLayer> Create() { |
| 2088 const LayerSettings& settings) { | 2073 return make_scoped_refptr(new DrawsContentChangeLayer()); |
| 2089 return make_scoped_refptr(new DrawsContentChangeLayer(settings)); | |
| 2090 } | 2074 } |
| 2091 | 2075 |
| 2092 void SetLayerTreeHost(LayerTreeHost* host) override { | 2076 void SetLayerTreeHost(LayerTreeHost* host) override { |
| 2093 Layer::SetLayerTreeHost(host); | 2077 Layer::SetLayerTreeHost(host); |
| 2094 SetFakeDrawsContent(!fake_draws_content_); | 2078 SetFakeDrawsContent(!fake_draws_content_); |
| 2095 } | 2079 } |
| 2096 | 2080 |
| 2097 bool HasDrawableContent() const override { | 2081 bool HasDrawableContent() const override { |
| 2098 return fake_draws_content_ && Layer::HasDrawableContent(); | 2082 return fake_draws_content_ && Layer::HasDrawableContent(); |
| 2099 } | 2083 } |
| 2100 | 2084 |
| 2101 void SetFakeDrawsContent(bool fake_draws_content) { | 2085 void SetFakeDrawsContent(bool fake_draws_content) { |
| 2102 fake_draws_content_ = fake_draws_content; | 2086 fake_draws_content_ = fake_draws_content; |
| 2103 UpdateDrawsContent(HasDrawableContent()); | 2087 UpdateDrawsContent(HasDrawableContent()); |
| 2104 } | 2088 } |
| 2105 | 2089 |
| 2106 private: | 2090 private: |
| 2107 explicit DrawsContentChangeLayer(const LayerSettings& settings) | 2091 DrawsContentChangeLayer() : Layer(), fake_draws_content_(false) {} |
| 2108 : Layer(settings), fake_draws_content_(false) {} | |
| 2109 ~DrawsContentChangeLayer() override {} | 2092 ~DrawsContentChangeLayer() override {} |
| 2110 | 2093 |
| 2111 bool fake_draws_content_; | 2094 bool fake_draws_content_; |
| 2112 }; | 2095 }; |
| 2113 | 2096 |
| 2114 TEST_F(LayerTest, DrawsContentChangedInSetLayerTreeHost) { | 2097 TEST_F(LayerTest, DrawsContentChangedInSetLayerTreeHost) { |
| 2115 scoped_refptr<Layer> root_layer = Layer::Create(layer_settings_); | 2098 scoped_refptr<Layer> root_layer = Layer::Create(); |
| 2116 scoped_refptr<DrawsContentChangeLayer> becomes_not_draws_content = | 2099 scoped_refptr<DrawsContentChangeLayer> becomes_not_draws_content = |
| 2117 DrawsContentChangeLayer::Create(layer_settings_); | 2100 DrawsContentChangeLayer::Create(); |
| 2118 scoped_refptr<DrawsContentChangeLayer> becomes_draws_content = | 2101 scoped_refptr<DrawsContentChangeLayer> becomes_draws_content = |
| 2119 DrawsContentChangeLayer::Create(layer_settings_); | 2102 DrawsContentChangeLayer::Create(); |
| 2120 root_layer->SetIsDrawable(true); | 2103 root_layer->SetIsDrawable(true); |
| 2121 becomes_not_draws_content->SetIsDrawable(true); | 2104 becomes_not_draws_content->SetIsDrawable(true); |
| 2122 becomes_not_draws_content->SetFakeDrawsContent(true); | 2105 becomes_not_draws_content->SetFakeDrawsContent(true); |
| 2123 EXPECT_EQ(0, root_layer->NumDescendantsThatDrawContent()); | 2106 EXPECT_EQ(0, root_layer->NumDescendantsThatDrawContent()); |
| 2124 root_layer->AddChild(becomes_not_draws_content); | 2107 root_layer->AddChild(becomes_not_draws_content); |
| 2125 EXPECT_EQ(0, root_layer->NumDescendantsThatDrawContent()); | 2108 EXPECT_EQ(0, root_layer->NumDescendantsThatDrawContent()); |
| 2126 | 2109 |
| 2127 becomes_draws_content->SetIsDrawable(true); | 2110 becomes_draws_content->SetIsDrawable(true); |
| 2128 root_layer->AddChild(becomes_draws_content); | 2111 root_layer->AddChild(becomes_draws_content); |
| 2129 EXPECT_EQ(1, root_layer->NumDescendantsThatDrawContent()); | 2112 EXPECT_EQ(1, root_layer->NumDescendantsThatDrawContent()); |
| 2130 } | 2113 } |
| 2131 | 2114 |
| 2132 void ReceiveCopyOutputResult(int* result_count, | 2115 void ReceiveCopyOutputResult(int* result_count, |
| 2133 scoped_ptr<CopyOutputResult> result) { | 2116 scoped_ptr<CopyOutputResult> result) { |
| 2134 ++(*result_count); | 2117 ++(*result_count); |
| 2135 } | 2118 } |
| 2136 | 2119 |
| 2137 TEST_F(LayerTest, DedupesCopyOutputRequestsBySource) { | 2120 TEST_F(LayerTest, DedupesCopyOutputRequestsBySource) { |
| 2138 scoped_refptr<Layer> layer = Layer::Create(layer_settings_); | 2121 scoped_refptr<Layer> layer = Layer::Create(); |
| 2139 int result_count = 0; | 2122 int result_count = 0; |
| 2140 | 2123 |
| 2141 // Create identical requests without the source being set, and expect the | 2124 // Create identical requests without the source being set, and expect the |
| 2142 // layer does not abort either one. | 2125 // layer does not abort either one. |
| 2143 scoped_ptr<CopyOutputRequest> request = CopyOutputRequest::CreateRequest( | 2126 scoped_ptr<CopyOutputRequest> request = CopyOutputRequest::CreateRequest( |
| 2144 base::Bind(&ReceiveCopyOutputResult, &result_count)); | 2127 base::Bind(&ReceiveCopyOutputResult, &result_count)); |
| 2145 layer->RequestCopyOfOutput(std::move(request)); | 2128 layer->RequestCopyOfOutput(std::move(request)); |
| 2146 EXPECT_EQ(0, result_count); | 2129 EXPECT_EQ(0, result_count); |
| 2147 request = CopyOutputRequest::CreateRequest( | 2130 request = CopyOutputRequest::CreateRequest( |
| 2148 base::Bind(&ReceiveCopyOutputResult, &result_count)); | 2131 base::Bind(&ReceiveCopyOutputResult, &result_count)); |
| 2149 layer->RequestCopyOfOutput(std::move(request)); | 2132 layer->RequestCopyOfOutput(std::move(request)); |
| 2150 EXPECT_EQ(0, result_count); | 2133 EXPECT_EQ(0, result_count); |
| 2151 | 2134 |
| 2152 // When the layer is destroyed, expect both requests to be aborted. | 2135 // When the layer is destroyed, expect both requests to be aborted. |
| 2153 layer = nullptr; | 2136 layer = nullptr; |
| 2154 EXPECT_EQ(2, result_count); | 2137 EXPECT_EQ(2, result_count); |
| 2155 | 2138 |
| 2156 layer = Layer::Create(layer_settings_); | 2139 layer = Layer::Create(); |
| 2157 result_count = 0; | 2140 result_count = 0; |
| 2158 | 2141 |
| 2159 // Create identical requests, but this time the source is being set. Expect | 2142 // Create identical requests, but this time the source is being set. Expect |
| 2160 // the first request from |this| source aborts immediately when the second | 2143 // the first request from |this| source aborts immediately when the second |
| 2161 // request from |this| source is made. | 2144 // request from |this| source is made. |
| 2162 int did_receive_first_result_from_this_source = 0; | 2145 int did_receive_first_result_from_this_source = 0; |
| 2163 request = CopyOutputRequest::CreateRequest(base::Bind( | 2146 request = CopyOutputRequest::CreateRequest(base::Bind( |
| 2164 &ReceiveCopyOutputResult, &did_receive_first_result_from_this_source)); | 2147 &ReceiveCopyOutputResult, &did_receive_first_result_from_this_source)); |
| 2165 request->set_source(this); | 2148 request->set_source(this); |
| 2166 layer->RequestCopyOfOutput(std::move(request)); | 2149 layer->RequestCopyOfOutput(std::move(request)); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 2192 | 2175 |
| 2193 // When the layer is destroyed, the other three requests should be aborted. | 2176 // When the layer is destroyed, the other three requests should be aborted. |
| 2194 layer = nullptr; | 2177 layer = nullptr; |
| 2195 EXPECT_EQ(1, did_receive_first_result_from_this_source); | 2178 EXPECT_EQ(1, did_receive_first_result_from_this_source); |
| 2196 EXPECT_EQ(1, did_receive_result_from_different_source); | 2179 EXPECT_EQ(1, did_receive_result_from_different_source); |
| 2197 EXPECT_EQ(1, did_receive_result_from_anonymous_source); | 2180 EXPECT_EQ(1, did_receive_result_from_anonymous_source); |
| 2198 EXPECT_EQ(1, did_receive_second_result_from_this_source); | 2181 EXPECT_EQ(1, did_receive_second_result_from_this_source); |
| 2199 } | 2182 } |
| 2200 | 2183 |
| 2201 TEST_F(LayerTest, AnimationSchedulesLayerUpdate) { | 2184 TEST_F(LayerTest, AnimationSchedulesLayerUpdate) { |
| 2202 scoped_refptr<Layer> layer = Layer::Create(layer_settings_); | 2185 scoped_refptr<Layer> layer = Layer::Create(); |
| 2203 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, layer_tree_host_->SetRootLayer(layer)); | 2186 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, layer_tree_host_->SetRootLayer(layer)); |
| 2204 | 2187 |
| 2205 EXPECT_CALL(*layer_tree_host_, SetNeedsUpdateLayers()).Times(1); | 2188 EXPECT_CALL(*layer_tree_host_, SetNeedsUpdateLayers()).Times(1); |
| 2206 layer->OnOpacityAnimated(0.5f); | 2189 layer->OnOpacityAnimated(0.5f); |
| 2207 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); | 2190 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); |
| 2208 | 2191 |
| 2209 EXPECT_CALL(*layer_tree_host_, SetNeedsUpdateLayers()).Times(1); | 2192 EXPECT_CALL(*layer_tree_host_, SetNeedsUpdateLayers()).Times(1); |
| 2210 gfx::Transform transform; | 2193 gfx::Transform transform; |
| 2211 transform.Rotate(45.0); | 2194 transform.Rotate(45.0); |
| 2212 layer->OnTransformAnimated(transform); | 2195 layer->OnTransformAnimated(transform); |
| 2213 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); | 2196 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); |
| 2214 | 2197 |
| 2215 // Scroll offset animation should not schedule a layer update since it is | 2198 // Scroll offset animation should not schedule a layer update since it is |
| 2216 // handled similarly to normal compositor scroll updates. | 2199 // handled similarly to normal compositor scroll updates. |
| 2217 EXPECT_CALL(*layer_tree_host_, SetNeedsUpdateLayers()).Times(0); | 2200 EXPECT_CALL(*layer_tree_host_, SetNeedsUpdateLayers()).Times(0); |
| 2218 layer->OnScrollOffsetAnimated(gfx::ScrollOffset(10, 10)); | 2201 layer->OnScrollOffsetAnimated(gfx::ScrollOffset(10, 10)); |
| 2219 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); | 2202 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); |
| 2220 } | 2203 } |
| 2221 | 2204 |
| 2222 TEST_F(LayerTest, RecursiveHierarchySerialization) { | 2205 TEST_F(LayerTest, RecursiveHierarchySerialization) { |
| 2223 /* Testing serialization and deserialization of a tree that looks like this: | 2206 /* Testing serialization and deserialization of a tree that looks like this: |
| 2224 root | 2207 root |
| 2225 / \ | 2208 / \ |
| 2226 a b | 2209 a b |
| 2227 \ | 2210 \ |
| 2228 c | 2211 c |
| 2229 Layer c also has a mask layer and a replica layer. | 2212 Layer c also has a mask layer and a replica layer. |
| 2230 */ | 2213 */ |
| 2231 scoped_refptr<Layer> layer_src_root = Layer::Create(LayerSettings()); | 2214 scoped_refptr<Layer> layer_src_root = Layer::Create(); |
| 2232 scoped_refptr<Layer> layer_src_a = Layer::Create(LayerSettings()); | 2215 scoped_refptr<Layer> layer_src_a = Layer::Create(); |
| 2233 scoped_refptr<Layer> layer_src_b = Layer::Create(LayerSettings()); | 2216 scoped_refptr<Layer> layer_src_b = Layer::Create(); |
| 2234 scoped_refptr<Layer> layer_src_c = Layer::Create(LayerSettings()); | 2217 scoped_refptr<Layer> layer_src_c = Layer::Create(); |
| 2235 scoped_refptr<Layer> layer_src_c_mask = Layer::Create(LayerSettings()); | 2218 scoped_refptr<Layer> layer_src_c_mask = Layer::Create(); |
| 2236 scoped_refptr<Layer> layer_src_c_replica = Layer::Create(LayerSettings()); | 2219 scoped_refptr<Layer> layer_src_c_replica = Layer::Create(); |
| 2237 layer_src_root->AddChild(layer_src_a); | 2220 layer_src_root->AddChild(layer_src_a); |
| 2238 layer_src_root->AddChild(layer_src_b); | 2221 layer_src_root->AddChild(layer_src_b); |
| 2239 layer_src_b->AddChild(layer_src_c); | 2222 layer_src_b->AddChild(layer_src_c); |
| 2240 layer_src_c->SetMaskLayer(layer_src_c_mask.get()); | 2223 layer_src_c->SetMaskLayer(layer_src_c_mask.get()); |
| 2241 layer_src_c->SetReplicaLayer(layer_src_c_replica.get()); | 2224 layer_src_c->SetReplicaLayer(layer_src_c_replica.get()); |
| 2242 | 2225 |
| 2243 proto::LayerNode proto; | 2226 proto::LayerNode proto; |
| 2244 layer_src_root->ToLayerNodeProto(&proto); | 2227 layer_src_root->ToLayerNodeProto(&proto); |
| 2245 | 2228 |
| 2246 Layer::LayerIdMap empty_dest_layer_map; | 2229 Layer::LayerIdMap empty_dest_layer_map; |
| 2247 scoped_refptr<Layer> layer_dest_root = Layer::Create(LayerSettings()); | 2230 scoped_refptr<Layer> layer_dest_root = Layer::Create(); |
| 2248 layer_dest_root->FromLayerNodeProto(proto, empty_dest_layer_map); | 2231 layer_dest_root->FromLayerNodeProto(proto, empty_dest_layer_map); |
| 2249 | 2232 |
| 2250 EXPECT_EQ(layer_src_root->id(), layer_dest_root->id()); | 2233 EXPECT_EQ(layer_src_root->id(), layer_dest_root->id()); |
| 2251 EXPECT_EQ(nullptr, layer_dest_root->parent()); | 2234 EXPECT_EQ(nullptr, layer_dest_root->parent()); |
| 2252 ASSERT_EQ(2u, layer_dest_root->children().size()); | 2235 ASSERT_EQ(2u, layer_dest_root->children().size()); |
| 2253 | 2236 |
| 2254 scoped_refptr<Layer> layer_dest_a = layer_dest_root->children()[0]; | 2237 scoped_refptr<Layer> layer_dest_a = layer_dest_root->children()[0]; |
| 2255 EXPECT_EQ(layer_src_a->id(), layer_dest_a->id()); | 2238 EXPECT_EQ(layer_src_a->id(), layer_dest_a->id()); |
| 2256 EXPECT_EQ(layer_src_root->id(), layer_dest_a->parent()->id()); | 2239 EXPECT_EQ(layer_src_root->id(), layer_dest_a->parent()->id()); |
| 2257 EXPECT_EQ(0u, layer_dest_a->children().size()); | 2240 EXPECT_EQ(0u, layer_dest_a->children().size()); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 2275 root | 2258 root |
| 2276 / | 2259 / |
| 2277 a | 2260 a |
| 2278 The source tree is then updated by adding layer |b|: | 2261 The source tree is then updated by adding layer |b|: |
| 2279 root | 2262 root |
| 2280 / \ | 2263 / \ |
| 2281 a b | 2264 a b |
| 2282 The deserialization should then re-use the Layers from last | 2265 The deserialization should then re-use the Layers from last |
| 2283 deserialization. | 2266 deserialization. |
| 2284 */ | 2267 */ |
| 2285 scoped_refptr<Layer> layer_src_root = Layer::Create(LayerSettings()); | 2268 scoped_refptr<Layer> layer_src_root = Layer::Create(); |
| 2286 scoped_refptr<Layer> layer_src_a = Layer::Create(LayerSettings()); | 2269 scoped_refptr<Layer> layer_src_a = Layer::Create(); |
| 2287 layer_src_root->AddChild(layer_src_a); | 2270 layer_src_root->AddChild(layer_src_a); |
| 2288 | 2271 |
| 2289 proto::LayerNode root_proto_1; | 2272 proto::LayerNode root_proto_1; |
| 2290 layer_src_root->ToLayerNodeProto(&root_proto_1); | 2273 layer_src_root->ToLayerNodeProto(&root_proto_1); |
| 2291 | 2274 |
| 2292 Layer::LayerIdMap dest_layer_map_1; | 2275 Layer::LayerIdMap dest_layer_map_1; |
| 2293 scoped_refptr<Layer> layer_dest_root = Layer::Create(LayerSettings()); | 2276 scoped_refptr<Layer> layer_dest_root = Layer::Create(); |
| 2294 layer_dest_root->FromLayerNodeProto(root_proto_1, dest_layer_map_1); | 2277 layer_dest_root->FromLayerNodeProto(root_proto_1, dest_layer_map_1); |
| 2295 | 2278 |
| 2296 EXPECT_EQ(layer_src_root->id(), layer_dest_root->id()); | 2279 EXPECT_EQ(layer_src_root->id(), layer_dest_root->id()); |
| 2297 ASSERT_EQ(1u, layer_dest_root->children().size()); | 2280 ASSERT_EQ(1u, layer_dest_root->children().size()); |
| 2298 scoped_refptr<Layer> layer_dest_a_1 = layer_dest_root->children()[0]; | 2281 scoped_refptr<Layer> layer_dest_a_1 = layer_dest_root->children()[0]; |
| 2299 EXPECT_EQ(layer_src_a->id(), layer_dest_a_1->id()); | 2282 EXPECT_EQ(layer_src_a->id(), layer_dest_a_1->id()); |
| 2300 | 2283 |
| 2301 // Setup new destination layer map. | 2284 // Setup new destination layer map. |
| 2302 Layer::LayerIdMap dest_layer_map_2; | 2285 Layer::LayerIdMap dest_layer_map_2; |
| 2303 dest_layer_map_2[layer_dest_root->id()] = layer_dest_root; | 2286 dest_layer_map_2[layer_dest_root->id()] = layer_dest_root; |
| 2304 dest_layer_map_2[layer_dest_a_1->id()] = layer_dest_a_1; | 2287 dest_layer_map_2[layer_dest_a_1->id()] = layer_dest_a_1; |
| 2305 | 2288 |
| 2306 // Add Layer |b|. | 2289 // Add Layer |b|. |
| 2307 scoped_refptr<Layer> layer_src_b = Layer::Create(LayerSettings()); | 2290 scoped_refptr<Layer> layer_src_b = Layer::Create(); |
| 2308 layer_src_root->AddChild(layer_src_b); | 2291 layer_src_root->AddChild(layer_src_b); |
| 2309 | 2292 |
| 2310 // Second serialization. | 2293 // Second serialization. |
| 2311 proto::LayerNode root_proto_2; | 2294 proto::LayerNode root_proto_2; |
| 2312 layer_src_root->ToLayerNodeProto(&root_proto_2); | 2295 layer_src_root->ToLayerNodeProto(&root_proto_2); |
| 2313 | 2296 |
| 2314 // Second deserialization. | 2297 // Second deserialization. |
| 2315 layer_dest_root->FromLayerNodeProto(root_proto_2, dest_layer_map_2); | 2298 layer_dest_root->FromLayerNodeProto(root_proto_2, dest_layer_map_2); |
| 2316 | 2299 |
| 2317 EXPECT_EQ(layer_src_root->id(), layer_dest_root->id()); | 2300 EXPECT_EQ(layer_src_root->id(), layer_dest_root->id()); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 2336 looks like this: | 2319 looks like this: |
| 2337 root | 2320 root |
| 2338 / \ | 2321 / \ |
| 2339 a b | 2322 a b |
| 2340 \ | 2323 \ |
| 2341 c | 2324 c |
| 2342 \ | 2325 \ |
| 2343 d | 2326 d |
| 2344 Then the subtree rooted at node |b| is deleted in the next update. | 2327 Then the subtree rooted at node |b| is deleted in the next update. |
| 2345 */ | 2328 */ |
| 2346 scoped_refptr<Layer> layer_src_root = Layer::Create(LayerSettings()); | 2329 scoped_refptr<Layer> layer_src_root = Layer::Create(); |
| 2347 scoped_refptr<Layer> layer_src_a = Layer::Create(LayerSettings()); | 2330 scoped_refptr<Layer> layer_src_a = Layer::Create(); |
| 2348 scoped_refptr<Layer> layer_src_b = Layer::Create(LayerSettings()); | 2331 scoped_refptr<Layer> layer_src_b = Layer::Create(); |
| 2349 scoped_refptr<Layer> layer_src_c = Layer::Create(LayerSettings()); | 2332 scoped_refptr<Layer> layer_src_c = Layer::Create(); |
| 2350 scoped_refptr<Layer> layer_src_d = Layer::Create(LayerSettings()); | 2333 scoped_refptr<Layer> layer_src_d = Layer::Create(); |
| 2351 layer_src_root->AddChild(layer_src_a); | 2334 layer_src_root->AddChild(layer_src_a); |
| 2352 layer_src_root->AddChild(layer_src_b); | 2335 layer_src_root->AddChild(layer_src_b); |
| 2353 layer_src_b->AddChild(layer_src_c); | 2336 layer_src_b->AddChild(layer_src_c); |
| 2354 layer_src_c->AddChild(layer_src_d); | 2337 layer_src_c->AddChild(layer_src_d); |
| 2355 | 2338 |
| 2356 // Serialization 1. | 2339 // Serialization 1. |
| 2357 proto::LayerNode proto1; | 2340 proto::LayerNode proto1; |
| 2358 layer_src_root->ToLayerNodeProto(&proto1); | 2341 layer_src_root->ToLayerNodeProto(&proto1); |
| 2359 | 2342 |
| 2360 // Deserialization 1. | 2343 // Deserialization 1. |
| 2361 Layer::LayerIdMap empty_dest_layer_map; | 2344 Layer::LayerIdMap empty_dest_layer_map; |
| 2362 scoped_refptr<Layer> layer_dest_root = Layer::Create(LayerSettings()); | 2345 scoped_refptr<Layer> layer_dest_root = Layer::Create(); |
| 2363 layer_dest_root->FromLayerNodeProto(proto1, empty_dest_layer_map); | 2346 layer_dest_root->FromLayerNodeProto(proto1, empty_dest_layer_map); |
| 2364 | 2347 |
| 2365 EXPECT_EQ(layer_src_root->id(), layer_dest_root->id()); | 2348 EXPECT_EQ(layer_src_root->id(), layer_dest_root->id()); |
| 2366 ASSERT_EQ(2u, layer_dest_root->children().size()); | 2349 ASSERT_EQ(2u, layer_dest_root->children().size()); |
| 2367 scoped_refptr<Layer> layer_dest_a = layer_dest_root->children()[0]; | 2350 scoped_refptr<Layer> layer_dest_a = layer_dest_root->children()[0]; |
| 2368 scoped_refptr<Layer> layer_dest_b = layer_dest_root->children()[1]; | 2351 scoped_refptr<Layer> layer_dest_b = layer_dest_root->children()[1]; |
| 2369 ASSERT_EQ(1u, layer_dest_b->children().size()); | 2352 ASSERT_EQ(1u, layer_dest_b->children().size()); |
| 2370 scoped_refptr<Layer> layer_dest_c = layer_dest_b->children()[0]; | 2353 scoped_refptr<Layer> layer_dest_c = layer_dest_b->children()[0]; |
| 2371 ASSERT_EQ(1u, layer_dest_c->children().size()); | 2354 ASSERT_EQ(1u, layer_dest_c->children().size()); |
| 2372 scoped_refptr<Layer> layer_dest_d = layer_dest_c->children()[0]; | 2355 scoped_refptr<Layer> layer_dest_d = layer_dest_c->children()[0]; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 2383 dest_layer_map_2[layer_dest_root->id()] = layer_dest_root; | 2366 dest_layer_map_2[layer_dest_root->id()] = layer_dest_root; |
| 2384 dest_layer_map_2[layer_dest_a->id()] = layer_dest_a; | 2367 dest_layer_map_2[layer_dest_a->id()] = layer_dest_a; |
| 2385 dest_layer_map_2[layer_dest_b->id()] = layer_dest_b; | 2368 dest_layer_map_2[layer_dest_b->id()] = layer_dest_b; |
| 2386 layer_dest_root->FromLayerNodeProto(proto2, dest_layer_map_2); | 2369 layer_dest_root->FromLayerNodeProto(proto2, dest_layer_map_2); |
| 2387 | 2370 |
| 2388 EXPECT_EQ(0u, layer_dest_a->children().size()); | 2371 EXPECT_EQ(0u, layer_dest_a->children().size()); |
| 2389 EXPECT_EQ(0u, layer_dest_b->children().size()); | 2372 EXPECT_EQ(0u, layer_dest_b->children().size()); |
| 2390 } | 2373 } |
| 2391 | 2374 |
| 2392 TEST_F(LayerTest, DeleteMaskAndReplicaLayer) { | 2375 TEST_F(LayerTest, DeleteMaskAndReplicaLayer) { |
| 2393 scoped_refptr<Layer> layer_src_root = Layer::Create(LayerSettings()); | 2376 scoped_refptr<Layer> layer_src_root = Layer::Create(); |
| 2394 scoped_refptr<Layer> layer_src_mask = Layer::Create(LayerSettings()); | 2377 scoped_refptr<Layer> layer_src_mask = Layer::Create(); |
| 2395 scoped_refptr<Layer> layer_src_replica = Layer::Create(LayerSettings()); | 2378 scoped_refptr<Layer> layer_src_replica = Layer::Create(); |
| 2396 layer_src_root->SetMaskLayer(layer_src_mask.get()); | 2379 layer_src_root->SetMaskLayer(layer_src_mask.get()); |
| 2397 layer_src_root->SetReplicaLayer(layer_src_replica.get()); | 2380 layer_src_root->SetReplicaLayer(layer_src_replica.get()); |
| 2398 | 2381 |
| 2399 // Serialization 1. | 2382 // Serialization 1. |
| 2400 proto::LayerNode proto1; | 2383 proto::LayerNode proto1; |
| 2401 layer_src_root->ToLayerNodeProto(&proto1); | 2384 layer_src_root->ToLayerNodeProto(&proto1); |
| 2402 | 2385 |
| 2403 // Deserialization 1. | 2386 // Deserialization 1. |
| 2404 Layer::LayerIdMap dest_layer_map; | 2387 Layer::LayerIdMap dest_layer_map; |
| 2405 scoped_refptr<Layer> layer_dest_root = Layer::Create(LayerSettings()); | 2388 scoped_refptr<Layer> layer_dest_root = Layer::Create(); |
| 2406 layer_dest_root->FromLayerNodeProto(proto1, dest_layer_map); | 2389 layer_dest_root->FromLayerNodeProto(proto1, dest_layer_map); |
| 2407 | 2390 |
| 2408 EXPECT_EQ(layer_src_root->id(), layer_dest_root->id()); | 2391 EXPECT_EQ(layer_src_root->id(), layer_dest_root->id()); |
| 2409 ASSERT_TRUE(layer_dest_root->mask_layer()); | 2392 ASSERT_TRUE(layer_dest_root->mask_layer()); |
| 2410 ASSERT_TRUE(layer_dest_root->replica_layer()); | 2393 ASSERT_TRUE(layer_dest_root->replica_layer()); |
| 2411 EXPECT_EQ(layer_src_root->mask_layer()->id(), | 2394 EXPECT_EQ(layer_src_root->mask_layer()->id(), |
| 2412 layer_dest_root->mask_layer()->id()); | 2395 layer_dest_root->mask_layer()->id()); |
| 2413 // TODO(nyquist): Add test for is_mask_ when PictureLayer is supported. | 2396 // TODO(nyquist): Add test for is_mask_ when PictureLayer is supported. |
| 2414 EXPECT_EQ(layer_src_root->replica_layer()->id(), | 2397 EXPECT_EQ(layer_src_root->replica_layer()->id(), |
| 2415 layer_dest_root->replica_layer()->id()); | 2398 layer_dest_root->replica_layer()->id()); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2470 /* Testing serialization of properties for a tree that looks like this: | 2453 /* Testing serialization of properties for a tree that looks like this: |
| 2471 root+ | 2454 root+ |
| 2472 / \ | 2455 / \ |
| 2473 a* b*+[mask:*,replica] | 2456 a* b*+[mask:*,replica] |
| 2474 / \ | 2457 / \ |
| 2475 c d* | 2458 c d* |
| 2476 Layers marked with * have changed properties. | 2459 Layers marked with * have changed properties. |
| 2477 Layers marked with + have descendants with changed properties. | 2460 Layers marked with + have descendants with changed properties. |
| 2478 Layer b also has a mask layer and a replica layer. | 2461 Layer b also has a mask layer and a replica layer. |
| 2479 */ | 2462 */ |
| 2480 scoped_refptr<Layer> layer_src_root = Layer::Create(LayerSettings()); | 2463 scoped_refptr<Layer> layer_src_root = Layer::Create(); |
| 2481 scoped_refptr<Layer> layer_src_a = Layer::Create(LayerSettings()); | 2464 scoped_refptr<Layer> layer_src_a = Layer::Create(); |
| 2482 scoped_refptr<Layer> layer_src_b = Layer::Create(LayerSettings()); | 2465 scoped_refptr<Layer> layer_src_b = Layer::Create(); |
| 2483 scoped_refptr<Layer> layer_src_b_mask = Layer::Create(LayerSettings()); | 2466 scoped_refptr<Layer> layer_src_b_mask = Layer::Create(); |
| 2484 scoped_refptr<Layer> layer_src_b_replica = Layer::Create(LayerSettings()); | 2467 scoped_refptr<Layer> layer_src_b_replica = Layer::Create(); |
| 2485 scoped_refptr<Layer> layer_src_c = Layer::Create(LayerSettings()); | 2468 scoped_refptr<Layer> layer_src_c = Layer::Create(); |
| 2486 scoped_refptr<Layer> layer_src_d = Layer::Create(LayerSettings()); | 2469 scoped_refptr<Layer> layer_src_d = Layer::Create(); |
| 2487 layer_src_root->AddChild(layer_src_a); | 2470 layer_src_root->AddChild(layer_src_a); |
| 2488 layer_src_root->AddChild(layer_src_b); | 2471 layer_src_root->AddChild(layer_src_b); |
| 2489 layer_src_a->AddChild(layer_src_c); | 2472 layer_src_a->AddChild(layer_src_c); |
| 2490 layer_src_b->AddChild(layer_src_d); | 2473 layer_src_b->AddChild(layer_src_d); |
| 2491 layer_src_b->SetMaskLayer(layer_src_b_mask.get()); | 2474 layer_src_b->SetMaskLayer(layer_src_b_mask.get()); |
| 2492 layer_src_b->SetReplicaLayer(layer_src_b_replica.get()); | 2475 layer_src_b->SetReplicaLayer(layer_src_b_replica.get()); |
| 2493 | 2476 |
| 2494 proto::LayerUpdate layer_update_root; | 2477 proto::LayerUpdate layer_update_root; |
| 2495 // Only layers with descendants that require pushing properties will | 2478 // Only layers with descendants that require pushing properties will |
| 2496 // return true from ToLayerPropertiesProto and AddChild will change the | 2479 // return true from ToLayerPropertiesProto and AddChild will change the |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2579 EXPECT_TRUE(dest_d.needs_push_properties()); | 2562 EXPECT_TRUE(dest_d.needs_push_properties()); |
| 2580 EXPECT_EQ(0, dest_d.num_dependents_need_push_properties()); | 2563 EXPECT_EQ(0, dest_d.num_dependents_need_push_properties()); |
| 2581 EXPECT_TRUE(dest_d.has_base()); | 2564 EXPECT_TRUE(dest_d.has_base()); |
| 2582 | 2565 |
| 2583 EXPECT_TRUE(dest_b_mask.needs_push_properties()); | 2566 EXPECT_TRUE(dest_b_mask.needs_push_properties()); |
| 2584 EXPECT_EQ(0, dest_b_mask.num_dependents_need_push_properties()); | 2567 EXPECT_EQ(0, dest_b_mask.num_dependents_need_push_properties()); |
| 2585 EXPECT_TRUE(dest_b_mask.has_base()); | 2568 EXPECT_TRUE(dest_b_mask.has_base()); |
| 2586 } | 2569 } |
| 2587 | 2570 |
| 2588 TEST_F(LayerSerializationTest, SimplePropertiesDeserialization) { | 2571 TEST_F(LayerSerializationTest, SimplePropertiesDeserialization) { |
| 2589 scoped_refptr<Layer> layer = Layer::Create(LayerSettings()); | 2572 scoped_refptr<Layer> layer = Layer::Create(); |
| 2590 layer->SetLayerTreeHost(layer_tree_host_.get()); | 2573 layer->SetLayerTreeHost(layer_tree_host_.get()); |
| 2591 proto::LayerProperties properties; | 2574 proto::LayerProperties properties; |
| 2592 properties.set_id(layer->id()); | 2575 properties.set_id(layer->id()); |
| 2593 | 2576 |
| 2594 properties.set_needs_push_properties(true); | 2577 properties.set_needs_push_properties(true); |
| 2595 properties.set_num_dependents_need_push_properties(2); | 2578 properties.set_num_dependents_need_push_properties(2); |
| 2596 properties.mutable_base(); | 2579 properties.mutable_base(); |
| 2597 layer->FromLayerPropertiesProto(properties); | 2580 layer->FromLayerPropertiesProto(properties); |
| 2598 EXPECT_TRUE(layer->needs_push_properties()); | 2581 EXPECT_TRUE(layer->needs_push_properties()); |
| 2599 EXPECT_TRUE(layer->descendant_needs_push_properties()); | 2582 EXPECT_TRUE(layer->descendant_needs_push_properties()); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 2628 | 2611 |
| 2629 TEST_F(LayerSerializationTest, AllMembersChanged) { | 2612 TEST_F(LayerSerializationTest, AllMembersChanged) { |
| 2630 RunAllMembersChangedTest(); | 2613 RunAllMembersChangedTest(); |
| 2631 } | 2614 } |
| 2632 | 2615 |
| 2633 TEST_F(LayerSerializationTest, ScrollAndClipLayers) { | 2616 TEST_F(LayerSerializationTest, ScrollAndClipLayers) { |
| 2634 RunScrollAndClipLayersTest(); | 2617 RunScrollAndClipLayersTest(); |
| 2635 } | 2618 } |
| 2636 | 2619 |
| 2637 TEST_F(LayerTest, ElementIdAndMutablePropertiesArePushed) { | 2620 TEST_F(LayerTest, ElementIdAndMutablePropertiesArePushed) { |
| 2638 scoped_refptr<Layer> test_layer = Layer::Create(layer_settings_); | 2621 scoped_refptr<Layer> test_layer = Layer::Create(); |
| 2639 scoped_ptr<LayerImpl> impl_layer = | 2622 scoped_ptr<LayerImpl> impl_layer = |
| 2640 LayerImpl::Create(host_impl_.active_tree(), 1); | 2623 LayerImpl::Create(host_impl_.active_tree(), 1); |
| 2641 | 2624 |
| 2642 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, | 2625 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, |
| 2643 layer_tree_host_->SetRootLayer(test_layer)); | 2626 layer_tree_host_->SetRootLayer(test_layer)); |
| 2644 | 2627 |
| 2645 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(2); | 2628 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(2); |
| 2646 | 2629 |
| 2647 test_layer->SetElementId(2); | 2630 test_layer->SetElementId(2); |
| 2648 test_layer->SetMutableProperties(MutableProperty::kTransform); | 2631 test_layer->SetMutableProperties(MutableProperty::kTransform); |
| 2649 | 2632 |
| 2650 EXPECT_EQ(0lu, impl_layer->element_id()); | 2633 EXPECT_EQ(0lu, impl_layer->element_id()); |
| 2651 EXPECT_EQ(MutableProperty::kNone, impl_layer->mutable_properties()); | 2634 EXPECT_EQ(MutableProperty::kNone, impl_layer->mutable_properties()); |
| 2652 | 2635 |
| 2653 test_layer->PushPropertiesTo(impl_layer.get()); | 2636 test_layer->PushPropertiesTo(impl_layer.get()); |
| 2654 | 2637 |
| 2655 EXPECT_EQ(2lu, impl_layer->element_id()); | 2638 EXPECT_EQ(2lu, impl_layer->element_id()); |
| 2656 EXPECT_EQ(MutableProperty::kTransform, impl_layer->mutable_properties()); | 2639 EXPECT_EQ(MutableProperty::kTransform, impl_layer->mutable_properties()); |
| 2657 } | 2640 } |
| 2658 | 2641 |
| 2659 } // namespace | 2642 } // namespace |
| 2660 } // namespace cc | 2643 } // namespace cc |
| OLD | NEW |