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. | |
| 1285 // Unsupported items: | |
| 1286 // - animations | |
| 1287 // - UI resources | |
| 1288 // - instrumentation of stats | |
| 1289 // - histograms | |
| 1290 // Skipped items: | |
| 1291 // - SwapPromise as they are mostly used for perf measurements. | |
| 1292 // - The bitmap and GPU memory related items. | |
| 1293 // Other notes: | |
| 1294 // - The output surfaces are only valid on the client-side so they are | |
| 1295 // therefore not serialized. | |
| 1296 // - LayerTreeSettings are needed only during construction of the | |
| 1297 // LayerTreeHost, so they are serialized outside of the LayerTreeHost | |
| 1298 // serialization. | |
| 1299 // - The |visible_| flag will be controlled from the client separately and | |
| 1300 // will need special handling outside of the serialization of the | |
| 1301 // LayerTreeHost. | |
| 1302 // TODO(nyquist): Figure out how to support animations. See crbug.com/570376. | |
| 1303 proto->set_needs_full_tree_sync(needs_full_tree_sync_); | |
| 1304 proto->set_needs_meta_info_recomputation(needs_meta_info_recomputation_); | |
| 1305 proto->set_source_frame_number(source_frame_number_); | |
| 1306 proto->set_meta_information_sequence_number( | |
| 1307 meta_information_sequence_number_); | |
| 1308 LayerProtoConverter::SerializeLayerHierarchy(root_layer_, | |
| 1309 proto->mutable_root_layer()); | |
| 1310 LayerProtoConverter::SerializeLayerProperties(root_layer_.get(), | |
| 1311 proto->mutable_layer_updates()); | |
| 1312 proto->set_hud_layer_id(hud_layer_ ? hud_layer_->id() : Layer::INVALID_ID); | |
| 1313 debug_state_.ToProtobuf(proto->mutable_debug_state()); | |
| 1314 SizeToProto(device_viewport_size_, proto->mutable_device_viewport_size()); | |
| 1315 proto->set_top_controls_shrink_blink_size(top_controls_shrink_blink_size_); | |
| 1316 proto->set_top_controls_height(top_controls_height_); | |
| 1317 proto->set_top_controls_shown_ratio(top_controls_shown_ratio_); | |
| 1318 proto->set_device_scale_factor(device_scale_factor_); | |
| 1319 proto->set_painted_device_scale_factor(painted_device_scale_factor_); | |
| 1320 proto->set_page_scale_factor(page_scale_factor_); | |
| 1321 proto->set_min_page_scale_factor(min_page_scale_factor_); | |
| 1322 proto->set_max_page_scale_factor(max_page_scale_factor_); | |
| 1323 Vector2dFToProto(elastic_overscroll_, proto->mutable_elastic_overscroll()); | |
| 1324 proto->set_has_gpu_rasterization_trigger(has_gpu_rasterization_trigger_); | |
| 1325 proto->set_content_is_suitable_for_gpu_rasterization( | |
| 1326 content_is_suitable_for_gpu_rasterization_); | |
| 1327 proto->set_background_color(background_color_); | |
| 1328 proto->set_has_transparent_background(has_transparent_background_); | |
| 1329 proto->set_in_paint_layer_contents(in_paint_layer_contents_); | |
| 1330 proto->set_id(id_); | |
| 1331 proto->set_next_commit_forces_redraw(next_commit_forces_redraw_); | |
| 1332 | |
| 1333 // Viewport layers. | |
| 1334 proto->set_overscroll_elasticity_layer_id( | |
| 1335 overscroll_elasticity_layer_ ? overscroll_elasticity_layer_->id() | |
| 1336 : Layer::INVALID_ID); | |
| 1337 proto->set_page_scale_layer_id(page_scale_layer_ ? page_scale_layer_->id() | |
| 1338 : Layer::INVALID_ID); | |
| 1339 proto->set_inner_viewport_scroll_layer_id( | |
| 1340 inner_viewport_scroll_layer_ ? inner_viewport_scroll_layer_->id() | |
| 1341 : Layer::INVALID_ID); | |
| 1342 proto->set_outer_viewport_scroll_layer_id( | |
| 1343 outer_viewport_scroll_layer_ ? outer_viewport_scroll_layer_->id() | |
| 1344 : Layer::INVALID_ID); | |
| 1345 | |
| 1346 LayerSelectionToProtobuf(selection_, proto->mutable_selection()); | |
| 1347 property_trees_.ToProtobuf(proto->mutable_property_trees()); | |
| 1348 proto->set_surface_id_namespace(surface_id_namespace_); | |
| 1349 proto->set_next_surface_sequence(next_surface_sequence_); | |
| 1350 } | |
| 1351 | |
| 1352 void LayerTreeHost::FromProtobufForCommit(const proto::LayerTreeHost& proto) { | |
| 1353 needs_full_tree_sync_ = proto.needs_full_tree_sync(); | |
| 1354 needs_meta_info_recomputation_ = proto.needs_meta_info_recomputation(); | |
| 1355 source_frame_number_ = proto.source_frame_number(); | |
| 1356 meta_information_sequence_number_ = proto.meta_information_sequence_number(); | |
| 1357 | |
| 1358 // Layer hierarchy. | |
| 1359 scoped_refptr<Layer> new_root_layer = | |
| 1360 LayerProtoConverter::DeserializeLayerHierarchy(root_layer_, | |
| 1361 proto.root_layer()); | |
| 1362 if (root_layer_ != new_root_layer) { | |
| 1363 root_layer_->SetLayerTreeHost(nullptr); | |
| 1364 root_layer_ = new_root_layer; | |
| 1365 root_layer_->SetLayerTreeHost(this); | |
| 1366 } | |
| 1367 | |
| 1368 // Populate layer_id_map_ with the new layers. | |
| 1369 layer_id_map_.clear(); | |
| 1370 LayerTreeHostCommon::CallFunctionForSubtree( | |
| 1371 root_layer(), | |
| 1372 [this](Layer* layer) { layer_id_map_[layer->id()] = layer; }); | |
| 1373 | |
| 1374 LayerProtoConverter::DeserializeLayerProperties(root_layer_.get(), | |
| 1375 proto.layer_updates()); | |
| 1376 | |
| 1377 debug_state_.FromProtobuf(proto.debug_state()); | |
| 1378 device_viewport_size_ = ProtoToSize(proto.device_viewport_size()); | |
| 1379 top_controls_shrink_blink_size_ = proto.top_controls_shrink_blink_size(); | |
| 1380 top_controls_height_ = proto.top_controls_height(); | |
| 1381 top_controls_shown_ratio_ = proto.top_controls_shown_ratio(); | |
| 1382 device_scale_factor_ = proto.device_scale_factor(); | |
| 1383 painted_device_scale_factor_ = proto.painted_device_scale_factor(); | |
| 1384 page_scale_factor_ = proto.page_scale_factor(); | |
| 1385 min_page_scale_factor_ = proto.min_page_scale_factor(); | |
| 1386 max_page_scale_factor_ = proto.max_page_scale_factor(); | |
| 1387 elastic_overscroll_ = ProtoToVector2dF(proto.elastic_overscroll()); | |
| 1388 has_gpu_rasterization_trigger_ = proto.has_gpu_rasterization_trigger(); | |
| 1389 content_is_suitable_for_gpu_rasterization_ = | |
| 1390 proto.content_is_suitable_for_gpu_rasterization(); | |
| 1391 background_color_ = proto.background_color(); | |
| 1392 has_transparent_background_ = proto.has_transparent_background(); | |
| 1393 in_paint_layer_contents_ = proto.in_paint_layer_contents(); | |
| 1394 id_ = proto.id(); | |
| 1395 next_commit_forces_redraw_ = proto.next_commit_forces_redraw(); | |
| 1396 | |
| 1397 if (proto.hud_layer_id() == Layer::INVALID_ID) { | |
|
vmpstr
2016/01/13 23:38:14
What do you think of a function
Layer* UpdateAndG
nyquist
2016/01/14 00:29:00
Done.
I first added it as a private function, sin
| |
| 1398 if (hud_layer_) | |
| 1399 hud_layer_->SetLayerTreeHost(nullptr); | |
| 1400 | |
| 1401 hud_layer_ = nullptr; | |
| 1402 } else { | |
| 1403 DCHECK(layer_id_map_.find(proto.hud_layer_id()) != layer_id_map_.end()); | |
| 1404 if (hud_layer_ && hud_layer_ != layer_id_map_[proto.hud_layer_id()]) | |
| 1405 hud_layer_->SetLayerTreeHost(nullptr); | |
| 1406 | |
| 1407 hud_layer_ = | |
| 1408 static_cast<HeadsUpDisplayLayer*>(layer_id_map_[proto.hud_layer_id()]); | |
| 1409 } | |
| 1410 | |
| 1411 // Viewport layers. | |
| 1412 if (proto.overscroll_elasticity_layer_id() == Layer::INVALID_ID) { | |
| 1413 if (overscroll_elasticity_layer_) | |
| 1414 overscroll_elasticity_layer_->SetLayerTreeHost(nullptr); | |
| 1415 | |
| 1416 overscroll_elasticity_layer_ = nullptr; | |
| 1417 } else { | |
| 1418 DCHECK(layer_id_map_.find(proto.overscroll_elasticity_layer_id()) != | |
| 1419 layer_id_map_.end()); | |
| 1420 if (overscroll_elasticity_layer_ && | |
| 1421 overscroll_elasticity_layer_ != | |
| 1422 layer_id_map_[proto.overscroll_elasticity_layer_id()]) { | |
| 1423 overscroll_elasticity_layer_->SetLayerTreeHost(nullptr); | |
| 1424 } | |
| 1425 overscroll_elasticity_layer_ = | |
| 1426 layer_id_map_[proto.overscroll_elasticity_layer_id()]; | |
| 1427 } | |
| 1428 | |
| 1429 if (proto.page_scale_layer_id() == Layer::INVALID_ID) { | |
| 1430 if (page_scale_layer_) | |
| 1431 page_scale_layer_->SetLayerTreeHost(nullptr); | |
| 1432 | |
| 1433 page_scale_layer_ = nullptr; | |
| 1434 } else { | |
| 1435 DCHECK(layer_id_map_.find(proto.page_scale_layer_id()) != | |
| 1436 layer_id_map_.end()); | |
| 1437 if (page_scale_layer_ && | |
| 1438 page_scale_layer_ != layer_id_map_[proto.page_scale_layer_id()]) { | |
| 1439 page_scale_layer_->SetLayerTreeHost(nullptr); | |
| 1440 } | |
| 1441 | |
| 1442 page_scale_layer_ = layer_id_map_[proto.page_scale_layer_id()]; | |
| 1443 } | |
| 1444 | |
| 1445 if (proto.inner_viewport_scroll_layer_id() == Layer::INVALID_ID) { | |
| 1446 if (inner_viewport_scroll_layer_) | |
| 1447 inner_viewport_scroll_layer_->SetLayerTreeHost(nullptr); | |
| 1448 | |
| 1449 inner_viewport_scroll_layer_ = nullptr; | |
| 1450 } else { | |
| 1451 DCHECK(layer_id_map_.find(proto.inner_viewport_scroll_layer_id()) != | |
| 1452 layer_id_map_.end()); | |
| 1453 if (inner_viewport_scroll_layer_ && | |
| 1454 inner_viewport_scroll_layer_ != | |
| 1455 layer_id_map_[proto.inner_viewport_scroll_layer_id()]) { | |
| 1456 inner_viewport_scroll_layer_->SetLayerTreeHost(nullptr); | |
| 1457 } | |
| 1458 | |
| 1459 inner_viewport_scroll_layer_ = | |
| 1460 layer_id_map_[proto.inner_viewport_scroll_layer_id()]; | |
| 1461 } | |
| 1462 | |
| 1463 if (proto.outer_viewport_scroll_layer_id() == Layer::INVALID_ID) { | |
| 1464 if (outer_viewport_scroll_layer_) | |
| 1465 outer_viewport_scroll_layer_->SetLayerTreeHost(nullptr); | |
| 1466 | |
| 1467 outer_viewport_scroll_layer_ = nullptr; | |
| 1468 } else { | |
| 1469 DCHECK(layer_id_map_.find(proto.outer_viewport_scroll_layer_id()) != | |
| 1470 layer_id_map_.end()); | |
| 1471 if (outer_viewport_scroll_layer_ && | |
| 1472 outer_viewport_scroll_layer_ != | |
| 1473 layer_id_map_[proto.outer_viewport_scroll_layer_id()]) { | |
| 1474 outer_viewport_scroll_layer_->SetLayerTreeHost(nullptr); | |
| 1475 } | |
| 1476 | |
| 1477 outer_viewport_scroll_layer_ = | |
| 1478 layer_id_map_[proto.outer_viewport_scroll_layer_id()]; | |
| 1479 } | |
| 1480 | |
| 1481 LayerSelectionFromProtobuf(&selection_, proto.selection()); | |
| 1482 | |
| 1483 // It is required to create new PropertyTrees before deserializing it. | |
| 1484 property_trees_ = PropertyTrees(); | |
| 1485 property_trees_.FromProtobuf(proto.property_trees()); | |
| 1486 | |
| 1487 surface_id_namespace_ = proto.surface_id_namespace(); | |
| 1488 next_surface_sequence_ = proto.next_surface_sequence(); | |
| 1489 } | |
| 1490 | |
| 1279 } // namespace cc | 1491 } // namespace cc |
| OLD | NEW |