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

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

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

Powered by Google App Engine
This is Rietveld 408576698