| 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" |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 commit_completion_event(NULL), | 112 commit_completion_event(NULL), |
| 113 completion_event_for_commit_held_on_tree_activation(NULL), | 113 completion_event_for_commit_held_on_tree_activation(NULL), |
| 114 next_frame_is_newly_committed_frame(false), | 114 next_frame_is_newly_committed_frame(false), |
| 115 inside_draw(false), | 115 inside_draw(false), |
| 116 input_throttled_until_commit(false), | 116 input_throttled_until_commit(false), |
| 117 smoothness_priority_expiration_notifier( | 117 smoothness_priority_expiration_notifier( |
| 118 proxy->ImplThreadTaskRunner(), | 118 proxy->ImplThreadTaskRunner(), |
| 119 base::Bind(&ThreadProxy::RenewTreePriority, base::Unretained(proxy)), | 119 base::Bind(&ThreadProxy::RenewTreePriority, base::Unretained(proxy)), |
| 120 base::TimeDelta::FromMilliseconds( | 120 base::TimeDelta::FromMilliseconds( |
| 121 kSmoothnessTakesPriorityExpirationDelay * 1000)), | 121 kSmoothnessTakesPriorityExpirationDelay * 1000)), |
| 122 timing_history(rendering_stats_instrumentation), | |
| 123 external_begin_frame_source(external_begin_frame_source.Pass()), | 122 external_begin_frame_source(external_begin_frame_source.Pass()), |
| 123 rendering_stats_instrumentation(rendering_stats_instrumentation), |
| 124 weak_factory(proxy) { | 124 weak_factory(proxy) { |
| 125 } | 125 } |
| 126 | 126 |
| 127 ThreadProxy::CompositorThreadOnly::~CompositorThreadOnly() {} | 127 ThreadProxy::CompositorThreadOnly::~CompositorThreadOnly() {} |
| 128 | 128 |
| 129 ThreadProxy::~ThreadProxy() { | 129 ThreadProxy::~ThreadProxy() { |
| 130 TRACE_EVENT0("cc", "ThreadProxy::~ThreadProxy"); | 130 TRACE_EVENT0("cc", "ThreadProxy::~ThreadProxy"); |
| 131 DCHECK(IsMainThread()); | 131 DCHECK(IsMainThread()); |
| 132 DCHECK(!main().started); | 132 DCHECK(!main().started); |
| 133 } | 133 } |
| (...skipping 579 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 713 // main_frame_before_activation_enabled is set, since we might run this code | 713 // main_frame_before_activation_enabled is set, since we might run this code |
| 714 // twice before recording a duration. crbug.com/469824 | 714 // twice before recording a duration. crbug.com/469824 |
| 715 impl().last_begin_main_frame_args = begin_main_frame_state->begin_frame_args; | 715 impl().last_begin_main_frame_args = begin_main_frame_state->begin_frame_args; |
| 716 Proxy::MainThreadTaskRunner()->PostTask( | 716 Proxy::MainThreadTaskRunner()->PostTask( |
| 717 FROM_HERE, | 717 FROM_HERE, |
| 718 base::Bind(&ThreadProxy::BeginMainFrame, | 718 base::Bind(&ThreadProxy::BeginMainFrame, |
| 719 main_thread_weak_ptr_, | 719 main_thread_weak_ptr_, |
| 720 base::Passed(&begin_main_frame_state))); | 720 base::Passed(&begin_main_frame_state))); |
| 721 devtools_instrumentation::DidRequestMainThreadFrame( | 721 devtools_instrumentation::DidRequestMainThreadFrame( |
| 722 impl().layer_tree_host_id); | 722 impl().layer_tree_host_id); |
| 723 impl().timing_history.DidBeginMainFrame(); | |
| 724 } | 723 } |
| 725 | 724 |
| 726 void ThreadProxy::SendBeginMainFrameNotExpectedSoon() { | 725 void ThreadProxy::SendBeginMainFrameNotExpectedSoon() { |
| 727 Proxy::MainThreadTaskRunner()->PostTask( | 726 Proxy::MainThreadTaskRunner()->PostTask( |
| 728 FROM_HERE, base::Bind(&ThreadProxy::BeginMainFrameNotExpectedSoon, | 727 FROM_HERE, base::Bind(&ThreadProxy::BeginMainFrameNotExpectedSoon, |
| 729 main_thread_weak_ptr_)); | 728 main_thread_weak_ptr_)); |
| 730 } | 729 } |
| 731 | 730 |
| 732 void ThreadProxy::BeginMainFrame( | 731 void ThreadProxy::BeginMainFrame( |
| 733 scoped_ptr<BeginMainFrameAndCommitState> begin_main_frame_state) { | 732 scoped_ptr<BeginMainFrameAndCommitState> begin_main_frame_state) { |
| (...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1016 // sync tree has already activated if there was no work to be done. | 1015 // sync tree has already activated if there was no work to be done. |
| 1017 TRACE_EVENT_INSTANT0("cc", "HoldCommit", TRACE_EVENT_SCOPE_THREAD); | 1016 TRACE_EVENT_INSTANT0("cc", "HoldCommit", TRACE_EVENT_SCOPE_THREAD); |
| 1018 impl().completion_event_for_commit_held_on_tree_activation = | 1017 impl().completion_event_for_commit_held_on_tree_activation = |
| 1019 impl().commit_completion_event; | 1018 impl().commit_completion_event; |
| 1020 impl().commit_completion_event = NULL; | 1019 impl().commit_completion_event = NULL; |
| 1021 } else { | 1020 } else { |
| 1022 impl().commit_completion_event->Signal(); | 1021 impl().commit_completion_event->Signal(); |
| 1023 impl().commit_completion_event = NULL; | 1022 impl().commit_completion_event = NULL; |
| 1024 } | 1023 } |
| 1025 | 1024 |
| 1025 impl().scheduler->DidCommit(); |
| 1026 |
| 1026 // Delay this step until afer the main thread has been released as it's | 1027 // Delay this step until afer the main thread has been released as it's |
| 1027 // often a good bit of work to update the tree and prepare the new frame. | 1028 // often a good bit of work to update the tree and prepare the new frame. |
| 1028 impl().layer_tree_host_impl->CommitComplete(); | 1029 impl().layer_tree_host_impl->CommitComplete(); |
| 1029 | 1030 |
| 1030 SetInputThrottledUntilCommitOnImplThread(false); | 1031 SetInputThrottledUntilCommitOnImplThread(false); |
| 1031 | 1032 |
| 1032 impl().next_frame_is_newly_committed_frame = true; | 1033 impl().next_frame_is_newly_committed_frame = true; |
| 1033 | |
| 1034 impl().timing_history.DidCommit(); | |
| 1035 } | 1034 } |
| 1036 | 1035 |
| 1037 void ThreadProxy::ScheduledActionActivateSyncTree() { | 1036 void ThreadProxy::ScheduledActionActivateSyncTree() { |
| 1038 TRACE_EVENT0("cc", "ThreadProxy::ScheduledActionActivateSyncTree"); | 1037 TRACE_EVENT0("cc", "ThreadProxy::ScheduledActionActivateSyncTree"); |
| 1039 DCHECK(IsImplThread()); | 1038 DCHECK(IsImplThread()); |
| 1040 impl().layer_tree_host_impl->ActivateSyncTree(); | 1039 impl().layer_tree_host_impl->ActivateSyncTree(); |
| 1041 } | 1040 } |
| 1042 | 1041 |
| 1043 void ThreadProxy::ScheduledActionBeginOutputSurfaceCreation() { | 1042 void ThreadProxy::ScheduledActionBeginOutputSurfaceCreation() { |
| 1044 TRACE_EVENT0("cc", "ThreadProxy::ScheduledActionBeginOutputSurfaceCreation"); | 1043 TRACE_EVENT0("cc", "ThreadProxy::ScheduledActionBeginOutputSurfaceCreation"); |
| 1045 DCHECK(IsImplThread()); | 1044 DCHECK(IsImplThread()); |
| 1046 Proxy::MainThreadTaskRunner()->PostTask( | 1045 Proxy::MainThreadTaskRunner()->PostTask( |
| 1047 FROM_HERE, | 1046 FROM_HERE, |
| 1048 base::Bind(&ThreadProxy::RequestNewOutputSurface, main_thread_weak_ptr_)); | 1047 base::Bind(&ThreadProxy::RequestNewOutputSurface, main_thread_weak_ptr_)); |
| 1049 } | 1048 } |
| 1050 | 1049 |
| 1051 DrawResult ThreadProxy::DrawSwapInternal(bool forced_draw) { | 1050 DrawResult ThreadProxy::DrawSwapInternal(bool forced_draw) { |
| 1052 TRACE_EVENT_SYNTHETIC_DELAY("cc.DrawAndSwap"); | 1051 TRACE_EVENT_SYNTHETIC_DELAY("cc.DrawAndSwap"); |
| 1053 DrawResult result; | 1052 DrawResult result; |
| 1054 | 1053 |
| 1055 DCHECK(IsImplThread()); | 1054 DCHECK(IsImplThread()); |
| 1056 DCHECK(impl().layer_tree_host_impl.get()); | 1055 DCHECK(impl().layer_tree_host_impl.get()); |
| 1057 | 1056 |
| 1058 impl().timing_history.DidStartDrawing(); | |
| 1059 base::AutoReset<bool> mark_inside(&impl().inside_draw, true); | 1057 base::AutoReset<bool> mark_inside(&impl().inside_draw, true); |
| 1060 | 1058 |
| 1061 if (impl().layer_tree_host_impl->pending_tree()) { | 1059 if (impl().layer_tree_host_impl->pending_tree()) { |
| 1062 bool update_lcd_text = false; | 1060 bool update_lcd_text = false; |
| 1063 impl().layer_tree_host_impl->pending_tree()->UpdateDrawProperties( | 1061 impl().layer_tree_host_impl->pending_tree()->UpdateDrawProperties( |
| 1064 update_lcd_text); | 1062 update_lcd_text); |
| 1065 } | 1063 } |
| 1066 | 1064 |
| 1067 // This method is called on a forced draw, regardless of whether we are able | 1065 // This method is called on a forced draw, regardless of whether we are able |
| 1068 // to produce a frame, as the calling site on main thread is blocked until its | 1066 // 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... |
| 1100 impl().layer_tree_host_impl->SwapBuffers(frame); | 1098 impl().layer_tree_host_impl->SwapBuffers(frame); |
| 1101 | 1099 |
| 1102 // Tell the main thread that the the newly-commited frame was drawn. | 1100 // Tell the main thread that the the newly-commited frame was drawn. |
| 1103 if (impl().next_frame_is_newly_committed_frame) { | 1101 if (impl().next_frame_is_newly_committed_frame) { |
| 1104 impl().next_frame_is_newly_committed_frame = false; | 1102 impl().next_frame_is_newly_committed_frame = false; |
| 1105 Proxy::MainThreadTaskRunner()->PostTask( | 1103 Proxy::MainThreadTaskRunner()->PostTask( |
| 1106 FROM_HERE, | 1104 FROM_HERE, |
| 1107 base::Bind(&ThreadProxy::DidCommitAndDrawFrame, main_thread_weak_ptr_)); | 1105 base::Bind(&ThreadProxy::DidCommitAndDrawFrame, main_thread_weak_ptr_)); |
| 1108 } | 1106 } |
| 1109 | 1107 |
| 1110 if (result == DRAW_SUCCESS) | |
| 1111 impl().timing_history.DidFinishDrawing(); | |
| 1112 | |
| 1113 DCHECK_NE(INVALID_RESULT, result); | 1108 DCHECK_NE(INVALID_RESULT, result); |
| 1114 return result; | 1109 return result; |
| 1115 } | 1110 } |
| 1116 | 1111 |
| 1117 void ThreadProxy::ScheduledActionPrepareTiles() { | 1112 void ThreadProxy::ScheduledActionPrepareTiles() { |
| 1118 TRACE_EVENT0("cc", "ThreadProxy::ScheduledActionPrepareTiles"); | 1113 TRACE_EVENT0("cc", "ThreadProxy::ScheduledActionPrepareTiles"); |
| 1119 DCHECK(impl().layer_tree_host_impl->settings().impl_side_painting); | 1114 DCHECK(impl().layer_tree_host_impl->settings().impl_side_painting); |
| 1120 impl().layer_tree_host_impl->PrepareTiles(); | 1115 impl().layer_tree_host_impl->PrepareTiles(); |
| 1121 } | 1116 } |
| 1122 | 1117 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 1142 TRACE_EVENT0("cc", "ThreadProxy::ScheduledActionInvalidateOutputSurface"); | 1137 TRACE_EVENT0("cc", "ThreadProxy::ScheduledActionInvalidateOutputSurface"); |
| 1143 DCHECK(impl().layer_tree_host_impl->output_surface()); | 1138 DCHECK(impl().layer_tree_host_impl->output_surface()); |
| 1144 impl().layer_tree_host_impl->output_surface()->Invalidate(); | 1139 impl().layer_tree_host_impl->output_surface()->Invalidate(); |
| 1145 } | 1140 } |
| 1146 | 1141 |
| 1147 void ThreadProxy::DidAnticipatedDrawTimeChange(base::TimeTicks time) { | 1142 void ThreadProxy::DidAnticipatedDrawTimeChange(base::TimeTicks time) { |
| 1148 if (impl().current_resource_update_controller) | 1143 if (impl().current_resource_update_controller) |
| 1149 impl().current_resource_update_controller->PerformMoreUpdates(time); | 1144 impl().current_resource_update_controller->PerformMoreUpdates(time); |
| 1150 } | 1145 } |
| 1151 | 1146 |
| 1152 base::TimeDelta ThreadProxy::DrawDurationEstimate() { | |
| 1153 return impl().timing_history.DrawDurationEstimate(); | |
| 1154 } | |
| 1155 | |
| 1156 base::TimeDelta ThreadProxy::BeginMainFrameToCommitDurationEstimate() { | |
| 1157 return impl().timing_history.BeginMainFrameToCommitDurationEstimate(); | |
| 1158 } | |
| 1159 | |
| 1160 base::TimeDelta ThreadProxy::CommitToActivateDurationEstimate() { | |
| 1161 return impl().timing_history.CommitToActivateDurationEstimate(); | |
| 1162 } | |
| 1163 | |
| 1164 void ThreadProxy::DidFinishImplFrame() { | 1147 void ThreadProxy::DidFinishImplFrame() { |
| 1165 impl().layer_tree_host_impl->DidFinishImplFrame(); | 1148 impl().layer_tree_host_impl->DidFinishImplFrame(); |
| 1166 } | 1149 } |
| 1167 | 1150 |
| 1168 void ThreadProxy::SendBeginFramesToChildren(const BeginFrameArgs& args) { | 1151 void ThreadProxy::SendBeginFramesToChildren(const BeginFrameArgs& args) { |
| 1169 NOTREACHED() << "Only used by SingleThreadProxy"; | 1152 NOTREACHED() << "Only used by SingleThreadProxy"; |
| 1170 } | 1153 } |
| 1171 | 1154 |
| 1172 void ThreadProxy::SetAuthoritativeVSyncInterval( | 1155 void ThreadProxy::SetAuthoritativeVSyncInterval( |
| 1173 const base::TimeDelta& interval) { | 1156 const base::TimeDelta& interval) { |
| (...skipping 22 matching lines...) Expand all Loading... |
| 1196 } | 1179 } |
| 1197 | 1180 |
| 1198 void ThreadProxy::InitializeImplOnImplThread(CompletionEvent* completion) { | 1181 void ThreadProxy::InitializeImplOnImplThread(CompletionEvent* completion) { |
| 1199 TRACE_EVENT0("cc", "ThreadProxy::InitializeImplOnImplThread"); | 1182 TRACE_EVENT0("cc", "ThreadProxy::InitializeImplOnImplThread"); |
| 1200 DCHECK(IsImplThread()); | 1183 DCHECK(IsImplThread()); |
| 1201 impl().layer_tree_host_impl = | 1184 impl().layer_tree_host_impl = |
| 1202 layer_tree_host()->CreateLayerTreeHostImpl(this); | 1185 layer_tree_host()->CreateLayerTreeHostImpl(this); |
| 1203 SchedulerSettings scheduler_settings( | 1186 SchedulerSettings scheduler_settings( |
| 1204 layer_tree_host()->settings().ToSchedulerSettings()); | 1187 layer_tree_host()->settings().ToSchedulerSettings()); |
| 1205 impl().scheduler = Scheduler::Create( | 1188 impl().scheduler = Scheduler::Create( |
| 1206 this, | 1189 this, scheduler_settings, impl().layer_tree_host_id, |
| 1207 scheduler_settings, | 1190 ImplThreadTaskRunner(), impl().external_begin_frame_source.Pass(), |
| 1208 impl().layer_tree_host_id, | 1191 impl().rendering_stats_instrumentation); |
| 1209 ImplThreadTaskRunner(), | |
| 1210 impl().external_begin_frame_source.Pass()); | |
| 1211 impl().scheduler->SetVisible(impl().layer_tree_host_impl->visible()); | 1192 impl().scheduler->SetVisible(impl().layer_tree_host_impl->visible()); |
| 1212 impl_thread_weak_ptr_ = impl().weak_factory.GetWeakPtr(); | 1193 impl_thread_weak_ptr_ = impl().weak_factory.GetWeakPtr(); |
| 1213 completion->Signal(); | 1194 completion->Signal(); |
| 1214 } | 1195 } |
| 1215 | 1196 |
| 1216 void ThreadProxy::DeleteContentsTexturesOnImplThread( | 1197 void ThreadProxy::DeleteContentsTexturesOnImplThread( |
| 1217 CompletionEvent* completion) { | 1198 CompletionEvent* completion) { |
| 1218 TRACE_EVENT0("cc", "ThreadProxy::DeleteContentsTexturesOnImplThread"); | 1199 TRACE_EVENT0("cc", "ThreadProxy::DeleteContentsTexturesOnImplThread"); |
| 1219 DCHECK(IsImplThread()); | 1200 DCHECK(IsImplThread()); |
| 1220 DCHECK(IsMainThreadBlocked()); | 1201 DCHECK(IsMainThreadBlocked()); |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1383 DCHECK(IsImplThread()); | 1364 DCHECK(IsImplThread()); |
| 1384 | 1365 |
| 1385 if (impl().completion_event_for_commit_held_on_tree_activation) { | 1366 if (impl().completion_event_for_commit_held_on_tree_activation) { |
| 1386 TRACE_EVENT_INSTANT0( | 1367 TRACE_EVENT_INSTANT0( |
| 1387 "cc", "ReleaseCommitbyActivation", TRACE_EVENT_SCOPE_THREAD); | 1368 "cc", "ReleaseCommitbyActivation", TRACE_EVENT_SCOPE_THREAD); |
| 1388 DCHECK(impl().layer_tree_host_impl->settings().impl_side_painting); | 1369 DCHECK(impl().layer_tree_host_impl->settings().impl_side_painting); |
| 1389 impl().completion_event_for_commit_held_on_tree_activation->Signal(); | 1370 impl().completion_event_for_commit_held_on_tree_activation->Signal(); |
| 1390 impl().completion_event_for_commit_held_on_tree_activation = NULL; | 1371 impl().completion_event_for_commit_held_on_tree_activation = NULL; |
| 1391 } | 1372 } |
| 1392 | 1373 |
| 1393 impl().timing_history.DidActivateSyncTree(); | |
| 1394 impl().last_processed_begin_main_frame_args = | 1374 impl().last_processed_begin_main_frame_args = |
| 1395 impl().last_begin_main_frame_args; | 1375 impl().last_begin_main_frame_args; |
| 1396 } | 1376 } |
| 1397 | 1377 |
| 1378 void ThreadProxy::WillPrepareTiles() { |
| 1379 DCHECK(IsImplThread()); |
| 1380 impl().scheduler->WillPrepareTiles(); |
| 1381 } |
| 1382 |
| 1398 void ThreadProxy::DidPrepareTiles() { | 1383 void ThreadProxy::DidPrepareTiles() { |
| 1399 DCHECK(IsImplThread()); | 1384 DCHECK(IsImplThread()); |
| 1400 impl().scheduler->DidPrepareTiles(); | 1385 impl().scheduler->DidPrepareTiles(); |
| 1401 } | 1386 } |
| 1402 | 1387 |
| 1403 void ThreadProxy::DidCompletePageScaleAnimationOnImplThread() { | 1388 void ThreadProxy::DidCompletePageScaleAnimationOnImplThread() { |
| 1404 DCHECK(IsImplThread()); | 1389 DCHECK(IsImplThread()); |
| 1405 Proxy::MainThreadTaskRunner()->PostTask( | 1390 Proxy::MainThreadTaskRunner()->PostTask( |
| 1406 FROM_HERE, base::Bind(&ThreadProxy::DidCompletePageScaleAnimation, | 1391 FROM_HERE, base::Bind(&ThreadProxy::DidCompletePageScaleAnimation, |
| 1407 main_thread_weak_ptr_)); | 1392 main_thread_weak_ptr_)); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 1425 | 1410 |
| 1426 void ThreadProxy::PostFrameTimingEvents( | 1411 void ThreadProxy::PostFrameTimingEvents( |
| 1427 scoped_ptr<FrameTimingTracker::CompositeTimingSet> composite_events, | 1412 scoped_ptr<FrameTimingTracker::CompositeTimingSet> composite_events, |
| 1428 scoped_ptr<FrameTimingTracker::MainFrameTimingSet> main_frame_events) { | 1413 scoped_ptr<FrameTimingTracker::MainFrameTimingSet> main_frame_events) { |
| 1429 DCHECK(IsMainThread()); | 1414 DCHECK(IsMainThread()); |
| 1430 layer_tree_host()->RecordFrameTimingEvents(composite_events.Pass(), | 1415 layer_tree_host()->RecordFrameTimingEvents(composite_events.Pass(), |
| 1431 main_frame_events.Pass()); | 1416 main_frame_events.Pass()); |
| 1432 } | 1417 } |
| 1433 | 1418 |
| 1434 } // namespace cc | 1419 } // namespace cc |
| OLD | NEW |