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

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

Powered by Google App Engine
This is Rietveld 408576698