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

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

Issue 987563002: cc: Simplify SetNeedsBeginFrames code in scheduler. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@remove_retro_frame
Patch Set: Address comments. Created 5 years, 9 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
« no previous file with comments | « cc/scheduler/scheduler_state_machine.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2011 The Chromium Authors. All rights reserved. 1 // Copyright 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "cc/scheduler/scheduler.h" 5 #include "cc/scheduler/scheduler.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 1547 matching lines...) Expand 10 before | Expand all | Expand 10 after
1558 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client_); 1558 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client_);
1559 1559
1560 client_->Reset(); 1560 client_->Reset();
1561 EXPECT_SCOPED(AdvanceFrame()); 1561 EXPECT_SCOPED(AdvanceFrame());
1562 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); 1562 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2);
1563 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); 1563 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2);
1564 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); 1564 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending());
1565 1565
1566 client_->Reset(); 1566 client_->Reset();
1567 scheduler_->DidLoseOutputSurface(); 1567 scheduler_->DidLoseOutputSurface();
1568 // Do nothing when impl frame is in deadine pending state. 1568 // SetNeedsBeginFrames(false) is not called until the end of the frame.
brianderson 2015/03/06 01:34:36 It's a little concerning that we won't stop reques
sunnyps 2015/03/06 01:38:50 We do have the ability to ignore BeginFrames in th
1569 EXPECT_ACTION("SetNeedsBeginFrames(false)", client_, 0, 2); 1569 EXPECT_NO_ACTION(client_);
1570 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 1, 2);
1571 1570
1572 client_->Reset(); 1571 client_->Reset();
1573 scheduler_->NotifyBeginMainFrameStarted(); 1572 scheduler_->NotifyBeginMainFrameStarted();
1574 scheduler_->NotifyReadyToCommit(); 1573 scheduler_->NotifyReadyToCommit();
1575 EXPECT_ACTION("ScheduledActionCommit", client_, 0, 1); 1574 EXPECT_ACTION("ScheduledActionCommit", client_, 0, 1);
1576 1575
1577 client_->Reset(); 1576 client_->Reset();
1578 task_runner().RunPendingTasks(); // Run posted deadline. 1577 task_runner().RunTasksWhile(client_->ImplFrameDeadlinePending(true));
1579 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client_); 1578 EXPECT_ACTION("ScheduledActionBeginOutputSurfaceCreation", client_, 0, 3);
1579 EXPECT_ACTION("SetNeedsBeginFrames(false)", client_, 1, 3);
brianderson 2015/03/06 01:34:36 I was going to say to try and change the code so S
sunnyps 2015/03/06 01:38:50 I would've liked that too - it's difficult to achi
1580 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 2, 3);
1580 } 1581 }
1581 1582
1582 void SchedulerTest::DidLoseOutputSurfaceAfterBeginFrameStartedWithHighLatency( 1583 void SchedulerTest::DidLoseOutputSurfaceAfterBeginFrameStartedWithHighLatency(
1583 bool impl_side_painting) { 1584 bool impl_side_painting) {
1584 scheduler_settings_.impl_side_painting = impl_side_painting; 1585 scheduler_settings_.impl_side_painting = impl_side_painting;
1585 scheduler_settings_.use_external_begin_frame_source = true; 1586 scheduler_settings_.use_external_begin_frame_source = true;
1586 SetUpScheduler(true); 1587 SetUpScheduler(true);
1587 1588
1588 // SetNeedsCommit should begin the frame. 1589 // SetNeedsCommit should begin the frame.
1589 scheduler_->SetNeedsCommit(); 1590 scheduler_->SetNeedsCommit();
1590 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client_); 1591 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client_);
1591 1592
1592 client_->Reset(); 1593 client_->Reset();
1593 EXPECT_SCOPED(AdvanceFrame()); 1594 EXPECT_SCOPED(AdvanceFrame());
1594 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); 1595 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2);
1595 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); 1596 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2);
1596 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); 1597 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending());
1597 1598
1598 client_->Reset(); 1599 client_->Reset();
1599 scheduler_->DidLoseOutputSurface(); 1600 scheduler_->DidLoseOutputSurface();
1600 // Do nothing when impl frame is in deadine pending state. 1601 // Do nothing when impl frame is in deadine pending state.
1601 EXPECT_ACTION("SetNeedsBeginFrames(false)", client_, 0, 2); 1602 EXPECT_NO_ACTION(client_);
1602 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 1, 2);
1603 1603
1604 client_->Reset(); 1604 client_->Reset();
1605 // Run posted deadline. 1605 // Run posted deadline.
1606 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); 1606 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending());
1607 task_runner().RunTasksWhile(client_->ImplFrameDeadlinePending(true)); 1607 task_runner().RunTasksWhile(client_->ImplFrameDeadlinePending(true));
1608 // OnBeginImplFrameDeadline didn't schedule any actions because main frame is 1608 // OnBeginImplFrameDeadline didn't schedule output surface creation because
1609 // not yet completed. 1609 // main frame is not yet completed.
1610 EXPECT_NO_ACTION(client_); 1610 EXPECT_ACTION("SetNeedsBeginFrames(false)", client_, 0, 2);
1611 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 1, 2);
1611 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); 1612 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending());
1612 1613
1613 // BeginImplFrame is not started. 1614 // BeginImplFrame is not started.
1615 client_->Reset();
1614 task_runner().RunUntilTime(now_src()->Now() + 1616 task_runner().RunUntilTime(now_src()->Now() +
1615 base::TimeDelta::FromMilliseconds(10)); 1617 base::TimeDelta::FromMilliseconds(10));
1616 EXPECT_NO_ACTION(client_); 1618 EXPECT_NO_ACTION(client_);
1617 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); 1619 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending());
1618 1620
1619 client_->Reset(); 1621 client_->Reset();
1620 scheduler_->NotifyBeginMainFrameStarted(); 1622 scheduler_->NotifyBeginMainFrameStarted();
1621 scheduler_->NotifyReadyToCommit(); 1623 scheduler_->NotifyReadyToCommit();
1622 if (impl_side_painting) { 1624 if (impl_side_painting) {
1623 EXPECT_ACTION("ScheduledActionCommit", client_, 0, 3); 1625 EXPECT_ACTION("ScheduledActionCommit", client_, 0, 3);
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
1657 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); 1659 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2);
1658 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); 1660 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending());
1659 1661
1660 client_->Reset(); 1662 client_->Reset();
1661 scheduler_->NotifyBeginMainFrameStarted(); 1663 scheduler_->NotifyBeginMainFrameStarted();
1662 scheduler_->NotifyReadyToCommit(); 1664 scheduler_->NotifyReadyToCommit();
1663 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_); 1665 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_);
1664 1666
1665 client_->Reset(); 1667 client_->Reset();
1666 scheduler_->DidLoseOutputSurface(); 1668 scheduler_->DidLoseOutputSurface();
1669 // SetNeedsBeginFrames(false) is not called until the end of the frame.
1667 if (impl_side_painting) { 1670 if (impl_side_painting) {
1668 // Sync tree should be forced to activate. 1671 // Sync tree should be forced to activate.
1669 EXPECT_ACTION("ScheduledActionActivateSyncTree", client_, 0, 3); 1672 EXPECT_SINGLE_ACTION("ScheduledActionActivateSyncTree", client_);
1670 EXPECT_ACTION("SetNeedsBeginFrames(false)", client_, 1, 3);
1671 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 2, 3);
1672 } else { 1673 } else {
1673 EXPECT_ACTION("SetNeedsBeginFrames(false)", client_, 0, 2); 1674 EXPECT_NO_ACTION(client_);
1674 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 1, 2);
1675 } 1675 }
1676 1676
1677 client_->Reset(); 1677 client_->Reset();
1678 task_runner().RunPendingTasks(); // Run posted deadline. 1678 task_runner().RunTasksWhile(client_->ImplFrameDeadlinePending(true));
1679 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client_); 1679 EXPECT_ACTION("ScheduledActionBeginOutputSurfaceCreation", client_, 0, 3);
1680 EXPECT_ACTION("SetNeedsBeginFrames(false)", client_, 1, 3);
1681 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 2, 3);
1680 } 1682 }
1681 1683
1682 TEST_F(SchedulerTest, DidLoseOutputSurfaceAfterReadyToCommit) { 1684 TEST_F(SchedulerTest, DidLoseOutputSurfaceAfterReadyToCommit) {
1683 DidLoseOutputSurfaceAfterReadyToCommit(false); 1685 DidLoseOutputSurfaceAfterReadyToCommit(false);
1684 } 1686 }
1685 1687
1686 TEST_F(SchedulerTest, DidLoseOutputSurfaceAfterReadyToCommitWithImplPainting) { 1688 TEST_F(SchedulerTest, DidLoseOutputSurfaceAfterReadyToCommitWithImplPainting) {
1687 DidLoseOutputSurfaceAfterReadyToCommit(true); 1689 DidLoseOutputSurfaceAfterReadyToCommit(true);
1688 } 1690 }
1689 1691
1690 TEST_F(SchedulerTest, DidLoseOutputSurfaceAfterSetNeedsPrepareTiles) { 1692 TEST_F(SchedulerTest, DidLoseOutputSurfaceAfterSetNeedsPrepareTiles) {
1691 scheduler_settings_.use_external_begin_frame_source = true; 1693 scheduler_settings_.use_external_begin_frame_source = true;
1692 SetUpScheduler(true); 1694 SetUpScheduler(true);
1693 1695
1694 scheduler_->SetNeedsPrepareTiles(); 1696 scheduler_->SetNeedsPrepareTiles();
1695 scheduler_->SetNeedsRedraw(); 1697 scheduler_->SetNeedsRedraw();
1696 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client_); 1698 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client_);
1697 1699
1698 client_->Reset(); 1700 client_->Reset();
1699 EXPECT_SCOPED(AdvanceFrame()); 1701 EXPECT_SCOPED(AdvanceFrame());
1700 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); 1702 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2);
1701 EXPECT_ACTION("ScheduledActionAnimate", client_, 1, 2); 1703 EXPECT_ACTION("ScheduledActionAnimate", client_, 1, 2);
1702 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); 1704 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending());
1703 1705
1704 client_->Reset(); 1706 client_->Reset();
1705 scheduler_->DidLoseOutputSurface(); 1707 scheduler_->DidLoseOutputSurface();
1706 EXPECT_ACTION("SetNeedsBeginFrames(false)", client_, 0, 2); 1708 // SetNeedsBeginFrames(false) is not called until the end of the frame.
1707 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 1, 2); 1709 EXPECT_NO_ACTION(client_);
1708 1710
1709 client_->Reset(); 1711 client_->Reset();
1710 task_runner().RunPendingTasks(); // Run posted deadline. 1712 task_runner().RunTasksWhile(client_->ImplFrameDeadlinePending(true));
1711 EXPECT_ACTION("ScheduledActionPrepareTiles", client_, 0, 2); 1713 EXPECT_ACTION("ScheduledActionPrepareTiles", client_, 0, 4);
1712 EXPECT_ACTION("ScheduledActionBeginOutputSurfaceCreation", client_, 1, 2); 1714 EXPECT_ACTION("ScheduledActionBeginOutputSurfaceCreation", client_, 1, 4);
1715 EXPECT_ACTION("SetNeedsBeginFrames(false)", client_, 2, 4);
1716 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 3, 4);
1713 } 1717 }
1714 1718
1715 TEST_F(SchedulerTest, 1719 TEST_F(SchedulerTest, DidLoseOutputSurfaceWithSyntheticBeginFrameSource) {
1716 StopBeginFrameAfterDidLoseOutputSurfaceWithSyntheticBeginFrameSource) {
1717 SetUpScheduler(true); 1720 SetUpScheduler(true);
1718 1721
1719 // SetNeedsCommit should begin the frame on the next BeginImplFrame. 1722 // SetNeedsCommit should begin the frame on the next BeginImplFrame.
1720 EXPECT_FALSE(scheduler_->frame_source().NeedsBeginFrames()); 1723 EXPECT_FALSE(scheduler_->frame_source().NeedsBeginFrames());
1721 scheduler_->SetNeedsCommit(); 1724 scheduler_->SetNeedsCommit();
1722 EXPECT_TRUE(scheduler_->frame_source().NeedsBeginFrames()); 1725 EXPECT_TRUE(scheduler_->frame_source().NeedsBeginFrames());
1723 1726
1724 client_->Reset(); 1727 client_->Reset();
1725 task_runner().RunPendingTasks(); // Run posted Tick. 1728 AdvanceFrame();
1726 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); 1729 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2);
1727 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); 1730 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2);
1728 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); 1731 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending());
1729 EXPECT_TRUE(scheduler_->frame_source().NeedsBeginFrames()); 1732 EXPECT_TRUE(scheduler_->frame_source().NeedsBeginFrames());
1730 1733
1731 // NotifyReadyToCommit should trigger the commit. 1734 // NotifyReadyToCommit should trigger the commit.
1732 client_->Reset(); 1735 client_->Reset();
1733 scheduler_->NotifyBeginMainFrameStarted(); 1736 scheduler_->NotifyBeginMainFrameStarted();
1734 scheduler_->NotifyReadyToCommit(); 1737 scheduler_->NotifyReadyToCommit();
1735 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_); 1738 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_);
1736 EXPECT_TRUE(scheduler_->frame_source().NeedsBeginFrames()); 1739 EXPECT_TRUE(scheduler_->frame_source().NeedsBeginFrames());
1737 1740
1738 client_->Reset(); 1741 client_->Reset();
1739 scheduler_->DidLoseOutputSurface(); 1742 scheduler_->DidLoseOutputSurface();
1740 EXPECT_SINGLE_ACTION("SendBeginMainFrameNotExpectedSoon", client_); 1743 // SetNeedsBeginFrames(false) is not called until the end of the frame.
1741 EXPECT_FALSE(scheduler_->frame_source().NeedsBeginFrames()); 1744 EXPECT_NO_ACTION(client_);
1745 EXPECT_TRUE(scheduler_->frame_source().NeedsBeginFrames());
1742 1746
1743 client_->Reset(); 1747 client_->Reset();
1744 task_runner().RunPendingTasks(); // Run posted deadline. 1748 task_runner().RunTasksWhile(client_->ImplFrameDeadlinePending(true));
1745 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client_); 1749 EXPECT_ACTION("ScheduledActionBeginOutputSurfaceCreation", client_, 0, 2);
1750 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 1, 2);
1746 EXPECT_FALSE(scheduler_->frame_source().NeedsBeginFrames()); 1751 EXPECT_FALSE(scheduler_->frame_source().NeedsBeginFrames());
1747 } 1752 }
1748 1753
1754 TEST_F(SchedulerTest, DidLoseOutputSurfaceWhenIdle) {
1755 scheduler_settings_.use_external_begin_frame_source = true;
1756 SetUpScheduler(true);
1757
1758 // SetNeedsCommit should begin the frame.
1759 scheduler_->SetNeedsCommit();
1760 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client_);
1761
1762 client_->Reset();
1763 EXPECT_SCOPED(AdvanceFrame());
1764 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2);
1765 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2);
1766 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending());
1767
1768 client_->Reset();
1769 scheduler_->NotifyBeginMainFrameStarted();
1770 scheduler_->NotifyReadyToCommit();
1771 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_);
1772
1773 client_->Reset();
1774 task_runner().RunTasksWhile(client_->ImplFrameDeadlinePending(true));
1775 EXPECT_ACTION("ScheduledActionAnimate", client_, 0, 2);
1776 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 1, 2);
1777
1778 // Idle time between BeginFrames.
1779 client_->Reset();
1780 scheduler_->DidLoseOutputSurface();
1781 EXPECT_ACTION("ScheduledActionBeginOutputSurfaceCreation", client_, 0, 3);
1782 EXPECT_ACTION("SetNeedsBeginFrames(false)", client_, 1, 3);
1783 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 2, 3);
1784 }
1785
1749 TEST_F(SchedulerTest, ScheduledActionActivateAfterBecomingInvisible) { 1786 TEST_F(SchedulerTest, ScheduledActionActivateAfterBecomingInvisible) {
1750 scheduler_settings_.impl_side_painting = true; 1787 scheduler_settings_.impl_side_painting = true;
1751 scheduler_settings_.use_external_begin_frame_source = true; 1788 scheduler_settings_.use_external_begin_frame_source = true;
1752 SetUpScheduler(true); 1789 SetUpScheduler(true);
1753 1790
1754 // SetNeedsCommit should begin the frame. 1791 // SetNeedsCommit should begin the frame.
1755 scheduler_->SetNeedsCommit(); 1792 scheduler_->SetNeedsCommit();
1756 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client_); 1793 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client_);
1757 1794
1758 client_->Reset(); 1795 client_->Reset();
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
1920 client_->Reset(); 1957 client_->Reset();
1921 1958
1922 task_runner().RunPendingTasks(); // Run posted deadline. 1959 task_runner().RunPendingTasks(); // Run posted deadline.
1923 EXPECT_ACTION("SetNeedsBeginFrames(false)", client_, 0, 2); 1960 EXPECT_ACTION("SetNeedsBeginFrames(false)", client_, 0, 2);
1924 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 1, 2); 1961 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 1, 2);
1925 client_->Reset(); 1962 client_->Reset();
1926 } 1963 }
1927 1964
1928 } // namespace 1965 } // namespace
1929 } // namespace cc 1966 } // namespace cc
OLDNEW
« no previous file with comments | « cc/scheduler/scheduler_state_machine.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698