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

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

Issue 164373012: Remove options to disable deadline scheduling (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: rebase Created 6 years, 10 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
« no previous file with comments | « cc/scheduler/scheduler_state_machine_unittest.cc ('k') | cc/trees/layer_tree_settings.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 scheduler->SetCanStart(); 199 scheduler->SetCanStart();
200 scheduler->SetVisible(true); 200 scheduler->SetVisible(true);
201 scheduler->SetCanDraw(true); 201 scheduler->SetCanDraw(true);
202 202
203 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); 203 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client);
204 client.Reset(); 204 client.Reset();
205 scheduler->DidCreateAndInitializeOutputSurface(); 205 scheduler->DidCreateAndInitializeOutputSurface();
206 EXPECT_EQ(0, client.num_actions_()); 206 EXPECT_EQ(0, client.num_actions_());
207 } 207 }
208 208
209 void RequestCommit(bool deadline_scheduling_enabled) { 209 TEST(SchedulerTest, RequestCommit) {
210 FakeSchedulerClient client; 210 FakeSchedulerClient client;
211 SchedulerSettings scheduler_settings; 211 SchedulerSettings scheduler_settings;
212 scheduler_settings.deadline_scheduling_enabled = deadline_scheduling_enabled;
213 Scheduler* scheduler = client.CreateScheduler(scheduler_settings); 212 Scheduler* scheduler = client.CreateScheduler(scheduler_settings);
214 scheduler->SetCanStart(); 213 scheduler->SetCanStart();
215 scheduler->SetVisible(true); 214 scheduler->SetVisible(true);
216 scheduler->SetCanDraw(true); 215 scheduler->SetCanDraw(true);
217 216
218 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); 217 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client);
219 InitializeOutputSurfaceAndFirstCommit(scheduler); 218 InitializeOutputSurfaceAndFirstCommit(scheduler);
220 219
221 // SetNeedsCommit should begin the frame on the next BeginImplFrame. 220 // SetNeedsCommit should begin the frame on the next BeginImplFrame.
222 client.Reset(); 221 client.Reset();
223 scheduler->SetNeedsCommit(); 222 scheduler->SetNeedsCommit();
224 EXPECT_TRUE(client.needs_begin_impl_frame()); 223 EXPECT_TRUE(client.needs_begin_impl_frame());
225 if (deadline_scheduling_enabled) { 224 EXPECT_SINGLE_ACTION("SetNeedsBeginImplFrame", client);
226 EXPECT_SINGLE_ACTION("SetNeedsBeginImplFrame", client);
227 } else {
228 EXPECT_EQ(client.num_actions_(), 2);
229 EXPECT_TRUE(client.HasAction("ScheduledActionSendBeginMainFrame"));
230 EXPECT_TRUE(client.HasAction("SetNeedsBeginImplFrame"));
231 }
232 client.Reset(); 225 client.Reset();
233 226
234 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); 227 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting());
235 if (deadline_scheduling_enabled) { 228 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 0, 2);
236 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 0, 2); 229 EXPECT_ACTION("PostBeginImplFrameDeadlineTask", client, 1, 2);
237 EXPECT_ACTION("PostBeginImplFrameDeadlineTask", client, 1, 2);
238 } else {
239 EXPECT_SINGLE_ACTION("PostBeginImplFrameDeadlineTask", client);
240 }
241 EXPECT_TRUE(client.needs_begin_impl_frame()); 230 EXPECT_TRUE(client.needs_begin_impl_frame());
242 client.Reset(); 231 client.Reset();
243 232
244 // If we don't swap on the deadline, we need to request another 233 // If we don't swap on the deadline, we need to request another
245 // BeginImplFrame. 234 // BeginImplFrame.
246 scheduler->OnBeginImplFrameDeadline(); 235 scheduler->OnBeginImplFrameDeadline();
247 EXPECT_SINGLE_ACTION("SetNeedsBeginImplFrame", client); 236 EXPECT_SINGLE_ACTION("SetNeedsBeginImplFrame", client);
248 EXPECT_TRUE(client.needs_begin_impl_frame()); 237 EXPECT_TRUE(client.needs_begin_impl_frame());
249 client.Reset(); 238 client.Reset();
250 239
(...skipping 21 matching lines...) Expand all
272 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); 261 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting());
273 EXPECT_SINGLE_ACTION("PostBeginImplFrameDeadlineTask", client); 262 EXPECT_SINGLE_ACTION("PostBeginImplFrameDeadlineTask", client);
274 client.Reset(); 263 client.Reset();
275 264
276 scheduler->OnBeginImplFrameDeadline(); 265 scheduler->OnBeginImplFrameDeadline();
277 EXPECT_SINGLE_ACTION("SetNeedsBeginImplFrame", client); 266 EXPECT_SINGLE_ACTION("SetNeedsBeginImplFrame", client);
278 EXPECT_FALSE(client.needs_begin_impl_frame()); 267 EXPECT_FALSE(client.needs_begin_impl_frame());
279 client.Reset(); 268 client.Reset();
280 } 269 }
281 270
282 TEST(SchedulerTest, RequestCommit) { 271 TEST(SchedulerTest, RequestCommitAfterBeginMainFrameSent) {
283 bool deadline_scheduling_enabled = false;
284 RequestCommit(deadline_scheduling_enabled);
285 }
286
287 TEST(SchedulerTest, RequestCommit_Deadline) {
288 bool deadline_scheduling_enabled = true;
289 RequestCommit(deadline_scheduling_enabled);
290 }
291
292 void RequestCommitAfterBeginMainFrameSent(
293 bool deadline_scheduling_enabled) {
294 FakeSchedulerClient client; 272 FakeSchedulerClient client;
295 SchedulerSettings scheduler_settings; 273 SchedulerSettings scheduler_settings;
296 scheduler_settings.deadline_scheduling_enabled = deadline_scheduling_enabled;
297 Scheduler* scheduler = client.CreateScheduler(scheduler_settings); 274 Scheduler* scheduler = client.CreateScheduler(scheduler_settings);
298 scheduler->SetCanStart(); 275 scheduler->SetCanStart();
299 scheduler->SetVisible(true); 276 scheduler->SetVisible(true);
300 scheduler->SetCanDraw(true); 277 scheduler->SetCanDraw(true);
301 278
302 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); 279 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client);
303 InitializeOutputSurfaceAndFirstCommit(scheduler); 280 InitializeOutputSurfaceAndFirstCommit(scheduler);
304 client.Reset(); 281 client.Reset();
305 282
306 // SetNeedsCommit should begin the frame. 283 // SetNeedsCommit should begin the frame.
307 scheduler->SetNeedsCommit(); 284 scheduler->SetNeedsCommit();
308 if (deadline_scheduling_enabled) { 285 EXPECT_SINGLE_ACTION("SetNeedsBeginImplFrame", client);
309 EXPECT_SINGLE_ACTION("SetNeedsBeginImplFrame", client);
310 } else {
311 EXPECT_EQ(client.num_actions_(), 2);
312 EXPECT_TRUE(client.HasAction("SetNeedsBeginImplFrame"));
313 EXPECT_TRUE(client.HasAction("ScheduledActionSendBeginMainFrame"));
314 }
315 286
316 client.Reset(); 287 client.Reset();
317 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); 288 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting());
318 if (deadline_scheduling_enabled) { 289 EXPECT_EQ(client.num_actions_(), 2);
319 EXPECT_EQ(client.num_actions_(), 2); 290 EXPECT_TRUE(client.HasAction("ScheduledActionSendBeginMainFrame"));
320 EXPECT_TRUE(client.HasAction("ScheduledActionSendBeginMainFrame")); 291 EXPECT_TRUE(client.HasAction("PostBeginImplFrameDeadlineTask"));
321 EXPECT_TRUE(client.HasAction("PostBeginImplFrameDeadlineTask"));
322 } else {
323 EXPECT_SINGLE_ACTION("PostBeginImplFrameDeadlineTask", client);
324 }
325 292
326 EXPECT_TRUE(client.needs_begin_impl_frame()); 293 EXPECT_TRUE(client.needs_begin_impl_frame());
327 client.Reset(); 294 client.Reset();
328 295
329 // Now SetNeedsCommit again. Calling here means we need a second commit. 296 // Now SetNeedsCommit again. Calling here means we need a second commit.
330 scheduler->SetNeedsCommit(); 297 scheduler->SetNeedsCommit();
331 EXPECT_EQ(client.num_actions_(), 0); 298 EXPECT_EQ(client.num_actions_(), 0);
332 client.Reset(); 299 client.Reset();
333 300
334 // Finish the first commit. 301 // Finish the first commit.
335 scheduler->FinishCommit(); 302 scheduler->FinishCommit();
336 EXPECT_ACTION("ScheduledActionCommit", client, 0, 2); 303 EXPECT_ACTION("ScheduledActionCommit", client, 0, 2);
337 EXPECT_ACTION("PostBeginImplFrameDeadlineTask", client, 1, 2); 304 EXPECT_ACTION("PostBeginImplFrameDeadlineTask", client, 1, 2);
338 client.Reset(); 305 client.Reset();
339 scheduler->OnBeginImplFrameDeadline(); 306 scheduler->OnBeginImplFrameDeadline();
340 if (deadline_scheduling_enabled) { 307 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 2);
341 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 2); 308 EXPECT_ACTION("SetNeedsBeginImplFrame", client, 1, 2);
342 EXPECT_ACTION("SetNeedsBeginImplFrame", client, 1, 2);
343 } else {
344 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 3);
345 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 3);
346 EXPECT_ACTION("SetNeedsBeginImplFrame", client, 2, 3);
347 }
348 309
349 // Because we just swapped, the Scheduler should also request the next 310 // Because we just swapped, the Scheduler should also request the next
350 // BeginImplFrame from the OutputSurface. 311 // BeginImplFrame from the OutputSurface.
351 EXPECT_TRUE(client.needs_begin_impl_frame()); 312 EXPECT_TRUE(client.needs_begin_impl_frame());
352 client.Reset(); 313 client.Reset();
353 314
354 // Since another commit is needed, the next BeginImplFrame should initiate 315 // Since another commit is needed, the next BeginImplFrame should initiate
355 // the second commit. 316 // the second commit.
356 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); 317 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting());
357 if (deadline_scheduling_enabled) { 318 EXPECT_EQ(client.num_actions_(), 2);
358 EXPECT_EQ(client.num_actions_(), 2); 319 EXPECT_TRUE(client.HasAction("ScheduledActionSendBeginMainFrame"));
359 EXPECT_TRUE(client.HasAction("ScheduledActionSendBeginMainFrame")); 320 EXPECT_TRUE(client.HasAction("PostBeginImplFrameDeadlineTask"));
360 EXPECT_TRUE(client.HasAction("PostBeginImplFrameDeadlineTask"));
361 } else {
362 EXPECT_SINGLE_ACTION("PostBeginImplFrameDeadlineTask", client);
363 }
364 client.Reset(); 321 client.Reset();
365 322
366 // Finishing the commit before the deadline should post a new deadline task 323 // Finishing the commit before the deadline should post a new deadline task
367 // to trigger the deadline early. 324 // to trigger the deadline early.
368 scheduler->FinishCommit(); 325 scheduler->FinishCommit();
369 EXPECT_ACTION("ScheduledActionCommit", client, 0, 2); 326 EXPECT_ACTION("ScheduledActionCommit", client, 0, 2);
370 EXPECT_ACTION("PostBeginImplFrameDeadlineTask", client, 1, 2); 327 EXPECT_ACTION("PostBeginImplFrameDeadlineTask", client, 1, 2);
371 client.Reset(); 328 client.Reset();
372 scheduler->OnBeginImplFrameDeadline(); 329 scheduler->OnBeginImplFrameDeadline();
373 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 2); 330 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 2);
374 EXPECT_ACTION("SetNeedsBeginImplFrame", client, 1, 2); 331 EXPECT_ACTION("SetNeedsBeginImplFrame", client, 1, 2);
375 EXPECT_TRUE(client.needs_begin_impl_frame()); 332 EXPECT_TRUE(client.needs_begin_impl_frame());
376 client.Reset(); 333 client.Reset();
377 334
378 // On the next BeginImplFrame, verify we go back to a quiescent state and 335 // On the next BeginImplFrame, verify we go back to a quiescent state and
379 // no longer request BeginImplFrames. 336 // no longer request BeginImplFrames.
380 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); 337 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting());
381 scheduler->OnBeginImplFrameDeadline(); 338 scheduler->OnBeginImplFrameDeadline();
382 EXPECT_FALSE(client.needs_begin_impl_frame()); 339 EXPECT_FALSE(client.needs_begin_impl_frame());
383 client.Reset(); 340 client.Reset();
384 } 341 }
385 342
386 TEST(SchedulerTest, RequestCommitAfterBeginMainFrameSent) { 343 TEST(SchedulerTest, TextureAcquisitionCausesCommitInsteadOfDraw) {
387 bool deadline_scheduling_enabled = false;
388 RequestCommitAfterBeginMainFrameSent(deadline_scheduling_enabled);
389 }
390
391 TEST(SchedulerTest, RequestCommitAfterBeginMainFrameSent_Deadline) {
392 bool deadline_scheduling_enabled = true;
393 RequestCommitAfterBeginMainFrameSent(deadline_scheduling_enabled);
394 }
395
396 void TextureAcquisitionCausesCommitInsteadOfDraw(
397 bool deadline_scheduling_enabled) {
398 FakeSchedulerClient client; 344 FakeSchedulerClient client;
399 SchedulerSettings scheduler_settings; 345 SchedulerSettings scheduler_settings;
400 scheduler_settings.deadline_scheduling_enabled = deadline_scheduling_enabled;
401 Scheduler* scheduler = client.CreateScheduler(scheduler_settings); 346 Scheduler* scheduler = client.CreateScheduler(scheduler_settings);
402 scheduler->SetCanStart(); 347 scheduler->SetCanStart();
403 scheduler->SetVisible(true); 348 scheduler->SetVisible(true);
404 scheduler->SetCanDraw(true); 349 scheduler->SetCanDraw(true);
405 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); 350 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client);
406 351
407 InitializeOutputSurfaceAndFirstCommit(scheduler); 352 InitializeOutputSurfaceAndFirstCommit(scheduler);
408 client.Reset(); 353 client.Reset();
409 scheduler->SetNeedsRedraw(); 354 scheduler->SetNeedsRedraw();
410 EXPECT_TRUE(scheduler->RedrawPending()); 355 EXPECT_TRUE(scheduler->RedrawPending());
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
447 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); 392 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting());
448 EXPECT_SINGLE_ACTION("PostBeginImplFrameDeadlineTask", client); 393 EXPECT_SINGLE_ACTION("PostBeginImplFrameDeadlineTask", client);
449 client.Reset(); 394 client.Reset();
450 scheduler->OnBeginImplFrameDeadline(); 395 scheduler->OnBeginImplFrameDeadline();
451 EXPECT_SINGLE_ACTION("SetNeedsBeginImplFrame", client); 396 EXPECT_SINGLE_ACTION("SetNeedsBeginImplFrame", client);
452 EXPECT_TRUE(scheduler->RedrawPending()); 397 EXPECT_TRUE(scheduler->RedrawPending());
453 EXPECT_TRUE(client.needs_begin_impl_frame()); 398 EXPECT_TRUE(client.needs_begin_impl_frame());
454 399
455 client.Reset(); 400 client.Reset();
456 scheduler->SetNeedsCommit(); 401 scheduler->SetNeedsCommit();
457 if (deadline_scheduling_enabled) { 402 EXPECT_EQ(0, client.num_actions_());
458 EXPECT_EQ(0, client.num_actions_());
459 } else {
460 EXPECT_SINGLE_ACTION("ScheduledActionSendBeginMainFrame", client);
461 }
462 403
463 client.Reset(); 404 client.Reset();
464 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); 405 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting());
465 if (deadline_scheduling_enabled) { 406 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 0, 2);
466 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 0, 2); 407 EXPECT_ACTION("PostBeginImplFrameDeadlineTask", client, 1, 2);
467 EXPECT_ACTION("PostBeginImplFrameDeadlineTask", client, 1, 2);
468 } else {
469 EXPECT_SINGLE_ACTION("PostBeginImplFrameDeadlineTask", client);
470 }
471 408
472 // Commit will release the texture. 409 // Commit will release the texture.
473 client.Reset(); 410 client.Reset();
474 scheduler->FinishCommit(); 411 scheduler->FinishCommit();
475 EXPECT_ACTION("ScheduledActionCommit", client, 0, 2); 412 EXPECT_ACTION("ScheduledActionCommit", client, 0, 2);
476 EXPECT_ACTION("PostBeginImplFrameDeadlineTask", client, 1, 2); 413 EXPECT_ACTION("PostBeginImplFrameDeadlineTask", client, 1, 2);
477 EXPECT_TRUE(scheduler->RedrawPending()); 414 EXPECT_TRUE(scheduler->RedrawPending());
478 415
479 // Now we can draw again after the commit happens. 416 // Now we can draw again after the commit happens.
480 client.Reset(); 417 client.Reset();
481 scheduler->OnBeginImplFrameDeadline(); 418 scheduler->OnBeginImplFrameDeadline();
482 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 2); 419 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 2);
483 EXPECT_ACTION("SetNeedsBeginImplFrame", client, 1, 2); 420 EXPECT_ACTION("SetNeedsBeginImplFrame", client, 1, 2);
484 EXPECT_FALSE(scheduler->RedrawPending()); 421 EXPECT_FALSE(scheduler->RedrawPending());
485 EXPECT_TRUE(client.needs_begin_impl_frame()); 422 EXPECT_TRUE(client.needs_begin_impl_frame());
486 423
487 // Make sure we stop requesting BeginImplFrames if we don't swap. 424 // Make sure we stop requesting BeginImplFrames if we don't swap.
488 client.Reset(); 425 client.Reset();
489 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); 426 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting());
490 EXPECT_SINGLE_ACTION("PostBeginImplFrameDeadlineTask", client); 427 EXPECT_SINGLE_ACTION("PostBeginImplFrameDeadlineTask", client);
491 client.Reset(); 428 client.Reset();
492 scheduler->OnBeginImplFrameDeadline(); 429 scheduler->OnBeginImplFrameDeadline();
493 EXPECT_SINGLE_ACTION("SetNeedsBeginImplFrame", client); 430 EXPECT_SINGLE_ACTION("SetNeedsBeginImplFrame", client);
494 EXPECT_FALSE(client.needs_begin_impl_frame()); 431 EXPECT_FALSE(client.needs_begin_impl_frame());
495 } 432 }
496 433
497 TEST(SchedulerTest, TextureAcquisitionCausesCommitInsteadOfDraw) { 434 TEST(SchedulerTest, TextureAcquisitionCollision) {
498 bool deadline_scheduling_enabled = false;
499 TextureAcquisitionCausesCommitInsteadOfDraw(deadline_scheduling_enabled);
500 }
501
502 TEST(SchedulerTest, TextureAcquisitionCausesCommitInsteadOfDraw_Deadline) {
503 bool deadline_scheduling_enabled = true;
504 TextureAcquisitionCausesCommitInsteadOfDraw(deadline_scheduling_enabled);
505 }
506
507 void TextureAcquisitionCollision(bool deadline_scheduling_enabled) {
508 FakeSchedulerClient client; 435 FakeSchedulerClient client;
509 SchedulerSettings scheduler_settings; 436 SchedulerSettings scheduler_settings;
510 scheduler_settings.deadline_scheduling_enabled = deadline_scheduling_enabled;
511 Scheduler* scheduler = client.CreateScheduler(scheduler_settings); 437 Scheduler* scheduler = client.CreateScheduler(scheduler_settings);
512 scheduler->SetCanStart(); 438 scheduler->SetCanStart();
513 scheduler->SetVisible(true); 439 scheduler->SetVisible(true);
514 scheduler->SetCanDraw(true); 440 scheduler->SetCanDraw(true);
515 441
516 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); 442 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client);
517 InitializeOutputSurfaceAndFirstCommit(scheduler); 443 InitializeOutputSurfaceAndFirstCommit(scheduler);
518 444
519 client.Reset(); 445 client.Reset();
520 scheduler->SetNeedsCommit(); 446 scheduler->SetNeedsCommit();
521 if (deadline_scheduling_enabled) { 447 EXPECT_SINGLE_ACTION("SetNeedsBeginImplFrame", client);
522 EXPECT_SINGLE_ACTION("SetNeedsBeginImplFrame", client);
523 } else {
524 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 0, 2);
525 EXPECT_ACTION("SetNeedsBeginImplFrame", client, 1, 2);
526 }
527 448
528 client.Reset(); 449 client.Reset();
529 scheduler->SetMainThreadNeedsLayerTextures(); 450 scheduler->SetMainThreadNeedsLayerTextures();
530 EXPECT_SINGLE_ACTION( 451 EXPECT_SINGLE_ACTION(
531 "ScheduledActionAcquireLayerTexturesForMainThread", client); 452 "ScheduledActionAcquireLayerTexturesForMainThread", client);
532 453
533 client.Reset(); 454 client.Reset();
534 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); 455 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting());
535 if (deadline_scheduling_enabled) { 456 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 0, 2);
536 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 0, 2); 457 EXPECT_ACTION("PostBeginImplFrameDeadlineTask", client, 1, 2);
537 EXPECT_ACTION("PostBeginImplFrameDeadlineTask", client, 1, 2);
538 } else {
539 EXPECT_SINGLE_ACTION("PostBeginImplFrameDeadlineTask", client);
540 }
541 458
542 client.Reset(); 459 client.Reset();
543 scheduler->OnBeginImplFrameDeadline(); 460 scheduler->OnBeginImplFrameDeadline();
544 EXPECT_SINGLE_ACTION("SetNeedsBeginImplFrame", client); 461 EXPECT_SINGLE_ACTION("SetNeedsBeginImplFrame", client);
545 462
546 // Although the compositor cannot draw because textures are locked by main 463 // Although the compositor cannot draw because textures are locked by main
547 // thread, we continue requesting SetNeedsBeginImplFrame in anticipation of 464 // thread, we continue requesting SetNeedsBeginImplFrame in anticipation of
548 // the unlock. 465 // the unlock.
549 EXPECT_TRUE(client.needs_begin_impl_frame()); 466 EXPECT_TRUE(client.needs_begin_impl_frame());
550 467
(...skipping 27 matching lines...) Expand all
578 EXPECT_SINGLE_ACTION("PostBeginImplFrameDeadlineTask", client); 495 EXPECT_SINGLE_ACTION("PostBeginImplFrameDeadlineTask", client);
579 client.Reset(); 496 client.Reset();
580 scheduler->OnBeginImplFrameDeadline(); 497 scheduler->OnBeginImplFrameDeadline();
581 EXPECT_SINGLE_ACTION("SetNeedsBeginImplFrame", client); 498 EXPECT_SINGLE_ACTION("SetNeedsBeginImplFrame", client);
582 EXPECT_FALSE(client.needs_begin_impl_frame()); 499 EXPECT_FALSE(client.needs_begin_impl_frame());
583 500
584 // The impl thread need an explicit commit from the main thread to lock 501 // The impl thread need an explicit commit from the main thread to lock
585 // the textures. 502 // the textures.
586 client.Reset(); 503 client.Reset();
587 scheduler->SetNeedsCommit(); 504 scheduler->SetNeedsCommit();
588 if (deadline_scheduling_enabled) { 505 EXPECT_SINGLE_ACTION("SetNeedsBeginImplFrame", client);
589 EXPECT_SINGLE_ACTION("SetNeedsBeginImplFrame", client);
590 } else {
591 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 0, 2);
592 EXPECT_ACTION("SetNeedsBeginImplFrame", client, 1, 2);
593 }
594 EXPECT_TRUE(client.needs_begin_impl_frame()); 506 EXPECT_TRUE(client.needs_begin_impl_frame());
595 507
596 client.Reset(); 508 client.Reset();
597 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); 509 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting());
598 if (deadline_scheduling_enabled) { 510 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 0, 2);
599 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 0, 2); 511 EXPECT_ACTION("PostBeginImplFrameDeadlineTask", client, 1, 2);
600 EXPECT_ACTION("PostBeginImplFrameDeadlineTask", client, 1, 2);
601 } else {
602 EXPECT_SINGLE_ACTION("PostBeginImplFrameDeadlineTask", client);
603 }
604 client.Reset(); 512 client.Reset();
605 513
606 // Trigger the commit, which will trigger the deadline task early. 514 // Trigger the commit, which will trigger the deadline task early.
607 scheduler->FinishCommit(); 515 scheduler->FinishCommit();
608 EXPECT_ACTION("ScheduledActionCommit", client, 0, 2); 516 EXPECT_ACTION("ScheduledActionCommit", client, 0, 2);
609 EXPECT_ACTION("PostBeginImplFrameDeadlineTask", client, 1, 2); 517 EXPECT_ACTION("PostBeginImplFrameDeadlineTask", client, 1, 2);
610 EXPECT_TRUE(client.needs_begin_impl_frame()); 518 EXPECT_TRUE(client.needs_begin_impl_frame());
611 client.Reset(); 519 client.Reset();
612 520
613 // Verify we draw on the next BeginImplFrame deadline 521 // Verify we draw on the next BeginImplFrame deadline
614 scheduler->OnBeginImplFrameDeadline(); 522 scheduler->OnBeginImplFrameDeadline();
615 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 2); 523 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 2);
616 EXPECT_ACTION("SetNeedsBeginImplFrame", client, 1, 2); 524 EXPECT_ACTION("SetNeedsBeginImplFrame", client, 1, 2);
617 EXPECT_TRUE(client.needs_begin_impl_frame()); 525 EXPECT_TRUE(client.needs_begin_impl_frame());
618 client.Reset(); 526 client.Reset();
619 } 527 }
620 528
621 TEST(SchedulerTest, TextureAcquisitionCollision) { 529 TEST(SchedulerTest, VisibilitySwitchWithTextureAcquisition) {
622 bool deadline_scheduling_enabled = false;
623 TextureAcquisitionCollision(deadline_scheduling_enabled);
624 }
625
626 TEST(SchedulerTest, TextureAcquisitionCollision_Deadline) {
627 bool deadline_scheduling_enabled = true;
628 TextureAcquisitionCollision(deadline_scheduling_enabled);
629 }
630
631 void VisibilitySwitchWithTextureAcquisition(bool deadline_scheduling_enabled) {
632 FakeSchedulerClient client; 530 FakeSchedulerClient client;
633 SchedulerSettings scheduler_settings; 531 SchedulerSettings scheduler_settings;
634 scheduler_settings.deadline_scheduling_enabled = deadline_scheduling_enabled;
635 Scheduler* scheduler = client.CreateScheduler(scheduler_settings); 532 Scheduler* scheduler = client.CreateScheduler(scheduler_settings);
636 scheduler->SetCanStart(); 533 scheduler->SetCanStart();
637 scheduler->SetVisible(true); 534 scheduler->SetVisible(true);
638 scheduler->SetCanDraw(true); 535 scheduler->SetCanDraw(true);
639 536
640 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); 537 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client);
641 client.Reset(); 538 client.Reset();
642 scheduler->DidCreateAndInitializeOutputSurface(); 539 scheduler->DidCreateAndInitializeOutputSurface();
643 540
644 scheduler->SetNeedsCommit(); 541 scheduler->SetNeedsCommit();
645 if (deadline_scheduling_enabled) { 542 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting());
646 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); 543 scheduler->OnBeginImplFrameDeadline();
647 scheduler->OnBeginImplFrameDeadline();
648 }
649 scheduler->FinishCommit(); 544 scheduler->FinishCommit();
650 scheduler->SetMainThreadNeedsLayerTextures(); 545 scheduler->SetMainThreadNeedsLayerTextures();
651 scheduler->SetNeedsCommit(); 546 scheduler->SetNeedsCommit();
652 client.Reset(); 547 client.Reset();
653 // Verify that pending texture acquisition fires when visibility 548 // Verify that pending texture acquisition fires when visibility
654 // is lost in order to avoid a deadlock. 549 // is lost in order to avoid a deadlock.
655 scheduler->SetVisible(false); 550 scheduler->SetVisible(false);
656 EXPECT_SINGLE_ACTION("ScheduledActionAcquireLayerTexturesForMainThread", 551 EXPECT_SINGLE_ACTION("ScheduledActionAcquireLayerTexturesForMainThread",
657 client); 552 client);
658 553
659 client.Reset(); 554 client.Reset();
660 scheduler->SetVisible(true); 555 scheduler->SetVisible(true);
661 EXPECT_EQ(0, client.num_actions_()); 556 EXPECT_EQ(0, client.num_actions_());
662 EXPECT_TRUE(client.needs_begin_impl_frame()); 557 EXPECT_TRUE(client.needs_begin_impl_frame());
663 558
664 // Regaining visibility with textures acquired by main thread while 559 // Regaining visibility with textures acquired by main thread while
665 // compositor is waiting for first draw should result in a request 560 // compositor is waiting for first draw should result in a request
666 // for a new frame in order to escape a deadlock. 561 // for a new frame in order to escape a deadlock.
667 client.Reset(); 562 client.Reset();
668 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); 563 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting());
669 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 0, 2); 564 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 0, 2);
670 EXPECT_ACTION("PostBeginImplFrameDeadlineTask", client, 1, 2); 565 EXPECT_ACTION("PostBeginImplFrameDeadlineTask", client, 1, 2);
671 } 566 }
672 567
673 TEST(SchedulerTest, VisibilitySwitchWithTextureAcquisition) {
674 bool deadline_scheduling_enabled = false;
675 VisibilitySwitchWithTextureAcquisition(deadline_scheduling_enabled);
676 }
677
678 TEST(SchedulerTest, VisibilitySwitchWithTextureAcquisition_Deadline) {
679 bool deadline_scheduling_enabled = true;
680 VisibilitySwitchWithTextureAcquisition(deadline_scheduling_enabled);
681 }
682
683 class SchedulerClientThatsetNeedsDrawInsideDraw : public FakeSchedulerClient { 568 class SchedulerClientThatsetNeedsDrawInsideDraw : public FakeSchedulerClient {
684 public: 569 public:
685 virtual void ScheduledActionSendBeginMainFrame() OVERRIDE {} 570 virtual void ScheduledActionSendBeginMainFrame() OVERRIDE {}
686 virtual DrawSwapReadbackResult ScheduledActionDrawAndSwapIfPossible() 571 virtual DrawSwapReadbackResult ScheduledActionDrawAndSwapIfPossible()
687 OVERRIDE { 572 OVERRIDE {
688 // Only SetNeedsRedraw the first time this is called 573 // Only SetNeedsRedraw the first time this is called
689 if (!num_draws_) 574 if (!num_draws_)
690 scheduler_->SetNeedsRedraw(); 575 scheduler_->SetNeedsRedraw();
691 return FakeSchedulerClient::ScheduledActionDrawAndSwapIfPossible(); 576 return FakeSchedulerClient::ScheduledActionDrawAndSwapIfPossible();
692 } 577 }
(...skipping 539 matching lines...) Expand 10 before | Expand all | Expand 10 after
1232 void MainFrameInHighLatencyMode(int64 begin_main_frame_to_commit_estimate_in_ms, 1117 void MainFrameInHighLatencyMode(int64 begin_main_frame_to_commit_estimate_in_ms,
1233 int64 commit_to_activate_estimate_in_ms, 1118 int64 commit_to_activate_estimate_in_ms,
1234 bool should_send_begin_main_frame) { 1119 bool should_send_begin_main_frame) {
1235 // Set up client with specified estimates (draw duration is set to 1). 1120 // Set up client with specified estimates (draw duration is set to 1).
1236 SchedulerClientWithFixedEstimates client( 1121 SchedulerClientWithFixedEstimates client(
1237 base::TimeDelta::FromMilliseconds(1), 1122 base::TimeDelta::FromMilliseconds(1),
1238 base::TimeDelta::FromMilliseconds( 1123 base::TimeDelta::FromMilliseconds(
1239 begin_main_frame_to_commit_estimate_in_ms), 1124 begin_main_frame_to_commit_estimate_in_ms),
1240 base::TimeDelta::FromMilliseconds(commit_to_activate_estimate_in_ms)); 1125 base::TimeDelta::FromMilliseconds(commit_to_activate_estimate_in_ms));
1241 SchedulerSettings scheduler_settings; 1126 SchedulerSettings scheduler_settings;
1242 scheduler_settings.deadline_scheduling_enabled = true;
1243 scheduler_settings.switch_to_low_latency_if_possible = true; 1127 scheduler_settings.switch_to_low_latency_if_possible = true;
1244 Scheduler* scheduler = client.CreateScheduler(scheduler_settings); 1128 Scheduler* scheduler = client.CreateScheduler(scheduler_settings);
1245 scheduler->SetCanStart(); 1129 scheduler->SetCanStart();
1246 scheduler->SetVisible(true); 1130 scheduler->SetVisible(true);
1247 scheduler->SetCanDraw(true); 1131 scheduler->SetCanDraw(true);
1248 InitializeOutputSurfaceAndFirstCommit(scheduler); 1132 InitializeOutputSurfaceAndFirstCommit(scheduler);
1249 1133
1250 // Impl thread hits deadline before commit finishes. 1134 // Impl thread hits deadline before commit finishes.
1251 client.Reset(); 1135 client.Reset();
1252 scheduler->SetNeedsCommit(); 1136 scheduler->SetNeedsCommit();
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
1338 SpinForMillis(interval * 2); 1222 SpinForMillis(interval * 2);
1339 EXPECT_GT(client.num_actions_(), actions_so_far); 1223 EXPECT_GT(client.num_actions_(), actions_so_far);
1340 EXPECT_STREQ(client.Action(client.num_actions_() - 1), 1224 EXPECT_STREQ(client.Action(client.num_actions_() - 1),
1341 "DidAnticipatedDrawTimeChange"); 1225 "DidAnticipatedDrawTimeChange");
1342 actions_so_far = client.num_actions_(); 1226 actions_so_far = client.num_actions_();
1343 } 1227 }
1344 } 1228 }
1345 1229
1346 } // namespace 1230 } // namespace
1347 } // namespace cc 1231 } // namespace cc
OLDNEW
« no previous file with comments | « cc/scheduler/scheduler_state_machine_unittest.cc ('k') | cc/trees/layer_tree_settings.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698