| 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.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 1453 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1464 fake_compositor_timing_history_->SetDrawDurationEstimate(slow_duration); | 1464 fake_compositor_timing_history_->SetDrawDurationEstimate(slow_duration); |
| 1465 | 1465 |
| 1466 bool expect_send_begin_main_frame = true; | 1466 bool expect_send_begin_main_frame = true; |
| 1467 EXPECT_SCOPED( | 1467 EXPECT_SCOPED( |
| 1468 CheckMainFrameSkippedAfterLateCommit(expect_send_begin_main_frame)); | 1468 CheckMainFrameSkippedAfterLateCommit(expect_send_begin_main_frame)); |
| 1469 } | 1469 } |
| 1470 | 1470 |
| 1471 void SchedulerTest::ImplFrameSkippedAfterLateSwapAck( | 1471 void SchedulerTest::ImplFrameSkippedAfterLateSwapAck( |
| 1472 bool swap_ack_before_deadline) { | 1472 bool swap_ack_before_deadline) { |
| 1473 // To get into a high latency state, this test disables automatic swap acks. | 1473 // To get into a high latency state, this test disables automatic swap acks. |
| 1474 scheduler_->SetMaxSwapsPending(1); | |
| 1475 client_->SetAutomaticSwapAck(false); | 1474 client_->SetAutomaticSwapAck(false); |
| 1476 | 1475 |
| 1477 // Draw and swap for first BeginFrame | 1476 // Draw and swap for first BeginFrame |
| 1478 client_->Reset(); | 1477 client_->Reset(); |
| 1479 scheduler_->SetNeedsBeginMainFrame(); | 1478 scheduler_->SetNeedsBeginMainFrame(); |
| 1480 scheduler_->SetNeedsRedraw(); | 1479 scheduler_->SetNeedsRedraw(); |
| 1481 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); | 1480 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); |
| 1482 SendNextBeginFrame(); | 1481 SendNextBeginFrame(); |
| 1483 EXPECT_ACTION("SetNeedsBeginFrames(true)", client_, 0, 4); | 1482 EXPECT_ACTION("SetNeedsBeginFrames(true)", client_, 0, 4); |
| 1484 EXPECT_ACTION("WillBeginImplFrame", client_, 1, 4); | 1483 EXPECT_ACTION("WillBeginImplFrame", client_, 1, 4); |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1588 EXPECT_SCOPED(ImplFrameSkippedAfterLateSwapAck(swap_ack_before_deadline)); | 1587 EXPECT_SCOPED(ImplFrameSkippedAfterLateSwapAck(swap_ack_before_deadline)); |
| 1589 } | 1588 } |
| 1590 | 1589 |
| 1591 TEST_F(SchedulerTest, | 1590 TEST_F(SchedulerTest, |
| 1592 ImplFrameSkippedAfterLateSwapAck_OnlyImplSideUpdatesExpected) { | 1591 ImplFrameSkippedAfterLateSwapAck_OnlyImplSideUpdatesExpected) { |
| 1593 // This tests that we recover impl thread latency when there are no commits. | 1592 // This tests that we recover impl thread latency when there are no commits. |
| 1594 scheduler_settings_.use_external_begin_frame_source = true; | 1593 scheduler_settings_.use_external_begin_frame_source = true; |
| 1595 SetUpScheduler(true); | 1594 SetUpScheduler(true); |
| 1596 | 1595 |
| 1597 // To get into a high latency state, this test disables automatic swap acks. | 1596 // To get into a high latency state, this test disables automatic swap acks. |
| 1598 scheduler_->SetMaxSwapsPending(1); | |
| 1599 client_->SetAutomaticSwapAck(false); | 1597 client_->SetAutomaticSwapAck(false); |
| 1600 | 1598 |
| 1601 // Even if every estimate related to the main thread is slow, we should | 1599 // Even if every estimate related to the main thread is slow, we should |
| 1602 // still expect to recover impl thread latency if there are no commits from | 1600 // still expect to recover impl thread latency if there are no commits from |
| 1603 // the main thread. | 1601 // the main thread. |
| 1604 auto slow_duration = base::TimeDelta::FromSeconds(1); | 1602 auto slow_duration = base::TimeDelta::FromSeconds(1); |
| 1605 fake_compositor_timing_history_->SetAllEstimatesTo(slow_duration); | 1603 fake_compositor_timing_history_->SetAllEstimatesTo(slow_duration); |
| 1606 auto fast_duration = base::TimeDelta::FromMilliseconds(1); | 1604 auto fast_duration = base::TimeDelta::FromMilliseconds(1); |
| 1607 fake_compositor_timing_history_->SetDrawDurationEstimate(fast_duration); | 1605 fake_compositor_timing_history_->SetDrawDurationEstimate(fast_duration); |
| 1608 | 1606 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1652 // Deadline should be immediate. | 1650 // Deadline should be immediate. |
| 1653 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 1651 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
| 1654 task_runner().RunUntilTime(now_src_->NowTicks()); | 1652 task_runner().RunUntilTime(now_src_->NowTicks()); |
| 1655 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | 1653 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); |
| 1656 EXPECT_SINGLE_ACTION("ScheduledActionDrawAndSwapIfPossible", client_); | 1654 EXPECT_SINGLE_ACTION("ScheduledActionDrawAndSwapIfPossible", client_); |
| 1657 } | 1655 } |
| 1658 } | 1656 } |
| 1659 | 1657 |
| 1660 void SchedulerTest::ImplFrameIsNotSkippedAfterLateSwapAck() { | 1658 void SchedulerTest::ImplFrameIsNotSkippedAfterLateSwapAck() { |
| 1661 // To get into a high latency state, this test disables automatic swap acks. | 1659 // To get into a high latency state, this test disables automatic swap acks. |
| 1662 scheduler_->SetMaxSwapsPending(1); | |
| 1663 client_->SetAutomaticSwapAck(false); | 1660 client_->SetAutomaticSwapAck(false); |
| 1664 | 1661 |
| 1665 // Draw and swap for first BeginFrame | 1662 // Draw and swap for first BeginFrame |
| 1666 client_->Reset(); | 1663 client_->Reset(); |
| 1667 scheduler_->SetNeedsBeginMainFrame(); | 1664 scheduler_->SetNeedsBeginMainFrame(); |
| 1668 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); | 1665 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); |
| 1669 SendNextBeginFrame(); | 1666 SendNextBeginFrame(); |
| 1670 EXPECT_ACTION("SetNeedsBeginFrames(true)", client_, 0, 3); | 1667 EXPECT_ACTION("SetNeedsBeginFrames(true)", client_, 0, 3); |
| 1671 EXPECT_ACTION("WillBeginImplFrame", client_, 1, 3); | 1668 EXPECT_ACTION("WillBeginImplFrame", client_, 1, 3); |
| 1672 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 2, 3); | 1669 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 2, 3); |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1763 // This test starts off with expensive estimates to prevent latency recovery | 1760 // This test starts off with expensive estimates to prevent latency recovery |
| 1764 // initially, then lowers the estimates to enable it once both the main | 1761 // initially, then lowers the estimates to enable it once both the main |
| 1765 // and impl threads are in a high latency mode. | 1762 // and impl threads are in a high latency mode. |
| 1766 scheduler_settings_.use_external_begin_frame_source = true; | 1763 scheduler_settings_.use_external_begin_frame_source = true; |
| 1767 SetUpScheduler(true); | 1764 SetUpScheduler(true); |
| 1768 | 1765 |
| 1769 auto slow_duration = base::TimeDelta::FromSeconds(1); | 1766 auto slow_duration = base::TimeDelta::FromSeconds(1); |
| 1770 fake_compositor_timing_history_->SetAllEstimatesTo(slow_duration); | 1767 fake_compositor_timing_history_->SetAllEstimatesTo(slow_duration); |
| 1771 | 1768 |
| 1772 // To get into a high latency state, this test disables automatic swap acks. | 1769 // To get into a high latency state, this test disables automatic swap acks. |
| 1773 scheduler_->SetMaxSwapsPending(1); | |
| 1774 client_->SetAutomaticSwapAck(false); | 1770 client_->SetAutomaticSwapAck(false); |
| 1775 | 1771 |
| 1776 // Impl thread hits deadline before commit finishes to make | 1772 // Impl thread hits deadline before commit finishes to make |
| 1777 // MainThreadMissedLastDeadline true | 1773 // MainThreadMissedLastDeadline true |
| 1778 client_->Reset(); | 1774 client_->Reset(); |
| 1779 scheduler_->SetNeedsBeginMainFrame(); | 1775 scheduler_->SetNeedsBeginMainFrame(); |
| 1780 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); | 1776 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); |
| 1781 EXPECT_SCOPED(AdvanceFrame()); | 1777 EXPECT_SCOPED(AdvanceFrame()); |
| 1782 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); | 1778 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); |
| 1783 task_runner().RunTasksWhile(client_->ImplFrameDeadlinePending(true)); | 1779 task_runner().RunTasksWhile(client_->ImplFrameDeadlinePending(true)); |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1892 Deadlock_CommitMakesProgressWhileSwapTrottledAndActiveTreeNeedsFirstDraw) { | 1888 Deadlock_CommitMakesProgressWhileSwapTrottledAndActiveTreeNeedsFirstDraw) { |
| 1893 // NPAPI plugins on Windows block the Browser UI thread on the Renderer main | 1889 // NPAPI plugins on Windows block the Browser UI thread on the Renderer main |
| 1894 // thread. This prevents the scheduler from receiving any pending swap acks. | 1890 // thread. This prevents the scheduler from receiving any pending swap acks. |
| 1895 | 1891 |
| 1896 scheduler_settings_.use_external_begin_frame_source = true; | 1892 scheduler_settings_.use_external_begin_frame_source = true; |
| 1897 scheduler_settings_.main_frame_while_swap_throttled_enabled = true; | 1893 scheduler_settings_.main_frame_while_swap_throttled_enabled = true; |
| 1898 SetUpScheduler(true); | 1894 SetUpScheduler(true); |
| 1899 | 1895 |
| 1900 // Disables automatic swap acks so this test can force swap ack throttling | 1896 // Disables automatic swap acks so this test can force swap ack throttling |
| 1901 // to simulate a blocked Browser ui thread. | 1897 // to simulate a blocked Browser ui thread. |
| 1902 scheduler_->SetMaxSwapsPending(1); | |
| 1903 client_->SetAutomaticSwapAck(false); | 1898 client_->SetAutomaticSwapAck(false); |
| 1904 | 1899 |
| 1905 // Get a new active tree in main-thread high latency mode and put us | 1900 // Get a new active tree in main-thread high latency mode and put us |
| 1906 // in a swap throttled state. | 1901 // in a swap throttled state. |
| 1907 client_->Reset(); | 1902 client_->Reset(); |
| 1908 EXPECT_FALSE(scheduler_->CommitPending()); | 1903 EXPECT_FALSE(scheduler_->CommitPending()); |
| 1909 scheduler_->SetNeedsBeginMainFrame(); | 1904 scheduler_->SetNeedsBeginMainFrame(); |
| 1910 scheduler_->SetNeedsRedraw(); | 1905 scheduler_->SetNeedsRedraw(); |
| 1911 EXPECT_SCOPED(AdvanceFrame()); | 1906 EXPECT_SCOPED(AdvanceFrame()); |
| 1912 EXPECT_TRUE(scheduler_->CommitPending()); | 1907 EXPECT_TRUE(scheduler_->CommitPending()); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1963 // swap trottled and we have a pending tree and active tree that | 1958 // swap trottled and we have a pending tree and active tree that |
| 1964 // still needs to be drawn for the first time. | 1959 // still needs to be drawn for the first time. |
| 1965 | 1960 |
| 1966 scheduler_settings_.use_external_begin_frame_source = true; | 1961 scheduler_settings_.use_external_begin_frame_source = true; |
| 1967 scheduler_settings_.main_frame_while_swap_throttled_enabled = true; | 1962 scheduler_settings_.main_frame_while_swap_throttled_enabled = true; |
| 1968 scheduler_settings_.main_frame_before_activation_enabled = true; | 1963 scheduler_settings_.main_frame_before_activation_enabled = true; |
| 1969 SetUpScheduler(true); | 1964 SetUpScheduler(true); |
| 1970 | 1965 |
| 1971 // Disables automatic swap acks so this test can force swap ack throttling | 1966 // Disables automatic swap acks so this test can force swap ack throttling |
| 1972 // to simulate a blocked Browser ui thread. | 1967 // to simulate a blocked Browser ui thread. |
| 1973 scheduler_->SetMaxSwapsPending(1); | |
| 1974 client_->SetAutomaticSwapAck(false); | 1968 client_->SetAutomaticSwapAck(false); |
| 1975 | 1969 |
| 1976 // Start a new commit in main-thread high latency mode and hold off on | 1970 // Start a new commit in main-thread high latency mode and hold off on |
| 1977 // activation. | 1971 // activation. |
| 1978 client_->Reset(); | 1972 client_->Reset(); |
| 1979 EXPECT_FALSE(scheduler_->CommitPending()); | 1973 EXPECT_FALSE(scheduler_->CommitPending()); |
| 1980 scheduler_->SetNeedsBeginMainFrame(); | 1974 scheduler_->SetNeedsBeginMainFrame(); |
| 1981 scheduler_->SetNeedsRedraw(); | 1975 scheduler_->SetNeedsRedraw(); |
| 1982 EXPECT_SCOPED(AdvanceFrame()); | 1976 EXPECT_SCOPED(AdvanceFrame()); |
| 1983 EXPECT_TRUE(scheduler_->CommitPending()); | 1977 EXPECT_TRUE(scheduler_->CommitPending()); |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2044 | 2038 |
| 2045 // Since we are simulating a long commit, set up a client with draw duration | 2039 // Since we are simulating a long commit, set up a client with draw duration |
| 2046 // estimates that prevent skipping main frames to get to low latency mode. | 2040 // estimates that prevent skipping main frames to get to low latency mode. |
| 2047 scheduler_settings_.use_external_begin_frame_source = true; | 2041 scheduler_settings_.use_external_begin_frame_source = true; |
| 2048 scheduler_settings_.main_frame_while_swap_throttled_enabled = true; | 2042 scheduler_settings_.main_frame_while_swap_throttled_enabled = true; |
| 2049 scheduler_settings_.main_frame_before_activation_enabled = true; | 2043 scheduler_settings_.main_frame_before_activation_enabled = true; |
| 2050 SetUpScheduler(true); | 2044 SetUpScheduler(true); |
| 2051 | 2045 |
| 2052 // Disables automatic swap acks so this test can force swap ack throttling | 2046 // Disables automatic swap acks so this test can force swap ack throttling |
| 2053 // to simulate a blocked Browser ui thread. | 2047 // to simulate a blocked Browser ui thread. |
| 2054 scheduler_->SetMaxSwapsPending(1); | |
| 2055 client_->SetAutomaticSwapAck(false); | 2048 client_->SetAutomaticSwapAck(false); |
| 2056 | 2049 |
| 2057 // Start a new commit in main-thread high latency mode and hold off on | 2050 // Start a new commit in main-thread high latency mode and hold off on |
| 2058 // activation. | 2051 // activation. |
| 2059 client_->Reset(); | 2052 client_->Reset(); |
| 2060 EXPECT_FALSE(scheduler_->CommitPending()); | 2053 EXPECT_FALSE(scheduler_->CommitPending()); |
| 2061 scheduler_->SetNeedsBeginMainFrame(); | 2054 scheduler_->SetNeedsBeginMainFrame(); |
| 2062 scheduler_->SetNeedsRedraw(); | 2055 scheduler_->SetNeedsRedraw(); |
| 2063 EXPECT_SCOPED(AdvanceFrame()); | 2056 EXPECT_SCOPED(AdvanceFrame()); |
| 2064 EXPECT_TRUE(scheduler_->CommitPending()); | 2057 EXPECT_TRUE(scheduler_->CommitPending()); |
| (...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2440 scheduler_settings_.throttle_frame_production = throttle_frame_production; | 2433 scheduler_settings_.throttle_frame_production = throttle_frame_production; |
| 2441 SetUpScheduler(true); | 2434 SetUpScheduler(true); |
| 2442 | 2435 |
| 2443 scheduler_->SetEstimatedParentDrawTime( | 2436 scheduler_->SetEstimatedParentDrawTime( |
| 2444 BeginFrameArgs::DefaultEstimatedParentDrawTime()); | 2437 BeginFrameArgs::DefaultEstimatedParentDrawTime()); |
| 2445 | 2438 |
| 2446 // Set the draw duration estimate to zero so that deadlines are accurate. | 2439 // Set the draw duration estimate to zero so that deadlines are accurate. |
| 2447 fake_compositor_timing_history_->SetDrawDurationEstimate(base::TimeDelta()); | 2440 fake_compositor_timing_history_->SetDrawDurationEstimate(base::TimeDelta()); |
| 2448 | 2441 |
| 2449 // To test swap ack throttling, this test disables automatic swap acks. | 2442 // To test swap ack throttling, this test disables automatic swap acks. |
| 2450 scheduler_->SetMaxSwapsPending(1); | |
| 2451 client_->SetAutomaticSwapAck(false); | 2443 client_->SetAutomaticSwapAck(false); |
| 2452 | 2444 |
| 2453 // SetNeedsBeginMainFrame should begin the frame on the next BeginImplFrame. | 2445 // SetNeedsBeginMainFrame should begin the frame on the next BeginImplFrame. |
| 2454 client_->Reset(); | 2446 client_->Reset(); |
| 2455 scheduler_->SetNeedsBeginMainFrame(); | 2447 scheduler_->SetNeedsBeginMainFrame(); |
| 2456 EXPECT_NO_ACTION(client_); | 2448 EXPECT_NO_ACTION(client_); |
| 2457 client_->Reset(); | 2449 client_->Reset(); |
| 2458 | 2450 |
| 2459 // Trigger the first BeginImplFrame and BeginMainFrame | 2451 // Trigger the first BeginImplFrame and BeginMainFrame |
| 2460 EXPECT_SCOPED(AdvanceFrame()); | 2452 EXPECT_SCOPED(AdvanceFrame()); |
| (...skipping 1055 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3516 | 3508 |
| 3517 client_->Reset(); | 3509 client_->Reset(); |
| 3518 EXPECT_FALSE(client_->last_begin_main_frame_args().IsValid()); | 3510 EXPECT_FALSE(client_->last_begin_main_frame_args().IsValid()); |
| 3519 EXPECT_SCOPED(AdvanceFrame()); | 3511 EXPECT_SCOPED(AdvanceFrame()); |
| 3520 EXPECT_TRUE(client_->last_begin_main_frame_args().IsValid()); | 3512 EXPECT_TRUE(client_->last_begin_main_frame_args().IsValid()); |
| 3521 EXPECT_FALSE(client_->last_begin_main_frame_args().on_critical_path); | 3513 EXPECT_FALSE(client_->last_begin_main_frame_args().on_critical_path); |
| 3522 } | 3514 } |
| 3523 | 3515 |
| 3524 } // namespace | 3516 } // namespace |
| 3525 } // namespace cc | 3517 } // namespace cc |
| OLD | NEW |