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 "cc/frame_rate_controller.h" | 7 #include "cc/frame_rate_controller.h" |
8 | 8 |
9 #include "base/debug/trace_event.h" | 9 #include "base/debug/trace_event.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "cc/delay_based_time_source.h" | 11 #include "cc/delay_based_time_source.h" |
12 #include "cc/time_source.h" | 12 #include "cc/time_source.h" |
| 13 #include "cc/thread.h" |
13 | 14 |
14 namespace { | 15 namespace { |
15 | 16 |
16 // This will be the maximum number of pending frames unless | 17 // This will be the maximum number of pending frames unless |
17 // FrameRateController::setMaxFramesPending is called. | 18 // FrameRateController::setMaxFramesPending is called. |
18 const int defaultMaxFramesPending = 2; | 19 const int defaultMaxFramesPending = 2; |
19 | 20 |
20 } // namespace | 21 } // namespace |
21 | 22 |
22 namespace cc { | 23 namespace cc { |
(...skipping 17 matching lines...) Expand all Loading... |
40 }; | 41 }; |
41 | 42 |
42 FrameRateController::FrameRateController(scoped_refptr<TimeSource> timer) | 43 FrameRateController::FrameRateController(scoped_refptr<TimeSource> timer) |
43 : m_client(0) | 44 : m_client(0) |
44 , m_numFramesPending(0) | 45 , m_numFramesPending(0) |
45 , m_maxFramesPending(defaultMaxFramesPending) | 46 , m_maxFramesPending(defaultMaxFramesPending) |
46 , m_timeSource(timer) | 47 , m_timeSource(timer) |
47 , m_active(false) | 48 , m_active(false) |
48 , m_swapBuffersCompleteSupported(true) | 49 , m_swapBuffersCompleteSupported(true) |
49 , m_isTimeSourceThrottling(true) | 50 , m_isTimeSourceThrottling(true) |
| 51 , m_thread(0) |
| 52 , m_weakFactory(ALLOW_THIS_IN_INITIALIZER_LIST(this)) |
50 { | 53 { |
51 m_timeSourceClientAdapter = FrameRateControllerTimeSourceAdapter::create(thi
s); | 54 m_timeSourceClientAdapter = FrameRateControllerTimeSourceAdapter::create(thi
s); |
52 m_timeSource->setClient(m_timeSourceClientAdapter.get()); | 55 m_timeSource->setClient(m_timeSourceClientAdapter.get()); |
53 } | 56 } |
54 | 57 |
55 FrameRateController::FrameRateController(Thread* thread) | 58 FrameRateController::FrameRateController(Thread* thread) |
56 : m_client(0) | 59 : m_client(0) |
57 , m_numFramesPending(0) | 60 , m_numFramesPending(0) |
58 , m_maxFramesPending(defaultMaxFramesPending) | 61 , m_maxFramesPending(defaultMaxFramesPending) |
59 , m_active(false) | 62 , m_active(false) |
60 , m_swapBuffersCompleteSupported(true) | 63 , m_swapBuffersCompleteSupported(true) |
61 , m_isTimeSourceThrottling(false) | 64 , m_isTimeSourceThrottling(false) |
62 , m_manualTicker(new Timer(thread, this)) | 65 , m_thread(thread) |
| 66 , m_weakFactory(ALLOW_THIS_IN_INITIALIZER_LIST(this)) |
63 { | 67 { |
64 } | 68 } |
65 | 69 |
66 FrameRateController::~FrameRateController() | 70 FrameRateController::~FrameRateController() |
67 { | 71 { |
68 if (m_isTimeSourceThrottling) | 72 if (m_isTimeSourceThrottling) |
69 m_timeSource->setActive(false); | 73 m_timeSource->setActive(false); |
70 } | 74 } |
71 | 75 |
72 void FrameRateController::setActive(bool active) | 76 void FrameRateController::setActive(bool active) |
73 { | 77 { |
74 if (m_active == active) | 78 if (m_active == active) |
75 return; | 79 return; |
76 TRACE_EVENT1("cc", "FrameRateController::setActive", "active", active); | 80 TRACE_EVENT1("cc", "FrameRateController::setActive", "active", active); |
77 m_active = active; | 81 m_active = active; |
78 | 82 |
79 if (m_isTimeSourceThrottling) | 83 if (m_isTimeSourceThrottling) |
80 m_timeSource->setActive(active); | 84 m_timeSource->setActive(active); |
81 else { | 85 else { |
82 if (active) | 86 if (active) |
83 postManualTick(); | 87 postManualTick(); |
84 else | 88 else |
85 m_manualTicker->stop(); | 89 m_weakFactory.InvalidateWeakPtrs(); |
86 } | 90 } |
87 } | 91 } |
88 | 92 |
89 void FrameRateController::setMaxFramesPending(int maxFramesPending) | 93 void FrameRateController::setMaxFramesPending(int maxFramesPending) |
90 { | 94 { |
91 DCHECK(maxFramesPending > 0); | 95 DCHECK(maxFramesPending > 0); |
92 m_maxFramesPending = maxFramesPending; | 96 m_maxFramesPending = maxFramesPending; |
93 } | 97 } |
94 | 98 |
95 void FrameRateController::setTimebaseAndInterval(base::TimeTicks timebase, base:
:TimeDelta interval) | 99 void FrameRateController::setTimebaseAndInterval(base::TimeTicks timebase, base:
:TimeDelta interval) |
(...skipping 17 matching lines...) Expand all Loading... |
113 if (m_client) | 117 if (m_client) |
114 m_client->vsyncTick(throttled); | 118 m_client->vsyncTick(throttled); |
115 | 119 |
116 if (m_swapBuffersCompleteSupported && !m_isTimeSourceThrottling && m_numFram
esPending < m_maxFramesPending) | 120 if (m_swapBuffersCompleteSupported && !m_isTimeSourceThrottling && m_numFram
esPending < m_maxFramesPending) |
117 postManualTick(); | 121 postManualTick(); |
118 } | 122 } |
119 | 123 |
120 void FrameRateController::postManualTick() | 124 void FrameRateController::postManualTick() |
121 { | 125 { |
122 if (m_active) | 126 if (m_active) |
123 m_manualTicker->startOneShot(0); | 127 m_thread->postTask(base::Bind(&FrameRateController::manualTick, m_weakFa
ctory.GetWeakPtr())); |
124 } | 128 } |
125 | 129 |
126 void FrameRateController::onTimerFired() | 130 void FrameRateController::manualTick() |
127 { | 131 { |
128 onTimerTick(); | 132 onTimerTick(); |
129 } | 133 } |
130 | 134 |
131 void FrameRateController::didBeginFrame() | 135 void FrameRateController::didBeginFrame() |
132 { | 136 { |
133 if (m_swapBuffersCompleteSupported) | 137 if (m_swapBuffersCompleteSupported) |
134 m_numFramesPending++; | 138 m_numFramesPending++; |
135 else if (!m_isTimeSourceThrottling) | 139 else if (!m_isTimeSourceThrottling) |
136 postManualTick(); | 140 postManualTick(); |
(...skipping 15 matching lines...) Expand all Loading... |
152 | 156 |
153 base::TimeTicks FrameRateController::nextTickTime() | 157 base::TimeTicks FrameRateController::nextTickTime() |
154 { | 158 { |
155 if (m_isTimeSourceThrottling) | 159 if (m_isTimeSourceThrottling) |
156 return m_timeSource->nextTickTime(); | 160 return m_timeSource->nextTickTime(); |
157 | 161 |
158 return base::TimeTicks(); | 162 return base::TimeTicks(); |
159 } | 163 } |
160 | 164 |
161 } | 165 } |
OLD | NEW |