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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 scheduler_ = Scheduler::Create(this, settings); | 59 scheduler_ = Scheduler::Create(this, settings); |
60 return scheduler_.get(); | 60 return scheduler_.get(); |
61 } | 61 } |
62 | 62 |
63 bool needs_begin_frame() { return needs_begin_frame_; } | 63 bool needs_begin_frame() { return needs_begin_frame_; } |
64 int num_draws() const { return num_draws_; } | 64 int num_draws() const { return num_draws_; } |
65 int num_actions_() const { return static_cast<int>(actions_.size()); } | 65 int num_actions_() const { return static_cast<int>(actions_.size()); } |
66 const char* Action(int i) const { return actions_[i]; } | 66 const char* Action(int i) const { return actions_[i]; } |
67 base::Value& StateForAction(int i) const { return *states_[i]; } | 67 base::Value& StateForAction(int i) const { return *states_[i]; } |
68 | 68 |
69 bool HasAction(const char* action) const { | 69 int ActionIndex(const char* action) const { |
70 for (size_t i = 0; i < actions_.size(); i++) | 70 for (size_t i = 0; i < actions_.size(); i++) |
71 if (!strcmp(actions_[i], action)) | 71 if (!strcmp(actions_[i], action)) |
72 return true; | 72 return i; |
73 return false; | 73 return -1; |
| 74 } |
| 75 |
| 76 bool HasAction(const char* action) const { |
| 77 return ActionIndex(action) >= 0; |
74 } | 78 } |
75 | 79 |
76 void SetDrawWillHappen(bool draw_will_happen) { | 80 void SetDrawWillHappen(bool draw_will_happen) { |
77 draw_will_happen_ = draw_will_happen; | 81 draw_will_happen_ = draw_will_happen; |
78 } | 82 } |
79 void SetSwapWillHappenIfDrawHappens(bool swap_will_happen_if_draw_happens) { | 83 void SetSwapWillHappenIfDrawHappens(bool swap_will_happen_if_draw_happens) { |
80 swap_will_happen_if_draw_happens_ = swap_will_happen_if_draw_happens; | 84 swap_will_happen_if_draw_happens_ = swap_will_happen_if_draw_happens; |
81 } | 85 } |
82 | 86 |
83 // Scheduler Implementation. | 87 // Scheduler Implementation. |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 states_.push_back(scheduler_->StateAsValue().release()); | 134 states_.push_back(scheduler_->StateAsValue().release()); |
131 } | 135 } |
132 virtual void ScheduledActionBeginOutputSurfaceCreation() OVERRIDE { | 136 virtual void ScheduledActionBeginOutputSurfaceCreation() OVERRIDE { |
133 actions_.push_back("ScheduledActionBeginOutputSurfaceCreation"); | 137 actions_.push_back("ScheduledActionBeginOutputSurfaceCreation"); |
134 states_.push_back(scheduler_->StateAsValue().release()); | 138 states_.push_back(scheduler_->StateAsValue().release()); |
135 } | 139 } |
136 virtual void ScheduledActionAcquireLayerTexturesForMainThread() OVERRIDE { | 140 virtual void ScheduledActionAcquireLayerTexturesForMainThread() OVERRIDE { |
137 actions_.push_back("ScheduledActionAcquireLayerTexturesForMainThread"); | 141 actions_.push_back("ScheduledActionAcquireLayerTexturesForMainThread"); |
138 states_.push_back(scheduler_->StateAsValue().release()); | 142 states_.push_back(scheduler_->StateAsValue().release()); |
139 } | 143 } |
| 144 virtual void ScheduledActionManageTiles() OVERRIDE { |
| 145 actions_.push_back("ScheduledActionManageTiles"); |
| 146 states_.push_back(scheduler_->StateAsValue().release()); |
| 147 } |
140 virtual void DidAnticipatedDrawTimeChange(base::TimeTicks) OVERRIDE {} | 148 virtual void DidAnticipatedDrawTimeChange(base::TimeTicks) OVERRIDE {} |
141 virtual base::TimeDelta DrawDurationEstimate() OVERRIDE { | 149 virtual base::TimeDelta DrawDurationEstimate() OVERRIDE { |
142 return base::TimeDelta(); | 150 return base::TimeDelta(); |
143 } | 151 } |
144 virtual base::TimeDelta BeginFrameToCommitDurationEstimate() OVERRIDE { | 152 virtual base::TimeDelta BeginFrameToCommitDurationEstimate() OVERRIDE { |
145 return base::TimeDelta(); | 153 return base::TimeDelta(); |
146 } | 154 } |
147 virtual base::TimeDelta CommitToActivateDurationEstimate() OVERRIDE { | 155 virtual base::TimeDelta CommitToActivateDurationEstimate() OVERRIDE { |
148 return base::TimeDelta(); | 156 return base::TimeDelta(); |
149 } | 157 } |
(...skipping 530 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
680 client.Reset(); | 688 client.Reset(); |
681 scheduler->SetNeedsForcedCommitForReadback(); | 689 scheduler->SetNeedsForcedCommitForReadback(); |
682 scheduler->FinishCommit(); | 690 scheduler->FinishCommit(); |
683 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndReadback")); | 691 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndReadback")); |
684 | 692 |
685 // The replacement commit comes in after 2 readbacks. | 693 // The replacement commit comes in after 2 readbacks. |
686 client.Reset(); | 694 client.Reset(); |
687 scheduler->FinishCommit(); | 695 scheduler->FinishCommit(); |
688 } | 696 } |
689 | 697 |
| 698 |
| 699 class SchedulerClientNeedsManageTilesInDraw : public FakeSchedulerClient { |
| 700 public: |
| 701 virtual DrawSwapReadbackResult ScheduledActionDrawAndSwapIfPossible() |
| 702 OVERRIDE { |
| 703 scheduler_->SetNeedsManageTiles(); |
| 704 return FakeSchedulerClient::ScheduledActionDrawAndSwapIfPossible(); |
| 705 } |
| 706 }; |
| 707 |
| 708 // Test manage tiles is independant of draws. |
| 709 TEST(SchedulerTest, ManageTiles) { |
| 710 SchedulerClientNeedsManageTilesInDraw client; |
| 711 SchedulerSettings default_scheduler_settings; |
| 712 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings); |
| 713 scheduler->SetCanStart(); |
| 714 scheduler->SetVisible(true); |
| 715 scheduler->SetCanDraw(true); |
| 716 InitializeOutputSurfaceAndFirstCommit(scheduler); |
| 717 |
| 718 // Request both draw and manage tiles. ManageTiles shouldn't |
| 719 // be trigged until BeginFrame. |
| 720 client.Reset(); |
| 721 scheduler->SetNeedsManageTiles(); |
| 722 scheduler->SetNeedsRedraw(); |
| 723 EXPECT_TRUE(scheduler->RedrawPending()); |
| 724 EXPECT_TRUE(scheduler->ManageTilesPending()); |
| 725 EXPECT_TRUE(client.needs_begin_frame()); |
| 726 EXPECT_EQ(0, client.num_draws()); |
| 727 EXPECT_FALSE(client.HasAction("ScheduledActionManageTiles")); |
| 728 EXPECT_FALSE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); |
| 729 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| 730 // The actions should have occured, in the right order. |
| 731 EXPECT_EQ(1, client.num_draws()); |
| 732 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); |
| 733 EXPECT_TRUE(client.HasAction("ScheduledActionManageTiles")); |
| 734 EXPECT_LT(client.ActionIndex("ScheduledActionDrawAndSwapIfPossible"), |
| 735 client.ActionIndex("ScheduledActionManageTiles")); |
| 736 EXPECT_FALSE(scheduler->RedrawPending()); |
| 737 EXPECT_FALSE(scheduler->ManageTilesPending()); |
| 738 |
| 739 // Request a draw. We don't need a ManageTiles yet. |
| 740 client.Reset(); |
| 741 scheduler->SetNeedsRedraw(); |
| 742 EXPECT_TRUE(scheduler->RedrawPending()); |
| 743 EXPECT_FALSE(scheduler->ManageTilesPending()); |
| 744 EXPECT_TRUE(client.needs_begin_frame()); |
| 745 EXPECT_EQ(0, client.num_draws()); |
| 746 |
| 747 // Draw. The draw will trigger SetNeedsManageTiles, and |
| 748 // then the ManageTiles action will be triggered after the Draw. |
| 749 // Afterwards, neither a draw nor ManageTiles are pending. |
| 750 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| 751 EXPECT_EQ(1, client.num_draws()); |
| 752 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); |
| 753 EXPECT_TRUE(client.HasAction("ScheduledActionManageTiles")); |
| 754 EXPECT_LT(client.ActionIndex("ScheduledActionDrawAndSwapIfPossible"), |
| 755 client.ActionIndex("ScheduledActionManageTiles")); |
| 756 EXPECT_FALSE(scheduler->RedrawPending()); |
| 757 EXPECT_FALSE(scheduler->ManageTilesPending()); |
| 758 |
| 759 // Now trigger a ManageTiles outside of a draw. We will then need |
| 760 // a begin-frame for the ManageTiles, but we don't need a draw. |
| 761 client.Reset(); |
| 762 EXPECT_FALSE(client.needs_begin_frame()); |
| 763 scheduler->SetNeedsManageTiles(); |
| 764 EXPECT_TRUE(client.needs_begin_frame()); |
| 765 EXPECT_TRUE(scheduler->ManageTilesPending()); |
| 766 EXPECT_FALSE(scheduler->RedrawPending()); |
| 767 |
| 768 // BeginFrame. There will be no draw, only ManageTiles. |
| 769 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| 770 EXPECT_EQ(0, client.num_draws()); |
| 771 EXPECT_FALSE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); |
| 772 EXPECT_TRUE(client.HasAction("ScheduledActionManageTiles")); |
| 773 } |
| 774 |
690 } // namespace | 775 } // namespace |
691 } // namespace cc | 776 } // namespace cc |
OLD | NEW |