Index: cc/CCFrameRateController.cpp |
diff --git a/cc/CCFrameRateController.cpp b/cc/CCFrameRateController.cpp |
index b264bc27ebcd4259b0eb6af669f4dc0d214b5198..15ff94c03c03c2e42a3cd379080d68c83226ba2b 100644 |
--- a/cc/CCFrameRateController.cpp |
+++ b/cc/CCFrameRateController.cpp |
@@ -11,6 +11,14 @@ |
#include "TraceEvent.h" |
#include <wtf/CurrentTime.h> |
+namespace { |
+ |
+// This will be the maximum number of pending frames unless |
+// CCFrameRateController::setMaxFramesPending is called. |
+const int defaultMaxFramesPending = 2; |
+ |
+} |
+ |
namespace WebCore { |
class CCFrameRateControllerTimeSourceAdapter : public CCTimeSourceClient { |
@@ -32,9 +40,10 @@ private: |
CCFrameRateController::CCFrameRateController(PassRefPtr<CCTimeSource> timer) |
: m_client(0) |
, m_numFramesPending(0) |
- , m_maxFramesPending(0) |
+ , m_maxFramesPending(defaultMaxFramesPending) |
, m_timeSource(timer) |
, m_active(false) |
+ , m_swapBuffersCompleteSupported(true) |
, m_isTimeSourceThrottling(true) |
{ |
m_timeSourceClientAdapter = CCFrameRateControllerTimeSourceAdapter::create(this); |
@@ -44,8 +53,9 @@ CCFrameRateController::CCFrameRateController(PassRefPtr<CCTimeSource> timer) |
CCFrameRateController::CCFrameRateController(CCThread* thread) |
: m_client(0) |
, m_numFramesPending(0) |
- , m_maxFramesPending(0) |
+ , m_maxFramesPending(defaultMaxFramesPending) |
, m_active(false) |
+ , m_swapBuffersCompleteSupported(true) |
, m_isTimeSourceThrottling(false) |
{ |
m_manualTicker = adoptPtr(new CCTimer(thread, this)); |
@@ -76,6 +86,7 @@ void CCFrameRateController::setActive(bool active) |
void CCFrameRateController::setMaxFramesPending(int maxFramesPending) |
{ |
+ ASSERT(maxFramesPending > 0); |
m_maxFramesPending = maxFramesPending; |
} |
@@ -85,12 +96,17 @@ void CCFrameRateController::setTimebaseAndInterval(double timebase, double inter |
m_timeSource->setTimebaseAndInterval(timebase, intervalSeconds); |
} |
+void CCFrameRateController::setSwapBuffersCompleteSupported(bool supported) |
+{ |
+ m_swapBuffersCompleteSupported = supported; |
+} |
+ |
void CCFrameRateController::onTimerTick() |
{ |
ASSERT(m_active); |
// Don't forward the tick if we have too many frames in flight. |
- if (m_maxFramesPending && m_numFramesPending >= m_maxFramesPending) { |
+ if (m_numFramesPending >= m_maxFramesPending) { |
TRACE_EVENT0("cc", "CCFrameRateController::onTimerTickButMaxFramesPending"); |
return; |
} |
@@ -98,8 +114,7 @@ void CCFrameRateController::onTimerTick() |
if (m_client) |
m_client->vsyncTick(); |
- if (!m_isTimeSourceThrottling |
- && (!m_maxFramesPending || m_numFramesPending < m_maxFramesPending)) |
+ if (m_swapBuffersCompleteSupported && !m_isTimeSourceThrottling && m_numFramesPending < m_maxFramesPending) |
postManualTick(); |
} |
@@ -116,11 +131,16 @@ void CCFrameRateController::onTimerFired() |
void CCFrameRateController::didBeginFrame() |
{ |
- m_numFramesPending++; |
+ if (m_swapBuffersCompleteSupported) |
+ m_numFramesPending++; |
+ else if (!m_isTimeSourceThrottling) |
+ postManualTick(); |
} |
void CCFrameRateController::didFinishFrame() |
{ |
+ ASSERT(m_swapBuffersCompleteSupported); |
+ |
m_numFramesPending--; |
if (!m_isTimeSourceThrottling) |
postManualTick(); |