Chromium Code Reviews| Index: cc/CCFrameRateController.cpp |
| diff --git a/cc/CCFrameRateController.cpp b/cc/CCFrameRateController.cpp |
| index 4418027e487bf6b6135a7d6d040e3dc5ebba8139..c61f3687abaed603024c0474f42419f2890313c5 100644 |
| --- a/cc/CCFrameRateController.cpp |
| +++ b/cc/CCFrameRateController.cpp |
| @@ -7,6 +7,7 @@ |
| #include "CCFrameRateController.h" |
| #include "CCDelayBasedTimeSource.h" |
| +#include "CCRenderingStats.h" |
| #include "CCTimeSource.h" |
| #include "TraceEvent.h" |
| #include <wtf/CurrentTime.h> |
| @@ -43,7 +44,13 @@ CCFrameRateController::CCFrameRateController(PassRefPtr<CCTimeSource> timer) |
| , m_maxFramesPending(defaultMaxFramesPending) |
| , m_timeSource(timer) |
| , m_active(false) |
| + , m_drawActive(false) |
| + , m_commitActive(false) |
| , m_swapBuffersCompleteSupported(true) |
| + , m_compositorSyncCount(0) |
| + , m_compositorSyncActiveCount(0) |
| + , m_numBeginFrames(0) |
| + , m_interval(m_timeSource->interval()) |
| , m_isTimeSourceThrottling(true) |
| { |
| m_timeSourceClientAdapter = CCFrameRateControllerTimeSourceAdapter::create(this); |
| @@ -55,7 +62,12 @@ CCFrameRateController::CCFrameRateController(CCThread* thread) |
| , m_numFramesPending(0) |
| , m_maxFramesPending(defaultMaxFramesPending) |
| , m_active(false) |
| + , m_drawActive(false) |
| + , m_commitActive(false) |
| , m_swapBuffersCompleteSupported(true) |
| + , m_compositorSyncCount(0) |
| + , m_compositorSyncActiveCount(0) |
| + , m_numBeginFrames(0) |
| , m_isTimeSourceThrottling(false) |
| { |
| m_manualTicker = adoptPtr(new CCTimer(thread, this)); |
| @@ -67,21 +79,38 @@ CCFrameRateController::~CCFrameRateController() |
| m_timeSource->setActive(false); |
| } |
| -void CCFrameRateController::setActive(bool active) |
| +void CCFrameRateController::setActive(bool drawActive, bool commitActive) |
| { |
| - if (m_active == active) |
| + if (m_drawActive == drawActive && m_commitActive == commitActive) |
| return; |
| - TRACE_EVENT1("cc", "CCFrameRateController::setActive", "active", active); |
| - m_active = active; |
| - if (m_isTimeSourceThrottling) |
| - m_timeSource->setActive(active); |
| - else { |
| + TRACE_EVENT2("cc", "CCFrameRateController::setActive", "draw", drawActive, "commit", commitActive); |
| + |
| + if (m_drawActive != drawActive) { |
| + if (m_isTimeSourceThrottling) |
| + m_timeSource->setActive(drawActive); |
| + else { |
| + if (drawActive) |
| + postManualTick(); |
| + else |
| + m_manualTicker->stop(); |
| + } |
| + } |
| + |
| + bool active = drawActive || commitActive; |
| + if (m_active != active) { |
| + base::TimeTicks now = base::TimeTicks::Now(); |
| if (active) |
| - postManualTick(); |
| - else |
| - m_manualTicker->stop(); |
| + m_activeTimestamp = now; |
| + else if (m_interval != base::TimeDelta()) { |
| + base::TimeDelta epsilon = base::TimeDelta::FromMicroseconds(1); |
| + m_compositorSyncActiveCount += (now - m_activeTimestamp + m_interval - epsilon) / m_interval; |
| + } |
| } |
| + |
| + m_active = active; |
| + m_drawActive = drawActive; |
| + m_commitActive = commitActive; |
| } |
| void CCFrameRateController::setMaxFramesPending(int maxFramesPending) |
| @@ -92,6 +121,14 @@ void CCFrameRateController::setMaxFramesPending(int maxFramesPending) |
| void CCFrameRateController::setTimebaseAndInterval(base::TimeTicks timebase, base::TimeDelta interval) |
| { |
| + if (interval != m_interval) { |
| + base::TimeTicks now = base::TimeTicks::Now(); |
| + if (m_interval != base::TimeDelta()) |
| + m_compositorSyncCount += (now - m_intervalChangedTime) / m_interval; |
| + m_intervalChangedTime = now; |
| + m_interval = interval; |
| + } |
| + |
| if (m_isTimeSourceThrottling) |
| m_timeSource->setTimebaseAndInterval(timebase, interval); |
| } |
| @@ -103,7 +140,7 @@ void CCFrameRateController::setSwapBuffersCompleteSupported(bool supported) |
| void CCFrameRateController::onTimerTick() |
| { |
| - ASSERT(m_active); |
| + ASSERT(m_drawActive); |
| // Check if we have too many frames in flight. |
| bool throttled = m_numFramesPending >= m_maxFramesPending; |
| @@ -117,7 +154,7 @@ void CCFrameRateController::onTimerTick() |
| void CCFrameRateController::postManualTick() |
| { |
| - if (m_active) |
| + if (m_drawActive) |
| m_manualTicker->startOneShot(0); |
| } |
| @@ -128,6 +165,10 @@ void CCFrameRateController::onTimerFired() |
| void CCFrameRateController::didBeginFrame() |
| { |
| + ASSERT(m_drawActive); |
| + |
| + m_numBeginFrames++; |
| + |
| if (m_swapBuffersCompleteSupported) |
| m_numFramesPending++; |
| else if (!m_isTimeSourceThrottling) |
| @@ -156,4 +197,23 @@ base::TimeTicks CCFrameRateController::nextTickTime() |
| return base::TimeTicks(); |
| } |
| + |
| +void CCFrameRateController::renderingStats(CCRenderingStats* stats) const |
| +{ |
| + base::TimeTicks now = base::TimeTicks::Now(); |
| + |
| + stats->compositorSyncCount = m_compositorSyncCount; |
| + if (m_interval != base::TimeDelta()) |
| + stats->compositorSyncCount += (now - m_intervalChangedTime) / m_interval; |
| + |
| + stats->compositorSyncActiveCount = m_compositorSyncActiveCount; |
| + if (m_active && m_interval != base::TimeDelta()) |
| + stats->compositorSyncActiveCount += (now - m_activeTimestamp) / m_interval; |
| + |
| + stats->compositorFrameCount = m_numBeginFrames; |
| + stats->droppedFrameCount = stats->compositorSyncActiveCount - m_numBeginFrames; |
| + |
| + return; |
|
dtu
2012/10/04 21:41:09
nit: the return is still here.
brianderson
2012/10/05 00:17:32
Doh, will get it in next patch
|
| +} |
| + |
| } |