| 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 <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 Loading... |
| 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 Loading... |
| 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::InitializeProxy(scoped_ptr<Proxy> proxy) { | 214 void LayerTreeHost::InitializeProxy(scoped_ptr<Proxy> proxy) { |
| 170 TRACE_EVENT0("cc", "LayerTreeHost::InitializeForReal"); | 215 TRACE_EVENT0("cc", "LayerTreeHost::InitializeForReal"); |
| 216 DCHECK(task_runner_provider_); |
| 171 | 217 |
| 172 proxy_ = std::move(proxy); | 218 proxy_ = std::move(proxy); |
| 173 proxy_->Start(); | 219 proxy_->Start(); |
| 174 if (settings_.accelerated_animation_enabled) { | 220 if (settings_.accelerated_animation_enabled) { |
| 175 if (animation_host_) | 221 if (animation_host_) |
| 176 animation_host_->SetSupportsScrollAnimations( | 222 animation_host_->SetSupportsScrollAnimations( |
| 177 proxy_->SupportsImplScrolling()); | 223 proxy_->SupportsImplScrolling()); |
| 178 else | 224 else |
| 179 animation_registrar_->set_supports_scroll_animations( | 225 animation_registrar_->set_supports_scroll_animations( |
| 180 proxy_->SupportsImplScrolling()); | 226 proxy_->SupportsImplScrolling()); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 void LayerTreeHost::RequestMainFrameUpdate() { | 284 void LayerTreeHost::RequestMainFrameUpdate() { |
| 239 client_->UpdateLayerTreeHost(); | 285 client_->UpdateLayerTreeHost(); |
| 240 } | 286 } |
| 241 | 287 |
| 242 // This function commits the LayerTreeHost to an impl tree. When modifying | 288 // This function commits the LayerTreeHost to an impl tree. When modifying |
| 243 // this function, keep in mind that the function *runs* on the impl thread! Any | 289 // this function, keep in mind that the function *runs* on the impl thread! Any |
| 244 // code that is logically a main thread operation, e.g. deletion of a Layer, | 290 // code that is logically a main thread operation, e.g. deletion of a Layer, |
| 245 // should be delayed until the LayerTreeHost::CommitComplete, which will run | 291 // should be delayed until the LayerTreeHost::CommitComplete, which will run |
| 246 // after the commit, but on the main thread. | 292 // after the commit, but on the main thread. |
| 247 void LayerTreeHost::FinishCommitOnImplThread(LayerTreeHostImpl* host_impl) { | 293 void LayerTreeHost::FinishCommitOnImplThread(LayerTreeHostImpl* host_impl) { |
| 294 DCHECK(!IsRemote()); |
| 248 DCHECK(task_runner_provider_->IsImplThread()); | 295 DCHECK(task_runner_provider_->IsImplThread()); |
| 249 | 296 |
| 250 bool is_new_trace; | 297 bool is_new_trace; |
| 251 TRACE_EVENT_IS_NEW_TRACE(&is_new_trace); | 298 TRACE_EVENT_IS_NEW_TRACE(&is_new_trace); |
| 252 if (is_new_trace && | 299 if (is_new_trace && |
| 253 frame_viewer_instrumentation::IsTracingLayerTreeSnapshots() && | 300 frame_viewer_instrumentation::IsTracingLayerTreeSnapshots() && |
| 254 root_layer()) { | 301 root_layer()) { |
| 255 LayerTreeHostCommon::CallFunctionForSubtree( | 302 LayerTreeHostCommon::CallFunctionForSubtree( |
| 256 root_layer(), [](Layer* layer) { layer->DidBeginTracing(); }); | 303 root_layer(), [](Layer* layer) { layer->DidBeginTracing(); }); |
| 257 } | 304 } |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 423 // Note: It is safe to drop all output surface references here as | 470 // Note: It is safe to drop all output surface references here as |
| 424 // LayerTreeHostImpl will not keep a pointer to either the old or | 471 // LayerTreeHostImpl will not keep a pointer to either the old or |
| 425 // new output surface after failing to initialize the new one. | 472 // new output surface after failing to initialize the new one. |
| 426 current_output_surface_ = nullptr; | 473 current_output_surface_ = nullptr; |
| 427 new_output_surface_ = nullptr; | 474 new_output_surface_ = nullptr; |
| 428 client_->DidFailToInitializeOutputSurface(); | 475 client_->DidFailToInitializeOutputSurface(); |
| 429 } | 476 } |
| 430 | 477 |
| 431 scoped_ptr<LayerTreeHostImpl> LayerTreeHost::CreateLayerTreeHostImpl( | 478 scoped_ptr<LayerTreeHostImpl> LayerTreeHost::CreateLayerTreeHostImpl( |
| 432 LayerTreeHostImplClient* client) { | 479 LayerTreeHostImplClient* client) { |
| 480 DCHECK(!IsRemote()); |
| 433 DCHECK(task_runner_provider_->IsImplThread()); | 481 DCHECK(task_runner_provider_->IsImplThread()); |
| 434 scoped_ptr<LayerTreeHostImpl> host_impl = LayerTreeHostImpl::Create( | 482 scoped_ptr<LayerTreeHostImpl> host_impl = LayerTreeHostImpl::Create( |
| 435 settings_, client, task_runner_provider_.get(), | 483 settings_, client, task_runner_provider_.get(), |
| 436 rendering_stats_instrumentation_.get(), shared_bitmap_manager_, | 484 rendering_stats_instrumentation_.get(), shared_bitmap_manager_, |
| 437 gpu_memory_buffer_manager_, task_graph_runner_, id_); | 485 gpu_memory_buffer_manager_, task_graph_runner_, id_); |
| 438 host_impl->SetHasGpuRasterizationTrigger(has_gpu_rasterization_trigger_); | 486 host_impl->SetHasGpuRasterizationTrigger(has_gpu_rasterization_trigger_); |
| 439 host_impl->SetContentIsSuitableForGpuRasterization( | 487 host_impl->SetContentIsSuitableForGpuRasterization( |
| 440 content_is_suitable_for_gpu_rasterization_); | 488 content_is_suitable_for_gpu_rasterization_); |
| 441 shared_bitmap_manager_ = NULL; | 489 shared_bitmap_manager_ = NULL; |
| 442 gpu_memory_buffer_manager_ = NULL; | 490 gpu_memory_buffer_manager_ = NULL; |
| (...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 730 Layer* found = FindFirstScrollableLayer(layer->children()[i].get()); | 778 Layer* found = FindFirstScrollableLayer(layer->children()[i].get()); |
| 731 if (found) | 779 if (found) |
| 732 return found; | 780 return found; |
| 733 } | 781 } |
| 734 | 782 |
| 735 return NULL; | 783 return NULL; |
| 736 } | 784 } |
| 737 | 785 |
| 738 void LayerTreeHost::RecordGpuRasterizationHistogram() { | 786 void LayerTreeHost::RecordGpuRasterizationHistogram() { |
| 739 // Gpu rasterization is only supported for Renderer compositors. | 787 // Gpu rasterization is only supported for Renderer compositors. |
| 740 // Checking for IsThreaded() to exclude Browser compositors. | 788 // Checking for IsSingleThreaded() to exclude Browser compositors. |
| 741 if (gpu_rasterization_histogram_recorded_ || IsThreaded()) | 789 if (gpu_rasterization_histogram_recorded_ || IsSingleThreaded()) |
| 742 return; | 790 return; |
| 743 | 791 |
| 744 // Record how widely gpu rasterization is enabled. | 792 // Record how widely gpu rasterization is enabled. |
| 745 // This number takes device/gpu whitelisting/backlisting into account. | 793 // This number takes device/gpu whitelisting/backlisting into account. |
| 746 // Note that we do not consider the forced gpu rasterization mode, which is | 794 // Note that we do not consider the forced gpu rasterization mode, which is |
| 747 // mostly used for debugging purposes. | 795 // mostly used for debugging purposes. |
| 748 UMA_HISTOGRAM_BOOLEAN("Renderer4.GpuRasterizationEnabled", | 796 UMA_HISTOGRAM_BOOLEAN("Renderer4.GpuRasterizationEnabled", |
| 749 settings_.gpu_rasterization_enabled); | 797 settings_.gpu_rasterization_enabled); |
| 750 if (settings_.gpu_rasterization_enabled) { | 798 if (settings_.gpu_rasterization_enabled) { |
| 751 UMA_HISTOGRAM_BOOLEAN("Renderer4.GpuRasterizationTriggered", | 799 UMA_HISTOGRAM_BOOLEAN("Renderer4.GpuRasterizationTriggered", |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 892 if (painted_device_scale_factor == painted_device_scale_factor_) | 940 if (painted_device_scale_factor == painted_device_scale_factor_) |
| 893 return; | 941 return; |
| 894 painted_device_scale_factor_ = painted_device_scale_factor; | 942 painted_device_scale_factor_ = painted_device_scale_factor; |
| 895 | 943 |
| 896 SetNeedsCommit(); | 944 SetNeedsCommit(); |
| 897 } | 945 } |
| 898 | 946 |
| 899 void LayerTreeHost::UpdateTopControlsState(TopControlsState constraints, | 947 void LayerTreeHost::UpdateTopControlsState(TopControlsState constraints, |
| 900 TopControlsState current, | 948 TopControlsState current, |
| 901 bool animate) { | 949 bool animate) { |
| 902 // Top controls are only used in threaded mode. | 950 // Top controls are only used in threaded or remote mode. |
| 903 DCHECK(IsThreaded()); | 951 DCHECK(IsThreaded() || IsRemote()); |
| 904 proxy_->UpdateTopControlsState(constraints, current, animate); | 952 proxy_->UpdateTopControlsState(constraints, current, animate); |
| 905 } | 953 } |
| 906 | 954 |
| 907 void LayerTreeHost::AnimateLayers(base::TimeTicks monotonic_time) { | 955 void LayerTreeHost::AnimateLayers(base::TimeTicks monotonic_time) { |
| 908 if (!settings_.accelerated_animation_enabled) | 956 if (!settings_.accelerated_animation_enabled) |
| 909 return; | 957 return; |
| 910 | 958 |
| 911 AnimationEventsVector events; | 959 AnimationEventsVector events; |
| 912 if (animation_host_) { | 960 if (animation_host_) { |
| 913 if (animation_host_->AnimateLayers(monotonic_time)) | 961 if (animation_host_->AnimateLayers(monotonic_time)) |
| (...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1256 !task_runner_provider_->HasImplThread()); | 1304 !task_runner_provider_->HasImplThread()); |
| 1257 return compositor_mode_ == CompositorMode::SingleThreaded; | 1305 return compositor_mode_ == CompositorMode::SingleThreaded; |
| 1258 } | 1306 } |
| 1259 | 1307 |
| 1260 bool LayerTreeHost::IsThreaded() const { | 1308 bool LayerTreeHost::IsThreaded() const { |
| 1261 DCHECK(compositor_mode_ != CompositorMode::Threaded || | 1309 DCHECK(compositor_mode_ != CompositorMode::Threaded || |
| 1262 task_runner_provider_->HasImplThread()); | 1310 task_runner_provider_->HasImplThread()); |
| 1263 return compositor_mode_ == CompositorMode::Threaded; | 1311 return compositor_mode_ == CompositorMode::Threaded; |
| 1264 } | 1312 } |
| 1265 | 1313 |
| 1314 bool LayerTreeHost::IsRemote() const { |
| 1315 DCHECK(compositor_mode_ != CompositorMode::Remote || |
| 1316 !task_runner_provider_->HasImplThread()); |
| 1317 return compositor_mode_ == CompositorMode::Remote; |
| 1318 } |
| 1319 |
| 1320 bool LayerTreeHost::IsDeserializable() const { |
| 1321 DCHECK(compositor_mode_ != CompositorMode::Deserializable || |
| 1322 task_runner_provider_->HasImplThread()); |
| 1323 return compositor_mode_ == CompositorMode::Deserializable; |
| 1324 } |
| 1325 |
| 1266 } // namespace cc | 1326 } // namespace cc |
| OLD | NEW |