Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(493)

Side by Side Diff: cc/ring_buffer.h

Issue 11817011: cc: add RingBuffer class for timestamp storing in FrameRateCounter (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: switched to FrameRateCounter has a RingBuffer Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2013 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 #ifndef CC_RING_BUFFER_H_
6 #define CC_RING_BUFFER_H_
7
8 namespace cc {
9
10 template<typename T, unsigned int size>
11 class RingBuffer {
12 public:
13 explicit RingBuffer()
14 : current_index_(0) {
15 }
16
17 unsigned int BufferSize() const {
18 return size;
19 }
20
21 unsigned int CurrentIndex() const {
22 return current_index_;
23 }
24
25 // tests if a value was saved to this index
26 bool IsFilledIndex(unsigned int n) const {
shawnsingh 2013/01/10 21:13:01 I just noticed that the style guide asks us never
danakj 2013/01/10 23:31:40 What, are you sure it doesn't mean to use "unsigne
27 return BufferIndex(n) < current_index_;
28 }
29
30 // n = 0 returns the oldest value and
31 // n = bufferSize() - 1 returns the most recent value.
32 T ReadBuffer(unsigned int n) const {
33 return buffer_[BufferIndex(n)];
shawnsingh 2013/01/10 21:13:01 Can we DCHECK here that n is always >= 0 and stric
34 }
35
36 void SaveToBuffer(T value)
37 {
38 buffer_[BufferIndex(0)] = value;
39 current_index_++;
40 }
41
42 private:
43 inline int BufferIndex(int n) const {
44 return (current_index_ + n) % size;
45 }
46
47 T buffer_[size];
48 unsigned int current_index_;
49 };
50
51 } // namespace cc
52
53 #endif // CC_RING_BUFFER_H_
OLDNEW
« cc/heads_up_display_layer_impl.cc ('K') | « cc/layer_tree_host_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698