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

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

Issue 2336493002: Revert of cc: Remove frame queuing from the scheduler. (Closed)
Patch Set: 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 { 65 {SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE,
66 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE, 66 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_BEGIN_FRAME,
67 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_BEGIN_FRAME, 67 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE, };
68 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE,
69 };
70 68
71 const SchedulerStateMachine::BeginMainFrameState begin_main_frame_states[] = { 69 const SchedulerStateMachine::BeginMainFrameState begin_main_frame_states[] = {
72 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_IDLE, 70 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_IDLE,
73 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_SENT, 71 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_SENT,
74 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_STARTED, 72 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_STARTED,
75 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_READY_TO_COMMIT, 73 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_READY_TO_COMMIT,
76 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_WAITING_FOR_ACTIVATION, 74 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_WAITING_FOR_ACTIVATION,
77 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_WAITING_FOR_DRAW}; 75 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_WAITING_FOR_DRAW};
78 76
79 // Exposes the protected state fields of the SchedulerStateMachine for testing 77 // Exposes the protected state fields of the SchedulerStateMachine for testing
(...skipping 1030 matching lines...) Expand 10 before | Expand all | Expand 10 after
1110 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1108 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1111 1109
1112 // Tell the scheduler the frame finished. 1110 // Tell the scheduler the frame finished.
1113 state.NotifyBeginMainFrameStarted(); 1111 state.NotifyBeginMainFrameStarted();
1114 state.NotifyReadyToCommit(); 1112 state.NotifyReadyToCommit();
1115 EXPECT_MAIN_FRAME_STATE( 1113 EXPECT_MAIN_FRAME_STATE(
1116 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_READY_TO_COMMIT); 1114 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_READY_TO_COMMIT);
1117 1115
1118 // Commit. 1116 // Commit.
1119 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 1117 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
1120 // Now commit should wait for activation but only momentarily. 1118
1119 // Now commit should wait for activation.
1121 EXPECT_MAIN_FRAME_STATE( 1120 EXPECT_MAIN_FRAME_STATE(
1122 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_WAITING_FOR_ACTIVATION); 1121 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_WAITING_FOR_ACTIVATION);
1123 1122
1124 // Commit always calls NotifyReadyToActivate in this mode. 1123 // No activation yet, so this commit is not drawn yet. Force to draw this
1124 // frame, and still block BeginMainFrame.
1125 state.SetNeedsRedraw(true);
1126 state.SetNeedsBeginMainFrame();
1127 state.OnBeginImplFrameDeadline();
1128 EXPECT_ACTION_UPDATE_STATE(
1129 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
1130 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1131
1132 // Cannot BeginMainFrame yet since last commit is not yet activated and drawn.
1133 state.OnBeginImplFrame();
1134 EXPECT_MAIN_FRAME_STATE(
1135 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_WAITING_FOR_ACTIVATION);
1136 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1137
1138 // Now activate sync tree.
1125 state.NotifyReadyToActivate(); 1139 state.NotifyReadyToActivate();
1126 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE); 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());
1143 EXPECT_TRUE(state.needs_redraw());
1127 EXPECT_MAIN_FRAME_STATE( 1144 EXPECT_MAIN_FRAME_STATE(
1128 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_WAITING_FOR_DRAW); 1145 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_WAITING_FOR_DRAW);
1129 1146
1130 // No draw because we haven't received NotifyReadyToDraw yet. 1147 // Swap throttled. Do not draw.
1148 state.DidSwapBuffers();
1131 state.OnBeginImplFrameDeadline(); 1149 state.OnBeginImplFrameDeadline();
1132 EXPECT_TRUE(state.active_tree_needs_first_draw()); 1150 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1133 EXPECT_TRUE(state.needs_redraw()); 1151 state.DidSwapBuffersComplete();
1152
1153 // Haven't draw since last commit, do not begin new main frame.
1154 state.OnBeginImplFrame();
1134 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1155 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1135 1156
1136 // Cannot BeginMainFrame yet since last commit is not ready to draw. 1157 // At BeginImplFrame deadline, draw. This draws unblocks BeginMainFrame.
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();
1146 state.OnBeginImplFrameDeadline(); 1158 state.OnBeginImplFrameDeadline();
1147 EXPECT_ACTION_UPDATE_STATE( 1159 EXPECT_ACTION_UPDATE_STATE(
1148 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 1160 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
1149 EXPECT_ACTION_UPDATE_STATE(
1150 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
1151 state.DidSwapBuffers(); 1161 state.DidSwapBuffers();
1162 state.DidSwapBuffersComplete();
1152 1163
1153 // Swap throttled from this point. 1164 // Now will be able to start main frame.
1154 state.OnBeginImplFrame(); 1165 EXPECT_MAIN_FRAME_STATE(SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_IDLE);
1155 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1166 EXPECT_FALSE(state.needs_redraw());
1156
1157 // Commit, activate and notify ready to draw.
1158 state.NotifyBeginMainFrameStarted();
1159 state.NotifyReadyToCommit();
1160 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
1161 state.NotifyReadyToActivate();
1162 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE);
1163 state.NotifyReadyToDraw();
1164 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1165
1166 // Swap throttled. Do not draw.
1167 state.OnBeginImplFrameDeadline();
1168 EXPECT_TRUE(state.active_tree_needs_first_draw());
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);
1176 EXPECT_MAIN_FRAME_STATE(
1177 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_WAITING_FOR_DRAW);
1178
1179 // Swap ack and draw which also unblocks BeginMainFrame.
1180 state.DidSwapBuffersComplete();
1181 state.OnBeginImplFrameDeadline();
1182 EXPECT_ACTION_UPDATE_STATE(
1183 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
1184 EXPECT_ACTION_UPDATE_STATE( 1167 EXPECT_ACTION_UPDATE_STATE(
1185 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 1168 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
1186 } 1169 }
1187 1170
1188 TEST(SchedulerStateMachineTest, TestFullCycleWithCommitRequestInbetween) { 1171 TEST(SchedulerStateMachineTest, TestFullCycleWithCommitRequestInbetween) {
1189 SchedulerSettings default_scheduler_settings; 1172 SchedulerSettings default_scheduler_settings;
1190 StateMachine state(default_scheduler_settings); 1173 StateMachine state(default_scheduler_settings);
1191 SET_UP_STATE(state) 1174 SET_UP_STATE(state)
1192 1175
1193 // Start clean and set commit. 1176 // Start clean and set commit.
(...skipping 990 matching lines...) Expand 10 before | Expand all | Expand 10 after
2184 state.OnBeginImplFrameDeadline(); 2167 state.OnBeginImplFrameDeadline();
2185 state.OnBeginImplFrameIdle(); 2168 state.OnBeginImplFrameIdle();
2186 2169
2187 // The scheduler should begin the output surface creation now. 2170 // The scheduler should begin the output surface creation now.
2188 EXPECT_ACTION_UPDATE_STATE( 2171 EXPECT_ACTION_UPDATE_STATE(
2189 SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION); 2172 SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION);
2190 } 2173 }
2191 2174
2192 } // namespace 2175 } // namespace
2193 } // namespace cc 2176 } // 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