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

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

Issue 275543004: Refactoring the debug creation of BeginFrameArgs objects to be in unittest code only. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebasing onto upstream master. Created 6 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 | Annotate | Revision Log
« no previous file with comments | « cc/output/output_surface_unittest.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 "cc/test/begin_frame_args_test.h"
8 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
9 10
10 #define EXPECT_ACTION_UPDATE_STATE(action) \ 11 #define EXPECT_ACTION_UPDATE_STATE(action) \
11 EXPECT_EQ(action, state.NextAction()) << *state.AsValue(); \ 12 EXPECT_EQ(action, state.NextAction()) << *state.AsValue(); \
12 if (action == SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE || \ 13 if (action == SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE || \
13 action == SchedulerStateMachine::ACTION_DRAW_AND_SWAP_FORCED) { \ 14 action == SchedulerStateMachine::ACTION_DRAW_AND_SWAP_FORCED) { \
14 EXPECT_EQ(SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE, \ 15 EXPECT_EQ(SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE, \
15 state.begin_impl_frame_state()) \ 16 state.begin_impl_frame_state()) \
16 << *state.AsValue(); \ 17 << *state.AsValue(); \
17 } \ 18 } \
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION) 125 SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION)
125 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 126 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
126 state.SetCommitState(SchedulerStateMachine::COMMIT_STATE_IDLE); 127 state.SetCommitState(SchedulerStateMachine::COMMIT_STATE_IDLE);
127 state.SetNeedsRedraw(false); 128 state.SetNeedsRedraw(false);
128 state.SetVisible(true); 129 state.SetVisible(true);
129 130
130 EXPECT_FALSE(state.BeginFrameNeeded()); 131 EXPECT_FALSE(state.BeginFrameNeeded());
131 132
132 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 133 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
133 EXPECT_FALSE(state.BeginFrameNeeded()); 134 EXPECT_FALSE(state.BeginFrameNeeded());
134 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 135 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting());
135 136
136 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 137 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
137 state.OnBeginImplFrameDeadline(); 138 state.OnBeginImplFrameDeadline();
138 } 139 }
139 140
140 // If commit requested but can_start is still false, do nothing. 141 // If commit requested but can_start is still false, do nothing.
141 { 142 {
142 StateMachine state(default_scheduler_settings); 143 StateMachine state(default_scheduler_settings);
143 state.SetCommitState(SchedulerStateMachine::COMMIT_STATE_IDLE); 144 state.SetCommitState(SchedulerStateMachine::COMMIT_STATE_IDLE);
144 state.SetNeedsRedraw(false); 145 state.SetNeedsRedraw(false);
145 state.SetVisible(true); 146 state.SetVisible(true);
146 state.SetNeedsCommit(); 147 state.SetNeedsCommit();
147 148
148 EXPECT_FALSE(state.BeginFrameNeeded()); 149 EXPECT_FALSE(state.BeginFrameNeeded());
149 150
150 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 151 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
151 EXPECT_FALSE(state.BeginFrameNeeded()); 152 EXPECT_FALSE(state.BeginFrameNeeded());
152 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 153 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting());
153 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 154 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
154 state.OnBeginImplFrameDeadline(); 155 state.OnBeginImplFrameDeadline();
155 } 156 }
156 157
157 // If commit requested, begin a main frame. 158 // If commit requested, begin a main frame.
158 { 159 {
159 StateMachine state(default_scheduler_settings); 160 StateMachine state(default_scheduler_settings);
160 state.SetCommitState(SchedulerStateMachine::COMMIT_STATE_IDLE); 161 state.SetCommitState(SchedulerStateMachine::COMMIT_STATE_IDLE);
161 state.SetCanStart(); 162 state.SetCanStart();
162 state.UpdateState(state.NextAction()); 163 state.UpdateState(state.NextAction());
163 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 164 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
164 state.SetNeedsRedraw(false); 165 state.SetNeedsRedraw(false);
165 state.SetVisible(true); 166 state.SetVisible(true);
166 state.SetNeedsCommit(); 167 state.SetNeedsCommit();
167 168
168 EXPECT_TRUE(state.BeginFrameNeeded()); 169 EXPECT_TRUE(state.BeginFrameNeeded());
169 170
170 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 171 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting());
171 EXPECT_ACTION_UPDATE_STATE( 172 EXPECT_ACTION_UPDATE_STATE(
172 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 173 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
173 } 174 }
174 175
175 // Begin the frame, make sure needs_commit and commit_state update correctly. 176 // Begin the frame, make sure needs_commit and commit_state update correctly.
176 { 177 {
177 StateMachine state(default_scheduler_settings); 178 StateMachine state(default_scheduler_settings);
178 state.SetCanStart(); 179 state.SetCanStart();
179 state.UpdateState(state.NextAction()); 180 state.UpdateState(state.NextAction());
180 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 181 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
(...skipping 16 matching lines...) Expand all
197 state.UpdateState(state.NextAction()); 198 state.UpdateState(state.NextAction());
198 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 199 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
199 state.SetNeedsRedraw(false); 200 state.SetNeedsRedraw(false);
200 state.SetVisible(true); 201 state.SetVisible(true);
201 state.SetCanDraw(true); 202 state.SetCanDraw(true);
202 state.SetNeedsCommit(); 203 state.SetNeedsCommit();
203 204
204 EXPECT_TRUE(state.BeginFrameNeeded()); 205 EXPECT_TRUE(state.BeginFrameNeeded());
205 206
206 // Commit to the pending tree. 207 // Commit to the pending tree.
207 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 208 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting());
208 EXPECT_ACTION_UPDATE_STATE( 209 EXPECT_ACTION_UPDATE_STATE(
209 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 210 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
210 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 211 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
211 state.NotifyBeginMainFrameStarted(); 212 state.NotifyBeginMainFrameStarted();
212 state.NotifyReadyToCommit(); 213 state.NotifyReadyToCommit();
213 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 214 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
214 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 215 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
215 EXPECT_EQ(state.CommitState(), 216 EXPECT_EQ(state.CommitState(),
216 SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW); 217 SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW);
217 218
218 state.OnBeginImplFrameDeadline(); 219 state.OnBeginImplFrameDeadline();
219 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 220 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
220 EXPECT_EQ(state.CommitState(), 221 EXPECT_EQ(state.CommitState(),
221 SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW); 222 SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW);
222 223
223 // Verify that the next commit doesn't start until the previous 224 // Verify that the next commit doesn't start until the previous
224 // commit has been drawn. 225 // commit has been drawn.
225 state.SetNeedsCommit(); 226 state.SetNeedsCommit();
226 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 227 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting());
227 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 228 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
228 229
229 // Make sure that a draw of the active tree doesn't spuriously advance 230 // Make sure that a draw of the active tree doesn't spuriously advance
230 // the commit state and unblock the next commit. 231 // the commit state and unblock the next commit.
231 state.SetNeedsRedraw(true); 232 state.SetNeedsRedraw(true);
232 state.OnBeginImplFrameDeadline(); 233 state.OnBeginImplFrameDeadline();
233 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE); 234 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
234 EXPECT_ACTION_UPDATE_STATE( 235 EXPECT_ACTION_UPDATE_STATE(
235 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 236 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
236 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 237 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
237 EXPECT_EQ(state.CommitState(), 238 EXPECT_EQ(state.CommitState(),
238 SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW); 239 SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW);
239 EXPECT_TRUE(state.has_pending_tree()); 240 EXPECT_TRUE(state.has_pending_tree());
240 241
241 // Verify NotifyReadyToActivate unblocks activation, draw, and 242 // Verify NotifyReadyToActivate unblocks activation, draw, and
242 // commit in that order. 243 // commit in that order.
243 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 244 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting());
244 245
245 state.NotifyReadyToActivate(); 246 state.NotifyReadyToActivate();
246 EXPECT_ACTION_UPDATE_STATE( 247 EXPECT_ACTION_UPDATE_STATE(
247 SchedulerStateMachine::ACTION_ACTIVATE_PENDING_TREE); 248 SchedulerStateMachine::ACTION_ACTIVATE_PENDING_TREE);
248 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE); 249 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
249 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 250 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
250 EXPECT_EQ(state.CommitState(), 251 EXPECT_EQ(state.CommitState(),
251 SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW); 252 SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW);
252 253
253 EXPECT_TRUE(state.ShouldTriggerBeginImplFrameDeadlineEarly()); 254 EXPECT_TRUE(state.ShouldTriggerBeginImplFrameDeadlineEarly());
(...skipping 26 matching lines...) Expand all
280 state.UpdateState(state.NextAction()); 281 state.UpdateState(state.NextAction());
281 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 282 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
282 state.SetNeedsRedraw(false); 283 state.SetNeedsRedraw(false);
283 state.SetVisible(true); 284 state.SetVisible(true);
284 state.SetCanDraw(true); 285 state.SetCanDraw(true);
285 state.SetNeedsCommit(); 286 state.SetNeedsCommit();
286 287
287 EXPECT_TRUE(state.BeginFrameNeeded()); 288 EXPECT_TRUE(state.BeginFrameNeeded());
288 289
289 // Commit to the pending tree. 290 // Commit to the pending tree.
290 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 291 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting());
291 EXPECT_ACTION_UPDATE_STATE( 292 EXPECT_ACTION_UPDATE_STATE(
292 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 293 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
293 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 294 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
294 295
295 state.NotifyBeginMainFrameStarted(); 296 state.NotifyBeginMainFrameStarted();
296 state.NotifyReadyToCommit(); 297 state.NotifyReadyToCommit();
297 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 298 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
298 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 299 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
299 EXPECT_EQ(state.CommitState(), SchedulerStateMachine::COMMIT_STATE_IDLE); 300 EXPECT_EQ(state.CommitState(), SchedulerStateMachine::COMMIT_STATE_IDLE);
300 301
301 state.OnBeginImplFrameDeadline(); 302 state.OnBeginImplFrameDeadline();
302 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 303 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
303 304
304 // Verify that the next commit starts while there is still a pending tree. 305 // Verify that the next commit starts while there is still a pending tree.
305 state.SetNeedsCommit(); 306 state.SetNeedsCommit();
306 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 307 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting());
307 EXPECT_ACTION_UPDATE_STATE( 308 EXPECT_ACTION_UPDATE_STATE(
308 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 309 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
309 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 310 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
310 311
311 // Verify the pending commit doesn't overwrite the pending 312 // Verify the pending commit doesn't overwrite the pending
312 // tree until the pending tree has been activated. 313 // tree until the pending tree has been activated.
313 state.NotifyBeginMainFrameStarted(); 314 state.NotifyBeginMainFrameStarted();
314 state.NotifyReadyToCommit(); 315 state.NotifyReadyToCommit();
315 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 316 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
316 317
(...skipping 19 matching lines...) Expand all
336 SchedulerSettings default_scheduler_settings; 337 SchedulerSettings default_scheduler_settings;
337 StateMachine state(default_scheduler_settings); 338 StateMachine state(default_scheduler_settings);
338 state.SetCanStart(); 339 state.SetCanStart();
339 state.UpdateState(state.NextAction()); 340 state.UpdateState(state.NextAction());
340 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 341 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
341 state.SetVisible(true); 342 state.SetVisible(true);
342 state.SetCanDraw(true); 343 state.SetCanDraw(true);
343 state.SetNeedsRedraw(true); 344 state.SetNeedsRedraw(true);
344 EXPECT_TRUE(state.RedrawPending()); 345 EXPECT_TRUE(state.RedrawPending());
345 EXPECT_TRUE(state.BeginFrameNeeded()); 346 EXPECT_TRUE(state.BeginFrameNeeded());
346 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 347 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting());
347 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE); 348 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
348 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 349 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
349 state.OnBeginImplFrameDeadline(); 350 state.OnBeginImplFrameDeadline();
350 351
351 // We're drawing now. 352 // We're drawing now.
352 EXPECT_ACTION_UPDATE_STATE( 353 EXPECT_ACTION_UPDATE_STATE(
353 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 354 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
354 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 355 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
355 356
356 EXPECT_FALSE(state.RedrawPending()); 357 EXPECT_FALSE(state.RedrawPending());
357 EXPECT_FALSE(state.CommitPending()); 358 EXPECT_FALSE(state.CommitPending());
358 359
359 // Failing the draw makes us require a commit. 360 // Failing the draw makes us require a commit.
360 state.DidDrawIfPossibleCompleted( 361 state.DidDrawIfPossibleCompleted(
361 DrawSwapReadbackResult::DRAW_ABORTED_CHECKERBOARD_ANIMATIONS); 362 DrawSwapReadbackResult::DRAW_ABORTED_CHECKERBOARD_ANIMATIONS);
362 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 363 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting());
363 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE); 364 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
364 EXPECT_ACTION_UPDATE_STATE( 365 EXPECT_ACTION_UPDATE_STATE(
365 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 366 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
366 EXPECT_TRUE(state.RedrawPending()); 367 EXPECT_TRUE(state.RedrawPending());
367 EXPECT_TRUE(state.CommitPending()); 368 EXPECT_TRUE(state.CommitPending());
368 } 369 }
369 370
370 TEST(SchedulerStateMachineTest, TestFailedDrawForMissingHighResNeedsCommit) { 371 TEST(SchedulerStateMachineTest, TestFailedDrawForMissingHighResNeedsCommit) {
371 SchedulerSettings default_scheduler_settings; 372 SchedulerSettings default_scheduler_settings;
372 StateMachine state(default_scheduler_settings); 373 StateMachine state(default_scheduler_settings);
373 state.SetCanStart(); 374 state.SetCanStart();
374 state.UpdateState(state.NextAction()); 375 state.UpdateState(state.NextAction());
375 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 376 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
376 state.SetVisible(true); 377 state.SetVisible(true);
377 state.SetCanDraw(true); 378 state.SetCanDraw(true);
378 state.SetNeedsRedraw(true); 379 state.SetNeedsRedraw(true);
379 EXPECT_TRUE(state.RedrawPending()); 380 EXPECT_TRUE(state.RedrawPending());
380 EXPECT_TRUE(state.BeginFrameNeeded()); 381 EXPECT_TRUE(state.BeginFrameNeeded());
381 382
382 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 383 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting());
383 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE); 384 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
384 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 385 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
385 state.OnBeginImplFrameDeadline(); 386 state.OnBeginImplFrameDeadline();
386 EXPECT_ACTION_UPDATE_STATE( 387 EXPECT_ACTION_UPDATE_STATE(
387 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 388 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
388 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 389 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
389 EXPECT_FALSE(state.RedrawPending()); 390 EXPECT_FALSE(state.RedrawPending());
390 EXPECT_FALSE(state.CommitPending()); 391 EXPECT_FALSE(state.CommitPending());
391 392
392 // Missing high res content requires a commit (but not a redraw) 393 // Missing high res content requires a commit (but not a redraw)
393 state.DidDrawIfPossibleCompleted( 394 state.DidDrawIfPossibleCompleted(
394 DrawSwapReadbackResult::DRAW_ABORTED_MISSING_HIGH_RES_CONTENT); 395 DrawSwapReadbackResult::DRAW_ABORTED_MISSING_HIGH_RES_CONTENT);
395 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 396 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting());
396 EXPECT_ACTION_UPDATE_STATE( 397 EXPECT_ACTION_UPDATE_STATE(
397 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 398 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
398 EXPECT_FALSE(state.RedrawPending()); 399 EXPECT_FALSE(state.RedrawPending());
399 EXPECT_TRUE(state.CommitPending()); 400 EXPECT_TRUE(state.CommitPending());
400 } 401 }
401 402
402 TEST(SchedulerStateMachineTest, 403 TEST(SchedulerStateMachineTest,
403 TestsetNeedsRedrawDuringFailedDrawDoesNotRemoveNeedsRedraw) { 404 TestsetNeedsRedrawDuringFailedDrawDoesNotRemoveNeedsRedraw) {
404 SchedulerSettings default_scheduler_settings; 405 SchedulerSettings default_scheduler_settings;
405 StateMachine state(default_scheduler_settings); 406 StateMachine state(default_scheduler_settings);
406 state.SetCanStart(); 407 state.SetCanStart();
407 state.UpdateState(state.NextAction()); 408 state.UpdateState(state.NextAction());
408 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 409 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
409 410
410 state.SetVisible(true); 411 state.SetVisible(true);
411 state.SetCanDraw(true); 412 state.SetCanDraw(true);
412 state.SetNeedsRedraw(true); 413 state.SetNeedsRedraw(true);
413 EXPECT_TRUE(state.RedrawPending()); 414 EXPECT_TRUE(state.RedrawPending());
414 EXPECT_TRUE(state.BeginFrameNeeded()); 415 EXPECT_TRUE(state.BeginFrameNeeded());
415 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 416 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting());
416 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE); 417 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
417 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 418 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
418 state.OnBeginImplFrameDeadline(); 419 state.OnBeginImplFrameDeadline();
419 420
420 // We're drawing now. 421 // We're drawing now.
421 EXPECT_ACTION_UPDATE_STATE( 422 EXPECT_ACTION_UPDATE_STATE(
422 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 423 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
423 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 424 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
424 EXPECT_FALSE(state.RedrawPending()); 425 EXPECT_FALSE(state.RedrawPending());
425 EXPECT_FALSE(state.CommitPending()); 426 EXPECT_FALSE(state.CommitPending());
426 427
427 // While still in the same BeginMainFrame callback on the main thread, 428 // While still in the same BeginMainFrame callback on the main thread,
428 // set needs redraw again. This should not redraw. 429 // set needs redraw again. This should not redraw.
429 state.SetNeedsRedraw(true); 430 state.SetNeedsRedraw(true);
430 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 431 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
431 432
432 // Failing the draw for animation checkerboards makes us require a commit. 433 // Failing the draw for animation checkerboards makes us require a commit.
433 state.DidDrawIfPossibleCompleted( 434 state.DidDrawIfPossibleCompleted(
434 DrawSwapReadbackResult::DRAW_ABORTED_CHECKERBOARD_ANIMATIONS); 435 DrawSwapReadbackResult::DRAW_ABORTED_CHECKERBOARD_ANIMATIONS);
435 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 436 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting());
436 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE); 437 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
437 EXPECT_ACTION_UPDATE_STATE( 438 EXPECT_ACTION_UPDATE_STATE(
438 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 439 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
439 EXPECT_TRUE(state.RedrawPending()); 440 EXPECT_TRUE(state.RedrawPending());
440 } 441 }
441 442
442 void TestFailedDrawsEventuallyForceDrawAfterNextCommit( 443 void TestFailedDrawsEventuallyForceDrawAfterNextCommit(
443 bool main_frame_before_draw_enabled) { 444 bool main_frame_before_draw_enabled) {
444 SchedulerSettings scheduler_settings; 445 SchedulerSettings scheduler_settings;
445 scheduler_settings.main_frame_before_draw_enabled = 446 scheduler_settings.main_frame_before_draw_enabled =
446 main_frame_before_draw_enabled; 447 main_frame_before_draw_enabled;
447 scheduler_settings.maximum_number_of_failed_draws_before_draw_is_forced_ = 1; 448 scheduler_settings.maximum_number_of_failed_draws_before_draw_is_forced_ = 1;
448 StateMachine state(scheduler_settings); 449 StateMachine state(scheduler_settings);
449 state.SetCanStart(); 450 state.SetCanStart();
450 state.UpdateState(state.NextAction()); 451 state.UpdateState(state.NextAction());
451 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 452 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
452 state.SetVisible(true); 453 state.SetVisible(true);
453 state.SetCanDraw(true); 454 state.SetCanDraw(true);
454 455
455 // Start a commit. 456 // Start a commit.
456 state.SetNeedsCommit(); 457 state.SetNeedsCommit();
457 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 458 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
458 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 459 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting());
459 EXPECT_ACTION_UPDATE_STATE( 460 EXPECT_ACTION_UPDATE_STATE(
460 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 461 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
461 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 462 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
462 EXPECT_TRUE(state.CommitPending()); 463 EXPECT_TRUE(state.CommitPending());
463 464
464 // Then initiate a draw. 465 // Then initiate a draw.
465 state.SetNeedsRedraw(true); 466 state.SetNeedsRedraw(true);
466 state.OnBeginImplFrameDeadline(); 467 state.OnBeginImplFrameDeadline();
467 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE); 468 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
468 EXPECT_ACTION_UPDATE_STATE( 469 EXPECT_ACTION_UPDATE_STATE(
(...skipping 10 matching lines...) Expand all
479 480
480 // Finish the commit. Note, we should not yet be forcing a draw, but should 481 // Finish the commit. Note, we should not yet be forcing a draw, but should
481 // continue the commit as usual. 482 // continue the commit as usual.
482 state.NotifyBeginMainFrameStarted(); 483 state.NotifyBeginMainFrameStarted();
483 state.NotifyReadyToCommit(); 484 state.NotifyReadyToCommit();
484 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 485 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
485 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 486 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
486 EXPECT_TRUE(state.RedrawPending()); 487 EXPECT_TRUE(state.RedrawPending());
487 488
488 // The redraw should be forced at the end of the next BeginImplFrame. 489 // The redraw should be forced at the end of the next BeginImplFrame.
489 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 490 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting());
490 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE); 491 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
491 if (main_frame_before_draw_enabled) { 492 if (main_frame_before_draw_enabled) {
492 EXPECT_ACTION_UPDATE_STATE( 493 EXPECT_ACTION_UPDATE_STATE(
493 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 494 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
494 } 495 }
495 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 496 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
496 state.OnBeginImplFrameDeadline(); 497 state.OnBeginImplFrameDeadline();
497 EXPECT_ACTION_UPDATE_STATE( 498 EXPECT_ACTION_UPDATE_STATE(
498 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_FORCED); 499 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_FORCED);
499 } 500 }
(...skipping 21 matching lines...) Expand all
521 StateMachine state(scheduler_settings); 522 StateMachine state(scheduler_settings);
522 state.SetCanStart(); 523 state.SetCanStart();
523 state.UpdateState(state.NextAction()); 524 state.UpdateState(state.NextAction());
524 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 525 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
525 state.SetVisible(true); 526 state.SetVisible(true);
526 state.SetCanDraw(true); 527 state.SetCanDraw(true);
527 528
528 // Start a commit. 529 // Start a commit.
529 state.SetNeedsCommit(); 530 state.SetNeedsCommit();
530 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 531 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
531 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 532 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting());
532 EXPECT_ACTION_UPDATE_STATE( 533 EXPECT_ACTION_UPDATE_STATE(
533 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 534 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
534 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 535 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
535 EXPECT_TRUE(state.CommitPending()); 536 EXPECT_TRUE(state.CommitPending());
536 537
537 // Then initiate a draw. 538 // Then initiate a draw.
538 state.SetNeedsRedraw(true); 539 state.SetNeedsRedraw(true);
539 state.OnBeginImplFrameDeadline(); 540 state.OnBeginImplFrameDeadline();
540 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE); 541 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
541 EXPECT_ACTION_UPDATE_STATE( 542 EXPECT_ACTION_UPDATE_STATE(
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
582 StateMachine state(default_scheduler_settings); 583 StateMachine state(default_scheduler_settings);
583 state.SetCanStart(); 584 state.SetCanStart();
584 state.UpdateState(state.NextAction()); 585 state.UpdateState(state.NextAction());
585 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 586 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
586 state.SetVisible(true); 587 state.SetVisible(true);
587 state.SetCanDraw(true); 588 state.SetCanDraw(true);
588 589
589 // Start a draw. 590 // Start a draw.
590 state.SetNeedsRedraw(true); 591 state.SetNeedsRedraw(true);
591 EXPECT_TRUE(state.BeginFrameNeeded()); 592 EXPECT_TRUE(state.BeginFrameNeeded());
592 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 593 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting());
593 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE); 594 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
594 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 595 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
595 state.OnBeginImplFrameDeadline(); 596 state.OnBeginImplFrameDeadline();
596 EXPECT_TRUE(state.RedrawPending()); 597 EXPECT_TRUE(state.RedrawPending());
597 EXPECT_ACTION_UPDATE_STATE( 598 EXPECT_ACTION_UPDATE_STATE(
598 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 599 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
599 600
600 // Failing the draw for animation checkerboards makes us require a commit. 601 // Failing the draw for animation checkerboards makes us require a commit.
601 state.DidDrawIfPossibleCompleted( 602 state.DidDrawIfPossibleCompleted(
602 DrawSwapReadbackResult::DRAW_ABORTED_CHECKERBOARD_ANIMATIONS); 603 DrawSwapReadbackResult::DRAW_ABORTED_CHECKERBOARD_ANIMATIONS);
603 EXPECT_ACTION_UPDATE_STATE( 604 EXPECT_ACTION_UPDATE_STATE(
604 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 605 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
605 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 606 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
606 EXPECT_TRUE(state.RedrawPending()); 607 EXPECT_TRUE(state.RedrawPending());
607 608
608 // We should not be trying to draw again now, but we have a commit pending. 609 // We should not be trying to draw again now, but we have a commit pending.
609 EXPECT_TRUE(state.BeginFrameNeeded()); 610 EXPECT_TRUE(state.BeginFrameNeeded());
610 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 611 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting());
611 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE); 612 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
612 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 613 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
613 614
614 // We should try to draw again at the end of the next BeginImplFrame on 615 // We should try to draw again at the end of the next BeginImplFrame on
615 // the impl thread. 616 // the impl thread.
616 state.OnBeginImplFrameDeadline(); 617 state.OnBeginImplFrameDeadline();
617 EXPECT_ACTION_UPDATE_STATE( 618 EXPECT_ACTION_UPDATE_STATE(
618 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 619 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
619 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 620 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
620 } 621 }
621 622
622 TEST(SchedulerStateMachineTest, TestDoestDrawTwiceInSameFrame) { 623 TEST(SchedulerStateMachineTest, TestDoestDrawTwiceInSameFrame) {
623 SchedulerSettings default_scheduler_settings; 624 SchedulerSettings default_scheduler_settings;
624 StateMachine state(default_scheduler_settings); 625 StateMachine state(default_scheduler_settings);
625 state.SetCanStart(); 626 state.SetCanStart();
626 state.UpdateState(state.NextAction()); 627 state.UpdateState(state.NextAction());
627 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 628 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
628 state.SetVisible(true); 629 state.SetVisible(true);
629 state.SetCanDraw(true); 630 state.SetCanDraw(true);
630 state.SetNeedsRedraw(true); 631 state.SetNeedsRedraw(true);
631 632
632 // Draw the first frame. 633 // Draw the first frame.
633 EXPECT_TRUE(state.BeginFrameNeeded()); 634 EXPECT_TRUE(state.BeginFrameNeeded());
634 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 635 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting());
635 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE); 636 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
636 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 637 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
637 638
638 state.OnBeginImplFrameDeadline(); 639 state.OnBeginImplFrameDeadline();
639 EXPECT_ACTION_UPDATE_STATE( 640 EXPECT_ACTION_UPDATE_STATE(
640 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 641 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
641 state.DidDrawIfPossibleCompleted(DrawSwapReadbackResult::DRAW_SUCCESS); 642 state.DidDrawIfPossibleCompleted(DrawSwapReadbackResult::DRAW_SUCCESS);
642 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 643 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
643 644
644 // Before the next BeginImplFrame, set needs redraw again. 645 // Before the next BeginImplFrame, set needs redraw again.
645 // This should not redraw until the next BeginImplFrame. 646 // This should not redraw until the next BeginImplFrame.
646 state.SetNeedsRedraw(true); 647 state.SetNeedsRedraw(true);
647 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 648 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
648 649
649 // Move to another frame. This should now draw. 650 // Move to another frame. This should now draw.
650 EXPECT_TRUE(state.BeginFrameNeeded()); 651 EXPECT_TRUE(state.BeginFrameNeeded());
651 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 652 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting());
652 653
653 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE); 654 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
654 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 655 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
655 656
656 state.OnBeginImplFrameDeadline(); 657 state.OnBeginImplFrameDeadline();
657 EXPECT_ACTION_UPDATE_STATE( 658 EXPECT_ACTION_UPDATE_STATE(
658 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 659 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
659 state.DidDrawIfPossibleCompleted(DrawSwapReadbackResult::DRAW_SUCCESS); 660 state.DidDrawIfPossibleCompleted(DrawSwapReadbackResult::DRAW_SUCCESS);
660 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 661 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
661 662
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
790 // There shouldn't be any drawing regardless of BeginImplFrame. 791 // There shouldn't be any drawing regardless of BeginImplFrame.
791 for (size_t j = 0; j < 2; ++j) { 792 for (size_t j = 0; j < 2; ++j) {
792 StateMachine state(default_scheduler_settings); 793 StateMachine state(default_scheduler_settings);
793 state.SetCanStart(); 794 state.SetCanStart();
794 state.UpdateState(state.NextAction()); 795 state.UpdateState(state.NextAction());
795 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 796 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
796 state.SetCommitState(all_commit_states[i]); 797 state.SetCommitState(all_commit_states[i]);
797 state.SetVisible(false); 798 state.SetVisible(false);
798 state.SetNeedsRedraw(true); 799 state.SetNeedsRedraw(true);
799 if (j == 1) 800 if (j == 1)
800 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 801 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting());
801 802
802 state.SetCanDraw(false); 803 state.SetCanDraw(false);
803 EXPECT_NE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE, 804 EXPECT_NE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE,
804 state.NextAction()); 805 state.NextAction());
805 } 806 }
806 } 807 }
807 } 808 }
808 809
809 TEST(SchedulerStateMachineTest, 810 TEST(SchedulerStateMachineTest,
810 TestCanRedrawWithWaitingForFirstDrawMakesProgress) { 811 TestCanRedrawWithWaitingForFirstDrawMakesProgress) {
811 SchedulerSettings default_scheduler_settings; 812 SchedulerSettings default_scheduler_settings;
812 StateMachine state(default_scheduler_settings); 813 StateMachine state(default_scheduler_settings);
813 state.SetCanStart(); 814 state.SetCanStart();
814 state.UpdateState(state.NextAction()); 815 state.UpdateState(state.NextAction());
815 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 816 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
816 817
817 state.SetActiveTreeNeedsFirstDraw(true); 818 state.SetActiveTreeNeedsFirstDraw(true);
818 state.SetNeedsCommit(); 819 state.SetNeedsCommit();
819 state.SetNeedsRedraw(true); 820 state.SetNeedsRedraw(true);
820 state.SetVisible(true); 821 state.SetVisible(true);
821 state.SetCanDraw(false); 822 state.SetCanDraw(false);
822 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 823 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting());
823 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT); 824 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT);
824 EXPECT_ACTION_UPDATE_STATE( 825 EXPECT_ACTION_UPDATE_STATE(
825 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 826 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
826 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 827 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
827 state.NotifyBeginMainFrameStarted(); 828 state.NotifyBeginMainFrameStarted();
828 state.NotifyReadyToCommit(); 829 state.NotifyReadyToCommit();
829 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 830 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
830 state.OnBeginImplFrameDeadline(); 831 state.OnBeginImplFrameDeadline();
831 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT); 832 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT);
832 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 833 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
833 } 834 }
834 835
835 void TestSetNeedsCommitIsNotLost(bool main_frame_before_draw_enabled) { 836 void TestSetNeedsCommitIsNotLost(bool main_frame_before_draw_enabled) {
836 SchedulerSettings scheduler_settings; 837 SchedulerSettings scheduler_settings;
837 scheduler_settings.main_frame_before_draw_enabled = 838 scheduler_settings.main_frame_before_draw_enabled =
838 main_frame_before_draw_enabled; 839 main_frame_before_draw_enabled;
839 StateMachine state(scheduler_settings); 840 StateMachine state(scheduler_settings);
840 state.SetCanStart(); 841 state.SetCanStart();
841 state.UpdateState(state.NextAction()); 842 state.UpdateState(state.NextAction());
842 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 843 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
843 state.SetNeedsCommit(); 844 state.SetNeedsCommit();
844 state.SetVisible(true); 845 state.SetVisible(true);
845 state.SetCanDraw(true); 846 state.SetCanDraw(true);
846 847
847 EXPECT_TRUE(state.BeginFrameNeeded()); 848 EXPECT_TRUE(state.BeginFrameNeeded());
848 849
849 // Begin the frame. 850 // Begin the frame.
850 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 851 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting());
851 EXPECT_ACTION_UPDATE_STATE( 852 EXPECT_ACTION_UPDATE_STATE(
852 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 853 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
853 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT, 854 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT,
854 state.CommitState()); 855 state.CommitState());
855 856
856 // Now, while the frame is in progress, set another commit. 857 // Now, while the frame is in progress, set another commit.
857 state.SetNeedsCommit(); 858 state.SetNeedsCommit();
858 EXPECT_TRUE(state.NeedsCommit()); 859 EXPECT_TRUE(state.NeedsCommit());
859 860
860 // Let the frame finish. 861 // Let the frame finish.
(...skipping 15 matching lines...) Expand all
876 state.OnBeginImplFrameDeadline(); 877 state.OnBeginImplFrameDeadline();
877 EXPECT_EQ(SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE, 878 EXPECT_EQ(SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE,
878 state.begin_impl_frame_state()); 879 state.begin_impl_frame_state());
879 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction()); 880 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction());
880 881
881 state.OnBeginImplFrameIdle(); 882 state.OnBeginImplFrameIdle();
882 EXPECT_EQ(SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE, 883 EXPECT_EQ(SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE,
883 state.begin_impl_frame_state()); 884 state.begin_impl_frame_state());
884 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction()); 885 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction());
885 886
886 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 887 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting());
887 EXPECT_EQ(SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_BEGIN_FRAME_STARTING, 888 EXPECT_EQ(SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_BEGIN_FRAME_STARTING,
888 state.begin_impl_frame_state()); 889 state.begin_impl_frame_state());
889 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction()); 890 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction());
890 891
891 // Finish the commit, then make sure we start the next commit immediately 892 // Finish the commit, then make sure we start the next commit immediately
892 // and draw on the next BeginImplFrame. 893 // and draw on the next BeginImplFrame.
893 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 894 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
894 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE); 895 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
895 if (main_frame_before_draw_enabled) { 896 if (main_frame_before_draw_enabled) {
896 EXPECT_ACTION_UPDATE_STATE( 897 EXPECT_ACTION_UPDATE_STATE(
(...skipping 30 matching lines...) Expand all
927 state.SetCanStart(); 928 state.SetCanStart();
928 state.UpdateState(state.NextAction()); 929 state.UpdateState(state.NextAction());
929 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 930 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
930 state.SetVisible(true); 931 state.SetVisible(true);
931 state.SetCanDraw(true); 932 state.SetCanDraw(true);
932 933
933 // Start clean and set commit. 934 // Start clean and set commit.
934 state.SetNeedsCommit(); 935 state.SetNeedsCommit();
935 936
936 // Begin the frame. 937 // Begin the frame.
937 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 938 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting());
938 EXPECT_ACTION_UPDATE_STATE( 939 EXPECT_ACTION_UPDATE_STATE(
939 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 940 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
940 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT, 941 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT,
941 state.CommitState()); 942 state.CommitState());
942 EXPECT_FALSE(state.NeedsCommit()); 943 EXPECT_FALSE(state.NeedsCommit());
943 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 944 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
944 945
945 // Tell the scheduler the frame finished. 946 // Tell the scheduler the frame finished.
946 state.NotifyBeginMainFrameStarted(); 947 state.NotifyBeginMainFrameStarted();
947 state.NotifyReadyToCommit(); 948 state.NotifyReadyToCommit();
(...skipping 27 matching lines...) Expand all
975 state.SetCanStart(); 976 state.SetCanStart();
976 state.UpdateState(state.NextAction()); 977 state.UpdateState(state.NextAction());
977 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 978 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
978 state.SetVisible(true); 979 state.SetVisible(true);
979 state.SetCanDraw(true); 980 state.SetCanDraw(true);
980 981
981 // Start clean and set commit. 982 // Start clean and set commit.
982 state.SetNeedsCommit(); 983 state.SetNeedsCommit();
983 984
984 // Begin the frame. 985 // Begin the frame.
985 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 986 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting());
986 EXPECT_ACTION_UPDATE_STATE( 987 EXPECT_ACTION_UPDATE_STATE(
987 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 988 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
988 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT, 989 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT,
989 state.CommitState()); 990 state.CommitState());
990 EXPECT_FALSE(state.NeedsCommit()); 991 EXPECT_FALSE(state.NeedsCommit());
991 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 992 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
992 993
993 // Request another commit while the commit is in flight. 994 // Request another commit while the commit is in flight.
994 state.SetNeedsCommit(); 995 state.SetNeedsCommit();
995 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 996 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
(...skipping 18 matching lines...) Expand all
1014 EXPECT_ACTION_UPDATE_STATE( 1015 EXPECT_ACTION_UPDATE_STATE(
1015 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 1016 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
1016 state.DidDrawIfPossibleCompleted(DrawSwapReadbackResult::DRAW_SUCCESS); 1017 state.DidDrawIfPossibleCompleted(DrawSwapReadbackResult::DRAW_SUCCESS);
1017 1018
1018 // Should be synchronized, no draw needed, no action needed. 1019 // Should be synchronized, no draw needed, no action needed.
1019 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1020 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1020 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState()); 1021 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState());
1021 EXPECT_FALSE(state.needs_redraw()); 1022 EXPECT_FALSE(state.needs_redraw());
1022 1023
1023 // Next BeginImplFrame should initiate second commit. 1024 // Next BeginImplFrame should initiate second commit.
1024 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 1025 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting());
1025 EXPECT_ACTION_UPDATE_STATE( 1026 EXPECT_ACTION_UPDATE_STATE(
1026 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 1027 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
1027 } 1028 }
1028 1029
1029 TEST(SchedulerStateMachineTest, TestRequestCommitInvisible) { 1030 TEST(SchedulerStateMachineTest, TestRequestCommitInvisible) {
1030 SchedulerSettings default_scheduler_settings; 1031 SchedulerSettings default_scheduler_settings;
1031 StateMachine state(default_scheduler_settings); 1032 StateMachine state(default_scheduler_settings);
1032 state.SetCanStart(); 1033 state.SetCanStart();
1033 state.UpdateState(state.NextAction()); 1034 state.UpdateState(state.NextAction());
1034 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 1035 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
1035 state.SetNeedsCommit(); 1036 state.SetNeedsCommit();
1036 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1037 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1037 } 1038 }
1038 1039
1039 TEST(SchedulerStateMachineTest, TestGoesInvisibleBeforeFinishCommit) { 1040 TEST(SchedulerStateMachineTest, TestGoesInvisibleBeforeFinishCommit) {
1040 SchedulerSettings default_scheduler_settings; 1041 SchedulerSettings default_scheduler_settings;
1041 StateMachine state(default_scheduler_settings); 1042 StateMachine state(default_scheduler_settings);
1042 state.SetCanStart(); 1043 state.SetCanStart();
1043 state.UpdateState(state.NextAction()); 1044 state.UpdateState(state.NextAction());
1044 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 1045 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
1045 state.SetVisible(true); 1046 state.SetVisible(true);
1046 state.SetCanDraw(true); 1047 state.SetCanDraw(true);
1047 1048
1048 // Start clean and set commit. 1049 // Start clean and set commit.
1049 state.SetNeedsCommit(); 1050 state.SetNeedsCommit();
1050 1051
1051 // Begin the frame while visible. 1052 // Begin the frame while visible.
1052 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 1053 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting());
1053 EXPECT_ACTION_UPDATE_STATE( 1054 EXPECT_ACTION_UPDATE_STATE(
1054 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 1055 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
1055 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT, 1056 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT,
1056 state.CommitState()); 1057 state.CommitState());
1057 EXPECT_FALSE(state.NeedsCommit()); 1058 EXPECT_FALSE(state.NeedsCommit());
1058 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1059 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1059 1060
1060 // Become invisible and abort BeginMainFrame. 1061 // Become invisible and abort BeginMainFrame.
1061 state.SetVisible(false); 1062 state.SetVisible(false);
1062 state.BeginMainFrameAborted(false); 1063 state.BeginMainFrameAborted(false);
1063 1064
1064 // We should now be back in the idle state as if we never started the frame. 1065 // We should now be back in the idle state as if we never started the frame.
1065 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState()); 1066 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState());
1066 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1067 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1067 1068
1068 // We shouldn't do anything on the BeginImplFrame deadline. 1069 // We shouldn't do anything on the BeginImplFrame deadline.
1069 state.OnBeginImplFrameDeadline(); 1070 state.OnBeginImplFrameDeadline();
1070 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1071 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1071 1072
1072 // Become visible again. 1073 // Become visible again.
1073 state.SetVisible(true); 1074 state.SetVisible(true);
1074 1075
1075 // Although we have aborted on this frame and haven't cancelled the commit 1076 // Although we have aborted on this frame and haven't cancelled the commit
1076 // (i.e. need another), don't send another BeginMainFrame yet. 1077 // (i.e. need another), don't send another BeginMainFrame yet.
1077 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState()); 1078 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState());
1078 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); 1079 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction());
1079 EXPECT_TRUE(state.NeedsCommit()); 1080 EXPECT_TRUE(state.NeedsCommit());
1080 1081
1081 // Start a new frame. 1082 // Start a new frame.
1082 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 1083 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting());
1083 EXPECT_ACTION_UPDATE_STATE( 1084 EXPECT_ACTION_UPDATE_STATE(
1084 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 1085 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
1085 1086
1086 // We should be starting the commit now. 1087 // We should be starting the commit now.
1087 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT, 1088 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT,
1088 state.CommitState()); 1089 state.CommitState());
1089 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1090 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1090 } 1091 }
1091 1092
1092 TEST(SchedulerStateMachineTest, AbortBeginMainFrameAndCancelCommit) { 1093 TEST(SchedulerStateMachineTest, AbortBeginMainFrameAndCancelCommit) {
(...skipping 18 matching lines...) Expand all
1111 // Abort the commit, cancelling future commits. 1112 // Abort the commit, cancelling future commits.
1112 state.BeginMainFrameAborted(true); 1113 state.BeginMainFrameAborted(true);
1113 1114
1114 // Verify that another commit doesn't start on the same frame. 1115 // Verify that another commit doesn't start on the same frame.
1115 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState()); 1116 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState());
1116 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); 1117 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction());
1117 EXPECT_FALSE(state.NeedsCommit()); 1118 EXPECT_FALSE(state.NeedsCommit());
1118 1119
1119 // Start a new frame; draw because this is the first frame since output 1120 // Start a new frame; draw because this is the first frame since output
1120 // surface init'd. 1121 // surface init'd.
1121 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 1122 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting());
1122 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE); 1123 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
1123 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1124 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1124 state.OnBeginImplFrameDeadline(); 1125 state.OnBeginImplFrameDeadline();
1125 EXPECT_ACTION_UPDATE_STATE( 1126 EXPECT_ACTION_UPDATE_STATE(
1126 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 1127 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
1127 1128
1128 // Verify another commit doesn't start on another frame either. 1129 // Verify another commit doesn't start on another frame either.
1129 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState()); 1130 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState());
1130 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); 1131 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction());
1131 EXPECT_FALSE(state.NeedsCommit()); 1132 EXPECT_FALSE(state.NeedsCommit());
(...skipping 11 matching lines...) Expand all
1143 state.SetCanStart(); 1144 state.SetCanStart();
1144 state.SetVisible(true); 1145 state.SetVisible(true);
1145 state.SetCanDraw(true); 1146 state.SetCanDraw(true);
1146 1147
1147 EXPECT_ACTION_UPDATE_STATE( 1148 EXPECT_ACTION_UPDATE_STATE(
1148 SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION); 1149 SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION);
1149 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 1150 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
1150 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1151 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1151 1152
1152 // Check that the first init does not SetNeedsCommit. 1153 // Check that the first init does not SetNeedsCommit.
1153 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 1154 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting());
1154 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1155 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1155 state.OnBeginImplFrameDeadline(); 1156 state.OnBeginImplFrameDeadline();
1156 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1157 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1157 1158
1158 // Check that a needs commit initiates a BeginMainFrame. 1159 // Check that a needs commit initiates a BeginMainFrame.
1159 state.SetNeedsCommit(); 1160 state.SetNeedsCommit();
1160 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 1161 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting());
1161 EXPECT_ACTION_UPDATE_STATE( 1162 EXPECT_ACTION_UPDATE_STATE(
1162 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 1163 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
1163 } 1164 }
1164 1165
1165 TEST(SchedulerStateMachineTest, TestContextLostWhenCompletelyIdle) { 1166 TEST(SchedulerStateMachineTest, TestContextLostWhenCompletelyIdle) {
1166 SchedulerSettings default_scheduler_settings; 1167 SchedulerSettings default_scheduler_settings;
1167 StateMachine state(default_scheduler_settings); 1168 StateMachine state(default_scheduler_settings);
1168 state.SetCanStart(); 1169 state.SetCanStart();
1169 state.UpdateState(state.NextAction()); 1170 state.UpdateState(state.NextAction());
1170 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 1171 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
1171 1172
1172 state.SetVisible(true); 1173 state.SetVisible(true);
1173 state.SetCanDraw(true); 1174 state.SetCanDraw(true);
1174 1175
1175 EXPECT_NE(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION, 1176 EXPECT_NE(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION,
1176 state.NextAction()); 1177 state.NextAction());
1177 state.DidLoseOutputSurface(); 1178 state.DidLoseOutputSurface();
1178 1179
1179 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION, 1180 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION,
1180 state.NextAction()); 1181 state.NextAction());
1181 state.UpdateState(state.NextAction()); 1182 state.UpdateState(state.NextAction());
1182 1183
1183 // Once context recreation begins, nothing should happen. 1184 // Once context recreation begins, nothing should happen.
1184 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1185 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1185 1186
1186 // Recreate the context. 1187 // Recreate the context.
1187 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 1188 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
1188 1189
1189 // When the context is recreated, we should begin a commit. 1190 // When the context is recreated, we should begin a commit.
1190 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 1191 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting());
1191 EXPECT_ACTION_UPDATE_STATE( 1192 EXPECT_ACTION_UPDATE_STATE(
1192 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 1193 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
1193 } 1194 }
1194 1195
1195 TEST(SchedulerStateMachineTest, 1196 TEST(SchedulerStateMachineTest,
1196 TestContextLostWhenIdleAndCommitRequestedWhileRecreating) { 1197 TestContextLostWhenIdleAndCommitRequestedWhileRecreating) {
1197 SchedulerSettings default_scheduler_settings; 1198 SchedulerSettings default_scheduler_settings;
1198 StateMachine state(default_scheduler_settings); 1199 StateMachine state(default_scheduler_settings);
1199 state.SetCanStart(); 1200 state.SetCanStart();
1200 state.UpdateState(state.NextAction()); 1201 state.UpdateState(state.NextAction());
1201 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 1202 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
1202 state.SetVisible(true); 1203 state.SetVisible(true);
1203 state.SetCanDraw(true); 1204 state.SetCanDraw(true);
1204 1205
1205 EXPECT_NE(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION, 1206 EXPECT_NE(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION,
1206 state.NextAction()); 1207 state.NextAction());
1207 state.DidLoseOutputSurface(); 1208 state.DidLoseOutputSurface();
1208 1209
1209 EXPECT_ACTION_UPDATE_STATE( 1210 EXPECT_ACTION_UPDATE_STATE(
1210 SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION); 1211 SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION);
1211 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1212 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1212 1213
1213 // Once context recreation begins, nothing should happen. 1214 // Once context recreation begins, nothing should happen.
1214 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 1215 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting());
1215 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1216 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1216 state.OnBeginImplFrameDeadline(); 1217 state.OnBeginImplFrameDeadline();
1217 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1218 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1218 1219
1219 // While context is recreating, commits shouldn't begin. 1220 // While context is recreating, commits shouldn't begin.
1220 state.SetNeedsCommit(); 1221 state.SetNeedsCommit();
1221 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 1222 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting());
1222 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1223 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1223 state.OnBeginImplFrameDeadline(); 1224 state.OnBeginImplFrameDeadline();
1224 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1225 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1225 1226
1226 // Recreate the context 1227 // Recreate the context
1227 state.DidCreateAndInitializeOutputSurface(); 1228 state.DidCreateAndInitializeOutputSurface();
1228 EXPECT_FALSE(state.RedrawPending()); 1229 EXPECT_FALSE(state.RedrawPending());
1229 1230
1230 // When the context is recreated, we should begin a commit 1231 // When the context is recreated, we should begin a commit
1231 EXPECT_ACTION_UPDATE_STATE( 1232 EXPECT_ACTION_UPDATE_STATE(
1232 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 1233 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
1233 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1234 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1234 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT, 1235 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT,
1235 state.CommitState()); 1236 state.CommitState());
1236 1237
1237 state.NotifyBeginMainFrameStarted(); 1238 state.NotifyBeginMainFrameStarted();
1238 state.NotifyReadyToCommit(); 1239 state.NotifyReadyToCommit();
1239 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 1240 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
1240 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1241 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1241 // Finishing the first commit after initializing an output surface should 1242 // Finishing the first commit after initializing an output surface should
1242 // automatically cause a redraw. 1243 // automatically cause a redraw.
1243 EXPECT_TRUE(state.RedrawPending()); 1244 EXPECT_TRUE(state.RedrawPending());
1244 1245
1245 // Once the context is recreated, whether we draw should be based on 1246 // Once the context is recreated, whether we draw should be based on
1246 // SetCanDraw. 1247 // SetCanDraw.
1247 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 1248 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting());
1248 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE); 1249 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
1249 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1250 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1250 state.OnBeginImplFrameDeadline(); 1251 state.OnBeginImplFrameDeadline();
1251 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE, 1252 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE,
1252 state.NextAction()); 1253 state.NextAction());
1253 state.SetCanDraw(false); 1254 state.SetCanDraw(false);
1254 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT, 1255 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT,
1255 state.NextAction()); 1256 state.NextAction());
1256 state.SetCanDraw(true); 1257 state.SetCanDraw(true);
1257 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE, 1258 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE,
1258 state.NextAction()); 1259 state.NextAction());
1259 } 1260 }
1260 1261
1261 TEST(SchedulerStateMachineTest, TestContextLostWhileCommitInProgress) { 1262 TEST(SchedulerStateMachineTest, TestContextLostWhileCommitInProgress) {
1262 SchedulerSettings scheduler_settings; 1263 SchedulerSettings scheduler_settings;
1263 StateMachine state(scheduler_settings); 1264 StateMachine state(scheduler_settings);
1264 state.SetCanStart(); 1265 state.SetCanStart();
1265 state.UpdateState(state.NextAction()); 1266 state.UpdateState(state.NextAction());
1266 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 1267 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
1267 state.SetVisible(true); 1268 state.SetVisible(true);
1268 state.SetCanDraw(true); 1269 state.SetCanDraw(true);
1269 1270
1270 // Get a commit in flight. 1271 // Get a commit in flight.
1271 state.SetNeedsCommit(); 1272 state.SetNeedsCommit();
1272 1273
1273 // Set damage and expect a draw. 1274 // Set damage and expect a draw.
1274 state.SetNeedsRedraw(true); 1275 state.SetNeedsRedraw(true);
1275 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 1276 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting());
1276 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE); 1277 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
1277 EXPECT_ACTION_UPDATE_STATE( 1278 EXPECT_ACTION_UPDATE_STATE(
1278 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 1279 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
1279 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1280 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1280 state.OnBeginImplFrameDeadline(); 1281 state.OnBeginImplFrameDeadline();
1281 EXPECT_ACTION_UPDATE_STATE( 1282 EXPECT_ACTION_UPDATE_STATE(
1282 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 1283 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
1283 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1284 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1284 1285
1285 // Cause a lost context while the BeginMainFrame is in flight. 1286 // Cause a lost context while the BeginMainFrame is in flight.
(...skipping 12 matching lines...) Expand all
1298 // waiting for the first draw to unblock the main thread. 1299 // waiting for the first draw to unblock the main thread.
1299 EXPECT_TRUE(state.active_tree_needs_first_draw()); 1300 EXPECT_TRUE(state.active_tree_needs_first_draw());
1300 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT); 1301 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT);
1301 1302
1302 // Expect to begin context recreation only in BEGIN_IMPL_FRAME_STATE_IDLE 1303 // Expect to begin context recreation only in BEGIN_IMPL_FRAME_STATE_IDLE
1303 EXPECT_EQ(SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE, 1304 EXPECT_EQ(SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE,
1304 state.begin_impl_frame_state()); 1305 state.begin_impl_frame_state());
1305 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION, 1306 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION,
1306 state.NextAction()); 1307 state.NextAction());
1307 1308
1308 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 1309 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting());
1309 EXPECT_EQ(SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_BEGIN_FRAME_STARTING, 1310 EXPECT_EQ(SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_BEGIN_FRAME_STARTING,
1310 state.begin_impl_frame_state()); 1311 state.begin_impl_frame_state());
1311 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); 1312 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction());
1312 1313
1313 state.OnBeginImplFrameDeadlinePending(); 1314 state.OnBeginImplFrameDeadlinePending();
1314 EXPECT_EQ(SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_BEGIN_FRAME, 1315 EXPECT_EQ(SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_BEGIN_FRAME,
1315 state.begin_impl_frame_state()); 1316 state.begin_impl_frame_state());
1316 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); 1317 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction());
1317 1318
1318 state.OnBeginImplFrameDeadline(); 1319 state.OnBeginImplFrameDeadline();
(...skipping 11 matching lines...) Expand all
1330 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 1331 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
1331 state.SetVisible(true); 1332 state.SetVisible(true);
1332 state.SetCanDraw(true); 1333 state.SetCanDraw(true);
1333 1334
1334 // Get a commit in flight. 1335 // Get a commit in flight.
1335 state.SetNeedsCommit(); 1336 state.SetNeedsCommit();
1336 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1337 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1337 1338
1338 // Set damage and expect a draw. 1339 // Set damage and expect a draw.
1339 state.SetNeedsRedraw(true); 1340 state.SetNeedsRedraw(true);
1340 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 1341 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting());
1341 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE); 1342 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
1342 EXPECT_ACTION_UPDATE_STATE( 1343 EXPECT_ACTION_UPDATE_STATE(
1343 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 1344 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
1344 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1345 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1345 state.OnBeginImplFrameDeadline(); 1346 state.OnBeginImplFrameDeadline();
1346 EXPECT_ACTION_UPDATE_STATE( 1347 EXPECT_ACTION_UPDATE_STATE(
1347 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 1348 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
1348 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1349 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1349 1350
1350 // Cause a lost context while the BeginMainFrame is in flight. 1351 // Cause a lost context while the BeginMainFrame is in flight.
(...skipping 12 matching lines...) Expand all
1363 1364
1364 // Because the output surface is missing, we expect the draw to abort. 1365 // Because the output surface is missing, we expect the draw to abort.
1365 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT); 1366 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT);
1366 1367
1367 // Expect to begin context recreation only in BEGIN_IMPL_FRAME_STATE_IDLE 1368 // Expect to begin context recreation only in BEGIN_IMPL_FRAME_STATE_IDLE
1368 EXPECT_EQ(SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE, 1369 EXPECT_EQ(SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE,
1369 state.begin_impl_frame_state()); 1370 state.begin_impl_frame_state());
1370 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION, 1371 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION,
1371 state.NextAction()); 1372 state.NextAction());
1372 1373
1373 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 1374 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting());
1374 EXPECT_EQ(SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_BEGIN_FRAME_STARTING, 1375 EXPECT_EQ(SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_BEGIN_FRAME_STARTING,
1375 state.begin_impl_frame_state()); 1376 state.begin_impl_frame_state());
1376 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); 1377 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction());
1377 1378
1378 state.OnBeginImplFrameDeadlinePending(); 1379 state.OnBeginImplFrameDeadlinePending();
1379 EXPECT_EQ(SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_BEGIN_FRAME, 1380 EXPECT_EQ(SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_BEGIN_FRAME,
1380 state.begin_impl_frame_state()); 1381 state.begin_impl_frame_state());
1381 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); 1382 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction());
1382 1383
1383 state.OnBeginImplFrameDeadline(); 1384 state.OnBeginImplFrameDeadline();
1384 EXPECT_EQ(SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE, 1385 EXPECT_EQ(SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE,
1385 state.begin_impl_frame_state()); 1386 state.begin_impl_frame_state());
1386 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); 1387 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction());
1387 1388
1388 state.OnBeginImplFrameIdle(); 1389 state.OnBeginImplFrameIdle();
1389 EXPECT_ACTION_UPDATE_STATE( 1390 EXPECT_ACTION_UPDATE_STATE(
1390 SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION); 1391 SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION);
1391 1392
1392 // After we get a new output surface, the commit flow should start. 1393 // After we get a new output surface, the commit flow should start.
1393 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 1394 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
1394 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 1395 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting());
1395 EXPECT_ACTION_UPDATE_STATE( 1396 EXPECT_ACTION_UPDATE_STATE(
1396 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 1397 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
1397 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1398 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1398 state.NotifyBeginMainFrameStarted(); 1399 state.NotifyBeginMainFrameStarted();
1399 state.NotifyReadyToCommit(); 1400 state.NotifyReadyToCommit();
1400 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 1401 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
1401 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1402 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1402 state.OnBeginImplFrameDeadline(); 1403 state.OnBeginImplFrameDeadline();
1403 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE); 1404 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
1404 EXPECT_ACTION_UPDATE_STATE( 1405 EXPECT_ACTION_UPDATE_STATE(
1405 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 1406 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
1406 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1407 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1407 } 1408 }
1408 1409
1409 TEST(SchedulerStateMachineTest, TestFinishAllRenderingWhileContextLost) { 1410 TEST(SchedulerStateMachineTest, TestFinishAllRenderingWhileContextLost) {
1410 SchedulerSettings default_scheduler_settings; 1411 SchedulerSettings default_scheduler_settings;
1411 StateMachine state(default_scheduler_settings); 1412 StateMachine state(default_scheduler_settings);
1412 state.SetCanStart(); 1413 state.SetCanStart();
1413 state.UpdateState(state.NextAction()); 1414 state.UpdateState(state.NextAction());
1414 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 1415 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
1415 state.SetVisible(true); 1416 state.SetVisible(true);
1416 state.SetCanDraw(true); 1417 state.SetCanDraw(true);
1417 1418
1418 // Cause a lost context lost. 1419 // Cause a lost context lost.
1419 state.DidLoseOutputSurface(); 1420 state.DidLoseOutputSurface();
1420 1421
1421 // Ask a forced redraw for readback and verify it ocurrs. 1422 // Ask a forced redraw for readback and verify it ocurrs.
1422 state.SetNeedsForcedRedrawForReadback(); 1423 state.SetNeedsForcedRedrawForReadback();
1423 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 1424 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting());
1424 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_READBACK); 1425 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_READBACK);
1425 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1426 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1426 1427
1427 // Forced redraws for readbacks need to be followed by a new commit 1428 // Forced redraws for readbacks need to be followed by a new commit
1428 // to replace the readback commit. 1429 // to replace the readback commit.
1429 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT, 1430 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT,
1430 state.CommitState()); 1431 state.CommitState());
1431 state.NotifyBeginMainFrameStarted(); 1432 state.NotifyBeginMainFrameStarted();
1432 state.NotifyReadyToCommit(); 1433 state.NotifyReadyToCommit();
1433 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 1434 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
(...skipping 29 matching lines...) Expand all
1463 state.SetNeedsRedraw(true); 1464 state.SetNeedsRedraw(true);
1464 1465
1465 // Cause a lost output surface, and restore it. 1466 // Cause a lost output surface, and restore it.
1466 state.DidLoseOutputSurface(); 1467 state.DidLoseOutputSurface();
1467 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION, 1468 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION,
1468 state.NextAction()); 1469 state.NextAction());
1469 state.UpdateState(state.NextAction()); 1470 state.UpdateState(state.NextAction());
1470 state.DidCreateAndInitializeOutputSurface(); 1471 state.DidCreateAndInitializeOutputSurface();
1471 1472
1472 EXPECT_FALSE(state.RedrawPending()); 1473 EXPECT_FALSE(state.RedrawPending());
1473 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 1474 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting());
1474 EXPECT_EQ(SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME, 1475 EXPECT_EQ(SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME,
1475 state.NextAction()); 1476 state.NextAction());
1476 } 1477 }
1477 1478
1478 TEST(SchedulerStateMachineTest, 1479 TEST(SchedulerStateMachineTest,
1479 TestPendingActivationsShouldBeForcedAfterLostOutputSurface) { 1480 TestPendingActivationsShouldBeForcedAfterLostOutputSurface) {
1480 SchedulerSettings settings; 1481 SchedulerSettings settings;
1481 settings.impl_side_painting = true; 1482 settings.impl_side_painting = true;
1482 StateMachine state(settings); 1483 StateMachine state(settings);
1483 state.SetCanStart(); 1484 state.SetCanStart();
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
1556 SchedulerStateMachine::READBACK_STATE_WAITING_FOR_REPLACEMENT_COMMIT, 1557 SchedulerStateMachine::READBACK_STATE_WAITING_FOR_REPLACEMENT_COMMIT,
1557 state.readback_state()); 1558 state.readback_state());
1558 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT, 1559 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT,
1559 state.CommitState()); 1560 state.CommitState());
1560 1561
1561 // Finish the replacement commit. 1562 // Finish the replacement commit.
1562 state.NotifyBeginMainFrameStarted(); 1563 state.NotifyBeginMainFrameStarted();
1563 state.NotifyReadyToCommit(); 1564 state.NotifyReadyToCommit();
1564 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 1565 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
1565 1566
1566 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 1567 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting());
1567 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE); 1568 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
1568 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1569 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1569 state.OnBeginImplFrameDeadline(); 1570 state.OnBeginImplFrameDeadline();
1570 EXPECT_ACTION_UPDATE_STATE( 1571 EXPECT_ACTION_UPDATE_STATE(
1571 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 1572 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
1572 EXPECT_EQ(SchedulerStateMachine::READBACK_STATE_IDLE, state.readback_state()); 1573 EXPECT_EQ(SchedulerStateMachine::READBACK_STATE_IDLE, state.readback_state());
1573 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1574 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1574 } 1575 }
1575 1576
1576 TEST(SchedulerStateMachineTest, TestFinishCommitWhenCommitInProgress) { 1577 TEST(SchedulerStateMachineTest, TestFinishCommitWhenCommitInProgress) {
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
1661 if (settings.main_frame_before_draw_enabled) { 1662 if (settings.main_frame_before_draw_enabled) {
1662 // New replacement commit is scheduled. 1663 // New replacement commit is scheduled.
1663 EXPECT_ACTION_UPDATE_STATE( 1664 EXPECT_ACTION_UPDATE_STATE(
1664 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 1665 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
1665 // Forced commit is started. 1666 // Forced commit is started.
1666 EXPECT_EQ(SchedulerStateMachine::READBACK_STATE_WAITING_FOR_COMMIT, 1667 EXPECT_EQ(SchedulerStateMachine::READBACK_STATE_WAITING_FOR_COMMIT,
1667 state.readback_state()); 1668 state.readback_state());
1668 } 1669 }
1669 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1670 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1670 1671
1671 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 1672 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting());
1672 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE); 1673 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
1673 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1674 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1674 // Perform the draw & swap of replacement commit. 1675 // Perform the draw & swap of replacement commit.
1675 state.OnBeginImplFrameDeadline(); 1676 state.OnBeginImplFrameDeadline();
1676 EXPECT_ACTION_UPDATE_STATE( 1677 EXPECT_ACTION_UPDATE_STATE(
1677 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 1678 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
1678 if (!settings.main_frame_before_draw_enabled) { 1679 if (!settings.main_frame_before_draw_enabled) {
1679 // New replacement commit is scheduled. 1680 // New replacement commit is scheduled.
1680 EXPECT_ACTION_UPDATE_STATE( 1681 EXPECT_ACTION_UPDATE_STATE(
1681 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 1682 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
(...skipping 19 matching lines...) Expand all
1701 state.CommitState()); 1702 state.CommitState());
1702 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1703 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1703 1704
1704 // Finish the replacement commit and draw it. 1705 // Finish the replacement commit and draw it.
1705 state.NotifyBeginMainFrameStarted(); 1706 state.NotifyBeginMainFrameStarted();
1706 state.NotifyReadyToCommit(); 1707 state.NotifyReadyToCommit();
1707 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 1708 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
1708 state.NotifyReadyToActivate(); 1709 state.NotifyReadyToActivate();
1709 EXPECT_ACTION_UPDATE_STATE( 1710 EXPECT_ACTION_UPDATE_STATE(
1710 SchedulerStateMachine::ACTION_ACTIVATE_PENDING_TREE); 1711 SchedulerStateMachine::ACTION_ACTIVATE_PENDING_TREE);
1711 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 1712 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting());
1712 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE); 1713 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
1713 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1714 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1714 state.OnBeginImplFrameDeadline(); 1715 state.OnBeginImplFrameDeadline();
1715 EXPECT_ACTION_UPDATE_STATE( 1716 EXPECT_ACTION_UPDATE_STATE(
1716 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 1717 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
1717 EXPECT_EQ(SchedulerStateMachine::READBACK_STATE_IDLE, state.readback_state()); 1718 EXPECT_EQ(SchedulerStateMachine::READBACK_STATE_IDLE, state.readback_state());
1718 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1719 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1719 } 1720 }
1720 1721
1721 // Explicitly test when main_frame_before_draw_enabled = true. 1722 // Explicitly test when main_frame_before_draw_enabled = true.
(...skipping 29 matching lines...) Expand all
1751 // is idle because main_frame_before_activation is enabled. 1752 // is idle because main_frame_before_activation is enabled.
1752 state.SetCommitState( 1753 state.SetCommitState(
1753 SchedulerStateMachine::COMMIT_STATE_IDLE); 1754 SchedulerStateMachine::COMMIT_STATE_IDLE);
1754 state.SetReadbackState( 1755 state.SetReadbackState(
1755 SchedulerStateMachine::READBACK_STATE_WAITING_FOR_REPLACEMENT_ACTIVATION); 1756 SchedulerStateMachine::READBACK_STATE_WAITING_FOR_REPLACEMENT_ACTIVATION);
1756 state.SetHasPendingTree(true); 1757 state.SetHasPendingTree(true);
1757 1758
1758 // New commit is requested and scheduled when impl-side painting is in 1759 // New commit is requested and scheduled when impl-side painting is in
1759 // progress. 1760 // progress.
1760 state.SetNeedsCommit(); 1761 state.SetNeedsCommit();
1761 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 1762 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting());
1762 EXPECT_ACTION_UPDATE_STATE( 1763 EXPECT_ACTION_UPDATE_STATE(
1763 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 1764 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
1764 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1765 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1765 1766
1766 // Forced commit is requested during the impl-side painting. 1767 // Forced commit is requested during the impl-side painting.
1767 state.SetNeedsForcedCommitForReadback(); 1768 state.SetNeedsForcedCommitForReadback();
1768 EXPECT_FALSE(state.NeedsCommit()); 1769 EXPECT_FALSE(state.NeedsCommit());
1769 1770
1770 state.OnBeginImplFrameDeadline(); 1771 state.OnBeginImplFrameDeadline();
1771 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1772 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1772 1773
1773 state.NotifyReadyToActivate(); 1774 state.NotifyReadyToActivate();
1774 EXPECT_ACTION_UPDATE_STATE( 1775 EXPECT_ACTION_UPDATE_STATE(
1775 SchedulerStateMachine::ACTION_ACTIVATE_PENDING_TREE); 1776 SchedulerStateMachine::ACTION_ACTIVATE_PENDING_TREE);
1776 // Replacement commit for requested forced commit is already scheduled. 1777 // Replacement commit for requested forced commit is already scheduled.
1777 EXPECT_EQ(SchedulerStateMachine::READBACK_STATE_WAITING_FOR_COMMIT, 1778 EXPECT_EQ(SchedulerStateMachine::READBACK_STATE_WAITING_FOR_COMMIT,
1778 state.readback_state()); 1779 state.readback_state());
1779 EXPECT_FALSE(state.NeedsCommit()); 1780 EXPECT_FALSE(state.NeedsCommit());
1780 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1781 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1781 1782
1782 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 1783 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting());
1783 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE); 1784 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
1784 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1785 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1785 // Perform the draw & swap of replacement commit. 1786 // Perform the draw & swap of replacement commit.
1786 state.OnBeginImplFrameDeadline(); 1787 state.OnBeginImplFrameDeadline();
1787 EXPECT_ACTION_UPDATE_STATE( 1788 EXPECT_ACTION_UPDATE_STATE(
1788 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 1789 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
1789 EXPECT_ACTION_UPDATE_STATE( 1790 EXPECT_ACTION_UPDATE_STATE(
1790 SchedulerStateMachine::ACTION_NONE); 1791 SchedulerStateMachine::ACTION_NONE);
1791 1792
1792 // forced commit is started. 1793 // forced commit is started.
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
2003 settings.impl_side_painting = true; 2004 settings.impl_side_painting = true;
2004 StateMachine state(settings); 2005 StateMachine state(settings);
2005 state.SetCanStart(); 2006 state.SetCanStart();
2006 state.UpdateState(state.NextAction()); 2007 state.UpdateState(state.NextAction());
2007 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 2008 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
2008 state.SetVisible(true); 2009 state.SetVisible(true);
2009 state.SetCanDraw(true); 2010 state.SetCanDraw(true);
2010 2011
2011 // This test mirrors what happens during the first frame of a scroll gesture. 2012 // This test mirrors what happens during the first frame of a scroll gesture.
2012 // First we get the input event and a BeginFrame. 2013 // First we get the input event and a BeginFrame.
2013 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 2014 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting());
2014 2015
2015 // As a response the compositor requests a redraw and a commit to tell the 2016 // As a response the compositor requests a redraw and a commit to tell the
2016 // main thread about the new scroll offset. 2017 // main thread about the new scroll offset.
2017 state.SetNeedsRedraw(true); 2018 state.SetNeedsRedraw(true);
2018 state.SetNeedsCommit(); 2019 state.SetNeedsCommit();
2019 2020
2020 // We should start the commit normally. 2021 // We should start the commit normally.
2021 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE); 2022 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
2022 EXPECT_ACTION_UPDATE_STATE( 2023 EXPECT_ACTION_UPDATE_STATE(
2023 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 2024 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
(...skipping 13 matching lines...) Expand all
2037 settings.impl_side_painting = true; 2038 settings.impl_side_painting = true;
2038 StateMachine state(settings); 2039 StateMachine state(settings);
2039 state.SetCanStart(); 2040 state.SetCanStart();
2040 state.UpdateState(state.NextAction()); 2041 state.UpdateState(state.NextAction());
2041 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 2042 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
2042 state.SetVisible(true); 2043 state.SetVisible(true);
2043 state.SetCanDraw(true); 2044 state.SetCanDraw(true);
2044 2045
2045 // This test ensures that impl-draws are prioritized over main thread updates 2046 // This test ensures that impl-draws are prioritized over main thread updates
2046 // in prefer smoothness mode. 2047 // in prefer smoothness mode.
2047 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 2048 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting());
2048 state.SetNeedsRedraw(true); 2049 state.SetNeedsRedraw(true);
2049 state.SetNeedsCommit(); 2050 state.SetNeedsCommit();
2050 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE); 2051 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
2051 EXPECT_ACTION_UPDATE_STATE( 2052 EXPECT_ACTION_UPDATE_STATE(
2052 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 2053 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
2053 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 2054 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
2054 2055
2055 // The deadline is not triggered early until we enter prefer smoothness mode. 2056 // The deadline is not triggered early until we enter prefer smoothness mode.
2056 EXPECT_FALSE(state.ShouldTriggerBeginImplFrameDeadlineEarly()); 2057 EXPECT_FALSE(state.ShouldTriggerBeginImplFrameDeadlineEarly());
2057 state.SetSmoothnessTakesPriority(true); 2058 state.SetSmoothnessTakesPriority(true);
2058 EXPECT_TRUE(state.ShouldTriggerBeginImplFrameDeadlineEarly()); 2059 EXPECT_TRUE(state.ShouldTriggerBeginImplFrameDeadlineEarly());
2059 } 2060 }
2060 2061
2061 TEST(SchedulerStateMachineTest, TestSetNeedsAnimate) { 2062 TEST(SchedulerStateMachineTest, TestSetNeedsAnimate) {
2062 SchedulerSettings settings; 2063 SchedulerSettings settings;
2063 settings.impl_side_painting = true; 2064 settings.impl_side_painting = true;
2064 StateMachine state(settings); 2065 StateMachine state(settings);
2065 state.SetCanStart(); 2066 state.SetCanStart();
2066 state.UpdateState(state.NextAction()); 2067 state.UpdateState(state.NextAction());
2067 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 2068 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
2068 state.SetVisible(true); 2069 state.SetVisible(true);
2069 state.SetCanDraw(true); 2070 state.SetCanDraw(true);
2070 2071
2071 // Test requesting an animation that, when run, causes us to draw. 2072 // Test requesting an animation that, when run, causes us to draw.
2072 state.SetNeedsAnimate(); 2073 state.SetNeedsAnimate();
2073 EXPECT_TRUE(state.BeginFrameNeeded()); 2074 EXPECT_TRUE(state.BeginFrameNeeded());
2074 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 2075 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
2075 2076
2076 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 2077 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting());
2077 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE); 2078 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
2078 2079
2079 state.OnBeginImplFrameDeadlinePending(); 2080 state.OnBeginImplFrameDeadlinePending();
2080 state.OnBeginImplFrameDeadline(); 2081 state.OnBeginImplFrameDeadline();
2081 EXPECT_ACTION_UPDATE_STATE( 2082 EXPECT_ACTION_UPDATE_STATE(
2082 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 2083 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
2083 } 2084 }
2084 2085
2085 TEST(SchedulerStateMachineTest, TestAnimateBeforeCommit) { 2086 TEST(SchedulerStateMachineTest, TestAnimateBeforeCommit) {
2086 SchedulerSettings settings; 2087 SchedulerSettings settings;
2087 settings.impl_side_painting = true; 2088 settings.impl_side_painting = true;
2088 StateMachine state(settings); 2089 StateMachine state(settings);
2089 state.SetCanStart(); 2090 state.SetCanStart();
2090 state.UpdateState(state.NextAction()); 2091 state.UpdateState(state.NextAction());
2091 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 2092 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
2092 state.SetVisible(true); 2093 state.SetVisible(true);
2093 state.SetCanDraw(true); 2094 state.SetCanDraw(true);
2094 2095
2095 // Check that animations are updated before we start a commit. 2096 // Check that animations are updated before we start a commit.
2096 state.SetNeedsAnimate(); 2097 state.SetNeedsAnimate();
2097 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 2098 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
2098 state.SetNeedsCommit(); 2099 state.SetNeedsCommit();
2099 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 2100 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
2100 EXPECT_TRUE(state.BeginFrameNeeded()); 2101 EXPECT_TRUE(state.BeginFrameNeeded());
2101 2102
2102 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 2103 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting());
2103 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE); 2104 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
2104 EXPECT_ACTION_UPDATE_STATE( 2105 EXPECT_ACTION_UPDATE_STATE(
2105 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 2106 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
2106 2107
2107 state.OnBeginImplFrameDeadlinePending(); 2108 state.OnBeginImplFrameDeadlinePending();
2108 state.OnBeginImplFrameDeadline(); 2109 state.OnBeginImplFrameDeadline();
2109 EXPECT_ACTION_UPDATE_STATE( 2110 EXPECT_ACTION_UPDATE_STATE(
2110 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 2111 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
2111 } 2112 }
2112 2113
2113 TEST(SchedulerStateMachineTest, TestSetNeedsAnimateAfterAnimate) { 2114 TEST(SchedulerStateMachineTest, TestSetNeedsAnimateAfterAnimate) {
2114 SchedulerSettings settings; 2115 SchedulerSettings settings;
2115 settings.impl_side_painting = true; 2116 settings.impl_side_painting = true;
2116 StateMachine state(settings); 2117 StateMachine state(settings);
2117 state.SetCanStart(); 2118 state.SetCanStart();
2118 state.UpdateState(state.NextAction()); 2119 state.UpdateState(state.NextAction());
2119 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 2120 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
2120 state.SetVisible(true); 2121 state.SetVisible(true);
2121 state.SetCanDraw(true); 2122 state.SetCanDraw(true);
2122 2123
2123 // Test requesting an animation after we have already animated during this 2124 // Test requesting an animation after we have already animated during this
2124 // frame. 2125 // frame.
2125 state.SetNeedsRedraw(true); 2126 state.SetNeedsRedraw(true);
2126 EXPECT_TRUE(state.BeginFrameNeeded()); 2127 EXPECT_TRUE(state.BeginFrameNeeded());
2127 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 2128 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
2128 2129
2129 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 2130 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting());
2130 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE); 2131 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
2131 2132
2132 state.SetNeedsAnimate(); 2133 state.SetNeedsAnimate();
2133 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 2134 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
2134 2135
2135 state.OnBeginImplFrameDeadline(); 2136 state.OnBeginImplFrameDeadline();
2136 EXPECT_ACTION_UPDATE_STATE( 2137 EXPECT_ACTION_UPDATE_STATE(
2137 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 2138 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
2138 } 2139 }
2139 2140
2140 } // namespace 2141 } // namespace
2141 } // namespace cc 2142 } // namespace cc
OLDNEW
« no previous file with comments | « cc/output/output_surface_unittest.cc ('k') | cc/scheduler/scheduler_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698