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