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

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: Addressing comments. Created 4 years, 11 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>
(...skipping 28 matching lines...) Expand all
39 #include "cc/layers/layer_settings.h" 39 #include "cc/layers/layer_settings.h"
40 #include "cc/layers/painted_scrollbar_layer.h" 40 #include "cc/layers/painted_scrollbar_layer.h"
41 #include "cc/resources/ui_resource_request.h" 41 #include "cc/resources/ui_resource_request.h"
42 #include "cc/scheduler/begin_frame_source.h" 42 #include "cc/scheduler/begin_frame_source.h"
43 #include "cc/trees/draw_property_utils.h" 43 #include "cc/trees/draw_property_utils.h"
44 #include "cc/trees/layer_tree_host_client.h" 44 #include "cc/trees/layer_tree_host_client.h"
45 #include "cc/trees/layer_tree_host_common.h" 45 #include "cc/trees/layer_tree_host_common.h"
46 #include "cc/trees/layer_tree_host_impl.h" 46 #include "cc/trees/layer_tree_host_impl.h"
47 #include "cc/trees/layer_tree_impl.h" 47 #include "cc/trees/layer_tree_impl.h"
48 #include "cc/trees/proxy_main.h" 48 #include "cc/trees/proxy_main.h"
49 #include "cc/trees/remote_channel_impl.h"
49 #include "cc/trees/single_thread_proxy.h" 50 #include "cc/trees/single_thread_proxy.h"
50 #include "cc/trees/tree_synchronizer.h" 51 #include "cc/trees/tree_synchronizer.h"
51 #include "ui/gfx/geometry/size_conversions.h" 52 #include "ui/gfx/geometry/size_conversions.h"
52 #include "ui/gfx/geometry/vector2d_conversions.h" 53 #include "ui/gfx/geometry/vector2d_conversions.h"
53 54
54 namespace { 55 namespace {
55 static base::StaticAtomicSequenceNumber s_layer_tree_host_sequence_number; 56 static base::StaticAtomicSequenceNumber s_layer_tree_host_sequence_number;
56 } 57 }
57 58
58 namespace cc { 59 namespace cc {
59 60
60 LayerTreeHost::InitParams::InitParams() { 61 LayerTreeHost::InitParams::InitParams() {
61 } 62 }
62 63
63 LayerTreeHost::InitParams::~InitParams() { 64 LayerTreeHost::InitParams::~InitParams() {
64 } 65 }
65 66
66 scoped_ptr<LayerTreeHost> LayerTreeHost::CreateThreaded( 67 scoped_ptr<LayerTreeHost> LayerTreeHost::CreateThreaded(
67 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner, 68 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner,
68 InitParams* params) { 69 InitParams* params) {
69 DCHECK(params->main_task_runner.get()); 70 DCHECK(params->main_task_runner.get());
70 DCHECK(impl_task_runner.get()); 71 DCHECK(impl_task_runner.get());
71 DCHECK(params->settings); 72 DCHECK(params->settings);
72 scoped_ptr<LayerTreeHost> layer_tree_host( 73 scoped_ptr<LayerTreeHost> layer_tree_host(
73 new LayerTreeHost(params, CompositorMode::Threaded)); 74 new LayerTreeHost(params, CompositorMode::THREADED));
74 layer_tree_host->InitializeThreaded( 75 layer_tree_host->InitializeThreaded(
75 params->main_task_runner, impl_task_runner, 76 params->main_task_runner, impl_task_runner,
76 std::move(params->external_begin_frame_source)); 77 std::move(params->external_begin_frame_source));
77 return layer_tree_host; 78 return layer_tree_host;
78 } 79 }
79 80
80 scoped_ptr<LayerTreeHost> LayerTreeHost::CreateSingleThreaded( 81 scoped_ptr<LayerTreeHost> LayerTreeHost::CreateSingleThreaded(
81 LayerTreeHostSingleThreadClient* single_thread_client, 82 LayerTreeHostSingleThreadClient* single_thread_client,
82 InitParams* params) { 83 InitParams* params) {
83 DCHECK(params->settings); 84 DCHECK(params->settings);
84 scoped_ptr<LayerTreeHost> layer_tree_host( 85 scoped_ptr<LayerTreeHost> layer_tree_host(
85 new LayerTreeHost(params, CompositorMode::SingleThreaded)); 86 new LayerTreeHost(params, CompositorMode::SINGLE_THREADED));
86 layer_tree_host->InitializeSingleThreaded( 87 layer_tree_host->InitializeSingleThreaded(
87 single_thread_client, params->main_task_runner, 88 single_thread_client, params->main_task_runner,
88 std::move(params->external_begin_frame_source)); 89 std::move(params->external_begin_frame_source));
89 return layer_tree_host; 90 return layer_tree_host;
90 } 91 }
91 92
93 scoped_ptr<LayerTreeHost> LayerTreeHost::CreateRemoteServer(
94 RemoteProtoChannel* remote_proto_channel,
95 InitParams* params) {
96 DCHECK(params->main_task_runner.get());
97 DCHECK(params->settings);
98 DCHECK(remote_proto_channel);
99
100 // Using an external begin frame source is not supported on the server in
101 // remote mode.
102 DCHECK(!params->settings->use_external_begin_frame_source);
103 DCHECK(!params->external_begin_frame_source);
104
105 scoped_ptr<LayerTreeHost> layer_tree_host(
106 new LayerTreeHost(params, CompositorMode::REMOTE));
107 layer_tree_host->InitializeRemoteServer(remote_proto_channel,
108 params->main_task_runner);
109 return layer_tree_host;
110 }
111
112 scoped_ptr<LayerTreeHost> LayerTreeHost::CreateRemoteClient(
113 RemoteProtoChannel* remote_proto_channel,
114 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner,
115 InitParams* params) {
116 DCHECK(params->main_task_runner.get());
117 DCHECK(params->settings);
118 DCHECK(remote_proto_channel);
119
120 // Using an external begin frame source is not supported in remote mode.
121 // TODO(khushalsagar): Add support for providing an external begin frame
122 // source on the client LayerTreeHost. crbug/576962
123 DCHECK(!params->settings->use_external_begin_frame_source);
124 DCHECK(!params->external_begin_frame_source);
125
126 scoped_ptr<LayerTreeHost> layer_tree_host(
127 new LayerTreeHost(params, CompositorMode::REMOTE));
128 layer_tree_host->InitializeRemoteClient(
129 remote_proto_channel, params->main_task_runner, impl_task_runner);
130 return layer_tree_host;
131 }
132
92 LayerTreeHost::LayerTreeHost(InitParams* params, CompositorMode mode) 133 LayerTreeHost::LayerTreeHost(InitParams* params, CompositorMode mode)
93 : micro_benchmark_controller_(this), 134 : micro_benchmark_controller_(this),
94 next_ui_resource_id_(1), 135 next_ui_resource_id_(1),
95 compositor_mode_(mode), 136 compositor_mode_(mode),
96 needs_full_tree_sync_(true), 137 needs_full_tree_sync_(true),
97 needs_meta_info_recomputation_(true), 138 needs_meta_info_recomputation_(true),
98 client_(params->client), 139 client_(params->client),
99 source_frame_number_(0), 140 source_frame_number_(0),
100 meta_information_sequence_number_(1), 141 meta_information_sequence_number_(1),
101 rendering_stats_instrumentation_(RenderingStatsInstrumentation::Create()), 142 rendering_stats_instrumentation_(RenderingStatsInstrumentation::Create()),
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 void LayerTreeHost::InitializeSingleThreaded( 196 void LayerTreeHost::InitializeSingleThreaded(
156 LayerTreeHostSingleThreadClient* single_thread_client, 197 LayerTreeHostSingleThreadClient* single_thread_client,
157 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, 198 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner,
158 scoped_ptr<BeginFrameSource> external_begin_frame_source) { 199 scoped_ptr<BeginFrameSource> external_begin_frame_source) {
159 task_runner_provider_ = TaskRunnerProvider::Create(main_task_runner, nullptr); 200 task_runner_provider_ = TaskRunnerProvider::Create(main_task_runner, nullptr);
160 InitializeProxy(SingleThreadProxy::Create(this, single_thread_client, 201 InitializeProxy(SingleThreadProxy::Create(this, single_thread_client,
161 task_runner_provider_.get()), 202 task_runner_provider_.get()),
162 std::move(external_begin_frame_source)); 203 std::move(external_begin_frame_source));
163 } 204 }
164 205
206 void LayerTreeHost::InitializeRemoteServer(
207 RemoteProtoChannel* remote_proto_channel,
208 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner) {
209 task_runner_provider_ = TaskRunnerProvider::Create(main_task_runner, nullptr);
210 InitializeProxy(ProxyMain::CreateRemote(remote_proto_channel, this,
211 task_runner_provider_.get()),
212 nullptr);
213 }
214
215 void LayerTreeHost::InitializeRemoteClient(
216 RemoteProtoChannel* remote_proto_channel,
217 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner,
218 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner) {
219 task_runner_provider_ =
220 TaskRunnerProvider::Create(main_task_runner, impl_task_runner);
221
222 // For the remote mode, the RemoteChannelImpl implements the Proxy, which is
223 // owned by the LayerTreeHost. The RemoteChannelImpl pipes requests which need
224 // to handled locally, for instance the Output Surface creation to the
225 // LayerTreeHost on the client, while the other requests are sent to the
226 // RemoteChannelMain on the server which directs them to ProxyMain and the
227 // remote server LayerTreeHost.
228 InitializeProxy(RemoteChannelImpl::Create(this, remote_proto_channel,
229 task_runner_provider_.get()),
230 nullptr);
231 }
232
165 void LayerTreeHost::InitializeForTesting( 233 void LayerTreeHost::InitializeForTesting(
166 scoped_ptr<TaskRunnerProvider> task_runner_provider, 234 scoped_ptr<TaskRunnerProvider> task_runner_provider,
167 scoped_ptr<Proxy> proxy_for_testing, 235 scoped_ptr<Proxy> proxy_for_testing,
168 scoped_ptr<BeginFrameSource> external_begin_frame_source) { 236 scoped_ptr<BeginFrameSource> external_begin_frame_source) {
169 task_runner_provider_ = std::move(task_runner_provider); 237 task_runner_provider_ = std::move(task_runner_provider);
170 InitializeProxy(std::move(proxy_for_testing), 238 InitializeProxy(std::move(proxy_for_testing),
171 std::move(external_begin_frame_source)); 239 std::move(external_begin_frame_source));
172 } 240 }
173 241
174 void LayerTreeHost::SetTaskRunnerProviderForTesting( 242 void LayerTreeHost::SetTaskRunnerProviderForTesting(
175 scoped_ptr<TaskRunnerProvider> task_runner_provider) { 243 scoped_ptr<TaskRunnerProvider> task_runner_provider) {
176 DCHECK(!task_runner_provider_); 244 DCHECK(!task_runner_provider_);
177 task_runner_provider_ = std::move(task_runner_provider); 245 task_runner_provider_ = std::move(task_runner_provider);
178 } 246 }
179 247
180 void LayerTreeHost::InitializeProxy( 248 void LayerTreeHost::InitializeProxy(
181 scoped_ptr<Proxy> proxy, 249 scoped_ptr<Proxy> proxy,
182 scoped_ptr<BeginFrameSource> external_begin_frame_source) { 250 scoped_ptr<BeginFrameSource> external_begin_frame_source) {
183 TRACE_EVENT0("cc", "LayerTreeHost::InitializeForReal"); 251 TRACE_EVENT0("cc", "LayerTreeHost::InitializeForReal");
252 DCHECK(task_runner_provider_);
184 253
185 proxy_ = std::move(proxy); 254 proxy_ = std::move(proxy);
186 proxy_->Start(std::move(external_begin_frame_source)); 255 proxy_->Start(std::move(external_begin_frame_source));
187 if (settings_.accelerated_animation_enabled) { 256 if (settings_.accelerated_animation_enabled) {
188 if (animation_host_) 257 if (animation_host_)
189 animation_host_->SetSupportsScrollAnimations( 258 animation_host_->SetSupportsScrollAnimations(
190 proxy_->SupportsImplScrolling()); 259 proxy_->SupportsImplScrolling());
191 else 260 else
192 animation_registrar_->set_supports_scroll_animations( 261 animation_registrar_->set_supports_scroll_animations(
193 proxy_->SupportsImplScrolling()); 262 proxy_->SupportsImplScrolling());
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 void LayerTreeHost::RequestMainFrameUpdate() { 320 void LayerTreeHost::RequestMainFrameUpdate() {
252 client_->UpdateLayerTreeHost(); 321 client_->UpdateLayerTreeHost();
253 } 322 }
254 323
255 // This function commits the LayerTreeHost to an impl tree. When modifying 324 // This function commits the LayerTreeHost to an impl tree. When modifying
256 // this function, keep in mind that the function *runs* on the impl thread! Any 325 // this function, keep in mind that the function *runs* on the impl thread! Any
257 // code that is logically a main thread operation, e.g. deletion of a Layer, 326 // code that is logically a main thread operation, e.g. deletion of a Layer,
258 // should be delayed until the LayerTreeHost::CommitComplete, which will run 327 // should be delayed until the LayerTreeHost::CommitComplete, which will run
259 // after the commit, but on the main thread. 328 // after the commit, but on the main thread.
260 void LayerTreeHost::FinishCommitOnImplThread(LayerTreeHostImpl* host_impl) { 329 void LayerTreeHost::FinishCommitOnImplThread(LayerTreeHostImpl* host_impl) {
330 DCHECK(!IsRemoteServer());
261 DCHECK(task_runner_provider_->IsImplThread()); 331 DCHECK(task_runner_provider_->IsImplThread());
262 332
263 bool is_new_trace; 333 bool is_new_trace;
264 TRACE_EVENT_IS_NEW_TRACE(&is_new_trace); 334 TRACE_EVENT_IS_NEW_TRACE(&is_new_trace);
265 if (is_new_trace && 335 if (is_new_trace &&
266 frame_viewer_instrumentation::IsTracingLayerTreeSnapshots() && 336 frame_viewer_instrumentation::IsTracingLayerTreeSnapshots() &&
267 root_layer()) { 337 root_layer()) {
268 LayerTreeHostCommon::CallFunctionForSubtree( 338 LayerTreeHostCommon::CallFunctionForSubtree(
269 root_layer(), [](Layer* layer) { layer->DidBeginTracing(); }); 339 root_layer(), [](Layer* layer) { layer->DidBeginTracing(); });
270 } 340 }
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
436 // Note: It is safe to drop all output surface references here as 506 // Note: It is safe to drop all output surface references here as
437 // LayerTreeHostImpl will not keep a pointer to either the old or 507 // LayerTreeHostImpl will not keep a pointer to either the old or
438 // new output surface after failing to initialize the new one. 508 // new output surface after failing to initialize the new one.
439 current_output_surface_ = nullptr; 509 current_output_surface_ = nullptr;
440 new_output_surface_ = nullptr; 510 new_output_surface_ = nullptr;
441 client_->DidFailToInitializeOutputSurface(); 511 client_->DidFailToInitializeOutputSurface();
442 } 512 }
443 513
444 scoped_ptr<LayerTreeHostImpl> LayerTreeHost::CreateLayerTreeHostImpl( 514 scoped_ptr<LayerTreeHostImpl> LayerTreeHost::CreateLayerTreeHostImpl(
445 LayerTreeHostImplClient* client) { 515 LayerTreeHostImplClient* client) {
516 DCHECK(!IsRemoteServer());
446 DCHECK(task_runner_provider_->IsImplThread()); 517 DCHECK(task_runner_provider_->IsImplThread());
447 scoped_ptr<LayerTreeHostImpl> host_impl = LayerTreeHostImpl::Create( 518 scoped_ptr<LayerTreeHostImpl> host_impl = LayerTreeHostImpl::Create(
448 settings_, client, task_runner_provider_.get(), 519 settings_, client, task_runner_provider_.get(),
449 rendering_stats_instrumentation_.get(), shared_bitmap_manager_, 520 rendering_stats_instrumentation_.get(), shared_bitmap_manager_,
450 gpu_memory_buffer_manager_, task_graph_runner_, id_); 521 gpu_memory_buffer_manager_, task_graph_runner_, id_);
451 host_impl->SetHasGpuRasterizationTrigger(has_gpu_rasterization_trigger_); 522 host_impl->SetHasGpuRasterizationTrigger(has_gpu_rasterization_trigger_);
452 host_impl->SetContentIsSuitableForGpuRasterization( 523 host_impl->SetContentIsSuitableForGpuRasterization(
453 content_is_suitable_for_gpu_rasterization_); 524 content_is_suitable_for_gpu_rasterization_);
454 shared_bitmap_manager_ = NULL; 525 shared_bitmap_manager_ = NULL;
455 gpu_memory_buffer_manager_ = NULL; 526 gpu_memory_buffer_manager_ = NULL;
(...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after
905 if (painted_device_scale_factor == painted_device_scale_factor_) 976 if (painted_device_scale_factor == painted_device_scale_factor_)
906 return; 977 return;
907 painted_device_scale_factor_ = painted_device_scale_factor; 978 painted_device_scale_factor_ = painted_device_scale_factor;
908 979
909 SetNeedsCommit(); 980 SetNeedsCommit();
910 } 981 }
911 982
912 void LayerTreeHost::UpdateTopControlsState(TopControlsState constraints, 983 void LayerTreeHost::UpdateTopControlsState(TopControlsState constraints,
913 TopControlsState current, 984 TopControlsState current,
914 bool animate) { 985 bool animate) {
915 // Top controls are only used in threaded mode. 986 // Top controls are only used in threaded or remote mode.
916 DCHECK(IsThreaded()); 987 DCHECK(IsThreaded() || IsRemoteServer());
917 proxy_->UpdateTopControlsState(constraints, current, animate); 988 proxy_->UpdateTopControlsState(constraints, current, animate);
918 } 989 }
919 990
920 void LayerTreeHost::AnimateLayers(base::TimeTicks monotonic_time) { 991 void LayerTreeHost::AnimateLayers(base::TimeTicks monotonic_time) {
921 if (!settings_.accelerated_animation_enabled) 992 if (!settings_.accelerated_animation_enabled)
922 return; 993 return;
923 994
924 AnimationEventsVector events; 995 AnimationEventsVector events;
925 if (animation_host_) { 996 if (animation_host_) {
926 if (animation_host_->AnimateLayers(monotonic_time)) 997 if (animation_host_->AnimateLayers(monotonic_time))
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after
1258 return animation_host_ ? animation_host_->HasAnyAnimation(layer->id()) 1329 return animation_host_ ? animation_host_->HasAnyAnimation(layer->id())
1259 : false; 1330 : false;
1260 } 1331 }
1261 1332
1262 bool LayerTreeHost::HasActiveAnimation(const Layer* layer) const { 1333 bool LayerTreeHost::HasActiveAnimation(const Layer* layer) const {
1263 return animation_host_ ? animation_host_->HasActiveAnimation(layer->id()) 1334 return animation_host_ ? animation_host_->HasActiveAnimation(layer->id())
1264 : false; 1335 : false;
1265 } 1336 }
1266 1337
1267 bool LayerTreeHost::IsSingleThreaded() const { 1338 bool LayerTreeHost::IsSingleThreaded() const {
1268 DCHECK(compositor_mode_ != CompositorMode::SingleThreaded || 1339 DCHECK(compositor_mode_ != CompositorMode::SINGLE_THREADED ||
1269 !task_runner_provider_->HasImplThread()); 1340 !task_runner_provider_->HasImplThread());
1270 return compositor_mode_ == CompositorMode::SingleThreaded; 1341 return compositor_mode_ == CompositorMode::SINGLE_THREADED;
1271 } 1342 }
1272 1343
1273 bool LayerTreeHost::IsThreaded() const { 1344 bool LayerTreeHost::IsThreaded() const {
1274 DCHECK(compositor_mode_ != CompositorMode::Threaded || 1345 DCHECK(compositor_mode_ != CompositorMode::THREADED ||
1275 task_runner_provider_->HasImplThread()); 1346 task_runner_provider_->HasImplThread());
1276 return compositor_mode_ == CompositorMode::Threaded; 1347 return compositor_mode_ == CompositorMode::THREADED;
1348 }
1349
1350 bool LayerTreeHost::IsRemoteServer() const {
1351 // The LayerTreeHost on the server does not have an impl task runner.
1352 return compositor_mode_ == CompositorMode::REMOTE &&
1353 !task_runner_provider_->HasImplThread();
1354 }
1355
1356 bool LayerTreeHost::IsRemoteClient() const {
1357 return compositor_mode_ == CompositorMode::REMOTE &&
1358 task_runner_provider_->HasImplThread();
1277 } 1359 }
1278 1360
1279 } // namespace cc 1361 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698