Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(50)

Side by Side Diff: cc/trees/layer_tree_host_unittest_serialization.cc

Issue 2159513003: Setup LayerTree class, refactor 2 functions from LayerTreeHost to it. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Use friend class for test code, or we need hundreds of SetSomethingForTest functions in future refa… Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 CompositorMode::SINGLE_THREADED, image_serialization_processor_.get()); 76 CompositorMode::SINGLE_THREADED, image_serialization_processor_.get());
76 layer_tree_host_dst_ = FakeLayerTreeHost::Create( 77 layer_tree_host_dst_ = FakeLayerTreeHost::Create(
77 &client_dst_, &task_graph_runner_dst_, settings, 78 &client_dst_, &task_graph_runner_dst_, settings,
78 CompositorMode::SINGLE_THREADED, image_serialization_processor_.get()); 79 CompositorMode::SINGLE_THREADED, image_serialization_processor_.get());
79 layer_tree_host_src_->InitializePictureCacheForTesting(); 80 layer_tree_host_src_->InitializePictureCacheForTesting();
80 layer_tree_host_dst_->InitializePictureCacheForTesting(); 81 layer_tree_host_dst_->InitializePictureCacheForTesting();
81 } 82 }
82 83
83 void TearDown() override { 84 void TearDown() override {
84 // Need to reset |in_paint_layer_contents_| to tear down. 85 // Need to reset |in_paint_layer_contents_| to tear down.
85 layer_tree_host_src_->in_paint_layer_contents_ = false; 86
86 layer_tree_host_dst_->in_paint_layer_contents_ = false; 87 layer_tree_host_src_->GetLayerTree()->in_paint_layer_contents_ = false;
88 layer_tree_host_dst_->GetLayerTree()->in_paint_layer_contents_ = false;
87 89
88 // Need to reset LayerTreeHost pointers before tear down. 90 // Need to reset LayerTreeHost pointers before tear down.
89 layer_tree_host_src_ = nullptr; 91 layer_tree_host_src_ = nullptr;
90 layer_tree_host_dst_ = nullptr; 92 layer_tree_host_dst_ = nullptr;
91 } 93 }
92 94
93 void VerifyHostHasAllExpectedLayersInTree(Layer* root_layer) { 95 void VerifyHostHasAllExpectedLayersInTree(Layer* root_layer) {
94 LayerTreeHostCommon::CallFunctionForEveryLayer( 96 LayerTreeHostCommon::CallFunctionForEveryLayer(
95 root_layer->layer_tree_host(), [root_layer](Layer* layer) { 97 root_layer->layer_tree_host(), [root_layer](Layer* layer) {
96 DCHECK(layer->layer_tree_host()); 98 DCHECK(layer->layer_tree_host());
97 EXPECT_EQ(layer, layer->layer_tree_host()->LayerById(layer->id())); 99 EXPECT_EQ(layer, layer->layer_tree_host()->LayerById(layer->id()));
98 }); 100 });
99 } 101 }
100 102
101 void VerifySerializationAndDeserialization() { 103 void VerifySerializationAndDeserialization() {
102 proto::LayerTreeHost proto; 104 proto::LayerTreeHost proto;
105 LayerTree* layer_tree_src = layer_tree_host_src_->GetLayerTree();
106 LayerTree* layer_tree_dst = layer_tree_host_dst_->GetLayerTree();
103 107
104 std::unordered_set<Layer*> layers_that_should_push_properties_src = 108 std::unordered_set<Layer*> layers_that_should_push_properties_src =
105 layer_tree_host_src_->LayersThatShouldPushProperties(); 109 layer_tree_src->LayersThatShouldPushProperties();
106 std::vector<std::unique_ptr<SwapPromise>> swap_promises; 110 std::vector<std::unique_ptr<SwapPromise>> swap_promises;
107 layer_tree_host_src_->ToProtobufForCommit(&proto, &swap_promises); 111 layer_tree_host_src_->ToProtobufForCommit(&proto, &swap_promises);
108 layer_tree_host_dst_->FromProtobufForCommit(proto); 112 layer_tree_host_dst_->FromProtobufForCommit(proto);
109 113
110 EXPECT_EQ(layer_tree_host_src_->needs_full_tree_sync_, 114 EXPECT_EQ(layer_tree_host_src_->needs_full_tree_sync_,
111 layer_tree_host_dst_->needs_full_tree_sync_); 115 layer_tree_host_dst_->needs_full_tree_sync_);
112 EXPECT_EQ(layer_tree_host_src_->needs_meta_info_recomputation_, 116 EXPECT_EQ(layer_tree_host_src_->needs_meta_info_recomputation_,
113 layer_tree_host_dst_->needs_meta_info_recomputation_); 117 layer_tree_host_dst_->needs_meta_info_recomputation_);
114 EXPECT_EQ(layer_tree_host_src_->source_frame_number_, 118 EXPECT_EQ(layer_tree_host_src_->source_frame_number_,
115 layer_tree_host_dst_->source_frame_number_); 119 layer_tree_host_dst_->source_frame_number_);
(...skipping 27 matching lines...) Expand all
143 EXPECT_EQ(layer_tree_host_src_->elastic_overscroll_, 147 EXPECT_EQ(layer_tree_host_src_->elastic_overscroll_,
144 layer_tree_host_dst_->elastic_overscroll_); 148 layer_tree_host_dst_->elastic_overscroll_);
145 EXPECT_EQ(layer_tree_host_src_->has_gpu_rasterization_trigger_, 149 EXPECT_EQ(layer_tree_host_src_->has_gpu_rasterization_trigger_,
146 layer_tree_host_dst_->has_gpu_rasterization_trigger_); 150 layer_tree_host_dst_->has_gpu_rasterization_trigger_);
147 EXPECT_EQ(layer_tree_host_src_->content_is_suitable_for_gpu_rasterization_, 151 EXPECT_EQ(layer_tree_host_src_->content_is_suitable_for_gpu_rasterization_,
148 layer_tree_host_dst_->content_is_suitable_for_gpu_rasterization_); 152 layer_tree_host_dst_->content_is_suitable_for_gpu_rasterization_);
149 EXPECT_EQ(layer_tree_host_src_->background_color_, 153 EXPECT_EQ(layer_tree_host_src_->background_color_,
150 layer_tree_host_dst_->background_color_); 154 layer_tree_host_dst_->background_color_);
151 EXPECT_EQ(layer_tree_host_src_->has_transparent_background_, 155 EXPECT_EQ(layer_tree_host_src_->has_transparent_background_,
152 layer_tree_host_dst_->has_transparent_background_); 156 layer_tree_host_dst_->has_transparent_background_);
153 EXPECT_EQ(layer_tree_host_src_->in_paint_layer_contents_, 157 EXPECT_EQ(layer_tree_src->in_paint_layer_contents(),
154 layer_tree_host_dst_->in_paint_layer_contents_); 158 layer_tree_dst->in_paint_layer_contents());
155 EXPECT_EQ(layer_tree_host_src_->id_, layer_tree_host_dst_->id_); 159 EXPECT_EQ(layer_tree_host_src_->id_, layer_tree_host_dst_->id_);
156 EXPECT_EQ(layer_tree_host_src_->next_commit_forces_redraw_, 160 EXPECT_EQ(layer_tree_host_src_->next_commit_forces_redraw_,
157 layer_tree_host_dst_->next_commit_forces_redraw_); 161 layer_tree_host_dst_->next_commit_forces_redraw_);
158 for (auto* layer : layers_that_should_push_properties_src) { 162 for (auto* layer : layers_that_should_push_properties_src) {
159 EXPECT_TRUE(layer_tree_host_dst_->LayerNeedsPushPropertiesForTesting( 163 EXPECT_TRUE(layer_tree_dst->LayerNeedsPushPropertiesForTesting(
160 layer_tree_host_dst_->LayerById(layer->id()))); 164 layer_tree_dst->LayerById(layer->id())));
161 } 165 }
162 166
163 if (layer_tree_host_src_->hud_layer_) { 167 if (layer_tree_host_src_->hud_layer_) {
164 EXPECT_EQ(layer_tree_host_src_->hud_layer_->id(), 168 EXPECT_EQ(layer_tree_host_src_->hud_layer_->id(),
165 layer_tree_host_dst_->hud_layer_->id()); 169 layer_tree_host_dst_->hud_layer_->id());
166 // The HUD layer member is a HeadsUpDisplayLayer instead of Layer, so 170 // The HUD layer member is a HeadsUpDisplayLayer instead of Layer, so
167 // inspect the proto to see if it contains the the right layer type. 171 // inspect the proto to see if it contains the the right layer type.
168 bool found_hud_layer_type = false; 172 bool found_hud_layer_type = false;
169 for (int i = 0; i < proto.root_layer().children_size(); ++i) { 173 for (int i = 0; i < proto.root_layer().children_size(); ++i) {
170 if (proto.root_layer().children(i).id() == 174 if (proto.root_layer().children(i).id() ==
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 root_layer_src->AddChild(layer_tree_host_src_->page_scale_layer_); 279 root_layer_src->AddChild(layer_tree_host_src_->page_scale_layer_);
276 layer_tree_host_src_->inner_viewport_scroll_layer_ = Layer::Create(); 280 layer_tree_host_src_->inner_viewport_scroll_layer_ = Layer::Create();
277 root_layer_src->AddChild( 281 root_layer_src->AddChild(
278 layer_tree_host_src_->inner_viewport_scroll_layer_); 282 layer_tree_host_src_->inner_viewport_scroll_layer_);
279 layer_tree_host_src_->outer_viewport_scroll_layer_ = Layer::Create(); 283 layer_tree_host_src_->outer_viewport_scroll_layer_ = Layer::Create();
280 root_layer_src->AddChild( 284 root_layer_src->AddChild(
281 layer_tree_host_src_->outer_viewport_scroll_layer_); 285 layer_tree_host_src_->outer_viewport_scroll_layer_);
282 286
283 // Set in_paint_layer_contents_ only after all calls to AddChild() have 287 // Set in_paint_layer_contents_ only after all calls to AddChild() have
284 // finished to ensure it's allowed to do so at that time. 288 // finished to ensure it's allowed to do so at that time.
285 layer_tree_host_src_->in_paint_layer_contents_ = 289 LayerTree* layer_tree_src = layer_tree_host_src_->GetLayerTree();
286 !layer_tree_host_src_->in_paint_layer_contents_; 290 layer_tree_src->in_paint_layer_contents_ =
291 !layer_tree_src->in_paint_layer_contents();
287 292
288 LayerSelectionBound sel_bound; 293 LayerSelectionBound sel_bound;
289 sel_bound.edge_top = gfx::Point(14, 3); 294 sel_bound.edge_top = gfx::Point(14, 3);
290 LayerSelection selection; 295 LayerSelection selection;
291 selection.start = sel_bound; 296 selection.start = sel_bound;
292 layer_tree_host_src_->selection_ = selection; 297 layer_tree_host_src_->selection_ = selection;
293 298
294 layer_tree_host_src_->property_trees_.sequence_number = 299 layer_tree_host_src_->property_trees_.sequence_number =
295 layer_tree_host_src_->property_trees_.sequence_number * 3 + 1; 300 layer_tree_host_src_->property_trees_.sequence_number * 3 + 1;
296 301
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
448 453
449 TEST_F(LayerTreeHostSerializationTest, AddAndRemoveNodeFromLayerTree) { 454 TEST_F(LayerTreeHostSerializationTest, AddAndRemoveNodeFromLayerTree) {
450 RunAddAndRemoveNodeFromLayerTree(); 455 RunAddAndRemoveNodeFromLayerTree();
451 } 456 }
452 457
453 TEST_F(LayerTreeHostSerializationTest, PictureLayerMultipleSerializations) { 458 TEST_F(LayerTreeHostSerializationTest, PictureLayerMultipleSerializations) {
454 RunPictureLayerMultipleSerializationsTest(); 459 RunPictureLayerMultipleSerializationsTest();
455 } 460 }
456 461
457 } // namespace cc 462 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698