| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 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 | 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/debug/paint_time_counter.h" | 5 #include "cc/debug/paint_time_counter.h" |
| 6 | 6 |
| 7 namespace cc { | 7 namespace cc { |
| 8 | 8 |
| 9 // static | 9 // static |
| 10 scoped_ptr<PaintTimeCounter> PaintTimeCounter::Create() { | 10 scoped_ptr<PaintTimeCounter> PaintTimeCounter::Create() { |
| 11 return make_scoped_ptr(new PaintTimeCounter()); | 11 return make_scoped_ptr(new PaintTimeCounter()); |
| 12 } | 12 } |
| 13 | 13 |
| 14 PaintTimeCounter::PaintTimeCounter() | 14 PaintTimeCounter::PaintTimeCounter() { |
| 15 : can_save_paint_time_delta_(false) { | |
| 16 } | 15 } |
| 17 | 16 |
| 18 void PaintTimeCounter::SavePaintTime(const base::TimeDelta& total_paint_time) { | 17 void PaintTimeCounter::SavePaintTime(const base::TimeDelta& paint_time) { |
| 19 if (can_save_paint_time_delta_) { | 18 ring_buffer_.SaveToBuffer(paint_time); |
| 20 base::TimeDelta paint_time = total_paint_time - last_total_paint_time_; | |
| 21 ring_buffer_.SaveToBuffer(paint_time); | |
| 22 } | |
| 23 | |
| 24 last_total_paint_time_ = total_paint_time; | |
| 25 can_save_paint_time_delta_ = true; | |
| 26 } | 19 } |
| 27 | 20 |
| 28 void PaintTimeCounter::GetMinAndMaxPaintTime(base::TimeDelta* min, | 21 void PaintTimeCounter::GetMinAndMaxPaintTime(base::TimeDelta* min, |
| 29 base::TimeDelta* max) const { | 22 base::TimeDelta* max) const { |
| 30 *min = base::TimeDelta::FromDays(1); | 23 *min = base::TimeDelta::FromDays(1); |
| 31 *max = base::TimeDelta(); | 24 *max = base::TimeDelta(); |
| 32 | 25 |
| 33 for (RingBufferType::Iterator it = ring_buffer_.Begin(); it; ++it) { | 26 for (RingBufferType::Iterator it = ring_buffer_.Begin(); it; ++it) { |
| 34 const base::TimeDelta paint_time = **it; | 27 const base::TimeDelta paint_time = **it; |
| 35 | 28 |
| 36 if (paint_time < *min) | 29 if (paint_time < *min) |
| 37 *min = paint_time; | 30 *min = paint_time; |
| 38 if (paint_time > *max) | 31 if (paint_time > *max) |
| 39 *max = paint_time; | 32 *max = paint_time; |
| 40 } | 33 } |
| 41 | 34 |
| 42 if (*min > *max) | 35 if (*min > *max) |
| 43 *min = *max; | 36 *min = *max; |
| 44 } | 37 } |
| 45 | 38 |
| 46 void PaintTimeCounter::ClearHistory() { | 39 void PaintTimeCounter::ClearHistory() { |
| 47 ring_buffer_.Clear(); | 40 ring_buffer_.Clear(); |
| 48 can_save_paint_time_delta_ = false; | |
| 49 } | 41 } |
| 50 | 42 |
| 51 } // namespace cc | 43 } // namespace cc |
| OLD | NEW |