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

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

Powered by Google App Engine
This is Rietveld 408576698