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

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

Issue 1519293002: Add support for (de)serializing LayerTreeHost. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove unreachable code, and use early return Created 4 years, 11 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
« no previous file with comments | « cc/trees/layer_tree_host.h ('k') | cc/trees/layer_tree_host_unittest_serialization.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/trees/layer_tree_host.h" 5 #include "cc/trees/layer_tree_host.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
(...skipping 18 matching lines...) Expand all
29 #include "cc/base/math_util.h" 29 #include "cc/base/math_util.h"
30 #include "cc/debug/devtools_instrumentation.h" 30 #include "cc/debug/devtools_instrumentation.h"
31 #include "cc/debug/frame_viewer_instrumentation.h" 31 #include "cc/debug/frame_viewer_instrumentation.h"
32 #include "cc/debug/rendering_stats_instrumentation.h" 32 #include "cc/debug/rendering_stats_instrumentation.h"
33 #include "cc/input/layer_selection_bound.h" 33 #include "cc/input/layer_selection_bound.h"
34 #include "cc/input/page_scale_animation.h" 34 #include "cc/input/page_scale_animation.h"
35 #include "cc/layers/heads_up_display_layer.h" 35 #include "cc/layers/heads_up_display_layer.h"
36 #include "cc/layers/heads_up_display_layer_impl.h" 36 #include "cc/layers/heads_up_display_layer_impl.h"
37 #include "cc/layers/layer.h" 37 #include "cc/layers/layer.h"
38 #include "cc/layers/layer_iterator.h" 38 #include "cc/layers/layer_iterator.h"
39 #include "cc/layers/layer_proto_converter.h"
39 #include "cc/layers/layer_settings.h" 40 #include "cc/layers/layer_settings.h"
40 #include "cc/layers/painted_scrollbar_layer.h" 41 #include "cc/layers/painted_scrollbar_layer.h"
42 #include "cc/proto/gfx_conversions.h"
43 #include "cc/proto/layer_tree_host.pb.h"
41 #include "cc/resources/ui_resource_request.h" 44 #include "cc/resources/ui_resource_request.h"
42 #include "cc/scheduler/begin_frame_source.h" 45 #include "cc/scheduler/begin_frame_source.h"
43 #include "cc/trees/draw_property_utils.h" 46 #include "cc/trees/draw_property_utils.h"
44 #include "cc/trees/layer_tree_host_client.h" 47 #include "cc/trees/layer_tree_host_client.h"
45 #include "cc/trees/layer_tree_host_common.h" 48 #include "cc/trees/layer_tree_host_common.h"
46 #include "cc/trees/layer_tree_host_impl.h" 49 #include "cc/trees/layer_tree_host_impl.h"
47 #include "cc/trees/layer_tree_impl.h" 50 #include "cc/trees/layer_tree_impl.h"
48 #include "cc/trees/proxy_main.h" 51 #include "cc/trees/proxy_main.h"
49 #include "cc/trees/single_thread_proxy.h" 52 #include "cc/trees/single_thread_proxy.h"
50 #include "cc/trees/tree_synchronizer.h" 53 #include "cc/trees/tree_synchronizer.h"
51 #include "ui/gfx/geometry/size_conversions.h" 54 #include "ui/gfx/geometry/size_conversions.h"
52 #include "ui/gfx/geometry/vector2d_conversions.h" 55 #include "ui/gfx/geometry/vector2d_conversions.h"
53 56
54 namespace { 57 namespace {
55 static base::StaticAtomicSequenceNumber s_layer_tree_host_sequence_number; 58 static base::StaticAtomicSequenceNumber s_layer_tree_host_sequence_number;
56 } 59 }
57 60
58 namespace cc { 61 namespace cc {
62 namespace {
63
64 Layer* UpdateAndGetLayer(Layer* current_layer,
65 int layer_id,
66 const base::hash_map<int, Layer*>& layer_id_map) {
67 if (layer_id == Layer::INVALID_ID) {
68 if (current_layer)
69 current_layer->SetLayerTreeHost(nullptr);
70
71 return nullptr;
72 }
73
74 auto layer_it = layer_id_map.find(layer_id);
75 DCHECK(layer_it != layer_id_map.end());
76 if (current_layer && current_layer != layer_it->second)
77 current_layer->SetLayerTreeHost(nullptr);
78
79 return layer_it->second;
80 }
81
82 } // namespace
59 83
60 LayerTreeHost::InitParams::InitParams() { 84 LayerTreeHost::InitParams::InitParams() {
61 } 85 }
62 86
63 LayerTreeHost::InitParams::~InitParams() { 87 LayerTreeHost::InitParams::~InitParams() {
64 } 88 }
65 89
66 scoped_ptr<LayerTreeHost> LayerTreeHost::CreateThreaded( 90 scoped_ptr<LayerTreeHost> LayerTreeHost::CreateThreaded(
67 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner, 91 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner,
68 InitParams* params) { 92 InitParams* params) {
(...skipping 1200 matching lines...) Expand 10 before | Expand all | Expand 10 after
1269 !task_runner_provider_->HasImplThread()); 1293 !task_runner_provider_->HasImplThread());
1270 return compositor_mode_ == CompositorMode::SingleThreaded; 1294 return compositor_mode_ == CompositorMode::SingleThreaded;
1271 } 1295 }
1272 1296
1273 bool LayerTreeHost::IsThreaded() const { 1297 bool LayerTreeHost::IsThreaded() const {
1274 DCHECK(compositor_mode_ != CompositorMode::Threaded || 1298 DCHECK(compositor_mode_ != CompositorMode::Threaded ||
1275 task_runner_provider_->HasImplThread()); 1299 task_runner_provider_->HasImplThread());
1276 return compositor_mode_ == CompositorMode::Threaded; 1300 return compositor_mode_ == CompositorMode::Threaded;
1277 } 1301 }
1278 1302
1303 void LayerTreeHost::ToProtobufForCommit(proto::LayerTreeHost* proto) const {
1304 // Not all fields are serialized, as they are eiher not needed for a commit,
1305 // or implementation isn't ready yet.
1306 // Unsupported items:
1307 // - animations
1308 // - UI resources
1309 // - instrumentation of stats
1310 // - histograms
1311 // Skipped items:
1312 // - SwapPromise as they are mostly used for perf measurements.
1313 // - The bitmap and GPU memory related items.
1314 // Other notes:
1315 // - The output surfaces are only valid on the client-side so they are
1316 // therefore not serialized.
1317 // - LayerTreeSettings are needed only during construction of the
1318 // LayerTreeHost, so they are serialized outside of the LayerTreeHost
1319 // serialization.
1320 // - The |visible_| flag will be controlled from the client separately and
1321 // will need special handling outside of the serialization of the
1322 // LayerTreeHost.
1323 // TODO(nyquist): Figure out how to support animations. See crbug.com/570376.
1324 proto->set_needs_full_tree_sync(needs_full_tree_sync_);
1325 proto->set_needs_meta_info_recomputation(needs_meta_info_recomputation_);
1326 proto->set_source_frame_number(source_frame_number_);
1327 proto->set_meta_information_sequence_number(
1328 meta_information_sequence_number_);
1329 LayerProtoConverter::SerializeLayerHierarchy(root_layer_,
1330 proto->mutable_root_layer());
1331 LayerProtoConverter::SerializeLayerProperties(root_layer_.get(),
1332 proto->mutable_layer_updates());
1333 proto->set_hud_layer_id(hud_layer_ ? hud_layer_->id() : Layer::INVALID_ID);
1334 debug_state_.ToProtobuf(proto->mutable_debug_state());
1335 SizeToProto(device_viewport_size_, proto->mutable_device_viewport_size());
1336 proto->set_top_controls_shrink_blink_size(top_controls_shrink_blink_size_);
1337 proto->set_top_controls_height(top_controls_height_);
1338 proto->set_top_controls_shown_ratio(top_controls_shown_ratio_);
1339 proto->set_device_scale_factor(device_scale_factor_);
1340 proto->set_painted_device_scale_factor(painted_device_scale_factor_);
1341 proto->set_page_scale_factor(page_scale_factor_);
1342 proto->set_min_page_scale_factor(min_page_scale_factor_);
1343 proto->set_max_page_scale_factor(max_page_scale_factor_);
1344 Vector2dFToProto(elastic_overscroll_, proto->mutable_elastic_overscroll());
1345 proto->set_has_gpu_rasterization_trigger(has_gpu_rasterization_trigger_);
1346 proto->set_content_is_suitable_for_gpu_rasterization(
1347 content_is_suitable_for_gpu_rasterization_);
1348 proto->set_background_color(background_color_);
1349 proto->set_has_transparent_background(has_transparent_background_);
1350 proto->set_in_paint_layer_contents(in_paint_layer_contents_);
1351 proto->set_id(id_);
1352 proto->set_next_commit_forces_redraw(next_commit_forces_redraw_);
1353
1354 // Viewport layers.
1355 proto->set_overscroll_elasticity_layer_id(
1356 overscroll_elasticity_layer_ ? overscroll_elasticity_layer_->id()
1357 : Layer::INVALID_ID);
1358 proto->set_page_scale_layer_id(page_scale_layer_ ? page_scale_layer_->id()
1359 : Layer::INVALID_ID);
1360 proto->set_inner_viewport_scroll_layer_id(
1361 inner_viewport_scroll_layer_ ? inner_viewport_scroll_layer_->id()
1362 : Layer::INVALID_ID);
1363 proto->set_outer_viewport_scroll_layer_id(
1364 outer_viewport_scroll_layer_ ? outer_viewport_scroll_layer_->id()
1365 : Layer::INVALID_ID);
1366
1367 LayerSelectionToProtobuf(selection_, proto->mutable_selection());
1368 property_trees_.ToProtobuf(proto->mutable_property_trees());
1369 proto->set_surface_id_namespace(surface_id_namespace_);
1370 proto->set_next_surface_sequence(next_surface_sequence_);
1371 }
1372
1373 void LayerTreeHost::FromProtobufForCommit(const proto::LayerTreeHost& proto) {
1374 needs_full_tree_sync_ = proto.needs_full_tree_sync();
1375 needs_meta_info_recomputation_ = proto.needs_meta_info_recomputation();
1376 source_frame_number_ = proto.source_frame_number();
1377 meta_information_sequence_number_ = proto.meta_information_sequence_number();
1378
1379 // Layer hierarchy.
1380 scoped_refptr<Layer> new_root_layer =
1381 LayerProtoConverter::DeserializeLayerHierarchy(root_layer_,
1382 proto.root_layer());
1383 if (root_layer_ != new_root_layer) {
1384 root_layer_->SetLayerTreeHost(nullptr);
1385 root_layer_ = new_root_layer;
1386 root_layer_->SetLayerTreeHost(this);
1387 }
1388
1389 // Populate layer_id_map_ with the new layers.
1390 layer_id_map_.clear();
1391 LayerTreeHostCommon::CallFunctionForSubtree(
1392 root_layer(),
1393 [this](Layer* layer) { layer_id_map_[layer->id()] = layer; });
1394
1395 LayerProtoConverter::DeserializeLayerProperties(root_layer_.get(),
1396 proto.layer_updates());
1397
1398 debug_state_.FromProtobuf(proto.debug_state());
1399 device_viewport_size_ = ProtoToSize(proto.device_viewport_size());
1400 top_controls_shrink_blink_size_ = proto.top_controls_shrink_blink_size();
1401 top_controls_height_ = proto.top_controls_height();
1402 top_controls_shown_ratio_ = proto.top_controls_shown_ratio();
1403 device_scale_factor_ = proto.device_scale_factor();
1404 painted_device_scale_factor_ = proto.painted_device_scale_factor();
1405 page_scale_factor_ = proto.page_scale_factor();
1406 min_page_scale_factor_ = proto.min_page_scale_factor();
1407 max_page_scale_factor_ = proto.max_page_scale_factor();
1408 elastic_overscroll_ = ProtoToVector2dF(proto.elastic_overscroll());
1409 has_gpu_rasterization_trigger_ = proto.has_gpu_rasterization_trigger();
1410 content_is_suitable_for_gpu_rasterization_ =
1411 proto.content_is_suitable_for_gpu_rasterization();
1412 background_color_ = proto.background_color();
1413 has_transparent_background_ = proto.has_transparent_background();
1414 in_paint_layer_contents_ = proto.in_paint_layer_contents();
1415 id_ = proto.id();
1416 next_commit_forces_redraw_ = proto.next_commit_forces_redraw();
1417
1418 hud_layer_ = static_cast<HeadsUpDisplayLayer*>(
1419 UpdateAndGetLayer(hud_layer_.get(), proto.hud_layer_id(), layer_id_map_));
1420 overscroll_elasticity_layer_ =
1421 UpdateAndGetLayer(overscroll_elasticity_layer_.get(),
1422 proto.overscroll_elasticity_layer_id(), layer_id_map_);
1423 page_scale_layer_ = UpdateAndGetLayer(
1424 page_scale_layer_.get(), proto.page_scale_layer_id(), layer_id_map_);
1425 inner_viewport_scroll_layer_ =
1426 UpdateAndGetLayer(inner_viewport_scroll_layer_.get(),
1427 proto.inner_viewport_scroll_layer_id(), layer_id_map_);
1428 outer_viewport_scroll_layer_ =
1429 UpdateAndGetLayer(outer_viewport_scroll_layer_.get(),
1430 proto.outer_viewport_scroll_layer_id(), layer_id_map_);
1431
1432 LayerSelectionFromProtobuf(&selection_, proto.selection());
1433
1434 // It is required to create new PropertyTrees before deserializing it.
1435 property_trees_ = PropertyTrees();
1436 property_trees_.FromProtobuf(proto.property_trees());
1437
1438 surface_id_namespace_ = proto.surface_id_namespace();
1439 next_surface_sequence_ = proto.next_surface_sequence();
1440 }
1441
1279 } // namespace cc 1442 } // namespace cc
OLDNEW
« no previous file with comments | « cc/trees/layer_tree_host.h ('k') | cc/trees/layer_tree_host_unittest_serialization.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698