Don't consider a Bluetooth adapter present until it has an address.
[chromium-blink-merge.git] / cc / CCFrameRateCounter.h
blob67763bc39c25d91c4af53813ff40033cc3b3d0da
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 CCFrameRateCounter_h
6 #define CCFrameRateCounter_h
8 #if USE(ACCELERATED_COMPOSITING)
10 #include <wtf/Noncopyable.h>
11 #include <wtf/PassOwnPtr.h>
13 namespace WebCore {
15 // This class maintains a history of timestamps, and provides functionality to
16 // intelligently compute average frames per second (and standard deviation).
17 class CCFrameRateCounter {
18 WTF_MAKE_NONCOPYABLE(CCFrameRateCounter);
19 public:
20 static PassOwnPtr<CCFrameRateCounter> create()
22 return adoptPtr(new CCFrameRateCounter());
25 void markBeginningOfFrame(double timestamp);
26 void markEndOfFrame();
27 int currentFrameNumber() const { return m_currentFrameNumber; }
28 void getAverageFPSAndStandardDeviation(double& averageFPS, double& standardDeviation) const;
29 int timeStampHistorySize() const { return kTimeStampHistorySize; }
31 // n = 0 returns the oldest frame retained in the history,
32 // while n = timeStampHistorySize() - 1 returns the timestamp most recent frame.
33 double timeStampOfRecentFrame(int /* n */);
35 // This is a heuristic that can be used to ignore frames in a reasonable way. Returns
36 // true if the given frame interval is too fast or too slow, based on constant thresholds.
37 bool isBadFrameInterval(double intervalBetweenConsecutiveFrames) const;
39 int droppedFrameCount() const { return m_droppedFrameCount; }
41 private:
42 CCFrameRateCounter();
44 double frameInterval(int frameNumber) const;
45 int frameIndex(int frameNumber) const;
46 bool isBadFrame(int frameNumber) const;
48 // Two thresholds (measured in seconds) that describe what is considered to be a "no-op frame" that should not be counted.
49 // - if the frame is too fast, then given our compositor implementation, the frame probably was a no-op and did not draw.
50 // - if the frame is too slow, then there is probably not animating content, so we should not pollute the average.
51 static const double kFrameTooFast;
52 static const double kFrameTooSlow;
54 // If a frame takes longer than this threshold (measured in seconds) then we
55 // (naively) assume that it missed a screen refresh; that is, we dropped a frame.
56 // FIXME: Determine this threshold based on monitor refresh rate, crbug.com/138642.
57 static const double kDroppedFrameTime;
59 static const int kTimeStampHistorySize = 120;
61 int m_currentFrameNumber;
62 double m_timeStampHistory[kTimeStampHistorySize];
64 int m_droppedFrameCount;
67 } // namespace WebCore
69 #endif // USE(ACCELERATED_COMPOSITING)
71 #endif