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

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

Issue 218633010: cc: Handle retroactive BeginFrames in the Scheduler. (Closed) Base URL: http://git.chromium.org/chromium/src.git@compositorVsyncDisable
Patch Set: rebase Created 6 years, 8 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
OLDNEW
1 // Copyright 2011 The Chromium Authors. All rights reserved. 1 // Copyright 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 #include "cc/scheduler/scheduler.h" 4 #include "cc/scheduler/scheduler.h"
5 5
6 #include <string> 6 #include <string>
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/memory/scoped_vector.h" 10 #include "base/memory/scoped_vector.h"
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 } 87 }
88 88
89 void SetDrawWillHappen(bool draw_will_happen) { 89 void SetDrawWillHappen(bool draw_will_happen) {
90 draw_will_happen_ = draw_will_happen; 90 draw_will_happen_ = draw_will_happen;
91 } 91 }
92 void SetSwapWillHappenIfDrawHappens(bool swap_will_happen_if_draw_happens) { 92 void SetSwapWillHappenIfDrawHappens(bool swap_will_happen_if_draw_happens) {
93 swap_will_happen_if_draw_happens_ = swap_will_happen_if_draw_happens; 93 swap_will_happen_if_draw_happens_ = swap_will_happen_if_draw_happens;
94 } 94 }
95 95
96 // SchedulerClient implementation. 96 // SchedulerClient implementation.
97 virtual void SetNeedsBeginImplFrame(bool enable) OVERRIDE { 97 virtual void SetNeedsBeginFrame(bool enable) OVERRIDE {
98 actions_.push_back("SetNeedsBeginImplFrame"); 98 actions_.push_back("SetNeedsBeginFrame");
99 states_.push_back(scheduler_->StateAsValue().release()); 99 states_.push_back(scheduler_->StateAsValue().release());
100 needs_begin_impl_frame_ = enable; 100 needs_begin_impl_frame_ = enable;
101 } 101 }
102 virtual void WillBeginImplFrame(const BeginFrameArgs& args) OVERRIDE {
103 actions_.push_back("WillBeginImplFrame");
104 states_.push_back(scheduler_->StateAsValue().release());
105 }
102 virtual void ScheduledActionSendBeginMainFrame() OVERRIDE { 106 virtual void ScheduledActionSendBeginMainFrame() OVERRIDE {
103 actions_.push_back("ScheduledActionSendBeginMainFrame"); 107 actions_.push_back("ScheduledActionSendBeginMainFrame");
104 states_.push_back(scheduler_->StateAsValue().release()); 108 states_.push_back(scheduler_->StateAsValue().release());
105 } 109 }
106 virtual DrawSwapReadbackResult ScheduledActionDrawAndSwapIfPossible() 110 virtual DrawSwapReadbackResult ScheduledActionDrawAndSwapIfPossible()
107 OVERRIDE { 111 OVERRIDE {
108 actions_.push_back("ScheduledActionDrawAndSwapIfPossible"); 112 actions_.push_back("ScheduledActionDrawAndSwapIfPossible");
109 states_.push_back(scheduler_->StateAsValue().release()); 113 states_.push_back(scheduler_->StateAsValue().release());
110 num_draws_++; 114 num_draws_++;
111 bool did_readback = false; 115 bool did_readback = false;
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 scoped_refptr<base::TestSimpleTaskRunner> task_runner_; 191 scoped_refptr<base::TestSimpleTaskRunner> task_runner_;
188 }; 192 };
189 193
190 void InitializeOutputSurfaceAndFirstCommit(Scheduler* scheduler, 194 void InitializeOutputSurfaceAndFirstCommit(Scheduler* scheduler,
191 FakeSchedulerClient* client) { 195 FakeSchedulerClient* client) {
192 scheduler->DidCreateAndInitializeOutputSurface(); 196 scheduler->DidCreateAndInitializeOutputSurface();
193 scheduler->SetNeedsCommit(); 197 scheduler->SetNeedsCommit();
194 scheduler->NotifyBeginMainFrameStarted(); 198 scheduler->NotifyBeginMainFrameStarted();
195 scheduler->NotifyReadyToCommit(); 199 scheduler->NotifyReadyToCommit();
196 // Go through the motions to draw the commit. 200 // Go through the motions to draw the commit.
197 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); 201 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting());
198 202
199 // Run the posted deadline task. 203 // Run the posted deadline task.
200 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 204 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending());
201 client->task_runner().RunPendingTasks(); 205 client->task_runner().RunPendingTasks();
202 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); 206 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending());
203 207
204 // We need another BeginImplFrame so Scheduler calls 208 // We need another BeginImplFrame so Scheduler calls
205 // SetNeedsBeginImplFrame(false). 209 // SetNeedsBeginFrame(false).
206 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); 210 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting());
207 211
208 // Run the posted deadline task. 212 // Run the posted deadline task.
209 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 213 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending());
210 client->task_runner().RunPendingTasks(); 214 client->task_runner().RunPendingTasks();
211 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); 215 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending());
212 } 216 }
213 217
214 TEST(SchedulerTest, InitializeOutputSurfaceDoesNotBeginImplFrame) { 218 TEST(SchedulerTest, InitializeOutputSurfaceDoesNotBeginImplFrame) {
215 FakeSchedulerClient client; 219 FakeSchedulerClient client;
216 SchedulerSettings default_scheduler_settings; 220 SchedulerSettings default_scheduler_settings;
(...skipping 16 matching lines...) Expand all
233 scheduler->SetVisible(true); 237 scheduler->SetVisible(true);
234 scheduler->SetCanDraw(true); 238 scheduler->SetCanDraw(true);
235 239
236 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); 240 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client);
237 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); 241 InitializeOutputSurfaceAndFirstCommit(scheduler, &client);
238 242
239 // SetNeedsCommit should begin the frame on the next BeginImplFrame. 243 // SetNeedsCommit should begin the frame on the next BeginImplFrame.
240 client.Reset(); 244 client.Reset();
241 scheduler->SetNeedsCommit(); 245 scheduler->SetNeedsCommit();
242 EXPECT_TRUE(client.needs_begin_impl_frame()); 246 EXPECT_TRUE(client.needs_begin_impl_frame());
243 EXPECT_SINGLE_ACTION("SetNeedsBeginImplFrame", client); 247 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client);
244 client.Reset(); 248 client.Reset();
245 249
246 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); 250 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting());
247 EXPECT_SINGLE_ACTION("ScheduledActionSendBeginMainFrame", client); 251 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2);
252 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2);
248 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 253 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending());
249 EXPECT_TRUE(client.needs_begin_impl_frame()); 254 EXPECT_TRUE(client.needs_begin_impl_frame());
250 client.Reset(); 255 client.Reset();
251 256
252 // If we don't swap on the deadline, we need to request another 257 // If we don't swap on the deadline, we need to request another
253 // BeginImplFrame. 258 // BeginImplFrame.
254 scheduler->OnBeginImplFrameDeadline(); 259 client.task_runner().RunPendingTasks(); // Run posted deadline.
255 EXPECT_SINGLE_ACTION("SetNeedsBeginImplFrame", client); 260 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client);
256 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); 261 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending());
257 EXPECT_TRUE(client.needs_begin_impl_frame()); 262 EXPECT_TRUE(client.needs_begin_impl_frame());
258 client.Reset(); 263 client.Reset();
259 264
260 // NotifyReadyToCommit should trigger the commit. 265 // NotifyReadyToCommit should trigger the commit.
261 scheduler->NotifyBeginMainFrameStarted(); 266 scheduler->NotifyBeginMainFrameStarted();
262 scheduler->NotifyReadyToCommit(); 267 scheduler->NotifyReadyToCommit();
263 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); 268 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client);
264 EXPECT_TRUE(client.needs_begin_impl_frame()); 269 EXPECT_TRUE(client.needs_begin_impl_frame());
265 client.Reset(); 270 client.Reset();
266 271
267 // BeginImplFrame should prepare the draw. 272 // BeginImplFrame should prepare the draw.
268 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); 273 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting());
269 EXPECT_EQ(client.num_actions_(), 0); 274 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client);
270 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 275 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending());
271 EXPECT_TRUE(client.needs_begin_impl_frame()); 276 EXPECT_TRUE(client.needs_begin_impl_frame());
272 client.Reset(); 277 client.Reset();
273 278
274 // BeginImplFrame deadline should draw. 279 // BeginImplFrame deadline should draw.
275 scheduler->OnBeginImplFrameDeadline(); 280 client.task_runner().RunPendingTasks(); // Run posted deadline.
276 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 2); 281 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 2);
277 EXPECT_ACTION("SetNeedsBeginImplFrame", client, 1, 2); 282 EXPECT_ACTION("SetNeedsBeginFrame", client, 1, 2);
278 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); 283 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending());
279 EXPECT_TRUE(client.needs_begin_impl_frame()); 284 EXPECT_TRUE(client.needs_begin_impl_frame());
280 client.Reset(); 285 client.Reset();
281 286
282 // The following BeginImplFrame deadline should SetNeedsBeginImplFrame(false) 287 // The following BeginImplFrame deadline should SetNeedsBeginFrame(false)
283 // to avoid excessive toggles. 288 // to avoid excessive toggles.
284 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); 289 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting());
285 EXPECT_EQ(client.num_actions_(), 0); 290 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client);
286 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 291 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending());
287 client.Reset(); 292 client.Reset();
288 293
289 scheduler->OnBeginImplFrameDeadline(); 294 client.task_runner().RunPendingTasks(); // Run posted deadline.
290 EXPECT_SINGLE_ACTION("SetNeedsBeginImplFrame", client); 295 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client);
291 EXPECT_FALSE(client.needs_begin_impl_frame()); 296 EXPECT_FALSE(client.needs_begin_impl_frame());
292 client.Reset(); 297 client.Reset();
293 } 298 }
294 299
295 TEST(SchedulerTest, RequestCommitAfterBeginMainFrameSent) { 300 TEST(SchedulerTest, RequestCommitAfterBeginMainFrameSent) {
296 FakeSchedulerClient client; 301 FakeSchedulerClient client;
297 SchedulerSettings scheduler_settings; 302 SchedulerSettings scheduler_settings;
298 Scheduler* scheduler = client.CreateScheduler(scheduler_settings); 303 Scheduler* scheduler = client.CreateScheduler(scheduler_settings);
299 scheduler->SetCanStart(); 304 scheduler->SetCanStart();
300 scheduler->SetVisible(true); 305 scheduler->SetVisible(true);
301 scheduler->SetCanDraw(true); 306 scheduler->SetCanDraw(true);
302 307
303 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); 308 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client);
304 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); 309 InitializeOutputSurfaceAndFirstCommit(scheduler, &client);
305 client.Reset(); 310 client.Reset();
306 311
307 // SetNeedsCommit should begin the frame. 312 // SetNeedsCommit should begin the frame.
308 scheduler->SetNeedsCommit(); 313 scheduler->SetNeedsCommit();
309 EXPECT_SINGLE_ACTION("SetNeedsBeginImplFrame", client); 314 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client);
310 315
311 client.Reset(); 316 client.Reset();
312 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); 317 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting());
313 EXPECT_SINGLE_ACTION("ScheduledActionSendBeginMainFrame", client); 318 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2);
319 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2);
314 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 320 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending());
315 321
316 EXPECT_TRUE(client.needs_begin_impl_frame()); 322 EXPECT_TRUE(client.needs_begin_impl_frame());
317 client.Reset(); 323 client.Reset();
318 324
319 // Now SetNeedsCommit again. Calling here means we need a second commit. 325 // Now SetNeedsCommit again. Calling here means we need a second commit.
320 scheduler->SetNeedsCommit(); 326 scheduler->SetNeedsCommit();
321 EXPECT_EQ(client.num_actions_(), 0); 327 EXPECT_EQ(client.num_actions_(), 0);
322 client.Reset(); 328 client.Reset();
323 329
324 // Finish the first commit. 330 // Finish the first commit.
325 scheduler->NotifyBeginMainFrameStarted(); 331 scheduler->NotifyBeginMainFrameStarted();
326 scheduler->NotifyReadyToCommit(); 332 scheduler->NotifyReadyToCommit();
327 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); 333 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client);
328 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 334 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending());
329 client.Reset(); 335 client.Reset();
330 scheduler->OnBeginImplFrameDeadline(); 336 client.task_runner().RunPendingTasks(); // Run posted deadline.
331 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 2); 337 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 2);
332 EXPECT_ACTION("SetNeedsBeginImplFrame", client, 1, 2); 338 EXPECT_ACTION("SetNeedsBeginFrame", client, 1, 2);
333 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); 339 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending());
334 340
335 // Because we just swapped, the Scheduler should also request the next 341 // Because we just swapped, the Scheduler should also request the next
336 // BeginImplFrame from the OutputSurface. 342 // BeginImplFrame from the OutputSurface.
337 EXPECT_TRUE(client.needs_begin_impl_frame()); 343 EXPECT_TRUE(client.needs_begin_impl_frame());
338 client.Reset(); 344 client.Reset();
339
340 // Since another commit is needed, the next BeginImplFrame should initiate 345 // Since another commit is needed, the next BeginImplFrame should initiate
341 // the second commit. 346 // the second commit.
342 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); 347 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting());
343 EXPECT_SINGLE_ACTION("ScheduledActionSendBeginMainFrame", client); 348 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2);
349 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2);
344 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 350 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending());
345 client.Reset(); 351 client.Reset();
346 352
347 // Finishing the commit before the deadline should post a new deadline task 353 // Finishing the commit before the deadline should post a new deadline task
348 // to trigger the deadline early. 354 // to trigger the deadline early.
349 scheduler->NotifyBeginMainFrameStarted(); 355 scheduler->NotifyBeginMainFrameStarted();
350 scheduler->NotifyReadyToCommit(); 356 scheduler->NotifyReadyToCommit();
351 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); 357 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client);
352 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 358 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending());
353 client.Reset(); 359 client.Reset();
354 scheduler->OnBeginImplFrameDeadline(); 360 client.task_runner().RunPendingTasks(); // Run posted deadline.
355 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 2); 361 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 2);
356 EXPECT_ACTION("SetNeedsBeginImplFrame", client, 1, 2); 362 EXPECT_ACTION("SetNeedsBeginFrame", client, 1, 2);
357 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); 363 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending());
358 EXPECT_TRUE(client.needs_begin_impl_frame()); 364 EXPECT_TRUE(client.needs_begin_impl_frame());
359 client.Reset(); 365 client.Reset();
360 366
361 // On the next BeginImplFrame, verify we go back to a quiescent state and 367 // On the next BeginImplFrame, verify we go back to a quiescent state and
362 // no longer request BeginImplFrames. 368 // no longer request BeginImplFrames.
363 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); 369 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting());
364 scheduler->OnBeginImplFrameDeadline(); 370 client.task_runner().RunPendingTasks(); // Run posted deadline.
365 EXPECT_FALSE(client.needs_begin_impl_frame()); 371 EXPECT_FALSE(client.needs_begin_impl_frame());
366 client.Reset(); 372 client.Reset();
367 } 373 }
368 374
369 TEST(SchedulerTest, TextureAcquisitionCausesCommitInsteadOfDraw) { 375 TEST(SchedulerTest, TextureAcquisitionCausesCommitInsteadOfDraw) {
370 FakeSchedulerClient client; 376 FakeSchedulerClient client;
371 SchedulerSettings scheduler_settings; 377 SchedulerSettings scheduler_settings;
372 Scheduler* scheduler = client.CreateScheduler(scheduler_settings); 378 Scheduler* scheduler = client.CreateScheduler(scheduler_settings);
373 scheduler->SetCanStart(); 379 scheduler->SetCanStart();
374 scheduler->SetVisible(true); 380 scheduler->SetVisible(true);
375 scheduler->SetCanDraw(true); 381 scheduler->SetCanDraw(true);
376 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); 382 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client);
377 383
378 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); 384 InitializeOutputSurfaceAndFirstCommit(scheduler, &client);
379 client.Reset(); 385 client.Reset();
380 scheduler->SetNeedsRedraw(); 386 scheduler->SetNeedsRedraw();
381 EXPECT_TRUE(scheduler->RedrawPending()); 387 EXPECT_TRUE(scheduler->RedrawPending());
382 EXPECT_SINGLE_ACTION("SetNeedsBeginImplFrame", client); 388 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client);
383 EXPECT_TRUE(client.needs_begin_impl_frame()); 389 EXPECT_TRUE(client.needs_begin_impl_frame());
384 390
385 client.Reset(); 391 client.Reset();
386 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); 392 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting());
387 EXPECT_EQ(client.num_actions_(), 0); 393 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client);
388 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 394 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending());
389 client.Reset(); 395 client.Reset();
390 scheduler->OnBeginImplFrameDeadline(); 396 client.task_runner().RunPendingTasks(); // Run posted deadline.
391 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 2); 397 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 2);
392 EXPECT_ACTION("SetNeedsBeginImplFrame", client, 1, 2); 398 EXPECT_ACTION("SetNeedsBeginFrame", client, 1, 2);
393 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); 399 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending());
394 EXPECT_FALSE(scheduler->RedrawPending()); 400 EXPECT_FALSE(scheduler->RedrawPending());
395 EXPECT_TRUE(client.needs_begin_impl_frame()); 401 EXPECT_TRUE(client.needs_begin_impl_frame());
396 402
397 client.Reset(); 403 client.Reset();
398 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); 404 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting());
399 EXPECT_EQ(client.num_actions_(), 0); 405 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client);
400 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 406 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending());
401 client.Reset(); 407 client.Reset();
402 scheduler->OnBeginImplFrameDeadline(); 408 client.task_runner().RunPendingTasks(); // Run posted deadline.
403 EXPECT_SINGLE_ACTION("SetNeedsBeginImplFrame", client); 409 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client);
404 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); 410 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending());
405 EXPECT_FALSE(scheduler->RedrawPending()); 411 EXPECT_FALSE(scheduler->RedrawPending());
406 EXPECT_FALSE(client.needs_begin_impl_frame()); 412 EXPECT_FALSE(client.needs_begin_impl_frame());
407 413
408 client.Reset(); 414 client.Reset();
409 scheduler->SetMainThreadNeedsLayerTextures(); 415 scheduler->SetMainThreadNeedsLayerTextures();
410 EXPECT_SINGLE_ACTION("ScheduledActionAcquireLayerTexturesForMainThread", 416 EXPECT_SINGLE_ACTION("ScheduledActionAcquireLayerTexturesForMainThread",
411 client); 417 client);
412 418
413 // We should request a BeginImplFrame in anticipation of a draw. 419 // We should request a BeginImplFrame in anticipation of a draw.
414 client.Reset(); 420 client.Reset();
415 scheduler->SetNeedsRedraw(); 421 scheduler->SetNeedsRedraw();
416 EXPECT_TRUE(scheduler->RedrawPending()); 422 EXPECT_TRUE(scheduler->RedrawPending());
417 EXPECT_SINGLE_ACTION("SetNeedsBeginImplFrame", client); 423 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client);
418 EXPECT_TRUE(client.needs_begin_impl_frame()); 424 EXPECT_TRUE(client.needs_begin_impl_frame());
419 425
420 // No draw happens since the textures are acquired by the main thread. 426 // No draw happens since the textures are acquired by the main thread.
421 client.Reset(); 427 client.Reset();
422 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); 428 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting());
423 EXPECT_EQ(client.num_actions_(), 0); 429 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client);
424 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 430 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending());
425 client.Reset(); 431 client.Reset();
426 scheduler->OnBeginImplFrameDeadline(); 432 client.task_runner().RunPendingTasks(); // Run posted deadline.
427 EXPECT_SINGLE_ACTION("SetNeedsBeginImplFrame", client); 433 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client);
428 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); 434 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending());
429 EXPECT_TRUE(scheduler->RedrawPending()); 435 EXPECT_TRUE(scheduler->RedrawPending());
430 EXPECT_TRUE(client.needs_begin_impl_frame()); 436 EXPECT_TRUE(client.needs_begin_impl_frame());
431 437
432 client.Reset(); 438 client.Reset();
433 scheduler->SetNeedsCommit(); 439 scheduler->SetNeedsCommit();
434 EXPECT_EQ(0, client.num_actions_()); 440 EXPECT_EQ(0, client.num_actions_());
435 441
436 client.Reset(); 442 client.Reset();
437 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); 443 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting());
438 EXPECT_SINGLE_ACTION("ScheduledActionSendBeginMainFrame", client); 444 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2);
445 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2);
439 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 446 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending());
440 447
441 // Commit will release the texture. 448 // Commit will release the texture.
442 client.Reset(); 449 client.Reset();
443 scheduler->NotifyBeginMainFrameStarted(); 450 scheduler->NotifyBeginMainFrameStarted();
444 scheduler->NotifyReadyToCommit(); 451 scheduler->NotifyReadyToCommit();
445 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); 452 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client);
446 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 453 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending());
447 EXPECT_TRUE(scheduler->RedrawPending()); 454 EXPECT_TRUE(scheduler->RedrawPending());
448 455
449 // Now we can draw again after the commit happens. 456 // Now we can draw again after the commit happens.
450 client.Reset(); 457 client.Reset();
451 scheduler->OnBeginImplFrameDeadline(); 458 client.task_runner().RunPendingTasks(); // Run posted deadline.
452 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 2); 459 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 2);
453 EXPECT_ACTION("SetNeedsBeginImplFrame", client, 1, 2); 460 EXPECT_ACTION("SetNeedsBeginFrame", client, 1, 2);
454 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); 461 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending());
455 EXPECT_FALSE(scheduler->RedrawPending()); 462 EXPECT_FALSE(scheduler->RedrawPending());
456 EXPECT_TRUE(client.needs_begin_impl_frame()); 463 EXPECT_TRUE(client.needs_begin_impl_frame());
457 464
458 // Make sure we stop requesting BeginImplFrames if we don't swap. 465 // Make sure we stop requesting BeginImplFrames if we don't swap.
459 client.Reset(); 466 client.Reset();
460 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); 467 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting());
461 EXPECT_EQ(client.num_actions_(), 0); 468 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client);
462 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 469 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending());
463 client.Reset(); 470 client.Reset();
464 scheduler->OnBeginImplFrameDeadline(); 471 client.task_runner().RunPendingTasks(); // Run posted deadline.
465 EXPECT_SINGLE_ACTION("SetNeedsBeginImplFrame", client); 472 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client);
466 EXPECT_FALSE(client.needs_begin_impl_frame()); 473 EXPECT_FALSE(client.needs_begin_impl_frame());
467 } 474 }
468 475
469 TEST(SchedulerTest, TextureAcquisitionCollision) { 476 TEST(SchedulerTest, TextureAcquisitionCollision) {
470 FakeSchedulerClient client; 477 FakeSchedulerClient client;
471 SchedulerSettings scheduler_settings; 478 SchedulerSettings scheduler_settings;
472 Scheduler* scheduler = client.CreateScheduler(scheduler_settings); 479 Scheduler* scheduler = client.CreateScheduler(scheduler_settings);
473 scheduler->SetCanStart(); 480 scheduler->SetCanStart();
474 scheduler->SetVisible(true); 481 scheduler->SetVisible(true);
475 scheduler->SetCanDraw(true); 482 scheduler->SetCanDraw(true);
476 483
477 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); 484 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client);
478 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); 485 InitializeOutputSurfaceAndFirstCommit(scheduler, &client);
479 486
480 client.Reset(); 487 client.Reset();
481 scheduler->SetNeedsCommit(); 488 scheduler->SetNeedsCommit();
482 EXPECT_SINGLE_ACTION("SetNeedsBeginImplFrame", client); 489 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client);
483 490
484 client.Reset(); 491 client.Reset();
485 scheduler->SetMainThreadNeedsLayerTextures(); 492 scheduler->SetMainThreadNeedsLayerTextures();
486 EXPECT_SINGLE_ACTION( 493 EXPECT_SINGLE_ACTION(
487 "ScheduledActionAcquireLayerTexturesForMainThread", client); 494 "ScheduledActionAcquireLayerTexturesForMainThread", client);
488 495
489 client.Reset(); 496 client.Reset();
490 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); 497 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting());
491 EXPECT_SINGLE_ACTION("ScheduledActionSendBeginMainFrame", client); 498 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2);
499 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2);
492 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 500 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending());
493 501
494 client.Reset(); 502 client.Reset();
495 scheduler->OnBeginImplFrameDeadline(); 503 client.task_runner().RunPendingTasks(); // Run posted deadline.
496 EXPECT_SINGLE_ACTION("SetNeedsBeginImplFrame", client); 504 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client);
497 505
498 // Although the compositor cannot draw because textures are locked by main 506 // Although the compositor cannot draw because textures are locked by main
499 // thread, we continue requesting SetNeedsBeginImplFrame in anticipation of 507 // thread, we continue requesting SetNeedsBeginFrame in anticipation of
500 // the unlock. 508 // the unlock.
501 EXPECT_TRUE(client.needs_begin_impl_frame()); 509 EXPECT_TRUE(client.needs_begin_impl_frame());
502 510
503 // Trigger the commit. 511 // Trigger the commit.
504 scheduler->NotifyBeginMainFrameStarted(); 512 scheduler->NotifyBeginMainFrameStarted();
505 scheduler->NotifyReadyToCommit(); 513 scheduler->NotifyReadyToCommit();
506 EXPECT_TRUE(client.needs_begin_impl_frame()); 514 EXPECT_TRUE(client.needs_begin_impl_frame());
507 515
508 // Between commit and draw, texture acquisition for main thread delayed, 516 // Between commit and draw, texture acquisition for main thread delayed,
509 // and main thread blocks. 517 // and main thread blocks.
510 client.Reset(); 518 client.Reset();
511 scheduler->SetMainThreadNeedsLayerTextures(); 519 scheduler->SetMainThreadNeedsLayerTextures();
512 EXPECT_EQ(0, client.num_actions_()); 520 EXPECT_EQ(0, client.num_actions_());
513 521
514 // No implicit commit is expected. 522 // No implicit commit is expected.
515 client.Reset(); 523 client.Reset();
516 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); 524 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting());
517 EXPECT_EQ(client.num_actions_(), 0); 525 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client);
518 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 526 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending());
519 527
520 client.Reset(); 528 client.Reset();
521 scheduler->OnBeginImplFrameDeadline(); 529 client.task_runner().RunPendingTasks(); // Run posted deadline.
522 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 3); 530 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 3);
523 EXPECT_ACTION( 531 EXPECT_ACTION(
524 "ScheduledActionAcquireLayerTexturesForMainThread", client, 1, 3); 532 "ScheduledActionAcquireLayerTexturesForMainThread", client, 1, 3);
525 EXPECT_ACTION("SetNeedsBeginImplFrame", client, 2, 3); 533 EXPECT_ACTION("SetNeedsBeginFrame", client, 2, 3);
526 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); 534 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending());
527 EXPECT_TRUE(client.needs_begin_impl_frame()); 535 EXPECT_TRUE(client.needs_begin_impl_frame());
528 536
529 // The compositor should not draw because textures are locked by main 537 // The compositor should not draw because textures are locked by main
530 // thread. 538 // thread.
531 client.Reset(); 539 client.Reset();
532 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); 540 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting());
533 EXPECT_EQ(client.num_actions_(), 0); 541 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client);
534 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 542 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending());
535 client.Reset(); 543 client.Reset();
536 scheduler->OnBeginImplFrameDeadline(); 544 client.task_runner().RunPendingTasks(); // Run posted deadline.
537 EXPECT_SINGLE_ACTION("SetNeedsBeginImplFrame", client); 545 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client);
538 EXPECT_FALSE(client.needs_begin_impl_frame()); 546 EXPECT_FALSE(client.needs_begin_impl_frame());
539 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); 547 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending());
540 548
541 // The impl thread need an explicit commit from the main thread to lock 549 // The impl thread need an explicit commit from the main thread to lock
542 // the textures. 550 // the textures.
543 client.Reset(); 551 client.Reset();
544 scheduler->SetNeedsCommit(); 552 scheduler->SetNeedsCommit();
545 EXPECT_SINGLE_ACTION("SetNeedsBeginImplFrame", client); 553 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client);
546 EXPECT_TRUE(client.needs_begin_impl_frame()); 554 EXPECT_TRUE(client.needs_begin_impl_frame());
547 555
548 client.Reset(); 556 client.Reset();
549 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); 557 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting());
550 EXPECT_SINGLE_ACTION("ScheduledActionSendBeginMainFrame", client); 558 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2);
559 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2);
551 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 560 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending());
552 client.Reset(); 561 client.Reset();
553 562
554 // Trigger the commit, which will trigger the deadline task early. 563 // Trigger the commit, which will trigger the deadline task early.
555 scheduler->NotifyBeginMainFrameStarted(); 564 scheduler->NotifyBeginMainFrameStarted();
556 scheduler->NotifyReadyToCommit(); 565 scheduler->NotifyReadyToCommit();
557 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); 566 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client);
558 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 567 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending());
559 EXPECT_TRUE(client.needs_begin_impl_frame()); 568 EXPECT_TRUE(client.needs_begin_impl_frame());
560 client.Reset(); 569 client.Reset();
561 570
562 // Verify we draw on the next BeginImplFrame deadline 571 // Verify we draw on the next BeginImplFrame deadline
563 scheduler->OnBeginImplFrameDeadline(); 572 client.task_runner().RunPendingTasks(); // Run posted deadline.
564 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 2); 573 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 2);
565 EXPECT_ACTION("SetNeedsBeginImplFrame", client, 1, 2); 574 EXPECT_ACTION("SetNeedsBeginFrame", client, 1, 2);
566 EXPECT_TRUE(client.needs_begin_impl_frame()); 575 EXPECT_TRUE(client.needs_begin_impl_frame());
567 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); 576 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending());
568 client.Reset(); 577 client.Reset();
569 } 578 }
570 579
571 TEST(SchedulerTest, VisibilitySwitchWithTextureAcquisition) { 580 TEST(SchedulerTest, VisibilitySwitchWithTextureAcquisition) {
572 FakeSchedulerClient client; 581 FakeSchedulerClient client;
573 SchedulerSettings scheduler_settings; 582 SchedulerSettings scheduler_settings;
574 Scheduler* scheduler = client.CreateScheduler(scheduler_settings); 583 Scheduler* scheduler = client.CreateScheduler(scheduler_settings);
575 scheduler->SetCanStart(); 584 scheduler->SetCanStart();
576 scheduler->SetVisible(true); 585 scheduler->SetVisible(true);
577 scheduler->SetCanDraw(true); 586 scheduler->SetCanDraw(true);
578 587
579 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); 588 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client);
580 client.Reset(); 589 client.Reset();
581 scheduler->DidCreateAndInitializeOutputSurface(); 590 scheduler->DidCreateAndInitializeOutputSurface();
582 591
583 scheduler->SetNeedsCommit(); 592 scheduler->SetNeedsCommit();
584 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); 593 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting());
585 scheduler->OnBeginImplFrameDeadline(); 594 client.task_runner().RunPendingTasks(); // Run posted deadline.
586 scheduler->NotifyBeginMainFrameStarted(); 595 scheduler->NotifyBeginMainFrameStarted();
587 scheduler->NotifyReadyToCommit(); 596 scheduler->NotifyReadyToCommit();
588 scheduler->SetMainThreadNeedsLayerTextures(); 597 scheduler->SetMainThreadNeedsLayerTextures();
589 scheduler->SetNeedsCommit(); 598 scheduler->SetNeedsCommit();
590 client.Reset(); 599 client.Reset();
591 // Verify that pending texture acquisition fires when visibility 600 // Verify that pending texture acquisition fires when visibility
592 // is lost in order to avoid a deadlock. 601 // is lost in order to avoid a deadlock.
593 scheduler->SetVisible(false); 602 scheduler->SetVisible(false);
594 EXPECT_SINGLE_ACTION("ScheduledActionAcquireLayerTexturesForMainThread", 603 EXPECT_SINGLE_ACTION("ScheduledActionAcquireLayerTexturesForMainThread",
595 client); 604 client);
596 605
597 client.Reset(); 606 client.Reset();
598 scheduler->SetVisible(true); 607 scheduler->SetVisible(true);
599 EXPECT_EQ(0, client.num_actions_()); 608 EXPECT_EQ(0, client.num_actions_());
600 EXPECT_TRUE(client.needs_begin_impl_frame()); 609 EXPECT_TRUE(client.needs_begin_impl_frame());
601 610
602 // Regaining visibility with textures acquired by main thread while 611 // Regaining visibility with textures acquired by main thread while
603 // compositor is waiting for first draw should result in a request 612 // compositor is waiting for first draw should result in a request
604 // for a new frame in order to escape a deadlock. 613 // for a new frame in order to escape a deadlock.
605 client.Reset(); 614 client.Reset();
606 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); 615 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting());
607 EXPECT_SINGLE_ACTION("ScheduledActionSendBeginMainFrame", client); 616 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2);
617 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2);
608 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 618 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending());
609 } 619 }
610 620
611 class SchedulerClientThatsetNeedsDrawInsideDraw : public FakeSchedulerClient { 621 class SchedulerClientThatsetNeedsDrawInsideDraw : public FakeSchedulerClient {
612 public: 622 public:
613 virtual void ScheduledActionSendBeginMainFrame() OVERRIDE {} 623 virtual void ScheduledActionSendBeginMainFrame() OVERRIDE {}
614 virtual DrawSwapReadbackResult ScheduledActionDrawAndSwapIfPossible() 624 virtual DrawSwapReadbackResult ScheduledActionDrawAndSwapIfPossible()
615 OVERRIDE { 625 OVERRIDE {
616 // Only SetNeedsRedraw the first time this is called 626 // Only SetNeedsRedraw the first time this is called
617 if (!num_draws_) 627 if (!num_draws_)
(...skipping 26 matching lines...) Expand all
644 scheduler->SetVisible(true); 654 scheduler->SetVisible(true);
645 scheduler->SetCanDraw(true); 655 scheduler->SetCanDraw(true);
646 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); 656 InitializeOutputSurfaceAndFirstCommit(scheduler, &client);
647 client.Reset(); 657 client.Reset();
648 658
649 scheduler->SetNeedsRedraw(); 659 scheduler->SetNeedsRedraw();
650 EXPECT_TRUE(scheduler->RedrawPending()); 660 EXPECT_TRUE(scheduler->RedrawPending());
651 EXPECT_TRUE(client.needs_begin_impl_frame()); 661 EXPECT_TRUE(client.needs_begin_impl_frame());
652 EXPECT_EQ(0, client.num_draws()); 662 EXPECT_EQ(0, client.num_draws());
653 663
654 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); 664 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting());
655 scheduler->OnBeginImplFrameDeadline(); 665 client.task_runner().RunPendingTasks(); // Run posted deadline.
656 EXPECT_EQ(1, client.num_draws()); 666 EXPECT_EQ(1, client.num_draws());
657 EXPECT_TRUE(scheduler->RedrawPending()); 667 EXPECT_TRUE(scheduler->RedrawPending());
658 EXPECT_TRUE(client.needs_begin_impl_frame()); 668 EXPECT_TRUE(client.needs_begin_impl_frame());
659 669
660 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); 670 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting());
661 scheduler->OnBeginImplFrameDeadline(); 671 client.task_runner().RunPendingTasks(); // Run posted deadline.
662 EXPECT_EQ(2, client.num_draws()); 672 EXPECT_EQ(2, client.num_draws());
663 EXPECT_FALSE(scheduler->RedrawPending()); 673 EXPECT_FALSE(scheduler->RedrawPending());
664 EXPECT_TRUE(client.needs_begin_impl_frame()); 674 EXPECT_TRUE(client.needs_begin_impl_frame());
665 675
666 // We stop requesting BeginImplFrames after a BeginImplFrame where we don't 676 // We stop requesting BeginImplFrames after a BeginImplFrame where we don't
667 // swap. 677 // swap.
668 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); 678 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting());
669 scheduler->OnBeginImplFrameDeadline(); 679 client.task_runner().RunPendingTasks(); // Run posted deadline.
670 EXPECT_EQ(2, client.num_draws()); 680 EXPECT_EQ(2, client.num_draws());
671 EXPECT_FALSE(scheduler->RedrawPending()); 681 EXPECT_FALSE(scheduler->RedrawPending());
672 EXPECT_FALSE(client.needs_begin_impl_frame()); 682 EXPECT_FALSE(client.needs_begin_impl_frame());
673 } 683 }
674 684
675 // Test that requesting redraw inside a failed draw doesn't lose the request. 685 // Test that requesting redraw inside a failed draw doesn't lose the request.
676 TEST(SchedulerTest, RequestRedrawInsideFailedDraw) { 686 TEST(SchedulerTest, RequestRedrawInsideFailedDraw) {
677 SchedulerClientThatsetNeedsDrawInsideDraw client; 687 SchedulerClientThatsetNeedsDrawInsideDraw client;
678 SchedulerSettings default_scheduler_settings; 688 SchedulerSettings default_scheduler_settings;
679 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings); 689 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings);
680 scheduler->SetCanStart(); 690 scheduler->SetCanStart();
681 scheduler->SetVisible(true); 691 scheduler->SetVisible(true);
682 scheduler->SetCanDraw(true); 692 scheduler->SetCanDraw(true);
683 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); 693 InitializeOutputSurfaceAndFirstCommit(scheduler, &client);
684 client.Reset(); 694 client.Reset();
685 695
686 client.SetDrawWillHappen(false); 696 client.SetDrawWillHappen(false);
687 697
688 scheduler->SetNeedsRedraw(); 698 scheduler->SetNeedsRedraw();
689 EXPECT_TRUE(scheduler->RedrawPending()); 699 EXPECT_TRUE(scheduler->RedrawPending());
690 EXPECT_TRUE(client.needs_begin_impl_frame()); 700 EXPECT_TRUE(client.needs_begin_impl_frame());
691 EXPECT_EQ(0, client.num_draws()); 701 EXPECT_EQ(0, client.num_draws());
692 702
693 // Fail the draw. 703 // Fail the draw.
694 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); 704 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting());
695 scheduler->OnBeginImplFrameDeadline(); 705 client.task_runner().RunPendingTasks(); // Run posted deadline.
696 EXPECT_EQ(1, client.num_draws()); 706 EXPECT_EQ(1, client.num_draws());
697 707
698 // We have a commit pending and the draw failed, and we didn't lose the redraw 708 // We have a commit pending and the draw failed, and we didn't lose the redraw
699 // request. 709 // request.
700 EXPECT_TRUE(scheduler->CommitPending()); 710 EXPECT_TRUE(scheduler->CommitPending());
701 EXPECT_TRUE(scheduler->RedrawPending()); 711 EXPECT_TRUE(scheduler->RedrawPending());
702 EXPECT_TRUE(client.needs_begin_impl_frame()); 712 EXPECT_TRUE(client.needs_begin_impl_frame());
703 713
704 // Fail the draw again. 714 // Fail the draw again.
705 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); 715 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting());
706 scheduler->OnBeginImplFrameDeadline(); 716 client.task_runner().RunPendingTasks(); // Run posted deadline.
707 EXPECT_EQ(2, client.num_draws()); 717 EXPECT_EQ(2, client.num_draws());
708 EXPECT_TRUE(scheduler->CommitPending()); 718 EXPECT_TRUE(scheduler->CommitPending());
709 EXPECT_TRUE(scheduler->RedrawPending()); 719 EXPECT_TRUE(scheduler->RedrawPending());
710 EXPECT_TRUE(client.needs_begin_impl_frame()); 720 EXPECT_TRUE(client.needs_begin_impl_frame());
711 721
712 // Draw successfully. 722 // Draw successfully.
713 client.SetDrawWillHappen(true); 723 client.SetDrawWillHappen(true);
714 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); 724 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting());
715 scheduler->OnBeginImplFrameDeadline(); 725 client.task_runner().RunPendingTasks(); // Run posted deadline.
716 EXPECT_EQ(3, client.num_draws()); 726 EXPECT_EQ(3, client.num_draws());
717 EXPECT_TRUE(scheduler->CommitPending()); 727 EXPECT_TRUE(scheduler->CommitPending());
718 EXPECT_FALSE(scheduler->RedrawPending()); 728 EXPECT_FALSE(scheduler->RedrawPending());
719 EXPECT_TRUE(client.needs_begin_impl_frame()); 729 EXPECT_TRUE(client.needs_begin_impl_frame());
720 } 730 }
721 731
722 class SchedulerClientThatSetNeedsCommitInsideDraw : public FakeSchedulerClient { 732 class SchedulerClientThatSetNeedsCommitInsideDraw : public FakeSchedulerClient {
723 public: 733 public:
724 SchedulerClientThatSetNeedsCommitInsideDraw() 734 SchedulerClientThatSetNeedsCommitInsideDraw()
725 : set_needs_commit_on_next_draw_(false) {} 735 : set_needs_commit_on_next_draw_(false) {}
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
765 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); 775 InitializeOutputSurfaceAndFirstCommit(scheduler, &client);
766 client.Reset(); 776 client.Reset();
767 777
768 EXPECT_FALSE(client.needs_begin_impl_frame()); 778 EXPECT_FALSE(client.needs_begin_impl_frame());
769 scheduler->SetNeedsRedraw(); 779 scheduler->SetNeedsRedraw();
770 EXPECT_TRUE(scheduler->RedrawPending()); 780 EXPECT_TRUE(scheduler->RedrawPending());
771 EXPECT_EQ(0, client.num_draws()); 781 EXPECT_EQ(0, client.num_draws());
772 EXPECT_TRUE(client.needs_begin_impl_frame()); 782 EXPECT_TRUE(client.needs_begin_impl_frame());
773 783
774 client.SetNeedsCommitOnNextDraw(); 784 client.SetNeedsCommitOnNextDraw();
775 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); 785 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting());
776 client.SetNeedsCommitOnNextDraw(); 786 client.SetNeedsCommitOnNextDraw();
777 scheduler->OnBeginImplFrameDeadline(); 787 client.task_runner().RunPendingTasks(); // Run posted deadline.
778 EXPECT_EQ(1, client.num_draws()); 788 EXPECT_EQ(1, client.num_draws());
779 EXPECT_TRUE(scheduler->CommitPending()); 789 EXPECT_TRUE(scheduler->CommitPending());
780 EXPECT_TRUE(client.needs_begin_impl_frame()); 790 EXPECT_TRUE(client.needs_begin_impl_frame());
781 scheduler->NotifyBeginMainFrameStarted(); 791 scheduler->NotifyBeginMainFrameStarted();
782 scheduler->NotifyReadyToCommit(); 792 scheduler->NotifyReadyToCommit();
783 793
784 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); 794 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting());
785 scheduler->OnBeginImplFrameDeadline(); 795 client.task_runner().RunPendingTasks(); // Run posted deadline.
786 EXPECT_EQ(2, client.num_draws()); 796 EXPECT_EQ(2, client.num_draws());
787 797
788 EXPECT_FALSE(scheduler->RedrawPending()); 798 EXPECT_FALSE(scheduler->RedrawPending());
789 EXPECT_FALSE(scheduler->CommitPending()); 799 EXPECT_FALSE(scheduler->CommitPending());
790 EXPECT_TRUE(client.needs_begin_impl_frame()); 800 EXPECT_TRUE(client.needs_begin_impl_frame());
791 801
792 // We stop requesting BeginImplFrames after a BeginImplFrame where we don't 802 // We stop requesting BeginImplFrames after a BeginImplFrame where we don't
793 // swap. 803 // swap.
794 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); 804 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting());
795 scheduler->OnBeginImplFrameDeadline(); 805 client.task_runner().RunPendingTasks(); // Run posted deadline.
796 EXPECT_EQ(2, client.num_draws()); 806 EXPECT_EQ(2, client.num_draws());
797 EXPECT_FALSE(scheduler->RedrawPending()); 807 EXPECT_FALSE(scheduler->RedrawPending());
798 EXPECT_FALSE(scheduler->CommitPending()); 808 EXPECT_FALSE(scheduler->CommitPending());
799 EXPECT_FALSE(client.needs_begin_impl_frame()); 809 EXPECT_FALSE(client.needs_begin_impl_frame());
800 } 810 }
801 811
802 // Tests that when a draw fails then the pending commit should not be dropped. 812 // Tests that when a draw fails then the pending commit should not be dropped.
803 TEST(SchedulerTest, RequestCommitInsideFailedDraw) { 813 TEST(SchedulerTest, RequestCommitInsideFailedDraw) {
804 SchedulerClientThatsetNeedsDrawInsideDraw client; 814 SchedulerClientThatsetNeedsDrawInsideDraw client;
805 SchedulerSettings default_scheduler_settings; 815 SchedulerSettings default_scheduler_settings;
806 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings); 816 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings);
807 scheduler->SetCanStart(); 817 scheduler->SetCanStart();
808 scheduler->SetVisible(true); 818 scheduler->SetVisible(true);
809 scheduler->SetCanDraw(true); 819 scheduler->SetCanDraw(true);
810 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); 820 InitializeOutputSurfaceAndFirstCommit(scheduler, &client);
811 client.Reset(); 821 client.Reset();
812 822
813 client.SetDrawWillHappen(false); 823 client.SetDrawWillHappen(false);
814 824
815 scheduler->SetNeedsRedraw(); 825 scheduler->SetNeedsRedraw();
816 EXPECT_TRUE(scheduler->RedrawPending()); 826 EXPECT_TRUE(scheduler->RedrawPending());
817 EXPECT_TRUE(client.needs_begin_impl_frame()); 827 EXPECT_TRUE(client.needs_begin_impl_frame());
818 EXPECT_EQ(0, client.num_draws()); 828 EXPECT_EQ(0, client.num_draws());
819 829
820 // Fail the draw. 830 // Fail the draw.
821 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); 831 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting());
822 scheduler->OnBeginImplFrameDeadline(); 832 client.task_runner().RunPendingTasks(); // Run posted deadline.
823 EXPECT_EQ(1, client.num_draws()); 833 EXPECT_EQ(1, client.num_draws());
824 834
825 // We have a commit pending and the draw failed, and we didn't lose the commit 835 // We have a commit pending and the draw failed, and we didn't lose the commit
826 // request. 836 // request.
827 EXPECT_TRUE(scheduler->CommitPending()); 837 EXPECT_TRUE(scheduler->CommitPending());
828 EXPECT_TRUE(scheduler->RedrawPending()); 838 EXPECT_TRUE(scheduler->RedrawPending());
829 EXPECT_TRUE(client.needs_begin_impl_frame()); 839 EXPECT_TRUE(client.needs_begin_impl_frame());
830 840
831 // Fail the draw again. 841 // Fail the draw again.
832 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); 842 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting());
833 scheduler->OnBeginImplFrameDeadline(); 843
844 client.task_runner().RunPendingTasks(); // Run posted deadline.
834 EXPECT_EQ(2, client.num_draws()); 845 EXPECT_EQ(2, client.num_draws());
835 EXPECT_TRUE(scheduler->CommitPending()); 846 EXPECT_TRUE(scheduler->CommitPending());
836 EXPECT_TRUE(scheduler->RedrawPending()); 847 EXPECT_TRUE(scheduler->RedrawPending());
837 EXPECT_TRUE(client.needs_begin_impl_frame()); 848 EXPECT_TRUE(client.needs_begin_impl_frame());
838 849
839 // Draw successfully. 850 // Draw successfully.
840 client.SetDrawWillHappen(true); 851 client.SetDrawWillHappen(true);
841 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); 852 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting());
842 scheduler->OnBeginImplFrameDeadline(); 853 client.task_runner().RunPendingTasks(); // Run posted deadline.
843 EXPECT_EQ(3, client.num_draws()); 854 EXPECT_EQ(3, client.num_draws());
844 EXPECT_TRUE(scheduler->CommitPending()); 855 EXPECT_TRUE(scheduler->CommitPending());
845 EXPECT_FALSE(scheduler->RedrawPending()); 856 EXPECT_FALSE(scheduler->RedrawPending());
846 EXPECT_TRUE(client.needs_begin_impl_frame()); 857 EXPECT_TRUE(client.needs_begin_impl_frame());
847 } 858 }
848 859
849 TEST(SchedulerTest, NoSwapWhenDrawFails) { 860 TEST(SchedulerTest, NoSwapWhenDrawFails) {
850 SchedulerClientThatSetNeedsCommitInsideDraw client; 861 SchedulerClientThatSetNeedsCommitInsideDraw client;
851 SchedulerSettings default_scheduler_settings; 862 SchedulerSettings default_scheduler_settings;
852 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings); 863 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings);
853 scheduler->SetCanStart(); 864 scheduler->SetCanStart();
854 scheduler->SetVisible(true); 865 scheduler->SetVisible(true);
855 scheduler->SetCanDraw(true); 866 scheduler->SetCanDraw(true);
856 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); 867 InitializeOutputSurfaceAndFirstCommit(scheduler, &client);
857 client.Reset(); 868 client.Reset();
858 869
859 scheduler->SetNeedsRedraw(); 870 scheduler->SetNeedsRedraw();
860 EXPECT_TRUE(scheduler->RedrawPending()); 871 EXPECT_TRUE(scheduler->RedrawPending());
861 EXPECT_TRUE(client.needs_begin_impl_frame()); 872 EXPECT_TRUE(client.needs_begin_impl_frame());
862 EXPECT_EQ(0, client.num_draws()); 873 EXPECT_EQ(0, client.num_draws());
863 874
864 // Draw successfully, this starts a new frame. 875 // Draw successfully, this starts a new frame.
865 client.SetNeedsCommitOnNextDraw(); 876 client.SetNeedsCommitOnNextDraw();
866 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); 877 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting());
867 scheduler->OnBeginImplFrameDeadline(); 878 client.task_runner().RunPendingTasks(); // Run posted deadline.
868 EXPECT_EQ(1, client.num_draws()); 879 EXPECT_EQ(1, client.num_draws());
869 880
870 scheduler->SetNeedsRedraw(); 881 scheduler->SetNeedsRedraw();
871 EXPECT_TRUE(scheduler->RedrawPending()); 882 EXPECT_TRUE(scheduler->RedrawPending());
872 EXPECT_TRUE(client.needs_begin_impl_frame()); 883 EXPECT_TRUE(client.needs_begin_impl_frame());
873 884
874 // Fail to draw, this should not start a frame. 885 // Fail to draw, this should not start a frame.
875 client.SetDrawWillHappen(false); 886 client.SetDrawWillHappen(false);
876 client.SetNeedsCommitOnNextDraw(); 887 client.SetNeedsCommitOnNextDraw();
877 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); 888 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting());
878 scheduler->OnBeginImplFrameDeadline(); 889 client.task_runner().RunPendingTasks(); // Run posted deadline.
879 EXPECT_EQ(2, client.num_draws()); 890 EXPECT_EQ(2, client.num_draws());
880 } 891 }
881 892
882 TEST(SchedulerTest, NoSwapWhenSwapFailsDuringForcedCommit) { 893 TEST(SchedulerTest, NoSwapWhenSwapFailsDuringForcedCommit) {
883 FakeSchedulerClient client; 894 FakeSchedulerClient client;
884 SchedulerSettings default_scheduler_settings; 895 SchedulerSettings default_scheduler_settings;
885 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings); 896 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings);
886 897
887 // Tell the client that it will fail to swap. 898 // Tell the client that it will fail to swap.
888 client.SetDrawWillHappen(true); 899 client.SetDrawWillHappen(true);
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
953 EXPECT_TRUE(scheduler->RedrawPending()); 964 EXPECT_TRUE(scheduler->RedrawPending());
954 EXPECT_TRUE(scheduler->ManageTilesPending()); 965 EXPECT_TRUE(scheduler->ManageTilesPending());
955 EXPECT_TRUE(client.needs_begin_impl_frame()); 966 EXPECT_TRUE(client.needs_begin_impl_frame());
956 EXPECT_EQ(0, client.num_draws()); 967 EXPECT_EQ(0, client.num_draws());
957 EXPECT_FALSE(client.HasAction("ScheduledActionManageTiles")); 968 EXPECT_FALSE(client.HasAction("ScheduledActionManageTiles"));
958 EXPECT_FALSE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); 969 EXPECT_FALSE(client.HasAction("ScheduledActionDrawAndSwapIfPossible"));
959 970
960 // We have no immediate actions to perform, so the BeginImplFrame should post 971 // We have no immediate actions to perform, so the BeginImplFrame should post
961 // the deadline task. 972 // the deadline task.
962 client.Reset(); 973 client.Reset();
963 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); 974 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting());
964 EXPECT_EQ(client.num_actions_(), 0); 975 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client);
965 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 976 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending());
966 977
967 // On the deadline, he actions should have occured in the right order. 978 // On the deadline, he actions should have occured in the right order.
968 client.Reset(); 979 client.Reset();
969 scheduler->OnBeginImplFrameDeadline(); 980 client.task_runner().RunPendingTasks(); // Run posted deadline.
970 EXPECT_EQ(1, client.num_draws()); 981 EXPECT_EQ(1, client.num_draws());
971 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); 982 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible"));
972 EXPECT_TRUE(client.HasAction("ScheduledActionManageTiles")); 983 EXPECT_TRUE(client.HasAction("ScheduledActionManageTiles"));
973 EXPECT_LT(client.ActionIndex("ScheduledActionDrawAndSwapIfPossible"), 984 EXPECT_LT(client.ActionIndex("ScheduledActionDrawAndSwapIfPossible"),
974 client.ActionIndex("ScheduledActionManageTiles")); 985 client.ActionIndex("ScheduledActionManageTiles"));
975 EXPECT_FALSE(scheduler->RedrawPending()); 986 EXPECT_FALSE(scheduler->RedrawPending());
976 EXPECT_FALSE(scheduler->ManageTilesPending()); 987 EXPECT_FALSE(scheduler->ManageTilesPending());
977 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); 988 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending());
978 989
979 // Request a draw. We don't need a ManageTiles yet. 990 // Request a draw. We don't need a ManageTiles yet.
980 client.Reset(); 991 client.Reset();
981 scheduler->SetNeedsRedraw(); 992 scheduler->SetNeedsRedraw();
982 EXPECT_TRUE(scheduler->RedrawPending()); 993 EXPECT_TRUE(scheduler->RedrawPending());
983 EXPECT_FALSE(scheduler->ManageTilesPending()); 994 EXPECT_FALSE(scheduler->ManageTilesPending());
984 EXPECT_TRUE(client.needs_begin_impl_frame()); 995 EXPECT_TRUE(client.needs_begin_impl_frame());
985 EXPECT_EQ(0, client.num_draws()); 996 EXPECT_EQ(0, client.num_draws());
986 997
987 // We have no immediate actions to perform, so the BeginImplFrame should post 998 // We have no immediate actions to perform, so the BeginImplFrame should post
988 // the deadline task. 999 // the deadline task.
989 client.Reset(); 1000 client.Reset();
990 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); 1001 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting());
991 EXPECT_EQ(client.num_actions_(), 0); 1002 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client);
992 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 1003 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending());
993 1004
994 // Draw. The draw will trigger SetNeedsManageTiles, and 1005 // Draw. The draw will trigger SetNeedsManageTiles, and
995 // then the ManageTiles action will be triggered after the Draw. 1006 // then the ManageTiles action will be triggered after the Draw.
996 // Afterwards, neither a draw nor ManageTiles are pending. 1007 // Afterwards, neither a draw nor ManageTiles are pending.
997 client.Reset(); 1008 client.Reset();
998 scheduler->OnBeginImplFrameDeadline(); 1009 client.task_runner().RunPendingTasks(); // Run posted deadline.
999 EXPECT_EQ(1, client.num_draws()); 1010 EXPECT_EQ(1, client.num_draws());
1000 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); 1011 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible"));
1001 EXPECT_TRUE(client.HasAction("ScheduledActionManageTiles")); 1012 EXPECT_TRUE(client.HasAction("ScheduledActionManageTiles"));
1002 EXPECT_LT(client.ActionIndex("ScheduledActionDrawAndSwapIfPossible"), 1013 EXPECT_LT(client.ActionIndex("ScheduledActionDrawAndSwapIfPossible"),
1003 client.ActionIndex("ScheduledActionManageTiles")); 1014 client.ActionIndex("ScheduledActionManageTiles"));
1004 EXPECT_FALSE(scheduler->RedrawPending()); 1015 EXPECT_FALSE(scheduler->RedrawPending());
1005 EXPECT_FALSE(scheduler->ManageTilesPending()); 1016 EXPECT_FALSE(scheduler->ManageTilesPending());
1006 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); 1017 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending());
1007 1018
1008 // We need a BeginImplFrame where we don't swap to go idle. 1019 // We need a BeginImplFrame where we don't swap to go idle.
1009 client.Reset(); 1020 client.Reset();
1010 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); 1021 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting());
1011 EXPECT_EQ(client.num_actions_(), 0); 1022 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client);
1012 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 1023 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending());
1013 client.Reset(); 1024 client.Reset();
1014 scheduler->OnBeginImplFrameDeadline(); 1025 client.task_runner().RunPendingTasks(); // Run posted deadline.
1015 EXPECT_SINGLE_ACTION("SetNeedsBeginImplFrame", client); 1026 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client);
1016 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); 1027 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending());
1017 EXPECT_EQ(0, client.num_draws()); 1028 EXPECT_EQ(0, client.num_draws());
1018 1029
1019 // Now trigger a ManageTiles outside of a draw. We will then need 1030 // Now trigger a ManageTiles outside of a draw. We will then need
1020 // a begin-frame for the ManageTiles, but we don't need a draw. 1031 // a begin-frame for the ManageTiles, but we don't need a draw.
1021 client.Reset(); 1032 client.Reset();
1022 EXPECT_FALSE(client.needs_begin_impl_frame()); 1033 EXPECT_FALSE(client.needs_begin_impl_frame());
1023 scheduler->SetNeedsManageTiles(); 1034 scheduler->SetNeedsManageTiles();
1024 EXPECT_TRUE(client.needs_begin_impl_frame()); 1035 EXPECT_TRUE(client.needs_begin_impl_frame());
1025 EXPECT_TRUE(scheduler->ManageTilesPending()); 1036 EXPECT_TRUE(scheduler->ManageTilesPending());
1026 EXPECT_FALSE(scheduler->RedrawPending()); 1037 EXPECT_FALSE(scheduler->RedrawPending());
1027 1038
1028 // BeginImplFrame. There will be no draw, only ManageTiles. 1039 // BeginImplFrame. There will be no draw, only ManageTiles.
1029 client.Reset(); 1040 client.Reset();
1030 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); 1041 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting());
1031 EXPECT_EQ(client.num_actions_(), 0); 1042 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client);
1032 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 1043 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending());
1033 client.Reset(); 1044 client.Reset();
1034 scheduler->OnBeginImplFrameDeadline(); 1045 client.task_runner().RunPendingTasks(); // Run posted deadline.
1035 EXPECT_EQ(0, client.num_draws()); 1046 EXPECT_EQ(0, client.num_draws());
1036 EXPECT_FALSE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); 1047 EXPECT_FALSE(client.HasAction("ScheduledActionDrawAndSwapIfPossible"));
1037 EXPECT_TRUE(client.HasAction("ScheduledActionManageTiles")); 1048 EXPECT_TRUE(client.HasAction("ScheduledActionManageTiles"));
1038 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); 1049 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending());
1039 } 1050 }
1040 1051
1041 // Test that ManageTiles only happens once per frame. If an external caller 1052 // Test that ManageTiles only happens once per frame. If an external caller
1042 // initiates it, then the state machine should not ManageTiles on that frame. 1053 // initiates it, then the state machine should not ManageTiles on that frame.
1043 TEST(SchedulerTest, ManageTilesOncePerFrame) { 1054 TEST(SchedulerTest, ManageTilesOncePerFrame) {
1044 FakeSchedulerClient client; 1055 FakeSchedulerClient client;
1045 SchedulerSettings default_scheduler_settings; 1056 SchedulerSettings default_scheduler_settings;
1046 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings); 1057 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings);
1047 scheduler->SetCanStart(); 1058 scheduler->SetCanStart();
1048 scheduler->SetVisible(true); 1059 scheduler->SetVisible(true);
1049 scheduler->SetCanDraw(true); 1060 scheduler->SetCanDraw(true);
1050 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); 1061 InitializeOutputSurfaceAndFirstCommit(scheduler, &client);
1051 1062
1052 // If DidManageTiles during a frame, then ManageTiles should not occur again. 1063 // If DidManageTiles during a frame, then ManageTiles should not occur again.
1053 scheduler->SetNeedsManageTiles(); 1064 scheduler->SetNeedsManageTiles();
1054 scheduler->SetNeedsRedraw(); 1065 scheduler->SetNeedsRedraw();
1055 client.Reset(); 1066 client.Reset();
1056 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); 1067 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting());
1057 EXPECT_EQ(client.num_actions_(), 0); 1068 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client);
1058 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 1069 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending());
1059 1070
1060 EXPECT_TRUE(scheduler->ManageTilesPending()); 1071 EXPECT_TRUE(scheduler->ManageTilesPending());
1061 scheduler->DidManageTiles(); // An explicit ManageTiles. 1072 scheduler->DidManageTiles(); // An explicit ManageTiles.
1062 EXPECT_FALSE(scheduler->ManageTilesPending()); 1073 EXPECT_FALSE(scheduler->ManageTilesPending());
1063 1074
1064 client.Reset(); 1075 client.Reset();
1065 scheduler->OnBeginImplFrameDeadline(); 1076 client.task_runner().RunPendingTasks(); // Run posted deadline.
1066 EXPECT_EQ(1, client.num_draws()); 1077 EXPECT_EQ(1, client.num_draws());
1067 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); 1078 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible"));
1068 EXPECT_FALSE(client.HasAction("ScheduledActionManageTiles")); 1079 EXPECT_FALSE(client.HasAction("ScheduledActionManageTiles"));
1069 EXPECT_FALSE(scheduler->RedrawPending()); 1080 EXPECT_FALSE(scheduler->RedrawPending());
1070 EXPECT_FALSE(scheduler->ManageTilesPending()); 1081 EXPECT_FALSE(scheduler->ManageTilesPending());
1071 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); 1082 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending());
1072 1083
1073 // Next frame without DidManageTiles should ManageTiles with draw. 1084 // Next frame without DidManageTiles should ManageTiles with draw.
1074 scheduler->SetNeedsManageTiles(); 1085 scheduler->SetNeedsManageTiles();
1075 scheduler->SetNeedsRedraw(); 1086 scheduler->SetNeedsRedraw();
1076 client.Reset(); 1087 client.Reset();
1077 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); 1088 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting());
1078 EXPECT_EQ(client.num_actions_(), 0); 1089 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client);
1079 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 1090 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending());
1080 1091
1081 client.Reset(); 1092 client.Reset();
1082 scheduler->OnBeginImplFrameDeadline(); 1093 client.task_runner().RunPendingTasks(); // Run posted deadline.
1083 EXPECT_EQ(1, client.num_draws()); 1094 EXPECT_EQ(1, client.num_draws());
1084 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); 1095 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible"));
1085 EXPECT_TRUE(client.HasAction("ScheduledActionManageTiles")); 1096 EXPECT_TRUE(client.HasAction("ScheduledActionManageTiles"));
1086 EXPECT_LT(client.ActionIndex("ScheduledActionDrawAndSwapIfPossible"), 1097 EXPECT_LT(client.ActionIndex("ScheduledActionDrawAndSwapIfPossible"),
1087 client.ActionIndex("ScheduledActionManageTiles")); 1098 client.ActionIndex("ScheduledActionManageTiles"));
1088 EXPECT_FALSE(scheduler->RedrawPending()); 1099 EXPECT_FALSE(scheduler->RedrawPending());
1089 EXPECT_FALSE(scheduler->ManageTilesPending()); 1100 EXPECT_FALSE(scheduler->ManageTilesPending());
1090 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); 1101 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending());
1091 scheduler->DidManageTiles(); // Corresponds to ScheduledActionManageTiles 1102 scheduler->DidManageTiles(); // Corresponds to ScheduledActionManageTiles
1092 1103
1093 // If we get another DidManageTiles within the same frame, we should 1104 // If we get another DidManageTiles within the same frame, we should
1094 // not ManageTiles on the next frame. 1105 // not ManageTiles on the next frame.
1095 scheduler->DidManageTiles(); // An explicit ManageTiles. 1106 scheduler->DidManageTiles(); // An explicit ManageTiles.
1096 scheduler->SetNeedsManageTiles(); 1107 scheduler->SetNeedsManageTiles();
1097 scheduler->SetNeedsRedraw(); 1108 scheduler->SetNeedsRedraw();
1098 client.Reset(); 1109 client.Reset();
1099 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); 1110 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting());
1100 EXPECT_EQ(client.num_actions_(), 0); 1111 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client);
1101 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 1112 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending());
1102 1113
1103 EXPECT_TRUE(scheduler->ManageTilesPending()); 1114 EXPECT_TRUE(scheduler->ManageTilesPending());
1104 1115
1105 client.Reset(); 1116 client.Reset();
1106 scheduler->OnBeginImplFrameDeadline(); 1117 client.task_runner().RunPendingTasks(); // Run posted deadline.
1107 EXPECT_EQ(1, client.num_draws()); 1118 EXPECT_EQ(1, client.num_draws());
1108 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); 1119 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible"));
1109 EXPECT_FALSE(client.HasAction("ScheduledActionManageTiles")); 1120 EXPECT_FALSE(client.HasAction("ScheduledActionManageTiles"));
1110 EXPECT_FALSE(scheduler->RedrawPending()); 1121 EXPECT_FALSE(scheduler->RedrawPending());
1111 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); 1122 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending());
1112 1123
1113 // If we get another DidManageTiles, we should not ManageTiles on the next 1124 // If we get another DidManageTiles, we should not ManageTiles on the next
1114 // frame. This verifies we don't alternate calling ManageTiles once and twice. 1125 // frame. This verifies we don't alternate calling ManageTiles once and twice.
1115 EXPECT_TRUE(scheduler->ManageTilesPending()); 1126 EXPECT_TRUE(scheduler->ManageTilesPending());
1116 scheduler->DidManageTiles(); // An explicit ManageTiles. 1127 scheduler->DidManageTiles(); // An explicit ManageTiles.
1117 EXPECT_FALSE(scheduler->ManageTilesPending()); 1128 EXPECT_FALSE(scheduler->ManageTilesPending());
1118 scheduler->SetNeedsManageTiles(); 1129 scheduler->SetNeedsManageTiles();
1119 scheduler->SetNeedsRedraw(); 1130 scheduler->SetNeedsRedraw();
1120 client.Reset(); 1131 client.Reset();
1121 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); 1132 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting());
1122 EXPECT_EQ(client.num_actions_(), 0); 1133 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client);
1123 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 1134 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending());
1124 1135
1125 EXPECT_TRUE(scheduler->ManageTilesPending()); 1136 EXPECT_TRUE(scheduler->ManageTilesPending());
1126 1137
1127 client.Reset(); 1138 client.Reset();
1128 scheduler->OnBeginImplFrameDeadline(); 1139 client.task_runner().RunPendingTasks(); // Run posted deadline.
1129 EXPECT_EQ(1, client.num_draws()); 1140 EXPECT_EQ(1, client.num_draws());
1130 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); 1141 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible"));
1131 EXPECT_FALSE(client.HasAction("ScheduledActionManageTiles")); 1142 EXPECT_FALSE(client.HasAction("ScheduledActionManageTiles"));
1132 EXPECT_FALSE(scheduler->RedrawPending()); 1143 EXPECT_FALSE(scheduler->RedrawPending());
1133 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); 1144 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending());
1134 1145
1135 // Next frame without DidManageTiles should ManageTiles with draw. 1146 // Next frame without DidManageTiles should ManageTiles with draw.
1136 scheduler->SetNeedsManageTiles(); 1147 scheduler->SetNeedsManageTiles();
1137 scheduler->SetNeedsRedraw(); 1148 scheduler->SetNeedsRedraw();
1138 client.Reset(); 1149 client.Reset();
1139 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); 1150 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting());
1140 EXPECT_EQ(client.num_actions_(), 0); 1151 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client);
1141 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 1152 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending());
1142 1153
1143 client.Reset(); 1154 client.Reset();
1144 scheduler->OnBeginImplFrameDeadline(); 1155 client.task_runner().RunPendingTasks(); // Run posted deadline.
1145 EXPECT_EQ(1, client.num_draws()); 1156 EXPECT_EQ(1, client.num_draws());
1146 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); 1157 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible"));
1147 EXPECT_TRUE(client.HasAction("ScheduledActionManageTiles")); 1158 EXPECT_TRUE(client.HasAction("ScheduledActionManageTiles"));
1148 EXPECT_LT(client.ActionIndex("ScheduledActionDrawAndSwapIfPossible"), 1159 EXPECT_LT(client.ActionIndex("ScheduledActionDrawAndSwapIfPossible"),
1149 client.ActionIndex("ScheduledActionManageTiles")); 1160 client.ActionIndex("ScheduledActionManageTiles"));
1150 EXPECT_FALSE(scheduler->RedrawPending()); 1161 EXPECT_FALSE(scheduler->RedrawPending());
1151 EXPECT_FALSE(scheduler->ManageTilesPending()); 1162 EXPECT_FALSE(scheduler->ManageTilesPending());
1152 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); 1163 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending());
1153 scheduler->DidManageTiles(); // Corresponds to ScheduledActionManageTiles 1164 scheduler->DidManageTiles(); // Corresponds to ScheduledActionManageTiles
1154 } 1165 }
1155 1166
1156 TEST(SchedulerTest, TriggerBeginFrameDeadlineEarly) { 1167 TEST(SchedulerTest, TriggerBeginFrameDeadlineEarly) {
1157 SchedulerClientNeedsManageTilesInDraw client; 1168 SchedulerClientNeedsManageTilesInDraw client;
1158 SchedulerSettings default_scheduler_settings; 1169 SchedulerSettings default_scheduler_settings;
1159 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings); 1170 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings);
1160 scheduler->SetCanStart(); 1171 scheduler->SetCanStart();
1161 scheduler->SetVisible(true); 1172 scheduler->SetVisible(true);
1162 scheduler->SetCanDraw(true); 1173 scheduler->SetCanDraw(true);
1163 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); 1174 InitializeOutputSurfaceAndFirstCommit(scheduler, &client);
1164 1175
1165 client.Reset(); 1176 client.Reset();
1166 BeginFrameArgs impl_frame_args = BeginFrameArgs::CreateForTesting();
1167 scheduler->SetNeedsRedraw(); 1177 scheduler->SetNeedsRedraw();
1168 scheduler->BeginImplFrame(impl_frame_args); 1178 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting());
1169 1179
1170 // The deadline should be zero since there is no work other than drawing 1180 // The deadline should be zero since there is no work other than drawing
1171 // pending. 1181 // pending.
1172 EXPECT_EQ(base::TimeTicks(), client.posted_begin_impl_frame_deadline()); 1182 EXPECT_EQ(base::TimeTicks(), client.posted_begin_impl_frame_deadline());
1173 } 1183 }
1174 1184
1175 class SchedulerClientWithFixedEstimates : public FakeSchedulerClient { 1185 class SchedulerClientWithFixedEstimates : public FakeSchedulerClient {
1176 public: 1186 public:
1177 SchedulerClientWithFixedEstimates( 1187 SchedulerClientWithFixedEstimates(
1178 base::TimeDelta draw_duration, 1188 base::TimeDelta draw_duration,
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
1214 scheduler->SetCanStart(); 1224 scheduler->SetCanStart();
1215 scheduler->SetVisible(true); 1225 scheduler->SetVisible(true);
1216 scheduler->SetCanDraw(true); 1226 scheduler->SetCanDraw(true);
1217 scheduler->SetSmoothnessTakesPriority(smoothness_takes_priority); 1227 scheduler->SetSmoothnessTakesPriority(smoothness_takes_priority);
1218 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); 1228 InitializeOutputSurfaceAndFirstCommit(scheduler, &client);
1219 1229
1220 // Impl thread hits deadline before commit finishes. 1230 // Impl thread hits deadline before commit finishes.
1221 client.Reset(); 1231 client.Reset();
1222 scheduler->SetNeedsCommit(); 1232 scheduler->SetNeedsCommit();
1223 EXPECT_FALSE(scheduler->MainThreadIsInHighLatencyMode()); 1233 EXPECT_FALSE(scheduler->MainThreadIsInHighLatencyMode());
1224 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); 1234 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting());
1225 EXPECT_FALSE(scheduler->MainThreadIsInHighLatencyMode()); 1235 EXPECT_FALSE(scheduler->MainThreadIsInHighLatencyMode());
1226 scheduler->OnBeginImplFrameDeadline(); 1236 client.task_runner().RunPendingTasks(); // Run posted deadline.
1227 EXPECT_TRUE(scheduler->MainThreadIsInHighLatencyMode()); 1237 EXPECT_TRUE(scheduler->MainThreadIsInHighLatencyMode());
1228 scheduler->NotifyBeginMainFrameStarted(); 1238 scheduler->NotifyBeginMainFrameStarted();
1229 scheduler->NotifyReadyToCommit(); 1239 scheduler->NotifyReadyToCommit();
1230 EXPECT_TRUE(scheduler->MainThreadIsInHighLatencyMode()); 1240 EXPECT_TRUE(scheduler->MainThreadIsInHighLatencyMode());
1231 EXPECT_TRUE(client.HasAction("ScheduledActionSendBeginMainFrame")); 1241 EXPECT_TRUE(client.HasAction("ScheduledActionSendBeginMainFrame"));
1232 1242
1233 client.Reset(); 1243 client.Reset();
1234 scheduler->SetNeedsCommit(); 1244 scheduler->SetNeedsCommit();
1235 EXPECT_TRUE(scheduler->MainThreadIsInHighLatencyMode()); 1245 EXPECT_TRUE(scheduler->MainThreadIsInHighLatencyMode());
1236 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); 1246 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting());
1237 EXPECT_TRUE(scheduler->MainThreadIsInHighLatencyMode()); 1247 EXPECT_TRUE(scheduler->MainThreadIsInHighLatencyMode());
1238 scheduler->OnBeginImplFrameDeadline(); 1248 client.task_runner().RunPendingTasks(); // Run posted deadline.
1239 EXPECT_EQ(scheduler->MainThreadIsInHighLatencyMode(), 1249 EXPECT_EQ(scheduler->MainThreadIsInHighLatencyMode(),
1240 should_send_begin_main_frame); 1250 should_send_begin_main_frame);
1241 EXPECT_EQ(client.HasAction("ScheduledActionSendBeginMainFrame"), 1251 EXPECT_EQ(client.HasAction("ScheduledActionSendBeginMainFrame"),
1242 should_send_begin_main_frame); 1252 should_send_begin_main_frame);
1243 } 1253 }
1244 1254
1245 TEST(SchedulerTest, 1255 TEST(SchedulerTest,
1246 SkipMainFrameIfHighLatencyAndCanCommitAndActivateBeforeDeadline) { 1256 SkipMainFrameIfHighLatencyAndCanCommitAndActivateBeforeDeadline) {
1247 // Set up client so that estimates indicate that we can commit and activate 1257 // Set up client so that estimates indicate that we can commit and activate
1248 // before the deadline (~8ms by default). 1258 // before the deadline (~8ms by default).
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1283 scheduler->SetCanStart(); 1293 scheduler->SetCanStart();
1284 scheduler->SetVisible(true); 1294 scheduler->SetVisible(true);
1285 scheduler->DidCreateAndInitializeOutputSurface(); 1295 scheduler->DidCreateAndInitializeOutputSurface();
1286 1296
1287 scheduler->SetNeedsCommit(); 1297 scheduler->SetNeedsCommit();
1288 EXPECT_TRUE(scheduler->CommitPending()); 1298 EXPECT_TRUE(scheduler->CommitPending());
1289 scheduler->NotifyBeginMainFrameStarted(); 1299 scheduler->NotifyBeginMainFrameStarted();
1290 scheduler->NotifyReadyToCommit(); 1300 scheduler->NotifyReadyToCommit();
1291 scheduler->SetNeedsRedraw(); 1301 scheduler->SetNeedsRedraw();
1292 1302
1293 BeginFrameArgs impl_frame_args = BeginFrameArgs::CreateForTesting(); 1303 BeginFrameArgs frame_args = BeginFrameArgs::CreateForTesting();
1294 impl_frame_args.interval = base::TimeDelta::FromMilliseconds(1000); 1304 frame_args.interval = base::TimeDelta::FromMilliseconds(1000);
1295 scheduler->BeginImplFrame(impl_frame_args); 1305 scheduler->BeginFrame(frame_args);
1296 1306
1297 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 1307 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending());
1298 client.task_runner().RunPendingTasks(); // Run posted deadline. 1308 client.task_runner().RunPendingTasks(); // Run posted deadline.
1299 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); 1309 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending());
1300 1310
1301 // At this point, we've drawn a frame. Start another commit, but hold off on 1311 // At this point, we've drawn a frame. Start another commit, but hold off on
1302 // the NotifyReadyToCommit for now. 1312 // the NotifyReadyToCommit for now.
1303 EXPECT_FALSE(scheduler->CommitPending()); 1313 EXPECT_FALSE(scheduler->CommitPending());
1304 scheduler->SetNeedsCommit(); 1314 scheduler->SetNeedsCommit();
1305 scheduler->BeginImplFrame(impl_frame_args); 1315 scheduler->BeginFrame(frame_args);
1306 EXPECT_TRUE(scheduler->CommitPending()); 1316 EXPECT_TRUE(scheduler->CommitPending());
1307 1317
1308 // Spin the event loop a few times and make sure we get more 1318 // Spin the event loop a few times and make sure we get more
1309 // DidAnticipateDrawTimeChange calls every time. 1319 // DidAnticipateDrawTimeChange calls every time.
1310 int actions_so_far = client.num_actions_(); 1320 int actions_so_far = client.num_actions_();
1311 1321
1312 // Does three iterations to make sure that the timer is properly repeating. 1322 // Does three iterations to make sure that the timer is properly repeating.
1313 for (int i = 0; i < 3; ++i) { 1323 for (int i = 0; i < 3; ++i) {
1314 EXPECT_EQ((impl_frame_args.interval * 2).InMicroseconds(), 1324 EXPECT_EQ((frame_args.interval * 2).InMicroseconds(),
1315 client.task_runner().NextPendingTaskDelay().InMicroseconds()) 1325 client.task_runner().NextPendingTaskDelay().InMicroseconds())
1316 << *scheduler->StateAsValue(); 1326 << *scheduler->StateAsValue();
1317 client.task_runner().RunPendingTasks(); 1327 client.task_runner().RunPendingTasks();
1318 EXPECT_GT(client.num_actions_(), actions_so_far); 1328 EXPECT_GT(client.num_actions_(), actions_so_far);
1319 EXPECT_STREQ(client.Action(client.num_actions_() - 1), 1329 EXPECT_STREQ(client.Action(client.num_actions_() - 1),
1320 "DidAnticipatedDrawTimeChange"); 1330 "DidAnticipatedDrawTimeChange");
1321 actions_so_far = client.num_actions_(); 1331 actions_so_far = client.num_actions_();
1322 } 1332 }
1323 1333
1324 // Do the same thing after BeginMainFrame starts but still before activation. 1334 // Do the same thing after BeginMainFrame starts but still before activation.
1325 scheduler->NotifyBeginMainFrameStarted(); 1335 scheduler->NotifyBeginMainFrameStarted();
1326 for (int i = 0; i < 3; ++i) { 1336 for (int i = 0; i < 3; ++i) {
1327 EXPECT_EQ((impl_frame_args.interval * 2).InMicroseconds(), 1337 EXPECT_EQ((frame_args.interval * 2).InMicroseconds(),
1328 client.task_runner().NextPendingTaskDelay().InMicroseconds()) 1338 client.task_runner().NextPendingTaskDelay().InMicroseconds())
1329 << *scheduler->StateAsValue(); 1339 << *scheduler->StateAsValue();
1330 client.task_runner().RunPendingTasks(); 1340 client.task_runner().RunPendingTasks();
1331 EXPECT_GT(client.num_actions_(), actions_so_far); 1341 EXPECT_GT(client.num_actions_(), actions_so_far);
1332 EXPECT_STREQ(client.Action(client.num_actions_() - 1), 1342 EXPECT_STREQ(client.Action(client.num_actions_() - 1),
1333 "DidAnticipatedDrawTimeChange"); 1343 "DidAnticipatedDrawTimeChange");
1334 actions_so_far = client.num_actions_(); 1344 actions_so_far = client.num_actions_();
1335 } 1345 }
1336 } 1346 }
1337 1347
1348 TEST(SchedulerTest, BeginRetroFrame) {
1349 FakeSchedulerClient client;
1350 SchedulerSettings scheduler_settings;
1351 Scheduler* scheduler = client.CreateScheduler(scheduler_settings);
1352 scheduler->SetCanStart();
1353 scheduler->SetVisible(true);
1354 scheduler->SetCanDraw(true);
1355 InitializeOutputSurfaceAndFirstCommit(scheduler, &client);
1356
1357 // SetNeedsCommit should begin the frame on the next BeginImplFrame.
1358 client.Reset();
1359 scheduler->SetNeedsCommit();
1360 EXPECT_TRUE(client.needs_begin_impl_frame());
1361 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client);
1362 client.Reset();
1363
1364 // Create a BeginFrame with a long deadline to avoid race conditions.
1365 // This is the first BeginFrame, which will be handled immediately.
1366 BeginFrameArgs args = BeginFrameArgs::CreateForTesting();
1367 args.deadline += base::TimeDelta::FromHours(1);
Sami 2014/04/08 11:25:25 I wish all our deadlines were this long :)
1368 scheduler->BeginFrame(args);
1369
1370 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2);
1371 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2);
1372 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending());
1373 EXPECT_TRUE(client.needs_begin_impl_frame());
1374 client.Reset();
1375
1376 // Queue BeginFrames while we are still handling the previous BeginFrame.
1377 args.frame_time += base::TimeDelta::FromSeconds(1);
1378 scheduler->BeginFrame(args);
1379 args.frame_time += base::TimeDelta::FromSeconds(1);
1380 scheduler->BeginFrame(args);
1381
1382 // If we don't swap on the deadline, we need to request another
1383 // BeginImplFrame.
1384 client.task_runner().RunPendingTasks(); // Run posted deadline.
1385 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client);
1386 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending());
1387 EXPECT_TRUE(client.needs_begin_impl_frame());
1388 client.Reset();
1389
1390 // NotifyReadyToCommit should trigger the commit.
1391 scheduler->NotifyBeginMainFrameStarted();
1392 scheduler->NotifyReadyToCommit();
1393 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client);
1394 EXPECT_TRUE(client.needs_begin_impl_frame());
1395 client.Reset();
1396
1397 // BeginImplFrame should prepare the draw.
1398 client.task_runner().RunPendingTasks(); // Run posted BeginRetroFrame.
1399 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client);
1400 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending());
1401 EXPECT_TRUE(client.needs_begin_impl_frame());
1402 client.Reset();
1403
1404 // BeginImplFrame deadline should draw.
1405 client.task_runner().RunPendingTasks(); // Run posted deadline.
1406 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 2);
1407 EXPECT_ACTION("SetNeedsBeginFrame", client, 1, 2);
1408 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending());
1409 EXPECT_TRUE(client.needs_begin_impl_frame());
1410 client.Reset();
1411
1412 // The following BeginImplFrame deadline should SetNeedsBeginFrame(false)
1413 // to avoid excessive toggles.
1414 client.task_runner().RunPendingTasks(); // Run posted BeginRetroFrame.
1415 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client);
1416 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending());
1417 client.Reset();
1418
1419 client.task_runner().RunPendingTasks(); // Run posted deadline.
1420 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client);
1421 EXPECT_FALSE(client.needs_begin_impl_frame());
1422 client.Reset();
1423 }
1424
1338 } // namespace 1425 } // namespace
1339 } // namespace cc 1426 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698