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