| 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 14 matching lines...) Expand all Loading... |
| 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 "ui/gfx/frame_time.h" | 28 #include "ui/gfx/frame_time.h" |
| 29 | 29 |
| 30 namespace { | 30 namespace { |
| 31 | 31 |
| 32 // Measured in seconds. | 32 // Measured in seconds. |
| 33 const double kSmoothnessTakesPriorityExpirationDelay = 0.25; | 33 const double kSmoothnessTakesPriorityExpirationDelay = 0.25; |
| 34 | 34 |
| 35 const size_t kDurationHistorySize = 60; | |
| 36 const double kCommitAndActivationDurationEstimationPercentile = 50.0; | |
| 37 const double kDrawDurationEstimationPercentile = 100.0; | |
| 38 const int kDrawDurationEstimatePaddingInMicroseconds = 0; | |
| 39 | |
| 40 class SwapPromiseChecker { | 35 class SwapPromiseChecker { |
| 41 public: | 36 public: |
| 42 explicit SwapPromiseChecker(cc::LayerTreeHost* layer_tree_host) | 37 explicit SwapPromiseChecker(cc::LayerTreeHost* layer_tree_host) |
| 43 : layer_tree_host_(layer_tree_host) {} | 38 : layer_tree_host_(layer_tree_host) {} |
| 44 | 39 |
| 45 ~SwapPromiseChecker() { | 40 ~SwapPromiseChecker() { |
| 46 layer_tree_host_->BreakSwapPromises(cc::SwapPromise::COMMIT_FAILS); | 41 layer_tree_host_->BreakSwapPromises(cc::SwapPromise::COMMIT_FAILS); |
| 47 } | 42 } |
| 48 | 43 |
| 49 private: | 44 private: |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 begin_main_frame_sent_completion_event(NULL), | 120 begin_main_frame_sent_completion_event(NULL), |
| 126 readback_request(NULL), | 121 readback_request(NULL), |
| 127 commit_completion_event(NULL), | 122 commit_completion_event(NULL), |
| 128 completion_event_for_commit_held_on_tree_activation(NULL), | 123 completion_event_for_commit_held_on_tree_activation(NULL), |
| 129 texture_acquisition_completion_event(NULL), | 124 texture_acquisition_completion_event(NULL), |
| 130 next_frame_is_newly_committed_frame(false), | 125 next_frame_is_newly_committed_frame(false), |
| 131 inside_draw(false), | 126 inside_draw(false), |
| 132 input_throttled_until_commit(false), | 127 input_throttled_until_commit(false), |
| 133 animations_frozen_until_next_draw(false), | 128 animations_frozen_until_next_draw(false), |
| 134 renew_tree_priority_pending(false), | 129 renew_tree_priority_pending(false), |
| 135 draw_duration_history(kDurationHistorySize), | |
| 136 begin_main_frame_to_commit_duration_history(kDurationHistorySize), | |
| 137 commit_to_activate_duration_history(kDurationHistorySize), | |
| 138 weak_factory(proxy) {} | 130 weak_factory(proxy) {} |
| 139 | 131 |
| 140 ThreadProxy::CompositorThreadOnly::~CompositorThreadOnly() {} | 132 ThreadProxy::CompositorThreadOnly::~CompositorThreadOnly() {} |
| 141 | 133 |
| 142 ThreadProxy::~ThreadProxy() { | 134 ThreadProxy::~ThreadProxy() { |
| 143 TRACE_EVENT0("cc", "ThreadProxy::~ThreadProxy"); | 135 TRACE_EVENT0("cc", "ThreadProxy::~ThreadProxy"); |
| 144 DCHECK(IsMainThread()); | 136 DCHECK(IsMainThread()); |
| 145 DCHECK(!main().started); | 137 DCHECK(!main().started); |
| 146 } | 138 } |
| 147 | 139 |
| (...skipping 632 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 780 Proxy::MainThreadTaskRunner()->PostTask( | 772 Proxy::MainThreadTaskRunner()->PostTask( |
| 781 FROM_HERE, | 773 FROM_HERE, |
| 782 base::Bind(&ThreadProxy::BeginMainFrame, | 774 base::Bind(&ThreadProxy::BeginMainFrame, |
| 783 main_thread_weak_ptr_, | 775 main_thread_weak_ptr_, |
| 784 base::Passed(&begin_main_frame_state))); | 776 base::Passed(&begin_main_frame_state))); |
| 785 | 777 |
| 786 if (impl().begin_main_frame_sent_completion_event) { | 778 if (impl().begin_main_frame_sent_completion_event) { |
| 787 impl().begin_main_frame_sent_completion_event->Signal(); | 779 impl().begin_main_frame_sent_completion_event->Signal(); |
| 788 impl().begin_main_frame_sent_completion_event = NULL; | 780 impl().begin_main_frame_sent_completion_event = NULL; |
| 789 } | 781 } |
| 790 impl().begin_main_frame_sent_time = base::TimeTicks::HighResNow(); | 782 impl().timing_history.DidBeginMainFrame(); |
| 791 } | 783 } |
| 792 | 784 |
| 793 void ThreadProxy::BeginMainFrame( | 785 void ThreadProxy::BeginMainFrame( |
| 794 scoped_ptr<BeginMainFrameAndCommitState> begin_main_frame_state) { | 786 scoped_ptr<BeginMainFrameAndCommitState> begin_main_frame_state) { |
| 795 TRACE_EVENT0("cc", "ThreadProxy::BeginMainFrame"); | 787 TRACE_EVENT0("cc", "ThreadProxy::BeginMainFrame"); |
| 796 TRACE_EVENT_SYNTHETIC_DELAY_BEGIN("cc.BeginMainFrame"); | 788 TRACE_EVENT_SYNTHETIC_DELAY_BEGIN("cc.BeginMainFrame"); |
| 797 DCHECK(IsMainThread()); | 789 DCHECK(IsMainThread()); |
| 798 | 790 |
| 799 if (!layer_tree_host()) | 791 if (!layer_tree_host()) |
| 800 return; | 792 return; |
| (...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1086 // Delay this step until afer the main thread has been released as it's | 1078 // Delay this step until afer the main thread has been released as it's |
| 1087 // often a good bit of work to update the tree and prepare the new frame. | 1079 // often a good bit of work to update the tree and prepare the new frame. |
| 1088 impl().layer_tree_host_impl->CommitComplete(); | 1080 impl().layer_tree_host_impl->CommitComplete(); |
| 1089 | 1081 |
| 1090 SetInputThrottledUntilCommitOnImplThread(false); | 1082 SetInputThrottledUntilCommitOnImplThread(false); |
| 1091 | 1083 |
| 1092 UpdateBackgroundAnimateTicking(); | 1084 UpdateBackgroundAnimateTicking(); |
| 1093 | 1085 |
| 1094 impl().next_frame_is_newly_committed_frame = true; | 1086 impl().next_frame_is_newly_committed_frame = true; |
| 1095 | 1087 |
| 1096 impl().commit_complete_time = base::TimeTicks::HighResNow(); | 1088 impl().timing_history.DidCommit(); |
| 1097 impl().begin_main_frame_to_commit_duration_history.InsertSample( | |
| 1098 impl().commit_complete_time - impl().begin_main_frame_sent_time); | |
| 1099 | 1089 |
| 1100 // SetVisible kicks off the next scheduler action, so this must be last. | 1090 // SetVisible kicks off the next scheduler action, so this must be last. |
| 1101 impl().scheduler->SetVisible(impl().layer_tree_host_impl->visible()); | 1091 impl().scheduler->SetVisible(impl().layer_tree_host_impl->visible()); |
| 1102 } | 1092 } |
| 1103 | 1093 |
| 1104 void ThreadProxy::ScheduledActionUpdateVisibleTiles() { | 1094 void ThreadProxy::ScheduledActionUpdateVisibleTiles() { |
| 1105 TRACE_EVENT0("cc", "ThreadProxy::ScheduledActionUpdateVisibleTiles"); | 1095 TRACE_EVENT0("cc", "ThreadProxy::ScheduledActionUpdateVisibleTiles"); |
| 1106 DCHECK(IsImplThread()); | 1096 DCHECK(IsImplThread()); |
| 1107 impl().layer_tree_host_impl->UpdateVisibleTiles(); | 1097 impl().layer_tree_host_impl->UpdateVisibleTiles(); |
| 1108 } | 1098 } |
| (...skipping 16 matching lines...) Expand all Loading... |
| 1125 DrawSwapReadbackResult ThreadProxy::DrawSwapReadbackInternal( | 1115 DrawSwapReadbackResult ThreadProxy::DrawSwapReadbackInternal( |
| 1126 bool forced_draw, | 1116 bool forced_draw, |
| 1127 bool swap_requested, | 1117 bool swap_requested, |
| 1128 bool readback_requested) { | 1118 bool readback_requested) { |
| 1129 TRACE_EVENT_SYNTHETIC_DELAY("cc.DrawAndSwap"); | 1119 TRACE_EVENT_SYNTHETIC_DELAY("cc.DrawAndSwap"); |
| 1130 DrawSwapReadbackResult result; | 1120 DrawSwapReadbackResult result; |
| 1131 | 1121 |
| 1132 DCHECK(IsImplThread()); | 1122 DCHECK(IsImplThread()); |
| 1133 DCHECK(impl().layer_tree_host_impl.get()); | 1123 DCHECK(impl().layer_tree_host_impl.get()); |
| 1134 | 1124 |
| 1135 base::TimeTicks start_time = base::TimeTicks::HighResNow(); | 1125 impl().timing_history.DidStartDrawing(); |
| 1136 base::TimeDelta draw_duration_estimate = DrawDurationEstimate(); | 1126 base::TimeDelta draw_duration_estimate = DrawDurationEstimate(); |
| 1137 base::AutoReset<bool> mark_inside(&impl().inside_draw, true); | 1127 base::AutoReset<bool> mark_inside(&impl().inside_draw, true); |
| 1138 | 1128 |
| 1139 // Advance our animations. | 1129 // Advance our animations. |
| 1140 base::TimeTicks monotonic_time; | 1130 base::TimeTicks monotonic_time; |
| 1141 if (impl().animations_frozen_until_next_draw) | 1131 if (impl().animations_frozen_until_next_draw) |
| 1142 monotonic_time = impl().animation_freeze_time; | 1132 monotonic_time = impl().animation_freeze_time; |
| 1143 else | 1133 else |
| 1144 monotonic_time = impl().layer_tree_host_impl->CurrentFrameTimeTicks(); | 1134 monotonic_time = impl().layer_tree_host_impl->CurrentFrameTimeTicks(); |
| 1145 | 1135 |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1235 if (impl().next_frame_is_newly_committed_frame) { | 1225 if (impl().next_frame_is_newly_committed_frame) { |
| 1236 impl().next_frame_is_newly_committed_frame = false; | 1226 impl().next_frame_is_newly_committed_frame = false; |
| 1237 Proxy::MainThreadTaskRunner()->PostTask( | 1227 Proxy::MainThreadTaskRunner()->PostTask( |
| 1238 FROM_HERE, | 1228 FROM_HERE, |
| 1239 base::Bind(&ThreadProxy::DidCommitAndDrawFrame, main_thread_weak_ptr_)); | 1229 base::Bind(&ThreadProxy::DidCommitAndDrawFrame, main_thread_weak_ptr_)); |
| 1240 } | 1230 } |
| 1241 | 1231 |
| 1242 if (draw_frame) { | 1232 if (draw_frame) { |
| 1243 CheckOutputSurfaceStatusOnImplThread(); | 1233 CheckOutputSurfaceStatusOnImplThread(); |
| 1244 | 1234 |
| 1245 base::TimeDelta draw_duration = base::TimeTicks::HighResNow() - start_time; | 1235 base::TimeDelta draw_duration = impl().timing_history.DidFinishDrawing(); |
| 1246 impl().draw_duration_history.InsertSample(draw_duration); | 1236 |
| 1247 base::TimeDelta draw_duration_overestimate; | 1237 base::TimeDelta draw_duration_overestimate; |
| 1248 base::TimeDelta draw_duration_underestimate; | 1238 base::TimeDelta draw_duration_underestimate; |
| 1249 if (draw_duration > draw_duration_estimate) | 1239 if (draw_duration > draw_duration_estimate) |
| 1250 draw_duration_underestimate = draw_duration - draw_duration_estimate; | 1240 draw_duration_underestimate = draw_duration - draw_duration_estimate; |
| 1251 else | 1241 else |
| 1252 draw_duration_overestimate = draw_duration_estimate - draw_duration; | 1242 draw_duration_overestimate = draw_duration_estimate - draw_duration; |
| 1253 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer.DrawDuration", | 1243 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer.DrawDuration", |
| 1254 draw_duration, | 1244 draw_duration, |
| 1255 base::TimeDelta::FromMilliseconds(1), | 1245 base::TimeDelta::FromMilliseconds(1), |
| 1256 base::TimeDelta::FromMilliseconds(100), | 1246 base::TimeDelta::FromMilliseconds(100), |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1343 return DrawSwapReadbackInternal( | 1333 return DrawSwapReadbackInternal( |
| 1344 forced_draw, swap_requested, readback_requested); | 1334 forced_draw, swap_requested, readback_requested); |
| 1345 } | 1335 } |
| 1346 | 1336 |
| 1347 void ThreadProxy::DidAnticipatedDrawTimeChange(base::TimeTicks time) { | 1337 void ThreadProxy::DidAnticipatedDrawTimeChange(base::TimeTicks time) { |
| 1348 if (impl().current_resource_update_controller) | 1338 if (impl().current_resource_update_controller) |
| 1349 impl().current_resource_update_controller->PerformMoreUpdates(time); | 1339 impl().current_resource_update_controller->PerformMoreUpdates(time); |
| 1350 } | 1340 } |
| 1351 | 1341 |
| 1352 base::TimeDelta ThreadProxy::DrawDurationEstimate() { | 1342 base::TimeDelta ThreadProxy::DrawDurationEstimate() { |
| 1353 base::TimeDelta historical_estimate = impl().draw_duration_history.Percentile( | 1343 return impl().timing_history.DrawDurationEstimate(); |
| 1354 kDrawDurationEstimationPercentile); | |
| 1355 base::TimeDelta padding = base::TimeDelta::FromMicroseconds( | |
| 1356 kDrawDurationEstimatePaddingInMicroseconds); | |
| 1357 return historical_estimate + padding; | |
| 1358 } | 1344 } |
| 1359 | 1345 |
| 1360 base::TimeDelta ThreadProxy::BeginMainFrameToCommitDurationEstimate() { | 1346 base::TimeDelta ThreadProxy::BeginMainFrameToCommitDurationEstimate() { |
| 1361 return impl().begin_main_frame_to_commit_duration_history.Percentile( | 1347 return impl().timing_history.BeginMainFrameToCommitDurationEstimate(); |
| 1362 kCommitAndActivationDurationEstimationPercentile); | |
| 1363 } | 1348 } |
| 1364 | 1349 |
| 1365 base::TimeDelta ThreadProxy::CommitToActivateDurationEstimate() { | 1350 base::TimeDelta ThreadProxy::CommitToActivateDurationEstimate() { |
| 1366 return impl().commit_to_activate_duration_history.Percentile( | 1351 return impl().timing_history.CommitToActivateDurationEstimate(); |
| 1367 kCommitAndActivationDurationEstimationPercentile); | |
| 1368 } | 1352 } |
| 1369 | 1353 |
| 1370 void ThreadProxy::PostBeginImplFrameDeadline(const base::Closure& closure, | 1354 void ThreadProxy::PostBeginImplFrameDeadline(const base::Closure& closure, |
| 1371 base::TimeTicks deadline) { | 1355 base::TimeTicks deadline) { |
| 1372 base::TimeDelta delta = deadline - gfx::FrameTime::Now(); | 1356 base::TimeDelta delta = deadline - gfx::FrameTime::Now(); |
| 1373 if (delta <= base::TimeDelta()) | 1357 if (delta <= base::TimeDelta()) |
| 1374 delta = base::TimeDelta(); | 1358 delta = base::TimeDelta(); |
| 1375 Proxy::ImplThreadTaskRunner()->PostDelayedTask(FROM_HERE, closure, delta); | 1359 Proxy::ImplThreadTaskRunner()->PostDelayedTask(FROM_HERE, closure, delta); |
| 1376 } | 1360 } |
| 1377 | 1361 |
| (...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1702 !impl().layer_tree_host_impl->pending_tree()) { | 1686 !impl().layer_tree_host_impl->pending_tree()) { |
| 1703 TRACE_EVENT_INSTANT0( | 1687 TRACE_EVENT_INSTANT0( |
| 1704 "cc", "ReleaseCommitbyActivation", TRACE_EVENT_SCOPE_THREAD); | 1688 "cc", "ReleaseCommitbyActivation", TRACE_EVENT_SCOPE_THREAD); |
| 1705 DCHECK(impl().layer_tree_host_impl->settings().impl_side_painting); | 1689 DCHECK(impl().layer_tree_host_impl->settings().impl_side_painting); |
| 1706 impl().completion_event_for_commit_held_on_tree_activation->Signal(); | 1690 impl().completion_event_for_commit_held_on_tree_activation->Signal(); |
| 1707 impl().completion_event_for_commit_held_on_tree_activation = NULL; | 1691 impl().completion_event_for_commit_held_on_tree_activation = NULL; |
| 1708 } | 1692 } |
| 1709 | 1693 |
| 1710 UpdateBackgroundAnimateTicking(); | 1694 UpdateBackgroundAnimateTicking(); |
| 1711 | 1695 |
| 1712 impl().commit_to_activate_duration_history.InsertSample( | 1696 impl().timing_history.DidActivatePendingTree(); |
| 1713 base::TimeTicks::HighResNow() - impl().commit_complete_time); | |
| 1714 } | 1697 } |
| 1715 | 1698 |
| 1716 void ThreadProxy::DidManageTiles() { | 1699 void ThreadProxy::DidManageTiles() { |
| 1717 DCHECK(IsImplThread()); | 1700 DCHECK(IsImplThread()); |
| 1718 impl().scheduler->DidManageTiles(); | 1701 impl().scheduler->DidManageTiles(); |
| 1719 } | 1702 } |
| 1720 | 1703 |
| 1721 } // namespace cc | 1704 } // namespace cc |
| OLD | NEW |