Chromium Code Reviews| 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/scheduler/delay_based_time_source.h" | 5 #include "cc/scheduler/delay_based_time_source.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <cmath> | 8 #include <cmath> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 56 TRACE_EVENT1("cc", "DelayBasedTimeSource::SetActive", "active", active); | 56 TRACE_EVENT1("cc", "DelayBasedTimeSource::SetActive", "active", active); |
| 57 if (active == active_) | 57 if (active == active_) |
| 58 return base::TimeTicks(); | 58 return base::TimeTicks(); |
| 59 active_ = active; | 59 active_ = active; |
| 60 | 60 |
| 61 if (!active_) { | 61 if (!active_) { |
| 62 weak_factory_.InvalidateWeakPtrs(); | 62 weak_factory_.InvalidateWeakPtrs(); |
| 63 return base::TimeTicks(); | 63 return base::TimeTicks(); |
| 64 } | 64 } |
| 65 | 65 |
| 66 PostNextTickTask(Now()); | 66 base::TimeTicks now = Now(); |
| 67 PostNextTickTask(now); | |
| 68 | |
| 69 if (current_parameters_.tick_target <= now) | |
| 70 return base::TimeTicks(); | |
| 67 | 71 |
| 68 // Determine if there was a tick that was missed while not active. | 72 // Determine if there was a tick that was missed while not active. |
| 69 base::TimeTicks last_tick_time_if_always_active = | 73 base::TimeTicks last_tick_time_if_always_active = |
| 70 current_parameters_.tick_target - current_parameters_.interval; | 74 current_parameters_.tick_target - current_parameters_.interval; |
| 71 base::TimeTicks new_tick_time_threshold = | 75 base::TimeTicks new_tick_time_threshold = |
| 72 last_tick_time_ + current_parameters_.interval / kDoubleTickDivisor; | 76 last_tick_time_ + current_parameters_.interval / kDoubleTickDivisor; |
| 73 if (last_tick_time_if_always_active > new_tick_time_threshold) { | 77 if (last_tick_time_if_always_active > new_tick_time_threshold) { |
| 74 last_tick_time_ = last_tick_time_if_always_active; | 78 last_tick_time_ = last_tick_time_if_always_active; |
| 75 return last_tick_time_; | 79 return last_tick_time_; |
| 76 } | 80 } |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 220 // 2) Jittery data is passed to SetTimebaseAndInterval(). | 224 // 2) Jittery data is passed to SetTimebaseAndInterval(). |
| 221 if (new_tick_target - last_tick_time_ <= | 225 if (new_tick_target - last_tick_time_ <= |
| 222 next_parameters_.interval / kDoubleTickDivisor) | 226 next_parameters_.interval / kDoubleTickDivisor) |
| 223 new_tick_target += next_parameters_.interval; | 227 new_tick_target += next_parameters_.interval; |
| 224 | 228 |
| 225 return new_tick_target; | 229 return new_tick_target; |
| 226 } | 230 } |
| 227 | 231 |
| 228 void DelayBasedTimeSource::PostNextTickTask(base::TimeTicks now) { | 232 void DelayBasedTimeSource::PostNextTickTask(base::TimeTicks now) { |
| 229 base::TimeTicks new_tick_target = NextTickTarget(now); | 233 base::TimeTicks new_tick_target = NextTickTarget(now); |
| 234 DCHECK(new_tick_target >= now); | |
|
brianderson
2015/06/23 21:00:29
DCHECK_GE
| |
| 230 | 235 |
| 231 // Post another task *before* the tick and update state | 236 // Post another task *before* the tick and update state |
| 232 base::TimeDelta delay; | 237 base::TimeDelta delay = new_tick_target - now; |
| 233 if (now <= new_tick_target) | |
|
brianderson
2015/06/23 21:00:29
I forget why this was needed. Could small jitter i
sunnyps
2015/06/26 00:45:28
This condition should always be true. See the DCHE
| |
| 234 delay = new_tick_target - now; | |
| 235 task_runner_->PostDelayedTask(FROM_HERE, | 238 task_runner_->PostDelayedTask(FROM_HERE, |
| 236 base::Bind(&DelayBasedTimeSource::OnTimerFired, | 239 base::Bind(&DelayBasedTimeSource::OnTimerFired, |
| 237 weak_factory_.GetWeakPtr()), | 240 weak_factory_.GetWeakPtr()), |
| 238 delay); | 241 delay); |
| 239 | 242 |
| 240 next_parameters_.tick_target = new_tick_target; | 243 next_parameters_.tick_target = new_tick_target; |
| 241 current_parameters_ = next_parameters_; | 244 current_parameters_ = next_parameters_; |
| 242 } | 245 } |
| 243 | 246 |
| 244 std::string DelayBasedTimeSource::TypeString() const { | 247 std::string DelayBasedTimeSource::TypeString() const { |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 261 state->BeginDictionary("next_parameters"); | 264 state->BeginDictionary("next_parameters"); |
| 262 state->SetDouble("interval_us", next_parameters_.interval.InMicroseconds()); | 265 state->SetDouble("interval_us", next_parameters_.interval.InMicroseconds()); |
| 263 state->SetDouble("tick_target_us", | 266 state->SetDouble("tick_target_us", |
| 264 next_parameters_.tick_target.ToInternalValue()); | 267 next_parameters_.tick_target.ToInternalValue()); |
| 265 state->EndDictionary(); | 268 state->EndDictionary(); |
| 266 | 269 |
| 267 state->SetBoolean("active", active_); | 270 state->SetBoolean("active", active_); |
| 268 } | 271 } |
| 269 | 272 |
| 270 } // namespace cc | 273 } // namespace cc |
| OLD | NEW |