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

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

Issue 206793003: cc: Split animating and drawing into separate actions (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix input handler proxy test build. 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/scheduler/scheduler_state_machine.cc ('k') | cc/scheduler/scheduler_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2011 The Chromium Authors. All rights reserved. 1 // Copyright 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "cc/scheduler/scheduler_state_machine.h" 5 #include "cc/scheduler/scheduler_state_machine.h"
6 6
7 #include "cc/scheduler/scheduler.h" 7 #include "cc/scheduler/scheduler.h"
8 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
9 9
10 #define EXPECT_ACTION_UPDATE_STATE(action) \ 10 #define EXPECT_ACTION_UPDATE_STATE(action) \
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 // commit in that order. 230 // commit in that order.
231 state.NotifyReadyToActivate(); 231 state.NotifyReadyToActivate();
232 EXPECT_ACTION_UPDATE_STATE( 232 EXPECT_ACTION_UPDATE_STATE(
233 SchedulerStateMachine::ACTION_ACTIVATE_PENDING_TREE); 233 SchedulerStateMachine::ACTION_ACTIVATE_PENDING_TREE);
234 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 234 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
235 EXPECT_EQ(state.CommitState(), 235 EXPECT_EQ(state.CommitState(),
236 SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW); 236 SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW);
237 237
238 EXPECT_TRUE(state.ShouldTriggerBeginImplFrameDeadlineEarly()); 238 EXPECT_TRUE(state.ShouldTriggerBeginImplFrameDeadlineEarly());
239 state.OnBeginImplFrameDeadline(); 239 state.OnBeginImplFrameDeadline();
240 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
240 EXPECT_ACTION_UPDATE_STATE( 241 EXPECT_ACTION_UPDATE_STATE(
241 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 242 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
242 EXPECT_EQ(state.CommitState(), SchedulerStateMachine::COMMIT_STATE_IDLE); 243 EXPECT_EQ(state.CommitState(), SchedulerStateMachine::COMMIT_STATE_IDLE);
243 EXPECT_ACTION_UPDATE_STATE( 244 EXPECT_ACTION_UPDATE_STATE(
244 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 245 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
245 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 246 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
246 EXPECT_EQ(state.CommitState(), 247 EXPECT_EQ(state.CommitState(),
247 SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT); 248 SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT);
248 249
249 state.NotifyBeginMainFrameStarted(); 250 state.NotifyBeginMainFrameStarted();
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 302
302 // Verify NotifyReadyToActivate unblocks activation, draw, and 303 // Verify NotifyReadyToActivate unblocks activation, draw, and
303 // commit in that order. 304 // commit in that order.
304 state.NotifyReadyToActivate(); 305 state.NotifyReadyToActivate();
305 EXPECT_ACTION_UPDATE_STATE( 306 EXPECT_ACTION_UPDATE_STATE(
306 SchedulerStateMachine::ACTION_ACTIVATE_PENDING_TREE); 307 SchedulerStateMachine::ACTION_ACTIVATE_PENDING_TREE);
307 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 308 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
308 309
309 EXPECT_TRUE(state.ShouldTriggerBeginImplFrameDeadlineEarly()); 310 EXPECT_TRUE(state.ShouldTriggerBeginImplFrameDeadlineEarly());
310 state.OnBeginImplFrameDeadline(); 311 state.OnBeginImplFrameDeadline();
312 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
311 EXPECT_ACTION_UPDATE_STATE( 313 EXPECT_ACTION_UPDATE_STATE(
312 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 314 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
313 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 315 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
314 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 316 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
315 EXPECT_EQ(state.CommitState(), SchedulerStateMachine::COMMIT_STATE_IDLE); 317 EXPECT_EQ(state.CommitState(), SchedulerStateMachine::COMMIT_STATE_IDLE);
316 } 318 }
317 319
318 TEST(SchedulerStateMachineTest, 320 TEST(SchedulerStateMachineTest,
319 TestFailedDrawForAnimationCheckerboardSetsNeedsCommitAndDoesNotDrawAgain) { 321 TestFailedDrawForAnimationCheckerboardSetsNeedsCommitAndDoesNotDrawAgain) {
320 SchedulerSettings default_scheduler_settings; 322 SchedulerSettings default_scheduler_settings;
321 StateMachine state(default_scheduler_settings); 323 StateMachine state(default_scheduler_settings);
322 state.SetCanStart(); 324 state.SetCanStart();
323 state.UpdateState(state.NextAction()); 325 state.UpdateState(state.NextAction());
324 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 326 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
325 state.SetVisible(true); 327 state.SetVisible(true);
326 state.SetCanDraw(true); 328 state.SetCanDraw(true);
327 state.SetNeedsRedraw(true); 329 state.SetNeedsRedraw(true);
328 EXPECT_TRUE(state.RedrawPending()); 330 EXPECT_TRUE(state.RedrawPending());
329 EXPECT_TRUE(state.BeginFrameNeeded()); 331 EXPECT_TRUE(state.BeginFrameNeeded());
330 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 332 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting());
333 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
331 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 334 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
332 state.OnBeginImplFrameDeadline(); 335 state.OnBeginImplFrameDeadline();
333 336
334 // We're drawing now. 337 // We're drawing now.
335 EXPECT_ACTION_UPDATE_STATE( 338 EXPECT_ACTION_UPDATE_STATE(
336 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 339 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
337 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 340 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
338 341
339 EXPECT_FALSE(state.RedrawPending()); 342 EXPECT_FALSE(state.RedrawPending());
340 EXPECT_FALSE(state.CommitPending()); 343 EXPECT_FALSE(state.CommitPending());
341 344
342 // Failing the draw makes us require a commit. 345 // Failing the draw makes us require a commit.
343 state.DidDrawIfPossibleCompleted( 346 state.DidDrawIfPossibleCompleted(
344 DrawSwapReadbackResult::DRAW_ABORTED_CHECKERBOARD_ANIMATIONS); 347 DrawSwapReadbackResult::DRAW_ABORTED_CHECKERBOARD_ANIMATIONS);
345 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 348 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting());
349 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
346 EXPECT_ACTION_UPDATE_STATE( 350 EXPECT_ACTION_UPDATE_STATE(
347 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 351 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
348 EXPECT_TRUE(state.RedrawPending()); 352 EXPECT_TRUE(state.RedrawPending());
349 EXPECT_TRUE(state.CommitPending()); 353 EXPECT_TRUE(state.CommitPending());
350 } 354 }
351 355
352 TEST(SchedulerStateMachineTest, TestFailedDrawForMissingHighResNeedsCommit) { 356 TEST(SchedulerStateMachineTest, TestFailedDrawForMissingHighResNeedsCommit) {
353 SchedulerSettings default_scheduler_settings; 357 SchedulerSettings default_scheduler_settings;
354 StateMachine state(default_scheduler_settings); 358 StateMachine state(default_scheduler_settings);
355 state.SetCanStart(); 359 state.SetCanStart();
356 state.UpdateState(state.NextAction()); 360 state.UpdateState(state.NextAction());
357 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 361 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
358 state.SetVisible(true); 362 state.SetVisible(true);
359 state.SetCanDraw(true); 363 state.SetCanDraw(true);
360 state.SetNeedsRedraw(true); 364 state.SetNeedsRedraw(true);
361 EXPECT_TRUE(state.RedrawPending()); 365 EXPECT_TRUE(state.RedrawPending());
362 EXPECT_TRUE(state.BeginFrameNeeded()); 366 EXPECT_TRUE(state.BeginFrameNeeded());
363 367
364 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 368 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting());
369 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
365 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 370 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
366 state.OnBeginImplFrameDeadline(); 371 state.OnBeginImplFrameDeadline();
367 EXPECT_ACTION_UPDATE_STATE( 372 EXPECT_ACTION_UPDATE_STATE(
368 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 373 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
369 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 374 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
370 EXPECT_FALSE(state.RedrawPending()); 375 EXPECT_FALSE(state.RedrawPending());
371 EXPECT_FALSE(state.CommitPending()); 376 EXPECT_FALSE(state.CommitPending());
372 377
373 // Missing high res content requires a commit (but not a redraw) 378 // Missing high res content requires a commit (but not a redraw)
374 state.DidDrawIfPossibleCompleted( 379 state.DidDrawIfPossibleCompleted(
(...skipping 12 matching lines...) Expand all
387 state.SetCanStart(); 392 state.SetCanStart();
388 state.UpdateState(state.NextAction()); 393 state.UpdateState(state.NextAction());
389 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 394 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
390 395
391 state.SetVisible(true); 396 state.SetVisible(true);
392 state.SetCanDraw(true); 397 state.SetCanDraw(true);
393 state.SetNeedsRedraw(true); 398 state.SetNeedsRedraw(true);
394 EXPECT_TRUE(state.RedrawPending()); 399 EXPECT_TRUE(state.RedrawPending());
395 EXPECT_TRUE(state.BeginFrameNeeded()); 400 EXPECT_TRUE(state.BeginFrameNeeded());
396 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 401 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting());
402 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
397 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 403 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
398 state.OnBeginImplFrameDeadline(); 404 state.OnBeginImplFrameDeadline();
399 405
400 // We're drawing now. 406 // We're drawing now.
401 EXPECT_ACTION_UPDATE_STATE( 407 EXPECT_ACTION_UPDATE_STATE(
402 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 408 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
403 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 409 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
404 EXPECT_FALSE(state.RedrawPending()); 410 EXPECT_FALSE(state.RedrawPending());
405 EXPECT_FALSE(state.CommitPending()); 411 EXPECT_FALSE(state.CommitPending());
406 412
407 // While still in the same BeginMainFrame callback on the main thread, 413 // While still in the same BeginMainFrame callback on the main thread,
408 // set needs redraw again. This should not redraw. 414 // set needs redraw again. This should not redraw.
409 state.SetNeedsRedraw(true); 415 state.SetNeedsRedraw(true);
410 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 416 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
411 417
412 // Failing the draw for animation checkerboards makes us require a commit. 418 // Failing the draw for animation checkerboards makes us require a commit.
413 state.DidDrawIfPossibleCompleted( 419 state.DidDrawIfPossibleCompleted(
414 DrawSwapReadbackResult::DRAW_ABORTED_CHECKERBOARD_ANIMATIONS); 420 DrawSwapReadbackResult::DRAW_ABORTED_CHECKERBOARD_ANIMATIONS);
415 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 421 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting());
422 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
416 EXPECT_ACTION_UPDATE_STATE( 423 EXPECT_ACTION_UPDATE_STATE(
417 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 424 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
418 EXPECT_TRUE(state.RedrawPending()); 425 EXPECT_TRUE(state.RedrawPending());
419 } 426 }
420 427
421 void TestFailedDrawsEventuallyForceDrawAfterNextCommit( 428 void TestFailedDrawsEventuallyForceDrawAfterNextCommit(
422 bool main_frame_before_draw_enabled) { 429 bool main_frame_before_draw_enabled) {
423 SchedulerSettings scheduler_settings; 430 SchedulerSettings scheduler_settings;
424 scheduler_settings.main_frame_before_draw_enabled = 431 scheduler_settings.main_frame_before_draw_enabled =
425 main_frame_before_draw_enabled; 432 main_frame_before_draw_enabled;
(...skipping 10 matching lines...) Expand all
436 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 443 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
437 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 444 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting());
438 EXPECT_ACTION_UPDATE_STATE( 445 EXPECT_ACTION_UPDATE_STATE(
439 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 446 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
440 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 447 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
441 EXPECT_TRUE(state.CommitPending()); 448 EXPECT_TRUE(state.CommitPending());
442 449
443 // Then initiate a draw. 450 // Then initiate a draw.
444 state.SetNeedsRedraw(true); 451 state.SetNeedsRedraw(true);
445 state.OnBeginImplFrameDeadline(); 452 state.OnBeginImplFrameDeadline();
453 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
446 EXPECT_ACTION_UPDATE_STATE( 454 EXPECT_ACTION_UPDATE_STATE(
447 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 455 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
448 456
449 // Fail the draw. 457 // Fail the draw.
450 state.DidDrawIfPossibleCompleted( 458 state.DidDrawIfPossibleCompleted(
451 DrawSwapReadbackResult::DRAW_ABORTED_CHECKERBOARD_ANIMATIONS); 459 DrawSwapReadbackResult::DRAW_ABORTED_CHECKERBOARD_ANIMATIONS);
452 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 460 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
453 EXPECT_TRUE(state.BeginFrameNeeded()); 461 EXPECT_TRUE(state.BeginFrameNeeded());
454 EXPECT_TRUE(state.RedrawPending()); 462 EXPECT_TRUE(state.RedrawPending());
455 // But the commit is ongoing. 463 // But the commit is ongoing.
456 EXPECT_TRUE(state.CommitPending()); 464 EXPECT_TRUE(state.CommitPending());
457 465
458 // Finish the commit. Note, we should not yet be forcing a draw, but should 466 // Finish the commit. Note, we should not yet be forcing a draw, but should
459 // continue the commit as usual. 467 // continue the commit as usual.
460 state.NotifyBeginMainFrameStarted(); 468 state.NotifyBeginMainFrameStarted();
461 state.NotifyReadyToCommit(); 469 state.NotifyReadyToCommit();
462 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 470 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
463 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 471 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
464 EXPECT_TRUE(state.RedrawPending()); 472 EXPECT_TRUE(state.RedrawPending());
465 473
466 // The redraw should be forced at the end of the next BeginImplFrame. 474 // The redraw should be forced at the end of the next BeginImplFrame.
467 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 475 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting());
476 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
468 if (main_frame_before_draw_enabled) { 477 if (main_frame_before_draw_enabled) {
469 EXPECT_ACTION_UPDATE_STATE( 478 EXPECT_ACTION_UPDATE_STATE(
470 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 479 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
471 } 480 }
472 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 481 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
473 state.OnBeginImplFrameDeadline(); 482 state.OnBeginImplFrameDeadline();
474 EXPECT_ACTION_UPDATE_STATE( 483 EXPECT_ACTION_UPDATE_STATE(
475 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_FORCED); 484 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_FORCED);
476 } 485 }
477 486
(...skipping 29 matching lines...) Expand all
507 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 516 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
508 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 517 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting());
509 EXPECT_ACTION_UPDATE_STATE( 518 EXPECT_ACTION_UPDATE_STATE(
510 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 519 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
511 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 520 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
512 EXPECT_TRUE(state.CommitPending()); 521 EXPECT_TRUE(state.CommitPending());
513 522
514 // Then initiate a draw. 523 // Then initiate a draw.
515 state.SetNeedsRedraw(true); 524 state.SetNeedsRedraw(true);
516 state.OnBeginImplFrameDeadline(); 525 state.OnBeginImplFrameDeadline();
526 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
517 EXPECT_ACTION_UPDATE_STATE( 527 EXPECT_ACTION_UPDATE_STATE(
518 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 528 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
519 529
520 // Fail the draw enough times to force a redraw, 530 // Fail the draw enough times to force a redraw,
521 // then once more for good measure. 531 // then once more for good measure.
522 for (int i = 0; i < draw_limit + 1; ++i) { 532 for (int i = 0; i < draw_limit + 1; ++i) {
523 state.DidDrawIfPossibleCompleted( 533 state.DidDrawIfPossibleCompleted(
524 DrawSwapReadbackResult::DRAW_ABORTED_CHECKERBOARD_ANIMATIONS); 534 DrawSwapReadbackResult::DRAW_ABORTED_CHECKERBOARD_ANIMATIONS);
525 } 535 }
526 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 536 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
559 state.SetCanStart(); 569 state.SetCanStart();
560 state.UpdateState(state.NextAction()); 570 state.UpdateState(state.NextAction());
561 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 571 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
562 state.SetVisible(true); 572 state.SetVisible(true);
563 state.SetCanDraw(true); 573 state.SetCanDraw(true);
564 574
565 // Start a draw. 575 // Start a draw.
566 state.SetNeedsRedraw(true); 576 state.SetNeedsRedraw(true);
567 EXPECT_TRUE(state.BeginFrameNeeded()); 577 EXPECT_TRUE(state.BeginFrameNeeded());
568 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 578 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting());
579 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
569 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 580 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
570 state.OnBeginImplFrameDeadline(); 581 state.OnBeginImplFrameDeadline();
571 EXPECT_TRUE(state.RedrawPending()); 582 EXPECT_TRUE(state.RedrawPending());
572 EXPECT_ACTION_UPDATE_STATE( 583 EXPECT_ACTION_UPDATE_STATE(
573 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 584 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
574 585
575 // Failing the draw for animation checkerboards makes us require a commit. 586 // Failing the draw for animation checkerboards makes us require a commit.
576 state.DidDrawIfPossibleCompleted( 587 state.DidDrawIfPossibleCompleted(
577 DrawSwapReadbackResult::DRAW_ABORTED_CHECKERBOARD_ANIMATIONS); 588 DrawSwapReadbackResult::DRAW_ABORTED_CHECKERBOARD_ANIMATIONS);
578 EXPECT_ACTION_UPDATE_STATE( 589 EXPECT_ACTION_UPDATE_STATE(
579 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 590 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
580 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 591 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
581 EXPECT_TRUE(state.RedrawPending()); 592 EXPECT_TRUE(state.RedrawPending());
582 593
583 // We should not be trying to draw again now, but we have a commit pending. 594 // We should not be trying to draw again now, but we have a commit pending.
584 EXPECT_TRUE(state.BeginFrameNeeded()); 595 EXPECT_TRUE(state.BeginFrameNeeded());
585 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 596 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting());
597 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
586 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 598 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
587 599
588 // We should try to draw again at the end of the next BeginImplFrame on 600 // We should try to draw again at the end of the next BeginImplFrame on
589 // the impl thread. 601 // the impl thread.
590 state.OnBeginImplFrameDeadline(); 602 state.OnBeginImplFrameDeadline();
591 EXPECT_ACTION_UPDATE_STATE( 603 EXPECT_ACTION_UPDATE_STATE(
592 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 604 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
593 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 605 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
594 } 606 }
595 607
596 TEST(SchedulerStateMachineTest, TestDoestDrawTwiceInSameFrame) { 608 TEST(SchedulerStateMachineTest, TestDoestDrawTwiceInSameFrame) {
597 SchedulerSettings default_scheduler_settings; 609 SchedulerSettings default_scheduler_settings;
598 StateMachine state(default_scheduler_settings); 610 StateMachine state(default_scheduler_settings);
599 state.SetCanStart(); 611 state.SetCanStart();
600 state.UpdateState(state.NextAction()); 612 state.UpdateState(state.NextAction());
601 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 613 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
602 state.SetVisible(true); 614 state.SetVisible(true);
603 state.SetCanDraw(true); 615 state.SetCanDraw(true);
604 state.SetNeedsRedraw(true); 616 state.SetNeedsRedraw(true);
605 617
606 // Draw the first frame. 618 // Draw the first frame.
607 EXPECT_TRUE(state.BeginFrameNeeded()); 619 EXPECT_TRUE(state.BeginFrameNeeded());
608 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 620 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting());
621 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
609 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 622 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
610 623
611 state.OnBeginImplFrameDeadline(); 624 state.OnBeginImplFrameDeadline();
612 EXPECT_ACTION_UPDATE_STATE( 625 EXPECT_ACTION_UPDATE_STATE(
613 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 626 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
614 state.DidDrawIfPossibleCompleted(DrawSwapReadbackResult::DRAW_SUCCESS); 627 state.DidDrawIfPossibleCompleted(DrawSwapReadbackResult::DRAW_SUCCESS);
615 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 628 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
616 629
617 // Before the next BeginImplFrame, set needs redraw again. 630 // Before the next BeginImplFrame, set needs redraw again.
618 // This should not redraw until the next BeginImplFrame. 631 // This should not redraw until the next BeginImplFrame.
619 state.SetNeedsRedraw(true); 632 state.SetNeedsRedraw(true);
620 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 633 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
621 634
622 // Move to another frame. This should now draw. 635 // Move to another frame. This should now draw.
623 EXPECT_TRUE(state.BeginFrameNeeded()); 636 EXPECT_TRUE(state.BeginFrameNeeded());
624 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 637 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting());
625 638
639 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
626 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 640 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
627 641
628 state.OnBeginImplFrameDeadline(); 642 state.OnBeginImplFrameDeadline();
629 EXPECT_ACTION_UPDATE_STATE( 643 EXPECT_ACTION_UPDATE_STATE(
630 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 644 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
631 state.DidDrawIfPossibleCompleted(DrawSwapReadbackResult::DRAW_SUCCESS); 645 state.DidDrawIfPossibleCompleted(DrawSwapReadbackResult::DRAW_SUCCESS);
632 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 646 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
633 647
634 // We just swapped, so we should proactively request another BeginImplFrame. 648 // We just swapped, so we should proactively request another BeginImplFrame.
635 EXPECT_TRUE(state.BeginFrameNeeded()); 649 EXPECT_TRUE(state.BeginFrameNeeded());
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
679 bool request_readback = j; 693 bool request_readback = j;
680 694
681 StateMachine state(default_scheduler_settings); 695 StateMachine state(default_scheduler_settings);
682 state.SetCanStart(); 696 state.SetCanStart();
683 state.UpdateState(state.NextAction()); 697 state.UpdateState(state.NextAction());
684 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 698 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
685 state.SetCanDraw(true); 699 state.SetCanDraw(true);
686 state.SetCommitState(all_commit_states[i]); 700 state.SetCommitState(all_commit_states[i]);
687 state.SetBeginImplFrameState( 701 state.SetBeginImplFrameState(
688 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE); 702 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE);
703
689 if (request_readback) { 704 if (request_readback) {
690 state.SetNeedsForcedRedrawForReadback(); 705 state.SetNeedsForcedRedrawForReadback();
691 } else { 706 } else {
692 state.SetNeedsRedraw(true); 707 state.SetNeedsRedraw(true);
693 state.SetVisible(true); 708 state.SetVisible(true);
694 } 709 }
695 710
696 SchedulerStateMachine::Action expected_action; 711 SchedulerStateMachine::Action expected_action;
697 if (request_readback) { 712 if (request_readback) {
698 expected_action = SchedulerStateMachine::ACTION_DRAW_AND_READBACK; 713 expected_action = SchedulerStateMachine::ACTION_DRAW_AND_READBACK;
699 } else if (all_commit_states[i] == 714 } else if (all_commit_states[i] ==
700 SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT) { 715 SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT) {
701 expected_action = SchedulerStateMachine::ACTION_COMMIT; 716 expected_action = SchedulerStateMachine::ACTION_COMMIT;
702 } else { 717 } else {
703 expected_action = 718 expected_action =
704 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE; 719 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE;
720 EXPECT_EQ(state.NextAction(), SchedulerStateMachine::ACTION_ANIMATE)
721 << *state.AsValue();
722 state.UpdateState(state.NextAction());
705 } 723 }
706 724
707 // Case 1: needs_commit=false. 725 // Case 1: needs_commit=false.
708 EXPECT_NE(state.BeginFrameNeeded(), request_readback) << *state.AsValue(); 726 EXPECT_NE(state.BeginFrameNeeded(), request_readback) << *state.AsValue();
709 EXPECT_EQ(state.NextAction(), expected_action) << *state.AsValue(); 727 EXPECT_EQ(state.NextAction(), expected_action) << *state.AsValue();
710 728
711 // Case 2: needs_commit=true. 729 // Case 2: needs_commit=true.
712 state.SetNeedsCommit(); 730 state.SetNeedsCommit();
713 EXPECT_NE(state.BeginFrameNeeded(), request_readback) << *state.AsValue(); 731 EXPECT_NE(state.BeginFrameNeeded(), request_readback) << *state.AsValue();
714 EXPECT_EQ(state.NextAction(), expected_action) << *state.AsValue(); 732 EXPECT_EQ(state.NextAction(), expected_action) << *state.AsValue();
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
852 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction()); 870 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction());
853 871
854 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 872 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting());
855 EXPECT_EQ(SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_BEGIN_FRAME_STARTING, 873 EXPECT_EQ(SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_BEGIN_FRAME_STARTING,
856 state.begin_impl_frame_state()); 874 state.begin_impl_frame_state());
857 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction()); 875 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction());
858 876
859 // Finish the commit, then make sure we start the next commit immediately 877 // Finish the commit, then make sure we start the next commit immediately
860 // and draw on the next BeginImplFrame. 878 // and draw on the next BeginImplFrame.
861 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 879 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
880 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
862 if (main_frame_before_draw_enabled) { 881 if (main_frame_before_draw_enabled) {
863 EXPECT_ACTION_UPDATE_STATE( 882 EXPECT_ACTION_UPDATE_STATE(
864 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 883 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
865 } 884 }
866 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 885 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
867 886
868 state.OnBeginImplFrameDeadline(); 887 state.OnBeginImplFrameDeadline();
869 888
870 EXPECT_TRUE(state.active_tree_needs_first_draw()); 889 EXPECT_TRUE(state.active_tree_needs_first_draw());
871 EXPECT_ACTION_UPDATE_STATE( 890 EXPECT_ACTION_UPDATE_STATE(
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
918 // Commit. 937 // Commit.
919 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 938 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
920 EXPECT_TRUE(state.active_tree_needs_first_draw()); 939 EXPECT_TRUE(state.active_tree_needs_first_draw());
921 EXPECT_TRUE(state.needs_redraw()); 940 EXPECT_TRUE(state.needs_redraw());
922 941
923 // Expect to do nothing until BeginImplFrame deadline 942 // Expect to do nothing until BeginImplFrame deadline
924 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 943 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
925 944
926 // At BeginImplFrame deadline, draw. 945 // At BeginImplFrame deadline, draw.
927 state.OnBeginImplFrameDeadline(); 946 state.OnBeginImplFrameDeadline();
947 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
928 EXPECT_ACTION_UPDATE_STATE( 948 EXPECT_ACTION_UPDATE_STATE(
929 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 949 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
930 state.DidDrawIfPossibleCompleted(DrawSwapReadbackResult::DRAW_SUCCESS); 950 state.DidDrawIfPossibleCompleted(DrawSwapReadbackResult::DRAW_SUCCESS);
931 951
932 // Should be synchronized, no draw needed, no action needed. 952 // Should be synchronized, no draw needed, no action needed.
933 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 953 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
934 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState()); 954 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState());
935 EXPECT_FALSE(state.needs_redraw()); 955 EXPECT_FALSE(state.needs_redraw());
936 } 956 }
937 957
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
969 // First commit. 989 // First commit.
970 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 990 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
971 EXPECT_TRUE(state.active_tree_needs_first_draw()); 991 EXPECT_TRUE(state.active_tree_needs_first_draw());
972 EXPECT_TRUE(state.needs_redraw()); 992 EXPECT_TRUE(state.needs_redraw());
973 993
974 // Expect to do nothing until BeginImplFrame deadline. 994 // Expect to do nothing until BeginImplFrame deadline.
975 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 995 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
976 996
977 // At BeginImplFrame deadline, draw. 997 // At BeginImplFrame deadline, draw.
978 state.OnBeginImplFrameDeadline(); 998 state.OnBeginImplFrameDeadline();
999 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
979 EXPECT_ACTION_UPDATE_STATE( 1000 EXPECT_ACTION_UPDATE_STATE(
980 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 1001 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
981 state.DidDrawIfPossibleCompleted(DrawSwapReadbackResult::DRAW_SUCCESS); 1002 state.DidDrawIfPossibleCompleted(DrawSwapReadbackResult::DRAW_SUCCESS);
982 1003
983 // Should be synchronized, no draw needed, no action needed. 1004 // Should be synchronized, no draw needed, no action needed.
984 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1005 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
985 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState()); 1006 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState());
986 EXPECT_FALSE(state.needs_redraw()); 1007 EXPECT_FALSE(state.needs_redraw());
987 1008
988 // Next BeginImplFrame should initiate second commit. 1009 // Next BeginImplFrame should initiate second commit.
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
1077 state.BeginMainFrameAborted(true); 1098 state.BeginMainFrameAborted(true);
1078 1099
1079 // Verify that another commit doesn't start on the same frame. 1100 // Verify that another commit doesn't start on the same frame.
1080 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState()); 1101 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState());
1081 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); 1102 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction());
1082 EXPECT_FALSE(state.NeedsCommit()); 1103 EXPECT_FALSE(state.NeedsCommit());
1083 1104
1084 // Start a new frame; draw because this is the first frame since output 1105 // Start a new frame; draw because this is the first frame since output
1085 // surface init'd. 1106 // surface init'd.
1086 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 1107 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting());
1108 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
1087 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1109 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1088 state.OnBeginImplFrameDeadline(); 1110 state.OnBeginImplFrameDeadline();
1089 EXPECT_ACTION_UPDATE_STATE( 1111 EXPECT_ACTION_UPDATE_STATE(
1090 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 1112 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
1091 1113
1092 // Verify another commit doesn't start on another frame either. 1114 // Verify another commit doesn't start on another frame either.
1093 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState()); 1115 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState());
1094 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); 1116 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction());
1095 EXPECT_FALSE(state.NeedsCommit()); 1117 EXPECT_FALSE(state.NeedsCommit());
1096 1118
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
1202 state.NotifyReadyToCommit(); 1224 state.NotifyReadyToCommit();
1203 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 1225 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
1204 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1226 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1205 // Finishing the first commit after initializing an output surface should 1227 // Finishing the first commit after initializing an output surface should
1206 // automatically cause a redraw. 1228 // automatically cause a redraw.
1207 EXPECT_TRUE(state.RedrawPending()); 1229 EXPECT_TRUE(state.RedrawPending());
1208 1230
1209 // Once the context is recreated, whether we draw should be based on 1231 // Once the context is recreated, whether we draw should be based on
1210 // SetCanDraw. 1232 // SetCanDraw.
1211 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 1233 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting());
1234 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
1212 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1235 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1213 state.OnBeginImplFrameDeadline(); 1236 state.OnBeginImplFrameDeadline();
1214 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE, 1237 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE,
1215 state.NextAction()); 1238 state.NextAction());
1216 state.SetCanDraw(false); 1239 state.SetCanDraw(false);
1217 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT, 1240 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT,
1218 state.NextAction()); 1241 state.NextAction());
1219 state.SetCanDraw(true); 1242 state.SetCanDraw(true);
1220 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE, 1243 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE,
1221 state.NextAction()); 1244 state.NextAction());
1222 } 1245 }
1223 1246
1224 TEST(SchedulerStateMachineTest, TestContextLostWhileCommitInProgress) { 1247 TEST(SchedulerStateMachineTest, TestContextLostWhileCommitInProgress) {
1225 SchedulerSettings scheduler_settings; 1248 SchedulerSettings scheduler_settings;
1226 StateMachine state(scheduler_settings); 1249 StateMachine state(scheduler_settings);
1227 state.SetCanStart(); 1250 state.SetCanStart();
1228 state.UpdateState(state.NextAction()); 1251 state.UpdateState(state.NextAction());
1229 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 1252 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
1230 state.SetVisible(true); 1253 state.SetVisible(true);
1231 state.SetCanDraw(true); 1254 state.SetCanDraw(true);
1232 1255
1233 // Get a commit in flight. 1256 // Get a commit in flight.
1234 state.SetNeedsCommit(); 1257 state.SetNeedsCommit();
1235 1258
1236 // Set damage and expect a draw. 1259 // Set damage and expect a draw.
1237 state.SetNeedsRedraw(true); 1260 state.SetNeedsRedraw(true);
1238 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 1261 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting());
1262 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
1239 EXPECT_ACTION_UPDATE_STATE( 1263 EXPECT_ACTION_UPDATE_STATE(
1240 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 1264 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
1241 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1265 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1242 state.OnBeginImplFrameDeadline(); 1266 state.OnBeginImplFrameDeadline();
1243 EXPECT_ACTION_UPDATE_STATE( 1267 EXPECT_ACTION_UPDATE_STATE(
1244 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 1268 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
1245 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1269 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1246 1270
1247 // Cause a lost context while the BeginMainFrame is in flight. 1271 // Cause a lost context while the BeginMainFrame is in flight.
1248 state.DidLoseOutputSurface(); 1272 state.DidLoseOutputSurface();
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
1293 state.SetVisible(true); 1317 state.SetVisible(true);
1294 state.SetCanDraw(true); 1318 state.SetCanDraw(true);
1295 1319
1296 // Get a commit in flight. 1320 // Get a commit in flight.
1297 state.SetNeedsCommit(); 1321 state.SetNeedsCommit();
1298 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1322 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1299 1323
1300 // Set damage and expect a draw. 1324 // Set damage and expect a draw.
1301 state.SetNeedsRedraw(true); 1325 state.SetNeedsRedraw(true);
1302 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 1326 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting());
1327 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
1303 EXPECT_ACTION_UPDATE_STATE( 1328 EXPECT_ACTION_UPDATE_STATE(
1304 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 1329 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
1305 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1330 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1306 state.OnBeginImplFrameDeadline(); 1331 state.OnBeginImplFrameDeadline();
1307 EXPECT_ACTION_UPDATE_STATE( 1332 EXPECT_ACTION_UPDATE_STATE(
1308 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 1333 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
1309 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1334 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1310 1335
1311 // Cause a lost context while the BeginMainFrame is in flight. 1336 // Cause a lost context while the BeginMainFrame is in flight.
1312 state.DidLoseOutputSurface(); 1337 state.DidLoseOutputSurface();
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
1354 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 1379 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
1355 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 1380 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting());
1356 EXPECT_ACTION_UPDATE_STATE( 1381 EXPECT_ACTION_UPDATE_STATE(
1357 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 1382 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
1358 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1383 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1359 state.NotifyBeginMainFrameStarted(); 1384 state.NotifyBeginMainFrameStarted();
1360 state.NotifyReadyToCommit(); 1385 state.NotifyReadyToCommit();
1361 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 1386 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
1362 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1387 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1363 state.OnBeginImplFrameDeadline(); 1388 state.OnBeginImplFrameDeadline();
1389 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
1364 EXPECT_ACTION_UPDATE_STATE( 1390 EXPECT_ACTION_UPDATE_STATE(
1365 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 1391 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
1366 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1392 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1367 } 1393 }
1368 1394
1369 TEST(SchedulerStateMachineTest, TestFinishAllRenderingWhileContextLost) { 1395 TEST(SchedulerStateMachineTest, TestFinishAllRenderingWhileContextLost) {
1370 SchedulerSettings default_scheduler_settings; 1396 SchedulerSettings default_scheduler_settings;
1371 StateMachine state(default_scheduler_settings); 1397 StateMachine state(default_scheduler_settings);
1372 state.SetCanStart(); 1398 state.SetCanStart();
1373 state.UpdateState(state.NextAction()); 1399 state.UpdateState(state.NextAction());
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
1517 state.readback_state()); 1543 state.readback_state());
1518 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT, 1544 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT,
1519 state.CommitState()); 1545 state.CommitState());
1520 1546
1521 // Finish the replacement commit. 1547 // Finish the replacement commit.
1522 state.NotifyBeginMainFrameStarted(); 1548 state.NotifyBeginMainFrameStarted();
1523 state.NotifyReadyToCommit(); 1549 state.NotifyReadyToCommit();
1524 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 1550 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
1525 1551
1526 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 1552 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting());
1553 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
1527 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1554 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1528 state.OnBeginImplFrameDeadline(); 1555 state.OnBeginImplFrameDeadline();
1529 EXPECT_ACTION_UPDATE_STATE( 1556 EXPECT_ACTION_UPDATE_STATE(
1530 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 1557 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
1531 EXPECT_EQ(SchedulerStateMachine::READBACK_STATE_IDLE, state.readback_state()); 1558 EXPECT_EQ(SchedulerStateMachine::READBACK_STATE_IDLE, state.readback_state());
1532 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1559 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1533 } 1560 }
1534 1561
1535 TEST(SchedulerStateMachineTest, TestFinishCommitWhenCommitInProgress) { 1562 TEST(SchedulerStateMachineTest, TestFinishCommitWhenCommitInProgress) {
1536 SchedulerSettings default_scheduler_settings; 1563 SchedulerSettings default_scheduler_settings;
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
1621 // New replacement commit is scheduled. 1648 // New replacement commit is scheduled.
1622 EXPECT_ACTION_UPDATE_STATE( 1649 EXPECT_ACTION_UPDATE_STATE(
1623 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 1650 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
1624 // Forced commit is started. 1651 // Forced commit is started.
1625 EXPECT_EQ(SchedulerStateMachine::READBACK_STATE_WAITING_FOR_COMMIT, 1652 EXPECT_EQ(SchedulerStateMachine::READBACK_STATE_WAITING_FOR_COMMIT,
1626 state.readback_state()); 1653 state.readback_state());
1627 } 1654 }
1628 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1655 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1629 1656
1630 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 1657 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting());
1658 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
1631 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1659 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1632 // Perform the draw & swap of replacement commit. 1660 // Perform the draw & swap of replacement commit.
1633 state.OnBeginImplFrameDeadline(); 1661 state.OnBeginImplFrameDeadline();
1634 EXPECT_ACTION_UPDATE_STATE( 1662 EXPECT_ACTION_UPDATE_STATE(
1635 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 1663 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
1636 if (!settings.main_frame_before_draw_enabled) { 1664 if (!settings.main_frame_before_draw_enabled) {
1637 // New replacement commit is scheduled. 1665 // New replacement commit is scheduled.
1638 EXPECT_ACTION_UPDATE_STATE( 1666 EXPECT_ACTION_UPDATE_STATE(
1639 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 1667 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
1640 // Forced commit is started. 1668 // Forced commit is started.
(...skipping 19 matching lines...) Expand all
1660 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1688 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1661 1689
1662 // Finish the replacement commit and draw it. 1690 // Finish the replacement commit and draw it.
1663 state.NotifyBeginMainFrameStarted(); 1691 state.NotifyBeginMainFrameStarted();
1664 state.NotifyReadyToCommit(); 1692 state.NotifyReadyToCommit();
1665 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 1693 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
1666 state.NotifyReadyToActivate(); 1694 state.NotifyReadyToActivate();
1667 EXPECT_ACTION_UPDATE_STATE( 1695 EXPECT_ACTION_UPDATE_STATE(
1668 SchedulerStateMachine::ACTION_ACTIVATE_PENDING_TREE); 1696 SchedulerStateMachine::ACTION_ACTIVATE_PENDING_TREE);
1669 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 1697 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting());
1698 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
1670 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1699 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1671 state.OnBeginImplFrameDeadline(); 1700 state.OnBeginImplFrameDeadline();
1672 EXPECT_ACTION_UPDATE_STATE( 1701 EXPECT_ACTION_UPDATE_STATE(
1673 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 1702 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
1674 EXPECT_EQ(SchedulerStateMachine::READBACK_STATE_IDLE, state.readback_state()); 1703 EXPECT_EQ(SchedulerStateMachine::READBACK_STATE_IDLE, state.readback_state());
1675 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1704 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1676 } 1705 }
1677 1706
1678 // Explicitly test when main_frame_before_draw_enabled = true. 1707 // Explicitly test when main_frame_before_draw_enabled = true.
1679 TEST(SchedulerStateMachineTest, 1708 TEST(SchedulerStateMachineTest,
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
1730 state.NotifyReadyToActivate(); 1759 state.NotifyReadyToActivate();
1731 EXPECT_ACTION_UPDATE_STATE( 1760 EXPECT_ACTION_UPDATE_STATE(
1732 SchedulerStateMachine::ACTION_ACTIVATE_PENDING_TREE); 1761 SchedulerStateMachine::ACTION_ACTIVATE_PENDING_TREE);
1733 // Replacement commit for requested forced commit is already scheduled. 1762 // Replacement commit for requested forced commit is already scheduled.
1734 EXPECT_EQ(SchedulerStateMachine::READBACK_STATE_WAITING_FOR_COMMIT, 1763 EXPECT_EQ(SchedulerStateMachine::READBACK_STATE_WAITING_FOR_COMMIT,
1735 state.readback_state()); 1764 state.readback_state());
1736 EXPECT_FALSE(state.NeedsCommit()); 1765 EXPECT_FALSE(state.NeedsCommit());
1737 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1766 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1738 1767
1739 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 1768 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting());
1769 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
1740 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1770 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1741 // Perform the draw & swap of replacement commit. 1771 // Perform the draw & swap of replacement commit.
1742 state.OnBeginImplFrameDeadline(); 1772 state.OnBeginImplFrameDeadline();
1743 EXPECT_ACTION_UPDATE_STATE( 1773 EXPECT_ACTION_UPDATE_STATE(
1744 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 1774 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
1745 EXPECT_ACTION_UPDATE_STATE( 1775 EXPECT_ACTION_UPDATE_STATE(
1746 SchedulerStateMachine::ACTION_NONE); 1776 SchedulerStateMachine::ACTION_NONE);
1747 1777
1748 // forced commit is started. 1778 // forced commit is started.
1749 state.NotifyBeginMainFrameStarted(); 1779 state.NotifyBeginMainFrameStarted();
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
1967 // This test mirrors what happens during the first frame of a scroll gesture. 1997 // This test mirrors what happens during the first frame of a scroll gesture.
1968 // First we get the input event and a BeginFrame. 1998 // First we get the input event and a BeginFrame.
1969 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 1999 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting());
1970 2000
1971 // As a response the compositor requests a redraw and a commit to tell the 2001 // As a response the compositor requests a redraw and a commit to tell the
1972 // main thread about the new scroll offset. 2002 // main thread about the new scroll offset.
1973 state.SetNeedsRedraw(true); 2003 state.SetNeedsRedraw(true);
1974 state.SetNeedsCommit(); 2004 state.SetNeedsCommit();
1975 2005
1976 // We should start the commit normally. 2006 // We should start the commit normally.
2007 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
1977 EXPECT_ACTION_UPDATE_STATE( 2008 EXPECT_ACTION_UPDATE_STATE(
1978 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 2009 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
1979 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 2010 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1980 2011
1981 // Since only the scroll offset changed, the main thread will abort the 2012 // Since only the scroll offset changed, the main thread will abort the
1982 // commit. 2013 // commit.
1983 state.BeginMainFrameAborted(true); 2014 state.BeginMainFrameAborted(true);
1984 2015
1985 // Since the commit was aborted, we should draw right away instead of waiting 2016 // Since the commit was aborted, we should draw right away instead of waiting
1986 // for the deadline. 2017 // for the deadline.
1987 EXPECT_TRUE(state.ShouldTriggerBeginImplFrameDeadlineEarly()); 2018 EXPECT_TRUE(state.ShouldTriggerBeginImplFrameDeadlineEarly());
1988 } 2019 }
1989 2020
1990 TEST(SchedulerStateMachineTest, TestTriggerDeadlineEarlyForSmoothness) { 2021 TEST(SchedulerStateMachineTest, TestTriggerDeadlineEarlyForSmoothness) {
1991 SchedulerSettings settings; 2022 SchedulerSettings settings;
1992 settings.impl_side_painting = true; 2023 settings.impl_side_painting = true;
1993 StateMachine state(settings); 2024 StateMachine state(settings);
1994 state.SetCanStart(); 2025 state.SetCanStart();
1995 state.UpdateState(state.NextAction()); 2026 state.UpdateState(state.NextAction());
1996 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 2027 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
1997 state.SetVisible(true); 2028 state.SetVisible(true);
1998 state.SetCanDraw(true); 2029 state.SetCanDraw(true);
1999 2030
2000 // This test ensures that impl-draws are prioritized over main thread updates 2031 // This test ensures that impl-draws are prioritized over main thread updates
2001 // in prefer smoothness mode. 2032 // in prefer smoothness mode.
2002 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 2033 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting());
2003 state.SetNeedsRedraw(true); 2034 state.SetNeedsRedraw(true);
2004 state.SetNeedsCommit(); 2035 state.SetNeedsCommit();
2036 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
2005 EXPECT_ACTION_UPDATE_STATE( 2037 EXPECT_ACTION_UPDATE_STATE(
2006 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 2038 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
2007 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 2039 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
2008 2040
2009 // The deadline is not triggered early until we enter prefer smoothness mode. 2041 // The deadline is not triggered early until we enter prefer smoothness mode.
2010 EXPECT_FALSE(state.ShouldTriggerBeginImplFrameDeadlineEarly()); 2042 EXPECT_FALSE(state.ShouldTriggerBeginImplFrameDeadlineEarly());
2011 state.SetSmoothnessTakesPriority(true); 2043 state.SetSmoothnessTakesPriority(true);
2012 EXPECT_TRUE(state.ShouldTriggerBeginImplFrameDeadlineEarly()); 2044 EXPECT_TRUE(state.ShouldTriggerBeginImplFrameDeadlineEarly());
2013 } 2045 }
2014 2046
2047 TEST(SchedulerStateMachineTest, TestSetNeedsAnimate) {
2048 SchedulerSettings settings;
2049 settings.impl_side_painting = true;
2050 StateMachine state(settings);
2051 state.SetCanStart();
2052 state.UpdateState(state.NextAction());
2053 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
2054 state.SetVisible(true);
2055 state.SetCanDraw(true);
2056
2057 // Test requesting an animation that, when run, causes us to draw.
2058 state.SetNeedsAnimate();
2059 EXPECT_TRUE(state.BeginFrameNeeded());
2060 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
2061
2062 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting());
2063 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
2064
2065 state.OnBeginImplFrameDeadlinePending();
2066 state.OnBeginImplFrameDeadline();
2067 EXPECT_ACTION_UPDATE_STATE(
2068 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
2069 }
2070
2071 TEST(SchedulerStateMachineTest, TestAnimateBeforeCommit) {
2072 SchedulerSettings settings;
2073 settings.impl_side_painting = true;
2074 StateMachine state(settings);
2075 state.SetCanStart();
2076 state.UpdateState(state.NextAction());
2077 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
2078 state.SetVisible(true);
2079 state.SetCanDraw(true);
2080
2081 // Check that animations are updated before we start a commit.
2082 state.SetNeedsAnimate();
2083 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
2084 state.SetNeedsCommit();
2085 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
2086 EXPECT_TRUE(state.BeginFrameNeeded());
2087
2088 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting());
2089 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
2090 EXPECT_ACTION_UPDATE_STATE(
2091 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
2092
2093 state.OnBeginImplFrameDeadlinePending();
2094 state.OnBeginImplFrameDeadline();
2095 EXPECT_ACTION_UPDATE_STATE(
2096 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
2097 }
2098
2099 TEST(SchedulerStateMachineTest, TestSetNeedsAnimateAfterAnimate) {
2100 SchedulerSettings settings;
2101 settings.impl_side_painting = true;
2102 StateMachine state(settings);
2103 state.SetCanStart();
2104 state.UpdateState(state.NextAction());
2105 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
2106 state.SetVisible(true);
2107 state.SetCanDraw(true);
2108
2109 // Test requesting an animation after we have already animated during this
2110 // frame.
2111 state.SetNeedsRedraw(true);
2112 EXPECT_TRUE(state.BeginFrameNeeded());
2113 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
2114
2115 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting());
2116 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
2117
2118 state.SetNeedsAnimate();
2119 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
2120
2121 state.OnBeginImplFrameDeadline();
2122 EXPECT_ACTION_UPDATE_STATE(
2123 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
2124 }
2125
2015 } // namespace 2126 } // namespace
2016 } // namespace cc 2127 } // namespace cc
OLDNEW
« no previous file with comments | « cc/scheduler/scheduler_state_machine.cc ('k') | cc/scheduler/scheduler_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698