cc: Added inline to Tile::IsReadyToDraw
[chromium-blink-merge.git] / cc / test / lap_timer.cc
blob6d16ba7530fb89d267c5de33f8a4679d291985a9
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "cc/test/lap_timer.h"
7 #include "base/logging.h"
9 namespace cc {
11 LapTimer::LapTimer(int warmup_laps,
12 base::TimeDelta time_limit,
13 int check_interval)
14 : warmup_laps_(warmup_laps),
15 time_limit_(time_limit),
16 check_interval_(check_interval) {
17 DCHECK_GT(check_interval, 0);
18 Reset();
21 void LapTimer::Reset() {
22 accumulator_ = base::TimeDelta();
23 num_laps_ = 0;
24 accumulated_ = true;
25 remaining_warmups_ = warmup_laps_;
26 Start();
29 void LapTimer::Start() { start_time_ = base::TimeTicks::HighResNow(); }
31 bool LapTimer::IsWarmedUp() { return remaining_warmups_ <= 0; }
33 void LapTimer::NextLap() {
34 if (!IsWarmedUp()) {
35 --remaining_warmups_;
36 if (IsWarmedUp()) {
37 Start();
39 return;
41 ++num_laps_;
42 accumulated_ = (num_laps_ % check_interval_) == 0;
43 if (accumulated_) {
44 base::TimeTicks now = base::TimeTicks::HighResNow();
45 accumulator_ += now - start_time_;
46 start_time_ = now;
50 bool LapTimer::HasTimeLimitExpired() { return accumulator_ >= time_limit_; }
52 float LapTimer::MsPerLap() {
53 DCHECK(accumulated_);
54 return accumulator_.InMillisecondsF() / num_laps_;
57 float LapTimer::LapsPerSecond() {
58 DCHECK(accumulated_);
59 return num_laps_ / accumulator_.InSecondsF();
62 int LapTimer::NumLaps() { return num_laps_; }
64 } // namespace cc