| 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 { | 14 namespace { |
| 15 | 15 |
| 16 // This will be the maximum number of pending frames unless | 16 // This will be the maximum number of pending frames unless |
| 17 // CCFrameRateController::setMaxFramesPending is called. | 17 // FrameRateController::setMaxFramesPending is called. |
| 18 const int defaultMaxFramesPending = 2; | 18 const int defaultMaxFramesPending = 2; |
| 19 | 19 |
| 20 } // namespace | 20 } // namespace |
| 21 | 21 |
| 22 namespace cc { | 22 namespace cc { |
| 23 | 23 |
| 24 class CCFrameRateControllerTimeSourceAdapter : public CCTimeSourceClient { | 24 class FrameRateControllerTimeSourceAdapter : public TimeSourceClient { |
| 25 public: | 25 public: |
| 26 static scoped_ptr<CCFrameRateControllerTimeSourceAdapter> create(CCFrameRate
Controller* frameRateController) { | 26 static scoped_ptr<FrameRateControllerTimeSourceAdapter> create(FrameRateCont
roller* frameRateController) { |
| 27 return make_scoped_ptr(new CCFrameRateControllerTimeSourceAdapter(frameR
ateController)); | 27 return make_scoped_ptr(new FrameRateControllerTimeSourceAdapter(frameRat
eController)); |
| 28 } | 28 } |
| 29 virtual ~CCFrameRateControllerTimeSourceAdapter() {} | 29 virtual ~FrameRateControllerTimeSourceAdapter() {} |
| 30 | 30 |
| 31 virtual void onTimerTick() OVERRIDE { | 31 virtual void onTimerTick() OVERRIDE { |
| 32 m_frameRateController->onTimerTick(); | 32 m_frameRateController->onTimerTick(); |
| 33 } | 33 } |
| 34 | 34 |
| 35 private: | 35 private: |
| 36 explicit CCFrameRateControllerTimeSourceAdapter(CCFrameRateController* frame
RateController) | 36 explicit FrameRateControllerTimeSourceAdapter(FrameRateController* frameRate
Controller) |
| 37 : m_frameRateController(frameRateController) {} | 37 : m_frameRateController(frameRateController) {} |
| 38 | 38 |
| 39 CCFrameRateController* m_frameRateController; | 39 FrameRateController* m_frameRateController; |
| 40 }; | 40 }; |
| 41 | 41 |
| 42 CCFrameRateController::CCFrameRateController(scoped_refptr<CCTimeSource> timer) | 42 FrameRateController::FrameRateController(scoped_refptr<TimeSource> timer) |
| 43 : m_client(0) | 43 : m_client(0) |
| 44 , m_numFramesPending(0) | 44 , m_numFramesPending(0) |
| 45 , m_maxFramesPending(defaultMaxFramesPending) | 45 , m_maxFramesPending(defaultMaxFramesPending) |
| 46 , m_timeSource(timer) | 46 , m_timeSource(timer) |
| 47 , m_active(false) | 47 , m_active(false) |
| 48 , m_swapBuffersCompleteSupported(true) | 48 , m_swapBuffersCompleteSupported(true) |
| 49 , m_isTimeSourceThrottling(true) | 49 , m_isTimeSourceThrottling(true) |
| 50 { | 50 { |
| 51 m_timeSourceClientAdapter = CCFrameRateControllerTimeSourceAdapter::create(t
his); | 51 m_timeSourceClientAdapter = FrameRateControllerTimeSourceAdapter::create(thi
s); |
| 52 m_timeSource->setClient(m_timeSourceClientAdapter.get()); | 52 m_timeSource->setClient(m_timeSourceClientAdapter.get()); |
| 53 } | 53 } |
| 54 | 54 |
| 55 CCFrameRateController::CCFrameRateController(CCThread* thread) | 55 FrameRateController::FrameRateController(Thread* thread) |
| 56 : m_client(0) | 56 : m_client(0) |
| 57 , m_numFramesPending(0) | 57 , m_numFramesPending(0) |
| 58 , m_maxFramesPending(defaultMaxFramesPending) | 58 , m_maxFramesPending(defaultMaxFramesPending) |
| 59 , m_active(false) | 59 , m_active(false) |
| 60 , m_swapBuffersCompleteSupported(true) | 60 , m_swapBuffersCompleteSupported(true) |
| 61 , m_isTimeSourceThrottling(false) | 61 , m_isTimeSourceThrottling(false) |
| 62 , m_manualTicker(new CCTimer(thread, this)) | 62 , m_manualTicker(new Timer(thread, this)) |
| 63 { | 63 { |
| 64 } | 64 } |
| 65 | 65 |
| 66 CCFrameRateController::~CCFrameRateController() | 66 FrameRateController::~FrameRateController() |
| 67 { | 67 { |
| 68 if (m_isTimeSourceThrottling) | 68 if (m_isTimeSourceThrottling) |
| 69 m_timeSource->setActive(false); | 69 m_timeSource->setActive(false); |
| 70 } | 70 } |
| 71 | 71 |
| 72 void CCFrameRateController::setActive(bool active) | 72 void FrameRateController::setActive(bool active) |
| 73 { | 73 { |
| 74 if (m_active == active) | 74 if (m_active == active) |
| 75 return; | 75 return; |
| 76 TRACE_EVENT1("cc", "CCFrameRateController::setActive", "active", active); | 76 TRACE_EVENT1("cc", "FrameRateController::setActive", "active", active); |
| 77 m_active = active; | 77 m_active = active; |
| 78 | 78 |
| 79 if (m_isTimeSourceThrottling) | 79 if (m_isTimeSourceThrottling) |
| 80 m_timeSource->setActive(active); | 80 m_timeSource->setActive(active); |
| 81 else { | 81 else { |
| 82 if (active) | 82 if (active) |
| 83 postManualTick(); | 83 postManualTick(); |
| 84 else | 84 else |
| 85 m_manualTicker->stop(); | 85 m_manualTicker->stop(); |
| 86 } | 86 } |
| 87 } | 87 } |
| 88 | 88 |
| 89 void CCFrameRateController::setMaxFramesPending(int maxFramesPending) | 89 void FrameRateController::setMaxFramesPending(int maxFramesPending) |
| 90 { | 90 { |
| 91 ASSERT(maxFramesPending > 0); | 91 ASSERT(maxFramesPending > 0); |
| 92 m_maxFramesPending = maxFramesPending; | 92 m_maxFramesPending = maxFramesPending; |
| 93 } | 93 } |
| 94 | 94 |
| 95 void CCFrameRateController::setTimebaseAndInterval(base::TimeTicks timebase, bas
e::TimeDelta interval) | 95 void FrameRateController::setTimebaseAndInterval(base::TimeTicks timebase, base:
:TimeDelta interval) |
| 96 { | 96 { |
| 97 if (m_isTimeSourceThrottling) | 97 if (m_isTimeSourceThrottling) |
| 98 m_timeSource->setTimebaseAndInterval(timebase, interval); | 98 m_timeSource->setTimebaseAndInterval(timebase, interval); |
| 99 } | 99 } |
| 100 | 100 |
| 101 void CCFrameRateController::setSwapBuffersCompleteSupported(bool supported) | 101 void FrameRateController::setSwapBuffersCompleteSupported(bool supported) |
| 102 { | 102 { |
| 103 m_swapBuffersCompleteSupported = supported; | 103 m_swapBuffersCompleteSupported = supported; |
| 104 } | 104 } |
| 105 | 105 |
| 106 void CCFrameRateController::onTimerTick() | 106 void FrameRateController::onTimerTick() |
| 107 { | 107 { |
| 108 ASSERT(m_active); | 108 ASSERT(m_active); |
| 109 | 109 |
| 110 // Check if we have too many frames in flight. | 110 // Check if we have too many frames in flight. |
| 111 bool throttled = m_numFramesPending >= m_maxFramesPending; | 111 bool throttled = m_numFramesPending >= m_maxFramesPending; |
| 112 | 112 |
| 113 if (m_client) | 113 if (m_client) |
| 114 m_client->vsyncTick(throttled); | 114 m_client->vsyncTick(throttled); |
| 115 | 115 |
| 116 if (m_swapBuffersCompleteSupported && !m_isTimeSourceThrottling && m_numFram
esPending < m_maxFramesPending) | 116 if (m_swapBuffersCompleteSupported && !m_isTimeSourceThrottling && m_numFram
esPending < m_maxFramesPending) |
| 117 postManualTick(); | 117 postManualTick(); |
| 118 } | 118 } |
| 119 | 119 |
| 120 void CCFrameRateController::postManualTick() | 120 void FrameRateController::postManualTick() |
| 121 { | 121 { |
| 122 if (m_active) | 122 if (m_active) |
| 123 m_manualTicker->startOneShot(0); | 123 m_manualTicker->startOneShot(0); |
| 124 } | 124 } |
| 125 | 125 |
| 126 void CCFrameRateController::onTimerFired() | 126 void FrameRateController::onTimerFired() |
| 127 { | 127 { |
| 128 onTimerTick(); | 128 onTimerTick(); |
| 129 } | 129 } |
| 130 | 130 |
| 131 void CCFrameRateController::didBeginFrame() | 131 void FrameRateController::didBeginFrame() |
| 132 { | 132 { |
| 133 if (m_swapBuffersCompleteSupported) | 133 if (m_swapBuffersCompleteSupported) |
| 134 m_numFramesPending++; | 134 m_numFramesPending++; |
| 135 else if (!m_isTimeSourceThrottling) | 135 else if (!m_isTimeSourceThrottling) |
| 136 postManualTick(); | 136 postManualTick(); |
| 137 } | 137 } |
| 138 | 138 |
| 139 void CCFrameRateController::didFinishFrame() | 139 void FrameRateController::didFinishFrame() |
| 140 { | 140 { |
| 141 ASSERT(m_swapBuffersCompleteSupported); | 141 ASSERT(m_swapBuffersCompleteSupported); |
| 142 | 142 |
| 143 m_numFramesPending--; | 143 m_numFramesPending--; |
| 144 if (!m_isTimeSourceThrottling) | 144 if (!m_isTimeSourceThrottling) |
| 145 postManualTick(); | 145 postManualTick(); |
| 146 } | 146 } |
| 147 | 147 |
| 148 void CCFrameRateController::didAbortAllPendingFrames() | 148 void FrameRateController::didAbortAllPendingFrames() |
| 149 { | 149 { |
| 150 m_numFramesPending = 0; | 150 m_numFramesPending = 0; |
| 151 } | 151 } |
| 152 | 152 |
| 153 base::TimeTicks CCFrameRateController::nextTickTime() | 153 base::TimeTicks FrameRateController::nextTickTime() |
| 154 { | 154 { |
| 155 if (m_isTimeSourceThrottling) | 155 if (m_isTimeSourceThrottling) |
| 156 return m_timeSource->nextTickTime(); | 156 return m_timeSource->nextTickTime(); |
| 157 | 157 |
| 158 return base::TimeTicks(); | 158 return base::TimeTicks(); |
| 159 } | 159 } |
| 160 | 160 |
| 161 } | 161 } |
| OLD | NEW |