OLD | NEW |
1 // Copyright 2011 The Chromium Authors. All rights reserved. | 1 // Copyright 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 #include "cc/scheduler/scheduler.h" | 4 #include "cc/scheduler/scheduler.h" |
5 | 5 |
6 #include <string> | 6 #include <string> |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/debug/trace_event.h" | 9 #include "base/debug/trace_event.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 25 matching lines...) Expand all Loading... |
36 EXPECT_ACTION(action, client, 0, 1) | 36 EXPECT_ACTION(action, client, 0, 1) |
37 | 37 |
38 namespace cc { | 38 namespace cc { |
39 namespace { | 39 namespace { |
40 | 40 |
41 class FakeSchedulerClient; | 41 class FakeSchedulerClient; |
42 | 42 |
43 void InitializeOutputSurfaceAndFirstCommit(Scheduler* scheduler, | 43 void InitializeOutputSurfaceAndFirstCommit(Scheduler* scheduler, |
44 FakeSchedulerClient* client); | 44 FakeSchedulerClient* client); |
45 | 45 |
46 class TestScheduler : public Scheduler { | |
47 public: | |
48 static scoped_ptr<TestScheduler> Create( | |
49 SchedulerClient* client, | |
50 const SchedulerSettings& scheduler_settings, | |
51 int layer_tree_host_id, | |
52 const scoped_refptr<base::SingleThreadTaskRunner>& impl_task_runner) { | |
53 return make_scoped_ptr(new TestScheduler( | |
54 client, scheduler_settings, layer_tree_host_id, impl_task_runner)); | |
55 } | |
56 | |
57 virtual ~TestScheduler() {} | |
58 | |
59 bool IsBeginRetroFrameArgsEmpty() const { | |
60 return begin_retro_frame_args_.empty(); | |
61 } | |
62 | |
63 bool IsSyntheticBeginFrameSourceActive() const { | |
64 return synthetic_begin_frame_source_->IsActive(); | |
65 } | |
66 | |
67 private: | |
68 TestScheduler( | |
69 SchedulerClient* client, | |
70 const SchedulerSettings& scheduler_settings, | |
71 int layer_tree_host_id, | |
72 const scoped_refptr<base::SingleThreadTaskRunner> & impl_task_runner) | |
73 : Scheduler(client, | |
74 scheduler_settings, | |
75 layer_tree_host_id, | |
76 impl_task_runner) { | |
77 } | |
78 }; | |
79 | |
80 class FakeSchedulerClient : public SchedulerClient { | 46 class FakeSchedulerClient : public SchedulerClient { |
81 public: | 47 public: |
82 FakeSchedulerClient() | 48 FakeSchedulerClient() |
83 : needs_begin_frame_(false), | 49 : needs_begin_frame_(false), |
84 automatic_swap_ack_(true), | 50 automatic_swap_ack_(true), |
85 swap_contains_incomplete_tile_(false), | 51 swap_contains_incomplete_tile_(false), |
86 redraw_will_happen_if_update_visible_tiles_happens_(false) { | 52 redraw_will_happen_if_update_visible_tiles_happens_(false), |
| 53 now_src_(TestNowSource::Create()) { |
87 Reset(); | 54 Reset(); |
88 } | 55 } |
89 | 56 |
90 void Reset() { | 57 void Reset() { |
91 actions_.clear(); | 58 actions_.clear(); |
92 states_.clear(); | 59 states_.clear(); |
93 draw_will_happen_ = true; | 60 draw_will_happen_ = true; |
94 swap_will_happen_if_draw_happens_ = true; | 61 swap_will_happen_if_draw_happens_ = true; |
95 num_draws_ = 0; | 62 num_draws_ = 0; |
96 log_anticipated_draw_time_change_ = false; | 63 log_anticipated_draw_time_change_ = false; |
97 } | 64 } |
98 | 65 |
99 TestScheduler* CreateScheduler(const SchedulerSettings& settings) { | 66 TestScheduler* CreateScheduler(const SchedulerSettings& settings) { |
100 task_runner_ = new OrderedSimpleTaskRunner; | 67 scheduler_ = TestScheduler::Create(now_src_, this, settings, 0); |
101 scheduler_ = TestScheduler::Create(this, settings, 0, task_runner_); | 68 // Fail if we need to run 100 tasks in a row. |
| 69 task_runner().SetRunTaskLimit(100); |
102 return scheduler_.get(); | 70 return scheduler_.get(); |
103 } | 71 } |
104 | 72 |
105 // Most tests don't care about DidAnticipatedDrawTimeChange, so only record it | 73 // Most tests don't care about DidAnticipatedDrawTimeChange, so only record it |
106 // for tests that do. | 74 // for tests that do. |
107 void set_log_anticipated_draw_time_change(bool log) { | 75 void set_log_anticipated_draw_time_change(bool log) { |
108 log_anticipated_draw_time_change_ = log; | 76 log_anticipated_draw_time_change_ = log; |
109 } | 77 } |
110 bool needs_begin_frame() { return needs_begin_frame_; } | 78 bool needs_begin_frame() { return needs_begin_frame_; } |
111 int num_draws() const { return num_draws_; } | 79 int num_draws() const { return num_draws_; } |
112 int num_actions_() const { return static_cast<int>(actions_.size()); } | 80 int num_actions_() const { return static_cast<int>(actions_.size()); } |
113 const char* Action(int i) const { return actions_[i]; } | 81 const char* Action(int i) const { return actions_[i]; } |
114 std::string StateForAction(int i) const { return states_[i]->ToString(); } | 82 std::string StateForAction(int i) const { return states_[i]->ToString(); } |
115 base::TimeTicks posted_begin_impl_frame_deadline() const { | 83 base::TimeTicks posted_begin_impl_frame_deadline() const { |
116 return posted_begin_impl_frame_deadline_; | 84 return posted_begin_impl_frame_deadline_; |
117 } | 85 } |
118 | 86 |
119 OrderedSimpleTaskRunner& task_runner() { return *task_runner_.get(); } | 87 void AdvanceFrame() { |
| 88 bool external_begin_frame = |
| 89 scheduler_->settings().begin_frame_scheduling_enabled && |
| 90 scheduler_->settings().throttle_frame_production; |
| 91 |
| 92 if (external_begin_frame) { |
| 93 scheduler_->BeginFrame(CreateBeginFrameArgsForTesting(now_src_)); |
| 94 } |
| 95 |
| 96 EXPECT_TRUE(task_runner().RunTasksWhile(ImplFrameDeadlinePending(false))); |
| 97 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
| 98 } |
| 99 |
| 100 OrderedSimpleTaskRunner& task_runner() { return scheduler_->task_runner(); } |
| 101 TestNowSource* now_src() { return now_src_.get(); } |
120 | 102 |
121 int ActionIndex(const char* action) const { | 103 int ActionIndex(const char* action) const { |
122 for (size_t i = 0; i < actions_.size(); i++) | 104 for (size_t i = 0; i < actions_.size(); i++) |
123 if (!strcmp(actions_[i], action)) | 105 if (!strcmp(actions_[i], action)) |
124 return i; | 106 return i; |
125 return -1; | 107 return -1; |
126 } | 108 } |
127 | 109 |
128 void SetSwapContainsIncompleteTile(bool contain) { | 110 void SetSwapContainsIncompleteTile(bool contain) { |
129 swap_contains_incomplete_tile_ = contain; | 111 swap_contains_incomplete_tile_ = contain; |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
221 } | 203 } |
222 virtual base::TimeDelta BeginMainFrameToCommitDurationEstimate() OVERRIDE { | 204 virtual base::TimeDelta BeginMainFrameToCommitDurationEstimate() OVERRIDE { |
223 return base::TimeDelta(); | 205 return base::TimeDelta(); |
224 } | 206 } |
225 virtual base::TimeDelta CommitToActivateDurationEstimate() OVERRIDE { | 207 virtual base::TimeDelta CommitToActivateDurationEstimate() OVERRIDE { |
226 return base::TimeDelta(); | 208 return base::TimeDelta(); |
227 } | 209 } |
228 | 210 |
229 virtual void DidBeginImplFrameDeadline() OVERRIDE {} | 211 virtual void DidBeginImplFrameDeadline() OVERRIDE {} |
230 | 212 |
| 213 base::Callback<bool(void)> ImplFrameDeadlinePending(bool state) { |
| 214 return base::Bind(&FakeSchedulerClient::ImplFrameDeadlinePendingCallback, |
| 215 base::Unretained(this), |
| 216 state); |
| 217 } |
| 218 |
231 protected: | 219 protected: |
| 220 bool ImplFrameDeadlinePendingCallback(bool state) { |
| 221 return scheduler_->BeginImplFrameDeadlinePending() == state; |
| 222 } |
| 223 |
232 bool needs_begin_frame_; | 224 bool needs_begin_frame_; |
233 bool draw_will_happen_; | 225 bool draw_will_happen_; |
234 bool swap_will_happen_if_draw_happens_; | 226 bool swap_will_happen_if_draw_happens_; |
235 bool automatic_swap_ack_; | 227 bool automatic_swap_ack_; |
236 int num_draws_; | 228 int num_draws_; |
237 bool log_anticipated_draw_time_change_; | 229 bool log_anticipated_draw_time_change_; |
238 bool swap_contains_incomplete_tile_; | 230 bool swap_contains_incomplete_tile_; |
239 bool redraw_will_happen_if_update_visible_tiles_happens_; | 231 bool redraw_will_happen_if_update_visible_tiles_happens_; |
240 base::TimeTicks posted_begin_impl_frame_deadline_; | 232 base::TimeTicks posted_begin_impl_frame_deadline_; |
241 std::vector<const char*> actions_; | 233 std::vector<const char*> actions_; |
242 std::vector<scoped_refptr<base::debug::ConvertableToTraceFormat> > states_; | 234 std::vector<scoped_refptr<base::debug::ConvertableToTraceFormat> > states_; |
243 scoped_ptr<TestScheduler> scheduler_; | 235 scoped_ptr<TestScheduler> scheduler_; |
244 scoped_refptr<OrderedSimpleTaskRunner> task_runner_; | 236 scoped_refptr<TestNowSource> now_src_; |
245 }; | 237 }; |
246 | 238 |
247 void InitializeOutputSurfaceAndFirstCommit(Scheduler* scheduler, | 239 void InitializeOutputSurfaceAndFirstCommit(Scheduler* scheduler, |
248 FakeSchedulerClient* client) { | 240 FakeSchedulerClient* client) { |
249 bool client_initiates_begin_frame = | 241 TRACE_EVENT0("cc", |
250 scheduler->settings().begin_frame_scheduling_enabled && | 242 "SchedulerUnitTest::InitializeOutputSurfaceAndFirstCommit"); |
251 scheduler->settings().throttle_frame_production; | |
252 | 243 |
253 scheduler->DidCreateAndInitializeOutputSurface(); | 244 scheduler->DidCreateAndInitializeOutputSurface(); |
254 scheduler->SetNeedsCommit(); | 245 scheduler->SetNeedsCommit(); |
255 scheduler->NotifyBeginMainFrameStarted(); | 246 scheduler->NotifyBeginMainFrameStarted(); |
256 scheduler->NotifyReadyToCommit(); | 247 scheduler->NotifyReadyToCommit(); |
257 if (scheduler->settings().impl_side_painting) | 248 if (scheduler->settings().impl_side_painting) |
258 scheduler->NotifyReadyToActivate(); | 249 scheduler->NotifyReadyToActivate(); |
| 250 |
259 // Go through the motions to draw the commit. | 251 // Go through the motions to draw the commit. |
260 if (client_initiates_begin_frame) | 252 client->AdvanceFrame(); |
261 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | |
262 else | |
263 client->task_runner().RunPendingTasks(); // Run posted BeginFrame. | |
264 | 253 |
265 // Run the posted deadline task. | 254 // Run the posted deadline task. |
266 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 255 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
267 client->task_runner().RunPendingTasks(); | 256 client->task_runner().RunTasksWhile(client->ImplFrameDeadlinePending(true)); |
268 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 257 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
269 | 258 |
270 // We need another BeginImplFrame so Scheduler calls | 259 // We need another BeginImplFrame so Scheduler calls |
271 // SetNeedsBeginFrame(false). | 260 // SetNeedsBeginFrame(false). |
272 if (client_initiates_begin_frame) | 261 client->AdvanceFrame(); |
273 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | |
274 else | |
275 client->task_runner().RunPendingTasks(); // Run posted BeginFrame. | |
276 | 262 |
277 // Run the posted deadline task. | 263 // Run the posted deadline task. |
278 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 264 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
279 client->task_runner().RunPendingTasks(); | 265 client->task_runner().RunTasksWhile(client->ImplFrameDeadlinePending(true)); |
280 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 266 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
281 } | 267 } |
282 | 268 |
283 TEST(SchedulerTest, InitializeOutputSurfaceDoesNotBeginImplFrame) { | 269 TEST(SchedulerTest, InitializeOutputSurfaceDoesNotBeginImplFrame) { |
284 FakeSchedulerClient client; | 270 FakeSchedulerClient client; |
285 SchedulerSettings default_scheduler_settings; | 271 SchedulerSettings default_scheduler_settings; |
286 TestScheduler* scheduler = client.CreateScheduler(default_scheduler_settings); | 272 TestScheduler* scheduler = client.CreateScheduler(default_scheduler_settings); |
287 scheduler->SetCanStart(); | 273 scheduler->SetCanStart(); |
288 scheduler->SetVisible(true); | 274 scheduler->SetVisible(true); |
289 scheduler->SetCanDraw(true); | 275 scheduler->SetCanDraw(true); |
(...skipping 15 matching lines...) Expand all Loading... |
305 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); | 291 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); |
306 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | 292 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
307 | 293 |
308 // SetNeedsCommit should begin the frame on the next BeginImplFrame. | 294 // SetNeedsCommit should begin the frame on the next BeginImplFrame. |
309 client.Reset(); | 295 client.Reset(); |
310 scheduler->SetNeedsCommit(); | 296 scheduler->SetNeedsCommit(); |
311 EXPECT_TRUE(client.needs_begin_frame()); | 297 EXPECT_TRUE(client.needs_begin_frame()); |
312 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); | 298 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); |
313 client.Reset(); | 299 client.Reset(); |
314 | 300 |
315 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | 301 client.AdvanceFrame(); |
316 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 302 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
317 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); | 303 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); |
318 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 304 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
319 EXPECT_TRUE(client.needs_begin_frame()); | 305 EXPECT_TRUE(client.needs_begin_frame()); |
320 client.Reset(); | 306 client.Reset(); |
321 | 307 |
322 // If we don't swap on the deadline, we wait for the next BeginFrame. | 308 // If we don't swap on the deadline, we wait for the next BeginFrame. |
323 client.task_runner().RunPendingTasks(); // Run posted deadline. | 309 client.task_runner().RunPendingTasks(); // Run posted deadline. |
324 EXPECT_NO_ACTION(client); | 310 EXPECT_NO_ACTION(client); |
325 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 311 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
326 EXPECT_TRUE(client.needs_begin_frame()); | 312 EXPECT_TRUE(client.needs_begin_frame()); |
327 client.Reset(); | 313 client.Reset(); |
328 | 314 |
329 // NotifyReadyToCommit should trigger the commit. | 315 // NotifyReadyToCommit should trigger the commit. |
330 scheduler->NotifyBeginMainFrameStarted(); | 316 scheduler->NotifyBeginMainFrameStarted(); |
331 scheduler->NotifyReadyToCommit(); | 317 scheduler->NotifyReadyToCommit(); |
332 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); | 318 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); |
333 EXPECT_TRUE(client.needs_begin_frame()); | 319 EXPECT_TRUE(client.needs_begin_frame()); |
334 client.Reset(); | 320 client.Reset(); |
335 | 321 |
336 // BeginImplFrame should prepare the draw. | 322 // BeginImplFrame should prepare the draw. |
337 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | 323 client.AdvanceFrame(); |
338 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 324 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
339 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); | 325 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); |
340 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 326 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
341 EXPECT_TRUE(client.needs_begin_frame()); | 327 EXPECT_TRUE(client.needs_begin_frame()); |
342 client.Reset(); | 328 client.Reset(); |
343 | 329 |
344 // BeginImplFrame deadline should draw. | 330 // BeginImplFrame deadline should draw. |
345 client.task_runner().RunPendingTasks(); // Run posted deadline. | 331 client.task_runner().RunPendingTasks(); // Run posted deadline. |
346 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 1); | 332 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 1); |
347 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 333 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
348 EXPECT_TRUE(client.needs_begin_frame()); | 334 EXPECT_TRUE(client.needs_begin_frame()); |
349 client.Reset(); | 335 client.Reset(); |
350 | 336 |
351 // The following BeginImplFrame deadline should SetNeedsBeginFrame(false) | 337 // The following BeginImplFrame deadline should SetNeedsBeginFrame(false) |
352 // to avoid excessive toggles. | 338 // to avoid excessive toggles. |
353 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | 339 client.AdvanceFrame(); |
354 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); | 340 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); |
355 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 341 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
356 client.Reset(); | 342 client.Reset(); |
357 | 343 |
358 client.task_runner().RunPendingTasks(); // Run posted deadline. | 344 client.task_runner().RunPendingTasks(); // Run posted deadline. |
359 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); | 345 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); |
360 EXPECT_FALSE(client.needs_begin_frame()); | 346 EXPECT_FALSE(client.needs_begin_frame()); |
361 client.Reset(); | 347 client.Reset(); |
362 } | 348 } |
363 | 349 |
364 TEST(SchedulerTest, RequestCommitAfterBeginMainFrameSent) { | 350 TEST(SchedulerTest, RequestCommitAfterBeginMainFrameSent) { |
365 FakeSchedulerClient client; | 351 FakeSchedulerClient client; |
366 SchedulerSettings scheduler_settings; | 352 SchedulerSettings scheduler_settings; |
367 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings); | 353 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings); |
368 scheduler->SetCanStart(); | 354 scheduler->SetCanStart(); |
369 scheduler->SetVisible(true); | 355 scheduler->SetVisible(true); |
370 scheduler->SetCanDraw(true); | 356 scheduler->SetCanDraw(true); |
371 | 357 |
372 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); | 358 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); |
373 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | 359 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
374 client.Reset(); | 360 client.Reset(); |
375 | 361 |
376 // SetNeedsCommit should begin the frame. | 362 // SetNeedsCommit should begin the frame. |
377 scheduler->SetNeedsCommit(); | 363 scheduler->SetNeedsCommit(); |
378 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); | 364 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); |
379 | 365 |
380 client.Reset(); | 366 client.Reset(); |
381 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | 367 client.AdvanceFrame(); |
382 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 368 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
383 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); | 369 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); |
384 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 370 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
385 | 371 |
386 EXPECT_TRUE(client.needs_begin_frame()); | 372 EXPECT_TRUE(client.needs_begin_frame()); |
387 client.Reset(); | 373 client.Reset(); |
388 | 374 |
389 // Now SetNeedsCommit again. Calling here means we need a second commit. | 375 // Now SetNeedsCommit again. Calling here means we need a second commit. |
390 scheduler->SetNeedsCommit(); | 376 scheduler->SetNeedsCommit(); |
391 EXPECT_EQ(client.num_actions_(), 0); | 377 EXPECT_EQ(client.num_actions_(), 0); |
392 client.Reset(); | 378 client.Reset(); |
393 | 379 |
394 // Finish the first commit. | 380 // Finish the first commit. |
395 scheduler->NotifyBeginMainFrameStarted(); | 381 scheduler->NotifyBeginMainFrameStarted(); |
396 scheduler->NotifyReadyToCommit(); | 382 scheduler->NotifyReadyToCommit(); |
397 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); | 383 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); |
398 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 384 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
399 client.Reset(); | 385 client.Reset(); |
400 client.task_runner().RunPendingTasks(); // Run posted deadline. | 386 client.task_runner().RunPendingTasks(); // Run posted deadline. |
401 EXPECT_ACTION("ScheduledActionAnimate", client, 0, 2); | 387 EXPECT_ACTION("ScheduledActionAnimate", client, 0, 2); |
402 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 1, 2); | 388 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 1, 2); |
403 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 389 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
404 | 390 |
405 // Because we just swapped, the Scheduler should also request the next | 391 // Because we just swapped, the Scheduler should also request the next |
406 // BeginImplFrame from the OutputSurface. | 392 // BeginImplFrame from the OutputSurface. |
407 EXPECT_TRUE(client.needs_begin_frame()); | 393 EXPECT_TRUE(client.needs_begin_frame()); |
408 client.Reset(); | 394 client.Reset(); |
409 // Since another commit is needed, the next BeginImplFrame should initiate | 395 // Since another commit is needed, the next BeginImplFrame should initiate |
410 // the second commit. | 396 // the second commit. |
411 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | 397 client.AdvanceFrame(); |
412 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 398 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
413 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); | 399 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); |
414 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 400 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
415 client.Reset(); | 401 client.Reset(); |
416 | 402 |
417 // Finishing the commit before the deadline should post a new deadline task | 403 // Finishing the commit before the deadline should post a new deadline task |
418 // to trigger the deadline early. | 404 // to trigger the deadline early. |
419 scheduler->NotifyBeginMainFrameStarted(); | 405 scheduler->NotifyBeginMainFrameStarted(); |
420 scheduler->NotifyReadyToCommit(); | 406 scheduler->NotifyReadyToCommit(); |
421 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); | 407 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); |
422 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 408 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
423 client.Reset(); | 409 client.Reset(); |
424 client.task_runner().RunPendingTasks(); // Run posted deadline. | 410 client.task_runner().RunPendingTasks(); // Run posted deadline. |
425 EXPECT_ACTION("ScheduledActionAnimate", client, 0, 2); | 411 EXPECT_ACTION("ScheduledActionAnimate", client, 0, 2); |
426 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 1, 2); | 412 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 1, 2); |
427 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 413 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
428 EXPECT_TRUE(client.needs_begin_frame()); | 414 EXPECT_TRUE(client.needs_begin_frame()); |
429 client.Reset(); | 415 client.Reset(); |
430 | 416 |
431 // On the next BeginImplFrame, verify we go back to a quiescent state and | 417 // On the next BeginImplFrame, verify we go back to a quiescent state and |
432 // no longer request BeginImplFrames. | 418 // no longer request BeginImplFrames. |
433 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | 419 client.AdvanceFrame(); |
434 client.task_runner().RunPendingTasks(); // Run posted deadline. | 420 client.task_runner().RunPendingTasks(); // Run posted deadline. |
435 EXPECT_FALSE(client.needs_begin_frame()); | 421 EXPECT_FALSE(client.needs_begin_frame()); |
436 client.Reset(); | 422 client.Reset(); |
437 } | 423 } |
438 | 424 |
439 class SchedulerClientThatsetNeedsDrawInsideDraw : public FakeSchedulerClient { | 425 class SchedulerClientThatsetNeedsDrawInsideDraw : public FakeSchedulerClient { |
440 public: | 426 public: |
441 virtual void ScheduledActionSendBeginMainFrame() OVERRIDE {} | 427 virtual void ScheduledActionSendBeginMainFrame() OVERRIDE {} |
442 virtual DrawResult ScheduledActionDrawAndSwapIfPossible() | 428 virtual DrawResult ScheduledActionDrawAndSwapIfPossible() |
443 OVERRIDE { | 429 OVERRIDE { |
(...skipping 25 matching lines...) Expand all Loading... |
469 scheduler->SetVisible(true); | 455 scheduler->SetVisible(true); |
470 scheduler->SetCanDraw(true); | 456 scheduler->SetCanDraw(true); |
471 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | 457 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
472 client.Reset(); | 458 client.Reset(); |
473 | 459 |
474 scheduler->SetNeedsRedraw(); | 460 scheduler->SetNeedsRedraw(); |
475 EXPECT_TRUE(scheduler->RedrawPending()); | 461 EXPECT_TRUE(scheduler->RedrawPending()); |
476 EXPECT_TRUE(client.needs_begin_frame()); | 462 EXPECT_TRUE(client.needs_begin_frame()); |
477 EXPECT_EQ(0, client.num_draws()); | 463 EXPECT_EQ(0, client.num_draws()); |
478 | 464 |
479 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | 465 client.AdvanceFrame(); |
480 client.task_runner().RunPendingTasks(); // Run posted deadline. | 466 client.task_runner().RunPendingTasks(); // Run posted deadline. |
481 EXPECT_EQ(1, client.num_draws()); | 467 EXPECT_EQ(1, client.num_draws()); |
482 EXPECT_TRUE(scheduler->RedrawPending()); | 468 EXPECT_TRUE(scheduler->RedrawPending()); |
483 EXPECT_TRUE(client.needs_begin_frame()); | 469 EXPECT_TRUE(client.needs_begin_frame()); |
484 | 470 |
485 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | 471 client.AdvanceFrame(); |
486 client.task_runner().RunPendingTasks(); // Run posted deadline. | 472 client.task_runner().RunPendingTasks(); // Run posted deadline. |
487 EXPECT_EQ(2, client.num_draws()); | 473 EXPECT_EQ(2, client.num_draws()); |
488 EXPECT_FALSE(scheduler->RedrawPending()); | 474 EXPECT_FALSE(scheduler->RedrawPending()); |
489 EXPECT_TRUE(client.needs_begin_frame()); | 475 EXPECT_TRUE(client.needs_begin_frame()); |
490 | 476 |
491 // We stop requesting BeginImplFrames after a BeginImplFrame where we don't | 477 // We stop requesting BeginImplFrames after a BeginImplFrame where we don't |
492 // swap. | 478 // swap. |
493 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | 479 client.AdvanceFrame(); |
494 client.task_runner().RunPendingTasks(); // Run posted deadline. | 480 client.task_runner().RunPendingTasks(); // Run posted deadline. |
495 EXPECT_EQ(2, client.num_draws()); | 481 EXPECT_EQ(2, client.num_draws()); |
496 EXPECT_FALSE(scheduler->RedrawPending()); | 482 EXPECT_FALSE(scheduler->RedrawPending()); |
497 EXPECT_FALSE(client.needs_begin_frame()); | 483 EXPECT_FALSE(client.needs_begin_frame()); |
498 } | 484 } |
499 | 485 |
500 // Test that requesting redraw inside a failed draw doesn't lose the request. | 486 // Test that requesting redraw inside a failed draw doesn't lose the request. |
501 TEST(SchedulerTest, RequestRedrawInsideFailedDraw) { | 487 TEST(SchedulerTest, RequestRedrawInsideFailedDraw) { |
502 SchedulerClientThatsetNeedsDrawInsideDraw client; | 488 SchedulerClientThatsetNeedsDrawInsideDraw client; |
503 SchedulerSettings default_scheduler_settings; | 489 SchedulerSettings default_scheduler_settings; |
504 TestScheduler* scheduler = client.CreateScheduler(default_scheduler_settings); | 490 TestScheduler* scheduler = client.CreateScheduler(default_scheduler_settings); |
505 scheduler->SetCanStart(); | 491 scheduler->SetCanStart(); |
506 scheduler->SetVisible(true); | 492 scheduler->SetVisible(true); |
507 scheduler->SetCanDraw(true); | 493 scheduler->SetCanDraw(true); |
508 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | 494 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
509 client.Reset(); | 495 client.Reset(); |
510 | 496 |
511 client.SetDrawWillHappen(false); | 497 client.SetDrawWillHappen(false); |
512 | 498 |
513 scheduler->SetNeedsRedraw(); | 499 scheduler->SetNeedsRedraw(); |
514 EXPECT_TRUE(scheduler->RedrawPending()); | 500 EXPECT_TRUE(scheduler->RedrawPending()); |
515 EXPECT_TRUE(client.needs_begin_frame()); | 501 EXPECT_TRUE(client.needs_begin_frame()); |
516 EXPECT_EQ(0, client.num_draws()); | 502 EXPECT_EQ(0, client.num_draws()); |
517 | 503 |
518 // Fail the draw. | 504 // Fail the draw. |
519 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | 505 client.AdvanceFrame(); |
520 client.task_runner().RunPendingTasks(); // Run posted deadline. | 506 client.task_runner().RunPendingTasks(); // Run posted deadline. |
521 EXPECT_EQ(1, client.num_draws()); | 507 EXPECT_EQ(1, client.num_draws()); |
522 | 508 |
523 // We have a commit pending and the draw failed, and we didn't lose the redraw | 509 // We have a commit pending and the draw failed, and we didn't lose the redraw |
524 // request. | 510 // request. |
525 EXPECT_TRUE(scheduler->CommitPending()); | 511 EXPECT_TRUE(scheduler->CommitPending()); |
526 EXPECT_TRUE(scheduler->RedrawPending()); | 512 EXPECT_TRUE(scheduler->RedrawPending()); |
527 EXPECT_TRUE(client.needs_begin_frame()); | 513 EXPECT_TRUE(client.needs_begin_frame()); |
528 | 514 |
529 // Fail the draw again. | 515 // Fail the draw again. |
530 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | 516 client.AdvanceFrame(); |
531 client.task_runner().RunPendingTasks(); // Run posted deadline. | 517 client.task_runner().RunPendingTasks(); // Run posted deadline. |
532 EXPECT_EQ(2, client.num_draws()); | 518 EXPECT_EQ(2, client.num_draws()); |
533 EXPECT_TRUE(scheduler->CommitPending()); | 519 EXPECT_TRUE(scheduler->CommitPending()); |
534 EXPECT_TRUE(scheduler->RedrawPending()); | 520 EXPECT_TRUE(scheduler->RedrawPending()); |
535 EXPECT_TRUE(client.needs_begin_frame()); | 521 EXPECT_TRUE(client.needs_begin_frame()); |
536 | 522 |
537 // Draw successfully. | 523 // Draw successfully. |
538 client.SetDrawWillHappen(true); | 524 client.SetDrawWillHappen(true); |
539 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | 525 client.AdvanceFrame(); |
540 client.task_runner().RunPendingTasks(); // Run posted deadline. | 526 client.task_runner().RunPendingTasks(); // Run posted deadline. |
541 EXPECT_EQ(3, client.num_draws()); | 527 EXPECT_EQ(3, client.num_draws()); |
542 EXPECT_TRUE(scheduler->CommitPending()); | 528 EXPECT_TRUE(scheduler->CommitPending()); |
543 EXPECT_FALSE(scheduler->RedrawPending()); | 529 EXPECT_FALSE(scheduler->RedrawPending()); |
544 EXPECT_TRUE(client.needs_begin_frame()); | 530 EXPECT_TRUE(client.needs_begin_frame()); |
545 } | 531 } |
546 | 532 |
547 class SchedulerClientThatSetNeedsCommitInsideDraw : public FakeSchedulerClient { | 533 class SchedulerClientThatSetNeedsCommitInsideDraw : public FakeSchedulerClient { |
548 public: | 534 public: |
549 SchedulerClientThatSetNeedsCommitInsideDraw() | 535 SchedulerClientThatSetNeedsCommitInsideDraw() |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
587 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | 573 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
588 client.Reset(); | 574 client.Reset(); |
589 | 575 |
590 EXPECT_FALSE(client.needs_begin_frame()); | 576 EXPECT_FALSE(client.needs_begin_frame()); |
591 scheduler->SetNeedsRedraw(); | 577 scheduler->SetNeedsRedraw(); |
592 EXPECT_TRUE(scheduler->RedrawPending()); | 578 EXPECT_TRUE(scheduler->RedrawPending()); |
593 EXPECT_EQ(0, client.num_draws()); | 579 EXPECT_EQ(0, client.num_draws()); |
594 EXPECT_TRUE(client.needs_begin_frame()); | 580 EXPECT_TRUE(client.needs_begin_frame()); |
595 | 581 |
596 client.SetNeedsCommitOnNextDraw(); | 582 client.SetNeedsCommitOnNextDraw(); |
597 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | 583 client.AdvanceFrame(); |
598 client.SetNeedsCommitOnNextDraw(); | 584 client.SetNeedsCommitOnNextDraw(); |
599 client.task_runner().RunPendingTasks(); // Run posted deadline. | 585 client.task_runner().RunPendingTasks(); // Run posted deadline. |
600 EXPECT_EQ(1, client.num_draws()); | 586 EXPECT_EQ(1, client.num_draws()); |
601 EXPECT_TRUE(scheduler->CommitPending()); | 587 EXPECT_TRUE(scheduler->CommitPending()); |
602 EXPECT_TRUE(client.needs_begin_frame()); | 588 EXPECT_TRUE(client.needs_begin_frame()); |
603 scheduler->NotifyBeginMainFrameStarted(); | 589 scheduler->NotifyBeginMainFrameStarted(); |
604 scheduler->NotifyReadyToCommit(); | 590 scheduler->NotifyReadyToCommit(); |
605 | 591 |
606 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | 592 client.AdvanceFrame(); |
607 client.task_runner().RunPendingTasks(); // Run posted deadline. | 593 client.task_runner().RunPendingTasks(); // Run posted deadline. |
608 EXPECT_EQ(2, client.num_draws()); | 594 EXPECT_EQ(2, client.num_draws()); |
609 | 595 |
610 EXPECT_FALSE(scheduler->RedrawPending()); | 596 EXPECT_FALSE(scheduler->RedrawPending()); |
611 EXPECT_FALSE(scheduler->CommitPending()); | 597 EXPECT_FALSE(scheduler->CommitPending()); |
612 EXPECT_TRUE(client.needs_begin_frame()); | 598 EXPECT_TRUE(client.needs_begin_frame()); |
613 | 599 |
614 // We stop requesting BeginImplFrames after a BeginImplFrame where we don't | 600 // We stop requesting BeginImplFrames after a BeginImplFrame where we don't |
615 // swap. | 601 // swap. |
616 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | 602 client.AdvanceFrame(); |
617 client.task_runner().RunPendingTasks(); // Run posted deadline. | 603 client.task_runner().RunPendingTasks(); // Run posted deadline. |
618 EXPECT_EQ(2, client.num_draws()); | 604 EXPECT_EQ(2, client.num_draws()); |
619 EXPECT_FALSE(scheduler->RedrawPending()); | 605 EXPECT_FALSE(scheduler->RedrawPending()); |
620 EXPECT_FALSE(scheduler->CommitPending()); | 606 EXPECT_FALSE(scheduler->CommitPending()); |
621 EXPECT_FALSE(client.needs_begin_frame()); | 607 EXPECT_FALSE(client.needs_begin_frame()); |
622 } | 608 } |
623 | 609 |
624 // Tests that when a draw fails then the pending commit should not be dropped. | 610 // Tests that when a draw fails then the pending commit should not be dropped. |
625 TEST(SchedulerTest, RequestCommitInsideFailedDraw) { | 611 TEST(SchedulerTest, RequestCommitInsideFailedDraw) { |
626 SchedulerClientThatsetNeedsDrawInsideDraw client; | 612 SchedulerClientThatsetNeedsDrawInsideDraw client; |
627 SchedulerSettings default_scheduler_settings; | 613 SchedulerSettings default_scheduler_settings; |
628 TestScheduler* scheduler = client.CreateScheduler(default_scheduler_settings); | 614 TestScheduler* scheduler = client.CreateScheduler(default_scheduler_settings); |
629 scheduler->SetCanStart(); | 615 scheduler->SetCanStart(); |
630 scheduler->SetVisible(true); | 616 scheduler->SetVisible(true); |
631 scheduler->SetCanDraw(true); | 617 scheduler->SetCanDraw(true); |
632 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | 618 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
633 client.Reset(); | 619 client.Reset(); |
634 | 620 |
635 client.SetDrawWillHappen(false); | 621 client.SetDrawWillHappen(false); |
636 | 622 |
637 scheduler->SetNeedsRedraw(); | 623 scheduler->SetNeedsRedraw(); |
638 EXPECT_TRUE(scheduler->RedrawPending()); | 624 EXPECT_TRUE(scheduler->RedrawPending()); |
639 EXPECT_TRUE(client.needs_begin_frame()); | 625 EXPECT_TRUE(client.needs_begin_frame()); |
640 EXPECT_EQ(0, client.num_draws()); | 626 EXPECT_EQ(0, client.num_draws()); |
641 | 627 |
642 // Fail the draw. | 628 // Fail the draw. |
643 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | 629 client.AdvanceFrame(); |
644 client.task_runner().RunPendingTasks(); // Run posted deadline. | 630 client.task_runner().RunPendingTasks(); // Run posted deadline. |
645 EXPECT_EQ(1, client.num_draws()); | 631 EXPECT_EQ(1, client.num_draws()); |
646 | 632 |
647 // We have a commit pending and the draw failed, and we didn't lose the commit | 633 // We have a commit pending and the draw failed, and we didn't lose the commit |
648 // request. | 634 // request. |
649 EXPECT_TRUE(scheduler->CommitPending()); | 635 EXPECT_TRUE(scheduler->CommitPending()); |
650 EXPECT_TRUE(scheduler->RedrawPending()); | 636 EXPECT_TRUE(scheduler->RedrawPending()); |
651 EXPECT_TRUE(client.needs_begin_frame()); | 637 EXPECT_TRUE(client.needs_begin_frame()); |
652 | 638 |
653 // Fail the draw again. | 639 // Fail the draw again. |
654 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | 640 client.AdvanceFrame(); |
655 | 641 |
656 client.task_runner().RunPendingTasks(); // Run posted deadline. | 642 client.task_runner().RunPendingTasks(); // Run posted deadline. |
657 EXPECT_EQ(2, client.num_draws()); | 643 EXPECT_EQ(2, client.num_draws()); |
658 EXPECT_TRUE(scheduler->CommitPending()); | 644 EXPECT_TRUE(scheduler->CommitPending()); |
659 EXPECT_TRUE(scheduler->RedrawPending()); | 645 EXPECT_TRUE(scheduler->RedrawPending()); |
660 EXPECT_TRUE(client.needs_begin_frame()); | 646 EXPECT_TRUE(client.needs_begin_frame()); |
661 | 647 |
662 // Draw successfully. | 648 // Draw successfully. |
663 client.SetDrawWillHappen(true); | 649 client.SetDrawWillHappen(true); |
664 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | 650 client.AdvanceFrame(); |
665 client.task_runner().RunPendingTasks(); // Run posted deadline. | 651 client.task_runner().RunPendingTasks(); // Run posted deadline. |
666 EXPECT_EQ(3, client.num_draws()); | 652 EXPECT_EQ(3, client.num_draws()); |
667 EXPECT_TRUE(scheduler->CommitPending()); | 653 EXPECT_TRUE(scheduler->CommitPending()); |
668 EXPECT_FALSE(scheduler->RedrawPending()); | 654 EXPECT_FALSE(scheduler->RedrawPending()); |
669 EXPECT_TRUE(client.needs_begin_frame()); | 655 EXPECT_TRUE(client.needs_begin_frame()); |
670 } | 656 } |
671 | 657 |
672 TEST(SchedulerTest, NoSwapWhenDrawFails) { | 658 TEST(SchedulerTest, NoSwapWhenDrawFails) { |
673 SchedulerClientThatSetNeedsCommitInsideDraw client; | 659 SchedulerClientThatSetNeedsCommitInsideDraw client; |
674 SchedulerSettings default_scheduler_settings; | 660 SchedulerSettings default_scheduler_settings; |
675 TestScheduler* scheduler = client.CreateScheduler(default_scheduler_settings); | 661 TestScheduler* scheduler = client.CreateScheduler(default_scheduler_settings); |
676 scheduler->SetCanStart(); | 662 scheduler->SetCanStart(); |
677 scheduler->SetVisible(true); | 663 scheduler->SetVisible(true); |
678 scheduler->SetCanDraw(true); | 664 scheduler->SetCanDraw(true); |
679 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | 665 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
680 client.Reset(); | 666 client.Reset(); |
681 | 667 |
682 scheduler->SetNeedsRedraw(); | 668 scheduler->SetNeedsRedraw(); |
683 EXPECT_TRUE(scheduler->RedrawPending()); | 669 EXPECT_TRUE(scheduler->RedrawPending()); |
684 EXPECT_TRUE(client.needs_begin_frame()); | 670 EXPECT_TRUE(client.needs_begin_frame()); |
685 EXPECT_EQ(0, client.num_draws()); | 671 EXPECT_EQ(0, client.num_draws()); |
686 | 672 |
687 // Draw successfully, this starts a new frame. | 673 // Draw successfully, this starts a new frame. |
688 client.SetNeedsCommitOnNextDraw(); | 674 client.SetNeedsCommitOnNextDraw(); |
689 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | 675 client.AdvanceFrame(); |
690 client.task_runner().RunPendingTasks(); // Run posted deadline. | 676 client.task_runner().RunPendingTasks(); // Run posted deadline. |
691 EXPECT_EQ(1, client.num_draws()); | 677 EXPECT_EQ(1, client.num_draws()); |
692 | 678 |
693 scheduler->SetNeedsRedraw(); | 679 scheduler->SetNeedsRedraw(); |
694 EXPECT_TRUE(scheduler->RedrawPending()); | 680 EXPECT_TRUE(scheduler->RedrawPending()); |
695 EXPECT_TRUE(client.needs_begin_frame()); | 681 EXPECT_TRUE(client.needs_begin_frame()); |
696 | 682 |
697 // Fail to draw, this should not start a frame. | 683 // Fail to draw, this should not start a frame. |
698 client.SetDrawWillHappen(false); | 684 client.SetDrawWillHappen(false); |
699 client.SetNeedsCommitOnNextDraw(); | 685 client.SetNeedsCommitOnNextDraw(); |
700 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | 686 client.AdvanceFrame(); |
701 client.task_runner().RunPendingTasks(); // Run posted deadline. | 687 client.task_runner().RunPendingTasks(); // Run posted deadline. |
702 EXPECT_EQ(2, client.num_draws()); | 688 EXPECT_EQ(2, client.num_draws()); |
703 } | 689 } |
704 | 690 |
705 class SchedulerClientNeedsManageTilesInDraw : public FakeSchedulerClient { | 691 class SchedulerClientNeedsManageTilesInDraw : public FakeSchedulerClient { |
706 public: | 692 public: |
707 virtual DrawResult ScheduledActionDrawAndSwapIfPossible() | 693 virtual DrawResult ScheduledActionDrawAndSwapIfPossible() |
708 OVERRIDE { | 694 OVERRIDE { |
709 scheduler_->SetNeedsManageTiles(); | 695 scheduler_->SetNeedsManageTiles(); |
710 return FakeSchedulerClient::ScheduledActionDrawAndSwapIfPossible(); | 696 return FakeSchedulerClient::ScheduledActionDrawAndSwapIfPossible(); |
(...skipping 18 matching lines...) Expand all Loading... |
729 EXPECT_TRUE(scheduler->RedrawPending()); | 715 EXPECT_TRUE(scheduler->RedrawPending()); |
730 EXPECT_TRUE(scheduler->ManageTilesPending()); | 716 EXPECT_TRUE(scheduler->ManageTilesPending()); |
731 EXPECT_TRUE(client.needs_begin_frame()); | 717 EXPECT_TRUE(client.needs_begin_frame()); |
732 EXPECT_EQ(0, client.num_draws()); | 718 EXPECT_EQ(0, client.num_draws()); |
733 EXPECT_FALSE(client.HasAction("ScheduledActionManageTiles")); | 719 EXPECT_FALSE(client.HasAction("ScheduledActionManageTiles")); |
734 EXPECT_FALSE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); | 720 EXPECT_FALSE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); |
735 | 721 |
736 // We have no immediate actions to perform, so the BeginImplFrame should post | 722 // We have no immediate actions to perform, so the BeginImplFrame should post |
737 // the deadline task. | 723 // the deadline task. |
738 client.Reset(); | 724 client.Reset(); |
739 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | 725 client.AdvanceFrame(); |
740 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 726 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
741 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); | 727 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); |
742 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 728 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
743 | 729 |
744 // On the deadline, he actions should have occured in the right order. | 730 // On the deadline, he actions should have occured in the right order. |
745 client.Reset(); | 731 client.Reset(); |
746 client.task_runner().RunPendingTasks(); // Run posted deadline. | 732 client.task_runner().RunPendingTasks(); // Run posted deadline. |
747 EXPECT_EQ(1, client.num_draws()); | 733 EXPECT_EQ(1, client.num_draws()); |
748 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); | 734 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); |
749 EXPECT_TRUE(client.HasAction("ScheduledActionManageTiles")); | 735 EXPECT_TRUE(client.HasAction("ScheduledActionManageTiles")); |
750 EXPECT_LT(client.ActionIndex("ScheduledActionDrawAndSwapIfPossible"), | 736 EXPECT_LT(client.ActionIndex("ScheduledActionDrawAndSwapIfPossible"), |
751 client.ActionIndex("ScheduledActionManageTiles")); | 737 client.ActionIndex("ScheduledActionManageTiles")); |
752 EXPECT_FALSE(scheduler->RedrawPending()); | 738 EXPECT_FALSE(scheduler->RedrawPending()); |
753 EXPECT_FALSE(scheduler->ManageTilesPending()); | 739 EXPECT_FALSE(scheduler->ManageTilesPending()); |
754 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 740 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
755 | 741 |
756 // Request a draw. We don't need a ManageTiles yet. | 742 // Request a draw. We don't need a ManageTiles yet. |
757 client.Reset(); | 743 client.Reset(); |
758 scheduler->SetNeedsRedraw(); | 744 scheduler->SetNeedsRedraw(); |
759 EXPECT_TRUE(scheduler->RedrawPending()); | 745 EXPECT_TRUE(scheduler->RedrawPending()); |
760 EXPECT_FALSE(scheduler->ManageTilesPending()); | 746 EXPECT_FALSE(scheduler->ManageTilesPending()); |
761 EXPECT_TRUE(client.needs_begin_frame()); | 747 EXPECT_TRUE(client.needs_begin_frame()); |
762 EXPECT_EQ(0, client.num_draws()); | 748 EXPECT_EQ(0, client.num_draws()); |
763 | 749 |
764 // We have no immediate actions to perform, so the BeginImplFrame should post | 750 // We have no immediate actions to perform, so the BeginImplFrame should post |
765 // the deadline task. | 751 // the deadline task. |
766 client.Reset(); | 752 client.Reset(); |
767 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | 753 client.AdvanceFrame(); |
768 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 754 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
769 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); | 755 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); |
770 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 756 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
771 | 757 |
772 // Draw. The draw will trigger SetNeedsManageTiles, and | 758 // Draw. The draw will trigger SetNeedsManageTiles, and |
773 // then the ManageTiles action will be triggered after the Draw. | 759 // then the ManageTiles action will be triggered after the Draw. |
774 // Afterwards, neither a draw nor ManageTiles are pending. | 760 // Afterwards, neither a draw nor ManageTiles are pending. |
775 client.Reset(); | 761 client.Reset(); |
776 client.task_runner().RunPendingTasks(); // Run posted deadline. | 762 client.task_runner().RunPendingTasks(); // Run posted deadline. |
777 EXPECT_EQ(1, client.num_draws()); | 763 EXPECT_EQ(1, client.num_draws()); |
778 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); | 764 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); |
779 EXPECT_TRUE(client.HasAction("ScheduledActionManageTiles")); | 765 EXPECT_TRUE(client.HasAction("ScheduledActionManageTiles")); |
780 EXPECT_LT(client.ActionIndex("ScheduledActionDrawAndSwapIfPossible"), | 766 EXPECT_LT(client.ActionIndex("ScheduledActionDrawAndSwapIfPossible"), |
781 client.ActionIndex("ScheduledActionManageTiles")); | 767 client.ActionIndex("ScheduledActionManageTiles")); |
782 EXPECT_FALSE(scheduler->RedrawPending()); | 768 EXPECT_FALSE(scheduler->RedrawPending()); |
783 EXPECT_FALSE(scheduler->ManageTilesPending()); | 769 EXPECT_FALSE(scheduler->ManageTilesPending()); |
784 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 770 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
785 | 771 |
786 // We need a BeginImplFrame where we don't swap to go idle. | 772 // We need a BeginImplFrame where we don't swap to go idle. |
787 client.Reset(); | 773 client.Reset(); |
788 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | 774 client.AdvanceFrame(); |
789 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); | 775 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); |
790 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 776 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
791 client.Reset(); | 777 client.Reset(); |
792 client.task_runner().RunPendingTasks(); // Run posted deadline. | 778 client.task_runner().RunPendingTasks(); // Run posted deadline. |
793 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); | 779 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); |
794 EXPECT_FALSE(client.needs_begin_frame()); | 780 EXPECT_FALSE(client.needs_begin_frame()); |
795 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 781 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
796 EXPECT_EQ(0, client.num_draws()); | 782 EXPECT_EQ(0, client.num_draws()); |
797 | 783 |
798 // Now trigger a ManageTiles outside of a draw. We will then need | 784 // Now trigger a ManageTiles outside of a draw. We will then need |
799 // a begin-frame for the ManageTiles, but we don't need a draw. | 785 // a begin-frame for the ManageTiles, but we don't need a draw. |
800 client.Reset(); | 786 client.Reset(); |
801 EXPECT_FALSE(client.needs_begin_frame()); | 787 EXPECT_FALSE(client.needs_begin_frame()); |
802 scheduler->SetNeedsManageTiles(); | 788 scheduler->SetNeedsManageTiles(); |
803 EXPECT_TRUE(client.needs_begin_frame()); | 789 EXPECT_TRUE(client.needs_begin_frame()); |
804 EXPECT_TRUE(scheduler->ManageTilesPending()); | 790 EXPECT_TRUE(scheduler->ManageTilesPending()); |
805 EXPECT_FALSE(scheduler->RedrawPending()); | 791 EXPECT_FALSE(scheduler->RedrawPending()); |
806 | 792 |
807 // BeginImplFrame. There will be no draw, only ManageTiles. | 793 // BeginImplFrame. There will be no draw, only ManageTiles. |
808 client.Reset(); | 794 client.Reset(); |
809 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | 795 client.AdvanceFrame(); |
810 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); | 796 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); |
811 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 797 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
812 client.Reset(); | 798 client.Reset(); |
813 client.task_runner().RunPendingTasks(); // Run posted deadline. | 799 client.task_runner().RunPendingTasks(); // Run posted deadline. |
814 EXPECT_EQ(0, client.num_draws()); | 800 EXPECT_EQ(0, client.num_draws()); |
815 EXPECT_FALSE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); | 801 EXPECT_FALSE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); |
816 EXPECT_TRUE(client.HasAction("ScheduledActionManageTiles")); | 802 EXPECT_TRUE(client.HasAction("ScheduledActionManageTiles")); |
817 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 803 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
818 } | 804 } |
819 | 805 |
820 // Test that ManageTiles only happens once per frame. If an external caller | 806 // Test that ManageTiles only happens once per frame. If an external caller |
821 // initiates it, then the state machine should not ManageTiles on that frame. | 807 // initiates it, then the state machine should not ManageTiles on that frame. |
822 TEST(SchedulerTest, ManageTilesOncePerFrame) { | 808 TEST(SchedulerTest, ManageTilesOncePerFrame) { |
823 FakeSchedulerClient client; | 809 FakeSchedulerClient client; |
824 SchedulerSettings default_scheduler_settings; | 810 SchedulerSettings default_scheduler_settings; |
825 TestScheduler* scheduler = client.CreateScheduler(default_scheduler_settings); | 811 TestScheduler* scheduler = client.CreateScheduler(default_scheduler_settings); |
826 scheduler->SetCanStart(); | 812 scheduler->SetCanStart(); |
827 scheduler->SetVisible(true); | 813 scheduler->SetVisible(true); |
828 scheduler->SetCanDraw(true); | 814 scheduler->SetCanDraw(true); |
829 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | 815 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
830 | 816 |
831 // If DidManageTiles during a frame, then ManageTiles should not occur again. | 817 // If DidManageTiles during a frame, then ManageTiles should not occur again. |
832 scheduler->SetNeedsManageTiles(); | 818 scheduler->SetNeedsManageTiles(); |
833 scheduler->SetNeedsRedraw(); | 819 scheduler->SetNeedsRedraw(); |
834 client.Reset(); | 820 client.Reset(); |
835 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | 821 client.AdvanceFrame(); |
836 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 822 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
837 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); | 823 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); |
838 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 824 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
839 | 825 |
840 EXPECT_TRUE(scheduler->ManageTilesPending()); | 826 EXPECT_TRUE(scheduler->ManageTilesPending()); |
841 scheduler->DidManageTiles(); // An explicit ManageTiles. | 827 scheduler->DidManageTiles(); // An explicit ManageTiles. |
842 EXPECT_FALSE(scheduler->ManageTilesPending()); | 828 EXPECT_FALSE(scheduler->ManageTilesPending()); |
843 | 829 |
844 client.Reset(); | 830 client.Reset(); |
845 client.task_runner().RunPendingTasks(); // Run posted deadline. | 831 client.task_runner().RunPendingTasks(); // Run posted deadline. |
846 EXPECT_EQ(1, client.num_draws()); | 832 EXPECT_EQ(1, client.num_draws()); |
847 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); | 833 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); |
848 EXPECT_FALSE(client.HasAction("ScheduledActionManageTiles")); | 834 EXPECT_FALSE(client.HasAction("ScheduledActionManageTiles")); |
849 EXPECT_FALSE(scheduler->RedrawPending()); | 835 EXPECT_FALSE(scheduler->RedrawPending()); |
850 EXPECT_FALSE(scheduler->ManageTilesPending()); | 836 EXPECT_FALSE(scheduler->ManageTilesPending()); |
851 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 837 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
852 | 838 |
853 // Next frame without DidManageTiles should ManageTiles with draw. | 839 // Next frame without DidManageTiles should ManageTiles with draw. |
854 scheduler->SetNeedsManageTiles(); | 840 scheduler->SetNeedsManageTiles(); |
855 scheduler->SetNeedsRedraw(); | 841 scheduler->SetNeedsRedraw(); |
856 client.Reset(); | 842 client.Reset(); |
857 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | 843 client.AdvanceFrame(); |
858 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 844 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
859 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); | 845 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); |
860 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 846 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
861 | 847 |
862 client.Reset(); | 848 client.Reset(); |
863 client.task_runner().RunPendingTasks(); // Run posted deadline. | 849 client.task_runner().RunPendingTasks(); // Run posted deadline. |
864 EXPECT_EQ(1, client.num_draws()); | 850 EXPECT_EQ(1, client.num_draws()); |
865 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); | 851 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); |
866 EXPECT_TRUE(client.HasAction("ScheduledActionManageTiles")); | 852 EXPECT_TRUE(client.HasAction("ScheduledActionManageTiles")); |
867 EXPECT_LT(client.ActionIndex("ScheduledActionDrawAndSwapIfPossible"), | 853 EXPECT_LT(client.ActionIndex("ScheduledActionDrawAndSwapIfPossible"), |
868 client.ActionIndex("ScheduledActionManageTiles")); | 854 client.ActionIndex("ScheduledActionManageTiles")); |
869 EXPECT_FALSE(scheduler->RedrawPending()); | 855 EXPECT_FALSE(scheduler->RedrawPending()); |
870 EXPECT_FALSE(scheduler->ManageTilesPending()); | 856 EXPECT_FALSE(scheduler->ManageTilesPending()); |
871 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 857 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
872 scheduler->DidManageTiles(); // Corresponds to ScheduledActionManageTiles | 858 scheduler->DidManageTiles(); // Corresponds to ScheduledActionManageTiles |
873 | 859 |
874 // If we get another DidManageTiles within the same frame, we should | 860 // If we get another DidManageTiles within the same frame, we should |
875 // not ManageTiles on the next frame. | 861 // not ManageTiles on the next frame. |
876 scheduler->DidManageTiles(); // An explicit ManageTiles. | 862 scheduler->DidManageTiles(); // An explicit ManageTiles. |
877 scheduler->SetNeedsManageTiles(); | 863 scheduler->SetNeedsManageTiles(); |
878 scheduler->SetNeedsRedraw(); | 864 scheduler->SetNeedsRedraw(); |
879 client.Reset(); | 865 client.Reset(); |
880 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | 866 client.AdvanceFrame(); |
881 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 867 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
882 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); | 868 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); |
883 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 869 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
884 | 870 |
885 EXPECT_TRUE(scheduler->ManageTilesPending()); | 871 EXPECT_TRUE(scheduler->ManageTilesPending()); |
886 | 872 |
887 client.Reset(); | 873 client.Reset(); |
888 client.task_runner().RunPendingTasks(); // Run posted deadline. | 874 client.task_runner().RunPendingTasks(); // Run posted deadline. |
889 EXPECT_EQ(1, client.num_draws()); | 875 EXPECT_EQ(1, client.num_draws()); |
890 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); | 876 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); |
891 EXPECT_FALSE(client.HasAction("ScheduledActionManageTiles")); | 877 EXPECT_FALSE(client.HasAction("ScheduledActionManageTiles")); |
892 EXPECT_FALSE(scheduler->RedrawPending()); | 878 EXPECT_FALSE(scheduler->RedrawPending()); |
893 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 879 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
894 | 880 |
895 // If we get another DidManageTiles, we should not ManageTiles on the next | 881 // If we get another DidManageTiles, we should not ManageTiles on the next |
896 // frame. This verifies we don't alternate calling ManageTiles once and twice. | 882 // frame. This verifies we don't alternate calling ManageTiles once and twice. |
897 EXPECT_TRUE(scheduler->ManageTilesPending()); | 883 EXPECT_TRUE(scheduler->ManageTilesPending()); |
898 scheduler->DidManageTiles(); // An explicit ManageTiles. | 884 scheduler->DidManageTiles(); // An explicit ManageTiles. |
899 EXPECT_FALSE(scheduler->ManageTilesPending()); | 885 EXPECT_FALSE(scheduler->ManageTilesPending()); |
900 scheduler->SetNeedsManageTiles(); | 886 scheduler->SetNeedsManageTiles(); |
901 scheduler->SetNeedsRedraw(); | 887 scheduler->SetNeedsRedraw(); |
902 client.Reset(); | 888 client.Reset(); |
903 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | 889 client.AdvanceFrame(); |
904 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 890 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
905 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); | 891 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); |
906 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 892 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
907 | 893 |
908 EXPECT_TRUE(scheduler->ManageTilesPending()); | 894 EXPECT_TRUE(scheduler->ManageTilesPending()); |
909 | 895 |
910 client.Reset(); | 896 client.Reset(); |
911 client.task_runner().RunPendingTasks(); // Run posted deadline. | 897 client.task_runner().RunPendingTasks(); // Run posted deadline. |
912 EXPECT_EQ(1, client.num_draws()); | 898 EXPECT_EQ(1, client.num_draws()); |
913 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); | 899 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); |
914 EXPECT_FALSE(client.HasAction("ScheduledActionManageTiles")); | 900 EXPECT_FALSE(client.HasAction("ScheduledActionManageTiles")); |
915 EXPECT_FALSE(scheduler->RedrawPending()); | 901 EXPECT_FALSE(scheduler->RedrawPending()); |
916 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 902 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
917 | 903 |
918 // Next frame without DidManageTiles should ManageTiles with draw. | 904 // Next frame without DidManageTiles should ManageTiles with draw. |
919 scheduler->SetNeedsManageTiles(); | 905 scheduler->SetNeedsManageTiles(); |
920 scheduler->SetNeedsRedraw(); | 906 scheduler->SetNeedsRedraw(); |
921 client.Reset(); | 907 client.Reset(); |
922 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | 908 client.AdvanceFrame(); |
923 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 909 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
924 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); | 910 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); |
925 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 911 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
926 | 912 |
927 client.Reset(); | 913 client.Reset(); |
928 client.task_runner().RunPendingTasks(); // Run posted deadline. | 914 client.task_runner().RunPendingTasks(); // Run posted deadline. |
929 EXPECT_EQ(1, client.num_draws()); | 915 EXPECT_EQ(1, client.num_draws()); |
930 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); | 916 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); |
931 EXPECT_TRUE(client.HasAction("ScheduledActionManageTiles")); | 917 EXPECT_TRUE(client.HasAction("ScheduledActionManageTiles")); |
932 EXPECT_LT(client.ActionIndex("ScheduledActionDrawAndSwapIfPossible"), | 918 EXPECT_LT(client.ActionIndex("ScheduledActionDrawAndSwapIfPossible"), |
(...skipping 15 matching lines...) Expand all Loading... |
948 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | 934 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
949 | 935 |
950 client.SetRedrawWillHappenIfUpdateVisibleTilesHappens(true); | 936 client.SetRedrawWillHappenIfUpdateVisibleTilesHappens(true); |
951 | 937 |
952 // SetNeedsCommit should begin the frame. | 938 // SetNeedsCommit should begin the frame. |
953 client.Reset(); | 939 client.Reset(); |
954 scheduler->SetNeedsCommit(); | 940 scheduler->SetNeedsCommit(); |
955 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); | 941 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); |
956 | 942 |
957 client.Reset(); | 943 client.Reset(); |
958 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | 944 client.AdvanceFrame(); |
959 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 945 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
960 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); | 946 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); |
961 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 947 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
962 | 948 |
963 client.Reset(); | 949 client.Reset(); |
964 scheduler->NotifyBeginMainFrameStarted(); | 950 scheduler->NotifyBeginMainFrameStarted(); |
965 scheduler->NotifyReadyToCommit(); | 951 scheduler->NotifyReadyToCommit(); |
966 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); | 952 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); |
967 | 953 |
968 client.Reset(); | 954 client.Reset(); |
969 scheduler->NotifyReadyToActivate(); | 955 scheduler->NotifyReadyToActivate(); |
970 EXPECT_SINGLE_ACTION("ScheduledActionActivateSyncTree", client); | 956 EXPECT_SINGLE_ACTION("ScheduledActionActivateSyncTree", client); |
971 | 957 |
972 client.Reset(); | 958 client.Reset(); |
973 client.SetSwapContainsIncompleteTile(true); | 959 client.SetSwapContainsIncompleteTile(true); |
974 client.task_runner().RunPendingTasks(); // Run posted deadline. | 960 client.task_runner().RunPendingTasks(); // Run posted deadline. |
975 EXPECT_ACTION("ScheduledActionAnimate", client, 0, 2); | 961 EXPECT_ACTION("ScheduledActionAnimate", client, 0, 2); |
976 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 1, 2); | 962 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 1, 2); |
977 EXPECT_FALSE(scheduler->RedrawPending()); | 963 EXPECT_FALSE(scheduler->RedrawPending()); |
978 | 964 |
979 client.Reset(); | 965 client.Reset(); |
980 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | 966 client.AdvanceFrame(); |
981 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); | 967 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); |
982 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 968 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
983 | 969 |
984 client.Reset(); | 970 client.Reset(); |
985 client.task_runner().RunPendingTasks(); // Run posted deadline. | 971 client.task_runner().RunPendingTasks(); // Run posted deadline. |
986 EXPECT_ACTION("ScheduledActionUpdateVisibleTiles", client, 0, 3); | 972 EXPECT_ACTION("ScheduledActionUpdateVisibleTiles", client, 0, 3); |
987 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 3); | 973 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 3); |
988 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 2, 3); | 974 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 2, 3); |
989 | 975 |
990 client.Reset(); | 976 client.Reset(); |
991 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | 977 client.AdvanceFrame(); |
992 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); | 978 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); |
993 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 979 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
994 | 980 |
995 // No more UpdateVisibleTiles(). | 981 // No more UpdateVisibleTiles(). |
996 client.Reset(); | 982 client.Reset(); |
997 client.task_runner().RunPendingTasks(); // Run posted deadline. | 983 client.task_runner().RunPendingTasks(); // Run posted deadline. |
998 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); | 984 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); |
999 EXPECT_FALSE(client.needs_begin_frame()); | 985 EXPECT_FALSE(client.needs_begin_frame()); |
1000 } | 986 } |
1001 | 987 |
1002 TEST(SchedulerTest, TriggerBeginFrameDeadlineEarly) { | 988 TEST(SchedulerTest, TriggerBeginFrameDeadlineEarly) { |
1003 SchedulerClientNeedsManageTilesInDraw client; | 989 SchedulerClientNeedsManageTilesInDraw client; |
1004 SchedulerSettings default_scheduler_settings; | 990 SchedulerSettings default_scheduler_settings; |
1005 TestScheduler* scheduler = client.CreateScheduler(default_scheduler_settings); | 991 TestScheduler* scheduler = client.CreateScheduler(default_scheduler_settings); |
1006 scheduler->SetCanStart(); | 992 scheduler->SetCanStart(); |
1007 scheduler->SetVisible(true); | 993 scheduler->SetVisible(true); |
1008 scheduler->SetCanDraw(true); | 994 scheduler->SetCanDraw(true); |
1009 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | 995 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
1010 | 996 |
1011 client.Reset(); | 997 client.Reset(); |
1012 scheduler->SetNeedsRedraw(); | 998 scheduler->SetNeedsRedraw(); |
1013 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | 999 client.AdvanceFrame(); |
1014 | 1000 |
1015 // The deadline should be zero since there is no work other than drawing | 1001 // The deadline should be zero since there is no work other than drawing |
1016 // pending. | 1002 // pending. |
1017 EXPECT_EQ(base::TimeTicks(), client.posted_begin_impl_frame_deadline()); | 1003 EXPECT_EQ(base::TimeTicks(), client.posted_begin_impl_frame_deadline()); |
1018 } | 1004 } |
1019 | 1005 |
1020 class SchedulerClientWithFixedEstimates : public FakeSchedulerClient { | 1006 class SchedulerClientWithFixedEstimates : public FakeSchedulerClient { |
1021 public: | 1007 public: |
1022 SchedulerClientWithFixedEstimates( | 1008 SchedulerClientWithFixedEstimates( |
1023 base::TimeDelta draw_duration, | 1009 base::TimeDelta draw_duration, |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1059 scheduler->SetCanStart(); | 1045 scheduler->SetCanStart(); |
1060 scheduler->SetVisible(true); | 1046 scheduler->SetVisible(true); |
1061 scheduler->SetCanDraw(true); | 1047 scheduler->SetCanDraw(true); |
1062 scheduler->SetImplLatencyTakesPriority(impl_latency_takes_priority); | 1048 scheduler->SetImplLatencyTakesPriority(impl_latency_takes_priority); |
1063 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | 1049 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
1064 | 1050 |
1065 // Impl thread hits deadline before commit finishes. | 1051 // Impl thread hits deadline before commit finishes. |
1066 client.Reset(); | 1052 client.Reset(); |
1067 scheduler->SetNeedsCommit(); | 1053 scheduler->SetNeedsCommit(); |
1068 EXPECT_FALSE(scheduler->MainThreadIsInHighLatencyMode()); | 1054 EXPECT_FALSE(scheduler->MainThreadIsInHighLatencyMode()); |
1069 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | 1055 client.AdvanceFrame(); |
1070 EXPECT_FALSE(scheduler->MainThreadIsInHighLatencyMode()); | 1056 EXPECT_FALSE(scheduler->MainThreadIsInHighLatencyMode()); |
1071 client.task_runner().RunPendingTasks(); // Run posted deadline. | 1057 client.task_runner().RunPendingTasks(); // Run posted deadline. |
1072 EXPECT_TRUE(scheduler->MainThreadIsInHighLatencyMode()); | 1058 EXPECT_TRUE(scheduler->MainThreadIsInHighLatencyMode()); |
1073 scheduler->NotifyBeginMainFrameStarted(); | 1059 scheduler->NotifyBeginMainFrameStarted(); |
1074 scheduler->NotifyReadyToCommit(); | 1060 scheduler->NotifyReadyToCommit(); |
1075 EXPECT_TRUE(scheduler->MainThreadIsInHighLatencyMode()); | 1061 EXPECT_TRUE(scheduler->MainThreadIsInHighLatencyMode()); |
1076 EXPECT_TRUE(client.HasAction("ScheduledActionSendBeginMainFrame")); | 1062 EXPECT_TRUE(client.HasAction("ScheduledActionSendBeginMainFrame")); |
1077 | 1063 |
1078 client.Reset(); | 1064 client.Reset(); |
1079 scheduler->SetNeedsCommit(); | 1065 scheduler->SetNeedsCommit(); |
1080 EXPECT_TRUE(scheduler->MainThreadIsInHighLatencyMode()); | 1066 EXPECT_TRUE(scheduler->MainThreadIsInHighLatencyMode()); |
1081 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | 1067 client.AdvanceFrame(); |
1082 EXPECT_TRUE(scheduler->MainThreadIsInHighLatencyMode()); | 1068 EXPECT_TRUE(scheduler->MainThreadIsInHighLatencyMode()); |
1083 client.task_runner().RunPendingTasks(); // Run posted deadline. | 1069 client.task_runner().RunPendingTasks(); // Run posted deadline. |
1084 EXPECT_EQ(scheduler->MainThreadIsInHighLatencyMode(), | 1070 EXPECT_EQ(scheduler->MainThreadIsInHighLatencyMode(), |
1085 should_send_begin_main_frame); | 1071 should_send_begin_main_frame); |
1086 EXPECT_EQ(client.HasAction("ScheduledActionSendBeginMainFrame"), | 1072 EXPECT_EQ(client.HasAction("ScheduledActionSendBeginMainFrame"), |
1087 should_send_begin_main_frame); | 1073 should_send_begin_main_frame); |
1088 } | 1074 } |
1089 | 1075 |
1090 TEST(SchedulerTest, | 1076 TEST(SchedulerTest, |
1091 SkipMainFrameIfHighLatencyAndCanCommitAndActivateBeforeDeadline) { | 1077 SkipMainFrameIfHighLatencyAndCanCommitAndActivateBeforeDeadline) { |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1128 scheduler->SetCanStart(); | 1114 scheduler->SetCanStart(); |
1129 scheduler->SetVisible(true); | 1115 scheduler->SetVisible(true); |
1130 scheduler->DidCreateAndInitializeOutputSurface(); | 1116 scheduler->DidCreateAndInitializeOutputSurface(); |
1131 | 1117 |
1132 scheduler->SetNeedsCommit(); | 1118 scheduler->SetNeedsCommit(); |
1133 EXPECT_TRUE(scheduler->CommitPending()); | 1119 EXPECT_TRUE(scheduler->CommitPending()); |
1134 scheduler->NotifyBeginMainFrameStarted(); | 1120 scheduler->NotifyBeginMainFrameStarted(); |
1135 scheduler->NotifyReadyToCommit(); | 1121 scheduler->NotifyReadyToCommit(); |
1136 scheduler->SetNeedsRedraw(); | 1122 scheduler->SetNeedsRedraw(); |
1137 | 1123 |
1138 BeginFrameArgs frame_args = CreateBeginFrameArgsForTesting(); | 1124 BeginFrameArgs frame_args = CreateBeginFrameArgsForTesting(client.now_src()); |
1139 frame_args.interval = base::TimeDelta::FromMilliseconds(1000); | 1125 frame_args.interval = base::TimeDelta::FromMilliseconds(1000); |
1140 scheduler->BeginFrame(frame_args); | 1126 scheduler->BeginFrame(frame_args); |
1141 | 1127 |
1142 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1128 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
1143 client.task_runner().RunPendingTasks(); // Run posted deadline. | 1129 client.task_runner().RunPendingTasks(); // Run posted deadline. |
1144 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 1130 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
1145 | 1131 |
1146 scheduler->DidSwapBuffers(); | 1132 scheduler->DidSwapBuffers(); |
1147 scheduler->DidSwapBuffersComplete(); | 1133 scheduler->DidSwapBuffersComplete(); |
1148 | 1134 |
(...skipping 11 matching lines...) Expand all Loading... |
1160 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 1146 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
1161 scheduler->DidSwapBuffers(); | 1147 scheduler->DidSwapBuffers(); |
1162 | 1148 |
1163 // Spin the event loop a few times and make sure we get more | 1149 // Spin the event loop a few times and make sure we get more |
1164 // DidAnticipateDrawTimeChange calls every time. | 1150 // DidAnticipateDrawTimeChange calls every time. |
1165 int actions_so_far = client.num_actions_(); | 1151 int actions_so_far = client.num_actions_(); |
1166 | 1152 |
1167 // Does three iterations to make sure that the timer is properly repeating. | 1153 // Does three iterations to make sure that the timer is properly repeating. |
1168 for (int i = 0; i < 3; ++i) { | 1154 for (int i = 0; i < 3; ++i) { |
1169 EXPECT_EQ((frame_args.interval * 2).InMicroseconds(), | 1155 EXPECT_EQ((frame_args.interval * 2).InMicroseconds(), |
1170 client.task_runner().NextPendingTaskDelay().InMicroseconds()) | 1156 client.task_runner().DelayToNextTaskTime().InMicroseconds()) |
1171 << scheduler->AsValue()->ToString(); | 1157 << scheduler->AsValue()->ToString(); |
1172 client.task_runner().RunPendingTasks(); | 1158 client.task_runner().RunPendingTasks(); |
1173 EXPECT_GT(client.num_actions_(), actions_so_far); | 1159 EXPECT_GT(client.num_actions_(), actions_so_far); |
1174 EXPECT_STREQ(client.Action(client.num_actions_() - 1), | 1160 EXPECT_STREQ(client.Action(client.num_actions_() - 1), |
1175 "DidAnticipatedDrawTimeChange"); | 1161 "DidAnticipatedDrawTimeChange"); |
1176 actions_so_far = client.num_actions_(); | 1162 actions_so_far = client.num_actions_(); |
1177 } | 1163 } |
1178 | 1164 |
1179 // Do the same thing after BeginMainFrame starts but still before activation. | 1165 // Do the same thing after BeginMainFrame starts but still before activation. |
1180 scheduler->NotifyBeginMainFrameStarted(); | 1166 scheduler->NotifyBeginMainFrameStarted(); |
1181 for (int i = 0; i < 3; ++i) { | 1167 for (int i = 0; i < 3; ++i) { |
1182 EXPECT_EQ((frame_args.interval * 2).InMicroseconds(), | 1168 EXPECT_EQ((frame_args.interval * 2).InMicroseconds(), |
1183 client.task_runner().NextPendingTaskDelay().InMicroseconds()) | 1169 client.task_runner().DelayToNextTaskTime().InMicroseconds()) |
1184 << scheduler->AsValue()->ToString(); | 1170 << scheduler->AsValue()->ToString(); |
1185 client.task_runner().RunPendingTasks(); | 1171 client.task_runner().RunPendingTasks(); |
1186 EXPECT_GT(client.num_actions_(), actions_so_far); | 1172 EXPECT_GT(client.num_actions_(), actions_so_far); |
1187 EXPECT_STREQ(client.Action(client.num_actions_() - 1), | 1173 EXPECT_STREQ(client.Action(client.num_actions_() - 1), |
1188 "DidAnticipatedDrawTimeChange"); | 1174 "DidAnticipatedDrawTimeChange"); |
1189 actions_so_far = client.num_actions_(); | 1175 actions_so_far = client.num_actions_(); |
1190 } | 1176 } |
1191 } | 1177 } |
1192 | 1178 |
1193 TEST(SchedulerTest, BeginRetroFrame) { | 1179 TEST(SchedulerTest, BeginRetroFrame) { |
1194 FakeSchedulerClient client; | 1180 FakeSchedulerClient client; |
1195 SchedulerSettings scheduler_settings; | 1181 SchedulerSettings scheduler_settings; |
1196 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings); | 1182 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings); |
1197 scheduler->SetCanStart(); | 1183 scheduler->SetCanStart(); |
1198 scheduler->SetVisible(true); | 1184 scheduler->SetVisible(true); |
1199 scheduler->SetCanDraw(true); | 1185 scheduler->SetCanDraw(true); |
1200 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | 1186 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
1201 | 1187 |
1202 // SetNeedsCommit should begin the frame on the next BeginImplFrame. | 1188 // SetNeedsCommit should begin the frame on the next BeginImplFrame. |
1203 client.Reset(); | 1189 client.Reset(); |
1204 scheduler->SetNeedsCommit(); | 1190 scheduler->SetNeedsCommit(); |
1205 EXPECT_TRUE(client.needs_begin_frame()); | 1191 EXPECT_TRUE(client.needs_begin_frame()); |
1206 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); | 1192 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); |
1207 client.Reset(); | 1193 client.Reset(); |
1208 | 1194 |
1209 // Create a BeginFrame with a long deadline to avoid race conditions. | 1195 // Create a BeginFrame with a long deadline to avoid race conditions. |
1210 // This is the first BeginFrame, which will be handled immediately. | 1196 // This is the first BeginFrame, which will be handled immediately. |
1211 BeginFrameArgs args = CreateBeginFrameArgsForTesting(); | 1197 BeginFrameArgs args = CreateBeginFrameArgsForTesting(client.now_src()); |
1212 args.deadline += base::TimeDelta::FromHours(1); | 1198 args.deadline += base::TimeDelta::FromHours(1); |
1213 scheduler->BeginFrame(args); | 1199 scheduler->BeginFrame(args); |
1214 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 1200 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
1215 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); | 1201 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); |
1216 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1202 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
1217 EXPECT_TRUE(client.needs_begin_frame()); | 1203 EXPECT_TRUE(client.needs_begin_frame()); |
1218 client.Reset(); | 1204 client.Reset(); |
1219 | 1205 |
1220 // Queue BeginFrames while we are still handling the previous BeginFrame. | 1206 // Queue BeginFrames while we are still handling the previous BeginFrame. |
1221 args.frame_time += base::TimeDelta::FromSeconds(1); | 1207 args.frame_time += base::TimeDelta::FromSeconds(1); |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1280 | 1266 |
1281 // SetNeedsCommit should begin the frame on the next BeginImplFrame. | 1267 // SetNeedsCommit should begin the frame on the next BeginImplFrame. |
1282 client.Reset(); | 1268 client.Reset(); |
1283 scheduler->SetNeedsCommit(); | 1269 scheduler->SetNeedsCommit(); |
1284 EXPECT_TRUE(client.needs_begin_frame()); | 1270 EXPECT_TRUE(client.needs_begin_frame()); |
1285 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); | 1271 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); |
1286 client.Reset(); | 1272 client.Reset(); |
1287 | 1273 |
1288 // Create a BeginFrame with a long deadline to avoid race conditions. | 1274 // Create a BeginFrame with a long deadline to avoid race conditions. |
1289 // This is the first BeginFrame, which will be handled immediately. | 1275 // This is the first BeginFrame, which will be handled immediately. |
1290 BeginFrameArgs args = CreateBeginFrameArgsForTesting(); | 1276 BeginFrameArgs args = CreateBeginFrameArgsForTesting(client.now_src()); |
1291 args.deadline += base::TimeDelta::FromHours(1); | 1277 args.deadline += base::TimeDelta::FromHours(1); |
1292 scheduler->BeginFrame(args); | 1278 scheduler->BeginFrame(args); |
1293 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 1279 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
1294 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); | 1280 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); |
1295 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1281 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
1296 EXPECT_TRUE(client.needs_begin_frame()); | 1282 EXPECT_TRUE(client.needs_begin_frame()); |
1297 client.Reset(); | 1283 client.Reset(); |
1298 | 1284 |
1299 // Queue BeginFrame while we are still handling the previous BeginFrame. | 1285 // Queue BeginFrame while we are still handling the previous BeginFrame. |
1300 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1286 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1338 | 1324 |
1339 // Take us out of a swap throttled state. | 1325 // Take us out of a swap throttled state. |
1340 scheduler->DidSwapBuffersComplete(); | 1326 scheduler->DidSwapBuffersComplete(); |
1341 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 0, 1); | 1327 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 0, 1); |
1342 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1328 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
1343 EXPECT_TRUE(client.needs_begin_frame()); | 1329 EXPECT_TRUE(client.needs_begin_frame()); |
1344 client.Reset(); | 1330 client.Reset(); |
1345 | 1331 |
1346 // BeginImplFrame deadline should draw. | 1332 // BeginImplFrame deadline should draw. |
1347 scheduler->SetNeedsRedraw(); | 1333 scheduler->SetNeedsRedraw(); |
1348 client.task_runner().RunPendingTasks(); // Run posted deadline. | 1334 |
| 1335 EXPECT_TRUE(client.task_runner().RunTasksWhile( |
| 1336 client.ImplFrameDeadlinePending(true))); |
| 1337 |
1349 EXPECT_ACTION("ScheduledActionAnimate", client, 0, 2); | 1338 EXPECT_ACTION("ScheduledActionAnimate", client, 0, 2); |
1350 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 1, 2); | 1339 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 1, 2); |
1351 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 1340 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
1352 EXPECT_TRUE(client.needs_begin_frame()); | 1341 EXPECT_TRUE(client.needs_begin_frame()); |
1353 client.Reset(); | 1342 client.Reset(); |
1354 } | 1343 } |
1355 | 1344 |
1356 void BeginFramesNotFromClient(bool begin_frame_scheduling_enabled, | 1345 void BeginFramesNotFromClient(bool begin_frame_scheduling_enabled, |
1357 bool throttle_frame_production) { | 1346 bool throttle_frame_production) { |
1358 FakeSchedulerClient client; | 1347 FakeSchedulerClient client; |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1399 | 1388 |
1400 // BeginImplFrame should prepare the draw. | 1389 // BeginImplFrame should prepare the draw. |
1401 client.task_runner().RunPendingTasks(); // Run posted BeginFrame. | 1390 client.task_runner().RunPendingTasks(); // Run posted BeginFrame. |
1402 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 1391 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
1403 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); | 1392 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); |
1404 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1393 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
1405 EXPECT_FALSE(client.needs_begin_frame()); | 1394 EXPECT_FALSE(client.needs_begin_frame()); |
1406 client.Reset(); | 1395 client.Reset(); |
1407 | 1396 |
1408 // BeginImplFrame deadline should draw. | 1397 // BeginImplFrame deadline should draw. |
1409 client.task_runner().RunPendingTasks(); // Run posted deadline. | 1398 client.task_runner().RunTasksWhile(client.ImplFrameDeadlinePending(true)); |
1410 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 1); | 1399 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 1); |
1411 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 1400 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
1412 EXPECT_FALSE(client.needs_begin_frame()); | 1401 EXPECT_FALSE(client.needs_begin_frame()); |
1413 client.Reset(); | 1402 client.Reset(); |
1414 | 1403 |
1415 // The following BeginImplFrame deadline should SetNeedsBeginFrame(false) | 1404 // The following BeginImplFrame deadline should SetNeedsBeginFrame(false) |
1416 // to avoid excessive toggles. | 1405 // to avoid excessive toggles. |
1417 client.task_runner().RunPendingTasks(); // Run posted BeginFrame. | 1406 client.task_runner().RunPendingTasks(); // Run posted BeginFrame. |
1418 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); | 1407 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); |
1419 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1408 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
1420 client.Reset(); | 1409 client.Reset(); |
1421 | 1410 |
1422 // Make sure SetNeedsBeginFrame isn't called on the client | 1411 // Make sure SetNeedsBeginFrame isn't called on the client |
1423 // when the BeginFrame is no longer needed. | 1412 // when the BeginFrame is no longer needed. |
1424 client.task_runner().RunPendingTasks(); // Run posted deadline. | 1413 client.task_runner().RunPendingTasks(); // Run posted deadline. |
1425 EXPECT_NO_ACTION(client); | 1414 EXPECT_NO_ACTION(client); |
1426 EXPECT_FALSE(client.needs_begin_frame()); | 1415 EXPECT_FALSE(client.needs_begin_frame()); |
1427 client.Reset(); | 1416 client.Reset(); |
1428 } | 1417 } |
1429 | 1418 |
1430 // See: http://crbug.com/380889 | 1419 TEST(SchedulerTest, SyntheticBeginFrames) { |
1431 TEST(SchedulerTest, DISABLED_SyntheticBeginFrames) { | |
1432 bool begin_frame_scheduling_enabled = false; | 1420 bool begin_frame_scheduling_enabled = false; |
1433 bool throttle_frame_production = true; | 1421 bool throttle_frame_production = true; |
1434 BeginFramesNotFromClient(begin_frame_scheduling_enabled, | 1422 BeginFramesNotFromClient(begin_frame_scheduling_enabled, |
1435 throttle_frame_production); | 1423 throttle_frame_production); |
1436 } | 1424 } |
1437 | 1425 |
1438 TEST(SchedulerTest, VSyncThrottlingDisabled) { | 1426 TEST(SchedulerTest, VSyncThrottlingDisabled) { |
1439 bool begin_frame_scheduling_enabled = true; | 1427 bool begin_frame_scheduling_enabled = true; |
1440 bool throttle_frame_production = false; | 1428 bool throttle_frame_production = false; |
1441 BeginFramesNotFromClient(begin_frame_scheduling_enabled, | 1429 BeginFramesNotFromClient(begin_frame_scheduling_enabled, |
1442 throttle_frame_production); | 1430 throttle_frame_production); |
1443 } | 1431 } |
1444 | 1432 |
1445 // See: http://crbug.com/380889 | 1433 TEST(SchedulerTest, SyntheticBeginFrames_And_VSyncThrottlingDisabled) { |
1446 TEST(SchedulerTest, DISABLED_SyntheticBeginFrames_And_VSyncThrottlingDisabled) { | |
1447 bool begin_frame_scheduling_enabled = false; | 1434 bool begin_frame_scheduling_enabled = false; |
1448 bool throttle_frame_production = false; | 1435 bool throttle_frame_production = false; |
1449 BeginFramesNotFromClient(begin_frame_scheduling_enabled, | 1436 BeginFramesNotFromClient(begin_frame_scheduling_enabled, |
1450 throttle_frame_production); | 1437 throttle_frame_production); |
1451 } | 1438 } |
1452 | 1439 |
1453 void BeginFramesNotFromClient_SwapThrottled(bool begin_frame_scheduling_enabled, | 1440 void BeginFramesNotFromClient_SwapThrottled(bool begin_frame_scheduling_enabled, |
1454 bool throttle_frame_production) { | 1441 bool throttle_frame_production) { |
1455 FakeSchedulerClient client; | 1442 FakeSchedulerClient client; |
1456 SchedulerSettings scheduler_settings; | 1443 SchedulerSettings scheduler_settings; |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1516 // BeginImplFrame deadline should draw. | 1503 // BeginImplFrame deadline should draw. |
1517 scheduler->SetNeedsRedraw(); | 1504 scheduler->SetNeedsRedraw(); |
1518 client.task_runner().RunPendingTasks(); // Run posted deadline. | 1505 client.task_runner().RunPendingTasks(); // Run posted deadline. |
1519 EXPECT_ACTION("ScheduledActionAnimate", client, 0, 2); | 1506 EXPECT_ACTION("ScheduledActionAnimate", client, 0, 2); |
1520 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 1, 2); | 1507 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 1, 2); |
1521 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 1508 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
1522 EXPECT_FALSE(client.needs_begin_frame()); | 1509 EXPECT_FALSE(client.needs_begin_frame()); |
1523 client.Reset(); | 1510 client.Reset(); |
1524 } | 1511 } |
1525 | 1512 |
1526 // See: http://crbug.com/380889 | 1513 TEST(SchedulerTest, SyntheticBeginFrames_SwapThrottled) { |
1527 TEST(SchedulerTest, DISABLED_SyntheticBeginFrames_SwapThrottled) { | |
1528 bool begin_frame_scheduling_enabled = false; | 1514 bool begin_frame_scheduling_enabled = false; |
1529 bool throttle_frame_production = true; | 1515 bool throttle_frame_production = true; |
1530 BeginFramesNotFromClient_SwapThrottled(begin_frame_scheduling_enabled, | 1516 BeginFramesNotFromClient_SwapThrottled(begin_frame_scheduling_enabled, |
1531 throttle_frame_production); | 1517 throttle_frame_production); |
1532 } | 1518 } |
1533 | 1519 |
1534 TEST(SchedulerTest, VSyncThrottlingDisabled_SwapThrottled) { | 1520 TEST(SchedulerTest, VSyncThrottlingDisabled_SwapThrottled) { |
1535 bool begin_frame_scheduling_enabled = true; | 1521 bool begin_frame_scheduling_enabled = true; |
1536 bool throttle_frame_production = false; | 1522 bool throttle_frame_production = false; |
1537 BeginFramesNotFromClient_SwapThrottled(begin_frame_scheduling_enabled, | 1523 BeginFramesNotFromClient_SwapThrottled(begin_frame_scheduling_enabled, |
1538 throttle_frame_production); | 1524 throttle_frame_production); |
1539 } | 1525 } |
1540 | 1526 |
1541 // See: http://crbug.com/380889 | |
1542 TEST(SchedulerTest, | 1527 TEST(SchedulerTest, |
1543 DISABLED_SyntheticBeginFrames_And_VSyncThrottlingDisabled_SwapThrottled) { | 1528 SyntheticBeginFrames_And_VSyncThrottlingDisabled_SwapThrottled) { |
1544 bool begin_frame_scheduling_enabled = false; | 1529 bool begin_frame_scheduling_enabled = false; |
1545 bool throttle_frame_production = false; | 1530 bool throttle_frame_production = false; |
1546 BeginFramesNotFromClient_SwapThrottled(begin_frame_scheduling_enabled, | 1531 BeginFramesNotFromClient_SwapThrottled(begin_frame_scheduling_enabled, |
1547 throttle_frame_production); | 1532 throttle_frame_production); |
1548 } | 1533 } |
1549 | 1534 |
1550 TEST(SchedulerTest, DidLoseOutputSurfaceAfterOutputSurfaceIsInitialized) { | 1535 TEST(SchedulerTest, DidLoseOutputSurfaceAfterOutputSurfaceIsInitialized) { |
1551 FakeSchedulerClient client; | 1536 FakeSchedulerClient client; |
1552 SchedulerSettings scheduler_settings; | 1537 SchedulerSettings scheduler_settings; |
1553 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings); | 1538 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings); |
(...skipping 19 matching lines...) Expand all Loading... |
1573 scheduler->SetCanDraw(true); | 1558 scheduler->SetCanDraw(true); |
1574 | 1559 |
1575 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); | 1560 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); |
1576 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | 1561 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
1577 // SetNeedsCommit should begin the frame. | 1562 // SetNeedsCommit should begin the frame. |
1578 client.Reset(); | 1563 client.Reset(); |
1579 scheduler->SetNeedsCommit(); | 1564 scheduler->SetNeedsCommit(); |
1580 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); | 1565 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); |
1581 | 1566 |
1582 client.Reset(); | 1567 client.Reset(); |
1583 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | 1568 client.AdvanceFrame(); |
1584 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 1569 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
1585 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); | 1570 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); |
1586 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1571 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
1587 | 1572 |
1588 client.Reset(); | 1573 client.Reset(); |
1589 scheduler->DidLoseOutputSurface(); | 1574 scheduler->DidLoseOutputSurface(); |
1590 // Do nothing when impl frame is in deadine pending state. | 1575 // Do nothing when impl frame is in deadine pending state. |
1591 EXPECT_NO_ACTION(client); | 1576 EXPECT_NO_ACTION(client); |
1592 | 1577 |
1593 client.Reset(); | 1578 client.Reset(); |
(...skipping 18 matching lines...) Expand all Loading... |
1612 | 1597 |
1613 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); | 1598 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); |
1614 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | 1599 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
1615 | 1600 |
1616 // SetNeedsCommit should begin the frame. | 1601 // SetNeedsCommit should begin the frame. |
1617 client.Reset(); | 1602 client.Reset(); |
1618 scheduler->SetNeedsCommit(); | 1603 scheduler->SetNeedsCommit(); |
1619 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); | 1604 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); |
1620 | 1605 |
1621 client.Reset(); | 1606 client.Reset(); |
1622 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | 1607 client.AdvanceFrame(); |
1623 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 1608 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
1624 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); | 1609 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); |
1625 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1610 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
1626 | 1611 |
1627 client.Reset(); | 1612 client.Reset(); |
1628 scheduler->DidLoseOutputSurface(); | 1613 scheduler->DidLoseOutputSurface(); |
1629 // Do nothing when impl frame is in deadine pending state. | 1614 // Do nothing when impl frame is in deadine pending state. |
1630 EXPECT_NO_ACTION(client); | 1615 EXPECT_NO_ACTION(client); |
1631 | 1616 |
1632 client.Reset(); | 1617 client.Reset(); |
1633 client.task_runner().RunPendingTasks(); // Run posted deadline. | 1618 // Run posted deadline. |
| 1619 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 1620 client.task_runner().RunTasksWhile(client.ImplFrameDeadlinePending(true)); |
1634 // OnBeginImplFrameDeadline didn't schedule any actions because main frame is | 1621 // OnBeginImplFrameDeadline didn't schedule any actions because main frame is |
1635 // not yet completed. | 1622 // not yet completed. |
1636 EXPECT_NO_ACTION(client); | 1623 EXPECT_NO_ACTION(client); |
| 1624 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
1637 | 1625 |
1638 // BeginImplFrame is not started. | 1626 // BeginImplFrame is not started. |
1639 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | 1627 client.task_runner().RunUntilTime(client.now_src()->Now() + |
| 1628 base::TimeDelta::FromMilliseconds(10)); |
1640 EXPECT_NO_ACTION(client); | 1629 EXPECT_NO_ACTION(client); |
1641 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 1630 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
1642 | 1631 |
1643 client.Reset(); | 1632 client.Reset(); |
1644 scheduler->NotifyBeginMainFrameStarted(); | 1633 scheduler->NotifyBeginMainFrameStarted(); |
1645 scheduler->NotifyReadyToCommit(); | 1634 scheduler->NotifyReadyToCommit(); |
1646 if (impl_side_painting) { | 1635 if (impl_side_painting) { |
1647 EXPECT_ACTION("ScheduledActionCommit", client, 0, 3); | 1636 EXPECT_ACTION("ScheduledActionCommit", client, 0, 3); |
1648 EXPECT_ACTION("ScheduledActionActivateSyncTree", client, 1, 3); | 1637 EXPECT_ACTION("ScheduledActionActivateSyncTree", client, 1, 3); |
1649 EXPECT_ACTION("ScheduledActionBeginOutputSurfaceCreation", client, 2, 3); | 1638 EXPECT_ACTION("ScheduledActionBeginOutputSurfaceCreation", client, 2, 3); |
(...skipping 25 matching lines...) Expand all Loading... |
1675 | 1664 |
1676 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); | 1665 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); |
1677 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | 1666 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
1678 | 1667 |
1679 // SetNeedsCommit should begin the frame. | 1668 // SetNeedsCommit should begin the frame. |
1680 client.Reset(); | 1669 client.Reset(); |
1681 scheduler->SetNeedsCommit(); | 1670 scheduler->SetNeedsCommit(); |
1682 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); | 1671 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); |
1683 | 1672 |
1684 client.Reset(); | 1673 client.Reset(); |
1685 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | 1674 client.AdvanceFrame(); |
1686 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 1675 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
1687 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); | 1676 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); |
1688 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1677 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
1689 | 1678 |
1690 client.Reset(); | 1679 client.Reset(); |
1691 scheduler->NotifyBeginMainFrameStarted(); | 1680 scheduler->NotifyBeginMainFrameStarted(); |
1692 scheduler->NotifyReadyToCommit(); | 1681 scheduler->NotifyReadyToCommit(); |
1693 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); | 1682 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); |
1694 | 1683 |
1695 client.Reset(); | 1684 client.Reset(); |
(...skipping 28 matching lines...) Expand all Loading... |
1724 scheduler->SetCanDraw(true); | 1713 scheduler->SetCanDraw(true); |
1725 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | 1714 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
1726 | 1715 |
1727 client.Reset(); | 1716 client.Reset(); |
1728 scheduler->SetNeedsManageTiles(); | 1717 scheduler->SetNeedsManageTiles(); |
1729 scheduler->SetNeedsRedraw(); | 1718 scheduler->SetNeedsRedraw(); |
1730 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); | 1719 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); |
1731 EXPECT_TRUE(client.needs_begin_frame()); | 1720 EXPECT_TRUE(client.needs_begin_frame()); |
1732 | 1721 |
1733 client.Reset(); | 1722 client.Reset(); |
1734 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | 1723 client.AdvanceFrame(); |
1735 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 1724 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
1736 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); | 1725 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); |
1737 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1726 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
1738 | 1727 |
1739 client.Reset(); | 1728 client.Reset(); |
1740 scheduler->DidLoseOutputSurface(); | 1729 scheduler->DidLoseOutputSurface(); |
1741 EXPECT_NO_ACTION(client); | 1730 EXPECT_NO_ACTION(client); |
1742 | 1731 |
1743 client.Reset(); | 1732 client.Reset(); |
1744 client.task_runner().RunPendingTasks(); // Run posted deadline. | 1733 client.task_runner().RunPendingTasks(); // Run posted deadline. |
(...skipping 12 matching lines...) Expand all Loading... |
1757 | 1746 |
1758 // SetNeedsCommit should begin the frame on the next BeginImplFrame. | 1747 // SetNeedsCommit should begin the frame on the next BeginImplFrame. |
1759 client.Reset(); | 1748 client.Reset(); |
1760 scheduler->SetNeedsCommit(); | 1749 scheduler->SetNeedsCommit(); |
1761 EXPECT_TRUE(client.needs_begin_frame()); | 1750 EXPECT_TRUE(client.needs_begin_frame()); |
1762 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); | 1751 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); |
1763 | 1752 |
1764 // Create a BeginFrame with a long deadline to avoid race conditions. | 1753 // Create a BeginFrame with a long deadline to avoid race conditions. |
1765 // This is the first BeginFrame, which will be handled immediately. | 1754 // This is the first BeginFrame, which will be handled immediately. |
1766 client.Reset(); | 1755 client.Reset(); |
1767 BeginFrameArgs args = CreateBeginFrameArgsForTesting(); | 1756 BeginFrameArgs args = CreateBeginFrameArgsForTesting(client.now_src()); |
1768 args.deadline += base::TimeDelta::FromHours(1); | 1757 args.deadline += base::TimeDelta::FromHours(1); |
1769 scheduler->BeginFrame(args); | 1758 scheduler->BeginFrame(args); |
1770 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 1759 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
1771 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); | 1760 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); |
1772 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1761 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
1773 EXPECT_TRUE(client.needs_begin_frame()); | 1762 EXPECT_TRUE(client.needs_begin_frame()); |
1774 | 1763 |
1775 // Queue BeginFrames while we are still handling the previous BeginFrame. | 1764 // Queue BeginFrames while we are still handling the previous BeginFrame. |
1776 args.frame_time += base::TimeDelta::FromSeconds(1); | 1765 args.frame_time += base::TimeDelta::FromSeconds(1); |
1777 scheduler->BeginFrame(args); | 1766 scheduler->BeginFrame(args); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1816 | 1805 |
1817 // SetNeedsCommit should begin the frame on the next BeginImplFrame. | 1806 // SetNeedsCommit should begin the frame on the next BeginImplFrame. |
1818 client.Reset(); | 1807 client.Reset(); |
1819 scheduler->SetNeedsCommit(); | 1808 scheduler->SetNeedsCommit(); |
1820 EXPECT_TRUE(client.needs_begin_frame()); | 1809 EXPECT_TRUE(client.needs_begin_frame()); |
1821 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); | 1810 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); |
1822 | 1811 |
1823 // Create a BeginFrame with a long deadline to avoid race conditions. | 1812 // Create a BeginFrame with a long deadline to avoid race conditions. |
1824 // This is the first BeginFrame, which will be handled immediately. | 1813 // This is the first BeginFrame, which will be handled immediately. |
1825 client.Reset(); | 1814 client.Reset(); |
1826 BeginFrameArgs args = CreateBeginFrameArgsForTesting(); | 1815 BeginFrameArgs args = CreateBeginFrameArgsForTesting(client.now_src()); |
1827 args.deadline += base::TimeDelta::FromHours(1); | 1816 args.deadline += base::TimeDelta::FromHours(1); |
1828 scheduler->BeginFrame(args); | 1817 scheduler->BeginFrame(args); |
1829 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 1818 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
1830 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); | 1819 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); |
1831 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1820 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
1832 EXPECT_TRUE(client.needs_begin_frame()); | 1821 EXPECT_TRUE(client.needs_begin_frame()); |
1833 | 1822 |
1834 // Queue BeginFrames while we are still handling the previous BeginFrame. | 1823 // Queue BeginFrames while we are still handling the previous BeginFrame. |
1835 args.frame_time += base::TimeDelta::FromSeconds(1); | 1824 args.frame_time += base::TimeDelta::FromSeconds(1); |
1836 scheduler->BeginFrame(args); | 1825 scheduler->BeginFrame(args); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1871 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); | 1860 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); |
1872 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 1861 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
1873 EXPECT_TRUE(client.needs_begin_frame()); | 1862 EXPECT_TRUE(client.needs_begin_frame()); |
1874 | 1863 |
1875 // No more BeginRetroFrame because BeginRetroFrame queue is cleared. | 1864 // No more BeginRetroFrame because BeginRetroFrame queue is cleared. |
1876 client.Reset(); | 1865 client.Reset(); |
1877 client.task_runner().RunPendingTasks(); | 1866 client.task_runner().RunPendingTasks(); |
1878 EXPECT_NO_ACTION(client); | 1867 EXPECT_NO_ACTION(client); |
1879 } | 1868 } |
1880 | 1869 |
1881 // See: http://crbug.com/380889 | 1870 TEST(SchedulerTest, |
1882 TEST( | 1871 StopBeginFrameAfterDidLoseOutputSurfaceWithSyntheticBeginFrameSource) { |
1883 SchedulerTest, | |
1884 DISABLED_StopBeginFrameAfterDidLoseOutputSurfaceWithSyntheticBeginFrameSourc
e) { | |
1885 FakeSchedulerClient client; | 1872 FakeSchedulerClient client; |
1886 SchedulerSettings scheduler_settings; | 1873 SchedulerSettings scheduler_settings; |
1887 scheduler_settings.begin_frame_scheduling_enabled = false; | 1874 scheduler_settings.begin_frame_scheduling_enabled = false; |
1888 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings); | 1875 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings); |
1889 scheduler->SetCanStart(); | 1876 scheduler->SetCanStart(); |
1890 scheduler->SetVisible(true); | 1877 scheduler->SetVisible(true); |
1891 scheduler->SetCanDraw(true); | 1878 scheduler->SetCanDraw(true); |
1892 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | 1879 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
1893 | 1880 |
1894 // SetNeedsCommit should begin the frame on the next BeginImplFrame. | 1881 // SetNeedsCommit should begin the frame on the next BeginImplFrame. |
(...skipping 22 matching lines...) Expand all Loading... |
1917 EXPECT_FALSE(scheduler->IsSyntheticBeginFrameSourceActive()); | 1904 EXPECT_FALSE(scheduler->IsSyntheticBeginFrameSourceActive()); |
1918 | 1905 |
1919 client.Reset(); | 1906 client.Reset(); |
1920 client.task_runner().RunPendingTasks(); // Run posted deadline. | 1907 client.task_runner().RunPendingTasks(); // Run posted deadline. |
1921 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); | 1908 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); |
1922 EXPECT_FALSE(scheduler->IsSyntheticBeginFrameSourceActive()); | 1909 EXPECT_FALSE(scheduler->IsSyntheticBeginFrameSourceActive()); |
1923 } | 1910 } |
1924 | 1911 |
1925 } // namespace | 1912 } // namespace |
1926 } // namespace cc | 1913 } // namespace cc |
OLD | NEW |