Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 { |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 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::SingleThreaded)); |
| 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 in remote mode. | |
|
vmpstr
2016/01/11 21:50:15
... in remote server mode.
Khushal
2016/01/13 02:07:12
Done.
| |
| 101 DCHECK(!params->settings->use_external_begin_frame_source); | |
| 102 DCHECK(!params->external_begin_frame_source); | |
| 103 | |
| 104 scoped_ptr<LayerTreeHost> layer_tree_host( | |
| 105 new LayerTreeHost(params, CompositorMode::Remote)); | |
| 106 layer_tree_host->InitializeRemoteServer(remote_proto_channel, | |
| 107 params->main_task_runner); | |
| 108 return layer_tree_host; | |
| 109 } | |
| 110 | |
| 111 scoped_ptr<LayerTreeHost> LayerTreeHost::CreateRemoteClient( | |
| 112 RemoteProtoChannel* remote_proto_channel, | |
| 113 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner, | |
| 114 InitParams* params) { | |
| 115 DCHECK(params->main_task_runner.get()); | |
| 116 DCHECK(params->settings); | |
| 117 DCHECK(remote_proto_channel); | |
| 118 | |
| 119 // Using an external begin frame source is not supported in remote mode. | |
| 120 // TODO(khushalsagar): Add support for providing an external begin frame | |
|
vmpstr
2016/01/11 21:50:15
File a bug for this and reference it in here, plea
Khushal
2016/01/13 02:07:12
Done.
| |
| 121 // source on the client LayerTreeHost. | |
| 122 DCHECK(!params->settings->use_external_begin_frame_source); | |
| 123 DCHECK(!params->external_begin_frame_source); | |
| 124 | |
| 125 scoped_ptr<LayerTreeHost> layer_tree_host( | |
| 126 new LayerTreeHost(params, CompositorMode::Remote)); | |
| 127 layer_tree_host->InitializeRemoteClient( | |
| 128 remote_proto_channel, params->main_task_runner, impl_task_runner); | |
| 129 return layer_tree_host; | |
| 130 } | |
| 131 | |
| 92 LayerTreeHost::LayerTreeHost(InitParams* params, CompositorMode mode) | 132 LayerTreeHost::LayerTreeHost(InitParams* params, CompositorMode mode) |
| 93 : micro_benchmark_controller_(this), | 133 : micro_benchmark_controller_(this), |
| 94 next_ui_resource_id_(1), | 134 next_ui_resource_id_(1), |
| 95 compositor_mode_(mode), | 135 compositor_mode_(mode), |
| 96 needs_full_tree_sync_(true), | 136 needs_full_tree_sync_(true), |
| 97 needs_meta_info_recomputation_(true), | 137 needs_meta_info_recomputation_(true), |
| 98 client_(params->client), | 138 client_(params->client), |
| 99 source_frame_number_(0), | 139 source_frame_number_(0), |
| 100 meta_information_sequence_number_(1), | 140 meta_information_sequence_number_(1), |
| 101 rendering_stats_instrumentation_(RenderingStatsInstrumentation::Create()), | 141 rendering_stats_instrumentation_(RenderingStatsInstrumentation::Create()), |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 155 void LayerTreeHost::InitializeSingleThreaded( | 195 void LayerTreeHost::InitializeSingleThreaded( |
| 156 LayerTreeHostSingleThreadClient* single_thread_client, | 196 LayerTreeHostSingleThreadClient* single_thread_client, |
| 157 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, | 197 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, |
| 158 scoped_ptr<BeginFrameSource> external_begin_frame_source) { | 198 scoped_ptr<BeginFrameSource> external_begin_frame_source) { |
| 159 task_runner_provider_ = TaskRunnerProvider::Create(main_task_runner, nullptr); | 199 task_runner_provider_ = TaskRunnerProvider::Create(main_task_runner, nullptr); |
| 160 InitializeProxy(SingleThreadProxy::Create(this, single_thread_client, | 200 InitializeProxy(SingleThreadProxy::Create(this, single_thread_client, |
| 161 task_runner_provider_.get()), | 201 task_runner_provider_.get()), |
| 162 std::move(external_begin_frame_source)); | 202 std::move(external_begin_frame_source)); |
| 163 } | 203 } |
| 164 | 204 |
| 205 void LayerTreeHost::InitializeRemoteServer( | |
| 206 RemoteProtoChannel* remote_proto_channel, | |
| 207 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner) { | |
| 208 task_runner_provider_ = TaskRunnerProvider::Create(main_task_runner, nullptr); | |
| 209 InitializeProxy(ProxyMain::CreateRemote(remote_proto_channel, this, | |
| 210 task_runner_provider_.get()), | |
| 211 nullptr); | |
| 212 } | |
| 213 | |
| 214 void LayerTreeHost::InitializeRemoteClient( | |
| 215 RemoteProtoChannel* remote_proto_channel, | |
| 216 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, | |
| 217 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner) { | |
| 218 task_runner_provider_ = | |
| 219 TaskRunnerProvider::Create(main_task_runner, impl_task_runner); | |
| 220 InitializeProxy(RemoteChannelImpl::Create(this, remote_proto_channel, | |
|
vmpstr
2016/01/11 21:50:15
I think it's worth putting a comment here to kind
Khushal
2016/01/13 02:07:12
Done.
| |
| 221 task_runner_provider_.get()), | |
| 222 nullptr); | |
| 223 } | |
| 224 | |
| 165 void LayerTreeHost::InitializeForTesting( | 225 void LayerTreeHost::InitializeForTesting( |
| 166 scoped_ptr<TaskRunnerProvider> task_runner_provider, | 226 scoped_ptr<TaskRunnerProvider> task_runner_provider, |
| 167 scoped_ptr<Proxy> proxy_for_testing, | 227 scoped_ptr<Proxy> proxy_for_testing, |
| 168 scoped_ptr<BeginFrameSource> external_begin_frame_source) { | 228 scoped_ptr<BeginFrameSource> external_begin_frame_source) { |
| 169 task_runner_provider_ = std::move(task_runner_provider); | 229 task_runner_provider_ = std::move(task_runner_provider); |
| 170 InitializeProxy(std::move(proxy_for_testing), | 230 InitializeProxy(std::move(proxy_for_testing), |
| 171 std::move(external_begin_frame_source)); | 231 std::move(external_begin_frame_source)); |
| 172 } | 232 } |
| 173 | 233 |
| 174 void LayerTreeHost::SetTaskRunnerProviderForTesting( | 234 void LayerTreeHost::SetTaskRunnerProviderForTesting( |
| 175 scoped_ptr<TaskRunnerProvider> task_runner_provider) { | 235 scoped_ptr<TaskRunnerProvider> task_runner_provider) { |
| 176 DCHECK(!task_runner_provider_); | 236 DCHECK(!task_runner_provider_); |
| 177 task_runner_provider_ = std::move(task_runner_provider); | 237 task_runner_provider_ = std::move(task_runner_provider); |
| 178 } | 238 } |
| 179 | 239 |
| 180 void LayerTreeHost::InitializeProxy( | 240 void LayerTreeHost::InitializeProxy( |
| 181 scoped_ptr<Proxy> proxy, | 241 scoped_ptr<Proxy> proxy, |
| 182 scoped_ptr<BeginFrameSource> external_begin_frame_source) { | 242 scoped_ptr<BeginFrameSource> external_begin_frame_source) { |
| 183 TRACE_EVENT0("cc", "LayerTreeHost::InitializeForReal"); | 243 TRACE_EVENT0("cc", "LayerTreeHost::InitializeForReal"); |
| 244 DCHECK(task_runner_provider_); | |
| 184 | 245 |
| 185 proxy_ = std::move(proxy); | 246 proxy_ = std::move(proxy); |
| 186 proxy_->Start(std::move(external_begin_frame_source)); | 247 proxy_->Start(std::move(external_begin_frame_source)); |
| 187 if (settings_.accelerated_animation_enabled) { | 248 if (settings_.accelerated_animation_enabled) { |
| 188 if (animation_host_) | 249 if (animation_host_) |
| 189 animation_host_->SetSupportsScrollAnimations( | 250 animation_host_->SetSupportsScrollAnimations( |
| 190 proxy_->SupportsImplScrolling()); | 251 proxy_->SupportsImplScrolling()); |
| 191 else | 252 else |
| 192 animation_registrar_->set_supports_scroll_animations( | 253 animation_registrar_->set_supports_scroll_animations( |
| 193 proxy_->SupportsImplScrolling()); | 254 proxy_->SupportsImplScrolling()); |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 219 RegisterViewportLayers(NULL, NULL, NULL, NULL); | 280 RegisterViewportLayers(NULL, NULL, NULL, NULL); |
| 220 | 281 |
| 221 if (root_layer_.get()) { | 282 if (root_layer_.get()) { |
| 222 // The layer tree must be destroyed before the layer tree host. We've | 283 // The layer tree must be destroyed before the layer tree host. We've |
| 223 // made a contract with our animation controllers that the registrar | 284 // made a contract with our animation controllers that the registrar |
| 224 // will outlive them, and we must make good. | 285 // will outlive them, and we must make good. |
| 225 root_layer_ = NULL; | 286 root_layer_ = NULL; |
| 226 } | 287 } |
| 227 } | 288 } |
| 228 | 289 |
| 290 void LayerTreeHost::ToProtobuf() { | |
| 291 DCHECK(task_runner_provider_->IsMainThread()); | |
| 292 DCHECK(IsRemoteServer()); | |
| 293 | |
| 294 // TODO(khushalsagar, nyquist): Serialize LayerTreeHost state to proto. | |
|
vmpstr
2016/01/11 21:50:15
crbug?
Khushal
2016/01/13 02:07:12
Removed.
| |
| 295 } | |
| 296 | |
| 297 void LayerTreeHost::FromProtobuf() { | |
| 298 DCHECK(task_runner_provider_->IsMainThread()); | |
| 299 DCHECK(IsRemoteClient()); | |
| 300 | |
| 301 // TODO(khushalsagar, nyquist): Deserialize LayerTreeHost state from proto. | |
|
vmpstr
2016/01/11 21:50:15
crbug?
Khushal
2016/01/13 02:07:12
Removed.
| |
| 302 } | |
| 303 | |
| 229 void LayerTreeHost::WillBeginMainFrame() { | 304 void LayerTreeHost::WillBeginMainFrame() { |
| 230 devtools_instrumentation::WillBeginMainThreadFrame(id(), | 305 devtools_instrumentation::WillBeginMainThreadFrame(id(), |
| 231 source_frame_number()); | 306 source_frame_number()); |
| 232 client_->WillBeginMainFrame(); | 307 client_->WillBeginMainFrame(); |
| 233 } | 308 } |
| 234 | 309 |
| 235 void LayerTreeHost::DidBeginMainFrame() { | 310 void LayerTreeHost::DidBeginMainFrame() { |
| 236 client_->DidBeginMainFrame(); | 311 client_->DidBeginMainFrame(); |
| 237 } | 312 } |
| 238 | 313 |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 251 void LayerTreeHost::RequestMainFrameUpdate() { | 326 void LayerTreeHost::RequestMainFrameUpdate() { |
| 252 client_->UpdateLayerTreeHost(); | 327 client_->UpdateLayerTreeHost(); |
| 253 } | 328 } |
| 254 | 329 |
| 255 // This function commits the LayerTreeHost to an impl tree. When modifying | 330 // 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 | 331 // 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, | 332 // 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 | 333 // should be delayed until the LayerTreeHost::CommitComplete, which will run |
| 259 // after the commit, but on the main thread. | 334 // after the commit, but on the main thread. |
| 260 void LayerTreeHost::FinishCommitOnImplThread(LayerTreeHostImpl* host_impl) { | 335 void LayerTreeHost::FinishCommitOnImplThread(LayerTreeHostImpl* host_impl) { |
| 336 DCHECK(!IsRemoteServer()); | |
| 261 DCHECK(task_runner_provider_->IsImplThread()); | 337 DCHECK(task_runner_provider_->IsImplThread()); |
| 262 | 338 |
| 263 bool is_new_trace; | 339 bool is_new_trace; |
| 264 TRACE_EVENT_IS_NEW_TRACE(&is_new_trace); | 340 TRACE_EVENT_IS_NEW_TRACE(&is_new_trace); |
| 265 if (is_new_trace && | 341 if (is_new_trace && |
| 266 frame_viewer_instrumentation::IsTracingLayerTreeSnapshots() && | 342 frame_viewer_instrumentation::IsTracingLayerTreeSnapshots() && |
| 267 root_layer()) { | 343 root_layer()) { |
| 268 LayerTreeHostCommon::CallFunctionForSubtree( | 344 LayerTreeHostCommon::CallFunctionForSubtree( |
| 269 root_layer(), [](Layer* layer) { layer->DidBeginTracing(); }); | 345 root_layer(), [](Layer* layer) { layer->DidBeginTracing(); }); |
| 270 } | 346 } |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 436 // Note: It is safe to drop all output surface references here as | 512 // Note: It is safe to drop all output surface references here as |
| 437 // LayerTreeHostImpl will not keep a pointer to either the old or | 513 // LayerTreeHostImpl will not keep a pointer to either the old or |
| 438 // new output surface after failing to initialize the new one. | 514 // new output surface after failing to initialize the new one. |
| 439 current_output_surface_ = nullptr; | 515 current_output_surface_ = nullptr; |
| 440 new_output_surface_ = nullptr; | 516 new_output_surface_ = nullptr; |
| 441 client_->DidFailToInitializeOutputSurface(); | 517 client_->DidFailToInitializeOutputSurface(); |
| 442 } | 518 } |
| 443 | 519 |
| 444 scoped_ptr<LayerTreeHostImpl> LayerTreeHost::CreateLayerTreeHostImpl( | 520 scoped_ptr<LayerTreeHostImpl> LayerTreeHost::CreateLayerTreeHostImpl( |
| 445 LayerTreeHostImplClient* client) { | 521 LayerTreeHostImplClient* client) { |
| 522 DCHECK(!IsRemoteServer()); | |
| 446 DCHECK(task_runner_provider_->IsImplThread()); | 523 DCHECK(task_runner_provider_->IsImplThread()); |
| 447 scoped_ptr<LayerTreeHostImpl> host_impl = LayerTreeHostImpl::Create( | 524 scoped_ptr<LayerTreeHostImpl> host_impl = LayerTreeHostImpl::Create( |
| 448 settings_, client, task_runner_provider_.get(), | 525 settings_, client, task_runner_provider_.get(), |
| 449 rendering_stats_instrumentation_.get(), shared_bitmap_manager_, | 526 rendering_stats_instrumentation_.get(), shared_bitmap_manager_, |
| 450 gpu_memory_buffer_manager_, task_graph_runner_, id_); | 527 gpu_memory_buffer_manager_, task_graph_runner_, id_); |
| 451 host_impl->SetHasGpuRasterizationTrigger(has_gpu_rasterization_trigger_); | 528 host_impl->SetHasGpuRasterizationTrigger(has_gpu_rasterization_trigger_); |
| 452 host_impl->SetContentIsSuitableForGpuRasterization( | 529 host_impl->SetContentIsSuitableForGpuRasterization( |
| 453 content_is_suitable_for_gpu_rasterization_); | 530 content_is_suitable_for_gpu_rasterization_); |
| 454 shared_bitmap_manager_ = NULL; | 531 shared_bitmap_manager_ = NULL; |
| 455 gpu_memory_buffer_manager_ = NULL; | 532 gpu_memory_buffer_manager_ = NULL; |
| (...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 905 if (painted_device_scale_factor == painted_device_scale_factor_) | 982 if (painted_device_scale_factor == painted_device_scale_factor_) |
| 906 return; | 983 return; |
| 907 painted_device_scale_factor_ = painted_device_scale_factor; | 984 painted_device_scale_factor_ = painted_device_scale_factor; |
| 908 | 985 |
| 909 SetNeedsCommit(); | 986 SetNeedsCommit(); |
| 910 } | 987 } |
| 911 | 988 |
| 912 void LayerTreeHost::UpdateTopControlsState(TopControlsState constraints, | 989 void LayerTreeHost::UpdateTopControlsState(TopControlsState constraints, |
| 913 TopControlsState current, | 990 TopControlsState current, |
| 914 bool animate) { | 991 bool animate) { |
| 915 // Top controls are only used in threaded mode. | 992 // Top controls are only used in threaded or remote mode. |
| 916 DCHECK(IsThreaded()); | 993 DCHECK(IsThreaded() || IsRemoteServer()); |
| 917 proxy_->UpdateTopControlsState(constraints, current, animate); | 994 proxy_->UpdateTopControlsState(constraints, current, animate); |
| 918 } | 995 } |
| 919 | 996 |
| 920 void LayerTreeHost::AnimateLayers(base::TimeTicks monotonic_time) { | 997 void LayerTreeHost::AnimateLayers(base::TimeTicks monotonic_time) { |
| 921 if (!settings_.accelerated_animation_enabled) | 998 if (!settings_.accelerated_animation_enabled) |
| 922 return; | 999 return; |
| 923 | 1000 |
| 924 AnimationEventsVector events; | 1001 AnimationEventsVector events; |
| 925 if (animation_host_) { | 1002 if (animation_host_) { |
| 926 if (animation_host_->AnimateLayers(monotonic_time)) | 1003 if (animation_host_->AnimateLayers(monotonic_time)) |
| (...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1269 !task_runner_provider_->HasImplThread()); | 1346 !task_runner_provider_->HasImplThread()); |
| 1270 return compositor_mode_ == CompositorMode::SingleThreaded; | 1347 return compositor_mode_ == CompositorMode::SingleThreaded; |
| 1271 } | 1348 } |
| 1272 | 1349 |
| 1273 bool LayerTreeHost::IsThreaded() const { | 1350 bool LayerTreeHost::IsThreaded() const { |
| 1274 DCHECK(compositor_mode_ != CompositorMode::Threaded || | 1351 DCHECK(compositor_mode_ != CompositorMode::Threaded || |
| 1275 task_runner_provider_->HasImplThread()); | 1352 task_runner_provider_->HasImplThread()); |
| 1276 return compositor_mode_ == CompositorMode::Threaded; | 1353 return compositor_mode_ == CompositorMode::Threaded; |
| 1277 } | 1354 } |
| 1278 | 1355 |
| 1356 bool LayerTreeHost::IsRemoteServer() const { | |
| 1357 // The LayerTreeHost on the server does not have an impl task runner. | |
| 1358 return compositor_mode_ == CompositorMode::Remote && | |
| 1359 !task_runner_provider_->HasImplThread(); | |
| 1360 } | |
| 1361 | |
| 1362 bool LayerTreeHost::IsRemoteClient() const { | |
| 1363 return compositor_mode_ == CompositorMode::Remote && | |
| 1364 task_runner_provider_->HasImplThread(); | |
| 1365 } | |
| 1366 | |
| 1279 } // namespace cc | 1367 } // namespace cc |
| OLD | NEW |