| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 390 // called inside EXPECT_SCOPED like so; | 390 // called inside EXPECT_SCOPED like so; |
| 391 // EXPECT_SCOPED(client.AdvanceFrame()); | 391 // EXPECT_SCOPED(client.AdvanceFrame()); |
| 392 void AdvanceFrame() { | 392 void AdvanceFrame() { |
| 393 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug.scheduler.frames"), | 393 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug.scheduler.frames"), |
| 394 "FakeSchedulerClient::AdvanceFrame"); | 394 "FakeSchedulerClient::AdvanceFrame"); |
| 395 | 395 |
| 396 // Send the next BeginFrame message if using an external source, otherwise | 396 // Send the next BeginFrame message if using an external source, otherwise |
| 397 // it will be already in the task queue. | 397 // it will be already in the task queue. |
| 398 if (scheduler_->begin_frame_source() == | 398 if (scheduler_->begin_frame_source() == |
| 399 fake_external_begin_frame_source_.get()) { | 399 fake_external_begin_frame_source_.get()) { |
| 400 // Run pending task for previous deadline first. | |
| 401 task_runner_->RunPendingTasks(); | |
| 402 EXPECT_TRUE(scheduler_->begin_frames_expected()); | 400 EXPECT_TRUE(scheduler_->begin_frames_expected()); |
| 403 SendNextBeginFrame(); | 401 SendNextBeginFrame(); |
| 404 } else { | 402 } else { |
| 405 // Begin frame might be queued up and posted after the previous deadline | |
| 406 // runs so run tasks until we get to the next frame. | |
| 407 task_runner_->RunTasksWhile(client_->FrameHasNotAdvancedCallback()); | 403 task_runner_->RunTasksWhile(client_->FrameHasNotAdvancedCallback()); |
| 408 } | 404 } |
| 409 } | 405 } |
| 410 | 406 |
| 411 BeginFrameArgs SendNextBeginFrame() { | 407 BeginFrameArgs SendNextBeginFrame() { |
| 412 DCHECK_EQ(scheduler_->begin_frame_source(), | 408 DCHECK_EQ(scheduler_->begin_frame_source(), |
| 413 fake_external_begin_frame_source_.get()); | 409 fake_external_begin_frame_source_.get()); |
| 414 // Creep the time forward so that any BeginFrameArgs is not equal to the | 410 // Creep the time forward so that any BeginFrameArgs is not equal to the |
| 415 // last one otherwise we violate the BeginFrameSource contract. | 411 // last one otherwise we violate the BeginFrameSource contract. |
| 416 now_src_->Advance(BeginFrameArgs::DefaultInterval()); | 412 now_src_->Advance(BeginFrameArgs::DefaultInterval()); |
| (...skipping 3090 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3507 client_->Reset(); | 3503 client_->Reset(); |
| 3508 | 3504 |
| 3509 SendNextBeginFrame(); | 3505 SendNextBeginFrame(); |
| 3510 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 1); | 3506 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 1); |
| 3511 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); | 3507 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); |
| 3512 // Until tiles were prepared, further proactive BeginFrames are expected. | 3508 // Until tiles were prepared, further proactive BeginFrames are expected. |
| 3513 EXPECT_TRUE(scheduler_->begin_frames_expected()); | 3509 EXPECT_TRUE(scheduler_->begin_frames_expected()); |
| 3514 client_->Reset(); | 3510 client_->Reset(); |
| 3515 | 3511 |
| 3516 // Send the next BeginFrame before the previous one's deadline was executed. | 3512 // Send the next BeginFrame before the previous one's deadline was executed. |
| 3517 // This will wait for the previous deadline after which no further BeginFrames | 3513 // This should trigger the previous BeginFrame's deadline synchronously, |
| 3518 // will be needed, and the new BeginFrame should be dropped. | 3514 // during which tiles will be prepared. As a result of that, no further |
| 3515 // BeginFrames will be needed, and the new BeginFrame should be dropped. |
| 3519 BeginFrameArgs args = SendNextBeginFrame(); | 3516 BeginFrameArgs args = SendNextBeginFrame(); |
| 3520 | |
| 3521 task_runner().RunPendingTasks(); // Run posted deadline. | |
| 3522 EXPECT_ACTION("ScheduledActionPrepareTiles", client_, 0, 3); | 3517 EXPECT_ACTION("ScheduledActionPrepareTiles", client_, 0, 3); |
| 3523 EXPECT_ACTION("RemoveObserver(this)", client_, 1, 3); | 3518 EXPECT_ACTION("RemoveObserver(this)", client_, 1, 3); |
| 3524 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 2, 3); | 3519 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 2, 3); |
| 3525 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); | 3520 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); |
| 3526 EXPECT_FALSE(scheduler_->begin_frames_expected()); | 3521 EXPECT_FALSE(scheduler_->begin_frames_expected()); |
| 3527 client_->Reset(); | 3522 client_->Reset(); |
| 3528 | 3523 |
| 3529 // Latest ack should be for the dropped BeginFrame. Since we don't have | 3524 // Latest ack should be for the dropped BeginFrame. Since we don't have |
| 3530 // further updates, its |latest_confirmed_sequence_number| should be for the | 3525 // further updates, its |latest_confirmed_sequence_number| should be for the |
| 3531 // dropped BeginFrame, too. | 3526 // dropped BeginFrame, too. |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3678 // |latest_confirmed_sequence_number| should be set to invalid. | 3673 // |latest_confirmed_sequence_number| should be set to invalid. |
| 3679 uint64_t latest_confirmed_sequence_number = | 3674 uint64_t latest_confirmed_sequence_number = |
| 3680 BeginFrameArgs::kInvalidFrameNumber; | 3675 BeginFrameArgs::kInvalidFrameNumber; |
| 3681 bool has_damage = false; | 3676 bool has_damage = false; |
| 3682 EXPECT_EQ( | 3677 EXPECT_EQ( |
| 3683 BeginFrameAck(args.source_id, args.sequence_number, | 3678 BeginFrameAck(args.source_id, args.sequence_number, |
| 3684 latest_confirmed_sequence_number, has_damage), | 3679 latest_confirmed_sequence_number, has_damage), |
| 3685 fake_external_begin_frame_source_->LastAckForObserver(scheduler_.get())); | 3680 fake_external_begin_frame_source_->LastAckForObserver(scheduler_.get())); |
| 3686 } | 3681 } |
| 3687 | 3682 |
| 3688 TEST_F(SchedulerTest, BeginFrameWhilePreviousDeadlinePending) { | |
| 3689 SetUpScheduler(EXTERNAL_BFS); | |
| 3690 | |
| 3691 scheduler_->SetNeedsRedraw(); | |
| 3692 | |
| 3693 client_->Reset(); | |
| 3694 EXPECT_SCOPED(AdvanceFrame()); | |
| 3695 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client_); | |
| 3696 | |
| 3697 // Do not run pending deadline but send a new begin frame. The begin frame is | |
| 3698 // saved and run when the previous frame is over. | |
| 3699 client_->Reset(); | |
| 3700 SendNextBeginFrame(); | |
| 3701 EXPECT_NO_ACTION(client_); | |
| 3702 | |
| 3703 task_runner_->RunPendingTasks(); | |
| 3704 EXPECT_SINGLE_ACTION("ScheduledActionDrawIfPossible", client_); | |
| 3705 | |
| 3706 // The saved begin frame is posted as a task. | |
| 3707 client_->Reset(); | |
| 3708 task_runner_->RunPendingTasks(); | |
| 3709 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client_); | |
| 3710 } | |
| 3711 | |
| 3712 TEST_F(SchedulerTest, IncomingBeginFrameReplacesSavedBeginFrame) { | |
| 3713 SetUpScheduler(EXTERNAL_BFS); | |
| 3714 | |
| 3715 scheduler_->SetNeedsRedraw(); | |
| 3716 | |
| 3717 client_->Reset(); | |
| 3718 EXPECT_SCOPED(AdvanceFrame()); | |
| 3719 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client_); | |
| 3720 | |
| 3721 // Send two BeginFrames while deadline is pending. | |
| 3722 client_->Reset(); | |
| 3723 SendNextBeginFrame(); | |
| 3724 EXPECT_NO_ACTION(client_); | |
| 3725 | |
| 3726 SendNextBeginFrame(); | |
| 3727 EXPECT_NO_ACTION(client_); | |
| 3728 | |
| 3729 task_runner_->RunPendingTasks(); | |
| 3730 EXPECT_SINGLE_ACTION("ScheduledActionDrawIfPossible", client_); | |
| 3731 | |
| 3732 // Only the last BeginFrame runs. | |
| 3733 client_->Reset(); | |
| 3734 task_runner_->RunPendingTasks(); | |
| 3735 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client_); | |
| 3736 | |
| 3737 client_->Reset(); | |
| 3738 task_runner_->RunPendingTasks(); | |
| 3739 EXPECT_ACTION("RemoveObserver(this)", client_, 0, 2); | |
| 3740 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 1, 2); | |
| 3741 } | |
| 3742 | |
| 3743 } // namespace | 3683 } // namespace |
| 3744 } // namespace cc | 3684 } // namespace cc |
| OLD | NEW |