| 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/memory/ptr_util.h" |
| 8 #include "base/profiler/scoped_tracker.h" | 9 #include "base/profiler/scoped_tracker.h" |
| 9 #include "base/trace_event/trace_event.h" | 10 #include "base/trace_event/trace_event.h" |
| 10 #include "cc/animation/animation_events.h" | 11 #include "cc/animation/animation_events.h" |
| 11 #include "cc/debug/benchmark_instrumentation.h" | 12 #include "cc/debug/benchmark_instrumentation.h" |
| 12 #include "cc/debug/devtools_instrumentation.h" | 13 #include "cc/debug/devtools_instrumentation.h" |
| 13 #include "cc/output/context_provider.h" | 14 #include "cc/output/context_provider.h" |
| 14 #include "cc/output/output_surface.h" | 15 #include "cc/output/output_surface.h" |
| 15 #include "cc/quads/draw_quad.h" | 16 #include "cc/quads/draw_quad.h" |
| 16 #include "cc/scheduler/commit_earlyout_reason.h" | 17 #include "cc/scheduler/commit_earlyout_reason.h" |
| 17 #include "cc/scheduler/compositor_timing_history.h" | 18 #include "cc/scheduler/compositor_timing_history.h" |
| 18 #include "cc/scheduler/scheduler.h" | 19 #include "cc/scheduler/scheduler.h" |
| 19 #include "cc/trees/layer_tree_host.h" | 20 #include "cc/trees/layer_tree_host.h" |
| 20 #include "cc/trees/layer_tree_host_common.h" | 21 #include "cc/trees/layer_tree_host_common.h" |
| 21 #include "cc/trees/layer_tree_host_single_thread_client.h" | 22 #include "cc/trees/layer_tree_host_single_thread_client.h" |
| 22 #include "cc/trees/layer_tree_impl.h" | 23 #include "cc/trees/layer_tree_impl.h" |
| 23 #include "cc/trees/scoped_abort_remaining_swap_promises.h" | 24 #include "cc/trees/scoped_abort_remaining_swap_promises.h" |
| 24 | 25 |
| 25 namespace cc { | 26 namespace cc { |
| 26 | 27 |
| 27 scoped_ptr<Proxy> SingleThreadProxy::Create( | 28 std::unique_ptr<Proxy> SingleThreadProxy::Create( |
| 28 LayerTreeHost* layer_tree_host, | 29 LayerTreeHost* layer_tree_host, |
| 29 LayerTreeHostSingleThreadClient* client, | 30 LayerTreeHostSingleThreadClient* client, |
| 30 TaskRunnerProvider* task_runner_provider) { | 31 TaskRunnerProvider* task_runner_provider) { |
| 31 return make_scoped_ptr( | 32 return base::WrapUnique( |
| 32 new SingleThreadProxy(layer_tree_host, client, task_runner_provider)); | 33 new SingleThreadProxy(layer_tree_host, client, task_runner_provider)); |
| 33 } | 34 } |
| 34 | 35 |
| 35 SingleThreadProxy::SingleThreadProxy(LayerTreeHost* layer_tree_host, | 36 SingleThreadProxy::SingleThreadProxy(LayerTreeHost* layer_tree_host, |
| 36 LayerTreeHostSingleThreadClient* client, | 37 LayerTreeHostSingleThreadClient* client, |
| 37 TaskRunnerProvider* task_runner_provider) | 38 TaskRunnerProvider* task_runner_provider) |
| 38 : layer_tree_host_(layer_tree_host), | 39 : layer_tree_host_(layer_tree_host), |
| 39 client_(client), | 40 client_(client), |
| 40 task_runner_provider_(task_runner_provider), | 41 task_runner_provider_(task_runner_provider), |
| 41 next_frame_is_newly_committed_frame_(false), | 42 next_frame_is_newly_committed_frame_(false), |
| 42 #if DCHECK_IS_ON() | 43 #if DCHECK_IS_ON() |
| 43 inside_impl_frame_(false), | 44 inside_impl_frame_(false), |
| 44 #endif | 45 #endif |
| 45 inside_draw_(false), | 46 inside_draw_(false), |
| 46 defer_commits_(false), | 47 defer_commits_(false), |
| 47 animate_requested_(false), | 48 animate_requested_(false), |
| 48 commit_requested_(false), | 49 commit_requested_(false), |
| 49 inside_synchronous_composite_(false), | 50 inside_synchronous_composite_(false), |
| 50 output_surface_creation_requested_(false), | 51 output_surface_creation_requested_(false), |
| 51 weak_factory_(this) { | 52 weak_factory_(this) { |
| 52 TRACE_EVENT0("cc", "SingleThreadProxy::SingleThreadProxy"); | 53 TRACE_EVENT0("cc", "SingleThreadProxy::SingleThreadProxy"); |
| 53 DCHECK(task_runner_provider_); | 54 DCHECK(task_runner_provider_); |
| 54 DCHECK(task_runner_provider_->IsMainThread()); | 55 DCHECK(task_runner_provider_->IsMainThread()); |
| 55 DCHECK(layer_tree_host); | 56 DCHECK(layer_tree_host); |
| 56 } | 57 } |
| 57 | 58 |
| 58 void SingleThreadProxy::Start( | 59 void SingleThreadProxy::Start( |
| 59 scoped_ptr<BeginFrameSource> external_begin_frame_source) { | 60 std::unique_ptr<BeginFrameSource> external_begin_frame_source) { |
| 60 DebugScopedSetImplThread impl(task_runner_provider_); | 61 DebugScopedSetImplThread impl(task_runner_provider_); |
| 61 external_begin_frame_source_ = std::move(external_begin_frame_source); | 62 external_begin_frame_source_ = std::move(external_begin_frame_source); |
| 62 | 63 |
| 63 if (layer_tree_host_->settings().single_thread_proxy_scheduler && | 64 if (layer_tree_host_->settings().single_thread_proxy_scheduler && |
| 64 !scheduler_on_impl_thread_) { | 65 !scheduler_on_impl_thread_) { |
| 65 SchedulerSettings scheduler_settings( | 66 SchedulerSettings scheduler_settings( |
| 66 layer_tree_host_->settings().ToSchedulerSettings()); | 67 layer_tree_host_->settings().ToSchedulerSettings()); |
| 67 scheduler_settings.commit_to_active_tree = CommitToActiveTree(); | 68 scheduler_settings.commit_to_active_tree = CommitToActiveTree(); |
| 68 | 69 |
| 69 scoped_ptr<CompositorTimingHistory> compositor_timing_history( | 70 std::unique_ptr<CompositorTimingHistory> compositor_timing_history( |
| 70 new CompositorTimingHistory( | 71 new CompositorTimingHistory( |
| 71 scheduler_settings.using_synchronous_renderer_compositor, | 72 scheduler_settings.using_synchronous_renderer_compositor, |
| 72 CompositorTimingHistory::BROWSER_UMA, | 73 CompositorTimingHistory::BROWSER_UMA, |
| 73 layer_tree_host_->rendering_stats_instrumentation())); | 74 layer_tree_host_->rendering_stats_instrumentation())); |
| 74 | 75 |
| 75 BeginFrameSource* frame_source = external_begin_frame_source_.get(); | 76 BeginFrameSource* frame_source = external_begin_frame_source_.get(); |
| 76 if (!scheduler_settings.throttle_frame_production) { | 77 if (!scheduler_settings.throttle_frame_production) { |
| 77 // Unthrottled source takes precedence over external sources. | 78 // Unthrottled source takes precedence over external sources. |
| 78 unthrottled_begin_frame_source_.reset(new BackToBackBeginFrameSource( | 79 unthrottled_begin_frame_source_.reset(new BackToBackBeginFrameSource( |
| 79 task_runner_provider_->MainThreadTaskRunner())); | 80 task_runner_provider_->MainThreadTaskRunner())); |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/461509 | 244 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/461509 |
| 244 // is fixed. | 245 // is fixed. |
| 245 tracked_objects::ScopedTracker tracking_profile7( | 246 tracked_objects::ScopedTracker tracking_profile7( |
| 246 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 247 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 247 "461509 SingleThreadProxy::DoCommit7")); | 248 "461509 SingleThreadProxy::DoCommit7")); |
| 248 layer_tree_host_->FinishCommitOnImplThread(layer_tree_host_impl_.get()); | 249 layer_tree_host_->FinishCommitOnImplThread(layer_tree_host_impl_.get()); |
| 249 | 250 |
| 250 #if DCHECK_IS_ON() | 251 #if DCHECK_IS_ON() |
| 251 // In the single-threaded case, the scale and scroll deltas should never be | 252 // In the single-threaded case, the scale and scroll deltas should never be |
| 252 // touched on the impl layer tree. | 253 // touched on the impl layer tree. |
| 253 scoped_ptr<ScrollAndScaleSet> scroll_info = | 254 std::unique_ptr<ScrollAndScaleSet> scroll_info = |
| 254 layer_tree_host_impl_->ProcessScrollDeltas(); | 255 layer_tree_host_impl_->ProcessScrollDeltas(); |
| 255 DCHECK(!scroll_info->scrolls.size()); | 256 DCHECK(!scroll_info->scrolls.size()); |
| 256 DCHECK_EQ(1.f, scroll_info->page_scale_delta); | 257 DCHECK_EQ(1.f, scroll_info->page_scale_delta); |
| 257 #endif | 258 #endif |
| 258 | 259 |
| 259 if (scheduler_on_impl_thread_) | 260 if (scheduler_on_impl_thread_) |
| 260 scheduler_on_impl_thread_->DidCommit(); | 261 scheduler_on_impl_thread_->DidCommit(); |
| 261 | 262 |
| 262 layer_tree_host_impl_->CommitComplete(); | 263 layer_tree_host_impl_->CommitComplete(); |
| 263 | 264 |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 416 | 417 |
| 417 void SingleThreadProxy::SetVideoNeedsBeginFrames(bool needs_begin_frames) { | 418 void SingleThreadProxy::SetVideoNeedsBeginFrames(bool needs_begin_frames) { |
| 418 TRACE_EVENT1("cc", "SingleThreadProxy::SetVideoNeedsBeginFrames", | 419 TRACE_EVENT1("cc", "SingleThreadProxy::SetVideoNeedsBeginFrames", |
| 419 "needs_begin_frames", needs_begin_frames); | 420 "needs_begin_frames", needs_begin_frames); |
| 420 // In tests the layer tree is destroyed after the scheduler is. | 421 // In tests the layer tree is destroyed after the scheduler is. |
| 421 if (scheduler_on_impl_thread_) | 422 if (scheduler_on_impl_thread_) |
| 422 scheduler_on_impl_thread_->SetVideoNeedsBeginFrames(needs_begin_frames); | 423 scheduler_on_impl_thread_->SetVideoNeedsBeginFrames(needs_begin_frames); |
| 423 } | 424 } |
| 424 | 425 |
| 425 void SingleThreadProxy::PostAnimationEventsToMainThreadOnImplThread( | 426 void SingleThreadProxy::PostAnimationEventsToMainThreadOnImplThread( |
| 426 scoped_ptr<AnimationEvents> events) { | 427 std::unique_ptr<AnimationEvents> events) { |
| 427 TRACE_EVENT0( | 428 TRACE_EVENT0( |
| 428 "cc", "SingleThreadProxy::PostAnimationEventsToMainThreadOnImplThread"); | 429 "cc", "SingleThreadProxy::PostAnimationEventsToMainThreadOnImplThread"); |
| 429 DCHECK(task_runner_provider_->IsImplThread()); | 430 DCHECK(task_runner_provider_->IsImplThread()); |
| 430 DebugScopedSetMainThread main(task_runner_provider_); | 431 DebugScopedSetMainThread main(task_runner_provider_); |
| 431 layer_tree_host_->SetAnimationEvents(std::move(events)); | 432 layer_tree_host_->SetAnimationEvents(std::move(events)); |
| 432 } | 433 } |
| 433 | 434 |
| 434 bool SingleThreadProxy::IsInsideDraw() { return inside_draw_; } | 435 bool SingleThreadProxy::IsInsideDraw() { return inside_draw_; } |
| 435 | 436 |
| 436 void SingleThreadProxy::DidActivateSyncTree() { | 437 void SingleThreadProxy::DidActivateSyncTree() { |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 509 scheduler_on_impl_thread_->DidSwapBuffersComplete(); | 510 scheduler_on_impl_thread_->DidSwapBuffersComplete(); |
| 510 layer_tree_host_->DidCompleteSwapBuffers(); | 511 layer_tree_host_->DidCompleteSwapBuffers(); |
| 511 } | 512 } |
| 512 | 513 |
| 513 void SingleThreadProxy::OnDrawForOutputSurface( | 514 void SingleThreadProxy::OnDrawForOutputSurface( |
| 514 bool resourceless_software_draw) { | 515 bool resourceless_software_draw) { |
| 515 NOTREACHED() << "Implemented by ThreadProxy for synchronous compositor."; | 516 NOTREACHED() << "Implemented by ThreadProxy for synchronous compositor."; |
| 516 } | 517 } |
| 517 | 518 |
| 518 void SingleThreadProxy::PostFrameTimingEventsOnImplThread( | 519 void SingleThreadProxy::PostFrameTimingEventsOnImplThread( |
| 519 scoped_ptr<FrameTimingTracker::CompositeTimingSet> composite_events, | 520 std::unique_ptr<FrameTimingTracker::CompositeTimingSet> composite_events, |
| 520 scoped_ptr<FrameTimingTracker::MainFrameTimingSet> main_frame_events) { | 521 std::unique_ptr<FrameTimingTracker::MainFrameTimingSet> main_frame_events) { |
| 521 layer_tree_host_->RecordFrameTimingEvents(std::move(composite_events), | 522 layer_tree_host_->RecordFrameTimingEvents(std::move(composite_events), |
| 522 std::move(main_frame_events)); | 523 std::move(main_frame_events)); |
| 523 } | 524 } |
| 524 | 525 |
| 525 void SingleThreadProxy::CompositeImmediately(base::TimeTicks frame_begin_time) { | 526 void SingleThreadProxy::CompositeImmediately(base::TimeTicks frame_begin_time) { |
| 526 TRACE_EVENT0("cc,benchmark", "SingleThreadProxy::CompositeImmediately"); | 527 TRACE_EVENT0("cc,benchmark", "SingleThreadProxy::CompositeImmediately"); |
| 527 DCHECK(task_runner_provider_->IsMainThread()); | 528 DCHECK(task_runner_provider_->IsMainThread()); |
| 528 #if DCHECK_IS_ON() | 529 #if DCHECK_IS_ON() |
| 529 DCHECK(!inside_impl_frame_); | 530 DCHECK(!inside_impl_frame_); |
| 530 #endif | 531 #endif |
| (...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 898 << "DidFinishImplFrame called while not inside an impl frame!"; | 899 << "DidFinishImplFrame called while not inside an impl frame!"; |
| 899 inside_impl_frame_ = false; | 900 inside_impl_frame_ = false; |
| 900 #endif | 901 #endif |
| 901 } | 902 } |
| 902 | 903 |
| 903 void SingleThreadProxy::SendBeginFramesToChildren(const BeginFrameArgs& args) { | 904 void SingleThreadProxy::SendBeginFramesToChildren(const BeginFrameArgs& args) { |
| 904 layer_tree_host_->SendBeginFramesToChildren(args); | 905 layer_tree_host_->SendBeginFramesToChildren(args); |
| 905 } | 906 } |
| 906 | 907 |
| 907 } // namespace cc | 908 } // namespace cc |
| OLD | NEW |