| 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. |
| 732 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState()); | 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()); |
| 733 EXPECT_EQ(SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD, | 739 EXPECT_EQ(SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD, |
| 734 state.NextAction()); | 740 state.NextAction()); |
| 735 | 741 |
| 736 // Begin the frame. | 742 // Begin the frame. |
| 737 state.UpdateState(state.NextAction()); | 743 state.UpdateState(state.NextAction()); |
| 738 | 744 |
| 739 // We should be starting the commit now. | 745 // We should be starting the commit now. |
| 740 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, | 746 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, |
| 741 state.CommitState()); | 747 state.CommitState()); |
| 742 } | 748 } |
| 743 | 749 |
| 750 TEST(SchedulerStateMachineTest, AbortBeginFrameAndCancelCommit) { |
| 751 SchedulerSettings default_scheduler_settings; |
| 752 StateMachine state(default_scheduler_settings); |
| 753 state.SetCanStart(); |
| 754 state.UpdateState(state.NextAction()); |
| 755 state.DidCreateAndInitializeOutputSurface(); |
| 756 state.SetVisible(true); |
| 757 state.SetCanDraw(true); |
| 758 |
| 759 // Get into a begin frame / commit state. |
| 760 state.SetNeedsCommit(); |
| 761 EXPECT_EQ(SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD, |
| 762 state.NextAction()); |
| 763 state.UpdateState( |
| 764 SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD); |
| 765 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, |
| 766 state.CommitState()); |
| 767 EXPECT_FALSE(state.NeedsCommit()); |
| 768 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); |
| 769 |
| 770 // Abort the commit, cancelling future commits. |
| 771 state.BeginFrameAbortedByMainThread(true); |
| 772 |
| 773 // Verify that another commit doesn't start on the same frame. |
| 774 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState()); |
| 775 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); |
| 776 EXPECT_FALSE(state.NeedsCommit()); |
| 777 |
| 778 // Start a new frame; draw because this is the first frame since output |
| 779 // surface init'd. |
| 780 state.DidEnterBeginFrame(BeginFrameArgs::CreateForTesting()); |
| 781 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.NextAction()); |
| 782 state.DidLeaveBeginFrame(); |
| 783 |
| 784 // Verify another commit doesn't start on another frame either. |
| 785 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState()); |
| 786 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); |
| 787 EXPECT_FALSE(state.NeedsCommit()); |
| 788 |
| 789 // Verify another commit can start if requested, though. |
| 790 state.SetNeedsCommit(); |
| 791 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState()); |
| 792 EXPECT_EQ(SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD, |
| 793 state.NextAction()); |
| 794 } |
| 795 |
| 744 TEST(SchedulerStateMachineTest, TestFirstContextCreation) { | 796 TEST(SchedulerStateMachineTest, TestFirstContextCreation) { |
| 745 SchedulerSettings default_scheduler_settings; | 797 SchedulerSettings default_scheduler_settings; |
| 746 StateMachine state(default_scheduler_settings); | 798 StateMachine state(default_scheduler_settings); |
| 747 state.SetCanStart(); | 799 state.SetCanStart(); |
| 748 state.SetVisible(true); | 800 state.SetVisible(true); |
| 749 state.SetCanDraw(true); | 801 state.SetCanDraw(true); |
| 750 | 802 |
| 751 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION, | 803 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION, |
| 752 state.NextAction()); | 804 state.NextAction()); |
| 753 state.UpdateState(state.NextAction()); | 805 state.UpdateState(state.NextAction()); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 809 | 861 |
| 810 // Once context recreation begins, nothing should happen. | 862 // Once context recreation begins, nothing should happen. |
| 811 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); | 863 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); |
| 812 | 864 |
| 813 // While context is recreating, commits shouldn't begin. | 865 // While context is recreating, commits shouldn't begin. |
| 814 state.SetNeedsCommit(); | 866 state.SetNeedsCommit(); |
| 815 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); | 867 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); |
| 816 | 868 |
| 817 // Recreate the context | 869 // Recreate the context |
| 818 state.DidCreateAndInitializeOutputSurface(); | 870 state.DidCreateAndInitializeOutputSurface(); |
| 871 EXPECT_FALSE(state.RedrawPending()); |
| 819 | 872 |
| 820 // When the context is recreated, we should begin a commit | 873 // When the context is recreated, we should begin a commit |
| 821 EXPECT_EQ(SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD, | 874 EXPECT_EQ(SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD, |
| 822 state.NextAction()); | 875 state.NextAction()); |
| 823 state.UpdateState(state.NextAction()); | 876 state.UpdateState(state.NextAction()); |
| 877 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, |
| 878 state.CommitState()); |
| 879 state.FinishCommit(); |
| 880 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction()); |
| 881 state.UpdateState(state.NextAction()); |
| 882 // Finishing the first commit after initializing an output surface should |
| 883 // automatically cause a redraw. |
| 884 EXPECT_TRUE(state.RedrawPending()); |
| 824 | 885 |
| 825 // Once the context is recreated, whether we draw should be based on | 886 // Once the context is recreated, whether we draw should be based on |
| 826 // SetCanDraw. | 887 // SetCanDraw. |
| 827 state.SetNeedsRedraw(true); | |
| 828 state.DidEnterBeginFrame(BeginFrameArgs::CreateForTesting()); | 888 state.DidEnterBeginFrame(BeginFrameArgs::CreateForTesting()); |
| 829 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.NextAction()); | 889 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.NextAction()); |
| 830 state.SetCanDraw(false); | 890 state.SetCanDraw(false); |
| 831 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); | 891 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); |
| 832 state.SetCanDraw(true); | 892 state.SetCanDraw(true); |
| 833 state.DidLeaveBeginFrame(); | 893 state.DidLeaveBeginFrame(); |
| 834 } | 894 } |
| 835 | 895 |
| 836 TEST(SchedulerStateMachineTest, TestContextLostWhileCommitInProgress) { | 896 TEST(SchedulerStateMachineTest, TestContextLostWhileCommitInProgress) { |
| 837 SchedulerSettings default_scheduler_settings; | 897 SchedulerSettings default_scheduler_settings; |
| (...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1185 state.UpdateState(state.NextAction()); | 1245 state.UpdateState(state.NextAction()); |
| 1186 state.DidDrawIfPossibleCompleted(true); | 1246 state.DidDrawIfPossibleCompleted(true); |
| 1187 state.DidLeaveBeginFrame(); | 1247 state.DidLeaveBeginFrame(); |
| 1188 | 1248 |
| 1189 // Should be waiting for the main thread's begin frame. | 1249 // Should be waiting for the main thread's begin frame. |
| 1190 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, | 1250 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, |
| 1191 state.CommitState()) << state.ToString(); | 1251 state.CommitState()) << state.ToString(); |
| 1192 | 1252 |
| 1193 // Become invisible and abort the main thread's begin frame. | 1253 // Become invisible and abort the main thread's begin frame. |
| 1194 state.SetVisible(false); | 1254 state.SetVisible(false); |
| 1195 state.BeginFrameAbortedByMainThread(); | 1255 state.BeginFrameAbortedByMainThread(false); |
| 1196 | 1256 |
| 1197 // Should be back in the idle state, but needing a commit. | 1257 // Should be back in the idle state, but needing a commit. |
| 1198 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState()); | 1258 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState()); |
| 1199 EXPECT_TRUE(state.NeedsCommit()); | 1259 EXPECT_TRUE(state.NeedsCommit()); |
| 1200 } | 1260 } |
| 1201 | 1261 |
| 1202 TEST(SchedulerStateMachineTest, ImmediateFinishCommitWhileCantDraw) { | 1262 TEST(SchedulerStateMachineTest, ImmediateFinishCommitWhileCantDraw) { |
| 1203 SchedulerSettings default_scheduler_settings; | 1263 SchedulerSettings default_scheduler_settings; |
| 1204 StateMachine state(default_scheduler_settings); | 1264 StateMachine state(default_scheduler_settings); |
| 1205 state.SetCanStart(); | 1265 state.SetCanStart(); |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1288 | 1348 |
| 1289 state.FinishCommit(); | 1349 state.FinishCommit(); |
| 1290 EXPECT_TRUE(state.DrawSuspendedUntilCommit()); | 1350 EXPECT_TRUE(state.DrawSuspendedUntilCommit()); |
| 1291 | 1351 |
| 1292 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction()); | 1352 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction()); |
| 1293 | 1353 |
| 1294 state.UpdateState(state.NextAction()); | 1354 state.UpdateState(state.NextAction()); |
| 1295 EXPECT_FALSE(state.DrawSuspendedUntilCommit()); | 1355 EXPECT_FALSE(state.DrawSuspendedUntilCommit()); |
| 1296 } | 1356 } |
| 1297 | 1357 |
| 1358 TEST(SchedulerStateMachineTest, AcquireTexturesWithAbort) { |
| 1359 SchedulerSettings default_scheduler_settings; |
| 1360 SchedulerStateMachine state(default_scheduler_settings); |
| 1361 state.SetCanStart(); |
| 1362 state.UpdateState(state.NextAction()); |
| 1363 state.DidCreateAndInitializeOutputSurface(); |
| 1364 state.SetCanDraw(true); |
| 1365 state.SetVisible(true); |
| 1366 |
| 1367 state.SetMainThreadNeedsLayerTextures(); |
| 1368 EXPECT_EQ( |
| 1369 SchedulerStateMachine::ACTION_ACQUIRE_LAYER_TEXTURES_FOR_MAIN_THREAD, |
| 1370 state.NextAction()); |
| 1371 state.UpdateState(state.NextAction()); |
| 1372 EXPECT_TRUE(state.DrawSuspendedUntilCommit()); |
| 1373 |
| 1374 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); |
| 1375 |
| 1376 state.SetNeedsCommit(); |
| 1377 EXPECT_EQ(SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD, |
| 1378 state.NextAction()); |
| 1379 state.UpdateState(state.NextAction()); |
| 1380 EXPECT_TRUE(state.DrawSuspendedUntilCommit()); |
| 1381 |
| 1382 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); |
| 1383 |
| 1384 state.BeginFrameAbortedByMainThread(true); |
| 1385 |
| 1386 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); |
| 1387 EXPECT_FALSE(state.DrawSuspendedUntilCommit()); |
| 1388 } |
| 1389 |
| 1298 } // namespace | 1390 } // namespace |
| 1299 } // namespace cc | 1391 } // namespace cc |
| OLD | NEW |