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 "CCSchedulerStateMachine.h" | 7 #include "CCSchedulerStateMachine.h" |
8 #include "base/stringprintf.h" | 8 #include "base/stringprintf.h" |
9 | 9 |
10 | 10 |
11 namespace WebCore { | 11 namespace WebCore { |
12 | 12 |
13 CCSchedulerStateMachine::CCSchedulerStateMachine() | 13 CCSchedulerStateMachine::CCSchedulerStateMachine() |
14 : m_commitState(COMMIT_STATE_IDLE) | 14 : m_commitState(COMMIT_STATE_IDLE) |
15 , m_currentFrameNumber(0) | 15 , m_currentFrameNumber(0) |
16 , m_lastFrameNumberWhereDrawWasCalled(-1) | 16 , m_lastFrameNumberWhereDrawWasCalled(-1) |
17 , m_consecutiveFailedDraws(0) | 17 , m_consecutiveFailedDraws(0) |
18 , m_maximumNumberOfFailedDrawsBeforeDrawIsForced(3) | 18 , m_maximumNumberOfFailedDrawsBeforeDrawIsForced(3) |
19 , m_needsRedraw(false) | 19 , m_needsRedraw(false) |
20 , m_needsForcedRedraw(false) | 20 , m_needsForcedRedraw(false) |
21 , m_needsForcedRedrawAfterNextCommit(false) | 21 , m_needsForcedRedrawAfterNextCommit(false) |
22 , m_needsCommit(false) | 22 , m_needsCommit(false) |
23 , m_needsForcedCommit(false) | 23 , m_needsForcedCommit(false) |
24 , m_mainThreadNeedsLayerTextures(false) | 24 , m_mainThreadNeedsLayerTextures(false) |
25 , m_updateMoreResourcesPending(false) | 25 , m_updateResourcesCompletePending(false) |
26 , m_insideVSync(false) | 26 , m_insideVSync(false) |
27 , m_visible(false) | 27 , m_visible(false) |
28 , m_canBeginFrame(false) | 28 , m_canBeginFrame(false) |
29 , m_canDraw(false) | 29 , m_canDraw(false) |
30 , m_drawIfPossibleFailed(false) | 30 , m_drawIfPossibleFailed(false) |
31 , m_textureState(LAYER_TEXTURE_STATE_UNLOCKED) | 31 , m_textureState(LAYER_TEXTURE_STATE_UNLOCKED) |
32 , m_contextState(CONTEXT_ACTIVE) | 32 , m_contextState(CONTEXT_ACTIVE) |
33 { | 33 { |
34 } | 34 } |
35 | 35 |
36 std::string CCSchedulerStateMachine::toString() | 36 std::string CCSchedulerStateMachine::toString() |
37 { | 37 { |
38 std::string str; | 38 std::string str; |
39 base::StringAppendF(&str, "m_commitState = %d; ", m_commitState); | 39 base::StringAppendF(&str, "m_commitState = %d; ", m_commitState); |
40 base::StringAppendF(&str, "m_currentFrameNumber = %d; ", m_currentFrameNumbe
r); | 40 base::StringAppendF(&str, "m_currentFrameNumber = %d; ", m_currentFrameNumbe
r); |
41 base::StringAppendF(&str, "m_lastFrameNumberWhereDrawWasCalled = %d; ", m_la
stFrameNumberWhereDrawWasCalled); | 41 base::StringAppendF(&str, "m_lastFrameNumberWhereDrawWasCalled = %d; ", m_la
stFrameNumberWhereDrawWasCalled); |
42 base::StringAppendF(&str, "m_consecutiveFailedDraws = %d; ", m_consecutiveFa
iledDraws); | 42 base::StringAppendF(&str, "m_consecutiveFailedDraws = %d; ", m_consecutiveFa
iledDraws); |
43 base::StringAppendF(&str, "m_maximumNumberOfFailedDrawsBeforeDrawIsForced =
%d; ", m_maximumNumberOfFailedDrawsBeforeDrawIsForced); | 43 base::StringAppendF(&str, "m_maximumNumberOfFailedDrawsBeforeDrawIsForced =
%d; ", m_maximumNumberOfFailedDrawsBeforeDrawIsForced); |
44 base::StringAppendF(&str, "m_needsRedraw = %d; ", m_needsRedraw); | 44 base::StringAppendF(&str, "m_needsRedraw = %d; ", m_needsRedraw); |
45 base::StringAppendF(&str, "m_needsForcedRedraw = %d; ", m_needsForcedRedraw)
; | 45 base::StringAppendF(&str, "m_needsForcedRedraw = %d; ", m_needsForcedRedraw)
; |
46 base::StringAppendF(&str, "m_needsForcedRedrawAfterNextCommit = %d; ", m_nee
dsForcedRedrawAfterNextCommit); | 46 base::StringAppendF(&str, "m_needsForcedRedrawAfterNextCommit = %d; ", m_nee
dsForcedRedrawAfterNextCommit); |
47 base::StringAppendF(&str, "m_needsCommit = %d; ", m_needsCommit); | 47 base::StringAppendF(&str, "m_needsCommit = %d; ", m_needsCommit); |
48 base::StringAppendF(&str, "m_needsForcedCommit = %d; ", m_needsForcedCommit)
; | 48 base::StringAppendF(&str, "m_needsForcedCommit = %d; ", m_needsForcedCommit)
; |
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_updateMoreResourcesPending = %d; ", m_updateMor
eResourcesPending); | 50 base::StringAppendF(&str, "m_updateResourcesCompletePending = %d; ", m_updat
eResourcesCompletePending); |
51 base::StringAppendF(&str, "m_insideVSync = %d; ", m_insideVSync); | 51 base::StringAppendF(&str, "m_insideVSync = %d; ", m_insideVSync); |
52 base::StringAppendF(&str, "m_visible = %d; ", m_visible); | 52 base::StringAppendF(&str, "m_visible = %d; ", m_visible); |
53 base::StringAppendF(&str, "m_canBeginFrame = %d; ", m_canBeginFrame); | 53 base::StringAppendF(&str, "m_canBeginFrame = %d; ", m_canBeginFrame); |
54 base::StringAppendF(&str, "m_canDraw = %d; ", m_canDraw); | 54 base::StringAppendF(&str, "m_canDraw = %d; ", m_canDraw); |
55 base::StringAppendF(&str, "m_drawIfPossibleFailed = %d; ", m_drawIfPossibleF
ailed); | 55 base::StringAppendF(&str, "m_drawIfPossibleFailed = %d; ", m_drawIfPossibleF
ailed); |
56 base::StringAppendF(&str, "m_textureState = %d; ", m_textureState); | 56 base::StringAppendF(&str, "m_textureState = %d; ", m_textureState); |
57 base::StringAppendF(&str, "m_contextState = %d; ", m_contextState); | 57 base::StringAppendF(&str, "m_contextState = %d; ", m_contextState); |
58 return str; | 58 return str; |
59 } | 59 } |
60 | 60 |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 return ACTION_NONE; | 136 return ACTION_NONE; |
137 | 137 |
138 case COMMIT_STATE_FRAME_IN_PROGRESS: | 138 case COMMIT_STATE_FRAME_IN_PROGRESS: |
139 if (shouldDraw()) | 139 if (shouldDraw()) |
140 return m_needsForcedRedraw ? ACTION_DRAW_FORCED : ACTION_DRAW_IF_POS
SIBLE; | 140 return m_needsForcedRedraw ? ACTION_DRAW_FORCED : ACTION_DRAW_IF_POS
SIBLE; |
141 return ACTION_NONE; | 141 return ACTION_NONE; |
142 | 142 |
143 case COMMIT_STATE_UPDATING_RESOURCES: | 143 case COMMIT_STATE_UPDATING_RESOURCES: |
144 if (shouldDraw()) | 144 if (shouldDraw()) |
145 return m_needsForcedRedraw ? ACTION_DRAW_FORCED : ACTION_DRAW_IF_POS
SIBLE; | 145 return m_needsForcedRedraw ? ACTION_DRAW_FORCED : ACTION_DRAW_IF_POS
SIBLE; |
146 if (!m_updateMoreResourcesPending) | 146 if (!m_updateResourcesCompletePending) |
147 return ACTION_BEGIN_UPDATE_MORE_RESOURCES; | 147 return ACTION_BEGIN_UPDATE_RESOURCES; |
148 return ACTION_NONE; | 148 return ACTION_NONE; |
149 | 149 |
150 case COMMIT_STATE_READY_TO_COMMIT: | 150 case COMMIT_STATE_READY_TO_COMMIT: |
151 return ACTION_COMMIT; | 151 return ACTION_COMMIT; |
152 | 152 |
153 case COMMIT_STATE_WAITING_FOR_FIRST_DRAW: | 153 case COMMIT_STATE_WAITING_FOR_FIRST_DRAW: |
154 if (shouldDraw() || m_contextState == CONTEXT_LOST) | 154 if (shouldDraw() || m_contextState == CONTEXT_LOST) |
155 return m_needsForcedRedraw ? ACTION_DRAW_FORCED : ACTION_DRAW_IF_POS
SIBLE; | 155 return m_needsForcedRedraw ? ACTION_DRAW_FORCED : ACTION_DRAW_IF_POS
SIBLE; |
156 // COMMIT_STATE_WAITING_FOR_FIRST_DRAW wants to enforce a draw. If m_can
Draw is false | 156 // COMMIT_STATE_WAITING_FOR_FIRST_DRAW wants to enforce a draw. If m_can
Draw is false |
157 // or textures are not available, proceed to the next step (similar as i
n COMMIT_STATE_IDLE). | 157 // or textures are not available, proceed to the next step (similar as i
n COMMIT_STATE_IDLE). |
(...skipping 12 matching lines...) Expand all Loading... |
170 case ACTION_NONE: | 170 case ACTION_NONE: |
171 return; | 171 return; |
172 | 172 |
173 case ACTION_BEGIN_FRAME: | 173 case ACTION_BEGIN_FRAME: |
174 ASSERT(m_visible || m_needsForcedCommit); | 174 ASSERT(m_visible || m_needsForcedCommit); |
175 m_commitState = COMMIT_STATE_FRAME_IN_PROGRESS; | 175 m_commitState = COMMIT_STATE_FRAME_IN_PROGRESS; |
176 m_needsCommit = false; | 176 m_needsCommit = false; |
177 m_needsForcedCommit = false; | 177 m_needsForcedCommit = false; |
178 return; | 178 return; |
179 | 179 |
180 case ACTION_BEGIN_UPDATE_MORE_RESOURCES: | 180 case ACTION_BEGIN_UPDATE_RESOURCES: |
181 ASSERT(m_commitState == COMMIT_STATE_UPDATING_RESOURCES); | 181 ASSERT(m_commitState == COMMIT_STATE_UPDATING_RESOURCES); |
182 m_updateMoreResourcesPending = true; | 182 m_updateResourcesCompletePending = true; |
183 return; | 183 return; |
184 | 184 |
185 case ACTION_COMMIT: | 185 case ACTION_COMMIT: |
186 m_commitState = COMMIT_STATE_WAITING_FOR_FIRST_DRAW; | 186 m_commitState = COMMIT_STATE_WAITING_FOR_FIRST_DRAW; |
187 m_needsRedraw = true; | 187 m_needsRedraw = true; |
188 if (m_drawIfPossibleFailed) | 188 if (m_drawIfPossibleFailed) |
189 m_lastFrameNumberWhereDrawWasCalled = -1; | 189 m_lastFrameNumberWhereDrawWasCalled = -1; |
190 | 190 |
191 if (m_needsForcedRedrawAfterNextCommit) { | 191 if (m_needsForcedRedrawAfterNextCommit) { |
192 m_needsForcedRedrawAfterNextCommit = false; | 192 m_needsForcedRedrawAfterNextCommit = false; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 void CCSchedulerStateMachine::setMainThreadNeedsLayerTextures() | 227 void CCSchedulerStateMachine::setMainThreadNeedsLayerTextures() |
228 { | 228 { |
229 ASSERT(!m_mainThreadNeedsLayerTextures); | 229 ASSERT(!m_mainThreadNeedsLayerTextures); |
230 ASSERT(m_textureState != LAYER_TEXTURE_STATE_ACQUIRED_BY_MAIN_THREAD); | 230 ASSERT(m_textureState != LAYER_TEXTURE_STATE_ACQUIRED_BY_MAIN_THREAD); |
231 m_mainThreadNeedsLayerTextures = true; | 231 m_mainThreadNeedsLayerTextures = true; |
232 } | 232 } |
233 | 233 |
234 bool CCSchedulerStateMachine::vsyncCallbackNeeded() const | 234 bool CCSchedulerStateMachine::vsyncCallbackNeeded() const |
235 { | 235 { |
236 // To prevent live-lock, we must always tick when updating resources. | 236 // To prevent live-lock, we must always tick when updating resources. |
237 if (m_updateMoreResourcesPending || m_commitState == COMMIT_STATE_UPDATING_R
ESOURCES) | 237 if (m_updateResourcesCompletePending || m_commitState == COMMIT_STATE_UPDATI
NG_RESOURCES) |
238 return true; | 238 return true; |
239 | 239 |
240 // If we can't draw, don't tick until we are notified that we can draw again
. | 240 // If we can't draw, don't tick until we are notified that we can draw again
. |
241 if (!m_canDraw) | 241 if (!m_canDraw) |
242 return false; | 242 return false; |
243 | 243 |
244 if (m_needsForcedRedraw) | 244 if (m_needsForcedRedraw) |
245 return true; | 245 return true; |
246 | 246 |
247 return m_needsRedraw && m_visible && m_contextState == CONTEXT_ACTIVE; | 247 return m_needsRedraw && m_visible && m_contextState == CONTEXT_ACTIVE; |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
293 void CCSchedulerStateMachine::setNeedsCommit() | 293 void CCSchedulerStateMachine::setNeedsCommit() |
294 { | 294 { |
295 m_needsCommit = true; | 295 m_needsCommit = true; |
296 } | 296 } |
297 | 297 |
298 void CCSchedulerStateMachine::setNeedsForcedCommit() | 298 void CCSchedulerStateMachine::setNeedsForcedCommit() |
299 { | 299 { |
300 m_needsForcedCommit = true; | 300 m_needsForcedCommit = true; |
301 } | 301 } |
302 | 302 |
303 void CCSchedulerStateMachine::beginFrameComplete() | 303 void CCSchedulerStateMachine::beginFrameComplete(bool hasResourceUpdates) |
304 { | 304 { |
305 ASSERT(m_commitState == COMMIT_STATE_FRAME_IN_PROGRESS); | 305 ASSERT(m_commitState == COMMIT_STATE_FRAME_IN_PROGRESS); |
306 m_commitState = COMMIT_STATE_UPDATING_RESOURCES; | 306 if (hasResourceUpdates) |
| 307 m_commitState = COMMIT_STATE_UPDATING_RESOURCES; |
| 308 else |
| 309 m_commitState = COMMIT_STATE_READY_TO_COMMIT; |
307 } | 310 } |
308 | 311 |
309 void CCSchedulerStateMachine::beginFrameAborted() | 312 void CCSchedulerStateMachine::beginFrameAborted() |
310 { | 313 { |
311 ASSERT(m_commitState == COMMIT_STATE_FRAME_IN_PROGRESS); | 314 ASSERT(m_commitState == COMMIT_STATE_FRAME_IN_PROGRESS); |
312 m_commitState = COMMIT_STATE_IDLE; | 315 m_commitState = COMMIT_STATE_IDLE; |
313 setNeedsCommit(); | 316 setNeedsCommit(); |
314 } | 317 } |
315 | 318 |
316 void CCSchedulerStateMachine::beginUpdateMoreResourcesComplete(bool morePending) | 319 void CCSchedulerStateMachine::updateResourcesComplete() |
317 { | 320 { |
318 ASSERT(m_commitState == COMMIT_STATE_UPDATING_RESOURCES); | 321 ASSERT(m_commitState == COMMIT_STATE_UPDATING_RESOURCES); |
319 ASSERT(m_updateMoreResourcesPending); | 322 ASSERT(m_updateResourcesCompletePending); |
320 m_updateMoreResourcesPending = false; | 323 m_updateResourcesCompletePending = false; |
321 if (!morePending) | 324 m_commitState = COMMIT_STATE_READY_TO_COMMIT; |
322 m_commitState = COMMIT_STATE_READY_TO_COMMIT; | |
323 } | 325 } |
324 | 326 |
325 void CCSchedulerStateMachine::didLoseContext() | 327 void CCSchedulerStateMachine::didLoseContext() |
326 { | 328 { |
327 if (m_contextState == CONTEXT_LOST || m_contextState == CONTEXT_RECREATING) | 329 if (m_contextState == CONTEXT_LOST || m_contextState == CONTEXT_RECREATING) |
328 return; | 330 return; |
329 m_contextState = CONTEXT_LOST; | 331 m_contextState = CONTEXT_LOST; |
330 } | 332 } |
331 | 333 |
332 void CCSchedulerStateMachine::didRecreateContext() | 334 void CCSchedulerStateMachine::didRecreateContext() |
333 { | 335 { |
334 ASSERT(m_contextState == CONTEXT_RECREATING); | 336 ASSERT(m_contextState == CONTEXT_RECREATING); |
335 m_contextState = CONTEXT_ACTIVE; | 337 m_contextState = CONTEXT_ACTIVE; |
336 setNeedsCommit(); | 338 setNeedsCommit(); |
337 } | 339 } |
338 | 340 |
339 void CCSchedulerStateMachine::setMaximumNumberOfFailedDrawsBeforeDrawIsForced(in
t numDraws) | 341 void CCSchedulerStateMachine::setMaximumNumberOfFailedDrawsBeforeDrawIsForced(in
t numDraws) |
340 { | 342 { |
341 m_maximumNumberOfFailedDrawsBeforeDrawIsForced = numDraws; | 343 m_maximumNumberOfFailedDrawsBeforeDrawIsForced = numDraws; |
342 } | 344 } |
343 | 345 |
344 } | 346 } |
OLD | NEW |