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

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

Powered by Google App Engine
This is Rietveld 408576698