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 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 } | 130 } |
131 | 131 |
132 rendering_stats_instrumentation_->set_record_rendering_stats( | 132 rendering_stats_instrumentation_->set_record_rendering_stats( |
133 debug_state_.RecordRenderingStats()); | 133 debug_state_.RecordRenderingStats()); |
134 } | 134 } |
135 | 135 |
136 void LayerTreeHost::InitializeThreaded( | 136 void LayerTreeHost::InitializeThreaded( |
137 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, | 137 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, |
138 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner, | 138 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner, |
139 scoped_ptr<BeginFrameSource> external_begin_frame_source) { | 139 scoped_ptr<BeginFrameSource> external_begin_frame_source) { |
140 InitializeProxy(ThreadProxy::Create(this, | 140 task_runner_provider_ = |
141 main_task_runner, | 141 TaskRunnerProvider::Create(main_task_runner, impl_task_runner); |
142 impl_task_runner, | 142 InitializeProxy(ThreadProxy::Create(this, task_runner_provider_.get(), |
143 external_begin_frame_source.Pass())); | 143 external_begin_frame_source.Pass())); |
144 } | 144 } |
145 | 145 |
146 void LayerTreeHost::InitializeSingleThreaded( | 146 void LayerTreeHost::InitializeSingleThreaded( |
147 LayerTreeHostSingleThreadClient* single_thread_client, | 147 LayerTreeHostSingleThreadClient* single_thread_client, |
148 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, | 148 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, |
149 scoped_ptr<BeginFrameSource> external_begin_frame_source) { | 149 scoped_ptr<BeginFrameSource> external_begin_frame_source) { |
150 InitializeProxy( | 150 task_runner_provider_ = TaskRunnerProvider::Create(main_task_runner, nullptr); |
151 SingleThreadProxy::Create(this, | 151 InitializeProxy(SingleThreadProxy::Create( |
152 single_thread_client, | 152 this, single_thread_client, task_runner_provider_.get(), |
153 main_task_runner, | 153 external_begin_frame_source.Pass())); |
154 external_begin_frame_source.Pass())); | |
155 } | 154 } |
156 | 155 |
157 void LayerTreeHost::InitializeForTesting(scoped_ptr<Proxy> proxy_for_testing) { | 156 void LayerTreeHost::InitializeForTesting( |
| 157 scoped_ptr<TaskRunnerProvider> task_runner_provider, |
| 158 scoped_ptr<Proxy> proxy_for_testing) { |
| 159 task_runner_provider_ = task_runner_provider.Pass(); |
158 InitializeProxy(proxy_for_testing.Pass()); | 160 InitializeProxy(proxy_for_testing.Pass()); |
159 } | 161 } |
160 | 162 |
161 void LayerTreeHost::InitializeProxy(scoped_ptr<Proxy> proxy) { | 163 void LayerTreeHost::InitializeProxy(scoped_ptr<Proxy> proxy) { |
162 TRACE_EVENT0("cc", "LayerTreeHost::InitializeForReal"); | 164 TRACE_EVENT0("cc", "LayerTreeHost::InitializeForReal"); |
163 | 165 |
164 proxy_ = proxy.Pass(); | 166 proxy_ = proxy.Pass(); |
165 proxy_->Start(); | 167 proxy_->Start(); |
166 if (settings_.accelerated_animation_enabled) { | 168 if (settings_.accelerated_animation_enabled) { |
167 if (animation_host_) | 169 if (animation_host_) |
(...skipping 12 matching lines...) Expand all Loading... |
180 animation_host_->SetMutatorHostClient(nullptr); | 182 animation_host_->SetMutatorHostClient(nullptr); |
181 | 183 |
182 if (root_layer_.get()) | 184 if (root_layer_.get()) |
183 root_layer_->SetLayerTreeHost(NULL); | 185 root_layer_->SetLayerTreeHost(NULL); |
184 | 186 |
185 DCHECK(swap_promise_monitor_.empty()); | 187 DCHECK(swap_promise_monitor_.empty()); |
186 | 188 |
187 BreakSwapPromises(SwapPromise::COMMIT_FAILS); | 189 BreakSwapPromises(SwapPromise::COMMIT_FAILS); |
188 | 190 |
189 if (proxy_) { | 191 if (proxy_) { |
190 DCHECK(proxy_->IsMainThread()); | 192 DCHECK(task_runner_provider_->IsMainThread()); |
191 proxy_->Stop(); | 193 proxy_->Stop(); |
| 194 |
| 195 // Proxy must be destroyed before the Task Runner Provider. |
| 196 proxy_ = nullptr; |
192 } | 197 } |
193 | 198 |
194 // We must clear any pointers into the layer tree prior to destroying it. | 199 // We must clear any pointers into the layer tree prior to destroying it. |
195 RegisterViewportLayers(NULL, NULL, NULL, NULL); | 200 RegisterViewportLayers(NULL, NULL, NULL, NULL); |
196 | 201 |
197 if (root_layer_.get()) { | 202 if (root_layer_.get()) { |
198 // The layer tree must be destroyed before the layer tree host. We've | 203 // The layer tree must be destroyed before the layer tree host. We've |
199 // made a contract with our animation controllers that the registrar | 204 // made a contract with our animation controllers that the registrar |
200 // will outlive them, and we must make good. | 205 // will outlive them, and we must make good. |
201 root_layer_ = NULL; | 206 root_layer_ = NULL; |
(...skipping 25 matching lines...) Expand all Loading... |
227 void LayerTreeHost::RequestMainFrameUpdate() { | 232 void LayerTreeHost::RequestMainFrameUpdate() { |
228 client_->UpdateLayerTreeHost(); | 233 client_->UpdateLayerTreeHost(); |
229 } | 234 } |
230 | 235 |
231 // This function commits the LayerTreeHost to an impl tree. When modifying | 236 // This function commits the LayerTreeHost to an impl tree. When modifying |
232 // this function, keep in mind that the function *runs* on the impl thread! Any | 237 // this function, keep in mind that the function *runs* on the impl thread! Any |
233 // code that is logically a main thread operation, e.g. deletion of a Layer, | 238 // code that is logically a main thread operation, e.g. deletion of a Layer, |
234 // should be delayed until the LayerTreeHost::CommitComplete, which will run | 239 // should be delayed until the LayerTreeHost::CommitComplete, which will run |
235 // after the commit, but on the main thread. | 240 // after the commit, but on the main thread. |
236 void LayerTreeHost::FinishCommitOnImplThread(LayerTreeHostImpl* host_impl) { | 241 void LayerTreeHost::FinishCommitOnImplThread(LayerTreeHostImpl* host_impl) { |
237 DCHECK(proxy_->IsImplThread()); | 242 DCHECK(task_runner_provider_->IsImplThread()); |
238 | 243 |
239 bool is_new_trace; | 244 bool is_new_trace; |
240 TRACE_EVENT_IS_NEW_TRACE(&is_new_trace); | 245 TRACE_EVENT_IS_NEW_TRACE(&is_new_trace); |
241 if (is_new_trace && | 246 if (is_new_trace && |
242 frame_viewer_instrumentation::IsTracingLayerTreeSnapshots() && | 247 frame_viewer_instrumentation::IsTracingLayerTreeSnapshots() && |
243 root_layer()) { | 248 root_layer()) { |
244 LayerTreeHostCommon::CallFunctionForSubtree( | 249 LayerTreeHostCommon::CallFunctionForSubtree( |
245 root_layer(), [](Layer* layer) { layer->DidBeginTracing(); }); | 250 root_layer(), [](Layer* layer) { layer->DidBeginTracing(); }); |
246 } | 251 } |
247 | 252 |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
412 // Note: It is safe to drop all output surface references here as | 417 // Note: It is safe to drop all output surface references here as |
413 // LayerTreeHostImpl will not keep a pointer to either the old or | 418 // LayerTreeHostImpl will not keep a pointer to either the old or |
414 // new output surface after failing to initialize the new one. | 419 // new output surface after failing to initialize the new one. |
415 current_output_surface_ = nullptr; | 420 current_output_surface_ = nullptr; |
416 new_output_surface_ = nullptr; | 421 new_output_surface_ = nullptr; |
417 client_->DidFailToInitializeOutputSurface(); | 422 client_->DidFailToInitializeOutputSurface(); |
418 } | 423 } |
419 | 424 |
420 scoped_ptr<LayerTreeHostImpl> LayerTreeHost::CreateLayerTreeHostImpl( | 425 scoped_ptr<LayerTreeHostImpl> LayerTreeHost::CreateLayerTreeHostImpl( |
421 LayerTreeHostImplClient* client) { | 426 LayerTreeHostImplClient* client) { |
422 DCHECK(proxy_->IsImplThread()); | 427 DCHECK(task_runner_provider_->IsImplThread()); |
423 scoped_ptr<LayerTreeHostImpl> host_impl = LayerTreeHostImpl::Create( | 428 scoped_ptr<LayerTreeHostImpl> host_impl = LayerTreeHostImpl::Create( |
424 settings_, client, proxy_.get(), rendering_stats_instrumentation_.get(), | 429 settings_, client, task_runner_provider_.get(), |
425 shared_bitmap_manager_, gpu_memory_buffer_manager_, task_graph_runner_, | 430 rendering_stats_instrumentation_.get(), shared_bitmap_manager_, |
426 id_); | 431 gpu_memory_buffer_manager_, task_graph_runner_, id_); |
427 host_impl->SetHasGpuRasterizationTrigger(has_gpu_rasterization_trigger_); | 432 host_impl->SetHasGpuRasterizationTrigger(has_gpu_rasterization_trigger_); |
428 host_impl->SetContentIsSuitableForGpuRasterization( | 433 host_impl->SetContentIsSuitableForGpuRasterization( |
429 content_is_suitable_for_gpu_rasterization_); | 434 content_is_suitable_for_gpu_rasterization_); |
430 shared_bitmap_manager_ = NULL; | 435 shared_bitmap_manager_ = NULL; |
431 gpu_memory_buffer_manager_ = NULL; | 436 gpu_memory_buffer_manager_ = NULL; |
432 task_graph_runner_ = NULL; | 437 task_graph_runner_ = NULL; |
433 input_handler_weak_ptr_ = host_impl->AsWeakPtr(); | 438 input_handler_weak_ptr_ = host_impl->AsWeakPtr(); |
434 return host_impl.Pass(); | 439 return host_impl.Pass(); |
435 } | 440 } |
436 | 441 |
437 void LayerTreeHost::DidLoseOutputSurface() { | 442 void LayerTreeHost::DidLoseOutputSurface() { |
438 TRACE_EVENT0("cc", "LayerTreeHost::DidLoseOutputSurface"); | 443 TRACE_EVENT0("cc", "LayerTreeHost::DidLoseOutputSurface"); |
439 DCHECK(proxy_->IsMainThread()); | 444 DCHECK(task_runner_provider_->IsMainThread()); |
440 | 445 |
441 if (output_surface_lost_) | 446 if (output_surface_lost_) |
442 return; | 447 return; |
443 | 448 |
444 output_surface_lost_ = true; | 449 output_surface_lost_ = true; |
445 SetNeedsCommit(); | 450 SetNeedsCommit(); |
446 } | 451 } |
447 | 452 |
448 void LayerTreeHost::FinishAllRendering() { | 453 void LayerTreeHost::FinishAllRendering() { |
449 proxy_->FinishAllRendering(); | 454 proxy_->FinishAllRendering(); |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
523 proxy_->SetNextCommitWaitsForActivation(); | 528 proxy_->SetNextCommitWaitsForActivation(); |
524 } | 529 } |
525 | 530 |
526 void LayerTreeHost::SetNextCommitForcesRedraw() { | 531 void LayerTreeHost::SetNextCommitForcesRedraw() { |
527 next_commit_forces_redraw_ = true; | 532 next_commit_forces_redraw_ = true; |
528 proxy_->SetNeedsUpdateLayers(); | 533 proxy_->SetNeedsUpdateLayers(); |
529 } | 534 } |
530 | 535 |
531 void LayerTreeHost::SetAnimationEvents( | 536 void LayerTreeHost::SetAnimationEvents( |
532 scoped_ptr<AnimationEventsVector> events) { | 537 scoped_ptr<AnimationEventsVector> events) { |
533 DCHECK(proxy_->IsMainThread()); | 538 DCHECK(task_runner_provider_->IsMainThread()); |
534 if (animation_host_) | 539 if (animation_host_) |
535 animation_host_->SetAnimationEvents(events.Pass()); | 540 animation_host_->SetAnimationEvents(events.Pass()); |
536 else | 541 else |
537 animation_registrar_->SetAnimationEvents(events.Pass()); | 542 animation_registrar_->SetAnimationEvents(events.Pass()); |
538 } | 543 } |
539 | 544 |
540 void LayerTreeHost::SetRootLayer(scoped_refptr<Layer> root_layer) { | 545 void LayerTreeHost::SetRootLayer(scoped_refptr<Layer> root_layer) { |
541 if (root_layer_.get() == root_layer.get()) | 546 if (root_layer_.get() == root_layer.get()) |
542 return; | 547 return; |
543 | 548 |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
661 duration)); | 666 duration)); |
662 | 667 |
663 SetNeedsCommit(); | 668 SetNeedsCommit(); |
664 } | 669 } |
665 | 670 |
666 void LayerTreeHost::NotifyInputThrottledUntilCommit() { | 671 void LayerTreeHost::NotifyInputThrottledUntilCommit() { |
667 proxy_->NotifyInputThrottledUntilCommit(); | 672 proxy_->NotifyInputThrottledUntilCommit(); |
668 } | 673 } |
669 | 674 |
670 void LayerTreeHost::LayoutAndUpdateLayers() { | 675 void LayerTreeHost::LayoutAndUpdateLayers() { |
671 DCHECK(!proxy_->HasImplThread()); | 676 DCHECK(!task_runner_provider_->HasImplThread()); |
672 // This function is only valid when not using the scheduler. | 677 // This function is only valid when not using the scheduler. |
673 DCHECK(!settings_.single_thread_proxy_scheduler); | 678 DCHECK(!settings_.single_thread_proxy_scheduler); |
674 SingleThreadProxy* proxy = static_cast<SingleThreadProxy*>(proxy_.get()); | 679 SingleThreadProxy* proxy = static_cast<SingleThreadProxy*>(proxy_.get()); |
675 | 680 |
676 if (output_surface_lost()) { | 681 if (output_surface_lost()) { |
677 proxy->RequestNewOutputSurface(); | 682 proxy->RequestNewOutputSurface(); |
678 // RequestNewOutputSurface could have synchronously created an output | 683 // RequestNewOutputSurface could have synchronously created an output |
679 // surface, so check again before returning. | 684 // surface, so check again before returning. |
680 if (output_surface_lost()) | 685 if (output_surface_lost()) |
681 return; | 686 return; |
682 } | 687 } |
683 | 688 |
684 RequestMainFrameUpdate(); | 689 RequestMainFrameUpdate(); |
685 UpdateLayers(); | 690 UpdateLayers(); |
686 } | 691 } |
687 | 692 |
688 void LayerTreeHost::Composite(base::TimeTicks frame_begin_time) { | 693 void LayerTreeHost::Composite(base::TimeTicks frame_begin_time) { |
689 DCHECK(!proxy_->HasImplThread()); | 694 DCHECK(!task_runner_provider_->HasImplThread()); |
690 // This function is only valid when not using the scheduler. | 695 // This function is only valid when not using the scheduler. |
691 DCHECK(!settings_.single_thread_proxy_scheduler); | 696 DCHECK(!settings_.single_thread_proxy_scheduler); |
692 SingleThreadProxy* proxy = static_cast<SingleThreadProxy*>(proxy_.get()); | 697 SingleThreadProxy* proxy = static_cast<SingleThreadProxy*>(proxy_.get()); |
693 | 698 |
694 proxy->CompositeImmediately(frame_begin_time); | 699 proxy->CompositeImmediately(frame_begin_time); |
695 } | 700 } |
696 | 701 |
697 bool LayerTreeHost::UpdateLayers() { | 702 bool LayerTreeHost::UpdateLayers() { |
698 DCHECK(!output_surface_lost_); | 703 DCHECK(!output_surface_lost_); |
699 if (!root_layer()) | 704 if (!root_layer()) |
(...skipping 20 matching lines...) Expand all Loading... |
720 if (found) | 725 if (found) |
721 return found; | 726 return found; |
722 } | 727 } |
723 | 728 |
724 return NULL; | 729 return NULL; |
725 } | 730 } |
726 | 731 |
727 void LayerTreeHost::RecordGpuRasterizationHistogram() { | 732 void LayerTreeHost::RecordGpuRasterizationHistogram() { |
728 // Gpu rasterization is only supported for Renderer compositors. | 733 // Gpu rasterization is only supported for Renderer compositors. |
729 // Checking for proxy_->HasImplThread() to exclude Browser compositors. | 734 // Checking for proxy_->HasImplThread() to exclude Browser compositors. |
730 if (gpu_rasterization_histogram_recorded_ || !proxy_->HasImplThread()) | 735 if (gpu_rasterization_histogram_recorded_ || |
| 736 !task_runner_provider_->HasImplThread()) |
731 return; | 737 return; |
732 | 738 |
733 // Record how widely gpu rasterization is enabled. | 739 // Record how widely gpu rasterization is enabled. |
734 // This number takes device/gpu whitelisting/backlisting into account. | 740 // This number takes device/gpu whitelisting/backlisting into account. |
735 // Note that we do not consider the forced gpu rasterization mode, which is | 741 // Note that we do not consider the forced gpu rasterization mode, which is |
736 // mostly used for debugging purposes. | 742 // mostly used for debugging purposes. |
737 UMA_HISTOGRAM_BOOLEAN("Renderer4.GpuRasterizationEnabled", | 743 UMA_HISTOGRAM_BOOLEAN("Renderer4.GpuRasterizationEnabled", |
738 settings_.gpu_rasterization_enabled); | 744 settings_.gpu_rasterization_enabled); |
739 if (settings_.gpu_rasterization_enabled) { | 745 if (settings_.gpu_rasterization_enabled) { |
740 UMA_HISTOGRAM_BOOLEAN("Renderer4.GpuRasterizationTriggered", | 746 UMA_HISTOGRAM_BOOLEAN("Renderer4.GpuRasterizationTriggered", |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
888 return; | 894 return; |
889 painted_device_scale_factor_ = painted_device_scale_factor; | 895 painted_device_scale_factor_ = painted_device_scale_factor; |
890 | 896 |
891 SetNeedsCommit(); | 897 SetNeedsCommit(); |
892 } | 898 } |
893 | 899 |
894 void LayerTreeHost::UpdateTopControlsState(TopControlsState constraints, | 900 void LayerTreeHost::UpdateTopControlsState(TopControlsState constraints, |
895 TopControlsState current, | 901 TopControlsState current, |
896 bool animate) { | 902 bool animate) { |
897 // Top controls are only used in threaded mode. | 903 // Top controls are only used in threaded mode. |
898 DCHECK(proxy_->HasImplThread()); | 904 DCHECK(task_runner_provider_->HasImplThread()); |
899 proxy_->UpdateTopControlsState(constraints, current, animate); | 905 proxy_->UpdateTopControlsState(constraints, current, animate); |
900 } | 906 } |
901 | 907 |
902 void LayerTreeHost::AnimateLayers(base::TimeTicks monotonic_time) { | 908 void LayerTreeHost::AnimateLayers(base::TimeTicks monotonic_time) { |
903 if (!settings_.accelerated_animation_enabled) | 909 if (!settings_.accelerated_animation_enabled) |
904 return; | 910 return; |
905 | 911 |
906 AnimationEventsVector events; | 912 AnimationEventsVector events; |
907 if (animation_host_) { | 913 if (animation_host_) { |
908 if (animation_host_->AnimateLayers(monotonic_time)) | 914 if (animation_host_->AnimateLayers(monotonic_time)) |
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1240 return animation_host_ ? animation_host_->HasAnyAnimation(layer->id()) | 1246 return animation_host_ ? animation_host_->HasAnyAnimation(layer->id()) |
1241 : false; | 1247 : false; |
1242 } | 1248 } |
1243 | 1249 |
1244 bool LayerTreeHost::HasActiveAnimation(const Layer* layer) const { | 1250 bool LayerTreeHost::HasActiveAnimation(const Layer* layer) const { |
1245 return animation_host_ ? animation_host_->HasActiveAnimation(layer->id()) | 1251 return animation_host_ ? animation_host_->HasActiveAnimation(layer->id()) |
1246 : false; | 1252 : false; |
1247 } | 1253 } |
1248 | 1254 |
1249 } // namespace cc | 1255 } // namespace cc |
OLD | NEW |