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

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

Issue 1982893002: [blimp] Add SkPicture caching support. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix non-existing SkPicture::uniqueID() when dealing with display items without SkPictures Created 4 years, 7 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
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>
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
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
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 1148 matching lines...) Expand 10 before | Expand all | Expand 10 after
1482 return compositor_mode_ == CompositorMode::REMOTE && 1511 return compositor_mode_ == CompositorMode::REMOTE &&
1483 !task_runner_provider_->HasImplThread(); 1512 !task_runner_provider_->HasImplThread();
1484 } 1513 }
1485 1514
1486 bool LayerTreeHost::IsRemoteClient() const { 1515 bool LayerTreeHost::IsRemoteClient() const {
1487 return compositor_mode_ == CompositorMode::REMOTE && 1516 return compositor_mode_ == CompositorMode::REMOTE &&
1488 task_runner_provider_->HasImplThread(); 1517 task_runner_provider_->HasImplThread();
1489 } 1518 }
1490 1519
1491 void LayerTreeHost::ToProtobufForCommit(proto::LayerTreeHost* proto) { 1520 void LayerTreeHost::ToProtobufForCommit(proto::LayerTreeHost* proto) {
1521 DCHECK(engine_picture_cache_);
1492 // Not all fields are serialized, as they are either not needed for a commit, 1522 // Not all fields are serialized, as they are either not needed for a commit,
1493 // or implementation isn't ready yet. 1523 // or implementation isn't ready yet.
1494 // Unsupported items: 1524 // Unsupported items:
1495 // - animations 1525 // - animations
1496 // - UI resources 1526 // - UI resources
1497 // - instrumentation of stats 1527 // - instrumentation of stats
1498 // - histograms 1528 // - histograms
1499 // Skipped items: 1529 // Skipped items:
1500 // - SwapPromise as they are mostly used for perf measurements. 1530 // - SwapPromise as they are mostly used for perf measurements.
1501 // - The bitmap and GPU memory related items. 1531 // - The bitmap and GPU memory related items.
(...skipping 16 matching lines...) Expand all
1518 proto->mutable_root_layer()); 1548 proto->mutable_root_layer());
1519 1549
1520 // layers_that_should_push_properties_ should be serialized before layer 1550 // layers_that_should_push_properties_ should be serialized before layer
1521 // properties because it is cleared during the properties serialization. 1551 // properties because it is cleared during the properties serialization.
1522 for (auto layer : layers_that_should_push_properties_) 1552 for (auto layer : layers_that_should_push_properties_)
1523 proto->add_layers_that_should_push_properties(layer->id()); 1553 proto->add_layers_that_should_push_properties(layer->id());
1524 1554
1525 LayerProtoConverter::SerializeLayerProperties(this, 1555 LayerProtoConverter::SerializeLayerProperties(this,
1526 proto->mutable_layer_updates()); 1556 proto->mutable_layer_updates());
1527 1557
1558 PictureCacheUpdate pictures =
1559 engine_picture_cache_->CalculateCacheUpdateAndFlush();
1560 proto::PictureDataVectorToSkPicturesProto(pictures,
1561 proto->mutable_pictures());
1562
1528 proto->set_hud_layer_id(hud_layer_ ? hud_layer_->id() : Layer::INVALID_ID); 1563 proto->set_hud_layer_id(hud_layer_ ? hud_layer_->id() : Layer::INVALID_ID);
1529 debug_state_.ToProtobuf(proto->mutable_debug_state()); 1564 debug_state_.ToProtobuf(proto->mutable_debug_state());
1530 SizeToProto(device_viewport_size_, proto->mutable_device_viewport_size()); 1565 SizeToProto(device_viewport_size_, proto->mutable_device_viewport_size());
1531 proto->set_top_controls_shrink_blink_size(top_controls_shrink_blink_size_); 1566 proto->set_top_controls_shrink_blink_size(top_controls_shrink_blink_size_);
1532 proto->set_top_controls_height(top_controls_height_); 1567 proto->set_top_controls_height(top_controls_height_);
1533 proto->set_top_controls_shown_ratio(top_controls_shown_ratio_); 1568 proto->set_top_controls_shown_ratio(top_controls_shown_ratio_);
1534 proto->set_device_scale_factor(device_scale_factor_); 1569 proto->set_device_scale_factor(device_scale_factor_);
1535 proto->set_painted_device_scale_factor(painted_device_scale_factor_); 1570 proto->set_painted_device_scale_factor(painted_device_scale_factor_);
1536 proto->set_page_scale_factor(page_scale_factor_); 1571 proto->set_page_scale_factor(page_scale_factor_);
1537 proto->set_min_page_scale_factor(min_page_scale_factor_); 1572 proto->set_min_page_scale_factor(min_page_scale_factor_);
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
1574 1609
1575 proto->set_surface_id_namespace(surface_id_namespace_); 1610 proto->set_surface_id_namespace(surface_id_namespace_);
1576 proto->set_next_surface_sequence(next_surface_sequence_); 1611 proto->set_next_surface_sequence(next_surface_sequence_);
1577 1612
1578 TRACE_EVENT_OBJECT_SNAPSHOT_WITH_ID( 1613 TRACE_EVENT_OBJECT_SNAPSHOT_WITH_ID(
1579 "cc.remote", "LayerTreeHostProto", source_frame_number_, 1614 "cc.remote", "LayerTreeHostProto", source_frame_number_,
1580 ComputeLayerTreeHostProtoSizeSplitAsValue(proto)); 1615 ComputeLayerTreeHostProtoSizeSplitAsValue(proto));
1581 } 1616 }
1582 1617
1583 void LayerTreeHost::FromProtobufForCommit(const proto::LayerTreeHost& proto) { 1618 void LayerTreeHost::FromProtobufForCommit(const proto::LayerTreeHost& proto) {
1619 DCHECK(client_picture_cache_);
1620
1584 needs_full_tree_sync_ = proto.needs_full_tree_sync(); 1621 needs_full_tree_sync_ = proto.needs_full_tree_sync();
1585 needs_meta_info_recomputation_ = proto.needs_meta_info_recomputation(); 1622 needs_meta_info_recomputation_ = proto.needs_meta_info_recomputation();
1586 source_frame_number_ = proto.source_frame_number(); 1623 source_frame_number_ = proto.source_frame_number();
1587 1624
1588 // Layer hierarchy. 1625 // Layer hierarchy.
1589 scoped_refptr<Layer> new_root_layer = 1626 scoped_refptr<Layer> new_root_layer =
1590 LayerProtoConverter::DeserializeLayerHierarchy(root_layer_, 1627 LayerProtoConverter::DeserializeLayerHierarchy(root_layer_,
1591 proto.root_layer(), this); 1628 proto.root_layer(), this);
1592 if (root_layer_ != new_root_layer) { 1629 if (root_layer_ != new_root_layer) {
1593 root_layer_ = new_root_layer; 1630 root_layer_ = new_root_layer;
1594 } 1631 }
1595 1632
1596 for (auto layer_id : proto.layers_that_should_push_properties()) 1633 for (auto layer_id : proto.layers_that_should_push_properties())
1597 layers_that_should_push_properties_.insert(layer_id_map_[layer_id]); 1634 layers_that_should_push_properties_.insert(layer_id_map_[layer_id]);
1598 1635
1636 // Ensure ClientPictureCache contains all the necessary SkPictures before
1637 // deserializing the properties.
1638 proto::SkPictures proto_pictures = proto.pictures();
1639 PictureCacheUpdate pictures =
1640 SkPicturesProtoToPictureDataVector(proto_pictures);
1641 client_picture_cache_->ApplyCacheUpdate(pictures);
1642
1599 LayerProtoConverter::DeserializeLayerProperties(root_layer_.get(), 1643 LayerProtoConverter::DeserializeLayerProperties(root_layer_.get(),
1600 proto.layer_updates()); 1644 proto.layer_updates());
1601 1645
1646 // The deserialization is finished, so now clear the cache.
1647 client_picture_cache_->Flush();
1648
1602 debug_state_.FromProtobuf(proto.debug_state()); 1649 debug_state_.FromProtobuf(proto.debug_state());
1603 device_viewport_size_ = ProtoToSize(proto.device_viewport_size()); 1650 device_viewport_size_ = ProtoToSize(proto.device_viewport_size());
1604 top_controls_shrink_blink_size_ = proto.top_controls_shrink_blink_size(); 1651 top_controls_shrink_blink_size_ = proto.top_controls_shrink_blink_size();
1605 top_controls_height_ = proto.top_controls_height(); 1652 top_controls_height_ = proto.top_controls_height();
1606 top_controls_shown_ratio_ = proto.top_controls_shown_ratio(); 1653 top_controls_shown_ratio_ = proto.top_controls_shown_ratio();
1607 device_scale_factor_ = proto.device_scale_factor(); 1654 device_scale_factor_ = proto.device_scale_factor();
1608 painted_device_scale_factor_ = proto.painted_device_scale_factor(); 1655 painted_device_scale_factor_ = proto.painted_device_scale_factor();
1609 page_scale_factor_ = proto.page_scale_factor(); 1656 page_scale_factor_ = proto.page_scale_factor();
1610 min_page_scale_factor_ = proto.min_page_scale_factor(); 1657 min_page_scale_factor_ = proto.min_page_scale_factor();
1611 max_page_scale_factor_ = proto.max_page_scale_factor(); 1658 max_page_scale_factor_ = proto.max_page_scale_factor();
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
1660 int seq_num = property_trees_.sequence_number; 1707 int seq_num = property_trees_.sequence_number;
1661 LayerTreeHostCommon::CallFunctionForEveryLayer(this, [seq_num](Layer* layer) { 1708 LayerTreeHostCommon::CallFunctionForEveryLayer(this, [seq_num](Layer* layer) {
1662 layer->set_property_tree_sequence_number(seq_num); 1709 layer->set_property_tree_sequence_number(seq_num);
1663 }); 1710 });
1664 1711
1665 surface_id_namespace_ = proto.surface_id_namespace(); 1712 surface_id_namespace_ = proto.surface_id_namespace();
1666 next_surface_sequence_ = proto.next_surface_sequence(); 1713 next_surface_sequence_ = proto.next_surface_sequence();
1667 } 1714 }
1668 1715
1669 } // namespace cc 1716 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698