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