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

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: Rebase. 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 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 InitParams* params) { 82 InitParams* params) {
83 DCHECK(params->settings); 83 DCHECK(params->settings);
84 scoped_ptr<LayerTreeHost> layer_tree_host( 84 scoped_ptr<LayerTreeHost> layer_tree_host(
85 new LayerTreeHost(params, CompositorMode::SingleThreaded)); 85 new LayerTreeHost(params, CompositorMode::SingleThreaded));
86 layer_tree_host->InitializeSingleThreaded( 86 layer_tree_host->InitializeSingleThreaded(
87 single_thread_client, params->main_task_runner, 87 single_thread_client, params->main_task_runner,
88 std::move(params->external_begin_frame_source)); 88 std::move(params->external_begin_frame_source));
89 return layer_tree_host; 89 return layer_tree_host;
90 } 90 }
91 91
92 scoped_ptr<LayerTreeHost> LayerTreeHost::CreateRemote(
93 RemoteProtoChannel* remote_proto_channel,
94 InitParams* params) {
95 DCHECK(params->main_task_runner.get());
96 DCHECK(params->settings);
97 DCHECK(remote_proto_channel);
98
99 // Using an external begin frame source is not supported in remote mode.
100 DCHECK(!params->settings->use_external_begin_frame_source);
101 DCHECK(!params->external_begin_frame_source);
102
103 scoped_ptr<LayerTreeHost> layer_tree_host(
104 new LayerTreeHost(params, CompositorMode::Remote));
105 layer_tree_host->InitializeRemote(remote_proto_channel,
106 params->main_task_runner);
107 return layer_tree_host;
108 }
109
110 scoped_ptr<LayerTreeHost> LayerTreeHost::CreateDeserializable(
111 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner,
112 InitParams* params) {
113 DCHECK(params->settings);
114
115 scoped_ptr<LayerTreeHost> layer_tree_host(
116 new LayerTreeHost(params, CompositorMode::Deserializable));
117 layer_tree_host->InitializeDeserializable(params->main_task_runner,
118 impl_task_runner);
119 return layer_tree_host;
120 }
121
92 LayerTreeHost::LayerTreeHost(InitParams* params, CompositorMode mode) 122 LayerTreeHost::LayerTreeHost(InitParams* params, CompositorMode mode)
93 : micro_benchmark_controller_(this), 123 : micro_benchmark_controller_(this),
94 next_ui_resource_id_(1), 124 next_ui_resource_id_(1),
95 compositor_mode_(mode), 125 compositor_mode_(mode),
96 needs_full_tree_sync_(true), 126 needs_full_tree_sync_(true),
97 needs_meta_info_recomputation_(true), 127 needs_meta_info_recomputation_(true),
98 client_(params->client), 128 client_(params->client),
99 source_frame_number_(0), 129 source_frame_number_(0),
100 meta_information_sequence_number_(1), 130 meta_information_sequence_number_(1),
101 rendering_stats_instrumentation_(RenderingStatsInstrumentation::Create()), 131 rendering_stats_instrumentation_(RenderingStatsInstrumentation::Create()),
(...skipping 16 matching lines...) Expand all
118 has_transparent_background_(false), 148 has_transparent_background_(false),
119 did_complete_scale_animation_(false), 149 did_complete_scale_animation_(false),
120 in_paint_layer_contents_(false), 150 in_paint_layer_contents_(false),
121 id_(s_layer_tree_host_sequence_number.GetNext() + 1), 151 id_(s_layer_tree_host_sequence_number.GetNext() + 1),
122 next_commit_forces_redraw_(false), 152 next_commit_forces_redraw_(false),
123 shared_bitmap_manager_(params->shared_bitmap_manager), 153 shared_bitmap_manager_(params->shared_bitmap_manager),
124 gpu_memory_buffer_manager_(params->gpu_memory_buffer_manager), 154 gpu_memory_buffer_manager_(params->gpu_memory_buffer_manager),
125 task_graph_runner_(params->task_graph_runner), 155 task_graph_runner_(params->task_graph_runner),
126 surface_id_namespace_(0u), 156 surface_id_namespace_(0u),
127 next_surface_sequence_(1u) { 157 next_surface_sequence_(1u) {
128 DCHECK(task_graph_runner_); 158 if (compositor_mode_ != CompositorMode::Remote)
159 DCHECK(task_graph_runner_);
129 160
130 if (settings_.accelerated_animation_enabled) { 161 if (settings_.accelerated_animation_enabled) {
131 if (settings_.use_compositor_animation_timelines) { 162 if (settings_.use_compositor_animation_timelines) {
132 animation_host_ = AnimationHost::Create(ThreadInstance::MAIN); 163 animation_host_ = AnimationHost::Create(ThreadInstance::MAIN);
133 animation_host_->SetMutatorHostClient(this); 164 animation_host_->SetMutatorHostClient(this);
134 } else { 165 } else {
135 animation_registrar_ = AnimationRegistrar::Create(); 166 animation_registrar_ = AnimationRegistrar::Create();
136 } 167 }
137 } 168 }
138 169
(...skipping 16 matching lines...) Expand all
155 void LayerTreeHost::InitializeSingleThreaded( 186 void LayerTreeHost::InitializeSingleThreaded(
156 LayerTreeHostSingleThreadClient* single_thread_client, 187 LayerTreeHostSingleThreadClient* single_thread_client,
157 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, 188 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner,
158 scoped_ptr<BeginFrameSource> external_begin_frame_source) { 189 scoped_ptr<BeginFrameSource> external_begin_frame_source) {
159 task_runner_provider_ = TaskRunnerProvider::Create(main_task_runner, nullptr); 190 task_runner_provider_ = TaskRunnerProvider::Create(main_task_runner, nullptr);
160 InitializeProxy(SingleThreadProxy::Create(this, single_thread_client, 191 InitializeProxy(SingleThreadProxy::Create(this, single_thread_client,
161 task_runner_provider_.get()), 192 task_runner_provider_.get()),
162 std::move(external_begin_frame_source)); 193 std::move(external_begin_frame_source));
163 } 194 }
164 195
196 void LayerTreeHost::InitializeRemote(
197 RemoteProtoChannel* remote_proto_channel,
198 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner) {
199 task_runner_provider_ = TaskRunnerProvider::Create(main_task_runner, nullptr);
200 InitializeProxy(ProxyMain::CreateRemote(remote_proto_channel, this,
201 task_runner_provider_.get()),
202 nullptr);
203 }
204
205 void LayerTreeHost::InitializeDeserializable(
vmpstr 2016/01/07 19:08:12 I think the rest of the review kind of depends on
Khushal 2016/01/08 21:17:19 Updated this to use the remote mode and the Remote
206 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner,
207 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner) {
208 task_runner_provider_ =
209 TaskRunnerProvider::Create(main_task_runner, impl_task_runner);
210 }
211
165 void LayerTreeHost::InitializeForTesting( 212 void LayerTreeHost::InitializeForTesting(
166 scoped_ptr<TaskRunnerProvider> task_runner_provider, 213 scoped_ptr<TaskRunnerProvider> task_runner_provider,
167 scoped_ptr<Proxy> proxy_for_testing, 214 scoped_ptr<Proxy> proxy_for_testing,
168 scoped_ptr<BeginFrameSource> external_begin_frame_source) { 215 scoped_ptr<BeginFrameSource> external_begin_frame_source) {
169 task_runner_provider_ = std::move(task_runner_provider); 216 task_runner_provider_ = std::move(task_runner_provider);
170 InitializeProxy(std::move(proxy_for_testing), 217 InitializeProxy(std::move(proxy_for_testing),
171 std::move(external_begin_frame_source)); 218 std::move(external_begin_frame_source));
172 } 219 }
173 220
174 void LayerTreeHost::SetTaskRunnerProviderForTesting( 221 void LayerTreeHost::SetTaskRunnerProviderForTesting(
175 scoped_ptr<TaskRunnerProvider> task_runner_provider) { 222 scoped_ptr<TaskRunnerProvider> task_runner_provider) {
176 DCHECK(!task_runner_provider_); 223 DCHECK(!task_runner_provider_);
177 task_runner_provider_ = std::move(task_runner_provider); 224 task_runner_provider_ = std::move(task_runner_provider);
178 } 225 }
179 226
180 void LayerTreeHost::InitializeProxy( 227 void LayerTreeHost::InitializeProxy(
181 scoped_ptr<Proxy> proxy, 228 scoped_ptr<Proxy> proxy,
182 scoped_ptr<BeginFrameSource> external_begin_frame_source) { 229 scoped_ptr<BeginFrameSource> external_begin_frame_source) {
183 TRACE_EVENT0("cc", "LayerTreeHost::InitializeForReal"); 230 TRACE_EVENT0("cc", "LayerTreeHost::InitializeForReal");
231 DCHECK(task_runner_provider_);
184 232
185 proxy_ = std::move(proxy); 233 proxy_ = std::move(proxy);
186 proxy_->Start(std::move(external_begin_frame_source)); 234 proxy_->Start(std::move(external_begin_frame_source));
187 if (settings_.accelerated_animation_enabled) { 235 if (settings_.accelerated_animation_enabled) {
188 if (animation_host_) 236 if (animation_host_)
189 animation_host_->SetSupportsScrollAnimations( 237 animation_host_->SetSupportsScrollAnimations(
190 proxy_->SupportsImplScrolling()); 238 proxy_->SupportsImplScrolling());
191 else 239 else
192 animation_registrar_->set_supports_scroll_animations( 240 animation_registrar_->set_supports_scroll_animations(
193 proxy_->SupportsImplScrolling()); 241 proxy_->SupportsImplScrolling());
(...skipping 25 matching lines...) Expand all
219 RegisterViewportLayers(NULL, NULL, NULL, NULL); 267 RegisterViewportLayers(NULL, NULL, NULL, NULL);
220 268
221 if (root_layer_.get()) { 269 if (root_layer_.get()) {
222 // The layer tree must be destroyed before the layer tree host. We've 270 // The layer tree must be destroyed before the layer tree host. We've
223 // made a contract with our animation controllers that the registrar 271 // made a contract with our animation controllers that the registrar
224 // will outlive them, and we must make good. 272 // will outlive them, and we must make good.
225 root_layer_ = NULL; 273 root_layer_ = NULL;
226 } 274 }
227 } 275 }
228 276
277 void LayerTreeHost::ToProtobuf() {
278 DCHECK(task_runner_provider_->IsMainThread());
279 DCHECK(IsRemote());
280
281 // TODO(khushalsagar, nyquist): Serialize LayerTreeHost state to proto.
282 }
283
284 void LayerTreeHost::FromProtobuf() {
285 DCHECK(task_runner_provider_->IsMainThread());
286 DCHECK(IsDeserializable());
287
288 // TODO(khushalsagar, nyquist): Deserialize LayerTreeHost state from proto.
289 }
290
229 void LayerTreeHost::WillBeginMainFrame() { 291 void LayerTreeHost::WillBeginMainFrame() {
230 devtools_instrumentation::WillBeginMainThreadFrame(id(), 292 devtools_instrumentation::WillBeginMainThreadFrame(id(),
231 source_frame_number()); 293 source_frame_number());
232 client_->WillBeginMainFrame(); 294 client_->WillBeginMainFrame();
233 } 295 }
234 296
235 void LayerTreeHost::DidBeginMainFrame() { 297 void LayerTreeHost::DidBeginMainFrame() {
236 client_->DidBeginMainFrame(); 298 client_->DidBeginMainFrame();
237 } 299 }
238 300
(...skipping 12 matching lines...) Expand all
251 void LayerTreeHost::RequestMainFrameUpdate() { 313 void LayerTreeHost::RequestMainFrameUpdate() {
252 client_->UpdateLayerTreeHost(); 314 client_->UpdateLayerTreeHost();
253 } 315 }
254 316
255 // This function commits the LayerTreeHost to an impl tree. When modifying 317 // 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 318 // 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, 319 // 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 320 // should be delayed until the LayerTreeHost::CommitComplete, which will run
259 // after the commit, but on the main thread. 321 // after the commit, but on the main thread.
260 void LayerTreeHost::FinishCommitOnImplThread(LayerTreeHostImpl* host_impl) { 322 void LayerTreeHost::FinishCommitOnImplThread(LayerTreeHostImpl* host_impl) {
323 DCHECK(!IsRemote());
261 DCHECK(task_runner_provider_->IsImplThread()); 324 DCHECK(task_runner_provider_->IsImplThread());
262 325
263 bool is_new_trace; 326 bool is_new_trace;
264 TRACE_EVENT_IS_NEW_TRACE(&is_new_trace); 327 TRACE_EVENT_IS_NEW_TRACE(&is_new_trace);
265 if (is_new_trace && 328 if (is_new_trace &&
266 frame_viewer_instrumentation::IsTracingLayerTreeSnapshots() && 329 frame_viewer_instrumentation::IsTracingLayerTreeSnapshots() &&
267 root_layer()) { 330 root_layer()) {
268 LayerTreeHostCommon::CallFunctionForSubtree( 331 LayerTreeHostCommon::CallFunctionForSubtree(
269 root_layer(), [](Layer* layer) { layer->DidBeginTracing(); }); 332 root_layer(), [](Layer* layer) { layer->DidBeginTracing(); });
270 } 333 }
(...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 499 // Note: It is safe to drop all output surface references here as
437 // LayerTreeHostImpl will not keep a pointer to either the old or 500 // LayerTreeHostImpl will not keep a pointer to either the old or
438 // new output surface after failing to initialize the new one. 501 // new output surface after failing to initialize the new one.
439 current_output_surface_ = nullptr; 502 current_output_surface_ = nullptr;
440 new_output_surface_ = nullptr; 503 new_output_surface_ = nullptr;
441 client_->DidFailToInitializeOutputSurface(); 504 client_->DidFailToInitializeOutputSurface();
442 } 505 }
443 506
444 scoped_ptr<LayerTreeHostImpl> LayerTreeHost::CreateLayerTreeHostImpl( 507 scoped_ptr<LayerTreeHostImpl> LayerTreeHost::CreateLayerTreeHostImpl(
445 LayerTreeHostImplClient* client) { 508 LayerTreeHostImplClient* client) {
509 DCHECK(!IsRemote());
446 DCHECK(task_runner_provider_->IsImplThread()); 510 DCHECK(task_runner_provider_->IsImplThread());
447 scoped_ptr<LayerTreeHostImpl> host_impl = LayerTreeHostImpl::Create( 511 scoped_ptr<LayerTreeHostImpl> host_impl = LayerTreeHostImpl::Create(
448 settings_, client, task_runner_provider_.get(), 512 settings_, client, task_runner_provider_.get(),
449 rendering_stats_instrumentation_.get(), shared_bitmap_manager_, 513 rendering_stats_instrumentation_.get(), shared_bitmap_manager_,
450 gpu_memory_buffer_manager_, task_graph_runner_, id_); 514 gpu_memory_buffer_manager_, task_graph_runner_, id_);
451 host_impl->SetHasGpuRasterizationTrigger(has_gpu_rasterization_trigger_); 515 host_impl->SetHasGpuRasterizationTrigger(has_gpu_rasterization_trigger_);
452 host_impl->SetContentIsSuitableForGpuRasterization( 516 host_impl->SetContentIsSuitableForGpuRasterization(
453 content_is_suitable_for_gpu_rasterization_); 517 content_is_suitable_for_gpu_rasterization_);
454 shared_bitmap_manager_ = NULL; 518 shared_bitmap_manager_ = NULL;
455 gpu_memory_buffer_manager_ = NULL; 519 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_) 969 if (painted_device_scale_factor == painted_device_scale_factor_)
906 return; 970 return;
907 painted_device_scale_factor_ = painted_device_scale_factor; 971 painted_device_scale_factor_ = painted_device_scale_factor;
908 972
909 SetNeedsCommit(); 973 SetNeedsCommit();
910 } 974 }
911 975
912 void LayerTreeHost::UpdateTopControlsState(TopControlsState constraints, 976 void LayerTreeHost::UpdateTopControlsState(TopControlsState constraints,
913 TopControlsState current, 977 TopControlsState current,
914 bool animate) { 978 bool animate) {
915 // Top controls are only used in threaded mode. 979 // Top controls are only used in threaded or remote mode.
916 DCHECK(IsThreaded()); 980 DCHECK(IsThreaded() || IsRemote());
917 proxy_->UpdateTopControlsState(constraints, current, animate); 981 proxy_->UpdateTopControlsState(constraints, current, animate);
918 } 982 }
919 983
920 void LayerTreeHost::AnimateLayers(base::TimeTicks monotonic_time) { 984 void LayerTreeHost::AnimateLayers(base::TimeTicks monotonic_time) {
921 if (!settings_.accelerated_animation_enabled) 985 if (!settings_.accelerated_animation_enabled)
922 return; 986 return;
923 987
924 AnimationEventsVector events; 988 AnimationEventsVector events;
925 if (animation_host_) { 989 if (animation_host_) {
926 if (animation_host_->AnimateLayers(monotonic_time)) 990 if (animation_host_->AnimateLayers(monotonic_time))
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after
1269 !task_runner_provider_->HasImplThread()); 1333 !task_runner_provider_->HasImplThread());
1270 return compositor_mode_ == CompositorMode::SingleThreaded; 1334 return compositor_mode_ == CompositorMode::SingleThreaded;
1271 } 1335 }
1272 1336
1273 bool LayerTreeHost::IsThreaded() const { 1337 bool LayerTreeHost::IsThreaded() const {
1274 DCHECK(compositor_mode_ != CompositorMode::Threaded || 1338 DCHECK(compositor_mode_ != CompositorMode::Threaded ||
1275 task_runner_provider_->HasImplThread()); 1339 task_runner_provider_->HasImplThread());
1276 return compositor_mode_ == CompositorMode::Threaded; 1340 return compositor_mode_ == CompositorMode::Threaded;
1277 } 1341 }
1278 1342
1343 bool LayerTreeHost::IsRemote() const {
1344 DCHECK(compositor_mode_ != CompositorMode::Remote ||
1345 !task_runner_provider_->HasImplThread());
1346 return compositor_mode_ == CompositorMode::Remote;
1347 }
1348
1349 bool LayerTreeHost::IsDeserializable() const {
1350 DCHECK(compositor_mode_ != CompositorMode::Deserializable ||
1351 task_runner_provider_->HasImplThread());
1352 return compositor_mode_ == CompositorMode::Deserializable;
1353 }
1354
1279 } // namespace cc 1355 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698