| 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 namespace cc { | 10 namespace cc { |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 | 52 |
| 53 EXPECT_FALSE(state.VSyncCallbackNeeded()); | 53 EXPECT_FALSE(state.VSyncCallbackNeeded()); |
| 54 | 54 |
| 55 state.DidLeaveVSync(); | 55 state.DidLeaveVSync(); |
| 56 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); | 56 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); |
| 57 EXPECT_FALSE(state.VSyncCallbackNeeded()); | 57 EXPECT_FALSE(state.VSyncCallbackNeeded()); |
| 58 state.DidEnterVSync(); | 58 state.DidEnterVSync(); |
| 59 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); | 59 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); |
| 60 } | 60 } |
| 61 | 61 |
| 62 // If commit requested but canBeginFrame is still false, do nothing. | 62 // If commit requested but can_begin_frame is still false, do nothing. |
| 63 { | 63 { |
| 64 StateMachine state(default_scheduler_settings); | 64 StateMachine state(default_scheduler_settings); |
| 65 state.SetCommitState(SchedulerStateMachine::COMMIT_STATE_IDLE); | 65 state.SetCommitState(SchedulerStateMachine::COMMIT_STATE_IDLE); |
| 66 state.SetNeedsRedraw(false); | 66 state.SetNeedsRedraw(false); |
| 67 state.SetVisible(true); | 67 state.SetVisible(true); |
| 68 | 68 |
| 69 EXPECT_FALSE(state.VSyncCallbackNeeded()); | 69 EXPECT_FALSE(state.VSyncCallbackNeeded()); |
| 70 | 70 |
| 71 state.DidLeaveVSync(); | 71 state.DidLeaveVSync(); |
| 72 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); | 72 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); |
| 73 EXPECT_FALSE(state.VSyncCallbackNeeded()); | 73 EXPECT_FALSE(state.VSyncCallbackNeeded()); |
| 74 state.DidEnterVSync(); | 74 state.DidEnterVSync(); |
| 75 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); | 75 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); |
| 76 } | 76 } |
| 77 | 77 |
| 78 // If commit requested, begin a frame. | 78 // If commit requested, begin a frame. |
| 79 { | 79 { |
| 80 StateMachine state(default_scheduler_settings); | 80 StateMachine state(default_scheduler_settings); |
| 81 state.SetCommitState(SchedulerStateMachine::COMMIT_STATE_IDLE); | 81 state.SetCommitState(SchedulerStateMachine::COMMIT_STATE_IDLE); |
| 82 state.SetCanBeginFrame(true); | 82 state.SetCanBeginFrame(true); |
| 83 state.SetNeedsRedraw(false); | 83 state.SetNeedsRedraw(false); |
| 84 state.SetVisible(true); | 84 state.SetVisible(true); |
| 85 EXPECT_FALSE(state.VSyncCallbackNeeded()); | 85 EXPECT_FALSE(state.VSyncCallbackNeeded()); |
| 86 } | 86 } |
| 87 | 87 |
| 88 // Begin the frame, make sure needsCommit and commitState update correctly. | 88 // Begin the frame, make sure needs_commit and commit_state update correctly. |
| 89 { | 89 { |
| 90 StateMachine state(default_scheduler_settings); | 90 StateMachine state(default_scheduler_settings); |
| 91 state.SetCanBeginFrame(true); | 91 state.SetCanBeginFrame(true); |
| 92 state.SetVisible(true); | 92 state.SetVisible(true); |
| 93 state.UpdateState(SchedulerStateMachine::ACTION_BEGIN_FRAME); | 93 state.UpdateState(SchedulerStateMachine::ACTION_BEGIN_FRAME); |
| 94 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, | 94 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, |
| 95 state.CommitState()); | 95 state.CommitState()); |
| 96 EXPECT_FALSE(state.NeedsCommit()); | 96 EXPECT_FALSE(state.NeedsCommit()); |
| 97 EXPECT_FALSE(state.VSyncCallbackNeeded()); | 97 EXPECT_FALSE(state.VSyncCallbackNeeded()); |
| 98 } | 98 } |
| (...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 364 StateMachine state(default_scheduler_settings); | 364 StateMachine state(default_scheduler_settings); |
| 365 state.SetCommitState(all_commit_states[i]); | 365 state.SetCommitState(all_commit_states[i]); |
| 366 bool visible = j; | 366 bool visible = j; |
| 367 if (!visible) { | 367 if (!visible) { |
| 368 state.DidEnterVSync(); | 368 state.DidEnterVSync(); |
| 369 state.SetVisible(false); | 369 state.SetVisible(false); |
| 370 } else { | 370 } else { |
| 371 state.SetVisible(true); | 371 state.SetVisible(true); |
| 372 } | 372 } |
| 373 | 373 |
| 374 // Case 1: needsCommit=false | 374 // Case 1: needs_commit=false |
| 375 EXPECT_NE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, | 375 EXPECT_NE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, |
| 376 state.NextAction()); | 376 state.NextAction()); |
| 377 | 377 |
| 378 // Case 2: needsCommit=true | 378 // Case 2: needs_commit=true |
| 379 state.SetNeedsCommit(); | 379 state.SetNeedsCommit(); |
| 380 EXPECT_NE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, | 380 EXPECT_NE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, |
| 381 state.NextAction()); | 381 state.NextAction()); |
| 382 } | 382 } |
| 383 } | 383 } |
| 384 | 384 |
| 385 // When on vsync, or not on vsync but needsForcedRedraw set, should always | 385 // When on vsync, or not on vsync but needs_forced_dedraw set, should always |
| 386 // draw except if you're ready to commit, in which case commit. | 386 // draw except if you're ready to commit, in which case commit. |
| 387 for (size_t i = 0; i < num_commit_states; ++i) { | 387 for (size_t i = 0; i < num_commit_states; ++i) { |
| 388 for (size_t j = 0; j < 2; ++j) { | 388 for (size_t j = 0; j < 2; ++j) { |
| 389 StateMachine state(default_scheduler_settings); | 389 StateMachine state(default_scheduler_settings); |
| 390 state.SetCanDraw(true); | 390 state.SetCanDraw(true); |
| 391 state.SetCommitState(all_commit_states[i]); | 391 state.SetCommitState(all_commit_states[i]); |
| 392 bool forced_draw = j; | 392 bool forced_draw = j; |
| 393 if (!forced_draw) { | 393 if (!forced_draw) { |
| 394 state.DidEnterVSync(); | 394 state.DidEnterVSync(); |
| 395 state.SetNeedsRedraw(true); | 395 state.SetNeedsRedraw(true); |
| 396 state.SetVisible(true); | 396 state.SetVisible(true); |
| 397 } else { | 397 } else { |
| 398 state.SetNeedsForcedRedraw(true); | 398 state.SetNeedsForcedRedraw(true); |
| 399 } | 399 } |
| 400 | 400 |
| 401 SchedulerStateMachine::Action expected_action; | 401 SchedulerStateMachine::Action expected_action; |
| 402 if (all_commit_states[i] != | 402 if (all_commit_states[i] != |
| 403 SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT) { | 403 SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT) { |
| 404 expected_action = | 404 expected_action = |
| 405 forced_draw ? SchedulerStateMachine::ACTION_DRAW_FORCED | 405 forced_draw ? SchedulerStateMachine::ACTION_DRAW_FORCED |
| 406 : SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE; | 406 : SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE; |
| 407 } else { | 407 } else { |
| 408 expected_action = SchedulerStateMachine::ACTION_COMMIT; | 408 expected_action = SchedulerStateMachine::ACTION_COMMIT; |
| 409 } | 409 } |
| 410 | 410 |
| 411 // Case 1: needsCommit=false. | 411 // Case 1: needs_commit=false. |
| 412 EXPECT_TRUE(state.VSyncCallbackNeeded()); | 412 EXPECT_TRUE(state.VSyncCallbackNeeded()); |
| 413 EXPECT_EQ(expected_action, state.NextAction()); | 413 EXPECT_EQ(expected_action, state.NextAction()); |
| 414 | 414 |
| 415 // Case 2: needsCommit=true. | 415 // Case 2: needs_commit=true. |
| 416 state.SetNeedsCommit(); | 416 state.SetNeedsCommit(); |
| 417 EXPECT_TRUE(state.VSyncCallbackNeeded()); | 417 EXPECT_TRUE(state.VSyncCallbackNeeded()); |
| 418 EXPECT_EQ(expected_action, state.NextAction()); | 418 EXPECT_EQ(expected_action, state.NextAction()); |
| 419 } | 419 } |
| 420 } | 420 } |
| 421 } | 421 } |
| 422 | 422 |
| 423 TEST(SchedulerStateMachineTest, TestNoCommitStatesRedrawWhenInvisible) { | 423 TEST(SchedulerStateMachineTest, TestNoCommitStatesRedrawWhenInvisible) { |
| 424 SchedulerSettings default_scheduler_settings; | 424 SchedulerSettings default_scheduler_settings; |
| 425 | 425 |
| 426 size_t num_commit_states = | 426 size_t num_commit_states = |
| 427 sizeof(all_commit_states) / sizeof(SchedulerStateMachine::CommitState); | 427 sizeof(all_commit_states) / sizeof(SchedulerStateMachine::CommitState); |
| 428 for (size_t i = 0; i < num_commit_states; ++i) { | 428 for (size_t i = 0; i < num_commit_states; ++i) { |
| 429 // There shouldn't be any drawing regardless of vsync. | 429 // There shouldn't be any drawing regardless of vsync. |
| 430 for (size_t j = 0; j < 2; ++j) { | 430 for (size_t j = 0; j < 2; ++j) { |
| 431 StateMachine state(default_scheduler_settings); | 431 StateMachine state(default_scheduler_settings); |
| 432 state.SetCommitState(all_commit_states[i]); | 432 state.SetCommitState(all_commit_states[i]); |
| 433 state.SetVisible(false); | 433 state.SetVisible(false); |
| 434 state.SetNeedsRedraw(true); | 434 state.SetNeedsRedraw(true); |
| 435 state.SetNeedsForcedRedraw(false); | 435 state.SetNeedsForcedRedraw(false); |
| 436 if (j == 1) | 436 if (j == 1) |
| 437 state.DidEnterVSync(); | 437 state.DidEnterVSync(); |
| 438 | 438 |
| 439 // Case 1: needsCommit=false. | 439 // Case 1: needs_commit=false. |
| 440 EXPECT_NE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, | 440 EXPECT_NE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, |
| 441 state.NextAction()); | 441 state.NextAction()); |
| 442 | 442 |
| 443 // Case 2: needsCommit=true. | 443 // Case 2: needs_commit=true. |
| 444 state.SetNeedsCommit(); | 444 state.SetNeedsCommit(); |
| 445 EXPECT_NE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, | 445 EXPECT_NE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, |
| 446 state.NextAction()); | 446 state.NextAction()); |
| 447 } | 447 } |
| 448 } | 448 } |
| 449 } | 449 } |
| 450 | 450 |
| 451 TEST(SchedulerStateMachineTest, TestCanRedraw_StopsDraw) { | 451 TEST(SchedulerStateMachineTest, TestCanRedraw_StopsDraw) { |
| 452 SchedulerSettings default_scheduler_settings; | 452 SchedulerSettings default_scheduler_settings; |
| 453 | 453 |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 641 state.SetNeedsCommit(); | 641 state.SetNeedsCommit(); |
| 642 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_FRAME, state.NextAction()); | 642 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_FRAME, state.NextAction()); |
| 643 | 643 |
| 644 // Begin the frame while visible. | 644 // Begin the frame while visible. |
| 645 state.UpdateState(SchedulerStateMachine::ACTION_BEGIN_FRAME); | 645 state.UpdateState(SchedulerStateMachine::ACTION_BEGIN_FRAME); |
| 646 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, | 646 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, |
| 647 state.CommitState()); | 647 state.CommitState()); |
| 648 EXPECT_FALSE(state.NeedsCommit()); | 648 EXPECT_FALSE(state.NeedsCommit()); |
| 649 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); | 649 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); |
| 650 | 650 |
| 651 // Become invisible and abort the beginFrame. | 651 // Become invisible and abort the BeginFrame. |
| 652 state.SetVisible(false); | 652 state.SetVisible(false); |
| 653 state.BeginFrameAborted(); | 653 state.BeginFrameAborted(); |
| 654 | 654 |
| 655 // We should now be back in the idle state as if we didn't start a frame at | 655 // We should now be back in the idle state as if we didn't start a frame at |
| 656 // all. | 656 // all. |
| 657 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState()); | 657 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState()); |
| 658 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); | 658 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); |
| 659 | 659 |
| 660 // Become visible again. | 660 // Become visible again. |
| 661 state.SetVisible(true); | 661 state.SetVisible(true); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 718 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); | 718 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); |
| 719 | 719 |
| 720 // Recreate the context | 720 // Recreate the context |
| 721 state.DidRecreateOutputSurface(); | 721 state.DidRecreateOutputSurface(); |
| 722 | 722 |
| 723 // When the context is recreated, we should begin a commit | 723 // When the context is recreated, we should begin a commit |
| 724 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_FRAME, state.NextAction()); | 724 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_FRAME, state.NextAction()); |
| 725 state.UpdateState(state.NextAction()); | 725 state.UpdateState(state.NextAction()); |
| 726 | 726 |
| 727 // Once the context is recreated, whether we draw should be based on | 727 // Once the context is recreated, whether we draw should be based on |
| 728 // setCanDraw. | 728 // SetCanDraw. |
| 729 state.SetNeedsRedraw(true); | 729 state.SetNeedsRedraw(true); |
| 730 state.DidEnterVSync(); | 730 state.DidEnterVSync(); |
| 731 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.NextAction()); | 731 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.NextAction()); |
| 732 state.SetCanDraw(false); | 732 state.SetCanDraw(false); |
| 733 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); | 733 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); |
| 734 state.SetCanDraw(true); | 734 state.SetCanDraw(true); |
| 735 state.DidLeaveVSync(); | 735 state.DidLeaveVSync(); |
| 736 } | 736 } |
| 737 | 737 |
| 738 TEST(SchedulerStateMachineTest, TestContextLostWhileCommitInProgress) { | 738 TEST(SchedulerStateMachineTest, TestContextLostWhileCommitInProgress) { |
| (...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1072 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); | 1072 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); |
| 1073 state.SetNeedsForcedRedraw(true); | 1073 state.SetNeedsForcedRedraw(true); |
| 1074 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_FORCED, state.NextAction()); | 1074 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_FORCED, state.NextAction()); |
| 1075 state.UpdateState(state.NextAction()); | 1075 state.UpdateState(state.NextAction()); |
| 1076 state.DidDrawIfPossibleCompleted(true); | 1076 state.DidDrawIfPossibleCompleted(true); |
| 1077 state.DidLeaveVSync(); | 1077 state.DidLeaveVSync(); |
| 1078 } | 1078 } |
| 1079 | 1079 |
| 1080 } // namespace | 1080 } // namespace |
| 1081 } // namespace cc | 1081 } // namespace cc |
| OLD | NEW |