Make a copy of HttpResponseHeaders in StreamHandleImpl.
[chromium-blink-merge.git] / cc / debug / frame_rate_counter.h
blob0b69b29aea541be345102d281c1acbf130fa7a79
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.
5 #ifndef CC_DEBUG_FRAME_RATE_COUNTER_H_
6 #define CC_DEBUG_FRAME_RATE_COUNTER_H_
8 #include "base/basictypes.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "base/time/time.h"
11 #include "cc/debug/ring_buffer.h"
13 namespace cc {
15 // This class maintains a history of timestamps, and provides functionality to
16 // intelligently compute average frames per second.
17 class FrameRateCounter {
18 public:
19 static scoped_ptr<FrameRateCounter> Create(bool has_impl_thread);
21 int current_frame_number() const { return ring_buffer_.CurrentIndex(); }
22 int dropped_frame_count() const { return dropped_frame_count_; }
23 size_t time_stamp_history_size() const { return ring_buffer_.BufferSize(); }
25 void SaveTimeStamp(base::TimeTicks timestamp, bool software);
27 // 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 base::TimeDelta RecentFrameInterval(size_t n) const;
31 // 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 // constant thresholds.
34 bool IsBadFrameInterval(
35 base::TimeDelta interval_between_consecutive_frames) const;
37 void GetMinAndMaxFPS(double* min_fps, double* max_fps) const;
38 double GetAverageFPS() const;
40 typedef RingBuffer<base::TimeTicks, 136> RingBufferType;
41 RingBufferType::Iterator begin() const { return ring_buffer_.Begin(); }
42 RingBufferType::Iterator end() const { return ring_buffer_.End(); }
44 private:
45 explicit FrameRateCounter(bool has_impl_thread);
47 RingBufferType ring_buffer_;
49 bool has_impl_thread_;
50 int dropped_frame_count_;
52 DISALLOW_COPY_AND_ASSIGN(FrameRateCounter);
55 } // namespace cc
57 #endif // CC_DEBUG_FRAME_RATE_COUNTER_H_