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

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

Issue 267783004: Refactoring the way begin frame sources inside scheduler work. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Lots of review comment fixes, plus addition of OnMissedBeginFrame. Created 6 years, 3 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/debug/trace_event.h" 9 #include "base/debug/trace_event.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 27 matching lines...) Expand all
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 FakeSchedulerClient : public SchedulerClient { 46 class FakeSchedulerClient : public SchedulerClient {
47 public: 47 public:
48 struct FakeBeginFrameSourceForFakeSchedulerClient
49 : public FakeBeginFrameSource {
50 FakeSchedulerClient* client_;
51
52 explicit FakeBeginFrameSourceForFakeSchedulerClient(
53 FakeSchedulerClient* client)
54 : client_(client) {}
55
56 virtual void SetNeedsBeginFrames(bool needs_begin_frames) OVERRIDE {
57 FakeBeginFrameSource::SetNeedsBeginFrames(needs_begin_frames);
58 if (needs_begin_frames) {
59 client_->actions_.push_back("SetNeedsBeginFrames(true)");
60 } else {
61 client_->actions_.push_back("SetNeedsBeginFrames(false)");
62 }
63 client_->states_.push_back(client_->scheduler_->AsValue());
64 }
65 };
66
48 FakeSchedulerClient() 67 FakeSchedulerClient()
49 : needs_begin_frame_(false), 68 : automatic_swap_ack_(true),
50 automatic_swap_ack_(true),
51 swap_contains_incomplete_tile_(false), 69 swap_contains_incomplete_tile_(false),
52 redraw_will_happen_if_update_visible_tiles_happens_(false), 70 redraw_will_happen_if_update_visible_tiles_happens_(false),
53 now_src_(TestNowSource::Create()) { 71 now_src_(TestNowSource::Create()),
72 fake_frame_source_(this) {
54 Reset(); 73 Reset();
55 } 74 }
56 75
57 void Reset() { 76 void Reset() {
58 actions_.clear(); 77 actions_.clear();
59 states_.clear(); 78 states_.clear();
60 draw_will_happen_ = true; 79 draw_will_happen_ = true;
61 swap_will_happen_if_draw_happens_ = true; 80 swap_will_happen_if_draw_happens_ = true;
62 num_draws_ = 0; 81 num_draws_ = 0;
63 log_anticipated_draw_time_change_ = false; 82 log_anticipated_draw_time_change_ = false;
64 } 83 }
65 84
66 TestScheduler* CreateScheduler(const SchedulerSettings& settings) { 85 TestScheduler* CreateScheduler(const SchedulerSettings& settings) {
67 scheduler_ = TestScheduler::Create(now_src_, this, settings, 0); 86 scheduler_ = TestScheduler::Create(now_src_, this, settings, 0);
87 DCHECK(scheduler_);
68 // Fail if we need to run 100 tasks in a row. 88 // Fail if we need to run 100 tasks in a row.
69 task_runner().SetRunTaskLimit(100); 89 task_runner().SetRunTaskLimit(100);
70 return scheduler_.get(); 90 return scheduler_.get();
71 } 91 }
72 92
73 // Most tests don't care about DidAnticipatedDrawTimeChange, so only record it 93 // Most tests don't care about DidAnticipatedDrawTimeChange, so only record it
74 // for tests that do. 94 // for tests that do.
75 void set_log_anticipated_draw_time_change(bool log) { 95 void set_log_anticipated_draw_time_change(bool log) {
76 log_anticipated_draw_time_change_ = log; 96 log_anticipated_draw_time_change_ = log;
77 } 97 }
78 bool needs_begin_frame() { return needs_begin_frame_; } 98 bool needs_begin_frames() { return fake_frame_source_.NeedsBeginFrames(); }
79 int num_draws() const { return num_draws_; } 99 int num_draws() const { return num_draws_; }
80 int num_actions_() const { return static_cast<int>(actions_.size()); } 100 int num_actions_() const { return static_cast<int>(actions_.size()); }
81 const char* Action(int i) const { return actions_[i]; } 101 const char* Action(int i) const { return actions_[i]; }
82 std::string StateForAction(int i) const { return states_[i]->ToString(); } 102 std::string StateForAction(int i) const { return states_[i]->ToString(); }
83 base::TimeTicks posted_begin_impl_frame_deadline() const { 103 base::TimeTicks posted_begin_impl_frame_deadline() const {
84 return posted_begin_impl_frame_deadline_; 104 return posted_begin_impl_frame_deadline_;
85 } 105 }
86 106
107 bool ExternalBeginFrame() {
108 return scheduler_->settings().begin_frame_scheduling_enabled &&
109 scheduler_->settings().throttle_frame_production;
110 }
111 virtual FakeBeginFrameSource* ExternalBeginFrameSource() OVERRIDE {
112 return &fake_frame_source_;
113 }
114
87 void AdvanceFrame() { 115 void AdvanceFrame() {
88 bool external_begin_frame = 116 if (ExternalBeginFrame()) {
89 scheduler_->settings().begin_frame_scheduling_enabled && 117 fake_frame_source_.TestOnBeginFrame(
90 scheduler_->settings().throttle_frame_production; 118 CreateBeginFrameArgsForTesting(now_src_));
91
92 if (external_begin_frame) {
93 scheduler_->BeginFrame(CreateBeginFrameArgsForTesting(now_src_));
94 } 119 }
95 120
96 EXPECT_TRUE(task_runner().RunTasksWhile(ImplFrameDeadlinePending(false))); 121 EXPECT_TRUE(task_runner().RunTasksWhile(ImplFrameDeadlinePending(false)));
97 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); 122 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending());
98 } 123 }
99 124
100 OrderedSimpleTaskRunner& task_runner() { return scheduler_->task_runner(); } 125 OrderedSimpleTaskRunner& task_runner() { return scheduler_->task_runner(); }
101 TestNowSource* now_src() { return now_src_.get(); } 126 TestNowSource* now_src() { return now_src_.get(); }
102 127
103 int ActionIndex(const char* action) const { 128 int ActionIndex(const char* action) const {
(...skipping 17 matching lines...) Expand all
121 void SetSwapWillHappenIfDrawHappens(bool swap_will_happen_if_draw_happens) { 146 void SetSwapWillHappenIfDrawHappens(bool swap_will_happen_if_draw_happens) {
122 swap_will_happen_if_draw_happens_ = swap_will_happen_if_draw_happens; 147 swap_will_happen_if_draw_happens_ = swap_will_happen_if_draw_happens;
123 } 148 }
124 void SetAutomaticSwapAck(bool automatic_swap_ack) { 149 void SetAutomaticSwapAck(bool automatic_swap_ack) {
125 automatic_swap_ack_ = automatic_swap_ack; 150 automatic_swap_ack_ = automatic_swap_ack;
126 } 151 }
127 void SetRedrawWillHappenIfUpdateVisibleTilesHappens(bool redraw) { 152 void SetRedrawWillHappenIfUpdateVisibleTilesHappens(bool redraw) {
128 redraw_will_happen_if_update_visible_tiles_happens_ = redraw; 153 redraw_will_happen_if_update_visible_tiles_happens_ = redraw;
129 } 154 }
130 // SchedulerClient implementation. 155 // SchedulerClient implementation.
131 virtual void SetNeedsBeginFrame(bool enable) OVERRIDE {
132 actions_.push_back("SetNeedsBeginFrame");
133 states_.push_back(scheduler_->AsValue());
134 needs_begin_frame_ = enable;
135 }
136 virtual void WillBeginImplFrame(const BeginFrameArgs& args) OVERRIDE { 156 virtual void WillBeginImplFrame(const BeginFrameArgs& args) OVERRIDE {
137 actions_.push_back("WillBeginImplFrame"); 157 actions_.push_back("WillBeginImplFrame");
138 states_.push_back(scheduler_->AsValue()); 158 states_.push_back(scheduler_->AsValue());
139 } 159 }
140 virtual void ScheduledActionSendBeginMainFrame() OVERRIDE { 160 virtual void ScheduledActionSendBeginMainFrame() OVERRIDE {
141 actions_.push_back("ScheduledActionSendBeginMainFrame"); 161 actions_.push_back("ScheduledActionSendBeginMainFrame");
142 states_.push_back(scheduler_->AsValue()); 162 states_.push_back(scheduler_->AsValue());
143 } 163 }
144 virtual void ScheduledActionAnimate() OVERRIDE { 164 virtual void ScheduledActionAnimate() OVERRIDE {
145 actions_.push_back("ScheduledActionAnimate"); 165 actions_.push_back("ScheduledActionAnimate");
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 return base::Bind(&FakeSchedulerClient::ImplFrameDeadlinePendingCallback, 234 return base::Bind(&FakeSchedulerClient::ImplFrameDeadlinePendingCallback,
215 base::Unretained(this), 235 base::Unretained(this),
216 state); 236 state);
217 } 237 }
218 238
219 protected: 239 protected:
220 bool ImplFrameDeadlinePendingCallback(bool state) { 240 bool ImplFrameDeadlinePendingCallback(bool state) {
221 return scheduler_->BeginImplFrameDeadlinePending() == state; 241 return scheduler_->BeginImplFrameDeadlinePending() == state;
222 } 242 }
223 243
224 bool needs_begin_frame_;
225 bool draw_will_happen_; 244 bool draw_will_happen_;
226 bool swap_will_happen_if_draw_happens_; 245 bool swap_will_happen_if_draw_happens_;
227 bool automatic_swap_ack_; 246 bool automatic_swap_ack_;
228 int num_draws_; 247 int num_draws_;
229 bool log_anticipated_draw_time_change_; 248 bool log_anticipated_draw_time_change_;
230 bool swap_contains_incomplete_tile_; 249 bool swap_contains_incomplete_tile_;
231 bool redraw_will_happen_if_update_visible_tiles_happens_; 250 bool redraw_will_happen_if_update_visible_tiles_happens_;
232 base::TimeTicks posted_begin_impl_frame_deadline_; 251 base::TimeTicks posted_begin_impl_frame_deadline_;
233 std::vector<const char*> actions_; 252 std::vector<const char*> actions_;
234 std::vector<scoped_refptr<base::debug::ConvertableToTraceFormat> > states_; 253 std::vector<scoped_refptr<base::debug::ConvertableToTraceFormat> > states_;
235 scoped_ptr<TestScheduler> scheduler_; 254 scoped_ptr<TestScheduler> scheduler_;
236 scoped_refptr<TestNowSource> now_src_; 255 scoped_refptr<TestNowSource> now_src_;
256 FakeBeginFrameSourceForFakeSchedulerClient fake_frame_source_;
237 }; 257 };
238 258
239 void InitializeOutputSurfaceAndFirstCommit(Scheduler* scheduler, 259 void InitializeOutputSurfaceAndFirstCommit(Scheduler* scheduler,
240 FakeSchedulerClient* client) { 260 FakeSchedulerClient* client) {
241 TRACE_EVENT0("cc", 261 TRACE_EVENT0("cc",
242 "SchedulerUnitTest::InitializeOutputSurfaceAndFirstCommit"); 262 "SchedulerUnitTest::InitializeOutputSurfaceAndFirstCommit");
243 263
244 scheduler->DidCreateAndInitializeOutputSurface(); 264 scheduler->DidCreateAndInitializeOutputSurface();
245 scheduler->SetNeedsCommit(); 265 scheduler->SetNeedsCommit();
246 scheduler->NotifyBeginMainFrameStarted(); 266 scheduler->NotifyBeginMainFrameStarted();
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 scheduler->SetCanStart(); 307 scheduler->SetCanStart();
288 scheduler->SetVisible(true); 308 scheduler->SetVisible(true);
289 scheduler->SetCanDraw(true); 309 scheduler->SetCanDraw(true);
290 310
291 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); 311 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client);
292 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); 312 InitializeOutputSurfaceAndFirstCommit(scheduler, &client);
293 313
294 // SetNeedsCommit should begin the frame on the next BeginImplFrame. 314 // SetNeedsCommit should begin the frame on the next BeginImplFrame.
295 client.Reset(); 315 client.Reset();
296 scheduler->SetNeedsCommit(); 316 scheduler->SetNeedsCommit();
297 EXPECT_TRUE(client.needs_begin_frame()); 317 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client);
298 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client);
299 client.Reset(); 318 client.Reset();
300 319
301 client.AdvanceFrame(); 320 client.AdvanceFrame();
302 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); 321 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2);
303 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); 322 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2);
304 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 323 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending());
305 EXPECT_TRUE(client.needs_begin_frame()); 324 EXPECT_TRUE(client.needs_begin_frames());
306 client.Reset(); 325 client.Reset();
307 326
308 // If we don't swap on the deadline, we wait for the next BeginFrame. 327 // If we don't swap on the deadline, we wait for the next BeginFrame.
309 client.task_runner().RunPendingTasks(); // Run posted deadline. 328 client.task_runner().RunPendingTasks(); // Run posted deadline.
310 EXPECT_NO_ACTION(client); 329 EXPECT_NO_ACTION(client);
311 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); 330 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending());
312 EXPECT_TRUE(client.needs_begin_frame()); 331 EXPECT_TRUE(client.needs_begin_frames());
313 client.Reset(); 332 client.Reset();
314 333
315 // NotifyReadyToCommit should trigger the commit. 334 // NotifyReadyToCommit should trigger the commit.
316 scheduler->NotifyBeginMainFrameStarted(); 335 scheduler->NotifyBeginMainFrameStarted();
317 scheduler->NotifyReadyToCommit(); 336 scheduler->NotifyReadyToCommit();
318 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); 337 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client);
319 EXPECT_TRUE(client.needs_begin_frame()); 338 EXPECT_TRUE(client.needs_begin_frames());
320 client.Reset(); 339 client.Reset();
321 340
322 // BeginImplFrame should prepare the draw. 341 // BeginImplFrame should prepare the draw.
323 client.AdvanceFrame(); 342 client.AdvanceFrame();
324 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); 343 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2);
325 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); 344 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2);
326 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 345 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending());
327 EXPECT_TRUE(client.needs_begin_frame()); 346 EXPECT_TRUE(client.needs_begin_frames());
328 client.Reset(); 347 client.Reset();
329 348
330 // BeginImplFrame deadline should draw. 349 // BeginImplFrame deadline should draw.
331 client.task_runner().RunPendingTasks(); // Run posted deadline. 350 client.task_runner().RunPendingTasks(); // Run posted deadline.
332 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 1); 351 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 1);
333 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); 352 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending());
334 EXPECT_TRUE(client.needs_begin_frame()); 353 EXPECT_TRUE(client.needs_begin_frames());
335 client.Reset(); 354 client.Reset();
336 355
337 // The following BeginImplFrame deadline should SetNeedsBeginFrame(false) 356 // The following BeginImplFrame deadline should SetNeedsBeginFrame(false)
338 // to avoid excessive toggles. 357 // to avoid excessive toggles.
339 client.AdvanceFrame(); 358 client.AdvanceFrame();
340 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); 359 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client);
341 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 360 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending());
342 client.Reset(); 361 client.Reset();
343 362
344 client.task_runner().RunPendingTasks(); // Run posted deadline. 363 client.task_runner().RunPendingTasks(); // Run posted deadline.
345 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); 364 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(false)", client);
346 EXPECT_FALSE(client.needs_begin_frame());
347 client.Reset(); 365 client.Reset();
348 } 366 }
349 367
350 TEST(SchedulerTest, RequestCommitAfterBeginMainFrameSent) { 368 TEST(SchedulerTest, RequestCommitAfterBeginMainFrameSent) {
351 FakeSchedulerClient client; 369 FakeSchedulerClient client;
352 SchedulerSettings scheduler_settings; 370 SchedulerSettings scheduler_settings;
353 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings); 371 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings);
354 scheduler->SetCanStart(); 372 scheduler->SetCanStart();
355 scheduler->SetVisible(true); 373 scheduler->SetVisible(true);
356 scheduler->SetCanDraw(true); 374 scheduler->SetCanDraw(true);
357 375
358 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); 376 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client);
359 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); 377 InitializeOutputSurfaceAndFirstCommit(scheduler, &client);
360 client.Reset(); 378 client.Reset();
361 379
362 // SetNeedsCommit should begin the frame. 380 // SetNeedsCommit should begin the frame.
363 scheduler->SetNeedsCommit(); 381 scheduler->SetNeedsCommit();
364 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); 382 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client);
365 383
366 client.Reset(); 384 client.Reset();
367 client.AdvanceFrame(); 385 client.AdvanceFrame();
368 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); 386 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2);
369 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); 387 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2);
370 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 388 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending());
371 389
372 EXPECT_TRUE(client.needs_begin_frame()); 390 EXPECT_TRUE(client.needs_begin_frames());
373 client.Reset(); 391 client.Reset();
374 392
375 // Now SetNeedsCommit again. Calling here means we need a second commit. 393 // Now SetNeedsCommit again. Calling here means we need a second commit.
376 scheduler->SetNeedsCommit(); 394 scheduler->SetNeedsCommit();
377 EXPECT_EQ(client.num_actions_(), 0); 395 EXPECT_EQ(client.num_actions_(), 0);
378 client.Reset(); 396 client.Reset();
379 397
380 // Finish the first commit. 398 // Finish the first commit.
381 scheduler->NotifyBeginMainFrameStarted(); 399 scheduler->NotifyBeginMainFrameStarted();
382 scheduler->NotifyReadyToCommit(); 400 scheduler->NotifyReadyToCommit();
383 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); 401 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client);
384 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 402 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending());
385 client.Reset(); 403 client.Reset();
386 client.task_runner().RunPendingTasks(); // Run posted deadline. 404 client.task_runner().RunPendingTasks(); // Run posted deadline.
387 EXPECT_ACTION("ScheduledActionAnimate", client, 0, 2); 405 EXPECT_ACTION("ScheduledActionAnimate", client, 0, 2);
388 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 1, 2); 406 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 1, 2);
389 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); 407 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending());
390 408
391 // Because we just swapped, the Scheduler should also request the next 409 // Because we just swapped, the Scheduler should also request the next
392 // BeginImplFrame from the OutputSurface. 410 // BeginImplFrame from the OutputSurface.
393 EXPECT_TRUE(client.needs_begin_frame()); 411 EXPECT_TRUE(client.needs_begin_frames());
394 client.Reset(); 412 client.Reset();
395 // Since another commit is needed, the next BeginImplFrame should initiate 413 // Since another commit is needed, the next BeginImplFrame should initiate
396 // the second commit. 414 // the second commit.
397 client.AdvanceFrame(); 415 client.AdvanceFrame();
398 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); 416 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2);
399 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); 417 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2);
400 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 418 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending());
401 client.Reset(); 419 client.Reset();
402 420
403 // Finishing the commit before the deadline should post a new deadline task 421 // Finishing the commit before the deadline should post a new deadline task
404 // to trigger the deadline early. 422 // to trigger the deadline early.
405 scheduler->NotifyBeginMainFrameStarted(); 423 scheduler->NotifyBeginMainFrameStarted();
406 scheduler->NotifyReadyToCommit(); 424 scheduler->NotifyReadyToCommit();
407 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); 425 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client);
408 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 426 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending());
409 client.Reset(); 427 client.Reset();
410 client.task_runner().RunPendingTasks(); // Run posted deadline. 428 client.task_runner().RunPendingTasks(); // Run posted deadline.
411 EXPECT_ACTION("ScheduledActionAnimate", client, 0, 2); 429 EXPECT_ACTION("ScheduledActionAnimate", client, 0, 2);
412 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 1, 2); 430 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 1, 2);
413 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); 431 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending());
414 EXPECT_TRUE(client.needs_begin_frame()); 432 EXPECT_TRUE(client.needs_begin_frames());
415 client.Reset(); 433 client.Reset();
416 434
417 // On the next BeginImplFrame, verify we go back to a quiescent state and 435 // On the next BeginImplFrame, verify we go back to a quiescent state and
418 // no longer request BeginImplFrames. 436 // no longer request BeginImplFrames.
419 client.AdvanceFrame(); 437 client.AdvanceFrame();
420 client.task_runner().RunPendingTasks(); // Run posted deadline. 438 client.task_runner().RunPendingTasks(); // Run posted deadline.
421 EXPECT_FALSE(client.needs_begin_frame()); 439 EXPECT_FALSE(client.needs_begin_frames());
422 client.Reset(); 440 client.Reset();
423 } 441 }
424 442
425 class SchedulerClientThatsetNeedsDrawInsideDraw : public FakeSchedulerClient { 443 class SchedulerClientThatsetNeedsDrawInsideDraw : public FakeSchedulerClient {
426 public: 444 public:
427 virtual void ScheduledActionSendBeginMainFrame() OVERRIDE {} 445 virtual void ScheduledActionSendBeginMainFrame() OVERRIDE {}
428 virtual DrawResult ScheduledActionDrawAndSwapIfPossible() 446 virtual DrawResult ScheduledActionDrawAndSwapIfPossible()
429 OVERRIDE { 447 OVERRIDE {
430 // Only SetNeedsRedraw the first time this is called 448 // Only SetNeedsRedraw the first time this is called
431 if (!num_draws_) 449 if (!num_draws_)
(...skipping 20 matching lines...) Expand all
452 SchedulerSettings default_scheduler_settings; 470 SchedulerSettings default_scheduler_settings;
453 TestScheduler* scheduler = client.CreateScheduler(default_scheduler_settings); 471 TestScheduler* scheduler = client.CreateScheduler(default_scheduler_settings);
454 scheduler->SetCanStart(); 472 scheduler->SetCanStart();
455 scheduler->SetVisible(true); 473 scheduler->SetVisible(true);
456 scheduler->SetCanDraw(true); 474 scheduler->SetCanDraw(true);
457 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); 475 InitializeOutputSurfaceAndFirstCommit(scheduler, &client);
458 client.Reset(); 476 client.Reset();
459 477
460 scheduler->SetNeedsRedraw(); 478 scheduler->SetNeedsRedraw();
461 EXPECT_TRUE(scheduler->RedrawPending()); 479 EXPECT_TRUE(scheduler->RedrawPending());
462 EXPECT_TRUE(client.needs_begin_frame()); 480 EXPECT_TRUE(client.needs_begin_frames());
463 EXPECT_EQ(0, client.num_draws()); 481 EXPECT_EQ(0, client.num_draws());
464 482
465 client.AdvanceFrame(); 483 client.AdvanceFrame();
466 client.task_runner().RunPendingTasks(); // Run posted deadline. 484 client.task_runner().RunPendingTasks(); // Run posted deadline.
467 EXPECT_EQ(1, client.num_draws()); 485 EXPECT_EQ(1, client.num_draws());
468 EXPECT_TRUE(scheduler->RedrawPending()); 486 EXPECT_TRUE(scheduler->RedrawPending());
469 EXPECT_TRUE(client.needs_begin_frame()); 487 EXPECT_TRUE(client.needs_begin_frames());
470 488
471 client.AdvanceFrame(); 489 client.AdvanceFrame();
472 client.task_runner().RunPendingTasks(); // Run posted deadline. 490 client.task_runner().RunPendingTasks(); // Run posted deadline.
473 EXPECT_EQ(2, client.num_draws()); 491 EXPECT_EQ(2, client.num_draws());
474 EXPECT_FALSE(scheduler->RedrawPending()); 492 EXPECT_FALSE(scheduler->RedrawPending());
475 EXPECT_TRUE(client.needs_begin_frame()); 493 EXPECT_TRUE(client.needs_begin_frames());
476 494
477 // We stop requesting BeginImplFrames after a BeginImplFrame where we don't 495 // We stop requesting BeginImplFrames after a BeginImplFrame where we don't
478 // swap. 496 // swap.
479 client.AdvanceFrame(); 497 client.AdvanceFrame();
480 client.task_runner().RunPendingTasks(); // Run posted deadline. 498 client.task_runner().RunPendingTasks(); // Run posted deadline.
481 EXPECT_EQ(2, client.num_draws()); 499 EXPECT_EQ(2, client.num_draws());
482 EXPECT_FALSE(scheduler->RedrawPending()); 500 EXPECT_FALSE(scheduler->RedrawPending());
483 EXPECT_FALSE(client.needs_begin_frame()); 501 EXPECT_FALSE(client.needs_begin_frames());
484 } 502 }
485 503
486 // Test that requesting redraw inside a failed draw doesn't lose the request. 504 // Test that requesting redraw inside a failed draw doesn't lose the request.
487 TEST(SchedulerTest, RequestRedrawInsideFailedDraw) { 505 TEST(SchedulerTest, RequestRedrawInsideFailedDraw) {
488 SchedulerClientThatsetNeedsDrawInsideDraw client; 506 SchedulerClientThatsetNeedsDrawInsideDraw client;
489 SchedulerSettings default_scheduler_settings; 507 SchedulerSettings default_scheduler_settings;
490 TestScheduler* scheduler = client.CreateScheduler(default_scheduler_settings); 508 TestScheduler* scheduler = client.CreateScheduler(default_scheduler_settings);
491 scheduler->SetCanStart(); 509 scheduler->SetCanStart();
492 scheduler->SetVisible(true); 510 scheduler->SetVisible(true);
493 scheduler->SetCanDraw(true); 511 scheduler->SetCanDraw(true);
494 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); 512 InitializeOutputSurfaceAndFirstCommit(scheduler, &client);
495 client.Reset(); 513 client.Reset();
496 514
497 client.SetDrawWillHappen(false); 515 client.SetDrawWillHappen(false);
498 516
499 scheduler->SetNeedsRedraw(); 517 scheduler->SetNeedsRedraw();
500 EXPECT_TRUE(scheduler->RedrawPending()); 518 EXPECT_TRUE(scheduler->RedrawPending());
501 EXPECT_TRUE(client.needs_begin_frame()); 519 EXPECT_TRUE(client.needs_begin_frames());
502 EXPECT_EQ(0, client.num_draws()); 520 EXPECT_EQ(0, client.num_draws());
503 521
504 // Fail the draw. 522 // Fail the draw.
505 client.AdvanceFrame(); 523 client.AdvanceFrame();
506 client.task_runner().RunPendingTasks(); // Run posted deadline. 524 client.task_runner().RunPendingTasks(); // Run posted deadline.
507 EXPECT_EQ(1, client.num_draws()); 525 EXPECT_EQ(1, client.num_draws());
508 526
509 // We have a commit pending and the draw failed, and we didn't lose the redraw 527 // We have a commit pending and the draw failed, and we didn't lose the redraw
510 // request. 528 // request.
511 EXPECT_TRUE(scheduler->CommitPending()); 529 EXPECT_TRUE(scheduler->CommitPending());
512 EXPECT_TRUE(scheduler->RedrawPending()); 530 EXPECT_TRUE(scheduler->RedrawPending());
513 EXPECT_TRUE(client.needs_begin_frame()); 531 EXPECT_TRUE(client.needs_begin_frames());
514 532
515 // Fail the draw again. 533 // Fail the draw again.
516 client.AdvanceFrame(); 534 client.AdvanceFrame();
517 client.task_runner().RunPendingTasks(); // Run posted deadline. 535 client.task_runner().RunPendingTasks(); // Run posted deadline.
518 EXPECT_EQ(2, client.num_draws()); 536 EXPECT_EQ(2, client.num_draws());
519 EXPECT_TRUE(scheduler->CommitPending()); 537 EXPECT_TRUE(scheduler->CommitPending());
520 EXPECT_TRUE(scheduler->RedrawPending()); 538 EXPECT_TRUE(scheduler->RedrawPending());
521 EXPECT_TRUE(client.needs_begin_frame()); 539 EXPECT_TRUE(client.needs_begin_frames());
522 540
523 // Draw successfully. 541 // Draw successfully.
524 client.SetDrawWillHappen(true); 542 client.SetDrawWillHappen(true);
525 client.AdvanceFrame(); 543 client.AdvanceFrame();
526 client.task_runner().RunPendingTasks(); // Run posted deadline. 544 client.task_runner().RunPendingTasks(); // Run posted deadline.
527 EXPECT_EQ(3, client.num_draws()); 545 EXPECT_EQ(3, client.num_draws());
528 EXPECT_TRUE(scheduler->CommitPending()); 546 EXPECT_TRUE(scheduler->CommitPending());
529 EXPECT_FALSE(scheduler->RedrawPending()); 547 EXPECT_FALSE(scheduler->RedrawPending());
530 EXPECT_TRUE(client.needs_begin_frame()); 548 EXPECT_TRUE(client.needs_begin_frames());
531 } 549 }
532 550
533 class SchedulerClientThatSetNeedsCommitInsideDraw : public FakeSchedulerClient { 551 class SchedulerClientThatSetNeedsCommitInsideDraw : public FakeSchedulerClient {
534 public: 552 public:
535 SchedulerClientThatSetNeedsCommitInsideDraw() 553 SchedulerClientThatSetNeedsCommitInsideDraw()
536 : set_needs_commit_on_next_draw_(false) {} 554 : set_needs_commit_on_next_draw_(false) {}
537 555
538 virtual void ScheduledActionSendBeginMainFrame() OVERRIDE {} 556 virtual void ScheduledActionSendBeginMainFrame() OVERRIDE {}
539 virtual DrawResult ScheduledActionDrawAndSwapIfPossible() 557 virtual DrawResult ScheduledActionDrawAndSwapIfPossible()
540 OVERRIDE { 558 OVERRIDE {
(...skipping 25 matching lines...) Expand all
566 TEST(SchedulerTest, RequestCommitInsideDraw) { 584 TEST(SchedulerTest, RequestCommitInsideDraw) {
567 SchedulerClientThatSetNeedsCommitInsideDraw client; 585 SchedulerClientThatSetNeedsCommitInsideDraw client;
568 SchedulerSettings default_scheduler_settings; 586 SchedulerSettings default_scheduler_settings;
569 TestScheduler* scheduler = client.CreateScheduler(default_scheduler_settings); 587 TestScheduler* scheduler = client.CreateScheduler(default_scheduler_settings);
570 scheduler->SetCanStart(); 588 scheduler->SetCanStart();
571 scheduler->SetVisible(true); 589 scheduler->SetVisible(true);
572 scheduler->SetCanDraw(true); 590 scheduler->SetCanDraw(true);
573 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); 591 InitializeOutputSurfaceAndFirstCommit(scheduler, &client);
574 client.Reset(); 592 client.Reset();
575 593
576 EXPECT_FALSE(client.needs_begin_frame()); 594 EXPECT_FALSE(client.needs_begin_frames());
577 scheduler->SetNeedsRedraw(); 595 scheduler->SetNeedsRedraw();
578 EXPECT_TRUE(scheduler->RedrawPending()); 596 EXPECT_TRUE(scheduler->RedrawPending());
579 EXPECT_EQ(0, client.num_draws()); 597 EXPECT_EQ(0, client.num_draws());
580 EXPECT_TRUE(client.needs_begin_frame()); 598 EXPECT_TRUE(client.needs_begin_frames());
581 599
582 client.SetNeedsCommitOnNextDraw(); 600 client.SetNeedsCommitOnNextDraw();
583 client.AdvanceFrame(); 601 client.AdvanceFrame();
584 client.SetNeedsCommitOnNextDraw(); 602 client.SetNeedsCommitOnNextDraw();
585 client.task_runner().RunPendingTasks(); // Run posted deadline. 603 client.task_runner().RunPendingTasks(); // Run posted deadline.
586 EXPECT_EQ(1, client.num_draws()); 604 EXPECT_EQ(1, client.num_draws());
587 EXPECT_TRUE(scheduler->CommitPending()); 605 EXPECT_TRUE(scheduler->CommitPending());
588 EXPECT_TRUE(client.needs_begin_frame()); 606 EXPECT_TRUE(client.needs_begin_frames());
589 scheduler->NotifyBeginMainFrameStarted(); 607 scheduler->NotifyBeginMainFrameStarted();
590 scheduler->NotifyReadyToCommit(); 608 scheduler->NotifyReadyToCommit();
591 609
592 client.AdvanceFrame(); 610 client.AdvanceFrame();
593 client.task_runner().RunPendingTasks(); // Run posted deadline. 611 client.task_runner().RunPendingTasks(); // Run posted deadline.
594 EXPECT_EQ(2, client.num_draws()); 612 EXPECT_EQ(2, client.num_draws());
595 613
596 EXPECT_FALSE(scheduler->RedrawPending()); 614 EXPECT_FALSE(scheduler->RedrawPending());
597 EXPECT_FALSE(scheduler->CommitPending()); 615 EXPECT_FALSE(scheduler->CommitPending());
598 EXPECT_TRUE(client.needs_begin_frame()); 616 EXPECT_TRUE(client.needs_begin_frames());
599 617
600 // We stop requesting BeginImplFrames after a BeginImplFrame where we don't 618 // We stop requesting BeginImplFrames after a BeginImplFrame where we don't
601 // swap. 619 // swap.
602 client.AdvanceFrame(); 620 client.AdvanceFrame();
603 client.task_runner().RunPendingTasks(); // Run posted deadline. 621 client.task_runner().RunPendingTasks(); // Run posted deadline.
604 EXPECT_EQ(2, client.num_draws()); 622 EXPECT_EQ(2, client.num_draws());
605 EXPECT_FALSE(scheduler->RedrawPending()); 623 EXPECT_FALSE(scheduler->RedrawPending());
606 EXPECT_FALSE(scheduler->CommitPending()); 624 EXPECT_FALSE(scheduler->CommitPending());
607 EXPECT_FALSE(client.needs_begin_frame()); 625 EXPECT_FALSE(client.needs_begin_frames());
608 } 626 }
609 627
610 // Tests that when a draw fails then the pending commit should not be dropped. 628 // Tests that when a draw fails then the pending commit should not be dropped.
611 TEST(SchedulerTest, RequestCommitInsideFailedDraw) { 629 TEST(SchedulerTest, RequestCommitInsideFailedDraw) {
612 SchedulerClientThatsetNeedsDrawInsideDraw client; 630 SchedulerClientThatsetNeedsDrawInsideDraw client;
613 SchedulerSettings default_scheduler_settings; 631 SchedulerSettings default_scheduler_settings;
614 TestScheduler* scheduler = client.CreateScheduler(default_scheduler_settings); 632 TestScheduler* scheduler = client.CreateScheduler(default_scheduler_settings);
615 scheduler->SetCanStart(); 633 scheduler->SetCanStart();
616 scheduler->SetVisible(true); 634 scheduler->SetVisible(true);
617 scheduler->SetCanDraw(true); 635 scheduler->SetCanDraw(true);
618 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); 636 InitializeOutputSurfaceAndFirstCommit(scheduler, &client);
619 client.Reset(); 637 client.Reset();
620 638
621 client.SetDrawWillHappen(false); 639 client.SetDrawWillHappen(false);
622 640
623 scheduler->SetNeedsRedraw(); 641 scheduler->SetNeedsRedraw();
624 EXPECT_TRUE(scheduler->RedrawPending()); 642 EXPECT_TRUE(scheduler->RedrawPending());
625 EXPECT_TRUE(client.needs_begin_frame()); 643 EXPECT_TRUE(client.needs_begin_frames());
626 EXPECT_EQ(0, client.num_draws()); 644 EXPECT_EQ(0, client.num_draws());
627 645
628 // Fail the draw. 646 // Fail the draw.
629 client.AdvanceFrame(); 647 client.AdvanceFrame();
630 client.task_runner().RunPendingTasks(); // Run posted deadline. 648 client.task_runner().RunPendingTasks(); // Run posted deadline.
631 EXPECT_EQ(1, client.num_draws()); 649 EXPECT_EQ(1, client.num_draws());
632 650
633 // We have a commit pending and the draw failed, and we didn't lose the commit 651 // We have a commit pending and the draw failed, and we didn't lose the commit
634 // request. 652 // request.
635 EXPECT_TRUE(scheduler->CommitPending()); 653 EXPECT_TRUE(scheduler->CommitPending());
636 EXPECT_TRUE(scheduler->RedrawPending()); 654 EXPECT_TRUE(scheduler->RedrawPending());
637 EXPECT_TRUE(client.needs_begin_frame()); 655 EXPECT_TRUE(client.needs_begin_frames());
638 656
639 // Fail the draw again. 657 // Fail the draw again.
640 client.AdvanceFrame(); 658 client.AdvanceFrame();
641 659
642 client.task_runner().RunPendingTasks(); // Run posted deadline. 660 client.task_runner().RunPendingTasks(); // Run posted deadline.
643 EXPECT_EQ(2, client.num_draws()); 661 EXPECT_EQ(2, client.num_draws());
644 EXPECT_TRUE(scheduler->CommitPending()); 662 EXPECT_TRUE(scheduler->CommitPending());
645 EXPECT_TRUE(scheduler->RedrawPending()); 663 EXPECT_TRUE(scheduler->RedrawPending());
646 EXPECT_TRUE(client.needs_begin_frame()); 664 EXPECT_TRUE(client.needs_begin_frames());
647 665
648 // Draw successfully. 666 // Draw successfully.
649 client.SetDrawWillHappen(true); 667 client.SetDrawWillHappen(true);
650 client.AdvanceFrame(); 668 client.AdvanceFrame();
651 client.task_runner().RunPendingTasks(); // Run posted deadline. 669 client.task_runner().RunPendingTasks(); // Run posted deadline.
652 EXPECT_EQ(3, client.num_draws()); 670 EXPECT_EQ(3, client.num_draws());
653 EXPECT_TRUE(scheduler->CommitPending()); 671 EXPECT_TRUE(scheduler->CommitPending());
654 EXPECT_FALSE(scheduler->RedrawPending()); 672 EXPECT_FALSE(scheduler->RedrawPending());
655 EXPECT_TRUE(client.needs_begin_frame()); 673 EXPECT_TRUE(client.needs_begin_frames());
656 } 674 }
657 675
658 TEST(SchedulerTest, NoSwapWhenDrawFails) { 676 TEST(SchedulerTest, NoSwapWhenDrawFails) {
659 SchedulerClientThatSetNeedsCommitInsideDraw client; 677 SchedulerClientThatSetNeedsCommitInsideDraw client;
660 SchedulerSettings default_scheduler_settings; 678 SchedulerSettings default_scheduler_settings;
661 TestScheduler* scheduler = client.CreateScheduler(default_scheduler_settings); 679 TestScheduler* scheduler = client.CreateScheduler(default_scheduler_settings);
662 scheduler->SetCanStart(); 680 scheduler->SetCanStart();
663 scheduler->SetVisible(true); 681 scheduler->SetVisible(true);
664 scheduler->SetCanDraw(true); 682 scheduler->SetCanDraw(true);
665 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); 683 InitializeOutputSurfaceAndFirstCommit(scheduler, &client);
666 client.Reset(); 684 client.Reset();
667 685
668 scheduler->SetNeedsRedraw(); 686 scheduler->SetNeedsRedraw();
669 EXPECT_TRUE(scheduler->RedrawPending()); 687 EXPECT_TRUE(scheduler->RedrawPending());
670 EXPECT_TRUE(client.needs_begin_frame()); 688 EXPECT_TRUE(client.needs_begin_frames());
671 EXPECT_EQ(0, client.num_draws()); 689 EXPECT_EQ(0, client.num_draws());
672 690
673 // Draw successfully, this starts a new frame. 691 // Draw successfully, this starts a new frame.
674 client.SetNeedsCommitOnNextDraw(); 692 client.SetNeedsCommitOnNextDraw();
675 client.AdvanceFrame(); 693 client.AdvanceFrame();
676 client.task_runner().RunPendingTasks(); // Run posted deadline. 694 client.task_runner().RunPendingTasks(); // Run posted deadline.
677 EXPECT_EQ(1, client.num_draws()); 695 EXPECT_EQ(1, client.num_draws());
678 696
679 scheduler->SetNeedsRedraw(); 697 scheduler->SetNeedsRedraw();
680 EXPECT_TRUE(scheduler->RedrawPending()); 698 EXPECT_TRUE(scheduler->RedrawPending());
681 EXPECT_TRUE(client.needs_begin_frame()); 699 EXPECT_TRUE(client.needs_begin_frames());
682 700
683 // Fail to draw, this should not start a frame. 701 // Fail to draw, this should not start a frame.
684 client.SetDrawWillHappen(false); 702 client.SetDrawWillHappen(false);
685 client.SetNeedsCommitOnNextDraw(); 703 client.SetNeedsCommitOnNextDraw();
686 client.AdvanceFrame(); 704 client.AdvanceFrame();
687 client.task_runner().RunPendingTasks(); // Run posted deadline. 705 client.task_runner().RunPendingTasks(); // Run posted deadline.
688 EXPECT_EQ(2, client.num_draws()); 706 EXPECT_EQ(2, client.num_draws());
689 } 707 }
690 708
691 class SchedulerClientNeedsManageTilesInDraw : public FakeSchedulerClient { 709 class SchedulerClientNeedsManageTilesInDraw : public FakeSchedulerClient {
(...skipping 15 matching lines...) Expand all
707 scheduler->SetCanDraw(true); 725 scheduler->SetCanDraw(true);
708 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); 726 InitializeOutputSurfaceAndFirstCommit(scheduler, &client);
709 727
710 // Request both draw and manage tiles. ManageTiles shouldn't 728 // Request both draw and manage tiles. ManageTiles shouldn't
711 // be trigged until BeginImplFrame. 729 // be trigged until BeginImplFrame.
712 client.Reset(); 730 client.Reset();
713 scheduler->SetNeedsManageTiles(); 731 scheduler->SetNeedsManageTiles();
714 scheduler->SetNeedsRedraw(); 732 scheduler->SetNeedsRedraw();
715 EXPECT_TRUE(scheduler->RedrawPending()); 733 EXPECT_TRUE(scheduler->RedrawPending());
716 EXPECT_TRUE(scheduler->ManageTilesPending()); 734 EXPECT_TRUE(scheduler->ManageTilesPending());
717 EXPECT_TRUE(client.needs_begin_frame()); 735 EXPECT_TRUE(client.needs_begin_frames());
718 EXPECT_EQ(0, client.num_draws()); 736 EXPECT_EQ(0, client.num_draws());
719 EXPECT_FALSE(client.HasAction("ScheduledActionManageTiles")); 737 EXPECT_FALSE(client.HasAction("ScheduledActionManageTiles"));
720 EXPECT_FALSE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); 738 EXPECT_FALSE(client.HasAction("ScheduledActionDrawAndSwapIfPossible"));
721 739
722 // We have no immediate actions to perform, so the BeginImplFrame should post 740 // We have no immediate actions to perform, so the BeginImplFrame should post
723 // the deadline task. 741 // the deadline task.
724 client.Reset(); 742 client.Reset();
725 client.AdvanceFrame(); 743 client.AdvanceFrame();
726 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); 744 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2);
727 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); 745 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2);
728 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 746 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending());
729 747
730 // On the deadline, he actions should have occured in the right order. 748 // On the deadline, he actions should have occured in the right order.
731 client.Reset(); 749 client.Reset();
732 client.task_runner().RunPendingTasks(); // Run posted deadline. 750 client.task_runner().RunPendingTasks(); // Run posted deadline.
733 EXPECT_EQ(1, client.num_draws()); 751 EXPECT_EQ(1, client.num_draws());
734 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); 752 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible"));
735 EXPECT_TRUE(client.HasAction("ScheduledActionManageTiles")); 753 EXPECT_TRUE(client.HasAction("ScheduledActionManageTiles"));
736 EXPECT_LT(client.ActionIndex("ScheduledActionDrawAndSwapIfPossible"), 754 EXPECT_LT(client.ActionIndex("ScheduledActionDrawAndSwapIfPossible"),
737 client.ActionIndex("ScheduledActionManageTiles")); 755 client.ActionIndex("ScheduledActionManageTiles"));
738 EXPECT_FALSE(scheduler->RedrawPending()); 756 EXPECT_FALSE(scheduler->RedrawPending());
739 EXPECT_FALSE(scheduler->ManageTilesPending()); 757 EXPECT_FALSE(scheduler->ManageTilesPending());
740 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); 758 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending());
741 759
742 // Request a draw. We don't need a ManageTiles yet. 760 // Request a draw. We don't need a ManageTiles yet.
743 client.Reset(); 761 client.Reset();
744 scheduler->SetNeedsRedraw(); 762 scheduler->SetNeedsRedraw();
745 EXPECT_TRUE(scheduler->RedrawPending()); 763 EXPECT_TRUE(scheduler->RedrawPending());
746 EXPECT_FALSE(scheduler->ManageTilesPending()); 764 EXPECT_FALSE(scheduler->ManageTilesPending());
747 EXPECT_TRUE(client.needs_begin_frame()); 765 EXPECT_TRUE(client.needs_begin_frames());
748 EXPECT_EQ(0, client.num_draws()); 766 EXPECT_EQ(0, client.num_draws());
749 767
750 // We have no immediate actions to perform, so the BeginImplFrame should post 768 // We have no immediate actions to perform, so the BeginImplFrame should post
751 // the deadline task. 769 // the deadline task.
752 client.Reset(); 770 client.Reset();
753 client.AdvanceFrame(); 771 client.AdvanceFrame();
754 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); 772 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2);
755 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); 773 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2);
756 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 774 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending());
757 775
(...skipping 11 matching lines...) Expand all
769 EXPECT_FALSE(scheduler->ManageTilesPending()); 787 EXPECT_FALSE(scheduler->ManageTilesPending());
770 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); 788 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending());
771 789
772 // We need a BeginImplFrame where we don't swap to go idle. 790 // We need a BeginImplFrame where we don't swap to go idle.
773 client.Reset(); 791 client.Reset();
774 client.AdvanceFrame(); 792 client.AdvanceFrame();
775 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); 793 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client);
776 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 794 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending());
777 client.Reset(); 795 client.Reset();
778 client.task_runner().RunPendingTasks(); // Run posted deadline. 796 client.task_runner().RunPendingTasks(); // Run posted deadline.
779 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); 797 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(false)", client);
780 EXPECT_FALSE(client.needs_begin_frame());
781 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); 798 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending());
782 EXPECT_EQ(0, client.num_draws()); 799 EXPECT_EQ(0, client.num_draws());
783 800
784 // Now trigger a ManageTiles outside of a draw. We will then need 801 // Now trigger a ManageTiles outside of a draw. We will then need
785 // a begin-frame for the ManageTiles, but we don't need a draw. 802 // a begin-frame for the ManageTiles, but we don't need a draw.
786 client.Reset(); 803 client.Reset();
787 EXPECT_FALSE(client.needs_begin_frame()); 804 EXPECT_FALSE(client.needs_begin_frames());
788 scheduler->SetNeedsManageTiles(); 805 scheduler->SetNeedsManageTiles();
789 EXPECT_TRUE(client.needs_begin_frame()); 806 EXPECT_TRUE(client.needs_begin_frames());
790 EXPECT_TRUE(scheduler->ManageTilesPending()); 807 EXPECT_TRUE(scheduler->ManageTilesPending());
791 EXPECT_FALSE(scheduler->RedrawPending()); 808 EXPECT_FALSE(scheduler->RedrawPending());
792 809
793 // BeginImplFrame. There will be no draw, only ManageTiles. 810 // BeginImplFrame. There will be no draw, only ManageTiles.
794 client.Reset(); 811 client.Reset();
795 client.AdvanceFrame(); 812 client.AdvanceFrame();
796 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); 813 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client);
797 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 814 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending());
798 client.Reset(); 815 client.Reset();
799 client.task_runner().RunPendingTasks(); // Run posted deadline. 816 client.task_runner().RunPendingTasks(); // Run posted deadline.
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
931 scheduler->SetCanStart(); 948 scheduler->SetCanStart();
932 scheduler->SetVisible(true); 949 scheduler->SetVisible(true);
933 scheduler->SetCanDraw(true); 950 scheduler->SetCanDraw(true);
934 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); 951 InitializeOutputSurfaceAndFirstCommit(scheduler, &client);
935 952
936 client.SetRedrawWillHappenIfUpdateVisibleTilesHappens(true); 953 client.SetRedrawWillHappenIfUpdateVisibleTilesHappens(true);
937 954
938 // SetNeedsCommit should begin the frame. 955 // SetNeedsCommit should begin the frame.
939 client.Reset(); 956 client.Reset();
940 scheduler->SetNeedsCommit(); 957 scheduler->SetNeedsCommit();
941 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); 958 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client);
942 959
943 client.Reset(); 960 client.Reset();
944 client.AdvanceFrame(); 961 client.AdvanceFrame();
945 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); 962 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2);
946 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); 963 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2);
947 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 964 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending());
948 965
949 client.Reset(); 966 client.Reset();
950 scheduler->NotifyBeginMainFrameStarted(); 967 scheduler->NotifyBeginMainFrameStarted();
951 scheduler->NotifyReadyToCommit(); 968 scheduler->NotifyReadyToCommit();
(...skipping 22 matching lines...) Expand all
974 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 2, 3); 991 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 2, 3);
975 992
976 client.Reset(); 993 client.Reset();
977 client.AdvanceFrame(); 994 client.AdvanceFrame();
978 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); 995 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client);
979 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 996 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending());
980 997
981 // No more UpdateVisibleTiles(). 998 // No more UpdateVisibleTiles().
982 client.Reset(); 999 client.Reset();
983 client.task_runner().RunPendingTasks(); // Run posted deadline. 1000 client.task_runner().RunPendingTasks(); // Run posted deadline.
984 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); 1001 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(false)", client);
985 EXPECT_FALSE(client.needs_begin_frame());
986 } 1002 }
987 1003
988 TEST(SchedulerTest, TriggerBeginFrameDeadlineEarly) { 1004 TEST(SchedulerTest, TriggerBeginFrameDeadlineEarly) {
989 SchedulerClientNeedsManageTilesInDraw client; 1005 SchedulerClientNeedsManageTilesInDraw client;
990 SchedulerSettings default_scheduler_settings; 1006 SchedulerSettings default_scheduler_settings;
991 TestScheduler* scheduler = client.CreateScheduler(default_scheduler_settings); 1007 TestScheduler* scheduler = client.CreateScheduler(default_scheduler_settings);
992 scheduler->SetCanStart(); 1008 scheduler->SetCanStart();
993 scheduler->SetVisible(true); 1009 scheduler->SetVisible(true);
994 scheduler->SetCanDraw(true); 1010 scheduler->SetCanDraw(true);
995 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); 1011 InitializeOutputSurfaceAndFirstCommit(scheduler, &client);
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
1116 scheduler->DidCreateAndInitializeOutputSurface(); 1132 scheduler->DidCreateAndInitializeOutputSurface();
1117 1133
1118 scheduler->SetNeedsCommit(); 1134 scheduler->SetNeedsCommit();
1119 EXPECT_TRUE(scheduler->CommitPending()); 1135 EXPECT_TRUE(scheduler->CommitPending());
1120 scheduler->NotifyBeginMainFrameStarted(); 1136 scheduler->NotifyBeginMainFrameStarted();
1121 scheduler->NotifyReadyToCommit(); 1137 scheduler->NotifyReadyToCommit();
1122 scheduler->SetNeedsRedraw(); 1138 scheduler->SetNeedsRedraw();
1123 1139
1124 BeginFrameArgs frame_args = CreateBeginFrameArgsForTesting(client.now_src()); 1140 BeginFrameArgs frame_args = CreateBeginFrameArgsForTesting(client.now_src());
1125 frame_args.interval = base::TimeDelta::FromMilliseconds(1000); 1141 frame_args.interval = base::TimeDelta::FromMilliseconds(1000);
1126 scheduler->BeginFrame(frame_args); 1142 client.ExternalBeginFrameSource()->TestOnBeginFrame(frame_args);
1127 1143
1128 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 1144 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending());
1129 client.task_runner().RunPendingTasks(); // Run posted deadline. 1145 client.task_runner().RunPendingTasks(); // Run posted deadline.
1130 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); 1146 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending());
1131 1147
1132 scheduler->DidSwapBuffers(); 1148 scheduler->DidSwapBuffers();
1133 scheduler->DidSwapBuffersComplete(); 1149 scheduler->DidSwapBuffersComplete();
1134 1150
1135 // At this point, we've drawn a frame. Start another commit, but hold off on 1151 // At this point, we've drawn a frame. Start another commit, but hold off on
1136 // the NotifyReadyToCommit for now. 1152 // the NotifyReadyToCommit for now.
1137 EXPECT_FALSE(scheduler->CommitPending()); 1153 EXPECT_FALSE(scheduler->CommitPending());
1138 scheduler->SetNeedsCommit(); 1154 scheduler->SetNeedsCommit();
1139 scheduler->BeginFrame(frame_args); 1155 client.ExternalBeginFrameSource()->TestOnBeginFrame(frame_args);
1140 EXPECT_TRUE(scheduler->CommitPending()); 1156 EXPECT_TRUE(scheduler->CommitPending());
1141 1157
1142 // Draw and swap the frame, but don't ack the swap to simulate the Browser 1158 // Draw and swap the frame, but don't ack the swap to simulate the Browser
1143 // blocking on the renderer. 1159 // blocking on the renderer.
1144 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 1160 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending());
1145 client.task_runner().RunPendingTasks(); // Run posted deadline. 1161 client.task_runner().RunPendingTasks(); // Run posted deadline.
1146 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); 1162 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending());
1147 scheduler->DidSwapBuffers(); 1163 scheduler->DidSwapBuffers();
1148 1164
1149 // Spin the event loop a few times and make sure we get more 1165 // Spin the event loop a few times and make sure we get more
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1181 SchedulerSettings scheduler_settings; 1197 SchedulerSettings scheduler_settings;
1182 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings); 1198 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings);
1183 scheduler->SetCanStart(); 1199 scheduler->SetCanStart();
1184 scheduler->SetVisible(true); 1200 scheduler->SetVisible(true);
1185 scheduler->SetCanDraw(true); 1201 scheduler->SetCanDraw(true);
1186 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); 1202 InitializeOutputSurfaceAndFirstCommit(scheduler, &client);
1187 1203
1188 // SetNeedsCommit should begin the frame on the next BeginImplFrame. 1204 // SetNeedsCommit should begin the frame on the next BeginImplFrame.
1189 client.Reset(); 1205 client.Reset();
1190 scheduler->SetNeedsCommit(); 1206 scheduler->SetNeedsCommit();
1191 EXPECT_TRUE(client.needs_begin_frame()); 1207 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client);
1192 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client);
1193 client.Reset(); 1208 client.Reset();
1194 1209
1195 // Create a BeginFrame with a long deadline to avoid race conditions. 1210 // Create a BeginFrame with a long deadline to avoid race conditions.
1196 // This is the first BeginFrame, which will be handled immediately. 1211 // This is the first BeginFrame, which will be handled immediately.
1197 BeginFrameArgs args = CreateBeginFrameArgsForTesting(client.now_src()); 1212 BeginFrameArgs args = CreateBeginFrameArgsForTesting(client.now_src());
1198 args.deadline += base::TimeDelta::FromHours(1); 1213 args.deadline += base::TimeDelta::FromHours(1);
1199 scheduler->BeginFrame(args); 1214 client.ExternalBeginFrameSource()->TestOnBeginFrame(args);
1200 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); 1215 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2);
1201 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); 1216 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2);
1202 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 1217 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending());
1203 EXPECT_TRUE(client.needs_begin_frame()); 1218 EXPECT_TRUE(client.needs_begin_frames());
1204 client.Reset(); 1219 client.Reset();
1205 1220
1206 // Queue BeginFrames while we are still handling the previous BeginFrame. 1221 // Queue BeginFrames while we are still handling the previous BeginFrame.
1207 args.frame_time += base::TimeDelta::FromSeconds(1); 1222 args.frame_time += base::TimeDelta::FromSeconds(1);
1208 scheduler->BeginFrame(args); 1223 client.ExternalBeginFrameSource()->TestOnBeginFrame(args);
1209 args.frame_time += base::TimeDelta::FromSeconds(1); 1224 args.frame_time += base::TimeDelta::FromSeconds(1);
1210 scheduler->BeginFrame(args); 1225 client.ExternalBeginFrameSource()->TestOnBeginFrame(args);
1211 1226
1212 // If we don't swap on the deadline, we wait for the next BeginImplFrame. 1227 // If we don't swap on the deadline, we wait for the next BeginImplFrame.
1213 client.task_runner().RunPendingTasks(); // Run posted deadline. 1228 client.task_runner().RunPendingTasks(); // Run posted deadline.
1214 EXPECT_NO_ACTION(client); 1229 EXPECT_NO_ACTION(client);
1215 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); 1230 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending());
1216 EXPECT_TRUE(client.needs_begin_frame()); 1231 EXPECT_TRUE(client.needs_begin_frames());
1217 client.Reset(); 1232 client.Reset();
1218 1233
1219 // NotifyReadyToCommit should trigger the commit. 1234 // NotifyReadyToCommit should trigger the commit.
1220 scheduler->NotifyBeginMainFrameStarted(); 1235 scheduler->NotifyBeginMainFrameStarted();
1221 scheduler->NotifyReadyToCommit(); 1236 scheduler->NotifyReadyToCommit();
1222 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); 1237 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client);
1223 EXPECT_TRUE(client.needs_begin_frame()); 1238 EXPECT_TRUE(client.needs_begin_frames());
1224 client.Reset(); 1239 client.Reset();
1225 1240
1226 // BeginImplFrame should prepare the draw. 1241 // BeginImplFrame should prepare the draw.
1227 client.task_runner().RunPendingTasks(); // Run posted BeginRetroFrame. 1242 client.task_runner().RunPendingTasks(); // Run posted BeginRetroFrame.
1228 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); 1243 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2);
1229 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); 1244 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2);
1230 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 1245 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending());
1231 EXPECT_TRUE(client.needs_begin_frame()); 1246 EXPECT_TRUE(client.needs_begin_frames());
1232 client.Reset(); 1247 client.Reset();
1233 1248
1234 // BeginImplFrame deadline should draw. 1249 // BeginImplFrame deadline should draw.
1235 client.task_runner().RunPendingTasks(); // Run posted deadline. 1250 client.task_runner().RunPendingTasks(); // Run posted deadline.
1236 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 1); 1251 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 1);
1237 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); 1252 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending());
1238 EXPECT_TRUE(client.needs_begin_frame()); 1253 EXPECT_TRUE(client.needs_begin_frames());
1239 client.Reset(); 1254 client.Reset();
1240 1255
1241 // The following BeginImplFrame deadline should SetNeedsBeginFrame(false) 1256 // The following BeginImplFrame deadline should SetNeedsBeginFrame(false)
1242 // to avoid excessive toggles. 1257 // to avoid excessive toggles.
1243 client.task_runner().RunPendingTasks(); // Run posted BeginRetroFrame. 1258 client.task_runner().RunPendingTasks(); // Run posted BeginRetroFrame.
1244 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); 1259 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client);
1245 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 1260 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending());
1246 client.Reset(); 1261 client.Reset();
1247 1262
1248 client.task_runner().RunPendingTasks(); // Run posted deadline. 1263 client.task_runner().RunPendingTasks(); // Run posted deadline.
1249 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); 1264 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(false)", client);
1250 EXPECT_FALSE(client.needs_begin_frame());
1251 client.Reset(); 1265 client.Reset();
1252 } 1266 }
1253 1267
1254 TEST(SchedulerTest, BeginRetroFrame_SwapThrottled) { 1268 TEST(SchedulerTest, BeginRetroFrame_SwapThrottled) {
1255 FakeSchedulerClient client; 1269 FakeSchedulerClient client;
1256 SchedulerSettings scheduler_settings; 1270 SchedulerSettings scheduler_settings;
1257 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings); 1271 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings);
1258 scheduler->SetCanStart(); 1272 scheduler->SetCanStart();
1259 scheduler->SetVisible(true); 1273 scheduler->SetVisible(true);
1260 scheduler->SetCanDraw(true); 1274 scheduler->SetCanDraw(true);
1261 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); 1275 InitializeOutputSurfaceAndFirstCommit(scheduler, &client);
1262 1276
1263 // To test swap ack throttling, this test disables automatic swap acks. 1277 // To test swap ack throttling, this test disables automatic swap acks.
1264 scheduler->SetMaxSwapsPending(1); 1278 scheduler->SetMaxSwapsPending(1);
1265 client.SetAutomaticSwapAck(false); 1279 client.SetAutomaticSwapAck(false);
1266 1280
1267 // SetNeedsCommit should begin the frame on the next BeginImplFrame. 1281 // SetNeedsCommit should begin the frame on the next BeginImplFrame.
1268 client.Reset(); 1282 client.Reset();
1269 scheduler->SetNeedsCommit(); 1283 scheduler->SetNeedsCommit();
1270 EXPECT_TRUE(client.needs_begin_frame()); 1284 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client);
1271 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client);
1272 client.Reset(); 1285 client.Reset();
1273 1286
1274 // Create a BeginFrame with a long deadline to avoid race conditions. 1287 // Create a BeginFrame with a long deadline to avoid race conditions.
1275 // This is the first BeginFrame, which will be handled immediately. 1288 // This is the first BeginFrame, which will be handled immediately.
1276 BeginFrameArgs args = CreateBeginFrameArgsForTesting(client.now_src()); 1289 BeginFrameArgs args = CreateBeginFrameArgsForTesting(client.now_src());
1277 args.deadline += base::TimeDelta::FromHours(1); 1290 args.deadline += base::TimeDelta::FromHours(1);
1278 scheduler->BeginFrame(args); 1291 client.ExternalBeginFrameSource()->TestOnBeginFrame(args);
1279 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); 1292 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2);
1280 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); 1293 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2);
1281 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 1294 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending());
1282 EXPECT_TRUE(client.needs_begin_frame()); 1295 EXPECT_TRUE(client.needs_begin_frames());
1283 client.Reset(); 1296 client.Reset();
1284 1297
1285 // Queue BeginFrame while we are still handling the previous BeginFrame. 1298 // Queue BeginFrame while we are still handling the previous BeginFrame.
1286 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 1299 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending());
1287 args.frame_time += base::TimeDelta::FromSeconds(1); 1300 args.frame_time += base::TimeDelta::FromSeconds(1);
1288 scheduler->BeginFrame(args); 1301 client.ExternalBeginFrameSource()->TestOnBeginFrame(args);
1289 EXPECT_NO_ACTION(client); 1302 EXPECT_NO_ACTION(client);
1290 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 1303 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending());
1291 client.Reset(); 1304 client.Reset();
1292 1305
1293 // NotifyReadyToCommit should trigger the pending commit and draw. 1306 // NotifyReadyToCommit should trigger the pending commit and draw.
1294 scheduler->NotifyBeginMainFrameStarted(); 1307 scheduler->NotifyBeginMainFrameStarted();
1295 scheduler->NotifyReadyToCommit(); 1308 scheduler->NotifyReadyToCommit();
1296 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); 1309 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client);
1297 EXPECT_TRUE(client.needs_begin_frame()); 1310 EXPECT_TRUE(client.needs_begin_frames());
1298 client.Reset(); 1311 client.Reset();
1299 1312
1300 // Swapping will put us into a swap throttled state. 1313 // Swapping will put us into a swap throttled state.
1301 client.task_runner().RunPendingTasks(); // Run posted deadline. 1314 client.task_runner().RunPendingTasks(); // Run posted deadline.
1302 EXPECT_ACTION("ScheduledActionAnimate", client, 0, 2); 1315 EXPECT_ACTION("ScheduledActionAnimate", client, 0, 2);
1303 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 1, 2); 1316 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 1, 2);
1304 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); 1317 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending());
1305 EXPECT_TRUE(client.needs_begin_frame()); 1318 EXPECT_TRUE(client.needs_begin_frames());
1306 client.Reset(); 1319 client.Reset();
1307 1320
1308 // While swap throttled, BeginRetroFrames should trigger BeginImplFrames 1321 // While swap throttled, BeginRetroFrames should trigger BeginImplFrames
1309 // but not a BeginMainFrame or draw. 1322 // but not a BeginMainFrame or draw.
1310 scheduler->SetNeedsCommit(); 1323 scheduler->SetNeedsCommit();
1311 client.task_runner().RunPendingTasks(); // Run posted BeginRetroFrame. 1324 client.task_runner().RunPendingTasks(); // Run posted BeginRetroFrame.
1312 EXPECT_ACTION("WillBeginImplFrame", client, 0, 1); 1325 EXPECT_ACTION("WillBeginImplFrame", client, 0, 1);
1313 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 1326 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending());
1314 EXPECT_TRUE(client.needs_begin_frame()); 1327 EXPECT_TRUE(client.needs_begin_frames());
1315 client.Reset(); 1328 client.Reset();
1316 1329
1317 // Queue BeginFrame while we are still handling the previous BeginFrame. 1330 // Queue BeginFrame while we are still handling the previous BeginFrame.
1318 args.frame_time += base::TimeDelta::FromSeconds(1); 1331 args.frame_time += base::TimeDelta::FromSeconds(1);
1319 scheduler->BeginFrame(args); 1332 client.ExternalBeginFrameSource()->TestOnBeginFrame(args);
1320 EXPECT_NO_ACTION(client); 1333 EXPECT_NO_ACTION(client);
1321 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 1334 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending());
1322 EXPECT_TRUE(client.needs_begin_frame()); 1335 EXPECT_TRUE(client.needs_begin_frames());
1323 client.Reset(); 1336 client.Reset();
1324 1337
1325 // Take us out of a swap throttled state. 1338 // Take us out of a swap throttled state.
1326 scheduler->DidSwapBuffersComplete(); 1339 scheduler->DidSwapBuffersComplete();
1327 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 0, 1); 1340 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 0, 1);
1328 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 1341 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending());
1329 EXPECT_TRUE(client.needs_begin_frame()); 1342 EXPECT_TRUE(client.needs_begin_frames());
1330 client.Reset(); 1343 client.Reset();
1331 1344
1332 // BeginImplFrame deadline should draw. 1345 // BeginImplFrame deadline should draw.
1333 scheduler->SetNeedsRedraw(); 1346 scheduler->SetNeedsRedraw();
1334 1347
1335 EXPECT_TRUE(client.task_runner().RunTasksWhile( 1348 EXPECT_TRUE(client.task_runner().RunTasksWhile(
1336 client.ImplFrameDeadlinePending(true))); 1349 client.ImplFrameDeadlinePending(true)));
1337 1350
1338 EXPECT_ACTION("ScheduledActionAnimate", client, 0, 2); 1351 EXPECT_ACTION("ScheduledActionAnimate", client, 0, 2);
1339 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 1, 2); 1352 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 1, 2);
1340 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); 1353 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending());
1341 EXPECT_TRUE(client.needs_begin_frame()); 1354 EXPECT_TRUE(client.needs_begin_frames());
1342 client.Reset(); 1355 client.Reset();
1343 } 1356 }
1344 1357
1345 void BeginFramesNotFromClient(bool begin_frame_scheduling_enabled, 1358 void BeginFramesNotFromClient(bool begin_frame_scheduling_enabled,
1346 bool throttle_frame_production) { 1359 bool throttle_frame_production) {
1347 FakeSchedulerClient client; 1360 FakeSchedulerClient client;
1348 SchedulerSettings scheduler_settings; 1361 SchedulerSettings scheduler_settings;
1349 scheduler_settings.begin_frame_scheduling_enabled = 1362 scheduler_settings.begin_frame_scheduling_enabled =
1350 begin_frame_scheduling_enabled; 1363 begin_frame_scheduling_enabled;
1351 scheduler_settings.throttle_frame_production = throttle_frame_production; 1364 scheduler_settings.throttle_frame_production = throttle_frame_production;
1352 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings); 1365 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings);
1353 scheduler->SetCanStart(); 1366 scheduler->SetCanStart();
1354 scheduler->SetVisible(true); 1367 scheduler->SetVisible(true);
1355 scheduler->SetCanDraw(true); 1368 scheduler->SetCanDraw(true);
1356 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); 1369 InitializeOutputSurfaceAndFirstCommit(scheduler, &client);
1357 1370
1358 // SetNeedsCommit should begin the frame on the next BeginImplFrame 1371 // SetNeedsCommit should begin the frame on the next BeginImplFrame
1359 // without calling SetNeedsBeginFrame. 1372 // without calling SetNeedsBeginFrame.
1360 client.Reset(); 1373 client.Reset();
1361 scheduler->SetNeedsCommit(); 1374 scheduler->SetNeedsCommit();
1362 EXPECT_FALSE(client.needs_begin_frame()); 1375 EXPECT_FALSE(client.needs_begin_frames());
1363 EXPECT_NO_ACTION(client); 1376 EXPECT_NO_ACTION(client);
1364 client.Reset(); 1377 client.Reset();
1365 1378
1366 // When the client-driven BeginFrame are disabled, the scheduler posts it's 1379 // When the client-driven BeginFrame are disabled, the scheduler posts it's
1367 // own BeginFrame tasks. 1380 // own BeginFrame tasks.
1368 client.task_runner().RunPendingTasks(); // Run posted BeginFrame. 1381 client.task_runner().RunPendingTasks(); // Run posted BeginFrame.
1369 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); 1382 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2);
1370 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); 1383 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2);
1371 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 1384 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending());
1372 EXPECT_FALSE(client.needs_begin_frame()); 1385 EXPECT_FALSE(client.needs_begin_frames());
1373 client.Reset(); 1386 client.Reset();
1374 1387
1375 // If we don't swap on the deadline, we wait for the next BeginFrame. 1388 // If we don't swap on the deadline, we wait for the next BeginFrame.
1376 client.task_runner().RunPendingTasks(); // Run posted deadline. 1389 client.task_runner().RunPendingTasks(); // Run posted deadline.
1377 EXPECT_NO_ACTION(client); 1390 EXPECT_NO_ACTION(client);
1378 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); 1391 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending());
1379 EXPECT_FALSE(client.needs_begin_frame()); 1392 EXPECT_FALSE(client.needs_begin_frames());
1380 client.Reset(); 1393 client.Reset();
1381 1394
1382 // NotifyReadyToCommit should trigger the commit. 1395 // NotifyReadyToCommit should trigger the commit.
1383 scheduler->NotifyBeginMainFrameStarted(); 1396 scheduler->NotifyBeginMainFrameStarted();
1384 scheduler->NotifyReadyToCommit(); 1397 scheduler->NotifyReadyToCommit();
1385 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); 1398 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client);
1386 EXPECT_FALSE(client.needs_begin_frame()); 1399 EXPECT_FALSE(client.needs_begin_frames());
1387 client.Reset(); 1400 client.Reset();
1388 1401
1389 // BeginImplFrame should prepare the draw. 1402 // BeginImplFrame should prepare the draw.
1390 client.task_runner().RunPendingTasks(); // Run posted BeginFrame. 1403 client.task_runner().RunPendingTasks(); // Run posted BeginFrame.
1391 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); 1404 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2);
1392 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); 1405 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2);
1393 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 1406 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending());
1394 EXPECT_FALSE(client.needs_begin_frame()); 1407 EXPECT_FALSE(client.needs_begin_frames());
1395 client.Reset(); 1408 client.Reset();
1396 1409
1397 // BeginImplFrame deadline should draw. 1410 // BeginImplFrame deadline should draw.
1398 client.task_runner().RunTasksWhile(client.ImplFrameDeadlinePending(true)); 1411 client.task_runner().RunTasksWhile(client.ImplFrameDeadlinePending(true));
1399 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 1); 1412 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 1);
1400 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); 1413 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending());
1401 EXPECT_FALSE(client.needs_begin_frame()); 1414 EXPECT_FALSE(client.needs_begin_frames());
1402 client.Reset(); 1415 client.Reset();
1403 1416
1404 // The following BeginImplFrame deadline should SetNeedsBeginFrame(false) 1417 // The following BeginImplFrame deadline should SetNeedsBeginFrame(false)
1405 // to avoid excessive toggles. 1418 // to avoid excessive toggles.
1406 client.task_runner().RunPendingTasks(); // Run posted BeginFrame. 1419 client.task_runner().RunPendingTasks(); // Run posted BeginFrame.
1407 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); 1420 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client);
1408 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 1421 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending());
1409 client.Reset(); 1422 client.Reset();
1410 1423
1411 // Make sure SetNeedsBeginFrame isn't called on the client 1424 // Make sure SetNeedsBeginFrame isn't called on the client
1412 // when the BeginFrame is no longer needed. 1425 // when the BeginFrame is no longer needed.
1413 client.task_runner().RunPendingTasks(); // Run posted deadline. 1426 client.task_runner().RunPendingTasks(); // Run posted deadline.
1414 EXPECT_NO_ACTION(client); 1427 EXPECT_NO_ACTION(client);
1415 EXPECT_FALSE(client.needs_begin_frame()); 1428 EXPECT_FALSE(client.needs_begin_frames());
1416 client.Reset(); 1429 client.Reset();
1417 } 1430 }
1418 1431
1419 TEST(SchedulerTest, SyntheticBeginFrames) { 1432 TEST(SchedulerTest, SyntheticBeginFrames) {
1420 bool begin_frame_scheduling_enabled = false; 1433 bool begin_frame_scheduling_enabled = false;
1421 bool throttle_frame_production = true; 1434 bool throttle_frame_production = true;
1422 BeginFramesNotFromClient(begin_frame_scheduling_enabled, 1435 BeginFramesNotFromClient(begin_frame_scheduling_enabled,
1423 throttle_frame_production); 1436 throttle_frame_production);
1424 } 1437 }
1425 1438
(...skipping 24 matching lines...) Expand all
1450 scheduler->SetCanDraw(true); 1463 scheduler->SetCanDraw(true);
1451 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); 1464 InitializeOutputSurfaceAndFirstCommit(scheduler, &client);
1452 1465
1453 // To test swap ack throttling, this test disables automatic swap acks. 1466 // To test swap ack throttling, this test disables automatic swap acks.
1454 scheduler->SetMaxSwapsPending(1); 1467 scheduler->SetMaxSwapsPending(1);
1455 client.SetAutomaticSwapAck(false); 1468 client.SetAutomaticSwapAck(false);
1456 1469
1457 // SetNeedsCommit should begin the frame on the next BeginImplFrame. 1470 // SetNeedsCommit should begin the frame on the next BeginImplFrame.
1458 client.Reset(); 1471 client.Reset();
1459 scheduler->SetNeedsCommit(); 1472 scheduler->SetNeedsCommit();
1460 EXPECT_FALSE(client.needs_begin_frame()); 1473 EXPECT_FALSE(client.needs_begin_frames());
1461 EXPECT_NO_ACTION(client); 1474 EXPECT_NO_ACTION(client);
1462 client.Reset(); 1475 client.Reset();
1463 1476
1464 // Trigger the first BeginImplFrame and BeginMainFrame 1477 // Trigger the first BeginImplFrame and BeginMainFrame
1465 client.task_runner().RunPendingTasks(); // Run posted BeginFrame. 1478 client.task_runner().RunPendingTasks(); // Run posted BeginFrame.
1466 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); 1479 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2);
1467 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); 1480 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2);
1468 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 1481 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending());
1469 EXPECT_FALSE(client.needs_begin_frame()); 1482 EXPECT_FALSE(client.needs_begin_frames());
1470 client.Reset(); 1483 client.Reset();
1471 1484
1472 // NotifyReadyToCommit should trigger the pending commit and draw. 1485 // NotifyReadyToCommit should trigger the pending commit and draw.
1473 scheduler->NotifyBeginMainFrameStarted(); 1486 scheduler->NotifyBeginMainFrameStarted();
1474 scheduler->NotifyReadyToCommit(); 1487 scheduler->NotifyReadyToCommit();
1475 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); 1488 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client);
1476 EXPECT_FALSE(client.needs_begin_frame()); 1489 EXPECT_FALSE(client.needs_begin_frames());
1477 client.Reset(); 1490 client.Reset();
1478 1491
1479 // Swapping will put us into a swap throttled state. 1492 // Swapping will put us into a swap throttled state.
1480 client.task_runner().RunPendingTasks(); // Run posted deadline. 1493 client.task_runner().RunPendingTasks(); // Run posted deadline.
1481 EXPECT_ACTION("ScheduledActionAnimate", client, 0, 2); 1494 EXPECT_ACTION("ScheduledActionAnimate", client, 0, 2);
1482 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 1, 2); 1495 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 1, 2);
1483 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); 1496 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending());
1484 EXPECT_FALSE(client.needs_begin_frame()); 1497 EXPECT_FALSE(client.needs_begin_frames());
1485 client.Reset(); 1498 client.Reset();
1486 1499
1487 // While swap throttled, BeginFrames should trigger BeginImplFrames, 1500 // While swap throttled, BeginFrames should trigger BeginImplFrames,
1488 // but not a BeginMainFrame or draw. 1501 // but not a BeginMainFrame or draw.
1489 scheduler->SetNeedsCommit(); 1502 scheduler->SetNeedsCommit();
1490 client.task_runner().RunPendingTasks(); // Run posted BeginFrame. 1503 client.task_runner().RunPendingTasks(); // Run posted BeginFrame.
1491 EXPECT_ACTION("WillBeginImplFrame", client, 0, 1); 1504 EXPECT_ACTION("WillBeginImplFrame", client, 0, 1);
1492 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 1505 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending());
1493 EXPECT_FALSE(client.needs_begin_frame()); 1506 EXPECT_FALSE(client.needs_begin_frames());
1494 client.Reset(); 1507 client.Reset();
1495 1508
1496 // Take us out of a swap throttled state. 1509 // Take us out of a swap throttled state.
1497 scheduler->DidSwapBuffersComplete(); 1510 scheduler->DidSwapBuffersComplete();
1498 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 0, 1); 1511 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 0, 1);
1499 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 1512 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending());
1500 EXPECT_FALSE(client.needs_begin_frame()); 1513 EXPECT_FALSE(client.needs_begin_frames());
1501 client.Reset(); 1514 client.Reset();
1502 1515
1503 // BeginImplFrame deadline should draw. 1516 // BeginImplFrame deadline should draw.
1504 scheduler->SetNeedsRedraw(); 1517 scheduler->SetNeedsRedraw();
1505 client.task_runner().RunPendingTasks(); // Run posted deadline. 1518 client.task_runner().RunPendingTasks(); // Run posted deadline.
1506 EXPECT_ACTION("ScheduledActionAnimate", client, 0, 2); 1519 EXPECT_ACTION("ScheduledActionAnimate", client, 0, 2);
1507 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 1, 2); 1520 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 1, 2);
1508 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); 1521 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending());
1509 EXPECT_FALSE(client.needs_begin_frame()); 1522 EXPECT_FALSE(client.needs_begin_frames());
1510 client.Reset(); 1523 client.Reset();
1511 } 1524 }
1512 1525
1513 TEST(SchedulerTest, SyntheticBeginFrames_SwapThrottled) { 1526 TEST(SchedulerTest, SyntheticBeginFrames_SwapThrottled) {
1514 bool begin_frame_scheduling_enabled = false; 1527 bool begin_frame_scheduling_enabled = false;
1515 bool throttle_frame_production = true; 1528 bool throttle_frame_production = true;
1516 BeginFramesNotFromClient_SwapThrottled(begin_frame_scheduling_enabled, 1529 BeginFramesNotFromClient_SwapThrottled(begin_frame_scheduling_enabled,
1517 throttle_frame_production); 1530 throttle_frame_production);
1518 } 1531 }
1519 1532
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
1555 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings); 1568 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings);
1556 scheduler->SetCanStart(); 1569 scheduler->SetCanStart();
1557 scheduler->SetVisible(true); 1570 scheduler->SetVisible(true);
1558 scheduler->SetCanDraw(true); 1571 scheduler->SetCanDraw(true);
1559 1572
1560 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); 1573 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client);
1561 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); 1574 InitializeOutputSurfaceAndFirstCommit(scheduler, &client);
1562 // SetNeedsCommit should begin the frame. 1575 // SetNeedsCommit should begin the frame.
1563 client.Reset(); 1576 client.Reset();
1564 scheduler->SetNeedsCommit(); 1577 scheduler->SetNeedsCommit();
1565 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); 1578 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client);
1566 1579
1567 client.Reset(); 1580 client.Reset();
1568 client.AdvanceFrame(); 1581 client.AdvanceFrame();
1569 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); 1582 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2);
1570 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); 1583 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2);
1571 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 1584 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending());
1572 1585
1573 client.Reset(); 1586 client.Reset();
1574 scheduler->DidLoseOutputSurface(); 1587 scheduler->DidLoseOutputSurface();
1575 // Do nothing when impl frame is in deadine pending state. 1588 // Do nothing when impl frame is in deadine pending state.
1576 EXPECT_NO_ACTION(client); 1589 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(false)", client);
1577 1590
1578 client.Reset(); 1591 client.Reset();
1579 scheduler->NotifyBeginMainFrameStarted(); 1592 scheduler->NotifyBeginMainFrameStarted();
1580 scheduler->NotifyReadyToCommit(); 1593 scheduler->NotifyReadyToCommit();
1581 EXPECT_ACTION("ScheduledActionCommit", client, 0, 1); 1594 EXPECT_ACTION("ScheduledActionCommit", client, 0, 1);
1582 1595
1583 client.Reset(); 1596 client.Reset();
1584 client.task_runner().RunPendingTasks(); // Run posted deadline. 1597 client.task_runner().RunPendingTasks(); // Run posted deadline.
1585 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); 1598 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client);
1586 } 1599 }
1587 1600
1588 void DidLoseOutputSurfaceAfterBeginFrameStartedWithHighLatency( 1601 void DidLoseOutputSurfaceAfterBeginFrameStartedWithHighLatency(
1589 bool impl_side_painting) { 1602 bool impl_side_painting) {
1590 FakeSchedulerClient client; 1603 FakeSchedulerClient client;
1591 SchedulerSettings scheduler_settings; 1604 SchedulerSettings scheduler_settings;
1592 scheduler_settings.impl_side_painting = impl_side_painting; 1605 scheduler_settings.impl_side_painting = impl_side_painting;
1593 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings); 1606 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings);
1594 scheduler->SetCanStart(); 1607 scheduler->SetCanStart();
1595 scheduler->SetVisible(true); 1608 scheduler->SetVisible(true);
1596 scheduler->SetCanDraw(true); 1609 scheduler->SetCanDraw(true);
1597 1610
1598 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); 1611 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client);
1599 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); 1612 InitializeOutputSurfaceAndFirstCommit(scheduler, &client);
1600 1613
1601 // SetNeedsCommit should begin the frame. 1614 // SetNeedsCommit should begin the frame.
1602 client.Reset(); 1615 client.Reset();
1603 scheduler->SetNeedsCommit(); 1616 scheduler->SetNeedsCommit();
1604 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); 1617 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client);
1605 1618
1606 client.Reset(); 1619 client.Reset();
1607 client.AdvanceFrame(); 1620 client.AdvanceFrame();
1608 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); 1621 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2);
1609 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); 1622 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2);
1610 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 1623 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending());
1611 1624
1612 client.Reset(); 1625 client.Reset();
1613 scheduler->DidLoseOutputSurface(); 1626 scheduler->DidLoseOutputSurface();
1614 // Do nothing when impl frame is in deadine pending state. 1627 // Do nothing when impl frame is in deadine pending state.
1615 EXPECT_NO_ACTION(client); 1628 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(false)", client);
1616 1629
1617 client.Reset(); 1630 client.Reset();
1618 // Run posted deadline. 1631 // Run posted deadline.
1619 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 1632 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending());
1620 client.task_runner().RunTasksWhile(client.ImplFrameDeadlinePending(true)); 1633 client.task_runner().RunTasksWhile(client.ImplFrameDeadlinePending(true));
1621 // OnBeginImplFrameDeadline didn't schedule any actions because main frame is 1634 // OnBeginImplFrameDeadline didn't schedule any actions because main frame is
1622 // not yet completed. 1635 // not yet completed.
1623 EXPECT_NO_ACTION(client); 1636 EXPECT_NO_ACTION(client);
1624 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); 1637 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending());
1625 1638
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
1661 scheduler->SetCanStart(); 1674 scheduler->SetCanStart();
1662 scheduler->SetVisible(true); 1675 scheduler->SetVisible(true);
1663 scheduler->SetCanDraw(true); 1676 scheduler->SetCanDraw(true);
1664 1677
1665 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); 1678 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client);
1666 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); 1679 InitializeOutputSurfaceAndFirstCommit(scheduler, &client);
1667 1680
1668 // SetNeedsCommit should begin the frame. 1681 // SetNeedsCommit should begin the frame.
1669 client.Reset(); 1682 client.Reset();
1670 scheduler->SetNeedsCommit(); 1683 scheduler->SetNeedsCommit();
1671 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); 1684 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client);
1672 1685
1673 client.Reset(); 1686 client.Reset();
1674 client.AdvanceFrame(); 1687 client.AdvanceFrame();
1675 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); 1688 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2);
1676 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); 1689 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2);
1677 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 1690 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending());
1678 1691
1679 client.Reset(); 1692 client.Reset();
1680 scheduler->NotifyBeginMainFrameStarted(); 1693 scheduler->NotifyBeginMainFrameStarted();
1681 scheduler->NotifyReadyToCommit(); 1694 scheduler->NotifyReadyToCommit();
1682 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); 1695 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client);
1683 1696
1684 client.Reset(); 1697 client.Reset();
1685 scheduler->DidLoseOutputSurface(); 1698 scheduler->DidLoseOutputSurface();
1686 if (impl_side_painting) { 1699 if (impl_side_painting) {
1687 // Sync tree should be forced to activate. 1700 // Sync tree should be forced to activate.
1688 EXPECT_SINGLE_ACTION("ScheduledActionActivateSyncTree", client); 1701 EXPECT_ACTION("SetNeedsBeginFrames(false)", client, 0, 2);
1702 EXPECT_ACTION("ScheduledActionActivateSyncTree", client, 1, 2);
1689 } else { 1703 } else {
1690 // Do nothing when impl frame is in deadine pending state. 1704 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(false)", client);
1691 EXPECT_NO_ACTION(client);
1692 } 1705 }
1693 1706
1694 client.Reset(); 1707 client.Reset();
1695 client.task_runner().RunPendingTasks(); // Run posted deadline. 1708 client.task_runner().RunPendingTasks(); // Run posted deadline.
1696 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); 1709 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client);
1697 } 1710 }
1698 1711
1699 TEST(SchedulerTest, DidLoseOutputSurfaceAfterReadyToCommit) { 1712 TEST(SchedulerTest, DidLoseOutputSurfaceAfterReadyToCommit) {
1700 DidLoseOutputSurfaceAfterReadyToCommit(false); 1713 DidLoseOutputSurfaceAfterReadyToCommit(false);
1701 } 1714 }
1702 1715
1703 TEST(SchedulerTest, DidLoseOutputSurfaceAfterReadyToCommitWithImplPainting) { 1716 TEST(SchedulerTest, DidLoseOutputSurfaceAfterReadyToCommitWithImplPainting) {
1704 DidLoseOutputSurfaceAfterReadyToCommit(true); 1717 DidLoseOutputSurfaceAfterReadyToCommit(true);
1705 } 1718 }
1706 1719
1707 TEST(SchedulerTest, DidLoseOutputSurfaceAfterSetNeedsManageTiles) { 1720 TEST(SchedulerTest, DidLoseOutputSurfaceAfterSetNeedsManageTiles) {
1708 FakeSchedulerClient client; 1721 FakeSchedulerClient client;
1709 SchedulerSettings scheduler_settings; 1722 SchedulerSettings scheduler_settings;
1710 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings); 1723 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings);
1711 scheduler->SetCanStart(); 1724 scheduler->SetCanStart();
1712 scheduler->SetVisible(true); 1725 scheduler->SetVisible(true);
1713 scheduler->SetCanDraw(true); 1726 scheduler->SetCanDraw(true);
1714 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); 1727 InitializeOutputSurfaceAndFirstCommit(scheduler, &client);
1715 1728
1716 client.Reset(); 1729 client.Reset();
1717 scheduler->SetNeedsManageTiles(); 1730 scheduler->SetNeedsManageTiles();
1718 scheduler->SetNeedsRedraw(); 1731 scheduler->SetNeedsRedraw();
1719 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); 1732 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client);
1720 EXPECT_TRUE(client.needs_begin_frame());
1721 1733
1722 client.Reset(); 1734 client.Reset();
1723 client.AdvanceFrame(); 1735 client.AdvanceFrame();
1724 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); 1736 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2);
1725 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); 1737 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2);
1726 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 1738 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending());
1727 1739
1728 client.Reset(); 1740 client.Reset();
1729 scheduler->DidLoseOutputSurface(); 1741 scheduler->DidLoseOutputSurface();
1730 EXPECT_NO_ACTION(client); 1742 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(false)", client);
1731 1743
1732 client.Reset(); 1744 client.Reset();
1733 client.task_runner().RunPendingTasks(); // Run posted deadline. 1745 client.task_runner().RunPendingTasks(); // Run posted deadline.
1734 EXPECT_ACTION("ScheduledActionManageTiles", client, 0, 2); 1746 EXPECT_ACTION("ScheduledActionManageTiles", client, 0, 2);
1735 EXPECT_ACTION("ScheduledActionBeginOutputSurfaceCreation", client, 1, 2); 1747 EXPECT_ACTION("ScheduledActionBeginOutputSurfaceCreation", client, 1, 2);
1736 } 1748 }
1737 1749
1738 TEST(SchedulerTest, DidLoseOutputSurfaceAfterBeginRetroFramePosted) { 1750 TEST(SchedulerTest, DidLoseOutputSurfaceAfterBeginRetroFramePosted) {
1739 FakeSchedulerClient client; 1751 FakeSchedulerClient client;
1740 SchedulerSettings scheduler_settings; 1752 SchedulerSettings scheduler_settings;
1741 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings); 1753 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings);
1742 scheduler->SetCanStart(); 1754 scheduler->SetCanStart();
1743 scheduler->SetVisible(true); 1755 scheduler->SetVisible(true);
1744 scheduler->SetCanDraw(true); 1756 scheduler->SetCanDraw(true);
1745 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); 1757 InitializeOutputSurfaceAndFirstCommit(scheduler, &client);
1746 1758
1747 // SetNeedsCommit should begin the frame on the next BeginImplFrame. 1759 // SetNeedsCommit should begin the frame on the next BeginImplFrame.
1748 client.Reset(); 1760 client.Reset();
1749 scheduler->SetNeedsCommit(); 1761 scheduler->SetNeedsCommit();
1750 EXPECT_TRUE(client.needs_begin_frame()); 1762 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client);
1751 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client);
1752 1763
1753 // Create a BeginFrame with a long deadline to avoid race conditions. 1764 // Create a BeginFrame with a long deadline to avoid race conditions.
1754 // This is the first BeginFrame, which will be handled immediately. 1765 // This is the first BeginFrame, which will be handled immediately.
1755 client.Reset(); 1766 client.Reset();
1756 BeginFrameArgs args = CreateBeginFrameArgsForTesting(client.now_src()); 1767 BeginFrameArgs args = CreateBeginFrameArgsForTesting(client.now_src());
1757 args.deadline += base::TimeDelta::FromHours(1); 1768 args.deadline += base::TimeDelta::FromHours(1);
1758 scheduler->BeginFrame(args); 1769 client.ExternalBeginFrameSource()->TestOnBeginFrame(args);
1759 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); 1770 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2);
1760 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); 1771 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2);
1761 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 1772 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending());
1762 EXPECT_TRUE(client.needs_begin_frame()); 1773 EXPECT_TRUE(client.needs_begin_frames());
1763 1774
1764 // Queue BeginFrames while we are still handling the previous BeginFrame. 1775 // Queue BeginFrames while we are still handling the previous BeginFrame.
1765 args.frame_time += base::TimeDelta::FromSeconds(1); 1776 args.frame_time += base::TimeDelta::FromSeconds(1);
1766 scheduler->BeginFrame(args); 1777 client.ExternalBeginFrameSource()->TestOnBeginFrame(args);
1767 args.frame_time += base::TimeDelta::FromSeconds(1); 1778 args.frame_time += base::TimeDelta::FromSeconds(1);
1768 scheduler->BeginFrame(args); 1779 client.ExternalBeginFrameSource()->TestOnBeginFrame(args);
1769 1780
1770 // If we don't swap on the deadline, we wait for the next BeginImplFrame. 1781 // If we don't swap on the deadline, we wait for the next BeginImplFrame.
1771 client.Reset(); 1782 client.Reset();
1772 client.task_runner().RunPendingTasks(); // Run posted deadline. 1783 client.task_runner().RunPendingTasks(); // Run posted deadline.
1773 EXPECT_NO_ACTION(client); 1784 EXPECT_NO_ACTION(client);
1774 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); 1785 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending());
1775 EXPECT_TRUE(client.needs_begin_frame()); 1786 EXPECT_TRUE(client.needs_begin_frames());
1776 1787
1777 // NotifyReadyToCommit should trigger the commit. 1788 // NotifyReadyToCommit should trigger the commit.
1778 client.Reset(); 1789 client.Reset();
1779 scheduler->NotifyBeginMainFrameStarted(); 1790 scheduler->NotifyBeginMainFrameStarted();
1780 scheduler->NotifyReadyToCommit(); 1791 scheduler->NotifyReadyToCommit();
1781 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); 1792 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client);
1782 EXPECT_TRUE(client.needs_begin_frame()); 1793 EXPECT_TRUE(client.needs_begin_frames());
1783 1794
1784 client.Reset(); 1795 client.Reset();
1785 EXPECT_FALSE(scheduler->IsBeginRetroFrameArgsEmpty()); 1796 EXPECT_FALSE(scheduler->IsBeginRetroFrameArgsEmpty());
1786 scheduler->DidLoseOutputSurface(); 1797 scheduler->DidLoseOutputSurface();
1787 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); 1798 EXPECT_ACTION("SetNeedsBeginFrames(false)", client, 0, 2);
1788 EXPECT_TRUE(client.needs_begin_frame()); 1799 EXPECT_ACTION("ScheduledActionBeginOutputSurfaceCreation", client, 1, 2);
1789 EXPECT_TRUE(scheduler->IsBeginRetroFrameArgsEmpty()); 1800 EXPECT_TRUE(scheduler->IsBeginRetroFrameArgsEmpty());
1790 1801
1791 // Posted BeginRetroFrame is aborted. 1802 // Posted BeginRetroFrame is aborted.
1792 client.Reset(); 1803 client.Reset();
1793 client.task_runner().RunPendingTasks(); 1804 client.task_runner().RunPendingTasks();
1794 EXPECT_NO_ACTION(client); 1805 EXPECT_NO_ACTION(client);
1795 } 1806 }
1796 1807
1797 TEST(SchedulerTest, DidLoseOutputSurfaceDuringBeginRetroFrameRunning) { 1808 TEST(SchedulerTest, DidLoseOutputSurfaceDuringBeginRetroFrameRunning) {
1798 FakeSchedulerClient client; 1809 FakeSchedulerClient client;
1799 SchedulerSettings scheduler_settings; 1810 SchedulerSettings scheduler_settings;
1800 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings); 1811 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings);
1801 scheduler->SetCanStart(); 1812 scheduler->SetCanStart();
1802 scheduler->SetVisible(true); 1813 scheduler->SetVisible(true);
1803 scheduler->SetCanDraw(true); 1814 scheduler->SetCanDraw(true);
1804 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); 1815 InitializeOutputSurfaceAndFirstCommit(scheduler, &client);
1805 1816
1806 // SetNeedsCommit should begin the frame on the next BeginImplFrame. 1817 // SetNeedsCommit should begin the frame on the next BeginImplFrame.
1807 client.Reset(); 1818 client.Reset();
1808 scheduler->SetNeedsCommit(); 1819 scheduler->SetNeedsCommit();
1809 EXPECT_TRUE(client.needs_begin_frame()); 1820 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client);
1810 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client);
1811 1821
1812 // Create a BeginFrame with a long deadline to avoid race conditions. 1822 // Create a BeginFrame with a long deadline to avoid race conditions.
1813 // This is the first BeginFrame, which will be handled immediately. 1823 // This is the first BeginFrame, which will be handled immediately.
1814 client.Reset(); 1824 client.Reset();
1815 BeginFrameArgs args = CreateBeginFrameArgsForTesting(client.now_src()); 1825 BeginFrameArgs args = CreateBeginFrameArgsForTesting(client.now_src());
1816 args.deadline += base::TimeDelta::FromHours(1); 1826 args.deadline += base::TimeDelta::FromHours(1);
1817 scheduler->BeginFrame(args); 1827 client.ExternalBeginFrameSource()->TestOnBeginFrame(args);
1818 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); 1828 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2);
1819 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); 1829 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2);
1820 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 1830 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending());
1821 EXPECT_TRUE(client.needs_begin_frame()); 1831 EXPECT_TRUE(client.needs_begin_frames());
1822 1832
1823 // Queue BeginFrames while we are still handling the previous BeginFrame. 1833 // Queue BeginFrames while we are still handling the previous BeginFrame.
1824 args.frame_time += base::TimeDelta::FromSeconds(1); 1834 args.frame_time += base::TimeDelta::FromSeconds(1);
1825 scheduler->BeginFrame(args); 1835 client.ExternalBeginFrameSource()->TestOnBeginFrame(args);
1826 args.frame_time += base::TimeDelta::FromSeconds(1); 1836 args.frame_time += base::TimeDelta::FromSeconds(1);
1827 scheduler->BeginFrame(args); 1837 client.ExternalBeginFrameSource()->TestOnBeginFrame(args);
1828 1838
1829 // If we don't swap on the deadline, we wait for the next BeginImplFrame. 1839 // If we don't swap on the deadline, we wait for the next BeginImplFrame.
1830 client.Reset(); 1840 client.Reset();
1831 client.task_runner().RunPendingTasks(); // Run posted deadline. 1841 client.task_runner().RunPendingTasks(); // Run posted deadline.
1832 EXPECT_NO_ACTION(client); 1842 EXPECT_NO_ACTION(client);
1833 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); 1843 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending());
1834 EXPECT_TRUE(client.needs_begin_frame()); 1844 EXPECT_TRUE(client.needs_begin_frames());
1835 1845
1836 // NotifyReadyToCommit should trigger the commit. 1846 // NotifyReadyToCommit should trigger the commit.
1837 client.Reset(); 1847 client.Reset();
1838 scheduler->NotifyBeginMainFrameStarted(); 1848 scheduler->NotifyBeginMainFrameStarted();
1839 scheduler->NotifyReadyToCommit(); 1849 scheduler->NotifyReadyToCommit();
1840 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); 1850 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client);
1841 EXPECT_TRUE(client.needs_begin_frame()); 1851 EXPECT_TRUE(client.needs_begin_frames());
1842 1852
1843 // BeginImplFrame should prepare the draw. 1853 // BeginImplFrame should prepare the draw.
1844 client.Reset(); 1854 client.Reset();
1845 client.task_runner().RunPendingTasks(); // Run posted BeginRetroFrame. 1855 client.task_runner().RunPendingTasks(); // Run posted BeginRetroFrame.
1846 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); 1856 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2);
1847 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); 1857 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2);
1848 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 1858 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending());
1849 EXPECT_TRUE(client.needs_begin_frame()); 1859 EXPECT_TRUE(client.needs_begin_frames());
1850 1860
1851 client.Reset(); 1861 client.Reset();
1852 EXPECT_FALSE(scheduler->IsBeginRetroFrameArgsEmpty()); 1862 EXPECT_FALSE(scheduler->IsBeginRetroFrameArgsEmpty());
1853 scheduler->DidLoseOutputSurface(); 1863 scheduler->DidLoseOutputSurface();
1854 EXPECT_NO_ACTION(client); 1864 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(false)", client);
1855 EXPECT_TRUE(scheduler->IsBeginRetroFrameArgsEmpty()); 1865 EXPECT_TRUE(scheduler->IsBeginRetroFrameArgsEmpty());
1856 1866
1857 // BeginImplFrame deadline should abort drawing. 1867 // BeginImplFrame deadline should abort drawing.
1858 client.Reset(); 1868 client.Reset();
1859 client.task_runner().RunPendingTasks(); // Run posted deadline. 1869 client.task_runner().RunPendingTasks(); // Run posted deadline.
1860 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); 1870 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client);
1861 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); 1871 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending());
1862 EXPECT_TRUE(client.needs_begin_frame()); 1872 EXPECT_FALSE(client.needs_begin_frames());
1863 1873
1864 // No more BeginRetroFrame because BeginRetroFrame queue is cleared. 1874 // No more BeginRetroFrame because BeginRetroFrame queue is cleared.
1865 client.Reset(); 1875 client.Reset();
1866 client.task_runner().RunPendingTasks(); 1876 client.task_runner().RunPendingTasks();
1867 EXPECT_NO_ACTION(client); 1877 EXPECT_NO_ACTION(client);
1868 } 1878 }
1869 1879
1870 TEST(SchedulerTest, 1880 TEST(SchedulerTest,
1871 StopBeginFrameAfterDidLoseOutputSurfaceWithSyntheticBeginFrameSource) { 1881 StopBeginFrameAfterDidLoseOutputSurfaceWithSyntheticBeginFrameSource) {
1872 FakeSchedulerClient client; 1882 FakeSchedulerClient client;
1873 SchedulerSettings scheduler_settings; 1883 SchedulerSettings scheduler_settings;
1874 scheduler_settings.begin_frame_scheduling_enabled = false; 1884 scheduler_settings.begin_frame_scheduling_enabled = false;
1875 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings); 1885 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings);
1876 scheduler->SetCanStart(); 1886 scheduler->SetCanStart();
1877 scheduler->SetVisible(true); 1887 scheduler->SetVisible(true);
1878 scheduler->SetCanDraw(true); 1888 scheduler->SetCanDraw(true);
1879 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); 1889 InitializeOutputSurfaceAndFirstCommit(scheduler, &client);
1880 1890
1881 // SetNeedsCommit should begin the frame on the next BeginImplFrame. 1891 // SetNeedsCommit should begin the frame on the next BeginImplFrame.
1882 client.Reset(); 1892 client.Reset();
1883 EXPECT_FALSE(scheduler->IsSyntheticBeginFrameSourceActive()); 1893 EXPECT_FALSE(scheduler->frame_source().NeedsBeginFrames());
1884 scheduler->SetNeedsCommit(); 1894 scheduler->SetNeedsCommit();
1885 EXPECT_TRUE(scheduler->IsSyntheticBeginFrameSourceActive()); 1895 EXPECT_TRUE(scheduler->frame_source().NeedsBeginFrames());
1886 1896
1887 client.Reset(); 1897 client.Reset();
1888 client.task_runner().RunPendingTasks(); // Run posted Tick. 1898 client.task_runner().RunPendingTasks(); // Run posted Tick.
1889 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); 1899 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2);
1890 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); 1900 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2);
1891 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 1901 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending());
1892 EXPECT_TRUE(scheduler->IsSyntheticBeginFrameSourceActive()); 1902 EXPECT_TRUE(scheduler->frame_source().NeedsBeginFrames());
1893 1903
1894 // NotifyReadyToCommit should trigger the commit. 1904 // NotifyReadyToCommit should trigger the commit.
1895 client.Reset(); 1905 client.Reset();
1896 scheduler->NotifyBeginMainFrameStarted(); 1906 scheduler->NotifyBeginMainFrameStarted();
1897 scheduler->NotifyReadyToCommit(); 1907 scheduler->NotifyReadyToCommit();
1898 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); 1908 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client);
1899 EXPECT_TRUE(scheduler->IsSyntheticBeginFrameSourceActive()); 1909 EXPECT_TRUE(scheduler->frame_source().NeedsBeginFrames());
1900 1910
1901 client.Reset(); 1911 client.Reset();
1902 scheduler->DidLoseOutputSurface(); 1912 scheduler->DidLoseOutputSurface();
1903 EXPECT_EQ(0, client.num_actions_()); 1913 EXPECT_NO_ACTION(client);
1904 EXPECT_FALSE(scheduler->IsSyntheticBeginFrameSourceActive()); 1914 EXPECT_FALSE(scheduler->frame_source().NeedsBeginFrames());
1905 1915
1906 client.Reset(); 1916 client.Reset();
1907 client.task_runner().RunPendingTasks(); // Run posted deadline. 1917 client.task_runner().RunPendingTasks(); // Run posted deadline.
1908 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); 1918 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client);
1909 EXPECT_FALSE(scheduler->IsSyntheticBeginFrameSourceActive()); 1919 EXPECT_FALSE(scheduler->frame_source().NeedsBeginFrames());
1910 } 1920 }
1911 1921
1912 } // namespace 1922 } // namespace
1913 } // namespace cc 1923 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698