Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2869)

Unified Diff: cc/CCFrameRateController.cpp

Issue 11028021: cc: Improve frame/commit accounting (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: cc/CCFrameRateController.cpp
diff --git a/cc/CCFrameRateController.cpp b/cc/CCFrameRateController.cpp
index 4418027e487bf6b6135a7d6d040e3dc5ebba8139..c0465a8f5231656b2bca791124bfb35131b3ab60 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_numCsyncs(0)
+ , m_numActiveCsyncs(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_numCsyncs(0)
+ , m_numActiveCsyncs(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_numActiveCsyncs += (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_numCsyncs += (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->numCSyncs = m_numCsyncs;
+ if (m_interval != base::TimeDelta())
+ stats->numCSyncs += (now - m_intervalChangedTime) / m_interval;
+
+ stats->numActiveCSyncs = m_numActiveCsyncs;
+ if (m_active && m_interval != base::TimeDelta())
+ stats->numActiveCSyncs += (now - m_activeTimestamp) / m_interval;
+
+ stats->numFramesSentToScreen = m_numBeginFrames;
+ stats->droppedFrameCount = stats->numActiveCSyncs - m_numBeginFrames;
+
+ return;
reveman 2012/10/04 02:15:56 nit: unnecessary return statement
brianderson 2012/10/04 20:11:59 Done.
+}
+
}
« no previous file with comments | « cc/CCFrameRateController.h ('k') | cc/CCFrameRateCounter.h » ('j') | cc/CCRenderingStats.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698