Chromium Code Reviews| 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 "cc/frame_rate_controller.h" | 5 #include "cc/frame_rate_controller.h" |
| 6 | 6 |
| 7 #include "base/debug/trace_event.h" | 7 #include "base/debug/trace_event.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "cc/delay_based_time_source.h" | 9 #include "cc/delay_based_time_source.h" |
| 10 #include "cc/time_source.h" | 10 #include "cc/time_source.h" |
| 11 #include "cc/thread.h" | 11 #include "cc/thread.h" |
| 12 | 12 |
| 13 namespace { | |
| 14 | |
| 15 // This will be the maximum number of pending frames unless | |
| 16 // FrameRateController::setMaxFramesPending is called. | |
| 17 const int defaultMaxFramesPending = 2; | |
| 18 | |
| 19 } // namespace | |
| 20 | |
| 21 namespace cc { | 13 namespace cc { |
| 22 | 14 |
| 23 class FrameRateControllerTimeSourceAdapter : public TimeSourceClient { | 15 class FrameRateControllerTimeSourceAdapter : public TimeSourceClient { |
| 24 public: | 16 public: |
| 25 static scoped_ptr<FrameRateControllerTimeSourceAdapter> create(FrameRateCont roller* frameRateController) { | 17 static scoped_ptr<FrameRateControllerTimeSourceAdapter> create(FrameRateCont roller* frameRateController) { |
| 26 return make_scoped_ptr(new FrameRateControllerTimeSourceAdapter(frameRat eController)); | 18 return make_scoped_ptr(new FrameRateControllerTimeSourceAdapter(frameRat eController)); |
| 27 } | 19 } |
| 28 virtual ~FrameRateControllerTimeSourceAdapter() {} | 20 virtual ~FrameRateControllerTimeSourceAdapter() {} |
| 29 | 21 |
| 30 virtual void onTimerTick() OVERRIDE { | 22 virtual void onTimerTick() OVERRIDE { |
| 31 m_frameRateController->onTimerTick(); | 23 m_frameRateController->onTimerTick(); |
| 32 } | 24 } |
| 33 | 25 |
| 34 private: | 26 private: |
| 35 explicit FrameRateControllerTimeSourceAdapter(FrameRateController* frameRate Controller) | 27 explicit FrameRateControllerTimeSourceAdapter(FrameRateController* frameRate Controller) |
| 36 : m_frameRateController(frameRateController) {} | 28 : m_frameRateController(frameRateController) {} |
| 37 | 29 |
| 38 FrameRateController* m_frameRateController; | 30 FrameRateController* m_frameRateController; |
| 39 }; | 31 }; |
| 40 | 32 |
| 41 FrameRateController::FrameRateController(scoped_refptr<TimeSource> timer) | 33 FrameRateController::FrameRateController(scoped_refptr<TimeSource> timer) |
| 42 : m_client(0) | 34 : m_client(0) |
| 43 , m_numFramesPending(0) | 35 , m_numFramesPending(0) |
| 44 , m_maxFramesPending(defaultMaxFramesPending) | 36 , m_maxFramesPending(0) |
| 45 , m_timeSource(timer) | 37 , m_timeSource(timer) |
| 46 , m_active(false) | 38 , m_active(false) |
| 47 , m_swapBuffersCompleteSupported(true) | 39 , m_swapBuffersCompleteSupported(true) |
| 48 , m_isTimeSourceThrottling(true) | 40 , m_isTimeSourceThrottling(true) |
| 49 , m_thread(0) | 41 , m_thread(0) |
| 50 , m_weakFactory(ALLOW_THIS_IN_INITIALIZER_LIST(this)) | 42 , m_weakFactory(ALLOW_THIS_IN_INITIALIZER_LIST(this)) |
| 51 { | 43 { |
| 52 m_timeSourceClientAdapter = FrameRateControllerTimeSourceAdapter::create(thi s); | 44 m_timeSourceClientAdapter = FrameRateControllerTimeSourceAdapter::create(thi s); |
| 53 m_timeSource->setClient(m_timeSourceClientAdapter.get()); | 45 m_timeSource->setClient(m_timeSourceClientAdapter.get()); |
| 54 } | 46 } |
| 55 | 47 |
| 56 FrameRateController::FrameRateController(Thread* thread) | 48 FrameRateController::FrameRateController(Thread* thread) |
| 57 : m_client(0) | 49 : m_client(0) |
| 58 , m_numFramesPending(0) | 50 , m_numFramesPending(0) |
| 59 , m_maxFramesPending(defaultMaxFramesPending) | 51 , m_maxFramesPending(0) |
| 60 , m_active(false) | 52 , m_active(false) |
| 61 , m_swapBuffersCompleteSupported(true) | 53 , m_swapBuffersCompleteSupported(true) |
| 62 , m_isTimeSourceThrottling(false) | 54 , m_isTimeSourceThrottling(false) |
| 63 , m_thread(thread) | 55 , m_thread(thread) |
| 64 , m_weakFactory(ALLOW_THIS_IN_INITIALIZER_LIST(this)) | 56 , m_weakFactory(ALLOW_THIS_IN_INITIALIZER_LIST(this)) |
| 65 { | 57 { |
| 66 } | 58 } |
| 67 | 59 |
| 68 FrameRateController::~FrameRateController() | 60 FrameRateController::~FrameRateController() |
| 69 { | 61 { |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 83 else { | 75 else { |
| 84 if (active) | 76 if (active) |
| 85 postManualTick(); | 77 postManualTick(); |
| 86 else | 78 else |
| 87 m_weakFactory.InvalidateWeakPtrs(); | 79 m_weakFactory.InvalidateWeakPtrs(); |
| 88 } | 80 } |
| 89 } | 81 } |
| 90 | 82 |
| 91 void FrameRateController::setMaxFramesPending(int maxFramesPending) | 83 void FrameRateController::setMaxFramesPending(int maxFramesPending) |
| 92 { | 84 { |
| 93 DCHECK(maxFramesPending > 0); | 85 DCHECK(maxFramesPending >= 0); |
| 94 m_maxFramesPending = maxFramesPending; | 86 m_maxFramesPending = maxFramesPending; |
| 95 } | 87 } |
| 96 | 88 |
| 97 void FrameRateController::setTimebaseAndInterval(base::TimeTicks timebase, base: :TimeDelta interval) | 89 void FrameRateController::setTimebaseAndInterval(base::TimeTicks timebase, base: :TimeDelta interval) |
| 98 { | 90 { |
| 99 if (m_isTimeSourceThrottling) | 91 if (m_isTimeSourceThrottling) |
| 100 m_timeSource->setTimebaseAndInterval(timebase, interval); | 92 m_timeSource->setTimebaseAndInterval(timebase, interval); |
| 101 } | 93 } |
| 102 | 94 |
| 103 void FrameRateController::setSwapBuffersCompleteSupported(bool supported) | 95 void FrameRateController::setSwapBuffersCompleteSupported(bool supported) |
| 104 { | 96 { |
| 105 m_swapBuffersCompleteSupported = supported; | 97 m_swapBuffersCompleteSupported = supported; |
| 106 } | 98 } |
| 107 | 99 |
| 108 void FrameRateController::onTimerTick() | 100 void FrameRateController::onTimerTick() |
| 109 { | 101 { |
| 110 DCHECK(m_active); | 102 DCHECK(m_active); |
| 111 | 103 |
| 112 // Check if we have too many frames in flight. | 104 // Check if we have too many frames in flight. |
| 113 bool throttled = m_numFramesPending >= m_maxFramesPending; | 105 bool throttled = m_maxFramesPending && m_numFramesPending >= m_maxFramesPend ing; |
| 114 TRACE_COUNTER_ID1("cc", "ThrottledVSyncInterval", m_thread, throttled); | 106 TRACE_COUNTER_ID1("cc", "ThrottledVSyncInterval", m_thread, throttled); |
| 115 | 107 |
| 116 if (m_client) | 108 if (m_client) |
| 117 m_client->vsyncTick(throttled); | 109 m_client->vsyncTick(throttled); |
| 118 | 110 |
| 119 if (m_swapBuffersCompleteSupported && !m_isTimeSourceThrottling && m_numFram esPending < m_maxFramesPending) | 111 if (m_swapBuffersCompleteSupported && !m_isTimeSourceThrottling && (!m_maxFr amesPending || m_numFramesPending < m_maxFramesPending)) |
|
enne (OOO)
2013/01/04 21:42:05
How about reusing throttled, i.e. "&& !throttled"?
danakj
2013/01/04 21:44:45
Ya good plan.
danakj
2013/01/04 22:24:07
Done.
| |
| 120 postManualTick(); | 112 postManualTick(); |
| 121 } | 113 } |
| 122 | 114 |
| 123 void FrameRateController::postManualTick() | 115 void FrameRateController::postManualTick() |
| 124 { | 116 { |
| 125 if (m_active) | 117 if (m_active) |
| 126 m_thread->postTask(base::Bind(&FrameRateController::manualTick, m_weakFa ctory.GetWeakPtr())); | 118 m_thread->postTask(base::Bind(&FrameRateController::manualTick, m_weakFa ctory.GetWeakPtr())); |
| 127 } | 119 } |
| 128 | 120 |
| 129 void FrameRateController::manualTick() | 121 void FrameRateController::manualTick() |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 155 | 147 |
| 156 base::TimeTicks FrameRateController::nextTickTime() | 148 base::TimeTicks FrameRateController::nextTickTime() |
| 157 { | 149 { |
| 158 if (m_isTimeSourceThrottling) | 150 if (m_isTimeSourceThrottling) |
| 159 return m_timeSource->nextTickTime(); | 151 return m_timeSource->nextTickTime(); |
| 160 | 152 |
| 161 return base::TimeTicks(); | 153 return base::TimeTicks(); |
| 162 } | 154 } |
| 163 | 155 |
| 164 } // namespace cc | 156 } // namespace cc |
| OLD | NEW |