| 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/profiler/scoped_tracker.h" | 8 #include "base/profiler/scoped_tracker.h" |
| 9 #include "base/trace_event/trace_event.h" | 9 #include "base/trace_event/trace_event.h" |
| 10 #include "cc/debug/benchmark_instrumentation.h" | 10 #include "cc/debug/benchmark_instrumentation.h" |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 } | 34 } |
| 35 | 35 |
| 36 SingleThreadProxy::SingleThreadProxy( | 36 SingleThreadProxy::SingleThreadProxy( |
| 37 LayerTreeHost* layer_tree_host, | 37 LayerTreeHost* layer_tree_host, |
| 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()), | |
| 45 next_frame_is_newly_committed_frame_(false), | 44 next_frame_is_newly_committed_frame_(false), |
| 46 #if DCHECK_IS_ON() | 45 #if DCHECK_IS_ON() |
| 47 inside_impl_frame_(false), | 46 inside_impl_frame_(false), |
| 48 #endif | 47 #endif |
| 49 inside_draw_(false), | 48 inside_draw_(false), |
| 50 defer_commits_(false), | 49 defer_commits_(false), |
| 51 animate_requested_(false), | 50 animate_requested_(false), |
| 52 commit_requested_(false), | 51 commit_requested_(false), |
| 53 inside_synchronous_composite_(false), | 52 inside_synchronous_composite_(false), |
| 54 output_surface_creation_requested_(false), | 53 output_surface_creation_requested_(false), |
| 55 weak_factory_(this) { | 54 weak_factory_(this) { |
| 56 TRACE_EVENT0("cc", "SingleThreadProxy::SingleThreadProxy"); | 55 TRACE_EVENT0("cc", "SingleThreadProxy::SingleThreadProxy"); |
| 57 DCHECK(Proxy::IsMainThread()); | 56 DCHECK(Proxy::IsMainThread()); |
| 58 DCHECK(layer_tree_host); | 57 DCHECK(layer_tree_host); |
| 59 | 58 |
| 60 if (layer_tree_host->settings().single_thread_proxy_scheduler && | 59 if (layer_tree_host->settings().single_thread_proxy_scheduler && |
| 61 !scheduler_on_impl_thread_) { | 60 !scheduler_on_impl_thread_) { |
| 62 SchedulerSettings scheduler_settings( | 61 SchedulerSettings scheduler_settings( |
| 63 layer_tree_host->settings().ToSchedulerSettings()); | 62 layer_tree_host->settings().ToSchedulerSettings()); |
| 64 // SingleThreadProxy should run in main thread low latency mode. | 63 // SingleThreadProxy should run in main thread low latency mode. |
| 65 scheduler_settings.main_thread_should_always_be_low_latency = true; | 64 scheduler_settings.main_thread_should_always_be_low_latency = true; |
| 66 scheduler_on_impl_thread_ = Scheduler::Create( | 65 scheduler_on_impl_thread_ = Scheduler::Create( |
| 67 this, scheduler_settings, layer_tree_host_->id(), | 66 this, scheduler_settings, layer_tree_host_->id(), |
| 68 MainThreadTaskRunner(), external_begin_frame_source.Pass()); | 67 MainThreadTaskRunner(), external_begin_frame_source.Pass(), |
| 68 layer_tree_host->rendering_stats_instrumentation()); |
| 69 } | 69 } |
| 70 } | 70 } |
| 71 | 71 |
| 72 void SingleThreadProxy::Start() { | 72 void SingleThreadProxy::Start() { |
| 73 DebugScopedSetImplThread impl(this); | 73 DebugScopedSetImplThread impl(this); |
| 74 layer_tree_host_impl_ = layer_tree_host_->CreateLayerTreeHostImpl(this); | 74 layer_tree_host_impl_ = layer_tree_host_->CreateLayerTreeHostImpl(this); |
| 75 } | 75 } |
| 76 | 76 |
| 77 SingleThreadProxy::~SingleThreadProxy() { | 77 SingleThreadProxy::~SingleThreadProxy() { |
| 78 TRACE_EVENT0("cc", "SingleThreadProxy::~SingleThreadProxy"); | 78 TRACE_EVENT0("cc", "SingleThreadProxy::~SingleThreadProxy"); |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 285 DCHECK(commit_blocking_task_runner_); | 285 DCHECK(commit_blocking_task_runner_); |
| 286 | 286 |
| 287 // Notify commit complete on the impl side after activate to satisfy any | 287 // Notify commit complete on the impl side after activate to satisfy any |
| 288 // SetNextCommitWaitsForActivation calls. | 288 // SetNextCommitWaitsForActivation calls. |
| 289 layer_tree_host_impl_->CommitComplete(); | 289 layer_tree_host_impl_->CommitComplete(); |
| 290 | 290 |
| 291 DebugScopedSetMainThread main(this); | 291 DebugScopedSetMainThread main(this); |
| 292 commit_blocking_task_runner_.reset(); | 292 commit_blocking_task_runner_.reset(); |
| 293 layer_tree_host_->CommitComplete(); | 293 layer_tree_host_->CommitComplete(); |
| 294 layer_tree_host_->DidBeginMainFrame(); | 294 layer_tree_host_->DidBeginMainFrame(); |
| 295 timing_history_.DidCommit(); | |
| 296 | 295 |
| 297 next_frame_is_newly_committed_frame_ = true; | 296 next_frame_is_newly_committed_frame_ = true; |
| 298 } | 297 } |
| 299 | 298 |
| 300 void SingleThreadProxy::SetNeedsCommit() { | 299 void SingleThreadProxy::SetNeedsCommit() { |
| 301 DCHECK(Proxy::IsMainThread()); | 300 DCHECK(Proxy::IsMainThread()); |
| 302 client_->ScheduleComposite(); | 301 client_->ScheduleComposite(); |
| 303 if (commit_requested_) | 302 if (commit_requested_) |
| 304 return; | 303 return; |
| 305 commit_requested_ = true; | 304 commit_requested_ = true; |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 441 void SingleThreadProxy::DidActivateSyncTree() { | 440 void SingleThreadProxy::DidActivateSyncTree() { |
| 442 // This is required because NotifyReadyToActivate gets called immediately | 441 // This is required because NotifyReadyToActivate gets called immediately |
| 443 // after commit since single thread commits directly to the active tree. | 442 // after commit since single thread commits directly to the active tree. |
| 444 if (scheduler_on_impl_thread_) | 443 if (scheduler_on_impl_thread_) |
| 445 scheduler_on_impl_thread_->SetWaitForReadyToDraw(); | 444 scheduler_on_impl_thread_->SetWaitForReadyToDraw(); |
| 446 | 445 |
| 447 // Synchronously call to CommitComplete. Resetting | 446 // Synchronously call to CommitComplete. Resetting |
| 448 // |commit_blocking_task_runner| would make sure all tasks posted during | 447 // |commit_blocking_task_runner| would make sure all tasks posted during |
| 449 // commit/activation before CommitComplete. | 448 // commit/activation before CommitComplete. |
| 450 CommitComplete(); | 449 CommitComplete(); |
| 451 | |
| 452 timing_history_.DidActivateSyncTree(); | |
| 453 } | 450 } |
| 454 | 451 |
| 455 void SingleThreadProxy::DidPrepareTiles() { | 452 void SingleThreadProxy::DidPrepareTiles() { |
| 456 DCHECK(Proxy::IsImplThread()); | 453 DCHECK(Proxy::IsImplThread()); |
| 457 if (scheduler_on_impl_thread_) | 454 if (scheduler_on_impl_thread_) |
| 458 scheduler_on_impl_thread_->DidPrepareTiles(); | 455 scheduler_on_impl_thread_->DidPrepareTiles(); |
| 459 } | 456 } |
| 460 | 457 |
| 461 void SingleThreadProxy::DidCompletePageScaleAnimationOnImplThread() { | 458 void SingleThreadProxy::DidCompletePageScaleAnimationOnImplThread() { |
| 462 layer_tree_host_->DidCompletePageScaleAnimation(); | 459 layer_tree_host_->DidCompletePageScaleAnimation(); |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 632 "461509 SingleThreadProxy::DoComposite1")); | 629 "461509 SingleThreadProxy::DoComposite1")); |
| 633 | 630 |
| 634 // We guard PrepareToDraw() with CanDraw() because it always returns a valid | 631 // We guard PrepareToDraw() with CanDraw() because it always returns a valid |
| 635 // frame, so can only be used when such a frame is possible. Since | 632 // frame, so can only be used when such a frame is possible. Since |
| 636 // DrawLayers() depends on the result of PrepareToDraw(), it is guarded on | 633 // DrawLayers() depends on the result of PrepareToDraw(), it is guarded on |
| 637 // CanDraw() as well. | 634 // CanDraw() as well. |
| 638 if (!ShouldComposite()) { | 635 if (!ShouldComposite()) { |
| 639 return DRAW_ABORTED_CANT_DRAW; | 636 return DRAW_ABORTED_CANT_DRAW; |
| 640 } | 637 } |
| 641 | 638 |
| 642 timing_history_.DidStartDrawing(); | |
| 643 | |
| 644 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/461509 | 639 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/461509 |
| 645 // is fixed. | 640 // is fixed. |
| 646 tracked_objects::ScopedTracker tracking_profile2( | 641 tracked_objects::ScopedTracker tracking_profile2( |
| 647 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 642 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 648 "461509 SingleThreadProxy::DoComposite2")); | 643 "461509 SingleThreadProxy::DoComposite2")); |
| 649 draw_result = layer_tree_host_impl_->PrepareToDraw(frame); | 644 draw_result = layer_tree_host_impl_->PrepareToDraw(frame); |
| 650 draw_frame = draw_result == DRAW_SUCCESS; | 645 draw_frame = draw_result == DRAW_SUCCESS; |
| 651 if (draw_frame) { | 646 if (draw_frame) { |
| 652 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/461509 | 647 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/461509 |
| 653 // is fixed. | 648 // is fixed. |
| (...skipping 15 matching lines...) Expand all Loading... |
| 669 tracked_objects::ScopedTracker tracking_profile5( | 664 tracked_objects::ScopedTracker tracking_profile5( |
| 670 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 665 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 671 "461509 SingleThreadProxy::DoComposite5")); | 666 "461509 SingleThreadProxy::DoComposite5")); |
| 672 layer_tree_host_impl_->UpdateAnimationState(start_ready_animations); | 667 layer_tree_host_impl_->UpdateAnimationState(start_ready_animations); |
| 673 | 668 |
| 674 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/461509 | 669 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/461509 |
| 675 // is fixed. | 670 // is fixed. |
| 676 tracked_objects::ScopedTracker tracking_profile7( | 671 tracked_objects::ScopedTracker tracking_profile7( |
| 677 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 672 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 678 "461509 SingleThreadProxy::DoComposite7")); | 673 "461509 SingleThreadProxy::DoComposite7")); |
| 679 timing_history_.DidFinishDrawing(); | |
| 680 } | 674 } |
| 681 | 675 |
| 682 if (draw_frame) { | 676 if (draw_frame) { |
| 683 DebugScopedSetImplThread impl(this); | 677 DebugScopedSetImplThread impl(this); |
| 684 | 678 |
| 685 // This CapturePostTasks should be destroyed before | 679 // This CapturePostTasks should be destroyed before |
| 686 // DidCommitAndDrawFrame() is called since that goes out to the | 680 // DidCommitAndDrawFrame() is called since that goes out to the |
| 687 // embedder, | 681 // embedder, |
| 688 // and we want the embedder to receive its callbacks before that. | 682 // and we want the embedder to receive its callbacks before that. |
| 689 // NOTE: This maintains consistent ordering with the ThreadProxy since | 683 // NOTE: This maintains consistent ordering with the ThreadProxy since |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 816 layer_tree_host_->WillBeginMainFrame(); | 810 layer_tree_host_->WillBeginMainFrame(); |
| 817 layer_tree_host_->BeginMainFrame(begin_frame_args); | 811 layer_tree_host_->BeginMainFrame(begin_frame_args); |
| 818 layer_tree_host_->AnimateLayers(begin_frame_args.frame_time); | 812 layer_tree_host_->AnimateLayers(begin_frame_args.frame_time); |
| 819 layer_tree_host_->Layout(); | 813 layer_tree_host_->Layout(); |
| 820 | 814 |
| 821 // New commits requested inside UpdateLayers should be respected. | 815 // New commits requested inside UpdateLayers should be respected. |
| 822 commit_requested_ = false; | 816 commit_requested_ = false; |
| 823 | 817 |
| 824 layer_tree_host_->UpdateLayers(); | 818 layer_tree_host_->UpdateLayers(); |
| 825 | 819 |
| 826 timing_history_.DidBeginMainFrame(); | |
| 827 | |
| 828 // TODO(enne): SingleThreadProxy does not support cancelling commits yet, | 820 // TODO(enne): SingleThreadProxy does not support cancelling commits yet, |
| 829 // search for CommitEarlyOutReason::FINISHED_NO_UPDATES inside | 821 // search for CommitEarlyOutReason::FINISHED_NO_UPDATES inside |
| 830 // thread_proxy.cc | 822 // thread_proxy.cc |
| 831 if (scheduler_on_impl_thread_) { | 823 if (scheduler_on_impl_thread_) { |
| 832 scheduler_on_impl_thread_->NotifyBeginMainFrameStarted(); | 824 scheduler_on_impl_thread_->NotifyBeginMainFrameStarted(); |
| 833 scheduler_on_impl_thread_->NotifyReadyToCommit(); | 825 scheduler_on_impl_thread_->NotifyReadyToCommit(); |
| 834 } | 826 } |
| 835 } | 827 } |
| 836 | 828 |
| 837 void SingleThreadProxy::BeginMainFrameAbortedOnImplThread( | 829 void SingleThreadProxy::BeginMainFrameAbortedOnImplThread( |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 888 void SingleThreadProxy::ScheduledActionPrepareTiles() { | 880 void SingleThreadProxy::ScheduledActionPrepareTiles() { |
| 889 TRACE_EVENT0("cc", "SingleThreadProxy::ScheduledActionPrepareTiles"); | 881 TRACE_EVENT0("cc", "SingleThreadProxy::ScheduledActionPrepareTiles"); |
| 890 DebugScopedSetImplThread impl(this); | 882 DebugScopedSetImplThread impl(this); |
| 891 layer_tree_host_impl_->PrepareTiles(); | 883 layer_tree_host_impl_->PrepareTiles(); |
| 892 } | 884 } |
| 893 | 885 |
| 894 void SingleThreadProxy::ScheduledActionInvalidateOutputSurface() { | 886 void SingleThreadProxy::ScheduledActionInvalidateOutputSurface() { |
| 895 NOTREACHED(); | 887 NOTREACHED(); |
| 896 } | 888 } |
| 897 | 889 |
| 898 base::TimeDelta SingleThreadProxy::DrawDurationEstimate() { | |
| 899 return timing_history_.DrawDurationEstimate(); | |
| 900 } | |
| 901 | |
| 902 base::TimeDelta SingleThreadProxy::BeginMainFrameToCommitDurationEstimate() { | |
| 903 return timing_history_.BeginMainFrameToCommitDurationEstimate(); | |
| 904 } | |
| 905 | |
| 906 base::TimeDelta SingleThreadProxy::CommitToActivateDurationEstimate() { | |
| 907 return timing_history_.CommitToActivateDurationEstimate(); | |
| 908 } | |
| 909 | |
| 910 void SingleThreadProxy::DidFinishImplFrame() { | 890 void SingleThreadProxy::DidFinishImplFrame() { |
| 911 layer_tree_host_impl_->DidFinishImplFrame(); | 891 layer_tree_host_impl_->DidFinishImplFrame(); |
| 912 #if DCHECK_IS_ON() | 892 #if DCHECK_IS_ON() |
| 913 DCHECK(inside_impl_frame_) | 893 DCHECK(inside_impl_frame_) |
| 914 << "DidFinishImplFrame called while not inside an impl frame!"; | 894 << "DidFinishImplFrame called while not inside an impl frame!"; |
| 915 inside_impl_frame_ = false; | 895 inside_impl_frame_ = false; |
| 916 #endif | 896 #endif |
| 917 } | 897 } |
| 918 | 898 |
| 919 void SingleThreadProxy::SendBeginFramesToChildren(const BeginFrameArgs& args) { | 899 void SingleThreadProxy::SendBeginFramesToChildren(const BeginFrameArgs& args) { |
| 920 layer_tree_host_->SendBeginFramesToChildren(args); | 900 layer_tree_host_->SendBeginFramesToChildren(args); |
| 921 } | 901 } |
| 922 | 902 |
| 923 } // namespace cc | 903 } // namespace cc |
| OLD | NEW |