| OLD | NEW |
| 1 // Copyright 2011 The Chromium Authors. All rights reserved. | 1 // Copyright 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "cc/layers/layer.h" | 5 #include "cc/layers/layer.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/threading/thread_task_runner_handle.h" | 9 #include "base/threading/thread_task_runner_handle.h" |
| 10 #include "cc/animation/animation_host.h" | 10 #include "cc/animation/animation_host.h" |
| 11 #include "cc/animation/animation_id_provider.h" | 11 #include "cc/animation/animation_id_provider.h" |
| 12 #include "cc/animation/keyframed_animation_curve.h" | 12 #include "cc/animation/keyframed_animation_curve.h" |
| 13 #include "cc/base/math_util.h" | 13 #include "cc/base/math_util.h" |
| 14 #include "cc/input/main_thread_scrolling_reason.h" | 14 #include "cc/input/main_thread_scrolling_reason.h" |
| 15 #include "cc/layers/layer_impl.h" | 15 #include "cc/layers/layer_impl.h" |
| 16 #include "cc/layers/solid_color_scrollbar_layer.h" | 16 #include "cc/layers/solid_color_scrollbar_layer.h" |
| 17 #include "cc/output/copy_output_request.h" | 17 #include "cc/output/copy_output_request.h" |
| 18 #include "cc/output/copy_output_result.h" | 18 #include "cc/output/copy_output_result.h" |
| 19 #include "cc/proto/layer.pb.h" | |
| 20 #include "cc/test/animation_test_common.h" | 19 #include "cc/test/animation_test_common.h" |
| 21 #include "cc/test/fake_impl_task_runner_provider.h" | 20 #include "cc/test/fake_impl_task_runner_provider.h" |
| 22 #include "cc/test/fake_layer_tree_host.h" | 21 #include "cc/test/fake_layer_tree_host.h" |
| 23 #include "cc/test/fake_layer_tree_host_client.h" | 22 #include "cc/test/fake_layer_tree_host_client.h" |
| 24 #include "cc/test/fake_layer_tree_host_impl.h" | 23 #include "cc/test/fake_layer_tree_host_impl.h" |
| 25 #include "cc/test/geometry_test_utils.h" | 24 #include "cc/test/geometry_test_utils.h" |
| 26 #include "cc/test/layer_internals_for_test.h" | 25 #include "cc/test/layer_internals_for_test.h" |
| 27 #include "cc/test/layer_test_common.h" | 26 #include "cc/test/layer_test_common.h" |
| 28 #include "cc/test/stub_layer_tree_host_single_thread_client.h" | 27 #include "cc/test/stub_layer_tree_host_single_thread_client.h" |
| 29 #include "cc/test/test_task_graph_runner.h" | 28 #include "cc/test/test_task_graph_runner.h" |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 EXPECT_FALSE(child->subtree_property_changed()); \ | 74 EXPECT_FALSE(child->subtree_property_changed()); \ |
| 76 EXPECT_FALSE( \ | 75 EXPECT_FALSE( \ |
| 77 child->GetLayerTree()->LayerNeedsPushPropertiesForTesting(child.get())); \ | 76 child->GetLayerTree()->LayerNeedsPushPropertiesForTesting(child.get())); \ |
| 78 EXPECT_FALSE(grand_child->subtree_property_changed()); \ | 77 EXPECT_FALSE(grand_child->subtree_property_changed()); \ |
| 79 EXPECT_FALSE( \ | 78 EXPECT_FALSE( \ |
| 80 grand_child->GetLayerTree()->LayerNeedsPushPropertiesForTesting( \ | 79 grand_child->GetLayerTree()->LayerNeedsPushPropertiesForTesting( \ |
| 81 grand_child.get())); | 80 grand_child.get())); |
| 82 | 81 |
| 83 namespace cc { | 82 namespace cc { |
| 84 | 83 |
| 85 // This class is a friend of Layer, and is used as a wrapper for all the tests | |
| 86 // related to proto serialization. This is done so that it is unnecessary to | |
| 87 // add FRIEND_TEST_ALL_PREFIXES in //cc/layers/layer.h for all the tests. | |
| 88 // It is in the cc namespace so that it can be a friend of Layer. | |
| 89 // The tests still have helpful names, and a test with the name FooBar would | |
| 90 // have a wrapper method in this class called RunFooBarTest. | |
| 91 class LayerSerializationTest : public testing::Test { | |
| 92 protected: | |
| 93 void SetUp() override { | |
| 94 animation_host_ = AnimationHost::CreateForTesting(ThreadInstance::MAIN); | |
| 95 layer_tree_host_ = FakeLayerTreeHost::Create( | |
| 96 &fake_client_, &task_graph_runner_, animation_host_.get()); | |
| 97 } | |
| 98 | |
| 99 void TearDown() override { | |
| 100 layer_tree_host_->SetRootLayer(nullptr); | |
| 101 layer_tree_host_ = nullptr; | |
| 102 } | |
| 103 | |
| 104 // Serializes |src| to proto and back again to a Layer, then verifies that | |
| 105 // the two Layers are equal for serialization purposes. | |
| 106 void VerifyBaseLayerPropertiesSerializationAndDeserialization(Layer* src) { | |
| 107 // This is required to ensure that properties are serialized. | |
| 108 src->SetNeedsPushProperties(); | |
| 109 src->SetLayerTreeHost(layer_tree_host_.get()); | |
| 110 | |
| 111 // The following member is reset during serialization, so store the original | |
| 112 // values. | |
| 113 gfx::Rect update_rect = src->inputs_.update_rect; | |
| 114 | |
| 115 // Serialize |src| to protobuf and read the first entry in the | |
| 116 // LayerUpdate. There are no descendants, so the serialization | |
| 117 // of |src| is the only entry. | |
| 118 proto::LayerUpdate layer_update; | |
| 119 src->ToLayerPropertiesProto(&layer_update, false); | |
| 120 ASSERT_EQ(1, layer_update.layers_size()); | |
| 121 proto::LayerProperties props = layer_update.layers(0); | |
| 122 | |
| 123 // The |dest| layer needs to be able to lookup the scroll and clip parents. | |
| 124 LayerTree* layer_tree = layer_tree_host_->GetLayerTree(); | |
| 125 if (src->inputs_.scroll_parent) | |
| 126 layer_tree->RegisterLayer(src->inputs_.scroll_parent); | |
| 127 if (src->scroll_children_) { | |
| 128 for (auto* child : *(src->scroll_children_)) | |
| 129 layer_tree->RegisterLayer(child); | |
| 130 } | |
| 131 if (src->inputs_.clip_parent) | |
| 132 layer_tree->RegisterLayer(src->inputs_.clip_parent); | |
| 133 if (src->clip_children_) { | |
| 134 for (auto* child : *(src->clip_children_)) | |
| 135 layer_tree->RegisterLayer(child); | |
| 136 } | |
| 137 // Reset the LayerTreeHost registration for the |src| layer so | |
| 138 // it can be re-used for the |dest| layer. | |
| 139 src->SetLayerTreeHost(nullptr); | |
| 140 | |
| 141 scoped_refptr<Layer> dest = Layer::Create(); | |
| 142 dest->inputs_.layer_id = src->inputs_.layer_id; | |
| 143 dest->SetLayerTreeHost(layer_tree_host_.get()); | |
| 144 dest->FromLayerPropertiesProto(props); | |
| 145 | |
| 146 // Verify that both layers are equal. | |
| 147 EXPECT_EQ(src->inputs_.transform_origin, dest->inputs_.transform_origin); | |
| 148 EXPECT_EQ(src->inputs_.background_color, dest->inputs_.background_color); | |
| 149 EXPECT_EQ(src->inputs_.bounds, dest->inputs_.bounds); | |
| 150 EXPECT_EQ(src->transform_tree_index_, dest->transform_tree_index_); | |
| 151 EXPECT_EQ(src->effect_tree_index_, dest->effect_tree_index_); | |
| 152 EXPECT_EQ(src->clip_tree_index_, dest->clip_tree_index_); | |
| 153 EXPECT_EQ(src->offset_to_transform_parent_, | |
| 154 dest->offset_to_transform_parent_); | |
| 155 EXPECT_EQ(src->inputs_.double_sided, dest->inputs_.double_sided); | |
| 156 EXPECT_EQ(src->draws_content_, dest->draws_content_); | |
| 157 EXPECT_EQ(src->may_contain_video_, dest->may_contain_video_); | |
| 158 EXPECT_EQ(src->inputs_.hide_layer_and_subtree, | |
| 159 dest->inputs_.hide_layer_and_subtree); | |
| 160 EXPECT_EQ(src->inputs_.masks_to_bounds, dest->inputs_.masks_to_bounds); | |
| 161 EXPECT_EQ(src->inputs_.main_thread_scrolling_reasons, | |
| 162 dest->inputs_.main_thread_scrolling_reasons); | |
| 163 EXPECT_EQ(src->inputs_.non_fast_scrollable_region, | |
| 164 dest->inputs_.non_fast_scrollable_region); | |
| 165 EXPECT_EQ(src->inputs_.touch_event_handler_region, | |
| 166 dest->inputs_.touch_event_handler_region); | |
| 167 EXPECT_EQ(src->inputs_.contents_opaque, dest->inputs_.contents_opaque); | |
| 168 EXPECT_EQ(src->inputs_.opacity, dest->inputs_.opacity); | |
| 169 EXPECT_EQ(src->inputs_.blend_mode, dest->inputs_.blend_mode); | |
| 170 EXPECT_EQ(src->inputs_.is_root_for_isolated_group, | |
| 171 dest->inputs_.is_root_for_isolated_group); | |
| 172 EXPECT_EQ(src->inputs_.position, dest->inputs_.position); | |
| 173 EXPECT_EQ(src->inputs_.is_container_for_fixed_position_layers, | |
| 174 dest->inputs_.is_container_for_fixed_position_layers); | |
| 175 EXPECT_EQ(src->inputs_.position_constraint, | |
| 176 dest->inputs_.position_constraint); | |
| 177 EXPECT_EQ(src->inputs_.should_flatten_transform, | |
| 178 dest->inputs_.should_flatten_transform); | |
| 179 EXPECT_EQ(src->should_flatten_transform_from_property_tree_, | |
| 180 dest->should_flatten_transform_from_property_tree_); | |
| 181 EXPECT_EQ(src->draw_blend_mode_, dest->draw_blend_mode_); | |
| 182 EXPECT_EQ(src->inputs_.use_parent_backface_visibility, | |
| 183 dest->inputs_.use_parent_backface_visibility); | |
| 184 EXPECT_EQ(src->inputs_.transform, dest->inputs_.transform); | |
| 185 EXPECT_EQ(src->inputs_.sorting_context_id, | |
| 186 dest->inputs_.sorting_context_id); | |
| 187 EXPECT_EQ(src->num_descendants_that_draw_content_, | |
| 188 dest->num_descendants_that_draw_content_); | |
| 189 EXPECT_EQ(src->inputs_.scroll_clip_layer_id, | |
| 190 dest->inputs_.scroll_clip_layer_id); | |
| 191 EXPECT_EQ(src->inputs_.user_scrollable_horizontal, | |
| 192 dest->inputs_.user_scrollable_horizontal); | |
| 193 EXPECT_EQ(src->inputs_.user_scrollable_vertical, | |
| 194 dest->inputs_.user_scrollable_vertical); | |
| 195 EXPECT_EQ(src->inputs_.scroll_offset, dest->inputs_.scroll_offset); | |
| 196 EXPECT_EQ(update_rect, dest->inputs_.update_rect); | |
| 197 | |
| 198 if (src->inputs_.scroll_parent) { | |
| 199 ASSERT_TRUE(dest->inputs_.scroll_parent); | |
| 200 EXPECT_EQ(src->inputs_.scroll_parent->id(), | |
| 201 dest->inputs_.scroll_parent->id()); | |
| 202 } else { | |
| 203 EXPECT_FALSE(dest->inputs_.scroll_parent); | |
| 204 } | |
| 205 if (src->scroll_children_) { | |
| 206 ASSERT_TRUE(dest->scroll_children_); | |
| 207 EXPECT_EQ(*(src->scroll_children_), *(dest->scroll_children_)); | |
| 208 } else { | |
| 209 EXPECT_FALSE(dest->scroll_children_); | |
| 210 } | |
| 211 | |
| 212 if (src->inputs_.clip_parent) { | |
| 213 ASSERT_TRUE(dest->inputs_.clip_parent); | |
| 214 EXPECT_EQ(src->inputs_.clip_parent->id(), | |
| 215 dest->inputs_.clip_parent->id()); | |
| 216 } else { | |
| 217 ASSERT_FALSE(dest->inputs_.clip_parent); | |
| 218 } | |
| 219 if (src->clip_children_) { | |
| 220 ASSERT_TRUE(dest->clip_children_); | |
| 221 EXPECT_EQ(*(src->clip_children_), *(dest->clip_children_)); | |
| 222 } else { | |
| 223 EXPECT_FALSE(dest->clip_children_); | |
| 224 } | |
| 225 | |
| 226 // The following member should have been reset during serialization. | |
| 227 EXPECT_EQ(gfx::Rect(), src->inputs_.update_rect); | |
| 228 | |
| 229 // Before deleting |dest|, the LayerTreeHost must be unset. | |
| 230 dest->SetLayerTreeHost(nullptr); | |
| 231 | |
| 232 // Cleanup scroll tree. | |
| 233 if (src->inputs_.scroll_parent) | |
| 234 layer_tree->UnregisterLayer(src->inputs_.scroll_parent); | |
| 235 src->inputs_.scroll_parent = nullptr; | |
| 236 dest->inputs_.scroll_parent = nullptr; | |
| 237 if (src->scroll_children_) { | |
| 238 for (auto* child : *(src->scroll_children_)) | |
| 239 layer_tree->UnregisterLayer(child); | |
| 240 src->scroll_children_.reset(); | |
| 241 dest->scroll_children_.reset(); | |
| 242 } | |
| 243 | |
| 244 // Cleanup clip tree. | |
| 245 if (src->inputs_.clip_parent) | |
| 246 layer_tree->UnregisterLayer(src->inputs_.clip_parent); | |
| 247 src->inputs_.clip_parent = nullptr; | |
| 248 dest->inputs_.clip_parent = nullptr; | |
| 249 if (src->clip_children_) { | |
| 250 for (auto* child : *(src->clip_children_)) | |
| 251 layer_tree->UnregisterLayer(child); | |
| 252 src->clip_children_.reset(); | |
| 253 dest->clip_children_.reset(); | |
| 254 } | |
| 255 } | |
| 256 | |
| 257 void RunNoMembersChangedTest() { | |
| 258 scoped_refptr<Layer> layer = Layer::Create(); | |
| 259 VerifyBaseLayerPropertiesSerializationAndDeserialization(layer.get()); | |
| 260 } | |
| 261 | |
| 262 void RunArbitraryMembersChangedTest() { | |
| 263 scoped_refptr<Layer> layer = Layer::Create(); | |
| 264 layer->inputs_.transform_origin = gfx::Point3F(3.0f, 1.0f, 4.0f); | |
| 265 layer->inputs_.background_color = SK_ColorRED; | |
| 266 layer->inputs_.bounds = gfx::Size(3, 14); | |
| 267 layer->transform_tree_index_ = -1; | |
| 268 layer->effect_tree_index_ = -1; | |
| 269 layer->clip_tree_index_ = 71; | |
| 270 layer->offset_to_transform_parent_ = gfx::Vector2dF(3.14f, 1.618f); | |
| 271 layer->inputs_.double_sided = true; | |
| 272 layer->draws_content_ = true; | |
| 273 layer->may_contain_video_ = true; | |
| 274 layer->inputs_.hide_layer_and_subtree = false; | |
| 275 layer->inputs_.masks_to_bounds = true; | |
| 276 layer->inputs_.main_thread_scrolling_reasons = | |
| 277 MainThreadScrollingReason::kNotScrollingOnMain; | |
| 278 layer->inputs_.non_fast_scrollable_region = Region(gfx::Rect(5, 1, 14, 3)); | |
| 279 layer->inputs_.touch_event_handler_region = Region(gfx::Rect(3, 14, 1, 5)); | |
| 280 layer->inputs_.contents_opaque = true; | |
| 281 layer->inputs_.opacity = 1.f; | |
| 282 layer->inputs_.blend_mode = SkXfermode::kSrcOver_Mode; | |
| 283 layer->inputs_.is_root_for_isolated_group = true; | |
| 284 layer->inputs_.position = gfx::PointF(3.14f, 6.28f); | |
| 285 layer->inputs_.is_container_for_fixed_position_layers = true; | |
| 286 LayerPositionConstraint pos_con; | |
| 287 pos_con.set_is_fixed_to_bottom_edge(true); | |
| 288 layer->inputs_.position_constraint = pos_con; | |
| 289 layer->inputs_.should_flatten_transform = true; | |
| 290 layer->should_flatten_transform_from_property_tree_ = true; | |
| 291 layer->draw_blend_mode_ = SkXfermode::kSrcOut_Mode; | |
| 292 layer->inputs_.use_parent_backface_visibility = true; | |
| 293 gfx::Transform transform; | |
| 294 transform.Rotate(90); | |
| 295 layer->inputs_.transform = transform; | |
| 296 layer->inputs_.sorting_context_id = 0; | |
| 297 layer->num_descendants_that_draw_content_ = 5; | |
| 298 layer->inputs_.scroll_clip_layer_id = Layer::INVALID_ID; | |
| 299 layer->inputs_.user_scrollable_horizontal = false; | |
| 300 layer->inputs_.user_scrollable_vertical = true; | |
| 301 layer->inputs_.scroll_offset = gfx::ScrollOffset(3, 14); | |
| 302 layer->inputs_.update_rect = gfx::Rect(14, 15); | |
| 303 | |
| 304 VerifyBaseLayerPropertiesSerializationAndDeserialization(layer.get()); | |
| 305 } | |
| 306 | |
| 307 void RunAllMembersChangedTest() { | |
| 308 scoped_refptr<Layer> layer = Layer::Create(); | |
| 309 layer->inputs_.transform_origin = gfx::Point3F(3.0f, 1.0f, 4.0f); | |
| 310 layer->inputs_.background_color = SK_ColorRED; | |
| 311 layer->inputs_.bounds = gfx::Size(3, 14); | |
| 312 layer->transform_tree_index_ = 39; | |
| 313 layer->effect_tree_index_ = 17; | |
| 314 layer->clip_tree_index_ = 71; | |
| 315 layer->offset_to_transform_parent_ = gfx::Vector2dF(3.14f, 1.618f); | |
| 316 layer->inputs_.double_sided = !layer->inputs_.double_sided; | |
| 317 layer->draws_content_ = !layer->draws_content_; | |
| 318 layer->may_contain_video_ = !layer->may_contain_video_; | |
| 319 layer->inputs_.hide_layer_and_subtree = | |
| 320 !layer->inputs_.hide_layer_and_subtree; | |
| 321 layer->inputs_.masks_to_bounds = !layer->inputs_.masks_to_bounds; | |
| 322 layer->inputs_.main_thread_scrolling_reasons = | |
| 323 MainThreadScrollingReason::kHasBackgroundAttachmentFixedObjects; | |
| 324 layer->inputs_.non_fast_scrollable_region = Region(gfx::Rect(5, 1, 14, 3)); | |
| 325 layer->inputs_.touch_event_handler_region = Region(gfx::Rect(3, 14, 1, 5)); | |
| 326 layer->inputs_.contents_opaque = !layer->inputs_.contents_opaque; | |
| 327 layer->inputs_.opacity = 3.14f; | |
| 328 layer->inputs_.blend_mode = SkXfermode::kSrcIn_Mode; | |
| 329 layer->inputs_.is_root_for_isolated_group = | |
| 330 !layer->inputs_.is_root_for_isolated_group; | |
| 331 layer->inputs_.position = gfx::PointF(3.14f, 6.28f); | |
| 332 layer->inputs_.is_container_for_fixed_position_layers = | |
| 333 !layer->inputs_.is_container_for_fixed_position_layers; | |
| 334 LayerPositionConstraint pos_con; | |
| 335 pos_con.set_is_fixed_to_bottom_edge(true); | |
| 336 layer->inputs_.position_constraint = pos_con; | |
| 337 layer->inputs_.should_flatten_transform = | |
| 338 !layer->inputs_.should_flatten_transform; | |
| 339 layer->should_flatten_transform_from_property_tree_ = | |
| 340 !layer->should_flatten_transform_from_property_tree_; | |
| 341 layer->draw_blend_mode_ = SkXfermode::kSrcOut_Mode; | |
| 342 layer->inputs_.use_parent_backface_visibility = | |
| 343 !layer->inputs_.use_parent_backface_visibility; | |
| 344 gfx::Transform transform; | |
| 345 transform.Rotate(90); | |
| 346 layer->inputs_.transform = transform; | |
| 347 layer->inputs_.sorting_context_id = 42; | |
| 348 layer->num_descendants_that_draw_content_ = 5; | |
| 349 layer->inputs_.scroll_clip_layer_id = 17; | |
| 350 layer->inputs_.user_scrollable_horizontal = | |
| 351 !layer->inputs_.user_scrollable_horizontal; | |
| 352 layer->inputs_.user_scrollable_vertical = | |
| 353 !layer->inputs_.user_scrollable_vertical; | |
| 354 layer->inputs_.scroll_offset = gfx::ScrollOffset(3, 14); | |
| 355 layer->inputs_.update_rect = gfx::Rect(14, 15); | |
| 356 | |
| 357 VerifyBaseLayerPropertiesSerializationAndDeserialization(layer.get()); | |
| 358 } | |
| 359 | |
| 360 void VerifySolidColorScrollbarLayerAfterSerializationAndDeserialization( | |
| 361 scoped_refptr<SolidColorScrollbarLayer> source_scrollbar) { | |
| 362 proto::LayerNode serialized_scrollbar_node; | |
| 363 source_scrollbar->ToLayerNodeProto(&serialized_scrollbar_node); | |
| 364 | |
| 365 scoped_refptr<SolidColorScrollbarLayer> deserialized_scrollbar = | |
| 366 SolidColorScrollbarLayer::Create(ScrollbarOrientation::HORIZONTAL, -1, | |
| 367 -1, false, Layer::INVALID_ID); | |
| 368 deserialized_scrollbar->inputs_.layer_id = | |
| 369 source_scrollbar->inputs_.layer_id; | |
| 370 | |
| 371 // FromLayerSpecificPropertiesProto expects a non-null LayerTreeHost to be | |
| 372 // set. | |
| 373 Layer::LayerIdMap layer_map; | |
| 374 deserialized_scrollbar->FromLayerNodeProto( | |
| 375 serialized_scrollbar_node, layer_map, layer_tree_host_.get()); | |
| 376 | |
| 377 EXPECT_EQ(source_scrollbar->solid_color_scrollbar_layer_inputs_.track_start, | |
| 378 deserialized_scrollbar->solid_color_scrollbar_layer_inputs_ | |
| 379 .track_start); | |
| 380 EXPECT_EQ( | |
| 381 source_scrollbar->solid_color_scrollbar_layer_inputs_.thumb_thickness, | |
| 382 deserialized_scrollbar->solid_color_scrollbar_layer_inputs_ | |
| 383 .thumb_thickness); | |
| 384 EXPECT_EQ( | |
| 385 source_scrollbar->solid_color_scrollbar_layer_inputs_.scroll_layer_id, | |
| 386 deserialized_scrollbar->solid_color_scrollbar_layer_inputs_ | |
| 387 .scroll_layer_id); | |
| 388 EXPECT_EQ(source_scrollbar->solid_color_scrollbar_layer_inputs_ | |
| 389 .is_left_side_vertical_scrollbar, | |
| 390 deserialized_scrollbar->solid_color_scrollbar_layer_inputs_ | |
| 391 .is_left_side_vertical_scrollbar); | |
| 392 EXPECT_EQ(source_scrollbar->solid_color_scrollbar_layer_inputs_.orientation, | |
| 393 deserialized_scrollbar->solid_color_scrollbar_layer_inputs_ | |
| 394 .orientation); | |
| 395 | |
| 396 deserialized_scrollbar->SetLayerTreeHost(nullptr); | |
| 397 } | |
| 398 | |
| 399 void RunScrollAndClipLayersTest() { | |
| 400 scoped_refptr<Layer> layer = Layer::Create(); | |
| 401 | |
| 402 scoped_refptr<Layer> scroll_parent = Layer::Create(); | |
| 403 layer->inputs_.scroll_parent = scroll_parent.get(); | |
| 404 scoped_refptr<Layer> scroll_child = Layer::Create(); | |
| 405 layer->scroll_children_.reset(new std::set<Layer*>); | |
| 406 layer->scroll_children_->insert(scroll_child.get()); | |
| 407 | |
| 408 scoped_refptr<Layer> clip_parent = Layer::Create(); | |
| 409 layer->inputs_.clip_parent = clip_parent.get(); | |
| 410 layer->clip_children_.reset(new std::set<Layer*>); | |
| 411 scoped_refptr<Layer> clip_child1 = Layer::Create(); | |
| 412 layer->clip_children_->insert(clip_child1.get()); | |
| 413 scoped_refptr<Layer> clip_child2 = Layer::Create(); | |
| 414 layer->clip_children_->insert(clip_child2.get()); | |
| 415 | |
| 416 VerifyBaseLayerPropertiesSerializationAndDeserialization(layer.get()); | |
| 417 } | |
| 418 | |
| 419 void RunHierarchyDeserializationWithLayerTreeHostTest() { | |
| 420 /* Testing serialization and deserialization of a tree that looks like this: | |
| 421 root | |
| 422 \ | |
| 423 a | |
| 424 \ | |
| 425 b | |
| 426 \ | |
| 427 c | |
| 428 The root layer has a LayerTreeHost, and it should propagate to all the | |
| 429 children. | |
| 430 */ | |
| 431 scoped_refptr<Layer> layer_src_root = Layer::Create(); | |
| 432 scoped_refptr<Layer> layer_src_a = Layer::Create(); | |
| 433 scoped_refptr<Layer> layer_src_b = Layer::Create(); | |
| 434 scoped_refptr<Layer> layer_src_c = Layer::Create(); | |
| 435 layer_src_root->AddChild(layer_src_a); | |
| 436 layer_src_a->AddChild(layer_src_b); | |
| 437 layer_src_b->AddChild(layer_src_c); | |
| 438 | |
| 439 proto::LayerNode proto; | |
| 440 layer_src_root->ToLayerNodeProto(&proto); | |
| 441 | |
| 442 Layer::LayerIdMap empty_dest_layer_map; | |
| 443 scoped_refptr<Layer> layer_dest_root = Layer::Create(); | |
| 444 | |
| 445 layer_dest_root->FromLayerNodeProto(proto, empty_dest_layer_map, | |
| 446 layer_tree_host_.get()); | |
| 447 | |
| 448 EXPECT_EQ(layer_src_root->id(), layer_dest_root->id()); | |
| 449 EXPECT_EQ(nullptr, layer_dest_root->parent()); | |
| 450 ASSERT_EQ(1u, layer_dest_root->children().size()); | |
| 451 EXPECT_EQ(layer_tree_host_.get(), layer_dest_root->layer_tree_host_); | |
| 452 | |
| 453 scoped_refptr<Layer> layer_dest_a = layer_dest_root->children()[0]; | |
| 454 EXPECT_EQ(layer_src_a->id(), layer_dest_a->id()); | |
| 455 EXPECT_EQ(layer_src_root->id(), layer_dest_a->parent()->id()); | |
| 456 EXPECT_EQ(1u, layer_dest_a->children().size()); | |
| 457 EXPECT_EQ(layer_tree_host_.get(), layer_dest_a->layer_tree_host_); | |
| 458 | |
| 459 scoped_refptr<Layer> layer_dest_b = layer_dest_a->children()[0]; | |
| 460 EXPECT_EQ(layer_src_b->id(), layer_dest_b->id()); | |
| 461 EXPECT_EQ(layer_src_a->id(), layer_dest_b->parent()->id()); | |
| 462 ASSERT_EQ(1u, layer_dest_b->children().size()); | |
| 463 EXPECT_EQ(layer_tree_host_.get(), layer_dest_b->layer_tree_host_); | |
| 464 | |
| 465 scoped_refptr<Layer> layer_dest_c = layer_dest_b->children()[0]; | |
| 466 EXPECT_EQ(layer_src_c->id(), layer_dest_c->id()); | |
| 467 EXPECT_EQ(layer_src_b->id(), layer_dest_c->parent()->id()); | |
| 468 EXPECT_EQ(0u, layer_dest_c->children().size()); | |
| 469 EXPECT_EQ(layer_tree_host_.get(), layer_dest_c->layer_tree_host_); | |
| 470 | |
| 471 // The layers have not been added to the LayerTreeHost layer map, so the | |
| 472 // LTH pointers must be cleared manually. | |
| 473 layer_dest_root->layer_tree_host_ = nullptr; | |
| 474 layer_dest_a->layer_tree_host_ = nullptr; | |
| 475 layer_dest_b->layer_tree_host_ = nullptr; | |
| 476 layer_dest_c->layer_tree_host_ = nullptr; | |
| 477 } | |
| 478 | |
| 479 void RunNonDestructiveDeserializationBaseCaseTest() { | |
| 480 /* Testing serialization and deserialization of a tree that initially looks | |
| 481 like this: | |
| 482 root | |
| 483 / | |
| 484 a | |
| 485 The source tree is then deserialized from the same structure which should | |
| 486 re-use the Layers from last deserialization and importantly it should | |
| 487 not have called InvalidatePropertyTreesIndices() for any of the layers, | |
| 488 which would happen in for example SetLayerTreeHost(...) calls. | |
| 489 */ | |
| 490 scoped_refptr<Layer> layer_root = Layer::Create(); | |
| 491 scoped_refptr<Layer> layer_src_a = Layer::Create(); | |
| 492 layer_root->AddChild(layer_src_a); | |
| 493 layer_root->transform_tree_index_ = 33; | |
| 494 layer_src_a->transform_tree_index_ = 42; | |
| 495 | |
| 496 proto::LayerNode root_proto; | |
| 497 layer_root->ToLayerNodeProto(&root_proto); | |
| 498 | |
| 499 Layer::LayerIdMap dest_layer_map; | |
| 500 layer_root->ClearLayerTreePropertiesForDeserializationAndAddToMap( | |
| 501 &dest_layer_map); | |
| 502 layer_root->FromLayerNodeProto(root_proto, dest_layer_map, | |
| 503 layer_tree_host_.get()); | |
| 504 | |
| 505 EXPECT_EQ(33, layer_root->transform_tree_index_); | |
| 506 ASSERT_EQ(1u, layer_root->children().size()); | |
| 507 scoped_refptr<Layer> layer_dest_a = layer_root->children()[0]; | |
| 508 EXPECT_EQ(layer_src_a, layer_dest_a); | |
| 509 EXPECT_EQ(42, layer_dest_a->transform_tree_index_); | |
| 510 | |
| 511 // Clear the reference to the LTH for all the layers. | |
| 512 layer_root->SetLayerTreeHost(nullptr); | |
| 513 } | |
| 514 | |
| 515 void RunNonDestructiveDeserializationReorderChildrenTest() { | |
| 516 /* Testing serialization and deserialization of a tree that initially looks | |
| 517 like this: | |
| 518 root | |
| 519 / \ | |
| 520 a b | |
| 521 The children are then re-ordered to: | |
| 522 root | |
| 523 / \ | |
| 524 b a | |
| 525 The tree is then serialized and deserialized again, and the the end | |
| 526 result should have the same structure and importantly it should | |
| 527 not have called InvalidatePropertyTreesIndices() for any of the layers, | |
| 528 which would happen in for example SetLayerTreeHost(...) calls. | |
| 529 */ | |
| 530 scoped_refptr<Layer> layer_src_root = Layer::Create(); | |
| 531 scoped_refptr<Layer> layer_src_a = Layer::Create(); | |
| 532 scoped_refptr<Layer> layer_src_b = Layer::Create(); | |
| 533 layer_src_root->AddChild(layer_src_a); | |
| 534 layer_src_root->AddChild(layer_src_b); | |
| 535 | |
| 536 // Copy tree-structure to new root. | |
| 537 proto::LayerNode root_proto_1; | |
| 538 layer_src_root->ToLayerNodeProto(&root_proto_1); | |
| 539 Layer::LayerIdMap dest_layer_map; | |
| 540 scoped_refptr<Layer> layer_dest_root = Layer::Create(); | |
| 541 layer_dest_root->FromLayerNodeProto(root_proto_1, dest_layer_map, | |
| 542 layer_tree_host_.get()); | |
| 543 | |
| 544 // Ensure initial copy is correct. | |
| 545 ASSERT_EQ(2u, layer_dest_root->children().size()); | |
| 546 scoped_refptr<Layer> layer_dest_a = layer_dest_root->children()[0]; | |
| 547 EXPECT_EQ(layer_src_a->id(), layer_dest_a->id()); | |
| 548 scoped_refptr<Layer> layer_dest_b = layer_dest_root->children()[1]; | |
| 549 EXPECT_EQ(layer_src_b->id(), layer_dest_b->id()); | |
| 550 | |
| 551 // Swap order of the children. | |
| 552 scoped_refptr<Layer> tmp_a = layer_src_root->inputs_.children[0]; | |
| 553 layer_src_root->inputs_.children[0] = layer_src_root->inputs_.children[1]; | |
| 554 layer_src_root->inputs_.children[1] = tmp_a; | |
| 555 | |
| 556 // Fake the fact that the destination layers have valid indexes. | |
| 557 layer_dest_root->transform_tree_index_ = 33; | |
| 558 layer_dest_a->transform_tree_index_ = 42; | |
| 559 layer_dest_b->transform_tree_index_ = 24; | |
| 560 | |
| 561 // Now serialize and deserialize again. | |
| 562 proto::LayerNode root_proto_2; | |
| 563 layer_src_root->ToLayerNodeProto(&root_proto_2); | |
| 564 layer_dest_root->ClearLayerTreePropertiesForDeserializationAndAddToMap( | |
| 565 &dest_layer_map); | |
| 566 layer_dest_root->FromLayerNodeProto(root_proto_2, dest_layer_map, | |
| 567 layer_tree_host_.get()); | |
| 568 | |
| 569 // Ensure second copy is correct. | |
| 570 EXPECT_EQ(33, layer_dest_root->transform_tree_index_); | |
| 571 ASSERT_EQ(2u, layer_dest_root->children().size()); | |
| 572 layer_dest_b = layer_dest_root->children()[0]; | |
| 573 EXPECT_EQ(layer_src_b->id(), layer_dest_b->id()); | |
| 574 EXPECT_EQ(24, layer_dest_b->transform_tree_index_); | |
| 575 layer_dest_a = layer_dest_root->children()[1]; | |
| 576 EXPECT_EQ(layer_src_a->id(), layer_dest_a->id()); | |
| 577 EXPECT_EQ(42, layer_dest_a->transform_tree_index_); | |
| 578 | |
| 579 layer_dest_root->SetLayerTreeHost(nullptr); | |
| 580 } | |
| 581 | |
| 582 void RunNonDestructiveDeserializationAddChildTest() { | |
| 583 /* Testing serialization and deserialization of a tree that initially looks | |
| 584 like this: | |
| 585 root | |
| 586 / | |
| 587 a | |
| 588 A child is then added to the root: | |
| 589 root | |
| 590 / \ | |
| 591 b a | |
| 592 The tree is then serialized and deserialized again, and the the end | |
| 593 result should have the same structure and importantly it should | |
| 594 not have called InvalidatePropertyTreesIndices() for any of the layers, | |
| 595 which would happen in for example SetLayerTreeHost(...) calls. | |
| 596 */ | |
| 597 scoped_refptr<Layer> layer_src_root = Layer::Create(); | |
| 598 scoped_refptr<Layer> layer_src_a = Layer::Create(); | |
| 599 layer_src_root->AddChild(layer_src_a); | |
| 600 | |
| 601 // Copy tree-structure to new root. | |
| 602 proto::LayerNode root_proto_1; | |
| 603 layer_src_root->ToLayerNodeProto(&root_proto_1); | |
| 604 Layer::LayerIdMap dest_layer_map; | |
| 605 scoped_refptr<Layer> layer_dest_root = Layer::Create(); | |
| 606 layer_dest_root->FromLayerNodeProto(root_proto_1, dest_layer_map, | |
| 607 layer_tree_host_.get()); | |
| 608 | |
| 609 // Ensure initial copy is correct. | |
| 610 ASSERT_EQ(1u, layer_dest_root->children().size()); | |
| 611 scoped_refptr<Layer> layer_dest_a = layer_dest_root->children()[0]; | |
| 612 EXPECT_EQ(layer_src_a->id(), layer_dest_a->id()); | |
| 613 | |
| 614 // Fake the fact that the destination layer |a| now has a valid index. | |
| 615 layer_dest_root->transform_tree_index_ = 33; | |
| 616 layer_dest_a->transform_tree_index_ = 42; | |
| 617 | |
| 618 // Add another child. | |
| 619 scoped_refptr<Layer> layer_src_b = Layer::Create(); | |
| 620 layer_src_root->AddChild(layer_src_b); | |
| 621 | |
| 622 // Now serialize and deserialize again. | |
| 623 proto::LayerNode root_proto_2; | |
| 624 layer_src_root->ToLayerNodeProto(&root_proto_2); | |
| 625 layer_dest_root->ClearLayerTreePropertiesForDeserializationAndAddToMap( | |
| 626 &dest_layer_map); | |
| 627 layer_dest_root->FromLayerNodeProto(root_proto_2, dest_layer_map, | |
| 628 layer_tree_host_.get()); | |
| 629 | |
| 630 // Ensure second copy is correct. | |
| 631 EXPECT_EQ(33, layer_dest_root->transform_tree_index_); | |
| 632 ASSERT_EQ(2u, layer_dest_root->children().size()); | |
| 633 layer_dest_a = layer_dest_root->children()[0]; | |
| 634 EXPECT_EQ(layer_src_a->id(), layer_dest_a->id()); | |
| 635 EXPECT_EQ(42, layer_dest_a->transform_tree_index_); | |
| 636 scoped_refptr<Layer> layer_dest_b = layer_dest_root->children()[1]; | |
| 637 EXPECT_EQ(layer_src_b->id(), layer_dest_b->id()); | |
| 638 | |
| 639 layer_dest_root->SetLayerTreeHost(nullptr); | |
| 640 } | |
| 641 | |
| 642 void RunNonDestructiveDeserializationRemoveChildTest() { | |
| 643 /* Testing serialization and deserialization of a tree that initially looks | |
| 644 like this: | |
| 645 root | |
| 646 / \ | |
| 647 a b | |
| 648 The |b| child is the removed from the root: | |
| 649 root | |
| 650 / | |
| 651 b | |
| 652 The tree is then serialized and deserialized again, and the the end | |
| 653 result should have the same structure and importantly it should | |
| 654 not have called InvalidatePropertyTreesIndices() for any of the layers, | |
| 655 which would happen in for example SetLayerTreeHost(...) calls. | |
| 656 */ | |
| 657 scoped_refptr<Layer> layer_src_root = Layer::Create(); | |
| 658 scoped_refptr<Layer> layer_src_a = Layer::Create(); | |
| 659 scoped_refptr<Layer> layer_src_b = Layer::Create(); | |
| 660 layer_src_root->AddChild(layer_src_a); | |
| 661 layer_src_root->AddChild(layer_src_b); | |
| 662 | |
| 663 // Copy tree-structure to new root. | |
| 664 proto::LayerNode root_proto_1; | |
| 665 layer_src_root->ToLayerNodeProto(&root_proto_1); | |
| 666 Layer::LayerIdMap dest_layer_map; | |
| 667 scoped_refptr<Layer> layer_dest_root = Layer::Create(); | |
| 668 layer_dest_root->FromLayerNodeProto(root_proto_1, dest_layer_map, | |
| 669 layer_tree_host_.get()); | |
| 670 | |
| 671 // Ensure initial copy is correct. | |
| 672 ASSERT_EQ(2u, layer_dest_root->children().size()); | |
| 673 scoped_refptr<Layer> layer_dest_a = layer_dest_root->children()[0]; | |
| 674 EXPECT_EQ(layer_src_a->id(), layer_dest_a->id()); | |
| 675 scoped_refptr<Layer> layer_dest_b = layer_dest_root->children()[1]; | |
| 676 EXPECT_EQ(layer_src_b->id(), layer_dest_b->id()); | |
| 677 | |
| 678 // Remove one child. | |
| 679 layer_src_b->RemoveFromParent(); | |
| 680 | |
| 681 // Fake the fact that the destination layers have valid indexes. | |
| 682 layer_dest_root->transform_tree_index_ = 33; | |
| 683 layer_dest_a->transform_tree_index_ = 42; | |
| 684 layer_dest_b->transform_tree_index_ = 24; | |
| 685 | |
| 686 // Now serialize and deserialize again. | |
| 687 proto::LayerNode root_proto_2; | |
| 688 layer_src_root->ToLayerNodeProto(&root_proto_2); | |
| 689 layer_dest_root->ClearLayerTreePropertiesForDeserializationAndAddToMap( | |
| 690 &dest_layer_map); | |
| 691 layer_dest_root->FromLayerNodeProto(root_proto_2, dest_layer_map, | |
| 692 layer_tree_host_.get()); | |
| 693 | |
| 694 // Ensure second copy is correct. | |
| 695 EXPECT_EQ(33, layer_dest_root->transform_tree_index_); | |
| 696 ASSERT_EQ(1u, layer_dest_root->children().size()); | |
| 697 layer_dest_a = layer_dest_root->children()[0]; | |
| 698 EXPECT_EQ(layer_src_a->id(), layer_dest_a->id()); | |
| 699 EXPECT_EQ(42, layer_dest_a->transform_tree_index_); | |
| 700 | |
| 701 layer_dest_root->SetLayerTreeHost(nullptr); | |
| 702 } | |
| 703 | |
| 704 void RunNonDestructiveDeserializationMoveChildEarlierTest() { | |
| 705 /* Testing serialization and deserialization of a tree that initially looks | |
| 706 like this: | |
| 707 root | |
| 708 / \ | |
| 709 a b | |
| 710 \ | |
| 711 c | |
| 712 The |c| child of |b| is then moved to become a child of |a|: | |
| 713 root | |
| 714 / \ | |
| 715 a b | |
| 716 / | |
| 717 c | |
| 718 The tree is then serialized and deserialized again, and the the end | |
| 719 result should have the same structure and importantly it should | |
| 720 not have called InvalidatePropertyTreesIndices() for any of the layers, | |
| 721 which would happen in for example SetLayerTreeHost(...) calls. | |
| 722 */ | |
| 723 scoped_refptr<Layer> layer_src_root = Layer::Create(); | |
| 724 scoped_refptr<Layer> layer_src_a = Layer::Create(); | |
| 725 scoped_refptr<Layer> layer_src_b = Layer::Create(); | |
| 726 scoped_refptr<Layer> layer_src_c = Layer::Create(); | |
| 727 layer_src_root->AddChild(layer_src_a); | |
| 728 layer_src_root->AddChild(layer_src_b); | |
| 729 layer_src_b->AddChild(layer_src_c); | |
| 730 | |
| 731 // Copy tree-structure to new root. | |
| 732 proto::LayerNode root_proto_1; | |
| 733 layer_src_root->ToLayerNodeProto(&root_proto_1); | |
| 734 Layer::LayerIdMap dest_layer_map; | |
| 735 scoped_refptr<Layer> layer_dest_root = Layer::Create(); | |
| 736 layer_dest_root->FromLayerNodeProto(root_proto_1, dest_layer_map, | |
| 737 layer_tree_host_.get()); | |
| 738 | |
| 739 // Ensure initial copy is correct. | |
| 740 ASSERT_EQ(2u, layer_dest_root->children().size()); | |
| 741 scoped_refptr<Layer> layer_dest_a = layer_dest_root->children()[0]; | |
| 742 scoped_refptr<Layer> layer_dest_b = layer_dest_root->children()[1]; | |
| 743 EXPECT_EQ(layer_src_a->id(), layer_dest_a->id()); | |
| 744 EXPECT_EQ(layer_src_b->id(), layer_dest_b->id()); | |
| 745 ASSERT_EQ(1u, layer_dest_b->children().size()); | |
| 746 scoped_refptr<Layer> layer_dest_c = layer_dest_b->children()[0]; | |
| 747 EXPECT_EQ(layer_src_c->id(), layer_dest_c->id()); | |
| 748 | |
| 749 // Move child |c| from |b| to |a|. | |
| 750 layer_src_c->RemoveFromParent(); | |
| 751 layer_src_a->AddChild(layer_src_c); | |
| 752 | |
| 753 // Moving a child invalidates the |transform_tree_index_|, so forcefully | |
| 754 // set it afterwards on the destination layer. | |
| 755 layer_dest_root->transform_tree_index_ = 33; | |
| 756 layer_dest_a->transform_tree_index_ = 42; | |
| 757 layer_dest_b->transform_tree_index_ = 24; | |
| 758 layer_dest_c->transform_tree_index_ = 99; | |
| 759 | |
| 760 // Now serialize and deserialize again. | |
| 761 proto::LayerNode root_proto_2; | |
| 762 layer_src_root->ToLayerNodeProto(&root_proto_2); | |
| 763 layer_dest_root->ClearLayerTreePropertiesForDeserializationAndAddToMap( | |
| 764 &dest_layer_map); | |
| 765 layer_dest_root->FromLayerNodeProto(root_proto_2, dest_layer_map, | |
| 766 layer_tree_host_.get()); | |
| 767 | |
| 768 // Ensure second copy is correct. | |
| 769 EXPECT_EQ(33, layer_dest_root->transform_tree_index_); | |
| 770 ASSERT_EQ(2u, layer_dest_root->children().size()); | |
| 771 layer_dest_a = layer_dest_root->children()[0]; | |
| 772 layer_dest_b = layer_dest_root->children()[1]; | |
| 773 EXPECT_EQ(layer_src_a->id(), layer_dest_a->id()); | |
| 774 EXPECT_EQ(42, layer_dest_a->transform_tree_index_); | |
| 775 EXPECT_EQ(layer_src_b->id(), layer_dest_b->id()); | |
| 776 EXPECT_EQ(24, layer_dest_b->transform_tree_index_); | |
| 777 ASSERT_EQ(1u, layer_dest_a->children().size()); | |
| 778 layer_dest_c = layer_dest_a->children()[0]; | |
| 779 EXPECT_EQ(layer_src_c->id(), layer_dest_c->id()); | |
| 780 EXPECT_EQ(99, layer_dest_c->transform_tree_index_); | |
| 781 | |
| 782 layer_dest_root->SetLayerTreeHost(nullptr); | |
| 783 } | |
| 784 | |
| 785 void RunNonDestructiveDeserializationMoveChildLaterTest() { | |
| 786 /* Testing serialization and deserialization of a tree that initially looks | |
| 787 like this: | |
| 788 root | |
| 789 / \ | |
| 790 a b | |
| 791 / | |
| 792 c | |
| 793 The |c| child of |a| is then moved to become a child of |b|: | |
| 794 root | |
| 795 / \ | |
| 796 a b | |
| 797 \ | |
| 798 c | |
| 799 The tree is then serialized and deserialized again, and the the end | |
| 800 result should have the same structure and importantly it should | |
| 801 not have called InvalidatePropertyTreesIndices() for any of the layers, | |
| 802 which would happen in for example SetLayerTreeHost(...) calls. | |
| 803 */ | |
| 804 scoped_refptr<Layer> layer_src_root = Layer::Create(); | |
| 805 scoped_refptr<Layer> layer_src_a = Layer::Create(); | |
| 806 scoped_refptr<Layer> layer_src_b = Layer::Create(); | |
| 807 scoped_refptr<Layer> layer_src_c = Layer::Create(); | |
| 808 layer_src_root->AddChild(layer_src_a); | |
| 809 layer_src_root->AddChild(layer_src_b); | |
| 810 layer_src_a->AddChild(layer_src_c); | |
| 811 | |
| 812 // Copy tree-structure to new root. | |
| 813 proto::LayerNode root_proto_1; | |
| 814 layer_src_root->ToLayerNodeProto(&root_proto_1); | |
| 815 Layer::LayerIdMap dest_layer_map; | |
| 816 scoped_refptr<Layer> layer_dest_root = Layer::Create(); | |
| 817 layer_dest_root->FromLayerNodeProto(root_proto_1, dest_layer_map, | |
| 818 layer_tree_host_.get()); | |
| 819 | |
| 820 // Ensure initial copy is correct. | |
| 821 ASSERT_EQ(2u, layer_dest_root->children().size()); | |
| 822 scoped_refptr<Layer> layer_dest_a = layer_dest_root->children()[0]; | |
| 823 scoped_refptr<Layer> layer_dest_b = layer_dest_root->children()[1]; | |
| 824 EXPECT_EQ(layer_src_a->id(), layer_dest_a->id()); | |
| 825 EXPECT_EQ(layer_src_b->id(), layer_dest_b->id()); | |
| 826 ASSERT_EQ(1u, layer_dest_a->children().size()); | |
| 827 scoped_refptr<Layer> layer_dest_c = layer_dest_a->children()[0]; | |
| 828 EXPECT_EQ(layer_src_c->id(), layer_dest_c->id()); | |
| 829 | |
| 830 // Move child |c| from |b| to |a|. | |
| 831 layer_src_c->RemoveFromParent(); | |
| 832 layer_src_b->AddChild(layer_src_c); | |
| 833 | |
| 834 // Moving a child invalidates the |transform_tree_index_|, so forcefully | |
| 835 // set it afterwards on the destination layer. | |
| 836 layer_dest_root->transform_tree_index_ = 33; | |
| 837 layer_dest_a->transform_tree_index_ = 42; | |
| 838 layer_dest_b->transform_tree_index_ = 24; | |
| 839 layer_dest_c->transform_tree_index_ = 99; | |
| 840 | |
| 841 // Now serialize and deserialize again. | |
| 842 proto::LayerNode root_proto_2; | |
| 843 layer_src_root->ToLayerNodeProto(&root_proto_2); | |
| 844 layer_dest_root->ClearLayerTreePropertiesForDeserializationAndAddToMap( | |
| 845 &dest_layer_map); | |
| 846 layer_dest_root->FromLayerNodeProto(root_proto_2, dest_layer_map, | |
| 847 layer_tree_host_.get()); | |
| 848 | |
| 849 // Ensure second copy is correct. | |
| 850 EXPECT_EQ(33, layer_dest_root->transform_tree_index_); | |
| 851 ASSERT_EQ(2u, layer_dest_root->children().size()); | |
| 852 layer_dest_a = layer_dest_root->children()[0]; | |
| 853 layer_dest_b = layer_dest_root->children()[1]; | |
| 854 EXPECT_EQ(layer_src_a->id(), layer_dest_a->id()); | |
| 855 EXPECT_EQ(42, layer_dest_a->transform_tree_index_); | |
| 856 EXPECT_EQ(layer_src_b->id(), layer_dest_b->id()); | |
| 857 EXPECT_EQ(24, layer_dest_b->transform_tree_index_); | |
| 858 ASSERT_EQ(1u, layer_dest_b->children().size()); | |
| 859 layer_dest_c = layer_dest_b->children()[0]; | |
| 860 EXPECT_EQ(layer_src_c->id(), layer_dest_c->id()); | |
| 861 EXPECT_EQ(99, layer_dest_c->transform_tree_index_); | |
| 862 | |
| 863 layer_dest_root->SetLayerTreeHost(nullptr); | |
| 864 } | |
| 865 | |
| 866 TestTaskGraphRunner task_graph_runner_; | |
| 867 FakeLayerTreeHostClient fake_client_; | |
| 868 std::unique_ptr<AnimationHost> animation_host_; | |
| 869 std::unique_ptr<FakeLayerTreeHost> layer_tree_host_; | |
| 870 }; | |
| 871 | |
| 872 namespace { | 84 namespace { |
| 873 | 85 |
| 874 class MockLayerTree : public LayerTree { | 86 class MockLayerTree : public LayerTree { |
| 875 public: | 87 public: |
| 876 MockLayerTree(LayerTreeHostInProcess::InitParams* params, | 88 MockLayerTree(LayerTreeHostInProcess::InitParams* params, |
| 877 LayerTreeHost* layer_tree_host) | 89 LayerTreeHost* layer_tree_host) |
| 878 : LayerTree(params->mutator_host, layer_tree_host) {} | 90 : LayerTree(params->mutator_host, layer_tree_host) {} |
| 879 ~MockLayerTree() override {} | 91 ~MockLayerTree() override {} |
| 880 | 92 |
| 881 MOCK_METHOD0(SetNeedsFullTreeSync, void()); | 93 MOCK_METHOD0(SetNeedsFullTreeSync, void()); |
| (...skipping 1308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2190 layer_internals.OnTransformAnimated(transform); | 1402 layer_internals.OnTransformAnimated(transform); |
| 2191 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); | 1403 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); |
| 2192 | 1404 |
| 2193 // Scroll offset animation should not schedule a layer update since it is | 1405 // Scroll offset animation should not schedule a layer update since it is |
| 2194 // handled similarly to normal compositor scroll updates. | 1406 // handled similarly to normal compositor scroll updates. |
| 2195 EXPECT_CALL(*layer_tree_host_, SetNeedsUpdateLayers()).Times(0); | 1407 EXPECT_CALL(*layer_tree_host_, SetNeedsUpdateLayers()).Times(0); |
| 2196 layer_internals.OnScrollOffsetAnimated(gfx::ScrollOffset(10, 10)); | 1408 layer_internals.OnScrollOffsetAnimated(gfx::ScrollOffset(10, 10)); |
| 2197 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); | 1409 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); |
| 2198 } | 1410 } |
| 2199 | 1411 |
| 2200 TEST_F(LayerTest, RecursiveHierarchySerialization) { | |
| 2201 /* Testing serialization and deserialization of a tree that looks like this: | |
| 2202 root | |
| 2203 / \ | |
| 2204 a b | |
| 2205 \ | |
| 2206 c | |
| 2207 Layer c also has a mask layer. | |
| 2208 */ | |
| 2209 scoped_refptr<Layer> layer_src_root = Layer::Create(); | |
| 2210 scoped_refptr<Layer> layer_src_a = Layer::Create(); | |
| 2211 scoped_refptr<Layer> layer_src_b = Layer::Create(); | |
| 2212 scoped_refptr<Layer> layer_src_c = Layer::Create(); | |
| 2213 scoped_refptr<Layer> layer_src_c_mask = Layer::Create(); | |
| 2214 layer_src_root->AddChild(layer_src_a); | |
| 2215 layer_src_root->AddChild(layer_src_b); | |
| 2216 layer_src_b->AddChild(layer_src_c); | |
| 2217 layer_src_c->SetMaskLayer(layer_src_c_mask.get()); | |
| 2218 | |
| 2219 proto::LayerNode proto; | |
| 2220 layer_src_root->ToLayerNodeProto(&proto); | |
| 2221 | |
| 2222 Layer::LayerIdMap empty_dest_layer_map; | |
| 2223 scoped_refptr<Layer> layer_dest_root = Layer::Create(); | |
| 2224 layer_dest_root->FromLayerNodeProto(proto, empty_dest_layer_map, | |
| 2225 layer_tree_host_.get()); | |
| 2226 | |
| 2227 EXPECT_EQ(layer_src_root->id(), layer_dest_root->id()); | |
| 2228 EXPECT_EQ(nullptr, layer_dest_root->parent()); | |
| 2229 ASSERT_EQ(2u, layer_dest_root->children().size()); | |
| 2230 | |
| 2231 scoped_refptr<Layer> layer_dest_a = layer_dest_root->children()[0]; | |
| 2232 EXPECT_EQ(layer_src_a->id(), layer_dest_a->id()); | |
| 2233 EXPECT_EQ(layer_src_root->id(), layer_dest_a->parent()->id()); | |
| 2234 EXPECT_EQ(0u, layer_dest_a->children().size()); | |
| 2235 | |
| 2236 scoped_refptr<Layer> layer_dest_b = layer_dest_root->children()[1]; | |
| 2237 EXPECT_EQ(layer_src_b->id(), layer_dest_b->id()); | |
| 2238 EXPECT_EQ(layer_src_root->id(), layer_dest_b->parent()->id()); | |
| 2239 ASSERT_EQ(1u, layer_dest_b->children().size()); | |
| 2240 | |
| 2241 scoped_refptr<Layer> layer_dest_c = layer_dest_b->children()[0]; | |
| 2242 EXPECT_EQ(layer_src_c->id(), layer_dest_c->id()); | |
| 2243 EXPECT_EQ(layer_src_b->id(), layer_dest_c->parent()->id()); | |
| 2244 EXPECT_EQ(0u, layer_dest_c->children().size()); | |
| 2245 EXPECT_EQ(layer_src_c_mask->id(), layer_dest_c->mask_layer()->id()); | |
| 2246 | |
| 2247 layer_dest_root->SetLayerTreeHost(nullptr); | |
| 2248 } | |
| 2249 | |
| 2250 TEST_F(LayerTest, RecursiveHierarchySerializationWithNodeReuse) { | |
| 2251 /* Testing serialization and deserialization of a tree that initially looks | |
| 2252 like this: | |
| 2253 root | |
| 2254 / | |
| 2255 a | |
| 2256 The source tree is then updated by adding layer |b|: | |
| 2257 root | |
| 2258 / \ | |
| 2259 a b | |
| 2260 The deserialization should then re-use the Layers from last | |
| 2261 deserialization. | |
| 2262 */ | |
| 2263 scoped_refptr<Layer> layer_src_root = Layer::Create(); | |
| 2264 scoped_refptr<Layer> layer_src_a = Layer::Create(); | |
| 2265 layer_src_root->AddChild(layer_src_a); | |
| 2266 | |
| 2267 proto::LayerNode root_proto_1; | |
| 2268 layer_src_root->ToLayerNodeProto(&root_proto_1); | |
| 2269 | |
| 2270 Layer::LayerIdMap dest_layer_map_1; | |
| 2271 scoped_refptr<Layer> layer_dest_root = Layer::Create(); | |
| 2272 layer_dest_root->FromLayerNodeProto(root_proto_1, dest_layer_map_1, | |
| 2273 layer_tree_host_.get()); | |
| 2274 | |
| 2275 EXPECT_EQ(layer_src_root->id(), layer_dest_root->id()); | |
| 2276 ASSERT_EQ(1u, layer_dest_root->children().size()); | |
| 2277 scoped_refptr<Layer> layer_dest_a_1 = layer_dest_root->children()[0]; | |
| 2278 EXPECT_EQ(layer_src_a->id(), layer_dest_a_1->id()); | |
| 2279 | |
| 2280 // Setup new destination layer map. | |
| 2281 Layer::LayerIdMap dest_layer_map_2; | |
| 2282 layer_dest_root->ClearLayerTreePropertiesForDeserializationAndAddToMap( | |
| 2283 &dest_layer_map_2); | |
| 2284 | |
| 2285 // Add Layer |b|. | |
| 2286 scoped_refptr<Layer> layer_src_b = Layer::Create(); | |
| 2287 layer_src_root->AddChild(layer_src_b); | |
| 2288 | |
| 2289 // Second serialization. | |
| 2290 proto::LayerNode root_proto_2; | |
| 2291 layer_src_root->ToLayerNodeProto(&root_proto_2); | |
| 2292 | |
| 2293 // Second deserialization. | |
| 2294 layer_dest_root->FromLayerNodeProto(root_proto_2, dest_layer_map_2, | |
| 2295 layer_tree_host_.get()); | |
| 2296 | |
| 2297 EXPECT_EQ(layer_src_root->id(), layer_dest_root->id()); | |
| 2298 ASSERT_EQ(2u, layer_dest_root->children().size()); | |
| 2299 | |
| 2300 scoped_refptr<Layer> layer_dest_a_2 = layer_dest_root->children()[0]; | |
| 2301 EXPECT_EQ(layer_src_a->id(), layer_dest_a_2->id()); | |
| 2302 EXPECT_EQ(layer_src_root->id(), layer_dest_a_2->parent()->id()); | |
| 2303 EXPECT_EQ(0u, layer_dest_a_2->children().size()); | |
| 2304 | |
| 2305 scoped_refptr<Layer> layer_dest_b_2 = layer_dest_root->children()[1]; | |
| 2306 EXPECT_EQ(layer_src_b->id(), layer_dest_b_2->id()); | |
| 2307 EXPECT_EQ(layer_src_root->id(), layer_dest_b_2->parent()->id()); | |
| 2308 EXPECT_EQ(0u, layer_dest_b_2->children().size()); | |
| 2309 | |
| 2310 // Layer |a| should be the same. | |
| 2311 EXPECT_EQ(layer_dest_a_1.get(), layer_dest_a_2.get()); | |
| 2312 | |
| 2313 layer_dest_root->SetLayerTreeHost(nullptr); | |
| 2314 } | |
| 2315 | |
| 2316 TEST_F(LayerTest, DeletingSubtreeDeletesLayers) { | |
| 2317 /* Testing serialization and deserialization of a tree that initially | |
| 2318 looks like this: | |
| 2319 root | |
| 2320 / \ | |
| 2321 a b | |
| 2322 \ | |
| 2323 c | |
| 2324 \ | |
| 2325 d | |
| 2326 Then the subtree rooted at node |b| is deleted in the next update. | |
| 2327 */ | |
| 2328 scoped_refptr<Layer> layer_src_root = Layer::Create(); | |
| 2329 scoped_refptr<Layer> layer_src_a = Layer::Create(); | |
| 2330 scoped_refptr<Layer> layer_src_b = Layer::Create(); | |
| 2331 scoped_refptr<Layer> layer_src_c = Layer::Create(); | |
| 2332 scoped_refptr<Layer> layer_src_d = Layer::Create(); | |
| 2333 layer_src_root->AddChild(layer_src_a); | |
| 2334 layer_src_root->AddChild(layer_src_b); | |
| 2335 layer_src_b->AddChild(layer_src_c); | |
| 2336 layer_src_c->AddChild(layer_src_d); | |
| 2337 | |
| 2338 // Serialization 1. | |
| 2339 proto::LayerNode proto1; | |
| 2340 layer_src_root->ToLayerNodeProto(&proto1); | |
| 2341 | |
| 2342 // Deserialization 1. | |
| 2343 Layer::LayerIdMap empty_dest_layer_map; | |
| 2344 scoped_refptr<Layer> layer_dest_root = Layer::Create(); | |
| 2345 layer_dest_root->FromLayerNodeProto(proto1, empty_dest_layer_map, | |
| 2346 layer_tree_host_.get()); | |
| 2347 | |
| 2348 EXPECT_EQ(layer_src_root->id(), layer_dest_root->id()); | |
| 2349 ASSERT_EQ(2u, layer_dest_root->children().size()); | |
| 2350 scoped_refptr<Layer> layer_dest_a = layer_dest_root->children()[0]; | |
| 2351 scoped_refptr<Layer> layer_dest_b = layer_dest_root->children()[1]; | |
| 2352 ASSERT_EQ(1u, layer_dest_b->children().size()); | |
| 2353 scoped_refptr<Layer> layer_dest_c = layer_dest_b->children()[0]; | |
| 2354 ASSERT_EQ(1u, layer_dest_c->children().size()); | |
| 2355 scoped_refptr<Layer> layer_dest_d = layer_dest_c->children()[0]; | |
| 2356 | |
| 2357 // Delete the Layer |b| subtree. | |
| 2358 layer_src_b->RemoveAllChildren(); | |
| 2359 | |
| 2360 // Serialization 2. | |
| 2361 proto::LayerNode proto2; | |
| 2362 layer_src_root->ToLayerNodeProto(&proto2); | |
| 2363 | |
| 2364 // Deserialization 2. | |
| 2365 Layer::LayerIdMap dest_layer_map_2; | |
| 2366 layer_dest_root->ClearLayerTreePropertiesForDeserializationAndAddToMap( | |
| 2367 &dest_layer_map_2); | |
| 2368 layer_dest_root->FromLayerNodeProto(proto2, dest_layer_map_2, | |
| 2369 layer_tree_host_.get()); | |
| 2370 | |
| 2371 EXPECT_EQ(0u, layer_dest_a->children().size()); | |
| 2372 EXPECT_EQ(0u, layer_dest_b->children().size()); | |
| 2373 | |
| 2374 layer_dest_root->SetLayerTreeHost(nullptr); | |
| 2375 } | |
| 2376 | |
| 2377 TEST_F(LayerTest, DeleteMaskLayer) { | |
| 2378 scoped_refptr<Layer> layer_src_root = Layer::Create(); | |
| 2379 scoped_refptr<Layer> layer_src_mask = Layer::Create(); | |
| 2380 layer_src_root->SetMaskLayer(layer_src_mask.get()); | |
| 2381 | |
| 2382 // Serialization 1. | |
| 2383 proto::LayerNode proto1; | |
| 2384 layer_src_root->ToLayerNodeProto(&proto1); | |
| 2385 | |
| 2386 // Deserialization 1. | |
| 2387 Layer::LayerIdMap dest_layer_map; | |
| 2388 scoped_refptr<Layer> layer_dest_root = Layer::Create(); | |
| 2389 layer_dest_root->FromLayerNodeProto(proto1, dest_layer_map, | |
| 2390 layer_tree_host_.get()); | |
| 2391 | |
| 2392 EXPECT_EQ(layer_src_root->id(), layer_dest_root->id()); | |
| 2393 ASSERT_TRUE(layer_dest_root->mask_layer()); | |
| 2394 EXPECT_EQ(layer_src_root->mask_layer()->id(), | |
| 2395 layer_dest_root->mask_layer()->id()); | |
| 2396 // TODO(nyquist): Add test for is_mask_ when PictureLayer is supported. | |
| 2397 | |
| 2398 // Clear mask layer. | |
| 2399 layer_src_root->mask_layer()->RemoveFromParent(); | |
| 2400 | |
| 2401 // Serialization 2. | |
| 2402 proto::LayerNode proto2; | |
| 2403 layer_src_root->ToLayerNodeProto(&proto2); | |
| 2404 | |
| 2405 // Deserialization 2. | |
| 2406 layer_dest_root->ClearLayerTreePropertiesForDeserializationAndAddToMap( | |
| 2407 &dest_layer_map); | |
| 2408 layer_dest_root->FromLayerNodeProto(proto2, dest_layer_map, | |
| 2409 layer_tree_host_.get()); | |
| 2410 | |
| 2411 EXPECT_EQ(nullptr, layer_dest_root->mask_layer()); | |
| 2412 | |
| 2413 layer_dest_root->SetLayerTreeHost(nullptr); | |
| 2414 } | |
| 2415 | |
| 2416 TEST_F(LayerSerializationTest, HierarchyDeserializationWithLayerTreeHost) { | |
| 2417 RunHierarchyDeserializationWithLayerTreeHostTest(); | |
| 2418 } | |
| 2419 | |
| 2420 TEST_F(LayerSerializationTest, NonDestructiveDeserializationBaseCase) { | |
| 2421 RunNonDestructiveDeserializationBaseCaseTest(); | |
| 2422 } | |
| 2423 | |
| 2424 TEST_F(LayerSerializationTest, NonDestructiveDeserializationReorderChildren) { | |
| 2425 RunNonDestructiveDeserializationReorderChildrenTest(); | |
| 2426 } | |
| 2427 | |
| 2428 TEST_F(LayerSerializationTest, NonDestructiveDeserializationAddChild) { | |
| 2429 RunNonDestructiveDeserializationAddChildTest(); | |
| 2430 } | |
| 2431 | |
| 2432 TEST_F(LayerSerializationTest, NonDestructiveDeserializationRemoveChild) { | |
| 2433 RunNonDestructiveDeserializationRemoveChildTest(); | |
| 2434 } | |
| 2435 | |
| 2436 TEST_F(LayerSerializationTest, | |
| 2437 NonDestructiveDeserializationMoveChildEarlierTest) { | |
| 2438 RunNonDestructiveDeserializationMoveChildEarlierTest(); | |
| 2439 } | |
| 2440 | |
| 2441 TEST_F(LayerSerializationTest, | |
| 2442 NonDestructiveDeserializationMoveChildLaterTest) { | |
| 2443 RunNonDestructiveDeserializationMoveChildLaterTest(); | |
| 2444 } | |
| 2445 | |
| 2446 TEST_F(LayerSerializationTest, NoMembersChanged) { | |
| 2447 RunNoMembersChangedTest(); | |
| 2448 } | |
| 2449 | |
| 2450 TEST_F(LayerSerializationTest, ArbitraryMembersChanged) { | |
| 2451 RunArbitraryMembersChangedTest(); | |
| 2452 } | |
| 2453 | |
| 2454 TEST_F(LayerSerializationTest, AllMembersChanged) { | |
| 2455 RunAllMembersChangedTest(); | |
| 2456 } | |
| 2457 | |
| 2458 TEST_F(LayerSerializationTest, ScrollAndClipLayers) { | |
| 2459 RunScrollAndClipLayersTest(); | |
| 2460 } | |
| 2461 | |
| 2462 TEST_F(LayerSerializationTest, SolidColorScrollbarSerialization) { | |
| 2463 std::vector<scoped_refptr<SolidColorScrollbarLayer>> scrollbar_layers; | |
| 2464 | |
| 2465 scrollbar_layers.push_back(SolidColorScrollbarLayer::Create( | |
| 2466 ScrollbarOrientation::HORIZONTAL, 20, 5, true, 3)); | |
| 2467 scrollbar_layers.push_back(SolidColorScrollbarLayer::Create( | |
| 2468 ScrollbarOrientation::VERTICAL, 20, 5, false, 3)); | |
| 2469 scrollbar_layers.push_back(SolidColorScrollbarLayer::Create( | |
| 2470 ScrollbarOrientation::HORIZONTAL, 0, 0, true, 0)); | |
| 2471 scrollbar_layers.push_back(SolidColorScrollbarLayer::Create( | |
| 2472 ScrollbarOrientation::VERTICAL, 10, 35, true, 3)); | |
| 2473 | |
| 2474 for (size_t i = 0; i < scrollbar_layers.size(); i++) { | |
| 2475 VerifySolidColorScrollbarLayerAfterSerializationAndDeserialization( | |
| 2476 scrollbar_layers[i]); | |
| 2477 } | |
| 2478 } | |
| 2479 | |
| 2480 TEST_F(LayerTest, ElementIdAndMutablePropertiesArePushed) { | 1412 TEST_F(LayerTest, ElementIdAndMutablePropertiesArePushed) { |
| 2481 scoped_refptr<Layer> test_layer = Layer::Create(); | 1413 scoped_refptr<Layer> test_layer = Layer::Create(); |
| 2482 std::unique_ptr<LayerImpl> impl_layer = | 1414 std::unique_ptr<LayerImpl> impl_layer = |
| 2483 LayerImpl::Create(host_impl_.active_tree(), 1); | 1415 LayerImpl::Create(host_impl_.active_tree(), 1); |
| 2484 | 1416 |
| 2485 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, layer_tree_->SetRootLayer(test_layer)); | 1417 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, layer_tree_->SetRootLayer(test_layer)); |
| 2486 | 1418 |
| 2487 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(2); | 1419 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(2); |
| 2488 | 1420 |
| 2489 test_layer->SetElementId(ElementId(2, 0)); | 1421 test_layer->SetElementId(ElementId(2, 0)); |
| 2490 test_layer->SetMutableProperties(MutableProperty::kTransform); | 1422 test_layer->SetMutableProperties(MutableProperty::kTransform); |
| 2491 | 1423 |
| 2492 EXPECT_FALSE(impl_layer->element_id()); | 1424 EXPECT_FALSE(impl_layer->element_id()); |
| 2493 EXPECT_EQ(MutableProperty::kNone, impl_layer->mutable_properties()); | 1425 EXPECT_EQ(MutableProperty::kNone, impl_layer->mutable_properties()); |
| 2494 | 1426 |
| 2495 test_layer->PushPropertiesTo(impl_layer.get()); | 1427 test_layer->PushPropertiesTo(impl_layer.get()); |
| 2496 | 1428 |
| 2497 EXPECT_EQ(ElementId(2, 0), impl_layer->element_id()); | 1429 EXPECT_EQ(ElementId(2, 0), impl_layer->element_id()); |
| 2498 EXPECT_EQ(MutableProperty::kTransform, impl_layer->mutable_properties()); | 1430 EXPECT_EQ(MutableProperty::kTransform, impl_layer->mutable_properties()); |
| 2499 } | 1431 } |
| 2500 | 1432 |
| 2501 } // namespace | 1433 } // namespace |
| 2502 } // namespace cc | 1434 } // namespace cc |
| OLD | NEW |