| 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 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 { | 120 { |
| 121 StateMachine state(default_scheduler_settings); | 121 StateMachine state(default_scheduler_settings); |
| 122 state.SetCanStart(); | 122 state.SetCanStart(); |
| 123 EXPECT_ACTION_UPDATE_STATE( | 123 EXPECT_ACTION_UPDATE_STATE( |
| 124 SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION) | 124 SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION) |
| 125 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); | 125 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); |
| 126 state.SetCommitState(SchedulerStateMachine::COMMIT_STATE_IDLE); | 126 state.SetCommitState(SchedulerStateMachine::COMMIT_STATE_IDLE); |
| 127 state.SetNeedsRedraw(false); | 127 state.SetNeedsRedraw(false); |
| 128 state.SetVisible(true); | 128 state.SetVisible(true); |
| 129 | 129 |
| 130 EXPECT_FALSE(state.BeginImplFrameNeeded()); | 130 EXPECT_FALSE(state.BeginFrameNeeded()); |
| 131 | 131 |
| 132 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | 132 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 133 EXPECT_FALSE(state.BeginImplFrameNeeded()); | 133 EXPECT_FALSE(state.BeginFrameNeeded()); |
| 134 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); | 134 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); |
| 135 | 135 |
| 136 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | 136 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 137 state.OnBeginImplFrameDeadline(); | 137 state.OnBeginImplFrameDeadline(); |
| 138 } | 138 } |
| 139 | 139 |
| 140 // If commit requested but can_start is still false, do nothing. | 140 // If commit requested but can_start is still false, do nothing. |
| 141 { | 141 { |
| 142 StateMachine state(default_scheduler_settings); | 142 StateMachine state(default_scheduler_settings); |
| 143 state.SetCommitState(SchedulerStateMachine::COMMIT_STATE_IDLE); | 143 state.SetCommitState(SchedulerStateMachine::COMMIT_STATE_IDLE); |
| 144 state.SetNeedsRedraw(false); | 144 state.SetNeedsRedraw(false); |
| 145 state.SetVisible(true); | 145 state.SetVisible(true); |
| 146 state.SetNeedsCommit(); | 146 state.SetNeedsCommit(); |
| 147 | 147 |
| 148 EXPECT_FALSE(state.BeginImplFrameNeeded()); | 148 EXPECT_FALSE(state.BeginFrameNeeded()); |
| 149 | 149 |
| 150 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | 150 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 151 EXPECT_FALSE(state.BeginImplFrameNeeded()); | 151 EXPECT_FALSE(state.BeginFrameNeeded()); |
| 152 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); | 152 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); |
| 153 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | 153 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 154 state.OnBeginImplFrameDeadline(); | 154 state.OnBeginImplFrameDeadline(); |
| 155 } | 155 } |
| 156 | 156 |
| 157 // If commit requested, begin a main frame. | 157 // If commit requested, begin a main frame. |
| 158 { | 158 { |
| 159 StateMachine state(default_scheduler_settings); | 159 StateMachine state(default_scheduler_settings); |
| 160 state.SetCommitState(SchedulerStateMachine::COMMIT_STATE_IDLE); | 160 state.SetCommitState(SchedulerStateMachine::COMMIT_STATE_IDLE); |
| 161 state.SetCanStart(); | 161 state.SetCanStart(); |
| 162 state.UpdateState(state.NextAction()); | 162 state.UpdateState(state.NextAction()); |
| 163 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); | 163 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); |
| 164 state.SetNeedsRedraw(false); | 164 state.SetNeedsRedraw(false); |
| 165 state.SetVisible(true); | 165 state.SetVisible(true); |
| 166 state.SetNeedsCommit(); | 166 state.SetNeedsCommit(); |
| 167 | 167 |
| 168 EXPECT_TRUE(state.BeginImplFrameNeeded()); | 168 EXPECT_TRUE(state.BeginFrameNeeded()); |
| 169 | 169 |
| 170 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); | 170 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); |
| 171 EXPECT_ACTION_UPDATE_STATE( | 171 EXPECT_ACTION_UPDATE_STATE( |
| 172 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); | 172 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); |
| 173 } | 173 } |
| 174 | 174 |
| 175 // Begin the frame, make sure needs_commit and commit_state update correctly. | 175 // Begin the frame, make sure needs_commit and commit_state update correctly. |
| 176 { | 176 { |
| 177 StateMachine state(default_scheduler_settings); | 177 StateMachine state(default_scheduler_settings); |
| 178 state.SetCanStart(); | 178 state.SetCanStart(); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 194 StateMachine state(scheduler_settings); | 194 StateMachine state(scheduler_settings); |
| 195 state.SetCommitState(SchedulerStateMachine::COMMIT_STATE_IDLE); | 195 state.SetCommitState(SchedulerStateMachine::COMMIT_STATE_IDLE); |
| 196 state.SetCanStart(); | 196 state.SetCanStart(); |
| 197 state.UpdateState(state.NextAction()); | 197 state.UpdateState(state.NextAction()); |
| 198 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); | 198 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); |
| 199 state.SetNeedsRedraw(false); | 199 state.SetNeedsRedraw(false); |
| 200 state.SetVisible(true); | 200 state.SetVisible(true); |
| 201 state.SetCanDraw(true); | 201 state.SetCanDraw(true); |
| 202 state.SetNeedsCommit(); | 202 state.SetNeedsCommit(); |
| 203 | 203 |
| 204 EXPECT_TRUE(state.BeginImplFrameNeeded()); | 204 EXPECT_TRUE(state.BeginFrameNeeded()); |
| 205 | 205 |
| 206 // Commit to the pending tree. | 206 // Commit to the pending tree. |
| 207 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); | 207 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); |
| 208 EXPECT_ACTION_UPDATE_STATE( | 208 EXPECT_ACTION_UPDATE_STATE( |
| 209 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); | 209 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); |
| 210 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | 210 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 211 state.NotifyBeginMainFrameStarted(); | 211 state.NotifyBeginMainFrameStarted(); |
| 212 state.NotifyReadyToCommit(); | 212 state.NotifyReadyToCommit(); |
| 213 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); | 213 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); |
| 214 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | 214 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 262 StateMachine state(scheduler_settings); | 262 StateMachine state(scheduler_settings); |
| 263 state.SetCommitState(SchedulerStateMachine::COMMIT_STATE_IDLE); | 263 state.SetCommitState(SchedulerStateMachine::COMMIT_STATE_IDLE); |
| 264 state.SetCanStart(); | 264 state.SetCanStart(); |
| 265 state.UpdateState(state.NextAction()); | 265 state.UpdateState(state.NextAction()); |
| 266 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); | 266 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); |
| 267 state.SetNeedsRedraw(false); | 267 state.SetNeedsRedraw(false); |
| 268 state.SetVisible(true); | 268 state.SetVisible(true); |
| 269 state.SetCanDraw(true); | 269 state.SetCanDraw(true); |
| 270 state.SetNeedsCommit(); | 270 state.SetNeedsCommit(); |
| 271 | 271 |
| 272 EXPECT_TRUE(state.BeginImplFrameNeeded()); | 272 EXPECT_TRUE(state.BeginFrameNeeded()); |
| 273 | 273 |
| 274 // Commit to the pending tree. | 274 // Commit to the pending tree. |
| 275 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); | 275 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); |
| 276 EXPECT_ACTION_UPDATE_STATE( | 276 EXPECT_ACTION_UPDATE_STATE( |
| 277 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); | 277 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); |
| 278 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | 278 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 279 | 279 |
| 280 state.NotifyBeginMainFrameStarted(); | 280 state.NotifyBeginMainFrameStarted(); |
| 281 state.NotifyReadyToCommit(); | 281 state.NotifyReadyToCommit(); |
| 282 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); | 282 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 319 TestFailedDrawForAnimationCheckerboardSetsNeedsCommitAndDoesNotDrawAgain) { | 319 TestFailedDrawForAnimationCheckerboardSetsNeedsCommitAndDoesNotDrawAgain) { |
| 320 SchedulerSettings default_scheduler_settings; | 320 SchedulerSettings default_scheduler_settings; |
| 321 StateMachine state(default_scheduler_settings); | 321 StateMachine state(default_scheduler_settings); |
| 322 state.SetCanStart(); | 322 state.SetCanStart(); |
| 323 state.UpdateState(state.NextAction()); | 323 state.UpdateState(state.NextAction()); |
| 324 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); | 324 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); |
| 325 state.SetVisible(true); | 325 state.SetVisible(true); |
| 326 state.SetCanDraw(true); | 326 state.SetCanDraw(true); |
| 327 state.SetNeedsRedraw(true); | 327 state.SetNeedsRedraw(true); |
| 328 EXPECT_TRUE(state.RedrawPending()); | 328 EXPECT_TRUE(state.RedrawPending()); |
| 329 EXPECT_TRUE(state.BeginImplFrameNeeded()); | 329 EXPECT_TRUE(state.BeginFrameNeeded()); |
| 330 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); | 330 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); |
| 331 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | 331 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 332 state.OnBeginImplFrameDeadline(); | 332 state.OnBeginImplFrameDeadline(); |
| 333 | 333 |
| 334 // We're drawing now. | 334 // We're drawing now. |
| 335 EXPECT_ACTION_UPDATE_STATE( | 335 EXPECT_ACTION_UPDATE_STATE( |
| 336 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); | 336 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); |
| 337 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | 337 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 338 | 338 |
| 339 EXPECT_FALSE(state.RedrawPending()); | 339 EXPECT_FALSE(state.RedrawPending()); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 352 TEST(SchedulerStateMachineTest, TestFailedDrawForMissingHighResNeedsCommit) { | 352 TEST(SchedulerStateMachineTest, TestFailedDrawForMissingHighResNeedsCommit) { |
| 353 SchedulerSettings default_scheduler_settings; | 353 SchedulerSettings default_scheduler_settings; |
| 354 StateMachine state(default_scheduler_settings); | 354 StateMachine state(default_scheduler_settings); |
| 355 state.SetCanStart(); | 355 state.SetCanStart(); |
| 356 state.UpdateState(state.NextAction()); | 356 state.UpdateState(state.NextAction()); |
| 357 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); | 357 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); |
| 358 state.SetVisible(true); | 358 state.SetVisible(true); |
| 359 state.SetCanDraw(true); | 359 state.SetCanDraw(true); |
| 360 state.SetNeedsRedraw(true); | 360 state.SetNeedsRedraw(true); |
| 361 EXPECT_TRUE(state.RedrawPending()); | 361 EXPECT_TRUE(state.RedrawPending()); |
| 362 EXPECT_TRUE(state.BeginImplFrameNeeded()); | 362 EXPECT_TRUE(state.BeginFrameNeeded()); |
| 363 | 363 |
| 364 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); | 364 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); |
| 365 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | 365 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 366 state.OnBeginImplFrameDeadline(); | 366 state.OnBeginImplFrameDeadline(); |
| 367 EXPECT_ACTION_UPDATE_STATE( | 367 EXPECT_ACTION_UPDATE_STATE( |
| 368 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); | 368 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); |
| 369 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | 369 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 370 EXPECT_FALSE(state.RedrawPending()); | 370 EXPECT_FALSE(state.RedrawPending()); |
| 371 EXPECT_FALSE(state.CommitPending()); | 371 EXPECT_FALSE(state.CommitPending()); |
| 372 | 372 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 385 SchedulerSettings default_scheduler_settings; | 385 SchedulerSettings default_scheduler_settings; |
| 386 StateMachine state(default_scheduler_settings); | 386 StateMachine state(default_scheduler_settings); |
| 387 state.SetCanStart(); | 387 state.SetCanStart(); |
| 388 state.UpdateState(state.NextAction()); | 388 state.UpdateState(state.NextAction()); |
| 389 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); | 389 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); |
| 390 | 390 |
| 391 state.SetVisible(true); | 391 state.SetVisible(true); |
| 392 state.SetCanDraw(true); | 392 state.SetCanDraw(true); |
| 393 state.SetNeedsRedraw(true); | 393 state.SetNeedsRedraw(true); |
| 394 EXPECT_TRUE(state.RedrawPending()); | 394 EXPECT_TRUE(state.RedrawPending()); |
| 395 EXPECT_TRUE(state.BeginImplFrameNeeded()); | 395 EXPECT_TRUE(state.BeginFrameNeeded()); |
| 396 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); | 396 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); |
| 397 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | 397 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 398 state.OnBeginImplFrameDeadline(); | 398 state.OnBeginImplFrameDeadline(); |
| 399 | 399 |
| 400 // We're drawing now. | 400 // We're drawing now. |
| 401 EXPECT_ACTION_UPDATE_STATE( | 401 EXPECT_ACTION_UPDATE_STATE( |
| 402 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); | 402 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); |
| 403 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | 403 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 404 EXPECT_FALSE(state.RedrawPending()); | 404 EXPECT_FALSE(state.RedrawPending()); |
| 405 EXPECT_FALSE(state.CommitPending()); | 405 EXPECT_FALSE(state.CommitPending()); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 443 // Then initiate a draw. | 443 // Then initiate a draw. |
| 444 state.SetNeedsRedraw(true); | 444 state.SetNeedsRedraw(true); |
| 445 state.OnBeginImplFrameDeadline(); | 445 state.OnBeginImplFrameDeadline(); |
| 446 EXPECT_ACTION_UPDATE_STATE( | 446 EXPECT_ACTION_UPDATE_STATE( |
| 447 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); | 447 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); |
| 448 | 448 |
| 449 // Fail the draw. | 449 // Fail the draw. |
| 450 state.DidDrawIfPossibleCompleted( | 450 state.DidDrawIfPossibleCompleted( |
| 451 DrawSwapReadbackResult::DRAW_ABORTED_CHECKERBOARD_ANIMATIONS); | 451 DrawSwapReadbackResult::DRAW_ABORTED_CHECKERBOARD_ANIMATIONS); |
| 452 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | 452 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 453 EXPECT_TRUE(state.BeginImplFrameNeeded()); | 453 EXPECT_TRUE(state.BeginFrameNeeded()); |
| 454 EXPECT_TRUE(state.RedrawPending()); | 454 EXPECT_TRUE(state.RedrawPending()); |
| 455 // But the commit is ongoing. | 455 // But the commit is ongoing. |
| 456 EXPECT_TRUE(state.CommitPending()); | 456 EXPECT_TRUE(state.CommitPending()); |
| 457 | 457 |
| 458 // Finish the commit. Note, we should not yet be forcing a draw, but should | 458 // Finish the commit. Note, we should not yet be forcing a draw, but should |
| 459 // continue the commit as usual. | 459 // continue the commit as usual. |
| 460 state.NotifyBeginMainFrameStarted(); | 460 state.NotifyBeginMainFrameStarted(); |
| 461 state.NotifyReadyToCommit(); | 461 state.NotifyReadyToCommit(); |
| 462 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); | 462 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); |
| 463 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | 463 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 517 EXPECT_ACTION_UPDATE_STATE( | 517 EXPECT_ACTION_UPDATE_STATE( |
| 518 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); | 518 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); |
| 519 | 519 |
| 520 // Fail the draw enough times to force a redraw, | 520 // Fail the draw enough times to force a redraw, |
| 521 // then once more for good measure. | 521 // then once more for good measure. |
| 522 for (int i = 0; i < draw_limit + 1; ++i) { | 522 for (int i = 0; i < draw_limit + 1; ++i) { |
| 523 state.DidDrawIfPossibleCompleted( | 523 state.DidDrawIfPossibleCompleted( |
| 524 DrawSwapReadbackResult::DRAW_ABORTED_CHECKERBOARD_ANIMATIONS); | 524 DrawSwapReadbackResult::DRAW_ABORTED_CHECKERBOARD_ANIMATIONS); |
| 525 } | 525 } |
| 526 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | 526 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 527 EXPECT_TRUE(state.BeginImplFrameNeeded()); | 527 EXPECT_TRUE(state.BeginFrameNeeded()); |
| 528 EXPECT_TRUE(state.RedrawPending()); | 528 EXPECT_TRUE(state.RedrawPending()); |
| 529 // But the commit is ongoing. | 529 // But the commit is ongoing. |
| 530 EXPECT_TRUE(state.CommitPending()); | 530 EXPECT_TRUE(state.CommitPending()); |
| 531 EXPECT_TRUE(state.ForcedRedrawState() == | 531 EXPECT_TRUE(state.ForcedRedrawState() == |
| 532 SchedulerStateMachine::FORCED_REDRAW_STATE_WAITING_FOR_COMMIT); | 532 SchedulerStateMachine::FORCED_REDRAW_STATE_WAITING_FOR_COMMIT); |
| 533 | 533 |
| 534 state.NotifyBeginMainFrameStarted(); | 534 state.NotifyBeginMainFrameStarted(); |
| 535 state.NotifyReadyToCommit(); | 535 state.NotifyReadyToCommit(); |
| 536 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); | 536 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); |
| 537 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | 537 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 557 SchedulerSettings default_scheduler_settings; | 557 SchedulerSettings default_scheduler_settings; |
| 558 StateMachine state(default_scheduler_settings); | 558 StateMachine state(default_scheduler_settings); |
| 559 state.SetCanStart(); | 559 state.SetCanStart(); |
| 560 state.UpdateState(state.NextAction()); | 560 state.UpdateState(state.NextAction()); |
| 561 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); | 561 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); |
| 562 state.SetVisible(true); | 562 state.SetVisible(true); |
| 563 state.SetCanDraw(true); | 563 state.SetCanDraw(true); |
| 564 | 564 |
| 565 // Start a draw. | 565 // Start a draw. |
| 566 state.SetNeedsRedraw(true); | 566 state.SetNeedsRedraw(true); |
| 567 EXPECT_TRUE(state.BeginImplFrameNeeded()); | 567 EXPECT_TRUE(state.BeginFrameNeeded()); |
| 568 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); | 568 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); |
| 569 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | 569 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 570 state.OnBeginImplFrameDeadline(); | 570 state.OnBeginImplFrameDeadline(); |
| 571 EXPECT_TRUE(state.RedrawPending()); | 571 EXPECT_TRUE(state.RedrawPending()); |
| 572 EXPECT_ACTION_UPDATE_STATE( | 572 EXPECT_ACTION_UPDATE_STATE( |
| 573 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); | 573 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); |
| 574 | 574 |
| 575 // Failing the draw for animation checkerboards makes us require a commit. | 575 // Failing the draw for animation checkerboards makes us require a commit. |
| 576 state.DidDrawIfPossibleCompleted( | 576 state.DidDrawIfPossibleCompleted( |
| 577 DrawSwapReadbackResult::DRAW_ABORTED_CHECKERBOARD_ANIMATIONS); | 577 DrawSwapReadbackResult::DRAW_ABORTED_CHECKERBOARD_ANIMATIONS); |
| 578 EXPECT_ACTION_UPDATE_STATE( | 578 EXPECT_ACTION_UPDATE_STATE( |
| 579 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); | 579 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); |
| 580 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | 580 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 581 EXPECT_TRUE(state.RedrawPending()); | 581 EXPECT_TRUE(state.RedrawPending()); |
| 582 | 582 |
| 583 // We should not be trying to draw again now, but we have a commit pending. | 583 // We should not be trying to draw again now, but we have a commit pending. |
| 584 EXPECT_TRUE(state.BeginImplFrameNeeded()); | 584 EXPECT_TRUE(state.BeginFrameNeeded()); |
| 585 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); | 585 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); |
| 586 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | 586 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 587 | 587 |
| 588 // We should try to draw again at the end of the next BeginImplFrame on | 588 // We should try to draw again at the end of the next BeginImplFrame on |
| 589 // the impl thread. | 589 // the impl thread. |
| 590 state.OnBeginImplFrameDeadline(); | 590 state.OnBeginImplFrameDeadline(); |
| 591 EXPECT_ACTION_UPDATE_STATE( | 591 EXPECT_ACTION_UPDATE_STATE( |
| 592 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); | 592 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); |
| 593 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | 593 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 594 } | 594 } |
| 595 | 595 |
| 596 TEST(SchedulerStateMachineTest, TestDoestDrawTwiceInSameFrame) { | 596 TEST(SchedulerStateMachineTest, TestDoestDrawTwiceInSameFrame) { |
| 597 SchedulerSettings default_scheduler_settings; | 597 SchedulerSettings default_scheduler_settings; |
| 598 StateMachine state(default_scheduler_settings); | 598 StateMachine state(default_scheduler_settings); |
| 599 state.SetCanStart(); | 599 state.SetCanStart(); |
| 600 state.UpdateState(state.NextAction()); | 600 state.UpdateState(state.NextAction()); |
| 601 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); | 601 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); |
| 602 state.SetVisible(true); | 602 state.SetVisible(true); |
| 603 state.SetCanDraw(true); | 603 state.SetCanDraw(true); |
| 604 state.SetNeedsRedraw(true); | 604 state.SetNeedsRedraw(true); |
| 605 | 605 |
| 606 // Draw the first frame. | 606 // Draw the first frame. |
| 607 EXPECT_TRUE(state.BeginImplFrameNeeded()); | 607 EXPECT_TRUE(state.BeginFrameNeeded()); |
| 608 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); | 608 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); |
| 609 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | 609 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 610 | 610 |
| 611 state.OnBeginImplFrameDeadline(); | 611 state.OnBeginImplFrameDeadline(); |
| 612 EXPECT_ACTION_UPDATE_STATE( | 612 EXPECT_ACTION_UPDATE_STATE( |
| 613 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); | 613 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); |
| 614 state.DidDrawIfPossibleCompleted(DrawSwapReadbackResult::DRAW_SUCCESS); | 614 state.DidDrawIfPossibleCompleted(DrawSwapReadbackResult::DRAW_SUCCESS); |
| 615 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | 615 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 616 | 616 |
| 617 // Before the next BeginImplFrame, set needs redraw again. | 617 // Before the next BeginImplFrame, set needs redraw again. |
| 618 // This should not redraw until the next BeginImplFrame. | 618 // This should not redraw until the next BeginImplFrame. |
| 619 state.SetNeedsRedraw(true); | 619 state.SetNeedsRedraw(true); |
| 620 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | 620 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 621 | 621 |
| 622 // Move to another frame. This should now draw. | 622 // Move to another frame. This should now draw. |
| 623 EXPECT_TRUE(state.BeginImplFrameNeeded()); | 623 EXPECT_TRUE(state.BeginFrameNeeded()); |
| 624 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); | 624 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); |
| 625 | 625 |
| 626 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | 626 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 627 | 627 |
| 628 state.OnBeginImplFrameDeadline(); | 628 state.OnBeginImplFrameDeadline(); |
| 629 EXPECT_ACTION_UPDATE_STATE( | 629 EXPECT_ACTION_UPDATE_STATE( |
| 630 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); | 630 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); |
| 631 state.DidDrawIfPossibleCompleted(DrawSwapReadbackResult::DRAW_SUCCESS); | 631 state.DidDrawIfPossibleCompleted(DrawSwapReadbackResult::DRAW_SUCCESS); |
| 632 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | 632 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 633 | 633 |
| 634 // We just swapped, so we should proactively request another BeginImplFrame. | 634 // We just swapped, so we should proactively request another BeginImplFrame. |
| 635 EXPECT_TRUE(state.BeginImplFrameNeeded()); | 635 EXPECT_TRUE(state.BeginFrameNeeded()); |
| 636 } | 636 } |
| 637 | 637 |
| 638 TEST(SchedulerStateMachineTest, TestNextActionDrawsOnBeginImplFrame) { | 638 TEST(SchedulerStateMachineTest, TestNextActionDrawsOnBeginImplFrame) { |
| 639 SchedulerSettings default_scheduler_settings; | 639 SchedulerSettings default_scheduler_settings; |
| 640 | 640 |
| 641 // When not in BeginImplFrame deadline, or in BeginImplFrame deadline | 641 // When not in BeginImplFrame deadline, or in BeginImplFrame deadline |
| 642 // but not visible, don't draw. | 642 // but not visible, don't draw. |
| 643 size_t num_commit_states = | 643 size_t num_commit_states = |
| 644 sizeof(all_commit_states) / sizeof(SchedulerStateMachine::CommitState); | 644 sizeof(all_commit_states) / sizeof(SchedulerStateMachine::CommitState); |
| 645 size_t num_begin_impl_frame_states = | 645 size_t num_begin_impl_frame_states = |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 698 expected_action = SchedulerStateMachine::ACTION_DRAW_AND_READBACK; | 698 expected_action = SchedulerStateMachine::ACTION_DRAW_AND_READBACK; |
| 699 } else if (all_commit_states[i] == | 699 } else if (all_commit_states[i] == |
| 700 SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT) { | 700 SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT) { |
| 701 expected_action = SchedulerStateMachine::ACTION_COMMIT; | 701 expected_action = SchedulerStateMachine::ACTION_COMMIT; |
| 702 } else { | 702 } else { |
| 703 expected_action = | 703 expected_action = |
| 704 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE; | 704 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE; |
| 705 } | 705 } |
| 706 | 706 |
| 707 // Case 1: needs_commit=false. | 707 // Case 1: needs_commit=false. |
| 708 EXPECT_NE(state.BeginImplFrameNeeded(), request_readback) | 708 EXPECT_NE(state.BeginFrameNeeded(), request_readback) << *state.AsValue(); |
| 709 << *state.AsValue(); | |
| 710 EXPECT_EQ(state.NextAction(), expected_action) << *state.AsValue(); | 709 EXPECT_EQ(state.NextAction(), expected_action) << *state.AsValue(); |
| 711 | 710 |
| 712 // Case 2: needs_commit=true. | 711 // Case 2: needs_commit=true. |
| 713 state.SetNeedsCommit(); | 712 state.SetNeedsCommit(); |
| 714 EXPECT_NE(state.BeginImplFrameNeeded(), request_readback) | 713 EXPECT_NE(state.BeginFrameNeeded(), request_readback) << *state.AsValue(); |
| 715 << *state.AsValue(); | |
| 716 EXPECT_EQ(state.NextAction(), expected_action) << *state.AsValue(); | 714 EXPECT_EQ(state.NextAction(), expected_action) << *state.AsValue(); |
| 717 } | 715 } |
| 718 } | 716 } |
| 719 } | 717 } |
| 720 | 718 |
| 721 TEST(SchedulerStateMachineTest, TestNoCommitStatesRedrawWhenInvisible) { | 719 TEST(SchedulerStateMachineTest, TestNoCommitStatesRedrawWhenInvisible) { |
| 722 SchedulerSettings default_scheduler_settings; | 720 SchedulerSettings default_scheduler_settings; |
| 723 | 721 |
| 724 size_t num_commit_states = | 722 size_t num_commit_states = |
| 725 sizeof(all_commit_states) / sizeof(SchedulerStateMachine::CommitState); | 723 sizeof(all_commit_states) / sizeof(SchedulerStateMachine::CommitState); |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 807 scheduler_settings.main_frame_before_draw_enabled = | 805 scheduler_settings.main_frame_before_draw_enabled = |
| 808 main_frame_before_draw_enabled; | 806 main_frame_before_draw_enabled; |
| 809 StateMachine state(scheduler_settings); | 807 StateMachine state(scheduler_settings); |
| 810 state.SetCanStart(); | 808 state.SetCanStart(); |
| 811 state.UpdateState(state.NextAction()); | 809 state.UpdateState(state.NextAction()); |
| 812 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); | 810 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); |
| 813 state.SetNeedsCommit(); | 811 state.SetNeedsCommit(); |
| 814 state.SetVisible(true); | 812 state.SetVisible(true); |
| 815 state.SetCanDraw(true); | 813 state.SetCanDraw(true); |
| 816 | 814 |
| 817 EXPECT_TRUE(state.BeginImplFrameNeeded()); | 815 EXPECT_TRUE(state.BeginFrameNeeded()); |
| 818 | 816 |
| 819 // Begin the frame. | 817 // Begin the frame. |
| 820 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); | 818 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); |
| 821 EXPECT_ACTION_UPDATE_STATE( | 819 EXPECT_ACTION_UPDATE_STATE( |
| 822 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); | 820 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); |
| 823 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT, | 821 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT, |
| 824 state.CommitState()); | 822 state.CommitState()); |
| 825 | 823 |
| 826 // Now, while the frame is in progress, set another commit. | 824 // Now, while the frame is in progress, set another commit. |
| 827 state.SetNeedsCommit(); | 825 state.SetNeedsCommit(); |
| (...skipping 1246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2074 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | 2072 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 2075 | 2073 |
| 2076 // The deadline is not triggered early until we enter prefer smoothness mode. | 2074 // The deadline is not triggered early until we enter prefer smoothness mode. |
| 2077 EXPECT_FALSE(state.ShouldTriggerBeginImplFrameDeadlineEarly()); | 2075 EXPECT_FALSE(state.ShouldTriggerBeginImplFrameDeadlineEarly()); |
| 2078 state.SetSmoothnessTakesPriority(true); | 2076 state.SetSmoothnessTakesPriority(true); |
| 2079 EXPECT_TRUE(state.ShouldTriggerBeginImplFrameDeadlineEarly()); | 2077 EXPECT_TRUE(state.ShouldTriggerBeginImplFrameDeadlineEarly()); |
| 2080 } | 2078 } |
| 2081 | 2079 |
| 2082 } // namespace | 2080 } // namespace |
| 2083 } // namespace cc | 2081 } // namespace cc |
| OLD | NEW |