| OLD | NEW |
| 1 // Copyright 2011 The Chromium Authors. All rights reserved. | 1 // Copyright 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "cc/scheduler/scheduler_state_machine.h" | 5 #include "cc/scheduler/scheduler_state_machine.h" |
| 6 | 6 |
| 7 #include "cc/scheduler/scheduler.h" | 7 #include "cc/scheduler/scheduler.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 | 9 |
| 10 #define EXPECT_ACTION_UPDATE_STATE(action) \ |
| 11 EXPECT_EQ(action, state.NextAction()) << state.ToString(); \ |
| 12 if (action == SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE || \ |
| 13 action == SchedulerStateMachine::ACTION_DRAW_AND_SWAP_FORCED) { \ |
| 14 if (SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW == \ |
| 15 state.CommitState() && \ |
| 16 SchedulerStateMachine::OUTPUT_SURFACE_ACTIVE != \ |
| 17 state.output_surface_state()) \ |
| 18 return; \ |
| 19 EXPECT_EQ(SchedulerStateMachine::BEGIN_FRAME_STATE_INSIDE_DEADLINE, \ |
| 20 state.begin_frame_state()) << state.ToString(); \ |
| 21 } \ |
| 22 state.UpdateState(action); \ |
| 23 if (action == SchedulerStateMachine::ACTION_NONE) { \ |
| 24 state.AdvanceBeginFrameStateWhenNoActionsRemain(); \ |
| 25 } |
| 26 |
| 10 namespace cc { | 27 namespace cc { |
| 11 | 28 |
| 12 namespace { | 29 namespace { |
| 13 | 30 |
| 31 const SchedulerStateMachine::BeginFrameState all_begin_frame_states[] = { |
| 32 SchedulerStateMachine::BEGIN_FRAME_STATE_IDLE, |
| 33 SchedulerStateMachine::BEGIN_FRAME_STATE_INSIDE_BEGIN_FRAME, |
| 34 SchedulerStateMachine::BEGIN_FRAME_STATE_DEADLINE_PENDING, |
| 35 SchedulerStateMachine::BEGIN_FRAME_STATE_INSIDE_DEADLINE, |
| 36 }; |
| 37 |
| 14 const SchedulerStateMachine::CommitState all_commit_states[] = { | 38 const SchedulerStateMachine::CommitState all_commit_states[] = { |
| 15 SchedulerStateMachine::COMMIT_STATE_IDLE, | 39 SchedulerStateMachine::COMMIT_STATE_IDLE, |
| 16 SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, | 40 SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, |
| 17 SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT, | 41 SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT, |
| 18 SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW | 42 SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_ACTIVATION, |
| 43 SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW, |
| 19 }; | 44 }; |
| 20 | 45 |
| 21 // Exposes the protected state fields of the SchedulerStateMachine for testing | 46 // Exposes the protected state fields of the SchedulerStateMachine for testing |
| 22 class StateMachine : public SchedulerStateMachine { | 47 class StateMachine : public SchedulerStateMachine { |
| 23 public: | 48 public: |
| 24 explicit StateMachine(const SchedulerSettings& scheduler_settings) | 49 explicit StateMachine(const SchedulerSettings& scheduler_settings) |
| 25 : SchedulerStateMachine(scheduler_settings) {} | 50 : SchedulerStateMachine(scheduler_settings) {} |
| 26 void SetCommitState(CommitState cs) { commit_state_ = cs; } | 51 void SetCommitState(CommitState cs) { commit_state_ = cs; } |
| 27 CommitState CommitState() const { return commit_state_; } | 52 CommitState CommitState() const { return commit_state_; } |
| 28 | 53 |
| 54 void SetBeginFrameState(BeginFrameState bfs) { begin_frame_state_ = bfs; } |
| 55 BeginFrameState begin_frame_state() const { return begin_frame_state_; } |
| 56 |
| 57 OutputSurfaceState output_surface_state() { |
| 58 return output_surface_state_; |
| 59 } |
| 60 |
| 29 bool NeedsCommit() const { return needs_commit_; } | 61 bool NeedsCommit() const { return needs_commit_; } |
| 30 | 62 |
| 31 void SetNeedsRedraw(bool b) { needs_redraw_ = b; } | 63 void SetNeedsRedraw(bool b) { needs_redraw_ = b; } |
| 32 bool NeedsRedraw() const { return needs_redraw_; } | 64 bool NeedsRedraw() const { return needs_redraw_; } |
| 33 | 65 |
| 34 void SetNeedsForcedRedraw(bool b) { needs_forced_redraw_ = b; } | 66 void SetNeedsForcedRedrawForTimeout(bool b) { |
| 35 bool NeedsForcedRedraw() const { return needs_forced_redraw_; } | 67 forced_redraw_state_ = FORCED_REDRAW_STATE_WAITING_FOR_COMMIT; |
| 68 } |
| 69 bool NeedsForcedRedrawForTimeout() const { |
| 70 return forced_redraw_state_ != FORCED_REDRAW_STATE_IDLE; |
| 71 } |
| 72 |
| 73 void SetNeedsForcedRedrawForReadback() { |
| 74 readback_state_ = READBACK_STATE_WAITING_FOR_DRAW_AND_READBACK; |
| 75 } |
| 76 |
| 77 bool NeedsForcedRedrawForReadback() const { |
| 78 return readback_state_ != READBACK_STATE_IDLE; |
| 79 } |
| 36 | 80 |
| 37 bool CanDraw() const { return can_draw_; } | 81 bool CanDraw() const { return can_draw_; } |
| 38 bool Visible() const { return visible_; } | 82 bool Visible() const { return visible_; } |
| 39 }; | 83 }; |
| 40 | 84 |
| 41 TEST(SchedulerStateMachineTest, TestNextActionBeginsMainFrameIfNeeded) { | 85 TEST(SchedulerStateMachineTest, TestNextActionBeginsMainFrameIfNeeded) { |
| 42 SchedulerSettings default_scheduler_settings; | 86 SchedulerSettings default_scheduler_settings; |
| 43 | 87 |
| 44 // If no commit needed, do nothing. | 88 // If no commit needed, do nothing. |
| 45 { | 89 { |
| 46 StateMachine state(default_scheduler_settings); | 90 StateMachine state(default_scheduler_settings); |
| 47 state.SetCanStart(); | 91 state.SetCanStart(); |
| 48 state.UpdateState(state.NextAction()); | 92 state.UpdateState(state.NextAction()); |
| 49 state.DidCreateAndInitializeOutputSurface(); | 93 state.DidCreateAndInitializeOutputSurface(); |
| 50 state.SetCommitState(SchedulerStateMachine::COMMIT_STATE_IDLE); | 94 state.SetCommitState(SchedulerStateMachine::COMMIT_STATE_IDLE); |
| 51 state.SetNeedsRedraw(false); | 95 state.SetNeedsRedraw(false); |
| 52 state.SetVisible(true); | 96 state.SetVisible(true); |
| 53 | 97 |
| 54 EXPECT_FALSE(state.BeginFrameNeededToDrawByImplThread()); | 98 EXPECT_FALSE(state.BeginFrameNeededByImplThread()); |
| 55 | 99 |
| 56 state.DidLeaveBeginFrame(); | 100 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 57 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); | 101 EXPECT_FALSE(state.BeginFrameNeededByImplThread()); |
| 58 EXPECT_FALSE(state.BeginFrameNeededToDrawByImplThread()); | 102 state.OnBeginFrame(BeginFrameArgs::CreateForTesting()); |
| 59 state.DidEnterBeginFrame(BeginFrameArgs::CreateForTesting()); | 103 |
| 60 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); | 104 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 105 state.OnBeginFrameDeadline(); |
| 61 } | 106 } |
| 62 | 107 |
| 63 // If commit requested but can_start is still false, do nothing. | 108 // If commit requested but can_start is still false, do nothing. |
| 64 { | 109 { |
| 65 StateMachine state(default_scheduler_settings); | 110 StateMachine state(default_scheduler_settings); |
| 66 state.SetCommitState(SchedulerStateMachine::COMMIT_STATE_IDLE); | 111 state.SetCommitState(SchedulerStateMachine::COMMIT_STATE_IDLE); |
| 67 state.SetNeedsRedraw(false); | 112 state.SetNeedsRedraw(false); |
| 68 state.SetVisible(true); | 113 state.SetVisible(true); |
| 69 | 114 |
| 70 EXPECT_FALSE(state.BeginFrameNeededToDrawByImplThread()); | 115 EXPECT_FALSE(state.BeginFrameNeededByImplThread()); |
| 71 | 116 |
| 72 state.DidLeaveBeginFrame(); | 117 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 73 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); | 118 EXPECT_FALSE(state.BeginFrameNeededByImplThread()); |
| 74 EXPECT_FALSE(state.BeginFrameNeededToDrawByImplThread()); | 119 state.OnBeginFrame(BeginFrameArgs::CreateForTesting()); |
| 75 state.DidEnterBeginFrame(BeginFrameArgs::CreateForTesting()); | 120 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 76 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); | 121 state.OnBeginFrameDeadline(); |
| 77 } | 122 } |
| 78 | 123 |
| 79 // If commit requested, begin a main frame. | 124 // If commit requested, begin a main frame. |
| 80 { | 125 { |
| 81 StateMachine state(default_scheduler_settings); | 126 StateMachine state(default_scheduler_settings); |
| 82 state.SetCommitState(SchedulerStateMachine::COMMIT_STATE_IDLE); | 127 state.SetCommitState(SchedulerStateMachine::COMMIT_STATE_IDLE); |
| 83 state.SetCanStart(); | 128 state.SetCanStart(); |
| 84 state.SetNeedsRedraw(false); | 129 state.SetNeedsRedraw(false); |
| 85 state.SetVisible(true); | 130 state.SetVisible(true); |
| 86 EXPECT_FALSE(state.BeginFrameNeededToDrawByImplThread()); | 131 EXPECT_FALSE(state.BeginFrameNeededByImplThread()); |
| 87 } | 132 } |
| 88 | 133 |
| 89 // Begin the frame, make sure needs_commit and commit_state update correctly. | 134 // Begin the frame, make sure needs_commit and commit_state update correctly. |
| 90 { | 135 { |
| 91 StateMachine state(default_scheduler_settings); | 136 StateMachine state(default_scheduler_settings); |
| 92 state.SetCanStart(); | 137 state.SetCanStart(); |
| 93 state.UpdateState(state.NextAction()); | 138 state.UpdateState(state.NextAction()); |
| 94 state.DidCreateAndInitializeOutputSurface(); | 139 state.DidCreateAndInitializeOutputSurface(); |
| 95 state.SetVisible(true); | 140 state.SetVisible(true); |
| 96 state.UpdateState( | 141 state.UpdateState( |
| 97 SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD); | 142 SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD); |
| 98 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, | 143 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, |
| 99 state.CommitState()); | 144 state.CommitState()); |
| 100 EXPECT_FALSE(state.NeedsCommit()); | 145 EXPECT_FALSE(state.NeedsCommit()); |
| 101 EXPECT_FALSE(state.BeginFrameNeededToDrawByImplThread()); | 146 EXPECT_FALSE(state.BeginFrameNeededToDrawByImplThread()); |
| 102 } | 147 } |
| 103 } | 148 } |
| 104 | 149 |
| 105 TEST(SchedulerStateMachineTest, TestSetForcedRedrawDoesNotSetsNormalRedraw) { | 150 TEST(SchedulerStateMachineTest, TestSetForcedRedrawDoesNotSetsNormalRedraw) { |
| 106 SchedulerSettings default_scheduler_settings; | 151 SchedulerSettings default_scheduler_settings; |
| 107 SchedulerStateMachine state(default_scheduler_settings); | 152 StateMachine state(default_scheduler_settings); |
| 108 state.SetCanDraw(true); | 153 state.SetCanDraw(true); |
| 109 state.SetNeedsForcedRedraw(); | 154 state.SetNeedsForcedRedrawForReadback(); |
| 110 EXPECT_FALSE(state.RedrawPending()); | 155 EXPECT_FALSE(state.RedrawPending()); |
| 111 EXPECT_TRUE(state.BeginFrameNeededToDrawByImplThread()); | 156 EXPECT_FALSE(state.BeginFrameNeededByImplThread()); |
| 112 } | 157 } |
| 113 | 158 |
| 114 TEST(SchedulerStateMachineTest, | 159 TEST(SchedulerStateMachineTest, |
| 115 TestFailedDrawSetsNeedsCommitAndDoesNotDrawAgain) { | 160 TestFailedDrawSetsNeedsCommitAndDoesNotDrawAgain) { |
| 116 SchedulerSettings default_scheduler_settings; | 161 SchedulerSettings default_scheduler_settings; |
| 117 SchedulerStateMachine state(default_scheduler_settings); | 162 StateMachine state(default_scheduler_settings); |
| 118 state.SetCanStart(); | 163 state.SetCanStart(); |
| 119 state.UpdateState(state.NextAction()); | 164 state.UpdateState(state.NextAction()); |
| 120 state.DidCreateAndInitializeOutputSurface(); | 165 state.DidCreateAndInitializeOutputSurface(); |
| 121 state.SetVisible(true); | 166 state.SetVisible(true); |
| 122 state.SetCanDraw(true); | 167 state.SetCanDraw(true); |
| 123 state.SetNeedsRedraw(); | 168 state.SetNeedsRedraw(true); |
| 124 EXPECT_TRUE(state.RedrawPending()); | 169 EXPECT_TRUE(state.RedrawPending()); |
| 125 EXPECT_TRUE(state.BeginFrameNeededToDrawByImplThread()); | 170 EXPECT_TRUE(state.BeginFrameNeededByImplThread()); |
| 126 state.DidEnterBeginFrame(BeginFrameArgs::CreateForTesting()); | 171 state.OnBeginFrame(BeginFrameArgs::CreateForTesting()); |
| 172 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 173 state.OnBeginFrameDeadline(); |
| 127 | 174 |
| 128 // We're drawing now. | 175 // We're drawing now. |
| 129 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.NextAction()); | 176 EXPECT_ACTION_UPDATE_STATE( |
| 130 state.UpdateState(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE); | 177 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); |
| 131 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); | 178 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 179 |
| 132 EXPECT_FALSE(state.RedrawPending()); | 180 EXPECT_FALSE(state.RedrawPending()); |
| 133 EXPECT_FALSE(state.CommitPending()); | 181 EXPECT_FALSE(state.CommitPending()); |
| 134 | 182 |
| 135 // Failing the draw makes us require a commit. | 183 // Failing the draw makes us require a commit. |
| 136 state.DidDrawIfPossibleCompleted(false); | 184 state.DidDrawIfPossibleCompleted(false); |
| 137 EXPECT_EQ(SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD, | 185 state.OnBeginFrame(BeginFrameArgs::CreateForTesting()); |
| 138 state.NextAction()); | 186 EXPECT_ACTION_UPDATE_STATE( |
| 139 state.UpdateState( | |
| 140 SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD); | 187 SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD); |
| 141 EXPECT_TRUE(state.RedrawPending()); | 188 EXPECT_TRUE(state.RedrawPending()); |
| 142 EXPECT_TRUE(state.CommitPending()); | 189 EXPECT_TRUE(state.CommitPending()); |
| 143 } | 190 } |
| 144 | 191 |
| 145 TEST(SchedulerStateMachineTest, | 192 TEST(SchedulerStateMachineTest, |
| 146 TestsetNeedsRedrawDuringFailedDrawDoesNotRemoveNeedsRedraw) { | 193 TestsetNeedsRedrawDuringFailedDrawDoesNotRemoveNeedsRedraw) { |
| 147 SchedulerSettings default_scheduler_settings; | 194 SchedulerSettings default_scheduler_settings; |
| 148 SchedulerStateMachine state(default_scheduler_settings); | 195 StateMachine state(default_scheduler_settings); |
| 149 state.SetCanStart(); | 196 state.SetCanStart(); |
| 150 state.UpdateState(state.NextAction()); | 197 state.UpdateState(state.NextAction()); |
| 151 state.DidCreateAndInitializeOutputSurface(); | 198 state.DidCreateAndInitializeOutputSurface(); |
| 152 | 199 |
| 153 state.SetVisible(true); | 200 state.SetVisible(true); |
| 154 state.SetCanDraw(true); | 201 state.SetCanDraw(true); |
| 155 state.SetNeedsRedraw(); | 202 state.SetNeedsRedraw(true); |
| 156 EXPECT_TRUE(state.RedrawPending()); | 203 EXPECT_TRUE(state.RedrawPending()); |
| 157 EXPECT_TRUE(state.BeginFrameNeededToDrawByImplThread()); | 204 EXPECT_TRUE(state.BeginFrameNeededByImplThread()); |
| 158 state.DidEnterBeginFrame(BeginFrameArgs::CreateForTesting()); | 205 state.OnBeginFrame(BeginFrameArgs::CreateForTesting()); |
| 206 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 207 state.OnBeginFrameDeadline(); |
| 159 | 208 |
| 160 // We're drawing now. | 209 // We're drawing now. |
| 161 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.NextAction()); | 210 EXPECT_ACTION_UPDATE_STATE( |
| 162 state.UpdateState(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE); | 211 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); |
| 163 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); | 212 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 164 EXPECT_FALSE(state.RedrawPending()); | 213 EXPECT_FALSE(state.RedrawPending()); |
| 165 EXPECT_FALSE(state.CommitPending()); | 214 EXPECT_FALSE(state.CommitPending()); |
| 166 | 215 |
| 167 // While still in the same begin frame callback on the main thread, | 216 // While still in the same begin frame callback on the main thread, |
| 168 // set needs redraw again. This should not redraw. | 217 // set needs redraw again. This should not redraw. |
| 169 state.SetNeedsRedraw(); | 218 state.SetNeedsRedraw(true); |
| 170 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); | 219 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 171 | 220 |
| 172 // Failing the draw makes us require a commit. | 221 // Failing the draw makes us require a commit. |
| 173 state.DidDrawIfPossibleCompleted(false); | 222 state.DidDrawIfPossibleCompleted(false); |
| 174 EXPECT_EQ(SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD, | 223 state.OnBeginFrame(BeginFrameArgs::CreateForTesting()); |
| 175 state.NextAction()); | 224 EXPECT_ACTION_UPDATE_STATE( |
| 225 SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD); |
| 176 EXPECT_TRUE(state.RedrawPending()); | 226 EXPECT_TRUE(state.RedrawPending()); |
| 177 } | 227 } |
| 178 | 228 |
| 179 TEST(SchedulerStateMachineTest, | 229 TEST(SchedulerStateMachineTest, |
| 180 TestCommitAfterFailedDrawAllowsDrawInSameFrame) { | |
| 181 SchedulerSettings default_scheduler_settings; | |
| 182 SchedulerStateMachine state(default_scheduler_settings); | |
| 183 state.SetCanStart(); | |
| 184 state.UpdateState(state.NextAction()); | |
| 185 state.DidCreateAndInitializeOutputSurface(); | |
| 186 state.SetVisible(true); | |
| 187 state.SetCanDraw(true); | |
| 188 | |
| 189 // Start a commit. | |
| 190 state.SetNeedsCommit(); | |
| 191 EXPECT_EQ(SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD, | |
| 192 state.NextAction()); | |
| 193 state.UpdateState( | |
| 194 SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD); | |
| 195 EXPECT_TRUE(state.CommitPending()); | |
| 196 | |
| 197 // Then initiate a draw. | |
| 198 state.SetNeedsRedraw(); | |
| 199 EXPECT_TRUE(state.BeginFrameNeededToDrawByImplThread()); | |
| 200 state.DidEnterBeginFrame(BeginFrameArgs::CreateForTesting()); | |
| 201 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.NextAction()); | |
| 202 EXPECT_TRUE(state.RedrawPending()); | |
| 203 | |
| 204 // Fail the draw. | |
| 205 state.UpdateState(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE); | |
| 206 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); | |
| 207 state.DidDrawIfPossibleCompleted(false); | |
| 208 EXPECT_TRUE(state.RedrawPending()); | |
| 209 // But the commit is ongoing. | |
| 210 EXPECT_TRUE(state.CommitPending()); | |
| 211 | |
| 212 // Finish the commit. | |
| 213 state.FinishCommit(); | |
| 214 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction()); | |
| 215 state.UpdateState(SchedulerStateMachine::ACTION_COMMIT); | |
| 216 EXPECT_TRUE(state.RedrawPending()); | |
| 217 | |
| 218 // And we should be allowed to draw again. | |
| 219 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.NextAction()); | |
| 220 } | |
| 221 | |
| 222 TEST(SchedulerStateMachineTest, | |
| 223 TestCommitAfterFailedAndSuccessfulDrawDoesNotAllowDrawInSameFrame) { | |
| 224 SchedulerSettings default_scheduler_settings; | |
| 225 SchedulerStateMachine state(default_scheduler_settings); | |
| 226 state.SetCanStart(); | |
| 227 state.UpdateState(state.NextAction()); | |
| 228 state.DidCreateAndInitializeOutputSurface(); | |
| 229 state.SetVisible(true); | |
| 230 state.SetCanDraw(true); | |
| 231 | |
| 232 // Start a commit. | |
| 233 state.SetNeedsCommit(); | |
| 234 EXPECT_EQ(SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD, | |
| 235 state.NextAction()); | |
| 236 state.UpdateState( | |
| 237 SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD); | |
| 238 EXPECT_TRUE(state.CommitPending()); | |
| 239 | |
| 240 // Then initiate a draw. | |
| 241 state.SetNeedsRedraw(); | |
| 242 EXPECT_TRUE(state.BeginFrameNeededToDrawByImplThread()); | |
| 243 state.DidEnterBeginFrame(BeginFrameArgs::CreateForTesting()); | |
| 244 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.NextAction()); | |
| 245 EXPECT_TRUE(state.RedrawPending()); | |
| 246 | |
| 247 // Fail the draw. | |
| 248 state.UpdateState(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE); | |
| 249 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); | |
| 250 state.DidDrawIfPossibleCompleted(false); | |
| 251 EXPECT_TRUE(state.RedrawPending()); | |
| 252 // But the commit is ongoing. | |
| 253 EXPECT_TRUE(state.CommitPending()); | |
| 254 | |
| 255 // Force a draw. | |
| 256 state.SetNeedsForcedRedraw(); | |
| 257 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_FORCED, state.NextAction()); | |
| 258 | |
| 259 // Do the forced draw. | |
| 260 state.UpdateState(SchedulerStateMachine::ACTION_DRAW_FORCED); | |
| 261 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); | |
| 262 EXPECT_FALSE(state.RedrawPending()); | |
| 263 // And the commit is still ongoing. | |
| 264 EXPECT_TRUE(state.CommitPending()); | |
| 265 | |
| 266 // Finish the commit. | |
| 267 state.FinishCommit(); | |
| 268 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction()); | |
| 269 state.UpdateState(SchedulerStateMachine::ACTION_COMMIT); | |
| 270 EXPECT_TRUE(state.RedrawPending()); | |
| 271 | |
| 272 // And we should not be allowed to draw again in the same frame.. | |
| 273 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); | |
| 274 } | |
| 275 | |
| 276 TEST(SchedulerStateMachineTest, | |
| 277 TestFailedDrawsWillEventuallyForceADrawAfterTheNextCommit) { | 230 TestFailedDrawsWillEventuallyForceADrawAfterTheNextCommit) { |
| 278 SchedulerSettings default_scheduler_settings; | 231 SchedulerSettings default_scheduler_settings; |
| 279 SchedulerStateMachine state(default_scheduler_settings); | 232 StateMachine state(default_scheduler_settings); |
| 280 state.SetCanStart(); | 233 state.SetCanStart(); |
| 281 state.UpdateState(state.NextAction()); | 234 state.UpdateState(state.NextAction()); |
| 282 state.DidCreateAndInitializeOutputSurface(); | 235 state.DidCreateAndInitializeOutputSurface(); |
| 283 state.SetVisible(true); | 236 state.SetVisible(true); |
| 284 state.SetCanDraw(true); | 237 state.SetCanDraw(true); |
| 285 state.SetMaximumNumberOfFailedDrawsBeforeDrawIsForced(1); | 238 state.SetMaximumNumberOfFailedDrawsBeforeDrawIsForced(1); |
| 286 | 239 |
| 287 // Start a commit. | 240 // Start a commit. |
| 288 state.SetNeedsCommit(); | 241 state.SetNeedsCommit(); |
| 289 EXPECT_EQ(SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD, | 242 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 290 state.NextAction()); | 243 state.OnBeginFrame(BeginFrameArgs::CreateForTesting()); |
| 291 state.UpdateState( | 244 EXPECT_ACTION_UPDATE_STATE( |
| 292 SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD); | 245 SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD); |
| 246 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 293 EXPECT_TRUE(state.CommitPending()); | 247 EXPECT_TRUE(state.CommitPending()); |
| 294 | 248 |
| 295 // Then initiate a draw. | 249 // Then initiate a draw. |
| 296 state.SetNeedsRedraw(); | 250 state.SetNeedsRedraw(true); |
| 297 EXPECT_TRUE(state.BeginFrameNeededToDrawByImplThread()); | 251 state.OnBeginFrameDeadline(); |
| 298 state.DidEnterBeginFrame(BeginFrameArgs::CreateForTesting()); | 252 EXPECT_ACTION_UPDATE_STATE( |
| 299 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.NextAction()); | 253 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); |
| 300 EXPECT_TRUE(state.RedrawPending()); | |
| 301 | 254 |
| 302 // Fail the draw. | 255 // Fail the draw. |
| 303 state.UpdateState(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE); | |
| 304 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); | |
| 305 state.DidDrawIfPossibleCompleted(false); | 256 state.DidDrawIfPossibleCompleted(false); |
| 257 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 258 EXPECT_TRUE(state.BeginFrameNeededByImplThread()); |
| 306 EXPECT_TRUE(state.RedrawPending()); | 259 EXPECT_TRUE(state.RedrawPending()); |
| 307 // But the commit is ongoing. | 260 // But the commit is ongoing. |
| 308 EXPECT_TRUE(state.CommitPending()); | 261 EXPECT_TRUE(state.CommitPending()); |
| 309 | 262 |
| 310 // Finish the commit. Note, we should not yet be forcing a draw, but should | 263 // Finish the commit. Note, we should not yet be forcing a draw, but should |
| 311 // continue the commit as usual. | 264 // continue the commit as usual. |
| 312 state.FinishCommit(); | 265 state.FinishCommit(); |
| 313 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction()); | 266 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); |
| 314 state.UpdateState(SchedulerStateMachine::ACTION_COMMIT); | 267 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 315 EXPECT_TRUE(state.RedrawPending()); | 268 EXPECT_TRUE(state.RedrawPending()); |
| 316 | 269 |
| 317 // The redraw should be forced in this case. | 270 // The redraw should be forced at the end of the next BeginFrame. |
| 318 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_FORCED, state.NextAction()); | 271 state.OnBeginFrame(BeginFrameArgs::CreateForTesting()); |
| 272 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 273 state.OnBeginFrameDeadline(); |
| 274 EXPECT_ACTION_UPDATE_STATE( |
| 275 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_FORCED); |
| 319 } | 276 } |
| 320 | 277 |
| 321 TEST(SchedulerStateMachineTest, | 278 TEST(SchedulerStateMachineTest, |
| 322 TestFailedDrawIsRetriedInNextBeginFrameForImplThread) { | 279 TestFailedDrawIsRetriedInNextBeginFrameForImplThread) { |
| 323 SchedulerSettings default_scheduler_settings; | 280 SchedulerSettings default_scheduler_settings; |
| 324 SchedulerStateMachine state(default_scheduler_settings); | 281 StateMachine state(default_scheduler_settings); |
| 325 state.SetCanStart(); | 282 state.SetCanStart(); |
| 326 state.UpdateState(state.NextAction()); | 283 state.UpdateState(state.NextAction()); |
| 327 state.DidCreateAndInitializeOutputSurface(); | 284 state.DidCreateAndInitializeOutputSurface(); |
| 328 state.SetVisible(true); | 285 state.SetVisible(true); |
| 329 state.SetCanDraw(true); | 286 state.SetCanDraw(true); |
| 330 | 287 |
| 331 // Start a draw. | 288 // Start a draw. |
| 332 state.SetNeedsRedraw(); | 289 state.SetNeedsRedraw(true); |
| 333 EXPECT_TRUE(state.BeginFrameNeededToDrawByImplThread()); | 290 EXPECT_TRUE(state.BeginFrameNeededByImplThread()); |
| 334 state.DidEnterBeginFrame(BeginFrameArgs::CreateForTesting()); | 291 state.OnBeginFrame(BeginFrameArgs::CreateForTesting()); |
| 335 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.NextAction()); | 292 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 293 state.OnBeginFrameDeadline(); |
| 336 EXPECT_TRUE(state.RedrawPending()); | 294 EXPECT_TRUE(state.RedrawPending()); |
| 295 EXPECT_ACTION_UPDATE_STATE( |
| 296 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); |
| 337 | 297 |
| 338 // Fail the draw. | 298 // Fail the draw |
| 339 state.UpdateState(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE); | |
| 340 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); | |
| 341 state.DidDrawIfPossibleCompleted(false); | 299 state.DidDrawIfPossibleCompleted(false); |
| 300 EXPECT_ACTION_UPDATE_STATE( |
| 301 SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD); |
| 302 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 342 EXPECT_TRUE(state.RedrawPending()); | 303 EXPECT_TRUE(state.RedrawPending()); |
| 343 | 304 |
| 344 // We should not be trying to draw again now, but we have a commit pending. | 305 // We should not be trying to draw again now, but we have a commit pending. |
| 345 EXPECT_EQ(SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD, | 306 EXPECT_TRUE(state.BeginFrameNeededByImplThread()); |
| 346 state.NextAction()); | 307 state.OnBeginFrame(BeginFrameArgs::CreateForTesting()); |
| 308 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 347 | 309 |
| 348 state.DidLeaveBeginFrame(); | 310 // We should try to draw again at the end of the next BeginFrame on |
| 349 EXPECT_TRUE(state.BeginFrameNeededToDrawByImplThread()); | 311 // the impl thread. |
| 350 state.DidEnterBeginFrame(BeginFrameArgs::CreateForTesting()); | 312 state.OnBeginFrameDeadline(); |
| 351 | 313 EXPECT_ACTION_UPDATE_STATE( |
| 352 // We should try to draw again in the next begin frame on the impl thread. | 314 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); |
| 353 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.NextAction()); | 315 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 354 } | 316 } |
| 355 | 317 |
| 356 TEST(SchedulerStateMachineTest, TestDoestDrawTwiceInSameFrame) { | 318 TEST(SchedulerStateMachineTest, TestDoestDrawTwiceInSameFrame) { |
| 357 SchedulerSettings default_scheduler_settings; | 319 SchedulerSettings default_scheduler_settings; |
| 358 SchedulerStateMachine state(default_scheduler_settings); | 320 StateMachine state(default_scheduler_settings); |
| 359 state.SetCanStart(); | 321 state.SetCanStart(); |
| 360 state.UpdateState(state.NextAction()); | 322 state.UpdateState(state.NextAction()); |
| 361 state.DidCreateAndInitializeOutputSurface(); | 323 state.DidCreateAndInitializeOutputSurface(); |
| 362 state.SetVisible(true); | 324 state.SetVisible(true); |
| 363 state.SetCanDraw(true); | 325 state.SetCanDraw(true); |
| 364 state.SetNeedsRedraw(); | 326 state.SetNeedsRedraw(true); |
| 365 EXPECT_TRUE(state.BeginFrameNeededToDrawByImplThread()); | |
| 366 state.DidEnterBeginFrame(BeginFrameArgs::CreateForTesting()); | |
| 367 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.NextAction()); | |
| 368 state.UpdateState(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE); | |
| 369 | 327 |
| 370 // While still in the same begin frame for the impl thread, set needs redraw | 328 // Draw the first frame. |
| 371 // again. This should not redraw. | 329 EXPECT_TRUE(state.BeginFrameNeededByImplThread()); |
| 372 state.SetNeedsRedraw(); | 330 state.OnBeginFrame(BeginFrameArgs::CreateForTesting()); |
| 373 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); | 331 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 332 |
| 333 state.OnBeginFrameDeadline(); |
| 334 EXPECT_ACTION_UPDATE_STATE( |
| 335 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); |
| 336 state.DidDrawIfPossibleCompleted(true); |
| 337 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 338 |
| 339 // Before the next begin frame for the impl thread, set needs redraw |
| 340 // again. This should not redraw until the next begin frame. |
| 341 state.SetNeedsRedraw(true); |
| 342 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 374 | 343 |
| 375 // Move to another frame. This should now draw. | 344 // Move to another frame. This should now draw. |
| 345 EXPECT_TRUE(state.BeginFrameNeededByImplThread()); |
| 346 state.OnBeginFrame(BeginFrameArgs::CreateForTesting()); |
| 347 |
| 348 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 349 |
| 350 state.OnBeginFrameDeadline(); |
| 351 EXPECT_ACTION_UPDATE_STATE( |
| 352 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); |
| 376 state.DidDrawIfPossibleCompleted(true); | 353 state.DidDrawIfPossibleCompleted(true); |
| 377 state.DidLeaveBeginFrame(); | 354 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 378 EXPECT_TRUE(state.BeginFrameNeededToDrawByImplThread()); | 355 EXPECT_FALSE(state.BeginFrameNeededByImplThread()); |
| 379 state.DidEnterBeginFrame(BeginFrameArgs::CreateForTesting()); | |
| 380 | |
| 381 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.NextAction()); | |
| 382 state.UpdateState(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE); | |
| 383 state.DidDrawIfPossibleCompleted(true); | |
| 384 EXPECT_FALSE(state.BeginFrameNeededToDrawByImplThread()); | |
| 385 } | 356 } |
| 386 | 357 |
| 387 TEST(SchedulerStateMachineTest, TestNextActionDrawsOnBeginFrame) { | 358 TEST(SchedulerStateMachineTest, TestNextActionDrawsOnBeginFrame) { |
| 388 SchedulerSettings default_scheduler_settings; | 359 SchedulerSettings default_scheduler_settings; |
| 389 | 360 |
| 390 // When not in BeginFrame, or in BeginFrame but not visible, | 361 // When not in BeginFrame deadline, or in BeginFrame deadline but not visible, |
| 391 // don't draw. | 362 // don't draw. |
| 392 size_t num_commit_states = | 363 size_t num_commit_states = sizeof(all_commit_states) / |
| 393 sizeof(all_commit_states) / sizeof(SchedulerStateMachine::CommitState); | 364 sizeof(SchedulerStateMachine::CommitState); |
| 365 size_t num_begin_frame_states = sizeof(all_begin_frame_states) / |
| 366 sizeof(SchedulerStateMachine::BeginFrameState); |
| 394 for (size_t i = 0; i < num_commit_states; ++i) { | 367 for (size_t i = 0; i < num_commit_states; ++i) { |
| 395 for (size_t j = 0; j < 2; ++j) { | 368 for (size_t j = 0; j < num_begin_frame_states; ++j) { |
| 396 StateMachine state(default_scheduler_settings); | 369 StateMachine state(default_scheduler_settings); |
| 397 state.SetCanStart(); | 370 state.SetCanStart(); |
| 398 state.UpdateState(state.NextAction()); | 371 state.UpdateState(state.NextAction()); |
| 399 state.DidCreateAndInitializeOutputSurface(); | 372 state.DidCreateAndInitializeOutputSurface(); |
| 400 state.SetCommitState(all_commit_states[i]); | 373 state.SetCommitState(all_commit_states[i]); |
| 401 bool visible = j; | 374 state.SetBeginFrameState(all_begin_frame_states[j]); |
| 402 if (!visible) { | 375 bool visible = (all_begin_frame_states[j] != |
| 403 state.DidEnterBeginFrame(BeginFrameArgs::CreateForTesting()); | 376 SchedulerStateMachine::BEGIN_FRAME_STATE_INSIDE_DEADLINE); |
| 404 state.SetVisible(false); | 377 state.SetVisible(visible); |
| 405 } else { | |
| 406 state.SetVisible(true); | |
| 407 } | |
| 408 | 378 |
| 409 // Case 1: needs_commit=false | 379 // Case 1: needs_commit=false |
| 410 EXPECT_NE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, | 380 EXPECT_NE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE, |
| 411 state.NextAction()); | 381 state.NextAction()); |
| 412 | 382 |
| 413 // Case 2: needs_commit=true | 383 // Case 2: needs_commit=true |
| 414 state.SetNeedsCommit(); | 384 state.SetNeedsCommit(); |
| 415 EXPECT_NE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, | 385 EXPECT_NE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE, |
| 416 state.NextAction()); | 386 state.NextAction()) << state.ToString(); |
| 417 } | 387 } |
| 418 } | 388 } |
| 419 | 389 |
| 420 // When in BeginFrame, or not in BeginFrame but needs_forced_dedraw | 390 // When in BeginFrame deadline we should always draw for SetNeedsRedraw or |
| 421 // set, should always draw except if you're ready to commit, in which case | 391 // SetNeedsForcedRedrawForReadback have been called... except if we're |
| 422 // commit. | 392 // ready to commit, in which case we expect a commit first. |
| 423 for (size_t i = 0; i < num_commit_states; ++i) { | 393 for (size_t i = 0; i < num_commit_states; ++i) { |
| 424 for (size_t j = 0; j < 2; ++j) { | 394 for (size_t j = 0; j < 2; ++j) { |
| 395 bool request_readback = j; |
| 396 |
| 397 // Skip invalid states |
| 398 if (request_readback && |
| 399 (SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW != |
| 400 all_commit_states[i])) |
| 401 continue; |
| 402 |
| 425 StateMachine state(default_scheduler_settings); | 403 StateMachine state(default_scheduler_settings); |
| 426 state.SetCanStart(); | 404 state.SetCanStart(); |
| 427 state.UpdateState(state.NextAction()); | 405 state.UpdateState(state.NextAction()); |
| 428 state.DidCreateAndInitializeOutputSurface(); | 406 state.DidCreateAndInitializeOutputSurface(); |
| 429 state.SetCanDraw(true); | 407 state.SetCanDraw(true); |
| 430 state.SetCommitState(all_commit_states[i]); | 408 state.SetCommitState(all_commit_states[i]); |
| 431 bool forced_draw = j; | 409 state.SetBeginFrameState( |
| 432 if (!forced_draw) { | 410 SchedulerStateMachine::BEGIN_FRAME_STATE_INSIDE_DEADLINE); |
| 433 state.DidEnterBeginFrame(BeginFrameArgs::CreateForTesting()); | 411 if (request_readback) { |
| 412 state.SetNeedsForcedRedrawForReadback(); |
| 413 } else { |
| 434 state.SetNeedsRedraw(true); | 414 state.SetNeedsRedraw(true); |
| 435 state.SetVisible(true); | 415 state.SetVisible(true); |
| 436 } else { | |
| 437 state.SetNeedsForcedRedraw(true); | |
| 438 } | 416 } |
| 439 | 417 |
| 440 SchedulerStateMachine::Action expected_action; | 418 SchedulerStateMachine::Action expected_action; |
| 441 if (all_commit_states[i] != | 419 if (all_commit_states[i] == |
| 442 SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT) { | 420 SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT) { |
| 421 expected_action = SchedulerStateMachine::ACTION_COMMIT; |
| 422 } else if (request_readback) { |
| 423 if (all_commit_states[i] == |
| 424 SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW) |
| 425 expected_action = SchedulerStateMachine::ACTION_DRAW_AND_READBACK; |
| 426 else |
| 427 expected_action = SchedulerStateMachine::ACTION_NONE; |
| 428 } else { |
| 443 expected_action = | 429 expected_action = |
| 444 forced_draw ? SchedulerStateMachine::ACTION_DRAW_FORCED | 430 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE; |
| 445 : SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE; | |
| 446 } else { | |
| 447 expected_action = SchedulerStateMachine::ACTION_COMMIT; | |
| 448 } | 431 } |
| 449 | 432 |
| 450 // Case 1: needs_commit=false. | 433 // Case 1: needs_commit=false. |
| 451 EXPECT_TRUE(state.BeginFrameNeededToDrawByImplThread()); | 434 EXPECT_EQ(state.BeginFrameNeededByImplThread(), |
| 452 EXPECT_EQ(expected_action, state.NextAction()); | 435 !request_readback); |
| 436 EXPECT_EQ(expected_action, state.NextAction()) << state.ToString(); |
| 453 | 437 |
| 454 // Case 2: needs_commit=true. | 438 // Case 2: needs_commit=true. |
| 455 state.SetNeedsCommit(); | 439 state.SetNeedsCommit(); |
| 456 EXPECT_TRUE(state.BeginFrameNeededToDrawByImplThread()); | 440 EXPECT_EQ(state.BeginFrameNeededByImplThread(), |
| 457 EXPECT_EQ(expected_action, state.NextAction()); | 441 !request_readback); |
| 442 EXPECT_EQ(expected_action, state.NextAction()) << state.ToString(); |
| 458 } | 443 } |
| 459 } | 444 } |
| 460 } | 445 } |
| 461 | 446 |
| 462 TEST(SchedulerStateMachineTest, TestNoCommitStatesRedrawWhenInvisible) { | 447 TEST(SchedulerStateMachineTest, TestNoCommitStatesRedrawWhenInvisible) { |
| 463 SchedulerSettings default_scheduler_settings; | 448 SchedulerSettings default_scheduler_settings; |
| 464 | 449 |
| 465 size_t num_commit_states = | 450 size_t num_commit_states = |
| 466 sizeof(all_commit_states) / sizeof(SchedulerStateMachine::CommitState); | 451 sizeof(all_commit_states) / sizeof(SchedulerStateMachine::CommitState); |
| 467 for (size_t i = 0; i < num_commit_states; ++i) { | 452 for (size_t i = 0; i < num_commit_states; ++i) { |
| 468 // There shouldn't be any drawing regardless of BeginFrame. | 453 // There shouldn't be any drawing regardless of BeginFrame. |
| 469 for (size_t j = 0; j < 2; ++j) { | 454 for (size_t j = 0; j < 2; ++j) { |
| 470 StateMachine state(default_scheduler_settings); | 455 StateMachine state(default_scheduler_settings); |
| 471 state.SetCanStart(); | 456 state.SetCanStart(); |
| 472 state.UpdateState(state.NextAction()); | 457 state.UpdateState(state.NextAction()); |
| 473 state.DidCreateAndInitializeOutputSurface(); | 458 state.DidCreateAndInitializeOutputSurface(); |
| 474 state.SetCommitState(all_commit_states[i]); | 459 state.SetCommitState(all_commit_states[i]); |
| 475 state.SetVisible(false); | 460 state.SetVisible(false); |
| 476 state.SetNeedsRedraw(true); | 461 state.SetNeedsRedraw(true); |
| 477 state.SetNeedsForcedRedraw(false); | 462 if (j == 1) { |
| 478 if (j == 1) | 463 state.SetBeginFrameState( |
| 479 state.DidEnterBeginFrame(BeginFrameArgs::CreateForTesting()); | 464 SchedulerStateMachine::BEGIN_FRAME_STATE_INSIDE_DEADLINE); |
| 465 } |
| 480 | 466 |
| 481 // Case 1: needs_commit=false. | 467 // Case 1: needs_commit=false. |
| 482 EXPECT_NE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, | 468 EXPECT_NE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE, |
| 483 state.NextAction()); | 469 state.NextAction()); |
| 484 | 470 |
| 485 // Case 2: needs_commit=true. | 471 // Case 2: needs_commit=true. |
| 486 state.SetNeedsCommit(); | 472 state.SetNeedsCommit(); |
| 487 EXPECT_NE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, | 473 EXPECT_NE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE, |
| 488 state.NextAction()); | 474 state.NextAction()) << state.ToString(); |
| 489 } | 475 } |
| 490 } | 476 } |
| 491 } | 477 } |
| 492 | 478 |
| 493 TEST(SchedulerStateMachineTest, TestCanRedraw_StopsDraw) { | 479 TEST(SchedulerStateMachineTest, TestCanRedraw_StopsDraw) { |
| 494 SchedulerSettings default_scheduler_settings; | 480 SchedulerSettings default_scheduler_settings; |
| 495 | 481 |
| 496 size_t num_commit_states = | 482 size_t num_commit_states = |
| 497 sizeof(all_commit_states) / sizeof(SchedulerStateMachine::CommitState); | 483 sizeof(all_commit_states) / sizeof(SchedulerStateMachine::CommitState); |
| 498 for (size_t i = 0; i < num_commit_states; ++i) { | 484 for (size_t i = 0; i < num_commit_states; ++i) { |
| 499 // There shouldn't be any drawing regardless of BeginFrame. | 485 // There shouldn't be any drawing regardless of BeginFrame. |
| 500 for (size_t j = 0; j < 2; ++j) { | 486 for (size_t j = 0; j < 2; ++j) { |
| 501 StateMachine state(default_scheduler_settings); | 487 StateMachine state(default_scheduler_settings); |
| 502 state.SetCanStart(); | 488 state.SetCanStart(); |
| 503 state.UpdateState(state.NextAction()); | 489 state.UpdateState(state.NextAction()); |
| 504 state.DidCreateAndInitializeOutputSurface(); | 490 state.DidCreateAndInitializeOutputSurface(); |
| 505 state.SetCommitState(all_commit_states[i]); | 491 state.SetCommitState(all_commit_states[i]); |
| 506 state.SetVisible(false); | 492 state.SetVisible(false); |
| 507 state.SetNeedsRedraw(true); | 493 state.SetNeedsRedraw(true); |
| 508 state.SetNeedsForcedRedraw(false); | |
| 509 if (j == 1) | 494 if (j == 1) |
| 510 state.DidEnterBeginFrame(BeginFrameArgs::CreateForTesting()); | 495 state.OnBeginFrame(BeginFrameArgs::CreateForTesting()); |
| 511 | 496 |
| 512 state.SetCanDraw(false); | 497 state.SetCanDraw(false); |
| 513 EXPECT_NE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, | 498 EXPECT_NE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE, |
| 514 state.NextAction()); | 499 state.NextAction()); |
| 515 } | 500 } |
| 516 } | 501 } |
| 517 } | 502 } |
| 518 | 503 |
| 519 TEST(SchedulerStateMachineTest, | 504 TEST(SchedulerStateMachineTest, |
| 520 TestCanRedrawWithWaitingForFirstDrawMakesProgress) { | 505 TestCanRedrawWithWaitingForFirstDrawMakesProgress) { |
| 521 SchedulerSettings default_scheduler_settings; | 506 SchedulerSettings default_scheduler_settings; |
| 522 StateMachine state(default_scheduler_settings); | 507 StateMachine state(default_scheduler_settings); |
| 523 state.SetCanStart(); | 508 state.SetCanStart(); |
| 524 state.UpdateState(state.NextAction()); | 509 state.UpdateState(state.NextAction()); |
| 525 state.DidCreateAndInitializeOutputSurface(); | 510 state.DidCreateAndInitializeOutputSurface(); |
| 526 state.SetCommitState( | 511 state.SetCommitState( |
| 527 SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW); | 512 SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW); |
| 528 state.SetNeedsCommit(); | 513 state.SetNeedsCommit(); |
| 529 state.SetNeedsRedraw(true); | 514 state.SetNeedsRedraw(true); |
| 530 state.SetVisible(true); | 515 state.SetVisible(true); |
| 531 state.SetCanDraw(false); | 516 state.SetCanDraw(false); |
| 532 EXPECT_EQ(SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD, | 517 state.OnBeginFrame(BeginFrameArgs::CreateForTesting()); |
| 533 state.NextAction()); | 518 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT); |
| 519 EXPECT_ACTION_UPDATE_STATE( |
| 520 SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD); |
| 521 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 522 state.FinishCommit(); |
| 523 EXPECT_ACTION_UPDATE_STATE( |
| 524 SchedulerStateMachine::ACTION_COMMIT); |
| 525 state.OnBeginFrameDeadline(); |
| 526 EXPECT_ACTION_UPDATE_STATE( |
| 527 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT); |
| 528 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 534 } | 529 } |
| 535 | 530 |
| 536 TEST(SchedulerStateMachineTest, TestsetNeedsCommitIsNotLost) { | 531 TEST(SchedulerStateMachineTest, TestsetNeedsCommitIsNotLost) { |
| 537 SchedulerSettings default_scheduler_settings; | 532 SchedulerSettings default_scheduler_settings; |
| 538 StateMachine state(default_scheduler_settings); | 533 StateMachine state(default_scheduler_settings); |
| 539 state.SetCanStart(); | 534 state.SetCanStart(); |
| 540 state.UpdateState(state.NextAction()); | 535 state.UpdateState(state.NextAction()); |
| 541 state.DidCreateAndInitializeOutputSurface(); | 536 state.DidCreateAndInitializeOutputSurface(); |
| 542 state.SetNeedsCommit(); | 537 state.SetNeedsCommit(); |
| 543 state.SetVisible(true); | 538 state.SetVisible(true); |
| 544 state.SetCanDraw(true); | 539 state.SetCanDraw(true); |
| 545 | 540 |
| 541 EXPECT_TRUE(state.BeginFrameNeededByImplThread()); |
| 542 |
| 546 // Begin the frame. | 543 // Begin the frame. |
| 547 EXPECT_EQ(SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD, | 544 state.OnBeginFrame(BeginFrameArgs::CreateForTesting()); |
| 548 state.NextAction()); | 545 EXPECT_ACTION_UPDATE_STATE( |
| 549 state.UpdateState(state.NextAction()); | 546 SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD); |
| 550 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, | 547 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, |
| 551 state.CommitState()); | 548 state.CommitState()); |
| 552 | 549 |
| 553 // Now, while the frame is in progress, set another commit. | 550 // Now, while the frame is in progress, set another commit. |
| 554 state.SetNeedsCommit(); | 551 state.SetNeedsCommit(); |
| 555 EXPECT_TRUE(state.NeedsCommit()); | 552 EXPECT_TRUE(state.NeedsCommit()); |
| 556 | 553 |
| 557 // Let the frame finish. | 554 // Let the frame finish. |
| 558 state.FinishCommit(); | 555 state.FinishCommit(); |
| 559 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT, | 556 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT, |
| 560 state.CommitState()); | 557 state.CommitState()); |
| 561 | 558 |
| 562 // Expect to commit regardless of BeginFrame state. | 559 // Expect to commit regardless of BeginFrame state. |
| 563 state.DidLeaveBeginFrame(); | 560 EXPECT_EQ(SchedulerStateMachine::BEGIN_FRAME_STATE_INSIDE_BEGIN_FRAME, |
| 561 state.begin_frame_state()); |
| 564 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction()); | 562 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction()); |
| 565 state.DidEnterBeginFrame(BeginFrameArgs::CreateForTesting()); | 563 |
| 564 state.AdvanceBeginFrameStateWhenNoActionsRemain(); |
| 565 EXPECT_EQ(SchedulerStateMachine::BEGIN_FRAME_STATE_DEADLINE_PENDING, |
| 566 state.begin_frame_state()); |
| 567 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction()); |
| 568 |
| 569 state.OnBeginFrameDeadline(); |
| 570 EXPECT_EQ(SchedulerStateMachine::BEGIN_FRAME_STATE_INSIDE_DEADLINE, |
| 571 state.begin_frame_state()); |
| 572 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction()); |
| 573 |
| 574 state.AdvanceBeginFrameStateWhenNoActionsRemain(); |
| 575 EXPECT_EQ(SchedulerStateMachine::BEGIN_FRAME_STATE_IDLE, |
| 576 state.begin_frame_state()); |
| 577 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction()); |
| 578 |
| 579 state.OnBeginFrame(BeginFrameArgs::CreateForTesting()); |
| 580 EXPECT_EQ(SchedulerStateMachine::BEGIN_FRAME_STATE_INSIDE_BEGIN_FRAME, |
| 581 state.begin_frame_state()); |
| 566 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction()); | 582 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction()); |
| 567 | 583 |
| 568 // Commit and make sure we draw on next BeginFrame | 584 // Commit and make sure we draw on next BeginFrame |
| 569 state.UpdateState(SchedulerStateMachine::ACTION_COMMIT); | 585 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); |
| 570 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.NextAction()); | 586 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 587 state.OnBeginFrameDeadline(); |
| 571 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW, | 588 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW, |
| 572 state.CommitState()); | 589 state.CommitState()); |
| 573 state.UpdateState(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE); | 590 EXPECT_ACTION_UPDATE_STATE( |
| 591 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); |
| 574 state.DidDrawIfPossibleCompleted(true); | 592 state.DidDrawIfPossibleCompleted(true); |
| 575 | 593 |
| 576 // Verify that another commit will begin. | 594 // Verify that another commit will start immediately after draw. |
| 577 state.DidLeaveBeginFrame(); | 595 EXPECT_ACTION_UPDATE_STATE( |
| 578 EXPECT_EQ(SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD, | 596 SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD); |
| 579 state.NextAction()); | 597 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 580 } | 598 } |
| 581 | 599 |
| 582 TEST(SchedulerStateMachineTest, TestFullCycle) { | 600 TEST(SchedulerStateMachineTest, TestFullCycle) { |
| 583 SchedulerSettings default_scheduler_settings; | 601 SchedulerSettings default_scheduler_settings; |
| 584 StateMachine state(default_scheduler_settings); | 602 StateMachine state(default_scheduler_settings); |
| 585 state.SetCanStart(); | 603 state.SetCanStart(); |
| 586 state.UpdateState(state.NextAction()); | 604 state.UpdateState(state.NextAction()); |
| 587 state.DidCreateAndInitializeOutputSurface(); | 605 state.DidCreateAndInitializeOutputSurface(); |
| 588 state.SetVisible(true); | 606 state.SetVisible(true); |
| 589 state.SetCanDraw(true); | 607 state.SetCanDraw(true); |
| 590 | 608 |
| 591 // Start clean and set commit. | 609 // Start clean and set commit. |
| 592 state.SetNeedsCommit(); | 610 state.SetNeedsCommit(); |
| 593 EXPECT_EQ(SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD, | |
| 594 state.NextAction()); | |
| 595 | 611 |
| 596 // Begin the frame. | 612 // Begin the frame. |
| 597 state.UpdateState( | 613 state.OnBeginFrame(BeginFrameArgs::CreateForTesting()); |
| 614 EXPECT_ACTION_UPDATE_STATE( |
| 598 SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD); | 615 SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD); |
| 599 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, | 616 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, |
| 600 state.CommitState()); | 617 state.CommitState()); |
| 601 EXPECT_FALSE(state.NeedsCommit()); | 618 EXPECT_FALSE(state.NeedsCommit()); |
| 602 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); | 619 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 603 | 620 |
| 604 // Tell the scheduler the frame finished. | 621 // Tell the scheduler the frame finished. |
| 605 state.FinishCommit(); | 622 state.FinishCommit(); |
| 606 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT, | 623 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT, |
| 607 state.CommitState()); | 624 state.CommitState()); |
| 608 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction()); | |
| 609 | 625 |
| 610 // Commit. | 626 // Commit. |
| 611 state.UpdateState(SchedulerStateMachine::ACTION_COMMIT); | 627 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); |
| 612 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW, | 628 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW, |
| 613 state.CommitState()); | 629 state.CommitState()); |
| 614 EXPECT_TRUE(state.NeedsRedraw()); | 630 EXPECT_TRUE(state.NeedsRedraw()); |
| 615 | 631 |
| 616 // Expect to do nothing until BeginFrame. | 632 // Expect to do nothing until BeginFrame deadline |
| 617 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); | 633 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 618 | 634 |
| 619 // At BeginFrame, draw. | 635 // At BeginFrame deadline, draw. |
| 620 state.DidEnterBeginFrame(BeginFrameArgs::CreateForTesting()); | 636 state.OnBeginFrameDeadline(); |
| 621 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.NextAction()); | 637 EXPECT_ACTION_UPDATE_STATE( |
| 622 state.UpdateState(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE); | 638 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); |
| 623 state.DidDrawIfPossibleCompleted(true); | 639 state.DidDrawIfPossibleCompleted(true); |
| 624 state.DidLeaveBeginFrame(); | |
| 625 | 640 |
| 626 // Should be synchronized, no draw needed, no action needed. | 641 // Should be synchronized, no draw needed, no action needed. |
| 642 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 627 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState()); | 643 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState()); |
| 628 EXPECT_FALSE(state.NeedsRedraw()); | 644 EXPECT_FALSE(state.NeedsRedraw()); |
| 629 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); | |
| 630 } | 645 } |
| 631 | 646 |
| 632 TEST(SchedulerStateMachineTest, TestFullCycleWithCommitRequestInbetween) { | 647 TEST(SchedulerStateMachineTest, TestFullCycleWithCommitRequestInbetween) { |
| 633 SchedulerSettings default_scheduler_settings; | 648 SchedulerSettings default_scheduler_settings; |
| 634 StateMachine state(default_scheduler_settings); | 649 StateMachine state(default_scheduler_settings); |
| 635 state.SetCanStart(); | 650 state.SetCanStart(); |
| 636 state.UpdateState(state.NextAction()); | 651 state.UpdateState(state.NextAction()); |
| 637 state.DidCreateAndInitializeOutputSurface(); | 652 state.DidCreateAndInitializeOutputSurface(); |
| 638 state.SetVisible(true); | 653 state.SetVisible(true); |
| 639 state.SetCanDraw(true); | 654 state.SetCanDraw(true); |
| 640 | 655 |
| 641 // Start clean and set commit. | 656 // Start clean and set commit. |
| 642 state.SetNeedsCommit(); | 657 state.SetNeedsCommit(); |
| 643 EXPECT_EQ(SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD, | |
| 644 state.NextAction()); | |
| 645 | 658 |
| 646 // Begin the frame. | 659 // Begin the frame. |
| 647 state.UpdateState( | 660 state.OnBeginFrame(BeginFrameArgs::CreateForTesting()); |
| 661 EXPECT_ACTION_UPDATE_STATE( |
| 648 SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD); | 662 SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD); |
| 649 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, | 663 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, |
| 650 state.CommitState()); | 664 state.CommitState()); |
| 651 EXPECT_FALSE(state.NeedsCommit()); | 665 EXPECT_FALSE(state.NeedsCommit()); |
| 652 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); | 666 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 653 | 667 |
| 654 // Request another commit while the commit is in flight. | 668 // Request another commit while the commit is in flight. |
| 655 state.SetNeedsCommit(); | 669 state.SetNeedsCommit(); |
| 656 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); | 670 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 657 | 671 |
| 658 // Tell the scheduler the frame finished. | 672 // Tell the scheduler the frame finished. |
| 659 state.FinishCommit(); | 673 state.FinishCommit(); |
| 660 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT, | 674 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT, |
| 661 state.CommitState()); | 675 state.CommitState()); |
| 662 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction()); | |
| 663 | 676 |
| 664 // Commit. | 677 // First commit. |
| 665 state.UpdateState(SchedulerStateMachine::ACTION_COMMIT); | 678 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); |
| 666 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW, | 679 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW, |
| 667 state.CommitState()); | 680 state.CommitState()); |
| 668 EXPECT_TRUE(state.NeedsRedraw()); | 681 EXPECT_TRUE(state.NeedsRedraw()); |
| 669 | 682 |
| 670 // Expect to do nothing until BeginFrame. | 683 // Expect to do nothing until BeginFrame deadline. |
| 671 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); | 684 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 672 | 685 |
| 673 // At BeginFrame, draw. | 686 // At BeginFrame deadline, draw. |
| 674 state.DidEnterBeginFrame(BeginFrameArgs::CreateForTesting()); | 687 state.OnBeginFrameDeadline(); |
| 675 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.NextAction()); | 688 EXPECT_ACTION_UPDATE_STATE( |
| 676 state.UpdateState(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE); | 689 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); |
| 677 state.DidDrawIfPossibleCompleted(true); | 690 state.DidDrawIfPossibleCompleted(true); |
| 678 state.DidLeaveBeginFrame(); | |
| 679 | 691 |
| 680 // Should be synchronized, no draw needed, no action needed. | 692 // Should be synchronized, no draw needed, no action needed. |
| 693 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 681 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState()); | 694 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState()); |
| 682 EXPECT_FALSE(state.NeedsRedraw()); | 695 EXPECT_FALSE(state.NeedsRedraw()); |
| 683 EXPECT_EQ(SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD, | 696 |
| 684 state.NextAction()); | 697 // Next BeginFrame should initiate second commit. |
| 698 state.OnBeginFrame(BeginFrameArgs::CreateForTesting()); |
| 699 EXPECT_ACTION_UPDATE_STATE( |
| 700 SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD); |
| 685 } | 701 } |
| 686 | 702 |
| 687 TEST(SchedulerStateMachineTest, TestRequestCommitInvisible) { | 703 TEST(SchedulerStateMachineTest, TestRequestCommitInvisible) { |
| 688 SchedulerSettings default_scheduler_settings; | 704 SchedulerSettings default_scheduler_settings; |
| 689 StateMachine state(default_scheduler_settings); | 705 StateMachine state(default_scheduler_settings); |
| 690 state.SetCanStart(); | 706 state.SetCanStart(); |
| 691 state.UpdateState(state.NextAction()); | 707 state.UpdateState(state.NextAction()); |
| 692 state.DidCreateAndInitializeOutputSurface(); | 708 state.DidCreateAndInitializeOutputSurface(); |
| 693 state.SetNeedsCommit(); | 709 state.SetNeedsCommit(); |
| 694 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); | 710 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 695 } | 711 } |
| 696 | 712 |
| 697 TEST(SchedulerStateMachineTest, TestGoesInvisibleBeforeFinishCommit) { | 713 TEST(SchedulerStateMachineTest, TestGoesInvisibleBeforeFinishCommit) { |
| 698 SchedulerSettings default_scheduler_settings; | 714 SchedulerSettings default_scheduler_settings; |
| 699 StateMachine state(default_scheduler_settings); | 715 StateMachine state(default_scheduler_settings); |
| 700 state.SetCanStart(); | 716 state.SetCanStart(); |
| 701 state.UpdateState(state.NextAction()); | 717 state.UpdateState(state.NextAction()); |
| 702 state.DidCreateAndInitializeOutputSurface(); | 718 state.DidCreateAndInitializeOutputSurface(); |
| 703 state.SetVisible(true); | 719 state.SetVisible(true); |
| 704 state.SetCanDraw(true); | 720 state.SetCanDraw(true); |
| 705 | 721 |
| 706 // Start clean and set commit. | 722 // Start clean and set commit. |
| 707 state.SetNeedsCommit(); | 723 state.SetNeedsCommit(); |
| 708 EXPECT_EQ(SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD, | |
| 709 state.NextAction()); | |
| 710 | 724 |
| 711 // Begin the frame while visible. | 725 // Begin the frame while visible. |
| 712 state.UpdateState( | 726 state.OnBeginFrame(BeginFrameArgs::CreateForTesting()); |
| 727 EXPECT_ACTION_UPDATE_STATE( |
| 713 SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD); | 728 SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD); |
| 714 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, | 729 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, |
| 715 state.CommitState()); | 730 state.CommitState()); |
| 716 EXPECT_FALSE(state.NeedsCommit()); | 731 EXPECT_FALSE(state.NeedsCommit()); |
| 717 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); | 732 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 718 | 733 |
| 719 // Become invisible and abort the main thread's begin frame. | 734 // Become invisible and abort the main thread's begin frame. |
| 720 state.SetVisible(false); | 735 state.SetVisible(false); |
| 721 state.BeginFrameAbortedByMainThread(); | 736 state.BeginFrameAbortedByMainThread(); |
| 722 | 737 |
| 723 // We should now be back in the idle state as if we didn't start a frame at | 738 // We should now be back in the idle state as if we never started the frame. |
| 724 // all. | |
| 725 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState()); | 739 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState()); |
| 726 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); | 740 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 741 |
| 742 // We shouldn't do anything on the BeginFrame deadline. |
| 743 state.OnBeginFrameDeadline(); |
| 744 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 727 | 745 |
| 728 // Become visible again. | 746 // Become visible again. |
| 729 state.SetVisible(true); | 747 state.SetVisible(true); |
| 730 | 748 |
| 731 // We should be beginning a frame now. | 749 // We should handle the aborted commit on the next BeginFrame. |
| 750 state.OnBeginFrame(BeginFrameArgs::CreateForTesting()); |
| 732 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState()); | 751 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState()); |
| 733 EXPECT_EQ(SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD, | 752 EXPECT_ACTION_UPDATE_STATE( |
| 734 state.NextAction()); | 753 SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD); |
| 735 | |
| 736 // Begin the frame. | |
| 737 state.UpdateState(state.NextAction()); | |
| 738 | 754 |
| 739 // We should be starting the commit now. | 755 // We should be starting the commit now. |
| 740 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, | 756 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, |
| 741 state.CommitState()); | 757 state.CommitState()); |
| 758 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 742 } | 759 } |
| 743 | 760 |
| 744 TEST(SchedulerStateMachineTest, TestFirstContextCreation) { | 761 TEST(SchedulerStateMachineTest, TestFirstContextCreation) { |
| 745 SchedulerSettings default_scheduler_settings; | 762 SchedulerSettings default_scheduler_settings; |
| 746 StateMachine state(default_scheduler_settings); | 763 StateMachine state(default_scheduler_settings); |
| 747 state.SetCanStart(); | 764 state.SetCanStart(); |
| 748 state.SetVisible(true); | 765 state.SetVisible(true); |
| 749 state.SetCanDraw(true); | 766 state.SetCanDraw(true); |
| 750 | 767 |
| 751 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION, | 768 EXPECT_ACTION_UPDATE_STATE( |
| 752 state.NextAction()); | 769 SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION); |
| 753 state.UpdateState(state.NextAction()); | |
| 754 state.DidCreateAndInitializeOutputSurface(); | 770 state.DidCreateAndInitializeOutputSurface(); |
| 755 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); | 771 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 756 | 772 |
| 757 // Check that the first init does not SetNeedsCommit. | 773 // Check that the first init does not SetNeedsCommit. |
| 774 state.OnBeginFrame(BeginFrameArgs::CreateForTesting()); |
| 775 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 776 state.OnBeginFrameDeadline(); |
| 777 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 778 |
| 779 // Check that a needs commit initiates a BeginFrame to the main thread. |
| 758 state.SetNeedsCommit(); | 780 state.SetNeedsCommit(); |
| 759 EXPECT_NE(SchedulerStateMachine::ACTION_NONE, state.NextAction()); | 781 state.OnBeginFrame(BeginFrameArgs::CreateForTesting()); |
| 782 EXPECT_ACTION_UPDATE_STATE( |
| 783 SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD); |
| 760 } | 784 } |
| 761 | 785 |
| 762 TEST(SchedulerStateMachineTest, TestContextLostWhenCompletelyIdle) { | 786 TEST(SchedulerStateMachineTest, TestContextLostWhenCompletelyIdle) { |
| 763 SchedulerSettings default_scheduler_settings; | 787 SchedulerSettings default_scheduler_settings; |
| 764 StateMachine state(default_scheduler_settings); | 788 StateMachine state(default_scheduler_settings); |
| 765 state.SetCanStart(); | 789 state.SetCanStart(); |
| 766 state.UpdateState(state.NextAction()); | 790 state.UpdateState(state.NextAction()); |
| 767 state.DidCreateAndInitializeOutputSurface(); | 791 state.DidCreateAndInitializeOutputSurface(); |
| 768 | 792 |
| 769 state.SetVisible(true); | 793 state.SetVisible(true); |
| 770 state.SetCanDraw(true); | 794 state.SetCanDraw(true); |
| 771 | 795 |
| 772 EXPECT_NE(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION, | 796 EXPECT_NE(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION, |
| 773 state.NextAction()); | 797 state.NextAction()); |
| 774 state.DidLoseOutputSurface(); | 798 state.DidLoseOutputSurface(); |
| 775 | 799 |
| 776 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION, | 800 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION, |
| 777 state.NextAction()); | 801 state.NextAction()); |
| 778 state.UpdateState(state.NextAction()); | 802 state.UpdateState(state.NextAction()); |
| 779 | 803 |
| 780 // Once context recreation begins, nothing should happen. | 804 // Once context recreation begins, nothing should happen. |
| 781 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); | 805 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 782 | 806 |
| 783 // Recreate the context. | 807 // Recreate the context. |
| 784 state.DidCreateAndInitializeOutputSurface(); | 808 state.DidCreateAndInitializeOutputSurface(); |
| 785 | 809 |
| 786 // When the context is recreated, we should begin a commit. | 810 // When the context is recreated, we should begin a commit. |
| 787 EXPECT_EQ(SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD, | 811 state.OnBeginFrame(BeginFrameArgs::CreateForTesting()); |
| 788 state.NextAction()); | 812 EXPECT_ACTION_UPDATE_STATE( |
| 789 state.UpdateState(state.NextAction()); | 813 SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD); |
| 790 } | 814 } |
| 791 | 815 |
| 792 TEST(SchedulerStateMachineTest, | 816 TEST(SchedulerStateMachineTest, |
| 793 TestContextLostWhenIdleAndCommitRequestedWhileRecreating) { | 817 TestContextLostWhenIdleAndCommitRequestedWhileRecreating) { |
| 794 SchedulerSettings default_scheduler_settings; | 818 SchedulerSettings default_scheduler_settings; |
| 795 StateMachine state(default_scheduler_settings); | 819 StateMachine state(default_scheduler_settings); |
| 796 state.SetCanStart(); | 820 state.SetCanStart(); |
| 797 state.UpdateState(state.NextAction()); | 821 state.UpdateState(state.NextAction()); |
| 798 state.DidCreateAndInitializeOutputSurface(); | 822 state.DidCreateAndInitializeOutputSurface(); |
| 799 state.SetVisible(true); | 823 state.SetVisible(true); |
| 800 state.SetCanDraw(true); | 824 state.SetCanDraw(true); |
| 801 | 825 |
| 802 EXPECT_NE(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION, | 826 EXPECT_NE(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION, |
| 803 state.NextAction()); | 827 state.NextAction()); |
| 804 state.DidLoseOutputSurface(); | 828 state.DidLoseOutputSurface(); |
| 805 | 829 |
| 806 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION, | 830 EXPECT_ACTION_UPDATE_STATE( |
| 807 state.NextAction()); | 831 SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION); |
| 808 state.UpdateState(state.NextAction()); | |
| 809 | 832 |
| 810 // Once context recreation begins, nothing should happen. | 833 // Once context recreation begins, nothing should happen. |
| 811 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); | 834 state.OnBeginFrame(BeginFrameArgs::CreateForTesting()); |
| 835 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 836 state.OnBeginFrameDeadline(); |
| 837 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 812 | 838 |
| 813 // While context is recreating, commits shouldn't begin. | 839 // While context is recreating, commits shouldn't begin. |
| 814 state.SetNeedsCommit(); | 840 state.SetNeedsCommit(); |
| 815 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); | 841 state.OnBeginFrame(BeginFrameArgs::CreateForTesting()); |
| 842 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 843 state.OnBeginFrameDeadline(); |
| 844 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 816 | 845 |
| 817 // Recreate the context | 846 // Recreate the context |
| 818 state.DidCreateAndInitializeOutputSurface(); | 847 state.DidCreateAndInitializeOutputSurface(); |
| 819 | 848 |
| 820 // When the context is recreated, we should begin a commit | 849 // When the context is recreated, we should begin a commit |
| 821 EXPECT_EQ(SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD, | 850 state.OnBeginFrame(BeginFrameArgs::CreateForTesting()); |
| 822 state.NextAction()); | 851 EXPECT_ACTION_UPDATE_STATE( |
| 823 state.UpdateState(state.NextAction()); | 852 SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD); |
| 853 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 854 state.FinishCommit(); |
| 855 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); |
| 856 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 824 | 857 |
| 825 // Once the context is recreated, whether we draw should be based on | 858 // Once the context is recreated, whether we draw should be based on |
| 826 // SetCanDraw. | 859 // SetCanDraw. |
| 860 state.OnBeginFrameDeadline(); |
| 827 state.SetNeedsRedraw(true); | 861 state.SetNeedsRedraw(true); |
| 828 state.DidEnterBeginFrame(BeginFrameArgs::CreateForTesting()); | 862 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE, |
| 829 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.NextAction()); | 863 state.NextAction()); |
| 830 state.SetCanDraw(false); | 864 state.SetCanDraw(false); |
| 831 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); | 865 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT, |
| 866 state.NextAction()); |
| 832 state.SetCanDraw(true); | 867 state.SetCanDraw(true); |
| 833 state.DidLeaveBeginFrame(); | 868 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE, |
| 869 state.NextAction()); |
| 834 } | 870 } |
| 835 | 871 |
| 836 TEST(SchedulerStateMachineTest, TestContextLostWhileCommitInProgress) { | 872 TEST(SchedulerStateMachineTest, TestContextLostWhileCommitInProgress) { |
| 837 SchedulerSettings default_scheduler_settings; | 873 SchedulerSettings default_scheduler_settings; |
| 838 StateMachine state(default_scheduler_settings); | 874 StateMachine state(default_scheduler_settings); |
| 839 state.SetCanStart(); | 875 state.SetCanStart(); |
| 840 state.UpdateState(state.NextAction()); | 876 state.UpdateState(state.NextAction()); |
| 841 state.DidCreateAndInitializeOutputSurface(); | 877 state.DidCreateAndInitializeOutputSurface(); |
| 842 state.SetVisible(true); | 878 state.SetVisible(true); |
| 843 state.SetCanDraw(true); | 879 state.SetCanDraw(true); |
| 844 | 880 |
| 845 // Get a commit in flight. | 881 // Get a commit in flight. |
| 846 state.SetNeedsCommit(); | 882 state.SetNeedsCommit(); |
| 847 EXPECT_EQ(SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD, | 883 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 848 state.NextAction()); | |
| 849 state.UpdateState(state.NextAction()); | |
| 850 | 884 |
| 851 // Set damage and expect a draw. | 885 // Set damage and expect a draw. |
| 852 state.SetNeedsRedraw(true); | 886 state.SetNeedsRedraw(true); |
| 853 state.DidEnterBeginFrame(BeginFrameArgs::CreateForTesting()); | 887 state.OnBeginFrame(BeginFrameArgs::CreateForTesting()); |
| 854 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.NextAction()); | 888 EXPECT_ACTION_UPDATE_STATE( |
| 855 state.UpdateState(state.NextAction()); | 889 SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD); |
| 856 state.DidLeaveBeginFrame(); | 890 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 891 state.OnBeginFrameDeadline(); |
| 892 EXPECT_ACTION_UPDATE_STATE( |
| 893 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); |
| 894 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 857 | 895 |
| 858 // Cause a lost context while the begin frame is in flight | 896 // Cause a lost context while the begin frame is in flight |
| 859 // for the main thread. | 897 // for the main thread. |
| 860 state.DidLoseOutputSurface(); | 898 state.DidLoseOutputSurface(); |
| 861 | 899 |
| 862 // Ask for another draw. Expect nothing happens. | 900 // Ask for another draw. Expect nothing happens. |
| 863 state.SetNeedsRedraw(true); | 901 state.SetNeedsRedraw(true); |
| 864 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); | 902 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); |
| 865 | 903 |
| 866 // Finish the frame, and commit. | 904 // Finish the frame, and commit. |
| 867 state.FinishCommit(); | 905 state.FinishCommit(); |
| 868 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction()); | 906 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); |
| 869 state.UpdateState(state.NextAction()); | |
| 870 | 907 |
| 908 // We will abort the draw when the output surface is lost if we are |
| 909 // waiting for the first draw to unblock the main thread. |
| 871 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW, | 910 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW, |
| 872 state.CommitState()); | 911 state.CommitState()); |
| 873 | 912 EXPECT_ACTION_UPDATE_STATE( |
| 874 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.NextAction()); | 913 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT); |
| 875 state.UpdateState(state.NextAction()); | |
| 876 | 914 |
| 877 // Expect to be told to begin context recreation, independent of | 915 // Expect to be told to begin context recreation, independent of |
| 878 // BeginFrame state. | 916 // BeginFrame state. |
| 879 state.DidEnterBeginFrame(BeginFrameArgs::CreateForTesting()); | 917 EXPECT_EQ(SchedulerStateMachine::BEGIN_FRAME_STATE_IDLE, |
| 918 state.begin_frame_state()); |
| 880 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION, | 919 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION, |
| 881 state.NextAction()); | 920 state.NextAction()); |
| 882 state.DidLeaveBeginFrame(); | 921 |
| 922 state.OnBeginFrame(BeginFrameArgs::CreateForTesting()); |
| 923 EXPECT_EQ(SchedulerStateMachine::BEGIN_FRAME_STATE_INSIDE_BEGIN_FRAME, |
| 924 state.begin_frame_state()); |
| 925 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION, |
| 926 state.NextAction()); |
| 927 |
| 928 state.AdvanceBeginFrameStateWhenNoActionsRemain(); |
| 929 EXPECT_EQ(SchedulerStateMachine::BEGIN_FRAME_STATE_DEADLINE_PENDING, |
| 930 state.begin_frame_state()); |
| 931 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION, |
| 932 state.NextAction()); |
| 933 |
| 934 state.OnBeginFrameDeadline(); |
| 935 EXPECT_EQ(SchedulerStateMachine::BEGIN_FRAME_STATE_INSIDE_DEADLINE, |
| 936 state.begin_frame_state()); |
| 883 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION, | 937 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION, |
| 884 state.NextAction()); | 938 state.NextAction()); |
| 885 } | 939 } |
| 886 | 940 |
| 887 TEST(SchedulerStateMachineTest, | 941 TEST(SchedulerStateMachineTest, |
| 888 TestContextLostWhileCommitInProgressAndAnotherCommitRequested) { | 942 TestContextLostWhileCommitInProgressAndAnotherCommitRequested) { |
| 889 SchedulerSettings default_scheduler_settings; | 943 SchedulerSettings default_scheduler_settings; |
| 890 StateMachine state(default_scheduler_settings); | 944 StateMachine state(default_scheduler_settings); |
| 891 state.SetCanStart(); | 945 state.SetCanStart(); |
| 892 state.UpdateState(state.NextAction()); | 946 state.UpdateState(state.NextAction()); |
| 893 state.DidCreateAndInitializeOutputSurface(); | 947 state.DidCreateAndInitializeOutputSurface(); |
| 894 state.SetVisible(true); | 948 state.SetVisible(true); |
| 895 state.SetCanDraw(true); | 949 state.SetCanDraw(true); |
| 896 | 950 |
| 897 // Get a commit in flight. | 951 // Get a commit in flight. |
| 898 state.SetNeedsCommit(); | 952 state.SetNeedsCommit(); |
| 899 EXPECT_EQ(SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD, | 953 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 900 state.NextAction()); | |
| 901 state.UpdateState(state.NextAction()); | |
| 902 | 954 |
| 903 // Set damage and expect a draw. | 955 // Set damage and expect a draw. |
| 904 state.SetNeedsRedraw(true); | 956 state.SetNeedsRedraw(true); |
| 905 state.DidEnterBeginFrame(BeginFrameArgs::CreateForTesting()); | 957 state.OnBeginFrame(BeginFrameArgs::CreateForTesting()); |
| 906 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.NextAction()); | 958 EXPECT_ACTION_UPDATE_STATE( |
| 907 state.UpdateState(state.NextAction()); | 959 SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD); |
| 908 state.DidLeaveBeginFrame(); | 960 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 961 state.OnBeginFrameDeadline(); |
| 962 EXPECT_ACTION_UPDATE_STATE( |
| 963 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); |
| 964 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 909 | 965 |
| 910 // Cause a lost context while the begin frame is in flight | 966 // Cause a lost context while the begin frame is in flight |
| 911 // for the main thread. | 967 // for the main thread. |
| 912 state.DidLoseOutputSurface(); | 968 state.DidLoseOutputSurface(); |
| 913 | 969 |
| 914 // Ask for another draw and also set needs commit. Expect nothing happens. | 970 // Ask for another draw and also set needs commit. Expect nothing happens. |
| 915 state.SetNeedsRedraw(true); | 971 state.SetNeedsRedraw(true); |
| 916 state.SetNeedsCommit(); | 972 state.SetNeedsCommit(); |
| 917 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); | 973 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 918 | 974 |
| 919 // Finish the frame, and commit. | 975 // Finish the frame, and commit. |
| 920 state.FinishCommit(); | 976 state.FinishCommit(); |
| 921 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction()); | 977 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); |
| 922 state.UpdateState(state.NextAction()); | |
| 923 | |
| 924 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW, | 978 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW, |
| 925 state.CommitState()); | 979 state.CommitState()); |
| 926 | 980 |
| 927 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.NextAction()); | 981 // Because the output surface is missing, we expect the draw to abort. |
| 928 state.UpdateState(state.NextAction()); | 982 EXPECT_ACTION_UPDATE_STATE( |
| 983 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT); |
| 929 | 984 |
| 930 // Expect to be told to begin context recreation, independent of | 985 // Expect to be told to begin context recreation, independent of |
| 931 // BeginFrame state | 986 // BeginFrame state |
| 932 state.DidEnterBeginFrame(BeginFrameArgs::CreateForTesting()); | 987 EXPECT_EQ(SchedulerStateMachine::BEGIN_FRAME_STATE_IDLE, |
| 988 state.begin_frame_state()); |
| 933 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION, | 989 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION, |
| 934 state.NextAction()); | 990 state.NextAction()); |
| 935 state.DidLeaveBeginFrame(); | 991 |
| 992 state.OnBeginFrame(BeginFrameArgs::CreateForTesting()); |
| 993 EXPECT_EQ(SchedulerStateMachine::BEGIN_FRAME_STATE_INSIDE_BEGIN_FRAME, |
| 994 state.begin_frame_state()); |
| 936 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION, | 995 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION, |
| 937 state.NextAction()); | 996 state.NextAction()); |
| 997 |
| 998 state.AdvanceBeginFrameStateWhenNoActionsRemain(); |
| 999 EXPECT_EQ(SchedulerStateMachine::BEGIN_FRAME_STATE_DEADLINE_PENDING, |
| 1000 state.begin_frame_state()); |
| 1001 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION, |
| 1002 state.NextAction()); |
| 1003 |
| 1004 state.OnBeginFrameDeadline(); |
| 1005 EXPECT_EQ(SchedulerStateMachine::BEGIN_FRAME_STATE_INSIDE_DEADLINE, |
| 1006 state.begin_frame_state()); |
| 1007 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION, |
| 1008 state.NextAction()); |
| 1009 |
| 1010 // After we get a new output surface, the commit flow should start. |
| 1011 EXPECT_ACTION_UPDATE_STATE( |
| 1012 SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION); |
| 1013 state.DidCreateAndInitializeOutputSurface(); |
| 1014 state.OnBeginFrame(BeginFrameArgs::CreateForTesting()); |
| 1015 EXPECT_ACTION_UPDATE_STATE( |
| 1016 SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD); |
| 1017 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 1018 state.FinishCommit(); |
| 1019 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); |
| 1020 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 1021 state.OnBeginFrameDeadline(); |
| 1022 EXPECT_ACTION_UPDATE_STATE( |
| 1023 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); |
| 1024 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 938 } | 1025 } |
| 939 | 1026 |
| 940 TEST(SchedulerStateMachineTest, TestFinishAllRenderingWhileContextLost) { | 1027 TEST(SchedulerStateMachineTest, TestFinishAllRenderingWhileContextLost) { |
| 941 SchedulerSettings default_scheduler_settings; | 1028 SchedulerSettings default_scheduler_settings; |
| 942 StateMachine state(default_scheduler_settings); | 1029 StateMachine state(default_scheduler_settings); |
| 943 state.SetCanStart(); | 1030 state.SetCanStart(); |
| 944 state.UpdateState(state.NextAction()); | 1031 state.UpdateState(state.NextAction()); |
| 945 state.DidCreateAndInitializeOutputSurface(); | 1032 state.DidCreateAndInitializeOutputSurface(); |
| 946 state.SetVisible(true); | 1033 state.SetVisible(true); |
| 947 state.SetCanDraw(true); | 1034 state.SetCanDraw(true); |
| 948 | 1035 |
| 949 // Cause a lost context lost. | 1036 // Cause a lost context lost. |
| 950 state.DidLoseOutputSurface(); | 1037 state.DidLoseOutputSurface(); |
| 951 | 1038 |
| 952 // Ask a forced redraw and verify it ocurrs. | 1039 // Ask a forced redraw for readback and verify it ocurrs. |
| 953 state.SetNeedsForcedRedraw(true); | 1040 state.SetCommitState( |
| 954 state.DidEnterBeginFrame(BeginFrameArgs::CreateForTesting()); | 1041 SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW); |
| 955 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_FORCED, state.NextAction()); | 1042 state.SetNeedsForcedRedrawForReadback(); |
| 956 state.DidLeaveBeginFrame(); | 1043 state.OnBeginFrame(BeginFrameArgs::CreateForTesting()); |
| 1044 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_READBACK); |
| 1045 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 957 | 1046 |
| 958 // Clear the forced redraw bit. | 1047 // Forced redraws for readbacks need to be followed by a new commit |
| 959 state.SetNeedsForcedRedraw(false); | 1048 // to replace the readback commit. |
| 1049 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, |
| 1050 state.CommitState()); |
| 1051 state.FinishCommit(); |
| 1052 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); |
| 1053 |
| 1054 // We don't yet have an output surface, so we the draw and swap should abort. |
| 1055 EXPECT_ACTION_UPDATE_STATE( |
| 1056 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT); |
| 960 | 1057 |
| 961 // Expect to be told to begin context recreation, independent of | 1058 // Expect to be told to begin context recreation, independent of |
| 962 // BeginFrame state | 1059 // BeginFrame state |
| 1060 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState()); |
| 963 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION, | 1061 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION, |
| 964 state.NextAction()); | 1062 state.NextAction()); |
| 965 state.UpdateState(state.NextAction()); | |
| 966 | 1063 |
| 967 // Ask a forced redraw and verify it ocurrs. | 1064 state.OnBeginFrameDeadline(); |
| 968 state.SetNeedsForcedRedraw(true); | 1065 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION, |
| 969 state.DidEnterBeginFrame(BeginFrameArgs::CreateForTesting()); | 1066 state.NextAction()); |
| 970 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_FORCED, state.NextAction()); | 1067 |
| 971 state.DidLeaveBeginFrame(); | 1068 // Ask a readback and verify it occurs. |
| 1069 state.SetCommitState( |
| 1070 SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW); |
| 1071 state.SetNeedsForcedRedrawForReadback(); |
| 1072 EXPECT_ACTION_UPDATE_STATE( |
| 1073 SchedulerStateMachine::ACTION_DRAW_AND_READBACK); |
| 1074 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 972 } | 1075 } |
| 973 | 1076 |
| 974 TEST(SchedulerStateMachineTest, DontDrawBeforeCommitAfterLostOutputSurface) { | 1077 TEST(SchedulerStateMachineTest, DontDrawBeforeCommitAfterLostOutputSurface) { |
| 975 SchedulerSettings default_scheduler_settings; | 1078 SchedulerSettings default_scheduler_settings; |
| 976 StateMachine state(default_scheduler_settings); | 1079 StateMachine state(default_scheduler_settings); |
| 977 state.SetCanStart(); | 1080 state.SetCanStart(); |
| 978 state.UpdateState(state.NextAction()); | 1081 state.UpdateState(state.NextAction()); |
| 979 state.DidCreateAndInitializeOutputSurface(); | 1082 state.DidCreateAndInitializeOutputSurface(); |
| 980 state.SetVisible(true); | 1083 state.SetVisible(true); |
| 981 state.SetCanDraw(true); | 1084 state.SetCanDraw(true); |
| 982 | 1085 |
| 983 state.SetNeedsRedraw(true); | 1086 state.SetNeedsRedraw(true); |
| 984 | 1087 |
| 985 // Cause a lost output surface, and restore it. | 1088 // Cause a lost output surface, and restore it. |
| 986 state.DidLoseOutputSurface(); | 1089 state.DidLoseOutputSurface(); |
| 987 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION, | 1090 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION, |
| 988 state.NextAction()); | 1091 state.NextAction()); |
| 989 state.UpdateState(state.NextAction()); | 1092 state.UpdateState(state.NextAction()); |
| 990 state.DidCreateAndInitializeOutputSurface(); | 1093 state.DidCreateAndInitializeOutputSurface(); |
| 991 | 1094 |
| 992 EXPECT_FALSE(state.RedrawPending()); | 1095 EXPECT_FALSE(state.RedrawPending()); |
| 1096 state.OnBeginFrame(BeginFrameArgs::CreateForTesting()); |
| 993 EXPECT_EQ(SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD, | 1097 EXPECT_EQ(SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD, |
| 994 state.NextAction()); | 1098 state.NextAction()); |
| 995 } | 1099 } |
| 996 | 1100 |
| 997 TEST(SchedulerStateMachineTest, | 1101 TEST(SchedulerStateMachineTest, |
| 998 TestSendBeginFrameToMainThreadWhenInvisibleAndForceCommit) { | 1102 TestSendBeginFrameToMainThreadWhenInvisibleAndForceCommit) { |
| 999 SchedulerSettings default_scheduler_settings; | 1103 SchedulerSettings default_scheduler_settings; |
| 1000 StateMachine state(default_scheduler_settings); | 1104 StateMachine state(default_scheduler_settings); |
| 1001 state.SetCanStart(); | 1105 state.SetCanStart(); |
| 1002 state.UpdateState(state.NextAction()); | 1106 state.UpdateState(state.NextAction()); |
| 1003 state.DidCreateAndInitializeOutputSurface(); | 1107 state.DidCreateAndInitializeOutputSurface(); |
| 1004 state.SetVisible(false); | 1108 state.SetVisible(false); |
| 1005 state.SetNeedsCommit(); | 1109 state.SetNeedsCommit(); |
| 1006 state.SetNeedsForcedCommit(); | 1110 state.SetNeedsForcedCommitForReadback(); |
| 1007 EXPECT_EQ(SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD, | 1111 EXPECT_EQ(SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD, |
| 1008 state.NextAction()); | 1112 state.NextAction()); |
| 1009 } | 1113 } |
| 1010 | 1114 |
| 1011 TEST(SchedulerStateMachineTest, | 1115 TEST(SchedulerStateMachineTest, |
| 1012 TestSendBeginFrameToMainThreadWhenCanStartFalseAndForceCommit) { | 1116 TestSendBeginFrameToMainThreadWhenCanStartFalseAndForceCommit) { |
| 1013 SchedulerSettings default_scheduler_settings; | 1117 SchedulerSettings default_scheduler_settings; |
| 1014 StateMachine state(default_scheduler_settings); | 1118 StateMachine state(default_scheduler_settings); |
| 1015 state.SetVisible(true); | 1119 state.SetVisible(true); |
| 1016 state.SetCanDraw(true); | 1120 state.SetCanDraw(true); |
| 1017 state.SetNeedsCommit(); | 1121 state.SetNeedsCommit(); |
| 1018 state.SetNeedsForcedCommit(); | 1122 state.SetNeedsForcedCommitForReadback(); |
| 1019 EXPECT_EQ(SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD, | 1123 EXPECT_EQ(SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD, |
| 1020 state.NextAction()); | 1124 state.NextAction()); |
| 1021 } | 1125 } |
| 1022 | 1126 |
| 1023 TEST(SchedulerStateMachineTest, TestFinishCommitWhenCommitInProgress) { | 1127 TEST(SchedulerStateMachineTest, TestFinishCommitWhenCommitInProgress) { |
| 1024 SchedulerSettings default_scheduler_settings; | 1128 SchedulerSettings default_scheduler_settings; |
| 1025 StateMachine state(default_scheduler_settings); | 1129 StateMachine state(default_scheduler_settings); |
| 1026 state.SetCanStart(); | 1130 state.SetCanStart(); |
| 1027 state.UpdateState(state.NextAction()); | 1131 state.UpdateState(state.NextAction()); |
| 1028 state.DidCreateAndInitializeOutputSurface(); | 1132 state.DidCreateAndInitializeOutputSurface(); |
| 1029 state.SetVisible(false); | 1133 state.SetVisible(false); |
| 1030 state.SetCommitState(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS); | 1134 state.SetCommitState(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS); |
| 1031 state.SetNeedsCommit(); | 1135 state.SetNeedsCommit(); |
| 1032 | 1136 |
| 1033 state.FinishCommit(); | 1137 state.FinishCommit(); |
| 1034 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction()); | 1138 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction()); |
| 1035 state.UpdateState(state.NextAction()); | 1139 state.UpdateState(state.NextAction()); |
| 1036 | 1140 |
| 1037 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW, | 1141 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW, |
| 1038 state.CommitState()); | 1142 state.CommitState()); |
| 1039 | 1143 |
| 1040 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); | 1144 // We should abort the draw because we are not visible. |
| 1145 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT, |
| 1146 state.NextAction()); |
| 1041 } | 1147 } |
| 1042 | 1148 |
| 1043 TEST(SchedulerStateMachineTest, TestFinishCommitWhenForcedCommitInProgress) { | 1149 TEST(SchedulerStateMachineTest, TestFinishCommitWhenForcedCommitInProgress) { |
| 1044 SchedulerSettings default_scheduler_settings; | 1150 SchedulerSettings default_scheduler_settings; |
| 1045 StateMachine state(default_scheduler_settings); | 1151 StateMachine state(default_scheduler_settings); |
| 1046 state.SetCanStart(); | 1152 state.SetCanStart(); |
| 1047 state.UpdateState(state.NextAction()); | 1153 state.UpdateState(state.NextAction()); |
| 1048 state.DidCreateAndInitializeOutputSurface(); | 1154 state.DidCreateAndInitializeOutputSurface(); |
| 1049 state.SetVisible(false); | 1155 state.SetVisible(false); |
| 1050 state.SetCommitState(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS); | 1156 state.SetCommitState(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS); |
| 1051 state.SetNeedsCommit(); | 1157 state.SetNeedsCommit(); |
| 1052 state.SetNeedsForcedCommit(); | 1158 state.SetNeedsForcedCommitForReadback(); |
| 1053 | 1159 |
| 1160 // The commit for readback interupts the normal commit. |
| 1054 state.FinishCommit(); | 1161 state.FinishCommit(); |
| 1055 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction()); | 1162 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); |
| 1056 state.UpdateState(state.NextAction()); | |
| 1057 | 1163 |
| 1058 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_FORCED_DRAW, | 1164 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW, |
| 1059 state.CommitState()); | 1165 state.CommitState()); |
| 1166 EXPECT_ACTION_UPDATE_STATE( |
| 1167 SchedulerStateMachine::ACTION_DRAW_AND_READBACK); |
| 1060 | 1168 |
| 1061 // If we are waiting for forced draw then we know a begin frame is already | 1169 // When the readback interrupts the normal commit, we should not get |
| 1062 // in flight for the main thread. | 1170 // another BeginFrame on the impl thread when the readback completes. |
| 1063 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); | 1171 EXPECT_NE(SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD, |
| 1172 state.NextAction()); |
| 1173 |
| 1174 // The normal commit can then proceed. |
| 1175 state.FinishCommit(); |
| 1176 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); |
| 1064 } | 1177 } |
| 1065 | 1178 |
| 1066 TEST(SchedulerStateMachineTest, TestSendBeginFrameToMainThreadWhenContextLost) { | 1179 TEST(SchedulerStateMachineTest, TestSendBeginFrameToMainThreadWhenContextLost) { |
| 1067 SchedulerSettings default_scheduler_settings; | 1180 SchedulerSettings default_scheduler_settings; |
| 1068 StateMachine state(default_scheduler_settings); | 1181 StateMachine state(default_scheduler_settings); |
| 1069 state.SetCanStart(); | 1182 state.SetCanStart(); |
| 1070 state.UpdateState(state.NextAction()); | 1183 state.UpdateState(state.NextAction()); |
| 1071 state.DidCreateAndInitializeOutputSurface(); | 1184 state.DidCreateAndInitializeOutputSurface(); |
| 1072 state.SetVisible(true); | 1185 state.SetVisible(true); |
| 1073 state.SetCanDraw(true); | 1186 state.SetCanDraw(true); |
| 1074 state.SetNeedsCommit(); | 1187 state.SetNeedsCommit(); |
| 1075 state.SetNeedsForcedCommit(); | 1188 state.SetNeedsForcedCommitForReadback(); |
| 1076 state.DidLoseOutputSurface(); | 1189 state.DidLoseOutputSurface(); |
| 1077 EXPECT_EQ(SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD, | 1190 EXPECT_EQ(SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD, |
| 1078 state.NextAction()); | 1191 state.NextAction()); |
| 1079 } | 1192 } |
| 1080 | 1193 |
| 1081 TEST(SchedulerStateMachineTest, TestImmediateFinishCommit) { | 1194 TEST(SchedulerStateMachineTest, TestImmediateFinishCommit) { |
| 1082 SchedulerSettings default_scheduler_settings; | 1195 SchedulerSettings default_scheduler_settings; |
| 1083 StateMachine state(default_scheduler_settings); | 1196 StateMachine state(default_scheduler_settings); |
| 1084 state.SetCanStart(); | 1197 state.SetCanStart(); |
| 1085 state.UpdateState(state.NextAction()); | 1198 state.UpdateState(state.NextAction()); |
| 1086 state.DidCreateAndInitializeOutputSurface(); | 1199 state.DidCreateAndInitializeOutputSurface(); |
| 1087 state.SetVisible(true); | 1200 state.SetVisible(true); |
| 1088 state.SetCanDraw(true); | 1201 state.SetCanDraw(true); |
| 1089 | 1202 |
| 1090 // Schedule a forced frame, commit it, draw it. | 1203 // Schedule a readback, commit it, draw it. |
| 1091 state.SetNeedsCommit(); | 1204 state.SetNeedsCommit(); |
| 1092 state.SetNeedsForcedCommit(); | 1205 state.SetNeedsForcedCommitForReadback(); |
| 1093 state.UpdateState(state.NextAction()); | 1206 EXPECT_ACTION_UPDATE_STATE( |
| 1207 SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD); |
| 1094 state.FinishCommit(); | 1208 state.FinishCommit(); |
| 1095 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction()); | 1209 |
| 1096 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT, | 1210 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT, |
| 1097 state.CommitState()); | 1211 state.CommitState()); |
| 1098 state.UpdateState(state.NextAction()); | 1212 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); |
| 1099 | 1213 |
| 1100 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_FORCED_DRAW, | 1214 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW, |
| 1101 state.CommitState()); | 1215 state.CommitState()); |
| 1102 | 1216 |
| 1103 state.DidEnterBeginFrame(BeginFrameArgs::CreateForTesting()); | 1217 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_READBACK); |
| 1104 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); | |
| 1105 state.SetNeedsForcedRedraw(true); | |
| 1106 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_FORCED, state.NextAction()); | |
| 1107 state.UpdateState(state.NextAction()); | |
| 1108 state.DidDrawIfPossibleCompleted(true); | 1218 state.DidDrawIfPossibleCompleted(true); |
| 1109 state.DidLeaveBeginFrame(); | 1219 |
| 1220 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 1110 | 1221 |
| 1111 // Should be waiting for the normal begin frame from the main thread. | 1222 // Should be waiting for the normal begin frame from the main thread. |
| 1112 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, | 1223 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, |
| 1113 state.CommitState()); | 1224 state.CommitState()); |
| 1114 } | 1225 } |
| 1115 | 1226 |
| 1116 TEST(SchedulerStateMachineTest, TestImmediateFinishCommitDuringCommit) { | 1227 TEST(SchedulerStateMachineTest, TestImmediateFinishCommitDuringCommit) { |
| 1117 SchedulerSettings default_scheduler_settings; | 1228 SchedulerSettings default_scheduler_settings; |
| 1118 StateMachine state(default_scheduler_settings); | 1229 StateMachine state(default_scheduler_settings); |
| 1119 state.SetCanStart(); | 1230 state.SetCanStart(); |
| 1120 state.UpdateState(state.NextAction()); | 1231 state.UpdateState(state.NextAction()); |
| 1121 state.DidCreateAndInitializeOutputSurface(); | 1232 state.DidCreateAndInitializeOutputSurface(); |
| 1122 state.SetVisible(true); | 1233 state.SetVisible(true); |
| 1123 state.SetCanDraw(true); | 1234 state.SetCanDraw(true); |
| 1124 | 1235 |
| 1125 // Start a normal commit. | 1236 // Start a normal commit. |
| 1126 state.SetNeedsCommit(); | 1237 state.SetNeedsCommit(); |
| 1127 state.UpdateState(state.NextAction()); | 1238 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 1128 | 1239 |
| 1129 // Schedule a forced frame, commit it, draw it. | 1240 // Schedule a readback, commit it, draw it. |
| 1130 state.SetNeedsCommit(); | 1241 state.SetNeedsForcedCommitForReadback(); |
| 1131 state.SetNeedsForcedCommit(); | 1242 EXPECT_ACTION_UPDATE_STATE( |
| 1132 state.UpdateState(state.NextAction()); | 1243 SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD); |
| 1133 state.FinishCommit(); | 1244 state.FinishCommit(); |
| 1134 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction()); | |
| 1135 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT, | 1245 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT, |
| 1136 state.CommitState()); | 1246 state.CommitState()); |
| 1137 state.UpdateState(state.NextAction()); | 1247 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); |
| 1138 | 1248 |
| 1139 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_FORCED_DRAW, | 1249 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW, |
| 1140 state.CommitState()); | 1250 state.CommitState()); |
| 1141 | 1251 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_READBACK); |
| 1142 state.DidEnterBeginFrame(BeginFrameArgs::CreateForTesting()); | |
| 1143 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); | |
| 1144 state.SetNeedsForcedRedraw(true); | |
| 1145 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_FORCED, state.NextAction()); | |
| 1146 state.UpdateState(state.NextAction()); | |
| 1147 state.DidDrawIfPossibleCompleted(true); | 1252 state.DidDrawIfPossibleCompleted(true); |
| 1148 state.DidLeaveBeginFrame(); | 1253 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 1149 | 1254 |
| 1150 // Should be waiting for the normal begin frame from the main thread. | 1255 // Should be waiting for the normal begin frame from the main thread. |
| 1151 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, | 1256 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, |
| 1152 state.CommitState()) << state.ToString(); | 1257 state.CommitState()) << state.ToString(); |
| 1153 } | 1258 } |
| 1154 | 1259 |
| 1155 TEST(SchedulerStateMachineTest, | 1260 TEST(SchedulerStateMachineTest, |
| 1156 ImmediateBeginFrameAbortedByMainThreadWhileInvisible) { | 1261 ImmediateBeginFrameAbortedByMainThreadWhileInvisible) { |
| 1157 SchedulerSettings default_scheduler_settings; | 1262 SchedulerSettings default_scheduler_settings; |
| 1158 StateMachine state(default_scheduler_settings); | 1263 StateMachine state(default_scheduler_settings); |
| 1159 state.SetCanStart(); | 1264 state.SetCanStart(); |
| 1160 state.UpdateState(state.NextAction()); | 1265 state.UpdateState(state.NextAction()); |
| 1161 state.DidCreateAndInitializeOutputSurface(); | 1266 state.DidCreateAndInitializeOutputSurface(); |
| 1162 state.SetVisible(true); | 1267 state.SetVisible(true); |
| 1163 state.SetCanDraw(true); | 1268 state.SetCanDraw(true); |
| 1164 | 1269 |
| 1165 state.SetNeedsCommit(); | 1270 state.SetNeedsCommit(); |
| 1166 state.UpdateState(state.NextAction()); | 1271 state.UpdateState(state.NextAction()); |
| 1167 | 1272 |
| 1168 state.SetNeedsCommit(); | 1273 state.SetNeedsCommit(); |
| 1169 state.SetNeedsForcedCommit(); | 1274 state.SetNeedsForcedCommitForReadback(); |
| 1170 state.UpdateState(state.NextAction()); | 1275 EXPECT_ACTION_UPDATE_STATE( |
| 1276 SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD); |
| 1171 state.FinishCommit(); | 1277 state.FinishCommit(); |
| 1172 | 1278 |
| 1173 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction()); | |
| 1174 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT, | 1279 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT, |
| 1175 state.CommitState()); | 1280 state.CommitState()); |
| 1176 state.UpdateState(state.NextAction()); | 1281 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); |
| 1177 | 1282 |
| 1178 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_FORCED_DRAW, | 1283 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW, |
| 1179 state.CommitState()); | 1284 state.CommitState()); |
| 1180 | 1285 |
| 1181 state.DidEnterBeginFrame(BeginFrameArgs::CreateForTesting()); | 1286 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_READBACK); |
| 1182 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); | |
| 1183 state.SetNeedsForcedRedraw(true); | |
| 1184 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_FORCED, state.NextAction()); | |
| 1185 state.UpdateState(state.NextAction()); | |
| 1186 state.DidDrawIfPossibleCompleted(true); | 1287 state.DidDrawIfPossibleCompleted(true); |
| 1187 state.DidLeaveBeginFrame(); | 1288 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 1188 | 1289 |
| 1189 // Should be waiting for the main thread's begin frame. | 1290 // Should be waiting for the main thread's begin frame. |
| 1190 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, | 1291 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, |
| 1191 state.CommitState()) << state.ToString(); | 1292 state.CommitState()) << state.ToString(); |
| 1192 | 1293 |
| 1193 // Become invisible and abort the main thread's begin frame. | 1294 // Become invisible and abort the main thread's begin frame. |
| 1194 state.SetVisible(false); | 1295 state.SetVisible(false); |
| 1195 state.BeginFrameAbortedByMainThread(); | 1296 state.BeginFrameAbortedByMainThread(); |
| 1196 | 1297 |
| 1197 // Should be back in the idle state, but needing a commit. | 1298 // Should be back in the idle state, but needing a commit. |
| 1198 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState()); | 1299 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState()); |
| 1199 EXPECT_TRUE(state.NeedsCommit()); | 1300 EXPECT_TRUE(state.NeedsCommit()); |
| 1200 } | 1301 } |
| 1201 | 1302 |
| 1202 TEST(SchedulerStateMachineTest, ImmediateFinishCommitWhileCantDraw) { | 1303 TEST(SchedulerStateMachineTest, ImmediateFinishCommitWhileCantDraw) { |
| 1203 SchedulerSettings default_scheduler_settings; | 1304 SchedulerSettings default_scheduler_settings; |
| 1204 StateMachine state(default_scheduler_settings); | 1305 StateMachine state(default_scheduler_settings); |
| 1205 state.SetCanStart(); | 1306 state.SetCanStart(); |
| 1206 state.UpdateState(state.NextAction()); | 1307 state.UpdateState(state.NextAction()); |
| 1207 state.DidCreateAndInitializeOutputSurface(); | 1308 state.DidCreateAndInitializeOutputSurface(); |
| 1208 state.SetVisible(true); | 1309 state.SetVisible(true); |
| 1209 state.SetCanDraw(false); | 1310 state.SetCanDraw(false); |
| 1210 | 1311 |
| 1211 state.SetNeedsCommit(); | 1312 state.SetNeedsCommit(); |
| 1212 state.UpdateState(state.NextAction()); | 1313 state.UpdateState(state.NextAction()); |
| 1213 | 1314 |
| 1214 state.SetNeedsCommit(); | 1315 state.SetNeedsCommit(); |
| 1215 state.SetNeedsForcedCommit(); | 1316 state.SetNeedsForcedCommitForReadback(); |
| 1216 state.UpdateState(state.NextAction()); | 1317 state.UpdateState(state.NextAction()); |
| 1217 state.FinishCommit(); | 1318 state.FinishCommit(); |
| 1218 | 1319 |
| 1219 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction()); | 1320 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction()); |
| 1220 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT, | 1321 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT, |
| 1221 state.CommitState()); | 1322 state.CommitState()); |
| 1222 state.UpdateState(state.NextAction()); | 1323 state.UpdateState(state.NextAction()); |
| 1223 | 1324 |
| 1224 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_FORCED_DRAW, | 1325 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW, |
| 1225 state.CommitState()); | 1326 state.CommitState()); |
| 1226 | 1327 |
| 1227 state.DidEnterBeginFrame(BeginFrameArgs::CreateForTesting()); | 1328 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_READBACK); |
| 1228 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); | |
| 1229 state.SetNeedsForcedRedraw(true); | |
| 1230 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_FORCED, state.NextAction()); | |
| 1231 state.UpdateState(state.NextAction()); | |
| 1232 state.DidDrawIfPossibleCompleted(true); | 1329 state.DidDrawIfPossibleCompleted(true); |
| 1233 state.DidLeaveBeginFrame(); | 1330 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 1234 } | 1331 } |
| 1235 | 1332 |
| 1236 TEST(SchedulerStateMachineTest, ReportIfNotDrawing) { | 1333 TEST(SchedulerStateMachineTest, ReportIfNotDrawing) { |
| 1237 SchedulerSettings default_scheduler_settings; | 1334 SchedulerSettings default_scheduler_settings; |
| 1238 SchedulerStateMachine state(default_scheduler_settings); | 1335 StateMachine state(default_scheduler_settings); |
| 1239 | 1336 |
| 1240 state.SetCanDraw(true); | 1337 state.SetCanDraw(true); |
| 1241 state.SetVisible(true); | 1338 state.SetVisible(true); |
| 1242 EXPECT_FALSE(state.DrawSuspendedUntilCommit()); | 1339 EXPECT_FALSE(state.DrawSuspendedUntilCommit()); |
| 1243 | 1340 |
| 1244 state.SetCanDraw(false); | 1341 state.SetCanDraw(false); |
| 1245 state.SetVisible(true); | 1342 state.SetVisible(true); |
| 1246 EXPECT_TRUE(state.DrawSuspendedUntilCommit()); | 1343 EXPECT_TRUE(state.DrawSuspendedUntilCommit()); |
| 1247 | 1344 |
| 1248 state.SetCanDraw(true); | 1345 state.SetCanDraw(true); |
| 1249 state.SetVisible(false); | 1346 state.SetVisible(false); |
| 1250 EXPECT_TRUE(state.DrawSuspendedUntilCommit()); | 1347 EXPECT_TRUE(state.DrawSuspendedUntilCommit()); |
| 1251 | 1348 |
| 1252 state.SetCanDraw(false); | 1349 state.SetCanDraw(false); |
| 1253 state.SetVisible(false); | 1350 state.SetVisible(false); |
| 1254 EXPECT_TRUE(state.DrawSuspendedUntilCommit()); | 1351 EXPECT_TRUE(state.DrawSuspendedUntilCommit()); |
| 1255 | 1352 |
| 1256 state.SetCanDraw(true); | 1353 state.SetCanDraw(true); |
| 1257 state.SetVisible(true); | 1354 state.SetVisible(true); |
| 1258 EXPECT_FALSE(state.DrawSuspendedUntilCommit()); | 1355 EXPECT_FALSE(state.DrawSuspendedUntilCommit()); |
| 1259 } | 1356 } |
| 1260 | 1357 |
| 1261 TEST(SchedulerStateMachineTest, ReportIfNotDrawingFromAcquiredTextures) { | 1358 TEST(SchedulerStateMachineTest, ReportIfNotDrawingFromAcquiredTextures) { |
| 1262 SchedulerSettings default_scheduler_settings; | 1359 SchedulerSettings default_scheduler_settings; |
| 1263 SchedulerStateMachine state(default_scheduler_settings); | 1360 StateMachine state(default_scheduler_settings); |
| 1264 state.SetCanStart(); | 1361 state.SetCanStart(); |
| 1265 state.UpdateState(state.NextAction()); | 1362 state.UpdateState(state.NextAction()); |
| 1266 state.DidCreateAndInitializeOutputSurface(); | 1363 state.DidCreateAndInitializeOutputSurface(); |
| 1267 state.SetCanDraw(true); | 1364 state.SetCanDraw(true); |
| 1268 state.SetVisible(true); | 1365 state.SetVisible(true); |
| 1269 EXPECT_FALSE(state.DrawSuspendedUntilCommit()); | 1366 EXPECT_FALSE(state.DrawSuspendedUntilCommit()); |
| 1270 | 1367 |
| 1271 state.SetMainThreadNeedsLayerTextures(); | 1368 state.SetMainThreadNeedsLayerTextures(); |
| 1272 EXPECT_EQ( | 1369 EXPECT_ACTION_UPDATE_STATE( |
| 1273 SchedulerStateMachine::ACTION_ACQUIRE_LAYER_TEXTURES_FOR_MAIN_THREAD, | 1370 SchedulerStateMachine::ACTION_ACQUIRE_LAYER_TEXTURES_FOR_MAIN_THREAD); |
| 1274 state.NextAction()); | 1371 EXPECT_TRUE(state.DrawSuspendedUntilCommit()); |
| 1275 state.UpdateState(state.NextAction()); | 1372 |
| 1373 state.SetNeedsCommit(); |
| 1374 state.OnBeginFrame(BeginFrameArgs::CreateForTesting()); |
| 1375 EXPECT_ACTION_UPDATE_STATE( |
| 1376 SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD); |
| 1276 EXPECT_TRUE(state.DrawSuspendedUntilCommit()); | 1377 EXPECT_TRUE(state.DrawSuspendedUntilCommit()); |
| 1277 | 1378 |
| 1278 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); | 1379 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); |
| 1279 | |
| 1280 state.SetNeedsCommit(); | |
| 1281 EXPECT_EQ(SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD, | |
| 1282 state.NextAction()); | |
| 1283 | |
| 1284 state.UpdateState(state.NextAction()); | |
| 1285 EXPECT_TRUE(state.DrawSuspendedUntilCommit()); | |
| 1286 | |
| 1287 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); | |
| 1288 | 1380 |
| 1289 state.FinishCommit(); | 1381 state.FinishCommit(); |
| 1290 EXPECT_TRUE(state.DrawSuspendedUntilCommit()); | 1382 EXPECT_TRUE(state.DrawSuspendedUntilCommit()); |
| 1291 | 1383 |
| 1292 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction()); | 1384 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction()); |
| 1293 | 1385 |
| 1294 state.UpdateState(state.NextAction()); | 1386 state.UpdateState(state.NextAction()); |
| 1295 EXPECT_FALSE(state.DrawSuspendedUntilCommit()); | 1387 EXPECT_FALSE(state.DrawSuspendedUntilCommit()); |
| 1296 } | 1388 } |
| 1297 | 1389 |
| 1298 } // namespace | 1390 } // namespace |
| 1299 } // namespace cc | 1391 } // namespace cc |
| OLD | NEW |