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 #ifndef CC_DEBUG_FRAME_RATE_COUNTER_H_ | 5 #ifndef CC_DEBUG_FRAME_RATE_COUNTER_H_ |
6 #define CC_DEBUG_FRAME_RATE_COUNTER_H_ | 6 #define CC_DEBUG_FRAME_RATE_COUNTER_H_ |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/time/time.h" | 10 #include "base/time/time.h" |
11 #include "cc/debug/ring_buffer.h" | 11 #include "cc/debug/ring_buffer.h" |
| 12 #include "ui/gfx/frame_time.h" |
12 | 13 |
13 namespace cc { | 14 namespace cc { |
14 | 15 |
15 // This class maintains a history of timestamps, and provides functionality to | 16 // This class maintains a history of timestamps, and provides functionality to |
16 // intelligently compute average frames per second. | 17 // intelligently compute average frames per second. |
17 class FrameRateCounter { | 18 class FrameRateCounter { |
18 public: | 19 public: |
19 static scoped_ptr<FrameRateCounter> Create(bool has_impl_thread); | 20 static scoped_ptr<FrameRateCounter> Create(bool has_impl_thread); |
20 | 21 |
21 int current_frame_number() const { return ring_buffer_.CurrentIndex(); } | 22 int current_frame_number() const { return ring_buffer_.CurrentIndex(); } |
22 int dropped_frame_count() const { return dropped_frame_count_; } | 23 int dropped_frame_count() const { return dropped_frame_count_; } |
23 size_t time_stamp_history_size() const { return ring_buffer_.BufferSize(); } | 24 size_t time_stamp_history_size() const { return ring_buffer_.BufferSize(); } |
24 | 25 |
25 void SaveTimeStamp(base::TimeTicks timestamp, bool software); | 26 void SaveTimeStamp(gfx::FrameTime timestamp, bool software); |
26 | 27 |
27 // n = 0 returns the oldest frame interval retained in the history, while n = | 28 // n = 0 returns the oldest frame interval retained in the history, while n = |
28 // time_stamp_history_size() - 1 returns the most recent frame interval. | 29 // time_stamp_history_size() - 1 returns the most recent frame interval. |
29 base::TimeDelta RecentFrameInterval(size_t n) const; | 30 base::TimeDelta RecentFrameInterval(size_t n) const; |
30 | 31 |
31 // This is a heuristic that can be used to ignore frames in a reasonable way. | 32 // This is a heuristic that can be used to ignore frames in a reasonable way. |
32 // Returns true if the given frame interval is too fast or too slow, based on | 33 // Returns true if the given frame interval is too fast or too slow, based on |
33 // constant thresholds. | 34 // constant thresholds. |
34 bool IsBadFrameInterval( | 35 bool IsBadFrameInterval( |
35 base::TimeDelta interval_between_consecutive_frames) const; | 36 base::TimeDelta interval_between_consecutive_frames) const; |
36 | 37 |
37 void GetMinAndMaxFPS(double* min_fps, double* max_fps) const; | 38 void GetMinAndMaxFPS(double* min_fps, double* max_fps) const; |
38 double GetAverageFPS() const; | 39 double GetAverageFPS() const; |
39 | 40 |
40 typedef RingBuffer<base::TimeTicks, 136> RingBufferType; | 41 typedef RingBuffer<gfx::FrameTime, 136> RingBufferType; |
41 RingBufferType::Iterator begin() const { return ring_buffer_.Begin(); } | 42 RingBufferType::Iterator begin() const { return ring_buffer_.Begin(); } |
42 RingBufferType::Iterator end() const { return ring_buffer_.End(); } | 43 RingBufferType::Iterator end() const { return ring_buffer_.End(); } |
43 | 44 |
44 private: | 45 private: |
45 explicit FrameRateCounter(bool has_impl_thread); | 46 explicit FrameRateCounter(bool has_impl_thread); |
46 | 47 |
47 RingBufferType ring_buffer_; | 48 RingBufferType ring_buffer_; |
48 | 49 |
49 bool has_impl_thread_; | 50 bool has_impl_thread_; |
50 int dropped_frame_count_; | 51 int dropped_frame_count_; |
51 | 52 |
52 DISALLOW_COPY_AND_ASSIGN(FrameRateCounter); | 53 DISALLOW_COPY_AND_ASSIGN(FrameRateCounter); |
53 }; | 54 }; |
54 | 55 |
55 } // namespace cc | 56 } // namespace cc |
56 | 57 |
57 #endif // CC_DEBUG_FRAME_RATE_COUNTER_H_ | 58 #endif // CC_DEBUG_FRAME_RATE_COUNTER_H_ |
OLD | NEW |