OLD | NEW |
1 // Copyright 2011 The Chromium Authors. All rights reserved. | 1 // Copyright 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 #include "cc/scheduler/scheduler.h" | 4 #include "cc/scheduler/scheduler.h" |
5 | 5 |
6 #include <string> | 6 #include <string> |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/debug/trace_event.h" | 9 #include "base/debug/trace_event.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 25 matching lines...) Expand all Loading... |
36 EXPECT_ACTION(action, client, 0, 1) | 36 EXPECT_ACTION(action, client, 0, 1) |
37 | 37 |
38 namespace cc { | 38 namespace cc { |
39 namespace { | 39 namespace { |
40 | 40 |
41 class FakeSchedulerClient; | 41 class FakeSchedulerClient; |
42 | 42 |
43 void InitializeOutputSurfaceAndFirstCommit(Scheduler* scheduler, | 43 void InitializeOutputSurfaceAndFirstCommit(Scheduler* scheduler, |
44 FakeSchedulerClient* client); | 44 FakeSchedulerClient* client); |
45 | 45 |
46 class TestScheduler : public Scheduler { | |
47 public: | |
48 static scoped_ptr<TestScheduler> Create( | |
49 SchedulerClient* client, | |
50 const SchedulerSettings& scheduler_settings, | |
51 int layer_tree_host_id, | |
52 const scoped_refptr<base::SingleThreadTaskRunner>& impl_task_runner) { | |
53 return make_scoped_ptr(new TestScheduler( | |
54 client, scheduler_settings, layer_tree_host_id, impl_task_runner)); | |
55 } | |
56 | |
57 virtual ~TestScheduler() {} | |
58 | |
59 bool IsBeginRetroFrameArgsEmpty() const { | |
60 return begin_retro_frame_args_.empty(); | |
61 } | |
62 | |
63 bool IsSyntheticBeginFrameSourceActive() const { | |
64 return synthetic_begin_frame_source_->IsActive(); | |
65 } | |
66 | |
67 private: | |
68 TestScheduler( | |
69 SchedulerClient* client, | |
70 const SchedulerSettings& scheduler_settings, | |
71 int layer_tree_host_id, | |
72 const scoped_refptr<base::SingleThreadTaskRunner> & impl_task_runner) | |
73 : Scheduler(client, | |
74 scheduler_settings, | |
75 layer_tree_host_id, | |
76 impl_task_runner) { | |
77 } | |
78 }; | |
79 | |
80 class FakeSchedulerClient : public SchedulerClient { | 46 class FakeSchedulerClient : public SchedulerClient { |
81 public: | 47 public: |
82 FakeSchedulerClient() | 48 FakeSchedulerClient() |
83 : needs_begin_frame_(false), | 49 : needs_begin_frame_(false), |
84 automatic_swap_ack_(true), | 50 automatic_swap_ack_(true), |
85 swap_contains_incomplete_tile_(false), | 51 swap_contains_incomplete_tile_(false), |
86 redraw_will_happen_if_update_visible_tiles_happens_(false) { | 52 redraw_will_happen_if_update_visible_tiles_happens_(false), |
| 53 now_src_(TestNowSource::Create()) { |
87 Reset(); | 54 Reset(); |
88 } | 55 } |
89 | 56 |
90 void Reset() { | 57 void Reset() { |
91 actions_.clear(); | 58 actions_.clear(); |
92 states_.clear(); | 59 states_.clear(); |
93 draw_will_happen_ = true; | 60 draw_will_happen_ = true; |
94 swap_will_happen_if_draw_happens_ = true; | 61 swap_will_happen_if_draw_happens_ = true; |
95 num_draws_ = 0; | 62 num_draws_ = 0; |
96 log_anticipated_draw_time_change_ = false; | 63 log_anticipated_draw_time_change_ = false; |
97 } | 64 } |
98 | 65 |
99 TestScheduler* CreateScheduler(const SchedulerSettings& settings) { | 66 TestScheduler* CreateScheduler(const SchedulerSettings& settings) { |
100 task_runner_ = new OrderedSimpleTaskRunner; | 67 scheduler_ = TestScheduler::Create(now_src_, this, settings, 0); |
101 scheduler_ = TestScheduler::Create(this, settings, 0, task_runner_); | |
102 return scheduler_.get(); | 68 return scheduler_.get(); |
103 } | 69 } |
104 | 70 |
105 // Most tests don't care about DidAnticipatedDrawTimeChange, so only record it | 71 // Most tests don't care about DidAnticipatedDrawTimeChange, so only record it |
106 // for tests that do. | 72 // for tests that do. |
107 void set_log_anticipated_draw_time_change(bool log) { | 73 void set_log_anticipated_draw_time_change(bool log) { |
108 log_anticipated_draw_time_change_ = log; | 74 log_anticipated_draw_time_change_ = log; |
109 } | 75 } |
110 bool needs_begin_frame() { return needs_begin_frame_; } | 76 bool needs_begin_frame() { return needs_begin_frame_; } |
111 int num_draws() const { return num_draws_; } | 77 int num_draws() const { return num_draws_; } |
112 int num_actions_() const { return static_cast<int>(actions_.size()); } | 78 int num_actions_() const { return static_cast<int>(actions_.size()); } |
113 const char* Action(int i) const { return actions_[i]; } | 79 const char* Action(int i) const { return actions_[i]; } |
114 std::string StateForAction(int i) const { return states_[i]->ToString(); } | 80 std::string StateForAction(int i) const { return states_[i]->ToString(); } |
115 base::TimeTicks posted_begin_impl_frame_deadline() const { | 81 base::TimeTicks posted_begin_impl_frame_deadline() const { |
116 return posted_begin_impl_frame_deadline_; | 82 return posted_begin_impl_frame_deadline_; |
117 } | 83 } |
118 | 84 |
119 OrderedSimpleTaskRunner& task_runner() { return *task_runner_; } | 85 void AdvanceFrame() { |
| 86 bool external_begin_frame = |
| 87 scheduler_->settings().begin_frame_scheduling_enabled && |
| 88 scheduler_->settings().throttle_frame_production; |
| 89 |
| 90 if (external_begin_frame) { |
| 91 TRACE_EVENT1("cc", |
| 92 "SchedulerUnitTest::AdvanceFrame", |
| 93 "external_begin_frame", |
| 94 external_begin_frame); |
| 95 scheduler_->BeginFrame(CreateBeginFrameArgsForTesting(now_src_)); |
| 96 } else { |
| 97 task_runner().RunPendingTasks(); |
| 98 } |
| 99 } |
| 100 |
| 101 OrderedSimpleTaskRunner& task_runner() { return scheduler_->task_runner(); } |
| 102 scoped_refptr<TestNowSource> now_src() { return now_src_; } |
120 | 103 |
121 int ActionIndex(const char* action) const { | 104 int ActionIndex(const char* action) const { |
122 for (size_t i = 0; i < actions_.size(); i++) | 105 for (size_t i = 0; i < actions_.size(); i++) |
123 if (!strcmp(actions_[i], action)) | 106 if (!strcmp(actions_[i], action)) |
124 return i; | 107 return i; |
125 return -1; | 108 return -1; |
126 } | 109 } |
127 | 110 |
128 void SetSwapContainsIncompleteTile(bool contain) { | 111 void SetSwapContainsIncompleteTile(bool contain) { |
129 swap_contains_incomplete_tile_ = contain; | 112 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_; | 217 bool swap_will_happen_if_draw_happens_; |
235 bool automatic_swap_ack_; | 218 bool automatic_swap_ack_; |
236 int num_draws_; | 219 int num_draws_; |
237 bool log_anticipated_draw_time_change_; | 220 bool log_anticipated_draw_time_change_; |
238 bool swap_contains_incomplete_tile_; | 221 bool swap_contains_incomplete_tile_; |
239 bool redraw_will_happen_if_update_visible_tiles_happens_; | 222 bool redraw_will_happen_if_update_visible_tiles_happens_; |
240 base::TimeTicks posted_begin_impl_frame_deadline_; | 223 base::TimeTicks posted_begin_impl_frame_deadline_; |
241 std::vector<const char*> actions_; | 224 std::vector<const char*> actions_; |
242 std::vector<scoped_refptr<base::debug::ConvertableToTraceFormat> > states_; | 225 std::vector<scoped_refptr<base::debug::ConvertableToTraceFormat> > states_; |
243 scoped_ptr<TestScheduler> scheduler_; | 226 scoped_ptr<TestScheduler> scheduler_; |
244 scoped_refptr<OrderedSimpleTaskRunner> task_runner_; | 227 scoped_refptr<TestNowSource> now_src_; |
245 }; | 228 }; |
246 | 229 |
247 void InitializeOutputSurfaceAndFirstCommit(Scheduler* scheduler, | 230 void InitializeOutputSurfaceAndFirstCommit(Scheduler* scheduler, |
248 FakeSchedulerClient* client) { | 231 FakeSchedulerClient* client) { |
249 bool client_initiates_begin_frame = | 232 TRACE_EVENT0("cc", |
250 scheduler->settings().begin_frame_scheduling_enabled && | 233 "SchedulerUnitTest::InitializeOutputSurfaceAndFirstCommit"); |
251 scheduler->settings().throttle_frame_production; | |
252 | 234 |
253 scheduler->DidCreateAndInitializeOutputSurface(); | 235 scheduler->DidCreateAndInitializeOutputSurface(); |
254 scheduler->SetNeedsCommit(); | 236 scheduler->SetNeedsCommit(); |
255 scheduler->NotifyBeginMainFrameStarted(); | 237 scheduler->NotifyBeginMainFrameStarted(); |
256 scheduler->NotifyReadyToCommit(); | 238 scheduler->NotifyReadyToCommit(); |
257 if (scheduler->settings().impl_side_painting) | 239 if (scheduler->settings().impl_side_painting) |
258 scheduler->NotifyReadyToActivate(); | 240 scheduler->NotifyReadyToActivate(); |
| 241 |
259 // Go through the motions to draw the commit. | 242 // Go through the motions to draw the commit. |
260 if (client_initiates_begin_frame) | 243 client->AdvanceFrame(); |
261 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | |
262 else | |
263 client->task_runner().RunPendingTasks(); // Run posted BeginFrame. | |
264 | 244 |
265 // Run the posted deadline task. | 245 // Run the posted deadline task. |
266 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 246 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
267 client->task_runner().RunPendingTasks(); | 247 client->task_runner().RunPendingTasks(); |
268 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | |
269 | 248 |
270 // We need another BeginImplFrame so Scheduler calls | 249 // We need another BeginImplFrame so Scheduler calls |
271 // SetNeedsBeginFrame(false). | 250 // SetNeedsBeginFrame(false). |
272 if (client_initiates_begin_frame) | 251 client->AdvanceFrame(); |
273 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | |
274 else | |
275 client->task_runner().RunPendingTasks(); // Run posted BeginFrame. | |
276 | 252 |
277 // Run the posted deadline task. | 253 // Run the posted deadline task. |
278 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | |
279 client->task_runner().RunPendingTasks(); | 254 client->task_runner().RunPendingTasks(); |
280 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 255 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
281 } | 256 } |
282 | 257 |
283 TEST(SchedulerTest, InitializeOutputSurfaceDoesNotBeginImplFrame) { | 258 TEST(SchedulerTest, InitializeOutputSurfaceDoesNotBeginImplFrame) { |
284 FakeSchedulerClient client; | 259 FakeSchedulerClient client; |
285 SchedulerSettings default_scheduler_settings; | 260 SchedulerSettings default_scheduler_settings; |
286 TestScheduler* scheduler = client.CreateScheduler(default_scheduler_settings); | 261 TestScheduler* scheduler = client.CreateScheduler(default_scheduler_settings); |
287 scheduler->SetCanStart(); | 262 scheduler->SetCanStart(); |
288 scheduler->SetVisible(true); | 263 scheduler->SetVisible(true); |
(...skipping 16 matching lines...) Expand all Loading... |
305 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); | 280 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); |
306 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | 281 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
307 | 282 |
308 // SetNeedsCommit should begin the frame on the next BeginImplFrame. | 283 // SetNeedsCommit should begin the frame on the next BeginImplFrame. |
309 client.Reset(); | 284 client.Reset(); |
310 scheduler->SetNeedsCommit(); | 285 scheduler->SetNeedsCommit(); |
311 EXPECT_TRUE(client.needs_begin_frame()); | 286 EXPECT_TRUE(client.needs_begin_frame()); |
312 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); | 287 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); |
313 client.Reset(); | 288 client.Reset(); |
314 | 289 |
315 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | 290 client.AdvanceFrame(); |
316 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 291 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
317 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); | 292 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); |
318 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 293 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
319 EXPECT_TRUE(client.needs_begin_frame()); | 294 EXPECT_TRUE(client.needs_begin_frame()); |
320 client.Reset(); | 295 client.Reset(); |
321 | 296 |
322 // If we don't swap on the deadline, we wait for the next BeginFrame. | 297 // If we don't swap on the deadline, we wait for the next BeginFrame. |
323 client.task_runner().RunPendingTasks(); // Run posted deadline. | 298 client.task_runner().RunPendingTasks(); // Run posted deadline. |
324 EXPECT_NO_ACTION(client); | 299 EXPECT_NO_ACTION(client); |
325 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 300 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
326 EXPECT_TRUE(client.needs_begin_frame()); | 301 EXPECT_TRUE(client.needs_begin_frame()); |
327 client.Reset(); | 302 client.Reset(); |
328 | 303 |
329 // NotifyReadyToCommit should trigger the commit. | 304 // NotifyReadyToCommit should trigger the commit. |
330 scheduler->NotifyBeginMainFrameStarted(); | 305 scheduler->NotifyBeginMainFrameStarted(); |
331 scheduler->NotifyReadyToCommit(); | 306 scheduler->NotifyReadyToCommit(); |
332 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); | 307 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); |
333 EXPECT_TRUE(client.needs_begin_frame()); | 308 EXPECT_TRUE(client.needs_begin_frame()); |
334 client.Reset(); | 309 client.Reset(); |
335 | 310 |
336 // BeginImplFrame should prepare the draw. | 311 // BeginImplFrame should prepare the draw. |
337 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | 312 client.AdvanceFrame(); |
338 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 313 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
339 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); | 314 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); |
340 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 315 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
341 EXPECT_TRUE(client.needs_begin_frame()); | 316 EXPECT_TRUE(client.needs_begin_frame()); |
342 client.Reset(); | 317 client.Reset(); |
343 | 318 |
344 // BeginImplFrame deadline should draw. | 319 // BeginImplFrame deadline should draw. |
345 client.task_runner().RunPendingTasks(); // Run posted deadline. | 320 client.task_runner().RunPendingTasks(); // Run posted deadline. |
346 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 1); | 321 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 1); |
347 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 322 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
348 EXPECT_TRUE(client.needs_begin_frame()); | 323 EXPECT_TRUE(client.needs_begin_frame()); |
349 client.Reset(); | 324 client.Reset(); |
350 | 325 |
351 // The following BeginImplFrame deadline should SetNeedsBeginFrame(false) | 326 // The following BeginImplFrame deadline should SetNeedsBeginFrame(false) |
352 // to avoid excessive toggles. | 327 // to avoid excessive toggles. |
353 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | 328 client.AdvanceFrame(); |
354 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); | 329 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); |
355 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 330 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
356 client.Reset(); | 331 client.Reset(); |
357 | 332 |
358 client.task_runner().RunPendingTasks(); // Run posted deadline. | 333 client.task_runner().RunPendingTasks(); // Run posted deadline. |
359 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); | 334 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); |
360 EXPECT_FALSE(client.needs_begin_frame()); | 335 EXPECT_FALSE(client.needs_begin_frame()); |
361 client.Reset(); | 336 client.Reset(); |
362 } | 337 } |
363 | 338 |
364 TEST(SchedulerTest, RequestCommitAfterBeginMainFrameSent) { | 339 TEST(SchedulerTest, RequestCommitAfterBeginMainFrameSent) { |
365 FakeSchedulerClient client; | 340 FakeSchedulerClient client; |
366 SchedulerSettings scheduler_settings; | 341 SchedulerSettings scheduler_settings; |
367 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings); | 342 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings); |
368 scheduler->SetCanStart(); | 343 scheduler->SetCanStart(); |
369 scheduler->SetVisible(true); | 344 scheduler->SetVisible(true); |
370 scheduler->SetCanDraw(true); | 345 scheduler->SetCanDraw(true); |
371 | 346 |
372 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); | 347 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); |
373 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | 348 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
374 client.Reset(); | 349 client.Reset(); |
375 | 350 |
376 // SetNeedsCommit should begin the frame. | 351 // SetNeedsCommit should begin the frame. |
377 scheduler->SetNeedsCommit(); | 352 scheduler->SetNeedsCommit(); |
378 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); | 353 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); |
379 | 354 |
380 client.Reset(); | 355 client.Reset(); |
381 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | 356 client.AdvanceFrame(); |
382 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 357 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
383 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); | 358 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); |
384 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 359 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
385 | 360 |
386 EXPECT_TRUE(client.needs_begin_frame()); | 361 EXPECT_TRUE(client.needs_begin_frame()); |
387 client.Reset(); | 362 client.Reset(); |
388 | 363 |
389 // Now SetNeedsCommit again. Calling here means we need a second commit. | 364 // Now SetNeedsCommit again. Calling here means we need a second commit. |
390 scheduler->SetNeedsCommit(); | 365 scheduler->SetNeedsCommit(); |
391 EXPECT_EQ(client.num_actions_(), 0); | 366 EXPECT_EQ(client.num_actions_(), 0); |
392 client.Reset(); | 367 client.Reset(); |
393 | 368 |
394 // Finish the first commit. | 369 // Finish the first commit. |
395 scheduler->NotifyBeginMainFrameStarted(); | 370 scheduler->NotifyBeginMainFrameStarted(); |
396 scheduler->NotifyReadyToCommit(); | 371 scheduler->NotifyReadyToCommit(); |
397 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); | 372 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); |
398 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 373 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
399 client.Reset(); | 374 client.Reset(); |
400 client.task_runner().RunPendingTasks(); // Run posted deadline. | 375 client.task_runner().RunPendingTasks(); // Run posted deadline. |
401 EXPECT_ACTION("ScheduledActionAnimate", client, 0, 2); | 376 EXPECT_ACTION("ScheduledActionAnimate", client, 0, 2); |
402 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 1, 2); | 377 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 1, 2); |
403 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 378 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
404 | 379 |
405 // Because we just swapped, the Scheduler should also request the next | 380 // Because we just swapped, the Scheduler should also request the next |
406 // BeginImplFrame from the OutputSurface. | 381 // BeginImplFrame from the OutputSurface. |
407 EXPECT_TRUE(client.needs_begin_frame()); | 382 EXPECT_TRUE(client.needs_begin_frame()); |
408 client.Reset(); | 383 client.Reset(); |
409 // Since another commit is needed, the next BeginImplFrame should initiate | 384 // Since another commit is needed, the next BeginImplFrame should initiate |
410 // the second commit. | 385 // the second commit. |
411 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | 386 client.AdvanceFrame(); |
412 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 387 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
413 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); | 388 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); |
414 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 389 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
415 client.Reset(); | 390 client.Reset(); |
416 | 391 |
417 // Finishing the commit before the deadline should post a new deadline task | 392 // Finishing the commit before the deadline should post a new deadline task |
418 // to trigger the deadline early. | 393 // to trigger the deadline early. |
419 scheduler->NotifyBeginMainFrameStarted(); | 394 scheduler->NotifyBeginMainFrameStarted(); |
420 scheduler->NotifyReadyToCommit(); | 395 scheduler->NotifyReadyToCommit(); |
421 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); | 396 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); |
422 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 397 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
423 client.Reset(); | 398 client.Reset(); |
424 client.task_runner().RunPendingTasks(); // Run posted deadline. | 399 client.task_runner().RunPendingTasks(); // Run posted deadline. |
425 EXPECT_ACTION("ScheduledActionAnimate", client, 0, 2); | 400 EXPECT_ACTION("ScheduledActionAnimate", client, 0, 2); |
426 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 1, 2); | 401 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 1, 2); |
427 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 402 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
428 EXPECT_TRUE(client.needs_begin_frame()); | 403 EXPECT_TRUE(client.needs_begin_frame()); |
429 client.Reset(); | 404 client.Reset(); |
430 | 405 |
431 // On the next BeginImplFrame, verify we go back to a quiescent state and | 406 // On the next BeginImplFrame, verify we go back to a quiescent state and |
432 // no longer request BeginImplFrames. | 407 // no longer request BeginImplFrames. |
433 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | 408 client.AdvanceFrame(); |
434 client.task_runner().RunPendingTasks(); // Run posted deadline. | 409 client.task_runner().RunPendingTasks(); // Run posted deadline. |
435 EXPECT_FALSE(client.needs_begin_frame()); | 410 EXPECT_FALSE(client.needs_begin_frame()); |
436 client.Reset(); | 411 client.Reset(); |
437 } | 412 } |
438 | 413 |
439 class SchedulerClientThatsetNeedsDrawInsideDraw : public FakeSchedulerClient { | 414 class SchedulerClientThatsetNeedsDrawInsideDraw : public FakeSchedulerClient { |
440 public: | 415 public: |
441 virtual void ScheduledActionSendBeginMainFrame() OVERRIDE {} | 416 virtual void ScheduledActionSendBeginMainFrame() OVERRIDE {} |
442 virtual DrawResult ScheduledActionDrawAndSwapIfPossible() | 417 virtual DrawResult ScheduledActionDrawAndSwapIfPossible() |
443 OVERRIDE { | 418 OVERRIDE { |
(...skipping 25 matching lines...) Expand all Loading... |
469 scheduler->SetVisible(true); | 444 scheduler->SetVisible(true); |
470 scheduler->SetCanDraw(true); | 445 scheduler->SetCanDraw(true); |
471 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | 446 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
472 client.Reset(); | 447 client.Reset(); |
473 | 448 |
474 scheduler->SetNeedsRedraw(); | 449 scheduler->SetNeedsRedraw(); |
475 EXPECT_TRUE(scheduler->RedrawPending()); | 450 EXPECT_TRUE(scheduler->RedrawPending()); |
476 EXPECT_TRUE(client.needs_begin_frame()); | 451 EXPECT_TRUE(client.needs_begin_frame()); |
477 EXPECT_EQ(0, client.num_draws()); | 452 EXPECT_EQ(0, client.num_draws()); |
478 | 453 |
479 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | 454 client.AdvanceFrame(); |
480 client.task_runner().RunPendingTasks(); // Run posted deadline. | 455 client.task_runner().RunPendingTasks(); // Run posted deadline. |
481 EXPECT_EQ(1, client.num_draws()); | 456 EXPECT_EQ(1, client.num_draws()); |
482 EXPECT_TRUE(scheduler->RedrawPending()); | 457 EXPECT_TRUE(scheduler->RedrawPending()); |
483 EXPECT_TRUE(client.needs_begin_frame()); | 458 EXPECT_TRUE(client.needs_begin_frame()); |
484 | 459 |
485 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | 460 client.AdvanceFrame(); |
486 client.task_runner().RunPendingTasks(); // Run posted deadline. | 461 client.task_runner().RunPendingTasks(); // Run posted deadline. |
487 EXPECT_EQ(2, client.num_draws()); | 462 EXPECT_EQ(2, client.num_draws()); |
488 EXPECT_FALSE(scheduler->RedrawPending()); | 463 EXPECT_FALSE(scheduler->RedrawPending()); |
489 EXPECT_TRUE(client.needs_begin_frame()); | 464 EXPECT_TRUE(client.needs_begin_frame()); |
490 | 465 |
491 // We stop requesting BeginImplFrames after a BeginImplFrame where we don't | 466 // We stop requesting BeginImplFrames after a BeginImplFrame where we don't |
492 // swap. | 467 // swap. |
493 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | 468 client.AdvanceFrame(); |
494 client.task_runner().RunPendingTasks(); // Run posted deadline. | 469 client.task_runner().RunPendingTasks(); // Run posted deadline. |
495 EXPECT_EQ(2, client.num_draws()); | 470 EXPECT_EQ(2, client.num_draws()); |
496 EXPECT_FALSE(scheduler->RedrawPending()); | 471 EXPECT_FALSE(scheduler->RedrawPending()); |
497 EXPECT_FALSE(client.needs_begin_frame()); | 472 EXPECT_FALSE(client.needs_begin_frame()); |
498 } | 473 } |
499 | 474 |
500 // Test that requesting redraw inside a failed draw doesn't lose the request. | 475 // Test that requesting redraw inside a failed draw doesn't lose the request. |
501 TEST(SchedulerTest, RequestRedrawInsideFailedDraw) { | 476 TEST(SchedulerTest, RequestRedrawInsideFailedDraw) { |
502 SchedulerClientThatsetNeedsDrawInsideDraw client; | 477 SchedulerClientThatsetNeedsDrawInsideDraw client; |
503 SchedulerSettings default_scheduler_settings; | 478 SchedulerSettings default_scheduler_settings; |
504 TestScheduler* scheduler = client.CreateScheduler(default_scheduler_settings); | 479 TestScheduler* scheduler = client.CreateScheduler(default_scheduler_settings); |
505 scheduler->SetCanStart(); | 480 scheduler->SetCanStart(); |
506 scheduler->SetVisible(true); | 481 scheduler->SetVisible(true); |
507 scheduler->SetCanDraw(true); | 482 scheduler->SetCanDraw(true); |
508 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | 483 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
509 client.Reset(); | 484 client.Reset(); |
510 | 485 |
511 client.SetDrawWillHappen(false); | 486 client.SetDrawWillHappen(false); |
512 | 487 |
513 scheduler->SetNeedsRedraw(); | 488 scheduler->SetNeedsRedraw(); |
514 EXPECT_TRUE(scheduler->RedrawPending()); | 489 EXPECT_TRUE(scheduler->RedrawPending()); |
515 EXPECT_TRUE(client.needs_begin_frame()); | 490 EXPECT_TRUE(client.needs_begin_frame()); |
516 EXPECT_EQ(0, client.num_draws()); | 491 EXPECT_EQ(0, client.num_draws()); |
517 | 492 |
518 // Fail the draw. | 493 // Fail the draw. |
519 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | 494 client.AdvanceFrame(); |
520 client.task_runner().RunPendingTasks(); // Run posted deadline. | 495 client.task_runner().RunPendingTasks(); // Run posted deadline. |
521 EXPECT_EQ(1, client.num_draws()); | 496 EXPECT_EQ(1, client.num_draws()); |
522 | 497 |
523 // We have a commit pending and the draw failed, and we didn't lose the redraw | 498 // We have a commit pending and the draw failed, and we didn't lose the redraw |
524 // request. | 499 // request. |
525 EXPECT_TRUE(scheduler->CommitPending()); | 500 EXPECT_TRUE(scheduler->CommitPending()); |
526 EXPECT_TRUE(scheduler->RedrawPending()); | 501 EXPECT_TRUE(scheduler->RedrawPending()); |
527 EXPECT_TRUE(client.needs_begin_frame()); | 502 EXPECT_TRUE(client.needs_begin_frame()); |
528 | 503 |
529 // Fail the draw again. | 504 // Fail the draw again. |
530 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | 505 client.AdvanceFrame(); |
531 client.task_runner().RunPendingTasks(); // Run posted deadline. | 506 client.task_runner().RunPendingTasks(); // Run posted deadline. |
532 EXPECT_EQ(2, client.num_draws()); | 507 EXPECT_EQ(2, client.num_draws()); |
533 EXPECT_TRUE(scheduler->CommitPending()); | 508 EXPECT_TRUE(scheduler->CommitPending()); |
534 EXPECT_TRUE(scheduler->RedrawPending()); | 509 EXPECT_TRUE(scheduler->RedrawPending()); |
535 EXPECT_TRUE(client.needs_begin_frame()); | 510 EXPECT_TRUE(client.needs_begin_frame()); |
536 | 511 |
537 // Draw successfully. | 512 // Draw successfully. |
538 client.SetDrawWillHappen(true); | 513 client.SetDrawWillHappen(true); |
539 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | 514 client.AdvanceFrame(); |
540 client.task_runner().RunPendingTasks(); // Run posted deadline. | 515 client.task_runner().RunPendingTasks(); // Run posted deadline. |
541 EXPECT_EQ(3, client.num_draws()); | 516 EXPECT_EQ(3, client.num_draws()); |
542 EXPECT_TRUE(scheduler->CommitPending()); | 517 EXPECT_TRUE(scheduler->CommitPending()); |
543 EXPECT_FALSE(scheduler->RedrawPending()); | 518 EXPECT_FALSE(scheduler->RedrawPending()); |
544 EXPECT_TRUE(client.needs_begin_frame()); | 519 EXPECT_TRUE(client.needs_begin_frame()); |
545 } | 520 } |
546 | 521 |
547 class SchedulerClientThatSetNeedsCommitInsideDraw : public FakeSchedulerClient { | 522 class SchedulerClientThatSetNeedsCommitInsideDraw : public FakeSchedulerClient { |
548 public: | 523 public: |
549 SchedulerClientThatSetNeedsCommitInsideDraw() | 524 SchedulerClientThatSetNeedsCommitInsideDraw() |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
587 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | 562 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
588 client.Reset(); | 563 client.Reset(); |
589 | 564 |
590 EXPECT_FALSE(client.needs_begin_frame()); | 565 EXPECT_FALSE(client.needs_begin_frame()); |
591 scheduler->SetNeedsRedraw(); | 566 scheduler->SetNeedsRedraw(); |
592 EXPECT_TRUE(scheduler->RedrawPending()); | 567 EXPECT_TRUE(scheduler->RedrawPending()); |
593 EXPECT_EQ(0, client.num_draws()); | 568 EXPECT_EQ(0, client.num_draws()); |
594 EXPECT_TRUE(client.needs_begin_frame()); | 569 EXPECT_TRUE(client.needs_begin_frame()); |
595 | 570 |
596 client.SetNeedsCommitOnNextDraw(); | 571 client.SetNeedsCommitOnNextDraw(); |
597 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | 572 client.AdvanceFrame(); |
598 client.SetNeedsCommitOnNextDraw(); | 573 client.SetNeedsCommitOnNextDraw(); |
599 client.task_runner().RunPendingTasks(); // Run posted deadline. | 574 client.task_runner().RunPendingTasks(); // Run posted deadline. |
600 EXPECT_EQ(1, client.num_draws()); | 575 EXPECT_EQ(1, client.num_draws()); |
601 EXPECT_TRUE(scheduler->CommitPending()); | 576 EXPECT_TRUE(scheduler->CommitPending()); |
602 EXPECT_TRUE(client.needs_begin_frame()); | 577 EXPECT_TRUE(client.needs_begin_frame()); |
603 scheduler->NotifyBeginMainFrameStarted(); | 578 scheduler->NotifyBeginMainFrameStarted(); |
604 scheduler->NotifyReadyToCommit(); | 579 scheduler->NotifyReadyToCommit(); |
605 | 580 |
606 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | 581 client.AdvanceFrame(); |
607 client.task_runner().RunPendingTasks(); // Run posted deadline. | 582 client.task_runner().RunPendingTasks(); // Run posted deadline. |
608 EXPECT_EQ(2, client.num_draws()); | 583 EXPECT_EQ(2, client.num_draws()); |
609 | 584 |
610 EXPECT_FALSE(scheduler->RedrawPending()); | 585 EXPECT_FALSE(scheduler->RedrawPending()); |
611 EXPECT_FALSE(scheduler->CommitPending()); | 586 EXPECT_FALSE(scheduler->CommitPending()); |
612 EXPECT_TRUE(client.needs_begin_frame()); | 587 EXPECT_TRUE(client.needs_begin_frame()); |
613 | 588 |
614 // We stop requesting BeginImplFrames after a BeginImplFrame where we don't | 589 // We stop requesting BeginImplFrames after a BeginImplFrame where we don't |
615 // swap. | 590 // swap. |
616 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | 591 client.AdvanceFrame(); |
617 client.task_runner().RunPendingTasks(); // Run posted deadline. | 592 client.task_runner().RunPendingTasks(); // Run posted deadline. |
618 EXPECT_EQ(2, client.num_draws()); | 593 EXPECT_EQ(2, client.num_draws()); |
619 EXPECT_FALSE(scheduler->RedrawPending()); | 594 EXPECT_FALSE(scheduler->RedrawPending()); |
620 EXPECT_FALSE(scheduler->CommitPending()); | 595 EXPECT_FALSE(scheduler->CommitPending()); |
621 EXPECT_FALSE(client.needs_begin_frame()); | 596 EXPECT_FALSE(client.needs_begin_frame()); |
622 } | 597 } |
623 | 598 |
624 // Tests that when a draw fails then the pending commit should not be dropped. | 599 // Tests that when a draw fails then the pending commit should not be dropped. |
625 TEST(SchedulerTest, RequestCommitInsideFailedDraw) { | 600 TEST(SchedulerTest, RequestCommitInsideFailedDraw) { |
626 SchedulerClientThatsetNeedsDrawInsideDraw client; | 601 SchedulerClientThatsetNeedsDrawInsideDraw client; |
627 SchedulerSettings default_scheduler_settings; | 602 SchedulerSettings default_scheduler_settings; |
628 TestScheduler* scheduler = client.CreateScheduler(default_scheduler_settings); | 603 TestScheduler* scheduler = client.CreateScheduler(default_scheduler_settings); |
629 scheduler->SetCanStart(); | 604 scheduler->SetCanStart(); |
630 scheduler->SetVisible(true); | 605 scheduler->SetVisible(true); |
631 scheduler->SetCanDraw(true); | 606 scheduler->SetCanDraw(true); |
632 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | 607 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
633 client.Reset(); | 608 client.Reset(); |
634 | 609 |
635 client.SetDrawWillHappen(false); | 610 client.SetDrawWillHappen(false); |
636 | 611 |
637 scheduler->SetNeedsRedraw(); | 612 scheduler->SetNeedsRedraw(); |
638 EXPECT_TRUE(scheduler->RedrawPending()); | 613 EXPECT_TRUE(scheduler->RedrawPending()); |
639 EXPECT_TRUE(client.needs_begin_frame()); | 614 EXPECT_TRUE(client.needs_begin_frame()); |
640 EXPECT_EQ(0, client.num_draws()); | 615 EXPECT_EQ(0, client.num_draws()); |
641 | 616 |
642 // Fail the draw. | 617 // Fail the draw. |
643 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | 618 client.AdvanceFrame(); |
644 client.task_runner().RunPendingTasks(); // Run posted deadline. | 619 client.task_runner().RunPendingTasks(); // Run posted deadline. |
645 EXPECT_EQ(1, client.num_draws()); | 620 EXPECT_EQ(1, client.num_draws()); |
646 | 621 |
647 // We have a commit pending and the draw failed, and we didn't lose the commit | 622 // We have a commit pending and the draw failed, and we didn't lose the commit |
648 // request. | 623 // request. |
649 EXPECT_TRUE(scheduler->CommitPending()); | 624 EXPECT_TRUE(scheduler->CommitPending()); |
650 EXPECT_TRUE(scheduler->RedrawPending()); | 625 EXPECT_TRUE(scheduler->RedrawPending()); |
651 EXPECT_TRUE(client.needs_begin_frame()); | 626 EXPECT_TRUE(client.needs_begin_frame()); |
652 | 627 |
653 // Fail the draw again. | 628 // Fail the draw again. |
654 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | 629 client.AdvanceFrame(); |
655 | 630 |
656 client.task_runner().RunPendingTasks(); // Run posted deadline. | 631 client.task_runner().RunPendingTasks(); // Run posted deadline. |
657 EXPECT_EQ(2, client.num_draws()); | 632 EXPECT_EQ(2, client.num_draws()); |
658 EXPECT_TRUE(scheduler->CommitPending()); | 633 EXPECT_TRUE(scheduler->CommitPending()); |
659 EXPECT_TRUE(scheduler->RedrawPending()); | 634 EXPECT_TRUE(scheduler->RedrawPending()); |
660 EXPECT_TRUE(client.needs_begin_frame()); | 635 EXPECT_TRUE(client.needs_begin_frame()); |
661 | 636 |
662 // Draw successfully. | 637 // Draw successfully. |
663 client.SetDrawWillHappen(true); | 638 client.SetDrawWillHappen(true); |
664 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | 639 client.AdvanceFrame(); |
665 client.task_runner().RunPendingTasks(); // Run posted deadline. | 640 client.task_runner().RunPendingTasks(); // Run posted deadline. |
666 EXPECT_EQ(3, client.num_draws()); | 641 EXPECT_EQ(3, client.num_draws()); |
667 EXPECT_TRUE(scheduler->CommitPending()); | 642 EXPECT_TRUE(scheduler->CommitPending()); |
668 EXPECT_FALSE(scheduler->RedrawPending()); | 643 EXPECT_FALSE(scheduler->RedrawPending()); |
669 EXPECT_TRUE(client.needs_begin_frame()); | 644 EXPECT_TRUE(client.needs_begin_frame()); |
670 } | 645 } |
671 | 646 |
672 TEST(SchedulerTest, NoSwapWhenDrawFails) { | 647 TEST(SchedulerTest, NoSwapWhenDrawFails) { |
673 SchedulerClientThatSetNeedsCommitInsideDraw client; | 648 SchedulerClientThatSetNeedsCommitInsideDraw client; |
674 SchedulerSettings default_scheduler_settings; | 649 SchedulerSettings default_scheduler_settings; |
675 TestScheduler* scheduler = client.CreateScheduler(default_scheduler_settings); | 650 TestScheduler* scheduler = client.CreateScheduler(default_scheduler_settings); |
676 scheduler->SetCanStart(); | 651 scheduler->SetCanStart(); |
677 scheduler->SetVisible(true); | 652 scheduler->SetVisible(true); |
678 scheduler->SetCanDraw(true); | 653 scheduler->SetCanDraw(true); |
679 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | 654 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
680 client.Reset(); | 655 client.Reset(); |
681 | 656 |
682 scheduler->SetNeedsRedraw(); | 657 scheduler->SetNeedsRedraw(); |
683 EXPECT_TRUE(scheduler->RedrawPending()); | 658 EXPECT_TRUE(scheduler->RedrawPending()); |
684 EXPECT_TRUE(client.needs_begin_frame()); | 659 EXPECT_TRUE(client.needs_begin_frame()); |
685 EXPECT_EQ(0, client.num_draws()); | 660 EXPECT_EQ(0, client.num_draws()); |
686 | 661 |
687 // Draw successfully, this starts a new frame. | 662 // Draw successfully, this starts a new frame. |
688 client.SetNeedsCommitOnNextDraw(); | 663 client.SetNeedsCommitOnNextDraw(); |
689 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | 664 client.AdvanceFrame(); |
690 client.task_runner().RunPendingTasks(); // Run posted deadline. | 665 client.task_runner().RunPendingTasks(); // Run posted deadline. |
691 EXPECT_EQ(1, client.num_draws()); | 666 EXPECT_EQ(1, client.num_draws()); |
692 | 667 |
693 scheduler->SetNeedsRedraw(); | 668 scheduler->SetNeedsRedraw(); |
694 EXPECT_TRUE(scheduler->RedrawPending()); | 669 EXPECT_TRUE(scheduler->RedrawPending()); |
695 EXPECT_TRUE(client.needs_begin_frame()); | 670 EXPECT_TRUE(client.needs_begin_frame()); |
696 | 671 |
697 // Fail to draw, this should not start a frame. | 672 // Fail to draw, this should not start a frame. |
698 client.SetDrawWillHappen(false); | 673 client.SetDrawWillHappen(false); |
699 client.SetNeedsCommitOnNextDraw(); | 674 client.SetNeedsCommitOnNextDraw(); |
700 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | 675 client.AdvanceFrame(); |
701 client.task_runner().RunPendingTasks(); // Run posted deadline. | 676 client.task_runner().RunPendingTasks(); // Run posted deadline. |
702 EXPECT_EQ(2, client.num_draws()); | 677 EXPECT_EQ(2, client.num_draws()); |
703 } | 678 } |
704 | 679 |
705 class SchedulerClientNeedsManageTilesInDraw : public FakeSchedulerClient { | 680 class SchedulerClientNeedsManageTilesInDraw : public FakeSchedulerClient { |
706 public: | 681 public: |
707 virtual DrawResult ScheduledActionDrawAndSwapIfPossible() | 682 virtual DrawResult ScheduledActionDrawAndSwapIfPossible() |
708 OVERRIDE { | 683 OVERRIDE { |
709 scheduler_->SetNeedsManageTiles(); | 684 scheduler_->SetNeedsManageTiles(); |
710 return FakeSchedulerClient::ScheduledActionDrawAndSwapIfPossible(); | 685 return FakeSchedulerClient::ScheduledActionDrawAndSwapIfPossible(); |
(...skipping 18 matching lines...) Expand all Loading... |
729 EXPECT_TRUE(scheduler->RedrawPending()); | 704 EXPECT_TRUE(scheduler->RedrawPending()); |
730 EXPECT_TRUE(scheduler->ManageTilesPending()); | 705 EXPECT_TRUE(scheduler->ManageTilesPending()); |
731 EXPECT_TRUE(client.needs_begin_frame()); | 706 EXPECT_TRUE(client.needs_begin_frame()); |
732 EXPECT_EQ(0, client.num_draws()); | 707 EXPECT_EQ(0, client.num_draws()); |
733 EXPECT_FALSE(client.HasAction("ScheduledActionManageTiles")); | 708 EXPECT_FALSE(client.HasAction("ScheduledActionManageTiles")); |
734 EXPECT_FALSE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); | 709 EXPECT_FALSE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); |
735 | 710 |
736 // We have no immediate actions to perform, so the BeginImplFrame should post | 711 // We have no immediate actions to perform, so the BeginImplFrame should post |
737 // the deadline task. | 712 // the deadline task. |
738 client.Reset(); | 713 client.Reset(); |
739 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | 714 client.AdvanceFrame(); |
740 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 715 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
741 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); | 716 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); |
742 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 717 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
743 | 718 |
744 // On the deadline, he actions should have occured in the right order. | 719 // On the deadline, he actions should have occured in the right order. |
745 client.Reset(); | 720 client.Reset(); |
746 client.task_runner().RunPendingTasks(); // Run posted deadline. | 721 client.task_runner().RunPendingTasks(); // Run posted deadline. |
747 EXPECT_EQ(1, client.num_draws()); | 722 EXPECT_EQ(1, client.num_draws()); |
748 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); | 723 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); |
749 EXPECT_TRUE(client.HasAction("ScheduledActionManageTiles")); | 724 EXPECT_TRUE(client.HasAction("ScheduledActionManageTiles")); |
750 EXPECT_LT(client.ActionIndex("ScheduledActionDrawAndSwapIfPossible"), | 725 EXPECT_LT(client.ActionIndex("ScheduledActionDrawAndSwapIfPossible"), |
751 client.ActionIndex("ScheduledActionManageTiles")); | 726 client.ActionIndex("ScheduledActionManageTiles")); |
752 EXPECT_FALSE(scheduler->RedrawPending()); | 727 EXPECT_FALSE(scheduler->RedrawPending()); |
753 EXPECT_FALSE(scheduler->ManageTilesPending()); | 728 EXPECT_FALSE(scheduler->ManageTilesPending()); |
754 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 729 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
755 | 730 |
756 // Request a draw. We don't need a ManageTiles yet. | 731 // Request a draw. We don't need a ManageTiles yet. |
757 client.Reset(); | 732 client.Reset(); |
758 scheduler->SetNeedsRedraw(); | 733 scheduler->SetNeedsRedraw(); |
759 EXPECT_TRUE(scheduler->RedrawPending()); | 734 EXPECT_TRUE(scheduler->RedrawPending()); |
760 EXPECT_FALSE(scheduler->ManageTilesPending()); | 735 EXPECT_FALSE(scheduler->ManageTilesPending()); |
761 EXPECT_TRUE(client.needs_begin_frame()); | 736 EXPECT_TRUE(client.needs_begin_frame()); |
762 EXPECT_EQ(0, client.num_draws()); | 737 EXPECT_EQ(0, client.num_draws()); |
763 | 738 |
764 // We have no immediate actions to perform, so the BeginImplFrame should post | 739 // We have no immediate actions to perform, so the BeginImplFrame should post |
765 // the deadline task. | 740 // the deadline task. |
766 client.Reset(); | 741 client.Reset(); |
767 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | 742 client.AdvanceFrame(); |
768 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 743 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
769 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); | 744 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); |
770 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 745 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
771 | 746 |
772 // Draw. The draw will trigger SetNeedsManageTiles, and | 747 // Draw. The draw will trigger SetNeedsManageTiles, and |
773 // then the ManageTiles action will be triggered after the Draw. | 748 // then the ManageTiles action will be triggered after the Draw. |
774 // Afterwards, neither a draw nor ManageTiles are pending. | 749 // Afterwards, neither a draw nor ManageTiles are pending. |
775 client.Reset(); | 750 client.Reset(); |
776 client.task_runner().RunPendingTasks(); // Run posted deadline. | 751 client.task_runner().RunPendingTasks(); // Run posted deadline. |
777 EXPECT_EQ(1, client.num_draws()); | 752 EXPECT_EQ(1, client.num_draws()); |
778 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); | 753 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); |
779 EXPECT_TRUE(client.HasAction("ScheduledActionManageTiles")); | 754 EXPECT_TRUE(client.HasAction("ScheduledActionManageTiles")); |
780 EXPECT_LT(client.ActionIndex("ScheduledActionDrawAndSwapIfPossible"), | 755 EXPECT_LT(client.ActionIndex("ScheduledActionDrawAndSwapIfPossible"), |
781 client.ActionIndex("ScheduledActionManageTiles")); | 756 client.ActionIndex("ScheduledActionManageTiles")); |
782 EXPECT_FALSE(scheduler->RedrawPending()); | 757 EXPECT_FALSE(scheduler->RedrawPending()); |
783 EXPECT_FALSE(scheduler->ManageTilesPending()); | 758 EXPECT_FALSE(scheduler->ManageTilesPending()); |
784 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 759 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
785 | 760 |
786 // We need a BeginImplFrame where we don't swap to go idle. | 761 // We need a BeginImplFrame where we don't swap to go idle. |
787 client.Reset(); | 762 client.Reset(); |
788 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | 763 client.AdvanceFrame(); |
789 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); | 764 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); |
790 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 765 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
791 client.Reset(); | 766 client.Reset(); |
792 client.task_runner().RunPendingTasks(); // Run posted deadline. | 767 client.task_runner().RunPendingTasks(); // Run posted deadline. |
793 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); | 768 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); |
794 EXPECT_FALSE(client.needs_begin_frame()); | 769 EXPECT_FALSE(client.needs_begin_frame()); |
795 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 770 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
796 EXPECT_EQ(0, client.num_draws()); | 771 EXPECT_EQ(0, client.num_draws()); |
797 | 772 |
798 // Now trigger a ManageTiles outside of a draw. We will then need | 773 // 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. | 774 // a begin-frame for the ManageTiles, but we don't need a draw. |
800 client.Reset(); | 775 client.Reset(); |
801 EXPECT_FALSE(client.needs_begin_frame()); | 776 EXPECT_FALSE(client.needs_begin_frame()); |
802 scheduler->SetNeedsManageTiles(); | 777 scheduler->SetNeedsManageTiles(); |
803 EXPECT_TRUE(client.needs_begin_frame()); | 778 EXPECT_TRUE(client.needs_begin_frame()); |
804 EXPECT_TRUE(scheduler->ManageTilesPending()); | 779 EXPECT_TRUE(scheduler->ManageTilesPending()); |
805 EXPECT_FALSE(scheduler->RedrawPending()); | 780 EXPECT_FALSE(scheduler->RedrawPending()); |
806 | 781 |
807 // BeginImplFrame. There will be no draw, only ManageTiles. | 782 // BeginImplFrame. There will be no draw, only ManageTiles. |
808 client.Reset(); | 783 client.Reset(); |
809 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | 784 client.AdvanceFrame(); |
810 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); | 785 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); |
811 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 786 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
812 client.Reset(); | 787 client.Reset(); |
813 client.task_runner().RunPendingTasks(); // Run posted deadline. | 788 client.task_runner().RunPendingTasks(); // Run posted deadline. |
814 EXPECT_EQ(0, client.num_draws()); | 789 EXPECT_EQ(0, client.num_draws()); |
815 EXPECT_FALSE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); | 790 EXPECT_FALSE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); |
816 EXPECT_TRUE(client.HasAction("ScheduledActionManageTiles")); | 791 EXPECT_TRUE(client.HasAction("ScheduledActionManageTiles")); |
817 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 792 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
818 } | 793 } |
819 | 794 |
820 // Test that ManageTiles only happens once per frame. If an external caller | 795 // 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. | 796 // initiates it, then the state machine should not ManageTiles on that frame. |
822 TEST(SchedulerTest, ManageTilesOncePerFrame) { | 797 TEST(SchedulerTest, ManageTilesOncePerFrame) { |
823 FakeSchedulerClient client; | 798 FakeSchedulerClient client; |
824 SchedulerSettings default_scheduler_settings; | 799 SchedulerSettings default_scheduler_settings; |
825 TestScheduler* scheduler = client.CreateScheduler(default_scheduler_settings); | 800 TestScheduler* scheduler = client.CreateScheduler(default_scheduler_settings); |
826 scheduler->SetCanStart(); | 801 scheduler->SetCanStart(); |
827 scheduler->SetVisible(true); | 802 scheduler->SetVisible(true); |
828 scheduler->SetCanDraw(true); | 803 scheduler->SetCanDraw(true); |
829 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | 804 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
830 | 805 |
831 // If DidManageTiles during a frame, then ManageTiles should not occur again. | 806 // If DidManageTiles during a frame, then ManageTiles should not occur again. |
832 scheduler->SetNeedsManageTiles(); | 807 scheduler->SetNeedsManageTiles(); |
833 scheduler->SetNeedsRedraw(); | 808 scheduler->SetNeedsRedraw(); |
834 client.Reset(); | 809 client.Reset(); |
835 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | 810 client.AdvanceFrame(); |
836 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 811 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
837 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); | 812 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); |
838 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 813 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
839 | 814 |
840 EXPECT_TRUE(scheduler->ManageTilesPending()); | 815 EXPECT_TRUE(scheduler->ManageTilesPending()); |
841 scheduler->DidManageTiles(); // An explicit ManageTiles. | 816 scheduler->DidManageTiles(); // An explicit ManageTiles. |
842 EXPECT_FALSE(scheduler->ManageTilesPending()); | 817 EXPECT_FALSE(scheduler->ManageTilesPending()); |
843 | 818 |
844 client.Reset(); | 819 client.Reset(); |
845 client.task_runner().RunPendingTasks(); // Run posted deadline. | 820 client.task_runner().RunPendingTasks(); // Run posted deadline. |
846 EXPECT_EQ(1, client.num_draws()); | 821 EXPECT_EQ(1, client.num_draws()); |
847 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); | 822 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); |
848 EXPECT_FALSE(client.HasAction("ScheduledActionManageTiles")); | 823 EXPECT_FALSE(client.HasAction("ScheduledActionManageTiles")); |
849 EXPECT_FALSE(scheduler->RedrawPending()); | 824 EXPECT_FALSE(scheduler->RedrawPending()); |
850 EXPECT_FALSE(scheduler->ManageTilesPending()); | 825 EXPECT_FALSE(scheduler->ManageTilesPending()); |
851 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 826 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
852 | 827 |
853 // Next frame without DidManageTiles should ManageTiles with draw. | 828 // Next frame without DidManageTiles should ManageTiles with draw. |
854 scheduler->SetNeedsManageTiles(); | 829 scheduler->SetNeedsManageTiles(); |
855 scheduler->SetNeedsRedraw(); | 830 scheduler->SetNeedsRedraw(); |
856 client.Reset(); | 831 client.Reset(); |
857 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | 832 client.AdvanceFrame(); |
858 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 833 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
859 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); | 834 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); |
860 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 835 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
861 | 836 |
862 client.Reset(); | 837 client.Reset(); |
863 client.task_runner().RunPendingTasks(); // Run posted deadline. | 838 client.task_runner().RunPendingTasks(); // Run posted deadline. |
864 EXPECT_EQ(1, client.num_draws()); | 839 EXPECT_EQ(1, client.num_draws()); |
865 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); | 840 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); |
866 EXPECT_TRUE(client.HasAction("ScheduledActionManageTiles")); | 841 EXPECT_TRUE(client.HasAction("ScheduledActionManageTiles")); |
867 EXPECT_LT(client.ActionIndex("ScheduledActionDrawAndSwapIfPossible"), | 842 EXPECT_LT(client.ActionIndex("ScheduledActionDrawAndSwapIfPossible"), |
868 client.ActionIndex("ScheduledActionManageTiles")); | 843 client.ActionIndex("ScheduledActionManageTiles")); |
869 EXPECT_FALSE(scheduler->RedrawPending()); | 844 EXPECT_FALSE(scheduler->RedrawPending()); |
870 EXPECT_FALSE(scheduler->ManageTilesPending()); | 845 EXPECT_FALSE(scheduler->ManageTilesPending()); |
871 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 846 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
872 scheduler->DidManageTiles(); // Corresponds to ScheduledActionManageTiles | 847 scheduler->DidManageTiles(); // Corresponds to ScheduledActionManageTiles |
873 | 848 |
874 // If we get another DidManageTiles within the same frame, we should | 849 // If we get another DidManageTiles within the same frame, we should |
875 // not ManageTiles on the next frame. | 850 // not ManageTiles on the next frame. |
876 scheduler->DidManageTiles(); // An explicit ManageTiles. | 851 scheduler->DidManageTiles(); // An explicit ManageTiles. |
877 scheduler->SetNeedsManageTiles(); | 852 scheduler->SetNeedsManageTiles(); |
878 scheduler->SetNeedsRedraw(); | 853 scheduler->SetNeedsRedraw(); |
879 client.Reset(); | 854 client.Reset(); |
880 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | 855 client.AdvanceFrame(); |
881 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 856 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
882 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); | 857 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); |
883 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 858 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
884 | 859 |
885 EXPECT_TRUE(scheduler->ManageTilesPending()); | 860 EXPECT_TRUE(scheduler->ManageTilesPending()); |
886 | 861 |
887 client.Reset(); | 862 client.Reset(); |
888 client.task_runner().RunPendingTasks(); // Run posted deadline. | 863 client.task_runner().RunPendingTasks(); // Run posted deadline. |
889 EXPECT_EQ(1, client.num_draws()); | 864 EXPECT_EQ(1, client.num_draws()); |
890 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); | 865 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); |
891 EXPECT_FALSE(client.HasAction("ScheduledActionManageTiles")); | 866 EXPECT_FALSE(client.HasAction("ScheduledActionManageTiles")); |
892 EXPECT_FALSE(scheduler->RedrawPending()); | 867 EXPECT_FALSE(scheduler->RedrawPending()); |
893 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 868 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
894 | 869 |
895 // If we get another DidManageTiles, we should not ManageTiles on the next | 870 // 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. | 871 // frame. This verifies we don't alternate calling ManageTiles once and twice. |
897 EXPECT_TRUE(scheduler->ManageTilesPending()); | 872 EXPECT_TRUE(scheduler->ManageTilesPending()); |
898 scheduler->DidManageTiles(); // An explicit ManageTiles. | 873 scheduler->DidManageTiles(); // An explicit ManageTiles. |
899 EXPECT_FALSE(scheduler->ManageTilesPending()); | 874 EXPECT_FALSE(scheduler->ManageTilesPending()); |
900 scheduler->SetNeedsManageTiles(); | 875 scheduler->SetNeedsManageTiles(); |
901 scheduler->SetNeedsRedraw(); | 876 scheduler->SetNeedsRedraw(); |
902 client.Reset(); | 877 client.Reset(); |
903 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | 878 client.AdvanceFrame(); |
904 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 879 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
905 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); | 880 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); |
906 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 881 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
907 | 882 |
908 EXPECT_TRUE(scheduler->ManageTilesPending()); | 883 EXPECT_TRUE(scheduler->ManageTilesPending()); |
909 | 884 |
910 client.Reset(); | 885 client.Reset(); |
911 client.task_runner().RunPendingTasks(); // Run posted deadline. | 886 client.task_runner().RunPendingTasks(); // Run posted deadline. |
912 EXPECT_EQ(1, client.num_draws()); | 887 EXPECT_EQ(1, client.num_draws()); |
913 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); | 888 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); |
914 EXPECT_FALSE(client.HasAction("ScheduledActionManageTiles")); | 889 EXPECT_FALSE(client.HasAction("ScheduledActionManageTiles")); |
915 EXPECT_FALSE(scheduler->RedrawPending()); | 890 EXPECT_FALSE(scheduler->RedrawPending()); |
916 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 891 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
917 | 892 |
918 // Next frame without DidManageTiles should ManageTiles with draw. | 893 // Next frame without DidManageTiles should ManageTiles with draw. |
919 scheduler->SetNeedsManageTiles(); | 894 scheduler->SetNeedsManageTiles(); |
920 scheduler->SetNeedsRedraw(); | 895 scheduler->SetNeedsRedraw(); |
921 client.Reset(); | 896 client.Reset(); |
922 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | 897 client.AdvanceFrame(); |
923 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 898 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
924 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); | 899 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); |
925 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 900 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
926 | 901 |
927 client.Reset(); | 902 client.Reset(); |
928 client.task_runner().RunPendingTasks(); // Run posted deadline. | 903 client.task_runner().RunPendingTasks(); // Run posted deadline. |
929 EXPECT_EQ(1, client.num_draws()); | 904 EXPECT_EQ(1, client.num_draws()); |
930 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); | 905 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); |
931 EXPECT_TRUE(client.HasAction("ScheduledActionManageTiles")); | 906 EXPECT_TRUE(client.HasAction("ScheduledActionManageTiles")); |
932 EXPECT_LT(client.ActionIndex("ScheduledActionDrawAndSwapIfPossible"), | 907 EXPECT_LT(client.ActionIndex("ScheduledActionDrawAndSwapIfPossible"), |
(...skipping 15 matching lines...) Expand all Loading... |
948 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | 923 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
949 | 924 |
950 client.SetRedrawWillHappenIfUpdateVisibleTilesHappens(true); | 925 client.SetRedrawWillHappenIfUpdateVisibleTilesHappens(true); |
951 | 926 |
952 // SetNeedsCommit should begin the frame. | 927 // SetNeedsCommit should begin the frame. |
953 client.Reset(); | 928 client.Reset(); |
954 scheduler->SetNeedsCommit(); | 929 scheduler->SetNeedsCommit(); |
955 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); | 930 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); |
956 | 931 |
957 client.Reset(); | 932 client.Reset(); |
958 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | 933 client.AdvanceFrame(); |
959 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 934 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
960 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); | 935 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); |
961 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 936 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
962 | 937 |
963 client.Reset(); | 938 client.Reset(); |
964 scheduler->NotifyBeginMainFrameStarted(); | 939 scheduler->NotifyBeginMainFrameStarted(); |
965 scheduler->NotifyReadyToCommit(); | 940 scheduler->NotifyReadyToCommit(); |
966 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); | 941 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); |
967 | 942 |
968 client.Reset(); | 943 client.Reset(); |
969 scheduler->NotifyReadyToActivate(); | 944 scheduler->NotifyReadyToActivate(); |
970 EXPECT_SINGLE_ACTION("ScheduledActionActivateSyncTree", client); | 945 EXPECT_SINGLE_ACTION("ScheduledActionActivateSyncTree", client); |
971 | 946 |
972 client.Reset(); | 947 client.Reset(); |
973 client.SetSwapContainsIncompleteTile(true); | 948 client.SetSwapContainsIncompleteTile(true); |
974 client.task_runner().RunPendingTasks(); // Run posted deadline. | 949 client.task_runner().RunPendingTasks(); // Run posted deadline. |
975 EXPECT_ACTION("ScheduledActionAnimate", client, 0, 2); | 950 EXPECT_ACTION("ScheduledActionAnimate", client, 0, 2); |
976 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 1, 2); | 951 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 1, 2); |
977 EXPECT_FALSE(scheduler->RedrawPending()); | 952 EXPECT_FALSE(scheduler->RedrawPending()); |
978 | 953 |
979 client.Reset(); | 954 client.Reset(); |
980 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | 955 client.AdvanceFrame(); |
981 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); | 956 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); |
982 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 957 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
983 | 958 |
984 client.Reset(); | 959 client.Reset(); |
985 client.task_runner().RunPendingTasks(); // Run posted deadline. | 960 client.task_runner().RunPendingTasks(); // Run posted deadline. |
986 EXPECT_ACTION("ScheduledActionUpdateVisibleTiles", client, 0, 3); | 961 EXPECT_ACTION("ScheduledActionUpdateVisibleTiles", client, 0, 3); |
987 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 3); | 962 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 3); |
988 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 2, 3); | 963 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 2, 3); |
989 | 964 |
990 client.Reset(); | 965 client.Reset(); |
991 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | 966 client.AdvanceFrame(); |
992 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); | 967 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); |
993 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 968 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
994 | 969 |
995 // No more UpdateVisibleTiles(). | 970 // No more UpdateVisibleTiles(). |
996 client.Reset(); | 971 client.Reset(); |
997 client.task_runner().RunPendingTasks(); // Run posted deadline. | 972 client.task_runner().RunPendingTasks(); // Run posted deadline. |
998 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); | 973 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); |
999 EXPECT_FALSE(client.needs_begin_frame()); | 974 EXPECT_FALSE(client.needs_begin_frame()); |
1000 } | 975 } |
1001 | 976 |
1002 TEST(SchedulerTest, TriggerBeginFrameDeadlineEarly) { | 977 TEST(SchedulerTest, TriggerBeginFrameDeadlineEarly) { |
1003 SchedulerClientNeedsManageTilesInDraw client; | 978 SchedulerClientNeedsManageTilesInDraw client; |
1004 SchedulerSettings default_scheduler_settings; | 979 SchedulerSettings default_scheduler_settings; |
1005 TestScheduler* scheduler = client.CreateScheduler(default_scheduler_settings); | 980 TestScheduler* scheduler = client.CreateScheduler(default_scheduler_settings); |
1006 scheduler->SetCanStart(); | 981 scheduler->SetCanStart(); |
1007 scheduler->SetVisible(true); | 982 scheduler->SetVisible(true); |
1008 scheduler->SetCanDraw(true); | 983 scheduler->SetCanDraw(true); |
1009 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | 984 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
1010 | 985 |
1011 client.Reset(); | 986 client.Reset(); |
1012 scheduler->SetNeedsRedraw(); | 987 scheduler->SetNeedsRedraw(); |
1013 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | 988 client.AdvanceFrame(); |
1014 | 989 |
1015 // The deadline should be zero since there is no work other than drawing | 990 // The deadline should be zero since there is no work other than drawing |
1016 // pending. | 991 // pending. |
1017 EXPECT_EQ(base::TimeTicks(), client.posted_begin_impl_frame_deadline()); | 992 EXPECT_EQ(base::TimeTicks(), client.posted_begin_impl_frame_deadline()); |
1018 } | 993 } |
1019 | 994 |
1020 class SchedulerClientWithFixedEstimates : public FakeSchedulerClient { | 995 class SchedulerClientWithFixedEstimates : public FakeSchedulerClient { |
1021 public: | 996 public: |
1022 SchedulerClientWithFixedEstimates( | 997 SchedulerClientWithFixedEstimates( |
1023 base::TimeDelta draw_duration, | 998 base::TimeDelta draw_duration, |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1059 scheduler->SetCanStart(); | 1034 scheduler->SetCanStart(); |
1060 scheduler->SetVisible(true); | 1035 scheduler->SetVisible(true); |
1061 scheduler->SetCanDraw(true); | 1036 scheduler->SetCanDraw(true); |
1062 scheduler->SetSmoothnessTakesPriority(smoothness_takes_priority); | 1037 scheduler->SetSmoothnessTakesPriority(smoothness_takes_priority); |
1063 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | 1038 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
1064 | 1039 |
1065 // Impl thread hits deadline before commit finishes. | 1040 // Impl thread hits deadline before commit finishes. |
1066 client.Reset(); | 1041 client.Reset(); |
1067 scheduler->SetNeedsCommit(); | 1042 scheduler->SetNeedsCommit(); |
1068 EXPECT_FALSE(scheduler->MainThreadIsInHighLatencyMode()); | 1043 EXPECT_FALSE(scheduler->MainThreadIsInHighLatencyMode()); |
1069 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | 1044 client.AdvanceFrame(); |
1070 EXPECT_FALSE(scheduler->MainThreadIsInHighLatencyMode()); | 1045 EXPECT_FALSE(scheduler->MainThreadIsInHighLatencyMode()); |
1071 client.task_runner().RunPendingTasks(); // Run posted deadline. | 1046 client.task_runner().RunPendingTasks(); // Run posted deadline. |
1072 EXPECT_TRUE(scheduler->MainThreadIsInHighLatencyMode()); | 1047 EXPECT_TRUE(scheduler->MainThreadIsInHighLatencyMode()); |
1073 scheduler->NotifyBeginMainFrameStarted(); | 1048 scheduler->NotifyBeginMainFrameStarted(); |
1074 scheduler->NotifyReadyToCommit(); | 1049 scheduler->NotifyReadyToCommit(); |
1075 EXPECT_TRUE(scheduler->MainThreadIsInHighLatencyMode()); | 1050 EXPECT_TRUE(scheduler->MainThreadIsInHighLatencyMode()); |
1076 EXPECT_TRUE(client.HasAction("ScheduledActionSendBeginMainFrame")); | 1051 EXPECT_TRUE(client.HasAction("ScheduledActionSendBeginMainFrame")); |
1077 | 1052 |
1078 client.Reset(); | 1053 client.Reset(); |
1079 scheduler->SetNeedsCommit(); | 1054 scheduler->SetNeedsCommit(); |
1080 EXPECT_TRUE(scheduler->MainThreadIsInHighLatencyMode()); | 1055 EXPECT_TRUE(scheduler->MainThreadIsInHighLatencyMode()); |
1081 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | 1056 client.AdvanceFrame(); |
1082 EXPECT_TRUE(scheduler->MainThreadIsInHighLatencyMode()); | 1057 EXPECT_TRUE(scheduler->MainThreadIsInHighLatencyMode()); |
1083 client.task_runner().RunPendingTasks(); // Run posted deadline. | 1058 client.task_runner().RunPendingTasks(); // Run posted deadline. |
1084 EXPECT_EQ(scheduler->MainThreadIsInHighLatencyMode(), | 1059 EXPECT_EQ(scheduler->MainThreadIsInHighLatencyMode(), |
1085 should_send_begin_main_frame); | 1060 should_send_begin_main_frame); |
1086 EXPECT_EQ(client.HasAction("ScheduledActionSendBeginMainFrame"), | 1061 EXPECT_EQ(client.HasAction("ScheduledActionSendBeginMainFrame"), |
1087 should_send_begin_main_frame); | 1062 should_send_begin_main_frame); |
1088 } | 1063 } |
1089 | 1064 |
1090 TEST(SchedulerTest, | 1065 TEST(SchedulerTest, |
1091 SkipMainFrameIfHighLatencyAndCanCommitAndActivateBeforeDeadline) { | 1066 SkipMainFrameIfHighLatencyAndCanCommitAndActivateBeforeDeadline) { |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1128 scheduler->SetCanStart(); | 1103 scheduler->SetCanStart(); |
1129 scheduler->SetVisible(true); | 1104 scheduler->SetVisible(true); |
1130 scheduler->DidCreateAndInitializeOutputSurface(); | 1105 scheduler->DidCreateAndInitializeOutputSurface(); |
1131 | 1106 |
1132 scheduler->SetNeedsCommit(); | 1107 scheduler->SetNeedsCommit(); |
1133 EXPECT_TRUE(scheduler->CommitPending()); | 1108 EXPECT_TRUE(scheduler->CommitPending()); |
1134 scheduler->NotifyBeginMainFrameStarted(); | 1109 scheduler->NotifyBeginMainFrameStarted(); |
1135 scheduler->NotifyReadyToCommit(); | 1110 scheduler->NotifyReadyToCommit(); |
1136 scheduler->SetNeedsRedraw(); | 1111 scheduler->SetNeedsRedraw(); |
1137 | 1112 |
1138 BeginFrameArgs frame_args = CreateBeginFrameArgsForTesting(); | 1113 BeginFrameArgs frame_args = CreateBeginFrameArgsForTesting(client.now_src()); |
1139 frame_args.interval = base::TimeDelta::FromMilliseconds(1000); | 1114 frame_args.interval = base::TimeDelta::FromMilliseconds(1000); |
1140 scheduler->BeginFrame(frame_args); | 1115 { |
| 1116 TRACE_EVENT1("cc", |
| 1117 "SchedulerTest::PollForCommitCompletion", |
| 1118 "frame_args", |
| 1119 frame_args.AsValue()); |
| 1120 scheduler->BeginFrame(frame_args); |
| 1121 } |
1141 | 1122 |
1142 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1123 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
1143 client.task_runner().RunPendingTasks(); // Run posted deadline. | 1124 client.task_runner().RunPendingTasks(); // Run posted deadline. |
1144 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 1125 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
1145 | 1126 |
1146 scheduler->DidSwapBuffers(); | 1127 scheduler->DidSwapBuffers(); |
1147 scheduler->DidSwapBuffersComplete(); | 1128 scheduler->DidSwapBuffersComplete(); |
1148 | 1129 |
1149 // At this point, we've drawn a frame. Start another commit, but hold off on | 1130 // At this point, we've drawn a frame. Start another commit, but hold off on |
1150 // the NotifyReadyToCommit for now. | 1131 // the NotifyReadyToCommit for now. |
1151 EXPECT_FALSE(scheduler->CommitPending()); | 1132 EXPECT_FALSE(scheduler->CommitPending()); |
1152 scheduler->SetNeedsCommit(); | 1133 scheduler->SetNeedsCommit(); |
1153 scheduler->BeginFrame(frame_args); | 1134 { |
| 1135 TRACE_EVENT1("cc", |
| 1136 "SchedulerTest::PollForCommitCompletion", |
| 1137 "frame_args", |
| 1138 frame_args.AsValue()); |
| 1139 scheduler->BeginFrame(frame_args); |
| 1140 } |
1154 EXPECT_TRUE(scheduler->CommitPending()); | 1141 EXPECT_TRUE(scheduler->CommitPending()); |
1155 | 1142 |
1156 // Draw and swap the frame, but don't ack the swap to simulate the Browser | 1143 // Draw and swap the frame, but don't ack the swap to simulate the Browser |
1157 // blocking on the renderer. | 1144 // blocking on the renderer. |
1158 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1145 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
1159 client.task_runner().RunPendingTasks(); // Run posted deadline. | 1146 client.task_runner().RunPendingTasks(); // Run posted deadline. |
1160 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 1147 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
1161 scheduler->DidSwapBuffers(); | 1148 scheduler->DidSwapBuffers(); |
1162 | 1149 |
1163 // Spin the event loop a few times and make sure we get more | 1150 // Spin the event loop a few times and make sure we get more |
1164 // DidAnticipateDrawTimeChange calls every time. | 1151 // DidAnticipateDrawTimeChange calls every time. |
1165 int actions_so_far = client.num_actions_(); | 1152 int actions_so_far = client.num_actions_(); |
1166 | 1153 |
1167 // Does three iterations to make sure that the timer is properly repeating. | 1154 // Does three iterations to make sure that the timer is properly repeating. |
1168 for (int i = 0; i < 3; ++i) { | 1155 for (int i = 0; i < 3; ++i) { |
1169 EXPECT_EQ((frame_args.interval * 2).InMicroseconds(), | 1156 EXPECT_EQ((frame_args.interval * 2).InMicroseconds(), |
1170 client.task_runner().NextPendingTaskDelay().InMicroseconds()) | 1157 client.task_runner().DelayToNextPendingTask().InMicroseconds()) |
1171 << scheduler->AsValue()->ToString(); | 1158 << scheduler->AsValue()->ToString(); |
1172 client.task_runner().RunPendingTasks(); | 1159 client.task_runner().RunPendingTasks(); |
1173 EXPECT_GT(client.num_actions_(), actions_so_far); | 1160 EXPECT_GT(client.num_actions_(), actions_so_far); |
1174 EXPECT_STREQ(client.Action(client.num_actions_() - 1), | 1161 EXPECT_STREQ(client.Action(client.num_actions_() - 1), |
1175 "DidAnticipatedDrawTimeChange"); | 1162 "DidAnticipatedDrawTimeChange"); |
1176 actions_so_far = client.num_actions_(); | 1163 actions_so_far = client.num_actions_(); |
1177 } | 1164 } |
1178 | 1165 |
1179 // Do the same thing after BeginMainFrame starts but still before activation. | 1166 // Do the same thing after BeginMainFrame starts but still before activation. |
1180 scheduler->NotifyBeginMainFrameStarted(); | 1167 scheduler->NotifyBeginMainFrameStarted(); |
1181 for (int i = 0; i < 3; ++i) { | 1168 for (int i = 0; i < 3; ++i) { |
1182 EXPECT_EQ((frame_args.interval * 2).InMicroseconds(), | 1169 EXPECT_EQ((frame_args.interval * 2).InMicroseconds(), |
1183 client.task_runner().NextPendingTaskDelay().InMicroseconds()) | 1170 client.task_runner().DelayToNextPendingTask().InMicroseconds()) |
1184 << scheduler->AsValue()->ToString(); | 1171 << scheduler->AsValue()->ToString(); |
1185 client.task_runner().RunPendingTasks(); | 1172 client.task_runner().RunPendingTasks(); |
1186 EXPECT_GT(client.num_actions_(), actions_so_far); | 1173 EXPECT_GT(client.num_actions_(), actions_so_far); |
1187 EXPECT_STREQ(client.Action(client.num_actions_() - 1), | 1174 EXPECT_STREQ(client.Action(client.num_actions_() - 1), |
1188 "DidAnticipatedDrawTimeChange"); | 1175 "DidAnticipatedDrawTimeChange"); |
1189 actions_so_far = client.num_actions_(); | 1176 actions_so_far = client.num_actions_(); |
1190 } | 1177 } |
1191 } | 1178 } |
1192 | 1179 |
1193 TEST(SchedulerTest, BeginRetroFrame) { | 1180 TEST(SchedulerTest, BeginRetroFrame) { |
1194 FakeSchedulerClient client; | 1181 FakeSchedulerClient client; |
1195 SchedulerSettings scheduler_settings; | 1182 SchedulerSettings scheduler_settings; |
1196 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings); | 1183 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings); |
1197 scheduler->SetCanStart(); | 1184 scheduler->SetCanStart(); |
1198 scheduler->SetVisible(true); | 1185 scheduler->SetVisible(true); |
1199 scheduler->SetCanDraw(true); | 1186 scheduler->SetCanDraw(true); |
1200 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | 1187 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
1201 | 1188 |
1202 // SetNeedsCommit should begin the frame on the next BeginImplFrame. | 1189 // SetNeedsCommit should begin the frame on the next BeginImplFrame. |
1203 client.Reset(); | 1190 client.Reset(); |
1204 scheduler->SetNeedsCommit(); | 1191 scheduler->SetNeedsCommit(); |
1205 EXPECT_TRUE(client.needs_begin_frame()); | 1192 EXPECT_TRUE(client.needs_begin_frame()); |
1206 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); | 1193 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); |
1207 client.Reset(); | 1194 client.Reset(); |
1208 | 1195 |
1209 // Create a BeginFrame with a long deadline to avoid race conditions. | 1196 // Create a BeginFrame with a long deadline to avoid race conditions. |
1210 // This is the first BeginFrame, which will be handled immediately. | 1197 // This is the first BeginFrame, which will be handled immediately. |
1211 BeginFrameArgs args = CreateBeginFrameArgsForTesting(); | 1198 BeginFrameArgs args = CreateBeginFrameArgsForTesting(client.now_src()); |
1212 args.deadline += base::TimeDelta::FromHours(1); | 1199 args.deadline += base::TimeDelta::FromHours(1); |
1213 scheduler->BeginFrame(args); | 1200 { |
| 1201 TRACE_EVENT1( |
| 1202 "cc", "SchedulerTest::BeginRetroFrame", "frame_args", args.AsValue()); |
| 1203 scheduler->BeginFrame(args); |
| 1204 } |
1214 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 1205 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
1215 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); | 1206 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); |
1216 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1207 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
1217 EXPECT_TRUE(client.needs_begin_frame()); | 1208 EXPECT_TRUE(client.needs_begin_frame()); |
1218 client.Reset(); | 1209 client.Reset(); |
1219 | 1210 |
1220 // Queue BeginFrames while we are still handling the previous BeginFrame. | 1211 // Queue BeginFrames while we are still handling the previous BeginFrame. |
1221 args.frame_time += base::TimeDelta::FromSeconds(1); | 1212 args.frame_time += base::TimeDelta::FromSeconds(1); |
1222 scheduler->BeginFrame(args); | 1213 { |
| 1214 TRACE_EVENT1( |
| 1215 "cc", "SchedulerTest::BeginRetroFrame", "frame_args", args.AsValue()); |
| 1216 scheduler->BeginFrame(args); |
| 1217 } |
1223 args.frame_time += base::TimeDelta::FromSeconds(1); | 1218 args.frame_time += base::TimeDelta::FromSeconds(1); |
1224 scheduler->BeginFrame(args); | 1219 { |
| 1220 TRACE_EVENT1( |
| 1221 "cc", "SchedulerTest::BeginRetroFrame", "frame_args", args.AsValue()); |
| 1222 scheduler->BeginFrame(args); |
| 1223 } |
1225 | 1224 |
1226 // If we don't swap on the deadline, we wait for the next BeginImplFrame. | 1225 // If we don't swap on the deadline, we wait for the next BeginImplFrame. |
1227 client.task_runner().RunPendingTasks(); // Run posted deadline. | 1226 client.task_runner().RunPendingTasks(); // Run posted deadline. |
1228 EXPECT_NO_ACTION(client); | 1227 EXPECT_NO_ACTION(client); |
1229 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 1228 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
1230 EXPECT_TRUE(client.needs_begin_frame()); | 1229 EXPECT_TRUE(client.needs_begin_frame()); |
1231 client.Reset(); | 1230 client.Reset(); |
1232 | 1231 |
1233 // NotifyReadyToCommit should trigger the commit. | 1232 // NotifyReadyToCommit should trigger the commit. |
1234 scheduler->NotifyBeginMainFrameStarted(); | 1233 scheduler->NotifyBeginMainFrameStarted(); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1280 | 1279 |
1281 // SetNeedsCommit should begin the frame on the next BeginImplFrame. | 1280 // SetNeedsCommit should begin the frame on the next BeginImplFrame. |
1282 client.Reset(); | 1281 client.Reset(); |
1283 scheduler->SetNeedsCommit(); | 1282 scheduler->SetNeedsCommit(); |
1284 EXPECT_TRUE(client.needs_begin_frame()); | 1283 EXPECT_TRUE(client.needs_begin_frame()); |
1285 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); | 1284 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); |
1286 client.Reset(); | 1285 client.Reset(); |
1287 | 1286 |
1288 // Create a BeginFrame with a long deadline to avoid race conditions. | 1287 // Create a BeginFrame with a long deadline to avoid race conditions. |
1289 // This is the first BeginFrame, which will be handled immediately. | 1288 // This is the first BeginFrame, which will be handled immediately. |
1290 BeginFrameArgs args = CreateBeginFrameArgsForTesting(); | 1289 BeginFrameArgs args = CreateBeginFrameArgsForTesting(client.now_src()); |
1291 args.deadline += base::TimeDelta::FromHours(1); | 1290 args.deadline += base::TimeDelta::FromHours(1); |
1292 scheduler->BeginFrame(args); | 1291 { |
| 1292 TRACE_EVENT1("cc", |
| 1293 "SchedulerTest::BeginRetroFrame_SwapThrottled", |
| 1294 "frame_args", |
| 1295 args.AsValue()); |
| 1296 scheduler->BeginFrame(args); |
| 1297 } |
1293 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 1298 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
1294 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); | 1299 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); |
1295 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1300 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
1296 EXPECT_TRUE(client.needs_begin_frame()); | 1301 EXPECT_TRUE(client.needs_begin_frame()); |
1297 client.Reset(); | 1302 client.Reset(); |
1298 | 1303 |
1299 // Queue BeginFrame while we are still handling the previous BeginFrame. | 1304 // Queue BeginFrame while we are still handling the previous BeginFrame. |
1300 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1305 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
1301 args.frame_time += base::TimeDelta::FromSeconds(1); | 1306 args.frame_time += base::TimeDelta::FromSeconds(1); |
1302 scheduler->BeginFrame(args); | 1307 { |
| 1308 TRACE_EVENT1("cc", |
| 1309 "SchedulerTest::BeginRetroFrame_SwapThrottled", |
| 1310 "frame_args", |
| 1311 args.AsValue()); |
| 1312 scheduler->BeginFrame(args); |
| 1313 } |
1303 EXPECT_NO_ACTION(client); | 1314 EXPECT_NO_ACTION(client); |
1304 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1315 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
1305 client.Reset(); | 1316 client.Reset(); |
1306 | 1317 |
1307 // NotifyReadyToCommit should trigger the pending commit and draw. | 1318 // NotifyReadyToCommit should trigger the pending commit and draw. |
1308 scheduler->NotifyBeginMainFrameStarted(); | 1319 scheduler->NotifyBeginMainFrameStarted(); |
1309 scheduler->NotifyReadyToCommit(); | 1320 scheduler->NotifyReadyToCommit(); |
1310 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); | 1321 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); |
1311 EXPECT_TRUE(client.needs_begin_frame()); | 1322 EXPECT_TRUE(client.needs_begin_frame()); |
1312 client.Reset(); | 1323 client.Reset(); |
(...skipping 10 matching lines...) Expand all Loading... |
1323 // but not a BeginMainFrame or draw. | 1334 // but not a BeginMainFrame or draw. |
1324 scheduler->SetNeedsCommit(); | 1335 scheduler->SetNeedsCommit(); |
1325 client.task_runner().RunPendingTasks(); // Run posted BeginRetroFrame. | 1336 client.task_runner().RunPendingTasks(); // Run posted BeginRetroFrame. |
1326 EXPECT_ACTION("WillBeginImplFrame", client, 0, 1); | 1337 EXPECT_ACTION("WillBeginImplFrame", client, 0, 1); |
1327 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1338 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
1328 EXPECT_TRUE(client.needs_begin_frame()); | 1339 EXPECT_TRUE(client.needs_begin_frame()); |
1329 client.Reset(); | 1340 client.Reset(); |
1330 | 1341 |
1331 // Queue BeginFrame while we are still handling the previous BeginFrame. | 1342 // Queue BeginFrame while we are still handling the previous BeginFrame. |
1332 args.frame_time += base::TimeDelta::FromSeconds(1); | 1343 args.frame_time += base::TimeDelta::FromSeconds(1); |
1333 scheduler->BeginFrame(args); | 1344 { |
| 1345 TRACE_EVENT1("cc", |
| 1346 "SchedulerTest::BeginRetroFrame_SwapThrottled", |
| 1347 "frame_args", |
| 1348 args.AsValue()); |
| 1349 scheduler->BeginFrame(args); |
| 1350 } |
1334 EXPECT_NO_ACTION(client); | 1351 EXPECT_NO_ACTION(client); |
1335 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1352 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
1336 EXPECT_TRUE(client.needs_begin_frame()); | 1353 EXPECT_TRUE(client.needs_begin_frame()); |
1337 client.Reset(); | 1354 client.Reset(); |
1338 | 1355 |
1339 // Take us out of a swap throttled state. | 1356 // Take us out of a swap throttled state. |
1340 scheduler->DidSwapBuffersComplete(); | 1357 scheduler->DidSwapBuffersComplete(); |
1341 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 0, 1); | 1358 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 0, 1); |
1342 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1359 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
1343 EXPECT_TRUE(client.needs_begin_frame()); | 1360 EXPECT_TRUE(client.needs_begin_frame()); |
1344 client.Reset(); | 1361 client.Reset(); |
1345 | 1362 |
1346 // BeginImplFrame deadline should draw. | 1363 // BeginImplFrame deadline should draw. |
1347 scheduler->SetNeedsRedraw(); | 1364 scheduler->SetNeedsRedraw(); |
| 1365 |
| 1366 // As we are now in polling mode - force time forward to next |
| 1367 // ScheduleBeginImplFrameDeadline task. |
| 1368 client.now_src()->AdvanceNow(base::TimeDelta::FromSeconds(1)); |
1348 client.task_runner().RunPendingTasks(); // Run posted deadline. | 1369 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 1370 |
1349 EXPECT_ACTION("ScheduledActionAnimate", client, 0, 2); | 1371 EXPECT_ACTION("ScheduledActionAnimate", client, 0, 2); |
1350 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 1, 2); | 1372 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 1, 2); |
1351 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 1373 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
1352 EXPECT_TRUE(client.needs_begin_frame()); | 1374 EXPECT_TRUE(client.needs_begin_frame()); |
1353 client.Reset(); | 1375 client.Reset(); |
1354 } | 1376 } |
1355 | 1377 |
1356 void BeginFramesNotFromClient(bool begin_frame_scheduling_enabled, | 1378 void BeginFramesNotFromClient(bool begin_frame_scheduling_enabled, |
1357 bool throttle_frame_production) { | 1379 bool throttle_frame_production) { |
1358 FakeSchedulerClient client; | 1380 FakeSchedulerClient client; |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1570 scheduler->SetCanDraw(true); | 1592 scheduler->SetCanDraw(true); |
1571 | 1593 |
1572 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); | 1594 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); |
1573 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | 1595 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
1574 // SetNeedsCommit should begin the frame. | 1596 // SetNeedsCommit should begin the frame. |
1575 client.Reset(); | 1597 client.Reset(); |
1576 scheduler->SetNeedsCommit(); | 1598 scheduler->SetNeedsCommit(); |
1577 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); | 1599 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); |
1578 | 1600 |
1579 client.Reset(); | 1601 client.Reset(); |
1580 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | 1602 client.AdvanceFrame(); |
1581 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 1603 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
1582 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); | 1604 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); |
1583 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1605 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
1584 | 1606 |
1585 client.Reset(); | 1607 client.Reset(); |
1586 scheduler->DidLoseOutputSurface(); | 1608 scheduler->DidLoseOutputSurface(); |
1587 // Do nothing when impl frame is in deadine pending state. | 1609 // Do nothing when impl frame is in deadine pending state. |
1588 EXPECT_NO_ACTION(client); | 1610 EXPECT_NO_ACTION(client); |
1589 | 1611 |
1590 client.Reset(); | 1612 client.Reset(); |
(...skipping 18 matching lines...) Expand all Loading... |
1609 | 1631 |
1610 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); | 1632 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); |
1611 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | 1633 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
1612 | 1634 |
1613 // SetNeedsCommit should begin the frame. | 1635 // SetNeedsCommit should begin the frame. |
1614 client.Reset(); | 1636 client.Reset(); |
1615 scheduler->SetNeedsCommit(); | 1637 scheduler->SetNeedsCommit(); |
1616 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); | 1638 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); |
1617 | 1639 |
1618 client.Reset(); | 1640 client.Reset(); |
1619 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | 1641 client.AdvanceFrame(); |
1620 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 1642 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
1621 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); | 1643 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); |
1622 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1644 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
1623 | 1645 |
1624 client.Reset(); | 1646 client.Reset(); |
1625 scheduler->DidLoseOutputSurface(); | 1647 scheduler->DidLoseOutputSurface(); |
1626 // Do nothing when impl frame is in deadine pending state. | 1648 // Do nothing when impl frame is in deadine pending state. |
1627 EXPECT_NO_ACTION(client); | 1649 EXPECT_NO_ACTION(client); |
1628 | 1650 |
1629 client.Reset(); | 1651 client.Reset(); |
1630 client.task_runner().RunPendingTasks(); // Run posted deadline. | 1652 client.task_runner().RunPendingTasks(); // Run posted deadline. |
1631 // OnBeginImplFrameDeadline didn't schedule any actions because main frame is | 1653 // OnBeginImplFrameDeadline didn't schedule any actions because main frame is |
1632 // not yet completed. | 1654 // not yet completed. |
1633 EXPECT_NO_ACTION(client); | 1655 EXPECT_NO_ACTION(client); |
1634 | 1656 |
1635 // BeginImplFrame is not started. | 1657 // BeginImplFrame is not started. |
1636 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | 1658 client.AdvanceFrame(); |
1637 EXPECT_NO_ACTION(client); | 1659 EXPECT_NO_ACTION(client); |
1638 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 1660 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
1639 | 1661 |
1640 client.Reset(); | 1662 client.Reset(); |
1641 scheduler->NotifyBeginMainFrameStarted(); | 1663 scheduler->NotifyBeginMainFrameStarted(); |
1642 scheduler->NotifyReadyToCommit(); | 1664 scheduler->NotifyReadyToCommit(); |
1643 if (impl_side_painting) { | 1665 if (impl_side_painting) { |
1644 EXPECT_ACTION("ScheduledActionCommit", client, 0, 3); | 1666 EXPECT_ACTION("ScheduledActionCommit", client, 0, 3); |
1645 EXPECT_ACTION("ScheduledActionActivateSyncTree", client, 1, 3); | 1667 EXPECT_ACTION("ScheduledActionActivateSyncTree", client, 1, 3); |
1646 EXPECT_ACTION("ScheduledActionBeginOutputSurfaceCreation", client, 2, 3); | 1668 EXPECT_ACTION("ScheduledActionBeginOutputSurfaceCreation", client, 2, 3); |
(...skipping 25 matching lines...) Expand all Loading... |
1672 | 1694 |
1673 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); | 1695 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); |
1674 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | 1696 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
1675 | 1697 |
1676 // SetNeedsCommit should begin the frame. | 1698 // SetNeedsCommit should begin the frame. |
1677 client.Reset(); | 1699 client.Reset(); |
1678 scheduler->SetNeedsCommit(); | 1700 scheduler->SetNeedsCommit(); |
1679 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); | 1701 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); |
1680 | 1702 |
1681 client.Reset(); | 1703 client.Reset(); |
1682 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | 1704 client.AdvanceFrame(); |
1683 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 1705 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
1684 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); | 1706 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); |
1685 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1707 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
1686 | 1708 |
1687 client.Reset(); | 1709 client.Reset(); |
1688 scheduler->NotifyBeginMainFrameStarted(); | 1710 scheduler->NotifyBeginMainFrameStarted(); |
1689 scheduler->NotifyReadyToCommit(); | 1711 scheduler->NotifyReadyToCommit(); |
1690 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); | 1712 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); |
1691 | 1713 |
1692 client.Reset(); | 1714 client.Reset(); |
(...skipping 28 matching lines...) Expand all Loading... |
1721 scheduler->SetCanDraw(true); | 1743 scheduler->SetCanDraw(true); |
1722 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | 1744 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
1723 | 1745 |
1724 client.Reset(); | 1746 client.Reset(); |
1725 scheduler->SetNeedsManageTiles(); | 1747 scheduler->SetNeedsManageTiles(); |
1726 scheduler->SetNeedsRedraw(); | 1748 scheduler->SetNeedsRedraw(); |
1727 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); | 1749 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); |
1728 EXPECT_TRUE(client.needs_begin_frame()); | 1750 EXPECT_TRUE(client.needs_begin_frame()); |
1729 | 1751 |
1730 client.Reset(); | 1752 client.Reset(); |
1731 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | 1753 client.AdvanceFrame(); |
1732 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 1754 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
1733 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); | 1755 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); |
1734 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1756 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
1735 | 1757 |
1736 client.Reset(); | 1758 client.Reset(); |
1737 scheduler->DidLoseOutputSurface(); | 1759 scheduler->DidLoseOutputSurface(); |
1738 EXPECT_NO_ACTION(client); | 1760 EXPECT_NO_ACTION(client); |
1739 | 1761 |
1740 client.Reset(); | 1762 client.Reset(); |
1741 client.task_runner().RunPendingTasks(); // Run posted deadline. | 1763 client.task_runner().RunPendingTasks(); // Run posted deadline. |
(...skipping 12 matching lines...) Expand all Loading... |
1754 | 1776 |
1755 // SetNeedsCommit should begin the frame on the next BeginImplFrame. | 1777 // SetNeedsCommit should begin the frame on the next BeginImplFrame. |
1756 client.Reset(); | 1778 client.Reset(); |
1757 scheduler->SetNeedsCommit(); | 1779 scheduler->SetNeedsCommit(); |
1758 EXPECT_TRUE(client.needs_begin_frame()); | 1780 EXPECT_TRUE(client.needs_begin_frame()); |
1759 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); | 1781 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); |
1760 | 1782 |
1761 // Create a BeginFrame with a long deadline to avoid race conditions. | 1783 // Create a BeginFrame with a long deadline to avoid race conditions. |
1762 // This is the first BeginFrame, which will be handled immediately. | 1784 // This is the first BeginFrame, which will be handled immediately. |
1763 client.Reset(); | 1785 client.Reset(); |
1764 BeginFrameArgs args = CreateBeginFrameArgsForTesting(); | 1786 BeginFrameArgs args = CreateBeginFrameArgsForTesting(client.now_src()); |
1765 args.deadline += base::TimeDelta::FromHours(1); | 1787 args.deadline += base::TimeDelta::FromHours(1); |
1766 scheduler->BeginFrame(args); | 1788 { |
| 1789 TRACE_EVENT1( |
| 1790 "cc", |
| 1791 "SchedulerTest::DidLoseOutputSurfaceAfterBeginRetroFramePosted", |
| 1792 "frame_args", |
| 1793 args.AsValue()); |
| 1794 scheduler->BeginFrame(args); |
| 1795 } |
1767 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 1796 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
1768 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); | 1797 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); |
1769 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1798 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
1770 EXPECT_TRUE(client.needs_begin_frame()); | 1799 EXPECT_TRUE(client.needs_begin_frame()); |
1771 | 1800 |
1772 // Queue BeginFrames while we are still handling the previous BeginFrame. | 1801 // Queue BeginFrames while we are still handling the previous BeginFrame. |
1773 args.frame_time += base::TimeDelta::FromSeconds(1); | 1802 args.frame_time += base::TimeDelta::FromSeconds(1); |
1774 scheduler->BeginFrame(args); | 1803 { |
| 1804 TRACE_EVENT1( |
| 1805 "cc", |
| 1806 "SchedulerTest::DidLoseOutputSurfaceAfterBeginRetroFramePosted", |
| 1807 "frame_args", |
| 1808 args.AsValue()); |
| 1809 scheduler->BeginFrame(args); |
| 1810 } |
1775 args.frame_time += base::TimeDelta::FromSeconds(1); | 1811 args.frame_time += base::TimeDelta::FromSeconds(1); |
1776 scheduler->BeginFrame(args); | 1812 { |
| 1813 TRACE_EVENT1( |
| 1814 "cc", |
| 1815 "SchedulerTest::DidLoseOutputSurfaceAfterBeginRetroFramePosted", |
| 1816 "frame_args", |
| 1817 args.AsValue()); |
| 1818 scheduler->BeginFrame(args); |
| 1819 } |
1777 | 1820 |
1778 // If we don't swap on the deadline, we wait for the next BeginImplFrame. | 1821 // If we don't swap on the deadline, we wait for the next BeginImplFrame. |
1779 client.Reset(); | 1822 client.Reset(); |
1780 client.task_runner().RunPendingTasks(); // Run posted deadline. | 1823 client.task_runner().RunPendingTasks(); // Run posted deadline. |
1781 EXPECT_NO_ACTION(client); | 1824 EXPECT_NO_ACTION(client); |
1782 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 1825 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
1783 EXPECT_TRUE(client.needs_begin_frame()); | 1826 EXPECT_TRUE(client.needs_begin_frame()); |
1784 | 1827 |
1785 // NotifyReadyToCommit should trigger the commit. | 1828 // NotifyReadyToCommit should trigger the commit. |
1786 client.Reset(); | 1829 client.Reset(); |
(...skipping 26 matching lines...) Expand all Loading... |
1813 | 1856 |
1814 // SetNeedsCommit should begin the frame on the next BeginImplFrame. | 1857 // SetNeedsCommit should begin the frame on the next BeginImplFrame. |
1815 client.Reset(); | 1858 client.Reset(); |
1816 scheduler->SetNeedsCommit(); | 1859 scheduler->SetNeedsCommit(); |
1817 EXPECT_TRUE(client.needs_begin_frame()); | 1860 EXPECT_TRUE(client.needs_begin_frame()); |
1818 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); | 1861 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); |
1819 | 1862 |
1820 // Create a BeginFrame with a long deadline to avoid race conditions. | 1863 // Create a BeginFrame with a long deadline to avoid race conditions. |
1821 // This is the first BeginFrame, which will be handled immediately. | 1864 // This is the first BeginFrame, which will be handled immediately. |
1822 client.Reset(); | 1865 client.Reset(); |
1823 BeginFrameArgs args = CreateBeginFrameArgsForTesting(); | 1866 BeginFrameArgs args = CreateBeginFrameArgsForTesting(client.now_src()); |
1824 args.deadline += base::TimeDelta::FromHours(1); | 1867 args.deadline += base::TimeDelta::FromHours(1); |
1825 scheduler->BeginFrame(args); | 1868 { |
| 1869 TRACE_EVENT1( |
| 1870 "cc", |
| 1871 "SchedulerTest::DidLoseOutputSurfaceDuringBeginRetroFrameRunning", |
| 1872 "frame_args", |
| 1873 args.AsValue()); |
| 1874 scheduler->BeginFrame(args); |
| 1875 } |
1826 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 1876 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
1827 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); | 1877 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); |
1828 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1878 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
1829 EXPECT_TRUE(client.needs_begin_frame()); | 1879 EXPECT_TRUE(client.needs_begin_frame()); |
1830 | 1880 |
1831 // Queue BeginFrames while we are still handling the previous BeginFrame. | 1881 // Queue BeginFrames while we are still handling the previous BeginFrame. |
1832 args.frame_time += base::TimeDelta::FromSeconds(1); | 1882 args.frame_time += base::TimeDelta::FromSeconds(1); |
1833 scheduler->BeginFrame(args); | 1883 { |
| 1884 TRACE_EVENT1( |
| 1885 "cc", |
| 1886 "SchedulerTest::DidLoseOutputSurfaceDuringBeginRetroFrameRunning", |
| 1887 "frame_args", |
| 1888 args.AsValue()); |
| 1889 scheduler->BeginFrame(args); |
| 1890 } |
1834 args.frame_time += base::TimeDelta::FromSeconds(1); | 1891 args.frame_time += base::TimeDelta::FromSeconds(1); |
1835 scheduler->BeginFrame(args); | 1892 { |
| 1893 TRACE_EVENT1( |
| 1894 "cc", |
| 1895 "SchedulerTest::DidLoseOutputSurfaceDuringBeginRetroFrameRunning", |
| 1896 "frame_args", |
| 1897 args.AsValue()); |
| 1898 scheduler->BeginFrame(args); |
| 1899 } |
1836 | 1900 |
1837 // If we don't swap on the deadline, we wait for the next BeginImplFrame. | 1901 // If we don't swap on the deadline, we wait for the next BeginImplFrame. |
1838 client.Reset(); | 1902 client.Reset(); |
1839 client.task_runner().RunPendingTasks(); // Run posted deadline. | 1903 client.task_runner().RunPendingTasks(); // Run posted deadline. |
1840 EXPECT_NO_ACTION(client); | 1904 EXPECT_NO_ACTION(client); |
1841 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 1905 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
1842 EXPECT_TRUE(client.needs_begin_frame()); | 1906 EXPECT_TRUE(client.needs_begin_frame()); |
1843 | 1907 |
1844 // NotifyReadyToCommit should trigger the commit. | 1908 // NotifyReadyToCommit should trigger the commit. |
1845 client.Reset(); | 1909 client.Reset(); |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1912 EXPECT_FALSE(scheduler->IsSyntheticBeginFrameSourceActive()); | 1976 EXPECT_FALSE(scheduler->IsSyntheticBeginFrameSourceActive()); |
1913 | 1977 |
1914 client.Reset(); | 1978 client.Reset(); |
1915 client.task_runner().RunPendingTasks(); // Run posted deadline. | 1979 client.task_runner().RunPendingTasks(); // Run posted deadline. |
1916 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); | 1980 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); |
1917 EXPECT_FALSE(scheduler->IsSyntheticBeginFrameSourceActive()); | 1981 EXPECT_FALSE(scheduler->IsSyntheticBeginFrameSourceActive()); |
1918 } | 1982 } |
1919 | 1983 |
1920 } // namespace | 1984 } // namespace |
1921 } // namespace cc | 1985 } // namespace cc |
OLD | NEW |