 Chromium Code Reviews
 Chromium Code Reviews Issue 1133673004:
  cc: Heuristic for Renderer latency recovery  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@master
    
  
    Issue 1133673004:
  cc: Heuristic for Renderer latency recovery  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@master| OLD | NEW | 
|---|---|
| 1 // Copyright 2011 The Chromium Authors. All rights reserved. | 1 // Copyright 2011 The Chromium Authors. All rights reserved. | 
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be | 
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. | 
| 4 | 4 | 
| 5 #include "cc/scheduler/scheduler.h" | 5 #include "cc/scheduler/scheduler.h" | 
| 6 | 6 | 
| 7 #include <string> | 7 #include <string> | 
| 8 #include <vector> | 8 #include <vector> | 
| 9 | 9 | 
| 10 #include "base/logging.h" | 10 #include "base/logging.h" | 
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 141 PushAction("ScheduledActionPrepareTiles"); | 141 PushAction("ScheduledActionPrepareTiles"); | 
| 142 } | 142 } | 
| 143 void ScheduledActionInvalidateOutputSurface() override { | 143 void ScheduledActionInvalidateOutputSurface() override { | 
| 144 actions_.push_back("ScheduledActionInvalidateOutputSurface"); | 144 actions_.push_back("ScheduledActionInvalidateOutputSurface"); | 
| 145 states_.push_back(scheduler_->AsValue()); | 145 states_.push_back(scheduler_->AsValue()); | 
| 146 } | 146 } | 
| 147 void DidAnticipatedDrawTimeChange(base::TimeTicks) override { | 147 void DidAnticipatedDrawTimeChange(base::TimeTicks) override { | 
| 148 if (log_anticipated_draw_time_change_) | 148 if (log_anticipated_draw_time_change_) | 
| 149 PushAction("DidAnticipatedDrawTimeChange"); | 149 PushAction("DidAnticipatedDrawTimeChange"); | 
| 150 } | 150 } | 
| 151 base::TimeDelta DrawDurationEstimate() override { return base::TimeDelta(); } | 151 | 
| 152 // Use really long estimations by default so we don't inadvertently | |
| 153 // test latency recovery logic unless a test explicitly wants to. | |
| 154 base::TimeDelta DrawDurationEstimate() override { | |
| 155 return base::TimeDelta::FromHours(1); | |
| 156 } | |
| 152 base::TimeDelta BeginMainFrameToCommitDurationEstimate() override { | 157 base::TimeDelta BeginMainFrameToCommitDurationEstimate() override { | 
| 153 return base::TimeDelta(); | 158 return base::TimeDelta::FromHours(1); | 
| 154 } | 159 } | 
| 155 base::TimeDelta CommitToActivateDurationEstimate() override { | 160 base::TimeDelta CommitToActivateDurationEstimate() override { | 
| 156 return base::TimeDelta(); | 161 return base::TimeDelta::FromHours(1); | 
| 157 } | 162 } | 
| 158 | 163 | 
| 159 void DidBeginImplFrameDeadline() override {} | 164 void DidBeginImplFrameDeadline() override {} | 
| 160 | 165 | 
| 161 void SendBeginFramesToChildren(const BeginFrameArgs& args) override { | 166 void SendBeginFramesToChildren(const BeginFrameArgs& args) override { | 
| 162 begin_frame_args_sent_to_children_ = args; | 167 begin_frame_args_sent_to_children_ = args; | 
| 163 } | 168 } | 
| 164 | 169 | 
| 165 void SendBeginMainFrameNotExpectedSoon() override { | 170 void SendBeginMainFrameNotExpectedSoon() override { | 
| 166 PushAction("SendBeginMainFrameNotExpectedSoon"); | 171 PushAction("SendBeginMainFrameNotExpectedSoon"); | 
| (...skipping 13 matching lines...) Expand all Loading... | |
| 180 return begin_frame_args_sent_to_children_; | 185 return begin_frame_args_sent_to_children_; | 
| 181 } | 186 } | 
| 182 | 187 | 
| 183 void PushAction(const char* description) { | 188 void PushAction(const char* description) { | 
| 184 actions_.push_back(description); | 189 actions_.push_back(description); | 
| 185 states_.push_back(scheduler_->AsValue()); | 190 states_.push_back(scheduler_->AsValue()); | 
| 186 } | 191 } | 
| 187 | 192 | 
| 188 protected: | 193 protected: | 
| 189 bool ImplFrameDeadlinePendingCallback(bool state) { | 194 bool ImplFrameDeadlinePendingCallback(bool state) { | 
| 190 return scheduler_->BeginImplFrameDeadlinePending() == state; | 195 return scheduler_->BeginImplFrameDeadlinePendingForTest() == state; | 
| 191 } | 196 } | 
| 192 | 197 | 
| 193 bool draw_will_happen_; | 198 bool draw_will_happen_; | 
| 194 bool swap_will_happen_if_draw_happens_; | 199 bool swap_will_happen_if_draw_happens_; | 
| 195 bool automatic_swap_ack_; | 200 bool automatic_swap_ack_; | 
| 196 int num_draws_; | 201 int num_draws_; | 
| 197 bool log_anticipated_draw_time_change_; | 202 bool log_anticipated_draw_time_change_; | 
| 198 BeginFrameArgs begin_frame_args_sent_to_children_; | 203 BeginFrameArgs begin_frame_args_sent_to_children_; | 
| 199 base::TimeTicks posted_begin_impl_frame_deadline_; | 204 base::TimeTicks posted_begin_impl_frame_deadline_; | 
| 200 std::vector<const char*> actions_; | 205 std::vector<const char*> actions_; | 
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 321 scheduler_->SetVisible(true); | 326 scheduler_->SetVisible(true); | 
| 322 scheduler_->SetCanDraw(true); | 327 scheduler_->SetCanDraw(true); | 
| 323 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client_); | 328 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client_); | 
| 324 | 329 | 
| 325 client_->Reset(); | 330 client_->Reset(); | 
| 326 | 331 | 
| 327 // We don't see anything happening until the first impl frame. | 332 // We don't see anything happening until the first impl frame. | 
| 328 scheduler_->DidCreateAndInitializeOutputSurface(); | 333 scheduler_->DidCreateAndInitializeOutputSurface(); | 
| 329 scheduler_->SetNeedsCommit(); | 334 scheduler_->SetNeedsCommit(); | 
| 330 EXPECT_TRUE(client_->needs_begin_frames()); | 335 EXPECT_TRUE(client_->needs_begin_frames()); | 
| 331 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | 336 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePendingForTest()); | 
| 332 client_->Reset(); | 337 client_->Reset(); | 
| 333 | 338 | 
| 334 { | 339 { | 
| 335 SCOPED_TRACE("Do first frame to commit after initialize."); | 340 SCOPED_TRACE("Do first frame to commit after initialize."); | 
| 336 AdvanceFrame(); | 341 AdvanceFrame(); | 
| 337 | 342 | 
| 338 scheduler_->NotifyBeginMainFrameStarted(); | 343 scheduler_->NotifyBeginMainFrameStarted(); | 
| 339 scheduler_->NotifyReadyToCommitThenActivateIfNeeded(); | 344 scheduler_->NotifyReadyToCommitThenActivateIfNeeded(); | 
| 340 | 345 | 
| 341 EXPECT_FALSE(scheduler_->CommitPending()); | 346 EXPECT_FALSE(scheduler_->CommitPending()); | 
| 342 | 347 | 
| 343 if (scheduler_settings_.using_synchronous_renderer_compositor) { | 348 if (scheduler_settings_.using_synchronous_renderer_compositor) { | 
| 344 scheduler_->SetNeedsRedraw(); | 349 scheduler_->SetNeedsRedraw(); | 
| 345 scheduler_->OnDrawForOutputSurface(); | 350 scheduler_->OnDrawForOutputSurface(); | 
| 346 } else { | 351 } else { | 
| 347 // Run the posted deadline task. | 352 // Run the posted deadline task. | 
| 348 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 353 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePendingForTest()); | 
| 349 task_runner_->RunTasksWhile(client_->ImplFrameDeadlinePending(true)); | 354 task_runner_->RunTasksWhile(client_->ImplFrameDeadlinePending(true)); | 
| 350 } | 355 } | 
| 351 | 356 | 
| 352 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | 357 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePendingForTest()); | 
| 353 } | 358 } | 
| 354 | 359 | 
| 355 client_->Reset(); | 360 client_->Reset(); | 
| 356 | 361 | 
| 357 { | 362 { | 
| 358 SCOPED_TRACE( | 363 SCOPED_TRACE( | 
| 359 "Run second frame so Scheduler calls SetNeedsBeginFrame(false)."); | 364 "Run second frame so Scheduler calls SetNeedsBeginFrame(false)."); | 
| 360 AdvanceFrame(); | 365 AdvanceFrame(); | 
| 361 | 366 | 
| 362 if (!scheduler_settings_.using_synchronous_renderer_compositor) { | 367 if (!scheduler_settings_.using_synchronous_renderer_compositor) { | 
| 363 // Run the posted deadline task. | 368 // Run the posted deadline task. | 
| 364 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 369 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePendingForTest()); | 
| 365 task_runner_->RunTasksWhile(client_->ImplFrameDeadlinePending(true)); | 370 task_runner_->RunTasksWhile(client_->ImplFrameDeadlinePending(true)); | 
| 366 } | 371 } | 
| 367 | 372 | 
| 368 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | 373 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePendingForTest()); | 
| 369 } | 374 } | 
| 370 | 375 | 
| 371 EXPECT_FALSE(client_->needs_begin_frames()); | 376 EXPECT_FALSE(client_->needs_begin_frames()); | 
| 372 client_->Reset(); | 377 client_->Reset(); | 
| 373 } | 378 } | 
| 374 | 379 | 
| 375 // As this function contains EXPECT macros, to allow debugging it should be | 380 // As this function contains EXPECT macros, to allow debugging it should be | 
| 376 // called inside EXPECT_SCOPED like so; | 381 // called inside EXPECT_SCOPED like so; | 
| 377 // EXPECT_SCOPED(client.AdvanceFrame()); | 382 // EXPECT_SCOPED(client.AdvanceFrame()); | 
| 378 void AdvanceFrame() { | 383 void AdvanceFrame() { | 
| 379 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug.scheduler.frames"), | 384 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug.scheduler.frames"), | 
| 380 "FakeSchedulerClient::AdvanceFrame"); | 385 "FakeSchedulerClient::AdvanceFrame"); | 
| 381 // Consume any previous deadline first, if no deadline is currently | 386 // Consume any previous deadline first, if no deadline is currently | 
| 382 // pending, ImplFrameDeadlinePending will return false straight away and we | 387 // pending, ImplFrameDeadlinePending will return false straight away and we | 
| 383 // will run no tasks. | 388 // will run no tasks. | 
| 384 task_runner_->RunTasksWhile(client_->ImplFrameDeadlinePending(true)); | 389 task_runner_->RunTasksWhile(client_->ImplFrameDeadlinePending(true)); | 
| 385 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | 390 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePendingForTest()); | 
| 386 | 391 | 
| 387 // Send the next BeginFrame message if using an external source, otherwise | 392 // Send the next BeginFrame message if using an external source, otherwise | 
| 388 // it will be already in the task queue. | 393 // it will be already in the task queue. | 
| 389 if (scheduler_->settings().use_external_begin_frame_source && | 394 if (scheduler_->settings().use_external_begin_frame_source && | 
| 390 scheduler_->FrameProductionThrottled()) { | 395 scheduler_->FrameProductionThrottled()) { | 
| 391 EXPECT_TRUE(client_->needs_begin_frames()); | 396 EXPECT_TRUE(client_->needs_begin_frames()); | 
| 392 SendNextBeginFrame(); | 397 SendNextBeginFrame(); | 
| 393 } | 398 } | 
| 394 | 399 | 
| 395 if (!scheduler_->settings().using_synchronous_renderer_compositor) { | 400 if (!scheduler_->settings().using_synchronous_renderer_compositor) { | 
| 396 // Then run tasks until new deadline is scheduled. | 401 // Then run tasks until new deadline is scheduled. | 
| 397 EXPECT_TRUE(task_runner_->RunTasksWhile( | 402 EXPECT_TRUE(task_runner_->RunTasksWhile( | 
| 398 client_->ImplFrameDeadlinePending(false))); | 403 client_->ImplFrameDeadlinePending(false))); | 
| 399 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 404 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePendingForTest()); | 
| 400 } | 405 } | 
| 401 } | 406 } | 
| 402 | 407 | 
| 403 void SendNextBeginFrame() { | 408 void SendNextBeginFrame() { | 
| 404 DCHECK(scheduler_->settings().use_external_begin_frame_source); | 409 DCHECK(scheduler_->settings().use_external_begin_frame_source); | 
| 405 // Creep the time forward so that any BeginFrameArgs is not equal to the | 410 // Creep the time forward so that any BeginFrameArgs is not equal to the | 
| 406 // last one otherwise we violate the BeginFrameSource contract. | 411 // last one otherwise we violate the BeginFrameSource contract. | 
| 407 now_src_->AdvanceNow(BeginFrameArgs::DefaultInterval()); | 412 now_src_->AdvanceNow(BeginFrameArgs::DefaultInterval()); | 
| 408 fake_external_begin_frame_source_->TestOnBeginFrame( | 413 fake_external_begin_frame_source_->TestOnBeginFrame( | 
| 409 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, now_src())); | 414 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, now_src())); | 
| 410 } | 415 } | 
| 411 | 416 | 
| 412 FakeExternalBeginFrameSource* fake_external_begin_frame_source() const { | 417 FakeExternalBeginFrameSource* fake_external_begin_frame_source() const { | 
| 413 return fake_external_begin_frame_source_; | 418 return fake_external_begin_frame_source_; | 
| 414 } | 419 } | 
| 415 | 420 | 
| 416 void MainFrameInHighLatencyMode( | 421 void MainFrameInHighLatencyMode( | 
| 417 int64 begin_main_frame_to_commit_estimate_in_ms, | 422 int64 begin_main_frame_to_commit_estimate_in_ms, | 
| 418 int64 commit_to_activate_estimate_in_ms, | 423 int64 commit_to_activate_estimate_in_ms, | 
| 419 bool impl_latency_takes_priority, | 424 bool impl_latency_takes_priority, | 
| 420 bool should_send_begin_main_frame); | 425 bool should_send_begin_main_frame); | 
| 426 void ImplFrameInHighLatencyMode( | |
| 427 int64 begin_main_frame_to_commit_estimate_in_ms, | |
| 428 int64 commit_to_activate_estimate_in_ms, | |
| 429 bool swap_ack_before_deadline, | |
| 430 bool should_begin_impl_frame_in_high_latency); | |
| 421 void BeginFramesNotFromClient(bool use_external_begin_frame_source, | 431 void BeginFramesNotFromClient(bool use_external_begin_frame_source, | 
| 422 bool throttle_frame_production); | 432 bool throttle_frame_production); | 
| 423 void BeginFramesNotFromClient_SwapThrottled( | 433 void BeginFramesNotFromClient_SwapThrottled( | 
| 424 bool use_external_begin_frame_source, | 434 bool use_external_begin_frame_source, | 
| 425 bool throttle_frame_production); | 435 bool throttle_frame_production); | 
| 426 void DidLoseOutputSurfaceAfterBeginFrameStartedWithHighLatency( | 436 void DidLoseOutputSurfaceAfterBeginFrameStartedWithHighLatency( | 
| 427 bool impl_side_painting); | 437 bool impl_side_painting); | 
| 428 void DidLoseOutputSurfaceAfterReadyToCommit(bool impl_side_painting); | 438 void DidLoseOutputSurfaceAfterReadyToCommit(bool impl_side_painting); | 
| 429 | 439 | 
| 430 scoped_refptr<TestNowSource> now_src_; | 440 scoped_refptr<TestNowSource> now_src_; | 
| (...skipping 24 matching lines...) Expand all Loading... | |
| 455 EXPECT_FALSE(client_->begin_frame_is_sent_to_children()); | 465 EXPECT_FALSE(client_->begin_frame_is_sent_to_children()); | 
| 456 scheduler_->SetNeedsCommit(); | 466 scheduler_->SetNeedsCommit(); | 
| 457 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client_); | 467 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client_); | 
| 458 EXPECT_TRUE(client_->needs_begin_frames()); | 468 EXPECT_TRUE(client_->needs_begin_frames()); | 
| 459 | 469 | 
| 460 scheduler_->SetChildrenNeedBeginFrames(true); | 470 scheduler_->SetChildrenNeedBeginFrames(true); | 
| 461 | 471 | 
| 462 client_->Reset(); | 472 client_->Reset(); | 
| 463 EXPECT_SCOPED(AdvanceFrame()); | 473 EXPECT_SCOPED(AdvanceFrame()); | 
| 464 EXPECT_TRUE(client_->begin_frame_is_sent_to_children()); | 474 EXPECT_TRUE(client_->begin_frame_is_sent_to_children()); | 
| 465 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 475 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePendingForTest()); | 
| 466 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); | 476 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); | 
| 467 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); | 477 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); | 
| 468 EXPECT_TRUE(client_->needs_begin_frames()); | 478 EXPECT_TRUE(client_->needs_begin_frames()); | 
| 469 } | 479 } | 
| 470 | 480 | 
| 471 TEST_F(SchedulerTest, SendBeginFramesToChildrenWithoutCommit) { | 481 TEST_F(SchedulerTest, SendBeginFramesToChildrenWithoutCommit) { | 
| 472 scheduler_settings_.use_external_begin_frame_source = true; | 482 scheduler_settings_.use_external_begin_frame_source = true; | 
| 473 SetUpScheduler(true); | 483 SetUpScheduler(true); | 
| 474 | 484 | 
| 475 EXPECT_FALSE(client_->needs_begin_frames()); | 485 EXPECT_FALSE(client_->needs_begin_frames()); | 
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 511 TEST_F(SchedulerTest, VideoNeedsBeginFrames) { | 521 TEST_F(SchedulerTest, VideoNeedsBeginFrames) { | 
| 512 scheduler_settings_.use_external_begin_frame_source = true; | 522 scheduler_settings_.use_external_begin_frame_source = true; | 
| 513 SetUpScheduler(true); | 523 SetUpScheduler(true); | 
| 514 | 524 | 
| 515 scheduler_->SetVideoNeedsBeginFrames(true); | 525 scheduler_->SetVideoNeedsBeginFrames(true); | 
| 516 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client_); | 526 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client_); | 
| 517 EXPECT_TRUE(client_->needs_begin_frames()); | 527 EXPECT_TRUE(client_->needs_begin_frames()); | 
| 518 | 528 | 
| 519 client_->Reset(); | 529 client_->Reset(); | 
| 520 EXPECT_SCOPED(AdvanceFrame()); | 530 EXPECT_SCOPED(AdvanceFrame()); | 
| 521 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 531 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePendingForTest()); | 
| 522 // WillBeginImplFrame is responsible for sending BeginFrames to video. | 532 // WillBeginImplFrame is responsible for sending BeginFrames to video. | 
| 523 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client_); | 533 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client_); | 
| 524 | 534 | 
| 525 client_->Reset(); | 535 client_->Reset(); | 
| 526 EXPECT_SCOPED(AdvanceFrame()); | 536 EXPECT_SCOPED(AdvanceFrame()); | 
| 527 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 537 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePendingForTest()); | 
| 528 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client_); | 538 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client_); | 
| 529 | 539 | 
| 530 client_->Reset(); | 540 client_->Reset(); | 
| 531 scheduler_->SetVideoNeedsBeginFrames(false); | 541 scheduler_->SetVideoNeedsBeginFrames(false); | 
| 532 EXPECT_NO_ACTION(client_); | 542 EXPECT_NO_ACTION(client_); | 
| 533 | 543 | 
| 534 client_->Reset(); | 544 client_->Reset(); | 
| 535 task_runner_->RunTasksWhile(client_->ImplFrameDeadlinePending(true)); | 545 task_runner_->RunTasksWhile(client_->ImplFrameDeadlinePending(true)); | 
| 536 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | 546 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePendingForTest()); | 
| 537 EXPECT_ACTION("SetNeedsBeginFrames(false)", client_, 0, 2); | 547 EXPECT_ACTION("SetNeedsBeginFrames(false)", client_, 0, 2); | 
| 538 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 1, 2); | 548 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 1, 2); | 
| 539 EXPECT_FALSE(client_->needs_begin_frames()); | 549 EXPECT_FALSE(client_->needs_begin_frames()); | 
| 540 } | 550 } | 
| 541 | 551 | 
| 542 TEST_F(SchedulerTest, RequestCommit) { | 552 TEST_F(SchedulerTest, RequestCommit) { | 
| 543 scheduler_settings_.use_external_begin_frame_source = true; | 553 scheduler_settings_.use_external_begin_frame_source = true; | 
| 544 SetUpScheduler(true); | 554 SetUpScheduler(true); | 
| 545 | 555 | 
| 546 // SetNeedsCommit should begin the frame on the next BeginImplFrame. | 556 // SetNeedsCommit should begin the frame on the next BeginImplFrame. | 
| 547 scheduler_->SetNeedsCommit(); | 557 scheduler_->SetNeedsCommit(); | 
| 548 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client_); | 558 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client_); | 
| 549 client_->Reset(); | 559 client_->Reset(); | 
| 550 | 560 | 
| 551 EXPECT_SCOPED(AdvanceFrame()); | 561 EXPECT_SCOPED(AdvanceFrame()); | 
| 552 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); | 562 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); | 
| 553 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); | 563 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); | 
| 554 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 564 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePendingForTest()); | 
| 555 EXPECT_TRUE(client_->needs_begin_frames()); | 565 EXPECT_TRUE(client_->needs_begin_frames()); | 
| 556 client_->Reset(); | 566 client_->Reset(); | 
| 557 | 567 | 
| 558 // If we don't swap on the deadline, we wait for the next BeginFrame. | 568 // If we don't swap on the deadline, we wait for the next BeginFrame. | 
| 559 task_runner().RunPendingTasks(); // Run posted deadline. | 569 task_runner().RunPendingTasks(); // Run posted deadline. | 
| 560 EXPECT_NO_ACTION(client_); | 570 EXPECT_NO_ACTION(client_); | 
| 561 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | 571 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePendingForTest()); | 
| 562 EXPECT_TRUE(client_->needs_begin_frames()); | 572 EXPECT_TRUE(client_->needs_begin_frames()); | 
| 563 client_->Reset(); | 573 client_->Reset(); | 
| 564 | 574 | 
| 565 // NotifyReadyToCommit should trigger the commit. | 575 // NotifyReadyToCommit should trigger the commit. | 
| 566 scheduler_->NotifyBeginMainFrameStarted(); | 576 scheduler_->NotifyBeginMainFrameStarted(); | 
| 567 scheduler_->NotifyReadyToCommit(); | 577 scheduler_->NotifyReadyToCommit(); | 
| 568 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_); | 578 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_); | 
| 569 EXPECT_TRUE(client_->needs_begin_frames()); | 579 EXPECT_TRUE(client_->needs_begin_frames()); | 
| 570 client_->Reset(); | 580 client_->Reset(); | 
| 571 | 581 | 
| 572 // BeginImplFrame should prepare the draw. | 582 // BeginImplFrame should prepare the draw. | 
| 573 EXPECT_SCOPED(AdvanceFrame()); | 583 EXPECT_SCOPED(AdvanceFrame()); | 
| 574 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); | 584 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); | 
| 575 EXPECT_ACTION("ScheduledActionAnimate", client_, 1, 2); | 585 EXPECT_ACTION("ScheduledActionAnimate", client_, 1, 2); | 
| 576 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 586 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePendingForTest()); | 
| 577 EXPECT_TRUE(client_->needs_begin_frames()); | 587 EXPECT_TRUE(client_->needs_begin_frames()); | 
| 578 client_->Reset(); | 588 client_->Reset(); | 
| 579 | 589 | 
| 580 // BeginImplFrame deadline should draw. | 590 // BeginImplFrame deadline should draw. | 
| 581 task_runner().RunPendingTasks(); // Run posted deadline. | 591 task_runner().RunPendingTasks(); // Run posted deadline. | 
| 582 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 0, 1); | 592 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 0, 1); | 
| 583 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | 593 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePendingForTest()); | 
| 584 EXPECT_TRUE(client_->needs_begin_frames()); | 594 EXPECT_TRUE(client_->needs_begin_frames()); | 
| 585 client_->Reset(); | 595 client_->Reset(); | 
| 586 | 596 | 
| 587 // The following BeginImplFrame deadline should SetNeedsBeginFrame(false) | 597 // The following BeginImplFrame deadline should SetNeedsBeginFrame(false) | 
| 588 // to avoid excessive toggles. | 598 // to avoid excessive toggles. | 
| 589 EXPECT_SCOPED(AdvanceFrame()); | 599 EXPECT_SCOPED(AdvanceFrame()); | 
| 590 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client_); | 600 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client_); | 
| 591 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 601 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePendingForTest()); | 
| 592 client_->Reset(); | 602 client_->Reset(); | 
| 593 | 603 | 
| 594 task_runner().RunPendingTasks(); // Run posted deadline. | 604 task_runner().RunPendingTasks(); // Run posted deadline. | 
| 595 EXPECT_ACTION("SetNeedsBeginFrames(false)", client_, 0, 2); | 605 EXPECT_ACTION("SetNeedsBeginFrames(false)", client_, 0, 2); | 
| 596 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 1, 2); | 606 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 1, 2); | 
| 597 client_->Reset(); | 607 client_->Reset(); | 
| 598 } | 608 } | 
| 599 | 609 | 
| 600 TEST_F(SchedulerTest, RequestCommitAfterSetDeferCommit) { | 610 TEST_F(SchedulerTest, RequestCommitAfterSetDeferCommit) { | 
| 601 scheduler_settings_.use_external_begin_frame_source = true; | 611 scheduler_settings_.use_external_begin_frame_source = true; | 
| (...skipping 12 matching lines...) Expand all Loading... | |
| 614 | 624 | 
| 615 client_->Reset(); | 625 client_->Reset(); | 
| 616 scheduler_->SetDeferCommits(false); | 626 scheduler_->SetDeferCommits(false); | 
| 617 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client_); | 627 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client_); | 
| 618 | 628 | 
| 619 // Start new BeginMainFrame after defer commit is off. | 629 // Start new BeginMainFrame after defer commit is off. | 
| 620 client_->Reset(); | 630 client_->Reset(); | 
| 621 EXPECT_SCOPED(AdvanceFrame()); | 631 EXPECT_SCOPED(AdvanceFrame()); | 
| 622 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); | 632 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); | 
| 623 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); | 633 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); | 
| 624 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 634 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePendingForTest()); | 
| 625 } | 635 } | 
| 626 | 636 | 
| 627 TEST_F(SchedulerTest, DeferCommitWithRedraw) { | 637 TEST_F(SchedulerTest, DeferCommitWithRedraw) { | 
| 628 scheduler_settings_.use_external_begin_frame_source = true; | 638 scheduler_settings_.use_external_begin_frame_source = true; | 
| 629 SetUpScheduler(true); | 639 SetUpScheduler(true); | 
| 630 | 640 | 
| 631 scheduler_->SetDeferCommits(true); | 641 scheduler_->SetDeferCommits(true); | 
| 632 | 642 | 
| 633 scheduler_->SetNeedsCommit(); | 643 scheduler_->SetNeedsCommit(); | 
| 634 EXPECT_NO_ACTION(client_); | 644 EXPECT_NO_ACTION(client_); | 
| 635 | 645 | 
| 636 // The SetNeedsRedraw will override the SetDeferCommits(true), to allow a | 646 // The SetNeedsRedraw will override the SetDeferCommits(true), to allow a | 
| 637 // begin frame to be needed. | 647 // begin frame to be needed. | 
| 638 client_->Reset(); | 648 client_->Reset(); | 
| 639 scheduler_->SetNeedsRedraw(); | 649 scheduler_->SetNeedsRedraw(); | 
| 640 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client_); | 650 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client_); | 
| 641 | 651 | 
| 642 client_->Reset(); | 652 client_->Reset(); | 
| 643 AdvanceFrame(); | 653 AdvanceFrame(); | 
| 644 // BeginMainFrame is not sent during the defer commit is on. | 654 // BeginMainFrame is not sent during the defer commit is on. | 
| 645 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); | 655 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); | 
| 646 EXPECT_ACTION("ScheduledActionAnimate", client_, 1, 2); | 656 EXPECT_ACTION("ScheduledActionAnimate", client_, 1, 2); | 
| 647 | 657 | 
| 648 client_->Reset(); | 658 client_->Reset(); | 
| 649 task_runner().RunPendingTasks(); // Run posted deadline. | 659 task_runner().RunPendingTasks(); // Run posted deadline. | 
| 650 EXPECT_SINGLE_ACTION("ScheduledActionDrawAndSwapIfPossible", client_); | 660 EXPECT_SINGLE_ACTION("ScheduledActionDrawAndSwapIfPossible", client_); | 
| 651 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | 661 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePendingForTest()); | 
| 652 EXPECT_TRUE(client_->needs_begin_frames()); | 662 EXPECT_TRUE(client_->needs_begin_frames()); | 
| 653 | 663 | 
| 654 client_->Reset(); | 664 client_->Reset(); | 
| 655 AdvanceFrame(); | 665 AdvanceFrame(); | 
| 656 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client_); | 666 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client_); | 
| 657 } | 667 } | 
| 658 | 668 | 
| 659 TEST_F(SchedulerTest, RequestCommitAfterBeginMainFrameSent) { | 669 TEST_F(SchedulerTest, RequestCommitAfterBeginMainFrameSent) { | 
| 660 scheduler_settings_.use_external_begin_frame_source = true; | 670 scheduler_settings_.use_external_begin_frame_source = true; | 
| 661 SetUpScheduler(true); | 671 SetUpScheduler(true); | 
| 662 | 672 | 
| 663 // SetNeedsCommit should begin the frame. | 673 // SetNeedsCommit should begin the frame. | 
| 664 scheduler_->SetNeedsCommit(); | 674 scheduler_->SetNeedsCommit(); | 
| 665 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client_); | 675 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client_); | 
| 666 | 676 | 
| 667 client_->Reset(); | 677 client_->Reset(); | 
| 668 EXPECT_SCOPED(AdvanceFrame()); | 678 EXPECT_SCOPED(AdvanceFrame()); | 
| 669 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); | 679 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); | 
| 670 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); | 680 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); | 
| 671 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 681 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePendingForTest()); | 
| 672 | 682 | 
| 673 EXPECT_TRUE(client_->needs_begin_frames()); | 683 EXPECT_TRUE(client_->needs_begin_frames()); | 
| 674 client_->Reset(); | 684 client_->Reset(); | 
| 675 | 685 | 
| 676 // Now SetNeedsCommit again. Calling here means we need a second commit. | 686 // Now SetNeedsCommit again. Calling here means we need a second commit. | 
| 677 scheduler_->SetNeedsCommit(); | 687 scheduler_->SetNeedsCommit(); | 
| 678 EXPECT_EQ(client_->num_actions_(), 0); | 688 EXPECT_EQ(client_->num_actions_(), 0); | 
| 679 client_->Reset(); | 689 client_->Reset(); | 
| 680 | 690 | 
| 681 // Finish the first commit. | 691 // Finish the first commit. | 
| 682 scheduler_->NotifyBeginMainFrameStarted(); | 692 scheduler_->NotifyBeginMainFrameStarted(); | 
| 683 scheduler_->NotifyReadyToCommit(); | 693 scheduler_->NotifyReadyToCommit(); | 
| 684 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_); | 694 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_); | 
| 685 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 695 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePendingForTest()); | 
| 686 client_->Reset(); | 696 client_->Reset(); | 
| 687 task_runner().RunPendingTasks(); // Run posted deadline. | 697 task_runner().RunPendingTasks(); // Run posted deadline. | 
| 688 EXPECT_ACTION("ScheduledActionAnimate", client_, 0, 2); | 698 EXPECT_ACTION("ScheduledActionAnimate", client_, 0, 2); | 
| 689 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 1, 2); | 699 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 1, 2); | 
| 690 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | 700 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePendingForTest()); | 
| 691 | 701 | 
| 692 // Because we just swapped, the Scheduler should also request the next | 702 // Because we just swapped, the Scheduler should also request the next | 
| 693 // BeginImplFrame from the OutputSurface. | 703 // BeginImplFrame from the OutputSurface. | 
| 694 EXPECT_TRUE(client_->needs_begin_frames()); | 704 EXPECT_TRUE(client_->needs_begin_frames()); | 
| 695 client_->Reset(); | 705 client_->Reset(); | 
| 696 // Since another commit is needed, the next BeginImplFrame should initiate | 706 // Since another commit is needed, the next BeginImplFrame should initiate | 
| 697 // the second commit. | 707 // the second commit. | 
| 698 EXPECT_SCOPED(AdvanceFrame()); | 708 EXPECT_SCOPED(AdvanceFrame()); | 
| 699 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); | 709 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); | 
| 700 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); | 710 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); | 
| 701 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 711 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePendingForTest()); | 
| 702 client_->Reset(); | 712 client_->Reset(); | 
| 703 | 713 | 
| 704 // Finishing the commit before the deadline should post a new deadline task | 714 // Finishing the commit before the deadline should post a new deadline task | 
| 705 // to trigger the deadline early. | 715 // to trigger the deadline early. | 
| 706 scheduler_->NotifyBeginMainFrameStarted(); | 716 scheduler_->NotifyBeginMainFrameStarted(); | 
| 707 scheduler_->NotifyReadyToCommit(); | 717 scheduler_->NotifyReadyToCommit(); | 
| 708 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_); | 718 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_); | 
| 709 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 719 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePendingForTest()); | 
| 710 client_->Reset(); | 720 client_->Reset(); | 
| 711 task_runner().RunPendingTasks(); // Run posted deadline. | 721 task_runner().RunPendingTasks(); // Run posted deadline. | 
| 712 EXPECT_ACTION("ScheduledActionAnimate", client_, 0, 2); | 722 EXPECT_ACTION("ScheduledActionAnimate", client_, 0, 2); | 
| 713 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 1, 2); | 723 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 1, 2); | 
| 714 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | 724 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePendingForTest()); | 
| 715 EXPECT_TRUE(client_->needs_begin_frames()); | 725 EXPECT_TRUE(client_->needs_begin_frames()); | 
| 716 client_->Reset(); | 726 client_->Reset(); | 
| 717 | 727 | 
| 718 // On the next BeginImplFrame, verify we go back to a quiescent state and | 728 // On the next BeginImplFrame, verify we go back to a quiescent state and | 
| 719 // no longer request BeginImplFrames. | 729 // no longer request BeginImplFrames. | 
| 720 EXPECT_SCOPED(AdvanceFrame()); | 730 EXPECT_SCOPED(AdvanceFrame()); | 
| 721 task_runner().RunPendingTasks(); // Run posted deadline. | 731 task_runner().RunPendingTasks(); // Run posted deadline. | 
| 722 EXPECT_FALSE(client_->needs_begin_frames()); | 732 EXPECT_FALSE(client_->needs_begin_frames()); | 
| 723 client_->Reset(); | 733 client_->Reset(); | 
| 724 } | 734 } | 
| (...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1008 EXPECT_EQ(0, client->num_draws()); | 1018 EXPECT_EQ(0, client->num_draws()); | 
| 1009 EXPECT_FALSE(client->HasAction("ScheduledActionPrepareTiles")); | 1019 EXPECT_FALSE(client->HasAction("ScheduledActionPrepareTiles")); | 
| 1010 EXPECT_FALSE(client->HasAction("ScheduledActionDrawAndSwapIfPossible")); | 1020 EXPECT_FALSE(client->HasAction("ScheduledActionDrawAndSwapIfPossible")); | 
| 1011 | 1021 | 
| 1012 // We have no immediate actions to perform, so the BeginImplFrame should post | 1022 // We have no immediate actions to perform, so the BeginImplFrame should post | 
| 1013 // the deadline task. | 1023 // the deadline task. | 
| 1014 client->Reset(); | 1024 client->Reset(); | 
| 1015 EXPECT_SCOPED(AdvanceFrame()); | 1025 EXPECT_SCOPED(AdvanceFrame()); | 
| 1016 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 1026 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 
| 1017 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); | 1027 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); | 
| 1018 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 1028 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePendingForTest()); | 
| 1019 | 1029 | 
| 1020 // On the deadline, he actions should have occured in the right order. | 1030 // On the deadline, he actions should have occured in the right order. | 
| 1021 client->Reset(); | 1031 client->Reset(); | 
| 1022 task_runner().RunPendingTasks(); // Run posted deadline. | 1032 task_runner().RunPendingTasks(); // Run posted deadline. | 
| 1023 EXPECT_EQ(1, client->num_draws()); | 1033 EXPECT_EQ(1, client->num_draws()); | 
| 1024 EXPECT_TRUE(client->HasAction("ScheduledActionDrawAndSwapIfPossible")); | 1034 EXPECT_TRUE(client->HasAction("ScheduledActionDrawAndSwapIfPossible")); | 
| 1025 EXPECT_TRUE(client->HasAction("ScheduledActionPrepareTiles")); | 1035 EXPECT_TRUE(client->HasAction("ScheduledActionPrepareTiles")); | 
| 1026 EXPECT_LT(client->ActionIndex("ScheduledActionDrawAndSwapIfPossible"), | 1036 EXPECT_LT(client->ActionIndex("ScheduledActionDrawAndSwapIfPossible"), | 
| 1027 client->ActionIndex("ScheduledActionPrepareTiles")); | 1037 client->ActionIndex("ScheduledActionPrepareTiles")); | 
| 1028 EXPECT_FALSE(scheduler_->RedrawPending()); | 1038 EXPECT_FALSE(scheduler_->RedrawPending()); | 
| 1029 EXPECT_FALSE(scheduler_->PrepareTilesPending()); | 1039 EXPECT_FALSE(scheduler_->PrepareTilesPending()); | 
| 1030 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | 1040 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePendingForTest()); | 
| 1031 | 1041 | 
| 1032 // Request a draw. We don't need a PrepareTiles yet. | 1042 // Request a draw. We don't need a PrepareTiles yet. | 
| 1033 client->Reset(); | 1043 client->Reset(); | 
| 1034 scheduler_->SetNeedsRedraw(); | 1044 scheduler_->SetNeedsRedraw(); | 
| 1035 EXPECT_TRUE(scheduler_->RedrawPending()); | 1045 EXPECT_TRUE(scheduler_->RedrawPending()); | 
| 1036 EXPECT_FALSE(scheduler_->PrepareTilesPending()); | 1046 EXPECT_FALSE(scheduler_->PrepareTilesPending()); | 
| 1037 EXPECT_TRUE(client->needs_begin_frames()); | 1047 EXPECT_TRUE(client->needs_begin_frames()); | 
| 1038 EXPECT_EQ(0, client->num_draws()); | 1048 EXPECT_EQ(0, client->num_draws()); | 
| 1039 | 1049 | 
| 1040 // We have no immediate actions to perform, so the BeginImplFrame should post | 1050 // We have no immediate actions to perform, so the BeginImplFrame should post | 
| 1041 // the deadline task. | 1051 // the deadline task. | 
| 1042 client->Reset(); | 1052 client->Reset(); | 
| 1043 EXPECT_SCOPED(AdvanceFrame()); | 1053 EXPECT_SCOPED(AdvanceFrame()); | 
| 1044 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 1054 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 
| 1045 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); | 1055 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); | 
| 1046 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 1056 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePendingForTest()); | 
| 1047 | 1057 | 
| 1048 // Draw. The draw will trigger SetNeedsPrepareTiles, and | 1058 // Draw. The draw will trigger SetNeedsPrepareTiles, and | 
| 1049 // then the PrepareTiles action will be triggered after the Draw. | 1059 // then the PrepareTiles action will be triggered after the Draw. | 
| 1050 // Afterwards, neither a draw nor PrepareTiles are pending. | 1060 // Afterwards, neither a draw nor PrepareTiles are pending. | 
| 1051 client->Reset(); | 1061 client->Reset(); | 
| 1052 task_runner().RunPendingTasks(); // Run posted deadline. | 1062 task_runner().RunPendingTasks(); // Run posted deadline. | 
| 1053 EXPECT_EQ(1, client->num_draws()); | 1063 EXPECT_EQ(1, client->num_draws()); | 
| 1054 EXPECT_TRUE(client->HasAction("ScheduledActionDrawAndSwapIfPossible")); | 1064 EXPECT_TRUE(client->HasAction("ScheduledActionDrawAndSwapIfPossible")); | 
| 1055 EXPECT_TRUE(client->HasAction("ScheduledActionPrepareTiles")); | 1065 EXPECT_TRUE(client->HasAction("ScheduledActionPrepareTiles")); | 
| 1056 EXPECT_LT(client->ActionIndex("ScheduledActionDrawAndSwapIfPossible"), | 1066 EXPECT_LT(client->ActionIndex("ScheduledActionDrawAndSwapIfPossible"), | 
| 1057 client->ActionIndex("ScheduledActionPrepareTiles")); | 1067 client->ActionIndex("ScheduledActionPrepareTiles")); | 
| 1058 EXPECT_FALSE(scheduler_->RedrawPending()); | 1068 EXPECT_FALSE(scheduler_->RedrawPending()); | 
| 1059 EXPECT_FALSE(scheduler_->PrepareTilesPending()); | 1069 EXPECT_FALSE(scheduler_->PrepareTilesPending()); | 
| 1060 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | 1070 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePendingForTest()); | 
| 1061 | 1071 | 
| 1062 // We need a BeginImplFrame where we don't swap to go idle. | 1072 // We need a BeginImplFrame where we don't swap to go idle. | 
| 1063 client->Reset(); | 1073 client->Reset(); | 
| 1064 EXPECT_SCOPED(AdvanceFrame()); | 1074 EXPECT_SCOPED(AdvanceFrame()); | 
| 1065 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); | 1075 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); | 
| 1066 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 1076 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePendingForTest()); | 
| 1067 client->Reset(); | 1077 client->Reset(); | 
| 1068 task_runner().RunPendingTasks(); // Run posted deadline. | 1078 task_runner().RunPendingTasks(); // Run posted deadline. | 
| 1069 EXPECT_ACTION("SetNeedsBeginFrames(false)", client_, 0, 2); | 1079 EXPECT_ACTION("SetNeedsBeginFrames(false)", client_, 0, 2); | 
| 1070 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 1, 2); | 1080 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 1, 2); | 
| 1071 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | 1081 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePendingForTest()); | 
| 1072 EXPECT_EQ(0, client->num_draws()); | 1082 EXPECT_EQ(0, client->num_draws()); | 
| 1073 | 1083 | 
| 1074 // Now trigger a PrepareTiles outside of a draw. We will then need | 1084 // Now trigger a PrepareTiles outside of a draw. We will then need | 
| 1075 // a begin-frame for the PrepareTiles, but we don't need a draw. | 1085 // a begin-frame for the PrepareTiles, but we don't need a draw. | 
| 1076 client->Reset(); | 1086 client->Reset(); | 
| 1077 EXPECT_FALSE(client->needs_begin_frames()); | 1087 EXPECT_FALSE(client->needs_begin_frames()); | 
| 1078 scheduler_->SetNeedsPrepareTiles(); | 1088 scheduler_->SetNeedsPrepareTiles(); | 
| 1079 EXPECT_TRUE(client->needs_begin_frames()); | 1089 EXPECT_TRUE(client->needs_begin_frames()); | 
| 1080 EXPECT_TRUE(scheduler_->PrepareTilesPending()); | 1090 EXPECT_TRUE(scheduler_->PrepareTilesPending()); | 
| 1081 EXPECT_FALSE(scheduler_->RedrawPending()); | 1091 EXPECT_FALSE(scheduler_->RedrawPending()); | 
| 1082 | 1092 | 
| 1083 // BeginImplFrame. There will be no draw, only PrepareTiles. | 1093 // BeginImplFrame. There will be no draw, only PrepareTiles. | 
| 1084 client->Reset(); | 1094 client->Reset(); | 
| 1085 EXPECT_SCOPED(AdvanceFrame()); | 1095 EXPECT_SCOPED(AdvanceFrame()); | 
| 1086 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); | 1096 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); | 
| 1087 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 1097 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePendingForTest()); | 
| 1088 client->Reset(); | 1098 client->Reset(); | 
| 1089 task_runner().RunPendingTasks(); // Run posted deadline. | 1099 task_runner().RunPendingTasks(); // Run posted deadline. | 
| 1090 EXPECT_EQ(0, client->num_draws()); | 1100 EXPECT_EQ(0, client->num_draws()); | 
| 1091 EXPECT_FALSE(client->HasAction("ScheduledActionDrawAndSwapIfPossible")); | 1101 EXPECT_FALSE(client->HasAction("ScheduledActionDrawAndSwapIfPossible")); | 
| 1092 EXPECT_TRUE(client->HasAction("ScheduledActionPrepareTiles")); | 1102 EXPECT_TRUE(client->HasAction("ScheduledActionPrepareTiles")); | 
| 1093 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | 1103 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePendingForTest()); | 
| 1094 } | 1104 } | 
| 1095 | 1105 | 
| 1096 // Test that PrepareTiles only happens once per frame. If an external caller | 1106 // Test that PrepareTiles only happens once per frame. If an external caller | 
| 1097 // initiates it, then the state machine should not PrepareTiles on that frame. | 1107 // initiates it, then the state machine should not PrepareTiles on that frame. | 
| 1098 TEST_F(SchedulerTest, PrepareTilesOncePerFrame) { | 1108 TEST_F(SchedulerTest, PrepareTilesOncePerFrame) { | 
| 1099 scheduler_settings_.use_external_begin_frame_source = true; | 1109 scheduler_settings_.use_external_begin_frame_source = true; | 
| 1100 SetUpScheduler(true); | 1110 SetUpScheduler(true); | 
| 1101 | 1111 | 
| 1102 // If DidPrepareTiles during a frame, then PrepareTiles should not occur | 1112 // If DidPrepareTiles during a frame, then PrepareTiles should not occur | 
| 1103 // again. | 1113 // again. | 
| 1104 scheduler_->SetNeedsPrepareTiles(); | 1114 scheduler_->SetNeedsPrepareTiles(); | 
| 1105 scheduler_->SetNeedsRedraw(); | 1115 scheduler_->SetNeedsRedraw(); | 
| 1106 client_->Reset(); | 1116 client_->Reset(); | 
| 1107 EXPECT_SCOPED(AdvanceFrame()); | 1117 EXPECT_SCOPED(AdvanceFrame()); | 
| 1108 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); | 1118 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); | 
| 1109 EXPECT_ACTION("ScheduledActionAnimate", client_, 1, 2); | 1119 EXPECT_ACTION("ScheduledActionAnimate", client_, 1, 2); | 
| 1110 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 1120 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePendingForTest()); | 
| 1111 | 1121 | 
| 1112 EXPECT_TRUE(scheduler_->PrepareTilesPending()); | 1122 EXPECT_TRUE(scheduler_->PrepareTilesPending()); | 
| 1113 scheduler_->DidPrepareTiles(); // An explicit PrepareTiles. | 1123 scheduler_->DidPrepareTiles(); // An explicit PrepareTiles. | 
| 1114 EXPECT_FALSE(scheduler_->PrepareTilesPending()); | 1124 EXPECT_FALSE(scheduler_->PrepareTilesPending()); | 
| 1115 | 1125 | 
| 1116 client_->Reset(); | 1126 client_->Reset(); | 
| 1117 task_runner().RunPendingTasks(); // Run posted deadline. | 1127 task_runner().RunPendingTasks(); // Run posted deadline. | 
| 1118 EXPECT_EQ(1, client_->num_draws()); | 1128 EXPECT_EQ(1, client_->num_draws()); | 
| 1119 EXPECT_TRUE(client_->HasAction("ScheduledActionDrawAndSwapIfPossible")); | 1129 EXPECT_TRUE(client_->HasAction("ScheduledActionDrawAndSwapIfPossible")); | 
| 1120 EXPECT_FALSE(client_->HasAction("ScheduledActionPrepareTiles")); | 1130 EXPECT_FALSE(client_->HasAction("ScheduledActionPrepareTiles")); | 
| 1121 EXPECT_FALSE(scheduler_->RedrawPending()); | 1131 EXPECT_FALSE(scheduler_->RedrawPending()); | 
| 1122 EXPECT_FALSE(scheduler_->PrepareTilesPending()); | 1132 EXPECT_FALSE(scheduler_->PrepareTilesPending()); | 
| 1123 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | 1133 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePendingForTest()); | 
| 1124 | 1134 | 
| 1125 // Next frame without DidPrepareTiles should PrepareTiles with draw. | 1135 // Next frame without DidPrepareTiles should PrepareTiles with draw. | 
| 1126 scheduler_->SetNeedsPrepareTiles(); | 1136 scheduler_->SetNeedsPrepareTiles(); | 
| 1127 scheduler_->SetNeedsRedraw(); | 1137 scheduler_->SetNeedsRedraw(); | 
| 1128 client_->Reset(); | 1138 client_->Reset(); | 
| 1129 EXPECT_SCOPED(AdvanceFrame()); | 1139 EXPECT_SCOPED(AdvanceFrame()); | 
| 1130 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); | 1140 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); | 
| 1131 EXPECT_ACTION("ScheduledActionAnimate", client_, 1, 2); | 1141 EXPECT_ACTION("ScheduledActionAnimate", client_, 1, 2); | 
| 1132 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 1142 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePendingForTest()); | 
| 1133 | 1143 | 
| 1134 client_->Reset(); | 1144 client_->Reset(); | 
| 1135 task_runner().RunPendingTasks(); // Run posted deadline. | 1145 task_runner().RunPendingTasks(); // Run posted deadline. | 
| 1136 EXPECT_EQ(1, client_->num_draws()); | 1146 EXPECT_EQ(1, client_->num_draws()); | 
| 1137 EXPECT_TRUE(client_->HasAction("ScheduledActionDrawAndSwapIfPossible")); | 1147 EXPECT_TRUE(client_->HasAction("ScheduledActionDrawAndSwapIfPossible")); | 
| 1138 EXPECT_TRUE(client_->HasAction("ScheduledActionPrepareTiles")); | 1148 EXPECT_TRUE(client_->HasAction("ScheduledActionPrepareTiles")); | 
| 1139 EXPECT_LT(client_->ActionIndex("ScheduledActionDrawAndSwapIfPossible"), | 1149 EXPECT_LT(client_->ActionIndex("ScheduledActionDrawAndSwapIfPossible"), | 
| 1140 client_->ActionIndex("ScheduledActionPrepareTiles")); | 1150 client_->ActionIndex("ScheduledActionPrepareTiles")); | 
| 1141 EXPECT_FALSE(scheduler_->RedrawPending()); | 1151 EXPECT_FALSE(scheduler_->RedrawPending()); | 
| 1142 EXPECT_FALSE(scheduler_->PrepareTilesPending()); | 1152 EXPECT_FALSE(scheduler_->PrepareTilesPending()); | 
| 1143 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | 1153 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePendingForTest()); | 
| 1144 scheduler_->DidPrepareTiles(); // Corresponds to ScheduledActionPrepareTiles | 1154 scheduler_->DidPrepareTiles(); // Corresponds to ScheduledActionPrepareTiles | 
| 1145 | 1155 | 
| 1146 // If we get another DidPrepareTiles within the same frame, we should | 1156 // If we get another DidPrepareTiles within the same frame, we should | 
| 1147 // not PrepareTiles on the next frame. | 1157 // not PrepareTiles on the next frame. | 
| 1148 scheduler_->DidPrepareTiles(); // An explicit PrepareTiles. | 1158 scheduler_->DidPrepareTiles(); // An explicit PrepareTiles. | 
| 1149 scheduler_->SetNeedsPrepareTiles(); | 1159 scheduler_->SetNeedsPrepareTiles(); | 
| 1150 scheduler_->SetNeedsRedraw(); | 1160 scheduler_->SetNeedsRedraw(); | 
| 1151 client_->Reset(); | 1161 client_->Reset(); | 
| 1152 EXPECT_SCOPED(AdvanceFrame()); | 1162 EXPECT_SCOPED(AdvanceFrame()); | 
| 1153 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); | 1163 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); | 
| 1154 EXPECT_ACTION("ScheduledActionAnimate", client_, 1, 2); | 1164 EXPECT_ACTION("ScheduledActionAnimate", client_, 1, 2); | 
| 1155 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 1165 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePendingForTest()); | 
| 1156 | 1166 | 
| 1157 EXPECT_TRUE(scheduler_->PrepareTilesPending()); | 1167 EXPECT_TRUE(scheduler_->PrepareTilesPending()); | 
| 1158 | 1168 | 
| 1159 client_->Reset(); | 1169 client_->Reset(); | 
| 1160 task_runner().RunPendingTasks(); // Run posted deadline. | 1170 task_runner().RunPendingTasks(); // Run posted deadline. | 
| 1161 EXPECT_EQ(1, client_->num_draws()); | 1171 EXPECT_EQ(1, client_->num_draws()); | 
| 1162 EXPECT_TRUE(client_->HasAction("ScheduledActionDrawAndSwapIfPossible")); | 1172 EXPECT_TRUE(client_->HasAction("ScheduledActionDrawAndSwapIfPossible")); | 
| 1163 EXPECT_FALSE(client_->HasAction("ScheduledActionPrepareTiles")); | 1173 EXPECT_FALSE(client_->HasAction("ScheduledActionPrepareTiles")); | 
| 1164 EXPECT_FALSE(scheduler_->RedrawPending()); | 1174 EXPECT_FALSE(scheduler_->RedrawPending()); | 
| 1165 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | 1175 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePendingForTest()); | 
| 1166 | 1176 | 
| 1167 // If we get another DidPrepareTiles, we should not PrepareTiles on the next | 1177 // If we get another DidPrepareTiles, we should not PrepareTiles on the next | 
| 1168 // frame. This verifies we don't alternate calling PrepareTiles once and | 1178 // frame. This verifies we don't alternate calling PrepareTiles once and | 
| 1169 // twice. | 1179 // twice. | 
| 1170 EXPECT_TRUE(scheduler_->PrepareTilesPending()); | 1180 EXPECT_TRUE(scheduler_->PrepareTilesPending()); | 
| 1171 scheduler_->DidPrepareTiles(); // An explicit PrepareTiles. | 1181 scheduler_->DidPrepareTiles(); // An explicit PrepareTiles. | 
| 1172 EXPECT_FALSE(scheduler_->PrepareTilesPending()); | 1182 EXPECT_FALSE(scheduler_->PrepareTilesPending()); | 
| 1173 scheduler_->SetNeedsPrepareTiles(); | 1183 scheduler_->SetNeedsPrepareTiles(); | 
| 1174 scheduler_->SetNeedsRedraw(); | 1184 scheduler_->SetNeedsRedraw(); | 
| 1175 client_->Reset(); | 1185 client_->Reset(); | 
| 1176 EXPECT_SCOPED(AdvanceFrame()); | 1186 EXPECT_SCOPED(AdvanceFrame()); | 
| 1177 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); | 1187 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); | 
| 1178 EXPECT_ACTION("ScheduledActionAnimate", client_, 1, 2); | 1188 EXPECT_ACTION("ScheduledActionAnimate", client_, 1, 2); | 
| 1179 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 1189 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePendingForTest()); | 
| 1180 | 1190 | 
| 1181 EXPECT_TRUE(scheduler_->PrepareTilesPending()); | 1191 EXPECT_TRUE(scheduler_->PrepareTilesPending()); | 
| 1182 | 1192 | 
| 1183 client_->Reset(); | 1193 client_->Reset(); | 
| 1184 task_runner().RunPendingTasks(); // Run posted deadline. | 1194 task_runner().RunPendingTasks(); // Run posted deadline. | 
| 1185 EXPECT_EQ(1, client_->num_draws()); | 1195 EXPECT_EQ(1, client_->num_draws()); | 
| 1186 EXPECT_TRUE(client_->HasAction("ScheduledActionDrawAndSwapIfPossible")); | 1196 EXPECT_TRUE(client_->HasAction("ScheduledActionDrawAndSwapIfPossible")); | 
| 1187 EXPECT_FALSE(client_->HasAction("ScheduledActionPrepareTiles")); | 1197 EXPECT_FALSE(client_->HasAction("ScheduledActionPrepareTiles")); | 
| 1188 EXPECT_FALSE(scheduler_->RedrawPending()); | 1198 EXPECT_FALSE(scheduler_->RedrawPending()); | 
| 1189 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | 1199 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePendingForTest()); | 
| 1190 | 1200 | 
| 1191 // Next frame without DidPrepareTiles should PrepareTiles with draw. | 1201 // Next frame without DidPrepareTiles should PrepareTiles with draw. | 
| 1192 scheduler_->SetNeedsPrepareTiles(); | 1202 scheduler_->SetNeedsPrepareTiles(); | 
| 1193 scheduler_->SetNeedsRedraw(); | 1203 scheduler_->SetNeedsRedraw(); | 
| 1194 client_->Reset(); | 1204 client_->Reset(); | 
| 1195 EXPECT_SCOPED(AdvanceFrame()); | 1205 EXPECT_SCOPED(AdvanceFrame()); | 
| 1196 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); | 1206 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); | 
| 1197 EXPECT_ACTION("ScheduledActionAnimate", client_, 1, 2); | 1207 EXPECT_ACTION("ScheduledActionAnimate", client_, 1, 2); | 
| 1198 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 1208 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePendingForTest()); | 
| 1199 | 1209 | 
| 1200 client_->Reset(); | 1210 client_->Reset(); | 
| 1201 task_runner().RunPendingTasks(); // Run posted deadline. | 1211 task_runner().RunPendingTasks(); // Run posted deadline. | 
| 1202 EXPECT_EQ(1, client_->num_draws()); | 1212 EXPECT_EQ(1, client_->num_draws()); | 
| 1203 EXPECT_TRUE(client_->HasAction("ScheduledActionDrawAndSwapIfPossible")); | 1213 EXPECT_TRUE(client_->HasAction("ScheduledActionDrawAndSwapIfPossible")); | 
| 1204 EXPECT_TRUE(client_->HasAction("ScheduledActionPrepareTiles")); | 1214 EXPECT_TRUE(client_->HasAction("ScheduledActionPrepareTiles")); | 
| 1205 EXPECT_LT(client_->ActionIndex("ScheduledActionDrawAndSwapIfPossible"), | 1215 EXPECT_LT(client_->ActionIndex("ScheduledActionDrawAndSwapIfPossible"), | 
| 1206 client_->ActionIndex("ScheduledActionPrepareTiles")); | 1216 client_->ActionIndex("ScheduledActionPrepareTiles")); | 
| 1207 EXPECT_FALSE(scheduler_->RedrawPending()); | 1217 EXPECT_FALSE(scheduler_->RedrawPending()); | 
| 1208 EXPECT_FALSE(scheduler_->PrepareTilesPending()); | 1218 EXPECT_FALSE(scheduler_->PrepareTilesPending()); | 
| 1209 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | 1219 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePendingForTest()); | 
| 1210 scheduler_->DidPrepareTiles(); // Corresponds to ScheduledActionPrepareTiles | 1220 scheduler_->DidPrepareTiles(); // Corresponds to ScheduledActionPrepareTiles | 
| 1211 } | 1221 } | 
| 1212 | 1222 | 
| 1213 TEST_F(SchedulerTest, TriggerBeginFrameDeadlineEarly) { | 1223 TEST_F(SchedulerTest, TriggerBeginFrameDeadlineEarly) { | 
| 1214 SchedulerClientNeedsPrepareTilesInDraw* client = | 1224 SchedulerClientNeedsPrepareTilesInDraw* client = | 
| 1215 new SchedulerClientNeedsPrepareTilesInDraw; | 1225 new SchedulerClientNeedsPrepareTilesInDraw; | 
| 1216 scheduler_settings_.use_external_begin_frame_source = true; | 1226 scheduler_settings_.use_external_begin_frame_source = true; | 
| 1217 SetUpScheduler(make_scoped_ptr(client).Pass(), true); | 1227 SetUpScheduler(make_scoped_ptr(client).Pass(), true); | 
| 1218 | 1228 | 
| 1219 scheduler_->SetNeedsRedraw(); | 1229 scheduler_->SetNeedsRedraw(); | 
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1296 // the mode. | 1306 // the mode. | 
| 1297 scheduler_->SetWaitForReadyToDraw(); | 1307 scheduler_->SetWaitForReadyToDraw(); | 
| 1298 client_->Reset(); | 1308 client_->Reset(); | 
| 1299 task_runner().RunPendingTasks(); // Try to run posted deadline. | 1309 task_runner().RunPendingTasks(); // Try to run posted deadline. | 
| 1300 // There is no posted deadline. | 1310 // There is no posted deadline. | 
| 1301 EXPECT_NO_ACTION(client_); | 1311 EXPECT_NO_ACTION(client_); | 
| 1302 | 1312 | 
| 1303 // Scheduler loses output surface, and stops waiting for ready to draw signal. | 1313 // Scheduler loses output surface, and stops waiting for ready to draw signal. | 
| 1304 client_->Reset(); | 1314 client_->Reset(); | 
| 1305 scheduler_->DidLoseOutputSurface(); | 1315 scheduler_->DidLoseOutputSurface(); | 
| 1306 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 1316 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePendingForTest()); | 
| 1307 task_runner().RunPendingTasks(); // Run posted deadline. | 1317 task_runner().RunPendingTasks(); // Run posted deadline. | 
| 1308 EXPECT_ACTION("ScheduledActionBeginOutputSurfaceCreation", client_, 0, 3); | 1318 EXPECT_ACTION("ScheduledActionBeginOutputSurfaceCreation", client_, 0, 3); | 
| 1309 EXPECT_ACTION("SetNeedsBeginFrames(false)", client_, 1, 3); | 1319 EXPECT_ACTION("SetNeedsBeginFrames(false)", client_, 1, 3); | 
| 1310 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 2, 3); | 1320 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 2, 3); | 
| 1311 } | 1321 } | 
| 1312 | 1322 | 
| 1313 void SchedulerTest::MainFrameInHighLatencyMode( | 1323 void SchedulerTest::MainFrameInHighLatencyMode( | 
| 1314 int64 begin_main_frame_to_commit_estimate_in_ms, | 1324 int64 begin_main_frame_to_commit_estimate_in_ms, | 
| 1315 int64 commit_to_activate_estimate_in_ms, | 1325 int64 commit_to_activate_estimate_in_ms, | 
| 1316 bool impl_latency_takes_priority, | 1326 bool impl_latency_takes_priority, | 
| (...skipping 10 matching lines...) Expand all Loading... | |
| 1327 SetUpScheduler(make_scoped_ptr(client).Pass(), true); | 1337 SetUpScheduler(make_scoped_ptr(client).Pass(), true); | 
| 1328 | 1338 | 
| 1329 scheduler_->SetImplLatencyTakesPriority(impl_latency_takes_priority); | 1339 scheduler_->SetImplLatencyTakesPriority(impl_latency_takes_priority); | 
| 1330 | 1340 | 
| 1331 // Impl thread hits deadline before commit finishes. | 1341 // Impl thread hits deadline before commit finishes. | 
| 1332 scheduler_->SetNeedsCommit(); | 1342 scheduler_->SetNeedsCommit(); | 
| 1333 EXPECT_FALSE(scheduler_->MainThreadIsInHighLatencyMode()); | 1343 EXPECT_FALSE(scheduler_->MainThreadIsInHighLatencyMode()); | 
| 1334 EXPECT_SCOPED(AdvanceFrame()); | 1344 EXPECT_SCOPED(AdvanceFrame()); | 
| 1335 EXPECT_FALSE(scheduler_->MainThreadIsInHighLatencyMode()); | 1345 EXPECT_FALSE(scheduler_->MainThreadIsInHighLatencyMode()); | 
| 1336 task_runner().RunPendingTasks(); // Run posted deadline. | 1346 task_runner().RunPendingTasks(); // Run posted deadline. | 
| 1347 scheduler_->DidSwapBuffersComplete(); | |
| 
brianderson
2015/05/08 16:52:50
Needed to add these calls to DidSwapBuffersComplet
 | |
| 1337 EXPECT_TRUE(scheduler_->MainThreadIsInHighLatencyMode()); | 1348 EXPECT_TRUE(scheduler_->MainThreadIsInHighLatencyMode()); | 
| 1338 scheduler_->NotifyBeginMainFrameStarted(); | 1349 scheduler_->NotifyBeginMainFrameStarted(); | 
| 1339 scheduler_->NotifyReadyToCommit(); | 1350 scheduler_->NotifyReadyToCommit(); | 
| 1340 EXPECT_TRUE(scheduler_->MainThreadIsInHighLatencyMode()); | 1351 EXPECT_TRUE(scheduler_->MainThreadIsInHighLatencyMode()); | 
| 1341 EXPECT_TRUE(client->HasAction("ScheduledActionSendBeginMainFrame")); | 1352 EXPECT_TRUE(client->HasAction("ScheduledActionSendBeginMainFrame")); | 
| 1342 | 1353 | 
| 1343 client->Reset(); | 1354 client->Reset(); | 
| 1344 scheduler_->SetNeedsCommit(); | 1355 scheduler_->SetNeedsCommit(); | 
| 1345 EXPECT_TRUE(scheduler_->MainThreadIsInHighLatencyMode()); | 1356 EXPECT_TRUE(scheduler_->MainThreadIsInHighLatencyMode()); | 
| 1346 EXPECT_SCOPED(AdvanceFrame()); | 1357 EXPECT_SCOPED(AdvanceFrame()); | 
| 1347 EXPECT_TRUE(scheduler_->MainThreadIsInHighLatencyMode()); | 1358 EXPECT_TRUE(scheduler_->MainThreadIsInHighLatencyMode()); | 
| 1348 task_runner().RunPendingTasks(); // Run posted deadline. | 1359 task_runner().RunPendingTasks(); // Run posted deadline. | 
| 1360 scheduler_->DidSwapBuffersComplete(); | |
| 1349 EXPECT_EQ(scheduler_->MainThreadIsInHighLatencyMode(), | 1361 EXPECT_EQ(scheduler_->MainThreadIsInHighLatencyMode(), | 
| 1350 should_send_begin_main_frame); | 1362 should_send_begin_main_frame); | 
| 1351 EXPECT_EQ(client->HasAction("ScheduledActionSendBeginMainFrame"), | 1363 EXPECT_EQ(client->HasAction("ScheduledActionSendBeginMainFrame"), | 
| 1352 should_send_begin_main_frame); | 1364 should_send_begin_main_frame); | 
| 1353 } | 1365 } | 
| 1354 | 1366 | 
| 1355 TEST_F(SchedulerTest, | 1367 TEST_F(SchedulerTest, | 
| 1356 SkipMainFrameIfHighLatencyAndCanCommitAndActivateBeforeDeadline) { | 1368 SkipMainFrameIfHighLatencyAndCanCommitAndActivateBeforeDeadline) { | 
| 1357 // Set up client so that estimates indicate that we can commit and activate | 1369 // Set up client so that estimates indicate that we can commit and activate | 
| 1358 // before the deadline (~8ms by default). | 1370 // before the deadline (~8ms by default). | 
| (...skipping 12 matching lines...) Expand all Loading... | |
| 1371 EXPECT_SCOPED(MainFrameInHighLatencyMode(1, 10, false, true)); | 1383 EXPECT_SCOPED(MainFrameInHighLatencyMode(1, 10, false, true)); | 
| 1372 } | 1384 } | 
| 1373 | 1385 | 
| 1374 TEST_F(SchedulerTest, NotSkipMainFrameInPreferImplLatencyMode) { | 1386 TEST_F(SchedulerTest, NotSkipMainFrameInPreferImplLatencyMode) { | 
| 1375 // Set up client so that estimates indicate that we can commit and activate | 1387 // Set up client so that estimates indicate that we can commit and activate | 
| 1376 // before the deadline (~8ms by default), but also enable impl latency takes | 1388 // before the deadline (~8ms by default), but also enable impl latency takes | 
| 1377 // priority mode. | 1389 // priority mode. | 
| 1378 EXPECT_SCOPED(MainFrameInHighLatencyMode(1, 1, true, true)); | 1390 EXPECT_SCOPED(MainFrameInHighLatencyMode(1, 1, true, true)); | 
| 1379 } | 1391 } | 
| 1380 | 1392 | 
| 1393 void SchedulerTest::ImplFrameInHighLatencyMode( | |
| 
brianderson
2015/05/08 16:52:50
Hmm. I need to make a version of this test that te
 | |
| 1394 int64 begin_main_frame_to_commit_estimate_in_ms, | |
| 1395 int64 commit_to_activate_estimate_in_ms, | |
| 1396 bool swap_ack_before_deadline, | |
| 1397 bool should_begin_impl_frame_in_high_latency) { | |
| 1398 // Set up client with specified estimates (draw duration is set to 1). | |
| 1399 SchedulerClientWithFixedEstimates* client = | |
| 1400 new SchedulerClientWithFixedEstimates( | |
| 1401 base::TimeDelta::FromMilliseconds(0), | |
| 1402 base::TimeDelta::FromMilliseconds( | |
| 1403 begin_main_frame_to_commit_estimate_in_ms), | |
| 1404 base::TimeDelta::FromMilliseconds(commit_to_activate_estimate_in_ms)); | |
| 1405 | |
| 1406 scheduler_settings_.use_external_begin_frame_source = true; | |
| 1407 SetUpScheduler(make_scoped_ptr(client).Pass(), true); | |
| 1408 EXPECT_FALSE(scheduler_->ImplThreadIsLikelyInHighLatencyMode()); | |
| 1409 | |
| 1410 // To get into a high latency state, this test disables automatic swap acks. | |
| 1411 scheduler_->SetMaxSwapsPending(1); | |
| 1412 client_->SetAutomaticSwapAck(false); | |
| 1413 | |
| 1414 // Draw and swap for first BeginFrame | |
| 1415 client->Reset(); | |
| 1416 scheduler_->SetNeedsRedraw(); | |
| 1417 EXPECT_FALSE(scheduler_->MainThreadIsInHighLatencyMode()); | |
| 1418 EXPECT_FALSE(scheduler_->ImplThreadIsLikelyInHighLatencyMode()); | |
| 1419 EXPECT_SCOPED(AdvanceFrame()); | |
| 1420 EXPECT_FALSE(scheduler_->MainThreadIsInHighLatencyMode()); | |
| 1421 EXPECT_FALSE(scheduler_->ImplThreadIsLikelyInHighLatencyMode()); | |
| 1422 task_runner().RunPendingTasks(); // Run posted deadline. | |
| 1423 EXPECT_TRUE(client->HasAction("ScheduledActionDrawAndSwapIfPossible")); | |
| 1424 | |
| 1425 // Not calling scheduler_->DidSwapBuffersComplete() until after next frame | |
| 1426 // puts impl thread in high latency mode. | |
| 1427 client->Reset(); | |
| 1428 scheduler_->SetNeedsRedraw(); | |
| 1429 EXPECT_FALSE(scheduler_->MainThreadIsInHighLatencyMode()); | |
| 1430 EXPECT_FALSE(scheduler_->ImplThreadIsLikelyInHighLatencyMode()); | |
| 1431 EXPECT_SCOPED(AdvanceFrame()); | |
| 1432 EXPECT_FALSE(scheduler_->MainThreadIsInHighLatencyMode()); | |
| 1433 EXPECT_FALSE(scheduler_->ImplThreadIsLikelyInHighLatencyMode()); | |
| 1434 if (swap_ack_before_deadline) { | |
| 1435 scheduler_->DidSwapBuffersComplete(); | |
| 1436 EXPECT_FALSE(scheduler_->MainThreadIsInHighLatencyMode()); | |
| 1437 EXPECT_TRUE(scheduler_->ImplThreadIsLikelyInHighLatencyMode()); | |
| 1438 } | |
| 1439 task_runner().RunPendingTasks(); // Run posted deadline. | |
| 1440 EXPECT_TRUE(scheduler_->ImplThreadIsLikelyInHighLatencyMode()); | |
| 1441 | |
| 1442 // Now that we are in a high latency mode, test if we recover or not. | |
| 1443 client->Reset(); | |
| 1444 scheduler_->SetNeedsRedraw(); | |
| 1445 EXPECT_FALSE(scheduler_->MainThreadIsInHighLatencyMode()); | |
| 1446 EXPECT_TRUE(scheduler_->ImplThreadIsLikelyInHighLatencyMode()); | |
| 1447 SendNextBeginFrame(); | |
| 1448 EXPECT_EQ(should_begin_impl_frame_in_high_latency, | |
| 1449 client->HasAction("WillBeginImplFrame")); | |
| 1450 } | |
| 1451 | |
| 1452 TEST_F(SchedulerTest, SkipImplFrameIfHighLatencyAndCanDrawBeforeDeadline) { | |
| 1453 // Set up client so that estimates indicate that we can commit and activate | |
| 1454 // before the deadline (~8ms by default). | |
| 1455 EXPECT_SCOPED(ImplFrameInHighLatencyMode(1, 1, true, false)); | |
| 1456 } | |
| 1457 | |
| 1458 TEST_F(SchedulerTest, NotSkipImplFrameIfHighLatencyAndCanCommitTooLong) { | |
| 1459 // Set up client so that estimates indicate that the commit cannot finish | |
| 1460 // before the deadline (~8ms by default). | |
| 1461 EXPECT_SCOPED(ImplFrameInHighLatencyMode(10, 1, true, true)); | |
| 1462 } | |
| 1463 | |
| 1464 TEST_F(SchedulerTest, NotSkipImplFrameIfHighLatencyAndCanActivateTooLong) { | |
| 1465 // Set up client so that estimates indicate that the activate cannot finish | |
| 1466 // before the deadline (~8ms by default). | |
| 1467 EXPECT_SCOPED(ImplFrameInHighLatencyMode(1, 10, false, true)); | |
| 1468 } | |
| 1469 | |
| 1381 TEST_F(SchedulerTest, PollForCommitCompletion) { | 1470 TEST_F(SchedulerTest, PollForCommitCompletion) { | 
| 1382 // Since we are simulating a long commit, set up a client with draw duration | 1471 // Since we are simulating a long commit, set up a client with draw duration | 
| 1383 // estimates that prevent skipping main frames to get to low latency mode. | 1472 // estimates that prevent skipping main frames to get to low latency mode. | 
| 1384 SchedulerClientWithFixedEstimates* client = | 1473 SchedulerClientWithFixedEstimates* client = | 
| 1385 new SchedulerClientWithFixedEstimates( | 1474 new SchedulerClientWithFixedEstimates( | 
| 1386 base::TimeDelta::FromMilliseconds(1), | 1475 base::TimeDelta::FromMilliseconds(1), | 
| 1387 base::TimeDelta::FromMilliseconds(32), | 1476 base::TimeDelta::FromMilliseconds(32), | 
| 1388 base::TimeDelta::FromMilliseconds(32)); | 1477 base::TimeDelta::FromMilliseconds(32)); | 
| 1389 scheduler_settings_.use_external_begin_frame_source = true; | 1478 scheduler_settings_.use_external_begin_frame_source = true; | 
| 1390 SetUpScheduler(make_scoped_ptr(client).Pass(), true); | 1479 SetUpScheduler(make_scoped_ptr(client).Pass(), true); | 
| 1391 | 1480 | 
| 1392 client->set_log_anticipated_draw_time_change(true); | 1481 client->set_log_anticipated_draw_time_change(true); | 
| 1393 | 1482 | 
| 1394 BeginFrameArgs frame_args = | 1483 BeginFrameArgs frame_args = | 
| 1395 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, now_src()); | 1484 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, now_src()); | 
| 1396 frame_args.interval = base::TimeDelta::FromMilliseconds(1000); | 1485 frame_args.interval = base::TimeDelta::FromMilliseconds(1000); | 
| 1397 | 1486 | 
| 1398 // At this point, we've drawn a frame. Start another commit, but hold off on | 1487 // At this point, we've drawn a frame. Start another commit, but hold off on | 
| 1399 // the NotifyReadyToCommit for now. | 1488 // the NotifyReadyToCommit for now. | 
| 1400 EXPECT_FALSE(scheduler_->CommitPending()); | 1489 EXPECT_FALSE(scheduler_->CommitPending()); | 
| 1401 scheduler_->SetNeedsCommit(); | 1490 scheduler_->SetNeedsCommit(); | 
| 1402 fake_external_begin_frame_source()->TestOnBeginFrame(frame_args); | 1491 fake_external_begin_frame_source()->TestOnBeginFrame(frame_args); | 
| 1403 EXPECT_TRUE(scheduler_->CommitPending()); | 1492 EXPECT_TRUE(scheduler_->CommitPending()); | 
| 1404 | 1493 | 
| 1405 // Draw and swap the frame, but don't ack the swap to simulate the Browser | 1494 // Draw and swap the frame, but don't ack the swap to simulate the Browser | 
| 1406 // blocking on the renderer. | 1495 // blocking on the renderer. | 
| 1407 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 1496 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePendingForTest()); | 
| 1408 task_runner().RunPendingTasks(); // Run posted deadline. | 1497 task_runner().RunPendingTasks(); // Run posted deadline. | 
| 1409 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | 1498 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePendingForTest()); | 
| 1410 scheduler_->DidSwapBuffers(); | 1499 scheduler_->DidSwapBuffers(); | 
| 1411 | 1500 | 
| 1412 // Spin the event loop a few times and make sure we get more | 1501 // Spin the event loop a few times and make sure we get more | 
| 1413 // DidAnticipateDrawTimeChange calls every time. | 1502 // DidAnticipateDrawTimeChange calls every time. | 
| 1414 int actions_so_far = client->num_actions_(); | 1503 int actions_so_far = client->num_actions_(); | 
| 1415 | 1504 | 
| 1416 // Does three iterations to make sure that the timer is properly repeating. | 1505 // Does three iterations to make sure that the timer is properly repeating. | 
| 1417 for (int i = 0; i < 3; ++i) { | 1506 for (int i = 0; i < 3; ++i) { | 
| 1418 EXPECT_EQ((frame_args.interval * 2).InMicroseconds(), | 1507 EXPECT_EQ((frame_args.interval * 2).InMicroseconds(), | 
| 1419 task_runner().DelayToNextTaskTime().InMicroseconds()) | 1508 task_runner().DelayToNextTaskTime().InMicroseconds()) | 
| (...skipping 29 matching lines...) Expand all Loading... | |
| 1449 client_->Reset(); | 1538 client_->Reset(); | 
| 1450 | 1539 | 
| 1451 // Create a BeginFrame with a long deadline to avoid race conditions. | 1540 // Create a BeginFrame with a long deadline to avoid race conditions. | 
| 1452 // This is the first BeginFrame, which will be handled immediately. | 1541 // This is the first BeginFrame, which will be handled immediately. | 
| 1453 BeginFrameArgs args = | 1542 BeginFrameArgs args = | 
| 1454 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, now_src()); | 1543 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, now_src()); | 
| 1455 args.deadline += base::TimeDelta::FromHours(1); | 1544 args.deadline += base::TimeDelta::FromHours(1); | 
| 1456 fake_external_begin_frame_source()->TestOnBeginFrame(args); | 1545 fake_external_begin_frame_source()->TestOnBeginFrame(args); | 
| 1457 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); | 1546 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); | 
| 1458 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); | 1547 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); | 
| 1459 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 1548 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePendingForTest()); | 
| 1460 EXPECT_TRUE(client_->needs_begin_frames()); | 1549 EXPECT_TRUE(client_->needs_begin_frames()); | 
| 1461 client_->Reset(); | 1550 client_->Reset(); | 
| 1462 | 1551 | 
| 1463 // Queue BeginFrames while we are still handling the previous BeginFrame. | 1552 // Queue BeginFrames while we are still handling the previous BeginFrame. | 
| 1464 args.frame_time += base::TimeDelta::FromSeconds(1); | 1553 args.frame_time += base::TimeDelta::FromSeconds(1); | 
| 1465 fake_external_begin_frame_source()->TestOnBeginFrame(args); | 1554 fake_external_begin_frame_source()->TestOnBeginFrame(args); | 
| 1466 args.frame_time += base::TimeDelta::FromSeconds(1); | 1555 args.frame_time += base::TimeDelta::FromSeconds(1); | 
| 1467 fake_external_begin_frame_source()->TestOnBeginFrame(args); | 1556 fake_external_begin_frame_source()->TestOnBeginFrame(args); | 
| 1468 | 1557 | 
| 1469 // If we don't swap on the deadline, we wait for the next BeginImplFrame. | 1558 // If we don't swap on the deadline, we wait for the next BeginImplFrame. | 
| 1470 task_runner().RunPendingTasks(); // Run posted deadline. | 1559 task_runner().RunPendingTasks(); // Run posted deadline. | 
| 1471 EXPECT_NO_ACTION(client_); | 1560 EXPECT_NO_ACTION(client_); | 
| 1472 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | 1561 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePendingForTest()); | 
| 1473 EXPECT_TRUE(client_->needs_begin_frames()); | 1562 EXPECT_TRUE(client_->needs_begin_frames()); | 
| 1474 client_->Reset(); | 1563 client_->Reset(); | 
| 1475 | 1564 | 
| 1476 // NotifyReadyToCommit should trigger the commit. | 1565 // NotifyReadyToCommit should trigger the commit. | 
| 1477 scheduler_->NotifyBeginMainFrameStarted(); | 1566 scheduler_->NotifyBeginMainFrameStarted(); | 
| 1478 scheduler_->NotifyReadyToCommit(); | 1567 scheduler_->NotifyReadyToCommit(); | 
| 1479 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_); | 1568 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_); | 
| 1480 EXPECT_TRUE(client_->needs_begin_frames()); | 1569 EXPECT_TRUE(client_->needs_begin_frames()); | 
| 1481 client_->Reset(); | 1570 client_->Reset(); | 
| 1482 | 1571 | 
| 1483 // BeginImplFrame should prepare the draw. | 1572 // BeginImplFrame should prepare the draw. | 
| 1484 task_runner().RunPendingTasks(); // Run posted BeginRetroFrame. | 1573 task_runner().RunPendingTasks(); // Run posted BeginRetroFrame. | 
| 1485 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); | 1574 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); | 
| 1486 EXPECT_ACTION("ScheduledActionAnimate", client_, 1, 2); | 1575 EXPECT_ACTION("ScheduledActionAnimate", client_, 1, 2); | 
| 1487 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 1576 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePendingForTest()); | 
| 1488 EXPECT_TRUE(client_->needs_begin_frames()); | 1577 EXPECT_TRUE(client_->needs_begin_frames()); | 
| 1489 client_->Reset(); | 1578 client_->Reset(); | 
| 1490 | 1579 | 
| 1491 // BeginImplFrame deadline should draw. | 1580 // BeginImplFrame deadline should draw. | 
| 1492 task_runner().RunPendingTasks(); // Run posted deadline. | 1581 task_runner().RunPendingTasks(); // Run posted deadline. | 
| 1493 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 0, 1); | 1582 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 0, 1); | 
| 1494 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | 1583 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePendingForTest()); | 
| 1495 EXPECT_TRUE(client_->needs_begin_frames()); | 1584 EXPECT_TRUE(client_->needs_begin_frames()); | 
| 1496 client_->Reset(); | 1585 client_->Reset(); | 
| 1497 | 1586 | 
| 1498 // The following BeginImplFrame deadline should SetNeedsBeginFrame(false) | 1587 // The following BeginImplFrame deadline should SetNeedsBeginFrame(false) | 
| 1499 // to avoid excessive toggles. | 1588 // to avoid excessive toggles. | 
| 1500 task_runner().RunPendingTasks(); // Run posted BeginRetroFrame. | 1589 task_runner().RunPendingTasks(); // Run posted BeginRetroFrame. | 
| 1501 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client_); | 1590 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client_); | 
| 1502 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 1591 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePendingForTest()); | 
| 1503 client_->Reset(); | 1592 client_->Reset(); | 
| 1504 | 1593 | 
| 1505 task_runner().RunPendingTasks(); // Run posted deadline. | 1594 task_runner().RunPendingTasks(); // Run posted deadline. | 
| 1506 EXPECT_ACTION("SetNeedsBeginFrames(false)", client_, 0, 2); | 1595 EXPECT_ACTION("SetNeedsBeginFrames(false)", client_, 0, 2); | 
| 1507 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 1, 2); | 1596 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 1, 2); | 
| 1508 client_->Reset(); | 1597 client_->Reset(); | 
| 1509 } | 1598 } | 
| 1510 | 1599 | 
| 1511 TEST_F(SchedulerTest, BeginRetroFrame_SwapThrottled) { | 1600 TEST_F(SchedulerTest, BeginRetroFrame_SwapThrottled) { | 
| 1512 scheduler_settings_.use_external_begin_frame_source = true; | 1601 scheduler_settings_.use_external_begin_frame_source = true; | 
| 1513 SetUpScheduler(true); | 1602 SetUpScheduler(true); | 
| 1514 | 1603 | 
| 1515 scheduler_->SetEstimatedParentDrawTime(base::TimeDelta::FromMicroseconds(1)); | 1604 scheduler_->SetEstimatedParentDrawTime(base::TimeDelta::FromMicroseconds(1)); | 
| 1516 | 1605 | 
| 1517 // To test swap ack throttling, this test disables automatic swap acks. | 1606 // To test swap ack throttling, this test disables automatic swap acks. | 
| 1518 scheduler_->SetMaxSwapsPending(1); | 1607 scheduler_->SetMaxSwapsPending(1); | 
| 1519 client_->SetAutomaticSwapAck(false); | 1608 client_->SetAutomaticSwapAck(false); | 
| 1520 | 1609 | 
| 1521 // SetNeedsCommit should begin the frame on the next BeginImplFrame. | 1610 // SetNeedsCommit should begin the frame on the next BeginImplFrame. | 
| 1522 client_->Reset(); | 1611 client_->Reset(); | 
| 1523 scheduler_->SetNeedsCommit(); | 1612 scheduler_->SetNeedsCommit(); | 
| 1524 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client_); | 1613 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client_); | 
| 1525 client_->Reset(); | 1614 client_->Reset(); | 
| 1526 | 1615 | 
| 1527 EXPECT_SCOPED(AdvanceFrame()); | 1616 EXPECT_SCOPED(AdvanceFrame()); | 
| 1528 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); | 1617 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); | 
| 1529 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); | 1618 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); | 
| 1530 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 1619 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePendingForTest()); | 
| 1531 EXPECT_TRUE(client_->needs_begin_frames()); | 1620 EXPECT_TRUE(client_->needs_begin_frames()); | 
| 1532 client_->Reset(); | 1621 client_->Reset(); | 
| 1533 | 1622 | 
| 1534 // Queue BeginFrame while we are still handling the previous BeginFrame. | 1623 // Queue BeginFrame while we are still handling the previous BeginFrame. | 
| 1535 SendNextBeginFrame(); | 1624 SendNextBeginFrame(); | 
| 1536 EXPECT_NO_ACTION(client_); | 1625 EXPECT_NO_ACTION(client_); | 
| 1537 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 1626 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePendingForTest()); | 
| 1538 EXPECT_TRUE(client_->needs_begin_frames()); | 1627 EXPECT_TRUE(client_->needs_begin_frames()); | 
| 1539 client_->Reset(); | 1628 client_->Reset(); | 
| 1540 | 1629 | 
| 1541 // NotifyReadyToCommit should trigger the pending commit and draw. | 1630 // NotifyReadyToCommit should trigger the pending commit and draw. | 
| 1542 scheduler_->NotifyBeginMainFrameStarted(); | 1631 scheduler_->NotifyBeginMainFrameStarted(); | 
| 1543 scheduler_->NotifyReadyToCommit(); | 1632 scheduler_->NotifyReadyToCommit(); | 
| 1544 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_); | 1633 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_); | 
| 1545 EXPECT_TRUE(client_->needs_begin_frames()); | 1634 EXPECT_TRUE(client_->needs_begin_frames()); | 
| 1546 client_->Reset(); | 1635 client_->Reset(); | 
| 1547 | 1636 | 
| 1548 // Swapping will put us into a swap throttled state. | 1637 // Swapping will put us into a swap throttled state. | 
| 1549 // Run posted deadline. | 1638 // Run posted deadline. | 
| 1550 task_runner().RunTasksWhile(client_->ImplFrameDeadlinePending(true)); | 1639 task_runner().RunTasksWhile(client_->ImplFrameDeadlinePending(true)); | 
| 1551 EXPECT_ACTION("ScheduledActionAnimate", client_, 0, 2); | 1640 EXPECT_ACTION("ScheduledActionAnimate", client_, 0, 2); | 
| 1552 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 1, 2); | 1641 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 1, 2); | 
| 1553 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | 1642 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePendingForTest()); | 
| 1554 EXPECT_TRUE(client_->needs_begin_frames()); | 1643 EXPECT_TRUE(client_->needs_begin_frames()); | 
| 1555 client_->Reset(); | 1644 client_->Reset(); | 
| 1556 | 1645 | 
| 1557 // While swap throttled, BeginRetroFrames should trigger BeginImplFrames | 1646 // While swap throttled, BeginRetroFrames should trigger BeginImplFrames | 
| 1558 // but not a BeginMainFrame or draw. | 1647 // but not a BeginMainFrame or draw. | 
| 1559 scheduler_->SetNeedsCommit(); | 1648 scheduler_->SetNeedsCommit(); | 
| 1560 scheduler_->SetNeedsRedraw(); | 1649 scheduler_->SetNeedsRedraw(); | 
| 1561 // Run posted BeginRetroFrame. | 1650 // Run posted BeginRetroFrame. | 
| 1562 task_runner().RunTasksWhile(client_->ImplFrameDeadlinePending(false)); | 1651 task_runner().RunTasksWhile(client_->ImplFrameDeadlinePending(false)); | 
| 1563 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); | 1652 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); | 
| 1564 EXPECT_ACTION("ScheduledActionAnimate", client_, 1, 2); | 1653 EXPECT_ACTION("ScheduledActionAnimate", client_, 1, 2); | 
| 1565 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 1654 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePendingForTest()); | 
| 1566 EXPECT_TRUE(client_->needs_begin_frames()); | 1655 EXPECT_TRUE(client_->needs_begin_frames()); | 
| 1567 client_->Reset(); | 1656 client_->Reset(); | 
| 1568 | 1657 | 
| 1569 // Let time pass sufficiently beyond the regular deadline but not beyond the | 1658 // Let time pass sufficiently beyond the regular deadline but not beyond the | 
| 1570 // late deadline. | 1659 // late deadline. | 
| 1571 now_src()->AdvanceNow(BeginFrameArgs::DefaultInterval() - | 1660 now_src()->AdvanceNow(BeginFrameArgs::DefaultInterval() - | 
| 1572 base::TimeDelta::FromMicroseconds(1)); | 1661 base::TimeDelta::FromMicroseconds(1)); | 
| 1573 task_runner().RunUntilTime(now_src()->Now()); | 1662 task_runner().RunUntilTime(now_src()->Now()); | 
| 1574 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 1663 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePendingForTest()); | 
| 1575 | 1664 | 
| 1576 // Take us out of a swap throttled state. | 1665 // Take us out of a swap throttled state. | 
| 1577 scheduler_->DidSwapBuffersComplete(); | 1666 scheduler_->DidSwapBuffersComplete(); | 
| 1578 EXPECT_SINGLE_ACTION("ScheduledActionSendBeginMainFrame", client_); | 1667 EXPECT_SINGLE_ACTION("ScheduledActionSendBeginMainFrame", client_); | 
| 1579 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 1668 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePendingForTest()); | 
| 1580 EXPECT_TRUE(client_->needs_begin_frames()); | 1669 EXPECT_TRUE(client_->needs_begin_frames()); | 
| 1581 client_->Reset(); | 1670 client_->Reset(); | 
| 1582 | 1671 | 
| 1583 // Verify that the deadline was rescheduled. | 1672 // Verify that the deadline was rescheduled. | 
| 1584 task_runner().RunUntilTime(now_src()->Now()); | 1673 task_runner().RunUntilTime(now_src()->Now()); | 
| 1585 EXPECT_SINGLE_ACTION("ScheduledActionDrawAndSwapIfPossible", client_); | 1674 EXPECT_SINGLE_ACTION("ScheduledActionDrawAndSwapIfPossible", client_); | 
| 1586 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | 1675 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePendingForTest()); | 
| 1587 EXPECT_TRUE(client_->needs_begin_frames()); | 1676 EXPECT_TRUE(client_->needs_begin_frames()); | 
| 1588 client_->Reset(); | 1677 client_->Reset(); | 
| 1589 } | 1678 } | 
| 1590 | 1679 | 
| 1591 TEST_F(SchedulerTest, RetroFrameDoesNotExpireTooEarly) { | 1680 TEST_F(SchedulerTest, RetroFrameDoesNotExpireTooEarly) { | 
| 1592 scheduler_settings_.use_external_begin_frame_source = true; | 1681 scheduler_settings_.use_external_begin_frame_source = true; | 
| 1593 SetUpScheduler(true); | 1682 SetUpScheduler(true); | 
| 1594 | 1683 | 
| 1595 scheduler_->SetNeedsCommit(); | 1684 scheduler_->SetNeedsCommit(); | 
| 1596 EXPECT_TRUE(client_->needs_begin_frames()); | 1685 EXPECT_TRUE(client_->needs_begin_frames()); | 
| 1597 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client_); | 1686 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client_); | 
| 1598 | 1687 | 
| 1599 client_->Reset(); | 1688 client_->Reset(); | 
| 1600 EXPECT_SCOPED(AdvanceFrame()); | 1689 EXPECT_SCOPED(AdvanceFrame()); | 
| 1601 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); | 1690 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); | 
| 1602 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); | 1691 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); | 
| 1603 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 1692 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePendingForTest()); | 
| 1604 | 1693 | 
| 1605 client_->Reset(); | 1694 client_->Reset(); | 
| 1606 scheduler_->NotifyBeginMainFrameStarted(); | 1695 scheduler_->NotifyBeginMainFrameStarted(); | 
| 1607 | 1696 | 
| 1608 client_->Reset(); | 1697 client_->Reset(); | 
| 1609 SendNextBeginFrame(); | 1698 SendNextBeginFrame(); | 
| 1610 // This BeginFrame is queued up as a retro frame. | 1699 // This BeginFrame is queued up as a retro frame. | 
| 1611 EXPECT_NO_ACTION(client_); | 1700 EXPECT_NO_ACTION(client_); | 
| 1612 // The previous deadline is still pending. | 1701 // The previous deadline is still pending. | 
| 1613 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 1702 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePendingForTest()); | 
| 1614 | 1703 | 
| 1615 client_->Reset(); | 1704 client_->Reset(); | 
| 1616 // This commit should schedule the (previous) deadline to trigger immediately. | 1705 // This commit should schedule the (previous) deadline to trigger immediately. | 
| 1617 scheduler_->NotifyReadyToCommit(); | 1706 scheduler_->NotifyReadyToCommit(); | 
| 1618 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_); | 1707 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_); | 
| 1619 | 1708 | 
| 1620 client_->Reset(); | 1709 client_->Reset(); | 
| 1621 // The deadline task should trigger causing a draw. | 1710 // The deadline task should trigger causing a draw. | 
| 1622 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 1711 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePendingForTest()); | 
| 1623 task_runner().RunTasksWhile(client_->ImplFrameDeadlinePending(true)); | 1712 task_runner().RunTasksWhile(client_->ImplFrameDeadlinePending(true)); | 
| 1624 EXPECT_ACTION("ScheduledActionAnimate", client_, 0, 2); | 1713 EXPECT_ACTION("ScheduledActionAnimate", client_, 0, 2); | 
| 1625 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 1, 2); | 1714 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 1, 2); | 
| 1626 | 1715 | 
| 1627 // Keep animating. | 1716 // Keep animating. | 
| 1628 client_->Reset(); | 1717 client_->Reset(); | 
| 1629 scheduler_->SetNeedsAnimate(); | 1718 scheduler_->SetNeedsAnimate(); | 
| 1630 scheduler_->SetNeedsRedraw(); | 1719 scheduler_->SetNeedsRedraw(); | 
| 1631 EXPECT_NO_ACTION(client_); | 1720 EXPECT_NO_ACTION(client_); | 
| 1632 | 1721 | 
| 1633 // Let's advance sufficiently past the next frame's deadline. | 1722 // Let's advance sufficiently past the next frame's deadline. | 
| 1634 now_src()->AdvanceNow(BeginFrameArgs::DefaultInterval() - | 1723 now_src()->AdvanceNow(BeginFrameArgs::DefaultInterval() - | 
| 1635 BeginFrameArgs::DefaultEstimatedParentDrawTime() + | 1724 BeginFrameArgs::DefaultEstimatedParentDrawTime() + | 
| 1636 base::TimeDelta::FromMicroseconds(1)); | 1725 base::TimeDelta::FromMicroseconds(1)); | 
| 1637 | 1726 | 
| 1638 // The retro frame hasn't expired yet. | 1727 // The retro frame hasn't expired yet. | 
| 1639 task_runner().RunTasksWhile(client_->ImplFrameDeadlinePending(false)); | 1728 task_runner().RunTasksWhile(client_->ImplFrameDeadlinePending(false)); | 
| 1640 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); | 1729 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); | 
| 1641 EXPECT_ACTION("ScheduledActionAnimate", client_, 1, 2); | 1730 EXPECT_ACTION("ScheduledActionAnimate", client_, 1, 2); | 
| 1642 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 1731 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePendingForTest()); | 
| 1643 | 1732 | 
| 1644 // This is an immediate deadline case. | 1733 // This is an immediate deadline case. | 
| 1645 client_->Reset(); | 1734 client_->Reset(); | 
| 1646 task_runner().RunPendingTasks(); | 1735 task_runner().RunPendingTasks(); | 
| 1647 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | 1736 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePendingForTest()); | 
| 1648 EXPECT_SINGLE_ACTION("ScheduledActionDrawAndSwapIfPossible", client_); | 1737 EXPECT_SINGLE_ACTION("ScheduledActionDrawAndSwapIfPossible", client_); | 
| 1649 } | 1738 } | 
| 1650 | 1739 | 
| 1651 TEST_F(SchedulerTest, RetroFrameDoesNotExpireTooLate) { | 1740 TEST_F(SchedulerTest, RetroFrameDoesNotExpireTooLate) { | 
| 1652 scheduler_settings_.use_external_begin_frame_source = true; | 1741 scheduler_settings_.use_external_begin_frame_source = true; | 
| 1653 SetUpScheduler(true); | 1742 SetUpScheduler(true); | 
| 1654 | 1743 | 
| 1655 scheduler_->SetNeedsCommit(); | 1744 scheduler_->SetNeedsCommit(); | 
| 1656 EXPECT_TRUE(client_->needs_begin_frames()); | 1745 EXPECT_TRUE(client_->needs_begin_frames()); | 
| 1657 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client_); | 1746 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client_); | 
| 1658 | 1747 | 
| 1659 client_->Reset(); | 1748 client_->Reset(); | 
| 1660 EXPECT_SCOPED(AdvanceFrame()); | 1749 EXPECT_SCOPED(AdvanceFrame()); | 
| 1661 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); | 1750 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); | 
| 1662 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); | 1751 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); | 
| 1663 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 1752 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePendingForTest()); | 
| 1664 | 1753 | 
| 1665 client_->Reset(); | 1754 client_->Reset(); | 
| 1666 scheduler_->NotifyBeginMainFrameStarted(); | 1755 scheduler_->NotifyBeginMainFrameStarted(); | 
| 1667 | 1756 | 
| 1668 client_->Reset(); | 1757 client_->Reset(); | 
| 1669 SendNextBeginFrame(); | 1758 SendNextBeginFrame(); | 
| 1670 // This BeginFrame is queued up as a retro frame. | 1759 // This BeginFrame is queued up as a retro frame. | 
| 1671 EXPECT_NO_ACTION(client_); | 1760 EXPECT_NO_ACTION(client_); | 
| 1672 // The previous deadline is still pending. | 1761 // The previous deadline is still pending. | 
| 1673 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 1762 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePendingForTest()); | 
| 1674 | 1763 | 
| 1675 client_->Reset(); | 1764 client_->Reset(); | 
| 1676 // This commit should schedule the (previous) deadline to trigger immediately. | 1765 // This commit should schedule the (previous) deadline to trigger immediately. | 
| 1677 scheduler_->NotifyReadyToCommit(); | 1766 scheduler_->NotifyReadyToCommit(); | 
| 1678 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_); | 1767 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_); | 
| 1679 | 1768 | 
| 1680 client_->Reset(); | 1769 client_->Reset(); | 
| 1681 // The deadline task should trigger causing a draw. | 1770 // The deadline task should trigger causing a draw. | 
| 1682 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 1771 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePendingForTest()); | 
| 1683 task_runner().RunTasksWhile(client_->ImplFrameDeadlinePending(true)); | 1772 task_runner().RunTasksWhile(client_->ImplFrameDeadlinePending(true)); | 
| 1684 EXPECT_ACTION("ScheduledActionAnimate", client_, 0, 2); | 1773 EXPECT_ACTION("ScheduledActionAnimate", client_, 0, 2); | 
| 1685 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 1, 2); | 1774 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 1, 2); | 
| 1686 | 1775 | 
| 1687 // Keep animating. | 1776 // Keep animating. | 
| 1688 client_->Reset(); | 1777 client_->Reset(); | 
| 1689 scheduler_->SetNeedsAnimate(); | 1778 scheduler_->SetNeedsAnimate(); | 
| 1690 scheduler_->SetNeedsRedraw(); | 1779 scheduler_->SetNeedsRedraw(); | 
| 1691 EXPECT_NO_ACTION(client_); | 1780 EXPECT_NO_ACTION(client_); | 
| 1692 | 1781 | 
| (...skipping 17 matching lines...) Expand all Loading... | |
| 1710 // without calling SetNeedsBeginFrame. | 1799 // without calling SetNeedsBeginFrame. | 
| 1711 scheduler_->SetNeedsCommit(); | 1800 scheduler_->SetNeedsCommit(); | 
| 1712 EXPECT_NO_ACTION(client_); | 1801 EXPECT_NO_ACTION(client_); | 
| 1713 client_->Reset(); | 1802 client_->Reset(); | 
| 1714 | 1803 | 
| 1715 // When the client-driven BeginFrame are disabled, the scheduler posts it's | 1804 // When the client-driven BeginFrame are disabled, the scheduler posts it's | 
| 1716 // own BeginFrame tasks. | 1805 // own BeginFrame tasks. | 
| 1717 task_runner().RunPendingTasks(); // Run posted BeginFrame. | 1806 task_runner().RunPendingTasks(); // Run posted BeginFrame. | 
| 1718 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); | 1807 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); | 
| 1719 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); | 1808 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); | 
| 1720 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 1809 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePendingForTest()); | 
| 1721 client_->Reset(); | 1810 client_->Reset(); | 
| 1722 | 1811 | 
| 1723 // If we don't swap on the deadline, we wait for the next BeginFrame. | 1812 // If we don't swap on the deadline, we wait for the next BeginFrame. | 
| 1724 task_runner().RunPendingTasks(); // Run posted deadline. | 1813 task_runner().RunPendingTasks(); // Run posted deadline. | 
| 1725 EXPECT_NO_ACTION(client_); | 1814 EXPECT_NO_ACTION(client_); | 
| 1726 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | 1815 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePendingForTest()); | 
| 1727 client_->Reset(); | 1816 client_->Reset(); | 
| 1728 | 1817 | 
| 1729 // NotifyReadyToCommit should trigger the commit. | 1818 // NotifyReadyToCommit should trigger the commit. | 
| 1730 scheduler_->NotifyBeginMainFrameStarted(); | 1819 scheduler_->NotifyBeginMainFrameStarted(); | 
| 1731 scheduler_->NotifyReadyToCommit(); | 1820 scheduler_->NotifyReadyToCommit(); | 
| 1732 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_); | 1821 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_); | 
| 1733 client_->Reset(); | 1822 client_->Reset(); | 
| 1734 | 1823 | 
| 1735 // BeginImplFrame should prepare the draw. | 1824 // BeginImplFrame should prepare the draw. | 
| 1736 task_runner().RunPendingTasks(); // Run posted BeginFrame. | 1825 task_runner().RunPendingTasks(); // Run posted BeginFrame. | 
| 1737 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); | 1826 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); | 
| 1738 EXPECT_ACTION("ScheduledActionAnimate", client_, 1, 2); | 1827 EXPECT_ACTION("ScheduledActionAnimate", client_, 1, 2); | 
| 1739 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 1828 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePendingForTest()); | 
| 1740 client_->Reset(); | 1829 client_->Reset(); | 
| 1741 | 1830 | 
| 1742 // BeginImplFrame deadline should draw. | 1831 // BeginImplFrame deadline should draw. | 
| 1743 task_runner().RunTasksWhile(client_->ImplFrameDeadlinePending(true)); | 1832 task_runner().RunTasksWhile(client_->ImplFrameDeadlinePending(true)); | 
| 1744 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 0, 1); | 1833 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 0, 1); | 
| 1745 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | 1834 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePendingForTest()); | 
| 1746 client_->Reset(); | 1835 client_->Reset(); | 
| 1747 | 1836 | 
| 1748 // The following BeginImplFrame deadline should SetNeedsBeginFrame(false) | 1837 // The following BeginImplFrame deadline should SetNeedsBeginFrame(false) | 
| 1749 // to avoid excessive toggles. | 1838 // to avoid excessive toggles. | 
| 1750 task_runner().RunPendingTasks(); // Run posted BeginFrame. | 1839 task_runner().RunPendingTasks(); // Run posted BeginFrame. | 
| 1751 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client_); | 1840 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client_); | 
| 1752 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 1841 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePendingForTest()); | 
| 1753 client_->Reset(); | 1842 client_->Reset(); | 
| 1754 | 1843 | 
| 1755 // Make sure SetNeedsBeginFrame isn't called on the client | 1844 // Make sure SetNeedsBeginFrame isn't called on the client | 
| 1756 // when the BeginFrame is no longer needed. | 1845 // when the BeginFrame is no longer needed. | 
| 1757 task_runner().RunPendingTasks(); // Run posted deadline. | 1846 task_runner().RunPendingTasks(); // Run posted deadline. | 
| 1758 EXPECT_SINGLE_ACTION("SendBeginMainFrameNotExpectedSoon", client_); | 1847 EXPECT_SINGLE_ACTION("SendBeginMainFrameNotExpectedSoon", client_); | 
| 1759 client_->Reset(); | 1848 client_->Reset(); | 
| 1760 } | 1849 } | 
| 1761 | 1850 | 
| 1762 TEST_F(SchedulerTest, SyntheticBeginFrames) { | 1851 TEST_F(SchedulerTest, SyntheticBeginFrames) { | 
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1797 // SetNeedsCommit should begin the frame on the next BeginImplFrame. | 1886 // SetNeedsCommit should begin the frame on the next BeginImplFrame. | 
| 1798 client_->Reset(); | 1887 client_->Reset(); | 
| 1799 scheduler_->SetNeedsCommit(); | 1888 scheduler_->SetNeedsCommit(); | 
| 1800 EXPECT_NO_ACTION(client_); | 1889 EXPECT_NO_ACTION(client_); | 
| 1801 client_->Reset(); | 1890 client_->Reset(); | 
| 1802 | 1891 | 
| 1803 // Trigger the first BeginImplFrame and BeginMainFrame | 1892 // Trigger the first BeginImplFrame and BeginMainFrame | 
| 1804 EXPECT_SCOPED(AdvanceFrame()); | 1893 EXPECT_SCOPED(AdvanceFrame()); | 
| 1805 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); | 1894 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); | 
| 1806 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); | 1895 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); | 
| 1807 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 1896 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePendingForTest()); | 
| 1808 client_->Reset(); | 1897 client_->Reset(); | 
| 1809 | 1898 | 
| 1810 // NotifyReadyToCommit should trigger the pending commit and draw. | 1899 // NotifyReadyToCommit should trigger the pending commit and draw. | 
| 1811 scheduler_->NotifyBeginMainFrameStarted(); | 1900 scheduler_->NotifyBeginMainFrameStarted(); | 
| 1812 scheduler_->NotifyReadyToCommit(); | 1901 scheduler_->NotifyReadyToCommit(); | 
| 1813 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_); | 1902 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_); | 
| 1814 client_->Reset(); | 1903 client_->Reset(); | 
| 1815 | 1904 | 
| 1816 // Swapping will put us into a swap throttled state. | 1905 // Swapping will put us into a swap throttled state. | 
| 1817 // Run posted deadline. | 1906 // Run posted deadline. | 
| 1818 task_runner().RunTasksWhile(client_->ImplFrameDeadlinePending(true)); | 1907 task_runner().RunTasksWhile(client_->ImplFrameDeadlinePending(true)); | 
| 1819 EXPECT_ACTION("ScheduledActionAnimate", client_, 0, 2); | 1908 EXPECT_ACTION("ScheduledActionAnimate", client_, 0, 2); | 
| 1820 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 1, 2); | 1909 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 1, 2); | 
| 1821 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | 1910 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePendingForTest()); | 
| 1822 client_->Reset(); | 1911 client_->Reset(); | 
| 1823 | 1912 | 
| 1824 // While swap throttled, BeginFrames should trigger BeginImplFrames, | 1913 // While swap throttled, BeginFrames should trigger BeginImplFrames, | 
| 1825 // but not a BeginMainFrame or draw. | 1914 // but not a BeginMainFrame or draw. | 
| 1826 scheduler_->SetNeedsCommit(); | 1915 scheduler_->SetNeedsCommit(); | 
| 1827 scheduler_->SetNeedsRedraw(); | 1916 scheduler_->SetNeedsRedraw(); | 
| 1828 EXPECT_SCOPED(AdvanceFrame()); // Run posted BeginFrame. | 1917 EXPECT_SCOPED(AdvanceFrame()); // Run posted BeginFrame. | 
| 1829 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); | 1918 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); | 
| 1830 EXPECT_ACTION("ScheduledActionAnimate", client_, 1, 2); | 1919 EXPECT_ACTION("ScheduledActionAnimate", client_, 1, 2); | 
| 1831 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 1920 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePendingForTest()); | 
| 1832 client_->Reset(); | 1921 client_->Reset(); | 
| 1833 | 1922 | 
| 1834 // Let time pass sufficiently beyond the regular deadline but not beyond the | 1923 // Let time pass sufficiently beyond the regular deadline but not beyond the | 
| 1835 // late deadline. | 1924 // late deadline. | 
| 1836 now_src()->AdvanceNow(BeginFrameArgs::DefaultInterval() - | 1925 now_src()->AdvanceNow(BeginFrameArgs::DefaultInterval() - | 
| 1837 base::TimeDelta::FromMicroseconds(1)); | 1926 base::TimeDelta::FromMicroseconds(1)); | 
| 1838 task_runner().RunUntilTime(now_src()->Now()); | 1927 task_runner().RunUntilTime(now_src()->Now()); | 
| 1839 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 1928 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePendingForTest()); | 
| 1840 | 1929 | 
| 1841 // Take us out of a swap throttled state. | 1930 // Take us out of a swap throttled state. | 
| 1842 scheduler_->DidSwapBuffersComplete(); | 1931 scheduler_->DidSwapBuffersComplete(); | 
| 1843 EXPECT_SINGLE_ACTION("ScheduledActionSendBeginMainFrame", client_); | 1932 EXPECT_SINGLE_ACTION("ScheduledActionSendBeginMainFrame", client_); | 
| 1844 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 1933 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePendingForTest()); | 
| 1845 client_->Reset(); | 1934 client_->Reset(); | 
| 1846 | 1935 | 
| 1847 // Verify that the deadline was rescheduled. | 1936 // Verify that the deadline was rescheduled. | 
| 1848 // We can't use RunUntilTime(now) here because the next frame is also | 1937 // We can't use RunUntilTime(now) here because the next frame is also | 
| 1849 // scheduled if throttle_frame_production = false. | 1938 // scheduled if throttle_frame_production = false. | 
| 1850 base::TimeTicks before_deadline = now_src()->Now(); | 1939 base::TimeTicks before_deadline = now_src()->Now(); | 
| 1851 task_runner().RunTasksWhile(client_->ImplFrameDeadlinePending(true)); | 1940 task_runner().RunTasksWhile(client_->ImplFrameDeadlinePending(true)); | 
| 1852 base::TimeTicks after_deadline = now_src()->Now(); | 1941 base::TimeTicks after_deadline = now_src()->Now(); | 
| 1853 EXPECT_EQ(after_deadline, before_deadline); | 1942 EXPECT_EQ(after_deadline, before_deadline); | 
| 1854 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | 1943 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePendingForTest()); | 
| 1855 client_->Reset(); | 1944 client_->Reset(); | 
| 1856 } | 1945 } | 
| 1857 | 1946 | 
| 1858 TEST_F(SchedulerTest, SyntheticBeginFrames_SwapThrottled) { | 1947 TEST_F(SchedulerTest, SyntheticBeginFrames_SwapThrottled) { | 
| 1859 bool use_external_begin_frame_source = false; | 1948 bool use_external_begin_frame_source = false; | 
| 1860 bool throttle_frame_production = true; | 1949 bool throttle_frame_production = true; | 
| 1861 BeginFramesNotFromClient_SwapThrottled(use_external_begin_frame_source, | 1950 BeginFramesNotFromClient_SwapThrottled(use_external_begin_frame_source, | 
| 1862 throttle_frame_production); | 1951 throttle_frame_production); | 
| 1863 } | 1952 } | 
| 1864 | 1953 | 
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1899 SetUpScheduler(true); | 1988 SetUpScheduler(true); | 
| 1900 | 1989 | 
| 1901 // SetNeedsCommit should begin the frame. | 1990 // SetNeedsCommit should begin the frame. | 
| 1902 scheduler_->SetNeedsCommit(); | 1991 scheduler_->SetNeedsCommit(); | 
| 1903 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client_); | 1992 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client_); | 
| 1904 | 1993 | 
| 1905 client_->Reset(); | 1994 client_->Reset(); | 
| 1906 EXPECT_SCOPED(AdvanceFrame()); | 1995 EXPECT_SCOPED(AdvanceFrame()); | 
| 1907 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); | 1996 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); | 
| 1908 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); | 1997 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); | 
| 1909 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 1998 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePendingForTest()); | 
| 1910 | 1999 | 
| 1911 client_->Reset(); | 2000 client_->Reset(); | 
| 1912 scheduler_->DidLoseOutputSurface(); | 2001 scheduler_->DidLoseOutputSurface(); | 
| 1913 // SetNeedsBeginFrames(false) is not called until the end of the frame. | 2002 // SetNeedsBeginFrames(false) is not called until the end of the frame. | 
| 1914 EXPECT_NO_ACTION(client_); | 2003 EXPECT_NO_ACTION(client_); | 
| 1915 | 2004 | 
| 1916 client_->Reset(); | 2005 client_->Reset(); | 
| 1917 scheduler_->NotifyBeginMainFrameStarted(); | 2006 scheduler_->NotifyBeginMainFrameStarted(); | 
| 1918 scheduler_->NotifyReadyToCommit(); | 2007 scheduler_->NotifyReadyToCommit(); | 
| 1919 EXPECT_ACTION("ScheduledActionCommit", client_, 0, 1); | 2008 EXPECT_ACTION("ScheduledActionCommit", client_, 0, 1); | 
| (...skipping 12 matching lines...) Expand all Loading... | |
| 1932 SetUpScheduler(true); | 2021 SetUpScheduler(true); | 
| 1933 | 2022 | 
| 1934 // SetNeedsCommit should begin the frame. | 2023 // SetNeedsCommit should begin the frame. | 
| 1935 scheduler_->SetNeedsCommit(); | 2024 scheduler_->SetNeedsCommit(); | 
| 1936 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client_); | 2025 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client_); | 
| 1937 | 2026 | 
| 1938 client_->Reset(); | 2027 client_->Reset(); | 
| 1939 EXPECT_SCOPED(AdvanceFrame()); | 2028 EXPECT_SCOPED(AdvanceFrame()); | 
| 1940 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); | 2029 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); | 
| 1941 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); | 2030 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); | 
| 1942 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 2031 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePendingForTest()); | 
| 1943 | 2032 | 
| 1944 client_->Reset(); | 2033 client_->Reset(); | 
| 1945 scheduler_->DidLoseOutputSurface(); | 2034 scheduler_->DidLoseOutputSurface(); | 
| 1946 // Do nothing when impl frame is in deadine pending state. | 2035 // Do nothing when impl frame is in deadine pending state. | 
| 1947 EXPECT_NO_ACTION(client_); | 2036 EXPECT_NO_ACTION(client_); | 
| 1948 | 2037 | 
| 1949 client_->Reset(); | 2038 client_->Reset(); | 
| 1950 // Run posted deadline. | 2039 // Run posted deadline. | 
| 1951 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 2040 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePendingForTest()); | 
| 1952 task_runner().RunTasksWhile(client_->ImplFrameDeadlinePending(true)); | 2041 task_runner().RunTasksWhile(client_->ImplFrameDeadlinePending(true)); | 
| 1953 // OnBeginImplFrameDeadline didn't schedule output surface creation because | 2042 // OnBeginImplFrameDeadline didn't schedule output surface creation because | 
| 1954 // main frame is not yet completed. | 2043 // main frame is not yet completed. | 
| 1955 EXPECT_ACTION("SetNeedsBeginFrames(false)", client_, 0, 2); | 2044 EXPECT_ACTION("SetNeedsBeginFrames(false)", client_, 0, 2); | 
| 1956 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 1, 2); | 2045 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 1, 2); | 
| 1957 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | 2046 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePendingForTest()); | 
| 1958 | 2047 | 
| 1959 // BeginImplFrame is not started. | 2048 // BeginImplFrame is not started. | 
| 1960 client_->Reset(); | 2049 client_->Reset(); | 
| 1961 task_runner().RunUntilTime(now_src()->Now() + | 2050 task_runner().RunUntilTime(now_src()->Now() + | 
| 1962 base::TimeDelta::FromMilliseconds(10)); | 2051 base::TimeDelta::FromMilliseconds(10)); | 
| 1963 EXPECT_NO_ACTION(client_); | 2052 EXPECT_NO_ACTION(client_); | 
| 1964 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | 2053 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePendingForTest()); | 
| 1965 | 2054 | 
| 1966 client_->Reset(); | 2055 client_->Reset(); | 
| 1967 scheduler_->NotifyBeginMainFrameStarted(); | 2056 scheduler_->NotifyBeginMainFrameStarted(); | 
| 1968 scheduler_->NotifyReadyToCommit(); | 2057 scheduler_->NotifyReadyToCommit(); | 
| 1969 if (impl_side_painting) { | 2058 if (impl_side_painting) { | 
| 1970 EXPECT_ACTION("ScheduledActionCommit", client_, 0, 3); | 2059 EXPECT_ACTION("ScheduledActionCommit", client_, 0, 3); | 
| 1971 EXPECT_ACTION("ScheduledActionActivateSyncTree", client_, 1, 3); | 2060 EXPECT_ACTION("ScheduledActionActivateSyncTree", client_, 1, 3); | 
| 1972 EXPECT_ACTION("ScheduledActionBeginOutputSurfaceCreation", client_, 2, 3); | 2061 EXPECT_ACTION("ScheduledActionBeginOutputSurfaceCreation", client_, 2, 3); | 
| 1973 } else { | 2062 } else { | 
| 1974 EXPECT_ACTION("ScheduledActionCommit", client_, 0, 2); | 2063 EXPECT_ACTION("ScheduledActionCommit", client_, 0, 2); | 
| (...skipping 20 matching lines...) Expand all Loading... | |
| 1995 SetUpScheduler(true); | 2084 SetUpScheduler(true); | 
| 1996 | 2085 | 
| 1997 // SetNeedsCommit should begin the frame. | 2086 // SetNeedsCommit should begin the frame. | 
| 1998 scheduler_->SetNeedsCommit(); | 2087 scheduler_->SetNeedsCommit(); | 
| 1999 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client_); | 2088 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client_); | 
| 2000 | 2089 | 
| 2001 client_->Reset(); | 2090 client_->Reset(); | 
| 2002 EXPECT_SCOPED(AdvanceFrame()); | 2091 EXPECT_SCOPED(AdvanceFrame()); | 
| 2003 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); | 2092 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); | 
| 2004 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); | 2093 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); | 
| 2005 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 2094 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePendingForTest()); | 
| 2006 | 2095 | 
| 2007 client_->Reset(); | 2096 client_->Reset(); | 
| 2008 scheduler_->NotifyBeginMainFrameStarted(); | 2097 scheduler_->NotifyBeginMainFrameStarted(); | 
| 2009 scheduler_->NotifyReadyToCommit(); | 2098 scheduler_->NotifyReadyToCommit(); | 
| 2010 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_); | 2099 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_); | 
| 2011 | 2100 | 
| 2012 client_->Reset(); | 2101 client_->Reset(); | 
| 2013 scheduler_->DidLoseOutputSurface(); | 2102 scheduler_->DidLoseOutputSurface(); | 
| 2014 // SetNeedsBeginFrames(false) is not called until the end of the frame. | 2103 // SetNeedsBeginFrames(false) is not called until the end of the frame. | 
| 2015 if (impl_side_painting) { | 2104 if (impl_side_painting) { | 
| (...skipping 23 matching lines...) Expand all Loading... | |
| 2039 SetUpScheduler(true); | 2128 SetUpScheduler(true); | 
| 2040 | 2129 | 
| 2041 scheduler_->SetNeedsPrepareTiles(); | 2130 scheduler_->SetNeedsPrepareTiles(); | 
| 2042 scheduler_->SetNeedsRedraw(); | 2131 scheduler_->SetNeedsRedraw(); | 
| 2043 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client_); | 2132 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client_); | 
| 2044 | 2133 | 
| 2045 client_->Reset(); | 2134 client_->Reset(); | 
| 2046 EXPECT_SCOPED(AdvanceFrame()); | 2135 EXPECT_SCOPED(AdvanceFrame()); | 
| 2047 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); | 2136 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); | 
| 2048 EXPECT_ACTION("ScheduledActionAnimate", client_, 1, 2); | 2137 EXPECT_ACTION("ScheduledActionAnimate", client_, 1, 2); | 
| 2049 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 2138 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePendingForTest()); | 
| 2050 | 2139 | 
| 2051 client_->Reset(); | 2140 client_->Reset(); | 
| 2052 scheduler_->DidLoseOutputSurface(); | 2141 scheduler_->DidLoseOutputSurface(); | 
| 2053 // SetNeedsBeginFrames(false) is not called until the end of the frame. | 2142 // SetNeedsBeginFrames(false) is not called until the end of the frame. | 
| 2054 EXPECT_NO_ACTION(client_); | 2143 EXPECT_NO_ACTION(client_); | 
| 2055 | 2144 | 
| 2056 client_->Reset(); | 2145 client_->Reset(); | 
| 2057 task_runner().RunTasksWhile(client_->ImplFrameDeadlinePending(true)); | 2146 task_runner().RunTasksWhile(client_->ImplFrameDeadlinePending(true)); | 
| 2058 EXPECT_ACTION("ScheduledActionPrepareTiles", client_, 0, 4); | 2147 EXPECT_ACTION("ScheduledActionPrepareTiles", client_, 0, 4); | 
| 2059 EXPECT_ACTION("ScheduledActionBeginOutputSurfaceCreation", client_, 1, 4); | 2148 EXPECT_ACTION("ScheduledActionBeginOutputSurfaceCreation", client_, 1, 4); | 
| (...skipping 11 matching lines...) Expand all Loading... | |
| 2071 | 2160 | 
| 2072 // Create a BeginFrame with a long deadline to avoid race conditions. | 2161 // Create a BeginFrame with a long deadline to avoid race conditions. | 
| 2073 // This is the first BeginFrame, which will be handled immediately. | 2162 // This is the first BeginFrame, which will be handled immediately. | 
| 2074 client_->Reset(); | 2163 client_->Reset(); | 
| 2075 BeginFrameArgs args = | 2164 BeginFrameArgs args = | 
| 2076 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, now_src()); | 2165 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, now_src()); | 
| 2077 args.deadline += base::TimeDelta::FromHours(1); | 2166 args.deadline += base::TimeDelta::FromHours(1); | 
| 2078 fake_external_begin_frame_source()->TestOnBeginFrame(args); | 2167 fake_external_begin_frame_source()->TestOnBeginFrame(args); | 
| 2079 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); | 2168 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); | 
| 2080 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); | 2169 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); | 
| 2081 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 2170 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePendingForTest()); | 
| 2082 EXPECT_TRUE(client_->needs_begin_frames()); | 2171 EXPECT_TRUE(client_->needs_begin_frames()); | 
| 2083 | 2172 | 
| 2084 // Queue BeginFrames while we are still handling the previous BeginFrame. | 2173 // Queue BeginFrames while we are still handling the previous BeginFrame. | 
| 2085 args.frame_time += base::TimeDelta::FromSeconds(1); | 2174 args.frame_time += base::TimeDelta::FromSeconds(1); | 
| 2086 fake_external_begin_frame_source()->TestOnBeginFrame(args); | 2175 fake_external_begin_frame_source()->TestOnBeginFrame(args); | 
| 2087 args.frame_time += base::TimeDelta::FromSeconds(1); | 2176 args.frame_time += base::TimeDelta::FromSeconds(1); | 
| 2088 fake_external_begin_frame_source()->TestOnBeginFrame(args); | 2177 fake_external_begin_frame_source()->TestOnBeginFrame(args); | 
| 2089 | 2178 | 
| 2090 // If we don't swap on the deadline, we wait for the next BeginImplFrame. | 2179 // If we don't swap on the deadline, we wait for the next BeginImplFrame. | 
| 2091 client_->Reset(); | 2180 client_->Reset(); | 
| 2092 task_runner().RunPendingTasks(); // Run posted deadline. | 2181 task_runner().RunPendingTasks(); // Run posted deadline. | 
| 2093 EXPECT_NO_ACTION(client_); | 2182 EXPECT_NO_ACTION(client_); | 
| 2094 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | 2183 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePendingForTest()); | 
| 2095 EXPECT_TRUE(client_->needs_begin_frames()); | 2184 EXPECT_TRUE(client_->needs_begin_frames()); | 
| 2096 | 2185 | 
| 2097 // NotifyReadyToCommit should trigger the commit. | 2186 // NotifyReadyToCommit should trigger the commit. | 
| 2098 client_->Reset(); | 2187 client_->Reset(); | 
| 2099 scheduler_->NotifyBeginMainFrameStarted(); | 2188 scheduler_->NotifyBeginMainFrameStarted(); | 
| 2100 scheduler_->NotifyReadyToCommit(); | 2189 scheduler_->NotifyReadyToCommit(); | 
| 2101 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_); | 2190 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_); | 
| 2102 EXPECT_TRUE(client_->needs_begin_frames()); | 2191 EXPECT_TRUE(client_->needs_begin_frames()); | 
| 2103 | 2192 | 
| 2104 client_->Reset(); | 2193 client_->Reset(); | 
| (...skipping 20 matching lines...) Expand all Loading... | |
| 2125 | 2214 | 
| 2126 // Create a BeginFrame with a long deadline to avoid race conditions. | 2215 // Create a BeginFrame with a long deadline to avoid race conditions. | 
| 2127 // This is the first BeginFrame, which will be handled immediately. | 2216 // This is the first BeginFrame, which will be handled immediately. | 
| 2128 client_->Reset(); | 2217 client_->Reset(); | 
| 2129 BeginFrameArgs args = | 2218 BeginFrameArgs args = | 
| 2130 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, now_src()); | 2219 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, now_src()); | 
| 2131 args.deadline += base::TimeDelta::FromHours(1); | 2220 args.deadline += base::TimeDelta::FromHours(1); | 
| 2132 fake_external_begin_frame_source()->TestOnBeginFrame(args); | 2221 fake_external_begin_frame_source()->TestOnBeginFrame(args); | 
| 2133 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); | 2222 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); | 
| 2134 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); | 2223 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); | 
| 2135 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 2224 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePendingForTest()); | 
| 2136 EXPECT_TRUE(client_->needs_begin_frames()); | 2225 EXPECT_TRUE(client_->needs_begin_frames()); | 
| 2137 | 2226 | 
| 2138 // Queue BeginFrames while we are still handling the previous BeginFrame. | 2227 // Queue BeginFrames while we are still handling the previous BeginFrame. | 
| 2139 args.frame_time += base::TimeDelta::FromSeconds(1); | 2228 args.frame_time += base::TimeDelta::FromSeconds(1); | 
| 2140 fake_external_begin_frame_source()->TestOnBeginFrame(args); | 2229 fake_external_begin_frame_source()->TestOnBeginFrame(args); | 
| 2141 args.frame_time += base::TimeDelta::FromSeconds(1); | 2230 args.frame_time += base::TimeDelta::FromSeconds(1); | 
| 2142 fake_external_begin_frame_source()->TestOnBeginFrame(args); | 2231 fake_external_begin_frame_source()->TestOnBeginFrame(args); | 
| 2143 | 2232 | 
| 2144 // If we don't swap on the deadline, we wait for the next BeginImplFrame. | 2233 // If we don't swap on the deadline, we wait for the next BeginImplFrame. | 
| 2145 client_->Reset(); | 2234 client_->Reset(); | 
| 2146 task_runner().RunPendingTasks(); // Run posted deadline. | 2235 task_runner().RunPendingTasks(); // Run posted deadline. | 
| 2147 EXPECT_NO_ACTION(client_); | 2236 EXPECT_NO_ACTION(client_); | 
| 2148 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | 2237 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePendingForTest()); | 
| 2149 EXPECT_TRUE(client_->needs_begin_frames()); | 2238 EXPECT_TRUE(client_->needs_begin_frames()); | 
| 2150 | 2239 | 
| 2151 // NotifyReadyToCommit should trigger the commit. | 2240 // NotifyReadyToCommit should trigger the commit. | 
| 2152 client_->Reset(); | 2241 client_->Reset(); | 
| 2153 scheduler_->NotifyBeginMainFrameStarted(); | 2242 scheduler_->NotifyBeginMainFrameStarted(); | 
| 2154 scheduler_->NotifyReadyToCommit(); | 2243 scheduler_->NotifyReadyToCommit(); | 
| 2155 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_); | 2244 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_); | 
| 2156 EXPECT_TRUE(client_->needs_begin_frames()); | 2245 EXPECT_TRUE(client_->needs_begin_frames()); | 
| 2157 | 2246 | 
| 2158 // BeginImplFrame should prepare the draw. | 2247 // BeginImplFrame should prepare the draw. | 
| 2159 client_->Reset(); | 2248 client_->Reset(); | 
| 2160 task_runner().RunPendingTasks(); // Run posted BeginRetroFrame. | 2249 task_runner().RunPendingTasks(); // Run posted BeginRetroFrame. | 
| 2161 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); | 2250 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); | 
| 2162 EXPECT_ACTION("ScheduledActionAnimate", client_, 1, 2); | 2251 EXPECT_ACTION("ScheduledActionAnimate", client_, 1, 2); | 
| 2163 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 2252 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePendingForTest()); | 
| 2164 EXPECT_TRUE(client_->needs_begin_frames()); | 2253 EXPECT_TRUE(client_->needs_begin_frames()); | 
| 2165 | 2254 | 
| 2166 client_->Reset(); | 2255 client_->Reset(); | 
| 2167 EXPECT_FALSE(scheduler_->IsBeginRetroFrameArgsEmpty()); | 2256 EXPECT_FALSE(scheduler_->IsBeginRetroFrameArgsEmpty()); | 
| 2168 scheduler_->DidLoseOutputSurface(); | 2257 scheduler_->DidLoseOutputSurface(); | 
| 2169 EXPECT_NO_ACTION(client_); | 2258 EXPECT_NO_ACTION(client_); | 
| 2170 EXPECT_TRUE(scheduler_->IsBeginRetroFrameArgsEmpty()); | 2259 EXPECT_TRUE(scheduler_->IsBeginRetroFrameArgsEmpty()); | 
| 2171 | 2260 | 
| 2172 // BeginImplFrame deadline should abort drawing. | 2261 // BeginImplFrame deadline should abort drawing. | 
| 2173 client_->Reset(); | 2262 client_->Reset(); | 
| 2174 task_runner().RunTasksWhile(client_->ImplFrameDeadlinePending(true)); | 2263 task_runner().RunTasksWhile(client_->ImplFrameDeadlinePending(true)); | 
| 2175 EXPECT_ACTION("ScheduledActionBeginOutputSurfaceCreation", client_, 0, 3); | 2264 EXPECT_ACTION("ScheduledActionBeginOutputSurfaceCreation", client_, 0, 3); | 
| 2176 EXPECT_ACTION("SetNeedsBeginFrames(false)", client_, 1, 3); | 2265 EXPECT_ACTION("SetNeedsBeginFrames(false)", client_, 1, 3); | 
| 2177 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 2, 3); | 2266 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 2, 3); | 
| 2178 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | 2267 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePendingForTest()); | 
| 2179 EXPECT_FALSE(client_->needs_begin_frames()); | 2268 EXPECT_FALSE(client_->needs_begin_frames()); | 
| 2180 | 2269 | 
| 2181 // No more BeginRetroFrame because BeginRetroFrame queue is cleared. | 2270 // No more BeginRetroFrame because BeginRetroFrame queue is cleared. | 
| 2182 client_->Reset(); | 2271 client_->Reset(); | 
| 2183 task_runner().RunPendingTasks(); | 2272 task_runner().RunPendingTasks(); | 
| 2184 EXPECT_NO_ACTION(client_); | 2273 EXPECT_NO_ACTION(client_); | 
| 2185 } | 2274 } | 
| 2186 | 2275 | 
| 2187 TEST_F(SchedulerTest, DidLoseOutputSurfaceWithSyntheticBeginFrameSource) { | 2276 TEST_F(SchedulerTest, DidLoseOutputSurfaceWithSyntheticBeginFrameSource) { | 
| 2188 SetUpScheduler(true); | 2277 SetUpScheduler(true); | 
| 2189 | 2278 | 
| 2190 // SetNeedsCommit should begin the frame on the next BeginImplFrame. | 2279 // SetNeedsCommit should begin the frame on the next BeginImplFrame. | 
| 2191 EXPECT_FALSE(scheduler_->frame_source().NeedsBeginFrames()); | 2280 EXPECT_FALSE(scheduler_->frame_source().NeedsBeginFrames()); | 
| 2192 scheduler_->SetNeedsCommit(); | 2281 scheduler_->SetNeedsCommit(); | 
| 2193 EXPECT_TRUE(scheduler_->frame_source().NeedsBeginFrames()); | 2282 EXPECT_TRUE(scheduler_->frame_source().NeedsBeginFrames()); | 
| 2194 | 2283 | 
| 2195 client_->Reset(); | 2284 client_->Reset(); | 
| 2196 AdvanceFrame(); | 2285 AdvanceFrame(); | 
| 2197 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); | 2286 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); | 
| 2198 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); | 2287 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); | 
| 2199 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 2288 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePendingForTest()); | 
| 2200 EXPECT_TRUE(scheduler_->frame_source().NeedsBeginFrames()); | 2289 EXPECT_TRUE(scheduler_->frame_source().NeedsBeginFrames()); | 
| 2201 | 2290 | 
| 2202 // NotifyReadyToCommit should trigger the commit. | 2291 // NotifyReadyToCommit should trigger the commit. | 
| 2203 client_->Reset(); | 2292 client_->Reset(); | 
| 2204 scheduler_->NotifyBeginMainFrameStarted(); | 2293 scheduler_->NotifyBeginMainFrameStarted(); | 
| 2205 scheduler_->NotifyReadyToCommit(); | 2294 scheduler_->NotifyReadyToCommit(); | 
| 2206 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_); | 2295 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_); | 
| 2207 EXPECT_TRUE(scheduler_->frame_source().NeedsBeginFrames()); | 2296 EXPECT_TRUE(scheduler_->frame_source().NeedsBeginFrames()); | 
| 2208 | 2297 | 
| 2209 client_->Reset(); | 2298 client_->Reset(); | 
| (...skipping 14 matching lines...) Expand all Loading... | |
| 2224 SetUpScheduler(true); | 2313 SetUpScheduler(true); | 
| 2225 | 2314 | 
| 2226 // SetNeedsCommit should begin the frame. | 2315 // SetNeedsCommit should begin the frame. | 
| 2227 scheduler_->SetNeedsCommit(); | 2316 scheduler_->SetNeedsCommit(); | 
| 2228 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client_); | 2317 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client_); | 
| 2229 | 2318 | 
| 2230 client_->Reset(); | 2319 client_->Reset(); | 
| 2231 EXPECT_SCOPED(AdvanceFrame()); | 2320 EXPECT_SCOPED(AdvanceFrame()); | 
| 2232 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); | 2321 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); | 
| 2233 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); | 2322 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); | 
| 2234 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 2323 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePendingForTest()); | 
| 2235 | 2324 | 
| 2236 client_->Reset(); | 2325 client_->Reset(); | 
| 2237 scheduler_->NotifyBeginMainFrameStarted(); | 2326 scheduler_->NotifyBeginMainFrameStarted(); | 
| 2238 scheduler_->NotifyReadyToCommit(); | 2327 scheduler_->NotifyReadyToCommit(); | 
| 2239 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_); | 2328 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_); | 
| 2240 | 2329 | 
| 2241 client_->Reset(); | 2330 client_->Reset(); | 
| 2242 task_runner().RunTasksWhile(client_->ImplFrameDeadlinePending(true)); | 2331 task_runner().RunTasksWhile(client_->ImplFrameDeadlinePending(true)); | 
| 2243 EXPECT_ACTION("ScheduledActionAnimate", client_, 0, 2); | 2332 EXPECT_ACTION("ScheduledActionAnimate", client_, 0, 2); | 
| 2244 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 1, 2); | 2333 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 1, 2); | 
| (...skipping 12 matching lines...) Expand all Loading... | |
| 2257 SetUpScheduler(true); | 2346 SetUpScheduler(true); | 
| 2258 | 2347 | 
| 2259 // SetNeedsCommit should begin the frame. | 2348 // SetNeedsCommit should begin the frame. | 
| 2260 scheduler_->SetNeedsCommit(); | 2349 scheduler_->SetNeedsCommit(); | 
| 2261 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client_); | 2350 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client_); | 
| 2262 | 2351 | 
| 2263 client_->Reset(); | 2352 client_->Reset(); | 
| 2264 EXPECT_SCOPED(AdvanceFrame()); | 2353 EXPECT_SCOPED(AdvanceFrame()); | 
| 2265 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); | 2354 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); | 
| 2266 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); | 2355 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); | 
| 2267 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 2356 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePendingForTest()); | 
| 2268 | 2357 | 
| 2269 client_->Reset(); | 2358 client_->Reset(); | 
| 2270 scheduler_->NotifyBeginMainFrameStarted(); | 2359 scheduler_->NotifyBeginMainFrameStarted(); | 
| 2271 scheduler_->NotifyReadyToCommit(); | 2360 scheduler_->NotifyReadyToCommit(); | 
| 2272 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_); | 2361 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_); | 
| 2273 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 2362 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePendingForTest()); | 
| 2274 | 2363 | 
| 2275 client_->Reset(); | 2364 client_->Reset(); | 
| 2276 scheduler_->SetVisible(false); | 2365 scheduler_->SetVisible(false); | 
| 2277 task_runner().RunPendingTasks(); // Run posted deadline. | 2366 task_runner().RunPendingTasks(); // Run posted deadline. | 
| 2278 | 2367 | 
| 2279 // Sync tree should be forced to activate. | 2368 // Sync tree should be forced to activate. | 
| 2280 EXPECT_ACTION("ScheduledActionActivateSyncTree", client_, 0, 3); | 2369 EXPECT_ACTION("ScheduledActionActivateSyncTree", client_, 0, 3); | 
| 2281 EXPECT_ACTION("SetNeedsBeginFrames(false)", client_, 1, 3); | 2370 EXPECT_ACTION("SetNeedsBeginFrames(false)", client_, 1, 3); | 
| 2282 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 2, 3); | 2371 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 2, 3); | 
| 2283 } | 2372 } | 
| 2284 | 2373 | 
| 2285 // Tests to ensure frame sources can be successfully changed while drawing. | 2374 // Tests to ensure frame sources can be successfully changed while drawing. | 
| 2286 TEST_F(SchedulerTest, SwitchFrameSourceToUnthrottled) { | 2375 TEST_F(SchedulerTest, SwitchFrameSourceToUnthrottled) { | 
| 2287 scheduler_settings_.use_external_begin_frame_source = true; | 2376 scheduler_settings_.use_external_begin_frame_source = true; | 
| 2288 SetUpScheduler(true); | 2377 SetUpScheduler(true); | 
| 2289 | 2378 | 
| 2290 // SetNeedsRedraw should begin the frame on the next BeginImplFrame. | 2379 // SetNeedsRedraw should begin the frame on the next BeginImplFrame. | 
| 2291 scheduler_->SetNeedsRedraw(); | 2380 scheduler_->SetNeedsRedraw(); | 
| 2292 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client_); | 2381 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client_); | 
| 2293 client_->Reset(); | 2382 client_->Reset(); | 
| 2294 | 2383 | 
| 2295 EXPECT_SCOPED(AdvanceFrame()); | 2384 EXPECT_SCOPED(AdvanceFrame()); | 
| 2296 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); | 2385 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); | 
| 2297 EXPECT_ACTION("ScheduledActionAnimate", client_, 1, 2); | 2386 EXPECT_ACTION("ScheduledActionAnimate", client_, 1, 2); | 
| 2298 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 2387 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePendingForTest()); | 
| 2299 EXPECT_TRUE(client_->needs_begin_frames()); | 2388 EXPECT_TRUE(client_->needs_begin_frames()); | 
| 2300 client_->Reset(); | 2389 client_->Reset(); | 
| 2301 task_runner().RunPendingTasks(); // Run posted deadline. | 2390 task_runner().RunPendingTasks(); // Run posted deadline. | 
| 2302 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 0, 1); | 2391 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 0, 1); | 
| 2303 scheduler_->SetNeedsRedraw(); | 2392 scheduler_->SetNeedsRedraw(); | 
| 2304 | 2393 | 
| 2305 // Switch to an unthrottled frame source. | 2394 // Switch to an unthrottled frame source. | 
| 2306 scheduler_->SetThrottleFrameProduction(false); | 2395 scheduler_->SetThrottleFrameProduction(false); | 
| 2307 client_->Reset(); | 2396 client_->Reset(); | 
| 2308 | 2397 | 
| 2309 // Unthrottled frame source will immediately begin a new frame. | 2398 // Unthrottled frame source will immediately begin a new frame. | 
| 2310 task_runner().RunPendingTasks(); // Run posted BeginFrame. | 2399 task_runner().RunPendingTasks(); // Run posted BeginFrame. | 
| 2311 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); | 2400 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); | 
| 2312 EXPECT_ACTION("ScheduledActionAnimate", client_, 1, 2); | 2401 EXPECT_ACTION("ScheduledActionAnimate", client_, 1, 2); | 
| 2313 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 2402 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePendingForTest()); | 
| 2314 client_->Reset(); | 2403 client_->Reset(); | 
| 2315 | 2404 | 
| 2316 // If we don't swap on the deadline, we wait for the next BeginFrame. | 2405 // If we don't swap on the deadline, we wait for the next BeginFrame. | 
| 2317 task_runner().RunPendingTasks(); // Run posted deadline. | 2406 task_runner().RunPendingTasks(); // Run posted deadline. | 
| 2318 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 0, 1); | 2407 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 0, 1); | 
| 2319 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | 2408 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePendingForTest()); | 
| 2320 client_->Reset(); | 2409 client_->Reset(); | 
| 2321 } | 2410 } | 
| 2322 | 2411 | 
| 2323 // Tests to ensure frame sources can be successfully changed while a frame | 2412 // Tests to ensure frame sources can be successfully changed while a frame | 
| 2324 // deadline is pending. | 2413 // deadline is pending. | 
| 2325 TEST_F(SchedulerTest, SwitchFrameSourceToUnthrottledBeforeDeadline) { | 2414 TEST_F(SchedulerTest, SwitchFrameSourceToUnthrottledBeforeDeadline) { | 
| 2326 scheduler_settings_.use_external_begin_frame_source = true; | 2415 scheduler_settings_.use_external_begin_frame_source = true; | 
| 2327 SetUpScheduler(true); | 2416 SetUpScheduler(true); | 
| 2328 | 2417 | 
| 2329 // SetNeedsRedraw should begin the frame on the next BeginImplFrame. | 2418 // SetNeedsRedraw should begin the frame on the next BeginImplFrame. | 
| 2330 scheduler_->SetNeedsRedraw(); | 2419 scheduler_->SetNeedsRedraw(); | 
| 2331 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client_); | 2420 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client_); | 
| 2332 client_->Reset(); | 2421 client_->Reset(); | 
| 2333 | 2422 | 
| 2334 EXPECT_SCOPED(AdvanceFrame()); | 2423 EXPECT_SCOPED(AdvanceFrame()); | 
| 2335 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); | 2424 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); | 
| 2336 EXPECT_ACTION("ScheduledActionAnimate", client_, 1, 2); | 2425 EXPECT_ACTION("ScheduledActionAnimate", client_, 1, 2); | 
| 2337 | 2426 | 
| 2338 // Switch to an unthrottled frame source before the frame deadline is hit. | 2427 // Switch to an unthrottled frame source before the frame deadline is hit. | 
| 2339 scheduler_->SetThrottleFrameProduction(false); | 2428 scheduler_->SetThrottleFrameProduction(false); | 
| 2340 client_->Reset(); | 2429 client_->Reset(); | 
| 2341 | 2430 | 
| 2342 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 2431 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePendingForTest()); | 
| 2343 EXPECT_TRUE(client_->needs_begin_frames()); | 2432 EXPECT_TRUE(client_->needs_begin_frames()); | 
| 2344 client_->Reset(); | 2433 client_->Reset(); | 
| 2345 | 2434 | 
| 2346 task_runner().RunPendingTasks(); // Run posted deadline and BeginFrame. | 2435 task_runner().RunPendingTasks(); // Run posted deadline and BeginFrame. | 
| 2347 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 0, 2); | 2436 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 0, 2); | 
| 2348 // Unthrottled frame source will immediately begin a new frame. | 2437 // Unthrottled frame source will immediately begin a new frame. | 
| 2349 EXPECT_ACTION("WillBeginImplFrame", client_, 1, 2); | 2438 EXPECT_ACTION("WillBeginImplFrame", client_, 1, 2); | 
| 2350 scheduler_->SetNeedsRedraw(); | 2439 scheduler_->SetNeedsRedraw(); | 
| 2351 client_->Reset(); | 2440 client_->Reset(); | 
| 2352 | 2441 | 
| 2353 task_runner().RunPendingTasks(); // Run posted deadline. | 2442 task_runner().RunPendingTasks(); // Run posted deadline. | 
| 2354 EXPECT_ACTION("ScheduledActionAnimate", client_, 0, 2); | 2443 EXPECT_ACTION("ScheduledActionAnimate", client_, 0, 2); | 
| 2355 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 1, 2); | 2444 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 1, 2); | 
| 2356 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | 2445 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePendingForTest()); | 
| 2357 client_->Reset(); | 2446 client_->Reset(); | 
| 2358 } | 2447 } | 
| 2359 | 2448 | 
| 2360 // Tests to ensure that the active frame source can successfully be changed from | 2449 // Tests to ensure that the active frame source can successfully be changed from | 
| 2361 // unthrottled to throttled. | 2450 // unthrottled to throttled. | 
| 2362 TEST_F(SchedulerTest, SwitchFrameSourceToThrottled) { | 2451 TEST_F(SchedulerTest, SwitchFrameSourceToThrottled) { | 
| 2363 scheduler_settings_.throttle_frame_production = false; | 2452 scheduler_settings_.throttle_frame_production = false; | 
| 2364 scheduler_settings_.use_external_begin_frame_source = true; | 2453 scheduler_settings_.use_external_begin_frame_source = true; | 
| 2365 SetUpScheduler(true); | 2454 SetUpScheduler(true); | 
| 2366 | 2455 | 
| 2367 scheduler_->SetNeedsRedraw(); | 2456 scheduler_->SetNeedsRedraw(); | 
| 2368 EXPECT_NO_ACTION(client_); | 2457 EXPECT_NO_ACTION(client_); | 
| 2369 client_->Reset(); | 2458 client_->Reset(); | 
| 2370 | 2459 | 
| 2371 task_runner().RunPendingTasks(); // Run posted BeginFrame. | 2460 task_runner().RunPendingTasks(); // Run posted BeginFrame. | 
| 2372 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); | 2461 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); | 
| 2373 EXPECT_ACTION("ScheduledActionAnimate", client_, 1, 2); | 2462 EXPECT_ACTION("ScheduledActionAnimate", client_, 1, 2); | 
| 2374 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 2463 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePendingForTest()); | 
| 2375 client_->Reset(); | 2464 client_->Reset(); | 
| 2376 | 2465 | 
| 2377 task_runner().RunPendingTasks(); // Run posted deadline. | 2466 task_runner().RunPendingTasks(); // Run posted deadline. | 
| 2378 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 0, 1); | 2467 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 0, 1); | 
| 2379 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | 2468 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePendingForTest()); | 
| 2380 client_->Reset(); | 2469 client_->Reset(); | 
| 2381 | 2470 | 
| 2382 // Switch to a throttled frame source. | 2471 // Switch to a throttled frame source. | 
| 2383 scheduler_->SetThrottleFrameProduction(true); | 2472 scheduler_->SetThrottleFrameProduction(true); | 
| 2384 client_->Reset(); | 2473 client_->Reset(); | 
| 2385 | 2474 | 
| 2386 // SetNeedsRedraw should begin the frame on the next BeginImplFrame. | 2475 // SetNeedsRedraw should begin the frame on the next BeginImplFrame. | 
| 2387 scheduler_->SetNeedsRedraw(); | 2476 scheduler_->SetNeedsRedraw(); | 
| 2388 task_runner().RunPendingTasks(); | 2477 task_runner().RunPendingTasks(); | 
| 2389 EXPECT_NO_ACTION(client_); | 2478 EXPECT_NO_ACTION(client_); | 
| 2390 client_->Reset(); | 2479 client_->Reset(); | 
| 2391 | 2480 | 
| 2392 EXPECT_SCOPED(AdvanceFrame()); | 2481 EXPECT_SCOPED(AdvanceFrame()); | 
| 2393 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); | 2482 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); | 
| 2394 EXPECT_ACTION("ScheduledActionAnimate", client_, 1, 2); | 2483 EXPECT_ACTION("ScheduledActionAnimate", client_, 1, 2); | 
| 2395 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 2484 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePendingForTest()); | 
| 2396 EXPECT_TRUE(client_->needs_begin_frames()); | 2485 EXPECT_TRUE(client_->needs_begin_frames()); | 
| 2397 client_->Reset(); | 2486 client_->Reset(); | 
| 2398 task_runner().RunPendingTasks(); // Run posted deadline. | 2487 task_runner().RunPendingTasks(); // Run posted deadline. | 
| 2399 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 0, 1); | 2488 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 0, 1); | 
| 2400 } | 2489 } | 
| 2401 | 2490 | 
| 2402 // Tests to ensure that we send a BeginMainFrameNotExpectedSoon when expected. | 2491 // Tests to ensure that we send a BeginMainFrameNotExpectedSoon when expected. | 
| 2403 TEST_F(SchedulerTest, SendBeginMainFrameNotExpectedSoon) { | 2492 TEST_F(SchedulerTest, SendBeginMainFrameNotExpectedSoon) { | 
| 2404 scheduler_settings_.use_external_begin_frame_source = true; | 2493 scheduler_settings_.use_external_begin_frame_source = true; | 
| 2405 SetUpScheduler(true); | 2494 SetUpScheduler(true); | 
| (...skipping 12 matching lines...) Expand all Loading... | |
| 2418 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 5); | 2507 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 5); | 
| 2419 EXPECT_ACTION("ScheduledActionCommit", client_, 2, 5); | 2508 EXPECT_ACTION("ScheduledActionCommit", client_, 2, 5); | 
| 2420 EXPECT_ACTION("ScheduledActionAnimate", client_, 3, 5); | 2509 EXPECT_ACTION("ScheduledActionAnimate", client_, 3, 5); | 
| 2421 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 4, 5); | 2510 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 4, 5); | 
| 2422 client_->Reset(); | 2511 client_->Reset(); | 
| 2423 | 2512 | 
| 2424 // The following BeginImplFrame deadline should SetNeedsBeginFrame(false) | 2513 // The following BeginImplFrame deadline should SetNeedsBeginFrame(false) | 
| 2425 // and send a SendBeginMainFrameNotExpectedSoon. | 2514 // and send a SendBeginMainFrameNotExpectedSoon. | 
| 2426 EXPECT_SCOPED(AdvanceFrame()); | 2515 EXPECT_SCOPED(AdvanceFrame()); | 
| 2427 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client_); | 2516 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client_); | 
| 2428 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 2517 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePendingForTest()); | 
| 2429 client_->Reset(); | 2518 client_->Reset(); | 
| 2430 | 2519 | 
| 2431 task_runner().RunPendingTasks(); // Run posted deadline. | 2520 task_runner().RunPendingTasks(); // Run posted deadline. | 
| 2432 EXPECT_ACTION("SetNeedsBeginFrames(false)", client_, 0, 2); | 2521 EXPECT_ACTION("SetNeedsBeginFrames(false)", client_, 0, 2); | 
| 2433 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 1, 2); | 2522 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 1, 2); | 
| 2434 client_->Reset(); | 2523 client_->Reset(); | 
| 2435 } | 2524 } | 
| 2436 | 2525 | 
| 2437 TEST_F(SchedulerTest, SynchronousCompositorAnimation) { | 2526 TEST_F(SchedulerTest, SynchronousCompositorAnimation) { | 
| 2438 scheduler_settings_.using_synchronous_renderer_compositor = true; | 2527 scheduler_settings_.using_synchronous_renderer_compositor = true; | 
| 2439 scheduler_settings_.use_external_begin_frame_source = true; | 2528 scheduler_settings_.use_external_begin_frame_source = true; | 
| 2440 scheduler_settings_.impl_side_painting = true; | 2529 scheduler_settings_.impl_side_painting = true; | 
| 2441 SetUpScheduler(true); | 2530 SetUpScheduler(true); | 
| 2442 | 2531 | 
| 2443 scheduler_->SetNeedsAnimate(); | 2532 scheduler_->SetNeedsAnimate(); | 
| 2444 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client_); | 2533 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client_); | 
| 2445 client_->Reset(); | 2534 client_->Reset(); | 
| 2446 | 2535 | 
| 2447 // Next vsync. | 2536 // Next vsync. | 
| 2448 AdvanceFrame(); | 2537 AdvanceFrame(); | 
| 2449 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 3); | 2538 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 3); | 
| 2450 EXPECT_ACTION("ScheduledActionAnimate", client_, 1, 3); | 2539 EXPECT_ACTION("ScheduledActionAnimate", client_, 1, 3); | 
| 2451 EXPECT_ACTION("ScheduledActionInvalidateOutputSurface", client_, 2, 3); | 2540 EXPECT_ACTION("ScheduledActionInvalidateOutputSurface", client_, 2, 3); | 
| 2452 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | 2541 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePendingForTest()); | 
| 2453 client_->Reset(); | 2542 client_->Reset(); | 
| 2454 | 2543 | 
| 2455 // Continue with animation. | 2544 // Continue with animation. | 
| 2456 scheduler_->SetNeedsAnimate(); | 2545 scheduler_->SetNeedsAnimate(); | 
| 2457 EXPECT_NO_ACTION(client_); | 2546 EXPECT_NO_ACTION(client_); | 
| 2458 | 2547 | 
| 2459 // Android onDraw. | 2548 // Android onDraw. | 
| 2460 scheduler_->SetNeedsRedraw(); | 2549 scheduler_->SetNeedsRedraw(); | 
| 2461 scheduler_->OnDrawForOutputSurface(); | 2550 scheduler_->OnDrawForOutputSurface(); | 
| 2462 EXPECT_SINGLE_ACTION("ScheduledActionDrawAndSwapIfPossible", client_); | 2551 EXPECT_SINGLE_ACTION("ScheduledActionDrawAndSwapIfPossible", client_); | 
| 2463 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | 2552 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePendingForTest()); | 
| 2464 client_->Reset(); | 2553 client_->Reset(); | 
| 2465 | 2554 | 
| 2466 // Next vsync. | 2555 // Next vsync. | 
| 2467 AdvanceFrame(); | 2556 AdvanceFrame(); | 
| 2468 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 3); | 2557 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 3); | 
| 2469 EXPECT_ACTION("ScheduledActionAnimate", client_, 1, 3); | 2558 EXPECT_ACTION("ScheduledActionAnimate", client_, 1, 3); | 
| 2470 EXPECT_ACTION("ScheduledActionInvalidateOutputSurface", client_, 2, 3); | 2559 EXPECT_ACTION("ScheduledActionInvalidateOutputSurface", client_, 2, 3); | 
| 2471 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | 2560 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePendingForTest()); | 
| 2472 client_->Reset(); | 2561 client_->Reset(); | 
| 2473 | 2562 | 
| 2474 // Android onDraw. | 2563 // Android onDraw. | 
| 2475 scheduler_->SetNeedsRedraw(); | 2564 scheduler_->SetNeedsRedraw(); | 
| 2476 scheduler_->OnDrawForOutputSurface(); | 2565 scheduler_->OnDrawForOutputSurface(); | 
| 2477 EXPECT_SINGLE_ACTION("ScheduledActionDrawAndSwapIfPossible", client_); | 2566 EXPECT_SINGLE_ACTION("ScheduledActionDrawAndSwapIfPossible", client_); | 
| 2478 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | 2567 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePendingForTest()); | 
| 2479 client_->Reset(); | 2568 client_->Reset(); | 
| 2480 | 2569 | 
| 2481 // Idle on next vsync. | 2570 // Idle on next vsync. | 
| 2482 AdvanceFrame(); | 2571 AdvanceFrame(); | 
| 2483 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 3); | 2572 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 3); | 
| 2484 EXPECT_ACTION("SetNeedsBeginFrames(false)", client_, 1, 3); | 2573 EXPECT_ACTION("SetNeedsBeginFrames(false)", client_, 1, 3); | 
| 2485 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 2, 3); | 2574 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 2, 3); | 
| 2486 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | 2575 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePendingForTest()); | 
| 2487 client_->Reset(); | 2576 client_->Reset(); | 
| 2488 } | 2577 } | 
| 2489 | 2578 | 
| 2490 TEST_F(SchedulerTest, SynchronousCompositorOnDrawDuringIdle) { | 2579 TEST_F(SchedulerTest, SynchronousCompositorOnDrawDuringIdle) { | 
| 2491 scheduler_settings_.using_synchronous_renderer_compositor = true; | 2580 scheduler_settings_.using_synchronous_renderer_compositor = true; | 
| 2492 scheduler_settings_.use_external_begin_frame_source = true; | 2581 scheduler_settings_.use_external_begin_frame_source = true; | 
| 2493 scheduler_settings_.impl_side_painting = true; | 2582 scheduler_settings_.impl_side_painting = true; | 
| 2494 SetUpScheduler(true); | 2583 SetUpScheduler(true); | 
| 2495 | 2584 | 
| 2496 scheduler_->SetNeedsRedraw(); | 2585 scheduler_->SetNeedsRedraw(); | 
| 2497 scheduler_->OnDrawForOutputSurface(); | 2586 scheduler_->OnDrawForOutputSurface(); | 
| 2498 EXPECT_ACTION("SetNeedsBeginFrames(true)", client_, 0, 3); | 2587 EXPECT_ACTION("SetNeedsBeginFrames(true)", client_, 0, 3); | 
| 2499 EXPECT_ACTION("ScheduledActionAnimate", client_, 1, 3); | 2588 EXPECT_ACTION("ScheduledActionAnimate", client_, 1, 3); | 
| 2500 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 2, 3); | 2589 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 2, 3); | 
| 2501 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | 2590 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePendingForTest()); | 
| 2502 client_->Reset(); | 2591 client_->Reset(); | 
| 2503 | 2592 | 
| 2504 // Idle on next vsync. | 2593 // Idle on next vsync. | 
| 2505 AdvanceFrame(); | 2594 AdvanceFrame(); | 
| 2506 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 3); | 2595 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 3); | 
| 2507 EXPECT_ACTION("SetNeedsBeginFrames(false)", client_, 1, 3); | 2596 EXPECT_ACTION("SetNeedsBeginFrames(false)", client_, 1, 3); | 
| 2508 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 2, 3); | 2597 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 2, 3); | 
| 2509 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | 2598 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePendingForTest()); | 
| 2510 client_->Reset(); | 2599 client_->Reset(); | 
| 2511 } | 2600 } | 
| 2512 | 2601 | 
| 2513 TEST_F(SchedulerTest, SynchronousCompositorCommit) { | 2602 TEST_F(SchedulerTest, SynchronousCompositorCommit) { | 
| 2514 scheduler_settings_.using_synchronous_renderer_compositor = true; | 2603 scheduler_settings_.using_synchronous_renderer_compositor = true; | 
| 2515 scheduler_settings_.use_external_begin_frame_source = true; | 2604 scheduler_settings_.use_external_begin_frame_source = true; | 
| 2516 scheduler_settings_.impl_side_painting = true; | 2605 scheduler_settings_.impl_side_painting = true; | 
| 2517 SetUpScheduler(true); | 2606 SetUpScheduler(true); | 
| 2518 | 2607 | 
| 2519 scheduler_->SetNeedsCommit(); | 2608 scheduler_->SetNeedsCommit(); | 
| 2520 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client_); | 2609 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client_); | 
| 2521 client_->Reset(); | 2610 client_->Reset(); | 
| 2522 | 2611 | 
| 2523 // Next vsync. | 2612 // Next vsync. | 
| 2524 AdvanceFrame(); | 2613 AdvanceFrame(); | 
| 2525 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); | 2614 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); | 
| 2526 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); | 2615 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); | 
| 2527 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | 2616 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePendingForTest()); | 
| 2528 client_->Reset(); | 2617 client_->Reset(); | 
| 2529 | 2618 | 
| 2530 scheduler_->NotifyBeginMainFrameStarted(); | 2619 scheduler_->NotifyBeginMainFrameStarted(); | 
| 2531 EXPECT_NO_ACTION(client_); | 2620 EXPECT_NO_ACTION(client_); | 
| 2532 | 2621 | 
| 2533 // Next vsync. | 2622 // Next vsync. | 
| 2534 AdvanceFrame(); | 2623 AdvanceFrame(); | 
| 2535 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client_); | 2624 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client_); | 
| 2536 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | 2625 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePendingForTest()); | 
| 2537 client_->Reset(); | 2626 client_->Reset(); | 
| 2538 | 2627 | 
| 2539 scheduler_->NotifyReadyToCommit(); | 2628 scheduler_->NotifyReadyToCommit(); | 
| 2540 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_); | 2629 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_); | 
| 2541 client_->Reset(); | 2630 client_->Reset(); | 
| 2542 | 2631 | 
| 2543 scheduler_->NotifyReadyToActivate(); | 2632 scheduler_->NotifyReadyToActivate(); | 
| 2544 EXPECT_SINGLE_ACTION("ScheduledActionActivateSyncTree", client_); | 2633 EXPECT_SINGLE_ACTION("ScheduledActionActivateSyncTree", client_); | 
| 2545 client_->Reset(); | 2634 client_->Reset(); | 
| 2546 | 2635 | 
| 2547 // Next vsync. | 2636 // Next vsync. | 
| 2548 AdvanceFrame(); | 2637 AdvanceFrame(); | 
| 2549 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 3); | 2638 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 3); | 
| 2550 EXPECT_ACTION("ScheduledActionAnimate", client_, 1, 3); | 2639 EXPECT_ACTION("ScheduledActionAnimate", client_, 1, 3); | 
| 2551 EXPECT_ACTION("ScheduledActionInvalidateOutputSurface", client_, 2, 3); | 2640 EXPECT_ACTION("ScheduledActionInvalidateOutputSurface", client_, 2, 3); | 
| 2552 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | 2641 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePendingForTest()); | 
| 2553 client_->Reset(); | 2642 client_->Reset(); | 
| 2554 | 2643 | 
| 2555 // Android onDraw. | 2644 // Android onDraw. | 
| 2556 scheduler_->SetNeedsRedraw(); | 2645 scheduler_->SetNeedsRedraw(); | 
| 2557 scheduler_->OnDrawForOutputSurface(); | 2646 scheduler_->OnDrawForOutputSurface(); | 
| 2558 EXPECT_SINGLE_ACTION("ScheduledActionDrawAndSwapIfPossible", client_); | 2647 EXPECT_SINGLE_ACTION("ScheduledActionDrawAndSwapIfPossible", client_); | 
| 2559 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | 2648 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePendingForTest()); | 
| 2560 client_->Reset(); | 2649 client_->Reset(); | 
| 2561 | 2650 | 
| 2562 // Idle on next vsync. | 2651 // Idle on next vsync. | 
| 2563 AdvanceFrame(); | 2652 AdvanceFrame(); | 
| 2564 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 3); | 2653 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 3); | 
| 2565 EXPECT_ACTION("SetNeedsBeginFrames(false)", client_, 1, 3); | 2654 EXPECT_ACTION("SetNeedsBeginFrames(false)", client_, 1, 3); | 
| 2566 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 2, 3); | 2655 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 2, 3); | 
| 2567 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | 2656 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePendingForTest()); | 
| 2568 client_->Reset(); | 2657 client_->Reset(); | 
| 2569 } | 2658 } | 
| 2570 | 2659 | 
| 2571 TEST_F(SchedulerTest, SynchronousCompositorDoubleCommitWithoutDraw) { | 2660 TEST_F(SchedulerTest, SynchronousCompositorDoubleCommitWithoutDraw) { | 
| 2572 scheduler_settings_.using_synchronous_renderer_compositor = true; | 2661 scheduler_settings_.using_synchronous_renderer_compositor = true; | 
| 2573 scheduler_settings_.use_external_begin_frame_source = true; | 2662 scheduler_settings_.use_external_begin_frame_source = true; | 
| 2574 scheduler_settings_.impl_side_painting = true; | 2663 scheduler_settings_.impl_side_painting = true; | 
| 2575 SetUpScheduler(true); | 2664 SetUpScheduler(true); | 
| 2576 | 2665 | 
| 2577 scheduler_->SetNeedsCommit(); | 2666 scheduler_->SetNeedsCommit(); | 
| 2578 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client_); | 2667 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client_); | 
| 2579 client_->Reset(); | 2668 client_->Reset(); | 
| 2580 | 2669 | 
| 2581 // Next vsync. | 2670 // Next vsync. | 
| 2582 AdvanceFrame(); | 2671 AdvanceFrame(); | 
| 2583 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); | 2672 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); | 
| 2584 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); | 2673 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); | 
| 2585 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | 2674 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePendingForTest()); | 
| 2586 client_->Reset(); | 2675 client_->Reset(); | 
| 2587 | 2676 | 
| 2588 scheduler_->NotifyBeginMainFrameStarted(); | 2677 scheduler_->NotifyBeginMainFrameStarted(); | 
| 2589 EXPECT_NO_ACTION(client_); | 2678 EXPECT_NO_ACTION(client_); | 
| 2590 | 2679 | 
| 2591 scheduler_->NotifyReadyToCommit(); | 2680 scheduler_->NotifyReadyToCommit(); | 
| 2592 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_); | 2681 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_); | 
| 2593 client_->Reset(); | 2682 client_->Reset(); | 
| 2594 | 2683 | 
| 2595 scheduler_->NotifyReadyToActivate(); | 2684 scheduler_->NotifyReadyToActivate(); | 
| 2596 EXPECT_SINGLE_ACTION("ScheduledActionActivateSyncTree", client_); | 2685 EXPECT_SINGLE_ACTION("ScheduledActionActivateSyncTree", client_); | 
| 2597 client_->Reset(); | 2686 client_->Reset(); | 
| 2598 | 2687 | 
| 2599 // Ask for another commit. | 2688 // Ask for another commit. | 
| 2600 scheduler_->SetNeedsCommit(); | 2689 scheduler_->SetNeedsCommit(); | 
| 2601 | 2690 | 
| 2602 AdvanceFrame(); | 2691 AdvanceFrame(); | 
| 2603 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 4); | 2692 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 4); | 
| 2604 EXPECT_ACTION("ScheduledActionAnimate", client_, 1, 4); | 2693 EXPECT_ACTION("ScheduledActionAnimate", client_, 1, 4); | 
| 2605 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 2, 4); | 2694 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 2, 4); | 
| 2606 EXPECT_ACTION("ScheduledActionInvalidateOutputSurface", client_, 3, 4); | 2695 EXPECT_ACTION("ScheduledActionInvalidateOutputSurface", client_, 3, 4); | 
| 2607 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | 2696 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePendingForTest()); | 
| 2608 client_->Reset(); | 2697 client_->Reset(); | 
| 2609 | 2698 | 
| 2610 scheduler_->NotifyBeginMainFrameStarted(); | 2699 scheduler_->NotifyBeginMainFrameStarted(); | 
| 2611 EXPECT_NO_ACTION(client_); | 2700 EXPECT_NO_ACTION(client_); | 
| 2612 | 2701 | 
| 2613 // Allow new commit even though previous commit hasn't been drawn. | 2702 // Allow new commit even though previous commit hasn't been drawn. | 
| 2614 scheduler_->NotifyReadyToCommit(); | 2703 scheduler_->NotifyReadyToCommit(); | 
| 2615 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_); | 2704 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_); | 
| 2616 client_->Reset(); | 2705 client_->Reset(); | 
| 2617 } | 2706 } | 
| (...skipping 21 matching lines...) Expand all Loading... | |
| 2639 | 2728 | 
| 2640 // At the next BeginFrame, authoritative interval is used instead of previous | 2729 // At the next BeginFrame, authoritative interval is used instead of previous | 
| 2641 // interval. | 2730 // interval. | 
| 2642 EXPECT_NE(initial_interval, scheduler_->begin_impl_frame_args().interval); | 2731 EXPECT_NE(initial_interval, scheduler_->begin_impl_frame_args().interval); | 
| 2643 EXPECT_EQ(authoritative_interval, | 2732 EXPECT_EQ(authoritative_interval, | 
| 2644 scheduler_->begin_impl_frame_args().interval); | 2733 scheduler_->begin_impl_frame_args().interval); | 
| 2645 } | 2734 } | 
| 2646 | 2735 | 
| 2647 } // namespace | 2736 } // namespace | 
| 2648 } // namespace cc | 2737 } // namespace cc | 
| OLD | NEW |