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

Unified 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: 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 side-by-side diff with in-line comments
Download patch
« cc/layer_tree_host_impl.cc ('K') | « cc/layer_tree_host_impl.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: cc/ring_buffer.h
diff --git a/cc/ring_buffer.h b/cc/ring_buffer.h
new file mode 100644
index 0000000000000000000000000000000000000000..2de3475b930f39f7155cee933cf4ab1d61b47fea
--- /dev/null
+++ b/cc/ring_buffer.h
@@ -0,0 +1,48 @@
+// Copyright 2012 The Chromium Authors. All rights reserved.
shawnsingh 2013/01/09 20:55:09 2013 now =)
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CC_RING_BUFFER_H_
shawnsingh 2013/01/09 20:55:09 As I understand, we are trying to make all new fil
+#define CC_RING_BUFFER_H_
+
+namespace cc {
+
+template<typename T, int size>
+class RingBuffer {
+public:
+ int bufferSize() const
+ {
+ return size;
+ }
+
+ // n = 0 returns the oldest value and
+ // n = bufferSize() - 1 returns the most recent value.
+ T readBuffer(int n) const
+ {
+ return m_buffer[bufferIndex(m_currentIndex + n)];
+ }
+
+protected:
+ explicit RingBuffer()
+ : m_currentIndex(0)
+ {
+ }
+
+ void saveToBuffer(T value)
+ {
+ m_buffer[bufferIndex(m_currentIndex)] = value;
+ m_currentIndex++;
+ }
+
+ inline int bufferIndex(int n) const
+ {
+ return (n % size + size) % size;
shawnsingh 2013/01/09 20:55:09 Wouldn't this be equivalent to (n+size) % size, w
+ }
+
+ T m_buffer[size];
+ int m_currentIndex;
+};
+
+} // namespace cc
+
+#endif // CC_RING_BUFFER_H_
« cc/layer_tree_host_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