| OLD | NEW |
| 1 // Copyright 2011 The Chromium Authors. All rights reserved. | 1 // Copyright 2011 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 "CCFrameRateController.h" | 7 #include "CCFrameRateController.h" |
| 8 | 8 |
| 9 #include "CCDelayBasedTimeSource.h" | 9 #include "CCDelayBasedTimeSource.h" |
| 10 #include "CCTimeSource.h" | 10 #include "CCTimeSource.h" |
| 11 #include "TraceEvent.h" | 11 #include "TraceEvent.h" |
| 12 #include <wtf/CurrentTime.h> | 12 #include <wtf/CurrentTime.h> |
| 13 | 13 |
| 14 namespace { |
| 15 |
| 16 // This will be the maximum number of pending frames unless |
| 17 // CCFrameRateController::setMaxFramesPending is called. |
| 18 const int defaultMaxFramesPending = 2; |
| 19 |
| 20 } |
| 21 |
| 14 namespace WebCore { | 22 namespace WebCore { |
| 15 | 23 |
| 16 class CCFrameRateControllerTimeSourceAdapter : public CCTimeSourceClient { | 24 class CCFrameRateControllerTimeSourceAdapter : public CCTimeSourceClient { |
| 17 public: | 25 public: |
| 18 static PassOwnPtr<CCFrameRateControllerTimeSourceAdapter> create(CCFrameRate
Controller* frameRateController) | 26 static PassOwnPtr<CCFrameRateControllerTimeSourceAdapter> create(CCFrameRate
Controller* frameRateController) |
| 19 { | 27 { |
| 20 return adoptPtr(new CCFrameRateControllerTimeSourceAdapter(frameRateCont
roller)); | 28 return adoptPtr(new CCFrameRateControllerTimeSourceAdapter(frameRateCont
roller)); |
| 21 } | 29 } |
| 22 virtual ~CCFrameRateControllerTimeSourceAdapter() { } | 30 virtual ~CCFrameRateControllerTimeSourceAdapter() { } |
| 23 | 31 |
| 24 virtual void onTimerTick() OVERRIDE { m_frameRateController->onTimerTick();
} | 32 virtual void onTimerTick() OVERRIDE { m_frameRateController->onTimerTick();
} |
| 25 private: | 33 private: |
| 26 explicit CCFrameRateControllerTimeSourceAdapter(CCFrameRateController* frame
RateController) | 34 explicit CCFrameRateControllerTimeSourceAdapter(CCFrameRateController* frame
RateController) |
| 27 : m_frameRateController(frameRateController) { } | 35 : m_frameRateController(frameRateController) { } |
| 28 | 36 |
| 29 CCFrameRateController* m_frameRateController; | 37 CCFrameRateController* m_frameRateController; |
| 30 }; | 38 }; |
| 31 | 39 |
| 32 CCFrameRateController::CCFrameRateController(PassRefPtr<CCTimeSource> timer) | 40 CCFrameRateController::CCFrameRateController(PassRefPtr<CCTimeSource> timer) |
| 33 : m_client(0) | 41 : m_client(0) |
| 34 , m_numFramesPending(0) | 42 , m_numFramesPending(0) |
| 35 , m_maxFramesPending(0) | 43 , m_maxFramesPending(defaultMaxFramesPending) |
| 36 , m_timeSource(timer) | 44 , m_timeSource(timer) |
| 37 , m_active(false) | 45 , m_active(false) |
| 46 , m_swapBuffersCompleteSupported(true) |
| 38 , m_isTimeSourceThrottling(true) | 47 , m_isTimeSourceThrottling(true) |
| 39 { | 48 { |
| 40 m_timeSourceClientAdapter = CCFrameRateControllerTimeSourceAdapter::create(t
his); | 49 m_timeSourceClientAdapter = CCFrameRateControllerTimeSourceAdapter::create(t
his); |
| 41 m_timeSource->setClient(m_timeSourceClientAdapter.get()); | 50 m_timeSource->setClient(m_timeSourceClientAdapter.get()); |
| 42 } | 51 } |
| 43 | 52 |
| 44 CCFrameRateController::CCFrameRateController(CCThread* thread) | 53 CCFrameRateController::CCFrameRateController(CCThread* thread) |
| 45 : m_client(0) | 54 : m_client(0) |
| 46 , m_numFramesPending(0) | 55 , m_numFramesPending(0) |
| 47 , m_maxFramesPending(0) | 56 , m_maxFramesPending(defaultMaxFramesPending) |
| 48 , m_active(false) | 57 , m_active(false) |
| 58 , m_swapBuffersCompleteSupported(true) |
| 49 , m_isTimeSourceThrottling(false) | 59 , m_isTimeSourceThrottling(false) |
| 50 { | 60 { |
| 51 m_manualTicker = adoptPtr(new CCTimer(thread, this)); | 61 m_manualTicker = adoptPtr(new CCTimer(thread, this)); |
| 52 } | 62 } |
| 53 | 63 |
| 54 CCFrameRateController::~CCFrameRateController() | 64 CCFrameRateController::~CCFrameRateController() |
| 55 { | 65 { |
| 56 if (m_isTimeSourceThrottling) | 66 if (m_isTimeSourceThrottling) |
| 57 m_timeSource->setActive(false); | 67 m_timeSource->setActive(false); |
| 58 } | 68 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 69 else { | 79 else { |
| 70 if (active) | 80 if (active) |
| 71 postManualTick(); | 81 postManualTick(); |
| 72 else | 82 else |
| 73 m_manualTicker->stop(); | 83 m_manualTicker->stop(); |
| 74 } | 84 } |
| 75 } | 85 } |
| 76 | 86 |
| 77 void CCFrameRateController::setMaxFramesPending(int maxFramesPending) | 87 void CCFrameRateController::setMaxFramesPending(int maxFramesPending) |
| 78 { | 88 { |
| 89 ASSERT(maxFramesPending > 0); |
| 79 m_maxFramesPending = maxFramesPending; | 90 m_maxFramesPending = maxFramesPending; |
| 80 } | 91 } |
| 81 | 92 |
| 82 void CCFrameRateController::setTimebaseAndInterval(double timebase, double inter
valSeconds) | 93 void CCFrameRateController::setTimebaseAndInterval(double timebase, double inter
valSeconds) |
| 83 { | 94 { |
| 84 if (m_isTimeSourceThrottling) | 95 if (m_isTimeSourceThrottling) |
| 85 m_timeSource->setTimebaseAndInterval(timebase, intervalSeconds); | 96 m_timeSource->setTimebaseAndInterval(timebase, intervalSeconds); |
| 86 } | 97 } |
| 87 | 98 |
| 99 void CCFrameRateController::setSwapBuffersCompleteSupported(bool supported) |
| 100 { |
| 101 m_swapBuffersCompleteSupported = supported; |
| 102 } |
| 103 |
| 88 void CCFrameRateController::onTimerTick() | 104 void CCFrameRateController::onTimerTick() |
| 89 { | 105 { |
| 90 ASSERT(m_active); | 106 ASSERT(m_active); |
| 91 | 107 |
| 92 // Don't forward the tick if we have too many frames in flight. | 108 // Don't forward the tick if we have too many frames in flight. |
| 93 if (m_maxFramesPending && m_numFramesPending >= m_maxFramesPending) { | 109 if (m_numFramesPending >= m_maxFramesPending) { |
| 94 TRACE_EVENT0("cc", "CCFrameRateController::onTimerTickButMaxFramesPendin
g"); | 110 TRACE_EVENT0("cc", "CCFrameRateController::onTimerTickButMaxFramesPendin
g"); |
| 95 return; | 111 return; |
| 96 } | 112 } |
| 97 | 113 |
| 98 if (m_client) | 114 if (m_client) |
| 99 m_client->vsyncTick(); | 115 m_client->vsyncTick(); |
| 100 | 116 |
| 101 if (!m_isTimeSourceThrottling | 117 if (m_swapBuffersCompleteSupported && !m_isTimeSourceThrottling && m_numFram
esPending < m_maxFramesPending) |
| 102 && (!m_maxFramesPending || m_numFramesPending < m_maxFramesPending)) | |
| 103 postManualTick(); | 118 postManualTick(); |
| 104 } | 119 } |
| 105 | 120 |
| 106 void CCFrameRateController::postManualTick() | 121 void CCFrameRateController::postManualTick() |
| 107 { | 122 { |
| 108 if (m_active) | 123 if (m_active) |
| 109 m_manualTicker->startOneShot(0); | 124 m_manualTicker->startOneShot(0); |
| 110 } | 125 } |
| 111 | 126 |
| 112 void CCFrameRateController::onTimerFired() | 127 void CCFrameRateController::onTimerFired() |
| 113 { | 128 { |
| 114 onTimerTick(); | 129 onTimerTick(); |
| 115 } | 130 } |
| 116 | 131 |
| 117 void CCFrameRateController::didBeginFrame() | 132 void CCFrameRateController::didBeginFrame() |
| 118 { | 133 { |
| 119 m_numFramesPending++; | 134 if (m_swapBuffersCompleteSupported) |
| 135 m_numFramesPending++; |
| 136 else if (!m_isTimeSourceThrottling) |
| 137 postManualTick(); |
| 120 } | 138 } |
| 121 | 139 |
| 122 void CCFrameRateController::didFinishFrame() | 140 void CCFrameRateController::didFinishFrame() |
| 123 { | 141 { |
| 142 ASSERT(m_swapBuffersCompleteSupported); |
| 143 |
| 124 m_numFramesPending--; | 144 m_numFramesPending--; |
| 125 if (!m_isTimeSourceThrottling) | 145 if (!m_isTimeSourceThrottling) |
| 126 postManualTick(); | 146 postManualTick(); |
| 127 } | 147 } |
| 128 | 148 |
| 129 void CCFrameRateController::didAbortAllPendingFrames() | 149 void CCFrameRateController::didAbortAllPendingFrames() |
| 130 { | 150 { |
| 131 m_numFramesPending = 0; | 151 m_numFramesPending = 0; |
| 132 } | 152 } |
| 133 | 153 |
| 134 double CCFrameRateController::nextTickTimeIfActivated() | 154 double CCFrameRateController::nextTickTimeIfActivated() |
| 135 { | 155 { |
| 136 if (m_isTimeSourceThrottling) | 156 if (m_isTimeSourceThrottling) |
| 137 return m_timeSource->nextTickTimeIfActivated(); | 157 return m_timeSource->nextTickTimeIfActivated(); |
| 138 | 158 |
| 139 return monotonicallyIncreasingTime(); | 159 return monotonicallyIncreasingTime(); |
| 140 } | 160 } |
| 141 | 161 |
| 142 } | 162 } |
| OLD | NEW |