OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "cc/trees/layer_tree_host.h" | |
6 | |
7 #include "cc/layers/heads_up_display_layer.h" | |
8 #include "cc/layers/layer.h" | |
9 #include "cc/layers/layer_settings.h" | |
10 #include "cc/proto/layer.pb.h" | |
11 #include "cc/proto/layer_tree_host.pb.h" | |
12 #include "cc/test/fake_layer_tree_host.h" | |
13 #include "cc/test/fake_layer_tree_host_client.h" | |
14 #include "cc/test/layer_tree_test.h" | |
15 #include "cc/test/test_task_graph_runner.h" | |
16 #include "cc/trees/layer_tree_settings.h" | |
17 #include "testing/gtest/include/gtest/gtest.h" | |
18 #include "third_party/skia/include/core/SkColor.h" | |
19 #include "ui/gfx/geometry/point.h" | |
20 #include "ui/gfx/geometry/size.h" | |
21 #include "ui/gfx/geometry/vector2d_f.h" | |
22 | |
23 namespace cc { | |
24 | |
25 class LayerTreeHostSerializationTest : public testing::Test { | |
26 public: | |
27 LayerTreeHostSerializationTest() | |
28 : fake_client_src_(FakeLayerTreeHostClient::DIRECT_3D), | |
vmpstr
2016/01/11 22:06:30
just client_src_ and client_dst_ is fine
nyquist
2016/01/13 01:34:12
Done.
| |
29 fake_client_dst_(FakeLayerTreeHostClient::DIRECT_3D) {} | |
30 | |
31 protected: | |
32 void SetUp() override { | |
33 layer_tree_host_src_ = | |
34 FakeLayerTreeHost::Create(&fake_client_src_, &task_graph_runner_src_); | |
35 layer_tree_host_dst_ = | |
36 FakeLayerTreeHost::Create(&fake_client_dst_, &task_graph_runner_dst_); | |
37 } | |
38 | |
39 void TearDown() override { | |
40 // Need to reset |in_paint_layer_contents_| to tear down. | |
41 layer_tree_host_src_->in_paint_layer_contents_ = false; | |
42 layer_tree_host_dst_->in_paint_layer_contents_ = false; | |
43 | |
44 // Need to reset root layer and LayerTreeHost pointers before tear down. | |
45 layer_tree_host_src_->SetRootLayer(nullptr); | |
46 layer_tree_host_src_ = nullptr; | |
47 layer_tree_host_dst_->SetRootLayer(nullptr); | |
48 layer_tree_host_dst_ = nullptr; | |
49 } | |
50 | |
51 void VerifySerializationAndDeserialization() { | |
52 proto::LayerTreeHost proto; | |
53 layer_tree_host_src_->ToProtobufForCommit(&proto); | |
54 layer_tree_host_dst_->FromProtobufForCommit(proto); | |
55 | |
56 EXPECT_EQ(layer_tree_host_src_->needs_full_tree_sync_, | |
57 layer_tree_host_dst_->needs_full_tree_sync_); | |
58 EXPECT_EQ(layer_tree_host_src_->needs_meta_info_recomputation_, | |
59 layer_tree_host_dst_->needs_meta_info_recomputation_); | |
60 EXPECT_EQ(layer_tree_host_src_->source_frame_number_, | |
61 layer_tree_host_dst_->source_frame_number_); | |
62 EXPECT_EQ(layer_tree_host_src_->meta_information_sequence_number_, | |
63 layer_tree_host_dst_->meta_information_sequence_number_); | |
64 EXPECT_EQ(layer_tree_host_src_->root_layer()->id(), | |
65 layer_tree_host_dst_->root_layer()->id()); | |
66 EXPECT_EQ(layer_tree_host_dst_.get(), | |
67 layer_tree_host_dst_->root_layer_->layer_tree_host()); | |
68 EXPECT_EQ(layer_tree_host_src_->root_layer_->double_sided(), | |
69 layer_tree_host_dst_->root_layer_->double_sided()); | |
70 | |
71 if (layer_tree_host_src_->hud_layer_) { | |
vmpstr
2016/01/11 22:06:30
group up ifs with other ifs, please
nyquist
2016/01/13 01:34:12
Done.
| |
72 EXPECT_EQ(layer_tree_host_src_->hud_layer_->id(), | |
73 layer_tree_host_dst_->hud_layer_->id()); | |
74 } else { | |
75 EXPECT_EQ(nullptr, layer_tree_host_dst_->hud_layer_); | |
76 } | |
77 | |
78 EXPECT_EQ( | |
79 layer_tree_host_src_->debug_state_.show_replica_screen_space_rects, | |
80 layer_tree_host_dst_->debug_state_.show_replica_screen_space_rects); | |
81 EXPECT_EQ(layer_tree_host_src_->device_viewport_size_, | |
82 layer_tree_host_dst_->device_viewport_size_); | |
83 EXPECT_EQ(layer_tree_host_src_->top_controls_shrink_blink_size_, | |
84 layer_tree_host_dst_->top_controls_shrink_blink_size_); | |
85 EXPECT_EQ(layer_tree_host_src_->top_controls_height_, | |
86 layer_tree_host_dst_->top_controls_height_); | |
87 EXPECT_EQ(layer_tree_host_src_->top_controls_shown_ratio_, | |
88 layer_tree_host_dst_->top_controls_shown_ratio_); | |
89 EXPECT_EQ(layer_tree_host_src_->device_scale_factor_, | |
90 layer_tree_host_dst_->device_scale_factor_); | |
91 EXPECT_EQ(layer_tree_host_src_->painted_device_scale_factor_, | |
92 layer_tree_host_dst_->painted_device_scale_factor_); | |
93 EXPECT_EQ(layer_tree_host_src_->page_scale_factor_, | |
94 layer_tree_host_dst_->page_scale_factor_); | |
95 EXPECT_EQ(layer_tree_host_src_->min_page_scale_factor_, | |
96 layer_tree_host_dst_->min_page_scale_factor_); | |
97 EXPECT_EQ(layer_tree_host_src_->max_page_scale_factor_, | |
98 layer_tree_host_dst_->max_page_scale_factor_); | |
99 EXPECT_EQ(layer_tree_host_src_->elastic_overscroll_, | |
100 layer_tree_host_dst_->elastic_overscroll_); | |
101 EXPECT_EQ(layer_tree_host_src_->has_gpu_rasterization_trigger_, | |
102 layer_tree_host_dst_->has_gpu_rasterization_trigger_); | |
103 EXPECT_EQ(layer_tree_host_src_->content_is_suitable_for_gpu_rasterization_, | |
104 layer_tree_host_dst_->content_is_suitable_for_gpu_rasterization_); | |
105 EXPECT_EQ(layer_tree_host_src_->background_color_, | |
106 layer_tree_host_dst_->background_color_); | |
107 EXPECT_EQ(layer_tree_host_src_->has_transparent_background_, | |
108 layer_tree_host_dst_->has_transparent_background_); | |
109 EXPECT_EQ(layer_tree_host_src_->in_paint_layer_contents_, | |
110 layer_tree_host_dst_->in_paint_layer_contents_); | |
111 EXPECT_EQ(layer_tree_host_src_->id_, layer_tree_host_dst_->id_); | |
112 EXPECT_EQ(layer_tree_host_src_->next_commit_forces_redraw_, | |
113 layer_tree_host_dst_->next_commit_forces_redraw_); | |
114 | |
115 if (layer_tree_host_src_->overscroll_elasticity_layer_) { | |
116 EXPECT_EQ(layer_tree_host_src_->overscroll_elasticity_layer_->id(), | |
117 layer_tree_host_dst_->overscroll_elasticity_layer_->id()); | |
118 } else { | |
119 EXPECT_EQ(nullptr, layer_tree_host_dst_->overscroll_elasticity_layer_); | |
120 } | |
121 if (layer_tree_host_src_->page_scale_layer_) { | |
122 EXPECT_EQ(layer_tree_host_src_->page_scale_layer_->id(), | |
123 layer_tree_host_dst_->page_scale_layer_->id()); | |
124 } else { | |
125 EXPECT_EQ(nullptr, layer_tree_host_dst_->page_scale_layer_); | |
126 } | |
127 if (layer_tree_host_src_->inner_viewport_scroll_layer_) { | |
128 EXPECT_EQ(layer_tree_host_src_->inner_viewport_scroll_layer_->id(), | |
129 layer_tree_host_dst_->inner_viewport_scroll_layer_->id()); | |
130 } else { | |
131 EXPECT_EQ(nullptr, layer_tree_host_dst_->inner_viewport_scroll_layer_); | |
132 } | |
133 if (layer_tree_host_src_->outer_viewport_scroll_layer_) { | |
134 EXPECT_EQ(layer_tree_host_src_->outer_viewport_scroll_layer_->id(), | |
135 layer_tree_host_dst_->outer_viewport_scroll_layer_->id()); | |
136 } else { | |
137 EXPECT_EQ(nullptr, layer_tree_host_dst_->outer_viewport_scroll_layer_); | |
138 } | |
139 EXPECT_EQ(layer_tree_host_src_->selection_, | |
140 layer_tree_host_dst_->selection_); | |
141 EXPECT_EQ(layer_tree_host_src_->property_trees_, | |
142 layer_tree_host_dst_->property_trees_); | |
143 EXPECT_EQ(layer_tree_host_src_->surface_id_namespace_, | |
144 layer_tree_host_dst_->surface_id_namespace_); | |
145 EXPECT_EQ(layer_tree_host_src_->next_surface_sequence_, | |
146 layer_tree_host_dst_->next_surface_sequence_); | |
147 } | |
148 | |
149 void RunAllMembersChangedTest() { | |
150 layer_tree_host_src_->needs_full_tree_sync_ = | |
151 !layer_tree_host_src_->needs_full_tree_sync_; | |
152 layer_tree_host_src_->needs_meta_info_recomputation_ = | |
153 !layer_tree_host_src_->needs_meta_info_recomputation_; | |
154 layer_tree_host_src_->source_frame_number_ *= 3; | |
155 layer_tree_host_src_->meta_information_sequence_number_ *= 3; | |
156 | |
157 // Just fake setup a layer for both source and dest. | |
158 scoped_refptr<Layer> root_layer_src = Layer::Create(LayerSettings()); | |
159 layer_tree_host_src_->SetRootLayer(root_layer_src); | |
160 layer_tree_host_dst_->SetRootLayer(Layer::Create(LayerSettings())); | |
161 layer_tree_host_src_->hud_layer_ = | |
162 HeadsUpDisplayLayer::Create(LayerSettings()); | |
163 root_layer_src->AddChild(layer_tree_host_src_->hud_layer_); | |
164 root_layer_src->SetDoubleSided(!root_layer_src->double_sided()); | |
165 | |
166 layer_tree_host_src_->debug_state_.show_replica_screen_space_rects = | |
167 !layer_tree_host_src_->debug_state_.show_replica_screen_space_rects; | |
168 layer_tree_host_src_->device_viewport_size_ = gfx::Size(3, 14); | |
169 layer_tree_host_src_->top_controls_shrink_blink_size_ = | |
170 !layer_tree_host_src_->top_controls_shrink_blink_size_; | |
171 layer_tree_host_src_->top_controls_height_ = | |
172 layer_tree_host_src_->top_controls_height_ * 3 + 1; | |
173 layer_tree_host_src_->top_controls_shown_ratio_ = | |
174 layer_tree_host_src_->top_controls_shown_ratio_ * 3 + 1; | |
175 layer_tree_host_src_->device_scale_factor_ = | |
176 layer_tree_host_src_->device_scale_factor_ * 3 + 1; | |
177 layer_tree_host_src_->painted_device_scale_factor_ = | |
178 layer_tree_host_src_->painted_device_scale_factor_ * 3 + 1; | |
179 layer_tree_host_src_->page_scale_factor_ = | |
180 layer_tree_host_src_->page_scale_factor_ * 3 + 1; | |
181 layer_tree_host_src_->min_page_scale_factor_ = | |
182 layer_tree_host_src_->min_page_scale_factor_ * 3 + 1; | |
183 layer_tree_host_src_->max_page_scale_factor_ = | |
184 layer_tree_host_src_->max_page_scale_factor_ * 3 + 1; | |
185 layer_tree_host_src_->elastic_overscroll_ = gfx::Vector2dF(3, 14); | |
186 layer_tree_host_src_->has_gpu_rasterization_trigger_ = | |
187 !layer_tree_host_src_->has_gpu_rasterization_trigger_; | |
188 layer_tree_host_src_->content_is_suitable_for_gpu_rasterization_ = | |
189 !layer_tree_host_src_->content_is_suitable_for_gpu_rasterization_; | |
190 layer_tree_host_src_->background_color_ = SK_ColorMAGENTA; | |
191 layer_tree_host_src_->has_transparent_background_ = | |
192 !layer_tree_host_src_->has_transparent_background_; | |
193 layer_tree_host_src_->id_ = layer_tree_host_src_->id_ * 3 + 1; | |
194 layer_tree_host_src_->next_commit_forces_redraw_ = | |
195 !layer_tree_host_src_->next_commit_forces_redraw_; | |
196 | |
197 layer_tree_host_src_->overscroll_elasticity_layer_ = | |
198 Layer::Create(LayerSettings()); | |
199 root_layer_src->AddChild( | |
200 layer_tree_host_src_->overscroll_elasticity_layer_); | |
201 layer_tree_host_src_->page_scale_layer_ = Layer::Create(LayerSettings()); | |
202 root_layer_src->AddChild(layer_tree_host_src_->page_scale_layer_); | |
203 layer_tree_host_src_->inner_viewport_scroll_layer_ = | |
204 Layer::Create(LayerSettings()); | |
205 root_layer_src->AddChild( | |
206 layer_tree_host_src_->inner_viewport_scroll_layer_); | |
207 layer_tree_host_src_->outer_viewport_scroll_layer_ = | |
208 Layer::Create(LayerSettings()); | |
209 root_layer_src->AddChild( | |
210 layer_tree_host_src_->outer_viewport_scroll_layer_); | |
211 | |
212 // Set in_paint_layer_contents_ only after all calls to AddChild() have | |
213 // finished to ensure it's allowed to do so at that time. | |
214 layer_tree_host_src_->in_paint_layer_contents_ = | |
215 !layer_tree_host_src_->in_paint_layer_contents_; | |
216 | |
217 LayerSelectionBound sel_bound; | |
218 sel_bound.edge_top = gfx::Point(14, 3); | |
219 LayerSelection selection; | |
220 selection.start = sel_bound; | |
221 layer_tree_host_src_->selection_ = selection; | |
222 | |
223 layer_tree_host_src_->property_trees_.sequence_number = | |
224 layer_tree_host_src_->property_trees_.sequence_number * 3 + 1; | |
225 | |
226 layer_tree_host_src_->surface_id_namespace_ = | |
227 layer_tree_host_src_->surface_id_namespace_ * 3 + 1; | |
228 layer_tree_host_src_->next_surface_sequence_ = | |
229 layer_tree_host_src_->next_surface_sequence_ * 3 + 1; | |
230 | |
231 VerifySerializationAndDeserialization(); | |
232 } | |
233 | |
234 void RunLayersChangedTest() { | |
235 // Just fake setup a layer for both source and dest. | |
236 scoped_refptr<Layer> root_layer_src = Layer::Create(LayerSettings()); | |
237 layer_tree_host_src_->SetRootLayer(root_layer_src); | |
238 layer_tree_host_dst_->SetRootLayer(Layer::Create(LayerSettings())); | |
239 root_layer_src->SetDoubleSided(!root_layer_src->double_sided()); | |
240 | |
241 // No HUD layer or |overscroll_elasticity_layer_|, or the inner/outer | |
242 // viewport scroll layers. | |
243 layer_tree_host_src_->overscroll_elasticity_layer_ = | |
244 Layer::Create(LayerSettings()); | |
245 root_layer_src->AddChild( | |
246 layer_tree_host_src_->overscroll_elasticity_layer_); | |
247 | |
248 VerifySerializationAndDeserialization(); | |
249 } | |
250 | |
251 TestTaskGraphRunner task_graph_runner_src_; | |
vmpstr
2016/01/11 22:06:30
nit: private: or protected:
nyquist
2016/01/13 01:34:11
Done.
| |
252 FakeLayerTreeHostClient fake_client_src_; | |
253 scoped_ptr<LayerTreeHost> layer_tree_host_src_; | |
254 | |
255 TestTaskGraphRunner task_graph_runner_dst_; | |
256 FakeLayerTreeHostClient fake_client_dst_; | |
257 scoped_ptr<LayerTreeHost> layer_tree_host_dst_; | |
258 }; | |
259 | |
260 TEST_F(LayerTreeHostSerializationTest, AllMembersChanged) { | |
261 RunAllMembersChangedTest(); | |
262 } | |
263 | |
264 TEST_F(LayerTreeHostSerializationTest, LayersChanged) { | |
265 RunLayersChangedTest(); | |
266 } | |
267 | |
268 } // namespace cc | |
OLD | NEW |