| 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 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 | 125 |
| 126 void ScheduledActionSendBeginMainFrame(const BeginFrameArgs& args) override { | 126 void ScheduledActionSendBeginMainFrame(const BeginFrameArgs& args) override { |
| 127 PushAction("ScheduledActionSendBeginMainFrame"); | 127 PushAction("ScheduledActionSendBeginMainFrame"); |
| 128 last_begin_main_frame_args_ = args; | 128 last_begin_main_frame_args_ = args; |
| 129 } | 129 } |
| 130 | 130 |
| 131 const BeginFrameArgs& last_begin_main_frame_args() { | 131 const BeginFrameArgs& last_begin_main_frame_args() { |
| 132 return last_begin_main_frame_args_; | 132 return last_begin_main_frame_args_; |
| 133 } | 133 } |
| 134 | 134 |
| 135 DrawResult ScheduledActionDrawAndSwapIfPossible() override { | 135 DrawResult ScheduledActionSubmitCompositorFrameIfPossible() override { |
| 136 PushAction("ScheduledActionDrawAndSwapIfPossible"); | 136 PushAction("ScheduledActionSubmitCompositorFrameIfPossible"); |
| 137 num_draws_++; | 137 num_draws_++; |
| 138 DrawResult result = | 138 DrawResult result = |
| 139 draw_will_happen_ ? DRAW_SUCCESS : DRAW_ABORTED_CHECKERBOARD_ANIMATIONS; | 139 draw_will_happen_ ? DRAW_SUCCESS : DRAW_ABORTED_CHECKERBOARD_ANIMATIONS; |
| 140 bool swap_will_happen = | 140 bool swap_will_happen = |
| 141 draw_will_happen_ && swap_will_happen_if_draw_happens_; | 141 draw_will_happen_ && swap_will_happen_if_draw_happens_; |
| 142 if (swap_will_happen) { | 142 if (swap_will_happen) { |
| 143 scheduler_->DidSwapBuffers(); | 143 scheduler_->DidSubmitCompositorFrame(); |
| 144 | 144 |
| 145 if (automatic_swap_ack_) | 145 if (automatic_swap_ack_) |
| 146 scheduler_->DidSwapBuffersComplete(); | 146 scheduler_->DidReceiveCompositorFrameAck(); |
| 147 } | 147 } |
| 148 return result; | 148 return result; |
| 149 } | 149 } |
| 150 DrawResult ScheduledActionDrawAndSwapForced() override { | 150 DrawResult ScheduledActionSubmitCompositorFrameForced() override { |
| 151 PushAction("ScheduledActionDrawAndSwapForced"); | 151 PushAction("ScheduledActionSubmitCompositorFrameForced"); |
| 152 return DRAW_SUCCESS; | 152 return DRAW_SUCCESS; |
| 153 } | 153 } |
| 154 void ScheduledActionCommit() override { | 154 void ScheduledActionCommit() override { |
| 155 PushAction("ScheduledActionCommit"); | 155 PushAction("ScheduledActionCommit"); |
| 156 scheduler_->DidCommit(); | 156 scheduler_->DidCommit(); |
| 157 } | 157 } |
| 158 void ScheduledActionActivateSyncTree() override { | 158 void ScheduledActionActivateSyncTree() override { |
| 159 PushAction("ScheduledActionActivateSyncTree"); | 159 PushAction("ScheduledActionActivateSyncTree"); |
| 160 } | 160 } |
| 161 void ScheduledActionBeginCompositorFrameSinkCreation() override { | 161 void ScheduledActionBeginCompositorFrameSinkCreation() override { |
| (...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 412 } | 412 } |
| 413 | 413 |
| 414 FakeExternalBeginFrameSource* fake_external_begin_frame_source() const { | 414 FakeExternalBeginFrameSource* fake_external_begin_frame_source() const { |
| 415 return fake_external_begin_frame_source_.get(); | 415 return fake_external_begin_frame_source_.get(); |
| 416 } | 416 } |
| 417 | 417 |
| 418 void CheckMainFrameSkippedAfterLateCommit(bool expect_send_begin_main_frame); | 418 void CheckMainFrameSkippedAfterLateCommit(bool expect_send_begin_main_frame); |
| 419 void ImplFrameSkippedAfterLateSwapAck(bool swap_ack_before_deadline); | 419 void ImplFrameSkippedAfterLateSwapAck(bool swap_ack_before_deadline); |
| 420 void ImplFrameNotSkippedAfterLateSwapAck(); | 420 void ImplFrameNotSkippedAfterLateSwapAck(); |
| 421 void BeginFramesNotFromClient(BeginFrameSourceType bfs_type); | 421 void BeginFramesNotFromClient(BeginFrameSourceType bfs_type); |
| 422 void BeginFramesNotFromClient_SwapThrottled(BeginFrameSourceType bfs_type); | 422 void BeginFramesNotFromClient_SubmitThrottled(BeginFrameSourceType bfs_type); |
| 423 bool BeginMainFrameOnCriticalPath(TreePriority tree_priority, | 423 bool BeginMainFrameOnCriticalPath(TreePriority tree_priority, |
| 424 ScrollHandlerState scroll_handler_state, | 424 ScrollHandlerState scroll_handler_state, |
| 425 base::TimeDelta durations); | 425 base::TimeDelta durations); |
| 426 | 426 |
| 427 std::unique_ptr<base::SimpleTestTickClock> now_src_; | 427 std::unique_ptr<base::SimpleTestTickClock> now_src_; |
| 428 scoped_refptr<OrderedSimpleTaskRunner> task_runner_; | 428 scoped_refptr<OrderedSimpleTaskRunner> task_runner_; |
| 429 std::unique_ptr<FakeExternalBeginFrameSource> | 429 std::unique_ptr<FakeExternalBeginFrameSource> |
| 430 fake_external_begin_frame_source_; | 430 fake_external_begin_frame_source_; |
| 431 std::unique_ptr<SyntheticBeginFrameSource> synthetic_frame_source_; | 431 std::unique_ptr<SyntheticBeginFrameSource> synthetic_frame_source_; |
| 432 std::unique_ptr<SyntheticBeginFrameSource> unthrottled_frame_source_; | 432 std::unique_ptr<SyntheticBeginFrameSource> unthrottled_frame_source_; |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 530 | 530 |
| 531 // BeginImplFrame should prepare the draw. | 531 // BeginImplFrame should prepare the draw. |
| 532 EXPECT_SCOPED(AdvanceFrame()); | 532 EXPECT_SCOPED(AdvanceFrame()); |
| 533 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 1); | 533 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 1); |
| 534 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); | 534 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); |
| 535 EXPECT_TRUE(scheduler_->begin_frames_expected()); | 535 EXPECT_TRUE(scheduler_->begin_frames_expected()); |
| 536 client_->Reset(); | 536 client_->Reset(); |
| 537 | 537 |
| 538 // BeginImplFrame deadline should draw. | 538 // BeginImplFrame deadline should draw. |
| 539 task_runner().RunPendingTasks(); // Run posted deadline. | 539 task_runner().RunPendingTasks(); // Run posted deadline. |
| 540 EXPECT_SINGLE_ACTION("ScheduledActionDrawAndSwapIfPossible", client_); | 540 EXPECT_SINGLE_ACTION("ScheduledActionSubmitCompositorFrameIfPossible", |
| 541 client_); |
| 541 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); | 542 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); |
| 542 EXPECT_TRUE(scheduler_->begin_frames_expected()); | 543 EXPECT_TRUE(scheduler_->begin_frames_expected()); |
| 543 client_->Reset(); | 544 client_->Reset(); |
| 544 | 545 |
| 545 // The following BeginImplFrame deadline should SetNeedsBeginFrame(false) | 546 // The following BeginImplFrame deadline should SetNeedsBeginFrame(false) |
| 546 // to avoid excessive toggles. | 547 // to avoid excessive toggles. |
| 547 EXPECT_SCOPED(AdvanceFrame()); | 548 EXPECT_SCOPED(AdvanceFrame()); |
| 548 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client_); | 549 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client_); |
| 549 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); | 550 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); |
| 550 client_->Reset(); | 551 client_->Reset(); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 595 scheduler_->SetNeedsRedraw(); | 596 scheduler_->SetNeedsRedraw(); |
| 596 EXPECT_SINGLE_ACTION("AddObserver(this)", client_); | 597 EXPECT_SINGLE_ACTION("AddObserver(this)", client_); |
| 597 | 598 |
| 598 client_->Reset(); | 599 client_->Reset(); |
| 599 AdvanceFrame(); | 600 AdvanceFrame(); |
| 600 // BeginMainFrame is not sent during the defer commit is on. | 601 // BeginMainFrame is not sent during the defer commit is on. |
| 601 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 1); | 602 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 1); |
| 602 | 603 |
| 603 client_->Reset(); | 604 client_->Reset(); |
| 604 task_runner().RunPendingTasks(); // Run posted deadline. | 605 task_runner().RunPendingTasks(); // Run posted deadline. |
| 605 EXPECT_SINGLE_ACTION("ScheduledActionDrawAndSwapIfPossible", client_); | 606 EXPECT_SINGLE_ACTION("ScheduledActionSubmitCompositorFrameIfPossible", |
| 607 client_); |
| 606 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); | 608 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); |
| 607 EXPECT_TRUE(scheduler_->begin_frames_expected()); | 609 EXPECT_TRUE(scheduler_->begin_frames_expected()); |
| 608 | 610 |
| 609 client_->Reset(); | 611 client_->Reset(); |
| 610 AdvanceFrame(); | 612 AdvanceFrame(); |
| 611 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client_); | 613 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client_); |
| 612 } | 614 } |
| 613 | 615 |
| 614 TEST_F(SchedulerTest, RequestCommitAfterBeginMainFrameSent) { | 616 TEST_F(SchedulerTest, RequestCommitAfterBeginMainFrameSent) { |
| 615 SetUpScheduler(EXTERNAL_BFS); | 617 SetUpScheduler(EXTERNAL_BFS); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 640 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); | 642 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); |
| 641 client_->Reset(); | 643 client_->Reset(); |
| 642 | 644 |
| 643 // Activate it. | 645 // Activate it. |
| 644 scheduler_->NotifyReadyToActivate(); | 646 scheduler_->NotifyReadyToActivate(); |
| 645 EXPECT_SINGLE_ACTION("ScheduledActionActivateSyncTree", client_); | 647 EXPECT_SINGLE_ACTION("ScheduledActionActivateSyncTree", client_); |
| 646 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); | 648 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); |
| 647 client_->Reset(); | 649 client_->Reset(); |
| 648 | 650 |
| 649 task_runner().RunPendingTasks(); // Run posted deadline. | 651 task_runner().RunPendingTasks(); // Run posted deadline. |
| 650 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 0, 1); | 652 EXPECT_ACTION("ScheduledActionSubmitCompositorFrameIfPossible", client_, 0, |
| 653 1); |
| 651 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); | 654 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); |
| 652 | 655 |
| 653 // Because we just swapped, the Scheduler should also request the next | 656 // Because we just swapped, the Scheduler should also request the next |
| 654 // BeginImplFrame from the CompositorFrameSink. | 657 // BeginImplFrame from the CompositorFrameSink. |
| 655 EXPECT_TRUE(scheduler_->begin_frames_expected()); | 658 EXPECT_TRUE(scheduler_->begin_frames_expected()); |
| 656 client_->Reset(); | 659 client_->Reset(); |
| 657 // Since another commit is needed, the next BeginImplFrame should initiate | 660 // Since another commit is needed, the next BeginImplFrame should initiate |
| 658 // the second commit. | 661 // the second commit. |
| 659 EXPECT_SCOPED(AdvanceFrame()); | 662 EXPECT_SCOPED(AdvanceFrame()); |
| 660 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); | 663 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
| 661 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); | 664 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); |
| 662 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); | 665 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); |
| 663 client_->Reset(); | 666 client_->Reset(); |
| 664 | 667 |
| 665 // Finishing the commit before the deadline should post a new deadline task | 668 // Finishing the commit before the deadline should post a new deadline task |
| 666 // to trigger the deadline early. | 669 // to trigger the deadline early. |
| 667 scheduler_->NotifyBeginMainFrameStarted(base::TimeTicks()); | 670 scheduler_->NotifyBeginMainFrameStarted(base::TimeTicks()); |
| 668 scheduler_->NotifyReadyToCommit(); | 671 scheduler_->NotifyReadyToCommit(); |
| 669 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_); | 672 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_); |
| 670 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); | 673 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); |
| 671 client_->Reset(); | 674 client_->Reset(); |
| 672 scheduler_->NotifyReadyToActivate(); | 675 scheduler_->NotifyReadyToActivate(); |
| 673 EXPECT_SINGLE_ACTION("ScheduledActionActivateSyncTree", client_); | 676 EXPECT_SINGLE_ACTION("ScheduledActionActivateSyncTree", client_); |
| 674 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); | 677 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); |
| 675 client_->Reset(); | 678 client_->Reset(); |
| 676 task_runner().RunPendingTasks(); // Run posted deadline. | 679 task_runner().RunPendingTasks(); // Run posted deadline. |
| 677 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 0, 1); | 680 EXPECT_ACTION("ScheduledActionSubmitCompositorFrameIfPossible", client_, 0, |
| 681 1); |
| 678 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); | 682 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); |
| 679 EXPECT_TRUE(scheduler_->begin_frames_expected()); | 683 EXPECT_TRUE(scheduler_->begin_frames_expected()); |
| 680 client_->Reset(); | 684 client_->Reset(); |
| 681 | 685 |
| 682 // On the next BeginImplFrame, verify we go back to a quiescent state and | 686 // On the next BeginImplFrame, verify we go back to a quiescent state and |
| 683 // no longer request BeginImplFrames. | 687 // no longer request BeginImplFrames. |
| 684 EXPECT_SCOPED(AdvanceFrame()); | 688 EXPECT_SCOPED(AdvanceFrame()); |
| 685 task_runner().RunPendingTasks(); // Run posted deadline. | 689 task_runner().RunPendingTasks(); // Run posted deadline. |
| 686 EXPECT_FALSE(scheduler_->begin_frames_expected()); | 690 EXPECT_FALSE(scheduler_->begin_frames_expected()); |
| 687 client_->Reset(); | 691 client_->Reset(); |
| 688 } | 692 } |
| 689 | 693 |
| 690 class SchedulerClientThatsetNeedsDrawInsideDraw : public FakeSchedulerClient { | 694 class SchedulerClientThatsetNeedsDrawInsideDraw : public FakeSchedulerClient { |
| 691 public: | 695 public: |
| 692 SchedulerClientThatsetNeedsDrawInsideDraw() | 696 SchedulerClientThatsetNeedsDrawInsideDraw() |
| 693 : FakeSchedulerClient(), request_redraws_(false) {} | 697 : FakeSchedulerClient(), request_redraws_(false) {} |
| 694 | 698 |
| 695 void SetRequestRedrawsInsideDraw(bool enable) { request_redraws_ = enable; } | 699 void SetRequestRedrawsInsideDraw(bool enable) { request_redraws_ = enable; } |
| 696 | 700 |
| 697 DrawResult ScheduledActionDrawAndSwapIfPossible() override { | 701 DrawResult ScheduledActionSubmitCompositorFrameIfPossible() override { |
| 698 // Only SetNeedsRedraw the first time this is called | 702 // Only SetNeedsRedraw the first time this is called |
| 699 if (request_redraws_) { | 703 if (request_redraws_) { |
| 700 scheduler_->SetNeedsRedraw(); | 704 scheduler_->SetNeedsRedraw(); |
| 701 } | 705 } |
| 702 return FakeSchedulerClient::ScheduledActionDrawAndSwapIfPossible(); | 706 return FakeSchedulerClient:: |
| 707 ScheduledActionSubmitCompositorFrameIfPossible(); |
| 703 } | 708 } |
| 704 | 709 |
| 705 DrawResult ScheduledActionDrawAndSwapForced() override { | 710 DrawResult ScheduledActionSubmitCompositorFrameForced() override { |
| 706 NOTREACHED(); | 711 NOTREACHED(); |
| 707 return DRAW_SUCCESS; | 712 return DRAW_SUCCESS; |
| 708 } | 713 } |
| 709 | 714 |
| 710 private: | 715 private: |
| 711 bool request_redraws_; | 716 bool request_redraws_; |
| 712 }; | 717 }; |
| 713 | 718 |
| 714 // Tests for two different situations: | 719 // Tests for two different situations: |
| 715 // 1. the scheduler dropping SetNeedsRedraw requests that happen inside | 720 // 1. the scheduler dropping SetNeedsRedraw requests that happen inside |
| 716 // a ScheduledActionDrawAndSwap | 721 // a ScheduledActionSubmitCompositorFrame |
| 717 // 2. the scheduler drawing twice inside a single tick | 722 // 2. the scheduler drawing twice inside a single tick |
| 718 TEST_F(SchedulerTest, RequestRedrawInsideDraw) { | 723 TEST_F(SchedulerTest, RequestRedrawInsideDraw) { |
| 719 SchedulerClientThatsetNeedsDrawInsideDraw* client = | 724 SchedulerClientThatsetNeedsDrawInsideDraw* client = |
| 720 new SchedulerClientThatsetNeedsDrawInsideDraw; | 725 new SchedulerClientThatsetNeedsDrawInsideDraw; |
| 721 SetUpScheduler(EXTERNAL_BFS, base::WrapUnique(client)); | 726 SetUpScheduler(EXTERNAL_BFS, base::WrapUnique(client)); |
| 722 client->SetRequestRedrawsInsideDraw(true); | 727 client->SetRequestRedrawsInsideDraw(true); |
| 723 | 728 |
| 724 scheduler_->SetNeedsRedraw(); | 729 scheduler_->SetNeedsRedraw(); |
| 725 EXPECT_TRUE(scheduler_->RedrawPending()); | 730 EXPECT_TRUE(scheduler_->RedrawPending()); |
| 726 EXPECT_TRUE(client->needs_begin_frames()); | 731 EXPECT_TRUE(client->needs_begin_frames()); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 793 EXPECT_FALSE(scheduler_->RedrawPending()); | 798 EXPECT_FALSE(scheduler_->RedrawPending()); |
| 794 EXPECT_TRUE(client->needs_begin_frames()); | 799 EXPECT_TRUE(client->needs_begin_frames()); |
| 795 } | 800 } |
| 796 | 801 |
| 797 class SchedulerClientThatSetNeedsBeginMainFrameInsideDraw | 802 class SchedulerClientThatSetNeedsBeginMainFrameInsideDraw |
| 798 : public FakeSchedulerClient { | 803 : public FakeSchedulerClient { |
| 799 public: | 804 public: |
| 800 SchedulerClientThatSetNeedsBeginMainFrameInsideDraw() | 805 SchedulerClientThatSetNeedsBeginMainFrameInsideDraw() |
| 801 : set_needs_commit_on_next_draw_(false) {} | 806 : set_needs_commit_on_next_draw_(false) {} |
| 802 | 807 |
| 803 DrawResult ScheduledActionDrawAndSwapIfPossible() override { | 808 DrawResult ScheduledActionSubmitCompositorFrameIfPossible() override { |
| 804 // Only SetNeedsBeginMainFrame the first time this is called | 809 // Only SetNeedsBeginMainFrame the first time this is called |
| 805 if (set_needs_commit_on_next_draw_) { | 810 if (set_needs_commit_on_next_draw_) { |
| 806 scheduler_->SetNeedsBeginMainFrame(); | 811 scheduler_->SetNeedsBeginMainFrame(); |
| 807 set_needs_commit_on_next_draw_ = false; | 812 set_needs_commit_on_next_draw_ = false; |
| 808 } | 813 } |
| 809 return FakeSchedulerClient::ScheduledActionDrawAndSwapIfPossible(); | 814 return FakeSchedulerClient:: |
| 815 ScheduledActionSubmitCompositorFrameIfPossible(); |
| 810 } | 816 } |
| 811 | 817 |
| 812 DrawResult ScheduledActionDrawAndSwapForced() override { | 818 DrawResult ScheduledActionSubmitCompositorFrameForced() override { |
| 813 NOTREACHED(); | 819 NOTREACHED(); |
| 814 return DRAW_SUCCESS; | 820 return DRAW_SUCCESS; |
| 815 } | 821 } |
| 816 | 822 |
| 817 void SetNeedsBeginMainFrameOnNextDraw() { | 823 void SetNeedsBeginMainFrameOnNextDraw() { |
| 818 set_needs_commit_on_next_draw_ = true; | 824 set_needs_commit_on_next_draw_ = true; |
| 819 } | 825 } |
| 820 | 826 |
| 821 private: | 827 private: |
| 822 bool set_needs_commit_on_next_draw_; | 828 bool set_needs_commit_on_next_draw_; |
| 823 }; | 829 }; |
| 824 | 830 |
| 825 // Tests for the scheduler infinite-looping on SetNeedsBeginMainFrame requests | 831 // Tests for the scheduler infinite-looping on SetNeedsBeginMainFrame requests |
| 826 // that happen inside a ScheduledActionDrawAndSwap | 832 // that happen inside a ScheduledActionSubmitCompositorFrame |
| 827 TEST_F(SchedulerTest, RequestCommitInsideDraw) { | 833 TEST_F(SchedulerTest, RequestCommitInsideDraw) { |
| 828 SchedulerClientThatSetNeedsBeginMainFrameInsideDraw* client = | 834 SchedulerClientThatSetNeedsBeginMainFrameInsideDraw* client = |
| 829 new SchedulerClientThatSetNeedsBeginMainFrameInsideDraw; | 835 new SchedulerClientThatSetNeedsBeginMainFrameInsideDraw; |
| 830 SetUpScheduler(EXTERNAL_BFS, base::WrapUnique(client)); | 836 SetUpScheduler(EXTERNAL_BFS, base::WrapUnique(client)); |
| 831 | 837 |
| 832 EXPECT_FALSE(client->needs_begin_frames()); | 838 EXPECT_FALSE(client->needs_begin_frames()); |
| 833 scheduler_->SetNeedsRedraw(); | 839 scheduler_->SetNeedsRedraw(); |
| 834 EXPECT_TRUE(scheduler_->RedrawPending()); | 840 EXPECT_TRUE(scheduler_->RedrawPending()); |
| 835 EXPECT_EQ(0, client->num_draws()); | 841 EXPECT_EQ(0, client->num_draws()); |
| 836 EXPECT_TRUE(client->needs_begin_frames()); | 842 EXPECT_TRUE(client->needs_begin_frames()); |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 930 // Fail to draw, this should not start a frame. | 936 // Fail to draw, this should not start a frame. |
| 931 client->SetDrawWillHappen(false); | 937 client->SetDrawWillHappen(false); |
| 932 client->SetNeedsBeginMainFrameOnNextDraw(); | 938 client->SetNeedsBeginMainFrameOnNextDraw(); |
| 933 EXPECT_SCOPED(AdvanceFrame()); | 939 EXPECT_SCOPED(AdvanceFrame()); |
| 934 task_runner().RunPendingTasks(); // Run posted deadline. | 940 task_runner().RunPendingTasks(); // Run posted deadline. |
| 935 EXPECT_EQ(2, client->num_draws()); | 941 EXPECT_EQ(2, client->num_draws()); |
| 936 } | 942 } |
| 937 | 943 |
| 938 class SchedulerClientNeedsPrepareTilesInDraw : public FakeSchedulerClient { | 944 class SchedulerClientNeedsPrepareTilesInDraw : public FakeSchedulerClient { |
| 939 public: | 945 public: |
| 940 DrawResult ScheduledActionDrawAndSwapIfPossible() override { | 946 DrawResult ScheduledActionSubmitCompositorFrameIfPossible() override { |
| 941 scheduler_->SetNeedsPrepareTiles(); | 947 scheduler_->SetNeedsPrepareTiles(); |
| 942 return FakeSchedulerClient::ScheduledActionDrawAndSwapIfPossible(); | 948 return FakeSchedulerClient:: |
| 949 ScheduledActionSubmitCompositorFrameIfPossible(); |
| 943 } | 950 } |
| 944 }; | 951 }; |
| 945 | 952 |
| 946 // Test prepare tiles is independant of draws. | 953 // Test prepare tiles is independant of draws. |
| 947 TEST_F(SchedulerTest, PrepareTiles) { | 954 TEST_F(SchedulerTest, PrepareTiles) { |
| 948 SchedulerClientNeedsPrepareTilesInDraw* client = | 955 SchedulerClientNeedsPrepareTilesInDraw* client = |
| 949 new SchedulerClientNeedsPrepareTilesInDraw; | 956 new SchedulerClientNeedsPrepareTilesInDraw; |
| 950 SetUpScheduler(EXTERNAL_BFS, base::WrapUnique(client)); | 957 SetUpScheduler(EXTERNAL_BFS, base::WrapUnique(client)); |
| 951 | 958 |
| 952 // Request both draw and prepare tiles. PrepareTiles shouldn't | 959 // Request both draw and prepare tiles. PrepareTiles shouldn't |
| 953 // be trigged until BeginImplFrame. | 960 // be trigged until BeginImplFrame. |
| 954 client->Reset(); | 961 client->Reset(); |
| 955 scheduler_->SetNeedsPrepareTiles(); | 962 scheduler_->SetNeedsPrepareTiles(); |
| 956 scheduler_->SetNeedsRedraw(); | 963 scheduler_->SetNeedsRedraw(); |
| 957 EXPECT_TRUE(scheduler_->RedrawPending()); | 964 EXPECT_TRUE(scheduler_->RedrawPending()); |
| 958 EXPECT_TRUE(scheduler_->PrepareTilesPending()); | 965 EXPECT_TRUE(scheduler_->PrepareTilesPending()); |
| 959 EXPECT_TRUE(client->needs_begin_frames()); | 966 EXPECT_TRUE(client->needs_begin_frames()); |
| 960 EXPECT_EQ(0, client->num_draws()); | 967 EXPECT_EQ(0, client->num_draws()); |
| 961 EXPECT_FALSE(client->HasAction("ScheduledActionPrepareTiles")); | 968 EXPECT_FALSE(client->HasAction("ScheduledActionPrepareTiles")); |
| 962 EXPECT_FALSE(client->HasAction("ScheduledActionDrawAndSwapIfPossible")); | 969 EXPECT_FALSE( |
| 970 client->HasAction("ScheduledActionSubmitCompositorFrameIfPossible")); |
| 963 | 971 |
| 964 // We have no immediate actions to perform, so the BeginImplFrame should post | 972 // We have no immediate actions to perform, so the BeginImplFrame should post |
| 965 // the deadline task. | 973 // the deadline task. |
| 966 client->Reset(); | 974 client->Reset(); |
| 967 EXPECT_SCOPED(AdvanceFrame()); | 975 EXPECT_SCOPED(AdvanceFrame()); |
| 968 EXPECT_ACTION("WillBeginImplFrame", client, 0, 1); | 976 EXPECT_ACTION("WillBeginImplFrame", client, 0, 1); |
| 969 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); | 977 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); |
| 970 | 978 |
| 971 // On the deadline, the actions should have occured in the right order. | 979 // On the deadline, the actions should have occured in the right order. |
| 972 client->Reset(); | 980 client->Reset(); |
| 973 task_runner().RunPendingTasks(); // Run posted deadline. | 981 task_runner().RunPendingTasks(); // Run posted deadline. |
| 974 EXPECT_EQ(1, client->num_draws()); | 982 EXPECT_EQ(1, client->num_draws()); |
| 975 EXPECT_TRUE(client->HasAction("ScheduledActionDrawAndSwapIfPossible")); | 983 EXPECT_TRUE( |
| 984 client->HasAction("ScheduledActionSubmitCompositorFrameIfPossible")); |
| 976 EXPECT_TRUE(client->HasAction("ScheduledActionPrepareTiles")); | 985 EXPECT_TRUE(client->HasAction("ScheduledActionPrepareTiles")); |
| 977 EXPECT_LT(client->ActionIndex("ScheduledActionDrawAndSwapIfPossible"), | 986 EXPECT_LT( |
| 978 client->ActionIndex("ScheduledActionPrepareTiles")); | 987 client->ActionIndex("ScheduledActionSubmitCompositorFrameIfPossible"), |
| 988 client->ActionIndex("ScheduledActionPrepareTiles")); |
| 979 EXPECT_FALSE(scheduler_->RedrawPending()); | 989 EXPECT_FALSE(scheduler_->RedrawPending()); |
| 980 EXPECT_FALSE(scheduler_->PrepareTilesPending()); | 990 EXPECT_FALSE(scheduler_->PrepareTilesPending()); |
| 981 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); | 991 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); |
| 982 | 992 |
| 983 // Request a draw. We don't need a PrepareTiles yet. | 993 // Request a draw. We don't need a PrepareTiles yet. |
| 984 client->Reset(); | 994 client->Reset(); |
| 985 scheduler_->SetNeedsRedraw(); | 995 scheduler_->SetNeedsRedraw(); |
| 986 EXPECT_TRUE(scheduler_->RedrawPending()); | 996 EXPECT_TRUE(scheduler_->RedrawPending()); |
| 987 EXPECT_FALSE(scheduler_->PrepareTilesPending()); | 997 EXPECT_FALSE(scheduler_->PrepareTilesPending()); |
| 988 EXPECT_TRUE(client->needs_begin_frames()); | 998 EXPECT_TRUE(client->needs_begin_frames()); |
| 989 EXPECT_EQ(0, client->num_draws()); | 999 EXPECT_EQ(0, client->num_draws()); |
| 990 | 1000 |
| 991 // We have no immediate actions to perform, so the BeginImplFrame should post | 1001 // We have no immediate actions to perform, so the BeginImplFrame should post |
| 992 // the deadline task. | 1002 // the deadline task. |
| 993 client->Reset(); | 1003 client->Reset(); |
| 994 EXPECT_SCOPED(AdvanceFrame()); | 1004 EXPECT_SCOPED(AdvanceFrame()); |
| 995 EXPECT_ACTION("WillBeginImplFrame", client, 0, 1); | 1005 EXPECT_ACTION("WillBeginImplFrame", client, 0, 1); |
| 996 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); | 1006 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); |
| 997 | 1007 |
| 998 // Draw. The draw will trigger SetNeedsPrepareTiles, and | 1008 // Draw. The draw will trigger SetNeedsPrepareTiles, and |
| 999 // then the PrepareTiles action will be triggered after the Draw. | 1009 // then the PrepareTiles action will be triggered after the Draw. |
| 1000 // Afterwards, neither a draw nor PrepareTiles are pending. | 1010 // Afterwards, neither a draw nor PrepareTiles are pending. |
| 1001 client->Reset(); | 1011 client->Reset(); |
| 1002 task_runner().RunPendingTasks(); // Run posted deadline. | 1012 task_runner().RunPendingTasks(); // Run posted deadline. |
| 1003 EXPECT_EQ(1, client->num_draws()); | 1013 EXPECT_EQ(1, client->num_draws()); |
| 1004 EXPECT_TRUE(client->HasAction("ScheduledActionDrawAndSwapIfPossible")); | 1014 EXPECT_TRUE( |
| 1015 client->HasAction("ScheduledActionSubmitCompositorFrameIfPossible")); |
| 1005 EXPECT_TRUE(client->HasAction("ScheduledActionPrepareTiles")); | 1016 EXPECT_TRUE(client->HasAction("ScheduledActionPrepareTiles")); |
| 1006 EXPECT_LT(client->ActionIndex("ScheduledActionDrawAndSwapIfPossible"), | 1017 EXPECT_LT( |
| 1007 client->ActionIndex("ScheduledActionPrepareTiles")); | 1018 client->ActionIndex("ScheduledActionSubmitCompositorFrameIfPossible"), |
| 1019 client->ActionIndex("ScheduledActionPrepareTiles")); |
| 1008 EXPECT_FALSE(scheduler_->RedrawPending()); | 1020 EXPECT_FALSE(scheduler_->RedrawPending()); |
| 1009 EXPECT_FALSE(scheduler_->PrepareTilesPending()); | 1021 EXPECT_FALSE(scheduler_->PrepareTilesPending()); |
| 1010 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); | 1022 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); |
| 1011 | 1023 |
| 1012 // We need a BeginImplFrame where we don't swap to go idle. | 1024 // We need a BeginImplFrame where we don't swap to go idle. |
| 1013 client->Reset(); | 1025 client->Reset(); |
| 1014 EXPECT_SCOPED(AdvanceFrame()); | 1026 EXPECT_SCOPED(AdvanceFrame()); |
| 1015 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); | 1027 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); |
| 1016 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); | 1028 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); |
| 1017 client->Reset(); | 1029 client->Reset(); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1031 EXPECT_FALSE(scheduler_->RedrawPending()); | 1043 EXPECT_FALSE(scheduler_->RedrawPending()); |
| 1032 | 1044 |
| 1033 // BeginImplFrame. There will be no draw, only PrepareTiles. | 1045 // BeginImplFrame. There will be no draw, only PrepareTiles. |
| 1034 client->Reset(); | 1046 client->Reset(); |
| 1035 EXPECT_SCOPED(AdvanceFrame()); | 1047 EXPECT_SCOPED(AdvanceFrame()); |
| 1036 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); | 1048 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); |
| 1037 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); | 1049 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); |
| 1038 client->Reset(); | 1050 client->Reset(); |
| 1039 task_runner().RunPendingTasks(); // Run posted deadline. | 1051 task_runner().RunPendingTasks(); // Run posted deadline. |
| 1040 EXPECT_EQ(0, client->num_draws()); | 1052 EXPECT_EQ(0, client->num_draws()); |
| 1041 EXPECT_FALSE(client->HasAction("ScheduledActionDrawAndSwapIfPossible")); | 1053 EXPECT_FALSE( |
| 1054 client->HasAction("ScheduledActionSubmitCompositorFrameIfPossible")); |
| 1042 EXPECT_TRUE(client->HasAction("ScheduledActionPrepareTiles")); | 1055 EXPECT_TRUE(client->HasAction("ScheduledActionPrepareTiles")); |
| 1043 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); | 1056 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); |
| 1044 } | 1057 } |
| 1045 | 1058 |
| 1046 // Test that PrepareTiles only happens once per frame. If an external caller | 1059 // Test that PrepareTiles only happens once per frame. If an external caller |
| 1047 // initiates it, then the state machine should not PrepareTiles on that frame. | 1060 // initiates it, then the state machine should not PrepareTiles on that frame. |
| 1048 TEST_F(SchedulerTest, PrepareTilesOncePerFrame) { | 1061 TEST_F(SchedulerTest, PrepareTilesOncePerFrame) { |
| 1049 SetUpScheduler(EXTERNAL_BFS); | 1062 SetUpScheduler(EXTERNAL_BFS); |
| 1050 | 1063 |
| 1051 // If DidPrepareTiles during a frame, then PrepareTiles should not occur | 1064 // If DidPrepareTiles during a frame, then PrepareTiles should not occur |
| 1052 // again. | 1065 // again. |
| 1053 scheduler_->SetNeedsPrepareTiles(); | 1066 scheduler_->SetNeedsPrepareTiles(); |
| 1054 scheduler_->SetNeedsRedraw(); | 1067 scheduler_->SetNeedsRedraw(); |
| 1055 client_->Reset(); | 1068 client_->Reset(); |
| 1056 EXPECT_SCOPED(AdvanceFrame()); | 1069 EXPECT_SCOPED(AdvanceFrame()); |
| 1057 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 1); | 1070 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 1); |
| 1058 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); | 1071 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); |
| 1059 | 1072 |
| 1060 EXPECT_TRUE(scheduler_->PrepareTilesPending()); | 1073 EXPECT_TRUE(scheduler_->PrepareTilesPending()); |
| 1061 scheduler_->WillPrepareTiles(); | 1074 scheduler_->WillPrepareTiles(); |
| 1062 scheduler_->DidPrepareTiles(); // An explicit PrepareTiles. | 1075 scheduler_->DidPrepareTiles(); // An explicit PrepareTiles. |
| 1063 EXPECT_FALSE(scheduler_->PrepareTilesPending()); | 1076 EXPECT_FALSE(scheduler_->PrepareTilesPending()); |
| 1064 | 1077 |
| 1065 client_->Reset(); | 1078 client_->Reset(); |
| 1066 task_runner().RunPendingTasks(); // Run posted deadline. | 1079 task_runner().RunPendingTasks(); // Run posted deadline. |
| 1067 EXPECT_EQ(1, client_->num_draws()); | 1080 EXPECT_EQ(1, client_->num_draws()); |
| 1068 EXPECT_TRUE(client_->HasAction("ScheduledActionDrawAndSwapIfPossible")); | 1081 EXPECT_TRUE( |
| 1082 client_->HasAction("ScheduledActionSubmitCompositorFrameIfPossible")); |
| 1069 EXPECT_FALSE(client_->HasAction("ScheduledActionPrepareTiles")); | 1083 EXPECT_FALSE(client_->HasAction("ScheduledActionPrepareTiles")); |
| 1070 EXPECT_FALSE(scheduler_->RedrawPending()); | 1084 EXPECT_FALSE(scheduler_->RedrawPending()); |
| 1071 EXPECT_FALSE(scheduler_->PrepareTilesPending()); | 1085 EXPECT_FALSE(scheduler_->PrepareTilesPending()); |
| 1072 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); | 1086 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); |
| 1073 | 1087 |
| 1074 // Next frame without DidPrepareTiles should PrepareTiles with draw. | 1088 // Next frame without DidPrepareTiles should PrepareTiles with draw. |
| 1075 scheduler_->SetNeedsPrepareTiles(); | 1089 scheduler_->SetNeedsPrepareTiles(); |
| 1076 scheduler_->SetNeedsRedraw(); | 1090 scheduler_->SetNeedsRedraw(); |
| 1077 client_->Reset(); | 1091 client_->Reset(); |
| 1078 EXPECT_SCOPED(AdvanceFrame()); | 1092 EXPECT_SCOPED(AdvanceFrame()); |
| 1079 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 1); | 1093 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 1); |
| 1080 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); | 1094 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); |
| 1081 | 1095 |
| 1082 client_->Reset(); | 1096 client_->Reset(); |
| 1083 task_runner().RunPendingTasks(); // Run posted deadline. | 1097 task_runner().RunPendingTasks(); // Run posted deadline. |
| 1084 EXPECT_EQ(1, client_->num_draws()); | 1098 EXPECT_EQ(1, client_->num_draws()); |
| 1085 EXPECT_TRUE(client_->HasAction("ScheduledActionDrawAndSwapIfPossible")); | 1099 EXPECT_TRUE( |
| 1100 client_->HasAction("ScheduledActionSubmitCompositorFrameIfPossible")); |
| 1086 EXPECT_TRUE(client_->HasAction("ScheduledActionPrepareTiles")); | 1101 EXPECT_TRUE(client_->HasAction("ScheduledActionPrepareTiles")); |
| 1087 EXPECT_LT(client_->ActionIndex("ScheduledActionDrawAndSwapIfPossible"), | 1102 EXPECT_LT( |
| 1088 client_->ActionIndex("ScheduledActionPrepareTiles")); | 1103 client_->ActionIndex("ScheduledActionSubmitCompositorFrameIfPossible"), |
| 1104 client_->ActionIndex("ScheduledActionPrepareTiles")); |
| 1089 EXPECT_FALSE(scheduler_->RedrawPending()); | 1105 EXPECT_FALSE(scheduler_->RedrawPending()); |
| 1090 EXPECT_FALSE(scheduler_->PrepareTilesPending()); | 1106 EXPECT_FALSE(scheduler_->PrepareTilesPending()); |
| 1091 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); | 1107 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); |
| 1092 | 1108 |
| 1093 // If we get another DidPrepareTiles within the same frame, we should | 1109 // If we get another DidPrepareTiles within the same frame, we should |
| 1094 // not PrepareTiles on the next frame. | 1110 // not PrepareTiles on the next frame. |
| 1095 scheduler_->WillPrepareTiles(); | 1111 scheduler_->WillPrepareTiles(); |
| 1096 scheduler_->DidPrepareTiles(); // An explicit PrepareTiles. | 1112 scheduler_->DidPrepareTiles(); // An explicit PrepareTiles. |
| 1097 scheduler_->SetNeedsPrepareTiles(); | 1113 scheduler_->SetNeedsPrepareTiles(); |
| 1098 scheduler_->SetNeedsRedraw(); | 1114 scheduler_->SetNeedsRedraw(); |
| 1099 client_->Reset(); | 1115 client_->Reset(); |
| 1100 EXPECT_SCOPED(AdvanceFrame()); | 1116 EXPECT_SCOPED(AdvanceFrame()); |
| 1101 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 1); | 1117 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 1); |
| 1102 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); | 1118 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); |
| 1103 | 1119 |
| 1104 EXPECT_TRUE(scheduler_->PrepareTilesPending()); | 1120 EXPECT_TRUE(scheduler_->PrepareTilesPending()); |
| 1105 | 1121 |
| 1106 client_->Reset(); | 1122 client_->Reset(); |
| 1107 task_runner().RunPendingTasks(); // Run posted deadline. | 1123 task_runner().RunPendingTasks(); // Run posted deadline. |
| 1108 EXPECT_EQ(1, client_->num_draws()); | 1124 EXPECT_EQ(1, client_->num_draws()); |
| 1109 EXPECT_TRUE(client_->HasAction("ScheduledActionDrawAndSwapIfPossible")); | 1125 EXPECT_TRUE( |
| 1126 client_->HasAction("ScheduledActionSubmitCompositorFrameIfPossible")); |
| 1110 EXPECT_FALSE(client_->HasAction("ScheduledActionPrepareTiles")); | 1127 EXPECT_FALSE(client_->HasAction("ScheduledActionPrepareTiles")); |
| 1111 EXPECT_FALSE(scheduler_->RedrawPending()); | 1128 EXPECT_FALSE(scheduler_->RedrawPending()); |
| 1112 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); | 1129 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); |
| 1113 | 1130 |
| 1114 // If we get another DidPrepareTiles, we should not PrepareTiles on the next | 1131 // If we get another DidPrepareTiles, we should not PrepareTiles on the next |
| 1115 // frame. This verifies we don't alternate calling PrepareTiles once and | 1132 // frame. This verifies we don't alternate calling PrepareTiles once and |
| 1116 // twice. | 1133 // twice. |
| 1117 EXPECT_TRUE(scheduler_->PrepareTilesPending()); | 1134 EXPECT_TRUE(scheduler_->PrepareTilesPending()); |
| 1118 scheduler_->WillPrepareTiles(); | 1135 scheduler_->WillPrepareTiles(); |
| 1119 scheduler_->DidPrepareTiles(); // An explicit PrepareTiles. | 1136 scheduler_->DidPrepareTiles(); // An explicit PrepareTiles. |
| 1120 EXPECT_FALSE(scheduler_->PrepareTilesPending()); | 1137 EXPECT_FALSE(scheduler_->PrepareTilesPending()); |
| 1121 scheduler_->SetNeedsPrepareTiles(); | 1138 scheduler_->SetNeedsPrepareTiles(); |
| 1122 scheduler_->SetNeedsRedraw(); | 1139 scheduler_->SetNeedsRedraw(); |
| 1123 client_->Reset(); | 1140 client_->Reset(); |
| 1124 EXPECT_SCOPED(AdvanceFrame()); | 1141 EXPECT_SCOPED(AdvanceFrame()); |
| 1125 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 1); | 1142 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 1); |
| 1126 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); | 1143 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); |
| 1127 | 1144 |
| 1128 EXPECT_TRUE(scheduler_->PrepareTilesPending()); | 1145 EXPECT_TRUE(scheduler_->PrepareTilesPending()); |
| 1129 | 1146 |
| 1130 client_->Reset(); | 1147 client_->Reset(); |
| 1131 task_runner().RunPendingTasks(); // Run posted deadline. | 1148 task_runner().RunPendingTasks(); // Run posted deadline. |
| 1132 EXPECT_EQ(1, client_->num_draws()); | 1149 EXPECT_EQ(1, client_->num_draws()); |
| 1133 EXPECT_TRUE(client_->HasAction("ScheduledActionDrawAndSwapIfPossible")); | 1150 EXPECT_TRUE( |
| 1151 client_->HasAction("ScheduledActionSubmitCompositorFrameIfPossible")); |
| 1134 EXPECT_FALSE(client_->HasAction("ScheduledActionPrepareTiles")); | 1152 EXPECT_FALSE(client_->HasAction("ScheduledActionPrepareTiles")); |
| 1135 EXPECT_FALSE(scheduler_->RedrawPending()); | 1153 EXPECT_FALSE(scheduler_->RedrawPending()); |
| 1136 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); | 1154 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); |
| 1137 | 1155 |
| 1138 // Next frame without DidPrepareTiles should PrepareTiles with draw. | 1156 // Next frame without DidPrepareTiles should PrepareTiles with draw. |
| 1139 scheduler_->SetNeedsPrepareTiles(); | 1157 scheduler_->SetNeedsPrepareTiles(); |
| 1140 scheduler_->SetNeedsRedraw(); | 1158 scheduler_->SetNeedsRedraw(); |
| 1141 client_->Reset(); | 1159 client_->Reset(); |
| 1142 EXPECT_SCOPED(AdvanceFrame()); | 1160 EXPECT_SCOPED(AdvanceFrame()); |
| 1143 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 1); | 1161 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 1); |
| 1144 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); | 1162 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); |
| 1145 | 1163 |
| 1146 client_->Reset(); | 1164 client_->Reset(); |
| 1147 task_runner().RunPendingTasks(); // Run posted deadline. | 1165 task_runner().RunPendingTasks(); // Run posted deadline. |
| 1148 EXPECT_EQ(1, client_->num_draws()); | 1166 EXPECT_EQ(1, client_->num_draws()); |
| 1149 EXPECT_TRUE(client_->HasAction("ScheduledActionDrawAndSwapIfPossible")); | 1167 EXPECT_TRUE( |
| 1168 client_->HasAction("ScheduledActionSubmitCompositorFrameIfPossible")); |
| 1150 EXPECT_TRUE(client_->HasAction("ScheduledActionPrepareTiles")); | 1169 EXPECT_TRUE(client_->HasAction("ScheduledActionPrepareTiles")); |
| 1151 EXPECT_LT(client_->ActionIndex("ScheduledActionDrawAndSwapIfPossible"), | 1170 EXPECT_LT( |
| 1152 client_->ActionIndex("ScheduledActionPrepareTiles")); | 1171 client_->ActionIndex("ScheduledActionSubmitCompositorFrameIfPossible"), |
| 1172 client_->ActionIndex("ScheduledActionPrepareTiles")); |
| 1153 EXPECT_FALSE(scheduler_->RedrawPending()); | 1173 EXPECT_FALSE(scheduler_->RedrawPending()); |
| 1154 EXPECT_FALSE(scheduler_->PrepareTilesPending()); | 1174 EXPECT_FALSE(scheduler_->PrepareTilesPending()); |
| 1155 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); | 1175 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); |
| 1156 } | 1176 } |
| 1157 | 1177 |
| 1158 TEST_F(SchedulerTest, PrepareTilesFunnelResetOnVisibilityChange) { | 1178 TEST_F(SchedulerTest, PrepareTilesFunnelResetOnVisibilityChange) { |
| 1159 std::unique_ptr<SchedulerClientNeedsPrepareTilesInDraw> client = | 1179 std::unique_ptr<SchedulerClientNeedsPrepareTilesInDraw> client = |
| 1160 base::WrapUnique(new SchedulerClientNeedsPrepareTilesInDraw); | 1180 base::WrapUnique(new SchedulerClientNeedsPrepareTilesInDraw); |
| 1161 SetUpScheduler(EXTERNAL_BFS, std::move(client)); | 1181 SetUpScheduler(EXTERNAL_BFS, std::move(client)); |
| 1162 | 1182 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1176 EXPECT_SINGLE_ACTION("AddObserver(this)", client_); | 1196 EXPECT_SINGLE_ACTION("AddObserver(this)", client_); |
| 1177 | 1197 |
| 1178 client_->Reset(); | 1198 client_->Reset(); |
| 1179 AdvanceFrame(); | 1199 AdvanceFrame(); |
| 1180 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 1); | 1200 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 1); |
| 1181 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); | 1201 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); |
| 1182 | 1202 |
| 1183 client_->Reset(); | 1203 client_->Reset(); |
| 1184 task_runner().RunTasksWhile(client_->InsideBeginImplFrame(true)); | 1204 task_runner().RunTasksWhile(client_->InsideBeginImplFrame(true)); |
| 1185 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); | 1205 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); |
| 1186 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 0, 2); | 1206 EXPECT_ACTION("ScheduledActionSubmitCompositorFrameIfPossible", client_, 0, |
| 1207 2); |
| 1187 EXPECT_ACTION("ScheduledActionPrepareTiles", client_, 1, 2); | 1208 EXPECT_ACTION("ScheduledActionPrepareTiles", client_, 1, 2); |
| 1188 } | 1209 } |
| 1189 | 1210 |
| 1190 TEST_F(SchedulerTest, TriggerBeginFrameDeadlineEarly) { | 1211 TEST_F(SchedulerTest, TriggerBeginFrameDeadlineEarly) { |
| 1191 SchedulerClientNeedsPrepareTilesInDraw* client = | 1212 SchedulerClientNeedsPrepareTilesInDraw* client = |
| 1192 new SchedulerClientNeedsPrepareTilesInDraw; | 1213 new SchedulerClientNeedsPrepareTilesInDraw; |
| 1193 SetUpScheduler(EXTERNAL_BFS, base::WrapUnique(client)); | 1214 SetUpScheduler(EXTERNAL_BFS, base::WrapUnique(client)); |
| 1194 | 1215 |
| 1195 scheduler_->SetNeedsRedraw(); | 1216 scheduler_->SetNeedsRedraw(); |
| 1196 EXPECT_SCOPED(AdvanceFrame()); | 1217 EXPECT_SCOPED(AdvanceFrame()); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1229 client_->Reset(); | 1250 client_->Reset(); |
| 1230 task_runner().RunPendingTasks(); // Try to run posted deadline. | 1251 task_runner().RunPendingTasks(); // Try to run posted deadline. |
| 1231 // There is no posted deadline. | 1252 // There is no posted deadline. |
| 1232 EXPECT_NO_ACTION(client_); | 1253 EXPECT_NO_ACTION(client_); |
| 1233 | 1254 |
| 1234 // Scheduler received ready to draw signal, and posted deadline. | 1255 // Scheduler received ready to draw signal, and posted deadline. |
| 1235 scheduler_->NotifyReadyToDraw(); | 1256 scheduler_->NotifyReadyToDraw(); |
| 1236 client_->Reset(); | 1257 client_->Reset(); |
| 1237 task_runner().RunPendingTasks(); // Run posted deadline. | 1258 task_runner().RunPendingTasks(); // Run posted deadline. |
| 1238 EXPECT_EQ(1, client_->num_draws()); | 1259 EXPECT_EQ(1, client_->num_draws()); |
| 1239 EXPECT_TRUE(client_->HasAction("ScheduledActionDrawAndSwapIfPossible")); | 1260 EXPECT_TRUE( |
| 1261 client_->HasAction("ScheduledActionSubmitCompositorFrameIfPossible")); |
| 1240 } | 1262 } |
| 1241 | 1263 |
| 1242 TEST_F(SchedulerTest, WaitForReadyToDrawCancelledWhenLostCompositorFrameSink) { | 1264 TEST_F(SchedulerTest, WaitForReadyToDrawCancelledWhenLostCompositorFrameSink) { |
| 1243 SchedulerClientNeedsPrepareTilesInDraw* client = | 1265 SchedulerClientNeedsPrepareTilesInDraw* client = |
| 1244 new SchedulerClientNeedsPrepareTilesInDraw; | 1266 new SchedulerClientNeedsPrepareTilesInDraw; |
| 1245 scheduler_settings_.commit_to_active_tree = true; | 1267 scheduler_settings_.commit_to_active_tree = true; |
| 1246 SetUpScheduler(EXTERNAL_BFS, base::WrapUnique(client)); | 1268 SetUpScheduler(EXTERNAL_BFS, base::WrapUnique(client)); |
| 1247 | 1269 |
| 1248 // SetNeedsBeginMainFrame should begin the frame on the next BeginImplFrame. | 1270 // SetNeedsBeginMainFrame should begin the frame on the next BeginImplFrame. |
| 1249 scheduler_->SetNeedsBeginMainFrame(); | 1271 scheduler_->SetNeedsBeginMainFrame(); |
| (...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1512 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 2, 3); | 1534 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 2, 3); |
| 1513 | 1535 |
| 1514 client_->Reset(); | 1536 client_->Reset(); |
| 1515 scheduler_->NotifyBeginMainFrameStarted(base::TimeTicks()); | 1537 scheduler_->NotifyBeginMainFrameStarted(base::TimeTicks()); |
| 1516 scheduler_->NotifyReadyToCommit(); | 1538 scheduler_->NotifyReadyToCommit(); |
| 1517 scheduler_->NotifyReadyToActivate(); | 1539 scheduler_->NotifyReadyToActivate(); |
| 1518 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); | 1540 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); |
| 1519 task_runner().RunTasksWhile(client_->InsideBeginImplFrame(true)); | 1541 task_runner().RunTasksWhile(client_->InsideBeginImplFrame(true)); |
| 1520 EXPECT_ACTION("ScheduledActionCommit", client_, 0, 3); | 1542 EXPECT_ACTION("ScheduledActionCommit", client_, 0, 3); |
| 1521 EXPECT_ACTION("ScheduledActionActivateSyncTree", client_, 1, 3); | 1543 EXPECT_ACTION("ScheduledActionActivateSyncTree", client_, 1, 3); |
| 1522 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 2, 3); | 1544 EXPECT_ACTION("ScheduledActionSubmitCompositorFrameIfPossible", client_, 2, |
| 1545 3); |
| 1523 | 1546 |
| 1524 // Verify we skip every other frame if the swap ack consistently | 1547 // Verify we skip every other frame if the swap ack consistently |
| 1525 // comes back late. | 1548 // comes back late. |
| 1526 for (int i = 0; i < 10; i++) { | 1549 for (int i = 0; i < 10; i++) { |
| 1527 // Not calling scheduler_->DidSwapBuffersComplete() until after next | 1550 // Not calling scheduler_->DidReceiveCompositorFrameAck() until after next |
| 1528 // BeginImplFrame puts the impl thread in high latency mode. | 1551 // BeginImplFrame puts the impl thread in high latency mode. |
| 1529 client_->Reset(); | 1552 client_->Reset(); |
| 1530 scheduler_->SetNeedsBeginMainFrame(); | 1553 scheduler_->SetNeedsBeginMainFrame(); |
| 1531 scheduler_->SetNeedsRedraw(); | 1554 scheduler_->SetNeedsRedraw(); |
| 1532 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); | 1555 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); |
| 1533 SendNextBeginFrame(); | 1556 SendNextBeginFrame(); |
| 1534 // Verify that we skip the BeginImplFrame | 1557 // Verify that we skip the BeginImplFrame |
| 1535 EXPECT_NO_ACTION(client_); | 1558 EXPECT_NO_ACTION(client_); |
| 1536 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); | 1559 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); |
| 1537 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); | 1560 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); |
| 1538 | 1561 |
| 1539 // Verify that we do not perform any actions after we are no longer | 1562 // Verify that we do not perform any actions after we are no longer |
| 1540 // swap throttled. | 1563 // swap throttled. |
| 1541 client_->Reset(); | 1564 client_->Reset(); |
| 1542 if (swap_ack_before_deadline) { | 1565 if (swap_ack_before_deadline) { |
| 1543 // It shouldn't matter if the swap ack comes back before the deadline... | 1566 // It shouldn't matter if the swap ack comes back before the deadline... |
| 1544 scheduler_->DidSwapBuffersComplete(); | 1567 scheduler_->DidReceiveCompositorFrameAck(); |
| 1545 task_runner().RunTasksWhile(client_->InsideBeginImplFrame(true)); | 1568 task_runner().RunTasksWhile(client_->InsideBeginImplFrame(true)); |
| 1546 } else { | 1569 } else { |
| 1547 // ... or after the deadline. | 1570 // ... or after the deadline. |
| 1548 task_runner().RunTasksWhile(client_->InsideBeginImplFrame(true)); | 1571 task_runner().RunTasksWhile(client_->InsideBeginImplFrame(true)); |
| 1549 scheduler_->DidSwapBuffersComplete(); | 1572 scheduler_->DidReceiveCompositorFrameAck(); |
| 1550 } | 1573 } |
| 1551 EXPECT_NO_ACTION(client_); | 1574 EXPECT_NO_ACTION(client_); |
| 1552 | 1575 |
| 1553 // Verify that we start the next BeginImplFrame and continue normally | 1576 // Verify that we start the next BeginImplFrame and continue normally |
| 1554 // after having just skipped a BeginImplFrame. | 1577 // after having just skipped a BeginImplFrame. |
| 1555 client_->Reset(); | 1578 client_->Reset(); |
| 1556 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); | 1579 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); |
| 1557 SendNextBeginFrame(); | 1580 SendNextBeginFrame(); |
| 1558 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); | 1581 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
| 1559 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); | 1582 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); |
| 1560 | 1583 |
| 1561 client_->Reset(); | 1584 client_->Reset(); |
| 1562 scheduler_->NotifyBeginMainFrameStarted(base::TimeTicks()); | 1585 scheduler_->NotifyBeginMainFrameStarted(base::TimeTicks()); |
| 1563 scheduler_->NotifyReadyToCommit(); | 1586 scheduler_->NotifyReadyToCommit(); |
| 1564 scheduler_->NotifyReadyToActivate(); | 1587 scheduler_->NotifyReadyToActivate(); |
| 1565 task_runner().RunTasksWhile(client_->InsideBeginImplFrame(true)); | 1588 task_runner().RunTasksWhile(client_->InsideBeginImplFrame(true)); |
| 1566 EXPECT_ACTION("ScheduledActionCommit", client_, 0, 3); | 1589 EXPECT_ACTION("ScheduledActionCommit", client_, 0, 3); |
| 1567 EXPECT_ACTION("ScheduledActionActivateSyncTree", client_, 1, 3); | 1590 EXPECT_ACTION("ScheduledActionActivateSyncTree", client_, 1, 3); |
| 1568 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 2, 3); | 1591 EXPECT_ACTION("ScheduledActionSubmitCompositorFrameIfPossible", client_, 2, |
| 1592 3); |
| 1569 } | 1593 } |
| 1570 } | 1594 } |
| 1571 | 1595 |
| 1572 TEST_F(SchedulerTest, | 1596 TEST_F(SchedulerTest, |
| 1573 ImplFrameSkippedAfterLateSwapAck_FastEstimates_SwapAckThenDeadline) { | 1597 ImplFrameSkippedAfterLateSwapAck_FastEstimates_SwapAckThenDeadline) { |
| 1574 SetUpScheduler(EXTERNAL_BFS); | 1598 SetUpScheduler(EXTERNAL_BFS); |
| 1575 fake_compositor_timing_history_->SetAllEstimatesTo(kFastDuration); | 1599 fake_compositor_timing_history_->SetAllEstimatesTo(kFastDuration); |
| 1576 | 1600 |
| 1577 bool swap_ack_before_deadline = true; | 1601 bool swap_ack_before_deadline = true; |
| 1578 EXPECT_SCOPED(ImplFrameSkippedAfterLateSwapAck(swap_ack_before_deadline)); | 1602 EXPECT_SCOPED(ImplFrameSkippedAfterLateSwapAck(swap_ack_before_deadline)); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1633 client_->Reset(); | 1657 client_->Reset(); |
| 1634 scheduler_->SetNeedsRedraw(); | 1658 scheduler_->SetNeedsRedraw(); |
| 1635 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); | 1659 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); |
| 1636 SendNextBeginFrame(); | 1660 SendNextBeginFrame(); |
| 1637 EXPECT_ACTION("AddObserver(this)", client_, 0, 2); | 1661 EXPECT_ACTION("AddObserver(this)", client_, 0, 2); |
| 1638 EXPECT_ACTION("WillBeginImplFrame", client_, 1, 2); | 1662 EXPECT_ACTION("WillBeginImplFrame", client_, 1, 2); |
| 1639 | 1663 |
| 1640 client_->Reset(); | 1664 client_->Reset(); |
| 1641 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); | 1665 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); |
| 1642 task_runner().RunTasksWhile(client_->InsideBeginImplFrame(true)); | 1666 task_runner().RunTasksWhile(client_->InsideBeginImplFrame(true)); |
| 1643 EXPECT_SINGLE_ACTION("ScheduledActionDrawAndSwapIfPossible", client_); | 1667 EXPECT_SINGLE_ACTION("ScheduledActionSubmitCompositorFrameIfPossible", |
| 1668 client_); |
| 1644 | 1669 |
| 1645 // Verify we skip every other frame if the swap ack consistently | 1670 // Verify we skip every other frame if the swap ack consistently |
| 1646 // comes back late. | 1671 // comes back late. |
| 1647 for (int i = 0; i < 10; i++) { | 1672 for (int i = 0; i < 10; i++) { |
| 1648 // Not calling scheduler_->DidSwapBuffersComplete() until after next | 1673 // Not calling scheduler_->DidReceiveCompositorFrameAck() until after next |
| 1649 // BeginImplFrame puts the impl thread in high latency mode. | 1674 // BeginImplFrame puts the impl thread in high latency mode. |
| 1650 client_->Reset(); | 1675 client_->Reset(); |
| 1651 scheduler_->SetNeedsRedraw(); | 1676 scheduler_->SetNeedsRedraw(); |
| 1652 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); | 1677 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); |
| 1653 SendNextBeginFrame(); | 1678 SendNextBeginFrame(); |
| 1654 // Verify that we skip the BeginImplFrame | 1679 // Verify that we skip the BeginImplFrame |
| 1655 EXPECT_NO_ACTION(client_); | 1680 EXPECT_NO_ACTION(client_); |
| 1656 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); | 1681 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); |
| 1657 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); | 1682 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); |
| 1658 | 1683 |
| 1659 // Verify that we do not perform any actions after we are no longer | 1684 // Verify that we do not perform any actions after we are no longer |
| 1660 // swap throttled. | 1685 // swap throttled. |
| 1661 client_->Reset(); | 1686 client_->Reset(); |
| 1662 scheduler_->DidSwapBuffersComplete(); | 1687 scheduler_->DidReceiveCompositorFrameAck(); |
| 1663 EXPECT_NO_ACTION(client_); | 1688 EXPECT_NO_ACTION(client_); |
| 1664 | 1689 |
| 1665 // Verify that we start the next BeginImplFrame and continue normally | 1690 // Verify that we start the next BeginImplFrame and continue normally |
| 1666 // after having just skipped a BeginImplFrame. | 1691 // after having just skipped a BeginImplFrame. |
| 1667 client_->Reset(); | 1692 client_->Reset(); |
| 1668 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); | 1693 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); |
| 1669 SendNextBeginFrame(); | 1694 SendNextBeginFrame(); |
| 1670 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 1); | 1695 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 1); |
| 1671 | 1696 |
| 1672 client_->Reset(); | 1697 client_->Reset(); |
| 1673 // Deadline should be immediate. | 1698 // Deadline should be immediate. |
| 1674 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); | 1699 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); |
| 1675 task_runner().RunUntilTime(now_src_->NowTicks()); | 1700 task_runner().RunUntilTime(now_src_->NowTicks()); |
| 1676 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); | 1701 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); |
| 1677 EXPECT_SINGLE_ACTION("ScheduledActionDrawAndSwapIfPossible", client_); | 1702 EXPECT_SINGLE_ACTION("ScheduledActionSubmitCompositorFrameIfPossible", |
| 1703 client_); |
| 1678 } | 1704 } |
| 1679 } | 1705 } |
| 1680 | 1706 |
| 1681 void SchedulerTest::ImplFrameNotSkippedAfterLateSwapAck() { | 1707 void SchedulerTest::ImplFrameNotSkippedAfterLateSwapAck() { |
| 1682 // To get into a high latency state, this test disables automatic swap acks. | 1708 // To get into a high latency state, this test disables automatic swap acks. |
| 1683 client_->SetAutomaticSwapAck(false); | 1709 client_->SetAutomaticSwapAck(false); |
| 1684 | 1710 |
| 1685 // Draw and swap for first BeginFrame | 1711 // Draw and swap for first BeginFrame |
| 1686 client_->Reset(); | 1712 client_->Reset(); |
| 1687 scheduler_->SetNeedsBeginMainFrame(); | 1713 scheduler_->SetNeedsBeginMainFrame(); |
| 1688 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); | 1714 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); |
| 1689 SendNextBeginFrame(); | 1715 SendNextBeginFrame(); |
| 1690 EXPECT_ACTION("AddObserver(this)", client_, 0, 3); | 1716 EXPECT_ACTION("AddObserver(this)", client_, 0, 3); |
| 1691 EXPECT_ACTION("WillBeginImplFrame", client_, 1, 3); | 1717 EXPECT_ACTION("WillBeginImplFrame", client_, 1, 3); |
| 1692 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 2, 3); | 1718 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 2, 3); |
| 1693 | 1719 |
| 1694 client_->Reset(); | 1720 client_->Reset(); |
| 1695 scheduler_->NotifyBeginMainFrameStarted(base::TimeTicks()); | 1721 scheduler_->NotifyBeginMainFrameStarted(base::TimeTicks()); |
| 1696 scheduler_->NotifyReadyToCommit(); | 1722 scheduler_->NotifyReadyToCommit(); |
| 1697 scheduler_->NotifyReadyToActivate(); | 1723 scheduler_->NotifyReadyToActivate(); |
| 1698 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); | 1724 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); |
| 1699 task_runner().RunTasksWhile(client_->InsideBeginImplFrame(true)); | 1725 task_runner().RunTasksWhile(client_->InsideBeginImplFrame(true)); |
| 1700 EXPECT_ACTION("ScheduledActionCommit", client_, 0, 3); | 1726 EXPECT_ACTION("ScheduledActionCommit", client_, 0, 3); |
| 1701 EXPECT_ACTION("ScheduledActionActivateSyncTree", client_, 1, 3); | 1727 EXPECT_ACTION("ScheduledActionActivateSyncTree", client_, 1, 3); |
| 1702 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 2, 3); | 1728 EXPECT_ACTION("ScheduledActionSubmitCompositorFrameIfPossible", client_, 2, |
| 1729 3); |
| 1703 | 1730 |
| 1704 // Verify impl thread consistently operates in high latency mode | 1731 // Verify impl thread consistently operates in high latency mode |
| 1705 // without skipping any frames. | 1732 // without skipping any frames. |
| 1706 for (int i = 0; i < 10; i++) { | 1733 for (int i = 0; i < 10; i++) { |
| 1707 // Not calling scheduler_->DidSwapBuffersComplete() until after next frame | 1734 // Not calling scheduler_->DidReceiveCompositorFrameAck() until after next |
| 1735 // frame |
| 1708 // puts the impl thread in high latency mode. | 1736 // puts the impl thread in high latency mode. |
| 1709 client_->Reset(); | 1737 client_->Reset(); |
| 1710 scheduler_->SetNeedsBeginMainFrame(); | 1738 scheduler_->SetNeedsBeginMainFrame(); |
| 1711 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); | 1739 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); |
| 1712 SendNextBeginFrame(); | 1740 SendNextBeginFrame(); |
| 1713 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client_); | 1741 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client_); |
| 1714 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); | 1742 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); |
| 1715 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); | 1743 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); |
| 1716 | 1744 |
| 1717 client_->Reset(); | 1745 client_->Reset(); |
| 1718 scheduler_->DidSwapBuffersComplete(); | 1746 scheduler_->DidReceiveCompositorFrameAck(); |
| 1719 scheduler_->NotifyBeginMainFrameStarted(base::TimeTicks()); | 1747 scheduler_->NotifyBeginMainFrameStarted(base::TimeTicks()); |
| 1720 scheduler_->NotifyReadyToCommit(); | 1748 scheduler_->NotifyReadyToCommit(); |
| 1721 scheduler_->NotifyReadyToActivate(); | 1749 scheduler_->NotifyReadyToActivate(); |
| 1722 task_runner().RunTasksWhile(client_->InsideBeginImplFrame(true)); | 1750 task_runner().RunTasksWhile(client_->InsideBeginImplFrame(true)); |
| 1723 | 1751 |
| 1724 // Verify that we don't skip the actions of the BeginImplFrame | 1752 // Verify that we don't skip the actions of the BeginImplFrame |
| 1725 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 0, 4); | 1753 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 0, 4); |
| 1726 EXPECT_ACTION("ScheduledActionCommit", client_, 1, 4); | 1754 EXPECT_ACTION("ScheduledActionCommit", client_, 1, 4); |
| 1727 EXPECT_ACTION("ScheduledActionActivateSyncTree", client_, 2, 4); | 1755 EXPECT_ACTION("ScheduledActionActivateSyncTree", client_, 2, 4); |
| 1728 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 3, 4); | 1756 EXPECT_ACTION("ScheduledActionSubmitCompositorFrameIfPossible", client_, 3, |
| 1757 4); |
| 1729 } | 1758 } |
| 1730 } | 1759 } |
| 1731 | 1760 |
| 1732 TEST_F( | 1761 TEST_F( |
| 1733 SchedulerTest, | 1762 SchedulerTest, |
| 1734 ImplFrameNotSkippedAfterLateSwapAck_MainFrameQueueDurationCriticalTooLong) { | 1763 ImplFrameNotSkippedAfterLateSwapAck_MainFrameQueueDurationCriticalTooLong) { |
| 1735 SetUpScheduler(EXTERNAL_BFS); | 1764 SetUpScheduler(EXTERNAL_BFS); |
| 1736 fake_compositor_timing_history_->SetAllEstimatesTo(kFastDuration); | 1765 fake_compositor_timing_history_->SetAllEstimatesTo(kFastDuration); |
| 1737 fake_compositor_timing_history_ | 1766 fake_compositor_timing_history_ |
| 1738 ->SetBeginMainFrameQueueDurationCriticalEstimate(kSlowDuration); | 1767 ->SetBeginMainFrameQueueDurationCriticalEstimate(kSlowDuration); |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1812 EXPECT_TRUE(scheduler_->MainThreadMissedLastDeadline()); | 1841 EXPECT_TRUE(scheduler_->MainThreadMissedLastDeadline()); |
| 1813 EXPECT_SCOPED(AdvanceFrame()); | 1842 EXPECT_SCOPED(AdvanceFrame()); |
| 1814 EXPECT_TRUE(scheduler_->MainThreadMissedLastDeadline()); | 1843 EXPECT_TRUE(scheduler_->MainThreadMissedLastDeadline()); |
| 1815 task_runner().RunTasksWhile(client_->InsideBeginImplFrame(true)); | 1844 task_runner().RunTasksWhile(client_->InsideBeginImplFrame(true)); |
| 1816 scheduler_->NotifyBeginMainFrameStarted(base::TimeTicks()); | 1845 scheduler_->NotifyBeginMainFrameStarted(base::TimeTicks()); |
| 1817 scheduler_->NotifyReadyToCommit(); | 1846 scheduler_->NotifyReadyToCommit(); |
| 1818 scheduler_->NotifyReadyToActivate(); | 1847 scheduler_->NotifyReadyToActivate(); |
| 1819 | 1848 |
| 1820 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 5); | 1849 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 5); |
| 1821 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 5); | 1850 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 5); |
| 1822 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 2, 5); | 1851 EXPECT_ACTION("ScheduledActionSubmitCompositorFrameIfPossible", client_, 2, |
| 1852 5); |
| 1823 EXPECT_ACTION("ScheduledActionCommit", client_, 3, 5); | 1853 EXPECT_ACTION("ScheduledActionCommit", client_, 3, 5); |
| 1824 EXPECT_ACTION("ScheduledActionActivateSyncTree", client_, 4, 5); | 1854 EXPECT_ACTION("ScheduledActionActivateSyncTree", client_, 4, 5); |
| 1825 | 1855 |
| 1826 // Don't call scheduler_->DidSwapBuffersComplete() until after next frame | 1856 // Don't call scheduler_->DidReceiveCompositorFrameAck() until after next |
| 1857 // frame |
| 1827 // to put the impl thread in a high latency mode. | 1858 // to put the impl thread in a high latency mode. |
| 1828 client_->Reset(); | 1859 client_->Reset(); |
| 1829 scheduler_->SetNeedsBeginMainFrame(); | 1860 scheduler_->SetNeedsBeginMainFrame(); |
| 1830 EXPECT_TRUE(scheduler_->MainThreadMissedLastDeadline()); | 1861 EXPECT_TRUE(scheduler_->MainThreadMissedLastDeadline()); |
| 1831 EXPECT_SCOPED(AdvanceFrame()); | 1862 EXPECT_SCOPED(AdvanceFrame()); |
| 1832 EXPECT_TRUE(scheduler_->MainThreadMissedLastDeadline()); | 1863 EXPECT_TRUE(scheduler_->MainThreadMissedLastDeadline()); |
| 1833 task_runner().RunTasksWhile(client_->InsideBeginImplFrame(true)); | 1864 task_runner().RunTasksWhile(client_->InsideBeginImplFrame(true)); |
| 1834 | 1865 |
| 1835 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 1); | 1866 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 1); |
| 1836 // Note: BeginMainFrame and swap are skipped here because of | 1867 // Note: BeginMainFrame and swap are skipped here because of |
| 1837 // swap ack backpressure, not because of latency recovery. | 1868 // swap ack backpressure, not because of latency recovery. |
| 1838 EXPECT_FALSE(client_->HasAction("ScheduledActionSendBeginMainFrame")); | 1869 EXPECT_FALSE(client_->HasAction("ScheduledActionSendBeginMainFrame")); |
| 1839 EXPECT_FALSE(client_->HasAction("ScheduledActionDrawAndSwapIfPossible")); | 1870 EXPECT_FALSE( |
| 1871 client_->HasAction("ScheduledActionSubmitCompositorFrameIfPossible")); |
| 1840 EXPECT_TRUE(scheduler_->MainThreadMissedLastDeadline()); | 1872 EXPECT_TRUE(scheduler_->MainThreadMissedLastDeadline()); |
| 1841 | 1873 |
| 1842 // Lower estimates so that the scheduler will attempt latency recovery. | 1874 // Lower estimates so that the scheduler will attempt latency recovery. |
| 1843 fake_compositor_timing_history_->SetAllEstimatesTo(kFastDuration); | 1875 fake_compositor_timing_history_->SetAllEstimatesTo(kFastDuration); |
| 1844 | 1876 |
| 1845 // Now that both threads are in a high latency mode, make sure we | 1877 // Now that both threads are in a high latency mode, make sure we |
| 1846 // skip the BeginMainFrame, then the BeginImplFrame, but not both | 1878 // skip the BeginMainFrame, then the BeginImplFrame, but not both |
| 1847 // at the same time. | 1879 // at the same time. |
| 1848 | 1880 |
| 1849 // Verify we skip BeginMainFrame first. | 1881 // Verify we skip BeginMainFrame first. |
| 1850 client_->Reset(); | 1882 client_->Reset(); |
| 1851 // Previous commit request is still outstanding. | 1883 // Previous commit request is still outstanding. |
| 1852 EXPECT_TRUE(scheduler_->NeedsBeginMainFrame()); | 1884 EXPECT_TRUE(scheduler_->NeedsBeginMainFrame()); |
| 1853 EXPECT_TRUE(scheduler_->SwapThrottled()); | 1885 EXPECT_TRUE(scheduler_->SubmitThrottled()); |
| 1854 SendNextBeginFrame(); | 1886 SendNextBeginFrame(); |
| 1855 EXPECT_TRUE(scheduler_->MainThreadMissedLastDeadline()); | 1887 EXPECT_TRUE(scheduler_->MainThreadMissedLastDeadline()); |
| 1856 scheduler_->DidSwapBuffersComplete(); | 1888 scheduler_->DidReceiveCompositorFrameAck(); |
| 1857 task_runner().RunTasksWhile(client_->InsideBeginImplFrame(true)); | 1889 task_runner().RunTasksWhile(client_->InsideBeginImplFrame(true)); |
| 1858 | 1890 |
| 1859 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); | 1891 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); |
| 1860 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); | 1892 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
| 1861 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 1, 2); | 1893 EXPECT_ACTION("ScheduledActionSubmitCompositorFrameIfPossible", client_, 1, |
| 1894 2); |
| 1862 | 1895 |
| 1863 // Verify we skip the BeginImplFrame second. | 1896 // Verify we skip the BeginImplFrame second. |
| 1864 client_->Reset(); | 1897 client_->Reset(); |
| 1865 // Previous commit request is still outstanding. | 1898 // Previous commit request is still outstanding. |
| 1866 EXPECT_TRUE(scheduler_->NeedsBeginMainFrame()); | 1899 EXPECT_TRUE(scheduler_->NeedsBeginMainFrame()); |
| 1867 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); | 1900 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); |
| 1868 SendNextBeginFrame(); | 1901 SendNextBeginFrame(); |
| 1869 task_runner().RunTasksWhile(client_->InsideBeginImplFrame(true)); | 1902 task_runner().RunTasksWhile(client_->InsideBeginImplFrame(true)); |
| 1870 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); | 1903 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); |
| 1871 scheduler_->DidSwapBuffersComplete(); | 1904 scheduler_->DidReceiveCompositorFrameAck(); |
| 1872 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); | 1905 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); |
| 1873 | 1906 |
| 1874 EXPECT_NO_ACTION(client_); | 1907 EXPECT_NO_ACTION(client_); |
| 1875 | 1908 |
| 1876 // Then verify we operate in a low latency mode. | 1909 // Then verify we operate in a low latency mode. |
| 1877 client_->Reset(); | 1910 client_->Reset(); |
| 1878 // Previous commit request is still outstanding. | 1911 // Previous commit request is still outstanding. |
| 1879 EXPECT_TRUE(scheduler_->NeedsBeginMainFrame()); | 1912 EXPECT_TRUE(scheduler_->NeedsBeginMainFrame()); |
| 1880 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); | 1913 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); |
| 1881 SendNextBeginFrame(); | 1914 SendNextBeginFrame(); |
| 1882 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); | 1915 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); |
| 1883 scheduler_->NotifyBeginMainFrameStarted(base::TimeTicks()); | 1916 scheduler_->NotifyBeginMainFrameStarted(base::TimeTicks()); |
| 1884 scheduler_->NotifyReadyToCommit(); | 1917 scheduler_->NotifyReadyToCommit(); |
| 1885 scheduler_->NotifyReadyToActivate(); | 1918 scheduler_->NotifyReadyToActivate(); |
| 1886 task_runner().RunTasksWhile(client_->InsideBeginImplFrame(true)); | 1919 task_runner().RunTasksWhile(client_->InsideBeginImplFrame(true)); |
| 1887 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); | 1920 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); |
| 1888 scheduler_->DidSwapBuffersComplete(); | 1921 scheduler_->DidReceiveCompositorFrameAck(); |
| 1889 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); | 1922 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); |
| 1890 | 1923 |
| 1891 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 5); | 1924 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 5); |
| 1892 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 5); | 1925 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 5); |
| 1893 EXPECT_ACTION("ScheduledActionCommit", client_, 2, 5); | 1926 EXPECT_ACTION("ScheduledActionCommit", client_, 2, 5); |
| 1894 EXPECT_ACTION("ScheduledActionActivateSyncTree", client_, 3, 5); | 1927 EXPECT_ACTION("ScheduledActionActivateSyncTree", client_, 3, 5); |
| 1895 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 4, 5); | 1928 EXPECT_ACTION("ScheduledActionSubmitCompositorFrameIfPossible", client_, 4, |
| 1929 5); |
| 1896 } | 1930 } |
| 1897 | 1931 |
| 1898 TEST_F( | 1932 TEST_F( |
| 1899 SchedulerTest, | 1933 SchedulerTest, |
| 1900 Deadlock_CommitMakesProgressWhileSwapTrottledAndActiveTreeNeedsFirstDraw) { | 1934 Deadlock_CommitMakesProgressWhileSwapTrottledAndActiveTreeNeedsFirstDraw) { |
| 1901 // NPAPI plugins on Windows block the Browser UI thread on the Renderer main | 1935 // NPAPI plugins on Windows block the Browser UI thread on the Renderer main |
| 1902 // thread. This prevents the scheduler from receiving any pending swap acks. | 1936 // thread. This prevents the scheduler from receiving any pending swap acks. |
| 1903 | 1937 |
| 1904 scheduler_settings_.main_frame_while_swap_throttled_enabled = true; | 1938 scheduler_settings_.main_frame_while_submit_frame_throttled_enabled = true; |
| 1905 SetUpScheduler(EXTERNAL_BFS); | 1939 SetUpScheduler(EXTERNAL_BFS); |
| 1906 | 1940 |
| 1907 // Disables automatic swap acks so this test can force swap ack throttling | 1941 // Disables automatic swap acks so this test can force swap ack throttling |
| 1908 // to simulate a blocked Browser ui thread. | 1942 // to simulate a blocked Browser ui thread. |
| 1909 client_->SetAutomaticSwapAck(false); | 1943 client_->SetAutomaticSwapAck(false); |
| 1910 | 1944 |
| 1911 // Get a new active tree in main-thread high latency mode and put us | 1945 // Get a new active tree in main-thread high latency mode and put us |
| 1912 // in a swap throttled state. | 1946 // in a swap throttled state. |
| 1913 client_->Reset(); | 1947 client_->Reset(); |
| 1914 EXPECT_FALSE(scheduler_->CommitPending()); | 1948 EXPECT_FALSE(scheduler_->CommitPending()); |
| 1915 scheduler_->SetNeedsBeginMainFrame(); | 1949 scheduler_->SetNeedsBeginMainFrame(); |
| 1916 scheduler_->SetNeedsRedraw(); | 1950 scheduler_->SetNeedsRedraw(); |
| 1917 EXPECT_SCOPED(AdvanceFrame()); | 1951 EXPECT_SCOPED(AdvanceFrame()); |
| 1918 EXPECT_TRUE(scheduler_->CommitPending()); | 1952 EXPECT_TRUE(scheduler_->CommitPending()); |
| 1919 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); | 1953 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); |
| 1920 task_runner().RunTasksWhile(client_->InsideBeginImplFrame(true)); | 1954 task_runner().RunTasksWhile(client_->InsideBeginImplFrame(true)); |
| 1921 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); | 1955 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); |
| 1922 scheduler_->NotifyBeginMainFrameStarted(base::TimeTicks()); | 1956 scheduler_->NotifyBeginMainFrameStarted(base::TimeTicks()); |
| 1923 scheduler_->NotifyReadyToCommit(); | 1957 scheduler_->NotifyReadyToCommit(); |
| 1924 scheduler_->NotifyReadyToActivate(); | 1958 scheduler_->NotifyReadyToActivate(); |
| 1925 EXPECT_FALSE(scheduler_->CommitPending()); | 1959 EXPECT_FALSE(scheduler_->CommitPending()); |
| 1926 EXPECT_ACTION("AddObserver(this)", client_, 0, 6); | 1960 EXPECT_ACTION("AddObserver(this)", client_, 0, 6); |
| 1927 EXPECT_ACTION("WillBeginImplFrame", client_, 1, 6); | 1961 EXPECT_ACTION("WillBeginImplFrame", client_, 1, 6); |
| 1928 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 2, 6); | 1962 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 2, 6); |
| 1929 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 3, 6); | 1963 EXPECT_ACTION("ScheduledActionSubmitCompositorFrameIfPossible", client_, 3, |
| 1964 6); |
| 1930 EXPECT_ACTION("ScheduledActionCommit", client_, 4, 6); | 1965 EXPECT_ACTION("ScheduledActionCommit", client_, 4, 6); |
| 1931 EXPECT_ACTION("ScheduledActionActivateSyncTree", client_, 5, 6); | 1966 EXPECT_ACTION("ScheduledActionActivateSyncTree", client_, 5, 6); |
| 1932 | 1967 |
| 1933 // Make sure that we can finish the next commit even while swap throttled. | 1968 // Make sure that we can finish the next commit even while swap throttled. |
| 1934 client_->Reset(); | 1969 client_->Reset(); |
| 1935 EXPECT_FALSE(scheduler_->CommitPending()); | 1970 EXPECT_FALSE(scheduler_->CommitPending()); |
| 1936 scheduler_->SetNeedsBeginMainFrame(); | 1971 scheduler_->SetNeedsBeginMainFrame(); |
| 1937 EXPECT_SCOPED(AdvanceFrame()); | 1972 EXPECT_SCOPED(AdvanceFrame()); |
| 1938 scheduler_->NotifyBeginMainFrameStarted(base::TimeTicks()); | 1973 scheduler_->NotifyBeginMainFrameStarted(base::TimeTicks()); |
| 1939 scheduler_->NotifyReadyToCommit(); | 1974 scheduler_->NotifyReadyToCommit(); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 1957 } | 1992 } |
| 1958 | 1993 |
| 1959 TEST_F( | 1994 TEST_F( |
| 1960 SchedulerTest, | 1995 SchedulerTest, |
| 1961 CommitMakesProgressWhenIdleAndHasPendingTreeAndActiveTreeNeedsFirstDraw) { | 1996 CommitMakesProgressWhenIdleAndHasPendingTreeAndActiveTreeNeedsFirstDraw) { |
| 1962 // This verifies we don't block commits longer than we need to | 1997 // This verifies we don't block commits longer than we need to |
| 1963 // for performance reasons - not deadlock reasons. | 1998 // for performance reasons - not deadlock reasons. |
| 1964 | 1999 |
| 1965 // Since we are simulating a long commit, set up a client with draw duration | 2000 // Since we are simulating a long commit, set up a client with draw duration |
| 1966 // estimates that prevent skipping main frames to get to low latency mode. | 2001 // estimates that prevent skipping main frames to get to low latency mode. |
| 1967 scheduler_settings_.main_frame_while_swap_throttled_enabled = true; | 2002 scheduler_settings_.main_frame_while_submit_frame_throttled_enabled = true; |
| 1968 scheduler_settings_.main_frame_before_activation_enabled = true; | 2003 scheduler_settings_.main_frame_before_activation_enabled = true; |
| 1969 SetUpScheduler(EXTERNAL_BFS); | 2004 SetUpScheduler(EXTERNAL_BFS); |
| 1970 | 2005 |
| 1971 // Disables automatic swap acks so this test can force swap ack throttling | 2006 // Disables automatic swap acks so this test can force swap ack throttling |
| 1972 // to simulate a blocked Browser ui thread. | 2007 // to simulate a blocked Browser ui thread. |
| 1973 client_->SetAutomaticSwapAck(false); | 2008 client_->SetAutomaticSwapAck(false); |
| 1974 | 2009 |
| 1975 // Start a new commit in main-thread high latency mode and hold off on | 2010 // Start a new commit in main-thread high latency mode and hold off on |
| 1976 // activation. | 2011 // activation. |
| 1977 client_->Reset(); | 2012 client_->Reset(); |
| 1978 EXPECT_FALSE(scheduler_->CommitPending()); | 2013 EXPECT_FALSE(scheduler_->CommitPending()); |
| 1979 scheduler_->SetNeedsBeginMainFrame(); | 2014 scheduler_->SetNeedsBeginMainFrame(); |
| 1980 scheduler_->SetNeedsRedraw(); | 2015 scheduler_->SetNeedsRedraw(); |
| 1981 EXPECT_SCOPED(AdvanceFrame()); | 2016 EXPECT_SCOPED(AdvanceFrame()); |
| 1982 EXPECT_TRUE(scheduler_->CommitPending()); | 2017 EXPECT_TRUE(scheduler_->CommitPending()); |
| 1983 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); | 2018 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); |
| 1984 task_runner().RunTasksWhile(client_->InsideBeginImplFrame(true)); | 2019 task_runner().RunTasksWhile(client_->InsideBeginImplFrame(true)); |
| 1985 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); | 2020 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); |
| 1986 scheduler_->DidSwapBuffersComplete(); | 2021 scheduler_->DidReceiveCompositorFrameAck(); |
| 1987 scheduler_->NotifyBeginMainFrameStarted(base::TimeTicks()); | 2022 scheduler_->NotifyBeginMainFrameStarted(base::TimeTicks()); |
| 1988 scheduler_->NotifyReadyToCommit(); | 2023 scheduler_->NotifyReadyToCommit(); |
| 1989 EXPECT_FALSE(scheduler_->CommitPending()); | 2024 EXPECT_FALSE(scheduler_->CommitPending()); |
| 1990 EXPECT_ACTION("AddObserver(this)", client_, 0, 5); | 2025 EXPECT_ACTION("AddObserver(this)", client_, 0, 5); |
| 1991 EXPECT_ACTION("WillBeginImplFrame", client_, 1, 5); | 2026 EXPECT_ACTION("WillBeginImplFrame", client_, 1, 5); |
| 1992 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 2, 5); | 2027 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 2, 5); |
| 1993 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 3, 5); | 2028 EXPECT_ACTION("ScheduledActionSubmitCompositorFrameIfPossible", client_, 3, |
| 2029 5); |
| 1994 EXPECT_ACTION("ScheduledActionCommit", client_, 4, 5); | 2030 EXPECT_ACTION("ScheduledActionCommit", client_, 4, 5); |
| 1995 | 2031 |
| 1996 // Start another commit while we still have an active tree. | 2032 // Start another commit while we still have an active tree. |
| 1997 client_->Reset(); | 2033 client_->Reset(); |
| 1998 EXPECT_FALSE(scheduler_->CommitPending()); | 2034 EXPECT_FALSE(scheduler_->CommitPending()); |
| 1999 scheduler_->SetNeedsBeginMainFrame(); | 2035 scheduler_->SetNeedsBeginMainFrame(); |
| 2000 scheduler_->SetNeedsRedraw(); | 2036 scheduler_->SetNeedsRedraw(); |
| 2001 EXPECT_SCOPED(AdvanceFrame()); | 2037 EXPECT_SCOPED(AdvanceFrame()); |
| 2002 EXPECT_TRUE(scheduler_->CommitPending()); | 2038 EXPECT_TRUE(scheduler_->CommitPending()); |
| 2003 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); | 2039 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); |
| 2004 task_runner().RunTasksWhile(client_->InsideBeginImplFrame(true)); | 2040 task_runner().RunTasksWhile(client_->InsideBeginImplFrame(true)); |
| 2005 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); | 2041 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); |
| 2006 scheduler_->DidSwapBuffersComplete(); | 2042 scheduler_->DidReceiveCompositorFrameAck(); |
| 2007 scheduler_->NotifyBeginMainFrameStarted(base::TimeTicks()); | 2043 scheduler_->NotifyBeginMainFrameStarted(base::TimeTicks()); |
| 2008 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 3); | 2044 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 3); |
| 2009 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 3); | 2045 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 3); |
| 2010 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 2, 3); | 2046 EXPECT_ACTION("ScheduledActionSubmitCompositorFrameIfPossible", client_, 2, |
| 2047 3); |
| 2011 | 2048 |
| 2012 // Can't commit yet because there's still a pending tree. | 2049 // Can't commit yet because there's still a pending tree. |
| 2013 client_->Reset(); | 2050 client_->Reset(); |
| 2014 scheduler_->NotifyReadyToCommit(); | 2051 scheduler_->NotifyReadyToCommit(); |
| 2015 EXPECT_NO_ACTION(client_); | 2052 EXPECT_NO_ACTION(client_); |
| 2016 | 2053 |
| 2017 // Activate the pending tree, which also unblocks the commit immediately | 2054 // Activate the pending tree, which also unblocks the commit immediately |
| 2018 // while we are in an idle state. | 2055 // while we are in an idle state. |
| 2019 client_->Reset(); | 2056 client_->Reset(); |
| 2020 scheduler_->NotifyReadyToActivate(); | 2057 scheduler_->NotifyReadyToActivate(); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 2051 client_->Reset(); | 2088 client_->Reset(); |
| 2052 | 2089 |
| 2053 // NotifyReadyToActivate should trigger the activation. | 2090 // NotifyReadyToActivate should trigger the activation. |
| 2054 scheduler_->NotifyReadyToActivate(); | 2091 scheduler_->NotifyReadyToActivate(); |
| 2055 EXPECT_SINGLE_ACTION("ScheduledActionActivateSyncTree", client_); | 2092 EXPECT_SINGLE_ACTION("ScheduledActionActivateSyncTree", client_); |
| 2056 client_->Reset(); | 2093 client_->Reset(); |
| 2057 | 2094 |
| 2058 // BeginImplFrame deadline should draw. The following BeginImplFrame deadline | 2095 // BeginImplFrame deadline should draw. The following BeginImplFrame deadline |
| 2059 // should SetNeedsBeginFrame(false) to avoid excessive toggles. | 2096 // should SetNeedsBeginFrame(false) to avoid excessive toggles. |
| 2060 EXPECT_SCOPED(AdvanceFrame()); | 2097 EXPECT_SCOPED(AdvanceFrame()); |
| 2061 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 0, 2); | 2098 EXPECT_ACTION("ScheduledActionSubmitCompositorFrameIfPossible", client_, 0, |
| 2099 2); |
| 2062 EXPECT_ACTION("WillBeginImplFrame", client_, 1, 2); | 2100 EXPECT_ACTION("WillBeginImplFrame", client_, 1, 2); |
| 2063 client_->Reset(); | 2101 client_->Reset(); |
| 2064 | 2102 |
| 2065 // Make sure SetNeedsBeginFrame isn't called on the client | 2103 // Make sure SetNeedsBeginFrame isn't called on the client |
| 2066 // when the BeginFrame is no longer needed. | 2104 // when the BeginFrame is no longer needed. |
| 2067 task_runner().RunPendingTasks(); // Run posted deadline. | 2105 task_runner().RunPendingTasks(); // Run posted deadline. |
| 2068 EXPECT_SINGLE_ACTION("SendBeginMainFrameNotExpectedSoon", client_); | 2106 EXPECT_SINGLE_ACTION("SendBeginMainFrameNotExpectedSoon", client_); |
| 2069 client_->Reset(); | 2107 client_->Reset(); |
| 2070 } | 2108 } |
| 2071 | 2109 |
| 2072 TEST_F(SchedulerTest, SyntheticBeginFrames) { | 2110 TEST_F(SchedulerTest, SyntheticBeginFrames) { |
| 2073 BeginFramesNotFromClient(THROTTLED_BFS); | 2111 BeginFramesNotFromClient(THROTTLED_BFS); |
| 2074 } | 2112 } |
| 2075 | 2113 |
| 2076 TEST_F(SchedulerTest, UnthrottledBeginFrames) { | 2114 TEST_F(SchedulerTest, UnthrottledBeginFrames) { |
| 2077 BeginFramesNotFromClient(UNTHROTTLED_BFS); | 2115 BeginFramesNotFromClient(UNTHROTTLED_BFS); |
| 2078 } | 2116 } |
| 2079 | 2117 |
| 2080 void SchedulerTest::BeginFramesNotFromClient_SwapThrottled( | 2118 void SchedulerTest::BeginFramesNotFromClient_SubmitThrottled( |
| 2081 BeginFrameSourceType bfs_type) { | 2119 BeginFrameSourceType bfs_type) { |
| 2082 SetUpScheduler(bfs_type); | 2120 SetUpScheduler(bfs_type); |
| 2083 | 2121 |
| 2084 // Set the draw duration estimate to zero so that deadlines are accurate. | 2122 // Set the draw duration estimate to zero so that deadlines are accurate. |
| 2085 fake_compositor_timing_history_->SetDrawDurationEstimate(base::TimeDelta()); | 2123 fake_compositor_timing_history_->SetDrawDurationEstimate(base::TimeDelta()); |
| 2086 | 2124 |
| 2087 // To test swap ack throttling, this test disables automatic swap acks. | 2125 // To test swap ack throttling, this test disables automatic swap acks. |
| 2088 client_->SetAutomaticSwapAck(false); | 2126 client_->SetAutomaticSwapAck(false); |
| 2089 | 2127 |
| 2090 // SetNeedsBeginMainFrame should begin the frame on the next BeginImplFrame. | 2128 // SetNeedsBeginMainFrame should begin the frame on the next BeginImplFrame. |
| (...skipping 16 matching lines...) Expand all Loading... |
| 2107 client_->Reset(); | 2145 client_->Reset(); |
| 2108 | 2146 |
| 2109 // NotifyReadyToActivate should trigger the activation and draw. | 2147 // NotifyReadyToActivate should trigger the activation and draw. |
| 2110 scheduler_->NotifyReadyToActivate(); | 2148 scheduler_->NotifyReadyToActivate(); |
| 2111 EXPECT_SINGLE_ACTION("ScheduledActionActivateSyncTree", client_); | 2149 EXPECT_SINGLE_ACTION("ScheduledActionActivateSyncTree", client_); |
| 2112 client_->Reset(); | 2150 client_->Reset(); |
| 2113 | 2151 |
| 2114 // Swapping will put us into a swap throttled state. | 2152 // Swapping will put us into a swap throttled state. |
| 2115 // Run posted deadline. | 2153 // Run posted deadline. |
| 2116 task_runner().RunTasksWhile(client_->InsideBeginImplFrame(true)); | 2154 task_runner().RunTasksWhile(client_->InsideBeginImplFrame(true)); |
| 2117 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 0, 1); | 2155 EXPECT_ACTION("ScheduledActionSubmitCompositorFrameIfPossible", client_, 0, |
| 2156 1); |
| 2118 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); | 2157 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); |
| 2119 client_->Reset(); | 2158 client_->Reset(); |
| 2120 | 2159 |
| 2121 // While swap throttled, BeginFrames should trigger BeginImplFrames, | 2160 // While swap throttled, BeginFrames should trigger BeginImplFrames, |
| 2122 // but not a BeginMainFrame or draw. | 2161 // but not a BeginMainFrame or draw. |
| 2123 scheduler_->SetNeedsBeginMainFrame(); | 2162 scheduler_->SetNeedsBeginMainFrame(); |
| 2124 scheduler_->SetNeedsRedraw(); | 2163 scheduler_->SetNeedsRedraw(); |
| 2125 EXPECT_SCOPED(AdvanceFrame()); // Run posted BeginFrame. | 2164 EXPECT_SCOPED(AdvanceFrame()); // Run posted BeginFrame. |
| 2126 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 1); | 2165 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 1); |
| 2127 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); | 2166 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 2140 before_deadline + BeginFrameArgs::DefaultInterval()); | 2179 before_deadline + BeginFrameArgs::DefaultInterval()); |
| 2141 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); | 2180 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); |
| 2142 client_->Reset(); | 2181 client_->Reset(); |
| 2143 | 2182 |
| 2144 EXPECT_SCOPED(AdvanceFrame()); // Run posted BeginFrame. | 2183 EXPECT_SCOPED(AdvanceFrame()); // Run posted BeginFrame. |
| 2145 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 1); | 2184 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 1); |
| 2146 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); | 2185 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); |
| 2147 client_->Reset(); | 2186 client_->Reset(); |
| 2148 | 2187 |
| 2149 // Take us out of a swap throttled state. | 2188 // Take us out of a swap throttled state. |
| 2150 scheduler_->DidSwapBuffersComplete(); | 2189 scheduler_->DidReceiveCompositorFrameAck(); |
| 2151 EXPECT_SINGLE_ACTION("ScheduledActionSendBeginMainFrame", client_); | 2190 EXPECT_SINGLE_ACTION("ScheduledActionSendBeginMainFrame", client_); |
| 2152 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); | 2191 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); |
| 2153 client_->Reset(); | 2192 client_->Reset(); |
| 2154 | 2193 |
| 2155 // The deadline is set to the regular deadline. | 2194 // The deadline is set to the regular deadline. |
| 2156 before_deadline = now_src()->NowTicks(); | 2195 before_deadline = now_src()->NowTicks(); |
| 2157 task_runner().RunTasksWhile(client_->InsideBeginImplFrame(true)); | 2196 task_runner().RunTasksWhile(client_->InsideBeginImplFrame(true)); |
| 2158 after_deadline = now_src()->NowTicks(); | 2197 after_deadline = now_src()->NowTicks(); |
| 2159 // We can't do an equality comparison here because the scheduler uses a fudge | 2198 // We can't do an equality comparison here because the scheduler uses a fudge |
| 2160 // factor that's an internal implementation detail. | 2199 // factor that's an internal implementation detail. |
| 2161 EXPECT_GT(after_deadline, before_deadline); | 2200 EXPECT_GT(after_deadline, before_deadline); |
| 2162 EXPECT_LT(after_deadline, | 2201 EXPECT_LT(after_deadline, |
| 2163 before_deadline + BeginFrameArgs::DefaultInterval()); | 2202 before_deadline + BeginFrameArgs::DefaultInterval()); |
| 2164 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); | 2203 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); |
| 2165 client_->Reset(); | 2204 client_->Reset(); |
| 2166 } | 2205 } |
| 2167 | 2206 |
| 2168 TEST_F(SchedulerTest, SyntheticBeginFrames_SwapThrottled) { | 2207 TEST_F(SchedulerTest, SyntheticBeginFrames_SubmitThrottled) { |
| 2169 BeginFramesNotFromClient_SwapThrottled(THROTTLED_BFS); | 2208 BeginFramesNotFromClient_SubmitThrottled(THROTTLED_BFS); |
| 2170 } | 2209 } |
| 2171 | 2210 |
| 2172 TEST_F(SchedulerTest, UnthrottledBeginFrames_SwapThrottled) { | 2211 TEST_F(SchedulerTest, UnthrottledBeginFrames_SubmitThrottled) { |
| 2173 BeginFramesNotFromClient_SwapThrottled(UNTHROTTLED_BFS); | 2212 BeginFramesNotFromClient_SubmitThrottled(UNTHROTTLED_BFS); |
| 2174 } | 2213 } |
| 2175 | 2214 |
| 2176 TEST_F(SchedulerTest, | 2215 TEST_F(SchedulerTest, |
| 2177 DidLoseCompositorFrameSinkAfterCompositorFrameSinkIsInitialized) { | 2216 DidLoseCompositorFrameSinkAfterCompositorFrameSinkIsInitialized) { |
| 2178 SetUpSchedulerWithNoCompositorFrameSink(EXTERNAL_BFS); | 2217 SetUpSchedulerWithNoCompositorFrameSink(EXTERNAL_BFS); |
| 2179 | 2218 |
| 2180 scheduler_->SetVisible(true); | 2219 scheduler_->SetVisible(true); |
| 2181 scheduler_->SetCanDraw(true); | 2220 scheduler_->SetCanDraw(true); |
| 2182 | 2221 |
| 2183 EXPECT_SINGLE_ACTION("ScheduledActionBeginCompositorFrameSinkCreation", | 2222 EXPECT_SINGLE_ACTION("ScheduledActionBeginCompositorFrameSinkCreation", |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2387 scheduler_->NotifyBeginMainFrameStarted(base::TimeTicks()); | 2426 scheduler_->NotifyBeginMainFrameStarted(base::TimeTicks()); |
| 2388 scheduler_->NotifyReadyToCommit(); | 2427 scheduler_->NotifyReadyToCommit(); |
| 2389 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_); | 2428 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_); |
| 2390 | 2429 |
| 2391 client_->Reset(); | 2430 client_->Reset(); |
| 2392 scheduler_->NotifyReadyToActivate(); | 2431 scheduler_->NotifyReadyToActivate(); |
| 2393 EXPECT_SINGLE_ACTION("ScheduledActionActivateSyncTree", client_); | 2432 EXPECT_SINGLE_ACTION("ScheduledActionActivateSyncTree", client_); |
| 2394 | 2433 |
| 2395 client_->Reset(); | 2434 client_->Reset(); |
| 2396 task_runner().RunTasksWhile(client_->InsideBeginImplFrame(true)); | 2435 task_runner().RunTasksWhile(client_->InsideBeginImplFrame(true)); |
| 2397 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 0, 1); | 2436 EXPECT_ACTION("ScheduledActionSubmitCompositorFrameIfPossible", client_, 0, |
| 2437 1); |
| 2398 | 2438 |
| 2399 // Idle time between BeginFrames. | 2439 // Idle time between BeginFrames. |
| 2400 client_->Reset(); | 2440 client_->Reset(); |
| 2401 scheduler_->DidLoseCompositorFrameSink(); | 2441 scheduler_->DidLoseCompositorFrameSink(); |
| 2402 EXPECT_ACTION("ScheduledActionBeginCompositorFrameSinkCreation", client_, 0, | 2442 EXPECT_ACTION("ScheduledActionBeginCompositorFrameSinkCreation", client_, 0, |
| 2403 3); | 2443 3); |
| 2404 EXPECT_ACTION("RemoveObserver(this)", client_, 1, 3); | 2444 EXPECT_ACTION("RemoveObserver(this)", client_, 1, 3); |
| 2405 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 2, 3); | 2445 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 2, 3); |
| 2406 } | 2446 } |
| 2407 | 2447 |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2469 scheduler_->SetNeedsRedraw(); | 2509 scheduler_->SetNeedsRedraw(); |
| 2470 EXPECT_SINGLE_ACTION("AddObserver(this)", client_); | 2510 EXPECT_SINGLE_ACTION("AddObserver(this)", client_); |
| 2471 client_->Reset(); | 2511 client_->Reset(); |
| 2472 | 2512 |
| 2473 EXPECT_SCOPED(AdvanceFrame()); | 2513 EXPECT_SCOPED(AdvanceFrame()); |
| 2474 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 1); | 2514 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 1); |
| 2475 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); | 2515 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); |
| 2476 EXPECT_TRUE(scheduler_->begin_frames_expected()); | 2516 EXPECT_TRUE(scheduler_->begin_frames_expected()); |
| 2477 client_->Reset(); | 2517 client_->Reset(); |
| 2478 task_runner().RunPendingTasks(); // Run posted deadline. | 2518 task_runner().RunPendingTasks(); // Run posted deadline. |
| 2479 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 0, 1); | 2519 EXPECT_ACTION("ScheduledActionSubmitCompositorFrameIfPossible", client_, 0, |
| 2520 1); |
| 2480 scheduler_->SetNeedsRedraw(); | 2521 scheduler_->SetNeedsRedraw(); |
| 2481 | 2522 |
| 2482 // Switch to an unthrottled frame source. | 2523 // Switch to an unthrottled frame source. |
| 2483 scheduler_->SetBeginFrameSource(unthrottled_frame_source_.get()); | 2524 scheduler_->SetBeginFrameSource(unthrottled_frame_source_.get()); |
| 2484 client_->Reset(); | 2525 client_->Reset(); |
| 2485 | 2526 |
| 2486 // Unthrottled frame source will immediately begin a new frame. | 2527 // Unthrottled frame source will immediately begin a new frame. |
| 2487 task_runner().RunPendingTasks(); // Run posted BeginFrame. | 2528 task_runner().RunPendingTasks(); // Run posted BeginFrame. |
| 2488 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 1); | 2529 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 1); |
| 2489 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); | 2530 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); |
| 2490 client_->Reset(); | 2531 client_->Reset(); |
| 2491 | 2532 |
| 2492 // If we don't swap on the deadline, we wait for the next BeginFrame. | 2533 // If we don't swap on the deadline, we wait for the next BeginFrame. |
| 2493 task_runner().RunPendingTasks(); // Run posted deadline. | 2534 task_runner().RunPendingTasks(); // Run posted deadline. |
| 2494 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 0, 1); | 2535 EXPECT_ACTION("ScheduledActionSubmitCompositorFrameIfPossible", client_, 0, |
| 2536 1); |
| 2495 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); | 2537 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); |
| 2496 client_->Reset(); | 2538 client_->Reset(); |
| 2497 } | 2539 } |
| 2498 | 2540 |
| 2499 // Tests to ensure frame sources can be successfully changed while a frame | 2541 // Tests to ensure frame sources can be successfully changed while a frame |
| 2500 // deadline is pending. | 2542 // deadline is pending. |
| 2501 TEST_F(SchedulerTest, SwitchFrameSourceToUnthrottledBeforeDeadline) { | 2543 TEST_F(SchedulerTest, SwitchFrameSourceToUnthrottledBeforeDeadline) { |
| 2502 SetUpScheduler(EXTERNAL_BFS); | 2544 SetUpScheduler(EXTERNAL_BFS); |
| 2503 | 2545 |
| 2504 // SetNeedsRedraw should begin the frame on the next BeginImplFrame. | 2546 // SetNeedsRedraw should begin the frame on the next BeginImplFrame. |
| 2505 scheduler_->SetNeedsRedraw(); | 2547 scheduler_->SetNeedsRedraw(); |
| 2506 EXPECT_SINGLE_ACTION("AddObserver(this)", client_); | 2548 EXPECT_SINGLE_ACTION("AddObserver(this)", client_); |
| 2507 client_->Reset(); | 2549 client_->Reset(); |
| 2508 | 2550 |
| 2509 EXPECT_SCOPED(AdvanceFrame()); | 2551 EXPECT_SCOPED(AdvanceFrame()); |
| 2510 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client_); | 2552 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client_); |
| 2511 | 2553 |
| 2512 // Switch to an unthrottled frame source before the frame deadline is hit. | 2554 // Switch to an unthrottled frame source before the frame deadline is hit. |
| 2513 scheduler_->SetBeginFrameSource(unthrottled_frame_source_.get()); | 2555 scheduler_->SetBeginFrameSource(unthrottled_frame_source_.get()); |
| 2514 client_->Reset(); | 2556 client_->Reset(); |
| 2515 | 2557 |
| 2516 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); | 2558 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); |
| 2517 EXPECT_TRUE(scheduler_->begin_frames_expected()); | 2559 EXPECT_TRUE(scheduler_->begin_frames_expected()); |
| 2518 client_->Reset(); | 2560 client_->Reset(); |
| 2519 | 2561 |
| 2520 task_runner().RunPendingTasks(); // Run posted deadline. | 2562 task_runner().RunPendingTasks(); // Run posted deadline. |
| 2521 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 0, 2); | 2563 EXPECT_ACTION("ScheduledActionSubmitCompositorFrameIfPossible", client_, 0, |
| 2564 2); |
| 2522 // Unthrottled frame source will immediately begin a new frame. | 2565 // Unthrottled frame source will immediately begin a new frame. |
| 2523 EXPECT_ACTION("WillBeginImplFrame", client_, 1, 2); | 2566 EXPECT_ACTION("WillBeginImplFrame", client_, 1, 2); |
| 2524 scheduler_->SetNeedsRedraw(); | 2567 scheduler_->SetNeedsRedraw(); |
| 2525 client_->Reset(); | 2568 client_->Reset(); |
| 2526 | 2569 |
| 2527 task_runner().RunPendingTasks(); // Run posted deadline. | 2570 task_runner().RunPendingTasks(); // Run posted deadline. |
| 2528 EXPECT_SINGLE_ACTION("ScheduledActionDrawAndSwapIfPossible", client_); | 2571 EXPECT_SINGLE_ACTION("ScheduledActionSubmitCompositorFrameIfPossible", |
| 2572 client_); |
| 2529 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); | 2573 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); |
| 2530 client_->Reset(); | 2574 client_->Reset(); |
| 2531 } | 2575 } |
| 2532 | 2576 |
| 2533 // Tests to ensure that the active frame source can successfully be changed from | 2577 // Tests to ensure that the active frame source can successfully be changed from |
| 2534 // unthrottled to throttled. | 2578 // unthrottled to throttled. |
| 2535 TEST_F(SchedulerTest, SwitchFrameSourceToThrottled) { | 2579 TEST_F(SchedulerTest, SwitchFrameSourceToThrottled) { |
| 2536 SetUpScheduler(UNTHROTTLED_BFS); | 2580 SetUpScheduler(UNTHROTTLED_BFS); |
| 2537 | 2581 |
| 2538 scheduler_->SetNeedsRedraw(); | 2582 scheduler_->SetNeedsRedraw(); |
| 2539 EXPECT_NO_ACTION(client_); | 2583 EXPECT_NO_ACTION(client_); |
| 2540 client_->Reset(); | 2584 client_->Reset(); |
| 2541 | 2585 |
| 2542 task_runner().RunPendingTasks(); // Run posted BeginFrame. | 2586 task_runner().RunPendingTasks(); // Run posted BeginFrame. |
| 2543 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 1); | 2587 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 1); |
| 2544 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); | 2588 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); |
| 2545 client_->Reset(); | 2589 client_->Reset(); |
| 2546 | 2590 |
| 2547 task_runner().RunPendingTasks(); // Run posted deadline. | 2591 task_runner().RunPendingTasks(); // Run posted deadline. |
| 2548 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 0, 1); | 2592 EXPECT_ACTION("ScheduledActionSubmitCompositorFrameIfPossible", client_, 0, |
| 2593 1); |
| 2549 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); | 2594 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); |
| 2550 client_->Reset(); | 2595 client_->Reset(); |
| 2551 | 2596 |
| 2552 // Switch to a throttled frame source. | 2597 // Switch to a throttled frame source. |
| 2553 scheduler_->SetBeginFrameSource(fake_external_begin_frame_source_.get()); | 2598 scheduler_->SetBeginFrameSource(fake_external_begin_frame_source_.get()); |
| 2554 client_->Reset(); | 2599 client_->Reset(); |
| 2555 | 2600 |
| 2556 // SetNeedsRedraw should begin the frame on the next BeginImplFrame. | 2601 // SetNeedsRedraw should begin the frame on the next BeginImplFrame. |
| 2557 scheduler_->SetNeedsRedraw(); | 2602 scheduler_->SetNeedsRedraw(); |
| 2558 task_runner().RunPendingTasks(); | 2603 task_runner().RunPendingTasks(); |
| 2559 EXPECT_NO_ACTION(client_); | 2604 EXPECT_NO_ACTION(client_); |
| 2560 client_->Reset(); | 2605 client_->Reset(); |
| 2561 | 2606 |
| 2562 EXPECT_SCOPED(AdvanceFrame()); | 2607 EXPECT_SCOPED(AdvanceFrame()); |
| 2563 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 1); | 2608 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 1); |
| 2564 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); | 2609 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); |
| 2565 EXPECT_TRUE(scheduler_->begin_frames_expected()); | 2610 EXPECT_TRUE(scheduler_->begin_frames_expected()); |
| 2566 client_->Reset(); | 2611 client_->Reset(); |
| 2567 task_runner().RunPendingTasks(); // Run posted deadline. | 2612 task_runner().RunPendingTasks(); // Run posted deadline. |
| 2568 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 0, 1); | 2613 EXPECT_ACTION("ScheduledActionSubmitCompositorFrameIfPossible", client_, 0, |
| 2614 1); |
| 2569 } | 2615 } |
| 2570 | 2616 |
| 2571 TEST_F(SchedulerTest, SwitchFrameSourceToNullInsideDeadline) { | 2617 TEST_F(SchedulerTest, SwitchFrameSourceToNullInsideDeadline) { |
| 2572 SetUpScheduler(EXTERNAL_BFS); | 2618 SetUpScheduler(EXTERNAL_BFS); |
| 2573 | 2619 |
| 2574 scheduler_->SetNeedsRedraw(); | 2620 scheduler_->SetNeedsRedraw(); |
| 2575 EXPECT_SINGLE_ACTION("AddObserver(this)", client_); | 2621 EXPECT_SINGLE_ACTION("AddObserver(this)", client_); |
| 2576 client_->Reset(); | 2622 client_->Reset(); |
| 2577 | 2623 |
| 2578 EXPECT_SCOPED(AdvanceFrame()); | 2624 EXPECT_SCOPED(AdvanceFrame()); |
| 2579 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client_); | 2625 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client_); |
| 2580 client_->Reset(); | 2626 client_->Reset(); |
| 2581 | 2627 |
| 2582 // Switch to a null frame source. | 2628 // Switch to a null frame source. |
| 2583 scheduler_->SetBeginFrameSource(nullptr); | 2629 scheduler_->SetBeginFrameSource(nullptr); |
| 2584 EXPECT_SINGLE_ACTION("RemoveObserver(this)", client_); | 2630 EXPECT_SINGLE_ACTION("RemoveObserver(this)", client_); |
| 2585 client_->Reset(); | 2631 client_->Reset(); |
| 2586 | 2632 |
| 2587 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); | 2633 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); |
| 2588 task_runner().RunPendingTasks(); // Run posted deadline. | 2634 task_runner().RunPendingTasks(); // Run posted deadline. |
| 2589 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 0, 1); | 2635 EXPECT_ACTION("ScheduledActionSubmitCompositorFrameIfPossible", client_, 0, |
| 2636 1); |
| 2590 EXPECT_FALSE(scheduler_->begin_frames_expected()); | 2637 EXPECT_FALSE(scheduler_->begin_frames_expected()); |
| 2591 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); | 2638 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); |
| 2592 client_->Reset(); | 2639 client_->Reset(); |
| 2593 | 2640 |
| 2594 // AdvanceFrame helper can't be used here because there's no deadline posted. | 2641 // AdvanceFrame helper can't be used here because there's no deadline posted. |
| 2595 scheduler_->SetNeedsRedraw(); | 2642 scheduler_->SetNeedsRedraw(); |
| 2596 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); | 2643 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); |
| 2597 EXPECT_NO_ACTION(client_); | 2644 EXPECT_NO_ACTION(client_); |
| 2598 client_->Reset(); | 2645 client_->Reset(); |
| 2599 | 2646 |
| 2600 scheduler_->SetNeedsBeginMainFrame(); | 2647 scheduler_->SetNeedsBeginMainFrame(); |
| 2601 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); | 2648 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); |
| 2602 EXPECT_NO_ACTION(client_); | 2649 EXPECT_NO_ACTION(client_); |
| 2603 client_->Reset(); | 2650 client_->Reset(); |
| 2604 | 2651 |
| 2605 // Switch back to the same source, make sure frames continue to be produced. | 2652 // Switch back to the same source, make sure frames continue to be produced. |
| 2606 scheduler_->SetBeginFrameSource(fake_external_begin_frame_source_.get()); | 2653 scheduler_->SetBeginFrameSource(fake_external_begin_frame_source_.get()); |
| 2607 EXPECT_SINGLE_ACTION("AddObserver(this)", client_); | 2654 EXPECT_SINGLE_ACTION("AddObserver(this)", client_); |
| 2608 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); | 2655 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); |
| 2609 client_->Reset(); | 2656 client_->Reset(); |
| 2610 | 2657 |
| 2611 EXPECT_SCOPED(AdvanceFrame()); | 2658 EXPECT_SCOPED(AdvanceFrame()); |
| 2612 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); | 2659 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
| 2613 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); | 2660 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); |
| 2614 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); | 2661 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); |
| 2615 client_->Reset(); | 2662 client_->Reset(); |
| 2616 | 2663 |
| 2617 task_runner().RunPendingTasks(); | 2664 task_runner().RunPendingTasks(); |
| 2618 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 0, 1); | 2665 EXPECT_ACTION("ScheduledActionSubmitCompositorFrameIfPossible", client_, 0, |
| 2666 1); |
| 2619 } | 2667 } |
| 2620 | 2668 |
| 2621 // This test maskes sure that switching a frame source when not observing | 2669 // This test maskes sure that switching a frame source when not observing |
| 2622 // such as when not visible also works. | 2670 // such as when not visible also works. |
| 2623 TEST_F(SchedulerTest, SwitchFrameSourceWhenNotObserving) { | 2671 TEST_F(SchedulerTest, SwitchFrameSourceWhenNotObserving) { |
| 2624 SetUpScheduler(EXTERNAL_BFS); | 2672 SetUpScheduler(EXTERNAL_BFS); |
| 2625 | 2673 |
| 2626 // SetNeedsBeginMainFrame should begin the frame on the next BeginImplFrame. | 2674 // SetNeedsBeginMainFrame should begin the frame on the next BeginImplFrame. |
| 2627 scheduler_->SetNeedsBeginMainFrame(); | 2675 scheduler_->SetNeedsBeginMainFrame(); |
| 2628 EXPECT_SINGLE_ACTION("AddObserver(this)", client_); | 2676 EXPECT_SINGLE_ACTION("AddObserver(this)", client_); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2685 // Trigger a frame draw. | 2733 // Trigger a frame draw. |
| 2686 EXPECT_SCOPED(AdvanceFrame()); | 2734 EXPECT_SCOPED(AdvanceFrame()); |
| 2687 scheduler_->NotifyBeginMainFrameStarted(base::TimeTicks()); | 2735 scheduler_->NotifyBeginMainFrameStarted(base::TimeTicks()); |
| 2688 scheduler_->NotifyReadyToCommit(); | 2736 scheduler_->NotifyReadyToCommit(); |
| 2689 scheduler_->NotifyReadyToActivate(); | 2737 scheduler_->NotifyReadyToActivate(); |
| 2690 task_runner().RunPendingTasks(); | 2738 task_runner().RunPendingTasks(); |
| 2691 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 5); | 2739 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 5); |
| 2692 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 5); | 2740 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 5); |
| 2693 EXPECT_ACTION("ScheduledActionCommit", client_, 2, 5); | 2741 EXPECT_ACTION("ScheduledActionCommit", client_, 2, 5); |
| 2694 EXPECT_ACTION("ScheduledActionActivateSyncTree", client_, 3, 5); | 2742 EXPECT_ACTION("ScheduledActionActivateSyncTree", client_, 3, 5); |
| 2695 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 4, 5); | 2743 EXPECT_ACTION("ScheduledActionSubmitCompositorFrameIfPossible", client_, 4, |
| 2744 5); |
| 2696 client_->Reset(); | 2745 client_->Reset(); |
| 2697 | 2746 |
| 2698 // The following BeginImplFrame deadline should SetNeedsBeginFrame(false) | 2747 // The following BeginImplFrame deadline should SetNeedsBeginFrame(false) |
| 2699 // and send a SendBeginMainFrameNotExpectedSoon. | 2748 // and send a SendBeginMainFrameNotExpectedSoon. |
| 2700 EXPECT_SCOPED(AdvanceFrame()); | 2749 EXPECT_SCOPED(AdvanceFrame()); |
| 2701 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client_); | 2750 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client_); |
| 2702 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); | 2751 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); |
| 2703 client_->Reset(); | 2752 client_->Reset(); |
| 2704 | 2753 |
| 2705 task_runner().RunPendingTasks(); // Run posted deadline. | 2754 task_runner().RunPendingTasks(); // Run posted deadline. |
| (...skipping 19 matching lines...) Expand all Loading... |
| 2725 AdvanceFrame(); | 2774 AdvanceFrame(); |
| 2726 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); | 2775 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
| 2727 EXPECT_ACTION("ScheduledActionInvalidateCompositorFrameSink", client_, 1, 2); | 2776 EXPECT_ACTION("ScheduledActionInvalidateCompositorFrameSink", client_, 1, 2); |
| 2728 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); | 2777 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); |
| 2729 client_->Reset(); | 2778 client_->Reset(); |
| 2730 | 2779 |
| 2731 // Android onDraw. This doesn't consume the single begin frame request. | 2780 // Android onDraw. This doesn't consume the single begin frame request. |
| 2732 scheduler_->SetNeedsRedraw(); | 2781 scheduler_->SetNeedsRedraw(); |
| 2733 bool resourceless_software_draw = false; | 2782 bool resourceless_software_draw = false; |
| 2734 scheduler_->OnDrawForCompositorFrameSink(resourceless_software_draw); | 2783 scheduler_->OnDrawForCompositorFrameSink(resourceless_software_draw); |
| 2735 EXPECT_SINGLE_ACTION("ScheduledActionDrawAndSwapIfPossible", client_); | 2784 EXPECT_SINGLE_ACTION("ScheduledActionSubmitCompositorFrameIfPossible", |
| 2785 client_); |
| 2736 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); | 2786 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); |
| 2737 client_->Reset(); | 2787 client_->Reset(); |
| 2738 | 2788 |
| 2739 // The animation inside of WillBeginImplFrame changes stuff on the screen, but | 2789 // The animation inside of WillBeginImplFrame changes stuff on the screen, but |
| 2740 // ends here, so does not cause another frame to happen. | 2790 // ends here, so does not cause another frame to happen. |
| 2741 client_->SetWillBeginImplFrameCausesRedraw(true); | 2791 client_->SetWillBeginImplFrameCausesRedraw(true); |
| 2742 | 2792 |
| 2743 // Next vsync. | 2793 // Next vsync. |
| 2744 AdvanceFrame(); | 2794 AdvanceFrame(); |
| 2745 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); | 2795 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
| 2746 EXPECT_ACTION("ScheduledActionInvalidateCompositorFrameSink", client_, 1, 2); | 2796 EXPECT_ACTION("ScheduledActionInvalidateCompositorFrameSink", client_, 1, 2); |
| 2747 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); | 2797 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); |
| 2748 client_->Reset(); | 2798 client_->Reset(); |
| 2749 | 2799 |
| 2750 // Android onDraw. | 2800 // Android onDraw. |
| 2751 scheduler_->SetNeedsRedraw(); | 2801 scheduler_->SetNeedsRedraw(); |
| 2752 scheduler_->OnDrawForCompositorFrameSink(resourceless_software_draw); | 2802 scheduler_->OnDrawForCompositorFrameSink(resourceless_software_draw); |
| 2753 EXPECT_SINGLE_ACTION("ScheduledActionDrawAndSwapIfPossible", client_); | 2803 EXPECT_SINGLE_ACTION("ScheduledActionSubmitCompositorFrameIfPossible", |
| 2804 client_); |
| 2754 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); | 2805 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); |
| 2755 client_->Reset(); | 2806 client_->Reset(); |
| 2756 | 2807 |
| 2757 // Idle on next vsync, as the animation has completed. | 2808 // Idle on next vsync, as the animation has completed. |
| 2758 AdvanceFrame(); | 2809 AdvanceFrame(); |
| 2759 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 3); | 2810 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 3); |
| 2760 EXPECT_ACTION("RemoveObserver(this)", client_, 1, 3); | 2811 EXPECT_ACTION("RemoveObserver(this)", client_, 1, 3); |
| 2761 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 2, 3); | 2812 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 2, 3); |
| 2762 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); | 2813 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); |
| 2763 client_->Reset(); | 2814 client_->Reset(); |
| 2764 } | 2815 } |
| 2765 | 2816 |
| 2766 TEST_F(SchedulerTest, SynchronousCompositorOnDrawDuringIdle) { | 2817 TEST_F(SchedulerTest, SynchronousCompositorOnDrawDuringIdle) { |
| 2767 scheduler_settings_.using_synchronous_renderer_compositor = true; | 2818 scheduler_settings_.using_synchronous_renderer_compositor = true; |
| 2768 SetUpScheduler(EXTERNAL_BFS); | 2819 SetUpScheduler(EXTERNAL_BFS); |
| 2769 | 2820 |
| 2770 scheduler_->SetNeedsRedraw(); | 2821 scheduler_->SetNeedsRedraw(); |
| 2771 bool resourceless_software_draw = false; | 2822 bool resourceless_software_draw = false; |
| 2772 scheduler_->OnDrawForCompositorFrameSink(resourceless_software_draw); | 2823 scheduler_->OnDrawForCompositorFrameSink(resourceless_software_draw); |
| 2773 EXPECT_ACTION("AddObserver(this)", client_, 0, 2); | 2824 EXPECT_ACTION("AddObserver(this)", client_, 0, 2); |
| 2774 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 1, 2); | 2825 EXPECT_ACTION("ScheduledActionSubmitCompositorFrameIfPossible", client_, 1, |
| 2826 2); |
| 2775 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); | 2827 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); |
| 2776 client_->Reset(); | 2828 client_->Reset(); |
| 2777 | 2829 |
| 2778 // Idle on next vsync. | 2830 // Idle on next vsync. |
| 2779 AdvanceFrame(); | 2831 AdvanceFrame(); |
| 2780 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 3); | 2832 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 3); |
| 2781 EXPECT_ACTION("RemoveObserver(this)", client_, 1, 3); | 2833 EXPECT_ACTION("RemoveObserver(this)", client_, 1, 3); |
| 2782 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 2, 3); | 2834 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 2, 3); |
| 2783 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); | 2835 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); |
| 2784 client_->Reset(); | 2836 client_->Reset(); |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2857 AdvanceFrame(); | 2909 AdvanceFrame(); |
| 2858 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); | 2910 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
| 2859 EXPECT_ACTION("ScheduledActionInvalidateCompositorFrameSink", client_, 1, 2); | 2911 EXPECT_ACTION("ScheduledActionInvalidateCompositorFrameSink", client_, 1, 2); |
| 2860 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); | 2912 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); |
| 2861 client_->Reset(); | 2913 client_->Reset(); |
| 2862 | 2914 |
| 2863 // Android onDraw. | 2915 // Android onDraw. |
| 2864 scheduler_->SetNeedsRedraw(); | 2916 scheduler_->SetNeedsRedraw(); |
| 2865 bool resourceless_software_draw = false; | 2917 bool resourceless_software_draw = false; |
| 2866 scheduler_->OnDrawForCompositorFrameSink(resourceless_software_draw); | 2918 scheduler_->OnDrawForCompositorFrameSink(resourceless_software_draw); |
| 2867 EXPECT_SINGLE_ACTION("ScheduledActionDrawAndSwapIfPossible", client_); | 2919 EXPECT_SINGLE_ACTION("ScheduledActionSubmitCompositorFrameIfPossible", |
| 2920 client_); |
| 2868 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); | 2921 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); |
| 2869 client_->Reset(); | 2922 client_->Reset(); |
| 2870 | 2923 |
| 2871 // Idle on next vsync. | 2924 // Idle on next vsync. |
| 2872 AdvanceFrame(); | 2925 AdvanceFrame(); |
| 2873 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 3); | 2926 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 3); |
| 2874 EXPECT_ACTION("RemoveObserver(this)", client_, 1, 3); | 2927 EXPECT_ACTION("RemoveObserver(this)", client_, 1, 3); |
| 2875 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 2, 3); | 2928 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 2, 3); |
| 2876 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); | 2929 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); |
| 2877 client_->Reset(); | 2930 client_->Reset(); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2920 scheduler_->NotifyReadyToCommit(); | 2973 scheduler_->NotifyReadyToCommit(); |
| 2921 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_); | 2974 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_); |
| 2922 client_->Reset(); | 2975 client_->Reset(); |
| 2923 } | 2976 } |
| 2924 | 2977 |
| 2925 class SchedulerClientSetNeedsPrepareTilesOnDraw : public FakeSchedulerClient { | 2978 class SchedulerClientSetNeedsPrepareTilesOnDraw : public FakeSchedulerClient { |
| 2926 public: | 2979 public: |
| 2927 SchedulerClientSetNeedsPrepareTilesOnDraw() : FakeSchedulerClient() {} | 2980 SchedulerClientSetNeedsPrepareTilesOnDraw() : FakeSchedulerClient() {} |
| 2928 | 2981 |
| 2929 protected: | 2982 protected: |
| 2930 DrawResult ScheduledActionDrawAndSwapIfPossible() override { | 2983 DrawResult ScheduledActionSubmitCompositorFrameIfPossible() override { |
| 2931 scheduler_->SetNeedsPrepareTiles(); | 2984 scheduler_->SetNeedsPrepareTiles(); |
| 2932 return FakeSchedulerClient::ScheduledActionDrawAndSwapIfPossible(); | 2985 return FakeSchedulerClient:: |
| 2986 ScheduledActionSubmitCompositorFrameIfPossible(); |
| 2933 } | 2987 } |
| 2934 }; | 2988 }; |
| 2935 | 2989 |
| 2936 TEST_F(SchedulerTest, SynchronousCompositorPrepareTilesOnDraw) { | 2990 TEST_F(SchedulerTest, SynchronousCompositorPrepareTilesOnDraw) { |
| 2937 scheduler_settings_.using_synchronous_renderer_compositor = true; | 2991 scheduler_settings_.using_synchronous_renderer_compositor = true; |
| 2938 | 2992 |
| 2939 std::unique_ptr<FakeSchedulerClient> client = | 2993 std::unique_ptr<FakeSchedulerClient> client = |
| 2940 base::WrapUnique(new SchedulerClientSetNeedsPrepareTilesOnDraw); | 2994 base::WrapUnique(new SchedulerClientSetNeedsPrepareTilesOnDraw); |
| 2941 SetUpScheduler(EXTERNAL_BFS, std::move(client)); | 2995 SetUpScheduler(EXTERNAL_BFS, std::move(client)); |
| 2942 | 2996 |
| 2943 scheduler_->SetNeedsRedraw(); | 2997 scheduler_->SetNeedsRedraw(); |
| 2944 EXPECT_SINGLE_ACTION("AddObserver(this)", client_); | 2998 EXPECT_SINGLE_ACTION("AddObserver(this)", client_); |
| 2945 client_->Reset(); | 2999 client_->Reset(); |
| 2946 | 3000 |
| 2947 // Next vsync. | 3001 // Next vsync. |
| 2948 EXPECT_SCOPED(AdvanceFrame()); | 3002 EXPECT_SCOPED(AdvanceFrame()); |
| 2949 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); | 3003 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
| 2950 EXPECT_ACTION("ScheduledActionInvalidateCompositorFrameSink", client_, 1, 2); | 3004 EXPECT_ACTION("ScheduledActionInvalidateCompositorFrameSink", client_, 1, 2); |
| 2951 client_->Reset(); | 3005 client_->Reset(); |
| 2952 | 3006 |
| 2953 // Android onDraw. | 3007 // Android onDraw. |
| 2954 scheduler_->SetNeedsRedraw(); | 3008 scheduler_->SetNeedsRedraw(); |
| 2955 bool resourceless_software_draw = false; | 3009 bool resourceless_software_draw = false; |
| 2956 scheduler_->OnDrawForCompositorFrameSink(resourceless_software_draw); | 3010 scheduler_->OnDrawForCompositorFrameSink(resourceless_software_draw); |
| 2957 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 0, 2); | 3011 EXPECT_ACTION("ScheduledActionSubmitCompositorFrameIfPossible", client_, 0, |
| 3012 2); |
| 2958 EXPECT_ACTION("ScheduledActionPrepareTiles", client_, 1, 2); | 3013 EXPECT_ACTION("ScheduledActionPrepareTiles", client_, 1, 2); |
| 2959 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); | 3014 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); |
| 2960 EXPECT_FALSE(scheduler_->PrepareTilesPending()); | 3015 EXPECT_FALSE(scheduler_->PrepareTilesPending()); |
| 2961 client_->Reset(); | 3016 client_->Reset(); |
| 2962 | 3017 |
| 2963 // Android onDraw. | 3018 // Android onDraw. |
| 2964 scheduler_->SetNeedsRedraw(); | 3019 scheduler_->SetNeedsRedraw(); |
| 2965 scheduler_->OnDrawForCompositorFrameSink(resourceless_software_draw); | 3020 scheduler_->OnDrawForCompositorFrameSink(resourceless_software_draw); |
| 2966 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 0, 2); | 3021 EXPECT_ACTION("ScheduledActionSubmitCompositorFrameIfPossible", client_, 0, |
| 3022 2); |
| 2967 EXPECT_ACTION("ScheduledActionPrepareTiles", client_, 1, 2); | 3023 EXPECT_ACTION("ScheduledActionPrepareTiles", client_, 1, 2); |
| 2968 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); | 3024 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); |
| 2969 EXPECT_FALSE(scheduler_->PrepareTilesPending()); | 3025 EXPECT_FALSE(scheduler_->PrepareTilesPending()); |
| 2970 client_->Reset(); | 3026 client_->Reset(); |
| 2971 | 3027 |
| 2972 // Next vsync. | 3028 // Next vsync. |
| 2973 EXPECT_SCOPED(AdvanceFrame()); | 3029 EXPECT_SCOPED(AdvanceFrame()); |
| 2974 EXPECT_FALSE(scheduler_->PrepareTilesPending()); | 3030 EXPECT_FALSE(scheduler_->PrepareTilesPending()); |
| 2975 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 3); | 3031 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 3); |
| 2976 EXPECT_ACTION("RemoveObserver(this)", client_, 1, 3); | 3032 EXPECT_ACTION("RemoveObserver(this)", client_, 1, 3); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 2990 // Next vsync. | 3046 // Next vsync. |
| 2991 EXPECT_SCOPED(AdvanceFrame()); | 3047 EXPECT_SCOPED(AdvanceFrame()); |
| 2992 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); | 3048 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
| 2993 EXPECT_ACTION("ScheduledActionInvalidateCompositorFrameSink", client_, 1, 2); | 3049 EXPECT_ACTION("ScheduledActionInvalidateCompositorFrameSink", client_, 1, 2); |
| 2994 client_->Reset(); | 3050 client_->Reset(); |
| 2995 | 3051 |
| 2996 // Android onDraw. | 3052 // Android onDraw. |
| 2997 scheduler_->SetNeedsRedraw(); | 3053 scheduler_->SetNeedsRedraw(); |
| 2998 bool resourceless_software_draw = false; | 3054 bool resourceless_software_draw = false; |
| 2999 scheduler_->OnDrawForCompositorFrameSink(resourceless_software_draw); | 3055 scheduler_->OnDrawForCompositorFrameSink(resourceless_software_draw); |
| 3000 EXPECT_SINGLE_ACTION("ScheduledActionDrawAndSwapIfPossible", client_); | 3056 EXPECT_SINGLE_ACTION("ScheduledActionSubmitCompositorFrameIfPossible", |
| 3057 client_); |
| 3001 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); | 3058 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); |
| 3002 EXPECT_FALSE(scheduler_->PrepareTilesPending()); | 3059 EXPECT_FALSE(scheduler_->PrepareTilesPending()); |
| 3003 client_->Reset(); | 3060 client_->Reset(); |
| 3004 | 3061 |
| 3005 // Simulate SetNeedsBeginMainFrame due to input event. | 3062 // Simulate SetNeedsBeginMainFrame due to input event. |
| 3006 scheduler_->SetNeedsBeginMainFrame(); | 3063 scheduler_->SetNeedsBeginMainFrame(); |
| 3007 EXPECT_SINGLE_ACTION("ScheduledActionSendBeginMainFrame", client_); | 3064 EXPECT_SINGLE_ACTION("ScheduledActionSendBeginMainFrame", client_); |
| 3008 client_->Reset(); | 3065 client_->Reset(); |
| 3009 | 3066 |
| 3010 scheduler_->NotifyBeginMainFrameStarted(base::TimeTicks()); | 3067 scheduler_->NotifyBeginMainFrameStarted(base::TimeTicks()); |
| 3011 scheduler_->NotifyReadyToCommit(); | 3068 scheduler_->NotifyReadyToCommit(); |
| 3012 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_); | 3069 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_); |
| 3013 client_->Reset(); | 3070 client_->Reset(); |
| 3014 | 3071 |
| 3015 scheduler_->NotifyReadyToActivate(); | 3072 scheduler_->NotifyReadyToActivate(); |
| 3016 EXPECT_SINGLE_ACTION("ScheduledActionActivateSyncTree", client_); | 3073 EXPECT_SINGLE_ACTION("ScheduledActionActivateSyncTree", client_); |
| 3017 client_->Reset(); | 3074 client_->Reset(); |
| 3018 | 3075 |
| 3019 // Next vsync. | 3076 // Next vsync. |
| 3020 EXPECT_SCOPED(AdvanceFrame()); | 3077 EXPECT_SCOPED(AdvanceFrame()); |
| 3021 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); | 3078 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
| 3022 EXPECT_ACTION("ScheduledActionInvalidateCompositorFrameSink", client_, 1, 2); | 3079 EXPECT_ACTION("ScheduledActionInvalidateCompositorFrameSink", client_, 1, 2); |
| 3023 client_->Reset(); | 3080 client_->Reset(); |
| 3024 | 3081 |
| 3025 // Android onDraw. | 3082 // Android onDraw. |
| 3026 scheduler_->SetNeedsRedraw(); | 3083 scheduler_->SetNeedsRedraw(); |
| 3027 scheduler_->OnDrawForCompositorFrameSink(resourceless_software_draw); | 3084 scheduler_->OnDrawForCompositorFrameSink(resourceless_software_draw); |
| 3028 EXPECT_SINGLE_ACTION("ScheduledActionDrawAndSwapIfPossible", client_); | 3085 EXPECT_SINGLE_ACTION("ScheduledActionSubmitCompositorFrameIfPossible", |
| 3086 client_); |
| 3029 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); | 3087 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); |
| 3030 EXPECT_FALSE(scheduler_->PrepareTilesPending()); | 3088 EXPECT_FALSE(scheduler_->PrepareTilesPending()); |
| 3031 client_->Reset(); | 3089 client_->Reset(); |
| 3032 | 3090 |
| 3033 // Simulate SetNeedsBeginMainFrame due to input event. | 3091 // Simulate SetNeedsBeginMainFrame due to input event. |
| 3034 scheduler_->SetNeedsBeginMainFrame(); | 3092 scheduler_->SetNeedsBeginMainFrame(); |
| 3035 EXPECT_SINGLE_ACTION("ScheduledActionSendBeginMainFrame", client_); | 3093 EXPECT_SINGLE_ACTION("ScheduledActionSendBeginMainFrame", client_); |
| 3036 client_->Reset(); | 3094 client_->Reset(); |
| 3037 } | 3095 } |
| 3038 | 3096 |
| 3039 TEST_F(SchedulerTest, SynchronousCompositorResourcelessOnDrawWhenInvisible) { | 3097 TEST_F(SchedulerTest, SynchronousCompositorResourcelessOnDrawWhenInvisible) { |
| 3040 scheduler_settings_.using_synchronous_renderer_compositor = true; | 3098 scheduler_settings_.using_synchronous_renderer_compositor = true; |
| 3041 SetUpScheduler(EXTERNAL_BFS); | 3099 SetUpScheduler(EXTERNAL_BFS); |
| 3042 | 3100 |
| 3043 scheduler_->SetVisible(false); | 3101 scheduler_->SetVisible(false); |
| 3044 | 3102 |
| 3045 scheduler_->SetNeedsRedraw(); | 3103 scheduler_->SetNeedsRedraw(); |
| 3046 bool resourceless_software_draw = true; | 3104 bool resourceless_software_draw = true; |
| 3047 scheduler_->OnDrawForCompositorFrameSink(resourceless_software_draw); | 3105 scheduler_->OnDrawForCompositorFrameSink(resourceless_software_draw); |
| 3048 // SynchronousCompositor has to draw regardless of visibility. | 3106 // SynchronousCompositor has to draw regardless of visibility. |
| 3049 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 0, 1); | 3107 EXPECT_ACTION("ScheduledActionSubmitCompositorFrameIfPossible", client_, 0, |
| 3108 1); |
| 3050 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); | 3109 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); |
| 3051 client_->Reset(); | 3110 client_->Reset(); |
| 3052 } | 3111 } |
| 3053 | 3112 |
| 3054 TEST_F(SchedulerTest, AuthoritativeVSyncInterval) { | 3113 TEST_F(SchedulerTest, AuthoritativeVSyncInterval) { |
| 3055 SetUpScheduler(THROTTLED_BFS); | 3114 SetUpScheduler(THROTTLED_BFS); |
| 3056 base::TimeDelta initial_interval = scheduler_->BeginImplFrameInterval(); | 3115 base::TimeDelta initial_interval = scheduler_->BeginImplFrameInterval(); |
| 3057 base::TimeDelta authoritative_interval = | 3116 base::TimeDelta authoritative_interval = |
| 3058 base::TimeDelta::FromMilliseconds(33); | 3117 base::TimeDelta::FromMilliseconds(33); |
| 3059 | 3118 |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3242 } | 3301 } |
| 3243 | 3302 |
| 3244 TEST_F(SchedulerTest, BeginMainFrameOnCriticalPath_AHS) { | 3303 TEST_F(SchedulerTest, BeginMainFrameOnCriticalPath_AHS) { |
| 3245 EXPECT_FALSE(BeginMainFrameOnCriticalPath( | 3304 EXPECT_FALSE(BeginMainFrameOnCriticalPath( |
| 3246 SMOOTHNESS_TAKES_PRIORITY, | 3305 SMOOTHNESS_TAKES_PRIORITY, |
| 3247 ScrollHandlerState::SCROLL_AFFECTS_SCROLL_HANDLER, kSlowDuration)); | 3306 ScrollHandlerState::SCROLL_AFFECTS_SCROLL_HANDLER, kSlowDuration)); |
| 3248 } | 3307 } |
| 3249 | 3308 |
| 3250 } // namespace | 3309 } // namespace |
| 3251 } // namespace cc | 3310 } // namespace cc |
| OLD | NEW |