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

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

Issue 15058004: cc: Rename VSync to BeginFrame (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Rebase Created 7 years, 7 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 "cc/scheduler/scheduler.h" 7 #include "cc/scheduler/scheduler.h"
8 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
9 9
10 namespace cc { 10 namespace cc {
(...skipping 17 matching lines...) Expand all
28 28
29 bool NeedsCommit() const { return needs_commit_; } 29 bool NeedsCommit() const { return needs_commit_; }
30 30
31 void SetNeedsRedraw(bool b) { needs_redraw_ = b; } 31 void SetNeedsRedraw(bool b) { needs_redraw_ = b; }
32 bool NeedsRedraw() const { return needs_redraw_; } 32 bool NeedsRedraw() const { return needs_redraw_; }
33 33
34 void SetNeedsForcedRedraw(bool b) { needs_forced_redraw_ = b; } 34 void SetNeedsForcedRedraw(bool b) { needs_forced_redraw_ = b; }
35 bool NeedsForcedRedraw() const { return needs_forced_redraw_; } 35 bool NeedsForcedRedraw() const { return needs_forced_redraw_; }
36 36
37 bool CanDraw() const { return can_draw_; } 37 bool CanDraw() const { return can_draw_; }
38 bool InsideVSync() const { return inside_vsync_; }
39 bool Visible() const { return visible_; } 38 bool Visible() const { return visible_; }
40 }; 39 };
41 40
42 TEST(SchedulerStateMachineTest, TestNextActionBeginsFrameIfNeeded) { 41 TEST(SchedulerStateMachineTest, TestNextActionBeginsMainFrameIfNeeded) {
43 SchedulerSettings default_scheduler_settings; 42 SchedulerSettings default_scheduler_settings;
44 43
45 // If no commit needed, do nothing. 44 // If no commit needed, do nothing.
46 { 45 {
47 StateMachine state(default_scheduler_settings); 46 StateMachine state(default_scheduler_settings);
48 state.SetCanStart(); 47 state.SetCanStart();
49 state.UpdateState(state.NextAction()); 48 state.UpdateState(state.NextAction());
50 state.DidCreateAndInitializeOutputSurface(); 49 state.DidCreateAndInitializeOutputSurface();
51 state.SetCommitState(SchedulerStateMachine::COMMIT_STATE_IDLE); 50 state.SetCommitState(SchedulerStateMachine::COMMIT_STATE_IDLE);
52 state.SetNeedsRedraw(false); 51 state.SetNeedsRedraw(false);
53 state.SetVisible(true); 52 state.SetVisible(true);
54 53
55 EXPECT_FALSE(state.VSyncCallbackNeeded()); 54 EXPECT_FALSE(state.BeginFrameNeededByImplThread());
56 55
57 state.DidLeaveVSync(); 56 state.DidLeaveBeginFrame();
58 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); 57 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction());
59 EXPECT_FALSE(state.VSyncCallbackNeeded()); 58 EXPECT_FALSE(state.BeginFrameNeededByImplThread());
60 state.DidEnterVSync(); 59 state.DidEnterBeginFrame();
61 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); 60 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction());
62 } 61 }
63 62
64 // If commit requested but can_begin_frame is still false, do nothing. 63 // If commit requested but can_start is still false, do nothing.
65 { 64 {
66 StateMachine state(default_scheduler_settings); 65 StateMachine state(default_scheduler_settings);
67 state.SetCommitState(SchedulerStateMachine::COMMIT_STATE_IDLE); 66 state.SetCommitState(SchedulerStateMachine::COMMIT_STATE_IDLE);
68 state.SetNeedsRedraw(false); 67 state.SetNeedsRedraw(false);
69 state.SetVisible(true); 68 state.SetVisible(true);
70 69
71 EXPECT_FALSE(state.VSyncCallbackNeeded()); 70 EXPECT_FALSE(state.BeginFrameNeededByImplThread());
72 71
73 state.DidLeaveVSync(); 72 state.DidLeaveBeginFrame();
74 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); 73 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction());
75 EXPECT_FALSE(state.VSyncCallbackNeeded()); 74 EXPECT_FALSE(state.BeginFrameNeededByImplThread());
76 state.DidEnterVSync(); 75 state.DidEnterBeginFrame();
77 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); 76 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction());
78 } 77 }
79 78
80 // If commit requested, begin a frame. 79 // If commit requested, begin a main frame.
81 { 80 {
82 StateMachine state(default_scheduler_settings); 81 StateMachine state(default_scheduler_settings);
83 state.SetCommitState(SchedulerStateMachine::COMMIT_STATE_IDLE); 82 state.SetCommitState(SchedulerStateMachine::COMMIT_STATE_IDLE);
84 state.SetCanStart(); 83 state.SetCanStart();
85 state.SetNeedsRedraw(false); 84 state.SetNeedsRedraw(false);
86 state.SetVisible(true); 85 state.SetVisible(true);
87 EXPECT_FALSE(state.VSyncCallbackNeeded()); 86 EXPECT_FALSE(state.BeginFrameNeededByImplThread());
88 } 87 }
89 88
90 // Begin the frame, make sure needs_commit and commit_state update correctly. 89 // Begin the frame, make sure needs_commit and commit_state update correctly.
91 { 90 {
92 StateMachine state(default_scheduler_settings); 91 StateMachine state(default_scheduler_settings);
93 state.SetCanStart(); 92 state.SetCanStart();
94 state.UpdateState(state.NextAction()); 93 state.UpdateState(state.NextAction());
95 state.DidCreateAndInitializeOutputSurface(); 94 state.DidCreateAndInitializeOutputSurface();
96 state.SetVisible(true); 95 state.SetVisible(true);
97 state.UpdateState(SchedulerStateMachine::ACTION_BEGIN_FRAME); 96 state.UpdateState(
97 SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD);
98 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, 98 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS,
99 state.CommitState()); 99 state.CommitState());
100 EXPECT_FALSE(state.NeedsCommit()); 100 EXPECT_FALSE(state.NeedsCommit());
101 EXPECT_FALSE(state.VSyncCallbackNeeded()); 101 EXPECT_FALSE(state.BeginFrameNeededByImplThread());
102 } 102 }
103 } 103 }
104 104
105 TEST(SchedulerStateMachineTest, TestSetForcedRedrawDoesNotSetsNormalRedraw) { 105 TEST(SchedulerStateMachineTest, TestSetForcedRedrawDoesNotSetsNormalRedraw) {
106 SchedulerSettings default_scheduler_settings; 106 SchedulerSettings default_scheduler_settings;
107 SchedulerStateMachine state(default_scheduler_settings); 107 SchedulerStateMachine state(default_scheduler_settings);
108 state.SetCanDraw(true); 108 state.SetCanDraw(true);
109 state.SetNeedsForcedRedraw(); 109 state.SetNeedsForcedRedraw();
110 EXPECT_FALSE(state.RedrawPending()); 110 EXPECT_FALSE(state.RedrawPending());
111 EXPECT_TRUE(state.VSyncCallbackNeeded()); 111 EXPECT_TRUE(state.BeginFrameNeededByImplThread());
112 } 112 }
113 113
114 TEST(SchedulerStateMachineTest, 114 TEST(SchedulerStateMachineTest,
115 TestFailedDrawSetsNeedsCommitAndDoesNotDrawAgain) { 115 TestFailedDrawSetsNeedsCommitAndDoesNotDrawAgain) {
116 SchedulerSettings default_scheduler_settings; 116 SchedulerSettings default_scheduler_settings;
117 SchedulerStateMachine state(default_scheduler_settings); 117 SchedulerStateMachine state(default_scheduler_settings);
118 state.SetCanStart(); 118 state.SetCanStart();
119 state.UpdateState(state.NextAction()); 119 state.UpdateState(state.NextAction());
120 state.DidCreateAndInitializeOutputSurface(); 120 state.DidCreateAndInitializeOutputSurface();
121 state.SetVisible(true); 121 state.SetVisible(true);
122 state.SetCanDraw(true); 122 state.SetCanDraw(true);
123 state.SetNeedsRedraw(); 123 state.SetNeedsRedraw();
124 EXPECT_TRUE(state.RedrawPending()); 124 EXPECT_TRUE(state.RedrawPending());
125 EXPECT_TRUE(state.VSyncCallbackNeeded()); 125 EXPECT_TRUE(state.BeginFrameNeededByImplThread());
126 state.DidEnterVSync(); 126 state.DidEnterBeginFrame();
127 127
128 // We're drawing now. 128 // We're drawing now.
129 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.NextAction()); 129 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.NextAction());
130 state.UpdateState(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE); 130 state.UpdateState(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE);
131 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); 131 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction());
132 EXPECT_FALSE(state.RedrawPending()); 132 EXPECT_FALSE(state.RedrawPending());
133 EXPECT_FALSE(state.CommitPending()); 133 EXPECT_FALSE(state.CommitPending());
134 134
135 // Failing the draw makes us require a commit. 135 // Failing the draw makes us require a commit.
136 state.DidDrawIfPossibleCompleted(false); 136 state.DidDrawIfPossibleCompleted(false);
137 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_FRAME, state.NextAction()); 137 EXPECT_EQ(SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD,
138 state.UpdateState(SchedulerStateMachine::ACTION_BEGIN_FRAME); 138 state.NextAction());
139 state.UpdateState(
140 SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD);
139 EXPECT_TRUE(state.RedrawPending()); 141 EXPECT_TRUE(state.RedrawPending());
140 EXPECT_TRUE(state.CommitPending()); 142 EXPECT_TRUE(state.CommitPending());
141 } 143 }
142 144
143 TEST(SchedulerStateMachineTest, 145 TEST(SchedulerStateMachineTest,
144 TestsetNeedsRedrawDuringFailedDrawDoesNotRemoveNeedsRedraw) { 146 TestsetNeedsRedrawDuringFailedDrawDoesNotRemoveNeedsRedraw) {
145 SchedulerSettings default_scheduler_settings; 147 SchedulerSettings default_scheduler_settings;
146 SchedulerStateMachine state(default_scheduler_settings); 148 SchedulerStateMachine state(default_scheduler_settings);
147 state.SetCanStart(); 149 state.SetCanStart();
148 state.UpdateState(state.NextAction()); 150 state.UpdateState(state.NextAction());
149 state.DidCreateAndInitializeOutputSurface(); 151 state.DidCreateAndInitializeOutputSurface();
150 152
151 state.SetVisible(true); 153 state.SetVisible(true);
152 state.SetCanDraw(true); 154 state.SetCanDraw(true);
153 state.SetNeedsRedraw(); 155 state.SetNeedsRedraw();
154 EXPECT_TRUE(state.RedrawPending()); 156 EXPECT_TRUE(state.RedrawPending());
155 EXPECT_TRUE(state.VSyncCallbackNeeded()); 157 EXPECT_TRUE(state.BeginFrameNeededByImplThread());
156 state.DidEnterVSync(); 158 state.DidEnterBeginFrame();
157 159
158 // We're drawing now. 160 // We're drawing now.
159 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.NextAction()); 161 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.NextAction());
160 state.UpdateState(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE); 162 state.UpdateState(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE);
161 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); 163 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction());
162 EXPECT_FALSE(state.RedrawPending()); 164 EXPECT_FALSE(state.RedrawPending());
163 EXPECT_FALSE(state.CommitPending()); 165 EXPECT_FALSE(state.CommitPending());
164 166
165 // While still in the same vsync callback, set needs redraw again. 167 // While still in the same begin frame callback on the main thread,
166 // This should not redraw. 168 // set needs redraw again. This should not redraw.
167 state.SetNeedsRedraw(); 169 state.SetNeedsRedraw();
168 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); 170 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction());
169 171
170 // Failing the draw makes us require a commit. 172 // Failing the draw makes us require a commit.
171 state.DidDrawIfPossibleCompleted(false); 173 state.DidDrawIfPossibleCompleted(false);
172 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_FRAME, state.NextAction()); 174 EXPECT_EQ(SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD,
175 state.NextAction());
173 EXPECT_TRUE(state.RedrawPending()); 176 EXPECT_TRUE(state.RedrawPending());
174 } 177 }
175 178
176 TEST(SchedulerStateMachineTest, 179 TEST(SchedulerStateMachineTest,
177 TestCommitAfterFailedDrawAllowsDrawInSameFrame) { 180 TestCommitAfterFailedDrawAllowsDrawInSameFrame) {
178 SchedulerSettings default_scheduler_settings; 181 SchedulerSettings default_scheduler_settings;
179 SchedulerStateMachine state(default_scheduler_settings); 182 SchedulerStateMachine state(default_scheduler_settings);
180 state.SetCanStart(); 183 state.SetCanStart();
181 state.UpdateState(state.NextAction()); 184 state.UpdateState(state.NextAction());
182 state.DidCreateAndInitializeOutputSurface(); 185 state.DidCreateAndInitializeOutputSurface();
183 state.SetVisible(true); 186 state.SetVisible(true);
184 state.SetCanDraw(true); 187 state.SetCanDraw(true);
185 188
186 // Start a commit. 189 // Start a commit.
187 state.SetNeedsCommit(); 190 state.SetNeedsCommit();
188 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_FRAME, state.NextAction()); 191 EXPECT_EQ(SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD,
189 state.UpdateState(SchedulerStateMachine::ACTION_BEGIN_FRAME); 192 state.NextAction());
193 state.UpdateState(
194 SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD);
190 EXPECT_TRUE(state.CommitPending()); 195 EXPECT_TRUE(state.CommitPending());
191 196
192 // Then initiate a draw. 197 // Then initiate a draw.
193 state.SetNeedsRedraw(); 198 state.SetNeedsRedraw();
194 EXPECT_TRUE(state.VSyncCallbackNeeded()); 199 EXPECT_TRUE(state.BeginFrameNeededByImplThread());
195 state.DidEnterVSync(); 200 state.DidEnterBeginFrame();
196 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.NextAction()); 201 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.NextAction());
197 EXPECT_TRUE(state.RedrawPending()); 202 EXPECT_TRUE(state.RedrawPending());
198 203
199 // Fail the draw. 204 // Fail the draw.
200 state.UpdateState(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE); 205 state.UpdateState(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE);
201 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); 206 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction());
202 state.DidDrawIfPossibleCompleted(false); 207 state.DidDrawIfPossibleCompleted(false);
203 EXPECT_TRUE(state.RedrawPending()); 208 EXPECT_TRUE(state.RedrawPending());
204 // But the commit is ongoing. 209 // But the commit is ongoing.
205 EXPECT_TRUE(state.CommitPending()); 210 EXPECT_TRUE(state.CommitPending());
206 211
207 // Finish the commit. 212 // Finish the commit.
208 state.BeginFrameComplete(); 213 state.FinishCommit();
209 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction()); 214 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction());
210 state.UpdateState(SchedulerStateMachine::ACTION_COMMIT); 215 state.UpdateState(SchedulerStateMachine::ACTION_COMMIT);
211 EXPECT_TRUE(state.RedrawPending()); 216 EXPECT_TRUE(state.RedrawPending());
212 217
213 // And we should be allowed to draw again. 218 // And we should be allowed to draw again.
214 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.NextAction()); 219 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.NextAction());
215 } 220 }
216 221
217 TEST(SchedulerStateMachineTest, 222 TEST(SchedulerStateMachineTest,
218 TestCommitAfterFailedAndSuccessfulDrawDoesNotAllowDrawInSameFrame) { 223 TestCommitAfterFailedAndSuccessfulDrawDoesNotAllowDrawInSameFrame) {
219 SchedulerSettings default_scheduler_settings; 224 SchedulerSettings default_scheduler_settings;
220 SchedulerStateMachine state(default_scheduler_settings); 225 SchedulerStateMachine state(default_scheduler_settings);
221 state.SetCanStart(); 226 state.SetCanStart();
222 state.UpdateState(state.NextAction()); 227 state.UpdateState(state.NextAction());
223 state.DidCreateAndInitializeOutputSurface(); 228 state.DidCreateAndInitializeOutputSurface();
224 state.SetVisible(true); 229 state.SetVisible(true);
225 state.SetCanDraw(true); 230 state.SetCanDraw(true);
226 231
227 // Start a commit. 232 // Start a commit.
228 state.SetNeedsCommit(); 233 state.SetNeedsCommit();
229 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_FRAME, state.NextAction()); 234 EXPECT_EQ(SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD,
230 state.UpdateState(SchedulerStateMachine::ACTION_BEGIN_FRAME); 235 state.NextAction());
236 state.UpdateState(
237 SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD);
231 EXPECT_TRUE(state.CommitPending()); 238 EXPECT_TRUE(state.CommitPending());
232 239
233 // Then initiate a draw. 240 // Then initiate a draw.
234 state.SetNeedsRedraw(); 241 state.SetNeedsRedraw();
235 EXPECT_TRUE(state.VSyncCallbackNeeded()); 242 EXPECT_TRUE(state.BeginFrameNeededByImplThread());
236 state.DidEnterVSync(); 243 state.DidEnterBeginFrame();
237 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.NextAction()); 244 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.NextAction());
238 EXPECT_TRUE(state.RedrawPending()); 245 EXPECT_TRUE(state.RedrawPending());
239 246
240 // Fail the draw. 247 // Fail the draw.
241 state.UpdateState(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE); 248 state.UpdateState(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE);
242 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); 249 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction());
243 state.DidDrawIfPossibleCompleted(false); 250 state.DidDrawIfPossibleCompleted(false);
244 EXPECT_TRUE(state.RedrawPending()); 251 EXPECT_TRUE(state.RedrawPending());
245 // But the commit is ongoing. 252 // But the commit is ongoing.
246 EXPECT_TRUE(state.CommitPending()); 253 EXPECT_TRUE(state.CommitPending());
247 254
248 // Force a draw. 255 // Force a draw.
249 state.SetNeedsForcedRedraw(); 256 state.SetNeedsForcedRedraw();
250 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_FORCED, state.NextAction()); 257 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_FORCED, state.NextAction());
251 258
252 // Do the forced draw. 259 // Do the forced draw.
253 state.UpdateState(SchedulerStateMachine::ACTION_DRAW_FORCED); 260 state.UpdateState(SchedulerStateMachine::ACTION_DRAW_FORCED);
254 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); 261 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction());
255 EXPECT_FALSE(state.RedrawPending()); 262 EXPECT_FALSE(state.RedrawPending());
256 // And the commit is still ongoing. 263 // And the commit is still ongoing.
257 EXPECT_TRUE(state.CommitPending()); 264 EXPECT_TRUE(state.CommitPending());
258 265
259 // Finish the commit. 266 // Finish the commit.
260 state.BeginFrameComplete(); 267 state.FinishCommit();
261 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction()); 268 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction());
262 state.UpdateState(SchedulerStateMachine::ACTION_COMMIT); 269 state.UpdateState(SchedulerStateMachine::ACTION_COMMIT);
263 EXPECT_TRUE(state.RedrawPending()); 270 EXPECT_TRUE(state.RedrawPending());
264 271
265 // And we should not be allowed to draw again in the same frame.. 272 // And we should not be allowed to draw again in the same frame..
266 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); 273 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction());
267 } 274 }
268 275
269 TEST(SchedulerStateMachineTest, 276 TEST(SchedulerStateMachineTest,
270 TestFailedDrawsWillEventuallyForceADrawAfterTheNextCommit) { 277 TestFailedDrawsWillEventuallyForceADrawAfterTheNextCommit) {
271 SchedulerSettings default_scheduler_settings; 278 SchedulerSettings default_scheduler_settings;
272 SchedulerStateMachine state(default_scheduler_settings); 279 SchedulerStateMachine state(default_scheduler_settings);
273 state.SetCanStart(); 280 state.SetCanStart();
274 state.UpdateState(state.NextAction()); 281 state.UpdateState(state.NextAction());
275 state.DidCreateAndInitializeOutputSurface(); 282 state.DidCreateAndInitializeOutputSurface();
276 state.SetVisible(true); 283 state.SetVisible(true);
277 state.SetCanDraw(true); 284 state.SetCanDraw(true);
278 state.SetMaximumNumberOfFailedDrawsBeforeDrawIsForced(1); 285 state.SetMaximumNumberOfFailedDrawsBeforeDrawIsForced(1);
279 286
280 // Start a commit. 287 // Start a commit.
281 state.SetNeedsCommit(); 288 state.SetNeedsCommit();
282 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_FRAME, state.NextAction()); 289 EXPECT_EQ(SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD,
283 state.UpdateState(SchedulerStateMachine::ACTION_BEGIN_FRAME); 290 state.NextAction());
291 state.UpdateState(
292 SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD);
284 EXPECT_TRUE(state.CommitPending()); 293 EXPECT_TRUE(state.CommitPending());
285 294
286 // Then initiate a draw. 295 // Then initiate a draw.
287 state.SetNeedsRedraw(); 296 state.SetNeedsRedraw();
288 EXPECT_TRUE(state.VSyncCallbackNeeded()); 297 EXPECT_TRUE(state.BeginFrameNeededByImplThread());
289 state.DidEnterVSync(); 298 state.DidEnterBeginFrame();
290 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.NextAction()); 299 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.NextAction());
291 EXPECT_TRUE(state.RedrawPending()); 300 EXPECT_TRUE(state.RedrawPending());
292 301
293 // Fail the draw. 302 // Fail the draw.
294 state.UpdateState(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE); 303 state.UpdateState(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE);
295 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); 304 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction());
296 state.DidDrawIfPossibleCompleted(false); 305 state.DidDrawIfPossibleCompleted(false);
297 EXPECT_TRUE(state.RedrawPending()); 306 EXPECT_TRUE(state.RedrawPending());
298 // But the commit is ongoing. 307 // But the commit is ongoing.
299 EXPECT_TRUE(state.CommitPending()); 308 EXPECT_TRUE(state.CommitPending());
300 309
301 // Finish the commit. Note, we should not yet be forcing a draw, but should 310 // Finish the commit. Note, we should not yet be forcing a draw, but should
302 // continue the commit as usual. 311 // continue the commit as usual.
303 state.BeginFrameComplete(); 312 state.FinishCommit();
304 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction()); 313 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction());
305 state.UpdateState(SchedulerStateMachine::ACTION_COMMIT); 314 state.UpdateState(SchedulerStateMachine::ACTION_COMMIT);
306 EXPECT_TRUE(state.RedrawPending()); 315 EXPECT_TRUE(state.RedrawPending());
307 316
308 // The redraw should be forced in this case. 317 // The redraw should be forced in this case.
309 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_FORCED, state.NextAction()); 318 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_FORCED, state.NextAction());
310 } 319 }
311 320
312 TEST(SchedulerStateMachineTest, TestFailedDrawIsRetriedNextVSync) { 321 TEST(SchedulerStateMachineTest,
322 TestFailedDrawIsRetriedInNextBeginFrameForImplThread) {
313 SchedulerSettings default_scheduler_settings; 323 SchedulerSettings default_scheduler_settings;
314 SchedulerStateMachine state(default_scheduler_settings); 324 SchedulerStateMachine state(default_scheduler_settings);
315 state.SetCanStart(); 325 state.SetCanStart();
316 state.UpdateState(state.NextAction()); 326 state.UpdateState(state.NextAction());
317 state.DidCreateAndInitializeOutputSurface(); 327 state.DidCreateAndInitializeOutputSurface();
318 state.SetVisible(true); 328 state.SetVisible(true);
319 state.SetCanDraw(true); 329 state.SetCanDraw(true);
320 330
321 // Start a draw. 331 // Start a draw.
322 state.SetNeedsRedraw(); 332 state.SetNeedsRedraw();
323 EXPECT_TRUE(state.VSyncCallbackNeeded()); 333 EXPECT_TRUE(state.BeginFrameNeededByImplThread());
324 state.DidEnterVSync(); 334 state.DidEnterBeginFrame();
325 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.NextAction()); 335 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.NextAction());
326 EXPECT_TRUE(state.RedrawPending()); 336 EXPECT_TRUE(state.RedrawPending());
327 337
328 // Fail the draw. 338 // Fail the draw.
329 state.UpdateState(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE); 339 state.UpdateState(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE);
330 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); 340 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction());
331 state.DidDrawIfPossibleCompleted(false); 341 state.DidDrawIfPossibleCompleted(false);
332 EXPECT_TRUE(state.RedrawPending()); 342 EXPECT_TRUE(state.RedrawPending());
333 343
334 // We should not be trying to draw again now, but we have a commit pending. 344 // We should not be trying to draw again now, but we have a commit pending.
335 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_FRAME, state.NextAction()); 345 EXPECT_EQ(SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD,
346 state.NextAction());
336 347
337 state.DidLeaveVSync(); 348 state.DidLeaveBeginFrame();
338 EXPECT_TRUE(state.VSyncCallbackNeeded()); 349 EXPECT_TRUE(state.BeginFrameNeededByImplThread());
339 state.DidEnterVSync(); 350 state.DidEnterBeginFrame();
340 351
341 // We should try draw again in the next vsync. 352 // We should try to draw again in the next begin frame on the impl thread.
342 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.NextAction()); 353 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.NextAction());
343 } 354 }
344 355
345 TEST(SchedulerStateMachineTest, TestDoestDrawTwiceInSameFrame) { 356 TEST(SchedulerStateMachineTest, TestDoestDrawTwiceInSameFrame) {
346 SchedulerSettings default_scheduler_settings; 357 SchedulerSettings default_scheduler_settings;
347 SchedulerStateMachine state(default_scheduler_settings); 358 SchedulerStateMachine state(default_scheduler_settings);
348 state.SetCanStart(); 359 state.SetCanStart();
349 state.UpdateState(state.NextAction()); 360 state.UpdateState(state.NextAction());
350 state.DidCreateAndInitializeOutputSurface(); 361 state.DidCreateAndInitializeOutputSurface();
351 state.SetVisible(true); 362 state.SetVisible(true);
352 state.SetCanDraw(true); 363 state.SetCanDraw(true);
353 state.SetNeedsRedraw(); 364 state.SetNeedsRedraw();
354 EXPECT_TRUE(state.VSyncCallbackNeeded()); 365 EXPECT_TRUE(state.BeginFrameNeededByImplThread());
355 state.DidEnterVSync(); 366 state.DidEnterBeginFrame();
356 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.NextAction()); 367 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.NextAction());
357 state.UpdateState(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE); 368 state.UpdateState(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE);
358 369
359 // While still in the same vsync callback, set needs redraw again. 370 // While still in the same begin frame for the impl thread, set needs redraw
360 // This should not redraw. 371 // again. This should not redraw.
361 state.SetNeedsRedraw(); 372 state.SetNeedsRedraw();
362 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); 373 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction());
363 374
364 // Move to another frame. This should now draw. 375 // Move to another frame. This should now draw.
365 state.DidDrawIfPossibleCompleted(true); 376 state.DidDrawIfPossibleCompleted(true);
366 state.DidLeaveVSync(); 377 state.DidLeaveBeginFrame();
367 EXPECT_TRUE(state.VSyncCallbackNeeded()); 378 EXPECT_TRUE(state.BeginFrameNeededByImplThread());
368 state.DidEnterVSync(); 379 state.DidEnterBeginFrame();
369 380
370 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.NextAction()); 381 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.NextAction());
371 state.UpdateState(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE); 382 state.UpdateState(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE);
372 state.DidDrawIfPossibleCompleted(true); 383 state.DidDrawIfPossibleCompleted(true);
373 EXPECT_FALSE(state.VSyncCallbackNeeded()); 384 EXPECT_FALSE(state.BeginFrameNeededByImplThread());
374 } 385 }
375 386
376 TEST(SchedulerStateMachineTest, TestNextActionDrawsOnVSync) { 387 TEST(SchedulerStateMachineTest, TestNextActionDrawsOnBeginFrame) {
377 SchedulerSettings default_scheduler_settings; 388 SchedulerSettings default_scheduler_settings;
378 389
379 // When not on vsync, or on vsync but not visible, don't draw. 390 // When not in BeginFrame, or in BeginFrame but not visible,
391 // don't draw.
380 size_t num_commit_states = 392 size_t num_commit_states =
381 sizeof(all_commit_states) / sizeof(SchedulerStateMachine::CommitState); 393 sizeof(all_commit_states) / sizeof(SchedulerStateMachine::CommitState);
382 for (size_t i = 0; i < num_commit_states; ++i) { 394 for (size_t i = 0; i < num_commit_states; ++i) {
383 for (size_t j = 0; j < 2; ++j) { 395 for (size_t j = 0; j < 2; ++j) {
384 StateMachine state(default_scheduler_settings); 396 StateMachine state(default_scheduler_settings);
385 state.SetCanStart(); 397 state.SetCanStart();
386 state.UpdateState(state.NextAction()); 398 state.UpdateState(state.NextAction());
387 state.DidCreateAndInitializeOutputSurface(); 399 state.DidCreateAndInitializeOutputSurface();
388 state.SetCommitState(all_commit_states[i]); 400 state.SetCommitState(all_commit_states[i]);
389 bool visible = j; 401 bool visible = j;
390 if (!visible) { 402 if (!visible) {
391 state.DidEnterVSync(); 403 state.DidEnterBeginFrame();
392 state.SetVisible(false); 404 state.SetVisible(false);
393 } else { 405 } else {
394 state.SetVisible(true); 406 state.SetVisible(true);
395 } 407 }
396 408
397 // Case 1: needs_commit=false 409 // Case 1: needs_commit=false
398 EXPECT_NE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, 410 EXPECT_NE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE,
399 state.NextAction()); 411 state.NextAction());
400 412
401 // Case 2: needs_commit=true 413 // Case 2: needs_commit=true
402 state.SetNeedsCommit(); 414 state.SetNeedsCommit();
403 EXPECT_NE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, 415 EXPECT_NE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE,
404 state.NextAction()); 416 state.NextAction());
405 } 417 }
406 } 418 }
407 419
408 // When on vsync, or not on vsync but needs_forced_dedraw set, should always 420 // When in BeginFrame, or not in BeginFrame but needs_forced_dedraw
409 // draw except if you're ready to commit, in which case commit. 421 // set, should always draw except if you're ready to commit, in which case
422 // commit.
410 for (size_t i = 0; i < num_commit_states; ++i) { 423 for (size_t i = 0; i < num_commit_states; ++i) {
411 for (size_t j = 0; j < 2; ++j) { 424 for (size_t j = 0; j < 2; ++j) {
412 StateMachine state(default_scheduler_settings); 425 StateMachine state(default_scheduler_settings);
413 state.SetCanStart(); 426 state.SetCanStart();
414 state.UpdateState(state.NextAction()); 427 state.UpdateState(state.NextAction());
415 state.DidCreateAndInitializeOutputSurface(); 428 state.DidCreateAndInitializeOutputSurface();
416 state.SetCanDraw(true); 429 state.SetCanDraw(true);
417 state.SetCommitState(all_commit_states[i]); 430 state.SetCommitState(all_commit_states[i]);
418 bool forced_draw = j; 431 bool forced_draw = j;
419 if (!forced_draw) { 432 if (!forced_draw) {
420 state.DidEnterVSync(); 433 state.DidEnterBeginFrame();
421 state.SetNeedsRedraw(true); 434 state.SetNeedsRedraw(true);
422 state.SetVisible(true); 435 state.SetVisible(true);
423 } else { 436 } else {
424 state.SetNeedsForcedRedraw(true); 437 state.SetNeedsForcedRedraw(true);
425 } 438 }
426 439
427 SchedulerStateMachine::Action expected_action; 440 SchedulerStateMachine::Action expected_action;
428 if (all_commit_states[i] != 441 if (all_commit_states[i] !=
429 SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT) { 442 SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT) {
430 expected_action = 443 expected_action =
431 forced_draw ? SchedulerStateMachine::ACTION_DRAW_FORCED 444 forced_draw ? SchedulerStateMachine::ACTION_DRAW_FORCED
432 : SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE; 445 : SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE;
433 } else { 446 } else {
434 expected_action = SchedulerStateMachine::ACTION_COMMIT; 447 expected_action = SchedulerStateMachine::ACTION_COMMIT;
435 } 448 }
436 449
437 // Case 1: needs_commit=false. 450 // Case 1: needs_commit=false.
438 EXPECT_TRUE(state.VSyncCallbackNeeded()); 451 EXPECT_TRUE(state.BeginFrameNeededByImplThread());
439 EXPECT_EQ(expected_action, state.NextAction()); 452 EXPECT_EQ(expected_action, state.NextAction());
440 453
441 // Case 2: needs_commit=true. 454 // Case 2: needs_commit=true.
442 state.SetNeedsCommit(); 455 state.SetNeedsCommit();
443 EXPECT_TRUE(state.VSyncCallbackNeeded()); 456 EXPECT_TRUE(state.BeginFrameNeededByImplThread());
444 EXPECT_EQ(expected_action, state.NextAction()); 457 EXPECT_EQ(expected_action, state.NextAction());
445 } 458 }
446 } 459 }
447 } 460 }
448 461
449 TEST(SchedulerStateMachineTest, TestNoCommitStatesRedrawWhenInvisible) { 462 TEST(SchedulerStateMachineTest, TestNoCommitStatesRedrawWhenInvisible) {
450 SchedulerSettings default_scheduler_settings; 463 SchedulerSettings default_scheduler_settings;
451 464
452 size_t num_commit_states = 465 size_t num_commit_states =
453 sizeof(all_commit_states) / sizeof(SchedulerStateMachine::CommitState); 466 sizeof(all_commit_states) / sizeof(SchedulerStateMachine::CommitState);
454 for (size_t i = 0; i < num_commit_states; ++i) { 467 for (size_t i = 0; i < num_commit_states; ++i) {
455 // There shouldn't be any drawing regardless of vsync. 468 // There shouldn't be any drawing regardless of BeginFrame.
456 for (size_t j = 0; j < 2; ++j) { 469 for (size_t j = 0; j < 2; ++j) {
457 StateMachine state(default_scheduler_settings); 470 StateMachine state(default_scheduler_settings);
458 state.SetCanStart(); 471 state.SetCanStart();
459 state.UpdateState(state.NextAction()); 472 state.UpdateState(state.NextAction());
460 state.DidCreateAndInitializeOutputSurface(); 473 state.DidCreateAndInitializeOutputSurface();
461 state.SetCommitState(all_commit_states[i]); 474 state.SetCommitState(all_commit_states[i]);
462 state.SetVisible(false); 475 state.SetVisible(false);
463 state.SetNeedsRedraw(true); 476 state.SetNeedsRedraw(true);
464 state.SetNeedsForcedRedraw(false); 477 state.SetNeedsForcedRedraw(false);
465 if (j == 1) 478 if (j == 1)
466 state.DidEnterVSync(); 479 state.DidEnterBeginFrame();
467 480
468 // Case 1: needs_commit=false. 481 // Case 1: needs_commit=false.
469 EXPECT_NE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, 482 EXPECT_NE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE,
470 state.NextAction()); 483 state.NextAction());
471 484
472 // Case 2: needs_commit=true. 485 // Case 2: needs_commit=true.
473 state.SetNeedsCommit(); 486 state.SetNeedsCommit();
474 EXPECT_NE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, 487 EXPECT_NE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE,
475 state.NextAction()); 488 state.NextAction());
476 } 489 }
477 } 490 }
478 } 491 }
479 492
480 TEST(SchedulerStateMachineTest, TestCanRedraw_StopsDraw) { 493 TEST(SchedulerStateMachineTest, TestCanRedraw_StopsDraw) {
481 SchedulerSettings default_scheduler_settings; 494 SchedulerSettings default_scheduler_settings;
482 495
483 size_t num_commit_states = 496 size_t num_commit_states =
484 sizeof(all_commit_states) / sizeof(SchedulerStateMachine::CommitState); 497 sizeof(all_commit_states) / sizeof(SchedulerStateMachine::CommitState);
485 for (size_t i = 0; i < num_commit_states; ++i) { 498 for (size_t i = 0; i < num_commit_states; ++i) {
486 // There shouldn't be any drawing regardless of vsync. 499 // There shouldn't be any drawing regardless of BeginFrame.
487 for (size_t j = 0; j < 2; ++j) { 500 for (size_t j = 0; j < 2; ++j) {
488 StateMachine state(default_scheduler_settings); 501 StateMachine state(default_scheduler_settings);
489 state.SetCanStart(); 502 state.SetCanStart();
490 state.UpdateState(state.NextAction()); 503 state.UpdateState(state.NextAction());
491 state.DidCreateAndInitializeOutputSurface(); 504 state.DidCreateAndInitializeOutputSurface();
492 state.SetCommitState(all_commit_states[i]); 505 state.SetCommitState(all_commit_states[i]);
493 state.SetVisible(false); 506 state.SetVisible(false);
494 state.SetNeedsRedraw(true); 507 state.SetNeedsRedraw(true);
495 state.SetNeedsForcedRedraw(false); 508 state.SetNeedsForcedRedraw(false);
496 if (j == 1) 509 if (j == 1)
497 state.DidEnterVSync(); 510 state.DidEnterBeginFrame();
498 511
499 state.SetCanDraw(false); 512 state.SetCanDraw(false);
500 EXPECT_NE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, 513 EXPECT_NE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE,
501 state.NextAction()); 514 state.NextAction());
502 } 515 }
503 } 516 }
504 } 517 }
505 518
506 TEST(SchedulerStateMachineTest, 519 TEST(SchedulerStateMachineTest,
507 TestCanRedrawWithWaitingForFirstDrawMakesProgress) { 520 TestCanRedrawWithWaitingForFirstDrawMakesProgress) {
508 SchedulerSettings default_scheduler_settings; 521 SchedulerSettings default_scheduler_settings;
509 StateMachine state(default_scheduler_settings); 522 StateMachine state(default_scheduler_settings);
510 state.SetCanStart(); 523 state.SetCanStart();
511 state.UpdateState(state.NextAction()); 524 state.UpdateState(state.NextAction());
512 state.DidCreateAndInitializeOutputSurface(); 525 state.DidCreateAndInitializeOutputSurface();
513 state.SetCommitState( 526 state.SetCommitState(
514 SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW); 527 SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW);
515 state.SetNeedsCommit(); 528 state.SetNeedsCommit();
516 state.SetNeedsRedraw(true); 529 state.SetNeedsRedraw(true);
517 state.SetVisible(true); 530 state.SetVisible(true);
518 state.SetCanDraw(false); 531 state.SetCanDraw(false);
519 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_FRAME, state.NextAction()); 532 EXPECT_EQ(SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD,
533 state.NextAction());
520 } 534 }
521 535
522 TEST(SchedulerStateMachineTest, TestsetNeedsCommitIsNotLost) { 536 TEST(SchedulerStateMachineTest, TestsetNeedsCommitIsNotLost) {
523 SchedulerSettings default_scheduler_settings; 537 SchedulerSettings default_scheduler_settings;
524 StateMachine state(default_scheduler_settings); 538 StateMachine state(default_scheduler_settings);
525 state.SetCanStart(); 539 state.SetCanStart();
526 state.UpdateState(state.NextAction()); 540 state.UpdateState(state.NextAction());
527 state.DidCreateAndInitializeOutputSurface(); 541 state.DidCreateAndInitializeOutputSurface();
528 state.SetNeedsCommit(); 542 state.SetNeedsCommit();
529 state.SetVisible(true); 543 state.SetVisible(true);
530 state.SetCanDraw(true); 544 state.SetCanDraw(true);
531 545
532 // Begin the frame. 546 // Begin the frame.
533 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_FRAME, state.NextAction()); 547 EXPECT_EQ(SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD,
548 state.NextAction());
534 state.UpdateState(state.NextAction()); 549 state.UpdateState(state.NextAction());
535 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, 550 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS,
536 state.CommitState()); 551 state.CommitState());
537 552
538 // Now, while the frame is in progress, set another commit. 553 // Now, while the frame is in progress, set another commit.
539 state.SetNeedsCommit(); 554 state.SetNeedsCommit();
540 EXPECT_TRUE(state.NeedsCommit()); 555 EXPECT_TRUE(state.NeedsCommit());
541 556
542 // Let the frame finish. 557 // Let the frame finish.
543 state.BeginFrameComplete(); 558 state.FinishCommit();
544 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT, 559 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT,
545 state.CommitState()); 560 state.CommitState());
546 561
547 // Expect to commit regardless of vsync state. 562 // Expect to commit regardless of BeginFrame state.
548 state.DidLeaveVSync(); 563 state.DidLeaveBeginFrame();
549 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction()); 564 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction());
550 state.DidEnterVSync(); 565 state.DidEnterBeginFrame();
551 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction()); 566 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction());
552 567
553 // Commit and make sure we draw on next vsync 568 // Commit and make sure we draw on next BeginFrame
554 state.UpdateState(SchedulerStateMachine::ACTION_COMMIT); 569 state.UpdateState(SchedulerStateMachine::ACTION_COMMIT);
555 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.NextAction()); 570 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.NextAction());
556 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW, 571 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW,
557 state.CommitState()); 572 state.CommitState());
558 state.UpdateState(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE); 573 state.UpdateState(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE);
559 state.DidDrawIfPossibleCompleted(true); 574 state.DidDrawIfPossibleCompleted(true);
560 575
561 // Verify that another commit will begin. 576 // Verify that another commit will begin.
562 state.DidLeaveVSync(); 577 state.DidLeaveBeginFrame();
563 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_FRAME, state.NextAction()); 578 EXPECT_EQ(SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD,
579 state.NextAction());
564 } 580 }
565 581
566 TEST(SchedulerStateMachineTest, TestFullCycle) { 582 TEST(SchedulerStateMachineTest, TestFullCycle) {
567 SchedulerSettings default_scheduler_settings; 583 SchedulerSettings default_scheduler_settings;
568 StateMachine state(default_scheduler_settings); 584 StateMachine state(default_scheduler_settings);
569 state.SetCanStart(); 585 state.SetCanStart();
570 state.UpdateState(state.NextAction()); 586 state.UpdateState(state.NextAction());
571 state.DidCreateAndInitializeOutputSurface(); 587 state.DidCreateAndInitializeOutputSurface();
572 state.SetVisible(true); 588 state.SetVisible(true);
573 state.SetCanDraw(true); 589 state.SetCanDraw(true);
574 590
575 // Start clean and set commit. 591 // Start clean and set commit.
576 state.SetNeedsCommit(); 592 state.SetNeedsCommit();
577 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_FRAME, state.NextAction()); 593 EXPECT_EQ(SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD,
594 state.NextAction());
578 595
579 // Begin the frame. 596 // Begin the frame.
580 state.UpdateState(SchedulerStateMachine::ACTION_BEGIN_FRAME); 597 state.UpdateState(
598 SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD);
581 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, 599 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS,
582 state.CommitState()); 600 state.CommitState());
583 EXPECT_FALSE(state.NeedsCommit()); 601 EXPECT_FALSE(state.NeedsCommit());
584 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); 602 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction());
585 603
586 // Tell the scheduler the frame finished. 604 // Tell the scheduler the frame finished.
587 state.BeginFrameComplete(); 605 state.FinishCommit();
588 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT, 606 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT,
589 state.CommitState()); 607 state.CommitState());
590 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction()); 608 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction());
591 609
592 // Commit. 610 // Commit.
593 state.UpdateState(SchedulerStateMachine::ACTION_COMMIT); 611 state.UpdateState(SchedulerStateMachine::ACTION_COMMIT);
594 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW, 612 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW,
595 state.CommitState()); 613 state.CommitState());
596 EXPECT_TRUE(state.NeedsRedraw()); 614 EXPECT_TRUE(state.NeedsRedraw());
597 615
598 // Expect to do nothing until vsync. 616 // Expect to do nothing until BeginFrame.
599 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); 617 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction());
600 618
601 // At vsync, draw. 619 // At BeginFrame, draw.
602 state.DidEnterVSync(); 620 state.DidEnterBeginFrame();
603 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.NextAction()); 621 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.NextAction());
604 state.UpdateState(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE); 622 state.UpdateState(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE);
605 state.DidDrawIfPossibleCompleted(true); 623 state.DidDrawIfPossibleCompleted(true);
606 state.DidLeaveVSync(); 624 state.DidLeaveBeginFrame();
607 625
608 // Should be synchronized, no draw needed, no action needed. 626 // Should be synchronized, no draw needed, no action needed.
609 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState()); 627 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState());
610 EXPECT_FALSE(state.NeedsRedraw()); 628 EXPECT_FALSE(state.NeedsRedraw());
611 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); 629 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction());
612 } 630 }
613 631
614 TEST(SchedulerStateMachineTest, TestFullCycleWithCommitRequestInbetween) { 632 TEST(SchedulerStateMachineTest, TestFullCycleWithCommitRequestInbetween) {
615 SchedulerSettings default_scheduler_settings; 633 SchedulerSettings default_scheduler_settings;
616 StateMachine state(default_scheduler_settings); 634 StateMachine state(default_scheduler_settings);
617 state.SetCanStart(); 635 state.SetCanStart();
618 state.UpdateState(state.NextAction()); 636 state.UpdateState(state.NextAction());
619 state.DidCreateAndInitializeOutputSurface(); 637 state.DidCreateAndInitializeOutputSurface();
620 state.SetVisible(true); 638 state.SetVisible(true);
621 state.SetCanDraw(true); 639 state.SetCanDraw(true);
622 640
623 // Start clean and set commit. 641 // Start clean and set commit.
624 state.SetNeedsCommit(); 642 state.SetNeedsCommit();
625 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_FRAME, state.NextAction()); 643 EXPECT_EQ(SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD,
644 state.NextAction());
626 645
627 // Begin the frame. 646 // Begin the frame.
628 state.UpdateState(SchedulerStateMachine::ACTION_BEGIN_FRAME); 647 state.UpdateState(
648 SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD);
629 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, 649 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS,
630 state.CommitState()); 650 state.CommitState());
631 EXPECT_FALSE(state.NeedsCommit()); 651 EXPECT_FALSE(state.NeedsCommit());
632 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); 652 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction());
633 653
634 // Request another commit while the commit is in flight. 654 // Request another commit while the commit is in flight.
635 state.SetNeedsCommit(); 655 state.SetNeedsCommit();
636 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); 656 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction());
637 657
638 // Tell the scheduler the frame finished. 658 // Tell the scheduler the frame finished.
639 state.BeginFrameComplete(); 659 state.FinishCommit();
640 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT, 660 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT,
641 state.CommitState()); 661 state.CommitState());
642 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction()); 662 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction());
643 663
644 // Commit. 664 // Commit.
645 state.UpdateState(SchedulerStateMachine::ACTION_COMMIT); 665 state.UpdateState(SchedulerStateMachine::ACTION_COMMIT);
646 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW, 666 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW,
647 state.CommitState()); 667 state.CommitState());
648 EXPECT_TRUE(state.NeedsRedraw()); 668 EXPECT_TRUE(state.NeedsRedraw());
649 669
650 // Expect to do nothing until vsync. 670 // Expect to do nothing until BeginFrame.
651 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); 671 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction());
652 672
653 // At vsync, draw. 673 // At BeginFrame, draw.
654 state.DidEnterVSync(); 674 state.DidEnterBeginFrame();
655 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.NextAction()); 675 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.NextAction());
656 state.UpdateState(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE); 676 state.UpdateState(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE);
657 state.DidDrawIfPossibleCompleted(true); 677 state.DidDrawIfPossibleCompleted(true);
658 state.DidLeaveVSync(); 678 state.DidLeaveBeginFrame();
659 679
660 // Should be synchronized, no draw needed, no action needed. 680 // Should be synchronized, no draw needed, no action needed.
661 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState()); 681 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState());
662 EXPECT_FALSE(state.NeedsRedraw()); 682 EXPECT_FALSE(state.NeedsRedraw());
663 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_FRAME, state.NextAction()); 683 EXPECT_EQ(SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD,
684 state.NextAction());
664 } 685 }
665 686
666 TEST(SchedulerStateMachineTest, TestRequestCommitInvisible) { 687 TEST(SchedulerStateMachineTest, TestRequestCommitInvisible) {
667 SchedulerSettings default_scheduler_settings; 688 SchedulerSettings default_scheduler_settings;
668 StateMachine state(default_scheduler_settings); 689 StateMachine state(default_scheduler_settings);
669 state.SetCanStart(); 690 state.SetCanStart();
670 state.UpdateState(state.NextAction()); 691 state.UpdateState(state.NextAction());
671 state.DidCreateAndInitializeOutputSurface(); 692 state.DidCreateAndInitializeOutputSurface();
672 state.SetNeedsCommit(); 693 state.SetNeedsCommit();
673 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); 694 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction());
674 } 695 }
675 696
676 TEST(SchedulerStateMachineTest, TestGoesInvisibleBeforeBeginFrameCompletes) { 697 TEST(SchedulerStateMachineTest, TestGoesInvisibleBeforeFinishCommit) {
677 SchedulerSettings default_scheduler_settings; 698 SchedulerSettings default_scheduler_settings;
678 StateMachine state(default_scheduler_settings); 699 StateMachine state(default_scheduler_settings);
679 state.SetCanStart(); 700 state.SetCanStart();
680 state.UpdateState(state.NextAction()); 701 state.UpdateState(state.NextAction());
681 state.DidCreateAndInitializeOutputSurface(); 702 state.DidCreateAndInitializeOutputSurface();
682 state.SetVisible(true); 703 state.SetVisible(true);
683 state.SetCanDraw(true); 704 state.SetCanDraw(true);
684 705
685 // Start clean and set commit. 706 // Start clean and set commit.
686 state.SetNeedsCommit(); 707 state.SetNeedsCommit();
687 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_FRAME, state.NextAction()); 708 EXPECT_EQ(SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD,
709 state.NextAction());
688 710
689 // Begin the frame while visible. 711 // Begin the frame while visible.
690 state.UpdateState(SchedulerStateMachine::ACTION_BEGIN_FRAME); 712 state.UpdateState(
713 SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD);
691 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, 714 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS,
692 state.CommitState()); 715 state.CommitState());
693 EXPECT_FALSE(state.NeedsCommit()); 716 EXPECT_FALSE(state.NeedsCommit());
694 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); 717 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction());
695 718
696 // Become invisible and abort the BeginFrame. 719 // Become invisible and abort the main thread's begin frame.
697 state.SetVisible(false); 720 state.SetVisible(false);
698 state.BeginFrameAborted(); 721 state.BeginFrameAbortedByMainThread();
699 722
700 // We should now be back in the idle state as if we didn't start a frame at 723 // We should now be back in the idle state as if we didn't start a frame at
701 // all. 724 // all.
702 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState()); 725 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState());
703 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); 726 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction());
704 727
705 // Become visible again. 728 // Become visible again.
706 state.SetVisible(true); 729 state.SetVisible(true);
707 730
708 // We should be beginning a frame now. 731 // We should be beginning a frame now.
709 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState()); 732 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState());
710 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_FRAME, state.NextAction()); 733 EXPECT_EQ(SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD,
734 state.NextAction());
711 735
712 // Begin the frame. 736 // Begin the frame.
713 state.UpdateState(state.NextAction()); 737 state.UpdateState(state.NextAction());
714 738
715 // We should be starting the commit now. 739 // We should be starting the commit now.
716 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, 740 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS,
717 state.CommitState()); 741 state.CommitState());
718 } 742 }
719 743
720 TEST(SchedulerStateMachineTest, TestFirstContextCreation) { 744 TEST(SchedulerStateMachineTest, TestFirstContextCreation) {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
753 state.NextAction()); 777 state.NextAction());
754 state.UpdateState(state.NextAction()); 778 state.UpdateState(state.NextAction());
755 779
756 // Once context recreation begins, nothing should happen. 780 // Once context recreation begins, nothing should happen.
757 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); 781 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction());
758 782
759 // Recreate the context. 783 // Recreate the context.
760 state.DidCreateAndInitializeOutputSurface(); 784 state.DidCreateAndInitializeOutputSurface();
761 785
762 // When the context is recreated, we should begin a commit. 786 // When the context is recreated, we should begin a commit.
763 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_FRAME, state.NextAction()); 787 EXPECT_EQ(SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD,
788 state.NextAction());
764 state.UpdateState(state.NextAction()); 789 state.UpdateState(state.NextAction());
765 } 790 }
766 791
767 TEST(SchedulerStateMachineTest, 792 TEST(SchedulerStateMachineTest,
768 TestContextLostWhenIdleAndCommitRequestedWhileRecreating) { 793 TestContextLostWhenIdleAndCommitRequestedWhileRecreating) {
769 SchedulerSettings default_scheduler_settings; 794 SchedulerSettings default_scheduler_settings;
770 StateMachine state(default_scheduler_settings); 795 StateMachine state(default_scheduler_settings);
771 state.SetCanStart(); 796 state.SetCanStart();
772 state.UpdateState(state.NextAction()); 797 state.UpdateState(state.NextAction());
773 state.DidCreateAndInitializeOutputSurface(); 798 state.DidCreateAndInitializeOutputSurface();
(...skipping 12 matching lines...) Expand all
786 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); 811 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction());
787 812
788 // While context is recreating, commits shouldn't begin. 813 // While context is recreating, commits shouldn't begin.
789 state.SetNeedsCommit(); 814 state.SetNeedsCommit();
790 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); 815 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction());
791 816
792 // Recreate the context 817 // Recreate the context
793 state.DidCreateAndInitializeOutputSurface(); 818 state.DidCreateAndInitializeOutputSurface();
794 819
795 // When the context is recreated, we should begin a commit 820 // When the context is recreated, we should begin a commit
796 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_FRAME, state.NextAction()); 821 EXPECT_EQ(SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD,
822 state.NextAction());
797 state.UpdateState(state.NextAction()); 823 state.UpdateState(state.NextAction());
798 824
799 // Once the context is recreated, whether we draw should be based on 825 // Once the context is recreated, whether we draw should be based on
800 // SetCanDraw. 826 // SetCanDraw.
801 state.SetNeedsRedraw(true); 827 state.SetNeedsRedraw(true);
802 state.DidEnterVSync(); 828 state.DidEnterBeginFrame();
803 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.NextAction()); 829 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.NextAction());
804 state.SetCanDraw(false); 830 state.SetCanDraw(false);
805 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); 831 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction());
806 state.SetCanDraw(true); 832 state.SetCanDraw(true);
807 state.DidLeaveVSync(); 833 state.DidLeaveBeginFrame();
808 } 834 }
809 835
810 TEST(SchedulerStateMachineTest, TestContextLostWhileCommitInProgress) { 836 TEST(SchedulerStateMachineTest, TestContextLostWhileCommitInProgress) {
811 SchedulerSettings default_scheduler_settings; 837 SchedulerSettings default_scheduler_settings;
812 StateMachine state(default_scheduler_settings); 838 StateMachine state(default_scheduler_settings);
813 state.SetCanStart(); 839 state.SetCanStart();
814 state.UpdateState(state.NextAction()); 840 state.UpdateState(state.NextAction());
815 state.DidCreateAndInitializeOutputSurface(); 841 state.DidCreateAndInitializeOutputSurface();
816 state.SetVisible(true); 842 state.SetVisible(true);
817 state.SetCanDraw(true); 843 state.SetCanDraw(true);
818 844
819 // Get a commit in flight. 845 // Get a commit in flight.
820 state.SetNeedsCommit(); 846 state.SetNeedsCommit();
821 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_FRAME, state.NextAction()); 847 EXPECT_EQ(SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD,
848 state.NextAction());
822 state.UpdateState(state.NextAction()); 849 state.UpdateState(state.NextAction());
823 850
824 // Set damage and expect a draw. 851 // Set damage and expect a draw.
825 state.SetNeedsRedraw(true); 852 state.SetNeedsRedraw(true);
826 state.DidEnterVSync(); 853 state.DidEnterBeginFrame();
827 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.NextAction()); 854 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.NextAction());
828 state.UpdateState(state.NextAction()); 855 state.UpdateState(state.NextAction());
829 state.DidLeaveVSync(); 856 state.DidLeaveBeginFrame();
830 857
831 // Cause a lost context while the begin frame is in flight. 858 // Cause a lost context while the begin frame is in flight
859 // for the main thread.
832 state.DidLoseOutputSurface(); 860 state.DidLoseOutputSurface();
833 861
834 // Ask for another draw. Expect nothing happens. 862 // Ask for another draw. Expect nothing happens.
835 state.SetNeedsRedraw(true); 863 state.SetNeedsRedraw(true);
836 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); 864 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction());
837 865
838 // Finish the frame, and commit. 866 // Finish the frame, and commit.
839 state.BeginFrameComplete(); 867 state.FinishCommit();
840 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction()); 868 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction());
841 state.UpdateState(state.NextAction()); 869 state.UpdateState(state.NextAction());
842 870
843 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW, 871 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW,
844 state.CommitState()); 872 state.CommitState());
845 873
846 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.NextAction()); 874 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.NextAction());
847 state.UpdateState(state.NextAction()); 875 state.UpdateState(state.NextAction());
848 876
849 // Expect to be told to begin context recreation, independent of vsync state. 877 // Expect to be told to begin context recreation, independent of
850 state.DidEnterVSync(); 878 // BeginFrame state.
879 state.DidEnterBeginFrame();
851 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION, 880 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION,
852 state.NextAction()); 881 state.NextAction());
853 state.DidLeaveVSync(); 882 state.DidLeaveBeginFrame();
854 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION, 883 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION,
855 state.NextAction()); 884 state.NextAction());
856 } 885 }
857 886
858 TEST(SchedulerStateMachineTest, 887 TEST(SchedulerStateMachineTest,
859 TestContextLostWhileCommitInProgressAndAnotherCommitRequested) { 888 TestContextLostWhileCommitInProgressAndAnotherCommitRequested) {
860 SchedulerSettings default_scheduler_settings; 889 SchedulerSettings default_scheduler_settings;
861 StateMachine state(default_scheduler_settings); 890 StateMachine state(default_scheduler_settings);
862 state.SetCanStart(); 891 state.SetCanStart();
863 state.UpdateState(state.NextAction()); 892 state.UpdateState(state.NextAction());
864 state.DidCreateAndInitializeOutputSurface(); 893 state.DidCreateAndInitializeOutputSurface();
865 state.SetVisible(true); 894 state.SetVisible(true);
866 state.SetCanDraw(true); 895 state.SetCanDraw(true);
867 896
868 // Get a commit in flight. 897 // Get a commit in flight.
869 state.SetNeedsCommit(); 898 state.SetNeedsCommit();
870 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_FRAME, state.NextAction()); 899 EXPECT_EQ(SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD,
900 state.NextAction());
871 state.UpdateState(state.NextAction()); 901 state.UpdateState(state.NextAction());
872 902
873 // Set damage and expect a draw. 903 // Set damage and expect a draw.
874 state.SetNeedsRedraw(true); 904 state.SetNeedsRedraw(true);
875 state.DidEnterVSync(); 905 state.DidEnterBeginFrame();
876 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.NextAction()); 906 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.NextAction());
877 state.UpdateState(state.NextAction()); 907 state.UpdateState(state.NextAction());
878 state.DidLeaveVSync(); 908 state.DidLeaveBeginFrame();
879 909
880 // Cause a lost context while the begin frame is in flight. 910 // Cause a lost context while the begin frame is in flight
911 // for the main thread.
881 state.DidLoseOutputSurface(); 912 state.DidLoseOutputSurface();
882 913
883 // Ask for another draw and also set needs commit. Expect nothing happens. 914 // Ask for another draw and also set needs commit. Expect nothing happens.
884 state.SetNeedsRedraw(true); 915 state.SetNeedsRedraw(true);
885 state.SetNeedsCommit(); 916 state.SetNeedsCommit();
886 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); 917 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction());
887 918
888 // Finish the frame, and commit. 919 // Finish the frame, and commit.
889 state.BeginFrameComplete(); 920 state.FinishCommit();
890 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction()); 921 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction());
891 state.UpdateState(state.NextAction()); 922 state.UpdateState(state.NextAction());
892 923
893 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW, 924 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW,
894 state.CommitState()); 925 state.CommitState());
895 926
896 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.NextAction()); 927 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.NextAction());
897 state.UpdateState(state.NextAction()); 928 state.UpdateState(state.NextAction());
898 929
899 // Expect to be told to begin context recreation, independent of vsync state 930 // Expect to be told to begin context recreation, independent of
900 state.DidEnterVSync(); 931 // BeginFrame state
932 state.DidEnterBeginFrame();
901 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION, 933 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION,
902 state.NextAction()); 934 state.NextAction());
903 state.DidLeaveVSync(); 935 state.DidLeaveBeginFrame();
904 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION, 936 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION,
905 state.NextAction()); 937 state.NextAction());
906 } 938 }
907 939
908 TEST(SchedulerStateMachineTest, TestFinishAllRenderingWhileContextLost) { 940 TEST(SchedulerStateMachineTest, TestFinishAllRenderingWhileContextLost) {
909 SchedulerSettings default_scheduler_settings; 941 SchedulerSettings default_scheduler_settings;
910 StateMachine state(default_scheduler_settings); 942 StateMachine state(default_scheduler_settings);
911 state.SetCanStart(); 943 state.SetCanStart();
912 state.UpdateState(state.NextAction()); 944 state.UpdateState(state.NextAction());
913 state.DidCreateAndInitializeOutputSurface(); 945 state.DidCreateAndInitializeOutputSurface();
914 state.SetVisible(true); 946 state.SetVisible(true);
915 state.SetCanDraw(true); 947 state.SetCanDraw(true);
916 948
917 // Cause a lost context lost. 949 // Cause a lost context lost.
918 state.DidLoseOutputSurface(); 950 state.DidLoseOutputSurface();
919 951
920 // Ask a forced redraw and verify it ocurrs. 952 // Ask a forced redraw and verify it ocurrs.
921 state.SetNeedsForcedRedraw(true); 953 state.SetNeedsForcedRedraw(true);
922 state.DidEnterVSync(); 954 state.DidEnterBeginFrame();
923 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_FORCED, state.NextAction()); 955 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_FORCED, state.NextAction());
924 state.DidLeaveVSync(); 956 state.DidLeaveBeginFrame();
925 957
926 // Clear the forced redraw bit. 958 // Clear the forced redraw bit.
927 state.SetNeedsForcedRedraw(false); 959 state.SetNeedsForcedRedraw(false);
928 960
929 // Expect to be told to begin context recreation, independent of vsync state 961 // Expect to be told to begin context recreation, independent of
962 // BeginFrame state
930 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION, 963 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION,
931 state.NextAction()); 964 state.NextAction());
932 state.UpdateState(state.NextAction()); 965 state.UpdateState(state.NextAction());
933 966
934 // Ask a forced redraw and verify it ocurrs. 967 // Ask a forced redraw and verify it ocurrs.
935 state.SetNeedsForcedRedraw(true); 968 state.SetNeedsForcedRedraw(true);
936 state.DidEnterVSync(); 969 state.DidEnterBeginFrame();
937 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_FORCED, state.NextAction()); 970 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_FORCED, state.NextAction());
938 state.DidLeaveVSync(); 971 state.DidLeaveBeginFrame();
939 } 972 }
940 973
941 TEST(SchedulerStateMachineTest, DontDrawBeforeCommitAfterLostOutputSurface) { 974 TEST(SchedulerStateMachineTest, DontDrawBeforeCommitAfterLostOutputSurface) {
942 SchedulerSettings default_scheduler_settings; 975 SchedulerSettings default_scheduler_settings;
943 StateMachine state(default_scheduler_settings); 976 StateMachine state(default_scheduler_settings);
944 state.SetCanStart(); 977 state.SetCanStart();
945 state.UpdateState(state.NextAction()); 978 state.UpdateState(state.NextAction());
946 state.DidCreateAndInitializeOutputSurface(); 979 state.DidCreateAndInitializeOutputSurface();
947 state.SetVisible(true); 980 state.SetVisible(true);
948 state.SetCanDraw(true); 981 state.SetCanDraw(true);
949 982
950 state.SetNeedsRedraw(true); 983 state.SetNeedsRedraw(true);
951 984
952 // Cause a lost output surface, and restore it. 985 // Cause a lost output surface, and restore it.
953 state.DidLoseOutputSurface(); 986 state.DidLoseOutputSurface();
954 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION, 987 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION,
955 state.NextAction()); 988 state.NextAction());
956 state.UpdateState(state.NextAction()); 989 state.UpdateState(state.NextAction());
957 state.DidCreateAndInitializeOutputSurface(); 990 state.DidCreateAndInitializeOutputSurface();
958 991
959 EXPECT_FALSE(state.RedrawPending()); 992 EXPECT_FALSE(state.RedrawPending());
960 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_FRAME, state.NextAction()); 993 EXPECT_EQ(SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD,
994 state.NextAction());
961 } 995 }
962 996
963 TEST(SchedulerStateMachineTest, TestBeginFrameWhenInvisibleAndForceCommit) { 997 TEST(SchedulerStateMachineTest,
998 TestSendBeginFrameToMainThreadWhenInvisibleAndForceCommit) {
964 SchedulerSettings default_scheduler_settings; 999 SchedulerSettings default_scheduler_settings;
965 StateMachine state(default_scheduler_settings); 1000 StateMachine state(default_scheduler_settings);
966 state.SetCanStart(); 1001 state.SetCanStart();
967 state.UpdateState(state.NextAction()); 1002 state.UpdateState(state.NextAction());
968 state.DidCreateAndInitializeOutputSurface(); 1003 state.DidCreateAndInitializeOutputSurface();
969 state.SetVisible(false); 1004 state.SetVisible(false);
970 state.SetNeedsCommit(); 1005 state.SetNeedsCommit();
971 state.SetNeedsForcedCommit(); 1006 state.SetNeedsForcedCommit();
972 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_FRAME, state.NextAction()); 1007 EXPECT_EQ(SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD,
1008 state.NextAction());
973 } 1009 }
974 1010
975 TEST(SchedulerStateMachineTest, 1011 TEST(SchedulerStateMachineTest,
976 TestBeginFrameWhenCanBeginFrameFalseAndForceCommit) { 1012 TestSendBeginFrameToMainThreadWhenCanStartFalseAndForceCommit) {
977 SchedulerSettings default_scheduler_settings; 1013 SchedulerSettings default_scheduler_settings;
978 StateMachine state(default_scheduler_settings); 1014 StateMachine state(default_scheduler_settings);
979 state.SetCanStart();
980 state.UpdateState(state.NextAction());
981 state.DidCreateAndInitializeOutputSurface();
982 state.SetVisible(true); 1015 state.SetVisible(true);
983 state.SetCanDraw(true); 1016 state.SetCanDraw(true);
984 state.SetNeedsCommit(); 1017 state.SetNeedsCommit();
985 state.SetNeedsForcedCommit(); 1018 state.SetNeedsForcedCommit();
986 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_FRAME, state.NextAction()); 1019 EXPECT_EQ(SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD,
1020 state.NextAction());
987 } 1021 }
988 1022
989 TEST(SchedulerStateMachineTest, TestBeginFrameWhenCommitInProgress) { 1023 TEST(SchedulerStateMachineTest, TestFinishCommitWhenCommitInProgress) {
990 SchedulerSettings default_scheduler_settings; 1024 SchedulerSettings default_scheduler_settings;
991 StateMachine state(default_scheduler_settings); 1025 StateMachine state(default_scheduler_settings);
992 state.SetCanStart(); 1026 state.SetCanStart();
993 state.UpdateState(state.NextAction()); 1027 state.UpdateState(state.NextAction());
994 state.DidCreateAndInitializeOutputSurface(); 1028 state.DidCreateAndInitializeOutputSurface();
995 state.SetVisible(false); 1029 state.SetVisible(false);
996 state.SetCommitState(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS); 1030 state.SetCommitState(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS);
997 state.SetNeedsCommit(); 1031 state.SetNeedsCommit();
998 1032
999 state.BeginFrameComplete(); 1033 state.FinishCommit();
1000 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction()); 1034 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction());
1001 state.UpdateState(state.NextAction()); 1035 state.UpdateState(state.NextAction());
1002 1036
1003 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW, 1037 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW,
1004 state.CommitState()); 1038 state.CommitState());
1005 1039
1006 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); 1040 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction());
1007 } 1041 }
1008 1042
1009 TEST(SchedulerStateMachineTest, TestBeginFrameWhenForcedCommitInProgress) { 1043 TEST(SchedulerStateMachineTest, TestFinishCommitWhenForcedCommitInProgress) {
1010 SchedulerSettings default_scheduler_settings; 1044 SchedulerSettings default_scheduler_settings;
1011 StateMachine state(default_scheduler_settings); 1045 StateMachine state(default_scheduler_settings);
1012 state.SetCanStart(); 1046 state.SetCanStart();
1013 state.UpdateState(state.NextAction()); 1047 state.UpdateState(state.NextAction());
1014 state.DidCreateAndInitializeOutputSurface(); 1048 state.DidCreateAndInitializeOutputSurface();
1015 state.SetVisible(false); 1049 state.SetVisible(false);
1016 state.SetCommitState(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS); 1050 state.SetCommitState(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS);
1017 state.SetNeedsCommit(); 1051 state.SetNeedsCommit();
1018 state.SetNeedsForcedCommit(); 1052 state.SetNeedsForcedCommit();
1019 1053
1020 state.BeginFrameComplete(); 1054 state.FinishCommit();
1021 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction()); 1055 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction());
1022 state.UpdateState(state.NextAction()); 1056 state.UpdateState(state.NextAction());
1023 1057
1024 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_FORCED_DRAW, 1058 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_FORCED_DRAW,
1025 state.CommitState()); 1059 state.CommitState());
1026 1060
1027 // If we are waiting for forced draw then we know a begin frame is already in 1061 // If we are waiting for forced draw then we know a begin frame is already
1028 // flight. 1062 // in flight for the main thread.
1029 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); 1063 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction());
1030 } 1064 }
1031 1065
1032 TEST(SchedulerStateMachineTest, TestBeginFrameWhenContextLost) { 1066 TEST(SchedulerStateMachineTest, TestSendBeginFrameToMainThreadWhenContextLost) {
1033 SchedulerSettings default_scheduler_settings; 1067 SchedulerSettings default_scheduler_settings;
1034 StateMachine state(default_scheduler_settings); 1068 StateMachine state(default_scheduler_settings);
1035 state.SetCanStart(); 1069 state.SetCanStart();
1036 state.UpdateState(state.NextAction()); 1070 state.UpdateState(state.NextAction());
1037 state.DidCreateAndInitializeOutputSurface(); 1071 state.DidCreateAndInitializeOutputSurface();
1038 state.SetVisible(true); 1072 state.SetVisible(true);
1039 state.SetCanDraw(true); 1073 state.SetCanDraw(true);
1040 state.SetNeedsCommit(); 1074 state.SetNeedsCommit();
1041 state.SetNeedsForcedCommit(); 1075 state.SetNeedsForcedCommit();
1042 state.DidLoseOutputSurface(); 1076 state.DidLoseOutputSurface();
1043 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_FRAME, state.NextAction()); 1077 EXPECT_EQ(SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD,
1078 state.NextAction());
1044 } 1079 }
1045 1080
1046 TEST(SchedulerStateMachineTest, TestImmediateBeginFrame) { 1081 TEST(SchedulerStateMachineTest, TestImmediateFinishCommit) {
1047 SchedulerSettings default_scheduler_settings; 1082 SchedulerSettings default_scheduler_settings;
1048 StateMachine state(default_scheduler_settings); 1083 StateMachine state(default_scheduler_settings);
1049 state.SetCanStart(); 1084 state.SetCanStart();
1050 state.UpdateState(state.NextAction()); 1085 state.UpdateState(state.NextAction());
1051 state.DidCreateAndInitializeOutputSurface(); 1086 state.DidCreateAndInitializeOutputSurface();
1052 state.SetVisible(true); 1087 state.SetVisible(true);
1053 state.SetCanDraw(true); 1088 state.SetCanDraw(true);
1054 1089
1055 // Schedule a forced frame, commit it, draw it. 1090 // Schedule a forced frame, commit it, draw it.
1056 state.SetNeedsCommit(); 1091 state.SetNeedsCommit();
1057 state.SetNeedsForcedCommit(); 1092 state.SetNeedsForcedCommit();
1058 state.UpdateState(state.NextAction()); 1093 state.UpdateState(state.NextAction());
1059 state.BeginFrameComplete(); 1094 state.FinishCommit();
1060 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction()); 1095 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction());
1061 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT, 1096 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT,
1062 state.CommitState()); 1097 state.CommitState());
1063 state.UpdateState(state.NextAction()); 1098 state.UpdateState(state.NextAction());
1064 1099
1065 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_FORCED_DRAW, 1100 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_FORCED_DRAW,
1066 state.CommitState()); 1101 state.CommitState());
1067 1102
1068 state.DidEnterVSync(); 1103 state.DidEnterBeginFrame();
1069 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); 1104 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction());
1070 state.SetNeedsForcedRedraw(true); 1105 state.SetNeedsForcedRedraw(true);
1071 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_FORCED, state.NextAction()); 1106 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_FORCED, state.NextAction());
1072 state.UpdateState(state.NextAction()); 1107 state.UpdateState(state.NextAction());
1073 state.DidDrawIfPossibleCompleted(true); 1108 state.DidDrawIfPossibleCompleted(true);
1074 state.DidLeaveVSync(); 1109 state.DidLeaveBeginFrame();
1075 1110
1076 // Should be waiting for the normal begin frame. 1111 // Should be waiting for the normal begin frame from the main thread.
1077 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, 1112 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS,
1078 state.CommitState()); 1113 state.CommitState());
1079 } 1114 }
1080 1115
1081 TEST(SchedulerStateMachineTest, TestImmediateBeginFrameDuringCommit) { 1116 TEST(SchedulerStateMachineTest, TestImmediateFinishCommitDuringCommit) {
1082 SchedulerSettings default_scheduler_settings; 1117 SchedulerSettings default_scheduler_settings;
1083 StateMachine state(default_scheduler_settings); 1118 StateMachine state(default_scheduler_settings);
1084 state.SetCanStart(); 1119 state.SetCanStart();
1085 state.UpdateState(state.NextAction()); 1120 state.UpdateState(state.NextAction());
1086 state.DidCreateAndInitializeOutputSurface(); 1121 state.DidCreateAndInitializeOutputSurface();
1087 state.SetVisible(true); 1122 state.SetVisible(true);
1088 state.SetCanDraw(true); 1123 state.SetCanDraw(true);
1089 1124
1090 // Start a normal commit. 1125 // Start a normal commit.
1091 state.SetNeedsCommit(); 1126 state.SetNeedsCommit();
1092 state.UpdateState(state.NextAction()); 1127 state.UpdateState(state.NextAction());
1093 1128
1094 // Schedule a forced frame, commit it, draw it. 1129 // Schedule a forced frame, commit it, draw it.
1095 state.SetNeedsCommit(); 1130 state.SetNeedsCommit();
1096 state.SetNeedsForcedCommit(); 1131 state.SetNeedsForcedCommit();
1097 state.UpdateState(state.NextAction()); 1132 state.UpdateState(state.NextAction());
1098 state.BeginFrameComplete(); 1133 state.FinishCommit();
1099 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction()); 1134 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction());
1100 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT, 1135 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT,
1101 state.CommitState()); 1136 state.CommitState());
1102 state.UpdateState(state.NextAction()); 1137 state.UpdateState(state.NextAction());
1103 1138
1104 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_FORCED_DRAW, 1139 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_FORCED_DRAW,
1105 state.CommitState()); 1140 state.CommitState());
1106 1141
1107 state.DidEnterVSync(); 1142 state.DidEnterBeginFrame();
1108 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); 1143 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction());
1109 state.SetNeedsForcedRedraw(true); 1144 state.SetNeedsForcedRedraw(true);
1110 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_FORCED, state.NextAction()); 1145 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_FORCED, state.NextAction());
1111 state.UpdateState(state.NextAction()); 1146 state.UpdateState(state.NextAction());
1112 state.DidDrawIfPossibleCompleted(true); 1147 state.DidDrawIfPossibleCompleted(true);
1113 state.DidLeaveVSync(); 1148 state.DidLeaveBeginFrame();
1114 1149
1115 // Should be waiting for the normal begin frame. 1150 // Should be waiting for the normal begin frame from the main thread.
1116 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, 1151 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS,
1117 state.CommitState()) << state.ToString(); 1152 state.CommitState()) << state.ToString();
1118 } 1153 }
1119 1154
1120 TEST(SchedulerStateMachineTest, ImmediateBeginFrameWhileInvisible) { 1155 TEST(SchedulerStateMachineTest,
1156 ImmediateBeginFrameAbortedByMainThreadWhileInvisible) {
1121 SchedulerSettings default_scheduler_settings; 1157 SchedulerSettings default_scheduler_settings;
1122 StateMachine state(default_scheduler_settings); 1158 StateMachine state(default_scheduler_settings);
1123 state.SetCanStart(); 1159 state.SetCanStart();
1124 state.UpdateState(state.NextAction()); 1160 state.UpdateState(state.NextAction());
1125 state.DidCreateAndInitializeOutputSurface(); 1161 state.DidCreateAndInitializeOutputSurface();
1126 state.SetVisible(true); 1162 state.SetVisible(true);
1127 state.SetCanDraw(true); 1163 state.SetCanDraw(true);
1128 1164
1129 state.SetNeedsCommit(); 1165 state.SetNeedsCommit();
1130 state.UpdateState(state.NextAction()); 1166 state.UpdateState(state.NextAction());
1131 1167
1132 state.SetNeedsCommit(); 1168 state.SetNeedsCommit();
1133 state.SetNeedsForcedCommit(); 1169 state.SetNeedsForcedCommit();
1134 state.UpdateState(state.NextAction()); 1170 state.UpdateState(state.NextAction());
1135 state.BeginFrameComplete(); 1171 state.FinishCommit();
1136 1172
1137 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction()); 1173 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction());
1138 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT, 1174 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT,
1139 state.CommitState()); 1175 state.CommitState());
1140 state.UpdateState(state.NextAction()); 1176 state.UpdateState(state.NextAction());
1141 1177
1142 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_FORCED_DRAW, 1178 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_FORCED_DRAW,
1143 state.CommitState()); 1179 state.CommitState());
1144 1180
1145 state.DidEnterVSync(); 1181 state.DidEnterBeginFrame();
1146 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); 1182 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction());
1147 state.SetNeedsForcedRedraw(true); 1183 state.SetNeedsForcedRedraw(true);
1148 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_FORCED, state.NextAction()); 1184 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_FORCED, state.NextAction());
1149 state.UpdateState(state.NextAction()); 1185 state.UpdateState(state.NextAction());
1150 state.DidDrawIfPossibleCompleted(true); 1186 state.DidDrawIfPossibleCompleted(true);
1151 state.DidLeaveVSync(); 1187 state.DidLeaveBeginFrame();
1152 1188
1153 // Should be waiting for the normal begin frame. 1189 // Should be waiting for the main thread's begin frame.
1154 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, 1190 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS,
1155 state.CommitState()) << state.ToString(); 1191 state.CommitState()) << state.ToString();
1156 1192
1157 // Become invisible and abort the "normal" begin frame. 1193 // Become invisible and abort the main thread's begin frame.
1158 state.SetVisible(false); 1194 state.SetVisible(false);
1159 state.BeginFrameAborted(); 1195 state.BeginFrameAbortedByMainThread();
1160 1196
1161 // Should be back in the idle state, but needing a commit. 1197 // Should be back in the idle state, but needing a commit.
1162 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState()); 1198 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState());
1163 EXPECT_TRUE(state.NeedsCommit()); 1199 EXPECT_TRUE(state.NeedsCommit());
1164 } 1200 }
1165 1201
1166 TEST(SchedulerStateMachineTest, ImmediateBeginFrameWhileCantDraw) { 1202 TEST(SchedulerStateMachineTest, ImmediateFinishCommitWhileCantDraw) {
1167 SchedulerSettings default_scheduler_settings; 1203 SchedulerSettings default_scheduler_settings;
1168 StateMachine state(default_scheduler_settings); 1204 StateMachine state(default_scheduler_settings);
1169 state.SetCanStart(); 1205 state.SetCanStart();
1170 state.UpdateState(state.NextAction()); 1206 state.UpdateState(state.NextAction());
1171 state.DidCreateAndInitializeOutputSurface(); 1207 state.DidCreateAndInitializeOutputSurface();
1172 state.SetVisible(true); 1208 state.SetVisible(true);
1173 state.SetCanDraw(false); 1209 state.SetCanDraw(false);
1174 1210
1175 state.SetNeedsCommit(); 1211 state.SetNeedsCommit();
1176 state.UpdateState(state.NextAction()); 1212 state.UpdateState(state.NextAction());
1177 1213
1178 state.SetNeedsCommit(); 1214 state.SetNeedsCommit();
1179 state.SetNeedsForcedCommit(); 1215 state.SetNeedsForcedCommit();
1180 state.UpdateState(state.NextAction()); 1216 state.UpdateState(state.NextAction());
1181 state.BeginFrameComplete(); 1217 state.FinishCommit();
1182 1218
1183 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction()); 1219 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction());
1184 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT, 1220 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT,
1185 state.CommitState()); 1221 state.CommitState());
1186 state.UpdateState(state.NextAction()); 1222 state.UpdateState(state.NextAction());
1187 1223
1188 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_FORCED_DRAW, 1224 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_FORCED_DRAW,
1189 state.CommitState()); 1225 state.CommitState());
1190 1226
1191 state.DidEnterVSync(); 1227 state.DidEnterBeginFrame();
1192 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); 1228 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction());
1193 state.SetNeedsForcedRedraw(true); 1229 state.SetNeedsForcedRedraw(true);
1194 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_FORCED, state.NextAction()); 1230 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_FORCED, state.NextAction());
1195 state.UpdateState(state.NextAction()); 1231 state.UpdateState(state.NextAction());
1196 state.DidDrawIfPossibleCompleted(true); 1232 state.DidDrawIfPossibleCompleted(true);
1197 state.DidLeaveVSync(); 1233 state.DidLeaveBeginFrame();
1198 } 1234 }
1199 1235
1200 TEST(SchedulerStateMachineTest, ReportIfNotDrawing) { 1236 TEST(SchedulerStateMachineTest, ReportIfNotDrawing) {
1201 SchedulerSettings default_scheduler_settings; 1237 SchedulerSettings default_scheduler_settings;
1202 SchedulerStateMachine state(default_scheduler_settings); 1238 SchedulerStateMachine state(default_scheduler_settings);
1203 1239
1204 state.SetCanDraw(true); 1240 state.SetCanDraw(true);
1205 state.SetVisible(true); 1241 state.SetVisible(true);
1206 EXPECT_FALSE(state.DrawSuspendedUntilCommit()); 1242 EXPECT_FALSE(state.DrawSuspendedUntilCommit());
1207 1243
(...skipping 24 matching lines...) Expand all
1232 state.SetVisible(true); 1268 state.SetVisible(true);
1233 EXPECT_FALSE(state.DrawSuspendedUntilCommit()); 1269 EXPECT_FALSE(state.DrawSuspendedUntilCommit());
1234 1270
1235 state.SetMainThreadNeedsLayerTextures(); 1271 state.SetMainThreadNeedsLayerTextures();
1236 EXPECT_EQ( 1272 EXPECT_EQ(
1237 SchedulerStateMachine::ACTION_ACQUIRE_LAYER_TEXTURES_FOR_MAIN_THREAD, 1273 SchedulerStateMachine::ACTION_ACQUIRE_LAYER_TEXTURES_FOR_MAIN_THREAD,
1238 state.NextAction()); 1274 state.NextAction());
1239 state.UpdateState(state.NextAction()); 1275 state.UpdateState(state.NextAction());
1240 EXPECT_TRUE(state.DrawSuspendedUntilCommit()); 1276 EXPECT_TRUE(state.DrawSuspendedUntilCommit());
1241 1277
1242 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_FRAME, state.NextAction()); 1278 EXPECT_EQ(SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD,
1279 state.NextAction());
1243 1280
1244 state.UpdateState(state.NextAction()); 1281 state.UpdateState(state.NextAction());
1245 EXPECT_TRUE(state.DrawSuspendedUntilCommit()); 1282 EXPECT_TRUE(state.DrawSuspendedUntilCommit());
1246 1283
1247 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); 1284 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction());
1248 1285
1249 state.BeginFrameComplete(); 1286 state.FinishCommit();
1250 EXPECT_TRUE(state.DrawSuspendedUntilCommit()); 1287 EXPECT_TRUE(state.DrawSuspendedUntilCommit());
1251 1288
1252 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction()); 1289 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction());
1253 1290
1254 state.UpdateState(state.NextAction()); 1291 state.UpdateState(state.NextAction());
1255 EXPECT_FALSE(state.DrawSuspendedUntilCommit()); 1292 EXPECT_FALSE(state.DrawSuspendedUntilCommit());
1256 } 1293 }
1257 1294
1258 } // namespace 1295 } // namespace
1259 } // namespace cc 1296 } // 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