Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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" |
| (...skipping 1218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1269 !task_runner_provider_->HasImplThread()); | 1272 !task_runner_provider_->HasImplThread()); |
| 1270 return compositor_mode_ == CompositorMode::SingleThreaded; | 1273 return compositor_mode_ == CompositorMode::SingleThreaded; |
| 1271 } | 1274 } |
| 1272 | 1275 |
| 1273 bool LayerTreeHost::IsThreaded() const { | 1276 bool LayerTreeHost::IsThreaded() const { |
| 1274 DCHECK(compositor_mode_ != CompositorMode::Threaded || | 1277 DCHECK(compositor_mode_ != CompositorMode::Threaded || |
| 1275 task_runner_provider_->HasImplThread()); | 1278 task_runner_provider_->HasImplThread()); |
| 1276 return compositor_mode_ == CompositorMode::Threaded; | 1279 return compositor_mode_ == CompositorMode::Threaded; |
| 1277 } | 1280 } |
| 1278 | 1281 |
| 1282 void LayerTreeHost::ToProtobufForCommit(proto::LayerTreeHost* proto) const { | |
| 1283 // Not all fields are serialized, as they are eiher not needed for a commit, | |
| 1284 // or implementation isn't ready yet. The members in the latter category | |
| 1285 // are listed below. | |
| 1286 // Things not supported include animations, UI resources, instrumentation | |
| 1287 // of stats, histograms. The output surfaces are only valid on the client-side | |
| 1288 // so they are therefore not serialized. The LayerTreeSettings are needed | |
| 1289 // during construction of the LayerTreeHost, so they should be serialized | |
| 1290 // outside of the LayerTreeHost serialization. SwapPromise are currently not | |
|
vmpstr
2016/01/11 22:06:29
Can you make all of the different things point for
nyquist
2016/01/13 01:34:11
Done.
| |
| 1291 // supported. The bitmap and GPU memory related items are also not serialized. | |
| 1292 // The |visible_| flag will be controlled from the client separately and will | |
| 1293 // need special handling outside of the serialization of the LayerTreeHost. | |
| 1294 // SwapPromise are skipped because they are mostly used for perf measurements. | |
| 1295 // TODO(nyquist): Figure out how to support animations. | |
|
vmpstr
2016/01/11 22:06:30
crbug?
nyquist
2016/01/13 01:34:11
OK with reusing the one for animationcontroller? h
| |
| 1296 proto->set_needs_full_tree_sync(needs_full_tree_sync_); | |
| 1297 proto->set_needs_meta_info_recomputation(needs_meta_info_recomputation_); | |
| 1298 proto->set_source_frame_number(source_frame_number_); | |
| 1299 proto->set_meta_information_sequence_number( | |
| 1300 meta_information_sequence_number_); | |
| 1301 LayerProtoConverter::SerializeLayerHierarchy(root_layer_, | |
| 1302 proto->mutable_root_layer()); | |
| 1303 LayerProtoConverter::SerializeLayerProperties(root_layer_.get(), | |
| 1304 proto->mutable_layer_updates()); | |
| 1305 proto->set_hud_layer_id(hud_layer_ ? hud_layer_->id() : Layer::INVALID_ID); | |
| 1306 debug_state_.ToProtobuf(proto->mutable_debug_state()); | |
| 1307 SizeToProto(device_viewport_size_, proto->mutable_device_viewport_size()); | |
| 1308 proto->set_top_controls_shrink_blink_size(top_controls_shrink_blink_size_); | |
| 1309 proto->set_top_controls_height(top_controls_height_); | |
| 1310 proto->set_top_controls_shown_ratio(top_controls_shown_ratio_); | |
| 1311 proto->set_device_scale_factor(device_scale_factor_); | |
| 1312 proto->set_painted_device_scale_factor(painted_device_scale_factor_); | |
| 1313 proto->set_page_scale_factor(page_scale_factor_); | |
| 1314 proto->set_min_page_scale_factor(min_page_scale_factor_); | |
| 1315 proto->set_max_page_scale_factor(max_page_scale_factor_); | |
| 1316 Vector2dFToProto(elastic_overscroll_, proto->mutable_elastic_overscroll()); | |
| 1317 proto->set_has_gpu_rasterization_trigger(has_gpu_rasterization_trigger_); | |
| 1318 proto->set_content_is_suitable_for_gpu_rasterization( | |
| 1319 content_is_suitable_for_gpu_rasterization_); | |
| 1320 proto->set_background_color(background_color_); | |
| 1321 proto->set_has_transparent_background(has_transparent_background_); | |
| 1322 proto->set_in_paint_layer_contents(in_paint_layer_contents_); | |
| 1323 proto->set_id(id_); | |
| 1324 proto->set_next_commit_forces_redraw(next_commit_forces_redraw_); | |
| 1325 | |
| 1326 // Viewport layers. | |
| 1327 proto->set_overscroll_elasticity_layer_id( | |
| 1328 overscroll_elasticity_layer_ ? overscroll_elasticity_layer_->id() | |
| 1329 : Layer::INVALID_ID); | |
| 1330 proto->set_page_scale_layer_id(page_scale_layer_ ? page_scale_layer_->id() | |
| 1331 : Layer::INVALID_ID); | |
| 1332 proto->set_inner_viewport_scroll_layer_id( | |
| 1333 inner_viewport_scroll_layer_ ? inner_viewport_scroll_layer_->id() | |
| 1334 : Layer::INVALID_ID); | |
| 1335 proto->set_outer_viewport_scroll_layer_id( | |
| 1336 outer_viewport_scroll_layer_ ? outer_viewport_scroll_layer_->id() | |
| 1337 : Layer::INVALID_ID); | |
| 1338 | |
| 1339 LayerSelectionToProtobuf(selection_, proto->mutable_selection()); | |
|
vmpstr
2016/01/11 22:06:30
I'm a little bit sad that some things are out of l
nyquist
2016/01/13 01:34:11
Agreed. See crbug.com/548432 which is tracking tha
| |
| 1340 property_trees_.ToProtobuf(proto->mutable_property_trees()); | |
| 1341 proto->set_surface_id_namespace(surface_id_namespace_); | |
| 1342 proto->set_next_surface_sequence(next_surface_sequence_); | |
| 1343 } | |
| 1344 | |
| 1345 void LayerTreeHost::FromProtobufForCommit(const proto::LayerTreeHost& proto) { | |
| 1346 needs_full_tree_sync_ = proto.needs_full_tree_sync(); | |
| 1347 needs_meta_info_recomputation_ = proto.needs_meta_info_recomputation(); | |
| 1348 source_frame_number_ = proto.source_frame_number(); | |
| 1349 meta_information_sequence_number_ = proto.meta_information_sequence_number(); | |
| 1350 | |
| 1351 // Layer hierarchy. | |
| 1352 scoped_refptr<Layer> new_root_layer = | |
| 1353 LayerProtoConverter::DeserializeLayerHierarchy(root_layer_, | |
| 1354 proto.root_layer()); | |
| 1355 if (root_layer_ != new_root_layer) { | |
| 1356 root_layer_->SetLayerTreeHost(nullptr); | |
| 1357 root_layer_ = new_root_layer; | |
| 1358 root_layer_->SetLayerTreeHost(this); | |
| 1359 } | |
|
vmpstr
2016/01/11 22:06:30
blank line after this please
nyquist
2016/01/13 01:34:11
Done.
| |
| 1360 layer_id_map_.clear(); | |
|
vmpstr
2016/01/11 22:06:30
// Populate layer_id_map_ with the new layers.
nyquist
2016/01/13 01:34:11
Done.
| |
| 1361 LayerTreeHostCommon::CallFunctionForSubtree( | |
| 1362 root_layer(), | |
| 1363 [this](Layer* layer) { layer_id_map_[layer->id()] = layer; }); | |
| 1364 | |
| 1365 LayerProtoConverter::DeserializeLayerProperties(root_layer_.get(), | |
| 1366 proto.layer_updates()); | |
| 1367 | |
| 1368 if (hud_layer_) | |
| 1369 hud_layer_->SetLayerTreeHost(nullptr); | |
|
vmpstr
2016/01/11 22:06:30
blank line after this please
nyquist
2016/01/13 01:34:11
Done.
| |
| 1370 if (proto.hud_layer_id() == Layer::INVALID_ID) { | |
|
vmpstr
2016/01/11 22:06:30
Should we check if it's the same layer id to avoid
nyquist
2016/01/13 01:34:11
Absolutely! Otherwise this apparently has a bug wh
| |
| 1371 hud_layer_ = nullptr; | |
| 1372 } else { | |
| 1373 DCHECK(layer_id_map_.find(proto.hud_layer_id()) != layer_id_map_.end()); | |
| 1374 hud_layer_ = | |
| 1375 static_cast<HeadsUpDisplayLayer*>(layer_id_map_[proto.hud_layer_id()]); | |
| 1376 } | |
| 1377 | |
| 1378 debug_state_.FromProtobuf(proto.debug_state()); | |
| 1379 device_viewport_size_ = ProtoToSize(proto.device_viewport_size()); | |
| 1380 top_controls_shrink_blink_size_ = proto.top_controls_shrink_blink_size(); | |
| 1381 top_controls_height_ = proto.top_controls_height(); | |
| 1382 top_controls_shown_ratio_ = proto.top_controls_shown_ratio(); | |
| 1383 device_scale_factor_ = proto.device_scale_factor(); | |
| 1384 painted_device_scale_factor_ = proto.painted_device_scale_factor(); | |
| 1385 page_scale_factor_ = proto.page_scale_factor(); | |
| 1386 min_page_scale_factor_ = proto.min_page_scale_factor(); | |
| 1387 max_page_scale_factor_ = proto.max_page_scale_factor(); | |
| 1388 elastic_overscroll_ = ProtoToVector2dF(proto.elastic_overscroll()); | |
| 1389 has_gpu_rasterization_trigger_ = proto.has_gpu_rasterization_trigger(); | |
| 1390 content_is_suitable_for_gpu_rasterization_ = | |
| 1391 proto.content_is_suitable_for_gpu_rasterization(); | |
| 1392 background_color_ = proto.background_color(); | |
| 1393 has_transparent_background_ = proto.has_transparent_background(); | |
| 1394 in_paint_layer_contents_ = proto.in_paint_layer_contents(); | |
| 1395 id_ = proto.id(); | |
| 1396 next_commit_forces_redraw_ = proto.next_commit_forces_redraw(); | |
| 1397 | |
| 1398 // Viewport layers. | |
| 1399 if (overscroll_elasticity_layer_) | |
|
vmpstr
2016/01/11 22:06:30
Same comment for all these layers as for the hud l
nyquist
2016/01/13 01:34:11
Done.
| |
| 1400 overscroll_elasticity_layer_->SetLayerTreeHost(nullptr); | |
| 1401 if (proto.overscroll_elasticity_layer_id() == Layer::INVALID_ID) { | |
| 1402 overscroll_elasticity_layer_ = nullptr; | |
| 1403 } else { | |
| 1404 DCHECK(layer_id_map_.find(proto.overscroll_elasticity_layer_id()) != | |
| 1405 layer_id_map_.end()); | |
| 1406 overscroll_elasticity_layer_ = | |
| 1407 layer_id_map_[proto.overscroll_elasticity_layer_id()]; | |
| 1408 } | |
| 1409 if (page_scale_layer_) | |
| 1410 page_scale_layer_->SetLayerTreeHost(nullptr); | |
| 1411 if (proto.page_scale_layer_id() == Layer::INVALID_ID) { | |
| 1412 page_scale_layer_ = nullptr; | |
| 1413 } else { | |
| 1414 DCHECK(layer_id_map_.find(proto.page_scale_layer_id()) != | |
| 1415 layer_id_map_.end()); | |
| 1416 page_scale_layer_ = layer_id_map_[proto.page_scale_layer_id()]; | |
| 1417 } | |
| 1418 if (inner_viewport_scroll_layer_) | |
| 1419 inner_viewport_scroll_layer_->SetLayerTreeHost(nullptr); | |
| 1420 if (proto.inner_viewport_scroll_layer_id() == Layer::INVALID_ID) { | |
| 1421 inner_viewport_scroll_layer_ = nullptr; | |
| 1422 } else { | |
| 1423 DCHECK(layer_id_map_.find(proto.inner_viewport_scroll_layer_id()) != | |
| 1424 layer_id_map_.end()); | |
| 1425 inner_viewport_scroll_layer_ = | |
| 1426 layer_id_map_[proto.inner_viewport_scroll_layer_id()]; | |
| 1427 } | |
| 1428 if (outer_viewport_scroll_layer_) | |
| 1429 outer_viewport_scroll_layer_->SetLayerTreeHost(nullptr); | |
| 1430 if (proto.outer_viewport_scroll_layer_id() == Layer::INVALID_ID) { | |
| 1431 outer_viewport_scroll_layer_ = nullptr; | |
| 1432 } else { | |
| 1433 DCHECK(layer_id_map_.find(proto.outer_viewport_scroll_layer_id()) != | |
| 1434 layer_id_map_.end()); | |
| 1435 outer_viewport_scroll_layer_ = | |
| 1436 layer_id_map_[proto.outer_viewport_scroll_layer_id()]; | |
| 1437 } | |
| 1438 | |
| 1439 LayerSelectionFromProtobuf(&selection_, proto.selection()); | |
| 1440 property_trees_.FromProtobuf(proto.property_trees()); | |
| 1441 surface_id_namespace_ = proto.surface_id_namespace(); | |
| 1442 next_surface_sequence_ = proto.next_surface_sequence(); | |
| 1443 } | |
| 1444 | |
| 1279 } // namespace cc | 1445 } // namespace cc |
| OLD | NEW |