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

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

Powered by Google App Engine
This is Rietveld 408576698