Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(12)

Side by Side Diff: cc/scheduler/scheduler_unittest.cc

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

Powered by Google App Engine
This is Rietveld 408576698