Index: cc/frame_rate_counter.cc |
diff --git a/cc/frame_rate_counter.cc b/cc/frame_rate_counter.cc |
index a02486bd0ec026e84e0d85f985f0d12ed7f3b15d..9e63977d70a437441d5745a8b50f1d3320c1d667 100644 |
--- a/cc/frame_rate_counter.cc |
+++ b/cc/frame_rate_counter.cc |
@@ -13,10 +13,6 @@ |
namespace cc { |
-const double CCFrameRateCounter::kFrameTooFast = 1.0 / 70.0; // measured in seconds |
-const double CCFrameRateCounter::kFrameTooSlow = 1.0 / 12.0; |
-const double CCFrameRateCounter::kDroppedFrameTime = 1.0 / 50.0; |
- |
// safeMod works on -1, returning m-1 in that case. |
static inline int safeMod(int number, int modulus) |
{ |
@@ -28,6 +24,19 @@ scoped_ptr<CCFrameRateCounter> CCFrameRateCounter::create() { |
return make_scoped_ptr(new CCFrameRateCounter()); |
} |
+void CCFrameRateCounter::setTimebaseAndInterval(base::TimeTicks timebase, base::TimeDelta interval) |
+{ |
+ if (interval != m_interval) { |
+ base::TimeTicks now = base::TimeTicks::Now(); |
+ m_vsyncCount = currentVsyncCount(now); |
+ m_intervalChangedTime = now; |
+ m_interval = interval; |
+ } |
+ |
+ m_frameTooFastSeconds = 0.8 * interval.InSecondsF(); |
+ m_frameTooSlowSeconds = 1.0 / 12.0; |
+} |
+ |
inline base::TimeDelta CCFrameRateCounter::frameInterval(int frameNumber) const |
{ |
return m_timeStampHistory[frameIndex(frameNumber)] - |
@@ -40,8 +49,10 @@ inline int CCFrameRateCounter::frameIndex(int frameNumber) const |
} |
CCFrameRateCounter::CCFrameRateCounter() |
- : m_currentFrameNumber(1) |
- , m_droppedFrameCount(0) |
+ : m_frameTooFastSeconds(0) |
+ , m_frameTooSlowSeconds(0) |
+ , m_vsyncCount(0) |
+ , m_currentFrameNumber(1) |
{ |
m_timeStampHistory[0] = base::TimeTicks::Now(); |
m_timeStampHistory[1] = m_timeStampHistory[0]; |
@@ -59,9 +70,6 @@ void CCFrameRateCounter::markBeginningOfFrame(base::TimeTicks timestamp) |
WebKit::Platform::current()->histogramCustomCounts("Renderer4.CompositorThreadImplDrawDelay", static_cast<int>(drawDelayMs), 1, 120, 60); |
} |
- if (!isBadFrameInterval(frameIntervalSeconds) && |
- frameIntervalSeconds.InSecondsF() > kDroppedFrameTime) |
- ++m_droppedFrameCount; |
} |
void CCFrameRateCounter::markEndOfFrame() |
@@ -71,9 +79,10 @@ void CCFrameRateCounter::markEndOfFrame() |
bool CCFrameRateCounter::isBadFrameInterval(base::TimeDelta intervalBetweenConsecutiveFrames) const |
{ |
+ ASSERT(m_interval != base::TimeDelta()); |
bool schedulerAllowsDoubleFrames = !CCProxy::hasImplThread(); |
- bool intervalTooFast = schedulerAllowsDoubleFrames && intervalBetweenConsecutiveFrames.InSecondsF() < kFrameTooFast; |
- bool intervalTooSlow = intervalBetweenConsecutiveFrames.InSecondsF() > kFrameTooSlow; |
+ bool intervalTooFast = schedulerAllowsDoubleFrames && intervalBetweenConsecutiveFrames.InSecondsF() < m_frameTooFastSeconds; |
+ bool intervalTooSlow = intervalBetweenConsecutiveFrames.InSecondsF() > m_frameTooSlowSeconds; |
return intervalTooFast || intervalTooSlow; |
} |
@@ -82,6 +91,14 @@ bool CCFrameRateCounter::isBadFrame(int frameNumber) const |
return isBadFrameInterval(frameInterval(frameNumber)); |
} |
+int64_t CCFrameRateCounter::currentVsyncCount(base::TimeTicks now) const |
+{ |
+ int64_t vsyncCount = m_vsyncCount; |
+ if (m_interval != base::TimeDelta()) |
+ vsyncCount += (now - m_intervalChangedTime + (m_interval/2)) / m_interval; |
+ return vsyncCount; |
+} |
+ |
void CCFrameRateCounter::getAverageFPSAndStandardDeviation(double& averageFPS, double& standardDeviation) const |
{ |
int frame = m_currentFrameNumber - 1; |
@@ -131,5 +148,15 @@ base::TimeTicks CCFrameRateCounter::timeStampOfRecentFrame(int n) |
return m_timeStampHistory[desiredIndex]; |
} |
+void CCFrameRateCounter::renderingStats(CCRenderingStats* stats) const |
+{ |
+ ASSERT(m_interval != base::TimeDelta()); |
+ |
+ base::TimeTicks now = base::TimeTicks::Now(); |
+ stats->vsyncCount = currentVsyncCount(now); |
+ stats->rendererFrameCount = m_currentFrameNumber - 1; |
+ stats->droppedFrameCount = stats->vsyncCount - stats->rendererFrameCount; |
+} |
+ |
} // namespace cc |