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" |
11 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
12 #include "base/run_loop.h" | 12 #include "base/run_loop.h" |
13 #include "base/test/test_simple_task_runner.h" | |
13 #include "base/time/time.h" | 14 #include "base/time/time.h" |
14 #include "cc/test/scheduler_test_common.h" | 15 #include "cc/test/scheduler_test_common.h" |
15 #include "testing/gmock/include/gmock/gmock.h" | 16 #include "testing/gmock/include/gmock/gmock.h" |
16 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
17 | 18 |
18 #define EXPECT_ACTION(action, client, action_index, expected_num_actions) \ | 19 #define EXPECT_ACTION(action, client, action_index, expected_num_actions) \ |
19 EXPECT_EQ(expected_num_actions, client.num_actions_()); \ | 20 EXPECT_EQ(expected_num_actions, client.num_actions_()); \ |
20 ASSERT_LT(action_index, client.num_actions_()); \ | 21 ASSERT_LT(action_index, client.num_actions_()); \ |
21 do { \ | 22 do { \ |
22 EXPECT_STREQ(action, client.Action(action_index)); \ | 23 EXPECT_STREQ(action, client.Action(action_index)); \ |
23 for (int i = expected_num_actions; i < client.num_actions_(); ++i) \ | 24 for (int i = expected_num_actions; i < client.num_actions_(); ++i) \ |
24 ADD_FAILURE() << "Unexpected action: " << client.Action(i) << \ | 25 ADD_FAILURE() << "Unexpected action: " << client.Action(i) << \ |
25 " with state:\n" << client.StateForAction(action_index); \ | 26 " with state:\n" << client.StateForAction(action_index); \ |
26 } while (false) | 27 } while (false) |
27 | 28 |
28 #define EXPECT_SINGLE_ACTION(action, client) \ | 29 #define EXPECT_SINGLE_ACTION(action, client) \ |
29 EXPECT_ACTION(action, client, 0, 1) | 30 EXPECT_ACTION(action, client, 0, 1) |
30 | 31 |
31 namespace cc { | 32 namespace cc { |
32 namespace { | 33 namespace { |
33 | 34 |
34 void InitializeOutputSurfaceAndFirstCommit(Scheduler* scheduler) { | 35 class FakeSchedulerClient; |
35 scheduler->DidCreateAndInitializeOutputSurface(); | 36 |
36 scheduler->SetNeedsCommit(); | 37 void InitializeOutputSurfaceAndFirstCommit(Scheduler* scheduler, |
37 scheduler->NotifyBeginMainFrameStarted(); | 38 FakeSchedulerClient* client); |
38 scheduler->NotifyReadyToCommit(); | |
39 // Go through the motions to draw the commit. | |
40 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); | |
41 scheduler->OnBeginImplFrameDeadline(); | |
42 // We need another BeginImplFrame so Scheduler calls | |
43 // SetNeedsBeginImplFrame(false). | |
44 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); | |
45 scheduler->OnBeginImplFrameDeadline(); | |
46 } | |
47 | 39 |
48 class FakeSchedulerClient : public SchedulerClient { | 40 class FakeSchedulerClient : public SchedulerClient { |
49 public: | 41 public: |
50 FakeSchedulerClient() | 42 FakeSchedulerClient() |
51 : needs_begin_impl_frame_(false) { | 43 : needs_begin_impl_frame_(false) { |
52 Reset(); | 44 Reset(); |
53 } | 45 } |
54 | 46 |
55 void Reset() { | 47 void Reset() { |
56 actions_.clear(); | 48 actions_.clear(); |
57 states_.clear(); | 49 states_.clear(); |
58 draw_will_happen_ = true; | 50 draw_will_happen_ = true; |
59 swap_will_happen_if_draw_happens_ = true; | 51 swap_will_happen_if_draw_happens_ = true; |
60 num_draws_ = 0; | 52 num_draws_ = 0; |
61 log_anticipated_draw_time_change_ = false; | 53 log_anticipated_draw_time_change_ = false; |
62 } | 54 } |
63 | 55 |
64 Scheduler* CreateScheduler(const SchedulerSettings& settings) { | 56 Scheduler* CreateScheduler(const SchedulerSettings& settings) { |
65 scheduler_ = | 57 task_runner_ = new base::TestSimpleTaskRunner; |
66 Scheduler::Create(this, settings, 0, base::MessageLoopProxy::current()); | 58 scheduler_ = Scheduler::Create(this, settings, 0, task_runner_); |
67 return scheduler_.get(); | 59 return scheduler_.get(); |
68 } | 60 } |
69 | 61 |
70 // Most tests don't care about DidAnticipatedDrawTimeChange, so only record it | 62 // Most tests don't care about DidAnticipatedDrawTimeChange, so only record it |
71 // for tests that do. | 63 // for tests that do. |
72 void set_log_anticipated_draw_time_change(bool log) { | 64 void set_log_anticipated_draw_time_change(bool log) { |
73 log_anticipated_draw_time_change_ = log; | 65 log_anticipated_draw_time_change_ = log; |
74 } | 66 } |
75 bool needs_begin_impl_frame() { return needs_begin_impl_frame_; } | 67 bool needs_begin_impl_frame() { return needs_begin_impl_frame_; } |
76 int num_draws() const { return num_draws_; } | 68 int num_draws() const { return num_draws_; } |
77 int num_actions_() const { return static_cast<int>(actions_.size()); } | 69 int num_actions_() const { return static_cast<int>(actions_.size()); } |
78 const char* Action(int i) const { return actions_[i]; } | 70 const char* Action(int i) const { return actions_[i]; } |
79 base::Value& StateForAction(int i) const { return *states_[i]; } | 71 base::Value& StateForAction(int i) const { return *states_[i]; } |
80 base::TimeTicks posted_begin_impl_frame_deadline() const { | 72 base::TimeTicks posted_begin_impl_frame_deadline() const { |
81 return posted_begin_impl_frame_deadline_; | 73 return posted_begin_impl_frame_deadline_; |
82 } | 74 } |
83 | 75 |
76 base::TestSimpleTaskRunner& task_runner() { return *task_runner_; } | |
77 | |
84 int ActionIndex(const char* action) const { | 78 int ActionIndex(const char* action) const { |
85 for (size_t i = 0; i < actions_.size(); i++) | 79 for (size_t i = 0; i < actions_.size(); i++) |
86 if (!strcmp(actions_[i], action)) | 80 if (!strcmp(actions_[i], action)) |
87 return i; | 81 return i; |
88 return -1; | 82 return -1; |
89 } | 83 } |
90 | 84 |
91 bool HasAction(const char* action) const { | 85 bool HasAction(const char* action) const { |
92 return ActionIndex(action) >= 0; | 86 return ActionIndex(action) >= 0; |
93 } | 87 } |
94 | 88 |
95 void SetDrawWillHappen(bool draw_will_happen) { | 89 void SetDrawWillHappen(bool draw_will_happen) { |
96 draw_will_happen_ = draw_will_happen; | 90 draw_will_happen_ = draw_will_happen; |
97 } | 91 } |
98 void SetSwapWillHappenIfDrawHappens(bool swap_will_happen_if_draw_happens) { | 92 void SetSwapWillHappenIfDrawHappens(bool swap_will_happen_if_draw_happens) { |
99 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; |
100 } | 94 } |
101 | 95 |
102 // SchedulerClient implementation. | 96 // SchedulerClient implementation. |
103 virtual void SetNeedsBeginImplFrame(bool enable) OVERRIDE { | 97 virtual void SetNeedsBeginFrame(bool enable) OVERRIDE { |
104 actions_.push_back("SetNeedsBeginImplFrame"); | 98 actions_.push_back("SetNeedsBeginFrame"); |
105 states_.push_back(scheduler_->StateAsValue().release()); | 99 states_.push_back(scheduler_->StateAsValue().release()); |
106 needs_begin_impl_frame_ = enable; | 100 needs_begin_impl_frame_ = enable; |
107 } | 101 } |
102 virtual void WillBeginImplFrame(const BeginFrameArgs& args) OVERRIDE { | |
103 actions_.push_back("WillBeginImplFrame"); | |
104 states_.push_back(scheduler_->StateAsValue().release()); | |
105 } | |
108 virtual void ScheduledActionSendBeginMainFrame() OVERRIDE { | 106 virtual void ScheduledActionSendBeginMainFrame() OVERRIDE { |
109 actions_.push_back("ScheduledActionSendBeginMainFrame"); | 107 actions_.push_back("ScheduledActionSendBeginMainFrame"); |
110 states_.push_back(scheduler_->StateAsValue().release()); | 108 states_.push_back(scheduler_->StateAsValue().release()); |
111 } | 109 } |
112 virtual DrawSwapReadbackResult ScheduledActionDrawAndSwapIfPossible() | 110 virtual DrawSwapReadbackResult ScheduledActionDrawAndSwapIfPossible() |
113 OVERRIDE { | 111 OVERRIDE { |
114 actions_.push_back("ScheduledActionDrawAndSwapIfPossible"); | 112 actions_.push_back("ScheduledActionDrawAndSwapIfPossible"); |
115 states_.push_back(scheduler_->StateAsValue().release()); | 113 states_.push_back(scheduler_->StateAsValue().release()); |
116 num_draws_++; | 114 num_draws_++; |
117 bool did_readback = false; | 115 bool did_readback = false; |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
183 protected: | 181 protected: |
184 bool needs_begin_impl_frame_; | 182 bool needs_begin_impl_frame_; |
185 bool draw_will_happen_; | 183 bool draw_will_happen_; |
186 bool swap_will_happen_if_draw_happens_; | 184 bool swap_will_happen_if_draw_happens_; |
187 int num_draws_; | 185 int num_draws_; |
188 bool log_anticipated_draw_time_change_; | 186 bool log_anticipated_draw_time_change_; |
189 base::TimeTicks posted_begin_impl_frame_deadline_; | 187 base::TimeTicks posted_begin_impl_frame_deadline_; |
190 std::vector<const char*> actions_; | 188 std::vector<const char*> actions_; |
191 ScopedVector<base::Value> states_; | 189 ScopedVector<base::Value> states_; |
192 scoped_ptr<Scheduler> scheduler_; | 190 scoped_ptr<Scheduler> scheduler_; |
191 scoped_refptr<base::TestSimpleTaskRunner> task_runner_; | |
brianderson
2014/04/02 16:57:50
I added an test task runner so we can make sure th
| |
193 }; | 192 }; |
194 | 193 |
194 void InitializeOutputSurfaceAndFirstCommit(Scheduler* scheduler, | |
195 FakeSchedulerClient* client) { | |
196 scheduler->DidCreateAndInitializeOutputSurface(); | |
197 scheduler->SetNeedsCommit(); | |
198 scheduler->NotifyBeginMainFrameStarted(); | |
199 scheduler->NotifyReadyToCommit(); | |
200 // Go through the motions to draw the commit. | |
201 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); | |
202 | |
203 // Run the posted deadline task. | |
204 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | |
205 client->task_runner().RunPendingTasks(); | |
206 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | |
207 | |
208 // We need another BeginImplFrame so Scheduler calls | |
209 // SetNeedsBeginFrame(false). | |
210 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); | |
211 | |
212 // Run the posted deadline task. | |
213 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | |
214 client->task_runner().RunPendingTasks(); | |
215 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | |
216 } | |
217 | |
195 TEST(SchedulerTest, InitializeOutputSurfaceDoesNotBeginImplFrame) { | 218 TEST(SchedulerTest, InitializeOutputSurfaceDoesNotBeginImplFrame) { |
196 FakeSchedulerClient client; | 219 FakeSchedulerClient client; |
197 SchedulerSettings default_scheduler_settings; | 220 SchedulerSettings default_scheduler_settings; |
198 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings); | 221 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings); |
199 scheduler->SetCanStart(); | 222 scheduler->SetCanStart(); |
200 scheduler->SetVisible(true); | 223 scheduler->SetVisible(true); |
201 scheduler->SetCanDraw(true); | 224 scheduler->SetCanDraw(true); |
202 | 225 |
203 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); | 226 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); |
204 client.Reset(); | 227 client.Reset(); |
205 scheduler->DidCreateAndInitializeOutputSurface(); | 228 scheduler->DidCreateAndInitializeOutputSurface(); |
206 EXPECT_EQ(0, client.num_actions_()); | 229 EXPECT_EQ(0, client.num_actions_()); |
207 } | 230 } |
208 | 231 |
209 TEST(SchedulerTest, RequestCommit) { | 232 TEST(SchedulerTest, RequestCommit) { |
210 FakeSchedulerClient client; | 233 FakeSchedulerClient client; |
211 SchedulerSettings scheduler_settings; | 234 SchedulerSettings scheduler_settings; |
212 Scheduler* scheduler = client.CreateScheduler(scheduler_settings); | 235 Scheduler* scheduler = client.CreateScheduler(scheduler_settings); |
213 scheduler->SetCanStart(); | 236 scheduler->SetCanStart(); |
214 scheduler->SetVisible(true); | 237 scheduler->SetVisible(true); |
215 scheduler->SetCanDraw(true); | 238 scheduler->SetCanDraw(true); |
216 | 239 |
217 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); | 240 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); |
218 InitializeOutputSurfaceAndFirstCommit(scheduler); | 241 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
219 | 242 |
220 // SetNeedsCommit should begin the frame on the next BeginImplFrame. | 243 // SetNeedsCommit should begin the frame on the next BeginImplFrame. |
221 client.Reset(); | 244 client.Reset(); |
222 scheduler->SetNeedsCommit(); | 245 scheduler->SetNeedsCommit(); |
223 EXPECT_TRUE(client.needs_begin_impl_frame()); | 246 EXPECT_TRUE(client.needs_begin_impl_frame()); |
224 EXPECT_SINGLE_ACTION("SetNeedsBeginImplFrame", client); | 247 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); |
225 client.Reset(); | 248 client.Reset(); |
226 | 249 |
227 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); | 250 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
228 EXPECT_SINGLE_ACTION("ScheduledActionSendBeginMainFrame", client); | 251 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
252 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); | |
229 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 253 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
230 EXPECT_TRUE(client.needs_begin_impl_frame()); | 254 EXPECT_TRUE(client.needs_begin_impl_frame()); |
231 client.Reset(); | 255 client.Reset(); |
232 | 256 |
233 // If we don't swap on the deadline, we need to request another | 257 // If we don't swap on the deadline, we need to request another |
234 // BeginImplFrame. | 258 // BeginImplFrame. |
235 scheduler->OnBeginImplFrameDeadline(); | 259 client.task_runner().RunPendingTasks(); // Run posted deadline. |
236 EXPECT_SINGLE_ACTION("SetNeedsBeginImplFrame", client); | 260 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); |
237 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 261 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
238 EXPECT_TRUE(client.needs_begin_impl_frame()); | 262 EXPECT_TRUE(client.needs_begin_impl_frame()); |
239 client.Reset(); | 263 client.Reset(); |
240 | 264 |
241 // NotifyReadyToCommit should trigger the commit. | 265 // NotifyReadyToCommit should trigger the commit. |
242 scheduler->NotifyBeginMainFrameStarted(); | 266 scheduler->NotifyBeginMainFrameStarted(); |
243 scheduler->NotifyReadyToCommit(); | 267 scheduler->NotifyReadyToCommit(); |
244 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); | 268 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); |
245 EXPECT_TRUE(client.needs_begin_impl_frame()); | 269 EXPECT_TRUE(client.needs_begin_impl_frame()); |
246 client.Reset(); | 270 client.Reset(); |
247 | 271 |
248 // BeginImplFrame should prepare the draw. | 272 // BeginImplFrame should prepare the draw. |
249 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); | 273 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
250 EXPECT_EQ(client.num_actions_(), 0); | 274 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); |
251 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 275 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
252 EXPECT_TRUE(client.needs_begin_impl_frame()); | 276 EXPECT_TRUE(client.needs_begin_impl_frame()); |
253 client.Reset(); | 277 client.Reset(); |
254 | 278 |
255 // BeginImplFrame deadline should draw. | 279 // BeginImplFrame deadline should draw. |
256 scheduler->OnBeginImplFrameDeadline(); | 280 client.task_runner().RunPendingTasks(); // Run posted deadline. |
257 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 2); | 281 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 2); |
258 EXPECT_ACTION("SetNeedsBeginImplFrame", client, 1, 2); | 282 EXPECT_ACTION("SetNeedsBeginFrame", client, 1, 2); |
259 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 283 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
260 EXPECT_TRUE(client.needs_begin_impl_frame()); | 284 EXPECT_TRUE(client.needs_begin_impl_frame()); |
261 client.Reset(); | 285 client.Reset(); |
262 | 286 |
263 // The following BeginImplFrame deadline should SetNeedsBeginImplFrame(false) | 287 // The following BeginImplFrame deadline should SetNeedsBeginFrame(false) |
264 // to avoid excessive toggles. | 288 // to avoid excessive toggles. |
265 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); | 289 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
266 EXPECT_EQ(client.num_actions_(), 0); | 290 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); |
267 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 291 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
268 client.Reset(); | 292 client.Reset(); |
269 | 293 |
270 scheduler->OnBeginImplFrameDeadline(); | 294 client.task_runner().RunPendingTasks(); // Run posted deadline. |
271 EXPECT_SINGLE_ACTION("SetNeedsBeginImplFrame", client); | 295 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); |
272 EXPECT_FALSE(client.needs_begin_impl_frame()); | 296 EXPECT_FALSE(client.needs_begin_impl_frame()); |
273 client.Reset(); | 297 client.Reset(); |
274 } | 298 } |
275 | 299 |
276 TEST(SchedulerTest, RequestCommitAfterBeginMainFrameSent) { | 300 TEST(SchedulerTest, RequestCommitAfterBeginMainFrameSent) { |
277 FakeSchedulerClient client; | 301 FakeSchedulerClient client; |
278 SchedulerSettings scheduler_settings; | 302 SchedulerSettings scheduler_settings; |
279 Scheduler* scheduler = client.CreateScheduler(scheduler_settings); | 303 Scheduler* scheduler = client.CreateScheduler(scheduler_settings); |
280 scheduler->SetCanStart(); | 304 scheduler->SetCanStart(); |
281 scheduler->SetVisible(true); | 305 scheduler->SetVisible(true); |
282 scheduler->SetCanDraw(true); | 306 scheduler->SetCanDraw(true); |
283 | 307 |
284 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); | 308 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); |
285 InitializeOutputSurfaceAndFirstCommit(scheduler); | 309 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
286 client.Reset(); | 310 client.Reset(); |
287 | 311 |
288 // SetNeedsCommit should begin the frame. | 312 // SetNeedsCommit should begin the frame. |
289 scheduler->SetNeedsCommit(); | 313 scheduler->SetNeedsCommit(); |
290 EXPECT_SINGLE_ACTION("SetNeedsBeginImplFrame", client); | 314 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); |
291 | 315 |
292 client.Reset(); | 316 client.Reset(); |
293 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); | 317 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
294 EXPECT_SINGLE_ACTION("ScheduledActionSendBeginMainFrame", client); | 318 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
319 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); | |
295 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 320 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
296 | 321 |
297 EXPECT_TRUE(client.needs_begin_impl_frame()); | 322 EXPECT_TRUE(client.needs_begin_impl_frame()); |
298 client.Reset(); | 323 client.Reset(); |
299 | 324 |
300 // Now SetNeedsCommit again. Calling here means we need a second commit. | 325 // Now SetNeedsCommit again. Calling here means we need a second commit. |
301 scheduler->SetNeedsCommit(); | 326 scheduler->SetNeedsCommit(); |
302 EXPECT_EQ(client.num_actions_(), 0); | 327 EXPECT_EQ(client.num_actions_(), 0); |
303 client.Reset(); | 328 client.Reset(); |
304 | 329 |
305 // Finish the first commit. | 330 // Finish the first commit. |
306 scheduler->NotifyBeginMainFrameStarted(); | 331 scheduler->NotifyBeginMainFrameStarted(); |
307 scheduler->NotifyReadyToCommit(); | 332 scheduler->NotifyReadyToCommit(); |
308 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); | 333 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); |
309 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 334 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
310 client.Reset(); | 335 client.Reset(); |
311 scheduler->OnBeginImplFrameDeadline(); | 336 client.task_runner().RunPendingTasks(); // Run posted deadline. |
312 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 2); | 337 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 2); |
313 EXPECT_ACTION("SetNeedsBeginImplFrame", client, 1, 2); | 338 EXPECT_ACTION("SetNeedsBeginFrame", client, 1, 2); |
314 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 339 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
315 | 340 |
316 // Because we just swapped, the Scheduler should also request the next | 341 // Because we just swapped, the Scheduler should also request the next |
317 // BeginImplFrame from the OutputSurface. | 342 // BeginImplFrame from the OutputSurface. |
318 EXPECT_TRUE(client.needs_begin_impl_frame()); | 343 EXPECT_TRUE(client.needs_begin_impl_frame()); |
319 client.Reset(); | 344 client.Reset(); |
320 | |
321 // Since another commit is needed, the next BeginImplFrame should initiate | 345 // Since another commit is needed, the next BeginImplFrame should initiate |
322 // the second commit. | 346 // the second commit. |
323 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); | 347 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
324 EXPECT_SINGLE_ACTION("ScheduledActionSendBeginMainFrame", client); | 348 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
349 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); | |
325 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 350 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
326 client.Reset(); | 351 client.Reset(); |
327 | 352 |
328 // Finishing the commit before the deadline should post a new deadline task | 353 // Finishing the commit before the deadline should post a new deadline task |
329 // to trigger the deadline early. | 354 // to trigger the deadline early. |
330 scheduler->NotifyBeginMainFrameStarted(); | 355 scheduler->NotifyBeginMainFrameStarted(); |
331 scheduler->NotifyReadyToCommit(); | 356 scheduler->NotifyReadyToCommit(); |
332 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); | 357 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); |
333 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 358 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
334 client.Reset(); | 359 client.Reset(); |
335 scheduler->OnBeginImplFrameDeadline(); | 360 client.task_runner().RunPendingTasks(); // Run posted deadline. |
336 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 2); | 361 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 2); |
337 EXPECT_ACTION("SetNeedsBeginImplFrame", client, 1, 2); | 362 EXPECT_ACTION("SetNeedsBeginFrame", client, 1, 2); |
338 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 363 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
339 EXPECT_TRUE(client.needs_begin_impl_frame()); | 364 EXPECT_TRUE(client.needs_begin_impl_frame()); |
340 client.Reset(); | 365 client.Reset(); |
341 | 366 |
342 // On the next BeginImplFrame, verify we go back to a quiescent state and | 367 // On the next BeginImplFrame, verify we go back to a quiescent state and |
343 // no longer request BeginImplFrames. | 368 // no longer request BeginImplFrames. |
344 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); | 369 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
345 scheduler->OnBeginImplFrameDeadline(); | 370 client.task_runner().RunPendingTasks(); // Run posted deadline. |
346 EXPECT_FALSE(client.needs_begin_impl_frame()); | 371 EXPECT_FALSE(client.needs_begin_impl_frame()); |
347 client.Reset(); | 372 client.Reset(); |
348 } | 373 } |
349 | 374 |
350 TEST(SchedulerTest, TextureAcquisitionCausesCommitInsteadOfDraw) { | 375 TEST(SchedulerTest, TextureAcquisitionCausesCommitInsteadOfDraw) { |
351 FakeSchedulerClient client; | 376 FakeSchedulerClient client; |
352 SchedulerSettings scheduler_settings; | 377 SchedulerSettings scheduler_settings; |
353 Scheduler* scheduler = client.CreateScheduler(scheduler_settings); | 378 Scheduler* scheduler = client.CreateScheduler(scheduler_settings); |
354 scheduler->SetCanStart(); | 379 scheduler->SetCanStart(); |
355 scheduler->SetVisible(true); | 380 scheduler->SetVisible(true); |
356 scheduler->SetCanDraw(true); | 381 scheduler->SetCanDraw(true); |
357 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); | 382 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); |
358 | 383 |
359 InitializeOutputSurfaceAndFirstCommit(scheduler); | 384 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
360 client.Reset(); | 385 client.Reset(); |
361 scheduler->SetNeedsRedraw(); | 386 scheduler->SetNeedsRedraw(); |
362 EXPECT_TRUE(scheduler->RedrawPending()); | 387 EXPECT_TRUE(scheduler->RedrawPending()); |
363 EXPECT_SINGLE_ACTION("SetNeedsBeginImplFrame", client); | 388 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); |
364 EXPECT_TRUE(client.needs_begin_impl_frame()); | 389 EXPECT_TRUE(client.needs_begin_impl_frame()); |
365 | 390 |
366 client.Reset(); | 391 client.Reset(); |
367 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); | 392 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
368 EXPECT_EQ(client.num_actions_(), 0); | 393 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); |
369 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 394 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
370 client.Reset(); | 395 client.Reset(); |
371 scheduler->OnBeginImplFrameDeadline(); | 396 client.task_runner().RunPendingTasks(); // Run posted deadline. |
372 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 2); | 397 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 2); |
373 EXPECT_ACTION("SetNeedsBeginImplFrame", client, 1, 2); | 398 EXPECT_ACTION("SetNeedsBeginFrame", client, 1, 2); |
374 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 399 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
375 EXPECT_FALSE(scheduler->RedrawPending()); | 400 EXPECT_FALSE(scheduler->RedrawPending()); |
376 EXPECT_TRUE(client.needs_begin_impl_frame()); | 401 EXPECT_TRUE(client.needs_begin_impl_frame()); |
377 | 402 |
378 client.Reset(); | 403 client.Reset(); |
379 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); | 404 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
380 EXPECT_EQ(client.num_actions_(), 0); | 405 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); |
381 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 406 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
382 client.Reset(); | 407 client.Reset(); |
383 scheduler->OnBeginImplFrameDeadline(); | 408 client.task_runner().RunPendingTasks(); // Run posted deadline. |
384 EXPECT_SINGLE_ACTION("SetNeedsBeginImplFrame", client); | 409 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); |
385 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 410 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
386 EXPECT_FALSE(scheduler->RedrawPending()); | 411 EXPECT_FALSE(scheduler->RedrawPending()); |
387 EXPECT_FALSE(client.needs_begin_impl_frame()); | 412 EXPECT_FALSE(client.needs_begin_impl_frame()); |
388 | 413 |
389 client.Reset(); | 414 client.Reset(); |
390 scheduler->SetMainThreadNeedsLayerTextures(); | 415 scheduler->SetMainThreadNeedsLayerTextures(); |
391 EXPECT_SINGLE_ACTION("ScheduledActionAcquireLayerTexturesForMainThread", | 416 EXPECT_SINGLE_ACTION("ScheduledActionAcquireLayerTexturesForMainThread", |
392 client); | 417 client); |
393 | 418 |
394 // We should request a BeginImplFrame in anticipation of a draw. | 419 // We should request a BeginImplFrame in anticipation of a draw. |
395 client.Reset(); | 420 client.Reset(); |
396 scheduler->SetNeedsRedraw(); | 421 scheduler->SetNeedsRedraw(); |
397 EXPECT_TRUE(scheduler->RedrawPending()); | 422 EXPECT_TRUE(scheduler->RedrawPending()); |
398 EXPECT_SINGLE_ACTION("SetNeedsBeginImplFrame", client); | 423 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); |
399 EXPECT_TRUE(client.needs_begin_impl_frame()); | 424 EXPECT_TRUE(client.needs_begin_impl_frame()); |
400 | 425 |
401 // No draw happens since the textures are acquired by the main thread. | 426 // No draw happens since the textures are acquired by the main thread. |
402 client.Reset(); | 427 client.Reset(); |
403 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); | 428 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
404 EXPECT_EQ(client.num_actions_(), 0); | 429 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); |
405 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 430 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
406 client.Reset(); | 431 client.Reset(); |
407 scheduler->OnBeginImplFrameDeadline(); | 432 client.task_runner().RunPendingTasks(); // Run posted deadline. |
408 EXPECT_SINGLE_ACTION("SetNeedsBeginImplFrame", client); | 433 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); |
409 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 434 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
410 EXPECT_TRUE(scheduler->RedrawPending()); | 435 EXPECT_TRUE(scheduler->RedrawPending()); |
411 EXPECT_TRUE(client.needs_begin_impl_frame()); | 436 EXPECT_TRUE(client.needs_begin_impl_frame()); |
412 | 437 |
413 client.Reset(); | 438 client.Reset(); |
414 scheduler->SetNeedsCommit(); | 439 scheduler->SetNeedsCommit(); |
415 EXPECT_EQ(0, client.num_actions_()); | 440 EXPECT_EQ(0, client.num_actions_()); |
416 | 441 |
417 client.Reset(); | 442 client.Reset(); |
418 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); | 443 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
419 EXPECT_SINGLE_ACTION("ScheduledActionSendBeginMainFrame", client); | 444 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
445 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); | |
420 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 446 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
421 | 447 |
422 // Commit will release the texture. | 448 // Commit will release the texture. |
423 client.Reset(); | 449 client.Reset(); |
424 scheduler->NotifyBeginMainFrameStarted(); | 450 scheduler->NotifyBeginMainFrameStarted(); |
425 scheduler->NotifyReadyToCommit(); | 451 scheduler->NotifyReadyToCommit(); |
426 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); | 452 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); |
427 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 453 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
428 EXPECT_TRUE(scheduler->RedrawPending()); | 454 EXPECT_TRUE(scheduler->RedrawPending()); |
429 | 455 |
430 // Now we can draw again after the commit happens. | 456 // Now we can draw again after the commit happens. |
431 client.Reset(); | 457 client.Reset(); |
432 scheduler->OnBeginImplFrameDeadline(); | 458 client.task_runner().RunPendingTasks(); // Run posted deadline. |
433 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 2); | 459 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 2); |
434 EXPECT_ACTION("SetNeedsBeginImplFrame", client, 1, 2); | 460 EXPECT_ACTION("SetNeedsBeginFrame", client, 1, 2); |
435 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 461 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
436 EXPECT_FALSE(scheduler->RedrawPending()); | 462 EXPECT_FALSE(scheduler->RedrawPending()); |
437 EXPECT_TRUE(client.needs_begin_impl_frame()); | 463 EXPECT_TRUE(client.needs_begin_impl_frame()); |
438 | 464 |
439 // Make sure we stop requesting BeginImplFrames if we don't swap. | 465 // Make sure we stop requesting BeginImplFrames if we don't swap. |
440 client.Reset(); | 466 client.Reset(); |
441 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); | 467 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
442 EXPECT_EQ(client.num_actions_(), 0); | 468 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); |
443 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 469 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
444 client.Reset(); | 470 client.Reset(); |
445 scheduler->OnBeginImplFrameDeadline(); | 471 client.task_runner().RunPendingTasks(); // Run posted deadline. |
446 EXPECT_SINGLE_ACTION("SetNeedsBeginImplFrame", client); | 472 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); |
447 EXPECT_FALSE(client.needs_begin_impl_frame()); | 473 EXPECT_FALSE(client.needs_begin_impl_frame()); |
448 } | 474 } |
449 | 475 |
450 TEST(SchedulerTest, TextureAcquisitionCollision) { | 476 TEST(SchedulerTest, TextureAcquisitionCollision) { |
451 FakeSchedulerClient client; | 477 FakeSchedulerClient client; |
452 SchedulerSettings scheduler_settings; | 478 SchedulerSettings scheduler_settings; |
453 Scheduler* scheduler = client.CreateScheduler(scheduler_settings); | 479 Scheduler* scheduler = client.CreateScheduler(scheduler_settings); |
454 scheduler->SetCanStart(); | 480 scheduler->SetCanStart(); |
455 scheduler->SetVisible(true); | 481 scheduler->SetVisible(true); |
456 scheduler->SetCanDraw(true); | 482 scheduler->SetCanDraw(true); |
457 | 483 |
458 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); | 484 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); |
459 InitializeOutputSurfaceAndFirstCommit(scheduler); | 485 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
460 | 486 |
461 client.Reset(); | 487 client.Reset(); |
462 scheduler->SetNeedsCommit(); | 488 scheduler->SetNeedsCommit(); |
463 EXPECT_SINGLE_ACTION("SetNeedsBeginImplFrame", client); | 489 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); |
464 | 490 |
465 client.Reset(); | 491 client.Reset(); |
466 scheduler->SetMainThreadNeedsLayerTextures(); | 492 scheduler->SetMainThreadNeedsLayerTextures(); |
467 EXPECT_SINGLE_ACTION( | 493 EXPECT_SINGLE_ACTION( |
468 "ScheduledActionAcquireLayerTexturesForMainThread", client); | 494 "ScheduledActionAcquireLayerTexturesForMainThread", client); |
469 | 495 |
470 client.Reset(); | 496 client.Reset(); |
471 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); | 497 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
472 EXPECT_SINGLE_ACTION("ScheduledActionSendBeginMainFrame", client); | 498 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
499 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); | |
473 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 500 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
474 | 501 |
475 client.Reset(); | 502 client.Reset(); |
476 scheduler->OnBeginImplFrameDeadline(); | 503 client.task_runner().RunPendingTasks(); // Run posted deadline. |
477 EXPECT_SINGLE_ACTION("SetNeedsBeginImplFrame", client); | 504 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); |
478 | 505 |
479 // Although the compositor cannot draw because textures are locked by main | 506 // Although the compositor cannot draw because textures are locked by main |
480 // thread, we continue requesting SetNeedsBeginImplFrame in anticipation of | 507 // thread, we continue requesting SetNeedsBeginFrame in anticipation of |
481 // the unlock. | 508 // the unlock. |
482 EXPECT_TRUE(client.needs_begin_impl_frame()); | 509 EXPECT_TRUE(client.needs_begin_impl_frame()); |
483 | 510 |
484 // Trigger the commit. | 511 // Trigger the commit. |
485 scheduler->NotifyBeginMainFrameStarted(); | 512 scheduler->NotifyBeginMainFrameStarted(); |
486 scheduler->NotifyReadyToCommit(); | 513 scheduler->NotifyReadyToCommit(); |
487 EXPECT_TRUE(client.needs_begin_impl_frame()); | 514 EXPECT_TRUE(client.needs_begin_impl_frame()); |
488 | 515 |
489 // Between commit and draw, texture acquisition for main thread delayed, | 516 // Between commit and draw, texture acquisition for main thread delayed, |
490 // and main thread blocks. | 517 // and main thread blocks. |
491 client.Reset(); | 518 client.Reset(); |
492 scheduler->SetMainThreadNeedsLayerTextures(); | 519 scheduler->SetMainThreadNeedsLayerTextures(); |
493 EXPECT_EQ(0, client.num_actions_()); | 520 EXPECT_EQ(0, client.num_actions_()); |
494 | 521 |
495 // No implicit commit is expected. | 522 // No implicit commit is expected. |
496 client.Reset(); | 523 client.Reset(); |
497 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); | 524 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
498 EXPECT_EQ(client.num_actions_(), 0); | 525 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); |
499 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 526 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
500 | 527 |
501 client.Reset(); | 528 client.Reset(); |
502 scheduler->OnBeginImplFrameDeadline(); | 529 client.task_runner().RunPendingTasks(); // Run posted deadline. |
503 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 3); | 530 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 3); |
504 EXPECT_ACTION( | 531 EXPECT_ACTION( |
505 "ScheduledActionAcquireLayerTexturesForMainThread", client, 1, 3); | 532 "ScheduledActionAcquireLayerTexturesForMainThread", client, 1, 3); |
506 EXPECT_ACTION("SetNeedsBeginImplFrame", client, 2, 3); | 533 EXPECT_ACTION("SetNeedsBeginFrame", client, 2, 3); |
507 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 534 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
508 EXPECT_TRUE(client.needs_begin_impl_frame()); | 535 EXPECT_TRUE(client.needs_begin_impl_frame()); |
509 | 536 |
510 // The compositor should not draw because textures are locked by main | 537 // The compositor should not draw because textures are locked by main |
511 // thread. | 538 // thread. |
512 client.Reset(); | 539 client.Reset(); |
513 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); | 540 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
514 EXPECT_EQ(client.num_actions_(), 0); | 541 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); |
515 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 542 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
516 client.Reset(); | 543 client.Reset(); |
517 scheduler->OnBeginImplFrameDeadline(); | 544 client.task_runner().RunPendingTasks(); // Run posted deadline. |
518 EXPECT_SINGLE_ACTION("SetNeedsBeginImplFrame", client); | 545 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); |
519 EXPECT_FALSE(client.needs_begin_impl_frame()); | 546 EXPECT_FALSE(client.needs_begin_impl_frame()); |
520 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 547 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
521 | 548 |
522 // The impl thread need an explicit commit from the main thread to lock | 549 // The impl thread need an explicit commit from the main thread to lock |
523 // the textures. | 550 // the textures. |
524 client.Reset(); | 551 client.Reset(); |
525 scheduler->SetNeedsCommit(); | 552 scheduler->SetNeedsCommit(); |
526 EXPECT_SINGLE_ACTION("SetNeedsBeginImplFrame", client); | 553 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); |
527 EXPECT_TRUE(client.needs_begin_impl_frame()); | 554 EXPECT_TRUE(client.needs_begin_impl_frame()); |
528 | 555 |
529 client.Reset(); | 556 client.Reset(); |
530 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); | 557 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
531 EXPECT_SINGLE_ACTION("ScheduledActionSendBeginMainFrame", client); | 558 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
559 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); | |
532 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 560 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
533 client.Reset(); | 561 client.Reset(); |
534 | 562 |
535 // Trigger the commit, which will trigger the deadline task early. | 563 // Trigger the commit, which will trigger the deadline task early. |
536 scheduler->NotifyBeginMainFrameStarted(); | 564 scheduler->NotifyBeginMainFrameStarted(); |
537 scheduler->NotifyReadyToCommit(); | 565 scheduler->NotifyReadyToCommit(); |
538 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); | 566 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); |
539 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 567 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
540 EXPECT_TRUE(client.needs_begin_impl_frame()); | 568 EXPECT_TRUE(client.needs_begin_impl_frame()); |
541 client.Reset(); | 569 client.Reset(); |
542 | 570 |
543 // Verify we draw on the next BeginImplFrame deadline | 571 // Verify we draw on the next BeginImplFrame deadline |
544 scheduler->OnBeginImplFrameDeadline(); | 572 client.task_runner().RunPendingTasks(); // Run posted deadline. |
545 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 2); | 573 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 2); |
546 EXPECT_ACTION("SetNeedsBeginImplFrame", client, 1, 2); | 574 EXPECT_ACTION("SetNeedsBeginFrame", client, 1, 2); |
547 EXPECT_TRUE(client.needs_begin_impl_frame()); | 575 EXPECT_TRUE(client.needs_begin_impl_frame()); |
548 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 576 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
549 client.Reset(); | 577 client.Reset(); |
550 } | 578 } |
551 | 579 |
552 TEST(SchedulerTest, VisibilitySwitchWithTextureAcquisition) { | 580 TEST(SchedulerTest, VisibilitySwitchWithTextureAcquisition) { |
553 FakeSchedulerClient client; | 581 FakeSchedulerClient client; |
554 SchedulerSettings scheduler_settings; | 582 SchedulerSettings scheduler_settings; |
555 Scheduler* scheduler = client.CreateScheduler(scheduler_settings); | 583 Scheduler* scheduler = client.CreateScheduler(scheduler_settings); |
556 scheduler->SetCanStart(); | 584 scheduler->SetCanStart(); |
557 scheduler->SetVisible(true); | 585 scheduler->SetVisible(true); |
558 scheduler->SetCanDraw(true); | 586 scheduler->SetCanDraw(true); |
559 | 587 |
560 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); | 588 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); |
561 client.Reset(); | 589 client.Reset(); |
562 scheduler->DidCreateAndInitializeOutputSurface(); | 590 scheduler->DidCreateAndInitializeOutputSurface(); |
563 | 591 |
564 scheduler->SetNeedsCommit(); | 592 scheduler->SetNeedsCommit(); |
565 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); | 593 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
566 scheduler->OnBeginImplFrameDeadline(); | 594 client.task_runner().RunPendingTasks(); // Run posted deadline. |
567 scheduler->NotifyBeginMainFrameStarted(); | 595 scheduler->NotifyBeginMainFrameStarted(); |
568 scheduler->NotifyReadyToCommit(); | 596 scheduler->NotifyReadyToCommit(); |
569 scheduler->SetMainThreadNeedsLayerTextures(); | 597 scheduler->SetMainThreadNeedsLayerTextures(); |
570 scheduler->SetNeedsCommit(); | 598 scheduler->SetNeedsCommit(); |
571 client.Reset(); | 599 client.Reset(); |
572 // Verify that pending texture acquisition fires when visibility | 600 // Verify that pending texture acquisition fires when visibility |
573 // is lost in order to avoid a deadlock. | 601 // is lost in order to avoid a deadlock. |
574 scheduler->SetVisible(false); | 602 scheduler->SetVisible(false); |
575 EXPECT_SINGLE_ACTION("ScheduledActionAcquireLayerTexturesForMainThread", | 603 EXPECT_SINGLE_ACTION("ScheduledActionAcquireLayerTexturesForMainThread", |
576 client); | 604 client); |
577 | 605 |
578 client.Reset(); | 606 client.Reset(); |
579 scheduler->SetVisible(true); | 607 scheduler->SetVisible(true); |
580 EXPECT_EQ(0, client.num_actions_()); | 608 EXPECT_EQ(0, client.num_actions_()); |
581 EXPECT_TRUE(client.needs_begin_impl_frame()); | 609 EXPECT_TRUE(client.needs_begin_impl_frame()); |
582 | 610 |
583 // Regaining visibility with textures acquired by main thread while | 611 // Regaining visibility with textures acquired by main thread while |
584 // compositor is waiting for first draw should result in a request | 612 // compositor is waiting for first draw should result in a request |
585 // for a new frame in order to escape a deadlock. | 613 // for a new frame in order to escape a deadlock. |
586 client.Reset(); | 614 client.Reset(); |
587 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); | 615 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
588 EXPECT_SINGLE_ACTION("ScheduledActionSendBeginMainFrame", client); | 616 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
617 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); | |
589 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 618 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
590 } | 619 } |
591 | 620 |
592 class SchedulerClientThatsetNeedsDrawInsideDraw : public FakeSchedulerClient { | 621 class SchedulerClientThatsetNeedsDrawInsideDraw : public FakeSchedulerClient { |
593 public: | 622 public: |
594 virtual void ScheduledActionSendBeginMainFrame() OVERRIDE {} | 623 virtual void ScheduledActionSendBeginMainFrame() OVERRIDE {} |
595 virtual DrawSwapReadbackResult ScheduledActionDrawAndSwapIfPossible() | 624 virtual DrawSwapReadbackResult ScheduledActionDrawAndSwapIfPossible() |
596 OVERRIDE { | 625 OVERRIDE { |
597 // Only SetNeedsRedraw the first time this is called | 626 // Only SetNeedsRedraw the first time this is called |
598 if (!num_draws_) | 627 if (!num_draws_) |
(...skipping 18 matching lines...) Expand all Loading... | |
617 // 1. the scheduler dropping SetNeedsRedraw requests that happen inside | 646 // 1. the scheduler dropping SetNeedsRedraw requests that happen inside |
618 // a ScheduledActionDrawAndSwap | 647 // a ScheduledActionDrawAndSwap |
619 // 2. the scheduler drawing twice inside a single tick | 648 // 2. the scheduler drawing twice inside a single tick |
620 TEST(SchedulerTest, RequestRedrawInsideDraw) { | 649 TEST(SchedulerTest, RequestRedrawInsideDraw) { |
621 SchedulerClientThatsetNeedsDrawInsideDraw client; | 650 SchedulerClientThatsetNeedsDrawInsideDraw client; |
622 SchedulerSettings default_scheduler_settings; | 651 SchedulerSettings default_scheduler_settings; |
623 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings); | 652 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings); |
624 scheduler->SetCanStart(); | 653 scheduler->SetCanStart(); |
625 scheduler->SetVisible(true); | 654 scheduler->SetVisible(true); |
626 scheduler->SetCanDraw(true); | 655 scheduler->SetCanDraw(true); |
627 InitializeOutputSurfaceAndFirstCommit(scheduler); | 656 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
628 client.Reset(); | 657 client.Reset(); |
629 | 658 |
630 scheduler->SetNeedsRedraw(); | 659 scheduler->SetNeedsRedraw(); |
631 EXPECT_TRUE(scheduler->RedrawPending()); | 660 EXPECT_TRUE(scheduler->RedrawPending()); |
632 EXPECT_TRUE(client.needs_begin_impl_frame()); | 661 EXPECT_TRUE(client.needs_begin_impl_frame()); |
633 EXPECT_EQ(0, client.num_draws()); | 662 EXPECT_EQ(0, client.num_draws()); |
634 | 663 |
635 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); | 664 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
636 scheduler->OnBeginImplFrameDeadline(); | 665 client.task_runner().RunPendingTasks(); // Run posted deadline. |
637 EXPECT_EQ(1, client.num_draws()); | 666 EXPECT_EQ(1, client.num_draws()); |
638 EXPECT_TRUE(scheduler->RedrawPending()); | 667 EXPECT_TRUE(scheduler->RedrawPending()); |
639 EXPECT_TRUE(client.needs_begin_impl_frame()); | 668 EXPECT_TRUE(client.needs_begin_impl_frame()); |
640 | 669 |
641 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); | 670 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
642 scheduler->OnBeginImplFrameDeadline(); | 671 client.task_runner().RunPendingTasks(); // Run posted deadline. |
643 EXPECT_EQ(2, client.num_draws()); | 672 EXPECT_EQ(2, client.num_draws()); |
644 EXPECT_FALSE(scheduler->RedrawPending()); | 673 EXPECT_FALSE(scheduler->RedrawPending()); |
645 EXPECT_TRUE(client.needs_begin_impl_frame()); | 674 EXPECT_TRUE(client.needs_begin_impl_frame()); |
646 | 675 |
647 // We stop requesting BeginImplFrames after a BeginImplFrame where we don't | 676 // We stop requesting BeginImplFrames after a BeginImplFrame where we don't |
648 // swap. | 677 // swap. |
649 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); | 678 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
650 scheduler->OnBeginImplFrameDeadline(); | 679 client.task_runner().RunPendingTasks(); // Run posted deadline. |
651 EXPECT_EQ(2, client.num_draws()); | 680 EXPECT_EQ(2, client.num_draws()); |
652 EXPECT_FALSE(scheduler->RedrawPending()); | 681 EXPECT_FALSE(scheduler->RedrawPending()); |
653 EXPECT_FALSE(client.needs_begin_impl_frame()); | 682 EXPECT_FALSE(client.needs_begin_impl_frame()); |
654 } | 683 } |
655 | 684 |
656 // Test that requesting redraw inside a failed draw doesn't lose the request. | 685 // Test that requesting redraw inside a failed draw doesn't lose the request. |
657 TEST(SchedulerTest, RequestRedrawInsideFailedDraw) { | 686 TEST(SchedulerTest, RequestRedrawInsideFailedDraw) { |
658 SchedulerClientThatsetNeedsDrawInsideDraw client; | 687 SchedulerClientThatsetNeedsDrawInsideDraw client; |
659 SchedulerSettings default_scheduler_settings; | 688 SchedulerSettings default_scheduler_settings; |
660 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings); | 689 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings); |
661 scheduler->SetCanStart(); | 690 scheduler->SetCanStart(); |
662 scheduler->SetVisible(true); | 691 scheduler->SetVisible(true); |
663 scheduler->SetCanDraw(true); | 692 scheduler->SetCanDraw(true); |
664 InitializeOutputSurfaceAndFirstCommit(scheduler); | 693 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
665 client.Reset(); | 694 client.Reset(); |
666 | 695 |
667 client.SetDrawWillHappen(false); | 696 client.SetDrawWillHappen(false); |
668 | 697 |
669 scheduler->SetNeedsRedraw(); | 698 scheduler->SetNeedsRedraw(); |
670 EXPECT_TRUE(scheduler->RedrawPending()); | 699 EXPECT_TRUE(scheduler->RedrawPending()); |
671 EXPECT_TRUE(client.needs_begin_impl_frame()); | 700 EXPECT_TRUE(client.needs_begin_impl_frame()); |
672 EXPECT_EQ(0, client.num_draws()); | 701 EXPECT_EQ(0, client.num_draws()); |
673 | 702 |
674 // Fail the draw. | 703 // Fail the draw. |
675 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); | 704 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
676 scheduler->OnBeginImplFrameDeadline(); | 705 client.task_runner().RunPendingTasks(); // Run posted deadline. |
677 EXPECT_EQ(1, client.num_draws()); | 706 EXPECT_EQ(1, client.num_draws()); |
678 | 707 |
679 // We have a commit pending and the draw failed, and we didn't lose the redraw | 708 // We have a commit pending and the draw failed, and we didn't lose the redraw |
680 // request. | 709 // request. |
681 EXPECT_TRUE(scheduler->CommitPending()); | 710 EXPECT_TRUE(scheduler->CommitPending()); |
682 EXPECT_TRUE(scheduler->RedrawPending()); | 711 EXPECT_TRUE(scheduler->RedrawPending()); |
683 EXPECT_TRUE(client.needs_begin_impl_frame()); | 712 EXPECT_TRUE(client.needs_begin_impl_frame()); |
684 | 713 |
685 // Fail the draw again. | 714 // Fail the draw again. |
686 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); | 715 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
687 scheduler->OnBeginImplFrameDeadline(); | 716 client.task_runner().RunPendingTasks(); // Run posted deadline. |
688 EXPECT_EQ(2, client.num_draws()); | 717 EXPECT_EQ(2, client.num_draws()); |
689 EXPECT_TRUE(scheduler->CommitPending()); | 718 EXPECT_TRUE(scheduler->CommitPending()); |
690 EXPECT_TRUE(scheduler->RedrawPending()); | 719 EXPECT_TRUE(scheduler->RedrawPending()); |
691 EXPECT_TRUE(client.needs_begin_impl_frame()); | 720 EXPECT_TRUE(client.needs_begin_impl_frame()); |
692 | 721 |
693 // Draw successfully. | 722 // Draw successfully. |
694 client.SetDrawWillHappen(true); | 723 client.SetDrawWillHappen(true); |
695 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); | 724 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
696 scheduler->OnBeginImplFrameDeadline(); | 725 client.task_runner().RunPendingTasks(); // Run posted deadline. |
697 EXPECT_EQ(3, client.num_draws()); | 726 EXPECT_EQ(3, client.num_draws()); |
698 EXPECT_TRUE(scheduler->CommitPending()); | 727 EXPECT_TRUE(scheduler->CommitPending()); |
699 EXPECT_FALSE(scheduler->RedrawPending()); | 728 EXPECT_FALSE(scheduler->RedrawPending()); |
700 EXPECT_TRUE(client.needs_begin_impl_frame()); | 729 EXPECT_TRUE(client.needs_begin_impl_frame()); |
701 } | 730 } |
702 | 731 |
703 class SchedulerClientThatSetNeedsCommitInsideDraw : public FakeSchedulerClient { | 732 class SchedulerClientThatSetNeedsCommitInsideDraw : public FakeSchedulerClient { |
704 public: | 733 public: |
705 SchedulerClientThatSetNeedsCommitInsideDraw() | 734 SchedulerClientThatSetNeedsCommitInsideDraw() |
706 : set_needs_commit_on_next_draw_(false) {} | 735 : set_needs_commit_on_next_draw_(false) {} |
(...skipping 29 matching lines...) Expand all Loading... | |
736 | 765 |
737 // Tests for the scheduler infinite-looping on SetNeedsCommit requests that | 766 // Tests for the scheduler infinite-looping on SetNeedsCommit requests that |
738 // happen inside a ScheduledActionDrawAndSwap | 767 // happen inside a ScheduledActionDrawAndSwap |
739 TEST(SchedulerTest, RequestCommitInsideDraw) { | 768 TEST(SchedulerTest, RequestCommitInsideDraw) { |
740 SchedulerClientThatSetNeedsCommitInsideDraw client; | 769 SchedulerClientThatSetNeedsCommitInsideDraw client; |
741 SchedulerSettings default_scheduler_settings; | 770 SchedulerSettings default_scheduler_settings; |
742 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings); | 771 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings); |
743 scheduler->SetCanStart(); | 772 scheduler->SetCanStart(); |
744 scheduler->SetVisible(true); | 773 scheduler->SetVisible(true); |
745 scheduler->SetCanDraw(true); | 774 scheduler->SetCanDraw(true); |
746 InitializeOutputSurfaceAndFirstCommit(scheduler); | 775 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
747 client.Reset(); | 776 client.Reset(); |
748 | 777 |
749 EXPECT_FALSE(client.needs_begin_impl_frame()); | 778 EXPECT_FALSE(client.needs_begin_impl_frame()); |
750 scheduler->SetNeedsRedraw(); | 779 scheduler->SetNeedsRedraw(); |
751 EXPECT_TRUE(scheduler->RedrawPending()); | 780 EXPECT_TRUE(scheduler->RedrawPending()); |
752 EXPECT_EQ(0, client.num_draws()); | 781 EXPECT_EQ(0, client.num_draws()); |
753 EXPECT_TRUE(client.needs_begin_impl_frame()); | 782 EXPECT_TRUE(client.needs_begin_impl_frame()); |
754 | 783 |
755 client.SetNeedsCommitOnNextDraw(); | 784 client.SetNeedsCommitOnNextDraw(); |
756 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); | 785 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
757 client.SetNeedsCommitOnNextDraw(); | 786 client.SetNeedsCommitOnNextDraw(); |
758 scheduler->OnBeginImplFrameDeadline(); | 787 client.task_runner().RunPendingTasks(); // Run posted deadline. |
759 EXPECT_EQ(1, client.num_draws()); | 788 EXPECT_EQ(1, client.num_draws()); |
760 EXPECT_TRUE(scheduler->CommitPending()); | 789 EXPECT_TRUE(scheduler->CommitPending()); |
761 EXPECT_TRUE(client.needs_begin_impl_frame()); | 790 EXPECT_TRUE(client.needs_begin_impl_frame()); |
762 scheduler->NotifyBeginMainFrameStarted(); | 791 scheduler->NotifyBeginMainFrameStarted(); |
763 scheduler->NotifyReadyToCommit(); | 792 scheduler->NotifyReadyToCommit(); |
764 | 793 |
765 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); | 794 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
766 scheduler->OnBeginImplFrameDeadline(); | 795 client.task_runner().RunPendingTasks(); // Run posted deadline. |
767 EXPECT_EQ(2, client.num_draws()); | 796 EXPECT_EQ(2, client.num_draws()); |
768 | 797 |
769 EXPECT_FALSE(scheduler->RedrawPending()); | 798 EXPECT_FALSE(scheduler->RedrawPending()); |
770 EXPECT_FALSE(scheduler->CommitPending()); | 799 EXPECT_FALSE(scheduler->CommitPending()); |
771 EXPECT_TRUE(client.needs_begin_impl_frame()); | 800 EXPECT_TRUE(client.needs_begin_impl_frame()); |
772 | 801 |
773 // We stop requesting BeginImplFrames after a BeginImplFrame where we don't | 802 // We stop requesting BeginImplFrames after a BeginImplFrame where we don't |
774 // swap. | 803 // swap. |
775 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); | 804 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
776 scheduler->OnBeginImplFrameDeadline(); | 805 client.task_runner().RunPendingTasks(); // Run posted deadline. |
777 EXPECT_EQ(2, client.num_draws()); | 806 EXPECT_EQ(2, client.num_draws()); |
778 EXPECT_FALSE(scheduler->RedrawPending()); | 807 EXPECT_FALSE(scheduler->RedrawPending()); |
779 EXPECT_FALSE(scheduler->CommitPending()); | 808 EXPECT_FALSE(scheduler->CommitPending()); |
780 EXPECT_FALSE(client.needs_begin_impl_frame()); | 809 EXPECT_FALSE(client.needs_begin_impl_frame()); |
781 } | 810 } |
782 | 811 |
783 // Tests that when a draw fails then the pending commit should not be dropped. | 812 // Tests that when a draw fails then the pending commit should not be dropped. |
784 TEST(SchedulerTest, RequestCommitInsideFailedDraw) { | 813 TEST(SchedulerTest, RequestCommitInsideFailedDraw) { |
785 SchedulerClientThatsetNeedsDrawInsideDraw client; | 814 SchedulerClientThatsetNeedsDrawInsideDraw client; |
786 SchedulerSettings default_scheduler_settings; | 815 SchedulerSettings default_scheduler_settings; |
787 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings); | 816 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings); |
788 scheduler->SetCanStart(); | 817 scheduler->SetCanStart(); |
789 scheduler->SetVisible(true); | 818 scheduler->SetVisible(true); |
790 scheduler->SetCanDraw(true); | 819 scheduler->SetCanDraw(true); |
791 InitializeOutputSurfaceAndFirstCommit(scheduler); | 820 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
792 client.Reset(); | 821 client.Reset(); |
793 | 822 |
794 client.SetDrawWillHappen(false); | 823 client.SetDrawWillHappen(false); |
795 | 824 |
796 scheduler->SetNeedsRedraw(); | 825 scheduler->SetNeedsRedraw(); |
797 EXPECT_TRUE(scheduler->RedrawPending()); | 826 EXPECT_TRUE(scheduler->RedrawPending()); |
798 EXPECT_TRUE(client.needs_begin_impl_frame()); | 827 EXPECT_TRUE(client.needs_begin_impl_frame()); |
799 EXPECT_EQ(0, client.num_draws()); | 828 EXPECT_EQ(0, client.num_draws()); |
800 | 829 |
801 // Fail the draw. | 830 // Fail the draw. |
802 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); | 831 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
803 scheduler->OnBeginImplFrameDeadline(); | 832 client.task_runner().RunPendingTasks(); // Run posted deadline. |
804 EXPECT_EQ(1, client.num_draws()); | 833 EXPECT_EQ(1, client.num_draws()); |
805 | 834 |
806 // We have a commit pending and the draw failed, and we didn't lose the commit | 835 // We have a commit pending and the draw failed, and we didn't lose the commit |
807 // request. | 836 // request. |
808 EXPECT_TRUE(scheduler->CommitPending()); | 837 EXPECT_TRUE(scheduler->CommitPending()); |
809 EXPECT_TRUE(scheduler->RedrawPending()); | 838 EXPECT_TRUE(scheduler->RedrawPending()); |
810 EXPECT_TRUE(client.needs_begin_impl_frame()); | 839 EXPECT_TRUE(client.needs_begin_impl_frame()); |
811 | 840 |
812 // Fail the draw again. | 841 // Fail the draw again. |
813 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); | 842 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
814 scheduler->OnBeginImplFrameDeadline(); | 843 |
844 client.task_runner().RunPendingTasks(); // Run posted deadline. | |
815 EXPECT_EQ(2, client.num_draws()); | 845 EXPECT_EQ(2, client.num_draws()); |
816 EXPECT_TRUE(scheduler->CommitPending()); | 846 EXPECT_TRUE(scheduler->CommitPending()); |
817 EXPECT_TRUE(scheduler->RedrawPending()); | 847 EXPECT_TRUE(scheduler->RedrawPending()); |
818 EXPECT_TRUE(client.needs_begin_impl_frame()); | 848 EXPECT_TRUE(client.needs_begin_impl_frame()); |
819 | 849 |
820 // Draw successfully. | 850 // Draw successfully. |
821 client.SetDrawWillHappen(true); | 851 client.SetDrawWillHappen(true); |
822 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); | 852 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
823 scheduler->OnBeginImplFrameDeadline(); | 853 client.task_runner().RunPendingTasks(); // Run posted deadline. |
824 EXPECT_EQ(3, client.num_draws()); | 854 EXPECT_EQ(3, client.num_draws()); |
825 EXPECT_TRUE(scheduler->CommitPending()); | 855 EXPECT_TRUE(scheduler->CommitPending()); |
826 EXPECT_FALSE(scheduler->RedrawPending()); | 856 EXPECT_FALSE(scheduler->RedrawPending()); |
827 EXPECT_TRUE(client.needs_begin_impl_frame()); | 857 EXPECT_TRUE(client.needs_begin_impl_frame()); |
828 } | 858 } |
829 | 859 |
830 TEST(SchedulerTest, NoSwapWhenDrawFails) { | 860 TEST(SchedulerTest, NoSwapWhenDrawFails) { |
831 SchedulerClientThatSetNeedsCommitInsideDraw client; | 861 SchedulerClientThatSetNeedsCommitInsideDraw client; |
832 SchedulerSettings default_scheduler_settings; | 862 SchedulerSettings default_scheduler_settings; |
833 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings); | 863 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings); |
834 scheduler->SetCanStart(); | 864 scheduler->SetCanStart(); |
835 scheduler->SetVisible(true); | 865 scheduler->SetVisible(true); |
836 scheduler->SetCanDraw(true); | 866 scheduler->SetCanDraw(true); |
837 InitializeOutputSurfaceAndFirstCommit(scheduler); | 867 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
838 client.Reset(); | 868 client.Reset(); |
839 | 869 |
840 scheduler->SetNeedsRedraw(); | 870 scheduler->SetNeedsRedraw(); |
841 EXPECT_TRUE(scheduler->RedrawPending()); | 871 EXPECT_TRUE(scheduler->RedrawPending()); |
842 EXPECT_TRUE(client.needs_begin_impl_frame()); | 872 EXPECT_TRUE(client.needs_begin_impl_frame()); |
843 EXPECT_EQ(0, client.num_draws()); | 873 EXPECT_EQ(0, client.num_draws()); |
844 | 874 |
845 // Draw successfully, this starts a new frame. | 875 // Draw successfully, this starts a new frame. |
846 client.SetNeedsCommitOnNextDraw(); | 876 client.SetNeedsCommitOnNextDraw(); |
847 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); | 877 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
848 scheduler->OnBeginImplFrameDeadline(); | 878 client.task_runner().RunPendingTasks(); // Run posted deadline. |
849 EXPECT_EQ(1, client.num_draws()); | 879 EXPECT_EQ(1, client.num_draws()); |
850 | 880 |
851 scheduler->SetNeedsRedraw(); | 881 scheduler->SetNeedsRedraw(); |
852 EXPECT_TRUE(scheduler->RedrawPending()); | 882 EXPECT_TRUE(scheduler->RedrawPending()); |
853 EXPECT_TRUE(client.needs_begin_impl_frame()); | 883 EXPECT_TRUE(client.needs_begin_impl_frame()); |
854 | 884 |
855 // Fail to draw, this should not start a frame. | 885 // Fail to draw, this should not start a frame. |
856 client.SetDrawWillHappen(false); | 886 client.SetDrawWillHappen(false); |
857 client.SetNeedsCommitOnNextDraw(); | 887 client.SetNeedsCommitOnNextDraw(); |
858 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); | 888 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
859 scheduler->OnBeginImplFrameDeadline(); | 889 client.task_runner().RunPendingTasks(); // Run posted deadline. |
860 EXPECT_EQ(2, client.num_draws()); | 890 EXPECT_EQ(2, client.num_draws()); |
861 } | 891 } |
862 | 892 |
863 TEST(SchedulerTest, NoSwapWhenSwapFailsDuringForcedCommit) { | 893 TEST(SchedulerTest, NoSwapWhenSwapFailsDuringForcedCommit) { |
864 FakeSchedulerClient client; | 894 FakeSchedulerClient client; |
865 SchedulerSettings default_scheduler_settings; | 895 SchedulerSettings default_scheduler_settings; |
866 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings); | 896 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings); |
867 | 897 |
868 // Tell the client that it will fail to swap. | 898 // Tell the client that it will fail to swap. |
869 client.SetDrawWillHappen(true); | 899 client.SetDrawWillHappen(true); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
917 }; | 947 }; |
918 | 948 |
919 // Test manage tiles is independant of draws. | 949 // Test manage tiles is independant of draws. |
920 TEST(SchedulerTest, ManageTiles) { | 950 TEST(SchedulerTest, ManageTiles) { |
921 SchedulerClientNeedsManageTilesInDraw client; | 951 SchedulerClientNeedsManageTilesInDraw client; |
922 SchedulerSettings default_scheduler_settings; | 952 SchedulerSettings default_scheduler_settings; |
923 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings); | 953 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings); |
924 scheduler->SetCanStart(); | 954 scheduler->SetCanStart(); |
925 scheduler->SetVisible(true); | 955 scheduler->SetVisible(true); |
926 scheduler->SetCanDraw(true); | 956 scheduler->SetCanDraw(true); |
927 InitializeOutputSurfaceAndFirstCommit(scheduler); | 957 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
928 | 958 |
929 // Request both draw and manage tiles. ManageTiles shouldn't | 959 // Request both draw and manage tiles. ManageTiles shouldn't |
930 // be trigged until BeginImplFrame. | 960 // be trigged until BeginImplFrame. |
931 client.Reset(); | 961 client.Reset(); |
932 scheduler->SetNeedsManageTiles(); | 962 scheduler->SetNeedsManageTiles(); |
933 scheduler->SetNeedsRedraw(); | 963 scheduler->SetNeedsRedraw(); |
934 EXPECT_TRUE(scheduler->RedrawPending()); | 964 EXPECT_TRUE(scheduler->RedrawPending()); |
935 EXPECT_TRUE(scheduler->ManageTilesPending()); | 965 EXPECT_TRUE(scheduler->ManageTilesPending()); |
936 EXPECT_TRUE(client.needs_begin_impl_frame()); | 966 EXPECT_TRUE(client.needs_begin_impl_frame()); |
937 EXPECT_EQ(0, client.num_draws()); | 967 EXPECT_EQ(0, client.num_draws()); |
938 EXPECT_FALSE(client.HasAction("ScheduledActionManageTiles")); | 968 EXPECT_FALSE(client.HasAction("ScheduledActionManageTiles")); |
939 EXPECT_FALSE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); | 969 EXPECT_FALSE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); |
940 | 970 |
941 // We have no immediate actions to perform, so the BeginImplFrame should post | 971 // We have no immediate actions to perform, so the BeginImplFrame should post |
942 // the deadline task. | 972 // the deadline task. |
943 client.Reset(); | 973 client.Reset(); |
944 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); | 974 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
945 EXPECT_EQ(client.num_actions_(), 0); | 975 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); |
946 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 976 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
947 | 977 |
948 // On the deadline, he actions should have occured in the right order. | 978 // On the deadline, he actions should have occured in the right order. |
949 client.Reset(); | 979 client.Reset(); |
950 scheduler->OnBeginImplFrameDeadline(); | 980 client.task_runner().RunPendingTasks(); // Run posted deadline. |
951 EXPECT_EQ(1, client.num_draws()); | 981 EXPECT_EQ(1, client.num_draws()); |
952 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); | 982 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); |
953 EXPECT_TRUE(client.HasAction("ScheduledActionManageTiles")); | 983 EXPECT_TRUE(client.HasAction("ScheduledActionManageTiles")); |
954 EXPECT_LT(client.ActionIndex("ScheduledActionDrawAndSwapIfPossible"), | 984 EXPECT_LT(client.ActionIndex("ScheduledActionDrawAndSwapIfPossible"), |
955 client.ActionIndex("ScheduledActionManageTiles")); | 985 client.ActionIndex("ScheduledActionManageTiles")); |
956 EXPECT_FALSE(scheduler->RedrawPending()); | 986 EXPECT_FALSE(scheduler->RedrawPending()); |
957 EXPECT_FALSE(scheduler->ManageTilesPending()); | 987 EXPECT_FALSE(scheduler->ManageTilesPending()); |
958 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 988 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
959 | 989 |
960 // Request a draw. We don't need a ManageTiles yet. | 990 // Request a draw. We don't need a ManageTiles yet. |
961 client.Reset(); | 991 client.Reset(); |
962 scheduler->SetNeedsRedraw(); | 992 scheduler->SetNeedsRedraw(); |
963 EXPECT_TRUE(scheduler->RedrawPending()); | 993 EXPECT_TRUE(scheduler->RedrawPending()); |
964 EXPECT_FALSE(scheduler->ManageTilesPending()); | 994 EXPECT_FALSE(scheduler->ManageTilesPending()); |
965 EXPECT_TRUE(client.needs_begin_impl_frame()); | 995 EXPECT_TRUE(client.needs_begin_impl_frame()); |
966 EXPECT_EQ(0, client.num_draws()); | 996 EXPECT_EQ(0, client.num_draws()); |
967 | 997 |
968 // We have no immediate actions to perform, so the BeginImplFrame should post | 998 // We have no immediate actions to perform, so the BeginImplFrame should post |
969 // the deadline task. | 999 // the deadline task. |
970 client.Reset(); | 1000 client.Reset(); |
971 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); | 1001 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
972 EXPECT_EQ(client.num_actions_(), 0); | 1002 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); |
973 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1003 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
974 | 1004 |
975 // Draw. The draw will trigger SetNeedsManageTiles, and | 1005 // Draw. The draw will trigger SetNeedsManageTiles, and |
976 // then the ManageTiles action will be triggered after the Draw. | 1006 // then the ManageTiles action will be triggered after the Draw. |
977 // Afterwards, neither a draw nor ManageTiles are pending. | 1007 // Afterwards, neither a draw nor ManageTiles are pending. |
978 client.Reset(); | 1008 client.Reset(); |
979 scheduler->OnBeginImplFrameDeadline(); | 1009 client.task_runner().RunPendingTasks(); // Run posted deadline. |
980 EXPECT_EQ(1, client.num_draws()); | 1010 EXPECT_EQ(1, client.num_draws()); |
981 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); | 1011 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); |
982 EXPECT_TRUE(client.HasAction("ScheduledActionManageTiles")); | 1012 EXPECT_TRUE(client.HasAction("ScheduledActionManageTiles")); |
983 EXPECT_LT(client.ActionIndex("ScheduledActionDrawAndSwapIfPossible"), | 1013 EXPECT_LT(client.ActionIndex("ScheduledActionDrawAndSwapIfPossible"), |
984 client.ActionIndex("ScheduledActionManageTiles")); | 1014 client.ActionIndex("ScheduledActionManageTiles")); |
985 EXPECT_FALSE(scheduler->RedrawPending()); | 1015 EXPECT_FALSE(scheduler->RedrawPending()); |
986 EXPECT_FALSE(scheduler->ManageTilesPending()); | 1016 EXPECT_FALSE(scheduler->ManageTilesPending()); |
987 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 1017 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
988 | 1018 |
989 // We need a BeginImplFrame where we don't swap to go idle. | 1019 // We need a BeginImplFrame where we don't swap to go idle. |
990 client.Reset(); | 1020 client.Reset(); |
991 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); | 1021 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
992 EXPECT_EQ(client.num_actions_(), 0); | 1022 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); |
993 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1023 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
994 client.Reset(); | 1024 client.Reset(); |
995 scheduler->OnBeginImplFrameDeadline(); | 1025 client.task_runner().RunPendingTasks(); // Run posted deadline. |
996 EXPECT_SINGLE_ACTION("SetNeedsBeginImplFrame", client); | 1026 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); |
997 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 1027 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
998 EXPECT_EQ(0, client.num_draws()); | 1028 EXPECT_EQ(0, client.num_draws()); |
999 | 1029 |
1000 // Now trigger a ManageTiles outside of a draw. We will then need | 1030 // Now trigger a ManageTiles outside of a draw. We will then need |
1001 // a begin-frame for the ManageTiles, but we don't need a draw. | 1031 // a begin-frame for the ManageTiles, but we don't need a draw. |
1002 client.Reset(); | 1032 client.Reset(); |
1003 EXPECT_FALSE(client.needs_begin_impl_frame()); | 1033 EXPECT_FALSE(client.needs_begin_impl_frame()); |
1004 scheduler->SetNeedsManageTiles(); | 1034 scheduler->SetNeedsManageTiles(); |
1005 EXPECT_TRUE(client.needs_begin_impl_frame()); | 1035 EXPECT_TRUE(client.needs_begin_impl_frame()); |
1006 EXPECT_TRUE(scheduler->ManageTilesPending()); | 1036 EXPECT_TRUE(scheduler->ManageTilesPending()); |
1007 EXPECT_FALSE(scheduler->RedrawPending()); | 1037 EXPECT_FALSE(scheduler->RedrawPending()); |
1008 | 1038 |
1009 // BeginImplFrame. There will be no draw, only ManageTiles. | 1039 // BeginImplFrame. There will be no draw, only ManageTiles. |
1010 client.Reset(); | 1040 client.Reset(); |
1011 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); | 1041 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
1012 EXPECT_EQ(client.num_actions_(), 0); | 1042 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); |
1013 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1043 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
1014 client.Reset(); | 1044 client.Reset(); |
1015 scheduler->OnBeginImplFrameDeadline(); | 1045 client.task_runner().RunPendingTasks(); // Run posted deadline. |
1016 EXPECT_EQ(0, client.num_draws()); | 1046 EXPECT_EQ(0, client.num_draws()); |
1017 EXPECT_FALSE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); | 1047 EXPECT_FALSE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); |
1018 EXPECT_TRUE(client.HasAction("ScheduledActionManageTiles")); | 1048 EXPECT_TRUE(client.HasAction("ScheduledActionManageTiles")); |
1019 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 1049 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
1020 } | 1050 } |
1021 | 1051 |
1022 // Test that ManageTiles only happens once per frame. If an external caller | 1052 // Test that ManageTiles only happens once per frame. If an external caller |
1023 // initiates it, then the state machine should not ManageTiles on that frame. | 1053 // initiates it, then the state machine should not ManageTiles on that frame. |
1024 TEST(SchedulerTest, ManageTilesOncePerFrame) { | 1054 TEST(SchedulerTest, ManageTilesOncePerFrame) { |
1025 FakeSchedulerClient client; | 1055 FakeSchedulerClient client; |
1026 SchedulerSettings default_scheduler_settings; | 1056 SchedulerSettings default_scheduler_settings; |
1027 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings); | 1057 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings); |
1028 scheduler->SetCanStart(); | 1058 scheduler->SetCanStart(); |
1029 scheduler->SetVisible(true); | 1059 scheduler->SetVisible(true); |
1030 scheduler->SetCanDraw(true); | 1060 scheduler->SetCanDraw(true); |
1031 InitializeOutputSurfaceAndFirstCommit(scheduler); | 1061 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
1032 | 1062 |
1033 // If DidManageTiles during a frame, then ManageTiles should not occur again. | 1063 // If DidManageTiles during a frame, then ManageTiles should not occur again. |
1034 scheduler->SetNeedsManageTiles(); | 1064 scheduler->SetNeedsManageTiles(); |
1035 scheduler->SetNeedsRedraw(); | 1065 scheduler->SetNeedsRedraw(); |
1036 client.Reset(); | 1066 client.Reset(); |
1037 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); | 1067 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
1038 EXPECT_EQ(client.num_actions_(), 0); | 1068 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); |
1039 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1069 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
1040 | 1070 |
1041 EXPECT_TRUE(scheduler->ManageTilesPending()); | 1071 EXPECT_TRUE(scheduler->ManageTilesPending()); |
1042 scheduler->DidManageTiles(); // An explicit ManageTiles. | 1072 scheduler->DidManageTiles(); // An explicit ManageTiles. |
1043 EXPECT_FALSE(scheduler->ManageTilesPending()); | 1073 EXPECT_FALSE(scheduler->ManageTilesPending()); |
1044 | 1074 |
1045 client.Reset(); | 1075 client.Reset(); |
1046 scheduler->OnBeginImplFrameDeadline(); | 1076 client.task_runner().RunPendingTasks(); // Run posted deadline. |
1047 EXPECT_EQ(1, client.num_draws()); | 1077 EXPECT_EQ(1, client.num_draws()); |
1048 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); | 1078 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); |
1049 EXPECT_FALSE(client.HasAction("ScheduledActionManageTiles")); | 1079 EXPECT_FALSE(client.HasAction("ScheduledActionManageTiles")); |
1050 EXPECT_FALSE(scheduler->RedrawPending()); | 1080 EXPECT_FALSE(scheduler->RedrawPending()); |
1051 EXPECT_FALSE(scheduler->ManageTilesPending()); | 1081 EXPECT_FALSE(scheduler->ManageTilesPending()); |
1052 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 1082 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
1053 | 1083 |
1054 // Next frame without DidManageTiles should ManageTiles with draw. | 1084 // Next frame without DidManageTiles should ManageTiles with draw. |
1055 scheduler->SetNeedsManageTiles(); | 1085 scheduler->SetNeedsManageTiles(); |
1056 scheduler->SetNeedsRedraw(); | 1086 scheduler->SetNeedsRedraw(); |
1057 client.Reset(); | 1087 client.Reset(); |
1058 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); | 1088 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
1059 EXPECT_EQ(client.num_actions_(), 0); | 1089 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); |
1060 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1090 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
1061 | 1091 |
1062 client.Reset(); | 1092 client.Reset(); |
1063 scheduler->OnBeginImplFrameDeadline(); | 1093 client.task_runner().RunPendingTasks(); // Run posted deadline. |
1064 EXPECT_EQ(1, client.num_draws()); | 1094 EXPECT_EQ(1, client.num_draws()); |
1065 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); | 1095 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); |
1066 EXPECT_TRUE(client.HasAction("ScheduledActionManageTiles")); | 1096 EXPECT_TRUE(client.HasAction("ScheduledActionManageTiles")); |
1067 EXPECT_LT(client.ActionIndex("ScheduledActionDrawAndSwapIfPossible"), | 1097 EXPECT_LT(client.ActionIndex("ScheduledActionDrawAndSwapIfPossible"), |
1068 client.ActionIndex("ScheduledActionManageTiles")); | 1098 client.ActionIndex("ScheduledActionManageTiles")); |
1069 EXPECT_FALSE(scheduler->RedrawPending()); | 1099 EXPECT_FALSE(scheduler->RedrawPending()); |
1070 EXPECT_FALSE(scheduler->ManageTilesPending()); | 1100 EXPECT_FALSE(scheduler->ManageTilesPending()); |
1071 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 1101 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
1072 scheduler->DidManageTiles(); // Corresponds to ScheduledActionManageTiles | 1102 scheduler->DidManageTiles(); // Corresponds to ScheduledActionManageTiles |
1073 | 1103 |
1074 // If we get another DidManageTiles within the same frame, we should | 1104 // If we get another DidManageTiles within the same frame, we should |
1075 // not ManageTiles on the next frame. | 1105 // not ManageTiles on the next frame. |
1076 scheduler->DidManageTiles(); // An explicit ManageTiles. | 1106 scheduler->DidManageTiles(); // An explicit ManageTiles. |
1077 scheduler->SetNeedsManageTiles(); | 1107 scheduler->SetNeedsManageTiles(); |
1078 scheduler->SetNeedsRedraw(); | 1108 scheduler->SetNeedsRedraw(); |
1079 client.Reset(); | 1109 client.Reset(); |
1080 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); | 1110 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
1081 EXPECT_EQ(client.num_actions_(), 0); | 1111 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); |
1082 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1112 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
1083 | 1113 |
1084 EXPECT_TRUE(scheduler->ManageTilesPending()); | 1114 EXPECT_TRUE(scheduler->ManageTilesPending()); |
1085 | 1115 |
1086 client.Reset(); | 1116 client.Reset(); |
1087 scheduler->OnBeginImplFrameDeadline(); | 1117 client.task_runner().RunPendingTasks(); // Run posted deadline. |
1088 EXPECT_EQ(1, client.num_draws()); | 1118 EXPECT_EQ(1, client.num_draws()); |
1089 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); | 1119 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); |
1090 EXPECT_FALSE(client.HasAction("ScheduledActionManageTiles")); | 1120 EXPECT_FALSE(client.HasAction("ScheduledActionManageTiles")); |
1091 EXPECT_FALSE(scheduler->RedrawPending()); | 1121 EXPECT_FALSE(scheduler->RedrawPending()); |
1092 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 1122 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
1093 | 1123 |
1094 // If we get another DidManageTiles, we should not ManageTiles on the next | 1124 // If we get another DidManageTiles, we should not ManageTiles on the next |
1095 // frame. This verifies we don't alternate calling ManageTiles once and twice. | 1125 // frame. This verifies we don't alternate calling ManageTiles once and twice. |
1096 EXPECT_TRUE(scheduler->ManageTilesPending()); | 1126 EXPECT_TRUE(scheduler->ManageTilesPending()); |
1097 scheduler->DidManageTiles(); // An explicit ManageTiles. | 1127 scheduler->DidManageTiles(); // An explicit ManageTiles. |
1098 EXPECT_FALSE(scheduler->ManageTilesPending()); | 1128 EXPECT_FALSE(scheduler->ManageTilesPending()); |
1099 scheduler->SetNeedsManageTiles(); | 1129 scheduler->SetNeedsManageTiles(); |
1100 scheduler->SetNeedsRedraw(); | 1130 scheduler->SetNeedsRedraw(); |
1101 client.Reset(); | 1131 client.Reset(); |
1102 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); | 1132 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
1103 EXPECT_EQ(client.num_actions_(), 0); | 1133 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); |
1104 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1134 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
1105 | 1135 |
1106 EXPECT_TRUE(scheduler->ManageTilesPending()); | 1136 EXPECT_TRUE(scheduler->ManageTilesPending()); |
1107 | 1137 |
1108 client.Reset(); | 1138 client.Reset(); |
1109 scheduler->OnBeginImplFrameDeadline(); | 1139 client.task_runner().RunPendingTasks(); // Run posted deadline. |
1110 EXPECT_EQ(1, client.num_draws()); | 1140 EXPECT_EQ(1, client.num_draws()); |
1111 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); | 1141 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); |
1112 EXPECT_FALSE(client.HasAction("ScheduledActionManageTiles")); | 1142 EXPECT_FALSE(client.HasAction("ScheduledActionManageTiles")); |
1113 EXPECT_FALSE(scheduler->RedrawPending()); | 1143 EXPECT_FALSE(scheduler->RedrawPending()); |
1114 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 1144 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
1115 | 1145 |
1116 // Next frame without DidManageTiles should ManageTiles with draw. | 1146 // Next frame without DidManageTiles should ManageTiles with draw. |
1117 scheduler->SetNeedsManageTiles(); | 1147 scheduler->SetNeedsManageTiles(); |
1118 scheduler->SetNeedsRedraw(); | 1148 scheduler->SetNeedsRedraw(); |
1119 client.Reset(); | 1149 client.Reset(); |
1120 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); | 1150 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
1121 EXPECT_EQ(client.num_actions_(), 0); | 1151 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); |
1122 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1152 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
1123 | 1153 |
1124 client.Reset(); | 1154 client.Reset(); |
1125 scheduler->OnBeginImplFrameDeadline(); | 1155 client.task_runner().RunPendingTasks(); // Run posted deadline. |
1126 EXPECT_EQ(1, client.num_draws()); | 1156 EXPECT_EQ(1, client.num_draws()); |
1127 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); | 1157 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); |
1128 EXPECT_TRUE(client.HasAction("ScheduledActionManageTiles")); | 1158 EXPECT_TRUE(client.HasAction("ScheduledActionManageTiles")); |
1129 EXPECT_LT(client.ActionIndex("ScheduledActionDrawAndSwapIfPossible"), | 1159 EXPECT_LT(client.ActionIndex("ScheduledActionDrawAndSwapIfPossible"), |
1130 client.ActionIndex("ScheduledActionManageTiles")); | 1160 client.ActionIndex("ScheduledActionManageTiles")); |
1131 EXPECT_FALSE(scheduler->RedrawPending()); | 1161 EXPECT_FALSE(scheduler->RedrawPending()); |
1132 EXPECT_FALSE(scheduler->ManageTilesPending()); | 1162 EXPECT_FALSE(scheduler->ManageTilesPending()); |
1133 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 1163 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
1134 scheduler->DidManageTiles(); // Corresponds to ScheduledActionManageTiles | 1164 scheduler->DidManageTiles(); // Corresponds to ScheduledActionManageTiles |
1135 } | 1165 } |
1136 | 1166 |
1137 TEST(SchedulerTest, TriggerBeginFrameDeadlineEarly) { | 1167 TEST(SchedulerTest, TriggerBeginFrameDeadlineEarly) { |
1138 SchedulerClientNeedsManageTilesInDraw client; | 1168 SchedulerClientNeedsManageTilesInDraw client; |
1139 SchedulerSettings default_scheduler_settings; | 1169 SchedulerSettings default_scheduler_settings; |
1140 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings); | 1170 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings); |
1141 scheduler->SetCanStart(); | 1171 scheduler->SetCanStart(); |
1142 scheduler->SetVisible(true); | 1172 scheduler->SetVisible(true); |
1143 scheduler->SetCanDraw(true); | 1173 scheduler->SetCanDraw(true); |
1144 InitializeOutputSurfaceAndFirstCommit(scheduler); | 1174 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
1145 | 1175 |
1146 client.Reset(); | 1176 client.Reset(); |
1147 BeginFrameArgs impl_frame_args = BeginFrameArgs::CreateForTesting(); | |
1148 scheduler->SetNeedsRedraw(); | 1177 scheduler->SetNeedsRedraw(); |
1149 scheduler->BeginImplFrame(impl_frame_args); | 1178 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
1150 | 1179 |
1151 // The deadline should be zero since there is no work other than drawing | 1180 // The deadline should be zero since there is no work other than drawing |
1152 // pending. | 1181 // pending. |
1153 EXPECT_EQ(base::TimeTicks(), client.posted_begin_impl_frame_deadline()); | 1182 EXPECT_EQ(base::TimeTicks(), client.posted_begin_impl_frame_deadline()); |
1154 } | 1183 } |
1155 | 1184 |
1156 class SchedulerClientWithFixedEstimates : public FakeSchedulerClient { | 1185 class SchedulerClientWithFixedEstimates : public FakeSchedulerClient { |
1157 public: | 1186 public: |
1158 SchedulerClientWithFixedEstimates( | 1187 SchedulerClientWithFixedEstimates( |
1159 base::TimeDelta draw_duration, | 1188 base::TimeDelta draw_duration, |
(...skipping 29 matching lines...) Expand all Loading... | |
1189 base::TimeDelta::FromMilliseconds(1), | 1218 base::TimeDelta::FromMilliseconds(1), |
1190 base::TimeDelta::FromMilliseconds( | 1219 base::TimeDelta::FromMilliseconds( |
1191 begin_main_frame_to_commit_estimate_in_ms), | 1220 begin_main_frame_to_commit_estimate_in_ms), |
1192 base::TimeDelta::FromMilliseconds(commit_to_activate_estimate_in_ms)); | 1221 base::TimeDelta::FromMilliseconds(commit_to_activate_estimate_in_ms)); |
1193 SchedulerSettings default_scheduler_settings; | 1222 SchedulerSettings default_scheduler_settings; |
1194 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings); | 1223 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings); |
1195 scheduler->SetCanStart(); | 1224 scheduler->SetCanStart(); |
1196 scheduler->SetVisible(true); | 1225 scheduler->SetVisible(true); |
1197 scheduler->SetCanDraw(true); | 1226 scheduler->SetCanDraw(true); |
1198 scheduler->SetSmoothnessTakesPriority(smoothness_takes_priority); | 1227 scheduler->SetSmoothnessTakesPriority(smoothness_takes_priority); |
1199 InitializeOutputSurfaceAndFirstCommit(scheduler); | 1228 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
1200 | 1229 |
1201 // Impl thread hits deadline before commit finishes. | 1230 // Impl thread hits deadline before commit finishes. |
1202 client.Reset(); | 1231 client.Reset(); |
1203 scheduler->SetNeedsCommit(); | 1232 scheduler->SetNeedsCommit(); |
1204 EXPECT_FALSE(scheduler->MainThreadIsInHighLatencyMode()); | 1233 EXPECT_FALSE(scheduler->MainThreadIsInHighLatencyMode()); |
1205 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); | 1234 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
1206 EXPECT_FALSE(scheduler->MainThreadIsInHighLatencyMode()); | 1235 EXPECT_FALSE(scheduler->MainThreadIsInHighLatencyMode()); |
1207 scheduler->OnBeginImplFrameDeadline(); | 1236 client.task_runner().RunPendingTasks(); // Run posted deadline. |
1208 EXPECT_TRUE(scheduler->MainThreadIsInHighLatencyMode()); | 1237 EXPECT_TRUE(scheduler->MainThreadIsInHighLatencyMode()); |
1209 scheduler->NotifyBeginMainFrameStarted(); | 1238 scheduler->NotifyBeginMainFrameStarted(); |
1210 scheduler->NotifyReadyToCommit(); | 1239 scheduler->NotifyReadyToCommit(); |
1211 EXPECT_TRUE(scheduler->MainThreadIsInHighLatencyMode()); | 1240 EXPECT_TRUE(scheduler->MainThreadIsInHighLatencyMode()); |
1212 EXPECT_TRUE(client.HasAction("ScheduledActionSendBeginMainFrame")); | 1241 EXPECT_TRUE(client.HasAction("ScheduledActionSendBeginMainFrame")); |
1213 | 1242 |
1214 client.Reset(); | 1243 client.Reset(); |
1215 scheduler->SetNeedsCommit(); | 1244 scheduler->SetNeedsCommit(); |
1216 EXPECT_TRUE(scheduler->MainThreadIsInHighLatencyMode()); | 1245 EXPECT_TRUE(scheduler->MainThreadIsInHighLatencyMode()); |
1217 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); | 1246 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
1218 EXPECT_TRUE(scheduler->MainThreadIsInHighLatencyMode()); | 1247 EXPECT_TRUE(scheduler->MainThreadIsInHighLatencyMode()); |
1219 scheduler->OnBeginImplFrameDeadline(); | 1248 client.task_runner().RunPendingTasks(); // Run posted deadline. |
1220 EXPECT_EQ(scheduler->MainThreadIsInHighLatencyMode(), | 1249 EXPECT_EQ(scheduler->MainThreadIsInHighLatencyMode(), |
1221 should_send_begin_main_frame); | 1250 should_send_begin_main_frame); |
1222 EXPECT_EQ(client.HasAction("ScheduledActionSendBeginMainFrame"), | 1251 EXPECT_EQ(client.HasAction("ScheduledActionSendBeginMainFrame"), |
1223 should_send_begin_main_frame); | 1252 should_send_begin_main_frame); |
1224 } | 1253 } |
1225 | 1254 |
1226 TEST(SchedulerTest, | 1255 TEST(SchedulerTest, |
1227 SkipMainFrameIfHighLatencyAndCanCommitAndActivateBeforeDeadline) { | 1256 SkipMainFrameIfHighLatencyAndCanCommitAndActivateBeforeDeadline) { |
1228 // Set up client so that estimates indicate that we can commit and activate | 1257 // Set up client so that estimates indicate that we can commit and activate |
1229 // before the deadline (~8ms by default). | 1258 // before the deadline (~8ms by default). |
(...skipping 12 matching lines...) Expand all Loading... | |
1242 MainFrameInHighLatencyMode(1, 10, false, true); | 1271 MainFrameInHighLatencyMode(1, 10, false, true); |
1243 } | 1272 } |
1244 | 1273 |
1245 TEST(SchedulerTest, NotSkipMainFrameInPreferSmoothnessMode) { | 1274 TEST(SchedulerTest, NotSkipMainFrameInPreferSmoothnessMode) { |
1246 // Set up client so that estimates indicate that we can commit and activate | 1275 // Set up client so that estimates indicate that we can commit and activate |
1247 // before the deadline (~8ms by default), but also enable smoothness takes | 1276 // before the deadline (~8ms by default), but also enable smoothness takes |
1248 // priority mode. | 1277 // priority mode. |
1249 MainFrameInHighLatencyMode(1, 1, true, true); | 1278 MainFrameInHighLatencyMode(1, 1, true, true); |
1250 } | 1279 } |
1251 | 1280 |
1252 void SpinForMillis(int millis) { | |
1253 base::RunLoop run_loop; | |
1254 base::MessageLoop::current()->PostDelayedTask( | |
1255 FROM_HERE, | |
1256 run_loop.QuitClosure(), | |
1257 base::TimeDelta::FromMilliseconds(millis)); | |
1258 run_loop.Run(); | |
1259 } | |
1260 | |
1261 TEST(SchedulerTest, PollForCommitCompletion) { | 1281 TEST(SchedulerTest, PollForCommitCompletion) { |
1262 // Since we are simulating a long commit, set up a client with draw duration | 1282 // Since we are simulating a long commit, set up a client with draw duration |
1263 // estimates that prevent skipping main frames to get to low latency mode. | 1283 // estimates that prevent skipping main frames to get to low latency mode. |
1264 SchedulerClientWithFixedEstimates client( | 1284 SchedulerClientWithFixedEstimates client( |
1265 base::TimeDelta::FromMilliseconds(1), | 1285 base::TimeDelta::FromMilliseconds(1), |
1266 base::TimeDelta::FromMilliseconds(32), | 1286 base::TimeDelta::FromMilliseconds(32), |
1267 base::TimeDelta::FromMilliseconds(32)); | 1287 base::TimeDelta::FromMilliseconds(32)); |
1268 client.set_log_anticipated_draw_time_change(true); | 1288 client.set_log_anticipated_draw_time_change(true); |
1269 SchedulerSettings settings = SchedulerSettings(); | 1289 SchedulerSettings settings = SchedulerSettings(); |
1270 settings.throttle_frame_production = false; | 1290 settings.throttle_frame_production = false; |
1271 Scheduler* scheduler = client.CreateScheduler(settings); | 1291 Scheduler* scheduler = client.CreateScheduler(settings); |
1272 | 1292 |
1273 scheduler->SetCanDraw(true); | 1293 scheduler->SetCanDraw(true); |
1274 scheduler->SetCanStart(); | 1294 scheduler->SetCanStart(); |
1275 scheduler->SetVisible(true); | 1295 scheduler->SetVisible(true); |
1276 scheduler->DidCreateAndInitializeOutputSurface(); | 1296 scheduler->DidCreateAndInitializeOutputSurface(); |
1277 | 1297 |
1278 scheduler->SetNeedsCommit(); | 1298 scheduler->SetNeedsCommit(); |
1279 EXPECT_TRUE(scheduler->CommitPending()); | 1299 EXPECT_TRUE(scheduler->CommitPending()); |
1280 scheduler->NotifyBeginMainFrameStarted(); | 1300 scheduler->NotifyBeginMainFrameStarted(); |
1281 scheduler->NotifyReadyToCommit(); | 1301 scheduler->NotifyReadyToCommit(); |
1282 scheduler->SetNeedsRedraw(); | 1302 scheduler->SetNeedsRedraw(); |
1283 BeginFrameArgs impl_frame_args = BeginFrameArgs::CreateForTesting(); | 1303 BeginFrameArgs frame_args = BeginFrameArgs::CreateForTesting(); |
1284 const int interval = 1; | 1304 const int interval = 1000; |
1285 impl_frame_args.interval = base::TimeDelta::FromMilliseconds(interval); | 1305 frame_args.interval = base::TimeDelta::FromMilliseconds(interval); |
1286 scheduler->BeginImplFrame(impl_frame_args); | 1306 scheduler->BeginFrame(frame_args); |
1287 scheduler->OnBeginImplFrameDeadline(); | 1307 |
1308 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | |
1309 client.task_runner().RunPendingTasks(); // Run posted deadline. | |
1310 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | |
1288 | 1311 |
1289 // At this point, we've drawn a frame. Start another commit, but hold off on | 1312 // At this point, we've drawn a frame. Start another commit, but hold off on |
1290 // the NotifyReadyToCommit for now. | 1313 // the NotifyReadyToCommit for now. |
1291 EXPECT_FALSE(scheduler->CommitPending()); | 1314 EXPECT_FALSE(scheduler->CommitPending()); |
1292 scheduler->SetNeedsCommit(); | 1315 scheduler->SetNeedsCommit(); |
1293 EXPECT_TRUE(scheduler->CommitPending()); | 1316 EXPECT_TRUE(scheduler->CommitPending()); |
1294 | 1317 |
1295 // Spin the event loop a few times and make sure we get more | 1318 // Spin the event loop a few times and make sure we get more |
1296 // DidAnticipateDrawTimeChange calls every time. | 1319 // DidAnticipateDrawTimeChange calls every time. |
1297 int actions_so_far = client.num_actions_(); | 1320 int actions_so_far = client.num_actions_(); |
1298 | 1321 |
1299 // Does three iterations to make sure that the timer is properly repeating. | 1322 // Does three iterations to make sure that the timer is properly repeating. |
1300 for (int i = 0; i < 3; ++i) { | 1323 for (int i = 0; i < 3; ++i) { |
1301 // Wait for 2x the frame interval to match | 1324 EXPECT_GT(client.task_runner().NextPendingTaskDelay(), base::TimeDelta()); |
1302 // Scheduler::advance_commit_state_timer_'s rate. | 1325 EXPECT_LT(client.task_runner().NextPendingTaskDelay(), |
1303 SpinForMillis(interval * 2); | 1326 frame_args.interval * 2); |
1327 client.task_runner().RunPendingTasks(); | |
1304 EXPECT_GT(client.num_actions_(), actions_so_far); | 1328 EXPECT_GT(client.num_actions_(), actions_so_far); |
1305 EXPECT_STREQ(client.Action(client.num_actions_() - 1), | 1329 EXPECT_STREQ(client.Action(client.num_actions_() - 1), |
1306 "DidAnticipatedDrawTimeChange"); | 1330 "DidAnticipatedDrawTimeChange"); |
1307 actions_so_far = client.num_actions_(); | 1331 actions_so_far = client.num_actions_(); |
1308 } | 1332 } |
1309 } | 1333 } |
1310 | 1334 |
1335 TEST(SchedulerTest, BeginRetroFrame) { | |
1336 FakeSchedulerClient client; | |
1337 SchedulerSettings scheduler_settings; | |
1338 Scheduler* scheduler = client.CreateScheduler(scheduler_settings); | |
1339 scheduler->SetCanStart(); | |
1340 scheduler->SetVisible(true); | |
1341 scheduler->SetCanDraw(true); | |
1342 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | |
1343 | |
1344 // SetNeedsCommit should begin the frame on the next BeginImplFrame. | |
1345 client.Reset(); | |
1346 scheduler->SetNeedsCommit(); | |
1347 EXPECT_TRUE(client.needs_begin_impl_frame()); | |
1348 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); | |
1349 client.Reset(); | |
1350 | |
1351 // Create a BeginFrame with a long deadline to avoid race conditions. | |
1352 // This is the first BeginFrame, which will be handled immediately. | |
1353 BeginFrameArgs args = BeginFrameArgs::CreateForTesting(); | |
1354 args.deadline += base::TimeDelta::FromHours(1); | |
1355 scheduler->BeginFrame(args); | |
1356 | |
1357 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | |
1358 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); | |
1359 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | |
1360 EXPECT_TRUE(client.needs_begin_impl_frame()); | |
1361 client.Reset(); | |
1362 | |
1363 // Queue BeginFrames while we are still handling the previous BeginFrame. | |
1364 args.frame_time += base::TimeDelta::FromSeconds(1); | |
1365 scheduler->BeginFrame(args); | |
1366 args.frame_time += base::TimeDelta::FromSeconds(1); | |
1367 scheduler->BeginFrame(args); | |
1368 | |
1369 // If we don't swap on the deadline, we need to request another | |
1370 // BeginImplFrame. | |
1371 client.task_runner().RunPendingTasks(); // Run posted deadline. | |
1372 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); | |
1373 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | |
1374 EXPECT_TRUE(client.needs_begin_impl_frame()); | |
1375 client.Reset(); | |
1376 | |
1377 // NotifyReadyToCommit should trigger the commit. | |
1378 scheduler->NotifyBeginMainFrameStarted(); | |
1379 scheduler->NotifyReadyToCommit(); | |
1380 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); | |
1381 EXPECT_TRUE(client.needs_begin_impl_frame()); | |
1382 client.Reset(); | |
1383 | |
1384 // BeginImplFrame should prepare the draw. | |
1385 client.task_runner().RunPendingTasks(); // Run posted BeginRetroFrame. | |
1386 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); | |
1387 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | |
1388 EXPECT_TRUE(client.needs_begin_impl_frame()); | |
1389 client.Reset(); | |
1390 | |
1391 // BeginImplFrame deadline should draw. | |
1392 client.task_runner().RunPendingTasks(); // Run posted deadline. | |
1393 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 2); | |
1394 EXPECT_ACTION("SetNeedsBeginFrame", client, 1, 2); | |
1395 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | |
1396 EXPECT_TRUE(client.needs_begin_impl_frame()); | |
1397 client.Reset(); | |
1398 | |
1399 // The following BeginImplFrame deadline should SetNeedsBeginFrame(false) | |
1400 // to avoid excessive toggles. | |
1401 client.task_runner().RunPendingTasks(); // Run posted BeginRetroFrame. | |
1402 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); | |
1403 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | |
1404 client.Reset(); | |
1405 | |
1406 client.task_runner().RunPendingTasks(); // Run posted deadline. | |
1407 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); | |
1408 EXPECT_FALSE(client.needs_begin_impl_frame()); | |
1409 client.Reset(); | |
1410 } | |
1411 | |
1311 } // namespace | 1412 } // namespace |
1312 } // namespace cc | 1413 } // namespace cc |
OLD | NEW |