OLD | NEW |
---|---|
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "config.h" | 5 #include "config.h" |
6 | 6 |
7 #include "CCFrameRateCounter.h" | 7 #include "CCFrameRateCounter.h" |
8 | 8 |
9 #include <cmath> | 9 #include <cmath> |
10 | 10 |
11 #include "CCProxy.h" | 11 #include "CCProxy.h" |
12 #include <public/Platform.h> | 12 #include <public/Platform.h> |
13 | 13 |
14 namespace cc { | 14 namespace cc { |
15 | 15 |
16 const double CCFrameRateCounter::kFrameTooFast = 1.0 / 70.0; // measured in seco nds | |
17 const double CCFrameRateCounter::kFrameTooSlow = 1.0 / 12.0; | |
18 const double CCFrameRateCounter::kDroppedFrameTime = 1.0 / 50.0; | |
19 | |
20 // safeMod works on -1, returning m-1 in that case. | 16 // safeMod works on -1, returning m-1 in that case. |
21 static inline int safeMod(int number, int modulus) | 17 static inline int safeMod(int number, int modulus) |
22 { | 18 { |
23 return (number + modulus) % modulus; | 19 return (number + modulus) % modulus; |
24 } | 20 } |
25 | 21 |
26 // static | 22 // static |
27 scoped_ptr<CCFrameRateCounter> CCFrameRateCounter::create() { | 23 scoped_ptr<CCFrameRateCounter> CCFrameRateCounter::create() { |
28 return make_scoped_ptr(new CCFrameRateCounter()); | 24 return make_scoped_ptr(new CCFrameRateCounter()); |
29 } | 25 } |
30 | 26 |
27 void CCFrameRateCounter::setTimebaseAndInterval(base::TimeTicks timebase, base:: TimeDelta interval) | |
28 { | |
29 if (interval != m_interval) { | |
30 base::TimeTicks now = base::TimeTicks::Now(); | |
31 if (m_interval != base::TimeDelta()) | |
32 m_vsyncCount += (now - m_intervalChangedTime + (m_interval/2)) / m_i nterval; | |
33 m_intervalChangedTime = now; | |
34 m_interval = interval; | |
35 } | |
36 | |
37 m_frameTooFastSeconds = 0.8 * interval.InSecondsF(); | |
38 m_frameTooSlowSeconds = 1.0 / 12.0; | |
39 } | |
40 | |
31 inline base::TimeDelta CCFrameRateCounter::frameInterval(int frameNumber) const | 41 inline base::TimeDelta CCFrameRateCounter::frameInterval(int frameNumber) const |
32 { | 42 { |
33 return m_timeStampHistory[frameIndex(frameNumber)] - | 43 return m_timeStampHistory[frameIndex(frameNumber)] - |
34 m_timeStampHistory[frameIndex(frameNumber - 1)]; | 44 m_timeStampHistory[frameIndex(frameNumber - 1)]; |
35 } | 45 } |
36 | 46 |
37 inline int CCFrameRateCounter::frameIndex(int frameNumber) const | 47 inline int CCFrameRateCounter::frameIndex(int frameNumber) const |
38 { | 48 { |
39 return safeMod(frameNumber, kTimeStampHistorySize); | 49 return safeMod(frameNumber, kTimeStampHistorySize); |
40 } | 50 } |
41 | 51 |
42 CCFrameRateCounter::CCFrameRateCounter() | 52 CCFrameRateCounter::CCFrameRateCounter() |
43 : m_currentFrameNumber(1) | 53 : m_vsyncCount(0) |
44 , m_droppedFrameCount(0) | 54 , m_currentFrameNumber(1) |
45 { | 55 { |
56 setTimebaseAndInterval( | |
57 base::TimeTicks(), base::TimeDelta::FromMicroseconds(base::Time::kMicros econdsPerSecond / 60)); | |
reveman
2012/10/17 19:32:30
this assumes that 60FPS is the initial frame rate,
brianderson
2012/10/17 22:34:48
Done.
| |
58 | |
46 m_timeStampHistory[0] = base::TimeTicks::Now(); | 59 m_timeStampHistory[0] = base::TimeTicks::Now(); |
47 m_timeStampHistory[1] = m_timeStampHistory[0]; | 60 m_timeStampHistory[1] = m_timeStampHistory[0]; |
48 for (int i = 2; i < kTimeStampHistorySize; i++) | 61 for (int i = 2; i < kTimeStampHistorySize; i++) |
49 m_timeStampHistory[i] = base::TimeTicks(); | 62 m_timeStampHistory[i] = base::TimeTicks(); |
50 } | 63 } |
51 | 64 |
52 void CCFrameRateCounter::markBeginningOfFrame(base::TimeTicks timestamp) | 65 void CCFrameRateCounter::markBeginningOfFrame(base::TimeTicks timestamp) |
53 { | 66 { |
54 m_timeStampHistory[frameIndex(m_currentFrameNumber)] = timestamp; | 67 m_timeStampHistory[frameIndex(m_currentFrameNumber)] = timestamp; |
55 base::TimeDelta frameIntervalSeconds = frameInterval(m_currentFrameNumber); | 68 base::TimeDelta frameIntervalSeconds = frameInterval(m_currentFrameNumber); |
56 | 69 |
57 if (CCProxy::hasImplThread() && m_currentFrameNumber > 0) { | 70 if (CCProxy::hasImplThread() && m_currentFrameNumber > 0) { |
58 double drawDelayMs = frameIntervalSeconds.InMillisecondsF(); | 71 double drawDelayMs = frameIntervalSeconds.InMillisecondsF(); |
59 WebKit::Platform::current()->histogramCustomCounts("Renderer4.Compositor ThreadImplDrawDelay", static_cast<int>(drawDelayMs), 1, 120, 60); | 72 WebKit::Platform::current()->histogramCustomCounts("Renderer4.Compositor ThreadImplDrawDelay", static_cast<int>(drawDelayMs), 1, 120, 60); |
60 } | 73 } |
61 | 74 |
62 if (!isBadFrameInterval(frameIntervalSeconds) && | |
63 frameIntervalSeconds.InSecondsF() > kDroppedFrameTime) | |
64 ++m_droppedFrameCount; | |
65 } | 75 } |
66 | 76 |
67 void CCFrameRateCounter::markEndOfFrame() | 77 void CCFrameRateCounter::markEndOfFrame() |
68 { | 78 { |
69 m_currentFrameNumber += 1; | 79 m_currentFrameNumber += 1; |
70 } | 80 } |
71 | 81 |
72 bool CCFrameRateCounter::isBadFrameInterval(base::TimeDelta intervalBetweenConse cutiveFrames) const | 82 bool CCFrameRateCounter::isBadFrameInterval(base::TimeDelta intervalBetweenConse cutiveFrames) const |
73 { | 83 { |
74 bool schedulerAllowsDoubleFrames = !CCProxy::hasImplThread(); | 84 bool schedulerAllowsDoubleFrames = !CCProxy::hasImplThread(); |
75 bool intervalTooFast = schedulerAllowsDoubleFrames && intervalBetweenConsecu tiveFrames.InSecondsF() < kFrameTooFast; | 85 bool intervalTooFast = schedulerAllowsDoubleFrames && intervalBetweenConsecu tiveFrames.InSecondsF() < m_frameTooFastSeconds; |
76 bool intervalTooSlow = intervalBetweenConsecutiveFrames.InSecondsF() > kFram eTooSlow; | 86 bool intervalTooSlow = intervalBetweenConsecutiveFrames.InSecondsF() > m_fra meTooSlowSeconds; |
77 return intervalTooFast || intervalTooSlow; | 87 return intervalTooFast || intervalTooSlow; |
78 } | 88 } |
79 | 89 |
80 bool CCFrameRateCounter::isBadFrame(int frameNumber) const | 90 bool CCFrameRateCounter::isBadFrame(int frameNumber) const |
81 { | 91 { |
82 return isBadFrameInterval(frameInterval(frameNumber)); | 92 return isBadFrameInterval(frameInterval(frameNumber)); |
83 } | 93 } |
84 | 94 |
85 void CCFrameRateCounter::getAverageFPSAndStandardDeviation(double& averageFPS, d ouble& standardDeviation) const | 95 void CCFrameRateCounter::getAverageFPSAndStandardDeviation(double& averageFPS, d ouble& standardDeviation) const |
86 { | 96 { |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
124 standardDeviation = sqrt(fpsVarianceNumerator / averageFPSCount); | 134 standardDeviation = sqrt(fpsVarianceNumerator / averageFPSCount); |
125 } | 135 } |
126 | 136 |
127 base::TimeTicks CCFrameRateCounter::timeStampOfRecentFrame(int n) | 137 base::TimeTicks CCFrameRateCounter::timeStampOfRecentFrame(int n) |
128 { | 138 { |
129 ASSERT(n >= 0 && n < kTimeStampHistorySize); | 139 ASSERT(n >= 0 && n < kTimeStampHistorySize); |
130 int desiredIndex = (frameIndex(m_currentFrameNumber) + n) % kTimeStampHistor ySize; | 140 int desiredIndex = (frameIndex(m_currentFrameNumber) + n) % kTimeStampHistor ySize; |
131 return m_timeStampHistory[desiredIndex]; | 141 return m_timeStampHistory[desiredIndex]; |
132 } | 142 } |
133 | 143 |
144 void CCFrameRateCounter::renderingStats(CCRenderingStats* stats) const | |
145 { | |
146 base::TimeTicks now = base::TimeTicks::Now(); | |
147 | |
148 stats->vsyncCount = m_vsyncCount; | |
149 if (m_interval != base::TimeDelta()) | |
150 stats->vsyncCount += (now - m_intervalChangedTime + (m_interval/2)) / m_ interval; | |
reveman
2012/10/17 19:32:30
this same logic is used in setTimebaseAndInterval.
brianderson
2012/10/17 22:34:48
Done.
| |
151 | |
152 stats->rendererFrameCount = m_currentFrameNumber - 1; | |
153 stats->droppedFrameCount = stats->vsyncCount - (m_currentFrameNumber - 1); | |
reveman
2012/10/17 19:32:30
Looks like droppedFrameCount is unnecessary. Shoul
brianderson
2012/10/17 22:34:48
I think it would be nice to keep it as a separate
| |
154 } | |
155 | |
134 } // namespace cc | 156 } // namespace cc |
135 | 157 |
OLD | NEW |