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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 : Proxy(main_task_runner, NULL), | 43 : Proxy(main_task_runner, NULL), |
44 layer_tree_host_(layer_tree_host), | 44 layer_tree_host_(layer_tree_host), |
45 client_(client), | 45 client_(client), |
46 timing_history_(layer_tree_host->rendering_stats_instrumentation()), | 46 timing_history_(layer_tree_host->rendering_stats_instrumentation()), |
47 next_frame_is_newly_committed_frame_(false), | 47 next_frame_is_newly_committed_frame_(false), |
48 inside_draw_(false), | 48 inside_draw_(false), |
49 defer_commits_(false), | 49 defer_commits_(false), |
50 commit_requested_(false), | 50 commit_requested_(false), |
51 inside_synchronous_composite_(false), | 51 inside_synchronous_composite_(false), |
52 output_surface_creation_requested_(false), | 52 output_surface_creation_requested_(false), |
53 external_begin_frame_source_(external_begin_frame_source.Pass()), | |
54 weak_factory_(this) { | 53 weak_factory_(this) { |
55 TRACE_EVENT0("cc", "SingleThreadProxy::SingleThreadProxy"); | 54 TRACE_EVENT0("cc", "SingleThreadProxy::SingleThreadProxy"); |
56 DCHECK(Proxy::IsMainThread()); | 55 DCHECK(Proxy::IsMainThread()); |
57 DCHECK(layer_tree_host); | 56 DCHECK(layer_tree_host); |
| 57 |
| 58 if (layer_tree_host->settings().single_thread_proxy_scheduler && |
| 59 !scheduler_on_impl_thread_) { |
| 60 SchedulerSettings scheduler_settings( |
| 61 layer_tree_host->settings().ToSchedulerSettings()); |
| 62 // SingleThreadProxy should run in main thread low latency mode. |
| 63 scheduler_settings.main_thread_should_always_be_low_latency = true; |
| 64 scheduler_on_impl_thread_ = Scheduler::Create( |
| 65 this, scheduler_settings, layer_tree_host_->id(), |
| 66 MainThreadTaskRunner(), external_begin_frame_source.Pass()); |
| 67 } |
58 } | 68 } |
59 | 69 |
60 void SingleThreadProxy::Start() { | 70 void SingleThreadProxy::Start() { |
61 DebugScopedSetImplThread impl(this); | 71 DebugScopedSetImplThread impl(this); |
62 layer_tree_host_impl_ = layer_tree_host_->CreateLayerTreeHostImpl(this); | 72 layer_tree_host_impl_ = layer_tree_host_->CreateLayerTreeHostImpl(this); |
63 } | 73 } |
64 | 74 |
65 SingleThreadProxy::~SingleThreadProxy() { | 75 SingleThreadProxy::~SingleThreadProxy() { |
66 TRACE_EVENT0("cc", "SingleThreadProxy::~SingleThreadProxy"); | 76 TRACE_EVENT0("cc", "SingleThreadProxy::~SingleThreadProxy"); |
67 DCHECK(Proxy::IsMainThread()); | 77 DCHECK(Proxy::IsMainThread()); |
(...skipping 20 matching lines...) Expand all Loading... |
88 // active tree. | 98 // active tree. |
89 return true; | 99 return true; |
90 } | 100 } |
91 | 101 |
92 void SingleThreadProxy::SetLayerTreeHostClientReady() { | 102 void SingleThreadProxy::SetLayerTreeHostClientReady() { |
93 TRACE_EVENT0("cc", "SingleThreadProxy::SetLayerTreeHostClientReady"); | 103 TRACE_EVENT0("cc", "SingleThreadProxy::SetLayerTreeHostClientReady"); |
94 // Scheduling is controlled by the embedder in the single thread case, so | 104 // Scheduling is controlled by the embedder in the single thread case, so |
95 // nothing to do. | 105 // nothing to do. |
96 DCHECK(Proxy::IsMainThread()); | 106 DCHECK(Proxy::IsMainThread()); |
97 DebugScopedSetImplThread impl(this); | 107 DebugScopedSetImplThread impl(this); |
98 if (layer_tree_host_->settings().single_thread_proxy_scheduler && | 108 if (scheduler_on_impl_thread_) { |
99 !scheduler_on_impl_thread_) { | |
100 SchedulerSettings scheduler_settings( | |
101 layer_tree_host_->settings().ToSchedulerSettings()); | |
102 // SingleThreadProxy should run in main thread low latency mode. | |
103 scheduler_settings.main_thread_should_always_be_low_latency = true; | |
104 scheduler_on_impl_thread_ = | |
105 Scheduler::Create(this, | |
106 scheduler_settings, | |
107 layer_tree_host_->id(), | |
108 MainThreadTaskRunner(), | |
109 external_begin_frame_source_.Pass()); | |
110 scheduler_on_impl_thread_->SetCanStart(); | 109 scheduler_on_impl_thread_->SetCanStart(); |
111 scheduler_on_impl_thread_->SetVisible(layer_tree_host_impl_->visible()); | 110 scheduler_on_impl_thread_->SetVisible(layer_tree_host_impl_->visible()); |
112 } | 111 } |
113 } | 112 } |
114 | 113 |
115 void SingleThreadProxy::SetVisible(bool visible) { | 114 void SingleThreadProxy::SetVisible(bool visible) { |
116 TRACE_EVENT1("cc", "SingleThreadProxy::SetVisible", "visible", visible); | 115 TRACE_EVENT1("cc", "SingleThreadProxy::SetVisible", "visible", visible); |
117 DebugScopedSetImplThread impl(this); | 116 DebugScopedSetImplThread impl(this); |
118 layer_tree_host_impl_->SetVisible(visible); | 117 layer_tree_host_impl_->SetVisible(visible); |
119 if (scheduler_on_impl_thread_) | 118 if (scheduler_on_impl_thread_) |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 } | 206 } |
208 | 207 |
209 void SingleThreadProxy::DoCommit() { | 208 void SingleThreadProxy::DoCommit() { |
210 TRACE_EVENT0("cc", "SingleThreadProxy::DoCommit"); | 209 TRACE_EVENT0("cc", "SingleThreadProxy::DoCommit"); |
211 DCHECK(Proxy::IsMainThread()); | 210 DCHECK(Proxy::IsMainThread()); |
212 | 211 |
213 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/461509 is | 212 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/461509 is |
214 // fixed. | 213 // fixed. |
215 tracked_objects::ScopedTracker tracking_profile1( | 214 tracked_objects::ScopedTracker tracking_profile1( |
216 FROM_HERE_WITH_EXPLICIT_FUNCTION("461509 SingleThreadProxy::DoCommit1")); | 215 FROM_HERE_WITH_EXPLICIT_FUNCTION("461509 SingleThreadProxy::DoCommit1")); |
217 commit_requested_ = false; | |
218 layer_tree_host_->WillCommit(); | 216 layer_tree_host_->WillCommit(); |
219 devtools_instrumentation::ScopedCommitTrace commit_task( | 217 devtools_instrumentation::ScopedCommitTrace commit_task( |
220 layer_tree_host_->id()); | 218 layer_tree_host_->id()); |
221 | 219 |
222 // Commit immediately. | 220 // Commit immediately. |
223 { | 221 { |
224 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/461509 | 222 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/461509 |
225 // is fixed. | 223 // is fixed. |
226 tracked_objects::ScopedTracker tracking_profile2( | 224 tracked_objects::ScopedTracker tracking_profile2( |
227 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 225 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
327 commit_blocking_task_runner_.reset(); | 325 commit_blocking_task_runner_.reset(); |
328 layer_tree_host_->CommitComplete(); | 326 layer_tree_host_->CommitComplete(); |
329 layer_tree_host_->DidBeginMainFrame(); | 327 layer_tree_host_->DidBeginMainFrame(); |
330 timing_history_.DidCommit(); | 328 timing_history_.DidCommit(); |
331 | 329 |
332 next_frame_is_newly_committed_frame_ = true; | 330 next_frame_is_newly_committed_frame_ = true; |
333 } | 331 } |
334 | 332 |
335 void SingleThreadProxy::SetNeedsCommit() { | 333 void SingleThreadProxy::SetNeedsCommit() { |
336 DCHECK(Proxy::IsMainThread()); | 334 DCHECK(Proxy::IsMainThread()); |
| 335 client_->ScheduleComposite(); |
| 336 if (commit_requested_) |
| 337 return; |
337 DebugScopedSetImplThread impl(this); | 338 DebugScopedSetImplThread impl(this); |
338 client_->ScheduleComposite(); | |
339 if (scheduler_on_impl_thread_) | 339 if (scheduler_on_impl_thread_) |
340 scheduler_on_impl_thread_->SetNeedsCommit(); | 340 scheduler_on_impl_thread_->SetNeedsCommit(); |
341 commit_requested_ = true; | 341 commit_requested_ = true; |
342 } | 342 } |
343 | 343 |
344 void SingleThreadProxy::SetNeedsRedraw(const gfx::Rect& damage_rect) { | 344 void SingleThreadProxy::SetNeedsRedraw(const gfx::Rect& damage_rect) { |
345 TRACE_EVENT0("cc", "SingleThreadProxy::SetNeedsRedraw"); | 345 TRACE_EVENT0("cc", "SingleThreadProxy::SetNeedsRedraw"); |
346 DCHECK(Proxy::IsMainThread()); | 346 DCHECK(Proxy::IsMainThread()); |
347 DebugScopedSetImplThread impl(this); | 347 DebugScopedSetImplThread impl(this); |
348 client_->ScheduleComposite(); | 348 client_->ScheduleComposite(); |
(...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
759 | 759 |
760 void SingleThreadProxy::DidCommitAndDrawFrame() { | 760 void SingleThreadProxy::DidCommitAndDrawFrame() { |
761 if (next_frame_is_newly_committed_frame_) { | 761 if (next_frame_is_newly_committed_frame_) { |
762 DebugScopedSetMainThread main(this); | 762 DebugScopedSetMainThread main(this); |
763 next_frame_is_newly_committed_frame_ = false; | 763 next_frame_is_newly_committed_frame_ = false; |
764 layer_tree_host_->DidCommitAndDrawFrame(); | 764 layer_tree_host_->DidCommitAndDrawFrame(); |
765 } | 765 } |
766 } | 766 } |
767 | 767 |
768 bool SingleThreadProxy::MainFrameWillHappenForTesting() { | 768 bool SingleThreadProxy::MainFrameWillHappenForTesting() { |
769 return false; | 769 if (layer_tree_host_->output_surface_lost()) |
| 770 return false; |
| 771 if (!scheduler_on_impl_thread_) |
| 772 return false; |
| 773 return scheduler_on_impl_thread_->MainFrameForTestingWillHappen(); |
770 } | 774 } |
771 | 775 |
772 void SingleThreadProxy::SetChildrenNeedBeginFrames( | 776 void SingleThreadProxy::SetChildrenNeedBeginFrames( |
773 bool children_need_begin_frames) { | 777 bool children_need_begin_frames) { |
774 scheduler_on_impl_thread_->SetChildrenNeedBeginFrames( | 778 scheduler_on_impl_thread_->SetChildrenNeedBeginFrames( |
775 children_need_begin_frames); | 779 children_need_begin_frames); |
776 } | 780 } |
777 | 781 |
778 void SingleThreadProxy::SetAuthoritativeVSyncInterval( | 782 void SingleThreadProxy::SetAuthoritativeVSyncInterval( |
779 const base::TimeDelta& interval) { | 783 const base::TimeDelta& interval) { |
(...skipping 17 matching lines...) Expand all Loading... |
797 FROM_HERE, | 801 FROM_HERE, |
798 base::Bind(&SingleThreadProxy::BeginMainFrame, | 802 base::Bind(&SingleThreadProxy::BeginMainFrame, |
799 weak_factory_.GetWeakPtr())); | 803 weak_factory_.GetWeakPtr())); |
800 } | 804 } |
801 | 805 |
802 void SingleThreadProxy::SendBeginMainFrameNotExpectedSoon() { | 806 void SingleThreadProxy::SendBeginMainFrameNotExpectedSoon() { |
803 layer_tree_host_->BeginMainFrameNotExpectedSoon(); | 807 layer_tree_host_->BeginMainFrameNotExpectedSoon(); |
804 } | 808 } |
805 | 809 |
806 void SingleThreadProxy::BeginMainFrame() { | 810 void SingleThreadProxy::BeginMainFrame() { |
| 811 commit_requested_ = false; |
| 812 |
807 if (defer_commits_) { | 813 if (defer_commits_) { |
808 TRACE_EVENT_INSTANT0("cc", "EarlyOut_DeferCommit", | 814 TRACE_EVENT_INSTANT0("cc", "EarlyOut_DeferCommit", |
809 TRACE_EVENT_SCOPE_THREAD); | 815 TRACE_EVENT_SCOPE_THREAD); |
810 BeginMainFrameAbortedOnImplThread( | 816 BeginMainFrameAbortedOnImplThread( |
811 CommitEarlyOutReason::ABORTED_DEFERRED_COMMIT); | 817 CommitEarlyOutReason::ABORTED_DEFERRED_COMMIT); |
812 return; | 818 return; |
813 } | 819 } |
814 | 820 |
815 // This checker assumes NotifyReadyToCommit in this stack causes a synchronous | 821 // This checker assumes NotifyReadyToCommit in this stack causes a synchronous |
816 // commit. | 822 // commit. |
817 ScopedAbortRemainingSwapPromises swap_promise_checker(layer_tree_host_); | 823 ScopedAbortRemainingSwapPromises swap_promise_checker(layer_tree_host_); |
818 | 824 |
819 if (!layer_tree_host_->visible()) { | 825 if (!layer_tree_host_->visible()) { |
820 TRACE_EVENT_INSTANT0("cc", "EarlyOut_NotVisible", TRACE_EVENT_SCOPE_THREAD); | 826 TRACE_EVENT_INSTANT0("cc", "EarlyOut_NotVisible", TRACE_EVENT_SCOPE_THREAD); |
821 BeginMainFrameAbortedOnImplThread( | 827 BeginMainFrameAbortedOnImplThread( |
822 CommitEarlyOutReason::ABORTED_NOT_VISIBLE); | 828 CommitEarlyOutReason::ABORTED_NOT_VISIBLE); |
823 return; | 829 return; |
824 } | 830 } |
825 | 831 |
826 if (layer_tree_host_->output_surface_lost()) { | 832 if (layer_tree_host_->output_surface_lost()) { |
827 TRACE_EVENT_INSTANT0( | 833 TRACE_EVENT_INSTANT0( |
828 "cc", "EarlyOut_OutputSurfaceLost", TRACE_EVENT_SCOPE_THREAD); | 834 "cc", "EarlyOut_OutputSurfaceLost", TRACE_EVENT_SCOPE_THREAD); |
829 BeginMainFrameAbortedOnImplThread( | 835 BeginMainFrameAbortedOnImplThread( |
830 CommitEarlyOutReason::ABORTED_OUTPUT_SURFACE_LOST); | 836 CommitEarlyOutReason::ABORTED_OUTPUT_SURFACE_LOST); |
831 return; | 837 return; |
832 } | 838 } |
833 | 839 |
| 840 // Prevent new commits from being requested inside DoBeginMainFrame. |
| 841 commit_requested_ = true; |
| 842 |
834 const BeginFrameArgs& begin_frame_args = | 843 const BeginFrameArgs& begin_frame_args = |
835 layer_tree_host_impl_->CurrentBeginFrameArgs(); | 844 layer_tree_host_impl_->CurrentBeginFrameArgs(); |
836 DoBeginMainFrame(begin_frame_args); | 845 DoBeginMainFrame(begin_frame_args); |
837 } | 846 } |
838 | 847 |
839 void SingleThreadProxy::DoBeginMainFrame( | 848 void SingleThreadProxy::DoBeginMainFrame( |
840 const BeginFrameArgs& begin_frame_args) { | 849 const BeginFrameArgs& begin_frame_args) { |
841 layer_tree_host_->WillBeginMainFrame(); | 850 layer_tree_host_->WillBeginMainFrame(); |
842 layer_tree_host_->BeginMainFrame(begin_frame_args); | 851 layer_tree_host_->BeginMainFrame(begin_frame_args); |
843 layer_tree_host_->AnimateLayers(begin_frame_args.frame_time); | 852 layer_tree_host_->AnimateLayers(begin_frame_args.frame_time); |
844 layer_tree_host_->Layout(); | 853 layer_tree_host_->Layout(); |
845 | 854 |
846 if (PrioritizedResourceManager* contents_texture_manager = | 855 if (PrioritizedResourceManager* contents_texture_manager = |
847 layer_tree_host_->contents_texture_manager()) { | 856 layer_tree_host_->contents_texture_manager()) { |
848 contents_texture_manager->UnlinkAndClearEvictedBackings(); | 857 contents_texture_manager->UnlinkAndClearEvictedBackings(); |
849 contents_texture_manager->SetMaxMemoryLimitBytes( | 858 contents_texture_manager->SetMaxMemoryLimitBytes( |
850 layer_tree_host_impl_->memory_allocation_limit_bytes()); | 859 layer_tree_host_impl_->memory_allocation_limit_bytes()); |
851 contents_texture_manager->SetExternalPriorityCutoff( | 860 contents_texture_manager->SetExternalPriorityCutoff( |
852 layer_tree_host_impl_->memory_allocation_priority_cutoff()); | 861 layer_tree_host_impl_->memory_allocation_priority_cutoff()); |
853 } | 862 } |
854 | 863 |
855 DCHECK(!queue_for_commit_); | 864 DCHECK(!queue_for_commit_); |
856 queue_for_commit_ = make_scoped_ptr(new ResourceUpdateQueue); | 865 queue_for_commit_ = make_scoped_ptr(new ResourceUpdateQueue); |
857 | 866 |
| 867 // New commits requested inside UpdateLayers should be respected. |
| 868 commit_requested_ = false; |
| 869 |
858 layer_tree_host_->UpdateLayers(queue_for_commit_.get()); | 870 layer_tree_host_->UpdateLayers(queue_for_commit_.get()); |
859 | 871 |
860 timing_history_.DidBeginMainFrame(); | 872 timing_history_.DidBeginMainFrame(); |
861 | 873 |
862 // TODO(enne): SingleThreadProxy does not support cancelling commits yet, | 874 // TODO(enne): SingleThreadProxy does not support cancelling commits yet, |
863 // search for CommitEarlyOutReason::FINISHED_NO_UPDATES inside | 875 // search for CommitEarlyOutReason::FINISHED_NO_UPDATES inside |
864 // thread_proxy.cc | 876 // thread_proxy.cc |
865 if (scheduler_on_impl_thread_) { | 877 if (scheduler_on_impl_thread_) { |
866 scheduler_on_impl_thread_->NotifyBeginMainFrameStarted(); | 878 scheduler_on_impl_thread_->NotifyBeginMainFrameStarted(); |
867 scheduler_on_impl_thread_->NotifyReadyToCommit(); | 879 scheduler_on_impl_thread_->NotifyReadyToCommit(); |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
948 | 960 |
949 void SingleThreadProxy::DidBeginImplFrameDeadline() { | 961 void SingleThreadProxy::DidBeginImplFrameDeadline() { |
950 layer_tree_host_impl_->ResetCurrentBeginFrameArgsForNextFrame(); | 962 layer_tree_host_impl_->ResetCurrentBeginFrameArgsForNextFrame(); |
951 } | 963 } |
952 | 964 |
953 void SingleThreadProxy::SendBeginFramesToChildren(const BeginFrameArgs& args) { | 965 void SingleThreadProxy::SendBeginFramesToChildren(const BeginFrameArgs& args) { |
954 layer_tree_host_->SendBeginFramesToChildren(args); | 966 layer_tree_host_->SendBeginFramesToChildren(args); |
955 } | 967 } |
956 | 968 |
957 } // namespace cc | 969 } // namespace cc |
OLD | NEW |