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 : client_src_(FakeLayerTreeHostClient::DIRECT_3D), |
| 29 client_dst_(FakeLayerTreeHostClient::DIRECT_3D) {} |
| 30 |
| 31 protected: |
| 32 void SetUp() override { |
| 33 layer_tree_host_src_ = |
| 34 FakeLayerTreeHost::Create(&client_src_, &task_graph_runner_src_); |
| 35 layer_tree_host_dst_ = |
| 36 FakeLayerTreeHost::Create(&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 EXPECT_EQ( |
| 71 layer_tree_host_src_->debug_state_.show_replica_screen_space_rects, |
| 72 layer_tree_host_dst_->debug_state_.show_replica_screen_space_rects); |
| 73 EXPECT_EQ(layer_tree_host_src_->device_viewport_size_, |
| 74 layer_tree_host_dst_->device_viewport_size_); |
| 75 EXPECT_EQ(layer_tree_host_src_->top_controls_shrink_blink_size_, |
| 76 layer_tree_host_dst_->top_controls_shrink_blink_size_); |
| 77 EXPECT_EQ(layer_tree_host_src_->top_controls_height_, |
| 78 layer_tree_host_dst_->top_controls_height_); |
| 79 EXPECT_EQ(layer_tree_host_src_->top_controls_shown_ratio_, |
| 80 layer_tree_host_dst_->top_controls_shown_ratio_); |
| 81 EXPECT_EQ(layer_tree_host_src_->device_scale_factor_, |
| 82 layer_tree_host_dst_->device_scale_factor_); |
| 83 EXPECT_EQ(layer_tree_host_src_->painted_device_scale_factor_, |
| 84 layer_tree_host_dst_->painted_device_scale_factor_); |
| 85 EXPECT_EQ(layer_tree_host_src_->page_scale_factor_, |
| 86 layer_tree_host_dst_->page_scale_factor_); |
| 87 EXPECT_EQ(layer_tree_host_src_->min_page_scale_factor_, |
| 88 layer_tree_host_dst_->min_page_scale_factor_); |
| 89 EXPECT_EQ(layer_tree_host_src_->max_page_scale_factor_, |
| 90 layer_tree_host_dst_->max_page_scale_factor_); |
| 91 EXPECT_EQ(layer_tree_host_src_->elastic_overscroll_, |
| 92 layer_tree_host_dst_->elastic_overscroll_); |
| 93 EXPECT_EQ(layer_tree_host_src_->has_gpu_rasterization_trigger_, |
| 94 layer_tree_host_dst_->has_gpu_rasterization_trigger_); |
| 95 EXPECT_EQ(layer_tree_host_src_->content_is_suitable_for_gpu_rasterization_, |
| 96 layer_tree_host_dst_->content_is_suitable_for_gpu_rasterization_); |
| 97 EXPECT_EQ(layer_tree_host_src_->background_color_, |
| 98 layer_tree_host_dst_->background_color_); |
| 99 EXPECT_EQ(layer_tree_host_src_->has_transparent_background_, |
| 100 layer_tree_host_dst_->has_transparent_background_); |
| 101 EXPECT_EQ(layer_tree_host_src_->in_paint_layer_contents_, |
| 102 layer_tree_host_dst_->in_paint_layer_contents_); |
| 103 EXPECT_EQ(layer_tree_host_src_->id_, layer_tree_host_dst_->id_); |
| 104 EXPECT_EQ(layer_tree_host_src_->next_commit_forces_redraw_, |
| 105 layer_tree_host_dst_->next_commit_forces_redraw_); |
| 106 |
| 107 if (layer_tree_host_src_->hud_layer_) { |
| 108 EXPECT_EQ(layer_tree_host_src_->hud_layer_->id(), |
| 109 layer_tree_host_dst_->hud_layer_->id()); |
| 110 } else { |
| 111 EXPECT_EQ(nullptr, layer_tree_host_dst_->hud_layer_); |
| 112 } |
| 113 if (layer_tree_host_src_->overscroll_elasticity_layer_) { |
| 114 EXPECT_EQ(layer_tree_host_src_->overscroll_elasticity_layer_->id(), |
| 115 layer_tree_host_dst_->overscroll_elasticity_layer_->id()); |
| 116 } else { |
| 117 EXPECT_EQ(nullptr, layer_tree_host_dst_->overscroll_elasticity_layer_); |
| 118 } |
| 119 if (layer_tree_host_src_->page_scale_layer_) { |
| 120 EXPECT_EQ(layer_tree_host_src_->page_scale_layer_->id(), |
| 121 layer_tree_host_dst_->page_scale_layer_->id()); |
| 122 } else { |
| 123 EXPECT_EQ(nullptr, layer_tree_host_dst_->page_scale_layer_); |
| 124 } |
| 125 if (layer_tree_host_src_->inner_viewport_scroll_layer_) { |
| 126 EXPECT_EQ(layer_tree_host_src_->inner_viewport_scroll_layer_->id(), |
| 127 layer_tree_host_dst_->inner_viewport_scroll_layer_->id()); |
| 128 } else { |
| 129 EXPECT_EQ(nullptr, layer_tree_host_dst_->inner_viewport_scroll_layer_); |
| 130 } |
| 131 if (layer_tree_host_src_->outer_viewport_scroll_layer_) { |
| 132 EXPECT_EQ(layer_tree_host_src_->outer_viewport_scroll_layer_->id(), |
| 133 layer_tree_host_dst_->outer_viewport_scroll_layer_->id()); |
| 134 } else { |
| 135 EXPECT_EQ(nullptr, layer_tree_host_dst_->outer_viewport_scroll_layer_); |
| 136 } |
| 137 EXPECT_EQ(layer_tree_host_src_->selection_, |
| 138 layer_tree_host_dst_->selection_); |
| 139 EXPECT_EQ(layer_tree_host_src_->property_trees_, |
| 140 layer_tree_host_dst_->property_trees_); |
| 141 EXPECT_EQ(layer_tree_host_src_->surface_id_namespace_, |
| 142 layer_tree_host_dst_->surface_id_namespace_); |
| 143 EXPECT_EQ(layer_tree_host_src_->next_surface_sequence_, |
| 144 layer_tree_host_dst_->next_surface_sequence_); |
| 145 } |
| 146 |
| 147 void RunAllMembersChangedTest() { |
| 148 layer_tree_host_src_->needs_full_tree_sync_ = |
| 149 !layer_tree_host_src_->needs_full_tree_sync_; |
| 150 layer_tree_host_src_->needs_meta_info_recomputation_ = |
| 151 !layer_tree_host_src_->needs_meta_info_recomputation_; |
| 152 layer_tree_host_src_->source_frame_number_ *= 3; |
| 153 layer_tree_host_src_->meta_information_sequence_number_ *= 3; |
| 154 |
| 155 // Just fake setup a layer for both source and dest. |
| 156 scoped_refptr<Layer> root_layer_src = Layer::Create(LayerSettings()); |
| 157 layer_tree_host_src_->SetRootLayer(root_layer_src); |
| 158 layer_tree_host_dst_->SetRootLayer(Layer::Create(LayerSettings())); |
| 159 root_layer_src->SetDoubleSided(!root_layer_src->double_sided()); |
| 160 |
| 161 layer_tree_host_src_->debug_state_.show_replica_screen_space_rects = |
| 162 !layer_tree_host_src_->debug_state_.show_replica_screen_space_rects; |
| 163 layer_tree_host_src_->device_viewport_size_ = gfx::Size(3, 14); |
| 164 layer_tree_host_src_->top_controls_shrink_blink_size_ = |
| 165 !layer_tree_host_src_->top_controls_shrink_blink_size_; |
| 166 layer_tree_host_src_->top_controls_height_ = |
| 167 layer_tree_host_src_->top_controls_height_ * 3 + 1; |
| 168 layer_tree_host_src_->top_controls_shown_ratio_ = |
| 169 layer_tree_host_src_->top_controls_shown_ratio_ * 3 + 1; |
| 170 layer_tree_host_src_->device_scale_factor_ = |
| 171 layer_tree_host_src_->device_scale_factor_ * 3 + 1; |
| 172 layer_tree_host_src_->painted_device_scale_factor_ = |
| 173 layer_tree_host_src_->painted_device_scale_factor_ * 3 + 1; |
| 174 layer_tree_host_src_->page_scale_factor_ = |
| 175 layer_tree_host_src_->page_scale_factor_ * 3 + 1; |
| 176 layer_tree_host_src_->min_page_scale_factor_ = |
| 177 layer_tree_host_src_->min_page_scale_factor_ * 3 + 1; |
| 178 layer_tree_host_src_->max_page_scale_factor_ = |
| 179 layer_tree_host_src_->max_page_scale_factor_ * 3 + 1; |
| 180 layer_tree_host_src_->elastic_overscroll_ = gfx::Vector2dF(3, 14); |
| 181 layer_tree_host_src_->has_gpu_rasterization_trigger_ = |
| 182 !layer_tree_host_src_->has_gpu_rasterization_trigger_; |
| 183 layer_tree_host_src_->content_is_suitable_for_gpu_rasterization_ = |
| 184 !layer_tree_host_src_->content_is_suitable_for_gpu_rasterization_; |
| 185 layer_tree_host_src_->background_color_ = SK_ColorMAGENTA; |
| 186 layer_tree_host_src_->has_transparent_background_ = |
| 187 !layer_tree_host_src_->has_transparent_background_; |
| 188 layer_tree_host_src_->id_ = layer_tree_host_src_->id_ * 3 + 1; |
| 189 layer_tree_host_src_->next_commit_forces_redraw_ = |
| 190 !layer_tree_host_src_->next_commit_forces_redraw_; |
| 191 |
| 192 layer_tree_host_src_->hud_layer_ = |
| 193 HeadsUpDisplayLayer::Create(LayerSettings()); |
| 194 root_layer_src->AddChild(layer_tree_host_src_->hud_layer_); |
| 195 layer_tree_host_src_->overscroll_elasticity_layer_ = |
| 196 Layer::Create(LayerSettings()); |
| 197 root_layer_src->AddChild( |
| 198 layer_tree_host_src_->overscroll_elasticity_layer_); |
| 199 layer_tree_host_src_->page_scale_layer_ = Layer::Create(LayerSettings()); |
| 200 root_layer_src->AddChild(layer_tree_host_src_->page_scale_layer_); |
| 201 layer_tree_host_src_->inner_viewport_scroll_layer_ = |
| 202 Layer::Create(LayerSettings()); |
| 203 root_layer_src->AddChild( |
| 204 layer_tree_host_src_->inner_viewport_scroll_layer_); |
| 205 layer_tree_host_src_->outer_viewport_scroll_layer_ = |
| 206 Layer::Create(LayerSettings()); |
| 207 root_layer_src->AddChild( |
| 208 layer_tree_host_src_->outer_viewport_scroll_layer_); |
| 209 |
| 210 // Set in_paint_layer_contents_ only after all calls to AddChild() have |
| 211 // finished to ensure it's allowed to do so at that time. |
| 212 layer_tree_host_src_->in_paint_layer_contents_ = |
| 213 !layer_tree_host_src_->in_paint_layer_contents_; |
| 214 |
| 215 LayerSelectionBound sel_bound; |
| 216 sel_bound.edge_top = gfx::Point(14, 3); |
| 217 LayerSelection selection; |
| 218 selection.start = sel_bound; |
| 219 layer_tree_host_src_->selection_ = selection; |
| 220 |
| 221 layer_tree_host_src_->property_trees_.sequence_number = |
| 222 layer_tree_host_src_->property_trees_.sequence_number * 3 + 1; |
| 223 |
| 224 layer_tree_host_src_->surface_id_namespace_ = |
| 225 layer_tree_host_src_->surface_id_namespace_ * 3 + 1; |
| 226 layer_tree_host_src_->next_surface_sequence_ = |
| 227 layer_tree_host_src_->next_surface_sequence_ * 3 + 1; |
| 228 |
| 229 VerifySerializationAndDeserialization(); |
| 230 } |
| 231 |
| 232 void RunLayersChangedTest() { |
| 233 // Just fake setup a layer for both source and dest. |
| 234 scoped_refptr<Layer> root_layer_src = Layer::Create(LayerSettings()); |
| 235 layer_tree_host_src_->SetRootLayer(root_layer_src); |
| 236 layer_tree_host_dst_->SetRootLayer(Layer::Create(LayerSettings())); |
| 237 root_layer_src->SetDoubleSided(!root_layer_src->double_sided()); |
| 238 |
| 239 // No HUD layer or |overscroll_elasticity_layer_|, or the inner/outer |
| 240 // viewport scroll layers. |
| 241 layer_tree_host_src_->overscroll_elasticity_layer_ = |
| 242 Layer::Create(LayerSettings()); |
| 243 root_layer_src->AddChild( |
| 244 layer_tree_host_src_->overscroll_elasticity_layer_); |
| 245 |
| 246 VerifySerializationAndDeserialization(); |
| 247 } |
| 248 |
| 249 void LayersChangedMultipleSerializations() { |
| 250 // Just fake setup a layer for both source and dest. |
| 251 scoped_refptr<Layer> root_layer_src = Layer::Create(LayerSettings()); |
| 252 layer_tree_host_src_->SetRootLayer(root_layer_src); |
| 253 layer_tree_host_dst_->SetRootLayer(Layer::Create(LayerSettings())); |
| 254 root_layer_src->SetDoubleSided(!root_layer_src->double_sided()); |
| 255 |
| 256 // Ensure that all the layers work correctly for multiple rounds of |
| 257 // serialization and deserialization. |
| 258 layer_tree_host_src_->hud_layer_ = |
| 259 HeadsUpDisplayLayer::Create(LayerSettings()); |
| 260 root_layer_src->AddChild(layer_tree_host_src_->hud_layer_); |
| 261 layer_tree_host_src_->overscroll_elasticity_layer_ = |
| 262 Layer::Create(LayerSettings()); |
| 263 root_layer_src->AddChild( |
| 264 layer_tree_host_src_->overscroll_elasticity_layer_); |
| 265 layer_tree_host_src_->page_scale_layer_ = Layer::Create(LayerSettings()); |
| 266 root_layer_src->AddChild(layer_tree_host_src_->page_scale_layer_); |
| 267 layer_tree_host_src_->inner_viewport_scroll_layer_ = |
| 268 Layer::Create(LayerSettings()); |
| 269 root_layer_src->AddChild( |
| 270 layer_tree_host_src_->inner_viewport_scroll_layer_); |
| 271 layer_tree_host_src_->outer_viewport_scroll_layer_ = |
| 272 Layer::Create(LayerSettings()); |
| 273 root_layer_src->AddChild( |
| 274 layer_tree_host_src_->outer_viewport_scroll_layer_); |
| 275 |
| 276 VerifySerializationAndDeserialization(); |
| 277 VerifySerializationAndDeserialization(); |
| 278 |
| 279 layer_tree_host_src_->hud_layer_ = nullptr; |
| 280 VerifySerializationAndDeserialization(); |
| 281 layer_tree_host_src_->overscroll_elasticity_layer_ = nullptr; |
| 282 VerifySerializationAndDeserialization(); |
| 283 layer_tree_host_src_->page_scale_layer_ = nullptr; |
| 284 VerifySerializationAndDeserialization(); |
| 285 layer_tree_host_src_->inner_viewport_scroll_layer_ = nullptr; |
| 286 VerifySerializationAndDeserialization(); |
| 287 layer_tree_host_src_->outer_viewport_scroll_layer_ = nullptr; |
| 288 VerifySerializationAndDeserialization(); |
| 289 } |
| 290 |
| 291 private: |
| 292 TestTaskGraphRunner task_graph_runner_src_; |
| 293 FakeLayerTreeHostClient client_src_; |
| 294 scoped_ptr<LayerTreeHost> layer_tree_host_src_; |
| 295 |
| 296 TestTaskGraphRunner task_graph_runner_dst_; |
| 297 FakeLayerTreeHostClient client_dst_; |
| 298 scoped_ptr<LayerTreeHost> layer_tree_host_dst_; |
| 299 }; |
| 300 |
| 301 TEST_F(LayerTreeHostSerializationTest, AllMembersChanged) { |
| 302 RunAllMembersChangedTest(); |
| 303 } |
| 304 |
| 305 TEST_F(LayerTreeHostSerializationTest, LayersChanged) { |
| 306 RunLayersChangedTest(); |
| 307 } |
| 308 |
| 309 TEST_F(LayerTreeHostSerializationTest, LayersChangedMultipleSerializations) { |
| 310 LayersChangedMultipleSerializations(); |
| 311 } |
| 312 |
| 313 } // namespace cc |
OLD | NEW |