| 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/single_thread_proxy.h" | 5 #include "cc/trees/single_thread_proxy.h" |
| 6 | 6 |
| 7 #include "base/auto_reset.h" | 7 #include "base/auto_reset.h" |
| 8 #include "base/debug/trace_event.h" | 8 #include "base/trace_event/trace_event.h" |
| 9 #include "cc/debug/benchmark_instrumentation.h" | 9 #include "cc/debug/benchmark_instrumentation.h" |
| 10 #include "cc/output/context_provider.h" | 10 #include "cc/output/context_provider.h" |
| 11 #include "cc/output/output_surface.h" | 11 #include "cc/output/output_surface.h" |
| 12 #include "cc/quads/draw_quad.h" | 12 #include "cc/quads/draw_quad.h" |
| 13 #include "cc/resources/prioritized_resource_manager.h" | 13 #include "cc/resources/prioritized_resource_manager.h" |
| 14 #include "cc/resources/resource_update_controller.h" | 14 #include "cc/resources/resource_update_controller.h" |
| 15 #include "cc/scheduler/commit_earlyout_reason.h" | 15 #include "cc/scheduler/commit_earlyout_reason.h" |
| 16 #include "cc/trees/layer_tree_host.h" | 16 #include "cc/trees/layer_tree_host.h" |
| 17 #include "cc/trees/layer_tree_host_single_thread_client.h" | 17 #include "cc/trees/layer_tree_host_single_thread_client.h" |
| 18 #include "cc/trees/layer_tree_impl.h" | 18 #include "cc/trees/layer_tree_impl.h" |
| (...skipping 19 matching lines...) Expand all Loading... |
| 38 LayerTreeHostSingleThreadClient* client, | 38 LayerTreeHostSingleThreadClient* client, |
| 39 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, | 39 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, |
| 40 scoped_ptr<BeginFrameSource> external_begin_frame_source) | 40 scoped_ptr<BeginFrameSource> external_begin_frame_source) |
| 41 : Proxy(main_task_runner, NULL), | 41 : Proxy(main_task_runner, NULL), |
| 42 layer_tree_host_(layer_tree_host), | 42 layer_tree_host_(layer_tree_host), |
| 43 client_(client), | 43 client_(client), |
| 44 timing_history_(layer_tree_host->rendering_stats_instrumentation()), | 44 timing_history_(layer_tree_host->rendering_stats_instrumentation()), |
| 45 next_frame_is_newly_committed_frame_(false), | 45 next_frame_is_newly_committed_frame_(false), |
| 46 inside_draw_(false), | 46 inside_draw_(false), |
| 47 defer_commits_(false), | 47 defer_commits_(false), |
| 48 commit_was_deferred_(false), | |
| 49 commit_requested_(false), | 48 commit_requested_(false), |
| 50 inside_synchronous_composite_(false), | 49 inside_synchronous_composite_(false), |
| 51 output_surface_creation_requested_(false), | 50 output_surface_creation_requested_(false), |
| 52 external_begin_frame_source_(external_begin_frame_source.Pass()), | 51 external_begin_frame_source_(external_begin_frame_source.Pass()), |
| 53 weak_factory_(this) { | 52 weak_factory_(this) { |
| 54 TRACE_EVENT0("cc", "SingleThreadProxy::SingleThreadProxy"); | 53 TRACE_EVENT0("cc", "SingleThreadProxy::SingleThreadProxy"); |
| 55 DCHECK(Proxy::IsMainThread()); | 54 DCHECK(Proxy::IsMainThread()); |
| 56 DCHECK(layer_tree_host); | 55 DCHECK(layer_tree_host); |
| 57 } | 56 } |
| 58 | 57 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 84 | 83 |
| 85 void SingleThreadProxy::SetLayerTreeHostClientReady() { | 84 void SingleThreadProxy::SetLayerTreeHostClientReady() { |
| 86 TRACE_EVENT0("cc", "SingleThreadProxy::SetLayerTreeHostClientReady"); | 85 TRACE_EVENT0("cc", "SingleThreadProxy::SetLayerTreeHostClientReady"); |
| 87 // Scheduling is controlled by the embedder in the single thread case, so | 86 // Scheduling is controlled by the embedder in the single thread case, so |
| 88 // nothing to do. | 87 // nothing to do. |
| 89 DCHECK(Proxy::IsMainThread()); | 88 DCHECK(Proxy::IsMainThread()); |
| 90 DebugScopedSetImplThread impl(this); | 89 DebugScopedSetImplThread impl(this); |
| 91 if (layer_tree_host_->settings().single_thread_proxy_scheduler && | 90 if (layer_tree_host_->settings().single_thread_proxy_scheduler && |
| 92 !scheduler_on_impl_thread_) { | 91 !scheduler_on_impl_thread_) { |
| 93 SchedulerSettings scheduler_settings(layer_tree_host_->settings()); | 92 SchedulerSettings scheduler_settings(layer_tree_host_->settings()); |
| 93 // SingleThreadProxy should run in main thread low latency mode. |
| 94 scheduler_settings.main_thread_should_always_be_low_latency = true; | 94 scheduler_settings.main_thread_should_always_be_low_latency = true; |
| 95 scheduler_on_impl_thread_ = | 95 scheduler_on_impl_thread_ = |
| 96 Scheduler::Create(this, | 96 Scheduler::Create(this, |
| 97 scheduler_settings, | 97 scheduler_settings, |
| 98 layer_tree_host_->id(), | 98 layer_tree_host_->id(), |
| 99 MainThreadTaskRunner(), | 99 MainThreadTaskRunner(), |
| 100 base::PowerMonitor::Get(), | 100 base::PowerMonitor::Get(), |
| 101 external_begin_frame_source_.Pass()); | 101 external_begin_frame_source_.Pass()); |
| 102 scheduler_on_impl_thread_->SetCanStart(); | 102 scheduler_on_impl_thread_->SetCanStart(); |
| 103 scheduler_on_impl_thread_->SetVisible(layer_tree_host_impl_->visible()); | 103 scheduler_on_impl_thread_->SetVisible(layer_tree_host_impl_->visible()); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 128 if (output_surface_creation_requested_) | 128 if (output_surface_creation_requested_) |
| 129 return; | 129 return; |
| 130 output_surface_creation_requested_ = true; | 130 output_surface_creation_requested_ = true; |
| 131 layer_tree_host_->RequestNewOutputSurface(); | 131 layer_tree_host_->RequestNewOutputSurface(); |
| 132 } | 132 } |
| 133 | 133 |
| 134 void SingleThreadProxy::SetOutputSurface( | 134 void SingleThreadProxy::SetOutputSurface( |
| 135 scoped_ptr<OutputSurface> output_surface) { | 135 scoped_ptr<OutputSurface> output_surface) { |
| 136 DCHECK(Proxy::IsMainThread()); | 136 DCHECK(Proxy::IsMainThread()); |
| 137 DCHECK(layer_tree_host_->output_surface_lost()); | 137 DCHECK(layer_tree_host_->output_surface_lost()); |
| 138 output_surface_creation_requested_ = false; | 138 DCHECK(output_surface_creation_requested_); |
| 139 renderer_capabilities_for_main_thread_ = RendererCapabilities(); | 139 renderer_capabilities_for_main_thread_ = RendererCapabilities(); |
| 140 | 140 |
| 141 bool success; | 141 bool success; |
| 142 { | 142 { |
| 143 DebugScopedSetMainThreadBlocked main_thread_blocked(this); | 143 DebugScopedSetMainThreadBlocked main_thread_blocked(this); |
| 144 DebugScopedSetImplThread impl(this); | 144 DebugScopedSetImplThread impl(this); |
| 145 layer_tree_host_->DeleteContentsTexturesOnImplThread( | 145 layer_tree_host_->DeleteContentsTexturesOnImplThread( |
| 146 layer_tree_host_impl_->resource_provider()); | 146 layer_tree_host_impl_->resource_provider()); |
| 147 success = layer_tree_host_impl_->InitializeRenderer(output_surface.Pass()); | 147 success = layer_tree_host_impl_->InitializeRenderer(output_surface.Pass()); |
| 148 } | 148 } |
| 149 | 149 |
| 150 if (success) { | 150 if (success) { |
| 151 layer_tree_host_->DidInitializeOutputSurface(); | 151 layer_tree_host_->DidInitializeOutputSurface(); |
| 152 if (scheduler_on_impl_thread_) | 152 if (scheduler_on_impl_thread_) |
| 153 scheduler_on_impl_thread_->DidCreateAndInitializeOutputSurface(); | 153 scheduler_on_impl_thread_->DidCreateAndInitializeOutputSurface(); |
| 154 else if (!inside_synchronous_composite_) | 154 else if (!inside_synchronous_composite_) |
| 155 SetNeedsCommit(); | 155 SetNeedsCommit(); |
| 156 output_surface_creation_requested_ = false; |
| 156 } else { | 157 } else { |
| 158 // DidFailToInitializeOutputSurface is treated as a RequestNewOutputSurface, |
| 159 // and so output_surface_creation_requested remains true. |
| 157 layer_tree_host_->DidFailToInitializeOutputSurface(); | 160 layer_tree_host_->DidFailToInitializeOutputSurface(); |
| 158 } | 161 } |
| 159 } | 162 } |
| 160 | 163 |
| 161 const RendererCapabilities& SingleThreadProxy::GetRendererCapabilities() const { | 164 const RendererCapabilities& SingleThreadProxy::GetRendererCapabilities() const { |
| 162 DCHECK(Proxy::IsMainThread()); | 165 DCHECK(Proxy::IsMainThread()); |
| 163 DCHECK(!layer_tree_host_->output_surface_lost()); | 166 DCHECK(!layer_tree_host_->output_surface_lost()); |
| 164 return renderer_capabilities_for_main_thread_; | 167 return renderer_capabilities_for_main_thread_; |
| 165 } | 168 } |
| 166 | 169 |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 302 return; | 305 return; |
| 303 if (defer_commits_ == defer_commits) | 306 if (defer_commits_ == defer_commits) |
| 304 return; | 307 return; |
| 305 | 308 |
| 306 if (defer_commits) | 309 if (defer_commits) |
| 307 TRACE_EVENT_ASYNC_BEGIN0("cc", "SingleThreadProxy::SetDeferCommits", this); | 310 TRACE_EVENT_ASYNC_BEGIN0("cc", "SingleThreadProxy::SetDeferCommits", this); |
| 308 else | 311 else |
| 309 TRACE_EVENT_ASYNC_END0("cc", "SingleThreadProxy::SetDeferCommits", this); | 312 TRACE_EVENT_ASYNC_END0("cc", "SingleThreadProxy::SetDeferCommits", this); |
| 310 | 313 |
| 311 defer_commits_ = defer_commits; | 314 defer_commits_ = defer_commits; |
| 312 if (!defer_commits_ && commit_was_deferred_) { | 315 scheduler_on_impl_thread_->SetDeferCommits(defer_commits); |
| 313 commit_was_deferred_ = false; | |
| 314 BeginMainFrame(); | |
| 315 } | |
| 316 } | 316 } |
| 317 | 317 |
| 318 bool SingleThreadProxy::CommitRequested() const { | 318 bool SingleThreadProxy::CommitRequested() const { |
| 319 DCHECK(Proxy::IsMainThread()); | 319 DCHECK(Proxy::IsMainThread()); |
| 320 return commit_requested_; | 320 return commit_requested_; |
| 321 } | 321 } |
| 322 | 322 |
| 323 bool SingleThreadProxy::BeginMainFrameRequested() const { | 323 bool SingleThreadProxy::BeginMainFrameRequested() const { |
| 324 DCHECK(Proxy::IsMainThread()); | 324 DCHECK(Proxy::IsMainThread()); |
| 325 // If there is no scheduler, then there can be no pending begin frame, | 325 // If there is no scheduler, then there can be no pending begin frame, |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 427 bool SingleThreadProxy::IsInsideDraw() { return inside_draw_; } | 427 bool SingleThreadProxy::IsInsideDraw() { return inside_draw_; } |
| 428 | 428 |
| 429 void SingleThreadProxy::DidActivateSyncTree() { | 429 void SingleThreadProxy::DidActivateSyncTree() { |
| 430 // Non-impl-side painting finishes commit in DoCommit. Impl-side painting | 430 // Non-impl-side painting finishes commit in DoCommit. Impl-side painting |
| 431 // defers until here to simulate SetNextCommitWaitsForActivation. | 431 // defers until here to simulate SetNextCommitWaitsForActivation. |
| 432 if (layer_tree_host_impl_->settings().impl_side_painting) { | 432 if (layer_tree_host_impl_->settings().impl_side_painting) { |
| 433 // This is required because NotifyReadyToActivate gets called when | 433 // This is required because NotifyReadyToActivate gets called when |
| 434 // the pending tree is not actually ready in the SingleThreadProxy. | 434 // the pending tree is not actually ready in the SingleThreadProxy. |
| 435 layer_tree_host_impl_->SetRequiresHighResToDraw(); | 435 layer_tree_host_impl_->SetRequiresHighResToDraw(); |
| 436 | 436 |
| 437 // Synchronously call to CommitComplete. Resetting |
| 438 // |commit_blocking_task_runner| would make sure all tasks posted during |
| 439 // commit/activation before CommitComplete. |
| 437 CommitComplete(); | 440 CommitComplete(); |
| 438 } | 441 } |
| 439 | 442 |
| 440 timing_history_.DidActivateSyncTree(); | 443 timing_history_.DidActivateSyncTree(); |
| 441 } | 444 } |
| 442 | 445 |
| 443 void SingleThreadProxy::DidPrepareTiles() { | 446 void SingleThreadProxy::DidPrepareTiles() { |
| 444 DCHECK(layer_tree_host_impl_->settings().impl_side_painting); | 447 DCHECK(layer_tree_host_impl_->settings().impl_side_painting); |
| 445 DCHECK(Proxy::IsImplThread()); | 448 DCHECK(Proxy::IsImplThread()); |
| 446 if (scheduler_on_impl_thread_) | 449 if (scheduler_on_impl_thread_) |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 666 // ThreadProxy::SetNeedsCommit where SetNeedsCommit will not cause a | 669 // ThreadProxy::SetNeedsCommit where SetNeedsCommit will not cause a |
| 667 // synchronous commit. | 670 // synchronous commit. |
| 668 MainThreadTaskRunner()->PostTask( | 671 MainThreadTaskRunner()->PostTask( |
| 669 FROM_HERE, | 672 FROM_HERE, |
| 670 base::Bind(&SingleThreadProxy::BeginMainFrame, | 673 base::Bind(&SingleThreadProxy::BeginMainFrame, |
| 671 weak_factory_.GetWeakPtr())); | 674 weak_factory_.GetWeakPtr())); |
| 672 } | 675 } |
| 673 | 676 |
| 674 void SingleThreadProxy::BeginMainFrame() { | 677 void SingleThreadProxy::BeginMainFrame() { |
| 675 if (defer_commits_) { | 678 if (defer_commits_) { |
| 676 DCHECK(!commit_was_deferred_); | 679 TRACE_EVENT_INSTANT0("cc", "EarlyOut_DeferCommit", |
| 677 commit_was_deferred_ = true; | 680 TRACE_EVENT_SCOPE_THREAD); |
| 678 layer_tree_host_->DidDeferCommit(); | 681 BeginMainFrameAbortedOnImplThread( |
| 682 CommitEarlyOutReason::ABORTED_DEFERRED_COMMIT); |
| 679 return; | 683 return; |
| 680 } | 684 } |
| 681 | 685 |
| 682 // This checker assumes NotifyReadyToCommit in this stack causes a synchronous | 686 // This checker assumes NotifyReadyToCommit in this stack causes a synchronous |
| 683 // commit. | 687 // commit. |
| 684 ScopedAbortRemainingSwapPromises swap_promise_checker(layer_tree_host_); | 688 ScopedAbortRemainingSwapPromises swap_promise_checker(layer_tree_host_); |
| 685 | 689 |
| 686 if (!layer_tree_host_->visible()) { | 690 if (!layer_tree_host_->visible()) { |
| 687 TRACE_EVENT_INSTANT0("cc", "EarlyOut_NotVisible", TRACE_EVENT_SCOPE_THREAD); | 691 TRACE_EVENT_INSTANT0("cc", "EarlyOut_NotVisible", TRACE_EVENT_SCOPE_THREAD); |
| 688 BeginMainFrameAbortedOnImplThread( | 692 BeginMainFrameAbortedOnImplThread( |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 811 | 815 |
| 812 void SingleThreadProxy::DidBeginImplFrameDeadline() { | 816 void SingleThreadProxy::DidBeginImplFrameDeadline() { |
| 813 layer_tree_host_impl_->ResetCurrentBeginFrameArgsForNextFrame(); | 817 layer_tree_host_impl_->ResetCurrentBeginFrameArgsForNextFrame(); |
| 814 } | 818 } |
| 815 | 819 |
| 816 void SingleThreadProxy::SendBeginFramesToChildren(const BeginFrameArgs& args) { | 820 void SingleThreadProxy::SendBeginFramesToChildren(const BeginFrameArgs& args) { |
| 817 layer_tree_host_->SendBeginFramesToChildren(args); | 821 layer_tree_host_->SendBeginFramesToChildren(args); |
| 818 } | 822 } |
| 819 | 823 |
| 820 } // namespace cc | 824 } // namespace cc |
| OLD | NEW |