diff options
author | Allan Sandfeld Jensen <allan.jensen@theqtcompany.com> | 2016-05-09 14:22:11 +0200 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2016-05-09 15:11:45 +0000 |
commit | 2ddb2d3e14eef3de7dbd0cef553d669b9ac2361c (patch) | |
tree | e75f511546c5fd1a173e87c1f9fb11d7ac8d1af3 /chromium/cc/layers/layer_unittest.cc | |
parent | a4f3d46271c57e8155ba912df46a05559d14726e (diff) |
BASELINE: Update Chromium to 51.0.2704.41
Also adds in all smaller components by reversing logic for exclusion.
Change-Id: Ibf90b506e7da088ea2f65dcf23f2b0992c504422
Reviewed-by: Joerg Bornemann <joerg.bornemann@theqtcompany.com>
Diffstat (limited to 'chromium/cc/layers/layer_unittest.cc')
-rw-r--r-- | chromium/cc/layers/layer_unittest.cc | 1494 |
1 files changed, 938 insertions, 556 deletions
diff --git a/chromium/cc/layers/layer_unittest.cc b/chromium/cc/layers/layer_unittest.cc index f73cb2543cc..752757b449a 100644 --- a/chromium/cc/layers/layer_unittest.cc +++ b/chromium/cc/layers/layer_unittest.cc @@ -12,8 +12,8 @@ #include "cc/animation/keyframed_animation_curve.h" #include "cc/animation/mutable_properties.h" #include "cc/base/math_util.h" +#include "cc/input/main_thread_scrolling_reason.h" #include "cc/layers/layer_impl.h" -#include "cc/layers/layer_settings.h" #include "cc/output/copy_output_request.h" #include "cc/output/copy_output_result.h" #include "cc/proto/layer.pb.h" @@ -52,6 +52,33 @@ using ::testing::_; Mock::VerifyAndClearExpectations(layer_tree_host_.get()); \ } while (false) +#define EXECUTE_AND_VERIFY_SUBTREE_CHANGED(code_to_test) \ + code_to_test; \ + root->layer_tree_host()->BuildPropertyTreesForTesting(); \ + EXPECT_TRUE(root->subtree_property_changed()); \ + EXPECT_TRUE(root->layer_tree_host()->LayerNeedsPushPropertiesForTesting( \ + root.get())); \ + EXPECT_TRUE(child->subtree_property_changed()); \ + EXPECT_TRUE(child->layer_tree_host()->LayerNeedsPushPropertiesForTesting( \ + child.get())); \ + EXPECT_TRUE(grand_child->subtree_property_changed()); \ + EXPECT_TRUE( \ + grand_child->layer_tree_host()->LayerNeedsPushPropertiesForTesting( \ + grand_child.get())); + +#define EXECUTE_AND_VERIFY_SUBTREE_CHANGES_RESET(code_to_test) \ + code_to_test; \ + EXPECT_FALSE(root->subtree_property_changed()); \ + EXPECT_FALSE(root->layer_tree_host()->LayerNeedsPushPropertiesForTesting( \ + root.get())); \ + EXPECT_FALSE(child->subtree_property_changed()); \ + EXPECT_FALSE(child->layer_tree_host()->LayerNeedsPushPropertiesForTesting( \ + child.get())); \ + EXPECT_FALSE(grand_child->subtree_property_changed()); \ + EXPECT_FALSE( \ + grand_child->layer_tree_host()->LayerNeedsPushPropertiesForTesting( \ + grand_child.get())); + namespace cc { // This class is a friend of Layer, and is used as a wrapper for all the tests @@ -82,16 +109,15 @@ class LayerSerializationTest : public testing::Test { src->SetNeedsPushProperties(); src->SetLayerTreeHost(layer_tree_host_.get()); - // The following two members are reset during serialization, so - // store the original values. - bool stacking_order_changed = src->stacking_order_changed_; + // The following member is reset during serialization, so store the original + // values. gfx::Rect update_rect = src->update_rect_; // Serialize |src| to protobuf and read the first entry in the // LayerUpdate. There are no descendants, so the serialization // of |src| is the only entry. proto::LayerUpdate layer_update; - EXPECT_FALSE(src->ToLayerPropertiesProto(&layer_update)); + src->ToLayerPropertiesProto(&layer_update); ASSERT_EQ(1, layer_update.layers_size()); proto::LayerProperties props = layer_update.layers(0); @@ -112,7 +138,7 @@ class LayerSerializationTest : public testing::Test { // it can be re-used for the |dest| layer. src->SetLayerTreeHost(nullptr); - scoped_refptr<Layer> dest = Layer::Create(LayerSettings()); + scoped_refptr<Layer> dest = Layer::Create(); dest->layer_id_ = src->layer_id_; dest->SetLayerTreeHost(layer_tree_host_.get()); dest->FromLayerPropertiesProto(props); @@ -131,17 +157,12 @@ class LayerSerializationTest : public testing::Test { EXPECT_EQ(src->hide_layer_and_subtree_, dest->hide_layer_and_subtree_); EXPECT_EQ(src->has_render_surface_, dest->has_render_surface_); EXPECT_EQ(src->masks_to_bounds_, dest->masks_to_bounds_); - EXPECT_EQ(src->should_scroll_on_main_thread_, - dest->should_scroll_on_main_thread_); - EXPECT_EQ(src->have_wheel_event_handlers_, - dest->have_wheel_event_handlers_); - EXPECT_EQ(src->have_scroll_event_handlers_, - dest->have_scroll_event_handlers_); + EXPECT_EQ(src->main_thread_scrolling_reasons_, + dest->main_thread_scrolling_reasons_); EXPECT_EQ(src->non_fast_scrollable_region_, dest->non_fast_scrollable_region_); EXPECT_EQ(src->touch_event_handler_region_, dest->touch_event_handler_region_); - EXPECT_EQ(src->scroll_blocks_on_, dest->scroll_blocks_on_); EXPECT_EQ(src->contents_opaque_, dest->contents_opaque_); EXPECT_EQ(src->opacity_, dest->opacity_); EXPECT_EQ(src->blend_mode_, dest->blend_mode_); @@ -167,10 +188,7 @@ class LayerSerializationTest : public testing::Test { dest->user_scrollable_horizontal_); EXPECT_EQ(src->user_scrollable_vertical_, dest->user_scrollable_vertical_); EXPECT_EQ(src->scroll_offset_, dest->scroll_offset_); - EXPECT_EQ(src->scroll_compensation_adjustment_, - dest->scroll_compensation_adjustment_); EXPECT_EQ(update_rect, dest->update_rect_); - EXPECT_EQ(stacking_order_changed, dest->stacking_order_changed_); if (src->scroll_parent_) { ASSERT_TRUE(dest->scroll_parent_); @@ -198,8 +216,7 @@ class LayerSerializationTest : public testing::Test { EXPECT_FALSE(dest->clip_children_); } - // The following two members should have been reset during serialization. - EXPECT_FALSE(src->stacking_order_changed_); + // The following member should have been reset during serialization. EXPECT_EQ(gfx::Rect(), src->update_rect_); // Before deleting |dest|, the LayerTreeHost must be unset. @@ -231,12 +248,12 @@ class LayerSerializationTest : public testing::Test { } void RunNoMembersChangedTest() { - scoped_refptr<Layer> layer = Layer::Create(LayerSettings()); + scoped_refptr<Layer> layer = Layer::Create(); VerifyBaseLayerPropertiesSerializationAndDeserialization(layer.get()); } void RunArbitraryMembersChangedTest() { - scoped_refptr<Layer> layer = Layer::Create(LayerSettings()); + scoped_refptr<Layer> layer = Layer::Create(); layer->transform_origin_ = gfx::Point3F(3.0f, 1.0f, 4.0f); layer->background_color_ = SK_ColorRED; layer->bounds_ = gfx::Size(3, 14); @@ -249,12 +266,10 @@ class LayerSerializationTest : public testing::Test { layer->hide_layer_and_subtree_ = false; layer->has_render_surface_ = false; layer->masks_to_bounds_ = true; - layer->should_scroll_on_main_thread_ = false; - layer->have_wheel_event_handlers_ = true; - layer->have_scroll_event_handlers_ = false; + layer->main_thread_scrolling_reasons_ = + MainThreadScrollingReason::kNotScrollingOnMain; layer->non_fast_scrollable_region_ = Region(gfx::Rect(5, 1, 14, 3)); layer->touch_event_handler_region_ = Region(gfx::Rect(3, 14, 1, 5)); - layer->scroll_blocks_on_ = SCROLL_BLOCKS_ON_NONE; layer->contents_opaque_ = true; layer->opacity_ = 1.f; layer->blend_mode_ = SkXfermode::kSrcOver_Mode; @@ -278,15 +293,13 @@ class LayerSerializationTest : public testing::Test { layer->user_scrollable_horizontal_ = false; layer->user_scrollable_vertical_ = true; layer->scroll_offset_ = gfx::ScrollOffset(3, 14); - layer->scroll_compensation_adjustment_ = gfx::Vector2dF(6.28f, 3.14f); layer->update_rect_ = gfx::Rect(14, 15); - layer->stacking_order_changed_ = true; VerifyBaseLayerPropertiesSerializationAndDeserialization(layer.get()); } void RunAllMembersChangedTest() { - scoped_refptr<Layer> layer = Layer::Create(LayerSettings()); + scoped_refptr<Layer> layer = Layer::Create(); layer->transform_origin_ = gfx::Point3F(3.0f, 1.0f, 4.0f); layer->background_color_ = SK_ColorRED; layer->bounds_ = gfx::Size(3, 14); @@ -299,13 +312,10 @@ class LayerSerializationTest : public testing::Test { layer->hide_layer_and_subtree_ = !layer->hide_layer_and_subtree_; layer->has_render_surface_ = !layer->has_render_surface_; layer->masks_to_bounds_ = !layer->masks_to_bounds_; - layer->should_scroll_on_main_thread_ = - !layer->should_scroll_on_main_thread_; - layer->have_wheel_event_handlers_ = !layer->have_wheel_event_handlers_; - layer->have_scroll_event_handlers_ = !layer->have_scroll_event_handlers_; + layer->main_thread_scrolling_reasons_ = + MainThreadScrollingReason::kHasBackgroundAttachmentFixedObjects; layer->non_fast_scrollable_region_ = Region(gfx::Rect(5, 1, 14, 3)); layer->touch_event_handler_region_ = Region(gfx::Rect(3, 14, 1, 5)); - layer->scroll_blocks_on_ = SCROLL_BLOCKS_ON_WHEEL_EVENT; layer->contents_opaque_ = !layer->contents_opaque_; layer->opacity_ = 3.14f; layer->blend_mode_ = SkXfermode::kSrcIn_Mode; @@ -332,33 +342,478 @@ class LayerSerializationTest : public testing::Test { layer->user_scrollable_horizontal_ = !layer->user_scrollable_horizontal_; layer->user_scrollable_vertical_ = !layer->user_scrollable_vertical_; layer->scroll_offset_ = gfx::ScrollOffset(3, 14); - layer->scroll_compensation_adjustment_ = gfx::Vector2dF(6.28f, 3.14f); layer->update_rect_ = gfx::Rect(14, 15); - layer->stacking_order_changed_ = !layer->stacking_order_changed_; VerifyBaseLayerPropertiesSerializationAndDeserialization(layer.get()); } void RunScrollAndClipLayersTest() { - scoped_refptr<Layer> layer = Layer::Create(LayerSettings()); + scoped_refptr<Layer> layer = Layer::Create(); - scoped_refptr<Layer> scroll_parent = Layer::Create(LayerSettings()); + scoped_refptr<Layer> scroll_parent = Layer::Create(); layer->scroll_parent_ = scroll_parent.get(); - scoped_refptr<Layer> scroll_child = Layer::Create(LayerSettings()); + scoped_refptr<Layer> scroll_child = Layer::Create(); layer->scroll_children_.reset(new std::set<Layer*>); layer->scroll_children_->insert(scroll_child.get()); - scoped_refptr<Layer> clip_parent = Layer::Create(LayerSettings()); + scoped_refptr<Layer> clip_parent = Layer::Create(); layer->clip_parent_ = clip_parent.get(); layer->clip_children_.reset(new std::set<Layer*>); - scoped_refptr<Layer> clip_child1 = Layer::Create(LayerSettings()); + scoped_refptr<Layer> clip_child1 = Layer::Create(); layer->clip_children_->insert(clip_child1.get()); - scoped_refptr<Layer> clip_child2 = Layer::Create(LayerSettings()); + scoped_refptr<Layer> clip_child2 = Layer::Create(); layer->clip_children_->insert(clip_child2.get()); VerifyBaseLayerPropertiesSerializationAndDeserialization(layer.get()); } + void RunHierarchyDeserializationWithLayerTreeHostTest() { + /* Testing serialization and deserialization of a tree that looks like this: + root + \ + a + \ + b + \ + c + The root layer has a LayerTreeHost, and it should propagate to all the + children. + */ + scoped_refptr<Layer> layer_src_root = Layer::Create(); + scoped_refptr<Layer> layer_src_a = Layer::Create(); + scoped_refptr<Layer> layer_src_b = Layer::Create(); + scoped_refptr<Layer> layer_src_c = Layer::Create(); + layer_src_root->AddChild(layer_src_a); + layer_src_a->AddChild(layer_src_b); + layer_src_b->AddChild(layer_src_c); + + proto::LayerNode proto; + layer_src_root->ToLayerNodeProto(&proto); + + Layer::LayerIdMap empty_dest_layer_map; + scoped_refptr<Layer> layer_dest_root = Layer::Create(); + + layer_dest_root->FromLayerNodeProto(proto, empty_dest_layer_map, + layer_tree_host_.get()); + + EXPECT_EQ(layer_src_root->id(), layer_dest_root->id()); + EXPECT_EQ(nullptr, layer_dest_root->parent()); + ASSERT_EQ(1u, layer_dest_root->children().size()); + EXPECT_EQ(layer_tree_host_.get(), layer_dest_root->layer_tree_host_); + + scoped_refptr<Layer> layer_dest_a = layer_dest_root->children()[0]; + EXPECT_EQ(layer_src_a->id(), layer_dest_a->id()); + EXPECT_EQ(layer_src_root->id(), layer_dest_a->parent()->id()); + EXPECT_EQ(1u, layer_dest_a->children().size()); + EXPECT_EQ(layer_tree_host_.get(), layer_dest_a->layer_tree_host_); + + scoped_refptr<Layer> layer_dest_b = layer_dest_a->children()[0]; + EXPECT_EQ(layer_src_b->id(), layer_dest_b->id()); + EXPECT_EQ(layer_src_a->id(), layer_dest_b->parent()->id()); + ASSERT_EQ(1u, layer_dest_b->children().size()); + EXPECT_EQ(layer_tree_host_.get(), layer_dest_b->layer_tree_host_); + + scoped_refptr<Layer> layer_dest_c = layer_dest_b->children()[0]; + EXPECT_EQ(layer_src_c->id(), layer_dest_c->id()); + EXPECT_EQ(layer_src_b->id(), layer_dest_c->parent()->id()); + EXPECT_EQ(0u, layer_dest_c->children().size()); + EXPECT_EQ(layer_tree_host_.get(), layer_dest_c->layer_tree_host_); + + // The layers have not been added to the LayerTreeHost layer map, so the + // LTH pointers must be cleared manually. + layer_dest_root->layer_tree_host_ = nullptr; + layer_dest_a->layer_tree_host_ = nullptr; + layer_dest_b->layer_tree_host_ = nullptr; + layer_dest_c->layer_tree_host_ = nullptr; + } + + void RunNonDestructiveDeserializationBaseCaseTest() { + /* Testing serialization and deserialization of a tree that initially looks + like this: + root + / + a + The source tree is then deserialized from the same structure which should + re-use the Layers from last deserialization and importantly it should + not have called InvalidatePropertyTreesIndices() for any of the layers, + which would happen in for example SetLayerTreeHost(...) calls. + */ + scoped_refptr<Layer> layer_root = Layer::Create(); + scoped_refptr<Layer> layer_src_a = Layer::Create(); + layer_root->AddChild(layer_src_a); + layer_root->transform_tree_index_ = 33; + layer_src_a->transform_tree_index_ = 42; + + proto::LayerNode root_proto; + layer_root->ToLayerNodeProto(&root_proto); + + Layer::LayerIdMap dest_layer_map; + layer_root->ClearLayerTreePropertiesForDeserializationAndAddToMap( + &dest_layer_map); + layer_root->FromLayerNodeProto(root_proto, dest_layer_map, + layer_tree_host_.get()); + + EXPECT_EQ(33, layer_root->transform_tree_index_); + ASSERT_EQ(1u, layer_root->children().size()); + scoped_refptr<Layer> layer_dest_a = layer_root->children()[0]; + EXPECT_EQ(layer_src_a, layer_dest_a); + EXPECT_EQ(42, layer_dest_a->transform_tree_index_); + + // Clear the reference to the LTH for all the layers. + layer_root->SetLayerTreeHost(nullptr); + } + + void RunNonDestructiveDeserializationReorderChildrenTest() { + /* Testing serialization and deserialization of a tree that initially looks + like this: + root + / \ + a b + The children are then re-ordered to: + root + / \ + b a + The tree is then serialized and deserialized again, and the the end + result should have the same structure and importantly it should + not have called InvalidatePropertyTreesIndices() for any of the layers, + which would happen in for example SetLayerTreeHost(...) calls. + */ + scoped_refptr<Layer> layer_src_root = Layer::Create(); + scoped_refptr<Layer> layer_src_a = Layer::Create(); + scoped_refptr<Layer> layer_src_b = Layer::Create(); + layer_src_root->AddChild(layer_src_a); + layer_src_root->AddChild(layer_src_b); + + // Copy tree-structure to new root. + proto::LayerNode root_proto_1; + layer_src_root->ToLayerNodeProto(&root_proto_1); + Layer::LayerIdMap dest_layer_map; + scoped_refptr<Layer> layer_dest_root = Layer::Create(); + layer_dest_root->FromLayerNodeProto(root_proto_1, dest_layer_map, + layer_tree_host_.get()); + + // Ensure initial copy is correct. + ASSERT_EQ(2u, layer_dest_root->children().size()); + scoped_refptr<Layer> layer_dest_a = layer_dest_root->children()[0]; + EXPECT_EQ(layer_src_a->id(), layer_dest_a->id()); + scoped_refptr<Layer> layer_dest_b = layer_dest_root->children()[1]; + EXPECT_EQ(layer_src_b->id(), layer_dest_b->id()); + + // Swap order of the children. + scoped_refptr<Layer> tmp_a = layer_src_root->children_[0]; + layer_src_root->children_[0] = layer_src_root->children_[1]; + layer_src_root->children_[1] = tmp_a; + + // Fake the fact that the destination layers have valid indexes. + layer_dest_root->transform_tree_index_ = 33; + layer_dest_a->transform_tree_index_ = 42; + layer_dest_b->transform_tree_index_ = 24; + + // Now serialize and deserialize again. + proto::LayerNode root_proto_2; + layer_src_root->ToLayerNodeProto(&root_proto_2); + layer_dest_root->ClearLayerTreePropertiesForDeserializationAndAddToMap( + &dest_layer_map); + layer_dest_root->FromLayerNodeProto(root_proto_2, dest_layer_map, + layer_tree_host_.get()); + + // Ensure second copy is correct. + EXPECT_EQ(33, layer_dest_root->transform_tree_index_); + ASSERT_EQ(2u, layer_dest_root->children().size()); + layer_dest_b = layer_dest_root->children()[0]; + EXPECT_EQ(layer_src_b->id(), layer_dest_b->id()); + EXPECT_EQ(24, layer_dest_b->transform_tree_index_); + layer_dest_a = layer_dest_root->children()[1]; + EXPECT_EQ(layer_src_a->id(), layer_dest_a->id()); + EXPECT_EQ(42, layer_dest_a->transform_tree_index_); + + layer_dest_root->SetLayerTreeHost(nullptr); + } + + void RunNonDestructiveDeserializationAddChildTest() { + /* Testing serialization and deserialization of a tree that initially looks + like this: + root + / + a + A child is then added to the root: + root + / \ + b a + The tree is then serialized and deserialized again, and the the end + result should have the same structure and importantly it should + not have called InvalidatePropertyTreesIndices() for any of the layers, + which would happen in for example SetLayerTreeHost(...) calls. + */ + scoped_refptr<Layer> layer_src_root = Layer::Create(); + scoped_refptr<Layer> layer_src_a = Layer::Create(); + layer_src_root->AddChild(layer_src_a); + + // Copy tree-structure to new root. + proto::LayerNode root_proto_1; + layer_src_root->ToLayerNodeProto(&root_proto_1); + Layer::LayerIdMap dest_layer_map; + scoped_refptr<Layer> layer_dest_root = Layer::Create(); + layer_dest_root->FromLayerNodeProto(root_proto_1, dest_layer_map, + layer_tree_host_.get()); + + // Ensure initial copy is correct. + ASSERT_EQ(1u, layer_dest_root->children().size()); + scoped_refptr<Layer> layer_dest_a = layer_dest_root->children()[0]; + EXPECT_EQ(layer_src_a->id(), layer_dest_a->id()); + + // Fake the fact that the destination layer |a| now has a valid index. + layer_dest_root->transform_tree_index_ = 33; + layer_dest_a->transform_tree_index_ = 42; + + // Add another child. + scoped_refptr<Layer> layer_src_b = Layer::Create(); + layer_src_root->AddChild(layer_src_b); + + // Now serialize and deserialize again. + proto::LayerNode root_proto_2; + layer_src_root->ToLayerNodeProto(&root_proto_2); + layer_dest_root->ClearLayerTreePropertiesForDeserializationAndAddToMap( + &dest_layer_map); + layer_dest_root->FromLayerNodeProto(root_proto_2, dest_layer_map, + layer_tree_host_.get()); + + // Ensure second copy is correct. + EXPECT_EQ(33, layer_dest_root->transform_tree_index_); + ASSERT_EQ(2u, layer_dest_root->children().size()); + layer_dest_a = layer_dest_root->children()[0]; + EXPECT_EQ(layer_src_a->id(), layer_dest_a->id()); + EXPECT_EQ(42, layer_dest_a->transform_tree_index_); + scoped_refptr<Layer> layer_dest_b = layer_dest_root->children()[1]; + EXPECT_EQ(layer_src_b->id(), layer_dest_b->id()); + + layer_dest_root->SetLayerTreeHost(nullptr); + } + + void RunNonDestructiveDeserializationRemoveChildTest() { + /* Testing serialization and deserialization of a tree that initially looks + like this: + root + / \ + a b + The |b| child is the removed from the root: + root + / + b + The tree is then serialized and deserialized again, and the the end + result should have the same structure and importantly it should + not have called InvalidatePropertyTreesIndices() for any of the layers, + which would happen in for example SetLayerTreeHost(...) calls. + */ + scoped_refptr<Layer> layer_src_root = Layer::Create(); + scoped_refptr<Layer> layer_src_a = Layer::Create(); + scoped_refptr<Layer> layer_src_b = Layer::Create(); + layer_src_root->AddChild(layer_src_a); + layer_src_root->AddChild(layer_src_b); + + // Copy tree-structure to new root. + proto::LayerNode root_proto_1; + layer_src_root->ToLayerNodeProto(&root_proto_1); + Layer::LayerIdMap dest_layer_map; + scoped_refptr<Layer> layer_dest_root = Layer::Create(); + layer_dest_root->FromLayerNodeProto(root_proto_1, dest_layer_map, + layer_tree_host_.get()); + + // Ensure initial copy is correct. + ASSERT_EQ(2u, layer_dest_root->children().size()); + scoped_refptr<Layer> layer_dest_a = layer_dest_root->children()[0]; + EXPECT_EQ(layer_src_a->id(), layer_dest_a->id()); + scoped_refptr<Layer> layer_dest_b = layer_dest_root->children()[1]; + EXPECT_EQ(layer_src_b->id(), layer_dest_b->id()); + + // Remove one child. + layer_src_b->RemoveFromParent(); + + // Fake the fact that the destination layers have valid indexes. + layer_dest_root->transform_tree_index_ = 33; + layer_dest_a->transform_tree_index_ = 42; + layer_dest_b->transform_tree_index_ = 24; + + // Now serialize and deserialize again. + proto::LayerNode root_proto_2; + layer_src_root->ToLayerNodeProto(&root_proto_2); + layer_dest_root->ClearLayerTreePropertiesForDeserializationAndAddToMap( + &dest_layer_map); + layer_dest_root->FromLayerNodeProto(root_proto_2, dest_layer_map, + layer_tree_host_.get()); + + // Ensure second copy is correct. + EXPECT_EQ(33, layer_dest_root->transform_tree_index_); + ASSERT_EQ(1u, layer_dest_root->children().size()); + layer_dest_a = layer_dest_root->children()[0]; + EXPECT_EQ(layer_src_a->id(), layer_dest_a->id()); + EXPECT_EQ(42, layer_dest_a->transform_tree_index_); + + layer_dest_root->SetLayerTreeHost(nullptr); + } + + void RunNonDestructiveDeserializationMoveChildEarlierTest() { + /* Testing serialization and deserialization of a tree that initially looks + like this: + root + / \ + a b + \ + c + The |c| child of |b| is then moved to become a child of |a|: + root + / \ + a b + / + c + The tree is then serialized and deserialized again, and the the end + result should have the same structure and importantly it should + not have called InvalidatePropertyTreesIndices() for any of the layers, + which would happen in for example SetLayerTreeHost(...) calls. + */ + scoped_refptr<Layer> layer_src_root = Layer::Create(); + scoped_refptr<Layer> layer_src_a = Layer::Create(); + scoped_refptr<Layer> layer_src_b = Layer::Create(); + scoped_refptr<Layer> layer_src_c = Layer::Create(); + layer_src_root->AddChild(layer_src_a); + layer_src_root->AddChild(layer_src_b); + layer_src_b->AddChild(layer_src_c); + + // Copy tree-structure to new root. + proto::LayerNode root_proto_1; + layer_src_root->ToLayerNodeProto(&root_proto_1); + Layer::LayerIdMap dest_layer_map; + scoped_refptr<Layer> layer_dest_root = Layer::Create(); + layer_dest_root->FromLayerNodeProto(root_proto_1, dest_layer_map, + layer_tree_host_.get()); + + // Ensure initial copy is correct. + ASSERT_EQ(2u, layer_dest_root->children().size()); + scoped_refptr<Layer> layer_dest_a = layer_dest_root->children()[0]; + scoped_refptr<Layer> layer_dest_b = layer_dest_root->children()[1]; + EXPECT_EQ(layer_src_a->id(), layer_dest_a->id()); + EXPECT_EQ(layer_src_b->id(), layer_dest_b->id()); + ASSERT_EQ(1u, layer_dest_b->children().size()); + scoped_refptr<Layer> layer_dest_c = layer_dest_b->children()[0]; + EXPECT_EQ(layer_src_c->id(), layer_dest_c->id()); + + // Move child |c| from |b| to |a|. + layer_src_c->RemoveFromParent(); + layer_src_a->AddChild(layer_src_c); + + // Moving a child invalidates the |transform_tree_index_|, so forcefully + // set it afterwards on the destination layer. + layer_dest_root->transform_tree_index_ = 33; + layer_dest_a->transform_tree_index_ = 42; + layer_dest_b->transform_tree_index_ = 24; + layer_dest_c->transform_tree_index_ = 99; + + // Now serialize and deserialize again. + proto::LayerNode root_proto_2; + layer_src_root->ToLayerNodeProto(&root_proto_2); + layer_dest_root->ClearLayerTreePropertiesForDeserializationAndAddToMap( + &dest_layer_map); + layer_dest_root->FromLayerNodeProto(root_proto_2, dest_layer_map, + layer_tree_host_.get()); + + // Ensure second copy is correct. + EXPECT_EQ(33, layer_dest_root->transform_tree_index_); + ASSERT_EQ(2u, layer_dest_root->children().size()); + layer_dest_a = layer_dest_root->children()[0]; + layer_dest_b = layer_dest_root->children()[1]; + EXPECT_EQ(layer_src_a->id(), layer_dest_a->id()); + EXPECT_EQ(42, layer_dest_a->transform_tree_index_); + EXPECT_EQ(layer_src_b->id(), layer_dest_b->id()); + EXPECT_EQ(24, layer_dest_b->transform_tree_index_); + ASSERT_EQ(1u, layer_dest_a->children().size()); + layer_dest_c = layer_dest_a->children()[0]; + EXPECT_EQ(layer_src_c->id(), layer_dest_c->id()); + EXPECT_EQ(99, layer_dest_c->transform_tree_index_); + + layer_dest_root->SetLayerTreeHost(nullptr); + } + + void RunNonDestructiveDeserializationMoveChildLaterTest() { + /* Testing serialization and deserialization of a tree that initially looks + like this: + root + / \ + a b + / + c + The |c| child of |a| is then moved to become a child of |b|: + root + / \ + a b + \ + c + The tree is then serialized and deserialized again, and the the end + result should have the same structure and importantly it should + not have called InvalidatePropertyTreesIndices() for any of the layers, + which would happen in for example SetLayerTreeHost(...) calls. + */ + scoped_refptr<Layer> layer_src_root = Layer::Create(); + scoped_refptr<Layer> layer_src_a = Layer::Create(); + scoped_refptr<Layer> layer_src_b = Layer::Create(); + scoped_refptr<Layer> layer_src_c = Layer::Create(); + layer_src_root->AddChild(layer_src_a); + layer_src_root->AddChild(layer_src_b); + layer_src_a->AddChild(layer_src_c); + + // Copy tree-structure to new root. + proto::LayerNode root_proto_1; + layer_src_root->ToLayerNodeProto(&root_proto_1); + Layer::LayerIdMap dest_layer_map; + scoped_refptr<Layer> layer_dest_root = Layer::Create(); + layer_dest_root->FromLayerNodeProto(root_proto_1, dest_layer_map, + layer_tree_host_.get()); + + // Ensure initial copy is correct. + ASSERT_EQ(2u, layer_dest_root->children().size()); + scoped_refptr<Layer> layer_dest_a = layer_dest_root->children()[0]; + scoped_refptr<Layer> layer_dest_b = layer_dest_root->children()[1]; + EXPECT_EQ(layer_src_a->id(), layer_dest_a->id()); + EXPECT_EQ(layer_src_b->id(), layer_dest_b->id()); + ASSERT_EQ(1u, layer_dest_a->children().size()); + scoped_refptr<Layer> layer_dest_c = layer_dest_a->children()[0]; + EXPECT_EQ(layer_src_c->id(), layer_dest_c->id()); + + // Move child |c| from |b| to |a|. + layer_src_c->RemoveFromParent(); + layer_src_b->AddChild(layer_src_c); + + // Moving a child invalidates the |transform_tree_index_|, so forcefully + // set it afterwards on the destination layer. + layer_dest_root->transform_tree_index_ = 33; + layer_dest_a->transform_tree_index_ = 42; + layer_dest_b->transform_tree_index_ = 24; + layer_dest_c->transform_tree_index_ = 99; + + // Now serialize and deserialize again. + proto::LayerNode root_proto_2; + layer_src_root->ToLayerNodeProto(&root_proto_2); + layer_dest_root->ClearLayerTreePropertiesForDeserializationAndAddToMap( + &dest_layer_map); + layer_dest_root->FromLayerNodeProto(root_proto_2, dest_layer_map, + layer_tree_host_.get()); + + // Ensure second copy is correct. + EXPECT_EQ(33, layer_dest_root->transform_tree_index_); + ASSERT_EQ(2u, layer_dest_root->children().size()); + layer_dest_a = layer_dest_root->children()[0]; + layer_dest_b = layer_dest_root->children()[1]; + EXPECT_EQ(layer_src_a->id(), layer_dest_a->id()); + EXPECT_EQ(42, layer_dest_a->transform_tree_index_); + EXPECT_EQ(layer_src_b->id(), layer_dest_b->id()); + EXPECT_EQ(24, layer_dest_b->transform_tree_index_); + ASSERT_EQ(1u, layer_dest_b->children().size()); + layer_dest_c = layer_dest_b->children()[0]; + EXPECT_EQ(layer_src_c->id(), layer_dest_c->id()); + EXPECT_EQ(99, layer_dest_c->transform_tree_index_); + + layer_dest_root->SetLayerTreeHost(nullptr); + } + TestTaskGraphRunner task_graph_runner_; FakeLayerTreeHostClient fake_client_; scoped_ptr<FakeLayerTreeHost> layer_tree_host_; @@ -370,7 +825,7 @@ class MockLayerTreeHost : public LayerTreeHost { public: MockLayerTreeHost(LayerTreeHostSingleThreadClient* single_thread_client, LayerTreeHost::InitParams* params) - : LayerTreeHost(params, CompositorMode::SingleThreaded) { + : LayerTreeHost(params, CompositorMode::SINGLE_THREADED) { InitializeSingleThreaded(single_thread_client, base::ThreadTaskRunnerHandle::Get(), nullptr); } @@ -380,27 +835,18 @@ class MockLayerTreeHost : public LayerTreeHost { MOCK_METHOD0(SetNeedsFullTreeSync, void()); }; -class LayerTreeSettingsForLayerTest : public LayerTreeSettings { - public: - LayerTreeSettingsForLayerTest() { use_compositor_animation_timelines = true; } -}; - class LayerTest : public testing::Test { public: LayerTest() - : host_impl_(LayerTreeSettingsForLayerTest(), + : host_impl_(LayerTreeSettings(), &task_runner_provider_, &shared_bitmap_manager_, &task_graph_runner_), fake_client_(FakeLayerTreeHostClient::DIRECT_3D) { - layer_settings_.use_compositor_animation_timelines = - settings().use_compositor_animation_timelines; - if (settings().use_compositor_animation_timelines) { - timeline_impl_ = - AnimationTimeline::Create(AnimationIdProvider::NextTimelineId()); - timeline_impl_->set_is_impl_only(true); - host_impl_.animation_host()->AddAnimationTimeline(timeline_impl_); - } + timeline_impl_ = + AnimationTimeline::Create(AnimationIdProvider::NextTimelineId()); + timeline_impl_->set_is_impl_only(true); + host_impl_.animation_host()->AddAnimationTimeline(timeline_impl_); } const LayerTreeSettings& settings() { return settings_; } @@ -454,13 +900,13 @@ class LayerTest : public testing::Test { } void CreateSimpleTestTree() { - parent_ = Layer::Create(layer_settings_); - child1_ = Layer::Create(layer_settings_); - child2_ = Layer::Create(layer_settings_); - child3_ = Layer::Create(layer_settings_); - grand_child1_ = Layer::Create(layer_settings_); - grand_child2_ = Layer::Create(layer_settings_); - grand_child3_ = Layer::Create(layer_settings_); + parent_ = Layer::Create(); + child1_ = Layer::Create(); + child2_ = Layer::Create(); + child3_ = Layer::Create(); + grand_child1_ = Layer::Create(); + grand_child2_ = Layer::Create(); + grand_child3_ = Layer::Create(); EXPECT_CALL(*layer_tree_host_, SetNeedsFullTreeSync()).Times(AnyNumber()); layer_tree_host_->SetRootLayer(parent_); @@ -494,12 +940,11 @@ class LayerTest : public testing::Test { scoped_refptr<AnimationTimeline> timeline_impl_; - LayerTreeSettingsForLayerTest settings_; - LayerSettings layer_settings_; + LayerTreeSettings settings_; }; TEST_F(LayerTest, BasicCreateAndDestroy) { - scoped_refptr<Layer> test_layer = Layer::Create(layer_settings_); + scoped_refptr<Layer> test_layer = Layer::Create(); ASSERT_TRUE(test_layer.get()); EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(0); @@ -510,9 +955,195 @@ TEST_F(LayerTest, BasicCreateAndDestroy) { test_layer->SetLayerTreeHost(nullptr); } +TEST_F(LayerTest, LayerPropertyChangedForSubtree) { + EXPECT_CALL(*layer_tree_host_, SetNeedsFullTreeSync()).Times(AtLeast(1)); + scoped_refptr<Layer> root = Layer::Create(); + scoped_refptr<Layer> child = Layer::Create(); + scoped_refptr<Layer> child2 = Layer::Create(); + scoped_refptr<Layer> grand_child = Layer::Create(); + scoped_refptr<Layer> dummy_layer1 = Layer::Create(); + scoped_refptr<Layer> dummy_layer2 = Layer::Create(); + + layer_tree_host_->SetRootLayer(root); + root->AddChild(child); + root->AddChild(child2); + child->AddChild(grand_child); + EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1)); + child->SetForceRenderSurface(true); + EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1)); + child2->SetScrollParent(grand_child.get()); + SkXfermode::Mode arbitrary_blend_mode = SkXfermode::kMultiply_Mode; + scoped_ptr<LayerImpl> root_impl = + LayerImpl::Create(host_impl_.active_tree(), root->id()); + scoped_ptr<LayerImpl> child_impl = + LayerImpl::Create(host_impl_.active_tree(), child->id()); + scoped_ptr<LayerImpl> child2_impl = + LayerImpl::Create(host_impl_.active_tree(), child2->id()); + scoped_ptr<LayerImpl> grand_child_impl = + LayerImpl::Create(host_impl_.active_tree(), grand_child->id()); + scoped_ptr<LayerImpl> dummy_layer1_impl = + LayerImpl::Create(host_impl_.active_tree(), dummy_layer1->id()); + scoped_ptr<LayerImpl> dummy_layer2_impl = + LayerImpl::Create(host_impl_.active_tree(), dummy_layer2->id()); + + EXPECT_CALL(*layer_tree_host_, SetNeedsFullTreeSync()).Times(1); + EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root->SetMaskLayer(dummy_layer1.get())); + EXECUTE_AND_VERIFY_SUBTREE_CHANGES_RESET( + root->PushPropertiesTo(root_impl.get()); + child->PushPropertiesTo(child_impl.get()); + child2->PushPropertiesTo(child2_impl.get()); + grand_child->PushPropertiesTo(grand_child_impl.get()); + dummy_layer1->PushPropertiesTo(dummy_layer1_impl.get())); + + EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(1); + EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root->SetMasksToBounds(true)); + EXECUTE_AND_VERIFY_SUBTREE_CHANGES_RESET( + root->PushPropertiesTo(root_impl.get()); + child->PushPropertiesTo(child_impl.get()); + child2->PushPropertiesTo(child2_impl.get()); + grand_child->PushPropertiesTo(grand_child_impl.get())); + + EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(1); + EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root->SetContentsOpaque(true)); + EXECUTE_AND_VERIFY_SUBTREE_CHANGES_RESET( + root->PushPropertiesTo(root_impl.get()); + child->PushPropertiesTo(child_impl.get()); + child2->PushPropertiesTo(child2_impl.get()); + grand_child->PushPropertiesTo(grand_child_impl.get())); + + EXPECT_CALL(*layer_tree_host_, SetNeedsFullTreeSync()).Times(1); + EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root->SetReplicaLayer(dummy_layer2.get())); + EXECUTE_AND_VERIFY_SUBTREE_CHANGES_RESET( + root->PushPropertiesTo(root_impl.get()); + child->PushPropertiesTo(child_impl.get()); + child2->PushPropertiesTo(child2_impl.get()); + grand_child->PushPropertiesTo(grand_child_impl.get()); + dummy_layer2->PushPropertiesTo(dummy_layer2_impl.get())); + + EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(1); + EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root->SetShouldFlattenTransform(false)); + EXECUTE_AND_VERIFY_SUBTREE_CHANGES_RESET( + root->PushPropertiesTo(root_impl.get()); + child->PushPropertiesTo(child_impl.get()); + child2->PushPropertiesTo(child2_impl.get()); + grand_child->PushPropertiesTo(grand_child_impl.get())); + + EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(1); + EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root->Set3dSortingContextId(1)); + EXECUTE_AND_VERIFY_SUBTREE_CHANGES_RESET( + root->PushPropertiesTo(root_impl.get()); + child->PushPropertiesTo(child_impl.get()); + child2->PushPropertiesTo(child2_impl.get()); + grand_child->PushPropertiesTo(grand_child_impl.get()); + dummy_layer2->PushPropertiesTo(dummy_layer2_impl.get())); + + EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(1); + EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root->SetDoubleSided(false)); + EXECUTE_AND_VERIFY_SUBTREE_CHANGES_RESET( + root->PushPropertiesTo(root_impl.get()); + child->PushPropertiesTo(child_impl.get()); + child2->PushPropertiesTo(child2_impl.get()); + grand_child->PushPropertiesTo(grand_child_impl.get())); + + EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(1); + EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root->SetHideLayerAndSubtree(true)); + EXECUTE_AND_VERIFY_SUBTREE_CHANGES_RESET( + root->PushPropertiesTo(root_impl.get()); + child->PushPropertiesTo(child_impl.get()); + child2->PushPropertiesTo(child2_impl.get()); + grand_child->PushPropertiesTo(grand_child_impl.get())); + + EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(1); + EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root->SetBlendMode(arbitrary_blend_mode)); + EXECUTE_AND_VERIFY_SUBTREE_CHANGES_RESET( + root->PushPropertiesTo(root_impl.get()); + child->PushPropertiesTo(child_impl.get()); + child2->PushPropertiesTo(child2_impl.get()); + grand_child->PushPropertiesTo(grand_child_impl.get())); + + // Should be a different size than previous call, to ensure it marks tree + // changed. + gfx::Size arbitrary_size = gfx::Size(111, 222); + EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(1); + EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root->SetBounds(arbitrary_size)); + EXECUTE_AND_VERIFY_SUBTREE_CHANGES_RESET( + root->PushPropertiesTo(root_impl.get()); + child->PushPropertiesTo(child_impl.get()); + child2->PushPropertiesTo(child2_impl.get()); + grand_child->PushPropertiesTo(grand_child_impl.get())); + + FilterOperations arbitrary_filters; + arbitrary_filters.Append(FilterOperation::CreateOpacityFilter(0.5f)); + EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(1); + EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root->SetFilters(arbitrary_filters)); + EXECUTE_AND_VERIFY_SUBTREE_CHANGES_RESET( + root->PushPropertiesTo(root_impl.get()); + child->PushPropertiesTo(child_impl.get()); + child2->PushPropertiesTo(child2_impl.get()); + grand_child->PushPropertiesTo(grand_child_impl.get())); + + gfx::PointF arbitrary_point_f = gfx::PointF(0.125f, 0.25f); + EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(1); + root->SetPosition(arbitrary_point_f); + TransformNode* node = layer_tree_host_->property_trees()->transform_tree.Node( + root->transform_tree_index()); + EXPECT_TRUE(node->data.transform_changed); + EXECUTE_AND_VERIFY_SUBTREE_CHANGES_RESET( + root->PushPropertiesTo(root_impl.get()); + child->PushPropertiesTo(child_impl.get()); + child2->PushPropertiesTo(child2_impl.get()); + grand_child->PushPropertiesTo(grand_child_impl.get()); + layer_tree_host_->property_trees()->ResetAllChangeTracking( + PropertyTrees::ResetFlags::ALL_TREES)); + EXPECT_FALSE(node->data.transform_changed); + + EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(1); + child->SetPosition(arbitrary_point_f); + node = layer_tree_host_->property_trees()->transform_tree.Node( + child->transform_tree_index()); + EXPECT_TRUE(node->data.transform_changed); + // child2 is not in the subtree of child, but its scroll parent is. So, its + // to_screen will be effected by change in position of child2. + layer_tree_host_->property_trees()->transform_tree.UpdateTransforms( + child2->transform_tree_index()); + node = layer_tree_host_->property_trees()->transform_tree.Node( + child2->transform_tree_index()); + EXPECT_TRUE(node->data.transform_changed); + EXECUTE_AND_VERIFY_SUBTREE_CHANGES_RESET( + child->PushPropertiesTo(child_impl.get()); + grand_child->PushPropertiesTo(grand_child_impl.get()); + layer_tree_host_->property_trees()->ResetAllChangeTracking( + PropertyTrees::ResetFlags::ALL_TREES)); + node = layer_tree_host_->property_trees()->transform_tree.Node( + child->transform_tree_index()); + EXPECT_FALSE(node->data.transform_changed); + + gfx::Point3F arbitrary_point_3f = gfx::Point3F(0.125f, 0.25f, 0.f); + EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(1); + root->SetTransformOrigin(arbitrary_point_3f); + node = layer_tree_host_->property_trees()->transform_tree.Node( + root->transform_tree_index()); + EXPECT_TRUE(node->data.transform_changed); + EXECUTE_AND_VERIFY_SUBTREE_CHANGES_RESET( + root->PushPropertiesTo(root_impl.get()); + child->PushPropertiesTo(child_impl.get()); + child2->PushPropertiesTo(child2_impl.get()); + grand_child->PushPropertiesTo(grand_child_impl.get()); + layer_tree_host_->property_trees()->ResetAllChangeTracking( + PropertyTrees::ResetFlags::ALL_TREES)); + + gfx::Transform arbitrary_transform; + arbitrary_transform.Scale3d(0.1f, 0.2f, 0.3f); + EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(1); + root->SetTransform(arbitrary_transform); + node = layer_tree_host_->property_trees()->transform_tree.Node( + root->transform_tree_index()); + EXPECT_TRUE(node->data.transform_changed); +} + TEST_F(LayerTest, AddAndRemoveChild) { - scoped_refptr<Layer> parent = Layer::Create(layer_settings_); - scoped_refptr<Layer> child = Layer::Create(layer_settings_); + scoped_refptr<Layer> parent = Layer::Create(); + scoped_refptr<Layer> child = Layer::Create(); // Upon creation, layers should not have children or parent. ASSERT_EQ(0U, parent->children().size()); @@ -522,7 +1153,7 @@ TEST_F(LayerTest, AddAndRemoveChild) { EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, parent->AddChild(child)); ASSERT_EQ(1U, parent->children().size()); - EXPECT_EQ(child.get(), parent->children()[0].get()); + EXPECT_EQ(child.get(), parent->children()[0]); EXPECT_EQ(parent.get(), child->parent()); EXPECT_EQ(parent.get(), child->RootLayer()); @@ -532,8 +1163,8 @@ TEST_F(LayerTest, AddAndRemoveChild) { TEST_F(LayerTest, AddSameChildTwice) { EXPECT_CALL(*layer_tree_host_, SetNeedsFullTreeSync()).Times(AtLeast(1)); - scoped_refptr<Layer> parent = Layer::Create(layer_settings_); - scoped_refptr<Layer> child = Layer::Create(layer_settings_); + scoped_refptr<Layer> parent = Layer::Create(); + scoped_refptr<Layer> child = Layer::Create(); layer_tree_host_->SetRootLayer(parent); @@ -549,11 +1180,11 @@ TEST_F(LayerTest, AddSameChildTwice) { } TEST_F(LayerTest, InsertChild) { - scoped_refptr<Layer> parent = Layer::Create(layer_settings_); - scoped_refptr<Layer> child1 = Layer::Create(layer_settings_); - scoped_refptr<Layer> child2 = Layer::Create(layer_settings_); - scoped_refptr<Layer> child3 = Layer::Create(layer_settings_); - scoped_refptr<Layer> child4 = Layer::Create(layer_settings_); + scoped_refptr<Layer> parent = Layer::Create(); + scoped_refptr<Layer> child1 = Layer::Create(); + scoped_refptr<Layer> child2 = Layer::Create(); + scoped_refptr<Layer> child3 = Layer::Create(); + scoped_refptr<Layer> child4 = Layer::Create(); EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, layer_tree_host_->SetRootLayer(parent)); @@ -594,9 +1225,9 @@ TEST_F(LayerTest, InsertChild) { } TEST_F(LayerTest, InsertChildPastEndOfList) { - scoped_refptr<Layer> parent = Layer::Create(layer_settings_); - scoped_refptr<Layer> child1 = Layer::Create(layer_settings_); - scoped_refptr<Layer> child2 = Layer::Create(layer_settings_); + scoped_refptr<Layer> parent = Layer::Create(); + scoped_refptr<Layer> child1 = Layer::Create(); + scoped_refptr<Layer> child2 = Layer::Create(); ASSERT_EQ(0U, parent->children().size()); @@ -615,9 +1246,9 @@ TEST_F(LayerTest, InsertChildPastEndOfList) { } TEST_F(LayerTest, InsertSameChildTwice) { - scoped_refptr<Layer> parent = Layer::Create(layer_settings_); - scoped_refptr<Layer> child1 = Layer::Create(layer_settings_); - scoped_refptr<Layer> child2 = Layer::Create(layer_settings_); + scoped_refptr<Layer> parent = Layer::Create(); + scoped_refptr<Layer> child1 = Layer::Create(); + scoped_refptr<Layer> child2 = Layer::Create(); EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, layer_tree_host_->SetRootLayer(parent)); @@ -644,7 +1275,7 @@ TEST_F(LayerTest, InsertSameChildTwice) { TEST_F(LayerTest, ReplaceChildWithNewChild) { CreateSimpleTestTree(); - scoped_refptr<Layer> child4 = Layer::Create(layer_settings_); + scoped_refptr<Layer> child4 = Layer::Create(); EXPECT_FALSE(child4->parent()); @@ -669,8 +1300,8 @@ TEST_F(LayerTest, ReplaceChildWithNewChildThatHasOtherParent) { CreateSimpleTestTree(); // create another simple tree with test_layer and child4. - scoped_refptr<Layer> test_layer = Layer::Create(layer_settings_); - scoped_refptr<Layer> child4 = Layer::Create(layer_settings_); + scoped_refptr<Layer> test_layer = Layer::Create(); + scoped_refptr<Layer> child4 = Layer::Create(); test_layer->AddChild(child4); ASSERT_EQ(1U, test_layer->children().size()); EXPECT_EQ(child4, test_layer->children()[0]); @@ -692,9 +1323,9 @@ TEST_F(LayerTest, ReplaceChildWithNewChildThatHasOtherParent) { } TEST_F(LayerTest, DeleteRemovedScrollParent) { - scoped_refptr<Layer> parent = Layer::Create(layer_settings_); - scoped_refptr<Layer> child1 = Layer::Create(layer_settings_); - scoped_refptr<Layer> child2 = Layer::Create(layer_settings_); + scoped_refptr<Layer> parent = Layer::Create(); + scoped_refptr<Layer> child1 = Layer::Create(); + scoped_refptr<Layer> child2 = Layer::Create(); EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, layer_tree_host_->SetRootLayer(parent)); @@ -711,19 +1342,20 @@ TEST_F(LayerTest, DeleteRemovedScrollParent) { EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, child2->RemoveFromParent()); - child1->reset_needs_push_properties_for_testing(); + child1->ResetNeedsPushPropertiesForTesting(); EXPECT_SET_NEEDS_COMMIT(1, child2 = nullptr); - EXPECT_TRUE(child1->needs_push_properties()); + EXPECT_TRUE( + layer_tree_host_->LayerNeedsPushPropertiesForTesting(child1.get())); EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, layer_tree_host_->SetRootLayer(nullptr)); } TEST_F(LayerTest, DeleteRemovedScrollChild) { - scoped_refptr<Layer> parent = Layer::Create(layer_settings_); - scoped_refptr<Layer> child1 = Layer::Create(layer_settings_); - scoped_refptr<Layer> child2 = Layer::Create(layer_settings_); + scoped_refptr<Layer> parent = Layer::Create(); + scoped_refptr<Layer> child1 = Layer::Create(); + scoped_refptr<Layer> child2 = Layer::Create(); EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, layer_tree_host_->SetRootLayer(parent)); @@ -740,11 +1372,12 @@ TEST_F(LayerTest, DeleteRemovedScrollChild) { EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, child1->RemoveFromParent()); - child2->reset_needs_push_properties_for_testing(); + child2->ResetNeedsPushPropertiesForTesting(); EXPECT_SET_NEEDS_COMMIT(1, child1 = nullptr); - EXPECT_TRUE(child2->needs_push_properties()); + EXPECT_TRUE( + layer_tree_host_->LayerNeedsPushPropertiesForTesting(child2.get())); EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, layer_tree_host_->SetRootLayer(nullptr)); } @@ -773,11 +1406,11 @@ TEST_F(LayerTest, RemoveAllChildren) { } TEST_F(LayerTest, SetChildren) { - scoped_refptr<Layer> old_parent = Layer::Create(layer_settings_); - scoped_refptr<Layer> new_parent = Layer::Create(layer_settings_); + scoped_refptr<Layer> old_parent = Layer::Create(); + scoped_refptr<Layer> new_parent = Layer::Create(); - scoped_refptr<Layer> child1 = Layer::Create(layer_settings_); - scoped_refptr<Layer> child2 = Layer::Create(layer_settings_); + scoped_refptr<Layer> child1 = Layer::Create(); + scoped_refptr<Layer> child2 = Layer::Create(); LayerList new_children; new_children.push_back(child1); @@ -804,17 +1437,17 @@ TEST_F(LayerTest, SetChildren) { } TEST_F(LayerTest, HasAncestor) { - scoped_refptr<Layer> parent = Layer::Create(layer_settings_); + scoped_refptr<Layer> parent = Layer::Create(); EXPECT_FALSE(parent->HasAncestor(parent.get())); - scoped_refptr<Layer> child = Layer::Create(layer_settings_); + scoped_refptr<Layer> child = Layer::Create(); parent->AddChild(child); EXPECT_FALSE(child->HasAncestor(child.get())); EXPECT_TRUE(child->HasAncestor(parent.get())); EXPECT_FALSE(parent->HasAncestor(child.get())); - scoped_refptr<Layer> child_child = Layer::Create(layer_settings_); + scoped_refptr<Layer> child_child = Layer::Create(); child->AddChild(child_child); EXPECT_FALSE(child_child->HasAncestor(child_child.get())); @@ -830,7 +1463,7 @@ TEST_F(LayerTest, GetRootLayerAfterTreeManipulations) { // For this test we don't care about SetNeedsFullTreeSync calls. EXPECT_CALL(*layer_tree_host_, SetNeedsFullTreeSync()).Times(AnyNumber()); - scoped_refptr<Layer> child4 = Layer::Create(layer_settings_); + scoped_refptr<Layer> child4 = Layer::Create(); EXPECT_EQ(parent_.get(), parent_->RootLayer()); EXPECT_EQ(parent_.get(), child1_->RootLayer()); @@ -885,7 +1518,7 @@ TEST_F(LayerTest, CheckSetNeedsDisplayCausesCorrectBehavior) { // 2. indirectly calls SetNeedsUpdate, exactly once for each call to // SetNeedsDisplay. - scoped_refptr<Layer> test_layer = Layer::Create(layer_settings_); + scoped_refptr<Layer> test_layer = Layer::Create(); EXPECT_SET_NEEDS_FULL_TREE_SYNC( 1, layer_tree_host_->SetRootLayer(test_layer)); EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetIsDrawable(true)); @@ -937,14 +1570,65 @@ TEST_F(LayerTest, CheckSetNeedsDisplayCausesCorrectBehavior) { EXPECT_TRUE(test_layer->NeedsDisplayForTesting()); } +TEST_F(LayerTest, TestSettingMainThreadScrollingReason) { + scoped_refptr<Layer> test_layer = Layer::Create(); + EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, + layer_tree_host_->SetRootLayer(test_layer)); + EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetIsDrawable(true)); + + // sanity check of initial test condition + EXPECT_FALSE(test_layer->NeedsDisplayForTesting()); + + uint32_t reasons = 0, reasons_to_clear = 0, reasons_after_clearing = 0; + reasons |= MainThreadScrollingReason::kEventHandlers; + reasons |= MainThreadScrollingReason::kContinuingMainThreadScroll; + reasons |= MainThreadScrollingReason::kScrollbarScrolling; + + reasons_to_clear |= MainThreadScrollingReason::kContinuingMainThreadScroll; + reasons_to_clear |= MainThreadScrollingReason::kThreadedScrollingDisabled; + + reasons_after_clearing |= MainThreadScrollingReason::kEventHandlers; + reasons_after_clearing |= MainThreadScrollingReason::kScrollbarScrolling; + + // Check that the reasons are added correctly. + EXPECT_SET_NEEDS_COMMIT(1, test_layer->AddMainThreadScrollingReasons( + MainThreadScrollingReason::kEventHandlers)); + EXPECT_SET_NEEDS_COMMIT( + 1, test_layer->AddMainThreadScrollingReasons( + MainThreadScrollingReason::kContinuingMainThreadScroll)); + EXPECT_SET_NEEDS_COMMIT(1, + test_layer->AddMainThreadScrollingReasons( + MainThreadScrollingReason::kScrollbarScrolling)); + EXPECT_EQ(reasons, test_layer->main_thread_scrolling_reasons()); + + // Check that the reasons can be selectively cleared. + EXPECT_SET_NEEDS_COMMIT( + 1, test_layer->ClearMainThreadScrollingReasons(reasons_to_clear)); + EXPECT_EQ(reasons_after_clearing, + test_layer->main_thread_scrolling_reasons()); + + // Check that clearing non-set reasons doesn't set needs commit. + reasons_to_clear = 0; + reasons_to_clear |= MainThreadScrollingReason::kThreadedScrollingDisabled; + reasons_to_clear |= MainThreadScrollingReason::kNoScrollingLayer; + EXPECT_SET_NEEDS_COMMIT( + 0, test_layer->ClearMainThreadScrollingReasons(reasons_to_clear)); + EXPECT_EQ(reasons_after_clearing, + test_layer->main_thread_scrolling_reasons()); + + // Check that adding an existing condition doesn't set needs commit. + EXPECT_SET_NEEDS_COMMIT(0, test_layer->AddMainThreadScrollingReasons( + MainThreadScrollingReason::kEventHandlers)); +} + TEST_F(LayerTest, CheckPropertyChangeCausesCorrectBehavior) { - scoped_refptr<Layer> test_layer = Layer::Create(layer_settings_); + scoped_refptr<Layer> test_layer = Layer::Create(); EXPECT_SET_NEEDS_FULL_TREE_SYNC( 1, layer_tree_host_->SetRootLayer(test_layer)); EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetIsDrawable(true)); - scoped_refptr<Layer> dummy_layer1 = Layer::Create(layer_settings_); - scoped_refptr<Layer> dummy_layer2 = Layer::Create(layer_settings_); + scoped_refptr<Layer> dummy_layer1 = Layer::Create(); + scoped_refptr<Layer> dummy_layer2 = Layer::Create(); // sanity check of initial test condition EXPECT_FALSE(test_layer->NeedsDisplayForTesting()); @@ -967,11 +1651,10 @@ TEST_F(LayerTest, CheckPropertyChangeCausesCorrectBehavior) { EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetUserScrollable(true, false)); EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetScrollOffset( gfx::ScrollOffset(10, 10))); - EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetShouldScrollOnMainThread(true)); + EXPECT_SET_NEEDS_COMMIT(1, test_layer->AddMainThreadScrollingReasons( + MainThreadScrollingReason::kEventHandlers)); EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetNonFastScrollableRegion( Region(gfx::Rect(1, 1, 2, 2)))); - EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetHaveWheelEventHandlers(true)); - EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetHaveScrollEventHandlers(true)); EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetTransform( gfx::Transform(0.0, 0.0, 0.0, 0.0, 0.0, 0.0))); EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetDoubleSided(false)); @@ -981,7 +1664,7 @@ TEST_F(LayerTest, CheckPropertyChangeCausesCorrectBehavior) { EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetHideLayerAndSubtree(true)); EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetElementId(2)); EXPECT_SET_NEEDS_COMMIT( - 1, test_layer->SetMutableProperties(kMutablePropertyTransform)); + 1, test_layer->SetMutableProperties(MutableProperty::kTransform)); EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, test_layer->SetMaskLayer( dummy_layer1.get())); @@ -996,36 +1679,39 @@ TEST_F(LayerTest, CheckPropertyChangeCausesCorrectBehavior) { } TEST_F(LayerTest, PushPropertiesAccumulatesUpdateRect) { - scoped_refptr<Layer> test_layer = Layer::Create(layer_settings_); + scoped_refptr<Layer> test_layer = Layer::Create(); scoped_ptr<LayerImpl> impl_layer = LayerImpl::Create(host_impl_.active_tree(), 1); EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, layer_tree_host_->SetRootLayer(test_layer)); + host_impl_.active_tree()->SetRootLayer(std::move(impl_layer)); + LayerImpl* impl_layer_ptr = host_impl_.active_tree()->LayerById(1); test_layer->SetNeedsDisplayRect(gfx::Rect(5, 5)); - test_layer->PushPropertiesTo(impl_layer.get()); + test_layer->PushPropertiesTo(impl_layer_ptr); EXPECT_FLOAT_RECT_EQ(gfx::RectF(0.f, 0.f, 5.f, 5.f), - impl_layer->update_rect()); + impl_layer_ptr->update_rect()); // The LayerImpl's update_rect() should be accumulated here, since we did not // do anything to clear it. test_layer->SetNeedsDisplayRect(gfx::Rect(10, 10, 5, 5)); - test_layer->PushPropertiesTo(impl_layer.get()); + test_layer->PushPropertiesTo(impl_layer_ptr); EXPECT_FLOAT_RECT_EQ(gfx::RectF(0.f, 0.f, 15.f, 15.f), - impl_layer->update_rect()); + impl_layer_ptr->update_rect()); // If we do clear the LayerImpl side, then the next update_rect() should be // fresh without accumulation. - impl_layer->ResetAllChangeTrackingForSubtree(); + host_impl_.active_tree()->ResetAllChangeTracking( + PropertyTrees::ResetFlags::ALL_TREES); test_layer->SetNeedsDisplayRect(gfx::Rect(10, 10, 5, 5)); - test_layer->PushPropertiesTo(impl_layer.get()); + test_layer->PushPropertiesTo(impl_layer_ptr); EXPECT_FLOAT_RECT_EQ(gfx::RectF(10.f, 10.f, 5.f, 5.f), - impl_layer->update_rect()); + impl_layer_ptr->update_rect()); } TEST_F(LayerTest, PushPropertiesCausesLayerPropertyChangedForTransform) { - scoped_refptr<Layer> test_layer = Layer::Create(layer_settings_); + scoped_refptr<Layer> test_layer = Layer::Create(); scoped_ptr<LayerImpl> impl_layer = LayerImpl::Create(host_impl_.active_tree(), 1); @@ -1044,185 +1730,31 @@ TEST_F(LayerTest, PushPropertiesCausesLayerPropertyChangedForTransform) { } TEST_F(LayerTest, PushPropertiesCausesLayerPropertyChangedForOpacity) { - scoped_refptr<Layer> test_layer = Layer::Create(layer_settings_); - scoped_ptr<LayerImpl> impl_layer = - LayerImpl::Create(host_impl_.active_tree(), 1); - - EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, - layer_tree_host_->SetRootLayer(test_layer)); - - EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetOpacity(0.5f)); - - EXPECT_FALSE(impl_layer->LayerPropertyChanged()); - - test_layer->PushPropertiesTo(impl_layer.get()); - - EXPECT_TRUE(impl_layer->LayerPropertyChanged()); -} - -TEST_F(LayerTest, - PushPropsDoesntCauseLayerPropertyChangedDuringImplOnlyTransformAnim) { - scoped_refptr<Layer> test_layer = Layer::Create(layer_settings_); - scoped_ptr<LayerImpl> impl_layer = - LayerImpl::Create(host_impl_.active_tree(), 1); - - EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, - layer_tree_host_->SetRootLayer(test_layer)); - - scoped_ptr<AnimationRegistrar> registrar; - if (settings().use_compositor_animation_timelines) { - AddAnimatedTransformToLayerWithPlayer(impl_layer->id(), timeline_impl(), - 1.0, 0, 100); - } else { - registrar = AnimationRegistrar::Create(); - impl_layer->layer_animation_controller()->SetAnimationRegistrar( - registrar.get()); - - AddAnimatedTransformToController(impl_layer->layer_animation_controller(), - 1.0, 0, 100); - } - - gfx::Transform transform; - transform.Rotate(45.0); - EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetTransform(transform)); - - EXPECT_FALSE(impl_layer->LayerPropertyChanged()); - test_layer->PushPropertiesTo(impl_layer.get()); - EXPECT_TRUE(impl_layer->LayerPropertyChanged()); - - impl_layer->ResetAllChangeTrackingForSubtree(); - if (settings().use_compositor_animation_timelines) { - int animation_id = AddAnimatedTransformToLayerWithPlayer( - impl_layer->id(), timeline_impl(), 1.0, 0, 100); - GetAnimationFromLayerWithExistingPlayer(impl_layer->id(), timeline_impl(), - animation_id) - ->set_is_impl_only(true); - } else { - AddAnimatedTransformToController(impl_layer->layer_animation_controller(), - 1.0, 0, 100); - impl_layer->layer_animation_controller() - ->GetAnimation(Animation::TRANSFORM) - ->set_is_impl_only(true); - } - transform.Rotate(45.0); - EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetTransform(transform)); - - EXPECT_FALSE(impl_layer->LayerPropertyChanged()); - test_layer->PushPropertiesTo(impl_layer.get()); - EXPECT_FALSE(impl_layer->LayerPropertyChanged()); -} - -TEST_F(LayerTest, - PushPropsDoesntCauseLayerPropertyChangedDuringImplOnlyOpacityAnim) { - scoped_refptr<Layer> test_layer = Layer::Create(layer_settings_); + scoped_refptr<Layer> test_layer = Layer::Create(); scoped_ptr<LayerImpl> impl_layer = LayerImpl::Create(host_impl_.active_tree(), 1); EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, layer_tree_host_->SetRootLayer(test_layer)); - scoped_ptr<AnimationRegistrar> registrar; - if (settings().use_compositor_animation_timelines) { - AddOpacityTransitionToLayerWithPlayer(impl_layer->id(), timeline_impl(), - 1.0, 0.3f, 0.7f, false); - } else { - registrar = AnimationRegistrar::Create(); - impl_layer->layer_animation_controller()->SetAnimationRegistrar( - registrar.get()); - - AddOpacityTransitionToController(impl_layer->layer_animation_controller(), - 1.0, 0.3f, 0.7f, false); - } - EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetOpacity(0.5f)); EXPECT_FALSE(impl_layer->LayerPropertyChanged()); - test_layer->PushPropertiesTo(impl_layer.get()); - EXPECT_TRUE(impl_layer->LayerPropertyChanged()); - - impl_layer->ResetAllChangeTrackingForSubtree(); - if (settings().use_compositor_animation_timelines) { - int animation_id = AddOpacityTransitionToLayerWithPlayer( - impl_layer->id(), timeline_impl(), 1.0, 0.3f, 0.7f, false); - GetAnimationFromLayerWithExistingPlayer(impl_layer->id(), timeline_impl(), - animation_id) - ->set_is_impl_only(true); - } else { - AddOpacityTransitionToController(impl_layer->layer_animation_controller(), - 1.0, 0.3f, 0.7f, false); - impl_layer->layer_animation_controller() - ->GetAnimation(Animation::OPACITY) - ->set_is_impl_only(true); - } - EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetOpacity(0.75f)); - EXPECT_FALSE(impl_layer->LayerPropertyChanged()); test_layer->PushPropertiesTo(impl_layer.get()); - EXPECT_FALSE(impl_layer->LayerPropertyChanged()); -} - -TEST_F(LayerTest, - PushPropsDoesntCauseLayerPropertyChangedDuringImplOnlyFilterAnim) { - scoped_refptr<Layer> test_layer = Layer::Create(layer_settings_); - scoped_ptr<LayerImpl> impl_layer = - LayerImpl::Create(host_impl_.active_tree(), 1); - EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, - layer_tree_host_->SetRootLayer(test_layer)); - - scoped_ptr<AnimationRegistrar> registrar; - if (settings().use_compositor_animation_timelines) { - AddAnimatedFilterToLayerWithPlayer(impl_layer->id(), timeline_impl(), 1.0, - 1.f, 2.f); - } else { - registrar = AnimationRegistrar::Create(); - impl_layer->layer_animation_controller()->SetAnimationRegistrar( - registrar.get()); - - AddAnimatedFilterToController(impl_layer->layer_animation_controller(), 1.0, - 1.f, 2.f); - } - - FilterOperations filters; - filters.Append(FilterOperation::CreateBlurFilter(2.f)); - EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetFilters(filters)); - - EXPECT_FALSE(impl_layer->LayerPropertyChanged()); - test_layer->PushPropertiesTo(impl_layer.get()); EXPECT_TRUE(impl_layer->LayerPropertyChanged()); - - impl_layer->ResetAllChangeTrackingForSubtree(); - if (settings().use_compositor_animation_timelines) { - int animation_id = AddAnimatedFilterToLayerWithPlayer( - impl_layer->id(), timeline_impl(), 1.0, 1.f, 2.f); - GetAnimationFromLayerWithExistingPlayer(impl_layer->id(), timeline_impl(), - animation_id) - ->set_is_impl_only(true); - } else { - AddAnimatedFilterToController(impl_layer->layer_animation_controller(), 1.0, - 1.f, 2.f); - impl_layer->layer_animation_controller() - ->GetAnimation(Animation::FILTER) - ->set_is_impl_only(true); - } - filters.Append(FilterOperation::CreateSepiaFilter(0.5f)); - EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetFilters(filters)); - - EXPECT_FALSE(impl_layer->LayerPropertyChanged()); - test_layer->PushPropertiesTo(impl_layer.get()); - EXPECT_FALSE(impl_layer->LayerPropertyChanged()); } TEST_F(LayerTest, MaskAndReplicaHasParent) { - scoped_refptr<Layer> parent = Layer::Create(layer_settings_); - scoped_refptr<Layer> child = Layer::Create(layer_settings_); - scoped_refptr<Layer> mask = Layer::Create(layer_settings_); - scoped_refptr<Layer> replica = Layer::Create(layer_settings_); - scoped_refptr<Layer> replica_mask = Layer::Create(layer_settings_); - scoped_refptr<Layer> mask_replacement = Layer::Create(layer_settings_); - scoped_refptr<Layer> replica_replacement = Layer::Create(layer_settings_); - scoped_refptr<Layer> replica_mask_replacement = - Layer::Create(layer_settings_); + scoped_refptr<Layer> parent = Layer::Create(); + scoped_refptr<Layer> child = Layer::Create(); + scoped_refptr<Layer> mask = Layer::Create(); + scoped_refptr<Layer> replica = Layer::Create(); + scoped_refptr<Layer> replica_mask = Layer::Create(); + scoped_refptr<Layer> mask_replacement = Layer::Create(); + scoped_refptr<Layer> replica_replacement = Layer::Create(); + scoped_refptr<Layer> replica_mask_replacement = Layer::Create(); parent->AddChild(child); child->SetMaskLayer(mask.get()); @@ -1250,7 +1782,7 @@ TEST_F(LayerTest, MaskAndReplicaHasParent) { } TEST_F(LayerTest, CheckTransformIsInvertible) { - scoped_refptr<Layer> layer = Layer::Create(layer_settings_); + scoped_refptr<Layer> layer = Layer::Create(); scoped_ptr<LayerImpl> impl_layer = LayerImpl::Create(host_impl_.active_tree(), 1); EXPECT_CALL(*layer_tree_host_, SetNeedsFullTreeSync()).Times(1); @@ -1281,7 +1813,7 @@ TEST_F(LayerTest, CheckTransformIsInvertible) { } TEST_F(LayerTest, TransformIsInvertibleAnimation) { - scoped_refptr<Layer> layer = Layer::Create(layer_settings_); + scoped_refptr<Layer> layer = Layer::Create(); scoped_ptr<LayerImpl> impl_layer = LayerImpl::Create(host_impl_.active_tree(), 1); EXPECT_CALL(*layer_tree_host_, SetNeedsFullTreeSync()).Times(1); @@ -1349,22 +1881,14 @@ void AssertLayerTreeHostMatchesForSubtree(Layer* layer, LayerTreeHost* host) { AssertLayerTreeHostMatchesForSubtree(layer->replica_layer(), host); } -class LayerLayerTreeHostTest : public testing::Test { - public: - LayerLayerTreeHostTest() { - layer_settings_.use_compositor_animation_timelines = true; - } - - protected: - LayerSettings layer_settings_; -}; +class LayerLayerTreeHostTest : public testing::Test {}; TEST_F(LayerLayerTreeHostTest, EnteringTree) { - scoped_refptr<Layer> parent = Layer::Create(layer_settings_); - scoped_refptr<Layer> child = Layer::Create(layer_settings_); - scoped_refptr<Layer> mask = Layer::Create(layer_settings_); - scoped_refptr<Layer> replica = Layer::Create(layer_settings_); - scoped_refptr<Layer> replica_mask = Layer::Create(layer_settings_); + scoped_refptr<Layer> parent = Layer::Create(); + scoped_refptr<Layer> child = Layer::Create(); + scoped_refptr<Layer> mask = Layer::Create(); + scoped_refptr<Layer> replica = Layer::Create(); + scoped_refptr<Layer> replica_mask = Layer::Create(); // Set up a detached tree of layers. The host pointer should be nil for these // layers. @@ -1391,7 +1915,7 @@ TEST_F(LayerLayerTreeHostTest, EnteringTree) { } TEST_F(LayerLayerTreeHostTest, AddingLayerSubtree) { - scoped_refptr<Layer> parent = Layer::Create(layer_settings_); + scoped_refptr<Layer> parent = Layer::Create(); LayerTreeHostFactory factory; scoped_ptr<LayerTreeHost> layer_tree_host = factory.Create(); @@ -1401,16 +1925,16 @@ TEST_F(LayerLayerTreeHostTest, AddingLayerSubtree) { // Adding a subtree to a layer already associated with a host should set the // host pointer on all layers in that subtree. - scoped_refptr<Layer> child = Layer::Create(layer_settings_); - scoped_refptr<Layer> grand_child = Layer::Create(layer_settings_); + scoped_refptr<Layer> child = Layer::Create(); + scoped_refptr<Layer> grand_child = Layer::Create(); child->AddChild(grand_child); // Masks, replicas, and replica masks should pick up the new host too. - scoped_refptr<Layer> child_mask = Layer::Create(layer_settings_); + scoped_refptr<Layer> child_mask = Layer::Create(); child->SetMaskLayer(child_mask.get()); - scoped_refptr<Layer> child_replica = Layer::Create(layer_settings_); + scoped_refptr<Layer> child_replica = Layer::Create(); child->SetReplicaLayer(child_replica.get()); - scoped_refptr<Layer> child_replica_mask = Layer::Create(layer_settings_); + scoped_refptr<Layer> child_replica_mask = Layer::Create(); child_replica->SetMaskLayer(child_replica_mask.get()); parent->AddChild(child); @@ -1420,11 +1944,11 @@ TEST_F(LayerLayerTreeHostTest, AddingLayerSubtree) { } TEST_F(LayerLayerTreeHostTest, ChangeHost) { - scoped_refptr<Layer> parent = Layer::Create(layer_settings_); - scoped_refptr<Layer> child = Layer::Create(layer_settings_); - scoped_refptr<Layer> mask = Layer::Create(layer_settings_); - scoped_refptr<Layer> replica = Layer::Create(layer_settings_); - scoped_refptr<Layer> replica_mask = Layer::Create(layer_settings_); + scoped_refptr<Layer> parent = Layer::Create(); + scoped_refptr<Layer> child = Layer::Create(); + scoped_refptr<Layer> mask = Layer::Create(); + scoped_refptr<Layer> replica = Layer::Create(); + scoped_refptr<Layer> replica_mask = Layer::Create(); // Same setup as the previous test. parent->AddChild(child); @@ -1451,11 +1975,11 @@ TEST_F(LayerLayerTreeHostTest, ChangeHost) { } TEST_F(LayerLayerTreeHostTest, ChangeHostInSubtree) { - scoped_refptr<Layer> first_parent = Layer::Create(layer_settings_); - scoped_refptr<Layer> first_child = Layer::Create(layer_settings_); - scoped_refptr<Layer> second_parent = Layer::Create(layer_settings_); - scoped_refptr<Layer> second_child = Layer::Create(layer_settings_); - scoped_refptr<Layer> second_grand_child = Layer::Create(layer_settings_); + scoped_refptr<Layer> first_parent = Layer::Create(); + scoped_refptr<Layer> first_child = Layer::Create(); + scoped_refptr<Layer> second_parent = Layer::Create(); + scoped_refptr<Layer> second_child = Layer::Create(); + scoped_refptr<Layer> second_grand_child = Layer::Create(); // First put all children under the first parent and set the first host. first_parent->AddChild(first_child); @@ -1487,13 +2011,13 @@ TEST_F(LayerLayerTreeHostTest, ChangeHostInSubtree) { } TEST_F(LayerLayerTreeHostTest, ReplaceMaskAndReplicaLayer) { - scoped_refptr<Layer> parent = Layer::Create(layer_settings_); - scoped_refptr<Layer> mask = Layer::Create(layer_settings_); - scoped_refptr<Layer> replica = Layer::Create(layer_settings_); - scoped_refptr<Layer> mask_child = Layer::Create(layer_settings_); - scoped_refptr<Layer> replica_child = Layer::Create(layer_settings_); - scoped_refptr<Layer> mask_replacement = Layer::Create(layer_settings_); - scoped_refptr<Layer> replica_replacement = Layer::Create(layer_settings_); + scoped_refptr<Layer> parent = Layer::Create(); + scoped_refptr<Layer> mask = Layer::Create(); + scoped_refptr<Layer> replica = Layer::Create(); + scoped_refptr<Layer> mask_child = Layer::Create(); + scoped_refptr<Layer> replica_child = Layer::Create(); + scoped_refptr<Layer> mask_replacement = Layer::Create(); + scoped_refptr<Layer> replica_replacement = Layer::Create(); parent->SetMaskLayer(mask.get()); parent->SetReplicaLayer(replica.get()); @@ -1521,62 +2045,19 @@ TEST_F(LayerLayerTreeHostTest, ReplaceMaskAndReplicaLayer) { } TEST_F(LayerLayerTreeHostTest, DestroyHostWithNonNullRootLayer) { - scoped_refptr<Layer> root = Layer::Create(layer_settings_); - scoped_refptr<Layer> child = Layer::Create(layer_settings_); + scoped_refptr<Layer> root = Layer::Create(); + scoped_refptr<Layer> child = Layer::Create(); root->AddChild(child); LayerTreeHostFactory factory; scoped_ptr<LayerTreeHost> layer_tree_host = factory.Create(); layer_tree_host->SetRootLayer(root); } -static bool AddTestAnimation(Layer* layer) { - scoped_ptr<KeyframedFloatAnimationCurve> curve = - KeyframedFloatAnimationCurve::Create(); - curve->AddKeyframe(FloatKeyframe::Create(base::TimeDelta(), 0.3f, nullptr)); - curve->AddKeyframe( - FloatKeyframe::Create(base::TimeDelta::FromSecondsD(1.0), 0.7f, nullptr)); - scoped_ptr<Animation> animation = - Animation::Create(std::move(curve), 0, 0, Animation::OPACITY); - - return layer->AddAnimation(std::move(animation)); -} - -TEST_F(LayerLayerTreeHostTest, ShouldNotAddAnimationWithoutAnimationRegistrar) { - // This tests isn't needed in new use_compositor_animation_timelines mode. - if (layer_settings_.use_compositor_animation_timelines) - return; - - scoped_refptr<Layer> layer = Layer::Create(layer_settings_); - - // Case 1: without a LayerTreeHost and without an AnimationRegistrar, the - // animation should not be accepted. - EXPECT_FALSE(AddTestAnimation(layer.get())); - - scoped_ptr<AnimationRegistrar> registrar = AnimationRegistrar::Create(); - layer->RegisterForAnimations(registrar.get()); - - // Case 2: with an AnimationRegistrar, the animation should be accepted. - EXPECT_TRUE(AddTestAnimation(layer.get())); - - LayerTreeSettings settings; - settings.accelerated_animation_enabled = false; - settings.use_compositor_animation_timelines = - layer_settings_.use_compositor_animation_timelines; - LayerTreeHostFactory factory; - scoped_ptr<LayerTreeHost> layer_tree_host = factory.Create(settings); - layer_tree_host->SetRootLayer(layer); - AssertLayerTreeHostMatchesForSubtree(layer.get(), layer_tree_host.get()); - - // Case 3: with a LayerTreeHost where accelerated animation is disabled, the - // animation should be rejected. - EXPECT_FALSE(AddTestAnimation(layer.get())); -} - TEST_F(LayerTest, SafeOpaqueBackgroundColor) { LayerTreeHostFactory factory; scoped_ptr<LayerTreeHost> layer_tree_host = factory.Create(); - scoped_refptr<Layer> layer = Layer::Create(layer_settings_); + scoped_refptr<Layer> layer = Layer::Create(); layer_tree_host->SetRootLayer(layer); for (int contents_opaque = 0; contents_opaque < 2; ++contents_opaque) { @@ -1588,6 +2069,8 @@ TEST_F(LayerTest, SafeOpaqueBackgroundColor) { layer_tree_host->set_background_color( host_opaque ? SK_ColorRED : SK_ColorTRANSPARENT); + layer_tree_host->property_trees()->needs_rebuild = true; + layer_tree_host->BuildPropertyTreesForTesting(); SkColor safe_color = layer->SafeOpaqueBackgroundColor(); if (contents_opaque) { EXPECT_EQ(SkColorGetA(safe_color), 255u) @@ -1605,9 +2088,8 @@ TEST_F(LayerTest, SafeOpaqueBackgroundColor) { class DrawsContentChangeLayer : public Layer { public: - static scoped_refptr<DrawsContentChangeLayer> Create( - const LayerSettings& settings) { - return make_scoped_refptr(new DrawsContentChangeLayer(settings)); + static scoped_refptr<DrawsContentChangeLayer> Create() { + return make_scoped_refptr(new DrawsContentChangeLayer()); } void SetLayerTreeHost(LayerTreeHost* host) override { @@ -1625,19 +2107,18 @@ class DrawsContentChangeLayer : public Layer { } private: - explicit DrawsContentChangeLayer(const LayerSettings& settings) - : Layer(settings), fake_draws_content_(false) {} + DrawsContentChangeLayer() : fake_draws_content_(false) {} ~DrawsContentChangeLayer() override {} bool fake_draws_content_; }; TEST_F(LayerTest, DrawsContentChangedInSetLayerTreeHost) { - scoped_refptr<Layer> root_layer = Layer::Create(layer_settings_); + scoped_refptr<Layer> root_layer = Layer::Create(); scoped_refptr<DrawsContentChangeLayer> becomes_not_draws_content = - DrawsContentChangeLayer::Create(layer_settings_); + DrawsContentChangeLayer::Create(); scoped_refptr<DrawsContentChangeLayer> becomes_draws_content = - DrawsContentChangeLayer::Create(layer_settings_); + DrawsContentChangeLayer::Create(); root_layer->SetIsDrawable(true); becomes_not_draws_content->SetIsDrawable(true); becomes_not_draws_content->SetFakeDrawsContent(true); @@ -1656,7 +2137,7 @@ void ReceiveCopyOutputResult(int* result_count, } TEST_F(LayerTest, DedupesCopyOutputRequestsBySource) { - scoped_refptr<Layer> layer = Layer::Create(layer_settings_); + scoped_refptr<Layer> layer = Layer::Create(); int result_count = 0; // Create identical requests without the source being set, and expect the @@ -1674,7 +2155,7 @@ TEST_F(LayerTest, DedupesCopyOutputRequestsBySource) { layer = nullptr; EXPECT_EQ(2, result_count); - layer = Layer::Create(layer_settings_); + layer = Layer::Create(); result_count = 0; // Create identical requests, but this time the source is being set. Expect @@ -1720,7 +2201,7 @@ TEST_F(LayerTest, DedupesCopyOutputRequestsBySource) { } TEST_F(LayerTest, AnimationSchedulesLayerUpdate) { - scoped_refptr<Layer> layer = Layer::Create(layer_settings_); + scoped_refptr<Layer> layer = Layer::Create(); EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, layer_tree_host_->SetRootLayer(layer)); EXPECT_CALL(*layer_tree_host_, SetNeedsUpdateLayers()).Times(1); @@ -1749,12 +2230,12 @@ TEST_F(LayerTest, RecursiveHierarchySerialization) { c Layer c also has a mask layer and a replica layer. */ - scoped_refptr<Layer> layer_src_root = Layer::Create(LayerSettings()); - scoped_refptr<Layer> layer_src_a = Layer::Create(LayerSettings()); - scoped_refptr<Layer> layer_src_b = Layer::Create(LayerSettings()); - scoped_refptr<Layer> layer_src_c = Layer::Create(LayerSettings()); - scoped_refptr<Layer> layer_src_c_mask = Layer::Create(LayerSettings()); - scoped_refptr<Layer> layer_src_c_replica = Layer::Create(LayerSettings()); + scoped_refptr<Layer> layer_src_root = Layer::Create(); + scoped_refptr<Layer> layer_src_a = Layer::Create(); + scoped_refptr<Layer> layer_src_b = Layer::Create(); + scoped_refptr<Layer> layer_src_c = Layer::Create(); + scoped_refptr<Layer> layer_src_c_mask = Layer::Create(); + scoped_refptr<Layer> layer_src_c_replica = Layer::Create(); layer_src_root->AddChild(layer_src_a); layer_src_root->AddChild(layer_src_b); layer_src_b->AddChild(layer_src_c); @@ -1765,8 +2246,9 @@ TEST_F(LayerTest, RecursiveHierarchySerialization) { layer_src_root->ToLayerNodeProto(&proto); Layer::LayerIdMap empty_dest_layer_map; - scoped_refptr<Layer> layer_dest_root = Layer::Create(LayerSettings()); - layer_dest_root->FromLayerNodeProto(proto, empty_dest_layer_map); + scoped_refptr<Layer> layer_dest_root = Layer::Create(); + layer_dest_root->FromLayerNodeProto(proto, empty_dest_layer_map, + layer_tree_host_.get()); EXPECT_EQ(layer_src_root->id(), layer_dest_root->id()); EXPECT_EQ(nullptr, layer_dest_root->parent()); @@ -1788,6 +2270,8 @@ TEST_F(LayerTest, RecursiveHierarchySerialization) { EXPECT_EQ(0u, layer_dest_c->children().size()); EXPECT_EQ(layer_src_c_mask->id(), layer_dest_c->mask_layer()->id()); EXPECT_EQ(layer_src_c_replica->id(), layer_dest_c->replica_layer()->id()); + + layer_dest_root->SetLayerTreeHost(nullptr); } TEST_F(LayerTest, RecursiveHierarchySerializationWithNodeReuse) { @@ -1803,16 +2287,17 @@ TEST_F(LayerTest, RecursiveHierarchySerializationWithNodeReuse) { The deserialization should then re-use the Layers from last deserialization. */ - scoped_refptr<Layer> layer_src_root = Layer::Create(LayerSettings()); - scoped_refptr<Layer> layer_src_a = Layer::Create(LayerSettings()); + scoped_refptr<Layer> layer_src_root = Layer::Create(); + scoped_refptr<Layer> layer_src_a = Layer::Create(); layer_src_root->AddChild(layer_src_a); proto::LayerNode root_proto_1; layer_src_root->ToLayerNodeProto(&root_proto_1); Layer::LayerIdMap dest_layer_map_1; - scoped_refptr<Layer> layer_dest_root = Layer::Create(LayerSettings()); - layer_dest_root->FromLayerNodeProto(root_proto_1, dest_layer_map_1); + scoped_refptr<Layer> layer_dest_root = Layer::Create(); + layer_dest_root->FromLayerNodeProto(root_proto_1, dest_layer_map_1, + layer_tree_host_.get()); EXPECT_EQ(layer_src_root->id(), layer_dest_root->id()); ASSERT_EQ(1u, layer_dest_root->children().size()); @@ -1821,11 +2306,11 @@ TEST_F(LayerTest, RecursiveHierarchySerializationWithNodeReuse) { // Setup new destination layer map. Layer::LayerIdMap dest_layer_map_2; - dest_layer_map_2[layer_dest_root->id()] = layer_dest_root; - dest_layer_map_2[layer_dest_a_1->id()] = layer_dest_a_1; + layer_dest_root->ClearLayerTreePropertiesForDeserializationAndAddToMap( + &dest_layer_map_2); // Add Layer |b|. - scoped_refptr<Layer> layer_src_b = Layer::Create(LayerSettings()); + scoped_refptr<Layer> layer_src_b = Layer::Create(); layer_src_root->AddChild(layer_src_b); // Second serialization. @@ -1833,7 +2318,8 @@ TEST_F(LayerTest, RecursiveHierarchySerializationWithNodeReuse) { layer_src_root->ToLayerNodeProto(&root_proto_2); // Second deserialization. - layer_dest_root->FromLayerNodeProto(root_proto_2, dest_layer_map_2); + layer_dest_root->FromLayerNodeProto(root_proto_2, dest_layer_map_2, + layer_tree_host_.get()); EXPECT_EQ(layer_src_root->id(), layer_dest_root->id()); ASSERT_EQ(2u, layer_dest_root->children().size()); @@ -1850,6 +2336,8 @@ TEST_F(LayerTest, RecursiveHierarchySerializationWithNodeReuse) { // Layer |a| should be the same. EXPECT_EQ(layer_dest_a_1.get(), layer_dest_a_2.get()); + + layer_dest_root->SetLayerTreeHost(nullptr); } TEST_F(LayerTest, DeletingSubtreeDeletesLayers) { @@ -1864,11 +2352,11 @@ TEST_F(LayerTest, DeletingSubtreeDeletesLayers) { d Then the subtree rooted at node |b| is deleted in the next update. */ - scoped_refptr<Layer> layer_src_root = Layer::Create(LayerSettings()); - scoped_refptr<Layer> layer_src_a = Layer::Create(LayerSettings()); - scoped_refptr<Layer> layer_src_b = Layer::Create(LayerSettings()); - scoped_refptr<Layer> layer_src_c = Layer::Create(LayerSettings()); - scoped_refptr<Layer> layer_src_d = Layer::Create(LayerSettings()); + scoped_refptr<Layer> layer_src_root = Layer::Create(); + scoped_refptr<Layer> layer_src_a = Layer::Create(); + scoped_refptr<Layer> layer_src_b = Layer::Create(); + scoped_refptr<Layer> layer_src_c = Layer::Create(); + scoped_refptr<Layer> layer_src_d = Layer::Create(); layer_src_root->AddChild(layer_src_a); layer_src_root->AddChild(layer_src_b); layer_src_b->AddChild(layer_src_c); @@ -1880,8 +2368,9 @@ TEST_F(LayerTest, DeletingSubtreeDeletesLayers) { // Deserialization 1. Layer::LayerIdMap empty_dest_layer_map; - scoped_refptr<Layer> layer_dest_root = Layer::Create(LayerSettings()); - layer_dest_root->FromLayerNodeProto(proto1, empty_dest_layer_map); + scoped_refptr<Layer> layer_dest_root = Layer::Create(); + layer_dest_root->FromLayerNodeProto(proto1, empty_dest_layer_map, + layer_tree_host_.get()); EXPECT_EQ(layer_src_root->id(), layer_dest_root->id()); ASSERT_EQ(2u, layer_dest_root->children().size()); @@ -1901,19 +2390,21 @@ TEST_F(LayerTest, DeletingSubtreeDeletesLayers) { // Deserialization 2. Layer::LayerIdMap dest_layer_map_2; - dest_layer_map_2[layer_dest_root->id()] = layer_dest_root; - dest_layer_map_2[layer_dest_a->id()] = layer_dest_a; - dest_layer_map_2[layer_dest_b->id()] = layer_dest_b; - layer_dest_root->FromLayerNodeProto(proto2, dest_layer_map_2); + layer_dest_root->ClearLayerTreePropertiesForDeserializationAndAddToMap( + &dest_layer_map_2); + layer_dest_root->FromLayerNodeProto(proto2, dest_layer_map_2, + layer_tree_host_.get()); EXPECT_EQ(0u, layer_dest_a->children().size()); EXPECT_EQ(0u, layer_dest_b->children().size()); + + layer_dest_root->SetLayerTreeHost(nullptr); } TEST_F(LayerTest, DeleteMaskAndReplicaLayer) { - scoped_refptr<Layer> layer_src_root = Layer::Create(LayerSettings()); - scoped_refptr<Layer> layer_src_mask = Layer::Create(LayerSettings()); - scoped_refptr<Layer> layer_src_replica = Layer::Create(LayerSettings()); + scoped_refptr<Layer> layer_src_root = Layer::Create(); + scoped_refptr<Layer> layer_src_mask = Layer::Create(); + scoped_refptr<Layer> layer_src_replica = Layer::Create(); layer_src_root->SetMaskLayer(layer_src_mask.get()); layer_src_root->SetReplicaLayer(layer_src_replica.get()); @@ -1923,8 +2414,9 @@ TEST_F(LayerTest, DeleteMaskAndReplicaLayer) { // Deserialization 1. Layer::LayerIdMap dest_layer_map; - scoped_refptr<Layer> layer_dest_root = Layer::Create(LayerSettings()); - layer_dest_root->FromLayerNodeProto(proto1, dest_layer_map); + scoped_refptr<Layer> layer_dest_root = Layer::Create(); + layer_dest_root->FromLayerNodeProto(proto1, dest_layer_map, + layer_tree_host_.get()); EXPECT_EQ(layer_src_root->id(), layer_dest_root->id()); ASSERT_TRUE(layer_dest_root->mask_layer()); @@ -1935,13 +2427,6 @@ TEST_F(LayerTest, DeleteMaskAndReplicaLayer) { EXPECT_EQ(layer_src_root->replica_layer()->id(), layer_dest_root->replica_layer()->id()); - // Store the newly constructed layer structure in the id map. - dest_layer_map[layer_dest_root->id()] = layer_dest_root; - dest_layer_map[layer_dest_root->mask_layer()->id()] = - layer_dest_root->mask_layer(); - dest_layer_map[layer_dest_root->replica_layer()->id()] = - layer_dest_root->replica_layer(); - // Clear mask and replica layers. layer_src_root->mask_layer()->RemoveFromParent(); layer_src_root->replica_layer()->RemoveFromParent(); @@ -1951,148 +2436,45 @@ TEST_F(LayerTest, DeleteMaskAndReplicaLayer) { layer_src_root->ToLayerNodeProto(&proto2); // Deserialization 2. - layer_dest_root->FromLayerNodeProto(proto2, dest_layer_map); + layer_dest_root->ClearLayerTreePropertiesForDeserializationAndAddToMap( + &dest_layer_map); + layer_dest_root->FromLayerNodeProto(proto2, dest_layer_map, + layer_tree_host_.get()); EXPECT_EQ(nullptr, layer_dest_root->mask_layer()); EXPECT_EQ(nullptr, layer_dest_root->replica_layer()); + + layer_dest_root->SetLayerTreeHost(nullptr); } -TEST_F(LayerTest, SimplePropertiesSerialization) { - /* Testing serialization of properties for a tree that looks like this: - root+ - / \ - a* b*+[mask:*,replica] - / \ - c d* - Layers marked with * have changed properties. - Layers marked with + have descendants with changed properties. - Layer b also has a mask layer and a replica layer. - */ - scoped_refptr<Layer> layer_src_root = Layer::Create(LayerSettings()); - scoped_refptr<Layer> layer_src_a = Layer::Create(LayerSettings()); - scoped_refptr<Layer> layer_src_b = Layer::Create(LayerSettings()); - scoped_refptr<Layer> layer_src_b_mask = Layer::Create(LayerSettings()); - scoped_refptr<Layer> layer_src_b_replica = Layer::Create(LayerSettings()); - scoped_refptr<Layer> layer_src_c = Layer::Create(LayerSettings()); - scoped_refptr<Layer> layer_src_d = Layer::Create(LayerSettings()); - layer_src_root->AddChild(layer_src_a); - layer_src_root->AddChild(layer_src_b); - layer_src_a->AddChild(layer_src_c); - layer_src_b->AddChild(layer_src_d); - layer_src_b->SetMaskLayer(layer_src_b_mask.get()); - layer_src_b->SetReplicaLayer(layer_src_b_replica.get()); - - layer_src_a->SetNeedsPushProperties(); - layer_src_b->SetNeedsPushProperties(); - layer_src_b_mask->SetNeedsPushProperties(); - layer_src_d->SetNeedsPushProperties(); - - // Only layers with descendants that require pushing properties will - // return true from ToLayerPropertiesProto. - proto::LayerUpdate layer_update_root; - EXPECT_TRUE(layer_src_root->ToLayerPropertiesProto(&layer_update_root)); - proto::LayerUpdate layer_update_a; - EXPECT_FALSE(layer_src_a->ToLayerPropertiesProto(&layer_update_a)); - proto::LayerUpdate layer_update_b; - EXPECT_TRUE(layer_src_b->ToLayerPropertiesProto(&layer_update_b)); - proto::LayerUpdate layer_update_b_mask; - EXPECT_FALSE(layer_src_b_mask->ToLayerPropertiesProto(&layer_update_b_mask)); - proto::LayerUpdate layer_update_b_replica; - EXPECT_FALSE( - layer_src_b_replica->ToLayerPropertiesProto(&layer_update_b_replica)); - proto::LayerUpdate layer_update_c; - EXPECT_FALSE(layer_src_c->ToLayerPropertiesProto(&layer_update_c)); - proto::LayerUpdate layer_update_d; - EXPECT_FALSE(layer_src_d->ToLayerPropertiesProto(&layer_update_d)); - - // All flags for pushing properties should have been cleared. - EXPECT_FALSE(layer_src_root->needs_push_properties()); - EXPECT_FALSE(layer_src_root->descendant_needs_push_properties()); - EXPECT_FALSE(layer_src_a->needs_push_properties()); - EXPECT_FALSE(layer_src_a->descendant_needs_push_properties()); - EXPECT_FALSE(layer_src_b->needs_push_properties()); - EXPECT_FALSE(layer_src_b->descendant_needs_push_properties()); - EXPECT_FALSE(layer_src_b_mask->needs_push_properties()); - EXPECT_FALSE(layer_src_b_mask->descendant_needs_push_properties()); - EXPECT_FALSE(layer_src_b_replica->needs_push_properties()); - EXPECT_FALSE(layer_src_b_replica->descendant_needs_push_properties()); - EXPECT_FALSE(layer_src_c->needs_push_properties()); - EXPECT_FALSE(layer_src_c->descendant_needs_push_properties()); - EXPECT_FALSE(layer_src_d->needs_push_properties()); - EXPECT_FALSE(layer_src_d->descendant_needs_push_properties()); - - // Only 5 of the layers should have been serialized. - ASSERT_EQ(1, layer_update_root.layers_size()); - EXPECT_EQ(layer_src_root->id(), layer_update_root.layers(0).id()); - proto::LayerProperties dest_root = layer_update_root.layers(0); - ASSERT_EQ(1, layer_update_a.layers_size()); - EXPECT_EQ(layer_src_a->id(), layer_update_a.layers(0).id()); - proto::LayerProperties dest_a = layer_update_a.layers(0); - ASSERT_EQ(1, layer_update_b.layers_size()); - EXPECT_EQ(layer_src_b->id(), layer_update_b.layers(0).id()); - proto::LayerProperties dest_b = layer_update_b.layers(0); - ASSERT_EQ(1, layer_update_b_mask.layers_size()); - EXPECT_EQ(layer_src_b_mask->id(), layer_update_b_mask.layers(0).id()); - proto::LayerProperties dest_b_mask = layer_update_b_mask.layers(0); - EXPECT_EQ(0, layer_update_b_replica.layers_size()); - EXPECT_EQ(0, layer_update_c.layers_size()); - ASSERT_EQ(1, layer_update_d.layers_size()); - EXPECT_EQ(layer_src_d->id(), layer_update_d.layers(0).id()); - proto::LayerProperties dest_d = layer_update_d.layers(0); - - // Ensure the properties and dependants metadata is correctly serialized. - EXPECT_FALSE(dest_root.needs_push_properties()); - EXPECT_EQ(2, dest_root.num_dependents_need_push_properties()); - EXPECT_FALSE(dest_root.has_base()); - - EXPECT_TRUE(dest_a.needs_push_properties()); - EXPECT_EQ(0, dest_a.num_dependents_need_push_properties()); - EXPECT_TRUE(dest_a.has_base()); - - EXPECT_TRUE(dest_b.needs_push_properties()); - EXPECT_EQ(2, dest_b.num_dependents_need_push_properties()); - EXPECT_TRUE(dest_b.has_base()); - - EXPECT_TRUE(dest_d.needs_push_properties()); - EXPECT_EQ(0, dest_d.num_dependents_need_push_properties()); - EXPECT_TRUE(dest_d.has_base()); - - EXPECT_TRUE(dest_b_mask.needs_push_properties()); - EXPECT_EQ(0, dest_b_mask.num_dependents_need_push_properties()); - EXPECT_TRUE(dest_b_mask.has_base()); +TEST_F(LayerSerializationTest, HierarchyDeserializationWithLayerTreeHost) { + RunHierarchyDeserializationWithLayerTreeHostTest(); +} + +TEST_F(LayerSerializationTest, NonDestructiveDeserializationBaseCase) { + RunNonDestructiveDeserializationBaseCaseTest(); +} + +TEST_F(LayerSerializationTest, NonDestructiveDeserializationReorderChildren) { + RunNonDestructiveDeserializationReorderChildrenTest(); +} + +TEST_F(LayerSerializationTest, NonDestructiveDeserializationAddChild) { + RunNonDestructiveDeserializationAddChildTest(); +} + +TEST_F(LayerSerializationTest, NonDestructiveDeserializationRemoveChild) { + RunNonDestructiveDeserializationRemoveChildTest(); +} + +TEST_F(LayerSerializationTest, + NonDestructiveDeserializationMoveChildEarlierTest) { + RunNonDestructiveDeserializationMoveChildEarlierTest(); } -TEST_F(LayerSerializationTest, SimplePropertiesDeserialization) { - scoped_refptr<Layer> layer = Layer::Create(LayerSettings()); - layer->SetLayerTreeHost(layer_tree_host_.get()); - proto::LayerProperties properties; - properties.set_id(layer->id()); - - properties.set_needs_push_properties(true); - properties.set_num_dependents_need_push_properties(2); - properties.mutable_base(); - layer->FromLayerPropertiesProto(properties); - EXPECT_TRUE(layer->needs_push_properties()); - EXPECT_TRUE(layer->descendant_needs_push_properties()); - - properties.set_needs_push_properties(false); - properties.mutable_base()->Clear(); - layer->FromLayerPropertiesProto(properties); - EXPECT_FALSE(layer->needs_push_properties()); - EXPECT_TRUE(layer->descendant_needs_push_properties()); - - properties.set_num_dependents_need_push_properties(0); - layer->FromLayerPropertiesProto(properties); - EXPECT_FALSE(layer->needs_push_properties()); - EXPECT_FALSE(layer->descendant_needs_push_properties()); - - properties.set_needs_push_properties(true); - properties.mutable_base(); - layer->FromLayerPropertiesProto(properties); - EXPECT_TRUE(layer->needs_push_properties()); - EXPECT_FALSE(layer->descendant_needs_push_properties()); - - layer->SetLayerTreeHost(nullptr); +TEST_F(LayerSerializationTest, + NonDestructiveDeserializationMoveChildLaterTest) { + RunNonDestructiveDeserializationMoveChildLaterTest(); } TEST_F(LayerSerializationTest, NoMembersChanged) { @@ -2112,7 +2494,7 @@ TEST_F(LayerSerializationTest, ScrollAndClipLayers) { } TEST_F(LayerTest, ElementIdAndMutablePropertiesArePushed) { - scoped_refptr<Layer> test_layer = Layer::Create(layer_settings_); + scoped_refptr<Layer> test_layer = Layer::Create(); scoped_ptr<LayerImpl> impl_layer = LayerImpl::Create(host_impl_.active_tree(), 1); @@ -2122,15 +2504,15 @@ TEST_F(LayerTest, ElementIdAndMutablePropertiesArePushed) { EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(2); test_layer->SetElementId(2); - test_layer->SetMutableProperties(kMutablePropertyTransform); + test_layer->SetMutableProperties(MutableProperty::kTransform); EXPECT_EQ(0lu, impl_layer->element_id()); - EXPECT_EQ(kMutablePropertyNone, impl_layer->mutable_properties()); + EXPECT_EQ(MutableProperty::kNone, impl_layer->mutable_properties()); test_layer->PushPropertiesTo(impl_layer.get()); EXPECT_EQ(2lu, impl_layer->element_id()); - EXPECT_EQ(kMutablePropertyTransform, impl_layer->mutable_properties()); + EXPECT_EQ(MutableProperty::kTransform, impl_layer->mutable_properties()); } } // namespace |