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