Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2011 The Chromium Authors. All rights reserved. | 1 // Copyright 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "cc/scheduler/scheduler_state_machine.h" | 5 #include "cc/scheduler/scheduler_state_machine.h" |
| 6 | 6 |
| 7 #include "cc/scheduler/scheduler.h" | 7 #include "cc/scheduler/scheduler.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 | 9 |
| 10 #define EXPECT_ACTION_UPDATE_STATE(action) \ | |
| 11 EXPECT_EQ(action, state.NextAction()) << *state.AsValue(); \ | |
| 12 state.UpdateState(action); | |
| 13 | |
| 10 namespace cc { | 14 namespace cc { |
| 11 | 15 |
| 12 namespace { | 16 namespace { |
| 13 | 17 |
| 14 const SchedulerStateMachine::CommitState all_commit_states[] = { | 18 const SchedulerStateMachine::CommitState all_commit_states[] = { |
| 15 SchedulerStateMachine::COMMIT_STATE_IDLE, | 19 SchedulerStateMachine::COMMIT_STATE_IDLE, |
| 16 SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, | 20 SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, |
| 17 SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT, | 21 SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT, |
| 18 SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW | 22 SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW |
| 19 }; | 23 }; |
| 20 | 24 |
| 21 // Exposes the protected state fields of the SchedulerStateMachine for testing | 25 // Exposes the protected state fields of the SchedulerStateMachine for testing |
| 22 class StateMachine : public SchedulerStateMachine { | 26 class StateMachine : public SchedulerStateMachine { |
| 23 public: | 27 public: |
| 24 explicit StateMachine(const SchedulerSettings& scheduler_settings) | 28 explicit StateMachine(const SchedulerSettings& scheduler_settings) |
| 25 : SchedulerStateMachine(scheduler_settings) {} | 29 : SchedulerStateMachine(scheduler_settings) {} |
| 26 | 30 |
| 27 void CreateAndInitializeOutputSurfaceWithActivatedCommit() { | 31 void CreateAndInitializeOutputSurfaceWithActivatedCommit() { |
| 28 DidCreateAndInitializeOutputSurface(); | 32 DidCreateAndInitializeOutputSurface(); |
| 29 output_surface_state_ = OUTPUT_SURFACE_ACTIVE; | 33 output_surface_state_ = OUTPUT_SURFACE_ACTIVE; |
| 30 } | 34 } |
| 31 | 35 |
| 32 void SetCommitState(CommitState cs) { commit_state_ = cs; } | 36 void SetCommitState(CommitState cs) { commit_state_ = cs; } |
| 33 CommitState CommitState() const { return commit_state_; } | 37 CommitState CommitState() const { return commit_state_; } |
| 34 | 38 |
| 39 OutputSurfaceState output_surface_state() { return output_surface_state_; } | |
| 40 | |
| 35 bool NeedsCommit() const { return needs_commit_; } | 41 bool NeedsCommit() const { return needs_commit_; } |
| 36 | 42 |
| 37 void SetNeedsRedraw(bool b) { needs_redraw_ = b; } | 43 void SetNeedsRedraw(bool b) { needs_redraw_ = b; } |
| 38 bool NeedsRedraw() const { return needs_redraw_; } | 44 bool NeedsRedraw() const { return needs_redraw_; } |
| 39 | 45 |
| 40 void SetNeedsForcedRedraw(bool b) { needs_forced_redraw_ = b; } | 46 void SetNeedsForcedRedrawForTimeout(bool b) { |
| 41 bool NeedsForcedRedraw() const { return needs_forced_redraw_; } | 47 forced_redraw_state_ = FORCED_REDRAW_STATE_WAITING_FOR_COMMIT; |
| 48 commit_state_ = COMMIT_STATE_WAITING_FOR_FIRST_DRAW; | |
| 49 } | |
| 50 bool NeedsForcedRedrawForTimeout() const { | |
| 51 return forced_redraw_state_ != FORCED_REDRAW_STATE_IDLE; | |
| 52 } | |
| 53 | |
| 54 void SetNeedsForcedRedrawForReadback() { | |
| 55 readback_state_ = READBACK_STATE_WAITING_FOR_DRAW_AND_READBACK; | |
| 56 commit_state_ = COMMIT_STATE_WAITING_FOR_FIRST_DRAW; | |
| 57 } | |
| 58 | |
| 59 bool NeedsForcedRedrawForReadback() const { | |
| 60 return readback_state_ != READBACK_STATE_IDLE; | |
| 61 } | |
| 42 | 62 |
| 43 bool CanDraw() const { return can_draw_; } | 63 bool CanDraw() const { return can_draw_; } |
| 44 bool Visible() const { return visible_; } | 64 bool Visible() const { return visible_; } |
| 45 }; | 65 }; |
| 46 | 66 |
| 47 TEST(SchedulerStateMachineTest, TestNextActionBeginsMainFrameIfNeeded) { | 67 TEST(SchedulerStateMachineTest, TestNextActionBeginsMainFrameIfNeeded) { |
| 48 SchedulerSettings default_scheduler_settings; | 68 SchedulerSettings default_scheduler_settings; |
| 49 | 69 |
| 50 // If no commit needed, do nothing. | 70 // If no commit needed, do nothing. |
| 51 { | 71 { |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 101 state.SetVisible(true); | 121 state.SetVisible(true); |
| 102 state.UpdateState( | 122 state.UpdateState( |
| 103 SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD); | 123 SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD); |
| 104 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, | 124 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, |
| 105 state.CommitState()); | 125 state.CommitState()); |
| 106 EXPECT_FALSE(state.NeedsCommit()); | 126 EXPECT_FALSE(state.NeedsCommit()); |
| 107 EXPECT_FALSE(state.BeginFrameNeededToDrawByImplThread()); | 127 EXPECT_FALSE(state.BeginFrameNeededToDrawByImplThread()); |
| 108 } | 128 } |
| 109 } | 129 } |
| 110 | 130 |
| 111 TEST(SchedulerStateMachineTest, TestSetForcedRedrawDoesNotSetsNormalRedraw) { | |
|
brianderson
2013/08/29 19:23:10
I removed this test because ToT has been setting n
| |
| 112 SchedulerSettings default_scheduler_settings; | |
| 113 SchedulerStateMachine state(default_scheduler_settings); | |
| 114 state.SetCanDraw(true); | |
| 115 state.SetNeedsForcedRedraw(); | |
| 116 EXPECT_FALSE(state.RedrawPending()); | |
| 117 EXPECT_TRUE(state.BeginFrameNeededToDrawByImplThread()); | |
| 118 } | |
| 119 | |
| 120 TEST(SchedulerStateMachineTest, | 131 TEST(SchedulerStateMachineTest, |
| 121 TestFailedDrawSetsNeedsCommitAndDoesNotDrawAgain) { | 132 TestFailedDrawSetsNeedsCommitAndDoesNotDrawAgain) { |
| 122 SchedulerSettings default_scheduler_settings; | 133 SchedulerSettings default_scheduler_settings; |
| 123 StateMachine state(default_scheduler_settings); | 134 StateMachine state(default_scheduler_settings); |
| 124 state.SetCanStart(); | 135 state.SetCanStart(); |
| 125 state.UpdateState(state.NextAction()); | 136 state.UpdateState(state.NextAction()); |
| 126 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); | 137 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); |
| 127 state.SetVisible(true); | 138 state.SetVisible(true); |
| 128 state.SetCanDraw(true); | 139 state.SetCanDraw(true); |
| 129 state.SetNeedsRedraw(true); | 140 state.SetNeedsRedraw(true); |
| 130 EXPECT_TRUE(state.RedrawPending()); | 141 EXPECT_TRUE(state.RedrawPending()); |
| 131 EXPECT_TRUE(state.BeginFrameNeededToDrawByImplThread()); | 142 EXPECT_TRUE(state.BeginFrameNeededToDrawByImplThread()); |
| 132 state.DidEnterBeginFrame(BeginFrameArgs::CreateForTesting()); | 143 state.DidEnterBeginFrame(BeginFrameArgs::CreateForTesting()); |
| 133 | 144 |
| 134 // We're drawing now. | 145 // We're drawing now. |
| 135 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.NextAction()); | 146 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE, |
| 136 state.UpdateState(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE); | 147 state.NextAction()); |
| 148 state.UpdateState(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); | |
| 137 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); | 149 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); |
| 138 EXPECT_FALSE(state.RedrawPending()); | 150 EXPECT_FALSE(state.RedrawPending()); |
| 139 EXPECT_FALSE(state.CommitPending()); | 151 EXPECT_FALSE(state.CommitPending()); |
| 140 | 152 |
| 141 // Failing the draw makes us require a commit. | 153 // Failing the draw makes us require a commit. |
| 142 state.DidDrawIfPossibleCompleted(false); | 154 state.DidDrawIfPossibleCompleted(false); |
| 143 EXPECT_EQ(SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD, | 155 EXPECT_EQ(SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD, |
| 144 state.NextAction()); | 156 state.NextAction()); |
| 145 state.UpdateState( | 157 state.UpdateState( |
| 146 SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD); | 158 SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD); |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 157 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); | 169 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); |
| 158 | 170 |
| 159 state.SetVisible(true); | 171 state.SetVisible(true); |
| 160 state.SetCanDraw(true); | 172 state.SetCanDraw(true); |
| 161 state.SetNeedsRedraw(true); | 173 state.SetNeedsRedraw(true); |
| 162 EXPECT_TRUE(state.RedrawPending()); | 174 EXPECT_TRUE(state.RedrawPending()); |
| 163 EXPECT_TRUE(state.BeginFrameNeededToDrawByImplThread()); | 175 EXPECT_TRUE(state.BeginFrameNeededToDrawByImplThread()); |
| 164 state.DidEnterBeginFrame(BeginFrameArgs::CreateForTesting()); | 176 state.DidEnterBeginFrame(BeginFrameArgs::CreateForTesting()); |
| 165 | 177 |
| 166 // We're drawing now. | 178 // We're drawing now. |
| 167 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.NextAction()); | 179 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE, |
| 168 state.UpdateState(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE); | 180 state.NextAction()); |
| 181 state.UpdateState(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); | |
| 169 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); | 182 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); |
| 170 EXPECT_FALSE(state.RedrawPending()); | 183 EXPECT_FALSE(state.RedrawPending()); |
| 171 EXPECT_FALSE(state.CommitPending()); | 184 EXPECT_FALSE(state.CommitPending()); |
| 172 | 185 |
| 173 // While still in the same begin frame callback on the main thread, | 186 // While still in the same begin frame callback on the main thread, |
| 174 // set needs redraw again. This should not redraw. | 187 // set needs redraw again. This should not redraw. |
| 175 state.SetNeedsRedraw(true); | 188 state.SetNeedsRedraw(true); |
| 176 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); | 189 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); |
| 177 | 190 |
| 178 // Failing the draw makes us require a commit. | 191 // Failing the draw makes us require a commit. |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 197 EXPECT_EQ(SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD, | 210 EXPECT_EQ(SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD, |
| 198 state.NextAction()); | 211 state.NextAction()); |
| 199 state.UpdateState( | 212 state.UpdateState( |
| 200 SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD); | 213 SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD); |
| 201 EXPECT_TRUE(state.CommitPending()); | 214 EXPECT_TRUE(state.CommitPending()); |
| 202 | 215 |
| 203 // Then initiate a draw. | 216 // Then initiate a draw. |
| 204 state.SetNeedsRedraw(true); | 217 state.SetNeedsRedraw(true); |
| 205 EXPECT_TRUE(state.BeginFrameNeededToDrawByImplThread()); | 218 EXPECT_TRUE(state.BeginFrameNeededToDrawByImplThread()); |
| 206 state.DidEnterBeginFrame(BeginFrameArgs::CreateForTesting()); | 219 state.DidEnterBeginFrame(BeginFrameArgs::CreateForTesting()); |
| 207 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.NextAction()); | 220 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE, |
| 221 state.NextAction()); | |
| 208 EXPECT_TRUE(state.RedrawPending()); | 222 EXPECT_TRUE(state.RedrawPending()); |
| 209 | 223 |
| 210 // Fail the draw. | 224 // Fail the draw. |
| 211 state.UpdateState(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE); | 225 state.UpdateState(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); |
| 212 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); | 226 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); |
| 213 state.DidDrawIfPossibleCompleted(false); | 227 state.DidDrawIfPossibleCompleted(false); |
| 214 EXPECT_TRUE(state.RedrawPending()); | 228 EXPECT_TRUE(state.RedrawPending()); |
| 215 // But the commit is ongoing. | 229 // But the commit is ongoing. |
| 216 EXPECT_TRUE(state.CommitPending()); | 230 EXPECT_TRUE(state.CommitPending()); |
| 217 | 231 |
| 218 // Finish the commit. | 232 // Finish the commit. |
| 219 state.FinishCommit(); | 233 state.FinishCommit(); |
| 220 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction()); | 234 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction()); |
| 221 state.UpdateState(SchedulerStateMachine::ACTION_COMMIT); | 235 state.UpdateState(SchedulerStateMachine::ACTION_COMMIT); |
| 222 EXPECT_TRUE(state.RedrawPending()); | 236 EXPECT_TRUE(state.RedrawPending()); |
| 223 | 237 |
| 224 // And we should be allowed to draw again. | 238 // And we should be allowed to draw again. |
| 225 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.NextAction()); | 239 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE, |
| 240 state.NextAction()); | |
| 226 } | 241 } |
| 227 | 242 |
| 228 TEST(SchedulerStateMachineTest, | 243 TEST(SchedulerStateMachineTest, |
| 229 TestCommitAfterFailedAndSuccessfulDrawDoesNotAllowDrawInSameFrame) { | |
| 230 SchedulerSettings default_scheduler_settings; | |
| 231 StateMachine state(default_scheduler_settings); | |
| 232 state.SetCanStart(); | |
| 233 state.UpdateState(state.NextAction()); | |
| 234 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); | |
| 235 state.SetVisible(true); | |
| 236 state.SetCanDraw(true); | |
| 237 | |
| 238 // Start a commit. | |
| 239 state.SetNeedsCommit(); | |
| 240 EXPECT_EQ(SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD, | |
| 241 state.NextAction()); | |
| 242 state.UpdateState( | |
| 243 SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD); | |
| 244 EXPECT_TRUE(state.CommitPending()); | |
| 245 | |
| 246 // Then initiate a draw. | |
| 247 state.SetNeedsRedraw(true); | |
| 248 EXPECT_TRUE(state.BeginFrameNeededToDrawByImplThread()); | |
| 249 state.DidEnterBeginFrame(BeginFrameArgs::CreateForTesting()); | |
| 250 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.NextAction()); | |
| 251 EXPECT_TRUE(state.RedrawPending()); | |
| 252 | |
| 253 // Fail the draw. | |
| 254 state.UpdateState(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE); | |
| 255 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); | |
| 256 state.DidDrawIfPossibleCompleted(false); | |
| 257 EXPECT_TRUE(state.RedrawPending()); | |
| 258 // But the commit is ongoing. | |
| 259 EXPECT_TRUE(state.CommitPending()); | |
| 260 | |
| 261 // Force a draw. | |
| 262 state.SetNeedsForcedRedraw(true); | |
| 263 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_FORCED, state.NextAction()); | |
| 264 | |
| 265 // Do the forced draw. | |
| 266 state.UpdateState(SchedulerStateMachine::ACTION_DRAW_FORCED); | |
| 267 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); | |
| 268 EXPECT_FALSE(state.RedrawPending()); | |
| 269 // And the commit is still ongoing. | |
| 270 EXPECT_TRUE(state.CommitPending()); | |
| 271 | |
| 272 // Finish the commit. | |
| 273 state.FinishCommit(); | |
| 274 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction()); | |
| 275 state.UpdateState(SchedulerStateMachine::ACTION_COMMIT); | |
| 276 EXPECT_TRUE(state.RedrawPending()); | |
| 277 | |
| 278 // And we should not be allowed to draw again in the same frame.. | |
| 279 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); | |
| 280 } | |
| 281 | |
| 282 TEST(SchedulerStateMachineTest, | |
| 283 TestFailedDrawsWillEventuallyForceADrawAfterTheNextCommit) { | 244 TestFailedDrawsWillEventuallyForceADrawAfterTheNextCommit) { |
| 284 SchedulerSettings default_scheduler_settings; | 245 SchedulerSettings default_scheduler_settings; |
| 285 StateMachine state(default_scheduler_settings); | 246 StateMachine state(default_scheduler_settings); |
| 286 state.SetCanStart(); | 247 state.SetCanStart(); |
| 287 state.UpdateState(state.NextAction()); | 248 state.UpdateState(state.NextAction()); |
| 288 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); | 249 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); |
| 289 state.SetVisible(true); | 250 state.SetVisible(true); |
| 290 state.SetCanDraw(true); | 251 state.SetCanDraw(true); |
| 291 state.SetMaximumNumberOfFailedDrawsBeforeDrawIsForced(1); | 252 state.SetMaximumNumberOfFailedDrawsBeforeDrawIsForced(1); |
| 292 | 253 |
| 293 // Start a commit. | 254 // Start a commit. |
| 294 state.SetNeedsCommit(); | 255 state.SetNeedsCommit(); |
| 295 EXPECT_EQ(SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD, | 256 EXPECT_EQ(SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD, |
| 296 state.NextAction()); | 257 state.NextAction()); |
| 297 state.UpdateState( | 258 state.UpdateState( |
| 298 SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD); | 259 SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD); |
| 299 EXPECT_TRUE(state.CommitPending()); | 260 EXPECT_TRUE(state.CommitPending()); |
| 300 | 261 |
| 301 // Then initiate a draw. | 262 // Then initiate a draw. |
| 302 state.SetNeedsRedraw(true); | 263 state.SetNeedsRedraw(true); |
| 303 EXPECT_TRUE(state.BeginFrameNeededToDrawByImplThread()); | 264 EXPECT_TRUE(state.BeginFrameNeededToDrawByImplThread()); |
| 304 state.DidEnterBeginFrame(BeginFrameArgs::CreateForTesting()); | 265 state.DidEnterBeginFrame(BeginFrameArgs::CreateForTesting()); |
| 305 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.NextAction()); | 266 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE, |
| 267 state.NextAction()); | |
| 306 EXPECT_TRUE(state.RedrawPending()); | 268 EXPECT_TRUE(state.RedrawPending()); |
| 307 | 269 |
| 308 // Fail the draw. | 270 // Fail the draw. |
| 309 state.UpdateState(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE); | 271 state.UpdateState(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); |
| 310 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); | 272 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); |
| 311 state.DidDrawIfPossibleCompleted(false); | 273 state.DidDrawIfPossibleCompleted(false); |
| 312 EXPECT_TRUE(state.RedrawPending()); | 274 EXPECT_TRUE(state.RedrawPending()); |
| 313 // But the commit is ongoing. | 275 // But the commit is ongoing. |
| 314 EXPECT_TRUE(state.CommitPending()); | 276 EXPECT_TRUE(state.CommitPending()); |
| 315 | 277 |
| 316 // Finish the commit. Note, we should not yet be forcing a draw, but should | 278 // Finish the commit. Note, we should not yet be forcing a draw, but should |
| 317 // continue the commit as usual. | 279 // continue the commit as usual. |
| 318 state.FinishCommit(); | 280 state.FinishCommit(); |
| 319 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction()); | 281 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction()); |
| 320 state.UpdateState(SchedulerStateMachine::ACTION_COMMIT); | 282 state.UpdateState(SchedulerStateMachine::ACTION_COMMIT); |
| 321 EXPECT_TRUE(state.RedrawPending()); | 283 EXPECT_TRUE(state.RedrawPending()); |
| 322 | 284 |
| 323 // The redraw should be forced in this case. | 285 // The redraw should be forced in this case. |
| 324 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_FORCED, state.NextAction()); | 286 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_FORCED, |
| 287 state.NextAction()); | |
| 325 } | 288 } |
| 326 | 289 |
| 327 TEST(SchedulerStateMachineTest, | 290 TEST(SchedulerStateMachineTest, |
| 328 TestFailedDrawIsRetriedInNextBeginFrameForImplThread) { | 291 TestFailedDrawIsRetriedInNextBeginFrameForImplThread) { |
| 329 SchedulerSettings default_scheduler_settings; | 292 SchedulerSettings default_scheduler_settings; |
| 330 StateMachine state(default_scheduler_settings); | 293 StateMachine state(default_scheduler_settings); |
| 331 state.SetCanStart(); | 294 state.SetCanStart(); |
| 332 state.UpdateState(state.NextAction()); | 295 state.UpdateState(state.NextAction()); |
| 333 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); | 296 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); |
| 334 state.SetVisible(true); | 297 state.SetVisible(true); |
| 335 state.SetCanDraw(true); | 298 state.SetCanDraw(true); |
| 336 | 299 |
| 337 // Start a draw. | 300 // Start a draw. |
| 338 state.SetNeedsRedraw(true); | 301 state.SetNeedsRedraw(true); |
| 339 EXPECT_TRUE(state.BeginFrameNeededToDrawByImplThread()); | 302 EXPECT_TRUE(state.BeginFrameNeededToDrawByImplThread()); |
| 340 state.DidEnterBeginFrame(BeginFrameArgs::CreateForTesting()); | 303 state.DidEnterBeginFrame(BeginFrameArgs::CreateForTesting()); |
| 341 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.NextAction()); | 304 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE, |
| 305 state.NextAction()); | |
| 342 EXPECT_TRUE(state.RedrawPending()); | 306 EXPECT_TRUE(state.RedrawPending()); |
| 343 | 307 |
| 344 // Fail the draw. | 308 // Fail the draw. |
| 345 state.UpdateState(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE); | 309 state.UpdateState(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); |
| 346 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); | 310 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); |
| 347 state.DidDrawIfPossibleCompleted(false); | 311 state.DidDrawIfPossibleCompleted(false); |
| 348 EXPECT_TRUE(state.RedrawPending()); | 312 EXPECT_TRUE(state.RedrawPending()); |
| 349 | 313 |
| 350 // We should not be trying to draw again now, but we have a commit pending. | 314 // We should not be trying to draw again now, but we have a commit pending. |
| 351 EXPECT_EQ(SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD, | 315 EXPECT_EQ(SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD, |
| 352 state.NextAction()); | 316 state.NextAction()); |
| 353 | 317 |
| 354 state.DidLeaveBeginFrame(); | 318 state.DidLeaveBeginFrame(); |
| 355 EXPECT_TRUE(state.BeginFrameNeededToDrawByImplThread()); | 319 EXPECT_TRUE(state.BeginFrameNeededToDrawByImplThread()); |
| 356 state.DidEnterBeginFrame(BeginFrameArgs::CreateForTesting()); | 320 state.DidEnterBeginFrame(BeginFrameArgs::CreateForTesting()); |
| 357 | 321 |
| 358 // We should try to draw again in the next begin frame on the impl thread. | 322 // We should try to draw again in the next begin frame on the impl thread. |
| 359 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.NextAction()); | 323 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE, |
| 324 state.NextAction()); | |
| 360 } | 325 } |
| 361 | 326 |
| 362 TEST(SchedulerStateMachineTest, TestDoestDrawTwiceInSameFrame) { | 327 TEST(SchedulerStateMachineTest, TestDoestDrawTwiceInSameFrame) { |
| 363 SchedulerSettings default_scheduler_settings; | 328 SchedulerSettings default_scheduler_settings; |
| 364 StateMachine state(default_scheduler_settings); | 329 StateMachine state(default_scheduler_settings); |
| 365 state.SetCanStart(); | 330 state.SetCanStart(); |
| 366 state.UpdateState(state.NextAction()); | 331 state.UpdateState(state.NextAction()); |
| 367 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); | 332 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); |
| 368 state.SetVisible(true); | 333 state.SetVisible(true); |
| 369 state.SetCanDraw(true); | 334 state.SetCanDraw(true); |
| 370 state.SetNeedsRedraw(true); | 335 state.SetNeedsRedraw(true); |
| 371 EXPECT_TRUE(state.BeginFrameNeededToDrawByImplThread()); | 336 EXPECT_TRUE(state.BeginFrameNeededToDrawByImplThread()); |
| 372 state.DidEnterBeginFrame(BeginFrameArgs::CreateForTesting()); | 337 state.DidEnterBeginFrame(BeginFrameArgs::CreateForTesting()); |
| 373 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.NextAction()); | 338 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE, |
| 374 state.UpdateState(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE); | 339 state.NextAction()); |
| 340 state.UpdateState(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); | |
| 375 | 341 |
| 376 // While still in the same begin frame for the impl thread, set needs redraw | 342 // While still in the same begin frame for the impl thread, set needs redraw |
| 377 // again. This should not redraw. | 343 // again. This should not redraw. |
| 378 state.SetNeedsRedraw(true); | 344 state.SetNeedsRedraw(true); |
| 379 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); | 345 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); |
| 380 | 346 |
| 381 // Move to another frame. This should now draw. | 347 // Move to another frame. This should now draw. |
| 382 state.DidDrawIfPossibleCompleted(true); | 348 state.DidDrawIfPossibleCompleted(true); |
| 383 state.DidLeaveBeginFrame(); | 349 state.DidLeaveBeginFrame(); |
| 384 EXPECT_TRUE(state.BeginFrameNeededToDrawByImplThread()); | 350 EXPECT_TRUE(state.BeginFrameNeededToDrawByImplThread()); |
| 385 state.DidEnterBeginFrame(BeginFrameArgs::CreateForTesting()); | 351 state.DidEnterBeginFrame(BeginFrameArgs::CreateForTesting()); |
| 386 | 352 |
| 387 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.NextAction()); | 353 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE, |
| 388 state.UpdateState(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE); | 354 state.NextAction()); |
| 355 state.UpdateState(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); | |
| 389 state.DidDrawIfPossibleCompleted(true); | 356 state.DidDrawIfPossibleCompleted(true); |
| 390 EXPECT_FALSE(state.BeginFrameNeededToDrawByImplThread()); | 357 EXPECT_FALSE(state.BeginFrameNeededToDrawByImplThread()); |
| 391 } | 358 } |
| 392 | 359 |
| 393 TEST(SchedulerStateMachineTest, TestNextActionDrawsOnBeginFrame) { | 360 TEST(SchedulerStateMachineTest, TestNextActionDrawsOnBeginFrame) { |
| 394 SchedulerSettings default_scheduler_settings; | 361 SchedulerSettings default_scheduler_settings; |
| 395 | 362 |
| 396 // When not in BeginFrame, or in BeginFrame but not visible, | 363 // When not in BeginFrame, or in BeginFrame but not visible, |
| 397 // don't draw. | 364 // don't draw. |
| 398 size_t num_commit_states = | 365 size_t num_commit_states = |
| 399 sizeof(all_commit_states) / sizeof(SchedulerStateMachine::CommitState); | 366 sizeof(all_commit_states) / sizeof(SchedulerStateMachine::CommitState); |
| 400 for (size_t i = 0; i < num_commit_states; ++i) { | 367 for (size_t i = 0; i < num_commit_states; ++i) { |
| 401 for (size_t j = 0; j < 2; ++j) { | 368 for (size_t j = 0; j < 2; ++j) { |
| 402 StateMachine state(default_scheduler_settings); | 369 StateMachine state(default_scheduler_settings); |
| 403 state.SetCanStart(); | 370 state.SetCanStart(); |
| 404 state.UpdateState(state.NextAction()); | 371 state.UpdateState(state.NextAction()); |
| 405 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); | 372 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); |
| 406 state.SetCommitState(all_commit_states[i]); | 373 state.SetCommitState(all_commit_states[i]); |
| 407 bool visible = j; | 374 bool visible = j; |
| 408 if (!visible) { | 375 if (!visible) { |
| 409 state.DidEnterBeginFrame(BeginFrameArgs::CreateForTesting()); | 376 state.DidEnterBeginFrame(BeginFrameArgs::CreateForTesting()); |
| 410 state.SetVisible(false); | 377 state.SetVisible(false); |
| 411 } else { | 378 } else { |
| 412 state.SetVisible(true); | 379 state.SetVisible(true); |
| 413 } | 380 } |
| 414 | 381 |
| 415 // Case 1: needs_commit=false | 382 // Case 1: needs_commit=false |
| 416 EXPECT_NE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, | 383 EXPECT_NE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE, |
| 417 state.NextAction()); | 384 state.NextAction()); |
| 418 | 385 |
| 419 // Case 2: needs_commit=true | 386 // Case 2: needs_commit=true |
| 420 state.SetNeedsCommit(); | 387 state.SetNeedsCommit(); |
| 421 EXPECT_NE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, | 388 EXPECT_NE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE, |
| 422 state.NextAction()); | 389 state.NextAction()); |
| 423 } | 390 } |
| 424 } | 391 } |
| 425 | 392 |
| 426 // When in BeginFrame, or not in BeginFrame but needs_forced_dedraw | 393 // When in BeginFrame, or not in BeginFrame but needs_forced_dedraw |
| 427 // set, should always draw except if you're ready to commit, in which case | 394 // set, should always draw except if you're ready to commit, in which case |
| 428 // commit. | 395 // commit. |
| 429 for (size_t i = 0; i < num_commit_states; ++i) { | 396 for (size_t i = 0; i < num_commit_states; ++i) { |
| 430 for (size_t j = 0; j < 2; ++j) { | 397 for (size_t j = 0; j < 2; ++j) { |
| 398 bool request_readback = j; | |
| 399 | |
| 400 // Skip invalid states | |
| 401 if (request_readback && | |
| 402 (SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW != | |
| 403 all_commit_states[i])) | |
| 404 continue; | |
| 405 | |
| 431 StateMachine state(default_scheduler_settings); | 406 StateMachine state(default_scheduler_settings); |
| 432 state.SetCanStart(); | 407 state.SetCanStart(); |
| 433 state.UpdateState(state.NextAction()); | 408 state.UpdateState(state.NextAction()); |
| 434 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); | 409 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); |
| 435 state.SetCanDraw(true); | 410 state.SetCanDraw(true); |
| 436 state.SetCommitState(all_commit_states[i]); | 411 state.SetCommitState(all_commit_states[i]); |
| 437 bool forced_draw = j; | 412 if (!request_readback) { |
| 438 if (!forced_draw) { | |
| 439 state.DidEnterBeginFrame(BeginFrameArgs::CreateForTesting()); | 413 state.DidEnterBeginFrame(BeginFrameArgs::CreateForTesting()); |
| 440 state.SetNeedsRedraw(true); | 414 state.SetNeedsRedraw(true); |
| 441 state.SetVisible(true); | 415 state.SetVisible(true); |
| 442 } else { | 416 } else { |
| 443 state.SetNeedsForcedRedraw(true); | 417 state.SetNeedsForcedRedrawForReadback(); |
| 444 } | 418 } |
| 445 | 419 |
| 446 SchedulerStateMachine::Action expected_action; | 420 SchedulerStateMachine::Action expected_action; |
| 447 if (all_commit_states[i] != | 421 if (all_commit_states[i] != |
| 448 SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT) { | 422 SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT) { |
| 449 expected_action = | 423 expected_action = |
| 450 forced_draw ? SchedulerStateMachine::ACTION_DRAW_FORCED | 424 request_readback |
| 451 : SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE; | 425 ? SchedulerStateMachine::ACTION_DRAW_AND_READBACK |
| 426 : SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE; | |
| 452 } else { | 427 } else { |
| 453 expected_action = SchedulerStateMachine::ACTION_COMMIT; | 428 expected_action = SchedulerStateMachine::ACTION_COMMIT; |
| 454 } | 429 } |
| 455 | 430 |
| 456 // Case 1: needs_commit=false. | 431 // Case 1: needs_commit=false. |
| 457 EXPECT_TRUE(state.BeginFrameNeededToDrawByImplThread()); | 432 EXPECT_NE(state.BeginFrameNeededToDrawByImplThread(), request_readback) |
| 433 << *state.AsValue(); | |
| 458 EXPECT_EQ(expected_action, state.NextAction()) << *state.AsValue(); | 434 EXPECT_EQ(expected_action, state.NextAction()) << *state.AsValue(); |
| 459 | 435 |
| 460 // Case 2: needs_commit=true. | 436 // Case 2: needs_commit=true. |
| 461 state.SetNeedsCommit(); | 437 state.SetNeedsCommit(); |
| 462 EXPECT_TRUE(state.BeginFrameNeededToDrawByImplThread()); | 438 EXPECT_NE(state.BeginFrameNeededToDrawByImplThread(), request_readback) |
| 439 << *state.AsValue(); | |
| 463 EXPECT_EQ(expected_action, state.NextAction()) << *state.AsValue(); | 440 EXPECT_EQ(expected_action, state.NextAction()) << *state.AsValue(); |
| 464 } | 441 } |
| 465 } | 442 } |
| 466 } | 443 } |
| 467 | 444 |
| 468 TEST(SchedulerStateMachineTest, TestNoCommitStatesRedrawWhenInvisible) { | 445 TEST(SchedulerStateMachineTest, TestNoCommitStatesRedrawWhenInvisible) { |
| 469 SchedulerSettings default_scheduler_settings; | 446 SchedulerSettings default_scheduler_settings; |
| 470 | 447 |
| 471 size_t num_commit_states = | 448 size_t num_commit_states = |
| 472 sizeof(all_commit_states) / sizeof(SchedulerStateMachine::CommitState); | 449 sizeof(all_commit_states) / sizeof(SchedulerStateMachine::CommitState); |
| 473 for (size_t i = 0; i < num_commit_states; ++i) { | 450 for (size_t i = 0; i < num_commit_states; ++i) { |
| 474 // There shouldn't be any drawing regardless of BeginFrame. | 451 // There shouldn't be any drawing regardless of BeginFrame. |
| 475 for (size_t j = 0; j < 2; ++j) { | 452 for (size_t j = 0; j < 2; ++j) { |
| 476 StateMachine state(default_scheduler_settings); | 453 StateMachine state(default_scheduler_settings); |
| 477 state.SetCanStart(); | 454 state.SetCanStart(); |
| 478 state.UpdateState(state.NextAction()); | 455 state.UpdateState(state.NextAction()); |
| 479 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); | 456 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); |
| 480 state.SetCommitState(all_commit_states[i]); | 457 state.SetCommitState(all_commit_states[i]); |
| 481 state.SetVisible(false); | 458 state.SetVisible(false); |
| 482 state.SetNeedsRedraw(true); | 459 state.SetNeedsRedraw(true); |
| 483 state.SetNeedsForcedRedraw(false); | |
| 484 if (j == 1) | 460 if (j == 1) |
| 485 state.DidEnterBeginFrame(BeginFrameArgs::CreateForTesting()); | 461 state.DidEnterBeginFrame(BeginFrameArgs::CreateForTesting()); |
| 486 | 462 |
| 487 // Case 1: needs_commit=false. | 463 // Case 1: needs_commit=false. |
| 488 EXPECT_NE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, | 464 EXPECT_NE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE, |
| 489 state.NextAction()); | 465 state.NextAction()); |
| 490 | 466 |
| 491 // Case 2: needs_commit=true. | 467 // Case 2: needs_commit=true. |
| 492 state.SetNeedsCommit(); | 468 state.SetNeedsCommit(); |
| 493 EXPECT_NE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, | 469 EXPECT_NE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE, |
| 494 state.NextAction()); | 470 state.NextAction()); |
| 495 } | 471 } |
| 496 } | 472 } |
| 497 } | 473 } |
| 498 | 474 |
| 499 TEST(SchedulerStateMachineTest, TestCanRedraw_StopsDraw) { | 475 TEST(SchedulerStateMachineTest, TestCanRedraw_StopsDraw) { |
| 500 SchedulerSettings default_scheduler_settings; | 476 SchedulerSettings default_scheduler_settings; |
| 501 | 477 |
| 502 size_t num_commit_states = | 478 size_t num_commit_states = |
| 503 sizeof(all_commit_states) / sizeof(SchedulerStateMachine::CommitState); | 479 sizeof(all_commit_states) / sizeof(SchedulerStateMachine::CommitState); |
| 504 for (size_t i = 0; i < num_commit_states; ++i) { | 480 for (size_t i = 0; i < num_commit_states; ++i) { |
| 505 // There shouldn't be any drawing regardless of BeginFrame. | 481 // There shouldn't be any drawing regardless of BeginFrame. |
| 506 for (size_t j = 0; j < 2; ++j) { | 482 for (size_t j = 0; j < 2; ++j) { |
| 507 StateMachine state(default_scheduler_settings); | 483 StateMachine state(default_scheduler_settings); |
| 508 state.SetCanStart(); | 484 state.SetCanStart(); |
| 509 state.UpdateState(state.NextAction()); | 485 state.UpdateState(state.NextAction()); |
| 510 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); | 486 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); |
| 511 state.SetCommitState(all_commit_states[i]); | 487 state.SetCommitState(all_commit_states[i]); |
| 512 state.SetVisible(false); | 488 state.SetVisible(false); |
| 513 state.SetNeedsRedraw(true); | 489 state.SetNeedsRedraw(true); |
| 514 state.SetNeedsForcedRedraw(false); | |
| 515 if (j == 1) | 490 if (j == 1) |
| 516 state.DidEnterBeginFrame(BeginFrameArgs::CreateForTesting()); | 491 state.DidEnterBeginFrame(BeginFrameArgs::CreateForTesting()); |
| 517 | 492 |
| 518 state.SetCanDraw(false); | 493 state.SetCanDraw(false); |
| 519 EXPECT_NE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, | 494 EXPECT_NE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE, |
| 520 state.NextAction()); | 495 state.NextAction()); |
| 521 } | 496 } |
| 522 } | 497 } |
| 523 } | 498 } |
| 524 | 499 |
| 525 TEST(SchedulerStateMachineTest, | 500 TEST(SchedulerStateMachineTest, |
| 526 TestCanRedrawWithWaitingForFirstDrawMakesProgress) { | 501 TestCanRedrawWithWaitingForFirstDrawMakesProgress) { |
| 527 SchedulerSettings default_scheduler_settings; | 502 SchedulerSettings default_scheduler_settings; |
| 528 StateMachine state(default_scheduler_settings); | 503 StateMachine state(default_scheduler_settings); |
| 529 state.SetCanStart(); | 504 state.SetCanStart(); |
| 530 state.UpdateState(state.NextAction()); | 505 state.UpdateState(state.NextAction()); |
| 531 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); | 506 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); |
| 532 state.SetCommitState( | 507 |
| 533 SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW); | 508 state.SetVisible(true); |
| 509 state.SetNeedsCommit(); | |
| 510 EXPECT_ACTION_UPDATE_STATE( | |
| 511 SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD); | |
| 512 state.FinishCommit(); | |
| 513 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); | |
| 514 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW, | |
| 515 state.CommitState()); | |
| 516 | |
| 534 state.SetNeedsCommit(); | 517 state.SetNeedsCommit(); |
| 535 state.SetNeedsRedraw(true); | 518 state.SetNeedsRedraw(true); |
| 536 state.SetVisible(true); | 519 state.SetVisible(true); |
| 537 state.SetCanDraw(false); | 520 state.SetCanDraw(false); |
| 538 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT, | 521 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT) |
| 539 state.NextAction()); | 522 |
| 540 state.UpdateState(state.NextAction()); | 523 state.DidEnterBeginFrame(BeginFrameArgs::CreateForTesting()); |
| 541 EXPECT_EQ(SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD, | 524 EXPECT_ACTION_UPDATE_STATE( |
| 542 state.NextAction()); | 525 SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD); |
| 526 state.DidLeaveBeginFrame(); | |
| 527 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | |
| 543 } | 528 } |
| 544 | 529 |
| 545 TEST(SchedulerStateMachineTest, TestsetNeedsCommitIsNotLost) { | 530 TEST(SchedulerStateMachineTest, TestsetNeedsCommitIsNotLost) { |
| 546 SchedulerSettings default_scheduler_settings; | 531 SchedulerSettings default_scheduler_settings; |
| 547 StateMachine state(default_scheduler_settings); | 532 StateMachine state(default_scheduler_settings); |
| 548 state.SetCanStart(); | 533 state.SetCanStart(); |
| 549 state.UpdateState(state.NextAction()); | 534 state.UpdateState(state.NextAction()); |
| 550 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); | 535 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); |
| 551 state.SetNeedsCommit(); | 536 state.SetNeedsCommit(); |
| 552 state.SetVisible(true); | 537 state.SetVisible(true); |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 569 state.CommitState()); | 554 state.CommitState()); |
| 570 | 555 |
| 571 // Expect to commit regardless of BeginFrame state. | 556 // Expect to commit regardless of BeginFrame state. |
| 572 state.DidLeaveBeginFrame(); | 557 state.DidLeaveBeginFrame(); |
| 573 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction()); | 558 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction()); |
| 574 state.DidEnterBeginFrame(BeginFrameArgs::CreateForTesting()); | 559 state.DidEnterBeginFrame(BeginFrameArgs::CreateForTesting()); |
| 575 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction()); | 560 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction()); |
| 576 | 561 |
| 577 // Commit and make sure we draw on next BeginFrame | 562 // Commit and make sure we draw on next BeginFrame |
| 578 state.UpdateState(SchedulerStateMachine::ACTION_COMMIT); | 563 state.UpdateState(SchedulerStateMachine::ACTION_COMMIT); |
| 579 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.NextAction()); | 564 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE, |
| 565 state.NextAction()); | |
| 580 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW, | 566 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW, |
| 581 state.CommitState()); | 567 state.CommitState()); |
| 582 state.UpdateState(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE); | 568 state.UpdateState(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); |
| 583 state.DidDrawIfPossibleCompleted(true); | 569 state.DidDrawIfPossibleCompleted(true); |
| 584 | 570 |
| 585 // Verify that another commit will begin. | 571 // Verify that another commit will begin. |
| 586 state.DidLeaveBeginFrame(); | 572 state.DidLeaveBeginFrame(); |
| 587 EXPECT_EQ(SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD, | 573 EXPECT_EQ(SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD, |
| 588 state.NextAction()); | 574 state.NextAction()); |
| 589 } | 575 } |
| 590 | 576 |
| 591 TEST(SchedulerStateMachineTest, TestFullCycle) { | 577 TEST(SchedulerStateMachineTest, TestFullCycle) { |
| 592 SchedulerSettings default_scheduler_settings; | 578 SchedulerSettings default_scheduler_settings; |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 620 state.UpdateState(SchedulerStateMachine::ACTION_COMMIT); | 606 state.UpdateState(SchedulerStateMachine::ACTION_COMMIT); |
| 621 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW, | 607 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW, |
| 622 state.CommitState()); | 608 state.CommitState()); |
| 623 EXPECT_TRUE(state.NeedsRedraw()); | 609 EXPECT_TRUE(state.NeedsRedraw()); |
| 624 | 610 |
| 625 // Expect to do nothing until BeginFrame. | 611 // Expect to do nothing until BeginFrame. |
| 626 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); | 612 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); |
| 627 | 613 |
| 628 // At BeginFrame, draw. | 614 // At BeginFrame, draw. |
| 629 state.DidEnterBeginFrame(BeginFrameArgs::CreateForTesting()); | 615 state.DidEnterBeginFrame(BeginFrameArgs::CreateForTesting()); |
| 630 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.NextAction()); | 616 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE, |
| 631 state.UpdateState(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE); | 617 state.NextAction()); |
| 618 state.UpdateState(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); | |
| 632 state.DidDrawIfPossibleCompleted(true); | 619 state.DidDrawIfPossibleCompleted(true); |
| 633 state.DidLeaveBeginFrame(); | 620 state.DidLeaveBeginFrame(); |
| 634 | 621 |
| 635 // Should be synchronized, no draw needed, no action needed. | 622 // Should be synchronized, no draw needed, no action needed. |
| 636 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState()); | 623 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState()); |
| 637 EXPECT_FALSE(state.NeedsRedraw()); | 624 EXPECT_FALSE(state.NeedsRedraw()); |
| 638 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); | 625 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); |
| 639 } | 626 } |
| 640 | 627 |
| 641 TEST(SchedulerStateMachineTest, TestFullCycleWithCommitRequestInbetween) { | 628 TEST(SchedulerStateMachineTest, TestFullCycleWithCommitRequestInbetween) { |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 674 state.UpdateState(SchedulerStateMachine::ACTION_COMMIT); | 661 state.UpdateState(SchedulerStateMachine::ACTION_COMMIT); |
| 675 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW, | 662 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW, |
| 676 state.CommitState()); | 663 state.CommitState()); |
| 677 EXPECT_TRUE(state.NeedsRedraw()); | 664 EXPECT_TRUE(state.NeedsRedraw()); |
| 678 | 665 |
| 679 // Expect to do nothing until BeginFrame. | 666 // Expect to do nothing until BeginFrame. |
| 680 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); | 667 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); |
| 681 | 668 |
| 682 // At BeginFrame, draw. | 669 // At BeginFrame, draw. |
| 683 state.DidEnterBeginFrame(BeginFrameArgs::CreateForTesting()); | 670 state.DidEnterBeginFrame(BeginFrameArgs::CreateForTesting()); |
| 684 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.NextAction()); | 671 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE, |
| 685 state.UpdateState(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE); | 672 state.NextAction()); |
| 673 state.UpdateState(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); | |
| 686 state.DidDrawIfPossibleCompleted(true); | 674 state.DidDrawIfPossibleCompleted(true); |
| 687 state.DidLeaveBeginFrame(); | 675 state.DidLeaveBeginFrame(); |
| 688 | 676 |
| 689 // Should be synchronized, no draw needed, no action needed. | 677 // Should be synchronized, no draw needed, no action needed. |
| 690 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState()); | 678 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState()); |
| 691 EXPECT_FALSE(state.NeedsRedraw()); | 679 EXPECT_FALSE(state.NeedsRedraw()); |
| 692 EXPECT_EQ(SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD, | 680 EXPECT_EQ(SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD, |
| 693 state.NextAction()); | 681 state.NextAction()); |
| 694 } | 682 } |
| 695 | 683 |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 780 state.BeginFrameAbortedByMainThread(true); | 768 state.BeginFrameAbortedByMainThread(true); |
| 781 | 769 |
| 782 // Verify that another commit doesn't start on the same frame. | 770 // Verify that another commit doesn't start on the same frame. |
| 783 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState()); | 771 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState()); |
| 784 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); | 772 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); |
| 785 EXPECT_FALSE(state.NeedsCommit()); | 773 EXPECT_FALSE(state.NeedsCommit()); |
| 786 | 774 |
| 787 // Start a new frame; draw because this is the first frame since output | 775 // Start a new frame; draw because this is the first frame since output |
| 788 // surface init'd. | 776 // surface init'd. |
| 789 state.DidEnterBeginFrame(BeginFrameArgs::CreateForTesting()); | 777 state.DidEnterBeginFrame(BeginFrameArgs::CreateForTesting()); |
| 790 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.NextAction()) | 778 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE, |
| 779 state.NextAction()) | |
| 791 << *state.AsValue(); | 780 << *state.AsValue(); |
| 792 state.DidLeaveBeginFrame(); | 781 state.DidLeaveBeginFrame(); |
| 793 | 782 |
| 794 // Verify another commit doesn't start on another frame either. | 783 // Verify another commit doesn't start on another frame either. |
| 795 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState()); | 784 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState()); |
| 796 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); | 785 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); |
| 797 EXPECT_FALSE(state.NeedsCommit()); | 786 EXPECT_FALSE(state.NeedsCommit()); |
| 798 | 787 |
| 799 // Verify another commit can start if requested, though. | 788 // Verify another commit can start if requested, though. |
| 800 state.SetNeedsCommit(); | 789 state.SetNeedsCommit(); |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 889 state.FinishCommit(); | 878 state.FinishCommit(); |
| 890 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction()); | 879 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction()); |
| 891 state.UpdateState(state.NextAction()); | 880 state.UpdateState(state.NextAction()); |
| 892 // Finishing the first commit after initializing an output surface should | 881 // Finishing the first commit after initializing an output surface should |
| 893 // automatically cause a redraw. | 882 // automatically cause a redraw. |
| 894 EXPECT_TRUE(state.RedrawPending()); | 883 EXPECT_TRUE(state.RedrawPending()); |
| 895 | 884 |
| 896 // Once the context is recreated, whether we draw should be based on | 885 // Once the context is recreated, whether we draw should be based on |
| 897 // SetCanDraw. | 886 // SetCanDraw. |
| 898 state.DidEnterBeginFrame(BeginFrameArgs::CreateForTesting()); | 887 state.DidEnterBeginFrame(BeginFrameArgs::CreateForTesting()); |
| 899 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.NextAction()); | 888 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE, |
| 889 state.NextAction()); | |
| 900 state.SetCanDraw(false); | 890 state.SetCanDraw(false); |
| 901 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT, | 891 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT, |
| 902 state.NextAction()); | 892 state.NextAction()); |
| 903 state.SetCanDraw(true); | 893 state.SetCanDraw(true); |
| 904 state.DidLeaveBeginFrame(); | 894 state.DidLeaveBeginFrame(); |
| 905 } | 895 } |
| 906 | 896 |
| 907 TEST(SchedulerStateMachineTest, TestContextLostWhileCommitInProgress) { | 897 TEST(SchedulerStateMachineTest, TestContextLostWhileCommitInProgress) { |
| 908 SchedulerSettings default_scheduler_settings; | 898 SchedulerSettings default_scheduler_settings; |
| 909 StateMachine state(default_scheduler_settings); | 899 StateMachine state(default_scheduler_settings); |
| 910 state.SetCanStart(); | 900 state.SetCanStart(); |
| 911 state.UpdateState(state.NextAction()); | 901 state.UpdateState(state.NextAction()); |
| 912 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); | 902 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); |
| 913 state.SetVisible(true); | 903 state.SetVisible(true); |
| 914 state.SetCanDraw(true); | 904 state.SetCanDraw(true); |
| 915 | 905 |
| 916 // Get a commit in flight. | 906 // Get a commit in flight. |
| 917 state.SetNeedsCommit(); | 907 state.SetNeedsCommit(); |
| 918 EXPECT_EQ(SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD, | 908 EXPECT_EQ(SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD, |
| 919 state.NextAction()); | 909 state.NextAction()); |
| 920 state.UpdateState(state.NextAction()); | 910 state.UpdateState(state.NextAction()); |
| 921 | 911 |
| 922 // Set damage and expect a draw. | 912 // Set damage and expect a draw. |
| 923 state.SetNeedsRedraw(true); | 913 state.SetNeedsRedraw(true); |
| 924 state.DidEnterBeginFrame(BeginFrameArgs::CreateForTesting()); | 914 state.DidEnterBeginFrame(BeginFrameArgs::CreateForTesting()); |
| 925 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.NextAction()); | 915 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE, |
| 916 state.NextAction()); | |
| 926 state.UpdateState(state.NextAction()); | 917 state.UpdateState(state.NextAction()); |
| 927 state.DidLeaveBeginFrame(); | 918 state.DidLeaveBeginFrame(); |
| 928 | 919 |
| 929 // Cause a lost context while the begin frame is in flight | 920 // Cause a lost context while the begin frame is in flight |
| 930 // for the main thread. | 921 // for the main thread. |
| 931 state.DidLoseOutputSurface(); | 922 state.DidLoseOutputSurface(); |
| 932 | 923 |
| 933 // Ask for another draw. Expect nothing happens. | 924 // Ask for another draw. Expect nothing happens. |
| 934 state.SetNeedsRedraw(true); | 925 state.SetNeedsRedraw(true); |
| 935 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); | 926 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 968 | 959 |
| 969 // Get a commit in flight. | 960 // Get a commit in flight. |
| 970 state.SetNeedsCommit(); | 961 state.SetNeedsCommit(); |
| 971 EXPECT_EQ(SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD, | 962 EXPECT_EQ(SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD, |
| 972 state.NextAction()); | 963 state.NextAction()); |
| 973 state.UpdateState(state.NextAction()); | 964 state.UpdateState(state.NextAction()); |
| 974 | 965 |
| 975 // Set damage and expect a draw. | 966 // Set damage and expect a draw. |
| 976 state.SetNeedsRedraw(true); | 967 state.SetNeedsRedraw(true); |
| 977 state.DidEnterBeginFrame(BeginFrameArgs::CreateForTesting()); | 968 state.DidEnterBeginFrame(BeginFrameArgs::CreateForTesting()); |
| 978 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.NextAction()); | 969 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE, |
| 970 state.NextAction()); | |
| 979 state.UpdateState(state.NextAction()); | 971 state.UpdateState(state.NextAction()); |
| 980 state.DidLeaveBeginFrame(); | 972 state.DidLeaveBeginFrame(); |
| 981 | 973 |
| 982 // Cause a lost context while the begin frame is in flight | 974 // Cause a lost context while the begin frame is in flight |
| 983 // for the main thread. | 975 // for the main thread. |
| 984 state.DidLoseOutputSurface(); | 976 state.DidLoseOutputSurface(); |
| 985 | 977 |
| 986 // Ask for another draw and also set needs commit. Expect nothing happens. | 978 // Ask for another draw and also set needs commit. Expect nothing happens. |
| 987 state.SetNeedsRedraw(true); | 979 state.SetNeedsRedraw(true); |
| 988 state.SetNeedsCommit(); | 980 state.SetNeedsCommit(); |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 1015 StateMachine state(default_scheduler_settings); | 1007 StateMachine state(default_scheduler_settings); |
| 1016 state.SetCanStart(); | 1008 state.SetCanStart(); |
| 1017 state.UpdateState(state.NextAction()); | 1009 state.UpdateState(state.NextAction()); |
| 1018 state.DidCreateAndInitializeOutputSurface(); | 1010 state.DidCreateAndInitializeOutputSurface(); |
| 1019 state.SetVisible(true); | 1011 state.SetVisible(true); |
| 1020 state.SetCanDraw(true); | 1012 state.SetCanDraw(true); |
| 1021 | 1013 |
| 1022 // Cause a lost context lost. | 1014 // Cause a lost context lost. |
| 1023 state.DidLoseOutputSurface(); | 1015 state.DidLoseOutputSurface(); |
| 1024 | 1016 |
| 1025 // Ask a forced redraw and verify it ocurrs. | 1017 // Ask a forced redraw and verify it ocurrs, even with a lost context, |
| 1026 state.SetNeedsForcedRedraw(true); | 1018 // independent of the BeginFrame stae. |
| 1027 state.DidEnterBeginFrame(BeginFrameArgs::CreateForTesting()); | 1019 state.SetNeedsForcedRedrawForReadback(); |
| 1028 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_FORCED, state.NextAction()); | 1020 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_READBACK); |
| 1029 state.DidLeaveBeginFrame(); | |
| 1030 | 1021 |
| 1031 // Clear the forced redraw bit. | 1022 // Forced redraws for readbacks need to be followed by a new commit |
| 1032 state.SetNeedsForcedRedraw(false); | 1023 // to replace the readback commit. |
| 1024 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, | |
| 1025 state.CommitState()); | |
| 1026 state.FinishCommit(); | |
| 1027 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); | |
| 1028 | |
| 1029 // We don't yet have an output surface, so we the draw and swap should abort. | |
| 1030 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT); | |
| 1033 | 1031 |
| 1034 // Expect to be told to begin context recreation, independent of | 1032 // Expect to be told to begin context recreation, independent of |
| 1035 // BeginFrame state | 1033 // BeginFrame state. |
| 1036 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION, | 1034 EXPECT_ACTION_UPDATE_STATE( |
| 1035 SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION); | |
| 1036 | |
| 1037 // Ask a readback and verify it ocurrs. | |
| 1038 state.SetNeedsForcedRedrawForReadback(); | |
| 1039 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_AND_READBACK, | |
| 1037 state.NextAction()); | 1040 state.NextAction()); |
| 1038 state.UpdateState(state.NextAction()); | |
| 1039 | |
| 1040 // Ask a forced redraw and verify it ocurrs. | |
| 1041 state.SetNeedsForcedRedraw(true); | |
| 1042 state.DidEnterBeginFrame(BeginFrameArgs::CreateForTesting()); | |
| 1043 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_FORCED, state.NextAction()); | |
| 1044 state.DidLeaveBeginFrame(); | |
| 1045 } | 1041 } |
| 1046 | 1042 |
| 1047 TEST(SchedulerStateMachineTest, DontDrawBeforeCommitAfterLostOutputSurface) { | 1043 TEST(SchedulerStateMachineTest, DontDrawBeforeCommitAfterLostOutputSurface) { |
| 1048 SchedulerSettings default_scheduler_settings; | 1044 SchedulerSettings default_scheduler_settings; |
| 1049 StateMachine state(default_scheduler_settings); | 1045 StateMachine state(default_scheduler_settings); |
| 1050 state.SetCanStart(); | 1046 state.SetCanStart(); |
| 1051 state.UpdateState(state.NextAction()); | 1047 state.UpdateState(state.NextAction()); |
| 1052 state.DidCreateAndInitializeOutputSurface(); | 1048 state.DidCreateAndInitializeOutputSurface(); |
| 1053 state.SetVisible(true); | 1049 state.SetVisible(true); |
| 1054 state.SetCanDraw(true); | 1050 state.SetCanDraw(true); |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 1069 | 1065 |
| 1070 TEST(SchedulerStateMachineTest, | 1066 TEST(SchedulerStateMachineTest, |
| 1071 TestSendBeginFrameToMainThreadWhenInvisibleAndForceCommit) { | 1067 TestSendBeginFrameToMainThreadWhenInvisibleAndForceCommit) { |
| 1072 SchedulerSettings default_scheduler_settings; | 1068 SchedulerSettings default_scheduler_settings; |
| 1073 StateMachine state(default_scheduler_settings); | 1069 StateMachine state(default_scheduler_settings); |
| 1074 state.SetCanStart(); | 1070 state.SetCanStart(); |
| 1075 state.UpdateState(state.NextAction()); | 1071 state.UpdateState(state.NextAction()); |
| 1076 state.DidCreateAndInitializeOutputSurface(); | 1072 state.DidCreateAndInitializeOutputSurface(); |
| 1077 state.SetVisible(false); | 1073 state.SetVisible(false); |
| 1078 state.SetNeedsCommit(); | 1074 state.SetNeedsCommit(); |
| 1079 state.SetNeedsForcedCommit(); | 1075 state.SetNeedsForcedCommitForReadback(); |
| 1080 EXPECT_EQ(SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD, | 1076 EXPECT_EQ(SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD, |
| 1081 state.NextAction()); | 1077 state.NextAction()); |
| 1082 } | 1078 } |
| 1083 | 1079 |
| 1084 TEST(SchedulerStateMachineTest, | 1080 TEST(SchedulerStateMachineTest, |
| 1085 TestSendBeginFrameToMainThreadWhenCanStartFalseAndForceCommit) { | 1081 TestSendBeginFrameToMainThreadWhenCanStartFalseAndForceCommit) { |
| 1086 SchedulerSettings default_scheduler_settings; | 1082 SchedulerSettings default_scheduler_settings; |
| 1087 StateMachine state(default_scheduler_settings); | 1083 StateMachine state(default_scheduler_settings); |
| 1088 state.SetVisible(true); | 1084 state.SetVisible(true); |
| 1089 state.SetCanDraw(true); | 1085 state.SetCanDraw(true); |
| 1090 state.SetNeedsCommit(); | 1086 state.SetNeedsCommit(); |
| 1091 state.SetNeedsForcedCommit(); | 1087 state.SetNeedsForcedCommitForReadback(); |
| 1092 EXPECT_EQ(SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD, | 1088 EXPECT_EQ(SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD, |
| 1093 state.NextAction()); | 1089 state.NextAction()); |
| 1094 } | 1090 } |
| 1095 | 1091 |
| 1096 TEST(SchedulerStateMachineTest, TestFinishCommitWhenCommitInProgress) { | 1092 TEST(SchedulerStateMachineTest, TestFinishCommitWhenCommitInProgress) { |
| 1097 SchedulerSettings default_scheduler_settings; | 1093 SchedulerSettings default_scheduler_settings; |
| 1098 StateMachine state(default_scheduler_settings); | 1094 StateMachine state(default_scheduler_settings); |
| 1099 state.SetCanStart(); | 1095 state.SetCanStart(); |
| 1100 state.UpdateState(state.NextAction()); | 1096 state.UpdateState(state.NextAction()); |
| 1101 state.DidCreateAndInitializeOutputSurface(); | 1097 state.DidCreateAndInitializeOutputSurface(); |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 1114 state.UpdateState(state.NextAction()); | 1110 state.UpdateState(state.NextAction()); |
| 1115 | 1111 |
| 1116 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); | 1112 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); |
| 1117 } | 1113 } |
| 1118 | 1114 |
| 1119 TEST(SchedulerStateMachineTest, TestFinishCommitWhenForcedCommitInProgress) { | 1115 TEST(SchedulerStateMachineTest, TestFinishCommitWhenForcedCommitInProgress) { |
| 1120 SchedulerSettings default_scheduler_settings; | 1116 SchedulerSettings default_scheduler_settings; |
| 1121 StateMachine state(default_scheduler_settings); | 1117 StateMachine state(default_scheduler_settings); |
| 1122 state.SetCanStart(); | 1118 state.SetCanStart(); |
| 1123 state.UpdateState(state.NextAction()); | 1119 state.UpdateState(state.NextAction()); |
| 1124 state.DidCreateAndInitializeOutputSurface(); | 1120 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); |
| 1125 state.SetVisible(false); | 1121 state.SetVisible(false); |
| 1126 state.SetCommitState(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS); | 1122 state.SetCommitState(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS); |
| 1127 state.SetNeedsCommit(); | 1123 state.SetNeedsCommit(); |
| 1128 state.SetNeedsForcedCommit(); | 1124 state.SetNeedsForcedCommitForReadback(); |
| 1129 | 1125 |
| 1126 // The commit for readback interupts the normal commit. | |
| 1130 state.FinishCommit(); | 1127 state.FinishCommit(); |
| 1131 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction()); | 1128 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); |
| 1132 state.UpdateState(state.NextAction()); | |
| 1133 | 1129 |
| 1134 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_FORCED_DRAW, | 1130 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW, |
| 1135 state.CommitState()); | 1131 state.CommitState()); |
| 1132 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_READBACK); | |
| 1136 | 1133 |
| 1137 // If we are waiting for forced draw then we know a begin frame is already | 1134 // When the readback interrupts the normal commit, we should not get |
| 1138 // in flight for the main thread. | 1135 // another BeginFrame on the impl thread when the readback completes. |
| 1139 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); | 1136 EXPECT_NE(SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD, |
| 1137 state.NextAction()); | |
| 1138 | |
| 1139 // The normal commit can then proceed. | |
| 1140 state.FinishCommit(); | |
| 1141 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); | |
| 1140 } | 1142 } |
| 1141 | 1143 |
| 1142 TEST(SchedulerStateMachineTest, TestInitialActionsWhenContextLost) { | 1144 TEST(SchedulerStateMachineTest, TestInitialActionsWhenContextLost) { |
| 1143 SchedulerSettings default_scheduler_settings; | 1145 SchedulerSettings default_scheduler_settings; |
| 1144 StateMachine state(default_scheduler_settings); | 1146 StateMachine state(default_scheduler_settings); |
| 1145 state.SetCanStart(); | 1147 state.SetCanStart(); |
| 1146 state.UpdateState(state.NextAction()); | 1148 state.UpdateState(state.NextAction()); |
| 1147 state.DidCreateAndInitializeOutputSurface(); | 1149 state.DidCreateAndInitializeOutputSurface(); |
| 1148 state.SetVisible(true); | 1150 state.SetVisible(true); |
| 1149 state.SetCanDraw(true); | 1151 state.SetCanDraw(true); |
| 1150 state.SetNeedsCommit(); | 1152 state.SetNeedsCommit(); |
| 1151 state.DidLoseOutputSurface(); | 1153 state.DidLoseOutputSurface(); |
| 1152 | 1154 |
| 1153 // When we are visible, we normally want to begin output surface creation | 1155 // When we are visible, we normally want to begin output surface creation |
| 1154 // as soon as possible. | 1156 // as soon as possible. |
| 1155 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION, | 1157 EXPECT_ACTION_UPDATE_STATE( |
| 1156 state.NextAction()) << *state.AsValue(); | 1158 SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION); |
| 1157 | 1159 |
| 1160 state.DidCreateAndInitializeOutputSurface(); | |
| 1161 EXPECT_EQ(state.output_surface_state(), | |
| 1162 SchedulerStateMachine::OUTPUT_SURFACE_WAITING_FOR_FIRST_COMMIT); | |
| 1158 | 1163 |
| 1159 // We should not send a BeginFrame to them main thread when we are invisible | 1164 // We should not send a BeginFrame to them main thread when we are invisible, |
| 1160 // even if we've lost the output surface since the main thread will | 1165 // even if we've lost the output surface and are trying to get the first |
| 1161 // just abort anyway. | 1166 // commit, since the main thread will just abort anyway. |
| 1162 state.SetVisible(false); | 1167 state.SetVisible(false); |
| 1163 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, | 1168 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, |
| 1164 state.NextAction()) << *state.AsValue(); | 1169 state.NextAction()) << *state.AsValue(); |
| 1165 | 1170 |
| 1166 // If there is a forced commit, however, we could be blocking a readback | 1171 // If there is a forced commit, however, we could be blocking a readback |
| 1167 // on the main thread, so we need to unblock it before we can get our | 1172 // on the main thread, so we need to unblock it before we can get our |
| 1168 // output surface, even if we are not visible. | 1173 // output surface, even if we are not visible. |
| 1169 state.SetNeedsForcedCommit(); | 1174 state.SetNeedsForcedCommitForReadback(); |
| 1170 EXPECT_EQ(SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD, | 1175 EXPECT_EQ(SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD, |
| 1171 state.NextAction()) << *state.AsValue(); | 1176 state.NextAction()) |
| 1177 << *state.AsValue(); | |
| 1172 } | 1178 } |
| 1173 | 1179 |
| 1174 TEST(SchedulerStateMachineTest, TestImmediateFinishCommit) { | 1180 TEST(SchedulerStateMachineTest, TestImmediateFinishCommit) { |
| 1175 SchedulerSettings default_scheduler_settings; | 1181 SchedulerSettings default_scheduler_settings; |
| 1176 StateMachine state(default_scheduler_settings); | 1182 StateMachine state(default_scheduler_settings); |
| 1177 state.SetCanStart(); | 1183 state.SetCanStart(); |
| 1178 state.UpdateState(state.NextAction()); | 1184 state.UpdateState(state.NextAction()); |
| 1179 state.DidCreateAndInitializeOutputSurface(); | 1185 state.DidCreateAndInitializeOutputSurface(); |
| 1180 state.SetVisible(true); | 1186 state.SetVisible(true); |
| 1181 state.SetCanDraw(true); | 1187 state.SetCanDraw(true); |
| 1182 | 1188 |
| 1183 // Schedule a forced frame, commit it, draw it. | 1189 // Schedule a readback, commit it, draw it. |
| 1184 state.SetNeedsCommit(); | 1190 state.SetNeedsCommit(); |
| 1185 state.SetNeedsForcedCommit(); | 1191 state.SetNeedsForcedCommitForReadback(); |
| 1186 state.UpdateState(state.NextAction()); | 1192 EXPECT_ACTION_UPDATE_STATE( |
| 1193 SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD); | |
| 1187 state.FinishCommit(); | 1194 state.FinishCommit(); |
| 1188 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction()); | 1195 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction()); |
| 1189 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT, | 1196 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT, |
| 1190 state.CommitState()); | 1197 state.CommitState()); |
| 1191 state.UpdateState(state.NextAction()); | 1198 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); |
| 1192 | 1199 |
| 1193 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_FORCED_DRAW, | 1200 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW, |
| 1194 state.CommitState()); | 1201 state.CommitState()); |
| 1195 | 1202 |
| 1196 state.DidEnterBeginFrame(BeginFrameArgs::CreateForTesting()); | 1203 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_READBACK); |
| 1197 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); | |
| 1198 state.SetNeedsForcedRedraw(true); | |
| 1199 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_FORCED, state.NextAction()); | |
| 1200 state.UpdateState(state.NextAction()); | |
| 1201 state.DidDrawIfPossibleCompleted(true); | 1204 state.DidDrawIfPossibleCompleted(true); |
| 1202 state.DidLeaveBeginFrame(); | 1205 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 1203 | 1206 |
| 1204 // Should be waiting for the normal begin frame from the main thread. | 1207 // Should be waiting for the normal begin frame from the main thread. |
| 1205 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, | 1208 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, |
| 1206 state.CommitState()); | 1209 state.CommitState()); |
| 1207 } | 1210 } |
| 1208 | 1211 |
| 1209 TEST(SchedulerStateMachineTest, TestImmediateFinishCommitDuringCommit) { | 1212 TEST(SchedulerStateMachineTest, TestImmediateFinishCommitDuringCommit) { |
| 1210 SchedulerSettings default_scheduler_settings; | 1213 SchedulerSettings default_scheduler_settings; |
| 1211 StateMachine state(default_scheduler_settings); | 1214 StateMachine state(default_scheduler_settings); |
| 1212 state.SetCanStart(); | 1215 state.SetCanStart(); |
| 1213 state.UpdateState(state.NextAction()); | 1216 state.UpdateState(state.NextAction()); |
| 1214 state.DidCreateAndInitializeOutputSurface(); | 1217 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); |
| 1215 state.SetVisible(true); | 1218 state.SetVisible(true); |
| 1216 state.SetCanDraw(true); | 1219 state.SetCanDraw(true); |
| 1217 | 1220 |
| 1218 // Start a normal commit. | 1221 // Start a normal commit. |
| 1219 state.SetNeedsCommit(); | 1222 state.SetNeedsCommit(); |
| 1220 state.UpdateState(state.NextAction()); | 1223 EXPECT_ACTION_UPDATE_STATE( |
| 1224 SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD); | |
| 1221 | 1225 |
| 1222 // Schedule a forced frame, commit it, draw it. | 1226 // Schedule a readback, commit it, draw it. |
| 1223 state.SetNeedsCommit(); | 1227 state.SetNeedsCommit(); |
| 1224 state.SetNeedsForcedCommit(); | 1228 state.SetNeedsForcedCommitForReadback(); |
| 1225 state.UpdateState(state.NextAction()); | 1229 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 1226 state.FinishCommit(); | 1230 state.FinishCommit(); |
| 1227 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction()); | |
| 1228 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT, | 1231 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT, |
| 1229 state.CommitState()); | 1232 state.CommitState()); |
| 1230 state.UpdateState(state.NextAction()); | 1233 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); |
| 1231 | 1234 |
| 1232 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_FORCED_DRAW, | 1235 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW, |
| 1233 state.CommitState()); | 1236 state.CommitState()); |
| 1234 | 1237 |
| 1235 state.DidEnterBeginFrame(BeginFrameArgs::CreateForTesting()); | 1238 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_READBACK); |
| 1236 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); | |
| 1237 state.SetNeedsForcedRedraw(true); | |
| 1238 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_FORCED, state.NextAction()); | |
| 1239 state.UpdateState(state.NextAction()); | |
| 1240 state.DidDrawIfPossibleCompleted(true); | 1239 state.DidDrawIfPossibleCompleted(true); |
| 1241 state.DidLeaveBeginFrame(); | 1240 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 1242 | 1241 |
| 1243 // Should be waiting for the normal begin frame from the main thread. | 1242 // Should be waiting for the normal begin frame from the main thread. |
| 1244 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, | 1243 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, |
| 1245 state.CommitState()) | 1244 state.CommitState()) |
| 1246 << *state.AsValue(); | 1245 << *state.AsValue(); |
| 1247 } | 1246 } |
| 1248 | 1247 |
| 1249 TEST(SchedulerStateMachineTest, | 1248 TEST(SchedulerStateMachineTest, |
| 1250 ImmediateBeginFrameAbortedByMainThreadWhileInvisible) { | 1249 ImmediateBeginFrameAbortedByMainThreadWhileInvisible) { |
| 1251 SchedulerSettings default_scheduler_settings; | 1250 SchedulerSettings default_scheduler_settings; |
| 1252 StateMachine state(default_scheduler_settings); | 1251 StateMachine state(default_scheduler_settings); |
| 1253 state.SetCanStart(); | 1252 state.SetCanStart(); |
| 1254 state.UpdateState(state.NextAction()); | 1253 state.UpdateState(state.NextAction()); |
| 1255 state.DidCreateAndInitializeOutputSurface(); | 1254 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); |
| 1256 state.SetVisible(true); | 1255 state.SetVisible(true); |
| 1257 state.SetCanDraw(true); | 1256 state.SetCanDraw(true); |
| 1258 | 1257 |
| 1259 state.SetNeedsCommit(); | 1258 state.SetNeedsCommit(); |
| 1260 state.UpdateState(state.NextAction()); | 1259 EXPECT_ACTION_UPDATE_STATE( |
| 1260 SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD); | |
| 1261 | 1261 |
| 1262 state.SetNeedsCommit(); | 1262 state.SetNeedsCommit(); |
| 1263 state.SetNeedsForcedCommit(); | 1263 state.SetNeedsForcedCommitForReadback(); |
| 1264 state.UpdateState(state.NextAction()); | 1264 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 1265 state.FinishCommit(); | 1265 state.FinishCommit(); |
| 1266 | 1266 |
| 1267 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction()); | |
| 1268 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT, | 1267 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT, |
| 1269 state.CommitState()); | 1268 state.CommitState()); |
| 1270 state.UpdateState(state.NextAction()); | 1269 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); |
| 1271 | 1270 |
| 1272 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_FORCED_DRAW, | 1271 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW, |
| 1273 state.CommitState()); | 1272 state.CommitState()); |
| 1274 | 1273 |
| 1275 state.DidEnterBeginFrame(BeginFrameArgs::CreateForTesting()); | 1274 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_READBACK); |
| 1276 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); | |
| 1277 state.SetNeedsForcedRedraw(true); | |
| 1278 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_FORCED, state.NextAction()); | |
| 1279 state.UpdateState(state.NextAction()); | |
| 1280 state.DidDrawIfPossibleCompleted(true); | 1275 state.DidDrawIfPossibleCompleted(true); |
| 1281 state.DidLeaveBeginFrame(); | 1276 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 1282 | 1277 |
| 1283 // Should be waiting for the main thread's begin frame. | 1278 // Should be waiting for the main thread's begin frame. |
| 1284 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, | 1279 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, |
| 1285 state.CommitState()) | 1280 state.CommitState()) |
| 1286 << *state.AsValue(); | 1281 << *state.AsValue(); |
| 1287 | 1282 |
| 1288 // Become invisible and abort the main thread's begin frame. | 1283 // Become invisible and abort the main thread's begin frame. |
| 1289 state.SetVisible(false); | 1284 state.SetVisible(false); |
| 1290 state.BeginFrameAbortedByMainThread(false); | 1285 state.BeginFrameAbortedByMainThread(false); |
| 1291 | 1286 |
| 1292 // Should be back in the idle state, but needing a commit. | 1287 // Should be back in the idle state, but needing a commit. |
| 1293 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState()); | 1288 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState()); |
| 1294 EXPECT_TRUE(state.NeedsCommit()); | 1289 EXPECT_TRUE(state.NeedsCommit()); |
| 1295 } | 1290 } |
| 1296 | 1291 |
| 1297 TEST(SchedulerStateMachineTest, ImmediateFinishCommitWhileCantDraw) { | 1292 TEST(SchedulerStateMachineTest, ImmediateFinishCommitWhileCantDraw) { |
| 1298 SchedulerSettings default_scheduler_settings; | 1293 SchedulerSettings default_scheduler_settings; |
| 1299 StateMachine state(default_scheduler_settings); | 1294 StateMachine state(default_scheduler_settings); |
| 1300 state.SetCanStart(); | 1295 state.SetCanStart(); |
| 1301 state.UpdateState(state.NextAction()); | 1296 state.UpdateState(state.NextAction()); |
| 1302 state.DidCreateAndInitializeOutputSurface(); | 1297 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); |
| 1303 state.SetVisible(true); | 1298 state.SetVisible(true); |
| 1304 state.SetCanDraw(false); | 1299 state.SetCanDraw(false); |
| 1305 | 1300 |
| 1306 state.SetNeedsCommit(); | 1301 state.SetNeedsCommit(); |
| 1307 state.UpdateState(state.NextAction()); | 1302 state.UpdateState(state.NextAction()); |
| 1308 | 1303 |
| 1309 state.SetNeedsCommit(); | 1304 state.SetNeedsCommit(); |
| 1310 state.SetNeedsForcedCommit(); | 1305 state.SetNeedsForcedCommitForReadback(); |
| 1311 state.UpdateState(state.NextAction()); | 1306 state.UpdateState(state.NextAction()); |
| 1312 state.FinishCommit(); | 1307 state.FinishCommit(); |
| 1313 | 1308 |
| 1314 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction()); | |
| 1315 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT, | 1309 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT, |
| 1316 state.CommitState()); | 1310 state.CommitState()); |
| 1317 state.UpdateState(state.NextAction()); | 1311 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); |
| 1318 | 1312 |
| 1319 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_FORCED_DRAW, | 1313 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW, |
| 1320 state.CommitState()); | 1314 state.CommitState()); |
| 1321 | 1315 |
| 1322 state.DidEnterBeginFrame(BeginFrameArgs::CreateForTesting()); | 1316 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_READBACK); |
| 1323 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); | |
| 1324 state.SetNeedsForcedRedraw(true); | |
| 1325 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_FORCED, state.NextAction()); | |
| 1326 state.UpdateState(state.NextAction()); | |
| 1327 state.DidDrawIfPossibleCompleted(true); | 1317 state.DidDrawIfPossibleCompleted(true); |
| 1328 state.DidLeaveBeginFrame(); | 1318 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 1329 } | 1319 } |
| 1330 | 1320 |
| 1331 TEST(SchedulerStateMachineTest, ReportIfNotDrawing) { | 1321 TEST(SchedulerStateMachineTest, ReportIfNotDrawing) { |
| 1332 SchedulerSettings default_scheduler_settings; | 1322 SchedulerSettings default_scheduler_settings; |
| 1333 StateMachine state(default_scheduler_settings); | 1323 StateMachine state(default_scheduler_settings); |
| 1334 state.SetCanStart(); | 1324 state.SetCanStart(); |
| 1335 state.UpdateState(state.NextAction()); | 1325 state.UpdateState(state.NextAction()); |
| 1336 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); | 1326 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); |
| 1337 | 1327 |
| 1338 state.SetCanDraw(true); | 1328 state.SetCanDraw(true); |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1420 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); | 1410 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); |
| 1421 | 1411 |
| 1422 state.BeginFrameAbortedByMainThread(true); | 1412 state.BeginFrameAbortedByMainThread(true); |
| 1423 | 1413 |
| 1424 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); | 1414 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); |
| 1425 EXPECT_FALSE(state.PendingDrawsShouldBeAborted()); | 1415 EXPECT_FALSE(state.PendingDrawsShouldBeAborted()); |
| 1426 } | 1416 } |
| 1427 | 1417 |
| 1428 } // namespace | 1418 } // namespace |
| 1429 } // namespace cc | 1419 } // namespace cc |
| OLD | NEW |