| 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 #include "cc/scheduler/scheduler.h" | 4 #include "cc/scheduler/scheduler.h" |
| 5 | 5 |
| 6 #include <string> | 6 #include <string> |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/debug/trace_event.h" | 9 #include "base/debug/trace_event.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 namespace cc { | 38 namespace cc { |
| 39 namespace { | 39 namespace { |
| 40 | 40 |
| 41 class FakeSchedulerClient; | 41 class FakeSchedulerClient; |
| 42 | 42 |
| 43 void InitializeOutputSurfaceAndFirstCommit(Scheduler* scheduler, | 43 void InitializeOutputSurfaceAndFirstCommit(Scheduler* scheduler, |
| 44 FakeSchedulerClient* client); | 44 FakeSchedulerClient* client); |
| 45 | 45 |
| 46 class FakeSchedulerClient : public SchedulerClient { | 46 class FakeSchedulerClient : public SchedulerClient { |
| 47 public: | 47 public: |
| 48 struct FakeBeginFrameSourceForFakeSchedulerClient |
| 49 : public FakeBeginFrameSource { |
| 50 FakeSchedulerClient* client_; |
| 51 |
| 52 explicit FakeBeginFrameSourceForFakeSchedulerClient( |
| 53 FakeSchedulerClient* client) |
| 54 : client_(client) {} |
| 55 |
| 56 virtual void SetNeedsBeginFrames(bool needs_begin_frames) OVERRIDE { |
| 57 FakeBeginFrameSource::SetNeedsBeginFrames(needs_begin_frames); |
| 58 client_->actions_.push_back("SetNeedsBeginFrame"); |
| 59 client_->states_.push_back(client_->scheduler_->AsValue()); |
| 60 } |
| 61 }; |
| 62 |
| 48 FakeSchedulerClient() | 63 FakeSchedulerClient() |
| 49 : needs_begin_frame_(false), | 64 : automatic_swap_ack_(true), |
| 50 automatic_swap_ack_(true), | |
| 51 swap_contains_incomplete_tile_(false), | 65 swap_contains_incomplete_tile_(false), |
| 52 redraw_will_happen_if_update_visible_tiles_happens_(false), | 66 redraw_will_happen_if_update_visible_tiles_happens_(false), |
| 53 now_src_(TestNowSource::Create()) { | 67 now_src_(TestNowSource::Create()), |
| 68 fake_frame_source_(this) { |
| 54 Reset(); | 69 Reset(); |
| 55 } | 70 } |
| 56 | 71 |
| 57 void Reset() { | 72 void Reset() { |
| 58 actions_.clear(); | 73 actions_.clear(); |
| 59 states_.clear(); | 74 states_.clear(); |
| 60 draw_will_happen_ = true; | 75 draw_will_happen_ = true; |
| 61 swap_will_happen_if_draw_happens_ = true; | 76 swap_will_happen_if_draw_happens_ = true; |
| 62 num_draws_ = 0; | 77 num_draws_ = 0; |
| 63 log_anticipated_draw_time_change_ = false; | 78 log_anticipated_draw_time_change_ = false; |
| 64 } | 79 } |
| 65 | 80 |
| 66 TestScheduler* CreateScheduler(const SchedulerSettings& settings) { | 81 TestScheduler* CreateScheduler(const SchedulerSettings& settings) { |
| 67 scheduler_ = TestScheduler::Create(now_src_, this, settings, 0); | 82 scheduler_ = TestScheduler::Create(now_src_, this, settings, 0); |
| 68 // Fail if we need to run 100 tasks in a row. | 83 // Fail if we need to run 100 tasks in a row. |
| 69 task_runner().SetRunTaskLimit(100); | 84 task_runner().SetRunTaskLimit(100); |
| 70 return scheduler_.get(); | 85 return scheduler_.get(); |
| 71 } | 86 } |
| 72 | 87 |
| 73 // Most tests don't care about DidAnticipatedDrawTimeChange, so only record it | 88 // Most tests don't care about DidAnticipatedDrawTimeChange, so only record it |
| 74 // for tests that do. | 89 // for tests that do. |
| 75 void set_log_anticipated_draw_time_change(bool log) { | 90 void set_log_anticipated_draw_time_change(bool log) { |
| 76 log_anticipated_draw_time_change_ = log; | 91 log_anticipated_draw_time_change_ = log; |
| 77 } | 92 } |
| 78 bool needs_begin_frame() { return needs_begin_frame_; } | 93 bool needs_begin_frames() { return fake_frame_source_.NeedsBeginFrames(); } |
| 79 int num_draws() const { return num_draws_; } | 94 int num_draws() const { return num_draws_; } |
| 80 int num_actions_() const { return static_cast<int>(actions_.size()); } | 95 int num_actions_() const { return static_cast<int>(actions_.size()); } |
| 81 const char* Action(int i) const { return actions_[i]; } | 96 const char* Action(int i) const { return actions_[i]; } |
| 82 std::string StateForAction(int i) const { return states_[i]->ToString(); } | 97 std::string StateForAction(int i) const { return states_[i]->ToString(); } |
| 83 base::TimeTicks posted_begin_impl_frame_deadline() const { | 98 base::TimeTicks posted_begin_impl_frame_deadline() const { |
| 84 return posted_begin_impl_frame_deadline_; | 99 return posted_begin_impl_frame_deadline_; |
| 85 } | 100 } |
| 86 | 101 |
| 102 bool ExternalBeginFrame() { |
| 103 return scheduler_->settings().begin_frame_scheduling_enabled && |
| 104 scheduler_->settings().throttle_frame_production; |
| 105 } |
| 106 virtual FakeBeginFrameSource* GetBeginFrameSource() OVERRIDE { |
| 107 EXPECT_TRUE(ExternalBeginFrame()); |
| 108 return &fake_frame_source_; |
| 109 } |
| 110 |
| 87 void AdvanceFrame() { | 111 void AdvanceFrame() { |
| 88 bool external_begin_frame = | 112 if (ExternalBeginFrame()) { |
| 89 scheduler_->settings().begin_frame_scheduling_enabled && | 113 fake_frame_source_.TestSendBeginFrame( |
| 90 scheduler_->settings().throttle_frame_production; | 114 CreateBeginFrameArgsForTesting(now_src_)); |
| 91 | |
| 92 if (external_begin_frame) { | |
| 93 scheduler_->BeginFrame(CreateBeginFrameArgsForTesting(now_src_)); | |
| 94 } | 115 } |
| 95 | 116 |
| 96 EXPECT_TRUE(task_runner().RunTasksWhile(ImplFrameDeadlinePending(false))); | 117 EXPECT_TRUE(task_runner().RunTasksWhile(ImplFrameDeadlinePending(false))); |
| 97 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 118 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
| 98 } | 119 } |
| 99 | 120 |
| 100 OrderedSimpleTaskRunner& task_runner() { return scheduler_->task_runner(); } | 121 OrderedSimpleTaskRunner& task_runner() { return scheduler_->task_runner(); } |
| 101 TestNowSource* now_src() { return now_src_.get(); } | 122 TestNowSource* now_src() { return now_src_.get(); } |
| 102 | 123 |
| 103 int ActionIndex(const char* action) const { | 124 int ActionIndex(const char* action) const { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 121 void SetSwapWillHappenIfDrawHappens(bool swap_will_happen_if_draw_happens) { | 142 void SetSwapWillHappenIfDrawHappens(bool swap_will_happen_if_draw_happens) { |
| 122 swap_will_happen_if_draw_happens_ = swap_will_happen_if_draw_happens; | 143 swap_will_happen_if_draw_happens_ = swap_will_happen_if_draw_happens; |
| 123 } | 144 } |
| 124 void SetAutomaticSwapAck(bool automatic_swap_ack) { | 145 void SetAutomaticSwapAck(bool automatic_swap_ack) { |
| 125 automatic_swap_ack_ = automatic_swap_ack; | 146 automatic_swap_ack_ = automatic_swap_ack; |
| 126 } | 147 } |
| 127 void SetRedrawWillHappenIfUpdateVisibleTilesHappens(bool redraw) { | 148 void SetRedrawWillHappenIfUpdateVisibleTilesHappens(bool redraw) { |
| 128 redraw_will_happen_if_update_visible_tiles_happens_ = redraw; | 149 redraw_will_happen_if_update_visible_tiles_happens_ = redraw; |
| 129 } | 150 } |
| 130 // SchedulerClient implementation. | 151 // SchedulerClient implementation. |
| 131 virtual void SetNeedsBeginFrame(bool enable) OVERRIDE { | |
| 132 actions_.push_back("SetNeedsBeginFrame"); | |
| 133 states_.push_back(scheduler_->AsValue()); | |
| 134 needs_begin_frame_ = enable; | |
| 135 } | |
| 136 virtual void WillBeginImplFrame(const BeginFrameArgs& args) OVERRIDE { | 152 virtual void WillBeginImplFrame(const BeginFrameArgs& args) OVERRIDE { |
| 137 actions_.push_back("WillBeginImplFrame"); | 153 actions_.push_back("WillBeginImplFrame"); |
| 138 states_.push_back(scheduler_->AsValue()); | 154 states_.push_back(scheduler_->AsValue()); |
| 139 } | 155 } |
| 140 virtual void ScheduledActionSendBeginMainFrame() OVERRIDE { | 156 virtual void ScheduledActionSendBeginMainFrame() OVERRIDE { |
| 141 actions_.push_back("ScheduledActionSendBeginMainFrame"); | 157 actions_.push_back("ScheduledActionSendBeginMainFrame"); |
| 142 states_.push_back(scheduler_->AsValue()); | 158 states_.push_back(scheduler_->AsValue()); |
| 143 } | 159 } |
| 144 virtual void ScheduledActionAnimate() OVERRIDE { | 160 virtual void ScheduledActionAnimate() OVERRIDE { |
| 145 actions_.push_back("ScheduledActionAnimate"); | 161 actions_.push_back("ScheduledActionAnimate"); |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 214 return base::Bind(&FakeSchedulerClient::ImplFrameDeadlinePendingCallback, | 230 return base::Bind(&FakeSchedulerClient::ImplFrameDeadlinePendingCallback, |
| 215 base::Unretained(this), | 231 base::Unretained(this), |
| 216 state); | 232 state); |
| 217 } | 233 } |
| 218 | 234 |
| 219 protected: | 235 protected: |
| 220 bool ImplFrameDeadlinePendingCallback(bool state) { | 236 bool ImplFrameDeadlinePendingCallback(bool state) { |
| 221 return scheduler_->BeginImplFrameDeadlinePending() == state; | 237 return scheduler_->BeginImplFrameDeadlinePending() == state; |
| 222 } | 238 } |
| 223 | 239 |
| 224 bool needs_begin_frame_; | |
| 225 bool draw_will_happen_; | 240 bool draw_will_happen_; |
| 226 bool swap_will_happen_if_draw_happens_; | 241 bool swap_will_happen_if_draw_happens_; |
| 227 bool automatic_swap_ack_; | 242 bool automatic_swap_ack_; |
| 228 int num_draws_; | 243 int num_draws_; |
| 229 bool log_anticipated_draw_time_change_; | 244 bool log_anticipated_draw_time_change_; |
| 230 bool swap_contains_incomplete_tile_; | 245 bool swap_contains_incomplete_tile_; |
| 231 bool redraw_will_happen_if_update_visible_tiles_happens_; | 246 bool redraw_will_happen_if_update_visible_tiles_happens_; |
| 232 base::TimeTicks posted_begin_impl_frame_deadline_; | 247 base::TimeTicks posted_begin_impl_frame_deadline_; |
| 233 std::vector<const char*> actions_; | 248 std::vector<const char*> actions_; |
| 234 std::vector<scoped_refptr<base::debug::ConvertableToTraceFormat> > states_; | 249 std::vector<scoped_refptr<base::debug::ConvertableToTraceFormat> > states_; |
| 235 scoped_ptr<TestScheduler> scheduler_; | 250 scoped_ptr<TestScheduler> scheduler_; |
| 236 scoped_refptr<TestNowSource> now_src_; | 251 scoped_refptr<TestNowSource> now_src_; |
| 252 FakeBeginFrameSourceForFakeSchedulerClient fake_frame_source_; |
| 237 }; | 253 }; |
| 238 | 254 |
| 239 void InitializeOutputSurfaceAndFirstCommit(Scheduler* scheduler, | 255 void InitializeOutputSurfaceAndFirstCommit(Scheduler* scheduler, |
| 240 FakeSchedulerClient* client) { | 256 FakeSchedulerClient* client) { |
| 241 TRACE_EVENT0("cc", | 257 TRACE_EVENT0("cc", |
| 242 "SchedulerUnitTest::InitializeOutputSurfaceAndFirstCommit"); | 258 "SchedulerUnitTest::InitializeOutputSurfaceAndFirstCommit"); |
| 243 | 259 |
| 244 scheduler->DidCreateAndInitializeOutputSurface(); | 260 scheduler->DidCreateAndInitializeOutputSurface(); |
| 245 scheduler->SetNeedsCommit(); | 261 scheduler->SetNeedsCommit(); |
| 246 scheduler->NotifyBeginMainFrameStarted(); | 262 scheduler->NotifyBeginMainFrameStarted(); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 287 scheduler->SetCanStart(); | 303 scheduler->SetCanStart(); |
| 288 scheduler->SetVisible(true); | 304 scheduler->SetVisible(true); |
| 289 scheduler->SetCanDraw(true); | 305 scheduler->SetCanDraw(true); |
| 290 | 306 |
| 291 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); | 307 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); |
| 292 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | 308 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
| 293 | 309 |
| 294 // SetNeedsCommit should begin the frame on the next BeginImplFrame. | 310 // SetNeedsCommit should begin the frame on the next BeginImplFrame. |
| 295 client.Reset(); | 311 client.Reset(); |
| 296 scheduler->SetNeedsCommit(); | 312 scheduler->SetNeedsCommit(); |
| 297 EXPECT_TRUE(client.needs_begin_frame()); | 313 EXPECT_TRUE(client.needs_begin_frames()); |
| 298 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); | 314 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames", client); |
| 299 client.Reset(); | 315 client.Reset(); |
| 300 | 316 |
| 301 client.AdvanceFrame(); | 317 client.AdvanceFrame(); |
| 302 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 318 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
| 303 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); | 319 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); |
| 304 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 320 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 305 EXPECT_TRUE(client.needs_begin_frame()); | 321 EXPECT_TRUE(client.needs_begin_frames()); |
| 306 client.Reset(); | 322 client.Reset(); |
| 307 | 323 |
| 308 // If we don't swap on the deadline, we wait for the next BeginFrame. | 324 // If we don't swap on the deadline, we wait for the next BeginFrame. |
| 309 client.task_runner().RunPendingTasks(); // Run posted deadline. | 325 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 310 EXPECT_NO_ACTION(client); | 326 EXPECT_NO_ACTION(client); |
| 311 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 327 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
| 312 EXPECT_TRUE(client.needs_begin_frame()); | 328 EXPECT_TRUE(client.needs_begin_frames()); |
| 313 client.Reset(); | 329 client.Reset(); |
| 314 | 330 |
| 315 // NotifyReadyToCommit should trigger the commit. | 331 // NotifyReadyToCommit should trigger the commit. |
| 316 scheduler->NotifyBeginMainFrameStarted(); | 332 scheduler->NotifyBeginMainFrameStarted(); |
| 317 scheduler->NotifyReadyToCommit(); | 333 scheduler->NotifyReadyToCommit(); |
| 318 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); | 334 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); |
| 319 EXPECT_TRUE(client.needs_begin_frame()); | 335 EXPECT_TRUE(client.needs_begin_frames()); |
| 320 client.Reset(); | 336 client.Reset(); |
| 321 | 337 |
| 322 // BeginImplFrame should prepare the draw. | 338 // BeginImplFrame should prepare the draw. |
| 323 client.AdvanceFrame(); | 339 client.AdvanceFrame(); |
| 324 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 340 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
| 325 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); | 341 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); |
| 326 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 342 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 327 EXPECT_TRUE(client.needs_begin_frame()); | 343 EXPECT_TRUE(client.needs_begin_frames()); |
| 328 client.Reset(); | 344 client.Reset(); |
| 329 | 345 |
| 330 // BeginImplFrame deadline should draw. | 346 // BeginImplFrame deadline should draw. |
| 331 client.task_runner().RunPendingTasks(); // Run posted deadline. | 347 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 332 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 1); | 348 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 1); |
| 333 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 349 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
| 334 EXPECT_TRUE(client.needs_begin_frame()); | 350 EXPECT_TRUE(client.needs_begin_frames()); |
| 335 client.Reset(); | 351 client.Reset(); |
| 336 | 352 |
| 337 // The following BeginImplFrame deadline should SetNeedsBeginFrame(false) | 353 // The following BeginImplFrame deadline should SetNeedsBeginFrame(false) |
| 338 // to avoid excessive toggles. | 354 // to avoid excessive toggles. |
| 339 client.AdvanceFrame(); | 355 client.AdvanceFrame(); |
| 340 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); | 356 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); |
| 341 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 357 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 342 client.Reset(); | 358 client.Reset(); |
| 343 | 359 |
| 344 client.task_runner().RunPendingTasks(); // Run posted deadline. | 360 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 345 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); | 361 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames", client); |
| 346 EXPECT_FALSE(client.needs_begin_frame()); | 362 EXPECT_FALSE(client.needs_begin_frames()); |
| 347 client.Reset(); | 363 client.Reset(); |
| 348 } | 364 } |
| 349 | 365 |
| 350 TEST(SchedulerTest, RequestCommitAfterBeginMainFrameSent) { | 366 TEST(SchedulerTest, RequestCommitAfterBeginMainFrameSent) { |
| 351 FakeSchedulerClient client; | 367 FakeSchedulerClient client; |
| 352 SchedulerSettings scheduler_settings; | 368 SchedulerSettings scheduler_settings; |
| 353 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings); | 369 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings); |
| 354 scheduler->SetCanStart(); | 370 scheduler->SetCanStart(); |
| 355 scheduler->SetVisible(true); | 371 scheduler->SetVisible(true); |
| 356 scheduler->SetCanDraw(true); | 372 scheduler->SetCanDraw(true); |
| 357 | 373 |
| 358 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); | 374 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); |
| 359 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | 375 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
| 360 client.Reset(); | 376 client.Reset(); |
| 361 | 377 |
| 362 // SetNeedsCommit should begin the frame. | 378 // SetNeedsCommit should begin the frame. |
| 363 scheduler->SetNeedsCommit(); | 379 scheduler->SetNeedsCommit(); |
| 364 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); | 380 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames", client); |
| 365 | 381 |
| 366 client.Reset(); | 382 client.Reset(); |
| 367 client.AdvanceFrame(); | 383 client.AdvanceFrame(); |
| 368 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 384 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
| 369 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); | 385 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); |
| 370 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 386 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 371 | 387 |
| 372 EXPECT_TRUE(client.needs_begin_frame()); | 388 EXPECT_TRUE(client.needs_begin_frames()); |
| 373 client.Reset(); | 389 client.Reset(); |
| 374 | 390 |
| 375 // Now SetNeedsCommit again. Calling here means we need a second commit. | 391 // Now SetNeedsCommit again. Calling here means we need a second commit. |
| 376 scheduler->SetNeedsCommit(); | 392 scheduler->SetNeedsCommit(); |
| 377 EXPECT_EQ(client.num_actions_(), 0); | 393 EXPECT_EQ(client.num_actions_(), 0); |
| 378 client.Reset(); | 394 client.Reset(); |
| 379 | 395 |
| 380 // Finish the first commit. | 396 // Finish the first commit. |
| 381 scheduler->NotifyBeginMainFrameStarted(); | 397 scheduler->NotifyBeginMainFrameStarted(); |
| 382 scheduler->NotifyReadyToCommit(); | 398 scheduler->NotifyReadyToCommit(); |
| 383 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); | 399 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); |
| 384 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 400 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 385 client.Reset(); | 401 client.Reset(); |
| 386 client.task_runner().RunPendingTasks(); // Run posted deadline. | 402 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 387 EXPECT_ACTION("ScheduledActionAnimate", client, 0, 2); | 403 EXPECT_ACTION("ScheduledActionAnimate", client, 0, 2); |
| 388 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 1, 2); | 404 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 1, 2); |
| 389 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 405 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
| 390 | 406 |
| 391 // Because we just swapped, the Scheduler should also request the next | 407 // Because we just swapped, the Scheduler should also request the next |
| 392 // BeginImplFrame from the OutputSurface. | 408 // BeginImplFrame from the OutputSurface. |
| 393 EXPECT_TRUE(client.needs_begin_frame()); | 409 EXPECT_TRUE(client.needs_begin_frames()); |
| 394 client.Reset(); | 410 client.Reset(); |
| 395 // Since another commit is needed, the next BeginImplFrame should initiate | 411 // Since another commit is needed, the next BeginImplFrame should initiate |
| 396 // the second commit. | 412 // the second commit. |
| 397 client.AdvanceFrame(); | 413 client.AdvanceFrame(); |
| 398 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 414 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
| 399 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); | 415 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); |
| 400 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 416 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 401 client.Reset(); | 417 client.Reset(); |
| 402 | 418 |
| 403 // Finishing the commit before the deadline should post a new deadline task | 419 // Finishing the commit before the deadline should post a new deadline task |
| 404 // to trigger the deadline early. | 420 // to trigger the deadline early. |
| 405 scheduler->NotifyBeginMainFrameStarted(); | 421 scheduler->NotifyBeginMainFrameStarted(); |
| 406 scheduler->NotifyReadyToCommit(); | 422 scheduler->NotifyReadyToCommit(); |
| 407 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); | 423 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); |
| 408 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 424 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 409 client.Reset(); | 425 client.Reset(); |
| 410 client.task_runner().RunPendingTasks(); // Run posted deadline. | 426 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 411 EXPECT_ACTION("ScheduledActionAnimate", client, 0, 2); | 427 EXPECT_ACTION("ScheduledActionAnimate", client, 0, 2); |
| 412 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 1, 2); | 428 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 1, 2); |
| 413 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 429 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
| 414 EXPECT_TRUE(client.needs_begin_frame()); | 430 EXPECT_TRUE(client.needs_begin_frames()); |
| 415 client.Reset(); | 431 client.Reset(); |
| 416 | 432 |
| 417 // On the next BeginImplFrame, verify we go back to a quiescent state and | 433 // On the next BeginImplFrame, verify we go back to a quiescent state and |
| 418 // no longer request BeginImplFrames. | 434 // no longer request BeginImplFrames. |
| 419 client.AdvanceFrame(); | 435 client.AdvanceFrame(); |
| 420 client.task_runner().RunPendingTasks(); // Run posted deadline. | 436 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 421 EXPECT_FALSE(client.needs_begin_frame()); | 437 EXPECT_FALSE(client.needs_begin_frames()); |
| 422 client.Reset(); | 438 client.Reset(); |
| 423 } | 439 } |
| 424 | 440 |
| 425 class SchedulerClientThatsetNeedsDrawInsideDraw : public FakeSchedulerClient { | 441 class SchedulerClientThatsetNeedsDrawInsideDraw : public FakeSchedulerClient { |
| 426 public: | 442 public: |
| 427 virtual void ScheduledActionSendBeginMainFrame() OVERRIDE {} | 443 virtual void ScheduledActionSendBeginMainFrame() OVERRIDE {} |
| 428 virtual DrawResult ScheduledActionDrawAndSwapIfPossible() | 444 virtual DrawResult ScheduledActionDrawAndSwapIfPossible() |
| 429 OVERRIDE { | 445 OVERRIDE { |
| 430 // Only SetNeedsRedraw the first time this is called | 446 // Only SetNeedsRedraw the first time this is called |
| 431 if (!num_draws_) | 447 if (!num_draws_) |
| (...skipping 20 matching lines...) Expand all Loading... |
| 452 SchedulerSettings default_scheduler_settings; | 468 SchedulerSettings default_scheduler_settings; |
| 453 TestScheduler* scheduler = client.CreateScheduler(default_scheduler_settings); | 469 TestScheduler* scheduler = client.CreateScheduler(default_scheduler_settings); |
| 454 scheduler->SetCanStart(); | 470 scheduler->SetCanStart(); |
| 455 scheduler->SetVisible(true); | 471 scheduler->SetVisible(true); |
| 456 scheduler->SetCanDraw(true); | 472 scheduler->SetCanDraw(true); |
| 457 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | 473 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
| 458 client.Reset(); | 474 client.Reset(); |
| 459 | 475 |
| 460 scheduler->SetNeedsRedraw(); | 476 scheduler->SetNeedsRedraw(); |
| 461 EXPECT_TRUE(scheduler->RedrawPending()); | 477 EXPECT_TRUE(scheduler->RedrawPending()); |
| 462 EXPECT_TRUE(client.needs_begin_frame()); | 478 EXPECT_TRUE(client.needs_begin_frames()); |
| 463 EXPECT_EQ(0, client.num_draws()); | 479 EXPECT_EQ(0, client.num_draws()); |
| 464 | 480 |
| 465 client.AdvanceFrame(); | 481 client.AdvanceFrame(); |
| 466 client.task_runner().RunPendingTasks(); // Run posted deadline. | 482 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 467 EXPECT_EQ(1, client.num_draws()); | 483 EXPECT_EQ(1, client.num_draws()); |
| 468 EXPECT_TRUE(scheduler->RedrawPending()); | 484 EXPECT_TRUE(scheduler->RedrawPending()); |
| 469 EXPECT_TRUE(client.needs_begin_frame()); | 485 EXPECT_TRUE(client.needs_begin_frames()); |
| 470 | 486 |
| 471 client.AdvanceFrame(); | 487 client.AdvanceFrame(); |
| 472 client.task_runner().RunPendingTasks(); // Run posted deadline. | 488 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 473 EXPECT_EQ(2, client.num_draws()); | 489 EXPECT_EQ(2, client.num_draws()); |
| 474 EXPECT_FALSE(scheduler->RedrawPending()); | 490 EXPECT_FALSE(scheduler->RedrawPending()); |
| 475 EXPECT_TRUE(client.needs_begin_frame()); | 491 EXPECT_TRUE(client.needs_begin_frames()); |
| 476 | 492 |
| 477 // We stop requesting BeginImplFrames after a BeginImplFrame where we don't | 493 // We stop requesting BeginImplFrames after a BeginImplFrame where we don't |
| 478 // swap. | 494 // swap. |
| 479 client.AdvanceFrame(); | 495 client.AdvanceFrame(); |
| 480 client.task_runner().RunPendingTasks(); // Run posted deadline. | 496 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 481 EXPECT_EQ(2, client.num_draws()); | 497 EXPECT_EQ(2, client.num_draws()); |
| 482 EXPECT_FALSE(scheduler->RedrawPending()); | 498 EXPECT_FALSE(scheduler->RedrawPending()); |
| 483 EXPECT_FALSE(client.needs_begin_frame()); | 499 EXPECT_FALSE(client.needs_begin_frames()); |
| 484 } | 500 } |
| 485 | 501 |
| 486 // Test that requesting redraw inside a failed draw doesn't lose the request. | 502 // Test that requesting redraw inside a failed draw doesn't lose the request. |
| 487 TEST(SchedulerTest, RequestRedrawInsideFailedDraw) { | 503 TEST(SchedulerTest, RequestRedrawInsideFailedDraw) { |
| 488 SchedulerClientThatsetNeedsDrawInsideDraw client; | 504 SchedulerClientThatsetNeedsDrawInsideDraw client; |
| 489 SchedulerSettings default_scheduler_settings; | 505 SchedulerSettings default_scheduler_settings; |
| 490 TestScheduler* scheduler = client.CreateScheduler(default_scheduler_settings); | 506 TestScheduler* scheduler = client.CreateScheduler(default_scheduler_settings); |
| 491 scheduler->SetCanStart(); | 507 scheduler->SetCanStart(); |
| 492 scheduler->SetVisible(true); | 508 scheduler->SetVisible(true); |
| 493 scheduler->SetCanDraw(true); | 509 scheduler->SetCanDraw(true); |
| 494 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | 510 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
| 495 client.Reset(); | 511 client.Reset(); |
| 496 | 512 |
| 497 client.SetDrawWillHappen(false); | 513 client.SetDrawWillHappen(false); |
| 498 | 514 |
| 499 scheduler->SetNeedsRedraw(); | 515 scheduler->SetNeedsRedraw(); |
| 500 EXPECT_TRUE(scheduler->RedrawPending()); | 516 EXPECT_TRUE(scheduler->RedrawPending()); |
| 501 EXPECT_TRUE(client.needs_begin_frame()); | 517 EXPECT_TRUE(client.needs_begin_frames()); |
| 502 EXPECT_EQ(0, client.num_draws()); | 518 EXPECT_EQ(0, client.num_draws()); |
| 503 | 519 |
| 504 // Fail the draw. | 520 // Fail the draw. |
| 505 client.AdvanceFrame(); | 521 client.AdvanceFrame(); |
| 506 client.task_runner().RunPendingTasks(); // Run posted deadline. | 522 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 507 EXPECT_EQ(1, client.num_draws()); | 523 EXPECT_EQ(1, client.num_draws()); |
| 508 | 524 |
| 509 // We have a commit pending and the draw failed, and we didn't lose the redraw | 525 // We have a commit pending and the draw failed, and we didn't lose the redraw |
| 510 // request. | 526 // request. |
| 511 EXPECT_TRUE(scheduler->CommitPending()); | 527 EXPECT_TRUE(scheduler->CommitPending()); |
| 512 EXPECT_TRUE(scheduler->RedrawPending()); | 528 EXPECT_TRUE(scheduler->RedrawPending()); |
| 513 EXPECT_TRUE(client.needs_begin_frame()); | 529 EXPECT_TRUE(client.needs_begin_frames()); |
| 514 | 530 |
| 515 // Fail the draw again. | 531 // Fail the draw again. |
| 516 client.AdvanceFrame(); | 532 client.AdvanceFrame(); |
| 517 client.task_runner().RunPendingTasks(); // Run posted deadline. | 533 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 518 EXPECT_EQ(2, client.num_draws()); | 534 EXPECT_EQ(2, client.num_draws()); |
| 519 EXPECT_TRUE(scheduler->CommitPending()); | 535 EXPECT_TRUE(scheduler->CommitPending()); |
| 520 EXPECT_TRUE(scheduler->RedrawPending()); | 536 EXPECT_TRUE(scheduler->RedrawPending()); |
| 521 EXPECT_TRUE(client.needs_begin_frame()); | 537 EXPECT_TRUE(client.needs_begin_frames()); |
| 522 | 538 |
| 523 // Draw successfully. | 539 // Draw successfully. |
| 524 client.SetDrawWillHappen(true); | 540 client.SetDrawWillHappen(true); |
| 525 client.AdvanceFrame(); | 541 client.AdvanceFrame(); |
| 526 client.task_runner().RunPendingTasks(); // Run posted deadline. | 542 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 527 EXPECT_EQ(3, client.num_draws()); | 543 EXPECT_EQ(3, client.num_draws()); |
| 528 EXPECT_TRUE(scheduler->CommitPending()); | 544 EXPECT_TRUE(scheduler->CommitPending()); |
| 529 EXPECT_FALSE(scheduler->RedrawPending()); | 545 EXPECT_FALSE(scheduler->RedrawPending()); |
| 530 EXPECT_TRUE(client.needs_begin_frame()); | 546 EXPECT_TRUE(client.needs_begin_frames()); |
| 531 } | 547 } |
| 532 | 548 |
| 533 class SchedulerClientThatSetNeedsCommitInsideDraw : public FakeSchedulerClient { | 549 class SchedulerClientThatSetNeedsCommitInsideDraw : public FakeSchedulerClient { |
| 534 public: | 550 public: |
| 535 SchedulerClientThatSetNeedsCommitInsideDraw() | 551 SchedulerClientThatSetNeedsCommitInsideDraw() |
| 536 : set_needs_commit_on_next_draw_(false) {} | 552 : set_needs_commit_on_next_draw_(false) {} |
| 537 | 553 |
| 538 virtual void ScheduledActionSendBeginMainFrame() OVERRIDE {} | 554 virtual void ScheduledActionSendBeginMainFrame() OVERRIDE {} |
| 539 virtual DrawResult ScheduledActionDrawAndSwapIfPossible() | 555 virtual DrawResult ScheduledActionDrawAndSwapIfPossible() |
| 540 OVERRIDE { | 556 OVERRIDE { |
| (...skipping 25 matching lines...) Expand all Loading... |
| 566 TEST(SchedulerTest, RequestCommitInsideDraw) { | 582 TEST(SchedulerTest, RequestCommitInsideDraw) { |
| 567 SchedulerClientThatSetNeedsCommitInsideDraw client; | 583 SchedulerClientThatSetNeedsCommitInsideDraw client; |
| 568 SchedulerSettings default_scheduler_settings; | 584 SchedulerSettings default_scheduler_settings; |
| 569 TestScheduler* scheduler = client.CreateScheduler(default_scheduler_settings); | 585 TestScheduler* scheduler = client.CreateScheduler(default_scheduler_settings); |
| 570 scheduler->SetCanStart(); | 586 scheduler->SetCanStart(); |
| 571 scheduler->SetVisible(true); | 587 scheduler->SetVisible(true); |
| 572 scheduler->SetCanDraw(true); | 588 scheduler->SetCanDraw(true); |
| 573 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | 589 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
| 574 client.Reset(); | 590 client.Reset(); |
| 575 | 591 |
| 576 EXPECT_FALSE(client.needs_begin_frame()); | 592 EXPECT_FALSE(client.needs_begin_frames()); |
| 577 scheduler->SetNeedsRedraw(); | 593 scheduler->SetNeedsRedraw(); |
| 578 EXPECT_TRUE(scheduler->RedrawPending()); | 594 EXPECT_TRUE(scheduler->RedrawPending()); |
| 579 EXPECT_EQ(0, client.num_draws()); | 595 EXPECT_EQ(0, client.num_draws()); |
| 580 EXPECT_TRUE(client.needs_begin_frame()); | 596 EXPECT_TRUE(client.needs_begin_frames()); |
| 581 | 597 |
| 582 client.SetNeedsCommitOnNextDraw(); | 598 client.SetNeedsCommitOnNextDraw(); |
| 583 client.AdvanceFrame(); | 599 client.AdvanceFrame(); |
| 584 client.SetNeedsCommitOnNextDraw(); | 600 client.SetNeedsCommitOnNextDraw(); |
| 585 client.task_runner().RunPendingTasks(); // Run posted deadline. | 601 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 586 EXPECT_EQ(1, client.num_draws()); | 602 EXPECT_EQ(1, client.num_draws()); |
| 587 EXPECT_TRUE(scheduler->CommitPending()); | 603 EXPECT_TRUE(scheduler->CommitPending()); |
| 588 EXPECT_TRUE(client.needs_begin_frame()); | 604 EXPECT_TRUE(client.needs_begin_frames()); |
| 589 scheduler->NotifyBeginMainFrameStarted(); | 605 scheduler->NotifyBeginMainFrameStarted(); |
| 590 scheduler->NotifyReadyToCommit(); | 606 scheduler->NotifyReadyToCommit(); |
| 591 | 607 |
| 592 client.AdvanceFrame(); | 608 client.AdvanceFrame(); |
| 593 client.task_runner().RunPendingTasks(); // Run posted deadline. | 609 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 594 EXPECT_EQ(2, client.num_draws()); | 610 EXPECT_EQ(2, client.num_draws()); |
| 595 | 611 |
| 596 EXPECT_FALSE(scheduler->RedrawPending()); | 612 EXPECT_FALSE(scheduler->RedrawPending()); |
| 597 EXPECT_FALSE(scheduler->CommitPending()); | 613 EXPECT_FALSE(scheduler->CommitPending()); |
| 598 EXPECT_TRUE(client.needs_begin_frame()); | 614 EXPECT_TRUE(client.needs_begin_frames()); |
| 599 | 615 |
| 600 // We stop requesting BeginImplFrames after a BeginImplFrame where we don't | 616 // We stop requesting BeginImplFrames after a BeginImplFrame where we don't |
| 601 // swap. | 617 // swap. |
| 602 client.AdvanceFrame(); | 618 client.AdvanceFrame(); |
| 603 client.task_runner().RunPendingTasks(); // Run posted deadline. | 619 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 604 EXPECT_EQ(2, client.num_draws()); | 620 EXPECT_EQ(2, client.num_draws()); |
| 605 EXPECT_FALSE(scheduler->RedrawPending()); | 621 EXPECT_FALSE(scheduler->RedrawPending()); |
| 606 EXPECT_FALSE(scheduler->CommitPending()); | 622 EXPECT_FALSE(scheduler->CommitPending()); |
| 607 EXPECT_FALSE(client.needs_begin_frame()); | 623 EXPECT_FALSE(client.needs_begin_frames()); |
| 608 } | 624 } |
| 609 | 625 |
| 610 // Tests that when a draw fails then the pending commit should not be dropped. | 626 // Tests that when a draw fails then the pending commit should not be dropped. |
| 611 TEST(SchedulerTest, RequestCommitInsideFailedDraw) { | 627 TEST(SchedulerTest, RequestCommitInsideFailedDraw) { |
| 612 SchedulerClientThatsetNeedsDrawInsideDraw client; | 628 SchedulerClientThatsetNeedsDrawInsideDraw client; |
| 613 SchedulerSettings default_scheduler_settings; | 629 SchedulerSettings default_scheduler_settings; |
| 614 TestScheduler* scheduler = client.CreateScheduler(default_scheduler_settings); | 630 TestScheduler* scheduler = client.CreateScheduler(default_scheduler_settings); |
| 615 scheduler->SetCanStart(); | 631 scheduler->SetCanStart(); |
| 616 scheduler->SetVisible(true); | 632 scheduler->SetVisible(true); |
| 617 scheduler->SetCanDraw(true); | 633 scheduler->SetCanDraw(true); |
| 618 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | 634 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
| 619 client.Reset(); | 635 client.Reset(); |
| 620 | 636 |
| 621 client.SetDrawWillHappen(false); | 637 client.SetDrawWillHappen(false); |
| 622 | 638 |
| 623 scheduler->SetNeedsRedraw(); | 639 scheduler->SetNeedsRedraw(); |
| 624 EXPECT_TRUE(scheduler->RedrawPending()); | 640 EXPECT_TRUE(scheduler->RedrawPending()); |
| 625 EXPECT_TRUE(client.needs_begin_frame()); | 641 EXPECT_TRUE(client.needs_begin_frames()); |
| 626 EXPECT_EQ(0, client.num_draws()); | 642 EXPECT_EQ(0, client.num_draws()); |
| 627 | 643 |
| 628 // Fail the draw. | 644 // Fail the draw. |
| 629 client.AdvanceFrame(); | 645 client.AdvanceFrame(); |
| 630 client.task_runner().RunPendingTasks(); // Run posted deadline. | 646 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 631 EXPECT_EQ(1, client.num_draws()); | 647 EXPECT_EQ(1, client.num_draws()); |
| 632 | 648 |
| 633 // We have a commit pending and the draw failed, and we didn't lose the commit | 649 // We have a commit pending and the draw failed, and we didn't lose the commit |
| 634 // request. | 650 // request. |
| 635 EXPECT_TRUE(scheduler->CommitPending()); | 651 EXPECT_TRUE(scheduler->CommitPending()); |
| 636 EXPECT_TRUE(scheduler->RedrawPending()); | 652 EXPECT_TRUE(scheduler->RedrawPending()); |
| 637 EXPECT_TRUE(client.needs_begin_frame()); | 653 EXPECT_TRUE(client.needs_begin_frames()); |
| 638 | 654 |
| 639 // Fail the draw again. | 655 // Fail the draw again. |
| 640 client.AdvanceFrame(); | 656 client.AdvanceFrame(); |
| 641 | 657 |
| 642 client.task_runner().RunPendingTasks(); // Run posted deadline. | 658 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 643 EXPECT_EQ(2, client.num_draws()); | 659 EXPECT_EQ(2, client.num_draws()); |
| 644 EXPECT_TRUE(scheduler->CommitPending()); | 660 EXPECT_TRUE(scheduler->CommitPending()); |
| 645 EXPECT_TRUE(scheduler->RedrawPending()); | 661 EXPECT_TRUE(scheduler->RedrawPending()); |
| 646 EXPECT_TRUE(client.needs_begin_frame()); | 662 EXPECT_TRUE(client.needs_begin_frames()); |
| 647 | 663 |
| 648 // Draw successfully. | 664 // Draw successfully. |
| 649 client.SetDrawWillHappen(true); | 665 client.SetDrawWillHappen(true); |
| 650 client.AdvanceFrame(); | 666 client.AdvanceFrame(); |
| 651 client.task_runner().RunPendingTasks(); // Run posted deadline. | 667 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 652 EXPECT_EQ(3, client.num_draws()); | 668 EXPECT_EQ(3, client.num_draws()); |
| 653 EXPECT_TRUE(scheduler->CommitPending()); | 669 EXPECT_TRUE(scheduler->CommitPending()); |
| 654 EXPECT_FALSE(scheduler->RedrawPending()); | 670 EXPECT_FALSE(scheduler->RedrawPending()); |
| 655 EXPECT_TRUE(client.needs_begin_frame()); | 671 EXPECT_TRUE(client.needs_begin_frames()); |
| 656 } | 672 } |
| 657 | 673 |
| 658 TEST(SchedulerTest, NoSwapWhenDrawFails) { | 674 TEST(SchedulerTest, NoSwapWhenDrawFails) { |
| 659 SchedulerClientThatSetNeedsCommitInsideDraw client; | 675 SchedulerClientThatSetNeedsCommitInsideDraw client; |
| 660 SchedulerSettings default_scheduler_settings; | 676 SchedulerSettings default_scheduler_settings; |
| 661 TestScheduler* scheduler = client.CreateScheduler(default_scheduler_settings); | 677 TestScheduler* scheduler = client.CreateScheduler(default_scheduler_settings); |
| 662 scheduler->SetCanStart(); | 678 scheduler->SetCanStart(); |
| 663 scheduler->SetVisible(true); | 679 scheduler->SetVisible(true); |
| 664 scheduler->SetCanDraw(true); | 680 scheduler->SetCanDraw(true); |
| 665 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | 681 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
| 666 client.Reset(); | 682 client.Reset(); |
| 667 | 683 |
| 668 scheduler->SetNeedsRedraw(); | 684 scheduler->SetNeedsRedraw(); |
| 669 EXPECT_TRUE(scheduler->RedrawPending()); | 685 EXPECT_TRUE(scheduler->RedrawPending()); |
| 670 EXPECT_TRUE(client.needs_begin_frame()); | 686 EXPECT_TRUE(client.needs_begin_frames()); |
| 671 EXPECT_EQ(0, client.num_draws()); | 687 EXPECT_EQ(0, client.num_draws()); |
| 672 | 688 |
| 673 // Draw successfully, this starts a new frame. | 689 // Draw successfully, this starts a new frame. |
| 674 client.SetNeedsCommitOnNextDraw(); | 690 client.SetNeedsCommitOnNextDraw(); |
| 675 client.AdvanceFrame(); | 691 client.AdvanceFrame(); |
| 676 client.task_runner().RunPendingTasks(); // Run posted deadline. | 692 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 677 EXPECT_EQ(1, client.num_draws()); | 693 EXPECT_EQ(1, client.num_draws()); |
| 678 | 694 |
| 679 scheduler->SetNeedsRedraw(); | 695 scheduler->SetNeedsRedraw(); |
| 680 EXPECT_TRUE(scheduler->RedrawPending()); | 696 EXPECT_TRUE(scheduler->RedrawPending()); |
| 681 EXPECT_TRUE(client.needs_begin_frame()); | 697 EXPECT_TRUE(client.needs_begin_frames()); |
| 682 | 698 |
| 683 // Fail to draw, this should not start a frame. | 699 // Fail to draw, this should not start a frame. |
| 684 client.SetDrawWillHappen(false); | 700 client.SetDrawWillHappen(false); |
| 685 client.SetNeedsCommitOnNextDraw(); | 701 client.SetNeedsCommitOnNextDraw(); |
| 686 client.AdvanceFrame(); | 702 client.AdvanceFrame(); |
| 687 client.task_runner().RunPendingTasks(); // Run posted deadline. | 703 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 688 EXPECT_EQ(2, client.num_draws()); | 704 EXPECT_EQ(2, client.num_draws()); |
| 689 } | 705 } |
| 690 | 706 |
| 691 class SchedulerClientNeedsManageTilesInDraw : public FakeSchedulerClient { | 707 class SchedulerClientNeedsManageTilesInDraw : public FakeSchedulerClient { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 707 scheduler->SetCanDraw(true); | 723 scheduler->SetCanDraw(true); |
| 708 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | 724 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
| 709 | 725 |
| 710 // Request both draw and manage tiles. ManageTiles shouldn't | 726 // Request both draw and manage tiles. ManageTiles shouldn't |
| 711 // be trigged until BeginImplFrame. | 727 // be trigged until BeginImplFrame. |
| 712 client.Reset(); | 728 client.Reset(); |
| 713 scheduler->SetNeedsManageTiles(); | 729 scheduler->SetNeedsManageTiles(); |
| 714 scheduler->SetNeedsRedraw(); | 730 scheduler->SetNeedsRedraw(); |
| 715 EXPECT_TRUE(scheduler->RedrawPending()); | 731 EXPECT_TRUE(scheduler->RedrawPending()); |
| 716 EXPECT_TRUE(scheduler->ManageTilesPending()); | 732 EXPECT_TRUE(scheduler->ManageTilesPending()); |
| 717 EXPECT_TRUE(client.needs_begin_frame()); | 733 EXPECT_TRUE(client.needs_begin_frames()); |
| 718 EXPECT_EQ(0, client.num_draws()); | 734 EXPECT_EQ(0, client.num_draws()); |
| 719 EXPECT_FALSE(client.HasAction("ScheduledActionManageTiles")); | 735 EXPECT_FALSE(client.HasAction("ScheduledActionManageTiles")); |
| 720 EXPECT_FALSE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); | 736 EXPECT_FALSE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); |
| 721 | 737 |
| 722 // We have no immediate actions to perform, so the BeginImplFrame should post | 738 // We have no immediate actions to perform, so the BeginImplFrame should post |
| 723 // the deadline task. | 739 // the deadline task. |
| 724 client.Reset(); | 740 client.Reset(); |
| 725 client.AdvanceFrame(); | 741 client.AdvanceFrame(); |
| 726 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 742 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
| 727 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); | 743 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); |
| 728 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 744 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 729 | 745 |
| 730 // On the deadline, he actions should have occured in the right order. | 746 // On the deadline, he actions should have occured in the right order. |
| 731 client.Reset(); | 747 client.Reset(); |
| 732 client.task_runner().RunPendingTasks(); // Run posted deadline. | 748 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 733 EXPECT_EQ(1, client.num_draws()); | 749 EXPECT_EQ(1, client.num_draws()); |
| 734 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); | 750 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); |
| 735 EXPECT_TRUE(client.HasAction("ScheduledActionManageTiles")); | 751 EXPECT_TRUE(client.HasAction("ScheduledActionManageTiles")); |
| 736 EXPECT_LT(client.ActionIndex("ScheduledActionDrawAndSwapIfPossible"), | 752 EXPECT_LT(client.ActionIndex("ScheduledActionDrawAndSwapIfPossible"), |
| 737 client.ActionIndex("ScheduledActionManageTiles")); | 753 client.ActionIndex("ScheduledActionManageTiles")); |
| 738 EXPECT_FALSE(scheduler->RedrawPending()); | 754 EXPECT_FALSE(scheduler->RedrawPending()); |
| 739 EXPECT_FALSE(scheduler->ManageTilesPending()); | 755 EXPECT_FALSE(scheduler->ManageTilesPending()); |
| 740 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 756 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
| 741 | 757 |
| 742 // Request a draw. We don't need a ManageTiles yet. | 758 // Request a draw. We don't need a ManageTiles yet. |
| 743 client.Reset(); | 759 client.Reset(); |
| 744 scheduler->SetNeedsRedraw(); | 760 scheduler->SetNeedsRedraw(); |
| 745 EXPECT_TRUE(scheduler->RedrawPending()); | 761 EXPECT_TRUE(scheduler->RedrawPending()); |
| 746 EXPECT_FALSE(scheduler->ManageTilesPending()); | 762 EXPECT_FALSE(scheduler->ManageTilesPending()); |
| 747 EXPECT_TRUE(client.needs_begin_frame()); | 763 EXPECT_TRUE(client.needs_begin_frames()); |
| 748 EXPECT_EQ(0, client.num_draws()); | 764 EXPECT_EQ(0, client.num_draws()); |
| 749 | 765 |
| 750 // We have no immediate actions to perform, so the BeginImplFrame should post | 766 // We have no immediate actions to perform, so the BeginImplFrame should post |
| 751 // the deadline task. | 767 // the deadline task. |
| 752 client.Reset(); | 768 client.Reset(); |
| 753 client.AdvanceFrame(); | 769 client.AdvanceFrame(); |
| 754 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 770 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
| 755 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); | 771 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); |
| 756 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 772 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 757 | 773 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 769 EXPECT_FALSE(scheduler->ManageTilesPending()); | 785 EXPECT_FALSE(scheduler->ManageTilesPending()); |
| 770 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 786 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
| 771 | 787 |
| 772 // We need a BeginImplFrame where we don't swap to go idle. | 788 // We need a BeginImplFrame where we don't swap to go idle. |
| 773 client.Reset(); | 789 client.Reset(); |
| 774 client.AdvanceFrame(); | 790 client.AdvanceFrame(); |
| 775 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); | 791 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); |
| 776 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 792 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 777 client.Reset(); | 793 client.Reset(); |
| 778 client.task_runner().RunPendingTasks(); // Run posted deadline. | 794 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 779 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); | 795 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames", client); |
| 780 EXPECT_FALSE(client.needs_begin_frame()); | 796 EXPECT_FALSE(client.needs_begin_frames()); |
| 781 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 797 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
| 782 EXPECT_EQ(0, client.num_draws()); | 798 EXPECT_EQ(0, client.num_draws()); |
| 783 | 799 |
| 784 // Now trigger a ManageTiles outside of a draw. We will then need | 800 // Now trigger a ManageTiles outside of a draw. We will then need |
| 785 // a begin-frame for the ManageTiles, but we don't need a draw. | 801 // a begin-frame for the ManageTiles, but we don't need a draw. |
| 786 client.Reset(); | 802 client.Reset(); |
| 787 EXPECT_FALSE(client.needs_begin_frame()); | 803 EXPECT_FALSE(client.needs_begin_frames()); |
| 788 scheduler->SetNeedsManageTiles(); | 804 scheduler->SetNeedsManageTiles(); |
| 789 EXPECT_TRUE(client.needs_begin_frame()); | 805 EXPECT_TRUE(client.needs_begin_frames()); |
| 790 EXPECT_TRUE(scheduler->ManageTilesPending()); | 806 EXPECT_TRUE(scheduler->ManageTilesPending()); |
| 791 EXPECT_FALSE(scheduler->RedrawPending()); | 807 EXPECT_FALSE(scheduler->RedrawPending()); |
| 792 | 808 |
| 793 // BeginImplFrame. There will be no draw, only ManageTiles. | 809 // BeginImplFrame. There will be no draw, only ManageTiles. |
| 794 client.Reset(); | 810 client.Reset(); |
| 795 client.AdvanceFrame(); | 811 client.AdvanceFrame(); |
| 796 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); | 812 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); |
| 797 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 813 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 798 client.Reset(); | 814 client.Reset(); |
| 799 client.task_runner().RunPendingTasks(); // Run posted deadline. | 815 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 931 scheduler->SetCanStart(); | 947 scheduler->SetCanStart(); |
| 932 scheduler->SetVisible(true); | 948 scheduler->SetVisible(true); |
| 933 scheduler->SetCanDraw(true); | 949 scheduler->SetCanDraw(true); |
| 934 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | 950 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
| 935 | 951 |
| 936 client.SetRedrawWillHappenIfUpdateVisibleTilesHappens(true); | 952 client.SetRedrawWillHappenIfUpdateVisibleTilesHappens(true); |
| 937 | 953 |
| 938 // SetNeedsCommit should begin the frame. | 954 // SetNeedsCommit should begin the frame. |
| 939 client.Reset(); | 955 client.Reset(); |
| 940 scheduler->SetNeedsCommit(); | 956 scheduler->SetNeedsCommit(); |
| 941 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); | 957 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames", client); |
| 942 | 958 |
| 943 client.Reset(); | 959 client.Reset(); |
| 944 client.AdvanceFrame(); | 960 client.AdvanceFrame(); |
| 945 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 961 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
| 946 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); | 962 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); |
| 947 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 963 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 948 | 964 |
| 949 client.Reset(); | 965 client.Reset(); |
| 950 scheduler->NotifyBeginMainFrameStarted(); | 966 scheduler->NotifyBeginMainFrameStarted(); |
| 951 scheduler->NotifyReadyToCommit(); | 967 scheduler->NotifyReadyToCommit(); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 974 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 2, 3); | 990 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 2, 3); |
| 975 | 991 |
| 976 client.Reset(); | 992 client.Reset(); |
| 977 client.AdvanceFrame(); | 993 client.AdvanceFrame(); |
| 978 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); | 994 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); |
| 979 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 995 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 980 | 996 |
| 981 // No more UpdateVisibleTiles(). | 997 // No more UpdateVisibleTiles(). |
| 982 client.Reset(); | 998 client.Reset(); |
| 983 client.task_runner().RunPendingTasks(); // Run posted deadline. | 999 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 984 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); | 1000 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames", client); |
| 985 EXPECT_FALSE(client.needs_begin_frame()); | 1001 EXPECT_FALSE(client.needs_begin_frames()); |
| 986 } | 1002 } |
| 987 | 1003 |
| 988 TEST(SchedulerTest, TriggerBeginFrameDeadlineEarly) { | 1004 TEST(SchedulerTest, TriggerBeginFrameDeadlineEarly) { |
| 989 SchedulerClientNeedsManageTilesInDraw client; | 1005 SchedulerClientNeedsManageTilesInDraw client; |
| 990 SchedulerSettings default_scheduler_settings; | 1006 SchedulerSettings default_scheduler_settings; |
| 991 TestScheduler* scheduler = client.CreateScheduler(default_scheduler_settings); | 1007 TestScheduler* scheduler = client.CreateScheduler(default_scheduler_settings); |
| 992 scheduler->SetCanStart(); | 1008 scheduler->SetCanStart(); |
| 993 scheduler->SetVisible(true); | 1009 scheduler->SetVisible(true); |
| 994 scheduler->SetCanDraw(true); | 1010 scheduler->SetCanDraw(true); |
| 995 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | 1011 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1116 scheduler->DidCreateAndInitializeOutputSurface(); | 1132 scheduler->DidCreateAndInitializeOutputSurface(); |
| 1117 | 1133 |
| 1118 scheduler->SetNeedsCommit(); | 1134 scheduler->SetNeedsCommit(); |
| 1119 EXPECT_TRUE(scheduler->CommitPending()); | 1135 EXPECT_TRUE(scheduler->CommitPending()); |
| 1120 scheduler->NotifyBeginMainFrameStarted(); | 1136 scheduler->NotifyBeginMainFrameStarted(); |
| 1121 scheduler->NotifyReadyToCommit(); | 1137 scheduler->NotifyReadyToCommit(); |
| 1122 scheduler->SetNeedsRedraw(); | 1138 scheduler->SetNeedsRedraw(); |
| 1123 | 1139 |
| 1124 BeginFrameArgs frame_args = CreateBeginFrameArgsForTesting(client.now_src()); | 1140 BeginFrameArgs frame_args = CreateBeginFrameArgsForTesting(client.now_src()); |
| 1125 frame_args.interval = base::TimeDelta::FromMilliseconds(1000); | 1141 frame_args.interval = base::TimeDelta::FromMilliseconds(1000); |
| 1126 scheduler->BeginFrame(frame_args); | 1142 client.GetBeginFrameSource()->TestSendBeginFrame(frame_args); |
| 1127 | 1143 |
| 1128 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1144 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 1129 client.task_runner().RunPendingTasks(); // Run posted deadline. | 1145 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 1130 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 1146 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
| 1131 | 1147 |
| 1132 scheduler->DidSwapBuffers(); | 1148 scheduler->DidSwapBuffers(); |
| 1133 scheduler->DidSwapBuffersComplete(); | 1149 scheduler->DidSwapBuffersComplete(); |
| 1134 | 1150 |
| 1135 // At this point, we've drawn a frame. Start another commit, but hold off on | 1151 // At this point, we've drawn a frame. Start another commit, but hold off on |
| 1136 // the NotifyReadyToCommit for now. | 1152 // the NotifyReadyToCommit for now. |
| 1137 EXPECT_FALSE(scheduler->CommitPending()); | 1153 EXPECT_FALSE(scheduler->CommitPending()); |
| 1138 scheduler->SetNeedsCommit(); | 1154 scheduler->SetNeedsCommit(); |
| 1139 scheduler->BeginFrame(frame_args); | 1155 client.GetBeginFrameSource()->TestSendBeginFrame(frame_args); |
| 1140 EXPECT_TRUE(scheduler->CommitPending()); | 1156 EXPECT_TRUE(scheduler->CommitPending()); |
| 1141 | 1157 |
| 1142 // Draw and swap the frame, but don't ack the swap to simulate the Browser | 1158 // Draw and swap the frame, but don't ack the swap to simulate the Browser |
| 1143 // blocking on the renderer. | 1159 // blocking on the renderer. |
| 1144 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1160 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 1145 client.task_runner().RunPendingTasks(); // Run posted deadline. | 1161 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 1146 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 1162 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
| 1147 scheduler->DidSwapBuffers(); | 1163 scheduler->DidSwapBuffers(); |
| 1148 | 1164 |
| 1149 // Spin the event loop a few times and make sure we get more | 1165 // Spin the event loop a few times and make sure we get more |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1181 SchedulerSettings scheduler_settings; | 1197 SchedulerSettings scheduler_settings; |
| 1182 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings); | 1198 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings); |
| 1183 scheduler->SetCanStart(); | 1199 scheduler->SetCanStart(); |
| 1184 scheduler->SetVisible(true); | 1200 scheduler->SetVisible(true); |
| 1185 scheduler->SetCanDraw(true); | 1201 scheduler->SetCanDraw(true); |
| 1186 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | 1202 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
| 1187 | 1203 |
| 1188 // SetNeedsCommit should begin the frame on the next BeginImplFrame. | 1204 // SetNeedsCommit should begin the frame on the next BeginImplFrame. |
| 1189 client.Reset(); | 1205 client.Reset(); |
| 1190 scheduler->SetNeedsCommit(); | 1206 scheduler->SetNeedsCommit(); |
| 1191 EXPECT_TRUE(client.needs_begin_frame()); | 1207 EXPECT_TRUE(client.needs_begin_frames()); |
| 1192 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); | 1208 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames", client); |
| 1193 client.Reset(); | 1209 client.Reset(); |
| 1194 | 1210 |
| 1195 // Create a BeginFrame with a long deadline to avoid race conditions. | 1211 // Create a BeginFrame with a long deadline to avoid race conditions. |
| 1196 // This is the first BeginFrame, which will be handled immediately. | 1212 // This is the first BeginFrame, which will be handled immediately. |
| 1197 BeginFrameArgs args = CreateBeginFrameArgsForTesting(client.now_src()); | 1213 BeginFrameArgs args = CreateBeginFrameArgsForTesting(client.now_src()); |
| 1198 args.deadline += base::TimeDelta::FromHours(1); | 1214 args.deadline += base::TimeDelta::FromHours(1); |
| 1199 scheduler->BeginFrame(args); | 1215 client.GetBeginFrameSource()->TestSendBeginFrame(args); |
| 1200 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 1216 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
| 1201 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); | 1217 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); |
| 1202 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1218 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 1203 EXPECT_TRUE(client.needs_begin_frame()); | 1219 EXPECT_TRUE(client.needs_begin_frames()); |
| 1204 client.Reset(); | 1220 client.Reset(); |
| 1205 | 1221 |
| 1206 // Queue BeginFrames while we are still handling the previous BeginFrame. | 1222 // Queue BeginFrames while we are still handling the previous BeginFrame. |
| 1207 args.frame_time += base::TimeDelta::FromSeconds(1); | 1223 args.frame_time += base::TimeDelta::FromSeconds(1); |
| 1208 scheduler->BeginFrame(args); | 1224 client.GetBeginFrameSource()->TestSendBeginFrame(args); |
| 1209 args.frame_time += base::TimeDelta::FromSeconds(1); | 1225 args.frame_time += base::TimeDelta::FromSeconds(1); |
| 1210 scheduler->BeginFrame(args); | 1226 client.GetBeginFrameSource()->TestSendBeginFrame(args); |
| 1211 | 1227 |
| 1212 // If we don't swap on the deadline, we wait for the next BeginImplFrame. | 1228 // If we don't swap on the deadline, we wait for the next BeginImplFrame. |
| 1213 client.task_runner().RunPendingTasks(); // Run posted deadline. | 1229 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 1214 EXPECT_NO_ACTION(client); | 1230 EXPECT_NO_ACTION(client); |
| 1215 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 1231 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
| 1216 EXPECT_TRUE(client.needs_begin_frame()); | 1232 EXPECT_TRUE(client.needs_begin_frames()); |
| 1217 client.Reset(); | 1233 client.Reset(); |
| 1218 | 1234 |
| 1219 // NotifyReadyToCommit should trigger the commit. | 1235 // NotifyReadyToCommit should trigger the commit. |
| 1220 scheduler->NotifyBeginMainFrameStarted(); | 1236 scheduler->NotifyBeginMainFrameStarted(); |
| 1221 scheduler->NotifyReadyToCommit(); | 1237 scheduler->NotifyReadyToCommit(); |
| 1222 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); | 1238 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); |
| 1223 EXPECT_TRUE(client.needs_begin_frame()); | 1239 EXPECT_TRUE(client.needs_begin_frames()); |
| 1224 client.Reset(); | 1240 client.Reset(); |
| 1225 | 1241 |
| 1226 // BeginImplFrame should prepare the draw. | 1242 // BeginImplFrame should prepare the draw. |
| 1227 client.task_runner().RunPendingTasks(); // Run posted BeginRetroFrame. | 1243 client.task_runner().RunPendingTasks(); // Run posted BeginRetroFrame. |
| 1228 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 1244 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
| 1229 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); | 1245 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); |
| 1230 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1246 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 1231 EXPECT_TRUE(client.needs_begin_frame()); | 1247 EXPECT_TRUE(client.needs_begin_frames()); |
| 1232 client.Reset(); | 1248 client.Reset(); |
| 1233 | 1249 |
| 1234 // BeginImplFrame deadline should draw. | 1250 // BeginImplFrame deadline should draw. |
| 1235 client.task_runner().RunPendingTasks(); // Run posted deadline. | 1251 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 1236 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 1); | 1252 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 1); |
| 1237 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 1253 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
| 1238 EXPECT_TRUE(client.needs_begin_frame()); | 1254 EXPECT_TRUE(client.needs_begin_frames()); |
| 1239 client.Reset(); | 1255 client.Reset(); |
| 1240 | 1256 |
| 1241 // The following BeginImplFrame deadline should SetNeedsBeginFrame(false) | 1257 // The following BeginImplFrame deadline should SetNeedsBeginFrame(false) |
| 1242 // to avoid excessive toggles. | 1258 // to avoid excessive toggles. |
| 1243 client.task_runner().RunPendingTasks(); // Run posted BeginRetroFrame. | 1259 client.task_runner().RunPendingTasks(); // Run posted BeginRetroFrame. |
| 1244 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); | 1260 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); |
| 1245 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1261 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 1246 client.Reset(); | 1262 client.Reset(); |
| 1247 | 1263 |
| 1248 client.task_runner().RunPendingTasks(); // Run posted deadline. | 1264 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 1249 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); | 1265 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames", client); |
| 1250 EXPECT_FALSE(client.needs_begin_frame()); | 1266 EXPECT_FALSE(client.needs_begin_frames()); |
| 1251 client.Reset(); | 1267 client.Reset(); |
| 1252 } | 1268 } |
| 1253 | 1269 |
| 1254 TEST(SchedulerTest, BeginRetroFrame_SwapThrottled) { | 1270 TEST(SchedulerTest, BeginRetroFrame_SwapThrottled) { |
| 1255 FakeSchedulerClient client; | 1271 FakeSchedulerClient client; |
| 1256 SchedulerSettings scheduler_settings; | 1272 SchedulerSettings scheduler_settings; |
| 1257 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings); | 1273 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings); |
| 1258 scheduler->SetCanStart(); | 1274 scheduler->SetCanStart(); |
| 1259 scheduler->SetVisible(true); | 1275 scheduler->SetVisible(true); |
| 1260 scheduler->SetCanDraw(true); | 1276 scheduler->SetCanDraw(true); |
| 1261 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | 1277 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
| 1262 | 1278 |
| 1263 // To test swap ack throttling, this test disables automatic swap acks. | 1279 // To test swap ack throttling, this test disables automatic swap acks. |
| 1264 scheduler->SetMaxSwapsPending(1); | 1280 scheduler->SetMaxSwapsPending(1); |
| 1265 client.SetAutomaticSwapAck(false); | 1281 client.SetAutomaticSwapAck(false); |
| 1266 | 1282 |
| 1267 // SetNeedsCommit should begin the frame on the next BeginImplFrame. | 1283 // SetNeedsCommit should begin the frame on the next BeginImplFrame. |
| 1268 client.Reset(); | 1284 client.Reset(); |
| 1269 scheduler->SetNeedsCommit(); | 1285 scheduler->SetNeedsCommit(); |
| 1270 EXPECT_TRUE(client.needs_begin_frame()); | 1286 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames", client); |
| 1271 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); | 1287 EXPECT_TRUE(client.needs_begin_frames()); |
| 1272 client.Reset(); | 1288 client.Reset(); |
| 1273 | 1289 |
| 1274 // Create a BeginFrame with a long deadline to avoid race conditions. | 1290 // Create a BeginFrame with a long deadline to avoid race conditions. |
| 1275 // This is the first BeginFrame, which will be handled immediately. | 1291 // This is the first BeginFrame, which will be handled immediately. |
| 1276 BeginFrameArgs args = CreateBeginFrameArgsForTesting(client.now_src()); | 1292 BeginFrameArgs args = CreateBeginFrameArgsForTesting(client.now_src()); |
| 1277 args.deadline += base::TimeDelta::FromHours(1); | 1293 args.deadline += base::TimeDelta::FromHours(1); |
| 1278 scheduler->BeginFrame(args); | 1294 client.GetBeginFrameSource()->TestSendBeginFrame(args); |
| 1279 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 1295 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
| 1280 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); | 1296 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); |
| 1281 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1297 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 1282 EXPECT_TRUE(client.needs_begin_frame()); | 1298 EXPECT_TRUE(client.needs_begin_frames()); |
| 1283 client.Reset(); | 1299 client.Reset(); |
| 1284 | 1300 |
| 1285 // Queue BeginFrame while we are still handling the previous BeginFrame. | 1301 // Queue BeginFrame while we are still handling the previous BeginFrame. |
| 1286 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1302 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 1287 args.frame_time += base::TimeDelta::FromSeconds(1); | 1303 args.frame_time += base::TimeDelta::FromSeconds(1); |
| 1288 scheduler->BeginFrame(args); | 1304 client.GetBeginFrameSource()->TestSendBeginFrame(args); |
| 1289 EXPECT_NO_ACTION(client); | 1305 EXPECT_NO_ACTION(client); |
| 1290 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1306 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 1291 client.Reset(); | 1307 client.Reset(); |
| 1292 | 1308 |
| 1293 // NotifyReadyToCommit should trigger the pending commit and draw. | 1309 // NotifyReadyToCommit should trigger the pending commit and draw. |
| 1294 scheduler->NotifyBeginMainFrameStarted(); | 1310 scheduler->NotifyBeginMainFrameStarted(); |
| 1295 scheduler->NotifyReadyToCommit(); | 1311 scheduler->NotifyReadyToCommit(); |
| 1296 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); | 1312 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); |
| 1297 EXPECT_TRUE(client.needs_begin_frame()); | 1313 EXPECT_TRUE(client.needs_begin_frames()); |
| 1298 client.Reset(); | 1314 client.Reset(); |
| 1299 | 1315 |
| 1300 // Swapping will put us into a swap throttled state. | 1316 // Swapping will put us into a swap throttled state. |
| 1301 client.task_runner().RunPendingTasks(); // Run posted deadline. | 1317 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 1302 EXPECT_ACTION("ScheduledActionAnimate", client, 0, 2); | 1318 EXPECT_ACTION("ScheduledActionAnimate", client, 0, 2); |
| 1303 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 1, 2); | 1319 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 1, 2); |
| 1304 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 1320 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
| 1305 EXPECT_TRUE(client.needs_begin_frame()); | 1321 EXPECT_TRUE(client.needs_begin_frames()); |
| 1306 client.Reset(); | 1322 client.Reset(); |
| 1307 | 1323 |
| 1308 // While swap throttled, BeginRetroFrames should trigger BeginImplFrames | 1324 // While swap throttled, BeginRetroFrames should trigger BeginImplFrames |
| 1309 // but not a BeginMainFrame or draw. | 1325 // but not a BeginMainFrame or draw. |
| 1310 scheduler->SetNeedsCommit(); | 1326 scheduler->SetNeedsCommit(); |
| 1311 client.task_runner().RunPendingTasks(); // Run posted BeginRetroFrame. | 1327 client.task_runner().RunPendingTasks(); // Run posted BeginRetroFrame. |
| 1312 EXPECT_ACTION("WillBeginImplFrame", client, 0, 1); | 1328 EXPECT_ACTION("WillBeginImplFrame", client, 0, 1); |
| 1313 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1329 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 1314 EXPECT_TRUE(client.needs_begin_frame()); | 1330 EXPECT_TRUE(client.needs_begin_frames()); |
| 1315 client.Reset(); | 1331 client.Reset(); |
| 1316 | 1332 |
| 1317 // Queue BeginFrame while we are still handling the previous BeginFrame. | 1333 // Queue BeginFrame while we are still handling the previous BeginFrame. |
| 1318 args.frame_time += base::TimeDelta::FromSeconds(1); | 1334 args.frame_time += base::TimeDelta::FromSeconds(1); |
| 1319 scheduler->BeginFrame(args); | 1335 client.GetBeginFrameSource()->TestSendBeginFrame(args); |
| 1320 EXPECT_NO_ACTION(client); | 1336 EXPECT_NO_ACTION(client); |
| 1321 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1337 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 1322 EXPECT_TRUE(client.needs_begin_frame()); | 1338 EXPECT_TRUE(client.needs_begin_frames()); |
| 1323 client.Reset(); | 1339 client.Reset(); |
| 1324 | 1340 |
| 1325 // Take us out of a swap throttled state. | 1341 // Take us out of a swap throttled state. |
| 1326 scheduler->DidSwapBuffersComplete(); | 1342 scheduler->DidSwapBuffersComplete(); |
| 1327 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 0, 1); | 1343 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 0, 1); |
| 1328 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1344 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 1329 EXPECT_TRUE(client.needs_begin_frame()); | 1345 EXPECT_TRUE(client.needs_begin_frames()); |
| 1330 client.Reset(); | 1346 client.Reset(); |
| 1331 | 1347 |
| 1332 // BeginImplFrame deadline should draw. | 1348 // BeginImplFrame deadline should draw. |
| 1333 scheduler->SetNeedsRedraw(); | 1349 scheduler->SetNeedsRedraw(); |
| 1334 | 1350 |
| 1335 EXPECT_TRUE(client.task_runner().RunTasksWhile( | 1351 EXPECT_TRUE(client.task_runner().RunTasksWhile( |
| 1336 client.ImplFrameDeadlinePending(true))); | 1352 client.ImplFrameDeadlinePending(true))); |
| 1337 | 1353 |
| 1338 EXPECT_ACTION("ScheduledActionAnimate", client, 0, 2); | 1354 EXPECT_ACTION("ScheduledActionAnimate", client, 0, 2); |
| 1339 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 1, 2); | 1355 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 1, 2); |
| 1340 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 1356 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
| 1341 EXPECT_TRUE(client.needs_begin_frame()); | 1357 EXPECT_TRUE(client.needs_begin_frames()); |
| 1342 client.Reset(); | 1358 client.Reset(); |
| 1343 } | 1359 } |
| 1344 | 1360 |
| 1345 void BeginFramesNotFromClient(bool begin_frame_scheduling_enabled, | 1361 void BeginFramesNotFromClient(bool begin_frame_scheduling_enabled, |
| 1346 bool throttle_frame_production) { | 1362 bool throttle_frame_production) { |
| 1347 FakeSchedulerClient client; | 1363 FakeSchedulerClient client; |
| 1348 SchedulerSettings scheduler_settings; | 1364 SchedulerSettings scheduler_settings; |
| 1349 scheduler_settings.begin_frame_scheduling_enabled = | 1365 scheduler_settings.begin_frame_scheduling_enabled = |
| 1350 begin_frame_scheduling_enabled; | 1366 begin_frame_scheduling_enabled; |
| 1351 scheduler_settings.throttle_frame_production = throttle_frame_production; | 1367 scheduler_settings.throttle_frame_production = throttle_frame_production; |
| 1352 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings); | 1368 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings); |
| 1353 scheduler->SetCanStart(); | 1369 scheduler->SetCanStart(); |
| 1354 scheduler->SetVisible(true); | 1370 scheduler->SetVisible(true); |
| 1355 scheduler->SetCanDraw(true); | 1371 scheduler->SetCanDraw(true); |
| 1356 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | 1372 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
| 1357 | 1373 |
| 1358 // SetNeedsCommit should begin the frame on the next BeginImplFrame | 1374 // SetNeedsCommit should begin the frame on the next BeginImplFrame |
| 1359 // without calling SetNeedsBeginFrame. | 1375 // without calling SetNeedsBeginFrame. |
| 1360 client.Reset(); | 1376 client.Reset(); |
| 1361 scheduler->SetNeedsCommit(); | 1377 scheduler->SetNeedsCommit(); |
| 1362 EXPECT_FALSE(client.needs_begin_frame()); | 1378 EXPECT_FALSE(client.needs_begin_frames()); |
| 1363 EXPECT_NO_ACTION(client); | 1379 EXPECT_NO_ACTION(client); |
| 1364 client.Reset(); | 1380 client.Reset(); |
| 1365 | 1381 |
| 1366 // When the client-driven BeginFrame are disabled, the scheduler posts it's | 1382 // When the client-driven BeginFrame are disabled, the scheduler posts it's |
| 1367 // own BeginFrame tasks. | 1383 // own BeginFrame tasks. |
| 1368 client.task_runner().RunPendingTasks(); // Run posted BeginFrame. | 1384 client.task_runner().RunPendingTasks(); // Run posted BeginFrame. |
| 1369 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 1385 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
| 1370 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); | 1386 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); |
| 1371 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1387 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 1372 EXPECT_FALSE(client.needs_begin_frame()); | 1388 EXPECT_FALSE(client.needs_begin_frames()); |
| 1373 client.Reset(); | 1389 client.Reset(); |
| 1374 | 1390 |
| 1375 // If we don't swap on the deadline, we wait for the next BeginFrame. | 1391 // If we don't swap on the deadline, we wait for the next BeginFrame. |
| 1376 client.task_runner().RunPendingTasks(); // Run posted deadline. | 1392 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 1377 EXPECT_NO_ACTION(client); | 1393 EXPECT_NO_ACTION(client); |
| 1378 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 1394 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
| 1379 EXPECT_FALSE(client.needs_begin_frame()); | 1395 EXPECT_FALSE(client.needs_begin_frames()); |
| 1380 client.Reset(); | 1396 client.Reset(); |
| 1381 | 1397 |
| 1382 // NotifyReadyToCommit should trigger the commit. | 1398 // NotifyReadyToCommit should trigger the commit. |
| 1383 scheduler->NotifyBeginMainFrameStarted(); | 1399 scheduler->NotifyBeginMainFrameStarted(); |
| 1384 scheduler->NotifyReadyToCommit(); | 1400 scheduler->NotifyReadyToCommit(); |
| 1385 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); | 1401 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); |
| 1386 EXPECT_FALSE(client.needs_begin_frame()); | 1402 EXPECT_FALSE(client.needs_begin_frames()); |
| 1387 client.Reset(); | 1403 client.Reset(); |
| 1388 | 1404 |
| 1389 // BeginImplFrame should prepare the draw. | 1405 // BeginImplFrame should prepare the draw. |
| 1390 client.task_runner().RunPendingTasks(); // Run posted BeginFrame. | 1406 client.task_runner().RunPendingTasks(); // Run posted BeginFrame. |
| 1391 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 1407 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
| 1392 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); | 1408 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); |
| 1393 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1409 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 1394 EXPECT_FALSE(client.needs_begin_frame()); | 1410 EXPECT_FALSE(client.needs_begin_frames()); |
| 1395 client.Reset(); | 1411 client.Reset(); |
| 1396 | 1412 |
| 1397 // BeginImplFrame deadline should draw. | 1413 // BeginImplFrame deadline should draw. |
| 1398 client.task_runner().RunTasksWhile(client.ImplFrameDeadlinePending(true)); | 1414 client.task_runner().RunTasksWhile(client.ImplFrameDeadlinePending(true)); |
| 1399 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 1); | 1415 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 1); |
| 1400 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 1416 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
| 1401 EXPECT_FALSE(client.needs_begin_frame()); | 1417 EXPECT_FALSE(client.needs_begin_frames()); |
| 1402 client.Reset(); | 1418 client.Reset(); |
| 1403 | 1419 |
| 1404 // The following BeginImplFrame deadline should SetNeedsBeginFrame(false) | 1420 // The following BeginImplFrame deadline should SetNeedsBeginFrame(false) |
| 1405 // to avoid excessive toggles. | 1421 // to avoid excessive toggles. |
| 1406 client.task_runner().RunPendingTasks(); // Run posted BeginFrame. | 1422 client.task_runner().RunPendingTasks(); // Run posted BeginFrame. |
| 1407 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); | 1423 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); |
| 1408 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1424 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 1409 client.Reset(); | 1425 client.Reset(); |
| 1410 | 1426 |
| 1411 // Make sure SetNeedsBeginFrame isn't called on the client | 1427 // Make sure SetNeedsBeginFrame isn't called on the client |
| 1412 // when the BeginFrame is no longer needed. | 1428 // when the BeginFrame is no longer needed. |
| 1413 client.task_runner().RunPendingTasks(); // Run posted deadline. | 1429 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 1414 EXPECT_NO_ACTION(client); | 1430 EXPECT_NO_ACTION(client); |
| 1415 EXPECT_FALSE(client.needs_begin_frame()); | 1431 EXPECT_FALSE(client.needs_begin_frames()); |
| 1416 client.Reset(); | 1432 client.Reset(); |
| 1417 } | 1433 } |
| 1418 | 1434 |
| 1419 TEST(SchedulerTest, SyntheticBeginFrames) { | 1435 TEST(SchedulerTest, SyntheticBeginFrames) { |
| 1420 bool begin_frame_scheduling_enabled = false; | 1436 bool begin_frame_scheduling_enabled = false; |
| 1421 bool throttle_frame_production = true; | 1437 bool throttle_frame_production = true; |
| 1422 BeginFramesNotFromClient(begin_frame_scheduling_enabled, | 1438 BeginFramesNotFromClient(begin_frame_scheduling_enabled, |
| 1423 throttle_frame_production); | 1439 throttle_frame_production); |
| 1424 } | 1440 } |
| 1425 | 1441 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 1450 scheduler->SetCanDraw(true); | 1466 scheduler->SetCanDraw(true); |
| 1451 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | 1467 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
| 1452 | 1468 |
| 1453 // To test swap ack throttling, this test disables automatic swap acks. | 1469 // To test swap ack throttling, this test disables automatic swap acks. |
| 1454 scheduler->SetMaxSwapsPending(1); | 1470 scheduler->SetMaxSwapsPending(1); |
| 1455 client.SetAutomaticSwapAck(false); | 1471 client.SetAutomaticSwapAck(false); |
| 1456 | 1472 |
| 1457 // SetNeedsCommit should begin the frame on the next BeginImplFrame. | 1473 // SetNeedsCommit should begin the frame on the next BeginImplFrame. |
| 1458 client.Reset(); | 1474 client.Reset(); |
| 1459 scheduler->SetNeedsCommit(); | 1475 scheduler->SetNeedsCommit(); |
| 1460 EXPECT_FALSE(client.needs_begin_frame()); | 1476 EXPECT_FALSE(client.needs_begin_frames()); |
| 1461 EXPECT_NO_ACTION(client); | 1477 EXPECT_NO_ACTION(client); |
| 1462 client.Reset(); | 1478 client.Reset(); |
| 1463 | 1479 |
| 1464 // Trigger the first BeginImplFrame and BeginMainFrame | 1480 // Trigger the first BeginImplFrame and BeginMainFrame |
| 1465 client.task_runner().RunPendingTasks(); // Run posted BeginFrame. | 1481 client.task_runner().RunPendingTasks(); // Run posted BeginFrame. |
| 1466 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 1482 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
| 1467 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); | 1483 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); |
| 1468 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1484 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 1469 EXPECT_FALSE(client.needs_begin_frame()); | 1485 EXPECT_FALSE(client.needs_begin_frames()); |
| 1470 client.Reset(); | 1486 client.Reset(); |
| 1471 | 1487 |
| 1472 // NotifyReadyToCommit should trigger the pending commit and draw. | 1488 // NotifyReadyToCommit should trigger the pending commit and draw. |
| 1473 scheduler->NotifyBeginMainFrameStarted(); | 1489 scheduler->NotifyBeginMainFrameStarted(); |
| 1474 scheduler->NotifyReadyToCommit(); | 1490 scheduler->NotifyReadyToCommit(); |
| 1475 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); | 1491 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); |
| 1476 EXPECT_FALSE(client.needs_begin_frame()); | 1492 EXPECT_FALSE(client.needs_begin_frames()); |
| 1477 client.Reset(); | 1493 client.Reset(); |
| 1478 | 1494 |
| 1479 // Swapping will put us into a swap throttled state. | 1495 // Swapping will put us into a swap throttled state. |
| 1480 client.task_runner().RunPendingTasks(); // Run posted deadline. | 1496 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 1481 EXPECT_ACTION("ScheduledActionAnimate", client, 0, 2); | 1497 EXPECT_ACTION("ScheduledActionAnimate", client, 0, 2); |
| 1482 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 1, 2); | 1498 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 1, 2); |
| 1483 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 1499 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
| 1484 EXPECT_FALSE(client.needs_begin_frame()); | 1500 EXPECT_FALSE(client.needs_begin_frames()); |
| 1485 client.Reset(); | 1501 client.Reset(); |
| 1486 | 1502 |
| 1487 // While swap throttled, BeginFrames should trigger BeginImplFrames, | 1503 // While swap throttled, BeginFrames should trigger BeginImplFrames, |
| 1488 // but not a BeginMainFrame or draw. | 1504 // but not a BeginMainFrame or draw. |
| 1489 scheduler->SetNeedsCommit(); | 1505 scheduler->SetNeedsCommit(); |
| 1490 client.task_runner().RunPendingTasks(); // Run posted BeginFrame. | 1506 client.task_runner().RunPendingTasks(); // Run posted BeginFrame. |
| 1491 EXPECT_ACTION("WillBeginImplFrame", client, 0, 1); | 1507 EXPECT_ACTION("WillBeginImplFrame", client, 0, 1); |
| 1492 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1508 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 1493 EXPECT_FALSE(client.needs_begin_frame()); | 1509 EXPECT_FALSE(client.needs_begin_frames()); |
| 1494 client.Reset(); | 1510 client.Reset(); |
| 1495 | 1511 |
| 1496 // Take us out of a swap throttled state. | 1512 // Take us out of a swap throttled state. |
| 1497 scheduler->DidSwapBuffersComplete(); | 1513 scheduler->DidSwapBuffersComplete(); |
| 1498 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 0, 1); | 1514 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 0, 1); |
| 1499 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1515 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 1500 EXPECT_FALSE(client.needs_begin_frame()); | 1516 EXPECT_FALSE(client.needs_begin_frames()); |
| 1501 client.Reset(); | 1517 client.Reset(); |
| 1502 | 1518 |
| 1503 // BeginImplFrame deadline should draw. | 1519 // BeginImplFrame deadline should draw. |
| 1504 scheduler->SetNeedsRedraw(); | 1520 scheduler->SetNeedsRedraw(); |
| 1505 client.task_runner().RunPendingTasks(); // Run posted deadline. | 1521 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 1506 EXPECT_ACTION("ScheduledActionAnimate", client, 0, 2); | 1522 EXPECT_ACTION("ScheduledActionAnimate", client, 0, 2); |
| 1507 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 1, 2); | 1523 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 1, 2); |
| 1508 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 1524 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
| 1509 EXPECT_FALSE(client.needs_begin_frame()); | 1525 EXPECT_FALSE(client.needs_begin_frames()); |
| 1510 client.Reset(); | 1526 client.Reset(); |
| 1511 } | 1527 } |
| 1512 | 1528 |
| 1513 TEST(SchedulerTest, SyntheticBeginFrames_SwapThrottled) { | 1529 TEST(SchedulerTest, SyntheticBeginFrames_SwapThrottled) { |
| 1514 bool begin_frame_scheduling_enabled = false; | 1530 bool begin_frame_scheduling_enabled = false; |
| 1515 bool throttle_frame_production = true; | 1531 bool throttle_frame_production = true; |
| 1516 BeginFramesNotFromClient_SwapThrottled(begin_frame_scheduling_enabled, | 1532 BeginFramesNotFromClient_SwapThrottled(begin_frame_scheduling_enabled, |
| 1517 throttle_frame_production); | 1533 throttle_frame_production); |
| 1518 } | 1534 } |
| 1519 | 1535 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1555 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings); | 1571 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings); |
| 1556 scheduler->SetCanStart(); | 1572 scheduler->SetCanStart(); |
| 1557 scheduler->SetVisible(true); | 1573 scheduler->SetVisible(true); |
| 1558 scheduler->SetCanDraw(true); | 1574 scheduler->SetCanDraw(true); |
| 1559 | 1575 |
| 1560 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); | 1576 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); |
| 1561 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | 1577 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
| 1562 // SetNeedsCommit should begin the frame. | 1578 // SetNeedsCommit should begin the frame. |
| 1563 client.Reset(); | 1579 client.Reset(); |
| 1564 scheduler->SetNeedsCommit(); | 1580 scheduler->SetNeedsCommit(); |
| 1565 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); | 1581 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames", client); |
| 1566 | 1582 |
| 1567 client.Reset(); | 1583 client.Reset(); |
| 1568 client.AdvanceFrame(); | 1584 client.AdvanceFrame(); |
| 1569 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 1585 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
| 1570 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); | 1586 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); |
| 1571 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1587 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 1572 | 1588 |
| 1573 client.Reset(); | 1589 client.Reset(); |
| 1574 scheduler->DidLoseOutputSurface(); | 1590 scheduler->DidLoseOutputSurface(); |
| 1575 // Do nothing when impl frame is in deadine pending state. | 1591 // Do nothing when impl frame is in deadine pending state. |
| (...skipping 18 matching lines...) Expand all Loading... |
| 1594 scheduler->SetCanStart(); | 1610 scheduler->SetCanStart(); |
| 1595 scheduler->SetVisible(true); | 1611 scheduler->SetVisible(true); |
| 1596 scheduler->SetCanDraw(true); | 1612 scheduler->SetCanDraw(true); |
| 1597 | 1613 |
| 1598 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); | 1614 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); |
| 1599 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | 1615 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
| 1600 | 1616 |
| 1601 // SetNeedsCommit should begin the frame. | 1617 // SetNeedsCommit should begin the frame. |
| 1602 client.Reset(); | 1618 client.Reset(); |
| 1603 scheduler->SetNeedsCommit(); | 1619 scheduler->SetNeedsCommit(); |
| 1604 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); | 1620 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames", client); |
| 1605 | 1621 |
| 1606 client.Reset(); | 1622 client.Reset(); |
| 1607 client.AdvanceFrame(); | 1623 client.AdvanceFrame(); |
| 1608 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 1624 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
| 1609 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); | 1625 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); |
| 1610 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1626 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 1611 | 1627 |
| 1612 client.Reset(); | 1628 client.Reset(); |
| 1613 scheduler->DidLoseOutputSurface(); | 1629 scheduler->DidLoseOutputSurface(); |
| 1614 // Do nothing when impl frame is in deadine pending state. | 1630 // Do nothing when impl frame is in deadine pending state. |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1661 scheduler->SetCanStart(); | 1677 scheduler->SetCanStart(); |
| 1662 scheduler->SetVisible(true); | 1678 scheduler->SetVisible(true); |
| 1663 scheduler->SetCanDraw(true); | 1679 scheduler->SetCanDraw(true); |
| 1664 | 1680 |
| 1665 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); | 1681 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); |
| 1666 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | 1682 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
| 1667 | 1683 |
| 1668 // SetNeedsCommit should begin the frame. | 1684 // SetNeedsCommit should begin the frame. |
| 1669 client.Reset(); | 1685 client.Reset(); |
| 1670 scheduler->SetNeedsCommit(); | 1686 scheduler->SetNeedsCommit(); |
| 1671 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); | 1687 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames", client); |
| 1672 | 1688 |
| 1673 client.Reset(); | 1689 client.Reset(); |
| 1674 client.AdvanceFrame(); | 1690 client.AdvanceFrame(); |
| 1675 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 1691 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
| 1676 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); | 1692 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); |
| 1677 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1693 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 1678 | 1694 |
| 1679 client.Reset(); | 1695 client.Reset(); |
| 1680 scheduler->NotifyBeginMainFrameStarted(); | 1696 scheduler->NotifyBeginMainFrameStarted(); |
| 1681 scheduler->NotifyReadyToCommit(); | 1697 scheduler->NotifyReadyToCommit(); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 1709 SchedulerSettings scheduler_settings; | 1725 SchedulerSettings scheduler_settings; |
| 1710 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings); | 1726 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings); |
| 1711 scheduler->SetCanStart(); | 1727 scheduler->SetCanStart(); |
| 1712 scheduler->SetVisible(true); | 1728 scheduler->SetVisible(true); |
| 1713 scheduler->SetCanDraw(true); | 1729 scheduler->SetCanDraw(true); |
| 1714 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | 1730 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
| 1715 | 1731 |
| 1716 client.Reset(); | 1732 client.Reset(); |
| 1717 scheduler->SetNeedsManageTiles(); | 1733 scheduler->SetNeedsManageTiles(); |
| 1718 scheduler->SetNeedsRedraw(); | 1734 scheduler->SetNeedsRedraw(); |
| 1719 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); | 1735 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames", client); |
| 1720 EXPECT_TRUE(client.needs_begin_frame()); | 1736 EXPECT_TRUE(client.needs_begin_frames()); |
| 1721 | 1737 |
| 1722 client.Reset(); | 1738 client.Reset(); |
| 1723 client.AdvanceFrame(); | 1739 client.AdvanceFrame(); |
| 1724 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 1740 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
| 1725 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); | 1741 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); |
| 1726 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1742 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 1727 | 1743 |
| 1728 client.Reset(); | 1744 client.Reset(); |
| 1729 scheduler->DidLoseOutputSurface(); | 1745 scheduler->DidLoseOutputSurface(); |
| 1730 EXPECT_NO_ACTION(client); | 1746 EXPECT_NO_ACTION(client); |
| 1731 | 1747 |
| 1732 client.Reset(); | 1748 client.Reset(); |
| 1733 client.task_runner().RunPendingTasks(); // Run posted deadline. | 1749 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 1734 EXPECT_ACTION("ScheduledActionManageTiles", client, 0, 2); | 1750 EXPECT_ACTION("ScheduledActionManageTiles", client, 0, 2); |
| 1735 EXPECT_ACTION("ScheduledActionBeginOutputSurfaceCreation", client, 1, 2); | 1751 EXPECT_ACTION("ScheduledActionBeginOutputSurfaceCreation", client, 1, 2); |
| 1736 } | 1752 } |
| 1737 | 1753 |
| 1738 TEST(SchedulerTest, DidLoseOutputSurfaceAfterBeginRetroFramePosted) { | 1754 TEST(SchedulerTest, DidLoseOutputSurfaceAfterBeginRetroFramePosted) { |
| 1739 FakeSchedulerClient client; | 1755 FakeSchedulerClient client; |
| 1740 SchedulerSettings scheduler_settings; | 1756 SchedulerSettings scheduler_settings; |
| 1741 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings); | 1757 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings); |
| 1742 scheduler->SetCanStart(); | 1758 scheduler->SetCanStart(); |
| 1743 scheduler->SetVisible(true); | 1759 scheduler->SetVisible(true); |
| 1744 scheduler->SetCanDraw(true); | 1760 scheduler->SetCanDraw(true); |
| 1745 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | 1761 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
| 1746 | 1762 |
| 1747 // SetNeedsCommit should begin the frame on the next BeginImplFrame. | 1763 // SetNeedsCommit should begin the frame on the next BeginImplFrame. |
| 1748 client.Reset(); | 1764 client.Reset(); |
| 1749 scheduler->SetNeedsCommit(); | 1765 scheduler->SetNeedsCommit(); |
| 1750 EXPECT_TRUE(client.needs_begin_frame()); | 1766 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames", client); |
| 1751 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); | 1767 EXPECT_TRUE(client.needs_begin_frames()); |
| 1752 | 1768 |
| 1753 // Create a BeginFrame with a long deadline to avoid race conditions. | 1769 // Create a BeginFrame with a long deadline to avoid race conditions. |
| 1754 // This is the first BeginFrame, which will be handled immediately. | 1770 // This is the first BeginFrame, which will be handled immediately. |
| 1755 client.Reset(); | 1771 client.Reset(); |
| 1756 BeginFrameArgs args = CreateBeginFrameArgsForTesting(client.now_src()); | 1772 BeginFrameArgs args = CreateBeginFrameArgsForTesting(client.now_src()); |
| 1757 args.deadline += base::TimeDelta::FromHours(1); | 1773 args.deadline += base::TimeDelta::FromHours(1); |
| 1758 scheduler->BeginFrame(args); | 1774 client.GetBeginFrameSource()->TestSendBeginFrame(args); |
| 1759 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 1775 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
| 1760 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); | 1776 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); |
| 1761 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1777 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 1762 EXPECT_TRUE(client.needs_begin_frame()); | 1778 EXPECT_TRUE(client.needs_begin_frames()); |
| 1763 | 1779 |
| 1764 // Queue BeginFrames while we are still handling the previous BeginFrame. | 1780 // Queue BeginFrames while we are still handling the previous BeginFrame. |
| 1765 args.frame_time += base::TimeDelta::FromSeconds(1); | 1781 args.frame_time += base::TimeDelta::FromSeconds(1); |
| 1766 scheduler->BeginFrame(args); | 1782 client.GetBeginFrameSource()->TestSendBeginFrame(args); |
| 1767 args.frame_time += base::TimeDelta::FromSeconds(1); | 1783 args.frame_time += base::TimeDelta::FromSeconds(1); |
| 1768 scheduler->BeginFrame(args); | 1784 client.GetBeginFrameSource()->TestSendBeginFrame(args); |
| 1769 | 1785 |
| 1770 // If we don't swap on the deadline, we wait for the next BeginImplFrame. | 1786 // If we don't swap on the deadline, we wait for the next BeginImplFrame. |
| 1771 client.Reset(); | 1787 client.Reset(); |
| 1772 client.task_runner().RunPendingTasks(); // Run posted deadline. | 1788 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 1773 EXPECT_NO_ACTION(client); | 1789 EXPECT_NO_ACTION(client); |
| 1774 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 1790 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
| 1775 EXPECT_TRUE(client.needs_begin_frame()); | 1791 EXPECT_TRUE(client.needs_begin_frames()); |
| 1776 | 1792 |
| 1777 // NotifyReadyToCommit should trigger the commit. | 1793 // NotifyReadyToCommit should trigger the commit. |
| 1778 client.Reset(); | 1794 client.Reset(); |
| 1779 scheduler->NotifyBeginMainFrameStarted(); | 1795 scheduler->NotifyBeginMainFrameStarted(); |
| 1780 scheduler->NotifyReadyToCommit(); | 1796 scheduler->NotifyReadyToCommit(); |
| 1781 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); | 1797 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); |
| 1782 EXPECT_TRUE(client.needs_begin_frame()); | 1798 EXPECT_TRUE(client.needs_begin_frames()); |
| 1783 | 1799 |
| 1784 client.Reset(); | 1800 client.Reset(); |
| 1785 EXPECT_FALSE(scheduler->IsBeginRetroFrameArgsEmpty()); | 1801 EXPECT_FALSE(scheduler->IsBeginRetroFrameArgsEmpty()); |
| 1786 scheduler->DidLoseOutputSurface(); | 1802 scheduler->DidLoseOutputSurface(); |
| 1787 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); | 1803 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); |
| 1788 EXPECT_TRUE(client.needs_begin_frame()); | 1804 EXPECT_TRUE(client.needs_begin_frames()); |
| 1789 EXPECT_TRUE(scheduler->IsBeginRetroFrameArgsEmpty()); | 1805 EXPECT_TRUE(scheduler->IsBeginRetroFrameArgsEmpty()); |
| 1790 | 1806 |
| 1791 // Posted BeginRetroFrame is aborted. | 1807 // Posted BeginRetroFrame is aborted. |
| 1792 client.Reset(); | 1808 client.Reset(); |
| 1793 client.task_runner().RunPendingTasks(); | 1809 client.task_runner().RunPendingTasks(); |
| 1794 EXPECT_NO_ACTION(client); | 1810 EXPECT_NO_ACTION(client); |
| 1795 } | 1811 } |
| 1796 | 1812 |
| 1797 TEST(SchedulerTest, DidLoseOutputSurfaceDuringBeginRetroFrameRunning) { | 1813 TEST(SchedulerTest, DidLoseOutputSurfaceDuringBeginRetroFrameRunning) { |
| 1798 FakeSchedulerClient client; | 1814 FakeSchedulerClient client; |
| 1799 SchedulerSettings scheduler_settings; | 1815 SchedulerSettings scheduler_settings; |
| 1800 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings); | 1816 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings); |
| 1801 scheduler->SetCanStart(); | 1817 scheduler->SetCanStart(); |
| 1802 scheduler->SetVisible(true); | 1818 scheduler->SetVisible(true); |
| 1803 scheduler->SetCanDraw(true); | 1819 scheduler->SetCanDraw(true); |
| 1804 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | 1820 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
| 1805 | 1821 |
| 1806 // SetNeedsCommit should begin the frame on the next BeginImplFrame. | 1822 // SetNeedsCommit should begin the frame on the next BeginImplFrame. |
| 1807 client.Reset(); | 1823 client.Reset(); |
| 1808 scheduler->SetNeedsCommit(); | 1824 scheduler->SetNeedsCommit(); |
| 1809 EXPECT_TRUE(client.needs_begin_frame()); | 1825 EXPECT_TRUE(client.needs_begin_frames()); |
| 1810 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); | 1826 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames", client); |
| 1811 | 1827 |
| 1812 // Create a BeginFrame with a long deadline to avoid race conditions. | 1828 // Create a BeginFrame with a long deadline to avoid race conditions. |
| 1813 // This is the first BeginFrame, which will be handled immediately. | 1829 // This is the first BeginFrame, which will be handled immediately. |
| 1814 client.Reset(); | 1830 client.Reset(); |
| 1815 BeginFrameArgs args = CreateBeginFrameArgsForTesting(client.now_src()); | 1831 BeginFrameArgs args = CreateBeginFrameArgsForTesting(client.now_src()); |
| 1816 args.deadline += base::TimeDelta::FromHours(1); | 1832 args.deadline += base::TimeDelta::FromHours(1); |
| 1817 scheduler->BeginFrame(args); | 1833 client.GetBeginFrameSource()->TestSendBeginFrame(args); |
| 1818 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 1834 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
| 1819 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); | 1835 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); |
| 1820 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1836 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 1821 EXPECT_TRUE(client.needs_begin_frame()); | 1837 EXPECT_TRUE(client.needs_begin_frames()); |
| 1822 | 1838 |
| 1823 // Queue BeginFrames while we are still handling the previous BeginFrame. | 1839 // Queue BeginFrames while we are still handling the previous BeginFrame. |
| 1824 args.frame_time += base::TimeDelta::FromSeconds(1); | 1840 args.frame_time += base::TimeDelta::FromSeconds(1); |
| 1825 scheduler->BeginFrame(args); | 1841 client.GetBeginFrameSource()->TestSendBeginFrame(args); |
| 1826 args.frame_time += base::TimeDelta::FromSeconds(1); | 1842 args.frame_time += base::TimeDelta::FromSeconds(1); |
| 1827 scheduler->BeginFrame(args); | 1843 client.GetBeginFrameSource()->TestSendBeginFrame(args); |
| 1828 | 1844 |
| 1829 // If we don't swap on the deadline, we wait for the next BeginImplFrame. | 1845 // If we don't swap on the deadline, we wait for the next BeginImplFrame. |
| 1830 client.Reset(); | 1846 client.Reset(); |
| 1831 client.task_runner().RunPendingTasks(); // Run posted deadline. | 1847 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 1832 EXPECT_NO_ACTION(client); | 1848 EXPECT_NO_ACTION(client); |
| 1833 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 1849 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
| 1834 EXPECT_TRUE(client.needs_begin_frame()); | 1850 EXPECT_TRUE(client.needs_begin_frames()); |
| 1835 | 1851 |
| 1836 // NotifyReadyToCommit should trigger the commit. | 1852 // NotifyReadyToCommit should trigger the commit. |
| 1837 client.Reset(); | 1853 client.Reset(); |
| 1838 scheduler->NotifyBeginMainFrameStarted(); | 1854 scheduler->NotifyBeginMainFrameStarted(); |
| 1839 scheduler->NotifyReadyToCommit(); | 1855 scheduler->NotifyReadyToCommit(); |
| 1840 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); | 1856 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); |
| 1841 EXPECT_TRUE(client.needs_begin_frame()); | 1857 EXPECT_TRUE(client.needs_begin_frames()); |
| 1842 | 1858 |
| 1843 // BeginImplFrame should prepare the draw. | 1859 // BeginImplFrame should prepare the draw. |
| 1844 client.Reset(); | 1860 client.Reset(); |
| 1845 client.task_runner().RunPendingTasks(); // Run posted BeginRetroFrame. | 1861 client.task_runner().RunPendingTasks(); // Run posted BeginRetroFrame. |
| 1846 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 1862 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
| 1847 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); | 1863 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); |
| 1848 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1864 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 1849 EXPECT_TRUE(client.needs_begin_frame()); | 1865 EXPECT_TRUE(client.needs_begin_frames()); |
| 1850 | 1866 |
| 1851 client.Reset(); | 1867 client.Reset(); |
| 1852 EXPECT_FALSE(scheduler->IsBeginRetroFrameArgsEmpty()); | 1868 EXPECT_FALSE(scheduler->IsBeginRetroFrameArgsEmpty()); |
| 1853 scheduler->DidLoseOutputSurface(); | 1869 scheduler->DidLoseOutputSurface(); |
| 1854 EXPECT_NO_ACTION(client); | 1870 EXPECT_NO_ACTION(client); |
| 1855 EXPECT_TRUE(scheduler->IsBeginRetroFrameArgsEmpty()); | 1871 EXPECT_TRUE(scheduler->IsBeginRetroFrameArgsEmpty()); |
| 1856 | 1872 |
| 1857 // BeginImplFrame deadline should abort drawing. | 1873 // BeginImplFrame deadline should abort drawing. |
| 1858 client.Reset(); | 1874 client.Reset(); |
| 1859 client.task_runner().RunPendingTasks(); // Run posted deadline. | 1875 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 1860 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); | 1876 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); |
| 1861 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 1877 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
| 1862 EXPECT_TRUE(client.needs_begin_frame()); | 1878 EXPECT_TRUE(client.needs_begin_frames()); |
| 1863 | 1879 |
| 1864 // No more BeginRetroFrame because BeginRetroFrame queue is cleared. | 1880 // No more BeginRetroFrame because BeginRetroFrame queue is cleared. |
| 1865 client.Reset(); | 1881 client.Reset(); |
| 1866 client.task_runner().RunPendingTasks(); | 1882 client.task_runner().RunPendingTasks(); |
| 1867 EXPECT_NO_ACTION(client); | 1883 EXPECT_NO_ACTION(client); |
| 1868 } | 1884 } |
| 1869 | 1885 |
| 1870 TEST(SchedulerTest, | 1886 TEST(SchedulerTest, |
| 1871 StopBeginFrameAfterDidLoseOutputSurfaceWithSyntheticBeginFrameSource) { | 1887 StopBeginFrameAfterDidLoseOutputSurfaceWithSyntheticBeginFrameSource) { |
| 1872 FakeSchedulerClient client; | 1888 FakeSchedulerClient client; |
| 1873 SchedulerSettings scheduler_settings; | 1889 SchedulerSettings scheduler_settings; |
| 1874 scheduler_settings.begin_frame_scheduling_enabled = false; | 1890 scheduler_settings.begin_frame_scheduling_enabled = false; |
| 1875 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings); | 1891 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings); |
| 1876 scheduler->SetCanStart(); | 1892 scheduler->SetCanStart(); |
| 1877 scheduler->SetVisible(true); | 1893 scheduler->SetVisible(true); |
| 1878 scheduler->SetCanDraw(true); | 1894 scheduler->SetCanDraw(true); |
| 1879 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | 1895 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
| 1880 | 1896 |
| 1881 // SetNeedsCommit should begin the frame on the next BeginImplFrame. | 1897 // SetNeedsCommit should begin the frame on the next BeginImplFrame. |
| 1882 client.Reset(); | 1898 client.Reset(); |
| 1883 EXPECT_FALSE(scheduler->IsSyntheticBeginFrameSourceActive()); | 1899 EXPECT_FALSE(scheduler->frame_source().NeedsBeginFrames()); |
| 1884 scheduler->SetNeedsCommit(); | 1900 scheduler->SetNeedsCommit(); |
| 1885 EXPECT_TRUE(scheduler->IsSyntheticBeginFrameSourceActive()); | 1901 EXPECT_TRUE(scheduler->frame_source().NeedsBeginFrames()); |
| 1886 | 1902 |
| 1887 client.Reset(); | 1903 client.Reset(); |
| 1888 client.task_runner().RunPendingTasks(); // Run posted Tick. | 1904 client.task_runner().RunPendingTasks(); // Run posted Tick. |
| 1889 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 1905 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
| 1890 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); | 1906 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); |
| 1891 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1907 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 1892 EXPECT_TRUE(scheduler->IsSyntheticBeginFrameSourceActive()); | 1908 EXPECT_TRUE(scheduler->frame_source().NeedsBeginFrames()); |
| 1893 | 1909 |
| 1894 // NotifyReadyToCommit should trigger the commit. | 1910 // NotifyReadyToCommit should trigger the commit. |
| 1895 client.Reset(); | 1911 client.Reset(); |
| 1896 scheduler->NotifyBeginMainFrameStarted(); | 1912 scheduler->NotifyBeginMainFrameStarted(); |
| 1897 scheduler->NotifyReadyToCommit(); | 1913 scheduler->NotifyReadyToCommit(); |
| 1898 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); | 1914 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); |
| 1899 EXPECT_TRUE(scheduler->IsSyntheticBeginFrameSourceActive()); | 1915 EXPECT_TRUE(scheduler->frame_source().NeedsBeginFrames()); |
| 1900 | 1916 |
| 1901 client.Reset(); | 1917 client.Reset(); |
| 1902 scheduler->DidLoseOutputSurface(); | 1918 scheduler->DidLoseOutputSurface(); |
| 1903 EXPECT_EQ(0, client.num_actions_()); | 1919 EXPECT_EQ(0, client.num_actions_()); |
| 1904 EXPECT_FALSE(scheduler->IsSyntheticBeginFrameSourceActive()); | 1920 EXPECT_FALSE(scheduler->frame_source().NeedsBeginFrames()); |
| 1905 | 1921 |
| 1906 client.Reset(); | 1922 client.Reset(); |
| 1907 client.task_runner().RunPendingTasks(); // Run posted deadline. | 1923 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 1908 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); | 1924 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); |
| 1909 EXPECT_FALSE(scheduler->IsSyntheticBeginFrameSourceActive()); | 1925 EXPECT_FALSE(scheduler->frame_source().NeedsBeginFrames()); |
| 1910 } | 1926 } |
| 1911 | 1927 |
| 1912 } // namespace | 1928 } // namespace |
| 1913 } // namespace cc | 1929 } // namespace cc |
| OLD | NEW |