| 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 "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 | 10 |
| 11 using namespace cc; | 11 using namespace cc; |
| 12 | 12 |
| 13 namespace { | 13 namespace { |
| 14 | 14 |
| 15 const CCSchedulerStateMachine::CommitState allCommitStates[] = { | 15 const SchedulerStateMachine::CommitState allCommitStates[] = { |
| 16 CCSchedulerStateMachine::COMMIT_STATE_IDLE, | 16 SchedulerStateMachine::COMMIT_STATE_IDLE, |
| 17 CCSchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, | 17 SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, |
| 18 CCSchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT, | 18 SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT, |
| 19 CCSchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW | 19 SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW |
| 20 }; | 20 }; |
| 21 | 21 |
| 22 // Exposes the protected state fields of the CCSchedulerStateMachine for testing | 22 // Exposes the protected state fields of the SchedulerStateMachine for testing |
| 23 class StateMachine : public CCSchedulerStateMachine { | 23 class StateMachine : public SchedulerStateMachine { |
| 24 public: | 24 public: |
| 25 void setCommitState(CommitState cs) { m_commitState = cs; } | 25 void setCommitState(CommitState cs) { m_commitState = cs; } |
| 26 CommitState commitState() const { return m_commitState; } | 26 CommitState commitState() const { return m_commitState; } |
| 27 | 27 |
| 28 void setNeedsCommit(bool b) { m_needsCommit = b; } | 28 void setNeedsCommit(bool b) { m_needsCommit = b; } |
| 29 bool needsCommit() const { return m_needsCommit; } | 29 bool needsCommit() const { return m_needsCommit; } |
| 30 | 30 |
| 31 void setNeedsForcedCommit(bool b) { m_needsForcedCommit = b; } | 31 void setNeedsForcedCommit(bool b) { m_needsForcedCommit = b; } |
| 32 bool needsForcedCommit() const { return m_needsForcedCommit; } | 32 bool needsForcedCommit() const { return m_needsForcedCommit; } |
| 33 | 33 |
| 34 void setNeedsRedraw(bool b) { m_needsRedraw = b; } | 34 void setNeedsRedraw(bool b) { m_needsRedraw = b; } |
| 35 bool needsRedraw() const { return m_needsRedraw; } | 35 bool needsRedraw() const { return m_needsRedraw; } |
| 36 | 36 |
| 37 void setNeedsForcedRedraw(bool b) { m_needsForcedRedraw = b; } | 37 void setNeedsForcedRedraw(bool b) { m_needsForcedRedraw = b; } |
| 38 bool needsForcedRedraw() const { return m_needsForcedRedraw; } | 38 bool needsForcedRedraw() const { return m_needsForcedRedraw; } |
| 39 | 39 |
| 40 bool canDraw() const { return m_canDraw; } | 40 bool canDraw() const { return m_canDraw; } |
| 41 bool insideVSync() const { return m_insideVSync; } | 41 bool insideVSync() const { return m_insideVSync; } |
| 42 bool visible() const { return m_visible; } | 42 bool visible() const { return m_visible; } |
| 43 }; | 43 }; |
| 44 | 44 |
| 45 TEST(CCSchedulerStateMachineTest, TestNextActionBeginsFrameIfNeeded) | 45 TEST(SchedulerStateMachineTest, TestNextActionBeginsFrameIfNeeded) |
| 46 { | 46 { |
| 47 // If no commit needed, do nothing | 47 // If no commit needed, do nothing |
| 48 { | 48 { |
| 49 StateMachine state; | 49 StateMachine state; |
| 50 state.setCommitState(CCSchedulerStateMachine::COMMIT_STATE_IDLE); | 50 state.setCommitState(SchedulerStateMachine::COMMIT_STATE_IDLE); |
| 51 state.setCanBeginFrame(true); | 51 state.setCanBeginFrame(true); |
| 52 state.setNeedsRedraw(false); | 52 state.setNeedsRedraw(false); |
| 53 state.setNeedsCommit(false); | 53 state.setNeedsCommit(false); |
| 54 state.setVisible(true); | 54 state.setVisible(true); |
| 55 | 55 |
| 56 EXPECT_FALSE(state.vsyncCallbackNeeded()); | 56 EXPECT_FALSE(state.vsyncCallbackNeeded()); |
| 57 | 57 |
| 58 state.didLeaveVSync(); | 58 state.didLeaveVSync(); |
| 59 EXPECT_EQ(CCSchedulerStateMachine::ACTION_NONE, state.nextAction()); | 59 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.nextAction()); |
| 60 EXPECT_FALSE(state.vsyncCallbackNeeded()); | 60 EXPECT_FALSE(state.vsyncCallbackNeeded()); |
| 61 state.didEnterVSync(); | 61 state.didEnterVSync(); |
| 62 EXPECT_EQ(CCSchedulerStateMachine::ACTION_NONE, state.nextAction()); | 62 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.nextAction()); |
| 63 } | 63 } |
| 64 | 64 |
| 65 // If commit requested but canBeginFrame is still false, do nothing. | 65 // If commit requested but canBeginFrame is still false, do nothing. |
| 66 { | 66 { |
| 67 StateMachine state; | 67 StateMachine state; |
| 68 state.setCommitState(CCSchedulerStateMachine::COMMIT_STATE_IDLE); | 68 state.setCommitState(SchedulerStateMachine::COMMIT_STATE_IDLE); |
| 69 state.setNeedsRedraw(false); | 69 state.setNeedsRedraw(false); |
| 70 state.setNeedsCommit(false); | 70 state.setNeedsCommit(false); |
| 71 state.setVisible(true); | 71 state.setVisible(true); |
| 72 | 72 |
| 73 EXPECT_FALSE(state.vsyncCallbackNeeded()); | 73 EXPECT_FALSE(state.vsyncCallbackNeeded()); |
| 74 | 74 |
| 75 state.didLeaveVSync(); | 75 state.didLeaveVSync(); |
| 76 EXPECT_EQ(CCSchedulerStateMachine::ACTION_NONE, state.nextAction()); | 76 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.nextAction()); |
| 77 EXPECT_FALSE(state.vsyncCallbackNeeded()); | 77 EXPECT_FALSE(state.vsyncCallbackNeeded()); |
| 78 state.didEnterVSync(); | 78 state.didEnterVSync(); |
| 79 EXPECT_EQ(CCSchedulerStateMachine::ACTION_NONE, state.nextAction()); | 79 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.nextAction()); |
| 80 } | 80 } |
| 81 | 81 |
| 82 | 82 |
| 83 // If commit requested, begin a frame | 83 // If commit requested, begin a frame |
| 84 { | 84 { |
| 85 StateMachine state; | 85 StateMachine state; |
| 86 state.setCommitState(CCSchedulerStateMachine::COMMIT_STATE_IDLE); | 86 state.setCommitState(SchedulerStateMachine::COMMIT_STATE_IDLE); |
| 87 state.setCanBeginFrame(true); | 87 state.setCanBeginFrame(true); |
| 88 state.setNeedsRedraw(false); | 88 state.setNeedsRedraw(false); |
| 89 state.setNeedsCommit(true); | 89 state.setNeedsCommit(true); |
| 90 state.setVisible(true); | 90 state.setVisible(true); |
| 91 EXPECT_FALSE(state.vsyncCallbackNeeded()); | 91 EXPECT_FALSE(state.vsyncCallbackNeeded()); |
| 92 } | 92 } |
| 93 | 93 |
| 94 // Begin the frame, make sure needsCommit and commitState update correctly. | 94 // Begin the frame, make sure needsCommit and commitState update correctly. |
| 95 { | 95 { |
| 96 StateMachine state; | 96 StateMachine state; |
| 97 state.setCanBeginFrame(true); | 97 state.setCanBeginFrame(true); |
| 98 state.setVisible(true); | 98 state.setVisible(true); |
| 99 state.updateState(CCSchedulerStateMachine::ACTION_BEGIN_FRAME); | 99 state.updateState(SchedulerStateMachine::ACTION_BEGIN_FRAME); |
| 100 EXPECT_EQ(CCSchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, state
.commitState()); | 100 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, state.c
ommitState()); |
| 101 EXPECT_FALSE(state.needsCommit()); | 101 EXPECT_FALSE(state.needsCommit()); |
| 102 EXPECT_FALSE(state.vsyncCallbackNeeded()); | 102 EXPECT_FALSE(state.vsyncCallbackNeeded()); |
| 103 } | 103 } |
| 104 } | 104 } |
| 105 | 105 |
| 106 TEST(CCSchedulerStateMachineTest, TestSetForcedRedrawDoesNotSetsNormalRedraw) | 106 TEST(SchedulerStateMachineTest, TestSetForcedRedrawDoesNotSetsNormalRedraw) |
| 107 { | 107 { |
| 108 CCSchedulerStateMachine state; | 108 SchedulerStateMachine state; |
| 109 state.setCanDraw(true); | 109 state.setCanDraw(true); |
| 110 state.setNeedsForcedRedraw(); | 110 state.setNeedsForcedRedraw(); |
| 111 EXPECT_FALSE(state.redrawPending()); | 111 EXPECT_FALSE(state.redrawPending()); |
| 112 EXPECT_TRUE(state.vsyncCallbackNeeded()); | 112 EXPECT_TRUE(state.vsyncCallbackNeeded()); |
| 113 } | 113 } |
| 114 | 114 |
| 115 TEST(CCSchedulerStateMachineTest, TestFailedDrawSetsNeedsCommitAndDoesNotDrawAga
in) | 115 TEST(SchedulerStateMachineTest, TestFailedDrawSetsNeedsCommitAndDoesNotDrawAgain
) |
| 116 { | 116 { |
| 117 CCSchedulerStateMachine state; | 117 SchedulerStateMachine state; |
| 118 state.setCanBeginFrame(true); | 118 state.setCanBeginFrame(true); |
| 119 state.setVisible(true); | 119 state.setVisible(true); |
| 120 state.setCanDraw(true); | 120 state.setCanDraw(true); |
| 121 state.setNeedsRedraw(); | 121 state.setNeedsRedraw(); |
| 122 EXPECT_TRUE(state.redrawPending()); | 122 EXPECT_TRUE(state.redrawPending()); |
| 123 EXPECT_TRUE(state.vsyncCallbackNeeded()); | 123 EXPECT_TRUE(state.vsyncCallbackNeeded()); |
| 124 state.didEnterVSync(); | 124 state.didEnterVSync(); |
| 125 | 125 |
| 126 // We're drawing now. | 126 // We're drawing now. |
| 127 EXPECT_EQ(CCSchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.nextAction
()); | 127 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.nextAction()
); |
| 128 state.updateState(CCSchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE); | 128 state.updateState(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE); |
| 129 EXPECT_EQ(CCSchedulerStateMachine::ACTION_NONE, state.nextAction()); | 129 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.nextAction()); |
| 130 EXPECT_FALSE(state.redrawPending()); | 130 EXPECT_FALSE(state.redrawPending()); |
| 131 EXPECT_FALSE(state.commitPending()); | 131 EXPECT_FALSE(state.commitPending()); |
| 132 | 132 |
| 133 // Failing the draw makes us require a commit. | 133 // Failing the draw makes us require a commit. |
| 134 state.didDrawIfPossibleCompleted(false); | 134 state.didDrawIfPossibleCompleted(false); |
| 135 EXPECT_EQ(CCSchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction()); | 135 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction()); |
| 136 state.updateState(CCSchedulerStateMachine::ACTION_BEGIN_FRAME); | 136 state.updateState(SchedulerStateMachine::ACTION_BEGIN_FRAME); |
| 137 EXPECT_TRUE(state.redrawPending()); | 137 EXPECT_TRUE(state.redrawPending()); |
| 138 EXPECT_TRUE(state.commitPending()); | 138 EXPECT_TRUE(state.commitPending()); |
| 139 } | 139 } |
| 140 | 140 |
| 141 TEST(CCSchedulerStateMachineTest, TestSetNeedsRedrawDuringFailedDrawDoesNotRemov
eNeedsRedraw) | 141 TEST(SchedulerStateMachineTest, TestSetNeedsRedrawDuringFailedDrawDoesNotRemoveN
eedsRedraw) |
| 142 { | 142 { |
| 143 CCSchedulerStateMachine state; | 143 SchedulerStateMachine state; |
| 144 state.setCanBeginFrame(true); | 144 state.setCanBeginFrame(true); |
| 145 state.setVisible(true); | 145 state.setVisible(true); |
| 146 state.setCanDraw(true); | 146 state.setCanDraw(true); |
| 147 state.setNeedsRedraw(); | 147 state.setNeedsRedraw(); |
| 148 EXPECT_TRUE(state.redrawPending()); | 148 EXPECT_TRUE(state.redrawPending()); |
| 149 EXPECT_TRUE(state.vsyncCallbackNeeded()); | 149 EXPECT_TRUE(state.vsyncCallbackNeeded()); |
| 150 state.didEnterVSync(); | 150 state.didEnterVSync(); |
| 151 | 151 |
| 152 // We're drawing now. | 152 // We're drawing now. |
| 153 EXPECT_EQ(CCSchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.nextAction
()); | 153 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.nextAction()
); |
| 154 state.updateState(CCSchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE); | 154 state.updateState(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE); |
| 155 EXPECT_EQ(CCSchedulerStateMachine::ACTION_NONE, state.nextAction()); | 155 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.nextAction()); |
| 156 EXPECT_FALSE(state.redrawPending()); | 156 EXPECT_FALSE(state.redrawPending()); |
| 157 EXPECT_FALSE(state.commitPending()); | 157 EXPECT_FALSE(state.commitPending()); |
| 158 | 158 |
| 159 // While still in the same vsync callback, set needs redraw again. | 159 // While still in the same vsync callback, set needs redraw again. |
| 160 // This should not redraw. | 160 // This should not redraw. |
| 161 state.setNeedsRedraw(); | 161 state.setNeedsRedraw(); |
| 162 EXPECT_EQ(CCSchedulerStateMachine::ACTION_NONE, state.nextAction()); | 162 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.nextAction()); |
| 163 | 163 |
| 164 // Failing the draw makes us require a commit. | 164 // Failing the draw makes us require a commit. |
| 165 state.didDrawIfPossibleCompleted(false); | 165 state.didDrawIfPossibleCompleted(false); |
| 166 EXPECT_EQ(CCSchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction()); | 166 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction()); |
| 167 EXPECT_TRUE(state.redrawPending()); | 167 EXPECT_TRUE(state.redrawPending()); |
| 168 } | 168 } |
| 169 | 169 |
| 170 TEST(CCSchedulerStateMachineTest, TestCommitAfterFailedDrawAllowsDrawInSameFrame
) | 170 TEST(SchedulerStateMachineTest, TestCommitAfterFailedDrawAllowsDrawInSameFrame) |
| 171 { | 171 { |
| 172 CCSchedulerStateMachine state; | 172 SchedulerStateMachine state; |
| 173 state.setCanBeginFrame(true); | 173 state.setCanBeginFrame(true); |
| 174 state.setVisible(true); | 174 state.setVisible(true); |
| 175 state.setCanDraw(true); | 175 state.setCanDraw(true); |
| 176 | 176 |
| 177 // Start a commit. | 177 // Start a commit. |
| 178 state.setNeedsCommit(); | 178 state.setNeedsCommit(); |
| 179 EXPECT_EQ(CCSchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction()); | 179 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction()); |
| 180 state.updateState(CCSchedulerStateMachine::ACTION_BEGIN_FRAME); | 180 state.updateState(SchedulerStateMachine::ACTION_BEGIN_FRAME); |
| 181 EXPECT_TRUE(state.commitPending()); | 181 EXPECT_TRUE(state.commitPending()); |
| 182 | 182 |
| 183 // Then initiate a draw. | 183 // Then initiate a draw. |
| 184 state.setNeedsRedraw(); | 184 state.setNeedsRedraw(); |
| 185 EXPECT_TRUE(state.vsyncCallbackNeeded()); | 185 EXPECT_TRUE(state.vsyncCallbackNeeded()); |
| 186 state.didEnterVSync(); | 186 state.didEnterVSync(); |
| 187 EXPECT_EQ(CCSchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.nextAction
()); | 187 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.nextAction()
); |
| 188 EXPECT_TRUE(state.redrawPending()); | 188 EXPECT_TRUE(state.redrawPending()); |
| 189 | 189 |
| 190 // Fail the draw. | 190 // Fail the draw. |
| 191 state.updateState(CCSchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE); | 191 state.updateState(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE); |
| 192 EXPECT_EQ(CCSchedulerStateMachine::ACTION_NONE, state.nextAction()); | 192 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.nextAction()); |
| 193 state.didDrawIfPossibleCompleted(false); | 193 state.didDrawIfPossibleCompleted(false); |
| 194 EXPECT_TRUE(state.redrawPending()); | 194 EXPECT_TRUE(state.redrawPending()); |
| 195 // But the commit is ongoing. | 195 // But the commit is ongoing. |
| 196 EXPECT_TRUE(state.commitPending()); | 196 EXPECT_TRUE(state.commitPending()); |
| 197 | 197 |
| 198 // Finish the commit. | 198 // Finish the commit. |
| 199 state.beginFrameComplete(); | 199 state.beginFrameComplete(); |
| 200 EXPECT_EQ(CCSchedulerStateMachine::ACTION_COMMIT, state.nextAction()); | 200 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.nextAction()); |
| 201 state.updateState(CCSchedulerStateMachine::ACTION_COMMIT); | 201 state.updateState(SchedulerStateMachine::ACTION_COMMIT); |
| 202 EXPECT_TRUE(state.redrawPending()); | 202 EXPECT_TRUE(state.redrawPending()); |
| 203 | 203 |
| 204 // And we should be allowed to draw again. | 204 // And we should be allowed to draw again. |
| 205 EXPECT_EQ(CCSchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.nextAction
()); | 205 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.nextAction()
); |
| 206 } | 206 } |
| 207 | 207 |
| 208 TEST(CCSchedulerStateMachineTest, TestCommitAfterFailedAndSuccessfulDrawDoesNotA
llowDrawInSameFrame) | 208 TEST(SchedulerStateMachineTest, TestCommitAfterFailedAndSuccessfulDrawDoesNotAll
owDrawInSameFrame) |
| 209 { | 209 { |
| 210 CCSchedulerStateMachine state; | 210 SchedulerStateMachine state; |
| 211 state.setCanBeginFrame(true); | 211 state.setCanBeginFrame(true); |
| 212 state.setVisible(true); | 212 state.setVisible(true); |
| 213 state.setCanDraw(true); | 213 state.setCanDraw(true); |
| 214 | 214 |
| 215 // Start a commit. | 215 // Start a commit. |
| 216 state.setNeedsCommit(); | 216 state.setNeedsCommit(); |
| 217 EXPECT_EQ(CCSchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction()); | 217 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction()); |
| 218 state.updateState(CCSchedulerStateMachine::ACTION_BEGIN_FRAME); | 218 state.updateState(SchedulerStateMachine::ACTION_BEGIN_FRAME); |
| 219 EXPECT_TRUE(state.commitPending()); | 219 EXPECT_TRUE(state.commitPending()); |
| 220 | 220 |
| 221 // Then initiate a draw. | 221 // Then initiate a draw. |
| 222 state.setNeedsRedraw(); | 222 state.setNeedsRedraw(); |
| 223 EXPECT_TRUE(state.vsyncCallbackNeeded()); | 223 EXPECT_TRUE(state.vsyncCallbackNeeded()); |
| 224 state.didEnterVSync(); | 224 state.didEnterVSync(); |
| 225 EXPECT_EQ(CCSchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.nextAction
()); | 225 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.nextAction()
); |
| 226 EXPECT_TRUE(state.redrawPending()); | 226 EXPECT_TRUE(state.redrawPending()); |
| 227 | 227 |
| 228 // Fail the draw. | 228 // Fail the draw. |
| 229 state.updateState(CCSchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE); | 229 state.updateState(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE); |
| 230 EXPECT_EQ(CCSchedulerStateMachine::ACTION_NONE, state.nextAction()); | 230 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.nextAction()); |
| 231 state.didDrawIfPossibleCompleted(false); | 231 state.didDrawIfPossibleCompleted(false); |
| 232 EXPECT_TRUE(state.redrawPending()); | 232 EXPECT_TRUE(state.redrawPending()); |
| 233 // But the commit is ongoing. | 233 // But the commit is ongoing. |
| 234 EXPECT_TRUE(state.commitPending()); | 234 EXPECT_TRUE(state.commitPending()); |
| 235 | 235 |
| 236 // Force a draw. | 236 // Force a draw. |
| 237 state.setNeedsForcedRedraw(); | 237 state.setNeedsForcedRedraw(); |
| 238 EXPECT_EQ(CCSchedulerStateMachine::ACTION_DRAW_FORCED, state.nextAction()); | 238 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_FORCED, state.nextAction()); |
| 239 | 239 |
| 240 // Do the forced draw. | 240 // Do the forced draw. |
| 241 state.updateState(CCSchedulerStateMachine::ACTION_DRAW_FORCED); | 241 state.updateState(SchedulerStateMachine::ACTION_DRAW_FORCED); |
| 242 EXPECT_EQ(CCSchedulerStateMachine::ACTION_NONE, state.nextAction()); | 242 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.nextAction()); |
| 243 EXPECT_FALSE(state.redrawPending()); | 243 EXPECT_FALSE(state.redrawPending()); |
| 244 // And the commit is still ongoing. | 244 // And the commit is still ongoing. |
| 245 EXPECT_TRUE(state.commitPending()); | 245 EXPECT_TRUE(state.commitPending()); |
| 246 | 246 |
| 247 // Finish the commit. | 247 // Finish the commit. |
| 248 state.beginFrameComplete(); | 248 state.beginFrameComplete(); |
| 249 EXPECT_EQ(CCSchedulerStateMachine::ACTION_COMMIT, state.nextAction()); | 249 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.nextAction()); |
| 250 state.updateState(CCSchedulerStateMachine::ACTION_COMMIT); | 250 state.updateState(SchedulerStateMachine::ACTION_COMMIT); |
| 251 EXPECT_TRUE(state.redrawPending()); | 251 EXPECT_TRUE(state.redrawPending()); |
| 252 | 252 |
| 253 // And we should not be allowed to draw again in the same frame.. | 253 // And we should not be allowed to draw again in the same frame.. |
| 254 EXPECT_EQ(CCSchedulerStateMachine::ACTION_NONE, state.nextAction()); | 254 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.nextAction()); |
| 255 } | 255 } |
| 256 | 256 |
| 257 TEST(CCSchedulerStateMachineTest, TestFailedDrawsWillEventuallyForceADrawAfterTh
eNextCommit) | 257 TEST(SchedulerStateMachineTest, TestFailedDrawsWillEventuallyForceADrawAfterTheN
extCommit) |
| 258 { | 258 { |
| 259 CCSchedulerStateMachine state; | 259 SchedulerStateMachine state; |
| 260 state.setCanBeginFrame(true); | 260 state.setCanBeginFrame(true); |
| 261 state.setVisible(true); | 261 state.setVisible(true); |
| 262 state.setCanDraw(true); | 262 state.setCanDraw(true); |
| 263 state.setMaximumNumberOfFailedDrawsBeforeDrawIsForced(1); | 263 state.setMaximumNumberOfFailedDrawsBeforeDrawIsForced(1); |
| 264 | 264 |
| 265 // Start a commit. | 265 // Start a commit. |
| 266 state.setNeedsCommit(); | 266 state.setNeedsCommit(); |
| 267 EXPECT_EQ(CCSchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction()); | 267 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction()); |
| 268 state.updateState(CCSchedulerStateMachine::ACTION_BEGIN_FRAME); | 268 state.updateState(SchedulerStateMachine::ACTION_BEGIN_FRAME); |
| 269 EXPECT_TRUE(state.commitPending()); | 269 EXPECT_TRUE(state.commitPending()); |
| 270 | 270 |
| 271 // Then initiate a draw. | 271 // Then initiate a draw. |
| 272 state.setNeedsRedraw(); | 272 state.setNeedsRedraw(); |
| 273 EXPECT_TRUE(state.vsyncCallbackNeeded()); | 273 EXPECT_TRUE(state.vsyncCallbackNeeded()); |
| 274 state.didEnterVSync(); | 274 state.didEnterVSync(); |
| 275 EXPECT_EQ(CCSchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.nextAction
()); | 275 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.nextAction()
); |
| 276 EXPECT_TRUE(state.redrawPending()); | 276 EXPECT_TRUE(state.redrawPending()); |
| 277 | 277 |
| 278 // Fail the draw. | 278 // Fail the draw. |
| 279 state.updateState(CCSchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE); | 279 state.updateState(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE); |
| 280 EXPECT_EQ(CCSchedulerStateMachine::ACTION_NONE, state.nextAction()); | 280 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.nextAction()); |
| 281 state.didDrawIfPossibleCompleted(false); | 281 state.didDrawIfPossibleCompleted(false); |
| 282 EXPECT_TRUE(state.redrawPending()); | 282 EXPECT_TRUE(state.redrawPending()); |
| 283 // But the commit is ongoing. | 283 // But the commit is ongoing. |
| 284 EXPECT_TRUE(state.commitPending()); | 284 EXPECT_TRUE(state.commitPending()); |
| 285 | 285 |
| 286 // Finish the commit. Note, we should not yet be forcing a draw, but should | 286 // Finish the commit. Note, we should not yet be forcing a draw, but should |
| 287 // continue the commit as usual. | 287 // continue the commit as usual. |
| 288 state.beginFrameComplete(); | 288 state.beginFrameComplete(); |
| 289 EXPECT_EQ(CCSchedulerStateMachine::ACTION_COMMIT, state.nextAction()); | 289 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.nextAction()); |
| 290 state.updateState(CCSchedulerStateMachine::ACTION_COMMIT); | 290 state.updateState(SchedulerStateMachine::ACTION_COMMIT); |
| 291 EXPECT_TRUE(state.redrawPending()); | 291 EXPECT_TRUE(state.redrawPending()); |
| 292 | 292 |
| 293 // The redraw should be forced in this case. | 293 // The redraw should be forced in this case. |
| 294 EXPECT_EQ(CCSchedulerStateMachine::ACTION_DRAW_FORCED, state.nextAction()); | 294 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_FORCED, state.nextAction()); |
| 295 } | 295 } |
| 296 | 296 |
| 297 TEST(CCSchedulerStateMachineTest, TestFailedDrawIsRetriedNextVSync) | 297 TEST(SchedulerStateMachineTest, TestFailedDrawIsRetriedNextVSync) |
| 298 { | 298 { |
| 299 CCSchedulerStateMachine state; | 299 SchedulerStateMachine state; |
| 300 state.setCanBeginFrame(true); | 300 state.setCanBeginFrame(true); |
| 301 state.setVisible(true); | 301 state.setVisible(true); |
| 302 state.setCanDraw(true); | 302 state.setCanDraw(true); |
| 303 | 303 |
| 304 // Start a draw. | 304 // Start a draw. |
| 305 state.setNeedsRedraw(); | 305 state.setNeedsRedraw(); |
| 306 EXPECT_TRUE(state.vsyncCallbackNeeded()); | 306 EXPECT_TRUE(state.vsyncCallbackNeeded()); |
| 307 state.didEnterVSync(); | 307 state.didEnterVSync(); |
| 308 EXPECT_EQ(CCSchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.nextAction
()); | 308 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.nextAction()
); |
| 309 EXPECT_TRUE(state.redrawPending()); | 309 EXPECT_TRUE(state.redrawPending()); |
| 310 | 310 |
| 311 // Fail the draw. | 311 // Fail the draw. |
| 312 state.updateState(CCSchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE); | 312 state.updateState(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE); |
| 313 EXPECT_EQ(CCSchedulerStateMachine::ACTION_NONE, state.nextAction()); | 313 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.nextAction()); |
| 314 state.didDrawIfPossibleCompleted(false); | 314 state.didDrawIfPossibleCompleted(false); |
| 315 EXPECT_TRUE(state.redrawPending()); | 315 EXPECT_TRUE(state.redrawPending()); |
| 316 | 316 |
| 317 // We should not be trying to draw again now, but we have a commit pending. | 317 // We should not be trying to draw again now, but we have a commit pending. |
| 318 EXPECT_EQ(CCSchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction()); | 318 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction()); |
| 319 | 319 |
| 320 state.didLeaveVSync(); | 320 state.didLeaveVSync(); |
| 321 EXPECT_TRUE(state.vsyncCallbackNeeded()); | 321 EXPECT_TRUE(state.vsyncCallbackNeeded()); |
| 322 state.didEnterVSync(); | 322 state.didEnterVSync(); |
| 323 | 323 |
| 324 // We should try draw again in the next vsync. | 324 // We should try draw again in the next vsync. |
| 325 EXPECT_EQ(CCSchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.nextAction
()); | 325 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.nextAction()
); |
| 326 } | 326 } |
| 327 | 327 |
| 328 TEST(CCSchedulerStateMachineTest, TestDoestDrawTwiceInSameFrame) | 328 TEST(SchedulerStateMachineTest, TestDoestDrawTwiceInSameFrame) |
| 329 { | 329 { |
| 330 CCSchedulerStateMachine state; | 330 SchedulerStateMachine state; |
| 331 state.setVisible(true); | 331 state.setVisible(true); |
| 332 state.setCanDraw(true); | 332 state.setCanDraw(true); |
| 333 state.setNeedsRedraw(); | 333 state.setNeedsRedraw(); |
| 334 EXPECT_TRUE(state.vsyncCallbackNeeded()); | 334 EXPECT_TRUE(state.vsyncCallbackNeeded()); |
| 335 state.didEnterVSync(); | 335 state.didEnterVSync(); |
| 336 EXPECT_EQ(CCSchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.nextAction
()); | 336 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.nextAction()
); |
| 337 state.updateState(CCSchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE); | 337 state.updateState(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE); |
| 338 | 338 |
| 339 // While still in the same vsync callback, set needs redraw again. | 339 // While still in the same vsync callback, set needs redraw again. |
| 340 // This should not redraw. | 340 // This should not redraw. |
| 341 state.setNeedsRedraw(); | 341 state.setNeedsRedraw(); |
| 342 EXPECT_EQ(CCSchedulerStateMachine::ACTION_NONE, state.nextAction()); | 342 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.nextAction()); |
| 343 | 343 |
| 344 // Move to another frame. This should now draw. | 344 // Move to another frame. This should now draw. |
| 345 state.didDrawIfPossibleCompleted(true); | 345 state.didDrawIfPossibleCompleted(true); |
| 346 state.didLeaveVSync(); | 346 state.didLeaveVSync(); |
| 347 EXPECT_TRUE(state.vsyncCallbackNeeded()); | 347 EXPECT_TRUE(state.vsyncCallbackNeeded()); |
| 348 state.didEnterVSync(); | 348 state.didEnterVSync(); |
| 349 | 349 |
| 350 EXPECT_EQ(CCSchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.nextAction
()); | 350 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.nextAction()
); |
| 351 state.updateState(CCSchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE); | 351 state.updateState(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE); |
| 352 state.didDrawIfPossibleCompleted(true); | 352 state.didDrawIfPossibleCompleted(true); |
| 353 EXPECT_FALSE(state.vsyncCallbackNeeded()); | 353 EXPECT_FALSE(state.vsyncCallbackNeeded()); |
| 354 } | 354 } |
| 355 | 355 |
| 356 TEST(CCSchedulerStateMachineTest, TestNextActionDrawsOnVSync) | 356 TEST(SchedulerStateMachineTest, TestNextActionDrawsOnVSync) |
| 357 { | 357 { |
| 358 // When not on vsync, or on vsync but not visible, don't draw. | 358 // When not on vsync, or on vsync but not visible, don't draw. |
| 359 size_t numCommitStates = sizeof(allCommitStates) / sizeof(CCSchedulerStateMa
chine::CommitState); | 359 size_t numCommitStates = sizeof(allCommitStates) / sizeof(SchedulerStateMach
ine::CommitState); |
| 360 for (size_t i = 0; i < numCommitStates; ++i) { | 360 for (size_t i = 0; i < numCommitStates; ++i) { |
| 361 for (unsigned j = 0; j < 2; ++j) { | 361 for (unsigned j = 0; j < 2; ++j) { |
| 362 StateMachine state; | 362 StateMachine state; |
| 363 state.setCommitState(allCommitStates[i]); | 363 state.setCommitState(allCommitStates[i]); |
| 364 bool visible = j; | 364 bool visible = j; |
| 365 if (!visible) { | 365 if (!visible) { |
| 366 state.didEnterVSync(); | 366 state.didEnterVSync(); |
| 367 state.setVisible(false); | 367 state.setVisible(false); |
| 368 } else | 368 } else |
| 369 state.setVisible(true); | 369 state.setVisible(true); |
| 370 | 370 |
| 371 // Case 1: needsCommit=false | 371 // Case 1: needsCommit=false |
| 372 state.setNeedsCommit(false); | 372 state.setNeedsCommit(false); |
| 373 EXPECT_NE(CCSchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.ne
xtAction()); | 373 EXPECT_NE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.next
Action()); |
| 374 | 374 |
| 375 // Case 2: needsCommit=true | 375 // Case 2: needsCommit=true |
| 376 state.setNeedsCommit(true); | 376 state.setNeedsCommit(true); |
| 377 EXPECT_NE(CCSchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.ne
xtAction()); | 377 EXPECT_NE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.next
Action()); |
| 378 } | 378 } |
| 379 } | 379 } |
| 380 | 380 |
| 381 // When on vsync, or not on vsync but needsForcedRedraw set, should always d
raw except if you're ready to commit, in which case commit. | 381 // When on vsync, or not on vsync but needsForcedRedraw set, should always d
raw except if you're ready to commit, in which case commit. |
| 382 for (size_t i = 0; i < numCommitStates; ++i) { | 382 for (size_t i = 0; i < numCommitStates; ++i) { |
| 383 for (unsigned j = 0; j < 2; ++j) { | 383 for (unsigned j = 0; j < 2; ++j) { |
| 384 StateMachine state; | 384 StateMachine state; |
| 385 state.setCanDraw(true); | 385 state.setCanDraw(true); |
| 386 state.setCommitState(allCommitStates[i]); | 386 state.setCommitState(allCommitStates[i]); |
| 387 bool forcedDraw = j; | 387 bool forcedDraw = j; |
| 388 if (!forcedDraw) { | 388 if (!forcedDraw) { |
| 389 state.didEnterVSync(); | 389 state.didEnterVSync(); |
| 390 state.setNeedsRedraw(true); | 390 state.setNeedsRedraw(true); |
| 391 state.setVisible(true); | 391 state.setVisible(true); |
| 392 } else | 392 } else |
| 393 state.setNeedsForcedRedraw(true); | 393 state.setNeedsForcedRedraw(true); |
| 394 | 394 |
| 395 CCSchedulerStateMachine::Action expectedAction; | 395 SchedulerStateMachine::Action expectedAction; |
| 396 if (allCommitStates[i] != CCSchedulerStateMachine::COMMIT_STATE_READ
Y_TO_COMMIT) | 396 if (allCommitStates[i] != SchedulerStateMachine::COMMIT_STATE_READY_
TO_COMMIT) |
| 397 expectedAction = forcedDraw ? CCSchedulerStateMachine::ACTION_DR
AW_FORCED : CCSchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE; | 397 expectedAction = forcedDraw ? SchedulerStateMachine::ACTION_DRAW
_FORCED : SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE; |
| 398 else | 398 else |
| 399 expectedAction = CCSchedulerStateMachine::ACTION_COMMIT; | 399 expectedAction = SchedulerStateMachine::ACTION_COMMIT; |
| 400 | 400 |
| 401 // Case 1: needsCommit=false. | 401 // Case 1: needsCommit=false. |
| 402 state.setNeedsCommit(false); | 402 state.setNeedsCommit(false); |
| 403 EXPECT_TRUE(state.vsyncCallbackNeeded()); | 403 EXPECT_TRUE(state.vsyncCallbackNeeded()); |
| 404 EXPECT_EQ(expectedAction, state.nextAction()); | 404 EXPECT_EQ(expectedAction, state.nextAction()); |
| 405 | 405 |
| 406 // Case 2: needsCommit=true. | 406 // Case 2: needsCommit=true. |
| 407 state.setNeedsCommit(true); | 407 state.setNeedsCommit(true); |
| 408 EXPECT_TRUE(state.vsyncCallbackNeeded()); | 408 EXPECT_TRUE(state.vsyncCallbackNeeded()); |
| 409 EXPECT_EQ(expectedAction, state.nextAction()); | 409 EXPECT_EQ(expectedAction, state.nextAction()); |
| 410 } | 410 } |
| 411 } | 411 } |
| 412 } | 412 } |
| 413 | 413 |
| 414 TEST(CCSchedulerStateMachineTest, TestNoCommitStatesRedrawWhenInvisible) | 414 TEST(SchedulerStateMachineTest, TestNoCommitStatesRedrawWhenInvisible) |
| 415 { | 415 { |
| 416 size_t numCommitStates = sizeof(allCommitStates) / sizeof(CCSchedulerStateMa
chine::CommitState); | 416 size_t numCommitStates = sizeof(allCommitStates) / sizeof(SchedulerStateMach
ine::CommitState); |
| 417 for (size_t i = 0; i < numCommitStates; ++i) { | 417 for (size_t i = 0; i < numCommitStates; ++i) { |
| 418 // There shouldn't be any drawing regardless of vsync. | 418 // There shouldn't be any drawing regardless of vsync. |
| 419 for (unsigned j = 0; j < 2; ++j) { | 419 for (unsigned j = 0; j < 2; ++j) { |
| 420 StateMachine state; | 420 StateMachine state; |
| 421 state.setCommitState(allCommitStates[i]); | 421 state.setCommitState(allCommitStates[i]); |
| 422 state.setVisible(false); | 422 state.setVisible(false); |
| 423 state.setNeedsRedraw(true); | 423 state.setNeedsRedraw(true); |
| 424 state.setNeedsForcedRedraw(false); | 424 state.setNeedsForcedRedraw(false); |
| 425 if (j == 1) | 425 if (j == 1) |
| 426 state.didEnterVSync(); | 426 state.didEnterVSync(); |
| 427 | 427 |
| 428 // Case 1: needsCommit=false. | 428 // Case 1: needsCommit=false. |
| 429 state.setNeedsCommit(false); | 429 state.setNeedsCommit(false); |
| 430 EXPECT_NE(CCSchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.ne
xtAction()); | 430 EXPECT_NE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.next
Action()); |
| 431 | 431 |
| 432 // Case 2: needsCommit=true. | 432 // Case 2: needsCommit=true. |
| 433 state.setNeedsCommit(true); | 433 state.setNeedsCommit(true); |
| 434 EXPECT_NE(CCSchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.ne
xtAction()); | 434 EXPECT_NE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.next
Action()); |
| 435 } | 435 } |
| 436 } | 436 } |
| 437 } | 437 } |
| 438 | 438 |
| 439 TEST(CCSchedulerStateMachineTest, TestCanRedraw_StopsDraw) | 439 TEST(SchedulerStateMachineTest, TestCanRedraw_StopsDraw) |
| 440 { | 440 { |
| 441 size_t numCommitStates = sizeof(allCommitStates) / sizeof(CCSchedulerStateMa
chine::CommitState); | 441 size_t numCommitStates = sizeof(allCommitStates) / sizeof(SchedulerStateMach
ine::CommitState); |
| 442 for (size_t i = 0; i < numCommitStates; ++i) { | 442 for (size_t i = 0; i < numCommitStates; ++i) { |
| 443 // There shouldn't be any drawing regardless of vsync. | 443 // There shouldn't be any drawing regardless of vsync. |
| 444 for (unsigned j = 0; j < 2; ++j) { | 444 for (unsigned j = 0; j < 2; ++j) { |
| 445 StateMachine state; | 445 StateMachine state; |
| 446 state.setCommitState(allCommitStates[i]); | 446 state.setCommitState(allCommitStates[i]); |
| 447 state.setVisible(false); | 447 state.setVisible(false); |
| 448 state.setNeedsRedraw(true); | 448 state.setNeedsRedraw(true); |
| 449 state.setNeedsForcedRedraw(false); | 449 state.setNeedsForcedRedraw(false); |
| 450 if (j == 1) | 450 if (j == 1) |
| 451 state.didEnterVSync(); | 451 state.didEnterVSync(); |
| 452 | 452 |
| 453 state.setCanDraw(false); | 453 state.setCanDraw(false); |
| 454 EXPECT_NE(CCSchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.ne
xtAction()); | 454 EXPECT_NE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.next
Action()); |
| 455 } | 455 } |
| 456 } | 456 } |
| 457 } | 457 } |
| 458 | 458 |
| 459 TEST(CCSchedulerStateMachineTest, TestCanRedrawWithWaitingForFirstDrawMakesProgr
ess) | 459 TEST(SchedulerStateMachineTest, TestCanRedrawWithWaitingForFirstDrawMakesProgres
s) |
| 460 { | 460 { |
| 461 StateMachine state; | 461 StateMachine state; |
| 462 state.setCommitState(CCSchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST
_DRAW); | 462 state.setCommitState(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_D
RAW); |
| 463 state.setCanBeginFrame(true); | 463 state.setCanBeginFrame(true); |
| 464 state.setNeedsCommit(true); | 464 state.setNeedsCommit(true); |
| 465 state.setNeedsRedraw(true); | 465 state.setNeedsRedraw(true); |
| 466 state.setVisible(true); | 466 state.setVisible(true); |
| 467 state.setCanDraw(false); | 467 state.setCanDraw(false); |
| 468 EXPECT_EQ(CCSchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction()); | 468 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction()); |
| 469 } | 469 } |
| 470 | 470 |
| 471 TEST(CCSchedulerStateMachineTest, TestSetNeedsCommitIsNotLost) | 471 TEST(SchedulerStateMachineTest, TestSetNeedsCommitIsNotLost) |
| 472 { | 472 { |
| 473 StateMachine state; | 473 StateMachine state; |
| 474 state.setCanBeginFrame(true); | 474 state.setCanBeginFrame(true); |
| 475 state.setNeedsCommit(true); | 475 state.setNeedsCommit(true); |
| 476 state.setVisible(true); | 476 state.setVisible(true); |
| 477 state.setCanDraw(true); | 477 state.setCanDraw(true); |
| 478 | 478 |
| 479 // Begin the frame. | 479 // Begin the frame. |
| 480 EXPECT_EQ(CCSchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction()); | 480 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction()); |
| 481 state.updateState(state.nextAction()); | 481 state.updateState(state.nextAction()); |
| 482 EXPECT_EQ(CCSchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, state.com
mitState()); | 482 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, state.commi
tState()); |
| 483 | 483 |
| 484 // Now, while the frame is in progress, set another commit. | 484 // Now, while the frame is in progress, set another commit. |
| 485 state.setNeedsCommit(true); | 485 state.setNeedsCommit(true); |
| 486 EXPECT_TRUE(state.needsCommit()); | 486 EXPECT_TRUE(state.needsCommit()); |
| 487 | 487 |
| 488 // Let the frame finish. | 488 // Let the frame finish. |
| 489 state.beginFrameComplete(); | 489 state.beginFrameComplete(); |
| 490 EXPECT_EQ(CCSchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT, state.commi
tState()); | 490 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT, state.commitS
tate()); |
| 491 | 491 |
| 492 // Expect to commit regardless of vsync state. | 492 // Expect to commit regardless of vsync state. |
| 493 state.didLeaveVSync(); | 493 state.didLeaveVSync(); |
| 494 EXPECT_EQ(CCSchedulerStateMachine::ACTION_COMMIT, state.nextAction()); | 494 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.nextAction()); |
| 495 state.didEnterVSync(); | 495 state.didEnterVSync(); |
| 496 EXPECT_EQ(CCSchedulerStateMachine::ACTION_COMMIT, state.nextAction()); | 496 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.nextAction()); |
| 497 | 497 |
| 498 // Commit and make sure we draw on next vsync | 498 // Commit and make sure we draw on next vsync |
| 499 state.updateState(CCSchedulerStateMachine::ACTION_COMMIT); | 499 state.updateState(SchedulerStateMachine::ACTION_COMMIT); |
| 500 EXPECT_EQ(CCSchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.nextAction
()); | 500 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.nextAction()
); |
| 501 EXPECT_EQ(CCSchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW, stat
e.commitState()); | 501 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW, state.
commitState()); |
| 502 state.updateState(CCSchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE); | 502 state.updateState(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE); |
| 503 state.didDrawIfPossibleCompleted(true); | 503 state.didDrawIfPossibleCompleted(true); |
| 504 | 504 |
| 505 // Verify that another commit will begin. | 505 // Verify that another commit will begin. |
| 506 state.didLeaveVSync(); | 506 state.didLeaveVSync(); |
| 507 EXPECT_EQ(CCSchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction()); | 507 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction()); |
| 508 } | 508 } |
| 509 | 509 |
| 510 TEST(CCSchedulerStateMachineTest, TestFullCycle) | 510 TEST(SchedulerStateMachineTest, TestFullCycle) |
| 511 { | 511 { |
| 512 StateMachine state; | 512 StateMachine state; |
| 513 state.setCanBeginFrame(true); | 513 state.setCanBeginFrame(true); |
| 514 state.setVisible(true); | 514 state.setVisible(true); |
| 515 state.setCanDraw(true); | 515 state.setCanDraw(true); |
| 516 | 516 |
| 517 // Start clean and set commit. | 517 // Start clean and set commit. |
| 518 state.setNeedsCommit(true); | 518 state.setNeedsCommit(true); |
| 519 EXPECT_EQ(CCSchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction()); | 519 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction()); |
| 520 | 520 |
| 521 // Begin the frame. | 521 // Begin the frame. |
| 522 state.updateState(CCSchedulerStateMachine::ACTION_BEGIN_FRAME); | 522 state.updateState(SchedulerStateMachine::ACTION_BEGIN_FRAME); |
| 523 EXPECT_EQ(CCSchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, state.com
mitState()); | 523 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, state.commi
tState()); |
| 524 EXPECT_FALSE(state.needsCommit()); | 524 EXPECT_FALSE(state.needsCommit()); |
| 525 EXPECT_EQ(CCSchedulerStateMachine::ACTION_NONE, state.nextAction()); | 525 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.nextAction()); |
| 526 | 526 |
| 527 // Tell the scheduler the frame finished. | 527 // Tell the scheduler the frame finished. |
| 528 state.beginFrameComplete(); | 528 state.beginFrameComplete(); |
| 529 EXPECT_EQ(CCSchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT, state.commi
tState()); | 529 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT, state.commitS
tate()); |
| 530 EXPECT_EQ(CCSchedulerStateMachine::ACTION_COMMIT, state.nextAction()); | 530 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.nextAction()); |
| 531 | 531 |
| 532 // Commit. | 532 // Commit. |
| 533 state.updateState(CCSchedulerStateMachine::ACTION_COMMIT); | 533 state.updateState(SchedulerStateMachine::ACTION_COMMIT); |
| 534 EXPECT_EQ(CCSchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW, stat
e.commitState()); | 534 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW, state.
commitState()); |
| 535 EXPECT_TRUE(state.needsRedraw()); | 535 EXPECT_TRUE(state.needsRedraw()); |
| 536 | 536 |
| 537 // Expect to do nothing until vsync. | 537 // Expect to do nothing until vsync. |
| 538 EXPECT_EQ(CCSchedulerStateMachine::ACTION_NONE, state.nextAction()); | 538 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.nextAction()); |
| 539 | 539 |
| 540 // At vsync, draw. | 540 // At vsync, draw. |
| 541 state.didEnterVSync(); | 541 state.didEnterVSync(); |
| 542 EXPECT_EQ(CCSchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.nextAction
()); | 542 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.nextAction()
); |
| 543 state.updateState(CCSchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE); | 543 state.updateState(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE); |
| 544 state.didDrawIfPossibleCompleted(true); | 544 state.didDrawIfPossibleCompleted(true); |
| 545 state.didLeaveVSync(); | 545 state.didLeaveVSync(); |
| 546 | 546 |
| 547 // Should be synchronized, no draw needed, no action needed. | 547 // Should be synchronized, no draw needed, no action needed. |
| 548 EXPECT_EQ(CCSchedulerStateMachine::COMMIT_STATE_IDLE, state.commitState()); | 548 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.commitState()); |
| 549 EXPECT_FALSE(state.needsRedraw()); | 549 EXPECT_FALSE(state.needsRedraw()); |
| 550 EXPECT_EQ(CCSchedulerStateMachine::ACTION_NONE, state.nextAction()); | 550 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.nextAction()); |
| 551 } | 551 } |
| 552 | 552 |
| 553 TEST(CCSchedulerStateMachineTest, TestFullCycleWithCommitRequestInbetween) | 553 TEST(SchedulerStateMachineTest, TestFullCycleWithCommitRequestInbetween) |
| 554 { | 554 { |
| 555 StateMachine state; | 555 StateMachine state; |
| 556 state.setCanBeginFrame(true); | 556 state.setCanBeginFrame(true); |
| 557 state.setVisible(true); | 557 state.setVisible(true); |
| 558 state.setCanDraw(true); | 558 state.setCanDraw(true); |
| 559 | 559 |
| 560 // Start clean and set commit. | 560 // Start clean and set commit. |
| 561 state.setNeedsCommit(true); | 561 state.setNeedsCommit(true); |
| 562 EXPECT_EQ(CCSchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction()); | 562 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction()); |
| 563 | 563 |
| 564 // Begin the frame. | 564 // Begin the frame. |
| 565 state.updateState(CCSchedulerStateMachine::ACTION_BEGIN_FRAME); | 565 state.updateState(SchedulerStateMachine::ACTION_BEGIN_FRAME); |
| 566 EXPECT_EQ(CCSchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, state.com
mitState()); | 566 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, state.commi
tState()); |
| 567 EXPECT_FALSE(state.needsCommit()); | 567 EXPECT_FALSE(state.needsCommit()); |
| 568 EXPECT_EQ(CCSchedulerStateMachine::ACTION_NONE, state.nextAction()); | 568 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.nextAction()); |
| 569 | 569 |
| 570 // Request another commit while the commit is in flight. | 570 // Request another commit while the commit is in flight. |
| 571 state.setNeedsCommit(true); | 571 state.setNeedsCommit(true); |
| 572 EXPECT_EQ(CCSchedulerStateMachine::ACTION_NONE, state.nextAction()); | 572 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.nextAction()); |
| 573 | 573 |
| 574 // Tell the scheduler the frame finished. | 574 // Tell the scheduler the frame finished. |
| 575 state.beginFrameComplete(); | 575 state.beginFrameComplete(); |
| 576 EXPECT_EQ(CCSchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT, state.commi
tState()); | 576 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT, state.commitS
tate()); |
| 577 EXPECT_EQ(CCSchedulerStateMachine::ACTION_COMMIT, state.nextAction()); | 577 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.nextAction()); |
| 578 | 578 |
| 579 // Commit. | 579 // Commit. |
| 580 state.updateState(CCSchedulerStateMachine::ACTION_COMMIT); | 580 state.updateState(SchedulerStateMachine::ACTION_COMMIT); |
| 581 EXPECT_EQ(CCSchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW, stat
e.commitState()); | 581 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW, state.
commitState()); |
| 582 EXPECT_TRUE(state.needsRedraw()); | 582 EXPECT_TRUE(state.needsRedraw()); |
| 583 | 583 |
| 584 // Expect to do nothing until vsync. | 584 // Expect to do nothing until vsync. |
| 585 EXPECT_EQ(CCSchedulerStateMachine::ACTION_NONE, state.nextAction()); | 585 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.nextAction()); |
| 586 | 586 |
| 587 // At vsync, draw. | 587 // At vsync, draw. |
| 588 state.didEnterVSync(); | 588 state.didEnterVSync(); |
| 589 EXPECT_EQ(CCSchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.nextAction
()); | 589 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.nextAction()
); |
| 590 state.updateState(CCSchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE); | 590 state.updateState(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE); |
| 591 state.didDrawIfPossibleCompleted(true); | 591 state.didDrawIfPossibleCompleted(true); |
| 592 state.didLeaveVSync(); | 592 state.didLeaveVSync(); |
| 593 | 593 |
| 594 // Should be synchronized, no draw needed, no action needed. | 594 // Should be synchronized, no draw needed, no action needed. |
| 595 EXPECT_EQ(CCSchedulerStateMachine::COMMIT_STATE_IDLE, state.commitState()); | 595 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.commitState()); |
| 596 EXPECT_FALSE(state.needsRedraw()); | 596 EXPECT_FALSE(state.needsRedraw()); |
| 597 EXPECT_EQ(CCSchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction()); | 597 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction()); |
| 598 } | 598 } |
| 599 | 599 |
| 600 TEST(CCSchedulerStateMachineTest, TestRequestCommitInvisible) | 600 TEST(SchedulerStateMachineTest, TestRequestCommitInvisible) |
| 601 { | 601 { |
| 602 StateMachine state; | 602 StateMachine state; |
| 603 state.setNeedsCommit(true); | 603 state.setNeedsCommit(true); |
| 604 EXPECT_EQ(CCSchedulerStateMachine::ACTION_NONE, state.nextAction()); | 604 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.nextAction()); |
| 605 } | 605 } |
| 606 | 606 |
| 607 TEST(CCSchedulerStateMachineTest, TestGoesInvisibleBeforeBeginFrameCompletes) | 607 TEST(SchedulerStateMachineTest, TestGoesInvisibleBeforeBeginFrameCompletes) |
| 608 { | 608 { |
| 609 StateMachine state; | 609 StateMachine state; |
| 610 state.setCanBeginFrame(true); | 610 state.setCanBeginFrame(true); |
| 611 state.setVisible(true); | 611 state.setVisible(true); |
| 612 state.setCanDraw(true); | 612 state.setCanDraw(true); |
| 613 | 613 |
| 614 // Start clean and set commit. | 614 // Start clean and set commit. |
| 615 state.setNeedsCommit(true); | 615 state.setNeedsCommit(true); |
| 616 EXPECT_EQ(CCSchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction()); | 616 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction()); |
| 617 | 617 |
| 618 // Begin the frame while visible. | 618 // Begin the frame while visible. |
| 619 state.updateState(CCSchedulerStateMachine::ACTION_BEGIN_FRAME); | 619 state.updateState(SchedulerStateMachine::ACTION_BEGIN_FRAME); |
| 620 EXPECT_EQ(CCSchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, state.com
mitState()); | 620 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, state.commi
tState()); |
| 621 EXPECT_FALSE(state.needsCommit()); | 621 EXPECT_FALSE(state.needsCommit()); |
| 622 EXPECT_EQ(CCSchedulerStateMachine::ACTION_NONE, state.nextAction()); | 622 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.nextAction()); |
| 623 | 623 |
| 624 // Become invisible and abort the beginFrame. | 624 // Become invisible and abort the beginFrame. |
| 625 state.setVisible(false); | 625 state.setVisible(false); |
| 626 state.beginFrameAborted(); | 626 state.beginFrameAborted(); |
| 627 | 627 |
| 628 // We should now be back in the idle state as if we didn't start a frame at
all. | 628 // We should now be back in the idle state as if we didn't start a frame at
all. |
| 629 EXPECT_EQ(CCSchedulerStateMachine::COMMIT_STATE_IDLE, state.commitState()); | 629 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.commitState()); |
| 630 EXPECT_EQ(CCSchedulerStateMachine::ACTION_NONE, state.nextAction()); | 630 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.nextAction()); |
| 631 | 631 |
| 632 // Become visible again | 632 // Become visible again |
| 633 state.setVisible(true); | 633 state.setVisible(true); |
| 634 | 634 |
| 635 // We should be beginning a frame now | 635 // We should be beginning a frame now |
| 636 EXPECT_EQ(CCSchedulerStateMachine::COMMIT_STATE_IDLE, state.commitState()); | 636 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.commitState()); |
| 637 EXPECT_EQ(CCSchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction()); | 637 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction()); |
| 638 | 638 |
| 639 // Begin the frame | 639 // Begin the frame |
| 640 state.updateState(state.nextAction()); | 640 state.updateState(state.nextAction()); |
| 641 | 641 |
| 642 // We should be starting the commit now | 642 // We should be starting the commit now |
| 643 EXPECT_EQ(CCSchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, state.com
mitState()); | 643 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, state.commi
tState()); |
| 644 } | 644 } |
| 645 | 645 |
| 646 TEST(CCSchedulerStateMachineTest, TestContextLostWhenCompletelyIdle) | 646 TEST(SchedulerStateMachineTest, TestContextLostWhenCompletelyIdle) |
| 647 { | 647 { |
| 648 StateMachine state; | 648 StateMachine state; |
| 649 state.setCanBeginFrame(true); | 649 state.setCanBeginFrame(true); |
| 650 state.setVisible(true); | 650 state.setVisible(true); |
| 651 state.setCanDraw(true); | 651 state.setCanDraw(true); |
| 652 | 652 |
| 653 state.didLoseContext(); | 653 state.didLoseContext(); |
| 654 | 654 |
| 655 EXPECT_EQ(CCSchedulerStateMachine::ACTION_BEGIN_CONTEXT_RECREATION, state.ne
xtAction()); | 655 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_CONTEXT_RECREATION, state.next
Action()); |
| 656 state.updateState(state.nextAction()); | 656 state.updateState(state.nextAction()); |
| 657 | 657 |
| 658 // Once context recreation begins, nothing should happen. | 658 // Once context recreation begins, nothing should happen. |
| 659 EXPECT_EQ(CCSchedulerStateMachine::ACTION_NONE, state.nextAction()); | 659 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.nextAction()); |
| 660 | 660 |
| 661 // Recreate the context | 661 // Recreate the context |
| 662 state.didRecreateContext(); | 662 state.didRecreateContext(); |
| 663 | 663 |
| 664 // When the context is recreated, we should begin a commit | 664 // When the context is recreated, we should begin a commit |
| 665 EXPECT_EQ(CCSchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction()); | 665 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction()); |
| 666 state.updateState(state.nextAction()); | 666 state.updateState(state.nextAction()); |
| 667 } | 667 } |
| 668 | 668 |
| 669 TEST(CCSchedulerStateMachineTest, TestContextLostWhenIdleAndCommitRequestedWhile
Recreating) | 669 TEST(SchedulerStateMachineTest, TestContextLostWhenIdleAndCommitRequestedWhileRe
creating) |
| 670 { | 670 { |
| 671 StateMachine state; | 671 StateMachine state; |
| 672 state.setCanBeginFrame(true); | 672 state.setCanBeginFrame(true); |
| 673 state.setVisible(true); | 673 state.setVisible(true); |
| 674 state.setCanDraw(true); | 674 state.setCanDraw(true); |
| 675 | 675 |
| 676 state.didLoseContext(); | 676 state.didLoseContext(); |
| 677 | 677 |
| 678 EXPECT_EQ(CCSchedulerStateMachine::ACTION_BEGIN_CONTEXT_RECREATION, state.ne
xtAction()); | 678 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_CONTEXT_RECREATION, state.next
Action()); |
| 679 state.updateState(state.nextAction()); | 679 state.updateState(state.nextAction()); |
| 680 | 680 |
| 681 // Once context recreation begins, nothing should happen. | 681 // Once context recreation begins, nothing should happen. |
| 682 EXPECT_EQ(CCSchedulerStateMachine::ACTION_NONE, state.nextAction()); | 682 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.nextAction()); |
| 683 | 683 |
| 684 // While context is recreating, commits shouldn't begin. | 684 // While context is recreating, commits shouldn't begin. |
| 685 state.setNeedsCommit(true); | 685 state.setNeedsCommit(true); |
| 686 EXPECT_EQ(CCSchedulerStateMachine::ACTION_NONE, state.nextAction()); | 686 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.nextAction()); |
| 687 | 687 |
| 688 // Recreate the context | 688 // Recreate the context |
| 689 state.didRecreateContext(); | 689 state.didRecreateContext(); |
| 690 | 690 |
| 691 // When the context is recreated, we should begin a commit | 691 // When the context is recreated, we should begin a commit |
| 692 EXPECT_EQ(CCSchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction()); | 692 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction()); |
| 693 state.updateState(state.nextAction()); | 693 state.updateState(state.nextAction()); |
| 694 | 694 |
| 695 // Once the context is recreated, whether we draw should be based on | 695 // Once the context is recreated, whether we draw should be based on |
| 696 // setCanDraw. | 696 // setCanDraw. |
| 697 state.setNeedsRedraw(true); | 697 state.setNeedsRedraw(true); |
| 698 state.didEnterVSync(); | 698 state.didEnterVSync(); |
| 699 EXPECT_EQ(CCSchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.nextAction
()); | 699 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.nextAction()
); |
| 700 state.setCanDraw(false); | 700 state.setCanDraw(false); |
| 701 EXPECT_EQ(CCSchedulerStateMachine::ACTION_NONE, state.nextAction()); | 701 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.nextAction()); |
| 702 state.setCanDraw(true); | 702 state.setCanDraw(true); |
| 703 state.didLeaveVSync(); | 703 state.didLeaveVSync(); |
| 704 } | 704 } |
| 705 | 705 |
| 706 TEST(CCSchedulerStateMachineTest, TestContextLostWhileCommitInProgress) | 706 TEST(SchedulerStateMachineTest, TestContextLostWhileCommitInProgress) |
| 707 { | 707 { |
| 708 StateMachine state; | 708 StateMachine state; |
| 709 state.setCanBeginFrame(true); | 709 state.setCanBeginFrame(true); |
| 710 state.setVisible(true); | 710 state.setVisible(true); |
| 711 state.setCanDraw(true); | 711 state.setCanDraw(true); |
| 712 | 712 |
| 713 // Get a commit in flight. | 713 // Get a commit in flight. |
| 714 state.setNeedsCommit(true); | 714 state.setNeedsCommit(true); |
| 715 EXPECT_EQ(CCSchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction()); | 715 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction()); |
| 716 state.updateState(state.nextAction()); | 716 state.updateState(state.nextAction()); |
| 717 | 717 |
| 718 // Set damage and expect a draw. | 718 // Set damage and expect a draw. |
| 719 state.setNeedsRedraw(true); | 719 state.setNeedsRedraw(true); |
| 720 state.didEnterVSync(); | 720 state.didEnterVSync(); |
| 721 EXPECT_EQ(CCSchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.nextAction
()); | 721 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.nextAction()
); |
| 722 state.updateState(state.nextAction()); | 722 state.updateState(state.nextAction()); |
| 723 state.didLeaveVSync(); | 723 state.didLeaveVSync(); |
| 724 | 724 |
| 725 // Cause a lost context while the begin frame is in flight. | 725 // Cause a lost context while the begin frame is in flight. |
| 726 state.didLoseContext(); | 726 state.didLoseContext(); |
| 727 | 727 |
| 728 // Ask for another draw. Expect nothing happens. | 728 // Ask for another draw. Expect nothing happens. |
| 729 state.setNeedsRedraw(true); | 729 state.setNeedsRedraw(true); |
| 730 EXPECT_EQ(CCSchedulerStateMachine::ACTION_NONE, state.nextAction()); | 730 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.nextAction()); |
| 731 | 731 |
| 732 // Finish the frame, and commit. | 732 // Finish the frame, and commit. |
| 733 state.beginFrameComplete(); | 733 state.beginFrameComplete(); |
| 734 EXPECT_EQ(CCSchedulerStateMachine::ACTION_COMMIT, state.nextAction()); | 734 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.nextAction()); |
| 735 state.updateState(state.nextAction()); | 735 state.updateState(state.nextAction()); |
| 736 | 736 |
| 737 EXPECT_EQ(CCSchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW, stat
e.commitState()); | 737 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW, state.
commitState()); |
| 738 | 738 |
| 739 EXPECT_EQ(CCSchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.nextAction
()); | 739 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.nextAction()
); |
| 740 state.updateState(state.nextAction()); | 740 state.updateState(state.nextAction()); |
| 741 | 741 |
| 742 // Expect to be told to begin context recreation, independent of vsync state | 742 // Expect to be told to begin context recreation, independent of vsync state |
| 743 state.didEnterVSync(); | 743 state.didEnterVSync(); |
| 744 EXPECT_EQ(CCSchedulerStateMachine::ACTION_BEGIN_CONTEXT_RECREATION, state.ne
xtAction()); | 744 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_CONTEXT_RECREATION, state.next
Action()); |
| 745 state.didLeaveVSync(); | 745 state.didLeaveVSync(); |
| 746 EXPECT_EQ(CCSchedulerStateMachine::ACTION_BEGIN_CONTEXT_RECREATION, state.ne
xtAction()); | 746 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_CONTEXT_RECREATION, state.next
Action()); |
| 747 } | 747 } |
| 748 | 748 |
| 749 TEST(CCSchedulerStateMachineTest, TestContextLostWhileCommitInProgressAndAnother
CommitRequested) | 749 TEST(SchedulerStateMachineTest, TestContextLostWhileCommitInProgressAndAnotherCo
mmitRequested) |
| 750 { | 750 { |
| 751 StateMachine state; | 751 StateMachine state; |
| 752 state.setCanBeginFrame(true); | 752 state.setCanBeginFrame(true); |
| 753 state.setVisible(true); | 753 state.setVisible(true); |
| 754 state.setCanDraw(true); | 754 state.setCanDraw(true); |
| 755 | 755 |
| 756 // Get a commit in flight. | 756 // Get a commit in flight. |
| 757 state.setNeedsCommit(true); | 757 state.setNeedsCommit(true); |
| 758 EXPECT_EQ(CCSchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction()); | 758 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction()); |
| 759 state.updateState(state.nextAction()); | 759 state.updateState(state.nextAction()); |
| 760 | 760 |
| 761 // Set damage and expect a draw. | 761 // Set damage and expect a draw. |
| 762 state.setNeedsRedraw(true); | 762 state.setNeedsRedraw(true); |
| 763 state.didEnterVSync(); | 763 state.didEnterVSync(); |
| 764 EXPECT_EQ(CCSchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.nextAction
()); | 764 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.nextAction()
); |
| 765 state.updateState(state.nextAction()); | 765 state.updateState(state.nextAction()); |
| 766 state.didLeaveVSync(); | 766 state.didLeaveVSync(); |
| 767 | 767 |
| 768 // Cause a lost context while the begin frame is in flight. | 768 // Cause a lost context while the begin frame is in flight. |
| 769 state.didLoseContext(); | 769 state.didLoseContext(); |
| 770 | 770 |
| 771 // Ask for another draw and also set needs commit. Expect nothing happens. | 771 // Ask for another draw and also set needs commit. Expect nothing happens. |
| 772 state.setNeedsRedraw(true); | 772 state.setNeedsRedraw(true); |
| 773 state.setNeedsCommit(true); | 773 state.setNeedsCommit(true); |
| 774 EXPECT_EQ(CCSchedulerStateMachine::ACTION_NONE, state.nextAction()); | 774 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.nextAction()); |
| 775 | 775 |
| 776 // Finish the frame, and commit. | 776 // Finish the frame, and commit. |
| 777 state.beginFrameComplete(); | 777 state.beginFrameComplete(); |
| 778 EXPECT_EQ(CCSchedulerStateMachine::ACTION_COMMIT, state.nextAction()); | 778 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.nextAction()); |
| 779 state.updateState(state.nextAction()); | 779 state.updateState(state.nextAction()); |
| 780 | 780 |
| 781 EXPECT_EQ(CCSchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW, stat
e.commitState()); | 781 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW, state.
commitState()); |
| 782 | 782 |
| 783 EXPECT_EQ(CCSchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.nextAction
()); | 783 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.nextAction()
); |
| 784 state.updateState(state.nextAction()); | 784 state.updateState(state.nextAction()); |
| 785 | 785 |
| 786 // Expect to be told to begin context recreation, independent of vsync state | 786 // Expect to be told to begin context recreation, independent of vsync state |
| 787 state.didEnterVSync(); | 787 state.didEnterVSync(); |
| 788 EXPECT_EQ(CCSchedulerStateMachine::ACTION_BEGIN_CONTEXT_RECREATION, state.ne
xtAction()); | 788 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_CONTEXT_RECREATION, state.next
Action()); |
| 789 state.didLeaveVSync(); | 789 state.didLeaveVSync(); |
| 790 EXPECT_EQ(CCSchedulerStateMachine::ACTION_BEGIN_CONTEXT_RECREATION, state.ne
xtAction()); | 790 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_CONTEXT_RECREATION, state.next
Action()); |
| 791 } | 791 } |
| 792 | 792 |
| 793 | 793 |
| 794 TEST(CCSchedulerStateMachineTest, TestFinishAllRenderingWhileContextLost) | 794 TEST(SchedulerStateMachineTest, TestFinishAllRenderingWhileContextLost) |
| 795 { | 795 { |
| 796 StateMachine state; | 796 StateMachine state; |
| 797 state.setVisible(true); | 797 state.setVisible(true); |
| 798 state.setCanDraw(true); | 798 state.setCanDraw(true); |
| 799 | 799 |
| 800 // Cause a lost context lost. | 800 // Cause a lost context lost. |
| 801 state.didLoseContext(); | 801 state.didLoseContext(); |
| 802 | 802 |
| 803 // Ask a forced redraw and verify it ocurrs. | 803 // Ask a forced redraw and verify it ocurrs. |
| 804 state.setNeedsForcedRedraw(true); | 804 state.setNeedsForcedRedraw(true); |
| 805 state.didEnterVSync(); | 805 state.didEnterVSync(); |
| 806 EXPECT_EQ(CCSchedulerStateMachine::ACTION_DRAW_FORCED, state.nextAction()); | 806 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_FORCED, state.nextAction()); |
| 807 state.didLeaveVSync(); | 807 state.didLeaveVSync(); |
| 808 | 808 |
| 809 // Clear the forced redraw bit. | 809 // Clear the forced redraw bit. |
| 810 state.setNeedsForcedRedraw(false); | 810 state.setNeedsForcedRedraw(false); |
| 811 | 811 |
| 812 // Expect to be told to begin context recreation, independent of vsync state | 812 // Expect to be told to begin context recreation, independent of vsync state |
| 813 EXPECT_EQ(CCSchedulerStateMachine::ACTION_BEGIN_CONTEXT_RECREATION, state.ne
xtAction()); | 813 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_CONTEXT_RECREATION, state.next
Action()); |
| 814 state.updateState(state.nextAction()); | 814 state.updateState(state.nextAction()); |
| 815 | 815 |
| 816 // Ask a forced redraw and verify it ocurrs. | 816 // Ask a forced redraw and verify it ocurrs. |
| 817 state.setNeedsForcedRedraw(true); | 817 state.setNeedsForcedRedraw(true); |
| 818 state.didEnterVSync(); | 818 state.didEnterVSync(); |
| 819 EXPECT_EQ(CCSchedulerStateMachine::ACTION_DRAW_FORCED, state.nextAction()); | 819 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_FORCED, state.nextAction()); |
| 820 state.didLeaveVSync(); | 820 state.didLeaveVSync(); |
| 821 } | 821 } |
| 822 | 822 |
| 823 TEST(CCSchedulerStateMachineTest, TestBeginFrameWhenInvisibleAndForceCommit) | 823 TEST(SchedulerStateMachineTest, TestBeginFrameWhenInvisibleAndForceCommit) |
| 824 { | 824 { |
| 825 StateMachine state; | 825 StateMachine state; |
| 826 state.setCanBeginFrame(true); | 826 state.setCanBeginFrame(true); |
| 827 state.setVisible(false); | 827 state.setVisible(false); |
| 828 state.setNeedsCommit(true); | 828 state.setNeedsCommit(true); |
| 829 state.setNeedsForcedCommit(true); | 829 state.setNeedsForcedCommit(true); |
| 830 EXPECT_EQ(CCSchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction()); | 830 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction()); |
| 831 } | 831 } |
| 832 | 832 |
| 833 TEST(CCSchedulerStateMachineTest, TestBeginFrameWhenCanBeginFrameFalseAndForceCo
mmit) | 833 TEST(SchedulerStateMachineTest, TestBeginFrameWhenCanBeginFrameFalseAndForceComm
it) |
| 834 { | 834 { |
| 835 StateMachine state; | 835 StateMachine state; |
| 836 state.setVisible(true); | 836 state.setVisible(true); |
| 837 state.setCanDraw(true); | 837 state.setCanDraw(true); |
| 838 state.setNeedsCommit(true); | 838 state.setNeedsCommit(true); |
| 839 state.setNeedsForcedCommit(true); | 839 state.setNeedsForcedCommit(true); |
| 840 EXPECT_EQ(CCSchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction()); | 840 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction()); |
| 841 } | 841 } |
| 842 | 842 |
| 843 TEST(CCSchedulerStateMachineTest, TestBeginFrameWhenCommitInProgress) | 843 TEST(SchedulerStateMachineTest, TestBeginFrameWhenCommitInProgress) |
| 844 { | 844 { |
| 845 StateMachine state; | 845 StateMachine state; |
| 846 state.setCanBeginFrame(true); | 846 state.setCanBeginFrame(true); |
| 847 state.setVisible(false); | 847 state.setVisible(false); |
| 848 state.setCommitState(CCSchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS
); | 848 state.setCommitState(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS); |
| 849 state.setNeedsCommit(true); | 849 state.setNeedsCommit(true); |
| 850 state.setNeedsForcedCommit(true); | 850 state.setNeedsForcedCommit(true); |
| 851 | 851 |
| 852 state.beginFrameComplete(); | 852 state.beginFrameComplete(); |
| 853 EXPECT_EQ(CCSchedulerStateMachine::ACTION_COMMIT, state.nextAction()); | 853 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.nextAction()); |
| 854 state.updateState(state.nextAction()); | 854 state.updateState(state.nextAction()); |
| 855 | 855 |
| 856 EXPECT_EQ(CCSchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW, stat
e.commitState()); | 856 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW, state.
commitState()); |
| 857 | 857 |
| 858 EXPECT_EQ(CCSchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction()); | 858 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction()); |
| 859 } | 859 } |
| 860 | 860 |
| 861 TEST(CCSchedulerStateMachineTest, TestBeginFrameWhenContextLost) | 861 TEST(SchedulerStateMachineTest, TestBeginFrameWhenContextLost) |
| 862 { | 862 { |
| 863 StateMachine state; | 863 StateMachine state; |
| 864 state.setCanBeginFrame(true); | 864 state.setCanBeginFrame(true); |
| 865 state.setVisible(true); | 865 state.setVisible(true); |
| 866 state.setCanDraw(true); | 866 state.setCanDraw(true); |
| 867 state.setNeedsCommit(true); | 867 state.setNeedsCommit(true); |
| 868 state.setNeedsForcedCommit(true); | 868 state.setNeedsForcedCommit(true); |
| 869 state.didLoseContext(); | 869 state.didLoseContext(); |
| 870 EXPECT_EQ(CCSchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction()); | 870 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction()); |
| 871 } | 871 } |
| 872 | 872 |
| 873 } | 873 } |
| OLD | NEW |