Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2011 The Chromium Authors. All rights reserved. | 1 // Copyright 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "cc/scheduler/scheduler.h" | 5 #include "cc/scheduler/scheduler.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 50 namespace { | 50 namespace { |
| 51 | 51 |
| 52 base::TimeDelta kSlowDuration = base::TimeDelta::FromSeconds(1); | 52 base::TimeDelta kSlowDuration = base::TimeDelta::FromSeconds(1); |
| 53 base::TimeDelta kFastDuration = base::TimeDelta::FromMilliseconds(1); | 53 base::TimeDelta kFastDuration = base::TimeDelta::FromMilliseconds(1); |
| 54 | 54 |
| 55 class FakeSchedulerClient : public SchedulerClient, | 55 class FakeSchedulerClient : public SchedulerClient, |
| 56 public FakeExternalBeginFrameSource::Client { | 56 public FakeExternalBeginFrameSource::Client { |
| 57 public: | 57 public: |
| 58 FakeSchedulerClient() | 58 FakeSchedulerClient() |
| 59 : inside_begin_impl_frame_(false), | 59 : inside_begin_impl_frame_(false), |
| 60 automatic_swap_ack_(true), | 60 automatic_ack_(true), |
| 61 scheduler_(nullptr) { | 61 scheduler_(nullptr) { |
| 62 Reset(); | 62 Reset(); |
| 63 } | 63 } |
| 64 | 64 |
| 65 void Reset() { | 65 void Reset() { |
| 66 actions_.clear(); | 66 actions_.clear(); |
| 67 states_.clear(); | 67 states_.clear(); |
| 68 will_begin_impl_frame_causes_redraw_ = false; | 68 will_begin_impl_frame_causes_redraw_ = false; |
| 69 will_begin_impl_frame_requests_one_begin_impl_frame_ = false; | 69 will_begin_impl_frame_requests_one_begin_impl_frame_ = false; |
| 70 draw_will_happen_ = true; | 70 draw_will_happen_ = true; |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 98 } | 98 } |
| 99 void SetWillBeginImplFrameCausesRedraw(bool causes_redraw) { | 99 void SetWillBeginImplFrameCausesRedraw(bool causes_redraw) { |
| 100 will_begin_impl_frame_causes_redraw_ = causes_redraw; | 100 will_begin_impl_frame_causes_redraw_ = causes_redraw; |
| 101 } | 101 } |
| 102 void SetDrawWillHappen(bool draw_will_happen) { | 102 void SetDrawWillHappen(bool draw_will_happen) { |
| 103 draw_will_happen_ = draw_will_happen; | 103 draw_will_happen_ = draw_will_happen; |
| 104 } | 104 } |
| 105 void SetSwapWillHappenIfDrawHappens(bool swap_will_happen_if_draw_happens) { | 105 void SetSwapWillHappenIfDrawHappens(bool swap_will_happen_if_draw_happens) { |
| 106 swap_will_happen_if_draw_happens_ = swap_will_happen_if_draw_happens; | 106 swap_will_happen_if_draw_happens_ = swap_will_happen_if_draw_happens; |
| 107 } | 107 } |
| 108 void SetAutomaticSwapAck(bool automatic_swap_ack) { | 108 void SetAutomaticSubmitCompositorFrameAck(bool automatic_ack) { |
| 109 automatic_swap_ack_ = automatic_swap_ack; | 109 automatic_ack_ = automatic_ack; |
| 110 } | 110 } |
| 111 // SchedulerClient implementation. | 111 // SchedulerClient implementation. |
| 112 void WillBeginImplFrame(const BeginFrameArgs& args) override { | 112 void WillBeginImplFrame(const BeginFrameArgs& args) override { |
| 113 EXPECT_FALSE(inside_begin_impl_frame_); | 113 EXPECT_FALSE(inside_begin_impl_frame_); |
| 114 inside_begin_impl_frame_ = true; | 114 inside_begin_impl_frame_ = true; |
| 115 PushAction("WillBeginImplFrame"); | 115 PushAction("WillBeginImplFrame"); |
| 116 if (will_begin_impl_frame_requests_one_begin_impl_frame_) | 116 if (will_begin_impl_frame_requests_one_begin_impl_frame_) |
| 117 scheduler_->SetNeedsOneBeginImplFrame(); | 117 scheduler_->SetNeedsOneBeginImplFrame(); |
| 118 if (will_begin_impl_frame_causes_redraw_) | 118 if (will_begin_impl_frame_causes_redraw_) |
| 119 scheduler_->SetNeedsRedraw(); | 119 scheduler_->SetNeedsRedraw(); |
| 120 } | 120 } |
| 121 void DidFinishImplFrame() override { | 121 void DidFinishImplFrame() override { |
| 122 EXPECT_TRUE(inside_begin_impl_frame_); | 122 EXPECT_TRUE(inside_begin_impl_frame_); |
| 123 inside_begin_impl_frame_ = false; | 123 inside_begin_impl_frame_ = false; |
| 124 } | 124 } |
| 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 ScheduledActionDrawIfPossible() override { |
| 136 PushAction("ScheduledActionDrawAndSwapIfPossible"); | 136 PushAction("ScheduledActionDrawIfPossible"); |
| 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_ack_) |
| 146 scheduler_->DidSwapBuffersComplete(); | 146 scheduler_->DidReceiveCompositorFrameAck(); |
| 147 } | 147 } |
| 148 return result; | 148 return result; |
| 149 } | 149 } |
| 150 DrawResult ScheduledActionDrawAndSwapForced() override { | 150 DrawResult ScheduledActionDrawForced() override { |
| 151 PushAction("ScheduledActionDrawAndSwapForced"); | 151 PushAction("ScheduledActionDrawForced"); |
| 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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 208 protected: | 208 protected: |
| 209 bool InsideBeginImplFrameCallback(bool state) { | 209 bool InsideBeginImplFrameCallback(bool state) { |
| 210 return inside_begin_impl_frame_ == state; | 210 return inside_begin_impl_frame_ == state; |
| 211 } | 211 } |
| 212 | 212 |
| 213 bool inside_begin_impl_frame_; | 213 bool inside_begin_impl_frame_; |
| 214 bool will_begin_impl_frame_causes_redraw_; | 214 bool will_begin_impl_frame_causes_redraw_; |
| 215 bool will_begin_impl_frame_requests_one_begin_impl_frame_; | 215 bool will_begin_impl_frame_requests_one_begin_impl_frame_; |
| 216 bool draw_will_happen_; | 216 bool draw_will_happen_; |
| 217 bool swap_will_happen_if_draw_happens_; | 217 bool swap_will_happen_if_draw_happens_; |
| 218 bool automatic_swap_ack_; | 218 bool automatic_ack_; |
| 219 int num_draws_; | 219 int num_draws_; |
| 220 BeginFrameArgs last_begin_main_frame_args_; | 220 BeginFrameArgs last_begin_main_frame_args_; |
| 221 base::TimeTicks posted_begin_impl_frame_deadline_; | 221 base::TimeTicks posted_begin_impl_frame_deadline_; |
| 222 std::vector<const char*> actions_; | 222 std::vector<const char*> actions_; |
| 223 std::vector<std::unique_ptr<base::trace_event::ConvertableToTraceFormat>> | 223 std::vector<std::unique_ptr<base::trace_event::ConvertableToTraceFormat>> |
| 224 states_; | 224 states_; |
| 225 TestScheduler* scheduler_; | 225 TestScheduler* scheduler_; |
| 226 }; | 226 }; |
| 227 | 227 |
| 228 enum BeginFrameSourceType { | 228 enum BeginFrameSourceType { |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 409 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, now_src()); | 409 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, now_src()); |
| 410 fake_external_begin_frame_source_->TestOnBeginFrame(args); | 410 fake_external_begin_frame_source_->TestOnBeginFrame(args); |
| 411 return args; | 411 return args; |
| 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 ImplFrameSkippedAfterLateAck(bool receive_ack_before_deadline); |
| 420 void ImplFrameNotSkippedAfterLateSwapAck(); | 420 void ImplFrameNotSkippedAfterLateAck(); |
| 421 void BeginFramesNotFromClient(BeginFrameSourceType bfs_type); | 421 void BeginFramesNotFromClient(BeginFrameSourceType bfs_type); |
| 422 void BeginFramesNotFromClient_SwapThrottled(BeginFrameSourceType bfs_type); | 422 void BeginFramesNotFromClient_IsDrawThrottled(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("ScheduledActionDrawIfPossible", client_); |
| 541 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); | 541 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); |
| 542 EXPECT_TRUE(scheduler_->begin_frames_expected()); | 542 EXPECT_TRUE(scheduler_->begin_frames_expected()); |
| 543 client_->Reset(); | 543 client_->Reset(); |
| 544 | 544 |
| 545 // The following BeginImplFrame deadline should SetNeedsBeginFrame(false) | 545 // The following BeginImplFrame deadline should SetNeedsBeginFrame(false) |
| 546 // to avoid excessive toggles. | 546 // to avoid excessive toggles. |
| 547 EXPECT_SCOPED(AdvanceFrame()); | 547 EXPECT_SCOPED(AdvanceFrame()); |
| 548 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client_); | 548 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client_); |
| 549 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); | 549 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); |
| 550 client_->Reset(); | 550 client_->Reset(); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 595 scheduler_->SetNeedsRedraw(); | 595 scheduler_->SetNeedsRedraw(); |
| 596 EXPECT_SINGLE_ACTION("AddObserver(this)", client_); | 596 EXPECT_SINGLE_ACTION("AddObserver(this)", client_); |
| 597 | 597 |
| 598 client_->Reset(); | 598 client_->Reset(); |
| 599 AdvanceFrame(); | 599 AdvanceFrame(); |
| 600 // BeginMainFrame is not sent during the defer commit is on. | 600 // BeginMainFrame is not sent during the defer commit is on. |
| 601 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 1); | 601 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 1); |
| 602 | 602 |
| 603 client_->Reset(); | 603 client_->Reset(); |
| 604 task_runner().RunPendingTasks(); // Run posted deadline. | 604 task_runner().RunPendingTasks(); // Run posted deadline. |
| 605 EXPECT_SINGLE_ACTION("ScheduledActionDrawAndSwapIfPossible", client_); | 605 EXPECT_SINGLE_ACTION("ScheduledActionDrawIfPossible", client_); |
| 606 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); | 606 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); |
| 607 EXPECT_TRUE(scheduler_->begin_frames_expected()); | 607 EXPECT_TRUE(scheduler_->begin_frames_expected()); |
| 608 | 608 |
| 609 client_->Reset(); | 609 client_->Reset(); |
| 610 AdvanceFrame(); | 610 AdvanceFrame(); |
| 611 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client_); | 611 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client_); |
| 612 } | 612 } |
| 613 | 613 |
| 614 TEST_F(SchedulerTest, RequestCommitAfterBeginMainFrameSent) { | 614 TEST_F(SchedulerTest, RequestCommitAfterBeginMainFrameSent) { |
| 615 SetUpScheduler(EXTERNAL_BFS); | 615 SetUpScheduler(EXTERNAL_BFS); |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 640 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); | 640 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); |
| 641 client_->Reset(); | 641 client_->Reset(); |
| 642 | 642 |
| 643 // Activate it. | 643 // Activate it. |
| 644 scheduler_->NotifyReadyToActivate(); | 644 scheduler_->NotifyReadyToActivate(); |
| 645 EXPECT_SINGLE_ACTION("ScheduledActionActivateSyncTree", client_); | 645 EXPECT_SINGLE_ACTION("ScheduledActionActivateSyncTree", client_); |
| 646 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); | 646 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); |
| 647 client_->Reset(); | 647 client_->Reset(); |
| 648 | 648 |
| 649 task_runner().RunPendingTasks(); // Run posted deadline. | 649 task_runner().RunPendingTasks(); // Run posted deadline. |
| 650 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 0, 1); | 650 EXPECT_ACTION("ScheduledActionDrawIfPossible", client_, 0, 1); |
| 651 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); | 651 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); |
| 652 | 652 |
| 653 // Because we just swapped, the Scheduler should also request the next | 653 // Because we just swapped, the Scheduler should also request the next |
| 654 // BeginImplFrame from the CompositorFrameSink. | 654 // BeginImplFrame from the CompositorFrameSink. |
| 655 EXPECT_TRUE(scheduler_->begin_frames_expected()); | 655 EXPECT_TRUE(scheduler_->begin_frames_expected()); |
| 656 client_->Reset(); | 656 client_->Reset(); |
| 657 // Since another commit is needed, the next BeginImplFrame should initiate | 657 // Since another commit is needed, the next BeginImplFrame should initiate |
| 658 // the second commit. | 658 // the second commit. |
| 659 EXPECT_SCOPED(AdvanceFrame()); | 659 EXPECT_SCOPED(AdvanceFrame()); |
| 660 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); | 660 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
| 661 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); | 661 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); |
| 662 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); | 662 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); |
| 663 client_->Reset(); | 663 client_->Reset(); |
| 664 | 664 |
| 665 // Finishing the commit before the deadline should post a new deadline task | 665 // Finishing the commit before the deadline should post a new deadline task |
| 666 // to trigger the deadline early. | 666 // to trigger the deadline early. |
| 667 scheduler_->NotifyBeginMainFrameStarted(base::TimeTicks()); | 667 scheduler_->NotifyBeginMainFrameStarted(base::TimeTicks()); |
| 668 scheduler_->NotifyReadyToCommit(); | 668 scheduler_->NotifyReadyToCommit(); |
| 669 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_); | 669 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_); |
| 670 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); | 670 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); |
| 671 client_->Reset(); | 671 client_->Reset(); |
| 672 scheduler_->NotifyReadyToActivate(); | 672 scheduler_->NotifyReadyToActivate(); |
| 673 EXPECT_SINGLE_ACTION("ScheduledActionActivateSyncTree", client_); | 673 EXPECT_SINGLE_ACTION("ScheduledActionActivateSyncTree", client_); |
| 674 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); | 674 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); |
| 675 client_->Reset(); | 675 client_->Reset(); |
| 676 task_runner().RunPendingTasks(); // Run posted deadline. | 676 task_runner().RunPendingTasks(); // Run posted deadline. |
| 677 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 0, 1); | 677 EXPECT_ACTION("ScheduledActionDrawIfPossible", client_, 0, 1); |
| 678 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); | 678 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); |
| 679 EXPECT_TRUE(scheduler_->begin_frames_expected()); | 679 EXPECT_TRUE(scheduler_->begin_frames_expected()); |
| 680 client_->Reset(); | 680 client_->Reset(); |
| 681 | 681 |
| 682 // On the next BeginImplFrame, verify we go back to a quiescent state and | 682 // On the next BeginImplFrame, verify we go back to a quiescent state and |
| 683 // no longer request BeginImplFrames. | 683 // no longer request BeginImplFrames. |
| 684 EXPECT_SCOPED(AdvanceFrame()); | 684 EXPECT_SCOPED(AdvanceFrame()); |
| 685 task_runner().RunPendingTasks(); // Run posted deadline. | 685 task_runner().RunPendingTasks(); // Run posted deadline. |
| 686 EXPECT_FALSE(scheduler_->begin_frames_expected()); | 686 EXPECT_FALSE(scheduler_->begin_frames_expected()); |
| 687 client_->Reset(); | 687 client_->Reset(); |
| 688 } | 688 } |
| 689 | 689 |
| 690 class SchedulerClientThatsetNeedsDrawInsideDraw : public FakeSchedulerClient { | 690 class SchedulerClientThatsetNeedsDrawInsideDraw : public FakeSchedulerClient { |
| 691 public: | 691 public: |
| 692 SchedulerClientThatsetNeedsDrawInsideDraw() | 692 SchedulerClientThatsetNeedsDrawInsideDraw() |
| 693 : FakeSchedulerClient(), request_redraws_(false) {} | 693 : FakeSchedulerClient(), request_redraws_(false) {} |
| 694 | 694 |
| 695 void SetRequestRedrawsInsideDraw(bool enable) { request_redraws_ = enable; } | 695 void SetRequestRedrawsInsideDraw(bool enable) { request_redraws_ = enable; } |
| 696 | 696 |
| 697 DrawResult ScheduledActionDrawAndSwapIfPossible() override { | 697 DrawResult ScheduledActionDrawIfPossible() override { |
| 698 // Only SetNeedsRedraw the first time this is called | 698 // Only SetNeedsRedraw the first time this is called |
| 699 if (request_redraws_) { | 699 if (request_redraws_) { |
| 700 scheduler_->SetNeedsRedraw(); | 700 scheduler_->SetNeedsRedraw(); |
| 701 } | 701 } |
| 702 return FakeSchedulerClient::ScheduledActionDrawAndSwapIfPossible(); | 702 return FakeSchedulerClient::ScheduledActionDrawIfPossible(); |
| 703 } | 703 } |
| 704 | 704 |
| 705 DrawResult ScheduledActionDrawAndSwapForced() override { | 705 DrawResult ScheduledActionDrawForced() override { |
| 706 NOTREACHED(); | 706 NOTREACHED(); |
| 707 return DRAW_SUCCESS; | 707 return DRAW_SUCCESS; |
| 708 } | 708 } |
| 709 | 709 |
| 710 private: | 710 private: |
| 711 bool request_redraws_; | 711 bool request_redraws_; |
| 712 }; | 712 }; |
| 713 | 713 |
| 714 // Tests for two different situations: | 714 // Tests for two different situations: |
| 715 // 1. the scheduler dropping SetNeedsRedraw requests that happen inside | 715 // 1. the scheduler dropping SetNeedsRedraw requests that happen inside |
| 716 // a ScheduledActionDrawAndSwap | 716 // a ScheduledActionDraw |
| 717 // 2. the scheduler drawing twice inside a single tick | 717 // 2. the scheduler drawing twice inside a single tick |
| 718 TEST_F(SchedulerTest, RequestRedrawInsideDraw) { | 718 TEST_F(SchedulerTest, RequestRedrawInsideDraw) { |
| 719 SchedulerClientThatsetNeedsDrawInsideDraw* client = | 719 SchedulerClientThatsetNeedsDrawInsideDraw* client = |
| 720 new SchedulerClientThatsetNeedsDrawInsideDraw; | 720 new SchedulerClientThatsetNeedsDrawInsideDraw; |
| 721 SetUpScheduler(EXTERNAL_BFS, base::WrapUnique(client)); | 721 SetUpScheduler(EXTERNAL_BFS, base::WrapUnique(client)); |
| 722 client->SetRequestRedrawsInsideDraw(true); | 722 client->SetRequestRedrawsInsideDraw(true); |
| 723 | 723 |
| 724 scheduler_->SetNeedsRedraw(); | 724 scheduler_->SetNeedsRedraw(); |
| 725 EXPECT_TRUE(scheduler_->RedrawPending()); | 725 EXPECT_TRUE(scheduler_->RedrawPending()); |
| 726 EXPECT_TRUE(client->needs_begin_frames()); | 726 EXPECT_TRUE(client->needs_begin_frames()); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 793 EXPECT_FALSE(scheduler_->RedrawPending()); | 793 EXPECT_FALSE(scheduler_->RedrawPending()); |
| 794 EXPECT_TRUE(client->needs_begin_frames()); | 794 EXPECT_TRUE(client->needs_begin_frames()); |
| 795 } | 795 } |
| 796 | 796 |
| 797 class SchedulerClientThatSetNeedsBeginMainFrameInsideDraw | 797 class SchedulerClientThatSetNeedsBeginMainFrameInsideDraw |
| 798 : public FakeSchedulerClient { | 798 : public FakeSchedulerClient { |
| 799 public: | 799 public: |
| 800 SchedulerClientThatSetNeedsBeginMainFrameInsideDraw() | 800 SchedulerClientThatSetNeedsBeginMainFrameInsideDraw() |
| 801 : set_needs_commit_on_next_draw_(false) {} | 801 : set_needs_commit_on_next_draw_(false) {} |
| 802 | 802 |
| 803 DrawResult ScheduledActionDrawAndSwapIfPossible() override { | 803 DrawResult ScheduledActionDrawIfPossible() override { |
| 804 // Only SetNeedsBeginMainFrame the first time this is called | 804 // Only SetNeedsBeginMainFrame the first time this is called |
| 805 if (set_needs_commit_on_next_draw_) { | 805 if (set_needs_commit_on_next_draw_) { |
| 806 scheduler_->SetNeedsBeginMainFrame(); | 806 scheduler_->SetNeedsBeginMainFrame(); |
| 807 set_needs_commit_on_next_draw_ = false; | 807 set_needs_commit_on_next_draw_ = false; |
| 808 } | 808 } |
| 809 return FakeSchedulerClient::ScheduledActionDrawAndSwapIfPossible(); | 809 return FakeSchedulerClient::ScheduledActionDrawIfPossible(); |
| 810 } | 810 } |
| 811 | 811 |
| 812 DrawResult ScheduledActionDrawAndSwapForced() override { | 812 DrawResult ScheduledActionDrawForced() override { |
| 813 NOTREACHED(); | 813 NOTREACHED(); |
| 814 return DRAW_SUCCESS; | 814 return DRAW_SUCCESS; |
| 815 } | 815 } |
| 816 | 816 |
| 817 void SetNeedsBeginMainFrameOnNextDraw() { | 817 void SetNeedsBeginMainFrameOnNextDraw() { |
| 818 set_needs_commit_on_next_draw_ = true; | 818 set_needs_commit_on_next_draw_ = true; |
| 819 } | 819 } |
| 820 | 820 |
| 821 private: | 821 private: |
| 822 bool set_needs_commit_on_next_draw_; | 822 bool set_needs_commit_on_next_draw_; |
| 823 }; | 823 }; |
| 824 | 824 |
| 825 // Tests for the scheduler infinite-looping on SetNeedsBeginMainFrame requests | 825 // Tests for the scheduler infinite-looping on SetNeedsBeginMainFrame requests |
| 826 // that happen inside a ScheduledActionDrawAndSwap | 826 // that happen inside a ScheduledActionDraw |
| 827 TEST_F(SchedulerTest, RequestCommitInsideDraw) { | 827 TEST_F(SchedulerTest, RequestCommitInsideDraw) { |
| 828 SchedulerClientThatSetNeedsBeginMainFrameInsideDraw* client = | 828 SchedulerClientThatSetNeedsBeginMainFrameInsideDraw* client = |
| 829 new SchedulerClientThatSetNeedsBeginMainFrameInsideDraw; | 829 new SchedulerClientThatSetNeedsBeginMainFrameInsideDraw; |
| 830 SetUpScheduler(EXTERNAL_BFS, base::WrapUnique(client)); | 830 SetUpScheduler(EXTERNAL_BFS, base::WrapUnique(client)); |
| 831 | 831 |
| 832 EXPECT_FALSE(client->needs_begin_frames()); | 832 EXPECT_FALSE(client->needs_begin_frames()); |
| 833 scheduler_->SetNeedsRedraw(); | 833 scheduler_->SetNeedsRedraw(); |
| 834 EXPECT_TRUE(scheduler_->RedrawPending()); | 834 EXPECT_TRUE(scheduler_->RedrawPending()); |
| 835 EXPECT_EQ(0, client->num_draws()); | 835 EXPECT_EQ(0, client->num_draws()); |
| 836 EXPECT_TRUE(client->needs_begin_frames()); | 836 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. | 930 // Fail to draw, this should not start a frame. |
| 931 client->SetDrawWillHappen(false); | 931 client->SetDrawWillHappen(false); |
| 932 client->SetNeedsBeginMainFrameOnNextDraw(); | 932 client->SetNeedsBeginMainFrameOnNextDraw(); |
| 933 EXPECT_SCOPED(AdvanceFrame()); | 933 EXPECT_SCOPED(AdvanceFrame()); |
| 934 task_runner().RunPendingTasks(); // Run posted deadline. | 934 task_runner().RunPendingTasks(); // Run posted deadline. |
| 935 EXPECT_EQ(2, client->num_draws()); | 935 EXPECT_EQ(2, client->num_draws()); |
| 936 } | 936 } |
| 937 | 937 |
| 938 class SchedulerClientNeedsPrepareTilesInDraw : public FakeSchedulerClient { | 938 class SchedulerClientNeedsPrepareTilesInDraw : public FakeSchedulerClient { |
| 939 public: | 939 public: |
| 940 DrawResult ScheduledActionDrawAndSwapIfPossible() override { | 940 DrawResult ScheduledActionDrawIfPossible() override { |
| 941 scheduler_->SetNeedsPrepareTiles(); | 941 scheduler_->SetNeedsPrepareTiles(); |
| 942 return FakeSchedulerClient::ScheduledActionDrawAndSwapIfPossible(); | 942 return FakeSchedulerClient::ScheduledActionDrawIfPossible(); |
| 943 } | 943 } |
| 944 }; | 944 }; |
| 945 | 945 |
| 946 // Test prepare tiles is independant of draws. | 946 // Test prepare tiles is independant of draws. |
| 947 TEST_F(SchedulerTest, PrepareTiles) { | 947 TEST_F(SchedulerTest, PrepareTiles) { |
| 948 SchedulerClientNeedsPrepareTilesInDraw* client = | 948 SchedulerClientNeedsPrepareTilesInDraw* client = |
| 949 new SchedulerClientNeedsPrepareTilesInDraw; | 949 new SchedulerClientNeedsPrepareTilesInDraw; |
| 950 SetUpScheduler(EXTERNAL_BFS, base::WrapUnique(client)); | 950 SetUpScheduler(EXTERNAL_BFS, base::WrapUnique(client)); |
| 951 | 951 |
| 952 // Request both draw and prepare tiles. PrepareTiles shouldn't | 952 // Request both draw and prepare tiles. PrepareTiles shouldn't |
| 953 // be trigged until BeginImplFrame. | 953 // be trigged until BeginImplFrame. |
| 954 client->Reset(); | 954 client->Reset(); |
| 955 scheduler_->SetNeedsPrepareTiles(); | 955 scheduler_->SetNeedsPrepareTiles(); |
| 956 scheduler_->SetNeedsRedraw(); | 956 scheduler_->SetNeedsRedraw(); |
| 957 EXPECT_TRUE(scheduler_->RedrawPending()); | 957 EXPECT_TRUE(scheduler_->RedrawPending()); |
| 958 EXPECT_TRUE(scheduler_->PrepareTilesPending()); | 958 EXPECT_TRUE(scheduler_->PrepareTilesPending()); |
| 959 EXPECT_TRUE(client->needs_begin_frames()); | 959 EXPECT_TRUE(client->needs_begin_frames()); |
| 960 EXPECT_EQ(0, client->num_draws()); | 960 EXPECT_EQ(0, client->num_draws()); |
| 961 EXPECT_FALSE(client->HasAction("ScheduledActionPrepareTiles")); | 961 EXPECT_FALSE(client->HasAction("ScheduledActionPrepareTiles")); |
| 962 EXPECT_FALSE(client->HasAction("ScheduledActionDrawAndSwapIfPossible")); | 962 EXPECT_FALSE(client->HasAction("ScheduledActionDrawIfPossible")); |
| 963 | 963 |
| 964 // We have no immediate actions to perform, so the BeginImplFrame should post | 964 // We have no immediate actions to perform, so the BeginImplFrame should post |
| 965 // the deadline task. | 965 // the deadline task. |
| 966 client->Reset(); | 966 client->Reset(); |
| 967 EXPECT_SCOPED(AdvanceFrame()); | 967 EXPECT_SCOPED(AdvanceFrame()); |
| 968 EXPECT_ACTION("WillBeginImplFrame", client, 0, 1); | 968 EXPECT_ACTION("WillBeginImplFrame", client, 0, 1); |
| 969 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); | 969 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); |
| 970 | 970 |
| 971 // On the deadline, the actions should have occured in the right order. | 971 // On the deadline, the actions should have occured in the right order. |
| 972 client->Reset(); | 972 client->Reset(); |
| 973 task_runner().RunPendingTasks(); // Run posted deadline. | 973 task_runner().RunPendingTasks(); // Run posted deadline. |
| 974 EXPECT_EQ(1, client->num_draws()); | 974 EXPECT_EQ(1, client->num_draws()); |
| 975 EXPECT_TRUE(client->HasAction("ScheduledActionDrawAndSwapIfPossible")); | 975 EXPECT_TRUE(client->HasAction("ScheduledActionDrawIfPossible")); |
| 976 EXPECT_TRUE(client->HasAction("ScheduledActionPrepareTiles")); | 976 EXPECT_TRUE(client->HasAction("ScheduledActionPrepareTiles")); |
| 977 EXPECT_LT(client->ActionIndex("ScheduledActionDrawAndSwapIfPossible"), | 977 EXPECT_LT(client->ActionIndex("ScheduledActionDrawIfPossible"), |
| 978 client->ActionIndex("ScheduledActionPrepareTiles")); | 978 client->ActionIndex("ScheduledActionPrepareTiles")); |
| 979 EXPECT_FALSE(scheduler_->RedrawPending()); | 979 EXPECT_FALSE(scheduler_->RedrawPending()); |
| 980 EXPECT_FALSE(scheduler_->PrepareTilesPending()); | 980 EXPECT_FALSE(scheduler_->PrepareTilesPending()); |
| 981 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); | 981 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); |
| 982 | 982 |
| 983 // Request a draw. We don't need a PrepareTiles yet. | 983 // Request a draw. We don't need a PrepareTiles yet. |
| 984 client->Reset(); | 984 client->Reset(); |
| 985 scheduler_->SetNeedsRedraw(); | 985 scheduler_->SetNeedsRedraw(); |
| 986 EXPECT_TRUE(scheduler_->RedrawPending()); | 986 EXPECT_TRUE(scheduler_->RedrawPending()); |
| 987 EXPECT_FALSE(scheduler_->PrepareTilesPending()); | 987 EXPECT_FALSE(scheduler_->PrepareTilesPending()); |
| 988 EXPECT_TRUE(client->needs_begin_frames()); | 988 EXPECT_TRUE(client->needs_begin_frames()); |
| 989 EXPECT_EQ(0, client->num_draws()); | 989 EXPECT_EQ(0, client->num_draws()); |
| 990 | 990 |
| 991 // We have no immediate actions to perform, so the BeginImplFrame should post | 991 // We have no immediate actions to perform, so the BeginImplFrame should post |
| 992 // the deadline task. | 992 // the deadline task. |
| 993 client->Reset(); | 993 client->Reset(); |
| 994 EXPECT_SCOPED(AdvanceFrame()); | 994 EXPECT_SCOPED(AdvanceFrame()); |
| 995 EXPECT_ACTION("WillBeginImplFrame", client, 0, 1); | 995 EXPECT_ACTION("WillBeginImplFrame", client, 0, 1); |
| 996 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); | 996 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); |
| 997 | 997 |
| 998 // Draw. The draw will trigger SetNeedsPrepareTiles, and | 998 // Draw. The draw will trigger SetNeedsPrepareTiles, and |
| 999 // then the PrepareTiles action will be triggered after the Draw. | 999 // then the PrepareTiles action will be triggered after the Draw. |
| 1000 // Afterwards, neither a draw nor PrepareTiles are pending. | 1000 // Afterwards, neither a draw nor PrepareTiles are pending. |
| 1001 client->Reset(); | 1001 client->Reset(); |
| 1002 task_runner().RunPendingTasks(); // Run posted deadline. | 1002 task_runner().RunPendingTasks(); // Run posted deadline. |
| 1003 EXPECT_EQ(1, client->num_draws()); | 1003 EXPECT_EQ(1, client->num_draws()); |
| 1004 EXPECT_TRUE(client->HasAction("ScheduledActionDrawAndSwapIfPossible")); | 1004 EXPECT_TRUE(client->HasAction("ScheduledActionDrawIfPossible")); |
| 1005 EXPECT_TRUE(client->HasAction("ScheduledActionPrepareTiles")); | 1005 EXPECT_TRUE(client->HasAction("ScheduledActionPrepareTiles")); |
| 1006 EXPECT_LT(client->ActionIndex("ScheduledActionDrawAndSwapIfPossible"), | 1006 EXPECT_LT(client->ActionIndex("ScheduledActionDrawIfPossible"), |
| 1007 client->ActionIndex("ScheduledActionPrepareTiles")); | 1007 client->ActionIndex("ScheduledActionPrepareTiles")); |
| 1008 EXPECT_FALSE(scheduler_->RedrawPending()); | 1008 EXPECT_FALSE(scheduler_->RedrawPending()); |
| 1009 EXPECT_FALSE(scheduler_->PrepareTilesPending()); | 1009 EXPECT_FALSE(scheduler_->PrepareTilesPending()); |
| 1010 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); | 1010 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); |
| 1011 | 1011 |
| 1012 // We need a BeginImplFrame where we don't swap to go idle. | 1012 // We need a BeginImplFrame where we don't swap to go idle. |
| 1013 client->Reset(); | 1013 client->Reset(); |
| 1014 EXPECT_SCOPED(AdvanceFrame()); | 1014 EXPECT_SCOPED(AdvanceFrame()); |
| 1015 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); | 1015 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); |
| 1016 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); | 1016 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 1031 EXPECT_FALSE(scheduler_->RedrawPending()); | 1031 EXPECT_FALSE(scheduler_->RedrawPending()); |
| 1032 | 1032 |
| 1033 // BeginImplFrame. There will be no draw, only PrepareTiles. | 1033 // BeginImplFrame. There will be no draw, only PrepareTiles. |
| 1034 client->Reset(); | 1034 client->Reset(); |
| 1035 EXPECT_SCOPED(AdvanceFrame()); | 1035 EXPECT_SCOPED(AdvanceFrame()); |
| 1036 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); | 1036 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); |
| 1037 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); | 1037 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); |
| 1038 client->Reset(); | 1038 client->Reset(); |
| 1039 task_runner().RunPendingTasks(); // Run posted deadline. | 1039 task_runner().RunPendingTasks(); // Run posted deadline. |
| 1040 EXPECT_EQ(0, client->num_draws()); | 1040 EXPECT_EQ(0, client->num_draws()); |
| 1041 EXPECT_FALSE(client->HasAction("ScheduledActionDrawAndSwapIfPossible")); | 1041 EXPECT_FALSE(client->HasAction("ScheduledActionDrawIfPossible")); |
| 1042 EXPECT_TRUE(client->HasAction("ScheduledActionPrepareTiles")); | 1042 EXPECT_TRUE(client->HasAction("ScheduledActionPrepareTiles")); |
| 1043 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); | 1043 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); |
| 1044 } | 1044 } |
| 1045 | 1045 |
| 1046 // Test that PrepareTiles only happens once per frame. If an external caller | 1046 // 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. | 1047 // initiates it, then the state machine should not PrepareTiles on that frame. |
| 1048 TEST_F(SchedulerTest, PrepareTilesOncePerFrame) { | 1048 TEST_F(SchedulerTest, PrepareTilesOncePerFrame) { |
| 1049 SetUpScheduler(EXTERNAL_BFS); | 1049 SetUpScheduler(EXTERNAL_BFS); |
| 1050 | 1050 |
| 1051 // If DidPrepareTiles during a frame, then PrepareTiles should not occur | 1051 // If DidPrepareTiles during a frame, then PrepareTiles should not occur |
| 1052 // again. | 1052 // again. |
| 1053 scheduler_->SetNeedsPrepareTiles(); | 1053 scheduler_->SetNeedsPrepareTiles(); |
| 1054 scheduler_->SetNeedsRedraw(); | 1054 scheduler_->SetNeedsRedraw(); |
| 1055 client_->Reset(); | 1055 client_->Reset(); |
| 1056 EXPECT_SCOPED(AdvanceFrame()); | 1056 EXPECT_SCOPED(AdvanceFrame()); |
| 1057 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 1); | 1057 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 1); |
| 1058 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); | 1058 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); |
| 1059 | 1059 |
| 1060 EXPECT_TRUE(scheduler_->PrepareTilesPending()); | 1060 EXPECT_TRUE(scheduler_->PrepareTilesPending()); |
| 1061 scheduler_->WillPrepareTiles(); | 1061 scheduler_->WillPrepareTiles(); |
| 1062 scheduler_->DidPrepareTiles(); // An explicit PrepareTiles. | 1062 scheduler_->DidPrepareTiles(); // An explicit PrepareTiles. |
| 1063 EXPECT_FALSE(scheduler_->PrepareTilesPending()); | 1063 EXPECT_FALSE(scheduler_->PrepareTilesPending()); |
| 1064 | 1064 |
| 1065 client_->Reset(); | 1065 client_->Reset(); |
| 1066 task_runner().RunPendingTasks(); // Run posted deadline. | 1066 task_runner().RunPendingTasks(); // Run posted deadline. |
| 1067 EXPECT_EQ(1, client_->num_draws()); | 1067 EXPECT_EQ(1, client_->num_draws()); |
| 1068 EXPECT_TRUE(client_->HasAction("ScheduledActionDrawAndSwapIfPossible")); | 1068 EXPECT_TRUE(client_->HasAction("ScheduledActionDrawIfPossible")); |
| 1069 EXPECT_FALSE(client_->HasAction("ScheduledActionPrepareTiles")); | 1069 EXPECT_FALSE(client_->HasAction("ScheduledActionPrepareTiles")); |
| 1070 EXPECT_FALSE(scheduler_->RedrawPending()); | 1070 EXPECT_FALSE(scheduler_->RedrawPending()); |
| 1071 EXPECT_FALSE(scheduler_->PrepareTilesPending()); | 1071 EXPECT_FALSE(scheduler_->PrepareTilesPending()); |
| 1072 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); | 1072 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); |
| 1073 | 1073 |
| 1074 // Next frame without DidPrepareTiles should PrepareTiles with draw. | 1074 // Next frame without DidPrepareTiles should PrepareTiles with draw. |
| 1075 scheduler_->SetNeedsPrepareTiles(); | 1075 scheduler_->SetNeedsPrepareTiles(); |
| 1076 scheduler_->SetNeedsRedraw(); | 1076 scheduler_->SetNeedsRedraw(); |
| 1077 client_->Reset(); | 1077 client_->Reset(); |
| 1078 EXPECT_SCOPED(AdvanceFrame()); | 1078 EXPECT_SCOPED(AdvanceFrame()); |
| 1079 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 1); | 1079 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 1); |
| 1080 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); | 1080 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); |
| 1081 | 1081 |
| 1082 client_->Reset(); | 1082 client_->Reset(); |
| 1083 task_runner().RunPendingTasks(); // Run posted deadline. | 1083 task_runner().RunPendingTasks(); // Run posted deadline. |
| 1084 EXPECT_EQ(1, client_->num_draws()); | 1084 EXPECT_EQ(1, client_->num_draws()); |
| 1085 EXPECT_TRUE(client_->HasAction("ScheduledActionDrawAndSwapIfPossible")); | 1085 EXPECT_TRUE(client_->HasAction("ScheduledActionDrawIfPossible")); |
| 1086 EXPECT_TRUE(client_->HasAction("ScheduledActionPrepareTiles")); | 1086 EXPECT_TRUE(client_->HasAction("ScheduledActionPrepareTiles")); |
| 1087 EXPECT_LT(client_->ActionIndex("ScheduledActionDrawAndSwapIfPossible"), | 1087 EXPECT_LT(client_->ActionIndex("ScheduledActionDrawIfPossible"), |
| 1088 client_->ActionIndex("ScheduledActionPrepareTiles")); | 1088 client_->ActionIndex("ScheduledActionPrepareTiles")); |
| 1089 EXPECT_FALSE(scheduler_->RedrawPending()); | 1089 EXPECT_FALSE(scheduler_->RedrawPending()); |
| 1090 EXPECT_FALSE(scheduler_->PrepareTilesPending()); | 1090 EXPECT_FALSE(scheduler_->PrepareTilesPending()); |
| 1091 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); | 1091 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); |
| 1092 | 1092 |
| 1093 // If we get another DidPrepareTiles within the same frame, we should | 1093 // If we get another DidPrepareTiles within the same frame, we should |
| 1094 // not PrepareTiles on the next frame. | 1094 // not PrepareTiles on the next frame. |
| 1095 scheduler_->WillPrepareTiles(); | 1095 scheduler_->WillPrepareTiles(); |
| 1096 scheduler_->DidPrepareTiles(); // An explicit PrepareTiles. | 1096 scheduler_->DidPrepareTiles(); // An explicit PrepareTiles. |
| 1097 scheduler_->SetNeedsPrepareTiles(); | 1097 scheduler_->SetNeedsPrepareTiles(); |
| 1098 scheduler_->SetNeedsRedraw(); | 1098 scheduler_->SetNeedsRedraw(); |
| 1099 client_->Reset(); | 1099 client_->Reset(); |
| 1100 EXPECT_SCOPED(AdvanceFrame()); | 1100 EXPECT_SCOPED(AdvanceFrame()); |
| 1101 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 1); | 1101 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 1); |
| 1102 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); | 1102 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); |
| 1103 | 1103 |
| 1104 EXPECT_TRUE(scheduler_->PrepareTilesPending()); | 1104 EXPECT_TRUE(scheduler_->PrepareTilesPending()); |
| 1105 | 1105 |
| 1106 client_->Reset(); | 1106 client_->Reset(); |
| 1107 task_runner().RunPendingTasks(); // Run posted deadline. | 1107 task_runner().RunPendingTasks(); // Run posted deadline. |
| 1108 EXPECT_EQ(1, client_->num_draws()); | 1108 EXPECT_EQ(1, client_->num_draws()); |
| 1109 EXPECT_TRUE(client_->HasAction("ScheduledActionDrawAndSwapIfPossible")); | 1109 EXPECT_TRUE(client_->HasAction("ScheduledActionDrawIfPossible")); |
| 1110 EXPECT_FALSE(client_->HasAction("ScheduledActionPrepareTiles")); | 1110 EXPECT_FALSE(client_->HasAction("ScheduledActionPrepareTiles")); |
| 1111 EXPECT_FALSE(scheduler_->RedrawPending()); | 1111 EXPECT_FALSE(scheduler_->RedrawPending()); |
| 1112 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); | 1112 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); |
| 1113 | 1113 |
| 1114 // If we get another DidPrepareTiles, we should not PrepareTiles on the next | 1114 // If we get another DidPrepareTiles, we should not PrepareTiles on the next |
| 1115 // frame. This verifies we don't alternate calling PrepareTiles once and | 1115 // frame. This verifies we don't alternate calling PrepareTiles once and |
| 1116 // twice. | 1116 // twice. |
| 1117 EXPECT_TRUE(scheduler_->PrepareTilesPending()); | 1117 EXPECT_TRUE(scheduler_->PrepareTilesPending()); |
| 1118 scheduler_->WillPrepareTiles(); | 1118 scheduler_->WillPrepareTiles(); |
| 1119 scheduler_->DidPrepareTiles(); // An explicit PrepareTiles. | 1119 scheduler_->DidPrepareTiles(); // An explicit PrepareTiles. |
| 1120 EXPECT_FALSE(scheduler_->PrepareTilesPending()); | 1120 EXPECT_FALSE(scheduler_->PrepareTilesPending()); |
| 1121 scheduler_->SetNeedsPrepareTiles(); | 1121 scheduler_->SetNeedsPrepareTiles(); |
| 1122 scheduler_->SetNeedsRedraw(); | 1122 scheduler_->SetNeedsRedraw(); |
| 1123 client_->Reset(); | 1123 client_->Reset(); |
| 1124 EXPECT_SCOPED(AdvanceFrame()); | 1124 EXPECT_SCOPED(AdvanceFrame()); |
| 1125 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 1); | 1125 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 1); |
| 1126 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); | 1126 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); |
| 1127 | 1127 |
| 1128 EXPECT_TRUE(scheduler_->PrepareTilesPending()); | 1128 EXPECT_TRUE(scheduler_->PrepareTilesPending()); |
| 1129 | 1129 |
| 1130 client_->Reset(); | 1130 client_->Reset(); |
| 1131 task_runner().RunPendingTasks(); // Run posted deadline. | 1131 task_runner().RunPendingTasks(); // Run posted deadline. |
| 1132 EXPECT_EQ(1, client_->num_draws()); | 1132 EXPECT_EQ(1, client_->num_draws()); |
| 1133 EXPECT_TRUE(client_->HasAction("ScheduledActionDrawAndSwapIfPossible")); | 1133 EXPECT_TRUE(client_->HasAction("ScheduledActionDrawIfPossible")); |
| 1134 EXPECT_FALSE(client_->HasAction("ScheduledActionPrepareTiles")); | 1134 EXPECT_FALSE(client_->HasAction("ScheduledActionPrepareTiles")); |
| 1135 EXPECT_FALSE(scheduler_->RedrawPending()); | 1135 EXPECT_FALSE(scheduler_->RedrawPending()); |
| 1136 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); | 1136 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); |
| 1137 | 1137 |
| 1138 // Next frame without DidPrepareTiles should PrepareTiles with draw. | 1138 // Next frame without DidPrepareTiles should PrepareTiles with draw. |
| 1139 scheduler_->SetNeedsPrepareTiles(); | 1139 scheduler_->SetNeedsPrepareTiles(); |
| 1140 scheduler_->SetNeedsRedraw(); | 1140 scheduler_->SetNeedsRedraw(); |
| 1141 client_->Reset(); | 1141 client_->Reset(); |
| 1142 EXPECT_SCOPED(AdvanceFrame()); | 1142 EXPECT_SCOPED(AdvanceFrame()); |
| 1143 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 1); | 1143 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 1); |
| 1144 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); | 1144 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); |
| 1145 | 1145 |
| 1146 client_->Reset(); | 1146 client_->Reset(); |
| 1147 task_runner().RunPendingTasks(); // Run posted deadline. | 1147 task_runner().RunPendingTasks(); // Run posted deadline. |
| 1148 EXPECT_EQ(1, client_->num_draws()); | 1148 EXPECT_EQ(1, client_->num_draws()); |
| 1149 EXPECT_TRUE(client_->HasAction("ScheduledActionDrawAndSwapIfPossible")); | 1149 EXPECT_TRUE(client_->HasAction("ScheduledActionDrawIfPossible")); |
| 1150 EXPECT_TRUE(client_->HasAction("ScheduledActionPrepareTiles")); | 1150 EXPECT_TRUE(client_->HasAction("ScheduledActionPrepareTiles")); |
| 1151 EXPECT_LT(client_->ActionIndex("ScheduledActionDrawAndSwapIfPossible"), | 1151 EXPECT_LT(client_->ActionIndex("ScheduledActionDrawIfPossible"), |
| 1152 client_->ActionIndex("ScheduledActionPrepareTiles")); | 1152 client_->ActionIndex("ScheduledActionPrepareTiles")); |
| 1153 EXPECT_FALSE(scheduler_->RedrawPending()); | 1153 EXPECT_FALSE(scheduler_->RedrawPending()); |
| 1154 EXPECT_FALSE(scheduler_->PrepareTilesPending()); | 1154 EXPECT_FALSE(scheduler_->PrepareTilesPending()); |
| 1155 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); | 1155 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); |
| 1156 } | 1156 } |
| 1157 | 1157 |
| 1158 TEST_F(SchedulerTest, PrepareTilesFunnelResetOnVisibilityChange) { | 1158 TEST_F(SchedulerTest, PrepareTilesFunnelResetOnVisibilityChange) { |
| 1159 std::unique_ptr<SchedulerClientNeedsPrepareTilesInDraw> client = | 1159 std::unique_ptr<SchedulerClientNeedsPrepareTilesInDraw> client = |
| 1160 base::WrapUnique(new SchedulerClientNeedsPrepareTilesInDraw); | 1160 base::WrapUnique(new SchedulerClientNeedsPrepareTilesInDraw); |
| 1161 SetUpScheduler(EXTERNAL_BFS, std::move(client)); | 1161 SetUpScheduler(EXTERNAL_BFS, std::move(client)); |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 1176 EXPECT_SINGLE_ACTION("AddObserver(this)", client_); | 1176 EXPECT_SINGLE_ACTION("AddObserver(this)", client_); |
| 1177 | 1177 |
| 1178 client_->Reset(); | 1178 client_->Reset(); |
| 1179 AdvanceFrame(); | 1179 AdvanceFrame(); |
| 1180 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 1); | 1180 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 1); |
| 1181 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); | 1181 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); |
| 1182 | 1182 |
| 1183 client_->Reset(); | 1183 client_->Reset(); |
| 1184 task_runner().RunTasksWhile(client_->InsideBeginImplFrame(true)); | 1184 task_runner().RunTasksWhile(client_->InsideBeginImplFrame(true)); |
| 1185 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); | 1185 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); |
| 1186 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 0, 2); | 1186 EXPECT_ACTION("ScheduledActionDrawIfPossible", client_, 0, 2); |
| 1187 EXPECT_ACTION("ScheduledActionPrepareTiles", client_, 1, 2); | 1187 EXPECT_ACTION("ScheduledActionPrepareTiles", client_, 1, 2); |
| 1188 } | 1188 } |
| 1189 | 1189 |
| 1190 TEST_F(SchedulerTest, TriggerBeginFrameDeadlineEarly) { | 1190 TEST_F(SchedulerTest, TriggerBeginFrameDeadlineEarly) { |
| 1191 SchedulerClientNeedsPrepareTilesInDraw* client = | 1191 SchedulerClientNeedsPrepareTilesInDraw* client = |
| 1192 new SchedulerClientNeedsPrepareTilesInDraw; | 1192 new SchedulerClientNeedsPrepareTilesInDraw; |
| 1193 SetUpScheduler(EXTERNAL_BFS, base::WrapUnique(client)); | 1193 SetUpScheduler(EXTERNAL_BFS, base::WrapUnique(client)); |
| 1194 | 1194 |
| 1195 scheduler_->SetNeedsRedraw(); | 1195 scheduler_->SetNeedsRedraw(); |
| 1196 EXPECT_SCOPED(AdvanceFrame()); | 1196 EXPECT_SCOPED(AdvanceFrame()); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1229 client_->Reset(); | 1229 client_->Reset(); |
| 1230 task_runner().RunPendingTasks(); // Try to run posted deadline. | 1230 task_runner().RunPendingTasks(); // Try to run posted deadline. |
| 1231 // There is no posted deadline. | 1231 // There is no posted deadline. |
| 1232 EXPECT_NO_ACTION(client_); | 1232 EXPECT_NO_ACTION(client_); |
| 1233 | 1233 |
| 1234 // Scheduler received ready to draw signal, and posted deadline. | 1234 // Scheduler received ready to draw signal, and posted deadline. |
| 1235 scheduler_->NotifyReadyToDraw(); | 1235 scheduler_->NotifyReadyToDraw(); |
| 1236 client_->Reset(); | 1236 client_->Reset(); |
| 1237 task_runner().RunPendingTasks(); // Run posted deadline. | 1237 task_runner().RunPendingTasks(); // Run posted deadline. |
| 1238 EXPECT_EQ(1, client_->num_draws()); | 1238 EXPECT_EQ(1, client_->num_draws()); |
| 1239 EXPECT_TRUE(client_->HasAction("ScheduledActionDrawAndSwapIfPossible")); | 1239 EXPECT_TRUE(client_->HasAction("ScheduledActionDrawIfPossible")); |
| 1240 } | 1240 } |
| 1241 | 1241 |
| 1242 TEST_F(SchedulerTest, WaitForReadyToDrawCancelledWhenLostCompositorFrameSink) { | 1242 TEST_F(SchedulerTest, WaitForReadyToDrawCancelledWhenLostCompositorFrameSink) { |
| 1243 SchedulerClientNeedsPrepareTilesInDraw* client = | 1243 SchedulerClientNeedsPrepareTilesInDraw* client = |
| 1244 new SchedulerClientNeedsPrepareTilesInDraw; | 1244 new SchedulerClientNeedsPrepareTilesInDraw; |
| 1245 scheduler_settings_.commit_to_active_tree = true; | 1245 scheduler_settings_.commit_to_active_tree = true; |
| 1246 SetUpScheduler(EXTERNAL_BFS, base::WrapUnique(client)); | 1246 SetUpScheduler(EXTERNAL_BFS, base::WrapUnique(client)); |
| 1247 | 1247 |
| 1248 // SetNeedsBeginMainFrame should begin the frame on the next BeginImplFrame. | 1248 // SetNeedsBeginMainFrame should begin the frame on the next BeginImplFrame. |
| 1249 scheduler_->SetNeedsBeginMainFrame(); | 1249 scheduler_->SetNeedsBeginMainFrame(); |
| (...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1489 scheduler_->SetNeedsBeginMainFrame(); | 1489 scheduler_->SetNeedsBeginMainFrame(); |
| 1490 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); | 1490 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); |
| 1491 EXPECT_SCOPED(AdvanceFrame()); | 1491 EXPECT_SCOPED(AdvanceFrame()); |
| 1492 EXPECT_TRUE(client_->HasAction("WillBeginImplFrame")); | 1492 EXPECT_TRUE(client_->HasAction("WillBeginImplFrame")); |
| 1493 EXPECT_TRUE(client_->HasAction("ScheduledActionSendBeginMainFrame")); | 1493 EXPECT_TRUE(client_->HasAction("ScheduledActionSendBeginMainFrame")); |
| 1494 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); | 1494 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); |
| 1495 task_runner().RunTasksWhile(client_->InsideBeginImplFrame(true)); | 1495 task_runner().RunTasksWhile(client_->InsideBeginImplFrame(true)); |
| 1496 EXPECT_TRUE(scheduler_->MainThreadMissedLastDeadline()); | 1496 EXPECT_TRUE(scheduler_->MainThreadMissedLastDeadline()); |
| 1497 } | 1497 } |
| 1498 | 1498 |
| 1499 void SchedulerTest::ImplFrameSkippedAfterLateSwapAck( | 1499 void SchedulerTest::ImplFrameSkippedAfterLateAck( |
|
sunnyps
2016/10/14 01:08:47
nit: Ack -> SubmitCompositorFrameAck
danakj
2016/10/14 01:19:31
This makes test names go over 80 columns so I'll l
| |
| 1500 bool swap_ack_before_deadline) { | 1500 bool receive_ack_before_deadline) { |
| 1501 // To get into a high latency state, this test disables automatic swap acks. | 1501 // To get into a high latency state, this test disables automatic swap acks. |
| 1502 client_->SetAutomaticSwapAck(false); | 1502 client_->SetAutomaticSubmitCompositorFrameAck(false); |
| 1503 | 1503 |
| 1504 // Draw and swap for first BeginFrame | 1504 // Draw and swap for first BeginFrame |
| 1505 client_->Reset(); | 1505 client_->Reset(); |
| 1506 scheduler_->SetNeedsBeginMainFrame(); | 1506 scheduler_->SetNeedsBeginMainFrame(); |
| 1507 scheduler_->SetNeedsRedraw(); | 1507 scheduler_->SetNeedsRedraw(); |
| 1508 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); | 1508 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); |
| 1509 SendNextBeginFrame(); | 1509 SendNextBeginFrame(); |
| 1510 EXPECT_ACTION("AddObserver(this)", client_, 0, 3); | 1510 EXPECT_ACTION("AddObserver(this)", client_, 0, 3); |
| 1511 EXPECT_ACTION("WillBeginImplFrame", client_, 1, 3); | 1511 EXPECT_ACTION("WillBeginImplFrame", client_, 1, 3); |
| 1512 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 2, 3); | 1512 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 2, 3); |
| 1513 | 1513 |
| 1514 client_->Reset(); | 1514 client_->Reset(); |
| 1515 scheduler_->NotifyBeginMainFrameStarted(base::TimeTicks()); | 1515 scheduler_->NotifyBeginMainFrameStarted(base::TimeTicks()); |
| 1516 scheduler_->NotifyReadyToCommit(); | 1516 scheduler_->NotifyReadyToCommit(); |
| 1517 scheduler_->NotifyReadyToActivate(); | 1517 scheduler_->NotifyReadyToActivate(); |
| 1518 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); | 1518 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); |
| 1519 task_runner().RunTasksWhile(client_->InsideBeginImplFrame(true)); | 1519 task_runner().RunTasksWhile(client_->InsideBeginImplFrame(true)); |
| 1520 EXPECT_ACTION("ScheduledActionCommit", client_, 0, 3); | 1520 EXPECT_ACTION("ScheduledActionCommit", client_, 0, 3); |
| 1521 EXPECT_ACTION("ScheduledActionActivateSyncTree", client_, 1, 3); | 1521 EXPECT_ACTION("ScheduledActionActivateSyncTree", client_, 1, 3); |
| 1522 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 2, 3); | 1522 EXPECT_ACTION("ScheduledActionDrawIfPossible", client_, 2, 3); |
| 1523 | 1523 |
| 1524 // Verify we skip every other frame if the swap ack consistently | 1524 // Verify we skip every other frame if the swap ack consistently |
| 1525 // comes back late. | 1525 // comes back late. |
| 1526 for (int i = 0; i < 10; i++) { | 1526 for (int i = 0; i < 10; i++) { |
| 1527 // Not calling scheduler_->DidSwapBuffersComplete() until after next | 1527 // Not calling scheduler_->DidReceiveCompositorFrameAck() until after next |
| 1528 // BeginImplFrame puts the impl thread in high latency mode. | 1528 // BeginImplFrame puts the impl thread in high latency mode. |
| 1529 client_->Reset(); | 1529 client_->Reset(); |
| 1530 scheduler_->SetNeedsBeginMainFrame(); | 1530 scheduler_->SetNeedsBeginMainFrame(); |
| 1531 scheduler_->SetNeedsRedraw(); | 1531 scheduler_->SetNeedsRedraw(); |
| 1532 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); | 1532 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); |
| 1533 SendNextBeginFrame(); | 1533 SendNextBeginFrame(); |
| 1534 // Verify that we skip the BeginImplFrame | 1534 // Verify that we skip the BeginImplFrame |
| 1535 EXPECT_NO_ACTION(client_); | 1535 EXPECT_NO_ACTION(client_); |
| 1536 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); | 1536 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); |
| 1537 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); | 1537 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); |
| 1538 | 1538 |
| 1539 // Verify that we do not perform any actions after we are no longer | 1539 // Verify that we do not perform any actions after we are no longer |
| 1540 // swap throttled. | 1540 // swap throttled. |
| 1541 client_->Reset(); | 1541 client_->Reset(); |
| 1542 if (swap_ack_before_deadline) { | 1542 if (receive_ack_before_deadline) { |
| 1543 // It shouldn't matter if the swap ack comes back before the deadline... | 1543 // It shouldn't matter if the swap ack comes back before the deadline... |
| 1544 scheduler_->DidSwapBuffersComplete(); | 1544 scheduler_->DidReceiveCompositorFrameAck(); |
| 1545 task_runner().RunTasksWhile(client_->InsideBeginImplFrame(true)); | 1545 task_runner().RunTasksWhile(client_->InsideBeginImplFrame(true)); |
| 1546 } else { | 1546 } else { |
| 1547 // ... or after the deadline. | 1547 // ... or after the deadline. |
| 1548 task_runner().RunTasksWhile(client_->InsideBeginImplFrame(true)); | 1548 task_runner().RunTasksWhile(client_->InsideBeginImplFrame(true)); |
| 1549 scheduler_->DidSwapBuffersComplete(); | 1549 scheduler_->DidReceiveCompositorFrameAck(); |
| 1550 } | 1550 } |
| 1551 EXPECT_NO_ACTION(client_); | 1551 EXPECT_NO_ACTION(client_); |
| 1552 | 1552 |
| 1553 // Verify that we start the next BeginImplFrame and continue normally | 1553 // Verify that we start the next BeginImplFrame and continue normally |
| 1554 // after having just skipped a BeginImplFrame. | 1554 // after having just skipped a BeginImplFrame. |
| 1555 client_->Reset(); | 1555 client_->Reset(); |
| 1556 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); | 1556 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); |
| 1557 SendNextBeginFrame(); | 1557 SendNextBeginFrame(); |
| 1558 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); | 1558 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
| 1559 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); | 1559 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); |
| 1560 | 1560 |
| 1561 client_->Reset(); | 1561 client_->Reset(); |
| 1562 scheduler_->NotifyBeginMainFrameStarted(base::TimeTicks()); | 1562 scheduler_->NotifyBeginMainFrameStarted(base::TimeTicks()); |
| 1563 scheduler_->NotifyReadyToCommit(); | 1563 scheduler_->NotifyReadyToCommit(); |
| 1564 scheduler_->NotifyReadyToActivate(); | 1564 scheduler_->NotifyReadyToActivate(); |
| 1565 task_runner().RunTasksWhile(client_->InsideBeginImplFrame(true)); | 1565 task_runner().RunTasksWhile(client_->InsideBeginImplFrame(true)); |
| 1566 EXPECT_ACTION("ScheduledActionCommit", client_, 0, 3); | 1566 EXPECT_ACTION("ScheduledActionCommit", client_, 0, 3); |
| 1567 EXPECT_ACTION("ScheduledActionActivateSyncTree", client_, 1, 3); | 1567 EXPECT_ACTION("ScheduledActionActivateSyncTree", client_, 1, 3); |
| 1568 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 2, 3); | 1568 EXPECT_ACTION("ScheduledActionDrawIfPossible", client_, 2, 3); |
| 1569 } | 1569 } |
| 1570 } | 1570 } |
| 1571 | 1571 |
| 1572 TEST_F(SchedulerTest, | 1572 TEST_F(SchedulerTest, |
| 1573 ImplFrameSkippedAfterLateSwapAck_FastEstimates_SwapAckThenDeadline) { | 1573 ImplFrameSkippedAfterLateAck_FastEstimates_SubmitAckThenDeadline) { |
| 1574 SetUpScheduler(EXTERNAL_BFS); | 1574 SetUpScheduler(EXTERNAL_BFS); |
| 1575 fake_compositor_timing_history_->SetAllEstimatesTo(kFastDuration); | 1575 fake_compositor_timing_history_->SetAllEstimatesTo(kFastDuration); |
| 1576 | 1576 |
| 1577 bool swap_ack_before_deadline = true; | 1577 bool receive_ack_before_deadline = true; |
| 1578 EXPECT_SCOPED(ImplFrameSkippedAfterLateSwapAck(swap_ack_before_deadline)); | 1578 EXPECT_SCOPED(ImplFrameSkippedAfterLateAck(receive_ack_before_deadline)); |
| 1579 } | 1579 } |
| 1580 | 1580 |
| 1581 TEST_F(SchedulerTest, | 1581 TEST_F(SchedulerTest, |
| 1582 ImplFrameSkippedAfterLateSwapAck_FastEstimates_DeadlineThenSwapAck) { | 1582 ImplFrameSkippedAfterLateAck_FastEstimates_DeadlineThenSubmitAck) { |
| 1583 SetUpScheduler(EXTERNAL_BFS); | 1583 SetUpScheduler(EXTERNAL_BFS); |
| 1584 fake_compositor_timing_history_->SetAllEstimatesTo(kFastDuration); | 1584 fake_compositor_timing_history_->SetAllEstimatesTo(kFastDuration); |
| 1585 | 1585 |
| 1586 bool swap_ack_before_deadline = false; | 1586 bool receive_ack_before_deadline = false; |
| 1587 EXPECT_SCOPED(ImplFrameSkippedAfterLateSwapAck(swap_ack_before_deadline)); | 1587 EXPECT_SCOPED(ImplFrameSkippedAfterLateAck(receive_ack_before_deadline)); |
| 1588 } | 1588 } |
| 1589 | 1589 |
| 1590 TEST_F(SchedulerTest, | 1590 TEST_F(SchedulerTest, |
| 1591 ImplFrameSkippedAfterLateSwapAck_LongMainFrameQueueDurationNotCritical) { | 1591 ImplFrameSkippedAfterLateAck_LongMainFrameQueueDurationNotCritical) { |
| 1592 SetUpScheduler(EXTERNAL_BFS); | 1592 SetUpScheduler(EXTERNAL_BFS); |
| 1593 fake_compositor_timing_history_->SetAllEstimatesTo(kFastDuration); | 1593 fake_compositor_timing_history_->SetAllEstimatesTo(kFastDuration); |
| 1594 fake_compositor_timing_history_ | 1594 fake_compositor_timing_history_ |
| 1595 ->SetBeginMainFrameQueueDurationNotCriticalEstimate(kSlowDuration); | 1595 ->SetBeginMainFrameQueueDurationNotCriticalEstimate(kSlowDuration); |
| 1596 | 1596 |
| 1597 bool swap_ack_before_deadline = false; | 1597 bool receive_ack_before_deadline = false; |
| 1598 EXPECT_SCOPED(ImplFrameSkippedAfterLateSwapAck(swap_ack_before_deadline)); | 1598 EXPECT_SCOPED(ImplFrameSkippedAfterLateAck(receive_ack_before_deadline)); |
| 1599 } | 1599 } |
| 1600 | 1600 |
| 1601 TEST_F(SchedulerTest, | 1601 TEST_F(SchedulerTest, ImplFrameSkippedAfterLateAck_ImplLatencyTakesPriority) { |
| 1602 ImplFrameSkippedAfterLateSwapAck_ImplLatencyTakesPriority) { | |
| 1603 SetUpScheduler(EXTERNAL_BFS); | 1602 SetUpScheduler(EXTERNAL_BFS); |
| 1604 | 1603 |
| 1605 // Even if every estimate related to the main thread is slow, we should | 1604 // Even if every estimate related to the main thread is slow, we should |
| 1606 // still expect to recover impl thread latency if the draw is fast and we | 1605 // still expect to recover impl thread latency if the draw is fast and we |
| 1607 // are in impl latency takes priority. | 1606 // are in impl latency takes priority. |
| 1608 scheduler_->SetTreePrioritiesAndScrollState( | 1607 scheduler_->SetTreePrioritiesAndScrollState( |
| 1609 SMOOTHNESS_TAKES_PRIORITY, | 1608 SMOOTHNESS_TAKES_PRIORITY, |
| 1610 ScrollHandlerState::SCROLL_DOES_NOT_AFFECT_SCROLL_HANDLER); | 1609 ScrollHandlerState::SCROLL_DOES_NOT_AFFECT_SCROLL_HANDLER); |
| 1611 fake_compositor_timing_history_->SetAllEstimatesTo(kSlowDuration); | 1610 fake_compositor_timing_history_->SetAllEstimatesTo(kSlowDuration); |
| 1612 fake_compositor_timing_history_->SetDrawDurationEstimate(kFastDuration); | 1611 fake_compositor_timing_history_->SetDrawDurationEstimate(kFastDuration); |
| 1613 | 1612 |
| 1614 bool swap_ack_before_deadline = false; | 1613 bool receive_ack_before_deadline = false; |
| 1615 EXPECT_SCOPED(ImplFrameSkippedAfterLateSwapAck(swap_ack_before_deadline)); | 1614 EXPECT_SCOPED(ImplFrameSkippedAfterLateAck(receive_ack_before_deadline)); |
| 1616 } | 1615 } |
| 1617 | 1616 |
| 1618 TEST_F(SchedulerTest, | 1617 TEST_F(SchedulerTest, |
| 1619 ImplFrameSkippedAfterLateSwapAck_OnlyImplSideUpdatesExpected) { | 1618 ImplFrameSkippedAfterLateAck_OnlyImplSideUpdatesExpected) { |
| 1620 // This tests that we recover impl thread latency when there are no commits. | 1619 // This tests that we recover impl thread latency when there are no commits. |
| 1621 SetUpScheduler(EXTERNAL_BFS); | 1620 SetUpScheduler(EXTERNAL_BFS); |
| 1622 | 1621 |
| 1623 // To get into a high latency state, this test disables automatic swap acks. | 1622 // To get into a high latency state, this test disables automatic swap acks. |
| 1624 client_->SetAutomaticSwapAck(false); | 1623 client_->SetAutomaticSubmitCompositorFrameAck(false); |
| 1625 | 1624 |
| 1626 // Even if every estimate related to the main thread is slow, we should | 1625 // Even if every estimate related to the main thread is slow, we should |
| 1627 // still expect to recover impl thread latency if there are no commits from | 1626 // still expect to recover impl thread latency if there are no commits from |
| 1628 // the main thread. | 1627 // the main thread. |
| 1629 fake_compositor_timing_history_->SetAllEstimatesTo(kSlowDuration); | 1628 fake_compositor_timing_history_->SetAllEstimatesTo(kSlowDuration); |
| 1630 fake_compositor_timing_history_->SetDrawDurationEstimate(kFastDuration); | 1629 fake_compositor_timing_history_->SetDrawDurationEstimate(kFastDuration); |
| 1631 | 1630 |
| 1632 // Draw and swap for first BeginFrame | 1631 // Draw and swap for first BeginFrame |
| 1633 client_->Reset(); | 1632 client_->Reset(); |
| 1634 scheduler_->SetNeedsRedraw(); | 1633 scheduler_->SetNeedsRedraw(); |
| 1635 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); | 1634 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); |
| 1636 SendNextBeginFrame(); | 1635 SendNextBeginFrame(); |
| 1637 EXPECT_ACTION("AddObserver(this)", client_, 0, 2); | 1636 EXPECT_ACTION("AddObserver(this)", client_, 0, 2); |
| 1638 EXPECT_ACTION("WillBeginImplFrame", client_, 1, 2); | 1637 EXPECT_ACTION("WillBeginImplFrame", client_, 1, 2); |
| 1639 | 1638 |
| 1640 client_->Reset(); | 1639 client_->Reset(); |
| 1641 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); | 1640 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); |
| 1642 task_runner().RunTasksWhile(client_->InsideBeginImplFrame(true)); | 1641 task_runner().RunTasksWhile(client_->InsideBeginImplFrame(true)); |
| 1643 EXPECT_SINGLE_ACTION("ScheduledActionDrawAndSwapIfPossible", client_); | 1642 EXPECT_SINGLE_ACTION("ScheduledActionDrawIfPossible", client_); |
| 1644 | 1643 |
| 1645 // Verify we skip every other frame if the swap ack consistently | 1644 // Verify we skip every other frame if the swap ack consistently |
| 1646 // comes back late. | 1645 // comes back late. |
| 1647 for (int i = 0; i < 10; i++) { | 1646 for (int i = 0; i < 10; i++) { |
| 1648 // Not calling scheduler_->DidSwapBuffersComplete() until after next | 1647 // Not calling scheduler_->DidReceiveCompositorFrameAck() until after next |
| 1649 // BeginImplFrame puts the impl thread in high latency mode. | 1648 // BeginImplFrame puts the impl thread in high latency mode. |
| 1650 client_->Reset(); | 1649 client_->Reset(); |
| 1651 scheduler_->SetNeedsRedraw(); | 1650 scheduler_->SetNeedsRedraw(); |
| 1652 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); | 1651 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); |
| 1653 SendNextBeginFrame(); | 1652 SendNextBeginFrame(); |
| 1654 // Verify that we skip the BeginImplFrame | 1653 // Verify that we skip the BeginImplFrame |
| 1655 EXPECT_NO_ACTION(client_); | 1654 EXPECT_NO_ACTION(client_); |
| 1656 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); | 1655 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); |
| 1657 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); | 1656 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); |
| 1658 | 1657 |
| 1659 // Verify that we do not perform any actions after we are no longer | 1658 // Verify that we do not perform any actions after we are no longer |
| 1660 // swap throttled. | 1659 // swap throttled. |
| 1661 client_->Reset(); | 1660 client_->Reset(); |
| 1662 scheduler_->DidSwapBuffersComplete(); | 1661 scheduler_->DidReceiveCompositorFrameAck(); |
| 1663 EXPECT_NO_ACTION(client_); | 1662 EXPECT_NO_ACTION(client_); |
| 1664 | 1663 |
| 1665 // Verify that we start the next BeginImplFrame and continue normally | 1664 // Verify that we start the next BeginImplFrame and continue normally |
| 1666 // after having just skipped a BeginImplFrame. | 1665 // after having just skipped a BeginImplFrame. |
| 1667 client_->Reset(); | 1666 client_->Reset(); |
| 1668 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); | 1667 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); |
| 1669 SendNextBeginFrame(); | 1668 SendNextBeginFrame(); |
| 1670 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 1); | 1669 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 1); |
| 1671 | 1670 |
| 1672 client_->Reset(); | 1671 client_->Reset(); |
| 1673 // Deadline should be immediate. | 1672 // Deadline should be immediate. |
| 1674 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); | 1673 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); |
| 1675 task_runner().RunUntilTime(now_src_->NowTicks()); | 1674 task_runner().RunUntilTime(now_src_->NowTicks()); |
| 1676 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); | 1675 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); |
| 1677 EXPECT_SINGLE_ACTION("ScheduledActionDrawAndSwapIfPossible", client_); | 1676 EXPECT_SINGLE_ACTION("ScheduledActionDrawIfPossible", client_); |
| 1678 } | 1677 } |
| 1679 } | 1678 } |
| 1680 | 1679 |
| 1681 void SchedulerTest::ImplFrameNotSkippedAfterLateSwapAck() { | 1680 void SchedulerTest::ImplFrameNotSkippedAfterLateAck() { |
| 1682 // To get into a high latency state, this test disables automatic swap acks. | 1681 // To get into a high latency state, this test disables automatic swap acks. |
| 1683 client_->SetAutomaticSwapAck(false); | 1682 client_->SetAutomaticSubmitCompositorFrameAck(false); |
| 1684 | 1683 |
| 1685 // Draw and swap for first BeginFrame | 1684 // Draw and swap for first BeginFrame |
| 1686 client_->Reset(); | 1685 client_->Reset(); |
| 1687 scheduler_->SetNeedsBeginMainFrame(); | 1686 scheduler_->SetNeedsBeginMainFrame(); |
| 1688 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); | 1687 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); |
| 1689 SendNextBeginFrame(); | 1688 SendNextBeginFrame(); |
| 1690 EXPECT_ACTION("AddObserver(this)", client_, 0, 3); | 1689 EXPECT_ACTION("AddObserver(this)", client_, 0, 3); |
| 1691 EXPECT_ACTION("WillBeginImplFrame", client_, 1, 3); | 1690 EXPECT_ACTION("WillBeginImplFrame", client_, 1, 3); |
| 1692 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 2, 3); | 1691 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 2, 3); |
| 1693 | 1692 |
| 1694 client_->Reset(); | 1693 client_->Reset(); |
| 1695 scheduler_->NotifyBeginMainFrameStarted(base::TimeTicks()); | 1694 scheduler_->NotifyBeginMainFrameStarted(base::TimeTicks()); |
| 1696 scheduler_->NotifyReadyToCommit(); | 1695 scheduler_->NotifyReadyToCommit(); |
| 1697 scheduler_->NotifyReadyToActivate(); | 1696 scheduler_->NotifyReadyToActivate(); |
| 1698 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); | 1697 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); |
| 1699 task_runner().RunTasksWhile(client_->InsideBeginImplFrame(true)); | 1698 task_runner().RunTasksWhile(client_->InsideBeginImplFrame(true)); |
| 1700 EXPECT_ACTION("ScheduledActionCommit", client_, 0, 3); | 1699 EXPECT_ACTION("ScheduledActionCommit", client_, 0, 3); |
| 1701 EXPECT_ACTION("ScheduledActionActivateSyncTree", client_, 1, 3); | 1700 EXPECT_ACTION("ScheduledActionActivateSyncTree", client_, 1, 3); |
| 1702 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 2, 3); | 1701 EXPECT_ACTION("ScheduledActionDrawIfPossible", client_, 2, 3); |
| 1703 | 1702 |
| 1704 // Verify impl thread consistently operates in high latency mode | 1703 // Verify impl thread consistently operates in high latency mode |
| 1705 // without skipping any frames. | 1704 // without skipping any frames. |
| 1706 for (int i = 0; i < 10; i++) { | 1705 for (int i = 0; i < 10; i++) { |
| 1707 // Not calling scheduler_->DidSwapBuffersComplete() until after next frame | 1706 // Not calling scheduler_->DidReceiveCompositorFrameAck() until after next |
| 1707 // frame | |
| 1708 // puts the impl thread in high latency mode. | 1708 // puts the impl thread in high latency mode. |
| 1709 client_->Reset(); | 1709 client_->Reset(); |
| 1710 scheduler_->SetNeedsBeginMainFrame(); | 1710 scheduler_->SetNeedsBeginMainFrame(); |
| 1711 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); | 1711 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); |
| 1712 SendNextBeginFrame(); | 1712 SendNextBeginFrame(); |
| 1713 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client_); | 1713 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client_); |
| 1714 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); | 1714 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); |
| 1715 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); | 1715 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); |
| 1716 | 1716 |
| 1717 client_->Reset(); | 1717 client_->Reset(); |
| 1718 scheduler_->DidSwapBuffersComplete(); | 1718 scheduler_->DidReceiveCompositorFrameAck(); |
| 1719 scheduler_->NotifyBeginMainFrameStarted(base::TimeTicks()); | 1719 scheduler_->NotifyBeginMainFrameStarted(base::TimeTicks()); |
| 1720 scheduler_->NotifyReadyToCommit(); | 1720 scheduler_->NotifyReadyToCommit(); |
| 1721 scheduler_->NotifyReadyToActivate(); | 1721 scheduler_->NotifyReadyToActivate(); |
| 1722 task_runner().RunTasksWhile(client_->InsideBeginImplFrame(true)); | 1722 task_runner().RunTasksWhile(client_->InsideBeginImplFrame(true)); |
| 1723 | 1723 |
| 1724 // Verify that we don't skip the actions of the BeginImplFrame | 1724 // Verify that we don't skip the actions of the BeginImplFrame |
| 1725 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 0, 4); | 1725 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 0, 4); |
| 1726 EXPECT_ACTION("ScheduledActionCommit", client_, 1, 4); | 1726 EXPECT_ACTION("ScheduledActionCommit", client_, 1, 4); |
| 1727 EXPECT_ACTION("ScheduledActionActivateSyncTree", client_, 2, 4); | 1727 EXPECT_ACTION("ScheduledActionActivateSyncTree", client_, 2, 4); |
| 1728 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 3, 4); | 1728 EXPECT_ACTION("ScheduledActionDrawIfPossible", client_, 3, 4); |
| 1729 } | 1729 } |
| 1730 } | 1730 } |
| 1731 | 1731 |
| 1732 TEST_F( | 1732 TEST_F(SchedulerTest, |
| 1733 SchedulerTest, | 1733 ImplFrameNotSkippedAfterLateAck_MainFrameQueueDurationCriticalTooLong) { |
| 1734 ImplFrameNotSkippedAfterLateSwapAck_MainFrameQueueDurationCriticalTooLong) { | |
| 1735 SetUpScheduler(EXTERNAL_BFS); | 1734 SetUpScheduler(EXTERNAL_BFS); |
| 1736 fake_compositor_timing_history_->SetAllEstimatesTo(kFastDuration); | 1735 fake_compositor_timing_history_->SetAllEstimatesTo(kFastDuration); |
| 1737 fake_compositor_timing_history_ | 1736 fake_compositor_timing_history_ |
| 1738 ->SetBeginMainFrameQueueDurationCriticalEstimate(kSlowDuration); | 1737 ->SetBeginMainFrameQueueDurationCriticalEstimate(kSlowDuration); |
| 1739 fake_compositor_timing_history_ | 1738 fake_compositor_timing_history_ |
| 1740 ->SetBeginMainFrameQueueDurationNotCriticalEstimate(kSlowDuration); | 1739 ->SetBeginMainFrameQueueDurationNotCriticalEstimate(kSlowDuration); |
| 1741 EXPECT_SCOPED(ImplFrameNotSkippedAfterLateSwapAck()); | 1740 EXPECT_SCOPED(ImplFrameNotSkippedAfterLateAck()); |
| 1742 } | 1741 } |
| 1743 | 1742 |
| 1744 TEST_F(SchedulerTest, | 1743 TEST_F(SchedulerTest, ImplFrameNotSkippedAfterLateAck_CommitEstimateTooLong) { |
| 1745 ImplFrameNotSkippedAfterLateSwapAck_CommitEstimateTooLong) { | |
| 1746 SetUpScheduler(EXTERNAL_BFS); | 1744 SetUpScheduler(EXTERNAL_BFS); |
| 1747 fake_compositor_timing_history_->SetAllEstimatesTo(kFastDuration); | 1745 fake_compositor_timing_history_->SetAllEstimatesTo(kFastDuration); |
| 1748 fake_compositor_timing_history_ | 1746 fake_compositor_timing_history_ |
| 1749 ->SetBeginMainFrameStartToCommitDurationEstimate(kSlowDuration); | 1747 ->SetBeginMainFrameStartToCommitDurationEstimate(kSlowDuration); |
| 1750 EXPECT_SCOPED(ImplFrameNotSkippedAfterLateSwapAck()); | 1748 EXPECT_SCOPED(ImplFrameNotSkippedAfterLateAck()); |
| 1751 } | 1749 } |
| 1752 | 1750 |
| 1753 TEST_F(SchedulerTest, | 1751 TEST_F(SchedulerTest, |
| 1754 ImplFrameNotSkippedAfterLateSwapAck_ReadyToActivateEstimateTooLong) { | 1752 ImplFrameNotSkippedAfterLateAck_ReadyToActivateEstimateTooLong) { |
| 1755 SetUpScheduler(EXTERNAL_BFS); | 1753 SetUpScheduler(EXTERNAL_BFS); |
| 1756 fake_compositor_timing_history_->SetAllEstimatesTo(kFastDuration); | 1754 fake_compositor_timing_history_->SetAllEstimatesTo(kFastDuration); |
| 1757 fake_compositor_timing_history_->SetCommitToReadyToActivateDurationEstimate( | 1755 fake_compositor_timing_history_->SetCommitToReadyToActivateDurationEstimate( |
| 1758 kSlowDuration); | 1756 kSlowDuration); |
| 1759 EXPECT_SCOPED(ImplFrameNotSkippedAfterLateSwapAck()); | 1757 EXPECT_SCOPED(ImplFrameNotSkippedAfterLateAck()); |
| 1760 } | 1758 } |
| 1761 | 1759 |
| 1762 TEST_F(SchedulerTest, | 1760 TEST_F(SchedulerTest, ImplFrameNotSkippedAfterLateAck_ActivateEstimateTooLong) { |
| 1763 ImplFrameNotSkippedAfterLateSwapAck_ActivateEstimateTooLong) { | |
| 1764 SetUpScheduler(EXTERNAL_BFS); | 1761 SetUpScheduler(EXTERNAL_BFS); |
| 1765 fake_compositor_timing_history_->SetAllEstimatesTo(kFastDuration); | 1762 fake_compositor_timing_history_->SetAllEstimatesTo(kFastDuration); |
| 1766 fake_compositor_timing_history_->SetActivateDurationEstimate(kSlowDuration); | 1763 fake_compositor_timing_history_->SetActivateDurationEstimate(kSlowDuration); |
| 1767 EXPECT_SCOPED(ImplFrameNotSkippedAfterLateSwapAck()); | 1764 EXPECT_SCOPED(ImplFrameNotSkippedAfterLateAck()); |
| 1768 } | 1765 } |
| 1769 | 1766 |
| 1770 TEST_F(SchedulerTest, ImplFrameNotSkippedAfterLateSwapAck_DrawEstimateTooLong) { | 1767 TEST_F(SchedulerTest, ImplFrameNotSkippedAfterLateAck_DrawEstimateTooLong) { |
| 1771 SetUpScheduler(EXTERNAL_BFS); | 1768 SetUpScheduler(EXTERNAL_BFS); |
| 1772 fake_compositor_timing_history_->SetAllEstimatesTo(kFastDuration); | 1769 fake_compositor_timing_history_->SetAllEstimatesTo(kFastDuration); |
| 1773 fake_compositor_timing_history_->SetDrawDurationEstimate(kSlowDuration); | 1770 fake_compositor_timing_history_->SetDrawDurationEstimate(kSlowDuration); |
| 1774 EXPECT_SCOPED(ImplFrameNotSkippedAfterLateSwapAck()); | 1771 EXPECT_SCOPED(ImplFrameNotSkippedAfterLateAck()); |
| 1775 } | 1772 } |
| 1776 | 1773 |
| 1777 TEST_F(SchedulerTest, | 1774 TEST_F(SchedulerTest, MainFrameThenImplFrameSkippedAfterLateCommitAndLateAck) { |
| 1778 MainFrameThenImplFrameSkippedAfterLateCommitAndLateSwapAck) { | |
| 1779 // Set up client with custom estimates. | 1775 // Set up client with custom estimates. |
| 1780 // This test starts off with expensive estimates to prevent latency recovery | 1776 // This test starts off with expensive estimates to prevent latency recovery |
| 1781 // initially, then lowers the estimates to enable it once both the main | 1777 // initially, then lowers the estimates to enable it once both the main |
| 1782 // and impl threads are in a high latency mode. | 1778 // and impl threads are in a high latency mode. |
| 1783 SetUpScheduler(EXTERNAL_BFS); | 1779 SetUpScheduler(EXTERNAL_BFS); |
| 1784 fake_compositor_timing_history_->SetAllEstimatesTo(kSlowDuration); | 1780 fake_compositor_timing_history_->SetAllEstimatesTo(kSlowDuration); |
| 1785 | 1781 |
| 1786 // To get into a high latency state, this test disables automatic swap acks. | 1782 // To get into a high latency state, this test disables automatic swap acks. |
| 1787 client_->SetAutomaticSwapAck(false); | 1783 client_->SetAutomaticSubmitCompositorFrameAck(false); |
| 1788 | 1784 |
| 1789 // Impl thread hits deadline before commit finishes to make | 1785 // Impl thread hits deadline before commit finishes to make |
| 1790 // MainThreadMissedLastDeadline true | 1786 // MainThreadMissedLastDeadline true |
| 1791 client_->Reset(); | 1787 client_->Reset(); |
| 1792 scheduler_->SetNeedsBeginMainFrame(); | 1788 scheduler_->SetNeedsBeginMainFrame(); |
| 1793 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); | 1789 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); |
| 1794 EXPECT_SCOPED(AdvanceFrame()); | 1790 EXPECT_SCOPED(AdvanceFrame()); |
| 1795 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); | 1791 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); |
| 1796 task_runner().RunTasksWhile(client_->InsideBeginImplFrame(true)); | 1792 task_runner().RunTasksWhile(client_->InsideBeginImplFrame(true)); |
| 1797 EXPECT_TRUE(scheduler_->MainThreadMissedLastDeadline()); | 1793 EXPECT_TRUE(scheduler_->MainThreadMissedLastDeadline()); |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 1812 EXPECT_TRUE(scheduler_->MainThreadMissedLastDeadline()); | 1808 EXPECT_TRUE(scheduler_->MainThreadMissedLastDeadline()); |
| 1813 EXPECT_SCOPED(AdvanceFrame()); | 1809 EXPECT_SCOPED(AdvanceFrame()); |
| 1814 EXPECT_TRUE(scheduler_->MainThreadMissedLastDeadline()); | 1810 EXPECT_TRUE(scheduler_->MainThreadMissedLastDeadline()); |
| 1815 task_runner().RunTasksWhile(client_->InsideBeginImplFrame(true)); | 1811 task_runner().RunTasksWhile(client_->InsideBeginImplFrame(true)); |
| 1816 scheduler_->NotifyBeginMainFrameStarted(base::TimeTicks()); | 1812 scheduler_->NotifyBeginMainFrameStarted(base::TimeTicks()); |
| 1817 scheduler_->NotifyReadyToCommit(); | 1813 scheduler_->NotifyReadyToCommit(); |
| 1818 scheduler_->NotifyReadyToActivate(); | 1814 scheduler_->NotifyReadyToActivate(); |
| 1819 | 1815 |
| 1820 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 5); | 1816 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 5); |
| 1821 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 5); | 1817 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 5); |
| 1822 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 2, 5); | 1818 EXPECT_ACTION("ScheduledActionDrawIfPossible", client_, 2, 5); |
| 1823 EXPECT_ACTION("ScheduledActionCommit", client_, 3, 5); | 1819 EXPECT_ACTION("ScheduledActionCommit", client_, 3, 5); |
| 1824 EXPECT_ACTION("ScheduledActionActivateSyncTree", client_, 4, 5); | 1820 EXPECT_ACTION("ScheduledActionActivateSyncTree", client_, 4, 5); |
| 1825 | 1821 |
| 1826 // Don't call scheduler_->DidSwapBuffersComplete() until after next frame | 1822 // Don't call scheduler_->DidReceiveCompositorFrameAck() until after next |
| 1823 // frame | |
| 1827 // to put the impl thread in a high latency mode. | 1824 // to put the impl thread in a high latency mode. |
| 1828 client_->Reset(); | 1825 client_->Reset(); |
| 1829 scheduler_->SetNeedsBeginMainFrame(); | 1826 scheduler_->SetNeedsBeginMainFrame(); |
| 1830 EXPECT_TRUE(scheduler_->MainThreadMissedLastDeadline()); | 1827 EXPECT_TRUE(scheduler_->MainThreadMissedLastDeadline()); |
| 1831 EXPECT_SCOPED(AdvanceFrame()); | 1828 EXPECT_SCOPED(AdvanceFrame()); |
| 1832 EXPECT_TRUE(scheduler_->MainThreadMissedLastDeadline()); | 1829 EXPECT_TRUE(scheduler_->MainThreadMissedLastDeadline()); |
| 1833 task_runner().RunTasksWhile(client_->InsideBeginImplFrame(true)); | 1830 task_runner().RunTasksWhile(client_->InsideBeginImplFrame(true)); |
| 1834 | 1831 |
| 1835 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 1); | 1832 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 1); |
| 1836 // Note: BeginMainFrame and swap are skipped here because of | 1833 // Note: BeginMainFrame and swap are skipped here because of |
| 1837 // swap ack backpressure, not because of latency recovery. | 1834 // swap ack backpressure, not because of latency recovery. |
| 1838 EXPECT_FALSE(client_->HasAction("ScheduledActionSendBeginMainFrame")); | 1835 EXPECT_FALSE(client_->HasAction("ScheduledActionSendBeginMainFrame")); |
| 1839 EXPECT_FALSE(client_->HasAction("ScheduledActionDrawAndSwapIfPossible")); | 1836 EXPECT_FALSE(client_->HasAction("ScheduledActionDrawIfPossible")); |
| 1840 EXPECT_TRUE(scheduler_->MainThreadMissedLastDeadline()); | 1837 EXPECT_TRUE(scheduler_->MainThreadMissedLastDeadline()); |
| 1841 | 1838 |
| 1842 // Lower estimates so that the scheduler will attempt latency recovery. | 1839 // Lower estimates so that the scheduler will attempt latency recovery. |
| 1843 fake_compositor_timing_history_->SetAllEstimatesTo(kFastDuration); | 1840 fake_compositor_timing_history_->SetAllEstimatesTo(kFastDuration); |
| 1844 | 1841 |
| 1845 // Now that both threads are in a high latency mode, make sure we | 1842 // Now that both threads are in a high latency mode, make sure we |
| 1846 // skip the BeginMainFrame, then the BeginImplFrame, but not both | 1843 // skip the BeginMainFrame, then the BeginImplFrame, but not both |
| 1847 // at the same time. | 1844 // at the same time. |
| 1848 | 1845 |
| 1849 // Verify we skip BeginMainFrame first. | 1846 // Verify we skip BeginMainFrame first. |
| 1850 client_->Reset(); | 1847 client_->Reset(); |
| 1851 // Previous commit request is still outstanding. | 1848 // Previous commit request is still outstanding. |
| 1852 EXPECT_TRUE(scheduler_->NeedsBeginMainFrame()); | 1849 EXPECT_TRUE(scheduler_->NeedsBeginMainFrame()); |
| 1853 EXPECT_TRUE(scheduler_->SwapThrottled()); | 1850 EXPECT_TRUE(scheduler_->IsDrawThrottled()); |
| 1854 SendNextBeginFrame(); | 1851 SendNextBeginFrame(); |
| 1855 EXPECT_TRUE(scheduler_->MainThreadMissedLastDeadline()); | 1852 EXPECT_TRUE(scheduler_->MainThreadMissedLastDeadline()); |
| 1856 scheduler_->DidSwapBuffersComplete(); | 1853 scheduler_->DidReceiveCompositorFrameAck(); |
| 1857 task_runner().RunTasksWhile(client_->InsideBeginImplFrame(true)); | 1854 task_runner().RunTasksWhile(client_->InsideBeginImplFrame(true)); |
| 1858 | 1855 |
| 1859 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); | 1856 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); |
| 1860 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); | 1857 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
| 1861 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 1, 2); | 1858 EXPECT_ACTION("ScheduledActionDrawIfPossible", client_, 1, 2); |
| 1862 | 1859 |
| 1863 // Verify we skip the BeginImplFrame second. | 1860 // Verify we skip the BeginImplFrame second. |
| 1864 client_->Reset(); | 1861 client_->Reset(); |
| 1865 // Previous commit request is still outstanding. | 1862 // Previous commit request is still outstanding. |
| 1866 EXPECT_TRUE(scheduler_->NeedsBeginMainFrame()); | 1863 EXPECT_TRUE(scheduler_->NeedsBeginMainFrame()); |
| 1867 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); | 1864 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); |
| 1868 SendNextBeginFrame(); | 1865 SendNextBeginFrame(); |
| 1869 task_runner().RunTasksWhile(client_->InsideBeginImplFrame(true)); | 1866 task_runner().RunTasksWhile(client_->InsideBeginImplFrame(true)); |
| 1870 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); | 1867 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); |
| 1871 scheduler_->DidSwapBuffersComplete(); | 1868 scheduler_->DidReceiveCompositorFrameAck(); |
| 1872 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); | 1869 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); |
| 1873 | 1870 |
| 1874 EXPECT_NO_ACTION(client_); | 1871 EXPECT_NO_ACTION(client_); |
| 1875 | 1872 |
| 1876 // Then verify we operate in a low latency mode. | 1873 // Then verify we operate in a low latency mode. |
| 1877 client_->Reset(); | 1874 client_->Reset(); |
| 1878 // Previous commit request is still outstanding. | 1875 // Previous commit request is still outstanding. |
| 1879 EXPECT_TRUE(scheduler_->NeedsBeginMainFrame()); | 1876 EXPECT_TRUE(scheduler_->NeedsBeginMainFrame()); |
| 1880 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); | 1877 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); |
| 1881 SendNextBeginFrame(); | 1878 SendNextBeginFrame(); |
| 1882 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); | 1879 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); |
| 1883 scheduler_->NotifyBeginMainFrameStarted(base::TimeTicks()); | 1880 scheduler_->NotifyBeginMainFrameStarted(base::TimeTicks()); |
| 1884 scheduler_->NotifyReadyToCommit(); | 1881 scheduler_->NotifyReadyToCommit(); |
| 1885 scheduler_->NotifyReadyToActivate(); | 1882 scheduler_->NotifyReadyToActivate(); |
| 1886 task_runner().RunTasksWhile(client_->InsideBeginImplFrame(true)); | 1883 task_runner().RunTasksWhile(client_->InsideBeginImplFrame(true)); |
| 1887 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); | 1884 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); |
| 1888 scheduler_->DidSwapBuffersComplete(); | 1885 scheduler_->DidReceiveCompositorFrameAck(); |
| 1889 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); | 1886 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); |
| 1890 | 1887 |
| 1891 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 5); | 1888 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 5); |
| 1892 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 5); | 1889 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 5); |
| 1893 EXPECT_ACTION("ScheduledActionCommit", client_, 2, 5); | 1890 EXPECT_ACTION("ScheduledActionCommit", client_, 2, 5); |
| 1894 EXPECT_ACTION("ScheduledActionActivateSyncTree", client_, 3, 5); | 1891 EXPECT_ACTION("ScheduledActionActivateSyncTree", client_, 3, 5); |
| 1895 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 4, 5); | 1892 EXPECT_ACTION("ScheduledActionDrawIfPossible", client_, 4, 5); |
| 1896 } | 1893 } |
| 1897 | 1894 |
| 1898 TEST_F( | 1895 TEST_F( |
| 1899 SchedulerTest, | 1896 SchedulerTest, |
| 1900 Deadlock_CommitMakesProgressWhileSwapTrottledAndActiveTreeNeedsFirstDraw) { | 1897 Deadlock_CommitMakesProgressWhileSwapTrottledAndActiveTreeNeedsFirstDraw) { |
| 1901 // NPAPI plugins on Windows block the Browser UI thread on the Renderer main | 1898 // 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. | 1899 // thread. This prevents the scheduler from receiving any pending swap acks. |
| 1903 | 1900 |
| 1904 scheduler_settings_.main_frame_while_swap_throttled_enabled = true; | 1901 scheduler_settings_.main_frame_while_submit_frame_throttled_enabled = true; |
| 1905 SetUpScheduler(EXTERNAL_BFS); | 1902 SetUpScheduler(EXTERNAL_BFS); |
| 1906 | 1903 |
| 1907 // Disables automatic swap acks so this test can force swap ack throttling | 1904 // Disables automatic swap acks so this test can force swap ack throttling |
| 1908 // to simulate a blocked Browser ui thread. | 1905 // to simulate a blocked Browser ui thread. |
| 1909 client_->SetAutomaticSwapAck(false); | 1906 client_->SetAutomaticSubmitCompositorFrameAck(false); |
| 1910 | 1907 |
| 1911 // Get a new active tree in main-thread high latency mode and put us | 1908 // Get a new active tree in main-thread high latency mode and put us |
| 1912 // in a swap throttled state. | 1909 // in a swap throttled state. |
| 1913 client_->Reset(); | 1910 client_->Reset(); |
| 1914 EXPECT_FALSE(scheduler_->CommitPending()); | 1911 EXPECT_FALSE(scheduler_->CommitPending()); |
| 1915 scheduler_->SetNeedsBeginMainFrame(); | 1912 scheduler_->SetNeedsBeginMainFrame(); |
| 1916 scheduler_->SetNeedsRedraw(); | 1913 scheduler_->SetNeedsRedraw(); |
| 1917 EXPECT_SCOPED(AdvanceFrame()); | 1914 EXPECT_SCOPED(AdvanceFrame()); |
| 1918 EXPECT_TRUE(scheduler_->CommitPending()); | 1915 EXPECT_TRUE(scheduler_->CommitPending()); |
| 1919 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); | 1916 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); |
| 1920 task_runner().RunTasksWhile(client_->InsideBeginImplFrame(true)); | 1917 task_runner().RunTasksWhile(client_->InsideBeginImplFrame(true)); |
| 1921 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); | 1918 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); |
| 1922 scheduler_->NotifyBeginMainFrameStarted(base::TimeTicks()); | 1919 scheduler_->NotifyBeginMainFrameStarted(base::TimeTicks()); |
| 1923 scheduler_->NotifyReadyToCommit(); | 1920 scheduler_->NotifyReadyToCommit(); |
| 1924 scheduler_->NotifyReadyToActivate(); | 1921 scheduler_->NotifyReadyToActivate(); |
| 1925 EXPECT_FALSE(scheduler_->CommitPending()); | 1922 EXPECT_FALSE(scheduler_->CommitPending()); |
| 1926 EXPECT_ACTION("AddObserver(this)", client_, 0, 6); | 1923 EXPECT_ACTION("AddObserver(this)", client_, 0, 6); |
| 1927 EXPECT_ACTION("WillBeginImplFrame", client_, 1, 6); | 1924 EXPECT_ACTION("WillBeginImplFrame", client_, 1, 6); |
| 1928 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 2, 6); | 1925 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 2, 6); |
| 1929 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 3, 6); | 1926 EXPECT_ACTION("ScheduledActionDrawIfPossible", client_, 3, 6); |
| 1930 EXPECT_ACTION("ScheduledActionCommit", client_, 4, 6); | 1927 EXPECT_ACTION("ScheduledActionCommit", client_, 4, 6); |
| 1931 EXPECT_ACTION("ScheduledActionActivateSyncTree", client_, 5, 6); | 1928 EXPECT_ACTION("ScheduledActionActivateSyncTree", client_, 5, 6); |
| 1932 | 1929 |
| 1933 // Make sure that we can finish the next commit even while swap throttled. | 1930 // Make sure that we can finish the next commit even while swap throttled. |
| 1934 client_->Reset(); | 1931 client_->Reset(); |
| 1935 EXPECT_FALSE(scheduler_->CommitPending()); | 1932 EXPECT_FALSE(scheduler_->CommitPending()); |
| 1936 scheduler_->SetNeedsBeginMainFrame(); | 1933 scheduler_->SetNeedsBeginMainFrame(); |
| 1937 EXPECT_SCOPED(AdvanceFrame()); | 1934 EXPECT_SCOPED(AdvanceFrame()); |
| 1938 scheduler_->NotifyBeginMainFrameStarted(base::TimeTicks()); | 1935 scheduler_->NotifyBeginMainFrameStarted(base::TimeTicks()); |
| 1939 scheduler_->NotifyReadyToCommit(); | 1936 scheduler_->NotifyReadyToCommit(); |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 1957 } | 1954 } |
| 1958 | 1955 |
| 1959 TEST_F( | 1956 TEST_F( |
| 1960 SchedulerTest, | 1957 SchedulerTest, |
| 1961 CommitMakesProgressWhenIdleAndHasPendingTreeAndActiveTreeNeedsFirstDraw) { | 1958 CommitMakesProgressWhenIdleAndHasPendingTreeAndActiveTreeNeedsFirstDraw) { |
| 1962 // This verifies we don't block commits longer than we need to | 1959 // This verifies we don't block commits longer than we need to |
| 1963 // for performance reasons - not deadlock reasons. | 1960 // for performance reasons - not deadlock reasons. |
| 1964 | 1961 |
| 1965 // Since we are simulating a long commit, set up a client with draw duration | 1962 // 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. | 1963 // estimates that prevent skipping main frames to get to low latency mode. |
| 1967 scheduler_settings_.main_frame_while_swap_throttled_enabled = true; | 1964 scheduler_settings_.main_frame_while_submit_frame_throttled_enabled = true; |
| 1968 scheduler_settings_.main_frame_before_activation_enabled = true; | 1965 scheduler_settings_.main_frame_before_activation_enabled = true; |
| 1969 SetUpScheduler(EXTERNAL_BFS); | 1966 SetUpScheduler(EXTERNAL_BFS); |
| 1970 | 1967 |
| 1971 // Disables automatic swap acks so this test can force swap ack throttling | 1968 // Disables automatic swap acks so this test can force swap ack throttling |
| 1972 // to simulate a blocked Browser ui thread. | 1969 // to simulate a blocked Browser ui thread. |
| 1973 client_->SetAutomaticSwapAck(false); | 1970 client_->SetAutomaticSubmitCompositorFrameAck(false); |
| 1974 | 1971 |
| 1975 // Start a new commit in main-thread high latency mode and hold off on | 1972 // Start a new commit in main-thread high latency mode and hold off on |
| 1976 // activation. | 1973 // activation. |
| 1977 client_->Reset(); | 1974 client_->Reset(); |
| 1978 EXPECT_FALSE(scheduler_->CommitPending()); | 1975 EXPECT_FALSE(scheduler_->CommitPending()); |
| 1979 scheduler_->SetNeedsBeginMainFrame(); | 1976 scheduler_->SetNeedsBeginMainFrame(); |
| 1980 scheduler_->SetNeedsRedraw(); | 1977 scheduler_->SetNeedsRedraw(); |
| 1981 EXPECT_SCOPED(AdvanceFrame()); | 1978 EXPECT_SCOPED(AdvanceFrame()); |
| 1982 EXPECT_TRUE(scheduler_->CommitPending()); | 1979 EXPECT_TRUE(scheduler_->CommitPending()); |
| 1983 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); | 1980 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); |
| 1984 task_runner().RunTasksWhile(client_->InsideBeginImplFrame(true)); | 1981 task_runner().RunTasksWhile(client_->InsideBeginImplFrame(true)); |
| 1985 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); | 1982 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); |
| 1986 scheduler_->DidSwapBuffersComplete(); | 1983 scheduler_->DidReceiveCompositorFrameAck(); |
| 1987 scheduler_->NotifyBeginMainFrameStarted(base::TimeTicks()); | 1984 scheduler_->NotifyBeginMainFrameStarted(base::TimeTicks()); |
| 1988 scheduler_->NotifyReadyToCommit(); | 1985 scheduler_->NotifyReadyToCommit(); |
| 1989 EXPECT_FALSE(scheduler_->CommitPending()); | 1986 EXPECT_FALSE(scheduler_->CommitPending()); |
| 1990 EXPECT_ACTION("AddObserver(this)", client_, 0, 5); | 1987 EXPECT_ACTION("AddObserver(this)", client_, 0, 5); |
| 1991 EXPECT_ACTION("WillBeginImplFrame", client_, 1, 5); | 1988 EXPECT_ACTION("WillBeginImplFrame", client_, 1, 5); |
| 1992 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 2, 5); | 1989 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 2, 5); |
| 1993 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 3, 5); | 1990 EXPECT_ACTION("ScheduledActionDrawIfPossible", client_, 3, 5); |
| 1994 EXPECT_ACTION("ScheduledActionCommit", client_, 4, 5); | 1991 EXPECT_ACTION("ScheduledActionCommit", client_, 4, 5); |
| 1995 | 1992 |
| 1996 // Start another commit while we still have an active tree. | 1993 // Start another commit while we still have an active tree. |
| 1997 client_->Reset(); | 1994 client_->Reset(); |
| 1998 EXPECT_FALSE(scheduler_->CommitPending()); | 1995 EXPECT_FALSE(scheduler_->CommitPending()); |
| 1999 scheduler_->SetNeedsBeginMainFrame(); | 1996 scheduler_->SetNeedsBeginMainFrame(); |
| 2000 scheduler_->SetNeedsRedraw(); | 1997 scheduler_->SetNeedsRedraw(); |
| 2001 EXPECT_SCOPED(AdvanceFrame()); | 1998 EXPECT_SCOPED(AdvanceFrame()); |
| 2002 EXPECT_TRUE(scheduler_->CommitPending()); | 1999 EXPECT_TRUE(scheduler_->CommitPending()); |
| 2003 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); | 2000 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); |
| 2004 task_runner().RunTasksWhile(client_->InsideBeginImplFrame(true)); | 2001 task_runner().RunTasksWhile(client_->InsideBeginImplFrame(true)); |
| 2005 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); | 2002 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); |
| 2006 scheduler_->DidSwapBuffersComplete(); | 2003 scheduler_->DidReceiveCompositorFrameAck(); |
| 2007 scheduler_->NotifyBeginMainFrameStarted(base::TimeTicks()); | 2004 scheduler_->NotifyBeginMainFrameStarted(base::TimeTicks()); |
| 2008 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 3); | 2005 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 3); |
| 2009 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 3); | 2006 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 3); |
| 2010 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 2, 3); | 2007 EXPECT_ACTION("ScheduledActionDrawIfPossible", client_, 2, 3); |
| 2011 | 2008 |
| 2012 // Can't commit yet because there's still a pending tree. | 2009 // Can't commit yet because there's still a pending tree. |
| 2013 client_->Reset(); | 2010 client_->Reset(); |
| 2014 scheduler_->NotifyReadyToCommit(); | 2011 scheduler_->NotifyReadyToCommit(); |
| 2015 EXPECT_NO_ACTION(client_); | 2012 EXPECT_NO_ACTION(client_); |
| 2016 | 2013 |
| 2017 // Activate the pending tree, which also unblocks the commit immediately | 2014 // Activate the pending tree, which also unblocks the commit immediately |
| 2018 // while we are in an idle state. | 2015 // while we are in an idle state. |
| 2019 client_->Reset(); | 2016 client_->Reset(); |
| 2020 scheduler_->NotifyReadyToActivate(); | 2017 scheduler_->NotifyReadyToActivate(); |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 2051 client_->Reset(); | 2048 client_->Reset(); |
| 2052 | 2049 |
| 2053 // NotifyReadyToActivate should trigger the activation. | 2050 // NotifyReadyToActivate should trigger the activation. |
| 2054 scheduler_->NotifyReadyToActivate(); | 2051 scheduler_->NotifyReadyToActivate(); |
| 2055 EXPECT_SINGLE_ACTION("ScheduledActionActivateSyncTree", client_); | 2052 EXPECT_SINGLE_ACTION("ScheduledActionActivateSyncTree", client_); |
| 2056 client_->Reset(); | 2053 client_->Reset(); |
| 2057 | 2054 |
| 2058 // BeginImplFrame deadline should draw. The following BeginImplFrame deadline | 2055 // BeginImplFrame deadline should draw. The following BeginImplFrame deadline |
| 2059 // should SetNeedsBeginFrame(false) to avoid excessive toggles. | 2056 // should SetNeedsBeginFrame(false) to avoid excessive toggles. |
| 2060 EXPECT_SCOPED(AdvanceFrame()); | 2057 EXPECT_SCOPED(AdvanceFrame()); |
| 2061 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 0, 2); | 2058 EXPECT_ACTION("ScheduledActionDrawIfPossible", client_, 0, 2); |
| 2062 EXPECT_ACTION("WillBeginImplFrame", client_, 1, 2); | 2059 EXPECT_ACTION("WillBeginImplFrame", client_, 1, 2); |
| 2063 client_->Reset(); | 2060 client_->Reset(); |
| 2064 | 2061 |
| 2065 // Make sure SetNeedsBeginFrame isn't called on the client | 2062 // Make sure SetNeedsBeginFrame isn't called on the client |
| 2066 // when the BeginFrame is no longer needed. | 2063 // when the BeginFrame is no longer needed. |
| 2067 task_runner().RunPendingTasks(); // Run posted deadline. | 2064 task_runner().RunPendingTasks(); // Run posted deadline. |
| 2068 EXPECT_SINGLE_ACTION("SendBeginMainFrameNotExpectedSoon", client_); | 2065 EXPECT_SINGLE_ACTION("SendBeginMainFrameNotExpectedSoon", client_); |
| 2069 client_->Reset(); | 2066 client_->Reset(); |
| 2070 } | 2067 } |
| 2071 | 2068 |
| 2072 TEST_F(SchedulerTest, SyntheticBeginFrames) { | 2069 TEST_F(SchedulerTest, SyntheticBeginFrames) { |
| 2073 BeginFramesNotFromClient(THROTTLED_BFS); | 2070 BeginFramesNotFromClient(THROTTLED_BFS); |
| 2074 } | 2071 } |
| 2075 | 2072 |
| 2076 TEST_F(SchedulerTest, UnthrottledBeginFrames) { | 2073 TEST_F(SchedulerTest, UnthrottledBeginFrames) { |
| 2077 BeginFramesNotFromClient(UNTHROTTLED_BFS); | 2074 BeginFramesNotFromClient(UNTHROTTLED_BFS); |
| 2078 } | 2075 } |
| 2079 | 2076 |
| 2080 void SchedulerTest::BeginFramesNotFromClient_SwapThrottled( | 2077 void SchedulerTest::BeginFramesNotFromClient_IsDrawThrottled( |
| 2081 BeginFrameSourceType bfs_type) { | 2078 BeginFrameSourceType bfs_type) { |
| 2082 SetUpScheduler(bfs_type); | 2079 SetUpScheduler(bfs_type); |
| 2083 | 2080 |
| 2084 // Set the draw duration estimate to zero so that deadlines are accurate. | 2081 // Set the draw duration estimate to zero so that deadlines are accurate. |
| 2085 fake_compositor_timing_history_->SetDrawDurationEstimate(base::TimeDelta()); | 2082 fake_compositor_timing_history_->SetDrawDurationEstimate(base::TimeDelta()); |
| 2086 | 2083 |
| 2087 // To test swap ack throttling, this test disables automatic swap acks. | 2084 // To test swap ack throttling, this test disables automatic swap acks. |
| 2088 client_->SetAutomaticSwapAck(false); | 2085 client_->SetAutomaticSubmitCompositorFrameAck(false); |
| 2089 | 2086 |
| 2090 // SetNeedsBeginMainFrame should begin the frame on the next BeginImplFrame. | 2087 // SetNeedsBeginMainFrame should begin the frame on the next BeginImplFrame. |
| 2091 client_->Reset(); | 2088 client_->Reset(); |
| 2092 scheduler_->SetNeedsBeginMainFrame(); | 2089 scheduler_->SetNeedsBeginMainFrame(); |
| 2093 EXPECT_NO_ACTION(client_); | 2090 EXPECT_NO_ACTION(client_); |
| 2094 client_->Reset(); | 2091 client_->Reset(); |
| 2095 | 2092 |
| 2096 // Trigger the first BeginImplFrame and BeginMainFrame | 2093 // Trigger the first BeginImplFrame and BeginMainFrame |
| 2097 EXPECT_SCOPED(AdvanceFrame()); | 2094 EXPECT_SCOPED(AdvanceFrame()); |
| 2098 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); | 2095 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
| 2099 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); | 2096 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); |
| 2100 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); | 2097 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); |
| 2101 client_->Reset(); | 2098 client_->Reset(); |
| 2102 | 2099 |
| 2103 // NotifyReadyToCommit should trigger the pending commit. | 2100 // NotifyReadyToCommit should trigger the pending commit. |
| 2104 scheduler_->NotifyBeginMainFrameStarted(base::TimeTicks()); | 2101 scheduler_->NotifyBeginMainFrameStarted(base::TimeTicks()); |
| 2105 scheduler_->NotifyReadyToCommit(); | 2102 scheduler_->NotifyReadyToCommit(); |
| 2106 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_); | 2103 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_); |
| 2107 client_->Reset(); | 2104 client_->Reset(); |
| 2108 | 2105 |
| 2109 // NotifyReadyToActivate should trigger the activation and draw. | 2106 // NotifyReadyToActivate should trigger the activation and draw. |
| 2110 scheduler_->NotifyReadyToActivate(); | 2107 scheduler_->NotifyReadyToActivate(); |
| 2111 EXPECT_SINGLE_ACTION("ScheduledActionActivateSyncTree", client_); | 2108 EXPECT_SINGLE_ACTION("ScheduledActionActivateSyncTree", client_); |
| 2112 client_->Reset(); | 2109 client_->Reset(); |
| 2113 | 2110 |
| 2114 // Swapping will put us into a swap throttled state. | 2111 // Swapping will put us into a swap throttled state. |
| 2115 // Run posted deadline. | 2112 // Run posted deadline. |
| 2116 task_runner().RunTasksWhile(client_->InsideBeginImplFrame(true)); | 2113 task_runner().RunTasksWhile(client_->InsideBeginImplFrame(true)); |
| 2117 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 0, 1); | 2114 EXPECT_ACTION("ScheduledActionDrawIfPossible", client_, 0, 1); |
| 2118 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); | 2115 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); |
| 2119 client_->Reset(); | 2116 client_->Reset(); |
| 2120 | 2117 |
| 2121 // While swap throttled, BeginFrames should trigger BeginImplFrames, | 2118 // While swap throttled, BeginFrames should trigger BeginImplFrames, |
| 2122 // but not a BeginMainFrame or draw. | 2119 // but not a BeginMainFrame or draw. |
| 2123 scheduler_->SetNeedsBeginMainFrame(); | 2120 scheduler_->SetNeedsBeginMainFrame(); |
| 2124 scheduler_->SetNeedsRedraw(); | 2121 scheduler_->SetNeedsRedraw(); |
| 2125 EXPECT_SCOPED(AdvanceFrame()); // Run posted BeginFrame. | 2122 EXPECT_SCOPED(AdvanceFrame()); // Run posted BeginFrame. |
| 2126 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 1); | 2123 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 1); |
| 2127 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); | 2124 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 2140 before_deadline + BeginFrameArgs::DefaultInterval()); | 2137 before_deadline + BeginFrameArgs::DefaultInterval()); |
| 2141 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); | 2138 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); |
| 2142 client_->Reset(); | 2139 client_->Reset(); |
| 2143 | 2140 |
| 2144 EXPECT_SCOPED(AdvanceFrame()); // Run posted BeginFrame. | 2141 EXPECT_SCOPED(AdvanceFrame()); // Run posted BeginFrame. |
| 2145 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 1); | 2142 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 1); |
| 2146 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); | 2143 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); |
| 2147 client_->Reset(); | 2144 client_->Reset(); |
| 2148 | 2145 |
| 2149 // Take us out of a swap throttled state. | 2146 // Take us out of a swap throttled state. |
| 2150 scheduler_->DidSwapBuffersComplete(); | 2147 scheduler_->DidReceiveCompositorFrameAck(); |
| 2151 EXPECT_SINGLE_ACTION("ScheduledActionSendBeginMainFrame", client_); | 2148 EXPECT_SINGLE_ACTION("ScheduledActionSendBeginMainFrame", client_); |
| 2152 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); | 2149 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); |
| 2153 client_->Reset(); | 2150 client_->Reset(); |
| 2154 | 2151 |
| 2155 // The deadline is set to the regular deadline. | 2152 // The deadline is set to the regular deadline. |
| 2156 before_deadline = now_src()->NowTicks(); | 2153 before_deadline = now_src()->NowTicks(); |
| 2157 task_runner().RunTasksWhile(client_->InsideBeginImplFrame(true)); | 2154 task_runner().RunTasksWhile(client_->InsideBeginImplFrame(true)); |
| 2158 after_deadline = now_src()->NowTicks(); | 2155 after_deadline = now_src()->NowTicks(); |
| 2159 // We can't do an equality comparison here because the scheduler uses a fudge | 2156 // We can't do an equality comparison here because the scheduler uses a fudge |
| 2160 // factor that's an internal implementation detail. | 2157 // factor that's an internal implementation detail. |
| 2161 EXPECT_GT(after_deadline, before_deadline); | 2158 EXPECT_GT(after_deadline, before_deadline); |
| 2162 EXPECT_LT(after_deadline, | 2159 EXPECT_LT(after_deadline, |
| 2163 before_deadline + BeginFrameArgs::DefaultInterval()); | 2160 before_deadline + BeginFrameArgs::DefaultInterval()); |
| 2164 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); | 2161 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); |
| 2165 client_->Reset(); | 2162 client_->Reset(); |
| 2166 } | 2163 } |
| 2167 | 2164 |
| 2168 TEST_F(SchedulerTest, SyntheticBeginFrames_SwapThrottled) { | 2165 TEST_F(SchedulerTest, SyntheticBeginFrames_IsDrawThrottled) { |
| 2169 BeginFramesNotFromClient_SwapThrottled(THROTTLED_BFS); | 2166 BeginFramesNotFromClient_IsDrawThrottled(THROTTLED_BFS); |
| 2170 } | 2167 } |
| 2171 | 2168 |
| 2172 TEST_F(SchedulerTest, UnthrottledBeginFrames_SwapThrottled) { | 2169 TEST_F(SchedulerTest, UnthrottledBeginFrames_IsDrawThrottled) { |
| 2173 BeginFramesNotFromClient_SwapThrottled(UNTHROTTLED_BFS); | 2170 BeginFramesNotFromClient_IsDrawThrottled(UNTHROTTLED_BFS); |
| 2174 } | 2171 } |
| 2175 | 2172 |
| 2176 TEST_F(SchedulerTest, | 2173 TEST_F(SchedulerTest, |
| 2177 DidLoseCompositorFrameSinkAfterCompositorFrameSinkIsInitialized) { | 2174 DidLoseCompositorFrameSinkAfterCompositorFrameSinkIsInitialized) { |
| 2178 SetUpSchedulerWithNoCompositorFrameSink(EXTERNAL_BFS); | 2175 SetUpSchedulerWithNoCompositorFrameSink(EXTERNAL_BFS); |
| 2179 | 2176 |
| 2180 scheduler_->SetVisible(true); | 2177 scheduler_->SetVisible(true); |
| 2181 scheduler_->SetCanDraw(true); | 2178 scheduler_->SetCanDraw(true); |
| 2182 | 2179 |
| 2183 EXPECT_SINGLE_ACTION("ScheduledActionBeginCompositorFrameSinkCreation", | 2180 EXPECT_SINGLE_ACTION("ScheduledActionBeginCompositorFrameSinkCreation", |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2387 scheduler_->NotifyBeginMainFrameStarted(base::TimeTicks()); | 2384 scheduler_->NotifyBeginMainFrameStarted(base::TimeTicks()); |
| 2388 scheduler_->NotifyReadyToCommit(); | 2385 scheduler_->NotifyReadyToCommit(); |
| 2389 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_); | 2386 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_); |
| 2390 | 2387 |
| 2391 client_->Reset(); | 2388 client_->Reset(); |
| 2392 scheduler_->NotifyReadyToActivate(); | 2389 scheduler_->NotifyReadyToActivate(); |
| 2393 EXPECT_SINGLE_ACTION("ScheduledActionActivateSyncTree", client_); | 2390 EXPECT_SINGLE_ACTION("ScheduledActionActivateSyncTree", client_); |
| 2394 | 2391 |
| 2395 client_->Reset(); | 2392 client_->Reset(); |
| 2396 task_runner().RunTasksWhile(client_->InsideBeginImplFrame(true)); | 2393 task_runner().RunTasksWhile(client_->InsideBeginImplFrame(true)); |
| 2397 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 0, 1); | 2394 EXPECT_ACTION("ScheduledActionDrawIfPossible", client_, 0, 1); |
| 2398 | 2395 |
| 2399 // Idle time between BeginFrames. | 2396 // Idle time between BeginFrames. |
| 2400 client_->Reset(); | 2397 client_->Reset(); |
| 2401 scheduler_->DidLoseCompositorFrameSink(); | 2398 scheduler_->DidLoseCompositorFrameSink(); |
| 2402 EXPECT_ACTION("ScheduledActionBeginCompositorFrameSinkCreation", client_, 0, | 2399 EXPECT_ACTION("ScheduledActionBeginCompositorFrameSinkCreation", client_, 0, |
| 2403 3); | 2400 3); |
| 2404 EXPECT_ACTION("RemoveObserver(this)", client_, 1, 3); | 2401 EXPECT_ACTION("RemoveObserver(this)", client_, 1, 3); |
| 2405 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 2, 3); | 2402 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 2, 3); |
| 2406 } | 2403 } |
| 2407 | 2404 |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2469 scheduler_->SetNeedsRedraw(); | 2466 scheduler_->SetNeedsRedraw(); |
| 2470 EXPECT_SINGLE_ACTION("AddObserver(this)", client_); | 2467 EXPECT_SINGLE_ACTION("AddObserver(this)", client_); |
| 2471 client_->Reset(); | 2468 client_->Reset(); |
| 2472 | 2469 |
| 2473 EXPECT_SCOPED(AdvanceFrame()); | 2470 EXPECT_SCOPED(AdvanceFrame()); |
| 2474 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 1); | 2471 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 1); |
| 2475 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); | 2472 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); |
| 2476 EXPECT_TRUE(scheduler_->begin_frames_expected()); | 2473 EXPECT_TRUE(scheduler_->begin_frames_expected()); |
| 2477 client_->Reset(); | 2474 client_->Reset(); |
| 2478 task_runner().RunPendingTasks(); // Run posted deadline. | 2475 task_runner().RunPendingTasks(); // Run posted deadline. |
| 2479 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 0, 1); | 2476 EXPECT_ACTION("ScheduledActionDrawIfPossible", client_, 0, 1); |
| 2480 scheduler_->SetNeedsRedraw(); | 2477 scheduler_->SetNeedsRedraw(); |
| 2481 | 2478 |
| 2482 // Switch to an unthrottled frame source. | 2479 // Switch to an unthrottled frame source. |
| 2483 scheduler_->SetBeginFrameSource(unthrottled_frame_source_.get()); | 2480 scheduler_->SetBeginFrameSource(unthrottled_frame_source_.get()); |
| 2484 client_->Reset(); | 2481 client_->Reset(); |
| 2485 | 2482 |
| 2486 // Unthrottled frame source will immediately begin a new frame. | 2483 // Unthrottled frame source will immediately begin a new frame. |
| 2487 task_runner().RunPendingTasks(); // Run posted BeginFrame. | 2484 task_runner().RunPendingTasks(); // Run posted BeginFrame. |
| 2488 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 1); | 2485 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 1); |
| 2489 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); | 2486 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); |
| 2490 client_->Reset(); | 2487 client_->Reset(); |
| 2491 | 2488 |
| 2492 // If we don't swap on the deadline, we wait for the next BeginFrame. | 2489 // If we don't swap on the deadline, we wait for the next BeginFrame. |
| 2493 task_runner().RunPendingTasks(); // Run posted deadline. | 2490 task_runner().RunPendingTasks(); // Run posted deadline. |
| 2494 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 0, 1); | 2491 EXPECT_ACTION("ScheduledActionDrawIfPossible", client_, 0, 1); |
| 2495 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); | 2492 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); |
| 2496 client_->Reset(); | 2493 client_->Reset(); |
| 2497 } | 2494 } |
| 2498 | 2495 |
| 2499 // Tests to ensure frame sources can be successfully changed while a frame | 2496 // Tests to ensure frame sources can be successfully changed while a frame |
| 2500 // deadline is pending. | 2497 // deadline is pending. |
| 2501 TEST_F(SchedulerTest, SwitchFrameSourceToUnthrottledBeforeDeadline) { | 2498 TEST_F(SchedulerTest, SwitchFrameSourceToUnthrottledBeforeDeadline) { |
| 2502 SetUpScheduler(EXTERNAL_BFS); | 2499 SetUpScheduler(EXTERNAL_BFS); |
| 2503 | 2500 |
| 2504 // SetNeedsRedraw should begin the frame on the next BeginImplFrame. | 2501 // SetNeedsRedraw should begin the frame on the next BeginImplFrame. |
| 2505 scheduler_->SetNeedsRedraw(); | 2502 scheduler_->SetNeedsRedraw(); |
| 2506 EXPECT_SINGLE_ACTION("AddObserver(this)", client_); | 2503 EXPECT_SINGLE_ACTION("AddObserver(this)", client_); |
| 2507 client_->Reset(); | 2504 client_->Reset(); |
| 2508 | 2505 |
| 2509 EXPECT_SCOPED(AdvanceFrame()); | 2506 EXPECT_SCOPED(AdvanceFrame()); |
| 2510 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client_); | 2507 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client_); |
| 2511 | 2508 |
| 2512 // Switch to an unthrottled frame source before the frame deadline is hit. | 2509 // Switch to an unthrottled frame source before the frame deadline is hit. |
| 2513 scheduler_->SetBeginFrameSource(unthrottled_frame_source_.get()); | 2510 scheduler_->SetBeginFrameSource(unthrottled_frame_source_.get()); |
| 2514 client_->Reset(); | 2511 client_->Reset(); |
| 2515 | 2512 |
| 2516 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); | 2513 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); |
| 2517 EXPECT_TRUE(scheduler_->begin_frames_expected()); | 2514 EXPECT_TRUE(scheduler_->begin_frames_expected()); |
| 2518 client_->Reset(); | 2515 client_->Reset(); |
| 2519 | 2516 |
| 2520 task_runner().RunPendingTasks(); // Run posted deadline. | 2517 task_runner().RunPendingTasks(); // Run posted deadline. |
| 2521 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 0, 2); | 2518 EXPECT_ACTION("ScheduledActionDrawIfPossible", client_, 0, 2); |
| 2522 // Unthrottled frame source will immediately begin a new frame. | 2519 // Unthrottled frame source will immediately begin a new frame. |
| 2523 EXPECT_ACTION("WillBeginImplFrame", client_, 1, 2); | 2520 EXPECT_ACTION("WillBeginImplFrame", client_, 1, 2); |
| 2524 scheduler_->SetNeedsRedraw(); | 2521 scheduler_->SetNeedsRedraw(); |
| 2525 client_->Reset(); | 2522 client_->Reset(); |
| 2526 | 2523 |
| 2527 task_runner().RunPendingTasks(); // Run posted deadline. | 2524 task_runner().RunPendingTasks(); // Run posted deadline. |
| 2528 EXPECT_SINGLE_ACTION("ScheduledActionDrawAndSwapIfPossible", client_); | 2525 EXPECT_SINGLE_ACTION("ScheduledActionDrawIfPossible", client_); |
| 2529 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); | 2526 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); |
| 2530 client_->Reset(); | 2527 client_->Reset(); |
| 2531 } | 2528 } |
| 2532 | 2529 |
| 2533 // Tests to ensure that the active frame source can successfully be changed from | 2530 // Tests to ensure that the active frame source can successfully be changed from |
| 2534 // unthrottled to throttled. | 2531 // unthrottled to throttled. |
| 2535 TEST_F(SchedulerTest, SwitchFrameSourceToThrottled) { | 2532 TEST_F(SchedulerTest, SwitchFrameSourceToThrottled) { |
| 2536 SetUpScheduler(UNTHROTTLED_BFS); | 2533 SetUpScheduler(UNTHROTTLED_BFS); |
| 2537 | 2534 |
| 2538 scheduler_->SetNeedsRedraw(); | 2535 scheduler_->SetNeedsRedraw(); |
| 2539 EXPECT_NO_ACTION(client_); | 2536 EXPECT_NO_ACTION(client_); |
| 2540 client_->Reset(); | 2537 client_->Reset(); |
| 2541 | 2538 |
| 2542 task_runner().RunPendingTasks(); // Run posted BeginFrame. | 2539 task_runner().RunPendingTasks(); // Run posted BeginFrame. |
| 2543 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 1); | 2540 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 1); |
| 2544 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); | 2541 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); |
| 2545 client_->Reset(); | 2542 client_->Reset(); |
| 2546 | 2543 |
| 2547 task_runner().RunPendingTasks(); // Run posted deadline. | 2544 task_runner().RunPendingTasks(); // Run posted deadline. |
| 2548 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 0, 1); | 2545 EXPECT_ACTION("ScheduledActionDrawIfPossible", client_, 0, 1); |
| 2549 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); | 2546 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); |
| 2550 client_->Reset(); | 2547 client_->Reset(); |
| 2551 | 2548 |
| 2552 // Switch to a throttled frame source. | 2549 // Switch to a throttled frame source. |
| 2553 scheduler_->SetBeginFrameSource(fake_external_begin_frame_source_.get()); | 2550 scheduler_->SetBeginFrameSource(fake_external_begin_frame_source_.get()); |
| 2554 client_->Reset(); | 2551 client_->Reset(); |
| 2555 | 2552 |
| 2556 // SetNeedsRedraw should begin the frame on the next BeginImplFrame. | 2553 // SetNeedsRedraw should begin the frame on the next BeginImplFrame. |
| 2557 scheduler_->SetNeedsRedraw(); | 2554 scheduler_->SetNeedsRedraw(); |
| 2558 task_runner().RunPendingTasks(); | 2555 task_runner().RunPendingTasks(); |
| 2559 EXPECT_NO_ACTION(client_); | 2556 EXPECT_NO_ACTION(client_); |
| 2560 client_->Reset(); | 2557 client_->Reset(); |
| 2561 | 2558 |
| 2562 EXPECT_SCOPED(AdvanceFrame()); | 2559 EXPECT_SCOPED(AdvanceFrame()); |
| 2563 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 1); | 2560 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 1); |
| 2564 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); | 2561 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); |
| 2565 EXPECT_TRUE(scheduler_->begin_frames_expected()); | 2562 EXPECT_TRUE(scheduler_->begin_frames_expected()); |
| 2566 client_->Reset(); | 2563 client_->Reset(); |
| 2567 task_runner().RunPendingTasks(); // Run posted deadline. | 2564 task_runner().RunPendingTasks(); // Run posted deadline. |
| 2568 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 0, 1); | 2565 EXPECT_ACTION("ScheduledActionDrawIfPossible", client_, 0, 1); |
| 2569 } | 2566 } |
| 2570 | 2567 |
| 2571 TEST_F(SchedulerTest, SwitchFrameSourceToNullInsideDeadline) { | 2568 TEST_F(SchedulerTest, SwitchFrameSourceToNullInsideDeadline) { |
| 2572 SetUpScheduler(EXTERNAL_BFS); | 2569 SetUpScheduler(EXTERNAL_BFS); |
| 2573 | 2570 |
| 2574 scheduler_->SetNeedsRedraw(); | 2571 scheduler_->SetNeedsRedraw(); |
| 2575 EXPECT_SINGLE_ACTION("AddObserver(this)", client_); | 2572 EXPECT_SINGLE_ACTION("AddObserver(this)", client_); |
| 2576 client_->Reset(); | 2573 client_->Reset(); |
| 2577 | 2574 |
| 2578 EXPECT_SCOPED(AdvanceFrame()); | 2575 EXPECT_SCOPED(AdvanceFrame()); |
| 2579 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client_); | 2576 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client_); |
| 2580 client_->Reset(); | 2577 client_->Reset(); |
| 2581 | 2578 |
| 2582 // Switch to a null frame source. | 2579 // Switch to a null frame source. |
| 2583 scheduler_->SetBeginFrameSource(nullptr); | 2580 scheduler_->SetBeginFrameSource(nullptr); |
| 2584 EXPECT_SINGLE_ACTION("RemoveObserver(this)", client_); | 2581 EXPECT_SINGLE_ACTION("RemoveObserver(this)", client_); |
| 2585 client_->Reset(); | 2582 client_->Reset(); |
| 2586 | 2583 |
| 2587 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); | 2584 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); |
| 2588 task_runner().RunPendingTasks(); // Run posted deadline. | 2585 task_runner().RunPendingTasks(); // Run posted deadline. |
| 2589 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 0, 1); | 2586 EXPECT_ACTION("ScheduledActionDrawIfPossible", client_, 0, 1); |
| 2590 EXPECT_FALSE(scheduler_->begin_frames_expected()); | 2587 EXPECT_FALSE(scheduler_->begin_frames_expected()); |
| 2591 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); | 2588 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); |
| 2592 client_->Reset(); | 2589 client_->Reset(); |
| 2593 | 2590 |
| 2594 // AdvanceFrame helper can't be used here because there's no deadline posted. | 2591 // AdvanceFrame helper can't be used here because there's no deadline posted. |
| 2595 scheduler_->SetNeedsRedraw(); | 2592 scheduler_->SetNeedsRedraw(); |
| 2596 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); | 2593 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); |
| 2597 EXPECT_NO_ACTION(client_); | 2594 EXPECT_NO_ACTION(client_); |
| 2598 client_->Reset(); | 2595 client_->Reset(); |
| 2599 | 2596 |
| 2600 scheduler_->SetNeedsBeginMainFrame(); | 2597 scheduler_->SetNeedsBeginMainFrame(); |
| 2601 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); | 2598 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); |
| 2602 EXPECT_NO_ACTION(client_); | 2599 EXPECT_NO_ACTION(client_); |
| 2603 client_->Reset(); | 2600 client_->Reset(); |
| 2604 | 2601 |
| 2605 // Switch back to the same source, make sure frames continue to be produced. | 2602 // Switch back to the same source, make sure frames continue to be produced. |
| 2606 scheduler_->SetBeginFrameSource(fake_external_begin_frame_source_.get()); | 2603 scheduler_->SetBeginFrameSource(fake_external_begin_frame_source_.get()); |
| 2607 EXPECT_SINGLE_ACTION("AddObserver(this)", client_); | 2604 EXPECT_SINGLE_ACTION("AddObserver(this)", client_); |
| 2608 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); | 2605 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); |
| 2609 client_->Reset(); | 2606 client_->Reset(); |
| 2610 | 2607 |
| 2611 EXPECT_SCOPED(AdvanceFrame()); | 2608 EXPECT_SCOPED(AdvanceFrame()); |
| 2612 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); | 2609 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
| 2613 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); | 2610 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); |
| 2614 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); | 2611 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); |
| 2615 client_->Reset(); | 2612 client_->Reset(); |
| 2616 | 2613 |
| 2617 task_runner().RunPendingTasks(); | 2614 task_runner().RunPendingTasks(); |
| 2618 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 0, 1); | 2615 EXPECT_ACTION("ScheduledActionDrawIfPossible", client_, 0, 1); |
| 2619 } | 2616 } |
| 2620 | 2617 |
| 2621 // This test maskes sure that switching a frame source when not observing | 2618 // This test maskes sure that switching a frame source when not observing |
| 2622 // such as when not visible also works. | 2619 // such as when not visible also works. |
| 2623 TEST_F(SchedulerTest, SwitchFrameSourceWhenNotObserving) { | 2620 TEST_F(SchedulerTest, SwitchFrameSourceWhenNotObserving) { |
| 2624 SetUpScheduler(EXTERNAL_BFS); | 2621 SetUpScheduler(EXTERNAL_BFS); |
| 2625 | 2622 |
| 2626 // SetNeedsBeginMainFrame should begin the frame on the next BeginImplFrame. | 2623 // SetNeedsBeginMainFrame should begin the frame on the next BeginImplFrame. |
| 2627 scheduler_->SetNeedsBeginMainFrame(); | 2624 scheduler_->SetNeedsBeginMainFrame(); |
| 2628 EXPECT_SINGLE_ACTION("AddObserver(this)", client_); | 2625 EXPECT_SINGLE_ACTION("AddObserver(this)", client_); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2685 // Trigger a frame draw. | 2682 // Trigger a frame draw. |
| 2686 EXPECT_SCOPED(AdvanceFrame()); | 2683 EXPECT_SCOPED(AdvanceFrame()); |
| 2687 scheduler_->NotifyBeginMainFrameStarted(base::TimeTicks()); | 2684 scheduler_->NotifyBeginMainFrameStarted(base::TimeTicks()); |
| 2688 scheduler_->NotifyReadyToCommit(); | 2685 scheduler_->NotifyReadyToCommit(); |
| 2689 scheduler_->NotifyReadyToActivate(); | 2686 scheduler_->NotifyReadyToActivate(); |
| 2690 task_runner().RunPendingTasks(); | 2687 task_runner().RunPendingTasks(); |
| 2691 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 5); | 2688 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 5); |
| 2692 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 5); | 2689 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 5); |
| 2693 EXPECT_ACTION("ScheduledActionCommit", client_, 2, 5); | 2690 EXPECT_ACTION("ScheduledActionCommit", client_, 2, 5); |
| 2694 EXPECT_ACTION("ScheduledActionActivateSyncTree", client_, 3, 5); | 2691 EXPECT_ACTION("ScheduledActionActivateSyncTree", client_, 3, 5); |
| 2695 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 4, 5); | 2692 EXPECT_ACTION("ScheduledActionDrawIfPossible", client_, 4, 5); |
| 2696 client_->Reset(); | 2693 client_->Reset(); |
| 2697 | 2694 |
| 2698 // The following BeginImplFrame deadline should SetNeedsBeginFrame(false) | 2695 // The following BeginImplFrame deadline should SetNeedsBeginFrame(false) |
| 2699 // and send a SendBeginMainFrameNotExpectedSoon. | 2696 // and send a SendBeginMainFrameNotExpectedSoon. |
| 2700 EXPECT_SCOPED(AdvanceFrame()); | 2697 EXPECT_SCOPED(AdvanceFrame()); |
| 2701 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client_); | 2698 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client_); |
| 2702 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); | 2699 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); |
| 2703 client_->Reset(); | 2700 client_->Reset(); |
| 2704 | 2701 |
| 2705 task_runner().RunPendingTasks(); // Run posted deadline. | 2702 task_runner().RunPendingTasks(); // Run posted deadline. |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 2725 AdvanceFrame(); | 2722 AdvanceFrame(); |
| 2726 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); | 2723 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
| 2727 EXPECT_ACTION("ScheduledActionInvalidateCompositorFrameSink", client_, 1, 2); | 2724 EXPECT_ACTION("ScheduledActionInvalidateCompositorFrameSink", client_, 1, 2); |
| 2728 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); | 2725 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); |
| 2729 client_->Reset(); | 2726 client_->Reset(); |
| 2730 | 2727 |
| 2731 // Android onDraw. This doesn't consume the single begin frame request. | 2728 // Android onDraw. This doesn't consume the single begin frame request. |
| 2732 scheduler_->SetNeedsRedraw(); | 2729 scheduler_->SetNeedsRedraw(); |
| 2733 bool resourceless_software_draw = false; | 2730 bool resourceless_software_draw = false; |
| 2734 scheduler_->OnDrawForCompositorFrameSink(resourceless_software_draw); | 2731 scheduler_->OnDrawForCompositorFrameSink(resourceless_software_draw); |
| 2735 EXPECT_SINGLE_ACTION("ScheduledActionDrawAndSwapIfPossible", client_); | 2732 EXPECT_SINGLE_ACTION("ScheduledActionDrawIfPossible", client_); |
| 2736 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); | 2733 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); |
| 2737 client_->Reset(); | 2734 client_->Reset(); |
| 2738 | 2735 |
| 2739 // The animation inside of WillBeginImplFrame changes stuff on the screen, but | 2736 // The animation inside of WillBeginImplFrame changes stuff on the screen, but |
| 2740 // ends here, so does not cause another frame to happen. | 2737 // ends here, so does not cause another frame to happen. |
| 2741 client_->SetWillBeginImplFrameCausesRedraw(true); | 2738 client_->SetWillBeginImplFrameCausesRedraw(true); |
| 2742 | 2739 |
| 2743 // Next vsync. | 2740 // Next vsync. |
| 2744 AdvanceFrame(); | 2741 AdvanceFrame(); |
| 2745 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); | 2742 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
| 2746 EXPECT_ACTION("ScheduledActionInvalidateCompositorFrameSink", client_, 1, 2); | 2743 EXPECT_ACTION("ScheduledActionInvalidateCompositorFrameSink", client_, 1, 2); |
| 2747 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); | 2744 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); |
| 2748 client_->Reset(); | 2745 client_->Reset(); |
| 2749 | 2746 |
| 2750 // Android onDraw. | 2747 // Android onDraw. |
| 2751 scheduler_->SetNeedsRedraw(); | 2748 scheduler_->SetNeedsRedraw(); |
| 2752 scheduler_->OnDrawForCompositorFrameSink(resourceless_software_draw); | 2749 scheduler_->OnDrawForCompositorFrameSink(resourceless_software_draw); |
| 2753 EXPECT_SINGLE_ACTION("ScheduledActionDrawAndSwapIfPossible", client_); | 2750 EXPECT_SINGLE_ACTION("ScheduledActionDrawIfPossible", client_); |
| 2754 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); | 2751 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); |
| 2755 client_->Reset(); | 2752 client_->Reset(); |
| 2756 | 2753 |
| 2757 // Idle on next vsync, as the animation has completed. | 2754 // Idle on next vsync, as the animation has completed. |
| 2758 AdvanceFrame(); | 2755 AdvanceFrame(); |
| 2759 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 3); | 2756 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 3); |
| 2760 EXPECT_ACTION("RemoveObserver(this)", client_, 1, 3); | 2757 EXPECT_ACTION("RemoveObserver(this)", client_, 1, 3); |
| 2761 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 2, 3); | 2758 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 2, 3); |
| 2762 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); | 2759 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); |
| 2763 client_->Reset(); | 2760 client_->Reset(); |
| 2764 } | 2761 } |
| 2765 | 2762 |
| 2766 TEST_F(SchedulerTest, SynchronousCompositorOnDrawDuringIdle) { | 2763 TEST_F(SchedulerTest, SynchronousCompositorOnDrawDuringIdle) { |
| 2767 scheduler_settings_.using_synchronous_renderer_compositor = true; | 2764 scheduler_settings_.using_synchronous_renderer_compositor = true; |
| 2768 SetUpScheduler(EXTERNAL_BFS); | 2765 SetUpScheduler(EXTERNAL_BFS); |
| 2769 | 2766 |
| 2770 scheduler_->SetNeedsRedraw(); | 2767 scheduler_->SetNeedsRedraw(); |
| 2771 bool resourceless_software_draw = false; | 2768 bool resourceless_software_draw = false; |
| 2772 scheduler_->OnDrawForCompositorFrameSink(resourceless_software_draw); | 2769 scheduler_->OnDrawForCompositorFrameSink(resourceless_software_draw); |
| 2773 EXPECT_ACTION("AddObserver(this)", client_, 0, 2); | 2770 EXPECT_ACTION("AddObserver(this)", client_, 0, 2); |
| 2774 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 1, 2); | 2771 EXPECT_ACTION("ScheduledActionDrawIfPossible", client_, 1, 2); |
| 2775 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); | 2772 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); |
| 2776 client_->Reset(); | 2773 client_->Reset(); |
| 2777 | 2774 |
| 2778 // Idle on next vsync. | 2775 // Idle on next vsync. |
| 2779 AdvanceFrame(); | 2776 AdvanceFrame(); |
| 2780 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 3); | 2777 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 3); |
| 2781 EXPECT_ACTION("RemoveObserver(this)", client_, 1, 3); | 2778 EXPECT_ACTION("RemoveObserver(this)", client_, 1, 3); |
| 2782 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 2, 3); | 2779 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 2, 3); |
| 2783 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); | 2780 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); |
| 2784 client_->Reset(); | 2781 client_->Reset(); |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2857 AdvanceFrame(); | 2854 AdvanceFrame(); |
| 2858 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); | 2855 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
| 2859 EXPECT_ACTION("ScheduledActionInvalidateCompositorFrameSink", client_, 1, 2); | 2856 EXPECT_ACTION("ScheduledActionInvalidateCompositorFrameSink", client_, 1, 2); |
| 2860 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); | 2857 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); |
| 2861 client_->Reset(); | 2858 client_->Reset(); |
| 2862 | 2859 |
| 2863 // Android onDraw. | 2860 // Android onDraw. |
| 2864 scheduler_->SetNeedsRedraw(); | 2861 scheduler_->SetNeedsRedraw(); |
| 2865 bool resourceless_software_draw = false; | 2862 bool resourceless_software_draw = false; |
| 2866 scheduler_->OnDrawForCompositorFrameSink(resourceless_software_draw); | 2863 scheduler_->OnDrawForCompositorFrameSink(resourceless_software_draw); |
| 2867 EXPECT_SINGLE_ACTION("ScheduledActionDrawAndSwapIfPossible", client_); | 2864 EXPECT_SINGLE_ACTION("ScheduledActionDrawIfPossible", client_); |
| 2868 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); | 2865 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); |
| 2869 client_->Reset(); | 2866 client_->Reset(); |
| 2870 | 2867 |
| 2871 // Idle on next vsync. | 2868 // Idle on next vsync. |
| 2872 AdvanceFrame(); | 2869 AdvanceFrame(); |
| 2873 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 3); | 2870 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 3); |
| 2874 EXPECT_ACTION("RemoveObserver(this)", client_, 1, 3); | 2871 EXPECT_ACTION("RemoveObserver(this)", client_, 1, 3); |
| 2875 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 2, 3); | 2872 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 2, 3); |
| 2876 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); | 2873 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); |
| 2877 client_->Reset(); | 2874 client_->Reset(); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2920 scheduler_->NotifyReadyToCommit(); | 2917 scheduler_->NotifyReadyToCommit(); |
| 2921 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_); | 2918 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_); |
| 2922 client_->Reset(); | 2919 client_->Reset(); |
| 2923 } | 2920 } |
| 2924 | 2921 |
| 2925 class SchedulerClientSetNeedsPrepareTilesOnDraw : public FakeSchedulerClient { | 2922 class SchedulerClientSetNeedsPrepareTilesOnDraw : public FakeSchedulerClient { |
| 2926 public: | 2923 public: |
| 2927 SchedulerClientSetNeedsPrepareTilesOnDraw() : FakeSchedulerClient() {} | 2924 SchedulerClientSetNeedsPrepareTilesOnDraw() : FakeSchedulerClient() {} |
| 2928 | 2925 |
| 2929 protected: | 2926 protected: |
| 2930 DrawResult ScheduledActionDrawAndSwapIfPossible() override { | 2927 DrawResult ScheduledActionDrawIfPossible() override { |
| 2931 scheduler_->SetNeedsPrepareTiles(); | 2928 scheduler_->SetNeedsPrepareTiles(); |
| 2932 return FakeSchedulerClient::ScheduledActionDrawAndSwapIfPossible(); | 2929 return FakeSchedulerClient::ScheduledActionDrawIfPossible(); |
| 2933 } | 2930 } |
| 2934 }; | 2931 }; |
| 2935 | 2932 |
| 2936 TEST_F(SchedulerTest, SynchronousCompositorPrepareTilesOnDraw) { | 2933 TEST_F(SchedulerTest, SynchronousCompositorPrepareTilesOnDraw) { |
| 2937 scheduler_settings_.using_synchronous_renderer_compositor = true; | 2934 scheduler_settings_.using_synchronous_renderer_compositor = true; |
| 2938 | 2935 |
| 2939 std::unique_ptr<FakeSchedulerClient> client = | 2936 std::unique_ptr<FakeSchedulerClient> client = |
| 2940 base::WrapUnique(new SchedulerClientSetNeedsPrepareTilesOnDraw); | 2937 base::WrapUnique(new SchedulerClientSetNeedsPrepareTilesOnDraw); |
| 2941 SetUpScheduler(EXTERNAL_BFS, std::move(client)); | 2938 SetUpScheduler(EXTERNAL_BFS, std::move(client)); |
| 2942 | 2939 |
| 2943 scheduler_->SetNeedsRedraw(); | 2940 scheduler_->SetNeedsRedraw(); |
| 2944 EXPECT_SINGLE_ACTION("AddObserver(this)", client_); | 2941 EXPECT_SINGLE_ACTION("AddObserver(this)", client_); |
| 2945 client_->Reset(); | 2942 client_->Reset(); |
| 2946 | 2943 |
| 2947 // Next vsync. | 2944 // Next vsync. |
| 2948 EXPECT_SCOPED(AdvanceFrame()); | 2945 EXPECT_SCOPED(AdvanceFrame()); |
| 2949 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); | 2946 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
| 2950 EXPECT_ACTION("ScheduledActionInvalidateCompositorFrameSink", client_, 1, 2); | 2947 EXPECT_ACTION("ScheduledActionInvalidateCompositorFrameSink", client_, 1, 2); |
| 2951 client_->Reset(); | 2948 client_->Reset(); |
| 2952 | 2949 |
| 2953 // Android onDraw. | 2950 // Android onDraw. |
| 2954 scheduler_->SetNeedsRedraw(); | 2951 scheduler_->SetNeedsRedraw(); |
| 2955 bool resourceless_software_draw = false; | 2952 bool resourceless_software_draw = false; |
| 2956 scheduler_->OnDrawForCompositorFrameSink(resourceless_software_draw); | 2953 scheduler_->OnDrawForCompositorFrameSink(resourceless_software_draw); |
| 2957 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 0, 2); | 2954 EXPECT_ACTION("ScheduledActionDrawIfPossible", client_, 0, 2); |
| 2958 EXPECT_ACTION("ScheduledActionPrepareTiles", client_, 1, 2); | 2955 EXPECT_ACTION("ScheduledActionPrepareTiles", client_, 1, 2); |
| 2959 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); | 2956 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); |
| 2960 EXPECT_FALSE(scheduler_->PrepareTilesPending()); | 2957 EXPECT_FALSE(scheduler_->PrepareTilesPending()); |
| 2961 client_->Reset(); | 2958 client_->Reset(); |
| 2962 | 2959 |
| 2963 // Android onDraw. | 2960 // Android onDraw. |
| 2964 scheduler_->SetNeedsRedraw(); | 2961 scheduler_->SetNeedsRedraw(); |
| 2965 scheduler_->OnDrawForCompositorFrameSink(resourceless_software_draw); | 2962 scheduler_->OnDrawForCompositorFrameSink(resourceless_software_draw); |
| 2966 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 0, 2); | 2963 EXPECT_ACTION("ScheduledActionDrawIfPossible", client_, 0, 2); |
| 2967 EXPECT_ACTION("ScheduledActionPrepareTiles", client_, 1, 2); | 2964 EXPECT_ACTION("ScheduledActionPrepareTiles", client_, 1, 2); |
| 2968 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); | 2965 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); |
| 2969 EXPECT_FALSE(scheduler_->PrepareTilesPending()); | 2966 EXPECT_FALSE(scheduler_->PrepareTilesPending()); |
| 2970 client_->Reset(); | 2967 client_->Reset(); |
| 2971 | 2968 |
| 2972 // Next vsync. | 2969 // Next vsync. |
| 2973 EXPECT_SCOPED(AdvanceFrame()); | 2970 EXPECT_SCOPED(AdvanceFrame()); |
| 2974 EXPECT_FALSE(scheduler_->PrepareTilesPending()); | 2971 EXPECT_FALSE(scheduler_->PrepareTilesPending()); |
| 2975 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 3); | 2972 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 3); |
| 2976 EXPECT_ACTION("RemoveObserver(this)", client_, 1, 3); | 2973 EXPECT_ACTION("RemoveObserver(this)", client_, 1, 3); |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 2990 // Next vsync. | 2987 // Next vsync. |
| 2991 EXPECT_SCOPED(AdvanceFrame()); | 2988 EXPECT_SCOPED(AdvanceFrame()); |
| 2992 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); | 2989 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
| 2993 EXPECT_ACTION("ScheduledActionInvalidateCompositorFrameSink", client_, 1, 2); | 2990 EXPECT_ACTION("ScheduledActionInvalidateCompositorFrameSink", client_, 1, 2); |
| 2994 client_->Reset(); | 2991 client_->Reset(); |
| 2995 | 2992 |
| 2996 // Android onDraw. | 2993 // Android onDraw. |
| 2997 scheduler_->SetNeedsRedraw(); | 2994 scheduler_->SetNeedsRedraw(); |
| 2998 bool resourceless_software_draw = false; | 2995 bool resourceless_software_draw = false; |
| 2999 scheduler_->OnDrawForCompositorFrameSink(resourceless_software_draw); | 2996 scheduler_->OnDrawForCompositorFrameSink(resourceless_software_draw); |
| 3000 EXPECT_SINGLE_ACTION("ScheduledActionDrawAndSwapIfPossible", client_); | 2997 EXPECT_SINGLE_ACTION("ScheduledActionDrawIfPossible", client_); |
| 3001 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); | 2998 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); |
| 3002 EXPECT_FALSE(scheduler_->PrepareTilesPending()); | 2999 EXPECT_FALSE(scheduler_->PrepareTilesPending()); |
| 3003 client_->Reset(); | 3000 client_->Reset(); |
| 3004 | 3001 |
| 3005 // Simulate SetNeedsBeginMainFrame due to input event. | 3002 // Simulate SetNeedsBeginMainFrame due to input event. |
| 3006 scheduler_->SetNeedsBeginMainFrame(); | 3003 scheduler_->SetNeedsBeginMainFrame(); |
| 3007 EXPECT_SINGLE_ACTION("ScheduledActionSendBeginMainFrame", client_); | 3004 EXPECT_SINGLE_ACTION("ScheduledActionSendBeginMainFrame", client_); |
| 3008 client_->Reset(); | 3005 client_->Reset(); |
| 3009 | 3006 |
| 3010 scheduler_->NotifyBeginMainFrameStarted(base::TimeTicks()); | 3007 scheduler_->NotifyBeginMainFrameStarted(base::TimeTicks()); |
| 3011 scheduler_->NotifyReadyToCommit(); | 3008 scheduler_->NotifyReadyToCommit(); |
| 3012 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_); | 3009 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_); |
| 3013 client_->Reset(); | 3010 client_->Reset(); |
| 3014 | 3011 |
| 3015 scheduler_->NotifyReadyToActivate(); | 3012 scheduler_->NotifyReadyToActivate(); |
| 3016 EXPECT_SINGLE_ACTION("ScheduledActionActivateSyncTree", client_); | 3013 EXPECT_SINGLE_ACTION("ScheduledActionActivateSyncTree", client_); |
| 3017 client_->Reset(); | 3014 client_->Reset(); |
| 3018 | 3015 |
| 3019 // Next vsync. | 3016 // Next vsync. |
| 3020 EXPECT_SCOPED(AdvanceFrame()); | 3017 EXPECT_SCOPED(AdvanceFrame()); |
| 3021 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); | 3018 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
| 3022 EXPECT_ACTION("ScheduledActionInvalidateCompositorFrameSink", client_, 1, 2); | 3019 EXPECT_ACTION("ScheduledActionInvalidateCompositorFrameSink", client_, 1, 2); |
| 3023 client_->Reset(); | 3020 client_->Reset(); |
| 3024 | 3021 |
| 3025 // Android onDraw. | 3022 // Android onDraw. |
| 3026 scheduler_->SetNeedsRedraw(); | 3023 scheduler_->SetNeedsRedraw(); |
| 3027 scheduler_->OnDrawForCompositorFrameSink(resourceless_software_draw); | 3024 scheduler_->OnDrawForCompositorFrameSink(resourceless_software_draw); |
| 3028 EXPECT_SINGLE_ACTION("ScheduledActionDrawAndSwapIfPossible", client_); | 3025 EXPECT_SINGLE_ACTION("ScheduledActionDrawIfPossible", client_); |
| 3029 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); | 3026 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); |
| 3030 EXPECT_FALSE(scheduler_->PrepareTilesPending()); | 3027 EXPECT_FALSE(scheduler_->PrepareTilesPending()); |
| 3031 client_->Reset(); | 3028 client_->Reset(); |
| 3032 | 3029 |
| 3033 // Simulate SetNeedsBeginMainFrame due to input event. | 3030 // Simulate SetNeedsBeginMainFrame due to input event. |
| 3034 scheduler_->SetNeedsBeginMainFrame(); | 3031 scheduler_->SetNeedsBeginMainFrame(); |
| 3035 EXPECT_SINGLE_ACTION("ScheduledActionSendBeginMainFrame", client_); | 3032 EXPECT_SINGLE_ACTION("ScheduledActionSendBeginMainFrame", client_); |
| 3036 client_->Reset(); | 3033 client_->Reset(); |
| 3037 } | 3034 } |
| 3038 | 3035 |
| 3039 TEST_F(SchedulerTest, SynchronousCompositorResourcelessOnDrawWhenInvisible) { | 3036 TEST_F(SchedulerTest, SynchronousCompositorResourcelessOnDrawWhenInvisible) { |
| 3040 scheduler_settings_.using_synchronous_renderer_compositor = true; | 3037 scheduler_settings_.using_synchronous_renderer_compositor = true; |
| 3041 SetUpScheduler(EXTERNAL_BFS); | 3038 SetUpScheduler(EXTERNAL_BFS); |
| 3042 | 3039 |
| 3043 scheduler_->SetVisible(false); | 3040 scheduler_->SetVisible(false); |
| 3044 | 3041 |
| 3045 scheduler_->SetNeedsRedraw(); | 3042 scheduler_->SetNeedsRedraw(); |
| 3046 bool resourceless_software_draw = true; | 3043 bool resourceless_software_draw = true; |
| 3047 scheduler_->OnDrawForCompositorFrameSink(resourceless_software_draw); | 3044 scheduler_->OnDrawForCompositorFrameSink(resourceless_software_draw); |
| 3048 // SynchronousCompositor has to draw regardless of visibility. | 3045 // SynchronousCompositor has to draw regardless of visibility. |
| 3049 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 0, 1); | 3046 EXPECT_ACTION("ScheduledActionDrawIfPossible", client_, 0, 1); |
| 3050 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); | 3047 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); |
| 3051 client_->Reset(); | 3048 client_->Reset(); |
| 3052 } | 3049 } |
| 3053 | 3050 |
| 3054 TEST_F(SchedulerTest, AuthoritativeVSyncInterval) { | 3051 TEST_F(SchedulerTest, AuthoritativeVSyncInterval) { |
| 3055 SetUpScheduler(THROTTLED_BFS); | 3052 SetUpScheduler(THROTTLED_BFS); |
| 3056 base::TimeDelta initial_interval = scheduler_->BeginImplFrameInterval(); | 3053 base::TimeDelta initial_interval = scheduler_->BeginImplFrameInterval(); |
| 3057 base::TimeDelta authoritative_interval = | 3054 base::TimeDelta authoritative_interval = |
| 3058 base::TimeDelta::FromMilliseconds(33); | 3055 base::TimeDelta::FromMilliseconds(33); |
| 3059 | 3056 |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3242 } | 3239 } |
| 3243 | 3240 |
| 3244 TEST_F(SchedulerTest, BeginMainFrameOnCriticalPath_AHS) { | 3241 TEST_F(SchedulerTest, BeginMainFrameOnCriticalPath_AHS) { |
| 3245 EXPECT_FALSE(BeginMainFrameOnCriticalPath( | 3242 EXPECT_FALSE(BeginMainFrameOnCriticalPath( |
| 3246 SMOOTHNESS_TAKES_PRIORITY, | 3243 SMOOTHNESS_TAKES_PRIORITY, |
| 3247 ScrollHandlerState::SCROLL_AFFECTS_SCROLL_HANDLER, kSlowDuration)); | 3244 ScrollHandlerState::SCROLL_AFFECTS_SCROLL_HANDLER, kSlowDuration)); |
| 3248 } | 3245 } |
| 3249 | 3246 |
| 3250 } // namespace | 3247 } // namespace |
| 3251 } // namespace cc | 3248 } // namespace cc |
| OLD | NEW |