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 22 matching lines...) Expand all Loading... |
33 namespace cc { | 33 namespace cc { |
34 namespace { | 34 namespace { |
35 | 35 |
36 class FakeSchedulerClient; | 36 class FakeSchedulerClient; |
37 | 37 |
38 void InitializeOutputSurfaceAndFirstCommit(Scheduler* scheduler, | 38 void InitializeOutputSurfaceAndFirstCommit(Scheduler* scheduler, |
39 FakeSchedulerClient* client); | 39 FakeSchedulerClient* client); |
40 | 40 |
41 class FakeSchedulerClient : public SchedulerClient { | 41 class FakeSchedulerClient : public SchedulerClient { |
42 public: | 42 public: |
43 FakeSchedulerClient() : needs_begin_frame_(false), automatic_swap_ack_(true) { | 43 FakeSchedulerClient() |
| 44 : needs_begin_frame_(false), |
| 45 automatic_swap_ack_(true), |
| 46 swap_contains_incomplete_tile_(false), |
| 47 redraw_will_happen_if_update_visible_tiles_happens_(false) { |
44 Reset(); | 48 Reset(); |
45 } | 49 } |
46 | 50 |
47 void Reset() { | 51 void Reset() { |
48 actions_.clear(); | 52 actions_.clear(); |
49 states_.clear(); | 53 states_.clear(); |
50 draw_will_happen_ = true; | 54 draw_will_happen_ = true; |
51 swap_will_happen_if_draw_happens_ = true; | 55 swap_will_happen_if_draw_happens_ = true; |
52 num_draws_ = 0; | 56 num_draws_ = 0; |
53 log_anticipated_draw_time_change_ = false; | 57 log_anticipated_draw_time_change_ = false; |
(...skipping 21 matching lines...) Expand all Loading... |
75 | 79 |
76 base::TestSimpleTaskRunner& task_runner() { return *task_runner_; } | 80 base::TestSimpleTaskRunner& task_runner() { return *task_runner_; } |
77 | 81 |
78 int ActionIndex(const char* action) const { | 82 int ActionIndex(const char* action) const { |
79 for (size_t i = 0; i < actions_.size(); i++) | 83 for (size_t i = 0; i < actions_.size(); i++) |
80 if (!strcmp(actions_[i], action)) | 84 if (!strcmp(actions_[i], action)) |
81 return i; | 85 return i; |
82 return -1; | 86 return -1; |
83 } | 87 } |
84 | 88 |
| 89 void SetSwapContainsIncompleteTile(bool contain) { |
| 90 swap_contains_incomplete_tile_ = contain; |
| 91 } |
| 92 |
85 bool HasAction(const char* action) const { | 93 bool HasAction(const char* action) const { |
86 return ActionIndex(action) >= 0; | 94 return ActionIndex(action) >= 0; |
87 } | 95 } |
88 | 96 |
89 void SetDrawWillHappen(bool draw_will_happen) { | 97 void SetDrawWillHappen(bool draw_will_happen) { |
90 draw_will_happen_ = draw_will_happen; | 98 draw_will_happen_ = draw_will_happen; |
91 } | 99 } |
92 void SetSwapWillHappenIfDrawHappens(bool swap_will_happen_if_draw_happens) { | 100 void SetSwapWillHappenIfDrawHappens(bool swap_will_happen_if_draw_happens) { |
93 swap_will_happen_if_draw_happens_ = swap_will_happen_if_draw_happens; | 101 swap_will_happen_if_draw_happens_ = swap_will_happen_if_draw_happens; |
94 } | 102 } |
95 void SetAutomaticSwapAck(bool automatic_swap_ack) { | 103 void SetAutomaticSwapAck(bool automatic_swap_ack) { |
96 automatic_swap_ack_ = automatic_swap_ack; | 104 automatic_swap_ack_ = automatic_swap_ack; |
97 } | 105 } |
98 | 106 void SetRedrawWillHappenIfUpdateVisibleTilesHappens(bool redraw) { |
| 107 redraw_will_happen_if_update_visible_tiles_happens_ = redraw; |
| 108 } |
99 // SchedulerClient implementation. | 109 // SchedulerClient implementation. |
100 virtual void SetNeedsBeginFrame(bool enable) OVERRIDE { | 110 virtual void SetNeedsBeginFrame(bool enable) OVERRIDE { |
101 actions_.push_back("SetNeedsBeginFrame"); | 111 actions_.push_back("SetNeedsBeginFrame"); |
102 states_.push_back(scheduler_->AsValue().release()); | 112 states_.push_back(scheduler_->AsValue().release()); |
103 needs_begin_frame_ = enable; | 113 needs_begin_frame_ = enable; |
104 } | 114 } |
105 virtual void WillBeginImplFrame(const BeginFrameArgs& args) OVERRIDE { | 115 virtual void WillBeginImplFrame(const BeginFrameArgs& args) OVERRIDE { |
106 actions_.push_back("WillBeginImplFrame"); | 116 actions_.push_back("WillBeginImplFrame"); |
107 states_.push_back(scheduler_->AsValue().release()); | 117 states_.push_back(scheduler_->AsValue().release()); |
108 } | 118 } |
109 virtual void ScheduledActionSendBeginMainFrame() OVERRIDE { | 119 virtual void ScheduledActionSendBeginMainFrame() OVERRIDE { |
110 actions_.push_back("ScheduledActionSendBeginMainFrame"); | 120 actions_.push_back("ScheduledActionSendBeginMainFrame"); |
111 states_.push_back(scheduler_->AsValue().release()); | 121 states_.push_back(scheduler_->AsValue().release()); |
112 } | 122 } |
113 virtual void ScheduledActionAnimate() OVERRIDE { | 123 virtual void ScheduledActionAnimate() OVERRIDE { |
114 actions_.push_back("ScheduledActionAnimate"); | 124 actions_.push_back("ScheduledActionAnimate"); |
115 states_.push_back(scheduler_->AsValue().release()); | 125 states_.push_back(scheduler_->AsValue().release()); |
116 } | 126 } |
117 virtual DrawResult ScheduledActionDrawAndSwapIfPossible() OVERRIDE { | 127 virtual DrawResult ScheduledActionDrawAndSwapIfPossible() OVERRIDE { |
118 actions_.push_back("ScheduledActionDrawAndSwapIfPossible"); | 128 actions_.push_back("ScheduledActionDrawAndSwapIfPossible"); |
119 states_.push_back(scheduler_->AsValue().release()); | 129 states_.push_back(scheduler_->AsValue().release()); |
120 num_draws_++; | 130 num_draws_++; |
121 DrawResult result = | 131 DrawResult result = |
122 draw_will_happen_ ? DRAW_SUCCESS : DRAW_ABORTED_CHECKERBOARD_ANIMATIONS; | 132 draw_will_happen_ ? DRAW_SUCCESS : DRAW_ABORTED_CHECKERBOARD_ANIMATIONS; |
123 bool swap_will_happen = | 133 bool swap_will_happen = |
124 draw_will_happen_ && swap_will_happen_if_draw_happens_; | 134 draw_will_happen_ && swap_will_happen_if_draw_happens_; |
125 if (swap_will_happen) { | 135 if (swap_will_happen) { |
126 scheduler_->DidSwapBuffers(); | 136 scheduler_->DidSwapBuffers(); |
| 137 if (swap_contains_incomplete_tile_) { |
| 138 scheduler_->SetSwapUsedIncompleteTile(true); |
| 139 swap_contains_incomplete_tile_ = false; |
| 140 } else { |
| 141 scheduler_->SetSwapUsedIncompleteTile(false); |
| 142 } |
| 143 |
127 if (automatic_swap_ack_) | 144 if (automatic_swap_ack_) |
128 scheduler_->DidSwapBuffersComplete(); | 145 scheduler_->DidSwapBuffersComplete(); |
129 } | 146 } |
130 return result; | 147 return result; |
131 } | 148 } |
132 virtual DrawResult ScheduledActionDrawAndSwapForced() OVERRIDE { | 149 virtual DrawResult ScheduledActionDrawAndSwapForced() OVERRIDE { |
133 actions_.push_back("ScheduledActionDrawAndSwapForced"); | 150 actions_.push_back("ScheduledActionDrawAndSwapForced"); |
134 states_.push_back(scheduler_->AsValue().release()); | 151 states_.push_back(scheduler_->AsValue().release()); |
135 return DRAW_SUCCESS; | 152 return DRAW_SUCCESS; |
136 } | 153 } |
137 virtual void ScheduledActionCommit() OVERRIDE { | 154 virtual void ScheduledActionCommit() OVERRIDE { |
138 actions_.push_back("ScheduledActionCommit"); | 155 actions_.push_back("ScheduledActionCommit"); |
139 states_.push_back(scheduler_->AsValue().release()); | 156 states_.push_back(scheduler_->AsValue().release()); |
140 } | 157 } |
141 virtual void ScheduledActionUpdateVisibleTiles() OVERRIDE { | 158 virtual void ScheduledActionUpdateVisibleTiles() OVERRIDE { |
142 actions_.push_back("ScheduledActionUpdateVisibleTiles"); | 159 actions_.push_back("ScheduledActionUpdateVisibleTiles"); |
143 states_.push_back(scheduler_->AsValue().release()); | 160 states_.push_back(scheduler_->AsValue().release()); |
| 161 if (redraw_will_happen_if_update_visible_tiles_happens_) |
| 162 scheduler_->SetNeedsRedraw(); |
144 } | 163 } |
145 virtual void ScheduledActionActivatePendingTree() OVERRIDE { | 164 virtual void ScheduledActionActivatePendingTree() OVERRIDE { |
146 actions_.push_back("ScheduledActionActivatePendingTree"); | 165 actions_.push_back("ScheduledActionActivatePendingTree"); |
147 states_.push_back(scheduler_->AsValue().release()); | 166 states_.push_back(scheduler_->AsValue().release()); |
148 } | 167 } |
149 virtual void ScheduledActionBeginOutputSurfaceCreation() OVERRIDE { | 168 virtual void ScheduledActionBeginOutputSurfaceCreation() OVERRIDE { |
150 actions_.push_back("ScheduledActionBeginOutputSurfaceCreation"); | 169 actions_.push_back("ScheduledActionBeginOutputSurfaceCreation"); |
151 states_.push_back(scheduler_->AsValue().release()); | 170 states_.push_back(scheduler_->AsValue().release()); |
152 } | 171 } |
153 virtual void ScheduledActionManageTiles() OVERRIDE { | 172 virtual void ScheduledActionManageTiles() OVERRIDE { |
(...skipping 16 matching lines...) Expand all Loading... |
170 | 189 |
171 virtual void DidBeginImplFrameDeadline() OVERRIDE {} | 190 virtual void DidBeginImplFrameDeadline() OVERRIDE {} |
172 | 191 |
173 protected: | 192 protected: |
174 bool needs_begin_frame_; | 193 bool needs_begin_frame_; |
175 bool draw_will_happen_; | 194 bool draw_will_happen_; |
176 bool swap_will_happen_if_draw_happens_; | 195 bool swap_will_happen_if_draw_happens_; |
177 bool automatic_swap_ack_; | 196 bool automatic_swap_ack_; |
178 int num_draws_; | 197 int num_draws_; |
179 bool log_anticipated_draw_time_change_; | 198 bool log_anticipated_draw_time_change_; |
| 199 bool swap_contains_incomplete_tile_; |
| 200 bool redraw_will_happen_if_update_visible_tiles_happens_; |
180 base::TimeTicks posted_begin_impl_frame_deadline_; | 201 base::TimeTicks posted_begin_impl_frame_deadline_; |
181 std::vector<const char*> actions_; | 202 std::vector<const char*> actions_; |
182 ScopedVector<base::Value> states_; | 203 ScopedVector<base::Value> states_; |
183 scoped_ptr<Scheduler> scheduler_; | 204 scoped_ptr<Scheduler> scheduler_; |
184 scoped_refptr<base::TestSimpleTaskRunner> task_runner_; | 205 scoped_refptr<base::TestSimpleTaskRunner> task_runner_; |
185 }; | 206 }; |
186 | 207 |
187 void InitializeOutputSurfaceAndFirstCommit(Scheduler* scheduler, | 208 void InitializeOutputSurfaceAndFirstCommit(Scheduler* scheduler, |
188 FakeSchedulerClient* client) { | 209 FakeSchedulerClient* client) { |
189 bool client_initiates_begin_frame = | 210 bool client_initiates_begin_frame = |
190 scheduler->settings().begin_frame_scheduling_enabled && | 211 scheduler->settings().begin_frame_scheduling_enabled && |
191 scheduler->settings().throttle_frame_production; | 212 scheduler->settings().throttle_frame_production; |
192 | 213 |
193 scheduler->DidCreateAndInitializeOutputSurface(); | 214 scheduler->DidCreateAndInitializeOutputSurface(); |
194 scheduler->SetNeedsCommit(); | 215 scheduler->SetNeedsCommit(); |
195 scheduler->NotifyBeginMainFrameStarted(); | 216 scheduler->NotifyBeginMainFrameStarted(); |
196 scheduler->NotifyReadyToCommit(); | 217 scheduler->NotifyReadyToCommit(); |
| 218 if (scheduler->settings().impl_side_painting) |
| 219 scheduler->NotifyReadyToActivate(); |
197 // Go through the motions to draw the commit. | 220 // Go through the motions to draw the commit. |
198 if (client_initiates_begin_frame) | 221 if (client_initiates_begin_frame) |
199 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | 222 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); |
200 else | 223 else |
201 client->task_runner().RunPendingTasks(); // Run posted BeginFrame. | 224 client->task_runner().RunPendingTasks(); // Run posted BeginFrame. |
202 | 225 |
203 // Run the posted deadline task. | 226 // Run the posted deadline task. |
204 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 227 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
205 client->task_runner().RunPendingTasks(); | 228 client->task_runner().RunPendingTasks(); |
206 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 229 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
(...skipping 661 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
868 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); | 891 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); |
869 EXPECT_TRUE(client.HasAction("ScheduledActionManageTiles")); | 892 EXPECT_TRUE(client.HasAction("ScheduledActionManageTiles")); |
870 EXPECT_LT(client.ActionIndex("ScheduledActionDrawAndSwapIfPossible"), | 893 EXPECT_LT(client.ActionIndex("ScheduledActionDrawAndSwapIfPossible"), |
871 client.ActionIndex("ScheduledActionManageTiles")); | 894 client.ActionIndex("ScheduledActionManageTiles")); |
872 EXPECT_FALSE(scheduler->RedrawPending()); | 895 EXPECT_FALSE(scheduler->RedrawPending()); |
873 EXPECT_FALSE(scheduler->ManageTilesPending()); | 896 EXPECT_FALSE(scheduler->ManageTilesPending()); |
874 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 897 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
875 scheduler->DidManageTiles(); // Corresponds to ScheduledActionManageTiles | 898 scheduler->DidManageTiles(); // Corresponds to ScheduledActionManageTiles |
876 } | 899 } |
877 | 900 |
| 901 TEST(SchedulerTest, ShouldUpdateVisibleTiles) { |
| 902 FakeSchedulerClient client; |
| 903 SchedulerSettings scheduler_settings; |
| 904 scheduler_settings.impl_side_painting = true; |
| 905 Scheduler* scheduler = client.CreateScheduler(scheduler_settings); |
| 906 scheduler->SetCanStart(); |
| 907 scheduler->SetVisible(true); |
| 908 scheduler->SetCanDraw(true); |
| 909 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
| 910 |
| 911 client.SetRedrawWillHappenIfUpdateVisibleTilesHappens(true); |
| 912 |
| 913 // SetNeedsCommit should begin the frame. |
| 914 client.Reset(); |
| 915 scheduler->SetNeedsCommit(); |
| 916 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); |
| 917 |
| 918 client.Reset(); |
| 919 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); |
| 920 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
| 921 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); |
| 922 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 923 |
| 924 client.Reset(); |
| 925 scheduler->NotifyBeginMainFrameStarted(); |
| 926 scheduler->NotifyReadyToCommit(); |
| 927 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); |
| 928 |
| 929 client.Reset(); |
| 930 scheduler->NotifyReadyToActivate(); |
| 931 EXPECT_SINGLE_ACTION("ScheduledActionActivatePendingTree", client); |
| 932 |
| 933 client.Reset(); |
| 934 client.SetSwapContainsIncompleteTile(true); |
| 935 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 936 EXPECT_ACTION("ScheduledActionAnimate", client, 0, 3); |
| 937 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 1, 3); |
| 938 EXPECT_ACTION("ScheduledActionUpdateVisibleTiles", client, 2, 3); |
| 939 EXPECT_TRUE(scheduler->RedrawPending()); |
| 940 |
| 941 client.Reset(); |
| 942 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); |
| 943 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
| 944 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); |
| 945 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 946 |
| 947 client.Reset(); |
| 948 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 949 EXPECT_ACTION("ScheduledActionUpdateVisibleTiles", client, 0, 2); |
| 950 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 1, 2); |
| 951 } |
| 952 |
878 TEST(SchedulerTest, TriggerBeginFrameDeadlineEarly) { | 953 TEST(SchedulerTest, TriggerBeginFrameDeadlineEarly) { |
879 SchedulerClientNeedsManageTilesInDraw client; | 954 SchedulerClientNeedsManageTilesInDraw client; |
880 SchedulerSettings default_scheduler_settings; | 955 SchedulerSettings default_scheduler_settings; |
881 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings); | 956 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings); |
882 scheduler->SetCanStart(); | 957 scheduler->SetCanStart(); |
883 scheduler->SetVisible(true); | 958 scheduler->SetVisible(true); |
884 scheduler->SetCanDraw(true); | 959 scheduler->SetCanDraw(true); |
885 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | 960 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
886 | 961 |
887 client.Reset(); | 962 client.Reset(); |
(...skipping 526 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1414 TEST(SchedulerTest, | 1489 TEST(SchedulerTest, |
1415 SyntheticBeginFrames_And_VSyncThrottlingDisabled_SwapThrottled) { | 1490 SyntheticBeginFrames_And_VSyncThrottlingDisabled_SwapThrottled) { |
1416 bool begin_frame_scheduling_enabled = false; | 1491 bool begin_frame_scheduling_enabled = false; |
1417 bool throttle_frame_production = false; | 1492 bool throttle_frame_production = false; |
1418 BeginFramesNotFromClient_SwapThrottled(begin_frame_scheduling_enabled, | 1493 BeginFramesNotFromClient_SwapThrottled(begin_frame_scheduling_enabled, |
1419 throttle_frame_production); | 1494 throttle_frame_production); |
1420 } | 1495 } |
1421 | 1496 |
1422 } // namespace | 1497 } // namespace |
1423 } // namespace cc | 1498 } // namespace cc |
OLD | NEW |