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

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

Issue 2386183003: Revert of cc: Remove frame queuing from the scheduler. (patchset #14 id:400001 of https://coderevie… (Closed)
Patch Set: fix revert Created 4 years, 2 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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 { 65 {
66 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE, 66 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE,
67 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_BEGIN_FRAME, 67 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_BEGIN_FRAME,
68 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE, 68 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE,
69 }; 69 };
70 70
71 const SchedulerStateMachine::BeginMainFrameState begin_main_frame_states[] = { 71 const SchedulerStateMachine::BeginMainFrameState begin_main_frame_states[] = {
72 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_IDLE, 72 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_IDLE,
73 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_SENT, 73 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_SENT,
74 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_STARTED, 74 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_STARTED,
75 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_READY_TO_COMMIT}; 75 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_READY_TO_COMMIT,
76 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_WAITING_FOR_ACTIVATION,
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
78 class StateMachine : public SchedulerStateMachine { 80 class StateMachine : public SchedulerStateMachine {
79 public: 81 public:
80 explicit StateMachine(const SchedulerSettings& scheduler_settings) 82 explicit StateMachine(const SchedulerSettings& scheduler_settings)
81 : SchedulerStateMachine(scheduler_settings), 83 : SchedulerStateMachine(scheduler_settings),
82 draw_result_for_test_(DRAW_SUCCESS) {} 84 draw_result_for_test_(DRAW_SUCCESS) {}
83 85
84 void CreateAndInitializeCompositorFrameSinkWithActivatedCommit() { 86 void CreateAndInitializeCompositorFrameSinkWithActivatedCommit() {
85 DidCreateAndInitializeCompositorFrameSink(); 87 DidCreateAndInitializeCompositorFrameSink();
(...skipping 1019 matching lines...) Expand 10 before | Expand all | Expand 10 after
1105 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 1107 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
1106 EXPECT_MAIN_FRAME_STATE(SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_SENT); 1108 EXPECT_MAIN_FRAME_STATE(SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_SENT);
1107 EXPECT_FALSE(state.NeedsCommit()); 1109 EXPECT_FALSE(state.NeedsCommit());
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);
1117
1115 // Commit. 1118 // Commit.
1116 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 1119 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
1117 // Commit always calls NotifyReadyToActivate in this mode.
1118 state.NotifyReadyToActivate();
1119 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE);
1120 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1121 1120
1122 // No draw because we haven't received NotifyReadyToDraw yet. 1121 // Now commit should wait for activation.
1123 state.OnBeginImplFrameDeadline(); 1122 EXPECT_MAIN_FRAME_STATE(
1124 EXPECT_TRUE(state.active_tree_needs_first_draw()); 1123 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_WAITING_FOR_ACTIVATION);
1125 EXPECT_TRUE(state.needs_redraw());
1126 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1127 1124
1128 // Can't BeginMainFrame yet since last commit hasn't been drawn yet. 1125 // No activation yet, so this commit is not drawn yet. Force to draw this
1126 // frame, and still block BeginMainFrame.
1127 state.SetNeedsRedraw(true);
1129 state.SetNeedsBeginMainFrame(); 1128 state.SetNeedsBeginMainFrame();
1130 state.OnBeginImplFrame();
1131 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1132
1133 // Now call ready to draw which will allow the draw to happen and
1134 // BeginMainFrame to be sent.
1135 state.NotifyReadyToDraw();
1136 state.OnBeginImplFrameDeadline();
1137 EXPECT_ACTION_UPDATE_STATE(
1138 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
1139 // Swap throttled from this point.
1140 state.DidSwapBuffers();
1141 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1142
1143 // Can't BeginMainFrame yet since we're swap throttled.
1144 state.OnBeginImplFrame();
1145 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1146
1147 // Swap ack unblocks BeginMainFrame.
1148 state.DidSwapBuffersComplete();
1149 EXPECT_ACTION_UPDATE_STATE(
1150 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
1151 state.NotifyBeginMainFrameStarted();
1152 state.NotifyReadyToCommit();
1153 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
1154 state.NotifyReadyToActivate();
1155 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE);
1156 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1157
1158 // Draw the newly activated tree.
1159 state.NotifyReadyToDraw();
1160 state.OnBeginImplFrameDeadline(); 1129 state.OnBeginImplFrameDeadline();
1161 EXPECT_ACTION_UPDATE_STATE( 1130 EXPECT_ACTION_UPDATE_STATE(
1162 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 1131 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
1163 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1132 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1133
1134 // Cannot BeginMainFrame yet since last commit is not yet activated and drawn.
1135 state.OnBeginImplFrame();
1136 EXPECT_MAIN_FRAME_STATE(
1137 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_WAITING_FOR_ACTIVATION);
1138 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1139
1140 // Now activate sync tree.
1141 state.NotifyReadyToActivate();
1142 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE);
1143 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1144 EXPECT_TRUE(state.active_tree_needs_first_draw());
1145 EXPECT_TRUE(state.needs_redraw());
1146 EXPECT_MAIN_FRAME_STATE(
1147 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_WAITING_FOR_DRAW);
1148
1149 // Swap throttled. Do not draw.
1150 state.DidSwapBuffers();
1151 state.OnBeginImplFrameDeadline();
1152 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1153 state.DidSwapBuffersComplete();
1154
1155 // Haven't draw since last commit, do not begin new main frame.
1156 state.OnBeginImplFrame();
1157 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1158
1159 // At BeginImplFrame deadline, draw. This draws unblocks BeginMainFrame.
1160 state.OnBeginImplFrameDeadline();
1161 EXPECT_ACTION_UPDATE_STATE(
1162 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
1163 state.DidSwapBuffers();
1164 state.DidSwapBuffersComplete();
1165
1166 // Now will be able to start main frame.
1167 EXPECT_MAIN_FRAME_STATE(SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_IDLE);
1168 EXPECT_FALSE(state.needs_redraw());
1169 EXPECT_ACTION_UPDATE_STATE(
1170 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
1164 } 1171 }
1165 1172
1166 TEST(SchedulerStateMachineTest, TestFullCycleWithCommitRequestInbetween) { 1173 TEST(SchedulerStateMachineTest, TestFullCycleWithCommitRequestInbetween) {
1167 SchedulerSettings default_scheduler_settings; 1174 SchedulerSettings default_scheduler_settings;
1168 StateMachine state(default_scheduler_settings); 1175 StateMachine state(default_scheduler_settings);
1169 SET_UP_STATE(state) 1176 SET_UP_STATE(state)
1170 1177
1171 // Start clean and set commit. 1178 // Start clean and set commit.
1172 state.SetNeedsBeginMainFrame(); 1179 state.SetNeedsBeginMainFrame();
1173 1180
(...skipping 997 matching lines...) Expand 10 before | Expand all | Expand 10 after
2171 state.OnBeginImplFrameDeadline(); 2178 state.OnBeginImplFrameDeadline();
2172 state.OnBeginImplFrameIdle(); 2179 state.OnBeginImplFrameIdle();
2173 2180
2174 // The scheduler should begin the CompositorFrameSink creation now. 2181 // The scheduler should begin the CompositorFrameSink creation now.
2175 EXPECT_ACTION_UPDATE_STATE( 2182 EXPECT_ACTION_UPDATE_STATE(
2176 SchedulerStateMachine::ACTION_BEGIN_COMPOSITOR_FRAME_SINK_CREATION); 2183 SchedulerStateMachine::ACTION_BEGIN_COMPOSITOR_FRAME_SINK_CREATION);
2177 } 2184 }
2178 2185
2179 } // namespace 2186 } // namespace
2180 } // namespace cc 2187 } // 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