| 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 "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() { | 27 scoped_ptr<FrameRateCounter> FrameRateCounter::create(bool hasImplThread) { |
| 28 return make_scoped_ptr(new FrameRateCounter()); | 28 return make_scoped_ptr(new FrameRateCounter(hasImplThread)); |
| 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() | 42 FrameRateCounter::FrameRateCounter(bool hasImplThread) |
| 43 : m_currentFrameNumber(1) | 43 : m_hasImplThread(hasImplThread) |
| 44 , m_currentFrameNumber(1) |
| 44 , m_droppedFrameCount(0) | 45 , m_droppedFrameCount(0) |
| 45 { | 46 { |
| 46 m_timeStampHistory[0] = base::TimeTicks::Now(); | 47 m_timeStampHistory[0] = base::TimeTicks::Now(); |
| 47 m_timeStampHistory[1] = m_timeStampHistory[0]; | 48 m_timeStampHistory[1] = m_timeStampHistory[0]; |
| 48 for (int i = 2; i < kTimeStampHistorySize; i++) | 49 for (int i = 2; i < kTimeStampHistorySize; i++) |
| 49 m_timeStampHistory[i] = base::TimeTicks(); | 50 m_timeStampHistory[i] = base::TimeTicks(); |
| 50 } | 51 } |
| 51 | 52 |
| 52 void FrameRateCounter::markBeginningOfFrame(base::TimeTicks timestamp) | 53 void FrameRateCounter::markBeginningOfFrame(base::TimeTicks timestamp) |
| 53 { | 54 { |
| 54 m_timeStampHistory[frameIndex(m_currentFrameNumber)] = timestamp; | 55 m_timeStampHistory[frameIndex(m_currentFrameNumber)] = timestamp; |
| 55 base::TimeDelta frameIntervalSeconds = frameInterval(m_currentFrameNumber); | 56 base::TimeDelta frameIntervalSeconds = frameInterval(m_currentFrameNumber); |
| 56 | 57 |
| 57 if (Proxy::hasImplThread() && m_currentFrameNumber > 0) { | 58 if (m_hasImplThread && m_currentFrameNumber > 0) { |
| 58 HISTOGRAM_CUSTOM_COUNTS("Renderer4.CompositorThreadImplDrawDelay", frame
IntervalSeconds.InMilliseconds(), 1, 120, 60); | 59 HISTOGRAM_CUSTOM_COUNTS("Renderer4.CompositorThreadImplDrawDelay", frame
IntervalSeconds.InMilliseconds(), 1, 120, 60); |
| 59 } | 60 } |
| 60 | 61 |
| 61 if (!isBadFrameInterval(frameIntervalSeconds) && | 62 if (!isBadFrameInterval(frameIntervalSeconds) && |
| 62 frameIntervalSeconds.InSecondsF() > kDroppedFrameTime) | 63 frameIntervalSeconds.InSecondsF() > kDroppedFrameTime) |
| 63 ++m_droppedFrameCount; | 64 ++m_droppedFrameCount; |
| 64 } | 65 } |
| 65 | 66 |
| 66 void FrameRateCounter::markEndOfFrame() | 67 void FrameRateCounter::markEndOfFrame() |
| 67 { | 68 { |
| 68 m_currentFrameNumber += 1; | 69 m_currentFrameNumber += 1; |
| 69 } | 70 } |
| 70 | 71 |
| 71 bool FrameRateCounter::isBadFrameInterval(base::TimeDelta intervalBetweenConsecu
tiveFrames) const | 72 bool FrameRateCounter::isBadFrameInterval(base::TimeDelta intervalBetweenConsecu
tiveFrames) const |
| 72 { | 73 { |
| 73 bool schedulerAllowsDoubleFrames = !Proxy::hasImplThread(); | 74 bool schedulerAllowsDoubleFrames = m_hasImplThread; |
| 74 bool intervalTooFast = schedulerAllowsDoubleFrames && intervalBetweenConsecu
tiveFrames.InSecondsF() < kFrameTooFast; | 75 bool intervalTooFast = schedulerAllowsDoubleFrames && intervalBetweenConsecu
tiveFrames.InSecondsF() < kFrameTooFast; |
| 75 bool intervalTooSlow = intervalBetweenConsecutiveFrames.InSecondsF() > kFram
eTooSlow; | 76 bool intervalTooSlow = intervalBetweenConsecutiveFrames.InSecondsF() > kFram
eTooSlow; |
| 76 return intervalTooFast || intervalTooSlow; | 77 return intervalTooFast || intervalTooSlow; |
| 77 } | 78 } |
| 78 | 79 |
| 79 bool FrameRateCounter::isBadFrame(int frameNumber) const | 80 bool FrameRateCounter::isBadFrame(int frameNumber) const |
| 80 { | 81 { |
| 81 return isBadFrameInterval(frameInterval(frameNumber)); | 82 return isBadFrameInterval(frameInterval(frameNumber)); |
| 82 } | 83 } |
| 83 | 84 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 | 126 |
| 126 base::TimeTicks FrameRateCounter::timeStampOfRecentFrame(int n) | 127 base::TimeTicks FrameRateCounter::timeStampOfRecentFrame(int n) |
| 127 { | 128 { |
| 128 DCHECK(n >= 0); | 129 DCHECK(n >= 0); |
| 129 DCHECK(n < kTimeStampHistorySize); | 130 DCHECK(n < kTimeStampHistorySize); |
| 130 int desiredIndex = (frameIndex(m_currentFrameNumber) + n) % kTimeStampHistor
ySize; | 131 int desiredIndex = (frameIndex(m_currentFrameNumber) + n) % kTimeStampHistor
ySize; |
| 131 return m_timeStampHistory[desiredIndex]; | 132 return m_timeStampHistory[desiredIndex]; |
| 132 } | 133 } |
| 133 | 134 |
| 134 } // namespace cc | 135 } // namespace cc |
| 135 | |
| OLD | NEW |