OLD | NEW |
(Empty) | |
| 1 // Copyright 2012 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. |
| 4 |
| 5 #include "cc/paint_time_counter.h" |
| 6 |
| 7 namespace cc { |
| 8 |
| 9 // static |
| 10 scoped_ptr<PaintTimeCounter> PaintTimeCounter::create() { |
| 11 return make_scoped_ptr(new PaintTimeCounter()); |
| 12 } |
| 13 |
| 14 PaintTimeCounter::PaintTimeCounter() { |
| 15 } |
| 16 |
| 17 base::TimeDelta PaintTimeCounter::GetPaintTimeOfRecentFrame( |
| 18 const size_t& n) const { |
| 19 DCHECK(n < ring_buffer_.BufferSize()); |
| 20 |
| 21 if (ring_buffer_.IsFilledIndex(n)) |
| 22 return ring_buffer_.ReadBuffer(n); |
| 23 |
| 24 return base::TimeDelta(); |
| 25 } |
| 26 |
| 27 void PaintTimeCounter::SavePaintTime(const base::TimeDelta& total_paint_time) { |
| 28 base::TimeDelta paint_time = total_paint_time - last_total_paint_time_; |
| 29 |
| 30 if (paint_time.InMillisecondsF() > 0) |
| 31 ring_buffer_.SaveToBuffer(paint_time); |
| 32 |
| 33 last_total_paint_time_ = total_paint_time; |
| 34 } |
| 35 |
| 36 void PaintTimeCounter::GetMinAndMaxPaintTime(base::TimeDelta* min, |
| 37 base::TimeDelta* max) const { |
| 38 *min = base::TimeDelta::FromDays(1); |
| 39 *max = base::TimeDelta(); |
| 40 |
| 41 for (size_t i = 0; i < ring_buffer_.BufferSize(); i++) { |
| 42 if (ring_buffer_.IsFilledIndex(i)) { |
| 43 base::TimeDelta paint_time = ring_buffer_.ReadBuffer(i); |
| 44 |
| 45 if (paint_time < *min) |
| 46 *min = paint_time; |
| 47 if (paint_time > *max) |
| 48 *max = paint_time; |
| 49 } |
| 50 } |
| 51 |
| 52 if (*min > *max) |
| 53 *min = *max; |
| 54 } |
| 55 |
| 56 } // namespace cc |
OLD | NEW |