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