summaryrefslogtreecommitdiffstats
path: root/cc/frame_rate_counter.h
diff options
context:
space:
mode:
authorenne@chromium.org <enne@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-10-12 22:43:41 +0000
committerenne@chromium.org <enne@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-10-12 22:43:41 +0000
commitcd57cc5a246367c2558fefa04ae9eca8f4d545d2 (patch)
treea2235045e9c5e4ff028d641b76f5d01aa5461b26 /cc/frame_rate_counter.h
parent3fe7ba055be580443445895c0ee01ada3b628487 (diff)
downloadchromium_src-cd57cc5a246367c2558fefa04ae9eca8f4d545d2.zip
chromium_src-cd57cc5a246367c2558fefa04ae9eca8f4d545d2.tar.gz
chromium_src-cd57cc5a246367c2558fefa04ae9eca8f4d545d2.tar.bz2
[cc] Rename all cc/ filenames to Chromium style
BUG=155413 Review URL: https://codereview.chromium.org/11122003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@161671 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'cc/frame_rate_counter.h')
-rw-r--r--cc/frame_rate_counter.h69
1 files changed, 69 insertions, 0 deletions
diff --git a/cc/frame_rate_counter.h b/cc/frame_rate_counter.h
index 638cbb2..76b4224 100644
--- a/cc/frame_rate_counter.h
+++ b/cc/frame_rate_counter.h
@@ -1,3 +1,72 @@
// Copyright 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+
+#ifndef CCFrameRateCounter_h
+#define CCFrameRateCounter_h
+
+#if USE(ACCELERATED_COMPOSITING)
+
+#include "base/basictypes.h"
+#include <wtf/PassOwnPtr.h>
+
+namespace cc {
+
+// This class maintains a history of timestamps, and provides functionality to
+// intelligently compute average frames per second (and standard deviation).
+class CCFrameRateCounter {
+public:
+ static PassOwnPtr<CCFrameRateCounter> create()
+ {
+ return adoptPtr(new CCFrameRateCounter());
+ }
+
+ void markBeginningOfFrame(double timestamp);
+ void markEndOfFrame();
+ int currentFrameNumber() const { return m_currentFrameNumber; }
+ void getAverageFPSAndStandardDeviation(double& averageFPS, double& standardDeviation) const;
+ int timeStampHistorySize() const { return kTimeStampHistorySize; }
+
+ // n = 0 returns the oldest frame retained in the history,
+ // while n = timeStampHistorySize() - 1 returns the timestamp most recent frame.
+ double timeStampOfRecentFrame(int /* n */);
+
+ // This is a heuristic that can be used to ignore frames in a reasonable way. Returns
+ // true if the given frame interval is too fast or too slow, based on constant thresholds.
+ bool isBadFrameInterval(double intervalBetweenConsecutiveFrames) const;
+
+ int droppedFrameCount() const { return m_droppedFrameCount; }
+
+private:
+ CCFrameRateCounter();
+
+ double frameInterval(int frameNumber) const;
+ int frameIndex(int frameNumber) const;
+ bool isBadFrame(int frameNumber) const;
+
+ // Two thresholds (measured in seconds) that describe what is considered to be a "no-op frame" that should not be counted.
+ // - if the frame is too fast, then given our compositor implementation, the frame probably was a no-op and did not draw.
+ // - if the frame is too slow, then there is probably not animating content, so we should not pollute the average.
+ static const double kFrameTooFast;
+ static const double kFrameTooSlow;
+
+ // If a frame takes longer than this threshold (measured in seconds) then we
+ // (naively) assume that it missed a screen refresh; that is, we dropped a frame.
+ // FIXME: Determine this threshold based on monitor refresh rate, crbug.com/138642.
+ static const double kDroppedFrameTime;
+
+ static const int kTimeStampHistorySize = 120;
+
+ int m_currentFrameNumber;
+ double m_timeStampHistory[kTimeStampHistorySize];
+
+ int m_droppedFrameCount;
+
+ DISALLOW_COPY_AND_ASSIGN(CCFrameRateCounter);
+};
+
+} // namespace cc
+
+#endif // USE(ACCELERATED_COMPOSITING)
+
+#endif