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 "config.h" | 5 #include "config.h" |
6 | 6 |
7 #include "CCDelayBasedTimeSource.h" | 7 #include "CCDelayBasedTimeSource.h" |
8 | 8 |
9 #include "TraceEvent.h" | 9 #include "TraceEvent.h" |
10 #include <algorithm> | 10 #include <algorithm> |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 return m_lastTickTime; | 85 return m_lastTickTime; |
86 } | 86 } |
87 | 87 |
88 base::TimeTicks CCDelayBasedTimeSource::nextTickTime() | 88 base::TimeTicks CCDelayBasedTimeSource::nextTickTime() |
89 { | 89 { |
90 return active() ? m_currentParameters.tickTarget : base::TimeTicks(); | 90 return active() ? m_currentParameters.tickTarget : base::TimeTicks(); |
91 } | 91 } |
92 | 92 |
93 void CCDelayBasedTimeSource::onTimerFired() | 93 void CCDelayBasedTimeSource::onTimerFired() |
94 { | 94 { |
95 ASSERT(m_state != STATE_INACTIVE); | 95 DCHECK(m_state != STATE_INACTIVE); |
96 | 96 |
97 base::TimeTicks now = this->now(); | 97 base::TimeTicks now = this->now(); |
98 m_lastTickTime = now; | 98 m_lastTickTime = now; |
99 | 99 |
100 if (m_state == STATE_STARTING) { | 100 if (m_state == STATE_STARTING) { |
101 setTimebaseAndInterval(now, m_currentParameters.interval); | 101 setTimebaseAndInterval(now, m_currentParameters.interval); |
102 m_state = STATE_ACTIVE; | 102 m_state = STATE_ACTIVE; |
103 } | 103 } |
104 | 104 |
105 postNextTickTask(now); | 105 postNextTickTask(now); |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 // This brings us back to 18+15 = 33, which was where we would have been if the
task hadn't been late. | 197 // This brings us back to 18+15 = 33, which was where we would have been if the
task hadn't been late. |
198 // | 198 // |
199 // For the really late delay, we we move to the next logical tick. The timebase
is not reset. | 199 // For the really late delay, we we move to the next logical tick. The timebase
is not reset. |
200 // now=37 tickTarget=16.667 newTarget=50.000 --> tick(), postDelayedTas
k(floor(50.000-37)) --> postDelayedTask(13) | 200 // now=37 tickTarget=16.667 newTarget=50.000 --> tick(), postDelayedTas
k(floor(50.000-37)) --> postDelayedTask(13) |
201 base::TimeTicks CCDelayBasedTimeSource::nextTickTarget(base::TimeTicks now) | 201 base::TimeTicks CCDelayBasedTimeSource::nextTickTarget(base::TimeTicks now) |
202 { | 202 { |
203 base::TimeDelta newInterval = m_nextParameters.interval; | 203 base::TimeDelta newInterval = m_nextParameters.interval; |
204 int intervalsElapsed = static_cast<int>(floor((now - m_nextParameters.tickTa
rget).InSecondsF() / newInterval.InSecondsF())); | 204 int intervalsElapsed = static_cast<int>(floor((now - m_nextParameters.tickTa
rget).InSecondsF() / newInterval.InSecondsF())); |
205 base::TimeTicks lastEffectiveTick = m_nextParameters.tickTarget + newInterva
l * intervalsElapsed; | 205 base::TimeTicks lastEffectiveTick = m_nextParameters.tickTarget + newInterva
l * intervalsElapsed; |
206 base::TimeTicks newTickTarget = lastEffectiveTick + newInterval; | 206 base::TimeTicks newTickTarget = lastEffectiveTick + newInterval; |
207 ASSERT(newTickTarget > now); | 207 DCHECK(newTickTarget > now); |
208 | 208 |
209 // Avoid double ticks when: | 209 // Avoid double ticks when: |
210 // 1) Turning off the timer and turning it right back on. | 210 // 1) Turning off the timer and turning it right back on. |
211 // 2) Jittery data is passed to setTimebaseAndInterval(). | 211 // 2) Jittery data is passed to setTimebaseAndInterval(). |
212 if (newTickTarget - m_lastTickTime <= newInterval / static_cast<int>(1.0 / d
oubleTickThreshold)) | 212 if (newTickTarget - m_lastTickTime <= newInterval / static_cast<int>(1.0 / d
oubleTickThreshold)) |
213 newTickTarget += newInterval; | 213 newTickTarget += newInterval; |
214 | 214 |
215 return newTickTarget; | 215 return newTickTarget; |
216 } | 216 } |
217 | 217 |
218 void CCDelayBasedTimeSource::postNextTickTask(base::TimeTicks now) | 218 void CCDelayBasedTimeSource::postNextTickTask(base::TimeTicks now) |
219 { | 219 { |
220 base::TimeTicks newTickTarget = nextTickTarget(now); | 220 base::TimeTicks newTickTarget = nextTickTarget(now); |
221 | 221 |
222 // Post another task *before* the tick and update state | 222 // Post another task *before* the tick and update state |
223 base::TimeDelta delay = newTickTarget - now; | 223 base::TimeDelta delay = newTickTarget - now; |
224 ASSERT(delay.InMillisecondsF() <= | 224 DCHECK(delay.InMillisecondsF() <= |
225 m_nextParameters.interval.InMillisecondsF() * (1.0 + doubleTickThresh
old)); | 225 m_nextParameters.interval.InMillisecondsF() * (1.0 + doubleTickThresh
old)); |
226 m_timer.startOneShot(delay.InSecondsF()); | 226 m_timer.startOneShot(delay.InSecondsF()); |
227 | 227 |
228 m_nextParameters.tickTarget = newTickTarget; | 228 m_nextParameters.tickTarget = newTickTarget; |
229 m_currentParameters = m_nextParameters; | 229 m_currentParameters = m_nextParameters; |
230 } | 230 } |
231 | 231 |
232 } | 232 } |
OLD | NEW |