| 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 #if USE(ACCELERATED_COMPOSITING) | 7 #if USE(ACCELERATED_COMPOSITING) |
| 8 #include "CCFrameRateCounter.h" | 8 #include "CCFrameRateCounter.h" |
| 9 | 9 |
| 10 #include "CCProxy.h" | 10 #include "CCProxy.h" |
| 11 #include <public/Platform.h> | 11 #include <public/Platform.h> |
| 12 #include <wtf/CurrentTime.h> | 12 #include <wtf/CurrentTime.h> |
| 13 | 13 |
| 14 namespace cc { | 14 namespace cc { |
| 15 | 15 |
| 16 const double CCFrameRateCounter::kFrameTooFast = 1.0 / 70.0; // measured in seco
nds | 16 const double CCFrameRateCounter::kFrameTooFast = 1.0 / 70.0; // measured in seco
nds |
| 17 const double CCFrameRateCounter::kFrameTooSlow = 1.0 / 12.0; | 17 const double CCFrameRateCounter::kFrameTooSlow = 1.0 / 12.0; |
| 18 const double CCFrameRateCounter::kDroppedFrameTime = 1.0 / 50.0; | |
| 19 | 18 |
| 20 // safeMod works on -1, returning m-1 in that case. | 19 // safeMod works on -1, returning m-1 in that case. |
| 21 static inline int safeMod(int number, int modulus) | 20 static inline int safeMod(int number, int modulus) |
| 22 { | 21 { |
| 23 return (number + modulus) % modulus; | 22 return (number + modulus) % modulus; |
| 24 } | 23 } |
| 25 | 24 |
| 26 inline double CCFrameRateCounter::frameInterval(int frameNumber) const | 25 inline double CCFrameRateCounter::frameInterval(int frameNumber) const |
| 27 { | 26 { |
| 28 return m_timeStampHistory[frameIndex(frameNumber)] - | 27 return m_timeStampHistory[frameIndex(frameNumber)] - |
| 29 m_timeStampHistory[frameIndex(frameNumber - 1)]; | 28 m_timeStampHistory[frameIndex(frameNumber - 1)]; |
| 30 } | 29 } |
| 31 | 30 |
| 32 inline int CCFrameRateCounter::frameIndex(int frameNumber) const | 31 inline int CCFrameRateCounter::frameIndex(int frameNumber) const |
| 33 { | 32 { |
| 34 return safeMod(frameNumber, kTimeStampHistorySize); | 33 return safeMod(frameNumber, kTimeStampHistorySize); |
| 35 } | 34 } |
| 36 | 35 |
| 37 CCFrameRateCounter::CCFrameRateCounter() | 36 CCFrameRateCounter::CCFrameRateCounter() |
| 38 : m_currentFrameNumber(1) | 37 : m_currentFrameNumber(1) |
| 39 , m_droppedFrameCount(0) | |
| 40 { | 38 { |
| 41 m_timeStampHistory[0] = currentTime(); | 39 m_timeStampHistory[0] = currentTime(); |
| 42 m_timeStampHistory[1] = m_timeStampHistory[0]; | 40 m_timeStampHistory[1] = m_timeStampHistory[0]; |
| 43 for (int i = 2; i < kTimeStampHistorySize; i++) | 41 for (int i = 2; i < kTimeStampHistorySize; i++) |
| 44 m_timeStampHistory[i] = 0; | 42 m_timeStampHistory[i] = 0; |
| 45 } | 43 } |
| 46 | 44 |
| 47 void CCFrameRateCounter::markBeginningOfFrame(double timestamp) | 45 void CCFrameRateCounter::markBeginningOfFrame(double timestamp) |
| 48 { | 46 { |
| 49 m_timeStampHistory[frameIndex(m_currentFrameNumber)] = timestamp; | 47 m_timeStampHistory[frameIndex(m_currentFrameNumber)] = timestamp; |
| 50 double frameIntervalSeconds = frameInterval(m_currentFrameNumber); | 48 double frameIntervalSeconds = frameInterval(m_currentFrameNumber); |
| 51 | 49 |
| 52 if (CCProxy::hasImplThread() && m_currentFrameNumber > 0) { | 50 if (CCProxy::hasImplThread() && m_currentFrameNumber > 0) { |
| 53 double drawDelayMs = frameIntervalSeconds * 1000.0; | 51 double drawDelayMs = frameIntervalSeconds * 1000.0; |
| 54 WebKit::Platform::current()->histogramCustomCounts("Renderer4.Compositor
ThreadImplDrawDelay", static_cast<int>(drawDelayMs), 1, 120, 60); | 52 WebKit::Platform::current()->histogramCustomCounts("Renderer4.Compositor
ThreadImplDrawDelay", static_cast<int>(drawDelayMs), 1, 120, 60); |
| 55 } | 53 } |
| 56 | |
| 57 if (!isBadFrameInterval(frameIntervalSeconds) && frameIntervalSeconds > kDro
ppedFrameTime) | |
| 58 ++m_droppedFrameCount; | |
| 59 } | 54 } |
| 60 | 55 |
| 61 void CCFrameRateCounter::markEndOfFrame() | 56 void CCFrameRateCounter::markEndOfFrame() |
| 62 { | 57 { |
| 63 m_currentFrameNumber += 1; | 58 m_currentFrameNumber += 1; |
| 64 } | 59 } |
| 65 | 60 |
| 66 bool CCFrameRateCounter::isBadFrameInterval(double intervalBetweenConsecutiveFra
mes) const | 61 bool CCFrameRateCounter::isBadFrameInterval(double intervalBetweenConsecutiveFra
mes) const |
| 67 { | 62 { |
| 68 bool schedulerAllowsDoubleFrames = !CCProxy::hasImplThread(); | 63 bool schedulerAllowsDoubleFrames = !CCProxy::hasImplThread(); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 double CCFrameRateCounter::timeStampOfRecentFrame(int n) | 116 double CCFrameRateCounter::timeStampOfRecentFrame(int n) |
| 122 { | 117 { |
| 123 ASSERT(n >= 0 && n < kTimeStampHistorySize); | 118 ASSERT(n >= 0 && n < kTimeStampHistorySize); |
| 124 int desiredIndex = (frameIndex(m_currentFrameNumber) + n) % kTimeStampHistor
ySize; | 119 int desiredIndex = (frameIndex(m_currentFrameNumber) + n) % kTimeStampHistor
ySize; |
| 125 return m_timeStampHistory[desiredIndex]; | 120 return m_timeStampHistory[desiredIndex]; |
| 126 } | 121 } |
| 127 | 122 |
| 128 } // namespace cc | 123 } // namespace cc |
| 129 | 124 |
| 130 #endif // USE(ACCELERATED_COMPOSITING) | 125 #endif // USE(ACCELERATED_COMPOSITING) |
| OLD | NEW |