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 20 matching lines...) Expand all Loading... | |
31 } while (false) | 31 } while (false) |
32 | 32 |
33 #define EXPECT_NO_ACTION(client) EXPECT_ACTION("", client, -1, 0) | 33 #define EXPECT_NO_ACTION(client) EXPECT_ACTION("", client, -1, 0) |
34 | 34 |
35 #define EXPECT_SINGLE_ACTION(action, client) \ | 35 #define EXPECT_SINGLE_ACTION(action, client) \ |
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 RunWhileImplFrameDeadlinePending | |
42 : public OrderedSimpleTaskRunner::RunCheck { | |
43 public: | |
44 explicit RunWhileImplFrameDeadlinePending(Scheduler* scheduler, bool state) | |
45 : scheduler_(scheduler), state_(state) {} | |
46 | |
47 virtual bool Check() OVERRIDE { | |
48 return scheduler_->BeginImplFrameDeadlinePending() != state_; | |
49 } | |
50 | |
51 private: | |
52 Scheduler* scheduler_; | |
53 bool state_; | |
54 }; | |
55 | |
41 class FakeSchedulerClient; | 56 class FakeSchedulerClient; |
42 | 57 |
43 void InitializeOutputSurfaceAndFirstCommit(Scheduler* scheduler, | 58 void InitializeOutputSurfaceAndFirstCommit(Scheduler* scheduler, |
44 FakeSchedulerClient* client); | 59 FakeSchedulerClient* client); |
45 | 60 |
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 { | 61 class FakeSchedulerClient : public SchedulerClient { |
81 public: | 62 public: |
82 FakeSchedulerClient() | 63 FakeSchedulerClient() |
83 : needs_begin_frame_(false), | 64 : needs_begin_frame_(false), |
84 automatic_swap_ack_(true), | 65 automatic_swap_ack_(true), |
85 swap_contains_incomplete_tile_(false), | 66 swap_contains_incomplete_tile_(false), |
86 redraw_will_happen_if_update_visible_tiles_happens_(false) { | 67 redraw_will_happen_if_update_visible_tiles_happens_(false), |
68 now_src_(TestNowSource::Create()) { | |
87 Reset(); | 69 Reset(); |
88 } | 70 } |
89 | 71 |
90 void Reset() { | 72 void Reset() { |
91 actions_.clear(); | 73 actions_.clear(); |
92 states_.clear(); | 74 states_.clear(); |
93 draw_will_happen_ = true; | 75 draw_will_happen_ = true; |
94 swap_will_happen_if_draw_happens_ = true; | 76 swap_will_happen_if_draw_happens_ = true; |
95 num_draws_ = 0; | 77 num_draws_ = 0; |
96 log_anticipated_draw_time_change_ = false; | 78 log_anticipated_draw_time_change_ = false; |
97 } | 79 } |
98 | 80 |
99 TestScheduler* CreateScheduler(const SchedulerSettings& settings) { | 81 TestScheduler* CreateScheduler(const SchedulerSettings& settings) { |
100 task_runner_ = new OrderedSimpleTaskRunner; | 82 scheduler_ = TestScheduler::Create(now_src_, this, settings, 0); |
101 scheduler_ = TestScheduler::Create(this, settings, 0, task_runner_); | 83 // Fail if we need to run 100 tasks in a row. |
84 task_runner().SetTimeout(100); | |
Sami
2014/08/29 13:13:51
Please call this something that makes it clear 100
mithro-old
2014/09/01 06:19:46
Done.
I went with "SetRunTaskLimit".
| |
102 return scheduler_.get(); | 85 return scheduler_.get(); |
103 } | 86 } |
104 | 87 |
105 // Most tests don't care about DidAnticipatedDrawTimeChange, so only record it | 88 // Most tests don't care about DidAnticipatedDrawTimeChange, so only record it |
106 // for tests that do. | 89 // for tests that do. |
107 void set_log_anticipated_draw_time_change(bool log) { | 90 void set_log_anticipated_draw_time_change(bool log) { |
108 log_anticipated_draw_time_change_ = log; | 91 log_anticipated_draw_time_change_ = log; |
109 } | 92 } |
110 bool needs_begin_frame() { return needs_begin_frame_; } | 93 bool needs_begin_frame() { return needs_begin_frame_; } |
111 int num_draws() const { return num_draws_; } | 94 int num_draws() const { return num_draws_; } |
112 int num_actions_() const { return static_cast<int>(actions_.size()); } | 95 int num_actions_() const { return static_cast<int>(actions_.size()); } |
113 const char* Action(int i) const { return actions_[i]; } | 96 const char* Action(int i) const { return actions_[i]; } |
114 std::string StateForAction(int i) const { return states_[i]->ToString(); } | 97 std::string StateForAction(int i) const { return states_[i]->ToString(); } |
115 base::TimeTicks posted_begin_impl_frame_deadline() const { | 98 base::TimeTicks posted_begin_impl_frame_deadline() const { |
116 return posted_begin_impl_frame_deadline_; | 99 return posted_begin_impl_frame_deadline_; |
117 } | 100 } |
118 | 101 |
119 OrderedSimpleTaskRunner& task_runner() { return *task_runner_.get(); } | 102 void AdvanceFrame() { |
103 bool external_begin_frame = | |
104 scheduler_->settings().begin_frame_scheduling_enabled && | |
105 scheduler_->settings().throttle_frame_production; | |
106 | |
107 if (external_begin_frame) { | |
108 TRACE_EVENT1("cc", | |
109 "SchedulerUnitTest::AdvanceFrame", | |
110 "external_begin_frame", | |
111 external_begin_frame); | |
Sami
2014/08/29 13:13:51
Having |external_begin_frame| here is redundant be
mithro-old
2014/09/01 06:19:46
Removed.
This trace only existed to make the inde
| |
112 scheduler_->BeginFrame(CreateBeginFrameArgsForTesting(now_src_)); | |
113 } | |
114 | |
115 EXPECT_TRUE(task_runner().RunTasksUntil( | |
116 RunWhileImplFrameDeadlinePending(scheduler_.get(), true))); | |
117 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | |
118 } | |
119 | |
120 OrderedSimpleTaskRunner& task_runner() { return scheduler_->task_runner(); } | |
121 scoped_refptr<TestNowSource> now_src() { return now_src_; } | |
Sami
2014/08/29 13:13:51
Could this be a raw pointer? Nobody needs to hang
mithro-old
2014/09/01 06:19:46
Done.
| |
120 | 122 |
121 int ActionIndex(const char* action) const { | 123 int ActionIndex(const char* action) const { |
122 for (size_t i = 0; i < actions_.size(); i++) | 124 for (size_t i = 0; i < actions_.size(); i++) |
123 if (!strcmp(actions_[i], action)) | 125 if (!strcmp(actions_[i], action)) |
124 return i; | 126 return i; |
125 return -1; | 127 return -1; |
126 } | 128 } |
127 | 129 |
128 void SetSwapContainsIncompleteTile(bool contain) { | 130 void SetSwapContainsIncompleteTile(bool contain) { |
129 swap_contains_incomplete_tile_ = contain; | 131 swap_contains_incomplete_tile_ = contain; |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
234 bool swap_will_happen_if_draw_happens_; | 236 bool swap_will_happen_if_draw_happens_; |
235 bool automatic_swap_ack_; | 237 bool automatic_swap_ack_; |
236 int num_draws_; | 238 int num_draws_; |
237 bool log_anticipated_draw_time_change_; | 239 bool log_anticipated_draw_time_change_; |
238 bool swap_contains_incomplete_tile_; | 240 bool swap_contains_incomplete_tile_; |
239 bool redraw_will_happen_if_update_visible_tiles_happens_; | 241 bool redraw_will_happen_if_update_visible_tiles_happens_; |
240 base::TimeTicks posted_begin_impl_frame_deadline_; | 242 base::TimeTicks posted_begin_impl_frame_deadline_; |
241 std::vector<const char*> actions_; | 243 std::vector<const char*> actions_; |
242 std::vector<scoped_refptr<base::debug::ConvertableToTraceFormat> > states_; | 244 std::vector<scoped_refptr<base::debug::ConvertableToTraceFormat> > states_; |
243 scoped_ptr<TestScheduler> scheduler_; | 245 scoped_ptr<TestScheduler> scheduler_; |
244 scoped_refptr<OrderedSimpleTaskRunner> task_runner_; | 246 scoped_refptr<TestNowSource> now_src_; |
Sami
2014/08/29 13:13:51
scoped_ptr?
mithro-old
2014/09/01 06:19:46
now_src is currently ref-counted. The fact that th
Sami
2014/09/01 11:35:32
Right, I was just wondering if the the scheduler's
| |
245 }; | 247 }; |
246 | 248 |
247 void InitializeOutputSurfaceAndFirstCommit(Scheduler* scheduler, | 249 void InitializeOutputSurfaceAndFirstCommit(Scheduler* scheduler, |
248 FakeSchedulerClient* client) { | 250 FakeSchedulerClient* client) { |
249 bool client_initiates_begin_frame = | 251 TRACE_EVENT0("cc", |
250 scheduler->settings().begin_frame_scheduling_enabled && | 252 "SchedulerUnitTest::InitializeOutputSurfaceAndFirstCommit"); |
251 scheduler->settings().throttle_frame_production; | |
252 | 253 |
253 scheduler->DidCreateAndInitializeOutputSurface(); | 254 scheduler->DidCreateAndInitializeOutputSurface(); |
254 scheduler->SetNeedsCommit(); | 255 scheduler->SetNeedsCommit(); |
255 scheduler->NotifyBeginMainFrameStarted(); | 256 scheduler->NotifyBeginMainFrameStarted(); |
256 scheduler->NotifyReadyToCommit(); | 257 scheduler->NotifyReadyToCommit(); |
257 if (scheduler->settings().impl_side_painting) | 258 if (scheduler->settings().impl_side_painting) |
258 scheduler->NotifyReadyToActivate(); | 259 scheduler->NotifyReadyToActivate(); |
260 | |
259 // Go through the motions to draw the commit. | 261 // Go through the motions to draw the commit. |
260 if (client_initiates_begin_frame) | 262 client->AdvanceFrame(); |
261 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | |
262 else | |
263 client->task_runner().RunPendingTasks(); // Run posted BeginFrame. | |
264 | 263 |
265 // Run the posted deadline task. | 264 // Run the posted deadline task. |
266 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 265 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
267 client->task_runner().RunPendingTasks(); | 266 client->task_runner().RunTasksUntil( |
Sami
2014/08/29 13:13:51
This reads a bit oddly -- "Run tasks until while i
mithro-old
2014/09/01 06:19:46
With the other changes this now reads as;
RunTask
| |
267 RunWhileImplFrameDeadlinePending(scheduler, false)); | |
268 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 268 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
269 | 269 |
270 // We need another BeginImplFrame so Scheduler calls | 270 // We need another BeginImplFrame so Scheduler calls |
271 // SetNeedsBeginFrame(false). | 271 // SetNeedsBeginFrame(false). |
272 if (client_initiates_begin_frame) | 272 client->AdvanceFrame(); |
273 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | |
274 else | |
275 client->task_runner().RunPendingTasks(); // Run posted BeginFrame. | |
276 | 273 |
277 // Run the posted deadline task. | 274 // Run the posted deadline task. |
278 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 275 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
279 client->task_runner().RunPendingTasks(); | 276 client->task_runner().RunTasksUntil( |
277 RunWhileImplFrameDeadlinePending(scheduler, false)); | |
280 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 278 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
281 } | 279 } |
282 | 280 |
283 TEST(SchedulerTest, InitializeOutputSurfaceDoesNotBeginImplFrame) { | 281 TEST(SchedulerTest, InitializeOutputSurfaceDoesNotBeginImplFrame) { |
284 FakeSchedulerClient client; | 282 FakeSchedulerClient client; |
285 SchedulerSettings default_scheduler_settings; | 283 SchedulerSettings default_scheduler_settings; |
286 TestScheduler* scheduler = client.CreateScheduler(default_scheduler_settings); | 284 TestScheduler* scheduler = client.CreateScheduler(default_scheduler_settings); |
287 scheduler->SetCanStart(); | 285 scheduler->SetCanStart(); |
288 scheduler->SetVisible(true); | 286 scheduler->SetVisible(true); |
289 scheduler->SetCanDraw(true); | 287 scheduler->SetCanDraw(true); |
(...skipping 15 matching lines...) Expand all Loading... | |
305 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); | 303 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); |
306 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | 304 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
307 | 305 |
308 // SetNeedsCommit should begin the frame on the next BeginImplFrame. | 306 // SetNeedsCommit should begin the frame on the next BeginImplFrame. |
309 client.Reset(); | 307 client.Reset(); |
310 scheduler->SetNeedsCommit(); | 308 scheduler->SetNeedsCommit(); |
311 EXPECT_TRUE(client.needs_begin_frame()); | 309 EXPECT_TRUE(client.needs_begin_frame()); |
312 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); | 310 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); |
313 client.Reset(); | 311 client.Reset(); |
314 | 312 |
315 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | 313 client.AdvanceFrame(); |
316 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 314 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
317 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); | 315 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); |
318 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 316 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
319 EXPECT_TRUE(client.needs_begin_frame()); | 317 EXPECT_TRUE(client.needs_begin_frame()); |
320 client.Reset(); | 318 client.Reset(); |
321 | 319 |
322 // If we don't swap on the deadline, we wait for the next BeginFrame. | 320 // If we don't swap on the deadline, we wait for the next BeginFrame. |
323 client.task_runner().RunPendingTasks(); // Run posted deadline. | 321 client.task_runner().RunPendingTasks(); // Run posted deadline. |
324 EXPECT_NO_ACTION(client); | 322 EXPECT_NO_ACTION(client); |
325 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 323 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
326 EXPECT_TRUE(client.needs_begin_frame()); | 324 EXPECT_TRUE(client.needs_begin_frame()); |
327 client.Reset(); | 325 client.Reset(); |
328 | 326 |
329 // NotifyReadyToCommit should trigger the commit. | 327 // NotifyReadyToCommit should trigger the commit. |
330 scheduler->NotifyBeginMainFrameStarted(); | 328 scheduler->NotifyBeginMainFrameStarted(); |
331 scheduler->NotifyReadyToCommit(); | 329 scheduler->NotifyReadyToCommit(); |
332 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); | 330 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); |
333 EXPECT_TRUE(client.needs_begin_frame()); | 331 EXPECT_TRUE(client.needs_begin_frame()); |
334 client.Reset(); | 332 client.Reset(); |
335 | 333 |
336 // BeginImplFrame should prepare the draw. | 334 // BeginImplFrame should prepare the draw. |
337 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | 335 client.AdvanceFrame(); |
338 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 336 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
339 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); | 337 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); |
340 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 338 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
341 EXPECT_TRUE(client.needs_begin_frame()); | 339 EXPECT_TRUE(client.needs_begin_frame()); |
342 client.Reset(); | 340 client.Reset(); |
343 | 341 |
344 // BeginImplFrame deadline should draw. | 342 // BeginImplFrame deadline should draw. |
345 client.task_runner().RunPendingTasks(); // Run posted deadline. | 343 client.task_runner().RunPendingTasks(); // Run posted deadline. |
346 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 1); | 344 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 1); |
347 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 345 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
348 EXPECT_TRUE(client.needs_begin_frame()); | 346 EXPECT_TRUE(client.needs_begin_frame()); |
349 client.Reset(); | 347 client.Reset(); |
350 | 348 |
351 // The following BeginImplFrame deadline should SetNeedsBeginFrame(false) | 349 // The following BeginImplFrame deadline should SetNeedsBeginFrame(false) |
352 // to avoid excessive toggles. | 350 // to avoid excessive toggles. |
353 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | 351 client.AdvanceFrame(); |
354 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); | 352 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); |
355 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 353 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
356 client.Reset(); | 354 client.Reset(); |
357 | 355 |
358 client.task_runner().RunPendingTasks(); // Run posted deadline. | 356 client.task_runner().RunPendingTasks(); // Run posted deadline. |
359 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); | 357 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); |
360 EXPECT_FALSE(client.needs_begin_frame()); | 358 EXPECT_FALSE(client.needs_begin_frame()); |
361 client.Reset(); | 359 client.Reset(); |
362 } | 360 } |
363 | 361 |
364 TEST(SchedulerTest, RequestCommitAfterBeginMainFrameSent) { | 362 TEST(SchedulerTest, RequestCommitAfterBeginMainFrameSent) { |
365 FakeSchedulerClient client; | 363 FakeSchedulerClient client; |
366 SchedulerSettings scheduler_settings; | 364 SchedulerSettings scheduler_settings; |
367 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings); | 365 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings); |
368 scheduler->SetCanStart(); | 366 scheduler->SetCanStart(); |
369 scheduler->SetVisible(true); | 367 scheduler->SetVisible(true); |
370 scheduler->SetCanDraw(true); | 368 scheduler->SetCanDraw(true); |
371 | 369 |
372 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); | 370 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); |
373 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | 371 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
374 client.Reset(); | 372 client.Reset(); |
375 | 373 |
376 // SetNeedsCommit should begin the frame. | 374 // SetNeedsCommit should begin the frame. |
377 scheduler->SetNeedsCommit(); | 375 scheduler->SetNeedsCommit(); |
378 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); | 376 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); |
379 | 377 |
380 client.Reset(); | 378 client.Reset(); |
381 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | 379 client.AdvanceFrame(); |
382 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 380 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
383 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); | 381 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); |
384 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 382 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
385 | 383 |
386 EXPECT_TRUE(client.needs_begin_frame()); | 384 EXPECT_TRUE(client.needs_begin_frame()); |
387 client.Reset(); | 385 client.Reset(); |
388 | 386 |
389 // Now SetNeedsCommit again. Calling here means we need a second commit. | 387 // Now SetNeedsCommit again. Calling here means we need a second commit. |
390 scheduler->SetNeedsCommit(); | 388 scheduler->SetNeedsCommit(); |
391 EXPECT_EQ(client.num_actions_(), 0); | 389 EXPECT_EQ(client.num_actions_(), 0); |
392 client.Reset(); | 390 client.Reset(); |
393 | 391 |
394 // Finish the first commit. | 392 // Finish the first commit. |
395 scheduler->NotifyBeginMainFrameStarted(); | 393 scheduler->NotifyBeginMainFrameStarted(); |
396 scheduler->NotifyReadyToCommit(); | 394 scheduler->NotifyReadyToCommit(); |
397 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); | 395 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); |
398 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 396 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
399 client.Reset(); | 397 client.Reset(); |
400 client.task_runner().RunPendingTasks(); // Run posted deadline. | 398 client.task_runner().RunPendingTasks(); // Run posted deadline. |
401 EXPECT_ACTION("ScheduledActionAnimate", client, 0, 2); | 399 EXPECT_ACTION("ScheduledActionAnimate", client, 0, 2); |
402 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 1, 2); | 400 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 1, 2); |
403 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 401 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
404 | 402 |
405 // Because we just swapped, the Scheduler should also request the next | 403 // Because we just swapped, the Scheduler should also request the next |
406 // BeginImplFrame from the OutputSurface. | 404 // BeginImplFrame from the OutputSurface. |
407 EXPECT_TRUE(client.needs_begin_frame()); | 405 EXPECT_TRUE(client.needs_begin_frame()); |
408 client.Reset(); | 406 client.Reset(); |
409 // Since another commit is needed, the next BeginImplFrame should initiate | 407 // Since another commit is needed, the next BeginImplFrame should initiate |
410 // the second commit. | 408 // the second commit. |
411 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | 409 client.AdvanceFrame(); |
412 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 410 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
413 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); | 411 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); |
414 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 412 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
415 client.Reset(); | 413 client.Reset(); |
416 | 414 |
417 // Finishing the commit before the deadline should post a new deadline task | 415 // Finishing the commit before the deadline should post a new deadline task |
418 // to trigger the deadline early. | 416 // to trigger the deadline early. |
419 scheduler->NotifyBeginMainFrameStarted(); | 417 scheduler->NotifyBeginMainFrameStarted(); |
420 scheduler->NotifyReadyToCommit(); | 418 scheduler->NotifyReadyToCommit(); |
421 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); | 419 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); |
422 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 420 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
423 client.Reset(); | 421 client.Reset(); |
424 client.task_runner().RunPendingTasks(); // Run posted deadline. | 422 client.task_runner().RunPendingTasks(); // Run posted deadline. |
425 EXPECT_ACTION("ScheduledActionAnimate", client, 0, 2); | 423 EXPECT_ACTION("ScheduledActionAnimate", client, 0, 2); |
426 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 1, 2); | 424 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 1, 2); |
427 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 425 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
428 EXPECT_TRUE(client.needs_begin_frame()); | 426 EXPECT_TRUE(client.needs_begin_frame()); |
429 client.Reset(); | 427 client.Reset(); |
430 | 428 |
431 // On the next BeginImplFrame, verify we go back to a quiescent state and | 429 // On the next BeginImplFrame, verify we go back to a quiescent state and |
432 // no longer request BeginImplFrames. | 430 // no longer request BeginImplFrames. |
433 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | 431 client.AdvanceFrame(); |
434 client.task_runner().RunPendingTasks(); // Run posted deadline. | 432 client.task_runner().RunPendingTasks(); // Run posted deadline. |
435 EXPECT_FALSE(client.needs_begin_frame()); | 433 EXPECT_FALSE(client.needs_begin_frame()); |
436 client.Reset(); | 434 client.Reset(); |
437 } | 435 } |
438 | 436 |
439 class SchedulerClientThatsetNeedsDrawInsideDraw : public FakeSchedulerClient { | 437 class SchedulerClientThatsetNeedsDrawInsideDraw : public FakeSchedulerClient { |
440 public: | 438 public: |
441 virtual void ScheduledActionSendBeginMainFrame() OVERRIDE {} | 439 virtual void ScheduledActionSendBeginMainFrame() OVERRIDE {} |
442 virtual DrawResult ScheduledActionDrawAndSwapIfPossible() | 440 virtual DrawResult ScheduledActionDrawAndSwapIfPossible() |
443 OVERRIDE { | 441 OVERRIDE { |
(...skipping 25 matching lines...) Expand all Loading... | |
469 scheduler->SetVisible(true); | 467 scheduler->SetVisible(true); |
470 scheduler->SetCanDraw(true); | 468 scheduler->SetCanDraw(true); |
471 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | 469 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
472 client.Reset(); | 470 client.Reset(); |
473 | 471 |
474 scheduler->SetNeedsRedraw(); | 472 scheduler->SetNeedsRedraw(); |
475 EXPECT_TRUE(scheduler->RedrawPending()); | 473 EXPECT_TRUE(scheduler->RedrawPending()); |
476 EXPECT_TRUE(client.needs_begin_frame()); | 474 EXPECT_TRUE(client.needs_begin_frame()); |
477 EXPECT_EQ(0, client.num_draws()); | 475 EXPECT_EQ(0, client.num_draws()); |
478 | 476 |
479 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | 477 client.AdvanceFrame(); |
480 client.task_runner().RunPendingTasks(); // Run posted deadline. | 478 client.task_runner().RunPendingTasks(); // Run posted deadline. |
481 EXPECT_EQ(1, client.num_draws()); | 479 EXPECT_EQ(1, client.num_draws()); |
482 EXPECT_TRUE(scheduler->RedrawPending()); | 480 EXPECT_TRUE(scheduler->RedrawPending()); |
483 EXPECT_TRUE(client.needs_begin_frame()); | 481 EXPECT_TRUE(client.needs_begin_frame()); |
484 | 482 |
485 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | 483 client.AdvanceFrame(); |
486 client.task_runner().RunPendingTasks(); // Run posted deadline. | 484 client.task_runner().RunPendingTasks(); // Run posted deadline. |
487 EXPECT_EQ(2, client.num_draws()); | 485 EXPECT_EQ(2, client.num_draws()); |
488 EXPECT_FALSE(scheduler->RedrawPending()); | 486 EXPECT_FALSE(scheduler->RedrawPending()); |
489 EXPECT_TRUE(client.needs_begin_frame()); | 487 EXPECT_TRUE(client.needs_begin_frame()); |
490 | 488 |
491 // We stop requesting BeginImplFrames after a BeginImplFrame where we don't | 489 // We stop requesting BeginImplFrames after a BeginImplFrame where we don't |
492 // swap. | 490 // swap. |
493 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | 491 client.AdvanceFrame(); |
494 client.task_runner().RunPendingTasks(); // Run posted deadline. | 492 client.task_runner().RunPendingTasks(); // Run posted deadline. |
495 EXPECT_EQ(2, client.num_draws()); | 493 EXPECT_EQ(2, client.num_draws()); |
496 EXPECT_FALSE(scheduler->RedrawPending()); | 494 EXPECT_FALSE(scheduler->RedrawPending()); |
497 EXPECT_FALSE(client.needs_begin_frame()); | 495 EXPECT_FALSE(client.needs_begin_frame()); |
498 } | 496 } |
499 | 497 |
500 // Test that requesting redraw inside a failed draw doesn't lose the request. | 498 // Test that requesting redraw inside a failed draw doesn't lose the request. |
501 TEST(SchedulerTest, RequestRedrawInsideFailedDraw) { | 499 TEST(SchedulerTest, RequestRedrawInsideFailedDraw) { |
502 SchedulerClientThatsetNeedsDrawInsideDraw client; | 500 SchedulerClientThatsetNeedsDrawInsideDraw client; |
503 SchedulerSettings default_scheduler_settings; | 501 SchedulerSettings default_scheduler_settings; |
504 TestScheduler* scheduler = client.CreateScheduler(default_scheduler_settings); | 502 TestScheduler* scheduler = client.CreateScheduler(default_scheduler_settings); |
505 scheduler->SetCanStart(); | 503 scheduler->SetCanStart(); |
506 scheduler->SetVisible(true); | 504 scheduler->SetVisible(true); |
507 scheduler->SetCanDraw(true); | 505 scheduler->SetCanDraw(true); |
508 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | 506 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
509 client.Reset(); | 507 client.Reset(); |
510 | 508 |
511 client.SetDrawWillHappen(false); | 509 client.SetDrawWillHappen(false); |
512 | 510 |
513 scheduler->SetNeedsRedraw(); | 511 scheduler->SetNeedsRedraw(); |
514 EXPECT_TRUE(scheduler->RedrawPending()); | 512 EXPECT_TRUE(scheduler->RedrawPending()); |
515 EXPECT_TRUE(client.needs_begin_frame()); | 513 EXPECT_TRUE(client.needs_begin_frame()); |
516 EXPECT_EQ(0, client.num_draws()); | 514 EXPECT_EQ(0, client.num_draws()); |
517 | 515 |
518 // Fail the draw. | 516 // Fail the draw. |
519 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | 517 client.AdvanceFrame(); |
520 client.task_runner().RunPendingTasks(); // Run posted deadline. | 518 client.task_runner().RunPendingTasks(); // Run posted deadline. |
521 EXPECT_EQ(1, client.num_draws()); | 519 EXPECT_EQ(1, client.num_draws()); |
522 | 520 |
523 // We have a commit pending and the draw failed, and we didn't lose the redraw | 521 // We have a commit pending and the draw failed, and we didn't lose the redraw |
524 // request. | 522 // request. |
525 EXPECT_TRUE(scheduler->CommitPending()); | 523 EXPECT_TRUE(scheduler->CommitPending()); |
526 EXPECT_TRUE(scheduler->RedrawPending()); | 524 EXPECT_TRUE(scheduler->RedrawPending()); |
527 EXPECT_TRUE(client.needs_begin_frame()); | 525 EXPECT_TRUE(client.needs_begin_frame()); |
528 | 526 |
529 // Fail the draw again. | 527 // Fail the draw again. |
530 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | 528 client.AdvanceFrame(); |
531 client.task_runner().RunPendingTasks(); // Run posted deadline. | 529 client.task_runner().RunPendingTasks(); // Run posted deadline. |
532 EXPECT_EQ(2, client.num_draws()); | 530 EXPECT_EQ(2, client.num_draws()); |
533 EXPECT_TRUE(scheduler->CommitPending()); | 531 EXPECT_TRUE(scheduler->CommitPending()); |
534 EXPECT_TRUE(scheduler->RedrawPending()); | 532 EXPECT_TRUE(scheduler->RedrawPending()); |
535 EXPECT_TRUE(client.needs_begin_frame()); | 533 EXPECT_TRUE(client.needs_begin_frame()); |
536 | 534 |
537 // Draw successfully. | 535 // Draw successfully. |
538 client.SetDrawWillHappen(true); | 536 client.SetDrawWillHappen(true); |
539 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | 537 client.AdvanceFrame(); |
540 client.task_runner().RunPendingTasks(); // Run posted deadline. | 538 client.task_runner().RunPendingTasks(); // Run posted deadline. |
541 EXPECT_EQ(3, client.num_draws()); | 539 EXPECT_EQ(3, client.num_draws()); |
542 EXPECT_TRUE(scheduler->CommitPending()); | 540 EXPECT_TRUE(scheduler->CommitPending()); |
543 EXPECT_FALSE(scheduler->RedrawPending()); | 541 EXPECT_FALSE(scheduler->RedrawPending()); |
544 EXPECT_TRUE(client.needs_begin_frame()); | 542 EXPECT_TRUE(client.needs_begin_frame()); |
545 } | 543 } |
546 | 544 |
547 class SchedulerClientThatSetNeedsCommitInsideDraw : public FakeSchedulerClient { | 545 class SchedulerClientThatSetNeedsCommitInsideDraw : public FakeSchedulerClient { |
548 public: | 546 public: |
549 SchedulerClientThatSetNeedsCommitInsideDraw() | 547 SchedulerClientThatSetNeedsCommitInsideDraw() |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
587 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | 585 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
588 client.Reset(); | 586 client.Reset(); |
589 | 587 |
590 EXPECT_FALSE(client.needs_begin_frame()); | 588 EXPECT_FALSE(client.needs_begin_frame()); |
591 scheduler->SetNeedsRedraw(); | 589 scheduler->SetNeedsRedraw(); |
592 EXPECT_TRUE(scheduler->RedrawPending()); | 590 EXPECT_TRUE(scheduler->RedrawPending()); |
593 EXPECT_EQ(0, client.num_draws()); | 591 EXPECT_EQ(0, client.num_draws()); |
594 EXPECT_TRUE(client.needs_begin_frame()); | 592 EXPECT_TRUE(client.needs_begin_frame()); |
595 | 593 |
596 client.SetNeedsCommitOnNextDraw(); | 594 client.SetNeedsCommitOnNextDraw(); |
597 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | 595 client.AdvanceFrame(); |
598 client.SetNeedsCommitOnNextDraw(); | 596 client.SetNeedsCommitOnNextDraw(); |
599 client.task_runner().RunPendingTasks(); // Run posted deadline. | 597 client.task_runner().RunPendingTasks(); // Run posted deadline. |
600 EXPECT_EQ(1, client.num_draws()); | 598 EXPECT_EQ(1, client.num_draws()); |
601 EXPECT_TRUE(scheduler->CommitPending()); | 599 EXPECT_TRUE(scheduler->CommitPending()); |
602 EXPECT_TRUE(client.needs_begin_frame()); | 600 EXPECT_TRUE(client.needs_begin_frame()); |
603 scheduler->NotifyBeginMainFrameStarted(); | 601 scheduler->NotifyBeginMainFrameStarted(); |
604 scheduler->NotifyReadyToCommit(); | 602 scheduler->NotifyReadyToCommit(); |
605 | 603 |
606 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | 604 client.AdvanceFrame(); |
607 client.task_runner().RunPendingTasks(); // Run posted deadline. | 605 client.task_runner().RunPendingTasks(); // Run posted deadline. |
608 EXPECT_EQ(2, client.num_draws()); | 606 EXPECT_EQ(2, client.num_draws()); |
609 | 607 |
610 EXPECT_FALSE(scheduler->RedrawPending()); | 608 EXPECT_FALSE(scheduler->RedrawPending()); |
611 EXPECT_FALSE(scheduler->CommitPending()); | 609 EXPECT_FALSE(scheduler->CommitPending()); |
612 EXPECT_TRUE(client.needs_begin_frame()); | 610 EXPECT_TRUE(client.needs_begin_frame()); |
613 | 611 |
614 // We stop requesting BeginImplFrames after a BeginImplFrame where we don't | 612 // We stop requesting BeginImplFrames after a BeginImplFrame where we don't |
615 // swap. | 613 // swap. |
616 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | 614 client.AdvanceFrame(); |
617 client.task_runner().RunPendingTasks(); // Run posted deadline. | 615 client.task_runner().RunPendingTasks(); // Run posted deadline. |
618 EXPECT_EQ(2, client.num_draws()); | 616 EXPECT_EQ(2, client.num_draws()); |
619 EXPECT_FALSE(scheduler->RedrawPending()); | 617 EXPECT_FALSE(scheduler->RedrawPending()); |
620 EXPECT_FALSE(scheduler->CommitPending()); | 618 EXPECT_FALSE(scheduler->CommitPending()); |
621 EXPECT_FALSE(client.needs_begin_frame()); | 619 EXPECT_FALSE(client.needs_begin_frame()); |
622 } | 620 } |
623 | 621 |
624 // Tests that when a draw fails then the pending commit should not be dropped. | 622 // Tests that when a draw fails then the pending commit should not be dropped. |
625 TEST(SchedulerTest, RequestCommitInsideFailedDraw) { | 623 TEST(SchedulerTest, RequestCommitInsideFailedDraw) { |
626 SchedulerClientThatsetNeedsDrawInsideDraw client; | 624 SchedulerClientThatsetNeedsDrawInsideDraw client; |
627 SchedulerSettings default_scheduler_settings; | 625 SchedulerSettings default_scheduler_settings; |
628 TestScheduler* scheduler = client.CreateScheduler(default_scheduler_settings); | 626 TestScheduler* scheduler = client.CreateScheduler(default_scheduler_settings); |
629 scheduler->SetCanStart(); | 627 scheduler->SetCanStart(); |
630 scheduler->SetVisible(true); | 628 scheduler->SetVisible(true); |
631 scheduler->SetCanDraw(true); | 629 scheduler->SetCanDraw(true); |
632 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | 630 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
633 client.Reset(); | 631 client.Reset(); |
634 | 632 |
635 client.SetDrawWillHappen(false); | 633 client.SetDrawWillHappen(false); |
636 | 634 |
637 scheduler->SetNeedsRedraw(); | 635 scheduler->SetNeedsRedraw(); |
638 EXPECT_TRUE(scheduler->RedrawPending()); | 636 EXPECT_TRUE(scheduler->RedrawPending()); |
639 EXPECT_TRUE(client.needs_begin_frame()); | 637 EXPECT_TRUE(client.needs_begin_frame()); |
640 EXPECT_EQ(0, client.num_draws()); | 638 EXPECT_EQ(0, client.num_draws()); |
641 | 639 |
642 // Fail the draw. | 640 // Fail the draw. |
643 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | 641 client.AdvanceFrame(); |
644 client.task_runner().RunPendingTasks(); // Run posted deadline. | 642 client.task_runner().RunPendingTasks(); // Run posted deadline. |
645 EXPECT_EQ(1, client.num_draws()); | 643 EXPECT_EQ(1, client.num_draws()); |
646 | 644 |
647 // We have a commit pending and the draw failed, and we didn't lose the commit | 645 // We have a commit pending and the draw failed, and we didn't lose the commit |
648 // request. | 646 // request. |
649 EXPECT_TRUE(scheduler->CommitPending()); | 647 EXPECT_TRUE(scheduler->CommitPending()); |
650 EXPECT_TRUE(scheduler->RedrawPending()); | 648 EXPECT_TRUE(scheduler->RedrawPending()); |
651 EXPECT_TRUE(client.needs_begin_frame()); | 649 EXPECT_TRUE(client.needs_begin_frame()); |
652 | 650 |
653 // Fail the draw again. | 651 // Fail the draw again. |
654 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | 652 client.AdvanceFrame(); |
655 | 653 |
656 client.task_runner().RunPendingTasks(); // Run posted deadline. | 654 client.task_runner().RunPendingTasks(); // Run posted deadline. |
657 EXPECT_EQ(2, client.num_draws()); | 655 EXPECT_EQ(2, client.num_draws()); |
658 EXPECT_TRUE(scheduler->CommitPending()); | 656 EXPECT_TRUE(scheduler->CommitPending()); |
659 EXPECT_TRUE(scheduler->RedrawPending()); | 657 EXPECT_TRUE(scheduler->RedrawPending()); |
660 EXPECT_TRUE(client.needs_begin_frame()); | 658 EXPECT_TRUE(client.needs_begin_frame()); |
661 | 659 |
662 // Draw successfully. | 660 // Draw successfully. |
663 client.SetDrawWillHappen(true); | 661 client.SetDrawWillHappen(true); |
664 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | 662 client.AdvanceFrame(); |
665 client.task_runner().RunPendingTasks(); // Run posted deadline. | 663 client.task_runner().RunPendingTasks(); // Run posted deadline. |
666 EXPECT_EQ(3, client.num_draws()); | 664 EXPECT_EQ(3, client.num_draws()); |
667 EXPECT_TRUE(scheduler->CommitPending()); | 665 EXPECT_TRUE(scheduler->CommitPending()); |
668 EXPECT_FALSE(scheduler->RedrawPending()); | 666 EXPECT_FALSE(scheduler->RedrawPending()); |
669 EXPECT_TRUE(client.needs_begin_frame()); | 667 EXPECT_TRUE(client.needs_begin_frame()); |
670 } | 668 } |
671 | 669 |
672 TEST(SchedulerTest, NoSwapWhenDrawFails) { | 670 TEST(SchedulerTest, NoSwapWhenDrawFails) { |
673 SchedulerClientThatSetNeedsCommitInsideDraw client; | 671 SchedulerClientThatSetNeedsCommitInsideDraw client; |
674 SchedulerSettings default_scheduler_settings; | 672 SchedulerSettings default_scheduler_settings; |
675 TestScheduler* scheduler = client.CreateScheduler(default_scheduler_settings); | 673 TestScheduler* scheduler = client.CreateScheduler(default_scheduler_settings); |
676 scheduler->SetCanStart(); | 674 scheduler->SetCanStart(); |
677 scheduler->SetVisible(true); | 675 scheduler->SetVisible(true); |
678 scheduler->SetCanDraw(true); | 676 scheduler->SetCanDraw(true); |
679 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | 677 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
680 client.Reset(); | 678 client.Reset(); |
681 | 679 |
682 scheduler->SetNeedsRedraw(); | 680 scheduler->SetNeedsRedraw(); |
683 EXPECT_TRUE(scheduler->RedrawPending()); | 681 EXPECT_TRUE(scheduler->RedrawPending()); |
684 EXPECT_TRUE(client.needs_begin_frame()); | 682 EXPECT_TRUE(client.needs_begin_frame()); |
685 EXPECT_EQ(0, client.num_draws()); | 683 EXPECT_EQ(0, client.num_draws()); |
686 | 684 |
687 // Draw successfully, this starts a new frame. | 685 // Draw successfully, this starts a new frame. |
688 client.SetNeedsCommitOnNextDraw(); | 686 client.SetNeedsCommitOnNextDraw(); |
689 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | 687 client.AdvanceFrame(); |
690 client.task_runner().RunPendingTasks(); // Run posted deadline. | 688 client.task_runner().RunPendingTasks(); // Run posted deadline. |
691 EXPECT_EQ(1, client.num_draws()); | 689 EXPECT_EQ(1, client.num_draws()); |
692 | 690 |
693 scheduler->SetNeedsRedraw(); | 691 scheduler->SetNeedsRedraw(); |
694 EXPECT_TRUE(scheduler->RedrawPending()); | 692 EXPECT_TRUE(scheduler->RedrawPending()); |
695 EXPECT_TRUE(client.needs_begin_frame()); | 693 EXPECT_TRUE(client.needs_begin_frame()); |
696 | 694 |
697 // Fail to draw, this should not start a frame. | 695 // Fail to draw, this should not start a frame. |
698 client.SetDrawWillHappen(false); | 696 client.SetDrawWillHappen(false); |
699 client.SetNeedsCommitOnNextDraw(); | 697 client.SetNeedsCommitOnNextDraw(); |
700 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | 698 client.AdvanceFrame(); |
701 client.task_runner().RunPendingTasks(); // Run posted deadline. | 699 client.task_runner().RunPendingTasks(); // Run posted deadline. |
702 EXPECT_EQ(2, client.num_draws()); | 700 EXPECT_EQ(2, client.num_draws()); |
703 } | 701 } |
704 | 702 |
705 class SchedulerClientNeedsManageTilesInDraw : public FakeSchedulerClient { | 703 class SchedulerClientNeedsManageTilesInDraw : public FakeSchedulerClient { |
706 public: | 704 public: |
707 virtual DrawResult ScheduledActionDrawAndSwapIfPossible() | 705 virtual DrawResult ScheduledActionDrawAndSwapIfPossible() |
708 OVERRIDE { | 706 OVERRIDE { |
709 scheduler_->SetNeedsManageTiles(); | 707 scheduler_->SetNeedsManageTiles(); |
710 return FakeSchedulerClient::ScheduledActionDrawAndSwapIfPossible(); | 708 return FakeSchedulerClient::ScheduledActionDrawAndSwapIfPossible(); |
(...skipping 18 matching lines...) Expand all Loading... | |
729 EXPECT_TRUE(scheduler->RedrawPending()); | 727 EXPECT_TRUE(scheduler->RedrawPending()); |
730 EXPECT_TRUE(scheduler->ManageTilesPending()); | 728 EXPECT_TRUE(scheduler->ManageTilesPending()); |
731 EXPECT_TRUE(client.needs_begin_frame()); | 729 EXPECT_TRUE(client.needs_begin_frame()); |
732 EXPECT_EQ(0, client.num_draws()); | 730 EXPECT_EQ(0, client.num_draws()); |
733 EXPECT_FALSE(client.HasAction("ScheduledActionManageTiles")); | 731 EXPECT_FALSE(client.HasAction("ScheduledActionManageTiles")); |
734 EXPECT_FALSE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); | 732 EXPECT_FALSE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); |
735 | 733 |
736 // We have no immediate actions to perform, so the BeginImplFrame should post | 734 // We have no immediate actions to perform, so the BeginImplFrame should post |
737 // the deadline task. | 735 // the deadline task. |
738 client.Reset(); | 736 client.Reset(); |
739 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | 737 client.AdvanceFrame(); |
740 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 738 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
741 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); | 739 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); |
742 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 740 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
743 | 741 |
744 // On the deadline, he actions should have occured in the right order. | 742 // On the deadline, he actions should have occured in the right order. |
745 client.Reset(); | 743 client.Reset(); |
746 client.task_runner().RunPendingTasks(); // Run posted deadline. | 744 client.task_runner().RunPendingTasks(); // Run posted deadline. |
747 EXPECT_EQ(1, client.num_draws()); | 745 EXPECT_EQ(1, client.num_draws()); |
748 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); | 746 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); |
749 EXPECT_TRUE(client.HasAction("ScheduledActionManageTiles")); | 747 EXPECT_TRUE(client.HasAction("ScheduledActionManageTiles")); |
750 EXPECT_LT(client.ActionIndex("ScheduledActionDrawAndSwapIfPossible"), | 748 EXPECT_LT(client.ActionIndex("ScheduledActionDrawAndSwapIfPossible"), |
751 client.ActionIndex("ScheduledActionManageTiles")); | 749 client.ActionIndex("ScheduledActionManageTiles")); |
752 EXPECT_FALSE(scheduler->RedrawPending()); | 750 EXPECT_FALSE(scheduler->RedrawPending()); |
753 EXPECT_FALSE(scheduler->ManageTilesPending()); | 751 EXPECT_FALSE(scheduler->ManageTilesPending()); |
754 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 752 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
755 | 753 |
756 // Request a draw. We don't need a ManageTiles yet. | 754 // Request a draw. We don't need a ManageTiles yet. |
757 client.Reset(); | 755 client.Reset(); |
758 scheduler->SetNeedsRedraw(); | 756 scheduler->SetNeedsRedraw(); |
759 EXPECT_TRUE(scheduler->RedrawPending()); | 757 EXPECT_TRUE(scheduler->RedrawPending()); |
760 EXPECT_FALSE(scheduler->ManageTilesPending()); | 758 EXPECT_FALSE(scheduler->ManageTilesPending()); |
761 EXPECT_TRUE(client.needs_begin_frame()); | 759 EXPECT_TRUE(client.needs_begin_frame()); |
762 EXPECT_EQ(0, client.num_draws()); | 760 EXPECT_EQ(0, client.num_draws()); |
763 | 761 |
764 // We have no immediate actions to perform, so the BeginImplFrame should post | 762 // We have no immediate actions to perform, so the BeginImplFrame should post |
765 // the deadline task. | 763 // the deadline task. |
766 client.Reset(); | 764 client.Reset(); |
767 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | 765 client.AdvanceFrame(); |
768 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 766 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
769 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); | 767 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); |
770 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 768 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
771 | 769 |
772 // Draw. The draw will trigger SetNeedsManageTiles, and | 770 // Draw. The draw will trigger SetNeedsManageTiles, and |
773 // then the ManageTiles action will be triggered after the Draw. | 771 // then the ManageTiles action will be triggered after the Draw. |
774 // Afterwards, neither a draw nor ManageTiles are pending. | 772 // Afterwards, neither a draw nor ManageTiles are pending. |
775 client.Reset(); | 773 client.Reset(); |
776 client.task_runner().RunPendingTasks(); // Run posted deadline. | 774 client.task_runner().RunPendingTasks(); // Run posted deadline. |
777 EXPECT_EQ(1, client.num_draws()); | 775 EXPECT_EQ(1, client.num_draws()); |
778 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); | 776 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); |
779 EXPECT_TRUE(client.HasAction("ScheduledActionManageTiles")); | 777 EXPECT_TRUE(client.HasAction("ScheduledActionManageTiles")); |
780 EXPECT_LT(client.ActionIndex("ScheduledActionDrawAndSwapIfPossible"), | 778 EXPECT_LT(client.ActionIndex("ScheduledActionDrawAndSwapIfPossible"), |
781 client.ActionIndex("ScheduledActionManageTiles")); | 779 client.ActionIndex("ScheduledActionManageTiles")); |
782 EXPECT_FALSE(scheduler->RedrawPending()); | 780 EXPECT_FALSE(scheduler->RedrawPending()); |
783 EXPECT_FALSE(scheduler->ManageTilesPending()); | 781 EXPECT_FALSE(scheduler->ManageTilesPending()); |
784 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 782 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
785 | 783 |
786 // We need a BeginImplFrame where we don't swap to go idle. | 784 // We need a BeginImplFrame where we don't swap to go idle. |
787 client.Reset(); | 785 client.Reset(); |
788 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | 786 client.AdvanceFrame(); |
789 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); | 787 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); |
790 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 788 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
791 client.Reset(); | 789 client.Reset(); |
792 client.task_runner().RunPendingTasks(); // Run posted deadline. | 790 client.task_runner().RunPendingTasks(); // Run posted deadline. |
793 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); | 791 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); |
794 EXPECT_FALSE(client.needs_begin_frame()); | 792 EXPECT_FALSE(client.needs_begin_frame()); |
795 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 793 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
796 EXPECT_EQ(0, client.num_draws()); | 794 EXPECT_EQ(0, client.num_draws()); |
797 | 795 |
798 // Now trigger a ManageTiles outside of a draw. We will then need | 796 // 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. | 797 // a begin-frame for the ManageTiles, but we don't need a draw. |
800 client.Reset(); | 798 client.Reset(); |
801 EXPECT_FALSE(client.needs_begin_frame()); | 799 EXPECT_FALSE(client.needs_begin_frame()); |
802 scheduler->SetNeedsManageTiles(); | 800 scheduler->SetNeedsManageTiles(); |
803 EXPECT_TRUE(client.needs_begin_frame()); | 801 EXPECT_TRUE(client.needs_begin_frame()); |
804 EXPECT_TRUE(scheduler->ManageTilesPending()); | 802 EXPECT_TRUE(scheduler->ManageTilesPending()); |
805 EXPECT_FALSE(scheduler->RedrawPending()); | 803 EXPECT_FALSE(scheduler->RedrawPending()); |
806 | 804 |
807 // BeginImplFrame. There will be no draw, only ManageTiles. | 805 // BeginImplFrame. There will be no draw, only ManageTiles. |
808 client.Reset(); | 806 client.Reset(); |
809 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | 807 client.AdvanceFrame(); |
810 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); | 808 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); |
811 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 809 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
812 client.Reset(); | 810 client.Reset(); |
813 client.task_runner().RunPendingTasks(); // Run posted deadline. | 811 client.task_runner().RunPendingTasks(); // Run posted deadline. |
814 EXPECT_EQ(0, client.num_draws()); | 812 EXPECT_EQ(0, client.num_draws()); |
815 EXPECT_FALSE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); | 813 EXPECT_FALSE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); |
816 EXPECT_TRUE(client.HasAction("ScheduledActionManageTiles")); | 814 EXPECT_TRUE(client.HasAction("ScheduledActionManageTiles")); |
817 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 815 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
818 } | 816 } |
819 | 817 |
820 // Test that ManageTiles only happens once per frame. If an external caller | 818 // 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. | 819 // initiates it, then the state machine should not ManageTiles on that frame. |
822 TEST(SchedulerTest, ManageTilesOncePerFrame) { | 820 TEST(SchedulerTest, ManageTilesOncePerFrame) { |
823 FakeSchedulerClient client; | 821 FakeSchedulerClient client; |
824 SchedulerSettings default_scheduler_settings; | 822 SchedulerSettings default_scheduler_settings; |
825 TestScheduler* scheduler = client.CreateScheduler(default_scheduler_settings); | 823 TestScheduler* scheduler = client.CreateScheduler(default_scheduler_settings); |
826 scheduler->SetCanStart(); | 824 scheduler->SetCanStart(); |
827 scheduler->SetVisible(true); | 825 scheduler->SetVisible(true); |
828 scheduler->SetCanDraw(true); | 826 scheduler->SetCanDraw(true); |
829 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | 827 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
830 | 828 |
831 // If DidManageTiles during a frame, then ManageTiles should not occur again. | 829 // If DidManageTiles during a frame, then ManageTiles should not occur again. |
832 scheduler->SetNeedsManageTiles(); | 830 scheduler->SetNeedsManageTiles(); |
833 scheduler->SetNeedsRedraw(); | 831 scheduler->SetNeedsRedraw(); |
834 client.Reset(); | 832 client.Reset(); |
835 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | 833 client.AdvanceFrame(); |
836 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 834 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
837 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); | 835 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); |
838 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 836 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
839 | 837 |
840 EXPECT_TRUE(scheduler->ManageTilesPending()); | 838 EXPECT_TRUE(scheduler->ManageTilesPending()); |
841 scheduler->DidManageTiles(); // An explicit ManageTiles. | 839 scheduler->DidManageTiles(); // An explicit ManageTiles. |
842 EXPECT_FALSE(scheduler->ManageTilesPending()); | 840 EXPECT_FALSE(scheduler->ManageTilesPending()); |
843 | 841 |
844 client.Reset(); | 842 client.Reset(); |
845 client.task_runner().RunPendingTasks(); // Run posted deadline. | 843 client.task_runner().RunPendingTasks(); // Run posted deadline. |
846 EXPECT_EQ(1, client.num_draws()); | 844 EXPECT_EQ(1, client.num_draws()); |
847 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); | 845 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); |
848 EXPECT_FALSE(client.HasAction("ScheduledActionManageTiles")); | 846 EXPECT_FALSE(client.HasAction("ScheduledActionManageTiles")); |
849 EXPECT_FALSE(scheduler->RedrawPending()); | 847 EXPECT_FALSE(scheduler->RedrawPending()); |
850 EXPECT_FALSE(scheduler->ManageTilesPending()); | 848 EXPECT_FALSE(scheduler->ManageTilesPending()); |
851 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 849 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
852 | 850 |
853 // Next frame without DidManageTiles should ManageTiles with draw. | 851 // Next frame without DidManageTiles should ManageTiles with draw. |
854 scheduler->SetNeedsManageTiles(); | 852 scheduler->SetNeedsManageTiles(); |
855 scheduler->SetNeedsRedraw(); | 853 scheduler->SetNeedsRedraw(); |
856 client.Reset(); | 854 client.Reset(); |
857 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | 855 client.AdvanceFrame(); |
858 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 856 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
859 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); | 857 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); |
860 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 858 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
861 | 859 |
862 client.Reset(); | 860 client.Reset(); |
863 client.task_runner().RunPendingTasks(); // Run posted deadline. | 861 client.task_runner().RunPendingTasks(); // Run posted deadline. |
864 EXPECT_EQ(1, client.num_draws()); | 862 EXPECT_EQ(1, client.num_draws()); |
865 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); | 863 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); |
866 EXPECT_TRUE(client.HasAction("ScheduledActionManageTiles")); | 864 EXPECT_TRUE(client.HasAction("ScheduledActionManageTiles")); |
867 EXPECT_LT(client.ActionIndex("ScheduledActionDrawAndSwapIfPossible"), | 865 EXPECT_LT(client.ActionIndex("ScheduledActionDrawAndSwapIfPossible"), |
868 client.ActionIndex("ScheduledActionManageTiles")); | 866 client.ActionIndex("ScheduledActionManageTiles")); |
869 EXPECT_FALSE(scheduler->RedrawPending()); | 867 EXPECT_FALSE(scheduler->RedrawPending()); |
870 EXPECT_FALSE(scheduler->ManageTilesPending()); | 868 EXPECT_FALSE(scheduler->ManageTilesPending()); |
871 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 869 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
872 scheduler->DidManageTiles(); // Corresponds to ScheduledActionManageTiles | 870 scheduler->DidManageTiles(); // Corresponds to ScheduledActionManageTiles |
873 | 871 |
874 // If we get another DidManageTiles within the same frame, we should | 872 // If we get another DidManageTiles within the same frame, we should |
875 // not ManageTiles on the next frame. | 873 // not ManageTiles on the next frame. |
876 scheduler->DidManageTiles(); // An explicit ManageTiles. | 874 scheduler->DidManageTiles(); // An explicit ManageTiles. |
877 scheduler->SetNeedsManageTiles(); | 875 scheduler->SetNeedsManageTiles(); |
878 scheduler->SetNeedsRedraw(); | 876 scheduler->SetNeedsRedraw(); |
879 client.Reset(); | 877 client.Reset(); |
880 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | 878 client.AdvanceFrame(); |
881 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 879 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
882 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); | 880 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); |
883 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 881 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
884 | 882 |
885 EXPECT_TRUE(scheduler->ManageTilesPending()); | 883 EXPECT_TRUE(scheduler->ManageTilesPending()); |
886 | 884 |
887 client.Reset(); | 885 client.Reset(); |
888 client.task_runner().RunPendingTasks(); // Run posted deadline. | 886 client.task_runner().RunPendingTasks(); // Run posted deadline. |
889 EXPECT_EQ(1, client.num_draws()); | 887 EXPECT_EQ(1, client.num_draws()); |
890 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); | 888 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); |
891 EXPECT_FALSE(client.HasAction("ScheduledActionManageTiles")); | 889 EXPECT_FALSE(client.HasAction("ScheduledActionManageTiles")); |
892 EXPECT_FALSE(scheduler->RedrawPending()); | 890 EXPECT_FALSE(scheduler->RedrawPending()); |
893 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 891 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
894 | 892 |
895 // If we get another DidManageTiles, we should not ManageTiles on the next | 893 // 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. | 894 // frame. This verifies we don't alternate calling ManageTiles once and twice. |
897 EXPECT_TRUE(scheduler->ManageTilesPending()); | 895 EXPECT_TRUE(scheduler->ManageTilesPending()); |
898 scheduler->DidManageTiles(); // An explicit ManageTiles. | 896 scheduler->DidManageTiles(); // An explicit ManageTiles. |
899 EXPECT_FALSE(scheduler->ManageTilesPending()); | 897 EXPECT_FALSE(scheduler->ManageTilesPending()); |
900 scheduler->SetNeedsManageTiles(); | 898 scheduler->SetNeedsManageTiles(); |
901 scheduler->SetNeedsRedraw(); | 899 scheduler->SetNeedsRedraw(); |
902 client.Reset(); | 900 client.Reset(); |
903 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | 901 client.AdvanceFrame(); |
904 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 902 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
905 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); | 903 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); |
906 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 904 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
907 | 905 |
908 EXPECT_TRUE(scheduler->ManageTilesPending()); | 906 EXPECT_TRUE(scheduler->ManageTilesPending()); |
909 | 907 |
910 client.Reset(); | 908 client.Reset(); |
911 client.task_runner().RunPendingTasks(); // Run posted deadline. | 909 client.task_runner().RunPendingTasks(); // Run posted deadline. |
912 EXPECT_EQ(1, client.num_draws()); | 910 EXPECT_EQ(1, client.num_draws()); |
913 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); | 911 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); |
914 EXPECT_FALSE(client.HasAction("ScheduledActionManageTiles")); | 912 EXPECT_FALSE(client.HasAction("ScheduledActionManageTiles")); |
915 EXPECT_FALSE(scheduler->RedrawPending()); | 913 EXPECT_FALSE(scheduler->RedrawPending()); |
916 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 914 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
917 | 915 |
918 // Next frame without DidManageTiles should ManageTiles with draw. | 916 // Next frame without DidManageTiles should ManageTiles with draw. |
919 scheduler->SetNeedsManageTiles(); | 917 scheduler->SetNeedsManageTiles(); |
920 scheduler->SetNeedsRedraw(); | 918 scheduler->SetNeedsRedraw(); |
921 client.Reset(); | 919 client.Reset(); |
922 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | 920 client.AdvanceFrame(); |
923 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 921 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
924 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); | 922 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); |
925 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 923 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
926 | 924 |
927 client.Reset(); | 925 client.Reset(); |
928 client.task_runner().RunPendingTasks(); // Run posted deadline. | 926 client.task_runner().RunPendingTasks(); // Run posted deadline. |
929 EXPECT_EQ(1, client.num_draws()); | 927 EXPECT_EQ(1, client.num_draws()); |
930 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); | 928 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); |
931 EXPECT_TRUE(client.HasAction("ScheduledActionManageTiles")); | 929 EXPECT_TRUE(client.HasAction("ScheduledActionManageTiles")); |
932 EXPECT_LT(client.ActionIndex("ScheduledActionDrawAndSwapIfPossible"), | 930 EXPECT_LT(client.ActionIndex("ScheduledActionDrawAndSwapIfPossible"), |
(...skipping 15 matching lines...) Expand all Loading... | |
948 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | 946 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
949 | 947 |
950 client.SetRedrawWillHappenIfUpdateVisibleTilesHappens(true); | 948 client.SetRedrawWillHappenIfUpdateVisibleTilesHappens(true); |
951 | 949 |
952 // SetNeedsCommit should begin the frame. | 950 // SetNeedsCommit should begin the frame. |
953 client.Reset(); | 951 client.Reset(); |
954 scheduler->SetNeedsCommit(); | 952 scheduler->SetNeedsCommit(); |
955 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); | 953 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); |
956 | 954 |
957 client.Reset(); | 955 client.Reset(); |
958 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | 956 client.AdvanceFrame(); |
959 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 957 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
960 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); | 958 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); |
961 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 959 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
962 | 960 |
963 client.Reset(); | 961 client.Reset(); |
964 scheduler->NotifyBeginMainFrameStarted(); | 962 scheduler->NotifyBeginMainFrameStarted(); |
965 scheduler->NotifyReadyToCommit(); | 963 scheduler->NotifyReadyToCommit(); |
966 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); | 964 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); |
967 | 965 |
968 client.Reset(); | 966 client.Reset(); |
969 scheduler->NotifyReadyToActivate(); | 967 scheduler->NotifyReadyToActivate(); |
970 EXPECT_SINGLE_ACTION("ScheduledActionActivateSyncTree", client); | 968 EXPECT_SINGLE_ACTION("ScheduledActionActivateSyncTree", client); |
971 | 969 |
972 client.Reset(); | 970 client.Reset(); |
973 client.SetSwapContainsIncompleteTile(true); | 971 client.SetSwapContainsIncompleteTile(true); |
974 client.task_runner().RunPendingTasks(); // Run posted deadline. | 972 client.task_runner().RunPendingTasks(); // Run posted deadline. |
975 EXPECT_ACTION("ScheduledActionAnimate", client, 0, 2); | 973 EXPECT_ACTION("ScheduledActionAnimate", client, 0, 2); |
976 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 1, 2); | 974 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 1, 2); |
977 EXPECT_FALSE(scheduler->RedrawPending()); | 975 EXPECT_FALSE(scheduler->RedrawPending()); |
978 | 976 |
979 client.Reset(); | 977 client.Reset(); |
980 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | 978 client.AdvanceFrame(); |
981 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); | 979 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); |
982 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 980 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
983 | 981 |
984 client.Reset(); | 982 client.Reset(); |
985 client.task_runner().RunPendingTasks(); // Run posted deadline. | 983 client.task_runner().RunPendingTasks(); // Run posted deadline. |
986 EXPECT_ACTION("ScheduledActionUpdateVisibleTiles", client, 0, 3); | 984 EXPECT_ACTION("ScheduledActionUpdateVisibleTiles", client, 0, 3); |
987 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 3); | 985 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 3); |
988 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 2, 3); | 986 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 2, 3); |
989 | 987 |
990 client.Reset(); | 988 client.Reset(); |
991 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | 989 client.AdvanceFrame(); |
992 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); | 990 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); |
993 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 991 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
994 | 992 |
995 // No more UpdateVisibleTiles(). | 993 // No more UpdateVisibleTiles(). |
996 client.Reset(); | 994 client.Reset(); |
997 client.task_runner().RunPendingTasks(); // Run posted deadline. | 995 client.task_runner().RunPendingTasks(); // Run posted deadline. |
998 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); | 996 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); |
999 EXPECT_FALSE(client.needs_begin_frame()); | 997 EXPECT_FALSE(client.needs_begin_frame()); |
1000 } | 998 } |
1001 | 999 |
1002 TEST(SchedulerTest, TriggerBeginFrameDeadlineEarly) { | 1000 TEST(SchedulerTest, TriggerBeginFrameDeadlineEarly) { |
1003 SchedulerClientNeedsManageTilesInDraw client; | 1001 SchedulerClientNeedsManageTilesInDraw client; |
1004 SchedulerSettings default_scheduler_settings; | 1002 SchedulerSettings default_scheduler_settings; |
1005 TestScheduler* scheduler = client.CreateScheduler(default_scheduler_settings); | 1003 TestScheduler* scheduler = client.CreateScheduler(default_scheduler_settings); |
1006 scheduler->SetCanStart(); | 1004 scheduler->SetCanStart(); |
1007 scheduler->SetVisible(true); | 1005 scheduler->SetVisible(true); |
1008 scheduler->SetCanDraw(true); | 1006 scheduler->SetCanDraw(true); |
1009 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | 1007 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
1010 | 1008 |
1011 client.Reset(); | 1009 client.Reset(); |
1012 scheduler->SetNeedsRedraw(); | 1010 scheduler->SetNeedsRedraw(); |
1013 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | 1011 client.AdvanceFrame(); |
1014 | 1012 |
1015 // The deadline should be zero since there is no work other than drawing | 1013 // The deadline should be zero since there is no work other than drawing |
1016 // pending. | 1014 // pending. |
1017 EXPECT_EQ(base::TimeTicks(), client.posted_begin_impl_frame_deadline()); | 1015 EXPECT_EQ(base::TimeTicks(), client.posted_begin_impl_frame_deadline()); |
1018 } | 1016 } |
1019 | 1017 |
1020 class SchedulerClientWithFixedEstimates : public FakeSchedulerClient { | 1018 class SchedulerClientWithFixedEstimates : public FakeSchedulerClient { |
1021 public: | 1019 public: |
1022 SchedulerClientWithFixedEstimates( | 1020 SchedulerClientWithFixedEstimates( |
1023 base::TimeDelta draw_duration, | 1021 base::TimeDelta draw_duration, |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1059 scheduler->SetCanStart(); | 1057 scheduler->SetCanStart(); |
1060 scheduler->SetVisible(true); | 1058 scheduler->SetVisible(true); |
1061 scheduler->SetCanDraw(true); | 1059 scheduler->SetCanDraw(true); |
1062 scheduler->SetSmoothnessTakesPriority(smoothness_takes_priority); | 1060 scheduler->SetSmoothnessTakesPriority(smoothness_takes_priority); |
1063 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | 1061 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
1064 | 1062 |
1065 // Impl thread hits deadline before commit finishes. | 1063 // Impl thread hits deadline before commit finishes. |
1066 client.Reset(); | 1064 client.Reset(); |
1067 scheduler->SetNeedsCommit(); | 1065 scheduler->SetNeedsCommit(); |
1068 EXPECT_FALSE(scheduler->MainThreadIsInHighLatencyMode()); | 1066 EXPECT_FALSE(scheduler->MainThreadIsInHighLatencyMode()); |
1069 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | 1067 client.AdvanceFrame(); |
1070 EXPECT_FALSE(scheduler->MainThreadIsInHighLatencyMode()); | 1068 EXPECT_FALSE(scheduler->MainThreadIsInHighLatencyMode()); |
1071 client.task_runner().RunPendingTasks(); // Run posted deadline. | 1069 client.task_runner().RunPendingTasks(); // Run posted deadline. |
1072 EXPECT_TRUE(scheduler->MainThreadIsInHighLatencyMode()); | 1070 EXPECT_TRUE(scheduler->MainThreadIsInHighLatencyMode()); |
1073 scheduler->NotifyBeginMainFrameStarted(); | 1071 scheduler->NotifyBeginMainFrameStarted(); |
1074 scheduler->NotifyReadyToCommit(); | 1072 scheduler->NotifyReadyToCommit(); |
1075 EXPECT_TRUE(scheduler->MainThreadIsInHighLatencyMode()); | 1073 EXPECT_TRUE(scheduler->MainThreadIsInHighLatencyMode()); |
1076 EXPECT_TRUE(client.HasAction("ScheduledActionSendBeginMainFrame")); | 1074 EXPECT_TRUE(client.HasAction("ScheduledActionSendBeginMainFrame")); |
1077 | 1075 |
1078 client.Reset(); | 1076 client.Reset(); |
1079 scheduler->SetNeedsCommit(); | 1077 scheduler->SetNeedsCommit(); |
1080 EXPECT_TRUE(scheduler->MainThreadIsInHighLatencyMode()); | 1078 EXPECT_TRUE(scheduler->MainThreadIsInHighLatencyMode()); |
1081 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | 1079 client.AdvanceFrame(); |
1082 EXPECT_TRUE(scheduler->MainThreadIsInHighLatencyMode()); | 1080 EXPECT_TRUE(scheduler->MainThreadIsInHighLatencyMode()); |
1083 client.task_runner().RunPendingTasks(); // Run posted deadline. | 1081 client.task_runner().RunPendingTasks(); // Run posted deadline. |
1084 EXPECT_EQ(scheduler->MainThreadIsInHighLatencyMode(), | 1082 EXPECT_EQ(scheduler->MainThreadIsInHighLatencyMode(), |
1085 should_send_begin_main_frame); | 1083 should_send_begin_main_frame); |
1086 EXPECT_EQ(client.HasAction("ScheduledActionSendBeginMainFrame"), | 1084 EXPECT_EQ(client.HasAction("ScheduledActionSendBeginMainFrame"), |
1087 should_send_begin_main_frame); | 1085 should_send_begin_main_frame); |
1088 } | 1086 } |
1089 | 1087 |
1090 TEST(SchedulerTest, | 1088 TEST(SchedulerTest, |
1091 SkipMainFrameIfHighLatencyAndCanCommitAndActivateBeforeDeadline) { | 1089 SkipMainFrameIfHighLatencyAndCanCommitAndActivateBeforeDeadline) { |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1128 scheduler->SetCanStart(); | 1126 scheduler->SetCanStart(); |
1129 scheduler->SetVisible(true); | 1127 scheduler->SetVisible(true); |
1130 scheduler->DidCreateAndInitializeOutputSurface(); | 1128 scheduler->DidCreateAndInitializeOutputSurface(); |
1131 | 1129 |
1132 scheduler->SetNeedsCommit(); | 1130 scheduler->SetNeedsCommit(); |
1133 EXPECT_TRUE(scheduler->CommitPending()); | 1131 EXPECT_TRUE(scheduler->CommitPending()); |
1134 scheduler->NotifyBeginMainFrameStarted(); | 1132 scheduler->NotifyBeginMainFrameStarted(); |
1135 scheduler->NotifyReadyToCommit(); | 1133 scheduler->NotifyReadyToCommit(); |
1136 scheduler->SetNeedsRedraw(); | 1134 scheduler->SetNeedsRedraw(); |
1137 | 1135 |
1138 BeginFrameArgs frame_args = CreateBeginFrameArgsForTesting(); | 1136 BeginFrameArgs frame_args = CreateBeginFrameArgsForTesting(client.now_src()); |
1139 frame_args.interval = base::TimeDelta::FromMilliseconds(1000); | 1137 frame_args.interval = base::TimeDelta::FromMilliseconds(1000); |
1140 scheduler->BeginFrame(frame_args); | 1138 { |
1139 TRACE_EVENT1("cc", | |
1140 "SchedulerTest::PollForCommitCompletion", | |
1141 "frame_args", | |
1142 frame_args.AsValue()); | |
1143 scheduler->BeginFrame(frame_args); | |
1144 } | |
1141 | 1145 |
1142 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1146 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
1143 client.task_runner().RunPendingTasks(); // Run posted deadline. | 1147 client.task_runner().RunPendingTasks(); // Run posted deadline. |
1144 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 1148 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
1145 | 1149 |
1146 scheduler->DidSwapBuffers(); | 1150 scheduler->DidSwapBuffers(); |
1147 scheduler->DidSwapBuffersComplete(); | 1151 scheduler->DidSwapBuffersComplete(); |
1148 | 1152 |
1149 // At this point, we've drawn a frame. Start another commit, but hold off on | 1153 // At this point, we've drawn a frame. Start another commit, but hold off on |
1150 // the NotifyReadyToCommit for now. | 1154 // the NotifyReadyToCommit for now. |
1151 EXPECT_FALSE(scheduler->CommitPending()); | 1155 EXPECT_FALSE(scheduler->CommitPending()); |
1152 scheduler->SetNeedsCommit(); | 1156 scheduler->SetNeedsCommit(); |
1153 scheduler->BeginFrame(frame_args); | 1157 { |
1158 TRACE_EVENT1("cc", | |
1159 "SchedulerTest::PollForCommitCompletion", | |
1160 "frame_args", | |
1161 frame_args.AsValue()); | |
1162 scheduler->BeginFrame(frame_args); | |
1163 } | |
1154 EXPECT_TRUE(scheduler->CommitPending()); | 1164 EXPECT_TRUE(scheduler->CommitPending()); |
1155 | 1165 |
1156 // Draw and swap the frame, but don't ack the swap to simulate the Browser | 1166 // Draw and swap the frame, but don't ack the swap to simulate the Browser |
1157 // blocking on the renderer. | 1167 // blocking on the renderer. |
1158 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1168 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
1159 client.task_runner().RunPendingTasks(); // Run posted deadline. | 1169 client.task_runner().RunPendingTasks(); // Run posted deadline. |
1160 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 1170 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
1161 scheduler->DidSwapBuffers(); | 1171 scheduler->DidSwapBuffers(); |
1162 | 1172 |
1163 // Spin the event loop a few times and make sure we get more | 1173 // Spin the event loop a few times and make sure we get more |
1164 // DidAnticipateDrawTimeChange calls every time. | 1174 // DidAnticipateDrawTimeChange calls every time. |
1165 int actions_so_far = client.num_actions_(); | 1175 int actions_so_far = client.num_actions_(); |
1166 | 1176 |
1167 // Does three iterations to make sure that the timer is properly repeating. | 1177 // Does three iterations to make sure that the timer is properly repeating. |
1168 for (int i = 0; i < 3; ++i) { | 1178 for (int i = 0; i < 3; ++i) { |
1169 EXPECT_EQ((frame_args.interval * 2).InMicroseconds(), | 1179 EXPECT_EQ((frame_args.interval * 2).InMicroseconds(), |
1170 client.task_runner().NextPendingTaskDelay().InMicroseconds()) | 1180 client.task_runner().DelayToNextPendingTask().InMicroseconds()) |
1171 << scheduler->AsValue()->ToString(); | 1181 << scheduler->AsValue()->ToString(); |
1172 client.task_runner().RunPendingTasks(); | 1182 client.task_runner().RunPendingTasks(); |
1173 EXPECT_GT(client.num_actions_(), actions_so_far); | 1183 EXPECT_GT(client.num_actions_(), actions_so_far); |
1174 EXPECT_STREQ(client.Action(client.num_actions_() - 1), | 1184 EXPECT_STREQ(client.Action(client.num_actions_() - 1), |
1175 "DidAnticipatedDrawTimeChange"); | 1185 "DidAnticipatedDrawTimeChange"); |
1176 actions_so_far = client.num_actions_(); | 1186 actions_so_far = client.num_actions_(); |
1177 } | 1187 } |
1178 | 1188 |
1179 // Do the same thing after BeginMainFrame starts but still before activation. | 1189 // Do the same thing after BeginMainFrame starts but still before activation. |
1180 scheduler->NotifyBeginMainFrameStarted(); | 1190 scheduler->NotifyBeginMainFrameStarted(); |
1181 for (int i = 0; i < 3; ++i) { | 1191 for (int i = 0; i < 3; ++i) { |
1182 EXPECT_EQ((frame_args.interval * 2).InMicroseconds(), | 1192 EXPECT_EQ((frame_args.interval * 2).InMicroseconds(), |
1183 client.task_runner().NextPendingTaskDelay().InMicroseconds()) | 1193 client.task_runner().DelayToNextPendingTask().InMicroseconds()) |
1184 << scheduler->AsValue()->ToString(); | 1194 << scheduler->AsValue()->ToString(); |
1185 client.task_runner().RunPendingTasks(); | 1195 client.task_runner().RunPendingTasks(); |
1186 EXPECT_GT(client.num_actions_(), actions_so_far); | 1196 EXPECT_GT(client.num_actions_(), actions_so_far); |
1187 EXPECT_STREQ(client.Action(client.num_actions_() - 1), | 1197 EXPECT_STREQ(client.Action(client.num_actions_() - 1), |
1188 "DidAnticipatedDrawTimeChange"); | 1198 "DidAnticipatedDrawTimeChange"); |
1189 actions_so_far = client.num_actions_(); | 1199 actions_so_far = client.num_actions_(); |
1190 } | 1200 } |
1191 } | 1201 } |
1192 | 1202 |
1193 TEST(SchedulerTest, BeginRetroFrame) { | 1203 TEST(SchedulerTest, BeginRetroFrame) { |
1194 FakeSchedulerClient client; | 1204 FakeSchedulerClient client; |
1195 SchedulerSettings scheduler_settings; | 1205 SchedulerSettings scheduler_settings; |
1196 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings); | 1206 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings); |
1197 scheduler->SetCanStart(); | 1207 scheduler->SetCanStart(); |
1198 scheduler->SetVisible(true); | 1208 scheduler->SetVisible(true); |
1199 scheduler->SetCanDraw(true); | 1209 scheduler->SetCanDraw(true); |
1200 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | 1210 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
1201 | 1211 |
1202 // SetNeedsCommit should begin the frame on the next BeginImplFrame. | 1212 // SetNeedsCommit should begin the frame on the next BeginImplFrame. |
1203 client.Reset(); | 1213 client.Reset(); |
1204 scheduler->SetNeedsCommit(); | 1214 scheduler->SetNeedsCommit(); |
1205 EXPECT_TRUE(client.needs_begin_frame()); | 1215 EXPECT_TRUE(client.needs_begin_frame()); |
1206 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); | 1216 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); |
1207 client.Reset(); | 1217 client.Reset(); |
1208 | 1218 |
1209 // Create a BeginFrame with a long deadline to avoid race conditions. | 1219 // Create a BeginFrame with a long deadline to avoid race conditions. |
1210 // This is the first BeginFrame, which will be handled immediately. | 1220 // This is the first BeginFrame, which will be handled immediately. |
1211 BeginFrameArgs args = CreateBeginFrameArgsForTesting(); | 1221 BeginFrameArgs args = CreateBeginFrameArgsForTesting(client.now_src()); |
1212 args.deadline += base::TimeDelta::FromHours(1); | 1222 args.deadline += base::TimeDelta::FromHours(1); |
1213 scheduler->BeginFrame(args); | 1223 { |
1224 TRACE_EVENT1( | |
1225 "cc", "SchedulerTest::BeginRetroFrame", "frame_args", args.AsValue()); | |
1226 scheduler->BeginFrame(args); | |
1227 } | |
1214 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 1228 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
1215 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); | 1229 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); |
1216 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1230 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
1217 EXPECT_TRUE(client.needs_begin_frame()); | 1231 EXPECT_TRUE(client.needs_begin_frame()); |
1218 client.Reset(); | 1232 client.Reset(); |
1219 | 1233 |
1220 // Queue BeginFrames while we are still handling the previous BeginFrame. | 1234 // Queue BeginFrames while we are still handling the previous BeginFrame. |
1221 args.frame_time += base::TimeDelta::FromSeconds(1); | 1235 args.frame_time += base::TimeDelta::FromSeconds(1); |
1222 scheduler->BeginFrame(args); | 1236 { |
1237 TRACE_EVENT1( | |
1238 "cc", "SchedulerTest::BeginRetroFrame", "frame_args", args.AsValue()); | |
1239 scheduler->BeginFrame(args); | |
1240 } | |
1223 args.frame_time += base::TimeDelta::FromSeconds(1); | 1241 args.frame_time += base::TimeDelta::FromSeconds(1); |
1224 scheduler->BeginFrame(args); | 1242 { |
1243 TRACE_EVENT1( | |
1244 "cc", "SchedulerTest::BeginRetroFrame", "frame_args", args.AsValue()); | |
1245 scheduler->BeginFrame(args); | |
1246 } | |
1225 | 1247 |
1226 // If we don't swap on the deadline, we wait for the next BeginImplFrame. | 1248 // If we don't swap on the deadline, we wait for the next BeginImplFrame. |
1227 client.task_runner().RunPendingTasks(); // Run posted deadline. | 1249 client.task_runner().RunPendingTasks(); // Run posted deadline. |
1228 EXPECT_NO_ACTION(client); | 1250 EXPECT_NO_ACTION(client); |
1229 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 1251 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
1230 EXPECT_TRUE(client.needs_begin_frame()); | 1252 EXPECT_TRUE(client.needs_begin_frame()); |
1231 client.Reset(); | 1253 client.Reset(); |
1232 | 1254 |
1233 // NotifyReadyToCommit should trigger the commit. | 1255 // NotifyReadyToCommit should trigger the commit. |
1234 scheduler->NotifyBeginMainFrameStarted(); | 1256 scheduler->NotifyBeginMainFrameStarted(); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1280 | 1302 |
1281 // SetNeedsCommit should begin the frame on the next BeginImplFrame. | 1303 // SetNeedsCommit should begin the frame on the next BeginImplFrame. |
1282 client.Reset(); | 1304 client.Reset(); |
1283 scheduler->SetNeedsCommit(); | 1305 scheduler->SetNeedsCommit(); |
1284 EXPECT_TRUE(client.needs_begin_frame()); | 1306 EXPECT_TRUE(client.needs_begin_frame()); |
1285 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); | 1307 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); |
1286 client.Reset(); | 1308 client.Reset(); |
1287 | 1309 |
1288 // Create a BeginFrame with a long deadline to avoid race conditions. | 1310 // Create a BeginFrame with a long deadline to avoid race conditions. |
1289 // This is the first BeginFrame, which will be handled immediately. | 1311 // This is the first BeginFrame, which will be handled immediately. |
1290 BeginFrameArgs args = CreateBeginFrameArgsForTesting(); | 1312 BeginFrameArgs args = CreateBeginFrameArgsForTesting(client.now_src()); |
1291 args.deadline += base::TimeDelta::FromHours(1); | 1313 args.deadline += base::TimeDelta::FromHours(1); |
1292 scheduler->BeginFrame(args); | 1314 { |
1315 TRACE_EVENT1("cc", | |
1316 "SchedulerTest::BeginRetroFrame_SwapThrottled", | |
1317 "frame_args", | |
1318 args.AsValue()); | |
1319 scheduler->BeginFrame(args); | |
1320 } | |
1293 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 1321 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
1294 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); | 1322 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); |
1295 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1323 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
1296 EXPECT_TRUE(client.needs_begin_frame()); | 1324 EXPECT_TRUE(client.needs_begin_frame()); |
1297 client.Reset(); | 1325 client.Reset(); |
1298 | 1326 |
1299 // Queue BeginFrame while we are still handling the previous BeginFrame. | 1327 // Queue BeginFrame while we are still handling the previous BeginFrame. |
1300 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1328 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
1301 args.frame_time += base::TimeDelta::FromSeconds(1); | 1329 args.frame_time += base::TimeDelta::FromSeconds(1); |
1302 scheduler->BeginFrame(args); | 1330 { |
1331 TRACE_EVENT1("cc", | |
1332 "SchedulerTest::BeginRetroFrame_SwapThrottled", | |
1333 "frame_args", | |
1334 args.AsValue()); | |
1335 scheduler->BeginFrame(args); | |
1336 } | |
1303 EXPECT_NO_ACTION(client); | 1337 EXPECT_NO_ACTION(client); |
1304 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1338 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
1305 client.Reset(); | 1339 client.Reset(); |
1306 | 1340 |
1307 // NotifyReadyToCommit should trigger the pending commit and draw. | 1341 // NotifyReadyToCommit should trigger the pending commit and draw. |
1308 scheduler->NotifyBeginMainFrameStarted(); | 1342 scheduler->NotifyBeginMainFrameStarted(); |
1309 scheduler->NotifyReadyToCommit(); | 1343 scheduler->NotifyReadyToCommit(); |
1310 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); | 1344 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); |
1311 EXPECT_TRUE(client.needs_begin_frame()); | 1345 EXPECT_TRUE(client.needs_begin_frame()); |
1312 client.Reset(); | 1346 client.Reset(); |
(...skipping 10 matching lines...) Expand all Loading... | |
1323 // but not a BeginMainFrame or draw. | 1357 // but not a BeginMainFrame or draw. |
1324 scheduler->SetNeedsCommit(); | 1358 scheduler->SetNeedsCommit(); |
1325 client.task_runner().RunPendingTasks(); // Run posted BeginRetroFrame. | 1359 client.task_runner().RunPendingTasks(); // Run posted BeginRetroFrame. |
1326 EXPECT_ACTION("WillBeginImplFrame", client, 0, 1); | 1360 EXPECT_ACTION("WillBeginImplFrame", client, 0, 1); |
1327 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1361 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
1328 EXPECT_TRUE(client.needs_begin_frame()); | 1362 EXPECT_TRUE(client.needs_begin_frame()); |
1329 client.Reset(); | 1363 client.Reset(); |
1330 | 1364 |
1331 // Queue BeginFrame while we are still handling the previous BeginFrame. | 1365 // Queue BeginFrame while we are still handling the previous BeginFrame. |
1332 args.frame_time += base::TimeDelta::FromSeconds(1); | 1366 args.frame_time += base::TimeDelta::FromSeconds(1); |
1333 scheduler->BeginFrame(args); | 1367 { |
1368 TRACE_EVENT1("cc", | |
1369 "SchedulerTest::BeginRetroFrame_SwapThrottled", | |
1370 "frame_args", | |
1371 args.AsValue()); | |
1372 scheduler->BeginFrame(args); | |
1373 } | |
1334 EXPECT_NO_ACTION(client); | 1374 EXPECT_NO_ACTION(client); |
1335 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1375 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
1336 EXPECT_TRUE(client.needs_begin_frame()); | 1376 EXPECT_TRUE(client.needs_begin_frame()); |
1337 client.Reset(); | 1377 client.Reset(); |
1338 | 1378 |
1339 // Take us out of a swap throttled state. | 1379 // Take us out of a swap throttled state. |
1340 scheduler->DidSwapBuffersComplete(); | 1380 scheduler->DidSwapBuffersComplete(); |
1341 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 0, 1); | 1381 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 0, 1); |
1342 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1382 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
1343 EXPECT_TRUE(client.needs_begin_frame()); | 1383 EXPECT_TRUE(client.needs_begin_frame()); |
1344 client.Reset(); | 1384 client.Reset(); |
1345 | 1385 |
1346 // BeginImplFrame deadline should draw. | 1386 // BeginImplFrame deadline should draw. |
1347 scheduler->SetNeedsRedraw(); | 1387 scheduler->SetNeedsRedraw(); |
1348 client.task_runner().RunPendingTasks(); // Run posted deadline. | 1388 |
1389 EXPECT_TRUE(client.task_runner().RunTasksUntil( | |
1390 RunWhileImplFrameDeadlinePending(scheduler, false))); | |
1391 | |
1349 EXPECT_ACTION("ScheduledActionAnimate", client, 0, 2); | 1392 EXPECT_ACTION("ScheduledActionAnimate", client, 0, 2); |
1350 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 1, 2); | 1393 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 1, 2); |
1351 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 1394 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
1352 EXPECT_TRUE(client.needs_begin_frame()); | 1395 EXPECT_TRUE(client.needs_begin_frame()); |
1353 client.Reset(); | 1396 client.Reset(); |
1354 } | 1397 } |
1355 | 1398 |
1356 void BeginFramesNotFromClient(bool begin_frame_scheduling_enabled, | 1399 void BeginFramesNotFromClient(bool begin_frame_scheduling_enabled, |
1357 bool throttle_frame_production) { | 1400 bool throttle_frame_production) { |
1358 FakeSchedulerClient client; | 1401 FakeSchedulerClient client; |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1399 | 1442 |
1400 // BeginImplFrame should prepare the draw. | 1443 // BeginImplFrame should prepare the draw. |
1401 client.task_runner().RunPendingTasks(); // Run posted BeginFrame. | 1444 client.task_runner().RunPendingTasks(); // Run posted BeginFrame. |
1402 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 1445 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
1403 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); | 1446 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); |
1404 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1447 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
1405 EXPECT_FALSE(client.needs_begin_frame()); | 1448 EXPECT_FALSE(client.needs_begin_frame()); |
1406 client.Reset(); | 1449 client.Reset(); |
1407 | 1450 |
1408 // BeginImplFrame deadline should draw. | 1451 // BeginImplFrame deadline should draw. |
1409 client.task_runner().RunPendingTasks(); // Run posted deadline. | 1452 client.task_runner().RunTasksUntil( |
1453 RunWhileImplFrameDeadlinePending(scheduler, false)); | |
1410 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 1); | 1454 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 1); |
1411 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 1455 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
1412 EXPECT_FALSE(client.needs_begin_frame()); | 1456 EXPECT_FALSE(client.needs_begin_frame()); |
1413 client.Reset(); | 1457 client.Reset(); |
1414 | 1458 |
1415 // The following BeginImplFrame deadline should SetNeedsBeginFrame(false) | 1459 // The following BeginImplFrame deadline should SetNeedsBeginFrame(false) |
1416 // to avoid excessive toggles. | 1460 // to avoid excessive toggles. |
1417 client.task_runner().RunPendingTasks(); // Run posted BeginFrame. | 1461 client.task_runner().RunPendingTasks(); // Run posted BeginFrame. |
1418 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); | 1462 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); |
1419 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1463 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
1420 client.Reset(); | 1464 client.Reset(); |
1421 | 1465 |
1422 // Make sure SetNeedsBeginFrame isn't called on the client | 1466 // Make sure SetNeedsBeginFrame isn't called on the client |
1423 // when the BeginFrame is no longer needed. | 1467 // when the BeginFrame is no longer needed. |
1424 client.task_runner().RunPendingTasks(); // Run posted deadline. | 1468 client.task_runner().RunPendingTasks(); // Run posted deadline. |
1425 EXPECT_NO_ACTION(client); | 1469 EXPECT_NO_ACTION(client); |
1426 EXPECT_FALSE(client.needs_begin_frame()); | 1470 EXPECT_FALSE(client.needs_begin_frame()); |
1427 client.Reset(); | 1471 client.Reset(); |
1428 } | 1472 } |
1429 | 1473 |
1430 // See: http://crbug.com/380889 | 1474 TEST(SchedulerTest, SyntheticBeginFrames) { |
1431 TEST(SchedulerTest, DISABLED_SyntheticBeginFrames) { | |
1432 bool begin_frame_scheduling_enabled = false; | 1475 bool begin_frame_scheduling_enabled = false; |
1433 bool throttle_frame_production = true; | 1476 bool throttle_frame_production = true; |
1434 BeginFramesNotFromClient(begin_frame_scheduling_enabled, | 1477 BeginFramesNotFromClient(begin_frame_scheduling_enabled, |
1435 throttle_frame_production); | 1478 throttle_frame_production); |
1436 } | 1479 } |
1437 | 1480 |
1438 TEST(SchedulerTest, VSyncThrottlingDisabled) { | 1481 TEST(SchedulerTest, VSyncThrottlingDisabled) { |
1439 bool begin_frame_scheduling_enabled = true; | 1482 bool begin_frame_scheduling_enabled = true; |
1440 bool throttle_frame_production = false; | 1483 bool throttle_frame_production = false; |
1441 BeginFramesNotFromClient(begin_frame_scheduling_enabled, | 1484 BeginFramesNotFromClient(begin_frame_scheduling_enabled, |
1442 throttle_frame_production); | 1485 throttle_frame_production); |
1443 } | 1486 } |
1444 | 1487 |
1445 // See: http://crbug.com/380889 | 1488 TEST(SchedulerTest, SyntheticBeginFrames_And_VSyncThrottlingDisabled) { |
1446 TEST(SchedulerTest, DISABLED_SyntheticBeginFrames_And_VSyncThrottlingDisabled) { | |
1447 bool begin_frame_scheduling_enabled = false; | 1489 bool begin_frame_scheduling_enabled = false; |
1448 bool throttle_frame_production = false; | 1490 bool throttle_frame_production = false; |
1449 BeginFramesNotFromClient(begin_frame_scheduling_enabled, | 1491 BeginFramesNotFromClient(begin_frame_scheduling_enabled, |
1450 throttle_frame_production); | 1492 throttle_frame_production); |
1451 } | 1493 } |
1452 | 1494 |
1453 void BeginFramesNotFromClient_SwapThrottled(bool begin_frame_scheduling_enabled, | 1495 void BeginFramesNotFromClient_SwapThrottled(bool begin_frame_scheduling_enabled, |
1454 bool throttle_frame_production) { | 1496 bool throttle_frame_production) { |
1455 FakeSchedulerClient client; | 1497 FakeSchedulerClient client; |
1456 SchedulerSettings scheduler_settings; | 1498 SchedulerSettings scheduler_settings; |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1516 // BeginImplFrame deadline should draw. | 1558 // BeginImplFrame deadline should draw. |
1517 scheduler->SetNeedsRedraw(); | 1559 scheduler->SetNeedsRedraw(); |
1518 client.task_runner().RunPendingTasks(); // Run posted deadline. | 1560 client.task_runner().RunPendingTasks(); // Run posted deadline. |
1519 EXPECT_ACTION("ScheduledActionAnimate", client, 0, 2); | 1561 EXPECT_ACTION("ScheduledActionAnimate", client, 0, 2); |
1520 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 1, 2); | 1562 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 1, 2); |
1521 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 1563 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
1522 EXPECT_FALSE(client.needs_begin_frame()); | 1564 EXPECT_FALSE(client.needs_begin_frame()); |
1523 client.Reset(); | 1565 client.Reset(); |
1524 } | 1566 } |
1525 | 1567 |
1526 // See: http://crbug.com/380889 | 1568 TEST(SchedulerTest, SyntheticBeginFrames_SwapThrottled) { |
1527 TEST(SchedulerTest, DISABLED_SyntheticBeginFrames_SwapThrottled) { | |
1528 bool begin_frame_scheduling_enabled = false; | 1569 bool begin_frame_scheduling_enabled = false; |
1529 bool throttle_frame_production = true; | 1570 bool throttle_frame_production = true; |
1530 BeginFramesNotFromClient_SwapThrottled(begin_frame_scheduling_enabled, | 1571 BeginFramesNotFromClient_SwapThrottled(begin_frame_scheduling_enabled, |
1531 throttle_frame_production); | 1572 throttle_frame_production); |
1532 } | 1573 } |
1533 | 1574 |
1534 TEST(SchedulerTest, VSyncThrottlingDisabled_SwapThrottled) { | 1575 TEST(SchedulerTest, VSyncThrottlingDisabled_SwapThrottled) { |
1535 bool begin_frame_scheduling_enabled = true; | 1576 bool begin_frame_scheduling_enabled = true; |
1536 bool throttle_frame_production = false; | 1577 bool throttle_frame_production = false; |
1537 BeginFramesNotFromClient_SwapThrottled(begin_frame_scheduling_enabled, | 1578 BeginFramesNotFromClient_SwapThrottled(begin_frame_scheduling_enabled, |
1538 throttle_frame_production); | 1579 throttle_frame_production); |
1539 } | 1580 } |
1540 | 1581 |
1541 // See: http://crbug.com/380889 | |
1542 TEST(SchedulerTest, | 1582 TEST(SchedulerTest, |
1543 DISABLED_SyntheticBeginFrames_And_VSyncThrottlingDisabled_SwapThrottled) { | 1583 SyntheticBeginFrames_And_VSyncThrottlingDisabled_SwapThrottled) { |
1544 bool begin_frame_scheduling_enabled = false; | 1584 bool begin_frame_scheduling_enabled = false; |
1545 bool throttle_frame_production = false; | 1585 bool throttle_frame_production = false; |
1546 BeginFramesNotFromClient_SwapThrottled(begin_frame_scheduling_enabled, | 1586 BeginFramesNotFromClient_SwapThrottled(begin_frame_scheduling_enabled, |
1547 throttle_frame_production); | 1587 throttle_frame_production); |
1548 } | 1588 } |
1549 | 1589 |
1550 TEST(SchedulerTest, DidLoseOutputSurfaceAfterOutputSurfaceIsInitialized) { | 1590 TEST(SchedulerTest, DidLoseOutputSurfaceAfterOutputSurfaceIsInitialized) { |
1551 FakeSchedulerClient client; | 1591 FakeSchedulerClient client; |
1552 SchedulerSettings scheduler_settings; | 1592 SchedulerSettings scheduler_settings; |
1553 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings); | 1593 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings); |
(...skipping 19 matching lines...) Expand all Loading... | |
1573 scheduler->SetCanDraw(true); | 1613 scheduler->SetCanDraw(true); |
1574 | 1614 |
1575 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); | 1615 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); |
1576 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | 1616 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
1577 // SetNeedsCommit should begin the frame. | 1617 // SetNeedsCommit should begin the frame. |
1578 client.Reset(); | 1618 client.Reset(); |
1579 scheduler->SetNeedsCommit(); | 1619 scheduler->SetNeedsCommit(); |
1580 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); | 1620 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); |
1581 | 1621 |
1582 client.Reset(); | 1622 client.Reset(); |
1583 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | 1623 client.AdvanceFrame(); |
1584 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 1624 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
1585 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); | 1625 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); |
1586 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1626 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
1587 | 1627 |
1588 client.Reset(); | 1628 client.Reset(); |
1589 scheduler->DidLoseOutputSurface(); | 1629 scheduler->DidLoseOutputSurface(); |
1590 // Do nothing when impl frame is in deadine pending state. | 1630 // Do nothing when impl frame is in deadine pending state. |
1591 EXPECT_NO_ACTION(client); | 1631 EXPECT_NO_ACTION(client); |
1592 | 1632 |
1593 client.Reset(); | 1633 client.Reset(); |
(...skipping 18 matching lines...) Expand all Loading... | |
1612 | 1652 |
1613 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); | 1653 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); |
1614 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | 1654 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
1615 | 1655 |
1616 // SetNeedsCommit should begin the frame. | 1656 // SetNeedsCommit should begin the frame. |
1617 client.Reset(); | 1657 client.Reset(); |
1618 scheduler->SetNeedsCommit(); | 1658 scheduler->SetNeedsCommit(); |
1619 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); | 1659 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); |
1620 | 1660 |
1621 client.Reset(); | 1661 client.Reset(); |
1622 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | 1662 client.AdvanceFrame(); |
1623 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 1663 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
1624 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); | 1664 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); |
1625 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1665 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
1626 | 1666 |
1627 client.Reset(); | 1667 client.Reset(); |
1628 scheduler->DidLoseOutputSurface(); | 1668 scheduler->DidLoseOutputSurface(); |
1629 // Do nothing when impl frame is in deadine pending state. | 1669 // Do nothing when impl frame is in deadine pending state. |
1630 EXPECT_NO_ACTION(client); | 1670 EXPECT_NO_ACTION(client); |
1631 | 1671 |
1632 client.Reset(); | 1672 client.Reset(); |
1633 client.task_runner().RunPendingTasks(); // Run posted deadline. | 1673 // Run posted deadline. |
1674 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | |
1675 client.task_runner().RunTasksUntil( | |
1676 RunWhileImplFrameDeadlinePending(scheduler, false)); | |
1634 // OnBeginImplFrameDeadline didn't schedule any actions because main frame is | 1677 // OnBeginImplFrameDeadline didn't schedule any actions because main frame is |
1635 // not yet completed. | 1678 // not yet completed. |
1636 EXPECT_NO_ACTION(client); | 1679 EXPECT_NO_ACTION(client); |
1637 | 1680 |
1638 // BeginImplFrame is not started. | 1681 // BeginImplFrame is not started. |
1639 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | 1682 client.task_runner().RunUntilTime(client.now_src()->Now() + |
1683 base::TimeDelta::FromMilliseconds(10)); | |
1640 EXPECT_NO_ACTION(client); | 1684 EXPECT_NO_ACTION(client); |
1641 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 1685 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
1642 | 1686 |
1643 client.Reset(); | 1687 client.Reset(); |
1644 scheduler->NotifyBeginMainFrameStarted(); | 1688 scheduler->NotifyBeginMainFrameStarted(); |
1645 scheduler->NotifyReadyToCommit(); | 1689 scheduler->NotifyReadyToCommit(); |
1646 if (impl_side_painting) { | 1690 if (impl_side_painting) { |
1647 EXPECT_ACTION("ScheduledActionCommit", client, 0, 3); | 1691 EXPECT_ACTION("ScheduledActionCommit", client, 0, 3); |
1648 EXPECT_ACTION("ScheduledActionActivateSyncTree", client, 1, 3); | 1692 EXPECT_ACTION("ScheduledActionActivateSyncTree", client, 1, 3); |
1649 EXPECT_ACTION("ScheduledActionBeginOutputSurfaceCreation", client, 2, 3); | 1693 EXPECT_ACTION("ScheduledActionBeginOutputSurfaceCreation", client, 2, 3); |
(...skipping 25 matching lines...) Expand all Loading... | |
1675 | 1719 |
1676 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); | 1720 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); |
1677 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | 1721 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
1678 | 1722 |
1679 // SetNeedsCommit should begin the frame. | 1723 // SetNeedsCommit should begin the frame. |
1680 client.Reset(); | 1724 client.Reset(); |
1681 scheduler->SetNeedsCommit(); | 1725 scheduler->SetNeedsCommit(); |
1682 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); | 1726 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); |
1683 | 1727 |
1684 client.Reset(); | 1728 client.Reset(); |
1685 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | 1729 client.AdvanceFrame(); |
1686 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 1730 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
1687 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); | 1731 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); |
1688 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1732 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
1689 | 1733 |
1690 client.Reset(); | 1734 client.Reset(); |
1691 scheduler->NotifyBeginMainFrameStarted(); | 1735 scheduler->NotifyBeginMainFrameStarted(); |
1692 scheduler->NotifyReadyToCommit(); | 1736 scheduler->NotifyReadyToCommit(); |
1693 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); | 1737 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); |
1694 | 1738 |
1695 client.Reset(); | 1739 client.Reset(); |
(...skipping 28 matching lines...) Expand all Loading... | |
1724 scheduler->SetCanDraw(true); | 1768 scheduler->SetCanDraw(true); |
1725 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | 1769 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
1726 | 1770 |
1727 client.Reset(); | 1771 client.Reset(); |
1728 scheduler->SetNeedsManageTiles(); | 1772 scheduler->SetNeedsManageTiles(); |
1729 scheduler->SetNeedsRedraw(); | 1773 scheduler->SetNeedsRedraw(); |
1730 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); | 1774 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); |
1731 EXPECT_TRUE(client.needs_begin_frame()); | 1775 EXPECT_TRUE(client.needs_begin_frame()); |
1732 | 1776 |
1733 client.Reset(); | 1777 client.Reset(); |
1734 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | 1778 client.AdvanceFrame(); |
1735 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 1779 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
1736 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); | 1780 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); |
1737 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1781 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
1738 | 1782 |
1739 client.Reset(); | 1783 client.Reset(); |
1740 scheduler->DidLoseOutputSurface(); | 1784 scheduler->DidLoseOutputSurface(); |
1741 EXPECT_NO_ACTION(client); | 1785 EXPECT_NO_ACTION(client); |
1742 | 1786 |
1743 client.Reset(); | 1787 client.Reset(); |
1744 client.task_runner().RunPendingTasks(); // Run posted deadline. | 1788 client.task_runner().RunPendingTasks(); // Run posted deadline. |
(...skipping 12 matching lines...) Expand all Loading... | |
1757 | 1801 |
1758 // SetNeedsCommit should begin the frame on the next BeginImplFrame. | 1802 // SetNeedsCommit should begin the frame on the next BeginImplFrame. |
1759 client.Reset(); | 1803 client.Reset(); |
1760 scheduler->SetNeedsCommit(); | 1804 scheduler->SetNeedsCommit(); |
1761 EXPECT_TRUE(client.needs_begin_frame()); | 1805 EXPECT_TRUE(client.needs_begin_frame()); |
1762 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); | 1806 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); |
1763 | 1807 |
1764 // Create a BeginFrame with a long deadline to avoid race conditions. | 1808 // Create a BeginFrame with a long deadline to avoid race conditions. |
1765 // This is the first BeginFrame, which will be handled immediately. | 1809 // This is the first BeginFrame, which will be handled immediately. |
1766 client.Reset(); | 1810 client.Reset(); |
1767 BeginFrameArgs args = CreateBeginFrameArgsForTesting(); | 1811 BeginFrameArgs args = CreateBeginFrameArgsForTesting(client.now_src()); |
1768 args.deadline += base::TimeDelta::FromHours(1); | 1812 args.deadline += base::TimeDelta::FromHours(1); |
1769 scheduler->BeginFrame(args); | 1813 { |
1814 TRACE_EVENT1( | |
1815 "cc", | |
1816 "SchedulerTest::DidLoseOutputSurfaceAfterBeginRetroFramePosted", | |
1817 "frame_args", | |
1818 args.AsValue()); | |
1819 scheduler->BeginFrame(args); | |
1820 } | |
1770 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 1821 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
1771 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); | 1822 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); |
1772 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1823 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
1773 EXPECT_TRUE(client.needs_begin_frame()); | 1824 EXPECT_TRUE(client.needs_begin_frame()); |
1774 | 1825 |
1775 // Queue BeginFrames while we are still handling the previous BeginFrame. | 1826 // Queue BeginFrames while we are still handling the previous BeginFrame. |
1776 args.frame_time += base::TimeDelta::FromSeconds(1); | 1827 args.frame_time += base::TimeDelta::FromSeconds(1); |
1777 scheduler->BeginFrame(args); | 1828 { |
1829 TRACE_EVENT1( | |
1830 "cc", | |
1831 "SchedulerTest::DidLoseOutputSurfaceAfterBeginRetroFramePosted", | |
1832 "frame_args", | |
1833 args.AsValue()); | |
1834 scheduler->BeginFrame(args); | |
1835 } | |
1778 args.frame_time += base::TimeDelta::FromSeconds(1); | 1836 args.frame_time += base::TimeDelta::FromSeconds(1); |
1779 scheduler->BeginFrame(args); | 1837 { |
1838 TRACE_EVENT1( | |
1839 "cc", | |
1840 "SchedulerTest::DidLoseOutputSurfaceAfterBeginRetroFramePosted", | |
1841 "frame_args", | |
1842 args.AsValue()); | |
1843 scheduler->BeginFrame(args); | |
1844 } | |
1780 | 1845 |
1781 // If we don't swap on the deadline, we wait for the next BeginImplFrame. | 1846 // If we don't swap on the deadline, we wait for the next BeginImplFrame. |
1782 client.Reset(); | 1847 client.Reset(); |
1783 client.task_runner().RunPendingTasks(); // Run posted deadline. | 1848 client.task_runner().RunPendingTasks(); // Run posted deadline. |
1784 EXPECT_NO_ACTION(client); | 1849 EXPECT_NO_ACTION(client); |
1785 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 1850 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
1786 EXPECT_TRUE(client.needs_begin_frame()); | 1851 EXPECT_TRUE(client.needs_begin_frame()); |
1787 | 1852 |
1788 // NotifyReadyToCommit should trigger the commit. | 1853 // NotifyReadyToCommit should trigger the commit. |
1789 client.Reset(); | 1854 client.Reset(); |
(...skipping 26 matching lines...) Expand all Loading... | |
1816 | 1881 |
1817 // SetNeedsCommit should begin the frame on the next BeginImplFrame. | 1882 // SetNeedsCommit should begin the frame on the next BeginImplFrame. |
1818 client.Reset(); | 1883 client.Reset(); |
1819 scheduler->SetNeedsCommit(); | 1884 scheduler->SetNeedsCommit(); |
1820 EXPECT_TRUE(client.needs_begin_frame()); | 1885 EXPECT_TRUE(client.needs_begin_frame()); |
1821 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); | 1886 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); |
1822 | 1887 |
1823 // Create a BeginFrame with a long deadline to avoid race conditions. | 1888 // Create a BeginFrame with a long deadline to avoid race conditions. |
1824 // This is the first BeginFrame, which will be handled immediately. | 1889 // This is the first BeginFrame, which will be handled immediately. |
1825 client.Reset(); | 1890 client.Reset(); |
1826 BeginFrameArgs args = CreateBeginFrameArgsForTesting(); | 1891 BeginFrameArgs args = CreateBeginFrameArgsForTesting(client.now_src()); |
1827 args.deadline += base::TimeDelta::FromHours(1); | 1892 args.deadline += base::TimeDelta::FromHours(1); |
1828 scheduler->BeginFrame(args); | 1893 { |
1894 TRACE_EVENT1( | |
1895 "cc", | |
1896 "SchedulerTest::DidLoseOutputSurfaceDuringBeginRetroFrameRunning", | |
1897 "frame_args", | |
1898 args.AsValue()); | |
1899 scheduler->BeginFrame(args); | |
1900 } | |
1829 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 1901 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
1830 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); | 1902 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); |
1831 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1903 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
1832 EXPECT_TRUE(client.needs_begin_frame()); | 1904 EXPECT_TRUE(client.needs_begin_frame()); |
1833 | 1905 |
1834 // Queue BeginFrames while we are still handling the previous BeginFrame. | 1906 // Queue BeginFrames while we are still handling the previous BeginFrame. |
1835 args.frame_time += base::TimeDelta::FromSeconds(1); | 1907 args.frame_time += base::TimeDelta::FromSeconds(1); |
1836 scheduler->BeginFrame(args); | 1908 { |
1909 TRACE_EVENT1( | |
1910 "cc", | |
1911 "SchedulerTest::DidLoseOutputSurfaceDuringBeginRetroFrameRunning", | |
1912 "frame_args", | |
1913 args.AsValue()); | |
1914 scheduler->BeginFrame(args); | |
1915 } | |
1837 args.frame_time += base::TimeDelta::FromSeconds(1); | 1916 args.frame_time += base::TimeDelta::FromSeconds(1); |
1838 scheduler->BeginFrame(args); | 1917 { |
1918 TRACE_EVENT1( | |
1919 "cc", | |
1920 "SchedulerTest::DidLoseOutputSurfaceDuringBeginRetroFrameRunning", | |
1921 "frame_args", | |
1922 args.AsValue()); | |
1923 scheduler->BeginFrame(args); | |
1924 } | |
1839 | 1925 |
1840 // If we don't swap on the deadline, we wait for the next BeginImplFrame. | 1926 // If we don't swap on the deadline, we wait for the next BeginImplFrame. |
1841 client.Reset(); | 1927 client.Reset(); |
1842 client.task_runner().RunPendingTasks(); // Run posted deadline. | 1928 client.task_runner().RunPendingTasks(); // Run posted deadline. |
1843 EXPECT_NO_ACTION(client); | 1929 EXPECT_NO_ACTION(client); |
1844 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 1930 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
1845 EXPECT_TRUE(client.needs_begin_frame()); | 1931 EXPECT_TRUE(client.needs_begin_frame()); |
1846 | 1932 |
1847 // NotifyReadyToCommit should trigger the commit. | 1933 // NotifyReadyToCommit should trigger the commit. |
1848 client.Reset(); | 1934 client.Reset(); |
(...skipping 22 matching lines...) Expand all Loading... | |
1871 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); | 1957 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); |
1872 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 1958 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
1873 EXPECT_TRUE(client.needs_begin_frame()); | 1959 EXPECT_TRUE(client.needs_begin_frame()); |
1874 | 1960 |
1875 // No more BeginRetroFrame because BeginRetroFrame queue is cleared. | 1961 // No more BeginRetroFrame because BeginRetroFrame queue is cleared. |
1876 client.Reset(); | 1962 client.Reset(); |
1877 client.task_runner().RunPendingTasks(); | 1963 client.task_runner().RunPendingTasks(); |
1878 EXPECT_NO_ACTION(client); | 1964 EXPECT_NO_ACTION(client); |
1879 } | 1965 } |
1880 | 1966 |
1881 // See: http://crbug.com/380889 | 1967 TEST(SchedulerTest, |
1882 TEST( | 1968 StopBeginFrameAfterDidLoseOutputSurfaceWithSyntheticBeginFrameSource) { |
1883 SchedulerTest, | |
1884 DISABLED_StopBeginFrameAfterDidLoseOutputSurfaceWithSyntheticBeginFrameSourc e) { | |
1885 FakeSchedulerClient client; | 1969 FakeSchedulerClient client; |
1886 SchedulerSettings scheduler_settings; | 1970 SchedulerSettings scheduler_settings; |
1887 scheduler_settings.begin_frame_scheduling_enabled = false; | 1971 scheduler_settings.begin_frame_scheduling_enabled = false; |
1888 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings); | 1972 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings); |
1889 scheduler->SetCanStart(); | 1973 scheduler->SetCanStart(); |
1890 scheduler->SetVisible(true); | 1974 scheduler->SetVisible(true); |
1891 scheduler->SetCanDraw(true); | 1975 scheduler->SetCanDraw(true); |
1892 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | 1976 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
1893 | 1977 |
1894 // SetNeedsCommit should begin the frame on the next BeginImplFrame. | 1978 // SetNeedsCommit should begin the frame on the next BeginImplFrame. |
(...skipping 22 matching lines...) Expand all Loading... | |
1917 EXPECT_FALSE(scheduler->IsSyntheticBeginFrameSourceActive()); | 2001 EXPECT_FALSE(scheduler->IsSyntheticBeginFrameSourceActive()); |
1918 | 2002 |
1919 client.Reset(); | 2003 client.Reset(); |
1920 client.task_runner().RunPendingTasks(); // Run posted deadline. | 2004 client.task_runner().RunPendingTasks(); // Run posted deadline. |
1921 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); | 2005 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); |
1922 EXPECT_FALSE(scheduler->IsSyntheticBeginFrameSourceActive()); | 2006 EXPECT_FALSE(scheduler->IsSyntheticBeginFrameSourceActive()); |
1923 } | 2007 } |
1924 | 2008 |
1925 } // namespace | 2009 } // namespace |
1926 } // namespace cc | 2010 } // namespace cc |
OLD | NEW |