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

Side by Side Diff: cc/scheduler/delay_based_time_source.cc

Issue 22887010: cc: Handle future timebases properly in DelayBasedTimeSource (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: nix extraneous epsilon Created 7 years, 4 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
« no previous file with comments | « no previous file | cc/scheduler/delay_based_time_source_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "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 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 // This brings us back to 18+15 = 33, which was where we would have been if the 186 // This brings us back to 18+15 = 33, which was where we would have been if the
187 // task hadn't been late. 187 // task hadn't been late.
188 // 188 //
189 // For the really late delay, we we move to the next logical tick. The timebase 189 // For the really late delay, we we move to the next logical tick. The timebase
190 // is not reset. 190 // is not reset.
191 // now=37 tick_target=16.667 new_target=50.000 --> 191 // now=37 tick_target=16.667 new_target=50.000 -->
192 // tick(), PostDelayedTask(floor(50.000-37)) --> PostDelayedTask(13) 192 // tick(), PostDelayedTask(floor(50.000-37)) --> PostDelayedTask(13)
193 base::TimeTicks DelayBasedTimeSource::NextTickTarget(base::TimeTicks now) { 193 base::TimeTicks DelayBasedTimeSource::NextTickTarget(base::TimeTicks now) {
194 const base::TimeDelta epsilon(base::TimeDelta::FromMicroseconds(1)); 194 const base::TimeDelta epsilon(base::TimeDelta::FromMicroseconds(1));
195 base::TimeDelta new_interval = next_parameters_.interval; 195 base::TimeDelta new_interval = next_parameters_.interval;
196 int intervals_elapsed = 196
197 (now - next_parameters_.tick_target + new_interval - epsilon) / 197 // Integer division rounds towards 0, but we always want to round down the
198 new_interval; 198 // number of intervals_elapsed, so we need the extra condition here.
199 int intervals_elapsed;
200 if (next_parameters_.tick_target < now) {
jdduke (slow) 2013/08/14 22:39:37 To make this a bit easier to read, what about defi
201 intervals_elapsed =
202 (now - next_parameters_.tick_target + new_interval - epsilon) /
203 new_interval;
204 } else {
205 intervals_elapsed = (now - next_parameters_.tick_target) / new_interval;
206 }
199 base::TimeTicks new_tick_target = 207 base::TimeTicks new_tick_target =
200 next_parameters_.tick_target + new_interval * intervals_elapsed; 208 next_parameters_.tick_target + new_interval * intervals_elapsed;
201 DCHECK(now <= new_tick_target) 209 DCHECK(now <= new_tick_target)
202 << "now = " << now.ToInternalValue() 210 << "now = " << now.ToInternalValue()
203 << "; new_tick_target = " << new_tick_target.ToInternalValue() 211 << "; new_tick_target = " << new_tick_target.ToInternalValue()
204 << "; new_interval = " << new_interval.InMicroseconds() 212 << "; new_interval = " << new_interval.InMicroseconds()
205 << "; tick_target = " << next_parameters_.tick_target.ToInternalValue() 213 << "; tick_target = " << next_parameters_.tick_target.ToInternalValue()
206 << "; intervals_elapsed = " << intervals_elapsed; 214 << "; intervals_elapsed = " << intervals_elapsed;
207 215
208 // Avoid double ticks when: 216 // Avoid double ticks when:
(...skipping 15 matching lines...) Expand all
224 task_runner_->PostDelayedTask(FROM_HERE, 232 task_runner_->PostDelayedTask(FROM_HERE,
225 base::Bind(&DelayBasedTimeSource::OnTimerFired, 233 base::Bind(&DelayBasedTimeSource::OnTimerFired,
226 weak_factory_.GetWeakPtr()), 234 weak_factory_.GetWeakPtr()),
227 delay); 235 delay);
228 236
229 next_parameters_.tick_target = new_tick_target; 237 next_parameters_.tick_target = new_tick_target;
230 current_parameters_ = next_parameters_; 238 current_parameters_ = next_parameters_;
231 } 239 }
232 240
233 } // namespace cc 241 } // namespace cc
OLDNEW
« no previous file with comments | « no previous file | cc/scheduler/delay_based_time_source_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698