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_state_machine.h" | 5 #include "cc/scheduler_state_machine.h" |
6 | 6 |
7 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
8 | 8 |
9 namespace cc { | 9 namespace cc { |
10 namespace { | 10 namespace { |
(...skipping 816 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
827 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction()); | 827 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction()); |
828 } | 828 } |
829 | 829 |
830 TEST(SchedulerStateMachineTest, TestBeginFrameWhenCommitInProgress) | 830 TEST(SchedulerStateMachineTest, TestBeginFrameWhenCommitInProgress) |
831 { | 831 { |
832 StateMachine state; | 832 StateMachine state; |
833 state.setCanBeginFrame(true); | 833 state.setCanBeginFrame(true); |
834 state.setVisible(false); | 834 state.setVisible(false); |
835 state.setCommitState(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS); | 835 state.setCommitState(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS); |
836 state.setNeedsCommit(); | 836 state.setNeedsCommit(); |
837 state.setNeedsForcedCommit(); | |
838 | 837 |
839 state.beginFrameComplete(); | 838 state.beginFrameComplete(); |
840 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.nextAction()); | 839 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.nextAction()); |
841 state.updateState(state.nextAction()); | 840 state.updateState(state.nextAction()); |
842 | 841 |
843 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW, state.
commitState()); | 842 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW, state.
commitState()); |
844 | 843 |
845 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction()); | 844 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.nextAction()); |
| 845 } |
| 846 |
| 847 TEST(SchedulerStateMachineTest, TestBeginFrameWhenForcedCommitInProgress) |
| 848 { |
| 849 StateMachine state; |
| 850 state.setCanBeginFrame(true); |
| 851 state.setVisible(false); |
| 852 state.setCommitState(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS); |
| 853 state.setNeedsCommit(); |
| 854 state.setNeedsForcedCommit(); |
| 855 |
| 856 state.beginFrameComplete(); |
| 857 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.nextAction()); |
| 858 state.updateState(state.nextAction()); |
| 859 |
| 860 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_FORCED_DRAW,
state.commitState()); |
| 861 |
| 862 // If we are waiting for forced draw then we know a begin frame is already i
n flight. |
| 863 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.nextAction()); |
846 } | 864 } |
847 | 865 |
848 TEST(SchedulerStateMachineTest, TestBeginFrameWhenContextLost) | 866 TEST(SchedulerStateMachineTest, TestBeginFrameWhenContextLost) |
849 { | 867 { |
850 StateMachine state; | 868 StateMachine state; |
851 state.setCanBeginFrame(true); | 869 state.setCanBeginFrame(true); |
852 state.setVisible(true); | 870 state.setVisible(true); |
853 state.setCanDraw(true); | 871 state.setCanDraw(true); |
854 state.setNeedsCommit(); | 872 state.setNeedsCommit(); |
855 state.setNeedsForcedCommit(); | 873 state.setNeedsForcedCommit(); |
(...skipping 10 matching lines...) Expand all Loading... |
866 | 884 |
867 // Schedule a forced frame, commit it, draw it. | 885 // Schedule a forced frame, commit it, draw it. |
868 state.setNeedsCommit(); | 886 state.setNeedsCommit(); |
869 state.setNeedsForcedCommit(); | 887 state.setNeedsForcedCommit(); |
870 state.updateState(state.nextAction()); | 888 state.updateState(state.nextAction()); |
871 state.beginFrameComplete(); | 889 state.beginFrameComplete(); |
872 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.nextAction()); | 890 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.nextAction()); |
873 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT, state.commitS
tate()); | 891 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT, state.commitS
tate()); |
874 state.updateState(state.nextAction()); | 892 state.updateState(state.nextAction()); |
875 | 893 |
| 894 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_FORCED_DRAW,
state.commitState()); |
| 895 |
876 state.didEnterVSync(); | 896 state.didEnterVSync(); |
877 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.nextAction()
); | 897 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.nextAction()); |
| 898 state.setNeedsForcedRedraw(true); |
| 899 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_FORCED, state.nextAction()); |
878 state.updateState(state.nextAction()); | 900 state.updateState(state.nextAction()); |
879 state.didDrawIfPossibleCompleted(true); | 901 state.didDrawIfPossibleCompleted(true); |
880 state.didLeaveVSync(); | 902 state.didLeaveVSync(); |
881 | 903 |
882 // Should be waiting for the normal begin frame | 904 // Should be waiting for the normal begin frame |
883 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, state.commit
State()); | 905 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, state.commi
tState()); |
884 } | 906 } |
885 | 907 |
886 TEST(SchedulerStateMachineTest, TestImmediateBeginFrameDuringCommit) | 908 TEST(SchedulerStateMachineTest, TestImmediateBeginFrameDuringCommit) |
887 { | 909 { |
888 StateMachine state; | 910 StateMachine state; |
889 state.setCanBeginFrame(true); | 911 state.setCanBeginFrame(true); |
890 state.setVisible(true); | 912 state.setVisible(true); |
891 state.setCanDraw(true); | 913 state.setCanDraw(true); |
892 | 914 |
893 // Start a normal commit. | 915 // Start a normal commit. |
894 state.setNeedsCommit(); | 916 state.setNeedsCommit(); |
895 state.updateState(state.nextAction()); | 917 state.updateState(state.nextAction()); |
896 | 918 |
897 // Schedule a forced frame, commit it, draw it. | 919 // Schedule a forced frame, commit it, draw it. |
898 state.setNeedsCommit(); | 920 state.setNeedsCommit(); |
899 state.setNeedsForcedCommit(); | 921 state.setNeedsForcedCommit(); |
900 state.updateState(state.nextAction()); | 922 state.updateState(state.nextAction()); |
901 state.beginFrameComplete(); | 923 state.beginFrameComplete(); |
902 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.nextAction()); | 924 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.nextAction()); |
903 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT, state.commitSt
ate()); | 925 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT, state.commitS
tate()); |
904 state.updateState(state.nextAction()); | 926 state.updateState(state.nextAction()); |
905 | 927 |
906 state.didEnterVSync(); | 928 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_FORCED_DRAW,
state.commitState()); |
907 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.nextAction())
; | |
908 state.updateState(state.nextAction()); | |
909 state.didDrawIfPossibleCompleted(true); | |
910 state.didLeaveVSync(); | |
911 | 929 |
912 // Should be waiting for the normal begin frame | 930 state.didEnterVSync(); |
913 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, state.commit
State()) << state.toString(); | 931 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.nextAction()); |
| 932 state.setNeedsForcedRedraw(true); |
| 933 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_FORCED, state.nextAction()); |
| 934 state.updateState(state.nextAction()); |
| 935 state.didDrawIfPossibleCompleted(true); |
| 936 state.didLeaveVSync(); |
| 937 |
| 938 // Should be waiting for the normal begin frame |
| 939 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, state.commi
tState()) << state.toString(); |
914 } | 940 } |
915 | 941 |
916 TEST(SchedulerStateMachineTest, ImmediateBeginFrameWhileInvisible) | 942 TEST(SchedulerStateMachineTest, ImmediateBeginFrameWhileInvisible) |
917 { | 943 { |
918 StateMachine state; | 944 StateMachine state; |
919 state.setCanBeginFrame(true); | 945 state.setCanBeginFrame(true); |
920 state.setVisible(true); | 946 state.setVisible(true); |
921 state.setCanDraw(true); | 947 state.setCanDraw(true); |
922 | 948 |
923 state.setNeedsCommit(); | 949 state.setNeedsCommit(); |
924 state.updateState(state.nextAction()); | 950 state.updateState(state.nextAction()); |
925 | 951 |
926 state.setNeedsCommit(); | 952 state.setNeedsCommit(); |
927 state.setNeedsForcedCommit(); | 953 state.setNeedsForcedCommit(); |
928 state.updateState(state.nextAction()); | 954 state.updateState(state.nextAction()); |
929 state.beginFrameComplete(); | 955 state.beginFrameComplete(); |
930 | 956 |
931 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.nextAction()); | 957 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.nextAction()); |
932 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT, state.commitSt
ate()); | 958 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT, state.commitS
tate()); |
933 state.updateState(state.nextAction()); | 959 state.updateState(state.nextAction()); |
934 | 960 |
935 state.didEnterVSync(); | 961 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_FORCED_DRAW,
state.commitState()); |
936 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.nextAction())
; | |
937 state.updateState(state.nextAction()); | |
938 state.didDrawIfPossibleCompleted(true); | |
939 state.didLeaveVSync(); | |
940 | 962 |
941 // Should be waiting for the normal begin frame | 963 state.didEnterVSync(); |
942 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, state.commit
State()) << state.toString(); | 964 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.nextAction()); |
| 965 state.setNeedsForcedRedraw(true); |
| 966 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_FORCED, state.nextAction()); |
| 967 state.updateState(state.nextAction()); |
| 968 state.didDrawIfPossibleCompleted(true); |
| 969 state.didLeaveVSync(); |
| 970 |
| 971 // Should be waiting for the normal begin frame |
| 972 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, state.commi
tState()) << state.toString(); |
943 | 973 |
944 | 974 |
945 // Become invisible and abort the "normal" begin frame. | 975 // Become invisible and abort the "normal" begin frame. |
946 state.setVisible(false); | 976 state.setVisible(false); |
947 state.beginFrameAborted(); | 977 state.beginFrameAborted(); |
948 | 978 |
949 // Should be back in the idle state, but needing a commit. | 979 // Should be back in the idle state, but needing a commit. |
950 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.commitState()); | 980 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.commitState()); |
951 EXPECT_TRUE(state.needsCommit()); | 981 EXPECT_TRUE(state.needsCommit()); |
| 982 } |
| 983 |
| 984 TEST(SchedulerStateMachineTest, ImmediateBeginFrameWhileCantDraw) |
| 985 { |
| 986 StateMachine state; |
| 987 state.setCanBeginFrame(true); |
| 988 state.setVisible(true); |
| 989 state.setCanDraw(false); |
| 990 |
| 991 state.setNeedsCommit(); |
| 992 state.updateState(state.nextAction()); |
| 993 |
| 994 state.setNeedsCommit(); |
| 995 state.setNeedsForcedCommit(); |
| 996 state.updateState(state.nextAction()); |
| 997 state.beginFrameComplete(); |
| 998 |
| 999 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.nextAction()); |
| 1000 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT, state.commitS
tate()); |
| 1001 state.updateState(state.nextAction()); |
| 1002 |
| 1003 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_FORCED_DRAW,
state.commitState()); |
| 1004 |
| 1005 state.didEnterVSync(); |
| 1006 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.nextAction()); |
| 1007 state.setNeedsForcedRedraw(true); |
| 1008 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_FORCED, state.nextAction()); |
| 1009 state.updateState(state.nextAction()); |
| 1010 state.didDrawIfPossibleCompleted(true); |
| 1011 state.didLeaveVSync(); |
952 } | 1012 } |
953 | 1013 |
954 } // namespace | 1014 } // namespace |
955 } // namespace cc | 1015 } // namespace cc |
OLD | NEW |