| 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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 : automatic_swap_ack_(true), | 51 : automatic_swap_ack_(true), |
| 52 scheduler_(nullptr) { | 52 scheduler_(nullptr) { |
| 53 Reset(); | 53 Reset(); |
| 54 } | 54 } |
| 55 | 55 |
| 56 void Reset() { | 56 void Reset() { |
| 57 actions_.clear(); | 57 actions_.clear(); |
| 58 states_.clear(); | 58 states_.clear(); |
| 59 animate_causes_redraw_ = false; | 59 animate_causes_redraw_ = false; |
| 60 animate_causes_animate_ = false; | 60 animate_causes_animate_ = false; |
| 61 will_begin_impl_frame_requests_one_begin_impl_frame_ = false; |
| 61 draw_will_happen_ = true; | 62 draw_will_happen_ = true; |
| 62 swap_will_happen_if_draw_happens_ = true; | 63 swap_will_happen_if_draw_happens_ = true; |
| 63 num_draws_ = 0; | 64 num_draws_ = 0; |
| 64 begin_frame_args_sent_to_children_ = BeginFrameArgs(); | 65 begin_frame_args_sent_to_children_ = BeginFrameArgs(); |
| 65 } | 66 } |
| 66 | 67 |
| 67 void set_scheduler(TestScheduler* scheduler) { scheduler_ = scheduler; } | 68 void set_scheduler(TestScheduler* scheduler) { scheduler_ = scheduler; } |
| 68 | 69 |
| 69 bool needs_begin_frames() { | 70 bool needs_begin_frames() { |
| 70 return scheduler_->frame_source().NeedsBeginFrames(); | 71 return scheduler_->frame_source().NeedsBeginFrames(); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 81 for (size_t i = 0; i < actions_.size(); i++) | 82 for (size_t i = 0; i < actions_.size(); i++) |
| 82 if (!strcmp(actions_[i], action)) | 83 if (!strcmp(actions_[i], action)) |
| 83 return base::checked_cast<int>(i); | 84 return base::checked_cast<int>(i); |
| 84 return -1; | 85 return -1; |
| 85 } | 86 } |
| 86 | 87 |
| 87 bool HasAction(const char* action) const { | 88 bool HasAction(const char* action) const { |
| 88 return ActionIndex(action) >= 0; | 89 return ActionIndex(action) >= 0; |
| 89 } | 90 } |
| 90 | 91 |
| 92 void SetWillBeginImplFrameRequestsOneBeginImplFrame(bool request) { |
| 93 will_begin_impl_frame_requests_one_begin_impl_frame_ = request; |
| 94 } |
| 91 void SetAnimateCausesRedraw(bool animate_causes_redraw) { | 95 void SetAnimateCausesRedraw(bool animate_causes_redraw) { |
| 92 animate_causes_redraw_ = animate_causes_redraw; | 96 animate_causes_redraw_ = animate_causes_redraw; |
| 93 } | 97 } |
| 94 void SetAnimateCausesAnimate(bool animate_causes_animate) { | 98 void SetAnimateCausesAnimate(bool animate_causes_animate) { |
| 95 animate_causes_animate_ = animate_causes_animate; | 99 animate_causes_animate_ = animate_causes_animate; |
| 96 } | 100 } |
| 97 void SetDrawWillHappen(bool draw_will_happen) { | 101 void SetDrawWillHappen(bool draw_will_happen) { |
| 98 draw_will_happen_ = draw_will_happen; | 102 draw_will_happen_ = draw_will_happen; |
| 99 } | 103 } |
| 100 void SetSwapWillHappenIfDrawHappens(bool swap_will_happen_if_draw_happens) { | 104 void SetSwapWillHappenIfDrawHappens(bool swap_will_happen_if_draw_happens) { |
| 101 swap_will_happen_if_draw_happens_ = swap_will_happen_if_draw_happens; | 105 swap_will_happen_if_draw_happens_ = swap_will_happen_if_draw_happens; |
| 102 } | 106 } |
| 103 void SetAutomaticSwapAck(bool automatic_swap_ack) { | 107 void SetAutomaticSwapAck(bool automatic_swap_ack) { |
| 104 automatic_swap_ack_ = automatic_swap_ack; | 108 automatic_swap_ack_ = automatic_swap_ack; |
| 105 } | 109 } |
| 106 // SchedulerClient implementation. | 110 // SchedulerClient implementation. |
| 107 void WillBeginImplFrame(const BeginFrameArgs& args) override { | 111 void WillBeginImplFrame(const BeginFrameArgs& args) override { |
| 108 PushAction("WillBeginImplFrame"); | 112 PushAction("WillBeginImplFrame"); |
| 113 if (will_begin_impl_frame_requests_one_begin_impl_frame_) |
| 114 scheduler_->SetNeedsOneBeginImplFrame(); |
| 109 } | 115 } |
| 110 void DidFinishImplFrame() override {} | 116 void DidFinishImplFrame() override {} |
| 111 | 117 |
| 112 void ScheduledActionSendBeginMainFrame() override { | 118 void ScheduledActionSendBeginMainFrame() override { |
| 113 PushAction("ScheduledActionSendBeginMainFrame"); | 119 PushAction("ScheduledActionSendBeginMainFrame"); |
| 114 } | 120 } |
| 115 void ScheduledActionAnimate() override { | 121 void ScheduledActionAnimate() override { |
| 116 PushAction("ScheduledActionAnimate"); | 122 PushAction("ScheduledActionAnimate"); |
| 117 if (animate_causes_redraw_) | 123 if (animate_causes_redraw_) |
| 118 scheduler_->SetNeedsRedraw(); | 124 scheduler_->SetNeedsRedraw(); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 states_.push_back(scheduler_->AsValue()); | 191 states_.push_back(scheduler_->AsValue()); |
| 186 } | 192 } |
| 187 | 193 |
| 188 protected: | 194 protected: |
| 189 bool ImplFrameDeadlinePendingCallback(bool state) { | 195 bool ImplFrameDeadlinePendingCallback(bool state) { |
| 190 return scheduler_->BeginImplFrameDeadlinePending() == state; | 196 return scheduler_->BeginImplFrameDeadlinePending() == state; |
| 191 } | 197 } |
| 192 | 198 |
| 193 bool animate_causes_redraw_; | 199 bool animate_causes_redraw_; |
| 194 bool animate_causes_animate_; | 200 bool animate_causes_animate_; |
| 201 bool will_begin_impl_frame_requests_one_begin_impl_frame_; |
| 195 bool draw_will_happen_; | 202 bool draw_will_happen_; |
| 196 bool swap_will_happen_if_draw_happens_; | 203 bool swap_will_happen_if_draw_happens_; |
| 197 bool automatic_swap_ack_; | 204 bool automatic_swap_ack_; |
| 198 int num_draws_; | 205 int num_draws_; |
| 199 BeginFrameArgs begin_frame_args_sent_to_children_; | 206 BeginFrameArgs begin_frame_args_sent_to_children_; |
| 200 base::TimeTicks posted_begin_impl_frame_deadline_; | 207 base::TimeTicks posted_begin_impl_frame_deadline_; |
| 201 std::vector<const char*> actions_; | 208 std::vector<const char*> actions_; |
| 202 std::vector<scoped_refptr<base::trace_event::ConvertableToTraceFormat>> | 209 std::vector<scoped_refptr<base::trace_event::ConvertableToTraceFormat>> |
| 203 states_; | 210 states_; |
| 204 TestScheduler* scheduler_; | 211 TestScheduler* scheduler_; |
| (...skipping 2953 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3158 | 3165 |
| 3159 // Idle on next vsync. | 3166 // Idle on next vsync. |
| 3160 AdvanceFrame(); | 3167 AdvanceFrame(); |
| 3161 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 3); | 3168 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 3); |
| 3162 EXPECT_ACTION("SetNeedsBeginFrames(false)", client_, 1, 3); | 3169 EXPECT_ACTION("SetNeedsBeginFrames(false)", client_, 1, 3); |
| 3163 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 2, 3); | 3170 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 2, 3); |
| 3164 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | 3171 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); |
| 3165 client_->Reset(); | 3172 client_->Reset(); |
| 3166 } | 3173 } |
| 3167 | 3174 |
| 3175 TEST_F(SchedulerTest, SetNeedsOneBeginImplFrame) { |
| 3176 scheduler_settings_.use_external_begin_frame_source = true; |
| 3177 SetUpScheduler(true); |
| 3178 |
| 3179 EXPECT_FALSE(client_->needs_begin_frames()); |
| 3180 |
| 3181 // Request a frame, should kick the source. |
| 3182 scheduler_->SetNeedsOneBeginImplFrame(); |
| 3183 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client_); |
| 3184 client_->Reset(); |
| 3185 |
| 3186 // The incoming WillBeginImplFrame will request another one. |
| 3187 client_->SetWillBeginImplFrameRequestsOneBeginImplFrame(true); |
| 3188 |
| 3189 // Next vsync, the first requested frame happens. |
| 3190 EXPECT_SCOPED(AdvanceFrame()); |
| 3191 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 1); |
| 3192 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
| 3193 client_->Reset(); |
| 3194 |
| 3195 // We don't request another frame here. |
| 3196 |
| 3197 // Next vsync, the second requested frame happens (the one requested inside |
| 3198 // the previous frame's begin impl frame step). |
| 3199 EXPECT_SCOPED(AdvanceFrame()); |
| 3200 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 1); |
| 3201 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
| 3202 client_->Reset(); |
| 3203 |
| 3204 // End that frame's deadline. |
| 3205 task_runner_->RunTasksWhile(client_->ImplFrameDeadlinePending(true)); |
| 3206 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); |
| 3207 |
| 3208 // Scheduler shuts down the source now that no begin frame is requested. |
| 3209 EXPECT_ACTION("SetNeedsBeginFrames(false)", client_, 0, 2); |
| 3210 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 1, 2); |
| 3211 } |
| 3212 |
| 3168 TEST_F(SchedulerTest, SynchronousCompositorCommit) { | 3213 TEST_F(SchedulerTest, SynchronousCompositorCommit) { |
| 3169 scheduler_settings_.using_synchronous_renderer_compositor = true; | 3214 scheduler_settings_.using_synchronous_renderer_compositor = true; |
| 3170 scheduler_settings_.use_external_begin_frame_source = true; | 3215 scheduler_settings_.use_external_begin_frame_source = true; |
| 3171 SetUpScheduler(true); | 3216 SetUpScheduler(true); |
| 3172 | 3217 |
| 3173 scheduler_->SetNeedsBeginMainFrame(); | 3218 scheduler_->SetNeedsBeginMainFrame(); |
| 3174 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client_); | 3219 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client_); |
| 3175 client_->Reset(); | 3220 client_->Reset(); |
| 3176 | 3221 |
| 3177 // Next vsync. | 3222 // Next vsync. |
| (...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3459 scheduler_->SetImplLatencyTakesPriority(true); | 3504 scheduler_->SetImplLatencyTakesPriority(true); |
| 3460 scheduler_->SetChildrenNeedBeginFrames(true); | 3505 scheduler_->SetChildrenNeedBeginFrames(true); |
| 3461 | 3506 |
| 3462 EXPECT_SCOPED(AdvanceFrame()); | 3507 EXPECT_SCOPED(AdvanceFrame()); |
| 3463 EXPECT_TRUE(client_->begin_frame_is_sent_to_children()); | 3508 EXPECT_TRUE(client_->begin_frame_is_sent_to_children()); |
| 3464 EXPECT_FALSE(client_->begin_frame_args_sent_to_children().on_critical_path); | 3509 EXPECT_FALSE(client_->begin_frame_args_sent_to_children().on_critical_path); |
| 3465 } | 3510 } |
| 3466 | 3511 |
| 3467 } // namespace | 3512 } // namespace |
| 3468 } // namespace cc | 3513 } // namespace cc |
| OLD | NEW |