| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/trees/layer_tree_host.h" | 5 #include "cc/trees/layer_tree_host.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
| 10 #include "cc/layers/empty_content_layer_client.h" | 10 #include "cc/layers/empty_content_layer_client.h" |
| 11 #include "cc/layers/heads_up_display_layer.h" | 11 #include "cc/layers/heads_up_display_layer.h" |
| 12 #include "cc/layers/layer.h" | 12 #include "cc/layers/layer.h" |
| 13 #include "cc/proto/layer.pb.h" | 13 #include "cc/proto/layer.pb.h" |
| 14 #include "cc/proto/layer_tree_host.pb.h" | 14 #include "cc/proto/layer_tree_host.pb.h" |
| 15 #include "cc/test/fake_image_serialization_processor.h" | 15 #include "cc/test/fake_image_serialization_processor.h" |
| 16 #include "cc/test/fake_layer_tree_host.h" | 16 #include "cc/test/fake_layer_tree_host.h" |
| 17 #include "cc/test/fake_layer_tree_host_client.h" | 17 #include "cc/test/fake_layer_tree_host_client.h" |
| 18 #include "cc/test/fake_picture_layer.h" | 18 #include "cc/test/fake_picture_layer.h" |
| 19 #include "cc/test/fake_recording_source.h" | 19 #include "cc/test/fake_recording_source.h" |
| 20 #include "cc/test/layer_tree_test.h" | 20 #include "cc/test/layer_tree_test.h" |
| 21 #include "cc/test/skia_common.h" | 21 #include "cc/test/skia_common.h" |
| 22 #include "cc/test/test_task_graph_runner.h" | 22 #include "cc/test/test_task_graph_runner.h" |
| 23 #include "cc/trees/layer_tree.h" |
| 23 #include "cc/trees/layer_tree_host_common.h" | 24 #include "cc/trees/layer_tree_host_common.h" |
| 24 #include "cc/trees/layer_tree_settings.h" | 25 #include "cc/trees/layer_tree_settings.h" |
| 25 #include "testing/gtest/include/gtest/gtest.h" | 26 #include "testing/gtest/include/gtest/gtest.h" |
| 26 #include "third_party/skia/include/core/SkColor.h" | 27 #include "third_party/skia/include/core/SkColor.h" |
| 27 #include "ui/gfx/geometry/point.h" | 28 #include "ui/gfx/geometry/point.h" |
| 28 #include "ui/gfx/geometry/size.h" | 29 #include "ui/gfx/geometry/size.h" |
| 29 #include "ui/gfx/geometry/vector2d_f.h" | 30 #include "ui/gfx/geometry/vector2d_f.h" |
| 30 | 31 |
| 31 namespace cc { | 32 namespace cc { |
| 32 | 33 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 CompositorMode::SINGLE_THREADED, image_serialization_processor_.get()); | 74 CompositorMode::SINGLE_THREADED, image_serialization_processor_.get()); |
| 74 layer_tree_host_dst_ = FakeLayerTreeHost::Create( | 75 layer_tree_host_dst_ = FakeLayerTreeHost::Create( |
| 75 &client_dst_, &task_graph_runner_dst_, settings, | 76 &client_dst_, &task_graph_runner_dst_, settings, |
| 76 CompositorMode::SINGLE_THREADED, image_serialization_processor_.get()); | 77 CompositorMode::SINGLE_THREADED, image_serialization_processor_.get()); |
| 77 layer_tree_host_src_->InitializePictureCacheForTesting(); | 78 layer_tree_host_src_->InitializePictureCacheForTesting(); |
| 78 layer_tree_host_dst_->InitializePictureCacheForTesting(); | 79 layer_tree_host_dst_->InitializePictureCacheForTesting(); |
| 79 } | 80 } |
| 80 | 81 |
| 81 void TearDown() override { | 82 void TearDown() override { |
| 82 // Need to reset |in_paint_layer_contents_| to tear down. | 83 // Need to reset |in_paint_layer_contents_| to tear down. |
| 83 layer_tree_host_src_->in_paint_layer_contents_ = false; | 84 |
| 84 layer_tree_host_dst_->in_paint_layer_contents_ = false; | 85 layer_tree_host_src_->GetLayerTree()->in_paint_layer_contents_ = false; |
| 86 layer_tree_host_dst_->GetLayerTree()->in_paint_layer_contents_ = false; |
| 85 | 87 |
| 86 // Need to reset LayerTreeHost pointers before tear down. | 88 // Need to reset LayerTreeHost pointers before tear down. |
| 87 layer_tree_host_src_ = nullptr; | 89 layer_tree_host_src_ = nullptr; |
| 88 layer_tree_host_dst_ = nullptr; | 90 layer_tree_host_dst_ = nullptr; |
| 89 } | 91 } |
| 90 | 92 |
| 91 void VerifyHostHasAllExpectedLayersInTree(Layer* root_layer) { | 93 void VerifyHostHasAllExpectedLayersInTree(Layer* root_layer) { |
| 92 LayerTreeHostCommon::CallFunctionForEveryLayer( | 94 LayerTreeHostCommon::CallFunctionForEveryLayer( |
| 93 root_layer->layer_tree_host(), [root_layer](Layer* layer) { | 95 root_layer->layer_tree_host(), [root_layer](Layer* layer) { |
| 94 DCHECK(layer->layer_tree_host()); | 96 DCHECK(layer->layer_tree_host()); |
| 95 EXPECT_EQ(layer, layer->layer_tree_host()->LayerById(layer->id())); | 97 EXPECT_EQ(layer, layer->layer_tree_host()->LayerById(layer->id())); |
| 96 }); | 98 }); |
| 97 } | 99 } |
| 98 | 100 |
| 99 void VerifySerializationAndDeserialization() { | 101 void VerifySerializationAndDeserialization() { |
| 100 proto::LayerTreeHost proto; | 102 proto::LayerTreeHost proto; |
| 103 LayerTree* layer_tree_src = layer_tree_host_src_->GetLayerTree(); |
| 104 LayerTree* layer_tree_dst = layer_tree_host_dst_->GetLayerTree(); |
| 101 | 105 |
| 102 std::unordered_set<Layer*> layers_that_should_push_properties_src = | 106 std::unordered_set<Layer*> layers_that_should_push_properties_src = |
| 103 layer_tree_host_src_->LayersThatShouldPushProperties(); | 107 layer_tree_src->LayersThatShouldPushProperties(); |
| 104 std::vector<std::unique_ptr<SwapPromise>> swap_promises; | 108 std::vector<std::unique_ptr<SwapPromise>> swap_promises; |
| 105 layer_tree_host_src_->ToProtobufForCommit(&proto, &swap_promises); | 109 layer_tree_host_src_->ToProtobufForCommit(&proto, &swap_promises); |
| 106 layer_tree_host_dst_->FromProtobufForCommit(proto); | 110 layer_tree_host_dst_->FromProtobufForCommit(proto); |
| 107 | 111 |
| 108 EXPECT_EQ(layer_tree_host_src_->needs_full_tree_sync_, | 112 EXPECT_EQ(layer_tree_host_src_->needs_full_tree_sync_, |
| 109 layer_tree_host_dst_->needs_full_tree_sync_); | 113 layer_tree_host_dst_->needs_full_tree_sync_); |
| 110 EXPECT_EQ(layer_tree_host_src_->needs_meta_info_recomputation_, | 114 EXPECT_EQ(layer_tree_host_src_->needs_meta_info_recomputation_, |
| 111 layer_tree_host_dst_->needs_meta_info_recomputation_); | 115 layer_tree_host_dst_->needs_meta_info_recomputation_); |
| 112 EXPECT_EQ(layer_tree_host_src_->source_frame_number_, | 116 EXPECT_EQ(layer_tree_host_src_->source_frame_number_, |
| 113 layer_tree_host_dst_->source_frame_number_); | 117 layer_tree_host_dst_->source_frame_number_); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 141 EXPECT_EQ(layer_tree_host_src_->elastic_overscroll_, | 145 EXPECT_EQ(layer_tree_host_src_->elastic_overscroll_, |
| 142 layer_tree_host_dst_->elastic_overscroll_); | 146 layer_tree_host_dst_->elastic_overscroll_); |
| 143 EXPECT_EQ(layer_tree_host_src_->has_gpu_rasterization_trigger_, | 147 EXPECT_EQ(layer_tree_host_src_->has_gpu_rasterization_trigger_, |
| 144 layer_tree_host_dst_->has_gpu_rasterization_trigger_); | 148 layer_tree_host_dst_->has_gpu_rasterization_trigger_); |
| 145 EXPECT_EQ(layer_tree_host_src_->content_is_suitable_for_gpu_rasterization_, | 149 EXPECT_EQ(layer_tree_host_src_->content_is_suitable_for_gpu_rasterization_, |
| 146 layer_tree_host_dst_->content_is_suitable_for_gpu_rasterization_); | 150 layer_tree_host_dst_->content_is_suitable_for_gpu_rasterization_); |
| 147 EXPECT_EQ(layer_tree_host_src_->background_color_, | 151 EXPECT_EQ(layer_tree_host_src_->background_color_, |
| 148 layer_tree_host_dst_->background_color_); | 152 layer_tree_host_dst_->background_color_); |
| 149 EXPECT_EQ(layer_tree_host_src_->has_transparent_background_, | 153 EXPECT_EQ(layer_tree_host_src_->has_transparent_background_, |
| 150 layer_tree_host_dst_->has_transparent_background_); | 154 layer_tree_host_dst_->has_transparent_background_); |
| 151 EXPECT_EQ(layer_tree_host_src_->in_paint_layer_contents_, | 155 EXPECT_EQ(layer_tree_src->in_paint_layer_contents(), |
| 152 layer_tree_host_dst_->in_paint_layer_contents_); | 156 layer_tree_dst->in_paint_layer_contents()); |
| 153 EXPECT_EQ(layer_tree_host_src_->id_, layer_tree_host_dst_->id_); | 157 EXPECT_EQ(layer_tree_host_src_->id_, layer_tree_host_dst_->id_); |
| 154 EXPECT_EQ(layer_tree_host_src_->next_commit_forces_redraw_, | 158 EXPECT_EQ(layer_tree_host_src_->next_commit_forces_redraw_, |
| 155 layer_tree_host_dst_->next_commit_forces_redraw_); | 159 layer_tree_host_dst_->next_commit_forces_redraw_); |
| 156 for (auto* layer : layers_that_should_push_properties_src) { | 160 for (auto* layer : layers_that_should_push_properties_src) { |
| 157 EXPECT_TRUE(layer_tree_host_dst_->LayerNeedsPushPropertiesForTesting( | 161 EXPECT_TRUE(layer_tree_dst->LayerNeedsPushPropertiesForTesting( |
| 158 layer_tree_host_dst_->LayerById(layer->id()))); | 162 layer_tree_dst->LayerById(layer->id()))); |
| 159 } | 163 } |
| 160 | 164 |
| 161 if (layer_tree_host_src_->hud_layer_) { | 165 if (layer_tree_host_src_->hud_layer_) { |
| 162 EXPECT_EQ(layer_tree_host_src_->hud_layer_->id(), | 166 EXPECT_EQ(layer_tree_host_src_->hud_layer_->id(), |
| 163 layer_tree_host_dst_->hud_layer_->id()); | 167 layer_tree_host_dst_->hud_layer_->id()); |
| 164 // The HUD layer member is a HeadsUpDisplayLayer instead of Layer, so | 168 // The HUD layer member is a HeadsUpDisplayLayer instead of Layer, so |
| 165 // inspect the proto to see if it contains the the right layer type. | 169 // inspect the proto to see if it contains the the right layer type. |
| 166 bool found_hud_layer_type = false; | 170 bool found_hud_layer_type = false; |
| 167 for (int i = 0; i < proto.root_layer().children_size(); ++i) { | 171 for (int i = 0; i < proto.root_layer().children_size(); ++i) { |
| 168 if (proto.root_layer().children(i).id() == | 172 if (proto.root_layer().children(i).id() == |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 273 root_layer_src->AddChild(layer_tree_host_src_->page_scale_layer_); | 277 root_layer_src->AddChild(layer_tree_host_src_->page_scale_layer_); |
| 274 layer_tree_host_src_->inner_viewport_scroll_layer_ = Layer::Create(); | 278 layer_tree_host_src_->inner_viewport_scroll_layer_ = Layer::Create(); |
| 275 root_layer_src->AddChild( | 279 root_layer_src->AddChild( |
| 276 layer_tree_host_src_->inner_viewport_scroll_layer_); | 280 layer_tree_host_src_->inner_viewport_scroll_layer_); |
| 277 layer_tree_host_src_->outer_viewport_scroll_layer_ = Layer::Create(); | 281 layer_tree_host_src_->outer_viewport_scroll_layer_ = Layer::Create(); |
| 278 root_layer_src->AddChild( | 282 root_layer_src->AddChild( |
| 279 layer_tree_host_src_->outer_viewport_scroll_layer_); | 283 layer_tree_host_src_->outer_viewport_scroll_layer_); |
| 280 | 284 |
| 281 // Set in_paint_layer_contents_ only after all calls to AddChild() have | 285 // Set in_paint_layer_contents_ only after all calls to AddChild() have |
| 282 // finished to ensure it's allowed to do so at that time. | 286 // finished to ensure it's allowed to do so at that time. |
| 283 layer_tree_host_src_->in_paint_layer_contents_ = | 287 LayerTree* layer_tree_src = layer_tree_host_src_->GetLayerTree(); |
| 284 !layer_tree_host_src_->in_paint_layer_contents_; | 288 layer_tree_src->in_paint_layer_contents_ = |
| 289 !layer_tree_src->in_paint_layer_contents(); |
| 285 | 290 |
| 286 LayerSelectionBound sel_bound; | 291 LayerSelectionBound sel_bound; |
| 287 sel_bound.edge_top = gfx::Point(14, 3); | 292 sel_bound.edge_top = gfx::Point(14, 3); |
| 288 LayerSelection selection; | 293 LayerSelection selection; |
| 289 selection.start = sel_bound; | 294 selection.start = sel_bound; |
| 290 layer_tree_host_src_->selection_ = selection; | 295 layer_tree_host_src_->selection_ = selection; |
| 291 | 296 |
| 292 layer_tree_host_src_->property_trees_.sequence_number = | 297 layer_tree_host_src_->property_trees_.sequence_number = |
| 293 layer_tree_host_src_->property_trees_.sequence_number * 3 + 1; | 298 layer_tree_host_src_->property_trees_.sequence_number * 3 + 1; |
| 294 | 299 |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 446 | 451 |
| 447 TEST_F(LayerTreeHostSerializationTest, AddAndRemoveNodeFromLayerTree) { | 452 TEST_F(LayerTreeHostSerializationTest, AddAndRemoveNodeFromLayerTree) { |
| 448 RunAddAndRemoveNodeFromLayerTree(); | 453 RunAddAndRemoveNodeFromLayerTree(); |
| 449 } | 454 } |
| 450 | 455 |
| 451 TEST_F(LayerTreeHostSerializationTest, PictureLayerMultipleSerializations) { | 456 TEST_F(LayerTreeHostSerializationTest, PictureLayerMultipleSerializations) { |
| 452 RunPictureLayerMultipleSerializationsTest(); | 457 RunPictureLayerMultipleSerializationsTest(); |
| 453 } | 458 } |
| 454 | 459 |
| 455 } // namespace cc | 460 } // namespace cc |
| OLD | NEW |