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

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

Issue 221833009: cc: Move scheduling logic out of OutputSurface (Closed) Base URL: http://git.chromium.org/chromium/src.git@swapAck2Sched11
Patch Set: rebase; add comment about race Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « cc/scheduler/scheduler_state_machine.cc ('k') | cc/test/fake_layer_tree_host_impl_client.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2011 The Chromium Authors. All rights reserved. 1 // Copyright 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 #include "cc/scheduler/scheduler.h" 4 #include "cc/scheduler/scheduler.h"
5 5
6 #include <string> 6 #include <string>
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/memory/scoped_vector.h" 10 #include "base/memory/scoped_vector.h"
(...skipping 21 matching lines...) Expand all
32 namespace cc { 32 namespace cc {
33 namespace { 33 namespace {
34 34
35 class FakeSchedulerClient; 35 class FakeSchedulerClient;
36 36
37 void InitializeOutputSurfaceAndFirstCommit(Scheduler* scheduler, 37 void InitializeOutputSurfaceAndFirstCommit(Scheduler* scheduler,
38 FakeSchedulerClient* client); 38 FakeSchedulerClient* client);
39 39
40 class FakeSchedulerClient : public SchedulerClient { 40 class FakeSchedulerClient : public SchedulerClient {
41 public: 41 public:
42 FakeSchedulerClient() 42 FakeSchedulerClient() : needs_begin_frame_(false), automatic_swap_ack_(true) {
43 : needs_begin_impl_frame_(false), automatic_swap_ack_(true) {
44 Reset(); 43 Reset();
45 } 44 }
46 45
47 void Reset() { 46 void Reset() {
48 actions_.clear(); 47 actions_.clear();
49 states_.clear(); 48 states_.clear();
50 draw_will_happen_ = true; 49 draw_will_happen_ = true;
51 swap_will_happen_if_draw_happens_ = true; 50 swap_will_happen_if_draw_happens_ = true;
52 num_draws_ = 0; 51 num_draws_ = 0;
53 log_anticipated_draw_time_change_ = false; 52 log_anticipated_draw_time_change_ = false;
54 } 53 }
55 54
56 Scheduler* CreateScheduler(const SchedulerSettings& settings) { 55 Scheduler* CreateScheduler(const SchedulerSettings& settings) {
57 task_runner_ = new base::TestSimpleTaskRunner; 56 task_runner_ = new base::TestSimpleTaskRunner;
58 scheduler_ = Scheduler::Create(this, settings, 0, task_runner_); 57 scheduler_ = Scheduler::Create(this, settings, 0, task_runner_);
59 return scheduler_.get(); 58 return scheduler_.get();
60 } 59 }
61 60
62 // Most tests don't care about DidAnticipatedDrawTimeChange, so only record it 61 // Most tests don't care about DidAnticipatedDrawTimeChange, so only record it
63 // for tests that do. 62 // for tests that do.
64 void set_log_anticipated_draw_time_change(bool log) { 63 void set_log_anticipated_draw_time_change(bool log) {
65 log_anticipated_draw_time_change_ = log; 64 log_anticipated_draw_time_change_ = log;
66 } 65 }
67 bool needs_begin_impl_frame() { return needs_begin_impl_frame_; } 66 bool needs_begin_frame() { return needs_begin_frame_; }
68 int num_draws() const { return num_draws_; } 67 int num_draws() const { return num_draws_; }
69 int num_actions_() const { return static_cast<int>(actions_.size()); } 68 int num_actions_() const { return static_cast<int>(actions_.size()); }
70 const char* Action(int i) const { return actions_[i]; } 69 const char* Action(int i) const { return actions_[i]; }
71 base::Value& StateForAction(int i) const { return *states_[i]; } 70 base::Value& StateForAction(int i) const { return *states_[i]; }
72 base::TimeTicks posted_begin_impl_frame_deadline() const { 71 base::TimeTicks posted_begin_impl_frame_deadline() const {
73 return posted_begin_impl_frame_deadline_; 72 return posted_begin_impl_frame_deadline_;
74 } 73 }
75 74
76 base::TestSimpleTaskRunner& task_runner() { return *task_runner_; } 75 base::TestSimpleTaskRunner& task_runner() { return *task_runner_; }
77 76
(...skipping 15 matching lines...) Expand all
93 swap_will_happen_if_draw_happens_ = swap_will_happen_if_draw_happens; 92 swap_will_happen_if_draw_happens_ = swap_will_happen_if_draw_happens;
94 } 93 }
95 void SetAutomaticSwapAck(bool automatic_swap_ack) { 94 void SetAutomaticSwapAck(bool automatic_swap_ack) {
96 automatic_swap_ack_ = automatic_swap_ack; 95 automatic_swap_ack_ = automatic_swap_ack;
97 } 96 }
98 97
99 // SchedulerClient implementation. 98 // SchedulerClient implementation.
100 virtual void SetNeedsBeginFrame(bool enable) OVERRIDE { 99 virtual void SetNeedsBeginFrame(bool enable) OVERRIDE {
101 actions_.push_back("SetNeedsBeginFrame"); 100 actions_.push_back("SetNeedsBeginFrame");
102 states_.push_back(scheduler_->StateAsValue().release()); 101 states_.push_back(scheduler_->StateAsValue().release());
103 needs_begin_impl_frame_ = enable; 102 needs_begin_frame_ = enable;
104 } 103 }
105 virtual void WillBeginImplFrame(const BeginFrameArgs& args) OVERRIDE { 104 virtual void WillBeginImplFrame(const BeginFrameArgs& args) OVERRIDE {
106 actions_.push_back("WillBeginImplFrame"); 105 actions_.push_back("WillBeginImplFrame");
107 states_.push_back(scheduler_->StateAsValue().release()); 106 states_.push_back(scheduler_->StateAsValue().release());
108 } 107 }
109 virtual void ScheduledActionSendBeginMainFrame() OVERRIDE { 108 virtual void ScheduledActionSendBeginMainFrame() OVERRIDE {
110 actions_.push_back("ScheduledActionSendBeginMainFrame"); 109 actions_.push_back("ScheduledActionSendBeginMainFrame");
111 states_.push_back(scheduler_->StateAsValue().release()); 110 states_.push_back(scheduler_->StateAsValue().release());
112 } 111 }
113 virtual DrawSwapReadbackResult ScheduledActionDrawAndSwapIfPossible() 112 virtual DrawSwapReadbackResult ScheduledActionDrawAndSwapIfPossible()
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 virtual base::TimeDelta BeginMainFrameToCommitDurationEstimate() OVERRIDE { 177 virtual base::TimeDelta BeginMainFrameToCommitDurationEstimate() OVERRIDE {
179 return base::TimeDelta(); 178 return base::TimeDelta();
180 } 179 }
181 virtual base::TimeDelta CommitToActivateDurationEstimate() OVERRIDE { 180 virtual base::TimeDelta CommitToActivateDurationEstimate() OVERRIDE {
182 return base::TimeDelta(); 181 return base::TimeDelta();
183 } 182 }
184 183
185 virtual void DidBeginImplFrameDeadline() OVERRIDE {} 184 virtual void DidBeginImplFrameDeadline() OVERRIDE {}
186 185
187 protected: 186 protected:
188 bool needs_begin_impl_frame_; 187 bool needs_begin_frame_;
189 bool draw_will_happen_; 188 bool draw_will_happen_;
190 bool swap_will_happen_if_draw_happens_; 189 bool swap_will_happen_if_draw_happens_;
191 bool automatic_swap_ack_; 190 bool automatic_swap_ack_;
192 int num_draws_; 191 int num_draws_;
193 bool log_anticipated_draw_time_change_; 192 bool log_anticipated_draw_time_change_;
194 base::TimeTicks posted_begin_impl_frame_deadline_; 193 base::TimeTicks posted_begin_impl_frame_deadline_;
195 std::vector<const char*> actions_; 194 std::vector<const char*> actions_;
196 ScopedVector<base::Value> states_; 195 ScopedVector<base::Value> states_;
197 scoped_ptr<Scheduler> scheduler_; 196 scoped_ptr<Scheduler> scheduler_;
198 scoped_refptr<base::TestSimpleTaskRunner> task_runner_; 197 scoped_refptr<base::TestSimpleTaskRunner> task_runner_;
199 }; 198 };
200 199
201 void InitializeOutputSurfaceAndFirstCommit(Scheduler* scheduler, 200 void InitializeOutputSurfaceAndFirstCommit(Scheduler* scheduler,
202 FakeSchedulerClient* client) { 201 FakeSchedulerClient* client) {
202 bool client_initiates_begin_frame =
203 scheduler->settings().begin_frame_scheduling_enabled &&
204 scheduler->settings().throttle_frame_production;
205
203 scheduler->DidCreateAndInitializeOutputSurface(); 206 scheduler->DidCreateAndInitializeOutputSurface();
204 scheduler->SetNeedsCommit(); 207 scheduler->SetNeedsCommit();
205 scheduler->NotifyBeginMainFrameStarted(); 208 scheduler->NotifyBeginMainFrameStarted();
206 scheduler->NotifyReadyToCommit(); 209 scheduler->NotifyReadyToCommit();
207 // Go through the motions to draw the commit. 210 // Go through the motions to draw the commit.
208 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); 211 if (client_initiates_begin_frame)
212 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting());
213 else
214 client->task_runner().RunPendingTasks(); // Run posted BeginFrame.
209 215
210 // Run the posted deadline task. 216 // Run the posted deadline task.
211 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 217 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending());
212 client->task_runner().RunPendingTasks(); 218 client->task_runner().RunPendingTasks();
213 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); 219 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending());
214 220
215 // We need another BeginImplFrame so Scheduler calls 221 // We need another BeginImplFrame so Scheduler calls
216 // SetNeedsBeginFrame(false). 222 // SetNeedsBeginFrame(false).
217 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); 223 if (client_initiates_begin_frame)
224 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting());
225 else
226 client->task_runner().RunPendingTasks(); // Run posted BeginFrame.
218 227
219 // Run the posted deadline task. 228 // Run the posted deadline task.
220 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 229 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending());
221 client->task_runner().RunPendingTasks(); 230 client->task_runner().RunPendingTasks();
222 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); 231 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending());
223 } 232 }
224 233
225 TEST(SchedulerTest, InitializeOutputSurfaceDoesNotBeginImplFrame) { 234 TEST(SchedulerTest, InitializeOutputSurfaceDoesNotBeginImplFrame) {
226 FakeSchedulerClient client; 235 FakeSchedulerClient client;
227 SchedulerSettings default_scheduler_settings; 236 SchedulerSettings default_scheduler_settings;
(...skipping 15 matching lines...) Expand all
243 scheduler->SetCanStart(); 252 scheduler->SetCanStart();
244 scheduler->SetVisible(true); 253 scheduler->SetVisible(true);
245 scheduler->SetCanDraw(true); 254 scheduler->SetCanDraw(true);
246 255
247 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); 256 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client);
248 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); 257 InitializeOutputSurfaceAndFirstCommit(scheduler, &client);
249 258
250 // SetNeedsCommit should begin the frame on the next BeginImplFrame. 259 // SetNeedsCommit should begin the frame on the next BeginImplFrame.
251 client.Reset(); 260 client.Reset();
252 scheduler->SetNeedsCommit(); 261 scheduler->SetNeedsCommit();
253 EXPECT_TRUE(client.needs_begin_impl_frame()); 262 EXPECT_TRUE(client.needs_begin_frame());
254 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); 263 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client);
255 client.Reset(); 264 client.Reset();
256 265
257 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); 266 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting());
258 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); 267 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2);
259 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); 268 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2);
260 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 269 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending());
261 EXPECT_TRUE(client.needs_begin_impl_frame()); 270 EXPECT_TRUE(client.needs_begin_frame());
262 client.Reset(); 271 client.Reset();
263 272
264 // If we don't swap on the deadline, we need to request another 273 // If we don't swap on the deadline, we wait for the next BeginFrame.
265 // BeginImplFrame.
266 client.task_runner().RunPendingTasks(); // Run posted deadline. 274 client.task_runner().RunPendingTasks(); // Run posted deadline.
267 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); 275 EXPECT_EQ(0, client.num_actions_());
268 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); 276 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending());
269 EXPECT_TRUE(client.needs_begin_impl_frame()); 277 EXPECT_TRUE(client.needs_begin_frame());
270 client.Reset(); 278 client.Reset();
271 279
272 // NotifyReadyToCommit should trigger the commit. 280 // NotifyReadyToCommit should trigger the commit.
273 scheduler->NotifyBeginMainFrameStarted(); 281 scheduler->NotifyBeginMainFrameStarted();
274 scheduler->NotifyReadyToCommit(); 282 scheduler->NotifyReadyToCommit();
275 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); 283 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client);
276 EXPECT_TRUE(client.needs_begin_impl_frame()); 284 EXPECT_TRUE(client.needs_begin_frame());
277 client.Reset(); 285 client.Reset();
278 286
279 // BeginImplFrame should prepare the draw. 287 // BeginImplFrame should prepare the draw.
280 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); 288 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting());
281 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); 289 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client);
282 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 290 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending());
283 EXPECT_TRUE(client.needs_begin_impl_frame()); 291 EXPECT_TRUE(client.needs_begin_frame());
284 client.Reset(); 292 client.Reset();
285 293
286 // BeginImplFrame deadline should draw. 294 // BeginImplFrame deadline should draw.
287 client.task_runner().RunPendingTasks(); // Run posted deadline. 295 client.task_runner().RunPendingTasks(); // Run posted deadline.
288 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 2); 296 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 1);
289 EXPECT_ACTION("SetNeedsBeginFrame", client, 1, 2);
290 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); 297 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending());
291 EXPECT_TRUE(client.needs_begin_impl_frame()); 298 EXPECT_TRUE(client.needs_begin_frame());
292 client.Reset(); 299 client.Reset();
293 300
294 // The following BeginImplFrame deadline should SetNeedsBeginFrame(false) 301 // The following BeginImplFrame deadline should SetNeedsBeginFrame(false)
295 // to avoid excessive toggles. 302 // to avoid excessive toggles.
296 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); 303 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting());
297 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); 304 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client);
298 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 305 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending());
299 client.Reset(); 306 client.Reset();
300 307
301 client.task_runner().RunPendingTasks(); // Run posted deadline. 308 client.task_runner().RunPendingTasks(); // Run posted deadline.
302 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); 309 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client);
303 EXPECT_FALSE(client.needs_begin_impl_frame()); 310 EXPECT_FALSE(client.needs_begin_frame());
304 client.Reset(); 311 client.Reset();
305 } 312 }
306 313
307 TEST(SchedulerTest, RequestCommitAfterBeginMainFrameSent) { 314 TEST(SchedulerTest, RequestCommitAfterBeginMainFrameSent) {
308 FakeSchedulerClient client; 315 FakeSchedulerClient client;
309 SchedulerSettings scheduler_settings; 316 SchedulerSettings scheduler_settings;
310 Scheduler* scheduler = client.CreateScheduler(scheduler_settings); 317 Scheduler* scheduler = client.CreateScheduler(scheduler_settings);
311 scheduler->SetCanStart(); 318 scheduler->SetCanStart();
312 scheduler->SetVisible(true); 319 scheduler->SetVisible(true);
313 scheduler->SetCanDraw(true); 320 scheduler->SetCanDraw(true);
314 321
315 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); 322 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client);
316 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); 323 InitializeOutputSurfaceAndFirstCommit(scheduler, &client);
317 client.Reset(); 324 client.Reset();
318 325
319 // SetNeedsCommit should begin the frame. 326 // SetNeedsCommit should begin the frame.
320 scheduler->SetNeedsCommit(); 327 scheduler->SetNeedsCommit();
321 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); 328 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client);
322 329
323 client.Reset(); 330 client.Reset();
324 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); 331 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting());
325 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); 332 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2);
326 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); 333 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2);
327 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 334 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending());
328 335
329 EXPECT_TRUE(client.needs_begin_impl_frame()); 336 EXPECT_TRUE(client.needs_begin_frame());
330 client.Reset(); 337 client.Reset();
331 338
332 // Now SetNeedsCommit again. Calling here means we need a second commit. 339 // Now SetNeedsCommit again. Calling here means we need a second commit.
333 scheduler->SetNeedsCommit(); 340 scheduler->SetNeedsCommit();
334 EXPECT_EQ(client.num_actions_(), 0); 341 EXPECT_EQ(client.num_actions_(), 0);
335 client.Reset(); 342 client.Reset();
336 343
337 // Finish the first commit. 344 // Finish the first commit.
338 scheduler->NotifyBeginMainFrameStarted(); 345 scheduler->NotifyBeginMainFrameStarted();
339 scheduler->NotifyReadyToCommit(); 346 scheduler->NotifyReadyToCommit();
340 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); 347 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client);
341 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 348 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending());
342 client.Reset(); 349 client.Reset();
343 client.task_runner().RunPendingTasks(); // Run posted deadline. 350 client.task_runner().RunPendingTasks(); // Run posted deadline.
344 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 2); 351 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 1);
345 EXPECT_ACTION("SetNeedsBeginFrame", client, 1, 2);
346 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); 352 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending());
347 353
348 // Because we just swapped, the Scheduler should also request the next 354 // Because we just swapped, the Scheduler should also request the next
349 // BeginImplFrame from the OutputSurface. 355 // BeginImplFrame from the OutputSurface.
350 EXPECT_TRUE(client.needs_begin_impl_frame()); 356 EXPECT_TRUE(client.needs_begin_frame());
351 client.Reset(); 357 client.Reset();
352 // Since another commit is needed, the next BeginImplFrame should initiate 358 // Since another commit is needed, the next BeginImplFrame should initiate
353 // the second commit. 359 // the second commit.
354 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); 360 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting());
355 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); 361 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2);
356 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); 362 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2);
357 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 363 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending());
358 client.Reset(); 364 client.Reset();
359 365
360 // Finishing the commit before the deadline should post a new deadline task 366 // Finishing the commit before the deadline should post a new deadline task
361 // to trigger the deadline early. 367 // to trigger the deadline early.
362 scheduler->NotifyBeginMainFrameStarted(); 368 scheduler->NotifyBeginMainFrameStarted();
363 scheduler->NotifyReadyToCommit(); 369 scheduler->NotifyReadyToCommit();
364 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); 370 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client);
365 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 371 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending());
366 client.Reset(); 372 client.Reset();
367 client.task_runner().RunPendingTasks(); // Run posted deadline. 373 client.task_runner().RunPendingTasks(); // Run posted deadline.
368 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 2); 374 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 1);
369 EXPECT_ACTION("SetNeedsBeginFrame", client, 1, 2);
370 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); 375 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending());
371 EXPECT_TRUE(client.needs_begin_impl_frame()); 376 EXPECT_TRUE(client.needs_begin_frame());
372 client.Reset(); 377 client.Reset();
373 378
374 // On the next BeginImplFrame, verify we go back to a quiescent state and 379 // On the next BeginImplFrame, verify we go back to a quiescent state and
375 // no longer request BeginImplFrames. 380 // no longer request BeginImplFrames.
376 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); 381 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting());
377 client.task_runner().RunPendingTasks(); // Run posted deadline. 382 client.task_runner().RunPendingTasks(); // Run posted deadline.
378 EXPECT_FALSE(client.needs_begin_impl_frame()); 383 EXPECT_FALSE(client.needs_begin_frame());
379 client.Reset(); 384 client.Reset();
380 } 385 }
381 386
382 class SchedulerClientThatsetNeedsDrawInsideDraw : public FakeSchedulerClient { 387 class SchedulerClientThatsetNeedsDrawInsideDraw : public FakeSchedulerClient {
383 public: 388 public:
384 virtual void ScheduledActionSendBeginMainFrame() OVERRIDE {} 389 virtual void ScheduledActionSendBeginMainFrame() OVERRIDE {}
385 virtual DrawSwapReadbackResult ScheduledActionDrawAndSwapIfPossible() 390 virtual DrawSwapReadbackResult ScheduledActionDrawAndSwapIfPossible()
386 OVERRIDE { 391 OVERRIDE {
387 // Only SetNeedsRedraw the first time this is called 392 // Only SetNeedsRedraw the first time this is called
388 if (!num_draws_) 393 if (!num_draws_)
(...skipping 23 matching lines...) Expand all
412 SchedulerSettings default_scheduler_settings; 417 SchedulerSettings default_scheduler_settings;
413 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings); 418 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings);
414 scheduler->SetCanStart(); 419 scheduler->SetCanStart();
415 scheduler->SetVisible(true); 420 scheduler->SetVisible(true);
416 scheduler->SetCanDraw(true); 421 scheduler->SetCanDraw(true);
417 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); 422 InitializeOutputSurfaceAndFirstCommit(scheduler, &client);
418 client.Reset(); 423 client.Reset();
419 424
420 scheduler->SetNeedsRedraw(); 425 scheduler->SetNeedsRedraw();
421 EXPECT_TRUE(scheduler->RedrawPending()); 426 EXPECT_TRUE(scheduler->RedrawPending());
422 EXPECT_TRUE(client.needs_begin_impl_frame()); 427 EXPECT_TRUE(client.needs_begin_frame());
423 EXPECT_EQ(0, client.num_draws()); 428 EXPECT_EQ(0, client.num_draws());
424 429
425 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); 430 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting());
426 client.task_runner().RunPendingTasks(); // Run posted deadline. 431 client.task_runner().RunPendingTasks(); // Run posted deadline.
427 EXPECT_EQ(1, client.num_draws()); 432 EXPECT_EQ(1, client.num_draws());
428 EXPECT_TRUE(scheduler->RedrawPending()); 433 EXPECT_TRUE(scheduler->RedrawPending());
429 EXPECT_TRUE(client.needs_begin_impl_frame()); 434 EXPECT_TRUE(client.needs_begin_frame());
430 435
431 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); 436 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting());
432 client.task_runner().RunPendingTasks(); // Run posted deadline. 437 client.task_runner().RunPendingTasks(); // Run posted deadline.
433 EXPECT_EQ(2, client.num_draws()); 438 EXPECT_EQ(2, client.num_draws());
434 EXPECT_FALSE(scheduler->RedrawPending()); 439 EXPECT_FALSE(scheduler->RedrawPending());
435 EXPECT_TRUE(client.needs_begin_impl_frame()); 440 EXPECT_TRUE(client.needs_begin_frame());
436 441
437 // We stop requesting BeginImplFrames after a BeginImplFrame where we don't 442 // We stop requesting BeginImplFrames after a BeginImplFrame where we don't
438 // swap. 443 // swap.
439 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); 444 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting());
440 client.task_runner().RunPendingTasks(); // Run posted deadline. 445 client.task_runner().RunPendingTasks(); // Run posted deadline.
441 EXPECT_EQ(2, client.num_draws()); 446 EXPECT_EQ(2, client.num_draws());
442 EXPECT_FALSE(scheduler->RedrawPending()); 447 EXPECT_FALSE(scheduler->RedrawPending());
443 EXPECT_FALSE(client.needs_begin_impl_frame()); 448 EXPECT_FALSE(client.needs_begin_frame());
444 } 449 }
445 450
446 // Test that requesting redraw inside a failed draw doesn't lose the request. 451 // Test that requesting redraw inside a failed draw doesn't lose the request.
447 TEST(SchedulerTest, RequestRedrawInsideFailedDraw) { 452 TEST(SchedulerTest, RequestRedrawInsideFailedDraw) {
448 SchedulerClientThatsetNeedsDrawInsideDraw client; 453 SchedulerClientThatsetNeedsDrawInsideDraw client;
449 SchedulerSettings default_scheduler_settings; 454 SchedulerSettings default_scheduler_settings;
450 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings); 455 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings);
451 scheduler->SetCanStart(); 456 scheduler->SetCanStart();
452 scheduler->SetVisible(true); 457 scheduler->SetVisible(true);
453 scheduler->SetCanDraw(true); 458 scheduler->SetCanDraw(true);
454 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); 459 InitializeOutputSurfaceAndFirstCommit(scheduler, &client);
455 client.Reset(); 460 client.Reset();
456 461
457 client.SetDrawWillHappen(false); 462 client.SetDrawWillHappen(false);
458 463
459 scheduler->SetNeedsRedraw(); 464 scheduler->SetNeedsRedraw();
460 EXPECT_TRUE(scheduler->RedrawPending()); 465 EXPECT_TRUE(scheduler->RedrawPending());
461 EXPECT_TRUE(client.needs_begin_impl_frame()); 466 EXPECT_TRUE(client.needs_begin_frame());
462 EXPECT_EQ(0, client.num_draws()); 467 EXPECT_EQ(0, client.num_draws());
463 468
464 // Fail the draw. 469 // Fail the draw.
465 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); 470 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting());
466 client.task_runner().RunPendingTasks(); // Run posted deadline. 471 client.task_runner().RunPendingTasks(); // Run posted deadline.
467 EXPECT_EQ(1, client.num_draws()); 472 EXPECT_EQ(1, client.num_draws());
468 473
469 // We have a commit pending and the draw failed, and we didn't lose the redraw 474 // We have a commit pending and the draw failed, and we didn't lose the redraw
470 // request. 475 // request.
471 EXPECT_TRUE(scheduler->CommitPending()); 476 EXPECT_TRUE(scheduler->CommitPending());
472 EXPECT_TRUE(scheduler->RedrawPending()); 477 EXPECT_TRUE(scheduler->RedrawPending());
473 EXPECT_TRUE(client.needs_begin_impl_frame()); 478 EXPECT_TRUE(client.needs_begin_frame());
474 479
475 // Fail the draw again. 480 // Fail the draw again.
476 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); 481 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting());
477 client.task_runner().RunPendingTasks(); // Run posted deadline. 482 client.task_runner().RunPendingTasks(); // Run posted deadline.
478 EXPECT_EQ(2, client.num_draws()); 483 EXPECT_EQ(2, client.num_draws());
479 EXPECT_TRUE(scheduler->CommitPending()); 484 EXPECT_TRUE(scheduler->CommitPending());
480 EXPECT_TRUE(scheduler->RedrawPending()); 485 EXPECT_TRUE(scheduler->RedrawPending());
481 EXPECT_TRUE(client.needs_begin_impl_frame()); 486 EXPECT_TRUE(client.needs_begin_frame());
482 487
483 // Draw successfully. 488 // Draw successfully.
484 client.SetDrawWillHappen(true); 489 client.SetDrawWillHappen(true);
485 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); 490 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting());
486 client.task_runner().RunPendingTasks(); // Run posted deadline. 491 client.task_runner().RunPendingTasks(); // Run posted deadline.
487 EXPECT_EQ(3, client.num_draws()); 492 EXPECT_EQ(3, client.num_draws());
488 EXPECT_TRUE(scheduler->CommitPending()); 493 EXPECT_TRUE(scheduler->CommitPending());
489 EXPECT_FALSE(scheduler->RedrawPending()); 494 EXPECT_FALSE(scheduler->RedrawPending());
490 EXPECT_TRUE(client.needs_begin_impl_frame()); 495 EXPECT_TRUE(client.needs_begin_frame());
491 } 496 }
492 497
493 class SchedulerClientThatSetNeedsCommitInsideDraw : public FakeSchedulerClient { 498 class SchedulerClientThatSetNeedsCommitInsideDraw : public FakeSchedulerClient {
494 public: 499 public:
495 SchedulerClientThatSetNeedsCommitInsideDraw() 500 SchedulerClientThatSetNeedsCommitInsideDraw()
496 : set_needs_commit_on_next_draw_(false) {} 501 : set_needs_commit_on_next_draw_(false) {}
497 502
498 virtual void ScheduledActionSendBeginMainFrame() OVERRIDE {} 503 virtual void ScheduledActionSendBeginMainFrame() OVERRIDE {}
499 virtual DrawSwapReadbackResult ScheduledActionDrawAndSwapIfPossible() 504 virtual DrawSwapReadbackResult ScheduledActionDrawAndSwapIfPossible()
500 OVERRIDE { 505 OVERRIDE {
(...skipping 28 matching lines...) Expand all
529 TEST(SchedulerTest, RequestCommitInsideDraw) { 534 TEST(SchedulerTest, RequestCommitInsideDraw) {
530 SchedulerClientThatSetNeedsCommitInsideDraw client; 535 SchedulerClientThatSetNeedsCommitInsideDraw client;
531 SchedulerSettings default_scheduler_settings; 536 SchedulerSettings default_scheduler_settings;
532 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings); 537 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings);
533 scheduler->SetCanStart(); 538 scheduler->SetCanStart();
534 scheduler->SetVisible(true); 539 scheduler->SetVisible(true);
535 scheduler->SetCanDraw(true); 540 scheduler->SetCanDraw(true);
536 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); 541 InitializeOutputSurfaceAndFirstCommit(scheduler, &client);
537 client.Reset(); 542 client.Reset();
538 543
539 EXPECT_FALSE(client.needs_begin_impl_frame()); 544 EXPECT_FALSE(client.needs_begin_frame());
540 scheduler->SetNeedsRedraw(); 545 scheduler->SetNeedsRedraw();
541 EXPECT_TRUE(scheduler->RedrawPending()); 546 EXPECT_TRUE(scheduler->RedrawPending());
542 EXPECT_EQ(0, client.num_draws()); 547 EXPECT_EQ(0, client.num_draws());
543 EXPECT_TRUE(client.needs_begin_impl_frame()); 548 EXPECT_TRUE(client.needs_begin_frame());
544 549
545 client.SetNeedsCommitOnNextDraw(); 550 client.SetNeedsCommitOnNextDraw();
546 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); 551 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting());
547 client.SetNeedsCommitOnNextDraw(); 552 client.SetNeedsCommitOnNextDraw();
548 client.task_runner().RunPendingTasks(); // Run posted deadline. 553 client.task_runner().RunPendingTasks(); // Run posted deadline.
549 EXPECT_EQ(1, client.num_draws()); 554 EXPECT_EQ(1, client.num_draws());
550 EXPECT_TRUE(scheduler->CommitPending()); 555 EXPECT_TRUE(scheduler->CommitPending());
551 EXPECT_TRUE(client.needs_begin_impl_frame()); 556 EXPECT_TRUE(client.needs_begin_frame());
552 scheduler->NotifyBeginMainFrameStarted(); 557 scheduler->NotifyBeginMainFrameStarted();
553 scheduler->NotifyReadyToCommit(); 558 scheduler->NotifyReadyToCommit();
554 559
555 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); 560 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting());
556 client.task_runner().RunPendingTasks(); // Run posted deadline. 561 client.task_runner().RunPendingTasks(); // Run posted deadline.
557 EXPECT_EQ(2, client.num_draws()); 562 EXPECT_EQ(2, client.num_draws());
558 563
559 EXPECT_FALSE(scheduler->RedrawPending()); 564 EXPECT_FALSE(scheduler->RedrawPending());
560 EXPECT_FALSE(scheduler->CommitPending()); 565 EXPECT_FALSE(scheduler->CommitPending());
561 EXPECT_TRUE(client.needs_begin_impl_frame()); 566 EXPECT_TRUE(client.needs_begin_frame());
562 567
563 // We stop requesting BeginImplFrames after a BeginImplFrame where we don't 568 // We stop requesting BeginImplFrames after a BeginImplFrame where we don't
564 // swap. 569 // swap.
565 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); 570 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting());
566 client.task_runner().RunPendingTasks(); // Run posted deadline. 571 client.task_runner().RunPendingTasks(); // Run posted deadline.
567 EXPECT_EQ(2, client.num_draws()); 572 EXPECT_EQ(2, client.num_draws());
568 EXPECT_FALSE(scheduler->RedrawPending()); 573 EXPECT_FALSE(scheduler->RedrawPending());
569 EXPECT_FALSE(scheduler->CommitPending()); 574 EXPECT_FALSE(scheduler->CommitPending());
570 EXPECT_FALSE(client.needs_begin_impl_frame()); 575 EXPECT_FALSE(client.needs_begin_frame());
571 } 576 }
572 577
573 // Tests that when a draw fails then the pending commit should not be dropped. 578 // Tests that when a draw fails then the pending commit should not be dropped.
574 TEST(SchedulerTest, RequestCommitInsideFailedDraw) { 579 TEST(SchedulerTest, RequestCommitInsideFailedDraw) {
575 SchedulerClientThatsetNeedsDrawInsideDraw client; 580 SchedulerClientThatsetNeedsDrawInsideDraw client;
576 SchedulerSettings default_scheduler_settings; 581 SchedulerSettings default_scheduler_settings;
577 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings); 582 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings);
578 scheduler->SetCanStart(); 583 scheduler->SetCanStart();
579 scheduler->SetVisible(true); 584 scheduler->SetVisible(true);
580 scheduler->SetCanDraw(true); 585 scheduler->SetCanDraw(true);
581 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); 586 InitializeOutputSurfaceAndFirstCommit(scheduler, &client);
582 client.Reset(); 587 client.Reset();
583 588
584 client.SetDrawWillHappen(false); 589 client.SetDrawWillHappen(false);
585 590
586 scheduler->SetNeedsRedraw(); 591 scheduler->SetNeedsRedraw();
587 EXPECT_TRUE(scheduler->RedrawPending()); 592 EXPECT_TRUE(scheduler->RedrawPending());
588 EXPECT_TRUE(client.needs_begin_impl_frame()); 593 EXPECT_TRUE(client.needs_begin_frame());
589 EXPECT_EQ(0, client.num_draws()); 594 EXPECT_EQ(0, client.num_draws());
590 595
591 // Fail the draw. 596 // Fail the draw.
592 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); 597 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting());
593 client.task_runner().RunPendingTasks(); // Run posted deadline. 598 client.task_runner().RunPendingTasks(); // Run posted deadline.
594 EXPECT_EQ(1, client.num_draws()); 599 EXPECT_EQ(1, client.num_draws());
595 600
596 // We have a commit pending and the draw failed, and we didn't lose the commit 601 // We have a commit pending and the draw failed, and we didn't lose the commit
597 // request. 602 // request.
598 EXPECT_TRUE(scheduler->CommitPending()); 603 EXPECT_TRUE(scheduler->CommitPending());
599 EXPECT_TRUE(scheduler->RedrawPending()); 604 EXPECT_TRUE(scheduler->RedrawPending());
600 EXPECT_TRUE(client.needs_begin_impl_frame()); 605 EXPECT_TRUE(client.needs_begin_frame());
601 606
602 // Fail the draw again. 607 // Fail the draw again.
603 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); 608 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting());
604 609
605 client.task_runner().RunPendingTasks(); // Run posted deadline. 610 client.task_runner().RunPendingTasks(); // Run posted deadline.
606 EXPECT_EQ(2, client.num_draws()); 611 EXPECT_EQ(2, client.num_draws());
607 EXPECT_TRUE(scheduler->CommitPending()); 612 EXPECT_TRUE(scheduler->CommitPending());
608 EXPECT_TRUE(scheduler->RedrawPending()); 613 EXPECT_TRUE(scheduler->RedrawPending());
609 EXPECT_TRUE(client.needs_begin_impl_frame()); 614 EXPECT_TRUE(client.needs_begin_frame());
610 615
611 // Draw successfully. 616 // Draw successfully.
612 client.SetDrawWillHappen(true); 617 client.SetDrawWillHappen(true);
613 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); 618 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting());
614 client.task_runner().RunPendingTasks(); // Run posted deadline. 619 client.task_runner().RunPendingTasks(); // Run posted deadline.
615 EXPECT_EQ(3, client.num_draws()); 620 EXPECT_EQ(3, client.num_draws());
616 EXPECT_TRUE(scheduler->CommitPending()); 621 EXPECT_TRUE(scheduler->CommitPending());
617 EXPECT_FALSE(scheduler->RedrawPending()); 622 EXPECT_FALSE(scheduler->RedrawPending());
618 EXPECT_TRUE(client.needs_begin_impl_frame()); 623 EXPECT_TRUE(client.needs_begin_frame());
619 } 624 }
620 625
621 TEST(SchedulerTest, NoSwapWhenDrawFails) { 626 TEST(SchedulerTest, NoSwapWhenDrawFails) {
622 SchedulerClientThatSetNeedsCommitInsideDraw client; 627 SchedulerClientThatSetNeedsCommitInsideDraw client;
623 SchedulerSettings default_scheduler_settings; 628 SchedulerSettings default_scheduler_settings;
624 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings); 629 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings);
625 scheduler->SetCanStart(); 630 scheduler->SetCanStart();
626 scheduler->SetVisible(true); 631 scheduler->SetVisible(true);
627 scheduler->SetCanDraw(true); 632 scheduler->SetCanDraw(true);
628 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); 633 InitializeOutputSurfaceAndFirstCommit(scheduler, &client);
629 client.Reset(); 634 client.Reset();
630 635
631 scheduler->SetNeedsRedraw(); 636 scheduler->SetNeedsRedraw();
632 EXPECT_TRUE(scheduler->RedrawPending()); 637 EXPECT_TRUE(scheduler->RedrawPending());
633 EXPECT_TRUE(client.needs_begin_impl_frame()); 638 EXPECT_TRUE(client.needs_begin_frame());
634 EXPECT_EQ(0, client.num_draws()); 639 EXPECT_EQ(0, client.num_draws());
635 640
636 // Draw successfully, this starts a new frame. 641 // Draw successfully, this starts a new frame.
637 client.SetNeedsCommitOnNextDraw(); 642 client.SetNeedsCommitOnNextDraw();
638 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); 643 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting());
639 client.task_runner().RunPendingTasks(); // Run posted deadline. 644 client.task_runner().RunPendingTasks(); // Run posted deadline.
640 EXPECT_EQ(1, client.num_draws()); 645 EXPECT_EQ(1, client.num_draws());
641 646
642 scheduler->SetNeedsRedraw(); 647 scheduler->SetNeedsRedraw();
643 EXPECT_TRUE(scheduler->RedrawPending()); 648 EXPECT_TRUE(scheduler->RedrawPending());
644 EXPECT_TRUE(client.needs_begin_impl_frame()); 649 EXPECT_TRUE(client.needs_begin_frame());
645 650
646 // Fail to draw, this should not start a frame. 651 // Fail to draw, this should not start a frame.
647 client.SetDrawWillHappen(false); 652 client.SetDrawWillHappen(false);
648 client.SetNeedsCommitOnNextDraw(); 653 client.SetNeedsCommitOnNextDraw();
649 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); 654 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting());
650 client.task_runner().RunPendingTasks(); // Run posted deadline. 655 client.task_runner().RunPendingTasks(); // Run posted deadline.
651 EXPECT_EQ(2, client.num_draws()); 656 EXPECT_EQ(2, client.num_draws());
652 } 657 }
653 658
654 TEST(SchedulerTest, NoSwapWhenSwapFailsDuringForcedCommit) { 659 TEST(SchedulerTest, NoSwapWhenSwapFailsDuringForcedCommit) {
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
717 scheduler->SetCanDraw(true); 722 scheduler->SetCanDraw(true);
718 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); 723 InitializeOutputSurfaceAndFirstCommit(scheduler, &client);
719 724
720 // Request both draw and manage tiles. ManageTiles shouldn't 725 // Request both draw and manage tiles. ManageTiles shouldn't
721 // be trigged until BeginImplFrame. 726 // be trigged until BeginImplFrame.
722 client.Reset(); 727 client.Reset();
723 scheduler->SetNeedsManageTiles(); 728 scheduler->SetNeedsManageTiles();
724 scheduler->SetNeedsRedraw(); 729 scheduler->SetNeedsRedraw();
725 EXPECT_TRUE(scheduler->RedrawPending()); 730 EXPECT_TRUE(scheduler->RedrawPending());
726 EXPECT_TRUE(scheduler->ManageTilesPending()); 731 EXPECT_TRUE(scheduler->ManageTilesPending());
727 EXPECT_TRUE(client.needs_begin_impl_frame()); 732 EXPECT_TRUE(client.needs_begin_frame());
728 EXPECT_EQ(0, client.num_draws()); 733 EXPECT_EQ(0, client.num_draws());
729 EXPECT_FALSE(client.HasAction("ScheduledActionManageTiles")); 734 EXPECT_FALSE(client.HasAction("ScheduledActionManageTiles"));
730 EXPECT_FALSE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); 735 EXPECT_FALSE(client.HasAction("ScheduledActionDrawAndSwapIfPossible"));
731 736
732 // We have no immediate actions to perform, so the BeginImplFrame should post 737 // We have no immediate actions to perform, so the BeginImplFrame should post
733 // the deadline task. 738 // the deadline task.
734 client.Reset(); 739 client.Reset();
735 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); 740 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting());
736 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); 741 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client);
737 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 742 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending());
738 743
739 // On the deadline, he actions should have occured in the right order. 744 // On the deadline, he actions should have occured in the right order.
740 client.Reset(); 745 client.Reset();
741 client.task_runner().RunPendingTasks(); // Run posted deadline. 746 client.task_runner().RunPendingTasks(); // Run posted deadline.
742 EXPECT_EQ(1, client.num_draws()); 747 EXPECT_EQ(1, client.num_draws());
743 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); 748 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible"));
744 EXPECT_TRUE(client.HasAction("ScheduledActionManageTiles")); 749 EXPECT_TRUE(client.HasAction("ScheduledActionManageTiles"));
745 EXPECT_LT(client.ActionIndex("ScheduledActionDrawAndSwapIfPossible"), 750 EXPECT_LT(client.ActionIndex("ScheduledActionDrawAndSwapIfPossible"),
746 client.ActionIndex("ScheduledActionManageTiles")); 751 client.ActionIndex("ScheduledActionManageTiles"));
747 EXPECT_FALSE(scheduler->RedrawPending()); 752 EXPECT_FALSE(scheduler->RedrawPending());
748 EXPECT_FALSE(scheduler->ManageTilesPending()); 753 EXPECT_FALSE(scheduler->ManageTilesPending());
749 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); 754 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending());
750 755
751 // Request a draw. We don't need a ManageTiles yet. 756 // Request a draw. We don't need a ManageTiles yet.
752 client.Reset(); 757 client.Reset();
753 scheduler->SetNeedsRedraw(); 758 scheduler->SetNeedsRedraw();
754 EXPECT_TRUE(scheduler->RedrawPending()); 759 EXPECT_TRUE(scheduler->RedrawPending());
755 EXPECT_FALSE(scheduler->ManageTilesPending()); 760 EXPECT_FALSE(scheduler->ManageTilesPending());
756 EXPECT_TRUE(client.needs_begin_impl_frame()); 761 EXPECT_TRUE(client.needs_begin_frame());
757 EXPECT_EQ(0, client.num_draws()); 762 EXPECT_EQ(0, client.num_draws());
758 763
759 // We have no immediate actions to perform, so the BeginImplFrame should post 764 // We have no immediate actions to perform, so the BeginImplFrame should post
760 // the deadline task. 765 // the deadline task.
761 client.Reset(); 766 client.Reset();
762 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); 767 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting());
763 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); 768 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client);
764 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 769 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending());
765 770
766 // Draw. The draw will trigger SetNeedsManageTiles, and 771 // Draw. The draw will trigger SetNeedsManageTiles, and
(...skipping 11 matching lines...) Expand all
778 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); 783 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending());
779 784
780 // We need a BeginImplFrame where we don't swap to go idle. 785 // We need a BeginImplFrame where we don't swap to go idle.
781 client.Reset(); 786 client.Reset();
782 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); 787 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting());
783 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); 788 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client);
784 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 789 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending());
785 client.Reset(); 790 client.Reset();
786 client.task_runner().RunPendingTasks(); // Run posted deadline. 791 client.task_runner().RunPendingTasks(); // Run posted deadline.
787 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); 792 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client);
793 EXPECT_FALSE(client.needs_begin_frame());
788 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); 794 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending());
789 EXPECT_EQ(0, client.num_draws()); 795 EXPECT_EQ(0, client.num_draws());
790 796
791 // Now trigger a ManageTiles outside of a draw. We will then need 797 // Now trigger a ManageTiles outside of a draw. We will then need
792 // a begin-frame for the ManageTiles, but we don't need a draw. 798 // a begin-frame for the ManageTiles, but we don't need a draw.
793 client.Reset(); 799 client.Reset();
794 EXPECT_FALSE(client.needs_begin_impl_frame()); 800 EXPECT_FALSE(client.needs_begin_frame());
795 scheduler->SetNeedsManageTiles(); 801 scheduler->SetNeedsManageTiles();
796 EXPECT_TRUE(client.needs_begin_impl_frame()); 802 EXPECT_TRUE(client.needs_begin_frame());
797 EXPECT_TRUE(scheduler->ManageTilesPending()); 803 EXPECT_TRUE(scheduler->ManageTilesPending());
798 EXPECT_FALSE(scheduler->RedrawPending()); 804 EXPECT_FALSE(scheduler->RedrawPending());
799 805
800 // BeginImplFrame. There will be no draw, only ManageTiles. 806 // BeginImplFrame. There will be no draw, only ManageTiles.
801 client.Reset(); 807 client.Reset();
802 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); 808 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting());
803 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); 809 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client);
804 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 810 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending());
805 client.Reset(); 811 client.Reset();
806 client.task_runner().RunPendingTasks(); // Run posted deadline. 812 client.task_runner().RunPendingTasks(); // Run posted deadline.
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after
1109 client.task_runner().NextPendingTaskDelay().InMicroseconds()) 1115 client.task_runner().NextPendingTaskDelay().InMicroseconds())
1110 << *scheduler->StateAsValue(); 1116 << *scheduler->StateAsValue();
1111 client.task_runner().RunPendingTasks(); 1117 client.task_runner().RunPendingTasks();
1112 EXPECT_GT(client.num_actions_(), actions_so_far); 1118 EXPECT_GT(client.num_actions_(), actions_so_far);
1113 EXPECT_STREQ(client.Action(client.num_actions_() - 1), 1119 EXPECT_STREQ(client.Action(client.num_actions_() - 1),
1114 "DidAnticipatedDrawTimeChange"); 1120 "DidAnticipatedDrawTimeChange");
1115 actions_so_far = client.num_actions_(); 1121 actions_so_far = client.num_actions_();
1116 } 1122 }
1117 } 1123 }
1118 1124
1119 TEST(SchedulerTest, BeginRetroFrameBasic) { 1125 TEST(SchedulerTest, BeginRetroFrame) {
1120 FakeSchedulerClient client; 1126 FakeSchedulerClient client;
1121 SchedulerSettings scheduler_settings; 1127 SchedulerSettings scheduler_settings;
1122 Scheduler* scheduler = client.CreateScheduler(scheduler_settings); 1128 Scheduler* scheduler = client.CreateScheduler(scheduler_settings);
1123 scheduler->SetCanStart(); 1129 scheduler->SetCanStart();
1124 scheduler->SetVisible(true); 1130 scheduler->SetVisible(true);
1125 scheduler->SetCanDraw(true); 1131 scheduler->SetCanDraw(true);
1126 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); 1132 InitializeOutputSurfaceAndFirstCommit(scheduler, &client);
1127 1133
1128 // SetNeedsCommit should begin the frame on the next BeginImplFrame. 1134 // SetNeedsCommit should begin the frame on the next BeginImplFrame.
1129 client.Reset(); 1135 client.Reset();
1130 scheduler->SetNeedsCommit(); 1136 scheduler->SetNeedsCommit();
1131 EXPECT_TRUE(client.needs_begin_impl_frame()); 1137 EXPECT_TRUE(client.needs_begin_frame());
1132 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); 1138 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client);
1133 client.Reset(); 1139 client.Reset();
1134 1140
1135 // Create a BeginFrame with a long deadline to avoid race conditions. 1141 // Create a BeginFrame with a long deadline to avoid race conditions.
1136 // This is the first BeginFrame, which will be handled immediately. 1142 // This is the first BeginFrame, which will be handled immediately.
1137 BeginFrameArgs args = BeginFrameArgs::CreateForTesting(); 1143 BeginFrameArgs args = BeginFrameArgs::CreateForTesting();
1138 args.deadline += base::TimeDelta::FromHours(1); 1144 args.deadline += base::TimeDelta::FromHours(1);
1139 scheduler->BeginFrame(args); 1145 scheduler->BeginFrame(args);
1140 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); 1146 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2);
1141 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); 1147 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2);
1142 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 1148 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending());
1143 EXPECT_TRUE(client.needs_begin_impl_frame()); 1149 EXPECT_TRUE(client.needs_begin_frame());
1144 client.Reset(); 1150 client.Reset();
1145 1151
1146 // Queue BeginFrames while we are still handling the previous BeginFrame. 1152 // Queue BeginFrames while we are still handling the previous BeginFrame.
1147 args.frame_time += base::TimeDelta::FromSeconds(1); 1153 args.frame_time += base::TimeDelta::FromSeconds(1);
1148 scheduler->BeginFrame(args); 1154 scheduler->BeginFrame(args);
1149 args.frame_time += base::TimeDelta::FromSeconds(1); 1155 args.frame_time += base::TimeDelta::FromSeconds(1);
1150 scheduler->BeginFrame(args); 1156 scheduler->BeginFrame(args);
1151 1157
1152 // If we don't swap on the deadline, we need to request another 1158 // If we don't swap on the deadline, we wait for the next BeginImplFrame.
1153 // BeginImplFrame.
1154 client.task_runner().RunPendingTasks(); // Run posted deadline. 1159 client.task_runner().RunPendingTasks(); // Run posted deadline.
1155 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); 1160 EXPECT_EQ(0, client.num_actions_());
1156 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); 1161 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending());
1157 EXPECT_TRUE(client.needs_begin_impl_frame()); 1162 EXPECT_TRUE(client.needs_begin_frame());
1158 client.Reset(); 1163 client.Reset();
1159 1164
1160 // NotifyReadyToCommit should trigger the commit. 1165 // NotifyReadyToCommit should trigger the commit.
1161 scheduler->NotifyBeginMainFrameStarted(); 1166 scheduler->NotifyBeginMainFrameStarted();
1162 scheduler->NotifyReadyToCommit(); 1167 scheduler->NotifyReadyToCommit();
1163 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); 1168 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client);
1164 EXPECT_TRUE(client.needs_begin_impl_frame()); 1169 EXPECT_TRUE(client.needs_begin_frame());
1165 client.Reset(); 1170 client.Reset();
1166 1171
1167 // BeginImplFrame should prepare the draw. 1172 // BeginImplFrame should prepare the draw.
1168 client.task_runner().RunPendingTasks(); // Run posted BeginRetroFrame. 1173 client.task_runner().RunPendingTasks(); // Run posted BeginRetroFrame.
1169 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); 1174 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client);
1170 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 1175 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending());
1171 EXPECT_TRUE(client.needs_begin_impl_frame()); 1176 EXPECT_TRUE(client.needs_begin_frame());
1172 client.Reset(); 1177 client.Reset();
1173 1178
1174 // BeginImplFrame deadline should draw. 1179 // BeginImplFrame deadline should draw.
1175 client.task_runner().RunPendingTasks(); // Run posted deadline. 1180 client.task_runner().RunPendingTasks(); // Run posted deadline.
1176 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 2); 1181 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 1);
1177 EXPECT_ACTION("SetNeedsBeginFrame", client, 1, 2);
1178 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); 1182 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending());
1179 EXPECT_TRUE(client.needs_begin_impl_frame()); 1183 EXPECT_TRUE(client.needs_begin_frame());
1180 client.Reset(); 1184 client.Reset();
1181 1185
1182 // The following BeginImplFrame deadline should SetNeedsBeginFrame(false) 1186 // The following BeginImplFrame deadline should SetNeedsBeginFrame(false)
1183 // to avoid excessive toggles. 1187 // to avoid excessive toggles.
1184 client.task_runner().RunPendingTasks(); // Run posted BeginRetroFrame. 1188 client.task_runner().RunPendingTasks(); // Run posted BeginRetroFrame.
1185 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); 1189 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client);
1186 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 1190 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending());
1187 client.Reset(); 1191 client.Reset();
1188 1192
1189 client.task_runner().RunPendingTasks(); // Run posted deadline. 1193 client.task_runner().RunPendingTasks(); // Run posted deadline.
1190 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); 1194 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client);
1191 EXPECT_FALSE(client.needs_begin_impl_frame()); 1195 EXPECT_FALSE(client.needs_begin_frame());
1192 client.Reset(); 1196 client.Reset();
1193 } 1197 }
1194 1198
1195 TEST(SchedulerTest, BeginRetroFrame_SwapThrottled) { 1199 TEST(SchedulerTest, BeginRetroFrame_SwapThrottled) {
1196 FakeSchedulerClient client; 1200 FakeSchedulerClient client;
1197 SchedulerSettings scheduler_settings; 1201 SchedulerSettings scheduler_settings;
1198 Scheduler* scheduler = client.CreateScheduler(scheduler_settings); 1202 Scheduler* scheduler = client.CreateScheduler(scheduler_settings);
1199 scheduler->SetCanStart(); 1203 scheduler->SetCanStart();
1200 scheduler->SetVisible(true); 1204 scheduler->SetVisible(true);
1201 scheduler->SetCanDraw(true); 1205 scheduler->SetCanDraw(true);
1202 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); 1206 InitializeOutputSurfaceAndFirstCommit(scheduler, &client);
1203 1207
1204 // To test swap ack throttling, this test disables automatic swap acks. 1208 // To test swap ack throttling, this test disables automatic swap acks.
1205 scheduler->SetMaxSwapsPending(1); 1209 scheduler->SetMaxSwapsPending(1);
1206 client.SetAutomaticSwapAck(false); 1210 client.SetAutomaticSwapAck(false);
1207 1211
1208 // SetNeedsCommit should begin the frame on the next BeginImplFrame. 1212 // SetNeedsCommit should begin the frame on the next BeginImplFrame.
1209 client.Reset(); 1213 client.Reset();
1210 scheduler->SetNeedsCommit(); 1214 scheduler->SetNeedsCommit();
1211 EXPECT_TRUE(client.needs_begin_impl_frame()); 1215 EXPECT_TRUE(client.needs_begin_frame());
1212 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); 1216 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client);
1213 client.Reset(); 1217 client.Reset();
1214 1218
1215 // Create a BeginFrame with a long deadline to avoid race conditions. 1219 // Create a BeginFrame with a long deadline to avoid race conditions.
1216 // This is the first BeginFrame, which will be handled immediately. 1220 // This is the first BeginFrame, which will be handled immediately.
1217 BeginFrameArgs args = BeginFrameArgs::CreateForTesting(); 1221 BeginFrameArgs args = BeginFrameArgs::CreateForTesting();
1218 args.deadline += base::TimeDelta::FromHours(1); 1222 args.deadline += base::TimeDelta::FromHours(1);
1219 scheduler->BeginFrame(args); 1223 scheduler->BeginFrame(args);
1220 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); 1224 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2);
1221 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); 1225 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2);
1222 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 1226 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending());
1223 EXPECT_TRUE(client.needs_begin_impl_frame()); 1227 EXPECT_TRUE(client.needs_begin_frame());
1224 client.Reset(); 1228 client.Reset();
1225 1229
1226 // Queue BeginFrame while we are still handling the previous BeginFrame. 1230 // Queue BeginFrame while we are still handling the previous BeginFrame.
1227 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 1231 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending());
1228 args.frame_time += base::TimeDelta::FromSeconds(1); 1232 args.frame_time += base::TimeDelta::FromSeconds(1);
1229 scheduler->BeginFrame(args); 1233 scheduler->BeginFrame(args);
1230 EXPECT_EQ(0, client.num_actions_()); 1234 EXPECT_EQ(0, client.num_actions_());
1231 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 1235 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending());
1232 client.Reset(); 1236 client.Reset();
1233 1237
1234 // NotifyReadyToCommit should trigger the pending commit and draw. 1238 // NotifyReadyToCommit should trigger the pending commit and draw.
1235 scheduler->NotifyBeginMainFrameStarted(); 1239 scheduler->NotifyBeginMainFrameStarted();
1236 scheduler->NotifyReadyToCommit(); 1240 scheduler->NotifyReadyToCommit();
1237 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); 1241 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client);
1238 EXPECT_TRUE(client.needs_begin_impl_frame()); 1242 EXPECT_TRUE(client.needs_begin_frame());
1239 client.Reset(); 1243 client.Reset();
1240 1244
1241 // Swapping will put us into a swap throttled state. 1245 // Swapping will put us into a swap throttled state.
1242 client.task_runner().RunPendingTasks(); // Run posted deadline. 1246 client.task_runner().RunPendingTasks(); // Run posted deadline.
1243 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 2); 1247 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 1);
1244 EXPECT_ACTION("SetNeedsBeginFrame", client, 1, 2);
1245 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); 1248 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending());
1246 EXPECT_TRUE(client.needs_begin_impl_frame()); 1249 EXPECT_TRUE(client.needs_begin_frame());
1247 client.Reset(); 1250 client.Reset();
1248 1251
1249 // While swap throttled, BeginRetroFrames should trigger BeginImplFrames 1252 // While swap throttled, BeginRetroFrames should trigger BeginImplFrames
1250 // but not a BeginMainFrame or draw. 1253 // but not a BeginMainFrame or draw.
1251 scheduler->SetNeedsCommit(); 1254 scheduler->SetNeedsCommit();
1252 client.task_runner().RunPendingTasks(); // Run posted BeginRetroFrame. 1255 client.task_runner().RunPendingTasks(); // Run posted BeginRetroFrame.
1253 EXPECT_ACTION("WillBeginImplFrame", client, 0, 1); 1256 EXPECT_ACTION("WillBeginImplFrame", client, 0, 1);
1254 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 1257 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending());
1255 EXPECT_TRUE(client.needs_begin_impl_frame()); 1258 EXPECT_TRUE(client.needs_begin_frame());
1256 client.Reset(); 1259 client.Reset();
1257 1260
1258 // Queue BeginFrame while we are still handling the previous BeginFrame. 1261 // Queue BeginFrame while we are still handling the previous BeginFrame.
1259 args.frame_time += base::TimeDelta::FromSeconds(1); 1262 args.frame_time += base::TimeDelta::FromSeconds(1);
1260 scheduler->BeginFrame(args); 1263 scheduler->BeginFrame(args);
1261 EXPECT_EQ(0, client.num_actions_()); 1264 EXPECT_EQ(0, client.num_actions_());
1262 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 1265 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending());
1263 EXPECT_TRUE(client.needs_begin_impl_frame()); 1266 EXPECT_TRUE(client.needs_begin_frame());
1264 client.Reset(); 1267 client.Reset();
1265 1268
1266 // Take us out of a swap throttled state. 1269 // Take us out of a swap throttled state.
1267 scheduler->DidSwapBuffersComplete(); 1270 scheduler->DidSwapBuffersComplete();
1268 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 0, 1); 1271 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 0, 1);
1269 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 1272 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending());
1270 EXPECT_TRUE(client.needs_begin_impl_frame()); 1273 EXPECT_TRUE(client.needs_begin_frame());
1271 client.Reset(); 1274 client.Reset();
1272 1275
1273 // BeginImplFrame deadline should draw. 1276 // BeginImplFrame deadline should draw.
1274 scheduler->SetNeedsRedraw(); 1277 scheduler->SetNeedsRedraw();
1275 client.task_runner().RunPendingTasks(); // Run posted deadline. 1278 client.task_runner().RunPendingTasks(); // Run posted deadline.
1276 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 2); 1279 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 1);
1277 EXPECT_ACTION("SetNeedsBeginFrame", client, 1, 2); 1280 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending());
1278 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); 1281 EXPECT_TRUE(client.needs_begin_frame());
1279 EXPECT_TRUE(client.needs_begin_impl_frame()); 1282 client.Reset();
1280 client.Reset(); 1283 }
1284
1285 void BeginFramesNotFromClient(bool begin_frame_scheduling_enabled,
1286 bool throttle_frame_production) {
1287 FakeSchedulerClient client;
1288 SchedulerSettings scheduler_settings;
1289 scheduler_settings.begin_frame_scheduling_enabled =
1290 begin_frame_scheduling_enabled;
1291 scheduler_settings.throttle_frame_production = throttle_frame_production;
1292 Scheduler* scheduler = client.CreateScheduler(scheduler_settings);
1293 scheduler->SetCanStart();
1294 scheduler->SetVisible(true);
1295 scheduler->SetCanDraw(true);
1296 InitializeOutputSurfaceAndFirstCommit(scheduler, &client);
1297
1298 // SetNeedsCommit should begin the frame on the next BeginImplFrame
1299 // without calling SetNeedsBeginFrame.
1300 client.Reset();
1301 scheduler->SetNeedsCommit();
1302 EXPECT_FALSE(client.needs_begin_frame());
1303 EXPECT_EQ(0, client.num_actions_());
1304 client.Reset();
1305
1306 // When the client-driven BeginFrame are disabled, the scheduler posts it's
1307 // own BeginFrame tasks.
1308 client.task_runner().RunPendingTasks(); // Run posted BeginFrame.
1309 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2);
1310 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2);
1311 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending());
1312 EXPECT_FALSE(client.needs_begin_frame());
1313 client.Reset();
1314
1315 // If we don't swap on the deadline, we wait for the next BeginFrame.
1316 client.task_runner().RunPendingTasks(); // Run posted deadline.
1317 EXPECT_EQ(0, client.num_actions_());
1318 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending());
1319 EXPECT_FALSE(client.needs_begin_frame());
1320 client.Reset();
1321
1322 // NotifyReadyToCommit should trigger the commit.
1323 scheduler->NotifyBeginMainFrameStarted();
1324 scheduler->NotifyReadyToCommit();
1325 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client);
1326 EXPECT_FALSE(client.needs_begin_frame());
1327 client.Reset();
1328
1329 // BeginImplFrame should prepare the draw.
1330 client.task_runner().RunPendingTasks(); // Run posted BeginFrame.
1331 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client);
1332 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending());
1333 EXPECT_FALSE(client.needs_begin_frame());
1334 client.Reset();
1335
1336 // BeginImplFrame deadline should draw.
1337 client.task_runner().RunPendingTasks(); // Run posted deadline.
1338 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 1);
1339 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending());
1340 EXPECT_FALSE(client.needs_begin_frame());
1341 client.Reset();
1342
1343 // The following BeginImplFrame deadline should SetNeedsBeginFrame(false)
1344 // to avoid excessive toggles.
1345 client.task_runner().RunPendingTasks(); // Run posted BeginFrame.
1346 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client);
1347 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending());
1348 client.Reset();
1349
1350 // Make sure SetNeedsBeginFrame isn't called on the client
1351 // when the BeginFrame is no longer needed.
1352 client.task_runner().RunPendingTasks(); // Run posted deadline.
1353 EXPECT_EQ(0, client.num_actions_());
1354 EXPECT_FALSE(client.needs_begin_frame());
1355 client.Reset();
1356 }
1357
1358 TEST(SchedulerTest, SyntheticBeginFrames) {
1359 bool begin_frame_scheduling_enabled = false;
1360 bool throttle_frame_production = true;
1361 BeginFramesNotFromClient(begin_frame_scheduling_enabled,
1362 throttle_frame_production);
1363 }
1364
1365 TEST(SchedulerTest, VSyncThrottlingDisabled) {
1366 bool begin_frame_scheduling_enabled = true;
1367 bool throttle_frame_production = false;
1368 BeginFramesNotFromClient(begin_frame_scheduling_enabled,
1369 throttle_frame_production);
1370 }
1371
1372 TEST(SchedulerTest, SyntheticBeginFrames_And_VSyncThrottlingDisabled) {
1373 bool begin_frame_scheduling_enabled = false;
1374 bool throttle_frame_production = false;
1375 BeginFramesNotFromClient(begin_frame_scheduling_enabled,
1376 throttle_frame_production);
1377 }
1378
1379 void BeginFramesNotFromClient_SwapThrottled(bool begin_frame_scheduling_enabled,
1380 bool throttle_frame_production) {
1381 FakeSchedulerClient client;
1382 SchedulerSettings scheduler_settings;
1383 scheduler_settings.begin_frame_scheduling_enabled =
1384 begin_frame_scheduling_enabled;
1385 scheduler_settings.throttle_frame_production = throttle_frame_production;
1386 Scheduler* scheduler = client.CreateScheduler(scheduler_settings);
1387 scheduler->SetCanStart();
1388 scheduler->SetVisible(true);
1389 scheduler->SetCanDraw(true);
1390 InitializeOutputSurfaceAndFirstCommit(scheduler, &client);
1391
1392 // To test swap ack throttling, this test disables automatic swap acks.
1393 scheduler->SetMaxSwapsPending(1);
1394 client.SetAutomaticSwapAck(false);
1395
1396 // SetNeedsCommit should begin the frame on the next BeginImplFrame.
1397 client.Reset();
1398 scheduler->SetNeedsCommit();
1399 EXPECT_FALSE(client.needs_begin_frame());
1400 EXPECT_EQ(0, client.num_actions_());
1401 client.Reset();
1402
1403 // Trigger the first BeginImplFrame and BeginMainFrame
1404 client.task_runner().RunPendingTasks(); // Run posted BeginFrame.
1405 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2);
1406 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2);
1407 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending());
1408 EXPECT_FALSE(client.needs_begin_frame());
1409 client.Reset();
1410
1411 // NotifyReadyToCommit should trigger the pending commit and draw.
1412 scheduler->NotifyBeginMainFrameStarted();
1413 scheduler->NotifyReadyToCommit();
1414 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client);
1415 EXPECT_FALSE(client.needs_begin_frame());
1416 client.Reset();
1417
1418 // Swapping will put us into a swap throttled state.
1419 client.task_runner().RunPendingTasks(); // Run posted deadline.
1420 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 1);
1421 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending());
1422 EXPECT_FALSE(client.needs_begin_frame());
1423 client.Reset();
1424
1425 // While swap throttled, BeginFrames should trigger BeginImplFrames,
1426 // but not a BeginMainFrame or draw.
1427 scheduler->SetNeedsCommit();
1428 client.task_runner().RunPendingTasks(); // Run posted BeginFrame.
1429 EXPECT_ACTION("WillBeginImplFrame", client, 0, 1);
1430 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending());
1431 EXPECT_FALSE(client.needs_begin_frame());
1432 client.Reset();
1433
1434 // Take us out of a swap throttled state.
1435 scheduler->DidSwapBuffersComplete();
1436 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 0, 1);
1437 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending());
1438 EXPECT_FALSE(client.needs_begin_frame());
1439 client.Reset();
1440
1441 // BeginImplFrame deadline should draw.
1442 scheduler->SetNeedsRedraw();
1443 client.task_runner().RunPendingTasks(); // Run posted deadline.
1444 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 1);
1445 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending());
1446 EXPECT_FALSE(client.needs_begin_frame());
1447 client.Reset();
1448 }
1449
1450 TEST(SchedulerTest, SyntheticBeginFrames_SwapThrottled) {
1451 bool begin_frame_scheduling_enabled = false;
1452 bool throttle_frame_production = true;
1453 BeginFramesNotFromClient_SwapThrottled(begin_frame_scheduling_enabled,
1454 throttle_frame_production);
1455 }
1456
1457 TEST(SchedulerTest, VSyncThrottlingDisabled_SwapThrottled) {
1458 bool begin_frame_scheduling_enabled = true;
1459 bool throttle_frame_production = false;
1460 BeginFramesNotFromClient_SwapThrottled(begin_frame_scheduling_enabled,
1461 throttle_frame_production);
1462 }
1463
1464 TEST(SchedulerTest,
1465 SyntheticBeginFrames_And_VSyncThrottlingDisabled_SwapThrottled) {
1466 bool begin_frame_scheduling_enabled = false;
1467 bool throttle_frame_production = false;
1468 BeginFramesNotFromClient_SwapThrottled(begin_frame_scheduling_enabled,
1469 throttle_frame_production);
1281 } 1470 }
1282 1471
1283 } // namespace 1472 } // namespace
1284 } // namespace cc 1473 } // namespace cc
OLDNEW
« no previous file with comments | « cc/scheduler/scheduler_state_machine.cc ('k') | cc/test/fake_layer_tree_host_impl_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698