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

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: git merge origin/master Created 4 years, 6 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 1167 matching lines...) Expand 10 before | Expand all | Expand 10 after
1501 } 1530 }
1502 1531
1503 bool LayerTreeHost::IsRemoteClient() const { 1532 bool LayerTreeHost::IsRemoteClient() const {
1504 return compositor_mode_ == CompositorMode::REMOTE && 1533 return compositor_mode_ == CompositorMode::REMOTE &&
1505 task_runner_provider_->HasImplThread(); 1534 task_runner_provider_->HasImplThread();
1506 } 1535 }
1507 1536
1508 void LayerTreeHost::ToProtobufForCommit( 1537 void LayerTreeHost::ToProtobufForCommit(
1509 proto::LayerTreeHost* proto, 1538 proto::LayerTreeHost* proto,
1510 std::vector<std::unique_ptr<SwapPromise>>* swap_promises) { 1539 std::vector<std::unique_ptr<SwapPromise>>* swap_promises) {
1540 DCHECK(engine_picture_cache_);
1511 // Not all fields are serialized, as they are either not needed for a commit, 1541 // Not all fields are serialized, as they are either not needed for a commit,
1512 // or implementation isn't ready yet. 1542 // or implementation isn't ready yet.
1513 // Unsupported items: 1543 // Unsupported items:
1514 // - animations 1544 // - animations
1515 // - UI resources 1545 // - UI resources
1516 // - instrumentation of stats 1546 // - instrumentation of stats
1517 // - histograms 1547 // - histograms
1518 // Skipped items: 1548 // Skipped items:
1519 // - SwapPromise as they are mostly used for perf measurements. 1549 // - SwapPromise as they are mostly used for perf measurements.
1520 // - The bitmap and GPU memory related items. 1550 // - The bitmap and GPU memory related items.
(...skipping 19 matching lines...) Expand all
1540 proto->mutable_root_layer()); 1570 proto->mutable_root_layer());
1541 1571
1542 // layers_that_should_push_properties_ should be serialized before layer 1572 // layers_that_should_push_properties_ should be serialized before layer
1543 // properties because it is cleared during the properties serialization. 1573 // properties because it is cleared during the properties serialization.
1544 for (auto layer : layers_that_should_push_properties_) 1574 for (auto layer : layers_that_should_push_properties_)
1545 proto->add_layers_that_should_push_properties(layer->id()); 1575 proto->add_layers_that_should_push_properties(layer->id());
1546 1576
1547 LayerProtoConverter::SerializeLayerProperties(this, 1577 LayerProtoConverter::SerializeLayerProperties(this,
1548 proto->mutable_layer_updates()); 1578 proto->mutable_layer_updates());
1549 1579
1580 PictureCacheUpdate pictures =
1581 engine_picture_cache_->CalculateCacheUpdateAndFlush();
1582 proto::PictureDataVectorToSkPicturesProto(pictures,
1583 proto->mutable_pictures());
1584
1550 proto->set_hud_layer_id(hud_layer_ ? hud_layer_->id() : Layer::INVALID_ID); 1585 proto->set_hud_layer_id(hud_layer_ ? hud_layer_->id() : Layer::INVALID_ID);
1551 debug_state_.ToProtobuf(proto->mutable_debug_state()); 1586 debug_state_.ToProtobuf(proto->mutable_debug_state());
1552 SizeToProto(device_viewport_size_, proto->mutable_device_viewport_size()); 1587 SizeToProto(device_viewport_size_, proto->mutable_device_viewport_size());
1553 proto->set_top_controls_shrink_blink_size(top_controls_shrink_blink_size_); 1588 proto->set_top_controls_shrink_blink_size(top_controls_shrink_blink_size_);
1554 proto->set_top_controls_height(top_controls_height_); 1589 proto->set_top_controls_height(top_controls_height_);
1555 proto->set_top_controls_shown_ratio(top_controls_shown_ratio_); 1590 proto->set_top_controls_shown_ratio(top_controls_shown_ratio_);
1556 proto->set_device_scale_factor(device_scale_factor_); 1591 proto->set_device_scale_factor(device_scale_factor_);
1557 proto->set_painted_device_scale_factor(painted_device_scale_factor_); 1592 proto->set_painted_device_scale_factor(painted_device_scale_factor_);
1558 proto->set_page_scale_factor(page_scale_factor_); 1593 proto->set_page_scale_factor(page_scale_factor_);
1559 proto->set_min_page_scale_factor(min_page_scale_factor_); 1594 proto->set_min_page_scale_factor(min_page_scale_factor_);
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
1596 1631
1597 proto->set_surface_id_namespace(surface_id_namespace_); 1632 proto->set_surface_id_namespace(surface_id_namespace_);
1598 proto->set_next_surface_sequence(next_surface_sequence_); 1633 proto->set_next_surface_sequence(next_surface_sequence_);
1599 1634
1600 TRACE_EVENT_OBJECT_SNAPSHOT_WITH_ID( 1635 TRACE_EVENT_OBJECT_SNAPSHOT_WITH_ID(
1601 "cc.remote", "LayerTreeHostProto", source_frame_number_, 1636 "cc.remote", "LayerTreeHostProto", source_frame_number_,
1602 ComputeLayerTreeHostProtoSizeSplitAsValue(proto)); 1637 ComputeLayerTreeHostProtoSizeSplitAsValue(proto));
1603 } 1638 }
1604 1639
1605 void LayerTreeHost::FromProtobufForCommit(const proto::LayerTreeHost& proto) { 1640 void LayerTreeHost::FromProtobufForCommit(const proto::LayerTreeHost& proto) {
1641 DCHECK(client_picture_cache_);
1642
1606 needs_full_tree_sync_ = proto.needs_full_tree_sync(); 1643 needs_full_tree_sync_ = proto.needs_full_tree_sync();
1607 needs_meta_info_recomputation_ = proto.needs_meta_info_recomputation(); 1644 needs_meta_info_recomputation_ = proto.needs_meta_info_recomputation();
1608 source_frame_number_ = proto.source_frame_number(); 1645 source_frame_number_ = proto.source_frame_number();
1609 1646
1610 // Layer hierarchy. 1647 // Layer hierarchy.
1611 scoped_refptr<Layer> new_root_layer = 1648 scoped_refptr<Layer> new_root_layer =
1612 LayerProtoConverter::DeserializeLayerHierarchy(root_layer_, 1649 LayerProtoConverter::DeserializeLayerHierarchy(root_layer_,
1613 proto.root_layer(), this); 1650 proto.root_layer(), this);
1614 if (root_layer_ != new_root_layer) { 1651 if (root_layer_ != new_root_layer) {
1615 root_layer_ = new_root_layer; 1652 root_layer_ = new_root_layer;
1616 } 1653 }
1617 1654
1618 for (auto layer_id : proto.layers_that_should_push_properties()) 1655 for (auto layer_id : proto.layers_that_should_push_properties())
1619 layers_that_should_push_properties_.insert(layer_id_map_[layer_id]); 1656 layers_that_should_push_properties_.insert(layer_id_map_[layer_id]);
1620 1657
1658 // Ensure ClientPictureCache contains all the necessary SkPictures before
1659 // deserializing the properties.
1660 proto::SkPictures proto_pictures = proto.pictures();
1661 PictureCacheUpdate pictures =
1662 SkPicturesProtoToPictureDataVector(proto_pictures);
1663 client_picture_cache_->ApplyCacheUpdate(pictures);
1664
1621 LayerProtoConverter::DeserializeLayerProperties(root_layer_.get(), 1665 LayerProtoConverter::DeserializeLayerProperties(root_layer_.get(),
1622 proto.layer_updates()); 1666 proto.layer_updates());
1623 1667
1668 // The deserialization is finished, so now clear the cache.
1669 client_picture_cache_->Flush();
1670
1624 debug_state_.FromProtobuf(proto.debug_state()); 1671 debug_state_.FromProtobuf(proto.debug_state());
1625 device_viewport_size_ = ProtoToSize(proto.device_viewport_size()); 1672 device_viewport_size_ = ProtoToSize(proto.device_viewport_size());
1626 top_controls_shrink_blink_size_ = proto.top_controls_shrink_blink_size(); 1673 top_controls_shrink_blink_size_ = proto.top_controls_shrink_blink_size();
1627 top_controls_height_ = proto.top_controls_height(); 1674 top_controls_height_ = proto.top_controls_height();
1628 top_controls_shown_ratio_ = proto.top_controls_shown_ratio(); 1675 top_controls_shown_ratio_ = proto.top_controls_shown_ratio();
1629 device_scale_factor_ = proto.device_scale_factor(); 1676 device_scale_factor_ = proto.device_scale_factor();
1630 painted_device_scale_factor_ = proto.painted_device_scale_factor(); 1677 painted_device_scale_factor_ = proto.painted_device_scale_factor();
1631 page_scale_factor_ = proto.page_scale_factor(); 1678 page_scale_factor_ = proto.page_scale_factor();
1632 min_page_scale_factor_ = proto.min_page_scale_factor(); 1679 min_page_scale_factor_ = proto.min_page_scale_factor();
1633 max_page_scale_factor_ = proto.max_page_scale_factor(); 1680 max_page_scale_factor_ = proto.max_page_scale_factor();
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
1682 int seq_num = property_trees_.sequence_number; 1729 int seq_num = property_trees_.sequence_number;
1683 LayerTreeHostCommon::CallFunctionForEveryLayer(this, [seq_num](Layer* layer) { 1730 LayerTreeHostCommon::CallFunctionForEveryLayer(this, [seq_num](Layer* layer) {
1684 layer->set_property_tree_sequence_number(seq_num); 1731 layer->set_property_tree_sequence_number(seq_num);
1685 }); 1732 });
1686 1733
1687 surface_id_namespace_ = proto.surface_id_namespace(); 1734 surface_id_namespace_ = proto.surface_id_namespace();
1688 next_surface_sequence_ = proto.next_surface_sequence(); 1735 next_surface_sequence_ = proto.next_surface_sequence();
1689 } 1736 }
1690 1737
1691 } // namespace cc 1738 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698