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