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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 statements; \ | 42 statements; \ |
43 } | 43 } |
44 | 44 |
45 namespace cc { | 45 namespace cc { |
46 namespace { | 46 namespace { |
47 | 47 |
48 class FakeSchedulerClient : public SchedulerClient { | 48 class FakeSchedulerClient : public SchedulerClient { |
49 public: | 49 public: |
50 FakeSchedulerClient() | 50 FakeSchedulerClient() |
51 : automatic_swap_ack_(true), | 51 : automatic_swap_ack_(true), |
52 begin_frame_is_sent_to_children_(false), | |
53 scheduler_(nullptr) { | 52 scheduler_(nullptr) { |
54 Reset(); | 53 Reset(); |
55 } | 54 } |
56 | 55 |
57 void Reset() { | 56 void Reset() { |
58 actions_.clear(); | 57 actions_.clear(); |
59 states_.clear(); | 58 states_.clear(); |
60 draw_will_happen_ = true; | 59 draw_will_happen_ = true; |
61 swap_will_happen_if_draw_happens_ = true; | 60 swap_will_happen_if_draw_happens_ = true; |
62 num_draws_ = 0; | 61 num_draws_ = 0; |
63 log_anticipated_draw_time_change_ = false; | 62 log_anticipated_draw_time_change_ = false; |
64 begin_frame_is_sent_to_children_ = false; | 63 begin_frame_args_sent_to_children_ = BeginFrameArgs(); |
65 } | 64 } |
66 | 65 |
67 void set_scheduler(TestScheduler* scheduler) { scheduler_ = scheduler; } | 66 void set_scheduler(TestScheduler* scheduler) { scheduler_ = scheduler; } |
68 | 67 |
69 // Most tests don't care about DidAnticipatedDrawTimeChange, so only record it | 68 // Most tests don't care about DidAnticipatedDrawTimeChange, so only record it |
70 // for tests that do. | 69 // for tests that do. |
71 void set_log_anticipated_draw_time_change(bool log) { | 70 void set_log_anticipated_draw_time_change(bool log) { |
72 log_anticipated_draw_time_change_ = log; | 71 log_anticipated_draw_time_change_ = log; |
73 } | 72 } |
74 bool needs_begin_frames() { | 73 bool needs_begin_frames() { |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 base::TimeDelta BeginMainFrameToCommitDurationEstimate() override { | 152 base::TimeDelta BeginMainFrameToCommitDurationEstimate() override { |
154 return base::TimeDelta(); | 153 return base::TimeDelta(); |
155 } | 154 } |
156 base::TimeDelta CommitToActivateDurationEstimate() override { | 155 base::TimeDelta CommitToActivateDurationEstimate() override { |
157 return base::TimeDelta(); | 156 return base::TimeDelta(); |
158 } | 157 } |
159 | 158 |
160 void DidBeginImplFrameDeadline() override {} | 159 void DidBeginImplFrameDeadline() override {} |
161 | 160 |
162 void SendBeginFramesToChildren(const BeginFrameArgs& args) override { | 161 void SendBeginFramesToChildren(const BeginFrameArgs& args) override { |
163 begin_frame_is_sent_to_children_ = true; | 162 begin_frame_args_sent_to_children_ = args; |
164 } | 163 } |
165 | 164 |
166 void SendBeginMainFrameNotExpectedSoon() override { | 165 void SendBeginMainFrameNotExpectedSoon() override { |
167 PushAction("SendBeginMainFrameNotExpectedSoon"); | 166 PushAction("SendBeginMainFrameNotExpectedSoon"); |
168 } | 167 } |
169 | 168 |
170 base::Callback<bool(void)> ImplFrameDeadlinePending(bool state) { | 169 base::Callback<bool(void)> ImplFrameDeadlinePending(bool state) { |
171 return base::Bind(&FakeSchedulerClient::ImplFrameDeadlinePendingCallback, | 170 return base::Bind(&FakeSchedulerClient::ImplFrameDeadlinePendingCallback, |
172 base::Unretained(this), | 171 base::Unretained(this), |
173 state); | 172 state); |
174 } | 173 } |
175 | 174 |
176 bool begin_frame_is_sent_to_children() const { | 175 bool begin_frame_is_sent_to_children() const { |
177 return begin_frame_is_sent_to_children_; | 176 return begin_frame_args_sent_to_children_.IsValid(); |
| 177 } |
| 178 |
| 179 const BeginFrameArgs& begin_frame_args_sent_to_children() const { |
| 180 return begin_frame_args_sent_to_children_; |
178 } | 181 } |
179 | 182 |
180 void PushAction(const char* description) { | 183 void PushAction(const char* description) { |
181 actions_.push_back(description); | 184 actions_.push_back(description); |
182 states_.push_back(scheduler_->AsValue()); | 185 states_.push_back(scheduler_->AsValue()); |
183 } | 186 } |
184 | 187 |
185 protected: | 188 protected: |
186 bool ImplFrameDeadlinePendingCallback(bool state) { | 189 bool ImplFrameDeadlinePendingCallback(bool state) { |
187 return scheduler_->BeginImplFrameDeadlinePending() == state; | 190 return scheduler_->BeginImplFrameDeadlinePending() == state; |
188 } | 191 } |
189 | 192 |
190 bool draw_will_happen_; | 193 bool draw_will_happen_; |
191 bool swap_will_happen_if_draw_happens_; | 194 bool swap_will_happen_if_draw_happens_; |
192 bool automatic_swap_ack_; | 195 bool automatic_swap_ack_; |
193 int num_draws_; | 196 int num_draws_; |
194 bool log_anticipated_draw_time_change_; | 197 bool log_anticipated_draw_time_change_; |
195 bool begin_frame_is_sent_to_children_; | 198 BeginFrameArgs begin_frame_args_sent_to_children_; |
196 base::TimeTicks posted_begin_impl_frame_deadline_; | 199 base::TimeTicks posted_begin_impl_frame_deadline_; |
197 std::vector<const char*> actions_; | 200 std::vector<const char*> actions_; |
198 std::vector<scoped_refptr<base::trace_event::ConvertableToTraceFormat>> | 201 std::vector<scoped_refptr<base::trace_event::ConvertableToTraceFormat>> |
199 states_; | 202 states_; |
200 TestScheduler* scheduler_; | 203 TestScheduler* scheduler_; |
201 }; | 204 }; |
202 | 205 |
| 206 class SchedulerClientWithFixedEstimates : public FakeSchedulerClient { |
| 207 public: |
| 208 SchedulerClientWithFixedEstimates( |
| 209 base::TimeDelta draw_duration, |
| 210 base::TimeDelta begin_main_frame_to_commit_duration, |
| 211 base::TimeDelta commit_to_activate_duration) |
| 212 : draw_duration_(draw_duration), |
| 213 begin_main_frame_to_commit_duration_( |
| 214 begin_main_frame_to_commit_duration), |
| 215 commit_to_activate_duration_(commit_to_activate_duration) {} |
| 216 |
| 217 base::TimeDelta DrawDurationEstimate() override { return draw_duration_; } |
| 218 base::TimeDelta BeginMainFrameToCommitDurationEstimate() override { |
| 219 return begin_main_frame_to_commit_duration_; |
| 220 } |
| 221 base::TimeDelta CommitToActivateDurationEstimate() override { |
| 222 return commit_to_activate_duration_; |
| 223 } |
| 224 |
| 225 private: |
| 226 base::TimeDelta draw_duration_; |
| 227 base::TimeDelta begin_main_frame_to_commit_duration_; |
| 228 base::TimeDelta commit_to_activate_duration_; |
| 229 }; |
| 230 |
203 class FakeExternalBeginFrameSource : public BeginFrameSourceMixIn { | 231 class FakeExternalBeginFrameSource : public BeginFrameSourceMixIn { |
204 public: | 232 public: |
205 explicit FakeExternalBeginFrameSource(FakeSchedulerClient* client) | 233 explicit FakeExternalBeginFrameSource(FakeSchedulerClient* client) |
206 : client_(client) {} | 234 : client_(client) {} |
207 ~FakeExternalBeginFrameSource() override {} | 235 ~FakeExternalBeginFrameSource() override {} |
208 | 236 |
209 void OnNeedsBeginFramesChange(bool needs_begin_frames) override { | 237 void OnNeedsBeginFramesChange(bool needs_begin_frames) override { |
210 if (needs_begin_frames) { | 238 if (needs_begin_frames) { |
211 client_->PushAction("SetNeedsBeginFrames(true)"); | 239 client_->PushAction("SetNeedsBeginFrames(true)"); |
212 } else { | 240 } else { |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
447 EXPECT_FALSE(client_->needs_begin_frames()); | 475 EXPECT_FALSE(client_->needs_begin_frames()); |
448 scheduler_->SetChildrenNeedBeginFrames(true); | 476 scheduler_->SetChildrenNeedBeginFrames(true); |
449 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client_); | 477 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client_); |
450 EXPECT_TRUE(client_->needs_begin_frames()); | 478 EXPECT_TRUE(client_->needs_begin_frames()); |
451 | 479 |
452 client_->Reset(); | 480 client_->Reset(); |
453 EXPECT_SCOPED(AdvanceFrame()); | 481 EXPECT_SCOPED(AdvanceFrame()); |
454 EXPECT_TRUE(client_->begin_frame_is_sent_to_children()); | 482 EXPECT_TRUE(client_->begin_frame_is_sent_to_children()); |
455 } | 483 } |
456 | 484 |
| 485 TEST_F(SchedulerTest, SendBeginFramesToChildrenDeadlineNotAdjusted) { |
| 486 // Set up client with specified estimates. |
| 487 SchedulerClientWithFixedEstimates* client = |
| 488 new SchedulerClientWithFixedEstimates( |
| 489 base::TimeDelta::FromMilliseconds(1), |
| 490 base::TimeDelta::FromMilliseconds(2), |
| 491 base::TimeDelta::FromMilliseconds(4)); |
| 492 scheduler_settings_.use_external_begin_frame_source = true; |
| 493 SetUpScheduler(make_scoped_ptr(client).Pass(), true); |
| 494 |
| 495 EXPECT_FALSE(client_->needs_begin_frames()); |
| 496 scheduler_->SetChildrenNeedBeginFrames(true); |
| 497 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client_); |
| 498 EXPECT_TRUE(client_->needs_begin_frames()); |
| 499 |
| 500 client_->Reset(); |
| 501 |
| 502 BeginFrameArgs frame_args = |
| 503 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, now_src()); |
| 504 fake_external_begin_frame_source()->TestOnBeginFrame(frame_args); |
| 505 |
| 506 EXPECT_TRUE(client_->begin_frame_is_sent_to_children()); |
| 507 EXPECT_EQ(client_->begin_frame_args_sent_to_children().deadline, |
| 508 frame_args.deadline); |
| 509 } |
| 510 |
457 TEST_F(SchedulerTest, VideoNeedsBeginFrames) { | 511 TEST_F(SchedulerTest, VideoNeedsBeginFrames) { |
458 scheduler_settings_.use_external_begin_frame_source = true; | 512 scheduler_settings_.use_external_begin_frame_source = true; |
459 SetUpScheduler(true); | 513 SetUpScheduler(true); |
460 | 514 |
461 scheduler_->SetVideoNeedsBeginFrames(true); | 515 scheduler_->SetVideoNeedsBeginFrames(true); |
462 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client_); | 516 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client_); |
463 EXPECT_TRUE(client_->needs_begin_frames()); | 517 EXPECT_TRUE(client_->needs_begin_frames()); |
464 | 518 |
465 client_->Reset(); | 519 client_->Reset(); |
466 EXPECT_SCOPED(AdvanceFrame()); | 520 EXPECT_SCOPED(AdvanceFrame()); |
(...skipping 782 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1249 // Scheduler loses output surface, and stops waiting for ready to draw signal. | 1303 // Scheduler loses output surface, and stops waiting for ready to draw signal. |
1250 client_->Reset(); | 1304 client_->Reset(); |
1251 scheduler_->DidLoseOutputSurface(); | 1305 scheduler_->DidLoseOutputSurface(); |
1252 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 1306 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
1253 task_runner().RunPendingTasks(); // Run posted deadline. | 1307 task_runner().RunPendingTasks(); // Run posted deadline. |
1254 EXPECT_ACTION("ScheduledActionBeginOutputSurfaceCreation", client_, 0, 3); | 1308 EXPECT_ACTION("ScheduledActionBeginOutputSurfaceCreation", client_, 0, 3); |
1255 EXPECT_ACTION("SetNeedsBeginFrames(false)", client_, 1, 3); | 1309 EXPECT_ACTION("SetNeedsBeginFrames(false)", client_, 1, 3); |
1256 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 2, 3); | 1310 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 2, 3); |
1257 } | 1311 } |
1258 | 1312 |
1259 class SchedulerClientWithFixedEstimates : public FakeSchedulerClient { | |
1260 public: | |
1261 SchedulerClientWithFixedEstimates( | |
1262 base::TimeDelta draw_duration, | |
1263 base::TimeDelta begin_main_frame_to_commit_duration, | |
1264 base::TimeDelta commit_to_activate_duration) | |
1265 : draw_duration_(draw_duration), | |
1266 begin_main_frame_to_commit_duration_( | |
1267 begin_main_frame_to_commit_duration), | |
1268 commit_to_activate_duration_(commit_to_activate_duration) {} | |
1269 | |
1270 base::TimeDelta DrawDurationEstimate() override { return draw_duration_; } | |
1271 base::TimeDelta BeginMainFrameToCommitDurationEstimate() override { | |
1272 return begin_main_frame_to_commit_duration_; | |
1273 } | |
1274 base::TimeDelta CommitToActivateDurationEstimate() override { | |
1275 return commit_to_activate_duration_; | |
1276 } | |
1277 | |
1278 private: | |
1279 base::TimeDelta draw_duration_; | |
1280 base::TimeDelta begin_main_frame_to_commit_duration_; | |
1281 base::TimeDelta commit_to_activate_duration_; | |
1282 }; | |
1283 | |
1284 void SchedulerTest::MainFrameInHighLatencyMode( | 1313 void SchedulerTest::MainFrameInHighLatencyMode( |
1285 int64 begin_main_frame_to_commit_estimate_in_ms, | 1314 int64 begin_main_frame_to_commit_estimate_in_ms, |
1286 int64 commit_to_activate_estimate_in_ms, | 1315 int64 commit_to_activate_estimate_in_ms, |
1287 bool impl_latency_takes_priority, | 1316 bool impl_latency_takes_priority, |
1288 bool should_send_begin_main_frame) { | 1317 bool should_send_begin_main_frame) { |
1289 // Set up client with specified estimates (draw duration is set to 1). | 1318 // Set up client with specified estimates (draw duration is set to 1). |
1290 SchedulerClientWithFixedEstimates* client = | 1319 SchedulerClientWithFixedEstimates* client = |
1291 new SchedulerClientWithFixedEstimates( | 1320 new SchedulerClientWithFixedEstimates( |
1292 base::TimeDelta::FromMilliseconds(1), | 1321 base::TimeDelta::FromMilliseconds(1), |
1293 base::TimeDelta::FromMilliseconds( | 1322 base::TimeDelta::FromMilliseconds( |
(...skipping 1316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2610 | 2639 |
2611 // At the next BeginFrame, authoritative interval is used instead of previous | 2640 // At the next BeginFrame, authoritative interval is used instead of previous |
2612 // interval. | 2641 // interval. |
2613 EXPECT_NE(initial_interval, scheduler_->begin_impl_frame_args().interval); | 2642 EXPECT_NE(initial_interval, scheduler_->begin_impl_frame_args().interval); |
2614 EXPECT_EQ(authoritative_interval, | 2643 EXPECT_EQ(authoritative_interval, |
2615 scheduler_->begin_impl_frame_args().interval); | 2644 scheduler_->begin_impl_frame_args().interval); |
2616 } | 2645 } |
2617 | 2646 |
2618 } // namespace | 2647 } // namespace |
2619 } // namespace cc | 2648 } // namespace cc |
OLD | NEW |