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 | 8 |
9 #include <gtest/gtest.h> | 9 #include <gtest/gtest.h> |
10 | 10 |
(...skipping 25 matching lines...) Expand all Loading... |
36 void setNeedsRedraw(bool b) { m_needsRedraw = b; } | 36 void setNeedsRedraw(bool b) { m_needsRedraw = b; } |
37 bool needsRedraw() const { return m_needsRedraw; } | 37 bool needsRedraw() const { return m_needsRedraw; } |
38 | 38 |
39 void setNeedsForcedRedraw(bool b) { m_needsForcedRedraw = b; } | 39 void setNeedsForcedRedraw(bool b) { m_needsForcedRedraw = b; } |
40 bool needsForcedRedraw() const { return m_needsForcedRedraw; } | 40 bool needsForcedRedraw() const { return m_needsForcedRedraw; } |
41 | 41 |
42 bool canDraw() const { return m_canDraw; } | 42 bool canDraw() const { return m_canDraw; } |
43 bool insideVSync() const { return m_insideVSync; } | 43 bool insideVSync() const { return m_insideVSync; } |
44 bool visible() const { return m_visible; } | 44 bool visible() const { return m_visible; } |
45 | 45 |
46 void setUpdateMoreResourcesPending(bool b) { m_updateMoreResourcesPending =
b; } | 46 void setUpdateResourcesCompletePending(bool b) { m_updateResourcesCompletePe
nding = b; } |
47 bool updateMoreResourcesPending() const { return m_updateMoreResourcesPendin
g; } | 47 bool updateResourcesCompletePending() const { return m_updateResourcesComple
tePending; } |
48 }; | 48 }; |
49 | 49 |
50 TEST(CCSchedulerStateMachineTest, TestNextActionBeginsFrameIfNeeded) | 50 TEST(CCSchedulerStateMachineTest, TestNextActionBeginsFrameIfNeeded) |
51 { | 51 { |
52 // If no commit needed, do nothing | 52 // If no commit needed, do nothing |
53 { | 53 { |
54 StateMachine state; | 54 StateMachine state; |
55 state.setCommitState(CCSchedulerStateMachine::COMMIT_STATE_IDLE); | 55 state.setCommitState(CCSchedulerStateMachine::COMMIT_STATE_IDLE); |
56 state.setCanBeginFrame(true); | 56 state.setCanBeginFrame(true); |
57 state.setNeedsRedraw(false); | 57 state.setNeedsRedraw(false); |
58 state.setNeedsCommit(false); | 58 state.setNeedsCommit(false); |
59 state.setUpdateMoreResourcesPending(false); | 59 state.setUpdateResourcesCompletePending(false); |
60 state.setVisible(true); | 60 state.setVisible(true); |
61 | 61 |
62 EXPECT_FALSE(state.vsyncCallbackNeeded()); | 62 EXPECT_FALSE(state.vsyncCallbackNeeded()); |
63 | 63 |
64 state.didLeaveVSync(); | 64 state.didLeaveVSync(); |
65 EXPECT_EQ(CCSchedulerStateMachine::ACTION_NONE, state.nextAction()); | 65 EXPECT_EQ(CCSchedulerStateMachine::ACTION_NONE, state.nextAction()); |
66 EXPECT_FALSE(state.vsyncCallbackNeeded()); | 66 EXPECT_FALSE(state.vsyncCallbackNeeded()); |
67 state.didEnterVSync(); | 67 state.didEnterVSync(); |
68 EXPECT_EQ(CCSchedulerStateMachine::ACTION_NONE, state.nextAction()); | 68 EXPECT_EQ(CCSchedulerStateMachine::ACTION_NONE, state.nextAction()); |
69 } | 69 } |
70 | 70 |
71 // If commit requested but canBeginFrame is still false, do nothing. | 71 // If commit requested but canBeginFrame is still false, do nothing. |
72 { | 72 { |
73 StateMachine state; | 73 StateMachine state; |
74 state.setCommitState(CCSchedulerStateMachine::COMMIT_STATE_IDLE); | 74 state.setCommitState(CCSchedulerStateMachine::COMMIT_STATE_IDLE); |
75 state.setNeedsRedraw(false); | 75 state.setNeedsRedraw(false); |
76 state.setNeedsCommit(false); | 76 state.setNeedsCommit(false); |
77 state.setUpdateMoreResourcesPending(false); | 77 state.setUpdateResourcesCompletePending(false); |
78 state.setVisible(true); | 78 state.setVisible(true); |
79 | 79 |
80 EXPECT_FALSE(state.vsyncCallbackNeeded()); | 80 EXPECT_FALSE(state.vsyncCallbackNeeded()); |
81 | 81 |
82 state.didLeaveVSync(); | 82 state.didLeaveVSync(); |
83 EXPECT_EQ(CCSchedulerStateMachine::ACTION_NONE, state.nextAction()); | 83 EXPECT_EQ(CCSchedulerStateMachine::ACTION_NONE, state.nextAction()); |
84 EXPECT_FALSE(state.vsyncCallbackNeeded()); | 84 EXPECT_FALSE(state.vsyncCallbackNeeded()); |
85 state.didEnterVSync(); | 85 state.didEnterVSync(); |
86 EXPECT_EQ(CCSchedulerStateMachine::ACTION_NONE, state.nextAction()); | 86 EXPECT_EQ(CCSchedulerStateMachine::ACTION_NONE, state.nextAction()); |
87 } | 87 } |
88 | 88 |
89 | 89 |
90 // If commit requested, begin a frame | 90 // If commit requested, begin a frame |
91 { | 91 { |
92 StateMachine state; | 92 StateMachine state; |
93 state.setCommitState(CCSchedulerStateMachine::COMMIT_STATE_IDLE); | 93 state.setCommitState(CCSchedulerStateMachine::COMMIT_STATE_IDLE); |
94 state.setCanBeginFrame(true); | 94 state.setCanBeginFrame(true); |
95 state.setNeedsRedraw(false); | 95 state.setNeedsRedraw(false); |
96 state.setNeedsCommit(true); | 96 state.setNeedsCommit(true); |
97 state.setUpdateMoreResourcesPending(false); | 97 state.setUpdateResourcesCompletePending(false); |
98 state.setVisible(true); | 98 state.setVisible(true); |
99 EXPECT_FALSE(state.vsyncCallbackNeeded()); | 99 EXPECT_FALSE(state.vsyncCallbackNeeded()); |
100 } | 100 } |
101 | 101 |
102 // Begin the frame, make sure needsCommit and commitState update correctly. | 102 // Begin the frame, make sure needsCommit and commitState update correctly. |
103 { | 103 { |
104 StateMachine state; | 104 StateMachine state; |
105 state.setCanBeginFrame(true); | 105 state.setCanBeginFrame(true); |
106 state.setVisible(true); | 106 state.setVisible(true); |
107 state.updateState(CCSchedulerStateMachine::ACTION_BEGIN_FRAME); | 107 state.updateState(CCSchedulerStateMachine::ACTION_BEGIN_FRAME); |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 | 197 |
198 // Fail the draw. | 198 // Fail the draw. |
199 state.updateState(CCSchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE); | 199 state.updateState(CCSchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE); |
200 EXPECT_EQ(CCSchedulerStateMachine::ACTION_NONE, state.nextAction()); | 200 EXPECT_EQ(CCSchedulerStateMachine::ACTION_NONE, state.nextAction()); |
201 state.didDrawIfPossibleCompleted(false); | 201 state.didDrawIfPossibleCompleted(false); |
202 EXPECT_TRUE(state.redrawPending()); | 202 EXPECT_TRUE(state.redrawPending()); |
203 // But the commit is ongoing. | 203 // But the commit is ongoing. |
204 EXPECT_TRUE(state.commitPending()); | 204 EXPECT_TRUE(state.commitPending()); |
205 | 205 |
206 // Finish the commit. | 206 // Finish the commit. |
207 state.beginFrameComplete(); | 207 state.beginFrameComplete(true); |
208 EXPECT_EQ(CCSchedulerStateMachine::ACTION_BEGIN_UPDATE_MORE_RESOURCES, state
.nextAction()); | 208 EXPECT_EQ(CCSchedulerStateMachine::ACTION_BEGIN_UPDATE_RESOURCES, state.next
Action()); |
209 state.updateState(CCSchedulerStateMachine::ACTION_BEGIN_UPDATE_MORE_RESOURCE
S); | 209 state.updateState(CCSchedulerStateMachine::ACTION_BEGIN_UPDATE_RESOURCES); |
210 state.beginUpdateMoreResourcesComplete(false); | 210 state.updateResourcesComplete(); |
211 EXPECT_EQ(CCSchedulerStateMachine::ACTION_COMMIT, state.nextAction()); | 211 EXPECT_EQ(CCSchedulerStateMachine::ACTION_COMMIT, state.nextAction()); |
212 state.updateState(CCSchedulerStateMachine::ACTION_COMMIT); | 212 state.updateState(CCSchedulerStateMachine::ACTION_COMMIT); |
213 EXPECT_TRUE(state.redrawPending()); | 213 EXPECT_TRUE(state.redrawPending()); |
214 | 214 |
215 // And we should be allowed to draw again. | 215 // And we should be allowed to draw again. |
216 EXPECT_EQ(CCSchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.nextAction
()); | 216 EXPECT_EQ(CCSchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.nextAction
()); |
217 } | 217 } |
218 | 218 |
219 TEST(CCSchedulerStateMachineTest, TestCommitAfterFailedAndSuccessfulDrawDoesNotA
llowDrawInSameFrame) | 219 TEST(CCSchedulerStateMachineTest, TestCommitAfterFailedAndSuccessfulDrawDoesNotA
llowDrawInSameFrame) |
220 { | 220 { |
(...skipping 28 matching lines...) Expand all Loading... |
249 EXPECT_EQ(CCSchedulerStateMachine::ACTION_DRAW_FORCED, state.nextAction()); | 249 EXPECT_EQ(CCSchedulerStateMachine::ACTION_DRAW_FORCED, state.nextAction()); |
250 | 250 |
251 // Do the forced draw. | 251 // Do the forced draw. |
252 state.updateState(CCSchedulerStateMachine::ACTION_DRAW_FORCED); | 252 state.updateState(CCSchedulerStateMachine::ACTION_DRAW_FORCED); |
253 EXPECT_EQ(CCSchedulerStateMachine::ACTION_NONE, state.nextAction()); | 253 EXPECT_EQ(CCSchedulerStateMachine::ACTION_NONE, state.nextAction()); |
254 EXPECT_FALSE(state.redrawPending()); | 254 EXPECT_FALSE(state.redrawPending()); |
255 // And the commit is still ongoing. | 255 // And the commit is still ongoing. |
256 EXPECT_TRUE(state.commitPending()); | 256 EXPECT_TRUE(state.commitPending()); |
257 | 257 |
258 // Finish the commit. | 258 // Finish the commit. |
259 state.beginFrameComplete(); | 259 state.beginFrameComplete(true); |
260 EXPECT_EQ(CCSchedulerStateMachine::ACTION_BEGIN_UPDATE_MORE_RESOURCES, state
.nextAction()); | 260 EXPECT_EQ(CCSchedulerStateMachine::ACTION_BEGIN_UPDATE_RESOURCES, state.next
Action()); |
261 state.updateState(CCSchedulerStateMachine::ACTION_BEGIN_UPDATE_MORE_RESOURCE
S); | 261 state.updateState(CCSchedulerStateMachine::ACTION_BEGIN_UPDATE_RESOURCES); |
262 state.beginUpdateMoreResourcesComplete(false); | 262 state.updateResourcesComplete(); |
263 EXPECT_EQ(CCSchedulerStateMachine::ACTION_COMMIT, state.nextAction()); | 263 EXPECT_EQ(CCSchedulerStateMachine::ACTION_COMMIT, state.nextAction()); |
264 state.updateState(CCSchedulerStateMachine::ACTION_COMMIT); | 264 state.updateState(CCSchedulerStateMachine::ACTION_COMMIT); |
265 EXPECT_TRUE(state.redrawPending()); | 265 EXPECT_TRUE(state.redrawPending()); |
266 | 266 |
267 // And we should not be allowed to draw again in the same frame.. | 267 // And we should not be allowed to draw again in the same frame.. |
268 EXPECT_EQ(CCSchedulerStateMachine::ACTION_NONE, state.nextAction()); | 268 EXPECT_EQ(CCSchedulerStateMachine::ACTION_NONE, state.nextAction()); |
269 } | 269 } |
270 | 270 |
271 TEST(CCSchedulerStateMachineTest, TestFailedDrawsWillEventuallyForceADrawAfterTh
eNextCommit) | 271 TEST(CCSchedulerStateMachineTest, TestFailedDrawsWillEventuallyForceADrawAfterTh
eNextCommit) |
272 { | 272 { |
(...skipping 19 matching lines...) Expand all Loading... |
292 // Fail the draw. | 292 // Fail the draw. |
293 state.updateState(CCSchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE); | 293 state.updateState(CCSchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE); |
294 EXPECT_EQ(CCSchedulerStateMachine::ACTION_NONE, state.nextAction()); | 294 EXPECT_EQ(CCSchedulerStateMachine::ACTION_NONE, state.nextAction()); |
295 state.didDrawIfPossibleCompleted(false); | 295 state.didDrawIfPossibleCompleted(false); |
296 EXPECT_TRUE(state.redrawPending()); | 296 EXPECT_TRUE(state.redrawPending()); |
297 // But the commit is ongoing. | 297 // But the commit is ongoing. |
298 EXPECT_TRUE(state.commitPending()); | 298 EXPECT_TRUE(state.commitPending()); |
299 | 299 |
300 // Finish the commit. Note, we should not yet be forcing a draw, but should | 300 // Finish the commit. Note, we should not yet be forcing a draw, but should |
301 // continue the commit as usual. | 301 // continue the commit as usual. |
302 state.beginFrameComplete(); | 302 state.beginFrameComplete(true); |
303 EXPECT_EQ(CCSchedulerStateMachine::ACTION_BEGIN_UPDATE_MORE_RESOURCES, state
.nextAction()); | 303 EXPECT_EQ(CCSchedulerStateMachine::ACTION_BEGIN_UPDATE_RESOURCES, state.next
Action()); |
304 state.updateState(CCSchedulerStateMachine::ACTION_BEGIN_UPDATE_MORE_RESOURCE
S); | 304 state.updateState(CCSchedulerStateMachine::ACTION_BEGIN_UPDATE_RESOURCES); |
305 state.beginUpdateMoreResourcesComplete(false); | 305 state.updateResourcesComplete(); |
306 EXPECT_EQ(CCSchedulerStateMachine::ACTION_COMMIT, state.nextAction()); | 306 EXPECT_EQ(CCSchedulerStateMachine::ACTION_COMMIT, state.nextAction()); |
307 state.updateState(CCSchedulerStateMachine::ACTION_COMMIT); | 307 state.updateState(CCSchedulerStateMachine::ACTION_COMMIT); |
308 EXPECT_TRUE(state.redrawPending()); | 308 EXPECT_TRUE(state.redrawPending()); |
309 | 309 |
310 // The redraw should be forced in this case. | 310 // The redraw should be forced in this case. |
311 EXPECT_EQ(CCSchedulerStateMachine::ACTION_DRAW_FORCED, state.nextAction()); | 311 EXPECT_EQ(CCSchedulerStateMachine::ACTION_DRAW_FORCED, state.nextAction()); |
312 } | 312 } |
313 | 313 |
314 TEST(CCSchedulerStateMachineTest, TestFailedDrawIsRetriedNextVSync) | 314 TEST(CCSchedulerStateMachineTest, TestFailedDrawIsRetriedNextVSync) |
315 { | 315 { |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
410 state.setNeedsForcedRedraw(true); | 410 state.setNeedsForcedRedraw(true); |
411 | 411 |
412 CCSchedulerStateMachine::Action expectedAction; | 412 CCSchedulerStateMachine::Action expectedAction; |
413 if (allCommitStates[i] != CCSchedulerStateMachine::COMMIT_STATE_READ
Y_TO_COMMIT) | 413 if (allCommitStates[i] != CCSchedulerStateMachine::COMMIT_STATE_READ
Y_TO_COMMIT) |
414 expectedAction = forcedDraw ? CCSchedulerStateMachine::ACTION_DR
AW_FORCED : CCSchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE; | 414 expectedAction = forcedDraw ? CCSchedulerStateMachine::ACTION_DR
AW_FORCED : CCSchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE; |
415 else | 415 else |
416 expectedAction = CCSchedulerStateMachine::ACTION_COMMIT; | 416 expectedAction = CCSchedulerStateMachine::ACTION_COMMIT; |
417 | 417 |
418 // Case 1: needsCommit=false updateMoreResourcesPending=false. | 418 // Case 1: needsCommit=false updateMoreResourcesPending=false. |
419 state.setNeedsCommit(false); | 419 state.setNeedsCommit(false); |
420 state.setUpdateMoreResourcesPending(false); | 420 state.setUpdateResourcesCompletePending(false); |
421 EXPECT_TRUE(state.vsyncCallbackNeeded()); | 421 EXPECT_TRUE(state.vsyncCallbackNeeded()); |
422 EXPECT_EQ(expectedAction, state.nextAction()); | 422 EXPECT_EQ(expectedAction, state.nextAction()); |
423 | 423 |
424 // Case 2: needsCommit=false updateMoreResourcesPending=true. | 424 // Case 2: needsCommit=false updateMoreResourcesPending=true. |
425 state.setNeedsCommit(false); | 425 state.setNeedsCommit(false); |
426 state.setUpdateMoreResourcesPending(true); | 426 state.setUpdateResourcesCompletePending(true); |
427 EXPECT_TRUE(state.vsyncCallbackNeeded()); | 427 EXPECT_TRUE(state.vsyncCallbackNeeded()); |
428 EXPECT_EQ(expectedAction, state.nextAction()); | 428 EXPECT_EQ(expectedAction, state.nextAction()); |
429 | 429 |
430 // Case 3: needsCommit=true updateMoreResourcesPending=false. | 430 // Case 3: needsCommit=true updateMoreResourcesPending=false. |
431 state.setNeedsCommit(true); | 431 state.setNeedsCommit(true); |
432 state.setUpdateMoreResourcesPending(false); | 432 state.setUpdateResourcesCompletePending(false); |
433 EXPECT_TRUE(state.vsyncCallbackNeeded()); | 433 EXPECT_TRUE(state.vsyncCallbackNeeded()); |
434 EXPECT_EQ(expectedAction, state.nextAction()); | 434 EXPECT_EQ(expectedAction, state.nextAction()); |
435 | 435 |
436 // Case 4: needsCommit=true updateMoreResourcesPending=true. | 436 // Case 4: needsCommit=true updateMoreResourcesPending=true. |
437 state.setNeedsCommit(true); | 437 state.setNeedsCommit(true); |
438 state.setUpdateMoreResourcesPending(true); | 438 state.setUpdateResourcesCompletePending(true); |
439 EXPECT_TRUE(state.vsyncCallbackNeeded()); | 439 EXPECT_TRUE(state.vsyncCallbackNeeded()); |
440 EXPECT_EQ(expectedAction, state.nextAction()); | 440 EXPECT_EQ(expectedAction, state.nextAction()); |
441 } | 441 } |
442 } | 442 } |
443 } | 443 } |
444 | 444 |
445 TEST(CCSchedulerStateMachineTest, TestNoCommitStatesRedrawWhenInvisible) | 445 TEST(CCSchedulerStateMachineTest, TestNoCommitStatesRedrawWhenInvisible) |
446 { | 446 { |
447 size_t numCommitStates = sizeof(allCommitStates) / sizeof(CCSchedulerStateMa
chine::CommitState); | 447 size_t numCommitStates = sizeof(allCommitStates) / sizeof(CCSchedulerStateMa
chine::CommitState); |
448 for (size_t i = 0; i < numCommitStates; ++i) { | 448 for (size_t i = 0; i < numCommitStates; ++i) { |
449 // There shouldn't be any drawing regardless of vsync. | 449 // There shouldn't be any drawing regardless of vsync. |
450 for (unsigned j = 0; j < 2; ++j) { | 450 for (unsigned j = 0; j < 2; ++j) { |
451 StateMachine state; | 451 StateMachine state; |
452 state.setCommitState(allCommitStates[i]); | 452 state.setCommitState(allCommitStates[i]); |
453 state.setVisible(false); | 453 state.setVisible(false); |
454 state.setNeedsRedraw(true); | 454 state.setNeedsRedraw(true); |
455 state.setNeedsForcedRedraw(false); | 455 state.setNeedsForcedRedraw(false); |
456 if (j == 1) | 456 if (j == 1) |
457 state.didEnterVSync(); | 457 state.didEnterVSync(); |
458 | 458 |
459 // Case 1: needsCommit=false updateMoreResourcesPending=false. | 459 // Case 1: needsCommit=false updateMoreResourcesPending=false. |
460 state.setNeedsCommit(false); | 460 state.setNeedsCommit(false); |
461 state.setUpdateMoreResourcesPending(false); | 461 state.setUpdateResourcesCompletePending(false); |
462 EXPECT_NE(CCSchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.ne
xtAction()); | 462 EXPECT_NE(CCSchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.ne
xtAction()); |
463 | 463 |
464 // Case 2: needsCommit=false updateMoreResourcesPending=true. | 464 // Case 2: needsCommit=false updateMoreResourcesPending=true. |
465 state.setNeedsCommit(false); | 465 state.setNeedsCommit(false); |
466 state.setUpdateMoreResourcesPending(true); | 466 state.setUpdateResourcesCompletePending(true); |
467 EXPECT_NE(CCSchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.ne
xtAction()); | 467 EXPECT_NE(CCSchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.ne
xtAction()); |
468 | 468 |
469 // Case 3: needsCommit=true updateMoreResourcesPending=false. | 469 // Case 3: needsCommit=true updateMoreResourcesPending=false. |
470 state.setNeedsCommit(true); | 470 state.setNeedsCommit(true); |
471 state.setUpdateMoreResourcesPending(false); | 471 state.setUpdateResourcesCompletePending(false); |
472 EXPECT_NE(CCSchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.ne
xtAction()); | 472 EXPECT_NE(CCSchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.ne
xtAction()); |
473 | 473 |
474 // Case 4: needsCommit=true updateMoreResourcesPending=true. | 474 // Case 4: needsCommit=true updateMoreResourcesPending=true. |
475 state.setNeedsCommit(true); | 475 state.setNeedsCommit(true); |
476 state.setUpdateMoreResourcesPending(true); | 476 state.setUpdateResourcesCompletePending(true); |
477 EXPECT_NE(CCSchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.ne
xtAction()); | 477 EXPECT_NE(CCSchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.ne
xtAction()); |
478 } | 478 } |
479 } | 479 } |
480 } | 480 } |
481 | 481 |
482 TEST(CCSchedulerStateMachineTest, TestCanRedraw_StopsDraw) | 482 TEST(CCSchedulerStateMachineTest, TestCanRedraw_StopsDraw) |
483 { | 483 { |
484 size_t numCommitStates = sizeof(allCommitStates) / sizeof(CCSchedulerStateMa
chine::CommitState); | 484 size_t numCommitStates = sizeof(allCommitStates) / sizeof(CCSchedulerStateMa
chine::CommitState); |
485 for (size_t i = 0; i < numCommitStates; ++i) { | 485 for (size_t i = 0; i < numCommitStates; ++i) { |
486 // There shouldn't be any drawing regardless of vsync. | 486 // There shouldn't be any drawing regardless of vsync. |
(...skipping 12 matching lines...) Expand all Loading... |
499 } | 499 } |
500 } | 500 } |
501 | 501 |
502 TEST(CCSchedulerStateMachineTest, TestCanRedrawWithWaitingForFirstDrawMakesProgr
ess) | 502 TEST(CCSchedulerStateMachineTest, TestCanRedrawWithWaitingForFirstDrawMakesProgr
ess) |
503 { | 503 { |
504 StateMachine state; | 504 StateMachine state; |
505 state.setCommitState(CCSchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST
_DRAW); | 505 state.setCommitState(CCSchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST
_DRAW); |
506 state.setCanBeginFrame(true); | 506 state.setCanBeginFrame(true); |
507 state.setNeedsCommit(true); | 507 state.setNeedsCommit(true); |
508 state.setNeedsRedraw(true); | 508 state.setNeedsRedraw(true); |
509 state.setUpdateMoreResourcesPending(false); | 509 state.setUpdateResourcesCompletePending(false); |
510 state.setVisible(true); | 510 state.setVisible(true); |
511 state.setCanDraw(false); | 511 state.setCanDraw(false); |
512 EXPECT_EQ(CCSchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction()); | 512 EXPECT_EQ(CCSchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction()); |
513 } | 513 } |
514 | 514 |
515 TEST(CCSchedulerStateMachineTest, TestVsyncCallbackNeededOnCanDrawAndResourceUpd
ates) | 515 TEST(CCSchedulerStateMachineTest, TestVsyncCallbackNeededOnCanDrawAndResourceUpd
ates) |
516 { | 516 { |
517 StateMachine state; | 517 StateMachine state; |
518 state.setCommitState(CCSchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST
_DRAW); | 518 state.setCommitState(CCSchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST
_DRAW); |
519 state.setCanBeginFrame(true); | 519 state.setCanBeginFrame(true); |
520 state.setNeedsCommit(true); | 520 state.setNeedsCommit(true); |
521 state.setNeedsRedraw(true); | 521 state.setNeedsRedraw(true); |
522 state.setUpdateMoreResourcesPending(false); | 522 state.setUpdateResourcesCompletePending(false); |
523 state.setVisible(true); | 523 state.setVisible(true); |
524 state.setCanDraw(false); | 524 state.setCanDraw(false); |
525 EXPECT_FALSE(state.vsyncCallbackNeeded()); | 525 EXPECT_FALSE(state.vsyncCallbackNeeded()); |
526 | 526 |
527 state.setUpdateMoreResourcesPending(true); | 527 state.setUpdateResourcesCompletePending(true); |
528 EXPECT_TRUE(state.vsyncCallbackNeeded()); | 528 EXPECT_TRUE(state.vsyncCallbackNeeded()); |
529 | 529 |
530 state.setUpdateMoreResourcesPending(false); | 530 state.setUpdateResourcesCompletePending(false); |
531 EXPECT_FALSE(state.vsyncCallbackNeeded()); | 531 EXPECT_FALSE(state.vsyncCallbackNeeded()); |
532 | 532 |
533 state.setCanDraw(true); | 533 state.setCanDraw(true); |
534 EXPECT_TRUE(state.vsyncCallbackNeeded()); | 534 EXPECT_TRUE(state.vsyncCallbackNeeded()); |
535 } | 535 } |
536 | 536 |
537 TEST(CCSchedulerStateMachineTest, TestUpdates_NoRedraw_OneRoundOfUpdates) | 537 TEST(CCSchedulerStateMachineTest, TestUpdates_NoRedraw_OneRoundOfUpdates) |
538 { | 538 { |
539 StateMachine state; | 539 StateMachine state; |
540 state.setCommitState(CCSchedulerStateMachine::COMMIT_STATE_UPDATING_RESOURCE
S); | 540 state.setCommitState(CCSchedulerStateMachine::COMMIT_STATE_UPDATING_RESOURCE
S); |
541 state.setNeedsRedraw(false); | 541 state.setNeedsRedraw(false); |
542 state.setUpdateMoreResourcesPending(false); | 542 state.setUpdateResourcesCompletePending(false); |
543 state.setVisible(true); | 543 state.setVisible(true); |
544 state.setCanDraw(true); | 544 state.setCanDraw(true); |
545 | 545 |
546 // Verify we begin update, both for vsync and not vsync. | 546 // Verify we begin update, both for vsync and not vsync. |
547 EXPECT_EQ(CCSchedulerStateMachine::ACTION_BEGIN_UPDATE_MORE_RESOURCES, state
.nextAction()); | 547 EXPECT_EQ(CCSchedulerStateMachine::ACTION_BEGIN_UPDATE_RESOURCES, state.next
Action()); |
548 state.didEnterVSync(); | 548 state.didEnterVSync(); |
549 EXPECT_EQ(CCSchedulerStateMachine::ACTION_BEGIN_UPDATE_MORE_RESOURCES, state
.nextAction()); | 549 EXPECT_EQ(CCSchedulerStateMachine::ACTION_BEGIN_UPDATE_RESOURCES, state.next
Action()); |
550 | 550 |
551 // Begin an update. | 551 // Begin an update. |
552 state.updateState(CCSchedulerStateMachine::ACTION_BEGIN_UPDATE_MORE_RESOURCE
S); | 552 state.updateState(CCSchedulerStateMachine::ACTION_BEGIN_UPDATE_RESOURCES); |
553 | 553 |
554 // Verify we don't do anything, both for vsync and not vsync. | 554 // Verify we don't do anything, both for vsync and not vsync. |
555 state.didLeaveVSync(); | 555 state.didLeaveVSync(); |
556 EXPECT_EQ(CCSchedulerStateMachine::ACTION_NONE, state.nextAction()); | 556 EXPECT_EQ(CCSchedulerStateMachine::ACTION_NONE, state.nextAction()); |
557 state.didEnterVSync(); | 557 state.didEnterVSync(); |
558 EXPECT_EQ(CCSchedulerStateMachine::ACTION_NONE, state.nextAction()); | 558 EXPECT_EQ(CCSchedulerStateMachine::ACTION_NONE, state.nextAction()); |
559 | 559 |
560 // End update with no more updates pending. | 560 // End update with no more updates pending. |
561 state.beginUpdateMoreResourcesComplete(false); | 561 state.updateResourcesComplete(); |
562 state.didLeaveVSync(); | 562 state.didLeaveVSync(); |
563 EXPECT_EQ(CCSchedulerStateMachine::ACTION_COMMIT, state.nextAction()); | 563 EXPECT_EQ(CCSchedulerStateMachine::ACTION_COMMIT, state.nextAction()); |
564 } | 564 } |
565 | 565 |
566 TEST(CCSchedulerStateMachineTest, TestUpdates_NoRedraw_TwoRoundsOfUpdates) | |
567 { | |
568 StateMachine state; | |
569 state.setCommitState(CCSchedulerStateMachine::COMMIT_STATE_UPDATING_RESOURCE
S); | |
570 state.setNeedsRedraw(false); | |
571 state.setUpdateMoreResourcesPending(false); | |
572 state.setVisible(true); | |
573 state.setCanDraw(true); | |
574 | |
575 // Verify the update begins, both for vsync and not vsync. | |
576 state.didEnterVSync(); | |
577 EXPECT_EQ(CCSchedulerStateMachine::ACTION_BEGIN_UPDATE_MORE_RESOURCES, state
.nextAction()); | |
578 state.didLeaveVSync(); | |
579 EXPECT_EQ(CCSchedulerStateMachine::ACTION_BEGIN_UPDATE_MORE_RESOURCES, state
.nextAction()); | |
580 | |
581 // Begin an update. | |
582 state.updateState(CCSchedulerStateMachine::ACTION_BEGIN_UPDATE_MORE_RESOURCE
S); | |
583 | |
584 // Verify we do nothing, both for vsync and not vsync. | |
585 EXPECT_EQ(CCSchedulerStateMachine::ACTION_NONE, state.nextAction()); | |
586 state.didEnterVSync(); | |
587 EXPECT_EQ(CCSchedulerStateMachine::ACTION_NONE, state.nextAction()); | |
588 | |
589 // Ack the update with more pending. | |
590 state.beginUpdateMoreResourcesComplete(true); | |
591 | |
592 // Verify we update more, both for vsync and not vsync. | |
593 state.didLeaveVSync(); | |
594 EXPECT_EQ(CCSchedulerStateMachine::ACTION_BEGIN_UPDATE_MORE_RESOURCES, state
.nextAction()); | |
595 state.didEnterVSync(); | |
596 EXPECT_EQ(CCSchedulerStateMachine::ACTION_BEGIN_UPDATE_MORE_RESOURCES, state
.nextAction()); | |
597 | |
598 // Begin another update, while inside vsync. And, it updating. | |
599 state.updateState(CCSchedulerStateMachine::ACTION_BEGIN_UPDATE_MORE_RESOURCE
S); | |
600 state.beginUpdateMoreResourcesComplete(false); | |
601 | |
602 // Make sure we commit, independent of vsync. | |
603 state.didLeaveVSync(); | |
604 EXPECT_EQ(CCSchedulerStateMachine::ACTION_COMMIT, state.nextAction()); | |
605 state.didEnterVSync(); | |
606 EXPECT_EQ(CCSchedulerStateMachine::ACTION_COMMIT, state.nextAction()); | |
607 } | |
608 | |
609 | |
610 TEST(CCSchedulerStateMachineTest, TestVSyncNeededWhenUpdatesPendingButInvisible) | 566 TEST(CCSchedulerStateMachineTest, TestVSyncNeededWhenUpdatesPendingButInvisible) |
611 { | 567 { |
612 StateMachine state; | 568 StateMachine state; |
613 state.setCanDraw(true); | 569 state.setCanDraw(true); |
614 state.setCommitState(CCSchedulerStateMachine::COMMIT_STATE_UPDATING_RESOURCE
S); | 570 state.setCommitState(CCSchedulerStateMachine::COMMIT_STATE_UPDATING_RESOURCE
S); |
615 state.setNeedsRedraw(false); | 571 state.setNeedsRedraw(false); |
616 state.setVisible(false); | 572 state.setVisible(false); |
617 state.setUpdateMoreResourcesPending(true); | 573 state.setUpdateResourcesCompletePending(true); |
618 EXPECT_TRUE(state.vsyncCallbackNeeded()); | 574 EXPECT_TRUE(state.vsyncCallbackNeeded()); |
619 | 575 |
620 state.setUpdateMoreResourcesPending(false); | 576 state.setUpdateResourcesCompletePending(false); |
621 EXPECT_TRUE(state.vsyncCallbackNeeded()); | 577 EXPECT_TRUE(state.vsyncCallbackNeeded()); |
622 } | 578 } |
623 | 579 |
624 TEST(CCSchedulerStateMachineTest, TestUpdates_WithRedraw_OneRoundOfUpdates) | 580 TEST(CCSchedulerStateMachineTest, TestUpdates_WithRedraw_OneRoundOfUpdates) |
625 { | 581 { |
626 StateMachine state; | 582 StateMachine state; |
627 state.setCommitState(CCSchedulerStateMachine::COMMIT_STATE_UPDATING_RESOURCE
S); | 583 state.setCommitState(CCSchedulerStateMachine::COMMIT_STATE_UPDATING_RESOURCE
S); |
628 state.setNeedsRedraw(true); | 584 state.setNeedsRedraw(true); |
629 state.setUpdateMoreResourcesPending(false); | 585 state.setUpdateResourcesCompletePending(false); |
630 state.setVisible(true); | 586 state.setVisible(true); |
631 state.setCanDraw(true); | 587 state.setCanDraw(true); |
632 EXPECT_EQ(CCSchedulerStateMachine::ACTION_BEGIN_UPDATE_MORE_RESOURCES, state
.nextAction()); | 588 EXPECT_EQ(CCSchedulerStateMachine::ACTION_BEGIN_UPDATE_RESOURCES, state.next
Action()); |
633 | 589 |
634 // Begin an update. | 590 // Begin an update. |
635 state.updateState(CCSchedulerStateMachine::ACTION_BEGIN_UPDATE_MORE_RESOURCE
S); | 591 state.updateState(CCSchedulerStateMachine::ACTION_BEGIN_UPDATE_RESOURCES); |
636 | 592 |
637 // Ensure we draw on the next vsync even though an update is in-progress. | 593 // Ensure we draw on the next vsync even though an update is in-progress. |
638 state.didEnterVSync(); | 594 state.didEnterVSync(); |
639 EXPECT_EQ(CCSchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.nextAction
()); | 595 EXPECT_EQ(CCSchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.nextAction
()); |
640 state.updateState(CCSchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE); | 596 state.updateState(CCSchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE); |
641 state.didDrawIfPossibleCompleted(true); | 597 state.didDrawIfPossibleCompleted(true); |
642 | 598 |
643 // Ensure that we once we have drawn, we dont do anything else. | 599 // Ensure that we once we have drawn, we dont do anything else. |
644 EXPECT_EQ(CCSchedulerStateMachine::ACTION_NONE, state.nextAction()); | 600 EXPECT_EQ(CCSchedulerStateMachine::ACTION_NONE, state.nextAction()); |
645 | 601 |
646 // Leave the vsync before we finish the update. | 602 // Leave the vsync before we finish the update. |
647 state.didLeaveVSync(); | 603 state.didLeaveVSync(); |
648 | 604 state.updateResourcesComplete(); |
649 // Finish update but leave more resources pending. | |
650 state.beginUpdateMoreResourcesComplete(true); | |
651 | |
652 // Verify that regardless of vsync, we update some more. | |
653 state.didLeaveVSync(); | |
654 EXPECT_EQ(CCSchedulerStateMachine::ACTION_BEGIN_UPDATE_MORE_RESOURCES, state
.nextAction()); | |
655 state.didEnterVSync(); | |
656 EXPECT_EQ(CCSchedulerStateMachine::ACTION_BEGIN_UPDATE_MORE_RESOURCES, state
.nextAction()); | |
657 state.didEnterVSync(); | |
658 EXPECT_EQ(CCSchedulerStateMachine::ACTION_BEGIN_UPDATE_MORE_RESOURCES, state
.nextAction()); | |
659 | |
660 // Begin another update. Finish it immediately. Inside the vsync. | |
661 state.didEnterVSync(); | |
662 state.updateState(CCSchedulerStateMachine::ACTION_BEGIN_UPDATE_MORE_RESOURCE
S); | |
663 state.didLeaveVSync(); | |
664 state.beginUpdateMoreResourcesComplete(false); | |
665 | 605 |
666 // Verify we commit regardless of vsync state | 606 // Verify we commit regardless of vsync state |
667 state.didLeaveVSync(); | 607 state.didLeaveVSync(); |
668 EXPECT_EQ(CCSchedulerStateMachine::ACTION_COMMIT, state.nextAction()); | 608 EXPECT_EQ(CCSchedulerStateMachine::ACTION_COMMIT, state.nextAction()); |
669 state.didEnterVSync(); | 609 state.didEnterVSync(); |
670 EXPECT_EQ(CCSchedulerStateMachine::ACTION_COMMIT, state.nextAction()); | 610 EXPECT_EQ(CCSchedulerStateMachine::ACTION_COMMIT, state.nextAction()); |
671 } | 611 } |
672 | 612 |
673 TEST(CCSchedulerStateMachineTest, TestSetNeedsCommitIsNotLost) | 613 TEST(CCSchedulerStateMachineTest, TestSetNeedsCommitIsNotLost) |
674 { | 614 { |
675 StateMachine state; | 615 StateMachine state; |
676 state.setCanBeginFrame(true); | 616 state.setCanBeginFrame(true); |
677 state.setNeedsCommit(true); | 617 state.setNeedsCommit(true); |
678 state.setVisible(true); | 618 state.setVisible(true); |
679 state.setCanDraw(true); | 619 state.setCanDraw(true); |
680 | 620 |
681 // Begin the frame. | 621 // Begin the frame. |
682 EXPECT_EQ(CCSchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction()); | 622 EXPECT_EQ(CCSchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction()); |
683 state.updateState(state.nextAction()); | 623 state.updateState(state.nextAction()); |
684 EXPECT_EQ(CCSchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, state.com
mitState()); | 624 EXPECT_EQ(CCSchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, state.com
mitState()); |
685 | 625 |
686 // Now, while the frame is in progress, set another commit. | 626 // Now, while the frame is in progress, set another commit. |
687 state.setNeedsCommit(true); | 627 state.setNeedsCommit(true); |
688 EXPECT_TRUE(state.needsCommit()); | 628 EXPECT_TRUE(state.needsCommit()); |
689 | 629 |
690 // Let the frame finish. | 630 // Let the frame finish. |
691 state.beginFrameComplete(); | 631 state.beginFrameComplete(true); |
692 EXPECT_EQ(CCSchedulerStateMachine::COMMIT_STATE_UPDATING_RESOURCES, state.co
mmitState()); | 632 EXPECT_EQ(CCSchedulerStateMachine::COMMIT_STATE_UPDATING_RESOURCES, state.co
mmitState()); |
693 EXPECT_EQ(CCSchedulerStateMachine::ACTION_BEGIN_UPDATE_MORE_RESOURCES, state
.nextAction()); | 633 EXPECT_EQ(CCSchedulerStateMachine::ACTION_BEGIN_UPDATE_RESOURCES, state.next
Action()); |
694 state.updateState(CCSchedulerStateMachine::ACTION_BEGIN_UPDATE_MORE_RESOURCE
S); | 634 state.updateState(CCSchedulerStateMachine::ACTION_BEGIN_UPDATE_RESOURCES); |
695 EXPECT_EQ(CCSchedulerStateMachine::ACTION_NONE, state.nextAction()); | 635 EXPECT_EQ(CCSchedulerStateMachine::ACTION_NONE, state.nextAction()); |
696 state.beginUpdateMoreResourcesComplete(false); | 636 state.updateResourcesComplete(); |
697 EXPECT_EQ(CCSchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT, state.commi
tState()); | 637 EXPECT_EQ(CCSchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT, state.commi
tState()); |
698 | 638 |
699 // Expect to commit regardless of vsync state. | 639 // Expect to commit regardless of vsync state. |
700 state.didLeaveVSync(); | 640 state.didLeaveVSync(); |
701 EXPECT_EQ(CCSchedulerStateMachine::ACTION_COMMIT, state.nextAction()); | 641 EXPECT_EQ(CCSchedulerStateMachine::ACTION_COMMIT, state.nextAction()); |
702 state.didEnterVSync(); | 642 state.didEnterVSync(); |
703 EXPECT_EQ(CCSchedulerStateMachine::ACTION_COMMIT, state.nextAction()); | 643 EXPECT_EQ(CCSchedulerStateMachine::ACTION_COMMIT, state.nextAction()); |
704 | 644 |
705 // Commit and make sure we draw on next vsync | 645 // Commit and make sure we draw on next vsync |
706 state.updateState(CCSchedulerStateMachine::ACTION_COMMIT); | 646 state.updateState(CCSchedulerStateMachine::ACTION_COMMIT); |
(...skipping 18 matching lines...) Expand all Loading... |
725 state.setNeedsCommit(true); | 665 state.setNeedsCommit(true); |
726 EXPECT_EQ(CCSchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction()); | 666 EXPECT_EQ(CCSchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction()); |
727 | 667 |
728 // Begin the frame. | 668 // Begin the frame. |
729 state.updateState(CCSchedulerStateMachine::ACTION_BEGIN_FRAME); | 669 state.updateState(CCSchedulerStateMachine::ACTION_BEGIN_FRAME); |
730 EXPECT_EQ(CCSchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, state.com
mitState()); | 670 EXPECT_EQ(CCSchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, state.com
mitState()); |
731 EXPECT_FALSE(state.needsCommit()); | 671 EXPECT_FALSE(state.needsCommit()); |
732 EXPECT_EQ(CCSchedulerStateMachine::ACTION_NONE, state.nextAction()); | 672 EXPECT_EQ(CCSchedulerStateMachine::ACTION_NONE, state.nextAction()); |
733 | 673 |
734 // Tell the scheduler the frame finished. | 674 // Tell the scheduler the frame finished. |
735 state.beginFrameComplete(); | 675 state.beginFrameComplete(true); |
736 EXPECT_EQ(CCSchedulerStateMachine::COMMIT_STATE_UPDATING_RESOURCES, state.co
mmitState()); | 676 EXPECT_EQ(CCSchedulerStateMachine::COMMIT_STATE_UPDATING_RESOURCES, state.co
mmitState()); |
737 EXPECT_EQ(CCSchedulerStateMachine::ACTION_BEGIN_UPDATE_MORE_RESOURCES, state
.nextAction()); | 677 EXPECT_EQ(CCSchedulerStateMachine::ACTION_BEGIN_UPDATE_RESOURCES, state.next
Action()); |
738 | 678 |
739 // Tell the scheduler the update began and finished | 679 // Tell the scheduler the update began and finished |
740 state.updateState(CCSchedulerStateMachine::ACTION_BEGIN_UPDATE_MORE_RESOURCE
S); | 680 state.updateState(CCSchedulerStateMachine::ACTION_BEGIN_UPDATE_RESOURCES); |
741 state.beginUpdateMoreResourcesComplete(false); | 681 state.updateResourcesComplete(); |
742 EXPECT_EQ(CCSchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT, state.commi
tState()); | 682 EXPECT_EQ(CCSchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT, state.commi
tState()); |
743 EXPECT_EQ(CCSchedulerStateMachine::ACTION_COMMIT, state.nextAction()); | 683 EXPECT_EQ(CCSchedulerStateMachine::ACTION_COMMIT, state.nextAction()); |
744 | 684 |
745 // Commit. | 685 // Commit. |
746 state.updateState(CCSchedulerStateMachine::ACTION_COMMIT); | 686 state.updateState(CCSchedulerStateMachine::ACTION_COMMIT); |
747 EXPECT_EQ(CCSchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW, stat
e.commitState()); | 687 EXPECT_EQ(CCSchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW, stat
e.commitState()); |
748 EXPECT_TRUE(state.needsRedraw()); | 688 EXPECT_TRUE(state.needsRedraw()); |
749 | 689 |
750 // Expect to do nothing until vsync. | 690 // Expect to do nothing until vsync. |
751 EXPECT_EQ(CCSchedulerStateMachine::ACTION_NONE, state.nextAction()); | 691 EXPECT_EQ(CCSchedulerStateMachine::ACTION_NONE, state.nextAction()); |
(...skipping 26 matching lines...) Expand all Loading... |
778 state.updateState(CCSchedulerStateMachine::ACTION_BEGIN_FRAME); | 718 state.updateState(CCSchedulerStateMachine::ACTION_BEGIN_FRAME); |
779 EXPECT_EQ(CCSchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, state.com
mitState()); | 719 EXPECT_EQ(CCSchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, state.com
mitState()); |
780 EXPECT_FALSE(state.needsCommit()); | 720 EXPECT_FALSE(state.needsCommit()); |
781 EXPECT_EQ(CCSchedulerStateMachine::ACTION_NONE, state.nextAction()); | 721 EXPECT_EQ(CCSchedulerStateMachine::ACTION_NONE, state.nextAction()); |
782 | 722 |
783 // Request another commit while the commit is in flight. | 723 // Request another commit while the commit is in flight. |
784 state.setNeedsCommit(true); | 724 state.setNeedsCommit(true); |
785 EXPECT_EQ(CCSchedulerStateMachine::ACTION_NONE, state.nextAction()); | 725 EXPECT_EQ(CCSchedulerStateMachine::ACTION_NONE, state.nextAction()); |
786 | 726 |
787 // Tell the scheduler the frame finished. | 727 // Tell the scheduler the frame finished. |
788 state.beginFrameComplete(); | 728 state.beginFrameComplete(true); |
789 EXPECT_EQ(CCSchedulerStateMachine::COMMIT_STATE_UPDATING_RESOURCES, state.co
mmitState()); | 729 EXPECT_EQ(CCSchedulerStateMachine::COMMIT_STATE_UPDATING_RESOURCES, state.co
mmitState()); |
790 EXPECT_EQ(CCSchedulerStateMachine::ACTION_BEGIN_UPDATE_MORE_RESOURCES, state
.nextAction()); | 730 EXPECT_EQ(CCSchedulerStateMachine::ACTION_BEGIN_UPDATE_RESOURCES, state.next
Action()); |
791 | 731 |
792 // Tell the scheduler the update began and finished | 732 // Tell the scheduler the update began and finished |
793 state.updateState(CCSchedulerStateMachine::ACTION_BEGIN_UPDATE_MORE_RESOURCE
S); | 733 state.updateState(CCSchedulerStateMachine::ACTION_BEGIN_UPDATE_RESOURCES); |
794 state.beginUpdateMoreResourcesComplete(false); | 734 state.updateResourcesComplete(); |
795 EXPECT_EQ(CCSchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT, state.commi
tState()); | 735 EXPECT_EQ(CCSchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT, state.commi
tState()); |
796 EXPECT_EQ(CCSchedulerStateMachine::ACTION_COMMIT, state.nextAction()); | 736 EXPECT_EQ(CCSchedulerStateMachine::ACTION_COMMIT, state.nextAction()); |
797 | 737 |
798 // Commit. | 738 // Commit. |
799 state.updateState(CCSchedulerStateMachine::ACTION_COMMIT); | 739 state.updateState(CCSchedulerStateMachine::ACTION_COMMIT); |
800 EXPECT_EQ(CCSchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW, stat
e.commitState()); | 740 EXPECT_EQ(CCSchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW, stat
e.commitState()); |
801 EXPECT_TRUE(state.needsRedraw()); | 741 EXPECT_TRUE(state.needsRedraw()); |
802 | 742 |
803 // Expect to do nothing until vsync. | 743 // Expect to do nothing until vsync. |
804 EXPECT_EQ(CCSchedulerStateMachine::ACTION_NONE, state.nextAction()); | 744 EXPECT_EQ(CCSchedulerStateMachine::ACTION_NONE, state.nextAction()); |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
942 state.didLeaveVSync(); | 882 state.didLeaveVSync(); |
943 | 883 |
944 // Cause a lost context while the begin frame is in flight. | 884 // Cause a lost context while the begin frame is in flight. |
945 state.didLoseContext(); | 885 state.didLoseContext(); |
946 | 886 |
947 // Ask for another draw. Expect nothing happens. | 887 // Ask for another draw. Expect nothing happens. |
948 state.setNeedsRedraw(true); | 888 state.setNeedsRedraw(true); |
949 EXPECT_EQ(CCSchedulerStateMachine::ACTION_NONE, state.nextAction()); | 889 EXPECT_EQ(CCSchedulerStateMachine::ACTION_NONE, state.nextAction()); |
950 | 890 |
951 // Finish the frame, update resources, and commit. | 891 // Finish the frame, update resources, and commit. |
952 state.beginFrameComplete(); | 892 state.beginFrameComplete(true); |
953 EXPECT_EQ(CCSchedulerStateMachine::ACTION_BEGIN_UPDATE_MORE_RESOURCES, state
.nextAction()); | 893 EXPECT_EQ(CCSchedulerStateMachine::ACTION_BEGIN_UPDATE_RESOURCES, state.next
Action()); |
954 state.updateState(state.nextAction()); | 894 state.updateState(state.nextAction()); |
955 EXPECT_EQ(CCSchedulerStateMachine::ACTION_NONE, state.nextAction()); | 895 EXPECT_EQ(CCSchedulerStateMachine::ACTION_NONE, state.nextAction()); |
956 state.beginUpdateMoreResourcesComplete(false); | 896 state.updateResourcesComplete(); |
957 EXPECT_EQ(CCSchedulerStateMachine::ACTION_COMMIT, state.nextAction()); | 897 EXPECT_EQ(CCSchedulerStateMachine::ACTION_COMMIT, state.nextAction()); |
958 state.updateState(state.nextAction()); | 898 state.updateState(state.nextAction()); |
959 | 899 |
960 EXPECT_EQ(CCSchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW, stat
e.commitState()); | 900 EXPECT_EQ(CCSchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW, stat
e.commitState()); |
961 | 901 |
962 EXPECT_EQ(CCSchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.nextAction
()); | 902 EXPECT_EQ(CCSchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.nextAction
()); |
963 state.updateState(state.nextAction()); | 903 state.updateState(state.nextAction()); |
964 | 904 |
965 // Expect to be told to begin context recreation, independent of vsync state | 905 // Expect to be told to begin context recreation, independent of vsync state |
966 state.didEnterVSync(); | 906 state.didEnterVSync(); |
(...skipping 23 matching lines...) Expand all Loading... |
990 | 930 |
991 // Cause a lost context while the begin frame is in flight. | 931 // Cause a lost context while the begin frame is in flight. |
992 state.didLoseContext(); | 932 state.didLoseContext(); |
993 | 933 |
994 // Ask for another draw and also set needs commit. Expect nothing happens. | 934 // Ask for another draw and also set needs commit. Expect nothing happens. |
995 state.setNeedsRedraw(true); | 935 state.setNeedsRedraw(true); |
996 state.setNeedsCommit(true); | 936 state.setNeedsCommit(true); |
997 EXPECT_EQ(CCSchedulerStateMachine::ACTION_NONE, state.nextAction()); | 937 EXPECT_EQ(CCSchedulerStateMachine::ACTION_NONE, state.nextAction()); |
998 | 938 |
999 // Finish the frame, update resources, and commit. | 939 // Finish the frame, update resources, and commit. |
1000 state.beginFrameComplete(); | 940 state.beginFrameComplete(true); |
1001 EXPECT_EQ(CCSchedulerStateMachine::ACTION_BEGIN_UPDATE_MORE_RESOURCES, state
.nextAction()); | 941 EXPECT_EQ(CCSchedulerStateMachine::ACTION_BEGIN_UPDATE_RESOURCES, state.next
Action()); |
1002 state.updateState(state.nextAction()); | 942 state.updateState(state.nextAction()); |
1003 EXPECT_EQ(CCSchedulerStateMachine::ACTION_NONE, state.nextAction()); | 943 EXPECT_EQ(CCSchedulerStateMachine::ACTION_NONE, state.nextAction()); |
1004 state.beginUpdateMoreResourcesComplete(false); | 944 state.updateResourcesComplete(); |
1005 EXPECT_EQ(CCSchedulerStateMachine::ACTION_COMMIT, state.nextAction()); | 945 EXPECT_EQ(CCSchedulerStateMachine::ACTION_COMMIT, state.nextAction()); |
1006 state.updateState(state.nextAction()); | 946 state.updateState(state.nextAction()); |
1007 | 947 |
1008 EXPECT_EQ(CCSchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW, stat
e.commitState()); | 948 EXPECT_EQ(CCSchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW, stat
e.commitState()); |
1009 | 949 |
1010 EXPECT_EQ(CCSchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.nextAction
()); | 950 EXPECT_EQ(CCSchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.nextAction
()); |
1011 state.updateState(state.nextAction()); | 951 state.updateState(state.nextAction()); |
1012 | 952 |
1013 // Expect to be told to begin context recreation, independent of vsync state | 953 // Expect to be told to begin context recreation, independent of vsync state |
1014 state.didEnterVSync(); | 954 state.didEnterVSync(); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1069 | 1009 |
1070 TEST(CCSchedulerStateMachineTest, TestBeginFrameWhenCommitInProgress) | 1010 TEST(CCSchedulerStateMachineTest, TestBeginFrameWhenCommitInProgress) |
1071 { | 1011 { |
1072 StateMachine state; | 1012 StateMachine state; |
1073 state.setCanBeginFrame(true); | 1013 state.setCanBeginFrame(true); |
1074 state.setVisible(false); | 1014 state.setVisible(false); |
1075 state.setCommitState(CCSchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS
); | 1015 state.setCommitState(CCSchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS
); |
1076 state.setNeedsCommit(true); | 1016 state.setNeedsCommit(true); |
1077 state.setNeedsForcedCommit(true); | 1017 state.setNeedsForcedCommit(true); |
1078 | 1018 |
1079 state.beginFrameComplete(); | 1019 state.beginFrameComplete(true); |
1080 EXPECT_EQ(CCSchedulerStateMachine::ACTION_BEGIN_UPDATE_MORE_RESOURCES, state
.nextAction()); | 1020 EXPECT_EQ(CCSchedulerStateMachine::ACTION_BEGIN_UPDATE_RESOURCES, state.next
Action()); |
1081 state.updateState(state.nextAction()); | 1021 state.updateState(state.nextAction()); |
1082 EXPECT_EQ(CCSchedulerStateMachine::ACTION_NONE, state.nextAction()); | 1022 EXPECT_EQ(CCSchedulerStateMachine::ACTION_NONE, state.nextAction()); |
1083 state.beginUpdateMoreResourcesComplete(false); | 1023 state.updateResourcesComplete(); |
1084 EXPECT_EQ(CCSchedulerStateMachine::ACTION_COMMIT, state.nextAction()); | 1024 EXPECT_EQ(CCSchedulerStateMachine::ACTION_COMMIT, state.nextAction()); |
1085 state.updateState(state.nextAction()); | 1025 state.updateState(state.nextAction()); |
1086 | 1026 |
1087 EXPECT_EQ(CCSchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW, stat
e.commitState()); | 1027 EXPECT_EQ(CCSchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW, stat
e.commitState()); |
1088 | 1028 |
1089 EXPECT_EQ(CCSchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction()); | 1029 EXPECT_EQ(CCSchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction()); |
1090 } | 1030 } |
1091 | 1031 |
1092 TEST(CCSchedulerStateMachineTest, TestBeginFrameWhenContextLost) | 1032 TEST(CCSchedulerStateMachineTest, TestBeginFrameWhenContextLost) |
1093 { | 1033 { |
1094 StateMachine state; | 1034 StateMachine state; |
1095 state.setCanBeginFrame(true); | 1035 state.setCanBeginFrame(true); |
1096 state.setVisible(true); | 1036 state.setVisible(true); |
1097 state.setCanDraw(true); | 1037 state.setCanDraw(true); |
1098 state.setNeedsCommit(true); | 1038 state.setNeedsCommit(true); |
1099 state.setNeedsForcedCommit(true); | 1039 state.setNeedsForcedCommit(true); |
1100 state.didLoseContext(); | 1040 state.didLoseContext(); |
1101 EXPECT_EQ(CCSchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction()); | 1041 EXPECT_EQ(CCSchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction()); |
1102 } | 1042 } |
1103 | 1043 |
1104 } | 1044 } |
OLD | NEW |