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/debug/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 : can_save_paint_time_delta_(false) { 16 } 17 18 void PaintTimeCounter::SavePaintTime(const base::TimeDelta& total_paint_time) { 19 if (can_save_paint_time_delta_) { 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 } 27 28 void PaintTimeCounter::GetMinAndMaxPaintTime(base::TimeDelta* min, 29 base::TimeDelta* max) const { 30 *min = base::TimeDelta::FromDays(1); 31 *max = base::TimeDelta(); 32 33 for (RingBufferType::Iterator it = ring_buffer_.Begin(); it; ++it) { 34 const base::TimeDelta paint_time = **it; 35 36 if (paint_time < *min) 37 *min = paint_time; 38 if (paint_time > *max) 39 *max = paint_time; 40 } 41 42 if (*min > *max) 43 *min = *max; 44 } 45 46 void PaintTimeCounter::ClearHistory() { 47 ring_buffer_.Clear(); 48 can_save_paint_time_delta_ = false; 49 } 50 51 } // namespace cc 52