| 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_BEGIN_FRAME_STARTING) \ |
| 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_BEGIN_FRAME_STARTING, |
| 40 SchedulerStateMachine::BEGIN_FRAME_STATE_INSIDE_BEGIN_FRAME, |
| 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 void TestFailedDrawsWillEventuallyForceADrawAfterTheNextCommit( |
| 202 TestCommitAfterFailedDrawAllowsDrawInSameFrame) { | 241 bool deadline_scheduling_enabled) { |
| 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) { | |
| 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; |
| 244 scheduler_settings.deadline_scheduling_enabled = deadline_scheduling_enabled; |
| 250 StateMachine state(scheduler_settings); | 245 StateMachine state(scheduler_settings); |
| 251 state.SetCanStart(); | 246 state.SetCanStart(); |
| 252 state.UpdateState(state.NextAction()); | 247 state.UpdateState(state.NextAction()); |
| 253 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); | 248 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); |
| 254 state.SetVisible(true); | 249 state.SetVisible(true); |
| 255 state.SetCanDraw(true); | 250 state.SetCanDraw(true); |
| 256 | 251 |
| 257 // Start a commit. | 252 // Start a commit. |
| 258 state.SetNeedsCommit(); | 253 state.SetNeedsCommit(); |
| 259 EXPECT_EQ(SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD, | 254 if (!deadline_scheduling_enabled) { |
| 260 state.NextAction()); | 255 EXPECT_ACTION_UPDATE_STATE( |
| 261 state.UpdateState( | 256 SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD); |
| 262 SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD); | 257 } |
| 258 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 259 state.OnBeginFrame(BeginFrameArgs::CreateForTesting()); |
| 260 if (deadline_scheduling_enabled) { |
| 261 EXPECT_ACTION_UPDATE_STATE( |
| 262 SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD); |
| 263 } |
| 264 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 263 EXPECT_TRUE(state.CommitPending()); | 265 EXPECT_TRUE(state.CommitPending()); |
| 264 | 266 |
| 265 // Then initiate a draw. | 267 // Then initiate a draw. |
| 266 state.SetNeedsRedraw(true); | 268 state.SetNeedsRedraw(true); |
| 267 EXPECT_TRUE(state.BeginFrameNeededToDrawByImplThread()); | 269 state.OnBeginFrameDeadline(); |
| 268 state.DidEnterBeginFrame(BeginFrameArgs::CreateForTesting()); | 270 EXPECT_ACTION_UPDATE_STATE( |
| 269 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE, | 271 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); |
| 270 state.NextAction()); | |
| 271 EXPECT_TRUE(state.RedrawPending()); | |
| 272 | 272 |
| 273 // Fail the draw. | 273 // 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); | 274 state.DidDrawIfPossibleCompleted(false); |
| 275 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 276 EXPECT_TRUE(state.BeginFrameNeededByImplThread()); |
| 277 EXPECT_TRUE(state.RedrawPending()); | 277 EXPECT_TRUE(state.RedrawPending()); |
| 278 // But the commit is ongoing. | 278 // But the commit is ongoing. |
| 279 EXPECT_TRUE(state.CommitPending()); | 279 EXPECT_TRUE(state.CommitPending()); |
| 280 | 280 |
| 281 // Finish the commit. Note, we should not yet be forcing a draw, but should | 281 // Finish the commit. Note, we should not yet be forcing a draw, but should |
| 282 // continue the commit as usual. | 282 // continue the commit as usual. |
| 283 state.FinishCommit(); | 283 state.FinishCommit(); |
| 284 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction()); | 284 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); |
| 285 state.UpdateState(SchedulerStateMachine::ACTION_COMMIT); | 285 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 286 EXPECT_TRUE(state.RedrawPending()); | 286 EXPECT_TRUE(state.RedrawPending()); |
| 287 | 287 |
| 288 // The redraw should be forced in this case. | 288 // The redraw should be forced at the end of the next BeginFrame. |
| 289 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_FORCED, | 289 state.OnBeginFrame(BeginFrameArgs::CreateForTesting()); |
| 290 state.NextAction()); | 290 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 291 state.OnBeginFrameDeadline(); |
| 292 EXPECT_ACTION_UPDATE_STATE( |
| 293 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_FORCED); |
| 291 } | 294 } |
| 292 | 295 |
| 293 TEST(SchedulerStateMachineTest, | 296 TEST(SchedulerStateMachineTest, |
| 297 TestFailedDrawsWillEventuallyForceADrawAfterTheNextCommit) { |
| 298 bool deadline_scheduling_enabled = false; |
| 299 TestFailedDrawsWillEventuallyForceADrawAfterTheNextCommit( |
| 300 deadline_scheduling_enabled); |
| 301 } |
| 302 |
| 303 TEST(SchedulerStateMachineTest, |
| 304 TestFailedDrawsWillEventuallyForceADrawAfterTheNextCommit_Deadline) { |
| 305 bool deadline_scheduling_enabled = true; |
| 306 TestFailedDrawsWillEventuallyForceADrawAfterTheNextCommit( |
| 307 deadline_scheduling_enabled); |
| 308 } |
| 309 |
| 310 TEST(SchedulerStateMachineTest, |
| 294 TestFailedDrawIsRetriedInNextBeginFrameForImplThread) { | 311 TestFailedDrawIsRetriedInNextBeginFrameForImplThread) { |
| 295 SchedulerSettings default_scheduler_settings; | 312 SchedulerSettings default_scheduler_settings; |
| 296 StateMachine state(default_scheduler_settings); | 313 StateMachine state(default_scheduler_settings); |
| 297 state.SetCanStart(); | 314 state.SetCanStart(); |
| 298 state.UpdateState(state.NextAction()); | 315 state.UpdateState(state.NextAction()); |
| 299 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); | 316 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); |
| 300 state.SetVisible(true); | 317 state.SetVisible(true); |
| 301 state.SetCanDraw(true); | 318 state.SetCanDraw(true); |
| 302 | 319 |
| 303 // Start a draw. | 320 // Start a draw. |
| 304 state.SetNeedsRedraw(true); | 321 state.SetNeedsRedraw(true); |
| 305 EXPECT_TRUE(state.BeginFrameNeededToDrawByImplThread()); | 322 EXPECT_TRUE(state.BeginFrameNeededByImplThread()); |
| 306 state.DidEnterBeginFrame(BeginFrameArgs::CreateForTesting()); | 323 state.OnBeginFrame(BeginFrameArgs::CreateForTesting()); |
| 307 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE, | 324 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 308 state.NextAction()); | 325 state.OnBeginFrameDeadline(); |
| 309 EXPECT_TRUE(state.RedrawPending()); | 326 EXPECT_TRUE(state.RedrawPending()); |
| 327 EXPECT_ACTION_UPDATE_STATE( |
| 328 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); |
| 310 | 329 |
| 311 // Fail the draw. | 330 // 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); | 331 state.DidDrawIfPossibleCompleted(false); |
| 332 EXPECT_ACTION_UPDATE_STATE( |
| 333 SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD); |
| 334 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 315 EXPECT_TRUE(state.RedrawPending()); | 335 EXPECT_TRUE(state.RedrawPending()); |
| 316 | 336 |
| 317 // We should not be trying to draw again now, but we have a commit pending. | 337 // 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, | 338 EXPECT_TRUE(state.BeginFrameNeededByImplThread()); |
| 319 state.NextAction()); | 339 state.OnBeginFrame(BeginFrameArgs::CreateForTesting()); |
| 340 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 320 | 341 |
| 321 state.DidLeaveBeginFrame(); | 342 // We should try to draw again at the end of the next BeginFrame on |
| 322 EXPECT_TRUE(state.BeginFrameNeededToDrawByImplThread()); | 343 // the impl thread. |
| 323 state.DidEnterBeginFrame(BeginFrameArgs::CreateForTesting()); | 344 state.OnBeginFrameDeadline(); |
| 324 | 345 EXPECT_ACTION_UPDATE_STATE( |
| 325 // We should try to draw again in the next begin frame on the impl thread. | 346 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); |
| 326 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE, | 347 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 327 state.NextAction()); | |
| 328 } | 348 } |
| 329 | 349 |
| 330 TEST(SchedulerStateMachineTest, TestDoestDrawTwiceInSameFrame) { | 350 TEST(SchedulerStateMachineTest, TestDoestDrawTwiceInSameFrame) { |
| 331 SchedulerSettings default_scheduler_settings; | 351 SchedulerSettings default_scheduler_settings; |
| 332 StateMachine state(default_scheduler_settings); | 352 StateMachine state(default_scheduler_settings); |
| 333 state.SetCanStart(); | 353 state.SetCanStart(); |
| 334 state.UpdateState(state.NextAction()); | 354 state.UpdateState(state.NextAction()); |
| 335 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); | 355 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); |
| 336 state.SetVisible(true); | 356 state.SetVisible(true); |
| 337 state.SetCanDraw(true); | 357 state.SetCanDraw(true); |
| 338 state.SetNeedsRedraw(true); | 358 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 | 359 |
| 345 // While still in the same begin frame for the impl thread, set needs redraw | 360 // Draw the first frame. |
| 346 // again. This should not redraw. | 361 EXPECT_TRUE(state.BeginFrameNeededByImplThread()); |
| 362 state.OnBeginFrame(BeginFrameArgs::CreateForTesting()); |
| 363 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 364 |
| 365 state.OnBeginFrameDeadline(); |
| 366 EXPECT_ACTION_UPDATE_STATE( |
| 367 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); |
| 368 state.DidDrawIfPossibleCompleted(true); |
| 369 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 370 |
| 371 // Before the next begin frame for the impl thread, set needs redraw |
| 372 // again. This should not redraw until the next begin frame. |
| 347 state.SetNeedsRedraw(true); | 373 state.SetNeedsRedraw(true); |
| 348 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); | 374 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 349 | 375 |
| 350 // Move to another frame. This should now draw. | 376 // Move to another frame. This should now draw. |
| 377 EXPECT_TRUE(state.BeginFrameNeededByImplThread()); |
| 378 state.OnBeginFrame(BeginFrameArgs::CreateForTesting()); |
| 379 |
| 380 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 381 |
| 382 state.OnBeginFrameDeadline(); |
| 383 EXPECT_ACTION_UPDATE_STATE( |
| 384 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); |
| 351 state.DidDrawIfPossibleCompleted(true); | 385 state.DidDrawIfPossibleCompleted(true); |
| 352 state.DidLeaveBeginFrame(); | 386 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 353 EXPECT_TRUE(state.BeginFrameNeededToDrawByImplThread()); | |
| 354 state.DidEnterBeginFrame(BeginFrameArgs::CreateForTesting()); | |
| 355 | 387 |
| 356 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE, | 388 // We just swapped, so we should proactively request another BeginFrame. |
| 357 state.NextAction()); | 389 EXPECT_TRUE(state.BeginFrameNeededByImplThread()); |
| 358 state.UpdateState(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); | |
| 359 state.DidDrawIfPossibleCompleted(true); | |
| 360 EXPECT_FALSE(state.BeginFrameNeededToDrawByImplThread()); | |
| 361 } | 390 } |
| 362 | 391 |
| 363 TEST(SchedulerStateMachineTest, TestNextActionDrawsOnBeginFrame) { | 392 TEST(SchedulerStateMachineTest, TestNextActionDrawsOnBeginFrame) { |
| 364 SchedulerSettings default_scheduler_settings; | 393 SchedulerSettings default_scheduler_settings; |
| 365 | 394 |
| 366 // When not in BeginFrame, or in BeginFrame but not visible, | 395 // When not in BeginFrame deadline, or in BeginFrame deadline but not visible, |
| 367 // don't draw. | 396 // don't draw. |
| 368 size_t num_commit_states = | 397 size_t num_commit_states = |
| 369 sizeof(all_commit_states) / sizeof(SchedulerStateMachine::CommitState); | 398 sizeof(all_commit_states) / sizeof(SchedulerStateMachine::CommitState); |
| 399 size_t num_begin_frame_states = |
| 400 sizeof(all_begin_frame_states) / |
| 401 sizeof(SchedulerStateMachine::BeginFrameState); |
| 370 for (size_t i = 0; i < num_commit_states; ++i) { | 402 for (size_t i = 0; i < num_commit_states; ++i) { |
| 371 for (size_t j = 0; j < 2; ++j) { | 403 for (size_t j = 0; j < num_begin_frame_states; ++j) { |
| 372 StateMachine state(default_scheduler_settings); | 404 StateMachine state(default_scheduler_settings); |
| 373 state.SetCanStart(); | 405 state.SetCanStart(); |
| 374 state.UpdateState(state.NextAction()); | 406 state.UpdateState(state.NextAction()); |
| 375 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); | 407 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); |
| 376 state.SetCommitState(all_commit_states[i]); | 408 state.SetCommitState(all_commit_states[i]); |
| 377 bool visible = j; | 409 state.SetBeginFrameState(all_begin_frame_states[j]); |
| 378 if (!visible) { | 410 bool visible = (all_begin_frame_states[j] != |
| 379 state.DidEnterBeginFrame(BeginFrameArgs::CreateForTesting()); | 411 SchedulerStateMachine::BEGIN_FRAME_STATE_INSIDE_DEADLINE); |
| 380 state.SetVisible(false); | 412 state.SetVisible(visible); |
| 381 } else { | |
| 382 state.SetVisible(true); | |
| 383 } | |
| 384 | 413 |
| 385 // Case 1: needs_commit=false | 414 // Case 1: needs_commit=false |
| 386 EXPECT_NE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE, | 415 EXPECT_NE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE, |
| 387 state.NextAction()); | 416 state.NextAction()); |
| 388 | 417 |
| 389 // Case 2: needs_commit=true | 418 // Case 2: needs_commit=true |
| 390 state.SetNeedsCommit(); | 419 state.SetNeedsCommit(); |
| 391 EXPECT_NE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE, | 420 EXPECT_NE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE, |
| 392 state.NextAction()); | 421 state.NextAction()) |
| 422 << *state.AsValue(); |
| 393 } | 423 } |
| 394 } | 424 } |
| 395 | 425 |
| 396 // When in BeginFrame, or not in BeginFrame but needs_forced_dedraw | 426 // 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 | 427 // SetNeedsForcedRedrawForReadback have been called... except if we're |
| 398 // commit. | 428 // ready to commit, in which case we expect a commit first. |
| 399 for (size_t i = 0; i < num_commit_states; ++i) { | 429 for (size_t i = 0; i < num_commit_states; ++i) { |
| 400 for (size_t j = 0; j < 2; ++j) { | 430 for (size_t j = 0; j < 2; ++j) { |
| 401 bool request_readback = j; | 431 bool request_readback = j; |
| 402 | 432 |
| 403 // Skip invalid states | 433 // Skip invalid states |
| 404 if (request_readback && | 434 if (request_readback && |
| 405 (SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW != | 435 (SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW != |
| 406 all_commit_states[i])) | 436 all_commit_states[i])) |
| 407 continue; | 437 continue; |
| 408 | 438 |
| 409 StateMachine state(default_scheduler_settings); | 439 StateMachine state(default_scheduler_settings); |
| 410 state.SetCanStart(); | 440 state.SetCanStart(); |
| 411 state.UpdateState(state.NextAction()); | 441 state.UpdateState(state.NextAction()); |
| 412 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); | 442 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); |
| 413 state.SetCanDraw(true); | 443 state.SetCanDraw(true); |
| 414 state.SetCommitState(all_commit_states[i]); | 444 state.SetCommitState(all_commit_states[i]); |
| 415 if (!request_readback) { | 445 state.SetBeginFrameState( |
| 416 state.DidEnterBeginFrame(BeginFrameArgs::CreateForTesting()); | 446 SchedulerStateMachine::BEGIN_FRAME_STATE_INSIDE_DEADLINE); |
| 447 if (request_readback) { |
| 448 state.SetNeedsForcedRedrawForReadback(); |
| 449 } else { |
| 417 state.SetNeedsRedraw(true); | 450 state.SetNeedsRedraw(true); |
| 418 state.SetVisible(true); | 451 state.SetVisible(true); |
| 419 } else { | |
| 420 state.SetNeedsForcedRedrawForReadback(); | |
| 421 } | 452 } |
| 422 | 453 |
| 423 SchedulerStateMachine::Action expected_action; | 454 SchedulerStateMachine::Action expected_action; |
| 424 if (all_commit_states[i] != | 455 if (all_commit_states[i] == |
| 425 SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT) { | 456 SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT) { |
| 457 expected_action = SchedulerStateMachine::ACTION_COMMIT; |
| 458 } else if (request_readback) { |
| 459 if (all_commit_states[i] == |
| 460 SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW) |
| 461 expected_action = SchedulerStateMachine::ACTION_DRAW_AND_READBACK; |
| 462 else |
| 463 expected_action = SchedulerStateMachine::ACTION_NONE; |
| 464 } else { |
| 426 expected_action = | 465 expected_action = |
| 427 request_readback | 466 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 } | 467 } |
| 433 | 468 |
| 434 // Case 1: needs_commit=false. | 469 // Case 1: needs_commit=false. |
| 435 EXPECT_NE(state.BeginFrameNeededToDrawByImplThread(), request_readback) | 470 EXPECT_NE(state.BeginFrameNeededByImplThread(), request_readback) |
| 436 << *state.AsValue(); | 471 << *state.AsValue(); |
| 437 EXPECT_EQ(expected_action, state.NextAction()) << *state.AsValue(); | 472 EXPECT_EQ(expected_action, state.NextAction()) << *state.AsValue(); |
| 438 | 473 |
| 439 // Case 2: needs_commit=true. | 474 // Case 2: needs_commit=true. |
| 440 state.SetNeedsCommit(); | 475 state.SetNeedsCommit(); |
| 441 EXPECT_NE(state.BeginFrameNeededToDrawByImplThread(), request_readback) | 476 EXPECT_NE(state.BeginFrameNeededByImplThread(), request_readback) |
| 442 << *state.AsValue(); | 477 << *state.AsValue(); |
| 443 EXPECT_EQ(expected_action, state.NextAction()) << *state.AsValue(); | 478 EXPECT_EQ(expected_action, state.NextAction()) << *state.AsValue(); |
| 444 } | 479 } |
| 445 } | 480 } |
| 446 } | 481 } |
| 447 | 482 |
| 448 TEST(SchedulerStateMachineTest, TestNoCommitStatesRedrawWhenInvisible) { | 483 TEST(SchedulerStateMachineTest, TestNoCommitStatesRedrawWhenInvisible) { |
| 449 SchedulerSettings default_scheduler_settings; | 484 SchedulerSettings default_scheduler_settings; |
| 450 | 485 |
| 451 size_t num_commit_states = | 486 size_t num_commit_states = |
| 452 sizeof(all_commit_states) / sizeof(SchedulerStateMachine::CommitState); | 487 sizeof(all_commit_states) / sizeof(SchedulerStateMachine::CommitState); |
| 453 for (size_t i = 0; i < num_commit_states; ++i) { | 488 for (size_t i = 0; i < num_commit_states; ++i) { |
| 454 // There shouldn't be any drawing regardless of BeginFrame. | 489 // There shouldn't be any drawing regardless of BeginFrame. |
| 455 for (size_t j = 0; j < 2; ++j) { | 490 for (size_t j = 0; j < 2; ++j) { |
| 456 StateMachine state(default_scheduler_settings); | 491 StateMachine state(default_scheduler_settings); |
| 457 state.SetCanStart(); | 492 state.SetCanStart(); |
| 458 state.UpdateState(state.NextAction()); | 493 state.UpdateState(state.NextAction()); |
| 459 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); | 494 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); |
| 460 state.SetCommitState(all_commit_states[i]); | 495 state.SetCommitState(all_commit_states[i]); |
| 461 state.SetVisible(false); | 496 state.SetVisible(false); |
| 462 state.SetNeedsRedraw(true); | 497 state.SetNeedsRedraw(true); |
| 463 if (j == 1) | 498 if (j == 1) { |
| 464 state.DidEnterBeginFrame(BeginFrameArgs::CreateForTesting()); | 499 state.SetBeginFrameState( |
| 500 SchedulerStateMachine::BEGIN_FRAME_STATE_INSIDE_DEADLINE); |
| 501 } |
| 465 | 502 |
| 466 // Case 1: needs_commit=false. | 503 // Case 1: needs_commit=false. |
| 467 EXPECT_NE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE, | 504 EXPECT_NE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE, |
| 468 state.NextAction()); | 505 state.NextAction()); |
| 469 | 506 |
| 470 // Case 2: needs_commit=true. | 507 // Case 2: needs_commit=true. |
| 471 state.SetNeedsCommit(); | 508 state.SetNeedsCommit(); |
| 472 EXPECT_NE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE, | 509 EXPECT_NE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE, |
| 473 state.NextAction()); | 510 state.NextAction()) |
| 511 << *state.AsValue(); |
| 474 } | 512 } |
| 475 } | 513 } |
| 476 } | 514 } |
| 477 | 515 |
| 478 TEST(SchedulerStateMachineTest, TestCanRedraw_StopsDraw) { | 516 TEST(SchedulerStateMachineTest, TestCanRedraw_StopsDraw) { |
| 479 SchedulerSettings default_scheduler_settings; | 517 SchedulerSettings default_scheduler_settings; |
| 480 | 518 |
| 481 size_t num_commit_states = | 519 size_t num_commit_states = |
| 482 sizeof(all_commit_states) / sizeof(SchedulerStateMachine::CommitState); | 520 sizeof(all_commit_states) / sizeof(SchedulerStateMachine::CommitState); |
| 483 for (size_t i = 0; i < num_commit_states; ++i) { | 521 for (size_t i = 0; i < num_commit_states; ++i) { |
| 484 // There shouldn't be any drawing regardless of BeginFrame. | 522 // There shouldn't be any drawing regardless of BeginFrame. |
| 485 for (size_t j = 0; j < 2; ++j) { | 523 for (size_t j = 0; j < 2; ++j) { |
| 486 StateMachine state(default_scheduler_settings); | 524 StateMachine state(default_scheduler_settings); |
| 487 state.SetCanStart(); | 525 state.SetCanStart(); |
| 488 state.UpdateState(state.NextAction()); | 526 state.UpdateState(state.NextAction()); |
| 489 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); | 527 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); |
| 490 state.SetCommitState(all_commit_states[i]); | 528 state.SetCommitState(all_commit_states[i]); |
| 491 state.SetVisible(false); | 529 state.SetVisible(false); |
| 492 state.SetNeedsRedraw(true); | 530 state.SetNeedsRedraw(true); |
| 493 if (j == 1) | 531 if (j == 1) |
| 494 state.DidEnterBeginFrame(BeginFrameArgs::CreateForTesting()); | 532 state.OnBeginFrame(BeginFrameArgs::CreateForTesting()); |
| 495 | 533 |
| 496 state.SetCanDraw(false); | 534 state.SetCanDraw(false); |
| 497 EXPECT_NE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE, | 535 EXPECT_NE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE, |
| 498 state.NextAction()); | 536 state.NextAction()); |
| 499 } | 537 } |
| 500 } | 538 } |
| 501 } | 539 } |
| 502 | 540 |
| 503 TEST(SchedulerStateMachineTest, | 541 TEST(SchedulerStateMachineTest, |
| 504 TestCanRedrawWithWaitingForFirstDrawMakesProgress) { | 542 TestCanRedrawWithWaitingForFirstDrawMakesProgress) { |
| 505 SchedulerSettings default_scheduler_settings; | 543 SchedulerSettings default_scheduler_settings; |
| 506 StateMachine state(default_scheduler_settings); | 544 StateMachine state(default_scheduler_settings); |
| 507 state.SetCanStart(); | 545 state.SetCanStart(); |
| 508 state.UpdateState(state.NextAction()); | 546 state.UpdateState(state.NextAction()); |
| 509 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); | 547 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); |
| 510 | 548 |
| 511 state.SetVisible(true); | 549 state.SetCommitState( |
| 512 state.SetNeedsCommit(); | 550 SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW); |
| 513 EXPECT_ACTION_UPDATE_STATE( | 551 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(); | 552 state.SetNeedsCommit(); |
| 521 state.SetNeedsRedraw(true); | 553 state.SetNeedsRedraw(true); |
| 522 state.SetVisible(true); | 554 state.SetVisible(true); |
| 523 state.SetCanDraw(false); | 555 state.SetCanDraw(false); |
| 524 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT) | 556 state.OnBeginFrame(BeginFrameArgs::CreateForTesting()); |
| 525 | 557 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT); |
| 526 state.DidEnterBeginFrame(BeginFrameArgs::CreateForTesting()); | |
| 527 EXPECT_ACTION_UPDATE_STATE( | 558 EXPECT_ACTION_UPDATE_STATE( |
| 528 SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD); | 559 SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD); |
| 529 state.DidLeaveBeginFrame(); | 560 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 561 state.FinishCommit(); |
| 562 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); |
| 563 state.OnBeginFrameDeadline(); |
| 564 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT); |
| 530 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | 565 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 531 } | 566 } |
| 532 | 567 |
| 533 TEST(SchedulerStateMachineTest, TestsetNeedsCommitIsNotLost) { | 568 TEST(SchedulerStateMachineTest, TestsetNeedsCommitIsNotLost) { |
| 534 SchedulerSettings default_scheduler_settings; | 569 SchedulerSettings default_scheduler_settings; |
| 535 StateMachine state(default_scheduler_settings); | 570 StateMachine state(default_scheduler_settings); |
| 536 state.SetCanStart(); | 571 state.SetCanStart(); |
| 537 state.UpdateState(state.NextAction()); | 572 state.UpdateState(state.NextAction()); |
| 538 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); | 573 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); |
| 539 state.SetNeedsCommit(); | 574 state.SetNeedsCommit(); |
| 540 state.SetVisible(true); | 575 state.SetVisible(true); |
| 541 state.SetCanDraw(true); | 576 state.SetCanDraw(true); |
| 542 | 577 |
| 578 EXPECT_TRUE(state.BeginFrameNeededByImplThread()); |
| 579 |
| 543 // Begin the frame. | 580 // Begin the frame. |
| 544 EXPECT_EQ(SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD, | 581 state.OnBeginFrame(BeginFrameArgs::CreateForTesting()); |
| 545 state.NextAction()); | 582 EXPECT_ACTION_UPDATE_STATE( |
| 546 state.UpdateState(state.NextAction()); | 583 SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD); |
| 547 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, | 584 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, |
| 548 state.CommitState()); | 585 state.CommitState()); |
| 549 | 586 |
| 550 // Now, while the frame is in progress, set another commit. | 587 // Now, while the frame is in progress, set another commit. |
| 551 state.SetNeedsCommit(); | 588 state.SetNeedsCommit(); |
| 552 EXPECT_TRUE(state.NeedsCommit()); | 589 EXPECT_TRUE(state.NeedsCommit()); |
| 553 | 590 |
| 554 // Let the frame finish. | 591 // Let the frame finish. |
| 555 state.FinishCommit(); | 592 state.FinishCommit(); |
| 556 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT, | 593 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT, |
| 557 state.CommitState()); | 594 state.CommitState()); |
| 558 | 595 |
| 559 // Expect to commit regardless of BeginFrame state. | 596 // Expect to commit regardless of BeginFrame state. |
| 560 state.DidLeaveBeginFrame(); | 597 EXPECT_EQ(SchedulerStateMachine::BEGIN_FRAME_STATE_BEGIN_FRAME_STARTING, |
| 598 state.begin_frame_state()); |
| 561 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction()); | 599 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction()); |
| 562 state.DidEnterBeginFrame(BeginFrameArgs::CreateForTesting()); | 600 |
| 601 state.OnBeginFrameDeadlinePending(); |
| 602 EXPECT_EQ(SchedulerStateMachine::BEGIN_FRAME_STATE_INSIDE_BEGIN_FRAME, |
| 603 state.begin_frame_state()); |
| 604 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction()); |
| 605 |
| 606 state.OnBeginFrameDeadline(); |
| 607 EXPECT_EQ(SchedulerStateMachine::BEGIN_FRAME_STATE_INSIDE_DEADLINE, |
| 608 state.begin_frame_state()); |
| 609 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction()); |
| 610 |
| 611 state.OnBeginFrameIdle(); |
| 612 EXPECT_EQ(SchedulerStateMachine::BEGIN_FRAME_STATE_IDLE, |
| 613 state.begin_frame_state()); |
| 614 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction()); |
| 615 |
| 616 state.OnBeginFrame(BeginFrameArgs::CreateForTesting()); |
| 617 EXPECT_EQ(SchedulerStateMachine::BEGIN_FRAME_STATE_BEGIN_FRAME_STARTING, |
| 618 state.begin_frame_state()); |
| 563 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction()); | 619 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction()); |
| 564 | 620 |
| 565 // Commit and make sure we draw on next BeginFrame | 621 // Commit and make sure we draw on next BeginFrame |
| 566 state.UpdateState(SchedulerStateMachine::ACTION_COMMIT); | 622 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); |
| 567 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE, | 623 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 568 state.NextAction()); | 624 state.OnBeginFrameDeadline(); |
| 569 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW, | 625 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW, |
| 570 state.CommitState()); | 626 state.CommitState()); |
| 571 state.UpdateState(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); | 627 EXPECT_ACTION_UPDATE_STATE( |
| 628 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); |
| 572 state.DidDrawIfPossibleCompleted(true); | 629 state.DidDrawIfPossibleCompleted(true); |
| 573 | 630 |
| 574 // Verify that another commit will begin. | 631 // Verify that another commit will start immediately after draw. |
| 575 state.DidLeaveBeginFrame(); | 632 EXPECT_ACTION_UPDATE_STATE( |
| 576 EXPECT_EQ(SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD, | 633 SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD); |
| 577 state.NextAction()); | 634 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 578 } | 635 } |
| 579 | 636 |
| 580 TEST(SchedulerStateMachineTest, TestFullCycle) { | 637 TEST(SchedulerStateMachineTest, TestFullCycle) { |
| 581 SchedulerSettings default_scheduler_settings; | 638 SchedulerSettings default_scheduler_settings; |
| 582 StateMachine state(default_scheduler_settings); | 639 StateMachine state(default_scheduler_settings); |
| 583 state.SetCanStart(); | 640 state.SetCanStart(); |
| 584 state.UpdateState(state.NextAction()); | 641 state.UpdateState(state.NextAction()); |
| 585 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); | 642 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); |
| 586 state.SetVisible(true); | 643 state.SetVisible(true); |
| 587 state.SetCanDraw(true); | 644 state.SetCanDraw(true); |
| 588 | 645 |
| 589 // Start clean and set commit. | 646 // Start clean and set commit. |
| 590 state.SetNeedsCommit(); | 647 state.SetNeedsCommit(); |
| 591 EXPECT_EQ(SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD, | |
| 592 state.NextAction()); | |
| 593 | 648 |
| 594 // Begin the frame. | 649 // Begin the frame. |
| 595 state.UpdateState( | 650 state.OnBeginFrame(BeginFrameArgs::CreateForTesting()); |
| 651 EXPECT_ACTION_UPDATE_STATE( |
| 596 SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD); | 652 SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD); |
| 597 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, | 653 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, |
| 598 state.CommitState()); | 654 state.CommitState()); |
| 599 EXPECT_FALSE(state.NeedsCommit()); | 655 EXPECT_FALSE(state.NeedsCommit()); |
| 600 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); | 656 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 601 | 657 |
| 602 // Tell the scheduler the frame finished. | 658 // Tell the scheduler the frame finished. |
| 603 state.FinishCommit(); | 659 state.FinishCommit(); |
| 604 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT, | 660 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT, |
| 605 state.CommitState()); | 661 state.CommitState()); |
| 606 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction()); | |
| 607 | 662 |
| 608 // Commit. | 663 // Commit. |
| 609 state.UpdateState(SchedulerStateMachine::ACTION_COMMIT); | 664 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); |
| 610 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW, | 665 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW, |
| 611 state.CommitState()); | 666 state.CommitState()); |
| 612 EXPECT_TRUE(state.NeedsRedraw()); | 667 EXPECT_TRUE(state.NeedsRedraw()); |
| 613 | 668 |
| 614 // Expect to do nothing until BeginFrame. | 669 // Expect to do nothing until BeginFrame deadline |
| 615 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); | 670 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 616 | 671 |
| 617 // At BeginFrame, draw. | 672 // At BeginFrame deadline, draw. |
| 618 state.DidEnterBeginFrame(BeginFrameArgs::CreateForTesting()); | 673 state.OnBeginFrameDeadline(); |
| 619 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE, | 674 EXPECT_ACTION_UPDATE_STATE( |
| 620 state.NextAction()); | 675 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); |
| 621 state.UpdateState(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); | |
| 622 state.DidDrawIfPossibleCompleted(true); | 676 state.DidDrawIfPossibleCompleted(true); |
| 623 state.DidLeaveBeginFrame(); | |
| 624 | 677 |
| 625 // Should be synchronized, no draw needed, no action needed. | 678 // Should be synchronized, no draw needed, no action needed. |
| 679 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 626 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState()); | 680 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState()); |
| 627 EXPECT_FALSE(state.NeedsRedraw()); | 681 EXPECT_FALSE(state.NeedsRedraw()); |
| 628 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); | |
| 629 } | 682 } |
| 630 | 683 |
| 631 TEST(SchedulerStateMachineTest, TestFullCycleWithCommitRequestInbetween) { | 684 TEST(SchedulerStateMachineTest, TestFullCycleWithCommitRequestInbetween) { |
| 632 SchedulerSettings default_scheduler_settings; | 685 SchedulerSettings default_scheduler_settings; |
| 633 StateMachine state(default_scheduler_settings); | 686 StateMachine state(default_scheduler_settings); |
| 634 state.SetCanStart(); | 687 state.SetCanStart(); |
| 635 state.UpdateState(state.NextAction()); | 688 state.UpdateState(state.NextAction()); |
| 636 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); | 689 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); |
| 637 state.SetVisible(true); | 690 state.SetVisible(true); |
| 638 state.SetCanDraw(true); | 691 state.SetCanDraw(true); |
| 639 | 692 |
| 640 // Start clean and set commit. | 693 // Start clean and set commit. |
| 641 state.SetNeedsCommit(); | 694 state.SetNeedsCommit(); |
| 642 EXPECT_EQ(SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD, | |
| 643 state.NextAction()); | |
| 644 | 695 |
| 645 // Begin the frame. | 696 // Begin the frame. |
| 646 state.UpdateState( | 697 state.OnBeginFrame(BeginFrameArgs::CreateForTesting()); |
| 698 EXPECT_ACTION_UPDATE_STATE( |
| 647 SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD); | 699 SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD); |
| 648 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, | 700 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, |
| 649 state.CommitState()); | 701 state.CommitState()); |
| 650 EXPECT_FALSE(state.NeedsCommit()); | 702 EXPECT_FALSE(state.NeedsCommit()); |
| 651 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); | 703 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 652 | 704 |
| 653 // Request another commit while the commit is in flight. | 705 // Request another commit while the commit is in flight. |
| 654 state.SetNeedsCommit(); | 706 state.SetNeedsCommit(); |
| 655 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); | 707 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 656 | 708 |
| 657 // Tell the scheduler the frame finished. | 709 // Tell the scheduler the frame finished. |
| 658 state.FinishCommit(); | 710 state.FinishCommit(); |
| 659 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT, | 711 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT, |
| 660 state.CommitState()); | 712 state.CommitState()); |
| 661 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction()); | |
| 662 | 713 |
| 663 // Commit. | 714 // First commit. |
| 664 state.UpdateState(SchedulerStateMachine::ACTION_COMMIT); | 715 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); |
| 665 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW, | 716 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW, |
| 666 state.CommitState()); | 717 state.CommitState()); |
| 667 EXPECT_TRUE(state.NeedsRedraw()); | 718 EXPECT_TRUE(state.NeedsRedraw()); |
| 668 | 719 |
| 669 // Expect to do nothing until BeginFrame. | 720 // Expect to do nothing until BeginFrame deadline. |
| 670 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); | 721 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 671 | 722 |
| 672 // At BeginFrame, draw. | 723 // At BeginFrame deadline, draw. |
| 673 state.DidEnterBeginFrame(BeginFrameArgs::CreateForTesting()); | 724 state.OnBeginFrameDeadline(); |
| 674 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE, | 725 EXPECT_ACTION_UPDATE_STATE( |
| 675 state.NextAction()); | 726 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); |
| 676 state.UpdateState(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); | |
| 677 state.DidDrawIfPossibleCompleted(true); | 727 state.DidDrawIfPossibleCompleted(true); |
| 678 state.DidLeaveBeginFrame(); | |
| 679 | 728 |
| 680 // Should be synchronized, no draw needed, no action needed. | 729 // Should be synchronized, no draw needed, no action needed. |
| 730 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 681 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState()); | 731 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState()); |
| 682 EXPECT_FALSE(state.NeedsRedraw()); | 732 EXPECT_FALSE(state.NeedsRedraw()); |
| 683 EXPECT_EQ(SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD, | 733 |
| 684 state.NextAction()); | 734 // Next BeginFrame should initiate second commit. |
| 735 state.OnBeginFrame(BeginFrameArgs::CreateForTesting()); |
| 736 EXPECT_ACTION_UPDATE_STATE( |
| 737 SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD); |
| 685 } | 738 } |
| 686 | 739 |
| 687 TEST(SchedulerStateMachineTest, TestRequestCommitInvisible) { | 740 TEST(SchedulerStateMachineTest, TestRequestCommitInvisible) { |
| 688 SchedulerSettings default_scheduler_settings; | 741 SchedulerSettings default_scheduler_settings; |
| 689 StateMachine state(default_scheduler_settings); | 742 StateMachine state(default_scheduler_settings); |
| 690 state.SetCanStart(); | 743 state.SetCanStart(); |
| 691 state.UpdateState(state.NextAction()); | 744 state.UpdateState(state.NextAction()); |
| 692 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); | 745 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); |
| 693 state.SetNeedsCommit(); | 746 state.SetNeedsCommit(); |
| 694 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); | 747 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 695 } | 748 } |
| 696 | 749 |
| 697 TEST(SchedulerStateMachineTest, TestGoesInvisibleBeforeFinishCommit) { | 750 TEST(SchedulerStateMachineTest, TestGoesInvisibleBeforeFinishCommit) { |
| 698 SchedulerSettings default_scheduler_settings; | 751 SchedulerSettings default_scheduler_settings; |
| 699 StateMachine state(default_scheduler_settings); | 752 StateMachine state(default_scheduler_settings); |
| 700 state.SetCanStart(); | 753 state.SetCanStart(); |
| 701 state.UpdateState(state.NextAction()); | 754 state.UpdateState(state.NextAction()); |
| 702 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); | 755 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); |
| 703 state.SetVisible(true); | 756 state.SetVisible(true); |
| 704 state.SetCanDraw(true); | 757 state.SetCanDraw(true); |
| 705 | 758 |
| 706 // Start clean and set commit. | 759 // Start clean and set commit. |
| 707 state.SetNeedsCommit(); | 760 state.SetNeedsCommit(); |
| 708 EXPECT_EQ(SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD, | |
| 709 state.NextAction()); | |
| 710 | 761 |
| 711 // Begin the frame while visible. | 762 // Begin the frame while visible. |
| 712 state.UpdateState( | 763 state.OnBeginFrame(BeginFrameArgs::CreateForTesting()); |
| 764 EXPECT_ACTION_UPDATE_STATE( |
| 713 SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD); | 765 SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD); |
| 714 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, | 766 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, |
| 715 state.CommitState()); | 767 state.CommitState()); |
| 716 EXPECT_FALSE(state.NeedsCommit()); | 768 EXPECT_FALSE(state.NeedsCommit()); |
| 717 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); | 769 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 718 | 770 |
| 719 // Become invisible and abort the main thread's begin frame. | 771 // Become invisible and abort the main thread's begin frame. |
| 720 state.SetVisible(false); | 772 state.SetVisible(false); |
| 721 state.BeginFrameAbortedByMainThread(false); | 773 state.BeginFrameAbortedByMainThread(false); |
| 722 | 774 |
| 723 // We should now be back in the idle state as if we didn't start a frame at | 775 // 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()); | 776 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState()); |
| 726 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); | 777 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 778 |
| 779 // We shouldn't do anything on the BeginFrame deadline. |
| 780 state.OnBeginFrameDeadline(); |
| 781 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 727 | 782 |
| 728 // Become visible again. | 783 // Become visible again. |
| 729 state.SetVisible(true); | 784 state.SetVisible(true); |
| 730 | 785 |
| 731 // Although we have aborted on this frame and haven't cancelled the commit | 786 // 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. | 787 // (i.e. need another), don't send another begin frame yet. |
| 733 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState()); | 788 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState()); |
| 734 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); | 789 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); |
| 735 EXPECT_TRUE(state.NeedsCommit()); | 790 EXPECT_TRUE(state.NeedsCommit()); |
| 736 | 791 |
| 737 // Start a new frame. | 792 // Start a new frame. |
| 738 state.DidEnterBeginFrame(BeginFrameArgs::CreateForTesting()); | 793 state.OnBeginFrame(BeginFrameArgs::CreateForTesting()); |
| 739 EXPECT_EQ(SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD, | 794 EXPECT_ACTION_UPDATE_STATE( |
| 740 state.NextAction()); | 795 SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD); |
| 741 | |
| 742 // Begin the frame. | |
| 743 state.UpdateState(state.NextAction()); | |
| 744 | 796 |
| 745 // We should be starting the commit now. | 797 // We should be starting the commit now. |
| 746 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, | 798 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, |
| 747 state.CommitState()); | 799 state.CommitState()); |
| 800 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 748 } | 801 } |
| 749 | 802 |
| 750 TEST(SchedulerStateMachineTest, AbortBeginFrameAndCancelCommit) { | 803 TEST(SchedulerStateMachineTest, AbortBeginFrameAndCancelCommit) { |
| 751 SchedulerSettings default_scheduler_settings; | 804 SchedulerSettings default_scheduler_settings; |
| 752 StateMachine state(default_scheduler_settings); | 805 StateMachine state(default_scheduler_settings); |
| 753 state.SetCanStart(); | 806 state.SetCanStart(); |
| 754 state.UpdateState(state.NextAction()); | 807 state.UpdateState(state.NextAction()); |
| 755 state.DidCreateAndInitializeOutputSurface(); | 808 state.DidCreateAndInitializeOutputSurface(); |
| 756 state.SetVisible(true); | 809 state.SetVisible(true); |
| 757 state.SetCanDraw(true); | 810 state.SetCanDraw(true); |
| 758 | 811 |
| 759 // Get into a begin frame / commit state. | 812 // Get into a begin frame / commit state. |
| 760 state.SetNeedsCommit(); | 813 state.SetNeedsCommit(); |
| 761 EXPECT_EQ(SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD, | 814 |
| 762 state.NextAction()); | 815 EXPECT_ACTION_UPDATE_STATE( |
| 763 state.UpdateState( | |
| 764 SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD); | 816 SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD); |
| 765 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, | 817 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, |
| 766 state.CommitState()); | 818 state.CommitState()); |
| 767 EXPECT_FALSE(state.NeedsCommit()); | 819 EXPECT_FALSE(state.NeedsCommit()); |
| 768 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); | 820 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); |
| 769 | 821 |
| 770 // Abort the commit, cancelling future commits. | 822 // Abort the commit, cancelling future commits. |
| 771 state.BeginFrameAbortedByMainThread(true); | 823 state.BeginFrameAbortedByMainThread(true); |
| 772 | 824 |
| 773 // Verify that another commit doesn't start on the same frame. | 825 // Verify that another commit doesn't start on the same frame. |
| 774 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState()); | 826 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState()); |
| 775 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); | 827 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); |
| 776 EXPECT_FALSE(state.NeedsCommit()); | 828 EXPECT_FALSE(state.NeedsCommit()); |
| 777 | 829 |
| 778 // Start a new frame; draw because this is the first frame since output | 830 // Start a new frame; draw because this is the first frame since output |
| 779 // surface init'd. | 831 // surface init'd. |
| 780 state.DidEnterBeginFrame(BeginFrameArgs::CreateForTesting()); | 832 state.OnBeginFrame(BeginFrameArgs::CreateForTesting()); |
| 781 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE, | 833 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 782 state.NextAction()) | 834 state.OnBeginFrameDeadline(); |
| 783 << *state.AsValue(); | 835 EXPECT_ACTION_UPDATE_STATE( |
| 784 state.DidLeaveBeginFrame(); | 836 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); |
| 785 | 837 |
| 786 // Verify another commit doesn't start on another frame either. | 838 // Verify another commit doesn't start on another frame either. |
| 787 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState()); | 839 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState()); |
| 788 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); | 840 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); |
| 789 EXPECT_FALSE(state.NeedsCommit()); | 841 EXPECT_FALSE(state.NeedsCommit()); |
| 790 | 842 |
| 791 // Verify another commit can start if requested, though. | 843 // Verify another commit can start if requested, though. |
| 792 state.SetNeedsCommit(); | 844 state.SetNeedsCommit(); |
| 793 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState()); | 845 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState()); |
| 794 EXPECT_EQ(SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD, | 846 EXPECT_EQ(SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD, |
| 795 state.NextAction()); | 847 state.NextAction()); |
| 796 } | 848 } |
| 797 | 849 |
| 798 TEST(SchedulerStateMachineTest, TestFirstContextCreation) { | 850 TEST(SchedulerStateMachineTest, TestFirstContextCreation) { |
| 799 SchedulerSettings default_scheduler_settings; | 851 SchedulerSettings default_scheduler_settings; |
| 800 StateMachine state(default_scheduler_settings); | 852 StateMachine state(default_scheduler_settings); |
| 801 state.SetCanStart(); | 853 state.SetCanStart(); |
| 802 state.SetVisible(true); | 854 state.SetVisible(true); |
| 803 state.SetCanDraw(true); | 855 state.SetCanDraw(true); |
| 804 | 856 |
| 805 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION, | 857 EXPECT_ACTION_UPDATE_STATE( |
| 806 state.NextAction()); | 858 SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION); |
| 807 state.UpdateState(state.NextAction()); | 859 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); |
| 808 state.DidCreateAndInitializeOutputSurface(); | 860 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 809 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); | |
| 810 | 861 |
| 811 // Check that the first init does not SetNeedsCommit. | 862 // Check that the first init does not SetNeedsCommit. |
| 863 state.OnBeginFrame(BeginFrameArgs::CreateForTesting()); |
| 864 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 865 state.OnBeginFrameDeadline(); |
| 866 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 867 |
| 868 // Check that a needs commit initiates a BeginFrame to the main thread. |
| 812 state.SetNeedsCommit(); | 869 state.SetNeedsCommit(); |
| 813 EXPECT_NE(SchedulerStateMachine::ACTION_NONE, state.NextAction()); | 870 state.OnBeginFrame(BeginFrameArgs::CreateForTesting()); |
| 871 EXPECT_ACTION_UPDATE_STATE( |
| 872 SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD); |
| 814 } | 873 } |
| 815 | 874 |
| 816 TEST(SchedulerStateMachineTest, TestContextLostWhenCompletelyIdle) { | 875 TEST(SchedulerStateMachineTest, TestContextLostWhenCompletelyIdle) { |
| 817 SchedulerSettings default_scheduler_settings; | 876 SchedulerSettings default_scheduler_settings; |
| 818 StateMachine state(default_scheduler_settings); | 877 StateMachine state(default_scheduler_settings); |
| 819 state.SetCanStart(); | 878 state.SetCanStart(); |
| 820 state.UpdateState(state.NextAction()); | 879 state.UpdateState(state.NextAction()); |
| 821 state.DidCreateAndInitializeOutputSurface(); | 880 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); |
| 822 | 881 |
| 823 state.SetVisible(true); | 882 state.SetVisible(true); |
| 824 state.SetCanDraw(true); | 883 state.SetCanDraw(true); |
| 825 | 884 |
| 826 EXPECT_NE(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION, | 885 EXPECT_NE(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION, |
| 827 state.NextAction()); | 886 state.NextAction()); |
| 828 state.DidLoseOutputSurface(); | 887 state.DidLoseOutputSurface(); |
| 829 | 888 |
| 830 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION, | 889 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION, |
| 831 state.NextAction()); | 890 state.NextAction()); |
| 832 state.UpdateState(state.NextAction()); | 891 state.UpdateState(state.NextAction()); |
| 833 | 892 |
| 834 // Once context recreation begins, nothing should happen. | 893 // Once context recreation begins, nothing should happen. |
| 835 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); | 894 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 836 | 895 |
| 837 // Recreate the context. | 896 // Recreate the context. |
| 838 state.DidCreateAndInitializeOutputSurface(); | 897 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); |
| 839 | 898 |
| 840 // When the context is recreated, we should begin a commit. | 899 // When the context is recreated, we should begin a commit. |
| 841 EXPECT_EQ(SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD, | 900 state.OnBeginFrame(BeginFrameArgs::CreateForTesting()); |
| 842 state.NextAction()); | 901 EXPECT_ACTION_UPDATE_STATE( |
| 843 state.UpdateState(state.NextAction()); | 902 SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD); |
| 844 } | 903 } |
| 845 | 904 |
| 846 TEST(SchedulerStateMachineTest, | 905 TEST(SchedulerStateMachineTest, |
| 847 TestContextLostWhenIdleAndCommitRequestedWhileRecreating) { | 906 TestContextLostWhenIdleAndCommitRequestedWhileRecreating) { |
| 848 SchedulerSettings default_scheduler_settings; | 907 SchedulerSettings default_scheduler_settings; |
| 849 StateMachine state(default_scheduler_settings); | 908 StateMachine state(default_scheduler_settings); |
| 850 state.SetCanStart(); | 909 state.SetCanStart(); |
| 851 state.UpdateState(state.NextAction()); | 910 state.UpdateState(state.NextAction()); |
| 852 state.DidCreateAndInitializeOutputSurface(); | 911 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); |
| 853 state.SetVisible(true); | 912 state.SetVisible(true); |
| 854 state.SetCanDraw(true); | 913 state.SetCanDraw(true); |
| 855 | 914 |
| 856 EXPECT_NE(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION, | 915 EXPECT_NE(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION, |
| 857 state.NextAction()); | 916 state.NextAction()); |
| 858 state.DidLoseOutputSurface(); | 917 state.DidLoseOutputSurface(); |
| 859 | 918 |
| 860 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION, | 919 EXPECT_ACTION_UPDATE_STATE( |
| 861 state.NextAction()); | 920 SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION); |
| 862 state.UpdateState(state.NextAction()); | 921 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 863 | 922 |
| 864 // Once context recreation begins, nothing should happen. | 923 // Once context recreation begins, nothing should happen. |
| 865 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); | 924 state.OnBeginFrame(BeginFrameArgs::CreateForTesting()); |
| 925 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 926 state.OnBeginFrameDeadline(); |
| 927 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 866 | 928 |
| 867 // While context is recreating, commits shouldn't begin. | 929 // While context is recreating, commits shouldn't begin. |
| 868 state.SetNeedsCommit(); | 930 state.SetNeedsCommit(); |
| 869 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); | 931 state.OnBeginFrame(BeginFrameArgs::CreateForTesting()); |
| 932 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 933 state.OnBeginFrameDeadline(); |
| 934 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 870 | 935 |
| 871 // Recreate the context | 936 // Recreate the context |
| 872 state.DidCreateAndInitializeOutputSurface(); | 937 state.DidCreateAndInitializeOutputSurface(); |
| 873 EXPECT_FALSE(state.RedrawPending()); | 938 EXPECT_FALSE(state.RedrawPending()); |
| 874 | 939 |
| 875 // When the context is recreated, we should begin a commit | 940 // When the context is recreated, we should begin a commit |
| 876 EXPECT_EQ(SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD, | 941 EXPECT_ACTION_UPDATE_STATE( |
| 877 state.NextAction()); | 942 SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD); |
| 878 state.UpdateState(state.NextAction()); | 943 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 879 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, | 944 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, |
| 880 state.CommitState()); | 945 state.CommitState()); |
| 881 state.FinishCommit(); | 946 state.FinishCommit(); |
| 882 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction()); | 947 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); |
| 883 state.UpdateState(state.NextAction()); | 948 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 884 // Finishing the first commit after initializing an output surface should | 949 // Finishing the first commit after initializing an output surface should |
| 885 // automatically cause a redraw. | 950 // automatically cause a redraw. |
| 886 EXPECT_TRUE(state.RedrawPending()); | 951 EXPECT_TRUE(state.RedrawPending()); |
| 887 | 952 |
| 888 // Once the context is recreated, whether we draw should be based on | 953 // Once the context is recreated, whether we draw should be based on |
| 889 // SetCanDraw. | 954 // SetCanDraw. |
| 890 state.DidEnterBeginFrame(BeginFrameArgs::CreateForTesting()); | 955 state.OnBeginFrame(BeginFrameArgs::CreateForTesting()); |
| 956 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 957 state.OnBeginFrameDeadline(); |
| 891 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE, | 958 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE, |
| 892 state.NextAction()); | 959 state.NextAction()); |
| 893 state.SetCanDraw(false); | 960 state.SetCanDraw(false); |
| 894 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT, | 961 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT, |
| 895 state.NextAction()); | 962 state.NextAction()); |
| 896 state.SetCanDraw(true); | 963 state.SetCanDraw(true); |
| 897 state.DidLeaveBeginFrame(); | 964 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE, |
| 965 state.NextAction()); |
| 898 } | 966 } |
| 899 | 967 |
| 900 TEST(SchedulerStateMachineTest, TestContextLostWhileCommitInProgress) { | 968 void TestContextLostWhileCommitInProgress(bool deadline_scheduling_enabled) { |
| 901 SchedulerSettings default_scheduler_settings; | 969 SchedulerSettings scheduler_settings; |
| 902 StateMachine state(default_scheduler_settings); | 970 scheduler_settings.deadline_scheduling_enabled = deadline_scheduling_enabled; |
| 971 StateMachine state(scheduler_settings); |
| 903 state.SetCanStart(); | 972 state.SetCanStart(); |
| 904 state.UpdateState(state.NextAction()); | 973 state.UpdateState(state.NextAction()); |
| 905 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); | 974 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); |
| 906 state.SetVisible(true); | 975 state.SetVisible(true); |
| 907 state.SetCanDraw(true); | 976 state.SetCanDraw(true); |
| 908 | 977 |
| 909 // Get a commit in flight. | 978 // Get a commit in flight. |
| 910 state.SetNeedsCommit(); | 979 state.SetNeedsCommit(); |
| 911 EXPECT_EQ(SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD, | 980 if (!deadline_scheduling_enabled) { |
| 912 state.NextAction()); | 981 EXPECT_ACTION_UPDATE_STATE( |
| 913 state.UpdateState(state.NextAction()); | 982 SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD); |
| 983 } |
| 914 | 984 |
| 915 // Set damage and expect a draw. | 985 // Set damage and expect a draw. |
| 916 state.SetNeedsRedraw(true); | 986 state.SetNeedsRedraw(true); |
| 917 state.DidEnterBeginFrame(BeginFrameArgs::CreateForTesting()); | 987 state.OnBeginFrame(BeginFrameArgs::CreateForTesting()); |
| 918 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE, | 988 if (deadline_scheduling_enabled) { |
| 919 state.NextAction()); | 989 EXPECT_ACTION_UPDATE_STATE( |
| 920 state.UpdateState(state.NextAction()); | 990 SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD); |
| 921 state.DidLeaveBeginFrame(); | 991 } |
| 992 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 993 state.OnBeginFrameDeadline(); |
| 994 EXPECT_ACTION_UPDATE_STATE( |
| 995 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); |
| 996 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 922 | 997 |
| 923 // Cause a lost context while the begin frame is in flight | 998 // Cause a lost context while the begin frame is in flight |
| 924 // for the main thread. | 999 // for the main thread. |
| 925 state.DidLoseOutputSurface(); | 1000 state.DidLoseOutputSurface(); |
| 926 | 1001 |
| 927 // Ask for another draw. Expect nothing happens. | 1002 // Ask for another draw. Expect nothing happens. |
| 928 state.SetNeedsRedraw(true); | 1003 state.SetNeedsRedraw(true); |
| 929 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); | 1004 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); |
| 930 | 1005 |
| 931 // Finish the frame, and commit. | 1006 // Finish the frame, and commit. |
| 932 state.FinishCommit(); | 1007 state.FinishCommit(); |
| 933 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction()); | 1008 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); |
| 934 state.UpdateState(state.NextAction()); | |
| 935 | 1009 |
| 1010 // We will abort the draw when the output surface is lost if we are |
| 1011 // waiting for the first draw to unblock the main thread. |
| 936 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW, | 1012 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW, |
| 937 state.CommitState()); | 1013 state.CommitState()); |
| 938 | 1014 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 | 1015 |
| 943 // Expect to be told to begin context recreation, independent of | 1016 // Expect to be told to begin context recreation, independent of |
| 944 // BeginFrame state. | 1017 // BeginFrame state. |
| 945 state.DidEnterBeginFrame(BeginFrameArgs::CreateForTesting()); | 1018 EXPECT_EQ(SchedulerStateMachine::BEGIN_FRAME_STATE_IDLE, |
| 1019 state.begin_frame_state()); |
| 946 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION, | 1020 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION, |
| 947 state.NextAction()); | 1021 state.NextAction()); |
| 948 state.DidLeaveBeginFrame(); | 1022 |
| 1023 state.OnBeginFrame(BeginFrameArgs::CreateForTesting()); |
| 1024 EXPECT_EQ(SchedulerStateMachine::BEGIN_FRAME_STATE_BEGIN_FRAME_STARTING, |
| 1025 state.begin_frame_state()); |
| 1026 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION, |
| 1027 state.NextAction()); |
| 1028 |
| 1029 state.OnBeginFrameDeadlinePending(); |
| 1030 EXPECT_EQ(SchedulerStateMachine::BEGIN_FRAME_STATE_INSIDE_BEGIN_FRAME, |
| 1031 state.begin_frame_state()); |
| 1032 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION, |
| 1033 state.NextAction()); |
| 1034 |
| 1035 state.OnBeginFrameDeadline(); |
| 1036 EXPECT_EQ(SchedulerStateMachine::BEGIN_FRAME_STATE_INSIDE_DEADLINE, |
| 1037 state.begin_frame_state()); |
| 949 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION, | 1038 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION, |
| 950 state.NextAction()); | 1039 state.NextAction()); |
| 951 } | 1040 } |
| 952 | 1041 |
| 953 TEST(SchedulerStateMachineTest, | 1042 TEST(SchedulerStateMachineTest, TestContextLostWhileCommitInProgress) { |
| 954 TestContextLostWhileCommitInProgressAndAnotherCommitRequested) { | 1043 bool deadline_scheduling_enabled = false; |
| 955 SchedulerSettings default_scheduler_settings; | 1044 TestContextLostWhileCommitInProgress(deadline_scheduling_enabled); |
| 956 StateMachine state(default_scheduler_settings); | 1045 } |
| 1046 |
| 1047 TEST(SchedulerStateMachineTest, TestContextLostWhileCommitInProgress_Deadline) { |
| 1048 bool deadline_scheduling_enabled = true; |
| 1049 TestContextLostWhileCommitInProgress(deadline_scheduling_enabled); |
| 1050 } |
| 1051 |
| 1052 void TestContextLostWhileCommitInProgressAndAnotherCommitRequested( |
| 1053 bool deadline_scheduling_enabled) { |
| 1054 SchedulerSettings scheduler_settings; |
| 1055 scheduler_settings.deadline_scheduling_enabled = deadline_scheduling_enabled; |
| 1056 StateMachine state(scheduler_settings); |
| 957 state.SetCanStart(); | 1057 state.SetCanStart(); |
| 958 state.UpdateState(state.NextAction()); | 1058 state.UpdateState(state.NextAction()); |
| 959 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); | 1059 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); |
| 960 state.SetVisible(true); | 1060 state.SetVisible(true); |
| 961 state.SetCanDraw(true); | 1061 state.SetCanDraw(true); |
| 962 | 1062 |
| 963 // Get a commit in flight. | 1063 // Get a commit in flight. |
| 964 state.SetNeedsCommit(); | 1064 state.SetNeedsCommit(); |
| 965 EXPECT_EQ(SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD, | 1065 if (!deadline_scheduling_enabled) { |
| 966 state.NextAction()); | 1066 EXPECT_ACTION_UPDATE_STATE( |
| 967 state.UpdateState(state.NextAction()); | 1067 SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD); |
| 1068 } |
| 1069 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 968 | 1070 |
| 969 // Set damage and expect a draw. | 1071 // Set damage and expect a draw. |
| 970 state.SetNeedsRedraw(true); | 1072 state.SetNeedsRedraw(true); |
| 971 state.DidEnterBeginFrame(BeginFrameArgs::CreateForTesting()); | 1073 state.OnBeginFrame(BeginFrameArgs::CreateForTesting()); |
| 972 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE, | 1074 if (deadline_scheduling_enabled) { |
| 973 state.NextAction()); | 1075 EXPECT_ACTION_UPDATE_STATE( |
| 974 state.UpdateState(state.NextAction()); | 1076 SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD); |
| 975 state.DidLeaveBeginFrame(); | 1077 } |
| 1078 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 1079 state.OnBeginFrameDeadline(); |
| 1080 EXPECT_ACTION_UPDATE_STATE( |
| 1081 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); |
| 1082 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 976 | 1083 |
| 977 // Cause a lost context while the begin frame is in flight | 1084 // Cause a lost context while the begin frame is in flight |
| 978 // for the main thread. | 1085 // for the main thread. |
| 979 state.DidLoseOutputSurface(); | 1086 state.DidLoseOutputSurface(); |
| 980 | 1087 |
| 981 // Ask for another draw and also set needs commit. Expect nothing happens. | 1088 // Ask for another draw and also set needs commit. Expect nothing happens. |
| 982 state.SetNeedsRedraw(true); | 1089 state.SetNeedsRedraw(true); |
| 983 state.SetNeedsCommit(); | 1090 state.SetNeedsCommit(); |
| 984 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); | 1091 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 985 | 1092 |
| 986 // Finish the frame, and commit. | 1093 // Finish the frame, and commit. |
| 987 state.FinishCommit(); | 1094 state.FinishCommit(); |
| 988 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction()); | 1095 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); |
| 989 state.UpdateState(state.NextAction()); | |
| 990 | |
| 991 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW, | 1096 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW, |
| 992 state.CommitState()); | 1097 state.CommitState()); |
| 993 | 1098 |
| 994 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT, | 1099 // Because the output surface is missing, we expect the draw to abort. |
| 995 state.NextAction()); | 1100 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT); |
| 996 state.UpdateState(state.NextAction()); | |
| 997 | 1101 |
| 998 // Expect to be told to begin context recreation, independent of | 1102 // Expect to be told to begin context recreation, independent of |
| 999 // BeginFrame state | 1103 // BeginFrame state |
| 1000 state.DidEnterBeginFrame(BeginFrameArgs::CreateForTesting()); | 1104 EXPECT_EQ(SchedulerStateMachine::BEGIN_FRAME_STATE_IDLE, |
| 1105 state.begin_frame_state()); |
| 1001 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION, | 1106 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION, |
| 1002 state.NextAction()); | 1107 state.NextAction()); |
| 1003 state.DidLeaveBeginFrame(); | 1108 |
| 1109 state.OnBeginFrame(BeginFrameArgs::CreateForTesting()); |
| 1110 EXPECT_EQ(SchedulerStateMachine::BEGIN_FRAME_STATE_BEGIN_FRAME_STARTING, |
| 1111 state.begin_frame_state()); |
| 1004 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION, | 1112 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION, |
| 1005 state.NextAction()); | 1113 state.NextAction()); |
| 1114 |
| 1115 state.OnBeginFrameDeadlinePending(); |
| 1116 EXPECT_EQ(SchedulerStateMachine::BEGIN_FRAME_STATE_INSIDE_BEGIN_FRAME, |
| 1117 state.begin_frame_state()); |
| 1118 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION, |
| 1119 state.NextAction()); |
| 1120 |
| 1121 state.OnBeginFrameDeadline(); |
| 1122 EXPECT_EQ(SchedulerStateMachine::BEGIN_FRAME_STATE_INSIDE_DEADLINE, |
| 1123 state.begin_frame_state()); |
| 1124 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION, |
| 1125 state.NextAction()); |
| 1126 |
| 1127 // After we get a new output surface, the commit flow should start. |
| 1128 EXPECT_ACTION_UPDATE_STATE( |
| 1129 SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION); |
| 1130 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); |
| 1131 state.OnBeginFrameIdle(); |
| 1132 state.OnBeginFrame(BeginFrameArgs::CreateForTesting()); |
| 1133 EXPECT_ACTION_UPDATE_STATE( |
| 1134 SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD); |
| 1135 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 1136 state.FinishCommit(); |
| 1137 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); |
| 1138 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 1139 state.OnBeginFrameDeadline(); |
| 1140 EXPECT_ACTION_UPDATE_STATE( |
| 1141 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); |
| 1142 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 1143 } |
| 1144 |
| 1145 TEST(SchedulerStateMachineTest, |
| 1146 TestContextLostWhileCommitInProgressAndAnotherCommitRequested) { |
| 1147 bool deadline_scheduling_enabled = false; |
| 1148 TestContextLostWhileCommitInProgressAndAnotherCommitRequested( |
| 1149 deadline_scheduling_enabled); |
| 1150 } |
| 1151 |
| 1152 TEST(SchedulerStateMachineTest, |
| 1153 TestContextLostWhileCommitInProgressAndAnotherCommitRequested_Deadline) { |
| 1154 bool deadline_scheduling_enabled = true; |
| 1155 TestContextLostWhileCommitInProgressAndAnotherCommitRequested( |
| 1156 deadline_scheduling_enabled); |
| 1006 } | 1157 } |
| 1007 | 1158 |
| 1008 TEST(SchedulerStateMachineTest, TestFinishAllRenderingWhileContextLost) { | 1159 TEST(SchedulerStateMachineTest, TestFinishAllRenderingWhileContextLost) { |
| 1009 SchedulerSettings default_scheduler_settings; | 1160 SchedulerSettings default_scheduler_settings; |
| 1010 StateMachine state(default_scheduler_settings); | 1161 StateMachine state(default_scheduler_settings); |
| 1011 state.SetCanStart(); | 1162 state.SetCanStart(); |
| 1012 state.UpdateState(state.NextAction()); | 1163 state.UpdateState(state.NextAction()); |
| 1013 state.DidCreateAndInitializeOutputSurface(); | 1164 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); |
| 1014 state.SetVisible(true); | 1165 state.SetVisible(true); |
| 1015 state.SetCanDraw(true); | 1166 state.SetCanDraw(true); |
| 1016 | 1167 |
| 1017 // Cause a lost context lost. | 1168 // Cause a lost context lost. |
| 1018 state.DidLoseOutputSurface(); | 1169 state.DidLoseOutputSurface(); |
| 1019 | 1170 |
| 1020 // Ask a forced redraw and verify it ocurrs, even with a lost context, | 1171 // Ask a forced redraw for readback and verify it ocurrs. |
| 1021 // independent of the BeginFrame stae. | 1172 state.SetCommitState( |
| 1173 SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW); |
| 1022 state.SetNeedsForcedRedrawForReadback(); | 1174 state.SetNeedsForcedRedrawForReadback(); |
| 1175 state.OnBeginFrame(BeginFrameArgs::CreateForTesting()); |
| 1023 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_READBACK); | 1176 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_READBACK); |
| 1177 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 1024 | 1178 |
| 1025 // Forced redraws for readbacks need to be followed by a new commit | 1179 // Forced redraws for readbacks need to be followed by a new commit |
| 1026 // to replace the readback commit. | 1180 // to replace the readback commit. |
| 1027 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, | 1181 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, |
| 1028 state.CommitState()); | 1182 state.CommitState()); |
| 1029 state.FinishCommit(); | 1183 state.FinishCommit(); |
| 1030 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); | 1184 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); |
| 1031 | 1185 |
| 1032 // We don't yet have an output surface, so we the draw and swap should abort. | 1186 // 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); | 1187 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT); |
| 1034 | 1188 |
| 1035 // Expect to be told to begin context recreation, independent of | 1189 // Expect to be told to begin context recreation, independent of |
| 1036 // BeginFrame state. | 1190 // BeginFrame state |
| 1037 EXPECT_ACTION_UPDATE_STATE( | 1191 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState()); |
| 1038 SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION); | 1192 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION, |
| 1193 state.NextAction()); |
| 1039 | 1194 |
| 1040 // Ask a readback and verify it ocurrs. | 1195 state.OnBeginFrameDeadline(); |
| 1196 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION, |
| 1197 state.NextAction()); |
| 1198 |
| 1199 // Ask a readback and verify it occurs. |
| 1200 state.SetCommitState( |
| 1201 SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW); |
| 1041 state.SetNeedsForcedRedrawForReadback(); | 1202 state.SetNeedsForcedRedrawForReadback(); |
| 1042 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_AND_READBACK, | 1203 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_READBACK); |
| 1043 state.NextAction()); | 1204 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 1044 } | 1205 } |
| 1045 | 1206 |
| 1046 TEST(SchedulerStateMachineTest, DontDrawBeforeCommitAfterLostOutputSurface) { | 1207 TEST(SchedulerStateMachineTest, DontDrawBeforeCommitAfterLostOutputSurface) { |
| 1047 SchedulerSettings default_scheduler_settings; | 1208 SchedulerSettings default_scheduler_settings; |
| 1048 StateMachine state(default_scheduler_settings); | 1209 StateMachine state(default_scheduler_settings); |
| 1049 state.SetCanStart(); | 1210 state.SetCanStart(); |
| 1050 state.UpdateState(state.NextAction()); | 1211 state.UpdateState(state.NextAction()); |
| 1051 state.DidCreateAndInitializeOutputSurface(); | 1212 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); |
| 1052 state.SetVisible(true); | 1213 state.SetVisible(true); |
| 1053 state.SetCanDraw(true); | 1214 state.SetCanDraw(true); |
| 1054 | 1215 |
| 1055 state.SetNeedsRedraw(true); | 1216 state.SetNeedsRedraw(true); |
| 1056 | 1217 |
| 1057 // Cause a lost output surface, and restore it. | 1218 // Cause a lost output surface, and restore it. |
| 1058 state.DidLoseOutputSurface(); | 1219 state.DidLoseOutputSurface(); |
| 1059 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION, | 1220 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION, |
| 1060 state.NextAction()); | 1221 state.NextAction()); |
| 1061 state.UpdateState(state.NextAction()); | 1222 state.UpdateState(state.NextAction()); |
| 1062 state.DidCreateAndInitializeOutputSurface(); | 1223 state.DidCreateAndInitializeOutputSurface(); |
| 1063 | 1224 |
| 1064 EXPECT_FALSE(state.RedrawPending()); | 1225 EXPECT_FALSE(state.RedrawPending()); |
| 1226 state.OnBeginFrame(BeginFrameArgs::CreateForTesting()); |
| 1065 EXPECT_EQ(SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD, | 1227 EXPECT_EQ(SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD, |
| 1066 state.NextAction()); | 1228 state.NextAction()); |
| 1067 } | 1229 } |
| 1068 | 1230 |
| 1069 TEST(SchedulerStateMachineTest, | 1231 TEST(SchedulerStateMachineTest, |
| 1070 TestSendBeginFrameToMainThreadWhenInvisibleAndForceCommit) { | 1232 TestSendBeginFrameToMainThreadWhenInvisibleAndForceCommit) { |
| 1071 SchedulerSettings default_scheduler_settings; | 1233 SchedulerSettings default_scheduler_settings; |
| 1072 StateMachine state(default_scheduler_settings); | 1234 StateMachine state(default_scheduler_settings); |
| 1073 state.SetCanStart(); | 1235 state.SetCanStart(); |
| 1074 state.UpdateState(state.NextAction()); | 1236 state.UpdateState(state.NextAction()); |
| 1075 state.DidCreateAndInitializeOutputSurface(); | 1237 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); |
| 1076 state.SetVisible(false); | 1238 state.SetVisible(false); |
| 1077 state.SetNeedsCommit(); | 1239 state.SetNeedsCommit(); |
| 1078 state.SetNeedsForcedCommitForReadback(); | 1240 state.SetNeedsForcedCommitForReadback(); |
| 1079 EXPECT_EQ(SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD, | 1241 EXPECT_EQ(SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD, |
| 1080 state.NextAction()); | 1242 state.NextAction()); |
| 1081 } | 1243 } |
| 1082 | 1244 |
| 1083 TEST(SchedulerStateMachineTest, | 1245 TEST(SchedulerStateMachineTest, |
| 1084 TestSendBeginFrameToMainThreadWhenCanStartFalseAndForceCommit) { | 1246 TestSendBeginFrameToMainThreadWhenCanStartFalseAndForceCommit) { |
| 1085 SchedulerSettings default_scheduler_settings; | 1247 SchedulerSettings default_scheduler_settings; |
| 1086 StateMachine state(default_scheduler_settings); | 1248 StateMachine state(default_scheduler_settings); |
| 1087 state.SetVisible(true); | 1249 state.SetVisible(true); |
| 1088 state.SetCanDraw(true); | 1250 state.SetCanDraw(true); |
| 1089 state.SetNeedsCommit(); | 1251 state.SetNeedsCommit(); |
| 1090 state.SetNeedsForcedCommitForReadback(); | 1252 state.SetNeedsForcedCommitForReadback(); |
| 1091 EXPECT_EQ(SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD, | 1253 EXPECT_EQ(SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD, |
| 1092 state.NextAction()); | 1254 state.NextAction()); |
| 1093 } | 1255 } |
| 1094 | 1256 |
| 1095 TEST(SchedulerStateMachineTest, TestFinishCommitWhenCommitInProgress) { | 1257 TEST(SchedulerStateMachineTest, TestFinishCommitWhenCommitInProgress) { |
| 1096 SchedulerSettings default_scheduler_settings; | 1258 SchedulerSettings default_scheduler_settings; |
| 1097 StateMachine state(default_scheduler_settings); | 1259 StateMachine state(default_scheduler_settings); |
| 1098 state.SetCanStart(); | 1260 state.SetCanStart(); |
| 1099 state.UpdateState(state.NextAction()); | 1261 state.UpdateState(state.NextAction()); |
| 1100 state.DidCreateAndInitializeOutputSurface(); | 1262 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); |
| 1101 state.SetVisible(false); | 1263 state.SetVisible(false); |
| 1102 state.SetCommitState(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS); | 1264 state.SetCommitState(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS); |
| 1103 state.SetNeedsCommit(); | 1265 state.SetNeedsCommit(); |
| 1104 | 1266 |
| 1105 state.FinishCommit(); | 1267 state.FinishCommit(); |
| 1106 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction()); | 1268 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction()); |
| 1107 state.UpdateState(state.NextAction()); | 1269 state.UpdateState(state.NextAction()); |
| 1108 | 1270 |
| 1109 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW, | 1271 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW, |
| 1110 state.CommitState()); | 1272 state.CommitState()); |
| 1111 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT, | 1273 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 } | 1274 } |
| 1117 | 1275 |
| 1118 TEST(SchedulerStateMachineTest, TestFinishCommitWhenForcedCommitInProgress) { | 1276 TEST(SchedulerStateMachineTest, TestFinishCommitWhenForcedCommitInProgress) { |
| 1119 SchedulerSettings default_scheduler_settings; | 1277 SchedulerSettings default_scheduler_settings; |
| 1120 StateMachine state(default_scheduler_settings); | 1278 StateMachine state(default_scheduler_settings); |
| 1121 state.SetCanStart(); | 1279 state.SetCanStart(); |
| 1122 state.UpdateState(state.NextAction()); | 1280 state.UpdateState(state.NextAction()); |
| 1123 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); | 1281 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); |
| 1124 state.SetVisible(false); | 1282 state.SetVisible(false); |
| 1125 state.SetCommitState(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS); | 1283 state.SetCommitState(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 1142 // The normal commit can then proceed. | 1300 // The normal commit can then proceed. |
| 1143 state.FinishCommit(); | 1301 state.FinishCommit(); |
| 1144 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); | 1302 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); |
| 1145 } | 1303 } |
| 1146 | 1304 |
| 1147 TEST(SchedulerStateMachineTest, TestInitialActionsWhenContextLost) { | 1305 TEST(SchedulerStateMachineTest, TestInitialActionsWhenContextLost) { |
| 1148 SchedulerSettings default_scheduler_settings; | 1306 SchedulerSettings default_scheduler_settings; |
| 1149 StateMachine state(default_scheduler_settings); | 1307 StateMachine state(default_scheduler_settings); |
| 1150 state.SetCanStart(); | 1308 state.SetCanStart(); |
| 1151 state.UpdateState(state.NextAction()); | 1309 state.UpdateState(state.NextAction()); |
| 1152 state.DidCreateAndInitializeOutputSurface(); | 1310 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); |
| 1153 state.SetVisible(true); | 1311 state.SetVisible(true); |
| 1154 state.SetCanDraw(true); | 1312 state.SetCanDraw(true); |
| 1155 state.SetNeedsCommit(); | 1313 state.SetNeedsCommit(); |
| 1156 state.DidLoseOutputSurface(); | 1314 state.DidLoseOutputSurface(); |
| 1157 | 1315 |
| 1158 // When we are visible, we normally want to begin output surface creation | 1316 // When we are visible, we normally want to begin output surface creation |
| 1159 // as soon as possible. | 1317 // as soon as possible. |
| 1160 EXPECT_ACTION_UPDATE_STATE( | 1318 EXPECT_ACTION_UPDATE_STATE( |
| 1161 SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION); | 1319 SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION); |
| 1162 | 1320 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1178 EXPECT_EQ(SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD, | 1336 EXPECT_EQ(SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD, |
| 1179 state.NextAction()) | 1337 state.NextAction()) |
| 1180 << *state.AsValue(); | 1338 << *state.AsValue(); |
| 1181 } | 1339 } |
| 1182 | 1340 |
| 1183 TEST(SchedulerStateMachineTest, TestImmediateFinishCommit) { | 1341 TEST(SchedulerStateMachineTest, TestImmediateFinishCommit) { |
| 1184 SchedulerSettings default_scheduler_settings; | 1342 SchedulerSettings default_scheduler_settings; |
| 1185 StateMachine state(default_scheduler_settings); | 1343 StateMachine state(default_scheduler_settings); |
| 1186 state.SetCanStart(); | 1344 state.SetCanStart(); |
| 1187 state.UpdateState(state.NextAction()); | 1345 state.UpdateState(state.NextAction()); |
| 1188 state.DidCreateAndInitializeOutputSurface(); | 1346 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); |
| 1189 state.SetVisible(true); | 1347 state.SetVisible(true); |
| 1190 state.SetCanDraw(true); | 1348 state.SetCanDraw(true); |
| 1191 | 1349 |
| 1192 // Schedule a readback, commit it, draw it. | 1350 // Schedule a readback, commit it, draw it. |
| 1193 state.SetNeedsCommit(); | 1351 state.SetNeedsCommit(); |
| 1194 state.SetNeedsForcedCommitForReadback(); | 1352 state.SetNeedsForcedCommitForReadback(); |
| 1195 EXPECT_ACTION_UPDATE_STATE( | 1353 EXPECT_ACTION_UPDATE_STATE( |
| 1196 SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD); | 1354 SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD); |
| 1197 state.FinishCommit(); | 1355 state.FinishCommit(); |
| 1198 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction()); | 1356 |
| 1199 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT, | 1357 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT, |
| 1200 state.CommitState()); | 1358 state.CommitState()); |
| 1201 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); | 1359 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); |
| 1202 | 1360 |
| 1203 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW, | 1361 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW, |
| 1204 state.CommitState()); | 1362 state.CommitState()); |
| 1205 | 1363 |
| 1206 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_READBACK); | 1364 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_READBACK); |
| 1207 state.DidDrawIfPossibleCompleted(true); | 1365 state.DidDrawIfPossibleCompleted(true); |
| 1366 |
| 1208 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | 1367 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 1209 | 1368 |
| 1210 // Should be waiting for the normal begin frame from the main thread. | 1369 // Should be waiting for the normal begin frame from the main thread. |
| 1211 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, | 1370 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, |
| 1212 state.CommitState()); | 1371 state.CommitState()); |
| 1213 } | 1372 } |
| 1214 | 1373 |
| 1215 TEST(SchedulerStateMachineTest, TestImmediateFinishCommitDuringCommit) { | 1374 void TestImmediateFinishCommitDuringCommit(bool deadline_scheduling_enabled) { |
| 1216 SchedulerSettings default_scheduler_settings; | 1375 SchedulerSettings scheduler_settings; |
| 1217 StateMachine state(default_scheduler_settings); | 1376 scheduler_settings.deadline_scheduling_enabled = deadline_scheduling_enabled; |
| 1377 StateMachine state(scheduler_settings); |
| 1218 state.SetCanStart(); | 1378 state.SetCanStart(); |
| 1219 state.UpdateState(state.NextAction()); | 1379 state.UpdateState(state.NextAction()); |
| 1220 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); | 1380 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); |
| 1221 state.SetVisible(true); | 1381 state.SetVisible(true); |
| 1222 state.SetCanDraw(true); | 1382 state.SetCanDraw(true); |
| 1223 | 1383 |
| 1224 // Start a normal commit. | 1384 // Start a normal commit. |
| 1225 state.SetNeedsCommit(); | 1385 state.SetNeedsCommit(); |
| 1226 EXPECT_ACTION_UPDATE_STATE( | 1386 if (!deadline_scheduling_enabled) { |
| 1227 SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD); | 1387 EXPECT_ACTION_UPDATE_STATE( |
| 1388 SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD); |
| 1389 } |
| 1390 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 1228 | 1391 |
| 1229 // Schedule a readback, commit it, draw it. | 1392 // Schedule a readback, commit it, draw it. |
| 1230 state.SetNeedsCommit(); | |
| 1231 state.SetNeedsForcedCommitForReadback(); | 1393 state.SetNeedsForcedCommitForReadback(); |
| 1394 if (deadline_scheduling_enabled) { |
| 1395 EXPECT_ACTION_UPDATE_STATE( |
| 1396 SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD); |
| 1397 } |
| 1232 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | 1398 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 1233 state.FinishCommit(); | 1399 state.FinishCommit(); |
| 1234 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT, | 1400 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT, |
| 1235 state.CommitState()); | 1401 state.CommitState()); |
| 1236 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); | 1402 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); |
| 1237 | 1403 |
| 1238 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW, | 1404 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW, |
| 1239 state.CommitState()); | 1405 state.CommitState()); |
| 1240 | 1406 |
| 1241 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_READBACK); | 1407 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_READBACK); |
| 1242 state.DidDrawIfPossibleCompleted(true); | 1408 state.DidDrawIfPossibleCompleted(true); |
| 1243 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | 1409 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 1244 | 1410 |
| 1245 // Should be waiting for the normal begin frame from the main thread. | 1411 // Should be waiting for the normal begin frame from the main thread. |
| 1246 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, | 1412 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, |
| 1247 state.CommitState()) | 1413 state.CommitState()) |
| 1248 << *state.AsValue(); | 1414 << *state.AsValue(); |
| 1249 } | 1415 } |
| 1250 | 1416 |
| 1251 TEST(SchedulerStateMachineTest, | 1417 TEST(SchedulerStateMachineTest, |
| 1252 ImmediateBeginFrameAbortedByMainThreadWhileInvisible) { | 1418 TestImmediateFinishCommitDuringCommit) { |
| 1253 SchedulerSettings default_scheduler_settings; | 1419 bool deadline_scheduling_enabled = false; |
| 1254 StateMachine state(default_scheduler_settings); | 1420 TestImmediateFinishCommitDuringCommit(deadline_scheduling_enabled); |
| 1421 } |
| 1422 |
| 1423 TEST(SchedulerStateMachineTest, |
| 1424 TestImmediateFinishCommitDuringCommit_Deadline) { |
| 1425 bool deadline_scheduling_enabled = true; |
| 1426 TestImmediateFinishCommitDuringCommit(deadline_scheduling_enabled); |
| 1427 } |
| 1428 |
| 1429 void ImmediateBeginFrameAbortedByMainThreadWhileInvisible( |
| 1430 bool deadline_scheduling_enabled) { |
| 1431 SchedulerSettings scheduler_settings; |
| 1432 scheduler_settings.deadline_scheduling_enabled = deadline_scheduling_enabled; |
| 1433 StateMachine state(scheduler_settings); |
| 1255 state.SetCanStart(); | 1434 state.SetCanStart(); |
| 1256 state.UpdateState(state.NextAction()); | 1435 state.UpdateState(state.NextAction()); |
| 1257 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); | 1436 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); |
| 1258 state.SetVisible(true); | 1437 state.SetVisible(true); |
| 1259 state.SetCanDraw(true); | 1438 state.SetCanDraw(true); |
| 1260 | 1439 |
| 1261 state.SetNeedsCommit(); | 1440 state.SetNeedsCommit(); |
| 1262 EXPECT_ACTION_UPDATE_STATE( | 1441 if (!deadline_scheduling_enabled) { |
| 1263 SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD); | 1442 EXPECT_ACTION_UPDATE_STATE( |
| 1443 SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD); |
| 1444 } |
| 1445 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 1264 | 1446 |
| 1265 state.SetNeedsCommit(); | 1447 state.SetNeedsCommit(); |
| 1266 state.SetNeedsForcedCommitForReadback(); | 1448 state.SetNeedsForcedCommitForReadback(); |
| 1267 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | 1449 if (deadline_scheduling_enabled) { |
| 1450 EXPECT_ACTION_UPDATE_STATE( |
| 1451 SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD); |
| 1452 } |
| 1268 state.FinishCommit(); | 1453 state.FinishCommit(); |
| 1269 | 1454 |
| 1270 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT, | 1455 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT, |
| 1271 state.CommitState()); | 1456 state.CommitState()); |
| 1272 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); | 1457 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); |
| 1273 | 1458 |
| 1274 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW, | 1459 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW, |
| 1275 state.CommitState()); | 1460 state.CommitState()); |
| 1276 | 1461 |
| 1277 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_READBACK); | 1462 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_READBACK); |
| 1278 state.DidDrawIfPossibleCompleted(true); | 1463 state.DidDrawIfPossibleCompleted(true); |
| 1279 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | 1464 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 1280 | 1465 |
| 1281 // Should be waiting for the main thread's begin frame. | 1466 // Should be waiting for the main thread's begin frame. |
| 1282 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, | 1467 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, |
| 1283 state.CommitState()) | 1468 state.CommitState()) |
| 1284 << *state.AsValue(); | 1469 << *state.AsValue(); |
| 1285 | 1470 |
| 1286 // Become invisible and abort the main thread's begin frame. | 1471 // Become invisible and abort the main thread's begin frame. |
| 1287 state.SetVisible(false); | 1472 state.SetVisible(false); |
| 1288 state.BeginFrameAbortedByMainThread(false); | 1473 state.BeginFrameAbortedByMainThread(false); |
| 1289 | 1474 |
| 1290 // Should be back in the idle state, but needing a commit. | 1475 // Should be back in the idle state, but needing a commit. |
| 1291 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState()); | 1476 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState()); |
| 1292 EXPECT_TRUE(state.NeedsCommit()); | 1477 EXPECT_TRUE(state.NeedsCommit()); |
| 1293 } | 1478 } |
| 1294 | 1479 |
| 1480 TEST(SchedulerStateMachineTest, |
| 1481 ImmediateBeginFrameAbortedByMainThreadWhileInvisible) { |
| 1482 bool deadline_scheduling_enabled = false; |
| 1483 ImmediateBeginFrameAbortedByMainThreadWhileInvisible( |
| 1484 deadline_scheduling_enabled); |
| 1485 } |
| 1486 |
| 1487 TEST(SchedulerStateMachineTest, |
| 1488 ImmediateBeginFrameAbortedByMainThreadWhileInvisible_Deadline) { |
| 1489 bool deadline_scheduling_enabled = true; |
| 1490 ImmediateBeginFrameAbortedByMainThreadWhileInvisible( |
| 1491 deadline_scheduling_enabled); |
| 1492 } |
| 1493 |
| 1295 TEST(SchedulerStateMachineTest, ImmediateFinishCommitWhileCantDraw) { | 1494 TEST(SchedulerStateMachineTest, ImmediateFinishCommitWhileCantDraw) { |
| 1296 SchedulerSettings default_scheduler_settings; | 1495 SchedulerSettings default_scheduler_settings; |
| 1297 StateMachine state(default_scheduler_settings); | 1496 StateMachine state(default_scheduler_settings); |
| 1298 state.SetCanStart(); | 1497 state.SetCanStart(); |
| 1299 state.UpdateState(state.NextAction()); | 1498 state.UpdateState(state.NextAction()); |
| 1300 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); | 1499 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); |
| 1301 state.SetVisible(true); | 1500 state.SetVisible(true); |
| 1302 state.SetCanDraw(false); | 1501 state.SetCanDraw(false); |
| 1303 | 1502 |
| 1304 state.SetNeedsCommit(); | 1503 state.SetNeedsCommit(); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1353 SchedulerSettings default_scheduler_settings; | 1552 SchedulerSettings default_scheduler_settings; |
| 1354 StateMachine state(default_scheduler_settings); | 1553 StateMachine state(default_scheduler_settings); |
| 1355 state.SetCanStart(); | 1554 state.SetCanStart(); |
| 1356 state.UpdateState(state.NextAction()); | 1555 state.UpdateState(state.NextAction()); |
| 1357 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); | 1556 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); |
| 1358 state.SetCanDraw(true); | 1557 state.SetCanDraw(true); |
| 1359 state.SetVisible(true); | 1558 state.SetVisible(true); |
| 1360 EXPECT_FALSE(state.PendingDrawsShouldBeAborted()); | 1559 EXPECT_FALSE(state.PendingDrawsShouldBeAborted()); |
| 1361 | 1560 |
| 1362 state.SetMainThreadNeedsLayerTextures(); | 1561 state.SetMainThreadNeedsLayerTextures(); |
| 1363 EXPECT_EQ( | 1562 EXPECT_ACTION_UPDATE_STATE( |
| 1364 SchedulerStateMachine::ACTION_ACQUIRE_LAYER_TEXTURES_FOR_MAIN_THREAD, | 1563 SchedulerStateMachine::ACTION_ACQUIRE_LAYER_TEXTURES_FOR_MAIN_THREAD); |
| 1365 state.NextAction()); | |
| 1366 state.UpdateState(state.NextAction()); | |
| 1367 EXPECT_TRUE(state.PendingDrawsShouldBeAborted()); | 1564 EXPECT_TRUE(state.PendingDrawsShouldBeAborted()); |
| 1565 EXPECT_TRUE(state.PendingActivationsShouldBeForced()); |
| 1566 |
| 1567 state.SetNeedsCommit(); |
| 1568 state.OnBeginFrame(BeginFrameArgs::CreateForTesting()); |
| 1569 EXPECT_ACTION_UPDATE_STATE( |
| 1570 SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD); |
| 1571 EXPECT_TRUE(state.PendingDrawsShouldBeAborted()); |
| 1572 EXPECT_TRUE(state.PendingActivationsShouldBeForced()); |
| 1368 | 1573 |
| 1369 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); | 1574 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); |
| 1370 | 1575 |
| 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(); | 1576 state.FinishCommit(); |
| 1381 EXPECT_TRUE(state.PendingDrawsShouldBeAborted()); | 1577 EXPECT_TRUE(state.PendingDrawsShouldBeAborted()); |
| 1382 | 1578 |
| 1383 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction()); | 1579 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction()); |
| 1384 | 1580 |
| 1385 state.UpdateState(state.NextAction()); | 1581 state.UpdateState(state.NextAction()); |
| 1386 EXPECT_FALSE(state.PendingDrawsShouldBeAborted()); | 1582 EXPECT_FALSE(state.PendingDrawsShouldBeAborted()); |
| 1387 } | 1583 } |
| 1388 | 1584 |
| 1389 TEST(SchedulerStateMachineTest, AcquireTexturesWithAbort) { | 1585 TEST(SchedulerStateMachineTest, AcquireTexturesWithAbort) { |
| 1390 SchedulerSettings default_scheduler_settings; | 1586 SchedulerSettings default_scheduler_settings; |
| 1391 SchedulerStateMachine state(default_scheduler_settings); | 1587 StateMachine state(default_scheduler_settings); |
| 1392 state.SetCanStart(); | 1588 state.SetCanStart(); |
| 1393 state.UpdateState(state.NextAction()); | 1589 state.UpdateState(state.NextAction()); |
| 1394 state.DidCreateAndInitializeOutputSurface(); | 1590 state.DidCreateAndInitializeOutputSurface(); |
| 1395 state.SetCanDraw(true); | 1591 state.SetCanDraw(true); |
| 1396 state.SetVisible(true); | 1592 state.SetVisible(true); |
| 1397 | 1593 |
| 1398 state.SetMainThreadNeedsLayerTextures(); | 1594 state.SetMainThreadNeedsLayerTextures(); |
| 1399 EXPECT_EQ( | 1595 EXPECT_EQ( |
| 1400 SchedulerStateMachine::ACTION_ACQUIRE_LAYER_TEXTURES_FOR_MAIN_THREAD, | 1596 SchedulerStateMachine::ACTION_ACQUIRE_LAYER_TEXTURES_FOR_MAIN_THREAD, |
| 1401 state.NextAction()); | 1597 state.NextAction()); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1413 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); | 1609 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); |
| 1414 | 1610 |
| 1415 state.BeginFrameAbortedByMainThread(true); | 1611 state.BeginFrameAbortedByMainThread(true); |
| 1416 | 1612 |
| 1417 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); | 1613 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); |
| 1418 EXPECT_FALSE(state.PendingDrawsShouldBeAborted()); | 1614 EXPECT_FALSE(state.PendingDrawsShouldBeAborted()); |
| 1419 } | 1615 } |
| 1420 | 1616 |
| 1421 } // namespace | 1617 } // namespace |
| 1422 } // namespace cc | 1618 } // namespace cc |
| OLD | NEW |