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

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

Issue 786123002: Update from https://crrev.com/307330 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 6 years 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') | cc/scheduler/scheduler_unittest.cc » ('j') | 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_state_machine.h" 5 #include "cc/scheduler/scheduler_state_machine.h"
6 6
7 #include "base/debug/trace_event.h" 7 #include "base/debug/trace_event.h"
8 #include "cc/scheduler/scheduler.h" 8 #include "cc/scheduler/scheduler.h"
9 #include "cc/test/begin_frame_args_test.h" 9 #include "cc/test/begin_frame_args_test.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 bool CanDraw() const { return can_draw_; } 96 bool CanDraw() const { return can_draw_; }
97 bool Visible() const { return visible_; } 97 bool Visible() const { return visible_; }
98 98
99 bool PendingActivationsShouldBeForced() const { 99 bool PendingActivationsShouldBeForced() const {
100 return SchedulerStateMachine::PendingActivationsShouldBeForced(); 100 return SchedulerStateMachine::PendingActivationsShouldBeForced();
101 } 101 }
102 102
103 void SetHasPendingTree(bool has_pending_tree) { 103 void SetHasPendingTree(bool has_pending_tree) {
104 has_pending_tree_ = has_pending_tree; 104 has_pending_tree_ = has_pending_tree;
105 } 105 }
106
107 using SchedulerStateMachine::ShouldTriggerBeginImplFrameDeadlineImmediately;
106 }; 108 };
107 109
108 TEST(SchedulerStateMachineTest, TestNextActionBeginsMainFrameIfNeeded) { 110 TEST(SchedulerStateMachineTest, TestNextActionBeginsMainFrameIfNeeded) {
109 SchedulerSettings default_scheduler_settings; 111 SchedulerSettings default_scheduler_settings;
110 112
111 // If no commit needed, do nothing. 113 // If no commit needed, do nothing.
112 { 114 {
113 StateMachine state(default_scheduler_settings); 115 StateMachine state(default_scheduler_settings);
114 state.SetCanStart(); 116 state.SetCanStart();
115 EXPECT_ACTION_UPDATE_STATE( 117 EXPECT_ACTION_UPDATE_STATE(
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 state.NotifyBeginMainFrameStarted(); 227 state.NotifyBeginMainFrameStarted();
226 state.NotifyReadyToCommit(); 228 state.NotifyReadyToCommit();
227 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 229 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
228 230
229 // Verify NotifyReadyToActivate unblocks activation, draw, and 231 // Verify NotifyReadyToActivate unblocks activation, draw, and
230 // commit in that order. 232 // commit in that order.
231 state.NotifyReadyToActivate(); 233 state.NotifyReadyToActivate();
232 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE); 234 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE);
233 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 235 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
234 236
235 EXPECT_TRUE(state.ShouldTriggerBeginImplFrameDeadlineEarly()); 237 EXPECT_TRUE(state.ShouldTriggerBeginImplFrameDeadlineImmediately());
236 state.OnBeginImplFrameDeadline(); 238 state.OnBeginImplFrameDeadline();
237 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE); 239 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
238 EXPECT_ACTION_UPDATE_STATE( 240 EXPECT_ACTION_UPDATE_STATE(
239 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 241 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
240 state.DidSwapBuffers(); 242 state.DidSwapBuffers();
241 state.DidSwapBuffersComplete(); 243 state.DidSwapBuffersComplete();
242 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 244 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
243 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 245 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
244 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState()); 246 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState());
245 } 247 }
(...skipping 1478 matching lines...) Expand 10 before | Expand all | Expand 10 after
1724 1726
1725 state.SetCanDraw(false); 1727 state.SetCanDraw(false);
1726 state.SetVisible(false); 1728 state.SetVisible(false);
1727 EXPECT_TRUE(state.PendingDrawsShouldBeAborted()); 1729 EXPECT_TRUE(state.PendingDrawsShouldBeAborted());
1728 1730
1729 state.SetCanDraw(true); 1731 state.SetCanDraw(true);
1730 state.SetVisible(true); 1732 state.SetVisible(true);
1731 EXPECT_FALSE(state.PendingDrawsShouldBeAborted()); 1733 EXPECT_FALSE(state.PendingDrawsShouldBeAborted());
1732 } 1734 }
1733 1735
1734 TEST(SchedulerStateMachineTest, TestTriggerDeadlineEarlyAfterAbortedCommit) { 1736 TEST(SchedulerStateMachineTest,
1737 TestTriggerDeadlineImmediatelyAfterAbortedCommit) {
1735 SchedulerSettings settings; 1738 SchedulerSettings settings;
1736 settings.impl_side_painting = true; 1739 settings.impl_side_painting = true;
1737 StateMachine state(settings); 1740 StateMachine state(settings);
1738 state.SetCanStart(); 1741 state.SetCanStart();
1739 state.UpdateState(state.NextAction()); 1742 state.UpdateState(state.NextAction());
1740 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 1743 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
1741 state.SetVisible(true); 1744 state.SetVisible(true);
1742 state.SetCanDraw(true); 1745 state.SetCanDraw(true);
1743 1746
1744 // This test mirrors what happens during the first frame of a scroll gesture. 1747 // This test mirrors what happens during the first frame of a scroll gesture.
(...skipping 10 matching lines...) Expand all
1755 EXPECT_ACTION_UPDATE_STATE( 1758 EXPECT_ACTION_UPDATE_STATE(
1756 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 1759 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
1757 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1760 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1758 1761
1759 // Since only the scroll offset changed, the main thread will abort the 1762 // Since only the scroll offset changed, the main thread will abort the
1760 // commit. 1763 // commit.
1761 state.BeginMainFrameAborted(true); 1764 state.BeginMainFrameAborted(true);
1762 1765
1763 // Since the commit was aborted, we should draw right away instead of waiting 1766 // Since the commit was aborted, we should draw right away instead of waiting
1764 // for the deadline. 1767 // for the deadline.
1765 EXPECT_TRUE(state.ShouldTriggerBeginImplFrameDeadlineEarly()); 1768 EXPECT_TRUE(state.ShouldTriggerBeginImplFrameDeadlineImmediately());
1766 } 1769 }
1767 1770
1768 void FinishPreviousCommitAndDrawWithoutExitingDeadline( 1771 void FinishPreviousCommitAndDrawWithoutExitingDeadline(
1769 StateMachine* state_ptr) { 1772 StateMachine* state_ptr) {
1770 // Gross, but allows us to use macros below. 1773 // Gross, but allows us to use macros below.
1771 StateMachine& state = *state_ptr; 1774 StateMachine& state = *state_ptr;
1772 1775
1773 state.NotifyBeginMainFrameStarted(); 1776 state.NotifyBeginMainFrameStarted();
1774 state.NotifyReadyToCommit(); 1777 state.NotifyReadyToCommit();
1775 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 1778 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
1776 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1779 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1777 state.NotifyReadyToActivate(); 1780 state.NotifyReadyToActivate();
1778 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE); 1781 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE);
1779 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1782 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1780 1783
1781 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE)); 1784 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE));
1782 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE); 1785 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
1783 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1786 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1784 1787
1785 EXPECT_TRUE(state.ShouldTriggerBeginImplFrameDeadlineEarly()); 1788 EXPECT_TRUE(state.ShouldTriggerBeginImplFrameDeadlineImmediately());
1786 state.OnBeginImplFrameDeadline(); 1789 state.OnBeginImplFrameDeadline();
1787 EXPECT_ACTION_UPDATE_STATE( 1790 EXPECT_ACTION_UPDATE_STATE(
1788 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 1791 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
1789 state.DidSwapBuffers(); 1792 state.DidSwapBuffers();
1790 } 1793 }
1791 1794
1792 TEST(SchedulerStateMachineTest, TestImplLatencyTakesPriority) { 1795 TEST(SchedulerStateMachineTest, TestImplLatencyTakesPriority) {
1793 SchedulerSettings settings; 1796 SchedulerSettings settings;
1794 settings.impl_side_painting = true; 1797 settings.impl_side_painting = true;
1795 StateMachine state(settings); 1798 StateMachine state(settings);
1796 state.SetCanStart(); 1799 state.SetCanStart();
1797 state.UpdateState(state.NextAction()); 1800 state.UpdateState(state.NextAction());
1798 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 1801 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
1799 state.SetVisible(true); 1802 state.SetVisible(true);
1800 state.SetCanDraw(true); 1803 state.SetCanDraw(true);
1801 1804
1802 // This test ensures that impl-draws are prioritized over main thread updates 1805 // This test ensures that impl-draws are prioritized over main thread updates
1803 // in prefer impl latency mode. 1806 // in prefer impl latency mode.
1804 state.SetNeedsRedraw(true); 1807 state.SetNeedsRedraw(true);
1805 state.SetNeedsCommit(); 1808 state.SetNeedsCommit();
1806 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE)); 1809 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE));
1807 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE); 1810 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
1808 EXPECT_ACTION_UPDATE_STATE( 1811 EXPECT_ACTION_UPDATE_STATE(
1809 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 1812 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
1810 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1813 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1811 1814
1812 // Verify the deadline is not triggered early until we enter 1815 // Verify the deadline is not triggered early until we enter
1813 // prefer impl latency mode. 1816 // prefer impl latency mode.
1814 EXPECT_FALSE(state.ShouldTriggerBeginImplFrameDeadlineEarly()); 1817 EXPECT_FALSE(state.ShouldTriggerBeginImplFrameDeadlineImmediately());
1815 state.SetImplLatencyTakesPriority(true); 1818 state.SetImplLatencyTakesPriority(true);
1816 EXPECT_TRUE(state.ShouldTriggerBeginImplFrameDeadlineEarly()); 1819 EXPECT_TRUE(state.ShouldTriggerBeginImplFrameDeadlineImmediately());
1817 1820
1818 // Trigger the deadline. 1821 // Trigger the deadline.
1819 state.OnBeginImplFrameDeadline(); 1822 state.OnBeginImplFrameDeadline();
1820 EXPECT_ACTION_UPDATE_STATE( 1823 EXPECT_ACTION_UPDATE_STATE(
1821 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 1824 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
1822 state.DidSwapBuffers(); 1825 state.DidSwapBuffers();
1823 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1826 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1824 state.DidSwapBuffersComplete(); 1827 state.DidSwapBuffersComplete();
1825 1828
1826 // Request a new commit and finish the previous one. 1829 // Request a new commit and finish the previous one.
1827 state.SetNeedsCommit(); 1830 state.SetNeedsCommit();
1828 FinishPreviousCommitAndDrawWithoutExitingDeadline(&state); 1831 FinishPreviousCommitAndDrawWithoutExitingDeadline(&state);
1829 EXPECT_ACTION_UPDATE_STATE( 1832 EXPECT_ACTION_UPDATE_STATE(
1830 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 1833 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
1831 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1834 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1832 state.DidSwapBuffersComplete(); 1835 state.DidSwapBuffersComplete();
1833 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1836 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1834 1837
1835 // Finish the previous commit and draw it. 1838 // Finish the previous commit and draw it.
1836 FinishPreviousCommitAndDrawWithoutExitingDeadline(&state); 1839 FinishPreviousCommitAndDrawWithoutExitingDeadline(&state);
1837 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1840 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1838 1841
1839 // Verify we do not send another BeginMainFrame if was are swap throttled 1842 // Verify we do not send another BeginMainFrame if was are swap throttled
1840 // and did not just swap. 1843 // and did not just swap.
1841 state.SetNeedsCommit(); 1844 state.SetNeedsCommit();
1842 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1845 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1843 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE)); 1846 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE));
1844 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1847 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1845 EXPECT_FALSE(state.ShouldTriggerBeginImplFrameDeadlineEarly()); 1848 EXPECT_FALSE(state.ShouldTriggerBeginImplFrameDeadlineImmediately());
1846 state.OnBeginImplFrameDeadline(); 1849 state.OnBeginImplFrameDeadline();
1847 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1850 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1848 } 1851 }
1849 1852
1850 TEST(SchedulerStateMachineTest, TestTriggerDeadlineEarlyOnLostOutputSurface) { 1853 TEST(SchedulerStateMachineTest,
1854 TestTriggerDeadlineImmediatelyOnLostOutputSurface) {
1851 SchedulerSettings default_scheduler_settings; 1855 SchedulerSettings default_scheduler_settings;
1852 StateMachine state(default_scheduler_settings); 1856 StateMachine state(default_scheduler_settings);
1853 state.SetCanStart(); 1857 state.SetCanStart();
1854 state.UpdateState(state.NextAction()); 1858 state.UpdateState(state.NextAction());
1855 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 1859 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
1856 state.SetVisible(true); 1860 state.SetVisible(true);
1857 state.SetCanDraw(true); 1861 state.SetCanDraw(true);
1858 1862
1859 state.SetNeedsCommit(); 1863 state.SetNeedsCommit();
1860 1864
1861 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE)); 1865 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE));
1862 EXPECT_ACTION_UPDATE_STATE( 1866 EXPECT_ACTION_UPDATE_STATE(
1863 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 1867 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
1864 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1868 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1865 EXPECT_FALSE(state.ShouldTriggerBeginImplFrameDeadlineEarly()); 1869 EXPECT_FALSE(state.ShouldTriggerBeginImplFrameDeadlineImmediately());
1866 1870
1867 state.DidLoseOutputSurface(); 1871 state.DidLoseOutputSurface();
1868 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1872 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1869 // The deadline should be triggered immediately when output surface is lost. 1873 // The deadline should be triggered immediately when output surface is lost.
1870 EXPECT_TRUE(state.ShouldTriggerBeginImplFrameDeadlineEarly()); 1874 EXPECT_TRUE(state.ShouldTriggerBeginImplFrameDeadlineImmediately());
1871 } 1875 }
1872 1876
1873 TEST(SchedulerStateMachineTest, TestSetNeedsAnimate) { 1877 TEST(SchedulerStateMachineTest, TestSetNeedsAnimate) {
1874 SchedulerSettings settings; 1878 SchedulerSettings settings;
1875 settings.impl_side_painting = true; 1879 settings.impl_side_painting = true;
1876 StateMachine state(settings); 1880 StateMachine state(settings);
1877 state.SetCanStart(); 1881 state.SetCanStart();
1878 state.UpdateState(state.NextAction()); 1882 state.UpdateState(state.NextAction());
1879 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 1883 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
1880 state.SetVisible(true); 1884 state.SetVisible(true);
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
1992 state.SetVisible(true); 1996 state.SetVisible(true);
1993 state.SetCanDraw(true); 1997 state.SetCanDraw(true);
1994 1998
1995 EXPECT_FALSE(state.BeginFrameNeeded()); 1999 EXPECT_FALSE(state.BeginFrameNeeded());
1996 state.SetChildrenNeedBeginFrames(true); 2000 state.SetChildrenNeedBeginFrames(true);
1997 EXPECT_TRUE(state.BeginFrameNeeded()); 2001 EXPECT_TRUE(state.BeginFrameNeeded());
1998 } 2002 }
1999 2003
2000 } // namespace 2004 } // namespace
2001 } // namespace cc 2005 } // namespace cc
OLDNEW
« no previous file with comments | « cc/scheduler/scheduler_state_machine.cc ('k') | cc/scheduler/scheduler_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698