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 "cc/frame_rate_counter.h" | 7 #include "cc/frame_rate_counter.h" |
8 | 8 |
9 #include <cmath> | 9 #include <cmath> |
10 | 10 |
11 #include "base/metrics/histogram.h" | 11 #include "base/metrics/histogram.h" |
12 #include "cc/proxy.h" | 12 #include "cc/proxy.h" |
13 | 13 |
14 namespace cc { | 14 namespace cc { |
15 | 15 |
16 const double FrameRateCounter::kFrameTooFast = 1.0 / 70.0; // measured in second
s | 16 const double FrameRateCounter::kFrameTooFast = 1.0 / 70.0; // measured in second
s |
17 const double FrameRateCounter::kFrameTooSlow = 1.0 / 12.0; | 17 const double FrameRateCounter::kFrameTooSlow = 1.0 / 12.0; |
18 const double FrameRateCounter::kDroppedFrameTime = 1.0 / 50.0; | 18 const double FrameRateCounter::kDroppedFrameTime = 1.0 / 50.0; |
19 | 19 |
20 // safeMod works on -1, returning m-1 in that case. | 20 // safeMod works on -1, returning m-1 in that case. |
21 static inline int safeMod(int number, int modulus) | 21 static inline int safeMod(int number, int modulus) |
22 { | 22 { |
23 return (number + modulus) % modulus; | 23 return (number + modulus) % modulus; |
24 } | 24 } |
25 | 25 |
26 // static | 26 // static |
27 scoped_ptr<FrameRateCounter> FrameRateCounter::create(bool hasImplThread) { | 27 scoped_ptr<FrameRateCounter> FrameRateCounter::create() { |
28 return make_scoped_ptr(new FrameRateCounter(hasImplThread)); | 28 return make_scoped_ptr(new FrameRateCounter()); |
29 } | 29 } |
30 | 30 |
31 inline base::TimeDelta FrameRateCounter::frameInterval(int frameNumber) const | 31 inline base::TimeDelta FrameRateCounter::frameInterval(int frameNumber) const |
32 { | 32 { |
33 return m_timeStampHistory[frameIndex(frameNumber)] - | 33 return m_timeStampHistory[frameIndex(frameNumber)] - |
34 m_timeStampHistory[frameIndex(frameNumber - 1)]; | 34 m_timeStampHistory[frameIndex(frameNumber - 1)]; |
35 } | 35 } |
36 | 36 |
37 inline int FrameRateCounter::frameIndex(int frameNumber) const | 37 inline int FrameRateCounter::frameIndex(int frameNumber) const |
38 { | 38 { |
39 return safeMod(frameNumber, kTimeStampHistorySize); | 39 return safeMod(frameNumber, kTimeStampHistorySize); |
40 } | 40 } |
41 | 41 |
42 FrameRateCounter::FrameRateCounter(bool hasImplThread) | 42 FrameRateCounter::FrameRateCounter() |
43 : m_hasImplThread(hasImplThread) | 43 : m_currentFrameNumber(1) |
44 , m_currentFrameNumber(1) | |
45 , m_droppedFrameCount(0) | 44 , m_droppedFrameCount(0) |
46 { | 45 { |
47 m_timeStampHistory[0] = base::TimeTicks::Now(); | 46 m_timeStampHistory[0] = base::TimeTicks::Now(); |
48 m_timeStampHistory[1] = m_timeStampHistory[0]; | 47 m_timeStampHistory[1] = m_timeStampHistory[0]; |
49 for (int i = 2; i < kTimeStampHistorySize; i++) | 48 for (int i = 2; i < kTimeStampHistorySize; i++) |
50 m_timeStampHistory[i] = base::TimeTicks(); | 49 m_timeStampHistory[i] = base::TimeTicks(); |
51 } | 50 } |
52 | 51 |
53 void FrameRateCounter::markBeginningOfFrame(base::TimeTicks timestamp) | 52 void FrameRateCounter::markBeginningOfFrame(base::TimeTicks timestamp) |
54 { | 53 { |
55 m_timeStampHistory[frameIndex(m_currentFrameNumber)] = timestamp; | 54 m_timeStampHistory[frameIndex(m_currentFrameNumber)] = timestamp; |
56 base::TimeDelta frameIntervalSeconds = frameInterval(m_currentFrameNumber); | 55 base::TimeDelta frameIntervalSeconds = frameInterval(m_currentFrameNumber); |
57 | 56 |
58 if (m_hasImplThread && m_currentFrameNumber > 0) { | 57 if (Proxy::hasImplThread() && m_currentFrameNumber > 0) { |
59 HISTOGRAM_CUSTOM_COUNTS("Renderer4.CompositorThreadImplDrawDelay", frame
IntervalSeconds.InMilliseconds(), 1, 120, 60); | 58 HISTOGRAM_CUSTOM_COUNTS("Renderer4.CompositorThreadImplDrawDelay", frame
IntervalSeconds.InMilliseconds(), 1, 120, 60); |
60 } | 59 } |
61 | 60 |
62 if (!isBadFrameInterval(frameIntervalSeconds) && | 61 if (!isBadFrameInterval(frameIntervalSeconds) && |
63 frameIntervalSeconds.InSecondsF() > kDroppedFrameTime) | 62 frameIntervalSeconds.InSecondsF() > kDroppedFrameTime) |
64 ++m_droppedFrameCount; | 63 ++m_droppedFrameCount; |
65 } | 64 } |
66 | 65 |
67 void FrameRateCounter::markEndOfFrame() | 66 void FrameRateCounter::markEndOfFrame() |
68 { | 67 { |
69 m_currentFrameNumber += 1; | 68 m_currentFrameNumber += 1; |
70 } | 69 } |
71 | 70 |
72 bool FrameRateCounter::isBadFrameInterval(base::TimeDelta intervalBetweenConsecu
tiveFrames) const | 71 bool FrameRateCounter::isBadFrameInterval(base::TimeDelta intervalBetweenConsecu
tiveFrames) const |
73 { | 72 { |
74 bool schedulerAllowsDoubleFrames = !m_hasImplThread; | 73 bool schedulerAllowsDoubleFrames = !Proxy::hasImplThread(); |
75 bool intervalTooFast = schedulerAllowsDoubleFrames && intervalBetweenConsecu
tiveFrames.InSecondsF() < kFrameTooFast; | 74 bool intervalTooFast = schedulerAllowsDoubleFrames && intervalBetweenConsecu
tiveFrames.InSecondsF() < kFrameTooFast; |
76 bool intervalTooSlow = intervalBetweenConsecutiveFrames.InSecondsF() > kFram
eTooSlow; | 75 bool intervalTooSlow = intervalBetweenConsecutiveFrames.InSecondsF() > kFram
eTooSlow; |
77 return intervalTooFast || intervalTooSlow; | 76 return intervalTooFast || intervalTooSlow; |
78 } | 77 } |
79 | 78 |
80 bool FrameRateCounter::isBadFrame(int frameNumber) const | 79 bool FrameRateCounter::isBadFrame(int frameNumber) const |
81 { | 80 { |
82 return isBadFrameInterval(frameInterval(frameNumber)); | 81 return isBadFrameInterval(frameInterval(frameNumber)); |
83 } | 82 } |
84 | 83 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
126 | 125 |
127 base::TimeTicks FrameRateCounter::timeStampOfRecentFrame(int n) | 126 base::TimeTicks FrameRateCounter::timeStampOfRecentFrame(int n) |
128 { | 127 { |
129 DCHECK(n >= 0); | 128 DCHECK(n >= 0); |
130 DCHECK(n < kTimeStampHistorySize); | 129 DCHECK(n < kTimeStampHistorySize); |
131 int desiredIndex = (frameIndex(m_currentFrameNumber) + n) % kTimeStampHistor
ySize; | 130 int desiredIndex = (frameIndex(m_currentFrameNumber) + n) % kTimeStampHistor
ySize; |
132 return m_timeStampHistory[desiredIndex]; | 131 return m_timeStampHistory[desiredIndex]; |
133 } | 132 } |
134 | 133 |
135 } // namespace cc | 134 } // namespace cc |
| 135 |
OLD | NEW |