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/debug/trace_event.h" | 9 #include "base/debug/trace_event.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 base::MessageLoop::current()->RunUntilIdle(); | 75 base::MessageLoop::current()->RunUntilIdle(); |
76 } | 76 } |
77 bool IsOnBatteryPowerImpl() override { return on_battery_power_impl_; } | 77 bool IsOnBatteryPowerImpl() override { return on_battery_power_impl_; } |
78 | 78 |
79 private: | 79 private: |
80 bool on_battery_power_impl_; | 80 bool on_battery_power_impl_; |
81 }; | 81 }; |
82 | 82 |
83 FakeSchedulerClient() | 83 FakeSchedulerClient() |
84 : automatic_swap_ack_(true), | 84 : automatic_swap_ack_(true), |
85 swap_contains_incomplete_tile_(false), | |
86 redraw_will_happen_if_update_visible_tiles_happens_(false), | |
87 now_src_(TestNowSource::Create()), | 85 now_src_(TestNowSource::Create()), |
88 task_runner_(new OrderedSimpleTaskRunner(now_src_, true)), | 86 task_runner_(new OrderedSimpleTaskRunner(now_src_, true)), |
89 fake_frame_source_(this), | 87 fake_frame_source_(this), |
90 fake_power_monitor_source_(new FakePowerMonitorSource), | 88 fake_power_monitor_source_(new FakePowerMonitorSource), |
91 power_monitor_(make_scoped_ptr<base::PowerMonitorSource>( | 89 power_monitor_(make_scoped_ptr<base::PowerMonitorSource>( |
92 fake_power_monitor_source_)), | 90 fake_power_monitor_source_)), |
93 scheduler_(nullptr) { | 91 scheduler_(nullptr) { |
94 // A bunch of tests require Now() to be > BeginFrameArgs::DefaultInterval() | 92 // A bunch of tests require Now() to be > BeginFrameArgs::DefaultInterval() |
95 now_src_->AdvanceNow(base::TimeDelta::FromMilliseconds(100)); | 93 now_src_->AdvanceNow(base::TimeDelta::FromMilliseconds(100)); |
96 // Fail if we need to run 100 tasks in a row. | 94 // Fail if we need to run 100 tasks in a row. |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 OrderedSimpleTaskRunner& task_runner() { return *task_runner_; } | 160 OrderedSimpleTaskRunner& task_runner() { return *task_runner_; } |
163 TestNowSource* now_src() { return now_src_.get(); } | 161 TestNowSource* now_src() { return now_src_.get(); } |
164 | 162 |
165 int ActionIndex(const char* action) const { | 163 int ActionIndex(const char* action) const { |
166 for (size_t i = 0; i < actions_.size(); i++) | 164 for (size_t i = 0; i < actions_.size(); i++) |
167 if (!strcmp(actions_[i], action)) | 165 if (!strcmp(actions_[i], action)) |
168 return i; | 166 return i; |
169 return -1; | 167 return -1; |
170 } | 168 } |
171 | 169 |
172 void SetSwapContainsIncompleteTile(bool contain) { | |
173 swap_contains_incomplete_tile_ = contain; | |
174 } | |
175 | |
176 bool HasAction(const char* action) const { | 170 bool HasAction(const char* action) const { |
177 return ActionIndex(action) >= 0; | 171 return ActionIndex(action) >= 0; |
178 } | 172 } |
179 | 173 |
180 void SetDrawWillHappen(bool draw_will_happen) { | 174 void SetDrawWillHappen(bool draw_will_happen) { |
181 draw_will_happen_ = draw_will_happen; | 175 draw_will_happen_ = draw_will_happen; |
182 } | 176 } |
183 void SetSwapWillHappenIfDrawHappens(bool swap_will_happen_if_draw_happens) { | 177 void SetSwapWillHappenIfDrawHappens(bool swap_will_happen_if_draw_happens) { |
184 swap_will_happen_if_draw_happens_ = swap_will_happen_if_draw_happens; | 178 swap_will_happen_if_draw_happens_ = swap_will_happen_if_draw_happens; |
185 } | 179 } |
186 void SetAutomaticSwapAck(bool automatic_swap_ack) { | 180 void SetAutomaticSwapAck(bool automatic_swap_ack) { |
187 automatic_swap_ack_ = automatic_swap_ack; | 181 automatic_swap_ack_ = automatic_swap_ack; |
188 } | 182 } |
189 void SetRedrawWillHappenIfUpdateVisibleTilesHappens(bool redraw) { | |
190 redraw_will_happen_if_update_visible_tiles_happens_ = redraw; | |
191 } | |
192 // SchedulerClient implementation. | 183 // SchedulerClient implementation. |
193 void WillBeginImplFrame(const BeginFrameArgs& args) override { | 184 void WillBeginImplFrame(const BeginFrameArgs& args) override { |
194 actions_.push_back("WillBeginImplFrame"); | 185 actions_.push_back("WillBeginImplFrame"); |
195 states_.push_back(scheduler_->AsValue()); | 186 states_.push_back(scheduler_->AsValue()); |
196 } | 187 } |
197 void ScheduledActionSendBeginMainFrame() override { | 188 void ScheduledActionSendBeginMainFrame() override { |
198 actions_.push_back("ScheduledActionSendBeginMainFrame"); | 189 actions_.push_back("ScheduledActionSendBeginMainFrame"); |
199 states_.push_back(scheduler_->AsValue()); | 190 states_.push_back(scheduler_->AsValue()); |
200 } | 191 } |
201 void ScheduledActionAnimate() override { | 192 void ScheduledActionAnimate() override { |
202 actions_.push_back("ScheduledActionAnimate"); | 193 actions_.push_back("ScheduledActionAnimate"); |
203 states_.push_back(scheduler_->AsValue()); | 194 states_.push_back(scheduler_->AsValue()); |
204 } | 195 } |
205 DrawResult ScheduledActionDrawAndSwapIfPossible() override { | 196 DrawResult ScheduledActionDrawAndSwapIfPossible() override { |
206 actions_.push_back("ScheduledActionDrawAndSwapIfPossible"); | 197 actions_.push_back("ScheduledActionDrawAndSwapIfPossible"); |
207 states_.push_back(scheduler_->AsValue()); | 198 states_.push_back(scheduler_->AsValue()); |
208 num_draws_++; | 199 num_draws_++; |
209 DrawResult result = | 200 DrawResult result = |
210 draw_will_happen_ ? DRAW_SUCCESS : DRAW_ABORTED_CHECKERBOARD_ANIMATIONS; | 201 draw_will_happen_ ? DRAW_SUCCESS : DRAW_ABORTED_CHECKERBOARD_ANIMATIONS; |
211 bool swap_will_happen = | 202 bool swap_will_happen = |
212 draw_will_happen_ && swap_will_happen_if_draw_happens_; | 203 draw_will_happen_ && swap_will_happen_if_draw_happens_; |
213 if (swap_will_happen) { | 204 if (swap_will_happen) { |
214 scheduler_->DidSwapBuffers(); | 205 scheduler_->DidSwapBuffers(); |
215 if (swap_contains_incomplete_tile_) { | |
216 scheduler_->SetSwapUsedIncompleteTile(true); | |
217 swap_contains_incomplete_tile_ = false; | |
218 } else { | |
219 scheduler_->SetSwapUsedIncompleteTile(false); | |
220 } | |
221 | 206 |
222 if (automatic_swap_ack_) | 207 if (automatic_swap_ack_) |
223 scheduler_->DidSwapBuffersComplete(); | 208 scheduler_->DidSwapBuffersComplete(); |
224 } | 209 } |
225 return result; | 210 return result; |
226 } | 211 } |
227 DrawResult ScheduledActionDrawAndSwapForced() override { | 212 DrawResult ScheduledActionDrawAndSwapForced() override { |
228 actions_.push_back("ScheduledActionDrawAndSwapForced"); | 213 actions_.push_back("ScheduledActionDrawAndSwapForced"); |
229 states_.push_back(scheduler_->AsValue()); | 214 states_.push_back(scheduler_->AsValue()); |
230 return DRAW_SUCCESS; | 215 return DRAW_SUCCESS; |
231 } | 216 } |
232 void ScheduledActionCommit() override { | 217 void ScheduledActionCommit() override { |
233 actions_.push_back("ScheduledActionCommit"); | 218 actions_.push_back("ScheduledActionCommit"); |
234 states_.push_back(scheduler_->AsValue()); | 219 states_.push_back(scheduler_->AsValue()); |
235 } | 220 } |
236 void ScheduledActionUpdateVisibleTiles() override { | |
237 actions_.push_back("ScheduledActionUpdateVisibleTiles"); | |
238 states_.push_back(scheduler_->AsValue()); | |
239 if (redraw_will_happen_if_update_visible_tiles_happens_) | |
240 scheduler_->SetNeedsRedraw(); | |
241 } | |
242 void ScheduledActionActivateSyncTree() override { | 221 void ScheduledActionActivateSyncTree() override { |
243 actions_.push_back("ScheduledActionActivateSyncTree"); | 222 actions_.push_back("ScheduledActionActivateSyncTree"); |
244 states_.push_back(scheduler_->AsValue()); | 223 states_.push_back(scheduler_->AsValue()); |
245 } | 224 } |
246 void ScheduledActionBeginOutputSurfaceCreation() override { | 225 void ScheduledActionBeginOutputSurfaceCreation() override { |
247 actions_.push_back("ScheduledActionBeginOutputSurfaceCreation"); | 226 actions_.push_back("ScheduledActionBeginOutputSurfaceCreation"); |
248 states_.push_back(scheduler_->AsValue()); | 227 states_.push_back(scheduler_->AsValue()); |
249 } | 228 } |
250 void ScheduledActionManageTiles() override { | 229 void ScheduledActionManageTiles() override { |
251 actions_.push_back("ScheduledActionManageTiles"); | 230 actions_.push_back("ScheduledActionManageTiles"); |
(...skipping 22 matching lines...) Expand all Loading... |
274 protected: | 253 protected: |
275 bool ImplFrameDeadlinePendingCallback(bool state) { | 254 bool ImplFrameDeadlinePendingCallback(bool state) { |
276 return scheduler_->BeginImplFrameDeadlinePending() == state; | 255 return scheduler_->BeginImplFrameDeadlinePending() == state; |
277 } | 256 } |
278 | 257 |
279 bool draw_will_happen_; | 258 bool draw_will_happen_; |
280 bool swap_will_happen_if_draw_happens_; | 259 bool swap_will_happen_if_draw_happens_; |
281 bool automatic_swap_ack_; | 260 bool automatic_swap_ack_; |
282 int num_draws_; | 261 int num_draws_; |
283 bool log_anticipated_draw_time_change_; | 262 bool log_anticipated_draw_time_change_; |
284 bool swap_contains_incomplete_tile_; | |
285 bool redraw_will_happen_if_update_visible_tiles_happens_; | |
286 base::TimeTicks posted_begin_impl_frame_deadline_; | 263 base::TimeTicks posted_begin_impl_frame_deadline_; |
287 std::vector<const char*> actions_; | 264 std::vector<const char*> actions_; |
288 std::vector<scoped_refptr<base::debug::ConvertableToTraceFormat>> states_; | 265 std::vector<scoped_refptr<base::debug::ConvertableToTraceFormat>> states_; |
289 scoped_refptr<TestNowSource> now_src_; | 266 scoped_refptr<TestNowSource> now_src_; |
290 scoped_refptr<OrderedSimpleTaskRunner> task_runner_; | 267 scoped_refptr<OrderedSimpleTaskRunner> task_runner_; |
291 FakeBeginFrameSourceForFakeSchedulerClient fake_frame_source_; | 268 FakeBeginFrameSourceForFakeSchedulerClient fake_frame_source_; |
292 FakePowerMonitorSource* fake_power_monitor_source_; | 269 FakePowerMonitorSource* fake_power_monitor_source_; |
293 base::PowerMonitor power_monitor_; | 270 base::PowerMonitor power_monitor_; |
294 scoped_ptr<TestScheduler> scheduler_; | 271 scoped_ptr<TestScheduler> scheduler_; |
295 }; | 272 }; |
(...skipping 679 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
975 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); | 952 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); |
976 EXPECT_TRUE(client.HasAction("ScheduledActionManageTiles")); | 953 EXPECT_TRUE(client.HasAction("ScheduledActionManageTiles")); |
977 EXPECT_LT(client.ActionIndex("ScheduledActionDrawAndSwapIfPossible"), | 954 EXPECT_LT(client.ActionIndex("ScheduledActionDrawAndSwapIfPossible"), |
978 client.ActionIndex("ScheduledActionManageTiles")); | 955 client.ActionIndex("ScheduledActionManageTiles")); |
979 EXPECT_FALSE(scheduler->RedrawPending()); | 956 EXPECT_FALSE(scheduler->RedrawPending()); |
980 EXPECT_FALSE(scheduler->ManageTilesPending()); | 957 EXPECT_FALSE(scheduler->ManageTilesPending()); |
981 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 958 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
982 scheduler->DidManageTiles(); // Corresponds to ScheduledActionManageTiles | 959 scheduler->DidManageTiles(); // Corresponds to ScheduledActionManageTiles |
983 } | 960 } |
984 | 961 |
985 TEST(SchedulerTest, ShouldUpdateVisibleTiles) { | |
986 FakeSchedulerClient client; | |
987 SchedulerSettings scheduler_settings; | |
988 scheduler_settings.impl_side_painting = true; | |
989 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings); | |
990 scheduler->SetCanStart(); | |
991 scheduler->SetVisible(true); | |
992 scheduler->SetCanDraw(true); | |
993 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | |
994 | |
995 client.SetRedrawWillHappenIfUpdateVisibleTilesHappens(true); | |
996 | |
997 // SetNeedsCommit should begin the frame. | |
998 client.Reset(); | |
999 scheduler->SetNeedsCommit(); | |
1000 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client); | |
1001 | |
1002 client.Reset(); | |
1003 client.AdvanceFrame(); | |
1004 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | |
1005 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); | |
1006 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | |
1007 | |
1008 client.Reset(); | |
1009 scheduler->NotifyBeginMainFrameStarted(); | |
1010 scheduler->NotifyReadyToCommit(); | |
1011 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); | |
1012 | |
1013 client.Reset(); | |
1014 scheduler->NotifyReadyToActivate(); | |
1015 EXPECT_SINGLE_ACTION("ScheduledActionActivateSyncTree", client); | |
1016 | |
1017 client.Reset(); | |
1018 client.SetSwapContainsIncompleteTile(true); | |
1019 client.task_runner().RunPendingTasks(); // Run posted deadline. | |
1020 EXPECT_ACTION("ScheduledActionAnimate", client, 0, 2); | |
1021 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 1, 2); | |
1022 EXPECT_FALSE(scheduler->RedrawPending()); | |
1023 | |
1024 client.Reset(); | |
1025 client.AdvanceFrame(); | |
1026 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); | |
1027 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | |
1028 | |
1029 client.Reset(); | |
1030 client.task_runner().RunPendingTasks(); // Run posted deadline. | |
1031 EXPECT_ACTION("ScheduledActionUpdateVisibleTiles", client, 0, 3); | |
1032 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 3); | |
1033 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 2, 3); | |
1034 | |
1035 client.Reset(); | |
1036 client.AdvanceFrame(); | |
1037 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); | |
1038 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | |
1039 | |
1040 // No more UpdateVisibleTiles(). | |
1041 client.Reset(); | |
1042 client.task_runner().RunPendingTasks(); // Run posted deadline. | |
1043 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(false)", client); | |
1044 } | |
1045 | |
1046 TEST(SchedulerTest, TriggerBeginFrameDeadlineEarly) { | 962 TEST(SchedulerTest, TriggerBeginFrameDeadlineEarly) { |
1047 SchedulerClientNeedsManageTilesInDraw client; | 963 SchedulerClientNeedsManageTilesInDraw client; |
1048 SchedulerSettings default_scheduler_settings; | 964 SchedulerSettings default_scheduler_settings; |
1049 TestScheduler* scheduler = client.CreateScheduler(default_scheduler_settings); | 965 TestScheduler* scheduler = client.CreateScheduler(default_scheduler_settings); |
1050 scheduler->SetCanStart(); | 966 scheduler->SetCanStart(); |
1051 scheduler->SetVisible(true); | 967 scheduler->SetVisible(true); |
1052 scheduler->SetCanDraw(true); | 968 scheduler->SetCanDraw(true); |
1053 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | 969 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
1054 | 970 |
1055 client.Reset(); | 971 client.Reset(); |
(...skipping 1080 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2136 | 2052 |
2137 // Deadline task is pending | 2053 // Deadline task is pending |
2138 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 2054 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
2139 client.task_runner().RunPendingTasks(); | 2055 client.task_runner().RunPendingTasks(); |
2140 // Deadline task runs immediately | 2056 // Deadline task runs immediately |
2141 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 2057 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
2142 } | 2058 } |
2143 | 2059 |
2144 } // namespace | 2060 } // namespace |
2145 } // namespace cc | 2061 } // namespace cc |
OLD | NEW |