| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2011 Google Inc. All rights reserved. | 2 * Copyright (C) 2011 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 void setUpdateMoreResourcesPending(bool b) { m_updateMoreResourcesPending =
b; } | 68 void setUpdateMoreResourcesPending(bool b) { m_updateMoreResourcesPending =
b; } |
| 69 bool updateMoreResourcesPending() const { return m_updateMoreResourcesPendin
g; } | 69 bool updateMoreResourcesPending() const { return m_updateMoreResourcesPendin
g; } |
| 70 }; | 70 }; |
| 71 | 71 |
| 72 TEST(CCSchedulerStateMachineTest, TestNextActionBeginsFrameIfNeeded) | 72 TEST(CCSchedulerStateMachineTest, TestNextActionBeginsFrameIfNeeded) |
| 73 { | 73 { |
| 74 // If no commit needed, do nothing | 74 // If no commit needed, do nothing |
| 75 { | 75 { |
| 76 StateMachine state; | 76 StateMachine state; |
| 77 state.setCommitState(CCSchedulerStateMachine::COMMIT_STATE_IDLE); | 77 state.setCommitState(CCSchedulerStateMachine::COMMIT_STATE_IDLE); |
| 78 state.setCanBeginFrame(true); |
| 78 state.setNeedsRedraw(false); | 79 state.setNeedsRedraw(false); |
| 79 state.setNeedsCommit(false); | 80 state.setNeedsCommit(false); |
| 80 state.setUpdateMoreResourcesPending(false); | 81 state.setUpdateMoreResourcesPending(false); |
| 81 state.setVisible(true); | 82 state.setVisible(true); |
| 82 | 83 |
| 83 EXPECT_FALSE(state.vsyncCallbackNeeded()); | 84 EXPECT_FALSE(state.vsyncCallbackNeeded()); |
| 84 | 85 |
| 85 state.didLeaveVSync(); | 86 state.didLeaveVSync(); |
| 86 EXPECT_EQ(CCSchedulerStateMachine::ACTION_NONE, state.nextAction()); | 87 EXPECT_EQ(CCSchedulerStateMachine::ACTION_NONE, state.nextAction()); |
| 87 EXPECT_FALSE(state.vsyncCallbackNeeded()); | 88 EXPECT_FALSE(state.vsyncCallbackNeeded()); |
| 88 state.didEnterVSync(); | 89 state.didEnterVSync(); |
| 89 EXPECT_EQ(CCSchedulerStateMachine::ACTION_NONE, state.nextAction()); | 90 EXPECT_EQ(CCSchedulerStateMachine::ACTION_NONE, state.nextAction()); |
| 90 } | 91 } |
| 91 | 92 |
| 93 // If commit requested but canBeginFrame is still false, do nothing. |
| 94 { |
| 95 StateMachine state; |
| 96 state.setCommitState(CCSchedulerStateMachine::COMMIT_STATE_IDLE); |
| 97 state.setNeedsRedraw(false); |
| 98 state.setNeedsCommit(false); |
| 99 state.setUpdateMoreResourcesPending(false); |
| 100 state.setVisible(true); |
| 101 |
| 102 EXPECT_FALSE(state.vsyncCallbackNeeded()); |
| 103 |
| 104 state.didLeaveVSync(); |
| 105 EXPECT_EQ(CCSchedulerStateMachine::ACTION_NONE, state.nextAction()); |
| 106 EXPECT_FALSE(state.vsyncCallbackNeeded()); |
| 107 state.didEnterVSync(); |
| 108 EXPECT_EQ(CCSchedulerStateMachine::ACTION_NONE, state.nextAction()); |
| 109 } |
| 110 |
| 111 |
| 92 // If commit requested, begin a frame | 112 // If commit requested, begin a frame |
| 93 { | 113 { |
| 94 StateMachine state; | 114 StateMachine state; |
| 95 state.setCommitState(CCSchedulerStateMachine::COMMIT_STATE_IDLE); | 115 state.setCommitState(CCSchedulerStateMachine::COMMIT_STATE_IDLE); |
| 116 state.setCanBeginFrame(true); |
| 96 state.setNeedsRedraw(false); | 117 state.setNeedsRedraw(false); |
| 97 state.setNeedsCommit(true); | 118 state.setNeedsCommit(true); |
| 98 state.setUpdateMoreResourcesPending(false); | 119 state.setUpdateMoreResourcesPending(false); |
| 99 state.setVisible(true); | 120 state.setVisible(true); |
| 100 EXPECT_FALSE(state.vsyncCallbackNeeded()); | 121 EXPECT_FALSE(state.vsyncCallbackNeeded()); |
| 101 } | 122 } |
| 102 | 123 |
| 103 // Begin the frame, make sure needsCommit and commitState update correctly. | 124 // Begin the frame, make sure needsCommit and commitState update correctly. |
| 104 { | 125 { |
| 105 StateMachine state; | 126 StateMachine state; |
| 127 state.setCanBeginFrame(true); |
| 106 state.setVisible(true); | 128 state.setVisible(true); |
| 107 state.updateState(CCSchedulerStateMachine::ACTION_BEGIN_FRAME); | 129 state.updateState(CCSchedulerStateMachine::ACTION_BEGIN_FRAME); |
| 108 EXPECT_EQ(CCSchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, state
.commitState()); | 130 EXPECT_EQ(CCSchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, state
.commitState()); |
| 109 EXPECT_FALSE(state.needsCommit()); | 131 EXPECT_FALSE(state.needsCommit()); |
| 110 EXPECT_FALSE(state.vsyncCallbackNeeded()); | 132 EXPECT_FALSE(state.vsyncCallbackNeeded()); |
| 111 } | 133 } |
| 112 } | 134 } |
| 113 | 135 |
| 114 TEST(CCSchedulerStateMachineTest, TestSetForcedRedrawDoesNotSetsNormalRedraw) | 136 TEST(CCSchedulerStateMachineTest, TestSetForcedRedrawDoesNotSetsNormalRedraw) |
| 115 { | 137 { |
| 116 CCSchedulerStateMachine state; | 138 CCSchedulerStateMachine state; |
| 117 state.setNeedsForcedRedraw(); | 139 state.setNeedsForcedRedraw(); |
| 118 EXPECT_FALSE(state.redrawPending()); | 140 EXPECT_FALSE(state.redrawPending()); |
| 119 EXPECT_TRUE(state.vsyncCallbackNeeded()); | 141 EXPECT_TRUE(state.vsyncCallbackNeeded()); |
| 120 } | 142 } |
| 121 | 143 |
| 122 TEST(CCSchedulerStateMachineTest, TestFailedDrawSetsNeedsCommitAndDoesNotDrawAga
in) | 144 TEST(CCSchedulerStateMachineTest, TestFailedDrawSetsNeedsCommitAndDoesNotDrawAga
in) |
| 123 { | 145 { |
| 124 CCSchedulerStateMachine state; | 146 CCSchedulerStateMachine state; |
| 147 state.setCanBeginFrame(true); |
| 125 state.setVisible(true); | 148 state.setVisible(true); |
| 126 state.setNeedsRedraw(); | 149 state.setNeedsRedraw(); |
| 127 EXPECT_TRUE(state.redrawPending()); | 150 EXPECT_TRUE(state.redrawPending()); |
| 128 EXPECT_TRUE(state.vsyncCallbackNeeded()); | 151 EXPECT_TRUE(state.vsyncCallbackNeeded()); |
| 129 state.didEnterVSync(); | 152 state.didEnterVSync(); |
| 130 | 153 |
| 131 // We're drawing now. | 154 // We're drawing now. |
| 132 EXPECT_EQ(CCSchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.nextAction
()); | 155 EXPECT_EQ(CCSchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.nextAction
()); |
| 133 state.updateState(CCSchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE); | 156 state.updateState(CCSchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE); |
| 134 EXPECT_EQ(CCSchedulerStateMachine::ACTION_NONE, state.nextAction()); | 157 EXPECT_EQ(CCSchedulerStateMachine::ACTION_NONE, state.nextAction()); |
| 135 EXPECT_FALSE(state.redrawPending()); | 158 EXPECT_FALSE(state.redrawPending()); |
| 136 EXPECT_FALSE(state.commitPending()); | 159 EXPECT_FALSE(state.commitPending()); |
| 137 | 160 |
| 138 // Failing the draw makes us require a commit. | 161 // Failing the draw makes us require a commit. |
| 139 state.didDrawIfPossibleCompleted(false); | 162 state.didDrawIfPossibleCompleted(false); |
| 140 EXPECT_EQ(CCSchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction()); | 163 EXPECT_EQ(CCSchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction()); |
| 141 state.updateState(CCSchedulerStateMachine::ACTION_BEGIN_FRAME); | 164 state.updateState(CCSchedulerStateMachine::ACTION_BEGIN_FRAME); |
| 142 EXPECT_TRUE(state.redrawPending()); | 165 EXPECT_TRUE(state.redrawPending()); |
| 143 EXPECT_TRUE(state.commitPending()); | 166 EXPECT_TRUE(state.commitPending()); |
| 144 } | 167 } |
| 145 | 168 |
| 146 TEST(CCSchedulerStateMachineTest, TestSetNeedsRedrawDuringFailedDrawDoesNotRemov
eNeedsRedraw) | 169 TEST(CCSchedulerStateMachineTest, TestSetNeedsRedrawDuringFailedDrawDoesNotRemov
eNeedsRedraw) |
| 147 { | 170 { |
| 148 CCSchedulerStateMachine state; | 171 CCSchedulerStateMachine state; |
| 172 state.setCanBeginFrame(true); |
| 149 state.setVisible(true); | 173 state.setVisible(true); |
| 150 state.setNeedsRedraw(); | 174 state.setNeedsRedraw(); |
| 151 EXPECT_TRUE(state.redrawPending()); | 175 EXPECT_TRUE(state.redrawPending()); |
| 152 EXPECT_TRUE(state.vsyncCallbackNeeded()); | 176 EXPECT_TRUE(state.vsyncCallbackNeeded()); |
| 153 state.didEnterVSync(); | 177 state.didEnterVSync(); |
| 154 | 178 |
| 155 // We're drawing now. | 179 // We're drawing now. |
| 156 EXPECT_EQ(CCSchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.nextAction
()); | 180 EXPECT_EQ(CCSchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.nextAction
()); |
| 157 state.updateState(CCSchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE); | 181 state.updateState(CCSchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE); |
| 158 EXPECT_EQ(CCSchedulerStateMachine::ACTION_NONE, state.nextAction()); | 182 EXPECT_EQ(CCSchedulerStateMachine::ACTION_NONE, state.nextAction()); |
| 159 EXPECT_FALSE(state.redrawPending()); | 183 EXPECT_FALSE(state.redrawPending()); |
| 160 EXPECT_FALSE(state.commitPending()); | 184 EXPECT_FALSE(state.commitPending()); |
| 161 | 185 |
| 162 // While still in the same vsync callback, set needs redraw again. | 186 // While still in the same vsync callback, set needs redraw again. |
| 163 // This should not redraw. | 187 // This should not redraw. |
| 164 state.setNeedsRedraw(); | 188 state.setNeedsRedraw(); |
| 165 EXPECT_EQ(CCSchedulerStateMachine::ACTION_NONE, state.nextAction()); | 189 EXPECT_EQ(CCSchedulerStateMachine::ACTION_NONE, state.nextAction()); |
| 166 | 190 |
| 167 // Failing the draw makes us require a commit. | 191 // Failing the draw makes us require a commit. |
| 168 state.didDrawIfPossibleCompleted(false); | 192 state.didDrawIfPossibleCompleted(false); |
| 169 EXPECT_EQ(CCSchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction()); | 193 EXPECT_EQ(CCSchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction()); |
| 170 EXPECT_TRUE(state.redrawPending()); | 194 EXPECT_TRUE(state.redrawPending()); |
| 171 } | 195 } |
| 172 | 196 |
| 173 TEST(CCSchedulerStateMachineTest, TestCommitAfterFailedDrawAllowsDrawInSameFrame
) | 197 TEST(CCSchedulerStateMachineTest, TestCommitAfterFailedDrawAllowsDrawInSameFrame
) |
| 174 { | 198 { |
| 175 CCSchedulerStateMachine state; | 199 CCSchedulerStateMachine state; |
| 200 state.setCanBeginFrame(true); |
| 176 state.setVisible(true); | 201 state.setVisible(true); |
| 177 | 202 |
| 178 // Start a commit. | 203 // Start a commit. |
| 179 state.setNeedsCommit(); | 204 state.setNeedsCommit(); |
| 180 EXPECT_EQ(CCSchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction()); | 205 EXPECT_EQ(CCSchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction()); |
| 181 state.updateState(CCSchedulerStateMachine::ACTION_BEGIN_FRAME); | 206 state.updateState(CCSchedulerStateMachine::ACTION_BEGIN_FRAME); |
| 182 EXPECT_TRUE(state.commitPending()); | 207 EXPECT_TRUE(state.commitPending()); |
| 183 | 208 |
| 184 // Then initiate a draw. | 209 // Then initiate a draw. |
| 185 state.setNeedsRedraw(); | 210 state.setNeedsRedraw(); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 205 state.updateState(CCSchedulerStateMachine::ACTION_COMMIT); | 230 state.updateState(CCSchedulerStateMachine::ACTION_COMMIT); |
| 206 EXPECT_TRUE(state.redrawPending()); | 231 EXPECT_TRUE(state.redrawPending()); |
| 207 | 232 |
| 208 // And we should be allowed to draw again. | 233 // And we should be allowed to draw again. |
| 209 EXPECT_EQ(CCSchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.nextAction
()); | 234 EXPECT_EQ(CCSchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.nextAction
()); |
| 210 } | 235 } |
| 211 | 236 |
| 212 TEST(CCSchedulerStateMachineTest, TestCommitAfterFailedAndSuccessfulDrawDoesNotA
llowDrawInSameFrame) | 237 TEST(CCSchedulerStateMachineTest, TestCommitAfterFailedAndSuccessfulDrawDoesNotA
llowDrawInSameFrame) |
| 213 { | 238 { |
| 214 CCSchedulerStateMachine state; | 239 CCSchedulerStateMachine state; |
| 240 state.setCanBeginFrame(true); |
| 215 state.setVisible(true); | 241 state.setVisible(true); |
| 216 | 242 |
| 217 // Start a commit. | 243 // Start a commit. |
| 218 state.setNeedsCommit(); | 244 state.setNeedsCommit(); |
| 219 EXPECT_EQ(CCSchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction()); | 245 EXPECT_EQ(CCSchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction()); |
| 220 state.updateState(CCSchedulerStateMachine::ACTION_BEGIN_FRAME); | 246 state.updateState(CCSchedulerStateMachine::ACTION_BEGIN_FRAME); |
| 221 EXPECT_TRUE(state.commitPending()); | 247 EXPECT_TRUE(state.commitPending()); |
| 222 | 248 |
| 223 // Then initiate a draw. | 249 // Then initiate a draw. |
| 224 state.setNeedsRedraw(); | 250 state.setNeedsRedraw(); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 255 state.updateState(CCSchedulerStateMachine::ACTION_COMMIT); | 281 state.updateState(CCSchedulerStateMachine::ACTION_COMMIT); |
| 256 EXPECT_TRUE(state.redrawPending()); | 282 EXPECT_TRUE(state.redrawPending()); |
| 257 | 283 |
| 258 // And we should not be allowed to draw again in the same frame.. | 284 // And we should not be allowed to draw again in the same frame.. |
| 259 EXPECT_EQ(CCSchedulerStateMachine::ACTION_NONE, state.nextAction()); | 285 EXPECT_EQ(CCSchedulerStateMachine::ACTION_NONE, state.nextAction()); |
| 260 } | 286 } |
| 261 | 287 |
| 262 TEST(CCSchedulerStateMachineTest, TestFailedDrawIsRetriedNextVSync) | 288 TEST(CCSchedulerStateMachineTest, TestFailedDrawIsRetriedNextVSync) |
| 263 { | 289 { |
| 264 CCSchedulerStateMachine state; | 290 CCSchedulerStateMachine state; |
| 291 state.setCanBeginFrame(true); |
| 265 state.setVisible(true); | 292 state.setVisible(true); |
| 266 | 293 |
| 267 // Start a draw. | 294 // Start a draw. |
| 268 state.setNeedsRedraw(); | 295 state.setNeedsRedraw(); |
| 269 EXPECT_TRUE(state.vsyncCallbackNeeded()); | 296 EXPECT_TRUE(state.vsyncCallbackNeeded()); |
| 270 state.didEnterVSync(); | 297 state.didEnterVSync(); |
| 271 EXPECT_EQ(CCSchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.nextAction
()); | 298 EXPECT_EQ(CCSchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.nextAction
()); |
| 272 EXPECT_TRUE(state.redrawPending()); | 299 EXPECT_TRUE(state.redrawPending()); |
| 273 | 300 |
| 274 // Fail the draw. | 301 // Fail the draw. |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 440 state.setCanDraw(false); | 467 state.setCanDraw(false); |
| 441 EXPECT_NE(CCSchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.ne
xtAction()); | 468 EXPECT_NE(CCSchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.ne
xtAction()); |
| 442 } | 469 } |
| 443 } | 470 } |
| 444 } | 471 } |
| 445 | 472 |
| 446 TEST(CCSchedulerStateMachineTest, TestCanRedrawWithWaitingForFirstDrawMakesProgr
ess) | 473 TEST(CCSchedulerStateMachineTest, TestCanRedrawWithWaitingForFirstDrawMakesProgr
ess) |
| 447 { | 474 { |
| 448 StateMachine state; | 475 StateMachine state; |
| 449 state.setCommitState(CCSchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST
_DRAW); | 476 state.setCommitState(CCSchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST
_DRAW); |
| 477 state.setCanBeginFrame(true); |
| 450 state.setNeedsCommit(true); | 478 state.setNeedsCommit(true); |
| 451 state.setNeedsRedraw(true); | 479 state.setNeedsRedraw(true); |
| 452 state.setUpdateMoreResourcesPending(false); | 480 state.setUpdateMoreResourcesPending(false); |
| 453 state.setVisible(true); | 481 state.setVisible(true); |
| 454 state.setCanDraw(false); | 482 state.setCanDraw(false); |
| 455 EXPECT_EQ(CCSchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction()); | 483 EXPECT_EQ(CCSchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction()); |
| 456 } | 484 } |
| 457 | 485 |
| 458 TEST(CCSchedulerStateMachineTest, TestUpdates_NoRedraw_OneRoundOfUpdates) | 486 TEST(CCSchedulerStateMachineTest, TestUpdates_NoRedraw_OneRoundOfUpdates) |
| 459 { | 487 { |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 583 // Verify we commit regardless of vsync state | 611 // Verify we commit regardless of vsync state |
| 584 state.didLeaveVSync(); | 612 state.didLeaveVSync(); |
| 585 EXPECT_EQ(CCSchedulerStateMachine::ACTION_COMMIT, state.nextAction()); | 613 EXPECT_EQ(CCSchedulerStateMachine::ACTION_COMMIT, state.nextAction()); |
| 586 state.didEnterVSync(); | 614 state.didEnterVSync(); |
| 587 EXPECT_EQ(CCSchedulerStateMachine::ACTION_COMMIT, state.nextAction()); | 615 EXPECT_EQ(CCSchedulerStateMachine::ACTION_COMMIT, state.nextAction()); |
| 588 } | 616 } |
| 589 | 617 |
| 590 TEST(CCSchedulerStateMachineTest, TestSetNeedsCommitIsNotLost) | 618 TEST(CCSchedulerStateMachineTest, TestSetNeedsCommitIsNotLost) |
| 591 { | 619 { |
| 592 StateMachine state; | 620 StateMachine state; |
| 621 state.setCanBeginFrame(true); |
| 593 state.setNeedsCommit(true); | 622 state.setNeedsCommit(true); |
| 594 state.setVisible(true); | 623 state.setVisible(true); |
| 595 | 624 |
| 596 // Begin the frame. | 625 // Begin the frame. |
| 597 EXPECT_EQ(CCSchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction()); | 626 EXPECT_EQ(CCSchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction()); |
| 598 state.updateState(state.nextAction()); | 627 state.updateState(state.nextAction()); |
| 599 EXPECT_EQ(CCSchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, state.com
mitState()); | 628 EXPECT_EQ(CCSchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, state.com
mitState()); |
| 600 | 629 |
| 601 // Now, while the frame is in progress, set another commit. | 630 // Now, while the frame is in progress, set another commit. |
| 602 state.setNeedsCommit(true); | 631 state.setNeedsCommit(true); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 625 state.didDrawIfPossibleCompleted(true); | 654 state.didDrawIfPossibleCompleted(true); |
| 626 | 655 |
| 627 // Verify that another commit will begin. | 656 // Verify that another commit will begin. |
| 628 state.didLeaveVSync(); | 657 state.didLeaveVSync(); |
| 629 EXPECT_EQ(CCSchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction()); | 658 EXPECT_EQ(CCSchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction()); |
| 630 } | 659 } |
| 631 | 660 |
| 632 TEST(CCSchedulerStateMachineTest, TestFullCycle) | 661 TEST(CCSchedulerStateMachineTest, TestFullCycle) |
| 633 { | 662 { |
| 634 StateMachine state; | 663 StateMachine state; |
| 664 state.setCanBeginFrame(true); |
| 635 state.setVisible(true); | 665 state.setVisible(true); |
| 636 | 666 |
| 637 // Start clean and set commit. | 667 // Start clean and set commit. |
| 638 state.setNeedsCommit(true); | 668 state.setNeedsCommit(true); |
| 639 EXPECT_EQ(CCSchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction()); | 669 EXPECT_EQ(CCSchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction()); |
| 640 | 670 |
| 641 // Begin the frame. | 671 // Begin the frame. |
| 642 state.updateState(CCSchedulerStateMachine::ACTION_BEGIN_FRAME); | 672 state.updateState(CCSchedulerStateMachine::ACTION_BEGIN_FRAME); |
| 643 EXPECT_EQ(CCSchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, state.com
mitState()); | 673 EXPECT_EQ(CCSchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, state.com
mitState()); |
| 644 EXPECT_FALSE(state.needsCommit()); | 674 EXPECT_FALSE(state.needsCommit()); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 672 | 702 |
| 673 // Should be synchronized, no draw needed, no action needed. | 703 // Should be synchronized, no draw needed, no action needed. |
| 674 EXPECT_EQ(CCSchedulerStateMachine::COMMIT_STATE_IDLE, state.commitState()); | 704 EXPECT_EQ(CCSchedulerStateMachine::COMMIT_STATE_IDLE, state.commitState()); |
| 675 EXPECT_FALSE(state.needsRedraw()); | 705 EXPECT_FALSE(state.needsRedraw()); |
| 676 EXPECT_EQ(CCSchedulerStateMachine::ACTION_NONE, state.nextAction()); | 706 EXPECT_EQ(CCSchedulerStateMachine::ACTION_NONE, state.nextAction()); |
| 677 } | 707 } |
| 678 | 708 |
| 679 TEST(CCSchedulerStateMachineTest, TestFullCycleWithCommitRequestInbetween) | 709 TEST(CCSchedulerStateMachineTest, TestFullCycleWithCommitRequestInbetween) |
| 680 { | 710 { |
| 681 StateMachine state; | 711 StateMachine state; |
| 712 state.setCanBeginFrame(true); |
| 682 state.setVisible(true); | 713 state.setVisible(true); |
| 683 | 714 |
| 684 // Start clean and set commit. | 715 // Start clean and set commit. |
| 685 state.setNeedsCommit(true); | 716 state.setNeedsCommit(true); |
| 686 EXPECT_EQ(CCSchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction()); | 717 EXPECT_EQ(CCSchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction()); |
| 687 | 718 |
| 688 // Begin the frame. | 719 // Begin the frame. |
| 689 state.updateState(CCSchedulerStateMachine::ACTION_BEGIN_FRAME); | 720 state.updateState(CCSchedulerStateMachine::ACTION_BEGIN_FRAME); |
| 690 EXPECT_EQ(CCSchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, state.com
mitState()); | 721 EXPECT_EQ(CCSchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, state.com
mitState()); |
| 691 EXPECT_FALSE(state.needsCommit()); | 722 EXPECT_FALSE(state.needsCommit()); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 730 TEST(CCSchedulerStateMachineTest, TestRequestCommitInvisible) | 761 TEST(CCSchedulerStateMachineTest, TestRequestCommitInvisible) |
| 731 { | 762 { |
| 732 StateMachine state; | 763 StateMachine state; |
| 733 state.setNeedsCommit(true); | 764 state.setNeedsCommit(true); |
| 734 EXPECT_EQ(CCSchedulerStateMachine::ACTION_NONE, state.nextAction()); | 765 EXPECT_EQ(CCSchedulerStateMachine::ACTION_NONE, state.nextAction()); |
| 735 } | 766 } |
| 736 | 767 |
| 737 TEST(CCSchedulerStateMachineTest, TestGoesInvisibleMidCommit) | 768 TEST(CCSchedulerStateMachineTest, TestGoesInvisibleMidCommit) |
| 738 { | 769 { |
| 739 StateMachine state; | 770 StateMachine state; |
| 771 state.setCanBeginFrame(true); |
| 740 state.setVisible(true); | 772 state.setVisible(true); |
| 741 | 773 |
| 742 // Start clean and set commit. | 774 // Start clean and set commit. |
| 743 state.setNeedsCommit(true); | 775 state.setNeedsCommit(true); |
| 744 EXPECT_EQ(CCSchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction()); | 776 EXPECT_EQ(CCSchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction()); |
| 745 | 777 |
| 746 // Begin the frame while visible. | 778 // Begin the frame while visible. |
| 747 state.updateState(CCSchedulerStateMachine::ACTION_BEGIN_FRAME); | 779 state.updateState(CCSchedulerStateMachine::ACTION_BEGIN_FRAME); |
| 748 EXPECT_EQ(CCSchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, state.com
mitState()); | 780 EXPECT_EQ(CCSchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, state.com
mitState()); |
| 749 EXPECT_FALSE(state.needsCommit()); | 781 EXPECT_FALSE(state.needsCommit()); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 775 // Expect to do nothing, both in and out of vsync. | 807 // Expect to do nothing, both in and out of vsync. |
| 776 state.didLeaveVSync(); | 808 state.didLeaveVSync(); |
| 777 EXPECT_EQ(CCSchedulerStateMachine::ACTION_NONE, state.nextAction()); | 809 EXPECT_EQ(CCSchedulerStateMachine::ACTION_NONE, state.nextAction()); |
| 778 state.didEnterVSync(); | 810 state.didEnterVSync(); |
| 779 EXPECT_EQ(CCSchedulerStateMachine::ACTION_NONE, state.nextAction()); | 811 EXPECT_EQ(CCSchedulerStateMachine::ACTION_NONE, state.nextAction()); |
| 780 } | 812 } |
| 781 | 813 |
| 782 TEST(CCSchedulerStateMachineTest, TestContextLostWhenCompletelyIdle) | 814 TEST(CCSchedulerStateMachineTest, TestContextLostWhenCompletelyIdle) |
| 783 { | 815 { |
| 784 StateMachine state; | 816 StateMachine state; |
| 817 state.setCanBeginFrame(true); |
| 785 state.setVisible(true); | 818 state.setVisible(true); |
| 786 | 819 |
| 787 state.didLoseContext(); | 820 state.didLoseContext(); |
| 788 | 821 |
| 789 EXPECT_EQ(CCSchedulerStateMachine::ACTION_BEGIN_CONTEXT_RECREATION, state.ne
xtAction()); | 822 EXPECT_EQ(CCSchedulerStateMachine::ACTION_BEGIN_CONTEXT_RECREATION, state.ne
xtAction()); |
| 790 state.updateState(state.nextAction()); | 823 state.updateState(state.nextAction()); |
| 791 | 824 |
| 792 // Once context recreation begins, nothing should happen. | 825 // Once context recreation begins, nothing should happen. |
| 793 EXPECT_EQ(CCSchedulerStateMachine::ACTION_NONE, state.nextAction()); | 826 EXPECT_EQ(CCSchedulerStateMachine::ACTION_NONE, state.nextAction()); |
| 794 | 827 |
| 795 // Recreate the context | 828 // Recreate the context |
| 796 state.didRecreateContext(); | 829 state.didRecreateContext(); |
| 797 | 830 |
| 798 // When the context is recreated, we should begin a commit | 831 // When the context is recreated, we should begin a commit |
| 799 EXPECT_EQ(CCSchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction()); | 832 EXPECT_EQ(CCSchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction()); |
| 800 state.updateState(state.nextAction()); | 833 state.updateState(state.nextAction()); |
| 801 } | 834 } |
| 802 | 835 |
| 803 TEST(CCSchedulerStateMachineTest, TestContextLostWhenIdleAndCommitRequestedWhile
Recreating) | 836 TEST(CCSchedulerStateMachineTest, TestContextLostWhenIdleAndCommitRequestedWhile
Recreating) |
| 804 { | 837 { |
| 805 StateMachine state; | 838 StateMachine state; |
| 839 state.setCanBeginFrame(true); |
| 806 state.setVisible(true); | 840 state.setVisible(true); |
| 807 | 841 |
| 808 state.didLoseContext(); | 842 state.didLoseContext(); |
| 809 | 843 |
| 810 EXPECT_EQ(CCSchedulerStateMachine::ACTION_BEGIN_CONTEXT_RECREATION, state.ne
xtAction()); | 844 EXPECT_EQ(CCSchedulerStateMachine::ACTION_BEGIN_CONTEXT_RECREATION, state.ne
xtAction()); |
| 811 state.updateState(state.nextAction()); | 845 state.updateState(state.nextAction()); |
| 812 | 846 |
| 813 // Once context recreation begins, nothing should happen. | 847 // Once context recreation begins, nothing should happen. |
| 814 EXPECT_EQ(CCSchedulerStateMachine::ACTION_NONE, state.nextAction()); | 848 EXPECT_EQ(CCSchedulerStateMachine::ACTION_NONE, state.nextAction()); |
| 815 | 849 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 831 EXPECT_EQ(CCSchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.nextAction
()); | 865 EXPECT_EQ(CCSchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.nextAction
()); |
| 832 state.setCanDraw(false); | 866 state.setCanDraw(false); |
| 833 EXPECT_EQ(CCSchedulerStateMachine::ACTION_NONE, state.nextAction()); | 867 EXPECT_EQ(CCSchedulerStateMachine::ACTION_NONE, state.nextAction()); |
| 834 state.setCanDraw(true); | 868 state.setCanDraw(true); |
| 835 state.didLeaveVSync(); | 869 state.didLeaveVSync(); |
| 836 } | 870 } |
| 837 | 871 |
| 838 TEST(CCSchedulerStateMachineTest, TestContextLostWhileCommitInProgress) | 872 TEST(CCSchedulerStateMachineTest, TestContextLostWhileCommitInProgress) |
| 839 { | 873 { |
| 840 StateMachine state; | 874 StateMachine state; |
| 875 state.setCanBeginFrame(true); |
| 841 state.setVisible(true); | 876 state.setVisible(true); |
| 842 | 877 |
| 843 // Get a commit in flight. | 878 // Get a commit in flight. |
| 844 state.setNeedsCommit(true); | 879 state.setNeedsCommit(true); |
| 845 EXPECT_EQ(CCSchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction()); | 880 EXPECT_EQ(CCSchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction()); |
| 846 state.updateState(state.nextAction()); | 881 state.updateState(state.nextAction()); |
| 847 | 882 |
| 848 // Set damage and expect a draw. | 883 // Set damage and expect a draw. |
| 849 state.setNeedsRedraw(true); | 884 state.setNeedsRedraw(true); |
| 850 state.didEnterVSync(); | 885 state.didEnterVSync(); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 871 // Expect to be told to begin context recreation, independent of vsync state | 906 // Expect to be told to begin context recreation, independent of vsync state |
| 872 state.didEnterVSync(); | 907 state.didEnterVSync(); |
| 873 EXPECT_EQ(CCSchedulerStateMachine::ACTION_BEGIN_CONTEXT_RECREATION, state.ne
xtAction()); | 908 EXPECT_EQ(CCSchedulerStateMachine::ACTION_BEGIN_CONTEXT_RECREATION, state.ne
xtAction()); |
| 874 state.didLeaveVSync(); | 909 state.didLeaveVSync(); |
| 875 EXPECT_EQ(CCSchedulerStateMachine::ACTION_BEGIN_CONTEXT_RECREATION, state.ne
xtAction()); | 910 EXPECT_EQ(CCSchedulerStateMachine::ACTION_BEGIN_CONTEXT_RECREATION, state.ne
xtAction()); |
| 876 } | 911 } |
| 877 | 912 |
| 878 TEST(CCSchedulerStateMachineTest, TestContextLostWhileCommitInProgressAndAnother
CommitRequested) | 913 TEST(CCSchedulerStateMachineTest, TestContextLostWhileCommitInProgressAndAnother
CommitRequested) |
| 879 { | 914 { |
| 880 StateMachine state; | 915 StateMachine state; |
| 916 state.setCanBeginFrame(true); |
| 881 state.setVisible(true); | 917 state.setVisible(true); |
| 882 | 918 |
| 883 // Get a commit in flight. | 919 // Get a commit in flight. |
| 884 state.setNeedsCommit(true); | 920 state.setNeedsCommit(true); |
| 885 EXPECT_EQ(CCSchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction()); | 921 EXPECT_EQ(CCSchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction()); |
| 886 state.updateState(state.nextAction()); | 922 state.updateState(state.nextAction()); |
| 887 | 923 |
| 888 // Set damage and expect a draw. | 924 // Set damage and expect a draw. |
| 889 state.setNeedsRedraw(true); | 925 state.setNeedsRedraw(true); |
| 890 state.didEnterVSync(); | 926 state.didEnterVSync(); |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 949 // Ask a forced redraw and verify it ocurrs. | 985 // Ask a forced redraw and verify it ocurrs. |
| 950 state.setNeedsForcedRedraw(true); | 986 state.setNeedsForcedRedraw(true); |
| 951 state.didEnterVSync(); | 987 state.didEnterVSync(); |
| 952 EXPECT_EQ(CCSchedulerStateMachine::ACTION_DRAW_FORCED, state.nextAction()); | 988 EXPECT_EQ(CCSchedulerStateMachine::ACTION_DRAW_FORCED, state.nextAction()); |
| 953 state.didLeaveVSync(); | 989 state.didLeaveVSync(); |
| 954 } | 990 } |
| 955 | 991 |
| 956 TEST(CCSchedulerStateMachineTest, TestBeginFrameWhenInvisibleAndForceCommit) | 992 TEST(CCSchedulerStateMachineTest, TestBeginFrameWhenInvisibleAndForceCommit) |
| 957 { | 993 { |
| 958 StateMachine state; | 994 StateMachine state; |
| 995 state.setCanBeginFrame(true); |
| 996 state.setVisible(false); |
| 997 state.setNeedsCommit(true); |
| 998 state.setNeedsForcedCommit(true); |
| 999 EXPECT_EQ(CCSchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction()); |
| 1000 } |
| 1001 |
| 1002 TEST(CCSchedulerStateMachineTest, TestBeginFrameWhenCanBeginFrameFalseAndForceCo
mmit) |
| 1003 { |
| 1004 StateMachine state; |
| 959 state.setVisible(true); | 1005 state.setVisible(true); |
| 960 state.setNeedsCommit(true); | 1006 state.setNeedsCommit(true); |
| 961 state.setNeedsForcedCommit(true); | 1007 state.setNeedsForcedCommit(true); |
| 962 EXPECT_EQ(CCSchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction()); | 1008 EXPECT_EQ(CCSchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction()); |
| 963 } | 1009 } |
| 964 | 1010 |
| 965 TEST(CCSchedulerStateMachineTest, TestBeginFrameWhenCommitInProgress) | 1011 TEST(CCSchedulerStateMachineTest, TestBeginFrameWhenCommitInProgress) |
| 966 { | 1012 { |
| 967 StateMachine state; | 1013 StateMachine state; |
| 1014 state.setCanBeginFrame(true); |
| 968 state.setVisible(false); | 1015 state.setVisible(false); |
| 969 state.setCommitState(CCSchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS
); | 1016 state.setCommitState(CCSchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS
); |
| 970 state.setNeedsCommit(true); | 1017 state.setNeedsCommit(true); |
| 971 state.setNeedsForcedCommit(true); | 1018 state.setNeedsForcedCommit(true); |
| 972 | 1019 |
| 973 state.beginFrameComplete(); | 1020 state.beginFrameComplete(); |
| 974 EXPECT_EQ(CCSchedulerStateMachine::ACTION_BEGIN_UPDATE_MORE_RESOURCES, state
.nextAction()); | 1021 EXPECT_EQ(CCSchedulerStateMachine::ACTION_BEGIN_UPDATE_MORE_RESOURCES, state
.nextAction()); |
| 975 state.updateState(state.nextAction()); | 1022 state.updateState(state.nextAction()); |
| 976 EXPECT_EQ(CCSchedulerStateMachine::ACTION_NONE, state.nextAction()); | 1023 EXPECT_EQ(CCSchedulerStateMachine::ACTION_NONE, state.nextAction()); |
| 977 state.beginUpdateMoreResourcesComplete(false); | 1024 state.beginUpdateMoreResourcesComplete(false); |
| 978 EXPECT_EQ(CCSchedulerStateMachine::ACTION_COMMIT, state.nextAction()); | 1025 EXPECT_EQ(CCSchedulerStateMachine::ACTION_COMMIT, state.nextAction()); |
| 979 state.updateState(state.nextAction()); | 1026 state.updateState(state.nextAction()); |
| 980 | 1027 |
| 981 EXPECT_EQ(CCSchedulerStateMachine::COMMIT_STATE_IDLE, state.commitState()); | 1028 EXPECT_EQ(CCSchedulerStateMachine::COMMIT_STATE_IDLE, state.commitState()); |
| 982 | 1029 |
| 983 EXPECT_EQ(CCSchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction()); | 1030 EXPECT_EQ(CCSchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction()); |
| 984 } | 1031 } |
| 985 | 1032 |
| 986 TEST(CCSchedulerStateMachineTest, TestBeginFrameWhenContextLost) | 1033 TEST(CCSchedulerStateMachineTest, TestBeginFrameWhenContextLost) |
| 987 { | 1034 { |
| 988 StateMachine state; | 1035 StateMachine state; |
| 1036 state.setCanBeginFrame(true); |
| 989 state.setVisible(true); | 1037 state.setVisible(true); |
| 990 state.setNeedsCommit(true); | 1038 state.setNeedsCommit(true); |
| 991 state.setNeedsForcedCommit(true); | 1039 state.setNeedsForcedCommit(true); |
| 992 state.didLoseContext(); | 1040 state.didLoseContext(); |
| 993 EXPECT_EQ(CCSchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction()); | 1041 EXPECT_EQ(CCSchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction()); |
| 994 } | 1042 } |
| 995 | 1043 |
| 996 } | 1044 } |
| OLD | NEW |