Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(508)

Side by Side Diff: cc/scheduler/scheduler_state_machine_unittest.cc

Issue 2158023005: cc: Remove retro frame logic from scheduler. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <stddef.h> 7 #include <stddef.h>
8 8
9 #include "base/trace_event/trace_event.h" 9 #include "base/trace_event/trace_event.h"
10 #include "cc/scheduler/scheduler.h" 10 #include "cc/scheduler/scheduler.h"
(...skipping 17 matching lines...) Expand all
28 << state.AsValue()->ToString() 28 << state.AsValue()->ToString()
29 29
30 #define EXPECT_MAIN_FRAME_STATE(expected) \ 30 #define EXPECT_MAIN_FRAME_STATE(expected) \
31 EXPECT_ENUM_EQ(BeginMainFrameStateToString, expected, \ 31 EXPECT_ENUM_EQ(BeginMainFrameStateToString, expected, \
32 state.BeginMainFrameState()) 32 state.BeginMainFrameState())
33 33
34 #define EXPECT_ACTION(expected) \ 34 #define EXPECT_ACTION(expected) \
35 EXPECT_ENUM_EQ(ActionToString, expected, state.NextAction()) \ 35 EXPECT_ENUM_EQ(ActionToString, expected, state.NextAction()) \
36 << state.AsValue()->ToString() 36 << state.AsValue()->ToString()
37 37
38 #define EXPECT_ACTION_UPDATE_STATE(action) \ 38 #define EXPECT_ACTION_UPDATE_STATE(action) \
39 EXPECT_ACTION(action); \ 39 EXPECT_ACTION(action); \
40 if (action == SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE || \ 40 if (action == SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE || \
41 action == SchedulerStateMachine::ACTION_DRAW_AND_SWAP_FORCED) { \ 41 action == SchedulerStateMachine::ACTION_DRAW_AND_SWAP_FORCED) { \
42 EXPECT_IMPL_FRAME_STATE( \ 42 EXPECT_IMPL_FRAME_STATE( \
43 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE); \ 43 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE); \
44 } \ 44 } \
45 PerformAction(&state, action); \ 45 PerformAction(&state, action); \
46 if (action == SchedulerStateMachine::ACTION_NONE) { \ 46 if (action == SchedulerStateMachine::ACTION_NONE) { \
47 if (state.begin_impl_frame_state() == \ 47 if (state.begin_impl_frame_state() == \
48 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE) \ 48 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE) \
49 state.OnBeginImplFrameIdle(); \ 49 state.OnBeginImplFrameIdle(); \
50 } 50 }
51 51
52 #define SET_UP_STATE(state) \ 52 #define SET_UP_STATE(state) \
53 state.SetVisible(true); \ 53 state.SetVisible(true); \
54 EXPECT_ACTION_UPDATE_STATE( \ 54 EXPECT_ACTION_UPDATE_STATE( \
55 SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION); \ 55 SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION); \
56 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); \ 56 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); \
57 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); \ 57 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); \
58 state.SetCanDraw(true); 58 state.SetCanDraw(true);
59 59
60 namespace cc { 60 namespace cc {
61 61
62 namespace { 62 namespace {
63 63
64 const SchedulerStateMachine::BeginImplFrameState all_begin_impl_frame_states[] = 64 const SchedulerStateMachine::BeginImplFrameState all_begin_impl_frame_states[] =
65 {SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE, 65 {
66 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_BEGIN_FRAME, 66 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE,
67 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE, }; 67 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_BEGIN_FRAME,
68 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE,
69 };
68 70
69 const SchedulerStateMachine::BeginMainFrameState begin_main_frame_states[] = { 71 const SchedulerStateMachine::BeginMainFrameState begin_main_frame_states[] = {
70 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_IDLE, 72 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_IDLE,
71 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_SENT, 73 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_SENT,
72 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_STARTED, 74 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_STARTED,
73 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_READY_TO_COMMIT, 75 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_READY_TO_COMMIT,
74 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_WAITING_FOR_ACTIVATION, 76 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_WAITING_FOR_ACTIVATION,
75 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_WAITING_FOR_DRAW}; 77 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_WAITING_FOR_DRAW};
76 78
77 // Exposes the protected state fields of the SchedulerStateMachine for testing 79 // Exposes the protected state fields of the SchedulerStateMachine for testing
(...skipping 1016 matching lines...) Expand 10 before | Expand all | Expand 10 after
1094 scheduler_settings.commit_to_active_tree = true; 1096 scheduler_settings.commit_to_active_tree = true;
1095 scheduler_settings.main_frame_before_activation_enabled = false; 1097 scheduler_settings.main_frame_before_activation_enabled = false;
1096 StateMachine state(scheduler_settings); 1098 StateMachine state(scheduler_settings);
1097 SET_UP_STATE(state) 1099 SET_UP_STATE(state)
1098 1100
1099 // Start clean and set commit. 1101 // Start clean and set commit.
1100 state.SetNeedsBeginMainFrame(); 1102 state.SetNeedsBeginMainFrame();
1101 1103
1102 // Begin the frame. 1104 // Begin the frame.
1103 state.OnBeginImplFrame(); 1105 state.OnBeginImplFrame();
1106 EXPECT_MAIN_FRAME_STATE(SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_IDLE);
1104 EXPECT_ACTION_UPDATE_STATE( 1107 EXPECT_ACTION_UPDATE_STATE(
1105 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 1108 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
1106 EXPECT_MAIN_FRAME_STATE(SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_SENT); 1109 EXPECT_MAIN_FRAME_STATE(SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_SENT);
1107 EXPECT_FALSE(state.NeedsCommit()); 1110 EXPECT_FALSE(state.NeedsCommit());
1108 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1111 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1109 1112
1110 // Tell the scheduler the frame finished. 1113 // Tell the scheduler the frame finished.
1111 state.NotifyBeginMainFrameStarted(); 1114 state.NotifyBeginMainFrameStarted();
1112 state.NotifyReadyToCommit(); 1115 state.NotifyReadyToCommit();
1113 EXPECT_MAIN_FRAME_STATE( 1116 EXPECT_MAIN_FRAME_STATE(
1114 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_READY_TO_COMMIT); 1117 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_READY_TO_COMMIT);
1115 1118
1116 // Commit. 1119 // Commit.
1117 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 1120 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
1118 1121
1119 // Now commit should wait for activation. 1122 // Now commit should wait for activation.
1120 EXPECT_MAIN_FRAME_STATE( 1123 EXPECT_MAIN_FRAME_STATE(
1121 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_WAITING_FOR_ACTIVATION); 1124 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_WAITING_FOR_ACTIVATION);
1122 1125
1123 // No activation yet, so this commit is not drawn yet. Force to draw this 1126 // No activation yet, so this commit is not drawn yet. Force to draw this
1124 // frame, and still block BeginMainFrame. 1127 // frame, and still block BeginMainFrame.
1125 state.SetNeedsRedraw(true); 1128 state.SetNeedsRedraw(true);
1126 state.SetNeedsBeginMainFrame(); 1129 state.SetNeedsBeginMainFrame();
1127 state.OnBeginImplFrameDeadline(); 1130 state.OnBeginImplFrameDeadline();
1128 EXPECT_ACTION_UPDATE_STATE(
1129 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
1130 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1131 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1131 1132
1132 // Cannot BeginMainFrame yet since last commit is not yet activated and drawn. 1133 // Cannot BeginMainFrame yet since last commit is not yet activated and drawn.
1133 state.OnBeginImplFrame(); 1134 state.OnBeginImplFrame();
1134 EXPECT_MAIN_FRAME_STATE( 1135 EXPECT_MAIN_FRAME_STATE(
1135 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_WAITING_FOR_ACTIVATION); 1136 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_WAITING_FOR_ACTIVATION);
1136 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1137 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1137 1138
1138 // Now activate sync tree. 1139 // Now activate sync tree.
1139 state.NotifyReadyToActivate(); 1140 state.NotifyReadyToActivate();
1140 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE); 1141 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE);
1141 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1142 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1142 EXPECT_TRUE(state.active_tree_needs_first_draw()); 1143 EXPECT_TRUE(state.active_tree_needs_first_draw());
1143 EXPECT_TRUE(state.needs_redraw()); 1144 EXPECT_TRUE(state.needs_redraw());
1144 EXPECT_MAIN_FRAME_STATE( 1145 EXPECT_MAIN_FRAME_STATE(
1145 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_WAITING_FOR_DRAW); 1146 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_WAITING_FOR_DRAW);
1146 1147
1148 // Draw only after ready to draw.
1149 state.OnBeginImplFrameDeadline();
1150 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1151
1152 // Haven't draw since last commit, do not begin new main frame.
1153 state.OnBeginImplFrame();
1154 EXPECT_MAIN_FRAME_STATE(
1155 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_WAITING_FOR_DRAW);
1156 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1157
1158 state.NotifyReadyToDraw();
1159 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1160
1161 // We can draw now. This draw unblocks BeginMainFrame.
1162 state.OnBeginImplFrameDeadline();
1163 EXPECT_ACTION_UPDATE_STATE(
1164 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
1165
1166 EXPECT_MAIN_FRAME_STATE(SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_IDLE);
1167 EXPECT_ACTION_UPDATE_STATE(
1168 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
1169 EXPECT_MAIN_FRAME_STATE(SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_SENT);
1170
1171 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1172
1173 state.OnBeginImplFrame();
1174 EXPECT_FALSE(state.needs_redraw());
1175 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1176
1147 // Swap throttled. Do not draw. 1177 // Swap throttled. Do not draw.
1148 state.DidSwapBuffers(); 1178 state.DidSwapBuffers();
1179 state.SetNeedsRedraw(true);
1149 state.OnBeginImplFrameDeadline(); 1180 state.OnBeginImplFrameDeadline();
1150 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1181 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1151 state.DidSwapBuffersComplete(); 1182 state.DidSwapBuffersComplete();
1152
1153 // Haven't draw since last commit, do not begin new main frame.
1154 state.OnBeginImplFrame();
1155 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1156
1157 // At BeginImplFrame deadline, draw. This draws unblocks BeginMainFrame.
1158 state.OnBeginImplFrameDeadline();
1159 EXPECT_ACTION_UPDATE_STATE(
1160 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
1161 state.DidSwapBuffers();
1162 state.DidSwapBuffersComplete();
1163
1164 // Now will be able to start main frame.
1165 EXPECT_MAIN_FRAME_STATE(SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_IDLE);
1166 EXPECT_FALSE(state.needs_redraw());
1167 EXPECT_ACTION_UPDATE_STATE(
1168 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
1169 } 1183 }
1170 1184
1171 TEST(SchedulerStateMachineTest, TestFullCycleWithCommitRequestInbetween) { 1185 TEST(SchedulerStateMachineTest, TestFullCycleWithCommitRequestInbetween) {
1172 SchedulerSettings default_scheduler_settings; 1186 SchedulerSettings default_scheduler_settings;
1173 StateMachine state(default_scheduler_settings); 1187 StateMachine state(default_scheduler_settings);
1174 SET_UP_STATE(state) 1188 SET_UP_STATE(state)
1175 1189
1176 // Start clean and set commit. 1190 // Start clean and set commit.
1177 state.SetNeedsBeginMainFrame(); 1191 state.SetNeedsBeginMainFrame();
1178 1192
(...skipping 988 matching lines...) Expand 10 before | Expand all | Expand 10 after
2167 state.OnBeginImplFrameDeadline(); 2181 state.OnBeginImplFrameDeadline();
2168 state.OnBeginImplFrameIdle(); 2182 state.OnBeginImplFrameIdle();
2169 2183
2170 // The scheduler should begin the output surface creation now. 2184 // The scheduler should begin the output surface creation now.
2171 EXPECT_ACTION_UPDATE_STATE( 2185 EXPECT_ACTION_UPDATE_STATE(
2172 SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION); 2186 SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION);
2173 } 2187 }
2174 2188
2175 } // namespace 2189 } // namespace
2176 } // namespace cc 2190 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698