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 #include "cc/scheduler/scheduler.h" | 4 #include "cc/scheduler/scheduler.h" |
5 | 5 |
6 #include <string> | 6 #include <string> |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/debug/trace_event.h" | 9 #include "base/debug/trace_event.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/memory/scoped_vector.h" | 11 #include "base/memory/scoped_vector.h" |
12 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
13 #include "base/power_monitor/power_monitor.h" | |
14 #include "base/power_monitor/power_monitor_source.h" | |
13 #include "base/run_loop.h" | 15 #include "base/run_loop.h" |
14 #include "base/time/time.h" | 16 #include "base/time/time.h" |
15 #include "cc/test/begin_frame_args_test.h" | 17 #include "cc/test/begin_frame_args_test.h" |
16 #include "cc/test/ordered_simple_task_runner.h" | 18 #include "cc/test/ordered_simple_task_runner.h" |
17 #include "cc/test/scheduler_test_common.h" | 19 #include "cc/test/scheduler_test_common.h" |
18 #include "testing/gmock/include/gmock/gmock.h" | 20 #include "testing/gmock/include/gmock/gmock.h" |
19 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
20 | 22 |
21 #define EXPECT_ACTION(action, client, action_index, expected_num_actions) \ | 23 #define EXPECT_ACTION(action, client, action_index, expected_num_actions) \ |
22 do { \ | 24 do { \ |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
83 base::TimeTicks posted_begin_impl_frame_deadline() const { | 85 base::TimeTicks posted_begin_impl_frame_deadline() const { |
84 return posted_begin_impl_frame_deadline_; | 86 return posted_begin_impl_frame_deadline_; |
85 } | 87 } |
86 | 88 |
87 void AdvanceFrame() { | 89 void AdvanceFrame() { |
88 bool external_begin_frame = | 90 bool external_begin_frame = |
89 scheduler_->settings().begin_frame_scheduling_enabled && | 91 scheduler_->settings().begin_frame_scheduling_enabled && |
90 scheduler_->settings().throttle_frame_production; | 92 scheduler_->settings().throttle_frame_production; |
91 | 93 |
92 if (external_begin_frame) { | 94 if (external_begin_frame) { |
93 scheduler_->BeginFrame(CreateBeginFrameArgsForTesting(now_src_)); | 95 SendBeginFrame(); |
94 } | 96 } |
95 | 97 |
96 EXPECT_TRUE(task_runner().RunTasksWhile(ImplFrameDeadlinePending(false))); | 98 EXPECT_TRUE(task_runner().RunTasksWhile(ImplFrameDeadlinePending(false))); |
97 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 99 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
98 } | 100 } |
99 | 101 |
102 void SendBeginFrame() { | |
brianderson
2014/09/12 22:05:27
Can you call this AdvanceFrameSynchronousDeadline
sunnyps
2014/09/15 21:52:48
Done.
| |
103 scheduler_->BeginFrame(CreateBeginFrameArgsForTesting(now_src_)); | |
104 } | |
105 | |
100 OrderedSimpleTaskRunner& task_runner() { return scheduler_->task_runner(); } | 106 OrderedSimpleTaskRunner& task_runner() { return scheduler_->task_runner(); } |
101 TestNowSource* now_src() { return now_src_.get(); } | 107 TestNowSource* now_src() { return now_src_.get(); } |
102 | 108 |
103 int ActionIndex(const char* action) const { | 109 int ActionIndex(const char* action) const { |
104 for (size_t i = 0; i < actions_.size(); i++) | 110 for (size_t i = 0; i < actions_.size(); i++) |
105 if (!strcmp(actions_[i], action)) | 111 if (!strcmp(actions_[i], action)) |
106 return i; | 112 return i; |
107 return -1; | 113 return -1; |
108 } | 114 } |
109 | 115 |
(...skipping 1792 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1902 scheduler->DidLoseOutputSurface(); | 1908 scheduler->DidLoseOutputSurface(); |
1903 EXPECT_EQ(0, client.num_actions_()); | 1909 EXPECT_EQ(0, client.num_actions_()); |
1904 EXPECT_FALSE(scheduler->IsSyntheticBeginFrameSourceActive()); | 1910 EXPECT_FALSE(scheduler->IsSyntheticBeginFrameSourceActive()); |
1905 | 1911 |
1906 client.Reset(); | 1912 client.Reset(); |
1907 client.task_runner().RunPendingTasks(); // Run posted deadline. | 1913 client.task_runner().RunPendingTasks(); // Run posted deadline. |
1908 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); | 1914 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); |
1909 EXPECT_FALSE(scheduler->IsSyntheticBeginFrameSourceActive()); | 1915 EXPECT_FALSE(scheduler->IsSyntheticBeginFrameSourceActive()); |
1910 } | 1916 } |
1911 | 1917 |
1918 class FakePowerMonitorSource : public base::PowerMonitorSource { | |
brianderson
2014/09/12 22:05:27
+bajones to make sure this FakePowerMonitorSource
sunnyps
2014/09/15 21:52:48
Done.
| |
1919 public: | |
1920 FakePowerMonitorSource() {} | |
1921 virtual ~FakePowerMonitorSource() {} | |
1922 void GeneratePowerStateEvent(bool on_battery_power) { | |
1923 on_battery_power_impl_ = on_battery_power; | |
1924 ProcessPowerEvent(POWER_STATE_EVENT); | |
1925 base::MessageLoop::current()->RunUntilIdle(); | |
1926 } | |
1927 virtual bool IsOnBatteryPowerImpl() OVERRIDE { | |
1928 return on_battery_power_impl_; | |
1929 } | |
1930 | |
1931 private: | |
1932 bool on_battery_power_impl_; | |
1933 }; | |
1934 | |
1935 TEST(SchedulerTest, HighLatencyModeOnBattery) { | |
brianderson
2014/09/12 22:05:27
This test looks good, however please create a vers
sunnyps
2014/09/15 21:52:48
I thought we decided to remove that test because r
| |
1936 // Create the power monitor before creating the scheduler | |
1937 FakePowerMonitorSource* power_monitor_source = new FakePowerMonitorSource; | |
1938 base::PowerMonitor power_monitor( | |
1939 (scoped_ptr<base::PowerMonitorSource>(power_monitor_source))); | |
1940 | |
1941 FakeSchedulerClient client; | |
1942 SchedulerSettings settings; | |
1943 settings.high_latency_mode_on_battery = true; | |
1944 TestScheduler* scheduler = client.CreateScheduler(settings); | |
1945 | |
1946 scheduler->SetCanStart(); | |
1947 scheduler->SetVisible(true); | |
1948 scheduler->SetCanDraw(true); | |
1949 | |
1950 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); | |
1951 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | |
1952 | |
1953 // On non-battery power | |
1954 EXPECT_FALSE(power_monitor.IsOnBatteryPower()); | |
1955 | |
1956 client.Reset(); | |
1957 scheduler->SetNeedsCommit(); | |
1958 EXPECT_TRUE(client.needs_begin_frame()); | |
1959 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); | |
1960 client.Reset(); | |
1961 | |
1962 client.SendBeginFrame(); | |
1963 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | |
1964 // The scheduler schedules a BeginMainFrame because it NeedsCommit | |
1965 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); | |
1966 // The scheduler waits for the renderer | |
1967 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | |
1968 client.Reset(); | |
1969 | |
1970 client.task_runner().RunPendingTasks(); // Run posted deadline. | |
1971 EXPECT_NO_ACTION(client); | |
1972 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | |
1973 EXPECT_TRUE(client.needs_begin_frame()); | |
1974 client.Reset(); | |
1975 | |
1976 // Switch to battery power | |
1977 power_monitor_source->GeneratePowerStateEvent(true); | |
1978 EXPECT_TRUE(power_monitor.IsOnBatteryPower()); | |
1979 | |
1980 client.SendBeginFrame(); | |
1981 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); | |
1982 // The scheduler does not post a deadline task, neither does it schedule | |
1983 // another BeginMainFrame because it's still waiting for the last one | |
1984 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | |
1985 client.Reset(); | |
1986 | |
1987 // Do nothing until the next BeginFrame is called | |
1988 EXPECT_NO_ACTION(client); | |
1989 EXPECT_TRUE(client.needs_begin_frame()); | |
1990 client.Reset(); | |
1991 | |
1992 // Switch to non-battery power | |
1993 power_monitor_source->GeneratePowerStateEvent(false); | |
1994 EXPECT_FALSE(power_monitor.IsOnBatteryPower()); | |
1995 | |
1996 client.SendBeginFrame(); | |
1997 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); | |
1998 // The scheduler waits for the renderer | |
1999 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | |
2000 client.Reset(); | |
2001 } | |
2002 | |
1912 } // namespace | 2003 } // namespace |
1913 } // namespace cc | 2004 } // namespace cc |
OLD | NEW |