Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2011 The Chromium Authors. All rights reserved. | 1 // Copyright 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "cc/scheduler/scheduler.h" | 5 #include "cc/scheduler/scheduler.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/debug/trace_event.h" | 10 #include "base/debug/trace_event.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/memory/scoped_vector.h" | 12 #include "base/memory/scoped_vector.h" |
| 13 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
| 14 #include "base/power_monitor/power_monitor.h" | 14 #include "base/power_monitor/power_monitor.h" |
| 15 #include "base/power_monitor/power_monitor_source.h" | 15 #include "base/power_monitor/power_monitor_source.h" |
| 16 #include "base/run_loop.h" | 16 #include "base/run_loop.h" |
| 17 #include "base/time/time.h" | 17 #include "base/time/time.h" |
| 18 #include "cc/test/begin_frame_args_test.h" | 18 #include "cc/test/begin_frame_args_test.h" |
| 19 #include "cc/test/ordered_simple_task_runner.h" | 19 #include "cc/test/ordered_simple_task_runner.h" |
| 20 #include "cc/test/scheduler_test_common.h" | 20 #include "cc/test/scheduler_test_common.h" |
| 21 #include "testing/gmock/include/gmock/gmock.h" | 21 #include "testing/gmock/include/gmock/gmock.h" |
| 22 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
| 23 | 23 |
| 24 using testing::Test; | |
|
simonhong
2015/01/15 14:10:00
Using using-directive is not preferred in chromium
Jimmy Jo
2015/01/16 06:39:50
Done.
| |
| 25 | |
| 24 #define EXPECT_ACTION(action, client, action_index, expected_num_actions) \ | 26 #define EXPECT_ACTION(action, client, action_index, expected_num_actions) \ |
| 25 do { \ | 27 client->ExpectAction(action, action_index, expected_num_actions, scheduler_); |
| 26 EXPECT_EQ(expected_num_actions, client.num_actions_()); \ | |
| 27 if (action_index >= 0) { \ | |
| 28 ASSERT_LT(action_index, client.num_actions_()) << scheduler; \ | |
| 29 EXPECT_STREQ(action, client.Action(action_index)); \ | |
| 30 } \ | |
| 31 for (int i = expected_num_actions; i < client.num_actions_(); ++i) \ | |
| 32 ADD_FAILURE() << "Unexpected action: " << client.Action(i) \ | |
| 33 << " with state:\n" << client.StateForAction(i); \ | |
| 34 } while (false) | |
| 35 | 28 |
| 36 #define EXPECT_NO_ACTION(client) EXPECT_ACTION("", client, -1, 0) | 29 #define EXPECT_NO_ACTION(client) EXPECT_ACTION("", client, -1, 0) |
| 37 | 30 |
| 38 #define EXPECT_SINGLE_ACTION(action, client) \ | 31 #define EXPECT_SINGLE_ACTION(action, client) \ |
| 39 EXPECT_ACTION(action, client, 0, 1) | 32 EXPECT_ACTION(action, client, 0, 1) |
| 40 | 33 |
| 41 #define EXPECT_SCOPED(statements) \ | 34 #define EXPECT_SCOPED(statements) \ |
| 42 { \ | 35 { \ |
| 43 SCOPED_TRACE(""); \ | 36 SCOPED_TRACE(""); \ |
| 44 statements; \ | 37 statements; \ |
| 45 } | 38 } |
| 46 | 39 |
| 47 #define CREATE_SCHEDULER_AND_INIT_SURFACE(settings) \ | 40 #define CREATE_SCHEDULER_AND_INIT_SURFACE(settings) \ |
|
simonhong
2015/01/15 14:10:00
This can be removed.
| |
| 48 TestScheduler* scheduler = client.CreateScheduler(settings); \ | 41 TestScheduler* scheduler = client.CreateScheduler(settings); \ |
| 49 EXPECT_SCOPED(client.InitializeOutputSurfaceAndFirstCommit(scheduler)); | 42 EXPECT_SCOPED(client.InitializeOutputSurfaceAndFirstCommit(scheduler)); |
| 50 | 43 |
| 51 namespace cc { | 44 namespace cc { |
| 52 namespace { | 45 namespace { |
| 53 | 46 |
| 54 class FakeSchedulerClient; | 47 class FakeSchedulerClient; |
|
simonhong
2015/01/15 14:10:00
This also can be removed.
| |
| 55 | 48 |
| 56 class FakeSchedulerClient : public SchedulerClient { | 49 class FakeSchedulerClient : public SchedulerClient { |
| 57 public: | 50 public: |
| 58 class FakeExternalBeginFrameSource : public BeginFrameSourceMixIn { | 51 class FakeExternalBeginFrameSource : public BeginFrameSourceMixIn { |
| 59 public: | 52 public: |
| 60 explicit FakeExternalBeginFrameSource(FakeSchedulerClient* client) | 53 explicit FakeExternalBeginFrameSource(FakeSchedulerClient* client) |
| 61 : client_(client) {} | 54 : client_(client) {} |
| 62 ~FakeExternalBeginFrameSource() override {} | 55 ~FakeExternalBeginFrameSource() override {} |
| 63 | 56 |
| 64 void OnNeedsBeginFramesChange(bool needs_begin_frames) override { | 57 void OnNeedsBeginFramesChange(bool needs_begin_frames) override { |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 168 // As this function contains EXPECT macros, to allow debugging it should be | 161 // As this function contains EXPECT macros, to allow debugging it should be |
| 169 // called inside EXPECT_SCOPED like so; | 162 // called inside EXPECT_SCOPED like so; |
| 170 // EXPECT_SCOPED(client.InitializeOutputSurfaceAndFirstCommit(scheduler)); | 163 // EXPECT_SCOPED(client.InitializeOutputSurfaceAndFirstCommit(scheduler)); |
| 171 void InitializeOutputSurfaceAndFirstCommit(TestScheduler* scheduler) { | 164 void InitializeOutputSurfaceAndFirstCommit(TestScheduler* scheduler) { |
| 172 TRACE_EVENT0("cc", | 165 TRACE_EVENT0("cc", |
| 173 "SchedulerUnitTest::InitializeOutputSurfaceAndFirstCommit"); | 166 "SchedulerUnitTest::InitializeOutputSurfaceAndFirstCommit"); |
| 174 DCHECK(scheduler); | 167 DCHECK(scheduler); |
| 175 | 168 |
| 176 // Check the client doesn't have any actions queued when calling this | 169 // Check the client doesn't have any actions queued when calling this |
| 177 // function. | 170 // function. |
| 178 EXPECT_NO_ACTION((*this)); | 171 ExpectAction("", -1, 0, scheduler); |
|
simonhong
2015/01/15 14:10:00
Using EXPECT_NO_ACTION is more self-descriptive.
Jimmy Jo
2015/01/16 06:39:50
Done.
| |
| 179 EXPECT_FALSE(needs_begin_frames()); | 172 EXPECT_FALSE(needs_begin_frames()); |
| 180 | 173 |
| 181 // Start the initial output surface creation. | 174 // Start the initial output surface creation. |
| 182 EXPECT_FALSE(scheduler->CanStart()); | 175 EXPECT_FALSE(scheduler->CanStart()); |
| 183 scheduler->SetCanStart(); | 176 scheduler->SetCanStart(); |
| 184 scheduler->SetVisible(true); | 177 scheduler->SetVisible(true); |
| 185 scheduler->SetCanDraw(true); | 178 scheduler->SetCanDraw(true); |
| 186 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", (*this)); | 179 ExpectAction("ScheduledActionBeginOutputSurfaceCreation", 0, 1, scheduler); |
|
simonhong
2015/01/15 14:10:00
In this case, EXPECT_SINGLE_ACTION() is more bette
Jimmy Jo
2015/01/16 06:39:50
Done.
| |
| 180 | |
| 187 Reset(); | 181 Reset(); |
| 188 | 182 |
| 189 // We don't see anything happening until the first impl frame. | 183 // We don't see anything happening until the first impl frame. |
| 190 scheduler->DidCreateAndInitializeOutputSurface(); | 184 scheduler->DidCreateAndInitializeOutputSurface(); |
| 191 scheduler->SetNeedsCommit(); | 185 scheduler->SetNeedsCommit(); |
| 192 EXPECT_TRUE(needs_begin_frames()); | 186 EXPECT_TRUE(needs_begin_frames()); |
| 193 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 187 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
| 194 Reset(); | 188 Reset(); |
| 195 | 189 |
| 196 { | 190 { |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 342 base::Callback<bool(void)> ImplFrameDeadlinePending(bool state) { | 336 base::Callback<bool(void)> ImplFrameDeadlinePending(bool state) { |
| 343 return base::Bind(&FakeSchedulerClient::ImplFrameDeadlinePendingCallback, | 337 return base::Bind(&FakeSchedulerClient::ImplFrameDeadlinePendingCallback, |
| 344 base::Unretained(this), | 338 base::Unretained(this), |
| 345 state); | 339 state); |
| 346 } | 340 } |
| 347 | 341 |
| 348 bool begin_frame_is_sent_to_children() const { | 342 bool begin_frame_is_sent_to_children() const { |
| 349 return begin_frame_is_sent_to_children_; | 343 return begin_frame_is_sent_to_children_; |
| 350 } | 344 } |
| 351 | 345 |
| 346 void ExpectAction(const char* action, | |
| 347 int action_index, | |
| 348 int expected_num_actions, | |
| 349 const TestScheduler* scheduler) { | |
| 350 EXPECT_EQ(expected_num_actions, num_actions_()); | |
| 351 if (action_index >= 0) { | |
| 352 ASSERT_LT(action_index, num_actions_()) << scheduler; | |
| 353 EXPECT_STREQ(action, Action(action_index)); | |
| 354 } | |
| 355 for (int i = expected_num_actions; i < num_actions_(); ++i) | |
| 356 ADD_FAILURE() << "Unexpected action: " << Action(i) << " with state:\n" | |
| 357 << StateForAction(i); | |
| 358 } | |
| 359 | |
| 352 protected: | 360 protected: |
| 353 bool ImplFrameDeadlinePendingCallback(bool state) { | 361 bool ImplFrameDeadlinePendingCallback(bool state) { |
| 354 return scheduler_->BeginImplFrameDeadlinePending() == state; | 362 return scheduler_->BeginImplFrameDeadlinePending() == state; |
| 355 } | 363 } |
| 356 | 364 |
| 357 void PushAction(const char* description) { | 365 void PushAction(const char* description) { |
| 358 actions_.push_back(description); | 366 actions_.push_back(description); |
| 359 states_.push_back(scheduler_->AsValue()); | 367 states_.push_back(scheduler_->AsValue()); |
| 360 } | 368 } |
| 361 | 369 |
| 362 bool draw_will_happen_; | 370 bool draw_will_happen_; |
| 363 bool swap_will_happen_if_draw_happens_; | 371 bool swap_will_happen_if_draw_happens_; |
| 364 bool automatic_swap_ack_; | 372 bool automatic_swap_ack_; |
| 365 int num_draws_; | 373 int num_draws_; |
| 366 bool log_anticipated_draw_time_change_; | 374 bool log_anticipated_draw_time_change_; |
| 367 bool begin_frame_is_sent_to_children_; | 375 bool begin_frame_is_sent_to_children_; |
| 368 base::TimeTicks posted_begin_impl_frame_deadline_; | 376 base::TimeTicks posted_begin_impl_frame_deadline_; |
| 369 std::vector<const char*> actions_; | 377 std::vector<const char*> actions_; |
| 370 std::vector<scoped_refptr<base::debug::ConvertableToTraceFormat>> states_; | 378 std::vector<scoped_refptr<base::debug::ConvertableToTraceFormat>> states_; |
| 371 scoped_refptr<TestNowSource> now_src_; | 379 scoped_refptr<TestNowSource> now_src_; |
| 372 scoped_refptr<OrderedSimpleTaskRunner> task_runner_; | 380 scoped_refptr<OrderedSimpleTaskRunner> task_runner_; |
| 373 FakeExternalBeginFrameSource* fake_external_begin_frame_source_; | 381 FakeExternalBeginFrameSource* fake_external_begin_frame_source_; |
| 374 FakePowerMonitorSource* fake_power_monitor_source_; | 382 FakePowerMonitorSource* fake_power_monitor_source_; |
| 375 base::PowerMonitor power_monitor_; | 383 base::PowerMonitor power_monitor_; |
| 376 scoped_ptr<TestScheduler> scheduler_; | 384 scoped_ptr<TestScheduler> scheduler_; |
| 377 }; | 385 }; |
| 378 | 386 |
| 379 TEST(SchedulerTest, InitializeOutputSurfaceDoesNotBeginImplFrame) { | 387 class SchedulerTest : public Test { |
| 380 FakeSchedulerClient client; | 388 public: |
| 381 SchedulerSettings scheduler_settings; | 389 SchedulerTest() {} |
| 382 scheduler_settings.use_external_begin_frame_source = true; | 390 ~SchedulerTest() override {} |
| 383 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings); | 391 |
| 384 scheduler->SetCanStart(); | 392 protected: |
| 385 scheduler->SetVisible(true); | 393 void CreateScheduler() { |
| 386 scheduler->SetCanDraw(true); | 394 scheduler_ = client_->CreateScheduler(scheduler_settings_); |
|
simonhong
2015/01/15 14:10:00
How about moving CreateScheduler() from FakeSchedu
Jimmy Jo
2015/01/16 06:39:50
Acknowledged.
| |
| 387 | 395 } |
| 388 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); | 396 |
| 389 client.Reset(); | 397 void CreateSchedulerAndInitSurface() { |
| 390 scheduler->DidCreateAndInitializeOutputSurface(); | 398 CreateScheduler(); |
| 391 EXPECT_NO_ACTION(client); | 399 EXPECT_SCOPED(client_->InitializeOutputSurfaceAndFirstCommit(scheduler_)); |
| 392 } | 400 } |
| 393 | 401 |
| 394 TEST(SchedulerTest, SendBeginFramesToChildren) { | 402 void SetUpScheduler(bool initSurface) { |
| 395 FakeSchedulerClient client; | 403 SetUpScheduler((new FakeSchedulerClient), initSurface); |
| 396 SchedulerSettings scheduler_settings; | 404 } |
| 397 scheduler_settings.use_external_begin_frame_source = true; | 405 |
| 398 scheduler_settings.forward_begin_frames_to_children = true; | 406 void SetUpScheduler(FakeSchedulerClient* client, bool initSurface) { |
| 399 | 407 client_.reset(client); |
| 400 CREATE_SCHEDULER_AND_INIT_SURFACE(scheduler_settings); | 408 if (initSurface) |
| 401 | 409 CreateSchedulerAndInitSurface(); |
| 402 EXPECT_FALSE(client.begin_frame_is_sent_to_children()); | 410 else |
| 403 scheduler->SetNeedsCommit(); | 411 CreateScheduler(); |
| 404 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client); | 412 } |
| 405 EXPECT_TRUE(client.needs_begin_frames()); | 413 |
| 406 | 414 void MainFrameInHighLatencyMode( |
| 407 scheduler->SetChildrenNeedBeginFrames(true); | 415 int64 begin_main_frame_to_commit_estimate_in_ms, |
| 408 | 416 int64 commit_to_activate_estimate_in_ms, |
| 409 client.Reset(); | 417 bool impl_latency_takes_priority, |
| 410 EXPECT_SCOPED(client.AdvanceFrame()); | 418 bool should_send_begin_main_frame); |
| 411 EXPECT_TRUE(client.begin_frame_is_sent_to_children()); | 419 void BeginFramesNotFromClient(bool use_external_begin_frame_source, |
| 412 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 420 bool throttle_frame_production); |
| 413 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 421 void BeginFramesNotFromClient_SwapThrottled( |
| 414 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); | 422 bool use_external_begin_frame_source, |
| 415 EXPECT_TRUE(client.needs_begin_frames()); | 423 bool throttle_frame_production); |
| 416 } | 424 void DidLoseOutputSurfaceAfterBeginFrameStartedWithHighLatency( |
| 417 | 425 bool impl_side_painting); |
| 418 TEST(SchedulerTest, SendBeginFramesToChildrenWithoutCommit) { | 426 void DidLoseOutputSurfaceAfterReadyToCommit(bool impl_side_painting); |
| 419 FakeSchedulerClient client; | 427 |
| 420 SchedulerSettings scheduler_settings; | 428 SchedulerSettings scheduler_settings_; |
| 421 scheduler_settings.use_external_begin_frame_source = true; | 429 TestScheduler* scheduler_; |
| 422 scheduler_settings.forward_begin_frames_to_children = true; | 430 scoped_ptr<FakeSchedulerClient> client_; |
| 423 | 431 }; |
| 424 CREATE_SCHEDULER_AND_INIT_SURFACE(scheduler_settings); | 432 |
| 425 | 433 TEST_F(SchedulerTest, InitializeOutputSurfaceDoesNotBeginImplFrame) { |
| 426 EXPECT_FALSE(client.needs_begin_frames()); | 434 scheduler_settings_.use_external_begin_frame_source = true; |
| 427 scheduler->SetChildrenNeedBeginFrames(true); | 435 SetUpScheduler(false); |
| 428 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client); | 436 scheduler_->SetCanStart(); |
| 429 EXPECT_TRUE(client.needs_begin_frames()); | 437 scheduler_->SetVisible(true); |
| 430 | 438 scheduler_->SetCanDraw(true); |
| 431 client.Reset(); | 439 |
| 432 EXPECT_SCOPED(client.AdvanceFrame()); | 440 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client_); |
| 433 EXPECT_TRUE(client.begin_frame_is_sent_to_children()); | 441 client_->Reset(); |
| 434 } | 442 scheduler_->DidCreateAndInitializeOutputSurface(); |
| 435 | 443 EXPECT_NO_ACTION(client_); |
| 436 TEST(SchedulerTest, RequestCommit) { | 444 } |
| 437 FakeSchedulerClient client; | 445 |
| 438 SchedulerSettings scheduler_settings; | 446 TEST_F(SchedulerTest, SendBeginFramesToChildren) { |
| 439 scheduler_settings.use_external_begin_frame_source = true; | 447 scheduler_settings_.use_external_begin_frame_source = true; |
| 440 | 448 scheduler_settings_.forward_begin_frames_to_children = true; |
| 441 CREATE_SCHEDULER_AND_INIT_SURFACE(scheduler_settings); | 449 SetUpScheduler(true); |
| 450 | |
| 451 EXPECT_FALSE(client_->begin_frame_is_sent_to_children()); | |
| 452 scheduler_->SetNeedsCommit(); | |
| 453 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client_); | |
| 454 EXPECT_TRUE(client_->needs_begin_frames()); | |
| 455 | |
| 456 scheduler_->SetChildrenNeedBeginFrames(true); | |
| 457 | |
| 458 client_->Reset(); | |
| 459 EXPECT_SCOPED(client_->AdvanceFrame()); | |
| 460 EXPECT_TRUE(client_->begin_frame_is_sent_to_children()); | |
| 461 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | |
| 462 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); | |
| 463 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); | |
| 464 EXPECT_TRUE(client_->needs_begin_frames()); | |
| 465 } | |
| 466 | |
| 467 TEST_F(SchedulerTest, SendBeginFramesToChildrenWithoutCommit) { | |
| 468 scheduler_settings_.use_external_begin_frame_source = true; | |
| 469 scheduler_settings_.forward_begin_frames_to_children = true; | |
| 470 SetUpScheduler(true); | |
| 471 | |
| 472 EXPECT_FALSE(client_->needs_begin_frames()); | |
| 473 scheduler_->SetChildrenNeedBeginFrames(true); | |
| 474 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client_); | |
| 475 EXPECT_TRUE(client_->needs_begin_frames()); | |
| 476 | |
| 477 client_->Reset(); | |
| 478 EXPECT_SCOPED(client_->AdvanceFrame()); | |
| 479 EXPECT_TRUE(client_->begin_frame_is_sent_to_children()); | |
| 480 } | |
| 481 | |
| 482 TEST_F(SchedulerTest, RequestCommit) { | |
| 483 scheduler_settings_.use_external_begin_frame_source = true; | |
| 484 SetUpScheduler(true); | |
| 442 | 485 |
| 443 // SetNeedsCommit should begin the frame on the next BeginImplFrame. | 486 // SetNeedsCommit should begin the frame on the next BeginImplFrame. |
| 444 scheduler->SetNeedsCommit(); | 487 scheduler_->SetNeedsCommit(); |
| 445 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client); | 488 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client_); |
| 446 client.Reset(); | 489 client_->Reset(); |
| 447 | 490 |
| 448 EXPECT_SCOPED(client.AdvanceFrame()); | 491 EXPECT_SCOPED(client_->AdvanceFrame()); |
| 449 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 492 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
| 450 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); | 493 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); |
| 451 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 494 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
| 452 EXPECT_TRUE(client.needs_begin_frames()); | 495 EXPECT_TRUE(client_->needs_begin_frames()); |
| 453 client.Reset(); | 496 client_->Reset(); |
| 454 | 497 |
| 455 // If we don't swap on the deadline, we wait for the next BeginFrame. | 498 // If we don't swap on the deadline, we wait for the next BeginFrame. |
| 456 client.task_runner().RunPendingTasks(); // Run posted deadline. | 499 client_->task_runner().RunPendingTasks(); // Run posted deadline. |
| 457 EXPECT_NO_ACTION(client); | 500 EXPECT_NO_ACTION(client_); |
| 458 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 501 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); |
| 459 EXPECT_TRUE(client.needs_begin_frames()); | 502 EXPECT_TRUE(client_->needs_begin_frames()); |
| 460 client.Reset(); | 503 client_->Reset(); |
| 461 | 504 |
| 462 // NotifyReadyToCommit should trigger the commit. | 505 // NotifyReadyToCommit should trigger the commit. |
| 463 scheduler->NotifyBeginMainFrameStarted(); | 506 scheduler_->NotifyBeginMainFrameStarted(); |
| 464 scheduler->NotifyReadyToCommit(); | 507 scheduler_->NotifyReadyToCommit(); |
| 465 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); | 508 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_); |
| 466 EXPECT_TRUE(client.needs_begin_frames()); | 509 EXPECT_TRUE(client_->needs_begin_frames()); |
| 467 client.Reset(); | 510 client_->Reset(); |
| 468 | 511 |
| 469 // BeginImplFrame should prepare the draw. | 512 // BeginImplFrame should prepare the draw. |
| 470 EXPECT_SCOPED(client.AdvanceFrame()); | 513 EXPECT_SCOPED(client_->AdvanceFrame()); |
| 471 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 514 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
| 472 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); | 515 EXPECT_ACTION("ScheduledActionAnimate", client_, 1, 2); |
| 473 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 516 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
| 474 EXPECT_TRUE(client.needs_begin_frames()); | 517 EXPECT_TRUE(client_->needs_begin_frames()); |
| 475 client.Reset(); | 518 client_->Reset(); |
| 476 | 519 |
| 477 // BeginImplFrame deadline should draw. | 520 // BeginImplFrame deadline should draw. |
| 478 client.task_runner().RunPendingTasks(); // Run posted deadline. | 521 client_->task_runner().RunPendingTasks(); // Run posted deadline. |
| 479 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 1); | 522 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 0, 1); |
| 480 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 523 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); |
| 481 EXPECT_TRUE(client.needs_begin_frames()); | 524 EXPECT_TRUE(client_->needs_begin_frames()); |
| 482 client.Reset(); | 525 client_->Reset(); |
| 483 | 526 |
| 484 // The following BeginImplFrame deadline should SetNeedsBeginFrame(false) | 527 // The following BeginImplFrame deadline should SetNeedsBeginFrame(false) |
| 485 // to avoid excessive toggles. | 528 // to avoid excessive toggles. |
| 486 EXPECT_SCOPED(client.AdvanceFrame()); | 529 EXPECT_SCOPED(client_->AdvanceFrame()); |
| 487 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); | 530 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client_); |
| 488 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 531 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
| 489 client.Reset(); | 532 client_->Reset(); |
| 490 | 533 |
| 491 client.task_runner().RunPendingTasks(); // Run posted deadline. | 534 client_->task_runner().RunPendingTasks(); // Run posted deadline. |
| 492 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(false)", client); | 535 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(false)", client_); |
| 493 client.Reset(); | 536 client_->Reset(); |
| 494 } | 537 } |
| 495 | 538 |
| 496 TEST(SchedulerTest, RequestCommitAfterBeginMainFrameSent) { | 539 TEST_F(SchedulerTest, RequestCommitAfterBeginMainFrameSent) { |
| 497 FakeSchedulerClient client; | 540 scheduler_settings_.use_external_begin_frame_source = true; |
| 498 SchedulerSettings scheduler_settings; | 541 SetUpScheduler(true); |
| 499 scheduler_settings.use_external_begin_frame_source = true; | |
| 500 | |
| 501 CREATE_SCHEDULER_AND_INIT_SURFACE(scheduler_settings); | |
| 502 | 542 |
| 503 // SetNeedsCommit should begin the frame. | 543 // SetNeedsCommit should begin the frame. |
| 504 scheduler->SetNeedsCommit(); | 544 scheduler_->SetNeedsCommit(); |
| 505 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client); | 545 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client_); |
| 506 | 546 |
| 507 client.Reset(); | 547 client_->Reset(); |
| 508 EXPECT_SCOPED(client.AdvanceFrame()); | 548 EXPECT_SCOPED(client_->AdvanceFrame()); |
| 509 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 549 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
| 510 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); | 550 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); |
| 511 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 551 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
| 512 | 552 |
| 513 EXPECT_TRUE(client.needs_begin_frames()); | 553 EXPECT_TRUE(client_->needs_begin_frames()); |
| 514 client.Reset(); | 554 client_->Reset(); |
| 515 | 555 |
| 516 // Now SetNeedsCommit again. Calling here means we need a second commit. | 556 // Now SetNeedsCommit again. Calling here means we need a second commit. |
| 517 scheduler->SetNeedsCommit(); | 557 scheduler_->SetNeedsCommit(); |
| 518 EXPECT_EQ(client.num_actions_(), 0); | 558 EXPECT_EQ(client_->num_actions_(), 0); |
| 519 client.Reset(); | 559 client_->Reset(); |
| 520 | 560 |
| 521 // Finish the first commit. | 561 // Finish the first commit. |
| 522 scheduler->NotifyBeginMainFrameStarted(); | 562 scheduler_->NotifyBeginMainFrameStarted(); |
| 523 scheduler->NotifyReadyToCommit(); | 563 scheduler_->NotifyReadyToCommit(); |
| 524 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); | 564 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_); |
| 525 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 565 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
| 526 client.Reset(); | 566 client_->Reset(); |
| 527 client.task_runner().RunPendingTasks(); // Run posted deadline. | 567 client_->task_runner().RunPendingTasks(); // Run posted deadline. |
| 528 EXPECT_ACTION("ScheduledActionAnimate", client, 0, 2); | 568 EXPECT_ACTION("ScheduledActionAnimate", client_, 0, 2); |
| 529 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 1, 2); | 569 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 1, 2); |
| 530 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 570 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); |
| 531 | 571 |
| 532 // Because we just swapped, the Scheduler should also request the next | 572 // Because we just swapped, the Scheduler should also request the next |
| 533 // BeginImplFrame from the OutputSurface. | 573 // BeginImplFrame from the OutputSurface. |
| 534 EXPECT_TRUE(client.needs_begin_frames()); | 574 EXPECT_TRUE(client_->needs_begin_frames()); |
| 535 client.Reset(); | 575 client_->Reset(); |
| 536 // Since another commit is needed, the next BeginImplFrame should initiate | 576 // Since another commit is needed, the next BeginImplFrame should initiate |
| 537 // the second commit. | 577 // the second commit. |
| 538 EXPECT_SCOPED(client.AdvanceFrame()); | 578 EXPECT_SCOPED(client_->AdvanceFrame()); |
| 539 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 579 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
| 540 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); | 580 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); |
| 541 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 581 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
| 542 client.Reset(); | 582 client_->Reset(); |
| 543 | 583 |
| 544 // Finishing the commit before the deadline should post a new deadline task | 584 // Finishing the commit before the deadline should post a new deadline task |
| 545 // to trigger the deadline early. | 585 // to trigger the deadline early. |
| 546 scheduler->NotifyBeginMainFrameStarted(); | 586 scheduler_->NotifyBeginMainFrameStarted(); |
| 547 scheduler->NotifyReadyToCommit(); | 587 scheduler_->NotifyReadyToCommit(); |
| 548 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); | 588 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_); |
| 549 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 589 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
| 550 client.Reset(); | 590 client_->Reset(); |
| 551 client.task_runner().RunPendingTasks(); // Run posted deadline. | 591 client_->task_runner().RunPendingTasks(); // Run posted deadline. |
| 552 EXPECT_ACTION("ScheduledActionAnimate", client, 0, 2); | 592 EXPECT_ACTION("ScheduledActionAnimate", client_, 0, 2); |
| 553 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 1, 2); | 593 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 1, 2); |
| 554 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 594 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); |
| 555 EXPECT_TRUE(client.needs_begin_frames()); | 595 EXPECT_TRUE(client_->needs_begin_frames()); |
| 556 client.Reset(); | 596 client_->Reset(); |
| 557 | 597 |
| 558 // On the next BeginImplFrame, verify we go back to a quiescent state and | 598 // On the next BeginImplFrame, verify we go back to a quiescent state and |
| 559 // no longer request BeginImplFrames. | 599 // no longer request BeginImplFrames. |
| 560 EXPECT_SCOPED(client.AdvanceFrame()); | 600 EXPECT_SCOPED(client_->AdvanceFrame()); |
| 561 client.task_runner().RunPendingTasks(); // Run posted deadline. | 601 client_->task_runner().RunPendingTasks(); // Run posted deadline. |
| 562 EXPECT_FALSE(client.needs_begin_frames()); | 602 EXPECT_FALSE(client_->needs_begin_frames()); |
| 563 client.Reset(); | 603 client_->Reset(); |
| 564 } | 604 } |
| 565 | 605 |
| 566 class SchedulerClientThatsetNeedsDrawInsideDraw : public FakeSchedulerClient { | 606 class SchedulerClientThatsetNeedsDrawInsideDraw : public FakeSchedulerClient { |
| 567 public: | 607 public: |
| 568 SchedulerClientThatsetNeedsDrawInsideDraw() | 608 SchedulerClientThatsetNeedsDrawInsideDraw() |
| 569 : FakeSchedulerClient(), request_redraws_(false) {} | 609 : FakeSchedulerClient(), request_redraws_(false) {} |
| 570 | 610 |
| 571 void ScheduledActionSendBeginMainFrame() override {} | 611 void ScheduledActionSendBeginMainFrame() override {} |
| 572 | 612 |
| 573 void SetRequestRedrawsInsideDraw(bool enable) { request_redraws_ = enable; } | 613 void SetRequestRedrawsInsideDraw(bool enable) { request_redraws_ = enable; } |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 589 void DidAnticipatedDrawTimeChange(base::TimeTicks) override {} | 629 void DidAnticipatedDrawTimeChange(base::TimeTicks) override {} |
| 590 | 630 |
| 591 private: | 631 private: |
| 592 bool request_redraws_; | 632 bool request_redraws_; |
| 593 }; | 633 }; |
| 594 | 634 |
| 595 // Tests for two different situations: | 635 // Tests for two different situations: |
| 596 // 1. the scheduler dropping SetNeedsRedraw requests that happen inside | 636 // 1. the scheduler dropping SetNeedsRedraw requests that happen inside |
| 597 // a ScheduledActionDrawAndSwap | 637 // a ScheduledActionDrawAndSwap |
| 598 // 2. the scheduler drawing twice inside a single tick | 638 // 2. the scheduler drawing twice inside a single tick |
| 599 TEST(SchedulerTest, RequestRedrawInsideDraw) { | 639 TEST_F(SchedulerTest, RequestRedrawInsideDraw) { |
| 600 SchedulerClientThatsetNeedsDrawInsideDraw client; | 640 SchedulerClientThatsetNeedsDrawInsideDraw* client = |
| 601 SchedulerSettings scheduler_settings; | 641 new SchedulerClientThatsetNeedsDrawInsideDraw; |
| 602 scheduler_settings.use_external_begin_frame_source = true; | 642 scheduler_settings_.use_external_begin_frame_source = true; |
| 643 SetUpScheduler(client, true); | |
| 644 client->SetRequestRedrawsInsideDraw(true); | |
| 603 | 645 |
| 604 CREATE_SCHEDULER_AND_INIT_SURFACE(scheduler_settings); | 646 scheduler_->SetNeedsRedraw(); |
| 605 client.SetRequestRedrawsInsideDraw(true); | 647 EXPECT_TRUE(scheduler_->RedrawPending()); |
| 648 EXPECT_TRUE(client->needs_begin_frames()); | |
| 649 EXPECT_EQ(0, client->num_draws()); | |
| 606 | 650 |
| 607 scheduler->SetNeedsRedraw(); | 651 EXPECT_SCOPED(client->AdvanceFrame()); |
| 608 EXPECT_TRUE(scheduler->RedrawPending()); | 652 client->task_runner().RunPendingTasks(); // Run posted deadline. |
| 609 EXPECT_TRUE(client.needs_begin_frames()); | 653 EXPECT_EQ(1, client->num_draws()); |
| 610 EXPECT_EQ(0, client.num_draws()); | 654 EXPECT_TRUE(scheduler_->RedrawPending()); |
| 655 EXPECT_TRUE(client->needs_begin_frames()); | |
| 611 | 656 |
| 612 EXPECT_SCOPED(client.AdvanceFrame()); | 657 client->SetRequestRedrawsInsideDraw(false); |
| 613 client.task_runner().RunPendingTasks(); // Run posted deadline. | |
| 614 EXPECT_EQ(1, client.num_draws()); | |
| 615 EXPECT_TRUE(scheduler->RedrawPending()); | |
| 616 EXPECT_TRUE(client.needs_begin_frames()); | |
| 617 | 658 |
| 618 client.SetRequestRedrawsInsideDraw(false); | 659 EXPECT_SCOPED(client_->AdvanceFrame()); |
| 619 | 660 client->task_runner().RunPendingTasks(); // Run posted deadline. |
| 620 EXPECT_SCOPED(client.AdvanceFrame()); | 661 EXPECT_EQ(2, client_->num_draws()); |
| 621 client.task_runner().RunPendingTasks(); // Run posted deadline. | 662 EXPECT_FALSE(scheduler_->RedrawPending()); |
| 622 EXPECT_EQ(2, client.num_draws()); | 663 EXPECT_TRUE(client->needs_begin_frames()); |
| 623 EXPECT_FALSE(scheduler->RedrawPending()); | |
| 624 EXPECT_TRUE(client.needs_begin_frames()); | |
| 625 | 664 |
| 626 // We stop requesting BeginImplFrames after a BeginImplFrame where we don't | 665 // We stop requesting BeginImplFrames after a BeginImplFrame where we don't |
| 627 // swap. | 666 // swap. |
| 628 EXPECT_SCOPED(client.AdvanceFrame()); | 667 EXPECT_SCOPED(client->AdvanceFrame()); |
| 629 client.task_runner().RunPendingTasks(); // Run posted deadline. | 668 client->task_runner().RunPendingTasks(); // Run posted deadline. |
| 630 EXPECT_EQ(2, client.num_draws()); | 669 EXPECT_EQ(2, client->num_draws()); |
| 631 EXPECT_FALSE(scheduler->RedrawPending()); | 670 EXPECT_FALSE(scheduler_->RedrawPending()); |
| 632 EXPECT_FALSE(client.needs_begin_frames()); | 671 EXPECT_FALSE(client->needs_begin_frames()); |
| 633 } | 672 } |
| 634 | 673 |
| 635 // Test that requesting redraw inside a failed draw doesn't lose the request. | 674 // Test that requesting redraw inside a failed draw doesn't lose the request. |
| 636 TEST(SchedulerTest, RequestRedrawInsideFailedDraw) { | 675 TEST_F(SchedulerTest, RequestRedrawInsideFailedDraw) { |
| 637 SchedulerClientThatsetNeedsDrawInsideDraw client; | 676 SchedulerClientThatsetNeedsDrawInsideDraw* client = |
| 638 SchedulerSettings scheduler_settings; | 677 new SchedulerClientThatsetNeedsDrawInsideDraw; |
| 639 scheduler_settings.use_external_begin_frame_source = true; | 678 scheduler_settings_.use_external_begin_frame_source = true; |
| 679 SetUpScheduler(client, true); | |
| 640 | 680 |
| 641 CREATE_SCHEDULER_AND_INIT_SURFACE(scheduler_settings); | 681 client->SetRequestRedrawsInsideDraw(true); |
| 642 client.SetRequestRedrawsInsideDraw(true); | 682 client->SetDrawWillHappen(false); |
| 643 client.SetDrawWillHappen(false); | |
| 644 | 683 |
| 645 scheduler->SetNeedsRedraw(); | 684 scheduler_->SetNeedsRedraw(); |
| 646 EXPECT_TRUE(scheduler->RedrawPending()); | 685 EXPECT_TRUE(scheduler_->RedrawPending()); |
| 647 EXPECT_TRUE(client.needs_begin_frames()); | 686 EXPECT_TRUE(client->needs_begin_frames()); |
| 648 EXPECT_EQ(0, client.num_draws()); | 687 EXPECT_EQ(0, client->num_draws()); |
| 649 | 688 |
| 650 // Fail the draw. | 689 // Fail the draw. |
| 651 EXPECT_SCOPED(client.AdvanceFrame()); | 690 EXPECT_SCOPED(client->AdvanceFrame()); |
| 652 client.task_runner().RunPendingTasks(); // Run posted deadline. | 691 client->task_runner().RunPendingTasks(); // Run posted deadline. |
| 653 EXPECT_EQ(1, client.num_draws()); | 692 EXPECT_EQ(1, client->num_draws()); |
| 654 | 693 |
| 655 // We have a commit pending and the draw failed, and we didn't lose the redraw | 694 // We have a commit pending and the draw failed, and we didn't lose the redraw |
| 656 // request. | 695 // request. |
| 657 EXPECT_TRUE(scheduler->CommitPending()); | 696 EXPECT_TRUE(scheduler_->CommitPending()); |
| 658 EXPECT_TRUE(scheduler->RedrawPending()); | 697 EXPECT_TRUE(scheduler_->RedrawPending()); |
| 659 EXPECT_TRUE(client.needs_begin_frames()); | 698 EXPECT_TRUE(client->needs_begin_frames()); |
| 660 | 699 |
| 661 client.SetRequestRedrawsInsideDraw(false); | 700 client->SetRequestRedrawsInsideDraw(false); |
| 662 | 701 |
| 663 // Fail the draw again. | 702 // Fail the draw again. |
| 664 EXPECT_SCOPED(client.AdvanceFrame()); | 703 EXPECT_SCOPED(client->AdvanceFrame()); |
| 665 client.task_runner().RunPendingTasks(); // Run posted deadline. | 704 client->task_runner().RunPendingTasks(); // Run posted deadline. |
| 666 EXPECT_EQ(2, client.num_draws()); | 705 EXPECT_EQ(2, client->num_draws()); |
| 667 EXPECT_TRUE(scheduler->CommitPending()); | 706 EXPECT_TRUE(scheduler_->CommitPending()); |
| 668 EXPECT_TRUE(scheduler->RedrawPending()); | 707 EXPECT_TRUE(scheduler_->RedrawPending()); |
| 669 EXPECT_TRUE(client.needs_begin_frames()); | 708 EXPECT_TRUE(client->needs_begin_frames()); |
| 670 | 709 |
| 671 // Draw successfully. | 710 // Draw successfully. |
| 672 client.SetDrawWillHappen(true); | 711 client->SetDrawWillHappen(true); |
| 673 EXPECT_SCOPED(client.AdvanceFrame()); | 712 EXPECT_SCOPED(client->AdvanceFrame()); |
| 674 client.task_runner().RunPendingTasks(); // Run posted deadline. | 713 client->task_runner().RunPendingTasks(); // Run posted deadline. |
| 675 EXPECT_EQ(3, client.num_draws()); | 714 EXPECT_EQ(3, client->num_draws()); |
| 676 EXPECT_TRUE(scheduler->CommitPending()); | 715 EXPECT_TRUE(scheduler_->CommitPending()); |
| 677 EXPECT_FALSE(scheduler->RedrawPending()); | 716 EXPECT_FALSE(scheduler_->RedrawPending()); |
| 678 EXPECT_TRUE(client.needs_begin_frames()); | 717 EXPECT_TRUE(client->needs_begin_frames()); |
| 679 } | 718 } |
| 680 | 719 |
| 681 class SchedulerClientThatSetNeedsCommitInsideDraw : public FakeSchedulerClient { | 720 class SchedulerClientThatSetNeedsCommitInsideDraw : public FakeSchedulerClient { |
| 682 public: | 721 public: |
| 683 SchedulerClientThatSetNeedsCommitInsideDraw() | 722 SchedulerClientThatSetNeedsCommitInsideDraw() |
| 684 : set_needs_commit_on_next_draw_(false) {} | 723 : set_needs_commit_on_next_draw_(false) {} |
| 685 | 724 |
| 686 void ScheduledActionSendBeginMainFrame() override {} | 725 void ScheduledActionSendBeginMainFrame() override {} |
| 687 DrawResult ScheduledActionDrawAndSwapIfPossible() override { | 726 DrawResult ScheduledActionDrawAndSwapIfPossible() override { |
| 688 // Only SetNeedsCommit the first time this is called | 727 // Only SetNeedsCommit the first time this is called |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 702 void DidAnticipatedDrawTimeChange(base::TimeTicks) override {} | 741 void DidAnticipatedDrawTimeChange(base::TimeTicks) override {} |
| 703 | 742 |
| 704 void SetNeedsCommitOnNextDraw() { set_needs_commit_on_next_draw_ = true; } | 743 void SetNeedsCommitOnNextDraw() { set_needs_commit_on_next_draw_ = true; } |
| 705 | 744 |
| 706 private: | 745 private: |
| 707 bool set_needs_commit_on_next_draw_; | 746 bool set_needs_commit_on_next_draw_; |
| 708 }; | 747 }; |
| 709 | 748 |
| 710 // Tests for the scheduler infinite-looping on SetNeedsCommit requests that | 749 // Tests for the scheduler infinite-looping on SetNeedsCommit requests that |
| 711 // happen inside a ScheduledActionDrawAndSwap | 750 // happen inside a ScheduledActionDrawAndSwap |
| 712 TEST(SchedulerTest, RequestCommitInsideDraw) { | 751 TEST_F(SchedulerTest, RequestCommitInsideDraw) { |
| 713 SchedulerClientThatSetNeedsCommitInsideDraw client; | 752 SchedulerClientThatSetNeedsCommitInsideDraw* client = |
| 714 SchedulerSettings scheduler_settings; | 753 new SchedulerClientThatSetNeedsCommitInsideDraw; |
| 715 scheduler_settings.use_external_begin_frame_source = true; | |
| 716 | 754 |
| 717 CREATE_SCHEDULER_AND_INIT_SURFACE(scheduler_settings); | 755 scheduler_settings_.use_external_begin_frame_source = true; |
| 756 SetUpScheduler(client, true); | |
| 718 | 757 |
| 719 EXPECT_FALSE(client.needs_begin_frames()); | 758 EXPECT_FALSE(client->needs_begin_frames()); |
| 720 scheduler->SetNeedsRedraw(); | 759 scheduler_->SetNeedsRedraw(); |
| 721 EXPECT_TRUE(scheduler->RedrawPending()); | 760 EXPECT_TRUE(scheduler_->RedrawPending()); |
| 722 EXPECT_EQ(0, client.num_draws()); | 761 EXPECT_EQ(0, client->num_draws()); |
| 723 EXPECT_TRUE(client.needs_begin_frames()); | 762 EXPECT_TRUE(client->needs_begin_frames()); |
| 724 | 763 |
| 725 client.SetNeedsCommitOnNextDraw(); | 764 client->SetNeedsCommitOnNextDraw(); |
| 726 EXPECT_SCOPED(client.AdvanceFrame()); | 765 EXPECT_SCOPED(client->AdvanceFrame()); |
| 727 client.SetNeedsCommitOnNextDraw(); | 766 client->SetNeedsCommitOnNextDraw(); |
| 728 client.task_runner().RunPendingTasks(); // Run posted deadline. | 767 client->task_runner().RunPendingTasks(); // Run posted deadline. |
| 729 EXPECT_EQ(1, client.num_draws()); | 768 EXPECT_EQ(1, client->num_draws()); |
| 730 EXPECT_TRUE(scheduler->CommitPending()); | 769 EXPECT_TRUE(scheduler_->CommitPending()); |
| 731 EXPECT_TRUE(client.needs_begin_frames()); | 770 EXPECT_TRUE(client->needs_begin_frames()); |
| 732 scheduler->NotifyBeginMainFrameStarted(); | 771 scheduler_->NotifyBeginMainFrameStarted(); |
| 733 scheduler->NotifyReadyToCommit(); | 772 scheduler_->NotifyReadyToCommit(); |
| 734 | 773 |
| 735 EXPECT_SCOPED(client.AdvanceFrame()); | 774 EXPECT_SCOPED(client->AdvanceFrame()); |
| 736 client.task_runner().RunPendingTasks(); // Run posted deadline. | 775 client->task_runner().RunPendingTasks(); // Run posted deadline. |
| 737 EXPECT_EQ(2, client.num_draws()); | 776 EXPECT_EQ(2, client->num_draws()); |
| 738 | 777 |
| 739 EXPECT_FALSE(scheduler->RedrawPending()); | 778 EXPECT_FALSE(scheduler_->RedrawPending()); |
| 740 EXPECT_FALSE(scheduler->CommitPending()); | 779 EXPECT_FALSE(scheduler_->CommitPending()); |
| 741 EXPECT_TRUE(client.needs_begin_frames()); | 780 EXPECT_TRUE(client->needs_begin_frames()); |
| 742 | 781 |
| 743 // We stop requesting BeginImplFrames after a BeginImplFrame where we don't | 782 // We stop requesting BeginImplFrames after a BeginImplFrame where we don't |
| 744 // swap. | 783 // swap. |
| 745 EXPECT_SCOPED(client.AdvanceFrame()); | 784 EXPECT_SCOPED(client->AdvanceFrame()); |
| 746 client.task_runner().RunPendingTasks(); // Run posted deadline. | 785 client->task_runner().RunPendingTasks(); // Run posted deadline. |
| 747 EXPECT_EQ(2, client.num_draws()); | 786 EXPECT_EQ(2, client->num_draws()); |
| 748 EXPECT_FALSE(scheduler->RedrawPending()); | 787 EXPECT_FALSE(scheduler_->RedrawPending()); |
| 749 EXPECT_FALSE(scheduler->CommitPending()); | 788 EXPECT_FALSE(scheduler_->CommitPending()); |
| 750 EXPECT_FALSE(client.needs_begin_frames()); | 789 EXPECT_FALSE(client->needs_begin_frames()); |
| 751 } | 790 } |
| 752 | 791 |
| 753 // Tests that when a draw fails then the pending commit should not be dropped. | 792 // Tests that when a draw fails then the pending commit should not be dropped. |
| 754 TEST(SchedulerTest, RequestCommitInsideFailedDraw) { | 793 TEST_F(SchedulerTest, RequestCommitInsideFailedDraw) { |
| 755 SchedulerClientThatsetNeedsDrawInsideDraw client; | 794 SchedulerClientThatsetNeedsDrawInsideDraw* client = |
| 756 SchedulerSettings scheduler_settings; | 795 new SchedulerClientThatsetNeedsDrawInsideDraw; |
| 757 scheduler_settings.use_external_begin_frame_source = true; | 796 scheduler_settings_.use_external_begin_frame_source = true; |
| 797 SetUpScheduler(client, true); | |
| 758 | 798 |
| 759 CREATE_SCHEDULER_AND_INIT_SURFACE(scheduler_settings); | 799 client->SetDrawWillHappen(false); |
| 760 | 800 |
| 761 client.SetDrawWillHappen(false); | 801 scheduler_->SetNeedsRedraw(); |
| 762 | 802 EXPECT_TRUE(scheduler_->RedrawPending()); |
| 763 scheduler->SetNeedsRedraw(); | 803 EXPECT_TRUE(client->needs_begin_frames()); |
| 764 EXPECT_TRUE(scheduler->RedrawPending()); | 804 EXPECT_EQ(0, client->num_draws()); |
| 765 EXPECT_TRUE(client.needs_begin_frames()); | |
| 766 EXPECT_EQ(0, client.num_draws()); | |
| 767 | 805 |
| 768 // Fail the draw. | 806 // Fail the draw. |
| 769 EXPECT_SCOPED(client.AdvanceFrame()); | 807 EXPECT_SCOPED(client->AdvanceFrame()); |
| 770 client.task_runner().RunPendingTasks(); // Run posted deadline. | 808 client->task_runner().RunPendingTasks(); // Run posted deadline. |
| 771 EXPECT_EQ(1, client.num_draws()); | 809 EXPECT_EQ(1, client->num_draws()); |
| 772 | 810 |
| 773 // We have a commit pending and the draw failed, and we didn't lose the commit | 811 // We have a commit pending and the draw failed, and we didn't lose the commit |
| 774 // request. | 812 // request. |
| 775 EXPECT_TRUE(scheduler->CommitPending()); | 813 EXPECT_TRUE(scheduler_->CommitPending()); |
| 776 EXPECT_TRUE(scheduler->RedrawPending()); | 814 EXPECT_TRUE(scheduler_->RedrawPending()); |
| 777 EXPECT_TRUE(client.needs_begin_frames()); | 815 EXPECT_TRUE(client->needs_begin_frames()); |
| 778 | 816 |
| 779 // Fail the draw again. | 817 // Fail the draw again. |
| 780 EXPECT_SCOPED(client.AdvanceFrame()); | 818 EXPECT_SCOPED(client->AdvanceFrame()); |
| 781 | 819 |
| 782 client.task_runner().RunPendingTasks(); // Run posted deadline. | 820 client->task_runner().RunPendingTasks(); // Run posted deadline. |
| 783 EXPECT_EQ(2, client.num_draws()); | 821 EXPECT_EQ(2, client->num_draws()); |
| 784 EXPECT_TRUE(scheduler->CommitPending()); | 822 EXPECT_TRUE(scheduler_->CommitPending()); |
| 785 EXPECT_TRUE(scheduler->RedrawPending()); | 823 EXPECT_TRUE(scheduler_->RedrawPending()); |
| 786 EXPECT_TRUE(client.needs_begin_frames()); | 824 EXPECT_TRUE(client->needs_begin_frames()); |
| 787 | 825 |
| 788 // Draw successfully. | 826 // Draw successfully. |
| 789 client.SetDrawWillHappen(true); | 827 client->SetDrawWillHappen(true); |
| 790 EXPECT_SCOPED(client.AdvanceFrame()); | 828 EXPECT_SCOPED(client->AdvanceFrame()); |
| 791 client.task_runner().RunPendingTasks(); // Run posted deadline. | 829 client->task_runner().RunPendingTasks(); // Run posted deadline. |
| 792 EXPECT_EQ(3, client.num_draws()); | 830 EXPECT_EQ(3, client->num_draws()); |
| 793 EXPECT_TRUE(scheduler->CommitPending()); | 831 EXPECT_TRUE(scheduler_->CommitPending()); |
| 794 EXPECT_FALSE(scheduler->RedrawPending()); | 832 EXPECT_FALSE(scheduler_->RedrawPending()); |
| 795 EXPECT_TRUE(client.needs_begin_frames()); | 833 EXPECT_TRUE(client->needs_begin_frames()); |
| 796 } | 834 } |
| 797 | 835 |
| 798 TEST(SchedulerTest, NoSwapWhenDrawFails) { | 836 TEST_F(SchedulerTest, NoSwapWhenDrawFails) { |
| 799 SchedulerClientThatSetNeedsCommitInsideDraw client; | 837 SchedulerClientThatSetNeedsCommitInsideDraw* client = |
| 800 SchedulerSettings scheduler_settings; | 838 new SchedulerClientThatSetNeedsCommitInsideDraw; |
| 801 scheduler_settings.use_external_begin_frame_source = true; | 839 scheduler_settings_.use_external_begin_frame_source = true; |
| 840 SetUpScheduler(client, true); | |
| 802 | 841 |
| 803 CREATE_SCHEDULER_AND_INIT_SURFACE(scheduler_settings); | 842 scheduler_->SetNeedsRedraw(); |
| 804 | 843 EXPECT_TRUE(scheduler_->RedrawPending()); |
| 805 scheduler->SetNeedsRedraw(); | 844 EXPECT_TRUE(client->needs_begin_frames()); |
| 806 EXPECT_TRUE(scheduler->RedrawPending()); | 845 EXPECT_EQ(0, client->num_draws()); |
| 807 EXPECT_TRUE(client.needs_begin_frames()); | |
| 808 EXPECT_EQ(0, client.num_draws()); | |
| 809 | 846 |
| 810 // Draw successfully, this starts a new frame. | 847 // Draw successfully, this starts a new frame. |
| 811 client.SetNeedsCommitOnNextDraw(); | 848 client->SetNeedsCommitOnNextDraw(); |
| 812 EXPECT_SCOPED(client.AdvanceFrame()); | 849 EXPECT_SCOPED(client->AdvanceFrame()); |
| 813 client.task_runner().RunPendingTasks(); // Run posted deadline. | 850 client->task_runner().RunPendingTasks(); // Run posted deadline. |
| 814 EXPECT_EQ(1, client.num_draws()); | 851 EXPECT_EQ(1, client->num_draws()); |
| 815 | 852 |
| 816 scheduler->SetNeedsRedraw(); | 853 scheduler_->SetNeedsRedraw(); |
| 817 EXPECT_TRUE(scheduler->RedrawPending()); | 854 EXPECT_TRUE(scheduler_->RedrawPending()); |
| 818 EXPECT_TRUE(client.needs_begin_frames()); | 855 EXPECT_TRUE(client->needs_begin_frames()); |
| 819 | 856 |
| 820 // Fail to draw, this should not start a frame. | 857 // Fail to draw, this should not start a frame. |
| 821 client.SetDrawWillHappen(false); | 858 client->SetDrawWillHappen(false); |
| 822 client.SetNeedsCommitOnNextDraw(); | 859 client->SetNeedsCommitOnNextDraw(); |
| 823 EXPECT_SCOPED(client.AdvanceFrame()); | 860 EXPECT_SCOPED(client->AdvanceFrame()); |
| 824 client.task_runner().RunPendingTasks(); // Run posted deadline. | 861 client->task_runner().RunPendingTasks(); // Run posted deadline. |
| 825 EXPECT_EQ(2, client.num_draws()); | 862 EXPECT_EQ(2, client->num_draws()); |
| 826 } | 863 } |
| 827 | 864 |
| 828 class SchedulerClientNeedsPrepareTilesInDraw : public FakeSchedulerClient { | 865 class SchedulerClientNeedsPrepareTilesInDraw : public FakeSchedulerClient { |
| 829 public: | 866 public: |
| 830 DrawResult ScheduledActionDrawAndSwapIfPossible() override { | 867 DrawResult ScheduledActionDrawAndSwapIfPossible() override { |
| 831 scheduler_->SetNeedsPrepareTiles(); | 868 scheduler_->SetNeedsPrepareTiles(); |
| 832 return FakeSchedulerClient::ScheduledActionDrawAndSwapIfPossible(); | 869 return FakeSchedulerClient::ScheduledActionDrawAndSwapIfPossible(); |
| 833 } | 870 } |
| 834 }; | 871 }; |
| 835 | 872 |
| 836 // Test prepare tiles is independant of draws. | 873 // Test prepare tiles is independant of draws. |
| 837 TEST(SchedulerTest, PrepareTiles) { | 874 TEST_F(SchedulerTest, PrepareTiles) { |
| 838 SchedulerClientNeedsPrepareTilesInDraw client; | 875 SchedulerClientNeedsPrepareTilesInDraw* client = |
| 839 SchedulerSettings scheduler_settings; | 876 new SchedulerClientNeedsPrepareTilesInDraw; |
| 840 scheduler_settings.use_external_begin_frame_source = true; | 877 scheduler_settings_.use_external_begin_frame_source = true; |
| 841 | 878 SetUpScheduler(client, true); |
| 842 CREATE_SCHEDULER_AND_INIT_SURFACE(scheduler_settings); | |
| 843 | 879 |
| 844 // Request both draw and prepare tiles. PrepareTiles shouldn't | 880 // Request both draw and prepare tiles. PrepareTiles shouldn't |
| 845 // be trigged until BeginImplFrame. | 881 // be trigged until BeginImplFrame. |
| 846 client.Reset(); | 882 client->Reset(); |
| 847 scheduler->SetNeedsPrepareTiles(); | 883 scheduler_->SetNeedsPrepareTiles(); |
| 848 scheduler->SetNeedsRedraw(); | 884 scheduler_->SetNeedsRedraw(); |
| 849 EXPECT_TRUE(scheduler->RedrawPending()); | 885 EXPECT_TRUE(scheduler_->RedrawPending()); |
| 850 EXPECT_TRUE(scheduler->PrepareTilesPending()); | 886 EXPECT_TRUE(scheduler_->PrepareTilesPending()); |
| 851 EXPECT_TRUE(client.needs_begin_frames()); | 887 EXPECT_TRUE(client->needs_begin_frames()); |
| 852 EXPECT_EQ(0, client.num_draws()); | 888 EXPECT_EQ(0, client->num_draws()); |
| 853 EXPECT_FALSE(client.HasAction("ScheduledActionPrepareTiles")); | 889 EXPECT_FALSE(client->HasAction("ScheduledActionPrepareTiles")); |
| 854 EXPECT_FALSE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); | 890 EXPECT_FALSE(client->HasAction("ScheduledActionDrawAndSwapIfPossible")); |
| 855 | 891 |
| 856 // We have no immediate actions to perform, so the BeginImplFrame should post | 892 // We have no immediate actions to perform, so the BeginImplFrame should post |
| 857 // the deadline task. | 893 // the deadline task. |
| 858 client.Reset(); | 894 client->Reset(); |
| 859 EXPECT_SCOPED(client.AdvanceFrame()); | 895 EXPECT_SCOPED(client->AdvanceFrame()); |
| 860 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 896 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
| 861 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); | 897 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); |
| 862 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 898 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
| 863 | 899 |
| 864 // On the deadline, he actions should have occured in the right order. | 900 // On the deadline, he actions should have occured in the right order. |
| 865 client.Reset(); | 901 client->Reset(); |
| 866 client.task_runner().RunPendingTasks(); // Run posted deadline. | 902 client->task_runner().RunPendingTasks(); // Run posted deadline. |
| 867 EXPECT_EQ(1, client.num_draws()); | 903 EXPECT_EQ(1, client->num_draws()); |
| 868 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); | 904 EXPECT_TRUE(client->HasAction("ScheduledActionDrawAndSwapIfPossible")); |
| 869 EXPECT_TRUE(client.HasAction("ScheduledActionPrepareTiles")); | 905 EXPECT_TRUE(client->HasAction("ScheduledActionPrepareTiles")); |
| 870 EXPECT_LT(client.ActionIndex("ScheduledActionDrawAndSwapIfPossible"), | 906 EXPECT_LT(client->ActionIndex("ScheduledActionDrawAndSwapIfPossible"), |
| 871 client.ActionIndex("ScheduledActionPrepareTiles")); | 907 client->ActionIndex("ScheduledActionPrepareTiles")); |
| 872 EXPECT_FALSE(scheduler->RedrawPending()); | 908 EXPECT_FALSE(scheduler_->RedrawPending()); |
| 873 EXPECT_FALSE(scheduler->PrepareTilesPending()); | 909 EXPECT_FALSE(scheduler_->PrepareTilesPending()); |
| 874 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 910 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); |
| 875 | 911 |
| 876 // Request a draw. We don't need a PrepareTiles yet. | 912 // Request a draw. We don't need a PrepareTiles yet. |
| 877 client.Reset(); | 913 client->Reset(); |
| 878 scheduler->SetNeedsRedraw(); | 914 scheduler_->SetNeedsRedraw(); |
| 879 EXPECT_TRUE(scheduler->RedrawPending()); | 915 EXPECT_TRUE(scheduler_->RedrawPending()); |
| 880 EXPECT_FALSE(scheduler->PrepareTilesPending()); | 916 EXPECT_FALSE(scheduler_->PrepareTilesPending()); |
| 881 EXPECT_TRUE(client.needs_begin_frames()); | 917 EXPECT_TRUE(client->needs_begin_frames()); |
| 882 EXPECT_EQ(0, client.num_draws()); | 918 EXPECT_EQ(0, client->num_draws()); |
| 883 | 919 |
| 884 // We have no immediate actions to perform, so the BeginImplFrame should post | 920 // We have no immediate actions to perform, so the BeginImplFrame should post |
| 885 // the deadline task. | 921 // the deadline task. |
| 886 client.Reset(); | 922 client->Reset(); |
| 887 EXPECT_SCOPED(client.AdvanceFrame()); | 923 EXPECT_SCOPED(client->AdvanceFrame()); |
| 888 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 924 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
| 889 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); | 925 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); |
| 890 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 926 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
| 891 | 927 |
| 892 // Draw. The draw will trigger SetNeedsPrepareTiles, and | 928 // Draw. The draw will trigger SetNeedsPrepareTiles, and |
| 893 // then the PrepareTiles action will be triggered after the Draw. | 929 // then the PrepareTiles action will be triggered after the Draw. |
| 894 // Afterwards, neither a draw nor PrepareTiles are pending. | 930 // Afterwards, neither a draw nor PrepareTiles are pending. |
| 895 client.Reset(); | 931 client->Reset(); |
| 896 client.task_runner().RunPendingTasks(); // Run posted deadline. | 932 client->task_runner().RunPendingTasks(); // Run posted deadline. |
| 897 EXPECT_EQ(1, client.num_draws()); | 933 EXPECT_EQ(1, client->num_draws()); |
| 898 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); | 934 EXPECT_TRUE(client->HasAction("ScheduledActionDrawAndSwapIfPossible")); |
| 899 EXPECT_TRUE(client.HasAction("ScheduledActionPrepareTiles")); | 935 EXPECT_TRUE(client->HasAction("ScheduledActionPrepareTiles")); |
| 900 EXPECT_LT(client.ActionIndex("ScheduledActionDrawAndSwapIfPossible"), | 936 EXPECT_LT(client->ActionIndex("ScheduledActionDrawAndSwapIfPossible"), |
| 901 client.ActionIndex("ScheduledActionPrepareTiles")); | 937 client->ActionIndex("ScheduledActionPrepareTiles")); |
| 902 EXPECT_FALSE(scheduler->RedrawPending()); | 938 EXPECT_FALSE(scheduler_->RedrawPending()); |
| 903 EXPECT_FALSE(scheduler->PrepareTilesPending()); | 939 EXPECT_FALSE(scheduler_->PrepareTilesPending()); |
| 904 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 940 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); |
| 905 | 941 |
| 906 // We need a BeginImplFrame where we don't swap to go idle. | 942 // We need a BeginImplFrame where we don't swap to go idle. |
| 907 client.Reset(); | 943 client->Reset(); |
| 908 EXPECT_SCOPED(client.AdvanceFrame()); | 944 EXPECT_SCOPED(client->AdvanceFrame()); |
| 909 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); | 945 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); |
| 910 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 946 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
| 911 client.Reset(); | 947 client->Reset(); |
| 912 client.task_runner().RunPendingTasks(); // Run posted deadline. | 948 client->task_runner().RunPendingTasks(); // Run posted deadline. |
| 913 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(false)", client); | 949 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(false)", client); |
| 914 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 950 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); |
| 915 EXPECT_EQ(0, client.num_draws()); | 951 EXPECT_EQ(0, client->num_draws()); |
| 916 | 952 |
| 917 // Now trigger a PrepareTiles outside of a draw. We will then need | 953 // Now trigger a PrepareTiles outside of a draw. We will then need |
| 918 // a begin-frame for the PrepareTiles, but we don't need a draw. | 954 // a begin-frame for the PrepareTiles, but we don't need a draw. |
| 919 client.Reset(); | 955 client->Reset(); |
| 920 EXPECT_FALSE(client.needs_begin_frames()); | 956 EXPECT_FALSE(client->needs_begin_frames()); |
| 921 scheduler->SetNeedsPrepareTiles(); | 957 scheduler_->SetNeedsPrepareTiles(); |
| 922 EXPECT_TRUE(client.needs_begin_frames()); | 958 EXPECT_TRUE(client->needs_begin_frames()); |
| 923 EXPECT_TRUE(scheduler->PrepareTilesPending()); | 959 EXPECT_TRUE(scheduler_->PrepareTilesPending()); |
| 924 EXPECT_FALSE(scheduler->RedrawPending()); | 960 EXPECT_FALSE(scheduler_->RedrawPending()); |
| 925 | 961 |
| 926 // BeginImplFrame. There will be no draw, only PrepareTiles. | 962 // BeginImplFrame. There will be no draw, only PrepareTiles. |
| 927 client.Reset(); | 963 client->Reset(); |
| 928 EXPECT_SCOPED(client.AdvanceFrame()); | 964 EXPECT_SCOPED(client->AdvanceFrame()); |
| 929 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); | 965 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); |
| 930 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 966 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
| 931 client.Reset(); | 967 client->Reset(); |
| 932 client.task_runner().RunPendingTasks(); // Run posted deadline. | 968 client->task_runner().RunPendingTasks(); // Run posted deadline. |
| 933 EXPECT_EQ(0, client.num_draws()); | 969 EXPECT_EQ(0, client->num_draws()); |
| 934 EXPECT_FALSE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); | 970 EXPECT_FALSE(client->HasAction("ScheduledActionDrawAndSwapIfPossible")); |
| 935 EXPECT_TRUE(client.HasAction("ScheduledActionPrepareTiles")); | 971 EXPECT_TRUE(client->HasAction("ScheduledActionPrepareTiles")); |
| 936 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 972 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); |
| 937 } | 973 } |
| 938 | 974 |
| 939 // Test that PrepareTiles only happens once per frame. If an external caller | 975 // Test that PrepareTiles only happens once per frame. If an external caller |
| 940 // initiates it, then the state machine should not PrepareTiles on that frame. | 976 // initiates it, then the state machine should not PrepareTiles on that frame. |
| 941 TEST(SchedulerTest, PrepareTilesOncePerFrame) { | 977 TEST_F(SchedulerTest, PrepareTilesOncePerFrame) { |
| 942 FakeSchedulerClient client; | 978 scheduler_settings_.use_external_begin_frame_source = true; |
| 943 SchedulerSettings scheduler_settings; | 979 SetUpScheduler(true); |
| 944 scheduler_settings.use_external_begin_frame_source = true; | |
| 945 | |
| 946 CREATE_SCHEDULER_AND_INIT_SURFACE(scheduler_settings); | |
| 947 | 980 |
| 948 // If DidPrepareTiles during a frame, then PrepareTiles should not occur | 981 // If DidPrepareTiles during a frame, then PrepareTiles should not occur |
| 949 // again. | 982 // again. |
| 950 scheduler->SetNeedsPrepareTiles(); | 983 scheduler_->SetNeedsPrepareTiles(); |
| 951 scheduler->SetNeedsRedraw(); | 984 scheduler_->SetNeedsRedraw(); |
| 952 client.Reset(); | 985 client_->Reset(); |
| 953 EXPECT_SCOPED(client.AdvanceFrame()); | 986 EXPECT_SCOPED(client_->AdvanceFrame()); |
| 954 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 987 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
| 955 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); | 988 EXPECT_ACTION("ScheduledActionAnimate", client_, 1, 2); |
| 956 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 989 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
| 957 | 990 |
| 958 EXPECT_TRUE(scheduler->PrepareTilesPending()); | 991 EXPECT_TRUE(scheduler_->PrepareTilesPending()); |
| 959 scheduler->DidPrepareTiles(); // An explicit PrepareTiles. | 992 scheduler_->DidPrepareTiles(); // An explicit PrepareTiles. |
| 960 EXPECT_FALSE(scheduler->PrepareTilesPending()); | 993 EXPECT_FALSE(scheduler_->PrepareTilesPending()); |
| 961 | 994 |
| 962 client.Reset(); | 995 client_->Reset(); |
| 963 client.task_runner().RunPendingTasks(); // Run posted deadline. | 996 client_->task_runner().RunPendingTasks(); // Run posted deadline. |
| 964 EXPECT_EQ(1, client.num_draws()); | 997 EXPECT_EQ(1, client_->num_draws()); |
| 965 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); | 998 EXPECT_TRUE(client_->HasAction("ScheduledActionDrawAndSwapIfPossible")); |
| 966 EXPECT_FALSE(client.HasAction("ScheduledActionPrepareTiles")); | 999 EXPECT_FALSE(client_->HasAction("ScheduledActionPrepareTiles")); |
| 967 EXPECT_FALSE(scheduler->RedrawPending()); | 1000 EXPECT_FALSE(scheduler_->RedrawPending()); |
| 968 EXPECT_FALSE(scheduler->PrepareTilesPending()); | 1001 EXPECT_FALSE(scheduler_->PrepareTilesPending()); |
| 969 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 1002 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); |
| 970 | 1003 |
| 971 // Next frame without DidPrepareTiles should PrepareTiles with draw. | 1004 // Next frame without DidPrepareTiles should PrepareTiles with draw. |
| 972 scheduler->SetNeedsPrepareTiles(); | 1005 scheduler_->SetNeedsPrepareTiles(); |
| 973 scheduler->SetNeedsRedraw(); | 1006 scheduler_->SetNeedsRedraw(); |
| 974 client.Reset(); | 1007 client_->Reset(); |
| 975 EXPECT_SCOPED(client.AdvanceFrame()); | 1008 EXPECT_SCOPED(client_->AdvanceFrame()); |
| 976 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 1009 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
| 977 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); | 1010 EXPECT_ACTION("ScheduledActionAnimate", client_, 1, 2); |
| 978 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1011 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
| 979 | 1012 |
| 980 client.Reset(); | 1013 client_->Reset(); |
| 981 client.task_runner().RunPendingTasks(); // Run posted deadline. | 1014 client_->task_runner().RunPendingTasks(); // Run posted deadline. |
| 982 EXPECT_EQ(1, client.num_draws()); | 1015 EXPECT_EQ(1, client_->num_draws()); |
| 983 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); | 1016 EXPECT_TRUE(client_->HasAction("ScheduledActionDrawAndSwapIfPossible")); |
| 984 EXPECT_TRUE(client.HasAction("ScheduledActionPrepareTiles")); | 1017 EXPECT_TRUE(client_->HasAction("ScheduledActionPrepareTiles")); |
| 985 EXPECT_LT(client.ActionIndex("ScheduledActionDrawAndSwapIfPossible"), | 1018 EXPECT_LT(client_->ActionIndex("ScheduledActionDrawAndSwapIfPossible"), |
| 986 client.ActionIndex("ScheduledActionPrepareTiles")); | 1019 client_->ActionIndex("ScheduledActionPrepareTiles")); |
| 987 EXPECT_FALSE(scheduler->RedrawPending()); | 1020 EXPECT_FALSE(scheduler_->RedrawPending()); |
| 988 EXPECT_FALSE(scheduler->PrepareTilesPending()); | 1021 EXPECT_FALSE(scheduler_->PrepareTilesPending()); |
| 989 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 1022 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); |
| 990 scheduler->DidPrepareTiles(); // Corresponds to ScheduledActionPrepareTiles | 1023 scheduler_->DidPrepareTiles(); // Corresponds to ScheduledActionPrepareTiles |
| 991 | 1024 |
| 992 // If we get another DidPrepareTiles within the same frame, we should | 1025 // If we get another DidPrepareTiles within the same frame, we should |
| 993 // not PrepareTiles on the next frame. | 1026 // not PrepareTiles on the next frame. |
| 994 scheduler->DidPrepareTiles(); // An explicit PrepareTiles. | 1027 scheduler_->DidPrepareTiles(); // An explicit PrepareTiles. |
| 995 scheduler->SetNeedsPrepareTiles(); | 1028 scheduler_->SetNeedsPrepareTiles(); |
| 996 scheduler->SetNeedsRedraw(); | 1029 scheduler_->SetNeedsRedraw(); |
| 997 client.Reset(); | 1030 client_->Reset(); |
| 998 EXPECT_SCOPED(client.AdvanceFrame()); | 1031 EXPECT_SCOPED(client_->AdvanceFrame()); |
| 999 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 1032 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
| 1000 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); | 1033 EXPECT_ACTION("ScheduledActionAnimate", client_, 1, 2); |
| 1001 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1034 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
| 1002 | 1035 |
| 1003 EXPECT_TRUE(scheduler->PrepareTilesPending()); | 1036 EXPECT_TRUE(scheduler_->PrepareTilesPending()); |
| 1004 | 1037 |
| 1005 client.Reset(); | 1038 client_->Reset(); |
| 1006 client.task_runner().RunPendingTasks(); // Run posted deadline. | 1039 client_->task_runner().RunPendingTasks(); // Run posted deadline. |
| 1007 EXPECT_EQ(1, client.num_draws()); | 1040 EXPECT_EQ(1, client_->num_draws()); |
| 1008 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); | 1041 EXPECT_TRUE(client_->HasAction("ScheduledActionDrawAndSwapIfPossible")); |
| 1009 EXPECT_FALSE(client.HasAction("ScheduledActionPrepareTiles")); | 1042 EXPECT_FALSE(client_->HasAction("ScheduledActionPrepareTiles")); |
| 1010 EXPECT_FALSE(scheduler->RedrawPending()); | 1043 EXPECT_FALSE(scheduler_->RedrawPending()); |
| 1011 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 1044 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); |
| 1012 | 1045 |
| 1013 // If we get another DidPrepareTiles, we should not PrepareTiles on the next | 1046 // If we get another DidPrepareTiles, we should not PrepareTiles on the next |
| 1014 // frame. This verifies we don't alternate calling PrepareTiles once and | 1047 // frame. This verifies we don't alternate calling PrepareTiles once and |
| 1015 // twice. | 1048 // twice. |
| 1016 EXPECT_TRUE(scheduler->PrepareTilesPending()); | 1049 EXPECT_TRUE(scheduler_->PrepareTilesPending()); |
| 1017 scheduler->DidPrepareTiles(); // An explicit PrepareTiles. | 1050 scheduler_->DidPrepareTiles(); // An explicit PrepareTiles. |
| 1018 EXPECT_FALSE(scheduler->PrepareTilesPending()); | 1051 EXPECT_FALSE(scheduler_->PrepareTilesPending()); |
| 1019 scheduler->SetNeedsPrepareTiles(); | 1052 scheduler_->SetNeedsPrepareTiles(); |
| 1020 scheduler->SetNeedsRedraw(); | 1053 scheduler_->SetNeedsRedraw(); |
| 1021 client.Reset(); | 1054 client_->Reset(); |
| 1022 EXPECT_SCOPED(client.AdvanceFrame()); | 1055 EXPECT_SCOPED(client_->AdvanceFrame()); |
| 1023 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 1056 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
| 1024 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); | 1057 EXPECT_ACTION("ScheduledActionAnimate", client_, 1, 2); |
| 1025 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1058 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
| 1026 | 1059 |
| 1027 EXPECT_TRUE(scheduler->PrepareTilesPending()); | 1060 EXPECT_TRUE(scheduler_->PrepareTilesPending()); |
| 1028 | 1061 |
| 1029 client.Reset(); | 1062 client_->Reset(); |
| 1030 client.task_runner().RunPendingTasks(); // Run posted deadline. | 1063 client_->task_runner().RunPendingTasks(); // Run posted deadline. |
| 1031 EXPECT_EQ(1, client.num_draws()); | 1064 EXPECT_EQ(1, client_->num_draws()); |
| 1032 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); | 1065 EXPECT_TRUE(client_->HasAction("ScheduledActionDrawAndSwapIfPossible")); |
| 1033 EXPECT_FALSE(client.HasAction("ScheduledActionPrepareTiles")); | 1066 EXPECT_FALSE(client_->HasAction("ScheduledActionPrepareTiles")); |
| 1034 EXPECT_FALSE(scheduler->RedrawPending()); | 1067 EXPECT_FALSE(scheduler_->RedrawPending()); |
| 1035 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 1068 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); |
| 1036 | 1069 |
| 1037 // Next frame without DidPrepareTiles should PrepareTiles with draw. | 1070 // Next frame without DidPrepareTiles should PrepareTiles with draw. |
| 1038 scheduler->SetNeedsPrepareTiles(); | 1071 scheduler_->SetNeedsPrepareTiles(); |
| 1039 scheduler->SetNeedsRedraw(); | 1072 scheduler_->SetNeedsRedraw(); |
| 1040 client.Reset(); | 1073 client_->Reset(); |
| 1041 EXPECT_SCOPED(client.AdvanceFrame()); | 1074 EXPECT_SCOPED(client_->AdvanceFrame()); |
| 1042 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 1075 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
| 1043 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); | 1076 EXPECT_ACTION("ScheduledActionAnimate", client_, 1, 2); |
| 1044 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1077 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
| 1045 | 1078 |
| 1046 client.Reset(); | 1079 client_->Reset(); |
| 1047 client.task_runner().RunPendingTasks(); // Run posted deadline. | 1080 client_->task_runner().RunPendingTasks(); // Run posted deadline. |
| 1048 EXPECT_EQ(1, client.num_draws()); | 1081 EXPECT_EQ(1, client_->num_draws()); |
| 1049 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); | 1082 EXPECT_TRUE(client_->HasAction("ScheduledActionDrawAndSwapIfPossible")); |
| 1050 EXPECT_TRUE(client.HasAction("ScheduledActionPrepareTiles")); | 1083 EXPECT_TRUE(client_->HasAction("ScheduledActionPrepareTiles")); |
| 1051 EXPECT_LT(client.ActionIndex("ScheduledActionDrawAndSwapIfPossible"), | 1084 EXPECT_LT(client_->ActionIndex("ScheduledActionDrawAndSwapIfPossible"), |
| 1052 client.ActionIndex("ScheduledActionPrepareTiles")); | 1085 client_->ActionIndex("ScheduledActionPrepareTiles")); |
| 1053 EXPECT_FALSE(scheduler->RedrawPending()); | 1086 EXPECT_FALSE(scheduler_->RedrawPending()); |
| 1054 EXPECT_FALSE(scheduler->PrepareTilesPending()); | 1087 EXPECT_FALSE(scheduler_->PrepareTilesPending()); |
| 1055 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 1088 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); |
| 1056 scheduler->DidPrepareTiles(); // Corresponds to ScheduledActionPrepareTiles | 1089 scheduler_->DidPrepareTiles(); // Corresponds to ScheduledActionPrepareTiles |
| 1057 } | 1090 } |
| 1058 | 1091 |
| 1059 TEST(SchedulerTest, TriggerBeginFrameDeadlineEarly) { | 1092 TEST_F(SchedulerTest, TriggerBeginFrameDeadlineEarly) { |
| 1060 SchedulerClientNeedsPrepareTilesInDraw client; | 1093 SchedulerClientNeedsPrepareTilesInDraw* client = |
| 1061 SchedulerSettings scheduler_settings; | 1094 new SchedulerClientNeedsPrepareTilesInDraw; |
| 1062 scheduler_settings.use_external_begin_frame_source = true; | 1095 scheduler_settings_.use_external_begin_frame_source = true; |
| 1063 | 1096 SetUpScheduler(client, true); |
| 1064 CREATE_SCHEDULER_AND_INIT_SURFACE(scheduler_settings); | 1097 |
| 1065 | 1098 scheduler_->SetNeedsRedraw(); |
| 1066 scheduler->SetNeedsRedraw(); | 1099 EXPECT_SCOPED(client->AdvanceFrame()); |
| 1067 EXPECT_SCOPED(client.AdvanceFrame()); | |
| 1068 | 1100 |
| 1069 // The deadline should be zero since there is no work other than drawing | 1101 // The deadline should be zero since there is no work other than drawing |
| 1070 // pending. | 1102 // pending. |
| 1071 EXPECT_EQ(base::TimeTicks(), client.posted_begin_impl_frame_deadline()); | 1103 EXPECT_EQ(base::TimeTicks(), client->posted_begin_impl_frame_deadline()); |
| 1072 } | 1104 } |
| 1073 | 1105 |
| 1074 class SchedulerClientWithFixedEstimates : public FakeSchedulerClient { | 1106 class SchedulerClientWithFixedEstimates : public FakeSchedulerClient { |
| 1075 public: | 1107 public: |
| 1076 SchedulerClientWithFixedEstimates( | 1108 SchedulerClientWithFixedEstimates( |
| 1077 base::TimeDelta draw_duration, | 1109 base::TimeDelta draw_duration, |
| 1078 base::TimeDelta begin_main_frame_to_commit_duration, | 1110 base::TimeDelta begin_main_frame_to_commit_duration, |
| 1079 base::TimeDelta commit_to_activate_duration) | 1111 base::TimeDelta commit_to_activate_duration) |
| 1080 : draw_duration_(draw_duration), | 1112 : draw_duration_(draw_duration), |
| 1081 begin_main_frame_to_commit_duration_( | 1113 begin_main_frame_to_commit_duration_( |
| 1082 begin_main_frame_to_commit_duration), | 1114 begin_main_frame_to_commit_duration), |
| 1083 commit_to_activate_duration_(commit_to_activate_duration) {} | 1115 commit_to_activate_duration_(commit_to_activate_duration) {} |
| 1084 | 1116 |
| 1085 base::TimeDelta DrawDurationEstimate() override { return draw_duration_; } | 1117 base::TimeDelta DrawDurationEstimate() override { return draw_duration_; } |
| 1086 base::TimeDelta BeginMainFrameToCommitDurationEstimate() override { | 1118 base::TimeDelta BeginMainFrameToCommitDurationEstimate() override { |
| 1087 return begin_main_frame_to_commit_duration_; | 1119 return begin_main_frame_to_commit_duration_; |
| 1088 } | 1120 } |
| 1089 base::TimeDelta CommitToActivateDurationEstimate() override { | 1121 base::TimeDelta CommitToActivateDurationEstimate() override { |
| 1090 return commit_to_activate_duration_; | 1122 return commit_to_activate_duration_; |
| 1091 } | 1123 } |
| 1092 | 1124 |
| 1093 private: | 1125 private: |
| 1094 base::TimeDelta draw_duration_; | 1126 base::TimeDelta draw_duration_; |
| 1095 base::TimeDelta begin_main_frame_to_commit_duration_; | 1127 base::TimeDelta begin_main_frame_to_commit_duration_; |
| 1096 base::TimeDelta commit_to_activate_duration_; | 1128 base::TimeDelta commit_to_activate_duration_; |
| 1097 }; | 1129 }; |
| 1098 | 1130 |
| 1099 void MainFrameInHighLatencyMode(int64 begin_main_frame_to_commit_estimate_in_ms, | 1131 void SchedulerTest::MainFrameInHighLatencyMode( |
| 1100 int64 commit_to_activate_estimate_in_ms, | 1132 int64 begin_main_frame_to_commit_estimate_in_ms, |
| 1101 bool impl_latency_takes_priority, | 1133 int64 commit_to_activate_estimate_in_ms, |
| 1102 bool should_send_begin_main_frame) { | 1134 bool impl_latency_takes_priority, |
| 1135 bool should_send_begin_main_frame) { | |
| 1103 // Set up client with specified estimates (draw duration is set to 1). | 1136 // Set up client with specified estimates (draw duration is set to 1). |
| 1104 SchedulerClientWithFixedEstimates client( | 1137 SchedulerClientWithFixedEstimates* client = |
| 1105 base::TimeDelta::FromMilliseconds(1), | 1138 new SchedulerClientWithFixedEstimates( |
| 1106 base::TimeDelta::FromMilliseconds( | 1139 base::TimeDelta::FromMilliseconds(1), |
| 1107 begin_main_frame_to_commit_estimate_in_ms), | 1140 base::TimeDelta::FromMilliseconds( |
| 1108 base::TimeDelta::FromMilliseconds(commit_to_activate_estimate_in_ms)); | 1141 begin_main_frame_to_commit_estimate_in_ms), |
| 1109 SchedulerSettings scheduler_settings; | 1142 base::TimeDelta::FromMilliseconds(commit_to_activate_estimate_in_ms)); |
| 1110 scheduler_settings.use_external_begin_frame_source = true; | 1143 |
| 1111 | 1144 scheduler_settings_.use_external_begin_frame_source = true; |
| 1112 CREATE_SCHEDULER_AND_INIT_SURFACE(scheduler_settings); | 1145 SetUpScheduler(client, true); |
| 1113 | 1146 |
| 1114 scheduler->SetImplLatencyTakesPriority(impl_latency_takes_priority); | 1147 scheduler_->SetImplLatencyTakesPriority(impl_latency_takes_priority); |
| 1115 | 1148 |
| 1116 // Impl thread hits deadline before commit finishes. | 1149 // Impl thread hits deadline before commit finishes. |
| 1117 scheduler->SetNeedsCommit(); | 1150 scheduler_->SetNeedsCommit(); |
| 1118 EXPECT_FALSE(scheduler->MainThreadIsInHighLatencyMode()); | 1151 EXPECT_FALSE(scheduler_->MainThreadIsInHighLatencyMode()); |
| 1119 EXPECT_SCOPED(client.AdvanceFrame()); | 1152 EXPECT_SCOPED(client->AdvanceFrame()); |
| 1120 EXPECT_FALSE(scheduler->MainThreadIsInHighLatencyMode()); | 1153 EXPECT_FALSE(scheduler_->MainThreadIsInHighLatencyMode()); |
| 1121 client.task_runner().RunPendingTasks(); // Run posted deadline. | 1154 client->task_runner().RunPendingTasks(); // Run posted deadline. |
| 1122 EXPECT_TRUE(scheduler->MainThreadIsInHighLatencyMode()); | 1155 EXPECT_TRUE(scheduler_->MainThreadIsInHighLatencyMode()); |
| 1123 scheduler->NotifyBeginMainFrameStarted(); | 1156 scheduler_->NotifyBeginMainFrameStarted(); |
| 1124 scheduler->NotifyReadyToCommit(); | 1157 scheduler_->NotifyReadyToCommit(); |
| 1125 EXPECT_TRUE(scheduler->MainThreadIsInHighLatencyMode()); | 1158 EXPECT_TRUE(scheduler_->MainThreadIsInHighLatencyMode()); |
| 1126 EXPECT_TRUE(client.HasAction("ScheduledActionSendBeginMainFrame")); | 1159 EXPECT_TRUE(client->HasAction("ScheduledActionSendBeginMainFrame")); |
| 1127 | 1160 |
| 1128 client.Reset(); | 1161 client->Reset(); |
| 1129 scheduler->SetNeedsCommit(); | 1162 scheduler_->SetNeedsCommit(); |
| 1130 EXPECT_TRUE(scheduler->MainThreadIsInHighLatencyMode()); | 1163 EXPECT_TRUE(scheduler_->MainThreadIsInHighLatencyMode()); |
| 1131 EXPECT_SCOPED(client.AdvanceFrame()); | 1164 EXPECT_SCOPED(client->AdvanceFrame()); |
| 1132 EXPECT_TRUE(scheduler->MainThreadIsInHighLatencyMode()); | 1165 EXPECT_TRUE(scheduler_->MainThreadIsInHighLatencyMode()); |
| 1133 client.task_runner().RunPendingTasks(); // Run posted deadline. | 1166 client->task_runner().RunPendingTasks(); // Run posted deadline. |
| 1134 EXPECT_EQ(scheduler->MainThreadIsInHighLatencyMode(), | 1167 EXPECT_EQ(scheduler_->MainThreadIsInHighLatencyMode(), |
| 1135 should_send_begin_main_frame); | 1168 should_send_begin_main_frame); |
| 1136 EXPECT_EQ(client.HasAction("ScheduledActionSendBeginMainFrame"), | 1169 EXPECT_EQ(client->HasAction("ScheduledActionSendBeginMainFrame"), |
| 1137 should_send_begin_main_frame); | 1170 should_send_begin_main_frame); |
| 1138 } | 1171 } |
| 1139 | 1172 |
| 1140 TEST(SchedulerTest, | 1173 TEST_F(SchedulerTest, |
| 1141 SkipMainFrameIfHighLatencyAndCanCommitAndActivateBeforeDeadline) { | 1174 SkipMainFrameIfHighLatencyAndCanCommitAndActivateBeforeDeadline) { |
| 1142 // Set up client so that estimates indicate that we can commit and activate | 1175 // Set up client so that estimates indicate that we can commit and activate |
| 1143 // before the deadline (~8ms by default). | 1176 // before the deadline (~8ms by default). |
| 1144 MainFrameInHighLatencyMode(1, 1, false, false); | 1177 MainFrameInHighLatencyMode(1, 1, false, false); |
| 1145 } | 1178 } |
| 1146 | 1179 |
| 1147 TEST(SchedulerTest, NotSkipMainFrameIfHighLatencyAndCanCommitTooLong) { | 1180 TEST_F(SchedulerTest, NotSkipMainFrameIfHighLatencyAndCanCommitTooLong) { |
| 1148 // Set up client so that estimates indicate that the commit cannot finish | 1181 // Set up client so that estimates indicate that the commit cannot finish |
| 1149 // before the deadline (~8ms by default). | 1182 // before the deadline (~8ms by default). |
| 1150 MainFrameInHighLatencyMode(10, 1, false, true); | 1183 MainFrameInHighLatencyMode(10, 1, false, true); |
| 1151 } | 1184 } |
| 1152 | 1185 |
| 1153 TEST(SchedulerTest, NotSkipMainFrameIfHighLatencyAndCanActivateTooLong) { | 1186 TEST_F(SchedulerTest, NotSkipMainFrameIfHighLatencyAndCanActivateTooLong) { |
| 1154 // Set up client so that estimates indicate that the activate cannot finish | 1187 // Set up client so that estimates indicate that the activate cannot finish |
| 1155 // before the deadline (~8ms by default). | 1188 // before the deadline (~8ms by default). |
| 1156 MainFrameInHighLatencyMode(1, 10, false, true); | 1189 MainFrameInHighLatencyMode(1, 10, false, true); |
| 1157 } | 1190 } |
| 1158 | 1191 |
| 1159 TEST(SchedulerTest, NotSkipMainFrameInPreferImplLatencyMode) { | 1192 TEST_F(SchedulerTest, NotSkipMainFrameInPreferImplLatencyMode) { |
| 1160 // Set up client so that estimates indicate that we can commit and activate | 1193 // Set up client so that estimates indicate that we can commit and activate |
| 1161 // before the deadline (~8ms by default), but also enable impl latency takes | 1194 // before the deadline (~8ms by default), but also enable impl latency takes |
| 1162 // priority mode. | 1195 // priority mode. |
| 1163 MainFrameInHighLatencyMode(1, 1, true, true); | 1196 MainFrameInHighLatencyMode(1, 1, true, true); |
| 1164 } | 1197 } |
| 1165 | 1198 |
| 1166 TEST(SchedulerTest, PollForCommitCompletion) { | 1199 TEST_F(SchedulerTest, PollForCommitCompletion) { |
| 1167 // Since we are simulating a long commit, set up a client with draw duration | 1200 // Since we are simulating a long commit, set up a client with draw duration |
| 1168 // estimates that prevent skipping main frames to get to low latency mode. | 1201 // estimates that prevent skipping main frames to get to low latency mode. |
| 1169 SchedulerClientWithFixedEstimates client( | 1202 SchedulerClientWithFixedEstimates* client = |
| 1170 base::TimeDelta::FromMilliseconds(1), | 1203 new SchedulerClientWithFixedEstimates( |
| 1171 base::TimeDelta::FromMilliseconds(32), | 1204 base::TimeDelta::FromMilliseconds(1), |
| 1172 base::TimeDelta::FromMilliseconds(32)); | 1205 base::TimeDelta::FromMilliseconds(32), |
| 1173 SchedulerSettings scheduler_settings; | 1206 base::TimeDelta::FromMilliseconds(32)); |
| 1174 scheduler_settings.use_external_begin_frame_source = true; | 1207 scheduler_settings_.use_external_begin_frame_source = true; |
| 1175 | 1208 SetUpScheduler(client, true); |
| 1176 CREATE_SCHEDULER_AND_INIT_SURFACE(scheduler_settings); | 1209 |
| 1177 | 1210 client->set_log_anticipated_draw_time_change(true); |
| 1178 client.set_log_anticipated_draw_time_change(true); | |
| 1179 | 1211 |
| 1180 BeginFrameArgs frame_args = | 1212 BeginFrameArgs frame_args = |
| 1181 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, client.now_src()); | 1213 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, client->now_src()); |
| 1182 frame_args.interval = base::TimeDelta::FromMilliseconds(1000); | 1214 frame_args.interval = base::TimeDelta::FromMilliseconds(1000); |
| 1183 | 1215 |
| 1184 // At this point, we've drawn a frame. Start another commit, but hold off on | 1216 // At this point, we've drawn a frame. Start another commit, but hold off on |
| 1185 // the NotifyReadyToCommit for now. | 1217 // the NotifyReadyToCommit for now. |
| 1186 EXPECT_FALSE(scheduler->CommitPending()); | 1218 EXPECT_FALSE(scheduler_->CommitPending()); |
| 1187 scheduler->SetNeedsCommit(); | 1219 scheduler_->SetNeedsCommit(); |
| 1188 client.fake_external_begin_frame_source()->TestOnBeginFrame(frame_args); | 1220 client->fake_external_begin_frame_source()->TestOnBeginFrame(frame_args); |
| 1189 EXPECT_TRUE(scheduler->CommitPending()); | 1221 EXPECT_TRUE(scheduler_->CommitPending()); |
| 1190 | 1222 |
| 1191 // Draw and swap the frame, but don't ack the swap to simulate the Browser | 1223 // Draw and swap the frame, but don't ack the swap to simulate the Browser |
| 1192 // blocking on the renderer. | 1224 // blocking on the renderer. |
| 1193 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1225 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
| 1194 client.task_runner().RunPendingTasks(); // Run posted deadline. | 1226 client->task_runner().RunPendingTasks(); // Run posted deadline. |
| 1195 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 1227 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); |
| 1196 scheduler->DidSwapBuffers(); | 1228 scheduler_->DidSwapBuffers(); |
| 1197 | 1229 |
| 1198 // Spin the event loop a few times and make sure we get more | 1230 // Spin the event loop a few times and make sure we get more |
| 1199 // DidAnticipateDrawTimeChange calls every time. | 1231 // DidAnticipateDrawTimeChange calls every time. |
| 1200 int actions_so_far = client.num_actions_(); | 1232 int actions_so_far = client->num_actions_(); |
| 1201 | 1233 |
| 1202 // Does three iterations to make sure that the timer is properly repeating. | 1234 // Does three iterations to make sure that the timer is properly repeating. |
| 1203 for (int i = 0; i < 3; ++i) { | 1235 for (int i = 0; i < 3; ++i) { |
| 1204 EXPECT_EQ((frame_args.interval * 2).InMicroseconds(), | 1236 EXPECT_EQ((frame_args.interval * 2).InMicroseconds(), |
| 1205 client.task_runner().DelayToNextTaskTime().InMicroseconds()) | 1237 client->task_runner().DelayToNextTaskTime().InMicroseconds()) |
| 1206 << scheduler->AsValue()->ToString(); | 1238 << scheduler_->AsValue()->ToString(); |
| 1207 client.task_runner().RunPendingTasks(); | 1239 client->task_runner().RunPendingTasks(); |
| 1208 EXPECT_GT(client.num_actions_(), actions_so_far); | 1240 EXPECT_GT(client->num_actions_(), actions_so_far); |
| 1209 EXPECT_STREQ(client.Action(client.num_actions_() - 1), | 1241 EXPECT_STREQ(client->Action(client->num_actions_() - 1), |
| 1210 "DidAnticipatedDrawTimeChange"); | 1242 "DidAnticipatedDrawTimeChange"); |
| 1211 actions_so_far = client.num_actions_(); | 1243 actions_so_far = client->num_actions_(); |
| 1212 } | 1244 } |
| 1213 | 1245 |
| 1214 // Do the same thing after BeginMainFrame starts but still before activation. | 1246 // Do the same thing after BeginMainFrame starts but still before activation. |
| 1215 scheduler->NotifyBeginMainFrameStarted(); | 1247 scheduler_->NotifyBeginMainFrameStarted(); |
| 1216 for (int i = 0; i < 3; ++i) { | 1248 for (int i = 0; i < 3; ++i) { |
| 1217 EXPECT_EQ((frame_args.interval * 2).InMicroseconds(), | 1249 EXPECT_EQ((frame_args.interval * 2).InMicroseconds(), |
| 1218 client.task_runner().DelayToNextTaskTime().InMicroseconds()) | 1250 client->task_runner().DelayToNextTaskTime().InMicroseconds()) |
| 1219 << scheduler->AsValue()->ToString(); | 1251 << scheduler_->AsValue()->ToString(); |
| 1220 client.task_runner().RunPendingTasks(); | 1252 client->task_runner().RunPendingTasks(); |
| 1221 EXPECT_GT(client.num_actions_(), actions_so_far); | 1253 EXPECT_GT(client->num_actions_(), actions_so_far); |
| 1222 EXPECT_STREQ(client.Action(client.num_actions_() - 1), | 1254 EXPECT_STREQ(client->Action(client->num_actions_() - 1), |
| 1223 "DidAnticipatedDrawTimeChange"); | 1255 "DidAnticipatedDrawTimeChange"); |
| 1224 actions_so_far = client.num_actions_(); | 1256 actions_so_far = client->num_actions_(); |
| 1225 } | 1257 } |
| 1226 } | 1258 } |
| 1227 | 1259 |
| 1228 TEST(SchedulerTest, BeginRetroFrame) { | 1260 TEST_F(SchedulerTest, BeginRetroFrame) { |
| 1229 FakeSchedulerClient client; | 1261 scheduler_settings_.use_external_begin_frame_source = true; |
| 1230 SchedulerSettings scheduler_settings; | 1262 SetUpScheduler(true); |
| 1231 scheduler_settings.use_external_begin_frame_source = true; | |
| 1232 | |
| 1233 CREATE_SCHEDULER_AND_INIT_SURFACE(scheduler_settings); | |
| 1234 | 1263 |
| 1235 // SetNeedsCommit should begin the frame on the next BeginImplFrame. | 1264 // SetNeedsCommit should begin the frame on the next BeginImplFrame. |
| 1236 scheduler->SetNeedsCommit(); | 1265 scheduler_->SetNeedsCommit(); |
| 1237 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client); | 1266 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client_); |
| 1238 client.Reset(); | 1267 client_->Reset(); |
| 1239 | 1268 |
| 1240 // Create a BeginFrame with a long deadline to avoid race conditions. | 1269 // Create a BeginFrame with a long deadline to avoid race conditions. |
| 1241 // This is the first BeginFrame, which will be handled immediately. | 1270 // This is the first BeginFrame, which will be handled immediately. |
| 1242 BeginFrameArgs args = | 1271 BeginFrameArgs args = |
| 1243 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, client.now_src()); | 1272 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, client_->now_src()); |
| 1244 args.deadline += base::TimeDelta::FromHours(1); | 1273 args.deadline += base::TimeDelta::FromHours(1); |
| 1245 client.fake_external_begin_frame_source()->TestOnBeginFrame(args); | 1274 client_->fake_external_begin_frame_source()->TestOnBeginFrame(args); |
| 1246 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 1275 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
| 1247 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); | 1276 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); |
| 1248 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1277 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
| 1249 EXPECT_TRUE(client.needs_begin_frames()); | 1278 EXPECT_TRUE(client_->needs_begin_frames()); |
| 1250 client.Reset(); | 1279 client_->Reset(); |
| 1251 | 1280 |
| 1252 // Queue BeginFrames while we are still handling the previous BeginFrame. | 1281 // Queue BeginFrames while we are still handling the previous BeginFrame. |
| 1253 args.frame_time += base::TimeDelta::FromSeconds(1); | 1282 args.frame_time += base::TimeDelta::FromSeconds(1); |
| 1254 client.fake_external_begin_frame_source()->TestOnBeginFrame(args); | 1283 client_->fake_external_begin_frame_source()->TestOnBeginFrame(args); |
| 1255 args.frame_time += base::TimeDelta::FromSeconds(1); | 1284 args.frame_time += base::TimeDelta::FromSeconds(1); |
| 1256 client.fake_external_begin_frame_source()->TestOnBeginFrame(args); | 1285 client_->fake_external_begin_frame_source()->TestOnBeginFrame(args); |
| 1257 | 1286 |
| 1258 // If we don't swap on the deadline, we wait for the next BeginImplFrame. | 1287 // If we don't swap on the deadline, we wait for the next BeginImplFrame. |
| 1259 client.task_runner().RunPendingTasks(); // Run posted deadline. | 1288 client_->task_runner().RunPendingTasks(); // Run posted deadline. |
| 1260 EXPECT_NO_ACTION(client); | 1289 EXPECT_NO_ACTION(client_); |
| 1261 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 1290 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); |
| 1262 EXPECT_TRUE(client.needs_begin_frames()); | 1291 EXPECT_TRUE(client_->needs_begin_frames()); |
| 1263 client.Reset(); | 1292 client_->Reset(); |
| 1264 | 1293 |
| 1265 // NotifyReadyToCommit should trigger the commit. | 1294 // NotifyReadyToCommit should trigger the commit. |
| 1266 scheduler->NotifyBeginMainFrameStarted(); | 1295 scheduler_->NotifyBeginMainFrameStarted(); |
| 1267 scheduler->NotifyReadyToCommit(); | 1296 scheduler_->NotifyReadyToCommit(); |
| 1268 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); | 1297 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_); |
| 1269 EXPECT_TRUE(client.needs_begin_frames()); | 1298 EXPECT_TRUE(client_->needs_begin_frames()); |
| 1270 client.Reset(); | 1299 client_->Reset(); |
| 1271 | 1300 |
| 1272 // BeginImplFrame should prepare the draw. | 1301 // BeginImplFrame should prepare the draw. |
| 1273 client.task_runner().RunPendingTasks(); // Run posted BeginRetroFrame. | 1302 client_->task_runner().RunPendingTasks(); // Run posted BeginRetroFrame. |
| 1274 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 1303 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
| 1275 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); | 1304 EXPECT_ACTION("ScheduledActionAnimate", client_, 1, 2); |
| 1276 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1305 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
| 1277 EXPECT_TRUE(client.needs_begin_frames()); | 1306 EXPECT_TRUE(client_->needs_begin_frames()); |
| 1278 client.Reset(); | 1307 client_->Reset(); |
| 1279 | 1308 |
| 1280 // BeginImplFrame deadline should draw. | 1309 // BeginImplFrame deadline should draw. |
| 1281 client.task_runner().RunPendingTasks(); // Run posted deadline. | 1310 client_->task_runner().RunPendingTasks(); // Run posted deadline. |
| 1282 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 1); | 1311 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 0, 1); |
| 1283 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 1312 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); |
| 1284 EXPECT_TRUE(client.needs_begin_frames()); | 1313 EXPECT_TRUE(client_->needs_begin_frames()); |
| 1285 client.Reset(); | 1314 client_->Reset(); |
| 1286 | 1315 |
| 1287 // The following BeginImplFrame deadline should SetNeedsBeginFrame(false) | 1316 // The following BeginImplFrame deadline should SetNeedsBeginFrame(false) |
| 1288 // to avoid excessive toggles. | 1317 // to avoid excessive toggles. |
| 1289 client.task_runner().RunPendingTasks(); // Run posted BeginRetroFrame. | 1318 client_->task_runner().RunPendingTasks(); // Run posted BeginRetroFrame. |
| 1290 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); | 1319 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client_); |
| 1291 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1320 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
| 1292 client.Reset(); | 1321 client_->Reset(); |
| 1293 | 1322 |
| 1294 client.task_runner().RunPendingTasks(); // Run posted deadline. | 1323 client_->task_runner().RunPendingTasks(); // Run posted deadline. |
| 1295 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(false)", client); | 1324 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(false)", client_); |
| 1296 client.Reset(); | 1325 client_->Reset(); |
| 1297 } | 1326 } |
| 1298 | 1327 |
| 1299 TEST(SchedulerTest, BeginRetroFrame_SwapThrottled) { | 1328 TEST_F(SchedulerTest, BeginRetroFrame_SwapThrottled) { |
| 1300 FakeSchedulerClient client; | 1329 scheduler_settings_.use_external_begin_frame_source = true; |
| 1301 SchedulerSettings scheduler_settings; | 1330 SetUpScheduler(true); |
| 1302 scheduler_settings.use_external_begin_frame_source = true; | 1331 |
| 1303 | 1332 scheduler_->SetEstimatedParentDrawTime(base::TimeDelta::FromMicroseconds(1)); |
| 1304 CREATE_SCHEDULER_AND_INIT_SURFACE(scheduler_settings); | |
| 1305 scheduler->SetEstimatedParentDrawTime(base::TimeDelta::FromMicroseconds(1)); | |
| 1306 | 1333 |
| 1307 // To test swap ack throttling, this test disables automatic swap acks. | 1334 // To test swap ack throttling, this test disables automatic swap acks. |
| 1308 scheduler->SetMaxSwapsPending(1); | 1335 scheduler_->SetMaxSwapsPending(1); |
| 1309 client.SetAutomaticSwapAck(false); | 1336 client_->SetAutomaticSwapAck(false); |
| 1310 | 1337 |
| 1311 // SetNeedsCommit should begin the frame on the next BeginImplFrame. | 1338 // SetNeedsCommit should begin the frame on the next BeginImplFrame. |
| 1312 client.Reset(); | 1339 client_->Reset(); |
| 1313 scheduler->SetNeedsCommit(); | 1340 scheduler_->SetNeedsCommit(); |
| 1314 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client); | 1341 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client_); |
| 1315 client.Reset(); | 1342 client_->Reset(); |
| 1316 | 1343 |
| 1317 EXPECT_SCOPED(client.AdvanceFrame()); | 1344 EXPECT_SCOPED(client_->AdvanceFrame()); |
| 1318 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 1345 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
| 1319 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); | 1346 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); |
| 1320 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1347 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
| 1321 EXPECT_TRUE(client.needs_begin_frames()); | 1348 EXPECT_TRUE(client_->needs_begin_frames()); |
| 1322 client.Reset(); | 1349 client_->Reset(); |
| 1323 | 1350 |
| 1324 // Queue BeginFrame while we are still handling the previous BeginFrame. | 1351 // Queue BeginFrame while we are still handling the previous BeginFrame. |
| 1325 client.SendNextBeginFrame(); | 1352 client_->SendNextBeginFrame(); |
| 1326 EXPECT_NO_ACTION(client); | 1353 EXPECT_NO_ACTION(client_); |
| 1327 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1354 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
| 1328 EXPECT_TRUE(client.needs_begin_frames()); | 1355 EXPECT_TRUE(client_->needs_begin_frames()); |
| 1329 client.Reset(); | 1356 client_->Reset(); |
| 1330 | 1357 |
| 1331 // NotifyReadyToCommit should trigger the pending commit and draw. | 1358 // NotifyReadyToCommit should trigger the pending commit and draw. |
| 1332 scheduler->NotifyBeginMainFrameStarted(); | 1359 scheduler_->NotifyBeginMainFrameStarted(); |
| 1333 scheduler->NotifyReadyToCommit(); | 1360 scheduler_->NotifyReadyToCommit(); |
| 1334 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); | 1361 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_); |
| 1335 EXPECT_TRUE(client.needs_begin_frames()); | 1362 EXPECT_TRUE(client_->needs_begin_frames()); |
| 1336 client.Reset(); | 1363 client_->Reset(); |
| 1337 | 1364 |
| 1338 // Swapping will put us into a swap throttled state. | 1365 // Swapping will put us into a swap throttled state. |
| 1339 // Run posted deadline. | 1366 // Run posted deadline. |
| 1340 client.task_runner().RunTasksWhile(client.ImplFrameDeadlinePending(true)); | 1367 client_->task_runner().RunTasksWhile(client_->ImplFrameDeadlinePending(true)); |
| 1341 EXPECT_ACTION("ScheduledActionAnimate", client, 0, 2); | 1368 EXPECT_ACTION("ScheduledActionAnimate", client_, 0, 2); |
| 1342 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 1, 2); | 1369 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 1, 2); |
| 1343 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 1370 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); |
| 1344 EXPECT_TRUE(client.needs_begin_frames()); | 1371 EXPECT_TRUE(client_->needs_begin_frames()); |
| 1345 client.Reset(); | 1372 client_->Reset(); |
| 1346 | 1373 |
| 1347 // While swap throttled, BeginRetroFrames should trigger BeginImplFrames | 1374 // While swap throttled, BeginRetroFrames should trigger BeginImplFrames |
| 1348 // but not a BeginMainFrame or draw. | 1375 // but not a BeginMainFrame or draw. |
| 1349 scheduler->SetNeedsCommit(); | 1376 scheduler_->SetNeedsCommit(); |
| 1350 scheduler->SetNeedsRedraw(); | 1377 scheduler_->SetNeedsRedraw(); |
| 1351 // Run posted BeginRetroFrame. | 1378 // Run posted BeginRetroFrame. |
| 1352 client.task_runner().RunTasksWhile(client.ImplFrameDeadlinePending(false)); | 1379 client_->task_runner().RunTasksWhile( |
| 1353 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 1380 client_->ImplFrameDeadlinePending(false)); |
| 1354 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); | 1381 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
| 1355 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1382 EXPECT_ACTION("ScheduledActionAnimate", client_, 1, 2); |
| 1356 EXPECT_TRUE(client.needs_begin_frames()); | 1383 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
| 1357 client.Reset(); | 1384 EXPECT_TRUE(client_->needs_begin_frames()); |
| 1385 client_->Reset(); | |
| 1358 | 1386 |
| 1359 // Let time pass sufficiently beyond the regular deadline but not beyond the | 1387 // Let time pass sufficiently beyond the regular deadline but not beyond the |
| 1360 // late deadline. | 1388 // late deadline. |
| 1361 client.now_src()->AdvanceNow(BeginFrameArgs::DefaultInterval() - | 1389 client_->now_src()->AdvanceNow(BeginFrameArgs::DefaultInterval() - |
| 1362 base::TimeDelta::FromMicroseconds(1)); | 1390 base::TimeDelta::FromMicroseconds(1)); |
| 1363 client.task_runner().RunUntilTime(client.now_src()->Now()); | 1391 client_->task_runner().RunUntilTime(client_->now_src()->Now()); |
| 1364 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1392 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
| 1365 | 1393 |
| 1366 // Take us out of a swap throttled state. | 1394 // Take us out of a swap throttled state. |
| 1367 scheduler->DidSwapBuffersComplete(); | 1395 scheduler_->DidSwapBuffersComplete(); |
| 1368 EXPECT_SINGLE_ACTION("ScheduledActionSendBeginMainFrame", client); | 1396 EXPECT_SINGLE_ACTION("ScheduledActionSendBeginMainFrame", client_); |
| 1369 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1397 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
| 1370 EXPECT_TRUE(client.needs_begin_frames()); | 1398 EXPECT_TRUE(client_->needs_begin_frames()); |
| 1371 client.Reset(); | 1399 client_->Reset(); |
| 1372 | 1400 |
| 1373 // Verify that the deadline was rescheduled. | 1401 // Verify that the deadline was rescheduled. |
| 1374 client.task_runner().RunUntilTime(client.now_src()->Now()); | 1402 client_->task_runner().RunUntilTime(client_->now_src()->Now()); |
| 1375 EXPECT_SINGLE_ACTION("ScheduledActionDrawAndSwapIfPossible", client); | 1403 EXPECT_SINGLE_ACTION("ScheduledActionDrawAndSwapIfPossible", client_); |
| 1376 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 1404 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); |
| 1377 EXPECT_TRUE(client.needs_begin_frames()); | 1405 EXPECT_TRUE(client_->needs_begin_frames()); |
| 1378 client.Reset(); | 1406 client_->Reset(); |
| 1379 } | 1407 } |
| 1380 | 1408 |
| 1381 TEST(SchedulerTest, RetroFrameDoesNotExpireTooEarly) { | 1409 TEST_F(SchedulerTest, RetroFrameDoesNotExpireTooEarly) { |
| 1382 FakeSchedulerClient client; | 1410 scheduler_settings_.use_external_begin_frame_source = true; |
| 1383 SchedulerSettings scheduler_settings; | 1411 SetUpScheduler(true); |
| 1384 scheduler_settings.use_external_begin_frame_source = true; | 1412 |
| 1385 | 1413 scheduler_->SetNeedsCommit(); |
| 1386 CREATE_SCHEDULER_AND_INIT_SURFACE(scheduler_settings); | 1414 EXPECT_TRUE(client_->needs_begin_frames()); |
| 1387 | 1415 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client_); |
| 1388 scheduler->SetNeedsCommit(); | 1416 |
| 1389 EXPECT_TRUE(client.needs_begin_frames()); | 1417 client_->Reset(); |
| 1390 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client); | 1418 EXPECT_SCOPED(client_->AdvanceFrame()); |
| 1391 | 1419 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
| 1392 client.Reset(); | 1420 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); |
| 1393 EXPECT_SCOPED(client.AdvanceFrame()); | 1421 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
| 1394 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 1422 |
| 1395 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); | 1423 client_->Reset(); |
| 1396 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1424 scheduler_->NotifyBeginMainFrameStarted(); |
| 1397 | 1425 |
| 1398 client.Reset(); | 1426 client_->Reset(); |
| 1399 scheduler->NotifyBeginMainFrameStarted(); | 1427 client_->SendNextBeginFrame(); |
| 1400 | |
| 1401 client.Reset(); | |
| 1402 client.SendNextBeginFrame(); | |
| 1403 // This BeginFrame is queued up as a retro frame. | 1428 // This BeginFrame is queued up as a retro frame. |
| 1404 EXPECT_NO_ACTION(client); | 1429 EXPECT_NO_ACTION(client_); |
| 1405 // The previous deadline is still pending. | 1430 // The previous deadline is still pending. |
| 1406 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1431 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
| 1407 | 1432 |
| 1408 client.Reset(); | 1433 client_->Reset(); |
| 1409 // This commit should schedule the (previous) deadline to trigger immediately. | 1434 // This commit should schedule the (previous) deadline to trigger immediately. |
| 1410 scheduler->NotifyReadyToCommit(); | 1435 scheduler_->NotifyReadyToCommit(); |
| 1411 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); | 1436 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_); |
| 1412 | 1437 |
| 1413 client.Reset(); | 1438 client_->Reset(); |
| 1414 // The deadline task should trigger causing a draw. | 1439 // The deadline task should trigger causing a draw. |
| 1415 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1440 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
| 1416 client.task_runner().RunTasksWhile(client.ImplFrameDeadlinePending(true)); | 1441 client_->task_runner().RunTasksWhile(client_->ImplFrameDeadlinePending(true)); |
| 1417 EXPECT_ACTION("ScheduledActionAnimate", client, 0, 2); | 1442 EXPECT_ACTION("ScheduledActionAnimate", client_, 0, 2); |
| 1418 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 1, 2); | 1443 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 1, 2); |
| 1419 | 1444 |
| 1420 // Keep animating. | 1445 // Keep animating. |
| 1421 client.Reset(); | 1446 client_->Reset(); |
| 1422 scheduler->SetNeedsAnimate(); | 1447 scheduler_->SetNeedsAnimate(); |
| 1423 scheduler->SetNeedsRedraw(); | 1448 scheduler_->SetNeedsRedraw(); |
| 1424 EXPECT_NO_ACTION(client); | 1449 EXPECT_NO_ACTION(client_); |
| 1425 | 1450 |
| 1426 // Let's advance sufficiently past the next frame's deadline. | 1451 // Let's advance sufficiently past the next frame's deadline. |
| 1427 client.now_src()->AdvanceNow( | 1452 client_->now_src()->AdvanceNow( |
| 1428 BeginFrameArgs::DefaultInterval() - | 1453 BeginFrameArgs::DefaultInterval() - |
| 1429 BeginFrameArgs::DefaultEstimatedParentDrawTime() + | 1454 BeginFrameArgs::DefaultEstimatedParentDrawTime() + |
| 1430 base::TimeDelta::FromMicroseconds(1)); | 1455 base::TimeDelta::FromMicroseconds(1)); |
| 1431 | 1456 |
| 1432 // The retro frame hasn't expired yet. | 1457 // The retro frame hasn't expired yet. |
| 1433 client.task_runner().RunTasksWhile(client.ImplFrameDeadlinePending(false)); | 1458 client_->task_runner().RunTasksWhile( |
| 1434 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 1459 client_->ImplFrameDeadlinePending(false)); |
| 1435 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); | 1460 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
| 1436 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1461 EXPECT_ACTION("ScheduledActionAnimate", client_, 1, 2); |
| 1462 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | |
| 1437 | 1463 |
| 1438 // This is an immediate deadline case. | 1464 // This is an immediate deadline case. |
| 1439 client.Reset(); | 1465 client_->Reset(); |
| 1440 client.task_runner().RunPendingTasks(); | 1466 client_->task_runner().RunPendingTasks(); |
| 1441 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 1467 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); |
| 1442 EXPECT_SINGLE_ACTION("ScheduledActionDrawAndSwapIfPossible", client); | 1468 EXPECT_SINGLE_ACTION("ScheduledActionDrawAndSwapIfPossible", client_); |
| 1443 } | 1469 } |
| 1444 | 1470 |
| 1445 TEST(SchedulerTest, RetroFrameDoesNotExpireTooLate) { | 1471 TEST_F(SchedulerTest, RetroFrameDoesNotExpireTooLate) { |
| 1446 FakeSchedulerClient client; | 1472 scheduler_settings_.use_external_begin_frame_source = true; |
| 1447 SchedulerSettings scheduler_settings; | 1473 SetUpScheduler(true); |
| 1448 scheduler_settings.use_external_begin_frame_source = true; | 1474 |
| 1449 | 1475 scheduler_->SetNeedsCommit(); |
| 1450 CREATE_SCHEDULER_AND_INIT_SURFACE(scheduler_settings); | 1476 EXPECT_TRUE(client_->needs_begin_frames()); |
| 1451 | 1477 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client_); |
| 1452 scheduler->SetNeedsCommit(); | 1478 |
| 1453 EXPECT_TRUE(client.needs_begin_frames()); | 1479 client_->Reset(); |
| 1454 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client); | 1480 EXPECT_SCOPED(client_->AdvanceFrame()); |
| 1455 | 1481 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
| 1456 client.Reset(); | 1482 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); |
| 1457 EXPECT_SCOPED(client.AdvanceFrame()); | 1483 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
| 1458 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 1484 |
| 1459 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); | 1485 client_->Reset(); |
| 1460 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1486 scheduler_->NotifyBeginMainFrameStarted(); |
| 1461 | 1487 |
| 1462 client.Reset(); | 1488 client_->Reset(); |
| 1463 scheduler->NotifyBeginMainFrameStarted(); | 1489 client_->SendNextBeginFrame(); |
| 1464 | |
| 1465 client.Reset(); | |
| 1466 client.SendNextBeginFrame(); | |
| 1467 // This BeginFrame is queued up as a retro frame. | 1490 // This BeginFrame is queued up as a retro frame. |
| 1468 EXPECT_NO_ACTION(client); | 1491 EXPECT_NO_ACTION(client_); |
| 1469 // The previous deadline is still pending. | 1492 // The previous deadline is still pending. |
| 1470 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1493 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
| 1471 | 1494 |
| 1472 client.Reset(); | 1495 client_->Reset(); |
| 1473 // This commit should schedule the (previous) deadline to trigger immediately. | 1496 // This commit should schedule the (previous) deadline to trigger immediately. |
| 1474 scheduler->NotifyReadyToCommit(); | 1497 scheduler_->NotifyReadyToCommit(); |
| 1475 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); | 1498 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_); |
| 1476 | 1499 |
| 1477 client.Reset(); | 1500 client_->Reset(); |
| 1478 // The deadline task should trigger causing a draw. | 1501 // The deadline task should trigger causing a draw. |
| 1479 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1502 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
| 1480 client.task_runner().RunTasksWhile(client.ImplFrameDeadlinePending(true)); | 1503 client_->task_runner().RunTasksWhile(client_->ImplFrameDeadlinePending(true)); |
| 1481 EXPECT_ACTION("ScheduledActionAnimate", client, 0, 2); | 1504 EXPECT_ACTION("ScheduledActionAnimate", client_, 0, 2); |
| 1482 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 1, 2); | 1505 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 1, 2); |
| 1483 | 1506 |
| 1484 // Keep animating. | 1507 // Keep animating. |
| 1485 client.Reset(); | 1508 client_->Reset(); |
| 1486 scheduler->SetNeedsAnimate(); | 1509 scheduler_->SetNeedsAnimate(); |
| 1487 scheduler->SetNeedsRedraw(); | 1510 scheduler_->SetNeedsRedraw(); |
| 1488 EXPECT_NO_ACTION(client); | 1511 EXPECT_NO_ACTION(client_); |
| 1489 | 1512 |
| 1490 // Let's advance sufficiently past the next frame's deadline. | 1513 // Let's advance sufficiently past the next frame's deadline. |
| 1491 client.now_src()->AdvanceNow(BeginFrameArgs::DefaultInterval() + | 1514 client_->now_src()->AdvanceNow(BeginFrameArgs::DefaultInterval() + |
| 1492 base::TimeDelta::FromMicroseconds(1)); | 1515 base::TimeDelta::FromMicroseconds(1)); |
| 1493 | 1516 |
| 1494 // The retro frame should've expired. | 1517 // The retro frame should've expired. |
| 1495 EXPECT_NO_ACTION(client); | 1518 EXPECT_NO_ACTION(client_); |
| 1496 } | 1519 } |
| 1497 | 1520 |
| 1498 void BeginFramesNotFromClient(bool use_external_begin_frame_source, | 1521 void SchedulerTest::BeginFramesNotFromClient( |
| 1499 bool throttle_frame_production) { | 1522 bool use_external_begin_frame_source, |
| 1500 FakeSchedulerClient client; | 1523 bool throttle_frame_production) { |
| 1501 SchedulerSettings scheduler_settings; | 1524 scheduler_settings_.use_external_begin_frame_source = |
| 1502 scheduler_settings.use_external_begin_frame_source = | |
| 1503 use_external_begin_frame_source; | 1525 use_external_begin_frame_source; |
| 1504 scheduler_settings.throttle_frame_production = throttle_frame_production; | 1526 scheduler_settings_.throttle_frame_production = throttle_frame_production; |
| 1505 | 1527 SetUpScheduler(true); |
| 1506 CREATE_SCHEDULER_AND_INIT_SURFACE(scheduler_settings); | |
| 1507 | 1528 |
| 1508 // SetNeedsCommit should begin the frame on the next BeginImplFrame | 1529 // SetNeedsCommit should begin the frame on the next BeginImplFrame |
| 1509 // without calling SetNeedsBeginFrame. | 1530 // without calling SetNeedsBeginFrame. |
| 1510 scheduler->SetNeedsCommit(); | 1531 scheduler_->SetNeedsCommit(); |
| 1511 EXPECT_NO_ACTION(client); | 1532 EXPECT_NO_ACTION(client_); |
| 1512 client.Reset(); | 1533 client_->Reset(); |
| 1513 | 1534 |
| 1514 // When the client-driven BeginFrame are disabled, the scheduler posts it's | 1535 // When the client-driven BeginFrame are disabled, the scheduler posts it's |
| 1515 // own BeginFrame tasks. | 1536 // own BeginFrame tasks. |
| 1516 client.task_runner().RunPendingTasks(); // Run posted BeginFrame. | 1537 client_->task_runner().RunPendingTasks(); // Run posted BeginFrame. |
| 1517 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 1538 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
| 1518 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); | 1539 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); |
| 1519 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1540 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
| 1520 client.Reset(); | 1541 client_->Reset(); |
| 1521 | 1542 |
| 1522 // If we don't swap on the deadline, we wait for the next BeginFrame. | 1543 // If we don't swap on the deadline, we wait for the next BeginFrame. |
| 1523 client.task_runner().RunPendingTasks(); // Run posted deadline. | 1544 client_->task_runner().RunPendingTasks(); // Run posted deadline. |
| 1524 EXPECT_NO_ACTION(client); | 1545 EXPECT_NO_ACTION(client_); |
| 1525 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 1546 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); |
| 1526 client.Reset(); | 1547 client_->Reset(); |
| 1527 | 1548 |
| 1528 // NotifyReadyToCommit should trigger the commit. | 1549 // NotifyReadyToCommit should trigger the commit. |
| 1529 scheduler->NotifyBeginMainFrameStarted(); | 1550 scheduler_->NotifyBeginMainFrameStarted(); |
| 1530 scheduler->NotifyReadyToCommit(); | 1551 scheduler_->NotifyReadyToCommit(); |
| 1531 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); | 1552 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_); |
| 1532 client.Reset(); | 1553 client_->Reset(); |
| 1533 | 1554 |
| 1534 // BeginImplFrame should prepare the draw. | 1555 // BeginImplFrame should prepare the draw. |
| 1535 client.task_runner().RunPendingTasks(); // Run posted BeginFrame. | 1556 client_->task_runner().RunPendingTasks(); // Run posted BeginFrame. |
| 1536 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 1557 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
| 1537 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); | 1558 EXPECT_ACTION("ScheduledActionAnimate", client_, 1, 2); |
| 1538 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1559 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
| 1539 client.Reset(); | 1560 client_->Reset(); |
| 1540 | 1561 |
| 1541 // BeginImplFrame deadline should draw. | 1562 // BeginImplFrame deadline should draw. |
| 1542 client.task_runner().RunTasksWhile(client.ImplFrameDeadlinePending(true)); | 1563 client_->task_runner().RunTasksWhile(client_->ImplFrameDeadlinePending(true)); |
| 1543 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 1); | 1564 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 0, 1); |
| 1544 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 1565 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); |
| 1545 client.Reset(); | 1566 client_->Reset(); |
| 1546 | 1567 |
| 1547 // The following BeginImplFrame deadline should SetNeedsBeginFrame(false) | 1568 // The following BeginImplFrame deadline should SetNeedsBeginFrame(false) |
| 1548 // to avoid excessive toggles. | 1569 // to avoid excessive toggles. |
| 1549 client.task_runner().RunPendingTasks(); // Run posted BeginFrame. | 1570 client_->task_runner().RunPendingTasks(); // Run posted BeginFrame. |
| 1550 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); | 1571 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client_); |
| 1551 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1572 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
| 1552 client.Reset(); | 1573 client_->Reset(); |
| 1553 | 1574 |
| 1554 // Make sure SetNeedsBeginFrame isn't called on the client | 1575 // Make sure SetNeedsBeginFrame isn't called on the client |
| 1555 // when the BeginFrame is no longer needed. | 1576 // when the BeginFrame is no longer needed. |
| 1556 client.task_runner().RunPendingTasks(); // Run posted deadline. | 1577 client_->task_runner().RunPendingTasks(); // Run posted deadline. |
| 1557 EXPECT_NO_ACTION(client); | 1578 EXPECT_NO_ACTION(client_); |
| 1558 client.Reset(); | 1579 client_->Reset(); |
| 1559 } | 1580 } |
| 1560 | 1581 |
| 1561 TEST(SchedulerTest, SyntheticBeginFrames) { | 1582 TEST_F(SchedulerTest, SyntheticBeginFrames) { |
| 1562 bool use_external_begin_frame_source = false; | 1583 bool use_external_begin_frame_source = false; |
| 1563 bool throttle_frame_production = true; | 1584 bool throttle_frame_production = true; |
| 1564 BeginFramesNotFromClient(use_external_begin_frame_source, | 1585 BeginFramesNotFromClient(use_external_begin_frame_source, |
| 1565 throttle_frame_production); | 1586 throttle_frame_production); |
| 1566 } | 1587 } |
| 1567 | 1588 |
| 1568 TEST(SchedulerTest, VSyncThrottlingDisabled) { | 1589 TEST_F(SchedulerTest, VSyncThrottlingDisabled) { |
| 1569 bool use_external_begin_frame_source = true; | 1590 bool use_external_begin_frame_source = true; |
| 1570 bool throttle_frame_production = false; | 1591 bool throttle_frame_production = false; |
| 1571 BeginFramesNotFromClient(use_external_begin_frame_source, | 1592 BeginFramesNotFromClient(use_external_begin_frame_source, |
| 1572 throttle_frame_production); | 1593 throttle_frame_production); |
| 1573 } | 1594 } |
| 1574 | 1595 |
| 1575 TEST(SchedulerTest, SyntheticBeginFrames_And_VSyncThrottlingDisabled) { | 1596 TEST_F(SchedulerTest, SyntheticBeginFrames_And_VSyncThrottlingDisabled) { |
| 1576 bool use_external_begin_frame_source = false; | 1597 bool use_external_begin_frame_source = false; |
| 1577 bool throttle_frame_production = false; | 1598 bool throttle_frame_production = false; |
| 1578 BeginFramesNotFromClient(use_external_begin_frame_source, | 1599 BeginFramesNotFromClient(use_external_begin_frame_source, |
| 1579 throttle_frame_production); | 1600 throttle_frame_production); |
| 1580 } | 1601 } |
| 1581 | 1602 |
| 1582 void BeginFramesNotFromClient_SwapThrottled( | 1603 void SchedulerTest::BeginFramesNotFromClient_SwapThrottled( |
| 1583 bool use_external_begin_frame_source, | 1604 bool use_external_begin_frame_source, |
| 1584 bool throttle_frame_production) { | 1605 bool throttle_frame_production) { |
| 1585 FakeSchedulerClient client; | 1606 scheduler_settings_.use_external_begin_frame_source = |
| 1586 SchedulerSettings scheduler_settings; | |
| 1587 scheduler_settings.use_external_begin_frame_source = | |
| 1588 use_external_begin_frame_source; | 1607 use_external_begin_frame_source; |
| 1589 scheduler_settings.throttle_frame_production = throttle_frame_production; | 1608 scheduler_settings_.throttle_frame_production = throttle_frame_production; |
| 1590 | 1609 SetUpScheduler(true); |
| 1591 CREATE_SCHEDULER_AND_INIT_SURFACE(scheduler_settings); | 1610 |
| 1592 scheduler->SetEstimatedParentDrawTime(base::TimeDelta::FromMicroseconds(1)); | 1611 scheduler_->SetEstimatedParentDrawTime(base::TimeDelta::FromMicroseconds(1)); |
| 1593 | 1612 |
| 1594 // To test swap ack throttling, this test disables automatic swap acks. | 1613 // To test swap ack throttling, this test disables automatic swap acks. |
| 1595 scheduler->SetMaxSwapsPending(1); | 1614 scheduler_->SetMaxSwapsPending(1); |
| 1596 client.SetAutomaticSwapAck(false); | 1615 client_->SetAutomaticSwapAck(false); |
| 1597 | 1616 |
| 1598 // SetNeedsCommit should begin the frame on the next BeginImplFrame. | 1617 // SetNeedsCommit should begin the frame on the next BeginImplFrame. |
| 1599 client.Reset(); | 1618 client_->Reset(); |
| 1600 scheduler->SetNeedsCommit(); | 1619 scheduler_->SetNeedsCommit(); |
| 1601 EXPECT_NO_ACTION(client); | 1620 EXPECT_NO_ACTION(client_); |
| 1602 client.Reset(); | 1621 client_->Reset(); |
| 1603 | 1622 |
| 1604 // Trigger the first BeginImplFrame and BeginMainFrame | 1623 // Trigger the first BeginImplFrame and BeginMainFrame |
| 1605 EXPECT_SCOPED(client.AdvanceFrame()); | 1624 EXPECT_SCOPED(client_->AdvanceFrame()); |
| 1606 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 1625 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
| 1607 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); | 1626 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); |
| 1608 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1627 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
| 1609 client.Reset(); | 1628 client_->Reset(); |
| 1610 | 1629 |
| 1611 // NotifyReadyToCommit should trigger the pending commit and draw. | 1630 // NotifyReadyToCommit should trigger the pending commit and draw. |
| 1612 scheduler->NotifyBeginMainFrameStarted(); | 1631 scheduler_->NotifyBeginMainFrameStarted(); |
| 1613 scheduler->NotifyReadyToCommit(); | 1632 scheduler_->NotifyReadyToCommit(); |
| 1614 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); | 1633 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_); |
| 1615 client.Reset(); | 1634 client_->Reset(); |
| 1616 | 1635 |
| 1617 // Swapping will put us into a swap throttled state. | 1636 // Swapping will put us into a swap throttled state. |
| 1618 // Run posted deadline. | 1637 // Run posted deadline. |
| 1619 client.task_runner().RunTasksWhile(client.ImplFrameDeadlinePending(true)); | 1638 client_->task_runner().RunTasksWhile(client_->ImplFrameDeadlinePending(true)); |
| 1620 EXPECT_ACTION("ScheduledActionAnimate", client, 0, 2); | 1639 EXPECT_ACTION("ScheduledActionAnimate", client_, 0, 2); |
| 1621 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 1, 2); | 1640 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 1, 2); |
| 1622 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 1641 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); |
| 1623 client.Reset(); | 1642 client_->Reset(); |
| 1624 | 1643 |
| 1625 // While swap throttled, BeginFrames should trigger BeginImplFrames, | 1644 // While swap throttled, BeginFrames should trigger BeginImplFrames, |
| 1626 // but not a BeginMainFrame or draw. | 1645 // but not a BeginMainFrame or draw. |
| 1627 scheduler->SetNeedsCommit(); | 1646 scheduler_->SetNeedsCommit(); |
| 1628 scheduler->SetNeedsRedraw(); | 1647 scheduler_->SetNeedsRedraw(); |
| 1629 EXPECT_SCOPED(client.AdvanceFrame()); // Run posted BeginFrame. | 1648 EXPECT_SCOPED(client_->AdvanceFrame()); // Run posted BeginFrame. |
| 1630 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 1649 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
| 1631 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); | 1650 EXPECT_ACTION("ScheduledActionAnimate", client_, 1, 2); |
| 1632 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1651 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
| 1633 client.Reset(); | 1652 client_->Reset(); |
| 1634 | 1653 |
| 1635 // Let time pass sufficiently beyond the regular deadline but not beyond the | 1654 // Let time pass sufficiently beyond the regular deadline but not beyond the |
| 1636 // late deadline. | 1655 // late deadline. |
| 1637 client.now_src()->AdvanceNow(BeginFrameArgs::DefaultInterval() - | 1656 client_->now_src()->AdvanceNow(BeginFrameArgs::DefaultInterval() - |
| 1638 base::TimeDelta::FromMicroseconds(1)); | 1657 base::TimeDelta::FromMicroseconds(1)); |
| 1639 client.task_runner().RunUntilTime(client.now_src()->Now()); | 1658 client_->task_runner().RunUntilTime(client_->now_src()->Now()); |
| 1640 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1659 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
| 1641 | 1660 |
| 1642 // Take us out of a swap throttled state. | 1661 // Take us out of a swap throttled state. |
| 1643 scheduler->DidSwapBuffersComplete(); | 1662 scheduler_->DidSwapBuffersComplete(); |
| 1644 EXPECT_SINGLE_ACTION("ScheduledActionSendBeginMainFrame", client); | 1663 EXPECT_SINGLE_ACTION("ScheduledActionSendBeginMainFrame", client_); |
| 1645 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1664 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
| 1646 client.Reset(); | 1665 client_->Reset(); |
| 1647 | 1666 |
| 1648 // Verify that the deadline was rescheduled. | 1667 // Verify that the deadline was rescheduled. |
| 1649 // We can't use RunUntilTime(now) here because the next frame is also | 1668 // We can't use RunUntilTime(now) here because the next frame is also |
| 1650 // scheduled if throttle_frame_production = false. | 1669 // scheduled if throttle_frame_production = false. |
| 1651 base::TimeTicks before_deadline = client.now_src()->Now(); | 1670 base::TimeTicks before_deadline = client_->now_src()->Now(); |
| 1652 client.task_runner().RunTasksWhile(client.ImplFrameDeadlinePending(true)); | 1671 client_->task_runner().RunTasksWhile(client_->ImplFrameDeadlinePending(true)); |
| 1653 base::TimeTicks after_deadline = client.now_src()->Now(); | 1672 base::TimeTicks after_deadline = client_->now_src()->Now(); |
| 1654 EXPECT_EQ(after_deadline, before_deadline); | 1673 EXPECT_EQ(after_deadline, before_deadline); |
| 1655 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 1674 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); |
| 1656 client.Reset(); | 1675 client_->Reset(); |
| 1657 } | 1676 } |
| 1658 | 1677 |
| 1659 TEST(SchedulerTest, SyntheticBeginFrames_SwapThrottled) { | 1678 TEST_F(SchedulerTest, SyntheticBeginFrames_SwapThrottled) { |
| 1660 bool use_external_begin_frame_source = false; | 1679 bool use_external_begin_frame_source = false; |
| 1661 bool throttle_frame_production = true; | 1680 bool throttle_frame_production = true; |
| 1662 BeginFramesNotFromClient_SwapThrottled(use_external_begin_frame_source, | 1681 BeginFramesNotFromClient_SwapThrottled(use_external_begin_frame_source, |
| 1663 throttle_frame_production); | 1682 throttle_frame_production); |
| 1664 } | 1683 } |
| 1665 | 1684 |
| 1666 TEST(SchedulerTest, VSyncThrottlingDisabled_SwapThrottled) { | 1685 TEST_F(SchedulerTest, VSyncThrottlingDisabled_SwapThrottled) { |
| 1667 bool use_external_begin_frame_source = true; | 1686 bool use_external_begin_frame_source = true; |
| 1668 bool throttle_frame_production = false; | 1687 bool throttle_frame_production = false; |
| 1669 BeginFramesNotFromClient_SwapThrottled(use_external_begin_frame_source, | 1688 BeginFramesNotFromClient_SwapThrottled(use_external_begin_frame_source, |
| 1670 throttle_frame_production); | 1689 throttle_frame_production); |
| 1671 } | 1690 } |
| 1672 | 1691 |
| 1673 TEST(SchedulerTest, | 1692 TEST_F(SchedulerTest, |
| 1674 SyntheticBeginFrames_And_VSyncThrottlingDisabled_SwapThrottled) { | 1693 SyntheticBeginFrames_And_VSyncThrottlingDisabled_SwapThrottled) { |
| 1675 bool use_external_begin_frame_source = false; | 1694 bool use_external_begin_frame_source = false; |
| 1676 bool throttle_frame_production = false; | 1695 bool throttle_frame_production = false; |
| 1677 BeginFramesNotFromClient_SwapThrottled(use_external_begin_frame_source, | 1696 BeginFramesNotFromClient_SwapThrottled(use_external_begin_frame_source, |
| 1678 throttle_frame_production); | 1697 throttle_frame_production); |
| 1679 } | 1698 } |
| 1680 | 1699 |
| 1681 TEST(SchedulerTest, DidLoseOutputSurfaceAfterOutputSurfaceIsInitialized) { | 1700 TEST_F(SchedulerTest, DidLoseOutputSurfaceAfterOutputSurfaceIsInitialized) { |
| 1682 FakeSchedulerClient client; | 1701 scheduler_settings_.use_external_begin_frame_source = true; |
| 1683 SchedulerSettings scheduler_settings; | 1702 SetUpScheduler(false); |
| 1684 scheduler_settings.use_external_begin_frame_source = true; | 1703 |
| 1685 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings); | 1704 scheduler_->SetCanStart(); |
| 1686 scheduler->SetCanStart(); | 1705 scheduler_->SetVisible(true); |
| 1687 scheduler->SetVisible(true); | 1706 scheduler_->SetCanDraw(true); |
| 1688 scheduler->SetCanDraw(true); | 1707 |
| 1689 | 1708 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client_); |
| 1690 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); | 1709 client_->Reset(); |
| 1691 client.Reset(); | 1710 scheduler_->DidCreateAndInitializeOutputSurface(); |
| 1692 scheduler->DidCreateAndInitializeOutputSurface(); | 1711 EXPECT_NO_ACTION(client_); |
| 1693 EXPECT_NO_ACTION(client); | 1712 |
| 1694 | 1713 scheduler_->DidLoseOutputSurface(); |
| 1695 scheduler->DidLoseOutputSurface(); | 1714 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client_); |
| 1696 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); | 1715 } |
| 1697 } | 1716 |
| 1698 | 1717 TEST_F(SchedulerTest, DidLoseOutputSurfaceAfterBeginFrameStarted) { |
| 1699 TEST(SchedulerTest, DidLoseOutputSurfaceAfterBeginFrameStarted) { | 1718 scheduler_settings_.use_external_begin_frame_source = true; |
| 1700 FakeSchedulerClient client; | 1719 SetUpScheduler(true); |
| 1701 SchedulerSettings scheduler_settings; | |
| 1702 scheduler_settings.use_external_begin_frame_source = true; | |
| 1703 | |
| 1704 CREATE_SCHEDULER_AND_INIT_SURFACE(scheduler_settings); | |
| 1705 | 1720 |
| 1706 // SetNeedsCommit should begin the frame. | 1721 // SetNeedsCommit should begin the frame. |
| 1707 scheduler->SetNeedsCommit(); | 1722 scheduler_->SetNeedsCommit(); |
| 1708 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client); | 1723 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client_); |
| 1709 | 1724 |
| 1710 client.Reset(); | 1725 client_->Reset(); |
| 1711 EXPECT_SCOPED(client.AdvanceFrame()); | 1726 EXPECT_SCOPED(client_->AdvanceFrame()); |
| 1712 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 1727 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
| 1713 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); | 1728 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); |
| 1714 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1729 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
| 1715 | 1730 |
| 1716 client.Reset(); | 1731 client_->Reset(); |
| 1717 scheduler->DidLoseOutputSurface(); | 1732 scheduler_->DidLoseOutputSurface(); |
| 1718 // Do nothing when impl frame is in deadine pending state. | 1733 // Do nothing when impl frame is in deadine pending state. |
| 1719 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(false)", client); | 1734 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(false)", client_); |
| 1720 | 1735 |
| 1721 client.Reset(); | 1736 client_->Reset(); |
| 1722 scheduler->NotifyBeginMainFrameStarted(); | 1737 scheduler_->NotifyBeginMainFrameStarted(); |
| 1723 scheduler->NotifyReadyToCommit(); | 1738 scheduler_->NotifyReadyToCommit(); |
| 1724 EXPECT_ACTION("ScheduledActionCommit", client, 0, 1); | 1739 EXPECT_ACTION("ScheduledActionCommit", client_, 0, 1); |
| 1725 | 1740 |
| 1726 client.Reset(); | 1741 client_->Reset(); |
| 1727 client.task_runner().RunPendingTasks(); // Run posted deadline. | 1742 client_->task_runner().RunPendingTasks(); // Run posted deadline. |
| 1728 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); | 1743 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client_); |
| 1729 } | 1744 } |
| 1730 | 1745 |
| 1731 void DidLoseOutputSurfaceAfterBeginFrameStartedWithHighLatency( | 1746 void SchedulerTest::DidLoseOutputSurfaceAfterBeginFrameStartedWithHighLatency( |
| 1732 bool impl_side_painting) { | 1747 bool impl_side_painting) { |
| 1733 FakeSchedulerClient client; | 1748 scheduler_settings_.impl_side_painting = impl_side_painting; |
| 1734 SchedulerSettings scheduler_settings; | 1749 scheduler_settings_.use_external_begin_frame_source = true; |
| 1735 scheduler_settings.impl_side_painting = impl_side_painting; | 1750 SetUpScheduler(true); |
| 1736 scheduler_settings.use_external_begin_frame_source = true; | |
| 1737 | |
| 1738 CREATE_SCHEDULER_AND_INIT_SURFACE(scheduler_settings); | |
| 1739 | 1751 |
| 1740 // SetNeedsCommit should begin the frame. | 1752 // SetNeedsCommit should begin the frame. |
| 1741 scheduler->SetNeedsCommit(); | 1753 scheduler_->SetNeedsCommit(); |
| 1742 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client); | 1754 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client_); |
| 1743 | 1755 |
| 1744 client.Reset(); | 1756 client_->Reset(); |
| 1745 EXPECT_SCOPED(client.AdvanceFrame()); | 1757 EXPECT_SCOPED(client_->AdvanceFrame()); |
| 1746 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 1758 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
| 1747 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); | 1759 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); |
| 1748 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1760 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
| 1749 | 1761 |
| 1750 client.Reset(); | 1762 client_->Reset(); |
| 1751 scheduler->DidLoseOutputSurface(); | 1763 scheduler_->DidLoseOutputSurface(); |
| 1752 // Do nothing when impl frame is in deadine pending state. | 1764 // Do nothing when impl frame is in deadine pending state. |
| 1753 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(false)", client); | 1765 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(false)", client_); |
| 1754 | 1766 |
| 1755 client.Reset(); | 1767 client_->Reset(); |
| 1756 // Run posted deadline. | 1768 // Run posted deadline. |
| 1757 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1769 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
| 1758 client.task_runner().RunTasksWhile(client.ImplFrameDeadlinePending(true)); | 1770 client_->task_runner().RunTasksWhile(client_->ImplFrameDeadlinePending(true)); |
| 1759 // OnBeginImplFrameDeadline didn't schedule any actions because main frame is | 1771 // OnBeginImplFrameDeadline didn't schedule any actions because main frame is |
| 1760 // not yet completed. | 1772 // not yet completed. |
| 1761 EXPECT_NO_ACTION(client); | 1773 EXPECT_NO_ACTION(client_); |
| 1762 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 1774 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); |
| 1763 | 1775 |
| 1764 // BeginImplFrame is not started. | 1776 // BeginImplFrame is not started. |
| 1765 client.task_runner().RunUntilTime(client.now_src()->Now() + | 1777 client_->task_runner().RunUntilTime(client_->now_src()->Now() + |
| 1766 base::TimeDelta::FromMilliseconds(10)); | 1778 base::TimeDelta::FromMilliseconds(10)); |
| 1767 EXPECT_NO_ACTION(client); | 1779 EXPECT_NO_ACTION(client_); |
| 1768 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 1780 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); |
| 1769 | 1781 |
| 1770 client.Reset(); | 1782 client_->Reset(); |
| 1771 scheduler->NotifyBeginMainFrameStarted(); | 1783 scheduler_->NotifyBeginMainFrameStarted(); |
| 1772 scheduler->NotifyReadyToCommit(); | 1784 scheduler_->NotifyReadyToCommit(); |
| 1773 if (impl_side_painting) { | 1785 if (impl_side_painting) { |
| 1774 EXPECT_ACTION("ScheduledActionCommit", client, 0, 3); | 1786 EXPECT_ACTION("ScheduledActionCommit", client_, 0, 3); |
| 1775 EXPECT_ACTION("ScheduledActionActivateSyncTree", client, 1, 3); | 1787 EXPECT_ACTION("ScheduledActionActivateSyncTree", client_, 1, 3); |
| 1776 EXPECT_ACTION("ScheduledActionBeginOutputSurfaceCreation", client, 2, 3); | 1788 EXPECT_ACTION("ScheduledActionBeginOutputSurfaceCreation", client_, 2, 3); |
| 1777 } else { | 1789 } else { |
| 1778 EXPECT_ACTION("ScheduledActionCommit", client, 0, 2); | 1790 EXPECT_ACTION("ScheduledActionCommit", client_, 0, 2); |
| 1779 EXPECT_ACTION("ScheduledActionBeginOutputSurfaceCreation", client, 1, 2); | 1791 EXPECT_ACTION("ScheduledActionBeginOutputSurfaceCreation", client_, 1, 2); |
| 1780 } | 1792 } |
| 1781 } | 1793 } |
| 1782 | 1794 |
| 1783 TEST(SchedulerTest, DidLoseOutputSurfaceAfterBeginFrameStartedWithHighLatency) { | 1795 TEST_F(SchedulerTest, |
| 1796 DidLoseOutputSurfaceAfterBeginFrameStartedWithHighLatency) { | |
| 1784 bool impl_side_painting = false; | 1797 bool impl_side_painting = false; |
| 1785 DidLoseOutputSurfaceAfterBeginFrameStartedWithHighLatency(impl_side_painting); | 1798 DidLoseOutputSurfaceAfterBeginFrameStartedWithHighLatency(impl_side_painting); |
| 1786 } | 1799 } |
| 1787 | 1800 |
| 1788 TEST(SchedulerTest, | 1801 TEST_F(SchedulerTest, |
| 1789 DidLoseOutputSurfaceAfterBeginFrameStartedWithHighLatencyWithImplPaint) { | 1802 DidLoseOutputSurfaceAfterBeginFrameStartedWithHighLatencyWithImplPaint) { |
| 1790 bool impl_side_painting = true; | 1803 bool impl_side_painting = true; |
| 1791 DidLoseOutputSurfaceAfterBeginFrameStartedWithHighLatency(impl_side_painting); | 1804 DidLoseOutputSurfaceAfterBeginFrameStartedWithHighLatency(impl_side_painting); |
| 1792 } | 1805 } |
| 1793 | 1806 |
| 1794 void DidLoseOutputSurfaceAfterReadyToCommit(bool impl_side_painting) { | 1807 void SchedulerTest::DidLoseOutputSurfaceAfterReadyToCommit( |
| 1795 FakeSchedulerClient client; | 1808 bool impl_side_painting) { |
| 1796 SchedulerSettings scheduler_settings; | 1809 scheduler_settings_.impl_side_painting = impl_side_painting; |
| 1797 scheduler_settings.impl_side_painting = impl_side_painting; | 1810 scheduler_settings_.use_external_begin_frame_source = true; |
| 1798 scheduler_settings.use_external_begin_frame_source = true; | 1811 SetUpScheduler(true); |
| 1799 | |
| 1800 CREATE_SCHEDULER_AND_INIT_SURFACE(scheduler_settings); | |
| 1801 | 1812 |
| 1802 // SetNeedsCommit should begin the frame. | 1813 // SetNeedsCommit should begin the frame. |
| 1803 scheduler->SetNeedsCommit(); | 1814 scheduler_->SetNeedsCommit(); |
| 1804 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client); | 1815 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client_); |
| 1805 | 1816 |
| 1806 client.Reset(); | 1817 client_->Reset(); |
| 1807 EXPECT_SCOPED(client.AdvanceFrame()); | 1818 EXPECT_SCOPED(client_->AdvanceFrame()); |
| 1808 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 1819 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
| 1809 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); | 1820 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); |
| 1810 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1821 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
| 1811 | 1822 |
| 1812 client.Reset(); | 1823 client_->Reset(); |
| 1813 scheduler->NotifyBeginMainFrameStarted(); | 1824 scheduler_->NotifyBeginMainFrameStarted(); |
| 1814 scheduler->NotifyReadyToCommit(); | 1825 scheduler_->NotifyReadyToCommit(); |
| 1815 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); | 1826 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_); |
| 1816 | 1827 |
| 1817 client.Reset(); | 1828 client_->Reset(); |
| 1818 scheduler->DidLoseOutputSurface(); | 1829 scheduler_->DidLoseOutputSurface(); |
| 1819 if (impl_side_painting) { | 1830 if (impl_side_painting) { |
| 1820 // Sync tree should be forced to activate. | 1831 // Sync tree should be forced to activate. |
| 1821 EXPECT_ACTION("ScheduledActionActivateSyncTree", client, 0, 2); | 1832 EXPECT_ACTION("ScheduledActionActivateSyncTree", client_, 0, 2); |
| 1822 EXPECT_ACTION("SetNeedsBeginFrames(false)", client, 1, 2); | 1833 EXPECT_ACTION("SetNeedsBeginFrames(false)", client_, 1, 2); |
| 1823 } else { | 1834 } else { |
| 1824 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(false)", client); | 1835 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(false)", client_); |
| 1825 } | 1836 } |
| 1826 | 1837 |
| 1827 client.Reset(); | 1838 client_->Reset(); |
| 1828 client.task_runner().RunPendingTasks(); // Run posted deadline. | 1839 client_->task_runner().RunPendingTasks(); // Run posted deadline. |
| 1829 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); | 1840 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client_); |
| 1830 } | 1841 } |
| 1831 | 1842 |
| 1832 TEST(SchedulerTest, DidLoseOutputSurfaceAfterReadyToCommit) { | 1843 TEST_F(SchedulerTest, DidLoseOutputSurfaceAfterReadyToCommit) { |
| 1833 DidLoseOutputSurfaceAfterReadyToCommit(false); | 1844 DidLoseOutputSurfaceAfterReadyToCommit(false); |
| 1834 } | 1845 } |
| 1835 | 1846 |
| 1836 TEST(SchedulerTest, DidLoseOutputSurfaceAfterReadyToCommitWithImplPainting) { | 1847 TEST_F(SchedulerTest, DidLoseOutputSurfaceAfterReadyToCommitWithImplPainting) { |
| 1837 DidLoseOutputSurfaceAfterReadyToCommit(true); | 1848 DidLoseOutputSurfaceAfterReadyToCommit(true); |
| 1838 } | 1849 } |
| 1839 | 1850 |
| 1840 TEST(SchedulerTest, DidLoseOutputSurfaceAfterSetNeedsPrepareTiles) { | 1851 TEST_F(SchedulerTest, DidLoseOutputSurfaceAfterSetNeedsPrepareTiles) { |
| 1841 FakeSchedulerClient client; | 1852 scheduler_settings_.use_external_begin_frame_source = true; |
| 1842 SchedulerSettings scheduler_settings; | 1853 SetUpScheduler(true); |
| 1843 scheduler_settings.use_external_begin_frame_source = true; | 1854 |
| 1844 | 1855 scheduler_->SetNeedsPrepareTiles(); |
| 1845 CREATE_SCHEDULER_AND_INIT_SURFACE(scheduler_settings); | 1856 scheduler_->SetNeedsRedraw(); |
| 1846 | 1857 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client_); |
| 1847 scheduler->SetNeedsPrepareTiles(); | 1858 |
| 1848 scheduler->SetNeedsRedraw(); | 1859 client_->Reset(); |
| 1849 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client); | 1860 EXPECT_SCOPED(client_->AdvanceFrame()); |
| 1850 | 1861 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
| 1851 client.Reset(); | 1862 EXPECT_ACTION("ScheduledActionAnimate", client_, 1, 2); |
| 1852 EXPECT_SCOPED(client.AdvanceFrame()); | 1863 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
| 1853 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 1864 |
| 1854 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); | 1865 client_->Reset(); |
| 1855 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1866 scheduler_->DidLoseOutputSurface(); |
| 1856 | 1867 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(false)", client_); |
| 1857 client.Reset(); | 1868 |
| 1858 scheduler->DidLoseOutputSurface(); | 1869 client_->Reset(); |
| 1859 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(false)", client); | 1870 client_->task_runner().RunPendingTasks(); // Run posted deadline. |
| 1860 | 1871 EXPECT_ACTION("ScheduledActionPrepareTiles", client_, 0, 2); |
| 1861 client.Reset(); | 1872 EXPECT_ACTION("ScheduledActionBeginOutputSurfaceCreation", client_, 1, 2); |
| 1862 client.task_runner().RunPendingTasks(); // Run posted deadline. | 1873 } |
| 1863 EXPECT_ACTION("ScheduledActionPrepareTiles", client, 0, 2); | 1874 |
| 1864 EXPECT_ACTION("ScheduledActionBeginOutputSurfaceCreation", client, 1, 2); | 1875 TEST_F(SchedulerTest, DidLoseOutputSurfaceAfterBeginRetroFramePosted) { |
| 1865 } | 1876 scheduler_settings_.use_external_begin_frame_source = true; |
| 1866 | 1877 SetUpScheduler(true); |
| 1867 TEST(SchedulerTest, DidLoseOutputSurfaceAfterBeginRetroFramePosted) { | |
| 1868 FakeSchedulerClient client; | |
| 1869 SchedulerSettings scheduler_settings; | |
| 1870 scheduler_settings.use_external_begin_frame_source = true; | |
| 1871 | |
| 1872 CREATE_SCHEDULER_AND_INIT_SURFACE(scheduler_settings); | |
| 1873 | 1878 |
| 1874 // SetNeedsCommit should begin the frame on the next BeginImplFrame. | 1879 // SetNeedsCommit should begin the frame on the next BeginImplFrame. |
| 1875 scheduler->SetNeedsCommit(); | 1880 scheduler_->SetNeedsCommit(); |
| 1876 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client); | 1881 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client_); |
| 1877 | 1882 |
| 1878 // Create a BeginFrame with a long deadline to avoid race conditions. | 1883 // Create a BeginFrame with a long deadline to avoid race conditions. |
| 1879 // This is the first BeginFrame, which will be handled immediately. | 1884 // This is the first BeginFrame, which will be handled immediately. |
| 1880 client.Reset(); | 1885 client_->Reset(); |
| 1881 BeginFrameArgs args = | 1886 BeginFrameArgs args = |
| 1882 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, client.now_src()); | 1887 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, client_->now_src()); |
| 1883 args.deadline += base::TimeDelta::FromHours(1); | 1888 args.deadline += base::TimeDelta::FromHours(1); |
| 1884 client.fake_external_begin_frame_source()->TestOnBeginFrame(args); | 1889 client_->fake_external_begin_frame_source()->TestOnBeginFrame(args); |
| 1885 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 1890 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
| 1886 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); | 1891 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); |
| 1887 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1892 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
| 1888 EXPECT_TRUE(client.needs_begin_frames()); | 1893 EXPECT_TRUE(client_->needs_begin_frames()); |
| 1889 | 1894 |
| 1890 // Queue BeginFrames while we are still handling the previous BeginFrame. | 1895 // Queue BeginFrames while we are still handling the previous BeginFrame. |
| 1891 args.frame_time += base::TimeDelta::FromSeconds(1); | 1896 args.frame_time += base::TimeDelta::FromSeconds(1); |
| 1892 client.fake_external_begin_frame_source()->TestOnBeginFrame(args); | 1897 client_->fake_external_begin_frame_source()->TestOnBeginFrame(args); |
| 1893 args.frame_time += base::TimeDelta::FromSeconds(1); | 1898 args.frame_time += base::TimeDelta::FromSeconds(1); |
| 1894 client.fake_external_begin_frame_source()->TestOnBeginFrame(args); | 1899 client_->fake_external_begin_frame_source()->TestOnBeginFrame(args); |
| 1895 | 1900 |
| 1896 // If we don't swap on the deadline, we wait for the next BeginImplFrame. | 1901 // If we don't swap on the deadline, we wait for the next BeginImplFrame. |
| 1897 client.Reset(); | 1902 client_->Reset(); |
| 1898 client.task_runner().RunPendingTasks(); // Run posted deadline. | 1903 client_->task_runner().RunPendingTasks(); // Run posted deadline. |
| 1899 EXPECT_NO_ACTION(client); | 1904 EXPECT_NO_ACTION(client_); |
| 1900 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 1905 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); |
| 1901 EXPECT_TRUE(client.needs_begin_frames()); | 1906 EXPECT_TRUE(client_->needs_begin_frames()); |
| 1902 | 1907 |
| 1903 // NotifyReadyToCommit should trigger the commit. | 1908 // NotifyReadyToCommit should trigger the commit. |
| 1904 client.Reset(); | 1909 client_->Reset(); |
| 1905 scheduler->NotifyBeginMainFrameStarted(); | 1910 scheduler_->NotifyBeginMainFrameStarted(); |
| 1906 scheduler->NotifyReadyToCommit(); | 1911 scheduler_->NotifyReadyToCommit(); |
| 1907 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); | 1912 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_); |
| 1908 EXPECT_TRUE(client.needs_begin_frames()); | 1913 EXPECT_TRUE(client_->needs_begin_frames()); |
| 1909 | 1914 |
| 1910 client.Reset(); | 1915 client_->Reset(); |
| 1911 EXPECT_FALSE(scheduler->IsBeginRetroFrameArgsEmpty()); | 1916 EXPECT_FALSE(scheduler_->IsBeginRetroFrameArgsEmpty()); |
| 1912 scheduler->DidLoseOutputSurface(); | 1917 scheduler_->DidLoseOutputSurface(); |
| 1913 EXPECT_ACTION("ScheduledActionBeginOutputSurfaceCreation", client, 0, 2); | 1918 EXPECT_ACTION("ScheduledActionBeginOutputSurfaceCreation", client_, 0, 2); |
| 1914 EXPECT_ACTION("SetNeedsBeginFrames(false)", client, 1, 2); | 1919 EXPECT_ACTION("SetNeedsBeginFrames(false)", client_, 1, 2); |
| 1915 EXPECT_TRUE(scheduler->IsBeginRetroFrameArgsEmpty()); | 1920 EXPECT_TRUE(scheduler_->IsBeginRetroFrameArgsEmpty()); |
| 1916 | 1921 |
| 1917 // Posted BeginRetroFrame is aborted. | 1922 // Posted BeginRetroFrame is aborted. |
| 1918 client.Reset(); | 1923 client_->Reset(); |
| 1919 client.task_runner().RunPendingTasks(); | 1924 client_->task_runner().RunPendingTasks(); |
| 1920 EXPECT_NO_ACTION(client); | 1925 EXPECT_NO_ACTION(client_); |
| 1921 } | 1926 } |
| 1922 | 1927 |
| 1923 TEST(SchedulerTest, DidLoseOutputSurfaceDuringBeginRetroFrameRunning) { | 1928 TEST_F(SchedulerTest, DidLoseOutputSurfaceDuringBeginRetroFrameRunning) { |
| 1924 FakeSchedulerClient client; | 1929 scheduler_settings_.use_external_begin_frame_source = true; |
| 1925 SchedulerSettings scheduler_settings; | 1930 SetUpScheduler(true); |
| 1926 scheduler_settings.use_external_begin_frame_source = true; | |
| 1927 | |
| 1928 CREATE_SCHEDULER_AND_INIT_SURFACE(scheduler_settings); | |
| 1929 | 1931 |
| 1930 // SetNeedsCommit should begin the frame on the next BeginImplFrame. | 1932 // SetNeedsCommit should begin the frame on the next BeginImplFrame. |
| 1931 scheduler->SetNeedsCommit(); | 1933 scheduler_->SetNeedsCommit(); |
| 1932 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client); | 1934 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client_); |
| 1933 | 1935 |
| 1934 // Create a BeginFrame with a long deadline to avoid race conditions. | 1936 // Create a BeginFrame with a long deadline to avoid race conditions. |
| 1935 // This is the first BeginFrame, which will be handled immediately. | 1937 // This is the first BeginFrame, which will be handled immediately. |
| 1936 client.Reset(); | 1938 client_->Reset(); |
| 1937 BeginFrameArgs args = | 1939 BeginFrameArgs args = |
| 1938 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, client.now_src()); | 1940 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, client_->now_src()); |
| 1939 args.deadline += base::TimeDelta::FromHours(1); | 1941 args.deadline += base::TimeDelta::FromHours(1); |
| 1940 client.fake_external_begin_frame_source()->TestOnBeginFrame(args); | 1942 client_->fake_external_begin_frame_source()->TestOnBeginFrame(args); |
| 1941 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 1943 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
| 1942 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); | 1944 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); |
| 1943 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1945 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
| 1944 EXPECT_TRUE(client.needs_begin_frames()); | 1946 EXPECT_TRUE(client_->needs_begin_frames()); |
| 1945 | 1947 |
| 1946 // Queue BeginFrames while we are still handling the previous BeginFrame. | 1948 // Queue BeginFrames while we are still handling the previous BeginFrame. |
| 1947 args.frame_time += base::TimeDelta::FromSeconds(1); | 1949 args.frame_time += base::TimeDelta::FromSeconds(1); |
| 1948 client.fake_external_begin_frame_source()->TestOnBeginFrame(args); | 1950 client_->fake_external_begin_frame_source()->TestOnBeginFrame(args); |
| 1949 args.frame_time += base::TimeDelta::FromSeconds(1); | 1951 args.frame_time += base::TimeDelta::FromSeconds(1); |
| 1950 client.fake_external_begin_frame_source()->TestOnBeginFrame(args); | 1952 client_->fake_external_begin_frame_source()->TestOnBeginFrame(args); |
| 1951 | 1953 |
| 1952 // If we don't swap on the deadline, we wait for the next BeginImplFrame. | 1954 // If we don't swap on the deadline, we wait for the next BeginImplFrame. |
| 1953 client.Reset(); | 1955 client_->Reset(); |
| 1954 client.task_runner().RunPendingTasks(); // Run posted deadline. | 1956 client_->task_runner().RunPendingTasks(); // Run posted deadline. |
| 1955 EXPECT_NO_ACTION(client); | 1957 EXPECT_NO_ACTION(client_); |
| 1956 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 1958 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); |
| 1957 EXPECT_TRUE(client.needs_begin_frames()); | 1959 EXPECT_TRUE(client_->needs_begin_frames()); |
| 1958 | 1960 |
| 1959 // NotifyReadyToCommit should trigger the commit. | 1961 // NotifyReadyToCommit should trigger the commit. |
| 1960 client.Reset(); | 1962 client_->Reset(); |
| 1961 scheduler->NotifyBeginMainFrameStarted(); | 1963 scheduler_->NotifyBeginMainFrameStarted(); |
| 1962 scheduler->NotifyReadyToCommit(); | 1964 scheduler_->NotifyReadyToCommit(); |
| 1963 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); | 1965 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_); |
| 1964 EXPECT_TRUE(client.needs_begin_frames()); | 1966 EXPECT_TRUE(client_->needs_begin_frames()); |
| 1965 | 1967 |
| 1966 // BeginImplFrame should prepare the draw. | 1968 // BeginImplFrame should prepare the draw. |
| 1967 client.Reset(); | 1969 client_->Reset(); |
| 1968 client.task_runner().RunPendingTasks(); // Run posted BeginRetroFrame. | 1970 client_->task_runner().RunPendingTasks(); // Run posted BeginRetroFrame. |
| 1969 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 1971 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
| 1970 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); | 1972 EXPECT_ACTION("ScheduledActionAnimate", client_, 1, 2); |
| 1971 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1973 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
| 1972 EXPECT_TRUE(client.needs_begin_frames()); | 1974 EXPECT_TRUE(client_->needs_begin_frames()); |
| 1973 | 1975 |
| 1974 client.Reset(); | 1976 client_->Reset(); |
| 1975 EXPECT_FALSE(scheduler->IsBeginRetroFrameArgsEmpty()); | 1977 EXPECT_FALSE(scheduler_->IsBeginRetroFrameArgsEmpty()); |
| 1976 scheduler->DidLoseOutputSurface(); | 1978 scheduler_->DidLoseOutputSurface(); |
| 1977 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(false)", client); | 1979 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(false)", client_); |
| 1978 EXPECT_TRUE(scheduler->IsBeginRetroFrameArgsEmpty()); | 1980 EXPECT_TRUE(scheduler_->IsBeginRetroFrameArgsEmpty()); |
| 1979 | 1981 |
| 1980 // BeginImplFrame deadline should abort drawing. | 1982 // BeginImplFrame deadline should abort drawing. |
| 1981 client.Reset(); | 1983 client_->Reset(); |
| 1982 client.task_runner().RunPendingTasks(); // Run posted deadline. | 1984 client_->task_runner().RunPendingTasks(); // Run posted deadline. |
| 1983 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); | 1985 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client_); |
| 1984 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 1986 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); |
| 1985 EXPECT_FALSE(client.needs_begin_frames()); | 1987 EXPECT_FALSE(client_->needs_begin_frames()); |
| 1986 | 1988 |
| 1987 // No more BeginRetroFrame because BeginRetroFrame queue is cleared. | 1989 // No more BeginRetroFrame because BeginRetroFrame queue is cleared. |
| 1988 client.Reset(); | 1990 client_->Reset(); |
| 1989 client.task_runner().RunPendingTasks(); | 1991 client_->task_runner().RunPendingTasks(); |
| 1990 EXPECT_NO_ACTION(client); | 1992 EXPECT_NO_ACTION(client_); |
| 1991 } | 1993 } |
| 1992 | 1994 |
| 1993 TEST(SchedulerTest, | 1995 TEST_F(SchedulerTest, |
| 1994 StopBeginFrameAfterDidLoseOutputSurfaceWithSyntheticBeginFrameSource) { | 1996 StopBeginFrameAfterDidLoseOutputSurfaceWithSyntheticBeginFrameSource) { |
| 1995 FakeSchedulerClient client; | 1997 SetUpScheduler(true); |
| 1996 SchedulerSettings scheduler_settings; | |
| 1997 | |
| 1998 CREATE_SCHEDULER_AND_INIT_SURFACE(scheduler_settings); | |
| 1999 | 1998 |
| 2000 // SetNeedsCommit should begin the frame on the next BeginImplFrame. | 1999 // SetNeedsCommit should begin the frame on the next BeginImplFrame. |
| 2001 EXPECT_FALSE(scheduler->frame_source().NeedsBeginFrames()); | 2000 EXPECT_FALSE(scheduler_->frame_source().NeedsBeginFrames()); |
| 2002 scheduler->SetNeedsCommit(); | 2001 scheduler_->SetNeedsCommit(); |
| 2003 EXPECT_TRUE(scheduler->frame_source().NeedsBeginFrames()); | 2002 EXPECT_TRUE(scheduler_->frame_source().NeedsBeginFrames()); |
| 2004 | 2003 |
| 2005 client.Reset(); | 2004 client_->Reset(); |
| 2006 client.task_runner().RunPendingTasks(); // Run posted Tick. | 2005 client_->task_runner().RunPendingTasks(); // Run posted Tick. |
| 2007 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 2006 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
| 2008 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); | 2007 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); |
| 2009 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 2008 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
| 2010 EXPECT_TRUE(scheduler->frame_source().NeedsBeginFrames()); | 2009 EXPECT_TRUE(scheduler_->frame_source().NeedsBeginFrames()); |
| 2011 | 2010 |
| 2012 // NotifyReadyToCommit should trigger the commit. | 2011 // NotifyReadyToCommit should trigger the commit. |
| 2013 client.Reset(); | 2012 client_->Reset(); |
| 2014 scheduler->NotifyBeginMainFrameStarted(); | 2013 scheduler_->NotifyBeginMainFrameStarted(); |
| 2015 scheduler->NotifyReadyToCommit(); | 2014 scheduler_->NotifyReadyToCommit(); |
| 2016 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); | 2015 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_); |
| 2017 EXPECT_TRUE(scheduler->frame_source().NeedsBeginFrames()); | 2016 EXPECT_TRUE(scheduler_->frame_source().NeedsBeginFrames()); |
| 2018 | 2017 |
| 2019 client.Reset(); | 2018 client_->Reset(); |
| 2020 scheduler->DidLoseOutputSurface(); | 2019 scheduler_->DidLoseOutputSurface(); |
| 2021 EXPECT_NO_ACTION(client); | 2020 EXPECT_NO_ACTION(client_); |
| 2022 EXPECT_FALSE(scheduler->frame_source().NeedsBeginFrames()); | 2021 EXPECT_FALSE(scheduler_->frame_source().NeedsBeginFrames()); |
| 2023 | 2022 |
| 2024 client.Reset(); | 2023 client_->Reset(); |
| 2025 client.task_runner().RunPendingTasks(); // Run posted deadline. | 2024 client_->task_runner().RunPendingTasks(); // Run posted deadline. |
| 2026 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); | 2025 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client_); |
| 2027 EXPECT_FALSE(scheduler->frame_source().NeedsBeginFrames()); | 2026 EXPECT_FALSE(scheduler_->frame_source().NeedsBeginFrames()); |
| 2028 } | 2027 } |
| 2029 | 2028 |
| 2030 TEST(SchedulerTest, ScheduledActionActivateAfterBecomingInvisible) { | 2029 TEST_F(SchedulerTest, ScheduledActionActivateAfterBecomingInvisible) { |
| 2031 FakeSchedulerClient client; | 2030 scheduler_settings_.impl_side_painting = true; |
| 2032 SchedulerSettings scheduler_settings; | 2031 scheduler_settings_.use_external_begin_frame_source = true; |
| 2033 scheduler_settings.impl_side_painting = true; | 2032 SetUpScheduler(true); |
| 2034 scheduler_settings.use_external_begin_frame_source = true; | |
| 2035 | |
| 2036 CREATE_SCHEDULER_AND_INIT_SURFACE(scheduler_settings); | |
| 2037 | 2033 |
| 2038 // SetNeedsCommit should begin the frame. | 2034 // SetNeedsCommit should begin the frame. |
| 2039 scheduler->SetNeedsCommit(); | 2035 scheduler_->SetNeedsCommit(); |
| 2040 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client); | 2036 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client_); |
| 2041 | 2037 |
| 2042 client.Reset(); | 2038 client_->Reset(); |
| 2043 EXPECT_SCOPED(client.AdvanceFrame()); | 2039 EXPECT_SCOPED(client_->AdvanceFrame()); |
| 2044 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 2040 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
| 2045 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); | 2041 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); |
| 2046 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 2042 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
| 2047 | 2043 |
| 2048 client.Reset(); | 2044 client_->Reset(); |
| 2049 scheduler->NotifyBeginMainFrameStarted(); | 2045 scheduler_->NotifyBeginMainFrameStarted(); |
| 2050 scheduler->NotifyReadyToCommit(); | 2046 scheduler_->NotifyReadyToCommit(); |
| 2051 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); | 2047 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_); |
| 2052 | 2048 |
| 2053 client.Reset(); | 2049 client_->Reset(); |
| 2054 scheduler->SetVisible(false); | 2050 scheduler_->SetVisible(false); |
| 2055 // Sync tree should be forced to activate. | 2051 // Sync tree should be forced to activate. |
| 2056 EXPECT_ACTION("SetNeedsBeginFrames(false)", client, 0, 2); | 2052 EXPECT_ACTION("SetNeedsBeginFrames(false)", client_, 0, 2); |
| 2057 EXPECT_ACTION("ScheduledActionActivateSyncTree", client, 1, 2); | 2053 EXPECT_ACTION("ScheduledActionActivateSyncTree", client_, 1, 2); |
| 2058 } | 2054 } |
| 2059 | 2055 |
| 2060 TEST(SchedulerTest, SchedulerPowerMonitoring) { | 2056 TEST_F(SchedulerTest, SchedulerPowerMonitoring) { |
| 2061 FakeSchedulerClient client; | 2057 scheduler_settings_.disable_hi_res_timer_tasks_on_battery = true; |
| 2062 SchedulerSettings settings; | 2058 SetUpScheduler(true); |
| 2063 settings.disable_hi_res_timer_tasks_on_battery = true; | |
| 2064 | |
| 2065 CREATE_SCHEDULER_AND_INIT_SURFACE(settings); | |
| 2066 | 2059 |
| 2067 base::TimeTicks before_deadline, after_deadline; | 2060 base::TimeTicks before_deadline, after_deadline; |
| 2068 | 2061 |
| 2069 scheduler->SetNeedsCommit(); | 2062 scheduler_->SetNeedsCommit(); |
| 2070 scheduler->SetNeedsRedraw(); | 2063 scheduler_->SetNeedsRedraw(); |
| 2071 client.Reset(); | 2064 client_->Reset(); |
| 2072 | 2065 |
| 2073 // On non-battery power | 2066 // On non-battery power |
| 2074 EXPECT_FALSE(client.PowerMonitor()->IsOnBatteryPower()); | 2067 EXPECT_FALSE(client_->PowerMonitor()->IsOnBatteryPower()); |
| 2075 | 2068 |
| 2076 EXPECT_SCOPED(client.AdvanceFrame()); | 2069 EXPECT_SCOPED(client_->AdvanceFrame()); |
| 2077 client.Reset(); | 2070 client_->Reset(); |
| 2078 | 2071 |
| 2079 before_deadline = client.now_src()->Now(); | 2072 before_deadline = client_->now_src()->Now(); |
| 2080 EXPECT_TRUE(client.task_runner().RunTasksWhile( | 2073 EXPECT_TRUE(client_->task_runner().RunTasksWhile( |
| 2081 client.ImplFrameDeadlinePending(true))); | 2074 client_->ImplFrameDeadlinePending(true))); |
| 2082 after_deadline = client.now_src()->Now(); | 2075 after_deadline = client_->now_src()->Now(); |
| 2083 | 2076 |
| 2084 // We post a non-zero deadline task when not on battery | 2077 // We post a non-zero deadline task when not on battery |
| 2085 EXPECT_LT(before_deadline, after_deadline); | 2078 EXPECT_LT(before_deadline, after_deadline); |
| 2086 | 2079 |
| 2087 // Switch to battery power | 2080 // Switch to battery power |
| 2088 client.PowerMonitorSource()->GeneratePowerStateEvent(true); | 2081 client_->PowerMonitorSource()->GeneratePowerStateEvent(true); |
| 2089 EXPECT_TRUE(client.PowerMonitor()->IsOnBatteryPower()); | 2082 EXPECT_TRUE(client_->PowerMonitor()->IsOnBatteryPower()); |
| 2090 | 2083 |
| 2091 EXPECT_SCOPED(client.AdvanceFrame()); | 2084 EXPECT_SCOPED(client_->AdvanceFrame()); |
| 2092 scheduler->SetNeedsCommit(); | 2085 scheduler_->SetNeedsCommit(); |
| 2093 scheduler->SetNeedsRedraw(); | 2086 scheduler_->SetNeedsRedraw(); |
| 2094 client.Reset(); | 2087 client_->Reset(); |
| 2095 | 2088 |
| 2096 before_deadline = client.now_src()->Now(); | 2089 before_deadline = client_->now_src()->Now(); |
| 2097 EXPECT_TRUE(client.task_runner().RunTasksWhile( | 2090 EXPECT_TRUE(client_->task_runner().RunTasksWhile( |
| 2098 client.ImplFrameDeadlinePending(true))); | 2091 client_->ImplFrameDeadlinePending(true))); |
| 2099 after_deadline = client.now_src()->Now(); | 2092 after_deadline = client_->now_src()->Now(); |
| 2100 | 2093 |
| 2101 // We post a zero deadline task when on battery | 2094 // We post a zero deadline task when on battery |
| 2102 EXPECT_EQ(before_deadline, after_deadline); | 2095 EXPECT_EQ(before_deadline, after_deadline); |
| 2103 | 2096 |
| 2104 // Switch to non-battery power | 2097 // Switch to non-battery power |
| 2105 client.PowerMonitorSource()->GeneratePowerStateEvent(false); | 2098 client_->PowerMonitorSource()->GeneratePowerStateEvent(false); |
| 2106 EXPECT_FALSE(client.PowerMonitor()->IsOnBatteryPower()); | 2099 EXPECT_FALSE(client_->PowerMonitor()->IsOnBatteryPower()); |
| 2107 | 2100 |
| 2108 EXPECT_SCOPED(client.AdvanceFrame()); | 2101 EXPECT_SCOPED(client_->AdvanceFrame()); |
| 2109 scheduler->SetNeedsCommit(); | 2102 scheduler_->SetNeedsCommit(); |
| 2110 scheduler->SetNeedsRedraw(); | 2103 scheduler_->SetNeedsRedraw(); |
| 2111 client.Reset(); | 2104 client_->Reset(); |
| 2112 | 2105 |
| 2113 // Same as before | 2106 // Same as before |
| 2114 before_deadline = client.now_src()->Now(); | 2107 before_deadline = client_->now_src()->Now(); |
| 2115 EXPECT_TRUE(client.task_runner().RunTasksWhile( | 2108 EXPECT_TRUE(client_->task_runner().RunTasksWhile( |
| 2116 client.ImplFrameDeadlinePending(true))); | 2109 client_->ImplFrameDeadlinePending(true))); |
| 2117 after_deadline = client.now_src()->Now(); | 2110 after_deadline = client_->now_src()->Now(); |
| 2118 } | 2111 } |
| 2119 | 2112 |
| 2120 TEST(SchedulerTest, | 2113 TEST_F(SchedulerTest, |
| 2121 SimulateWindowsLowResolutionTimerOnBattery_PrioritizeImplLatencyOff) { | 2114 SimulateWindowsLowResolutionTimerOnBattery_PrioritizeImplLatencyOff) { |
| 2122 FakeSchedulerClient client; | 2115 scheduler_settings_.use_external_begin_frame_source = true; |
| 2123 SchedulerSettings settings; | 2116 SetUpScheduler(true); |
| 2124 settings.use_external_begin_frame_source = true; | |
| 2125 | |
| 2126 CREATE_SCHEDULER_AND_INIT_SURFACE(settings); | |
| 2127 | 2117 |
| 2128 // Set needs commit so that the scheduler tries to wait for the main thread | 2118 // Set needs commit so that the scheduler tries to wait for the main thread |
| 2129 scheduler->SetNeedsCommit(); | 2119 scheduler_->SetNeedsCommit(); |
| 2130 // Set needs redraw so that the scheduler doesn't wait too long | 2120 // Set needs redraw so that the scheduler doesn't wait too long |
| 2131 scheduler->SetNeedsRedraw(); | 2121 scheduler_->SetNeedsRedraw(); |
| 2132 client.Reset(); | 2122 client_->Reset(); |
| 2133 | 2123 |
| 2134 // Switch to battery power | 2124 // Switch to battery power |
| 2135 client.PowerMonitorSource()->GeneratePowerStateEvent(true); | 2125 client_->PowerMonitorSource()->GeneratePowerStateEvent(true); |
| 2136 EXPECT_TRUE(client.PowerMonitor()->IsOnBatteryPower()); | 2126 EXPECT_TRUE(client_->PowerMonitor()->IsOnBatteryPower()); |
| 2137 | 2127 |
| 2138 EXPECT_SCOPED(client.AdvanceFrame()); | 2128 EXPECT_SCOPED(client_->AdvanceFrame()); |
| 2139 scheduler->SetNeedsCommit(); | 2129 scheduler_->SetNeedsCommit(); |
| 2140 scheduler->SetNeedsRedraw(); | 2130 scheduler_->SetNeedsRedraw(); |
| 2141 client.Reset(); | 2131 client_->Reset(); |
| 2142 | 2132 |
| 2143 // Disable auto-advancing of now_src | 2133 // Disable auto-advancing of now_src |
| 2144 client.task_runner().SetAutoAdvanceNowToPendingTasks(false); | 2134 client_->task_runner().SetAutoAdvanceNowToPendingTasks(false); |
| 2145 | 2135 |
| 2146 // Deadline task is pending | 2136 // Deadline task is pending |
| 2147 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 2137 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
| 2148 client.task_runner().RunPendingTasks(); | 2138 client_->task_runner().RunPendingTasks(); |
| 2149 // Deadline task is still pending | 2139 // Deadline task is still pending |
| 2150 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 2140 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
| 2151 | 2141 |
| 2152 // Advance now by 15 ms - same as windows low res timer | 2142 // Advance now by 15 ms - same as windows low res timer |
| 2153 client.now_src()->AdvanceNowMicroseconds(15000); | 2143 client_->now_src()->AdvanceNowMicroseconds(15000); |
| 2154 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 2144 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
| 2155 client.task_runner().RunPendingTasks(); | 2145 client_->task_runner().RunPendingTasks(); |
| 2156 // Deadline task finally completes | 2146 // Deadline task finally completes |
| 2157 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 2147 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); |
| 2158 } | 2148 } |
| 2159 | 2149 |
| 2160 TEST(SchedulerTest, | 2150 TEST_F(SchedulerTest, |
| 2161 SimulateWindowsLowResolutionTimerOnBattery_PrioritizeImplLatencyOn) { | 2151 SimulateWindowsLowResolutionTimerOnBattery_PrioritizeImplLatencyOn) { |
| 2162 FakeSchedulerClient client; | 2152 scheduler_settings_.disable_hi_res_timer_tasks_on_battery = true; |
| 2163 SchedulerSettings settings; | 2153 scheduler_settings_.use_external_begin_frame_source = true; |
| 2164 settings.disable_hi_res_timer_tasks_on_battery = true; | 2154 SetUpScheduler(true); |
| 2165 settings.use_external_begin_frame_source = true; | |
| 2166 | |
| 2167 CREATE_SCHEDULER_AND_INIT_SURFACE(settings); | |
| 2168 | 2155 |
| 2169 // Set needs commit so that the scheduler tries to wait for the main thread | 2156 // Set needs commit so that the scheduler tries to wait for the main thread |
| 2170 scheduler->SetNeedsCommit(); | 2157 scheduler_->SetNeedsCommit(); |
| 2171 // Set needs redraw so that the scheduler doesn't wait too long | 2158 // Set needs redraw so that the scheduler doesn't wait too long |
| 2172 scheduler->SetNeedsRedraw(); | 2159 scheduler_->SetNeedsRedraw(); |
| 2173 client.Reset(); | 2160 client_->Reset(); |
| 2174 | 2161 |
| 2175 // Switch to battery power | 2162 // Switch to battery power |
| 2176 client.PowerMonitorSource()->GeneratePowerStateEvent(true); | 2163 client_->PowerMonitorSource()->GeneratePowerStateEvent(true); |
| 2177 EXPECT_TRUE(client.PowerMonitor()->IsOnBatteryPower()); | 2164 EXPECT_TRUE(client_->PowerMonitor()->IsOnBatteryPower()); |
| 2178 | 2165 |
| 2179 EXPECT_SCOPED(client.AdvanceFrame()); | 2166 EXPECT_SCOPED(client_->AdvanceFrame()); |
| 2180 scheduler->SetNeedsCommit(); | 2167 scheduler_->SetNeedsCommit(); |
| 2181 scheduler->SetNeedsRedraw(); | 2168 scheduler_->SetNeedsRedraw(); |
| 2182 client.Reset(); | 2169 client_->Reset(); |
| 2183 | 2170 |
| 2184 // Disable auto-advancing of now_src | 2171 // Disable auto-advancing of now_src |
| 2185 client.task_runner().SetAutoAdvanceNowToPendingTasks(false); | 2172 client_->task_runner().SetAutoAdvanceNowToPendingTasks(false); |
| 2186 | 2173 |
| 2187 // Deadline task is pending | 2174 // Deadline task is pending |
| 2188 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 2175 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
| 2189 client.task_runner().RunPendingTasks(); | 2176 client_->task_runner().RunPendingTasks(); |
| 2190 // Deadline task runs immediately | 2177 // Deadline task runs immediately |
| 2191 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 2178 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); |
| 2192 } | 2179 } |
| 2193 | 2180 |
| 2194 // Tests to ensure frame sources can be successfully changed while drawing. | 2181 // Tests to ensure frame sources can be successfully changed while drawing. |
| 2195 TEST(SchedulerTest, SwitchFrameSourceToUnthrottled) { | 2182 TEST_F(SchedulerTest, SwitchFrameSourceToUnthrottled) { |
| 2196 FakeSchedulerClient client; | 2183 scheduler_settings_.use_external_begin_frame_source = true; |
| 2197 SchedulerSettings scheduler_settings; | 2184 SetUpScheduler(true); |
| 2198 scheduler_settings.use_external_begin_frame_source = true; | |
| 2199 | |
| 2200 CREATE_SCHEDULER_AND_INIT_SURFACE(scheduler_settings); | |
| 2201 | 2185 |
| 2202 // SetNeedsRedraw should begin the frame on the next BeginImplFrame. | 2186 // SetNeedsRedraw should begin the frame on the next BeginImplFrame. |
| 2203 scheduler->SetNeedsRedraw(); | 2187 scheduler_->SetNeedsRedraw(); |
| 2204 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client); | 2188 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client_); |
| 2205 client.Reset(); | 2189 client_->Reset(); |
| 2206 | 2190 |
| 2207 EXPECT_SCOPED(client.AdvanceFrame()); | 2191 EXPECT_SCOPED(client_->AdvanceFrame()); |
| 2208 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 2192 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
| 2209 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); | 2193 EXPECT_ACTION("ScheduledActionAnimate", client_, 1, 2); |
| 2210 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 2194 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
| 2211 EXPECT_TRUE(client.needs_begin_frames()); | 2195 EXPECT_TRUE(client_->needs_begin_frames()); |
| 2212 client.Reset(); | 2196 client_->Reset(); |
| 2213 client.task_runner().RunPendingTasks(); // Run posted deadline. | 2197 client_->task_runner().RunPendingTasks(); // Run posted deadline. |
| 2214 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 1); | 2198 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 0, 1); |
| 2215 scheduler->SetNeedsRedraw(); | 2199 scheduler_->SetNeedsRedraw(); |
| 2216 | 2200 |
| 2217 // Switch to an unthrottled frame source. | 2201 // Switch to an unthrottled frame source. |
| 2218 scheduler->SetThrottleFrameProduction(false); | 2202 scheduler_->SetThrottleFrameProduction(false); |
| 2219 client.Reset(); | 2203 client_->Reset(); |
| 2220 | 2204 |
| 2221 // Unthrottled frame source will immediately begin a new frame. | 2205 // Unthrottled frame source will immediately begin a new frame. |
| 2222 client.task_runner().RunPendingTasks(); // Run posted BeginFrame. | 2206 client_->task_runner().RunPendingTasks(); // Run posted BeginFrame. |
| 2223 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 2207 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
| 2224 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); | 2208 EXPECT_ACTION("ScheduledActionAnimate", client_, 1, 2); |
| 2225 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 2209 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
| 2226 client.Reset(); | 2210 client_->Reset(); |
| 2227 | 2211 |
| 2228 // If we don't swap on the deadline, we wait for the next BeginFrame. | 2212 // If we don't swap on the deadline, we wait for the next BeginFrame. |
| 2229 client.task_runner().RunPendingTasks(); // Run posted deadline. | 2213 client_->task_runner().RunPendingTasks(); // Run posted deadline. |
| 2230 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 1); | 2214 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 0, 1); |
| 2231 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 2215 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); |
| 2232 client.Reset(); | 2216 client_->Reset(); |
| 2233 } | 2217 } |
| 2234 | 2218 |
| 2235 // Tests to ensure frame sources can be successfully changed while a frame | 2219 // Tests to ensure frame sources can be successfully changed while a frame |
| 2236 // deadline is pending. | 2220 // deadline is pending. |
| 2237 TEST(SchedulerTest, SwitchFrameSourceToUnthrottledBeforeDeadline) { | 2221 TEST_F(SchedulerTest, SwitchFrameSourceToUnthrottledBeforeDeadline) { |
| 2238 FakeSchedulerClient client; | 2222 scheduler_settings_.use_external_begin_frame_source = true; |
| 2239 SchedulerSettings scheduler_settings; | 2223 SetUpScheduler(true); |
| 2240 scheduler_settings.use_external_begin_frame_source = true; | |
| 2241 | |
| 2242 CREATE_SCHEDULER_AND_INIT_SURFACE(scheduler_settings); | |
| 2243 | 2224 |
| 2244 // SetNeedsRedraw should begin the frame on the next BeginImplFrame. | 2225 // SetNeedsRedraw should begin the frame on the next BeginImplFrame. |
| 2245 scheduler->SetNeedsRedraw(); | 2226 scheduler_->SetNeedsRedraw(); |
| 2246 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client); | 2227 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client_); |
| 2247 client.Reset(); | 2228 client_->Reset(); |
| 2248 | 2229 |
| 2249 EXPECT_SCOPED(client.AdvanceFrame()); | 2230 EXPECT_SCOPED(client_->AdvanceFrame()); |
| 2250 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 2231 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
| 2251 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); | 2232 EXPECT_ACTION("ScheduledActionAnimate", client_, 1, 2); |
| 2252 | 2233 |
| 2253 // Switch to an unthrottled frame source before the frame deadline is hit. | 2234 // Switch to an unthrottled frame source before the frame deadline is hit. |
| 2254 scheduler->SetThrottleFrameProduction(false); | 2235 scheduler_->SetThrottleFrameProduction(false); |
| 2255 client.Reset(); | 2236 client_->Reset(); |
| 2256 | 2237 |
| 2257 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 2238 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
| 2258 EXPECT_TRUE(client.needs_begin_frames()); | 2239 EXPECT_TRUE(client_->needs_begin_frames()); |
| 2259 client.Reset(); | 2240 client_->Reset(); |
| 2260 | 2241 |
| 2261 client.task_runner() | 2242 client_->task_runner() |
| 2262 .RunPendingTasks(); // Run posted deadline and BeginFrame. | 2243 .RunPendingTasks(); // Run posted deadline and BeginFrame. |
| 2263 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 2); | 2244 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 0, 2); |
| 2264 // Unthrottled frame source will immediately begin a new frame. | 2245 // Unthrottled frame source will immediately begin a new frame. |
| 2265 EXPECT_ACTION("WillBeginImplFrame", client, 1, 2); | 2246 EXPECT_ACTION("WillBeginImplFrame", client_, 1, 2); |
| 2266 scheduler->SetNeedsRedraw(); | 2247 scheduler_->SetNeedsRedraw(); |
| 2267 client.Reset(); | 2248 client_->Reset(); |
| 2268 | 2249 |
| 2269 client.task_runner().RunPendingTasks(); // Run posted deadline. | 2250 client_->task_runner().RunPendingTasks(); // Run posted deadline. |
| 2270 EXPECT_ACTION("ScheduledActionAnimate", client, 0, 2); | 2251 EXPECT_ACTION("ScheduledActionAnimate", client_, 0, 2); |
| 2271 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 1, 2); | 2252 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 1, 2); |
| 2272 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 2253 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); |
| 2273 client.Reset(); | 2254 client_->Reset(); |
| 2274 } | 2255 } |
| 2275 | 2256 |
| 2276 // Tests to ensure that the active frame source can successfully be changed from | 2257 // Tests to ensure that the active frame source can successfully be changed from |
| 2277 // unthrottled to throttled. | 2258 // unthrottled to throttled. |
| 2278 TEST(SchedulerTest, SwitchFrameSourceToThrottled) { | 2259 TEST_F(SchedulerTest, SwitchFrameSourceToThrottled) { |
| 2279 FakeSchedulerClient client; | 2260 scheduler_settings_.throttle_frame_production = false; |
| 2280 SchedulerSettings scheduler_settings; | 2261 scheduler_settings_.use_external_begin_frame_source = true; |
| 2281 scheduler_settings.throttle_frame_production = false; | 2262 SetUpScheduler(true); |
| 2282 scheduler_settings.use_external_begin_frame_source = true; | 2263 |
| 2283 | 2264 scheduler_->SetNeedsRedraw(); |
| 2284 CREATE_SCHEDULER_AND_INIT_SURFACE(scheduler_settings); | 2265 EXPECT_NO_ACTION(client_); |
| 2285 | 2266 client_->Reset(); |
| 2286 scheduler->SetNeedsRedraw(); | 2267 |
| 2287 EXPECT_NO_ACTION(client); | 2268 client_->task_runner().RunPendingTasks(); // Run posted BeginFrame. |
| 2288 client.Reset(); | 2269 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
| 2289 | 2270 EXPECT_ACTION("ScheduledActionAnimate", client_, 1, 2); |
| 2290 client.task_runner().RunPendingTasks(); // Run posted BeginFrame. | 2271 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
| 2291 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 2272 client_->Reset(); |
| 2292 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); | 2273 |
| 2293 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 2274 client_->task_runner().RunPendingTasks(); // Run posted deadline. |
| 2294 client.Reset(); | 2275 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 0, 1); |
| 2295 | 2276 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); |
| 2296 client.task_runner().RunPendingTasks(); // Run posted deadline. | 2277 client_->Reset(); |
| 2297 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 1); | |
| 2298 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | |
| 2299 client.Reset(); | |
| 2300 | 2278 |
| 2301 // Switch to a throttled frame source. | 2279 // Switch to a throttled frame source. |
| 2302 scheduler->SetThrottleFrameProduction(true); | 2280 scheduler_->SetThrottleFrameProduction(true); |
| 2303 client.Reset(); | 2281 client_->Reset(); |
| 2304 | 2282 |
| 2305 // SetNeedsRedraw should begin the frame on the next BeginImplFrame. | 2283 // SetNeedsRedraw should begin the frame on the next BeginImplFrame. |
| 2306 scheduler->SetNeedsRedraw(); | 2284 scheduler_->SetNeedsRedraw(); |
| 2307 client.task_runner().RunPendingTasks(); | 2285 client_->task_runner().RunPendingTasks(); |
| 2308 EXPECT_NO_ACTION(client); | 2286 EXPECT_NO_ACTION(client_); |
| 2309 client.Reset(); | 2287 client_->Reset(); |
| 2310 | 2288 |
| 2311 EXPECT_SCOPED(client.AdvanceFrame()); | 2289 EXPECT_SCOPED(client_->AdvanceFrame()); |
| 2312 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 2290 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
| 2313 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); | 2291 EXPECT_ACTION("ScheduledActionAnimate", client_, 1, 2); |
| 2314 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 2292 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
| 2315 EXPECT_TRUE(client.needs_begin_frames()); | 2293 EXPECT_TRUE(client_->needs_begin_frames()); |
| 2316 client.Reset(); | 2294 client_->Reset(); |
| 2317 client.task_runner().RunPendingTasks(); // Run posted deadline. | 2295 client_->task_runner().RunPendingTasks(); // Run posted deadline. |
| 2318 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 1); | 2296 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 0, 1); |
| 2319 } | 2297 } |
| 2320 | 2298 |
| 2321 } // namespace | 2299 } // namespace |
| 2322 } // namespace cc | 2300 } // namespace cc |
| OLD | NEW |