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/debug/trace_event.h" | 10 #include "base/debug/trace_event.h" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/memory/scoped_vector.h" | 12 #include "base/memory/scoped_vector.h" |
13 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
14 #include "base/power_monitor/power_monitor.h" | 14 #include "base/power_monitor/power_monitor.h" |
15 #include "base/power_monitor/power_monitor_source.h" | 15 #include "base/power_monitor/power_monitor_source.h" |
16 #include "base/run_loop.h" | 16 #include "base/run_loop.h" |
17 #include "base/time/time.h" | 17 #include "base/time/time.h" |
18 #include "cc/test/begin_frame_args_test.h" | 18 #include "cc/test/begin_frame_args_test.h" |
19 #include "cc/test/ordered_simple_task_runner.h" | 19 #include "cc/test/ordered_simple_task_runner.h" |
20 #include "cc/test/scheduler_test_common.h" | 20 #include "cc/test/scheduler_test_common.h" |
21 #include "testing/gmock/include/gmock/gmock.h" | 21 #include "testing/gmock/include/gmock/gmock.h" |
22 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
23 | 23 |
24 #define EXPECT_ACTION(action, client, action_index, expected_num_actions) \ | 24 #define EXPECT_ACTION(action, client, action_index, expected_num_actions) \ |
25 do { \ | 25 do { \ |
26 EXPECT_EQ(expected_num_actions, client.num_actions_()); \ | 26 EXPECT_EQ(expected_num_actions, client->num_actions_()); \ |
27 if (action_index >= 0) { \ | 27 if (action_index >= 0) { \ |
28 ASSERT_LT(action_index, client.num_actions_()) << scheduler; \ | 28 ASSERT_LT(action_index, client->num_actions_()) << scheduler_.get(); \ |
29 EXPECT_STREQ(action, client.Action(action_index)); \ | 29 EXPECT_STREQ(action, client->Action(action_index)); \ |
30 } \ | 30 } \ |
31 for (int i = expected_num_actions; i < client.num_actions_(); ++i) \ | 31 for (int i = expected_num_actions; i < client->num_actions_(); ++i) \ |
32 ADD_FAILURE() << "Unexpected action: " << client.Action(i) \ | 32 ADD_FAILURE() << "Unexpected action: " << client->Action(i) \ |
33 << " with state:\n" << client.StateForAction(i); \ | 33 << " with state:\n" << client->StateForAction(i); \ |
34 } while (false) | 34 } while (false) |
35 | 35 |
36 #define EXPECT_NO_ACTION(client) EXPECT_ACTION("", client, -1, 0) | 36 #define EXPECT_NO_ACTION(client) EXPECT_ACTION("", client, -1, 0) |
37 | 37 |
38 #define EXPECT_SINGLE_ACTION(action, client) \ | 38 #define EXPECT_SINGLE_ACTION(action, client) \ |
39 EXPECT_ACTION(action, client, 0, 1) | 39 EXPECT_ACTION(action, client, 0, 1) |
40 | 40 |
41 #define EXPECT_SCOPED(statements) \ | 41 #define EXPECT_SCOPED(statements) \ |
42 { \ | 42 { \ |
43 SCOPED_TRACE(""); \ | 43 SCOPED_TRACE(""); \ |
44 statements; \ | 44 statements; \ |
45 } | 45 } |
46 | 46 |
47 #define CREATE_SCHEDULER_AND_INIT_SURFACE(settings) \ | |
48 TestScheduler* scheduler = client.CreateScheduler(settings); \ | |
49 EXPECT_SCOPED(client.InitializeOutputSurfaceAndFirstCommit(scheduler)); | |
50 | |
51 namespace cc { | 47 namespace cc { |
52 namespace { | 48 namespace { |
53 | 49 |
54 class FakeSchedulerClient; | |
55 | |
56 class FakeSchedulerClient : public SchedulerClient { | 50 class FakeSchedulerClient : public SchedulerClient { |
57 public: | 51 public: |
58 class FakeExternalBeginFrameSource : public BeginFrameSourceMixIn { | |
59 public: | |
60 explicit FakeExternalBeginFrameSource(FakeSchedulerClient* client) | |
61 : client_(client) {} | |
62 ~FakeExternalBeginFrameSource() override {} | |
63 | |
64 void OnNeedsBeginFramesChange(bool needs_begin_frames) override { | |
65 if (needs_begin_frames) { | |
66 client_->PushAction("SetNeedsBeginFrames(true)"); | |
67 } else { | |
68 client_->PushAction("SetNeedsBeginFrames(false)"); | |
69 } | |
70 client_->states_.push_back(client_->scheduler_->AsValue()); | |
71 } | |
72 | |
73 void TestOnBeginFrame(const BeginFrameArgs& args) { | |
74 return CallOnBeginFrame(args); | |
75 } | |
76 | |
77 private: | |
78 FakeSchedulerClient* client_; | |
79 }; | |
80 | |
81 class FakePowerMonitorSource : public base::PowerMonitorSource { | |
82 public: | |
83 FakePowerMonitorSource() {} | |
84 ~FakePowerMonitorSource() override {} | |
85 void GeneratePowerStateEvent(bool on_battery_power) { | |
86 on_battery_power_impl_ = on_battery_power; | |
87 ProcessPowerEvent(POWER_STATE_EVENT); | |
88 base::MessageLoop::current()->RunUntilIdle(); | |
89 } | |
90 bool IsOnBatteryPowerImpl() override { return on_battery_power_impl_; } | |
91 | |
92 private: | |
93 bool on_battery_power_impl_; | |
94 }; | |
95 | |
96 FakeSchedulerClient() | 52 FakeSchedulerClient() |
97 : automatic_swap_ack_(true), | 53 : automatic_swap_ack_(true), |
98 begin_frame_is_sent_to_children_(false), | 54 begin_frame_is_sent_to_children_(false), |
99 now_src_(TestNowSource::Create()), | |
100 task_runner_(new OrderedSimpleTaskRunner(now_src_, true)), | |
101 fake_external_begin_frame_source_(nullptr), | |
102 fake_power_monitor_source_(new FakePowerMonitorSource), | |
103 power_monitor_(make_scoped_ptr<base::PowerMonitorSource>( | |
104 fake_power_monitor_source_)), | |
105 scheduler_(nullptr) { | 55 scheduler_(nullptr) { |
106 // A bunch of tests require Now() to be > BeginFrameArgs::DefaultInterval() | |
107 now_src_->AdvanceNow(base::TimeDelta::FromMilliseconds(100)); | |
108 // Fail if we need to run 100 tasks in a row. | |
109 task_runner_->SetRunTaskLimit(100); | |
110 Reset(); | 56 Reset(); |
111 } | 57 } |
112 | 58 |
113 void Reset() { | 59 void Reset() { |
114 actions_.clear(); | 60 actions_.clear(); |
115 states_.clear(); | 61 states_.clear(); |
116 draw_will_happen_ = true; | 62 draw_will_happen_ = true; |
117 swap_will_happen_if_draw_happens_ = true; | 63 swap_will_happen_if_draw_happens_ = true; |
118 num_draws_ = 0; | 64 num_draws_ = 0; |
119 log_anticipated_draw_time_change_ = false; | 65 log_anticipated_draw_time_change_ = false; |
120 begin_frame_is_sent_to_children_ = false; | 66 begin_frame_is_sent_to_children_ = false; |
121 } | 67 } |
122 | 68 |
123 TestScheduler* CreateScheduler(const SchedulerSettings& settings) { | 69 void set_scheduler(TestScheduler* scheduler) { scheduler_ = scheduler; } |
124 scoped_ptr<FakeExternalBeginFrameSource> fake_external_begin_frame_source; | |
125 if (settings.use_external_begin_frame_source) { | |
126 fake_external_begin_frame_source.reset( | |
127 new FakeExternalBeginFrameSource(this)); | |
128 fake_external_begin_frame_source_ = | |
129 fake_external_begin_frame_source.get(); | |
130 } | |
131 scheduler_ = TestScheduler::Create(now_src_, | |
132 this, | |
133 settings, | |
134 0, | |
135 task_runner_, | |
136 &power_monitor_, | |
137 fake_external_begin_frame_source.Pass()); | |
138 DCHECK(scheduler_); | |
139 return scheduler_.get(); | |
140 } | |
141 | 70 |
142 // Most tests don't care about DidAnticipatedDrawTimeChange, so only record it | 71 // Most tests don't care about DidAnticipatedDrawTimeChange, so only record it |
143 // for tests that do. | 72 // for tests that do. |
144 void set_log_anticipated_draw_time_change(bool log) { | 73 void set_log_anticipated_draw_time_change(bool log) { |
145 log_anticipated_draw_time_change_ = log; | 74 log_anticipated_draw_time_change_ = log; |
146 } | 75 } |
147 bool needs_begin_frames() { | 76 bool needs_begin_frames() { |
148 return scheduler_->frame_source().NeedsBeginFrames(); | 77 return scheduler_->frame_source().NeedsBeginFrames(); |
149 } | 78 } |
150 int num_draws() const { return num_draws_; } | 79 int num_draws() const { return num_draws_; } |
151 int num_actions_() const { return static_cast<int>(actions_.size()); } | 80 int num_actions_() const { return static_cast<int>(actions_.size()); } |
152 const char* Action(int i) const { return actions_[i]; } | 81 const char* Action(int i) const { return actions_[i]; } |
153 std::string StateForAction(int i) const { return states_[i]->ToString(); } | 82 std::string StateForAction(int i) const { return states_[i]->ToString(); } |
154 base::TimeTicks posted_begin_impl_frame_deadline() const { | 83 base::TimeTicks posted_begin_impl_frame_deadline() const { |
155 return posted_begin_impl_frame_deadline_; | 84 return posted_begin_impl_frame_deadline_; |
156 } | 85 } |
157 | 86 |
158 FakeExternalBeginFrameSource* fake_external_begin_frame_source() const { | |
159 return fake_external_begin_frame_source_; | |
160 } | |
161 | |
162 base::PowerMonitor* PowerMonitor() { return &power_monitor_; } | |
163 | |
164 FakePowerMonitorSource* PowerMonitorSource() { | |
165 return fake_power_monitor_source_; | |
166 } | |
167 | |
168 // As this function contains EXPECT macros, to allow debugging it should be | |
169 // called inside EXPECT_SCOPED like so; | |
170 // EXPECT_SCOPED(client.InitializeOutputSurfaceAndFirstCommit(scheduler)); | |
171 void InitializeOutputSurfaceAndFirstCommit(TestScheduler* scheduler) { | |
172 TRACE_EVENT0("cc", | |
173 "SchedulerUnitTest::InitializeOutputSurfaceAndFirstCommit"); | |
174 DCHECK(scheduler); | |
175 | |
176 // Check the client doesn't have any actions queued when calling this | |
177 // function. | |
178 EXPECT_NO_ACTION((*this)); | |
179 EXPECT_FALSE(needs_begin_frames()); | |
180 | |
181 // Start the initial output surface creation. | |
182 EXPECT_FALSE(scheduler->CanStart()); | |
183 scheduler->SetCanStart(); | |
184 scheduler->SetVisible(true); | |
185 scheduler->SetCanDraw(true); | |
186 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", (*this)); | |
187 Reset(); | |
188 | |
189 // We don't see anything happening until the first impl frame. | |
190 scheduler->DidCreateAndInitializeOutputSurface(); | |
191 scheduler->SetNeedsCommit(); | |
192 EXPECT_TRUE(needs_begin_frames()); | |
193 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | |
194 Reset(); | |
195 | |
196 { | |
197 SCOPED_TRACE("Do first frame to commit after initialize."); | |
198 AdvanceFrame(); | |
199 | |
200 scheduler->NotifyBeginMainFrameStarted(); | |
201 scheduler->NotifyReadyToCommitThenActivateIfNeeded(); | |
202 | |
203 // Run the posted deadline task. | |
204 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | |
205 task_runner().RunTasksWhile(ImplFrameDeadlinePending(true)); | |
206 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | |
207 | |
208 EXPECT_FALSE(scheduler->CommitPending()); | |
209 } | |
210 | |
211 Reset(); | |
212 | |
213 { | |
214 SCOPED_TRACE( | |
215 "Run second frame so Scheduler calls SetNeedsBeginFrame(false)."); | |
216 AdvanceFrame(); | |
217 | |
218 // Run the posted deadline task. | |
219 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | |
220 task_runner().RunTasksWhile(ImplFrameDeadlinePending(true)); | |
221 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | |
222 } | |
223 | |
224 EXPECT_FALSE(needs_begin_frames()); | |
225 Reset(); | |
226 } | |
227 | |
228 // As this function contains EXPECT macros, to allow debugging it should be | |
229 // called inside EXPECT_SCOPED like so; | |
230 // EXPECT_SCOPED(client.AdvanceFrame()); | |
231 void AdvanceFrame() { | |
232 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug.scheduler.frames"), | |
233 "FakeSchedulerClient::AdvanceFrame"); | |
234 // Consume any previous deadline first, if no deadline is currently | |
235 // pending, ImplFrameDeadlinePending will return false straight away and we | |
236 // will run no tasks. | |
237 task_runner().RunTasksWhile(ImplFrameDeadlinePending(true)); | |
238 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | |
239 | |
240 // Send the next BeginFrame message if using an external source, otherwise | |
241 // it will be already in the task queue. | |
242 if (scheduler_->settings().use_external_begin_frame_source && | |
243 scheduler_->FrameProductionThrottled()) { | |
244 SendNextBeginFrame(); | |
245 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | |
246 } | |
247 | |
248 // Then run tasks until new deadline is scheduled. | |
249 EXPECT_TRUE(task_runner().RunTasksWhile(ImplFrameDeadlinePending(false))); | |
250 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | |
251 } | |
252 | |
253 void SendNextBeginFrame() { | |
254 DCHECK(scheduler_->settings().use_external_begin_frame_source); | |
255 // Creep the time forward so that any BeginFrameArgs is not equal to the | |
256 // last one otherwise we violate the BeginFrameSource contract. | |
257 now_src_->AdvanceNow(BeginFrameArgs::DefaultInterval()); | |
258 fake_external_begin_frame_source_->TestOnBeginFrame( | |
259 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, now_src_)); | |
260 } | |
261 | |
262 OrderedSimpleTaskRunner& task_runner() { return *task_runner_; } | |
263 TestNowSource* now_src() { return now_src_.get(); } | |
264 | |
265 int ActionIndex(const char* action) const { | 87 int ActionIndex(const char* action) const { |
266 for (size_t i = 0; i < actions_.size(); i++) | 88 for (size_t i = 0; i < actions_.size(); i++) |
267 if (!strcmp(actions_[i], action)) | 89 if (!strcmp(actions_[i], action)) |
268 return i; | 90 return i; |
269 return -1; | 91 return -1; |
270 } | 92 } |
271 | 93 |
272 bool HasAction(const char* action) const { | 94 bool HasAction(const char* action) const { |
273 return ActionIndex(action) >= 0; | 95 return ActionIndex(action) >= 0; |
274 } | 96 } |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
342 base::Callback<bool(void)> ImplFrameDeadlinePending(bool state) { | 164 base::Callback<bool(void)> ImplFrameDeadlinePending(bool state) { |
343 return base::Bind(&FakeSchedulerClient::ImplFrameDeadlinePendingCallback, | 165 return base::Bind(&FakeSchedulerClient::ImplFrameDeadlinePendingCallback, |
344 base::Unretained(this), | 166 base::Unretained(this), |
345 state); | 167 state); |
346 } | 168 } |
347 | 169 |
348 bool begin_frame_is_sent_to_children() const { | 170 bool begin_frame_is_sent_to_children() const { |
349 return begin_frame_is_sent_to_children_; | 171 return begin_frame_is_sent_to_children_; |
350 } | 172 } |
351 | 173 |
174 void PushAction(const char* description) { | |
175 actions_.push_back(description); | |
176 states_.push_back(scheduler_->AsValue()); | |
177 } | |
178 | |
352 protected: | 179 protected: |
353 bool ImplFrameDeadlinePendingCallback(bool state) { | 180 bool ImplFrameDeadlinePendingCallback(bool state) { |
354 return scheduler_->BeginImplFrameDeadlinePending() == state; | 181 return scheduler_->BeginImplFrameDeadlinePending() == state; |
355 } | 182 } |
356 | 183 |
357 void PushAction(const char* description) { | |
358 actions_.push_back(description); | |
359 states_.push_back(scheduler_->AsValue()); | |
360 } | |
361 | |
362 bool draw_will_happen_; | 184 bool draw_will_happen_; |
363 bool swap_will_happen_if_draw_happens_; | 185 bool swap_will_happen_if_draw_happens_; |
364 bool automatic_swap_ack_; | 186 bool automatic_swap_ack_; |
365 int num_draws_; | 187 int num_draws_; |
366 bool log_anticipated_draw_time_change_; | 188 bool log_anticipated_draw_time_change_; |
367 bool begin_frame_is_sent_to_children_; | 189 bool begin_frame_is_sent_to_children_; |
368 base::TimeTicks posted_begin_impl_frame_deadline_; | 190 base::TimeTicks posted_begin_impl_frame_deadline_; |
369 std::vector<const char*> actions_; | 191 std::vector<const char*> actions_; |
370 std::vector<scoped_refptr<base::debug::ConvertableToTraceFormat>> states_; | 192 std::vector<scoped_refptr<base::debug::ConvertableToTraceFormat>> states_; |
193 TestScheduler* scheduler_; | |
194 }; | |
195 | |
196 class FakePowerMonitorSource : public base::PowerMonitorSource { | |
197 public: | |
198 FakePowerMonitorSource() {} | |
199 ~FakePowerMonitorSource() override {} | |
200 void GeneratePowerStateEvent(bool on_battery_power) { | |
201 on_battery_power_impl_ = on_battery_power; | |
202 ProcessPowerEvent(POWER_STATE_EVENT); | |
203 base::MessageLoop::current()->RunUntilIdle(); | |
204 } | |
205 bool IsOnBatteryPowerImpl() override { return on_battery_power_impl_; } | |
206 | |
207 private: | |
208 bool on_battery_power_impl_; | |
209 }; | |
210 | |
211 class FakeExternalBeginFrameSource : public BeginFrameSourceMixIn { | |
212 public: | |
213 explicit FakeExternalBeginFrameSource(FakeSchedulerClient* client) | |
214 : client_(client) {} | |
215 ~FakeExternalBeginFrameSource() override {} | |
216 | |
217 void OnNeedsBeginFramesChange(bool needs_begin_frames) override { | |
218 if (needs_begin_frames) { | |
219 client_->PushAction("SetNeedsBeginFrames(true)"); | |
220 } else { | |
221 client_->PushAction("SetNeedsBeginFrames(false)"); | |
222 } | |
223 } | |
224 | |
225 void TestOnBeginFrame(const BeginFrameArgs& args) { | |
226 return CallOnBeginFrame(args); | |
227 } | |
228 | |
229 private: | |
230 FakeSchedulerClient* client_; | |
231 }; | |
232 | |
233 class SchedulerTest : public testing::Test { | |
234 public: | |
235 SchedulerTest() | |
236 : now_src_(TestNowSource::Create()), | |
237 task_runner_(new OrderedSimpleTaskRunner(now_src_, true)), | |
238 fake_external_begin_frame_source_(nullptr), | |
239 fake_power_monitor_source_(new FakePowerMonitorSource), | |
240 power_monitor_(make_scoped_ptr<base::PowerMonitorSource>( | |
241 fake_power_monitor_source_)) { | |
242 // A bunch of tests require Now() to be > BeginFrameArgs::DefaultInterval() | |
243 now_src_->AdvanceNow(base::TimeDelta::FromMilliseconds(100)); | |
244 // Fail if we need to run 100 tasks in a row. | |
245 task_runner_->SetRunTaskLimit(100); | |
246 } | |
247 | |
248 ~SchedulerTest() override {} | |
249 | |
250 protected: | |
251 TestScheduler* CreateScheduler() { | |
252 scoped_ptr<FakeExternalBeginFrameSource> fake_external_begin_frame_source; | |
253 if (scheduler_settings_.use_external_begin_frame_source) { | |
254 fake_external_begin_frame_source.reset( | |
255 new FakeExternalBeginFrameSource(client_.get())); | |
256 fake_external_begin_frame_source_ = | |
257 fake_external_begin_frame_source.get(); | |
258 } | |
259 scheduler_ = TestScheduler::Create( | |
260 now_src_, client_.get(), scheduler_settings_, 0, task_runner_, | |
261 &power_monitor_, fake_external_begin_frame_source.Pass()); | |
262 DCHECK(scheduler_); | |
263 client_->set_scheduler(scheduler_.get()); | |
264 return scheduler_.get(); | |
265 } | |
266 | |
267 void CreateSchedulerAndInitSurface() { | |
268 CreateScheduler(); | |
269 EXPECT_SCOPED(InitializeOutputSurfaceAndFirstCommit()); | |
270 } | |
271 | |
272 void SetUpScheduler(bool initSurface) { | |
273 SetUpScheduler(make_scoped_ptr(new FakeSchedulerClient), initSurface); | |
274 } | |
275 | |
276 void SetUpScheduler(scoped_ptr<FakeSchedulerClient> client, | |
277 bool initSurface) { | |
278 client_ = client.Pass(); | |
279 if (initSurface) | |
280 CreateSchedulerAndInitSurface(); | |
281 else | |
282 CreateScheduler(); | |
283 } | |
284 | |
285 OrderedSimpleTaskRunner& task_runner() { return *task_runner_; } | |
286 TestNowSource* now_src() { return now_src_.get(); } | |
287 | |
288 // As this function contains EXPECT macros, to allow debugging it should be | |
289 // called inside EXPECT_SCOPED like so; | |
290 // EXPECT_SCOPED(client.InitializeOutputSurfaceAndFirstCommit(scheduler)); | |
291 void InitializeOutputSurfaceAndFirstCommit() { | |
292 TRACE_EVENT0("cc", | |
293 "SchedulerUnitTest::InitializeOutputSurfaceAndFirstCommit"); | |
294 DCHECK(scheduler_); | |
295 | |
296 // Check the client doesn't have any actions queued when calling this | |
297 // function. | |
298 EXPECT_NO_ACTION(client_); | |
299 EXPECT_FALSE(client_->needs_begin_frames()); | |
300 | |
301 // Start the initial output surface creation. | |
302 EXPECT_FALSE(scheduler_->CanStart()); | |
303 scheduler_->SetCanStart(); | |
304 scheduler_->SetVisible(true); | |
305 scheduler_->SetCanDraw(true); | |
306 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client_); | |
307 | |
308 client_->Reset(); | |
309 | |
310 // We don't see anything happening until the first impl frame. | |
311 scheduler_->DidCreateAndInitializeOutputSurface(); | |
312 scheduler_->SetNeedsCommit(); | |
313 EXPECT_TRUE(client_->needs_begin_frames()); | |
314 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | |
315 client_->Reset(); | |
316 | |
317 { | |
318 SCOPED_TRACE("Do first frame to commit after initialize."); | |
319 AdvanceFrame(); | |
320 | |
321 scheduler_->NotifyBeginMainFrameStarted(); | |
322 scheduler_->NotifyReadyToCommitThenActivateIfNeeded(); | |
323 | |
324 // Run the posted deadline task. | |
325 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | |
326 task_runner_->RunTasksWhile(client_->ImplFrameDeadlinePending(true)); | |
327 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | |
328 | |
329 EXPECT_FALSE(scheduler_->CommitPending()); | |
330 } | |
331 | |
332 client_->Reset(); | |
333 | |
334 { | |
335 SCOPED_TRACE( | |
336 "Run second frame so Scheduler calls SetNeedsBeginFrame(false)."); | |
337 AdvanceFrame(); | |
338 | |
339 // Run the posted deadline task. | |
340 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | |
341 task_runner_->RunTasksWhile(client_->ImplFrameDeadlinePending(true)); | |
342 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | |
343 } | |
344 | |
345 EXPECT_FALSE(client_->needs_begin_frames()); | |
346 client_->Reset(); | |
347 } | |
348 | |
349 // As this function contains EXPECT macros, to allow debugging it should be | |
350 // called inside EXPECT_SCOPED like so; | |
351 // EXPECT_SCOPED(client.AdvanceFrame()); | |
352 void AdvanceFrame() { | |
353 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug.scheduler.frames"), | |
354 "FakeSchedulerClient::AdvanceFrame"); | |
355 // Consume any previous deadline first, if no deadline is currently | |
356 // pending, ImplFrameDeadlinePending will return false straight away and we | |
357 // will run no tasks. | |
358 task_runner_->RunTasksWhile(client_->ImplFrameDeadlinePending(true)); | |
359 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | |
360 | |
361 // Send the next BeginFrame message if using an external source, otherwise | |
362 // it will be already in the task queue. | |
363 if (scheduler_->settings().use_external_begin_frame_source && | |
364 scheduler_->FrameProductionThrottled()) { | |
365 SendNextBeginFrame(); | |
366 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | |
367 } | |
368 | |
369 // Then run tasks until new deadline is scheduled. | |
370 EXPECT_TRUE( | |
371 task_runner_->RunTasksWhile(client_->ImplFrameDeadlinePending(false))); | |
372 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | |
373 } | |
374 | |
375 void SendNextBeginFrame() { | |
376 DCHECK(scheduler_->settings().use_external_begin_frame_source); | |
377 // Creep the time forward so that any BeginFrameArgs is not equal to the | |
378 // last one otherwise we violate the BeginFrameSource contract. | |
379 now_src_->AdvanceNow(BeginFrameArgs::DefaultInterval()); | |
380 fake_external_begin_frame_source_->TestOnBeginFrame( | |
381 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, now_src())); | |
382 } | |
383 | |
384 base::PowerMonitor* PowerMonitor() { return &power_monitor_; } | |
385 FakePowerMonitorSource* PowerMonitorSource() { | |
386 return fake_power_monitor_source_; | |
387 } | |
388 | |
389 FakeExternalBeginFrameSource* fake_external_begin_frame_source() const { | |
390 return fake_external_begin_frame_source_; | |
391 } | |
392 | |
393 void MainFrameInHighLatencyMode( | |
394 int64 begin_main_frame_to_commit_estimate_in_ms, | |
395 int64 commit_to_activate_estimate_in_ms, | |
396 bool impl_latency_takes_priority, | |
397 bool should_send_begin_main_frame); | |
398 void BeginFramesNotFromClient(bool use_external_begin_frame_source, | |
399 bool throttle_frame_production); | |
400 void BeginFramesNotFromClient_SwapThrottled( | |
401 bool use_external_begin_frame_source, | |
402 bool throttle_frame_production); | |
403 void DidLoseOutputSurfaceAfterBeginFrameStartedWithHighLatency( | |
404 bool impl_side_painting); | |
405 void DidLoseOutputSurfaceAfterReadyToCommit(bool impl_side_painting); | |
406 | |
371 scoped_refptr<TestNowSource> now_src_; | 407 scoped_refptr<TestNowSource> now_src_; |
372 scoped_refptr<OrderedSimpleTaskRunner> task_runner_; | 408 scoped_refptr<OrderedSimpleTaskRunner> task_runner_; |
373 FakeExternalBeginFrameSource* fake_external_begin_frame_source_; | 409 FakeExternalBeginFrameSource* fake_external_begin_frame_source_; |
374 FakePowerMonitorSource* fake_power_monitor_source_; | 410 FakePowerMonitorSource* fake_power_monitor_source_; |
375 base::PowerMonitor power_monitor_; | 411 base::PowerMonitor power_monitor_; |
412 SchedulerSettings scheduler_settings_; | |
413 scoped_ptr<FakeSchedulerClient> client_; | |
376 scoped_ptr<TestScheduler> scheduler_; | 414 scoped_ptr<TestScheduler> scheduler_; |
377 }; | 415 }; |
378 | 416 |
379 TEST(SchedulerTest, InitializeOutputSurfaceDoesNotBeginImplFrame) { | 417 TEST_F(SchedulerTest, InitializeOutputSurfaceDoesNotBeginImplFrame) { |
380 FakeSchedulerClient client; | 418 scheduler_settings_.use_external_begin_frame_source = true; |
381 SchedulerSettings scheduler_settings; | 419 SetUpScheduler(false); |
382 scheduler_settings.use_external_begin_frame_source = true; | 420 scheduler_->SetCanStart(); |
383 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings); | 421 scheduler_->SetVisible(true); |
384 scheduler->SetCanStart(); | 422 scheduler_->SetCanDraw(true); |
385 scheduler->SetVisible(true); | 423 |
386 scheduler->SetCanDraw(true); | 424 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client_); |
387 | 425 client_->Reset(); |
388 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); | 426 scheduler_->DidCreateAndInitializeOutputSurface(); |
389 client.Reset(); | 427 EXPECT_NO_ACTION(client_); |
390 scheduler->DidCreateAndInitializeOutputSurface(); | |
391 EXPECT_NO_ACTION(client); | |
392 } | 428 } |
393 | 429 |
394 TEST(SchedulerTest, SendBeginFramesToChildren) { | 430 TEST_F(SchedulerTest, SendBeginFramesToChildren) { |
395 FakeSchedulerClient client; | 431 scheduler_settings_.use_external_begin_frame_source = true; |
396 SchedulerSettings scheduler_settings; | 432 scheduler_settings_.forward_begin_frames_to_children = true; |
397 scheduler_settings.use_external_begin_frame_source = true; | 433 SetUpScheduler(true); |
398 scheduler_settings.forward_begin_frames_to_children = true; | 434 |
399 | 435 EXPECT_FALSE(client_->begin_frame_is_sent_to_children()); |
400 CREATE_SCHEDULER_AND_INIT_SURFACE(scheduler_settings); | 436 scheduler_->SetNeedsCommit(); |
401 | 437 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client_); |
402 EXPECT_FALSE(client.begin_frame_is_sent_to_children()); | 438 EXPECT_TRUE(client_->needs_begin_frames()); |
403 scheduler->SetNeedsCommit(); | 439 |
404 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client); | 440 scheduler_->SetChildrenNeedBeginFrames(true); |
405 EXPECT_TRUE(client.needs_begin_frames()); | 441 |
406 | 442 client_->Reset(); |
407 scheduler->SetChildrenNeedBeginFrames(true); | 443 EXPECT_SCOPED(AdvanceFrame()); |
408 | 444 EXPECT_TRUE(client_->begin_frame_is_sent_to_children()); |
409 client.Reset(); | 445 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
410 EXPECT_SCOPED(client.AdvanceFrame()); | 446 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
411 EXPECT_TRUE(client.begin_frame_is_sent_to_children()); | 447 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); |
412 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 448 EXPECT_TRUE(client_->needs_begin_frames()); |
413 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | |
414 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); | |
415 EXPECT_TRUE(client.needs_begin_frames()); | |
416 } | 449 } |
417 | 450 |
418 TEST(SchedulerTest, SendBeginFramesToChildrenWithoutCommit) { | 451 TEST_F(SchedulerTest, SendBeginFramesToChildrenWithoutCommit) { |
419 FakeSchedulerClient client; | 452 scheduler_settings_.use_external_begin_frame_source = true; |
420 SchedulerSettings scheduler_settings; | 453 scheduler_settings_.forward_begin_frames_to_children = true; |
421 scheduler_settings.use_external_begin_frame_source = true; | 454 SetUpScheduler(true); |
422 scheduler_settings.forward_begin_frames_to_children = true; | 455 |
423 | 456 EXPECT_FALSE(client_->needs_begin_frames()); |
424 CREATE_SCHEDULER_AND_INIT_SURFACE(scheduler_settings); | 457 scheduler_->SetChildrenNeedBeginFrames(true); |
425 | 458 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client_); |
426 EXPECT_FALSE(client.needs_begin_frames()); | 459 EXPECT_TRUE(client_->needs_begin_frames()); |
427 scheduler->SetChildrenNeedBeginFrames(true); | 460 |
428 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client); | 461 client_->Reset(); |
429 EXPECT_TRUE(client.needs_begin_frames()); | 462 EXPECT_SCOPED(AdvanceFrame()); |
430 | 463 EXPECT_TRUE(client_->begin_frame_is_sent_to_children()); |
431 client.Reset(); | |
432 EXPECT_SCOPED(client.AdvanceFrame()); | |
433 EXPECT_TRUE(client.begin_frame_is_sent_to_children()); | |
434 } | 464 } |
435 | 465 |
436 TEST(SchedulerTest, RequestCommit) { | 466 TEST_F(SchedulerTest, RequestCommit) { |
437 FakeSchedulerClient client; | 467 scheduler_settings_.use_external_begin_frame_source = true; |
438 SchedulerSettings scheduler_settings; | 468 SetUpScheduler(true); |
439 scheduler_settings.use_external_begin_frame_source = true; | |
440 | |
441 CREATE_SCHEDULER_AND_INIT_SURFACE(scheduler_settings); | |
442 | 469 |
443 // SetNeedsCommit should begin the frame on the next BeginImplFrame. | 470 // SetNeedsCommit should begin the frame on the next BeginImplFrame. |
444 scheduler->SetNeedsCommit(); | 471 scheduler_->SetNeedsCommit(); |
445 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client); | 472 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client_); |
446 client.Reset(); | 473 client_->Reset(); |
447 | 474 |
448 EXPECT_SCOPED(client.AdvanceFrame()); | 475 EXPECT_SCOPED(AdvanceFrame()); |
449 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 476 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
450 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); | 477 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); |
451 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 478 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
452 EXPECT_TRUE(client.needs_begin_frames()); | 479 EXPECT_TRUE(client_->needs_begin_frames()); |
453 client.Reset(); | 480 client_->Reset(); |
454 | 481 |
455 // If we don't swap on the deadline, we wait for the next BeginFrame. | 482 // If we don't swap on the deadline, we wait for the next BeginFrame. |
456 client.task_runner().RunPendingTasks(); // Run posted deadline. | 483 task_runner().RunPendingTasks(); // Run posted deadline. |
457 EXPECT_NO_ACTION(client); | 484 EXPECT_NO_ACTION(client_); |
458 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 485 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); |
459 EXPECT_TRUE(client.needs_begin_frames()); | 486 EXPECT_TRUE(client_->needs_begin_frames()); |
460 client.Reset(); | 487 client_->Reset(); |
461 | 488 |
462 // NotifyReadyToCommit should trigger the commit. | 489 // NotifyReadyToCommit should trigger the commit. |
463 scheduler->NotifyBeginMainFrameStarted(); | 490 scheduler_->NotifyBeginMainFrameStarted(); |
464 scheduler->NotifyReadyToCommit(); | 491 scheduler_->NotifyReadyToCommit(); |
465 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); | 492 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_); |
466 EXPECT_TRUE(client.needs_begin_frames()); | 493 EXPECT_TRUE(client_->needs_begin_frames()); |
467 client.Reset(); | 494 client_->Reset(); |
468 | 495 |
469 // BeginImplFrame should prepare the draw. | 496 // BeginImplFrame should prepare the draw. |
470 EXPECT_SCOPED(client.AdvanceFrame()); | 497 EXPECT_SCOPED(AdvanceFrame()); |
471 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 498 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
472 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); | 499 EXPECT_ACTION("ScheduledActionAnimate", client_, 1, 2); |
473 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 500 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
474 EXPECT_TRUE(client.needs_begin_frames()); | 501 EXPECT_TRUE(client_->needs_begin_frames()); |
475 client.Reset(); | 502 client_->Reset(); |
476 | 503 |
477 // BeginImplFrame deadline should draw. | 504 // BeginImplFrame deadline should draw. |
478 client.task_runner().RunPendingTasks(); // Run posted deadline. | 505 task_runner().RunPendingTasks(); // Run posted deadline. |
479 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 1); | 506 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 0, 1); |
480 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 507 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); |
481 EXPECT_TRUE(client.needs_begin_frames()); | 508 EXPECT_TRUE(client_->needs_begin_frames()); |
482 client.Reset(); | 509 client_->Reset(); |
483 | 510 |
484 // The following BeginImplFrame deadline should SetNeedsBeginFrame(false) | 511 // The following BeginImplFrame deadline should SetNeedsBeginFrame(false) |
485 // to avoid excessive toggles. | 512 // to avoid excessive toggles. |
486 EXPECT_SCOPED(client.AdvanceFrame()); | 513 EXPECT_SCOPED(AdvanceFrame()); |
487 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); | 514 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client_); |
488 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 515 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
489 client.Reset(); | 516 client_->Reset(); |
490 | 517 |
491 client.task_runner().RunPendingTasks(); // Run posted deadline. | 518 task_runner().RunPendingTasks(); // Run posted deadline. |
492 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(false)", client); | 519 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(false)", client_); |
493 client.Reset(); | 520 client_->Reset(); |
494 } | 521 } |
495 | 522 |
496 TEST(SchedulerTest, RequestCommitAfterBeginMainFrameSent) { | 523 TEST_F(SchedulerTest, RequestCommitAfterBeginMainFrameSent) { |
497 FakeSchedulerClient client; | 524 scheduler_settings_.use_external_begin_frame_source = true; |
498 SchedulerSettings scheduler_settings; | 525 SetUpScheduler(true); |
499 scheduler_settings.use_external_begin_frame_source = true; | |
500 | |
501 CREATE_SCHEDULER_AND_INIT_SURFACE(scheduler_settings); | |
502 | 526 |
503 // SetNeedsCommit should begin the frame. | 527 // SetNeedsCommit should begin the frame. |
504 scheduler->SetNeedsCommit(); | 528 scheduler_->SetNeedsCommit(); |
505 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client); | 529 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client_); |
506 | 530 |
507 client.Reset(); | 531 client_->Reset(); |
508 EXPECT_SCOPED(client.AdvanceFrame()); | 532 EXPECT_SCOPED(AdvanceFrame()); |
509 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 533 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
510 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); | 534 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); |
511 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 535 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
512 | 536 |
513 EXPECT_TRUE(client.needs_begin_frames()); | 537 EXPECT_TRUE(client_->needs_begin_frames()); |
514 client.Reset(); | 538 client_->Reset(); |
515 | 539 |
516 // Now SetNeedsCommit again. Calling here means we need a second commit. | 540 // Now SetNeedsCommit again. Calling here means we need a second commit. |
517 scheduler->SetNeedsCommit(); | 541 scheduler_->SetNeedsCommit(); |
518 EXPECT_EQ(client.num_actions_(), 0); | 542 EXPECT_EQ(client_->num_actions_(), 0); |
519 client.Reset(); | 543 client_->Reset(); |
520 | 544 |
521 // Finish the first commit. | 545 // Finish the first commit. |
522 scheduler->NotifyBeginMainFrameStarted(); | 546 scheduler_->NotifyBeginMainFrameStarted(); |
523 scheduler->NotifyReadyToCommit(); | 547 scheduler_->NotifyReadyToCommit(); |
524 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); | 548 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_); |
525 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 549 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
526 client.Reset(); | 550 client_->Reset(); |
527 client.task_runner().RunPendingTasks(); // Run posted deadline. | 551 task_runner().RunPendingTasks(); // Run posted deadline. |
528 EXPECT_ACTION("ScheduledActionAnimate", client, 0, 2); | 552 EXPECT_ACTION("ScheduledActionAnimate", client_, 0, 2); |
529 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 1, 2); | 553 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 1, 2); |
530 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 554 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); |
531 | 555 |
532 // Because we just swapped, the Scheduler should also request the next | 556 // Because we just swapped, the Scheduler should also request the next |
533 // BeginImplFrame from the OutputSurface. | 557 // BeginImplFrame from the OutputSurface. |
534 EXPECT_TRUE(client.needs_begin_frames()); | 558 EXPECT_TRUE(client_->needs_begin_frames()); |
535 client.Reset(); | 559 client_->Reset(); |
536 // Since another commit is needed, the next BeginImplFrame should initiate | 560 // Since another commit is needed, the next BeginImplFrame should initiate |
537 // the second commit. | 561 // the second commit. |
538 EXPECT_SCOPED(client.AdvanceFrame()); | 562 EXPECT_SCOPED(AdvanceFrame()); |
539 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 563 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
540 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); | 564 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); |
541 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 565 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
542 client.Reset(); | 566 client_->Reset(); |
543 | 567 |
544 // Finishing the commit before the deadline should post a new deadline task | 568 // Finishing the commit before the deadline should post a new deadline task |
545 // to trigger the deadline early. | 569 // to trigger the deadline early. |
546 scheduler->NotifyBeginMainFrameStarted(); | 570 scheduler_->NotifyBeginMainFrameStarted(); |
547 scheduler->NotifyReadyToCommit(); | 571 scheduler_->NotifyReadyToCommit(); |
548 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); | 572 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_); |
549 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 573 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
550 client.Reset(); | 574 client_->Reset(); |
551 client.task_runner().RunPendingTasks(); // Run posted deadline. | 575 task_runner().RunPendingTasks(); // Run posted deadline. |
552 EXPECT_ACTION("ScheduledActionAnimate", client, 0, 2); | 576 EXPECT_ACTION("ScheduledActionAnimate", client_, 0, 2); |
553 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 1, 2); | 577 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 1, 2); |
554 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 578 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); |
555 EXPECT_TRUE(client.needs_begin_frames()); | 579 EXPECT_TRUE(client_->needs_begin_frames()); |
556 client.Reset(); | 580 client_->Reset(); |
557 | 581 |
558 // On the next BeginImplFrame, verify we go back to a quiescent state and | 582 // On the next BeginImplFrame, verify we go back to a quiescent state and |
559 // no longer request BeginImplFrames. | 583 // no longer request BeginImplFrames. |
560 EXPECT_SCOPED(client.AdvanceFrame()); | 584 EXPECT_SCOPED(AdvanceFrame()); |
561 client.task_runner().RunPendingTasks(); // Run posted deadline. | 585 task_runner().RunPendingTasks(); // Run posted deadline. |
562 EXPECT_FALSE(client.needs_begin_frames()); | 586 EXPECT_FALSE(client_->needs_begin_frames()); |
563 client.Reset(); | 587 client_->Reset(); |
564 } | 588 } |
565 | 589 |
566 class SchedulerClientThatsetNeedsDrawInsideDraw : public FakeSchedulerClient { | 590 class SchedulerClientThatsetNeedsDrawInsideDraw : public FakeSchedulerClient { |
567 public: | 591 public: |
568 SchedulerClientThatsetNeedsDrawInsideDraw() | 592 SchedulerClientThatsetNeedsDrawInsideDraw() |
569 : FakeSchedulerClient(), request_redraws_(false) {} | 593 : FakeSchedulerClient(), request_redraws_(false) {} |
570 | 594 |
571 void ScheduledActionSendBeginMainFrame() override {} | 595 void ScheduledActionSendBeginMainFrame() override {} |
572 | 596 |
573 void SetRequestRedrawsInsideDraw(bool enable) { request_redraws_ = enable; } | 597 void SetRequestRedrawsInsideDraw(bool enable) { request_redraws_ = enable; } |
(...skipping 15 matching lines...) Expand all Loading... | |
589 void DidAnticipatedDrawTimeChange(base::TimeTicks) override {} | 613 void DidAnticipatedDrawTimeChange(base::TimeTicks) override {} |
590 | 614 |
591 private: | 615 private: |
592 bool request_redraws_; | 616 bool request_redraws_; |
593 }; | 617 }; |
594 | 618 |
595 // Tests for two different situations: | 619 // Tests for two different situations: |
596 // 1. the scheduler dropping SetNeedsRedraw requests that happen inside | 620 // 1. the scheduler dropping SetNeedsRedraw requests that happen inside |
597 // a ScheduledActionDrawAndSwap | 621 // a ScheduledActionDrawAndSwap |
598 // 2. the scheduler drawing twice inside a single tick | 622 // 2. the scheduler drawing twice inside a single tick |
599 TEST(SchedulerTest, RequestRedrawInsideDraw) { | 623 TEST_F(SchedulerTest, RequestRedrawInsideDraw) { |
600 SchedulerClientThatsetNeedsDrawInsideDraw client; | 624 scoped_ptr<SchedulerClientThatsetNeedsDrawInsideDraw> client = |
601 SchedulerSettings scheduler_settings; | 625 make_scoped_ptr(new SchedulerClientThatsetNeedsDrawInsideDraw); |
602 scheduler_settings.use_external_begin_frame_source = true; | 626 SchedulerClientThatsetNeedsDrawInsideDraw* client_ptr = client.get(); |
627 scheduler_settings_.use_external_begin_frame_source = true; | |
628 SetUpScheduler(client.Pass(), true); | |
629 client_ptr->SetRequestRedrawsInsideDraw(true); | |
603 | 630 |
604 CREATE_SCHEDULER_AND_INIT_SURFACE(scheduler_settings); | 631 scheduler_->SetNeedsRedraw(); |
605 client.SetRequestRedrawsInsideDraw(true); | 632 EXPECT_TRUE(scheduler_->RedrawPending()); |
633 EXPECT_TRUE(client_ptr->needs_begin_frames()); | |
634 EXPECT_EQ(0, client_ptr->num_draws()); | |
606 | 635 |
607 scheduler->SetNeedsRedraw(); | 636 EXPECT_SCOPED(AdvanceFrame()); |
608 EXPECT_TRUE(scheduler->RedrawPending()); | 637 task_runner().RunPendingTasks(); // Run posted deadline. |
609 EXPECT_TRUE(client.needs_begin_frames()); | 638 EXPECT_EQ(1, client_ptr->num_draws()); |
610 EXPECT_EQ(0, client.num_draws()); | 639 EXPECT_TRUE(scheduler_->RedrawPending()); |
640 EXPECT_TRUE(client_ptr->needs_begin_frames()); | |
611 | 641 |
612 EXPECT_SCOPED(client.AdvanceFrame()); | 642 client_ptr->SetRequestRedrawsInsideDraw(false); |
613 client.task_runner().RunPendingTasks(); // Run posted deadline. | |
614 EXPECT_EQ(1, client.num_draws()); | |
615 EXPECT_TRUE(scheduler->RedrawPending()); | |
616 EXPECT_TRUE(client.needs_begin_frames()); | |
617 | 643 |
618 client.SetRequestRedrawsInsideDraw(false); | 644 EXPECT_SCOPED(AdvanceFrame()); |
619 | 645 task_runner().RunPendingTasks(); // Run posted deadline. |
620 EXPECT_SCOPED(client.AdvanceFrame()); | 646 EXPECT_EQ(2, client_ptr->num_draws()); |
621 client.task_runner().RunPendingTasks(); // Run posted deadline. | 647 EXPECT_FALSE(scheduler_->RedrawPending()); |
622 EXPECT_EQ(2, client.num_draws()); | 648 EXPECT_TRUE(client_ptr->needs_begin_frames()); |
623 EXPECT_FALSE(scheduler->RedrawPending()); | |
624 EXPECT_TRUE(client.needs_begin_frames()); | |
625 | 649 |
626 // We stop requesting BeginImplFrames after a BeginImplFrame where we don't | 650 // We stop requesting BeginImplFrames after a BeginImplFrame where we don't |
627 // swap. | 651 // swap. |
628 EXPECT_SCOPED(client.AdvanceFrame()); | 652 EXPECT_SCOPED(AdvanceFrame()); |
629 client.task_runner().RunPendingTasks(); // Run posted deadline. | 653 task_runner().RunPendingTasks(); // Run posted deadline. |
630 EXPECT_EQ(2, client.num_draws()); | 654 EXPECT_EQ(2, client_ptr->num_draws()); |
631 EXPECT_FALSE(scheduler->RedrawPending()); | 655 EXPECT_FALSE(scheduler_->RedrawPending()); |
632 EXPECT_FALSE(client.needs_begin_frames()); | 656 EXPECT_FALSE(client_ptr->needs_begin_frames()); |
633 } | 657 } |
634 | 658 |
635 // Test that requesting redraw inside a failed draw doesn't lose the request. | 659 // Test that requesting redraw inside a failed draw doesn't lose the request. |
636 TEST(SchedulerTest, RequestRedrawInsideFailedDraw) { | 660 TEST_F(SchedulerTest, RequestRedrawInsideFailedDraw) { |
637 SchedulerClientThatsetNeedsDrawInsideDraw client; | 661 scoped_ptr<SchedulerClientThatsetNeedsDrawInsideDraw> client = |
brianderson
2015/01/28 03:32:42
Hmm, this is a bit verbose. Does the following wor
Jimmy Jo
2015/01/28 05:01:07
Done.
| |
638 SchedulerSettings scheduler_settings; | 662 make_scoped_ptr(new SchedulerClientThatsetNeedsDrawInsideDraw); |
639 scheduler_settings.use_external_begin_frame_source = true; | 663 SchedulerClientThatsetNeedsDrawInsideDraw* client_ptr = client.get(); |
664 scheduler_settings_.use_external_begin_frame_source = true; | |
665 SetUpScheduler(client.Pass(), true); | |
640 | 666 |
641 CREATE_SCHEDULER_AND_INIT_SURFACE(scheduler_settings); | 667 client_ptr->SetRequestRedrawsInsideDraw(true); |
642 client.SetRequestRedrawsInsideDraw(true); | 668 client_ptr->SetDrawWillHappen(false); |
643 client.SetDrawWillHappen(false); | |
644 | 669 |
645 scheduler->SetNeedsRedraw(); | 670 scheduler_->SetNeedsRedraw(); |
646 EXPECT_TRUE(scheduler->RedrawPending()); | 671 EXPECT_TRUE(scheduler_->RedrawPending()); |
647 EXPECT_TRUE(client.needs_begin_frames()); | 672 EXPECT_TRUE(client_ptr->needs_begin_frames()); |
648 EXPECT_EQ(0, client.num_draws()); | 673 EXPECT_EQ(0, client_ptr->num_draws()); |
649 | 674 |
650 // Fail the draw. | 675 // Fail the draw. |
651 EXPECT_SCOPED(client.AdvanceFrame()); | 676 EXPECT_SCOPED(AdvanceFrame()); |
652 client.task_runner().RunPendingTasks(); // Run posted deadline. | 677 task_runner().RunPendingTasks(); // Run posted deadline. |
653 EXPECT_EQ(1, client.num_draws()); | 678 EXPECT_EQ(1, client_ptr->num_draws()); |
654 | 679 |
655 // We have a commit pending and the draw failed, and we didn't lose the redraw | 680 // We have a commit pending and the draw failed, and we didn't lose the redraw |
656 // request. | 681 // request. |
657 EXPECT_TRUE(scheduler->CommitPending()); | 682 EXPECT_TRUE(scheduler_->CommitPending()); |
658 EXPECT_TRUE(scheduler->RedrawPending()); | 683 EXPECT_TRUE(scheduler_->RedrawPending()); |
659 EXPECT_TRUE(client.needs_begin_frames()); | 684 EXPECT_TRUE(client_ptr->needs_begin_frames()); |
660 | 685 |
661 client.SetRequestRedrawsInsideDraw(false); | 686 client_ptr->SetRequestRedrawsInsideDraw(false); |
662 | 687 |
663 // Fail the draw again. | 688 // Fail the draw again. |
664 EXPECT_SCOPED(client.AdvanceFrame()); | 689 EXPECT_SCOPED(AdvanceFrame()); |
665 client.task_runner().RunPendingTasks(); // Run posted deadline. | 690 task_runner().RunPendingTasks(); // Run posted deadline. |
666 EXPECT_EQ(2, client.num_draws()); | 691 EXPECT_EQ(2, client_ptr->num_draws()); |
667 EXPECT_TRUE(scheduler->CommitPending()); | 692 EXPECT_TRUE(scheduler_->CommitPending()); |
668 EXPECT_TRUE(scheduler->RedrawPending()); | 693 EXPECT_TRUE(scheduler_->RedrawPending()); |
669 EXPECT_TRUE(client.needs_begin_frames()); | 694 EXPECT_TRUE(client_ptr->needs_begin_frames()); |
670 | 695 |
671 // Draw successfully. | 696 // Draw successfully. |
672 client.SetDrawWillHappen(true); | 697 client_ptr->SetDrawWillHappen(true); |
673 EXPECT_SCOPED(client.AdvanceFrame()); | 698 EXPECT_SCOPED(AdvanceFrame()); |
674 client.task_runner().RunPendingTasks(); // Run posted deadline. | 699 task_runner().RunPendingTasks(); // Run posted deadline. |
675 EXPECT_EQ(3, client.num_draws()); | 700 EXPECT_EQ(3, client_ptr->num_draws()); |
676 EXPECT_TRUE(scheduler->CommitPending()); | 701 EXPECT_TRUE(scheduler_->CommitPending()); |
677 EXPECT_FALSE(scheduler->RedrawPending()); | 702 EXPECT_FALSE(scheduler_->RedrawPending()); |
678 EXPECT_TRUE(client.needs_begin_frames()); | 703 EXPECT_TRUE(client_ptr->needs_begin_frames()); |
679 } | 704 } |
680 | 705 |
681 class SchedulerClientThatSetNeedsCommitInsideDraw : public FakeSchedulerClient { | 706 class SchedulerClientThatSetNeedsCommitInsideDraw : public FakeSchedulerClient { |
682 public: | 707 public: |
683 SchedulerClientThatSetNeedsCommitInsideDraw() | 708 SchedulerClientThatSetNeedsCommitInsideDraw() |
684 : set_needs_commit_on_next_draw_(false) {} | 709 : set_needs_commit_on_next_draw_(false) {} |
685 | 710 |
686 void ScheduledActionSendBeginMainFrame() override {} | 711 void ScheduledActionSendBeginMainFrame() override {} |
687 DrawResult ScheduledActionDrawAndSwapIfPossible() override { | 712 DrawResult ScheduledActionDrawAndSwapIfPossible() override { |
688 // Only SetNeedsCommit the first time this is called | 713 // Only SetNeedsCommit the first time this is called |
(...skipping 13 matching lines...) Expand all Loading... | |
702 void DidAnticipatedDrawTimeChange(base::TimeTicks) override {} | 727 void DidAnticipatedDrawTimeChange(base::TimeTicks) override {} |
703 | 728 |
704 void SetNeedsCommitOnNextDraw() { set_needs_commit_on_next_draw_ = true; } | 729 void SetNeedsCommitOnNextDraw() { set_needs_commit_on_next_draw_ = true; } |
705 | 730 |
706 private: | 731 private: |
707 bool set_needs_commit_on_next_draw_; | 732 bool set_needs_commit_on_next_draw_; |
708 }; | 733 }; |
709 | 734 |
710 // Tests for the scheduler infinite-looping on SetNeedsCommit requests that | 735 // Tests for the scheduler infinite-looping on SetNeedsCommit requests that |
711 // happen inside a ScheduledActionDrawAndSwap | 736 // happen inside a ScheduledActionDrawAndSwap |
712 TEST(SchedulerTest, RequestCommitInsideDraw) { | 737 TEST_F(SchedulerTest, RequestCommitInsideDraw) { |
713 SchedulerClientThatSetNeedsCommitInsideDraw client; | 738 scoped_ptr<SchedulerClientThatSetNeedsCommitInsideDraw> client = |
714 SchedulerSettings scheduler_settings; | 739 make_scoped_ptr(new SchedulerClientThatSetNeedsCommitInsideDraw); |
715 scheduler_settings.use_external_begin_frame_source = true; | |
716 | 740 |
717 CREATE_SCHEDULER_AND_INIT_SURFACE(scheduler_settings); | 741 SchedulerClientThatSetNeedsCommitInsideDraw* client_ptr = client.get(); |
742 scheduler_settings_.use_external_begin_frame_source = true; | |
743 SetUpScheduler(client.Pass(), true); | |
718 | 744 |
719 EXPECT_FALSE(client.needs_begin_frames()); | 745 EXPECT_FALSE(client_ptr->needs_begin_frames()); |
720 scheduler->SetNeedsRedraw(); | 746 scheduler_->SetNeedsRedraw(); |
721 EXPECT_TRUE(scheduler->RedrawPending()); | 747 EXPECT_TRUE(scheduler_->RedrawPending()); |
722 EXPECT_EQ(0, client.num_draws()); | 748 EXPECT_EQ(0, client_ptr->num_draws()); |
723 EXPECT_TRUE(client.needs_begin_frames()); | 749 EXPECT_TRUE(client_ptr->needs_begin_frames()); |
724 | 750 |
725 client.SetNeedsCommitOnNextDraw(); | 751 client_ptr->SetNeedsCommitOnNextDraw(); |
726 EXPECT_SCOPED(client.AdvanceFrame()); | 752 EXPECT_SCOPED(AdvanceFrame()); |
727 client.SetNeedsCommitOnNextDraw(); | 753 client_ptr->SetNeedsCommitOnNextDraw(); |
728 client.task_runner().RunPendingTasks(); // Run posted deadline. | 754 task_runner().RunPendingTasks(); // Run posted deadline. |
729 EXPECT_EQ(1, client.num_draws()); | 755 EXPECT_EQ(1, client_ptr->num_draws()); |
730 EXPECT_TRUE(scheduler->CommitPending()); | 756 EXPECT_TRUE(scheduler_->CommitPending()); |
731 EXPECT_TRUE(client.needs_begin_frames()); | 757 EXPECT_TRUE(client_ptr->needs_begin_frames()); |
732 scheduler->NotifyBeginMainFrameStarted(); | 758 scheduler_->NotifyBeginMainFrameStarted(); |
733 scheduler->NotifyReadyToCommit(); | 759 scheduler_->NotifyReadyToCommit(); |
734 | 760 |
735 EXPECT_SCOPED(client.AdvanceFrame()); | 761 EXPECT_SCOPED(AdvanceFrame()); |
736 client.task_runner().RunPendingTasks(); // Run posted deadline. | 762 task_runner().RunPendingTasks(); // Run posted deadline. |
737 EXPECT_EQ(2, client.num_draws()); | 763 EXPECT_EQ(2, client_ptr->num_draws()); |
738 | 764 |
739 EXPECT_FALSE(scheduler->RedrawPending()); | 765 EXPECT_FALSE(scheduler_->RedrawPending()); |
740 EXPECT_FALSE(scheduler->CommitPending()); | 766 EXPECT_FALSE(scheduler_->CommitPending()); |
741 EXPECT_TRUE(client.needs_begin_frames()); | 767 EXPECT_TRUE(client_ptr->needs_begin_frames()); |
742 | 768 |
743 // We stop requesting BeginImplFrames after a BeginImplFrame where we don't | 769 // We stop requesting BeginImplFrames after a BeginImplFrame where we don't |
744 // swap. | 770 // swap. |
745 EXPECT_SCOPED(client.AdvanceFrame()); | 771 EXPECT_SCOPED(AdvanceFrame()); |
746 client.task_runner().RunPendingTasks(); // Run posted deadline. | 772 task_runner().RunPendingTasks(); // Run posted deadline. |
747 EXPECT_EQ(2, client.num_draws()); | 773 EXPECT_EQ(2, client_ptr->num_draws()); |
748 EXPECT_FALSE(scheduler->RedrawPending()); | 774 EXPECT_FALSE(scheduler_->RedrawPending()); |
749 EXPECT_FALSE(scheduler->CommitPending()); | 775 EXPECT_FALSE(scheduler_->CommitPending()); |
750 EXPECT_FALSE(client.needs_begin_frames()); | 776 EXPECT_FALSE(client_ptr->needs_begin_frames()); |
751 } | 777 } |
752 | 778 |
753 // Tests that when a draw fails then the pending commit should not be dropped. | 779 // Tests that when a draw fails then the pending commit should not be dropped. |
754 TEST(SchedulerTest, RequestCommitInsideFailedDraw) { | 780 TEST_F(SchedulerTest, RequestCommitInsideFailedDraw) { |
755 SchedulerClientThatsetNeedsDrawInsideDraw client; | 781 scoped_ptr<SchedulerClientThatsetNeedsDrawInsideDraw> client = |
756 SchedulerSettings scheduler_settings; | 782 make_scoped_ptr(new SchedulerClientThatsetNeedsDrawInsideDraw); |
757 scheduler_settings.use_external_begin_frame_source = true; | 783 SchedulerClientThatsetNeedsDrawInsideDraw* client_ptr = client.get(); |
784 scheduler_settings_.use_external_begin_frame_source = true; | |
785 SetUpScheduler(client.Pass(), true); | |
758 | 786 |
759 CREATE_SCHEDULER_AND_INIT_SURFACE(scheduler_settings); | 787 client_ptr->SetDrawWillHappen(false); |
760 | 788 |
761 client.SetDrawWillHappen(false); | 789 scheduler_->SetNeedsRedraw(); |
762 | 790 EXPECT_TRUE(scheduler_->RedrawPending()); |
763 scheduler->SetNeedsRedraw(); | 791 EXPECT_TRUE(client_ptr->needs_begin_frames()); |
764 EXPECT_TRUE(scheduler->RedrawPending()); | 792 EXPECT_EQ(0, client_ptr->num_draws()); |
765 EXPECT_TRUE(client.needs_begin_frames()); | |
766 EXPECT_EQ(0, client.num_draws()); | |
767 | 793 |
768 // Fail the draw. | 794 // Fail the draw. |
769 EXPECT_SCOPED(client.AdvanceFrame()); | 795 EXPECT_SCOPED(AdvanceFrame()); |
770 client.task_runner().RunPendingTasks(); // Run posted deadline. | 796 task_runner().RunPendingTasks(); // Run posted deadline. |
771 EXPECT_EQ(1, client.num_draws()); | 797 EXPECT_EQ(1, client_ptr->num_draws()); |
772 | 798 |
773 // We have a commit pending and the draw failed, and we didn't lose the commit | 799 // We have a commit pending and the draw failed, and we didn't lose the commit |
774 // request. | 800 // request. |
775 EXPECT_TRUE(scheduler->CommitPending()); | 801 EXPECT_TRUE(scheduler_->CommitPending()); |
776 EXPECT_TRUE(scheduler->RedrawPending()); | 802 EXPECT_TRUE(scheduler_->RedrawPending()); |
777 EXPECT_TRUE(client.needs_begin_frames()); | 803 EXPECT_TRUE(client_ptr->needs_begin_frames()); |
778 | 804 |
779 // Fail the draw again. | 805 // Fail the draw again. |
780 EXPECT_SCOPED(client.AdvanceFrame()); | 806 EXPECT_SCOPED(AdvanceFrame()); |
781 | 807 |
782 client.task_runner().RunPendingTasks(); // Run posted deadline. | 808 task_runner().RunPendingTasks(); // Run posted deadline. |
783 EXPECT_EQ(2, client.num_draws()); | 809 EXPECT_EQ(2, client_ptr->num_draws()); |
784 EXPECT_TRUE(scheduler->CommitPending()); | 810 EXPECT_TRUE(scheduler_->CommitPending()); |
785 EXPECT_TRUE(scheduler->RedrawPending()); | 811 EXPECT_TRUE(scheduler_->RedrawPending()); |
786 EXPECT_TRUE(client.needs_begin_frames()); | 812 EXPECT_TRUE(client_ptr->needs_begin_frames()); |
787 | 813 |
788 // Draw successfully. | 814 // Draw successfully. |
789 client.SetDrawWillHappen(true); | 815 client_ptr->SetDrawWillHappen(true); |
790 EXPECT_SCOPED(client.AdvanceFrame()); | 816 EXPECT_SCOPED(AdvanceFrame()); |
791 client.task_runner().RunPendingTasks(); // Run posted deadline. | 817 task_runner().RunPendingTasks(); // Run posted deadline. |
792 EXPECT_EQ(3, client.num_draws()); | 818 EXPECT_EQ(3, client_ptr->num_draws()); |
793 EXPECT_TRUE(scheduler->CommitPending()); | 819 EXPECT_TRUE(scheduler_->CommitPending()); |
794 EXPECT_FALSE(scheduler->RedrawPending()); | 820 EXPECT_FALSE(scheduler_->RedrawPending()); |
795 EXPECT_TRUE(client.needs_begin_frames()); | 821 EXPECT_TRUE(client_ptr->needs_begin_frames()); |
796 } | 822 } |
797 | 823 |
798 TEST(SchedulerTest, NoSwapWhenDrawFails) { | 824 TEST_F(SchedulerTest, NoSwapWhenDrawFails) { |
799 SchedulerClientThatSetNeedsCommitInsideDraw client; | 825 scoped_ptr<SchedulerClientThatSetNeedsCommitInsideDraw> client = |
800 SchedulerSettings scheduler_settings; | 826 make_scoped_ptr(new SchedulerClientThatSetNeedsCommitInsideDraw); |
801 scheduler_settings.use_external_begin_frame_source = true; | 827 SchedulerClientThatSetNeedsCommitInsideDraw* client_ptr = client.get(); |
828 scheduler_settings_.use_external_begin_frame_source = true; | |
829 SetUpScheduler(client.Pass(), true); | |
802 | 830 |
803 CREATE_SCHEDULER_AND_INIT_SURFACE(scheduler_settings); | 831 scheduler_->SetNeedsRedraw(); |
804 | 832 EXPECT_TRUE(scheduler_->RedrawPending()); |
805 scheduler->SetNeedsRedraw(); | 833 EXPECT_TRUE(client_ptr->needs_begin_frames()); |
806 EXPECT_TRUE(scheduler->RedrawPending()); | 834 EXPECT_EQ(0, client_ptr->num_draws()); |
807 EXPECT_TRUE(client.needs_begin_frames()); | |
808 EXPECT_EQ(0, client.num_draws()); | |
809 | 835 |
810 // Draw successfully, this starts a new frame. | 836 // Draw successfully, this starts a new frame. |
811 client.SetNeedsCommitOnNextDraw(); | 837 client_ptr->SetNeedsCommitOnNextDraw(); |
812 EXPECT_SCOPED(client.AdvanceFrame()); | 838 EXPECT_SCOPED(AdvanceFrame()); |
813 client.task_runner().RunPendingTasks(); // Run posted deadline. | 839 task_runner().RunPendingTasks(); // Run posted deadline. |
814 EXPECT_EQ(1, client.num_draws()); | 840 EXPECT_EQ(1, client_ptr->num_draws()); |
815 | 841 |
816 scheduler->SetNeedsRedraw(); | 842 scheduler_->SetNeedsRedraw(); |
817 EXPECT_TRUE(scheduler->RedrawPending()); | 843 EXPECT_TRUE(scheduler_->RedrawPending()); |
818 EXPECT_TRUE(client.needs_begin_frames()); | 844 EXPECT_TRUE(client_ptr->needs_begin_frames()); |
819 | 845 |
820 // Fail to draw, this should not start a frame. | 846 // Fail to draw, this should not start a frame. |
821 client.SetDrawWillHappen(false); | 847 client_ptr->SetDrawWillHappen(false); |
822 client.SetNeedsCommitOnNextDraw(); | 848 client_ptr->SetNeedsCommitOnNextDraw(); |
823 EXPECT_SCOPED(client.AdvanceFrame()); | 849 EXPECT_SCOPED(AdvanceFrame()); |
824 client.task_runner().RunPendingTasks(); // Run posted deadline. | 850 task_runner().RunPendingTasks(); // Run posted deadline. |
825 EXPECT_EQ(2, client.num_draws()); | 851 EXPECT_EQ(2, client_ptr->num_draws()); |
826 } | 852 } |
827 | 853 |
828 class SchedulerClientNeedsPrepareTilesInDraw : public FakeSchedulerClient { | 854 class SchedulerClientNeedsPrepareTilesInDraw : public FakeSchedulerClient { |
829 public: | 855 public: |
830 DrawResult ScheduledActionDrawAndSwapIfPossible() override { | 856 DrawResult ScheduledActionDrawAndSwapIfPossible() override { |
831 scheduler_->SetNeedsPrepareTiles(); | 857 scheduler_->SetNeedsPrepareTiles(); |
832 return FakeSchedulerClient::ScheduledActionDrawAndSwapIfPossible(); | 858 return FakeSchedulerClient::ScheduledActionDrawAndSwapIfPossible(); |
833 } | 859 } |
834 }; | 860 }; |
835 | 861 |
836 // Test prepare tiles is independant of draws. | 862 // Test prepare tiles is independant of draws. |
837 TEST(SchedulerTest, PrepareTiles) { | 863 TEST_F(SchedulerTest, PrepareTiles) { |
838 SchedulerClientNeedsPrepareTilesInDraw client; | 864 scoped_ptr<SchedulerClientNeedsPrepareTilesInDraw> client = |
839 SchedulerSettings scheduler_settings; | 865 make_scoped_ptr(new SchedulerClientNeedsPrepareTilesInDraw); |
840 scheduler_settings.use_external_begin_frame_source = true; | 866 SchedulerClientNeedsPrepareTilesInDraw* client_ptr = client.get(); |
841 | 867 scheduler_settings_.use_external_begin_frame_source = true; |
842 CREATE_SCHEDULER_AND_INIT_SURFACE(scheduler_settings); | 868 SetUpScheduler(client.Pass(), true); |
843 | 869 |
844 // Request both draw and prepare tiles. PrepareTiles shouldn't | 870 // Request both draw and prepare tiles. PrepareTiles shouldn't |
845 // be trigged until BeginImplFrame. | 871 // be trigged until BeginImplFrame. |
846 client.Reset(); | 872 client_ptr->Reset(); |
847 scheduler->SetNeedsPrepareTiles(); | 873 scheduler_->SetNeedsPrepareTiles(); |
848 scheduler->SetNeedsRedraw(); | 874 scheduler_->SetNeedsRedraw(); |
849 EXPECT_TRUE(scheduler->RedrawPending()); | 875 EXPECT_TRUE(scheduler_->RedrawPending()); |
850 EXPECT_TRUE(scheduler->PrepareTilesPending()); | 876 EXPECT_TRUE(scheduler_->PrepareTilesPending()); |
851 EXPECT_TRUE(client.needs_begin_frames()); | 877 EXPECT_TRUE(client_ptr->needs_begin_frames()); |
852 EXPECT_EQ(0, client.num_draws()); | 878 EXPECT_EQ(0, client_ptr->num_draws()); |
853 EXPECT_FALSE(client.HasAction("ScheduledActionPrepareTiles")); | 879 EXPECT_FALSE(client_ptr->HasAction("ScheduledActionPrepareTiles")); |
854 EXPECT_FALSE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); | 880 EXPECT_FALSE(client_ptr->HasAction("ScheduledActionDrawAndSwapIfPossible")); |
855 | 881 |
856 // We have no immediate actions to perform, so the BeginImplFrame should post | 882 // We have no immediate actions to perform, so the BeginImplFrame should post |
857 // the deadline task. | 883 // the deadline task. |
858 client.Reset(); | 884 client_ptr->Reset(); |
859 EXPECT_SCOPED(client.AdvanceFrame()); | 885 EXPECT_SCOPED(AdvanceFrame()); |
860 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 886 EXPECT_ACTION("WillBeginImplFrame", client_ptr, 0, 2); |
861 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); | 887 EXPECT_ACTION("ScheduledActionAnimate", client_ptr, 1, 2); |
862 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 888 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
863 | 889 |
864 // On the deadline, he actions should have occured in the right order. | 890 // On the deadline, he actions should have occured in the right order. |
865 client.Reset(); | 891 client_ptr->Reset(); |
866 client.task_runner().RunPendingTasks(); // Run posted deadline. | 892 task_runner().RunPendingTasks(); // Run posted deadline. |
867 EXPECT_EQ(1, client.num_draws()); | 893 EXPECT_EQ(1, client_ptr->num_draws()); |
868 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); | 894 EXPECT_TRUE(client_ptr->HasAction("ScheduledActionDrawAndSwapIfPossible")); |
869 EXPECT_TRUE(client.HasAction("ScheduledActionPrepareTiles")); | 895 EXPECT_TRUE(client_ptr->HasAction("ScheduledActionPrepareTiles")); |
870 EXPECT_LT(client.ActionIndex("ScheduledActionDrawAndSwapIfPossible"), | 896 EXPECT_LT(client_ptr->ActionIndex("ScheduledActionDrawAndSwapIfPossible"), |
871 client.ActionIndex("ScheduledActionPrepareTiles")); | 897 client_ptr->ActionIndex("ScheduledActionPrepareTiles")); |
872 EXPECT_FALSE(scheduler->RedrawPending()); | 898 EXPECT_FALSE(scheduler_->RedrawPending()); |
873 EXPECT_FALSE(scheduler->PrepareTilesPending()); | 899 EXPECT_FALSE(scheduler_->PrepareTilesPending()); |
874 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 900 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); |
875 | 901 |
876 // Request a draw. We don't need a PrepareTiles yet. | 902 // Request a draw. We don't need a PrepareTiles yet. |
877 client.Reset(); | 903 client_ptr->Reset(); |
878 scheduler->SetNeedsRedraw(); | 904 scheduler_->SetNeedsRedraw(); |
879 EXPECT_TRUE(scheduler->RedrawPending()); | 905 EXPECT_TRUE(scheduler_->RedrawPending()); |
880 EXPECT_FALSE(scheduler->PrepareTilesPending()); | 906 EXPECT_FALSE(scheduler_->PrepareTilesPending()); |
881 EXPECT_TRUE(client.needs_begin_frames()); | 907 EXPECT_TRUE(client_ptr->needs_begin_frames()); |
882 EXPECT_EQ(0, client.num_draws()); | 908 EXPECT_EQ(0, client_ptr->num_draws()); |
883 | 909 |
884 // We have no immediate actions to perform, so the BeginImplFrame should post | 910 // We have no immediate actions to perform, so the BeginImplFrame should post |
885 // the deadline task. | 911 // the deadline task. |
886 client.Reset(); | 912 client_ptr->Reset(); |
887 EXPECT_SCOPED(client.AdvanceFrame()); | 913 EXPECT_SCOPED(AdvanceFrame()); |
888 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 914 EXPECT_ACTION("WillBeginImplFrame", client_ptr, 0, 2); |
889 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); | 915 EXPECT_ACTION("ScheduledActionAnimate", client_ptr, 1, 2); |
890 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 916 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
891 | 917 |
892 // Draw. The draw will trigger SetNeedsPrepareTiles, and | 918 // Draw. The draw will trigger SetNeedsPrepareTiles, and |
893 // then the PrepareTiles action will be triggered after the Draw. | 919 // then the PrepareTiles action will be triggered after the Draw. |
894 // Afterwards, neither a draw nor PrepareTiles are pending. | 920 // Afterwards, neither a draw nor PrepareTiles are pending. |
895 client.Reset(); | 921 client_ptr->Reset(); |
896 client.task_runner().RunPendingTasks(); // Run posted deadline. | 922 task_runner().RunPendingTasks(); // Run posted deadline. |
897 EXPECT_EQ(1, client.num_draws()); | 923 EXPECT_EQ(1, client_ptr->num_draws()); |
898 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); | 924 EXPECT_TRUE(client_ptr->HasAction("ScheduledActionDrawAndSwapIfPossible")); |
899 EXPECT_TRUE(client.HasAction("ScheduledActionPrepareTiles")); | 925 EXPECT_TRUE(client_ptr->HasAction("ScheduledActionPrepareTiles")); |
900 EXPECT_LT(client.ActionIndex("ScheduledActionDrawAndSwapIfPossible"), | 926 EXPECT_LT(client_ptr->ActionIndex("ScheduledActionDrawAndSwapIfPossible"), |
901 client.ActionIndex("ScheduledActionPrepareTiles")); | 927 client_ptr->ActionIndex("ScheduledActionPrepareTiles")); |
902 EXPECT_FALSE(scheduler->RedrawPending()); | 928 EXPECT_FALSE(scheduler_->RedrawPending()); |
903 EXPECT_FALSE(scheduler->PrepareTilesPending()); | 929 EXPECT_FALSE(scheduler_->PrepareTilesPending()); |
904 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 930 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); |
905 | 931 |
906 // We need a BeginImplFrame where we don't swap to go idle. | 932 // We need a BeginImplFrame where we don't swap to go idle. |
907 client.Reset(); | 933 client_ptr->Reset(); |
908 EXPECT_SCOPED(client.AdvanceFrame()); | 934 EXPECT_SCOPED(AdvanceFrame()); |
909 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); | 935 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client_ptr); |
910 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 936 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
911 client.Reset(); | 937 client_ptr->Reset(); |
912 client.task_runner().RunPendingTasks(); // Run posted deadline. | 938 task_runner().RunPendingTasks(); // Run posted deadline. |
913 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(false)", client); | 939 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(false)", client_ptr); |
914 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 940 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); |
915 EXPECT_EQ(0, client.num_draws()); | 941 EXPECT_EQ(0, client_ptr->num_draws()); |
916 | 942 |
917 // Now trigger a PrepareTiles outside of a draw. We will then need | 943 // Now trigger a PrepareTiles outside of a draw. We will then need |
918 // a begin-frame for the PrepareTiles, but we don't need a draw. | 944 // a begin-frame for the PrepareTiles, but we don't need a draw. |
919 client.Reset(); | 945 client_ptr->Reset(); |
920 EXPECT_FALSE(client.needs_begin_frames()); | 946 EXPECT_FALSE(client_ptr->needs_begin_frames()); |
921 scheduler->SetNeedsPrepareTiles(); | 947 scheduler_->SetNeedsPrepareTiles(); |
922 EXPECT_TRUE(client.needs_begin_frames()); | 948 EXPECT_TRUE(client_ptr->needs_begin_frames()); |
923 EXPECT_TRUE(scheduler->PrepareTilesPending()); | 949 EXPECT_TRUE(scheduler_->PrepareTilesPending()); |
924 EXPECT_FALSE(scheduler->RedrawPending()); | 950 EXPECT_FALSE(scheduler_->RedrawPending()); |
925 | 951 |
926 // BeginImplFrame. There will be no draw, only PrepareTiles. | 952 // BeginImplFrame. There will be no draw, only PrepareTiles. |
927 client.Reset(); | 953 client_ptr->Reset(); |
928 EXPECT_SCOPED(client.AdvanceFrame()); | 954 EXPECT_SCOPED(AdvanceFrame()); |
929 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); | 955 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client_ptr); |
930 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 956 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
931 client.Reset(); | 957 client_ptr->Reset(); |
932 client.task_runner().RunPendingTasks(); // Run posted deadline. | 958 task_runner().RunPendingTasks(); // Run posted deadline. |
933 EXPECT_EQ(0, client.num_draws()); | 959 EXPECT_EQ(0, client_ptr->num_draws()); |
934 EXPECT_FALSE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); | 960 EXPECT_FALSE(client_ptr->HasAction("ScheduledActionDrawAndSwapIfPossible")); |
935 EXPECT_TRUE(client.HasAction("ScheduledActionPrepareTiles")); | 961 EXPECT_TRUE(client_ptr->HasAction("ScheduledActionPrepareTiles")); |
936 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 962 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); |
937 } | 963 } |
938 | 964 |
939 // Test that PrepareTiles only happens once per frame. If an external caller | 965 // Test that PrepareTiles only happens once per frame. If an external caller |
940 // initiates it, then the state machine should not PrepareTiles on that frame. | 966 // initiates it, then the state machine should not PrepareTiles on that frame. |
941 TEST(SchedulerTest, PrepareTilesOncePerFrame) { | 967 TEST_F(SchedulerTest, PrepareTilesOncePerFrame) { |
942 FakeSchedulerClient client; | 968 scheduler_settings_.use_external_begin_frame_source = true; |
943 SchedulerSettings scheduler_settings; | 969 SetUpScheduler(true); |
944 scheduler_settings.use_external_begin_frame_source = true; | |
945 | |
946 CREATE_SCHEDULER_AND_INIT_SURFACE(scheduler_settings); | |
947 | 970 |
948 // If DidPrepareTiles during a frame, then PrepareTiles should not occur | 971 // If DidPrepareTiles during a frame, then PrepareTiles should not occur |
949 // again. | 972 // again. |
950 scheduler->SetNeedsPrepareTiles(); | 973 scheduler_->SetNeedsPrepareTiles(); |
951 scheduler->SetNeedsRedraw(); | 974 scheduler_->SetNeedsRedraw(); |
952 client.Reset(); | 975 client_->Reset(); |
953 EXPECT_SCOPED(client.AdvanceFrame()); | 976 EXPECT_SCOPED(AdvanceFrame()); |
954 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 977 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
955 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); | 978 EXPECT_ACTION("ScheduledActionAnimate", client_, 1, 2); |
956 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 979 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
957 | 980 |
958 EXPECT_TRUE(scheduler->PrepareTilesPending()); | 981 EXPECT_TRUE(scheduler_->PrepareTilesPending()); |
959 scheduler->DidPrepareTiles(); // An explicit PrepareTiles. | 982 scheduler_->DidPrepareTiles(); // An explicit PrepareTiles. |
960 EXPECT_FALSE(scheduler->PrepareTilesPending()); | 983 EXPECT_FALSE(scheduler_->PrepareTilesPending()); |
961 | 984 |
962 client.Reset(); | 985 client_->Reset(); |
963 client.task_runner().RunPendingTasks(); // Run posted deadline. | 986 task_runner().RunPendingTasks(); // Run posted deadline. |
964 EXPECT_EQ(1, client.num_draws()); | 987 EXPECT_EQ(1, client_->num_draws()); |
965 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); | 988 EXPECT_TRUE(client_->HasAction("ScheduledActionDrawAndSwapIfPossible")); |
966 EXPECT_FALSE(client.HasAction("ScheduledActionPrepareTiles")); | 989 EXPECT_FALSE(client_->HasAction("ScheduledActionPrepareTiles")); |
967 EXPECT_FALSE(scheduler->RedrawPending()); | 990 EXPECT_FALSE(scheduler_->RedrawPending()); |
968 EXPECT_FALSE(scheduler->PrepareTilesPending()); | 991 EXPECT_FALSE(scheduler_->PrepareTilesPending()); |
969 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 992 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); |
970 | 993 |
971 // Next frame without DidPrepareTiles should PrepareTiles with draw. | 994 // Next frame without DidPrepareTiles should PrepareTiles with draw. |
972 scheduler->SetNeedsPrepareTiles(); | 995 scheduler_->SetNeedsPrepareTiles(); |
973 scheduler->SetNeedsRedraw(); | 996 scheduler_->SetNeedsRedraw(); |
974 client.Reset(); | 997 client_->Reset(); |
975 EXPECT_SCOPED(client.AdvanceFrame()); | 998 EXPECT_SCOPED(AdvanceFrame()); |
976 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 999 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
977 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); | 1000 EXPECT_ACTION("ScheduledActionAnimate", client_, 1, 2); |
978 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1001 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
979 | 1002 |
980 client.Reset(); | 1003 client_->Reset(); |
981 client.task_runner().RunPendingTasks(); // Run posted deadline. | 1004 task_runner().RunPendingTasks(); // Run posted deadline. |
982 EXPECT_EQ(1, client.num_draws()); | 1005 EXPECT_EQ(1, client_->num_draws()); |
983 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); | 1006 EXPECT_TRUE(client_->HasAction("ScheduledActionDrawAndSwapIfPossible")); |
984 EXPECT_TRUE(client.HasAction("ScheduledActionPrepareTiles")); | 1007 EXPECT_TRUE(client_->HasAction("ScheduledActionPrepareTiles")); |
985 EXPECT_LT(client.ActionIndex("ScheduledActionDrawAndSwapIfPossible"), | 1008 EXPECT_LT(client_->ActionIndex("ScheduledActionDrawAndSwapIfPossible"), |
986 client.ActionIndex("ScheduledActionPrepareTiles")); | 1009 client_->ActionIndex("ScheduledActionPrepareTiles")); |
987 EXPECT_FALSE(scheduler->RedrawPending()); | 1010 EXPECT_FALSE(scheduler_->RedrawPending()); |
988 EXPECT_FALSE(scheduler->PrepareTilesPending()); | 1011 EXPECT_FALSE(scheduler_->PrepareTilesPending()); |
989 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 1012 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); |
990 scheduler->DidPrepareTiles(); // Corresponds to ScheduledActionPrepareTiles | 1013 scheduler_->DidPrepareTiles(); // Corresponds to ScheduledActionPrepareTiles |
991 | 1014 |
992 // If we get another DidPrepareTiles within the same frame, we should | 1015 // If we get another DidPrepareTiles within the same frame, we should |
993 // not PrepareTiles on the next frame. | 1016 // not PrepareTiles on the next frame. |
994 scheduler->DidPrepareTiles(); // An explicit PrepareTiles. | 1017 scheduler_->DidPrepareTiles(); // An explicit PrepareTiles. |
995 scheduler->SetNeedsPrepareTiles(); | 1018 scheduler_->SetNeedsPrepareTiles(); |
996 scheduler->SetNeedsRedraw(); | 1019 scheduler_->SetNeedsRedraw(); |
997 client.Reset(); | 1020 client_->Reset(); |
998 EXPECT_SCOPED(client.AdvanceFrame()); | 1021 EXPECT_SCOPED(AdvanceFrame()); |
999 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 1022 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
1000 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); | 1023 EXPECT_ACTION("ScheduledActionAnimate", client_, 1, 2); |
1001 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1024 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
1002 | 1025 |
1003 EXPECT_TRUE(scheduler->PrepareTilesPending()); | 1026 EXPECT_TRUE(scheduler_->PrepareTilesPending()); |
1004 | 1027 |
1005 client.Reset(); | 1028 client_->Reset(); |
1006 client.task_runner().RunPendingTasks(); // Run posted deadline. | 1029 task_runner().RunPendingTasks(); // Run posted deadline. |
1007 EXPECT_EQ(1, client.num_draws()); | 1030 EXPECT_EQ(1, client_->num_draws()); |
1008 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); | 1031 EXPECT_TRUE(client_->HasAction("ScheduledActionDrawAndSwapIfPossible")); |
1009 EXPECT_FALSE(client.HasAction("ScheduledActionPrepareTiles")); | 1032 EXPECT_FALSE(client_->HasAction("ScheduledActionPrepareTiles")); |
1010 EXPECT_FALSE(scheduler->RedrawPending()); | 1033 EXPECT_FALSE(scheduler_->RedrawPending()); |
1011 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 1034 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); |
1012 | 1035 |
1013 // If we get another DidPrepareTiles, we should not PrepareTiles on the next | 1036 // If we get another DidPrepareTiles, we should not PrepareTiles on the next |
1014 // frame. This verifies we don't alternate calling PrepareTiles once and | 1037 // frame. This verifies we don't alternate calling PrepareTiles once and |
1015 // twice. | 1038 // twice. |
1016 EXPECT_TRUE(scheduler->PrepareTilesPending()); | 1039 EXPECT_TRUE(scheduler_->PrepareTilesPending()); |
1017 scheduler->DidPrepareTiles(); // An explicit PrepareTiles. | 1040 scheduler_->DidPrepareTiles(); // An explicit PrepareTiles. |
1018 EXPECT_FALSE(scheduler->PrepareTilesPending()); | 1041 EXPECT_FALSE(scheduler_->PrepareTilesPending()); |
1019 scheduler->SetNeedsPrepareTiles(); | 1042 scheduler_->SetNeedsPrepareTiles(); |
1020 scheduler->SetNeedsRedraw(); | 1043 scheduler_->SetNeedsRedraw(); |
1021 client.Reset(); | 1044 client_->Reset(); |
1022 EXPECT_SCOPED(client.AdvanceFrame()); | 1045 EXPECT_SCOPED(AdvanceFrame()); |
1023 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 1046 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
1024 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); | 1047 EXPECT_ACTION("ScheduledActionAnimate", client_, 1, 2); |
1025 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1048 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
1026 | 1049 |
1027 EXPECT_TRUE(scheduler->PrepareTilesPending()); | 1050 EXPECT_TRUE(scheduler_->PrepareTilesPending()); |
1028 | 1051 |
1029 client.Reset(); | 1052 client_->Reset(); |
1030 client.task_runner().RunPendingTasks(); // Run posted deadline. | 1053 task_runner().RunPendingTasks(); // Run posted deadline. |
1031 EXPECT_EQ(1, client.num_draws()); | 1054 EXPECT_EQ(1, client_->num_draws()); |
1032 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); | 1055 EXPECT_TRUE(client_->HasAction("ScheduledActionDrawAndSwapIfPossible")); |
1033 EXPECT_FALSE(client.HasAction("ScheduledActionPrepareTiles")); | 1056 EXPECT_FALSE(client_->HasAction("ScheduledActionPrepareTiles")); |
1034 EXPECT_FALSE(scheduler->RedrawPending()); | 1057 EXPECT_FALSE(scheduler_->RedrawPending()); |
1035 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 1058 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); |
1036 | 1059 |
1037 // Next frame without DidPrepareTiles should PrepareTiles with draw. | 1060 // Next frame without DidPrepareTiles should PrepareTiles with draw. |
1038 scheduler->SetNeedsPrepareTiles(); | 1061 scheduler_->SetNeedsPrepareTiles(); |
1039 scheduler->SetNeedsRedraw(); | 1062 scheduler_->SetNeedsRedraw(); |
1040 client.Reset(); | 1063 client_->Reset(); |
1041 EXPECT_SCOPED(client.AdvanceFrame()); | 1064 EXPECT_SCOPED(AdvanceFrame()); |
1042 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 1065 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
1043 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); | 1066 EXPECT_ACTION("ScheduledActionAnimate", client_, 1, 2); |
1044 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1067 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
1045 | 1068 |
1046 client.Reset(); | 1069 client_->Reset(); |
1047 client.task_runner().RunPendingTasks(); // Run posted deadline. | 1070 task_runner().RunPendingTasks(); // Run posted deadline. |
1048 EXPECT_EQ(1, client.num_draws()); | 1071 EXPECT_EQ(1, client_->num_draws()); |
1049 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); | 1072 EXPECT_TRUE(client_->HasAction("ScheduledActionDrawAndSwapIfPossible")); |
1050 EXPECT_TRUE(client.HasAction("ScheduledActionPrepareTiles")); | 1073 EXPECT_TRUE(client_->HasAction("ScheduledActionPrepareTiles")); |
1051 EXPECT_LT(client.ActionIndex("ScheduledActionDrawAndSwapIfPossible"), | 1074 EXPECT_LT(client_->ActionIndex("ScheduledActionDrawAndSwapIfPossible"), |
1052 client.ActionIndex("ScheduledActionPrepareTiles")); | 1075 client_->ActionIndex("ScheduledActionPrepareTiles")); |
1053 EXPECT_FALSE(scheduler->RedrawPending()); | 1076 EXPECT_FALSE(scheduler_->RedrawPending()); |
1054 EXPECT_FALSE(scheduler->PrepareTilesPending()); | 1077 EXPECT_FALSE(scheduler_->PrepareTilesPending()); |
1055 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 1078 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); |
1056 scheduler->DidPrepareTiles(); // Corresponds to ScheduledActionPrepareTiles | 1079 scheduler_->DidPrepareTiles(); // Corresponds to ScheduledActionPrepareTiles |
1057 } | 1080 } |
1058 | 1081 |
1059 TEST(SchedulerTest, TriggerBeginFrameDeadlineEarly) { | 1082 TEST_F(SchedulerTest, TriggerBeginFrameDeadlineEarly) { |
1060 SchedulerClientNeedsPrepareTilesInDraw client; | 1083 scoped_ptr<SchedulerClientNeedsPrepareTilesInDraw> client = |
1061 SchedulerSettings scheduler_settings; | 1084 make_scoped_ptr(new SchedulerClientNeedsPrepareTilesInDraw); |
1062 scheduler_settings.use_external_begin_frame_source = true; | 1085 scheduler_settings_.use_external_begin_frame_source = true; |
1063 | 1086 SchedulerClientNeedsPrepareTilesInDraw* client_ptr = client.get(); |
1064 CREATE_SCHEDULER_AND_INIT_SURFACE(scheduler_settings); | 1087 SetUpScheduler(client.Pass(), true); |
1065 | 1088 |
1066 scheduler->SetNeedsRedraw(); | 1089 scheduler_->SetNeedsRedraw(); |
1067 EXPECT_SCOPED(client.AdvanceFrame()); | 1090 EXPECT_SCOPED(AdvanceFrame()); |
1068 | 1091 |
1069 // The deadline should be zero since there is no work other than drawing | 1092 // The deadline should be zero since there is no work other than drawing |
1070 // pending. | 1093 // pending. |
1071 EXPECT_EQ(base::TimeTicks(), client.posted_begin_impl_frame_deadline()); | 1094 EXPECT_EQ(base::TimeTicks(), client_ptr->posted_begin_impl_frame_deadline()); |
1072 } | 1095 } |
1073 | 1096 |
1074 class SchedulerClientWithFixedEstimates : public FakeSchedulerClient { | 1097 class SchedulerClientWithFixedEstimates : public FakeSchedulerClient { |
1075 public: | 1098 public: |
1076 SchedulerClientWithFixedEstimates( | 1099 SchedulerClientWithFixedEstimates( |
1077 base::TimeDelta draw_duration, | 1100 base::TimeDelta draw_duration, |
1078 base::TimeDelta begin_main_frame_to_commit_duration, | 1101 base::TimeDelta begin_main_frame_to_commit_duration, |
1079 base::TimeDelta commit_to_activate_duration) | 1102 base::TimeDelta commit_to_activate_duration) |
1080 : draw_duration_(draw_duration), | 1103 : draw_duration_(draw_duration), |
1081 begin_main_frame_to_commit_duration_( | 1104 begin_main_frame_to_commit_duration_( |
1082 begin_main_frame_to_commit_duration), | 1105 begin_main_frame_to_commit_duration), |
1083 commit_to_activate_duration_(commit_to_activate_duration) {} | 1106 commit_to_activate_duration_(commit_to_activate_duration) {} |
1084 | 1107 |
1085 base::TimeDelta DrawDurationEstimate() override { return draw_duration_; } | 1108 base::TimeDelta DrawDurationEstimate() override { return draw_duration_; } |
1086 base::TimeDelta BeginMainFrameToCommitDurationEstimate() override { | 1109 base::TimeDelta BeginMainFrameToCommitDurationEstimate() override { |
1087 return begin_main_frame_to_commit_duration_; | 1110 return begin_main_frame_to_commit_duration_; |
1088 } | 1111 } |
1089 base::TimeDelta CommitToActivateDurationEstimate() override { | 1112 base::TimeDelta CommitToActivateDurationEstimate() override { |
1090 return commit_to_activate_duration_; | 1113 return commit_to_activate_duration_; |
1091 } | 1114 } |
1092 | 1115 |
1093 private: | 1116 private: |
1094 base::TimeDelta draw_duration_; | 1117 base::TimeDelta draw_duration_; |
1095 base::TimeDelta begin_main_frame_to_commit_duration_; | 1118 base::TimeDelta begin_main_frame_to_commit_duration_; |
1096 base::TimeDelta commit_to_activate_duration_; | 1119 base::TimeDelta commit_to_activate_duration_; |
1097 }; | 1120 }; |
1098 | 1121 |
1099 void MainFrameInHighLatencyMode(int64 begin_main_frame_to_commit_estimate_in_ms, | 1122 void SchedulerTest::MainFrameInHighLatencyMode( |
1100 int64 commit_to_activate_estimate_in_ms, | 1123 int64 begin_main_frame_to_commit_estimate_in_ms, |
1101 bool impl_latency_takes_priority, | 1124 int64 commit_to_activate_estimate_in_ms, |
1102 bool should_send_begin_main_frame) { | 1125 bool impl_latency_takes_priority, |
1126 bool should_send_begin_main_frame) { | |
1103 // Set up client with specified estimates (draw duration is set to 1). | 1127 // Set up client with specified estimates (draw duration is set to 1). |
1104 SchedulerClientWithFixedEstimates client( | 1128 scoped_ptr<SchedulerClientWithFixedEstimates> client = |
1105 base::TimeDelta::FromMilliseconds(1), | 1129 make_scoped_ptr(new SchedulerClientWithFixedEstimates( |
1106 base::TimeDelta::FromMilliseconds( | 1130 base::TimeDelta::FromMilliseconds(1), |
1107 begin_main_frame_to_commit_estimate_in_ms), | 1131 base::TimeDelta::FromMilliseconds( |
1108 base::TimeDelta::FromMilliseconds(commit_to_activate_estimate_in_ms)); | 1132 begin_main_frame_to_commit_estimate_in_ms), |
1109 SchedulerSettings scheduler_settings; | 1133 base::TimeDelta::FromMilliseconds( |
1110 scheduler_settings.use_external_begin_frame_source = true; | 1134 commit_to_activate_estimate_in_ms))); |
1111 | 1135 |
1112 CREATE_SCHEDULER_AND_INIT_SURFACE(scheduler_settings); | 1136 SchedulerClientWithFixedEstimates* client_ptr = client.get(); |
1113 | 1137 scheduler_settings_.use_external_begin_frame_source = true; |
1114 scheduler->SetImplLatencyTakesPriority(impl_latency_takes_priority); | 1138 SetUpScheduler(client.Pass(), true); |
1139 | |
1140 scheduler_->SetImplLatencyTakesPriority(impl_latency_takes_priority); | |
1115 | 1141 |
1116 // Impl thread hits deadline before commit finishes. | 1142 // Impl thread hits deadline before commit finishes. |
1117 scheduler->SetNeedsCommit(); | 1143 scheduler_->SetNeedsCommit(); |
1118 EXPECT_FALSE(scheduler->MainThreadIsInHighLatencyMode()); | 1144 EXPECT_FALSE(scheduler_->MainThreadIsInHighLatencyMode()); |
1119 EXPECT_SCOPED(client.AdvanceFrame()); | 1145 EXPECT_SCOPED(AdvanceFrame()); |
1120 EXPECT_FALSE(scheduler->MainThreadIsInHighLatencyMode()); | 1146 EXPECT_FALSE(scheduler_->MainThreadIsInHighLatencyMode()); |
1121 client.task_runner().RunPendingTasks(); // Run posted deadline. | 1147 task_runner().RunPendingTasks(); // Run posted deadline. |
1122 EXPECT_TRUE(scheduler->MainThreadIsInHighLatencyMode()); | 1148 EXPECT_TRUE(scheduler_->MainThreadIsInHighLatencyMode()); |
1123 scheduler->NotifyBeginMainFrameStarted(); | 1149 scheduler_->NotifyBeginMainFrameStarted(); |
1124 scheduler->NotifyReadyToCommit(); | 1150 scheduler_->NotifyReadyToCommit(); |
1125 EXPECT_TRUE(scheduler->MainThreadIsInHighLatencyMode()); | 1151 EXPECT_TRUE(scheduler_->MainThreadIsInHighLatencyMode()); |
1126 EXPECT_TRUE(client.HasAction("ScheduledActionSendBeginMainFrame")); | 1152 EXPECT_TRUE(client_ptr->HasAction("ScheduledActionSendBeginMainFrame")); |
1127 | 1153 |
1128 client.Reset(); | 1154 client_ptr->Reset(); |
1129 scheduler->SetNeedsCommit(); | 1155 scheduler_->SetNeedsCommit(); |
1130 EXPECT_TRUE(scheduler->MainThreadIsInHighLatencyMode()); | 1156 EXPECT_TRUE(scheduler_->MainThreadIsInHighLatencyMode()); |
1131 EXPECT_SCOPED(client.AdvanceFrame()); | 1157 EXPECT_SCOPED(AdvanceFrame()); |
1132 EXPECT_TRUE(scheduler->MainThreadIsInHighLatencyMode()); | 1158 EXPECT_TRUE(scheduler_->MainThreadIsInHighLatencyMode()); |
1133 client.task_runner().RunPendingTasks(); // Run posted deadline. | 1159 task_runner().RunPendingTasks(); // Run posted deadline. |
1134 EXPECT_EQ(scheduler->MainThreadIsInHighLatencyMode(), | 1160 EXPECT_EQ(scheduler_->MainThreadIsInHighLatencyMode(), |
1135 should_send_begin_main_frame); | 1161 should_send_begin_main_frame); |
1136 EXPECT_EQ(client.HasAction("ScheduledActionSendBeginMainFrame"), | 1162 EXPECT_EQ(client_ptr->HasAction("ScheduledActionSendBeginMainFrame"), |
1137 should_send_begin_main_frame); | 1163 should_send_begin_main_frame); |
1138 } | 1164 } |
1139 | 1165 |
1140 TEST(SchedulerTest, | 1166 TEST_F(SchedulerTest, |
1141 SkipMainFrameIfHighLatencyAndCanCommitAndActivateBeforeDeadline) { | 1167 SkipMainFrameIfHighLatencyAndCanCommitAndActivateBeforeDeadline) { |
1142 // Set up client so that estimates indicate that we can commit and activate | 1168 // Set up client so that estimates indicate that we can commit and activate |
1143 // before the deadline (~8ms by default). | 1169 // before the deadline (~8ms by default). |
1144 MainFrameInHighLatencyMode(1, 1, false, false); | 1170 MainFrameInHighLatencyMode(1, 1, false, false); |
1145 } | 1171 } |
1146 | 1172 |
1147 TEST(SchedulerTest, NotSkipMainFrameIfHighLatencyAndCanCommitTooLong) { | 1173 TEST_F(SchedulerTest, NotSkipMainFrameIfHighLatencyAndCanCommitTooLong) { |
1148 // Set up client so that estimates indicate that the commit cannot finish | 1174 // Set up client so that estimates indicate that the commit cannot finish |
1149 // before the deadline (~8ms by default). | 1175 // before the deadline (~8ms by default). |
1150 MainFrameInHighLatencyMode(10, 1, false, true); | 1176 MainFrameInHighLatencyMode(10, 1, false, true); |
1151 } | 1177 } |
1152 | 1178 |
1153 TEST(SchedulerTest, NotSkipMainFrameIfHighLatencyAndCanActivateTooLong) { | 1179 TEST_F(SchedulerTest, NotSkipMainFrameIfHighLatencyAndCanActivateTooLong) { |
1154 // Set up client so that estimates indicate that the activate cannot finish | 1180 // Set up client so that estimates indicate that the activate cannot finish |
1155 // before the deadline (~8ms by default). | 1181 // before the deadline (~8ms by default). |
1156 MainFrameInHighLatencyMode(1, 10, false, true); | 1182 MainFrameInHighLatencyMode(1, 10, false, true); |
1157 } | 1183 } |
1158 | 1184 |
1159 TEST(SchedulerTest, NotSkipMainFrameInPreferImplLatencyMode) { | 1185 TEST_F(SchedulerTest, NotSkipMainFrameInPreferImplLatencyMode) { |
1160 // Set up client so that estimates indicate that we can commit and activate | 1186 // Set up client so that estimates indicate that we can commit and activate |
1161 // before the deadline (~8ms by default), but also enable impl latency takes | 1187 // before the deadline (~8ms by default), but also enable impl latency takes |
1162 // priority mode. | 1188 // priority mode. |
1163 MainFrameInHighLatencyMode(1, 1, true, true); | 1189 MainFrameInHighLatencyMode(1, 1, true, true); |
1164 } | 1190 } |
1165 | 1191 |
1166 TEST(SchedulerTest, PollForCommitCompletion) { | 1192 TEST_F(SchedulerTest, PollForCommitCompletion) { |
1167 // Since we are simulating a long commit, set up a client with draw duration | 1193 // Since we are simulating a long commit, set up a client with draw duration |
1168 // estimates that prevent skipping main frames to get to low latency mode. | 1194 // estimates that prevent skipping main frames to get to low latency mode. |
1169 SchedulerClientWithFixedEstimates client( | 1195 scoped_ptr<SchedulerClientWithFixedEstimates> client = |
1170 base::TimeDelta::FromMilliseconds(1), | 1196 make_scoped_ptr(new SchedulerClientWithFixedEstimates( |
1171 base::TimeDelta::FromMilliseconds(32), | 1197 base::TimeDelta::FromMilliseconds(1), |
1172 base::TimeDelta::FromMilliseconds(32)); | 1198 base::TimeDelta::FromMilliseconds(32), |
1173 SchedulerSettings scheduler_settings; | 1199 base::TimeDelta::FromMilliseconds(32))); |
1174 scheduler_settings.use_external_begin_frame_source = true; | 1200 SchedulerClientWithFixedEstimates* client_ptr = client.get(); |
1175 | 1201 scheduler_settings_.use_external_begin_frame_source = true; |
1176 CREATE_SCHEDULER_AND_INIT_SURFACE(scheduler_settings); | 1202 SetUpScheduler(client.Pass(), true); |
1177 | 1203 |
1178 client.set_log_anticipated_draw_time_change(true); | 1204 client_ptr->set_log_anticipated_draw_time_change(true); |
1179 | 1205 |
1180 BeginFrameArgs frame_args = | 1206 BeginFrameArgs frame_args = |
1181 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, client.now_src()); | 1207 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, now_src()); |
1182 frame_args.interval = base::TimeDelta::FromMilliseconds(1000); | 1208 frame_args.interval = base::TimeDelta::FromMilliseconds(1000); |
1183 | 1209 |
1184 // At this point, we've drawn a frame. Start another commit, but hold off on | 1210 // At this point, we've drawn a frame. Start another commit, but hold off on |
1185 // the NotifyReadyToCommit for now. | 1211 // the NotifyReadyToCommit for now. |
1186 EXPECT_FALSE(scheduler->CommitPending()); | 1212 EXPECT_FALSE(scheduler_->CommitPending()); |
1187 scheduler->SetNeedsCommit(); | 1213 scheduler_->SetNeedsCommit(); |
1188 client.fake_external_begin_frame_source()->TestOnBeginFrame(frame_args); | 1214 fake_external_begin_frame_source()->TestOnBeginFrame(frame_args); |
1189 EXPECT_TRUE(scheduler->CommitPending()); | 1215 EXPECT_TRUE(scheduler_->CommitPending()); |
1190 | 1216 |
1191 // Draw and swap the frame, but don't ack the swap to simulate the Browser | 1217 // Draw and swap the frame, but don't ack the swap to simulate the Browser |
1192 // blocking on the renderer. | 1218 // blocking on the renderer. |
1193 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1219 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
1194 client.task_runner().RunPendingTasks(); // Run posted deadline. | 1220 task_runner().RunPendingTasks(); // Run posted deadline. |
1195 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 1221 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); |
1196 scheduler->DidSwapBuffers(); | 1222 scheduler_->DidSwapBuffers(); |
1197 | 1223 |
1198 // Spin the event loop a few times and make sure we get more | 1224 // Spin the event loop a few times and make sure we get more |
1199 // DidAnticipateDrawTimeChange calls every time. | 1225 // DidAnticipateDrawTimeChange calls every time. |
1200 int actions_so_far = client.num_actions_(); | 1226 int actions_so_far = client_ptr->num_actions_(); |
1201 | 1227 |
1202 // Does three iterations to make sure that the timer is properly repeating. | 1228 // Does three iterations to make sure that the timer is properly repeating. |
1203 for (int i = 0; i < 3; ++i) { | 1229 for (int i = 0; i < 3; ++i) { |
1204 EXPECT_EQ((frame_args.interval * 2).InMicroseconds(), | 1230 EXPECT_EQ((frame_args.interval * 2).InMicroseconds(), |
1205 client.task_runner().DelayToNextTaskTime().InMicroseconds()) | 1231 task_runner().DelayToNextTaskTime().InMicroseconds()) |
1206 << scheduler->AsValue()->ToString(); | 1232 << scheduler_->AsValue()->ToString(); |
1207 client.task_runner().RunPendingTasks(); | 1233 task_runner().RunPendingTasks(); |
1208 EXPECT_GT(client.num_actions_(), actions_so_far); | 1234 EXPECT_GT(client_ptr->num_actions_(), actions_so_far); |
1209 EXPECT_STREQ(client.Action(client.num_actions_() - 1), | 1235 EXPECT_STREQ(client_ptr->Action(client_ptr->num_actions_() - 1), |
1210 "DidAnticipatedDrawTimeChange"); | 1236 "DidAnticipatedDrawTimeChange"); |
1211 actions_so_far = client.num_actions_(); | 1237 actions_so_far = client_ptr->num_actions_(); |
1212 } | 1238 } |
1213 | 1239 |
1214 // Do the same thing after BeginMainFrame starts but still before activation. | 1240 // Do the same thing after BeginMainFrame starts but still before activation. |
1215 scheduler->NotifyBeginMainFrameStarted(); | 1241 scheduler_->NotifyBeginMainFrameStarted(); |
1216 for (int i = 0; i < 3; ++i) { | 1242 for (int i = 0; i < 3; ++i) { |
1217 EXPECT_EQ((frame_args.interval * 2).InMicroseconds(), | 1243 EXPECT_EQ((frame_args.interval * 2).InMicroseconds(), |
1218 client.task_runner().DelayToNextTaskTime().InMicroseconds()) | 1244 task_runner().DelayToNextTaskTime().InMicroseconds()) |
1219 << scheduler->AsValue()->ToString(); | 1245 << scheduler_->AsValue()->ToString(); |
1220 client.task_runner().RunPendingTasks(); | 1246 task_runner().RunPendingTasks(); |
1221 EXPECT_GT(client.num_actions_(), actions_so_far); | 1247 EXPECT_GT(client_ptr->num_actions_(), actions_so_far); |
1222 EXPECT_STREQ(client.Action(client.num_actions_() - 1), | 1248 EXPECT_STREQ(client_ptr->Action(client_ptr->num_actions_() - 1), |
1223 "DidAnticipatedDrawTimeChange"); | 1249 "DidAnticipatedDrawTimeChange"); |
1224 actions_so_far = client.num_actions_(); | 1250 actions_so_far = client_ptr->num_actions_(); |
1225 } | 1251 } |
1226 } | 1252 } |
1227 | 1253 |
1228 TEST(SchedulerTest, BeginRetroFrame) { | 1254 TEST_F(SchedulerTest, BeginRetroFrame) { |
1229 FakeSchedulerClient client; | 1255 scheduler_settings_.use_external_begin_frame_source = true; |
1230 SchedulerSettings scheduler_settings; | 1256 SetUpScheduler(true); |
1231 scheduler_settings.use_external_begin_frame_source = true; | |
1232 | |
1233 CREATE_SCHEDULER_AND_INIT_SURFACE(scheduler_settings); | |
1234 | 1257 |
1235 // SetNeedsCommit should begin the frame on the next BeginImplFrame. | 1258 // SetNeedsCommit should begin the frame on the next BeginImplFrame. |
1236 scheduler->SetNeedsCommit(); | 1259 scheduler_->SetNeedsCommit(); |
1237 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client); | 1260 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client_); |
1238 client.Reset(); | 1261 client_->Reset(); |
1239 | 1262 |
1240 // Create a BeginFrame with a long deadline to avoid race conditions. | 1263 // Create a BeginFrame with a long deadline to avoid race conditions. |
1241 // This is the first BeginFrame, which will be handled immediately. | 1264 // This is the first BeginFrame, which will be handled immediately. |
1242 BeginFrameArgs args = | 1265 BeginFrameArgs args = |
1243 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, client.now_src()); | 1266 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, now_src()); |
1244 args.deadline += base::TimeDelta::FromHours(1); | 1267 args.deadline += base::TimeDelta::FromHours(1); |
1245 client.fake_external_begin_frame_source()->TestOnBeginFrame(args); | 1268 fake_external_begin_frame_source()->TestOnBeginFrame(args); |
1246 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 1269 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
1247 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); | 1270 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); |
1248 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1271 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
1249 EXPECT_TRUE(client.needs_begin_frames()); | 1272 EXPECT_TRUE(client_->needs_begin_frames()); |
1250 client.Reset(); | 1273 client_->Reset(); |
1251 | 1274 |
1252 // Queue BeginFrames while we are still handling the previous BeginFrame. | 1275 // Queue BeginFrames while we are still handling the previous BeginFrame. |
1253 args.frame_time += base::TimeDelta::FromSeconds(1); | 1276 args.frame_time += base::TimeDelta::FromSeconds(1); |
1254 client.fake_external_begin_frame_source()->TestOnBeginFrame(args); | 1277 fake_external_begin_frame_source()->TestOnBeginFrame(args); |
1255 args.frame_time += base::TimeDelta::FromSeconds(1); | 1278 args.frame_time += base::TimeDelta::FromSeconds(1); |
1256 client.fake_external_begin_frame_source()->TestOnBeginFrame(args); | 1279 fake_external_begin_frame_source()->TestOnBeginFrame(args); |
1257 | 1280 |
1258 // If we don't swap on the deadline, we wait for the next BeginImplFrame. | 1281 // If we don't swap on the deadline, we wait for the next BeginImplFrame. |
1259 client.task_runner().RunPendingTasks(); // Run posted deadline. | 1282 task_runner().RunPendingTasks(); // Run posted deadline. |
1260 EXPECT_NO_ACTION(client); | 1283 EXPECT_NO_ACTION(client_); |
1261 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 1284 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); |
1262 EXPECT_TRUE(client.needs_begin_frames()); | 1285 EXPECT_TRUE(client_->needs_begin_frames()); |
1263 client.Reset(); | 1286 client_->Reset(); |
1264 | 1287 |
1265 // NotifyReadyToCommit should trigger the commit. | 1288 // NotifyReadyToCommit should trigger the commit. |
1266 scheduler->NotifyBeginMainFrameStarted(); | 1289 scheduler_->NotifyBeginMainFrameStarted(); |
1267 scheduler->NotifyReadyToCommit(); | 1290 scheduler_->NotifyReadyToCommit(); |
1268 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); | 1291 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_); |
1269 EXPECT_TRUE(client.needs_begin_frames()); | 1292 EXPECT_TRUE(client_->needs_begin_frames()); |
1270 client.Reset(); | 1293 client_->Reset(); |
1271 | 1294 |
1272 // BeginImplFrame should prepare the draw. | 1295 // BeginImplFrame should prepare the draw. |
1273 client.task_runner().RunPendingTasks(); // Run posted BeginRetroFrame. | 1296 task_runner().RunPendingTasks(); // Run posted BeginRetroFrame. |
1274 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 1297 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
1275 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); | 1298 EXPECT_ACTION("ScheduledActionAnimate", client_, 1, 2); |
1276 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1299 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
1277 EXPECT_TRUE(client.needs_begin_frames()); | 1300 EXPECT_TRUE(client_->needs_begin_frames()); |
1278 client.Reset(); | 1301 client_->Reset(); |
1279 | 1302 |
1280 // BeginImplFrame deadline should draw. | 1303 // BeginImplFrame deadline should draw. |
1281 client.task_runner().RunPendingTasks(); // Run posted deadline. | 1304 task_runner().RunPendingTasks(); // Run posted deadline. |
1282 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 1); | 1305 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 0, 1); |
1283 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 1306 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); |
1284 EXPECT_TRUE(client.needs_begin_frames()); | 1307 EXPECT_TRUE(client_->needs_begin_frames()); |
1285 client.Reset(); | 1308 client_->Reset(); |
1286 | 1309 |
1287 // The following BeginImplFrame deadline should SetNeedsBeginFrame(false) | 1310 // The following BeginImplFrame deadline should SetNeedsBeginFrame(false) |
1288 // to avoid excessive toggles. | 1311 // to avoid excessive toggles. |
1289 client.task_runner().RunPendingTasks(); // Run posted BeginRetroFrame. | 1312 task_runner().RunPendingTasks(); // Run posted BeginRetroFrame. |
1290 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); | 1313 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client_); |
1291 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1314 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
1292 client.Reset(); | 1315 client_->Reset(); |
1293 | 1316 |
1294 client.task_runner().RunPendingTasks(); // Run posted deadline. | 1317 task_runner().RunPendingTasks(); // Run posted deadline. |
1295 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(false)", client); | 1318 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(false)", client_); |
1296 client.Reset(); | 1319 client_->Reset(); |
1297 } | 1320 } |
1298 | 1321 |
1299 TEST(SchedulerTest, BeginRetroFrame_SwapThrottled) { | 1322 TEST_F(SchedulerTest, BeginRetroFrame_SwapThrottled) { |
1300 FakeSchedulerClient client; | 1323 scheduler_settings_.use_external_begin_frame_source = true; |
1301 SchedulerSettings scheduler_settings; | 1324 SetUpScheduler(true); |
1302 scheduler_settings.use_external_begin_frame_source = true; | 1325 |
1303 | 1326 scheduler_->SetEstimatedParentDrawTime(base::TimeDelta::FromMicroseconds(1)); |
1304 CREATE_SCHEDULER_AND_INIT_SURFACE(scheduler_settings); | |
1305 scheduler->SetEstimatedParentDrawTime(base::TimeDelta::FromMicroseconds(1)); | |
1306 | 1327 |
1307 // To test swap ack throttling, this test disables automatic swap acks. | 1328 // To test swap ack throttling, this test disables automatic swap acks. |
1308 scheduler->SetMaxSwapsPending(1); | 1329 scheduler_->SetMaxSwapsPending(1); |
1309 client.SetAutomaticSwapAck(false); | 1330 client_->SetAutomaticSwapAck(false); |
1310 | 1331 |
1311 // SetNeedsCommit should begin the frame on the next BeginImplFrame. | 1332 // SetNeedsCommit should begin the frame on the next BeginImplFrame. |
1312 client.Reset(); | 1333 client_->Reset(); |
1313 scheduler->SetNeedsCommit(); | 1334 scheduler_->SetNeedsCommit(); |
1314 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client); | 1335 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client_); |
1315 client.Reset(); | 1336 client_->Reset(); |
1316 | 1337 |
1317 EXPECT_SCOPED(client.AdvanceFrame()); | 1338 EXPECT_SCOPED(AdvanceFrame()); |
1318 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 1339 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
1319 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); | 1340 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); |
1320 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1341 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
1321 EXPECT_TRUE(client.needs_begin_frames()); | 1342 EXPECT_TRUE(client_->needs_begin_frames()); |
1322 client.Reset(); | 1343 client_->Reset(); |
1323 | 1344 |
1324 // Queue BeginFrame while we are still handling the previous BeginFrame. | 1345 // Queue BeginFrame while we are still handling the previous BeginFrame. |
1325 client.SendNextBeginFrame(); | 1346 SendNextBeginFrame(); |
1326 EXPECT_NO_ACTION(client); | 1347 EXPECT_NO_ACTION(client_); |
1327 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1348 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
1328 EXPECT_TRUE(client.needs_begin_frames()); | 1349 EXPECT_TRUE(client_->needs_begin_frames()); |
1329 client.Reset(); | 1350 client_->Reset(); |
1330 | 1351 |
1331 // NotifyReadyToCommit should trigger the pending commit and draw. | 1352 // NotifyReadyToCommit should trigger the pending commit and draw. |
1332 scheduler->NotifyBeginMainFrameStarted(); | 1353 scheduler_->NotifyBeginMainFrameStarted(); |
1333 scheduler->NotifyReadyToCommit(); | 1354 scheduler_->NotifyReadyToCommit(); |
1334 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); | 1355 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_); |
1335 EXPECT_TRUE(client.needs_begin_frames()); | 1356 EXPECT_TRUE(client_->needs_begin_frames()); |
1336 client.Reset(); | 1357 client_->Reset(); |
1337 | 1358 |
1338 // Swapping will put us into a swap throttled state. | 1359 // Swapping will put us into a swap throttled state. |
1339 // Run posted deadline. | 1360 // Run posted deadline. |
1340 client.task_runner().RunTasksWhile(client.ImplFrameDeadlinePending(true)); | 1361 task_runner().RunTasksWhile(client_->ImplFrameDeadlinePending(true)); |
1341 EXPECT_ACTION("ScheduledActionAnimate", client, 0, 2); | 1362 EXPECT_ACTION("ScheduledActionAnimate", client_, 0, 2); |
1342 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 1, 2); | 1363 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 1, 2); |
1343 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 1364 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); |
1344 EXPECT_TRUE(client.needs_begin_frames()); | 1365 EXPECT_TRUE(client_->needs_begin_frames()); |
1345 client.Reset(); | 1366 client_->Reset(); |
1346 | 1367 |
1347 // While swap throttled, BeginRetroFrames should trigger BeginImplFrames | 1368 // While swap throttled, BeginRetroFrames should trigger BeginImplFrames |
1348 // but not a BeginMainFrame or draw. | 1369 // but not a BeginMainFrame or draw. |
1349 scheduler->SetNeedsCommit(); | 1370 scheduler_->SetNeedsCommit(); |
1350 scheduler->SetNeedsRedraw(); | 1371 scheduler_->SetNeedsRedraw(); |
1351 // Run posted BeginRetroFrame. | 1372 // Run posted BeginRetroFrame. |
1352 client.task_runner().RunTasksWhile(client.ImplFrameDeadlinePending(false)); | 1373 task_runner().RunTasksWhile(client_->ImplFrameDeadlinePending(false)); |
1353 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 1374 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
1354 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); | 1375 EXPECT_ACTION("ScheduledActionAnimate", client_, 1, 2); |
1355 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1376 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
1356 EXPECT_TRUE(client.needs_begin_frames()); | 1377 EXPECT_TRUE(client_->needs_begin_frames()); |
1357 client.Reset(); | 1378 client_->Reset(); |
1358 | 1379 |
1359 // Let time pass sufficiently beyond the regular deadline but not beyond the | 1380 // Let time pass sufficiently beyond the regular deadline but not beyond the |
1360 // late deadline. | 1381 // late deadline. |
1361 client.now_src()->AdvanceNow(BeginFrameArgs::DefaultInterval() - | 1382 now_src()->AdvanceNow(BeginFrameArgs::DefaultInterval() - |
1362 base::TimeDelta::FromMicroseconds(1)); | 1383 base::TimeDelta::FromMicroseconds(1)); |
1363 client.task_runner().RunUntilTime(client.now_src()->Now()); | 1384 task_runner().RunUntilTime(now_src()->Now()); |
1364 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1385 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
1365 | 1386 |
1366 // Take us out of a swap throttled state. | 1387 // Take us out of a swap throttled state. |
1367 scheduler->DidSwapBuffersComplete(); | 1388 scheduler_->DidSwapBuffersComplete(); |
1368 EXPECT_SINGLE_ACTION("ScheduledActionSendBeginMainFrame", client); | 1389 EXPECT_SINGLE_ACTION("ScheduledActionSendBeginMainFrame", client_); |
1369 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1390 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
1370 EXPECT_TRUE(client.needs_begin_frames()); | 1391 EXPECT_TRUE(client_->needs_begin_frames()); |
1371 client.Reset(); | 1392 client_->Reset(); |
1372 | 1393 |
1373 // Verify that the deadline was rescheduled. | 1394 // Verify that the deadline was rescheduled. |
1374 client.task_runner().RunUntilTime(client.now_src()->Now()); | 1395 task_runner().RunUntilTime(now_src()->Now()); |
1375 EXPECT_SINGLE_ACTION("ScheduledActionDrawAndSwapIfPossible", client); | 1396 EXPECT_SINGLE_ACTION("ScheduledActionDrawAndSwapIfPossible", client_); |
1376 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 1397 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); |
1377 EXPECT_TRUE(client.needs_begin_frames()); | 1398 EXPECT_TRUE(client_->needs_begin_frames()); |
1378 client.Reset(); | 1399 client_->Reset(); |
1379 } | 1400 } |
1380 | 1401 |
1381 TEST(SchedulerTest, RetroFrameDoesNotExpireTooEarly) { | 1402 TEST_F(SchedulerTest, RetroFrameDoesNotExpireTooEarly) { |
1382 FakeSchedulerClient client; | 1403 scheduler_settings_.use_external_begin_frame_source = true; |
1383 SchedulerSettings scheduler_settings; | 1404 SetUpScheduler(true); |
1384 scheduler_settings.use_external_begin_frame_source = true; | 1405 |
1385 | 1406 scheduler_->SetNeedsCommit(); |
1386 CREATE_SCHEDULER_AND_INIT_SURFACE(scheduler_settings); | 1407 EXPECT_TRUE(client_->needs_begin_frames()); |
1387 | 1408 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client_); |
1388 scheduler->SetNeedsCommit(); | 1409 |
1389 EXPECT_TRUE(client.needs_begin_frames()); | 1410 client_->Reset(); |
1390 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client); | 1411 EXPECT_SCOPED(AdvanceFrame()); |
1391 | 1412 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
1392 client.Reset(); | 1413 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); |
1393 EXPECT_SCOPED(client.AdvanceFrame()); | 1414 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
1394 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 1415 |
1395 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); | 1416 client_->Reset(); |
1396 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1417 scheduler_->NotifyBeginMainFrameStarted(); |
1397 | 1418 |
1398 client.Reset(); | 1419 client_->Reset(); |
1399 scheduler->NotifyBeginMainFrameStarted(); | 1420 SendNextBeginFrame(); |
1400 | |
1401 client.Reset(); | |
1402 client.SendNextBeginFrame(); | |
1403 // This BeginFrame is queued up as a retro frame. | 1421 // This BeginFrame is queued up as a retro frame. |
1404 EXPECT_NO_ACTION(client); | 1422 EXPECT_NO_ACTION(client_); |
1405 // The previous deadline is still pending. | 1423 // The previous deadline is still pending. |
1406 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1424 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
1407 | 1425 |
1408 client.Reset(); | 1426 client_->Reset(); |
1409 // This commit should schedule the (previous) deadline to trigger immediately. | 1427 // This commit should schedule the (previous) deadline to trigger immediately. |
1410 scheduler->NotifyReadyToCommit(); | 1428 scheduler_->NotifyReadyToCommit(); |
1411 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); | 1429 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_); |
1412 | 1430 |
1413 client.Reset(); | 1431 client_->Reset(); |
1414 // The deadline task should trigger causing a draw. | 1432 // The deadline task should trigger causing a draw. |
1415 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1433 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
1416 client.task_runner().RunTasksWhile(client.ImplFrameDeadlinePending(true)); | 1434 task_runner().RunTasksWhile(client_->ImplFrameDeadlinePending(true)); |
1417 EXPECT_ACTION("ScheduledActionAnimate", client, 0, 2); | 1435 EXPECT_ACTION("ScheduledActionAnimate", client_, 0, 2); |
1418 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 1, 2); | 1436 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 1, 2); |
1419 | 1437 |
1420 // Keep animating. | 1438 // Keep animating. |
1421 client.Reset(); | 1439 client_->Reset(); |
1422 scheduler->SetNeedsAnimate(); | 1440 scheduler_->SetNeedsAnimate(); |
1423 scheduler->SetNeedsRedraw(); | 1441 scheduler_->SetNeedsRedraw(); |
1424 EXPECT_NO_ACTION(client); | 1442 EXPECT_NO_ACTION(client_); |
1425 | 1443 |
1426 // Let's advance sufficiently past the next frame's deadline. | 1444 // Let's advance sufficiently past the next frame's deadline. |
1427 client.now_src()->AdvanceNow( | 1445 now_src()->AdvanceNow(BeginFrameArgs::DefaultInterval() - |
1428 BeginFrameArgs::DefaultInterval() - | 1446 BeginFrameArgs::DefaultEstimatedParentDrawTime() + |
1429 BeginFrameArgs::DefaultEstimatedParentDrawTime() + | 1447 base::TimeDelta::FromMicroseconds(1)); |
1430 base::TimeDelta::FromMicroseconds(1)); | |
1431 | 1448 |
1432 // The retro frame hasn't expired yet. | 1449 // The retro frame hasn't expired yet. |
1433 client.task_runner().RunTasksWhile(client.ImplFrameDeadlinePending(false)); | 1450 task_runner().RunTasksWhile(client_->ImplFrameDeadlinePending(false)); |
1434 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 1451 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
1435 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); | 1452 EXPECT_ACTION("ScheduledActionAnimate", client_, 1, 2); |
1436 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1453 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
1437 | 1454 |
1438 // This is an immediate deadline case. | 1455 // This is an immediate deadline case. |
1439 client.Reset(); | 1456 client_->Reset(); |
1440 client.task_runner().RunPendingTasks(); | 1457 task_runner().RunPendingTasks(); |
1441 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 1458 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); |
1442 EXPECT_SINGLE_ACTION("ScheduledActionDrawAndSwapIfPossible", client); | 1459 EXPECT_SINGLE_ACTION("ScheduledActionDrawAndSwapIfPossible", client_); |
1443 } | 1460 } |
1444 | 1461 |
1445 TEST(SchedulerTest, RetroFrameDoesNotExpireTooLate) { | 1462 TEST_F(SchedulerTest, RetroFrameDoesNotExpireTooLate) { |
1446 FakeSchedulerClient client; | 1463 scheduler_settings_.use_external_begin_frame_source = true; |
1447 SchedulerSettings scheduler_settings; | 1464 SetUpScheduler(true); |
1448 scheduler_settings.use_external_begin_frame_source = true; | 1465 |
1449 | 1466 scheduler_->SetNeedsCommit(); |
1450 CREATE_SCHEDULER_AND_INIT_SURFACE(scheduler_settings); | 1467 EXPECT_TRUE(client_->needs_begin_frames()); |
1451 | 1468 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client_); |
1452 scheduler->SetNeedsCommit(); | 1469 |
1453 EXPECT_TRUE(client.needs_begin_frames()); | 1470 client_->Reset(); |
1454 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client); | 1471 EXPECT_SCOPED(AdvanceFrame()); |
1455 | 1472 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
1456 client.Reset(); | 1473 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); |
1457 EXPECT_SCOPED(client.AdvanceFrame()); | 1474 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
1458 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 1475 |
1459 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); | 1476 client_->Reset(); |
1460 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1477 scheduler_->NotifyBeginMainFrameStarted(); |
1461 | 1478 |
1462 client.Reset(); | 1479 client_->Reset(); |
1463 scheduler->NotifyBeginMainFrameStarted(); | 1480 SendNextBeginFrame(); |
1464 | |
1465 client.Reset(); | |
1466 client.SendNextBeginFrame(); | |
1467 // This BeginFrame is queued up as a retro frame. | 1481 // This BeginFrame is queued up as a retro frame. |
1468 EXPECT_NO_ACTION(client); | 1482 EXPECT_NO_ACTION(client_); |
1469 // The previous deadline is still pending. | 1483 // The previous deadline is still pending. |
1470 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1484 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
1471 | 1485 |
1472 client.Reset(); | 1486 client_->Reset(); |
1473 // This commit should schedule the (previous) deadline to trigger immediately. | 1487 // This commit should schedule the (previous) deadline to trigger immediately. |
1474 scheduler->NotifyReadyToCommit(); | 1488 scheduler_->NotifyReadyToCommit(); |
1475 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); | 1489 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_); |
1476 | 1490 |
1477 client.Reset(); | 1491 client_->Reset(); |
1478 // The deadline task should trigger causing a draw. | 1492 // The deadline task should trigger causing a draw. |
1479 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1493 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
1480 client.task_runner().RunTasksWhile(client.ImplFrameDeadlinePending(true)); | 1494 task_runner().RunTasksWhile(client_->ImplFrameDeadlinePending(true)); |
1481 EXPECT_ACTION("ScheduledActionAnimate", client, 0, 2); | 1495 EXPECT_ACTION("ScheduledActionAnimate", client_, 0, 2); |
1482 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 1, 2); | 1496 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 1, 2); |
1483 | 1497 |
1484 // Keep animating. | 1498 // Keep animating. |
1485 client.Reset(); | 1499 client_->Reset(); |
1486 scheduler->SetNeedsAnimate(); | 1500 scheduler_->SetNeedsAnimate(); |
1487 scheduler->SetNeedsRedraw(); | 1501 scheduler_->SetNeedsRedraw(); |
1488 EXPECT_NO_ACTION(client); | 1502 EXPECT_NO_ACTION(client_); |
1489 | 1503 |
1490 // Let's advance sufficiently past the next frame's deadline. | 1504 // Let's advance sufficiently past the next frame's deadline. |
1491 client.now_src()->AdvanceNow(BeginFrameArgs::DefaultInterval() + | 1505 now_src()->AdvanceNow(BeginFrameArgs::DefaultInterval() + |
1492 base::TimeDelta::FromMicroseconds(1)); | 1506 base::TimeDelta::FromMicroseconds(1)); |
1493 | 1507 |
1494 // The retro frame should've expired. | 1508 // The retro frame should've expired. |
1495 EXPECT_NO_ACTION(client); | 1509 EXPECT_NO_ACTION(client_); |
1496 } | 1510 } |
1497 | 1511 |
1498 void BeginFramesNotFromClient(bool use_external_begin_frame_source, | 1512 void SchedulerTest::BeginFramesNotFromClient( |
1499 bool throttle_frame_production) { | 1513 bool use_external_begin_frame_source, |
1500 FakeSchedulerClient client; | 1514 bool throttle_frame_production) { |
1501 SchedulerSettings scheduler_settings; | 1515 scheduler_settings_.use_external_begin_frame_source = |
1502 scheduler_settings.use_external_begin_frame_source = | |
1503 use_external_begin_frame_source; | 1516 use_external_begin_frame_source; |
1504 scheduler_settings.throttle_frame_production = throttle_frame_production; | 1517 scheduler_settings_.throttle_frame_production = throttle_frame_production; |
1505 | 1518 SetUpScheduler(true); |
1506 CREATE_SCHEDULER_AND_INIT_SURFACE(scheduler_settings); | |
1507 | 1519 |
1508 // SetNeedsCommit should begin the frame on the next BeginImplFrame | 1520 // SetNeedsCommit should begin the frame on the next BeginImplFrame |
1509 // without calling SetNeedsBeginFrame. | 1521 // without calling SetNeedsBeginFrame. |
1510 scheduler->SetNeedsCommit(); | 1522 scheduler_->SetNeedsCommit(); |
1511 EXPECT_NO_ACTION(client); | 1523 EXPECT_NO_ACTION(client_); |
1512 client.Reset(); | 1524 client_->Reset(); |
1513 | 1525 |
1514 // When the client-driven BeginFrame are disabled, the scheduler posts it's | 1526 // When the client-driven BeginFrame are disabled, the scheduler posts it's |
1515 // own BeginFrame tasks. | 1527 // own BeginFrame tasks. |
1516 client.task_runner().RunPendingTasks(); // Run posted BeginFrame. | 1528 task_runner().RunPendingTasks(); // Run posted BeginFrame. |
1517 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 1529 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
1518 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); | 1530 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); |
1519 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1531 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
1520 client.Reset(); | 1532 client_->Reset(); |
1521 | 1533 |
1522 // If we don't swap on the deadline, we wait for the next BeginFrame. | 1534 // If we don't swap on the deadline, we wait for the next BeginFrame. |
1523 client.task_runner().RunPendingTasks(); // Run posted deadline. | 1535 task_runner().RunPendingTasks(); // Run posted deadline. |
1524 EXPECT_NO_ACTION(client); | 1536 EXPECT_NO_ACTION(client_); |
1525 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 1537 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); |
1526 client.Reset(); | 1538 client_->Reset(); |
1527 | 1539 |
1528 // NotifyReadyToCommit should trigger the commit. | 1540 // NotifyReadyToCommit should trigger the commit. |
1529 scheduler->NotifyBeginMainFrameStarted(); | 1541 scheduler_->NotifyBeginMainFrameStarted(); |
1530 scheduler->NotifyReadyToCommit(); | 1542 scheduler_->NotifyReadyToCommit(); |
1531 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); | 1543 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_); |
1532 client.Reset(); | 1544 client_->Reset(); |
1533 | 1545 |
1534 // BeginImplFrame should prepare the draw. | 1546 // BeginImplFrame should prepare the draw. |
1535 client.task_runner().RunPendingTasks(); // Run posted BeginFrame. | 1547 task_runner().RunPendingTasks(); // Run posted BeginFrame. |
1536 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 1548 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
1537 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); | 1549 EXPECT_ACTION("ScheduledActionAnimate", client_, 1, 2); |
1538 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1550 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
1539 client.Reset(); | 1551 client_->Reset(); |
1540 | 1552 |
1541 // BeginImplFrame deadline should draw. | 1553 // BeginImplFrame deadline should draw. |
1542 client.task_runner().RunTasksWhile(client.ImplFrameDeadlinePending(true)); | 1554 task_runner().RunTasksWhile(client_->ImplFrameDeadlinePending(true)); |
1543 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 1); | 1555 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 0, 1); |
1544 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 1556 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); |
1545 client.Reset(); | 1557 client_->Reset(); |
1546 | 1558 |
1547 // The following BeginImplFrame deadline should SetNeedsBeginFrame(false) | 1559 // The following BeginImplFrame deadline should SetNeedsBeginFrame(false) |
1548 // to avoid excessive toggles. | 1560 // to avoid excessive toggles. |
1549 client.task_runner().RunPendingTasks(); // Run posted BeginFrame. | 1561 task_runner().RunPendingTasks(); // Run posted BeginFrame. |
1550 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); | 1562 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client_); |
1551 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1563 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
1552 client.Reset(); | 1564 client_->Reset(); |
1553 | 1565 |
1554 // Make sure SetNeedsBeginFrame isn't called on the client | 1566 // Make sure SetNeedsBeginFrame isn't called on the client |
1555 // when the BeginFrame is no longer needed. | 1567 // when the BeginFrame is no longer needed. |
1556 client.task_runner().RunPendingTasks(); // Run posted deadline. | 1568 task_runner().RunPendingTasks(); // Run posted deadline. |
1557 EXPECT_NO_ACTION(client); | 1569 EXPECT_NO_ACTION(client_); |
1558 client.Reset(); | 1570 client_->Reset(); |
1559 } | 1571 } |
1560 | 1572 |
1561 TEST(SchedulerTest, SyntheticBeginFrames) { | 1573 TEST_F(SchedulerTest, SyntheticBeginFrames) { |
1562 bool use_external_begin_frame_source = false; | 1574 bool use_external_begin_frame_source = false; |
1563 bool throttle_frame_production = true; | 1575 bool throttle_frame_production = true; |
1564 BeginFramesNotFromClient(use_external_begin_frame_source, | 1576 BeginFramesNotFromClient(use_external_begin_frame_source, |
1565 throttle_frame_production); | 1577 throttle_frame_production); |
1566 } | 1578 } |
1567 | 1579 |
1568 TEST(SchedulerTest, VSyncThrottlingDisabled) { | 1580 TEST_F(SchedulerTest, VSyncThrottlingDisabled) { |
1569 bool use_external_begin_frame_source = true; | 1581 bool use_external_begin_frame_source = true; |
1570 bool throttle_frame_production = false; | 1582 bool throttle_frame_production = false; |
1571 BeginFramesNotFromClient(use_external_begin_frame_source, | 1583 BeginFramesNotFromClient(use_external_begin_frame_source, |
1572 throttle_frame_production); | 1584 throttle_frame_production); |
1573 } | 1585 } |
1574 | 1586 |
1575 TEST(SchedulerTest, SyntheticBeginFrames_And_VSyncThrottlingDisabled) { | 1587 TEST_F(SchedulerTest, SyntheticBeginFrames_And_VSyncThrottlingDisabled) { |
1576 bool use_external_begin_frame_source = false; | 1588 bool use_external_begin_frame_source = false; |
1577 bool throttle_frame_production = false; | 1589 bool throttle_frame_production = false; |
1578 BeginFramesNotFromClient(use_external_begin_frame_source, | 1590 BeginFramesNotFromClient(use_external_begin_frame_source, |
1579 throttle_frame_production); | 1591 throttle_frame_production); |
1580 } | 1592 } |
1581 | 1593 |
1582 void BeginFramesNotFromClient_SwapThrottled( | 1594 void SchedulerTest::BeginFramesNotFromClient_SwapThrottled( |
1583 bool use_external_begin_frame_source, | 1595 bool use_external_begin_frame_source, |
1584 bool throttle_frame_production) { | 1596 bool throttle_frame_production) { |
1585 FakeSchedulerClient client; | 1597 scheduler_settings_.use_external_begin_frame_source = |
1586 SchedulerSettings scheduler_settings; | |
1587 scheduler_settings.use_external_begin_frame_source = | |
1588 use_external_begin_frame_source; | 1598 use_external_begin_frame_source; |
1589 scheduler_settings.throttle_frame_production = throttle_frame_production; | 1599 scheduler_settings_.throttle_frame_production = throttle_frame_production; |
1590 | 1600 SetUpScheduler(true); |
1591 CREATE_SCHEDULER_AND_INIT_SURFACE(scheduler_settings); | 1601 |
1592 scheduler->SetEstimatedParentDrawTime(base::TimeDelta::FromMicroseconds(1)); | 1602 scheduler_->SetEstimatedParentDrawTime(base::TimeDelta::FromMicroseconds(1)); |
1593 | 1603 |
1594 // To test swap ack throttling, this test disables automatic swap acks. | 1604 // To test swap ack throttling, this test disables automatic swap acks. |
1595 scheduler->SetMaxSwapsPending(1); | 1605 scheduler_->SetMaxSwapsPending(1); |
1596 client.SetAutomaticSwapAck(false); | 1606 client_->SetAutomaticSwapAck(false); |
1597 | 1607 |
1598 // SetNeedsCommit should begin the frame on the next BeginImplFrame. | 1608 // SetNeedsCommit should begin the frame on the next BeginImplFrame. |
1599 client.Reset(); | 1609 client_->Reset(); |
1600 scheduler->SetNeedsCommit(); | 1610 scheduler_->SetNeedsCommit(); |
1601 EXPECT_NO_ACTION(client); | 1611 EXPECT_NO_ACTION(client_); |
1602 client.Reset(); | 1612 client_->Reset(); |
1603 | 1613 |
1604 // Trigger the first BeginImplFrame and BeginMainFrame | 1614 // Trigger the first BeginImplFrame and BeginMainFrame |
1605 EXPECT_SCOPED(client.AdvanceFrame()); | 1615 EXPECT_SCOPED(AdvanceFrame()); |
1606 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 1616 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
1607 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); | 1617 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); |
1608 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1618 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
1609 client.Reset(); | 1619 client_->Reset(); |
1610 | 1620 |
1611 // NotifyReadyToCommit should trigger the pending commit and draw. | 1621 // NotifyReadyToCommit should trigger the pending commit and draw. |
1612 scheduler->NotifyBeginMainFrameStarted(); | 1622 scheduler_->NotifyBeginMainFrameStarted(); |
1613 scheduler->NotifyReadyToCommit(); | 1623 scheduler_->NotifyReadyToCommit(); |
1614 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); | 1624 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_); |
1615 client.Reset(); | 1625 client_->Reset(); |
1616 | 1626 |
1617 // Swapping will put us into a swap throttled state. | 1627 // Swapping will put us into a swap throttled state. |
1618 // Run posted deadline. | 1628 // Run posted deadline. |
1619 client.task_runner().RunTasksWhile(client.ImplFrameDeadlinePending(true)); | 1629 task_runner().RunTasksWhile(client_->ImplFrameDeadlinePending(true)); |
1620 EXPECT_ACTION("ScheduledActionAnimate", client, 0, 2); | 1630 EXPECT_ACTION("ScheduledActionAnimate", client_, 0, 2); |
1621 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 1, 2); | 1631 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 1, 2); |
1622 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 1632 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); |
1623 client.Reset(); | 1633 client_->Reset(); |
1624 | 1634 |
1625 // While swap throttled, BeginFrames should trigger BeginImplFrames, | 1635 // While swap throttled, BeginFrames should trigger BeginImplFrames, |
1626 // but not a BeginMainFrame or draw. | 1636 // but not a BeginMainFrame or draw. |
1627 scheduler->SetNeedsCommit(); | 1637 scheduler_->SetNeedsCommit(); |
1628 scheduler->SetNeedsRedraw(); | 1638 scheduler_->SetNeedsRedraw(); |
1629 EXPECT_SCOPED(client.AdvanceFrame()); // Run posted BeginFrame. | 1639 EXPECT_SCOPED(AdvanceFrame()); // Run posted BeginFrame. |
1630 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 1640 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
1631 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); | 1641 EXPECT_ACTION("ScheduledActionAnimate", client_, 1, 2); |
1632 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1642 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
1633 client.Reset(); | 1643 client_->Reset(); |
1634 | 1644 |
1635 // Let time pass sufficiently beyond the regular deadline but not beyond the | 1645 // Let time pass sufficiently beyond the regular deadline but not beyond the |
1636 // late deadline. | 1646 // late deadline. |
1637 client.now_src()->AdvanceNow(BeginFrameArgs::DefaultInterval() - | 1647 now_src()->AdvanceNow(BeginFrameArgs::DefaultInterval() - |
1638 base::TimeDelta::FromMicroseconds(1)); | 1648 base::TimeDelta::FromMicroseconds(1)); |
1639 client.task_runner().RunUntilTime(client.now_src()->Now()); | 1649 task_runner().RunUntilTime(now_src()->Now()); |
1640 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1650 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
1641 | 1651 |
1642 // Take us out of a swap throttled state. | 1652 // Take us out of a swap throttled state. |
1643 scheduler->DidSwapBuffersComplete(); | 1653 scheduler_->DidSwapBuffersComplete(); |
1644 EXPECT_SINGLE_ACTION("ScheduledActionSendBeginMainFrame", client); | 1654 EXPECT_SINGLE_ACTION("ScheduledActionSendBeginMainFrame", client_); |
1645 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1655 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
1646 client.Reset(); | 1656 client_->Reset(); |
1647 | 1657 |
1648 // Verify that the deadline was rescheduled. | 1658 // Verify that the deadline was rescheduled. |
1649 // We can't use RunUntilTime(now) here because the next frame is also | 1659 // We can't use RunUntilTime(now) here because the next frame is also |
1650 // scheduled if throttle_frame_production = false. | 1660 // scheduled if throttle_frame_production = false. |
1651 base::TimeTicks before_deadline = client.now_src()->Now(); | 1661 base::TimeTicks before_deadline = now_src()->Now(); |
1652 client.task_runner().RunTasksWhile(client.ImplFrameDeadlinePending(true)); | 1662 task_runner().RunTasksWhile(client_->ImplFrameDeadlinePending(true)); |
1653 base::TimeTicks after_deadline = client.now_src()->Now(); | 1663 base::TimeTicks after_deadline = now_src()->Now(); |
1654 EXPECT_EQ(after_deadline, before_deadline); | 1664 EXPECT_EQ(after_deadline, before_deadline); |
1655 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 1665 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); |
1656 client.Reset(); | 1666 client_->Reset(); |
1657 } | 1667 } |
1658 | 1668 |
1659 TEST(SchedulerTest, SyntheticBeginFrames_SwapThrottled) { | 1669 TEST_F(SchedulerTest, SyntheticBeginFrames_SwapThrottled) { |
1660 bool use_external_begin_frame_source = false; | 1670 bool use_external_begin_frame_source = false; |
1661 bool throttle_frame_production = true; | 1671 bool throttle_frame_production = true; |
1662 BeginFramesNotFromClient_SwapThrottled(use_external_begin_frame_source, | 1672 BeginFramesNotFromClient_SwapThrottled(use_external_begin_frame_source, |
1663 throttle_frame_production); | 1673 throttle_frame_production); |
1664 } | 1674 } |
1665 | 1675 |
1666 TEST(SchedulerTest, VSyncThrottlingDisabled_SwapThrottled) { | 1676 TEST_F(SchedulerTest, VSyncThrottlingDisabled_SwapThrottled) { |
1667 bool use_external_begin_frame_source = true; | 1677 bool use_external_begin_frame_source = true; |
1668 bool throttle_frame_production = false; | 1678 bool throttle_frame_production = false; |
1669 BeginFramesNotFromClient_SwapThrottled(use_external_begin_frame_source, | 1679 BeginFramesNotFromClient_SwapThrottled(use_external_begin_frame_source, |
1670 throttle_frame_production); | 1680 throttle_frame_production); |
1671 } | 1681 } |
1672 | 1682 |
1673 TEST(SchedulerTest, | 1683 TEST_F(SchedulerTest, |
1674 SyntheticBeginFrames_And_VSyncThrottlingDisabled_SwapThrottled) { | 1684 SyntheticBeginFrames_And_VSyncThrottlingDisabled_SwapThrottled) { |
1675 bool use_external_begin_frame_source = false; | 1685 bool use_external_begin_frame_source = false; |
1676 bool throttle_frame_production = false; | 1686 bool throttle_frame_production = false; |
1677 BeginFramesNotFromClient_SwapThrottled(use_external_begin_frame_source, | 1687 BeginFramesNotFromClient_SwapThrottled(use_external_begin_frame_source, |
1678 throttle_frame_production); | 1688 throttle_frame_production); |
1679 } | 1689 } |
1680 | 1690 |
1681 TEST(SchedulerTest, DidLoseOutputSurfaceAfterOutputSurfaceIsInitialized) { | 1691 TEST_F(SchedulerTest, DidLoseOutputSurfaceAfterOutputSurfaceIsInitialized) { |
1682 FakeSchedulerClient client; | 1692 scheduler_settings_.use_external_begin_frame_source = true; |
1683 SchedulerSettings scheduler_settings; | 1693 SetUpScheduler(false); |
1684 scheduler_settings.use_external_begin_frame_source = true; | 1694 |
1685 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings); | 1695 scheduler_->SetCanStart(); |
1686 scheduler->SetCanStart(); | 1696 scheduler_->SetVisible(true); |
1687 scheduler->SetVisible(true); | 1697 scheduler_->SetCanDraw(true); |
1688 scheduler->SetCanDraw(true); | 1698 |
1689 | 1699 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client_); |
1690 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); | 1700 client_->Reset(); |
1691 client.Reset(); | 1701 scheduler_->DidCreateAndInitializeOutputSurface(); |
1692 scheduler->DidCreateAndInitializeOutputSurface(); | 1702 EXPECT_NO_ACTION(client_); |
1693 EXPECT_NO_ACTION(client); | 1703 |
1694 | 1704 scheduler_->DidLoseOutputSurface(); |
1695 scheduler->DidLoseOutputSurface(); | 1705 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client_); |
1696 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); | 1706 } |
1697 } | 1707 |
1698 | 1708 TEST_F(SchedulerTest, DidLoseOutputSurfaceAfterBeginFrameStarted) { |
1699 TEST(SchedulerTest, DidLoseOutputSurfaceAfterBeginFrameStarted) { | 1709 scheduler_settings_.use_external_begin_frame_source = true; |
1700 FakeSchedulerClient client; | 1710 SetUpScheduler(true); |
1701 SchedulerSettings scheduler_settings; | |
1702 scheduler_settings.use_external_begin_frame_source = true; | |
1703 | |
1704 CREATE_SCHEDULER_AND_INIT_SURFACE(scheduler_settings); | |
1705 | 1711 |
1706 // SetNeedsCommit should begin the frame. | 1712 // SetNeedsCommit should begin the frame. |
1707 scheduler->SetNeedsCommit(); | 1713 scheduler_->SetNeedsCommit(); |
1708 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client); | 1714 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client_); |
1709 | 1715 |
1710 client.Reset(); | 1716 client_->Reset(); |
1711 EXPECT_SCOPED(client.AdvanceFrame()); | 1717 EXPECT_SCOPED(AdvanceFrame()); |
1712 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 1718 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
1713 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); | 1719 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); |
1714 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1720 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
1715 | 1721 |
1716 client.Reset(); | 1722 client_->Reset(); |
1717 scheduler->DidLoseOutputSurface(); | 1723 scheduler_->DidLoseOutputSurface(); |
1718 // Do nothing when impl frame is in deadine pending state. | 1724 // Do nothing when impl frame is in deadine pending state. |
1719 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(false)", client); | 1725 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(false)", client_); |
1720 | 1726 |
1721 client.Reset(); | 1727 client_->Reset(); |
1722 scheduler->NotifyBeginMainFrameStarted(); | 1728 scheduler_->NotifyBeginMainFrameStarted(); |
1723 scheduler->NotifyReadyToCommit(); | 1729 scheduler_->NotifyReadyToCommit(); |
1724 EXPECT_ACTION("ScheduledActionCommit", client, 0, 1); | 1730 EXPECT_ACTION("ScheduledActionCommit", client_, 0, 1); |
1725 | 1731 |
1726 client.Reset(); | 1732 client_->Reset(); |
1727 client.task_runner().RunPendingTasks(); // Run posted deadline. | 1733 task_runner().RunPendingTasks(); // Run posted deadline. |
1728 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); | 1734 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client_); |
1729 } | 1735 } |
1730 | 1736 |
1731 void DidLoseOutputSurfaceAfterBeginFrameStartedWithHighLatency( | 1737 void SchedulerTest::DidLoseOutputSurfaceAfterBeginFrameStartedWithHighLatency( |
1732 bool impl_side_painting) { | 1738 bool impl_side_painting) { |
1733 FakeSchedulerClient client; | 1739 scheduler_settings_.impl_side_painting = impl_side_painting; |
1734 SchedulerSettings scheduler_settings; | 1740 scheduler_settings_.use_external_begin_frame_source = true; |
1735 scheduler_settings.impl_side_painting = impl_side_painting; | 1741 SetUpScheduler(true); |
1736 scheduler_settings.use_external_begin_frame_source = true; | |
1737 | |
1738 CREATE_SCHEDULER_AND_INIT_SURFACE(scheduler_settings); | |
1739 | 1742 |
1740 // SetNeedsCommit should begin the frame. | 1743 // SetNeedsCommit should begin the frame. |
1741 scheduler->SetNeedsCommit(); | 1744 scheduler_->SetNeedsCommit(); |
1742 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client); | 1745 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client_); |
1743 | 1746 |
1744 client.Reset(); | 1747 client_->Reset(); |
1745 EXPECT_SCOPED(client.AdvanceFrame()); | 1748 EXPECT_SCOPED(AdvanceFrame()); |
1746 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 1749 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
1747 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); | 1750 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); |
1748 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1751 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
1749 | 1752 |
1750 client.Reset(); | 1753 client_->Reset(); |
1751 scheduler->DidLoseOutputSurface(); | 1754 scheduler_->DidLoseOutputSurface(); |
1752 // Do nothing when impl frame is in deadine pending state. | 1755 // Do nothing when impl frame is in deadine pending state. |
1753 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(false)", client); | 1756 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(false)", client_); |
1754 | 1757 |
1755 client.Reset(); | 1758 client_->Reset(); |
1756 // Run posted deadline. | 1759 // Run posted deadline. |
1757 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1760 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
1758 client.task_runner().RunTasksWhile(client.ImplFrameDeadlinePending(true)); | 1761 task_runner().RunTasksWhile(client_->ImplFrameDeadlinePending(true)); |
1759 // OnBeginImplFrameDeadline didn't schedule any actions because main frame is | 1762 // OnBeginImplFrameDeadline didn't schedule any actions because main frame is |
1760 // not yet completed. | 1763 // not yet completed. |
1761 EXPECT_NO_ACTION(client); | 1764 EXPECT_NO_ACTION(client_); |
1762 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 1765 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); |
1763 | 1766 |
1764 // BeginImplFrame is not started. | 1767 // BeginImplFrame is not started. |
1765 client.task_runner().RunUntilTime(client.now_src()->Now() + | 1768 task_runner().RunUntilTime(now_src()->Now() + |
1766 base::TimeDelta::FromMilliseconds(10)); | 1769 base::TimeDelta::FromMilliseconds(10)); |
1767 EXPECT_NO_ACTION(client); | 1770 EXPECT_NO_ACTION(client_); |
1768 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 1771 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); |
1769 | 1772 |
1770 client.Reset(); | 1773 client_->Reset(); |
1771 scheduler->NotifyBeginMainFrameStarted(); | 1774 scheduler_->NotifyBeginMainFrameStarted(); |
1772 scheduler->NotifyReadyToCommit(); | 1775 scheduler_->NotifyReadyToCommit(); |
1773 if (impl_side_painting) { | 1776 if (impl_side_painting) { |
1774 EXPECT_ACTION("ScheduledActionCommit", client, 0, 3); | 1777 EXPECT_ACTION("ScheduledActionCommit", client_, 0, 3); |
1775 EXPECT_ACTION("ScheduledActionActivateSyncTree", client, 1, 3); | 1778 EXPECT_ACTION("ScheduledActionActivateSyncTree", client_, 1, 3); |
1776 EXPECT_ACTION("ScheduledActionBeginOutputSurfaceCreation", client, 2, 3); | 1779 EXPECT_ACTION("ScheduledActionBeginOutputSurfaceCreation", client_, 2, 3); |
1777 } else { | 1780 } else { |
1778 EXPECT_ACTION("ScheduledActionCommit", client, 0, 2); | 1781 EXPECT_ACTION("ScheduledActionCommit", client_, 0, 2); |
1779 EXPECT_ACTION("ScheduledActionBeginOutputSurfaceCreation", client, 1, 2); | 1782 EXPECT_ACTION("ScheduledActionBeginOutputSurfaceCreation", client_, 1, 2); |
1780 } | 1783 } |
1781 } | 1784 } |
1782 | 1785 |
1783 TEST(SchedulerTest, DidLoseOutputSurfaceAfterBeginFrameStartedWithHighLatency) { | 1786 TEST_F(SchedulerTest, |
1787 DidLoseOutputSurfaceAfterBeginFrameStartedWithHighLatency) { | |
1784 bool impl_side_painting = false; | 1788 bool impl_side_painting = false; |
1785 DidLoseOutputSurfaceAfterBeginFrameStartedWithHighLatency(impl_side_painting); | 1789 DidLoseOutputSurfaceAfterBeginFrameStartedWithHighLatency(impl_side_painting); |
1786 } | 1790 } |
1787 | 1791 |
1788 TEST(SchedulerTest, | 1792 TEST_F(SchedulerTest, |
1789 DidLoseOutputSurfaceAfterBeginFrameStartedWithHighLatencyWithImplPaint) { | 1793 DidLoseOutputSurfaceAfterBeginFrameStartedWithHighLatencyWithImplPaint) { |
1790 bool impl_side_painting = true; | 1794 bool impl_side_painting = true; |
1791 DidLoseOutputSurfaceAfterBeginFrameStartedWithHighLatency(impl_side_painting); | 1795 DidLoseOutputSurfaceAfterBeginFrameStartedWithHighLatency(impl_side_painting); |
1792 } | 1796 } |
1793 | 1797 |
1794 void DidLoseOutputSurfaceAfterReadyToCommit(bool impl_side_painting) { | 1798 void SchedulerTest::DidLoseOutputSurfaceAfterReadyToCommit( |
1795 FakeSchedulerClient client; | 1799 bool impl_side_painting) { |
1796 SchedulerSettings scheduler_settings; | 1800 scheduler_settings_.impl_side_painting = impl_side_painting; |
1797 scheduler_settings.impl_side_painting = impl_side_painting; | 1801 scheduler_settings_.use_external_begin_frame_source = true; |
1798 scheduler_settings.use_external_begin_frame_source = true; | 1802 SetUpScheduler(true); |
1799 | |
1800 CREATE_SCHEDULER_AND_INIT_SURFACE(scheduler_settings); | |
1801 | 1803 |
1802 // SetNeedsCommit should begin the frame. | 1804 // SetNeedsCommit should begin the frame. |
1803 scheduler->SetNeedsCommit(); | 1805 scheduler_->SetNeedsCommit(); |
1804 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client); | 1806 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client_); |
1805 | 1807 |
1806 client.Reset(); | 1808 client_->Reset(); |
1807 EXPECT_SCOPED(client.AdvanceFrame()); | 1809 EXPECT_SCOPED(AdvanceFrame()); |
1808 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 1810 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
1809 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); | 1811 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); |
1810 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1812 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
1811 | 1813 |
1812 client.Reset(); | 1814 client_->Reset(); |
1813 scheduler->NotifyBeginMainFrameStarted(); | 1815 scheduler_->NotifyBeginMainFrameStarted(); |
1814 scheduler->NotifyReadyToCommit(); | 1816 scheduler_->NotifyReadyToCommit(); |
1815 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); | 1817 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_); |
1816 | 1818 |
1817 client.Reset(); | 1819 client_->Reset(); |
1818 scheduler->DidLoseOutputSurface(); | 1820 scheduler_->DidLoseOutputSurface(); |
1819 if (impl_side_painting) { | 1821 if (impl_side_painting) { |
1820 // Sync tree should be forced to activate. | 1822 // Sync tree should be forced to activate. |
1821 EXPECT_ACTION("ScheduledActionActivateSyncTree", client, 0, 2); | 1823 EXPECT_ACTION("ScheduledActionActivateSyncTree", client_, 0, 2); |
1822 EXPECT_ACTION("SetNeedsBeginFrames(false)", client, 1, 2); | 1824 EXPECT_ACTION("SetNeedsBeginFrames(false)", client_, 1, 2); |
1823 } else { | 1825 } else { |
1824 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(false)", client); | 1826 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(false)", client_); |
1825 } | 1827 } |
1826 | 1828 |
1827 client.Reset(); | 1829 client_->Reset(); |
1828 client.task_runner().RunPendingTasks(); // Run posted deadline. | 1830 task_runner().RunPendingTasks(); // Run posted deadline. |
1829 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); | 1831 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client_); |
1830 } | 1832 } |
1831 | 1833 |
1832 TEST(SchedulerTest, DidLoseOutputSurfaceAfterReadyToCommit) { | 1834 TEST_F(SchedulerTest, DidLoseOutputSurfaceAfterReadyToCommit) { |
1833 DidLoseOutputSurfaceAfterReadyToCommit(false); | 1835 DidLoseOutputSurfaceAfterReadyToCommit(false); |
1834 } | 1836 } |
1835 | 1837 |
1836 TEST(SchedulerTest, DidLoseOutputSurfaceAfterReadyToCommitWithImplPainting) { | 1838 TEST_F(SchedulerTest, DidLoseOutputSurfaceAfterReadyToCommitWithImplPainting) { |
1837 DidLoseOutputSurfaceAfterReadyToCommit(true); | 1839 DidLoseOutputSurfaceAfterReadyToCommit(true); |
1838 } | 1840 } |
1839 | 1841 |
1840 TEST(SchedulerTest, DidLoseOutputSurfaceAfterSetNeedsPrepareTiles) { | 1842 TEST_F(SchedulerTest, DidLoseOutputSurfaceAfterSetNeedsPrepareTiles) { |
1841 FakeSchedulerClient client; | 1843 scheduler_settings_.use_external_begin_frame_source = true; |
1842 SchedulerSettings scheduler_settings; | 1844 SetUpScheduler(true); |
1843 scheduler_settings.use_external_begin_frame_source = true; | 1845 |
1844 | 1846 scheduler_->SetNeedsPrepareTiles(); |
1845 CREATE_SCHEDULER_AND_INIT_SURFACE(scheduler_settings); | 1847 scheduler_->SetNeedsRedraw(); |
1846 | 1848 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client_); |
1847 scheduler->SetNeedsPrepareTiles(); | 1849 |
1848 scheduler->SetNeedsRedraw(); | 1850 client_->Reset(); |
1849 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client); | 1851 EXPECT_SCOPED(AdvanceFrame()); |
1850 | 1852 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
1851 client.Reset(); | 1853 EXPECT_ACTION("ScheduledActionAnimate", client_, 1, 2); |
1852 EXPECT_SCOPED(client.AdvanceFrame()); | 1854 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
1853 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 1855 |
1854 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); | 1856 client_->Reset(); |
1855 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1857 scheduler_->DidLoseOutputSurface(); |
1856 | 1858 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(false)", client_); |
1857 client.Reset(); | 1859 |
1858 scheduler->DidLoseOutputSurface(); | 1860 client_->Reset(); |
1859 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(false)", client); | 1861 task_runner().RunPendingTasks(); // Run posted deadline. |
1860 | 1862 EXPECT_ACTION("ScheduledActionPrepareTiles", client_, 0, 2); |
1861 client.Reset(); | 1863 EXPECT_ACTION("ScheduledActionBeginOutputSurfaceCreation", client_, 1, 2); |
1862 client.task_runner().RunPendingTasks(); // Run posted deadline. | 1864 } |
1863 EXPECT_ACTION("ScheduledActionPrepareTiles", client, 0, 2); | 1865 |
1864 EXPECT_ACTION("ScheduledActionBeginOutputSurfaceCreation", client, 1, 2); | 1866 TEST_F(SchedulerTest, DidLoseOutputSurfaceAfterBeginRetroFramePosted) { |
1865 } | 1867 scheduler_settings_.use_external_begin_frame_source = true; |
1866 | 1868 SetUpScheduler(true); |
1867 TEST(SchedulerTest, DidLoseOutputSurfaceAfterBeginRetroFramePosted) { | |
1868 FakeSchedulerClient client; | |
1869 SchedulerSettings scheduler_settings; | |
1870 scheduler_settings.use_external_begin_frame_source = true; | |
1871 | |
1872 CREATE_SCHEDULER_AND_INIT_SURFACE(scheduler_settings); | |
1873 | 1869 |
1874 // SetNeedsCommit should begin the frame on the next BeginImplFrame. | 1870 // SetNeedsCommit should begin the frame on the next BeginImplFrame. |
1875 scheduler->SetNeedsCommit(); | 1871 scheduler_->SetNeedsCommit(); |
1876 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client); | 1872 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client_); |
1877 | 1873 |
1878 // Create a BeginFrame with a long deadline to avoid race conditions. | 1874 // Create a BeginFrame with a long deadline to avoid race conditions. |
1879 // This is the first BeginFrame, which will be handled immediately. | 1875 // This is the first BeginFrame, which will be handled immediately. |
1880 client.Reset(); | 1876 client_->Reset(); |
1881 BeginFrameArgs args = | 1877 BeginFrameArgs args = |
1882 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, client.now_src()); | 1878 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, now_src()); |
1883 args.deadline += base::TimeDelta::FromHours(1); | 1879 args.deadline += base::TimeDelta::FromHours(1); |
1884 client.fake_external_begin_frame_source()->TestOnBeginFrame(args); | 1880 fake_external_begin_frame_source()->TestOnBeginFrame(args); |
1885 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 1881 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
1886 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); | 1882 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); |
1887 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1883 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
1888 EXPECT_TRUE(client.needs_begin_frames()); | 1884 EXPECT_TRUE(client_->needs_begin_frames()); |
1889 | 1885 |
1890 // Queue BeginFrames while we are still handling the previous BeginFrame. | 1886 // Queue BeginFrames while we are still handling the previous BeginFrame. |
1891 args.frame_time += base::TimeDelta::FromSeconds(1); | 1887 args.frame_time += base::TimeDelta::FromSeconds(1); |
1892 client.fake_external_begin_frame_source()->TestOnBeginFrame(args); | 1888 fake_external_begin_frame_source()->TestOnBeginFrame(args); |
1893 args.frame_time += base::TimeDelta::FromSeconds(1); | 1889 args.frame_time += base::TimeDelta::FromSeconds(1); |
1894 client.fake_external_begin_frame_source()->TestOnBeginFrame(args); | 1890 fake_external_begin_frame_source()->TestOnBeginFrame(args); |
1895 | 1891 |
1896 // If we don't swap on the deadline, we wait for the next BeginImplFrame. | 1892 // If we don't swap on the deadline, we wait for the next BeginImplFrame. |
1897 client.Reset(); | 1893 client_->Reset(); |
1898 client.task_runner().RunPendingTasks(); // Run posted deadline. | 1894 task_runner().RunPendingTasks(); // Run posted deadline. |
1899 EXPECT_NO_ACTION(client); | 1895 EXPECT_NO_ACTION(client_); |
1900 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 1896 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); |
1901 EXPECT_TRUE(client.needs_begin_frames()); | 1897 EXPECT_TRUE(client_->needs_begin_frames()); |
1902 | 1898 |
1903 // NotifyReadyToCommit should trigger the commit. | 1899 // NotifyReadyToCommit should trigger the commit. |
1904 client.Reset(); | 1900 client_->Reset(); |
1905 scheduler->NotifyBeginMainFrameStarted(); | 1901 scheduler_->NotifyBeginMainFrameStarted(); |
1906 scheduler->NotifyReadyToCommit(); | 1902 scheduler_->NotifyReadyToCommit(); |
1907 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); | 1903 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_); |
1908 EXPECT_TRUE(client.needs_begin_frames()); | 1904 EXPECT_TRUE(client_->needs_begin_frames()); |
1909 | 1905 |
1910 client.Reset(); | 1906 client_->Reset(); |
1911 EXPECT_FALSE(scheduler->IsBeginRetroFrameArgsEmpty()); | 1907 EXPECT_FALSE(scheduler_->IsBeginRetroFrameArgsEmpty()); |
1912 scheduler->DidLoseOutputSurface(); | 1908 scheduler_->DidLoseOutputSurface(); |
1913 EXPECT_ACTION("ScheduledActionBeginOutputSurfaceCreation", client, 0, 2); | 1909 EXPECT_ACTION("ScheduledActionBeginOutputSurfaceCreation", client_, 0, 2); |
1914 EXPECT_ACTION("SetNeedsBeginFrames(false)", client, 1, 2); | 1910 EXPECT_ACTION("SetNeedsBeginFrames(false)", client_, 1, 2); |
1915 EXPECT_TRUE(scheduler->IsBeginRetroFrameArgsEmpty()); | 1911 EXPECT_TRUE(scheduler_->IsBeginRetroFrameArgsEmpty()); |
1916 | 1912 |
1917 // Posted BeginRetroFrame is aborted. | 1913 // Posted BeginRetroFrame is aborted. |
1918 client.Reset(); | 1914 client_->Reset(); |
1919 client.task_runner().RunPendingTasks(); | 1915 task_runner().RunPendingTasks(); |
1920 EXPECT_NO_ACTION(client); | 1916 EXPECT_NO_ACTION(client_); |
1921 } | 1917 } |
1922 | 1918 |
1923 TEST(SchedulerTest, DidLoseOutputSurfaceDuringBeginRetroFrameRunning) { | 1919 TEST_F(SchedulerTest, DidLoseOutputSurfaceDuringBeginRetroFrameRunning) { |
1924 FakeSchedulerClient client; | 1920 scheduler_settings_.use_external_begin_frame_source = true; |
1925 SchedulerSettings scheduler_settings; | 1921 SetUpScheduler(true); |
1926 scheduler_settings.use_external_begin_frame_source = true; | |
1927 | |
1928 CREATE_SCHEDULER_AND_INIT_SURFACE(scheduler_settings); | |
1929 | 1922 |
1930 // SetNeedsCommit should begin the frame on the next BeginImplFrame. | 1923 // SetNeedsCommit should begin the frame on the next BeginImplFrame. |
1931 scheduler->SetNeedsCommit(); | 1924 scheduler_->SetNeedsCommit(); |
1932 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client); | 1925 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client_); |
1933 | 1926 |
1934 // Create a BeginFrame with a long deadline to avoid race conditions. | 1927 // Create a BeginFrame with a long deadline to avoid race conditions. |
1935 // This is the first BeginFrame, which will be handled immediately. | 1928 // This is the first BeginFrame, which will be handled immediately. |
1936 client.Reset(); | 1929 client_->Reset(); |
1937 BeginFrameArgs args = | 1930 BeginFrameArgs args = |
1938 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, client.now_src()); | 1931 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, now_src()); |
1939 args.deadline += base::TimeDelta::FromHours(1); | 1932 args.deadline += base::TimeDelta::FromHours(1); |
1940 client.fake_external_begin_frame_source()->TestOnBeginFrame(args); | 1933 fake_external_begin_frame_source()->TestOnBeginFrame(args); |
1941 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 1934 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
1942 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); | 1935 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); |
1943 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1936 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
1944 EXPECT_TRUE(client.needs_begin_frames()); | 1937 EXPECT_TRUE(client_->needs_begin_frames()); |
1945 | 1938 |
1946 // Queue BeginFrames while we are still handling the previous BeginFrame. | 1939 // Queue BeginFrames while we are still handling the previous BeginFrame. |
1947 args.frame_time += base::TimeDelta::FromSeconds(1); | 1940 args.frame_time += base::TimeDelta::FromSeconds(1); |
1948 client.fake_external_begin_frame_source()->TestOnBeginFrame(args); | 1941 fake_external_begin_frame_source()->TestOnBeginFrame(args); |
1949 args.frame_time += base::TimeDelta::FromSeconds(1); | 1942 args.frame_time += base::TimeDelta::FromSeconds(1); |
1950 client.fake_external_begin_frame_source()->TestOnBeginFrame(args); | 1943 fake_external_begin_frame_source()->TestOnBeginFrame(args); |
1951 | 1944 |
1952 // If we don't swap on the deadline, we wait for the next BeginImplFrame. | 1945 // If we don't swap on the deadline, we wait for the next BeginImplFrame. |
1953 client.Reset(); | 1946 client_->Reset(); |
1954 client.task_runner().RunPendingTasks(); // Run posted deadline. | 1947 task_runner().RunPendingTasks(); // Run posted deadline. |
1955 EXPECT_NO_ACTION(client); | 1948 EXPECT_NO_ACTION(client_); |
1956 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 1949 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); |
1957 EXPECT_TRUE(client.needs_begin_frames()); | 1950 EXPECT_TRUE(client_->needs_begin_frames()); |
1958 | 1951 |
1959 // NotifyReadyToCommit should trigger the commit. | 1952 // NotifyReadyToCommit should trigger the commit. |
1960 client.Reset(); | 1953 client_->Reset(); |
1961 scheduler->NotifyBeginMainFrameStarted(); | 1954 scheduler_->NotifyBeginMainFrameStarted(); |
1962 scheduler->NotifyReadyToCommit(); | 1955 scheduler_->NotifyReadyToCommit(); |
1963 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); | 1956 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_); |
1964 EXPECT_TRUE(client.needs_begin_frames()); | 1957 EXPECT_TRUE(client_->needs_begin_frames()); |
1965 | 1958 |
1966 // BeginImplFrame should prepare the draw. | 1959 // BeginImplFrame should prepare the draw. |
1967 client.Reset(); | 1960 client_->Reset(); |
1968 client.task_runner().RunPendingTasks(); // Run posted BeginRetroFrame. | 1961 task_runner().RunPendingTasks(); // Run posted BeginRetroFrame. |
1969 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 1962 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
1970 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); | 1963 EXPECT_ACTION("ScheduledActionAnimate", client_, 1, 2); |
1971 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1964 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
1972 EXPECT_TRUE(client.needs_begin_frames()); | 1965 EXPECT_TRUE(client_->needs_begin_frames()); |
1973 | 1966 |
1974 client.Reset(); | 1967 client_->Reset(); |
1975 EXPECT_FALSE(scheduler->IsBeginRetroFrameArgsEmpty()); | 1968 EXPECT_FALSE(scheduler_->IsBeginRetroFrameArgsEmpty()); |
1976 scheduler->DidLoseOutputSurface(); | 1969 scheduler_->DidLoseOutputSurface(); |
1977 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(false)", client); | 1970 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(false)", client_); |
1978 EXPECT_TRUE(scheduler->IsBeginRetroFrameArgsEmpty()); | 1971 EXPECT_TRUE(scheduler_->IsBeginRetroFrameArgsEmpty()); |
1979 | 1972 |
1980 // BeginImplFrame deadline should abort drawing. | 1973 // BeginImplFrame deadline should abort drawing. |
1981 client.Reset(); | 1974 client_->Reset(); |
1982 client.task_runner().RunPendingTasks(); // Run posted deadline. | 1975 task_runner().RunPendingTasks(); // Run posted deadline. |
1983 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); | 1976 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client_); |
1984 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 1977 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); |
1985 EXPECT_FALSE(client.needs_begin_frames()); | 1978 EXPECT_FALSE(client_->needs_begin_frames()); |
1986 | 1979 |
1987 // No more BeginRetroFrame because BeginRetroFrame queue is cleared. | 1980 // No more BeginRetroFrame because BeginRetroFrame queue is cleared. |
1988 client.Reset(); | 1981 client_->Reset(); |
1989 client.task_runner().RunPendingTasks(); | 1982 task_runner().RunPendingTasks(); |
1990 EXPECT_NO_ACTION(client); | 1983 EXPECT_NO_ACTION(client_); |
1991 } | 1984 } |
1992 | 1985 |
1993 TEST(SchedulerTest, | 1986 TEST_F(SchedulerTest, |
1994 StopBeginFrameAfterDidLoseOutputSurfaceWithSyntheticBeginFrameSource) { | 1987 StopBeginFrameAfterDidLoseOutputSurfaceWithSyntheticBeginFrameSource) { |
1995 FakeSchedulerClient client; | 1988 SetUpScheduler(true); |
1996 SchedulerSettings scheduler_settings; | |
1997 | |
1998 CREATE_SCHEDULER_AND_INIT_SURFACE(scheduler_settings); | |
1999 | 1989 |
2000 // SetNeedsCommit should begin the frame on the next BeginImplFrame. | 1990 // SetNeedsCommit should begin the frame on the next BeginImplFrame. |
2001 EXPECT_FALSE(scheduler->frame_source().NeedsBeginFrames()); | 1991 EXPECT_FALSE(scheduler_->frame_source().NeedsBeginFrames()); |
2002 scheduler->SetNeedsCommit(); | 1992 scheduler_->SetNeedsCommit(); |
2003 EXPECT_TRUE(scheduler->frame_source().NeedsBeginFrames()); | 1993 EXPECT_TRUE(scheduler_->frame_source().NeedsBeginFrames()); |
2004 | 1994 |
2005 client.Reset(); | 1995 client_->Reset(); |
2006 client.task_runner().RunPendingTasks(); // Run posted Tick. | 1996 task_runner().RunPendingTasks(); // Run posted Tick. |
2007 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 1997 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
2008 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); | 1998 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); |
2009 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1999 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
2010 EXPECT_TRUE(scheduler->frame_source().NeedsBeginFrames()); | 2000 EXPECT_TRUE(scheduler_->frame_source().NeedsBeginFrames()); |
2011 | 2001 |
2012 // NotifyReadyToCommit should trigger the commit. | 2002 // NotifyReadyToCommit should trigger the commit. |
2013 client.Reset(); | 2003 client_->Reset(); |
2014 scheduler->NotifyBeginMainFrameStarted(); | 2004 scheduler_->NotifyBeginMainFrameStarted(); |
2015 scheduler->NotifyReadyToCommit(); | 2005 scheduler_->NotifyReadyToCommit(); |
2016 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); | 2006 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_); |
2017 EXPECT_TRUE(scheduler->frame_source().NeedsBeginFrames()); | 2007 EXPECT_TRUE(scheduler_->frame_source().NeedsBeginFrames()); |
2018 | 2008 |
2019 client.Reset(); | 2009 client_->Reset(); |
2020 scheduler->DidLoseOutputSurface(); | 2010 scheduler_->DidLoseOutputSurface(); |
2021 EXPECT_NO_ACTION(client); | 2011 EXPECT_NO_ACTION(client_); |
2022 EXPECT_FALSE(scheduler->frame_source().NeedsBeginFrames()); | 2012 EXPECT_FALSE(scheduler_->frame_source().NeedsBeginFrames()); |
2023 | 2013 |
2024 client.Reset(); | 2014 client_->Reset(); |
2025 client.task_runner().RunPendingTasks(); // Run posted deadline. | 2015 task_runner().RunPendingTasks(); // Run posted deadline. |
2026 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); | 2016 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client_); |
2027 EXPECT_FALSE(scheduler->frame_source().NeedsBeginFrames()); | 2017 EXPECT_FALSE(scheduler_->frame_source().NeedsBeginFrames()); |
2028 } | 2018 } |
2029 | 2019 |
2030 TEST(SchedulerTest, ScheduledActionActivateAfterBecomingInvisible) { | 2020 TEST_F(SchedulerTest, ScheduledActionActivateAfterBecomingInvisible) { |
2031 FakeSchedulerClient client; | 2021 scheduler_settings_.impl_side_painting = true; |
2032 SchedulerSettings scheduler_settings; | 2022 scheduler_settings_.use_external_begin_frame_source = true; |
2033 scheduler_settings.impl_side_painting = true; | 2023 SetUpScheduler(true); |
2034 scheduler_settings.use_external_begin_frame_source = true; | |
2035 | |
2036 CREATE_SCHEDULER_AND_INIT_SURFACE(scheduler_settings); | |
2037 | 2024 |
2038 // SetNeedsCommit should begin the frame. | 2025 // SetNeedsCommit should begin the frame. |
2039 scheduler->SetNeedsCommit(); | 2026 scheduler_->SetNeedsCommit(); |
2040 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client); | 2027 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client_); |
2041 | 2028 |
2042 client.Reset(); | 2029 client_->Reset(); |
2043 EXPECT_SCOPED(client.AdvanceFrame()); | 2030 EXPECT_SCOPED(AdvanceFrame()); |
2044 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 2031 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
2045 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); | 2032 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); |
2046 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 2033 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
2047 | 2034 |
2048 client.Reset(); | 2035 client_->Reset(); |
2049 scheduler->NotifyBeginMainFrameStarted(); | 2036 scheduler_->NotifyBeginMainFrameStarted(); |
2050 scheduler->NotifyReadyToCommit(); | 2037 scheduler_->NotifyReadyToCommit(); |
2051 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); | 2038 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_); |
2052 | 2039 |
2053 client.Reset(); | 2040 client_->Reset(); |
2054 scheduler->SetVisible(false); | 2041 scheduler_->SetVisible(false); |
2055 // Sync tree should be forced to activate. | 2042 // Sync tree should be forced to activate. |
2056 EXPECT_ACTION("SetNeedsBeginFrames(false)", client, 0, 2); | 2043 EXPECT_ACTION("SetNeedsBeginFrames(false)", client_, 0, 2); |
2057 EXPECT_ACTION("ScheduledActionActivateSyncTree", client, 1, 2); | 2044 EXPECT_ACTION("ScheduledActionActivateSyncTree", client_, 1, 2); |
2058 } | 2045 } |
2059 | 2046 |
2060 TEST(SchedulerTest, SchedulerPowerMonitoring) { | 2047 TEST_F(SchedulerTest, SchedulerPowerMonitoring) { |
2061 FakeSchedulerClient client; | 2048 scheduler_settings_.disable_hi_res_timer_tasks_on_battery = true; |
2062 SchedulerSettings settings; | 2049 SetUpScheduler(true); |
2063 settings.disable_hi_res_timer_tasks_on_battery = true; | |
2064 | |
2065 CREATE_SCHEDULER_AND_INIT_SURFACE(settings); | |
2066 | 2050 |
2067 base::TimeTicks before_deadline, after_deadline; | 2051 base::TimeTicks before_deadline, after_deadline; |
2068 | 2052 |
2069 scheduler->SetNeedsCommit(); | 2053 scheduler_->SetNeedsCommit(); |
2070 scheduler->SetNeedsRedraw(); | 2054 scheduler_->SetNeedsRedraw(); |
2071 client.Reset(); | 2055 client_->Reset(); |
2072 | 2056 |
2073 // On non-battery power | 2057 // On non-battery power |
2074 EXPECT_FALSE(client.PowerMonitor()->IsOnBatteryPower()); | 2058 EXPECT_FALSE(PowerMonitor()->IsOnBatteryPower()); |
2075 | 2059 |
2076 EXPECT_SCOPED(client.AdvanceFrame()); | 2060 EXPECT_SCOPED(AdvanceFrame()); |
2077 client.Reset(); | 2061 client_->Reset(); |
2078 | 2062 |
2079 before_deadline = client.now_src()->Now(); | 2063 before_deadline = now_src()->Now(); |
2080 EXPECT_TRUE(client.task_runner().RunTasksWhile( | 2064 EXPECT_TRUE( |
2081 client.ImplFrameDeadlinePending(true))); | 2065 task_runner().RunTasksWhile(client_->ImplFrameDeadlinePending(true))); |
2082 after_deadline = client.now_src()->Now(); | 2066 after_deadline = now_src()->Now(); |
2083 | 2067 |
2084 // We post a non-zero deadline task when not on battery | 2068 // We post a non-zero deadline task when not on battery |
2085 EXPECT_LT(before_deadline, after_deadline); | 2069 EXPECT_LT(before_deadline, after_deadline); |
2086 | 2070 |
2087 // Switch to battery power | 2071 // Switch to battery power |
2088 client.PowerMonitorSource()->GeneratePowerStateEvent(true); | 2072 PowerMonitorSource()->GeneratePowerStateEvent(true); |
2089 EXPECT_TRUE(client.PowerMonitor()->IsOnBatteryPower()); | 2073 EXPECT_TRUE(PowerMonitor()->IsOnBatteryPower()); |
2090 | 2074 |
2091 EXPECT_SCOPED(client.AdvanceFrame()); | 2075 EXPECT_SCOPED(AdvanceFrame()); |
2092 scheduler->SetNeedsCommit(); | 2076 scheduler_->SetNeedsCommit(); |
2093 scheduler->SetNeedsRedraw(); | 2077 scheduler_->SetNeedsRedraw(); |
2094 client.Reset(); | 2078 client_->Reset(); |
2095 | 2079 |
2096 before_deadline = client.now_src()->Now(); | 2080 before_deadline = now_src()->Now(); |
2097 EXPECT_TRUE(client.task_runner().RunTasksWhile( | 2081 EXPECT_TRUE( |
2098 client.ImplFrameDeadlinePending(true))); | 2082 task_runner().RunTasksWhile(client_->ImplFrameDeadlinePending(true))); |
2099 after_deadline = client.now_src()->Now(); | 2083 after_deadline = now_src()->Now(); |
2100 | 2084 |
2101 // We post a zero deadline task when on battery | 2085 // We post a zero deadline task when on battery |
2102 EXPECT_EQ(before_deadline, after_deadline); | 2086 EXPECT_EQ(before_deadline, after_deadline); |
2103 | 2087 |
2104 // Switch to non-battery power | 2088 // Switch to non-battery power |
2105 client.PowerMonitorSource()->GeneratePowerStateEvent(false); | 2089 PowerMonitorSource()->GeneratePowerStateEvent(false); |
2106 EXPECT_FALSE(client.PowerMonitor()->IsOnBatteryPower()); | 2090 EXPECT_FALSE(PowerMonitor()->IsOnBatteryPower()); |
2107 | 2091 |
2108 EXPECT_SCOPED(client.AdvanceFrame()); | 2092 EXPECT_SCOPED(AdvanceFrame()); |
2109 scheduler->SetNeedsCommit(); | 2093 scheduler_->SetNeedsCommit(); |
2110 scheduler->SetNeedsRedraw(); | 2094 scheduler_->SetNeedsRedraw(); |
2111 client.Reset(); | 2095 client_->Reset(); |
2112 | 2096 |
2113 // Same as before | 2097 // Same as before |
2114 before_deadline = client.now_src()->Now(); | 2098 before_deadline = now_src()->Now(); |
2115 EXPECT_TRUE(client.task_runner().RunTasksWhile( | 2099 EXPECT_TRUE( |
2116 client.ImplFrameDeadlinePending(true))); | 2100 task_runner().RunTasksWhile(client_->ImplFrameDeadlinePending(true))); |
2117 after_deadline = client.now_src()->Now(); | 2101 after_deadline = now_src()->Now(); |
2118 } | 2102 } |
2119 | 2103 |
2120 TEST(SchedulerTest, | 2104 TEST_F(SchedulerTest, |
2121 SimulateWindowsLowResolutionTimerOnBattery_PrioritizeImplLatencyOff) { | 2105 SimulateWindowsLowResolutionTimerOnBattery_PrioritizeImplLatencyOff) { |
2122 FakeSchedulerClient client; | 2106 scheduler_settings_.use_external_begin_frame_source = true; |
2123 SchedulerSettings settings; | 2107 SetUpScheduler(true); |
2124 settings.use_external_begin_frame_source = true; | |
2125 | |
2126 CREATE_SCHEDULER_AND_INIT_SURFACE(settings); | |
2127 | 2108 |
2128 // Set needs commit so that the scheduler tries to wait for the main thread | 2109 // Set needs commit so that the scheduler tries to wait for the main thread |
2129 scheduler->SetNeedsCommit(); | 2110 scheduler_->SetNeedsCommit(); |
2130 // Set needs redraw so that the scheduler doesn't wait too long | 2111 // Set needs redraw so that the scheduler doesn't wait too long |
2131 scheduler->SetNeedsRedraw(); | 2112 scheduler_->SetNeedsRedraw(); |
2132 client.Reset(); | 2113 client_->Reset(); |
2133 | 2114 |
2134 // Switch to battery power | 2115 // Switch to battery power |
2135 client.PowerMonitorSource()->GeneratePowerStateEvent(true); | 2116 PowerMonitorSource()->GeneratePowerStateEvent(true); |
2136 EXPECT_TRUE(client.PowerMonitor()->IsOnBatteryPower()); | 2117 EXPECT_TRUE(PowerMonitor()->IsOnBatteryPower()); |
2137 | 2118 |
2138 EXPECT_SCOPED(client.AdvanceFrame()); | 2119 EXPECT_SCOPED(AdvanceFrame()); |
2139 scheduler->SetNeedsCommit(); | 2120 scheduler_->SetNeedsCommit(); |
2140 scheduler->SetNeedsRedraw(); | 2121 scheduler_->SetNeedsRedraw(); |
2141 client.Reset(); | 2122 client_->Reset(); |
2142 | 2123 |
2143 // Disable auto-advancing of now_src | 2124 // Disable auto-advancing of now_src |
2144 client.task_runner().SetAutoAdvanceNowToPendingTasks(false); | 2125 task_runner().SetAutoAdvanceNowToPendingTasks(false); |
2145 | 2126 |
2146 // Deadline task is pending | 2127 // Deadline task is pending |
2147 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 2128 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
2148 client.task_runner().RunPendingTasks(); | 2129 task_runner().RunPendingTasks(); |
2149 // Deadline task is still pending | 2130 // Deadline task is still pending |
2150 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 2131 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
2151 | 2132 |
2152 // Advance now by 15 ms - same as windows low res timer | 2133 // Advance now by 15 ms - same as windows low res timer |
2153 client.now_src()->AdvanceNowMicroseconds(15000); | 2134 now_src()->AdvanceNowMicroseconds(15000); |
2154 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 2135 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
2155 client.task_runner().RunPendingTasks(); | 2136 task_runner().RunPendingTasks(); |
2156 // Deadline task finally completes | 2137 // Deadline task finally completes |
2157 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 2138 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); |
2158 } | 2139 } |
2159 | 2140 |
2160 TEST(SchedulerTest, | 2141 TEST_F(SchedulerTest, |
2161 SimulateWindowsLowResolutionTimerOnBattery_PrioritizeImplLatencyOn) { | 2142 SimulateWindowsLowResolutionTimerOnBattery_PrioritizeImplLatencyOn) { |
2162 FakeSchedulerClient client; | 2143 scheduler_settings_.disable_hi_res_timer_tasks_on_battery = true; |
2163 SchedulerSettings settings; | 2144 scheduler_settings_.use_external_begin_frame_source = true; |
2164 settings.disable_hi_res_timer_tasks_on_battery = true; | 2145 SetUpScheduler(true); |
2165 settings.use_external_begin_frame_source = true; | |
2166 | |
2167 CREATE_SCHEDULER_AND_INIT_SURFACE(settings); | |
2168 | 2146 |
2169 // Set needs commit so that the scheduler tries to wait for the main thread | 2147 // Set needs commit so that the scheduler tries to wait for the main thread |
2170 scheduler->SetNeedsCommit(); | 2148 scheduler_->SetNeedsCommit(); |
2171 // Set needs redraw so that the scheduler doesn't wait too long | 2149 // Set needs redraw so that the scheduler doesn't wait too long |
2172 scheduler->SetNeedsRedraw(); | 2150 scheduler_->SetNeedsRedraw(); |
2173 client.Reset(); | 2151 client_->Reset(); |
2174 | 2152 |
2175 // Switch to battery power | 2153 // Switch to battery power |
2176 client.PowerMonitorSource()->GeneratePowerStateEvent(true); | 2154 PowerMonitorSource()->GeneratePowerStateEvent(true); |
2177 EXPECT_TRUE(client.PowerMonitor()->IsOnBatteryPower()); | 2155 EXPECT_TRUE(PowerMonitor()->IsOnBatteryPower()); |
2178 | 2156 |
2179 EXPECT_SCOPED(client.AdvanceFrame()); | 2157 EXPECT_SCOPED(AdvanceFrame()); |
2180 scheduler->SetNeedsCommit(); | 2158 scheduler_->SetNeedsCommit(); |
2181 scheduler->SetNeedsRedraw(); | 2159 scheduler_->SetNeedsRedraw(); |
2182 client.Reset(); | 2160 client_->Reset(); |
2183 | 2161 |
2184 // Disable auto-advancing of now_src | 2162 // Disable auto-advancing of now_src |
2185 client.task_runner().SetAutoAdvanceNowToPendingTasks(false); | 2163 task_runner().SetAutoAdvanceNowToPendingTasks(false); |
2186 | 2164 |
2187 // Deadline task is pending | 2165 // Deadline task is pending |
2188 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 2166 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
2189 client.task_runner().RunPendingTasks(); | 2167 task_runner().RunPendingTasks(); |
2190 // Deadline task runs immediately | 2168 // Deadline task runs immediately |
2191 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 2169 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); |
2192 } | 2170 } |
2193 | 2171 |
2194 // Tests to ensure frame sources can be successfully changed while drawing. | 2172 // Tests to ensure frame sources can be successfully changed while drawing. |
2195 TEST(SchedulerTest, SwitchFrameSourceToUnthrottled) { | 2173 TEST_F(SchedulerTest, SwitchFrameSourceToUnthrottled) { |
2196 FakeSchedulerClient client; | 2174 scheduler_settings_.use_external_begin_frame_source = true; |
2197 SchedulerSettings scheduler_settings; | 2175 SetUpScheduler(true); |
2198 scheduler_settings.use_external_begin_frame_source = true; | |
2199 | |
2200 CREATE_SCHEDULER_AND_INIT_SURFACE(scheduler_settings); | |
2201 | 2176 |
2202 // SetNeedsRedraw should begin the frame on the next BeginImplFrame. | 2177 // SetNeedsRedraw should begin the frame on the next BeginImplFrame. |
2203 scheduler->SetNeedsRedraw(); | 2178 scheduler_->SetNeedsRedraw(); |
2204 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client); | 2179 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client_); |
2205 client.Reset(); | 2180 client_->Reset(); |
2206 | 2181 |
2207 EXPECT_SCOPED(client.AdvanceFrame()); | 2182 EXPECT_SCOPED(AdvanceFrame()); |
2208 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 2183 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
2209 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); | 2184 EXPECT_ACTION("ScheduledActionAnimate", client_, 1, 2); |
2210 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 2185 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
2211 EXPECT_TRUE(client.needs_begin_frames()); | 2186 EXPECT_TRUE(client_->needs_begin_frames()); |
2212 client.Reset(); | 2187 client_->Reset(); |
2213 client.task_runner().RunPendingTasks(); // Run posted deadline. | 2188 task_runner().RunPendingTasks(); // Run posted deadline. |
2214 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 1); | 2189 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 0, 1); |
2215 scheduler->SetNeedsRedraw(); | 2190 scheduler_->SetNeedsRedraw(); |
2216 | 2191 |
2217 // Switch to an unthrottled frame source. | 2192 // Switch to an unthrottled frame source. |
2218 scheduler->SetThrottleFrameProduction(false); | 2193 scheduler_->SetThrottleFrameProduction(false); |
2219 client.Reset(); | 2194 client_->Reset(); |
2220 | 2195 |
2221 // Unthrottled frame source will immediately begin a new frame. | 2196 // Unthrottled frame source will immediately begin a new frame. |
2222 client.task_runner().RunPendingTasks(); // Run posted BeginFrame. | 2197 task_runner().RunPendingTasks(); // Run posted BeginFrame. |
2223 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 2198 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
2224 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); | 2199 EXPECT_ACTION("ScheduledActionAnimate", client_, 1, 2); |
2225 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 2200 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
2226 client.Reset(); | 2201 client_->Reset(); |
2227 | 2202 |
2228 // If we don't swap on the deadline, we wait for the next BeginFrame. | 2203 // If we don't swap on the deadline, we wait for the next BeginFrame. |
2229 client.task_runner().RunPendingTasks(); // Run posted deadline. | 2204 task_runner().RunPendingTasks(); // Run posted deadline. |
2230 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 1); | 2205 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 0, 1); |
2231 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 2206 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); |
2232 client.Reset(); | 2207 client_->Reset(); |
2233 } | 2208 } |
2234 | 2209 |
2235 // Tests to ensure frame sources can be successfully changed while a frame | 2210 // Tests to ensure frame sources can be successfully changed while a frame |
2236 // deadline is pending. | 2211 // deadline is pending. |
2237 TEST(SchedulerTest, SwitchFrameSourceToUnthrottledBeforeDeadline) { | 2212 TEST_F(SchedulerTest, SwitchFrameSourceToUnthrottledBeforeDeadline) { |
2238 FakeSchedulerClient client; | 2213 scheduler_settings_.use_external_begin_frame_source = true; |
2239 SchedulerSettings scheduler_settings; | 2214 SetUpScheduler(true); |
2240 scheduler_settings.use_external_begin_frame_source = true; | |
2241 | |
2242 CREATE_SCHEDULER_AND_INIT_SURFACE(scheduler_settings); | |
2243 | 2215 |
2244 // SetNeedsRedraw should begin the frame on the next BeginImplFrame. | 2216 // SetNeedsRedraw should begin the frame on the next BeginImplFrame. |
2245 scheduler->SetNeedsRedraw(); | 2217 scheduler_->SetNeedsRedraw(); |
2246 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client); | 2218 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client_); |
2247 client.Reset(); | 2219 client_->Reset(); |
2248 | 2220 |
2249 EXPECT_SCOPED(client.AdvanceFrame()); | 2221 EXPECT_SCOPED(AdvanceFrame()); |
2250 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 2222 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
2251 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); | 2223 EXPECT_ACTION("ScheduledActionAnimate", client_, 1, 2); |
2252 | 2224 |
2253 // Switch to an unthrottled frame source before the frame deadline is hit. | 2225 // Switch to an unthrottled frame source before the frame deadline is hit. |
2254 scheduler->SetThrottleFrameProduction(false); | 2226 scheduler_->SetThrottleFrameProduction(false); |
2255 client.Reset(); | 2227 client_->Reset(); |
2256 | 2228 |
2257 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 2229 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
2258 EXPECT_TRUE(client.needs_begin_frames()); | 2230 EXPECT_TRUE(client_->needs_begin_frames()); |
2259 client.Reset(); | 2231 client_->Reset(); |
2260 | 2232 |
2261 client.task_runner() | 2233 task_runner().RunPendingTasks(); // Run posted deadline and BeginFrame. |
2262 .RunPendingTasks(); // Run posted deadline and BeginFrame. | 2234 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 0, 2); |
2263 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 2); | |
2264 // Unthrottled frame source will immediately begin a new frame. | 2235 // Unthrottled frame source will immediately begin a new frame. |
2265 EXPECT_ACTION("WillBeginImplFrame", client, 1, 2); | 2236 EXPECT_ACTION("WillBeginImplFrame", client_, 1, 2); |
2266 scheduler->SetNeedsRedraw(); | 2237 scheduler_->SetNeedsRedraw(); |
2267 client.Reset(); | 2238 client_->Reset(); |
2268 | 2239 |
2269 client.task_runner().RunPendingTasks(); // Run posted deadline. | 2240 task_runner().RunPendingTasks(); // Run posted deadline. |
2270 EXPECT_ACTION("ScheduledActionAnimate", client, 0, 2); | 2241 EXPECT_ACTION("ScheduledActionAnimate", client_, 0, 2); |
2271 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 1, 2); | 2242 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 1, 2); |
2272 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 2243 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); |
2273 client.Reset(); | 2244 client_->Reset(); |
2274 } | 2245 } |
2275 | 2246 |
2276 // Tests to ensure that the active frame source can successfully be changed from | 2247 // Tests to ensure that the active frame source can successfully be changed from |
2277 // unthrottled to throttled. | 2248 // unthrottled to throttled. |
2278 TEST(SchedulerTest, SwitchFrameSourceToThrottled) { | 2249 TEST_F(SchedulerTest, SwitchFrameSourceToThrottled) { |
2279 FakeSchedulerClient client; | 2250 scheduler_settings_.throttle_frame_production = false; |
2280 SchedulerSettings scheduler_settings; | 2251 scheduler_settings_.use_external_begin_frame_source = true; |
2281 scheduler_settings.throttle_frame_production = false; | 2252 SetUpScheduler(true); |
2282 scheduler_settings.use_external_begin_frame_source = true; | 2253 |
2283 | 2254 scheduler_->SetNeedsRedraw(); |
2284 CREATE_SCHEDULER_AND_INIT_SURFACE(scheduler_settings); | 2255 EXPECT_NO_ACTION(client_); |
2285 | 2256 client_->Reset(); |
2286 scheduler->SetNeedsRedraw(); | 2257 |
2287 EXPECT_NO_ACTION(client); | 2258 task_runner().RunPendingTasks(); // Run posted BeginFrame. |
2288 client.Reset(); | 2259 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
2289 | 2260 EXPECT_ACTION("ScheduledActionAnimate", client_, 1, 2); |
2290 client.task_runner().RunPendingTasks(); // Run posted BeginFrame. | 2261 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
2291 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 2262 client_->Reset(); |
2292 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); | 2263 |
2293 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 2264 task_runner().RunPendingTasks(); // Run posted deadline. |
2294 client.Reset(); | 2265 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 0, 1); |
2295 | 2266 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); |
2296 client.task_runner().RunPendingTasks(); // Run posted deadline. | 2267 client_->Reset(); |
2297 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 1); | |
2298 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | |
2299 client.Reset(); | |
2300 | 2268 |
2301 // Switch to a throttled frame source. | 2269 // Switch to a throttled frame source. |
2302 scheduler->SetThrottleFrameProduction(true); | 2270 scheduler_->SetThrottleFrameProduction(true); |
2303 client.Reset(); | 2271 client_->Reset(); |
2304 | 2272 |
2305 // SetNeedsRedraw should begin the frame on the next BeginImplFrame. | 2273 // SetNeedsRedraw should begin the frame on the next BeginImplFrame. |
2306 scheduler->SetNeedsRedraw(); | 2274 scheduler_->SetNeedsRedraw(); |
2307 client.task_runner().RunPendingTasks(); | 2275 task_runner().RunPendingTasks(); |
2308 EXPECT_NO_ACTION(client); | 2276 EXPECT_NO_ACTION(client_); |
2309 client.Reset(); | 2277 client_->Reset(); |
2310 | 2278 |
2311 EXPECT_SCOPED(client.AdvanceFrame()); | 2279 EXPECT_SCOPED(AdvanceFrame()); |
2312 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 2280 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
2313 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); | 2281 EXPECT_ACTION("ScheduledActionAnimate", client_, 1, 2); |
2314 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 2282 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
2315 EXPECT_TRUE(client.needs_begin_frames()); | 2283 EXPECT_TRUE(client_->needs_begin_frames()); |
2316 client.Reset(); | 2284 client_->Reset(); |
2317 client.task_runner().RunPendingTasks(); // Run posted deadline. | 2285 task_runner().RunPendingTasks(); // Run posted deadline. |
2318 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 1); | 2286 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 0, 1); |
2319 } | 2287 } |
2320 | 2288 |
2321 } // namespace | 2289 } // namespace |
2322 } // namespace cc | 2290 } // namespace cc |
OLD | NEW |