Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1110)

Side by Side Diff: cc/scheduler/scheduler_unittest.cc

Issue 671653005: SetNeedsRedraw directly when updating a visible tile. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: pinchblurmerge-test: . Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « cc/scheduler/scheduler_state_machine.cc ('k') | cc/test/fake_layer_tree_host_impl_client.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/debug/trace_event.h" 10 #include "base/debug/trace_event.h"
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 base::MessageLoop::current()->RunUntilIdle(); 81 base::MessageLoop::current()->RunUntilIdle();
82 } 82 }
83 bool IsOnBatteryPowerImpl() override { return on_battery_power_impl_; } 83 bool IsOnBatteryPowerImpl() override { return on_battery_power_impl_; }
84 84
85 private: 85 private:
86 bool on_battery_power_impl_; 86 bool on_battery_power_impl_;
87 }; 87 };
88 88
89 FakeSchedulerClient() 89 FakeSchedulerClient()
90 : automatic_swap_ack_(true), 90 : automatic_swap_ack_(true),
91 swap_contains_incomplete_tile_(false),
92 redraw_will_happen_if_update_visible_tiles_happens_(false),
93 now_src_(TestNowSource::Create()), 91 now_src_(TestNowSource::Create()),
94 task_runner_(new OrderedSimpleTaskRunner(now_src_, true)), 92 task_runner_(new OrderedSimpleTaskRunner(now_src_, true)),
95 fake_external_begin_frame_source_(nullptr), 93 fake_external_begin_frame_source_(nullptr),
96 fake_power_monitor_source_(new FakePowerMonitorSource), 94 fake_power_monitor_source_(new FakePowerMonitorSource),
97 power_monitor_(make_scoped_ptr<base::PowerMonitorSource>( 95 power_monitor_(make_scoped_ptr<base::PowerMonitorSource>(
98 fake_power_monitor_source_)), 96 fake_power_monitor_source_)),
99 scheduler_(nullptr) { 97 scheduler_(nullptr) {
100 // A bunch of tests require Now() to be > BeginFrameArgs::DefaultInterval() 98 // A bunch of tests require Now() to be > BeginFrameArgs::DefaultInterval()
101 now_src_->AdvanceNow(base::TimeDelta::FromMilliseconds(100)); 99 now_src_->AdvanceNow(base::TimeDelta::FromMilliseconds(100));
102 // Fail if we need to run 100 tasks in a row. 100 // Fail if we need to run 100 tasks in a row.
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 OrderedSimpleTaskRunner& task_runner() { return *task_runner_; } 182 OrderedSimpleTaskRunner& task_runner() { return *task_runner_; }
185 TestNowSource* now_src() { return now_src_.get(); } 183 TestNowSource* now_src() { return now_src_.get(); }
186 184
187 int ActionIndex(const char* action) const { 185 int ActionIndex(const char* action) const {
188 for (size_t i = 0; i < actions_.size(); i++) 186 for (size_t i = 0; i < actions_.size(); i++)
189 if (!strcmp(actions_[i], action)) 187 if (!strcmp(actions_[i], action))
190 return i; 188 return i;
191 return -1; 189 return -1;
192 } 190 }
193 191
194 void SetSwapContainsIncompleteTile(bool contain) {
195 swap_contains_incomplete_tile_ = contain;
196 }
197
198 bool HasAction(const char* action) const { 192 bool HasAction(const char* action) const {
199 return ActionIndex(action) >= 0; 193 return ActionIndex(action) >= 0;
200 } 194 }
201 195
202 void SetDrawWillHappen(bool draw_will_happen) { 196 void SetDrawWillHappen(bool draw_will_happen) {
203 draw_will_happen_ = draw_will_happen; 197 draw_will_happen_ = draw_will_happen;
204 } 198 }
205 void SetSwapWillHappenIfDrawHappens(bool swap_will_happen_if_draw_happens) { 199 void SetSwapWillHappenIfDrawHappens(bool swap_will_happen_if_draw_happens) {
206 swap_will_happen_if_draw_happens_ = swap_will_happen_if_draw_happens; 200 swap_will_happen_if_draw_happens_ = swap_will_happen_if_draw_happens;
207 } 201 }
208 void SetAutomaticSwapAck(bool automatic_swap_ack) { 202 void SetAutomaticSwapAck(bool automatic_swap_ack) {
209 automatic_swap_ack_ = automatic_swap_ack; 203 automatic_swap_ack_ = automatic_swap_ack;
210 } 204 }
211 void SetRedrawWillHappenIfUpdateVisibleTilesHappens(bool redraw) {
212 redraw_will_happen_if_update_visible_tiles_happens_ = redraw;
213 }
214 // SchedulerClient implementation. 205 // SchedulerClient implementation.
215 void WillBeginImplFrame(const BeginFrameArgs& args) override { 206 void WillBeginImplFrame(const BeginFrameArgs& args) override {
216 actions_.push_back("WillBeginImplFrame"); 207 actions_.push_back("WillBeginImplFrame");
217 states_.push_back(scheduler_->AsValue()); 208 states_.push_back(scheduler_->AsValue());
218 } 209 }
219 void ScheduledActionSendBeginMainFrame() override { 210 void ScheduledActionSendBeginMainFrame() override {
220 actions_.push_back("ScheduledActionSendBeginMainFrame"); 211 actions_.push_back("ScheduledActionSendBeginMainFrame");
221 states_.push_back(scheduler_->AsValue()); 212 states_.push_back(scheduler_->AsValue());
222 } 213 }
223 void ScheduledActionAnimate() override { 214 void ScheduledActionAnimate() override {
224 actions_.push_back("ScheduledActionAnimate"); 215 actions_.push_back("ScheduledActionAnimate");
225 states_.push_back(scheduler_->AsValue()); 216 states_.push_back(scheduler_->AsValue());
226 } 217 }
227 DrawResult ScheduledActionDrawAndSwapIfPossible() override { 218 DrawResult ScheduledActionDrawAndSwapIfPossible() override {
228 actions_.push_back("ScheduledActionDrawAndSwapIfPossible"); 219 actions_.push_back("ScheduledActionDrawAndSwapIfPossible");
229 states_.push_back(scheduler_->AsValue()); 220 states_.push_back(scheduler_->AsValue());
230 num_draws_++; 221 num_draws_++;
231 DrawResult result = 222 DrawResult result =
232 draw_will_happen_ ? DRAW_SUCCESS : DRAW_ABORTED_CHECKERBOARD_ANIMATIONS; 223 draw_will_happen_ ? DRAW_SUCCESS : DRAW_ABORTED_CHECKERBOARD_ANIMATIONS;
233 bool swap_will_happen = 224 bool swap_will_happen =
234 draw_will_happen_ && swap_will_happen_if_draw_happens_; 225 draw_will_happen_ && swap_will_happen_if_draw_happens_;
235 if (swap_will_happen) { 226 if (swap_will_happen) {
236 scheduler_->DidSwapBuffers(); 227 scheduler_->DidSwapBuffers();
237 if (swap_contains_incomplete_tile_) {
238 scheduler_->SetSwapUsedIncompleteTile(true);
239 swap_contains_incomplete_tile_ = false;
240 } else {
241 scheduler_->SetSwapUsedIncompleteTile(false);
242 }
243 228
244 if (automatic_swap_ack_) 229 if (automatic_swap_ack_)
245 scheduler_->DidSwapBuffersComplete(); 230 scheduler_->DidSwapBuffersComplete();
246 } 231 }
247 return result; 232 return result;
248 } 233 }
249 DrawResult ScheduledActionDrawAndSwapForced() override { 234 DrawResult ScheduledActionDrawAndSwapForced() override {
250 actions_.push_back("ScheduledActionDrawAndSwapForced"); 235 actions_.push_back("ScheduledActionDrawAndSwapForced");
251 states_.push_back(scheduler_->AsValue()); 236 states_.push_back(scheduler_->AsValue());
252 return DRAW_SUCCESS; 237 return DRAW_SUCCESS;
253 } 238 }
254 void ScheduledActionCommit() override { 239 void ScheduledActionCommit() override {
255 actions_.push_back("ScheduledActionCommit"); 240 actions_.push_back("ScheduledActionCommit");
256 states_.push_back(scheduler_->AsValue()); 241 states_.push_back(scheduler_->AsValue());
257 } 242 }
258 void ScheduledActionUpdateVisibleTiles() override {
259 actions_.push_back("ScheduledActionUpdateVisibleTiles");
260 states_.push_back(scheduler_->AsValue());
261 if (redraw_will_happen_if_update_visible_tiles_happens_)
262 scheduler_->SetNeedsRedraw();
263 }
264 void ScheduledActionActivateSyncTree() override { 243 void ScheduledActionActivateSyncTree() override {
265 actions_.push_back("ScheduledActionActivateSyncTree"); 244 actions_.push_back("ScheduledActionActivateSyncTree");
266 states_.push_back(scheduler_->AsValue()); 245 states_.push_back(scheduler_->AsValue());
267 } 246 }
268 void ScheduledActionBeginOutputSurfaceCreation() override { 247 void ScheduledActionBeginOutputSurfaceCreation() override {
269 actions_.push_back("ScheduledActionBeginOutputSurfaceCreation"); 248 actions_.push_back("ScheduledActionBeginOutputSurfaceCreation");
270 states_.push_back(scheduler_->AsValue()); 249 states_.push_back(scheduler_->AsValue());
271 } 250 }
272 void ScheduledActionManageTiles() override { 251 void ScheduledActionManageTiles() override {
273 actions_.push_back("ScheduledActionManageTiles"); 252 actions_.push_back("ScheduledActionManageTiles");
(...skipping 22 matching lines...) Expand all
296 protected: 275 protected:
297 bool ImplFrameDeadlinePendingCallback(bool state) { 276 bool ImplFrameDeadlinePendingCallback(bool state) {
298 return scheduler_->BeginImplFrameDeadlinePending() == state; 277 return scheduler_->BeginImplFrameDeadlinePending() == state;
299 } 278 }
300 279
301 bool draw_will_happen_; 280 bool draw_will_happen_;
302 bool swap_will_happen_if_draw_happens_; 281 bool swap_will_happen_if_draw_happens_;
303 bool automatic_swap_ack_; 282 bool automatic_swap_ack_;
304 int num_draws_; 283 int num_draws_;
305 bool log_anticipated_draw_time_change_; 284 bool log_anticipated_draw_time_change_;
306 bool swap_contains_incomplete_tile_;
307 bool redraw_will_happen_if_update_visible_tiles_happens_;
308 base::TimeTicks posted_begin_impl_frame_deadline_; 285 base::TimeTicks posted_begin_impl_frame_deadline_;
309 std::vector<const char*> actions_; 286 std::vector<const char*> actions_;
310 std::vector<scoped_refptr<base::debug::ConvertableToTraceFormat>> states_; 287 std::vector<scoped_refptr<base::debug::ConvertableToTraceFormat>> states_;
311 scoped_refptr<TestNowSource> now_src_; 288 scoped_refptr<TestNowSource> now_src_;
312 scoped_refptr<OrderedSimpleTaskRunner> task_runner_; 289 scoped_refptr<OrderedSimpleTaskRunner> task_runner_;
313 FakeExternalBeginFrameSource* fake_external_begin_frame_source_; 290 FakeExternalBeginFrameSource* fake_external_begin_frame_source_;
314 FakePowerMonitorSource* fake_power_monitor_source_; 291 FakePowerMonitorSource* fake_power_monitor_source_;
315 base::PowerMonitor power_monitor_; 292 base::PowerMonitor power_monitor_;
316 scoped_ptr<TestScheduler> scheduler_; 293 scoped_ptr<TestScheduler> scheduler_;
317 }; 294 };
(...skipping 687 matching lines...) Expand 10 before | Expand all | Expand 10 after
1005 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); 982 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible"));
1006 EXPECT_TRUE(client.HasAction("ScheduledActionManageTiles")); 983 EXPECT_TRUE(client.HasAction("ScheduledActionManageTiles"));
1007 EXPECT_LT(client.ActionIndex("ScheduledActionDrawAndSwapIfPossible"), 984 EXPECT_LT(client.ActionIndex("ScheduledActionDrawAndSwapIfPossible"),
1008 client.ActionIndex("ScheduledActionManageTiles")); 985 client.ActionIndex("ScheduledActionManageTiles"));
1009 EXPECT_FALSE(scheduler->RedrawPending()); 986 EXPECT_FALSE(scheduler->RedrawPending());
1010 EXPECT_FALSE(scheduler->ManageTilesPending()); 987 EXPECT_FALSE(scheduler->ManageTilesPending());
1011 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); 988 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending());
1012 scheduler->DidManageTiles(); // Corresponds to ScheduledActionManageTiles 989 scheduler->DidManageTiles(); // Corresponds to ScheduledActionManageTiles
1013 } 990 }
1014 991
1015 TEST(SchedulerTest, ShouldUpdateVisibleTiles) {
1016 FakeSchedulerClient client;
1017 SchedulerSettings scheduler_settings;
1018 scheduler_settings.impl_side_painting = true;
1019 scheduler_settings.use_external_begin_frame_source = true;
1020 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings);
1021 scheduler->SetCanStart();
1022 scheduler->SetVisible(true);
1023 scheduler->SetCanDraw(true);
1024 InitializeOutputSurfaceAndFirstCommit(scheduler, &client);
1025
1026 client.SetRedrawWillHappenIfUpdateVisibleTilesHappens(true);
1027
1028 // SetNeedsCommit should begin the frame.
1029 client.Reset();
1030 scheduler->SetNeedsCommit();
1031 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client);
1032
1033 client.Reset();
1034 client.AdvanceFrame();
1035 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2);
1036 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2);
1037 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending());
1038
1039 client.Reset();
1040 scheduler->NotifyBeginMainFrameStarted();
1041 scheduler->NotifyReadyToCommit();
1042 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client);
1043
1044 client.Reset();
1045 scheduler->NotifyReadyToActivate();
1046 EXPECT_SINGLE_ACTION("ScheduledActionActivateSyncTree", client);
1047
1048 client.Reset();
1049 client.SetSwapContainsIncompleteTile(true);
1050 client.task_runner().RunPendingTasks(); // Run posted deadline.
1051 EXPECT_ACTION("ScheduledActionAnimate", client, 0, 2);
1052 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 1, 2);
1053 EXPECT_FALSE(scheduler->RedrawPending());
1054
1055 client.Reset();
1056 client.AdvanceFrame();
1057 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client);
1058 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending());
1059
1060 client.Reset();
1061 client.task_runner().RunPendingTasks(); // Run posted deadline.
1062 EXPECT_ACTION("ScheduledActionUpdateVisibleTiles", client, 0, 3);
1063 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 3);
1064 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 2, 3);
1065
1066 client.Reset();
1067 client.AdvanceFrame();
1068 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client);
1069 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending());
1070
1071 // No more UpdateVisibleTiles().
1072 client.Reset();
1073 client.task_runner().RunPendingTasks(); // Run posted deadline.
1074 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(false)", client);
1075 }
1076
1077 TEST(SchedulerTest, TriggerBeginFrameDeadlineEarly) { 992 TEST(SchedulerTest, TriggerBeginFrameDeadlineEarly) {
1078 SchedulerClientNeedsManageTilesInDraw client; 993 SchedulerClientNeedsManageTilesInDraw client;
1079 SchedulerSettings scheduler_settings; 994 SchedulerSettings scheduler_settings;
1080 scheduler_settings.use_external_begin_frame_source = true; 995 scheduler_settings.use_external_begin_frame_source = true;
1081 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings); 996 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings);
1082 scheduler->SetCanStart(); 997 scheduler->SetCanStart();
1083 scheduler->SetVisible(true); 998 scheduler->SetVisible(true);
1084 scheduler->SetCanDraw(true); 999 scheduler->SetCanDraw(true);
1085 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); 1000 InitializeOutputSurfaceAndFirstCommit(scheduler, &client);
1086 1001
(...skipping 1085 matching lines...) Expand 10 before | Expand all | Expand 10 after
2172 2087
2173 // Deadline task is pending 2088 // Deadline task is pending
2174 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 2089 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending());
2175 client.task_runner().RunPendingTasks(); 2090 client.task_runner().RunPendingTasks();
2176 // Deadline task runs immediately 2091 // Deadline task runs immediately
2177 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); 2092 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending());
2178 } 2093 }
2179 2094
2180 } // namespace 2095 } // namespace
2181 } // namespace cc 2096 } // namespace cc
OLDNEW
« no previous file with comments | « cc/scheduler/scheduler_state_machine.cc ('k') | cc/test/fake_layer_tree_host_impl_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698