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

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: Use LayerTreeSettings::ToProtobuf, update comments. Created 5 years 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 <algorithm> 7 #include <algorithm>
8 #include <stack> 8 #include <stack>
9 #include <string> 9 #include <string>
10 10
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 InitParams* params) { 79 InitParams* params) {
80 DCHECK(params->settings); 80 DCHECK(params->settings);
81 scoped_ptr<LayerTreeHost> layer_tree_host( 81 scoped_ptr<LayerTreeHost> layer_tree_host(
82 new LayerTreeHost(params, CompositorMode::SingleThreaded)); 82 new LayerTreeHost(params, CompositorMode::SingleThreaded));
83 layer_tree_host->InitializeSingleThreaded( 83 layer_tree_host->InitializeSingleThreaded(
84 single_thread_client, params->main_task_runner, 84 single_thread_client, params->main_task_runner,
85 std::move(params->external_begin_frame_source)); 85 std::move(params->external_begin_frame_source));
86 return layer_tree_host; 86 return layer_tree_host;
87 } 87 }
88 88
89 scoped_ptr<LayerTreeHost> LayerTreeHost::CreateRemote(
90 RemoteProtoChannel* remote_proto_channel,
91 InitParams* params) {
92 DCHECK(params->main_task_runner.get());
93 DCHECK(params->settings);
94 DCHECK(remote_proto_channel);
95
96 // Using an external begin frame source is not supported in remote mode.
97 DCHECK(!params->settings->use_external_begin_frame_source);
98 DCHECK(!params->external_begin_frame_source);
99
100 scoped_ptr<LayerTreeHost> layer_tree_host(
101 new LayerTreeHost(params, CompositorMode::Remote));
102 layer_tree_host->InitializeRemote(remote_proto_channel,
103 params->main_task_runner);
104 return layer_tree_host;
105 }
106
107 scoped_ptr<LayerTreeHost> LayerTreeHost::CreateDeserializable(
108 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner,
109 InitParams* params) {
110 DCHECK(params->settings);
111
112 scoped_ptr<LayerTreeHost> layer_tree_host(
113 new LayerTreeHost(params, CompositorMode::Deserializable));
114 layer_tree_host->InitializeDeserializable(params->main_task_runner,
115 impl_task_runner);
116 return layer_tree_host;
117 }
118
89 LayerTreeHost::LayerTreeHost(InitParams* params, CompositorMode mode) 119 LayerTreeHost::LayerTreeHost(InitParams* params, CompositorMode mode)
90 : micro_benchmark_controller_(this), 120 : micro_benchmark_controller_(this),
91 next_ui_resource_id_(1), 121 next_ui_resource_id_(1),
92 compositor_mode_(mode), 122 compositor_mode_(mode),
93 needs_full_tree_sync_(true), 123 needs_full_tree_sync_(true),
94 needs_meta_info_recomputation_(true), 124 needs_meta_info_recomputation_(true),
95 client_(params->client), 125 client_(params->client),
96 source_frame_number_(0), 126 source_frame_number_(0),
97 meta_information_sequence_number_(1), 127 meta_information_sequence_number_(1),
98 rendering_stats_instrumentation_(RenderingStatsInstrumentation::Create()), 128 rendering_stats_instrumentation_(RenderingStatsInstrumentation::Create()),
(...skipping 16 matching lines...) Expand all
115 has_transparent_background_(false), 145 has_transparent_background_(false),
116 did_complete_scale_animation_(false), 146 did_complete_scale_animation_(false),
117 in_paint_layer_contents_(false), 147 in_paint_layer_contents_(false),
118 id_(s_layer_tree_host_sequence_number.GetNext() + 1), 148 id_(s_layer_tree_host_sequence_number.GetNext() + 1),
119 next_commit_forces_redraw_(false), 149 next_commit_forces_redraw_(false),
120 shared_bitmap_manager_(params->shared_bitmap_manager), 150 shared_bitmap_manager_(params->shared_bitmap_manager),
121 gpu_memory_buffer_manager_(params->gpu_memory_buffer_manager), 151 gpu_memory_buffer_manager_(params->gpu_memory_buffer_manager),
122 task_graph_runner_(params->task_graph_runner), 152 task_graph_runner_(params->task_graph_runner),
123 surface_id_namespace_(0u), 153 surface_id_namespace_(0u),
124 next_surface_sequence_(1u) { 154 next_surface_sequence_(1u) {
125 DCHECK(task_graph_runner_); 155 if (compositor_mode_ != CompositorMode::Remote)
156 DCHECK(task_graph_runner_);
126 157
127 if (settings_.accelerated_animation_enabled) { 158 if (settings_.accelerated_animation_enabled) {
128 if (settings_.use_compositor_animation_timelines) { 159 if (settings_.use_compositor_animation_timelines) {
129 animation_host_ = AnimationHost::Create(ThreadInstance::MAIN); 160 animation_host_ = AnimationHost::Create(ThreadInstance::MAIN);
130 animation_host_->SetMutatorHostClient(this); 161 animation_host_->SetMutatorHostClient(this);
131 } else { 162 } else {
132 animation_registrar_ = AnimationRegistrar::Create(); 163 animation_registrar_ = AnimationRegistrar::Create();
133 } 164 }
134 } 165 }
135 166
136 rendering_stats_instrumentation_->set_record_rendering_stats( 167 rendering_stats_instrumentation_->set_record_rendering_stats(
137 debug_state_.RecordRenderingStats()); 168 debug_state_.RecordRenderingStats());
138 } 169 }
139 170
140 void LayerTreeHost::InitializeThreaded( 171 void LayerTreeHost::InitializeThreaded(
141 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, 172 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner,
142 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner, 173 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner,
143 scoped_ptr<BeginFrameSource> external_begin_frame_source) { 174 scoped_ptr<BeginFrameSource> external_begin_frame_source) {
144 task_runner_provider_ = 175 task_runner_provider_ =
145 TaskRunnerProvider::Create(main_task_runner, impl_task_runner); 176 TaskRunnerProvider::Create(main_task_runner, impl_task_runner);
146 scoped_ptr<ProxyMain> proxy_main = 177 InitializeProxy(
147 ProxyMain::CreateThreaded(this, task_runner_provider_.get(), 178 ProxyMain::CreateThreaded(this, task_runner_provider_.get(),
148 std::move(external_begin_frame_source)); 179 std::move(external_begin_frame_source)));
149 InitializeProxy(std::move(proxy_main));
150 } 180 }
151 181
152 void LayerTreeHost::InitializeSingleThreaded( 182 void LayerTreeHost::InitializeSingleThreaded(
153 LayerTreeHostSingleThreadClient* single_thread_client, 183 LayerTreeHostSingleThreadClient* single_thread_client,
154 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, 184 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner,
155 scoped_ptr<BeginFrameSource> external_begin_frame_source) { 185 scoped_ptr<BeginFrameSource> external_begin_frame_source) {
156 task_runner_provider_ = TaskRunnerProvider::Create(main_task_runner, nullptr); 186 task_runner_provider_ = TaskRunnerProvider::Create(main_task_runner, nullptr);
157 InitializeProxy(SingleThreadProxy::Create( 187 InitializeProxy(SingleThreadProxy::Create(
158 this, single_thread_client, task_runner_provider_.get(), 188 this, single_thread_client, task_runner_provider_.get(),
159 std::move(external_begin_frame_source))); 189 std::move(external_begin_frame_source)));
160 } 190 }
161 191
192 void LayerTreeHost::InitializeRemote(
193 RemoteProtoChannel* remote_proto_channel,
194 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner) {
195 task_runner_provider_ = TaskRunnerProvider::Create(main_task_runner, nullptr);
196 InitializeProxy(ProxyMain::CreateRemote(remote_proto_channel, this,
197 task_runner_provider_.get()));
198 }
199
200 void LayerTreeHost::InitializeDeserializable(
201 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner,
202 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner) {
203 task_runner_provider_ =
204 TaskRunnerProvider::Create(main_task_runner, impl_task_runner);
205 }
206
162 void LayerTreeHost::InitializeForTesting( 207 void LayerTreeHost::InitializeForTesting(
163 scoped_ptr<TaskRunnerProvider> task_runner_provider, 208 scoped_ptr<TaskRunnerProvider> task_runner_provider,
164 scoped_ptr<Proxy> proxy_for_testing) { 209 scoped_ptr<Proxy> proxy_for_testing) {
165 task_runner_provider_ = std::move(task_runner_provider); 210 task_runner_provider_ = std::move(task_runner_provider);
166 InitializeProxy(std::move(proxy_for_testing)); 211 InitializeProxy(std::move(proxy_for_testing));
167 } 212 }
168 213
169 void LayerTreeHost::SetTaskRunnerProviderForTesting( 214 void LayerTreeHost::SetTaskRunnerProviderForTesting(
170 scoped_ptr<TaskRunnerProvider> task_runner_provider) { 215 scoped_ptr<TaskRunnerProvider> task_runner_provider) {
171 DCHECK(!task_runner_provider_); 216 DCHECK(!task_runner_provider_);
172 task_runner_provider_ = std::move(task_runner_provider); 217 task_runner_provider_ = std::move(task_runner_provider);
173 } 218 }
174 219
175 void LayerTreeHost::InitializeProxy(scoped_ptr<Proxy> proxy) { 220 void LayerTreeHost::InitializeProxy(scoped_ptr<Proxy> proxy) {
176 TRACE_EVENT0("cc", "LayerTreeHost::InitializeForReal"); 221 TRACE_EVENT0("cc", "LayerTreeHost::InitializeForReal");
222 DCHECK(task_runner_provider_);
177 223
178 proxy_ = std::move(proxy); 224 proxy_ = std::move(proxy);
179 proxy_->Start(); 225 proxy_->Start();
180 if (settings_.accelerated_animation_enabled) { 226 if (settings_.accelerated_animation_enabled) {
181 if (animation_host_) 227 if (animation_host_)
182 animation_host_->SetSupportsScrollAnimations( 228 animation_host_->SetSupportsScrollAnimations(
183 proxy_->SupportsImplScrolling()); 229 proxy_->SupportsImplScrolling());
184 else 230 else
185 animation_registrar_->set_supports_scroll_animations( 231 animation_registrar_->set_supports_scroll_animations(
186 proxy_->SupportsImplScrolling()); 232 proxy_->SupportsImplScrolling());
(...skipping 25 matching lines...) Expand all
212 RegisterViewportLayers(NULL, NULL, NULL, NULL); 258 RegisterViewportLayers(NULL, NULL, NULL, NULL);
213 259
214 if (root_layer_.get()) { 260 if (root_layer_.get()) {
215 // The layer tree must be destroyed before the layer tree host. We've 261 // The layer tree must be destroyed before the layer tree host. We've
216 // made a contract with our animation controllers that the registrar 262 // made a contract with our animation controllers that the registrar
217 // will outlive them, and we must make good. 263 // will outlive them, and we must make good.
218 root_layer_ = NULL; 264 root_layer_ = NULL;
219 } 265 }
220 } 266 }
221 267
268 void LayerTreeHost::ToProtobuf() {
David Trainor- moved to gerrit 2015/12/15 00:52:14 Add todo to implement?
Khushal 2015/12/15 05:05:30 Done.
269 DCHECK(task_runner_provider_->IsMainThread());
270 DCHECK(IsRemote());
271 }
272
273 void LayerTreeHost::FromProtobuf() {
274 DCHECK(task_runner_provider_->IsMainThread());
275 DCHECK(IsDeserializable());
276 }
277
222 void LayerTreeHost::WillBeginMainFrame() { 278 void LayerTreeHost::WillBeginMainFrame() {
223 devtools_instrumentation::WillBeginMainThreadFrame(id(), 279 devtools_instrumentation::WillBeginMainThreadFrame(id(),
224 source_frame_number()); 280 source_frame_number());
225 client_->WillBeginMainFrame(); 281 client_->WillBeginMainFrame();
226 } 282 }
227 283
228 void LayerTreeHost::DidBeginMainFrame() { 284 void LayerTreeHost::DidBeginMainFrame() {
229 client_->DidBeginMainFrame(); 285 client_->DidBeginMainFrame();
230 } 286 }
231 287
(...skipping 12 matching lines...) Expand all
244 void LayerTreeHost::RequestMainFrameUpdate() { 300 void LayerTreeHost::RequestMainFrameUpdate() {
245 client_->UpdateLayerTreeHost(); 301 client_->UpdateLayerTreeHost();
246 } 302 }
247 303
248 // This function commits the LayerTreeHost to an impl tree. When modifying 304 // This function commits the LayerTreeHost to an impl tree. When modifying
249 // this function, keep in mind that the function *runs* on the impl thread! Any 305 // this function, keep in mind that the function *runs* on the impl thread! Any
250 // code that is logically a main thread operation, e.g. deletion of a Layer, 306 // code that is logically a main thread operation, e.g. deletion of a Layer,
251 // should be delayed until the LayerTreeHost::CommitComplete, which will run 307 // should be delayed until the LayerTreeHost::CommitComplete, which will run
252 // after the commit, but on the main thread. 308 // after the commit, but on the main thread.
253 void LayerTreeHost::FinishCommitOnImplThread(LayerTreeHostImpl* host_impl) { 309 void LayerTreeHost::FinishCommitOnImplThread(LayerTreeHostImpl* host_impl) {
310 DCHECK(!IsRemote());
254 DCHECK(task_runner_provider_->IsImplThread()); 311 DCHECK(task_runner_provider_->IsImplThread());
255 312
256 bool is_new_trace; 313 bool is_new_trace;
257 TRACE_EVENT_IS_NEW_TRACE(&is_new_trace); 314 TRACE_EVENT_IS_NEW_TRACE(&is_new_trace);
258 if (is_new_trace && 315 if (is_new_trace &&
259 frame_viewer_instrumentation::IsTracingLayerTreeSnapshots() && 316 frame_viewer_instrumentation::IsTracingLayerTreeSnapshots() &&
260 root_layer()) { 317 root_layer()) {
261 LayerTreeHostCommon::CallFunctionForSubtree( 318 LayerTreeHostCommon::CallFunctionForSubtree(
262 root_layer(), [](Layer* layer) { layer->DidBeginTracing(); }); 319 root_layer(), [](Layer* layer) { layer->DidBeginTracing(); });
263 } 320 }
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
429 // Note: It is safe to drop all output surface references here as 486 // Note: It is safe to drop all output surface references here as
430 // LayerTreeHostImpl will not keep a pointer to either the old or 487 // LayerTreeHostImpl will not keep a pointer to either the old or
431 // new output surface after failing to initialize the new one. 488 // new output surface after failing to initialize the new one.
432 current_output_surface_ = nullptr; 489 current_output_surface_ = nullptr;
433 new_output_surface_ = nullptr; 490 new_output_surface_ = nullptr;
434 client_->DidFailToInitializeOutputSurface(); 491 client_->DidFailToInitializeOutputSurface();
435 } 492 }
436 493
437 scoped_ptr<LayerTreeHostImpl> LayerTreeHost::CreateLayerTreeHostImpl( 494 scoped_ptr<LayerTreeHostImpl> LayerTreeHost::CreateLayerTreeHostImpl(
438 LayerTreeHostImplClient* client) { 495 LayerTreeHostImplClient* client) {
496 DCHECK(!IsRemote());
439 DCHECK(task_runner_provider_->IsImplThread()); 497 DCHECK(task_runner_provider_->IsImplThread());
440 scoped_ptr<LayerTreeHostImpl> host_impl = LayerTreeHostImpl::Create( 498 scoped_ptr<LayerTreeHostImpl> host_impl = LayerTreeHostImpl::Create(
441 settings_, client, task_runner_provider_.get(), 499 settings_, client, task_runner_provider_.get(),
442 rendering_stats_instrumentation_.get(), shared_bitmap_manager_, 500 rendering_stats_instrumentation_.get(), shared_bitmap_manager_,
443 gpu_memory_buffer_manager_, task_graph_runner_, id_); 501 gpu_memory_buffer_manager_, task_graph_runner_, id_);
444 host_impl->SetHasGpuRasterizationTrigger(has_gpu_rasterization_trigger_); 502 host_impl->SetHasGpuRasterizationTrigger(has_gpu_rasterization_trigger_);
445 host_impl->SetContentIsSuitableForGpuRasterization( 503 host_impl->SetContentIsSuitableForGpuRasterization(
446 content_is_suitable_for_gpu_rasterization_); 504 content_is_suitable_for_gpu_rasterization_);
447 shared_bitmap_manager_ = NULL; 505 shared_bitmap_manager_ = NULL;
448 gpu_memory_buffer_manager_ = NULL; 506 gpu_memory_buffer_manager_ = NULL;
(...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after
898 if (painted_device_scale_factor == painted_device_scale_factor_) 956 if (painted_device_scale_factor == painted_device_scale_factor_)
899 return; 957 return;
900 painted_device_scale_factor_ = painted_device_scale_factor; 958 painted_device_scale_factor_ = painted_device_scale_factor;
901 959
902 SetNeedsCommit(); 960 SetNeedsCommit();
903 } 961 }
904 962
905 void LayerTreeHost::UpdateTopControlsState(TopControlsState constraints, 963 void LayerTreeHost::UpdateTopControlsState(TopControlsState constraints,
906 TopControlsState current, 964 TopControlsState current,
907 bool animate) { 965 bool animate) {
908 // Top controls are only used in threaded mode. 966 // Top controls are only used in threaded or remote mode.
909 DCHECK(IsThreaded()); 967 DCHECK(IsThreaded() || IsRemote());
910 proxy_->UpdateTopControlsState(constraints, current, animate); 968 proxy_->UpdateTopControlsState(constraints, current, animate);
911 } 969 }
912 970
913 void LayerTreeHost::AnimateLayers(base::TimeTicks monotonic_time) { 971 void LayerTreeHost::AnimateLayers(base::TimeTicks monotonic_time) {
914 if (!settings_.accelerated_animation_enabled) 972 if (!settings_.accelerated_animation_enabled)
915 return; 973 return;
916 974
917 AnimationEventsVector events; 975 AnimationEventsVector events;
918 if (animation_host_) { 976 if (animation_host_) {
919 if (animation_host_->AnimateLayers(monotonic_time)) 977 if (animation_host_->AnimateLayers(monotonic_time))
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after
1262 !task_runner_provider_->HasImplThread()); 1320 !task_runner_provider_->HasImplThread());
1263 return compositor_mode_ == CompositorMode::SingleThreaded; 1321 return compositor_mode_ == CompositorMode::SingleThreaded;
1264 } 1322 }
1265 1323
1266 bool LayerTreeHost::IsThreaded() const { 1324 bool LayerTreeHost::IsThreaded() const {
1267 DCHECK(compositor_mode_ != CompositorMode::Threaded || 1325 DCHECK(compositor_mode_ != CompositorMode::Threaded ||
1268 task_runner_provider_->HasImplThread()); 1326 task_runner_provider_->HasImplThread());
1269 return compositor_mode_ == CompositorMode::Threaded; 1327 return compositor_mode_ == CompositorMode::Threaded;
1270 } 1328 }
1271 1329
1330 bool LayerTreeHost::IsRemote() const {
1331 DCHECK(compositor_mode_ != CompositorMode::Remote ||
1332 !task_runner_provider_->HasImplThread());
1333 return compositor_mode_ == CompositorMode::Remote;
1334 }
1335
1336 bool LayerTreeHost::IsDeserializable() const {
1337 DCHECK(compositor_mode_ != CompositorMode::Deserializable ||
1338 task_runner_provider_->HasImplThread());
1339 return compositor_mode_ == CompositorMode::Deserializable;
1340 }
1341
1272 } // namespace cc 1342 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698