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/scheduler_state_machine.h" | 7 #include "cc/scheduler_state_machine.h" |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/stringprintf.h" | 10 #include "base/stringprintf.h" |
11 #include "cc/settings.h" | 11 #include "cc/settings.h" |
12 | 12 |
13 namespace cc { | 13 namespace cc { |
14 | 14 |
15 SchedulerStateMachine::SchedulerStateMachine() | 15 SchedulerStateMachine::SchedulerStateMachine() |
16 : m_commitState(COMMIT_STATE_IDLE) | 16 : m_commitState(COMMIT_STATE_IDLE) |
17 , m_currentFrameNumber(0) | 17 , m_currentFrameNumber(0) |
18 , m_lastFrameNumberWhereDrawWasCalled(-1) | 18 , m_lastFrameNumberWhereDrawWasCalled(-1) |
19 , m_consecutiveFailedDraws(0) | 19 , m_consecutiveFailedDraws(0) |
20 , m_maximumNumberOfFailedDrawsBeforeDrawIsForced(3) | 20 , m_maximumNumberOfFailedDrawsBeforeDrawIsForced(3) |
21 , m_needsRedraw(false) | 21 , m_needsRedraw(false) |
22 , m_needsForcedRedraw(false) | 22 , m_needsForcedRedraw(false) |
23 , m_needsForcedRedrawAfterNextCommit(false) | 23 , m_needsForcedRedrawAfterNextCommit(false) |
24 , m_needsCommit(false) | 24 , m_needsCommit(false) |
25 , m_needsForcedCommit(false) | 25 , m_needsForcedCommit(false) |
| 26 , m_expectImmediateBeginFrame(false) |
26 , m_mainThreadNeedsLayerTextures(false) | 27 , m_mainThreadNeedsLayerTextures(false) |
27 , m_insideVSync(false) | 28 , m_insideVSync(false) |
28 , m_visible(false) | 29 , m_visible(false) |
29 , m_canBeginFrame(false) | 30 , m_canBeginFrame(false) |
30 , m_canDraw(false) | 31 , m_canDraw(false) |
31 , m_drawIfPossibleFailed(false) | 32 , m_drawIfPossibleFailed(false) |
32 , m_textureState(LAYER_TEXTURE_STATE_UNLOCKED) | 33 , m_textureState(LAYER_TEXTURE_STATE_UNLOCKED) |
33 , m_contextState(CONTEXT_ACTIVE) | 34 , m_contextState(CONTEXT_ACTIVE) |
34 { | 35 { |
35 } | 36 } |
36 | 37 |
37 std::string SchedulerStateMachine::toString() | 38 std::string SchedulerStateMachine::toString() |
38 { | 39 { |
39 std::string str; | 40 std::string str; |
40 base::StringAppendF(&str, "m_commitState = %d; ", m_commitState); | 41 base::StringAppendF(&str, "m_commitState = %d; ", m_commitState); |
41 base::StringAppendF(&str, "m_currentFrameNumber = %d; ", m_currentFrameNumbe
r); | 42 base::StringAppendF(&str, "m_currentFrameNumber = %d; ", m_currentFrameNumbe
r); |
42 base::StringAppendF(&str, "m_lastFrameNumberWhereDrawWasCalled = %d; ", m_la
stFrameNumberWhereDrawWasCalled); | 43 base::StringAppendF(&str, "m_lastFrameNumberWhereDrawWasCalled = %d; ", m_la
stFrameNumberWhereDrawWasCalled); |
43 base::StringAppendF(&str, "m_consecutiveFailedDraws = %d; ", m_consecutiveFa
iledDraws); | 44 base::StringAppendF(&str, "m_consecutiveFailedDraws = %d; ", m_consecutiveFa
iledDraws); |
44 base::StringAppendF(&str, "m_maximumNumberOfFailedDrawsBeforeDrawIsForced =
%d; ", m_maximumNumberOfFailedDrawsBeforeDrawIsForced); | 45 base::StringAppendF(&str, "m_maximumNumberOfFailedDrawsBeforeDrawIsForced =
%d; ", m_maximumNumberOfFailedDrawsBeforeDrawIsForced); |
45 base::StringAppendF(&str, "m_needsRedraw = %d; ", m_needsRedraw); | 46 base::StringAppendF(&str, "m_needsRedraw = %d; ", m_needsRedraw); |
46 base::StringAppendF(&str, "m_needsForcedRedraw = %d; ", m_needsForcedRedraw)
; | 47 base::StringAppendF(&str, "m_needsForcedRedraw = %d; ", m_needsForcedRedraw)
; |
47 base::StringAppendF(&str, "m_needsForcedRedrawAfterNextCommit = %d; ", m_nee
dsForcedRedrawAfterNextCommit); | 48 base::StringAppendF(&str, "m_needsForcedRedrawAfterNextCommit = %d; ", m_nee
dsForcedRedrawAfterNextCommit); |
48 base::StringAppendF(&str, "m_needsCommit = %d; ", m_needsCommit); | 49 base::StringAppendF(&str, "m_needsCommit = %d; ", m_needsCommit); |
49 base::StringAppendF(&str, "m_needsForcedCommit = %d; ", m_needsForcedCommit)
; | 50 base::StringAppendF(&str, "m_needsForcedCommit = %d; ", m_needsForcedCommit)
; |
| 51 base::StringAppendF(&str, "m_expectImmediateBeginFrame = %d; ", m_expectImme
diateBeginFrame); |
50 base::StringAppendF(&str, "m_mainThreadNeedsLayerTextures = %d; ", m_mainThr
eadNeedsLayerTextures); | 52 base::StringAppendF(&str, "m_mainThreadNeedsLayerTextures = %d; ", m_mainThr
eadNeedsLayerTextures); |
51 base::StringAppendF(&str, "m_insideVSync = %d; ", m_insideVSync); | 53 base::StringAppendF(&str, "m_insideVSync = %d; ", m_insideVSync); |
52 base::StringAppendF(&str, "m_visible = %d; ", m_visible); | 54 base::StringAppendF(&str, "m_visible = %d; ", m_visible); |
53 base::StringAppendF(&str, "m_canBeginFrame = %d; ", m_canBeginFrame); | 55 base::StringAppendF(&str, "m_canBeginFrame = %d; ", m_canBeginFrame); |
54 base::StringAppendF(&str, "m_canDraw = %d; ", m_canDraw); | 56 base::StringAppendF(&str, "m_canDraw = %d; ", m_canDraw); |
55 base::StringAppendF(&str, "m_drawIfPossibleFailed = %d; ", m_drawIfPossibleF
ailed); | 57 base::StringAppendF(&str, "m_drawIfPossibleFailed = %d; ", m_drawIfPossibleF
ailed); |
56 base::StringAppendF(&str, "m_textureState = %d; ", m_textureState); | 58 base::StringAppendF(&str, "m_textureState = %d; ", m_textureState); |
57 base::StringAppendF(&str, "m_contextState = %d; ", m_contextState); | 59 base::StringAppendF(&str, "m_contextState = %d; ", m_contextState); |
58 return str; | 60 return str; |
59 } | 61 } |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 m_textureState = LAYER_TEXTURE_STATE_ACQUIRED_BY_IMPL_THREAD; | 186 m_textureState = LAYER_TEXTURE_STATE_ACQUIRED_BY_IMPL_THREAD; |
185 return; | 187 return; |
186 | 188 |
187 case ACTION_DRAW_FORCED: | 189 case ACTION_DRAW_FORCED: |
188 case ACTION_DRAW_IF_POSSIBLE: | 190 case ACTION_DRAW_IF_POSSIBLE: |
189 m_needsRedraw = false; | 191 m_needsRedraw = false; |
190 m_needsForcedRedraw = false; | 192 m_needsForcedRedraw = false; |
191 m_drawIfPossibleFailed = false; | 193 m_drawIfPossibleFailed = false; |
192 if (m_insideVSync) | 194 if (m_insideVSync) |
193 m_lastFrameNumberWhereDrawWasCalled = m_currentFrameNumber; | 195 m_lastFrameNumberWhereDrawWasCalled = m_currentFrameNumber; |
194 if (m_commitState == COMMIT_STATE_WAITING_FOR_FIRST_DRAW) | 196 if (m_commitState == COMMIT_STATE_WAITING_FOR_FIRST_DRAW) { |
195 m_commitState = COMMIT_STATE_IDLE; | 197 if (m_expectImmediateBeginFrame) { |
| 198 m_commitState = COMMIT_STATE_FRAME_IN_PROGRESS; |
| 199 m_expectImmediateBeginFrame = false; |
| 200 } else |
| 201 m_commitState = COMMIT_STATE_IDLE; |
| 202 } |
196 if (m_textureState == LAYER_TEXTURE_STATE_ACQUIRED_BY_IMPL_THREAD) | 203 if (m_textureState == LAYER_TEXTURE_STATE_ACQUIRED_BY_IMPL_THREAD) |
197 m_textureState = LAYER_TEXTURE_STATE_UNLOCKED; | 204 m_textureState = LAYER_TEXTURE_STATE_UNLOCKED; |
198 return; | 205 return; |
199 | 206 |
200 case ACTION_BEGIN_CONTEXT_RECREATION: | 207 case ACTION_BEGIN_CONTEXT_RECREATION: |
201 DCHECK(m_commitState == COMMIT_STATE_IDLE); | 208 DCHECK(m_commitState == COMMIT_STATE_IDLE); |
202 DCHECK(m_contextState == CONTEXT_LOST); | 209 DCHECK(m_contextState == CONTEXT_LOST); |
203 m_contextState = CONTEXT_RECREATING; | 210 m_contextState = CONTEXT_RECREATING; |
204 return; | 211 return; |
205 | 212 |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
275 } | 282 } |
276 | 283 |
277 void SchedulerStateMachine::setNeedsCommit() | 284 void SchedulerStateMachine::setNeedsCommit() |
278 { | 285 { |
279 m_needsCommit = true; | 286 m_needsCommit = true; |
280 } | 287 } |
281 | 288 |
282 void SchedulerStateMachine::setNeedsForcedCommit() | 289 void SchedulerStateMachine::setNeedsForcedCommit() |
283 { | 290 { |
284 m_needsForcedCommit = true; | 291 m_needsForcedCommit = true; |
| 292 m_expectImmediateBeginFrame = true; |
285 } | 293 } |
286 | 294 |
287 void SchedulerStateMachine::beginFrameComplete() | 295 void SchedulerStateMachine::beginFrameComplete() |
288 { | 296 { |
289 DCHECK(m_commitState == COMMIT_STATE_FRAME_IN_PROGRESS); | 297 DCHECK(m_commitState == COMMIT_STATE_FRAME_IN_PROGRESS || |
| 298 (m_expectImmediateBeginFrame && m_commitState != COMMIT_STATE_IDLE))
<< toString(); |
290 m_commitState = COMMIT_STATE_READY_TO_COMMIT; | 299 m_commitState = COMMIT_STATE_READY_TO_COMMIT; |
291 } | 300 } |
292 | 301 |
293 void SchedulerStateMachine::beginFrameAborted() | 302 void SchedulerStateMachine::beginFrameAborted() |
294 { | 303 { |
295 DCHECK(m_commitState == COMMIT_STATE_FRAME_IN_PROGRESS); | 304 DCHECK(m_commitState == COMMIT_STATE_FRAME_IN_PROGRESS); |
296 m_commitState = COMMIT_STATE_IDLE; | 305 if (m_expectImmediateBeginFrame) |
297 setNeedsCommit(); | 306 m_expectImmediateBeginFrame = false; |
| 307 else { |
| 308 m_commitState = COMMIT_STATE_IDLE; |
| 309 setNeedsCommit(); |
| 310 } |
298 } | 311 } |
299 | 312 |
300 void SchedulerStateMachine::didLoseContext() | 313 void SchedulerStateMachine::didLoseContext() |
301 { | 314 { |
302 if (m_contextState == CONTEXT_LOST || m_contextState == CONTEXT_RECREATING) | 315 if (m_contextState == CONTEXT_LOST || m_contextState == CONTEXT_RECREATING) |
303 return; | 316 return; |
304 m_contextState = CONTEXT_LOST; | 317 m_contextState = CONTEXT_LOST; |
305 } | 318 } |
306 | 319 |
307 void SchedulerStateMachine::didRecreateContext() | 320 void SchedulerStateMachine::didRecreateContext() |
308 { | 321 { |
309 DCHECK(m_contextState == CONTEXT_RECREATING); | 322 DCHECK(m_contextState == CONTEXT_RECREATING); |
310 m_contextState = CONTEXT_ACTIVE; | 323 m_contextState = CONTEXT_ACTIVE; |
311 setNeedsCommit(); | 324 setNeedsCommit(); |
312 } | 325 } |
313 | 326 |
314 void SchedulerStateMachine::setMaximumNumberOfFailedDrawsBeforeDrawIsForced(int
numDraws) | 327 void SchedulerStateMachine::setMaximumNumberOfFailedDrawsBeforeDrawIsForced(int
numDraws) |
315 { | 328 { |
316 m_maximumNumberOfFailedDrawsBeforeDrawIsForced = numDraws; | 329 m_maximumNumberOfFailedDrawsBeforeDrawIsForced = numDraws; |
317 } | 330 } |
318 | 331 |
319 } | 332 } |
OLD | NEW |