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 | 4 |
5 #include "cc/scheduler/scheduler.h" | 5 #include "cc/scheduler/scheduler.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 // Scheduler Implementation. | 83 // Scheduler Implementation. |
84 virtual void SetNeedsBeginFrameOnImplThread(bool enable) OVERRIDE { | 84 virtual void SetNeedsBeginFrameOnImplThread(bool enable) OVERRIDE { |
85 actions_.push_back("SetNeedsBeginFrameOnImplThread"); | 85 actions_.push_back("SetNeedsBeginFrameOnImplThread"); |
86 states_.push_back(scheduler_->StateAsValueForTesting().release()); | 86 states_.push_back(scheduler_->StateAsValueForTesting().release()); |
87 needs_begin_frame_ = enable; | 87 needs_begin_frame_ = enable; |
88 } | 88 } |
89 virtual void ScheduledActionSendBeginFrameToMainThread() OVERRIDE { | 89 virtual void ScheduledActionSendBeginFrameToMainThread() OVERRIDE { |
90 actions_.push_back("ScheduledActionSendBeginFrameToMainThread"); | 90 actions_.push_back("ScheduledActionSendBeginFrameToMainThread"); |
91 states_.push_back(scheduler_->StateAsValueForTesting().release()); | 91 states_.push_back(scheduler_->StateAsValueForTesting().release()); |
92 } | 92 } |
93 virtual ScheduledActionDrawAndSwapResult | 93 virtual DrawSwapReadbackResult ScheduledActionDrawAndSwapIfPossible() |
94 ScheduledActionDrawAndSwapIfPossible() OVERRIDE { | 94 OVERRIDE { |
95 actions_.push_back("ScheduledActionDrawAndSwapIfPossible"); | 95 actions_.push_back("ScheduledActionDrawAndSwapIfPossible"); |
96 states_.push_back(scheduler_->StateAsValueForTesting().release()); | 96 states_.push_back(scheduler_->StateAsValueForTesting().release()); |
97 num_draws_++; | 97 num_draws_++; |
98 return ScheduledActionDrawAndSwapResult(draw_will_happen_, | 98 bool did_readback = false; |
99 draw_will_happen_ && | 99 return DrawSwapReadbackResult( |
100 swap_will_happen_if_draw_happens_); | 100 draw_will_happen_, |
| 101 draw_will_happen_ && swap_will_happen_if_draw_happens_, |
| 102 did_readback); |
101 } | 103 } |
102 virtual ScheduledActionDrawAndSwapResult ScheduledActionDrawAndSwapForced() | 104 virtual DrawSwapReadbackResult ScheduledActionDrawAndSwapForced() OVERRIDE { |
103 OVERRIDE { | |
104 actions_.push_back("ScheduledActionDrawAndSwapForced"); | 105 actions_.push_back("ScheduledActionDrawAndSwapForced"); |
105 states_.push_back(scheduler_->StateAsValueForTesting().release()); | 106 states_.push_back(scheduler_->StateAsValueForTesting().release()); |
106 return ScheduledActionDrawAndSwapResult(true, | 107 bool did_draw = true; |
107 swap_will_happen_if_draw_happens_); | 108 bool did_swap = swap_will_happen_if_draw_happens_; |
| 109 bool did_readback = false; |
| 110 return DrawSwapReadbackResult(did_draw, did_swap, did_readback); |
| 111 } |
| 112 virtual DrawSwapReadbackResult ScheduledActionDrawAndReadback() OVERRIDE { |
| 113 actions_.push_back("ScheduledActionDrawAndReadback"); |
| 114 states_.push_back(scheduler_->StateAsValueForTesting().release()); |
| 115 bool did_draw = true; |
| 116 bool did_swap = false; |
| 117 bool did_readback = true; |
| 118 return DrawSwapReadbackResult(did_draw, did_swap, did_readback); |
108 } | 119 } |
109 virtual void ScheduledActionCommit() OVERRIDE { | 120 virtual void ScheduledActionCommit() OVERRIDE { |
110 actions_.push_back("ScheduledActionCommit"); | 121 actions_.push_back("ScheduledActionCommit"); |
111 states_.push_back(scheduler_->StateAsValueForTesting().release()); | 122 states_.push_back(scheduler_->StateAsValueForTesting().release()); |
112 } | 123 } |
113 virtual void ScheduledActionUpdateVisibleTiles() OVERRIDE { | 124 virtual void ScheduledActionUpdateVisibleTiles() OVERRIDE { |
114 actions_.push_back("ScheduledActionUpdateVisibleTiles"); | 125 actions_.push_back("ScheduledActionUpdateVisibleTiles"); |
115 states_.push_back(scheduler_->StateAsValueForTesting().release()); | 126 states_.push_back(scheduler_->StateAsValueForTesting().release()); |
116 } | 127 } |
117 virtual void ScheduledActionActivatePendingTree() OVERRIDE { | 128 virtual void ScheduledActionActivatePendingTree() OVERRIDE { |
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
392 // compositor is waiting for first draw should result in a request | 403 // compositor is waiting for first draw should result in a request |
393 // for a new frame in order to escape a deadlock. | 404 // for a new frame in order to escape a deadlock. |
394 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); | 405 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
395 EXPECT_ACTION("ScheduledActionSendBeginFrameToMainThread", client, 0, 2); | 406 EXPECT_ACTION("ScheduledActionSendBeginFrameToMainThread", client, 0, 2); |
396 EXPECT_ACTION("SetNeedsBeginFrameOnImplThread", client, 1, 2); | 407 EXPECT_ACTION("SetNeedsBeginFrameOnImplThread", client, 1, 2); |
397 } | 408 } |
398 | 409 |
399 class SchedulerClientThatsetNeedsDrawInsideDraw : public FakeSchedulerClient { | 410 class SchedulerClientThatsetNeedsDrawInsideDraw : public FakeSchedulerClient { |
400 public: | 411 public: |
401 virtual void ScheduledActionSendBeginFrameToMainThread() OVERRIDE {} | 412 virtual void ScheduledActionSendBeginFrameToMainThread() OVERRIDE {} |
402 virtual ScheduledActionDrawAndSwapResult | 413 virtual DrawSwapReadbackResult ScheduledActionDrawAndSwapIfPossible() |
403 ScheduledActionDrawAndSwapIfPossible() OVERRIDE { | 414 OVERRIDE { |
404 // Only SetNeedsRedraw the first time this is called | 415 // Only SetNeedsRedraw the first time this is called |
405 if (!num_draws_) | 416 if (!num_draws_) |
406 scheduler_->SetNeedsRedraw(); | 417 scheduler_->SetNeedsRedraw(); |
407 return FakeSchedulerClient::ScheduledActionDrawAndSwapIfPossible(); | 418 return FakeSchedulerClient::ScheduledActionDrawAndSwapIfPossible(); |
408 } | 419 } |
409 | 420 |
410 virtual ScheduledActionDrawAndSwapResult ScheduledActionDrawAndSwapForced() | 421 virtual DrawSwapReadbackResult ScheduledActionDrawAndSwapForced() OVERRIDE { |
411 OVERRIDE { | |
412 NOTREACHED(); | 422 NOTREACHED(); |
413 return ScheduledActionDrawAndSwapResult(true, true); | 423 bool did_draw = true; |
| 424 bool did_swap = true; |
| 425 bool did_readback = false; |
| 426 return DrawSwapReadbackResult(did_draw, did_swap, did_readback); |
414 } | 427 } |
415 | 428 |
416 virtual void ScheduledActionCommit() OVERRIDE {} | 429 virtual void ScheduledActionCommit() OVERRIDE {} |
417 virtual void ScheduledActionBeginOutputSurfaceCreation() OVERRIDE {} | 430 virtual void ScheduledActionBeginOutputSurfaceCreation() OVERRIDE {} |
418 virtual void DidAnticipatedDrawTimeChange(base::TimeTicks) OVERRIDE {} | 431 virtual void DidAnticipatedDrawTimeChange(base::TimeTicks) OVERRIDE {} |
419 }; | 432 }; |
420 | 433 |
421 // Tests for two different situations: | 434 // Tests for two different situations: |
422 // 1. the scheduler dropping SetNeedsRedraw requests that happen inside | 435 // 1. the scheduler dropping SetNeedsRedraw requests that happen inside |
423 // a ScheduledActionDrawAndSwap | 436 // a ScheduledActionDrawAndSwap |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
491 EXPECT_FALSE(scheduler->RedrawPending()); | 504 EXPECT_FALSE(scheduler->RedrawPending()); |
492 EXPECT_TRUE(client.needs_begin_frame()); | 505 EXPECT_TRUE(client.needs_begin_frame()); |
493 } | 506 } |
494 | 507 |
495 class SchedulerClientThatSetNeedsCommitInsideDraw : public FakeSchedulerClient { | 508 class SchedulerClientThatSetNeedsCommitInsideDraw : public FakeSchedulerClient { |
496 public: | 509 public: |
497 SchedulerClientThatSetNeedsCommitInsideDraw() | 510 SchedulerClientThatSetNeedsCommitInsideDraw() |
498 : set_needs_commit_on_next_draw_(false) {} | 511 : set_needs_commit_on_next_draw_(false) {} |
499 | 512 |
500 virtual void ScheduledActionSendBeginFrameToMainThread() OVERRIDE {} | 513 virtual void ScheduledActionSendBeginFrameToMainThread() OVERRIDE {} |
501 virtual ScheduledActionDrawAndSwapResult | 514 virtual DrawSwapReadbackResult ScheduledActionDrawAndSwapIfPossible() |
502 ScheduledActionDrawAndSwapIfPossible() OVERRIDE { | 515 OVERRIDE { |
503 // Only SetNeedsCommit the first time this is called | 516 // Only SetNeedsCommit the first time this is called |
504 if (set_needs_commit_on_next_draw_) { | 517 if (set_needs_commit_on_next_draw_) { |
505 scheduler_->SetNeedsCommit(); | 518 scheduler_->SetNeedsCommit(); |
506 set_needs_commit_on_next_draw_ = false; | 519 set_needs_commit_on_next_draw_ = false; |
507 } | 520 } |
508 return FakeSchedulerClient::ScheduledActionDrawAndSwapIfPossible(); | 521 return FakeSchedulerClient::ScheduledActionDrawAndSwapIfPossible(); |
509 } | 522 } |
510 | 523 |
511 virtual ScheduledActionDrawAndSwapResult ScheduledActionDrawAndSwapForced() | 524 virtual DrawSwapReadbackResult ScheduledActionDrawAndSwapForced() OVERRIDE { |
512 OVERRIDE { | |
513 NOTREACHED(); | 525 NOTREACHED(); |
514 return ScheduledActionDrawAndSwapResult(true, true); | 526 bool did_draw = true; |
| 527 bool did_swap = false; |
| 528 bool did_readback = false; |
| 529 return DrawSwapReadbackResult(did_draw, did_swap, did_readback); |
515 } | 530 } |
516 | 531 |
517 virtual void ScheduledActionCommit() OVERRIDE {} | 532 virtual void ScheduledActionCommit() OVERRIDE {} |
518 virtual void ScheduledActionBeginOutputSurfaceCreation() OVERRIDE {} | 533 virtual void ScheduledActionBeginOutputSurfaceCreation() OVERRIDE {} |
519 virtual void DidAnticipatedDrawTimeChange(base::TimeTicks) OVERRIDE {} | 534 virtual void DidAnticipatedDrawTimeChange(base::TimeTicks) OVERRIDE {} |
520 | 535 |
521 void SetNeedsCommitOnNextDraw() { set_needs_commit_on_next_draw_ = true; } | 536 void SetNeedsCommitOnNextDraw() { set_needs_commit_on_next_draw_ = true; } |
522 | 537 |
523 private: | 538 private: |
524 bool set_needs_commit_on_next_draw_; | 539 bool set_needs_commit_on_next_draw_; |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
632 | 647 |
633 TEST(SchedulerTest, NoSwapWhenSwapFailsDuringForcedCommit) { | 648 TEST(SchedulerTest, NoSwapWhenSwapFailsDuringForcedCommit) { |
634 FakeSchedulerClient client; | 649 FakeSchedulerClient client; |
635 SchedulerSettings default_scheduler_settings; | 650 SchedulerSettings default_scheduler_settings; |
636 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings); | 651 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings); |
637 | 652 |
638 // Tell the client that it will fail to swap. | 653 // Tell the client that it will fail to swap. |
639 client.SetDrawWillHappen(true); | 654 client.SetDrawWillHappen(true); |
640 client.SetSwapWillHappenIfDrawHappens(false); | 655 client.SetSwapWillHappenIfDrawHappens(false); |
641 | 656 |
642 // Get the compositor to do a ScheduledActionDrawAndSwapForced. | 657 // Get the compositor to do a ScheduledActionDrawAndReadback. |
643 scheduler->SetCanDraw(true); | 658 scheduler->SetCanDraw(true); |
644 scheduler->SetNeedsRedraw(); | 659 scheduler->SetNeedsRedraw(); |
645 scheduler->SetNeedsForcedRedraw(); | 660 scheduler->SetNeedsForcedCommitForReadback(); |
646 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapForced")); | 661 scheduler->FinishCommit(); |
| 662 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndReadback")); |
| 663 } |
| 664 |
| 665 TEST(SchedulerTest, BackToBackReadbackAllowed) { |
| 666 // Some clients call readbacks twice in a row before the replacement |
| 667 // commit comes in. Make sure it is allowed. |
| 668 FakeSchedulerClient client; |
| 669 SchedulerSettings default_scheduler_settings; |
| 670 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings); |
| 671 |
| 672 // Get the compositor to do 2 ScheduledActionDrawAndReadbacks before |
| 673 // the replacement commit comes in. |
| 674 scheduler->SetCanDraw(true); |
| 675 scheduler->SetNeedsRedraw(); |
| 676 scheduler->SetNeedsForcedCommitForReadback(); |
| 677 scheduler->FinishCommit(); |
| 678 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndReadback")); |
| 679 |
| 680 client.Reset(); |
| 681 scheduler->SetNeedsForcedCommitForReadback(); |
| 682 scheduler->FinishCommit(); |
| 683 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndReadback")); |
| 684 |
| 685 // The replacement commit comes in after 2 readbacks. |
| 686 client.Reset(); |
| 687 scheduler->FinishCommit(); |
647 } | 688 } |
648 | 689 |
649 } // namespace | 690 } // namespace |
650 } // namespace cc | 691 } // namespace cc |
OLD | NEW |