OLD | NEW |
1 // Copyright 2011 The Chromium Authors. All rights reserved. | 1 // Copyright 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 #include "cc/scheduler/scheduler.h" | 4 #include "cc/scheduler/scheduler.h" |
5 | 5 |
6 #include <string> | 6 #include <string> |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/memory/scoped_vector.h" | 10 #include "base/memory/scoped_vector.h" |
(...skipping 22 matching lines...) Expand all Loading... |
33 namespace { | 33 namespace { |
34 | 34 |
35 class FakeSchedulerClient; | 35 class FakeSchedulerClient; |
36 | 36 |
37 void InitializeOutputSurfaceAndFirstCommit(Scheduler* scheduler, | 37 void InitializeOutputSurfaceAndFirstCommit(Scheduler* scheduler, |
38 FakeSchedulerClient* client); | 38 FakeSchedulerClient* client); |
39 | 39 |
40 class FakeSchedulerClient : public SchedulerClient { | 40 class FakeSchedulerClient : public SchedulerClient { |
41 public: | 41 public: |
42 FakeSchedulerClient() | 42 FakeSchedulerClient() |
43 : needs_begin_impl_frame_(false) { | 43 : needs_begin_impl_frame_(false), automatic_swap_ack_(true) { |
44 Reset(); | 44 Reset(); |
45 } | 45 } |
46 | 46 |
47 void Reset() { | 47 void Reset() { |
48 actions_.clear(); | 48 actions_.clear(); |
49 states_.clear(); | 49 states_.clear(); |
50 draw_will_happen_ = true; | 50 draw_will_happen_ = true; |
51 swap_will_happen_if_draw_happens_ = true; | 51 swap_will_happen_if_draw_happens_ = true; |
52 num_draws_ = 0; | 52 num_draws_ = 0; |
53 log_anticipated_draw_time_change_ = false; | 53 log_anticipated_draw_time_change_ = false; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 bool HasAction(const char* action) const { | 85 bool HasAction(const char* action) const { |
86 return ActionIndex(action) >= 0; | 86 return ActionIndex(action) >= 0; |
87 } | 87 } |
88 | 88 |
89 void SetDrawWillHappen(bool draw_will_happen) { | 89 void SetDrawWillHappen(bool draw_will_happen) { |
90 draw_will_happen_ = draw_will_happen; | 90 draw_will_happen_ = draw_will_happen; |
91 } | 91 } |
92 void SetSwapWillHappenIfDrawHappens(bool swap_will_happen_if_draw_happens) { | 92 void SetSwapWillHappenIfDrawHappens(bool swap_will_happen_if_draw_happens) { |
93 swap_will_happen_if_draw_happens_ = swap_will_happen_if_draw_happens; | 93 swap_will_happen_if_draw_happens_ = swap_will_happen_if_draw_happens; |
94 } | 94 } |
| 95 void SetAutomaticSwapAck(bool automatic_swap_ack) { |
| 96 automatic_swap_ack_ = automatic_swap_ack; |
| 97 } |
95 | 98 |
96 // SchedulerClient implementation. | 99 // SchedulerClient implementation. |
97 virtual void SetNeedsBeginFrame(bool enable) OVERRIDE { | 100 virtual void SetNeedsBeginFrame(bool enable) OVERRIDE { |
98 actions_.push_back("SetNeedsBeginFrame"); | 101 actions_.push_back("SetNeedsBeginFrame"); |
99 states_.push_back(scheduler_->StateAsValue().release()); | 102 states_.push_back(scheduler_->StateAsValue().release()); |
100 needs_begin_impl_frame_ = enable; | 103 needs_begin_impl_frame_ = enable; |
101 } | 104 } |
102 virtual void WillBeginImplFrame(const BeginFrameArgs& args) OVERRIDE { | 105 virtual void WillBeginImplFrame(const BeginFrameArgs& args) OVERRIDE { |
103 actions_.push_back("WillBeginImplFrame"); | 106 actions_.push_back("WillBeginImplFrame"); |
104 states_.push_back(scheduler_->StateAsValue().release()); | 107 states_.push_back(scheduler_->StateAsValue().release()); |
105 } | 108 } |
106 virtual void ScheduledActionSendBeginMainFrame() OVERRIDE { | 109 virtual void ScheduledActionSendBeginMainFrame() OVERRIDE { |
107 actions_.push_back("ScheduledActionSendBeginMainFrame"); | 110 actions_.push_back("ScheduledActionSendBeginMainFrame"); |
108 states_.push_back(scheduler_->StateAsValue().release()); | 111 states_.push_back(scheduler_->StateAsValue().release()); |
109 } | 112 } |
110 virtual DrawSwapReadbackResult ScheduledActionDrawAndSwapIfPossible() | 113 virtual DrawSwapReadbackResult ScheduledActionDrawAndSwapIfPossible() |
111 OVERRIDE { | 114 OVERRIDE { |
112 actions_.push_back("ScheduledActionDrawAndSwapIfPossible"); | 115 actions_.push_back("ScheduledActionDrawAndSwapIfPossible"); |
113 states_.push_back(scheduler_->StateAsValue().release()); | 116 states_.push_back(scheduler_->StateAsValue().release()); |
114 num_draws_++; | 117 num_draws_++; |
115 bool did_readback = false; | 118 bool did_readback = false; |
116 DrawSwapReadbackResult::DrawResult result = | 119 DrawSwapReadbackResult::DrawResult result = |
117 draw_will_happen_ | 120 draw_will_happen_ |
118 ? DrawSwapReadbackResult::DRAW_SUCCESS | 121 ? DrawSwapReadbackResult::DRAW_SUCCESS |
119 : DrawSwapReadbackResult::DRAW_ABORTED_CHECKERBOARD_ANIMATIONS; | 122 : DrawSwapReadbackResult::DRAW_ABORTED_CHECKERBOARD_ANIMATIONS; |
| 123 bool swap_will_happen = |
| 124 draw_will_happen_ && swap_will_happen_if_draw_happens_; |
| 125 if (swap_will_happen) { |
| 126 scheduler_->DidSwapBuffers(); |
| 127 if (automatic_swap_ack_) |
| 128 scheduler_->DidSwapBuffersComplete(); |
| 129 } |
120 return DrawSwapReadbackResult( | 130 return DrawSwapReadbackResult( |
121 result, | 131 result, |
122 draw_will_happen_ && swap_will_happen_if_draw_happens_, | 132 draw_will_happen_ && swap_will_happen_if_draw_happens_, |
123 did_readback); | 133 did_readback); |
124 } | 134 } |
125 virtual DrawSwapReadbackResult ScheduledActionDrawAndSwapForced() OVERRIDE { | 135 virtual DrawSwapReadbackResult ScheduledActionDrawAndSwapForced() OVERRIDE { |
126 actions_.push_back("ScheduledActionDrawAndSwapForced"); | 136 actions_.push_back("ScheduledActionDrawAndSwapForced"); |
127 states_.push_back(scheduler_->StateAsValue().release()); | 137 states_.push_back(scheduler_->StateAsValue().release()); |
128 bool did_swap = swap_will_happen_if_draw_happens_; | 138 bool did_request_swap = swap_will_happen_if_draw_happens_; |
129 bool did_readback = false; | 139 bool did_readback = false; |
130 return DrawSwapReadbackResult( | 140 return DrawSwapReadbackResult( |
131 DrawSwapReadbackResult::DRAW_SUCCESS, did_swap, did_readback); | 141 DrawSwapReadbackResult::DRAW_SUCCESS, did_request_swap, did_readback); |
132 } | 142 } |
133 virtual DrawSwapReadbackResult ScheduledActionDrawAndReadback() OVERRIDE { | 143 virtual DrawSwapReadbackResult ScheduledActionDrawAndReadback() OVERRIDE { |
134 actions_.push_back("ScheduledActionDrawAndReadback"); | 144 actions_.push_back("ScheduledActionDrawAndReadback"); |
135 states_.push_back(scheduler_->StateAsValue().release()); | 145 states_.push_back(scheduler_->StateAsValue().release()); |
136 bool did_swap = false; | 146 bool did_request_swap = false; |
137 bool did_readback = true; | 147 bool did_readback = true; |
138 return DrawSwapReadbackResult( | 148 return DrawSwapReadbackResult( |
139 DrawSwapReadbackResult::DRAW_SUCCESS, did_swap, did_readback); | 149 DrawSwapReadbackResult::DRAW_SUCCESS, did_request_swap, did_readback); |
140 } | 150 } |
141 virtual void ScheduledActionCommit() OVERRIDE { | 151 virtual void ScheduledActionCommit() OVERRIDE { |
142 actions_.push_back("ScheduledActionCommit"); | 152 actions_.push_back("ScheduledActionCommit"); |
143 states_.push_back(scheduler_->StateAsValue().release()); | 153 states_.push_back(scheduler_->StateAsValue().release()); |
144 } | 154 } |
145 virtual void ScheduledActionUpdateVisibleTiles() OVERRIDE { | 155 virtual void ScheduledActionUpdateVisibleTiles() OVERRIDE { |
146 actions_.push_back("ScheduledActionUpdateVisibleTiles"); | 156 actions_.push_back("ScheduledActionUpdateVisibleTiles"); |
147 states_.push_back(scheduler_->StateAsValue().release()); | 157 states_.push_back(scheduler_->StateAsValue().release()); |
148 } | 158 } |
149 virtual void ScheduledActionActivatePendingTree() OVERRIDE { | 159 virtual void ScheduledActionActivatePendingTree() OVERRIDE { |
(...skipping 21 matching lines...) Expand all Loading... |
171 virtual base::TimeDelta CommitToActivateDurationEstimate() OVERRIDE { | 181 virtual base::TimeDelta CommitToActivateDurationEstimate() OVERRIDE { |
172 return base::TimeDelta(); | 182 return base::TimeDelta(); |
173 } | 183 } |
174 | 184 |
175 virtual void DidBeginImplFrameDeadline() OVERRIDE {} | 185 virtual void DidBeginImplFrameDeadline() OVERRIDE {} |
176 | 186 |
177 protected: | 187 protected: |
178 bool needs_begin_impl_frame_; | 188 bool needs_begin_impl_frame_; |
179 bool draw_will_happen_; | 189 bool draw_will_happen_; |
180 bool swap_will_happen_if_draw_happens_; | 190 bool swap_will_happen_if_draw_happens_; |
| 191 bool automatic_swap_ack_; |
181 int num_draws_; | 192 int num_draws_; |
182 bool log_anticipated_draw_time_change_; | 193 bool log_anticipated_draw_time_change_; |
183 base::TimeTicks posted_begin_impl_frame_deadline_; | 194 base::TimeTicks posted_begin_impl_frame_deadline_; |
184 std::vector<const char*> actions_; | 195 std::vector<const char*> actions_; |
185 ScopedVector<base::Value> states_; | 196 ScopedVector<base::Value> states_; |
186 scoped_ptr<Scheduler> scheduler_; | 197 scoped_ptr<Scheduler> scheduler_; |
187 scoped_refptr<base::TestSimpleTaskRunner> task_runner_; | 198 scoped_refptr<base::TestSimpleTaskRunner> task_runner_; |
188 }; | 199 }; |
189 | 200 |
190 void InitializeOutputSurfaceAndFirstCommit(Scheduler* scheduler, | 201 void InitializeOutputSurfaceAndFirstCommit(Scheduler* scheduler, |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
374 virtual DrawSwapReadbackResult ScheduledActionDrawAndSwapIfPossible() | 385 virtual DrawSwapReadbackResult ScheduledActionDrawAndSwapIfPossible() |
375 OVERRIDE { | 386 OVERRIDE { |
376 // Only SetNeedsRedraw the first time this is called | 387 // Only SetNeedsRedraw the first time this is called |
377 if (!num_draws_) | 388 if (!num_draws_) |
378 scheduler_->SetNeedsRedraw(); | 389 scheduler_->SetNeedsRedraw(); |
379 return FakeSchedulerClient::ScheduledActionDrawAndSwapIfPossible(); | 390 return FakeSchedulerClient::ScheduledActionDrawAndSwapIfPossible(); |
380 } | 391 } |
381 | 392 |
382 virtual DrawSwapReadbackResult ScheduledActionDrawAndSwapForced() OVERRIDE { | 393 virtual DrawSwapReadbackResult ScheduledActionDrawAndSwapForced() OVERRIDE { |
383 NOTREACHED(); | 394 NOTREACHED(); |
384 bool did_swap = true; | 395 bool did_request_swap = true; |
385 bool did_readback = false; | 396 bool did_readback = false; |
386 return DrawSwapReadbackResult( | 397 return DrawSwapReadbackResult( |
387 DrawSwapReadbackResult::DRAW_SUCCESS, did_swap, did_readback); | 398 DrawSwapReadbackResult::DRAW_SUCCESS, did_request_swap, did_readback); |
388 } | 399 } |
389 | 400 |
390 virtual void ScheduledActionCommit() OVERRIDE {} | 401 virtual void ScheduledActionCommit() OVERRIDE {} |
391 virtual void ScheduledActionBeginOutputSurfaceCreation() OVERRIDE {} | 402 virtual void ScheduledActionBeginOutputSurfaceCreation() OVERRIDE {} |
392 virtual void DidAnticipatedDrawTimeChange(base::TimeTicks) OVERRIDE {} | 403 virtual void DidAnticipatedDrawTimeChange(base::TimeTicks) OVERRIDE {} |
393 }; | 404 }; |
394 | 405 |
395 // Tests for two different situations: | 406 // Tests for two different situations: |
396 // 1. the scheduler dropping SetNeedsRedraw requests that happen inside | 407 // 1. the scheduler dropping SetNeedsRedraw requests that happen inside |
397 // a ScheduledActionDrawAndSwap | 408 // a ScheduledActionDrawAndSwap |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
490 // Only SetNeedsCommit the first time this is called | 501 // Only SetNeedsCommit the first time this is called |
491 if (set_needs_commit_on_next_draw_) { | 502 if (set_needs_commit_on_next_draw_) { |
492 scheduler_->SetNeedsCommit(); | 503 scheduler_->SetNeedsCommit(); |
493 set_needs_commit_on_next_draw_ = false; | 504 set_needs_commit_on_next_draw_ = false; |
494 } | 505 } |
495 return FakeSchedulerClient::ScheduledActionDrawAndSwapIfPossible(); | 506 return FakeSchedulerClient::ScheduledActionDrawAndSwapIfPossible(); |
496 } | 507 } |
497 | 508 |
498 virtual DrawSwapReadbackResult ScheduledActionDrawAndSwapForced() OVERRIDE { | 509 virtual DrawSwapReadbackResult ScheduledActionDrawAndSwapForced() OVERRIDE { |
499 NOTREACHED(); | 510 NOTREACHED(); |
500 bool did_swap = false; | 511 bool did_request_swap = false; |
501 bool did_readback = false; | 512 bool did_readback = false; |
502 return DrawSwapReadbackResult( | 513 return DrawSwapReadbackResult( |
503 DrawSwapReadbackResult::DRAW_SUCCESS, did_swap, did_readback); | 514 DrawSwapReadbackResult::DRAW_SUCCESS, did_request_swap, did_readback); |
504 } | 515 } |
505 | 516 |
506 virtual void ScheduledActionCommit() OVERRIDE {} | 517 virtual void ScheduledActionCommit() OVERRIDE {} |
507 virtual void ScheduledActionBeginOutputSurfaceCreation() OVERRIDE {} | 518 virtual void ScheduledActionBeginOutputSurfaceCreation() OVERRIDE {} |
508 virtual void DidAnticipatedDrawTimeChange(base::TimeTicks) OVERRIDE {} | 519 virtual void DidAnticipatedDrawTimeChange(base::TimeTicks) OVERRIDE {} |
509 | 520 |
510 void SetNeedsCommitOnNextDraw() { set_needs_commit_on_next_draw_ = true; } | 521 void SetNeedsCommitOnNextDraw() { set_needs_commit_on_next_draw_ = true; } |
511 | 522 |
512 private: | 523 private: |
513 bool set_needs_commit_on_next_draw_; | 524 bool set_needs_commit_on_next_draw_; |
(...skipping 537 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1051 scheduler->SetNeedsRedraw(); | 1062 scheduler->SetNeedsRedraw(); |
1052 | 1063 |
1053 BeginFrameArgs frame_args = BeginFrameArgs::CreateForTesting(); | 1064 BeginFrameArgs frame_args = BeginFrameArgs::CreateForTesting(); |
1054 frame_args.interval = base::TimeDelta::FromMilliseconds(1000); | 1065 frame_args.interval = base::TimeDelta::FromMilliseconds(1000); |
1055 scheduler->BeginFrame(frame_args); | 1066 scheduler->BeginFrame(frame_args); |
1056 | 1067 |
1057 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1068 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
1058 client.task_runner().RunPendingTasks(); // Run posted deadline. | 1069 client.task_runner().RunPendingTasks(); // Run posted deadline. |
1059 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 1070 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
1060 | 1071 |
| 1072 scheduler->DidSwapBuffers(); |
| 1073 scheduler->DidSwapBuffersComplete(); |
| 1074 |
1061 // At this point, we've drawn a frame. Start another commit, but hold off on | 1075 // At this point, we've drawn a frame. Start another commit, but hold off on |
1062 // the NotifyReadyToCommit for now. | 1076 // the NotifyReadyToCommit for now. |
1063 EXPECT_FALSE(scheduler->CommitPending()); | 1077 EXPECT_FALSE(scheduler->CommitPending()); |
1064 scheduler->SetNeedsCommit(); | 1078 scheduler->SetNeedsCommit(); |
1065 scheduler->BeginFrame(frame_args); | 1079 scheduler->BeginFrame(frame_args); |
1066 EXPECT_TRUE(scheduler->CommitPending()); | 1080 EXPECT_TRUE(scheduler->CommitPending()); |
1067 | 1081 |
| 1082 // Draw and swap the frame, but don't ack the swap to simulate the Browser |
| 1083 // blocking on the renderer. |
| 1084 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 1085 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 1086 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
| 1087 scheduler->DidSwapBuffers(); |
| 1088 |
1068 // Spin the event loop a few times and make sure we get more | 1089 // Spin the event loop a few times and make sure we get more |
1069 // DidAnticipateDrawTimeChange calls every time. | 1090 // DidAnticipateDrawTimeChange calls every time. |
1070 int actions_so_far = client.num_actions_(); | 1091 int actions_so_far = client.num_actions_(); |
1071 | 1092 |
1072 // Does three iterations to make sure that the timer is properly repeating. | 1093 // Does three iterations to make sure that the timer is properly repeating. |
1073 for (int i = 0; i < 3; ++i) { | 1094 for (int i = 0; i < 3; ++i) { |
1074 EXPECT_EQ((frame_args.interval * 2).InMicroseconds(), | 1095 EXPECT_EQ((frame_args.interval * 2).InMicroseconds(), |
1075 client.task_runner().NextPendingTaskDelay().InMicroseconds()) | 1096 client.task_runner().NextPendingTaskDelay().InMicroseconds()) |
1076 << *scheduler->StateAsValue(); | 1097 << *scheduler->StateAsValue(); |
1077 client.task_runner().RunPendingTasks(); | 1098 client.task_runner().RunPendingTasks(); |
(...skipping 10 matching lines...) Expand all Loading... |
1088 client.task_runner().NextPendingTaskDelay().InMicroseconds()) | 1109 client.task_runner().NextPendingTaskDelay().InMicroseconds()) |
1089 << *scheduler->StateAsValue(); | 1110 << *scheduler->StateAsValue(); |
1090 client.task_runner().RunPendingTasks(); | 1111 client.task_runner().RunPendingTasks(); |
1091 EXPECT_GT(client.num_actions_(), actions_so_far); | 1112 EXPECT_GT(client.num_actions_(), actions_so_far); |
1092 EXPECT_STREQ(client.Action(client.num_actions_() - 1), | 1113 EXPECT_STREQ(client.Action(client.num_actions_() - 1), |
1093 "DidAnticipatedDrawTimeChange"); | 1114 "DidAnticipatedDrawTimeChange"); |
1094 actions_so_far = client.num_actions_(); | 1115 actions_so_far = client.num_actions_(); |
1095 } | 1116 } |
1096 } | 1117 } |
1097 | 1118 |
1098 TEST(SchedulerTest, BeginRetroFrame) { | 1119 TEST(SchedulerTest, BeginRetroFrameBasic) { |
1099 FakeSchedulerClient client; | 1120 FakeSchedulerClient client; |
1100 SchedulerSettings scheduler_settings; | 1121 SchedulerSettings scheduler_settings; |
1101 Scheduler* scheduler = client.CreateScheduler(scheduler_settings); | 1122 Scheduler* scheduler = client.CreateScheduler(scheduler_settings); |
1102 scheduler->SetCanStart(); | 1123 scheduler->SetCanStart(); |
1103 scheduler->SetVisible(true); | 1124 scheduler->SetVisible(true); |
1104 scheduler->SetCanDraw(true); | 1125 scheduler->SetCanDraw(true); |
1105 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | 1126 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
1106 | 1127 |
1107 // SetNeedsCommit should begin the frame on the next BeginImplFrame. | 1128 // SetNeedsCommit should begin the frame on the next BeginImplFrame. |
1108 client.Reset(); | 1129 client.Reset(); |
1109 scheduler->SetNeedsCommit(); | 1130 scheduler->SetNeedsCommit(); |
1110 EXPECT_TRUE(client.needs_begin_impl_frame()); | 1131 EXPECT_TRUE(client.needs_begin_impl_frame()); |
1111 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); | 1132 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); |
1112 client.Reset(); | 1133 client.Reset(); |
1113 | 1134 |
1114 // Create a BeginFrame with a long deadline to avoid race conditions. | 1135 // Create a BeginFrame with a long deadline to avoid race conditions. |
1115 // This is the first BeginFrame, which will be handled immediately. | 1136 // This is the first BeginFrame, which will be handled immediately. |
1116 BeginFrameArgs args = BeginFrameArgs::CreateForTesting(); | 1137 BeginFrameArgs args = BeginFrameArgs::CreateForTesting(); |
1117 args.deadline += base::TimeDelta::FromHours(1); | 1138 args.deadline += base::TimeDelta::FromHours(1); |
1118 scheduler->BeginFrame(args); | 1139 scheduler->BeginFrame(args); |
1119 | |
1120 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 1140 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
1121 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); | 1141 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); |
1122 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1142 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
1123 EXPECT_TRUE(client.needs_begin_impl_frame()); | 1143 EXPECT_TRUE(client.needs_begin_impl_frame()); |
1124 client.Reset(); | 1144 client.Reset(); |
1125 | 1145 |
1126 // Queue BeginFrames while we are still handling the previous BeginFrame. | 1146 // Queue BeginFrames while we are still handling the previous BeginFrame. |
1127 args.frame_time += base::TimeDelta::FromSeconds(1); | 1147 args.frame_time += base::TimeDelta::FromSeconds(1); |
1128 scheduler->BeginFrame(args); | 1148 scheduler->BeginFrame(args); |
1129 args.frame_time += base::TimeDelta::FromSeconds(1); | 1149 args.frame_time += base::TimeDelta::FromSeconds(1); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1165 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); | 1185 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); |
1166 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1186 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
1167 client.Reset(); | 1187 client.Reset(); |
1168 | 1188 |
1169 client.task_runner().RunPendingTasks(); // Run posted deadline. | 1189 client.task_runner().RunPendingTasks(); // Run posted deadline. |
1170 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); | 1190 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); |
1171 EXPECT_FALSE(client.needs_begin_impl_frame()); | 1191 EXPECT_FALSE(client.needs_begin_impl_frame()); |
1172 client.Reset(); | 1192 client.Reset(); |
1173 } | 1193 } |
1174 | 1194 |
| 1195 TEST(SchedulerTest, BeginRetroFrame_SwapThrottled) { |
| 1196 FakeSchedulerClient client; |
| 1197 SchedulerSettings scheduler_settings; |
| 1198 Scheduler* scheduler = client.CreateScheduler(scheduler_settings); |
| 1199 scheduler->SetCanStart(); |
| 1200 scheduler->SetVisible(true); |
| 1201 scheduler->SetCanDraw(true); |
| 1202 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
| 1203 |
| 1204 // To test swap ack throttling, this test disables automatic swap acks. |
| 1205 scheduler->SetMaxSwapsPending(1); |
| 1206 client.SetAutomaticSwapAck(false); |
| 1207 |
| 1208 // SetNeedsCommit should begin the frame on the next BeginImplFrame. |
| 1209 client.Reset(); |
| 1210 scheduler->SetNeedsCommit(); |
| 1211 EXPECT_TRUE(client.needs_begin_impl_frame()); |
| 1212 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); |
| 1213 client.Reset(); |
| 1214 |
| 1215 // Create a BeginFrame with a long deadline to avoid race conditions. |
| 1216 // This is the first BeginFrame, which will be handled immediately. |
| 1217 BeginFrameArgs args = BeginFrameArgs::CreateForTesting(); |
| 1218 args.deadline += base::TimeDelta::FromHours(1); |
| 1219 scheduler->BeginFrame(args); |
| 1220 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
| 1221 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); |
| 1222 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 1223 EXPECT_TRUE(client.needs_begin_impl_frame()); |
| 1224 client.Reset(); |
| 1225 |
| 1226 // Queue BeginFrame while we are still handling the previous BeginFrame. |
| 1227 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 1228 args.frame_time += base::TimeDelta::FromSeconds(1); |
| 1229 scheduler->BeginFrame(args); |
| 1230 EXPECT_EQ(0, client.num_actions_()); |
| 1231 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 1232 client.Reset(); |
| 1233 |
| 1234 // NotifyReadyToCommit should trigger the pending commit and draw. |
| 1235 scheduler->NotifyBeginMainFrameStarted(); |
| 1236 scheduler->NotifyReadyToCommit(); |
| 1237 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); |
| 1238 EXPECT_TRUE(client.needs_begin_impl_frame()); |
| 1239 client.Reset(); |
| 1240 |
| 1241 // Swapping will put us into a swap throttled state. |
| 1242 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 1243 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 2); |
| 1244 EXPECT_ACTION("SetNeedsBeginFrame", client, 1, 2); |
| 1245 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
| 1246 EXPECT_TRUE(client.needs_begin_impl_frame()); |
| 1247 client.Reset(); |
| 1248 |
| 1249 // While swap throttled, BeginRetroFrames should trigger BeginImplFrames |
| 1250 // but not a BeginMainFrame or draw. |
| 1251 scheduler->SetNeedsCommit(); |
| 1252 client.task_runner().RunPendingTasks(); // Run posted BeginRetroFrame. |
| 1253 EXPECT_ACTION("WillBeginImplFrame", client, 0, 1); |
| 1254 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 1255 EXPECT_TRUE(client.needs_begin_impl_frame()); |
| 1256 client.Reset(); |
| 1257 |
| 1258 // Queue BeginFrame while we are still handling the previous BeginFrame. |
| 1259 args.frame_time += base::TimeDelta::FromSeconds(1); |
| 1260 scheduler->BeginFrame(args); |
| 1261 EXPECT_EQ(0, client.num_actions_()); |
| 1262 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 1263 EXPECT_TRUE(client.needs_begin_impl_frame()); |
| 1264 client.Reset(); |
| 1265 |
| 1266 // Take us out of a swap throttled state. |
| 1267 scheduler->DidSwapBuffersComplete(); |
| 1268 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 0, 1); |
| 1269 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 1270 EXPECT_TRUE(client.needs_begin_impl_frame()); |
| 1271 client.Reset(); |
| 1272 |
| 1273 // BeginImplFrame deadline should draw. |
| 1274 scheduler->SetNeedsRedraw(); |
| 1275 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 1276 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 2); |
| 1277 EXPECT_ACTION("SetNeedsBeginFrame", client, 1, 2); |
| 1278 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
| 1279 EXPECT_TRUE(client.needs_begin_impl_frame()); |
| 1280 client.Reset(); |
| 1281 } |
| 1282 |
1175 } // namespace | 1283 } // namespace |
1176 } // namespace cc | 1284 } // namespace cc |
OLD | NEW |