| 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) \ |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 { | 115 { |
| 116 StateMachine state(default_scheduler_settings); | 116 StateMachine state(default_scheduler_settings); |
| 117 state.SetCanStart(); | 117 state.SetCanStart(); |
| 118 EXPECT_ACTION_UPDATE_STATE( | 118 EXPECT_ACTION_UPDATE_STATE( |
| 119 SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION) | 119 SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION) |
| 120 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); | 120 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); |
| 121 state.SetCommitState(SchedulerStateMachine::COMMIT_STATE_IDLE); | 121 state.SetCommitState(SchedulerStateMachine::COMMIT_STATE_IDLE); |
| 122 state.SetNeedsRedraw(false); | 122 state.SetNeedsRedraw(false); |
| 123 state.SetVisible(true); | 123 state.SetVisible(true); |
| 124 | 124 |
| 125 EXPECT_FALSE(state.BeginImplFrameNeeded()); | 125 EXPECT_FALSE(state.BeginFrameNeeded()); |
| 126 | 126 |
| 127 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | 127 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 128 EXPECT_FALSE(state.BeginImplFrameNeeded()); | 128 EXPECT_FALSE(state.BeginFrameNeeded()); |
| 129 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); | 129 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); |
| 130 | 130 |
| 131 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | 131 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 132 state.OnBeginImplFrameDeadline(); | 132 state.OnBeginImplFrameDeadline(); |
| 133 } | 133 } |
| 134 | 134 |
| 135 // If commit requested but can_start is still false, do nothing. | 135 // If commit requested but can_start is still false, do nothing. |
| 136 { | 136 { |
| 137 StateMachine state(default_scheduler_settings); | 137 StateMachine state(default_scheduler_settings); |
| 138 state.SetCommitState(SchedulerStateMachine::COMMIT_STATE_IDLE); | 138 state.SetCommitState(SchedulerStateMachine::COMMIT_STATE_IDLE); |
| 139 state.SetNeedsRedraw(false); | 139 state.SetNeedsRedraw(false); |
| 140 state.SetVisible(true); | 140 state.SetVisible(true); |
| 141 state.SetNeedsCommit(); | 141 state.SetNeedsCommit(); |
| 142 | 142 |
| 143 EXPECT_FALSE(state.BeginImplFrameNeeded()); | 143 EXPECT_FALSE(state.BeginFrameNeeded()); |
| 144 | 144 |
| 145 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | 145 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 146 EXPECT_FALSE(state.BeginImplFrameNeeded()); | 146 EXPECT_FALSE(state.BeginFrameNeeded()); |
| 147 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); | 147 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); |
| 148 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | 148 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 149 state.OnBeginImplFrameDeadline(); | 149 state.OnBeginImplFrameDeadline(); |
| 150 } | 150 } |
| 151 | 151 |
| 152 // If commit requested, begin a main frame. | 152 // If commit requested, begin a main frame. |
| 153 { | 153 { |
| 154 StateMachine state(default_scheduler_settings); | 154 StateMachine state(default_scheduler_settings); |
| 155 state.SetCommitState(SchedulerStateMachine::COMMIT_STATE_IDLE); | 155 state.SetCommitState(SchedulerStateMachine::COMMIT_STATE_IDLE); |
| 156 state.SetCanStart(); | 156 state.SetCanStart(); |
| 157 state.UpdateState(state.NextAction()); | 157 state.UpdateState(state.NextAction()); |
| 158 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); | 158 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); |
| 159 state.SetNeedsRedraw(false); | 159 state.SetNeedsRedraw(false); |
| 160 state.SetVisible(true); | 160 state.SetVisible(true); |
| 161 state.SetNeedsCommit(); | 161 state.SetNeedsCommit(); |
| 162 | 162 |
| 163 EXPECT_TRUE(state.BeginImplFrameNeeded()); | 163 EXPECT_TRUE(state.BeginFrameNeeded()); |
| 164 | 164 |
| 165 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); | 165 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); |
| 166 EXPECT_ACTION_UPDATE_STATE( | 166 EXPECT_ACTION_UPDATE_STATE( |
| 167 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); | 167 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); |
| 168 } | 168 } |
| 169 | 169 |
| 170 // Begin the frame, make sure needs_commit and commit_state update correctly. | 170 // Begin the frame, make sure needs_commit and commit_state update correctly. |
| 171 { | 171 { |
| 172 StateMachine state(default_scheduler_settings); | 172 StateMachine state(default_scheduler_settings); |
| 173 state.SetCanStart(); | 173 state.SetCanStart(); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 189 StateMachine state(scheduler_settings); | 189 StateMachine state(scheduler_settings); |
| 190 state.SetCommitState(SchedulerStateMachine::COMMIT_STATE_IDLE); | 190 state.SetCommitState(SchedulerStateMachine::COMMIT_STATE_IDLE); |
| 191 state.SetCanStart(); | 191 state.SetCanStart(); |
| 192 state.UpdateState(state.NextAction()); | 192 state.UpdateState(state.NextAction()); |
| 193 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); | 193 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); |
| 194 state.SetNeedsRedraw(false); | 194 state.SetNeedsRedraw(false); |
| 195 state.SetVisible(true); | 195 state.SetVisible(true); |
| 196 state.SetCanDraw(true); | 196 state.SetCanDraw(true); |
| 197 state.SetNeedsCommit(); | 197 state.SetNeedsCommit(); |
| 198 | 198 |
| 199 EXPECT_TRUE(state.BeginImplFrameNeeded()); | 199 EXPECT_TRUE(state.BeginFrameNeeded()); |
| 200 | 200 |
| 201 // Commit to the pending tree. | 201 // Commit to the pending tree. |
| 202 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); | 202 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); |
| 203 EXPECT_ACTION_UPDATE_STATE( | 203 EXPECT_ACTION_UPDATE_STATE( |
| 204 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); | 204 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); |
| 205 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | 205 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 206 state.NotifyBeginMainFrameStarted(); | 206 state.NotifyBeginMainFrameStarted(); |
| 207 state.NotifyReadyToCommit(); | 207 state.NotifyReadyToCommit(); |
| 208 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); | 208 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); |
| 209 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | 209 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 257 StateMachine state(scheduler_settings); | 257 StateMachine state(scheduler_settings); |
| 258 state.SetCommitState(SchedulerStateMachine::COMMIT_STATE_IDLE); | 258 state.SetCommitState(SchedulerStateMachine::COMMIT_STATE_IDLE); |
| 259 state.SetCanStart(); | 259 state.SetCanStart(); |
| 260 state.UpdateState(state.NextAction()); | 260 state.UpdateState(state.NextAction()); |
| 261 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); | 261 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); |
| 262 state.SetNeedsRedraw(false); | 262 state.SetNeedsRedraw(false); |
| 263 state.SetVisible(true); | 263 state.SetVisible(true); |
| 264 state.SetCanDraw(true); | 264 state.SetCanDraw(true); |
| 265 state.SetNeedsCommit(); | 265 state.SetNeedsCommit(); |
| 266 | 266 |
| 267 EXPECT_TRUE(state.BeginImplFrameNeeded()); | 267 EXPECT_TRUE(state.BeginFrameNeeded()); |
| 268 | 268 |
| 269 // Commit to the pending tree. | 269 // Commit to the pending tree. |
| 270 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); | 270 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); |
| 271 EXPECT_ACTION_UPDATE_STATE( | 271 EXPECT_ACTION_UPDATE_STATE( |
| 272 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); | 272 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); |
| 273 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | 273 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 274 | 274 |
| 275 state.NotifyBeginMainFrameStarted(); | 275 state.NotifyBeginMainFrameStarted(); |
| 276 state.NotifyReadyToCommit(); | 276 state.NotifyReadyToCommit(); |
| 277 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); | 277 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 314 TestFailedDrawForAnimationCheckerboardSetsNeedsCommitAndDoesNotDrawAgain) { | 314 TestFailedDrawForAnimationCheckerboardSetsNeedsCommitAndDoesNotDrawAgain) { |
| 315 SchedulerSettings default_scheduler_settings; | 315 SchedulerSettings default_scheduler_settings; |
| 316 StateMachine state(default_scheduler_settings); | 316 StateMachine state(default_scheduler_settings); |
| 317 state.SetCanStart(); | 317 state.SetCanStart(); |
| 318 state.UpdateState(state.NextAction()); | 318 state.UpdateState(state.NextAction()); |
| 319 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); | 319 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); |
| 320 state.SetVisible(true); | 320 state.SetVisible(true); |
| 321 state.SetCanDraw(true); | 321 state.SetCanDraw(true); |
| 322 state.SetNeedsRedraw(true); | 322 state.SetNeedsRedraw(true); |
| 323 EXPECT_TRUE(state.RedrawPending()); | 323 EXPECT_TRUE(state.RedrawPending()); |
| 324 EXPECT_TRUE(state.BeginImplFrameNeeded()); | 324 EXPECT_TRUE(state.BeginFrameNeeded()); |
| 325 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); | 325 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); |
| 326 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | 326 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 327 state.OnBeginImplFrameDeadline(); | 327 state.OnBeginImplFrameDeadline(); |
| 328 | 328 |
| 329 // We're drawing now. | 329 // We're drawing now. |
| 330 EXPECT_ACTION_UPDATE_STATE( | 330 EXPECT_ACTION_UPDATE_STATE( |
| 331 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); | 331 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); |
| 332 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | 332 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 333 | 333 |
| 334 EXPECT_FALSE(state.RedrawPending()); | 334 EXPECT_FALSE(state.RedrawPending()); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 347 TEST(SchedulerStateMachineTest, TestFailedDrawForMissingHighResNeedsCommit) { | 347 TEST(SchedulerStateMachineTest, TestFailedDrawForMissingHighResNeedsCommit) { |
| 348 SchedulerSettings default_scheduler_settings; | 348 SchedulerSettings default_scheduler_settings; |
| 349 StateMachine state(default_scheduler_settings); | 349 StateMachine state(default_scheduler_settings); |
| 350 state.SetCanStart(); | 350 state.SetCanStart(); |
| 351 state.UpdateState(state.NextAction()); | 351 state.UpdateState(state.NextAction()); |
| 352 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); | 352 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); |
| 353 state.SetVisible(true); | 353 state.SetVisible(true); |
| 354 state.SetCanDraw(true); | 354 state.SetCanDraw(true); |
| 355 state.SetNeedsRedraw(true); | 355 state.SetNeedsRedraw(true); |
| 356 EXPECT_TRUE(state.RedrawPending()); | 356 EXPECT_TRUE(state.RedrawPending()); |
| 357 EXPECT_TRUE(state.BeginImplFrameNeeded()); | 357 EXPECT_TRUE(state.BeginFrameNeeded()); |
| 358 | 358 |
| 359 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); | 359 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); |
| 360 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | 360 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 361 state.OnBeginImplFrameDeadline(); | 361 state.OnBeginImplFrameDeadline(); |
| 362 EXPECT_ACTION_UPDATE_STATE( | 362 EXPECT_ACTION_UPDATE_STATE( |
| 363 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); | 363 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); |
| 364 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | 364 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 365 EXPECT_FALSE(state.RedrawPending()); | 365 EXPECT_FALSE(state.RedrawPending()); |
| 366 EXPECT_FALSE(state.CommitPending()); | 366 EXPECT_FALSE(state.CommitPending()); |
| 367 | 367 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 380 SchedulerSettings default_scheduler_settings; | 380 SchedulerSettings default_scheduler_settings; |
| 381 StateMachine state(default_scheduler_settings); | 381 StateMachine state(default_scheduler_settings); |
| 382 state.SetCanStart(); | 382 state.SetCanStart(); |
| 383 state.UpdateState(state.NextAction()); | 383 state.UpdateState(state.NextAction()); |
| 384 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); | 384 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); |
| 385 | 385 |
| 386 state.SetVisible(true); | 386 state.SetVisible(true); |
| 387 state.SetCanDraw(true); | 387 state.SetCanDraw(true); |
| 388 state.SetNeedsRedraw(true); | 388 state.SetNeedsRedraw(true); |
| 389 EXPECT_TRUE(state.RedrawPending()); | 389 EXPECT_TRUE(state.RedrawPending()); |
| 390 EXPECT_TRUE(state.BeginImplFrameNeeded()); | 390 EXPECT_TRUE(state.BeginFrameNeeded()); |
| 391 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); | 391 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); |
| 392 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | 392 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 393 state.OnBeginImplFrameDeadline(); | 393 state.OnBeginImplFrameDeadline(); |
| 394 | 394 |
| 395 // We're drawing now. | 395 // We're drawing now. |
| 396 EXPECT_ACTION_UPDATE_STATE( | 396 EXPECT_ACTION_UPDATE_STATE( |
| 397 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); | 397 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); |
| 398 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | 398 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 399 EXPECT_FALSE(state.RedrawPending()); | 399 EXPECT_FALSE(state.RedrawPending()); |
| 400 EXPECT_FALSE(state.CommitPending()); | 400 EXPECT_FALSE(state.CommitPending()); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 438 // Then initiate a draw. | 438 // Then initiate a draw. |
| 439 state.SetNeedsRedraw(true); | 439 state.SetNeedsRedraw(true); |
| 440 state.OnBeginImplFrameDeadline(); | 440 state.OnBeginImplFrameDeadline(); |
| 441 EXPECT_ACTION_UPDATE_STATE( | 441 EXPECT_ACTION_UPDATE_STATE( |
| 442 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); | 442 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); |
| 443 | 443 |
| 444 // Fail the draw. | 444 // Fail the draw. |
| 445 state.DidDrawIfPossibleCompleted( | 445 state.DidDrawIfPossibleCompleted( |
| 446 DrawSwapReadbackResult::DRAW_ABORTED_CHECKERBOARD_ANIMATIONS); | 446 DrawSwapReadbackResult::DRAW_ABORTED_CHECKERBOARD_ANIMATIONS); |
| 447 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | 447 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 448 EXPECT_TRUE(state.BeginImplFrameNeeded()); | 448 EXPECT_TRUE(state.BeginFrameNeeded()); |
| 449 EXPECT_TRUE(state.RedrawPending()); | 449 EXPECT_TRUE(state.RedrawPending()); |
| 450 // But the commit is ongoing. | 450 // But the commit is ongoing. |
| 451 EXPECT_TRUE(state.CommitPending()); | 451 EXPECT_TRUE(state.CommitPending()); |
| 452 | 452 |
| 453 // Finish the commit. Note, we should not yet be forcing a draw, but should | 453 // Finish the commit. Note, we should not yet be forcing a draw, but should |
| 454 // continue the commit as usual. | 454 // continue the commit as usual. |
| 455 state.NotifyBeginMainFrameStarted(); | 455 state.NotifyBeginMainFrameStarted(); |
| 456 state.NotifyReadyToCommit(); | 456 state.NotifyReadyToCommit(); |
| 457 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); | 457 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); |
| 458 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | 458 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 512 EXPECT_ACTION_UPDATE_STATE( | 512 EXPECT_ACTION_UPDATE_STATE( |
| 513 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); | 513 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); |
| 514 | 514 |
| 515 // Fail the draw enough times to force a redraw, | 515 // Fail the draw enough times to force a redraw, |
| 516 // then once more for good measure. | 516 // then once more for good measure. |
| 517 for (int i = 0; i < draw_limit + 1; ++i) { | 517 for (int i = 0; i < draw_limit + 1; ++i) { |
| 518 state.DidDrawIfPossibleCompleted( | 518 state.DidDrawIfPossibleCompleted( |
| 519 DrawSwapReadbackResult::DRAW_ABORTED_CHECKERBOARD_ANIMATIONS); | 519 DrawSwapReadbackResult::DRAW_ABORTED_CHECKERBOARD_ANIMATIONS); |
| 520 } | 520 } |
| 521 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | 521 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 522 EXPECT_TRUE(state.BeginImplFrameNeeded()); | 522 EXPECT_TRUE(state.BeginFrameNeeded()); |
| 523 EXPECT_TRUE(state.RedrawPending()); | 523 EXPECT_TRUE(state.RedrawPending()); |
| 524 // But the commit is ongoing. | 524 // But the commit is ongoing. |
| 525 EXPECT_TRUE(state.CommitPending()); | 525 EXPECT_TRUE(state.CommitPending()); |
| 526 EXPECT_TRUE(state.ForcedRedrawState() == | 526 EXPECT_TRUE(state.ForcedRedrawState() == |
| 527 SchedulerStateMachine::FORCED_REDRAW_STATE_WAITING_FOR_COMMIT); | 527 SchedulerStateMachine::FORCED_REDRAW_STATE_WAITING_FOR_COMMIT); |
| 528 | 528 |
| 529 state.NotifyBeginMainFrameStarted(); | 529 state.NotifyBeginMainFrameStarted(); |
| 530 state.NotifyReadyToCommit(); | 530 state.NotifyReadyToCommit(); |
| 531 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); | 531 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); |
| 532 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | 532 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 552 SchedulerSettings default_scheduler_settings; | 552 SchedulerSettings default_scheduler_settings; |
| 553 StateMachine state(default_scheduler_settings); | 553 StateMachine state(default_scheduler_settings); |
| 554 state.SetCanStart(); | 554 state.SetCanStart(); |
| 555 state.UpdateState(state.NextAction()); | 555 state.UpdateState(state.NextAction()); |
| 556 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); | 556 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); |
| 557 state.SetVisible(true); | 557 state.SetVisible(true); |
| 558 state.SetCanDraw(true); | 558 state.SetCanDraw(true); |
| 559 | 559 |
| 560 // Start a draw. | 560 // Start a draw. |
| 561 state.SetNeedsRedraw(true); | 561 state.SetNeedsRedraw(true); |
| 562 EXPECT_TRUE(state.BeginImplFrameNeeded()); | 562 EXPECT_TRUE(state.BeginFrameNeeded()); |
| 563 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); | 563 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); |
| 564 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | 564 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 565 state.OnBeginImplFrameDeadline(); | 565 state.OnBeginImplFrameDeadline(); |
| 566 EXPECT_TRUE(state.RedrawPending()); | 566 EXPECT_TRUE(state.RedrawPending()); |
| 567 EXPECT_ACTION_UPDATE_STATE( | 567 EXPECT_ACTION_UPDATE_STATE( |
| 568 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); | 568 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); |
| 569 | 569 |
| 570 // Failing the draw for animation checkerboards makes us require a commit. | 570 // Failing the draw for animation checkerboards makes us require a commit. |
| 571 state.DidDrawIfPossibleCompleted( | 571 state.DidDrawIfPossibleCompleted( |
| 572 DrawSwapReadbackResult::DRAW_ABORTED_CHECKERBOARD_ANIMATIONS); | 572 DrawSwapReadbackResult::DRAW_ABORTED_CHECKERBOARD_ANIMATIONS); |
| 573 EXPECT_ACTION_UPDATE_STATE( | 573 EXPECT_ACTION_UPDATE_STATE( |
| 574 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); | 574 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); |
| 575 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | 575 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 576 EXPECT_TRUE(state.RedrawPending()); | 576 EXPECT_TRUE(state.RedrawPending()); |
| 577 | 577 |
| 578 // We should not be trying to draw again now, but we have a commit pending. | 578 // We should not be trying to draw again now, but we have a commit pending. |
| 579 EXPECT_TRUE(state.BeginImplFrameNeeded()); | 579 EXPECT_TRUE(state.BeginFrameNeeded()); |
| 580 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); | 580 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); |
| 581 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | 581 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 582 | 582 |
| 583 // We should try to draw again at the end of the next BeginImplFrame on | 583 // We should try to draw again at the end of the next BeginImplFrame on |
| 584 // the impl thread. | 584 // the impl thread. |
| 585 state.OnBeginImplFrameDeadline(); | 585 state.OnBeginImplFrameDeadline(); |
| 586 EXPECT_ACTION_UPDATE_STATE( | 586 EXPECT_ACTION_UPDATE_STATE( |
| 587 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); | 587 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); |
| 588 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | 588 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 589 } | 589 } |
| 590 | 590 |
| 591 TEST(SchedulerStateMachineTest, TestDoestDrawTwiceInSameFrame) { | 591 TEST(SchedulerStateMachineTest, TestDoestDrawTwiceInSameFrame) { |
| 592 SchedulerSettings default_scheduler_settings; | 592 SchedulerSettings default_scheduler_settings; |
| 593 StateMachine state(default_scheduler_settings); | 593 StateMachine state(default_scheduler_settings); |
| 594 state.SetCanStart(); | 594 state.SetCanStart(); |
| 595 state.UpdateState(state.NextAction()); | 595 state.UpdateState(state.NextAction()); |
| 596 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); | 596 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); |
| 597 state.SetVisible(true); | 597 state.SetVisible(true); |
| 598 state.SetCanDraw(true); | 598 state.SetCanDraw(true); |
| 599 state.SetNeedsRedraw(true); | 599 state.SetNeedsRedraw(true); |
| 600 | 600 |
| 601 // Draw the first frame. | 601 // Draw the first frame. |
| 602 EXPECT_TRUE(state.BeginImplFrameNeeded()); | 602 EXPECT_TRUE(state.BeginFrameNeeded()); |
| 603 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); | 603 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); |
| 604 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | 604 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 605 | 605 |
| 606 state.OnBeginImplFrameDeadline(); | 606 state.OnBeginImplFrameDeadline(); |
| 607 EXPECT_ACTION_UPDATE_STATE( | 607 EXPECT_ACTION_UPDATE_STATE( |
| 608 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); | 608 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); |
| 609 state.DidDrawIfPossibleCompleted(DrawSwapReadbackResult::DRAW_SUCCESS); | 609 state.DidDrawIfPossibleCompleted(DrawSwapReadbackResult::DRAW_SUCCESS); |
| 610 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | 610 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 611 | 611 |
| 612 // Before the next BeginImplFrame, set needs redraw again. | 612 // Before the next BeginImplFrame, set needs redraw again. |
| 613 // This should not redraw until the next BeginImplFrame. | 613 // This should not redraw until the next BeginImplFrame. |
| 614 state.SetNeedsRedraw(true); | 614 state.SetNeedsRedraw(true); |
| 615 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | 615 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 616 | 616 |
| 617 // Move to another frame. This should now draw. | 617 // Move to another frame. This should now draw. |
| 618 EXPECT_TRUE(state.BeginImplFrameNeeded()); | 618 EXPECT_TRUE(state.BeginFrameNeeded()); |
| 619 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); | 619 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); |
| 620 | 620 |
| 621 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | 621 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 622 | 622 |
| 623 state.OnBeginImplFrameDeadline(); | 623 state.OnBeginImplFrameDeadline(); |
| 624 EXPECT_ACTION_UPDATE_STATE( | 624 EXPECT_ACTION_UPDATE_STATE( |
| 625 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); | 625 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); |
| 626 state.DidDrawIfPossibleCompleted(DrawSwapReadbackResult::DRAW_SUCCESS); | 626 state.DidDrawIfPossibleCompleted(DrawSwapReadbackResult::DRAW_SUCCESS); |
| 627 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | 627 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 628 | 628 |
| 629 // We just swapped, so we should proactively request another BeginImplFrame. | 629 // We just swapped, so we should proactively request another BeginImplFrame. |
| 630 EXPECT_TRUE(state.BeginImplFrameNeeded()); | 630 EXPECT_TRUE(state.BeginFrameNeeded()); |
| 631 } | 631 } |
| 632 | 632 |
| 633 TEST(SchedulerStateMachineTest, TestNextActionDrawsOnBeginImplFrame) { | 633 TEST(SchedulerStateMachineTest, TestNextActionDrawsOnBeginImplFrame) { |
| 634 SchedulerSettings default_scheduler_settings; | 634 SchedulerSettings default_scheduler_settings; |
| 635 | 635 |
| 636 // When not in BeginImplFrame deadline, or in BeginImplFrame deadline | 636 // When not in BeginImplFrame deadline, or in BeginImplFrame deadline |
| 637 // but not visible, don't draw. | 637 // but not visible, don't draw. |
| 638 size_t num_commit_states = | 638 size_t num_commit_states = |
| 639 sizeof(all_commit_states) / sizeof(SchedulerStateMachine::CommitState); | 639 sizeof(all_commit_states) / sizeof(SchedulerStateMachine::CommitState); |
| 640 size_t num_begin_impl_frame_states = | 640 size_t num_begin_impl_frame_states = |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 693 expected_action = SchedulerStateMachine::ACTION_DRAW_AND_READBACK; | 693 expected_action = SchedulerStateMachine::ACTION_DRAW_AND_READBACK; |
| 694 } else if (all_commit_states[i] == | 694 } else if (all_commit_states[i] == |
| 695 SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT) { | 695 SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT) { |
| 696 expected_action = SchedulerStateMachine::ACTION_COMMIT; | 696 expected_action = SchedulerStateMachine::ACTION_COMMIT; |
| 697 } else { | 697 } else { |
| 698 expected_action = | 698 expected_action = |
| 699 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE; | 699 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE; |
| 700 } | 700 } |
| 701 | 701 |
| 702 // Case 1: needs_commit=false. | 702 // Case 1: needs_commit=false. |
| 703 EXPECT_NE(state.BeginImplFrameNeeded(), request_readback) | 703 EXPECT_NE(state.BeginFrameNeeded(), request_readback) << *state.AsValue(); |
| 704 << *state.AsValue(); | |
| 705 EXPECT_EQ(state.NextAction(), expected_action) << *state.AsValue(); | 704 EXPECT_EQ(state.NextAction(), expected_action) << *state.AsValue(); |
| 706 | 705 |
| 707 // Case 2: needs_commit=true. | 706 // Case 2: needs_commit=true. |
| 708 state.SetNeedsCommit(); | 707 state.SetNeedsCommit(); |
| 709 EXPECT_NE(state.BeginImplFrameNeeded(), request_readback) | 708 EXPECT_NE(state.BeginFrameNeeded(), request_readback) << *state.AsValue(); |
| 710 << *state.AsValue(); | |
| 711 EXPECT_EQ(state.NextAction(), expected_action) << *state.AsValue(); | 709 EXPECT_EQ(state.NextAction(), expected_action) << *state.AsValue(); |
| 712 } | 710 } |
| 713 } | 711 } |
| 714 } | 712 } |
| 715 | 713 |
| 716 TEST(SchedulerStateMachineTest, TestNoCommitStatesRedrawWhenInvisible) { | 714 TEST(SchedulerStateMachineTest, TestNoCommitStatesRedrawWhenInvisible) { |
| 717 SchedulerSettings default_scheduler_settings; | 715 SchedulerSettings default_scheduler_settings; |
| 718 | 716 |
| 719 size_t num_commit_states = | 717 size_t num_commit_states = |
| 720 sizeof(all_commit_states) / sizeof(SchedulerStateMachine::CommitState); | 718 sizeof(all_commit_states) / sizeof(SchedulerStateMachine::CommitState); |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 802 scheduler_settings.main_frame_before_draw_enabled = | 800 scheduler_settings.main_frame_before_draw_enabled = |
| 803 main_frame_before_draw_enabled; | 801 main_frame_before_draw_enabled; |
| 804 StateMachine state(scheduler_settings); | 802 StateMachine state(scheduler_settings); |
| 805 state.SetCanStart(); | 803 state.SetCanStart(); |
| 806 state.UpdateState(state.NextAction()); | 804 state.UpdateState(state.NextAction()); |
| 807 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); | 805 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); |
| 808 state.SetNeedsCommit(); | 806 state.SetNeedsCommit(); |
| 809 state.SetVisible(true); | 807 state.SetVisible(true); |
| 810 state.SetCanDraw(true); | 808 state.SetCanDraw(true); |
| 811 | 809 |
| 812 EXPECT_TRUE(state.BeginImplFrameNeeded()); | 810 EXPECT_TRUE(state.BeginFrameNeeded()); |
| 813 | 811 |
| 814 // Begin the frame. | 812 // Begin the frame. |
| 815 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); | 813 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); |
| 816 EXPECT_ACTION_UPDATE_STATE( | 814 EXPECT_ACTION_UPDATE_STATE( |
| 817 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); | 815 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); |
| 818 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT, | 816 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT, |
| 819 state.CommitState()); | 817 state.CommitState()); |
| 820 | 818 |
| 821 // Now, while the frame is in progress, set another commit. | 819 // Now, while the frame is in progress, set another commit. |
| 822 state.SetNeedsCommit(); | 820 state.SetNeedsCommit(); |
| (...skipping 1077 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1900 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | 1898 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 1901 | 1899 |
| 1902 // The deadline is not triggered early until we enter prefer smoothness mode. | 1900 // The deadline is not triggered early until we enter prefer smoothness mode. |
| 1903 EXPECT_FALSE(state.ShouldTriggerBeginImplFrameDeadlineEarly()); | 1901 EXPECT_FALSE(state.ShouldTriggerBeginImplFrameDeadlineEarly()); |
| 1904 state.SetSmoothnessTakesPriority(true); | 1902 state.SetSmoothnessTakesPriority(true); |
| 1905 EXPECT_TRUE(state.ShouldTriggerBeginImplFrameDeadlineEarly()); | 1903 EXPECT_TRUE(state.ShouldTriggerBeginImplFrameDeadlineEarly()); |
| 1906 } | 1904 } |
| 1907 | 1905 |
| 1908 } // namespace | 1906 } // namespace |
| 1909 } // namespace cc | 1907 } // namespace cc |
| OLD | NEW |