| 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/debug/trace_event.h" | 10 #include "base/debug/trace_event.h" |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 for (int i = expected_num_actions; i < client.num_actions_(); ++i) \ | 31 for (int i = expected_num_actions; i < client.num_actions_(); ++i) \ |
| 32 ADD_FAILURE() << "Unexpected action: " << client.Action(i) \ | 32 ADD_FAILURE() << "Unexpected action: " << client.Action(i) \ |
| 33 << " with state:\n" << client.StateForAction(i); \ | 33 << " with state:\n" << client.StateForAction(i); \ |
| 34 } while (false) | 34 } while (false) |
| 35 | 35 |
| 36 #define EXPECT_NO_ACTION(client) EXPECT_ACTION("", client, -1, 0) | 36 #define EXPECT_NO_ACTION(client) EXPECT_ACTION("", client, -1, 0) |
| 37 | 37 |
| 38 #define EXPECT_SINGLE_ACTION(action, client) \ | 38 #define EXPECT_SINGLE_ACTION(action, client) \ |
| 39 EXPECT_ACTION(action, client, 0, 1) | 39 EXPECT_ACTION(action, client, 0, 1) |
| 40 | 40 |
| 41 #define EXPECT_SCOPED(statements) \ |
| 42 { \ |
| 43 SCOPED_TRACE(""); \ |
| 44 statements; \ |
| 45 } |
| 46 |
| 47 #define CREATE_SCHEDULER_AND_INIT_SURFACE(settings) \ |
| 48 TestScheduler* scheduler = client.CreateScheduler(settings); \ |
| 49 EXPECT_SCOPED(client.InitializeOutputSurfaceAndFirstCommit(scheduler)); |
| 50 |
| 41 namespace cc { | 51 namespace cc { |
| 42 namespace { | 52 namespace { |
| 43 | 53 |
| 44 class FakeSchedulerClient; | 54 class FakeSchedulerClient; |
| 45 | 55 |
| 46 void InitializeOutputSurfaceAndFirstCommit(Scheduler* scheduler, | |
| 47 FakeSchedulerClient* client); | |
| 48 | |
| 49 class FakeSchedulerClient : public SchedulerClient { | 56 class FakeSchedulerClient : public SchedulerClient { |
| 50 public: | 57 public: |
| 51 class FakeExternalBeginFrameSource : public BeginFrameSourceMixIn { | 58 class FakeExternalBeginFrameSource : public BeginFrameSourceMixIn { |
| 52 public: | 59 public: |
| 53 explicit FakeExternalBeginFrameSource(FakeSchedulerClient* client) | 60 explicit FakeExternalBeginFrameSource(FakeSchedulerClient* client) |
| 54 : client_(client) {} | 61 : client_(client) {} |
| 55 virtual ~FakeExternalBeginFrameSource() {} | 62 virtual ~FakeExternalBeginFrameSource() {} |
| 56 | 63 |
| 57 void OnNeedsBeginFramesChange(bool needs_begin_frames) override { | 64 void OnNeedsBeginFramesChange(bool needs_begin_frames) override { |
| 58 if (needs_begin_frames) { | 65 if (needs_begin_frames) { |
| 59 client_->actions_.push_back("SetNeedsBeginFrames(true)"); | 66 client_->PushAction("SetNeedsBeginFrames(true)"); |
| 60 } else { | 67 } else { |
| 61 client_->actions_.push_back("SetNeedsBeginFrames(false)"); | 68 client_->PushAction("SetNeedsBeginFrames(false)"); |
| 62 } | 69 } |
| 63 client_->states_.push_back(client_->scheduler_->AsValue()); | 70 client_->states_.push_back(client_->scheduler_->AsValue()); |
| 64 } | 71 } |
| 65 | 72 |
| 66 void TestOnBeginFrame(const BeginFrameArgs& args) { | 73 void TestOnBeginFrame(const BeginFrameArgs& args) { |
| 67 return CallOnBeginFrame(args); | 74 return CallOnBeginFrame(args); |
| 68 } | 75 } |
| 69 | 76 |
| 70 private: | 77 private: |
| 71 FakeSchedulerClient* client_; | 78 FakeSchedulerClient* client_; |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 DCHECK(scheduler_); | 139 DCHECK(scheduler_); |
| 133 return scheduler_.get(); | 140 return scheduler_.get(); |
| 134 } | 141 } |
| 135 | 142 |
| 136 // Most tests don't care about DidAnticipatedDrawTimeChange, so only record it | 143 // Most tests don't care about DidAnticipatedDrawTimeChange, so only record it |
| 137 // for tests that do. | 144 // for tests that do. |
| 138 void set_log_anticipated_draw_time_change(bool log) { | 145 void set_log_anticipated_draw_time_change(bool log) { |
| 139 log_anticipated_draw_time_change_ = log; | 146 log_anticipated_draw_time_change_ = log; |
| 140 } | 147 } |
| 141 bool needs_begin_frames() { | 148 bool needs_begin_frames() { |
| 142 DCHECK(ExternalBeginFrame()); | 149 return scheduler_->frame_source().NeedsBeginFrames(); |
| 143 return fake_external_begin_frame_source_->NeedsBeginFrames(); | |
| 144 } | 150 } |
| 145 int num_draws() const { return num_draws_; } | 151 int num_draws() const { return num_draws_; } |
| 146 int num_actions_() const { return static_cast<int>(actions_.size()); } | 152 int num_actions_() const { return static_cast<int>(actions_.size()); } |
| 147 const char* Action(int i) const { return actions_[i]; } | 153 const char* Action(int i) const { return actions_[i]; } |
| 148 std::string StateForAction(int i) const { return states_[i]->ToString(); } | 154 std::string StateForAction(int i) const { return states_[i]->ToString(); } |
| 149 base::TimeTicks posted_begin_impl_frame_deadline() const { | 155 base::TimeTicks posted_begin_impl_frame_deadline() const { |
| 150 return posted_begin_impl_frame_deadline_; | 156 return posted_begin_impl_frame_deadline_; |
| 151 } | 157 } |
| 152 | 158 |
| 153 bool ExternalBeginFrame() { | 159 bool ExternalBeginFrame() { |
| 154 return scheduler_->settings().use_external_begin_frame_source && | 160 return scheduler_->settings().use_external_begin_frame_source && |
| 155 scheduler_->settings().throttle_frame_production; | 161 scheduler_->settings().throttle_frame_production; |
| 156 } | 162 } |
| 157 | 163 |
| 158 FakeExternalBeginFrameSource* fake_external_begin_frame_source() const { | 164 FakeExternalBeginFrameSource* fake_external_begin_frame_source() const { |
| 159 return fake_external_begin_frame_source_; | 165 return fake_external_begin_frame_source_; |
| 160 } | 166 } |
| 161 | 167 |
| 162 base::PowerMonitor* PowerMonitor() { return &power_monitor_; } | 168 base::PowerMonitor* PowerMonitor() { return &power_monitor_; } |
| 163 | 169 |
| 164 FakePowerMonitorSource* PowerMonitorSource() { | 170 FakePowerMonitorSource* PowerMonitorSource() { |
| 165 return fake_power_monitor_source_; | 171 return fake_power_monitor_source_; |
| 166 } | 172 } |
| 167 | 173 |
| 174 // As this function contains EXPECT macros, to allow debugging it should be |
| 175 // called inside EXPECT_SCOPED like so; |
| 176 // EXPECT_SCOPED(client.InitializeOutputSurfaceAndFirstCommit(scheduler)); |
| 177 void InitializeOutputSurfaceAndFirstCommit(TestScheduler* scheduler) { |
| 178 TRACE_EVENT0("cc", |
| 179 "SchedulerUnitTest::InitializeOutputSurfaceAndFirstCommit"); |
| 180 DCHECK(scheduler); |
| 181 |
| 182 // Check the client doesn't have any actions queued when calling this |
| 183 // function. |
| 184 EXPECT_NO_ACTION((*this)); |
| 185 EXPECT_FALSE(needs_begin_frames()); |
| 186 |
| 187 // Start the initial output surface creation. |
| 188 EXPECT_FALSE(scheduler->CanStart()); |
| 189 scheduler->SetCanStart(); |
| 190 scheduler->SetVisible(true); |
| 191 scheduler->SetCanDraw(true); |
| 192 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", (*this)); |
| 193 Reset(); |
| 194 |
| 195 // Finish the initial output surface creation and run the first commit. |
| 196 scheduler->DidCreateAndInitializeOutputSurface(); |
| 197 scheduler->SetNeedsCommit(); |
| 198 scheduler->NotifyBeginMainFrameStarted(); |
| 199 scheduler->NotifyReadyToCommitThenActivateIfNeeded(); |
| 200 |
| 201 { |
| 202 SCOPED_TRACE("Go through the motions to draw the commit"); |
| 203 AdvanceFrame(); |
| 204 |
| 205 // Run the posted deadline task. |
| 206 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 207 task_runner().RunTasksWhile(ImplFrameDeadlinePending(true)); |
| 208 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
| 209 |
| 210 EXPECT_FALSE(scheduler->CommitPending()); |
| 211 } |
| 212 |
| 213 Reset(); |
| 214 |
| 215 { |
| 216 SCOPED_TRACE( |
| 217 "Run second frame so Scheduler calls SetNeedsBeginFrame(false)."); |
| 218 AdvanceFrame(); |
| 219 |
| 220 // Run the posted deadline task. |
| 221 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 222 task_runner().RunTasksWhile(ImplFrameDeadlinePending(true)); |
| 223 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
| 224 } |
| 225 |
| 226 EXPECT_FALSE(needs_begin_frames()); |
| 227 Reset(); |
| 228 } |
| 229 |
| 230 // As this function contains EXPECT macros, to allow debugging it should be |
| 231 // called inside EXPECT_SCOPED like so; |
| 232 // EXPECT_SCOPED(client.AdvanceFrame()); |
| 168 void AdvanceFrame() { | 233 void AdvanceFrame() { |
| 169 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug.scheduler.frames"), | 234 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug.scheduler.frames"), |
| 170 "FakeSchedulerClient::AdvanceFrame"); | 235 "FakeSchedulerClient::AdvanceFrame"); |
| 171 bool previous_deadline_pending = | 236 // Consume any previous deadline first, if no deadline is currently |
| 172 scheduler_->BeginImplFrameDeadlinePending(); | 237 // pending, ImplFrameDeadlinePending will return false straight away and we |
| 238 // will run no tasks. |
| 239 task_runner().RunTasksWhile(ImplFrameDeadlinePending(true)); |
| 240 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); |
| 241 |
| 242 // Send the next BeginFrame message if using an external source, otherwise |
| 243 // it will be already in the task queue. |
| 173 if (ExternalBeginFrame()) { | 244 if (ExternalBeginFrame()) { |
| 174 SendNextBeginFrame(); | 245 SendNextBeginFrame(); |
| 175 // This could be the previous deadline or a new one. | |
| 176 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 246 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
| 177 } | 247 } |
| 178 // Consume previous deadline first. It is important that we check for the | 248 |
| 179 // existence of a previous deadline so that we do not consume the new one. | |
| 180 if (previous_deadline_pending) { | |
| 181 EXPECT_TRUE(task_runner().RunTasksWhile(ImplFrameDeadlinePending(true))); | |
| 182 } | |
| 183 // Then run tasks until new deadline is scheduled. | 249 // Then run tasks until new deadline is scheduled. |
| 184 EXPECT_TRUE(task_runner().RunTasksWhile(ImplFrameDeadlinePending(false))); | 250 EXPECT_TRUE(task_runner().RunTasksWhile(ImplFrameDeadlinePending(false))); |
| 185 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 251 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
| 186 } | 252 } |
| 187 | 253 |
| 188 void SendNextBeginFrame() { | 254 void SendNextBeginFrame() { |
| 189 DCHECK(ExternalBeginFrame()); | 255 DCHECK(ExternalBeginFrame()); |
| 190 // Creep the time forward so that any BeginFrameArgs is not equal to the | 256 // Creep the time forward so that any BeginFrameArgs is not equal to the |
| 191 // last one otherwise we violate the BeginFrameSource contract. | 257 // last one otherwise we violate the BeginFrameSource contract. |
| 192 now_src_->AdvanceNow(BeginFrameArgs::DefaultInterval()); | 258 now_src_->AdvanceNow(BeginFrameArgs::DefaultInterval()); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 212 draw_will_happen_ = draw_will_happen; | 278 draw_will_happen_ = draw_will_happen; |
| 213 } | 279 } |
| 214 void SetSwapWillHappenIfDrawHappens(bool swap_will_happen_if_draw_happens) { | 280 void SetSwapWillHappenIfDrawHappens(bool swap_will_happen_if_draw_happens) { |
| 215 swap_will_happen_if_draw_happens_ = swap_will_happen_if_draw_happens; | 281 swap_will_happen_if_draw_happens_ = swap_will_happen_if_draw_happens; |
| 216 } | 282 } |
| 217 void SetAutomaticSwapAck(bool automatic_swap_ack) { | 283 void SetAutomaticSwapAck(bool automatic_swap_ack) { |
| 218 automatic_swap_ack_ = automatic_swap_ack; | 284 automatic_swap_ack_ = automatic_swap_ack; |
| 219 } | 285 } |
| 220 // SchedulerClient implementation. | 286 // SchedulerClient implementation. |
| 221 void WillBeginImplFrame(const BeginFrameArgs& args) override { | 287 void WillBeginImplFrame(const BeginFrameArgs& args) override { |
| 222 actions_.push_back("WillBeginImplFrame"); | 288 PushAction("WillBeginImplFrame"); |
| 223 states_.push_back(scheduler_->AsValue()); | |
| 224 } | 289 } |
| 225 void ScheduledActionSendBeginMainFrame() override { | 290 void ScheduledActionSendBeginMainFrame() override { |
| 226 actions_.push_back("ScheduledActionSendBeginMainFrame"); | 291 PushAction("ScheduledActionSendBeginMainFrame"); |
| 227 states_.push_back(scheduler_->AsValue()); | |
| 228 } | 292 } |
| 229 void ScheduledActionAnimate() override { | 293 void ScheduledActionAnimate() override { |
| 230 actions_.push_back("ScheduledActionAnimate"); | 294 PushAction("ScheduledActionAnimate"); |
| 231 states_.push_back(scheduler_->AsValue()); | |
| 232 } | 295 } |
| 233 DrawResult ScheduledActionDrawAndSwapIfPossible() override { | 296 DrawResult ScheduledActionDrawAndSwapIfPossible() override { |
| 234 actions_.push_back("ScheduledActionDrawAndSwapIfPossible"); | 297 PushAction("ScheduledActionDrawAndSwapIfPossible"); |
| 235 states_.push_back(scheduler_->AsValue()); | |
| 236 num_draws_++; | 298 num_draws_++; |
| 237 DrawResult result = | 299 DrawResult result = |
| 238 draw_will_happen_ ? DRAW_SUCCESS : DRAW_ABORTED_CHECKERBOARD_ANIMATIONS; | 300 draw_will_happen_ ? DRAW_SUCCESS : DRAW_ABORTED_CHECKERBOARD_ANIMATIONS; |
| 239 bool swap_will_happen = | 301 bool swap_will_happen = |
| 240 draw_will_happen_ && swap_will_happen_if_draw_happens_; | 302 draw_will_happen_ && swap_will_happen_if_draw_happens_; |
| 241 if (swap_will_happen) { | 303 if (swap_will_happen) { |
| 242 scheduler_->DidSwapBuffers(); | 304 scheduler_->DidSwapBuffers(); |
| 243 | 305 |
| 244 if (automatic_swap_ack_) | 306 if (automatic_swap_ack_) |
| 245 scheduler_->DidSwapBuffersComplete(); | 307 scheduler_->DidSwapBuffersComplete(); |
| 246 } | 308 } |
| 247 return result; | 309 return result; |
| 248 } | 310 } |
| 249 DrawResult ScheduledActionDrawAndSwapForced() override { | 311 DrawResult ScheduledActionDrawAndSwapForced() override { |
| 250 actions_.push_back("ScheduledActionDrawAndSwapForced"); | 312 PushAction("ScheduledActionDrawAndSwapForced"); |
| 251 states_.push_back(scheduler_->AsValue()); | |
| 252 return DRAW_SUCCESS; | 313 return DRAW_SUCCESS; |
| 253 } | 314 } |
| 254 void ScheduledActionCommit() override { | 315 void ScheduledActionCommit() override { PushAction("ScheduledActionCommit"); } |
| 255 actions_.push_back("ScheduledActionCommit"); | |
| 256 states_.push_back(scheduler_->AsValue()); | |
| 257 } | |
| 258 void ScheduledActionActivateSyncTree() override { | 316 void ScheduledActionActivateSyncTree() override { |
| 259 actions_.push_back("ScheduledActionActivateSyncTree"); | 317 PushAction("ScheduledActionActivateSyncTree"); |
| 260 states_.push_back(scheduler_->AsValue()); | |
| 261 } | 318 } |
| 262 void ScheduledActionBeginOutputSurfaceCreation() override { | 319 void ScheduledActionBeginOutputSurfaceCreation() override { |
| 263 actions_.push_back("ScheduledActionBeginOutputSurfaceCreation"); | 320 PushAction("ScheduledActionBeginOutputSurfaceCreation"); |
| 264 states_.push_back(scheduler_->AsValue()); | |
| 265 } | 321 } |
| 266 void ScheduledActionPrepareTiles() override { | 322 void ScheduledActionPrepareTiles() override { |
| 267 actions_.push_back("ScheduledActionPrepareTiles"); | 323 PushAction("ScheduledActionPrepareTiles"); |
| 268 states_.push_back(scheduler_->AsValue()); | |
| 269 } | 324 } |
| 270 void DidAnticipatedDrawTimeChange(base::TimeTicks) override { | 325 void DidAnticipatedDrawTimeChange(base::TimeTicks) override { |
| 271 if (log_anticipated_draw_time_change_) | 326 if (log_anticipated_draw_time_change_) |
| 272 actions_.push_back("DidAnticipatedDrawTimeChange"); | 327 PushAction("DidAnticipatedDrawTimeChange"); |
| 273 } | 328 } |
| 274 base::TimeDelta DrawDurationEstimate() override { return base::TimeDelta(); } | 329 base::TimeDelta DrawDurationEstimate() override { return base::TimeDelta(); } |
| 275 base::TimeDelta BeginMainFrameToCommitDurationEstimate() override { | 330 base::TimeDelta BeginMainFrameToCommitDurationEstimate() override { |
| 276 return base::TimeDelta(); | 331 return base::TimeDelta(); |
| 277 } | 332 } |
| 278 base::TimeDelta CommitToActivateDurationEstimate() override { | 333 base::TimeDelta CommitToActivateDurationEstimate() override { |
| 279 return base::TimeDelta(); | 334 return base::TimeDelta(); |
| 280 } | 335 } |
| 281 | 336 |
| 282 void DidBeginImplFrameDeadline() override {} | 337 void DidBeginImplFrameDeadline() override {} |
| (...skipping 10 matching lines...) Expand all Loading... |
| 293 | 348 |
| 294 bool begin_frame_is_sent_to_children() const { | 349 bool begin_frame_is_sent_to_children() const { |
| 295 return begin_frame_is_sent_to_children_; | 350 return begin_frame_is_sent_to_children_; |
| 296 } | 351 } |
| 297 | 352 |
| 298 protected: | 353 protected: |
| 299 bool ImplFrameDeadlinePendingCallback(bool state) { | 354 bool ImplFrameDeadlinePendingCallback(bool state) { |
| 300 return scheduler_->BeginImplFrameDeadlinePending() == state; | 355 return scheduler_->BeginImplFrameDeadlinePending() == state; |
| 301 } | 356 } |
| 302 | 357 |
| 358 void PushAction(const char* description) { |
| 359 actions_.push_back(description); |
| 360 states_.push_back(scheduler_->AsValue()); |
| 361 } |
| 362 |
| 303 bool draw_will_happen_; | 363 bool draw_will_happen_; |
| 304 bool swap_will_happen_if_draw_happens_; | 364 bool swap_will_happen_if_draw_happens_; |
| 305 bool automatic_swap_ack_; | 365 bool automatic_swap_ack_; |
| 306 int num_draws_; | 366 int num_draws_; |
| 307 bool log_anticipated_draw_time_change_; | 367 bool log_anticipated_draw_time_change_; |
| 308 bool begin_frame_is_sent_to_children_; | 368 bool begin_frame_is_sent_to_children_; |
| 309 base::TimeTicks posted_begin_impl_frame_deadline_; | 369 base::TimeTicks posted_begin_impl_frame_deadline_; |
| 310 std::vector<const char*> actions_; | 370 std::vector<const char*> actions_; |
| 311 std::vector<scoped_refptr<base::debug::ConvertableToTraceFormat>> states_; | 371 std::vector<scoped_refptr<base::debug::ConvertableToTraceFormat>> states_; |
| 312 scoped_refptr<TestNowSource> now_src_; | 372 scoped_refptr<TestNowSource> now_src_; |
| 313 scoped_refptr<OrderedSimpleTaskRunner> task_runner_; | 373 scoped_refptr<OrderedSimpleTaskRunner> task_runner_; |
| 314 FakeExternalBeginFrameSource* fake_external_begin_frame_source_; | 374 FakeExternalBeginFrameSource* fake_external_begin_frame_source_; |
| 315 FakePowerMonitorSource* fake_power_monitor_source_; | 375 FakePowerMonitorSource* fake_power_monitor_source_; |
| 316 base::PowerMonitor power_monitor_; | 376 base::PowerMonitor power_monitor_; |
| 317 scoped_ptr<TestScheduler> scheduler_; | 377 scoped_ptr<TestScheduler> scheduler_; |
| 318 }; | 378 }; |
| 319 | 379 |
| 320 void InitializeOutputSurfaceAndFirstCommit(Scheduler* scheduler, | |
| 321 FakeSchedulerClient* client) { | |
| 322 TRACE_EVENT0("cc", | |
| 323 "SchedulerUnitTest::InitializeOutputSurfaceAndFirstCommit"); | |
| 324 | |
| 325 scheduler->DidCreateAndInitializeOutputSurface(); | |
| 326 scheduler->SetNeedsCommit(); | |
| 327 scheduler->NotifyBeginMainFrameStarted(); | |
| 328 scheduler->NotifyReadyToCommit(); | |
| 329 if (scheduler->settings().impl_side_painting) | |
| 330 scheduler->NotifyReadyToActivate(); | |
| 331 | |
| 332 { | |
| 333 SCOPED_TRACE("Go through the motions to draw the commit"); | |
| 334 client->AdvanceFrame(); | |
| 335 } | |
| 336 | |
| 337 // Run the posted deadline task. | |
| 338 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | |
| 339 client->task_runner().RunTasksWhile(client->ImplFrameDeadlinePending(true)); | |
| 340 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | |
| 341 | |
| 342 { | |
| 343 SCOPED_TRACE( | |
| 344 "We need another BeginImplFrame so Scheduler calls " | |
| 345 "SetNeedsBeginFrame(false)."); | |
| 346 client->AdvanceFrame(); | |
| 347 } | |
| 348 | |
| 349 // Run the posted deadline task. | |
| 350 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | |
| 351 client->task_runner().RunTasksWhile(client->ImplFrameDeadlinePending(true)); | |
| 352 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | |
| 353 } | |
| 354 | |
| 355 TEST(SchedulerTest, InitializeOutputSurfaceDoesNotBeginImplFrame) { | 380 TEST(SchedulerTest, InitializeOutputSurfaceDoesNotBeginImplFrame) { |
| 356 FakeSchedulerClient client; | 381 FakeSchedulerClient client; |
| 357 SchedulerSettings scheduler_settings; | 382 SchedulerSettings scheduler_settings; |
| 358 scheduler_settings.use_external_begin_frame_source = true; | 383 scheduler_settings.use_external_begin_frame_source = true; |
| 359 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings); | 384 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings); |
| 360 scheduler->SetCanStart(); | 385 scheduler->SetCanStart(); |
| 361 scheduler->SetVisible(true); | 386 scheduler->SetVisible(true); |
| 362 scheduler->SetCanDraw(true); | 387 scheduler->SetCanDraw(true); |
| 363 | 388 |
| 364 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); | 389 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); |
| 365 client.Reset(); | 390 client.Reset(); |
| 366 scheduler->DidCreateAndInitializeOutputSurface(); | 391 scheduler->DidCreateAndInitializeOutputSurface(); |
| 367 EXPECT_NO_ACTION(client); | 392 EXPECT_NO_ACTION(client); |
| 368 } | 393 } |
| 369 | 394 |
| 370 TEST(SchedulerTest, SendBeginFramesToChildren) { | 395 TEST(SchedulerTest, SendBeginFramesToChildren) { |
| 371 FakeSchedulerClient client; | 396 FakeSchedulerClient client; |
| 372 SchedulerSettings scheduler_settings; | 397 SchedulerSettings scheduler_settings; |
| 373 scheduler_settings.use_external_begin_frame_source = true; | 398 scheduler_settings.use_external_begin_frame_source = true; |
| 374 scheduler_settings.forward_begin_frames_to_children = true; | 399 scheduler_settings.forward_begin_frames_to_children = true; |
| 375 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings); | |
| 376 scheduler->SetCanStart(); | |
| 377 scheduler->SetVisible(true); | |
| 378 scheduler->SetCanDraw(true); | |
| 379 | 400 |
| 380 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); | 401 CREATE_SCHEDULER_AND_INIT_SURFACE(scheduler_settings); |
| 381 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | |
| 382 | 402 |
| 383 client.Reset(); | |
| 384 EXPECT_FALSE(client.begin_frame_is_sent_to_children()); | 403 EXPECT_FALSE(client.begin_frame_is_sent_to_children()); |
| 385 scheduler->SetNeedsCommit(); | 404 scheduler->SetNeedsCommit(); |
| 386 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client); | 405 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client); |
| 387 client.Reset(); | 406 EXPECT_TRUE(client.needs_begin_frames()); |
| 388 | 407 |
| 389 scheduler->SetChildrenNeedBeginFrames(true); | 408 scheduler->SetChildrenNeedBeginFrames(true); |
| 390 | 409 |
| 391 client.AdvanceFrame(); | 410 client.Reset(); |
| 411 EXPECT_SCOPED(client.AdvanceFrame()); |
| 392 EXPECT_TRUE(client.begin_frame_is_sent_to_children()); | 412 EXPECT_TRUE(client.begin_frame_is_sent_to_children()); |
| 393 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 413 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 394 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 414 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
| 395 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); | 415 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); |
| 396 EXPECT_TRUE(client.needs_begin_frames()); | 416 EXPECT_TRUE(client.needs_begin_frames()); |
| 417 } |
| 418 |
| 419 TEST(SchedulerTest, SendBeginFramesToChildrenWithoutCommit) { |
| 420 FakeSchedulerClient client; |
| 421 SchedulerSettings scheduler_settings; |
| 422 scheduler_settings.use_external_begin_frame_source = true; |
| 423 scheduler_settings.forward_begin_frames_to_children = true; |
| 424 |
| 425 CREATE_SCHEDULER_AND_INIT_SURFACE(scheduler_settings); |
| 426 |
| 427 EXPECT_FALSE(client.needs_begin_frames()); |
| 428 scheduler->SetChildrenNeedBeginFrames(true); |
| 429 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client); |
| 430 EXPECT_TRUE(client.needs_begin_frames()); |
| 431 |
| 397 client.Reset(); | 432 client.Reset(); |
| 433 EXPECT_SCOPED(client.AdvanceFrame()); |
| 434 EXPECT_TRUE(client.begin_frame_is_sent_to_children()); |
| 398 } | 435 } |
| 399 | 436 |
| 400 TEST(SchedulerTest, RequestCommit) { | 437 TEST(SchedulerTest, RequestCommit) { |
| 401 FakeSchedulerClient client; | 438 FakeSchedulerClient client; |
| 402 SchedulerSettings scheduler_settings; | 439 SchedulerSettings scheduler_settings; |
| 403 scheduler_settings.use_external_begin_frame_source = true; | 440 scheduler_settings.use_external_begin_frame_source = true; |
| 404 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings); | |
| 405 scheduler->SetCanStart(); | |
| 406 scheduler->SetVisible(true); | |
| 407 scheduler->SetCanDraw(true); | |
| 408 | 441 |
| 409 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); | 442 CREATE_SCHEDULER_AND_INIT_SURFACE(scheduler_settings); |
| 410 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | |
| 411 | 443 |
| 412 // SetNeedsCommit should begin the frame on the next BeginImplFrame. | 444 // SetNeedsCommit should begin the frame on the next BeginImplFrame. |
| 413 client.Reset(); | |
| 414 scheduler->SetNeedsCommit(); | 445 scheduler->SetNeedsCommit(); |
| 415 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client); | 446 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client); |
| 416 client.Reset(); | 447 client.Reset(); |
| 417 | 448 |
| 418 client.AdvanceFrame(); | 449 EXPECT_SCOPED(client.AdvanceFrame()); |
| 419 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 450 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
| 420 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); | 451 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); |
| 421 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 452 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 422 EXPECT_TRUE(client.needs_begin_frames()); | 453 EXPECT_TRUE(client.needs_begin_frames()); |
| 423 client.Reset(); | 454 client.Reset(); |
| 424 | 455 |
| 425 // If we don't swap on the deadline, we wait for the next BeginFrame. | 456 // If we don't swap on the deadline, we wait for the next BeginFrame. |
| 426 client.task_runner().RunPendingTasks(); // Run posted deadline. | 457 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 427 EXPECT_NO_ACTION(client); | 458 EXPECT_NO_ACTION(client); |
| 428 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 459 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
| 429 EXPECT_TRUE(client.needs_begin_frames()); | 460 EXPECT_TRUE(client.needs_begin_frames()); |
| 430 client.Reset(); | 461 client.Reset(); |
| 431 | 462 |
| 432 // NotifyReadyToCommit should trigger the commit. | 463 // NotifyReadyToCommit should trigger the commit. |
| 433 scheduler->NotifyBeginMainFrameStarted(); | 464 scheduler->NotifyBeginMainFrameStarted(); |
| 434 scheduler->NotifyReadyToCommit(); | 465 scheduler->NotifyReadyToCommit(); |
| 435 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); | 466 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); |
| 436 EXPECT_TRUE(client.needs_begin_frames()); | 467 EXPECT_TRUE(client.needs_begin_frames()); |
| 437 client.Reset(); | 468 client.Reset(); |
| 438 | 469 |
| 439 // BeginImplFrame should prepare the draw. | 470 // BeginImplFrame should prepare the draw. |
| 440 client.AdvanceFrame(); | 471 EXPECT_SCOPED(client.AdvanceFrame()); |
| 441 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 472 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
| 442 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); | 473 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); |
| 443 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 474 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 444 EXPECT_TRUE(client.needs_begin_frames()); | 475 EXPECT_TRUE(client.needs_begin_frames()); |
| 445 client.Reset(); | 476 client.Reset(); |
| 446 | 477 |
| 447 // BeginImplFrame deadline should draw. | 478 // BeginImplFrame deadline should draw. |
| 448 client.task_runner().RunPendingTasks(); // Run posted deadline. | 479 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 449 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 1); | 480 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 1); |
| 450 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 481 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
| 451 EXPECT_TRUE(client.needs_begin_frames()); | 482 EXPECT_TRUE(client.needs_begin_frames()); |
| 452 client.Reset(); | 483 client.Reset(); |
| 453 | 484 |
| 454 // The following BeginImplFrame deadline should SetNeedsBeginFrame(false) | 485 // The following BeginImplFrame deadline should SetNeedsBeginFrame(false) |
| 455 // to avoid excessive toggles. | 486 // to avoid excessive toggles. |
| 456 client.AdvanceFrame(); | 487 EXPECT_SCOPED(client.AdvanceFrame()); |
| 457 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); | 488 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); |
| 458 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 489 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 459 client.Reset(); | 490 client.Reset(); |
| 460 | 491 |
| 461 client.task_runner().RunPendingTasks(); // Run posted deadline. | 492 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 462 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(false)", client); | 493 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(false)", client); |
| 463 client.Reset(); | 494 client.Reset(); |
| 464 } | 495 } |
| 465 | 496 |
| 466 TEST(SchedulerTest, RequestCommitAfterBeginMainFrameSent) { | 497 TEST(SchedulerTest, RequestCommitAfterBeginMainFrameSent) { |
| 467 FakeSchedulerClient client; | 498 FakeSchedulerClient client; |
| 468 SchedulerSettings scheduler_settings; | 499 SchedulerSettings scheduler_settings; |
| 469 scheduler_settings.use_external_begin_frame_source = true; | 500 scheduler_settings.use_external_begin_frame_source = true; |
| 470 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings); | |
| 471 scheduler->SetCanStart(); | |
| 472 scheduler->SetVisible(true); | |
| 473 scheduler->SetCanDraw(true); | |
| 474 | 501 |
| 475 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); | 502 CREATE_SCHEDULER_AND_INIT_SURFACE(scheduler_settings); |
| 476 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | |
| 477 client.Reset(); | |
| 478 | 503 |
| 479 // SetNeedsCommit should begin the frame. | 504 // SetNeedsCommit should begin the frame. |
| 480 scheduler->SetNeedsCommit(); | 505 scheduler->SetNeedsCommit(); |
| 481 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client); | 506 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client); |
| 482 | 507 |
| 483 client.Reset(); | 508 client.Reset(); |
| 484 client.AdvanceFrame(); | 509 EXPECT_SCOPED(client.AdvanceFrame()); |
| 485 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 510 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
| 486 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); | 511 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); |
| 487 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 512 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 488 | 513 |
| 489 EXPECT_TRUE(client.needs_begin_frames()); | 514 EXPECT_TRUE(client.needs_begin_frames()); |
| 490 client.Reset(); | 515 client.Reset(); |
| 491 | 516 |
| 492 // Now SetNeedsCommit again. Calling here means we need a second commit. | 517 // Now SetNeedsCommit again. Calling here means we need a second commit. |
| 493 scheduler->SetNeedsCommit(); | 518 scheduler->SetNeedsCommit(); |
| 494 EXPECT_EQ(client.num_actions_(), 0); | 519 EXPECT_EQ(client.num_actions_(), 0); |
| 495 client.Reset(); | 520 client.Reset(); |
| 496 | 521 |
| 497 // Finish the first commit. | 522 // Finish the first commit. |
| 498 scheduler->NotifyBeginMainFrameStarted(); | 523 scheduler->NotifyBeginMainFrameStarted(); |
| 499 scheduler->NotifyReadyToCommit(); | 524 scheduler->NotifyReadyToCommit(); |
| 500 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); | 525 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); |
| 501 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 526 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 502 client.Reset(); | 527 client.Reset(); |
| 503 client.task_runner().RunPendingTasks(); // Run posted deadline. | 528 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 504 EXPECT_ACTION("ScheduledActionAnimate", client, 0, 2); | 529 EXPECT_ACTION("ScheduledActionAnimate", client, 0, 2); |
| 505 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 1, 2); | 530 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 1, 2); |
| 506 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 531 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
| 507 | 532 |
| 508 // Because we just swapped, the Scheduler should also request the next | 533 // Because we just swapped, the Scheduler should also request the next |
| 509 // BeginImplFrame from the OutputSurface. | 534 // BeginImplFrame from the OutputSurface. |
| 510 EXPECT_TRUE(client.needs_begin_frames()); | 535 EXPECT_TRUE(client.needs_begin_frames()); |
| 511 client.Reset(); | 536 client.Reset(); |
| 512 // Since another commit is needed, the next BeginImplFrame should initiate | 537 // Since another commit is needed, the next BeginImplFrame should initiate |
| 513 // the second commit. | 538 // the second commit. |
| 514 client.AdvanceFrame(); | 539 EXPECT_SCOPED(client.AdvanceFrame()); |
| 515 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 540 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
| 516 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); | 541 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); |
| 517 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 542 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 518 client.Reset(); | 543 client.Reset(); |
| 519 | 544 |
| 520 // Finishing the commit before the deadline should post a new deadline task | 545 // Finishing the commit before the deadline should post a new deadline task |
| 521 // to trigger the deadline early. | 546 // to trigger the deadline early. |
| 522 scheduler->NotifyBeginMainFrameStarted(); | 547 scheduler->NotifyBeginMainFrameStarted(); |
| 523 scheduler->NotifyReadyToCommit(); | 548 scheduler->NotifyReadyToCommit(); |
| 524 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); | 549 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); |
| 525 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 550 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 526 client.Reset(); | 551 client.Reset(); |
| 527 client.task_runner().RunPendingTasks(); // Run posted deadline. | 552 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 528 EXPECT_ACTION("ScheduledActionAnimate", client, 0, 2); | 553 EXPECT_ACTION("ScheduledActionAnimate", client, 0, 2); |
| 529 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 1, 2); | 554 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 1, 2); |
| 530 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 555 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
| 531 EXPECT_TRUE(client.needs_begin_frames()); | 556 EXPECT_TRUE(client.needs_begin_frames()); |
| 532 client.Reset(); | 557 client.Reset(); |
| 533 | 558 |
| 534 // On the next BeginImplFrame, verify we go back to a quiescent state and | 559 // On the next BeginImplFrame, verify we go back to a quiescent state and |
| 535 // no longer request BeginImplFrames. | 560 // no longer request BeginImplFrames. |
| 536 client.AdvanceFrame(); | 561 EXPECT_SCOPED(client.AdvanceFrame()); |
| 537 client.task_runner().RunPendingTasks(); // Run posted deadline. | 562 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 538 EXPECT_FALSE(client.needs_begin_frames()); | 563 EXPECT_FALSE(client.needs_begin_frames()); |
| 539 client.Reset(); | 564 client.Reset(); |
| 540 } | 565 } |
| 541 | 566 |
| 542 class SchedulerClientThatsetNeedsDrawInsideDraw : public FakeSchedulerClient { | 567 class SchedulerClientThatsetNeedsDrawInsideDraw : public FakeSchedulerClient { |
| 543 public: | 568 public: |
| 569 SchedulerClientThatsetNeedsDrawInsideDraw() |
| 570 : FakeSchedulerClient(), request_redraws_(false) {} |
| 571 |
| 544 void ScheduledActionSendBeginMainFrame() override {} | 572 void ScheduledActionSendBeginMainFrame() override {} |
| 573 |
| 574 void SetRequestRedrawsInsideDraw(bool enable) { request_redraws_ = enable; } |
| 575 |
| 545 DrawResult ScheduledActionDrawAndSwapIfPossible() override { | 576 DrawResult ScheduledActionDrawAndSwapIfPossible() override { |
| 546 // Only SetNeedsRedraw the first time this is called | 577 // Only SetNeedsRedraw the first time this is called |
| 547 if (!num_draws_) | 578 if (request_redraws_) { |
| 548 scheduler_->SetNeedsRedraw(); | 579 scheduler_->SetNeedsRedraw(); |
| 580 } |
| 549 return FakeSchedulerClient::ScheduledActionDrawAndSwapIfPossible(); | 581 return FakeSchedulerClient::ScheduledActionDrawAndSwapIfPossible(); |
| 550 } | 582 } |
| 551 | 583 |
| 552 DrawResult ScheduledActionDrawAndSwapForced() override { | 584 DrawResult ScheduledActionDrawAndSwapForced() override { |
| 553 NOTREACHED(); | 585 NOTREACHED(); |
| 554 return DRAW_SUCCESS; | 586 return DRAW_SUCCESS; |
| 555 } | 587 } |
| 556 | 588 |
| 557 void ScheduledActionCommit() override {} | 589 void ScheduledActionCommit() override {} |
| 558 void ScheduledActionBeginOutputSurfaceCreation() override {} | |
| 559 void DidAnticipatedDrawTimeChange(base::TimeTicks) override {} | 590 void DidAnticipatedDrawTimeChange(base::TimeTicks) override {} |
| 591 |
| 592 private: |
| 593 bool request_redraws_; |
| 560 }; | 594 }; |
| 561 | 595 |
| 562 // Tests for two different situations: | 596 // Tests for two different situations: |
| 563 // 1. the scheduler dropping SetNeedsRedraw requests that happen inside | 597 // 1. the scheduler dropping SetNeedsRedraw requests that happen inside |
| 564 // a ScheduledActionDrawAndSwap | 598 // a ScheduledActionDrawAndSwap |
| 565 // 2. the scheduler drawing twice inside a single tick | 599 // 2. the scheduler drawing twice inside a single tick |
| 566 TEST(SchedulerTest, RequestRedrawInsideDraw) { | 600 TEST(SchedulerTest, RequestRedrawInsideDraw) { |
| 567 SchedulerClientThatsetNeedsDrawInsideDraw client; | 601 SchedulerClientThatsetNeedsDrawInsideDraw client; |
| 568 SchedulerSettings scheduler_settings; | 602 SchedulerSettings scheduler_settings; |
| 569 scheduler_settings.use_external_begin_frame_source = true; | 603 scheduler_settings.use_external_begin_frame_source = true; |
| 570 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings); | 604 |
| 571 scheduler->SetCanStart(); | 605 CREATE_SCHEDULER_AND_INIT_SURFACE(scheduler_settings); |
| 572 scheduler->SetVisible(true); | 606 client.SetRequestRedrawsInsideDraw(true); |
| 573 scheduler->SetCanDraw(true); | |
| 574 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | |
| 575 client.Reset(); | |
| 576 | 607 |
| 577 scheduler->SetNeedsRedraw(); | 608 scheduler->SetNeedsRedraw(); |
| 578 EXPECT_TRUE(scheduler->RedrawPending()); | 609 EXPECT_TRUE(scheduler->RedrawPending()); |
| 579 EXPECT_TRUE(client.needs_begin_frames()); | 610 EXPECT_TRUE(client.needs_begin_frames()); |
| 580 EXPECT_EQ(0, client.num_draws()); | 611 EXPECT_EQ(0, client.num_draws()); |
| 581 | 612 |
| 582 client.AdvanceFrame(); | 613 EXPECT_SCOPED(client.AdvanceFrame()); |
| 583 client.task_runner().RunPendingTasks(); // Run posted deadline. | 614 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 584 EXPECT_EQ(1, client.num_draws()); | 615 EXPECT_EQ(1, client.num_draws()); |
| 585 EXPECT_TRUE(scheduler->RedrawPending()); | 616 EXPECT_TRUE(scheduler->RedrawPending()); |
| 586 EXPECT_TRUE(client.needs_begin_frames()); | 617 EXPECT_TRUE(client.needs_begin_frames()); |
| 587 | 618 |
| 588 client.AdvanceFrame(); | 619 client.SetRequestRedrawsInsideDraw(false); |
| 620 |
| 621 EXPECT_SCOPED(client.AdvanceFrame()); |
| 589 client.task_runner().RunPendingTasks(); // Run posted deadline. | 622 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 590 EXPECT_EQ(2, client.num_draws()); | 623 EXPECT_EQ(2, client.num_draws()); |
| 591 EXPECT_FALSE(scheduler->RedrawPending()); | 624 EXPECT_FALSE(scheduler->RedrawPending()); |
| 592 EXPECT_TRUE(client.needs_begin_frames()); | 625 EXPECT_TRUE(client.needs_begin_frames()); |
| 593 | 626 |
| 594 // We stop requesting BeginImplFrames after a BeginImplFrame where we don't | 627 // We stop requesting BeginImplFrames after a BeginImplFrame where we don't |
| 595 // swap. | 628 // swap. |
| 596 client.AdvanceFrame(); | 629 EXPECT_SCOPED(client.AdvanceFrame()); |
| 597 client.task_runner().RunPendingTasks(); // Run posted deadline. | 630 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 598 EXPECT_EQ(2, client.num_draws()); | 631 EXPECT_EQ(2, client.num_draws()); |
| 599 EXPECT_FALSE(scheduler->RedrawPending()); | 632 EXPECT_FALSE(scheduler->RedrawPending()); |
| 600 EXPECT_FALSE(client.needs_begin_frames()); | 633 EXPECT_FALSE(client.needs_begin_frames()); |
| 601 } | 634 } |
| 602 | 635 |
| 603 // Test that requesting redraw inside a failed draw doesn't lose the request. | 636 // Test that requesting redraw inside a failed draw doesn't lose the request. |
| 604 TEST(SchedulerTest, RequestRedrawInsideFailedDraw) { | 637 TEST(SchedulerTest, RequestRedrawInsideFailedDraw) { |
| 605 SchedulerClientThatsetNeedsDrawInsideDraw client; | 638 SchedulerClientThatsetNeedsDrawInsideDraw client; |
| 606 SchedulerSettings scheduler_settings; | 639 SchedulerSettings scheduler_settings; |
| 607 scheduler_settings.use_external_begin_frame_source = true; | 640 scheduler_settings.use_external_begin_frame_source = true; |
| 608 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings); | |
| 609 scheduler->SetCanStart(); | |
| 610 scheduler->SetVisible(true); | |
| 611 scheduler->SetCanDraw(true); | |
| 612 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | |
| 613 client.Reset(); | |
| 614 | 641 |
| 642 CREATE_SCHEDULER_AND_INIT_SURFACE(scheduler_settings); |
| 643 client.SetRequestRedrawsInsideDraw(true); |
| 615 client.SetDrawWillHappen(false); | 644 client.SetDrawWillHappen(false); |
| 616 | 645 |
| 617 scheduler->SetNeedsRedraw(); | 646 scheduler->SetNeedsRedraw(); |
| 618 EXPECT_TRUE(scheduler->RedrawPending()); | 647 EXPECT_TRUE(scheduler->RedrawPending()); |
| 619 EXPECT_TRUE(client.needs_begin_frames()); | 648 EXPECT_TRUE(client.needs_begin_frames()); |
| 620 EXPECT_EQ(0, client.num_draws()); | 649 EXPECT_EQ(0, client.num_draws()); |
| 621 | 650 |
| 622 // Fail the draw. | 651 // Fail the draw. |
| 623 client.AdvanceFrame(); | 652 EXPECT_SCOPED(client.AdvanceFrame()); |
| 624 client.task_runner().RunPendingTasks(); // Run posted deadline. | 653 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 625 EXPECT_EQ(1, client.num_draws()); | 654 EXPECT_EQ(1, client.num_draws()); |
| 626 | 655 |
| 627 // We have a commit pending and the draw failed, and we didn't lose the redraw | 656 // We have a commit pending and the draw failed, and we didn't lose the redraw |
| 628 // request. | 657 // request. |
| 629 EXPECT_TRUE(scheduler->CommitPending()); | 658 EXPECT_TRUE(scheduler->CommitPending()); |
| 630 EXPECT_TRUE(scheduler->RedrawPending()); | 659 EXPECT_TRUE(scheduler->RedrawPending()); |
| 631 EXPECT_TRUE(client.needs_begin_frames()); | 660 EXPECT_TRUE(client.needs_begin_frames()); |
| 632 | 661 |
| 662 client.SetRequestRedrawsInsideDraw(false); |
| 663 |
| 633 // Fail the draw again. | 664 // Fail the draw again. |
| 634 client.AdvanceFrame(); | 665 EXPECT_SCOPED(client.AdvanceFrame()); |
| 635 client.task_runner().RunPendingTasks(); // Run posted deadline. | 666 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 636 EXPECT_EQ(2, client.num_draws()); | 667 EXPECT_EQ(2, client.num_draws()); |
| 637 EXPECT_TRUE(scheduler->CommitPending()); | 668 EXPECT_TRUE(scheduler->CommitPending()); |
| 638 EXPECT_TRUE(scheduler->RedrawPending()); | 669 EXPECT_TRUE(scheduler->RedrawPending()); |
| 639 EXPECT_TRUE(client.needs_begin_frames()); | 670 EXPECT_TRUE(client.needs_begin_frames()); |
| 640 | 671 |
| 641 // Draw successfully. | 672 // Draw successfully. |
| 642 client.SetDrawWillHappen(true); | 673 client.SetDrawWillHappen(true); |
| 643 client.AdvanceFrame(); | 674 EXPECT_SCOPED(client.AdvanceFrame()); |
| 644 client.task_runner().RunPendingTasks(); // Run posted deadline. | 675 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 645 EXPECT_EQ(3, client.num_draws()); | 676 EXPECT_EQ(3, client.num_draws()); |
| 646 EXPECT_TRUE(scheduler->CommitPending()); | 677 EXPECT_TRUE(scheduler->CommitPending()); |
| 647 EXPECT_FALSE(scheduler->RedrawPending()); | 678 EXPECT_FALSE(scheduler->RedrawPending()); |
| 648 EXPECT_TRUE(client.needs_begin_frames()); | 679 EXPECT_TRUE(client.needs_begin_frames()); |
| 649 } | 680 } |
| 650 | 681 |
| 651 class SchedulerClientThatSetNeedsCommitInsideDraw : public FakeSchedulerClient { | 682 class SchedulerClientThatSetNeedsCommitInsideDraw : public FakeSchedulerClient { |
| 652 public: | 683 public: |
| 653 SchedulerClientThatSetNeedsCommitInsideDraw() | 684 SchedulerClientThatSetNeedsCommitInsideDraw() |
| 654 : set_needs_commit_on_next_draw_(false) {} | 685 : set_needs_commit_on_next_draw_(false) {} |
| 655 | 686 |
| 656 void ScheduledActionSendBeginMainFrame() override {} | 687 void ScheduledActionSendBeginMainFrame() override {} |
| 657 DrawResult ScheduledActionDrawAndSwapIfPossible() override { | 688 DrawResult ScheduledActionDrawAndSwapIfPossible() override { |
| 658 // Only SetNeedsCommit the first time this is called | 689 // Only SetNeedsCommit the first time this is called |
| 659 if (set_needs_commit_on_next_draw_) { | 690 if (set_needs_commit_on_next_draw_) { |
| 660 scheduler_->SetNeedsCommit(); | 691 scheduler_->SetNeedsCommit(); |
| 661 set_needs_commit_on_next_draw_ = false; | 692 set_needs_commit_on_next_draw_ = false; |
| 662 } | 693 } |
| 663 return FakeSchedulerClient::ScheduledActionDrawAndSwapIfPossible(); | 694 return FakeSchedulerClient::ScheduledActionDrawAndSwapIfPossible(); |
| 664 } | 695 } |
| 665 | 696 |
| 666 DrawResult ScheduledActionDrawAndSwapForced() override { | 697 DrawResult ScheduledActionDrawAndSwapForced() override { |
| 667 NOTREACHED(); | 698 NOTREACHED(); |
| 668 return DRAW_SUCCESS; | 699 return DRAW_SUCCESS; |
| 669 } | 700 } |
| 670 | 701 |
| 671 void ScheduledActionCommit() override {} | 702 void ScheduledActionCommit() override {} |
| 672 void ScheduledActionBeginOutputSurfaceCreation() override {} | |
| 673 void DidAnticipatedDrawTimeChange(base::TimeTicks) override {} | 703 void DidAnticipatedDrawTimeChange(base::TimeTicks) override {} |
| 674 | 704 |
| 675 void SetNeedsCommitOnNextDraw() { set_needs_commit_on_next_draw_ = true; } | 705 void SetNeedsCommitOnNextDraw() { set_needs_commit_on_next_draw_ = true; } |
| 676 | 706 |
| 677 private: | 707 private: |
| 678 bool set_needs_commit_on_next_draw_; | 708 bool set_needs_commit_on_next_draw_; |
| 679 }; | 709 }; |
| 680 | 710 |
| 681 // Tests for the scheduler infinite-looping on SetNeedsCommit requests that | 711 // Tests for the scheduler infinite-looping on SetNeedsCommit requests that |
| 682 // happen inside a ScheduledActionDrawAndSwap | 712 // happen inside a ScheduledActionDrawAndSwap |
| 683 TEST(SchedulerTest, RequestCommitInsideDraw) { | 713 TEST(SchedulerTest, RequestCommitInsideDraw) { |
| 684 SchedulerClientThatSetNeedsCommitInsideDraw client; | 714 SchedulerClientThatSetNeedsCommitInsideDraw client; |
| 685 SchedulerSettings scheduler_settings; | 715 SchedulerSettings scheduler_settings; |
| 686 scheduler_settings.use_external_begin_frame_source = true; | 716 scheduler_settings.use_external_begin_frame_source = true; |
| 687 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings); | 717 |
| 688 scheduler->SetCanStart(); | 718 CREATE_SCHEDULER_AND_INIT_SURFACE(scheduler_settings); |
| 689 scheduler->SetVisible(true); | |
| 690 scheduler->SetCanDraw(true); | |
| 691 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | |
| 692 client.Reset(); | |
| 693 | 719 |
| 694 EXPECT_FALSE(client.needs_begin_frames()); | 720 EXPECT_FALSE(client.needs_begin_frames()); |
| 695 scheduler->SetNeedsRedraw(); | 721 scheduler->SetNeedsRedraw(); |
| 696 EXPECT_TRUE(scheduler->RedrawPending()); | 722 EXPECT_TRUE(scheduler->RedrawPending()); |
| 697 EXPECT_EQ(0, client.num_draws()); | 723 EXPECT_EQ(0, client.num_draws()); |
| 698 EXPECT_TRUE(client.needs_begin_frames()); | 724 EXPECT_TRUE(client.needs_begin_frames()); |
| 699 | 725 |
| 700 client.SetNeedsCommitOnNextDraw(); | 726 client.SetNeedsCommitOnNextDraw(); |
| 701 client.AdvanceFrame(); | 727 EXPECT_SCOPED(client.AdvanceFrame()); |
| 702 client.SetNeedsCommitOnNextDraw(); | 728 client.SetNeedsCommitOnNextDraw(); |
| 703 client.task_runner().RunPendingTasks(); // Run posted deadline. | 729 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 704 EXPECT_EQ(1, client.num_draws()); | 730 EXPECT_EQ(1, client.num_draws()); |
| 705 EXPECT_TRUE(scheduler->CommitPending()); | 731 EXPECT_TRUE(scheduler->CommitPending()); |
| 706 EXPECT_TRUE(client.needs_begin_frames()); | 732 EXPECT_TRUE(client.needs_begin_frames()); |
| 707 scheduler->NotifyBeginMainFrameStarted(); | 733 scheduler->NotifyBeginMainFrameStarted(); |
| 708 scheduler->NotifyReadyToCommit(); | 734 scheduler->NotifyReadyToCommit(); |
| 709 | 735 |
| 710 client.AdvanceFrame(); | 736 EXPECT_SCOPED(client.AdvanceFrame()); |
| 711 client.task_runner().RunPendingTasks(); // Run posted deadline. | 737 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 712 EXPECT_EQ(2, client.num_draws()); | 738 EXPECT_EQ(2, client.num_draws()); |
| 713 | 739 |
| 714 EXPECT_FALSE(scheduler->RedrawPending()); | 740 EXPECT_FALSE(scheduler->RedrawPending()); |
| 715 EXPECT_FALSE(scheduler->CommitPending()); | 741 EXPECT_FALSE(scheduler->CommitPending()); |
| 716 EXPECT_TRUE(client.needs_begin_frames()); | 742 EXPECT_TRUE(client.needs_begin_frames()); |
| 717 | 743 |
| 718 // We stop requesting BeginImplFrames after a BeginImplFrame where we don't | 744 // We stop requesting BeginImplFrames after a BeginImplFrame where we don't |
| 719 // swap. | 745 // swap. |
| 720 client.AdvanceFrame(); | 746 EXPECT_SCOPED(client.AdvanceFrame()); |
| 721 client.task_runner().RunPendingTasks(); // Run posted deadline. | 747 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 722 EXPECT_EQ(2, client.num_draws()); | 748 EXPECT_EQ(2, client.num_draws()); |
| 723 EXPECT_FALSE(scheduler->RedrawPending()); | 749 EXPECT_FALSE(scheduler->RedrawPending()); |
| 724 EXPECT_FALSE(scheduler->CommitPending()); | 750 EXPECT_FALSE(scheduler->CommitPending()); |
| 725 EXPECT_FALSE(client.needs_begin_frames()); | 751 EXPECT_FALSE(client.needs_begin_frames()); |
| 726 } | 752 } |
| 727 | 753 |
| 728 // Tests that when a draw fails then the pending commit should not be dropped. | 754 // Tests that when a draw fails then the pending commit should not be dropped. |
| 729 TEST(SchedulerTest, RequestCommitInsideFailedDraw) { | 755 TEST(SchedulerTest, RequestCommitInsideFailedDraw) { |
| 730 SchedulerClientThatsetNeedsDrawInsideDraw client; | 756 SchedulerClientThatsetNeedsDrawInsideDraw client; |
| 731 SchedulerSettings scheduler_settings; | 757 SchedulerSettings scheduler_settings; |
| 732 scheduler_settings.use_external_begin_frame_source = true; | 758 scheduler_settings.use_external_begin_frame_source = true; |
| 733 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings); | 759 |
| 734 scheduler->SetCanStart(); | 760 CREATE_SCHEDULER_AND_INIT_SURFACE(scheduler_settings); |
| 735 scheduler->SetVisible(true); | |
| 736 scheduler->SetCanDraw(true); | |
| 737 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | |
| 738 client.Reset(); | |
| 739 | 761 |
| 740 client.SetDrawWillHappen(false); | 762 client.SetDrawWillHappen(false); |
| 741 | 763 |
| 742 scheduler->SetNeedsRedraw(); | 764 scheduler->SetNeedsRedraw(); |
| 743 EXPECT_TRUE(scheduler->RedrawPending()); | 765 EXPECT_TRUE(scheduler->RedrawPending()); |
| 744 EXPECT_TRUE(client.needs_begin_frames()); | 766 EXPECT_TRUE(client.needs_begin_frames()); |
| 745 EXPECT_EQ(0, client.num_draws()); | 767 EXPECT_EQ(0, client.num_draws()); |
| 746 | 768 |
| 747 // Fail the draw. | 769 // Fail the draw. |
| 748 client.AdvanceFrame(); | 770 EXPECT_SCOPED(client.AdvanceFrame()); |
| 749 client.task_runner().RunPendingTasks(); // Run posted deadline. | 771 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 750 EXPECT_EQ(1, client.num_draws()); | 772 EXPECT_EQ(1, client.num_draws()); |
| 751 | 773 |
| 752 // We have a commit pending and the draw failed, and we didn't lose the commit | 774 // We have a commit pending and the draw failed, and we didn't lose the commit |
| 753 // request. | 775 // request. |
| 754 EXPECT_TRUE(scheduler->CommitPending()); | 776 EXPECT_TRUE(scheduler->CommitPending()); |
| 755 EXPECT_TRUE(scheduler->RedrawPending()); | 777 EXPECT_TRUE(scheduler->RedrawPending()); |
| 756 EXPECT_TRUE(client.needs_begin_frames()); | 778 EXPECT_TRUE(client.needs_begin_frames()); |
| 757 | 779 |
| 758 // Fail the draw again. | 780 // Fail the draw again. |
| 759 client.AdvanceFrame(); | 781 EXPECT_SCOPED(client.AdvanceFrame()); |
| 760 | 782 |
| 761 client.task_runner().RunPendingTasks(); // Run posted deadline. | 783 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 762 EXPECT_EQ(2, client.num_draws()); | 784 EXPECT_EQ(2, client.num_draws()); |
| 763 EXPECT_TRUE(scheduler->CommitPending()); | 785 EXPECT_TRUE(scheduler->CommitPending()); |
| 764 EXPECT_TRUE(scheduler->RedrawPending()); | 786 EXPECT_TRUE(scheduler->RedrawPending()); |
| 765 EXPECT_TRUE(client.needs_begin_frames()); | 787 EXPECT_TRUE(client.needs_begin_frames()); |
| 766 | 788 |
| 767 // Draw successfully. | 789 // Draw successfully. |
| 768 client.SetDrawWillHappen(true); | 790 client.SetDrawWillHappen(true); |
| 769 client.AdvanceFrame(); | 791 EXPECT_SCOPED(client.AdvanceFrame()); |
| 770 client.task_runner().RunPendingTasks(); // Run posted deadline. | 792 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 771 EXPECT_EQ(3, client.num_draws()); | 793 EXPECT_EQ(3, client.num_draws()); |
| 772 EXPECT_TRUE(scheduler->CommitPending()); | 794 EXPECT_TRUE(scheduler->CommitPending()); |
| 773 EXPECT_FALSE(scheduler->RedrawPending()); | 795 EXPECT_FALSE(scheduler->RedrawPending()); |
| 774 EXPECT_TRUE(client.needs_begin_frames()); | 796 EXPECT_TRUE(client.needs_begin_frames()); |
| 775 } | 797 } |
| 776 | 798 |
| 777 TEST(SchedulerTest, NoSwapWhenDrawFails) { | 799 TEST(SchedulerTest, NoSwapWhenDrawFails) { |
| 778 SchedulerClientThatSetNeedsCommitInsideDraw client; | 800 SchedulerClientThatSetNeedsCommitInsideDraw client; |
| 779 SchedulerSettings scheduler_settings; | 801 SchedulerSettings scheduler_settings; |
| 780 scheduler_settings.use_external_begin_frame_source = true; | 802 scheduler_settings.use_external_begin_frame_source = true; |
| 781 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings); | 803 |
| 782 scheduler->SetCanStart(); | 804 CREATE_SCHEDULER_AND_INIT_SURFACE(scheduler_settings); |
| 783 scheduler->SetVisible(true); | |
| 784 scheduler->SetCanDraw(true); | |
| 785 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | |
| 786 client.Reset(); | |
| 787 | 805 |
| 788 scheduler->SetNeedsRedraw(); | 806 scheduler->SetNeedsRedraw(); |
| 789 EXPECT_TRUE(scheduler->RedrawPending()); | 807 EXPECT_TRUE(scheduler->RedrawPending()); |
| 790 EXPECT_TRUE(client.needs_begin_frames()); | 808 EXPECT_TRUE(client.needs_begin_frames()); |
| 791 EXPECT_EQ(0, client.num_draws()); | 809 EXPECT_EQ(0, client.num_draws()); |
| 792 | 810 |
| 793 // Draw successfully, this starts a new frame. | 811 // Draw successfully, this starts a new frame. |
| 794 client.SetNeedsCommitOnNextDraw(); | 812 client.SetNeedsCommitOnNextDraw(); |
| 795 client.AdvanceFrame(); | 813 EXPECT_SCOPED(client.AdvanceFrame()); |
| 796 client.task_runner().RunPendingTasks(); // Run posted deadline. | 814 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 797 EXPECT_EQ(1, client.num_draws()); | 815 EXPECT_EQ(1, client.num_draws()); |
| 798 | 816 |
| 799 scheduler->SetNeedsRedraw(); | 817 scheduler->SetNeedsRedraw(); |
| 800 EXPECT_TRUE(scheduler->RedrawPending()); | 818 EXPECT_TRUE(scheduler->RedrawPending()); |
| 801 EXPECT_TRUE(client.needs_begin_frames()); | 819 EXPECT_TRUE(client.needs_begin_frames()); |
| 802 | 820 |
| 803 // Fail to draw, this should not start a frame. | 821 // Fail to draw, this should not start a frame. |
| 804 client.SetDrawWillHappen(false); | 822 client.SetDrawWillHappen(false); |
| 805 client.SetNeedsCommitOnNextDraw(); | 823 client.SetNeedsCommitOnNextDraw(); |
| 806 client.AdvanceFrame(); | 824 EXPECT_SCOPED(client.AdvanceFrame()); |
| 807 client.task_runner().RunPendingTasks(); // Run posted deadline. | 825 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 808 EXPECT_EQ(2, client.num_draws()); | 826 EXPECT_EQ(2, client.num_draws()); |
| 809 } | 827 } |
| 810 | 828 |
| 811 class SchedulerClientNeedsPrepareTilesInDraw : public FakeSchedulerClient { | 829 class SchedulerClientNeedsPrepareTilesInDraw : public FakeSchedulerClient { |
| 812 public: | 830 public: |
| 813 DrawResult ScheduledActionDrawAndSwapIfPossible() override { | 831 DrawResult ScheduledActionDrawAndSwapIfPossible() override { |
| 814 scheduler_->SetNeedsPrepareTiles(); | 832 scheduler_->SetNeedsPrepareTiles(); |
| 815 return FakeSchedulerClient::ScheduledActionDrawAndSwapIfPossible(); | 833 return FakeSchedulerClient::ScheduledActionDrawAndSwapIfPossible(); |
| 816 } | 834 } |
| 817 }; | 835 }; |
| 818 | 836 |
| 819 // Test prepare tiles is independant of draws. | 837 // Test prepare tiles is independant of draws. |
| 820 TEST(SchedulerTest, PrepareTiles) { | 838 TEST(SchedulerTest, PrepareTiles) { |
| 821 SchedulerClientNeedsPrepareTilesInDraw client; | 839 SchedulerClientNeedsPrepareTilesInDraw client; |
| 822 SchedulerSettings scheduler_settings; | 840 SchedulerSettings scheduler_settings; |
| 823 scheduler_settings.use_external_begin_frame_source = true; | 841 scheduler_settings.use_external_begin_frame_source = true; |
| 824 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings); | 842 |
| 825 scheduler->SetCanStart(); | 843 CREATE_SCHEDULER_AND_INIT_SURFACE(scheduler_settings); |
| 826 scheduler->SetVisible(true); | |
| 827 scheduler->SetCanDraw(true); | |
| 828 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | |
| 829 | 844 |
| 830 // Request both draw and prepare tiles. PrepareTiles shouldn't | 845 // Request both draw and prepare tiles. PrepareTiles shouldn't |
| 831 // be trigged until BeginImplFrame. | 846 // be trigged until BeginImplFrame. |
| 832 client.Reset(); | 847 client.Reset(); |
| 833 scheduler->SetNeedsPrepareTiles(); | 848 scheduler->SetNeedsPrepareTiles(); |
| 834 scheduler->SetNeedsRedraw(); | 849 scheduler->SetNeedsRedraw(); |
| 835 EXPECT_TRUE(scheduler->RedrawPending()); | 850 EXPECT_TRUE(scheduler->RedrawPending()); |
| 836 EXPECT_TRUE(scheduler->PrepareTilesPending()); | 851 EXPECT_TRUE(scheduler->PrepareTilesPending()); |
| 837 EXPECT_TRUE(client.needs_begin_frames()); | 852 EXPECT_TRUE(client.needs_begin_frames()); |
| 838 EXPECT_EQ(0, client.num_draws()); | 853 EXPECT_EQ(0, client.num_draws()); |
| 839 EXPECT_FALSE(client.HasAction("ScheduledActionPrepareTiles")); | 854 EXPECT_FALSE(client.HasAction("ScheduledActionPrepareTiles")); |
| 840 EXPECT_FALSE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); | 855 EXPECT_FALSE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); |
| 841 | 856 |
| 842 // We have no immediate actions to perform, so the BeginImplFrame should post | 857 // We have no immediate actions to perform, so the BeginImplFrame should post |
| 843 // the deadline task. | 858 // the deadline task. |
| 844 client.Reset(); | 859 client.Reset(); |
| 845 client.AdvanceFrame(); | 860 EXPECT_SCOPED(client.AdvanceFrame()); |
| 846 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 861 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
| 847 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); | 862 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); |
| 848 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 863 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 849 | 864 |
| 850 // On the deadline, he actions should have occured in the right order. | 865 // On the deadline, he actions should have occured in the right order. |
| 851 client.Reset(); | 866 client.Reset(); |
| 852 client.task_runner().RunPendingTasks(); // Run posted deadline. | 867 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 853 EXPECT_EQ(1, client.num_draws()); | 868 EXPECT_EQ(1, client.num_draws()); |
| 854 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); | 869 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); |
| 855 EXPECT_TRUE(client.HasAction("ScheduledActionPrepareTiles")); | 870 EXPECT_TRUE(client.HasAction("ScheduledActionPrepareTiles")); |
| 856 EXPECT_LT(client.ActionIndex("ScheduledActionDrawAndSwapIfPossible"), | 871 EXPECT_LT(client.ActionIndex("ScheduledActionDrawAndSwapIfPossible"), |
| 857 client.ActionIndex("ScheduledActionPrepareTiles")); | 872 client.ActionIndex("ScheduledActionPrepareTiles")); |
| 858 EXPECT_FALSE(scheduler->RedrawPending()); | 873 EXPECT_FALSE(scheduler->RedrawPending()); |
| 859 EXPECT_FALSE(scheduler->PrepareTilesPending()); | 874 EXPECT_FALSE(scheduler->PrepareTilesPending()); |
| 860 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 875 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
| 861 | 876 |
| 862 // Request a draw. We don't need a PrepareTiles yet. | 877 // Request a draw. We don't need a PrepareTiles yet. |
| 863 client.Reset(); | 878 client.Reset(); |
| 864 scheduler->SetNeedsRedraw(); | 879 scheduler->SetNeedsRedraw(); |
| 865 EXPECT_TRUE(scheduler->RedrawPending()); | 880 EXPECT_TRUE(scheduler->RedrawPending()); |
| 866 EXPECT_FALSE(scheduler->PrepareTilesPending()); | 881 EXPECT_FALSE(scheduler->PrepareTilesPending()); |
| 867 EXPECT_TRUE(client.needs_begin_frames()); | 882 EXPECT_TRUE(client.needs_begin_frames()); |
| 868 EXPECT_EQ(0, client.num_draws()); | 883 EXPECT_EQ(0, client.num_draws()); |
| 869 | 884 |
| 870 // We have no immediate actions to perform, so the BeginImplFrame should post | 885 // We have no immediate actions to perform, so the BeginImplFrame should post |
| 871 // the deadline task. | 886 // the deadline task. |
| 872 client.Reset(); | 887 client.Reset(); |
| 873 client.AdvanceFrame(); | 888 EXPECT_SCOPED(client.AdvanceFrame()); |
| 874 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 889 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
| 875 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); | 890 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); |
| 876 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 891 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 877 | 892 |
| 878 // Draw. The draw will trigger SetNeedsPrepareTiles, and | 893 // Draw. The draw will trigger SetNeedsPrepareTiles, and |
| 879 // then the PrepareTiles action will be triggered after the Draw. | 894 // then the PrepareTiles action will be triggered after the Draw. |
| 880 // Afterwards, neither a draw nor PrepareTiles are pending. | 895 // Afterwards, neither a draw nor PrepareTiles are pending. |
| 881 client.Reset(); | 896 client.Reset(); |
| 882 client.task_runner().RunPendingTasks(); // Run posted deadline. | 897 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 883 EXPECT_EQ(1, client.num_draws()); | 898 EXPECT_EQ(1, client.num_draws()); |
| 884 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); | 899 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); |
| 885 EXPECT_TRUE(client.HasAction("ScheduledActionPrepareTiles")); | 900 EXPECT_TRUE(client.HasAction("ScheduledActionPrepareTiles")); |
| 886 EXPECT_LT(client.ActionIndex("ScheduledActionDrawAndSwapIfPossible"), | 901 EXPECT_LT(client.ActionIndex("ScheduledActionDrawAndSwapIfPossible"), |
| 887 client.ActionIndex("ScheduledActionPrepareTiles")); | 902 client.ActionIndex("ScheduledActionPrepareTiles")); |
| 888 EXPECT_FALSE(scheduler->RedrawPending()); | 903 EXPECT_FALSE(scheduler->RedrawPending()); |
| 889 EXPECT_FALSE(scheduler->PrepareTilesPending()); | 904 EXPECT_FALSE(scheduler->PrepareTilesPending()); |
| 890 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 905 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
| 891 | 906 |
| 892 // We need a BeginImplFrame where we don't swap to go idle. | 907 // We need a BeginImplFrame where we don't swap to go idle. |
| 893 client.Reset(); | 908 client.Reset(); |
| 894 client.AdvanceFrame(); | 909 EXPECT_SCOPED(client.AdvanceFrame()); |
| 895 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); | 910 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); |
| 896 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 911 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 897 client.Reset(); | 912 client.Reset(); |
| 898 client.task_runner().RunPendingTasks(); // Run posted deadline. | 913 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 899 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(false)", client); | 914 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(false)", client); |
| 900 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 915 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
| 901 EXPECT_EQ(0, client.num_draws()); | 916 EXPECT_EQ(0, client.num_draws()); |
| 902 | 917 |
| 903 // Now trigger a PrepareTiles outside of a draw. We will then need | 918 // Now trigger a PrepareTiles outside of a draw. We will then need |
| 904 // a begin-frame for the PrepareTiles, but we don't need a draw. | 919 // a begin-frame for the PrepareTiles, but we don't need a draw. |
| 905 client.Reset(); | 920 client.Reset(); |
| 906 EXPECT_FALSE(client.needs_begin_frames()); | 921 EXPECT_FALSE(client.needs_begin_frames()); |
| 907 scheduler->SetNeedsPrepareTiles(); | 922 scheduler->SetNeedsPrepareTiles(); |
| 908 EXPECT_TRUE(client.needs_begin_frames()); | 923 EXPECT_TRUE(client.needs_begin_frames()); |
| 909 EXPECT_TRUE(scheduler->PrepareTilesPending()); | 924 EXPECT_TRUE(scheduler->PrepareTilesPending()); |
| 910 EXPECT_FALSE(scheduler->RedrawPending()); | 925 EXPECT_FALSE(scheduler->RedrawPending()); |
| 911 | 926 |
| 912 // BeginImplFrame. There will be no draw, only PrepareTiles. | 927 // BeginImplFrame. There will be no draw, only PrepareTiles. |
| 913 client.Reset(); | 928 client.Reset(); |
| 914 client.AdvanceFrame(); | 929 EXPECT_SCOPED(client.AdvanceFrame()); |
| 915 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); | 930 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); |
| 916 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 931 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 917 client.Reset(); | 932 client.Reset(); |
| 918 client.task_runner().RunPendingTasks(); // Run posted deadline. | 933 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 919 EXPECT_EQ(0, client.num_draws()); | 934 EXPECT_EQ(0, client.num_draws()); |
| 920 EXPECT_FALSE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); | 935 EXPECT_FALSE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); |
| 921 EXPECT_TRUE(client.HasAction("ScheduledActionPrepareTiles")); | 936 EXPECT_TRUE(client.HasAction("ScheduledActionPrepareTiles")); |
| 922 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 937 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
| 923 } | 938 } |
| 924 | 939 |
| 925 // Test that PrepareTiles only happens once per frame. If an external caller | 940 // Test that PrepareTiles only happens once per frame. If an external caller |
| 926 // initiates it, then the state machine should not PrepareTiles on that frame. | 941 // initiates it, then the state machine should not PrepareTiles on that frame. |
| 927 TEST(SchedulerTest, PrepareTilesOncePerFrame) { | 942 TEST(SchedulerTest, PrepareTilesOncePerFrame) { |
| 928 FakeSchedulerClient client; | 943 FakeSchedulerClient client; |
| 929 SchedulerSettings scheduler_settings; | 944 SchedulerSettings scheduler_settings; |
| 930 scheduler_settings.use_external_begin_frame_source = true; | 945 scheduler_settings.use_external_begin_frame_source = true; |
| 931 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings); | 946 |
| 932 scheduler->SetCanStart(); | 947 CREATE_SCHEDULER_AND_INIT_SURFACE(scheduler_settings); |
| 933 scheduler->SetVisible(true); | |
| 934 scheduler->SetCanDraw(true); | |
| 935 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | |
| 936 | 948 |
| 937 // If DidPrepareTiles during a frame, then PrepareTiles should not occur | 949 // If DidPrepareTiles during a frame, then PrepareTiles should not occur |
| 938 // again. | 950 // again. |
| 939 scheduler->SetNeedsPrepareTiles(); | 951 scheduler->SetNeedsPrepareTiles(); |
| 940 scheduler->SetNeedsRedraw(); | 952 scheduler->SetNeedsRedraw(); |
| 941 client.Reset(); | 953 client.Reset(); |
| 942 client.AdvanceFrame(); | 954 EXPECT_SCOPED(client.AdvanceFrame()); |
| 943 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 955 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
| 944 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); | 956 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); |
| 945 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 957 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 946 | 958 |
| 947 EXPECT_TRUE(scheduler->PrepareTilesPending()); | 959 EXPECT_TRUE(scheduler->PrepareTilesPending()); |
| 948 scheduler->DidPrepareTiles(); // An explicit PrepareTiles. | 960 scheduler->DidPrepareTiles(); // An explicit PrepareTiles. |
| 949 EXPECT_FALSE(scheduler->PrepareTilesPending()); | 961 EXPECT_FALSE(scheduler->PrepareTilesPending()); |
| 950 | 962 |
| 951 client.Reset(); | 963 client.Reset(); |
| 952 client.task_runner().RunPendingTasks(); // Run posted deadline. | 964 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 953 EXPECT_EQ(1, client.num_draws()); | 965 EXPECT_EQ(1, client.num_draws()); |
| 954 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); | 966 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); |
| 955 EXPECT_FALSE(client.HasAction("ScheduledActionPrepareTiles")); | 967 EXPECT_FALSE(client.HasAction("ScheduledActionPrepareTiles")); |
| 956 EXPECT_FALSE(scheduler->RedrawPending()); | 968 EXPECT_FALSE(scheduler->RedrawPending()); |
| 957 EXPECT_FALSE(scheduler->PrepareTilesPending()); | 969 EXPECT_FALSE(scheduler->PrepareTilesPending()); |
| 958 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 970 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
| 959 | 971 |
| 960 // Next frame without DidPrepareTiles should PrepareTiles with draw. | 972 // Next frame without DidPrepareTiles should PrepareTiles with draw. |
| 961 scheduler->SetNeedsPrepareTiles(); | 973 scheduler->SetNeedsPrepareTiles(); |
| 962 scheduler->SetNeedsRedraw(); | 974 scheduler->SetNeedsRedraw(); |
| 963 client.Reset(); | 975 client.Reset(); |
| 964 client.AdvanceFrame(); | 976 EXPECT_SCOPED(client.AdvanceFrame()); |
| 965 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 977 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
| 966 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); | 978 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); |
| 967 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 979 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 968 | 980 |
| 969 client.Reset(); | 981 client.Reset(); |
| 970 client.task_runner().RunPendingTasks(); // Run posted deadline. | 982 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 971 EXPECT_EQ(1, client.num_draws()); | 983 EXPECT_EQ(1, client.num_draws()); |
| 972 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); | 984 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); |
| 973 EXPECT_TRUE(client.HasAction("ScheduledActionPrepareTiles")); | 985 EXPECT_TRUE(client.HasAction("ScheduledActionPrepareTiles")); |
| 974 EXPECT_LT(client.ActionIndex("ScheduledActionDrawAndSwapIfPossible"), | 986 EXPECT_LT(client.ActionIndex("ScheduledActionDrawAndSwapIfPossible"), |
| 975 client.ActionIndex("ScheduledActionPrepareTiles")); | 987 client.ActionIndex("ScheduledActionPrepareTiles")); |
| 976 EXPECT_FALSE(scheduler->RedrawPending()); | 988 EXPECT_FALSE(scheduler->RedrawPending()); |
| 977 EXPECT_FALSE(scheduler->PrepareTilesPending()); | 989 EXPECT_FALSE(scheduler->PrepareTilesPending()); |
| 978 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 990 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
| 979 scheduler->DidPrepareTiles(); // Corresponds to ScheduledActionPrepareTiles | 991 scheduler->DidPrepareTiles(); // Corresponds to ScheduledActionPrepareTiles |
| 980 | 992 |
| 981 // If we get another DidPrepareTiles within the same frame, we should | 993 // If we get another DidPrepareTiles within the same frame, we should |
| 982 // not PrepareTiles on the next frame. | 994 // not PrepareTiles on the next frame. |
| 983 scheduler->DidPrepareTiles(); // An explicit PrepareTiles. | 995 scheduler->DidPrepareTiles(); // An explicit PrepareTiles. |
| 984 scheduler->SetNeedsPrepareTiles(); | 996 scheduler->SetNeedsPrepareTiles(); |
| 985 scheduler->SetNeedsRedraw(); | 997 scheduler->SetNeedsRedraw(); |
| 986 client.Reset(); | 998 client.Reset(); |
| 987 client.AdvanceFrame(); | 999 EXPECT_SCOPED(client.AdvanceFrame()); |
| 988 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 1000 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
| 989 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); | 1001 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); |
| 990 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1002 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 991 | 1003 |
| 992 EXPECT_TRUE(scheduler->PrepareTilesPending()); | 1004 EXPECT_TRUE(scheduler->PrepareTilesPending()); |
| 993 | 1005 |
| 994 client.Reset(); | 1006 client.Reset(); |
| 995 client.task_runner().RunPendingTasks(); // Run posted deadline. | 1007 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 996 EXPECT_EQ(1, client.num_draws()); | 1008 EXPECT_EQ(1, client.num_draws()); |
| 997 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); | 1009 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); |
| 998 EXPECT_FALSE(client.HasAction("ScheduledActionPrepareTiles")); | 1010 EXPECT_FALSE(client.HasAction("ScheduledActionPrepareTiles")); |
| 999 EXPECT_FALSE(scheduler->RedrawPending()); | 1011 EXPECT_FALSE(scheduler->RedrawPending()); |
| 1000 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 1012 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
| 1001 | 1013 |
| 1002 // If we get another DidPrepareTiles, we should not PrepareTiles on the next | 1014 // If we get another DidPrepareTiles, we should not PrepareTiles on the next |
| 1003 // frame. This verifies we don't alternate calling PrepareTiles once and | 1015 // frame. This verifies we don't alternate calling PrepareTiles once and |
| 1004 // twice. | 1016 // twice. |
| 1005 EXPECT_TRUE(scheduler->PrepareTilesPending()); | 1017 EXPECT_TRUE(scheduler->PrepareTilesPending()); |
| 1006 scheduler->DidPrepareTiles(); // An explicit PrepareTiles. | 1018 scheduler->DidPrepareTiles(); // An explicit PrepareTiles. |
| 1007 EXPECT_FALSE(scheduler->PrepareTilesPending()); | 1019 EXPECT_FALSE(scheduler->PrepareTilesPending()); |
| 1008 scheduler->SetNeedsPrepareTiles(); | 1020 scheduler->SetNeedsPrepareTiles(); |
| 1009 scheduler->SetNeedsRedraw(); | 1021 scheduler->SetNeedsRedraw(); |
| 1010 client.Reset(); | 1022 client.Reset(); |
| 1011 client.AdvanceFrame(); | 1023 EXPECT_SCOPED(client.AdvanceFrame()); |
| 1012 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 1024 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
| 1013 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); | 1025 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); |
| 1014 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1026 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 1015 | 1027 |
| 1016 EXPECT_TRUE(scheduler->PrepareTilesPending()); | 1028 EXPECT_TRUE(scheduler->PrepareTilesPending()); |
| 1017 | 1029 |
| 1018 client.Reset(); | 1030 client.Reset(); |
| 1019 client.task_runner().RunPendingTasks(); // Run posted deadline. | 1031 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 1020 EXPECT_EQ(1, client.num_draws()); | 1032 EXPECT_EQ(1, client.num_draws()); |
| 1021 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); | 1033 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); |
| 1022 EXPECT_FALSE(client.HasAction("ScheduledActionPrepareTiles")); | 1034 EXPECT_FALSE(client.HasAction("ScheduledActionPrepareTiles")); |
| 1023 EXPECT_FALSE(scheduler->RedrawPending()); | 1035 EXPECT_FALSE(scheduler->RedrawPending()); |
| 1024 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 1036 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
| 1025 | 1037 |
| 1026 // Next frame without DidPrepareTiles should PrepareTiles with draw. | 1038 // Next frame without DidPrepareTiles should PrepareTiles with draw. |
| 1027 scheduler->SetNeedsPrepareTiles(); | 1039 scheduler->SetNeedsPrepareTiles(); |
| 1028 scheduler->SetNeedsRedraw(); | 1040 scheduler->SetNeedsRedraw(); |
| 1029 client.Reset(); | 1041 client.Reset(); |
| 1030 client.AdvanceFrame(); | 1042 EXPECT_SCOPED(client.AdvanceFrame()); |
| 1031 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 1043 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
| 1032 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); | 1044 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); |
| 1033 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1045 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 1034 | 1046 |
| 1035 client.Reset(); | 1047 client.Reset(); |
| 1036 client.task_runner().RunPendingTasks(); // Run posted deadline. | 1048 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 1037 EXPECT_EQ(1, client.num_draws()); | 1049 EXPECT_EQ(1, client.num_draws()); |
| 1038 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); | 1050 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); |
| 1039 EXPECT_TRUE(client.HasAction("ScheduledActionPrepareTiles")); | 1051 EXPECT_TRUE(client.HasAction("ScheduledActionPrepareTiles")); |
| 1040 EXPECT_LT(client.ActionIndex("ScheduledActionDrawAndSwapIfPossible"), | 1052 EXPECT_LT(client.ActionIndex("ScheduledActionDrawAndSwapIfPossible"), |
| 1041 client.ActionIndex("ScheduledActionPrepareTiles")); | 1053 client.ActionIndex("ScheduledActionPrepareTiles")); |
| 1042 EXPECT_FALSE(scheduler->RedrawPending()); | 1054 EXPECT_FALSE(scheduler->RedrawPending()); |
| 1043 EXPECT_FALSE(scheduler->PrepareTilesPending()); | 1055 EXPECT_FALSE(scheduler->PrepareTilesPending()); |
| 1044 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 1056 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
| 1045 scheduler->DidPrepareTiles(); // Corresponds to ScheduledActionPrepareTiles | 1057 scheduler->DidPrepareTiles(); // Corresponds to ScheduledActionPrepareTiles |
| 1046 } | 1058 } |
| 1047 | 1059 |
| 1048 TEST(SchedulerTest, TriggerBeginFrameDeadlineEarly) { | 1060 TEST(SchedulerTest, TriggerBeginFrameDeadlineEarly) { |
| 1049 SchedulerClientNeedsPrepareTilesInDraw client; | 1061 SchedulerClientNeedsPrepareTilesInDraw client; |
| 1050 SchedulerSettings scheduler_settings; | 1062 SchedulerSettings scheduler_settings; |
| 1051 scheduler_settings.use_external_begin_frame_source = true; | 1063 scheduler_settings.use_external_begin_frame_source = true; |
| 1052 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings); | |
| 1053 scheduler->SetCanStart(); | |
| 1054 scheduler->SetVisible(true); | |
| 1055 scheduler->SetCanDraw(true); | |
| 1056 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | |
| 1057 | 1064 |
| 1058 client.Reset(); | 1065 CREATE_SCHEDULER_AND_INIT_SURFACE(scheduler_settings); |
| 1066 |
| 1059 scheduler->SetNeedsRedraw(); | 1067 scheduler->SetNeedsRedraw(); |
| 1060 client.AdvanceFrame(); | 1068 EXPECT_SCOPED(client.AdvanceFrame()); |
| 1061 | 1069 |
| 1062 // The deadline should be zero since there is no work other than drawing | 1070 // The deadline should be zero since there is no work other than drawing |
| 1063 // pending. | 1071 // pending. |
| 1064 EXPECT_EQ(base::TimeTicks(), client.posted_begin_impl_frame_deadline()); | 1072 EXPECT_EQ(base::TimeTicks(), client.posted_begin_impl_frame_deadline()); |
| 1065 } | 1073 } |
| 1066 | 1074 |
| 1067 class SchedulerClientWithFixedEstimates : public FakeSchedulerClient { | 1075 class SchedulerClientWithFixedEstimates : public FakeSchedulerClient { |
| 1068 public: | 1076 public: |
| 1069 SchedulerClientWithFixedEstimates( | 1077 SchedulerClientWithFixedEstimates( |
| 1070 base::TimeDelta draw_duration, | 1078 base::TimeDelta draw_duration, |
| (...skipping 23 matching lines...) Expand all Loading... |
| 1094 bool impl_latency_takes_priority, | 1102 bool impl_latency_takes_priority, |
| 1095 bool should_send_begin_main_frame) { | 1103 bool should_send_begin_main_frame) { |
| 1096 // Set up client with specified estimates (draw duration is set to 1). | 1104 // Set up client with specified estimates (draw duration is set to 1). |
| 1097 SchedulerClientWithFixedEstimates client( | 1105 SchedulerClientWithFixedEstimates client( |
| 1098 base::TimeDelta::FromMilliseconds(1), | 1106 base::TimeDelta::FromMilliseconds(1), |
| 1099 base::TimeDelta::FromMilliseconds( | 1107 base::TimeDelta::FromMilliseconds( |
| 1100 begin_main_frame_to_commit_estimate_in_ms), | 1108 begin_main_frame_to_commit_estimate_in_ms), |
| 1101 base::TimeDelta::FromMilliseconds(commit_to_activate_estimate_in_ms)); | 1109 base::TimeDelta::FromMilliseconds(commit_to_activate_estimate_in_ms)); |
| 1102 SchedulerSettings scheduler_settings; | 1110 SchedulerSettings scheduler_settings; |
| 1103 scheduler_settings.use_external_begin_frame_source = true; | 1111 scheduler_settings.use_external_begin_frame_source = true; |
| 1104 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings); | 1112 |
| 1105 scheduler->SetCanStart(); | 1113 CREATE_SCHEDULER_AND_INIT_SURFACE(scheduler_settings); |
| 1106 scheduler->SetVisible(true); | 1114 |
| 1107 scheduler->SetCanDraw(true); | |
| 1108 scheduler->SetImplLatencyTakesPriority(impl_latency_takes_priority); | 1115 scheduler->SetImplLatencyTakesPriority(impl_latency_takes_priority); |
| 1109 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | |
| 1110 | 1116 |
| 1111 // Impl thread hits deadline before commit finishes. | 1117 // Impl thread hits deadline before commit finishes. |
| 1112 client.Reset(); | |
| 1113 scheduler->SetNeedsCommit(); | 1118 scheduler->SetNeedsCommit(); |
| 1114 EXPECT_FALSE(scheduler->MainThreadIsInHighLatencyMode()); | 1119 EXPECT_FALSE(scheduler->MainThreadIsInHighLatencyMode()); |
| 1115 client.AdvanceFrame(); | 1120 EXPECT_SCOPED(client.AdvanceFrame()); |
| 1116 EXPECT_FALSE(scheduler->MainThreadIsInHighLatencyMode()); | 1121 EXPECT_FALSE(scheduler->MainThreadIsInHighLatencyMode()); |
| 1117 client.task_runner().RunPendingTasks(); // Run posted deadline. | 1122 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 1118 EXPECT_TRUE(scheduler->MainThreadIsInHighLatencyMode()); | 1123 EXPECT_TRUE(scheduler->MainThreadIsInHighLatencyMode()); |
| 1119 scheduler->NotifyBeginMainFrameStarted(); | 1124 scheduler->NotifyBeginMainFrameStarted(); |
| 1120 scheduler->NotifyReadyToCommit(); | 1125 scheduler->NotifyReadyToCommit(); |
| 1121 EXPECT_TRUE(scheduler->MainThreadIsInHighLatencyMode()); | 1126 EXPECT_TRUE(scheduler->MainThreadIsInHighLatencyMode()); |
| 1122 EXPECT_TRUE(client.HasAction("ScheduledActionSendBeginMainFrame")); | 1127 EXPECT_TRUE(client.HasAction("ScheduledActionSendBeginMainFrame")); |
| 1123 | 1128 |
| 1124 client.Reset(); | 1129 client.Reset(); |
| 1125 scheduler->SetNeedsCommit(); | 1130 scheduler->SetNeedsCommit(); |
| 1126 EXPECT_TRUE(scheduler->MainThreadIsInHighLatencyMode()); | 1131 EXPECT_TRUE(scheduler->MainThreadIsInHighLatencyMode()); |
| 1127 client.AdvanceFrame(); | 1132 EXPECT_SCOPED(client.AdvanceFrame()); |
| 1128 EXPECT_TRUE(scheduler->MainThreadIsInHighLatencyMode()); | 1133 EXPECT_TRUE(scheduler->MainThreadIsInHighLatencyMode()); |
| 1129 client.task_runner().RunPendingTasks(); // Run posted deadline. | 1134 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 1130 EXPECT_EQ(scheduler->MainThreadIsInHighLatencyMode(), | 1135 EXPECT_EQ(scheduler->MainThreadIsInHighLatencyMode(), |
| 1131 should_send_begin_main_frame); | 1136 should_send_begin_main_frame); |
| 1132 EXPECT_EQ(client.HasAction("ScheduledActionSendBeginMainFrame"), | 1137 EXPECT_EQ(client.HasAction("ScheduledActionSendBeginMainFrame"), |
| 1133 should_send_begin_main_frame); | 1138 should_send_begin_main_frame); |
| 1134 } | 1139 } |
| 1135 | 1140 |
| 1136 TEST(SchedulerTest, | 1141 TEST(SchedulerTest, |
| 1137 SkipMainFrameIfHighLatencyAndCanCommitAndActivateBeforeDeadline) { | 1142 SkipMainFrameIfHighLatencyAndCanCommitAndActivateBeforeDeadline) { |
| (...skipping 21 matching lines...) Expand all Loading... |
| 1159 MainFrameInHighLatencyMode(1, 1, true, true); | 1164 MainFrameInHighLatencyMode(1, 1, true, true); |
| 1160 } | 1165 } |
| 1161 | 1166 |
| 1162 TEST(SchedulerTest, PollForCommitCompletion) { | 1167 TEST(SchedulerTest, PollForCommitCompletion) { |
| 1163 // Since we are simulating a long commit, set up a client with draw duration | 1168 // Since we are simulating a long commit, set up a client with draw duration |
| 1164 // estimates that prevent skipping main frames to get to low latency mode. | 1169 // estimates that prevent skipping main frames to get to low latency mode. |
| 1165 SchedulerClientWithFixedEstimates client( | 1170 SchedulerClientWithFixedEstimates client( |
| 1166 base::TimeDelta::FromMilliseconds(1), | 1171 base::TimeDelta::FromMilliseconds(1), |
| 1167 base::TimeDelta::FromMilliseconds(32), | 1172 base::TimeDelta::FromMilliseconds(32), |
| 1168 base::TimeDelta::FromMilliseconds(32)); | 1173 base::TimeDelta::FromMilliseconds(32)); |
| 1169 client.set_log_anticipated_draw_time_change(true); | |
| 1170 SchedulerSettings scheduler_settings; | 1174 SchedulerSettings scheduler_settings; |
| 1171 scheduler_settings.use_external_begin_frame_source = true; | 1175 scheduler_settings.use_external_begin_frame_source = true; |
| 1172 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings); | |
| 1173 | 1176 |
| 1174 scheduler->SetCanDraw(true); | 1177 CREATE_SCHEDULER_AND_INIT_SURFACE(scheduler_settings); |
| 1175 scheduler->SetCanStart(); | |
| 1176 scheduler->SetVisible(true); | |
| 1177 scheduler->DidCreateAndInitializeOutputSurface(); | |
| 1178 | 1178 |
| 1179 scheduler->SetNeedsCommit(); | 1179 client.set_log_anticipated_draw_time_change(true); |
| 1180 EXPECT_TRUE(scheduler->CommitPending()); | |
| 1181 scheduler->NotifyBeginMainFrameStarted(); | |
| 1182 scheduler->NotifyReadyToCommit(); | |
| 1183 scheduler->SetNeedsRedraw(); | |
| 1184 | 1180 |
| 1185 BeginFrameArgs frame_args = | 1181 BeginFrameArgs frame_args = |
| 1186 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, client.now_src()); | 1182 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, client.now_src()); |
| 1187 frame_args.interval = base::TimeDelta::FromMilliseconds(1000); | 1183 frame_args.interval = base::TimeDelta::FromMilliseconds(1000); |
| 1188 client.fake_external_begin_frame_source()->TestOnBeginFrame(frame_args); | |
| 1189 | |
| 1190 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | |
| 1191 client.task_runner().RunPendingTasks(); // Run posted deadline. | |
| 1192 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | |
| 1193 | |
| 1194 scheduler->DidSwapBuffers(); | |
| 1195 scheduler->DidSwapBuffersComplete(); | |
| 1196 | 1184 |
| 1197 // At this point, we've drawn a frame. Start another commit, but hold off on | 1185 // At this point, we've drawn a frame. Start another commit, but hold off on |
| 1198 // the NotifyReadyToCommit for now. | 1186 // the NotifyReadyToCommit for now. |
| 1199 EXPECT_FALSE(scheduler->CommitPending()); | 1187 EXPECT_FALSE(scheduler->CommitPending()); |
| 1200 scheduler->SetNeedsCommit(); | 1188 scheduler->SetNeedsCommit(); |
| 1201 client.fake_external_begin_frame_source()->TestOnBeginFrame(frame_args); | 1189 client.fake_external_begin_frame_source()->TestOnBeginFrame(frame_args); |
| 1202 EXPECT_TRUE(scheduler->CommitPending()); | 1190 EXPECT_TRUE(scheduler->CommitPending()); |
| 1203 | 1191 |
| 1204 // Draw and swap the frame, but don't ack the swap to simulate the Browser | 1192 // Draw and swap the frame, but don't ack the swap to simulate the Browser |
| 1205 // blocking on the renderer. | 1193 // blocking on the renderer. |
| (...skipping 29 matching lines...) Expand all Loading... |
| 1235 EXPECT_STREQ(client.Action(client.num_actions_() - 1), | 1223 EXPECT_STREQ(client.Action(client.num_actions_() - 1), |
| 1236 "DidAnticipatedDrawTimeChange"); | 1224 "DidAnticipatedDrawTimeChange"); |
| 1237 actions_so_far = client.num_actions_(); | 1225 actions_so_far = client.num_actions_(); |
| 1238 } | 1226 } |
| 1239 } | 1227 } |
| 1240 | 1228 |
| 1241 TEST(SchedulerTest, BeginRetroFrame) { | 1229 TEST(SchedulerTest, BeginRetroFrame) { |
| 1242 FakeSchedulerClient client; | 1230 FakeSchedulerClient client; |
| 1243 SchedulerSettings scheduler_settings; | 1231 SchedulerSettings scheduler_settings; |
| 1244 scheduler_settings.use_external_begin_frame_source = true; | 1232 scheduler_settings.use_external_begin_frame_source = true; |
| 1245 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings); | 1233 |
| 1246 scheduler->SetCanStart(); | 1234 CREATE_SCHEDULER_AND_INIT_SURFACE(scheduler_settings); |
| 1247 scheduler->SetVisible(true); | |
| 1248 scheduler->SetCanDraw(true); | |
| 1249 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | |
| 1250 | 1235 |
| 1251 // SetNeedsCommit should begin the frame on the next BeginImplFrame. | 1236 // SetNeedsCommit should begin the frame on the next BeginImplFrame. |
| 1252 client.Reset(); | |
| 1253 scheduler->SetNeedsCommit(); | 1237 scheduler->SetNeedsCommit(); |
| 1254 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client); | 1238 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client); |
| 1255 client.Reset(); | 1239 client.Reset(); |
| 1256 | 1240 |
| 1257 // Create a BeginFrame with a long deadline to avoid race conditions. | 1241 // Create a BeginFrame with a long deadline to avoid race conditions. |
| 1258 // This is the first BeginFrame, which will be handled immediately. | 1242 // This is the first BeginFrame, which will be handled immediately. |
| 1259 BeginFrameArgs args = | 1243 BeginFrameArgs args = |
| 1260 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, client.now_src()); | 1244 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, client.now_src()); |
| 1261 args.deadline += base::TimeDelta::FromHours(1); | 1245 args.deadline += base::TimeDelta::FromHours(1); |
| 1262 client.fake_external_begin_frame_source()->TestOnBeginFrame(args); | 1246 client.fake_external_begin_frame_source()->TestOnBeginFrame(args); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1310 | 1294 |
| 1311 client.task_runner().RunPendingTasks(); // Run posted deadline. | 1295 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 1312 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(false)", client); | 1296 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(false)", client); |
| 1313 client.Reset(); | 1297 client.Reset(); |
| 1314 } | 1298 } |
| 1315 | 1299 |
| 1316 TEST(SchedulerTest, BeginRetroFrame_SwapThrottled) { | 1300 TEST(SchedulerTest, BeginRetroFrame_SwapThrottled) { |
| 1317 FakeSchedulerClient client; | 1301 FakeSchedulerClient client; |
| 1318 SchedulerSettings scheduler_settings; | 1302 SchedulerSettings scheduler_settings; |
| 1319 scheduler_settings.use_external_begin_frame_source = true; | 1303 scheduler_settings.use_external_begin_frame_source = true; |
| 1320 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings); | 1304 |
| 1321 scheduler->SetCanStart(); | 1305 CREATE_SCHEDULER_AND_INIT_SURFACE(scheduler_settings); |
| 1322 scheduler->SetVisible(true); | |
| 1323 scheduler->SetCanDraw(true); | |
| 1324 scheduler->SetEstimatedParentDrawTime(base::TimeDelta::FromMicroseconds(1)); | 1306 scheduler->SetEstimatedParentDrawTime(base::TimeDelta::FromMicroseconds(1)); |
| 1325 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | |
| 1326 | 1307 |
| 1327 // To test swap ack throttling, this test disables automatic swap acks. | 1308 // To test swap ack throttling, this test disables automatic swap acks. |
| 1328 scheduler->SetMaxSwapsPending(1); | 1309 scheduler->SetMaxSwapsPending(1); |
| 1329 client.SetAutomaticSwapAck(false); | 1310 client.SetAutomaticSwapAck(false); |
| 1330 | 1311 |
| 1331 // SetNeedsCommit should begin the frame on the next BeginImplFrame. | 1312 // SetNeedsCommit should begin the frame on the next BeginImplFrame. |
| 1332 client.Reset(); | 1313 client.Reset(); |
| 1333 scheduler->SetNeedsCommit(); | 1314 scheduler->SetNeedsCommit(); |
| 1334 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client); | 1315 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client); |
| 1335 client.Reset(); | 1316 client.Reset(); |
| 1336 | 1317 |
| 1337 client.AdvanceFrame(); | 1318 EXPECT_SCOPED(client.AdvanceFrame()); |
| 1338 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 1319 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
| 1339 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); | 1320 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); |
| 1340 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1321 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 1341 EXPECT_TRUE(client.needs_begin_frames()); | 1322 EXPECT_TRUE(client.needs_begin_frames()); |
| 1342 client.Reset(); | 1323 client.Reset(); |
| 1343 | 1324 |
| 1344 // Queue BeginFrame while we are still handling the previous BeginFrame. | 1325 // Queue BeginFrame while we are still handling the previous BeginFrame. |
| 1345 client.SendNextBeginFrame(); | 1326 client.SendNextBeginFrame(); |
| 1346 EXPECT_NO_ACTION(client); | 1327 EXPECT_NO_ACTION(client); |
| 1347 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1328 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1395 EXPECT_SINGLE_ACTION("ScheduledActionDrawAndSwapIfPossible", client); | 1376 EXPECT_SINGLE_ACTION("ScheduledActionDrawAndSwapIfPossible", client); |
| 1396 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 1377 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
| 1397 EXPECT_TRUE(client.needs_begin_frames()); | 1378 EXPECT_TRUE(client.needs_begin_frames()); |
| 1398 client.Reset(); | 1379 client.Reset(); |
| 1399 } | 1380 } |
| 1400 | 1381 |
| 1401 TEST(SchedulerTest, RetroFrameDoesNotExpireTooEarly) { | 1382 TEST(SchedulerTest, RetroFrameDoesNotExpireTooEarly) { |
| 1402 FakeSchedulerClient client; | 1383 FakeSchedulerClient client; |
| 1403 SchedulerSettings scheduler_settings; | 1384 SchedulerSettings scheduler_settings; |
| 1404 scheduler_settings.use_external_begin_frame_source = true; | 1385 scheduler_settings.use_external_begin_frame_source = true; |
| 1405 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings); | |
| 1406 scheduler->SetCanStart(); | |
| 1407 scheduler->SetVisible(true); | |
| 1408 scheduler->SetCanDraw(true); | |
| 1409 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | |
| 1410 | 1386 |
| 1411 client.Reset(); | 1387 CREATE_SCHEDULER_AND_INIT_SURFACE(scheduler_settings); |
| 1388 |
| 1412 scheduler->SetNeedsCommit(); | 1389 scheduler->SetNeedsCommit(); |
| 1413 EXPECT_TRUE(client.needs_begin_frames()); | 1390 EXPECT_TRUE(client.needs_begin_frames()); |
| 1414 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client); | 1391 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client); |
| 1415 | 1392 |
| 1416 client.Reset(); | 1393 client.Reset(); |
| 1417 client.AdvanceFrame(); | 1394 EXPECT_SCOPED(client.AdvanceFrame()); |
| 1418 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 1395 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
| 1419 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); | 1396 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); |
| 1420 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1397 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 1421 | 1398 |
| 1422 client.Reset(); | 1399 client.Reset(); |
| 1423 scheduler->NotifyBeginMainFrameStarted(); | 1400 scheduler->NotifyBeginMainFrameStarted(); |
| 1424 | 1401 |
| 1425 client.Reset(); | 1402 client.Reset(); |
| 1426 client.SendNextBeginFrame(); | 1403 client.SendNextBeginFrame(); |
| 1427 // This BeginFrame is queued up as a retro frame. | 1404 // This BeginFrame is queued up as a retro frame. |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1463 client.Reset(); | 1440 client.Reset(); |
| 1464 client.task_runner().RunPendingTasks(); | 1441 client.task_runner().RunPendingTasks(); |
| 1465 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 1442 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
| 1466 EXPECT_SINGLE_ACTION("ScheduledActionDrawAndSwapIfPossible", client); | 1443 EXPECT_SINGLE_ACTION("ScheduledActionDrawAndSwapIfPossible", client); |
| 1467 } | 1444 } |
| 1468 | 1445 |
| 1469 TEST(SchedulerTest, RetroFrameDoesNotExpireTooLate) { | 1446 TEST(SchedulerTest, RetroFrameDoesNotExpireTooLate) { |
| 1470 FakeSchedulerClient client; | 1447 FakeSchedulerClient client; |
| 1471 SchedulerSettings scheduler_settings; | 1448 SchedulerSettings scheduler_settings; |
| 1472 scheduler_settings.use_external_begin_frame_source = true; | 1449 scheduler_settings.use_external_begin_frame_source = true; |
| 1473 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings); | |
| 1474 scheduler->SetCanStart(); | |
| 1475 scheduler->SetVisible(true); | |
| 1476 scheduler->SetCanDraw(true); | |
| 1477 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | |
| 1478 | 1450 |
| 1479 client.Reset(); | 1451 CREATE_SCHEDULER_AND_INIT_SURFACE(scheduler_settings); |
| 1452 |
| 1480 scheduler->SetNeedsCommit(); | 1453 scheduler->SetNeedsCommit(); |
| 1481 EXPECT_TRUE(client.needs_begin_frames()); | 1454 EXPECT_TRUE(client.needs_begin_frames()); |
| 1482 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client); | 1455 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client); |
| 1483 | 1456 |
| 1484 client.Reset(); | 1457 client.Reset(); |
| 1485 client.AdvanceFrame(); | 1458 EXPECT_SCOPED(client.AdvanceFrame()); |
| 1486 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 1459 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
| 1487 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); | 1460 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); |
| 1488 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1461 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 1489 | 1462 |
| 1490 client.Reset(); | 1463 client.Reset(); |
| 1491 scheduler->NotifyBeginMainFrameStarted(); | 1464 scheduler->NotifyBeginMainFrameStarted(); |
| 1492 | 1465 |
| 1493 client.Reset(); | 1466 client.Reset(); |
| 1494 client.SendNextBeginFrame(); | 1467 client.SendNextBeginFrame(); |
| 1495 // This BeginFrame is queued up as a retro frame. | 1468 // This BeginFrame is queued up as a retro frame. |
| (...skipping 27 matching lines...) Expand all Loading... |
| 1523 EXPECT_NO_ACTION(client); | 1496 EXPECT_NO_ACTION(client); |
| 1524 } | 1497 } |
| 1525 | 1498 |
| 1526 void BeginFramesNotFromClient(bool use_external_begin_frame_source, | 1499 void BeginFramesNotFromClient(bool use_external_begin_frame_source, |
| 1527 bool throttle_frame_production) { | 1500 bool throttle_frame_production) { |
| 1528 FakeSchedulerClient client; | 1501 FakeSchedulerClient client; |
| 1529 SchedulerSettings scheduler_settings; | 1502 SchedulerSettings scheduler_settings; |
| 1530 scheduler_settings.use_external_begin_frame_source = | 1503 scheduler_settings.use_external_begin_frame_source = |
| 1531 use_external_begin_frame_source; | 1504 use_external_begin_frame_source; |
| 1532 scheduler_settings.throttle_frame_production = throttle_frame_production; | 1505 scheduler_settings.throttle_frame_production = throttle_frame_production; |
| 1533 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings); | 1506 |
| 1534 scheduler->SetCanStart(); | 1507 CREATE_SCHEDULER_AND_INIT_SURFACE(scheduler_settings); |
| 1535 scheduler->SetVisible(true); | |
| 1536 scheduler->SetCanDraw(true); | |
| 1537 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | |
| 1538 | 1508 |
| 1539 DCHECK(!client.fake_external_begin_frame_source()); | 1509 DCHECK(!client.fake_external_begin_frame_source()); |
| 1540 | 1510 |
| 1541 // SetNeedsCommit should begin the frame on the next BeginImplFrame | 1511 // SetNeedsCommit should begin the frame on the next BeginImplFrame |
| 1542 // without calling SetNeedsBeginFrame. | 1512 // without calling SetNeedsBeginFrame. |
| 1543 client.Reset(); | |
| 1544 scheduler->SetNeedsCommit(); | 1513 scheduler->SetNeedsCommit(); |
| 1545 EXPECT_NO_ACTION(client); | 1514 EXPECT_NO_ACTION(client); |
| 1546 client.Reset(); | 1515 client.Reset(); |
| 1547 | 1516 |
| 1548 // When the client-driven BeginFrame are disabled, the scheduler posts it's | 1517 // When the client-driven BeginFrame are disabled, the scheduler posts it's |
| 1549 // own BeginFrame tasks. | 1518 // own BeginFrame tasks. |
| 1550 client.task_runner().RunPendingTasks(); // Run posted BeginFrame. | 1519 client.task_runner().RunPendingTasks(); // Run posted BeginFrame. |
| 1551 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 1520 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
| 1552 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); | 1521 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); |
| 1553 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1522 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1614 } | 1583 } |
| 1615 | 1584 |
| 1616 void BeginFramesNotFromClient_SwapThrottled( | 1585 void BeginFramesNotFromClient_SwapThrottled( |
| 1617 bool use_external_begin_frame_source, | 1586 bool use_external_begin_frame_source, |
| 1618 bool throttle_frame_production) { | 1587 bool throttle_frame_production) { |
| 1619 FakeSchedulerClient client; | 1588 FakeSchedulerClient client; |
| 1620 SchedulerSettings scheduler_settings; | 1589 SchedulerSettings scheduler_settings; |
| 1621 scheduler_settings.use_external_begin_frame_source = | 1590 scheduler_settings.use_external_begin_frame_source = |
| 1622 use_external_begin_frame_source; | 1591 use_external_begin_frame_source; |
| 1623 scheduler_settings.throttle_frame_production = throttle_frame_production; | 1592 scheduler_settings.throttle_frame_production = throttle_frame_production; |
| 1624 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings); | 1593 |
| 1625 scheduler->SetCanStart(); | 1594 CREATE_SCHEDULER_AND_INIT_SURFACE(scheduler_settings); |
| 1626 scheduler->SetVisible(true); | |
| 1627 scheduler->SetCanDraw(true); | |
| 1628 scheduler->SetEstimatedParentDrawTime(base::TimeDelta::FromMicroseconds(1)); | 1595 scheduler->SetEstimatedParentDrawTime(base::TimeDelta::FromMicroseconds(1)); |
| 1629 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | |
| 1630 | 1596 |
| 1631 DCHECK(!client.fake_external_begin_frame_source()); | 1597 DCHECK(!client.fake_external_begin_frame_source()); |
| 1632 | 1598 |
| 1633 // To test swap ack throttling, this test disables automatic swap acks. | 1599 // To test swap ack throttling, this test disables automatic swap acks. |
| 1634 scheduler->SetMaxSwapsPending(1); | 1600 scheduler->SetMaxSwapsPending(1); |
| 1635 client.SetAutomaticSwapAck(false); | 1601 client.SetAutomaticSwapAck(false); |
| 1636 | 1602 |
| 1637 // SetNeedsCommit should begin the frame on the next BeginImplFrame. | 1603 // SetNeedsCommit should begin the frame on the next BeginImplFrame. |
| 1638 client.Reset(); | 1604 client.Reset(); |
| 1639 scheduler->SetNeedsCommit(); | 1605 scheduler->SetNeedsCommit(); |
| 1640 EXPECT_NO_ACTION(client); | 1606 EXPECT_NO_ACTION(client); |
| 1641 client.Reset(); | 1607 client.Reset(); |
| 1642 | 1608 |
| 1643 // Trigger the first BeginImplFrame and BeginMainFrame | 1609 // Trigger the first BeginImplFrame and BeginMainFrame |
| 1644 client.AdvanceFrame(); | 1610 EXPECT_SCOPED(client.AdvanceFrame()); |
| 1645 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 1611 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
| 1646 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); | 1612 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); |
| 1647 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1613 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 1648 client.Reset(); | 1614 client.Reset(); |
| 1649 | 1615 |
| 1650 // NotifyReadyToCommit should trigger the pending commit and draw. | 1616 // NotifyReadyToCommit should trigger the pending commit and draw. |
| 1651 scheduler->NotifyBeginMainFrameStarted(); | 1617 scheduler->NotifyBeginMainFrameStarted(); |
| 1652 scheduler->NotifyReadyToCommit(); | 1618 scheduler->NotifyReadyToCommit(); |
| 1653 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); | 1619 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); |
| 1654 client.Reset(); | 1620 client.Reset(); |
| 1655 | 1621 |
| 1656 // Swapping will put us into a swap throttled state. | 1622 // Swapping will put us into a swap throttled state. |
| 1657 // Run posted deadline. | 1623 // Run posted deadline. |
| 1658 client.task_runner().RunTasksWhile(client.ImplFrameDeadlinePending(true)); | 1624 client.task_runner().RunTasksWhile(client.ImplFrameDeadlinePending(true)); |
| 1659 EXPECT_ACTION("ScheduledActionAnimate", client, 0, 2); | 1625 EXPECT_ACTION("ScheduledActionAnimate", client, 0, 2); |
| 1660 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 1, 2); | 1626 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 1, 2); |
| 1661 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 1627 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
| 1662 client.Reset(); | 1628 client.Reset(); |
| 1663 | 1629 |
| 1664 // While swap throttled, BeginFrames should trigger BeginImplFrames, | 1630 // While swap throttled, BeginFrames should trigger BeginImplFrames, |
| 1665 // but not a BeginMainFrame or draw. | 1631 // but not a BeginMainFrame or draw. |
| 1666 scheduler->SetNeedsCommit(); | 1632 scheduler->SetNeedsCommit(); |
| 1667 scheduler->SetNeedsRedraw(); | 1633 scheduler->SetNeedsRedraw(); |
| 1668 client.AdvanceFrame(); // Run posted BeginFrame. | 1634 EXPECT_SCOPED(client.AdvanceFrame()); // Run posted BeginFrame. |
| 1669 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 1635 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
| 1670 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); | 1636 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); |
| 1671 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1637 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 1672 client.Reset(); | 1638 client.Reset(); |
| 1673 | 1639 |
| 1674 // Let time pass sufficiently beyond the regular deadline but not beyond the | 1640 // Let time pass sufficiently beyond the regular deadline but not beyond the |
| 1675 // late deadline. | 1641 // late deadline. |
| 1676 client.now_src()->AdvanceNow(BeginFrameArgs::DefaultInterval() - | 1642 client.now_src()->AdvanceNow(BeginFrameArgs::DefaultInterval() - |
| 1677 base::TimeDelta::FromMicroseconds(1)); | 1643 base::TimeDelta::FromMicroseconds(1)); |
| 1678 client.task_runner().RunUntilTime(client.now_src()->Now()); | 1644 client.task_runner().RunUntilTime(client.now_src()->Now()); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1732 EXPECT_NO_ACTION(client); | 1698 EXPECT_NO_ACTION(client); |
| 1733 | 1699 |
| 1734 scheduler->DidLoseOutputSurface(); | 1700 scheduler->DidLoseOutputSurface(); |
| 1735 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); | 1701 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); |
| 1736 } | 1702 } |
| 1737 | 1703 |
| 1738 TEST(SchedulerTest, DidLoseOutputSurfaceAfterBeginFrameStarted) { | 1704 TEST(SchedulerTest, DidLoseOutputSurfaceAfterBeginFrameStarted) { |
| 1739 FakeSchedulerClient client; | 1705 FakeSchedulerClient client; |
| 1740 SchedulerSettings scheduler_settings; | 1706 SchedulerSettings scheduler_settings; |
| 1741 scheduler_settings.use_external_begin_frame_source = true; | 1707 scheduler_settings.use_external_begin_frame_source = true; |
| 1742 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings); | |
| 1743 scheduler->SetCanStart(); | |
| 1744 scheduler->SetVisible(true); | |
| 1745 scheduler->SetCanDraw(true); | |
| 1746 | 1708 |
| 1747 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); | 1709 CREATE_SCHEDULER_AND_INIT_SURFACE(scheduler_settings); |
| 1748 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | 1710 |
| 1749 // SetNeedsCommit should begin the frame. | 1711 // SetNeedsCommit should begin the frame. |
| 1750 client.Reset(); | |
| 1751 scheduler->SetNeedsCommit(); | 1712 scheduler->SetNeedsCommit(); |
| 1752 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client); | 1713 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client); |
| 1753 | 1714 |
| 1754 client.Reset(); | 1715 client.Reset(); |
| 1755 client.AdvanceFrame(); | 1716 EXPECT_SCOPED(client.AdvanceFrame()); |
| 1756 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 1717 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
| 1757 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); | 1718 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); |
| 1758 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1719 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 1759 | 1720 |
| 1760 client.Reset(); | 1721 client.Reset(); |
| 1761 scheduler->DidLoseOutputSurface(); | 1722 scheduler->DidLoseOutputSurface(); |
| 1762 // Do nothing when impl frame is in deadine pending state. | 1723 // Do nothing when impl frame is in deadine pending state. |
| 1763 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(false)", client); | 1724 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(false)", client); |
| 1764 | 1725 |
| 1765 client.Reset(); | 1726 client.Reset(); |
| 1766 scheduler->NotifyBeginMainFrameStarted(); | 1727 scheduler->NotifyBeginMainFrameStarted(); |
| 1767 scheduler->NotifyReadyToCommit(); | 1728 scheduler->NotifyReadyToCommit(); |
| 1768 EXPECT_ACTION("ScheduledActionCommit", client, 0, 1); | 1729 EXPECT_ACTION("ScheduledActionCommit", client, 0, 1); |
| 1769 | 1730 |
| 1770 client.Reset(); | 1731 client.Reset(); |
| 1771 client.task_runner().RunPendingTasks(); // Run posted deadline. | 1732 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 1772 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); | 1733 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); |
| 1773 } | 1734 } |
| 1774 | 1735 |
| 1775 void DidLoseOutputSurfaceAfterBeginFrameStartedWithHighLatency( | 1736 void DidLoseOutputSurfaceAfterBeginFrameStartedWithHighLatency( |
| 1776 bool impl_side_painting) { | 1737 bool impl_side_painting) { |
| 1777 FakeSchedulerClient client; | 1738 FakeSchedulerClient client; |
| 1778 SchedulerSettings scheduler_settings; | 1739 SchedulerSettings scheduler_settings; |
| 1779 scheduler_settings.impl_side_painting = impl_side_painting; | 1740 scheduler_settings.impl_side_painting = impl_side_painting; |
| 1780 scheduler_settings.use_external_begin_frame_source = true; | 1741 scheduler_settings.use_external_begin_frame_source = true; |
| 1781 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings); | |
| 1782 scheduler->SetCanStart(); | |
| 1783 scheduler->SetVisible(true); | |
| 1784 scheduler->SetCanDraw(true); | |
| 1785 | 1742 |
| 1786 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); | 1743 CREATE_SCHEDULER_AND_INIT_SURFACE(scheduler_settings); |
| 1787 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | |
| 1788 | 1744 |
| 1789 // SetNeedsCommit should begin the frame. | 1745 // SetNeedsCommit should begin the frame. |
| 1790 client.Reset(); | |
| 1791 scheduler->SetNeedsCommit(); | 1746 scheduler->SetNeedsCommit(); |
| 1792 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client); | 1747 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client); |
| 1793 | 1748 |
| 1794 client.Reset(); | 1749 client.Reset(); |
| 1795 client.AdvanceFrame(); | 1750 EXPECT_SCOPED(client.AdvanceFrame()); |
| 1796 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 1751 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
| 1797 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); | 1752 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); |
| 1798 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1753 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 1799 | 1754 |
| 1800 client.Reset(); | 1755 client.Reset(); |
| 1801 scheduler->DidLoseOutputSurface(); | 1756 scheduler->DidLoseOutputSurface(); |
| 1802 // Do nothing when impl frame is in deadine pending state. | 1757 // Do nothing when impl frame is in deadine pending state. |
| 1803 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(false)", client); | 1758 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(false)", client); |
| 1804 | 1759 |
| 1805 client.Reset(); | 1760 client.Reset(); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1839 DidLoseOutputSurfaceAfterBeginFrameStartedWithHighLatencyWithImplPaint) { | 1794 DidLoseOutputSurfaceAfterBeginFrameStartedWithHighLatencyWithImplPaint) { |
| 1840 bool impl_side_painting = true; | 1795 bool impl_side_painting = true; |
| 1841 DidLoseOutputSurfaceAfterBeginFrameStartedWithHighLatency(impl_side_painting); | 1796 DidLoseOutputSurfaceAfterBeginFrameStartedWithHighLatency(impl_side_painting); |
| 1842 } | 1797 } |
| 1843 | 1798 |
| 1844 void DidLoseOutputSurfaceAfterReadyToCommit(bool impl_side_painting) { | 1799 void DidLoseOutputSurfaceAfterReadyToCommit(bool impl_side_painting) { |
| 1845 FakeSchedulerClient client; | 1800 FakeSchedulerClient client; |
| 1846 SchedulerSettings scheduler_settings; | 1801 SchedulerSettings scheduler_settings; |
| 1847 scheduler_settings.impl_side_painting = impl_side_painting; | 1802 scheduler_settings.impl_side_painting = impl_side_painting; |
| 1848 scheduler_settings.use_external_begin_frame_source = true; | 1803 scheduler_settings.use_external_begin_frame_source = true; |
| 1849 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings); | |
| 1850 scheduler->SetCanStart(); | |
| 1851 scheduler->SetVisible(true); | |
| 1852 scheduler->SetCanDraw(true); | |
| 1853 | 1804 |
| 1854 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); | 1805 CREATE_SCHEDULER_AND_INIT_SURFACE(scheduler_settings); |
| 1855 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | |
| 1856 | 1806 |
| 1857 // SetNeedsCommit should begin the frame. | 1807 // SetNeedsCommit should begin the frame. |
| 1858 client.Reset(); | |
| 1859 scheduler->SetNeedsCommit(); | 1808 scheduler->SetNeedsCommit(); |
| 1860 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client); | 1809 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client); |
| 1861 | 1810 |
| 1862 client.Reset(); | 1811 client.Reset(); |
| 1863 client.AdvanceFrame(); | 1812 EXPECT_SCOPED(client.AdvanceFrame()); |
| 1864 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 1813 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
| 1865 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); | 1814 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); |
| 1866 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1815 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 1867 | 1816 |
| 1868 client.Reset(); | 1817 client.Reset(); |
| 1869 scheduler->NotifyBeginMainFrameStarted(); | 1818 scheduler->NotifyBeginMainFrameStarted(); |
| 1870 scheduler->NotifyReadyToCommit(); | 1819 scheduler->NotifyReadyToCommit(); |
| 1871 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); | 1820 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); |
| 1872 | 1821 |
| 1873 client.Reset(); | 1822 client.Reset(); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 1890 } | 1839 } |
| 1891 | 1840 |
| 1892 TEST(SchedulerTest, DidLoseOutputSurfaceAfterReadyToCommitWithImplPainting) { | 1841 TEST(SchedulerTest, DidLoseOutputSurfaceAfterReadyToCommitWithImplPainting) { |
| 1893 DidLoseOutputSurfaceAfterReadyToCommit(true); | 1842 DidLoseOutputSurfaceAfterReadyToCommit(true); |
| 1894 } | 1843 } |
| 1895 | 1844 |
| 1896 TEST(SchedulerTest, DidLoseOutputSurfaceAfterSetNeedsPrepareTiles) { | 1845 TEST(SchedulerTest, DidLoseOutputSurfaceAfterSetNeedsPrepareTiles) { |
| 1897 FakeSchedulerClient client; | 1846 FakeSchedulerClient client; |
| 1898 SchedulerSettings scheduler_settings; | 1847 SchedulerSettings scheduler_settings; |
| 1899 scheduler_settings.use_external_begin_frame_source = true; | 1848 scheduler_settings.use_external_begin_frame_source = true; |
| 1900 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings); | |
| 1901 scheduler->SetCanStart(); | |
| 1902 scheduler->SetVisible(true); | |
| 1903 scheduler->SetCanDraw(true); | |
| 1904 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | |
| 1905 | 1849 |
| 1906 client.Reset(); | 1850 CREATE_SCHEDULER_AND_INIT_SURFACE(scheduler_settings); |
| 1851 |
| 1907 scheduler->SetNeedsPrepareTiles(); | 1852 scheduler->SetNeedsPrepareTiles(); |
| 1908 scheduler->SetNeedsRedraw(); | 1853 scheduler->SetNeedsRedraw(); |
| 1909 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client); | 1854 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client); |
| 1910 | 1855 |
| 1911 client.Reset(); | 1856 client.Reset(); |
| 1912 client.AdvanceFrame(); | 1857 EXPECT_SCOPED(client.AdvanceFrame()); |
| 1913 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 1858 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
| 1914 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); | 1859 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); |
| 1915 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1860 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 1916 | 1861 |
| 1917 client.Reset(); | 1862 client.Reset(); |
| 1918 scheduler->DidLoseOutputSurface(); | 1863 scheduler->DidLoseOutputSurface(); |
| 1919 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(false)", client); | 1864 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(false)", client); |
| 1920 | 1865 |
| 1921 client.Reset(); | 1866 client.Reset(); |
| 1922 client.task_runner().RunPendingTasks(); // Run posted deadline. | 1867 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 1923 EXPECT_ACTION("ScheduledActionPrepareTiles", client, 0, 2); | 1868 EXPECT_ACTION("ScheduledActionPrepareTiles", client, 0, 2); |
| 1924 EXPECT_ACTION("ScheduledActionBeginOutputSurfaceCreation", client, 1, 2); | 1869 EXPECT_ACTION("ScheduledActionBeginOutputSurfaceCreation", client, 1, 2); |
| 1925 } | 1870 } |
| 1926 | 1871 |
| 1927 TEST(SchedulerTest, DidLoseOutputSurfaceAfterBeginRetroFramePosted) { | 1872 TEST(SchedulerTest, DidLoseOutputSurfaceAfterBeginRetroFramePosted) { |
| 1928 FakeSchedulerClient client; | 1873 FakeSchedulerClient client; |
| 1929 SchedulerSettings scheduler_settings; | 1874 SchedulerSettings scheduler_settings; |
| 1930 scheduler_settings.use_external_begin_frame_source = true; | 1875 scheduler_settings.use_external_begin_frame_source = true; |
| 1931 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings); | 1876 |
| 1932 scheduler->SetCanStart(); | 1877 CREATE_SCHEDULER_AND_INIT_SURFACE(scheduler_settings); |
| 1933 scheduler->SetVisible(true); | |
| 1934 scheduler->SetCanDraw(true); | |
| 1935 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | |
| 1936 | 1878 |
| 1937 // SetNeedsCommit should begin the frame on the next BeginImplFrame. | 1879 // SetNeedsCommit should begin the frame on the next BeginImplFrame. |
| 1938 client.Reset(); | |
| 1939 scheduler->SetNeedsCommit(); | 1880 scheduler->SetNeedsCommit(); |
| 1940 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client); | 1881 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client); |
| 1941 | 1882 |
| 1942 // Create a BeginFrame with a long deadline to avoid race conditions. | 1883 // Create a BeginFrame with a long deadline to avoid race conditions. |
| 1943 // This is the first BeginFrame, which will be handled immediately. | 1884 // This is the first BeginFrame, which will be handled immediately. |
| 1944 client.Reset(); | 1885 client.Reset(); |
| 1945 BeginFrameArgs args = | 1886 BeginFrameArgs args = |
| 1946 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, client.now_src()); | 1887 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, client.now_src()); |
| 1947 args.deadline += base::TimeDelta::FromHours(1); | 1888 args.deadline += base::TimeDelta::FromHours(1); |
| 1948 client.fake_external_begin_frame_source()->TestOnBeginFrame(args); | 1889 client.fake_external_begin_frame_source()->TestOnBeginFrame(args); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1981 // Posted BeginRetroFrame is aborted. | 1922 // Posted BeginRetroFrame is aborted. |
| 1982 client.Reset(); | 1923 client.Reset(); |
| 1983 client.task_runner().RunPendingTasks(); | 1924 client.task_runner().RunPendingTasks(); |
| 1984 EXPECT_NO_ACTION(client); | 1925 EXPECT_NO_ACTION(client); |
| 1985 } | 1926 } |
| 1986 | 1927 |
| 1987 TEST(SchedulerTest, DidLoseOutputSurfaceDuringBeginRetroFrameRunning) { | 1928 TEST(SchedulerTest, DidLoseOutputSurfaceDuringBeginRetroFrameRunning) { |
| 1988 FakeSchedulerClient client; | 1929 FakeSchedulerClient client; |
| 1989 SchedulerSettings scheduler_settings; | 1930 SchedulerSettings scheduler_settings; |
| 1990 scheduler_settings.use_external_begin_frame_source = true; | 1931 scheduler_settings.use_external_begin_frame_source = true; |
| 1991 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings); | 1932 |
| 1992 scheduler->SetCanStart(); | 1933 CREATE_SCHEDULER_AND_INIT_SURFACE(scheduler_settings); |
| 1993 scheduler->SetVisible(true); | |
| 1994 scheduler->SetCanDraw(true); | |
| 1995 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | |
| 1996 | 1934 |
| 1997 // SetNeedsCommit should begin the frame on the next BeginImplFrame. | 1935 // SetNeedsCommit should begin the frame on the next BeginImplFrame. |
| 1998 client.Reset(); | |
| 1999 scheduler->SetNeedsCommit(); | 1936 scheduler->SetNeedsCommit(); |
| 2000 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client); | 1937 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client); |
| 2001 | 1938 |
| 2002 // Create a BeginFrame with a long deadline to avoid race conditions. | 1939 // Create a BeginFrame with a long deadline to avoid race conditions. |
| 2003 // This is the first BeginFrame, which will be handled immediately. | 1940 // This is the first BeginFrame, which will be handled immediately. |
| 2004 client.Reset(); | 1941 client.Reset(); |
| 2005 BeginFrameArgs args = | 1942 BeginFrameArgs args = |
| 2006 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, client.now_src()); | 1943 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, client.now_src()); |
| 2007 args.deadline += base::TimeDelta::FromHours(1); | 1944 args.deadline += base::TimeDelta::FromHours(1); |
| 2008 client.fake_external_begin_frame_source()->TestOnBeginFrame(args); | 1945 client.fake_external_begin_frame_source()->TestOnBeginFrame(args); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2055 // No more BeginRetroFrame because BeginRetroFrame queue is cleared. | 1992 // No more BeginRetroFrame because BeginRetroFrame queue is cleared. |
| 2056 client.Reset(); | 1993 client.Reset(); |
| 2057 client.task_runner().RunPendingTasks(); | 1994 client.task_runner().RunPendingTasks(); |
| 2058 EXPECT_NO_ACTION(client); | 1995 EXPECT_NO_ACTION(client); |
| 2059 } | 1996 } |
| 2060 | 1997 |
| 2061 TEST(SchedulerTest, | 1998 TEST(SchedulerTest, |
| 2062 StopBeginFrameAfterDidLoseOutputSurfaceWithSyntheticBeginFrameSource) { | 1999 StopBeginFrameAfterDidLoseOutputSurfaceWithSyntheticBeginFrameSource) { |
| 2063 FakeSchedulerClient client; | 2000 FakeSchedulerClient client; |
| 2064 SchedulerSettings scheduler_settings; | 2001 SchedulerSettings scheduler_settings; |
| 2065 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings); | 2002 |
| 2066 scheduler->SetCanStart(); | 2003 CREATE_SCHEDULER_AND_INIT_SURFACE(scheduler_settings); |
| 2067 scheduler->SetVisible(true); | |
| 2068 scheduler->SetCanDraw(true); | |
| 2069 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | |
| 2070 | 2004 |
| 2071 // SetNeedsCommit should begin the frame on the next BeginImplFrame. | 2005 // SetNeedsCommit should begin the frame on the next BeginImplFrame. |
| 2072 client.Reset(); | |
| 2073 EXPECT_FALSE(scheduler->frame_source().NeedsBeginFrames()); | 2006 EXPECT_FALSE(scheduler->frame_source().NeedsBeginFrames()); |
| 2074 scheduler->SetNeedsCommit(); | 2007 scheduler->SetNeedsCommit(); |
| 2075 EXPECT_TRUE(scheduler->frame_source().NeedsBeginFrames()); | 2008 EXPECT_TRUE(scheduler->frame_source().NeedsBeginFrames()); |
| 2076 | 2009 |
| 2077 client.Reset(); | 2010 client.Reset(); |
| 2078 client.task_runner().RunPendingTasks(); // Run posted Tick. | 2011 client.task_runner().RunPendingTasks(); // Run posted Tick. |
| 2079 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 2012 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
| 2080 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); | 2013 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); |
| 2081 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 2014 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 2082 EXPECT_TRUE(scheduler->frame_source().NeedsBeginFrames()); | 2015 EXPECT_TRUE(scheduler->frame_source().NeedsBeginFrames()); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 2097 client.task_runner().RunPendingTasks(); // Run posted deadline. | 2030 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 2098 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); | 2031 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); |
| 2099 EXPECT_FALSE(scheduler->frame_source().NeedsBeginFrames()); | 2032 EXPECT_FALSE(scheduler->frame_source().NeedsBeginFrames()); |
| 2100 } | 2033 } |
| 2101 | 2034 |
| 2102 TEST(SchedulerTest, ScheduledActionActivateAfterBecomingInvisible) { | 2035 TEST(SchedulerTest, ScheduledActionActivateAfterBecomingInvisible) { |
| 2103 FakeSchedulerClient client; | 2036 FakeSchedulerClient client; |
| 2104 SchedulerSettings scheduler_settings; | 2037 SchedulerSettings scheduler_settings; |
| 2105 scheduler_settings.impl_side_painting = true; | 2038 scheduler_settings.impl_side_painting = true; |
| 2106 scheduler_settings.use_external_begin_frame_source = true; | 2039 scheduler_settings.use_external_begin_frame_source = true; |
| 2107 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings); | |
| 2108 scheduler->SetCanStart(); | |
| 2109 scheduler->SetVisible(true); | |
| 2110 scheduler->SetCanDraw(true); | |
| 2111 | 2040 |
| 2112 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); | 2041 CREATE_SCHEDULER_AND_INIT_SURFACE(scheduler_settings); |
| 2113 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | |
| 2114 | 2042 |
| 2115 // SetNeedsCommit should begin the frame. | 2043 // SetNeedsCommit should begin the frame. |
| 2116 client.Reset(); | |
| 2117 scheduler->SetNeedsCommit(); | 2044 scheduler->SetNeedsCommit(); |
| 2118 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client); | 2045 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client); |
| 2119 | 2046 |
| 2120 client.Reset(); | 2047 client.Reset(); |
| 2121 client.AdvanceFrame(); | 2048 EXPECT_SCOPED(client.AdvanceFrame()); |
| 2122 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 2049 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
| 2123 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); | 2050 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); |
| 2124 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 2051 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 2125 | 2052 |
| 2126 client.Reset(); | 2053 client.Reset(); |
| 2127 scheduler->NotifyBeginMainFrameStarted(); | 2054 scheduler->NotifyBeginMainFrameStarted(); |
| 2128 scheduler->NotifyReadyToCommit(); | 2055 scheduler->NotifyReadyToCommit(); |
| 2129 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); | 2056 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); |
| 2130 | 2057 |
| 2131 client.Reset(); | 2058 client.Reset(); |
| 2132 scheduler->SetVisible(false); | 2059 scheduler->SetVisible(false); |
| 2133 // Sync tree should be forced to activate. | 2060 // Sync tree should be forced to activate. |
| 2134 EXPECT_ACTION("SetNeedsBeginFrames(false)", client, 0, 2); | 2061 EXPECT_ACTION("SetNeedsBeginFrames(false)", client, 0, 2); |
| 2135 EXPECT_ACTION("ScheduledActionActivateSyncTree", client, 1, 2); | 2062 EXPECT_ACTION("ScheduledActionActivateSyncTree", client, 1, 2); |
| 2136 } | 2063 } |
| 2137 | 2064 |
| 2138 TEST(SchedulerTest, SchedulerPowerMonitoring) { | 2065 TEST(SchedulerTest, SchedulerPowerMonitoring) { |
| 2139 FakeSchedulerClient client; | 2066 FakeSchedulerClient client; |
| 2140 SchedulerSettings settings; | 2067 SchedulerSettings settings; |
| 2141 settings.disable_hi_res_timer_tasks_on_battery = true; | 2068 settings.disable_hi_res_timer_tasks_on_battery = true; |
| 2142 TestScheduler* scheduler = client.CreateScheduler(settings); | 2069 |
| 2070 CREATE_SCHEDULER_AND_INIT_SURFACE(settings); |
| 2143 | 2071 |
| 2144 base::TimeTicks before_deadline, after_deadline; | 2072 base::TimeTicks before_deadline, after_deadline; |
| 2145 | 2073 |
| 2146 scheduler->SetCanStart(); | |
| 2147 scheduler->SetVisible(true); | |
| 2148 scheduler->SetCanDraw(true); | |
| 2149 | |
| 2150 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | |
| 2151 | |
| 2152 scheduler->SetNeedsCommit(); | 2074 scheduler->SetNeedsCommit(); |
| 2153 scheduler->SetNeedsRedraw(); | 2075 scheduler->SetNeedsRedraw(); |
| 2154 client.Reset(); | 2076 client.Reset(); |
| 2155 | 2077 |
| 2156 // On non-battery power | 2078 // On non-battery power |
| 2157 EXPECT_FALSE(client.PowerMonitor()->IsOnBatteryPower()); | 2079 EXPECT_FALSE(client.PowerMonitor()->IsOnBatteryPower()); |
| 2158 | 2080 |
| 2159 client.AdvanceFrame(); | 2081 EXPECT_SCOPED(client.AdvanceFrame()); |
| 2160 client.Reset(); | 2082 client.Reset(); |
| 2161 | 2083 |
| 2162 before_deadline = client.now_src()->Now(); | 2084 before_deadline = client.now_src()->Now(); |
| 2163 EXPECT_TRUE(client.task_runner().RunTasksWhile( | 2085 EXPECT_TRUE(client.task_runner().RunTasksWhile( |
| 2164 client.ImplFrameDeadlinePending(true))); | 2086 client.ImplFrameDeadlinePending(true))); |
| 2165 after_deadline = client.now_src()->Now(); | 2087 after_deadline = client.now_src()->Now(); |
| 2166 | 2088 |
| 2167 // We post a non-zero deadline task when not on battery | 2089 // We post a non-zero deadline task when not on battery |
| 2168 EXPECT_LT(before_deadline, after_deadline); | 2090 EXPECT_LT(before_deadline, after_deadline); |
| 2169 | 2091 |
| 2170 // Switch to battery power | 2092 // Switch to battery power |
| 2171 client.PowerMonitorSource()->GeneratePowerStateEvent(true); | 2093 client.PowerMonitorSource()->GeneratePowerStateEvent(true); |
| 2172 EXPECT_TRUE(client.PowerMonitor()->IsOnBatteryPower()); | 2094 EXPECT_TRUE(client.PowerMonitor()->IsOnBatteryPower()); |
| 2173 | 2095 |
| 2174 client.AdvanceFrame(); | 2096 EXPECT_SCOPED(client.AdvanceFrame()); |
| 2175 scheduler->SetNeedsCommit(); | 2097 scheduler->SetNeedsCommit(); |
| 2176 scheduler->SetNeedsRedraw(); | 2098 scheduler->SetNeedsRedraw(); |
| 2177 client.Reset(); | 2099 client.Reset(); |
| 2178 | 2100 |
| 2179 before_deadline = client.now_src()->Now(); | 2101 before_deadline = client.now_src()->Now(); |
| 2180 EXPECT_TRUE(client.task_runner().RunTasksWhile( | 2102 EXPECT_TRUE(client.task_runner().RunTasksWhile( |
| 2181 client.ImplFrameDeadlinePending(true))); | 2103 client.ImplFrameDeadlinePending(true))); |
| 2182 after_deadline = client.now_src()->Now(); | 2104 after_deadline = client.now_src()->Now(); |
| 2183 | 2105 |
| 2184 // We post a zero deadline task when on battery | 2106 // We post a zero deadline task when on battery |
| 2185 EXPECT_EQ(before_deadline, after_deadline); | 2107 EXPECT_EQ(before_deadline, after_deadline); |
| 2186 | 2108 |
| 2187 // Switch to non-battery power | 2109 // Switch to non-battery power |
| 2188 client.PowerMonitorSource()->GeneratePowerStateEvent(false); | 2110 client.PowerMonitorSource()->GeneratePowerStateEvent(false); |
| 2189 EXPECT_FALSE(client.PowerMonitor()->IsOnBatteryPower()); | 2111 EXPECT_FALSE(client.PowerMonitor()->IsOnBatteryPower()); |
| 2190 | 2112 |
| 2191 client.AdvanceFrame(); | 2113 EXPECT_SCOPED(client.AdvanceFrame()); |
| 2192 scheduler->SetNeedsCommit(); | 2114 scheduler->SetNeedsCommit(); |
| 2193 scheduler->SetNeedsRedraw(); | 2115 scheduler->SetNeedsRedraw(); |
| 2194 client.Reset(); | 2116 client.Reset(); |
| 2195 | 2117 |
| 2196 // Same as before | 2118 // Same as before |
| 2197 before_deadline = client.now_src()->Now(); | 2119 before_deadline = client.now_src()->Now(); |
| 2198 EXPECT_TRUE(client.task_runner().RunTasksWhile( | 2120 EXPECT_TRUE(client.task_runner().RunTasksWhile( |
| 2199 client.ImplFrameDeadlinePending(true))); | 2121 client.ImplFrameDeadlinePending(true))); |
| 2200 after_deadline = client.now_src()->Now(); | 2122 after_deadline = client.now_src()->Now(); |
| 2201 } | 2123 } |
| 2202 | 2124 |
| 2203 TEST(SchedulerTest, | 2125 TEST(SchedulerTest, |
| 2204 SimulateWindowsLowResolutionTimerOnBattery_PrioritizeImplLatencyOff) { | 2126 SimulateWindowsLowResolutionTimerOnBattery_PrioritizeImplLatencyOff) { |
| 2205 FakeSchedulerClient client; | 2127 FakeSchedulerClient client; |
| 2206 SchedulerSettings settings; | 2128 SchedulerSettings settings; |
| 2207 settings.use_external_begin_frame_source = true; | 2129 settings.use_external_begin_frame_source = true; |
| 2208 TestScheduler* scheduler = client.CreateScheduler(settings); | |
| 2209 | 2130 |
| 2210 scheduler->SetCanStart(); | 2131 CREATE_SCHEDULER_AND_INIT_SURFACE(settings); |
| 2211 scheduler->SetVisible(true); | |
| 2212 scheduler->SetCanDraw(true); | |
| 2213 | |
| 2214 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | |
| 2215 | 2132 |
| 2216 // Set needs commit so that the scheduler tries to wait for the main thread | 2133 // Set needs commit so that the scheduler tries to wait for the main thread |
| 2217 scheduler->SetNeedsCommit(); | 2134 scheduler->SetNeedsCommit(); |
| 2218 // Set needs redraw so that the scheduler doesn't wait too long | 2135 // Set needs redraw so that the scheduler doesn't wait too long |
| 2219 scheduler->SetNeedsRedraw(); | 2136 scheduler->SetNeedsRedraw(); |
| 2220 client.Reset(); | 2137 client.Reset(); |
| 2221 | 2138 |
| 2222 // Switch to battery power | 2139 // Switch to battery power |
| 2223 client.PowerMonitorSource()->GeneratePowerStateEvent(true); | 2140 client.PowerMonitorSource()->GeneratePowerStateEvent(true); |
| 2224 EXPECT_TRUE(client.PowerMonitor()->IsOnBatteryPower()); | 2141 EXPECT_TRUE(client.PowerMonitor()->IsOnBatteryPower()); |
| 2225 | 2142 |
| 2226 client.AdvanceFrame(); | 2143 EXPECT_SCOPED(client.AdvanceFrame()); |
| 2227 scheduler->SetNeedsCommit(); | 2144 scheduler->SetNeedsCommit(); |
| 2228 scheduler->SetNeedsRedraw(); | 2145 scheduler->SetNeedsRedraw(); |
| 2229 client.Reset(); | 2146 client.Reset(); |
| 2230 | 2147 |
| 2231 // Disable auto-advancing of now_src | 2148 // Disable auto-advancing of now_src |
| 2232 client.task_runner().SetAutoAdvanceNowToPendingTasks(false); | 2149 client.task_runner().SetAutoAdvanceNowToPendingTasks(false); |
| 2233 | 2150 |
| 2234 // Deadline task is pending | 2151 // Deadline task is pending |
| 2235 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 2152 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 2236 client.task_runner().RunPendingTasks(); | 2153 client.task_runner().RunPendingTasks(); |
| 2237 // Deadline task is still pending | 2154 // Deadline task is still pending |
| 2238 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 2155 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 2239 | 2156 |
| 2240 // Advance now by 15 ms - same as windows low res timer | 2157 // Advance now by 15 ms - same as windows low res timer |
| 2241 client.now_src()->AdvanceNowMicroseconds(15000); | 2158 client.now_src()->AdvanceNowMicroseconds(15000); |
| 2242 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 2159 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 2243 client.task_runner().RunPendingTasks(); | 2160 client.task_runner().RunPendingTasks(); |
| 2244 // Deadline task finally completes | 2161 // Deadline task finally completes |
| 2245 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 2162 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
| 2246 } | 2163 } |
| 2247 | 2164 |
| 2248 TEST(SchedulerTest, | 2165 TEST(SchedulerTest, |
| 2249 SimulateWindowsLowResolutionTimerOnBattery_PrioritizeImplLatencyOn) { | 2166 SimulateWindowsLowResolutionTimerOnBattery_PrioritizeImplLatencyOn) { |
| 2250 FakeSchedulerClient client; | 2167 FakeSchedulerClient client; |
| 2251 SchedulerSettings settings; | 2168 SchedulerSettings settings; |
| 2252 settings.disable_hi_res_timer_tasks_on_battery = true; | 2169 settings.disable_hi_res_timer_tasks_on_battery = true; |
| 2253 settings.use_external_begin_frame_source = true; | 2170 settings.use_external_begin_frame_source = true; |
| 2254 TestScheduler* scheduler = client.CreateScheduler(settings); | |
| 2255 | 2171 |
| 2256 scheduler->SetCanStart(); | 2172 CREATE_SCHEDULER_AND_INIT_SURFACE(settings); |
| 2257 scheduler->SetVisible(true); | |
| 2258 scheduler->SetCanDraw(true); | |
| 2259 | |
| 2260 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | |
| 2261 | 2173 |
| 2262 // Set needs commit so that the scheduler tries to wait for the main thread | 2174 // Set needs commit so that the scheduler tries to wait for the main thread |
| 2263 scheduler->SetNeedsCommit(); | 2175 scheduler->SetNeedsCommit(); |
| 2264 // Set needs redraw so that the scheduler doesn't wait too long | 2176 // Set needs redraw so that the scheduler doesn't wait too long |
| 2265 scheduler->SetNeedsRedraw(); | 2177 scheduler->SetNeedsRedraw(); |
| 2266 client.Reset(); | 2178 client.Reset(); |
| 2267 | 2179 |
| 2268 // Switch to battery power | 2180 // Switch to battery power |
| 2269 client.PowerMonitorSource()->GeneratePowerStateEvent(true); | 2181 client.PowerMonitorSource()->GeneratePowerStateEvent(true); |
| 2270 EXPECT_TRUE(client.PowerMonitor()->IsOnBatteryPower()); | 2182 EXPECT_TRUE(client.PowerMonitor()->IsOnBatteryPower()); |
| 2271 | 2183 |
| 2272 client.AdvanceFrame(); | 2184 EXPECT_SCOPED(client.AdvanceFrame()); |
| 2273 scheduler->SetNeedsCommit(); | 2185 scheduler->SetNeedsCommit(); |
| 2274 scheduler->SetNeedsRedraw(); | 2186 scheduler->SetNeedsRedraw(); |
| 2275 client.Reset(); | 2187 client.Reset(); |
| 2276 | 2188 |
| 2277 // Disable auto-advancing of now_src | 2189 // Disable auto-advancing of now_src |
| 2278 client.task_runner().SetAutoAdvanceNowToPendingTasks(false); | 2190 client.task_runner().SetAutoAdvanceNowToPendingTasks(false); |
| 2279 | 2191 |
| 2280 // Deadline task is pending | 2192 // Deadline task is pending |
| 2281 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 2193 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 2282 client.task_runner().RunPendingTasks(); | 2194 client.task_runner().RunPendingTasks(); |
| 2283 // Deadline task runs immediately | 2195 // Deadline task runs immediately |
| 2284 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 2196 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
| 2285 } | 2197 } |
| 2286 | 2198 |
| 2287 } // namespace | 2199 } // namespace |
| 2288 } // namespace cc | 2200 } // namespace cc |
| OLD | NEW |