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 "config.h" | 5 #include "config.h" |
6 | 6 |
7 #include "cc/scheduler_state_machine.h" | 7 #include "cc/scheduler_state_machine.h" |
8 | 8 |
9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 | 10 |
(...skipping 10 matching lines...) Expand all Loading... |
21 | 21 |
22 // Exposes the protected state fields of the SchedulerStateMachine for testing | 22 // Exposes the protected state fields of the SchedulerStateMachine for testing |
23 class StateMachine : public SchedulerStateMachine { | 23 class StateMachine : public SchedulerStateMachine { |
24 public: | 24 public: |
25 void setCommitState(CommitState cs) { m_commitState = cs; } | 25 void setCommitState(CommitState cs) { m_commitState = cs; } |
26 CommitState commitState() const { return m_commitState; } | 26 CommitState commitState() const { return m_commitState; } |
27 | 27 |
28 void setNeedsCommit(bool b) { m_needsCommit = b; } | 28 void setNeedsCommit(bool b) { m_needsCommit = b; } |
29 bool needsCommit() const { return m_needsCommit; } | 29 bool needsCommit() const { return m_needsCommit; } |
30 | 30 |
31 void setNeedsForcedCommit(bool b) { m_needsForcedCommit = b; } | |
32 bool needsForcedCommit() const { return m_needsForcedCommit; } | |
33 | |
34 void setNeedsRedraw(bool b) { m_needsRedraw = b; } | 31 void setNeedsRedraw(bool b) { m_needsRedraw = b; } |
35 bool needsRedraw() const { return m_needsRedraw; } | 32 bool needsRedraw() const { return m_needsRedraw; } |
36 | 33 |
37 void setNeedsForcedRedraw(bool b) { m_needsForcedRedraw = b; } | 34 void setNeedsForcedRedraw(bool b) { m_needsForcedRedraw = b; } |
38 bool needsForcedRedraw() const { return m_needsForcedRedraw; } | 35 bool needsForcedRedraw() const { return m_needsForcedRedraw; } |
39 | 36 |
40 bool canDraw() const { return m_canDraw; } | 37 bool canDraw() const { return m_canDraw; } |
41 bool insideVSync() const { return m_insideVSync; } | 38 bool insideVSync() const { return m_insideVSync; } |
42 bool visible() const { return m_visible; } | 39 bool visible() const { return m_visible; } |
43 }; | 40 }; |
(...skipping 775 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
819 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_FORCED, state.nextAction()); | 816 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_FORCED, state.nextAction()); |
820 state.didLeaveVSync(); | 817 state.didLeaveVSync(); |
821 } | 818 } |
822 | 819 |
823 TEST(SchedulerStateMachineTest, TestBeginFrameWhenInvisibleAndForceCommit) | 820 TEST(SchedulerStateMachineTest, TestBeginFrameWhenInvisibleAndForceCommit) |
824 { | 821 { |
825 StateMachine state; | 822 StateMachine state; |
826 state.setCanBeginFrame(true); | 823 state.setCanBeginFrame(true); |
827 state.setVisible(false); | 824 state.setVisible(false); |
828 state.setNeedsCommit(true); | 825 state.setNeedsCommit(true); |
829 state.setNeedsForcedCommit(true); | 826 state.setNeedsForcedCommit(); |
830 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction()); | 827 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction()); |
831 } | 828 } |
832 | 829 |
833 TEST(SchedulerStateMachineTest, TestBeginFrameWhenCanBeginFrameFalseAndForceComm
it) | 830 TEST(SchedulerStateMachineTest, TestBeginFrameWhenCanBeginFrameFalseAndForceComm
it) |
834 { | 831 { |
835 StateMachine state; | 832 StateMachine state; |
836 state.setVisible(true); | 833 state.setVisible(true); |
837 state.setCanDraw(true); | 834 state.setCanDraw(true); |
838 state.setNeedsCommit(true); | 835 state.setNeedsCommit(true); |
839 state.setNeedsForcedCommit(true); | 836 state.setNeedsForcedCommit(); |
840 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction()); | 837 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction()); |
841 } | 838 } |
842 | 839 |
843 TEST(SchedulerStateMachineTest, TestBeginFrameWhenCommitInProgress) | 840 TEST(SchedulerStateMachineTest, TestBeginFrameWhenCommitInProgress) |
844 { | 841 { |
845 StateMachine state; | 842 StateMachine state; |
846 state.setCanBeginFrame(true); | 843 state.setCanBeginFrame(true); |
847 state.setVisible(false); | 844 state.setVisible(false); |
848 state.setCommitState(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS); | 845 state.setCommitState(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS); |
849 state.setNeedsCommit(true); | 846 state.setNeedsCommit(true); |
850 state.setNeedsForcedCommit(true); | 847 state.setNeedsForcedCommit(); |
851 | 848 |
852 state.beginFrameComplete(); | 849 state.beginFrameComplete(); |
853 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.nextAction()); | 850 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.nextAction()); |
854 state.updateState(state.nextAction()); | 851 state.updateState(state.nextAction()); |
855 | 852 |
856 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW, state.
commitState()); | 853 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW, state.
commitState()); |
857 | 854 |
858 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction()); | 855 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction()); |
859 } | 856 } |
860 | 857 |
861 TEST(SchedulerStateMachineTest, TestBeginFrameWhenContextLost) | 858 TEST(SchedulerStateMachineTest, TestBeginFrameWhenContextLost) |
862 { | 859 { |
863 StateMachine state; | 860 StateMachine state; |
864 state.setCanBeginFrame(true); | 861 state.setCanBeginFrame(true); |
865 state.setVisible(true); | 862 state.setVisible(true); |
866 state.setCanDraw(true); | 863 state.setCanDraw(true); |
867 state.setNeedsCommit(true); | 864 state.setNeedsCommit(true); |
868 state.setNeedsForcedCommit(true); | 865 state.setNeedsForcedCommit(); |
869 state.didLoseContext(); | 866 state.didLoseContext(); |
870 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction()); | 867 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction()); |
871 } | 868 } |
872 | 869 |
| 870 TEST(SchedulerStateMachineTest, TestImmediateBeginFrame) |
| 871 { |
| 872 StateMachine state; |
| 873 state.setCanBeginFrame(true); |
| 874 state.setVisible(true); |
| 875 state.setCanDraw(true); |
| 876 |
| 877 // Schedule a forced frame, commit it, draw it. |
| 878 state.setNeedsCommit(true); |
| 879 state.setNeedsForcedCommit(); |
| 880 state.updateState(state.nextAction()); |
| 881 state.beginFrameComplete(); |
| 882 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.nextAction()); |
| 883 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT, state.commitS
tate()); |
| 884 state.updateState(state.nextAction()); |
| 885 |
| 886 state.didEnterVSync(); |
| 887 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.nextAction()
); |
| 888 state.updateState(state.nextAction()); |
| 889 state.didDrawIfPossibleCompleted(true); |
| 890 state.didLeaveVSync(); |
| 891 |
| 892 // Should be waiting for the normal begin frame |
| 893 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, state.commi
tState()); |
873 } | 894 } |
| 895 |
| 896 TEST(SchedulerStateMachineTest, TestImmediateBeginFrameDuringCommit) |
| 897 { |
| 898 StateMachine state; |
| 899 state.setCanBeginFrame(true); |
| 900 state.setVisible(true); |
| 901 state.setCanDraw(true); |
| 902 |
| 903 // Start a normal commit. |
| 904 state.setNeedsCommit(true); |
| 905 state.updateState(state.nextAction()); |
| 906 |
| 907 // Schedule a forced frame, commit it, draw it. |
| 908 state.setNeedsCommit(true); |
| 909 state.setNeedsForcedCommit(); |
| 910 state.updateState(state.nextAction()); |
| 911 state.beginFrameComplete(); |
| 912 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.nextAction()); |
| 913 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT, state.commitS
tate()); |
| 914 state.updateState(state.nextAction()); |
| 915 |
| 916 state.didEnterVSync(); |
| 917 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.nextAction()
); |
| 918 state.updateState(state.nextAction()); |
| 919 state.didDrawIfPossibleCompleted(true); |
| 920 state.didLeaveVSync(); |
| 921 |
| 922 // Should be waiting for the normal begin frame |
| 923 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, state.commi
tState()) << state.toString(); |
| 924 } |
| 925 |
| 926 |
| 927 } |
OLD | NEW |