| 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 1705 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1716 | 1716 |
| 1717 // Since only the scroll offset changed, the main thread will abort the | 1717 // Since only the scroll offset changed, the main thread will abort the |
| 1718 // commit. | 1718 // commit. |
| 1719 state.BeginMainFrameAborted(true); | 1719 state.BeginMainFrameAborted(true); |
| 1720 | 1720 |
| 1721 // Since the commit was aborted, we should draw right away instead of waiting | 1721 // Since the commit was aborted, we should draw right away instead of waiting |
| 1722 // for the deadline. | 1722 // for the deadline. |
| 1723 EXPECT_TRUE(state.ShouldTriggerBeginImplFrameDeadlineEarly()); | 1723 EXPECT_TRUE(state.ShouldTriggerBeginImplFrameDeadlineEarly()); |
| 1724 } | 1724 } |
| 1725 | 1725 |
| 1726 TEST(SchedulerStateMachineTest, TestTriggerDeadlineEarlyForSmoothness) { | 1726 void FinishPreviousCommitAndDrawWithoutExitingDeadline( |
| 1727 StateMachine* state_ptr) { |
| 1728 // Gross, but allows us to use macros below. |
| 1729 StateMachine& state = *state_ptr; |
| 1730 |
| 1731 state.NotifyBeginMainFrameStarted(); |
| 1732 state.NotifyReadyToCommit(); |
| 1733 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); |
| 1734 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 1735 state.NotifyReadyToActivate(); |
| 1736 EXPECT_ACTION_UPDATE_STATE( |
| 1737 SchedulerStateMachine::ACTION_ACTIVATE_PENDING_TREE); |
| 1738 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 1739 |
| 1740 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting()); |
| 1741 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE); |
| 1742 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 1743 |
| 1744 EXPECT_TRUE(state.ShouldTriggerBeginImplFrameDeadlineEarly()); |
| 1745 state.OnBeginImplFrameDeadline(); |
| 1746 EXPECT_ACTION_UPDATE_STATE( |
| 1747 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); |
| 1748 state.DidSwapBuffers(); |
| 1749 } |
| 1750 |
| 1751 TEST(SchedulerStateMachineTest, TestSmoothnessTakesPriority) { |
| 1727 SchedulerSettings settings; | 1752 SchedulerSettings settings; |
| 1728 settings.impl_side_painting = true; | 1753 settings.impl_side_painting = true; |
| 1729 StateMachine state(settings); | 1754 StateMachine state(settings); |
| 1730 state.SetCanStart(); | 1755 state.SetCanStart(); |
| 1731 state.UpdateState(state.NextAction()); | 1756 state.UpdateState(state.NextAction()); |
| 1732 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); | 1757 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); |
| 1733 state.SetVisible(true); | 1758 state.SetVisible(true); |
| 1734 state.SetCanDraw(true); | 1759 state.SetCanDraw(true); |
| 1735 | 1760 |
| 1736 // This test ensures that impl-draws are prioritized over main thread updates | 1761 // This test ensures that impl-draws are prioritized over main thread updates |
| 1737 // in prefer smoothness mode. | 1762 // in prefer smoothness mode. |
| 1738 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting()); | |
| 1739 state.SetNeedsRedraw(true); | 1763 state.SetNeedsRedraw(true); |
| 1740 state.SetNeedsCommit(); | 1764 state.SetNeedsCommit(); |
| 1765 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting()); |
| 1741 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE); | 1766 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE); |
| 1742 EXPECT_ACTION_UPDATE_STATE( | 1767 EXPECT_ACTION_UPDATE_STATE( |
| 1743 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); | 1768 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); |
| 1744 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | 1769 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 1745 | 1770 |
| 1746 // The deadline is not triggered early until we enter prefer smoothness mode. | 1771 // Verify the deadline is not triggered early until we enter |
| 1772 // prefer smoothness mode. |
| 1747 EXPECT_FALSE(state.ShouldTriggerBeginImplFrameDeadlineEarly()); | 1773 EXPECT_FALSE(state.ShouldTriggerBeginImplFrameDeadlineEarly()); |
| 1748 state.SetSmoothnessTakesPriority(true); | 1774 state.SetSmoothnessTakesPriority(true); |
| 1749 EXPECT_TRUE(state.ShouldTriggerBeginImplFrameDeadlineEarly()); | 1775 EXPECT_TRUE(state.ShouldTriggerBeginImplFrameDeadlineEarly()); |
| 1776 |
| 1777 // Trigger the deadline. |
| 1778 state.OnBeginImplFrameDeadline(); |
| 1779 EXPECT_ACTION_UPDATE_STATE( |
| 1780 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); |
| 1781 state.DidSwapBuffers(); |
| 1782 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 1783 state.DidSwapBuffersComplete(); |
| 1784 |
| 1785 // Request a new commit and finish the previous one. |
| 1786 state.SetNeedsCommit(); |
| 1787 FinishPreviousCommitAndDrawWithoutExitingDeadline(&state); |
| 1788 EXPECT_ACTION_UPDATE_STATE( |
| 1789 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); |
| 1790 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 1791 state.DidSwapBuffersComplete(); |
| 1792 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 1793 |
| 1794 // Finish the previous commit and draw it. |
| 1795 FinishPreviousCommitAndDrawWithoutExitingDeadline(&state); |
| 1796 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 1797 |
| 1798 // Verify we do not send another BeginMainFrame if was are swap throttled |
| 1799 // and did not just swap. |
| 1800 state.SetNeedsCommit(); |
| 1801 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 1802 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting()); |
| 1803 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 1804 EXPECT_FALSE(state.ShouldTriggerBeginImplFrameDeadlineEarly()); |
| 1805 state.OnBeginImplFrameDeadline(); |
| 1806 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 1750 } | 1807 } |
| 1751 | 1808 |
| 1752 TEST(SchedulerStateMachineTest, TestTriggerDeadlineEarlyOnLostOutputSurface) { | 1809 TEST(SchedulerStateMachineTest, TestTriggerDeadlineEarlyOnLostOutputSurface) { |
| 1753 SchedulerSettings default_scheduler_settings; | 1810 SchedulerSettings default_scheduler_settings; |
| 1754 StateMachine state(default_scheduler_settings); | 1811 StateMachine state(default_scheduler_settings); |
| 1755 state.SetCanStart(); | 1812 state.SetCanStart(); |
| 1756 state.UpdateState(state.NextAction()); | 1813 state.UpdateState(state.NextAction()); |
| 1757 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); | 1814 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); |
| 1758 state.SetVisible(true); | 1815 state.SetVisible(true); |
| 1759 state.SetCanDraw(true); | 1816 state.SetCanDraw(true); |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1846 state.SetNeedsAnimate(); | 1903 state.SetNeedsAnimate(); |
| 1847 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | 1904 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 1848 | 1905 |
| 1849 state.OnBeginImplFrameDeadline(); | 1906 state.OnBeginImplFrameDeadline(); |
| 1850 EXPECT_ACTION_UPDATE_STATE( | 1907 EXPECT_ACTION_UPDATE_STATE( |
| 1851 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); | 1908 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); |
| 1852 } | 1909 } |
| 1853 | 1910 |
| 1854 } // namespace | 1911 } // namespace |
| 1855 } // namespace cc | 1912 } // namespace cc |
| OLD | NEW |