Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2011 The Chromium Authors. All rights reserved. | 1 // Copyright 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "cc/scheduler/scheduler_state_machine.h" | 5 #include "cc/scheduler/scheduler_state_machine.h" |
| 6 | 6 |
| 7 #include "cc/scheduler/scheduler.h" | 7 #include "cc/scheduler/scheduler.h" |
| 8 #include "cc/test/begin_frame_args_test.h" | 8 #include "cc/test/begin_frame_args_test.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 | 10 |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 67 } | 67 } |
| 68 | 68 |
| 69 BeginImplFrameState begin_impl_frame_state() const { | 69 BeginImplFrameState begin_impl_frame_state() const { |
| 70 return begin_impl_frame_state_; | 70 return begin_impl_frame_state_; |
| 71 } | 71 } |
| 72 | 72 |
| 73 OutputSurfaceState output_surface_state() const { | 73 OutputSurfaceState output_surface_state() const { |
| 74 return output_surface_state_; | 74 return output_surface_state_; |
| 75 } | 75 } |
| 76 | 76 |
| 77 void SetReadbackState(SynchronousReadbackState rs) { readback_state_ = rs; } | |
| 78 SynchronousReadbackState readback_state() const { return readback_state_; } | |
| 79 | |
| 80 bool NeedsCommit() const { return needs_commit_; } | 77 bool NeedsCommit() const { return needs_commit_; } |
| 81 | 78 |
| 82 void SetNeedsRedraw(bool b) { needs_redraw_ = b; } | 79 void SetNeedsRedraw(bool b) { needs_redraw_ = b; } |
| 83 | 80 |
| 84 void SetNeedsForcedRedrawForTimeout(bool b) { | 81 void SetNeedsForcedRedrawForTimeout(bool b) { |
| 85 forced_redraw_state_ = FORCED_REDRAW_STATE_WAITING_FOR_COMMIT; | 82 forced_redraw_state_ = FORCED_REDRAW_STATE_WAITING_FOR_COMMIT; |
| 86 active_tree_needs_first_draw_ = true; | 83 active_tree_needs_first_draw_ = true; |
| 87 } | 84 } |
| 88 bool NeedsForcedRedrawForTimeout() const { | 85 bool NeedsForcedRedrawForTimeout() const { |
| 89 return forced_redraw_state_ != FORCED_REDRAW_STATE_IDLE; | 86 return forced_redraw_state_ != FORCED_REDRAW_STATE_IDLE; |
| 90 } | 87 } |
| 91 | 88 |
| 92 void SetNeedsForcedRedrawForReadback() { | |
| 93 readback_state_ = READBACK_STATE_WAITING_FOR_DRAW_AND_READBACK; | |
| 94 active_tree_needs_first_draw_ = true; | |
| 95 } | |
| 96 | |
| 97 bool NeedsForcedRedrawForReadback() const { | |
| 98 return readback_state_ != READBACK_STATE_IDLE; | |
| 99 } | |
| 100 | |
| 101 void SetActiveTreeNeedsFirstDraw(bool needs_first_draw) { | 89 void SetActiveTreeNeedsFirstDraw(bool needs_first_draw) { |
| 102 active_tree_needs_first_draw_ = needs_first_draw; | 90 active_tree_needs_first_draw_ = needs_first_draw; |
| 103 } | 91 } |
| 104 | 92 |
| 105 bool CanDraw() const { return can_draw_; } | 93 bool CanDraw() const { return can_draw_; } |
| 106 bool Visible() const { return visible_; } | 94 bool Visible() const { return visible_; } |
| 107 | 95 |
| 108 bool PendingActivationsShouldBeForced() const { | 96 bool PendingActivationsShouldBeForced() const { |
| 109 return SchedulerStateMachine::PendingActivationsShouldBeForced(); | 97 return SchedulerStateMachine::PendingActivationsShouldBeForced(); |
| 110 } | 98 } |
| (...skipping 592 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 703 // Case 2: needs_commit=true | 691 // Case 2: needs_commit=true |
| 704 state.SetNeedsCommit(); | 692 state.SetNeedsCommit(); |
| 705 EXPECT_NE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE, | 693 EXPECT_NE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE, |
| 706 state.NextAction()) | 694 state.NextAction()) |
| 707 << *state.AsValue(); | 695 << *state.AsValue(); |
| 708 } | 696 } |
| 709 } | 697 } |
| 710 | 698 |
| 711 // When in BeginImplFrame deadline we should always draw for SetNeedsRedraw | 699 // When in BeginImplFrame deadline we should always draw for SetNeedsRedraw |
| 712 // except if we're ready to commit, in which case we expect a commit first. | 700 // except if we're ready to commit, in which case we expect a commit first. |
| 713 // SetNeedsForcedRedrawForReadback should take precedence over all and | |
| 714 // issue a readback. | |
| 715 for (size_t i = 0; i < num_commit_states; ++i) { | 701 for (size_t i = 0; i < num_commit_states; ++i) { |
| 716 for (size_t j = 0; j < 2; ++j) { | 702 StateMachine state(default_scheduler_settings); |
| 717 bool request_readback = j; | 703 state.SetCanStart(); |
| 704 state.UpdateState(state.NextAction()); | |
| 705 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); | |
| 706 state.SetCanDraw(true); | |
| 707 state.SetCommitState(all_commit_states[i]); | |
| 708 state.SetBeginImplFrameState( | |
| 709 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE); | |
| 718 | 710 |
| 719 StateMachine state(default_scheduler_settings); | 711 state.SetNeedsRedraw(true); |
| 720 state.SetCanStart(); | 712 state.SetVisible(true); |
| 713 | |
| 714 SchedulerStateMachine::Action expected_action; | |
| 715 if (all_commit_states[i] == | |
| 716 SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT) { | |
| 717 expected_action = SchedulerStateMachine::ACTION_COMMIT; | |
| 718 } else { | |
| 719 expected_action = SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE; | |
| 720 EXPECT_EQ(state.NextAction(), SchedulerStateMachine::ACTION_ANIMATE) | |
| 721 << *state.AsValue(); | |
| 721 state.UpdateState(state.NextAction()); | 722 state.UpdateState(state.NextAction()); |
| 722 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); | 723 } |
| 723 state.SetCanDraw(true); | |
| 724 state.SetCommitState(all_commit_states[i]); | |
| 725 state.SetBeginImplFrameState( | |
| 726 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE); | |
| 727 | 724 |
| 728 if (request_readback) { | 725 // Case 1: needs_commit=false. |
| 729 state.SetNeedsForcedRedrawForReadback(); | 726 EXPECT_EQ(state.NextAction(), expected_action) << *state.AsValue(); |
| 730 } else { | |
| 731 state.SetNeedsRedraw(true); | |
| 732 state.SetVisible(true); | |
| 733 } | |
| 734 | 727 |
| 735 SchedulerStateMachine::Action expected_action; | 728 // Case 2: needs_commit=true. |
| 736 if (request_readback) { | 729 state.SetNeedsCommit(); |
| 737 expected_action = SchedulerStateMachine::ACTION_DRAW_AND_READBACK; | 730 EXPECT_EQ(state.NextAction(), expected_action) << *state.AsValue(); |
| 738 } else if (all_commit_states[i] == | |
| 739 SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT) { | |
| 740 expected_action = SchedulerStateMachine::ACTION_COMMIT; | |
| 741 } else { | |
| 742 expected_action = | |
| 743 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE; | |
| 744 EXPECT_EQ(state.NextAction(), SchedulerStateMachine::ACTION_ANIMATE) | |
| 745 << *state.AsValue(); | |
| 746 state.UpdateState(state.NextAction()); | |
| 747 } | |
| 748 | |
| 749 // Case 1: needs_commit=false. | |
| 750 EXPECT_NE(state.BeginFrameNeeded(), request_readback) << *state.AsValue(); | |
| 751 EXPECT_EQ(state.NextAction(), expected_action) << *state.AsValue(); | |
| 752 | |
| 753 // Case 2: needs_commit=true. | |
| 754 state.SetNeedsCommit(); | |
| 755 EXPECT_NE(state.BeginFrameNeeded(), request_readback) << *state.AsValue(); | |
| 756 EXPECT_EQ(state.NextAction(), expected_action) << *state.AsValue(); | |
| 757 } | |
| 758 } | 731 } |
| 759 } | 732 } |
| 760 | 733 |
| 761 TEST(SchedulerStateMachineTest, TestNoCommitStatesRedrawWhenInvisible) { | 734 TEST(SchedulerStateMachineTest, TestNoCommitStatesRedrawWhenInvisible) { |
| 762 SchedulerSettings default_scheduler_settings; | 735 SchedulerSettings default_scheduler_settings; |
| 763 | 736 |
| 764 size_t num_commit_states = | 737 size_t num_commit_states = |
| 765 sizeof(all_commit_states) / sizeof(SchedulerStateMachine::CommitState); | 738 sizeof(all_commit_states) / sizeof(SchedulerStateMachine::CommitState); |
| 766 for (size_t i = 0; i < num_commit_states; ++i) { | 739 for (size_t i = 0; i < num_commit_states; ++i) { |
| 767 // There shouldn't be any drawing regardless of BeginImplFrame. | 740 // There shouldn't be any drawing regardless of BeginImplFrame. |
| (...skipping 655 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1423 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | 1396 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 1424 state.OnBeginImplFrameDeadline(); | 1397 state.OnBeginImplFrameDeadline(); |
| 1425 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE); | 1398 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE); |
| 1426 EXPECT_ACTION_UPDATE_STATE( | 1399 EXPECT_ACTION_UPDATE_STATE( |
| 1427 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); | 1400 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); |
| 1428 state.DidSwapBuffers(); | 1401 state.DidSwapBuffers(); |
| 1429 state.DidSwapBuffersComplete(); | 1402 state.DidSwapBuffersComplete(); |
| 1430 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | 1403 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 1431 } | 1404 } |
| 1432 | 1405 |
| 1433 TEST(SchedulerStateMachineTest, TestFinishAllRenderingWhileContextLost) { | |
|
brianderson
2014/05/16 21:38:17
I was worried we might be losing DRAW_AND_SWAP_ABO
| |
| 1434 SchedulerSettings default_scheduler_settings; | |
| 1435 StateMachine state(default_scheduler_settings); | |
| 1436 state.SetCanStart(); | |
| 1437 state.UpdateState(state.NextAction()); | |
| 1438 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); | |
| 1439 state.SetVisible(true); | |
| 1440 state.SetCanDraw(true); | |
| 1441 | |
| 1442 // Cause a lost context lost. | |
| 1443 state.DidLoseOutputSurface(); | |
| 1444 | |
| 1445 // Ask a forced redraw for readback and verify it ocurrs. | |
| 1446 state.SetNeedsForcedRedrawForReadback(); | |
| 1447 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting()); | |
| 1448 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_READBACK); | |
| 1449 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | |
| 1450 | |
| 1451 // Forced redraws for readbacks need to be followed by a new commit | |
| 1452 // to replace the readback commit. | |
| 1453 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT, | |
| 1454 state.CommitState()); | |
| 1455 state.NotifyBeginMainFrameStarted(); | |
| 1456 state.NotifyReadyToCommit(); | |
| 1457 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); | |
| 1458 | |
| 1459 // We don't yet have an output surface, so we the draw and swap should abort. | |
| 1460 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT); | |
| 1461 | |
| 1462 // Expect to begin context recreation only in BEGIN_IMPL_FRAME_STATE_IDLE | |
| 1463 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); | |
| 1464 | |
| 1465 state.OnBeginImplFrameDeadline(); | |
| 1466 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); | |
| 1467 | |
| 1468 state.OnBeginImplFrameIdle(); | |
| 1469 EXPECT_ACTION_UPDATE_STATE( | |
| 1470 SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION); | |
| 1471 | |
| 1472 // Ask a readback and verify it occurs. | |
| 1473 state.SetNeedsForcedRedrawForReadback(); | |
| 1474 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_READBACK); | |
| 1475 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | |
| 1476 } | |
| 1477 | |
| 1478 TEST(SchedulerStateMachineTest, DontDrawBeforeCommitAfterLostOutputSurface) { | 1406 TEST(SchedulerStateMachineTest, DontDrawBeforeCommitAfterLostOutputSurface) { |
| 1479 SchedulerSettings default_scheduler_settings; | 1407 SchedulerSettings default_scheduler_settings; |
| 1480 StateMachine state(default_scheduler_settings); | 1408 StateMachine state(default_scheduler_settings); |
| 1481 state.SetCanStart(); | 1409 state.SetCanStart(); |
| 1482 state.UpdateState(state.NextAction()); | 1410 state.UpdateState(state.NextAction()); |
| 1483 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); | 1411 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); |
| 1484 state.SetVisible(true); | 1412 state.SetVisible(true); |
| 1485 state.SetCanDraw(true); | 1413 state.SetCanDraw(true); |
| 1486 | 1414 |
| 1487 state.SetNeedsRedraw(true); | 1415 state.SetNeedsRedraw(true); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1521 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); | 1449 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); |
| 1522 | 1450 |
| 1523 EXPECT_TRUE(state.PendingActivationsShouldBeForced()); | 1451 EXPECT_TRUE(state.PendingActivationsShouldBeForced()); |
| 1524 EXPECT_ACTION_UPDATE_STATE( | 1452 EXPECT_ACTION_UPDATE_STATE( |
| 1525 SchedulerStateMachine::ACTION_ACTIVATE_PENDING_TREE); | 1453 SchedulerStateMachine::ACTION_ACTIVATE_PENDING_TREE); |
| 1526 | 1454 |
| 1527 EXPECT_TRUE(state.PendingDrawsShouldBeAborted()); | 1455 EXPECT_TRUE(state.PendingDrawsShouldBeAborted()); |
| 1528 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT); | 1456 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT); |
| 1529 } | 1457 } |
| 1530 | 1458 |
| 1531 TEST(SchedulerStateMachineTest, | 1459 TEST(SchedulerStateMachineTest, TestSendBeginMainFrameWhenInvisible) { |
|
brianderson
2014/05/16 21:38:17
TestNoBeginMainFrameWhenInvisible?
danakj
2014/05/16 22:16:03
Done.
| |
| 1532 TestSendBeginMainFrameWhenInvisibleAndForceCommit) { | |
| 1533 SchedulerSettings default_scheduler_settings; | 1460 SchedulerSettings default_scheduler_settings; |
| 1534 StateMachine state(default_scheduler_settings); | 1461 StateMachine state(default_scheduler_settings); |
| 1535 state.SetCanStart(); | 1462 state.SetCanStart(); |
| 1536 state.UpdateState(state.NextAction()); | 1463 state.UpdateState(state.NextAction()); |
| 1537 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); | 1464 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); |
| 1538 state.SetVisible(false); | 1465 state.SetVisible(false); |
| 1539 state.SetNeedsForcedCommitForReadback(); | 1466 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); |
|
brianderson
2014/05/16 21:38:17
Before this line, put:
state.SetNeedsCommit();
so
danakj
2014/05/16 22:16:03
Done.
| |
| 1540 EXPECT_EQ(SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME, | |
| 1541 state.NextAction()); | |
| 1542 } | |
| 1543 | |
| 1544 TEST(SchedulerStateMachineTest, | |
| 1545 TestSendBeginMainFrameWhenCanStartFalseAndForceCommit) { | |
| 1546 SchedulerSettings default_scheduler_settings; | |
| 1547 StateMachine state(default_scheduler_settings); | |
| 1548 state.SetVisible(true); | |
| 1549 state.SetCanDraw(true); | |
| 1550 state.SetNeedsForcedCommitForReadback(); | |
| 1551 EXPECT_EQ(SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME, | |
| 1552 state.NextAction()); | |
| 1553 } | |
| 1554 | |
| 1555 // If new commit is not requested explicitly after starting forced commit, | |
| 1556 // new commit should not scheduled after drawing the replacement commit. | |
| 1557 TEST(SchedulerStateMachineTest, DontMakeNewCommitAfterDrawingReplaceCommit) { | |
| 1558 SchedulerSettings default_scheduler_settings; | |
| 1559 StateMachine state(default_scheduler_settings); | |
| 1560 state.SetCanStart(); | |
| 1561 state.UpdateState(state.NextAction()); | |
| 1562 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); | |
| 1563 state.SetVisible(true); | |
| 1564 state.SetCanDraw(true); | |
| 1565 | |
| 1566 // There is a scheduled commit. | |
| 1567 state.SetCommitState( | |
| 1568 SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT); | |
| 1569 | |
| 1570 // Request a forced commit. | |
| 1571 state.SetNeedsForcedCommitForReadback(); | |
| 1572 | |
| 1573 state.NotifyBeginMainFrameStarted(); | |
| 1574 state.NotifyReadyToCommit(); | |
| 1575 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); | |
| 1576 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_AND_READBACK, | |
| 1577 state.NextAction()); | |
| 1578 state.UpdateState(state.NextAction()); | |
| 1579 EXPECT_EQ( | |
| 1580 SchedulerStateMachine::READBACK_STATE_WAITING_FOR_REPLACEMENT_COMMIT, | |
| 1581 state.readback_state()); | |
| 1582 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT, | |
| 1583 state.CommitState()); | |
| 1584 | |
| 1585 // Finish the replacement commit. | |
| 1586 state.NotifyBeginMainFrameStarted(); | |
| 1587 state.NotifyReadyToCommit(); | |
| 1588 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); | |
| 1589 | |
| 1590 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting()); | |
| 1591 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE); | |
| 1592 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | |
| 1593 state.OnBeginImplFrameDeadline(); | |
| 1594 EXPECT_ACTION_UPDATE_STATE( | |
| 1595 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); | |
| 1596 EXPECT_EQ(SchedulerStateMachine::READBACK_STATE_IDLE, state.readback_state()); | |
| 1597 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | |
| 1598 } | 1467 } |
| 1599 | 1468 |
| 1600 TEST(SchedulerStateMachineTest, TestFinishCommitWhenCommitInProgress) { | 1469 TEST(SchedulerStateMachineTest, TestFinishCommitWhenCommitInProgress) { |
| 1601 SchedulerSettings default_scheduler_settings; | 1470 SchedulerSettings default_scheduler_settings; |
| 1602 StateMachine state(default_scheduler_settings); | 1471 StateMachine state(default_scheduler_settings); |
| 1603 state.SetCanStart(); | 1472 state.SetCanStart(); |
| 1604 state.UpdateState(state.NextAction()); | 1473 state.UpdateState(state.NextAction()); |
| 1605 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); | 1474 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); |
| 1606 state.SetVisible(false); | 1475 state.SetVisible(false); |
| 1607 state.SetCommitState( | 1476 state.SetCommitState( |
| 1608 SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT); | 1477 SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT); |
| 1609 state.SetNeedsCommit(); | 1478 state.SetNeedsCommit(); |
| 1610 | 1479 |
| 1611 state.NotifyBeginMainFrameStarted(); | 1480 state.NotifyBeginMainFrameStarted(); |
| 1612 state.NotifyReadyToCommit(); | 1481 state.NotifyReadyToCommit(); |
| 1613 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction()); | 1482 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction()); |
| 1614 state.UpdateState(state.NextAction()); | 1483 state.UpdateState(state.NextAction()); |
| 1615 | 1484 |
| 1616 EXPECT_TRUE(state.active_tree_needs_first_draw()); | 1485 EXPECT_TRUE(state.active_tree_needs_first_draw()); |
| 1617 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT); | 1486 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT); |
| 1618 } | 1487 } |
| 1619 | 1488 |
| 1620 TEST(SchedulerStateMachineTest, TestFinishCommitWhenForcedCommitInProgress) { | |
| 1621 SchedulerSettings default_scheduler_settings; | |
| 1622 StateMachine state(default_scheduler_settings); | |
| 1623 state.SetCanStart(); | |
| 1624 state.UpdateState(state.NextAction()); | |
| 1625 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); | |
| 1626 state.SetVisible(false); | |
| 1627 state.SetCommitState( | |
| 1628 SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT); | |
| 1629 state.SetNeedsForcedCommitForReadback(); | |
| 1630 | |
| 1631 // The commit for readback interupts the normal commit. | |
| 1632 state.NotifyBeginMainFrameStarted(); | |
| 1633 state.NotifyReadyToCommit(); | |
| 1634 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); | |
| 1635 | |
| 1636 EXPECT_TRUE(state.active_tree_needs_first_draw()); | |
| 1637 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_READBACK); | |
| 1638 | |
| 1639 // When the readback interrupts the normal commit, we should not get | |
| 1640 // another BeginMainFrame when the readback completes. | |
| 1641 EXPECT_NE(SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME, | |
| 1642 state.NextAction()); | |
| 1643 | |
| 1644 // The normal commit can then proceed. | |
| 1645 state.NotifyBeginMainFrameStarted(); | |
| 1646 state.NotifyReadyToCommit(); | |
| 1647 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); | |
| 1648 } | |
| 1649 | |
| 1650 void TestForceCommitWhenReplacementActivationInProgress( | |
| 1651 bool main_frame_before_draw_enabled) { | |
| 1652 SchedulerSettings settings; | |
| 1653 settings.impl_side_painting = true; | |
| 1654 settings.main_frame_before_draw_enabled = main_frame_before_draw_enabled; | |
| 1655 StateMachine state(settings); | |
| 1656 state.SetCanStart(); | |
| 1657 state.UpdateState(state.NextAction()); | |
| 1658 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); | |
| 1659 state.SetVisible(true); | |
| 1660 state.SetCanDraw(true); | |
| 1661 | |
| 1662 // Impl-side painting of replacement commit is in-progress. | |
| 1663 if (settings.main_frame_before_draw_enabled) { | |
| 1664 state.SetCommitState( | |
| 1665 SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_ACTIVATION); | |
| 1666 } else { | |
| 1667 state.SetCommitState( | |
| 1668 SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW); | |
| 1669 } | |
| 1670 state.SetReadbackState( | |
| 1671 SchedulerStateMachine::READBACK_STATE_WAITING_FOR_REPLACEMENT_ACTIVATION); | |
| 1672 state.SetHasPendingTree(true); | |
| 1673 | |
| 1674 // Forced commit is requested during the impl-side painting. | |
| 1675 state.SetNeedsForcedCommitForReadback(); | |
| 1676 EXPECT_FALSE(state.NeedsCommit()); | |
| 1677 | |
| 1678 state.NotifyReadyToActivate(); | |
| 1679 EXPECT_ACTION_UPDATE_STATE( | |
| 1680 SchedulerStateMachine::ACTION_ACTIVATE_PENDING_TREE); | |
| 1681 // New replacement commit is needed for incoming forced commit. | |
| 1682 EXPECT_EQ(SchedulerStateMachine::READBACK_STATE_NEEDS_BEGIN_MAIN_FRAME, | |
| 1683 state.readback_state()); | |
| 1684 EXPECT_TRUE(state.NeedsCommit()); | |
| 1685 if (settings.main_frame_before_draw_enabled) { | |
| 1686 // New replacement commit is scheduled. | |
| 1687 EXPECT_ACTION_UPDATE_STATE( | |
| 1688 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); | |
| 1689 // Forced commit is started. | |
| 1690 EXPECT_EQ(SchedulerStateMachine::READBACK_STATE_WAITING_FOR_COMMIT, | |
| 1691 state.readback_state()); | |
| 1692 } | |
| 1693 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | |
| 1694 | |
| 1695 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting()); | |
| 1696 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE); | |
| 1697 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | |
| 1698 // Perform the draw & swap of replacement commit. | |
| 1699 state.OnBeginImplFrameDeadline(); | |
| 1700 EXPECT_ACTION_UPDATE_STATE( | |
| 1701 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); | |
| 1702 state.DidSwapBuffers(); | |
| 1703 state.DidSwapBuffersComplete(); | |
| 1704 if (!settings.main_frame_before_draw_enabled) { | |
| 1705 // New replacement commit is scheduled. | |
| 1706 EXPECT_ACTION_UPDATE_STATE( | |
| 1707 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); | |
| 1708 // Forced commit is started. | |
| 1709 EXPECT_EQ(SchedulerStateMachine::READBACK_STATE_WAITING_FOR_COMMIT, | |
| 1710 state.readback_state()); | |
| 1711 } | |
| 1712 EXPECT_ACTION_UPDATE_STATE( | |
| 1713 SchedulerStateMachine::ACTION_NONE); | |
| 1714 | |
| 1715 // Finish the forced commit and draw it. | |
| 1716 state.NotifyBeginMainFrameStarted(); | |
| 1717 state.NotifyReadyToCommit(); | |
| 1718 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); | |
| 1719 state.NotifyReadyToActivate(); | |
| 1720 EXPECT_ACTION_UPDATE_STATE( | |
| 1721 SchedulerStateMachine::ACTION_ACTIVATE_PENDING_TREE); | |
| 1722 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_READBACK) | |
| 1723 EXPECT_EQ( | |
| 1724 SchedulerStateMachine::READBACK_STATE_WAITING_FOR_REPLACEMENT_COMMIT, | |
| 1725 state.readback_state()); | |
| 1726 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT, | |
| 1727 state.CommitState()); | |
| 1728 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | |
| 1729 | |
| 1730 // Finish the replacement commit and draw it. | |
| 1731 state.NotifyBeginMainFrameStarted(); | |
| 1732 state.NotifyReadyToCommit(); | |
| 1733 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); | |
| 1734 state.NotifyReadyToActivate(); | |
| 1735 EXPECT_ACTION_UPDATE_STATE( | |
| 1736 SchedulerStateMachine::ACTION_ACTIVATE_PENDING_TREE); | |
| 1737 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting()); | |
| 1738 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE); | |
| 1739 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | |
| 1740 state.OnBeginImplFrameDeadline(); | |
| 1741 EXPECT_ACTION_UPDATE_STATE( | |
| 1742 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); | |
| 1743 state.DidSwapBuffers(); | |
| 1744 state.DidSwapBuffersComplete(); | |
| 1745 EXPECT_EQ(SchedulerStateMachine::READBACK_STATE_IDLE, state.readback_state()); | |
| 1746 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | |
| 1747 } | |
| 1748 | |
| 1749 // Explicitly test when main_frame_before_draw_enabled = true. | |
| 1750 TEST(SchedulerStateMachineTest, | |
| 1751 ForceCommitWhenReplacementActivationInProgressAndMainFrameEnabled) { | |
| 1752 bool main_frame_before_draw_enabled = true; | |
| 1753 TestForceCommitWhenReplacementActivationInProgress( | |
| 1754 main_frame_before_draw_enabled); | |
| 1755 } | |
| 1756 | |
| 1757 // Explicitly test when main_frame_before_draw_enabled = false. | |
| 1758 TEST(SchedulerStateMachineTest, | |
| 1759 ForceCommitWhenReplacementActivationInProgressAndMainFrameDisabled) { | |
| 1760 bool main_frame_before_draw_enabled = false; | |
| 1761 TestForceCommitWhenReplacementActivationInProgress( | |
| 1762 main_frame_before_draw_enabled); | |
| 1763 } | |
| 1764 | |
| 1765 // Test with main_frame_before_activation_enable = true; | |
| 1766 TEST(SchedulerStateMachineTest, | |
| 1767 ForceCommitWhenReplacementActivationInProgressWithMFBA) { | |
| 1768 SchedulerSettings settings; | |
| 1769 settings.impl_side_painting = true; | |
| 1770 settings.main_frame_before_activation_enabled = true; | |
| 1771 StateMachine state(settings); | |
| 1772 state.SetCanStart(); | |
| 1773 state.UpdateState(state.NextAction()); | |
| 1774 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); | |
| 1775 state.SetVisible(true); | |
| 1776 state.SetCanDraw(true); | |
| 1777 | |
| 1778 // When impl-side painting of replacement commit is in-progress, commit state | |
| 1779 // is idle because main_frame_before_activation is enabled. | |
| 1780 state.SetCommitState( | |
| 1781 SchedulerStateMachine::COMMIT_STATE_IDLE); | |
| 1782 state.SetReadbackState( | |
| 1783 SchedulerStateMachine::READBACK_STATE_WAITING_FOR_REPLACEMENT_ACTIVATION); | |
| 1784 state.SetHasPendingTree(true); | |
| 1785 | |
| 1786 // New commit is requested and scheduled when impl-side painting is in | |
| 1787 // progress. | |
| 1788 state.SetNeedsCommit(); | |
| 1789 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting()); | |
| 1790 EXPECT_ACTION_UPDATE_STATE( | |
| 1791 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); | |
| 1792 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | |
| 1793 | |
| 1794 // Forced commit is requested during the impl-side painting. | |
| 1795 state.SetNeedsForcedCommitForReadback(); | |
| 1796 EXPECT_FALSE(state.NeedsCommit()); | |
| 1797 | |
| 1798 state.OnBeginImplFrameDeadline(); | |
| 1799 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | |
| 1800 | |
| 1801 state.NotifyReadyToActivate(); | |
| 1802 EXPECT_ACTION_UPDATE_STATE( | |
| 1803 SchedulerStateMachine::ACTION_ACTIVATE_PENDING_TREE); | |
| 1804 // Replacement commit for requested forced commit is already scheduled. | |
| 1805 EXPECT_EQ(SchedulerStateMachine::READBACK_STATE_WAITING_FOR_COMMIT, | |
| 1806 state.readback_state()); | |
| 1807 EXPECT_FALSE(state.NeedsCommit()); | |
| 1808 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | |
| 1809 | |
| 1810 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting()); | |
| 1811 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE); | |
| 1812 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | |
| 1813 // Perform the draw & swap of replacement commit. | |
| 1814 state.OnBeginImplFrameDeadline(); | |
| 1815 EXPECT_ACTION_UPDATE_STATE( | |
| 1816 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); | |
| 1817 state.DidSwapBuffers(); | |
| 1818 state.DidSwapBuffersComplete(); | |
| 1819 EXPECT_ACTION_UPDATE_STATE( | |
| 1820 SchedulerStateMachine::ACTION_NONE); | |
| 1821 | |
| 1822 // forced commit is started. | |
| 1823 state.NotifyBeginMainFrameStarted(); | |
| 1824 state.NotifyReadyToCommit(); | |
| 1825 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); | |
| 1826 } | |
| 1827 | |
| 1828 TEST(SchedulerStateMachineTest, TestInitialActionsWhenContextLost) { | 1489 TEST(SchedulerStateMachineTest, TestInitialActionsWhenContextLost) { |
| 1829 SchedulerSettings default_scheduler_settings; | 1490 SchedulerSettings default_scheduler_settings; |
| 1830 StateMachine state(default_scheduler_settings); | 1491 StateMachine state(default_scheduler_settings); |
| 1831 state.SetCanStart(); | 1492 state.SetCanStart(); |
| 1832 state.UpdateState(state.NextAction()); | 1493 state.UpdateState(state.NextAction()); |
| 1833 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); | 1494 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); |
| 1834 state.SetVisible(true); | 1495 state.SetVisible(true); |
| 1835 state.SetCanDraw(true); | 1496 state.SetCanDraw(true); |
| 1836 state.SetNeedsCommit(); | 1497 state.SetNeedsCommit(); |
| 1837 state.DidLoseOutputSurface(); | 1498 state.DidLoseOutputSurface(); |
| 1838 | 1499 |
| 1839 // When we are visible, we normally want to begin output surface creation | 1500 // When we are visible, we normally want to begin output surface creation |
| 1840 // as soon as possible. | 1501 // as soon as possible. |
| 1841 EXPECT_ACTION_UPDATE_STATE( | 1502 EXPECT_ACTION_UPDATE_STATE( |
| 1842 SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION); | 1503 SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION); |
| 1843 | 1504 |
| 1844 state.DidCreateAndInitializeOutputSurface(); | 1505 state.DidCreateAndInitializeOutputSurface(); |
| 1845 EXPECT_EQ(state.output_surface_state(), | 1506 EXPECT_EQ(state.output_surface_state(), |
| 1846 SchedulerStateMachine::OUTPUT_SURFACE_WAITING_FOR_FIRST_COMMIT); | 1507 SchedulerStateMachine::OUTPUT_SURFACE_WAITING_FOR_FIRST_COMMIT); |
| 1847 | 1508 |
| 1848 // We should not send a BeginMainFrame when we are invisible, even if we've | 1509 // We should not send a BeginMainFrame when we are invisible, even if we've |
| 1849 // lost the output surface and are trying to get the first commit, since the | 1510 // lost the output surface and are trying to get the first commit, since the |
| 1850 // main thread will just abort anyway. | 1511 // main thread will just abort anyway. |
| 1851 state.SetVisible(false); | 1512 state.SetVisible(false); |
| 1852 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()) | 1513 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()) |
| 1853 << *state.AsValue(); | 1514 << *state.AsValue(); |
| 1854 | |
| 1855 // If there is a forced commit, however, we could be blocking a readback | |
| 1856 // on the main thread, so we need to unblock it before we can get our | |
| 1857 // output surface, even if we are not visible. | |
| 1858 state.SetNeedsForcedCommitForReadback(); | |
| 1859 EXPECT_EQ( | |
| 1860 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME, state.NextAction()) | |
| 1861 << *state.AsValue(); | |
| 1862 } | |
| 1863 | |
| 1864 TEST(SchedulerStateMachineTest, TestImmediateFinishCommit) { | |
| 1865 SchedulerSettings default_scheduler_settings; | |
| 1866 StateMachine state(default_scheduler_settings); | |
| 1867 state.SetCanStart(); | |
| 1868 state.UpdateState(state.NextAction()); | |
| 1869 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); | |
| 1870 state.SetVisible(true); | |
| 1871 state.SetCanDraw(true); | |
| 1872 | |
| 1873 // Schedule a readback, commit it, draw it. | |
| 1874 state.SetNeedsForcedCommitForReadback(); | |
| 1875 EXPECT_ACTION_UPDATE_STATE( | |
| 1876 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); | |
| 1877 | |
| 1878 state.NotifyBeginMainFrameStarted(); | |
| 1879 state.NotifyReadyToCommit(); | |
| 1880 | |
| 1881 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT, | |
| 1882 state.CommitState()); | |
| 1883 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); | |
| 1884 | |
| 1885 EXPECT_TRUE(state.active_tree_needs_first_draw()); | |
| 1886 | |
| 1887 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_READBACK); | |
| 1888 state.DidSwapBuffers(); | |
| 1889 state.DidDrawIfPossibleCompleted(DRAW_SUCCESS); | |
| 1890 state.DidSwapBuffersComplete(); | |
| 1891 | |
| 1892 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | |
| 1893 | |
| 1894 // Should be waiting for the normal BeginMainFrame. | |
| 1895 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT, | |
| 1896 state.CommitState()); | |
| 1897 } | |
| 1898 | |
| 1899 TEST(SchedulerStateMachineTest, TestImmediateFinishCommitDuringCommit) { | |
| 1900 SchedulerSettings scheduler_settings; | |
| 1901 StateMachine state(scheduler_settings); | |
| 1902 state.SetCanStart(); | |
| 1903 state.UpdateState(state.NextAction()); | |
| 1904 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); | |
| 1905 state.SetVisible(true); | |
| 1906 state.SetCanDraw(true); | |
| 1907 | |
| 1908 // Start a normal commit. | |
| 1909 state.SetNeedsCommit(); | |
| 1910 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | |
| 1911 | |
| 1912 // Schedule a readback, commit it, draw it. | |
| 1913 state.SetNeedsForcedCommitForReadback(); | |
| 1914 EXPECT_ACTION_UPDATE_STATE( | |
| 1915 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); | |
| 1916 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | |
| 1917 state.NotifyBeginMainFrameStarted(); | |
| 1918 state.NotifyReadyToCommit(); | |
| 1919 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT, | |
| 1920 state.CommitState()); | |
| 1921 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); | |
| 1922 | |
| 1923 EXPECT_TRUE(state.active_tree_needs_first_draw()); | |
| 1924 | |
| 1925 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_READBACK); | |
| 1926 state.DidSwapBuffers(); | |
| 1927 state.DidDrawIfPossibleCompleted(DRAW_SUCCESS); | |
| 1928 state.DidSwapBuffersComplete(); | |
| 1929 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | |
| 1930 | |
| 1931 // Should be waiting for the normal BeginMainFrame. | |
| 1932 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT, | |
| 1933 state.CommitState()) | |
| 1934 << *state.AsValue(); | |
| 1935 } | |
| 1936 | |
| 1937 TEST(SchedulerStateMachineTest, ImmediateBeginMainFrameAbortedWhileInvisible) { | |
| 1938 SchedulerSettings scheduler_settings; | |
| 1939 StateMachine state(scheduler_settings); | |
| 1940 state.SetCanStart(); | |
| 1941 state.UpdateState(state.NextAction()); | |
| 1942 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); | |
| 1943 state.SetVisible(true); | |
| 1944 state.SetCanDraw(true); | |
| 1945 | |
| 1946 state.SetNeedsCommit(); | |
| 1947 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | |
| 1948 | |
| 1949 state.SetNeedsForcedCommitForReadback(); | |
| 1950 EXPECT_ACTION_UPDATE_STATE( | |
| 1951 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); | |
| 1952 state.NotifyBeginMainFrameStarted(); | |
| 1953 state.NotifyReadyToCommit(); | |
| 1954 | |
| 1955 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT, | |
| 1956 state.CommitState()); | |
| 1957 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); | |
| 1958 | |
| 1959 EXPECT_TRUE(state.active_tree_needs_first_draw()); | |
| 1960 | |
| 1961 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_READBACK); | |
| 1962 state.DidSwapBuffers(); | |
| 1963 state.DidDrawIfPossibleCompleted(DRAW_SUCCESS); | |
| 1964 state.DidSwapBuffersComplete(); | |
| 1965 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | |
| 1966 | |
| 1967 // Should be waiting for BeginMainFrame. | |
| 1968 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT, | |
| 1969 state.CommitState()) | |
| 1970 << *state.AsValue(); | |
| 1971 | |
| 1972 // Become invisible and abort BeginMainFrame. | |
| 1973 state.SetVisible(false); | |
| 1974 state.BeginMainFrameAborted(false); | |
| 1975 | |
| 1976 // Should be back in the idle state, but needing a commit. | |
|
brianderson
2014/05/16 21:38:17
Do we need to test aborted commits without a readb
danakj
2014/05/16 22:16:03
Line 1101 does verify that an aborted commit leave
brianderson
2014/05/16 22:25:45
This test is testing with !visible. I don't think
danakj
2014/05/16 22:42:31
Ok, I added a few tests, PTAL!
| |
| 1977 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState()); | |
| 1978 EXPECT_TRUE(state.NeedsCommit()); | |
| 1979 } | |
| 1980 | |
| 1981 TEST(SchedulerStateMachineTest, ImmediateFinishCommitWhileCantDraw) { | |
| 1982 SchedulerSettings default_scheduler_settings; | |
| 1983 StateMachine state(default_scheduler_settings); | |
| 1984 state.SetCanStart(); | |
| 1985 state.UpdateState(state.NextAction()); | |
| 1986 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); | |
| 1987 state.SetVisible(true); | |
| 1988 state.SetCanDraw(false); | |
| 1989 | |
| 1990 state.SetNeedsCommit(); | |
| 1991 state.UpdateState(state.NextAction()); | |
| 1992 | |
| 1993 state.SetNeedsForcedCommitForReadback(); | |
| 1994 state.UpdateState(state.NextAction()); | |
| 1995 state.NotifyBeginMainFrameStarted(); | |
| 1996 state.NotifyReadyToCommit(); | |
| 1997 | |
| 1998 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT, | |
| 1999 state.CommitState()); | |
| 2000 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); | |
| 2001 | |
| 2002 EXPECT_TRUE(state.active_tree_needs_first_draw()); | |
| 2003 | |
| 2004 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_READBACK); | |
| 2005 state.DidSwapBuffers(); | |
| 2006 state.DidDrawIfPossibleCompleted(DRAW_SUCCESS); | |
| 2007 state.DidSwapBuffersComplete(); | |
| 2008 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | |
| 2009 } | 1515 } |
| 2010 | 1516 |
| 2011 TEST(SchedulerStateMachineTest, ReportIfNotDrawing) { | 1517 TEST(SchedulerStateMachineTest, ReportIfNotDrawing) { |
| 2012 SchedulerSettings default_scheduler_settings; | 1518 SchedulerSettings default_scheduler_settings; |
| 2013 StateMachine state(default_scheduler_settings); | 1519 StateMachine state(default_scheduler_settings); |
| 2014 state.SetCanStart(); | 1520 state.SetCanStart(); |
| 2015 state.UpdateState(state.NextAction()); | 1521 state.UpdateState(state.NextAction()); |
| 2016 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); | 1522 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); |
| 2017 | 1523 |
| 2018 state.SetCanDraw(true); | 1524 state.SetCanDraw(true); |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2170 state.SetNeedsAnimate(); | 1676 state.SetNeedsAnimate(); |
| 2171 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | 1677 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 2172 | 1678 |
| 2173 state.OnBeginImplFrameDeadline(); | 1679 state.OnBeginImplFrameDeadline(); |
| 2174 EXPECT_ACTION_UPDATE_STATE( | 1680 EXPECT_ACTION_UPDATE_STATE( |
| 2175 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); | 1681 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); |
| 2176 } | 1682 } |
| 2177 | 1683 |
| 2178 } // namespace | 1684 } // namespace |
| 2179 } // namespace cc | 1685 } // namespace cc |
| OLD | NEW |