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

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

Issue 1513643010: cc:: Add remote mode to the compositor (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed vmpstr's comments. Created 4 years, 10 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_common_perftest.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>
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 #include "cc/proto/gfx_conversions.h" 44 #include "cc/proto/gfx_conversions.h"
45 #include "cc/proto/layer_tree_host.pb.h" 45 #include "cc/proto/layer_tree_host.pb.h"
46 #include "cc/resources/ui_resource_request.h" 46 #include "cc/resources/ui_resource_request.h"
47 #include "cc/scheduler/begin_frame_source.h" 47 #include "cc/scheduler/begin_frame_source.h"
48 #include "cc/trees/draw_property_utils.h" 48 #include "cc/trees/draw_property_utils.h"
49 #include "cc/trees/layer_tree_host_client.h" 49 #include "cc/trees/layer_tree_host_client.h"
50 #include "cc/trees/layer_tree_host_common.h" 50 #include "cc/trees/layer_tree_host_common.h"
51 #include "cc/trees/layer_tree_host_impl.h" 51 #include "cc/trees/layer_tree_host_impl.h"
52 #include "cc/trees/layer_tree_impl.h" 52 #include "cc/trees/layer_tree_impl.h"
53 #include "cc/trees/proxy_main.h" 53 #include "cc/trees/proxy_main.h"
54 #include "cc/trees/remote_channel_impl.h"
54 #include "cc/trees/single_thread_proxy.h" 55 #include "cc/trees/single_thread_proxy.h"
55 #include "cc/trees/tree_synchronizer.h" 56 #include "cc/trees/tree_synchronizer.h"
56 #include "ui/gfx/geometry/size_conversions.h" 57 #include "ui/gfx/geometry/size_conversions.h"
57 #include "ui/gfx/geometry/vector2d_conversions.h" 58 #include "ui/gfx/geometry/vector2d_conversions.h"
58 59
59 namespace { 60 namespace {
60 static base::StaticAtomicSequenceNumber s_layer_tree_host_sequence_number; 61 static base::StaticAtomicSequenceNumber s_layer_tree_host_sequence_number;
61 } 62 }
62 63
63 namespace cc { 64 namespace cc {
(...skipping 25 matching lines...) Expand all
89 LayerTreeHost::InitParams::~InitParams() { 90 LayerTreeHost::InitParams::~InitParams() {
90 } 91 }
91 92
92 scoped_ptr<LayerTreeHost> LayerTreeHost::CreateThreaded( 93 scoped_ptr<LayerTreeHost> LayerTreeHost::CreateThreaded(
93 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner, 94 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner,
94 InitParams* params) { 95 InitParams* params) {
95 DCHECK(params->main_task_runner.get()); 96 DCHECK(params->main_task_runner.get());
96 DCHECK(impl_task_runner.get()); 97 DCHECK(impl_task_runner.get());
97 DCHECK(params->settings); 98 DCHECK(params->settings);
98 scoped_ptr<LayerTreeHost> layer_tree_host( 99 scoped_ptr<LayerTreeHost> layer_tree_host(
99 new LayerTreeHost(params, CompositorMode::Threaded)); 100 new LayerTreeHost(params, CompositorMode::THREADED));
100 layer_tree_host->InitializeThreaded( 101 layer_tree_host->InitializeThreaded(
101 params->main_task_runner, impl_task_runner, 102 params->main_task_runner, impl_task_runner,
102 std::move(params->external_begin_frame_source)); 103 std::move(params->external_begin_frame_source));
103 return layer_tree_host; 104 return layer_tree_host;
104 } 105 }
105 106
106 scoped_ptr<LayerTreeHost> LayerTreeHost::CreateSingleThreaded( 107 scoped_ptr<LayerTreeHost> LayerTreeHost::CreateSingleThreaded(
107 LayerTreeHostSingleThreadClient* single_thread_client, 108 LayerTreeHostSingleThreadClient* single_thread_client,
108 InitParams* params) { 109 InitParams* params) {
109 DCHECK(params->settings); 110 DCHECK(params->settings);
110 scoped_ptr<LayerTreeHost> layer_tree_host( 111 scoped_ptr<LayerTreeHost> layer_tree_host(
111 new LayerTreeHost(params, CompositorMode::SingleThreaded)); 112 new LayerTreeHost(params, CompositorMode::SINGLE_THREADED));
112 layer_tree_host->InitializeSingleThreaded( 113 layer_tree_host->InitializeSingleThreaded(
113 single_thread_client, params->main_task_runner, 114 single_thread_client, params->main_task_runner,
114 std::move(params->external_begin_frame_source)); 115 std::move(params->external_begin_frame_source));
115 return layer_tree_host; 116 return layer_tree_host;
116 } 117 }
117 118
119 scoped_ptr<LayerTreeHost> LayerTreeHost::CreateRemoteServer(
120 RemoteProtoChannel* remote_proto_channel,
121 InitParams* params) {
122 DCHECK(params->main_task_runner.get());
123 DCHECK(params->settings);
124 DCHECK(remote_proto_channel);
125
126 // Using an external begin frame source is not supported on the server in
127 // remote mode.
128 DCHECK(!params->settings->use_external_begin_frame_source);
129 DCHECK(!params->external_begin_frame_source);
130
131 scoped_ptr<LayerTreeHost> layer_tree_host(
132 new LayerTreeHost(params, CompositorMode::REMOTE));
133 layer_tree_host->InitializeRemoteServer(remote_proto_channel,
134 params->main_task_runner);
135 return layer_tree_host;
136 }
137
138 scoped_ptr<LayerTreeHost> LayerTreeHost::CreateRemoteClient(
139 RemoteProtoChannel* remote_proto_channel,
140 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner,
141 InitParams* params) {
142 DCHECK(params->main_task_runner.get());
143 DCHECK(params->settings);
144 DCHECK(remote_proto_channel);
145
146 // Using an external begin frame source is not supported in remote mode.
147 // TODO(khushalsagar): Add support for providing an external begin frame
148 // source on the client LayerTreeHost. crbug/576962
149 DCHECK(!params->settings->use_external_begin_frame_source);
150 DCHECK(!params->external_begin_frame_source);
151
152 scoped_ptr<LayerTreeHost> layer_tree_host(
153 new LayerTreeHost(params, CompositorMode::REMOTE));
154 layer_tree_host->InitializeRemoteClient(
155 remote_proto_channel, params->main_task_runner, impl_task_runner);
156 return layer_tree_host;
157 }
158
118 LayerTreeHost::LayerTreeHost(InitParams* params, CompositorMode mode) 159 LayerTreeHost::LayerTreeHost(InitParams* params, CompositorMode mode)
119 : micro_benchmark_controller_(this), 160 : micro_benchmark_controller_(this),
120 next_ui_resource_id_(1), 161 next_ui_resource_id_(1),
121 compositor_mode_(mode), 162 compositor_mode_(mode),
122 needs_full_tree_sync_(true), 163 needs_full_tree_sync_(true),
123 needs_meta_info_recomputation_(true), 164 needs_meta_info_recomputation_(true),
124 client_(params->client), 165 client_(params->client),
125 source_frame_number_(0), 166 source_frame_number_(0),
126 meta_information_sequence_number_(1), 167 meta_information_sequence_number_(1),
127 rendering_stats_instrumentation_(RenderingStatsInstrumentation::Create()), 168 rendering_stats_instrumentation_(RenderingStatsInstrumentation::Create()),
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 void LayerTreeHost::InitializeSingleThreaded( 222 void LayerTreeHost::InitializeSingleThreaded(
182 LayerTreeHostSingleThreadClient* single_thread_client, 223 LayerTreeHostSingleThreadClient* single_thread_client,
183 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, 224 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner,
184 scoped_ptr<BeginFrameSource> external_begin_frame_source) { 225 scoped_ptr<BeginFrameSource> external_begin_frame_source) {
185 task_runner_provider_ = TaskRunnerProvider::Create(main_task_runner, nullptr); 226 task_runner_provider_ = TaskRunnerProvider::Create(main_task_runner, nullptr);
186 InitializeProxy(SingleThreadProxy::Create(this, single_thread_client, 227 InitializeProxy(SingleThreadProxy::Create(this, single_thread_client,
187 task_runner_provider_.get()), 228 task_runner_provider_.get()),
188 std::move(external_begin_frame_source)); 229 std::move(external_begin_frame_source));
189 } 230 }
190 231
232 void LayerTreeHost::InitializeRemoteServer(
233 RemoteProtoChannel* remote_proto_channel,
234 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner) {
235 task_runner_provider_ = TaskRunnerProvider::Create(main_task_runner, nullptr);
236 InitializeProxy(ProxyMain::CreateRemote(remote_proto_channel, this,
237 task_runner_provider_.get()),
238 nullptr);
239 }
240
241 void LayerTreeHost::InitializeRemoteClient(
242 RemoteProtoChannel* remote_proto_channel,
243 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner,
244 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner) {
245 task_runner_provider_ =
246 TaskRunnerProvider::Create(main_task_runner, impl_task_runner);
247
248 // For the remote mode, the RemoteChannelImpl implements the Proxy, which is
249 // owned by the LayerTreeHost. The RemoteChannelImpl pipes requests which need
250 // to handled locally, for instance the Output Surface creation to the
251 // LayerTreeHost on the client, while the other requests are sent to the
252 // RemoteChannelMain on the server which directs them to ProxyMain and the
253 // remote server LayerTreeHost.
254 InitializeProxy(RemoteChannelImpl::Create(this, remote_proto_channel,
255 task_runner_provider_.get()),
256 nullptr);
257 }
258
191 void LayerTreeHost::InitializeForTesting( 259 void LayerTreeHost::InitializeForTesting(
192 scoped_ptr<TaskRunnerProvider> task_runner_provider, 260 scoped_ptr<TaskRunnerProvider> task_runner_provider,
193 scoped_ptr<Proxy> proxy_for_testing, 261 scoped_ptr<Proxy> proxy_for_testing,
194 scoped_ptr<BeginFrameSource> external_begin_frame_source) { 262 scoped_ptr<BeginFrameSource> external_begin_frame_source) {
195 task_runner_provider_ = std::move(task_runner_provider); 263 task_runner_provider_ = std::move(task_runner_provider);
196 InitializeProxy(std::move(proxy_for_testing), 264 InitializeProxy(std::move(proxy_for_testing),
197 std::move(external_begin_frame_source)); 265 std::move(external_begin_frame_source));
198 } 266 }
199 267
200 void LayerTreeHost::SetTaskRunnerProviderForTesting( 268 void LayerTreeHost::SetTaskRunnerProviderForTesting(
201 scoped_ptr<TaskRunnerProvider> task_runner_provider) { 269 scoped_ptr<TaskRunnerProvider> task_runner_provider) {
202 DCHECK(!task_runner_provider_); 270 DCHECK(!task_runner_provider_);
203 task_runner_provider_ = std::move(task_runner_provider); 271 task_runner_provider_ = std::move(task_runner_provider);
204 } 272 }
205 273
206 void LayerTreeHost::InitializeProxy( 274 void LayerTreeHost::InitializeProxy(
207 scoped_ptr<Proxy> proxy, 275 scoped_ptr<Proxy> proxy,
208 scoped_ptr<BeginFrameSource> external_begin_frame_source) { 276 scoped_ptr<BeginFrameSource> external_begin_frame_source) {
209 TRACE_EVENT0("cc", "LayerTreeHost::InitializeForReal"); 277 TRACE_EVENT0("cc", "LayerTreeHost::InitializeForReal");
278 DCHECK(task_runner_provider_);
210 279
211 proxy_ = std::move(proxy); 280 proxy_ = std::move(proxy);
212 proxy_->Start(std::move(external_begin_frame_source)); 281 proxy_->Start(std::move(external_begin_frame_source));
213 if (settings_.accelerated_animation_enabled) { 282 if (settings_.accelerated_animation_enabled) {
214 if (animation_host_) 283 if (animation_host_)
215 animation_host_->SetSupportsScrollAnimations( 284 animation_host_->SetSupportsScrollAnimations(
216 proxy_->SupportsImplScrolling()); 285 proxy_->SupportsImplScrolling());
217 else 286 else
218 animation_registrar_->set_supports_scroll_animations( 287 animation_registrar_->set_supports_scroll_animations(
219 proxy_->SupportsImplScrolling()); 288 proxy_->SupportsImplScrolling());
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 void LayerTreeHost::RequestMainFrameUpdate() { 346 void LayerTreeHost::RequestMainFrameUpdate() {
278 client_->UpdateLayerTreeHost(); 347 client_->UpdateLayerTreeHost();
279 } 348 }
280 349
281 // This function commits the LayerTreeHost to an impl tree. When modifying 350 // This function commits the LayerTreeHost to an impl tree. When modifying
282 // this function, keep in mind that the function *runs* on the impl thread! Any 351 // this function, keep in mind that the function *runs* on the impl thread! Any
283 // code that is logically a main thread operation, e.g. deletion of a Layer, 352 // code that is logically a main thread operation, e.g. deletion of a Layer,
284 // should be delayed until the LayerTreeHost::CommitComplete, which will run 353 // should be delayed until the LayerTreeHost::CommitComplete, which will run
285 // after the commit, but on the main thread. 354 // after the commit, but on the main thread.
286 void LayerTreeHost::FinishCommitOnImplThread(LayerTreeHostImpl* host_impl) { 355 void LayerTreeHost::FinishCommitOnImplThread(LayerTreeHostImpl* host_impl) {
356 DCHECK(!IsRemoteServer());
287 DCHECK(task_runner_provider_->IsImplThread()); 357 DCHECK(task_runner_provider_->IsImplThread());
288 358
289 bool is_new_trace; 359 bool is_new_trace;
290 TRACE_EVENT_IS_NEW_TRACE(&is_new_trace); 360 TRACE_EVENT_IS_NEW_TRACE(&is_new_trace);
291 if (is_new_trace && 361 if (is_new_trace &&
292 frame_viewer_instrumentation::IsTracingLayerTreeSnapshots() && 362 frame_viewer_instrumentation::IsTracingLayerTreeSnapshots() &&
293 root_layer()) { 363 root_layer()) {
294 LayerTreeHostCommon::CallFunctionForSubtree( 364 LayerTreeHostCommon::CallFunctionForSubtree(
295 root_layer(), [](Layer* layer) { layer->DidBeginTracing(); }); 365 root_layer(), [](Layer* layer) { layer->DidBeginTracing(); });
296 } 366 }
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
463 // Note: It is safe to drop all output surface references here as 533 // Note: It is safe to drop all output surface references here as
464 // LayerTreeHostImpl will not keep a pointer to either the old or 534 // LayerTreeHostImpl will not keep a pointer to either the old or
465 // new output surface after failing to initialize the new one. 535 // new output surface after failing to initialize the new one.
466 current_output_surface_ = nullptr; 536 current_output_surface_ = nullptr;
467 new_output_surface_ = nullptr; 537 new_output_surface_ = nullptr;
468 client_->DidFailToInitializeOutputSurface(); 538 client_->DidFailToInitializeOutputSurface();
469 } 539 }
470 540
471 scoped_ptr<LayerTreeHostImpl> LayerTreeHost::CreateLayerTreeHostImpl( 541 scoped_ptr<LayerTreeHostImpl> LayerTreeHost::CreateLayerTreeHostImpl(
472 LayerTreeHostImplClient* client) { 542 LayerTreeHostImplClient* client) {
543 DCHECK(!IsRemoteServer());
473 DCHECK(task_runner_provider_->IsImplThread()); 544 DCHECK(task_runner_provider_->IsImplThread());
474 scoped_ptr<LayerTreeHostImpl> host_impl = LayerTreeHostImpl::Create( 545 scoped_ptr<LayerTreeHostImpl> host_impl = LayerTreeHostImpl::Create(
475 settings_, client, task_runner_provider_.get(), 546 settings_, client, task_runner_provider_.get(),
476 rendering_stats_instrumentation_.get(), shared_bitmap_manager_, 547 rendering_stats_instrumentation_.get(), shared_bitmap_manager_,
477 gpu_memory_buffer_manager_, task_graph_runner_, id_); 548 gpu_memory_buffer_manager_, task_graph_runner_, id_);
478 host_impl->SetHasGpuRasterizationTrigger(has_gpu_rasterization_trigger_); 549 host_impl->SetHasGpuRasterizationTrigger(has_gpu_rasterization_trigger_);
479 host_impl->SetContentIsSuitableForGpuRasterization( 550 host_impl->SetContentIsSuitableForGpuRasterization(
480 content_is_suitable_for_gpu_rasterization_); 551 content_is_suitable_for_gpu_rasterization_);
481 shared_bitmap_manager_ = NULL; 552 shared_bitmap_manager_ = NULL;
482 gpu_memory_buffer_manager_ = NULL; 553 gpu_memory_buffer_manager_ = NULL;
(...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after
931 if (painted_device_scale_factor == painted_device_scale_factor_) 1002 if (painted_device_scale_factor == painted_device_scale_factor_)
932 return; 1003 return;
933 painted_device_scale_factor_ = painted_device_scale_factor; 1004 painted_device_scale_factor_ = painted_device_scale_factor;
934 1005
935 SetNeedsCommit(); 1006 SetNeedsCommit();
936 } 1007 }
937 1008
938 void LayerTreeHost::UpdateTopControlsState(TopControlsState constraints, 1009 void LayerTreeHost::UpdateTopControlsState(TopControlsState constraints,
939 TopControlsState current, 1010 TopControlsState current,
940 bool animate) { 1011 bool animate) {
941 // Top controls are only used in threaded mode. 1012 // Top controls are only used in threaded or remote mode.
942 DCHECK(IsThreaded()); 1013 DCHECK(IsThreaded() || IsRemoteServer());
943 proxy_->UpdateTopControlsState(constraints, current, animate); 1014 proxy_->UpdateTopControlsState(constraints, current, animate);
944 } 1015 }
945 1016
946 void LayerTreeHost::AnimateLayers(base::TimeTicks monotonic_time) { 1017 void LayerTreeHost::AnimateLayers(base::TimeTicks monotonic_time) {
947 if (!settings_.accelerated_animation_enabled) 1018 if (!settings_.accelerated_animation_enabled)
948 return; 1019 return;
949 1020
950 scoped_ptr<AnimationEvents> events; 1021 scoped_ptr<AnimationEvents> events;
951 if (animation_host_) { 1022 if (animation_host_) {
952 events = animation_host_->CreateEvents(); 1023 events = animation_host_->CreateEvents();
(...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after
1286 return animation_host_ ? animation_host_->HasAnyAnimation(layer->id()) 1357 return animation_host_ ? animation_host_->HasAnyAnimation(layer->id())
1287 : false; 1358 : false;
1288 } 1359 }
1289 1360
1290 bool LayerTreeHost::HasActiveAnimation(const Layer* layer) const { 1361 bool LayerTreeHost::HasActiveAnimation(const Layer* layer) const {
1291 return animation_host_ ? animation_host_->HasActiveAnimation(layer->id()) 1362 return animation_host_ ? animation_host_->HasActiveAnimation(layer->id())
1292 : false; 1363 : false;
1293 } 1364 }
1294 1365
1295 bool LayerTreeHost::IsSingleThreaded() const { 1366 bool LayerTreeHost::IsSingleThreaded() const {
1296 DCHECK(compositor_mode_ != CompositorMode::SingleThreaded || 1367 DCHECK(compositor_mode_ != CompositorMode::SINGLE_THREADED ||
1297 !task_runner_provider_->HasImplThread()); 1368 !task_runner_provider_->HasImplThread());
1298 return compositor_mode_ == CompositorMode::SingleThreaded; 1369 return compositor_mode_ == CompositorMode::SINGLE_THREADED;
1299 } 1370 }
1300 1371
1301 bool LayerTreeHost::IsThreaded() const { 1372 bool LayerTreeHost::IsThreaded() const {
1302 DCHECK(compositor_mode_ != CompositorMode::Threaded || 1373 DCHECK(compositor_mode_ != CompositorMode::THREADED ||
1303 task_runner_provider_->HasImplThread()); 1374 task_runner_provider_->HasImplThread());
1304 return compositor_mode_ == CompositorMode::Threaded; 1375 return compositor_mode_ == CompositorMode::THREADED;
1376 }
1377
1378 bool LayerTreeHost::IsRemoteServer() const {
1379 // The LayerTreeHost on the server does not have an impl task runner.
1380 return compositor_mode_ == CompositorMode::REMOTE &&
1381 !task_runner_provider_->HasImplThread();
1382 }
1383
1384 bool LayerTreeHost::IsRemoteClient() const {
1385 return compositor_mode_ == CompositorMode::REMOTE &&
1386 task_runner_provider_->HasImplThread();
1305 } 1387 }
1306 1388
1307 void LayerTreeHost::ToProtobufForCommit(proto::LayerTreeHost* proto) const { 1389 void LayerTreeHost::ToProtobufForCommit(proto::LayerTreeHost* proto) const {
1308 // Not all fields are serialized, as they are eiher not needed for a commit, 1390 // Not all fields are serialized, as they are eiher not needed for a commit,
1309 // or implementation isn't ready yet. 1391 // or implementation isn't ready yet.
1310 // Unsupported items: 1392 // Unsupported items:
1311 // - animations 1393 // - animations
1312 // - UI resources 1394 // - UI resources
1313 // - instrumentation of stats 1395 // - instrumentation of stats
1314 // - histograms 1396 // - histograms
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
1448 LayerTreeHostCommon::CallFunctionForSubtree( 1530 LayerTreeHostCommon::CallFunctionForSubtree(
1449 root_layer(), [seq_num](Layer* layer) { 1531 root_layer(), [seq_num](Layer* layer) {
1450 layer->set_property_tree_sequence_number(seq_num); 1532 layer->set_property_tree_sequence_number(seq_num);
1451 }); 1533 });
1452 1534
1453 surface_id_namespace_ = proto.surface_id_namespace(); 1535 surface_id_namespace_ = proto.surface_id_namespace();
1454 next_surface_sequence_ = proto.next_surface_sequence(); 1536 next_surface_sequence_ = proto.next_surface_sequence();
1455 } 1537 }
1456 1538
1457 } // namespace cc 1539 } // namespace cc
OLDNEW
« no previous file with comments | « cc/trees/layer_tree_host.h ('k') | cc/trees/layer_tree_host_common_perftest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698