Chromium Code Reviews| Index: cc/paint_time_counter.cc |
| diff --git a/cc/paint_time_counter.cc b/cc/paint_time_counter.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..baff1804eaea36039600bf45777ec0e61306aca7 |
| --- /dev/null |
| +++ b/cc/paint_time_counter.cc |
| @@ -0,0 +1,53 @@ |
| +// Copyright 2012 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "cc/paint_time_counter.h" |
| + |
| +#include <limits> |
| + |
| +namespace cc { |
| + |
| +// static |
| +scoped_ptr<PaintTimeCounter> PaintTimeCounter::create() { |
| + return make_scoped_ptr(new PaintTimeCounter()); |
| +} |
| + |
| +PaintTimeCounter::PaintTimeCounter() { |
| +} |
| + |
| +base::TimeDelta PaintTimeCounter::GetPaintTimeOfRecentFrame(const size_t& n) const { |
|
reveman
2013/01/16 22:48:04
nit: line not <= 80 characters long.
|
| + DCHECK(n < ring_buffer_.BufferSize()); |
| + |
| + if (ring_buffer_.IsFilledIndex(n)) |
| + return ring_buffer_.ReadBuffer(n); |
| + |
| + return base::TimeDelta(); |
| +} |
| + |
| +void PaintTimeCounter::SavePaintTime(const base::TimeDelta& total_paint_time) { |
| + base::TimeDelta paint_time = total_paint_time - last_total_paint_time_; |
| + |
| + if (paint_time.InMillisecondsF() > 0) |
| + ring_buffer_.SaveToBuffer(paint_time); |
| + |
| + last_total_paint_time_ = total_paint_time; |
| +} |
| + |
| +void PaintTimeCounter::GetMinAndMaxPaintTimeInMilliseconds(double* min, double* max) const { |
|
reveman
2013/01/16 22:48:04
nit: line not <= 80 characters long.
|
| + *min = std::numeric_limits<double>::max(); |
| + *max = 0; |
| + |
| + for (size_t i = 0; i < ring_buffer_.BufferSize(); i++) { |
|
egraether
2013/01/16 19:31:56
Loops in increasing direction because the iterator
|
| + if (ring_buffer_.IsFilledIndex(i)) { |
| + double paint_time = ring_buffer_.ReadBuffer(i).InMillisecondsF(); |
| + *min = std::min(paint_time, *min); |
| + *max = std::max(paint_time, *max); |
| + } |
| + } |
| + |
| + if (*min > *max) |
| + *min = *max; |
| +} |
| + |
| +} // namespace cc |