summaryrefslogtreecommitdiffstats
path: root/chromium/cc/layers/layer_unittest.cc
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@qt.io>2017-03-08 10:28:10 +0100
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2017-03-20 13:40:30 +0000
commite733310db58160074f574c429d48f8308c0afe17 (patch)
treef8aef4b7e62a69928dbcf880620eece20f98c6df /chromium/cc/layers/layer_unittest.cc
parent2f583e4aec1ae3a86fa047829c96b310dc12ecdf (diff)
BASELINE: Update Chromium to 56.0.2924.122
Change-Id: I4e04de8f47e47e501c46ed934c76a431c6337ced Reviewed-by: Michael BrĂ¼ning <michael.bruning@qt.io>
Diffstat (limited to 'chromium/cc/layers/layer_unittest.cc')
-rw-r--r--chromium/cc/layers/layer_unittest.cc1136
1 files changed, 43 insertions, 1093 deletions
diff --git a/chromium/cc/layers/layer_unittest.cc b/chromium/cc/layers/layer_unittest.cc
index 11d6facce8d..0c2858f5505 100644
--- a/chromium/cc/layers/layer_unittest.cc
+++ b/chromium/cc/layers/layer_unittest.cc
@@ -10,14 +10,12 @@
#include "cc/animation/animation_host.h"
#include "cc/animation/animation_id_provider.h"
#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/solid_color_scrollbar_layer.h"
#include "cc/output/copy_output_request.h"
#include "cc/output/copy_output_result.h"
-#include "cc/proto/layer.pb.h"
#include "cc/test/animation_test_common.h"
#include "cc/test/fake_impl_task_runner_provider.h"
#include "cc/test/fake_layer_tree_host.h"
@@ -27,10 +25,9 @@
#include "cc/test/layer_internals_for_test.h"
#include "cc/test/layer_test_common.h"
#include "cc/test/stub_layer_tree_host_single_thread_client.h"
-#include "cc/test/test_gpu_memory_buffer_manager.h"
-#include "cc/test/test_shared_bitmap_manager.h"
#include "cc/test/test_task_graph_runner.h"
#include "cc/trees/layer_tree_host.h"
+#include "cc/trees/mutable_properties.h"
#include "cc/trees/single_thread_proxy.h"
#include "cc/trees/transform_node.h"
#include "testing/gmock/include/gmock/gmock.h"
@@ -84,799 +81,13 @@ using ::testing::_;
namespace cc {
-// This class is a friend of Layer, and is used as a wrapper for all the tests
-// related to proto serialization. This is done so that it is unnecessary to
-// add FRIEND_TEST_ALL_PREFIXES in //cc/layers/layer.h for all the tests.
-// It is in the cc namespace so that it can be a friend of Layer.
-// The tests still have helpful names, and a test with the name FooBar would
-// have a wrapper method in this class called RunFooBarTest.
-class LayerSerializationTest : public testing::Test {
- protected:
- void SetUp() override {
- layer_tree_host_ =
- FakeLayerTreeHost::Create(&fake_client_, &task_graph_runner_);
- }
-
- void TearDown() override {
- layer_tree_host_->SetRootLayer(nullptr);
- layer_tree_host_ = nullptr;
- }
-
- // Serializes |src| to proto and back again to a Layer, then verifies that
- // the two Layers are equal for serialization purposes.
- void VerifyBaseLayerPropertiesSerializationAndDeserialization(Layer* src) {
- // This is required to ensure that properties are serialized.
- src->SetNeedsPushProperties();
- src->SetLayerTreeHost(layer_tree_host_.get());
-
- // The following member is reset during serialization, so store the original
- // values.
- gfx::Rect update_rect = src->inputs_.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;
- src->ToLayerPropertiesProto(&layer_update, false);
- ASSERT_EQ(1, layer_update.layers_size());
- proto::LayerProperties props = layer_update.layers(0);
-
- // The |dest| layer needs to be able to lookup the scroll and clip parents.
- LayerTree* layer_tree = layer_tree_host_->GetLayerTree();
- if (src->inputs_.scroll_parent)
- layer_tree->RegisterLayer(src->inputs_.scroll_parent);
- if (src->scroll_children_) {
- for (auto* child : *(src->scroll_children_))
- layer_tree->RegisterLayer(child);
- }
- if (src->inputs_.clip_parent)
- layer_tree->RegisterLayer(src->inputs_.clip_parent);
- if (src->clip_children_) {
- for (auto* child : *(src->clip_children_))
- layer_tree->RegisterLayer(child);
- }
- // Reset the LayerTreeHost registration for the |src| layer so
- // it can be re-used for the |dest| layer.
- src->SetLayerTreeHost(nullptr);
-
- scoped_refptr<Layer> dest = Layer::Create();
- dest->inputs_.layer_id = src->inputs_.layer_id;
- dest->SetLayerTreeHost(layer_tree_host_.get());
- dest->FromLayerPropertiesProto(props);
-
- // Verify that both layers are equal.
- EXPECT_EQ(src->inputs_.transform_origin, dest->inputs_.transform_origin);
- EXPECT_EQ(src->inputs_.background_color, dest->inputs_.background_color);
- EXPECT_EQ(src->inputs_.bounds, dest->inputs_.bounds);
- EXPECT_EQ(src->transform_tree_index_, dest->transform_tree_index_);
- EXPECT_EQ(src->effect_tree_index_, dest->effect_tree_index_);
- EXPECT_EQ(src->clip_tree_index_, dest->clip_tree_index_);
- EXPECT_EQ(src->offset_to_transform_parent_,
- dest->offset_to_transform_parent_);
- EXPECT_EQ(src->inputs_.double_sided, dest->inputs_.double_sided);
- EXPECT_EQ(src->draws_content_, dest->draws_content_);
- EXPECT_EQ(src->may_contain_video_, dest->may_contain_video_);
- EXPECT_EQ(src->inputs_.hide_layer_and_subtree,
- dest->inputs_.hide_layer_and_subtree);
- EXPECT_EQ(src->inputs_.masks_to_bounds, dest->inputs_.masks_to_bounds);
- EXPECT_EQ(src->inputs_.main_thread_scrolling_reasons,
- dest->inputs_.main_thread_scrolling_reasons);
- EXPECT_EQ(src->inputs_.non_fast_scrollable_region,
- dest->inputs_.non_fast_scrollable_region);
- EXPECT_EQ(src->inputs_.touch_event_handler_region,
- dest->inputs_.touch_event_handler_region);
- EXPECT_EQ(src->inputs_.contents_opaque, dest->inputs_.contents_opaque);
- EXPECT_EQ(src->inputs_.opacity, dest->inputs_.opacity);
- EXPECT_EQ(src->inputs_.blend_mode, dest->inputs_.blend_mode);
- EXPECT_EQ(src->inputs_.is_root_for_isolated_group,
- dest->inputs_.is_root_for_isolated_group);
- EXPECT_EQ(src->inputs_.position, dest->inputs_.position);
- EXPECT_EQ(src->inputs_.is_container_for_fixed_position_layers,
- dest->inputs_.is_container_for_fixed_position_layers);
- EXPECT_EQ(src->inputs_.position_constraint,
- dest->inputs_.position_constraint);
- EXPECT_EQ(src->inputs_.should_flatten_transform,
- dest->inputs_.should_flatten_transform);
- EXPECT_EQ(src->should_flatten_transform_from_property_tree_,
- dest->should_flatten_transform_from_property_tree_);
- EXPECT_EQ(src->draw_blend_mode_, dest->draw_blend_mode_);
- EXPECT_EQ(src->inputs_.use_parent_backface_visibility,
- dest->inputs_.use_parent_backface_visibility);
- EXPECT_EQ(src->inputs_.transform, dest->inputs_.transform);
- EXPECT_EQ(src->inputs_.sorting_context_id,
- dest->inputs_.sorting_context_id);
- EXPECT_EQ(src->num_descendants_that_draw_content_,
- dest->num_descendants_that_draw_content_);
- EXPECT_EQ(src->inputs_.scroll_clip_layer_id,
- dest->inputs_.scroll_clip_layer_id);
- EXPECT_EQ(src->inputs_.user_scrollable_horizontal,
- dest->inputs_.user_scrollable_horizontal);
- EXPECT_EQ(src->inputs_.user_scrollable_vertical,
- dest->inputs_.user_scrollable_vertical);
- EXPECT_EQ(src->inputs_.scroll_offset, dest->inputs_.scroll_offset);
- EXPECT_EQ(update_rect, dest->inputs_.update_rect);
-
- if (src->inputs_.scroll_parent) {
- ASSERT_TRUE(dest->inputs_.scroll_parent);
- EXPECT_EQ(src->inputs_.scroll_parent->id(),
- dest->inputs_.scroll_parent->id());
- } else {
- EXPECT_FALSE(dest->inputs_.scroll_parent);
- }
- if (src->scroll_children_) {
- ASSERT_TRUE(dest->scroll_children_);
- EXPECT_EQ(*(src->scroll_children_), *(dest->scroll_children_));
- } else {
- EXPECT_FALSE(dest->scroll_children_);
- }
-
- if (src->inputs_.clip_parent) {
- ASSERT_TRUE(dest->inputs_.clip_parent);
- EXPECT_EQ(src->inputs_.clip_parent->id(),
- dest->inputs_.clip_parent->id());
- } else {
- ASSERT_FALSE(dest->inputs_.clip_parent);
- }
- if (src->clip_children_) {
- ASSERT_TRUE(dest->clip_children_);
- EXPECT_EQ(*(src->clip_children_), *(dest->clip_children_));
- } else {
- EXPECT_FALSE(dest->clip_children_);
- }
-
- // The following member should have been reset during serialization.
- EXPECT_EQ(gfx::Rect(), src->inputs_.update_rect);
-
- // Before deleting |dest|, the LayerTreeHost must be unset.
- dest->SetLayerTreeHost(nullptr);
-
- // Cleanup scroll tree.
- if (src->inputs_.scroll_parent)
- layer_tree->UnregisterLayer(src->inputs_.scroll_parent);
- src->inputs_.scroll_parent = nullptr;
- dest->inputs_.scroll_parent = nullptr;
- if (src->scroll_children_) {
- for (auto* child : *(src->scroll_children_))
- layer_tree->UnregisterLayer(child);
- src->scroll_children_.reset();
- dest->scroll_children_.reset();
- }
-
- // Cleanup clip tree.
- if (src->inputs_.clip_parent)
- layer_tree->UnregisterLayer(src->inputs_.clip_parent);
- src->inputs_.clip_parent = nullptr;
- dest->inputs_.clip_parent = nullptr;
- if (src->clip_children_) {
- for (auto* child : *(src->clip_children_))
- layer_tree->UnregisterLayer(child);
- src->clip_children_.reset();
- dest->clip_children_.reset();
- }
- }
-
- void RunNoMembersChangedTest() {
- scoped_refptr<Layer> layer = Layer::Create();
- VerifyBaseLayerPropertiesSerializationAndDeserialization(layer.get());
- }
-
- void RunArbitraryMembersChangedTest() {
- scoped_refptr<Layer> layer = Layer::Create();
- layer->inputs_.transform_origin = gfx::Point3F(3.0f, 1.0f, 4.0f);
- layer->inputs_.background_color = SK_ColorRED;
- layer->inputs_.bounds = gfx::Size(3, 14);
- layer->transform_tree_index_ = -1;
- layer->effect_tree_index_ = -1;
- layer->clip_tree_index_ = 71;
- layer->offset_to_transform_parent_ = gfx::Vector2dF(3.14f, 1.618f);
- layer->inputs_.double_sided = true;
- layer->draws_content_ = true;
- layer->may_contain_video_ = true;
- layer->inputs_.hide_layer_and_subtree = false;
- layer->inputs_.masks_to_bounds = true;
- layer->inputs_.main_thread_scrolling_reasons =
- MainThreadScrollingReason::kNotScrollingOnMain;
- layer->inputs_.non_fast_scrollable_region = Region(gfx::Rect(5, 1, 14, 3));
- layer->inputs_.touch_event_handler_region = Region(gfx::Rect(3, 14, 1, 5));
- layer->inputs_.contents_opaque = true;
- layer->inputs_.opacity = 1.f;
- layer->inputs_.blend_mode = SkXfermode::kSrcOver_Mode;
- layer->inputs_.is_root_for_isolated_group = true;
- layer->inputs_.position = gfx::PointF(3.14f, 6.28f);
- layer->inputs_.is_container_for_fixed_position_layers = true;
- LayerPositionConstraint pos_con;
- pos_con.set_is_fixed_to_bottom_edge(true);
- layer->inputs_.position_constraint = pos_con;
- layer->inputs_.should_flatten_transform = true;
- layer->should_flatten_transform_from_property_tree_ = true;
- layer->draw_blend_mode_ = SkXfermode::kSrcOut_Mode;
- layer->inputs_.use_parent_backface_visibility = true;
- gfx::Transform transform;
- transform.Rotate(90);
- layer->inputs_.transform = transform;
- layer->inputs_.sorting_context_id = 0;
- layer->num_descendants_that_draw_content_ = 5;
- layer->inputs_.scroll_clip_layer_id = Layer::INVALID_ID;
- layer->inputs_.user_scrollable_horizontal = false;
- layer->inputs_.user_scrollable_vertical = true;
- layer->inputs_.scroll_offset = gfx::ScrollOffset(3, 14);
- layer->inputs_.update_rect = gfx::Rect(14, 15);
-
- VerifyBaseLayerPropertiesSerializationAndDeserialization(layer.get());
- }
-
- void RunAllMembersChangedTest() {
- scoped_refptr<Layer> layer = Layer::Create();
- layer->inputs_.transform_origin = gfx::Point3F(3.0f, 1.0f, 4.0f);
- layer->inputs_.background_color = SK_ColorRED;
- layer->inputs_.bounds = gfx::Size(3, 14);
- layer->transform_tree_index_ = 39;
- layer->effect_tree_index_ = 17;
- layer->clip_tree_index_ = 71;
- layer->offset_to_transform_parent_ = gfx::Vector2dF(3.14f, 1.618f);
- layer->inputs_.double_sided = !layer->inputs_.double_sided;
- layer->draws_content_ = !layer->draws_content_;
- layer->may_contain_video_ = !layer->may_contain_video_;
- layer->inputs_.hide_layer_and_subtree =
- !layer->inputs_.hide_layer_and_subtree;
- layer->inputs_.masks_to_bounds = !layer->inputs_.masks_to_bounds;
- layer->inputs_.main_thread_scrolling_reasons =
- MainThreadScrollingReason::kHasBackgroundAttachmentFixedObjects;
- layer->inputs_.non_fast_scrollable_region = Region(gfx::Rect(5, 1, 14, 3));
- layer->inputs_.touch_event_handler_region = Region(gfx::Rect(3, 14, 1, 5));
- layer->inputs_.contents_opaque = !layer->inputs_.contents_opaque;
- layer->inputs_.opacity = 3.14f;
- layer->inputs_.blend_mode = SkXfermode::kSrcIn_Mode;
- layer->inputs_.is_root_for_isolated_group =
- !layer->inputs_.is_root_for_isolated_group;
- layer->inputs_.position = gfx::PointF(3.14f, 6.28f);
- layer->inputs_.is_container_for_fixed_position_layers =
- !layer->inputs_.is_container_for_fixed_position_layers;
- LayerPositionConstraint pos_con;
- pos_con.set_is_fixed_to_bottom_edge(true);
- layer->inputs_.position_constraint = pos_con;
- layer->inputs_.should_flatten_transform =
- !layer->inputs_.should_flatten_transform;
- layer->should_flatten_transform_from_property_tree_ =
- !layer->should_flatten_transform_from_property_tree_;
- layer->draw_blend_mode_ = SkXfermode::kSrcOut_Mode;
- layer->inputs_.use_parent_backface_visibility =
- !layer->inputs_.use_parent_backface_visibility;
- gfx::Transform transform;
- transform.Rotate(90);
- layer->inputs_.transform = transform;
- layer->inputs_.sorting_context_id = 42;
- layer->num_descendants_that_draw_content_ = 5;
- layer->inputs_.scroll_clip_layer_id = 17;
- layer->inputs_.user_scrollable_horizontal =
- !layer->inputs_.user_scrollable_horizontal;
- layer->inputs_.user_scrollable_vertical =
- !layer->inputs_.user_scrollable_vertical;
- layer->inputs_.scroll_offset = gfx::ScrollOffset(3, 14);
- layer->inputs_.update_rect = gfx::Rect(14, 15);
-
- VerifyBaseLayerPropertiesSerializationAndDeserialization(layer.get());
- }
-
- void VerifySolidColorScrollbarLayerAfterSerializationAndDeserialization(
- scoped_refptr<SolidColorScrollbarLayer> source_scrollbar) {
- proto::LayerProperties serialized_scrollbar;
- source_scrollbar->LayerSpecificPropertiesToProto(&serialized_scrollbar,
- false);
-
- scoped_refptr<SolidColorScrollbarLayer> deserialized_scrollbar =
- SolidColorScrollbarLayer::Create(ScrollbarOrientation::HORIZONTAL, -1,
- -1, false, Layer::INVALID_ID);
- deserialized_scrollbar->inputs_.layer_id =
- source_scrollbar->inputs_.layer_id;
-
- // FromLayerSpecificPropertiesProto expects a non-null LayerTreeHost to be
- // set.
- deserialized_scrollbar->SetLayerTreeHost(layer_tree_host_.get());
- deserialized_scrollbar->FromLayerSpecificPropertiesProto(
- serialized_scrollbar);
-
- EXPECT_EQ(source_scrollbar->solid_color_scrollbar_layer_inputs_.track_start,
- deserialized_scrollbar->solid_color_scrollbar_layer_inputs_
- .track_start);
- EXPECT_EQ(
- source_scrollbar->solid_color_scrollbar_layer_inputs_.thumb_thickness,
- deserialized_scrollbar->solid_color_scrollbar_layer_inputs_
- .thumb_thickness);
- EXPECT_EQ(
- source_scrollbar->solid_color_scrollbar_layer_inputs_.scroll_layer_id,
- deserialized_scrollbar->solid_color_scrollbar_layer_inputs_
- .scroll_layer_id);
- EXPECT_EQ(source_scrollbar->solid_color_scrollbar_layer_inputs_
- .is_left_side_vertical_scrollbar,
- deserialized_scrollbar->solid_color_scrollbar_layer_inputs_
- .is_left_side_vertical_scrollbar);
- EXPECT_EQ(source_scrollbar->solid_color_scrollbar_layer_inputs_.orientation,
- deserialized_scrollbar->solid_color_scrollbar_layer_inputs_
- .orientation);
-
- deserialized_scrollbar->SetLayerTreeHost(nullptr);
- }
-
- void RunScrollAndClipLayersTest() {
- scoped_refptr<Layer> layer = Layer::Create();
-
- scoped_refptr<Layer> scroll_parent = Layer::Create();
- layer->inputs_.scroll_parent = scroll_parent.get();
- 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();
- layer->inputs_.clip_parent = clip_parent.get();
- layer->clip_children_.reset(new std::set<Layer*>);
- scoped_refptr<Layer> clip_child1 = Layer::Create();
- layer->clip_children_->insert(clip_child1.get());
- 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->inputs_.children[0];
- layer_src_root->inputs_.children[0] = layer_src_root->inputs_.children[1];
- layer_src_root->inputs_.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_;
- std::unique_ptr<FakeLayerTreeHost> layer_tree_host_;
-};
-
namespace {
class MockLayerTree : public LayerTree {
public:
MockLayerTree(LayerTreeHostInProcess::InitParams* params,
LayerTreeHost* layer_tree_host)
- : LayerTree(std::move(params->animation_host), layer_tree_host) {}
+ : LayerTree(params->mutator_host, layer_tree_host) {}
~MockLayerTree() override {}
MOCK_METHOD0(SetNeedsFullTreeSync, void());
@@ -903,7 +114,6 @@ class LayerTest : public testing::Test {
LayerTest()
: host_impl_(LayerTreeSettings(),
&task_runner_provider_,
- &shared_bitmap_manager_,
&task_graph_runner_) {
timeline_impl_ =
AnimationTimeline::Create(AnimationIdProvider::NextTimelineId());
@@ -916,12 +126,13 @@ class LayerTest : public testing::Test {
protected:
void SetUp() override {
+ animation_host_ = AnimationHost::CreateForTesting(ThreadInstance::MAIN);
+
LayerTreeHostInProcess::InitParams params;
params.client = &fake_client_;
params.settings = &settings_;
params.task_graph_runner = &task_graph_runner_;
- params.animation_host =
- AnimationHost::CreateForTesting(ThreadInstance::MAIN);
+ params.mutator_host = animation_host_.get();
layer_tree_host_.reset(
new StrictMock<MockLayerTreeHost>(&single_thread_client_, &params));
@@ -942,7 +153,9 @@ class LayerTest : public testing::Test {
grand_child3_ = nullptr;
layer_tree_->SetRootLayer(nullptr);
+ animation_host_->SetMutatorHostClient(nullptr);
layer_tree_host_ = nullptr;
+ animation_host_ = nullptr;
layer_tree_ = nullptr;
}
@@ -993,13 +206,13 @@ class LayerTest : public testing::Test {
}
FakeImplTaskRunnerProvider task_runner_provider_;
- TestSharedBitmapManager shared_bitmap_manager_;
TestTaskGraphRunner task_graph_runner_;
FakeLayerTreeHostImpl host_impl_;
StubLayerTreeHostSingleThreadClient single_thread_client_;
FakeLayerTreeHostClient fake_client_;
std::unique_ptr<StrictMock<MockLayerTreeHost>> layer_tree_host_;
+ std::unique_ptr<AnimationHost> animation_host_;
StrictMock<MockLayerTree>* layer_tree_;
scoped_refptr<Layer> parent_;
scoped_refptr<Layer> child1_;
@@ -1819,20 +1032,19 @@ TEST_F(LayerTest, MaskHasParent) {
class LayerTreeHostFactory {
public:
- std::unique_ptr<LayerTreeHost> Create() {
- return Create(LayerTreeSettings());
+ std::unique_ptr<LayerTreeHost> Create(MutatorHost* mutator_host) {
+ return Create(LayerTreeSettings(), mutator_host);
}
- std::unique_ptr<LayerTreeHost> Create(LayerTreeSettings settings) {
+ std::unique_ptr<LayerTreeHost> Create(LayerTreeSettings settings,
+ MutatorHost* mutator_host) {
LayerTreeHostInProcess::InitParams params;
params.client = &client_;
- params.shared_bitmap_manager = &shared_bitmap_manager_;
params.task_graph_runner = &task_graph_runner_;
- params.gpu_memory_buffer_manager = &gpu_memory_buffer_manager_;
params.settings = &settings;
params.main_task_runner = base::ThreadTaskRunnerHandle::Get();
- params.animation_host =
- AnimationHost::CreateForTesting(ThreadInstance::MAIN);
+ params.mutator_host = mutator_host;
+
return LayerTreeHostInProcess::CreateSingleThreaded(&single_thread_client_,
&params);
}
@@ -1840,9 +1052,7 @@ class LayerTreeHostFactory {
private:
FakeLayerTreeHostClient client_;
StubLayerTreeHostSingleThreadClient single_thread_client_;
- TestSharedBitmapManager shared_bitmap_manager_;
TestTaskGraphRunner task_graph_runner_;
- TestGpuMemoryBufferManager gpu_memory_buffer_manager_;
};
void AssertLayerTreeHostMatchesForSubtree(Layer* layer, LayerTreeHost* host) {
@@ -1870,7 +1080,10 @@ TEST_F(LayerLayerTreeHostTest, EnteringTree) {
AssertLayerTreeHostMatchesForSubtree(parent.get(), nullptr);
LayerTreeHostFactory factory;
- std::unique_ptr<LayerTreeHost> layer_tree_host = factory.Create();
+
+ auto animation_host = AnimationHost::CreateForTesting(ThreadInstance::MAIN);
+ std::unique_ptr<LayerTreeHost> layer_tree_host =
+ factory.Create(animation_host.get());
LayerTree* layer_tree = layer_tree_host->GetLayerTree();
// Setting the root layer should set the host pointer for all layers in the
// tree.
@@ -1888,7 +1101,10 @@ TEST_F(LayerLayerTreeHostTest, EnteringTree) {
TEST_F(LayerLayerTreeHostTest, AddingLayerSubtree) {
scoped_refptr<Layer> parent = Layer::Create();
LayerTreeHostFactory factory;
- std::unique_ptr<LayerTreeHost> layer_tree_host = factory.Create();
+
+ auto animation_host = AnimationHost::CreateForTesting(ThreadInstance::MAIN);
+ std::unique_ptr<LayerTreeHost> layer_tree_host =
+ factory.Create(animation_host.get());
LayerTree* layer_tree = layer_tree_host->GetLayerTree();
layer_tree->SetRootLayer(parent.get());
@@ -1921,7 +1137,9 @@ TEST_F(LayerLayerTreeHostTest, ChangeHost) {
child->SetMaskLayer(mask.get());
LayerTreeHostFactory factory;
- std::unique_ptr<LayerTreeHost> first_layer_tree_host = factory.Create();
+ auto animation_host1 = AnimationHost::CreateForTesting(ThreadInstance::MAIN);
+ std::unique_ptr<LayerTreeHost> first_layer_tree_host =
+ factory.Create(animation_host1.get());
first_layer_tree_host->GetLayerTree()->SetRootLayer(parent.get());
AssertLayerTreeHostMatchesForSubtree(parent.get(),
@@ -1929,7 +1147,9 @@ TEST_F(LayerLayerTreeHostTest, ChangeHost) {
// Now re-root the tree to a new host (simulating what we do on a context lost
// event). This should update the host pointers for all layers in the tree.
- std::unique_ptr<LayerTreeHost> second_layer_tree_host = factory.Create();
+ auto animation_host2 = AnimationHost::CreateForTesting(ThreadInstance::MAIN);
+ std::unique_ptr<LayerTreeHost> second_layer_tree_host =
+ factory.Create(animation_host2.get());
second_layer_tree_host->GetLayerTree()->SetRootLayer(parent.get());
AssertLayerTreeHostMatchesForSubtree(parent.get(),
@@ -1951,7 +1171,9 @@ TEST_F(LayerLayerTreeHostTest, ChangeHostInSubtree) {
first_parent->AddChild(second_child);
LayerTreeHostFactory factory;
- std::unique_ptr<LayerTreeHost> first_layer_tree_host = factory.Create();
+ auto animation_host1 = AnimationHost::CreateForTesting(ThreadInstance::MAIN);
+ std::unique_ptr<LayerTreeHost> first_layer_tree_host =
+ factory.Create(animation_host1.get());
first_layer_tree_host->GetLayerTree()->SetRootLayer(first_parent.get());
AssertLayerTreeHostMatchesForSubtree(first_parent.get(),
@@ -1959,7 +1181,9 @@ TEST_F(LayerLayerTreeHostTest, ChangeHostInSubtree) {
// Now reparent the subtree starting at second_child to a layer in a different
// tree.
- std::unique_ptr<LayerTreeHost> second_layer_tree_host = factory.Create();
+ auto animation_host2 = AnimationHost::CreateForTesting(ThreadInstance::MAIN);
+ std::unique_ptr<LayerTreeHost> second_layer_tree_host =
+ factory.Create(animation_host2.get());
second_layer_tree_host->GetLayerTree()->SetRootLayer(second_parent.get());
second_parent->AddChild(second_child);
@@ -1985,7 +1209,9 @@ TEST_F(LayerLayerTreeHostTest, ReplaceMaskLayer) {
mask->AddChild(mask_child);
LayerTreeHostFactory factory;
- std::unique_ptr<LayerTreeHost> layer_tree_host = factory.Create();
+ auto animation_host = AnimationHost::CreateForTesting(ThreadInstance::MAIN);
+ std::unique_ptr<LayerTreeHost> layer_tree_host =
+ factory.Create(animation_host.get());
layer_tree_host->GetLayerTree()->SetRootLayer(parent.get());
AssertLayerTreeHostMatchesForSubtree(parent.get(), layer_tree_host.get());
@@ -2004,13 +1230,17 @@ TEST_F(LayerLayerTreeHostTest, DestroyHostWithNonNullRootLayer) {
scoped_refptr<Layer> child = Layer::Create();
root->AddChild(child);
LayerTreeHostFactory factory;
- std::unique_ptr<LayerTreeHost> layer_tree_host = factory.Create();
+ auto animation_host = AnimationHost::CreateForTesting(ThreadInstance::MAIN);
+ std::unique_ptr<LayerTreeHost> layer_tree_host =
+ factory.Create(animation_host.get());
layer_tree_host->GetLayerTree()->SetRootLayer(root);
}
TEST_F(LayerTest, SafeOpaqueBackgroundColor) {
LayerTreeHostFactory factory;
- std::unique_ptr<LayerTreeHost> layer_tree_host = factory.Create();
+ auto animation_host = AnimationHost::CreateForTesting(ThreadInstance::MAIN);
+ std::unique_ptr<LayerTreeHost> layer_tree_host =
+ factory.Create(animation_host.get());
LayerTree* layer_tree = layer_tree_host->GetLayerTree();
scoped_refptr<Layer> layer = Layer::Create();
@@ -2179,286 +1409,6 @@ TEST_F(LayerTest, AnimationSchedulesLayerUpdate) {
Mock::VerifyAndClearExpectations(layer_tree_host_.get());
}
-TEST_F(LayerTest, RecursiveHierarchySerialization) {
- /* Testing serialization and deserialization of a tree that looks like this:
- root
- / \
- a b
- \
- c
- Layer c also has a mask layer.
- */
- 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();
- layer_src_root->AddChild(layer_src_a);
- layer_src_root->AddChild(layer_src_b);
- layer_src_b->AddChild(layer_src_c);
- layer_src_c->SetMaskLayer(layer_src_c_mask.get());
-
- 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(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());
- EXPECT_EQ(layer_src_root->id(), layer_dest_a->parent()->id());
- EXPECT_EQ(0u, layer_dest_a->children().size());
-
- scoped_refptr<Layer> layer_dest_b = layer_dest_root->children()[1];
- EXPECT_EQ(layer_src_b->id(), layer_dest_b->id());
- EXPECT_EQ(layer_src_root->id(), layer_dest_b->parent()->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());
- EXPECT_EQ(layer_src_b->id(), layer_dest_c->parent()->id());
- EXPECT_EQ(0u, layer_dest_c->children().size());
- EXPECT_EQ(layer_src_c_mask->id(), layer_dest_c->mask_layer()->id());
-
- layer_dest_root->SetLayerTreeHost(nullptr);
-}
-
-TEST_F(LayerTest, RecursiveHierarchySerializationWithNodeReuse) {
- /* Testing serialization and deserialization of a tree that initially looks
- like this:
- root
- /
- a
- The source tree is then updated by adding layer |b|:
- root
- / \
- a b
- The deserialization should then re-use the Layers from last
- deserialization.
- */
- 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();
- 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());
- scoped_refptr<Layer> layer_dest_a_1 = layer_dest_root->children()[0];
- EXPECT_EQ(layer_src_a->id(), layer_dest_a_1->id());
-
- // Setup new destination layer map.
- Layer::LayerIdMap dest_layer_map_2;
- layer_dest_root->ClearLayerTreePropertiesForDeserializationAndAddToMap(
- &dest_layer_map_2);
-
- // Add Layer |b|.
- scoped_refptr<Layer> layer_src_b = Layer::Create();
- layer_src_root->AddChild(layer_src_b);
-
- // Second serialization.
- proto::LayerNode root_proto_2;
- layer_src_root->ToLayerNodeProto(&root_proto_2);
-
- // Second deserialization.
- 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());
-
- scoped_refptr<Layer> layer_dest_a_2 = layer_dest_root->children()[0];
- EXPECT_EQ(layer_src_a->id(), layer_dest_a_2->id());
- EXPECT_EQ(layer_src_root->id(), layer_dest_a_2->parent()->id());
- EXPECT_EQ(0u, layer_dest_a_2->children().size());
-
- scoped_refptr<Layer> layer_dest_b_2 = layer_dest_root->children()[1];
- EXPECT_EQ(layer_src_b->id(), layer_dest_b_2->id());
- EXPECT_EQ(layer_src_root->id(), layer_dest_b_2->parent()->id());
- EXPECT_EQ(0u, layer_dest_b_2->children().size());
-
- // 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) {
- /* Testing serialization and deserialization of a tree that initially
- looks like this:
- root
- / \
- a b
- \
- c
- \
- d
- Then the subtree rooted at node |b| is deleted in the next update.
- */
- 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);
- layer_src_c->AddChild(layer_src_d);
-
- // Serialization 1.
- proto::LayerNode proto1;
- layer_src_root->ToLayerNodeProto(&proto1);
-
- // Deserialization 1.
- Layer::LayerIdMap 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());
- scoped_refptr<Layer> layer_dest_a = layer_dest_root->children()[0];
- scoped_refptr<Layer> layer_dest_b = layer_dest_root->children()[1];
- ASSERT_EQ(1u, layer_dest_b->children().size());
- scoped_refptr<Layer> layer_dest_c = layer_dest_b->children()[0];
- ASSERT_EQ(1u, layer_dest_c->children().size());
- scoped_refptr<Layer> layer_dest_d = layer_dest_c->children()[0];
-
- // Delete the Layer |b| subtree.
- layer_src_b->RemoveAllChildren();
-
- // Serialization 2.
- proto::LayerNode proto2;
- layer_src_root->ToLayerNodeProto(&proto2);
-
- // Deserialization 2.
- Layer::LayerIdMap 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, DeleteMaskLayer) {
- scoped_refptr<Layer> layer_src_root = Layer::Create();
- scoped_refptr<Layer> layer_src_mask = Layer::Create();
- layer_src_root->SetMaskLayer(layer_src_mask.get());
-
- // Serialization 1.
- proto::LayerNode proto1;
- layer_src_root->ToLayerNodeProto(&proto1);
-
- // Deserialization 1.
- Layer::LayerIdMap 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());
- EXPECT_EQ(layer_src_root->mask_layer()->id(),
- layer_dest_root->mask_layer()->id());
- // TODO(nyquist): Add test for is_mask_ when PictureLayer is supported.
-
- // Clear mask layer.
- layer_src_root->mask_layer()->RemoveFromParent();
-
- // Serialization 2.
- proto::LayerNode proto2;
- layer_src_root->ToLayerNodeProto(&proto2);
-
- // Deserialization 2.
- 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());
-
- layer_dest_root->SetLayerTreeHost(nullptr);
-}
-
-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,
- NonDestructiveDeserializationMoveChildLaterTest) {
- RunNonDestructiveDeserializationMoveChildLaterTest();
-}
-
-TEST_F(LayerSerializationTest, NoMembersChanged) {
- RunNoMembersChangedTest();
-}
-
-TEST_F(LayerSerializationTest, ArbitraryMembersChanged) {
- RunArbitraryMembersChangedTest();
-}
-
-TEST_F(LayerSerializationTest, AllMembersChanged) {
- RunAllMembersChangedTest();
-}
-
-TEST_F(LayerSerializationTest, ScrollAndClipLayers) {
- RunScrollAndClipLayersTest();
-}
-
-TEST_F(LayerSerializationTest, SolidColorScrollbarSerialization) {
- std::vector<scoped_refptr<SolidColorScrollbarLayer>> scrollbar_layers;
-
- scrollbar_layers.push_back(SolidColorScrollbarLayer::Create(
- ScrollbarOrientation::HORIZONTAL, 20, 5, true, 3));
- scrollbar_layers.push_back(SolidColorScrollbarLayer::Create(
- ScrollbarOrientation::VERTICAL, 20, 5, false, 3));
- scrollbar_layers.push_back(SolidColorScrollbarLayer::Create(
- ScrollbarOrientation::HORIZONTAL, 0, 0, true, 0));
- scrollbar_layers.push_back(SolidColorScrollbarLayer::Create(
- ScrollbarOrientation::VERTICAL, 10, 35, true, 3));
-
- for (size_t i = 0; i < scrollbar_layers.size(); i++) {
- VerifySolidColorScrollbarLayerAfterSerializationAndDeserialization(
- scrollbar_layers[i]);
- }
-}
-
TEST_F(LayerTest, ElementIdAndMutablePropertiesArePushed) {
scoped_refptr<Layer> test_layer = Layer::Create();
std::unique_ptr<LayerImpl> impl_layer =