| 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/thread_proxy.h" | 5 #include "cc/trees/thread_proxy.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/auto_reset.h" | 10 #include "base/auto_reset.h" |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/trace_event/trace_event.h" | 12 #include "base/trace_event/trace_event.h" |
| 13 #include "base/trace_event/trace_event_argument.h" | 13 #include "base/trace_event/trace_event_argument.h" |
| 14 #include "base/trace_event/trace_event_synthetic_delay.h" | 14 #include "base/trace_event/trace_event_synthetic_delay.h" |
| 15 #include "cc/debug/benchmark_instrumentation.h" | 15 #include "cc/debug/benchmark_instrumentation.h" |
| 16 #include "cc/debug/devtools_instrumentation.h" | 16 #include "cc/debug/devtools_instrumentation.h" |
| 17 #include "cc/input/input_handler.h" | 17 #include "cc/input/input_handler.h" |
| 18 #include "cc/output/context_provider.h" | 18 #include "cc/output/context_provider.h" |
| 19 #include "cc/output/output_surface.h" | 19 #include "cc/output/output_surface.h" |
| 20 #include "cc/output/swap_promise.h" | 20 #include "cc/output/swap_promise.h" |
| 21 #include "cc/quads/draw_quad.h" | 21 #include "cc/quads/draw_quad.h" |
| 22 #include "cc/scheduler/commit_earlyout_reason.h" | 22 #include "cc/scheduler/commit_earlyout_reason.h" |
| 23 #include "cc/scheduler/delay_based_time_source.h" | 23 #include "cc/scheduler/compositor_timing_history.h" |
| 24 #include "cc/scheduler/scheduler.h" | 24 #include "cc/scheduler/scheduler.h" |
| 25 #include "cc/trees/blocking_task_runner.h" | 25 #include "cc/trees/blocking_task_runner.h" |
| 26 #include "cc/trees/layer_tree_host.h" | 26 #include "cc/trees/layer_tree_host.h" |
| 27 #include "cc/trees/layer_tree_impl.h" | 27 #include "cc/trees/layer_tree_impl.h" |
| 28 #include "cc/trees/scoped_abort_remaining_swap_promises.h" | 28 #include "cc/trees/scoped_abort_remaining_swap_promises.h" |
| 29 #include "gpu/command_buffer/client/gles2_interface.h" | 29 #include "gpu/command_buffer/client/gles2_interface.h" |
| 30 | 30 |
| 31 namespace cc { | 31 namespace cc { |
| 32 | 32 |
| 33 namespace { | 33 namespace { |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 commit_completion_event(NULL), | 105 commit_completion_event(NULL), |
| 106 completion_event_for_commit_held_on_tree_activation(NULL), | 106 completion_event_for_commit_held_on_tree_activation(NULL), |
| 107 next_frame_is_newly_committed_frame(false), | 107 next_frame_is_newly_committed_frame(false), |
| 108 inside_draw(false), | 108 inside_draw(false), |
| 109 input_throttled_until_commit(false), | 109 input_throttled_until_commit(false), |
| 110 smoothness_priority_expiration_notifier( | 110 smoothness_priority_expiration_notifier( |
| 111 proxy->ImplThreadTaskRunner(), | 111 proxy->ImplThreadTaskRunner(), |
| 112 base::Bind(&ThreadProxy::RenewTreePriority, base::Unretained(proxy)), | 112 base::Bind(&ThreadProxy::RenewTreePriority, base::Unretained(proxy)), |
| 113 base::TimeDelta::FromMilliseconds( | 113 base::TimeDelta::FromMilliseconds( |
| 114 kSmoothnessTakesPriorityExpirationDelay * 1000)), | 114 kSmoothnessTakesPriorityExpirationDelay * 1000)), |
| 115 timing_history(rendering_stats_instrumentation), | |
| 116 external_begin_frame_source(external_begin_frame_source.Pass()), | 115 external_begin_frame_source(external_begin_frame_source.Pass()), |
| 116 rendering_stats_instrumentation(rendering_stats_instrumentation), |
| 117 weak_factory(proxy) { | 117 weak_factory(proxy) { |
| 118 } | 118 } |
| 119 | 119 |
| 120 ThreadProxy::CompositorThreadOnly::~CompositorThreadOnly() {} | 120 ThreadProxy::CompositorThreadOnly::~CompositorThreadOnly() {} |
| 121 | 121 |
| 122 ThreadProxy::~ThreadProxy() { | 122 ThreadProxy::~ThreadProxy() { |
| 123 TRACE_EVENT0("cc", "ThreadProxy::~ThreadProxy"); | 123 TRACE_EVENT0("cc", "ThreadProxy::~ThreadProxy"); |
| 124 DCHECK(IsMainThread()); | 124 DCHECK(IsMainThread()); |
| 125 DCHECK(!main().started); | 125 DCHECK(!main().started); |
| 126 } | 126 } |
| (...skipping 531 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 658 // main_frame_before_activation_enabled is set, since we might run this code | 658 // main_frame_before_activation_enabled is set, since we might run this code |
| 659 // twice before recording a duration. crbug.com/469824 | 659 // twice before recording a duration. crbug.com/469824 |
| 660 impl().last_begin_main_frame_args = begin_main_frame_state->begin_frame_args; | 660 impl().last_begin_main_frame_args = begin_main_frame_state->begin_frame_args; |
| 661 Proxy::MainThreadTaskRunner()->PostTask( | 661 Proxy::MainThreadTaskRunner()->PostTask( |
| 662 FROM_HERE, | 662 FROM_HERE, |
| 663 base::Bind(&ThreadProxy::BeginMainFrame, | 663 base::Bind(&ThreadProxy::BeginMainFrame, |
| 664 main_thread_weak_ptr_, | 664 main_thread_weak_ptr_, |
| 665 base::Passed(&begin_main_frame_state))); | 665 base::Passed(&begin_main_frame_state))); |
| 666 devtools_instrumentation::DidRequestMainThreadFrame( | 666 devtools_instrumentation::DidRequestMainThreadFrame( |
| 667 impl().layer_tree_host_id); | 667 impl().layer_tree_host_id); |
| 668 impl().timing_history.DidBeginMainFrame(); | |
| 669 } | 668 } |
| 670 | 669 |
| 671 void ThreadProxy::SendBeginMainFrameNotExpectedSoon() { | 670 void ThreadProxy::SendBeginMainFrameNotExpectedSoon() { |
| 672 Proxy::MainThreadTaskRunner()->PostTask( | 671 Proxy::MainThreadTaskRunner()->PostTask( |
| 673 FROM_HERE, base::Bind(&ThreadProxy::BeginMainFrameNotExpectedSoon, | 672 FROM_HERE, base::Bind(&ThreadProxy::BeginMainFrameNotExpectedSoon, |
| 674 main_thread_weak_ptr_)); | 673 main_thread_weak_ptr_)); |
| 675 } | 674 } |
| 676 | 675 |
| 677 void ThreadProxy::BeginMainFrame( | 676 void ThreadProxy::BeginMainFrame( |
| 678 scoped_ptr<BeginMainFrameAndCommitState> begin_main_frame_state) { | 677 scoped_ptr<BeginMainFrameAndCommitState> begin_main_frame_state) { |
| (...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 913 impl().commit_completion_event = NULL; | 912 impl().commit_completion_event = NULL; |
| 914 } | 913 } |
| 915 | 914 |
| 916 // Delay this step until afer the main thread has been released as it's | 915 // Delay this step until afer the main thread has been released as it's |
| 917 // often a good bit of work to update the tree and prepare the new frame. | 916 // often a good bit of work to update the tree and prepare the new frame. |
| 918 impl().layer_tree_host_impl->CommitComplete(); | 917 impl().layer_tree_host_impl->CommitComplete(); |
| 919 | 918 |
| 920 SetInputThrottledUntilCommitOnImplThread(false); | 919 SetInputThrottledUntilCommitOnImplThread(false); |
| 921 | 920 |
| 922 impl().next_frame_is_newly_committed_frame = true; | 921 impl().next_frame_is_newly_committed_frame = true; |
| 923 | |
| 924 impl().timing_history.DidCommit(); | |
| 925 } | 922 } |
| 926 | 923 |
| 927 void ThreadProxy::ScheduledActionActivateSyncTree() { | 924 void ThreadProxy::ScheduledActionActivateSyncTree() { |
| 928 TRACE_EVENT0("cc", "ThreadProxy::ScheduledActionActivateSyncTree"); | 925 TRACE_EVENT0("cc", "ThreadProxy::ScheduledActionActivateSyncTree"); |
| 929 DCHECK(IsImplThread()); | 926 DCHECK(IsImplThread()); |
| 930 impl().layer_tree_host_impl->ActivateSyncTree(); | 927 impl().layer_tree_host_impl->ActivateSyncTree(); |
| 931 } | 928 } |
| 932 | 929 |
| 933 void ThreadProxy::ScheduledActionBeginOutputSurfaceCreation() { | 930 void ThreadProxy::ScheduledActionBeginOutputSurfaceCreation() { |
| 934 TRACE_EVENT0("cc", "ThreadProxy::ScheduledActionBeginOutputSurfaceCreation"); | 931 TRACE_EVENT0("cc", "ThreadProxy::ScheduledActionBeginOutputSurfaceCreation"); |
| 935 DCHECK(IsImplThread()); | 932 DCHECK(IsImplThread()); |
| 936 Proxy::MainThreadTaskRunner()->PostTask( | 933 Proxy::MainThreadTaskRunner()->PostTask( |
| 937 FROM_HERE, | 934 FROM_HERE, |
| 938 base::Bind(&ThreadProxy::RequestNewOutputSurface, main_thread_weak_ptr_)); | 935 base::Bind(&ThreadProxy::RequestNewOutputSurface, main_thread_weak_ptr_)); |
| 939 } | 936 } |
| 940 | 937 |
| 941 DrawResult ThreadProxy::DrawSwapInternal(bool forced_draw) { | 938 DrawResult ThreadProxy::DrawSwapInternal(bool forced_draw) { |
| 942 TRACE_EVENT_SYNTHETIC_DELAY("cc.DrawAndSwap"); | 939 TRACE_EVENT_SYNTHETIC_DELAY("cc.DrawAndSwap"); |
| 943 DrawResult result; | 940 DrawResult result; |
| 944 | 941 |
| 945 DCHECK(IsImplThread()); | 942 DCHECK(IsImplThread()); |
| 946 DCHECK(impl().layer_tree_host_impl.get()); | 943 DCHECK(impl().layer_tree_host_impl.get()); |
| 947 | 944 |
| 948 impl().timing_history.DidStartDrawing(); | |
| 949 base::AutoReset<bool> mark_inside(&impl().inside_draw, true); | 945 base::AutoReset<bool> mark_inside(&impl().inside_draw, true); |
| 950 | 946 |
| 951 if (impl().layer_tree_host_impl->pending_tree()) { | 947 if (impl().layer_tree_host_impl->pending_tree()) { |
| 952 bool update_lcd_text = false; | 948 bool update_lcd_text = false; |
| 953 impl().layer_tree_host_impl->pending_tree()->UpdateDrawProperties( | 949 impl().layer_tree_host_impl->pending_tree()->UpdateDrawProperties( |
| 954 update_lcd_text); | 950 update_lcd_text); |
| 955 } | 951 } |
| 956 | 952 |
| 957 // This method is called on a forced draw, regardless of whether we are able | 953 // This method is called on a forced draw, regardless of whether we are able |
| 958 // to produce a frame, as the calling site on main thread is blocked until its | 954 // to produce a frame, as the calling site on main thread is blocked until its |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 990 impl().layer_tree_host_impl->SwapBuffers(frame); | 986 impl().layer_tree_host_impl->SwapBuffers(frame); |
| 991 | 987 |
| 992 // Tell the main thread that the the newly-commited frame was drawn. | 988 // Tell the main thread that the the newly-commited frame was drawn. |
| 993 if (impl().next_frame_is_newly_committed_frame) { | 989 if (impl().next_frame_is_newly_committed_frame) { |
| 994 impl().next_frame_is_newly_committed_frame = false; | 990 impl().next_frame_is_newly_committed_frame = false; |
| 995 Proxy::MainThreadTaskRunner()->PostTask( | 991 Proxy::MainThreadTaskRunner()->PostTask( |
| 996 FROM_HERE, | 992 FROM_HERE, |
| 997 base::Bind(&ThreadProxy::DidCommitAndDrawFrame, main_thread_weak_ptr_)); | 993 base::Bind(&ThreadProxy::DidCommitAndDrawFrame, main_thread_weak_ptr_)); |
| 998 } | 994 } |
| 999 | 995 |
| 1000 if (result == DRAW_SUCCESS) | |
| 1001 impl().timing_history.DidFinishDrawing(); | |
| 1002 | |
| 1003 DCHECK_NE(INVALID_RESULT, result); | 996 DCHECK_NE(INVALID_RESULT, result); |
| 1004 return result; | 997 return result; |
| 1005 } | 998 } |
| 1006 | 999 |
| 1007 void ThreadProxy::ScheduledActionPrepareTiles() { | 1000 void ThreadProxy::ScheduledActionPrepareTiles() { |
| 1008 TRACE_EVENT0("cc", "ThreadProxy::ScheduledActionPrepareTiles"); | 1001 TRACE_EVENT0("cc", "ThreadProxy::ScheduledActionPrepareTiles"); |
| 1009 impl().layer_tree_host_impl->PrepareTiles(); | 1002 impl().layer_tree_host_impl->PrepareTiles(); |
| 1010 } | 1003 } |
| 1011 | 1004 |
| 1012 DrawResult ThreadProxy::ScheduledActionDrawAndSwapIfPossible() { | 1005 DrawResult ThreadProxy::ScheduledActionDrawAndSwapIfPossible() { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1026 bool forced_draw = true; | 1019 bool forced_draw = true; |
| 1027 return DrawSwapInternal(forced_draw); | 1020 return DrawSwapInternal(forced_draw); |
| 1028 } | 1021 } |
| 1029 | 1022 |
| 1030 void ThreadProxy::ScheduledActionInvalidateOutputSurface() { | 1023 void ThreadProxy::ScheduledActionInvalidateOutputSurface() { |
| 1031 TRACE_EVENT0("cc", "ThreadProxy::ScheduledActionInvalidateOutputSurface"); | 1024 TRACE_EVENT0("cc", "ThreadProxy::ScheduledActionInvalidateOutputSurface"); |
| 1032 DCHECK(impl().layer_tree_host_impl->output_surface()); | 1025 DCHECK(impl().layer_tree_host_impl->output_surface()); |
| 1033 impl().layer_tree_host_impl->output_surface()->Invalidate(); | 1026 impl().layer_tree_host_impl->output_surface()->Invalidate(); |
| 1034 } | 1027 } |
| 1035 | 1028 |
| 1036 base::TimeDelta ThreadProxy::DrawDurationEstimate() { | |
| 1037 return impl().timing_history.DrawDurationEstimate(); | |
| 1038 } | |
| 1039 | |
| 1040 base::TimeDelta ThreadProxy::BeginMainFrameToCommitDurationEstimate() { | |
| 1041 return impl().timing_history.BeginMainFrameToCommitDurationEstimate(); | |
| 1042 } | |
| 1043 | |
| 1044 base::TimeDelta ThreadProxy::CommitToActivateDurationEstimate() { | |
| 1045 return impl().timing_history.CommitToActivateDurationEstimate(); | |
| 1046 } | |
| 1047 | |
| 1048 void ThreadProxy::DidFinishImplFrame() { | 1029 void ThreadProxy::DidFinishImplFrame() { |
| 1049 impl().layer_tree_host_impl->DidFinishImplFrame(); | 1030 impl().layer_tree_host_impl->DidFinishImplFrame(); |
| 1050 } | 1031 } |
| 1051 | 1032 |
| 1052 void ThreadProxy::SendBeginFramesToChildren(const BeginFrameArgs& args) { | 1033 void ThreadProxy::SendBeginFramesToChildren(const BeginFrameArgs& args) { |
| 1053 NOTREACHED() << "Only used by SingleThreadProxy"; | 1034 NOTREACHED() << "Only used by SingleThreadProxy"; |
| 1054 } | 1035 } |
| 1055 | 1036 |
| 1056 void ThreadProxy::SetAuthoritativeVSyncInterval( | 1037 void ThreadProxy::SetAuthoritativeVSyncInterval( |
| 1057 const base::TimeDelta& interval) { | 1038 const base::TimeDelta& interval) { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1072 TRACE_EVENT0("cc", "ThreadProxy::SetAnimationEvents"); | 1053 TRACE_EVENT0("cc", "ThreadProxy::SetAnimationEvents"); |
| 1073 DCHECK(IsMainThread()); | 1054 DCHECK(IsMainThread()); |
| 1074 layer_tree_host()->SetAnimationEvents(events.Pass()); | 1055 layer_tree_host()->SetAnimationEvents(events.Pass()); |
| 1075 } | 1056 } |
| 1076 | 1057 |
| 1077 void ThreadProxy::InitializeImplOnImplThread(CompletionEvent* completion) { | 1058 void ThreadProxy::InitializeImplOnImplThread(CompletionEvent* completion) { |
| 1078 TRACE_EVENT0("cc", "ThreadProxy::InitializeImplOnImplThread"); | 1059 TRACE_EVENT0("cc", "ThreadProxy::InitializeImplOnImplThread"); |
| 1079 DCHECK(IsImplThread()); | 1060 DCHECK(IsImplThread()); |
| 1080 impl().layer_tree_host_impl = | 1061 impl().layer_tree_host_impl = |
| 1081 layer_tree_host()->CreateLayerTreeHostImpl(this); | 1062 layer_tree_host()->CreateLayerTreeHostImpl(this); |
| 1063 |
| 1082 SchedulerSettings scheduler_settings( | 1064 SchedulerSettings scheduler_settings( |
| 1083 layer_tree_host()->settings().ToSchedulerSettings()); | 1065 layer_tree_host()->settings().ToSchedulerSettings()); |
| 1066 |
| 1067 scoped_ptr<CompositorTimingHistory> compositor_timing_history( |
| 1068 new CompositorTimingHistory(impl().rendering_stats_instrumentation)); |
| 1069 |
| 1084 impl().scheduler = Scheduler::Create( | 1070 impl().scheduler = Scheduler::Create( |
| 1085 this, scheduler_settings, impl().layer_tree_host_id, | 1071 this, scheduler_settings, impl().layer_tree_host_id, |
| 1086 ImplThreadTaskRunner(), impl().external_begin_frame_source.get()); | 1072 ImplThreadTaskRunner(), impl().external_begin_frame_source.get(), |
| 1073 compositor_timing_history.Pass()); |
| 1074 |
| 1087 impl().scheduler->SetVisible(impl().layer_tree_host_impl->visible()); | 1075 impl().scheduler->SetVisible(impl().layer_tree_host_impl->visible()); |
| 1088 impl_thread_weak_ptr_ = impl().weak_factory.GetWeakPtr(); | 1076 impl_thread_weak_ptr_ = impl().weak_factory.GetWeakPtr(); |
| 1089 completion->Signal(); | 1077 completion->Signal(); |
| 1090 } | 1078 } |
| 1091 | 1079 |
| 1092 void ThreadProxy::InitializeOutputSurfaceOnImplThread( | 1080 void ThreadProxy::InitializeOutputSurfaceOnImplThread( |
| 1093 scoped_ptr<OutputSurface> output_surface) { | 1081 scoped_ptr<OutputSurface> output_surface) { |
| 1094 TRACE_EVENT0("cc", "ThreadProxy::InitializeOutputSurfaceOnImplThread"); | 1082 TRACE_EVENT0("cc", "ThreadProxy::InitializeOutputSurfaceOnImplThread"); |
| 1095 DCHECK(IsImplThread()); | 1083 DCHECK(IsImplThread()); |
| 1096 | 1084 |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1239 TRACE_EVENT0("cc", "ThreadProxy::DidActivateSyncTreeOnImplThread"); | 1227 TRACE_EVENT0("cc", "ThreadProxy::DidActivateSyncTreeOnImplThread"); |
| 1240 DCHECK(IsImplThread()); | 1228 DCHECK(IsImplThread()); |
| 1241 | 1229 |
| 1242 if (impl().completion_event_for_commit_held_on_tree_activation) { | 1230 if (impl().completion_event_for_commit_held_on_tree_activation) { |
| 1243 TRACE_EVENT_INSTANT0( | 1231 TRACE_EVENT_INSTANT0( |
| 1244 "cc", "ReleaseCommitbyActivation", TRACE_EVENT_SCOPE_THREAD); | 1232 "cc", "ReleaseCommitbyActivation", TRACE_EVENT_SCOPE_THREAD); |
| 1245 impl().completion_event_for_commit_held_on_tree_activation->Signal(); | 1233 impl().completion_event_for_commit_held_on_tree_activation->Signal(); |
| 1246 impl().completion_event_for_commit_held_on_tree_activation = NULL; | 1234 impl().completion_event_for_commit_held_on_tree_activation = NULL; |
| 1247 } | 1235 } |
| 1248 | 1236 |
| 1249 impl().timing_history.DidActivateSyncTree(); | |
| 1250 impl().last_processed_begin_main_frame_args = | 1237 impl().last_processed_begin_main_frame_args = |
| 1251 impl().last_begin_main_frame_args; | 1238 impl().last_begin_main_frame_args; |
| 1252 } | 1239 } |
| 1253 | 1240 |
| 1254 void ThreadProxy::DidPrepareTiles() { | 1241 void ThreadProxy::DidPrepareTiles() { |
| 1255 DCHECK(IsImplThread()); | 1242 DCHECK(IsImplThread()); |
| 1256 impl().scheduler->DidPrepareTiles(); | 1243 impl().scheduler->DidPrepareTiles(); |
| 1257 } | 1244 } |
| 1258 | 1245 |
| 1259 void ThreadProxy::DidCompletePageScaleAnimationOnImplThread() { | 1246 void ThreadProxy::DidCompletePageScaleAnimationOnImplThread() { |
| (...skipping 21 matching lines...) Expand all Loading... |
| 1281 | 1268 |
| 1282 void ThreadProxy::PostFrameTimingEvents( | 1269 void ThreadProxy::PostFrameTimingEvents( |
| 1283 scoped_ptr<FrameTimingTracker::CompositeTimingSet> composite_events, | 1270 scoped_ptr<FrameTimingTracker::CompositeTimingSet> composite_events, |
| 1284 scoped_ptr<FrameTimingTracker::MainFrameTimingSet> main_frame_events) { | 1271 scoped_ptr<FrameTimingTracker::MainFrameTimingSet> main_frame_events) { |
| 1285 DCHECK(IsMainThread()); | 1272 DCHECK(IsMainThread()); |
| 1286 layer_tree_host()->RecordFrameTimingEvents(composite_events.Pass(), | 1273 layer_tree_host()->RecordFrameTimingEvents(composite_events.Pass(), |
| 1287 main_frame_events.Pass()); | 1274 main_frame_events.Pass()); |
| 1288 } | 1275 } |
| 1289 | 1276 |
| 1290 } // namespace cc | 1277 } // namespace cc |
| OLD | NEW |