OLD | NEW |
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 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 states_.push_back(scheduler_->StateAsValue().release()); | 143 states_.push_back(scheduler_->StateAsValue().release()); |
144 } | 144 } |
145 virtual void ScheduledActionActivatePendingTree() OVERRIDE { | 145 virtual void ScheduledActionActivatePendingTree() OVERRIDE { |
146 actions_.push_back("ScheduledActionActivatePendingTree"); | 146 actions_.push_back("ScheduledActionActivatePendingTree"); |
147 states_.push_back(scheduler_->StateAsValue().release()); | 147 states_.push_back(scheduler_->StateAsValue().release()); |
148 } | 148 } |
149 virtual void ScheduledActionBeginOutputSurfaceCreation() OVERRIDE { | 149 virtual void ScheduledActionBeginOutputSurfaceCreation() OVERRIDE { |
150 actions_.push_back("ScheduledActionBeginOutputSurfaceCreation"); | 150 actions_.push_back("ScheduledActionBeginOutputSurfaceCreation"); |
151 states_.push_back(scheduler_->StateAsValue().release()); | 151 states_.push_back(scheduler_->StateAsValue().release()); |
152 } | 152 } |
153 virtual void ScheduledActionAcquireLayerTexturesForMainThread() OVERRIDE { | |
154 actions_.push_back("ScheduledActionAcquireLayerTexturesForMainThread"); | |
155 states_.push_back(scheduler_->StateAsValue().release()); | |
156 } | |
157 virtual void ScheduledActionManageTiles() OVERRIDE { | 153 virtual void ScheduledActionManageTiles() OVERRIDE { |
158 actions_.push_back("ScheduledActionManageTiles"); | 154 actions_.push_back("ScheduledActionManageTiles"); |
159 states_.push_back(scheduler_->StateAsValue().release()); | 155 states_.push_back(scheduler_->StateAsValue().release()); |
160 } | 156 } |
161 virtual void DidAnticipatedDrawTimeChange(base::TimeTicks) OVERRIDE { | 157 virtual void DidAnticipatedDrawTimeChange(base::TimeTicks) OVERRIDE { |
162 if (log_anticipated_draw_time_change_) | 158 if (log_anticipated_draw_time_change_) |
163 actions_.push_back("DidAnticipatedDrawTimeChange"); | 159 actions_.push_back("DidAnticipatedDrawTimeChange"); |
164 } | 160 } |
165 virtual base::TimeDelta DrawDurationEstimate() OVERRIDE { | 161 virtual base::TimeDelta DrawDurationEstimate() OVERRIDE { |
166 return base::TimeDelta(); | 162 return base::TimeDelta(); |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
359 client.Reset(); | 355 client.Reset(); |
360 | 356 |
361 // On the next BeginImplFrame, verify we go back to a quiescent state and | 357 // On the next BeginImplFrame, verify we go back to a quiescent state and |
362 // no longer request BeginImplFrames. | 358 // no longer request BeginImplFrames. |
363 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); | 359 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); |
364 scheduler->OnBeginImplFrameDeadline(); | 360 scheduler->OnBeginImplFrameDeadline(); |
365 EXPECT_FALSE(client.needs_begin_impl_frame()); | 361 EXPECT_FALSE(client.needs_begin_impl_frame()); |
366 client.Reset(); | 362 client.Reset(); |
367 } | 363 } |
368 | 364 |
369 TEST(SchedulerTest, TextureAcquisitionCausesCommitInsteadOfDraw) { | |
370 FakeSchedulerClient client; | |
371 SchedulerSettings scheduler_settings; | |
372 Scheduler* scheduler = client.CreateScheduler(scheduler_settings); | |
373 scheduler->SetCanStart(); | |
374 scheduler->SetVisible(true); | |
375 scheduler->SetCanDraw(true); | |
376 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); | |
377 | |
378 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | |
379 client.Reset(); | |
380 scheduler->SetNeedsRedraw(); | |
381 EXPECT_TRUE(scheduler->RedrawPending()); | |
382 EXPECT_SINGLE_ACTION("SetNeedsBeginImplFrame", client); | |
383 EXPECT_TRUE(client.needs_begin_impl_frame()); | |
384 | |
385 client.Reset(); | |
386 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); | |
387 EXPECT_EQ(client.num_actions_(), 0); | |
388 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | |
389 client.Reset(); | |
390 scheduler->OnBeginImplFrameDeadline(); | |
391 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 2); | |
392 EXPECT_ACTION("SetNeedsBeginImplFrame", client, 1, 2); | |
393 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | |
394 EXPECT_FALSE(scheduler->RedrawPending()); | |
395 EXPECT_TRUE(client.needs_begin_impl_frame()); | |
396 | |
397 client.Reset(); | |
398 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); | |
399 EXPECT_EQ(client.num_actions_(), 0); | |
400 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | |
401 client.Reset(); | |
402 scheduler->OnBeginImplFrameDeadline(); | |
403 EXPECT_SINGLE_ACTION("SetNeedsBeginImplFrame", client); | |
404 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | |
405 EXPECT_FALSE(scheduler->RedrawPending()); | |
406 EXPECT_FALSE(client.needs_begin_impl_frame()); | |
407 | |
408 client.Reset(); | |
409 scheduler->SetMainThreadNeedsLayerTextures(); | |
410 EXPECT_SINGLE_ACTION("ScheduledActionAcquireLayerTexturesForMainThread", | |
411 client); | |
412 | |
413 // We should request a BeginImplFrame in anticipation of a draw. | |
414 client.Reset(); | |
415 scheduler->SetNeedsRedraw(); | |
416 EXPECT_TRUE(scheduler->RedrawPending()); | |
417 EXPECT_SINGLE_ACTION("SetNeedsBeginImplFrame", client); | |
418 EXPECT_TRUE(client.needs_begin_impl_frame()); | |
419 | |
420 // No draw happens since the textures are acquired by the main thread. | |
421 client.Reset(); | |
422 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); | |
423 EXPECT_EQ(client.num_actions_(), 0); | |
424 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | |
425 client.Reset(); | |
426 scheduler->OnBeginImplFrameDeadline(); | |
427 EXPECT_SINGLE_ACTION("SetNeedsBeginImplFrame", client); | |
428 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | |
429 EXPECT_TRUE(scheduler->RedrawPending()); | |
430 EXPECT_TRUE(client.needs_begin_impl_frame()); | |
431 | |
432 client.Reset(); | |
433 scheduler->SetNeedsCommit(); | |
434 EXPECT_EQ(0, client.num_actions_()); | |
435 | |
436 client.Reset(); | |
437 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); | |
438 EXPECT_SINGLE_ACTION("ScheduledActionSendBeginMainFrame", client); | |
439 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | |
440 | |
441 // Commit will release the texture. | |
442 client.Reset(); | |
443 scheduler->NotifyBeginMainFrameStarted(); | |
444 scheduler->NotifyReadyToCommit(); | |
445 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); | |
446 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | |
447 EXPECT_TRUE(scheduler->RedrawPending()); | |
448 | |
449 // Now we can draw again after the commit happens. | |
450 client.Reset(); | |
451 scheduler->OnBeginImplFrameDeadline(); | |
452 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 2); | |
453 EXPECT_ACTION("SetNeedsBeginImplFrame", client, 1, 2); | |
454 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | |
455 EXPECT_FALSE(scheduler->RedrawPending()); | |
456 EXPECT_TRUE(client.needs_begin_impl_frame()); | |
457 | |
458 // Make sure we stop requesting BeginImplFrames if we don't swap. | |
459 client.Reset(); | |
460 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); | |
461 EXPECT_EQ(client.num_actions_(), 0); | |
462 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | |
463 client.Reset(); | |
464 scheduler->OnBeginImplFrameDeadline(); | |
465 EXPECT_SINGLE_ACTION("SetNeedsBeginImplFrame", client); | |
466 EXPECT_FALSE(client.needs_begin_impl_frame()); | |
467 } | |
468 | |
469 TEST(SchedulerTest, TextureAcquisitionCollision) { | |
470 FakeSchedulerClient client; | |
471 SchedulerSettings scheduler_settings; | |
472 Scheduler* scheduler = client.CreateScheduler(scheduler_settings); | |
473 scheduler->SetCanStart(); | |
474 scheduler->SetVisible(true); | |
475 scheduler->SetCanDraw(true); | |
476 | |
477 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); | |
478 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | |
479 | |
480 client.Reset(); | |
481 scheduler->SetNeedsCommit(); | |
482 EXPECT_SINGLE_ACTION("SetNeedsBeginImplFrame", client); | |
483 | |
484 client.Reset(); | |
485 scheduler->SetMainThreadNeedsLayerTextures(); | |
486 EXPECT_SINGLE_ACTION( | |
487 "ScheduledActionAcquireLayerTexturesForMainThread", client); | |
488 | |
489 client.Reset(); | |
490 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); | |
491 EXPECT_SINGLE_ACTION("ScheduledActionSendBeginMainFrame", client); | |
492 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | |
493 | |
494 client.Reset(); | |
495 scheduler->OnBeginImplFrameDeadline(); | |
496 EXPECT_SINGLE_ACTION("SetNeedsBeginImplFrame", client); | |
497 | |
498 // Although the compositor cannot draw because textures are locked by main | |
499 // thread, we continue requesting SetNeedsBeginImplFrame in anticipation of | |
500 // the unlock. | |
501 EXPECT_TRUE(client.needs_begin_impl_frame()); | |
502 | |
503 // Trigger the commit. | |
504 scheduler->NotifyBeginMainFrameStarted(); | |
505 scheduler->NotifyReadyToCommit(); | |
506 EXPECT_TRUE(client.needs_begin_impl_frame()); | |
507 | |
508 // Between commit and draw, texture acquisition for main thread delayed, | |
509 // and main thread blocks. | |
510 client.Reset(); | |
511 scheduler->SetMainThreadNeedsLayerTextures(); | |
512 EXPECT_EQ(0, client.num_actions_()); | |
513 | |
514 // No implicit commit is expected. | |
515 client.Reset(); | |
516 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); | |
517 EXPECT_EQ(client.num_actions_(), 0); | |
518 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | |
519 | |
520 client.Reset(); | |
521 scheduler->OnBeginImplFrameDeadline(); | |
522 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 3); | |
523 EXPECT_ACTION( | |
524 "ScheduledActionAcquireLayerTexturesForMainThread", client, 1, 3); | |
525 EXPECT_ACTION("SetNeedsBeginImplFrame", client, 2, 3); | |
526 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | |
527 EXPECT_TRUE(client.needs_begin_impl_frame()); | |
528 | |
529 // The compositor should not draw because textures are locked by main | |
530 // thread. | |
531 client.Reset(); | |
532 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); | |
533 EXPECT_EQ(client.num_actions_(), 0); | |
534 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | |
535 client.Reset(); | |
536 scheduler->OnBeginImplFrameDeadline(); | |
537 EXPECT_SINGLE_ACTION("SetNeedsBeginImplFrame", client); | |
538 EXPECT_FALSE(client.needs_begin_impl_frame()); | |
539 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | |
540 | |
541 // The impl thread need an explicit commit from the main thread to lock | |
542 // the textures. | |
543 client.Reset(); | |
544 scheduler->SetNeedsCommit(); | |
545 EXPECT_SINGLE_ACTION("SetNeedsBeginImplFrame", client); | |
546 EXPECT_TRUE(client.needs_begin_impl_frame()); | |
547 | |
548 client.Reset(); | |
549 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); | |
550 EXPECT_SINGLE_ACTION("ScheduledActionSendBeginMainFrame", client); | |
551 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | |
552 client.Reset(); | |
553 | |
554 // Trigger the commit, which will trigger the deadline task early. | |
555 scheduler->NotifyBeginMainFrameStarted(); | |
556 scheduler->NotifyReadyToCommit(); | |
557 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); | |
558 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | |
559 EXPECT_TRUE(client.needs_begin_impl_frame()); | |
560 client.Reset(); | |
561 | |
562 // Verify we draw on the next BeginImplFrame deadline | |
563 scheduler->OnBeginImplFrameDeadline(); | |
564 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 2); | |
565 EXPECT_ACTION("SetNeedsBeginImplFrame", client, 1, 2); | |
566 EXPECT_TRUE(client.needs_begin_impl_frame()); | |
567 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | |
568 client.Reset(); | |
569 } | |
570 | |
571 TEST(SchedulerTest, VisibilitySwitchWithTextureAcquisition) { | |
572 FakeSchedulerClient client; | |
573 SchedulerSettings scheduler_settings; | |
574 Scheduler* scheduler = client.CreateScheduler(scheduler_settings); | |
575 scheduler->SetCanStart(); | |
576 scheduler->SetVisible(true); | |
577 scheduler->SetCanDraw(true); | |
578 | |
579 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); | |
580 client.Reset(); | |
581 scheduler->DidCreateAndInitializeOutputSurface(); | |
582 | |
583 scheduler->SetNeedsCommit(); | |
584 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); | |
585 scheduler->OnBeginImplFrameDeadline(); | |
586 scheduler->NotifyBeginMainFrameStarted(); | |
587 scheduler->NotifyReadyToCommit(); | |
588 scheduler->SetMainThreadNeedsLayerTextures(); | |
589 scheduler->SetNeedsCommit(); | |
590 client.Reset(); | |
591 // Verify that pending texture acquisition fires when visibility | |
592 // is lost in order to avoid a deadlock. | |
593 scheduler->SetVisible(false); | |
594 EXPECT_SINGLE_ACTION("ScheduledActionAcquireLayerTexturesForMainThread", | |
595 client); | |
596 | |
597 client.Reset(); | |
598 scheduler->SetVisible(true); | |
599 EXPECT_EQ(0, client.num_actions_()); | |
600 EXPECT_TRUE(client.needs_begin_impl_frame()); | |
601 | |
602 // Regaining visibility with textures acquired by main thread while | |
603 // compositor is waiting for first draw should result in a request | |
604 // for a new frame in order to escape a deadlock. | |
605 client.Reset(); | |
606 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); | |
607 EXPECT_SINGLE_ACTION("ScheduledActionSendBeginMainFrame", client); | |
608 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | |
609 } | |
610 | |
611 class SchedulerClientThatsetNeedsDrawInsideDraw : public FakeSchedulerClient { | 365 class SchedulerClientThatsetNeedsDrawInsideDraw : public FakeSchedulerClient { |
612 public: | 366 public: |
613 virtual void ScheduledActionSendBeginMainFrame() OVERRIDE {} | 367 virtual void ScheduledActionSendBeginMainFrame() OVERRIDE {} |
614 virtual DrawSwapReadbackResult ScheduledActionDrawAndSwapIfPossible() | 368 virtual DrawSwapReadbackResult ScheduledActionDrawAndSwapIfPossible() |
615 OVERRIDE { | 369 OVERRIDE { |
616 // Only SetNeedsRedraw the first time this is called | 370 // Only SetNeedsRedraw the first time this is called |
617 if (!num_draws_) | 371 if (!num_draws_) |
618 scheduler_->SetNeedsRedraw(); | 372 scheduler_->SetNeedsRedraw(); |
619 return FakeSchedulerClient::ScheduledActionDrawAndSwapIfPossible(); | 373 return FakeSchedulerClient::ScheduledActionDrawAndSwapIfPossible(); |
620 } | 374 } |
(...skipping 709 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1330 client.task_runner().RunPendingTasks(); | 1084 client.task_runner().RunPendingTasks(); |
1331 EXPECT_GT(client.num_actions_(), actions_so_far); | 1085 EXPECT_GT(client.num_actions_(), actions_so_far); |
1332 EXPECT_STREQ(client.Action(client.num_actions_() - 1), | 1086 EXPECT_STREQ(client.Action(client.num_actions_() - 1), |
1333 "DidAnticipatedDrawTimeChange"); | 1087 "DidAnticipatedDrawTimeChange"); |
1334 actions_so_far = client.num_actions_(); | 1088 actions_so_far = client.num_actions_(); |
1335 } | 1089 } |
1336 } | 1090 } |
1337 | 1091 |
1338 } // namespace | 1092 } // namespace |
1339 } // namespace cc | 1093 } // namespace cc |
OLD | NEW |