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

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: 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
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 1572 matching lines...) Expand 10 before | Expand all | Expand 10 after
1583 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client_); 1583 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client_);
1584 1584
1585 client_->Reset(); 1585 client_->Reset();
1586 EXPECT_SCOPED(AdvanceFrame()); 1586 EXPECT_SCOPED(AdvanceFrame());
1587 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); 1587 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2);
1588 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); 1588 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2);
1589 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); 1589 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending());
1590 1590
1591 client_->Reset(); 1591 client_->Reset();
1592 scheduler_->DidLoseOutputSurface(); 1592 scheduler_->DidLoseOutputSurface();
1593 // Do nothing when impl frame is in deadine pending state. 1593 // SetNeedsBeginFrames(false) is not called until the end of the frame.
1594 EXPECT_ACTION("SetNeedsBeginFrames(false)", client_, 0, 2); 1594 EXPECT_NO_ACTION(client_);
1595 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 1, 2);
1596 1595
1597 client_->Reset(); 1596 client_->Reset();
1598 scheduler_->NotifyBeginMainFrameStarted(); 1597 scheduler_->NotifyBeginMainFrameStarted();
1599 scheduler_->NotifyReadyToCommit(); 1598 scheduler_->NotifyReadyToCommit();
1600 EXPECT_ACTION("ScheduledActionCommit", client_, 0, 1); 1599 EXPECT_ACTION("ScheduledActionCommit", client_, 0, 1);
1601 1600
1602 client_->Reset(); 1601 client_->Reset();
1603 task_runner().RunPendingTasks(); // Run posted deadline. 1602 task_runner().RunTasksWhile(client_->ImplFrameDeadlinePending(true));
1604 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client_); 1603 EXPECT_ACTION("ScheduledActionBeginOutputSurfaceCreation", client_, 0, 3);
1604 EXPECT_ACTION("SetNeedsBeginFrames(false)", client_, 1, 3);
1605 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 2, 3);
1605 } 1606 }
1606 1607
1607 void SchedulerTest::DidLoseOutputSurfaceAfterBeginFrameStartedWithHighLatency( 1608 void SchedulerTest::DidLoseOutputSurfaceAfterBeginFrameStartedWithHighLatency(
1608 bool impl_side_painting) { 1609 bool impl_side_painting) {
1609 scheduler_settings_.impl_side_painting = impl_side_painting; 1610 scheduler_settings_.impl_side_painting = impl_side_painting;
1610 scheduler_settings_.use_external_begin_frame_source = true; 1611 scheduler_settings_.use_external_begin_frame_source = true;
1611 SetUpScheduler(true); 1612 SetUpScheduler(true);
1612 1613
1613 // SetNeedsCommit should begin the frame. 1614 // SetNeedsCommit should begin the frame.
1614 scheduler_->SetNeedsCommit(); 1615 scheduler_->SetNeedsCommit();
1615 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client_); 1616 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client_);
1616 1617
1617 client_->Reset(); 1618 client_->Reset();
1618 EXPECT_SCOPED(AdvanceFrame()); 1619 EXPECT_SCOPED(AdvanceFrame());
1619 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); 1620 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2);
1620 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); 1621 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2);
1621 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); 1622 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending());
1622 1623
1623 client_->Reset(); 1624 client_->Reset();
1624 scheduler_->DidLoseOutputSurface(); 1625 scheduler_->DidLoseOutputSurface();
1625 // Do nothing when impl frame is in deadine pending state. 1626 // Do nothing when impl frame is in deadine pending state.
1626 EXPECT_ACTION("SetNeedsBeginFrames(false)", client_, 0, 2); 1627 EXPECT_NO_ACTION(client_);
1627 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 1, 2);
1628 1628
1629 client_->Reset(); 1629 client_->Reset();
1630 // Run posted deadline. 1630 // Run posted deadline.
1631 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); 1631 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending());
1632 task_runner().RunTasksWhile(client_->ImplFrameDeadlinePending(true)); 1632 task_runner().RunTasksWhile(client_->ImplFrameDeadlinePending(true));
1633 // OnBeginImplFrameDeadline didn't schedule any actions because main frame is 1633 // OnBeginImplFrameDeadline didn't schedule output surface creation because
1634 // not yet completed. 1634 // main frame is not yet completed.
1635 EXPECT_NO_ACTION(client_); 1635 EXPECT_ACTION("SetNeedsBeginFrames(false)", client_, 0, 2);
1636 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 1, 2);
1636 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); 1637 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending());
1637 1638
1638 // BeginImplFrame is not started. 1639 // BeginImplFrame is not started.
1640 client_->Reset();
1639 task_runner().RunUntilTime(now_src()->Now() + 1641 task_runner().RunUntilTime(now_src()->Now() +
1640 base::TimeDelta::FromMilliseconds(10)); 1642 base::TimeDelta::FromMilliseconds(10));
1641 EXPECT_NO_ACTION(client_); 1643 EXPECT_NO_ACTION(client_);
1642 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); 1644 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending());
1643 1645
1644 client_->Reset(); 1646 client_->Reset();
1645 scheduler_->NotifyBeginMainFrameStarted(); 1647 scheduler_->NotifyBeginMainFrameStarted();
1646 scheduler_->NotifyReadyToCommit(); 1648 scheduler_->NotifyReadyToCommit();
1647 if (impl_side_painting) { 1649 if (impl_side_painting) {
1648 EXPECT_ACTION("ScheduledActionCommit", client_, 0, 3); 1650 EXPECT_ACTION("ScheduledActionCommit", client_, 0, 3);
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
1682 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); 1684 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2);
1683 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); 1685 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending());
1684 1686
1685 client_->Reset(); 1687 client_->Reset();
1686 scheduler_->NotifyBeginMainFrameStarted(); 1688 scheduler_->NotifyBeginMainFrameStarted();
1687 scheduler_->NotifyReadyToCommit(); 1689 scheduler_->NotifyReadyToCommit();
1688 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_); 1690 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_);
1689 1691
1690 client_->Reset(); 1692 client_->Reset();
1691 scheduler_->DidLoseOutputSurface(); 1693 scheduler_->DidLoseOutputSurface();
1694 // SetNeedsBeginFrames(false) is not called until the end of the frame.
1692 if (impl_side_painting) { 1695 if (impl_side_painting) {
1693 // Sync tree should be forced to activate. 1696 // Sync tree should be forced to activate.
1694 EXPECT_ACTION("ScheduledActionActivateSyncTree", client_, 0, 3); 1697 EXPECT_SINGLE_ACTION("ScheduledActionActivateSyncTree", client_);
1695 EXPECT_ACTION("SetNeedsBeginFrames(false)", client_, 1, 3);
1696 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 2, 3);
1697 } else { 1698 } else {
1698 EXPECT_ACTION("SetNeedsBeginFrames(false)", client_, 0, 2); 1699 EXPECT_NO_ACTION(client_);
1699 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 1, 2);
1700 } 1700 }
1701 1701
1702 client_->Reset(); 1702 client_->Reset();
1703 task_runner().RunPendingTasks(); // Run posted deadline. 1703 task_runner().RunTasksWhile(client_->ImplFrameDeadlinePending(true));
1704 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client_); 1704 EXPECT_ACTION("ScheduledActionBeginOutputSurfaceCreation", client_, 0, 3);
1705 EXPECT_ACTION("SetNeedsBeginFrames(false)", client_, 1, 3);
1706 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 2, 3);
1705 } 1707 }
1706 1708
1707 TEST_F(SchedulerTest, DidLoseOutputSurfaceAfterReadyToCommit) { 1709 TEST_F(SchedulerTest, DidLoseOutputSurfaceAfterReadyToCommit) {
1708 DidLoseOutputSurfaceAfterReadyToCommit(false); 1710 DidLoseOutputSurfaceAfterReadyToCommit(false);
1709 } 1711 }
1710 1712
1711 TEST_F(SchedulerTest, DidLoseOutputSurfaceAfterReadyToCommitWithImplPainting) { 1713 TEST_F(SchedulerTest, DidLoseOutputSurfaceAfterReadyToCommitWithImplPainting) {
1712 DidLoseOutputSurfaceAfterReadyToCommit(true); 1714 DidLoseOutputSurfaceAfterReadyToCommit(true);
1713 } 1715 }
1714 1716
1715 TEST_F(SchedulerTest, DidLoseOutputSurfaceAfterSetNeedsPrepareTiles) { 1717 TEST_F(SchedulerTest, DidLoseOutputSurfaceAfterSetNeedsPrepareTiles) {
1716 scheduler_settings_.use_external_begin_frame_source = true; 1718 scheduler_settings_.use_external_begin_frame_source = true;
1717 SetUpScheduler(true); 1719 SetUpScheduler(true);
1718 1720
1719 scheduler_->SetNeedsPrepareTiles(); 1721 scheduler_->SetNeedsPrepareTiles();
1720 scheduler_->SetNeedsRedraw(); 1722 scheduler_->SetNeedsRedraw();
1721 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client_); 1723 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client_);
1722 1724
1723 client_->Reset(); 1725 client_->Reset();
1724 EXPECT_SCOPED(AdvanceFrame()); 1726 EXPECT_SCOPED(AdvanceFrame());
1725 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); 1727 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2);
1726 EXPECT_ACTION("ScheduledActionAnimate", client_, 1, 2); 1728 EXPECT_ACTION("ScheduledActionAnimate", client_, 1, 2);
1727 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); 1729 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending());
1728 1730
1729 client_->Reset(); 1731 client_->Reset();
1730 scheduler_->DidLoseOutputSurface(); 1732 scheduler_->DidLoseOutputSurface();
1731 EXPECT_ACTION("SetNeedsBeginFrames(false)", client_, 0, 2); 1733 // SetNeedsBeginFrames(false) is not called until the end of the frame.
1732 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 1, 2); 1734 EXPECT_NO_ACTION(client_);
1733 1735
1734 client_->Reset(); 1736 client_->Reset();
1735 task_runner().RunPendingTasks(); // Run posted deadline. 1737 task_runner().RunTasksWhile(client_->ImplFrameDeadlinePending(true));
1736 EXPECT_ACTION("ScheduledActionPrepareTiles", client_, 0, 2); 1738 EXPECT_ACTION("ScheduledActionPrepareTiles", client_, 0, 4);
1737 EXPECT_ACTION("ScheduledActionBeginOutputSurfaceCreation", client_, 1, 2); 1739 EXPECT_ACTION("ScheduledActionBeginOutputSurfaceCreation", client_, 1, 4);
1740 EXPECT_ACTION("SetNeedsBeginFrames(false)", client_, 2, 4);
1741 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 3, 4);
1738 } 1742 }
1739 1743
1740 TEST_F(SchedulerTest, 1744 TEST_F(SchedulerTest, DidLoseOutputSurfaceWithSyntheticBeginFrameSource) {
1741 StopBeginFrameAfterDidLoseOutputSurfaceWithSyntheticBeginFrameSource) {
1742 SetUpScheduler(true); 1745 SetUpScheduler(true);
1743 1746
1744 // SetNeedsCommit should begin the frame on the next BeginImplFrame. 1747 // SetNeedsCommit should begin the frame on the next BeginImplFrame.
1745 EXPECT_FALSE(scheduler_->frame_source().NeedsBeginFrames()); 1748 EXPECT_FALSE(scheduler_->frame_source().NeedsBeginFrames());
1746 scheduler_->SetNeedsCommit(); 1749 scheduler_->SetNeedsCommit();
1747 EXPECT_TRUE(scheduler_->frame_source().NeedsBeginFrames()); 1750 EXPECT_TRUE(scheduler_->frame_source().NeedsBeginFrames());
1748 1751
1749 client_->Reset(); 1752 client_->Reset();
1750 task_runner().RunPendingTasks(); // Run posted Tick. 1753 AdvanceFrame();
1751 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); 1754 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2);
1752 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); 1755 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2);
1753 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); 1756 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending());
1754 EXPECT_TRUE(scheduler_->frame_source().NeedsBeginFrames()); 1757 EXPECT_TRUE(scheduler_->frame_source().NeedsBeginFrames());
1755 1758
1756 // NotifyReadyToCommit should trigger the commit. 1759 // NotifyReadyToCommit should trigger the commit.
1757 client_->Reset(); 1760 client_->Reset();
1758 scheduler_->NotifyBeginMainFrameStarted(); 1761 scheduler_->NotifyBeginMainFrameStarted();
1759 scheduler_->NotifyReadyToCommit(); 1762 scheduler_->NotifyReadyToCommit();
1760 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_); 1763 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_);
1761 EXPECT_TRUE(scheduler_->frame_source().NeedsBeginFrames()); 1764 EXPECT_TRUE(scheduler_->frame_source().NeedsBeginFrames());
1762 1765
1763 client_->Reset(); 1766 client_->Reset();
1764 scheduler_->DidLoseOutputSurface(); 1767 scheduler_->DidLoseOutputSurface();
1765 EXPECT_SINGLE_ACTION("SendBeginMainFrameNotExpectedSoon", client_); 1768 // SetNeedsBeginFrames(false) is not called until the end of the frame.
1766 EXPECT_FALSE(scheduler_->frame_source().NeedsBeginFrames()); 1769 EXPECT_NO_ACTION(client_);
1770 EXPECT_TRUE(scheduler_->frame_source().NeedsBeginFrames());
1767 1771
1768 client_->Reset(); 1772 client_->Reset();
1769 task_runner().RunPendingTasks(); // Run posted deadline. 1773 task_runner().RunTasksWhile(client_->ImplFrameDeadlinePending(true));
1770 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client_); 1774 EXPECT_ACTION("ScheduledActionBeginOutputSurfaceCreation", client_, 0, 2);
1775 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 1, 2);
1771 EXPECT_FALSE(scheduler_->frame_source().NeedsBeginFrames()); 1776 EXPECT_FALSE(scheduler_->frame_source().NeedsBeginFrames());
1772 } 1777 }
1773 1778
1779 TEST_F(SchedulerTest, DidLoseOutputSurfaceWhenIdle) {
1780 scheduler_settings_.use_external_begin_frame_source = true;
1781 SetUpScheduler(true);
1782
1783 // SetNeedsCommit should begin the frame.
1784 scheduler_->SetNeedsCommit();
1785 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client_);
1786
1787 client_->Reset();
1788 EXPECT_SCOPED(AdvanceFrame());
1789 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2);
1790 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2);
1791 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending());
1792
1793 client_->Reset();
1794 scheduler_->NotifyBeginMainFrameStarted();
1795 scheduler_->NotifyReadyToCommit();
1796 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_);
1797
1798 client_->Reset();
1799 task_runner().RunTasksWhile(client_->ImplFrameDeadlinePending(true));
1800 EXPECT_ACTION("ScheduledActionAnimate", client_, 0, 2);
1801 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 1, 2);
1802
1803 // Idle time between BeginFrames.
1804 client_->Reset();
1805 scheduler_->DidLoseOutputSurface();
1806 EXPECT_ACTION("ScheduledActionBeginOutputSurfaceCreation", client_, 0, 3);
1807 EXPECT_ACTION("SetNeedsBeginFrames(false)", client_, 1, 3);
1808 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 2, 3);
1809 }
1810
1774 TEST_F(SchedulerTest, ScheduledActionActivateAfterBecomingInvisible) { 1811 TEST_F(SchedulerTest, ScheduledActionActivateAfterBecomingInvisible) {
1775 scheduler_settings_.impl_side_painting = true; 1812 scheduler_settings_.impl_side_painting = true;
1776 scheduler_settings_.use_external_begin_frame_source = true; 1813 scheduler_settings_.use_external_begin_frame_source = true;
1777 SetUpScheduler(true); 1814 SetUpScheduler(true);
1778 1815
1779 // SetNeedsCommit should begin the frame. 1816 // SetNeedsCommit should begin the frame.
1780 scheduler_->SetNeedsCommit(); 1817 scheduler_->SetNeedsCommit();
1781 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client_); 1818 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client_);
1782 1819
1783 client_->Reset(); 1820 client_->Reset();
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after
2070 client_->Reset(); 2107 client_->Reset();
2071 2108
2072 task_runner().RunPendingTasks(); // Run posted deadline. 2109 task_runner().RunPendingTasks(); // Run posted deadline.
2073 EXPECT_ACTION("SetNeedsBeginFrames(false)", client_, 0, 2); 2110 EXPECT_ACTION("SetNeedsBeginFrames(false)", client_, 0, 2);
2074 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 1, 2); 2111 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 1, 2);
2075 client_->Reset(); 2112 client_->Reset();
2076 } 2113 }
2077 2114
2078 } // namespace 2115 } // namespace
2079 } // namespace cc 2116 } // namespace cc
OLDNEW
« cc/scheduler/scheduler_state_machine.cc ('K') | « cc/scheduler/scheduler_state_machine.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698