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