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

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

Powered by Google App Engine
This is Rietveld 408576698