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 <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 } | 60 } |
61 | 61 |
62 void Reset() { | 62 void Reset() { |
63 actions_.clear(); | 63 actions_.clear(); |
64 states_.clear(); | 64 states_.clear(); |
65 will_begin_impl_frame_causes_redraw_ = false; | 65 will_begin_impl_frame_causes_redraw_ = false; |
66 will_begin_impl_frame_requests_one_begin_impl_frame_ = false; | 66 will_begin_impl_frame_requests_one_begin_impl_frame_ = false; |
67 draw_will_happen_ = true; | 67 draw_will_happen_ = true; |
68 swap_will_happen_if_draw_happens_ = true; | 68 swap_will_happen_if_draw_happens_ = true; |
69 num_draws_ = 0; | 69 num_draws_ = 0; |
70 begin_frame_args_sent_to_children_ = BeginFrameArgs(); | |
71 last_begin_main_frame_args_ = BeginFrameArgs(); | 70 last_begin_main_frame_args_ = BeginFrameArgs(); |
72 } | 71 } |
73 | 72 |
74 void set_scheduler(TestScheduler* scheduler) { scheduler_ = scheduler; } | 73 void set_scheduler(TestScheduler* scheduler) { scheduler_ = scheduler; } |
75 | 74 |
76 bool needs_begin_frames() { return scheduler_->begin_frames_expected(); } | 75 bool needs_begin_frames() { return scheduler_->begin_frames_expected(); } |
77 int num_draws() const { return num_draws_; } | 76 int num_draws() const { return num_draws_; } |
78 int num_actions_() const { return static_cast<int>(actions_.size()); } | 77 int num_actions_() const { return static_cast<int>(actions_.size()); } |
79 const char* Action(int i) const { return actions_[i]; } | 78 const char* Action(int i) const { return actions_[i]; } |
80 std::string StateForAction(int i) const { return states_[i]->ToString(); } | 79 std::string StateForAction(int i) const { return states_[i]->ToString(); } |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 void ScheduledActionPrepareTiles() override { | 158 void ScheduledActionPrepareTiles() override { |
160 PushAction("ScheduledActionPrepareTiles"); | 159 PushAction("ScheduledActionPrepareTiles"); |
161 scheduler_->WillPrepareTiles(); | 160 scheduler_->WillPrepareTiles(); |
162 scheduler_->DidPrepareTiles(); | 161 scheduler_->DidPrepareTiles(); |
163 } | 162 } |
164 void ScheduledActionInvalidateOutputSurface() override { | 163 void ScheduledActionInvalidateOutputSurface() override { |
165 actions_.push_back("ScheduledActionInvalidateOutputSurface"); | 164 actions_.push_back("ScheduledActionInvalidateOutputSurface"); |
166 states_.push_back(scheduler_->AsValue()); | 165 states_.push_back(scheduler_->AsValue()); |
167 } | 166 } |
168 | 167 |
169 void SendBeginFramesToChildren(const BeginFrameArgs& args) override { | |
170 begin_frame_args_sent_to_children_ = args; | |
171 } | |
172 | |
173 void SendBeginMainFrameNotExpectedSoon() override { | 168 void SendBeginMainFrameNotExpectedSoon() override { |
174 PushAction("SendBeginMainFrameNotExpectedSoon"); | 169 PushAction("SendBeginMainFrameNotExpectedSoon"); |
175 } | 170 } |
176 | 171 |
177 base::Callback<bool(void)> ImplFrameDeadlinePending(bool state) { | 172 base::Callback<bool(void)> ImplFrameDeadlinePending(bool state) { |
178 return base::Bind(&FakeSchedulerClient::ImplFrameDeadlinePendingCallback, | 173 return base::Bind(&FakeSchedulerClient::ImplFrameDeadlinePendingCallback, |
179 base::Unretained(this), | 174 base::Unretained(this), |
180 state); | 175 state); |
181 } | 176 } |
182 | 177 |
183 bool begin_frame_is_sent_to_children() const { | |
184 return begin_frame_args_sent_to_children_.IsValid(); | |
185 } | |
186 | |
187 const BeginFrameArgs& begin_frame_args_sent_to_children() const { | |
188 return begin_frame_args_sent_to_children_; | |
189 } | |
190 | |
191 void PushAction(const char* description) { | 178 void PushAction(const char* description) { |
192 actions_.push_back(description); | 179 actions_.push_back(description); |
193 states_.push_back(scheduler_->AsValue()); | 180 states_.push_back(scheduler_->AsValue()); |
194 } | 181 } |
195 | 182 |
196 protected: | 183 protected: |
197 bool ImplFrameDeadlinePendingCallback(bool state) { | 184 bool ImplFrameDeadlinePendingCallback(bool state) { |
198 return scheduler_->BeginImplFrameDeadlinePending() == state; | 185 return scheduler_->BeginImplFrameDeadlinePending() == state; |
199 } | 186 } |
200 | 187 |
201 bool will_begin_impl_frame_causes_redraw_; | 188 bool will_begin_impl_frame_causes_redraw_; |
202 bool will_begin_impl_frame_requests_one_begin_impl_frame_; | 189 bool will_begin_impl_frame_requests_one_begin_impl_frame_; |
203 bool draw_will_happen_; | 190 bool draw_will_happen_; |
204 bool swap_will_happen_if_draw_happens_; | 191 bool swap_will_happen_if_draw_happens_; |
205 bool automatic_swap_ack_; | 192 bool automatic_swap_ack_; |
206 int num_draws_; | 193 int num_draws_; |
207 BeginFrameArgs begin_frame_args_sent_to_children_; | |
208 BeginFrameArgs last_begin_main_frame_args_; | 194 BeginFrameArgs last_begin_main_frame_args_; |
209 base::TimeTicks posted_begin_impl_frame_deadline_; | 195 base::TimeTicks posted_begin_impl_frame_deadline_; |
210 std::vector<const char*> actions_; | 196 std::vector<const char*> actions_; |
211 std::vector<std::unique_ptr<base::trace_event::ConvertableToTraceFormat>> | 197 std::vector<std::unique_ptr<base::trace_event::ConvertableToTraceFormat>> |
212 states_; | 198 states_; |
213 TestScheduler* scheduler_; | 199 TestScheduler* scheduler_; |
214 }; | 200 }; |
215 | 201 |
216 class FakeExternalBeginFrameSource : public BeginFrameSourceBase { | 202 class FakeExternalBeginFrameSource : public BeginFrameSourceBase { |
217 public: | 203 public: |
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
456 SetUpScheduler(false); | 442 SetUpScheduler(false); |
457 scheduler_->SetVisible(true); | 443 scheduler_->SetVisible(true); |
458 scheduler_->SetCanDraw(true); | 444 scheduler_->SetCanDraw(true); |
459 | 445 |
460 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client_); | 446 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client_); |
461 client_->Reset(); | 447 client_->Reset(); |
462 scheduler_->DidCreateAndInitializeOutputSurface(); | 448 scheduler_->DidCreateAndInitializeOutputSurface(); |
463 EXPECT_NO_ACTION(client_); | 449 EXPECT_NO_ACTION(client_); |
464 } | 450 } |
465 | 451 |
466 TEST_F(SchedulerTest, SendBeginFramesToChildren) { | |
467 scheduler_settings_.use_external_begin_frame_source = true; | |
468 SetUpScheduler(true); | |
469 | |
470 EXPECT_FALSE(client_->begin_frame_is_sent_to_children()); | |
471 scheduler_->SetNeedsBeginMainFrame(); | |
472 EXPECT_SINGLE_ACTION("AddObserver(this)", client_); | |
473 EXPECT_TRUE(scheduler_->begin_frames_expected()); | |
474 | |
475 scheduler_->SetChildrenNeedBeginFrames(true); | |
476 | |
477 client_->Reset(); | |
478 EXPECT_SCOPED(AdvanceFrame()); | |
479 EXPECT_TRUE(client_->begin_frame_is_sent_to_children()); | |
480 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | |
481 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); | |
482 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); | |
483 EXPECT_TRUE(scheduler_->begin_frames_expected()); | |
484 } | |
485 | |
486 TEST_F(SchedulerTest, SendBeginFramesToChildrenWithoutCommit) { | |
487 scheduler_settings_.use_external_begin_frame_source = true; | |
488 SetUpScheduler(true); | |
489 | |
490 EXPECT_FALSE(scheduler_->begin_frames_expected()); | |
491 scheduler_->SetChildrenNeedBeginFrames(true); | |
492 EXPECT_SINGLE_ACTION("AddObserver(this)", client_); | |
493 EXPECT_TRUE(scheduler_->begin_frames_expected()); | |
494 | |
495 client_->Reset(); | |
496 EXPECT_SCOPED(AdvanceFrame()); | |
497 EXPECT_TRUE(client_->begin_frame_is_sent_to_children()); | |
498 } | |
499 | |
500 TEST_F(SchedulerTest, SendBeginFramesToChildrenDeadlineNotAdjusted) { | |
501 // Set up client with specified estimates. | |
502 scheduler_settings_.use_external_begin_frame_source = true; | |
503 SetUpScheduler(true); | |
504 | |
505 fake_compositor_timing_history_ | |
506 ->SetBeginMainFrameStartToCommitDurationEstimate( | |
507 base::TimeDelta::FromMilliseconds(2)); | |
508 fake_compositor_timing_history_->SetCommitToReadyToActivateDurationEstimate( | |
509 base::TimeDelta::FromMilliseconds(4)); | |
510 fake_compositor_timing_history_->SetDrawDurationEstimate( | |
511 base::TimeDelta::FromMilliseconds(1)); | |
512 | |
513 EXPECT_FALSE(scheduler_->begin_frames_expected()); | |
514 scheduler_->SetChildrenNeedBeginFrames(true); | |
515 EXPECT_SINGLE_ACTION("AddObserver(this)", client_); | |
516 EXPECT_TRUE(scheduler_->begin_frames_expected()); | |
517 | |
518 client_->Reset(); | |
519 | |
520 BeginFrameArgs frame_args = | |
521 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, now_src()); | |
522 fake_external_begin_frame_source()->TestOnBeginFrame(frame_args); | |
523 | |
524 EXPECT_TRUE(client_->begin_frame_is_sent_to_children()); | |
525 EXPECT_EQ(client_->begin_frame_args_sent_to_children().deadline, | |
526 frame_args.deadline); | |
527 } | |
528 | |
529 TEST_F(SchedulerTest, VideoNeedsBeginFrames) { | 452 TEST_F(SchedulerTest, VideoNeedsBeginFrames) { |
530 scheduler_settings_.use_external_begin_frame_source = true; | 453 scheduler_settings_.use_external_begin_frame_source = true; |
531 SetUpScheduler(true); | 454 SetUpScheduler(true); |
532 | 455 |
533 scheduler_->SetVideoNeedsBeginFrames(true); | 456 scheduler_->SetVideoNeedsBeginFrames(true); |
534 EXPECT_SINGLE_ACTION("AddObserver(this)", client_); | 457 EXPECT_SINGLE_ACTION("AddObserver(this)", client_); |
535 EXPECT_TRUE(scheduler_->begin_frames_expected()); | 458 EXPECT_TRUE(scheduler_->begin_frames_expected()); |
536 | 459 |
537 client_->Reset(); | 460 client_->Reset(); |
538 EXPECT_SCOPED(AdvanceFrame()); | 461 EXPECT_SCOPED(AdvanceFrame()); |
(...skipping 3314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3853 } | 3776 } |
3854 | 3777 |
3855 TEST_F(SchedulerTest, BeginMainFrameOnCriticalPath_AHS) { | 3778 TEST_F(SchedulerTest, BeginMainFrameOnCriticalPath_AHS) { |
3856 EXPECT_FALSE(BeginMainFrameOnCriticalPath( | 3779 EXPECT_FALSE(BeginMainFrameOnCriticalPath( |
3857 SMOOTHNESS_TAKES_PRIORITY, | 3780 SMOOTHNESS_TAKES_PRIORITY, |
3858 ScrollHandlerState::SCROLL_AFFECTS_SCROLL_HANDLER, kSlowDuration)); | 3781 ScrollHandlerState::SCROLL_AFFECTS_SCROLL_HANDLER, kSlowDuration)); |
3859 } | 3782 } |
3860 | 3783 |
3861 } // namespace | 3784 } // namespace |
3862 } // namespace cc | 3785 } // namespace cc |
OLD | NEW |