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> |
| 11 #include <memory> |
11 #include <stack> | 12 #include <stack> |
12 #include <string> | 13 #include <string> |
13 #include <unordered_map> | 14 #include <unordered_map> |
14 | 15 |
15 #include "base/atomic_sequence_num.h" | 16 #include "base/atomic_sequence_num.h" |
16 #include "base/auto_reset.h" | 17 #include "base/auto_reset.h" |
17 #include "base/bind.h" | 18 #include "base/bind.h" |
18 #include "base/command_line.h" | 19 #include "base/command_line.h" |
19 #include "base/location.h" | 20 #include "base/location.h" |
20 #include "base/metrics/histogram.h" | 21 #include "base/metrics/histogram.h" |
(...skipping 12 matching lines...) Expand all Loading... |
33 #include "cc/debug/rendering_stats_instrumentation.h" | 34 #include "cc/debug/rendering_stats_instrumentation.h" |
34 #include "cc/input/layer_selection_bound.h" | 35 #include "cc/input/layer_selection_bound.h" |
35 #include "cc/input/page_scale_animation.h" | 36 #include "cc/input/page_scale_animation.h" |
36 #include "cc/layers/heads_up_display_layer.h" | 37 #include "cc/layers/heads_up_display_layer.h" |
37 #include "cc/layers/heads_up_display_layer_impl.h" | 38 #include "cc/layers/heads_up_display_layer_impl.h" |
38 #include "cc/layers/layer.h" | 39 #include "cc/layers/layer.h" |
39 #include "cc/layers/layer_iterator.h" | 40 #include "cc/layers/layer_iterator.h" |
40 #include "cc/layers/layer_proto_converter.h" | 41 #include "cc/layers/layer_proto_converter.h" |
41 #include "cc/layers/painted_scrollbar_layer.h" | 42 #include "cc/layers/painted_scrollbar_layer.h" |
42 #include "cc/proto/gfx_conversions.h" | 43 #include "cc/proto/gfx_conversions.h" |
| 44 #include "cc/proto/image_serialization_processor.h" |
43 #include "cc/proto/layer_tree_host.pb.h" | 45 #include "cc/proto/layer_tree_host.pb.h" |
| 46 #include "cc/proto/picture_cache.h" |
| 47 #include "cc/proto/picture_cache_conversions.h" |
44 #include "cc/resources/ui_resource_request.h" | 48 #include "cc/resources/ui_resource_request.h" |
45 #include "cc/scheduler/begin_frame_source.h" | 49 #include "cc/scheduler/begin_frame_source.h" |
46 #include "cc/trees/draw_property_utils.h" | 50 #include "cc/trees/draw_property_utils.h" |
47 #include "cc/trees/layer_tree_host_client.h" | 51 #include "cc/trees/layer_tree_host_client.h" |
48 #include "cc/trees/layer_tree_host_common.h" | 52 #include "cc/trees/layer_tree_host_common.h" |
49 #include "cc/trees/layer_tree_host_impl.h" | 53 #include "cc/trees/layer_tree_host_impl.h" |
50 #include "cc/trees/layer_tree_impl.h" | 54 #include "cc/trees/layer_tree_impl.h" |
51 #include "cc/trees/property_tree_builder.h" | 55 #include "cc/trees/property_tree_builder.h" |
52 #include "cc/trees/proxy_main.h" | 56 #include "cc/trees/proxy_main.h" |
53 #include "cc/trees/remote_channel_impl.h" | 57 #include "cc/trees/remote_channel_impl.h" |
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
276 InitializeProxy(SingleThreadProxy::Create(this, single_thread_client, | 280 InitializeProxy(SingleThreadProxy::Create(this, single_thread_client, |
277 task_runner_provider_.get()), | 281 task_runner_provider_.get()), |
278 std::move(external_begin_frame_source)); | 282 std::move(external_begin_frame_source)); |
279 } | 283 } |
280 | 284 |
281 void LayerTreeHost::InitializeRemoteServer( | 285 void LayerTreeHost::InitializeRemoteServer( |
282 RemoteProtoChannel* remote_proto_channel, | 286 RemoteProtoChannel* remote_proto_channel, |
283 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner) { | 287 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner) { |
284 task_runner_provider_ = TaskRunnerProvider::Create(main_task_runner, nullptr); | 288 task_runner_provider_ = TaskRunnerProvider::Create(main_task_runner, nullptr); |
285 | 289 |
| 290 if (image_serialization_processor_) { |
| 291 engine_picture_cache_ = |
| 292 image_serialization_processor_->CreateEnginePictureCache(); |
| 293 } |
| 294 |
286 // The LayerTreeHost on the server never requests the output surface since | 295 // The LayerTreeHost on the server never requests the output surface since |
287 // it is only needed on the client. Since ProxyMain aborts commits if | 296 // it is only needed on the client. Since ProxyMain aborts commits if |
288 // output_surface_lost() is true, always assume we have the output surface | 297 // output_surface_lost() is true, always assume we have the output surface |
289 // on the server. | 298 // on the server. |
290 output_surface_lost_ = false; | 299 output_surface_lost_ = false; |
291 | 300 |
292 InitializeProxy(ProxyMain::CreateRemote(remote_proto_channel, this, | 301 InitializeProxy(ProxyMain::CreateRemote(remote_proto_channel, this, |
293 task_runner_provider_.get()), | 302 task_runner_provider_.get()), |
294 nullptr); | 303 nullptr); |
295 } | 304 } |
296 | 305 |
297 void LayerTreeHost::InitializeRemoteClient( | 306 void LayerTreeHost::InitializeRemoteClient( |
298 RemoteProtoChannel* remote_proto_channel, | 307 RemoteProtoChannel* remote_proto_channel, |
299 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, | 308 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, |
300 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner) { | 309 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner) { |
301 task_runner_provider_ = | 310 task_runner_provider_ = |
302 TaskRunnerProvider::Create(main_task_runner, impl_task_runner); | 311 TaskRunnerProvider::Create(main_task_runner, impl_task_runner); |
303 | 312 |
| 313 if (image_serialization_processor_) { |
| 314 client_picture_cache_ = |
| 315 image_serialization_processor_->CreateClientPictureCache(); |
| 316 } |
| 317 |
304 // For the remote mode, the RemoteChannelImpl implements the Proxy, which is | 318 // For the remote mode, the RemoteChannelImpl implements the Proxy, which is |
305 // owned by the LayerTreeHost. The RemoteChannelImpl pipes requests which need | 319 // owned by the LayerTreeHost. The RemoteChannelImpl pipes requests which need |
306 // to handled locally, for instance the Output Surface creation to the | 320 // to handled locally, for instance the Output Surface creation to the |
307 // LayerTreeHost on the client, while the other requests are sent to the | 321 // LayerTreeHost on the client, while the other requests are sent to the |
308 // RemoteChannelMain on the server which directs them to ProxyMain and the | 322 // RemoteChannelMain on the server which directs them to ProxyMain and the |
309 // remote server LayerTreeHost. | 323 // remote server LayerTreeHost. |
310 InitializeProxy(RemoteChannelImpl::Create(this, remote_proto_channel, | 324 InitializeProxy(RemoteChannelImpl::Create(this, remote_proto_channel, |
311 task_runner_provider_.get()), | 325 task_runner_provider_.get()), |
312 nullptr); | 326 nullptr); |
313 } | 327 } |
314 | 328 |
315 void LayerTreeHost::InitializeForTesting( | 329 void LayerTreeHost::InitializeForTesting( |
316 std::unique_ptr<TaskRunnerProvider> task_runner_provider, | 330 std::unique_ptr<TaskRunnerProvider> task_runner_provider, |
317 std::unique_ptr<Proxy> proxy_for_testing, | 331 std::unique_ptr<Proxy> proxy_for_testing, |
318 std::unique_ptr<BeginFrameSource> external_begin_frame_source) { | 332 std::unique_ptr<BeginFrameSource> external_begin_frame_source) { |
319 task_runner_provider_ = std::move(task_runner_provider); | 333 task_runner_provider_ = std::move(task_runner_provider); |
| 334 |
| 335 InitializePictureCacheForTesting(); |
| 336 |
320 InitializeProxy(std::move(proxy_for_testing), | 337 InitializeProxy(std::move(proxy_for_testing), |
321 std::move(external_begin_frame_source)); | 338 std::move(external_begin_frame_source)); |
322 } | 339 } |
323 | 340 |
| 341 void LayerTreeHost::InitializePictureCacheForTesting() { |
| 342 if (!image_serialization_processor_) |
| 343 return; |
| 344 |
| 345 // Initialize both engine and client cache to ensure serialization tests |
| 346 // with a single LayerTreeHost can work correctly. |
| 347 engine_picture_cache_ = |
| 348 image_serialization_processor_->CreateEnginePictureCache(); |
| 349 client_picture_cache_ = |
| 350 image_serialization_processor_->CreateClientPictureCache(); |
| 351 } |
| 352 |
324 void LayerTreeHost::SetTaskRunnerProviderForTesting( | 353 void LayerTreeHost::SetTaskRunnerProviderForTesting( |
325 std::unique_ptr<TaskRunnerProvider> task_runner_provider) { | 354 std::unique_ptr<TaskRunnerProvider> task_runner_provider) { |
326 DCHECK(!task_runner_provider_); | 355 DCHECK(!task_runner_provider_); |
327 task_runner_provider_ = std::move(task_runner_provider); | 356 task_runner_provider_ = std::move(task_runner_provider); |
328 } | 357 } |
329 | 358 |
330 void LayerTreeHost::InitializeProxy( | 359 void LayerTreeHost::InitializeProxy( |
331 std::unique_ptr<Proxy> proxy, | 360 std::unique_ptr<Proxy> proxy, |
332 std::unique_ptr<BeginFrameSource> external_begin_frame_source) { | 361 std::unique_ptr<BeginFrameSource> external_begin_frame_source) { |
333 TRACE_EVENT0("cc", "LayerTreeHost::InitializeForReal"); | 362 TRACE_EVENT0("cc", "LayerTreeHost::InitializeForReal"); |
(...skipping 1159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1493 } | 1522 } |
1494 | 1523 |
1495 bool LayerTreeHost::IsRemoteClient() const { | 1524 bool LayerTreeHost::IsRemoteClient() const { |
1496 return compositor_mode_ == CompositorMode::REMOTE && | 1525 return compositor_mode_ == CompositorMode::REMOTE && |
1497 task_runner_provider_->HasImplThread(); | 1526 task_runner_provider_->HasImplThread(); |
1498 } | 1527 } |
1499 | 1528 |
1500 void LayerTreeHost::ToProtobufForCommit( | 1529 void LayerTreeHost::ToProtobufForCommit( |
1501 proto::LayerTreeHost* proto, | 1530 proto::LayerTreeHost* proto, |
1502 std::vector<std::unique_ptr<SwapPromise>>* swap_promises) { | 1531 std::vector<std::unique_ptr<SwapPromise>>* swap_promises) { |
| 1532 DCHECK(engine_picture_cache_); |
1503 // Not all fields are serialized, as they are either not needed for a commit, | 1533 // Not all fields are serialized, as they are either not needed for a commit, |
1504 // or implementation isn't ready yet. | 1534 // or implementation isn't ready yet. |
1505 // Unsupported items: | 1535 // Unsupported items: |
1506 // - animations | 1536 // - animations |
1507 // - UI resources | 1537 // - UI resources |
1508 // - instrumentation of stats | 1538 // - instrumentation of stats |
1509 // - histograms | 1539 // - histograms |
1510 // Skipped items: | 1540 // Skipped items: |
1511 // - SwapPromise as they are mostly used for perf measurements. | 1541 // - SwapPromise as they are mostly used for perf measurements. |
1512 // - The bitmap and GPU memory related items. | 1542 // - The bitmap and GPU memory related items. |
(...skipping 19 matching lines...) Expand all Loading... |
1532 proto->mutable_root_layer()); | 1562 proto->mutable_root_layer()); |
1533 | 1563 |
1534 // layers_that_should_push_properties_ should be serialized before layer | 1564 // layers_that_should_push_properties_ should be serialized before layer |
1535 // properties because it is cleared during the properties serialization. | 1565 // properties because it is cleared during the properties serialization. |
1536 for (auto layer : layers_that_should_push_properties_) | 1566 for (auto layer : layers_that_should_push_properties_) |
1537 proto->add_layers_that_should_push_properties(layer->id()); | 1567 proto->add_layers_that_should_push_properties(layer->id()); |
1538 | 1568 |
1539 LayerProtoConverter::SerializeLayerProperties(this, | 1569 LayerProtoConverter::SerializeLayerProperties(this, |
1540 proto->mutable_layer_updates()); | 1570 proto->mutable_layer_updates()); |
1541 | 1571 |
| 1572 PictureCacheUpdate pictures = |
| 1573 engine_picture_cache_->CalculateCacheUpdateAndFlush(); |
| 1574 proto::PictureDataVectorToSkPicturesProto(pictures, |
| 1575 proto->mutable_pictures()); |
| 1576 |
1542 proto->set_hud_layer_id(hud_layer_ ? hud_layer_->id() : Layer::INVALID_ID); | 1577 proto->set_hud_layer_id(hud_layer_ ? hud_layer_->id() : Layer::INVALID_ID); |
1543 debug_state_.ToProtobuf(proto->mutable_debug_state()); | 1578 debug_state_.ToProtobuf(proto->mutable_debug_state()); |
1544 SizeToProto(device_viewport_size_, proto->mutable_device_viewport_size()); | 1579 SizeToProto(device_viewport_size_, proto->mutable_device_viewport_size()); |
1545 proto->set_top_controls_shrink_blink_size(top_controls_shrink_blink_size_); | 1580 proto->set_top_controls_shrink_blink_size(top_controls_shrink_blink_size_); |
1546 proto->set_top_controls_height(top_controls_height_); | 1581 proto->set_top_controls_height(top_controls_height_); |
1547 proto->set_top_controls_shown_ratio(top_controls_shown_ratio_); | 1582 proto->set_top_controls_shown_ratio(top_controls_shown_ratio_); |
1548 proto->set_device_scale_factor(device_scale_factor_); | 1583 proto->set_device_scale_factor(device_scale_factor_); |
1549 proto->set_painted_device_scale_factor(painted_device_scale_factor_); | 1584 proto->set_painted_device_scale_factor(painted_device_scale_factor_); |
1550 proto->set_page_scale_factor(page_scale_factor_); | 1585 proto->set_page_scale_factor(page_scale_factor_); |
1551 proto->set_min_page_scale_factor(min_page_scale_factor_); | 1586 proto->set_min_page_scale_factor(min_page_scale_factor_); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1588 | 1623 |
1589 proto->set_surface_id_namespace(surface_id_namespace_); | 1624 proto->set_surface_id_namespace(surface_id_namespace_); |
1590 proto->set_next_surface_sequence(next_surface_sequence_); | 1625 proto->set_next_surface_sequence(next_surface_sequence_); |
1591 | 1626 |
1592 TRACE_EVENT_OBJECT_SNAPSHOT_WITH_ID( | 1627 TRACE_EVENT_OBJECT_SNAPSHOT_WITH_ID( |
1593 "cc.remote", "LayerTreeHostProto", source_frame_number_, | 1628 "cc.remote", "LayerTreeHostProto", source_frame_number_, |
1594 ComputeLayerTreeHostProtoSizeSplitAsValue(proto)); | 1629 ComputeLayerTreeHostProtoSizeSplitAsValue(proto)); |
1595 } | 1630 } |
1596 | 1631 |
1597 void LayerTreeHost::FromProtobufForCommit(const proto::LayerTreeHost& proto) { | 1632 void LayerTreeHost::FromProtobufForCommit(const proto::LayerTreeHost& proto) { |
| 1633 DCHECK(client_picture_cache_); |
| 1634 |
1598 needs_full_tree_sync_ = proto.needs_full_tree_sync(); | 1635 needs_full_tree_sync_ = proto.needs_full_tree_sync(); |
1599 needs_meta_info_recomputation_ = proto.needs_meta_info_recomputation(); | 1636 needs_meta_info_recomputation_ = proto.needs_meta_info_recomputation(); |
1600 source_frame_number_ = proto.source_frame_number(); | 1637 source_frame_number_ = proto.source_frame_number(); |
1601 | 1638 |
1602 // Layer hierarchy. | 1639 // Layer hierarchy. |
1603 scoped_refptr<Layer> new_root_layer = | 1640 scoped_refptr<Layer> new_root_layer = |
1604 LayerProtoConverter::DeserializeLayerHierarchy(root_layer_, | 1641 LayerProtoConverter::DeserializeLayerHierarchy(root_layer_, |
1605 proto.root_layer(), this); | 1642 proto.root_layer(), this); |
1606 if (root_layer_ != new_root_layer) { | 1643 if (root_layer_ != new_root_layer) { |
1607 root_layer_ = new_root_layer; | 1644 root_layer_ = new_root_layer; |
1608 } | 1645 } |
1609 | 1646 |
1610 for (auto layer_id : proto.layers_that_should_push_properties()) | 1647 for (auto layer_id : proto.layers_that_should_push_properties()) |
1611 layers_that_should_push_properties_.insert(layer_id_map_[layer_id]); | 1648 layers_that_should_push_properties_.insert(layer_id_map_[layer_id]); |
1612 | 1649 |
| 1650 // Ensure ClientPictureCache contains all the necessary SkPictures before |
| 1651 // deserializing the properties. |
| 1652 proto::SkPictures proto_pictures = proto.pictures(); |
| 1653 PictureCacheUpdate pictures = |
| 1654 SkPicturesProtoToPictureDataVector(proto_pictures); |
| 1655 client_picture_cache_->ApplyCacheUpdate(pictures); |
| 1656 |
1613 LayerProtoConverter::DeserializeLayerProperties(root_layer_.get(), | 1657 LayerProtoConverter::DeserializeLayerProperties(root_layer_.get(), |
1614 proto.layer_updates()); | 1658 proto.layer_updates()); |
1615 | 1659 |
| 1660 // The deserialization is finished, so now clear the cache. |
| 1661 client_picture_cache_->Flush(); |
| 1662 |
1616 debug_state_.FromProtobuf(proto.debug_state()); | 1663 debug_state_.FromProtobuf(proto.debug_state()); |
1617 device_viewport_size_ = ProtoToSize(proto.device_viewport_size()); | 1664 device_viewport_size_ = ProtoToSize(proto.device_viewport_size()); |
1618 top_controls_shrink_blink_size_ = proto.top_controls_shrink_blink_size(); | 1665 top_controls_shrink_blink_size_ = proto.top_controls_shrink_blink_size(); |
1619 top_controls_height_ = proto.top_controls_height(); | 1666 top_controls_height_ = proto.top_controls_height(); |
1620 top_controls_shown_ratio_ = proto.top_controls_shown_ratio(); | 1667 top_controls_shown_ratio_ = proto.top_controls_shown_ratio(); |
1621 device_scale_factor_ = proto.device_scale_factor(); | 1668 device_scale_factor_ = proto.device_scale_factor(); |
1622 painted_device_scale_factor_ = proto.painted_device_scale_factor(); | 1669 painted_device_scale_factor_ = proto.painted_device_scale_factor(); |
1623 page_scale_factor_ = proto.page_scale_factor(); | 1670 page_scale_factor_ = proto.page_scale_factor(); |
1624 min_page_scale_factor_ = proto.min_page_scale_factor(); | 1671 min_page_scale_factor_ = proto.min_page_scale_factor(); |
1625 max_page_scale_factor_ = proto.max_page_scale_factor(); | 1672 max_page_scale_factor_ = proto.max_page_scale_factor(); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1674 int seq_num = property_trees_.sequence_number; | 1721 int seq_num = property_trees_.sequence_number; |
1675 LayerTreeHostCommon::CallFunctionForEveryLayer(this, [seq_num](Layer* layer) { | 1722 LayerTreeHostCommon::CallFunctionForEveryLayer(this, [seq_num](Layer* layer) { |
1676 layer->set_property_tree_sequence_number(seq_num); | 1723 layer->set_property_tree_sequence_number(seq_num); |
1677 }); | 1724 }); |
1678 | 1725 |
1679 surface_id_namespace_ = proto.surface_id_namespace(); | 1726 surface_id_namespace_ = proto.surface_id_namespace(); |
1680 next_surface_sequence_ = proto.next_surface_sequence(); | 1727 next_surface_sequence_ = proto.next_surface_sequence(); |
1681 } | 1728 } |
1682 | 1729 |
1683 } // namespace cc | 1730 } // namespace cc |
OLD | NEW |