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

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: Cleanup. Created 6 years, 8 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 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 // commit in that order. 225 // commit in that order.
226 state.NotifyReadyToActivate(); 226 state.NotifyReadyToActivate();
227 EXPECT_ACTION_UPDATE_STATE( 227 EXPECT_ACTION_UPDATE_STATE(
228 SchedulerStateMachine::ACTION_ACTIVATE_PENDING_TREE); 228 SchedulerStateMachine::ACTION_ACTIVATE_PENDING_TREE);
229 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 229 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
230 EXPECT_EQ(state.CommitState(), 230 EXPECT_EQ(state.CommitState(),
231 SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW); 231 SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW);
232 232
233 EXPECT_TRUE(state.ShouldTriggerBeginImplFrameDeadlineEarly()); 233 EXPECT_TRUE(state.ShouldTriggerBeginImplFrameDeadlineEarly());
234 state.OnBeginImplFrameDeadline(); 234 state.OnBeginImplFrameDeadline();
235 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
235 EXPECT_ACTION_UPDATE_STATE( 236 EXPECT_ACTION_UPDATE_STATE(
236 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 237 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
237 EXPECT_EQ(state.CommitState(), SchedulerStateMachine::COMMIT_STATE_IDLE); 238 EXPECT_EQ(state.CommitState(), SchedulerStateMachine::COMMIT_STATE_IDLE);
238 EXPECT_ACTION_UPDATE_STATE( 239 EXPECT_ACTION_UPDATE_STATE(
239 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 240 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
240 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 241 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
241 EXPECT_EQ(state.CommitState(), 242 EXPECT_EQ(state.CommitState(),
242 SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT); 243 SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT);
243 244
244 state.NotifyBeginMainFrameStarted(); 245 state.NotifyBeginMainFrameStarted();
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 297
297 // Verify NotifyReadyToActivate unblocks activation, draw, and 298 // Verify NotifyReadyToActivate unblocks activation, draw, and
298 // commit in that order. 299 // commit in that order.
299 state.NotifyReadyToActivate(); 300 state.NotifyReadyToActivate();
300 EXPECT_ACTION_UPDATE_STATE( 301 EXPECT_ACTION_UPDATE_STATE(
301 SchedulerStateMachine::ACTION_ACTIVATE_PENDING_TREE); 302 SchedulerStateMachine::ACTION_ACTIVATE_PENDING_TREE);
302 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 303 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
303 304
304 EXPECT_TRUE(state.ShouldTriggerBeginImplFrameDeadlineEarly()); 305 EXPECT_TRUE(state.ShouldTriggerBeginImplFrameDeadlineEarly());
305 state.OnBeginImplFrameDeadline(); 306 state.OnBeginImplFrameDeadline();
307 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
306 EXPECT_ACTION_UPDATE_STATE( 308 EXPECT_ACTION_UPDATE_STATE(
307 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 309 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
308 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 310 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
309 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 311 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
310 EXPECT_EQ(state.CommitState(), SchedulerStateMachine::COMMIT_STATE_IDLE); 312 EXPECT_EQ(state.CommitState(), SchedulerStateMachine::COMMIT_STATE_IDLE);
311 } 313 }
312 314
313 TEST(SchedulerStateMachineTest, 315 TEST(SchedulerStateMachineTest,
314 TestFailedDrawForAnimationCheckerboardSetsNeedsCommitAndDoesNotDrawAgain) { 316 TestFailedDrawForAnimationCheckerboardSetsNeedsCommitAndDoesNotDrawAgain) {
315 SchedulerSettings default_scheduler_settings; 317 SchedulerSettings default_scheduler_settings;
316 StateMachine state(default_scheduler_settings); 318 StateMachine state(default_scheduler_settings);
317 state.SetCanStart(); 319 state.SetCanStart();
318 state.UpdateState(state.NextAction()); 320 state.UpdateState(state.NextAction());
319 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 321 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
320 state.SetVisible(true); 322 state.SetVisible(true);
321 state.SetCanDraw(true); 323 state.SetCanDraw(true);
322 state.SetNeedsRedraw(true); 324 state.SetNeedsRedraw(true);
323 EXPECT_TRUE(state.RedrawPending()); 325 EXPECT_TRUE(state.RedrawPending());
324 EXPECT_TRUE(state.BeginImplFrameNeeded()); 326 EXPECT_TRUE(state.BeginImplFrameNeeded());
325 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 327 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting());
328 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
326 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 329 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
327 state.OnBeginImplFrameDeadline(); 330 state.OnBeginImplFrameDeadline();
328 331
329 // We're drawing now. 332 // We're drawing now.
330 EXPECT_ACTION_UPDATE_STATE( 333 EXPECT_ACTION_UPDATE_STATE(
331 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 334 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
332 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 335 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
333 336
334 EXPECT_FALSE(state.RedrawPending()); 337 EXPECT_FALSE(state.RedrawPending());
335 EXPECT_FALSE(state.CommitPending()); 338 EXPECT_FALSE(state.CommitPending());
336 339
337 // Failing the draw makes us require a commit. 340 // Failing the draw makes us require a commit.
338 state.DidDrawIfPossibleCompleted( 341 state.DidDrawIfPossibleCompleted(
339 DrawSwapReadbackResult::DRAW_ABORTED_CHECKERBOARD_ANIMATIONS); 342 DrawSwapReadbackResult::DRAW_ABORTED_CHECKERBOARD_ANIMATIONS);
340 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 343 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting());
344 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
341 EXPECT_ACTION_UPDATE_STATE( 345 EXPECT_ACTION_UPDATE_STATE(
342 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 346 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
343 EXPECT_TRUE(state.RedrawPending()); 347 EXPECT_TRUE(state.RedrawPending());
344 EXPECT_TRUE(state.CommitPending()); 348 EXPECT_TRUE(state.CommitPending());
345 } 349 }
346 350
347 TEST(SchedulerStateMachineTest, TestFailedDrawForMissingHighResNeedsCommit) { 351 TEST(SchedulerStateMachineTest, TestFailedDrawForMissingHighResNeedsCommit) {
348 SchedulerSettings default_scheduler_settings; 352 SchedulerSettings default_scheduler_settings;
349 StateMachine state(default_scheduler_settings); 353 StateMachine state(default_scheduler_settings);
350 state.SetCanStart(); 354 state.SetCanStart();
351 state.UpdateState(state.NextAction()); 355 state.UpdateState(state.NextAction());
352 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 356 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
353 state.SetVisible(true); 357 state.SetVisible(true);
354 state.SetCanDraw(true); 358 state.SetCanDraw(true);
355 state.SetNeedsRedraw(true); 359 state.SetNeedsRedraw(true);
356 EXPECT_TRUE(state.RedrawPending()); 360 EXPECT_TRUE(state.RedrawPending());
357 EXPECT_TRUE(state.BeginImplFrameNeeded()); 361 EXPECT_TRUE(state.BeginImplFrameNeeded());
358 362
359 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 363 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting());
364 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
360 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 365 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
361 state.OnBeginImplFrameDeadline(); 366 state.OnBeginImplFrameDeadline();
362 EXPECT_ACTION_UPDATE_STATE( 367 EXPECT_ACTION_UPDATE_STATE(
363 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 368 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
364 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 369 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
365 EXPECT_FALSE(state.RedrawPending()); 370 EXPECT_FALSE(state.RedrawPending());
366 EXPECT_FALSE(state.CommitPending()); 371 EXPECT_FALSE(state.CommitPending());
367 372
368 // Missing high res content requires a commit (but not a redraw) 373 // Missing high res content requires a commit (but not a redraw)
369 state.DidDrawIfPossibleCompleted( 374 state.DidDrawIfPossibleCompleted(
(...skipping 12 matching lines...) Expand all
382 state.SetCanStart(); 387 state.SetCanStart();
383 state.UpdateState(state.NextAction()); 388 state.UpdateState(state.NextAction());
384 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 389 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
385 390
386 state.SetVisible(true); 391 state.SetVisible(true);
387 state.SetCanDraw(true); 392 state.SetCanDraw(true);
388 state.SetNeedsRedraw(true); 393 state.SetNeedsRedraw(true);
389 EXPECT_TRUE(state.RedrawPending()); 394 EXPECT_TRUE(state.RedrawPending());
390 EXPECT_TRUE(state.BeginImplFrameNeeded()); 395 EXPECT_TRUE(state.BeginImplFrameNeeded());
391 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 396 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting());
397 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
392 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 398 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
393 state.OnBeginImplFrameDeadline(); 399 state.OnBeginImplFrameDeadline();
394 400
395 // We're drawing now. 401 // We're drawing now.
396 EXPECT_ACTION_UPDATE_STATE( 402 EXPECT_ACTION_UPDATE_STATE(
397 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 403 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
398 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 404 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
399 EXPECT_FALSE(state.RedrawPending()); 405 EXPECT_FALSE(state.RedrawPending());
400 EXPECT_FALSE(state.CommitPending()); 406 EXPECT_FALSE(state.CommitPending());
401 407
402 // While still in the same BeginMainFrame callback on the main thread, 408 // While still in the same BeginMainFrame callback on the main thread,
403 // set needs redraw again. This should not redraw. 409 // set needs redraw again. This should not redraw.
404 state.SetNeedsRedraw(true); 410 state.SetNeedsRedraw(true);
405 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 411 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
406 412
407 // Failing the draw for animation checkerboards makes us require a commit. 413 // Failing the draw for animation checkerboards makes us require a commit.
408 state.DidDrawIfPossibleCompleted( 414 state.DidDrawIfPossibleCompleted(
409 DrawSwapReadbackResult::DRAW_ABORTED_CHECKERBOARD_ANIMATIONS); 415 DrawSwapReadbackResult::DRAW_ABORTED_CHECKERBOARD_ANIMATIONS);
410 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 416 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting());
417 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
411 EXPECT_ACTION_UPDATE_STATE( 418 EXPECT_ACTION_UPDATE_STATE(
412 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 419 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
413 EXPECT_TRUE(state.RedrawPending()); 420 EXPECT_TRUE(state.RedrawPending());
414 } 421 }
415 422
416 void TestFailedDrawsEventuallyForceDrawAfterNextCommit( 423 void TestFailedDrawsEventuallyForceDrawAfterNextCommit(
417 bool main_frame_before_draw_enabled) { 424 bool main_frame_before_draw_enabled) {
418 SchedulerSettings scheduler_settings; 425 SchedulerSettings scheduler_settings;
419 scheduler_settings.main_frame_before_draw_enabled = 426 scheduler_settings.main_frame_before_draw_enabled =
420 main_frame_before_draw_enabled; 427 main_frame_before_draw_enabled;
(...skipping 10 matching lines...) Expand all
431 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 438 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
432 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 439 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting());
433 EXPECT_ACTION_UPDATE_STATE( 440 EXPECT_ACTION_UPDATE_STATE(
434 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 441 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
435 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 442 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
436 EXPECT_TRUE(state.CommitPending()); 443 EXPECT_TRUE(state.CommitPending());
437 444
438 // Then initiate a draw. 445 // Then initiate a draw.
439 state.SetNeedsRedraw(true); 446 state.SetNeedsRedraw(true);
440 state.OnBeginImplFrameDeadline(); 447 state.OnBeginImplFrameDeadline();
448 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
441 EXPECT_ACTION_UPDATE_STATE( 449 EXPECT_ACTION_UPDATE_STATE(
442 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 450 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
443 451
444 // Fail the draw. 452 // Fail the draw.
445 state.DidDrawIfPossibleCompleted( 453 state.DidDrawIfPossibleCompleted(
446 DrawSwapReadbackResult::DRAW_ABORTED_CHECKERBOARD_ANIMATIONS); 454 DrawSwapReadbackResult::DRAW_ABORTED_CHECKERBOARD_ANIMATIONS);
447 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 455 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
448 EXPECT_TRUE(state.BeginImplFrameNeeded()); 456 EXPECT_TRUE(state.BeginImplFrameNeeded());
449 EXPECT_TRUE(state.RedrawPending()); 457 EXPECT_TRUE(state.RedrawPending());
450 // But the commit is ongoing. 458 // But the commit is ongoing.
451 EXPECT_TRUE(state.CommitPending()); 459 EXPECT_TRUE(state.CommitPending());
452 460
453 // Finish the commit. Note, we should not yet be forcing a draw, but should 461 // Finish the commit. Note, we should not yet be forcing a draw, but should
454 // continue the commit as usual. 462 // continue the commit as usual.
455 state.NotifyBeginMainFrameStarted(); 463 state.NotifyBeginMainFrameStarted();
456 state.NotifyReadyToCommit(); 464 state.NotifyReadyToCommit();
457 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 465 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
458 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 466 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
459 EXPECT_TRUE(state.RedrawPending()); 467 EXPECT_TRUE(state.RedrawPending());
460 468
461 // The redraw should be forced at the end of the next BeginImplFrame. 469 // The redraw should be forced at the end of the next BeginImplFrame.
462 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 470 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting());
471 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
463 if (main_frame_before_draw_enabled) { 472 if (main_frame_before_draw_enabled) {
464 EXPECT_ACTION_UPDATE_STATE( 473 EXPECT_ACTION_UPDATE_STATE(
465 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 474 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
466 } 475 }
467 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 476 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
468 state.OnBeginImplFrameDeadline(); 477 state.OnBeginImplFrameDeadline();
469 EXPECT_ACTION_UPDATE_STATE( 478 EXPECT_ACTION_UPDATE_STATE(
470 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_FORCED); 479 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_FORCED);
471 } 480 }
472 481
(...skipping 29 matching lines...) Expand all
502 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 511 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
503 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 512 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting());
504 EXPECT_ACTION_UPDATE_STATE( 513 EXPECT_ACTION_UPDATE_STATE(
505 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 514 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
506 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 515 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
507 EXPECT_TRUE(state.CommitPending()); 516 EXPECT_TRUE(state.CommitPending());
508 517
509 // Then initiate a draw. 518 // Then initiate a draw.
510 state.SetNeedsRedraw(true); 519 state.SetNeedsRedraw(true);
511 state.OnBeginImplFrameDeadline(); 520 state.OnBeginImplFrameDeadline();
521 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
512 EXPECT_ACTION_UPDATE_STATE( 522 EXPECT_ACTION_UPDATE_STATE(
513 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 523 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
514 524
515 // Fail the draw enough times to force a redraw, 525 // Fail the draw enough times to force a redraw,
516 // then once more for good measure. 526 // then once more for good measure.
517 for (int i = 0; i < draw_limit + 1; ++i) { 527 for (int i = 0; i < draw_limit + 1; ++i) {
518 state.DidDrawIfPossibleCompleted( 528 state.DidDrawIfPossibleCompleted(
519 DrawSwapReadbackResult::DRAW_ABORTED_CHECKERBOARD_ANIMATIONS); 529 DrawSwapReadbackResult::DRAW_ABORTED_CHECKERBOARD_ANIMATIONS);
520 } 530 }
521 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 531 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
554 state.SetCanStart(); 564 state.SetCanStart();
555 state.UpdateState(state.NextAction()); 565 state.UpdateState(state.NextAction());
556 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 566 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
557 state.SetVisible(true); 567 state.SetVisible(true);
558 state.SetCanDraw(true); 568 state.SetCanDraw(true);
559 569
560 // Start a draw. 570 // Start a draw.
561 state.SetNeedsRedraw(true); 571 state.SetNeedsRedraw(true);
562 EXPECT_TRUE(state.BeginImplFrameNeeded()); 572 EXPECT_TRUE(state.BeginImplFrameNeeded());
563 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 573 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting());
574 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
564 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 575 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
565 state.OnBeginImplFrameDeadline(); 576 state.OnBeginImplFrameDeadline();
566 EXPECT_TRUE(state.RedrawPending()); 577 EXPECT_TRUE(state.RedrawPending());
567 EXPECT_ACTION_UPDATE_STATE( 578 EXPECT_ACTION_UPDATE_STATE(
568 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 579 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
569 580
570 // Failing the draw for animation checkerboards makes us require a commit. 581 // Failing the draw for animation checkerboards makes us require a commit.
571 state.DidDrawIfPossibleCompleted( 582 state.DidDrawIfPossibleCompleted(
572 DrawSwapReadbackResult::DRAW_ABORTED_CHECKERBOARD_ANIMATIONS); 583 DrawSwapReadbackResult::DRAW_ABORTED_CHECKERBOARD_ANIMATIONS);
573 EXPECT_ACTION_UPDATE_STATE( 584 EXPECT_ACTION_UPDATE_STATE(
574 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 585 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
575 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 586 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
576 EXPECT_TRUE(state.RedrawPending()); 587 EXPECT_TRUE(state.RedrawPending());
577 588
578 // We should not be trying to draw again now, but we have a commit pending. 589 // We should not be trying to draw again now, but we have a commit pending.
579 EXPECT_TRUE(state.BeginImplFrameNeeded()); 590 EXPECT_TRUE(state.BeginImplFrameNeeded());
580 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 591 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting());
592 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
581 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 593 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
582 594
583 // We should try to draw again at the end of the next BeginImplFrame on 595 // We should try to draw again at the end of the next BeginImplFrame on
584 // the impl thread. 596 // the impl thread.
585 state.OnBeginImplFrameDeadline(); 597 state.OnBeginImplFrameDeadline();
586 EXPECT_ACTION_UPDATE_STATE( 598 EXPECT_ACTION_UPDATE_STATE(
587 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 599 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
588 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 600 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
589 } 601 }
590 602
591 TEST(SchedulerStateMachineTest, TestDoestDrawTwiceInSameFrame) { 603 TEST(SchedulerStateMachineTest, TestDoestDrawTwiceInSameFrame) {
592 SchedulerSettings default_scheduler_settings; 604 SchedulerSettings default_scheduler_settings;
593 StateMachine state(default_scheduler_settings); 605 StateMachine state(default_scheduler_settings);
594 state.SetCanStart(); 606 state.SetCanStart();
595 state.UpdateState(state.NextAction()); 607 state.UpdateState(state.NextAction());
596 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 608 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
597 state.SetVisible(true); 609 state.SetVisible(true);
598 state.SetCanDraw(true); 610 state.SetCanDraw(true);
599 state.SetNeedsRedraw(true); 611 state.SetNeedsRedraw(true);
600 612
601 // Draw the first frame. 613 // Draw the first frame.
602 EXPECT_TRUE(state.BeginImplFrameNeeded()); 614 EXPECT_TRUE(state.BeginImplFrameNeeded());
603 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 615 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting());
616 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
604 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 617 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
605 618
606 state.OnBeginImplFrameDeadline(); 619 state.OnBeginImplFrameDeadline();
607 EXPECT_ACTION_UPDATE_STATE( 620 EXPECT_ACTION_UPDATE_STATE(
608 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 621 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
609 state.DidDrawIfPossibleCompleted(DrawSwapReadbackResult::DRAW_SUCCESS); 622 state.DidDrawIfPossibleCompleted(DrawSwapReadbackResult::DRAW_SUCCESS);
610 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 623 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
611 624
612 // Before the next BeginImplFrame, set needs redraw again. 625 // Before the next BeginImplFrame, set needs redraw again.
613 // This should not redraw until the next BeginImplFrame. 626 // This should not redraw until the next BeginImplFrame.
614 state.SetNeedsRedraw(true); 627 state.SetNeedsRedraw(true);
615 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 628 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
616 629
617 // Move to another frame. This should now draw. 630 // Move to another frame. This should now draw.
618 EXPECT_TRUE(state.BeginImplFrameNeeded()); 631 EXPECT_TRUE(state.BeginImplFrameNeeded());
619 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 632 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting());
620 633
634 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
621 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 635 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
622 636
623 state.OnBeginImplFrameDeadline(); 637 state.OnBeginImplFrameDeadline();
624 EXPECT_ACTION_UPDATE_STATE( 638 EXPECT_ACTION_UPDATE_STATE(
625 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 639 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
626 state.DidDrawIfPossibleCompleted(DrawSwapReadbackResult::DRAW_SUCCESS); 640 state.DidDrawIfPossibleCompleted(DrawSwapReadbackResult::DRAW_SUCCESS);
627 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 641 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
628 642
629 // We just swapped, so we should proactively request another BeginImplFrame. 643 // We just swapped, so we should proactively request another BeginImplFrame.
630 EXPECT_TRUE(state.BeginImplFrameNeeded()); 644 EXPECT_TRUE(state.BeginImplFrameNeeded());
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
674 bool request_readback = j; 688 bool request_readback = j;
675 689
676 StateMachine state(default_scheduler_settings); 690 StateMachine state(default_scheduler_settings);
677 state.SetCanStart(); 691 state.SetCanStart();
678 state.UpdateState(state.NextAction()); 692 state.UpdateState(state.NextAction());
679 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 693 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
680 state.SetCanDraw(true); 694 state.SetCanDraw(true);
681 state.SetCommitState(all_commit_states[i]); 695 state.SetCommitState(all_commit_states[i]);
682 state.SetBeginImplFrameState( 696 state.SetBeginImplFrameState(
683 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE); 697 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE);
698
684 if (request_readback) { 699 if (request_readback) {
685 state.SetNeedsForcedRedrawForReadback(); 700 state.SetNeedsForcedRedrawForReadback();
686 } else { 701 } else {
687 state.SetNeedsRedraw(true); 702 state.SetNeedsRedraw(true);
688 state.SetVisible(true); 703 state.SetVisible(true);
689 } 704 }
690 705
691 SchedulerStateMachine::Action expected_action; 706 SchedulerStateMachine::Action expected_action;
692 if (request_readback) { 707 if (request_readback) {
693 expected_action = SchedulerStateMachine::ACTION_DRAW_AND_READBACK; 708 expected_action = SchedulerStateMachine::ACTION_DRAW_AND_READBACK;
694 } else if (all_commit_states[i] == 709 } else if (all_commit_states[i] ==
695 SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT) { 710 SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT) {
696 expected_action = SchedulerStateMachine::ACTION_COMMIT; 711 expected_action = SchedulerStateMachine::ACTION_COMMIT;
697 } else { 712 } else {
698 expected_action = 713 expected_action =
699 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE; 714 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE;
715 EXPECT_EQ(state.NextAction(), SchedulerStateMachine::ACTION_ANIMATE)
716 << *state.AsValue();
717 state.UpdateState(state.NextAction());
700 } 718 }
701 719
702 // Case 1: needs_commit=false. 720 // Case 1: needs_commit=false.
703 EXPECT_NE(state.BeginImplFrameNeeded(), request_readback) 721 EXPECT_NE(state.BeginImplFrameNeeded(), request_readback)
704 << *state.AsValue(); 722 << *state.AsValue();
705 EXPECT_EQ(state.NextAction(), expected_action) << *state.AsValue(); 723 EXPECT_EQ(state.NextAction(), expected_action) << *state.AsValue();
706 724
707 // Case 2: needs_commit=true. 725 // Case 2: needs_commit=true.
708 state.SetNeedsCommit(); 726 state.SetNeedsCommit();
709 EXPECT_NE(state.BeginImplFrameNeeded(), request_readback) 727 EXPECT_NE(state.BeginImplFrameNeeded(), request_readback)
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
849 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction()); 867 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction());
850 868
851 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 869 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting());
852 EXPECT_EQ(SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_BEGIN_FRAME_STARTING, 870 EXPECT_EQ(SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_BEGIN_FRAME_STARTING,
853 state.begin_impl_frame_state()); 871 state.begin_impl_frame_state());
854 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction()); 872 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction());
855 873
856 // Finish the commit, then make sure we start the next commit immediately 874 // Finish the commit, then make sure we start the next commit immediately
857 // and draw on the next BeginImplFrame. 875 // and draw on the next BeginImplFrame.
858 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 876 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
877 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
859 if (main_frame_before_draw_enabled) { 878 if (main_frame_before_draw_enabled) {
860 EXPECT_ACTION_UPDATE_STATE( 879 EXPECT_ACTION_UPDATE_STATE(
861 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 880 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
862 } 881 }
863 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 882 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
864 883
865 state.OnBeginImplFrameDeadline(); 884 state.OnBeginImplFrameDeadline();
866 885
867 EXPECT_TRUE(state.active_tree_needs_first_draw()); 886 EXPECT_TRUE(state.active_tree_needs_first_draw());
868 EXPECT_ACTION_UPDATE_STATE( 887 EXPECT_ACTION_UPDATE_STATE(
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
915 // Commit. 934 // Commit.
916 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 935 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
917 EXPECT_TRUE(state.active_tree_needs_first_draw()); 936 EXPECT_TRUE(state.active_tree_needs_first_draw());
918 EXPECT_TRUE(state.needs_redraw()); 937 EXPECT_TRUE(state.needs_redraw());
919 938
920 // Expect to do nothing until BeginImplFrame deadline 939 // Expect to do nothing until BeginImplFrame deadline
921 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 940 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
922 941
923 // At BeginImplFrame deadline, draw. 942 // At BeginImplFrame deadline, draw.
924 state.OnBeginImplFrameDeadline(); 943 state.OnBeginImplFrameDeadline();
944 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
925 EXPECT_ACTION_UPDATE_STATE( 945 EXPECT_ACTION_UPDATE_STATE(
926 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 946 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
927 state.DidDrawIfPossibleCompleted(DrawSwapReadbackResult::DRAW_SUCCESS); 947 state.DidDrawIfPossibleCompleted(DrawSwapReadbackResult::DRAW_SUCCESS);
928 948
929 // Should be synchronized, no draw needed, no action needed. 949 // Should be synchronized, no draw needed, no action needed.
930 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 950 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
931 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState()); 951 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState());
932 EXPECT_FALSE(state.needs_redraw()); 952 EXPECT_FALSE(state.needs_redraw());
933 } 953 }
934 954
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
966 // First commit. 986 // First commit.
967 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 987 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
968 EXPECT_TRUE(state.active_tree_needs_first_draw()); 988 EXPECT_TRUE(state.active_tree_needs_first_draw());
969 EXPECT_TRUE(state.needs_redraw()); 989 EXPECT_TRUE(state.needs_redraw());
970 990
971 // Expect to do nothing until BeginImplFrame deadline. 991 // Expect to do nothing until BeginImplFrame deadline.
972 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 992 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
973 993
974 // At BeginImplFrame deadline, draw. 994 // At BeginImplFrame deadline, draw.
975 state.OnBeginImplFrameDeadline(); 995 state.OnBeginImplFrameDeadline();
996 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
976 EXPECT_ACTION_UPDATE_STATE( 997 EXPECT_ACTION_UPDATE_STATE(
977 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 998 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
978 state.DidDrawIfPossibleCompleted(DrawSwapReadbackResult::DRAW_SUCCESS); 999 state.DidDrawIfPossibleCompleted(DrawSwapReadbackResult::DRAW_SUCCESS);
979 1000
980 // Should be synchronized, no draw needed, no action needed. 1001 // Should be synchronized, no draw needed, no action needed.
981 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1002 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
982 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState()); 1003 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState());
983 EXPECT_FALSE(state.needs_redraw()); 1004 EXPECT_FALSE(state.needs_redraw());
984 1005
985 // Next BeginImplFrame should initiate second commit. 1006 // Next BeginImplFrame should initiate second commit.
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
1074 state.BeginMainFrameAborted(true); 1095 state.BeginMainFrameAborted(true);
1075 1096
1076 // Verify that another commit doesn't start on the same frame. 1097 // Verify that another commit doesn't start on the same frame.
1077 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState()); 1098 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState());
1078 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); 1099 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction());
1079 EXPECT_FALSE(state.NeedsCommit()); 1100 EXPECT_FALSE(state.NeedsCommit());
1080 1101
1081 // Start a new frame; draw because this is the first frame since output 1102 // Start a new frame; draw because this is the first frame since output
1082 // surface init'd. 1103 // surface init'd.
1083 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 1104 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting());
1105 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
1084 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1106 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1085 state.OnBeginImplFrameDeadline(); 1107 state.OnBeginImplFrameDeadline();
1086 EXPECT_ACTION_UPDATE_STATE( 1108 EXPECT_ACTION_UPDATE_STATE(
1087 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 1109 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
1088 1110
1089 // Verify another commit doesn't start on another frame either. 1111 // Verify another commit doesn't start on another frame either.
1090 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState()); 1112 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState());
1091 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); 1113 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction());
1092 EXPECT_FALSE(state.NeedsCommit()); 1114 EXPECT_FALSE(state.NeedsCommit());
1093 1115
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
1199 state.NotifyReadyToCommit(); 1221 state.NotifyReadyToCommit();
1200 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 1222 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
1201 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1223 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1202 // Finishing the first commit after initializing an output surface should 1224 // Finishing the first commit after initializing an output surface should
1203 // automatically cause a redraw. 1225 // automatically cause a redraw.
1204 EXPECT_TRUE(state.RedrawPending()); 1226 EXPECT_TRUE(state.RedrawPending());
1205 1227
1206 // Once the context is recreated, whether we draw should be based on 1228 // Once the context is recreated, whether we draw should be based on
1207 // SetCanDraw. 1229 // SetCanDraw.
1208 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 1230 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting());
1231 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
1209 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1232 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1210 state.OnBeginImplFrameDeadline(); 1233 state.OnBeginImplFrameDeadline();
1211 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE, 1234 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE,
1212 state.NextAction()); 1235 state.NextAction());
1213 state.SetCanDraw(false); 1236 state.SetCanDraw(false);
1214 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT, 1237 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT,
1215 state.NextAction()); 1238 state.NextAction());
1216 state.SetCanDraw(true); 1239 state.SetCanDraw(true);
1217 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE, 1240 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE,
1218 state.NextAction()); 1241 state.NextAction());
1219 } 1242 }
1220 1243
1221 TEST(SchedulerStateMachineTest, TestContextLostWhileCommitInProgress) { 1244 TEST(SchedulerStateMachineTest, TestContextLostWhileCommitInProgress) {
1222 SchedulerSettings scheduler_settings; 1245 SchedulerSettings scheduler_settings;
1223 StateMachine state(scheduler_settings); 1246 StateMachine state(scheduler_settings);
1224 state.SetCanStart(); 1247 state.SetCanStart();
1225 state.UpdateState(state.NextAction()); 1248 state.UpdateState(state.NextAction());
1226 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 1249 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
1227 state.SetVisible(true); 1250 state.SetVisible(true);
1228 state.SetCanDraw(true); 1251 state.SetCanDraw(true);
1229 1252
1230 // Get a commit in flight. 1253 // Get a commit in flight.
1231 state.SetNeedsCommit(); 1254 state.SetNeedsCommit();
1232 1255
1233 // Set damage and expect a draw. 1256 // Set damage and expect a draw.
1234 state.SetNeedsRedraw(true); 1257 state.SetNeedsRedraw(true);
1235 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 1258 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting());
1259 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
1236 EXPECT_ACTION_UPDATE_STATE( 1260 EXPECT_ACTION_UPDATE_STATE(
1237 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 1261 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
1238 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1262 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1239 state.OnBeginImplFrameDeadline(); 1263 state.OnBeginImplFrameDeadline();
1240 EXPECT_ACTION_UPDATE_STATE( 1264 EXPECT_ACTION_UPDATE_STATE(
1241 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 1265 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
1242 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1266 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1243 1267
1244 // Cause a lost context while the BeginMainFrame is in flight. 1268 // Cause a lost context while the BeginMainFrame is in flight.
1245 state.DidLoseOutputSurface(); 1269 state.DidLoseOutputSurface();
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
1290 state.SetVisible(true); 1314 state.SetVisible(true);
1291 state.SetCanDraw(true); 1315 state.SetCanDraw(true);
1292 1316
1293 // Get a commit in flight. 1317 // Get a commit in flight.
1294 state.SetNeedsCommit(); 1318 state.SetNeedsCommit();
1295 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1319 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1296 1320
1297 // Set damage and expect a draw. 1321 // Set damage and expect a draw.
1298 state.SetNeedsRedraw(true); 1322 state.SetNeedsRedraw(true);
1299 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 1323 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting());
1324 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
1300 EXPECT_ACTION_UPDATE_STATE( 1325 EXPECT_ACTION_UPDATE_STATE(
1301 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 1326 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
1302 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1327 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1303 state.OnBeginImplFrameDeadline(); 1328 state.OnBeginImplFrameDeadline();
1304 EXPECT_ACTION_UPDATE_STATE( 1329 EXPECT_ACTION_UPDATE_STATE(
1305 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 1330 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
1306 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1331 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1307 1332
1308 // Cause a lost context while the BeginMainFrame is in flight. 1333 // Cause a lost context while the BeginMainFrame is in flight.
1309 state.DidLoseOutputSurface(); 1334 state.DidLoseOutputSurface();
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
1351 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 1376 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
1352 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 1377 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting());
1353 EXPECT_ACTION_UPDATE_STATE( 1378 EXPECT_ACTION_UPDATE_STATE(
1354 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 1379 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
1355 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1380 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1356 state.NotifyBeginMainFrameStarted(); 1381 state.NotifyBeginMainFrameStarted();
1357 state.NotifyReadyToCommit(); 1382 state.NotifyReadyToCommit();
1358 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 1383 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
1359 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1384 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1360 state.OnBeginImplFrameDeadline(); 1385 state.OnBeginImplFrameDeadline();
1386 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
1361 EXPECT_ACTION_UPDATE_STATE( 1387 EXPECT_ACTION_UPDATE_STATE(
1362 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 1388 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
1363 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1389 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1364 } 1390 }
1365 1391
1366 TEST(SchedulerStateMachineTest, TestFinishAllRenderingWhileContextLost) { 1392 TEST(SchedulerStateMachineTest, TestFinishAllRenderingWhileContextLost) {
1367 SchedulerSettings default_scheduler_settings; 1393 SchedulerSettings default_scheduler_settings;
1368 StateMachine state(default_scheduler_settings); 1394 StateMachine state(default_scheduler_settings);
1369 state.SetCanStart(); 1395 state.SetCanStart();
1370 state.UpdateState(state.NextAction()); 1396 state.UpdateState(state.NextAction());
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
1514 state.readback_state()); 1540 state.readback_state());
1515 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT, 1541 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT,
1516 state.CommitState()); 1542 state.CommitState());
1517 1543
1518 // Finish the replacement commit. 1544 // Finish the replacement commit.
1519 state.NotifyBeginMainFrameStarted(); 1545 state.NotifyBeginMainFrameStarted();
1520 state.NotifyReadyToCommit(); 1546 state.NotifyReadyToCommit();
1521 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 1547 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
1522 1548
1523 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 1549 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting());
1550 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
1524 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1551 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1525 state.OnBeginImplFrameDeadline(); 1552 state.OnBeginImplFrameDeadline();
1526 EXPECT_ACTION_UPDATE_STATE( 1553 EXPECT_ACTION_UPDATE_STATE(
1527 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 1554 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
1528 EXPECT_EQ(SchedulerStateMachine::READBACK_STATE_IDLE, state.readback_state()); 1555 EXPECT_EQ(SchedulerStateMachine::READBACK_STATE_IDLE, state.readback_state());
1529 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1556 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1530 } 1557 }
1531 1558
1532 TEST(SchedulerStateMachineTest, TestFinishCommitWhenCommitInProgress) { 1559 TEST(SchedulerStateMachineTest, TestFinishCommitWhenCommitInProgress) {
1533 SchedulerSettings default_scheduler_settings; 1560 SchedulerSettings default_scheduler_settings;
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after
1860 // This test mirrors what happens during the first frame of a scroll gesture. 1887 // This test mirrors what happens during the first frame of a scroll gesture.
1861 // First we get the input event and a BeginFrame. 1888 // First we get the input event and a BeginFrame.
1862 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 1889 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting());
1863 1890
1864 // As a response the compositor requests a redraw and a commit to tell the 1891 // As a response the compositor requests a redraw and a commit to tell the
1865 // main thread about the new scroll offset. 1892 // main thread about the new scroll offset.
1866 state.SetNeedsRedraw(true); 1893 state.SetNeedsRedraw(true);
1867 state.SetNeedsCommit(); 1894 state.SetNeedsCommit();
1868 1895
1869 // We should start the commit normally. 1896 // We should start the commit normally.
1897 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
1870 EXPECT_ACTION_UPDATE_STATE( 1898 EXPECT_ACTION_UPDATE_STATE(
1871 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 1899 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
1872 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1900 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1873 1901
1874 // Since only the scroll offset changed, the main thread will abort the 1902 // Since only the scroll offset changed, the main thread will abort the
1875 // commit. 1903 // commit.
1876 state.BeginMainFrameAborted(true); 1904 state.BeginMainFrameAborted(true);
1877 1905
1878 // Since the commit was aborted, we should draw right away instead of waiting 1906 // Since the commit was aborted, we should draw right away instead of waiting
1879 // for the deadline. 1907 // for the deadline.
1880 EXPECT_TRUE(state.ShouldTriggerBeginImplFrameDeadlineEarly()); 1908 EXPECT_TRUE(state.ShouldTriggerBeginImplFrameDeadlineEarly());
1881 } 1909 }
1882 1910
1883 TEST(SchedulerStateMachineTest, TestTriggerDeadlineEarlyForSmoothness) { 1911 TEST(SchedulerStateMachineTest, TestTriggerDeadlineEarlyForSmoothness) {
1884 SchedulerSettings settings; 1912 SchedulerSettings settings;
1885 settings.impl_side_painting = true; 1913 settings.impl_side_painting = true;
1886 StateMachine state(settings); 1914 StateMachine state(settings);
1887 state.SetCanStart(); 1915 state.SetCanStart();
1888 state.UpdateState(state.NextAction()); 1916 state.UpdateState(state.NextAction());
1889 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 1917 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
1890 state.SetVisible(true); 1918 state.SetVisible(true);
1891 state.SetCanDraw(true); 1919 state.SetCanDraw(true);
1892 1920
1893 // This test ensures that impl-draws are prioritized over main thread updates 1921 // This test ensures that impl-draws are prioritized over main thread updates
1894 // in prefer smoothness mode. 1922 // in prefer smoothness mode.
1895 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 1923 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting());
1896 state.SetNeedsRedraw(true); 1924 state.SetNeedsRedraw(true);
1897 state.SetNeedsCommit(); 1925 state.SetNeedsCommit();
1926 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
1898 EXPECT_ACTION_UPDATE_STATE( 1927 EXPECT_ACTION_UPDATE_STATE(
1899 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 1928 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
1900 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1929 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1901 1930
1902 // The deadline is not triggered early until we enter prefer smoothness mode. 1931 // The deadline is not triggered early until we enter prefer smoothness mode.
1903 EXPECT_FALSE(state.ShouldTriggerBeginImplFrameDeadlineEarly()); 1932 EXPECT_FALSE(state.ShouldTriggerBeginImplFrameDeadlineEarly());
1904 state.SetSmoothnessTakesPriority(true); 1933 state.SetSmoothnessTakesPriority(true);
1905 EXPECT_TRUE(state.ShouldTriggerBeginImplFrameDeadlineEarly()); 1934 EXPECT_TRUE(state.ShouldTriggerBeginImplFrameDeadlineEarly());
1906 } 1935 }
1907 1936
1937 TEST(SchedulerStateMachineTest, TestSetNeedsAnimate) {
1938 SchedulerSettings settings;
1939 settings.impl_side_painting = true;
1940 StateMachine state(settings);
1941 state.SetCanStart();
1942 state.UpdateState(state.NextAction());
1943 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
1944 state.SetVisible(true);
1945 state.SetCanDraw(true);
1946
1947 // Test requesting an animation that, when run, causes us to draw.
1948 state.SetNeedsAnimate();
1949 EXPECT_TRUE(state.BeginImplFrameNeeded());
1950
1951 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting());
1952 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
1953
1954 state.OnBeginImplFrameDeadlinePending();
1955 state.OnBeginImplFrameDeadline();
1956 EXPECT_ACTION_UPDATE_STATE(
1957 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
1958 }
1959
1960 TEST(SchedulerStateMachineTest, TestAnimateBeforeCommit) {
1961 SchedulerSettings settings;
1962 settings.impl_side_painting = true;
1963 StateMachine state(settings);
1964 state.SetCanStart();
1965 state.UpdateState(state.NextAction());
1966 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
1967 state.SetVisible(true);
1968 state.SetCanDraw(true);
1969
1970 // Check that animations are updated before we start a commit.
1971 state.SetNeedsAnimate();
brianderson 2014/04/01 16:05:11 Can you add a test that verifies what happens when
Sami 2014/04/17 15:16:33 Good idea, done.
1972 state.SetNeedsCommit();
1973 EXPECT_TRUE(state.BeginImplFrameNeeded());
1974
1975 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting());
brianderson 2014/04/01 16:05:11 Can you verify that no actions are triggered befor
Sami 2014/04/17 15:16:33 Done.
1976 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
1977 EXPECT_ACTION_UPDATE_STATE(
1978 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
1979
1980 state.OnBeginImplFrameDeadlinePending();
1981 state.OnBeginImplFrameDeadline();
1982 EXPECT_ACTION_UPDATE_STATE(
1983 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
1984 }
1985
1908 } // namespace 1986 } // namespace
1909 } // namespace cc 1987 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698