Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(434)

Side by Side Diff: cc/scheduler/scheduler_unittest.cc

Issue 2753843003: Create a new action triggered when a BeginMainFrame is not expected before vsync (Closed)
Patch Set: missed one Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 states_.push_back(scheduler_->AsValue()); 172 states_.push_back(scheduler_->AsValue());
173 } 173 }
174 void ScheduledActionPerformImplSideInvalidation() override { 174 void ScheduledActionPerformImplSideInvalidation() override {
175 PushAction("ScheduledActionPerformImplSideInvalidation"); 175 PushAction("ScheduledActionPerformImplSideInvalidation");
176 } 176 }
177 177
178 void SendBeginMainFrameNotExpectedSoon() override { 178 void SendBeginMainFrameNotExpectedSoon() override {
179 PushAction("SendBeginMainFrameNotExpectedSoon"); 179 PushAction("SendBeginMainFrameNotExpectedSoon");
180 } 180 }
181 181
182 void ScheduledActionDoShortIdleWork(const BeginFrameArgs& args) override {
183 PushAction("ScheduledActionDoShortIdleWork");
184 }
185
182 bool IsInsideBeginImplFrame() const { return inside_begin_impl_frame_; } 186 bool IsInsideBeginImplFrame() const { return inside_begin_impl_frame_; }
183 187
184 base::Callback<bool(void)> InsideBeginImplFrame(bool state) { 188 base::Callback<bool(void)> InsideBeginImplFrame(bool state) {
185 return base::Bind(&FakeSchedulerClient::InsideBeginImplFrameCallback, 189 return base::Bind(&FakeSchedulerClient::InsideBeginImplFrameCallback,
186 base::Unretained(this), state); 190 base::Unretained(this), state);
187 } 191 }
188 192
189 bool IsCurrentFrame(int last_frame_number) const { 193 bool IsCurrentFrame(int last_frame_number) const {
190 return scheduler_->current_frame_number() == last_frame_number; 194 return scheduler_->current_frame_number() == last_frame_number;
191 } 195 }
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after
474 SetUpScheduler(EXTERNAL_BFS); 478 SetUpScheduler(EXTERNAL_BFS);
475 479
476 scheduler_->SetVideoNeedsBeginFrames(true); 480 scheduler_->SetVideoNeedsBeginFrames(true);
477 EXPECT_SINGLE_ACTION("AddObserver(this)", client_); 481 EXPECT_SINGLE_ACTION("AddObserver(this)", client_);
478 EXPECT_TRUE(scheduler_->begin_frames_expected()); 482 EXPECT_TRUE(scheduler_->begin_frames_expected());
479 483
480 client_->Reset(); 484 client_->Reset();
481 EXPECT_SCOPED(AdvanceFrame()); 485 EXPECT_SCOPED(AdvanceFrame());
482 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); 486 EXPECT_TRUE(client_->IsInsideBeginImplFrame());
483 // WillBeginImplFrame is responsible for sending BeginFrames to video. 487 // WillBeginImplFrame is responsible for sending BeginFrames to video.
484 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client_); 488 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2);
489 EXPECT_ACTION("ScheduledActionDoShortIdleWork", client_, 1, 2);
485 490
486 client_->Reset(); 491 client_->Reset();
487 EXPECT_SCOPED(AdvanceFrame()); 492 EXPECT_SCOPED(AdvanceFrame());
488 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); 493 EXPECT_TRUE(client_->IsInsideBeginImplFrame());
489 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client_); 494 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2);
495 EXPECT_ACTION("ScheduledActionDoShortIdleWork", client_, 1, 2);
490 496
491 client_->Reset(); 497 client_->Reset();
492 scheduler_->SetVideoNeedsBeginFrames(false); 498 scheduler_->SetVideoNeedsBeginFrames(false);
493 EXPECT_NO_ACTION(client_); 499 EXPECT_NO_ACTION(client_);
494 500
495 client_->Reset(); 501 client_->Reset();
496 task_runner_->RunTasksWhile(client_->InsideBeginImplFrame(true)); 502 task_runner_->RunTasksWhile(client_->InsideBeginImplFrame(true));
497 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); 503 EXPECT_FALSE(client_->IsInsideBeginImplFrame());
498 EXPECT_ACTION("RemoveObserver(this)", client_, 0, 2); 504 EXPECT_ACTION("RemoveObserver(this)", client_, 0, 2);
499 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 1, 2); 505 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 1, 2);
(...skipping 30 matching lines...) Expand all
530 client_->Reset(); 536 client_->Reset();
531 537
532 // NotifyReadyToActivate should trigger the activation. 538 // NotifyReadyToActivate should trigger the activation.
533 scheduler_->NotifyReadyToActivate(); 539 scheduler_->NotifyReadyToActivate();
534 EXPECT_SINGLE_ACTION("ScheduledActionActivateSyncTree", client_); 540 EXPECT_SINGLE_ACTION("ScheduledActionActivateSyncTree", client_);
535 EXPECT_TRUE(scheduler_->begin_frames_expected()); 541 EXPECT_TRUE(scheduler_->begin_frames_expected());
536 client_->Reset(); 542 client_->Reset();
537 543
538 // BeginImplFrame should prepare the draw. 544 // BeginImplFrame should prepare the draw.
539 EXPECT_SCOPED(AdvanceFrame()); 545 EXPECT_SCOPED(AdvanceFrame());
540 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 1); 546 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2);
547 EXPECT_ACTION("ScheduledActionDoShortIdleWork", client_, 1, 2);
541 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); 548 EXPECT_TRUE(client_->IsInsideBeginImplFrame());
542 EXPECT_TRUE(scheduler_->begin_frames_expected()); 549 EXPECT_TRUE(scheduler_->begin_frames_expected());
543 client_->Reset(); 550 client_->Reset();
544 551
545 // BeginImplFrame deadline should draw. 552 // BeginImplFrame deadline should draw.
546 task_runner().RunPendingTasks(); // Run posted deadline. 553 task_runner().RunPendingTasks(); // Run posted deadline.
547 EXPECT_SINGLE_ACTION("ScheduledActionDrawIfPossible", client_); 554 EXPECT_SINGLE_ACTION("ScheduledActionDrawIfPossible", client_);
548 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); 555 EXPECT_FALSE(client_->IsInsideBeginImplFrame());
549 EXPECT_TRUE(scheduler_->begin_frames_expected()); 556 EXPECT_TRUE(scheduler_->begin_frames_expected());
550 client_->Reset(); 557 client_->Reset();
551 558
552 // The following BeginImplFrame deadline should SetNeedsBeginFrame(false) 559 // The following BeginImplFrame deadline should SetNeedsBeginFrame(false)
553 // to avoid excessive toggles. 560 // to avoid excessive toggles.
554 EXPECT_SCOPED(AdvanceFrame()); 561 EXPECT_SCOPED(AdvanceFrame());
555 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client_); 562 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2);
563 EXPECT_ACTION("ScheduledActionDoShortIdleWork", client_, 1, 2);
556 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); 564 EXPECT_TRUE(client_->IsInsideBeginImplFrame());
557 client_->Reset(); 565 client_->Reset();
558 566
559 task_runner().RunPendingTasks(); // Run posted deadline. 567 task_runner().RunPendingTasks(); // Run posted deadline.
560 EXPECT_ACTION("RemoveObserver(this)", client_, 0, 2); 568 EXPECT_ACTION("RemoveObserver(this)", client_, 0, 2);
561 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 1, 2); 569 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 1, 2);
562 client_->Reset(); 570 client_->Reset();
563 } 571 }
564 572
565 TEST_F(SchedulerTest, RequestCommitAfterSetDeferCommit) { 573 TEST_F(SchedulerTest, RequestCommitAfterSetDeferCommit) {
(...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after
965 EXPECT_TRUE(scheduler_->PrepareTilesPending()); 973 EXPECT_TRUE(scheduler_->PrepareTilesPending());
966 EXPECT_TRUE(client->needs_begin_frames()); 974 EXPECT_TRUE(client->needs_begin_frames());
967 EXPECT_EQ(0, client->num_draws()); 975 EXPECT_EQ(0, client->num_draws());
968 EXPECT_FALSE(client->HasAction("ScheduledActionPrepareTiles")); 976 EXPECT_FALSE(client->HasAction("ScheduledActionPrepareTiles"));
969 EXPECT_FALSE(client->HasAction("ScheduledActionDrawIfPossible")); 977 EXPECT_FALSE(client->HasAction("ScheduledActionDrawIfPossible"));
970 978
971 // We have no immediate actions to perform, so the BeginImplFrame should post 979 // We have no immediate actions to perform, so the BeginImplFrame should post
972 // the deadline task. 980 // the deadline task.
973 client->Reset(); 981 client->Reset();
974 EXPECT_SCOPED(AdvanceFrame()); 982 EXPECT_SCOPED(AdvanceFrame());
975 EXPECT_ACTION("WillBeginImplFrame", client, 0, 1); 983 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2);
984 EXPECT_ACTION("ScheduledActionDoShortIdleWork", client, 1, 2);
976 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); 985 EXPECT_TRUE(client_->IsInsideBeginImplFrame());
977 986
978 // On the deadline, the actions should have occured in the right order. 987 // On the deadline, the actions should have occured in the right order.
979 client->Reset(); 988 client->Reset();
980 task_runner().RunPendingTasks(); // Run posted deadline. 989 task_runner().RunPendingTasks(); // Run posted deadline.
981 EXPECT_EQ(1, client->num_draws()); 990 EXPECT_EQ(1, client->num_draws());
982 EXPECT_TRUE(client->HasAction("ScheduledActionDrawIfPossible")); 991 EXPECT_TRUE(client->HasAction("ScheduledActionDrawIfPossible"));
983 EXPECT_TRUE(client->HasAction("ScheduledActionPrepareTiles")); 992 EXPECT_TRUE(client->HasAction("ScheduledActionPrepareTiles"));
984 EXPECT_LT(client->ActionIndex("ScheduledActionDrawIfPossible"), 993 EXPECT_LT(client->ActionIndex("ScheduledActionDrawIfPossible"),
985 client->ActionIndex("ScheduledActionPrepareTiles")); 994 client->ActionIndex("ScheduledActionPrepareTiles"));
986 EXPECT_FALSE(scheduler_->RedrawPending()); 995 EXPECT_FALSE(scheduler_->RedrawPending());
987 EXPECT_FALSE(scheduler_->PrepareTilesPending()); 996 EXPECT_FALSE(scheduler_->PrepareTilesPending());
988 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); 997 EXPECT_FALSE(client_->IsInsideBeginImplFrame());
989 998
990 // Request a draw. We don't need a PrepareTiles yet. 999 // Request a draw. We don't need a PrepareTiles yet.
991 client->Reset(); 1000 client->Reset();
992 scheduler_->SetNeedsRedraw(); 1001 scheduler_->SetNeedsRedraw();
993 EXPECT_TRUE(scheduler_->RedrawPending()); 1002 EXPECT_TRUE(scheduler_->RedrawPending());
994 EXPECT_FALSE(scheduler_->PrepareTilesPending()); 1003 EXPECT_FALSE(scheduler_->PrepareTilesPending());
995 EXPECT_TRUE(client->needs_begin_frames()); 1004 EXPECT_TRUE(client->needs_begin_frames());
996 EXPECT_EQ(0, client->num_draws()); 1005 EXPECT_EQ(0, client->num_draws());
997 1006
998 // We have no immediate actions to perform, so the BeginImplFrame should post 1007 // We have no immediate actions to perform, so the BeginImplFrame should post
999 // the deadline task. 1008 // the deadline task.
1000 client->Reset(); 1009 client->Reset();
1001 EXPECT_SCOPED(AdvanceFrame()); 1010 EXPECT_SCOPED(AdvanceFrame());
1002 EXPECT_ACTION("WillBeginImplFrame", client, 0, 1); 1011 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2);
1012 EXPECT_ACTION("ScheduledActionDoShortIdleWork", client, 1, 2);
1003 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); 1013 EXPECT_TRUE(client_->IsInsideBeginImplFrame());
1004 1014
1005 // Draw. The draw will trigger SetNeedsPrepareTiles, and 1015 // Draw. The draw will trigger SetNeedsPrepareTiles, and
1006 // then the PrepareTiles action will be triggered after the Draw. 1016 // then the PrepareTiles action will be triggered after the Draw.
1007 // Afterwards, neither a draw nor PrepareTiles are pending. 1017 // Afterwards, neither a draw nor PrepareTiles are pending.
1008 client->Reset(); 1018 client->Reset();
1009 task_runner().RunPendingTasks(); // Run posted deadline. 1019 task_runner().RunPendingTasks(); // Run posted deadline.
1010 EXPECT_EQ(1, client->num_draws()); 1020 EXPECT_EQ(1, client->num_draws());
1011 EXPECT_TRUE(client->HasAction("ScheduledActionDrawIfPossible")); 1021 EXPECT_TRUE(client->HasAction("ScheduledActionDrawIfPossible"));
1012 EXPECT_TRUE(client->HasAction("ScheduledActionPrepareTiles")); 1022 EXPECT_TRUE(client->HasAction("ScheduledActionPrepareTiles"));
1013 EXPECT_LT(client->ActionIndex("ScheduledActionDrawIfPossible"), 1023 EXPECT_LT(client->ActionIndex("ScheduledActionDrawIfPossible"),
1014 client->ActionIndex("ScheduledActionPrepareTiles")); 1024 client->ActionIndex("ScheduledActionPrepareTiles"));
1015 EXPECT_FALSE(scheduler_->RedrawPending()); 1025 EXPECT_FALSE(scheduler_->RedrawPending());
1016 EXPECT_FALSE(scheduler_->PrepareTilesPending()); 1026 EXPECT_FALSE(scheduler_->PrepareTilesPending());
1017 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); 1027 EXPECT_FALSE(client_->IsInsideBeginImplFrame());
1018 1028
1019 // We need a BeginImplFrame where we don't swap to go idle. 1029 // We need a BeginImplFrame where we don't swap to go idle.
1020 client->Reset(); 1030 client->Reset();
1021 EXPECT_SCOPED(AdvanceFrame()); 1031 EXPECT_SCOPED(AdvanceFrame());
1022 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); 1032 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2);
1033 EXPECT_ACTION("ScheduledActionDoShortIdleWork", client, 1, 2);
1023 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); 1034 EXPECT_TRUE(client_->IsInsideBeginImplFrame());
1024 client->Reset(); 1035 client->Reset();
1025 task_runner().RunPendingTasks(); // Run posted deadline. 1036 task_runner().RunPendingTasks(); // Run posted deadline.
1026 EXPECT_ACTION("RemoveObserver(this)", client_, 0, 2); 1037 EXPECT_ACTION("RemoveObserver(this)", client_, 0, 2);
1027 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 1, 2); 1038 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 1, 2);
1028 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); 1039 EXPECT_FALSE(client_->IsInsideBeginImplFrame());
1029 EXPECT_EQ(0, client->num_draws()); 1040 EXPECT_EQ(0, client->num_draws());
1030 1041
1031 // Now trigger a PrepareTiles outside of a draw. We will then need 1042 // Now trigger a PrepareTiles outside of a draw. We will then need
1032 // a begin-frame for the PrepareTiles, but we don't need a draw. 1043 // a begin-frame for the PrepareTiles, but we don't need a draw.
1033 client->Reset(); 1044 client->Reset();
1034 EXPECT_FALSE(client->needs_begin_frames()); 1045 EXPECT_FALSE(client->needs_begin_frames());
1035 scheduler_->SetNeedsPrepareTiles(); 1046 scheduler_->SetNeedsPrepareTiles();
1036 EXPECT_TRUE(client->needs_begin_frames()); 1047 EXPECT_TRUE(client->needs_begin_frames());
1037 EXPECT_TRUE(scheduler_->PrepareTilesPending()); 1048 EXPECT_TRUE(scheduler_->PrepareTilesPending());
1038 EXPECT_FALSE(scheduler_->RedrawPending()); 1049 EXPECT_FALSE(scheduler_->RedrawPending());
1039 1050
1040 // BeginImplFrame. There will be no draw, only PrepareTiles. 1051 // BeginImplFrame. There will be no draw, only PrepareTiles.
1041 client->Reset(); 1052 client->Reset();
1042 EXPECT_SCOPED(AdvanceFrame()); 1053 EXPECT_SCOPED(AdvanceFrame());
1043 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); 1054 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2);
1055 EXPECT_ACTION("ScheduledActionDoShortIdleWork", client, 1, 2);
1044 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); 1056 EXPECT_TRUE(client_->IsInsideBeginImplFrame());
1045 client->Reset(); 1057 client->Reset();
1046 task_runner().RunPendingTasks(); // Run posted deadline. 1058 task_runner().RunPendingTasks(); // Run posted deadline.
1047 EXPECT_EQ(0, client->num_draws()); 1059 EXPECT_EQ(0, client->num_draws());
1048 EXPECT_FALSE(client->HasAction("ScheduledActionDrawIfPossible")); 1060 EXPECT_FALSE(client->HasAction("ScheduledActionDrawIfPossible"));
1049 EXPECT_TRUE(client->HasAction("ScheduledActionPrepareTiles")); 1061 EXPECT_TRUE(client->HasAction("ScheduledActionPrepareTiles"));
1050 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); 1062 EXPECT_FALSE(client_->IsInsideBeginImplFrame());
1051 } 1063 }
1052 1064
1053 // Test that PrepareTiles only happens once per frame. If an external caller 1065 // Test that PrepareTiles only happens once per frame. If an external caller
1054 // initiates it, then the state machine should not PrepareTiles on that frame. 1066 // initiates it, then the state machine should not PrepareTiles on that frame.
1055 TEST_F(SchedulerTest, PrepareTilesOncePerFrame) { 1067 TEST_F(SchedulerTest, PrepareTilesOncePerFrame) {
1056 SetUpScheduler(EXTERNAL_BFS); 1068 SetUpScheduler(EXTERNAL_BFS);
1057 1069
1058 // If DidPrepareTiles during a frame, then PrepareTiles should not occur 1070 // If DidPrepareTiles during a frame, then PrepareTiles should not occur
1059 // again. 1071 // again.
1060 scheduler_->SetNeedsPrepareTiles(); 1072 scheduler_->SetNeedsPrepareTiles();
1061 scheduler_->SetNeedsRedraw(); 1073 scheduler_->SetNeedsRedraw();
1062 client_->Reset(); 1074 client_->Reset();
1063 EXPECT_SCOPED(AdvanceFrame()); 1075 EXPECT_SCOPED(AdvanceFrame());
1064 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 1); 1076 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2);
1077 EXPECT_ACTION("ScheduledActionDoShortIdleWork", client_, 1, 2);
1065 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); 1078 EXPECT_TRUE(client_->IsInsideBeginImplFrame());
1066 1079
1067 EXPECT_TRUE(scheduler_->PrepareTilesPending()); 1080 EXPECT_TRUE(scheduler_->PrepareTilesPending());
1068 scheduler_->WillPrepareTiles(); 1081 scheduler_->WillPrepareTiles();
1069 scheduler_->DidPrepareTiles(); // An explicit PrepareTiles. 1082 scheduler_->DidPrepareTiles(); // An explicit PrepareTiles.
1070 EXPECT_FALSE(scheduler_->PrepareTilesPending()); 1083 EXPECT_FALSE(scheduler_->PrepareTilesPending());
1071 1084
1072 client_->Reset(); 1085 client_->Reset();
1073 task_runner().RunPendingTasks(); // Run posted deadline. 1086 task_runner().RunPendingTasks(); // Run posted deadline.
1074 EXPECT_EQ(1, client_->num_draws()); 1087 EXPECT_EQ(1, client_->num_draws());
1075 EXPECT_TRUE(client_->HasAction("ScheduledActionDrawIfPossible")); 1088 EXPECT_TRUE(client_->HasAction("ScheduledActionDrawIfPossible"));
1076 EXPECT_FALSE(client_->HasAction("ScheduledActionPrepareTiles")); 1089 EXPECT_FALSE(client_->HasAction("ScheduledActionPrepareTiles"));
1077 EXPECT_FALSE(scheduler_->RedrawPending()); 1090 EXPECT_FALSE(scheduler_->RedrawPending());
1078 EXPECT_FALSE(scheduler_->PrepareTilesPending()); 1091 EXPECT_FALSE(scheduler_->PrepareTilesPending());
1079 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); 1092 EXPECT_FALSE(client_->IsInsideBeginImplFrame());
1080 1093
1081 // Next frame without DidPrepareTiles should PrepareTiles with draw. 1094 // Next frame without DidPrepareTiles should PrepareTiles with draw.
1082 scheduler_->SetNeedsPrepareTiles(); 1095 scheduler_->SetNeedsPrepareTiles();
1083 scheduler_->SetNeedsRedraw(); 1096 scheduler_->SetNeedsRedraw();
1084 client_->Reset(); 1097 client_->Reset();
1085 EXPECT_SCOPED(AdvanceFrame()); 1098 EXPECT_SCOPED(AdvanceFrame());
1086 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 1); 1099 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2);
1100 EXPECT_ACTION("ScheduledActionDoShortIdleWork", client_, 1, 2);
1087 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); 1101 EXPECT_TRUE(client_->IsInsideBeginImplFrame());
1088 1102
1089 client_->Reset(); 1103 client_->Reset();
1090 task_runner().RunPendingTasks(); // Run posted deadline. 1104 task_runner().RunPendingTasks(); // Run posted deadline.
1091 EXPECT_EQ(1, client_->num_draws()); 1105 EXPECT_EQ(1, client_->num_draws());
1092 EXPECT_TRUE(client_->HasAction("ScheduledActionDrawIfPossible")); 1106 EXPECT_TRUE(client_->HasAction("ScheduledActionDrawIfPossible"));
1093 EXPECT_TRUE(client_->HasAction("ScheduledActionPrepareTiles")); 1107 EXPECT_TRUE(client_->HasAction("ScheduledActionPrepareTiles"));
1094 EXPECT_LT(client_->ActionIndex("ScheduledActionDrawIfPossible"), 1108 EXPECT_LT(client_->ActionIndex("ScheduledActionDrawIfPossible"),
1095 client_->ActionIndex("ScheduledActionPrepareTiles")); 1109 client_->ActionIndex("ScheduledActionPrepareTiles"));
1096 EXPECT_FALSE(scheduler_->RedrawPending()); 1110 EXPECT_FALSE(scheduler_->RedrawPending());
1097 EXPECT_FALSE(scheduler_->PrepareTilesPending()); 1111 EXPECT_FALSE(scheduler_->PrepareTilesPending());
1098 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); 1112 EXPECT_FALSE(client_->IsInsideBeginImplFrame());
1099 1113
1100 // If we get another DidPrepareTiles within the same frame, we should 1114 // If we get another DidPrepareTiles within the same frame, we should
1101 // not PrepareTiles on the next frame. 1115 // not PrepareTiles on the next frame.
1102 scheduler_->WillPrepareTiles(); 1116 scheduler_->WillPrepareTiles();
1103 scheduler_->DidPrepareTiles(); // An explicit PrepareTiles. 1117 scheduler_->DidPrepareTiles(); // An explicit PrepareTiles.
1104 scheduler_->SetNeedsPrepareTiles(); 1118 scheduler_->SetNeedsPrepareTiles();
1105 scheduler_->SetNeedsRedraw(); 1119 scheduler_->SetNeedsRedraw();
1106 client_->Reset(); 1120 client_->Reset();
1107 EXPECT_SCOPED(AdvanceFrame()); 1121 EXPECT_SCOPED(AdvanceFrame());
1108 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 1); 1122 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2);
1123 EXPECT_ACTION("ScheduledActionDoShortIdleWork", client_, 1, 2);
1109 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); 1124 EXPECT_TRUE(client_->IsInsideBeginImplFrame());
1110 1125
1111 EXPECT_TRUE(scheduler_->PrepareTilesPending()); 1126 EXPECT_TRUE(scheduler_->PrepareTilesPending());
1112 1127
1113 client_->Reset(); 1128 client_->Reset();
1114 task_runner().RunPendingTasks(); // Run posted deadline. 1129 task_runner().RunPendingTasks(); // Run posted deadline.
1115 EXPECT_EQ(1, client_->num_draws()); 1130 EXPECT_EQ(1, client_->num_draws());
1116 EXPECT_TRUE(client_->HasAction("ScheduledActionDrawIfPossible")); 1131 EXPECT_TRUE(client_->HasAction("ScheduledActionDrawIfPossible"));
1117 EXPECT_FALSE(client_->HasAction("ScheduledActionPrepareTiles")); 1132 EXPECT_FALSE(client_->HasAction("ScheduledActionPrepareTiles"));
1118 EXPECT_FALSE(scheduler_->RedrawPending()); 1133 EXPECT_FALSE(scheduler_->RedrawPending());
1119 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); 1134 EXPECT_FALSE(client_->IsInsideBeginImplFrame());
1120 1135
1121 // If we get another DidPrepareTiles, we should not PrepareTiles on the next 1136 // If we get another DidPrepareTiles, we should not PrepareTiles on the next
1122 // frame. This verifies we don't alternate calling PrepareTiles once and 1137 // frame. This verifies we don't alternate calling PrepareTiles once and
1123 // twice. 1138 // twice.
1124 EXPECT_TRUE(scheduler_->PrepareTilesPending()); 1139 EXPECT_TRUE(scheduler_->PrepareTilesPending());
1125 scheduler_->WillPrepareTiles(); 1140 scheduler_->WillPrepareTiles();
1126 scheduler_->DidPrepareTiles(); // An explicit PrepareTiles. 1141 scheduler_->DidPrepareTiles(); // An explicit PrepareTiles.
1127 EXPECT_FALSE(scheduler_->PrepareTilesPending()); 1142 EXPECT_FALSE(scheduler_->PrepareTilesPending());
1128 scheduler_->SetNeedsPrepareTiles(); 1143 scheduler_->SetNeedsPrepareTiles();
1129 scheduler_->SetNeedsRedraw(); 1144 scheduler_->SetNeedsRedraw();
1130 client_->Reset(); 1145 client_->Reset();
1131 EXPECT_SCOPED(AdvanceFrame()); 1146 EXPECT_SCOPED(AdvanceFrame());
1132 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 1); 1147 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2);
1148 EXPECT_ACTION("ScheduledActionDoShortIdleWork", client_, 1, 2);
1133 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); 1149 EXPECT_TRUE(client_->IsInsideBeginImplFrame());
1134 1150
1135 EXPECT_TRUE(scheduler_->PrepareTilesPending()); 1151 EXPECT_TRUE(scheduler_->PrepareTilesPending());
1136 1152
1137 client_->Reset(); 1153 client_->Reset();
1138 task_runner().RunPendingTasks(); // Run posted deadline. 1154 task_runner().RunPendingTasks(); // Run posted deadline.
1139 EXPECT_EQ(1, client_->num_draws()); 1155 EXPECT_EQ(1, client_->num_draws());
1140 EXPECT_TRUE(client_->HasAction("ScheduledActionDrawIfPossible")); 1156 EXPECT_TRUE(client_->HasAction("ScheduledActionDrawIfPossible"));
1141 EXPECT_FALSE(client_->HasAction("ScheduledActionPrepareTiles")); 1157 EXPECT_FALSE(client_->HasAction("ScheduledActionPrepareTiles"));
1142 EXPECT_FALSE(scheduler_->RedrawPending()); 1158 EXPECT_FALSE(scheduler_->RedrawPending());
1143 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); 1159 EXPECT_FALSE(client_->IsInsideBeginImplFrame());
1144 1160
1145 // Next frame without DidPrepareTiles should PrepareTiles with draw. 1161 // Next frame without DidPrepareTiles should PrepareTiles with draw.
1146 scheduler_->SetNeedsPrepareTiles(); 1162 scheduler_->SetNeedsPrepareTiles();
1147 scheduler_->SetNeedsRedraw(); 1163 scheduler_->SetNeedsRedraw();
1148 client_->Reset(); 1164 client_->Reset();
1149 EXPECT_SCOPED(AdvanceFrame()); 1165 EXPECT_SCOPED(AdvanceFrame());
1150 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 1); 1166 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2);
1167 EXPECT_ACTION("ScheduledActionDoShortIdleWork", client_, 1, 2);
1151 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); 1168 EXPECT_TRUE(client_->IsInsideBeginImplFrame());
1152 1169
1153 client_->Reset(); 1170 client_->Reset();
1154 task_runner().RunPendingTasks(); // Run posted deadline. 1171 task_runner().RunPendingTasks(); // Run posted deadline.
1155 EXPECT_EQ(1, client_->num_draws()); 1172 EXPECT_EQ(1, client_->num_draws());
1156 EXPECT_TRUE(client_->HasAction("ScheduledActionDrawIfPossible")); 1173 EXPECT_TRUE(client_->HasAction("ScheduledActionDrawIfPossible"));
1157 EXPECT_TRUE(client_->HasAction("ScheduledActionPrepareTiles")); 1174 EXPECT_TRUE(client_->HasAction("ScheduledActionPrepareTiles"));
1158 EXPECT_LT(client_->ActionIndex("ScheduledActionDrawIfPossible"), 1175 EXPECT_LT(client_->ActionIndex("ScheduledActionDrawIfPossible"),
1159 client_->ActionIndex("ScheduledActionPrepareTiles")); 1176 client_->ActionIndex("ScheduledActionPrepareTiles"));
1160 EXPECT_FALSE(scheduler_->RedrawPending()); 1177 EXPECT_FALSE(scheduler_->RedrawPending());
(...skipping 16 matching lines...) Expand all
1177 scheduler_->WillPrepareTiles(); 1194 scheduler_->WillPrepareTiles();
1178 scheduler_->DidPrepareTiles(); 1195 scheduler_->DidPrepareTiles();
1179 } 1196 }
1180 1197
1181 client_->Reset(); 1198 client_->Reset();
1182 scheduler_->SetNeedsRedraw(); 1199 scheduler_->SetNeedsRedraw();
1183 EXPECT_SINGLE_ACTION("AddObserver(this)", client_); 1200 EXPECT_SINGLE_ACTION("AddObserver(this)", client_);
1184 1201
1185 client_->Reset(); 1202 client_->Reset();
1186 AdvanceFrame(); 1203 AdvanceFrame();
1187 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 1); 1204 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2);
1205 EXPECT_ACTION("ScheduledActionDoShortIdleWork", client_, 1, 2);
1188 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); 1206 EXPECT_TRUE(client_->IsInsideBeginImplFrame());
1189 1207
1190 client_->Reset(); 1208 client_->Reset();
1191 task_runner().RunTasksWhile(client_->InsideBeginImplFrame(true)); 1209 task_runner().RunTasksWhile(client_->InsideBeginImplFrame(true));
1192 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); 1210 EXPECT_FALSE(client_->IsInsideBeginImplFrame());
1193 EXPECT_ACTION("ScheduledActionDrawIfPossible", client_, 0, 2); 1211 EXPECT_ACTION("ScheduledActionDrawIfPossible", client_, 0, 2);
1194 EXPECT_ACTION("ScheduledActionPrepareTiles", client_, 1, 2); 1212 EXPECT_ACTION("ScheduledActionPrepareTiles", client_, 1, 2);
1195 } 1213 }
1196 1214
1197 TEST_F(SchedulerTest, TriggerBeginFrameDeadlineEarly) { 1215 TEST_F(SchedulerTest, TriggerBeginFrameDeadlineEarly) {
(...skipping 466 matching lines...) Expand 10 before | Expand all | Expand 10 after
1664 // still expect to recover impl thread latency if there are no commits from 1682 // still expect to recover impl thread latency if there are no commits from
1665 // the main thread. 1683 // the main thread.
1666 fake_compositor_timing_history_->SetAllEstimatesTo(kSlowDuration); 1684 fake_compositor_timing_history_->SetAllEstimatesTo(kSlowDuration);
1667 fake_compositor_timing_history_->SetDrawDurationEstimate(kFastDuration); 1685 fake_compositor_timing_history_->SetDrawDurationEstimate(kFastDuration);
1668 1686
1669 // Draw and swap for first BeginFrame 1687 // Draw and swap for first BeginFrame
1670 client_->Reset(); 1688 client_->Reset();
1671 scheduler_->SetNeedsRedraw(); 1689 scheduler_->SetNeedsRedraw();
1672 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); 1690 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline());
1673 SendNextBeginFrame(); 1691 SendNextBeginFrame();
1674 EXPECT_ACTION("AddObserver(this)", client_, 0, 2); 1692 EXPECT_ACTION("AddObserver(this)", client_, 0, 3);
1675 EXPECT_ACTION("WillBeginImplFrame", client_, 1, 2); 1693 EXPECT_ACTION("WillBeginImplFrame", client_, 1, 3);
1694 EXPECT_ACTION("ScheduledActionDoShortIdleWork", client_, 2, 3);
1676 1695
1677 client_->Reset(); 1696 client_->Reset();
1678 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); 1697 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline());
1679 task_runner().RunTasksWhile(client_->InsideBeginImplFrame(true)); 1698 task_runner().RunTasksWhile(client_->InsideBeginImplFrame(true));
1680 EXPECT_SINGLE_ACTION("ScheduledActionDrawIfPossible", client_); 1699 EXPECT_SINGLE_ACTION("ScheduledActionDrawIfPossible", client_);
1681 1700
1682 // Verify we skip every other frame if the swap ack consistently 1701 // Verify we skip every other frame if the swap ack consistently
1683 // comes back late. 1702 // comes back late.
1684 for (int i = 0; i < 10; i++) { 1703 for (int i = 0; i < 10; i++) {
1685 // Not calling scheduler_->DidReceiveCompositorFrameAck() until after next 1704 // Not calling scheduler_->DidReceiveCompositorFrameAck() until after next
(...skipping 11 matching lines...) Expand all
1697 // swap throttled. 1716 // swap throttled.
1698 client_->Reset(); 1717 client_->Reset();
1699 scheduler_->DidReceiveCompositorFrameAck(); 1718 scheduler_->DidReceiveCompositorFrameAck();
1700 EXPECT_NO_ACTION(client_); 1719 EXPECT_NO_ACTION(client_);
1701 1720
1702 // Verify that we start the next BeginImplFrame and continue normally 1721 // Verify that we start the next BeginImplFrame and continue normally
1703 // after having just skipped a BeginImplFrame. 1722 // after having just skipped a BeginImplFrame.
1704 client_->Reset(); 1723 client_->Reset();
1705 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); 1724 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline());
1706 SendNextBeginFrame(); 1725 SendNextBeginFrame();
1707 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 1); 1726 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2);
1727 EXPECT_ACTION("ScheduledActionDoShortIdleWork", client_, 1, 2);
1708 1728
1709 client_->Reset(); 1729 client_->Reset();
1710 // Deadline should be immediate. 1730 // Deadline should be immediate.
1711 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); 1731 EXPECT_TRUE(client_->IsInsideBeginImplFrame());
1712 task_runner().RunUntilTime(now_src_->NowTicks()); 1732 task_runner().RunUntilTime(now_src_->NowTicks());
1713 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); 1733 EXPECT_FALSE(client_->IsInsideBeginImplFrame());
1714 EXPECT_SINGLE_ACTION("ScheduledActionDrawIfPossible", client_); 1734 EXPECT_SINGLE_ACTION("ScheduledActionDrawIfPossible", client_);
1715 } 1735 }
1716 } 1736 }
1717 1737
(...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after
2075 // Can't run the deadline task because it can race with begin frame for the 2095 // Can't run the deadline task because it can race with begin frame for the
2076 // SyntheticBFS case. 2096 // SyntheticBFS case.
2077 EXPECT_SCOPED(AdvanceFrame()); 2097 EXPECT_SCOPED(AdvanceFrame());
2078 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 1); 2098 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 1);
2079 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); 2099 EXPECT_TRUE(client_->IsInsideBeginImplFrame());
2080 client_->Reset(); 2100 client_->Reset();
2081 2101
2082 // NotifyReadyToCommit should trigger the commit. 2102 // NotifyReadyToCommit should trigger the commit.
2083 scheduler_->NotifyBeginMainFrameStarted(base::TimeTicks()); 2103 scheduler_->NotifyBeginMainFrameStarted(base::TimeTicks());
2084 scheduler_->NotifyReadyToCommit(); 2104 scheduler_->NotifyReadyToCommit();
2085 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_); 2105 EXPECT_ACTION("ScheduledActionCommit", client_, 0, 2);
2106 EXPECT_ACTION("ScheduledActionDoShortIdleWork", client_, 1, 2);
2086 client_->Reset(); 2107 client_->Reset();
2087 2108
2088 // NotifyReadyToActivate should trigger the activation. 2109 // NotifyReadyToActivate should trigger the activation.
2089 scheduler_->NotifyReadyToActivate(); 2110 scheduler_->NotifyReadyToActivate();
2090 EXPECT_SINGLE_ACTION("ScheduledActionActivateSyncTree", client_); 2111 EXPECT_SINGLE_ACTION("ScheduledActionActivateSyncTree", client_);
2091 client_->Reset(); 2112 client_->Reset();
2092 2113
2093 // BeginImplFrame deadline should draw. The following BeginImplFrame deadline 2114 // BeginImplFrame deadline should draw. The following BeginImplFrame deadline
2094 // should SetNeedsBeginFrame(false) to avoid excessive toggles. 2115 // should SetNeedsBeginFrame(false) to avoid excessive toggles.
2095 EXPECT_SCOPED(AdvanceFrame()); 2116 EXPECT_SCOPED(AdvanceFrame());
2096 EXPECT_ACTION("ScheduledActionDrawIfPossible", client_, 0, 2); 2117 EXPECT_ACTION("ScheduledActionDrawIfPossible", client_, 0, 3);
2097 EXPECT_ACTION("WillBeginImplFrame", client_, 1, 2); 2118 EXPECT_ACTION("WillBeginImplFrame", client_, 1, 3);
2119 EXPECT_ACTION("ScheduledActionDoShortIdleWork", client_, 2, 3);
2098 client_->Reset(); 2120 client_->Reset();
2099 2121
2100 // Make sure SetNeedsBeginFrame isn't called on the client 2122 // Make sure SetNeedsBeginFrame isn't called on the client
2101 // when the BeginFrame is no longer needed. 2123 // when the BeginFrame is no longer needed.
2102 task_runner().RunPendingTasks(); // Run posted deadline. 2124 task_runner().RunPendingTasks(); // Run posted deadline.
2103 EXPECT_SINGLE_ACTION("SendBeginMainFrameNotExpectedSoon", client_); 2125 EXPECT_SINGLE_ACTION("SendBeginMainFrameNotExpectedSoon", client_);
2104 client_->Reset(); 2126 client_->Reset();
2105 } 2127 }
2106 2128
2107 TEST_F(SchedulerTest, SyntheticBeginFrames) { 2129 TEST_F(SchedulerTest, SyntheticBeginFrames) {
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
2338 2360
2339 TEST_F(SchedulerTest, DidLoseCompositorFrameSinkAfterSetNeedsPrepareTiles) { 2361 TEST_F(SchedulerTest, DidLoseCompositorFrameSinkAfterSetNeedsPrepareTiles) {
2340 SetUpScheduler(EXTERNAL_BFS); 2362 SetUpScheduler(EXTERNAL_BFS);
2341 2363
2342 scheduler_->SetNeedsPrepareTiles(); 2364 scheduler_->SetNeedsPrepareTiles();
2343 scheduler_->SetNeedsRedraw(); 2365 scheduler_->SetNeedsRedraw();
2344 EXPECT_SINGLE_ACTION("AddObserver(this)", client_); 2366 EXPECT_SINGLE_ACTION("AddObserver(this)", client_);
2345 2367
2346 client_->Reset(); 2368 client_->Reset();
2347 EXPECT_SCOPED(AdvanceFrame()); 2369 EXPECT_SCOPED(AdvanceFrame());
2348 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 1); 2370 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2);
2371 EXPECT_ACTION("ScheduledActionDoShortIdleWork", client_, 1, 2);
2349 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); 2372 EXPECT_TRUE(client_->IsInsideBeginImplFrame());
2350 2373
2351 client_->Reset(); 2374 client_->Reset();
2352 scheduler_->DidLoseCompositorFrameSink(); 2375 scheduler_->DidLoseCompositorFrameSink();
2353 // RemoveObserver(this) is not called until the end of the frame. 2376 // RemoveObserver(this) is not called until the end of the frame.
2354 EXPECT_NO_ACTION(client_); 2377 EXPECT_NO_ACTION(client_);
2355 2378
2356 client_->Reset(); 2379 client_->Reset();
2357 task_runner().RunTasksWhile(client_->InsideBeginImplFrame(true)); 2380 task_runner().RunTasksWhile(client_->InsideBeginImplFrame(true));
2358 EXPECT_ACTION("ScheduledActionPrepareTiles", client_, 0, 4); 2381 EXPECT_ACTION("ScheduledActionPrepareTiles", client_, 0, 4);
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
2499 // Tests to ensure frame sources can be successfully changed while drawing. 2522 // Tests to ensure frame sources can be successfully changed while drawing.
2500 TEST_F(SchedulerTest, SwitchFrameSourceToUnthrottled) { 2523 TEST_F(SchedulerTest, SwitchFrameSourceToUnthrottled) {
2501 SetUpScheduler(EXTERNAL_BFS); 2524 SetUpScheduler(EXTERNAL_BFS);
2502 2525
2503 // SetNeedsRedraw should begin the frame on the next BeginImplFrame. 2526 // SetNeedsRedraw should begin the frame on the next BeginImplFrame.
2504 scheduler_->SetNeedsRedraw(); 2527 scheduler_->SetNeedsRedraw();
2505 EXPECT_SINGLE_ACTION("AddObserver(this)", client_); 2528 EXPECT_SINGLE_ACTION("AddObserver(this)", client_);
2506 client_->Reset(); 2529 client_->Reset();
2507 2530
2508 EXPECT_SCOPED(AdvanceFrame()); 2531 EXPECT_SCOPED(AdvanceFrame());
2509 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 1); 2532 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2);
2533 EXPECT_ACTION("ScheduledActionDoShortIdleWork", client_, 1, 2);
2510 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); 2534 EXPECT_TRUE(client_->IsInsideBeginImplFrame());
2511 EXPECT_TRUE(scheduler_->begin_frames_expected()); 2535 EXPECT_TRUE(scheduler_->begin_frames_expected());
2512 client_->Reset(); 2536 client_->Reset();
2513 task_runner().RunPendingTasks(); // Run posted deadline. 2537 task_runner().RunPendingTasks(); // Run posted deadline.
2514 EXPECT_ACTION("ScheduledActionDrawIfPossible", client_, 0, 1); 2538 EXPECT_ACTION("ScheduledActionDrawIfPossible", client_, 0, 1);
2515 scheduler_->SetNeedsRedraw(); 2539 scheduler_->SetNeedsRedraw();
2516 2540
2517 // Switch to an unthrottled frame source. 2541 // Switch to an unthrottled frame source.
2518 scheduler_->SetBeginFrameSource(unthrottled_frame_source_.get()); 2542 scheduler_->SetBeginFrameSource(unthrottled_frame_source_.get());
2519 client_->Reset(); 2543 client_->Reset();
2520 2544
2521 // Unthrottled frame source will immediately begin a new frame. 2545 // Unthrottled frame source will immediately begin a new frame.
2522 task_runner().RunPendingTasks(); // Run posted BeginFrame. 2546 task_runner().RunPendingTasks(); // Run posted BeginFrame.
2523 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 1); 2547 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2);
2548 EXPECT_ACTION("ScheduledActionDoShortIdleWork", client_, 1, 2);
2524 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); 2549 EXPECT_TRUE(client_->IsInsideBeginImplFrame());
2525 client_->Reset(); 2550 client_->Reset();
2526 2551
2527 // If we don't swap on the deadline, we wait for the next BeginFrame. 2552 // If we don't swap on the deadline, we wait for the next BeginFrame.
2528 task_runner().RunPendingTasks(); // Run posted deadline. 2553 task_runner().RunPendingTasks(); // Run posted deadline.
2529 EXPECT_ACTION("ScheduledActionDrawIfPossible", client_, 0, 1); 2554 EXPECT_ACTION("ScheduledActionDrawIfPossible", client_, 0, 1);
2530 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); 2555 EXPECT_FALSE(client_->IsInsideBeginImplFrame());
2531 client_->Reset(); 2556 client_->Reset();
2532 } 2557 }
2533 2558
2534 // Tests to ensure frame sources can be successfully changed while a frame 2559 // Tests to ensure frame sources can be successfully changed while a frame
2535 // deadline is pending. 2560 // deadline is pending.
2536 TEST_F(SchedulerTest, SwitchFrameSourceToUnthrottledBeforeDeadline) { 2561 TEST_F(SchedulerTest, SwitchFrameSourceToUnthrottledBeforeDeadline) {
2537 SetUpScheduler(EXTERNAL_BFS); 2562 SetUpScheduler(EXTERNAL_BFS);
2538 2563
2539 // SetNeedsRedraw should begin the frame on the next BeginImplFrame. 2564 // SetNeedsRedraw should begin the frame on the next BeginImplFrame.
2540 scheduler_->SetNeedsRedraw(); 2565 scheduler_->SetNeedsRedraw();
2541 EXPECT_SINGLE_ACTION("AddObserver(this)", client_); 2566 EXPECT_SINGLE_ACTION("AddObserver(this)", client_);
2542 client_->Reset(); 2567 client_->Reset();
2543 2568
2544 EXPECT_SCOPED(AdvanceFrame()); 2569 EXPECT_SCOPED(AdvanceFrame());
2545 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client_); 2570 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2);
2571 EXPECT_ACTION("ScheduledActionDoShortIdleWork", client_, 1, 2);
2546 2572
2547 // Switch to an unthrottled frame source before the frame deadline is hit. 2573 // Switch to an unthrottled frame source before the frame deadline is hit.
2548 scheduler_->SetBeginFrameSource(unthrottled_frame_source_.get()); 2574 scheduler_->SetBeginFrameSource(unthrottled_frame_source_.get());
2549 client_->Reset(); 2575 client_->Reset();
2550 2576
2551 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); 2577 EXPECT_TRUE(client_->IsInsideBeginImplFrame());
2552 EXPECT_TRUE(scheduler_->begin_frames_expected()); 2578 EXPECT_TRUE(scheduler_->begin_frames_expected());
2553 client_->Reset(); 2579 client_->Reset();
2554 2580
2555 task_runner().RunPendingTasks(); // Run posted deadline. 2581 task_runner().RunPendingTasks(); // Run posted deadline.
2556 EXPECT_ACTION("ScheduledActionDrawIfPossible", client_, 0, 2); 2582 EXPECT_ACTION("ScheduledActionDrawIfPossible", client_, 0, 3);
2557 // Unthrottled frame source will immediately begin a new frame. 2583 // Unthrottled frame source will immediately begin a new frame.
2558 EXPECT_ACTION("WillBeginImplFrame", client_, 1, 2); 2584 EXPECT_ACTION("WillBeginImplFrame", client_, 1, 3);
2585 EXPECT_ACTION("ScheduledActionDoShortIdleWork", client_, 2, 3);
2559 scheduler_->SetNeedsRedraw(); 2586 scheduler_->SetNeedsRedraw();
2560 client_->Reset(); 2587 client_->Reset();
2561 2588
2562 task_runner().RunPendingTasks(); // Run posted deadline. 2589 task_runner().RunPendingTasks(); // Run posted deadline.
2563 EXPECT_SINGLE_ACTION("ScheduledActionDrawIfPossible", client_); 2590 EXPECT_SINGLE_ACTION("ScheduledActionDrawIfPossible", client_);
2564 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); 2591 EXPECT_FALSE(client_->IsInsideBeginImplFrame());
2565 client_->Reset(); 2592 client_->Reset();
2566 } 2593 }
2567 2594
2568 // Tests to ensure that the active frame source can successfully be changed from 2595 // Tests to ensure that the active frame source can successfully be changed from
2569 // unthrottled to throttled. 2596 // unthrottled to throttled.
2570 TEST_F(SchedulerTest, SwitchFrameSourceToThrottled) { 2597 TEST_F(SchedulerTest, SwitchFrameSourceToThrottled) {
2571 SetUpScheduler(UNTHROTTLED_BFS); 2598 SetUpScheduler(UNTHROTTLED_BFS);
2572 2599
2573 scheduler_->SetNeedsRedraw(); 2600 scheduler_->SetNeedsRedraw();
2574 EXPECT_NO_ACTION(client_); 2601 EXPECT_NO_ACTION(client_);
2575 client_->Reset(); 2602 client_->Reset();
2576 2603
2577 task_runner().RunPendingTasks(); // Run posted BeginFrame. 2604 task_runner().RunPendingTasks(); // Run posted BeginFrame.
2578 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 1); 2605 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2);
2606 EXPECT_ACTION("ScheduledActionDoShortIdleWork", client_, 1, 2);
2579 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); 2607 EXPECT_TRUE(client_->IsInsideBeginImplFrame());
2580 client_->Reset(); 2608 client_->Reset();
2581 2609
2582 task_runner().RunPendingTasks(); // Run posted deadline. 2610 task_runner().RunPendingTasks(); // Run posted deadline.
2583 EXPECT_ACTION("ScheduledActionDrawIfPossible", client_, 0, 1); 2611 EXPECT_ACTION("ScheduledActionDrawIfPossible", client_, 0, 1);
2584 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); 2612 EXPECT_FALSE(client_->IsInsideBeginImplFrame());
2585 client_->Reset(); 2613 client_->Reset();
2586 2614
2587 // Switch to a throttled frame source. 2615 // Switch to a throttled frame source.
2588 scheduler_->SetBeginFrameSource(fake_external_begin_frame_source_.get()); 2616 scheduler_->SetBeginFrameSource(fake_external_begin_frame_source_.get());
2589 client_->Reset(); 2617 client_->Reset();
2590 2618
2591 // SetNeedsRedraw should begin the frame on the next BeginImplFrame. 2619 // SetNeedsRedraw should begin the frame on the next BeginImplFrame.
2592 scheduler_->SetNeedsRedraw(); 2620 scheduler_->SetNeedsRedraw();
2593 task_runner().RunPendingTasks(); 2621 task_runner().RunPendingTasks();
2594 EXPECT_NO_ACTION(client_); 2622 EXPECT_NO_ACTION(client_);
2595 client_->Reset(); 2623 client_->Reset();
2596 2624
2597 EXPECT_SCOPED(AdvanceFrame()); 2625 EXPECT_SCOPED(AdvanceFrame());
2598 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 1); 2626 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2);
2627 EXPECT_ACTION("ScheduledActionDoShortIdleWork", client_, 1, 2);
2599 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); 2628 EXPECT_TRUE(client_->IsInsideBeginImplFrame());
2600 EXPECT_TRUE(scheduler_->begin_frames_expected()); 2629 EXPECT_TRUE(scheduler_->begin_frames_expected());
2601 client_->Reset(); 2630 client_->Reset();
2602 task_runner().RunPendingTasks(); // Run posted deadline. 2631 task_runner().RunPendingTasks(); // Run posted deadline.
2603 EXPECT_ACTION("ScheduledActionDrawIfPossible", client_, 0, 1); 2632 EXPECT_ACTION("ScheduledActionDrawIfPossible", client_, 0, 1);
2604 } 2633 }
2605 2634
2606 TEST_F(SchedulerTest, SwitchFrameSourceToNullInsideDeadline) { 2635 TEST_F(SchedulerTest, SwitchFrameSourceToNullInsideDeadline) {
2607 SetUpScheduler(EXTERNAL_BFS); 2636 SetUpScheduler(EXTERNAL_BFS);
2608 2637
2609 scheduler_->SetNeedsRedraw(); 2638 scheduler_->SetNeedsRedraw();
2610 EXPECT_SINGLE_ACTION("AddObserver(this)", client_); 2639 EXPECT_SINGLE_ACTION("AddObserver(this)", client_);
2611 client_->Reset(); 2640 client_->Reset();
2612 2641
2613 EXPECT_SCOPED(AdvanceFrame()); 2642 EXPECT_SCOPED(AdvanceFrame());
2614 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client_); 2643 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2);
2644 EXPECT_ACTION("ScheduledActionDoShortIdleWork", client_, 1, 2);
2615 client_->Reset(); 2645 client_->Reset();
2616 2646
2617 // Switch to a null frame source. 2647 // Switch to a null frame source.
2618 scheduler_->SetBeginFrameSource(nullptr); 2648 scheduler_->SetBeginFrameSource(nullptr);
2619 EXPECT_SINGLE_ACTION("RemoveObserver(this)", client_); 2649 EXPECT_SINGLE_ACTION("RemoveObserver(this)", client_);
2620 client_->Reset(); 2650 client_->Reset();
2621 2651
2622 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); 2652 EXPECT_TRUE(client_->IsInsideBeginImplFrame());
2623 task_runner().RunPendingTasks(); // Run posted deadline. 2653 task_runner().RunPendingTasks(); // Run posted deadline.
2624 EXPECT_ACTION("ScheduledActionDrawIfPossible", client_, 0, 1); 2654 EXPECT_ACTION("ScheduledActionDrawIfPossible", client_, 0, 1);
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
2726 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 5); 2756 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 5);
2727 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 5); 2757 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 5);
2728 EXPECT_ACTION("ScheduledActionCommit", client_, 2, 5); 2758 EXPECT_ACTION("ScheduledActionCommit", client_, 2, 5);
2729 EXPECT_ACTION("ScheduledActionActivateSyncTree", client_, 3, 5); 2759 EXPECT_ACTION("ScheduledActionActivateSyncTree", client_, 3, 5);
2730 EXPECT_ACTION("ScheduledActionDrawIfPossible", client_, 4, 5); 2760 EXPECT_ACTION("ScheduledActionDrawIfPossible", client_, 4, 5);
2731 client_->Reset(); 2761 client_->Reset();
2732 2762
2733 // The following BeginImplFrame deadline should SetNeedsBeginFrame(false) 2763 // The following BeginImplFrame deadline should SetNeedsBeginFrame(false)
2734 // and send a SendBeginMainFrameNotExpectedSoon. 2764 // and send a SendBeginMainFrameNotExpectedSoon.
2735 EXPECT_SCOPED(AdvanceFrame()); 2765 EXPECT_SCOPED(AdvanceFrame());
2736 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client_); 2766 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2);
2767 EXPECT_ACTION("ScheduledActionDoShortIdleWork", client_, 1, 2);
2737 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); 2768 EXPECT_TRUE(client_->IsInsideBeginImplFrame());
2738 client_->Reset(); 2769 client_->Reset();
2739 2770
2740 task_runner().RunPendingTasks(); // Run posted deadline. 2771 task_runner().RunPendingTasks(); // Run posted deadline.
2741 EXPECT_ACTION("RemoveObserver(this)", client_, 0, 2); 2772 EXPECT_ACTION("RemoveObserver(this)", client_, 0, 2);
2742 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 1, 2); 2773 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 1, 2);
2743 client_->Reset(); 2774 client_->Reset();
2744 } 2775 }
2745 2776
2746 TEST_F(SchedulerTest, SynchronousCompositorAnimation) { 2777 TEST_F(SchedulerTest, SynchronousCompositorAnimation) {
2747 scheduler_settings_.using_synchronous_renderer_compositor = true; 2778 scheduler_settings_.using_synchronous_renderer_compositor = true;
2748 SetUpScheduler(EXTERNAL_BFS); 2779 SetUpScheduler(EXTERNAL_BFS);
2749 2780
2750 scheduler_->SetNeedsOneBeginImplFrame(); 2781 scheduler_->SetNeedsOneBeginImplFrame();
2751 EXPECT_SINGLE_ACTION("AddObserver(this)", client_); 2782 EXPECT_SINGLE_ACTION("AddObserver(this)", client_);
2752 client_->Reset(); 2783 client_->Reset();
2753 2784
2754 // Testing the case where animation ticks a fling scroll. 2785 // Testing the case where animation ticks a fling scroll.
2755 client_->SetWillBeginImplFrameCausesRedraw(true); 2786 client_->SetWillBeginImplFrameCausesRedraw(true);
2756 // The animation isn't done so it'll cause another tick in the future. 2787 // The animation isn't done so it'll cause another tick in the future.
2757 client_->SetWillBeginImplFrameRequestsOneBeginImplFrame(true); 2788 client_->SetWillBeginImplFrameRequestsOneBeginImplFrame(true);
2758 2789
2759 // Next vsync. 2790 // Next vsync.
2760 AdvanceFrame(); 2791 AdvanceFrame();
2761 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); 2792 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 3);
2762 EXPECT_ACTION("ScheduledActionInvalidateCompositorFrameSink", client_, 1, 2); 2793 EXPECT_ACTION("ScheduledActionInvalidateCompositorFrameSink", client_, 2, 3);
2794 EXPECT_ACTION("ScheduledActionDoShortIdleWork", client_, 1, 3);
2763 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); 2795 EXPECT_FALSE(client_->IsInsideBeginImplFrame());
2764 client_->Reset(); 2796 client_->Reset();
2765 2797
2766 // Android onDraw. This doesn't consume the single begin frame request. 2798 // Android onDraw. This doesn't consume the single begin frame request.
2767 scheduler_->SetNeedsRedraw(); 2799 scheduler_->SetNeedsRedraw();
2768 bool resourceless_software_draw = false; 2800 bool resourceless_software_draw = false;
2769 scheduler_->OnDrawForCompositorFrameSink(resourceless_software_draw); 2801 scheduler_->OnDrawForCompositorFrameSink(resourceless_software_draw);
2770 EXPECT_SINGLE_ACTION("ScheduledActionDrawIfPossible", client_); 2802 EXPECT_SINGLE_ACTION("ScheduledActionDrawIfPossible", client_);
2771 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); 2803 EXPECT_FALSE(client_->IsInsideBeginImplFrame());
2772 client_->Reset(); 2804 client_->Reset();
2773 2805
2774 // The animation inside of WillBeginImplFrame changes stuff on the screen, but 2806 // The animation inside of WillBeginImplFrame changes stuff on the screen, but
2775 // ends here, so does not cause another frame to happen. 2807 // ends here, so does not cause another frame to happen.
2776 client_->SetWillBeginImplFrameCausesRedraw(true); 2808 client_->SetWillBeginImplFrameCausesRedraw(true);
2777 2809
2778 // Next vsync. 2810 // Next vsync.
2779 AdvanceFrame(); 2811 AdvanceFrame();
2780 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); 2812 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 3);
2781 EXPECT_ACTION("ScheduledActionInvalidateCompositorFrameSink", client_, 1, 2); 2813 EXPECT_ACTION("ScheduledActionInvalidateCompositorFrameSink", client_, 1, 3);
2814 EXPECT_ACTION("ScheduledActionDoShortIdleWork", client_, 2, 3);
2782 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); 2815 EXPECT_FALSE(client_->IsInsideBeginImplFrame());
2783 client_->Reset(); 2816 client_->Reset();
2784 2817
2785 // Android onDraw. 2818 // Android onDraw.
2786 scheduler_->SetNeedsRedraw(); 2819 scheduler_->SetNeedsRedraw();
2787 scheduler_->OnDrawForCompositorFrameSink(resourceless_software_draw); 2820 scheduler_->OnDrawForCompositorFrameSink(resourceless_software_draw);
2788 EXPECT_SINGLE_ACTION("ScheduledActionDrawIfPossible", client_); 2821 EXPECT_SINGLE_ACTION("ScheduledActionDrawIfPossible", client_);
2789 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); 2822 EXPECT_FALSE(client_->IsInsideBeginImplFrame());
2790 client_->Reset(); 2823 client_->Reset();
2791 2824
2792 // Idle on next vsync, as the animation has completed. 2825 // Idle on next vsync, as the animation has completed.
2793 AdvanceFrame(); 2826 AdvanceFrame();
2794 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 3); 2827 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 4);
2795 EXPECT_ACTION("RemoveObserver(this)", client_, 1, 3); 2828 EXPECT_ACTION("ScheduledActionDoShortIdleWork", client_, 1, 4);
2796 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 2, 3); 2829 EXPECT_ACTION("RemoveObserver(this)", client_, 2, 4);
2830 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 3, 4);
2797 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); 2831 EXPECT_FALSE(client_->IsInsideBeginImplFrame());
2798 client_->Reset(); 2832 client_->Reset();
2799 } 2833 }
2800 2834
2801 TEST_F(SchedulerTest, SynchronousCompositorOnDrawDuringIdle) { 2835 TEST_F(SchedulerTest, SynchronousCompositorOnDrawDuringIdle) {
2802 scheduler_settings_.using_synchronous_renderer_compositor = true; 2836 scheduler_settings_.using_synchronous_renderer_compositor = true;
2803 SetUpScheduler(EXTERNAL_BFS); 2837 SetUpScheduler(EXTERNAL_BFS);
2804 2838
2805 scheduler_->SetNeedsRedraw(); 2839 scheduler_->SetNeedsRedraw();
2806 bool resourceless_software_draw = false; 2840 bool resourceless_software_draw = false;
2807 scheduler_->OnDrawForCompositorFrameSink(resourceless_software_draw); 2841 scheduler_->OnDrawForCompositorFrameSink(resourceless_software_draw);
2808 EXPECT_ACTION("AddObserver(this)", client_, 0, 2); 2842 EXPECT_ACTION("AddObserver(this)", client_, 0, 2);
2809 EXPECT_ACTION("ScheduledActionDrawIfPossible", client_, 1, 2); 2843 EXPECT_ACTION("ScheduledActionDrawIfPossible", client_, 1, 2);
2810 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); 2844 EXPECT_FALSE(client_->IsInsideBeginImplFrame());
2811 client_->Reset(); 2845 client_->Reset();
2812 2846
2813 // Idle on next vsync. 2847 // Idle on next vsync.
2814 AdvanceFrame(); 2848 AdvanceFrame();
2815 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 3); 2849 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 4);
2816 EXPECT_ACTION("RemoveObserver(this)", client_, 1, 3); 2850 EXPECT_ACTION("ScheduledActionDoShortIdleWork", client_, 1, 4);
2817 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 2, 3); 2851 EXPECT_ACTION("RemoveObserver(this)", client_, 2, 4);
2852 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 3, 4);
2818 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); 2853 EXPECT_FALSE(client_->IsInsideBeginImplFrame());
2819 client_->Reset(); 2854 client_->Reset();
2820 } 2855 }
2821 2856
2822 TEST_F(SchedulerTest, SetNeedsOneBeginImplFrame) { 2857 TEST_F(SchedulerTest, SetNeedsOneBeginImplFrame) {
2823 SetUpScheduler(EXTERNAL_BFS); 2858 SetUpScheduler(EXTERNAL_BFS);
2824 2859
2825 EXPECT_FALSE(scheduler_->begin_frames_expected()); 2860 EXPECT_FALSE(scheduler_->begin_frames_expected());
2826 2861
2827 // Request a frame, should kick the source. 2862 // Request a frame, should kick the source.
2828 scheduler_->SetNeedsOneBeginImplFrame(); 2863 scheduler_->SetNeedsOneBeginImplFrame();
2829 EXPECT_SINGLE_ACTION("AddObserver(this)", client_); 2864 EXPECT_SINGLE_ACTION("AddObserver(this)", client_);
2830 client_->Reset(); 2865 client_->Reset();
2831 2866
2832 // The incoming WillBeginImplFrame will request another one. 2867 // The incoming WillBeginImplFrame will request another one.
2833 client_->SetWillBeginImplFrameRequestsOneBeginImplFrame(true); 2868 client_->SetWillBeginImplFrameRequestsOneBeginImplFrame(true);
2834 2869
2835 // Next vsync, the first requested frame happens. 2870 // Next vsync, the first requested frame happens.
2836 EXPECT_SCOPED(AdvanceFrame()); 2871 EXPECT_SCOPED(AdvanceFrame());
2837 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 1); 2872 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2);
2873 EXPECT_ACTION("ScheduledActionDoShortIdleWork", client_, 1, 2);
2838 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); 2874 EXPECT_TRUE(client_->IsInsideBeginImplFrame());
2839 client_->Reset(); 2875 client_->Reset();
2840 2876
2841 // We don't request another frame here. 2877 // We don't request another frame here.
2842 2878
2843 // Next vsync, the second requested frame happens (the one requested inside 2879 // Next vsync, the second requested frame happens (the one requested inside
2844 // the previous frame's begin impl frame step). 2880 // the previous frame's begin impl frame step).
2845 EXPECT_SCOPED(AdvanceFrame()); 2881 EXPECT_SCOPED(AdvanceFrame());
2846 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 1); 2882 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2);
2883 EXPECT_ACTION("ScheduledActionDoShortIdleWork", client_, 1, 2);
2847 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); 2884 EXPECT_TRUE(client_->IsInsideBeginImplFrame());
2848 client_->Reset(); 2885 client_->Reset();
2849 2886
2850 // End that frame's deadline. 2887 // End that frame's deadline.
2851 task_runner_->RunTasksWhile(client_->InsideBeginImplFrame(true)); 2888 task_runner_->RunTasksWhile(client_->InsideBeginImplFrame(true));
2852 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); 2889 EXPECT_FALSE(client_->IsInsideBeginImplFrame());
2853 2890
2854 // Scheduler shuts down the source now that no begin frame is requested. 2891 // Scheduler shuts down the source now that no begin frame is requested.
2855 EXPECT_ACTION("RemoveObserver(this)", client_, 0, 2); 2892 EXPECT_ACTION("RemoveObserver(this)", client_, 0, 2);
2856 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 1, 2); 2893 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 1, 2);
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
2897 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); 2934 EXPECT_FALSE(client_->IsInsideBeginImplFrame());
2898 client_->Reset(); 2935 client_->Reset();
2899 2936
2900 has_damage = false; 2937 has_damage = false;
2901 EXPECT_EQ( 2938 EXPECT_EQ(
2902 BeginFrameAck(args.source_id, args.sequence_number, 2939 BeginFrameAck(args.source_id, args.sequence_number,
2903 latest_confirmed_sequence_number, 0, has_damage), 2940 latest_confirmed_sequence_number, 0, has_damage),
2904 fake_external_begin_frame_source_->LastAckForObserver(scheduler_.get())); 2941 fake_external_begin_frame_source_->LastAckForObserver(scheduler_.get()));
2905 2942
2906 scheduler_->NotifyReadyToCommit(); 2943 scheduler_->NotifyReadyToCommit();
2907 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_); 2944 EXPECT_ACTION("ScheduledActionCommit", client_, 0, 2);
2945 EXPECT_ACTION("ScheduledActionDoShortIdleWork", client_, 1, 2);
2908 client_->Reset(); 2946 client_->Reset();
2909 2947
2910 scheduler_->NotifyReadyToActivate(); 2948 scheduler_->NotifyReadyToActivate();
2911 EXPECT_SINGLE_ACTION("ScheduledActionActivateSyncTree", client_); 2949 EXPECT_SINGLE_ACTION("ScheduledActionActivateSyncTree", client_);
2912 client_->Reset(); 2950 client_->Reset();
2913 2951
2914 // Next vsync. 2952 // Next vsync.
2915 args = SendNextBeginFrame(); 2953 args = SendNextBeginFrame();
2916 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); 2954 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 3);
2917 EXPECT_ACTION("ScheduledActionInvalidateCompositorFrameSink", client_, 1, 2); 2955 EXPECT_ACTION("ScheduledActionInvalidateCompositorFrameSink", client_, 1, 3);
2956 EXPECT_ACTION("ScheduledActionDoShortIdleWork", client_, 2, 3);
2918 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); 2957 EXPECT_FALSE(client_->IsInsideBeginImplFrame());
2919 client_->Reset(); 2958 client_->Reset();
2920 2959
2921 // Not confirmed yet and no damage, since not drawn yet. 2960 // Not confirmed yet and no damage, since not drawn yet.
2922 // TODO(eseckler): In the future, |has_damage = false| will prevent us from 2961 // TODO(eseckler): In the future, |has_damage = false| will prevent us from
2923 // filtering this ack (in CompositorExternalBeginFrameSource) and instead 2962 // filtering this ack (in CompositorExternalBeginFrameSource) and instead
2924 // forwarding the one attached to the later submitted CompositorFrame. 2963 // forwarding the one attached to the later submitted CompositorFrame.
2925 has_damage = false; 2964 has_damage = false;
2926 EXPECT_EQ( 2965 EXPECT_EQ(
2927 BeginFrameAck(args.source_id, args.sequence_number, 2966 BeginFrameAck(args.source_id, args.sequence_number,
2928 latest_confirmed_sequence_number, 0, has_damage), 2967 latest_confirmed_sequence_number, 0, has_damage),
2929 fake_external_begin_frame_source_->LastAckForObserver(scheduler_.get())); 2968 fake_external_begin_frame_source_->LastAckForObserver(scheduler_.get()));
2930 2969
2931 // Android onDraw. 2970 // Android onDraw.
2932 scheduler_->SetNeedsRedraw(); 2971 scheduler_->SetNeedsRedraw();
2933 bool resourceless_software_draw = false; 2972 bool resourceless_software_draw = false;
2934 scheduler_->OnDrawForCompositorFrameSink(resourceless_software_draw); 2973 scheduler_->OnDrawForCompositorFrameSink(resourceless_software_draw);
2935 EXPECT_SINGLE_ACTION("ScheduledActionDrawIfPossible", client_); 2974 EXPECT_SINGLE_ACTION("ScheduledActionDrawIfPossible", client_);
2936 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); 2975 EXPECT_FALSE(client_->IsInsideBeginImplFrame());
2937 client_->Reset(); 2976 client_->Reset();
2938 2977
2939 // Idle on next vsync. 2978 // Idle on next vsync.
2940 args = SendNextBeginFrame(); 2979 args = SendNextBeginFrame();
2941 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 3); 2980 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 4);
2942 EXPECT_ACTION("RemoveObserver(this)", client_, 1, 3); 2981 EXPECT_ACTION("ScheduledActionDoShortIdleWork", client_, 1, 4);
2943 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 2, 3); 2982 EXPECT_ACTION("RemoveObserver(this)", client_, 2, 4);
2983 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 3, 4);
2944 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); 2984 EXPECT_FALSE(client_->IsInsideBeginImplFrame());
2945 client_->Reset(); 2985 client_->Reset();
2946 2986
2947 latest_confirmed_sequence_number = args.sequence_number; 2987 latest_confirmed_sequence_number = args.sequence_number;
2948 has_damage = false; 2988 has_damage = false;
2949 EXPECT_EQ( 2989 EXPECT_EQ(
2950 BeginFrameAck(args.source_id, args.sequence_number, 2990 BeginFrameAck(args.source_id, args.sequence_number,
2951 latest_confirmed_sequence_number, 0, has_damage), 2991 latest_confirmed_sequence_number, 0, has_damage),
2952 fake_external_begin_frame_source_->LastAckForObserver(scheduler_.get())); 2992 fake_external_begin_frame_source_->LastAckForObserver(scheduler_.get()));
2953 } 2993 }
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
3014 std::unique_ptr<FakeSchedulerClient> client = 3054 std::unique_ptr<FakeSchedulerClient> client =
3015 base::WrapUnique(new SchedulerClientSetNeedsPrepareTilesOnDraw); 3055 base::WrapUnique(new SchedulerClientSetNeedsPrepareTilesOnDraw);
3016 SetUpScheduler(EXTERNAL_BFS, std::move(client)); 3056 SetUpScheduler(EXTERNAL_BFS, std::move(client));
3017 3057
3018 scheduler_->SetNeedsRedraw(); 3058 scheduler_->SetNeedsRedraw();
3019 EXPECT_SINGLE_ACTION("AddObserver(this)", client_); 3059 EXPECT_SINGLE_ACTION("AddObserver(this)", client_);
3020 client_->Reset(); 3060 client_->Reset();
3021 3061
3022 // Next vsync. 3062 // Next vsync.
3023 EXPECT_SCOPED(AdvanceFrame()); 3063 EXPECT_SCOPED(AdvanceFrame());
3024 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); 3064 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 3);
3025 EXPECT_ACTION("ScheduledActionInvalidateCompositorFrameSink", client_, 1, 2); 3065 EXPECT_ACTION("ScheduledActionInvalidateCompositorFrameSink", client_, 1, 3);
3066 EXPECT_ACTION("ScheduledActionDoShortIdleWork", client_, 2, 3);
3026 client_->Reset(); 3067 client_->Reset();
3027 3068
3028 // Android onDraw. 3069 // Android onDraw.
3029 scheduler_->SetNeedsRedraw(); 3070 scheduler_->SetNeedsRedraw();
3030 bool resourceless_software_draw = false; 3071 bool resourceless_software_draw = false;
3031 scheduler_->OnDrawForCompositorFrameSink(resourceless_software_draw); 3072 scheduler_->OnDrawForCompositorFrameSink(resourceless_software_draw);
3032 EXPECT_ACTION("ScheduledActionDrawIfPossible", client_, 0, 2); 3073 EXPECT_ACTION("ScheduledActionDrawIfPossible", client_, 0, 2);
3033 EXPECT_ACTION("ScheduledActionPrepareTiles", client_, 1, 2); 3074 EXPECT_ACTION("ScheduledActionPrepareTiles", client_, 1, 2);
3034 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); 3075 EXPECT_FALSE(client_->IsInsideBeginImplFrame());
3035 EXPECT_FALSE(scheduler_->PrepareTilesPending()); 3076 EXPECT_FALSE(scheduler_->PrepareTilesPending());
3036 client_->Reset(); 3077 client_->Reset();
3037 3078
3038 // Android onDraw. 3079 // Android onDraw.
3039 scheduler_->SetNeedsRedraw(); 3080 scheduler_->SetNeedsRedraw();
3040 scheduler_->OnDrawForCompositorFrameSink(resourceless_software_draw); 3081 scheduler_->OnDrawForCompositorFrameSink(resourceless_software_draw);
3041 EXPECT_ACTION("ScheduledActionDrawIfPossible", client_, 0, 2); 3082 EXPECT_ACTION("ScheduledActionDrawIfPossible", client_, 0, 2);
3042 EXPECT_ACTION("ScheduledActionPrepareTiles", client_, 1, 2); 3083 EXPECT_ACTION("ScheduledActionPrepareTiles", client_, 1, 2);
3043 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); 3084 EXPECT_FALSE(client_->IsInsideBeginImplFrame());
3044 EXPECT_FALSE(scheduler_->PrepareTilesPending()); 3085 EXPECT_FALSE(scheduler_->PrepareTilesPending());
3045 client_->Reset(); 3086 client_->Reset();
3046 3087
3047 // Next vsync. 3088 // Next vsync.
3048 EXPECT_SCOPED(AdvanceFrame()); 3089 EXPECT_SCOPED(AdvanceFrame());
3049 EXPECT_FALSE(scheduler_->PrepareTilesPending()); 3090 EXPECT_FALSE(scheduler_->PrepareTilesPending());
3050 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 3); 3091 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 4);
3051 EXPECT_ACTION("RemoveObserver(this)", client_, 1, 3); 3092 EXPECT_ACTION("ScheduledActionDoShortIdleWork", client_, 1, 4);
3052 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 2, 3); 3093 EXPECT_ACTION("RemoveObserver(this)", client_, 2, 4);
3094 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 3, 4);
3053 EXPECT_FALSE(scheduler_->begin_frames_expected()); 3095 EXPECT_FALSE(scheduler_->begin_frames_expected());
3054 client_->Reset(); 3096 client_->Reset();
3055 } 3097 }
3056 3098
3057 TEST_F(SchedulerTest, SynchronousCompositorSendBeginMainFrameWhileIdle) { 3099 TEST_F(SchedulerTest, SynchronousCompositorSendBeginMainFrameWhileIdle) {
3058 scheduler_settings_.using_synchronous_renderer_compositor = true; 3100 scheduler_settings_.using_synchronous_renderer_compositor = true;
3059 SetUpScheduler(EXTERNAL_BFS); 3101 SetUpScheduler(EXTERNAL_BFS);
3060 3102
3061 scheduler_->SetNeedsRedraw(); 3103 scheduler_->SetNeedsRedraw();
3062 EXPECT_SINGLE_ACTION("AddObserver(this)", client_); 3104 EXPECT_SINGLE_ACTION("AddObserver(this)", client_);
3063 client_->Reset(); 3105 client_->Reset();
3064 3106
3065 // Next vsync. 3107 // Next vsync.
3066 EXPECT_SCOPED(AdvanceFrame()); 3108 EXPECT_SCOPED(AdvanceFrame());
3067 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); 3109 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 3);
3068 EXPECT_ACTION("ScheduledActionInvalidateCompositorFrameSink", client_, 1, 2); 3110 EXPECT_ACTION("ScheduledActionInvalidateCompositorFrameSink", client_, 1, 3);
3111 EXPECT_ACTION("ScheduledActionDoShortIdleWork", client_, 2, 3);
3069 client_->Reset(); 3112 client_->Reset();
3070 3113
3071 // Android onDraw. 3114 // Android onDraw.
3072 scheduler_->SetNeedsRedraw(); 3115 scheduler_->SetNeedsRedraw();
3073 bool resourceless_software_draw = false; 3116 bool resourceless_software_draw = false;
3074 scheduler_->OnDrawForCompositorFrameSink(resourceless_software_draw); 3117 scheduler_->OnDrawForCompositorFrameSink(resourceless_software_draw);
3075 EXPECT_SINGLE_ACTION("ScheduledActionDrawIfPossible", client_); 3118 EXPECT_SINGLE_ACTION("ScheduledActionDrawIfPossible", client_);
3076 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); 3119 EXPECT_FALSE(client_->IsInsideBeginImplFrame());
3077 EXPECT_FALSE(scheduler_->PrepareTilesPending()); 3120 EXPECT_FALSE(scheduler_->PrepareTilesPending());
3078 client_->Reset(); 3121 client_->Reset();
3079 3122
3080 // Simulate SetNeedsBeginMainFrame due to input event. 3123 // Simulate SetNeedsBeginMainFrame due to input event.
3081 scheduler_->SetNeedsBeginMainFrame(); 3124 scheduler_->SetNeedsBeginMainFrame();
3082 EXPECT_SINGLE_ACTION("ScheduledActionSendBeginMainFrame", client_); 3125 EXPECT_SINGLE_ACTION("ScheduledActionSendBeginMainFrame", client_);
3083 client_->Reset(); 3126 client_->Reset();
3084 3127
3085 scheduler_->NotifyBeginMainFrameStarted(base::TimeTicks()); 3128 scheduler_->NotifyBeginMainFrameStarted(base::TimeTicks());
3086 scheduler_->NotifyReadyToCommit(); 3129 scheduler_->NotifyReadyToCommit();
3087 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_); 3130 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_);
3088 client_->Reset(); 3131 client_->Reset();
3089 3132
3090 scheduler_->NotifyReadyToActivate(); 3133 scheduler_->NotifyReadyToActivate();
3091 EXPECT_SINGLE_ACTION("ScheduledActionActivateSyncTree", client_); 3134 EXPECT_SINGLE_ACTION("ScheduledActionActivateSyncTree", client_);
3092 client_->Reset(); 3135 client_->Reset();
3093 3136
3094 // Next vsync. 3137 // Next vsync.
3095 EXPECT_SCOPED(AdvanceFrame()); 3138 EXPECT_SCOPED(AdvanceFrame());
3096 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); 3139 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 3);
3097 EXPECT_ACTION("ScheduledActionInvalidateCompositorFrameSink", client_, 1, 2); 3140 EXPECT_ACTION("ScheduledActionInvalidateCompositorFrameSink", client_, 1, 3);
3141 EXPECT_ACTION("ScheduledActionDoShortIdleWork", client_, 2, 3);
3098 client_->Reset(); 3142 client_->Reset();
3099 3143
3100 // Android onDraw. 3144 // Android onDraw.
3101 scheduler_->SetNeedsRedraw(); 3145 scheduler_->SetNeedsRedraw();
3102 scheduler_->OnDrawForCompositorFrameSink(resourceless_software_draw); 3146 scheduler_->OnDrawForCompositorFrameSink(resourceless_software_draw);
3103 EXPECT_SINGLE_ACTION("ScheduledActionDrawIfPossible", client_); 3147 EXPECT_SINGLE_ACTION("ScheduledActionDrawIfPossible", client_);
3104 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); 3148 EXPECT_FALSE(client_->IsInsideBeginImplFrame());
3105 EXPECT_FALSE(scheduler_->PrepareTilesPending()); 3149 EXPECT_FALSE(scheduler_->PrepareTilesPending());
3106 client_->Reset(); 3150 client_->Reset();
3107 3151
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
3222 } 3266 }
3223 3267
3224 TEST_F(SchedulerTest, ImplSideInvalidationsInDeadline) { 3268 TEST_F(SchedulerTest, ImplSideInvalidationsInDeadline) {
3225 SetUpScheduler(EXTERNAL_BFS); 3269 SetUpScheduler(EXTERNAL_BFS);
3226 3270
3227 // Request an impl-side invalidation and trigger the deadline. Ensure that the 3271 // Request an impl-side invalidation and trigger the deadline. Ensure that the
3228 // invalidation runs inside the deadline. 3272 // invalidation runs inside the deadline.
3229 scheduler_->SetNeedsImplSideInvalidation(); 3273 scheduler_->SetNeedsImplSideInvalidation();
3230 client_->Reset(); 3274 client_->Reset();
3231 EXPECT_SCOPED(AdvanceFrame()); 3275 EXPECT_SCOPED(AdvanceFrame());
3232 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client_); 3276 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2);
3277 EXPECT_ACTION("ScheduledActionDoShortIdleWork", client_, 1, 2);
3233 3278
3234 // Deadline. 3279 // Deadline.
3235 client_->Reset(); 3280 client_->Reset();
3236 task_runner_->RunTasksWhile(client_->InsideBeginImplFrame(true)); 3281 task_runner_->RunTasksWhile(client_->InsideBeginImplFrame(true));
3237 EXPECT_SINGLE_ACTION("ScheduledActionPerformImplSideInvalidation", client_); 3282 EXPECT_SINGLE_ACTION("ScheduledActionPerformImplSideInvalidation", client_);
3238 } 3283 }
3239 3284
3240 TEST_F(SchedulerTest, ImplSideInvalidationsMergedWithCommit) { 3285 TEST_F(SchedulerTest, ImplSideInvalidationsMergedWithCommit) {
3241 SetUpScheduler(EXTERNAL_BFS); 3286 SetUpScheduler(EXTERNAL_BFS);
3242 3287
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
3388 last_begin_frame_number, latest_confirmed_sequence_number, 3433 last_begin_frame_number, latest_confirmed_sequence_number,
3389 0, has_damage), 3434 0, has_damage),
3390 fake_external_begin_frame_source_->LastAckForObserver(scheduler_.get())); 3435 fake_external_begin_frame_source_->LastAckForObserver(scheduler_.get()));
3391 3436
3392 // Run a successful redraw and verify that a new ack is sent. 3437 // Run a successful redraw and verify that a new ack is sent.
3393 scheduler_->SetNeedsRedraw(); 3438 scheduler_->SetNeedsRedraw();
3394 client_->Reset(); 3439 client_->Reset();
3395 3440
3396 BeginFrameArgs args = SendNextBeginFrame(); 3441 BeginFrameArgs args = SendNextBeginFrame();
3397 EXPECT_LT(latest_confirmed_sequence_number, args.sequence_number); 3442 EXPECT_LT(latest_confirmed_sequence_number, args.sequence_number);
3398 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 1); 3443 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2);
3444 EXPECT_ACTION("ScheduledActionDoShortIdleWork", client_, 1, 2);
3399 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); 3445 EXPECT_TRUE(client_->IsInsideBeginImplFrame());
3400 EXPECT_TRUE(scheduler_->begin_frames_expected()); 3446 EXPECT_TRUE(scheduler_->begin_frames_expected());
3401 client_->Reset(); 3447 client_->Reset();
3402 3448
3403 task_runner().RunPendingTasks(); // Run posted deadline. 3449 task_runner().RunPendingTasks(); // Run posted deadline.
3404 EXPECT_ACTION("ScheduledActionDrawIfPossible", client_, 0, 1); 3450 EXPECT_ACTION("ScheduledActionDrawIfPossible", client_, 0, 1);
3405 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); 3451 EXPECT_FALSE(client_->IsInsideBeginImplFrame());
3406 EXPECT_TRUE(scheduler_->begin_frames_expected()); 3452 EXPECT_TRUE(scheduler_->begin_frames_expected());
3407 client_->Reset(); 3453 client_->Reset();
3408 3454
3409 // Successful draw caused damage. 3455 // Successful draw caused damage.
3410 latest_confirmed_sequence_number = args.sequence_number; 3456 latest_confirmed_sequence_number = args.sequence_number;
3411 has_damage = true; 3457 has_damage = true;
3412 EXPECT_EQ( 3458 EXPECT_EQ(
3413 BeginFrameAck(args.source_id, args.sequence_number, 3459 BeginFrameAck(args.source_id, args.sequence_number,
3414 latest_confirmed_sequence_number, 0, has_damage), 3460 latest_confirmed_sequence_number, 0, has_damage),
3415 fake_external_begin_frame_source_->LastAckForObserver(scheduler_.get())); 3461 fake_external_begin_frame_source_->LastAckForObserver(scheduler_.get()));
3416 3462
3417 // Request another redraw, but fail it. Verify that a new ack is sent, but 3463 // Request another redraw, but fail it. Verify that a new ack is sent, but
3418 // that its |latest_confirmed_sequence_number| didn't change. 3464 // that its |latest_confirmed_sequence_number| didn't change.
3419 scheduler_->SetNeedsRedraw(); 3465 scheduler_->SetNeedsRedraw();
3420 client_->Reset(); 3466 client_->Reset();
3421 3467
3422 args = SendNextBeginFrame(); 3468 args = SendNextBeginFrame();
3423 EXPECT_LT(latest_confirmed_sequence_number, args.sequence_number); 3469 EXPECT_LT(latest_confirmed_sequence_number, args.sequence_number);
3424 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 1); 3470 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2);
3471 EXPECT_ACTION("ScheduledActionDoShortIdleWork", client_, 1, 2);
3425 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); 3472 EXPECT_TRUE(client_->IsInsideBeginImplFrame());
3426 EXPECT_TRUE(scheduler_->begin_frames_expected()); 3473 EXPECT_TRUE(scheduler_->begin_frames_expected());
3427 client_->Reset(); 3474 client_->Reset();
3428 3475
3429 client_->SetDrawWillHappen(false); 3476 client_->SetDrawWillHappen(false);
3430 task_runner().RunPendingTasks(); // Run posted deadline. 3477 task_runner().RunPendingTasks(); // Run posted deadline.
3431 EXPECT_ACTION("ScheduledActionDrawIfPossible", client_, 0, 2); 3478 EXPECT_ACTION("ScheduledActionDrawIfPossible", client_, 0, 2);
3432 // Failed draw triggers SendBeginMainFrame. 3479 // Failed draw triggers SendBeginMainFrame.
3433 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); 3480 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2);
3434 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); 3481 EXPECT_FALSE(client_->IsInsideBeginImplFrame());
(...skipping 14 matching lines...) Expand all
3449 // To get into a high latency state, this test disables automatic swap acks. 3496 // To get into a high latency state, this test disables automatic swap acks.
3450 client_->SetAutomaticSubmitCompositorFrameAck(false); 3497 client_->SetAutomaticSubmitCompositorFrameAck(false);
3451 fake_compositor_timing_history_->SetAllEstimatesTo(kFastDuration); 3498 fake_compositor_timing_history_->SetAllEstimatesTo(kFastDuration);
3452 3499
3453 // Run a successful redraw that submits a compositor frame but doesn't receive 3500 // Run a successful redraw that submits a compositor frame but doesn't receive
3454 // a swap ack. Verify that a BeginFrameAck is sent for it. 3501 // a swap ack. Verify that a BeginFrameAck is sent for it.
3455 scheduler_->SetNeedsRedraw(); 3502 scheduler_->SetNeedsRedraw();
3456 client_->Reset(); 3503 client_->Reset();
3457 3504
3458 BeginFrameArgs args = SendNextBeginFrame(); 3505 BeginFrameArgs args = SendNextBeginFrame();
3459 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 1); 3506 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2);
3507 EXPECT_ACTION("ScheduledActionDoShortIdleWork", client_, 1, 2);
3460 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); 3508 EXPECT_TRUE(client_->IsInsideBeginImplFrame());
3461 EXPECT_TRUE(scheduler_->begin_frames_expected()); 3509 EXPECT_TRUE(scheduler_->begin_frames_expected());
3462 client_->Reset(); 3510 client_->Reset();
3463 3511
3464 task_runner().RunPendingTasks(); // Run posted deadline. 3512 task_runner().RunPendingTasks(); // Run posted deadline.
3465 EXPECT_ACTION("ScheduledActionDrawIfPossible", client_, 0, 1); 3513 EXPECT_ACTION("ScheduledActionDrawIfPossible", client_, 0, 1);
3466 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); 3514 EXPECT_FALSE(client_->IsInsideBeginImplFrame());
3467 EXPECT_TRUE(scheduler_->begin_frames_expected()); 3515 EXPECT_TRUE(scheduler_->begin_frames_expected());
3468 client_->Reset(); 3516 client_->Reset();
3469 3517
(...skipping 26 matching lines...) Expand all
3496 } 3544 }
3497 3545
3498 TEST_F(SchedulerTest, BeginFrameAckForBeginFrameBeforeLastDeadline) { 3546 TEST_F(SchedulerTest, BeginFrameAckForBeginFrameBeforeLastDeadline) {
3499 SetUpScheduler(EXTERNAL_BFS); 3547 SetUpScheduler(EXTERNAL_BFS);
3500 3548
3501 // Request tile preparation to schedule a proactive BeginFrame. 3549 // Request tile preparation to schedule a proactive BeginFrame.
3502 scheduler_->SetNeedsPrepareTiles(); 3550 scheduler_->SetNeedsPrepareTiles();
3503 client_->Reset(); 3551 client_->Reset();
3504 3552
3505 SendNextBeginFrame(); 3553 SendNextBeginFrame();
3506 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 1); 3554 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2);
3555 EXPECT_ACTION("ScheduledActionDoShortIdleWork", client_, 1, 2);
3507 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); 3556 EXPECT_TRUE(client_->IsInsideBeginImplFrame());
3508 // Until tiles were prepared, further proactive BeginFrames are expected. 3557 // Until tiles were prepared, further proactive BeginFrames are expected.
3509 EXPECT_TRUE(scheduler_->begin_frames_expected()); 3558 EXPECT_TRUE(scheduler_->begin_frames_expected());
3510 client_->Reset(); 3559 client_->Reset();
3511 3560
3512 // Send the next BeginFrame before the previous one's deadline was executed. 3561 // Send the next BeginFrame before the previous one's deadline was executed.
3513 // This should trigger the previous BeginFrame's deadline synchronously, 3562 // This should trigger the previous BeginFrame's deadline synchronously,
3514 // during which tiles will be prepared. As a result of that, no further 3563 // during which tiles will be prepared. As a result of that, no further
3515 // BeginFrames will be needed, and the new BeginFrame should be dropped. 3564 // BeginFrames will be needed, and the new BeginFrame should be dropped.
3516 BeginFrameArgs args = SendNextBeginFrame(); 3565 BeginFrameArgs args = SendNextBeginFrame();
(...skipping 22 matching lines...) Expand all
3539 uint64_t latest_confirmed_sequence_number = 3588 uint64_t latest_confirmed_sequence_number =
3540 fake_external_begin_frame_source_->next_begin_frame_number() - 1; 3589 fake_external_begin_frame_source_->next_begin_frame_number() - 1;
3541 3590
3542 // Request a single BeginFrame. 3591 // Request a single BeginFrame.
3543 scheduler_->SetNeedsOneBeginImplFrame(); 3592 scheduler_->SetNeedsOneBeginImplFrame();
3544 EXPECT_TRUE(scheduler_->begin_frames_expected()); 3593 EXPECT_TRUE(scheduler_->begin_frames_expected());
3545 client_->Reset(); 3594 client_->Reset();
3546 3595
3547 // First BeginFrame is handled by StateMachine. 3596 // First BeginFrame is handled by StateMachine.
3548 BeginFrameArgs first_args = SendNextBeginFrame(); 3597 BeginFrameArgs first_args = SendNextBeginFrame();
3549 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 1); 3598 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2);
3599 EXPECT_ACTION("ScheduledActionDoShortIdleWork", client_, 1, 2);
3550 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); 3600 EXPECT_TRUE(client_->IsInsideBeginImplFrame());
3551 // State machine is no longer interested in BeginFrames, but scheduler is 3601 // State machine is no longer interested in BeginFrames, but scheduler is
3552 // still observing the source. 3602 // still observing the source.
3553 EXPECT_TRUE(scheduler_->begin_frames_expected()); 3603 EXPECT_TRUE(scheduler_->begin_frames_expected());
3554 EXPECT_FALSE(scheduler_->BeginFrameNeeded()); 3604 EXPECT_FALSE(scheduler_->BeginFrameNeeded());
3555 client_->Reset(); 3605 client_->Reset();
3556 3606
3557 // Send the next BeginFrame before the previous one's deadline was executed. 3607 // Send the next BeginFrame before the previous one's deadline was executed.
3558 // The BeginFrame should be dropped immediately, since the state machine is 3608 // The BeginFrame should be dropped immediately, since the state machine is
3559 // not expecting any BeginFrames. 3609 // not expecting any BeginFrames.
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
3620 scheduler_->SetNeedsRedraw(); 3670 scheduler_->SetNeedsRedraw();
3621 client_->Reset(); 3671 client_->Reset();
3622 3672
3623 // Send a BeginFrame with a different source_id. 3673 // Send a BeginFrame with a different source_id.
3624 now_src_->Advance(BeginFrameArgs::DefaultInterval()); 3674 now_src_->Advance(BeginFrameArgs::DefaultInterval());
3625 uint32_t source_id = fake_external_begin_frame_source_->source_id() + 1; 3675 uint32_t source_id = fake_external_begin_frame_source_->source_id() + 1;
3626 BeginFrameArgs args = CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, 3676 BeginFrameArgs args = CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE,
3627 source_id, 1, now_src()); 3677 source_id, 1, now_src());
3628 fake_external_begin_frame_source_->TestOnBeginFrame(args); 3678 fake_external_begin_frame_source_->TestOnBeginFrame(args);
3629 3679
3630 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 1); 3680 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2);
3681 EXPECT_ACTION("ScheduledActionDoShortIdleWork", client_, 1, 2);
3631 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); 3682 EXPECT_TRUE(client_->IsInsideBeginImplFrame());
3632 EXPECT_TRUE(scheduler_->begin_frames_expected()); 3683 EXPECT_TRUE(scheduler_->begin_frames_expected());
3633 client_->Reset(); 3684 client_->Reset();
3634 3685
3635 task_runner().RunPendingTasks(); // Run posted deadline. 3686 task_runner().RunPendingTasks(); // Run posted deadline.
3636 EXPECT_ACTION("ScheduledActionDrawIfPossible", client_, 0, 1); 3687 EXPECT_ACTION("ScheduledActionDrawIfPossible", client_, 0, 1);
3637 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); 3688 EXPECT_FALSE(client_->IsInsideBeginImplFrame());
3638 EXPECT_TRUE(scheduler_->begin_frames_expected()); 3689 EXPECT_TRUE(scheduler_->begin_frames_expected());
3639 client_->Reset(); 3690 client_->Reset();
3640 3691
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
3675 BeginFrameArgs::kInvalidFrameNumber; 3726 BeginFrameArgs::kInvalidFrameNumber;
3676 bool has_damage = false; 3727 bool has_damage = false;
3677 EXPECT_EQ( 3728 EXPECT_EQ(
3678 BeginFrameAck(args.source_id, args.sequence_number, 3729 BeginFrameAck(args.source_id, args.sequence_number,
3679 latest_confirmed_sequence_number, 0, has_damage), 3730 latest_confirmed_sequence_number, 0, has_damage),
3680 fake_external_begin_frame_source_->LastAckForObserver(scheduler_.get())); 3731 fake_external_begin_frame_source_->LastAckForObserver(scheduler_.get()));
3681 } 3732 }
3682 3733
3683 } // namespace 3734 } // namespace
3684 } // namespace cc 3735 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698