diff options
author | dominikg@chromium.org <dominikg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-11-08 00:51:45 +0000 |
---|---|---|
committer | dominikg@chromium.org <dominikg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-11-08 00:51:45 +0000 |
commit | 56ec73072f135e7e77788f5a09e43e807faa9882 (patch) | |
tree | 3eba8d6d7ab158e2bdafe65616d8d28c3e2018cf /cc/scheduler/scheduler_unittest.cc | |
parent | 6ee97bc958ab1e45df101763dbd7afd2c7cb6526 (diff) | |
download | chromium_src-56ec73072f135e7e77788f5a09e43e807faa9882.zip chromium_src-56ec73072f135e7e77788f5a09e43e807faa9882.tar.gz chromium_src-56ec73072f135e7e77788f5a09e43e807faa9882.tar.bz2 |
Scheduler: Switch from high to low latency mode if possible.
Detect if the renderer's impl thread is one frame behind the main thread (i.e. the main thread is in a high
latency mode). If, based on our estimates, the main thread can produce a new tree
before the impl thread's deadline, skip a BeginMainFrame to let the impl thread
catch up and operate in low latency mode from then on.
This feature is currently disabled by default.
BUG=309648
Review URL: https://codereview.chromium.org/54913003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@233734 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'cc/scheduler/scheduler_unittest.cc')
-rw-r--r-- | cc/scheduler/scheduler_unittest.cc | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/cc/scheduler/scheduler_unittest.cc b/cc/scheduler/scheduler_unittest.cc index 03f3148..772ce7c 100644 --- a/cc/scheduler/scheduler_unittest.cc +++ b/cc/scheduler/scheduler_unittest.cc @@ -8,6 +8,7 @@ #include "base/logging.h" #include "base/memory/scoped_vector.h" +#include "base/time/time.h" #include "cc/test/scheduler_test_common.h" #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" @@ -1128,5 +1129,93 @@ TEST(SchedulerTest, ManageTilesOncePerFrame) { EXPECT_FALSE(scheduler->ManageTilesPending()); } +class SchedulerClientWithFixedEstimates : public FakeSchedulerClient { + public: + SchedulerClientWithFixedEstimates( + base::TimeDelta draw_duration, + base::TimeDelta begin_main_frame_to_commit_duration, + base::TimeDelta commit_to_activate_duration) + : draw_duration_(draw_duration), + begin_main_frame_to_commit_duration_( + begin_main_frame_to_commit_duration), + commit_to_activate_duration_(commit_to_activate_duration) {} + + virtual base::TimeDelta DrawDurationEstimate() OVERRIDE { + return draw_duration_; + } + virtual base::TimeDelta BeginMainFrameToCommitDurationEstimate() OVERRIDE { + return begin_main_frame_to_commit_duration_; + } + virtual base::TimeDelta CommitToActivateDurationEstimate() OVERRIDE { + return commit_to_activate_duration_; + } + + private: + base::TimeDelta draw_duration_; + base::TimeDelta begin_main_frame_to_commit_duration_; + base::TimeDelta commit_to_activate_duration_; +}; + +void MainFrameInHighLatencyMode(int64 begin_main_frame_to_commit_estimate_in_ms, + int64 commit_to_activate_estimate_in_ms, + bool should_send_begin_main_frame) { + // Set up client with specified estimates (draw duration is set to 1). + SchedulerClientWithFixedEstimates client( + base::TimeDelta::FromMilliseconds(1), + base::TimeDelta::FromMilliseconds( + begin_main_frame_to_commit_estimate_in_ms), + base::TimeDelta::FromMilliseconds(commit_to_activate_estimate_in_ms)); + SchedulerSettings scheduler_settings; + scheduler_settings.deadline_scheduling_enabled = true; + scheduler_settings.switch_to_low_latency_if_possible = true; + Scheduler* scheduler = client.CreateScheduler(scheduler_settings); + scheduler->SetCanStart(); + scheduler->SetVisible(true); + scheduler->SetCanDraw(true); + InitializeOutputSurfaceAndFirstCommit(scheduler); + + // Impl thread hits deadline before commit finishes. + client.Reset(); + scheduler->SetNeedsCommit(); + EXPECT_FALSE(scheduler->MainThreadIsInHighLatencyMode()); + scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); + EXPECT_FALSE(scheduler->MainThreadIsInHighLatencyMode()); + scheduler->OnBeginImplFrameDeadline(); + EXPECT_TRUE(scheduler->MainThreadIsInHighLatencyMode()); + scheduler->FinishCommit(); + EXPECT_TRUE(scheduler->MainThreadIsInHighLatencyMode()); + EXPECT_TRUE(client.HasAction("ScheduledActionSendBeginMainFrame")); + + client.Reset(); + scheduler->SetNeedsCommit(); + EXPECT_TRUE(scheduler->MainThreadIsInHighLatencyMode()); + scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); + EXPECT_TRUE(scheduler->MainThreadIsInHighLatencyMode()); + scheduler->OnBeginImplFrameDeadline(); + EXPECT_EQ(scheduler->MainThreadIsInHighLatencyMode(), + should_send_begin_main_frame); + EXPECT_EQ(client.HasAction("ScheduledActionSendBeginMainFrame"), + should_send_begin_main_frame); +} + +TEST(SchedulerTest, + SkipMainFrameIfHighLatencyAndCanCommitAndActivateBeforeDeadline) { + // Set up client so that estimates indicate that we can commit and activate + // before the deadline (~8ms by default). + MainFrameInHighLatencyMode(1, 1, false); +} + +TEST(SchedulerTest, NotSkipMainFrameIfHighLatencyAndCanCommitTooLong) { + // Set up client so that estimates indicate that the commit cannot finish + // before the deadline (~8ms by default). + MainFrameInHighLatencyMode(10, 1, true); +} + +TEST(SchedulerTest, NotSkipMainFrameIfHighLatencyAndCanActivateTooLong) { + // Set up client so that estimates indicate that the activate cannot finish + // before the deadline (~8ms by default). + MainFrameInHighLatencyMode(1, 10, true); +} + } // namespace } // namespace cc |