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