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/scheduler_state_machine.h" | 5 #include "cc/scheduler_state_machine.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/stringprintf.h" | 8 #include "base/stringprintf.h" |
9 | 9 |
10 namespace cc { | 10 namespace cc { |
(...skipping 10 matching lines...) Expand all Loading... |
21 , m_needsCommit(false) | 21 , m_needsCommit(false) |
22 , m_needsForcedCommit(false) | 22 , m_needsForcedCommit(false) |
23 , m_expectImmediateBeginFrame(false) | 23 , m_expectImmediateBeginFrame(false) |
24 , m_mainThreadNeedsLayerTextures(false) | 24 , m_mainThreadNeedsLayerTextures(false) |
25 , m_insideVSync(false) | 25 , m_insideVSync(false) |
26 , m_visible(false) | 26 , m_visible(false) |
27 , m_canBeginFrame(false) | 27 , m_canBeginFrame(false) |
28 , m_canDraw(false) | 28 , m_canDraw(false) |
29 , m_drawIfPossibleFailed(false) | 29 , m_drawIfPossibleFailed(false) |
30 , m_textureState(LAYER_TEXTURE_STATE_UNLOCKED) | 30 , m_textureState(LAYER_TEXTURE_STATE_UNLOCKED) |
31 , m_outputSurfaceState(OUTPUT_SURFACE_ACTIVE) | 31 , m_contextState(CONTEXT_ACTIVE) |
32 { | 32 { |
33 } | 33 } |
34 | 34 |
35 std::string SchedulerStateMachine::toString() | 35 std::string SchedulerStateMachine::toString() |
36 { | 36 { |
37 std::string str; | 37 std::string str; |
38 base::StringAppendF(&str, "m_commitState = %d; ", m_commitState); | 38 base::StringAppendF(&str, "m_commitState = %d; ", m_commitState); |
39 base::StringAppendF(&str, "m_currentFrameNumber = %d; ", m_currentFrameNumbe
r); | 39 base::StringAppendF(&str, "m_currentFrameNumber = %d; ", m_currentFrameNumbe
r); |
40 base::StringAppendF(&str, "m_lastFrameNumberWhereDrawWasCalled = %d; ", m_la
stFrameNumberWhereDrawWasCalled); | 40 base::StringAppendF(&str, "m_lastFrameNumberWhereDrawWasCalled = %d; ", m_la
stFrameNumberWhereDrawWasCalled); |
41 base::StringAppendF(&str, "m_consecutiveFailedDraws = %d; ", m_consecutiveFa
iledDraws); | 41 base::StringAppendF(&str, "m_consecutiveFailedDraws = %d; ", m_consecutiveFa
iledDraws); |
42 base::StringAppendF(&str, "m_maximumNumberOfFailedDrawsBeforeDrawIsForced =
%d; ", m_maximumNumberOfFailedDrawsBeforeDrawIsForced); | 42 base::StringAppendF(&str, "m_maximumNumberOfFailedDrawsBeforeDrawIsForced =
%d; ", m_maximumNumberOfFailedDrawsBeforeDrawIsForced); |
43 base::StringAppendF(&str, "m_needsRedraw = %d; ", m_needsRedraw); | 43 base::StringAppendF(&str, "m_needsRedraw = %d; ", m_needsRedraw); |
44 base::StringAppendF(&str, "m_needsForcedRedraw = %d; ", m_needsForcedRedraw)
; | 44 base::StringAppendF(&str, "m_needsForcedRedraw = %d; ", m_needsForcedRedraw)
; |
45 base::StringAppendF(&str, "m_needsForcedRedrawAfterNextCommit = %d; ", m_nee
dsForcedRedrawAfterNextCommit); | 45 base::StringAppendF(&str, "m_needsForcedRedrawAfterNextCommit = %d; ", m_nee
dsForcedRedrawAfterNextCommit); |
46 base::StringAppendF(&str, "m_needsCommit = %d; ", m_needsCommit); | 46 base::StringAppendF(&str, "m_needsCommit = %d; ", m_needsCommit); |
47 base::StringAppendF(&str, "m_needsForcedCommit = %d; ", m_needsForcedCommit)
; | 47 base::StringAppendF(&str, "m_needsForcedCommit = %d; ", m_needsForcedCommit)
; |
48 base::StringAppendF(&str, "m_expectImmediateBeginFrame = %d; ", m_expectImme
diateBeginFrame); | 48 base::StringAppendF(&str, "m_expectImmediateBeginFrame = %d; ", m_expectImme
diateBeginFrame); |
49 base::StringAppendF(&str, "m_mainThreadNeedsLayerTextures = %d; ", m_mainThr
eadNeedsLayerTextures); | 49 base::StringAppendF(&str, "m_mainThreadNeedsLayerTextures = %d; ", m_mainThr
eadNeedsLayerTextures); |
50 base::StringAppendF(&str, "m_insideVSync = %d; ", m_insideVSync); | 50 base::StringAppendF(&str, "m_insideVSync = %d; ", m_insideVSync); |
51 base::StringAppendF(&str, "m_visible = %d; ", m_visible); | 51 base::StringAppendF(&str, "m_visible = %d; ", m_visible); |
52 base::StringAppendF(&str, "m_canBeginFrame = %d; ", m_canBeginFrame); | 52 base::StringAppendF(&str, "m_canBeginFrame = %d; ", m_canBeginFrame); |
53 base::StringAppendF(&str, "m_canDraw = %d; ", m_canDraw); | 53 base::StringAppendF(&str, "m_canDraw = %d; ", m_canDraw); |
54 base::StringAppendF(&str, "m_drawIfPossibleFailed = %d; ", m_drawIfPossibleF
ailed); | 54 base::StringAppendF(&str, "m_drawIfPossibleFailed = %d; ", m_drawIfPossibleF
ailed); |
55 base::StringAppendF(&str, "m_textureState = %d; ", m_textureState); | 55 base::StringAppendF(&str, "m_textureState = %d; ", m_textureState); |
56 base::StringAppendF(&str, "m_outputSurfaceState = %d; ", m_outputSurfaceStat
e); | 56 base::StringAppendF(&str, "m_contextState = %d; ", m_contextState); |
57 return str; | 57 return str; |
58 } | 58 } |
59 | 59 |
60 bool SchedulerStateMachine::hasDrawnThisFrame() const | 60 bool SchedulerStateMachine::hasDrawnThisFrame() const |
61 { | 61 { |
62 return m_currentFrameNumber == m_lastFrameNumberWhereDrawWasCalled; | 62 return m_currentFrameNumber == m_lastFrameNumberWhereDrawWasCalled; |
63 } | 63 } |
64 | 64 |
65 bool SchedulerStateMachine::drawSuspendedUntilCommit() const | 65 bool SchedulerStateMachine::drawSuspendedUntilCommit() const |
66 { | 66 { |
(...skipping 19 matching lines...) Expand all Loading... |
86 { | 86 { |
87 if (m_needsForcedRedraw) | 87 if (m_needsForcedRedraw) |
88 return true; | 88 return true; |
89 | 89 |
90 if (!scheduledToDraw()) | 90 if (!scheduledToDraw()) |
91 return false; | 91 return false; |
92 if (!m_insideVSync) | 92 if (!m_insideVSync) |
93 return false; | 93 return false; |
94 if (hasDrawnThisFrame()) | 94 if (hasDrawnThisFrame()) |
95 return false; | 95 return false; |
96 if (m_outputSurfaceState != OUTPUT_SURFACE_ACTIVE) | 96 if (m_contextState != CONTEXT_ACTIVE) |
97 return false; | 97 return false; |
98 return true; | 98 return true; |
99 } | 99 } |
100 | 100 |
101 bool SchedulerStateMachine::shouldAcquireLayerTexturesForMainThread() const | 101 bool SchedulerStateMachine::shouldAcquireLayerTexturesForMainThread() const |
102 { | 102 { |
103 if (!m_mainThreadNeedsLayerTextures) | 103 if (!m_mainThreadNeedsLayerTextures) |
104 return false; | 104 return false; |
105 if (m_textureState == LAYER_TEXTURE_STATE_UNLOCKED) | 105 if (m_textureState == LAYER_TEXTURE_STATE_UNLOCKED) |
106 return true; | 106 return true; |
107 DCHECK(m_textureState == LAYER_TEXTURE_STATE_ACQUIRED_BY_IMPL_THREAD); | 107 DCHECK(m_textureState == LAYER_TEXTURE_STATE_ACQUIRED_BY_IMPL_THREAD); |
108 // Transfer the lock from impl thread to main thread immediately if the | 108 // Transfer the lock from impl thread to main thread immediately if the |
109 // impl thread is not even scheduled to draw. Guards against deadlocking. | 109 // impl thread is not even scheduled to draw. Guards against deadlocking. |
110 if (!scheduledToDraw()) | 110 if (!scheduledToDraw()) |
111 return true; | 111 return true; |
112 if (!vsyncCallbackNeeded()) | 112 if (!vsyncCallbackNeeded()) |
113 return true; | 113 return true; |
114 return false; | 114 return false; |
115 } | 115 } |
116 | 116 |
117 SchedulerStateMachine::Action SchedulerStateMachine::nextAction() const | 117 SchedulerStateMachine::Action SchedulerStateMachine::nextAction() const |
118 { | 118 { |
119 if (shouldAcquireLayerTexturesForMainThread()) | 119 if (shouldAcquireLayerTexturesForMainThread()) |
120 return ACTION_ACQUIRE_LAYER_TEXTURES_FOR_MAIN_THREAD; | 120 return ACTION_ACQUIRE_LAYER_TEXTURES_FOR_MAIN_THREAD; |
121 switch (m_commitState) { | 121 switch (m_commitState) { |
122 case COMMIT_STATE_IDLE: | 122 case COMMIT_STATE_IDLE: |
123 if (m_outputSurfaceState != OUTPUT_SURFACE_ACTIVE && m_needsForcedRedraw
) | 123 if (m_contextState != CONTEXT_ACTIVE && m_needsForcedRedraw) |
124 return ACTION_DRAW_FORCED; | 124 return ACTION_DRAW_FORCED; |
125 if (m_outputSurfaceState != OUTPUT_SURFACE_ACTIVE && m_needsForcedCommit
) | 125 if (m_contextState != CONTEXT_ACTIVE && m_needsForcedCommit) |
126 return ACTION_BEGIN_FRAME; | 126 return ACTION_BEGIN_FRAME; |
127 if (m_outputSurfaceState == OUTPUT_SURFACE_LOST) | 127 if (m_contextState == CONTEXT_LOST) |
128 return ACTION_BEGIN_OUTPUT_SURFACE_RECREATION; | 128 return ACTION_BEGIN_CONTEXT_RECREATION; |
129 if (m_outputSurfaceState == OUTPUT_SURFACE_RECREATING) | 129 if (m_contextState == CONTEXT_RECREATING) |
130 return ACTION_NONE; | 130 return ACTION_NONE; |
131 if (shouldDraw()) | 131 if (shouldDraw()) |
132 return m_needsForcedRedraw ? ACTION_DRAW_FORCED : ACTION_DRAW_IF_POS
SIBLE; | 132 return m_needsForcedRedraw ? ACTION_DRAW_FORCED : ACTION_DRAW_IF_POS
SIBLE; |
133 if (m_needsCommit && ((m_visible && m_canBeginFrame) || m_needsForcedCom
mit)) | 133 if (m_needsCommit && ((m_visible && m_canBeginFrame) || m_needsForcedCom
mit)) |
134 return ACTION_BEGIN_FRAME; | 134 return ACTION_BEGIN_FRAME; |
135 return ACTION_NONE; | 135 return ACTION_NONE; |
136 | 136 |
137 case COMMIT_STATE_FRAME_IN_PROGRESS: | 137 case COMMIT_STATE_FRAME_IN_PROGRESS: |
138 if (shouldDraw()) | 138 if (shouldDraw()) |
139 return m_needsForcedRedraw ? ACTION_DRAW_FORCED : ACTION_DRAW_IF_POS
SIBLE; | 139 return m_needsForcedRedraw ? ACTION_DRAW_FORCED : ACTION_DRAW_IF_POS
SIBLE; |
140 return ACTION_NONE; | 140 return ACTION_NONE; |
141 | 141 |
142 case COMMIT_STATE_READY_TO_COMMIT: | 142 case COMMIT_STATE_READY_TO_COMMIT: |
143 return ACTION_COMMIT; | 143 return ACTION_COMMIT; |
144 | 144 |
145 case COMMIT_STATE_WAITING_FOR_FIRST_DRAW: | 145 case COMMIT_STATE_WAITING_FOR_FIRST_DRAW: |
146 if (shouldDraw() || m_outputSurfaceState == OUTPUT_SURFACE_LOST) | 146 if (shouldDraw() || m_contextState == CONTEXT_LOST) |
147 return m_needsForcedRedraw ? ACTION_DRAW_FORCED : ACTION_DRAW_IF_POS
SIBLE; | 147 return m_needsForcedRedraw ? ACTION_DRAW_FORCED : ACTION_DRAW_IF_POS
SIBLE; |
148 // COMMIT_STATE_WAITING_FOR_FIRST_DRAW wants to enforce a draw. If m_can
Draw is false | 148 // COMMIT_STATE_WAITING_FOR_FIRST_DRAW wants to enforce a draw. If m_can
Draw is false |
149 // or textures are not available, proceed to the next step (similar as i
n COMMIT_STATE_IDLE). | 149 // or textures are not available, proceed to the next step (similar as i
n COMMIT_STATE_IDLE). |
150 bool canCommit = m_visible || m_needsForcedCommit; | 150 bool canCommit = m_visible || m_needsForcedCommit; |
151 if (m_needsCommit && canCommit && drawSuspendedUntilCommit()) | 151 if (m_needsCommit && canCommit && drawSuspendedUntilCommit()) |
152 return ACTION_BEGIN_FRAME; | 152 return ACTION_BEGIN_FRAME; |
153 return ACTION_NONE; | 153 return ACTION_NONE; |
154 } | 154 } |
155 NOTREACHED(); | 155 NOTREACHED(); |
156 return ACTION_NONE; | 156 return ACTION_NONE; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 if (m_expectImmediateBeginFrame) { | 194 if (m_expectImmediateBeginFrame) { |
195 m_commitState = COMMIT_STATE_FRAME_IN_PROGRESS; | 195 m_commitState = COMMIT_STATE_FRAME_IN_PROGRESS; |
196 m_expectImmediateBeginFrame = false; | 196 m_expectImmediateBeginFrame = false; |
197 } else | 197 } else |
198 m_commitState = COMMIT_STATE_IDLE; | 198 m_commitState = COMMIT_STATE_IDLE; |
199 } | 199 } |
200 if (m_textureState == LAYER_TEXTURE_STATE_ACQUIRED_BY_IMPL_THREAD) | 200 if (m_textureState == LAYER_TEXTURE_STATE_ACQUIRED_BY_IMPL_THREAD) |
201 m_textureState = LAYER_TEXTURE_STATE_UNLOCKED; | 201 m_textureState = LAYER_TEXTURE_STATE_UNLOCKED; |
202 return; | 202 return; |
203 | 203 |
204 case ACTION_BEGIN_OUTPUT_SURFACE_RECREATION: | 204 case ACTION_BEGIN_CONTEXT_RECREATION: |
205 DCHECK(m_commitState == COMMIT_STATE_IDLE); | 205 DCHECK(m_commitState == COMMIT_STATE_IDLE); |
206 DCHECK(m_outputSurfaceState == OUTPUT_SURFACE_LOST); | 206 DCHECK(m_contextState == CONTEXT_LOST); |
207 m_outputSurfaceState = OUTPUT_SURFACE_RECREATING; | 207 m_contextState = CONTEXT_RECREATING; |
208 return; | 208 return; |
209 | 209 |
210 case ACTION_ACQUIRE_LAYER_TEXTURES_FOR_MAIN_THREAD: | 210 case ACTION_ACQUIRE_LAYER_TEXTURES_FOR_MAIN_THREAD: |
211 m_textureState = LAYER_TEXTURE_STATE_ACQUIRED_BY_MAIN_THREAD; | 211 m_textureState = LAYER_TEXTURE_STATE_ACQUIRED_BY_MAIN_THREAD; |
212 m_mainThreadNeedsLayerTextures = false; | 212 m_mainThreadNeedsLayerTextures = false; |
213 if (m_commitState != COMMIT_STATE_FRAME_IN_PROGRESS) | 213 if (m_commitState != COMMIT_STATE_FRAME_IN_PROGRESS) |
214 m_needsCommit = true; | 214 m_needsCommit = true; |
215 return; | 215 return; |
216 } | 216 } |
217 } | 217 } |
218 | 218 |
219 void SchedulerStateMachine::setMainThreadNeedsLayerTextures() | 219 void SchedulerStateMachine::setMainThreadNeedsLayerTextures() |
220 { | 220 { |
221 DCHECK(!m_mainThreadNeedsLayerTextures); | 221 DCHECK(!m_mainThreadNeedsLayerTextures); |
222 DCHECK(m_textureState != LAYER_TEXTURE_STATE_ACQUIRED_BY_MAIN_THREAD); | 222 DCHECK(m_textureState != LAYER_TEXTURE_STATE_ACQUIRED_BY_MAIN_THREAD); |
223 m_mainThreadNeedsLayerTextures = true; | 223 m_mainThreadNeedsLayerTextures = true; |
224 } | 224 } |
225 | 225 |
226 bool SchedulerStateMachine::vsyncCallbackNeeded() const | 226 bool SchedulerStateMachine::vsyncCallbackNeeded() const |
227 { | 227 { |
228 // If we can't draw, don't tick until we are notified that we can draw again
. | 228 // If we can't draw, don't tick until we are notified that we can draw again
. |
229 if (!m_canDraw) | 229 if (!m_canDraw) |
230 return false; | 230 return false; |
231 | 231 |
232 if (m_needsForcedRedraw) | 232 if (m_needsForcedRedraw) |
233 return true; | 233 return true; |
234 | 234 |
235 return m_needsRedraw && m_visible && m_outputSurfaceState == OUTPUT_SURFACE_
ACTIVE; | 235 return m_needsRedraw && m_visible && m_contextState == CONTEXT_ACTIVE; |
236 } | 236 } |
237 | 237 |
238 void SchedulerStateMachine::didEnterVSync() | 238 void SchedulerStateMachine::didEnterVSync() |
239 { | 239 { |
240 m_insideVSync = true; | 240 m_insideVSync = true; |
241 } | 241 } |
242 | 242 |
243 void SchedulerStateMachine::didLeaveVSync() | 243 void SchedulerStateMachine::didLeaveVSync() |
244 { | 244 { |
245 m_currentFrameNumber++; | 245 m_currentFrameNumber++; |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
300 { | 300 { |
301 DCHECK(m_commitState == COMMIT_STATE_FRAME_IN_PROGRESS); | 301 DCHECK(m_commitState == COMMIT_STATE_FRAME_IN_PROGRESS); |
302 if (m_expectImmediateBeginFrame) | 302 if (m_expectImmediateBeginFrame) |
303 m_expectImmediateBeginFrame = false; | 303 m_expectImmediateBeginFrame = false; |
304 else { | 304 else { |
305 m_commitState = COMMIT_STATE_IDLE; | 305 m_commitState = COMMIT_STATE_IDLE; |
306 setNeedsCommit(); | 306 setNeedsCommit(); |
307 } | 307 } |
308 } | 308 } |
309 | 309 |
310 void SchedulerStateMachine::didLoseOutputSurface() | 310 void SchedulerStateMachine::didLoseContext() |
311 { | 311 { |
312 if (m_outputSurfaceState == OUTPUT_SURFACE_LOST || m_outputSurfaceState == O
UTPUT_SURFACE_RECREATING) | 312 if (m_contextState == CONTEXT_LOST || m_contextState == CONTEXT_RECREATING) |
313 return; | 313 return; |
314 m_outputSurfaceState = OUTPUT_SURFACE_LOST; | 314 m_contextState = CONTEXT_LOST; |
315 } | 315 } |
316 | 316 |
317 void SchedulerStateMachine::didRecreateOutputSurface() | 317 void SchedulerStateMachine::didRecreateContext() |
318 { | 318 { |
319 DCHECK(m_outputSurfaceState == OUTPUT_SURFACE_RECREATING); | 319 DCHECK(m_contextState == CONTEXT_RECREATING); |
320 m_outputSurfaceState = OUTPUT_SURFACE_ACTIVE; | 320 m_contextState = CONTEXT_ACTIVE; |
321 setNeedsCommit(); | 321 setNeedsCommit(); |
322 } | 322 } |
323 | 323 |
324 void SchedulerStateMachine::setMaximumNumberOfFailedDrawsBeforeDrawIsForced(int
numDraws) | 324 void SchedulerStateMachine::setMaximumNumberOfFailedDrawsBeforeDrawIsForced(int
numDraws) |
325 { | 325 { |
326 m_maximumNumberOfFailedDrawsBeforeDrawIsForced = numDraws; | 326 m_maximumNumberOfFailedDrawsBeforeDrawIsForced = numDraws; |
327 } | 327 } |
328 | 328 |
329 } // namespace cc | 329 } // namespace cc |
OLD | NEW |