Chromium Code Reviews| Index: cc/scheduler/delay_based_time_source.cc |
| diff --git a/cc/scheduler/delay_based_time_source.cc b/cc/scheduler/delay_based_time_source.cc |
| index 5d2f20bee6fd41695b9bcf84d85bd2ca50138163..5cd3ddd6f7c55a5bd7739f7c6e35e81ce299b54b 100644 |
| --- a/cc/scheduler/delay_based_time_source.cc |
| +++ b/cc/scheduler/delay_based_time_source.cc |
| @@ -15,10 +15,10 @@ namespace cc { |
| namespace { |
| -// kDoubleTickThreshold prevents ticks from running within the specified |
| +// kDoubleTickDivisor prevents ticks from running within the specified |
| // fraction of an interval. This helps account for jitter in the timebase as |
| // well as quick timer reactivation. |
| -static const double kDoubleTickThreshold = 0.25; |
| +static const int kDoubleTickDivisor = 4; |
|
brianderson
2013/07/03 00:01:54
We can divide TimeTicks so I switched this to a di
|
| // kIntervalChangeThreshold is the fraction of the interval that will trigger an |
| // immediate interval change. kPhaseChangeThreshold is the fraction of the |
| @@ -87,13 +87,11 @@ base::TimeTicks DelayBasedTimeSource::NextTickTime() { |
| void DelayBasedTimeSource::OnTimerFired() { |
| DCHECK(state_ != STATE_INACTIVE); |
| - base::TimeTicks now = this->Now(); |
| - last_tick_time_ = now; |
| + last_tick_time_ = current_parameters_.tick_target; |
|
brianderson
2013/07/03 00:01:54
Instead of setting the last_tick_time_ to the time
|
| - if (state_ == STATE_STARTING) { |
| - SetTimebaseAndInterval(now, current_parameters_.interval); |
| + base::TimeTicks now = this->Now(); |
| + if (state_ == STATE_STARTING) |
| state_ = STATE_ACTIVE; |
| - } |
| PostNextTickTask(now); |
| @@ -123,6 +121,7 @@ void DelayBasedTimeSource::SetTimebaseAndInterval(base::TimeTicks timebase, |
| std::abs((interval - current_parameters_.interval).InSecondsF()); |
| double interval_change = interval_delta / interval.InSecondsF(); |
| if (interval_change > kIntervalChangeThreshold) { |
| + TRACE_EVENT0("cc", "DelayBasedTimeSource::IntervalChanged"); |
| SetActive(false); |
| SetActive(true); |
| return; |
| @@ -140,6 +139,7 @@ void DelayBasedTimeSource::SetTimebaseAndInterval(base::TimeTicks timebase, |
| fmod(target_delta, interval.InSecondsF()) / interval.InSecondsF(); |
| if (phase_change > kPhaseChangeThreshold && |
| phase_change < (1.0 - kPhaseChangeThreshold)) { |
| + TRACE_EVENT0("cc", "DelayBasedTimeSource::PhaseChanged"); |
|
brianderson
2013/07/03 00:01:54
IntervalChanged and PhaseChanged show up way too o
|
| SetActive(false); |
| SetActive(true); |
| return; |
| @@ -206,9 +206,7 @@ base::TimeTicks DelayBasedTimeSource::Now() const { |
| // tick(), PostDelayedTask(floor(50.000-37)) --> PostDelayedTask(13) |
| base::TimeTicks DelayBasedTimeSource::NextTickTarget(base::TimeTicks now) { |
| base::TimeDelta new_interval = next_parameters_.interval; |
| - int intervals_elapsed = |
| - static_cast<int>(floor((now - next_parameters_.tick_target).InSecondsF() / |
| - new_interval.InSecondsF())); |
| + int intervals_elapsed = (now - next_parameters_.tick_target) / new_interval; |
|
brianderson
2013/07/03 00:01:54
Goodbye floating point math.
|
| base::TimeTicks last_effective_tick = |
| next_parameters_.tick_target + new_interval * intervals_elapsed; |
| base::TimeTicks new_tick_target = last_effective_tick + new_interval; |
| @@ -223,8 +221,7 @@ base::TimeTicks DelayBasedTimeSource::NextTickTarget(base::TimeTicks now) { |
| // Avoid double ticks when: |
| // 1) Turning off the timer and turning it right back on. |
| // 2) Jittery data is passed to SetTimebaseAndInterval(). |
| - if (new_tick_target - last_tick_time_ <= |
| - new_interval / static_cast<int>(1.0 / kDoubleTickThreshold)) |
| + if (new_tick_target - last_tick_time_ <= new_interval / kDoubleTickDivisor) |
|
brianderson
2013/07/03 00:01:54
Goodbye more floating point math.
|
| new_tick_target += new_interval; |
| return new_tick_target; |
| @@ -234,10 +231,9 @@ void DelayBasedTimeSource::PostNextTickTask(base::TimeTicks now) { |
| base::TimeTicks new_tick_target = NextTickTarget(now); |
| // Post another task *before* the tick and update state |
| - base::TimeDelta delay = new_tick_target - now; |
| - DCHECK(delay.InMillisecondsF() <= |
| - next_parameters_.interval.InMillisecondsF() * |
| - (1.0 + kDoubleTickThreshold)); |
| + base::TimeDelta delay; |
| + if (new_tick_target > now) |
| + delay = new_tick_target - now; |
| task_runner_->PostDelayedTask(FROM_HERE, |
| base::Bind(&DelayBasedTimeSource::OnTimerFired, |
| weak_factory_.GetWeakPtr()), |