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

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

Issue 2323063004: cc: Remove frame queuing from the scheduler. (Closed)
Patch Set: nit Created 4 years, 3 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
« no previous file with comments | « cc/scheduler/scheduler_state_machine.cc ('k') | cc/scheduler/scheduler_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 1030 matching lines...) Expand 10 before | Expand all | Expand 10 after
1108 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1110 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1109 1111
1110 // Tell the scheduler the frame finished. 1112 // Tell the scheduler the frame finished.
1111 state.NotifyBeginMainFrameStarted(); 1113 state.NotifyBeginMainFrameStarted();
1112 state.NotifyReadyToCommit(); 1114 state.NotifyReadyToCommit();
1113 EXPECT_MAIN_FRAME_STATE( 1115 EXPECT_MAIN_FRAME_STATE(
1114 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_READY_TO_COMMIT); 1116 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_READY_TO_COMMIT);
1115 1117
1116 // Commit. 1118 // Commit.
1117 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 1119 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
1118 1120 // Now commit should wait for activation but only momentarily.
1119 // Now commit should wait for activation.
1120 EXPECT_MAIN_FRAME_STATE( 1121 EXPECT_MAIN_FRAME_STATE(
1121 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_WAITING_FOR_ACTIVATION); 1122 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_WAITING_FOR_ACTIVATION);
1122 1123
1123 // No activation yet, so this commit is not drawn yet. Force to draw this 1124 // Commit always calls NotifyReadyToActivate in this mode.
1124 // frame, and still block BeginMainFrame. 1125 state.NotifyReadyToActivate();
1125 state.SetNeedsRedraw(true); 1126 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE);
1127 EXPECT_MAIN_FRAME_STATE(
1128 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_WAITING_FOR_DRAW);
1129
1130 // No draw because we haven't received NotifyReadyToDraw yet.
1131 state.OnBeginImplFrameDeadline();
1132 EXPECT_TRUE(state.active_tree_needs_first_draw());
1133 EXPECT_TRUE(state.needs_redraw());
1134 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1135
1136 // Cannot BeginMainFrame yet since last commit is not ready to draw.
1126 state.SetNeedsBeginMainFrame(); 1137 state.SetNeedsBeginMainFrame();
1138 state.OnBeginImplFrame();
1139 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1140 EXPECT_MAIN_FRAME_STATE(
1141 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_WAITING_FOR_DRAW);
1142
1143 // Now call ready to draw which will allow the draw to happen and
1144 // BeginMainFrame to be sent.
1145 state.NotifyReadyToDraw();
1127 state.OnBeginImplFrameDeadline(); 1146 state.OnBeginImplFrameDeadline();
1128 EXPECT_ACTION_UPDATE_STATE( 1147 EXPECT_ACTION_UPDATE_STATE(
1129 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 1148 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
1149 EXPECT_ACTION_UPDATE_STATE(
1150 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
1151 state.DidSwapBuffers();
1152
1153 // Swap throttled from this point.
1154 state.OnBeginImplFrame();
1130 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1155 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1131 1156
1132 // Cannot BeginMainFrame yet since last commit is not yet activated and drawn. 1157 // Commit, activate and notify ready to draw.
1133 state.OnBeginImplFrame(); 1158 state.NotifyBeginMainFrameStarted();
1134 EXPECT_MAIN_FRAME_STATE( 1159 state.NotifyReadyToCommit();
1135 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_WAITING_FOR_ACTIVATION); 1160 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
1161 state.NotifyReadyToActivate();
1162 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE);
1163 state.NotifyReadyToDraw();
1136 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1164 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1137 1165
1138 // Now activate sync tree. 1166 // Swap throttled. Do not draw.
1139 state.NotifyReadyToActivate(); 1167 state.OnBeginImplFrameDeadline();
1140 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE);
1141 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1142 EXPECT_TRUE(state.active_tree_needs_first_draw()); 1168 EXPECT_TRUE(state.active_tree_needs_first_draw());
1143 EXPECT_TRUE(state.needs_redraw()); 1169 EXPECT_TRUE(state.needs_redraw());
1170 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1171
1172 // Haven't drawn since last commit, do not begin new main frame.
1173 state.SetNeedsBeginMainFrame();
1174 state.OnBeginImplFrame();
1175 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1144 EXPECT_MAIN_FRAME_STATE( 1176 EXPECT_MAIN_FRAME_STATE(
1145 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_WAITING_FOR_DRAW); 1177 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_WAITING_FOR_DRAW);
1146 1178
1147 // Swap throttled. Do not draw. 1179 // Swap ack and draw which also unblocks BeginMainFrame.
1148 state.DidSwapBuffers();
1149 state.OnBeginImplFrameDeadline();
1150 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1151 state.DidSwapBuffersComplete(); 1180 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(); 1181 state.OnBeginImplFrameDeadline();
1159 EXPECT_ACTION_UPDATE_STATE( 1182 EXPECT_ACTION_UPDATE_STATE(
1160 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 1183 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( 1184 EXPECT_ACTION_UPDATE_STATE(
1168 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 1185 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
1169 } 1186 }
1170 1187
1171 TEST(SchedulerStateMachineTest, TestFullCycleWithCommitRequestInbetween) { 1188 TEST(SchedulerStateMachineTest, TestFullCycleWithCommitRequestInbetween) {
1172 SchedulerSettings default_scheduler_settings; 1189 SchedulerSettings default_scheduler_settings;
1173 StateMachine state(default_scheduler_settings); 1190 StateMachine state(default_scheduler_settings);
1174 SET_UP_STATE(state) 1191 SET_UP_STATE(state)
1175 1192
1176 // Start clean and set commit. 1193 // Start clean and set commit.
(...skipping 990 matching lines...) Expand 10 before | Expand all | Expand 10 after
2167 state.OnBeginImplFrameDeadline(); 2184 state.OnBeginImplFrameDeadline();
2168 state.OnBeginImplFrameIdle(); 2185 state.OnBeginImplFrameIdle();
2169 2186
2170 // The scheduler should begin the output surface creation now. 2187 // The scheduler should begin the output surface creation now.
2171 EXPECT_ACTION_UPDATE_STATE( 2188 EXPECT_ACTION_UPDATE_STATE(
2172 SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION); 2189 SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION);
2173 } 2190 }
2174 2191
2175 } // namespace 2192 } // namespace
2176 } // namespace cc 2193 } // namespace cc
OLDNEW
« no previous file with comments | « cc/scheduler/scheduler_state_machine.cc ('k') | cc/scheduler/scheduler_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698