Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(143)

Side by Side Diff: cc/delay_based_time_source.cc

Issue 11192030: cc: Switch to Chromium DCHECKs LOGs (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: dcheck and ndebug Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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"
9 #include "TraceEvent.h" 10 #include "TraceEvent.h"
10 #include <algorithm> 11 #include <algorithm>
11 #include <wtf/CurrentTime.h> 12 #include <wtf/CurrentTime.h>
12 #include <wtf/MathExtras.h> 13 #include <wtf/MathExtras.h>
13 14
14 namespace cc { 15 namespace cc {
15 16
16 namespace { 17 namespace {
17 18
18 // doubleTickThreshold prevents ticks from running within the specified fraction of an interval. 19 // doubleTickThreshold prevents ticks from running within the specified fraction of an interval.
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 return m_lastTickTime; 85 return m_lastTickTime;
85 } 86 }
86 87
87 base::TimeTicks CCDelayBasedTimeSource::nextTickTime() 88 base::TimeTicks CCDelayBasedTimeSource::nextTickTime()
88 { 89 {
89 return active() ? m_currentParameters.tickTarget : base::TimeTicks(); 90 return active() ? m_currentParameters.tickTarget : base::TimeTicks();
90 } 91 }
91 92
92 void CCDelayBasedTimeSource::onTimerFired() 93 void CCDelayBasedTimeSource::onTimerFired()
93 { 94 {
94 ASSERT(m_state != STATE_INACTIVE); 95 DCHECK(m_state != STATE_INACTIVE);
95 96
96 base::TimeTicks now = this->now(); 97 base::TimeTicks now = this->now();
97 m_lastTickTime = now; 98 m_lastTickTime = now;
98 99
99 if (m_state == STATE_STARTING) { 100 if (m_state == STATE_STARTING) {
100 setTimebaseAndInterval(now, m_currentParameters.interval); 101 setTimebaseAndInterval(now, m_currentParameters.interval);
101 m_state = STATE_ACTIVE; 102 m_state = STATE_ACTIVE;
102 } 103 }
103 104
104 postNextTickTask(now); 105 postNextTickTask(now);
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 // 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.
197 // 198 //
198 // 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.
199 // 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)
200 base::TimeTicks CCDelayBasedTimeSource::nextTickTarget(base::TimeTicks now) 201 base::TimeTicks CCDelayBasedTimeSource::nextTickTarget(base::TimeTicks now)
201 { 202 {
202 base::TimeDelta newInterval = m_nextParameters.interval; 203 base::TimeDelta newInterval = m_nextParameters.interval;
203 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()));
204 base::TimeTicks lastEffectiveTick = m_nextParameters.tickTarget + newInterva l * intervalsElapsed; 205 base::TimeTicks lastEffectiveTick = m_nextParameters.tickTarget + newInterva l * intervalsElapsed;
205 base::TimeTicks newTickTarget = lastEffectiveTick + newInterval; 206 base::TimeTicks newTickTarget = lastEffectiveTick + newInterval;
206 ASSERT(newTickTarget > now); 207 DCHECK(newTickTarget > now);
207 208
208 // Avoid double ticks when: 209 // Avoid double ticks when:
209 // 1) Turning off the timer and turning it right back on. 210 // 1) Turning off the timer and turning it right back on.
210 // 2) Jittery data is passed to setTimebaseAndInterval(). 211 // 2) Jittery data is passed to setTimebaseAndInterval().
211 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))
212 newTickTarget += newInterval; 213 newTickTarget += newInterval;
213 214
214 return newTickTarget; 215 return newTickTarget;
215 } 216 }
216 217
217 void CCDelayBasedTimeSource::postNextTickTask(base::TimeTicks now) 218 void CCDelayBasedTimeSource::postNextTickTask(base::TimeTicks now)
218 { 219 {
219 base::TimeTicks newTickTarget = nextTickTarget(now); 220 base::TimeTicks newTickTarget = nextTickTarget(now);
220 221
221 // Post another task *before* the tick and update state 222 // Post another task *before* the tick and update state
222 base::TimeDelta delay = newTickTarget - now; 223 base::TimeDelta delay = newTickTarget - now;
223 ASSERT(delay.InMillisecondsF() <= 224 DCHECK(delay.InMillisecondsF() <=
224 m_nextParameters.interval.InMillisecondsF() * (1.0 + doubleTickThresh old)); 225 m_nextParameters.interval.InMillisecondsF() * (1.0 + doubleTickThresh old));
225 m_timer.startOneShot(delay.InSecondsF()); 226 m_timer.startOneShot(delay.InSecondsF());
226 227
227 m_nextParameters.tickTarget = newTickTarget; 228 m_nextParameters.tickTarget = newTickTarget;
228 m_currentParameters = m_nextParameters; 229 m_currentParameters = m_nextParameters;
229 } 230 }
230 231
231 } // namespace cc 232 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698