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 700 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
711 // Begin the frame while visible. | 711 // Begin the frame while visible. |
712 state.UpdateState( | 712 state.UpdateState( |
713 SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD); | 713 SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD); |
714 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, | 714 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, |
715 state.CommitState()); | 715 state.CommitState()); |
716 EXPECT_FALSE(state.NeedsCommit()); | 716 EXPECT_FALSE(state.NeedsCommit()); |
717 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); | 717 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); |
718 | 718 |
719 // Become invisible and abort the main thread's begin frame. | 719 // Become invisible and abort the main thread's begin frame. |
720 state.SetVisible(false); | 720 state.SetVisible(false); |
721 state.BeginFrameAbortedByMainThread(); | 721 state.BeginFrameAbortedByMainThread(false); |
722 | 722 |
723 // We should now be back in the idle state as if we didn't start a frame at | 723 // We should now be back in the idle state as if we didn't start a frame at |
724 // all. | 724 // all. |
725 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState()); | 725 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState()); |
726 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); | 726 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); |
727 | 727 |
728 // Become visible again. | 728 // Become visible again. |
729 state.SetVisible(true); | 729 state.SetVisible(true); |
730 | 730 |
731 // We should be beginning a frame now. | 731 // Although we have aborted on this frame and haven't cancelled the commit |
732 // (i.e. need another), don't send another begin frame yet. | |
733 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState()); | |
734 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); | |
735 EXPECT_TRUE(state.NeedsCommit()); | |
736 | |
737 // Start a new frame. | |
738 state.DidEnterBeginFrame(BeginFrameArgs::CreateForTesting()); | |
739 EXPECT_EQ(SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD, | |
740 state.NextAction()); | |
741 } | |
742 | |
743 TEST(SchedulerStateMachineTest, AbortBeginFrameAndCancelCommit) { | |
744 SchedulerSettings default_scheduler_settings; | |
745 StateMachine state(default_scheduler_settings); | |
746 state.SetCanStart(); | |
747 state.UpdateState(state.NextAction()); | |
748 state.DidCreateAndInitializeOutputSurface(); | |
749 state.SetVisible(true); | |
750 state.SetCanDraw(true); | |
751 | |
752 // Get into a begin frame / commit state. | |
753 state.SetNeedsCommit(); | |
754 EXPECT_EQ(SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD, | |
755 state.NextAction()); | |
756 state.UpdateState( | |
757 SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD); | |
758 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, | |
759 state.CommitState()); | |
760 EXPECT_FALSE(state.NeedsCommit()); | |
761 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); | |
762 | |
763 // Abort the commit, cancelling future commits. | |
764 state.BeginFrameAbortedByMainThread(true); | |
765 | |
766 // Verify that another commit doesn't start on the same frame. | |
767 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState()); | |
768 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); | |
769 EXPECT_FALSE(state.NeedsCommit()); | |
770 | |
771 // Start a new frame. | |
772 state.DidEnterBeginFrame(BeginFrameArgs::CreateForTesting()); | |
773 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); | |
774 state.DidLeaveBeginFrame(); | |
775 | |
776 // Verify another commit doesn't start on another frame either. | |
777 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState()); | |
778 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); | |
779 EXPECT_FALSE(state.NeedsCommit()); | |
780 | |
781 // Verify another commit can start if requested, though. | |
782 state.SetNeedsCommit(); | |
732 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState()); | 783 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState()); |
733 EXPECT_EQ(SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD, | 784 EXPECT_EQ(SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD, |
734 state.NextAction()); | 785 state.NextAction()); |
735 | |
736 // Begin the frame. | |
737 state.UpdateState(state.NextAction()); | |
738 | |
739 // We should be starting the commit now. | |
danakj
2013/07/17 20:53:24
Why is this stuff removed?
enne (OOO)
2013/07/18 17:36:37
I put it back, but the important part of the test
| |
740 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, | |
741 state.CommitState()); | |
742 } | 786 } |
743 | 787 |
744 TEST(SchedulerStateMachineTest, TestFirstContextCreation) { | 788 TEST(SchedulerStateMachineTest, TestFirstContextCreation) { |
745 SchedulerSettings default_scheduler_settings; | 789 SchedulerSettings default_scheduler_settings; |
746 StateMachine state(default_scheduler_settings); | 790 StateMachine state(default_scheduler_settings); |
747 state.SetCanStart(); | 791 state.SetCanStart(); |
748 state.SetVisible(true); | 792 state.SetVisible(true); |
749 state.SetCanDraw(true); | 793 state.SetCanDraw(true); |
750 | 794 |
751 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION, | 795 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION, |
(...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1185 state.UpdateState(state.NextAction()); | 1229 state.UpdateState(state.NextAction()); |
1186 state.DidDrawIfPossibleCompleted(true); | 1230 state.DidDrawIfPossibleCompleted(true); |
1187 state.DidLeaveBeginFrame(); | 1231 state.DidLeaveBeginFrame(); |
1188 | 1232 |
1189 // Should be waiting for the main thread's begin frame. | 1233 // Should be waiting for the main thread's begin frame. |
1190 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, | 1234 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, |
1191 state.CommitState()) << state.ToString(); | 1235 state.CommitState()) << state.ToString(); |
1192 | 1236 |
1193 // Become invisible and abort the main thread's begin frame. | 1237 // Become invisible and abort the main thread's begin frame. |
1194 state.SetVisible(false); | 1238 state.SetVisible(false); |
1195 state.BeginFrameAbortedByMainThread(); | 1239 state.BeginFrameAbortedByMainThread(false); |
1196 | 1240 |
1197 // Should be back in the idle state, but needing a commit. | 1241 // Should be back in the idle state, but needing a commit. |
1198 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState()); | 1242 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState()); |
1199 EXPECT_TRUE(state.NeedsCommit()); | 1243 EXPECT_TRUE(state.NeedsCommit()); |
1200 } | 1244 } |
1201 | 1245 |
1202 TEST(SchedulerStateMachineTest, ImmediateFinishCommitWhileCantDraw) { | 1246 TEST(SchedulerStateMachineTest, ImmediateFinishCommitWhileCantDraw) { |
1203 SchedulerSettings default_scheduler_settings; | 1247 SchedulerSettings default_scheduler_settings; |
1204 StateMachine state(default_scheduler_settings); | 1248 StateMachine state(default_scheduler_settings); |
1205 state.SetCanStart(); | 1249 state.SetCanStart(); |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1290 EXPECT_TRUE(state.DrawSuspendedUntilCommit()); | 1334 EXPECT_TRUE(state.DrawSuspendedUntilCommit()); |
1291 | 1335 |
1292 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction()); | 1336 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction()); |
1293 | 1337 |
1294 state.UpdateState(state.NextAction()); | 1338 state.UpdateState(state.NextAction()); |
1295 EXPECT_FALSE(state.DrawSuspendedUntilCommit()); | 1339 EXPECT_FALSE(state.DrawSuspendedUntilCommit()); |
1296 } | 1340 } |
1297 | 1341 |
1298 } // namespace | 1342 } // namespace |
1299 } // namespace cc | 1343 } // namespace cc |
OLD | NEW |