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

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

Issue 2632563003: [cc] Calculate the correct latest_confirmed_sequence_number in cc::Scheduler. (Closed)
Patch Set: rebase. Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2011 The Chromium Authors. All rights reserved. 1 // Copyright 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "cc/scheduler/scheduler_state_machine.h" 5 #include "cc/scheduler/scheduler_state_machine.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include "base/trace_event/trace_event.h" 9 #include "base/trace_event/trace_event.h"
10 #include "cc/output/begin_frame_args.h"
10 #include "cc/scheduler/scheduler.h" 11 #include "cc/scheduler/scheduler.h"
11 #include "cc/test/begin_frame_args_test.h" 12 #include "cc/test/begin_frame_args_test.h"
12 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
13 14
14 // Macro to compare two enum values and get nice output. 15 // Macro to compare two enum values and get nice output.
15 // Without: 16 // Without:
16 // Value of: actual() Actual: 7 17 // Value of: actual() Actual: 7
17 // Expected: expected() Which is: 0 18 // Expected: expected() Which is: 0
18 // With: 19 // With:
19 // Value of: actual() Actual: "ACTION_DRAW" 20 // Value of: actual() Actual: "ACTION_DRAW"
20 // Expected: expected() Which is: "ACTION_NONE" 21 // Expected: expected() Which is: "ACTION_NONE"
21 #define EXPECT_ENUM_EQ(enum_tostring, expected, actual) \ 22 #define EXPECT_ENUM_EQ(enum_tostring, expected, actual) \
22 EXPECT_STREQ(SchedulerStateMachine::enum_tostring(expected), \ 23 EXPECT_STREQ(SchedulerStateMachine::enum_tostring(expected), \
23 SchedulerStateMachine::enum_tostring(actual)) 24 SchedulerStateMachine::enum_tostring(actual))
24 25
26 #define EXPECT_SEQUENCE_NUMBERS(current, main_frame, pending_tree, \
27 active_tree, compositor_frame) \
28 EXPECT_EQ(current, state.begin_frame_sequence_number()); \
29 EXPECT_EQ(main_frame, \
30 state.last_begin_frame_sequence_number_begin_main_frame_sent()); \
31 EXPECT_EQ(pending_tree, \
32 state.last_begin_frame_sequence_number_pending_tree_was_fresh()); \
33 EXPECT_EQ(active_tree, \
34 state.last_begin_frame_sequence_number_active_tree_was_fresh()); \
35 EXPECT_EQ( \
36 compositor_frame, \
37 state.last_begin_frame_sequence_number_compositor_frame_was_fresh())
38
25 #define EXPECT_IMPL_FRAME_STATE(expected) \ 39 #define EXPECT_IMPL_FRAME_STATE(expected) \
26 EXPECT_ENUM_EQ(BeginImplFrameStateToString, expected, \ 40 EXPECT_ENUM_EQ(BeginImplFrameStateToString, expected, \
27 state.begin_impl_frame_state()) \ 41 state.begin_impl_frame_state()) \
28 << state.AsValue()->ToString() 42 << state.AsValue()->ToString()
29 43
30 #define EXPECT_MAIN_FRAME_STATE(expected) \ 44 #define EXPECT_MAIN_FRAME_STATE(expected) \
31 EXPECT_ENUM_EQ(BeginMainFrameStateToString, expected, \ 45 EXPECT_ENUM_EQ(BeginMainFrameStateToString, expected, \
32 state.BeginMainFrameState()) 46 state.BeginMainFrameState())
33 47
34 #define EXPECT_ACTION(expected) \ 48 #define EXPECT_ACTION(expected) \
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 public: 93 public:
80 explicit StateMachine(const SchedulerSettings& scheduler_settings) 94 explicit StateMachine(const SchedulerSettings& scheduler_settings)
81 : SchedulerStateMachine(scheduler_settings), 95 : SchedulerStateMachine(scheduler_settings),
82 draw_result_for_test_(DRAW_SUCCESS) {} 96 draw_result_for_test_(DRAW_SUCCESS) {}
83 97
84 void CreateAndInitializeCompositorFrameSinkWithActivatedCommit() { 98 void CreateAndInitializeCompositorFrameSinkWithActivatedCommit() {
85 DidCreateAndInitializeCompositorFrameSink(); 99 DidCreateAndInitializeCompositorFrameSink();
86 compositor_frame_sink_state_ = COMPOSITOR_FRAME_SINK_ACTIVE; 100 compositor_frame_sink_state_ = COMPOSITOR_FRAME_SINK_ACTIVE;
87 } 101 }
88 102
103 void IssueNextBeginImplFrame() {
104 OnBeginImplFrame(0, next_begin_frame_number_++);
105 }
106
89 void SetBeginMainFrameState(BeginMainFrameState cs) { 107 void SetBeginMainFrameState(BeginMainFrameState cs) {
90 begin_main_frame_state_ = cs; 108 begin_main_frame_state_ = cs;
91 } 109 }
92 BeginMainFrameState BeginMainFrameState() const { 110 BeginMainFrameState BeginMainFrameState() const {
93 return begin_main_frame_state_; 111 return begin_main_frame_state_;
94 } 112 }
95 113
96 ForcedRedrawOnTimeoutState ForcedRedrawState() const { 114 ForcedRedrawOnTimeoutState ForcedRedrawState() const {
97 return forced_redraw_state_; 115 return forced_redraw_state_;
98 } 116 }
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 161
144 bool PendingActivationsShouldBeForced() const { 162 bool PendingActivationsShouldBeForced() const {
145 return SchedulerStateMachine::PendingActivationsShouldBeForced(); 163 return SchedulerStateMachine::PendingActivationsShouldBeForced();
146 } 164 }
147 165
148 bool has_pending_tree() const { return has_pending_tree_; } 166 bool has_pending_tree() const { return has_pending_tree_; }
149 void SetHasPendingTree(bool has_pending_tree) { 167 void SetHasPendingTree(bool has_pending_tree) {
150 has_pending_tree_ = has_pending_tree; 168 has_pending_tree_ = has_pending_tree;
151 } 169 }
152 170
171 uint64_t begin_frame_sequence_number() const {
172 return begin_frame_sequence_number_;
173 }
174 uint64_t last_begin_frame_sequence_number_begin_main_frame_sent() const {
175 return last_begin_frame_sequence_number_begin_main_frame_sent_;
176 }
177 uint64_t last_begin_frame_sequence_number_pending_tree_was_fresh() const {
178 return last_begin_frame_sequence_number_pending_tree_was_fresh_;
179 }
180 uint64_t last_begin_frame_sequence_number_active_tree_was_fresh() const {
181 return last_begin_frame_sequence_number_active_tree_was_fresh_;
182 }
183
153 using SchedulerStateMachine::ShouldTriggerBeginImplFrameDeadlineImmediately; 184 using SchedulerStateMachine::ShouldTriggerBeginImplFrameDeadlineImmediately;
154 using SchedulerStateMachine::ProactiveBeginFrameWanted; 185 using SchedulerStateMachine::ProactiveBeginFrameWanted;
155 using SchedulerStateMachine::WillCommit; 186 using SchedulerStateMachine::WillCommit;
156 187
157 protected: 188 protected:
158 DrawResult draw_result_for_test_; 189 DrawResult draw_result_for_test_;
190 uint64_t next_begin_frame_number_ = BeginFrameArgs::kStartingFrameNumber;
159 }; 191 };
160 192
161 void PerformAction(StateMachine* sm, SchedulerStateMachine::Action action) { 193 void PerformAction(StateMachine* sm, SchedulerStateMachine::Action action) {
162 switch (action) { 194 switch (action) {
163 case SchedulerStateMachine::ACTION_NONE: 195 case SchedulerStateMachine::ACTION_NONE:
164 return; 196 return;
165 197
166 case SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE: 198 case SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE:
167 sm->WillActivate(); 199 sm->WillActivate();
168 return; 200 return;
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 SchedulerStateMachine::ACTION_BEGIN_COMPOSITOR_FRAME_SINK_CREATION); 296 SchedulerStateMachine::ACTION_BEGIN_COMPOSITOR_FRAME_SINK_CREATION);
265 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 297 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
266 state.CreateAndInitializeCompositorFrameSinkWithActivatedCommit(); 298 state.CreateAndInitializeCompositorFrameSinkWithActivatedCommit();
267 state.SetBeginMainFrameState( 299 state.SetBeginMainFrameState(
268 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_IDLE); 300 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_IDLE);
269 state.SetNeedsRedraw(false); 301 state.SetNeedsRedraw(false);
270 302
271 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 303 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
272 EXPECT_FALSE(state.NeedsCommit()); 304 EXPECT_FALSE(state.NeedsCommit());
273 305
274 state.OnBeginImplFrame(); 306 state.IssueNextBeginImplFrame();
275 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 307 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
276 308
277 state.OnBeginImplFrameDeadline(); 309 state.OnBeginImplFrameDeadline();
278 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 310 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
279 EXPECT_FALSE(state.NeedsCommit()); 311 EXPECT_FALSE(state.NeedsCommit());
280 } 312 }
281 313
282 // If commit requested but not visible yet, do nothing. 314 // If commit requested but not visible yet, do nothing.
283 { 315 {
284 StateMachine state(default_scheduler_settings); 316 StateMachine state(default_scheduler_settings);
285 state.SetBeginMainFrameState( 317 state.SetBeginMainFrameState(
286 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_IDLE); 318 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_IDLE);
287 state.SetNeedsRedraw(false); 319 state.SetNeedsRedraw(false);
288 state.SetNeedsBeginMainFrame(); 320 state.SetNeedsBeginMainFrame();
289 321
290 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 322 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
291 EXPECT_TRUE(state.NeedsCommit()); 323 EXPECT_TRUE(state.NeedsCommit());
292 324
293 state.OnBeginImplFrame(); 325 state.IssueNextBeginImplFrame();
294 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 326 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
295 327
296 state.OnBeginImplFrameDeadline(); 328 state.OnBeginImplFrameDeadline();
297 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 329 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
298 EXPECT_TRUE(state.NeedsCommit()); 330 EXPECT_TRUE(state.NeedsCommit());
299 } 331 }
300 332
301 // If commit requested, begin a main frame. 333 // If commit requested, begin a main frame.
302 { 334 {
303 StateMachine state(default_scheduler_settings); 335 StateMachine state(default_scheduler_settings);
304 state.SetBeginMainFrameState( 336 state.SetBeginMainFrameState(
305 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_IDLE); 337 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_IDLE);
306 state.SetVisible(true); 338 state.SetVisible(true);
307 EXPECT_ACTION_UPDATE_STATE( 339 EXPECT_ACTION_UPDATE_STATE(
308 SchedulerStateMachine::ACTION_BEGIN_COMPOSITOR_FRAME_SINK_CREATION); 340 SchedulerStateMachine::ACTION_BEGIN_COMPOSITOR_FRAME_SINK_CREATION);
309 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 341 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
310 state.CreateAndInitializeCompositorFrameSinkWithActivatedCommit(); 342 state.CreateAndInitializeCompositorFrameSinkWithActivatedCommit();
311 state.SetNeedsRedraw(false); 343 state.SetNeedsRedraw(false);
312 state.SetNeedsBeginMainFrame(); 344 state.SetNeedsBeginMainFrame();
313 345
314 // Expect nothing to happen until after OnBeginImplFrame. 346 // Expect nothing to happen until after OnBeginImplFrame.
315 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 347 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
316 EXPECT_MAIN_FRAME_STATE(SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_IDLE); 348 EXPECT_MAIN_FRAME_STATE(SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_IDLE);
317 EXPECT_IMPL_FRAME_STATE(SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE); 349 EXPECT_IMPL_FRAME_STATE(SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE);
318 EXPECT_TRUE(state.NeedsCommit()); 350 EXPECT_TRUE(state.NeedsCommit());
319 EXPECT_TRUE(state.BeginFrameNeeded()); 351 EXPECT_TRUE(state.BeginFrameNeeded());
320 352
321 state.OnBeginImplFrame(); 353 state.IssueNextBeginImplFrame();
322 EXPECT_ACTION_UPDATE_STATE( 354 EXPECT_ACTION_UPDATE_STATE(
323 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 355 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
324 EXPECT_MAIN_FRAME_STATE(SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_SENT); 356 EXPECT_MAIN_FRAME_STATE(SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_SENT);
325 EXPECT_FALSE(state.NeedsCommit()); 357 EXPECT_FALSE(state.NeedsCommit());
326 } 358 }
327 359
328 // If commit requested and can't draw, still begin a main frame. 360 // If commit requested and can't draw, still begin a main frame.
329 { 361 {
330 StateMachine state(default_scheduler_settings); 362 StateMachine state(default_scheduler_settings);
331 state.SetBeginMainFrameState( 363 state.SetBeginMainFrameState(
332 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_IDLE); 364 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_IDLE);
333 state.SetVisible(true); 365 state.SetVisible(true);
334 EXPECT_ACTION_UPDATE_STATE( 366 EXPECT_ACTION_UPDATE_STATE(
335 SchedulerStateMachine::ACTION_BEGIN_COMPOSITOR_FRAME_SINK_CREATION); 367 SchedulerStateMachine::ACTION_BEGIN_COMPOSITOR_FRAME_SINK_CREATION);
336 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 368 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
337 state.CreateAndInitializeCompositorFrameSinkWithActivatedCommit(); 369 state.CreateAndInitializeCompositorFrameSinkWithActivatedCommit();
338 state.SetNeedsRedraw(false); 370 state.SetNeedsRedraw(false);
339 state.SetNeedsBeginMainFrame(); 371 state.SetNeedsBeginMainFrame();
340 state.SetCanDraw(false); 372 state.SetCanDraw(false);
341 373
342 // Expect nothing to happen until after OnBeginImplFrame. 374 // Expect nothing to happen until after OnBeginImplFrame.
343 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 375 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
344 EXPECT_MAIN_FRAME_STATE(SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_IDLE); 376 EXPECT_MAIN_FRAME_STATE(SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_IDLE);
345 EXPECT_IMPL_FRAME_STATE(SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE); 377 EXPECT_IMPL_FRAME_STATE(SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE);
346 EXPECT_TRUE(state.BeginFrameNeeded()); 378 EXPECT_TRUE(state.BeginFrameNeeded());
347 379
348 state.OnBeginImplFrame(); 380 state.IssueNextBeginImplFrame();
349 EXPECT_ACTION_UPDATE_STATE( 381 EXPECT_ACTION_UPDATE_STATE(
350 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 382 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
351 EXPECT_MAIN_FRAME_STATE(SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_SENT); 383 EXPECT_MAIN_FRAME_STATE(SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_SENT);
352 EXPECT_FALSE(state.NeedsCommit()); 384 EXPECT_FALSE(state.NeedsCommit());
353 } 385 }
354 } 386 }
355 387
356 // Explicitly test main_frame_before_activation_enabled = true 388 // Explicitly test main_frame_before_activation_enabled = true
357 TEST(SchedulerStateMachineTest, MainFrameBeforeActivationEnabled) { 389 TEST(SchedulerStateMachineTest, MainFrameBeforeActivationEnabled) {
358 SchedulerSettings scheduler_settings; 390 SchedulerSettings scheduler_settings;
359 scheduler_settings.main_frame_before_activation_enabled = true; 391 scheduler_settings.main_frame_before_activation_enabled = true;
360 StateMachine state(scheduler_settings); 392 StateMachine state(scheduler_settings);
361 state.SetBeginMainFrameState( 393 state.SetBeginMainFrameState(
362 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_IDLE); 394 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_IDLE);
363 SET_UP_STATE(state) 395 SET_UP_STATE(state)
364 state.SetNeedsRedraw(false); 396 state.SetNeedsRedraw(false);
365 state.SetNeedsBeginMainFrame(); 397 state.SetNeedsBeginMainFrame();
366 398
367 EXPECT_TRUE(state.BeginFrameNeeded()); 399 EXPECT_TRUE(state.BeginFrameNeeded());
368 400
369 // Commit to the pending tree. 401 // Commit to the pending tree.
370 state.OnBeginImplFrame(); 402 state.IssueNextBeginImplFrame();
371 EXPECT_ACTION_UPDATE_STATE( 403 EXPECT_ACTION_UPDATE_STATE(
372 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 404 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
373 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 405 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
374 406
375 state.NotifyBeginMainFrameStarted(); 407 state.NotifyBeginMainFrameStarted();
376 state.NotifyReadyToCommit(); 408 state.NotifyReadyToCommit();
377 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 409 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
378 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 410 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
379 EXPECT_MAIN_FRAME_STATE(SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_IDLE); 411 EXPECT_MAIN_FRAME_STATE(SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_IDLE);
380 412
381 state.OnBeginImplFrameDeadline(); 413 state.OnBeginImplFrameDeadline();
382 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 414 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
383 415
384 // Verify that the next commit starts while there is still a pending tree. 416 // Verify that the next commit starts while there is still a pending tree.
385 state.SetNeedsBeginMainFrame(); 417 state.SetNeedsBeginMainFrame();
386 state.OnBeginImplFrame(); 418 state.IssueNextBeginImplFrame();
387 EXPECT_ACTION_UPDATE_STATE( 419 EXPECT_ACTION_UPDATE_STATE(
388 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 420 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
389 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 421 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
390 422
391 // Verify the pending commit doesn't overwrite the pending 423 // Verify the pending commit doesn't overwrite the pending
392 // tree until the pending tree has been activated. 424 // tree until the pending tree has been activated.
393 state.NotifyBeginMainFrameStarted(); 425 state.NotifyBeginMainFrameStarted();
394 state.NotifyReadyToCommit(); 426 state.NotifyReadyToCommit();
395 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 427 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
396 428
(...skipping 16 matching lines...) Expand all
413 TEST(SchedulerStateMachineTest, 445 TEST(SchedulerStateMachineTest,
414 FailedDrawForAnimationCheckerboardSetsNeedsCommitAndRetriesDraw) { 446 FailedDrawForAnimationCheckerboardSetsNeedsCommitAndRetriesDraw) {
415 SchedulerSettings default_scheduler_settings; 447 SchedulerSettings default_scheduler_settings;
416 StateMachine state(default_scheduler_settings); 448 StateMachine state(default_scheduler_settings);
417 SET_UP_STATE(state) 449 SET_UP_STATE(state)
418 state.SetNeedsRedraw(true); 450 state.SetNeedsRedraw(true);
419 EXPECT_TRUE(state.RedrawPending()); 451 EXPECT_TRUE(state.RedrawPending());
420 EXPECT_TRUE(state.BeginFrameNeeded()); 452 EXPECT_TRUE(state.BeginFrameNeeded());
421 453
422 // Start a frame. 454 // Start a frame.
423 state.OnBeginImplFrame(); 455 state.IssueNextBeginImplFrame();
424 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 456 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
425 EXPECT_FALSE(state.CommitPending()); 457 EXPECT_FALSE(state.CommitPending());
426 458
427 // Failing a draw triggers request for a new BeginMainFrame. 459 // Failing a draw triggers request for a new BeginMainFrame.
428 state.OnBeginImplFrameDeadline(); 460 state.OnBeginImplFrameDeadline();
429 state.SetDrawResultForTest(DRAW_ABORTED_CHECKERBOARD_ANIMATIONS); 461 state.SetDrawResultForTest(DRAW_ABORTED_CHECKERBOARD_ANIMATIONS);
430 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE); 462 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE);
431 EXPECT_ACTION_UPDATE_STATE( 463 EXPECT_ACTION_UPDATE_STATE(
432 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 464 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
433 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 465 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
434 state.OnBeginImplFrameIdle(); 466 state.OnBeginImplFrameIdle();
435 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 467 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
436 468
437 // It's okay to attempt more draws just in case additional raster 469 // It's okay to attempt more draws just in case additional raster
438 // finishes and the requested commit wasn't actually necessary. 470 // finishes and the requested commit wasn't actually necessary.
439 EXPECT_TRUE(state.CommitPending()); 471 EXPECT_TRUE(state.CommitPending());
440 EXPECT_TRUE(state.RedrawPending()); 472 EXPECT_TRUE(state.RedrawPending());
441 state.OnBeginImplFrame(); 473 state.IssueNextBeginImplFrame();
442 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 474 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
443 state.OnBeginImplFrameDeadline(); 475 state.OnBeginImplFrameDeadline();
444 state.SetDrawResultForTest(DRAW_ABORTED_CHECKERBOARD_ANIMATIONS); 476 state.SetDrawResultForTest(DRAW_ABORTED_CHECKERBOARD_ANIMATIONS);
445 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE); 477 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE);
446 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 478 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
447 state.OnBeginImplFrameIdle(); 479 state.OnBeginImplFrameIdle();
448 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 480 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
449 } 481 }
450 482
451 TEST(SchedulerStateMachineTest, FailedDrawForMissingHighResNeedsCommit) { 483 TEST(SchedulerStateMachineTest, FailedDrawForMissingHighResNeedsCommit) {
452 SchedulerSettings default_scheduler_settings; 484 SchedulerSettings default_scheduler_settings;
453 StateMachine state(default_scheduler_settings); 485 StateMachine state(default_scheduler_settings);
454 SET_UP_STATE(state) 486 SET_UP_STATE(state)
455 state.SetNeedsRedraw(true); 487 state.SetNeedsRedraw(true);
456 EXPECT_TRUE(state.RedrawPending()); 488 EXPECT_TRUE(state.RedrawPending());
457 EXPECT_TRUE(state.BeginFrameNeeded()); 489 EXPECT_TRUE(state.BeginFrameNeeded());
458 490
459 // Start a frame. 491 // Start a frame.
460 state.OnBeginImplFrame(); 492 state.IssueNextBeginImplFrame();
461 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 493 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
462 EXPECT_FALSE(state.CommitPending()); 494 EXPECT_FALSE(state.CommitPending());
463 495
464 // Failing a draw triggers because of high res tiles missing 496 // Failing a draw triggers because of high res tiles missing
465 // request for a new BeginMainFrame. 497 // request for a new BeginMainFrame.
466 state.OnBeginImplFrameDeadline(); 498 state.OnBeginImplFrameDeadline();
467 state.SetDrawResultForTest(DRAW_ABORTED_MISSING_HIGH_RES_CONTENT); 499 state.SetDrawResultForTest(DRAW_ABORTED_MISSING_HIGH_RES_CONTENT);
468 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE); 500 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE);
469 EXPECT_ACTION_UPDATE_STATE( 501 EXPECT_ACTION_UPDATE_STATE(
470 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 502 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
471 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 503 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
472 state.OnBeginImplFrameIdle(); 504 state.OnBeginImplFrameIdle();
473 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 505 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
474 506
475 // It doesn't request a draw until we get a new commit though. 507 // It doesn't request a draw until we get a new commit though.
476 EXPECT_TRUE(state.CommitPending()); 508 EXPECT_TRUE(state.CommitPending());
477 EXPECT_FALSE(state.RedrawPending()); 509 EXPECT_FALSE(state.RedrawPending());
478 state.OnBeginImplFrame(); 510 state.IssueNextBeginImplFrame();
479 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 511 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
480 state.OnBeginImplFrameDeadline(); 512 state.OnBeginImplFrameDeadline();
481 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 513 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
482 state.OnBeginImplFrameIdle(); 514 state.OnBeginImplFrameIdle();
483 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 515 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
484 516
485 // Finish the commit and activation. 517 // Finish the commit and activation.
486 state.NotifyBeginMainFrameStarted(); 518 state.NotifyBeginMainFrameStarted();
487 state.NotifyReadyToCommit(); 519 state.NotifyReadyToCommit();
488 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 520 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
489 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 521 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
490 state.NotifyReadyToActivate(); 522 state.NotifyReadyToActivate();
491 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE); 523 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE);
492 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 524 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
493 EXPECT_TRUE(state.RedrawPending()); 525 EXPECT_TRUE(state.RedrawPending());
494 526
495 // Verify we draw with the new frame. 527 // Verify we draw with the new frame.
496 state.OnBeginImplFrame(); 528 state.IssueNextBeginImplFrame();
497 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 529 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
498 state.OnBeginImplFrameDeadline(); 530 state.OnBeginImplFrameDeadline();
499 state.SetDrawResultForTest(DRAW_SUCCESS); 531 state.SetDrawResultForTest(DRAW_SUCCESS);
500 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE); 532 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE);
501 state.DidSubmitCompositorFrame(); 533 state.DidSubmitCompositorFrame();
502 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 534 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
503 state.OnBeginImplFrameIdle(); 535 state.OnBeginImplFrameIdle();
504 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 536 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
505 } 537 }
506 538
507 TEST(SchedulerStateMachineTest, 539 TEST(SchedulerStateMachineTest,
508 TestFailedDrawsEventuallyForceDrawAfterNextCommit) { 540 TestFailedDrawsEventuallyForceDrawAfterNextCommit) {
509 SchedulerSettings scheduler_settings; 541 SchedulerSettings scheduler_settings;
510 scheduler_settings.maximum_number_of_failed_draws_before_draw_is_forced = 1; 542 scheduler_settings.maximum_number_of_failed_draws_before_draw_is_forced = 1;
511 StateMachine state(scheduler_settings); 543 StateMachine state(scheduler_settings);
512 SET_UP_STATE(state) 544 SET_UP_STATE(state)
513 545
514 // Start a commit. 546 // Start a commit.
515 state.SetNeedsBeginMainFrame(); 547 state.SetNeedsBeginMainFrame();
516 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 548 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
517 state.OnBeginImplFrame(); 549 state.IssueNextBeginImplFrame();
518 EXPECT_ACTION_UPDATE_STATE( 550 EXPECT_ACTION_UPDATE_STATE(
519 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 551 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
520 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 552 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
521 EXPECT_TRUE(state.CommitPending()); 553 EXPECT_TRUE(state.CommitPending());
522 554
523 // Then initiate a draw that fails. 555 // Then initiate a draw that fails.
524 state.SetNeedsRedraw(true); 556 state.SetNeedsRedraw(true);
525 state.OnBeginImplFrameDeadline(); 557 state.OnBeginImplFrameDeadline();
526 state.SetDrawResultForTest(DRAW_ABORTED_CHECKERBOARD_ANIMATIONS); 558 state.SetDrawResultForTest(DRAW_ABORTED_CHECKERBOARD_ANIMATIONS);
527 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE); 559 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE);
(...skipping 10 matching lines...) Expand all
538 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 570 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
539 EXPECT_TRUE(state.RedrawPending()); 571 EXPECT_TRUE(state.RedrawPending());
540 572
541 // Activate so we're ready for a new main frame. 573 // Activate so we're ready for a new main frame.
542 state.NotifyReadyToActivate(); 574 state.NotifyReadyToActivate();
543 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE); 575 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE);
544 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 576 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
545 EXPECT_TRUE(state.RedrawPending()); 577 EXPECT_TRUE(state.RedrawPending());
546 578
547 // The redraw should be forced at the end of the next BeginImplFrame. 579 // The redraw should be forced at the end of the next BeginImplFrame.
548 state.OnBeginImplFrame(); 580 state.IssueNextBeginImplFrame();
549 EXPECT_ACTION_UPDATE_STATE( 581 EXPECT_ACTION_UPDATE_STATE(
550 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 582 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
551 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 583 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
552 state.OnBeginImplFrameDeadline(); 584 state.OnBeginImplFrameDeadline();
553 state.SetDrawResultForTest(DRAW_SUCCESS); 585 state.SetDrawResultForTest(DRAW_SUCCESS);
554 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_FORCED); 586 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_FORCED);
555 state.DidSubmitCompositorFrame(); 587 state.DidSubmitCompositorFrame();
556 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 588 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
557 state.DidReceiveCompositorFrameAck(); 589 state.DidReceiveCompositorFrameAck();
558 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 590 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
559 } 591 }
560 592
561 TEST(SchedulerStateMachineTest, TestFailedDrawsDoNotRestartForcedDraw) { 593 TEST(SchedulerStateMachineTest, TestFailedDrawsDoNotRestartForcedDraw) {
562 SchedulerSettings scheduler_settings; 594 SchedulerSettings scheduler_settings;
563 int draw_limit = 2; 595 int draw_limit = 2;
564 scheduler_settings.maximum_number_of_failed_draws_before_draw_is_forced = 596 scheduler_settings.maximum_number_of_failed_draws_before_draw_is_forced =
565 draw_limit; 597 draw_limit;
566 StateMachine state(scheduler_settings); 598 StateMachine state(scheduler_settings);
567 SET_UP_STATE(state) 599 SET_UP_STATE(state)
568 600
569 // Start a commit. 601 // Start a commit.
570 state.SetNeedsBeginMainFrame(); 602 state.SetNeedsBeginMainFrame();
571 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 603 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
572 state.OnBeginImplFrame(); 604 state.IssueNextBeginImplFrame();
573 EXPECT_ACTION_UPDATE_STATE( 605 EXPECT_ACTION_UPDATE_STATE(
574 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 606 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
575 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 607 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
576 EXPECT_TRUE(state.CommitPending()); 608 EXPECT_TRUE(state.CommitPending());
577 609
578 // Then initiate a draw. 610 // Then initiate a draw.
579 state.SetNeedsRedraw(true); 611 state.SetNeedsRedraw(true);
580 state.OnBeginImplFrameDeadline(); 612 state.OnBeginImplFrameDeadline();
581 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE); 613 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE);
582 614
583 // Fail the draw enough times to force a redraw. 615 // Fail the draw enough times to force a redraw.
584 for (int i = 0; i < draw_limit; ++i) { 616 for (int i = 0; i < draw_limit; ++i) {
585 state.SetNeedsRedraw(true); 617 state.SetNeedsRedraw(true);
586 state.OnBeginImplFrame(); 618 state.IssueNextBeginImplFrame();
587 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 619 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
588 state.OnBeginImplFrameDeadline(); 620 state.OnBeginImplFrameDeadline();
589 state.SetDrawResultForTest(DRAW_ABORTED_CHECKERBOARD_ANIMATIONS); 621 state.SetDrawResultForTest(DRAW_ABORTED_CHECKERBOARD_ANIMATIONS);
590 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE); 622 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE);
591 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 623 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
592 state.OnBeginImplFrameIdle(); 624 state.OnBeginImplFrameIdle();
593 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 625 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
594 } 626 }
595 627
596 EXPECT_TRUE(state.BeginFrameNeeded()); 628 EXPECT_TRUE(state.BeginFrameNeeded());
597 EXPECT_TRUE(state.RedrawPending()); 629 EXPECT_TRUE(state.RedrawPending());
598 // But the commit is ongoing. 630 // But the commit is ongoing.
599 EXPECT_TRUE(state.CommitPending()); 631 EXPECT_TRUE(state.CommitPending());
600 EXPECT_TRUE(state.ForcedRedrawState() == 632 EXPECT_TRUE(state.ForcedRedrawState() ==
601 SchedulerStateMachine::FORCED_REDRAW_STATE_WAITING_FOR_COMMIT); 633 SchedulerStateMachine::FORCED_REDRAW_STATE_WAITING_FOR_COMMIT);
602 634
603 // After failing additional draws, we should still be in a forced 635 // After failing additional draws, we should still be in a forced
604 // redraw, but not back in IDLE. 636 // redraw, but not back in IDLE.
605 for (int i = 0; i < draw_limit; ++i) { 637 for (int i = 0; i < draw_limit; ++i) {
606 state.SetNeedsRedraw(true); 638 state.SetNeedsRedraw(true);
607 state.OnBeginImplFrame(); 639 state.IssueNextBeginImplFrame();
608 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 640 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
609 state.OnBeginImplFrameDeadline(); 641 state.OnBeginImplFrameDeadline();
610 state.SetDrawResultForTest(DRAW_ABORTED_CHECKERBOARD_ANIMATIONS); 642 state.SetDrawResultForTest(DRAW_ABORTED_CHECKERBOARD_ANIMATIONS);
611 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE); 643 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE);
612 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 644 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
613 state.OnBeginImplFrameIdle(); 645 state.OnBeginImplFrameIdle();
614 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 646 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
615 } 647 }
616 EXPECT_TRUE(state.RedrawPending()); 648 EXPECT_TRUE(state.RedrawPending());
617 EXPECT_TRUE(state.ForcedRedrawState() == 649 EXPECT_TRUE(state.ForcedRedrawState() ==
618 SchedulerStateMachine::FORCED_REDRAW_STATE_WAITING_FOR_COMMIT); 650 SchedulerStateMachine::FORCED_REDRAW_STATE_WAITING_FOR_COMMIT);
619 } 651 }
620 652
621 TEST(SchedulerStateMachineTest, TestFailedDrawIsRetriedInNextBeginImplFrame) { 653 TEST(SchedulerStateMachineTest, TestFailedDrawIsRetriedInNextBeginImplFrame) {
622 SchedulerSettings default_scheduler_settings; 654 SchedulerSettings default_scheduler_settings;
623 StateMachine state(default_scheduler_settings); 655 StateMachine state(default_scheduler_settings);
624 SET_UP_STATE(state) 656 SET_UP_STATE(state)
625 657
626 // Start a draw. 658 // Start a draw.
627 state.SetNeedsRedraw(true); 659 state.SetNeedsRedraw(true);
628 EXPECT_TRUE(state.BeginFrameNeeded()); 660 EXPECT_TRUE(state.BeginFrameNeeded());
629 state.OnBeginImplFrame(); 661 state.IssueNextBeginImplFrame();
630 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 662 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
631 state.OnBeginImplFrameDeadline(); 663 state.OnBeginImplFrameDeadline();
632 EXPECT_TRUE(state.RedrawPending()); 664 EXPECT_TRUE(state.RedrawPending());
633 state.SetDrawResultForTest(DRAW_ABORTED_CHECKERBOARD_ANIMATIONS); 665 state.SetDrawResultForTest(DRAW_ABORTED_CHECKERBOARD_ANIMATIONS);
634 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE); 666 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE);
635 667
636 // Failing the draw for animation checkerboards makes us require a commit. 668 // Failing the draw for animation checkerboards makes us require a commit.
637 EXPECT_ACTION_UPDATE_STATE( 669 EXPECT_ACTION_UPDATE_STATE(
638 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 670 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
639 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 671 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
640 EXPECT_TRUE(state.RedrawPending()); 672 EXPECT_TRUE(state.RedrawPending());
641 673
642 // We should not be trying to draw again now, but we have a commit pending. 674 // We should not be trying to draw again now, but we have a commit pending.
643 EXPECT_TRUE(state.BeginFrameNeeded()); 675 EXPECT_TRUE(state.BeginFrameNeeded());
644 state.OnBeginImplFrame(); 676 state.IssueNextBeginImplFrame();
645 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 677 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
646 678
647 // We should try to draw again at the end of the next BeginImplFrame on 679 // We should try to draw again at the end of the next BeginImplFrame on
648 // the impl thread. 680 // the impl thread.
649 state.OnBeginImplFrameDeadline(); 681 state.OnBeginImplFrameDeadline();
650 state.SetDrawResultForTest(DRAW_SUCCESS); 682 state.SetDrawResultForTest(DRAW_SUCCESS);
651 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE); 683 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE);
652 state.DidSubmitCompositorFrame(); 684 state.DidSubmitCompositorFrame();
653 state.DidReceiveCompositorFrameAck(); 685 state.DidReceiveCompositorFrameAck();
654 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 686 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
655 } 687 }
656 688
657 TEST(SchedulerStateMachineTest, TestDoestDrawTwiceInSameFrame) { 689 TEST(SchedulerStateMachineTest, TestDoestDrawTwiceInSameFrame) {
658 SchedulerSettings default_scheduler_settings; 690 SchedulerSettings default_scheduler_settings;
659 StateMachine state(default_scheduler_settings); 691 StateMachine state(default_scheduler_settings);
660 SET_UP_STATE(state) 692 SET_UP_STATE(state)
661 state.SetNeedsRedraw(true); 693 state.SetNeedsRedraw(true);
662 694
663 // Draw the first frame. 695 // Draw the first frame.
664 EXPECT_TRUE(state.BeginFrameNeeded()); 696 EXPECT_TRUE(state.BeginFrameNeeded());
665 state.OnBeginImplFrame(); 697 state.IssueNextBeginImplFrame();
666 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 698 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
667 699
668 state.OnBeginImplFrameDeadline(); 700 state.OnBeginImplFrameDeadline();
669 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE); 701 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE);
670 state.DidSubmitCompositorFrame(); 702 state.DidSubmitCompositorFrame();
671 state.DidReceiveCompositorFrameAck(); 703 state.DidReceiveCompositorFrameAck();
672 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 704 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
673 705
674 // Before the next BeginImplFrame, set needs redraw again. 706 // Before the next BeginImplFrame, set needs redraw again.
675 // This should not redraw until the next BeginImplFrame. 707 // This should not redraw until the next BeginImplFrame.
676 state.SetNeedsRedraw(true); 708 state.SetNeedsRedraw(true);
677 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 709 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
678 710
679 // Move to another frame. This should now draw. 711 // Move to another frame. This should now draw.
680 EXPECT_TRUE(state.BeginFrameNeeded()); 712 EXPECT_TRUE(state.BeginFrameNeeded());
681 state.OnBeginImplFrame(); 713 state.IssueNextBeginImplFrame();
682 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 714 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
683 state.OnBeginImplFrameDeadline(); 715 state.OnBeginImplFrameDeadline();
684 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE); 716 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE);
685 state.DidSubmitCompositorFrame(); 717 state.DidSubmitCompositorFrame();
686 state.DidReceiveCompositorFrameAck(); 718 state.DidReceiveCompositorFrameAck();
687 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 719 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
688 720
689 // We just submitted, so we should proactively request another BeginImplFrame. 721 // We just submitted, so we should proactively request another BeginImplFrame.
690 EXPECT_TRUE(state.BeginFrameNeeded()); 722 EXPECT_TRUE(state.BeginFrameNeeded());
691 } 723 }
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
809 StateMachine state(default_scheduler_settings); 841 StateMachine state(default_scheduler_settings);
810 state.SetVisible(true); 842 state.SetVisible(true);
811 EXPECT_ACTION_UPDATE_STATE( 843 EXPECT_ACTION_UPDATE_STATE(
812 SchedulerStateMachine::ACTION_BEGIN_COMPOSITOR_FRAME_SINK_CREATION); 844 SchedulerStateMachine::ACTION_BEGIN_COMPOSITOR_FRAME_SINK_CREATION);
813 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 845 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
814 state.CreateAndInitializeCompositorFrameSinkWithActivatedCommit(); 846 state.CreateAndInitializeCompositorFrameSinkWithActivatedCommit();
815 state.SetBeginMainFrameState(begin_main_frame_states[i]); 847 state.SetBeginMainFrameState(begin_main_frame_states[i]);
816 state.SetVisible(false); 848 state.SetVisible(false);
817 state.SetNeedsRedraw(true); 849 state.SetNeedsRedraw(true);
818 if (j == 1) 850 if (j == 1)
819 state.OnBeginImplFrame(); 851 state.IssueNextBeginImplFrame();
820 852
821 state.SetCanDraw(false); 853 state.SetCanDraw(false);
822 EXPECT_NE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, 854 EXPECT_NE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE,
823 state.NextAction()); 855 state.NextAction());
824 } 856 }
825 } 857 }
826 } 858 }
827 859
828 TEST(SchedulerStateMachineTest, 860 TEST(SchedulerStateMachineTest,
829 TestCanRedrawWithWaitingForFirstDrawMakesProgress) { 861 TestCanRedrawWithWaitingForFirstDrawMakesProgress) {
830 SchedulerSettings default_scheduler_settings; 862 SchedulerSettings default_scheduler_settings;
831 StateMachine state(default_scheduler_settings); 863 StateMachine state(default_scheduler_settings);
832 state.SetVisible(true); 864 state.SetVisible(true);
833 EXPECT_ACTION_UPDATE_STATE( 865 EXPECT_ACTION_UPDATE_STATE(
834 SchedulerStateMachine::ACTION_BEGIN_COMPOSITOR_FRAME_SINK_CREATION); 866 SchedulerStateMachine::ACTION_BEGIN_COMPOSITOR_FRAME_SINK_CREATION);
835 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 867 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
836 state.CreateAndInitializeCompositorFrameSinkWithActivatedCommit(); 868 state.CreateAndInitializeCompositorFrameSinkWithActivatedCommit();
837 869
838 state.SetActiveTreeNeedsFirstDraw(true); 870 state.SetActiveTreeNeedsFirstDraw(true);
839 state.SetNeedsBeginMainFrame(); 871 state.SetNeedsBeginMainFrame();
840 state.SetNeedsRedraw(true); 872 state.SetNeedsRedraw(true);
841 state.SetCanDraw(false); 873 state.SetCanDraw(false);
842 state.OnBeginImplFrame(); 874 state.IssueNextBeginImplFrame();
843 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_ABORT); 875 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_ABORT);
844 EXPECT_ACTION_UPDATE_STATE( 876 EXPECT_ACTION_UPDATE_STATE(
845 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 877 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
846 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 878 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
847 state.NotifyBeginMainFrameStarted(); 879 state.NotifyBeginMainFrameStarted();
848 state.NotifyReadyToCommit(); 880 state.NotifyReadyToCommit();
849 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 881 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
850 state.NotifyReadyToActivate(); 882 state.NotifyReadyToActivate();
851 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE); 883 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE);
852 state.OnBeginImplFrameDeadline(); 884 state.OnBeginImplFrameDeadline();
853 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_ABORT); 885 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_ABORT);
854 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 886 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
855 } 887 }
856 888
857 TEST(SchedulerStateMachineTest, TestSetNeedsBeginMainFrameIsNotLost) { 889 TEST(SchedulerStateMachineTest, TestSetNeedsBeginMainFrameIsNotLost) {
858 SchedulerSettings scheduler_settings; 890 SchedulerSettings scheduler_settings;
859 StateMachine state(scheduler_settings); 891 StateMachine state(scheduler_settings);
860 SET_UP_STATE(state) 892 SET_UP_STATE(state)
861 state.SetNeedsBeginMainFrame(); 893 state.SetNeedsBeginMainFrame();
862 894
863 EXPECT_TRUE(state.BeginFrameNeeded()); 895 EXPECT_TRUE(state.BeginFrameNeeded());
864 896
865 // Begin the frame. 897 // Begin the frame.
866 state.OnBeginImplFrame(); 898 state.IssueNextBeginImplFrame();
867 EXPECT_ACTION_UPDATE_STATE( 899 EXPECT_ACTION_UPDATE_STATE(
868 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 900 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
869 EXPECT_MAIN_FRAME_STATE(SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_SENT); 901 EXPECT_MAIN_FRAME_STATE(SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_SENT);
870 902
871 // Now, while the frame is in progress, set another commit. 903 // Now, while the frame is in progress, set another commit.
872 state.SetNeedsBeginMainFrame(); 904 state.SetNeedsBeginMainFrame();
873 EXPECT_TRUE(state.NeedsCommit()); 905 EXPECT_TRUE(state.NeedsCommit());
874 906
875 // Let the frame finish. 907 // Let the frame finish.
876 state.NotifyBeginMainFrameStarted(); 908 state.NotifyBeginMainFrameStarted();
877 state.NotifyReadyToCommit(); 909 state.NotifyReadyToCommit();
878 EXPECT_MAIN_FRAME_STATE( 910 EXPECT_MAIN_FRAME_STATE(
879 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_READY_TO_COMMIT); 911 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_READY_TO_COMMIT);
880 912
881 // Expect to commit regardless of BeginImplFrame state. 913 // Expect to commit regardless of BeginImplFrame state.
882 EXPECT_IMPL_FRAME_STATE( 914 EXPECT_IMPL_FRAME_STATE(
883 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_BEGIN_FRAME); 915 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_BEGIN_FRAME);
884 EXPECT_ACTION(SchedulerStateMachine::ACTION_COMMIT); 916 EXPECT_ACTION(SchedulerStateMachine::ACTION_COMMIT);
885 917
886 state.OnBeginImplFrameDeadline(); 918 state.OnBeginImplFrameDeadline();
887 EXPECT_IMPL_FRAME_STATE( 919 EXPECT_IMPL_FRAME_STATE(
888 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE); 920 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE);
889 EXPECT_ACTION(SchedulerStateMachine::ACTION_COMMIT); 921 EXPECT_ACTION(SchedulerStateMachine::ACTION_COMMIT);
890 922
891 state.OnBeginImplFrameIdle(); 923 state.OnBeginImplFrameIdle();
892 EXPECT_IMPL_FRAME_STATE(SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE); 924 EXPECT_IMPL_FRAME_STATE(SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE);
893 EXPECT_ACTION(SchedulerStateMachine::ACTION_COMMIT); 925 EXPECT_ACTION(SchedulerStateMachine::ACTION_COMMIT);
894 926
895 state.OnBeginImplFrame(); 927 state.IssueNextBeginImplFrame();
896 EXPECT_IMPL_FRAME_STATE( 928 EXPECT_IMPL_FRAME_STATE(
897 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_BEGIN_FRAME); 929 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_BEGIN_FRAME);
898 EXPECT_ACTION(SchedulerStateMachine::ACTION_COMMIT); 930 EXPECT_ACTION(SchedulerStateMachine::ACTION_COMMIT);
899 931
900 // Finish the commit and activate, then make sure we start the next commit 932 // Finish the commit and activate, then make sure we start the next commit
901 // immediately and draw on the next BeginImplFrame. 933 // immediately and draw on the next BeginImplFrame.
902 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 934 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
903 state.NotifyReadyToActivate(); 935 state.NotifyReadyToActivate();
904 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE); 936 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE);
905 EXPECT_ACTION_UPDATE_STATE( 937 EXPECT_ACTION_UPDATE_STATE(
(...skipping 11 matching lines...) Expand all
917 949
918 TEST(SchedulerStateMachineTest, TestFullCycle) { 950 TEST(SchedulerStateMachineTest, TestFullCycle) {
919 SchedulerSettings default_scheduler_settings; 951 SchedulerSettings default_scheduler_settings;
920 StateMachine state(default_scheduler_settings); 952 StateMachine state(default_scheduler_settings);
921 SET_UP_STATE(state) 953 SET_UP_STATE(state)
922 954
923 // Start clean and set commit. 955 // Start clean and set commit.
924 state.SetNeedsBeginMainFrame(); 956 state.SetNeedsBeginMainFrame();
925 957
926 // Begin the frame. 958 // Begin the frame.
927 state.OnBeginImplFrame(); 959 state.IssueNextBeginImplFrame();
928 EXPECT_ACTION_UPDATE_STATE( 960 EXPECT_ACTION_UPDATE_STATE(
929 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 961 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
930 EXPECT_MAIN_FRAME_STATE(SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_SENT); 962 EXPECT_MAIN_FRAME_STATE(SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_SENT);
931 EXPECT_FALSE(state.NeedsCommit()); 963 EXPECT_FALSE(state.NeedsCommit());
932 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 964 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
933 965
934 // Tell the scheduler the frame finished. 966 // Tell the scheduler the frame finished.
935 state.NotifyBeginMainFrameStarted(); 967 state.NotifyBeginMainFrameStarted();
936 state.NotifyReadyToCommit(); 968 state.NotifyReadyToCommit();
937 EXPECT_MAIN_FRAME_STATE( 969 EXPECT_MAIN_FRAME_STATE(
(...skipping 25 matching lines...) Expand all
963 995
964 TEST(SchedulerStateMachineTest, CommitWithoutDrawWithPendingTree) { 996 TEST(SchedulerStateMachineTest, CommitWithoutDrawWithPendingTree) {
965 SchedulerSettings default_scheduler_settings; 997 SchedulerSettings default_scheduler_settings;
966 StateMachine state(default_scheduler_settings); 998 StateMachine state(default_scheduler_settings);
967 SET_UP_STATE(state) 999 SET_UP_STATE(state)
968 1000
969 // Start clean and set commit. 1001 // Start clean and set commit.
970 state.SetNeedsBeginMainFrame(); 1002 state.SetNeedsBeginMainFrame();
971 1003
972 // Make a main frame, commit and activate it. But don't draw it. 1004 // Make a main frame, commit and activate it. But don't draw it.
973 state.OnBeginImplFrame(); 1005 state.IssueNextBeginImplFrame();
974 EXPECT_ACTION_UPDATE_STATE( 1006 EXPECT_ACTION_UPDATE_STATE(
975 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 1007 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
976 state.NotifyBeginMainFrameStarted(); 1008 state.NotifyBeginMainFrameStarted();
977 state.NotifyReadyToCommit(); 1009 state.NotifyReadyToCommit();
978 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 1010 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
979 state.NotifyReadyToActivate(); 1011 state.NotifyReadyToActivate();
980 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE); 1012 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE);
981 1013
982 // Try to make a new main frame before drawing. Since we will commit it to a 1014 // Try to make a new main frame before drawing. Since we will commit it to a
983 // pending tree and not clobber the active tree, we're able to start a new 1015 // pending tree and not clobber the active tree, we're able to start a new
984 // begin frame and commit it. 1016 // begin frame and commit it.
985 state.SetNeedsBeginMainFrame(); 1017 state.SetNeedsBeginMainFrame();
986 state.OnBeginImplFrame(); 1018 state.IssueNextBeginImplFrame();
987 EXPECT_ACTION_UPDATE_STATE( 1019 EXPECT_ACTION_UPDATE_STATE(
988 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 1020 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
989 state.NotifyBeginMainFrameStarted(); 1021 state.NotifyBeginMainFrameStarted();
990 state.NotifyReadyToCommit(); 1022 state.NotifyReadyToCommit();
991 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 1023 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
992 } 1024 }
993 1025
994 TEST(SchedulerStateMachineTest, DontCommitWithoutDrawWithoutPendingTree) { 1026 TEST(SchedulerStateMachineTest, DontCommitWithoutDrawWithoutPendingTree) {
995 SchedulerSettings scheduler_settings; 1027 SchedulerSettings scheduler_settings;
996 scheduler_settings.commit_to_active_tree = true; 1028 scheduler_settings.commit_to_active_tree = true;
997 scheduler_settings.main_frame_before_activation_enabled = false; 1029 scheduler_settings.main_frame_before_activation_enabled = false;
998 StateMachine state(scheduler_settings); 1030 StateMachine state(scheduler_settings);
999 SET_UP_STATE(state) 1031 SET_UP_STATE(state)
1000 1032
1001 // Start clean and set commit. 1033 // Start clean and set commit.
1002 state.SetNeedsBeginMainFrame(); 1034 state.SetNeedsBeginMainFrame();
1003 1035
1004 // Make a main frame, commit and activate it. But don't draw it. 1036 // Make a main frame, commit and activate it. But don't draw it.
1005 state.OnBeginImplFrame(); 1037 state.IssueNextBeginImplFrame();
1006 EXPECT_ACTION_UPDATE_STATE( 1038 EXPECT_ACTION_UPDATE_STATE(
1007 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 1039 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
1008 state.NotifyBeginMainFrameStarted(); 1040 state.NotifyBeginMainFrameStarted();
1009 state.NotifyReadyToCommit(); 1041 state.NotifyReadyToCommit();
1010 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 1042 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
1011 state.NotifyReadyToActivate(); 1043 state.NotifyReadyToActivate();
1012 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE); 1044 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE);
1013 1045
1014 // Try to make a new main frame before drawing, but since we would clobber the 1046 // Try to make a new main frame before drawing, but since we would clobber the
1015 // active tree, we will not do so. 1047 // active tree, we will not do so.
1016 state.SetNeedsBeginMainFrame(); 1048 state.SetNeedsBeginMainFrame();
1017 state.OnBeginImplFrame(); 1049 state.IssueNextBeginImplFrame();
1018 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1050 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1019 } 1051 }
1020 1052
1021 TEST(SchedulerStateMachineTest, AbortedMainFrameDoesNotResetPendingTree) { 1053 TEST(SchedulerStateMachineTest, AbortedMainFrameDoesNotResetPendingTree) {
1022 SchedulerSettings scheduler_settings; 1054 SchedulerSettings scheduler_settings;
1023 scheduler_settings.main_frame_before_activation_enabled = true; 1055 scheduler_settings.main_frame_before_activation_enabled = true;
1024 StateMachine state(scheduler_settings); 1056 StateMachine state(scheduler_settings);
1025 SET_UP_STATE(state); 1057 SET_UP_STATE(state);
1026 1058
1027 // Perform a commit so that we have an active tree. 1059 // Perform a commit so that we have an active tree.
1028 state.SetNeedsBeginMainFrame(); 1060 state.SetNeedsBeginMainFrame();
1029 state.OnBeginImplFrame(); 1061 state.IssueNextBeginImplFrame();
1030 EXPECT_ACTION_UPDATE_STATE( 1062 EXPECT_ACTION_UPDATE_STATE(
1031 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 1063 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
1032 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1064 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1033 state.NotifyBeginMainFrameStarted(); 1065 state.NotifyBeginMainFrameStarted();
1034 state.NotifyReadyToCommit(); 1066 state.NotifyReadyToCommit();
1035 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 1067 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
1036 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1068 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1037 EXPECT_TRUE(state.has_pending_tree()); 1069 EXPECT_TRUE(state.has_pending_tree());
1038 state.OnBeginImplFrameDeadline(); 1070 state.OnBeginImplFrameDeadline();
1039 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1071 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1040 1072
1041 // Ask for another commit but abort it. Verify that we didn't reset pending 1073 // Ask for another commit but abort it. Verify that we didn't reset pending
1042 // tree state. 1074 // tree state.
1043 state.SetNeedsBeginMainFrame(); 1075 state.SetNeedsBeginMainFrame();
1044 state.OnBeginImplFrame(); 1076 state.IssueNextBeginImplFrame();
1045 EXPECT_ACTION_UPDATE_STATE( 1077 EXPECT_ACTION_UPDATE_STATE(
1046 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 1078 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
1047 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1079 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1048 EXPECT_TRUE(state.has_pending_tree()); 1080 EXPECT_TRUE(state.has_pending_tree());
1049 state.NotifyBeginMainFrameStarted(); 1081 state.NotifyBeginMainFrameStarted();
1050 state.BeginMainFrameAborted(CommitEarlyOutReason::FINISHED_NO_UPDATES); 1082 state.BeginMainFrameAborted(CommitEarlyOutReason::FINISHED_NO_UPDATES);
1051 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1083 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1052 EXPECT_TRUE(state.has_pending_tree()); 1084 EXPECT_TRUE(state.has_pending_tree());
1053 state.OnBeginImplFrameDeadline(); 1085 state.OnBeginImplFrameDeadline();
1054 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1086 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1055 1087
1056 // Ask for another commit that doesn't abort. 1088 // Ask for another commit that doesn't abort.
1057 state.SetNeedsBeginMainFrame(); 1089 state.SetNeedsBeginMainFrame();
1058 state.OnBeginImplFrame(); 1090 state.IssueNextBeginImplFrame();
1059 EXPECT_ACTION_UPDATE_STATE( 1091 EXPECT_ACTION_UPDATE_STATE(
1060 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 1092 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
1061 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1093 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1062 state.NotifyBeginMainFrameStarted(); 1094 state.NotifyBeginMainFrameStarted();
1063 state.NotifyReadyToCommit(); 1095 state.NotifyReadyToCommit();
1064 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1096 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1065 EXPECT_TRUE(state.has_pending_tree()); 1097 EXPECT_TRUE(state.has_pending_tree());
1066 1098
1067 // Verify that commit is delayed until the pending tree is activated. 1099 // Verify that commit is delayed until the pending tree is activated.
1068 state.NotifyReadyToActivate(); 1100 state.NotifyReadyToActivate();
1069 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE); 1101 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE);
1070 EXPECT_FALSE(state.has_pending_tree()); 1102 EXPECT_FALSE(state.has_pending_tree());
1071 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 1103 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
1072 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1104 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1073 EXPECT_TRUE(state.has_pending_tree()); 1105 EXPECT_TRUE(state.has_pending_tree());
1074 } 1106 }
1075 1107
1076 TEST(SchedulerStateMachineTest, TestFullCycleWithCommitToActive) { 1108 TEST(SchedulerStateMachineTest, TestFullCycleWithCommitToActive) {
1077 SchedulerSettings scheduler_settings; 1109 SchedulerSettings scheduler_settings;
1078 scheduler_settings.commit_to_active_tree = true; 1110 scheduler_settings.commit_to_active_tree = true;
1079 scheduler_settings.main_frame_before_activation_enabled = false; 1111 scheduler_settings.main_frame_before_activation_enabled = false;
1080 StateMachine state(scheduler_settings); 1112 StateMachine state(scheduler_settings);
1081 SET_UP_STATE(state) 1113 SET_UP_STATE(state)
1082 1114
1083 // Start clean and set commit. 1115 // Start clean and set commit.
1084 state.SetNeedsBeginMainFrame(); 1116 state.SetNeedsBeginMainFrame();
1085 1117
1086 // Begin the frame. 1118 // Begin the frame.
1087 state.OnBeginImplFrame(); 1119 state.IssueNextBeginImplFrame();
1088 EXPECT_ACTION_UPDATE_STATE( 1120 EXPECT_ACTION_UPDATE_STATE(
1089 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 1121 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
1090 EXPECT_MAIN_FRAME_STATE(SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_SENT); 1122 EXPECT_MAIN_FRAME_STATE(SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_SENT);
1091 EXPECT_FALSE(state.NeedsCommit()); 1123 EXPECT_FALSE(state.NeedsCommit());
1092 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1124 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1093 1125
1094 // Tell the scheduler the frame finished. 1126 // Tell the scheduler the frame finished.
1095 state.NotifyBeginMainFrameStarted(); 1127 state.NotifyBeginMainFrameStarted();
1096 state.NotifyReadyToCommit(); 1128 state.NotifyReadyToCommit();
1097 EXPECT_MAIN_FRAME_STATE( 1129 EXPECT_MAIN_FRAME_STATE(
1098 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_READY_TO_COMMIT); 1130 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_READY_TO_COMMIT);
1099 // Commit. 1131 // Commit.
1100 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 1132 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
1101 // Commit always calls NotifyReadyToActivate in this mode. 1133 // Commit always calls NotifyReadyToActivate in this mode.
1102 state.NotifyReadyToActivate(); 1134 state.NotifyReadyToActivate();
1103 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE); 1135 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE);
1104 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1136 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1105 1137
1106 // No draw because we haven't received NotifyReadyToDraw yet. 1138 // No draw because we haven't received NotifyReadyToDraw yet.
1107 state.OnBeginImplFrameDeadline(); 1139 state.OnBeginImplFrameDeadline();
1108 EXPECT_TRUE(state.active_tree_needs_first_draw()); 1140 EXPECT_TRUE(state.active_tree_needs_first_draw());
1109 EXPECT_TRUE(state.needs_redraw()); 1141 EXPECT_TRUE(state.needs_redraw());
1110 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1142 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1111 1143
1112 // Can't BeginMainFrame yet since last commit hasn't been drawn yet. 1144 // Can't BeginMainFrame yet since last commit hasn't been drawn yet.
1113 state.SetNeedsBeginMainFrame(); 1145 state.SetNeedsBeginMainFrame();
1114 state.OnBeginImplFrame(); 1146 state.IssueNextBeginImplFrame();
1115 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1147 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1116 1148
1117 // Now call ready to draw which will allow the draw to happen and 1149 // Now call ready to draw which will allow the draw to happen and
1118 // BeginMainFrame to be sent. 1150 // BeginMainFrame to be sent.
1119 state.NotifyReadyToDraw(); 1151 state.NotifyReadyToDraw();
1120 state.OnBeginImplFrameDeadline(); 1152 state.OnBeginImplFrameDeadline();
1121 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE); 1153 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE);
1122 // Submit throttled from this point. 1154 // Submit throttled from this point.
1123 state.DidSubmitCompositorFrame(); 1155 state.DidSubmitCompositorFrame();
1124 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1156 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1125 1157
1126 // Can't BeginMainFrame yet since we're submit-frame throttled. 1158 // Can't BeginMainFrame yet since we're submit-frame throttled.
1127 state.OnBeginImplFrame(); 1159 state.IssueNextBeginImplFrame();
1128 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1160 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1129 1161
1130 // CompositorFrameAck unblocks BeginMainFrame. 1162 // CompositorFrameAck unblocks BeginMainFrame.
1131 state.DidReceiveCompositorFrameAck(); 1163 state.DidReceiveCompositorFrameAck();
1132 EXPECT_ACTION_UPDATE_STATE( 1164 EXPECT_ACTION_UPDATE_STATE(
1133 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 1165 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
1134 state.NotifyBeginMainFrameStarted(); 1166 state.NotifyBeginMainFrameStarted();
1135 state.NotifyReadyToCommit(); 1167 state.NotifyReadyToCommit();
1136 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 1168 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
1137 state.NotifyReadyToActivate(); 1169 state.NotifyReadyToActivate();
1138 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE); 1170 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE);
1139 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1171 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1140 1172
1141 // Draw the newly activated tree. 1173 // Draw the newly activated tree.
1142 state.NotifyReadyToDraw(); 1174 state.NotifyReadyToDraw();
1143 state.OnBeginImplFrameDeadline(); 1175 state.OnBeginImplFrameDeadline();
1144 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE); 1176 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE);
1145 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1177 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1146 } 1178 }
1147 1179
1148 TEST(SchedulerStateMachineTest, TestFullCycleWithCommitRequestInbetween) { 1180 TEST(SchedulerStateMachineTest, TestFullCycleWithCommitRequestInbetween) {
1149 SchedulerSettings default_scheduler_settings; 1181 SchedulerSettings default_scheduler_settings;
1150 StateMachine state(default_scheduler_settings); 1182 StateMachine state(default_scheduler_settings);
1151 SET_UP_STATE(state) 1183 SET_UP_STATE(state)
1152 1184
1153 // Start clean and set commit. 1185 // Start clean and set commit.
1154 state.SetNeedsBeginMainFrame(); 1186 state.SetNeedsBeginMainFrame();
1155 1187
1156 // Begin the frame. 1188 // Begin the frame.
1157 state.OnBeginImplFrame(); 1189 state.IssueNextBeginImplFrame();
1158 EXPECT_ACTION_UPDATE_STATE( 1190 EXPECT_ACTION_UPDATE_STATE(
1159 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 1191 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
1160 EXPECT_MAIN_FRAME_STATE(SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_SENT); 1192 EXPECT_MAIN_FRAME_STATE(SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_SENT);
1161 EXPECT_FALSE(state.NeedsCommit()); 1193 EXPECT_FALSE(state.NeedsCommit());
1162 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1194 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1163 1195
1164 // Request another commit while the commit is in flight. 1196 // Request another commit while the commit is in flight.
1165 state.SetNeedsBeginMainFrame(); 1197 state.SetNeedsBeginMainFrame();
1166 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1198 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1167 1199
(...skipping 18 matching lines...) Expand all
1186 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE); 1218 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE);
1187 state.DidSubmitCompositorFrame(); 1219 state.DidSubmitCompositorFrame();
1188 state.DidReceiveCompositorFrameAck(); 1220 state.DidReceiveCompositorFrameAck();
1189 1221
1190 // Should be synchronized, no draw needed, no action needed. 1222 // Should be synchronized, no draw needed, no action needed.
1191 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1223 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1192 EXPECT_MAIN_FRAME_STATE(SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_IDLE); 1224 EXPECT_MAIN_FRAME_STATE(SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_IDLE);
1193 EXPECT_FALSE(state.needs_redraw()); 1225 EXPECT_FALSE(state.needs_redraw());
1194 1226
1195 // Next BeginImplFrame should initiate second commit. 1227 // Next BeginImplFrame should initiate second commit.
1196 state.OnBeginImplFrame(); 1228 state.IssueNextBeginImplFrame();
1197 EXPECT_ACTION_UPDATE_STATE( 1229 EXPECT_ACTION_UPDATE_STATE(
1198 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 1230 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
1199 } 1231 }
1200 1232
1201 TEST(SchedulerStateMachineTest, TestNoRequestCommitWhenInvisible) { 1233 TEST(SchedulerStateMachineTest, TestNoRequestCommitWhenInvisible) {
1202 SchedulerSettings default_scheduler_settings; 1234 SchedulerSettings default_scheduler_settings;
1203 StateMachine state(default_scheduler_settings); 1235 StateMachine state(default_scheduler_settings);
1204 state.SetVisible(true); 1236 state.SetVisible(true);
1205 EXPECT_ACTION_UPDATE_STATE( 1237 EXPECT_ACTION_UPDATE_STATE(
1206 SchedulerStateMachine::ACTION_BEGIN_COMPOSITOR_FRAME_SINK_CREATION); 1238 SchedulerStateMachine::ACTION_BEGIN_COMPOSITOR_FRAME_SINK_CREATION);
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
1249 // "EarlyOut_CompositorFrameSinkLost" cases. 1281 // "EarlyOut_CompositorFrameSinkLost" cases.
1250 TEST(SchedulerStateMachineTest, TestAbortBeginMainFrameBecauseInvisible) { 1282 TEST(SchedulerStateMachineTest, TestAbortBeginMainFrameBecauseInvisible) {
1251 SchedulerSettings default_scheduler_settings; 1283 SchedulerSettings default_scheduler_settings;
1252 StateMachine state(default_scheduler_settings); 1284 StateMachine state(default_scheduler_settings);
1253 SET_UP_STATE(state) 1285 SET_UP_STATE(state)
1254 1286
1255 // Start clean and set commit. 1287 // Start clean and set commit.
1256 state.SetNeedsBeginMainFrame(); 1288 state.SetNeedsBeginMainFrame();
1257 1289
1258 // Begin the frame while visible. 1290 // Begin the frame while visible.
1259 state.OnBeginImplFrame(); 1291 state.IssueNextBeginImplFrame();
1260 EXPECT_ACTION_UPDATE_STATE( 1292 EXPECT_ACTION_UPDATE_STATE(
1261 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 1293 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
1262 EXPECT_MAIN_FRAME_STATE(SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_SENT); 1294 EXPECT_MAIN_FRAME_STATE(SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_SENT);
1263 EXPECT_FALSE(state.NeedsCommit()); 1295 EXPECT_FALSE(state.NeedsCommit());
1264 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1296 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1265 1297
1266 // Become invisible and abort BeginMainFrame. 1298 // Become invisible and abort BeginMainFrame.
1267 state.SetVisible(false); 1299 state.SetVisible(false);
1268 state.NotifyBeginMainFrameStarted(); 1300 state.NotifyBeginMainFrameStarted();
1269 state.BeginMainFrameAborted(CommitEarlyOutReason::ABORTED_NOT_VISIBLE); 1301 state.BeginMainFrameAborted(CommitEarlyOutReason::ABORTED_NOT_VISIBLE);
(...skipping 13 matching lines...) Expand all
1283 // Become visible again. 1315 // Become visible again.
1284 state.SetVisible(true); 1316 state.SetVisible(true);
1285 1317
1286 // Although we have aborted on this frame and haven't cancelled the commit 1318 // Although we have aborted on this frame and haven't cancelled the commit
1287 // (i.e. need another), don't send another BeginMainFrame yet. 1319 // (i.e. need another), don't send another BeginMainFrame yet.
1288 EXPECT_MAIN_FRAME_STATE(SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_IDLE); 1320 EXPECT_MAIN_FRAME_STATE(SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_IDLE);
1289 EXPECT_ACTION(SchedulerStateMachine::ACTION_NONE); 1321 EXPECT_ACTION(SchedulerStateMachine::ACTION_NONE);
1290 EXPECT_TRUE(state.NeedsCommit()); 1322 EXPECT_TRUE(state.NeedsCommit());
1291 1323
1292 // Start a new frame. 1324 // Start a new frame.
1293 state.OnBeginImplFrame(); 1325 state.IssueNextBeginImplFrame();
1294 EXPECT_ACTION_UPDATE_STATE( 1326 EXPECT_ACTION_UPDATE_STATE(
1295 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 1327 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
1296 1328
1297 // We should be starting the commit now. 1329 // We should be starting the commit now.
1298 EXPECT_MAIN_FRAME_STATE(SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_SENT); 1330 EXPECT_MAIN_FRAME_STATE(SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_SENT);
1299 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1331 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1300 } 1332 }
1301 1333
1302 // See ProxyMain::BeginMainFrame "EarlyOut_NoUpdates" case. 1334 // See ProxyMain::BeginMainFrame "EarlyOut_NoUpdates" case.
1303 TEST(SchedulerStateMachineTest, TestAbortBeginMainFrameBecauseCommitNotNeeded) { 1335 TEST(SchedulerStateMachineTest, TestAbortBeginMainFrameBecauseCommitNotNeeded) {
1304 SchedulerSettings default_scheduler_settings; 1336 SchedulerSettings default_scheduler_settings;
1305 StateMachine state(default_scheduler_settings); 1337 StateMachine state(default_scheduler_settings);
1306 state.SetVisible(true); 1338 state.SetVisible(true);
1307 EXPECT_ACTION_UPDATE_STATE( 1339 EXPECT_ACTION_UPDATE_STATE(
1308 SchedulerStateMachine::ACTION_BEGIN_COMPOSITOR_FRAME_SINK_CREATION); 1340 SchedulerStateMachine::ACTION_BEGIN_COMPOSITOR_FRAME_SINK_CREATION);
1309 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1341 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1310 state.DidCreateAndInitializeCompositorFrameSink(); 1342 state.DidCreateAndInitializeCompositorFrameSink();
1311 state.SetCanDraw(true); 1343 state.SetCanDraw(true);
1312 1344
1313 // Get into a begin frame / commit state. 1345 // Get into a begin frame / commit state.
1314 state.SetNeedsBeginMainFrame(); 1346 state.SetNeedsBeginMainFrame();
1315 state.OnBeginImplFrame(); 1347 state.IssueNextBeginImplFrame();
1316 EXPECT_ACTION_UPDATE_STATE( 1348 EXPECT_ACTION_UPDATE_STATE(
1317 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 1349 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
1318 EXPECT_MAIN_FRAME_STATE(SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_SENT); 1350 EXPECT_MAIN_FRAME_STATE(SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_SENT);
1319 EXPECT_FALSE(state.NeedsCommit()); 1351 EXPECT_FALSE(state.NeedsCommit());
1320 EXPECT_ACTION(SchedulerStateMachine::ACTION_NONE); 1352 EXPECT_ACTION(SchedulerStateMachine::ACTION_NONE);
1321 1353
1322 // Abort the commit, true means that the BeginMainFrame was sent but there 1354 // Abort the commit, true means that the BeginMainFrame was sent but there
1323 // was no work to do on the main thread. 1355 // was no work to do on the main thread.
1324 state.NotifyBeginMainFrameStarted(); 1356 state.NotifyBeginMainFrameStarted();
1325 state.BeginMainFrameAborted(CommitEarlyOutReason::FINISHED_NO_UPDATES); 1357 state.BeginMainFrameAborted(CommitEarlyOutReason::FINISHED_NO_UPDATES);
1326 1358
1327 // NeedsCommit should now be false because the commit was actually handled. 1359 // NeedsCommit should now be false because the commit was actually handled.
1328 EXPECT_FALSE(state.NeedsCommit()); 1360 EXPECT_FALSE(state.NeedsCommit());
1329 1361
1330 // Since the commit was aborted, we don't need to try and draw. 1362 // Since the commit was aborted, we don't need to try and draw.
1331 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1363 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1332 state.OnBeginImplFrameDeadline(); 1364 state.OnBeginImplFrameDeadline();
1333 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1365 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1334 1366
1335 // Verify another commit doesn't start on another frame either. 1367 // Verify another commit doesn't start on another frame either.
1336 EXPECT_FALSE(state.NeedsCommit()); 1368 EXPECT_FALSE(state.NeedsCommit());
1337 EXPECT_MAIN_FRAME_STATE(SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_IDLE); 1369 EXPECT_MAIN_FRAME_STATE(SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_IDLE);
1338 1370
1339 state.OnBeginImplFrame(); 1371 state.IssueNextBeginImplFrame();
1340 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1372 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1341 state.OnBeginImplFrameDeadline(); 1373 state.OnBeginImplFrameDeadline();
1342 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1374 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1343 1375
1344 // Verify another commit can start if requested, though. 1376 // Verify another commit can start if requested, though.
1345 state.SetNeedsBeginMainFrame(); 1377 state.SetNeedsBeginMainFrame();
1346 EXPECT_MAIN_FRAME_STATE(SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_IDLE); 1378 EXPECT_MAIN_FRAME_STATE(SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_IDLE);
1347 state.OnBeginImplFrame(); 1379 state.IssueNextBeginImplFrame();
1348 EXPECT_ACTION(SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 1380 EXPECT_ACTION(SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
1349 } 1381 }
1350 1382
1351 TEST(SchedulerStateMachineTest, TestFirstContextCreation) { 1383 TEST(SchedulerStateMachineTest, TestFirstContextCreation) {
1352 SchedulerSettings default_scheduler_settings; 1384 SchedulerSettings default_scheduler_settings;
1353 StateMachine state(default_scheduler_settings); 1385 StateMachine state(default_scheduler_settings);
1354 state.SetVisible(true); 1386 state.SetVisible(true);
1355 state.SetCanDraw(true); 1387 state.SetCanDraw(true);
1356 1388
1357 EXPECT_ACTION_UPDATE_STATE( 1389 EXPECT_ACTION_UPDATE_STATE(
1358 SchedulerStateMachine::ACTION_BEGIN_COMPOSITOR_FRAME_SINK_CREATION); 1390 SchedulerStateMachine::ACTION_BEGIN_COMPOSITOR_FRAME_SINK_CREATION);
1359 state.CreateAndInitializeCompositorFrameSinkWithActivatedCommit(); 1391 state.CreateAndInitializeCompositorFrameSinkWithActivatedCommit();
1360 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1392 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1361 1393
1362 // Check that the first init does not SetNeedsBeginMainFrame. 1394 // Check that the first init does not SetNeedsBeginMainFrame.
1363 state.OnBeginImplFrame(); 1395 state.IssueNextBeginImplFrame();
1364 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1396 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1365 state.OnBeginImplFrameDeadline(); 1397 state.OnBeginImplFrameDeadline();
1366 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1398 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1367 1399
1368 // Check that a needs commit initiates a BeginMainFrame. 1400 // Check that a needs commit initiates a BeginMainFrame.
1369 state.SetNeedsBeginMainFrame(); 1401 state.SetNeedsBeginMainFrame();
1370 state.OnBeginImplFrame(); 1402 state.IssueNextBeginImplFrame();
1371 EXPECT_ACTION_UPDATE_STATE( 1403 EXPECT_ACTION_UPDATE_STATE(
1372 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 1404 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
1373 } 1405 }
1374 1406
1375 TEST(SchedulerStateMachineTest, TestContextLostWhenCompletelyIdle) { 1407 TEST(SchedulerStateMachineTest, TestContextLostWhenCompletelyIdle) {
1376 SchedulerSettings default_scheduler_settings; 1408 SchedulerSettings default_scheduler_settings;
1377 StateMachine state(default_scheduler_settings); 1409 StateMachine state(default_scheduler_settings);
1378 SET_UP_STATE(state) 1410 SET_UP_STATE(state)
1379 1411
1380 EXPECT_NE(SchedulerStateMachine::ACTION_BEGIN_COMPOSITOR_FRAME_SINK_CREATION, 1412 EXPECT_NE(SchedulerStateMachine::ACTION_BEGIN_COMPOSITOR_FRAME_SINK_CREATION,
1381 state.NextAction()); 1413 state.NextAction());
1382 state.DidLoseCompositorFrameSink(); 1414 state.DidLoseCompositorFrameSink();
1383 1415
1384 EXPECT_ACTION_UPDATE_STATE( 1416 EXPECT_ACTION_UPDATE_STATE(
1385 SchedulerStateMachine::ACTION_BEGIN_COMPOSITOR_FRAME_SINK_CREATION); 1417 SchedulerStateMachine::ACTION_BEGIN_COMPOSITOR_FRAME_SINK_CREATION);
1386 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1418 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1387 1419
1388 // Once context recreation begins, nothing should happen. 1420 // Once context recreation begins, nothing should happen.
1389 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1421 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1390 1422
1391 // Recreate the context. 1423 // Recreate the context.
1392 state.CreateAndInitializeCompositorFrameSinkWithActivatedCommit(); 1424 state.CreateAndInitializeCompositorFrameSinkWithActivatedCommit();
1393 1425
1394 // When the context is recreated, we should begin a commit. 1426 // When the context is recreated, we should begin a commit.
1395 state.OnBeginImplFrame(); 1427 state.IssueNextBeginImplFrame();
1396 EXPECT_ACTION_UPDATE_STATE( 1428 EXPECT_ACTION_UPDATE_STATE(
1397 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 1429 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
1398 } 1430 }
1399 1431
1400 TEST(SchedulerStateMachineTest, 1432 TEST(SchedulerStateMachineTest,
1401 TestContextLostWhenIdleAndCommitRequestedWhileRecreating) { 1433 TestContextLostWhenIdleAndCommitRequestedWhileRecreating) {
1402 SchedulerSettings default_scheduler_settings; 1434 SchedulerSettings default_scheduler_settings;
1403 StateMachine state(default_scheduler_settings); 1435 StateMachine state(default_scheduler_settings);
1404 SET_UP_STATE(state) 1436 SET_UP_STATE(state)
1405 1437
1406 EXPECT_NE(SchedulerStateMachine::ACTION_BEGIN_COMPOSITOR_FRAME_SINK_CREATION, 1438 EXPECT_NE(SchedulerStateMachine::ACTION_BEGIN_COMPOSITOR_FRAME_SINK_CREATION,
1407 state.NextAction()); 1439 state.NextAction());
1408 state.DidLoseCompositorFrameSink(); 1440 state.DidLoseCompositorFrameSink();
1409 EXPECT_EQ(state.compositor_frame_sink_state(), 1441 EXPECT_EQ(state.compositor_frame_sink_state(),
1410 SchedulerStateMachine::COMPOSITOR_FRAME_SINK_NONE); 1442 SchedulerStateMachine::COMPOSITOR_FRAME_SINK_NONE);
1411 1443
1412 EXPECT_ACTION_UPDATE_STATE( 1444 EXPECT_ACTION_UPDATE_STATE(
1413 SchedulerStateMachine::ACTION_BEGIN_COMPOSITOR_FRAME_SINK_CREATION); 1445 SchedulerStateMachine::ACTION_BEGIN_COMPOSITOR_FRAME_SINK_CREATION);
1414 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1446 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1415 1447
1416 // Once context recreation begins, nothing should happen. 1448 // Once context recreation begins, nothing should happen.
1417 state.OnBeginImplFrame(); 1449 state.IssueNextBeginImplFrame();
1418 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1450 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1419 state.OnBeginImplFrameDeadline(); 1451 state.OnBeginImplFrameDeadline();
1420 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1452 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1421 1453
1422 // While context is recreating, commits shouldn't begin. 1454 // While context is recreating, commits shouldn't begin.
1423 state.SetNeedsBeginMainFrame(); 1455 state.SetNeedsBeginMainFrame();
1424 state.OnBeginImplFrame(); 1456 state.IssueNextBeginImplFrame();
1425 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1457 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1426 state.OnBeginImplFrameDeadline(); 1458 state.OnBeginImplFrameDeadline();
1427 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1459 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1428 1460
1429 // Recreate the context 1461 // Recreate the context
1430 state.DidCreateAndInitializeCompositorFrameSink(); 1462 state.DidCreateAndInitializeCompositorFrameSink();
1431 EXPECT_EQ( 1463 EXPECT_EQ(
1432 state.compositor_frame_sink_state(), 1464 state.compositor_frame_sink_state(),
1433 SchedulerStateMachine::COMPOSITOR_FRAME_SINK_WAITING_FOR_FIRST_COMMIT); 1465 SchedulerStateMachine::COMPOSITOR_FRAME_SINK_WAITING_FOR_FIRST_COMMIT);
1434 EXPECT_FALSE(state.RedrawPending()); 1466 EXPECT_FALSE(state.RedrawPending());
1435 1467
1436 // When the context is recreated, we wait until the next BeginImplFrame 1468 // When the context is recreated, we wait until the next BeginImplFrame
1437 // before starting. 1469 // before starting.
1438 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1470 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1439 1471
1440 // When the BeginFrame comes in we should begin a commit 1472 // When the BeginFrame comes in we should begin a commit
1441 state.OnBeginImplFrame(); 1473 state.IssueNextBeginImplFrame();
1442 EXPECT_ACTION_UPDATE_STATE( 1474 EXPECT_ACTION_UPDATE_STATE(
1443 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 1475 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
1444 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1476 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1445 EXPECT_MAIN_FRAME_STATE(SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_SENT); 1477 EXPECT_MAIN_FRAME_STATE(SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_SENT);
1446 1478
1447 // Until that commit finishes, we shouldn't be drawing. 1479 // Until that commit finishes, we shouldn't be drawing.
1448 state.OnBeginImplFrameDeadline(); 1480 state.OnBeginImplFrameDeadline();
1449 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1481 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1450 1482
1451 // Finish the commit, which should make the surface active. 1483 // Finish the commit, which should make the surface active.
1452 state.NotifyBeginMainFrameStarted(); 1484 state.NotifyBeginMainFrameStarted();
1453 state.NotifyReadyToCommit(); 1485 state.NotifyReadyToCommit();
1454 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 1486 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
1455 EXPECT_EQ(state.compositor_frame_sink_state(), 1487 EXPECT_EQ(state.compositor_frame_sink_state(),
1456 SchedulerStateMachine:: 1488 SchedulerStateMachine::
1457 COMPOSITOR_FRAME_SINK_WAITING_FOR_FIRST_ACTIVATION); 1489 COMPOSITOR_FRAME_SINK_WAITING_FOR_FIRST_ACTIVATION);
1458 state.NotifyReadyToActivate(); 1490 state.NotifyReadyToActivate();
1459 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE); 1491 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE);
1460 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1492 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1461 EXPECT_EQ(state.compositor_frame_sink_state(), 1493 EXPECT_EQ(state.compositor_frame_sink_state(),
1462 SchedulerStateMachine::COMPOSITOR_FRAME_SINK_ACTIVE); 1494 SchedulerStateMachine::COMPOSITOR_FRAME_SINK_ACTIVE);
1463 1495
1464 // Finishing the first commit after initializing an CompositorFrameSink should 1496 // Finishing the first commit after initializing an CompositorFrameSink should
1465 // automatically cause a redraw. 1497 // automatically cause a redraw.
1466 EXPECT_TRUE(state.RedrawPending()); 1498 EXPECT_TRUE(state.RedrawPending());
1467 state.OnBeginImplFrame(); 1499 state.IssueNextBeginImplFrame();
1468 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1500 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1469 state.OnBeginImplFrameDeadline(); 1501 state.OnBeginImplFrameDeadline();
1470 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE); 1502 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE);
1471 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1503 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1472 EXPECT_FALSE(state.RedrawPending()); 1504 EXPECT_FALSE(state.RedrawPending());
1473 1505
1474 // Next frame as no work to do. 1506 // Next frame as no work to do.
1475 state.OnBeginImplFrame(); 1507 state.IssueNextBeginImplFrame();
1476 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1508 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1477 state.OnBeginImplFrameDeadline(); 1509 state.OnBeginImplFrameDeadline();
1478 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1510 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1479 1511
1480 // Once the context is recreated, whether we draw should be based on 1512 // Once the context is recreated, whether we draw should be based on
1481 // SetCanDraw if waiting on first draw after activate. 1513 // SetCanDraw if waiting on first draw after activate.
1482 state.SetNeedsRedraw(true); 1514 state.SetNeedsRedraw(true);
1483 state.OnBeginImplFrame(); 1515 state.IssueNextBeginImplFrame();
1484 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1516 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1485 state.OnBeginImplFrameDeadline(); 1517 state.OnBeginImplFrameDeadline();
1486 EXPECT_ACTION(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE); 1518 EXPECT_ACTION(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE);
1487 state.SetCanDraw(false); 1519 state.SetCanDraw(false);
1488 EXPECT_ACTION(SchedulerStateMachine::ACTION_NONE); 1520 EXPECT_ACTION(SchedulerStateMachine::ACTION_NONE);
1489 state.SetCanDraw(true); 1521 state.SetCanDraw(true);
1490 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE); 1522 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE);
1491 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1523 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1492 1524
1493 // Once the context is recreated, whether we draw should be based on 1525 // Once the context is recreated, whether we draw should be based on
1494 // SetCanDraw if waiting on first draw after activate. 1526 // SetCanDraw if waiting on first draw after activate.
1495 state.SetNeedsRedraw(true); 1527 state.SetNeedsRedraw(true);
1496 state.SetNeedsBeginMainFrame(); 1528 state.SetNeedsBeginMainFrame();
1497 state.OnBeginImplFrame(); 1529 state.IssueNextBeginImplFrame();
1498 EXPECT_ACTION_UPDATE_STATE( 1530 EXPECT_ACTION_UPDATE_STATE(
1499 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 1531 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
1500 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1532 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1501 // Activate so we need the first draw 1533 // Activate so we need the first draw
1502 state.NotifyBeginMainFrameStarted(); 1534 state.NotifyBeginMainFrameStarted();
1503 state.NotifyReadyToCommit(); 1535 state.NotifyReadyToCommit();
1504 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 1536 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
1505 state.NotifyReadyToActivate(); 1537 state.NotifyReadyToActivate();
1506 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE); 1538 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE);
1507 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1539 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
(...skipping 11 matching lines...) Expand all
1519 TEST(SchedulerStateMachineTest, TestContextLostWhileCommitInProgress) { 1551 TEST(SchedulerStateMachineTest, TestContextLostWhileCommitInProgress) {
1520 SchedulerSettings scheduler_settings; 1552 SchedulerSettings scheduler_settings;
1521 StateMachine state(scheduler_settings); 1553 StateMachine state(scheduler_settings);
1522 SET_UP_STATE(state) 1554 SET_UP_STATE(state)
1523 1555
1524 // Get a commit in flight. 1556 // Get a commit in flight.
1525 state.SetNeedsBeginMainFrame(); 1557 state.SetNeedsBeginMainFrame();
1526 1558
1527 // Set damage and expect a draw. 1559 // Set damage and expect a draw.
1528 state.SetNeedsRedraw(true); 1560 state.SetNeedsRedraw(true);
1529 state.OnBeginImplFrame(); 1561 state.IssueNextBeginImplFrame();
1530 EXPECT_ACTION_UPDATE_STATE( 1562 EXPECT_ACTION_UPDATE_STATE(
1531 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 1563 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
1532 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1564 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1533 state.OnBeginImplFrameDeadline(); 1565 state.OnBeginImplFrameDeadline();
1534 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE); 1566 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE);
1535 state.DidSubmitCompositorFrame(); 1567 state.DidSubmitCompositorFrame();
1536 state.DidReceiveCompositorFrameAck(); 1568 state.DidReceiveCompositorFrameAck();
1537 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1569 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1538 1570
1539 // Cause a lost context while the BeginMainFrame is in flight. 1571 // Cause a lost context while the BeginMainFrame is in flight.
(...skipping 13 matching lines...) Expand all
1553 // We will abort the draw when the CompositorFrameSink is lost if we are 1585 // We will abort the draw when the CompositorFrameSink is lost if we are
1554 // waiting for the first draw to unblock the main thread. 1586 // waiting for the first draw to unblock the main thread.
1555 EXPECT_TRUE(state.active_tree_needs_first_draw()); 1587 EXPECT_TRUE(state.active_tree_needs_first_draw());
1556 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_ABORT); 1588 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_ABORT);
1557 1589
1558 // Expect to begin context recreation only in BEGIN_IMPL_FRAME_STATE_IDLE 1590 // Expect to begin context recreation only in BEGIN_IMPL_FRAME_STATE_IDLE
1559 EXPECT_IMPL_FRAME_STATE(SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE); 1591 EXPECT_IMPL_FRAME_STATE(SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE);
1560 EXPECT_ACTION( 1592 EXPECT_ACTION(
1561 SchedulerStateMachine::ACTION_BEGIN_COMPOSITOR_FRAME_SINK_CREATION); 1593 SchedulerStateMachine::ACTION_BEGIN_COMPOSITOR_FRAME_SINK_CREATION);
1562 1594
1563 state.OnBeginImplFrame(); 1595 state.IssueNextBeginImplFrame();
1564 EXPECT_IMPL_FRAME_STATE( 1596 EXPECT_IMPL_FRAME_STATE(
1565 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_BEGIN_FRAME); 1597 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_BEGIN_FRAME);
1566 EXPECT_ACTION(SchedulerStateMachine::ACTION_NONE); 1598 EXPECT_ACTION(SchedulerStateMachine::ACTION_NONE);
1567 1599
1568 state.OnBeginImplFrameDeadline(); 1600 state.OnBeginImplFrameDeadline();
1569 EXPECT_IMPL_FRAME_STATE( 1601 EXPECT_IMPL_FRAME_STATE(
1570 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE); 1602 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE);
1571 EXPECT_ACTION(SchedulerStateMachine::ACTION_NONE); 1603 EXPECT_ACTION(SchedulerStateMachine::ACTION_NONE);
1572 } 1604 }
1573 1605
1574 TEST(SchedulerStateMachineTest, 1606 TEST(SchedulerStateMachineTest,
1575 TestContextLostWhileCommitInProgressAndAnotherCommitRequested) { 1607 TestContextLostWhileCommitInProgressAndAnotherCommitRequested) {
1576 SchedulerSettings scheduler_settings; 1608 SchedulerSettings scheduler_settings;
1577 StateMachine state(scheduler_settings); 1609 StateMachine state(scheduler_settings);
1578 SET_UP_STATE(state) 1610 SET_UP_STATE(state)
1579 1611
1580 // Get a commit in flight. 1612 // Get a commit in flight.
1581 state.SetNeedsBeginMainFrame(); 1613 state.SetNeedsBeginMainFrame();
1582 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1614 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1583 1615
1584 // Set damage and expect a draw. 1616 // Set damage and expect a draw.
1585 state.SetNeedsRedraw(true); 1617 state.SetNeedsRedraw(true);
1586 state.OnBeginImplFrame(); 1618 state.IssueNextBeginImplFrame();
1587 EXPECT_ACTION_UPDATE_STATE( 1619 EXPECT_ACTION_UPDATE_STATE(
1588 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 1620 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
1589 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1621 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1590 state.OnBeginImplFrameDeadline(); 1622 state.OnBeginImplFrameDeadline();
1591 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE); 1623 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE);
1592 state.DidSubmitCompositorFrame(); 1624 state.DidSubmitCompositorFrame();
1593 state.DidReceiveCompositorFrameAck(); 1625 state.DidReceiveCompositorFrameAck();
1594 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1626 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1595 1627
1596 // Cause a lost context while the BeginMainFrame is in flight. 1628 // Cause a lost context while the BeginMainFrame is in flight.
(...skipping 13 matching lines...) Expand all
1610 EXPECT_TRUE(state.active_tree_needs_first_draw()); 1642 EXPECT_TRUE(state.active_tree_needs_first_draw());
1611 1643
1612 // Because the CompositorFrameSink is missing, we expect the draw to abort. 1644 // Because the CompositorFrameSink is missing, we expect the draw to abort.
1613 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_ABORT); 1645 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_ABORT);
1614 1646
1615 // Expect to begin context recreation only in BEGIN_IMPL_FRAME_STATE_IDLE 1647 // Expect to begin context recreation only in BEGIN_IMPL_FRAME_STATE_IDLE
1616 EXPECT_IMPL_FRAME_STATE(SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE); 1648 EXPECT_IMPL_FRAME_STATE(SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE);
1617 EXPECT_ACTION( 1649 EXPECT_ACTION(
1618 SchedulerStateMachine::ACTION_BEGIN_COMPOSITOR_FRAME_SINK_CREATION); 1650 SchedulerStateMachine::ACTION_BEGIN_COMPOSITOR_FRAME_SINK_CREATION);
1619 1651
1620 state.OnBeginImplFrame(); 1652 state.IssueNextBeginImplFrame();
1621 EXPECT_IMPL_FRAME_STATE( 1653 EXPECT_IMPL_FRAME_STATE(
1622 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_BEGIN_FRAME); 1654 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_BEGIN_FRAME);
1623 EXPECT_ACTION(SchedulerStateMachine::ACTION_NONE); 1655 EXPECT_ACTION(SchedulerStateMachine::ACTION_NONE);
1624 1656
1625 state.OnBeginImplFrameDeadline(); 1657 state.OnBeginImplFrameDeadline();
1626 EXPECT_IMPL_FRAME_STATE( 1658 EXPECT_IMPL_FRAME_STATE(
1627 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE); 1659 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE);
1628 EXPECT_ACTION(SchedulerStateMachine::ACTION_NONE); 1660 EXPECT_ACTION(SchedulerStateMachine::ACTION_NONE);
1629 1661
1630 state.OnBeginImplFrameIdle(); 1662 state.OnBeginImplFrameIdle();
1631 EXPECT_ACTION_UPDATE_STATE( 1663 EXPECT_ACTION_UPDATE_STATE(
1632 SchedulerStateMachine::ACTION_BEGIN_COMPOSITOR_FRAME_SINK_CREATION); 1664 SchedulerStateMachine::ACTION_BEGIN_COMPOSITOR_FRAME_SINK_CREATION);
1633 1665
1634 // After we get a new CompositorFrameSink, the commit flow should start. 1666 // After we get a new CompositorFrameSink, the commit flow should start.
1635 state.CreateAndInitializeCompositorFrameSinkWithActivatedCommit(); 1667 state.CreateAndInitializeCompositorFrameSinkWithActivatedCommit();
1636 state.OnBeginImplFrame(); 1668 state.IssueNextBeginImplFrame();
1637 EXPECT_ACTION_UPDATE_STATE( 1669 EXPECT_ACTION_UPDATE_STATE(
1638 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 1670 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
1639 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1671 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1640 state.NotifyBeginMainFrameStarted(); 1672 state.NotifyBeginMainFrameStarted();
1641 state.NotifyReadyToCommit(); 1673 state.NotifyReadyToCommit();
1642 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 1674 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
1643 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1675 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1644 state.NotifyReadyToActivate(); 1676 state.NotifyReadyToActivate();
1645 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE); 1677 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE);
1646 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1678 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
(...skipping 13 matching lines...) Expand all
1660 state.SetNeedsRedraw(true); 1692 state.SetNeedsRedraw(true);
1661 1693
1662 // Cause a lost CompositorFrameSink, and restore it. 1694 // Cause a lost CompositorFrameSink, and restore it.
1663 state.DidLoseCompositorFrameSink(); 1695 state.DidLoseCompositorFrameSink();
1664 EXPECT_ACTION_UPDATE_STATE( 1696 EXPECT_ACTION_UPDATE_STATE(
1665 SchedulerStateMachine::ACTION_BEGIN_COMPOSITOR_FRAME_SINK_CREATION); 1697 SchedulerStateMachine::ACTION_BEGIN_COMPOSITOR_FRAME_SINK_CREATION);
1666 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1698 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1667 state.DidCreateAndInitializeCompositorFrameSink(); 1699 state.DidCreateAndInitializeCompositorFrameSink();
1668 1700
1669 EXPECT_FALSE(state.RedrawPending()); 1701 EXPECT_FALSE(state.RedrawPending());
1670 state.OnBeginImplFrame(); 1702 state.IssueNextBeginImplFrame();
1671 EXPECT_ACTION(SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 1703 EXPECT_ACTION(SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
1672 } 1704 }
1673 1705
1674 TEST(SchedulerStateMachineTest, 1706 TEST(SchedulerStateMachineTest,
1675 TestPendingActivationsShouldBeForcedAfterLostCompositorFrameSink) { 1707 TestPendingActivationsShouldBeForcedAfterLostCompositorFrameSink) {
1676 SchedulerSettings default_scheduler_settings; 1708 SchedulerSettings default_scheduler_settings;
1677 StateMachine state(default_scheduler_settings); 1709 StateMachine state(default_scheduler_settings);
1678 SET_UP_STATE(state) 1710 SET_UP_STATE(state)
1679 1711
1680 state.SetBeginMainFrameState( 1712 state.SetBeginMainFrameState(
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
1723 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1755 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1724 state.CreateAndInitializeCompositorFrameSinkWithActivatedCommit(); 1756 state.CreateAndInitializeCompositorFrameSinkWithActivatedCommit();
1725 state.SetVisible(false); 1757 state.SetVisible(false);
1726 state.SetNeedsBeginMainFrame(); 1758 state.SetNeedsBeginMainFrame();
1727 EXPECT_ACTION(SchedulerStateMachine::ACTION_NONE); 1759 EXPECT_ACTION(SchedulerStateMachine::ACTION_NONE);
1728 EXPECT_FALSE(state.BeginFrameNeeded()); 1760 EXPECT_FALSE(state.BeginFrameNeeded());
1729 1761
1730 // When become visible again, the needs commit should still be pending. 1762 // When become visible again, the needs commit should still be pending.
1731 state.SetVisible(true); 1763 state.SetVisible(true);
1732 EXPECT_TRUE(state.BeginFrameNeeded()); 1764 EXPECT_TRUE(state.BeginFrameNeeded());
1733 state.OnBeginImplFrame(); 1765 state.IssueNextBeginImplFrame();
1734 EXPECT_ACTION_UPDATE_STATE( 1766 EXPECT_ACTION_UPDATE_STATE(
1735 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 1767 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
1736 } 1768 }
1737 1769
1738 TEST(SchedulerStateMachineTest, TestFinishCommitWhenCommitInProgress) { 1770 TEST(SchedulerStateMachineTest, TestFinishCommitWhenCommitInProgress) {
1739 SchedulerSettings default_scheduler_settings; 1771 SchedulerSettings default_scheduler_settings;
1740 StateMachine state(default_scheduler_settings); 1772 StateMachine state(default_scheduler_settings);
1741 state.SetVisible(true); 1773 state.SetVisible(true);
1742 EXPECT_ACTION_UPDATE_STATE( 1774 EXPECT_ACTION_UPDATE_STATE(
1743 SchedulerStateMachine::ACTION_BEGIN_COMPOSITOR_FRAME_SINK_CREATION); 1775 SchedulerStateMachine::ACTION_BEGIN_COMPOSITOR_FRAME_SINK_CREATION);
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
1887 } 1919 }
1888 1920
1889 TEST(SchedulerStateMachineTest, 1921 TEST(SchedulerStateMachineTest,
1890 TestTriggerDeadlineImmediatelyAfterAbortedCommit) { 1922 TestTriggerDeadlineImmediatelyAfterAbortedCommit) {
1891 SchedulerSettings default_scheduler_settings; 1923 SchedulerSettings default_scheduler_settings;
1892 StateMachine state(default_scheduler_settings); 1924 StateMachine state(default_scheduler_settings);
1893 SET_UP_STATE(state) 1925 SET_UP_STATE(state)
1894 1926
1895 // This test mirrors what happens during the first frame of a scroll gesture. 1927 // This test mirrors what happens during the first frame of a scroll gesture.
1896 // First we get the input event and a BeginFrame. 1928 // First we get the input event and a BeginFrame.
1897 state.OnBeginImplFrame(); 1929 state.IssueNextBeginImplFrame();
1898 1930
1899 // As a response the compositor requests a redraw and a commit to tell the 1931 // As a response the compositor requests a redraw and a commit to tell the
1900 // main thread about the new scroll offset. 1932 // main thread about the new scroll offset.
1901 state.SetNeedsRedraw(true); 1933 state.SetNeedsRedraw(true);
1902 state.SetNeedsBeginMainFrame(); 1934 state.SetNeedsBeginMainFrame();
1903 1935
1904 // We should start the commit normally. 1936 // We should start the commit normally.
1905 EXPECT_ACTION_UPDATE_STATE( 1937 EXPECT_ACTION_UPDATE_STATE(
1906 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 1938 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
1907 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1939 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
(...skipping 14 matching lines...) Expand all
1922 StateMachine& state = *state_ptr; 1954 StateMachine& state = *state_ptr;
1923 1955
1924 state.NotifyBeginMainFrameStarted(); 1956 state.NotifyBeginMainFrameStarted();
1925 state.NotifyReadyToCommit(); 1957 state.NotifyReadyToCommit();
1926 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 1958 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
1927 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1959 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1928 state.NotifyReadyToActivate(); 1960 state.NotifyReadyToActivate();
1929 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE); 1961 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE);
1930 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1962 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1931 1963
1932 state.OnBeginImplFrame(); 1964 state.IssueNextBeginImplFrame();
1933 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1965 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1934 1966
1935 EXPECT_TRUE(state.ShouldTriggerBeginImplFrameDeadlineImmediately()); 1967 EXPECT_TRUE(state.ShouldTriggerBeginImplFrameDeadlineImmediately());
1936 state.OnBeginImplFrameDeadline(); 1968 state.OnBeginImplFrameDeadline();
1937 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE); 1969 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE);
1938 state.DidSubmitCompositorFrame(); 1970 state.DidSubmitCompositorFrame();
1939 } 1971 }
1940 1972
1941 TEST(SchedulerStateMachineTest, TestImplLatencyTakesPriority) { 1973 TEST(SchedulerStateMachineTest, TestImplLatencyTakesPriority) {
1942 SchedulerSettings default_scheduler_settings; 1974 SchedulerSettings default_scheduler_settings;
1943 StateMachine state(default_scheduler_settings); 1975 StateMachine state(default_scheduler_settings);
1944 SET_UP_STATE(state) 1976 SET_UP_STATE(state)
1945 1977
1946 // This test ensures that impl-draws are prioritized over main thread updates 1978 // This test ensures that impl-draws are prioritized over main thread updates
1947 // in prefer impl latency mode. 1979 // in prefer impl latency mode.
1948 state.SetNeedsRedraw(true); 1980 state.SetNeedsRedraw(true);
1949 state.SetNeedsBeginMainFrame(); 1981 state.SetNeedsBeginMainFrame();
1950 state.OnBeginImplFrame(); 1982 state.IssueNextBeginImplFrame();
1951 EXPECT_ACTION_UPDATE_STATE( 1983 EXPECT_ACTION_UPDATE_STATE(
1952 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 1984 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
1953 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1985 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1954 1986
1955 // Verify the deadline is not triggered early until we enter 1987 // Verify the deadline is not triggered early until we enter
1956 // prefer impl latency mode. 1988 // prefer impl latency mode.
1957 EXPECT_FALSE(state.ShouldTriggerBeginImplFrameDeadlineImmediately()); 1989 EXPECT_FALSE(state.ShouldTriggerBeginImplFrameDeadlineImmediately());
1958 state.SetTreePrioritiesAndScrollState( 1990 state.SetTreePrioritiesAndScrollState(
1959 SMOOTHNESS_TAKES_PRIORITY, 1991 SMOOTHNESS_TAKES_PRIORITY,
1960 ScrollHandlerState::SCROLL_DOES_NOT_AFFECT_SCROLL_HANDLER); 1992 ScrollHandlerState::SCROLL_DOES_NOT_AFFECT_SCROLL_HANDLER);
(...skipping 16 matching lines...) Expand all
1977 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 2009 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1978 2010
1979 // Finish the previous commit and draw it. 2011 // Finish the previous commit and draw it.
1980 FinishPreviousCommitAndDrawWithoutExitingDeadline(&state); 2012 FinishPreviousCommitAndDrawWithoutExitingDeadline(&state);
1981 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 2013 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1982 2014
1983 // Verify we do not send another BeginMainFrame if was are submit-frame 2015 // Verify we do not send another BeginMainFrame if was are submit-frame
1984 // throttled and did not just submit one. 2016 // throttled and did not just submit one.
1985 state.SetNeedsBeginMainFrame(); 2017 state.SetNeedsBeginMainFrame();
1986 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 2018 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1987 state.OnBeginImplFrame(); 2019 state.IssueNextBeginImplFrame();
1988 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 2020 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1989 EXPECT_FALSE(state.ShouldTriggerBeginImplFrameDeadlineImmediately()); 2021 EXPECT_FALSE(state.ShouldTriggerBeginImplFrameDeadlineImmediately());
1990 state.OnBeginImplFrameDeadline(); 2022 state.OnBeginImplFrameDeadline();
1991 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 2023 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1992 } 2024 }
1993 2025
1994 TEST(SchedulerStateMachineTest, 2026 TEST(SchedulerStateMachineTest,
1995 TestTriggerDeadlineImmediatelyOnLostCompositorFrameSink) { 2027 TestTriggerDeadlineImmediatelyOnLostCompositorFrameSink) {
1996 SchedulerSettings default_scheduler_settings; 2028 SchedulerSettings default_scheduler_settings;
1997 StateMachine state(default_scheduler_settings); 2029 StateMachine state(default_scheduler_settings);
1998 SET_UP_STATE(state) 2030 SET_UP_STATE(state)
1999 2031
2000 state.SetNeedsBeginMainFrame(); 2032 state.SetNeedsBeginMainFrame();
2001 2033
2002 state.OnBeginImplFrame(); 2034 state.IssueNextBeginImplFrame();
2003 EXPECT_ACTION_UPDATE_STATE( 2035 EXPECT_ACTION_UPDATE_STATE(
2004 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 2036 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
2005 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 2037 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
2006 EXPECT_FALSE(state.ShouldTriggerBeginImplFrameDeadlineImmediately()); 2038 EXPECT_FALSE(state.ShouldTriggerBeginImplFrameDeadlineImmediately());
2007 2039
2008 state.DidLoseCompositorFrameSink(); 2040 state.DidLoseCompositorFrameSink();
2009 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 2041 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
2010 // The deadline should be triggered immediately when CompositorFrameSink is 2042 // The deadline should be triggered immediately when CompositorFrameSink is
2011 // lost. 2043 // lost.
2012 EXPECT_TRUE(state.ShouldTriggerBeginImplFrameDeadlineImmediately()); 2044 EXPECT_TRUE(state.ShouldTriggerBeginImplFrameDeadlineImmediately());
2013 } 2045 }
2014 2046
2015 TEST(SchedulerStateMachineTest, TestTriggerDeadlineImmediatelyWhenInvisible) { 2047 TEST(SchedulerStateMachineTest, TestTriggerDeadlineImmediatelyWhenInvisible) {
2016 SchedulerSettings default_scheduler_settings; 2048 SchedulerSettings default_scheduler_settings;
2017 StateMachine state(default_scheduler_settings); 2049 StateMachine state(default_scheduler_settings);
2018 SET_UP_STATE(state) 2050 SET_UP_STATE(state)
2019 2051
2020 state.SetNeedsBeginMainFrame(); 2052 state.SetNeedsBeginMainFrame();
2021 2053
2022 state.OnBeginImplFrame(); 2054 state.IssueNextBeginImplFrame();
2023 EXPECT_ACTION_UPDATE_STATE( 2055 EXPECT_ACTION_UPDATE_STATE(
2024 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 2056 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
2025 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 2057 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
2026 EXPECT_FALSE(state.ShouldTriggerBeginImplFrameDeadlineImmediately()); 2058 EXPECT_FALSE(state.ShouldTriggerBeginImplFrameDeadlineImmediately());
2027 2059
2028 state.SetVisible(false); 2060 state.SetVisible(false);
2029 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 2061 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
2030 EXPECT_TRUE(state.PendingActivationsShouldBeForced()); 2062 EXPECT_TRUE(state.PendingActivationsShouldBeForced());
2031 EXPECT_TRUE(state.ShouldTriggerBeginImplFrameDeadlineImmediately()); 2063 EXPECT_TRUE(state.ShouldTriggerBeginImplFrameDeadlineImmediately());
2032 } 2064 }
2033 2065
2034 TEST(SchedulerStateMachineTest, 2066 TEST(SchedulerStateMachineTest,
2035 TestTriggerDeadlineImmediatelyWhenBeginFrameSourcePaused) { 2067 TestTriggerDeadlineImmediatelyWhenBeginFrameSourcePaused) {
2036 SchedulerSettings default_scheduler_settings; 2068 SchedulerSettings default_scheduler_settings;
2037 StateMachine state(default_scheduler_settings); 2069 StateMachine state(default_scheduler_settings);
2038 SET_UP_STATE(state) 2070 SET_UP_STATE(state)
2039 2071
2040 state.SetNeedsBeginMainFrame(); 2072 state.SetNeedsBeginMainFrame();
2041 2073
2042 state.OnBeginImplFrame(); 2074 state.IssueNextBeginImplFrame();
2043 EXPECT_ACTION_UPDATE_STATE( 2075 EXPECT_ACTION_UPDATE_STATE(
2044 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 2076 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
2045 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 2077 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
2046 EXPECT_FALSE(state.ShouldTriggerBeginImplFrameDeadlineImmediately()); 2078 EXPECT_FALSE(state.ShouldTriggerBeginImplFrameDeadlineImmediately());
2047 2079
2048 state.SetBeginFrameSourcePaused(true); 2080 state.SetBeginFrameSourcePaused(true);
2049 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 2081 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
2050 EXPECT_TRUE(state.PendingActivationsShouldBeForced()); 2082 EXPECT_TRUE(state.PendingActivationsShouldBeForced());
2051 EXPECT_TRUE(state.ShouldTriggerBeginImplFrameDeadlineImmediately()); 2083 EXPECT_TRUE(state.ShouldTriggerBeginImplFrameDeadlineImmediately());
2052 } 2084 }
2053 2085
2054 TEST(SchedulerStateMachineTest, TestDeferCommit) { 2086 TEST(SchedulerStateMachineTest, TestDeferCommit) {
2055 SchedulerSettings settings; 2087 SchedulerSettings settings;
2056 StateMachine state(settings); 2088 StateMachine state(settings);
2057 SET_UP_STATE(state) 2089 SET_UP_STATE(state)
2058 2090
2059 state.SetDeferCommits(true); 2091 state.SetDeferCommits(true);
2060 2092
2061 state.SetNeedsBeginMainFrame(); 2093 state.SetNeedsBeginMainFrame();
2062 EXPECT_FALSE(state.BeginFrameNeeded()); 2094 EXPECT_FALSE(state.BeginFrameNeeded());
2063 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 2095 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
2064 2096
2065 state.OnBeginImplFrame(); 2097 state.IssueNextBeginImplFrame();
2066 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 2098 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
2067 2099
2068 state.OnBeginImplFrameDeadline(); 2100 state.OnBeginImplFrameDeadline();
2069 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 2101 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
2070 2102
2071 state.SetDeferCommits(false); 2103 state.SetDeferCommits(false);
2072 state.OnBeginImplFrame(); 2104 state.IssueNextBeginImplFrame();
2073 EXPECT_ACTION_UPDATE_STATE( 2105 EXPECT_ACTION_UPDATE_STATE(
2074 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 2106 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
2075 } 2107 }
2076 2108
2077 TEST(SchedulerStateMachineTest, EarlyOutCommitWantsProactiveBeginFrame) { 2109 TEST(SchedulerStateMachineTest, EarlyOutCommitWantsProactiveBeginFrame) {
2078 SchedulerSettings settings; 2110 SchedulerSettings settings;
2079 StateMachine state(settings); 2111 StateMachine state(settings);
2080 SET_UP_STATE(state); 2112 SET_UP_STATE(state);
2081 2113
2082 EXPECT_FALSE(state.ProactiveBeginFrameWanted()); 2114 EXPECT_FALSE(state.ProactiveBeginFrameWanted());
2083 bool commit_has_no_updates = true; 2115 bool commit_has_no_updates = true;
2084 state.WillCommit(commit_has_no_updates); 2116 state.WillCommit(commit_has_no_updates);
2085 EXPECT_TRUE(state.ProactiveBeginFrameWanted()); 2117 EXPECT_TRUE(state.ProactiveBeginFrameWanted());
2086 state.OnBeginImplFrame(); 2118 state.IssueNextBeginImplFrame();
2087 EXPECT_FALSE(state.ProactiveBeginFrameWanted()); 2119 EXPECT_FALSE(state.ProactiveBeginFrameWanted());
2088 } 2120 }
2089 2121
2090 TEST(SchedulerStateMachineTest, 2122 TEST(SchedulerStateMachineTest,
2091 NoCompositorFrameSinkCreationWhileCommitPending) { 2123 NoCompositorFrameSinkCreationWhileCommitPending) {
2092 SchedulerSettings settings; 2124 SchedulerSettings settings;
2093 StateMachine state(settings); 2125 StateMachine state(settings);
2094 SET_UP_STATE(state); 2126 SET_UP_STATE(state);
2095 2127
2096 // Set up the request for a commit and start a frame. 2128 // Set up the request for a commit and start a frame.
2097 state.SetNeedsBeginMainFrame(); 2129 state.SetNeedsBeginMainFrame();
2098 state.OnBeginImplFrame(); 2130 state.IssueNextBeginImplFrame();
2099 PerformAction(&state, SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 2131 PerformAction(&state, SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
2100 2132
2101 // Lose the CompositorFrameSink. 2133 // Lose the CompositorFrameSink.
2102 state.DidLoseCompositorFrameSink(); 2134 state.DidLoseCompositorFrameSink();
2103 2135
2104 // The scheduler shouldn't trigger the CompositorFrameSink creation till the 2136 // The scheduler shouldn't trigger the CompositorFrameSink creation till the
2105 // previous commit has been cleared. 2137 // previous commit has been cleared.
2106 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 2138 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
2107 2139
2108 // Trigger the deadline and ensure that the scheduler does not trigger any 2140 // Trigger the deadline and ensure that the scheduler does not trigger any
2109 // actions until we receive a response for the pending commit. 2141 // actions until we receive a response for the pending commit.
2110 state.OnBeginImplFrameDeadline(); 2142 state.OnBeginImplFrameDeadline();
2111 state.OnBeginImplFrameIdle(); 2143 state.OnBeginImplFrameIdle();
2112 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 2144 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
2113 2145
2114 // Abort the commit, since that is what we expect the main thread to do if the 2146 // Abort the commit, since that is what we expect the main thread to do if the
2115 // CompositorFrameSink was lost due to a synchronous call from the main thread 2147 // CompositorFrameSink was lost due to a synchronous call from the main thread
2116 // to release the CompositorFrameSink. 2148 // to release the CompositorFrameSink.
2117 state.NotifyBeginMainFrameStarted(); 2149 state.NotifyBeginMainFrameStarted();
2118 state.BeginMainFrameAborted( 2150 state.BeginMainFrameAborted(
2119 CommitEarlyOutReason::ABORTED_COMPOSITOR_FRAME_SINK_LOST); 2151 CommitEarlyOutReason::ABORTED_COMPOSITOR_FRAME_SINK_LOST);
2120 2152
2121 // The scheduler should begin the CompositorFrameSink creation now. 2153 // The scheduler should begin the CompositorFrameSink creation now.
2122 EXPECT_ACTION_UPDATE_STATE( 2154 EXPECT_ACTION_UPDATE_STATE(
2123 SchedulerStateMachine::ACTION_BEGIN_COMPOSITOR_FRAME_SINK_CREATION); 2155 SchedulerStateMachine::ACTION_BEGIN_COMPOSITOR_FRAME_SINK_CREATION);
2124 } 2156 }
2125 2157
2158 TEST(SchedulerStateMachineTest, TestBeginFrameFreshnessInitialState) {
2159 SchedulerSettings default_scheduler_settings;
2160 StateMachine state(default_scheduler_settings);
2161 SET_UP_STATE(state)
2162
2163 // Initially, we report a valid current frame number, but invalid frame
2164 // numbers for freshness.
2165 EXPECT_SEQUENCE_NUMBERS(
2166 BeginFrameArgs::kStartingFrameNumber, BeginFrameArgs::kInvalidFrameNumber,
2167 BeginFrameArgs::kInvalidFrameNumber, BeginFrameArgs::kInvalidFrameNumber,
2168 BeginFrameArgs::kInvalidFrameNumber);
2169 }
2170
2171 TEST(SchedulerStateMachineTest, TestBeginFrameFreshnessWithoutUpdates) {
2172 // Setup without any requested updates.
2173 SchedulerSettings default_scheduler_settings;
2174 StateMachine state(default_scheduler_settings);
2175 SET_UP_STATE(state)
2176 state.SetNeedsRedraw(false);
2177 EXPECT_FALSE(state.RedrawPending());
2178 EXPECT_FALSE(state.NeedsCommit());
2179
2180 // OnBeginImplFrame() updates the sequence number.
2181 state.OnBeginImplFrame(0, 10);
2182 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
2183 EXPECT_SEQUENCE_NUMBERS(10u, BeginFrameArgs::kInvalidFrameNumber,
2184 BeginFrameArgs::kInvalidFrameNumber,
2185 BeginFrameArgs::kInvalidFrameNumber,
2186 BeginFrameArgs::kInvalidFrameNumber);
2187
2188 // When no updates are required, OnBeginImplFrameDeadline() updates active
2189 // tree and compositor frame freshness.
2190 state.OnBeginImplFrameDeadline();
2191 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
2192 EXPECT_SEQUENCE_NUMBERS(10u, BeginFrameArgs::kInvalidFrameNumber,
2193 BeginFrameArgs::kInvalidFrameNumber, 10u, 10u);
2194 state.OnBeginImplFrameIdle();
2195 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
2196 }
2197
2198 TEST(SchedulerStateMachineTest, TestBeginFrameFreshnessWithImplFrameUpdates) {
2199 // Setup with an impl-thread draw requested.
2200 SchedulerSettings default_scheduler_settings;
2201 StateMachine state(default_scheduler_settings);
2202 SET_UP_STATE(state)
2203 state.SetNeedsRedraw(true);
2204 EXPECT_TRUE(state.RedrawPending());
2205 EXPECT_FALSE(state.NeedsCommit());
2206
2207 // OnBeginImplFrame() updates the sequence number.
2208 state.OnBeginImplFrame(0, 10);
2209 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
2210 EXPECT_SEQUENCE_NUMBERS(10u, BeginFrameArgs::kInvalidFrameNumber,
2211 BeginFrameArgs::kInvalidFrameNumber,
2212 BeginFrameArgs::kInvalidFrameNumber,
2213 BeginFrameArgs::kInvalidFrameNumber);
2214
2215 // With only an impl-thread draw requested, OnBeginImplFrameDeadline()
2216 // updates the active tree freshness.
2217 state.OnBeginImplFrameDeadline();
2218 EXPECT_SEQUENCE_NUMBERS(10u, BeginFrameArgs::kInvalidFrameNumber,
2219 BeginFrameArgs::kInvalidFrameNumber, 10u,
2220 BeginFrameArgs::kInvalidFrameNumber);
2221
2222 // Compositor frame freshness is updated when active tree is drawn.
2223 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE);
2224 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
2225 EXPECT_FALSE(state.RedrawPending());
2226 state.DidSubmitCompositorFrame();
2227 state.DidReceiveCompositorFrameAck();
2228 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
2229 EXPECT_SEQUENCE_NUMBERS(10u, BeginFrameArgs::kInvalidFrameNumber,
2230 BeginFrameArgs::kInvalidFrameNumber, 10u, 10u);
2231 state.OnBeginImplFrameIdle();
2232 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
2233 }
2234
2235 TEST(SchedulerStateMachineTest, TestBeginFrameFreshnessWithMainFrameUpdates) {
2236 // Setup with a BeginMainFrame requested.
2237 SchedulerSettings default_scheduler_settings;
2238 StateMachine state(default_scheduler_settings);
2239 SET_UP_STATE(state)
2240 state.SetNeedsRedraw(false);
2241 state.SetNeedsBeginMainFrameForTest(true);
2242 EXPECT_FALSE(state.RedrawPending());
2243 EXPECT_TRUE(state.NeedsCommit());
2244
2245 // OnBeginImplFrame() updates the sequence number, WillSendBeginMainFrame()
2246 // updates begin_main_frame_sent sequence number.
2247 state.OnBeginImplFrame(0, 10);
2248 EXPECT_ACTION_UPDATE_STATE(
2249 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
2250 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
2251 EXPECT_FALSE(state.NeedsCommit());
2252 EXPECT_TRUE(state.CommitPending());
2253 EXPECT_SEQUENCE_NUMBERS(10u, 10u, BeginFrameArgs::kInvalidFrameNumber,
2254 BeginFrameArgs::kInvalidFrameNumber,
2255 BeginFrameArgs::kInvalidFrameNumber);
2256
2257 // When a BeginMainFrame is needed, OnBeginImplFrameDeadline() updates no
2258 // freshness numbers.
2259 state.OnBeginImplFrameDeadline();
2260 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
2261 EXPECT_SEQUENCE_NUMBERS(10u, 10u, BeginFrameArgs::kInvalidFrameNumber,
2262 BeginFrameArgs::kInvalidFrameNumber,
2263 BeginFrameArgs::kInvalidFrameNumber);
2264 state.OnBeginImplFrameIdle();
2265 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
2266
2267 // When a main frame is in progress, OnBeginImplFrameDeadline() updates no
2268 // freshness numbers.
2269 state.NotifyBeginMainFrameStarted();
2270 state.OnBeginImplFrame(0, 11);
2271 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
2272 state.OnBeginImplFrameDeadline();
2273 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
2274 EXPECT_SEQUENCE_NUMBERS(11u, 10u, BeginFrameArgs::kInvalidFrameNumber,
2275 BeginFrameArgs::kInvalidFrameNumber,
2276 BeginFrameArgs::kInvalidFrameNumber);
2277 state.OnBeginImplFrameIdle();
2278 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
2279
2280 // Pending tree freshness is updated when the new pending tree is committed.
2281 state.NotifyReadyToCommit();
2282 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
2283 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
2284 EXPECT_FALSE(state.CommitPending());
2285 EXPECT_TRUE(state.has_pending_tree());
2286 EXPECT_SEQUENCE_NUMBERS(11u, 10u, 10u, BeginFrameArgs::kInvalidFrameNumber,
2287 BeginFrameArgs::kInvalidFrameNumber);
2288
2289 // If no further BeginMainFrame is needed, OnBeginFrameImplDeadline()
2290 // updates the pending tree's frame number.
2291 state.OnBeginImplFrame(0, 12);
2292 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
2293 state.OnBeginImplFrameDeadline();
2294 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
2295 EXPECT_SEQUENCE_NUMBERS(12u, 10u, 12u, BeginFrameArgs::kInvalidFrameNumber,
brianderson 2017/02/15 00:13:54 Can you verify that before the deadline, the pendi
Eric Seckler 2017/02/17 00:07:27 Done.
2296 BeginFrameArgs::kInvalidFrameNumber);
2297 state.OnBeginImplFrameIdle();
2298 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
2299
2300 // If a further BeginMainFrame is needed, OnBeginFrameImplDeadline()
2301 // updates no freshness numbers.
2302 state.SetNeedsBeginMainFrameForTest(true);
2303 EXPECT_TRUE(state.NeedsCommit());
2304 state.OnBeginImplFrame(0, 13);
2305 // BMF will be sent only after pending_tree activation.
2306 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
2307 state.OnBeginImplFrameDeadline();
2308 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
2309 EXPECT_SEQUENCE_NUMBERS(13u, 10u, 12u, BeginFrameArgs::kInvalidFrameNumber,
2310 BeginFrameArgs::kInvalidFrameNumber);
2311 state.OnBeginImplFrameIdle();
2312 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
2313
2314 // Active tree freshness is updated when pending frame is activated.
2315 state.NotifyReadyToActivate();
2316 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE);
2317 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
2318 EXPECT_FALSE(state.has_pending_tree());
2319 EXPECT_SEQUENCE_NUMBERS(13u, 10u, 12u, 12u,
2320 BeginFrameArgs::kInvalidFrameNumber);
2321 EXPECT_TRUE(state.RedrawPending());
2322
2323 // BMF requested above will be sent after activation.
2324 state.OnBeginImplFrame(0, 14);
2325 EXPECT_ACTION_UPDATE_STATE(
2326 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
2327 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
2328
2329 // Active tree freshness is updated when commit didn't have updates.
2330 state.NotifyBeginMainFrameStarted();
2331 state.BeginMainFrameAborted(CommitEarlyOutReason::FINISHED_NO_UPDATES);
2332 EXPECT_SEQUENCE_NUMBERS(14u, 14u, 12u, 14u,
2333 BeginFrameArgs::kInvalidFrameNumber);
2334
2335 // Compositor frame freshness is updated when active tree is drawn.
2336 state.OnBeginImplFrameDeadline();
2337 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE);
2338 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
2339 EXPECT_FALSE(state.RedrawPending());
2340 state.DidSubmitCompositorFrame();
2341 state.DidReceiveCompositorFrameAck();
2342 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
2343 EXPECT_SEQUENCE_NUMBERS(14u, 14u, 12u, 14u, 14u);
2344 state.OnBeginImplFrameIdle();
2345 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
2346
2347 // When no updates are required, OnBeginImplFrameDeadline() updates active
2348 // tree and compositor frame freshness.
2349 state.OnBeginImplFrame(0, 15);
2350 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
2351 state.OnBeginImplFrameDeadline();
2352 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
2353 EXPECT_SEQUENCE_NUMBERS(15u, 14u, 12u, 15u, 15u);
2354 state.OnBeginImplFrameIdle();
2355 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
2356
2357 // When the source changes, the current frame number is updated and frame
2358 // numbers for freshness are reset to invalid numbers.
2359 state.OnBeginImplFrame(1, 5);
2360 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
2361 EXPECT_SEQUENCE_NUMBERS(5u, BeginFrameArgs::kInvalidFrameNumber,
2362 BeginFrameArgs::kInvalidFrameNumber,
2363 BeginFrameArgs::kInvalidFrameNumber,
2364 BeginFrameArgs::kInvalidFrameNumber);
2365
2366 // When no updates are required, OnBeginImplFrameDeadline() updates active
2367 // tree and compositor frame freshness.
2368 state.OnBeginImplFrameDeadline();
2369 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
2370 EXPECT_SEQUENCE_NUMBERS(5u, BeginFrameArgs::kInvalidFrameNumber,
2371 BeginFrameArgs::kInvalidFrameNumber, 5u, 5u);
2372 state.OnBeginImplFrameIdle();
2373 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
2374 }
2375
2376 TEST(SchedulerStateMachineTest,
2377 TestBeginFrameFreshnessWithNoUpdatesCommitAndPendingTree) {
2378 // Setup with main_frame_before_activation_enabled, a pending tree, and a
2379 // new BeginMainFrame requested.
2380 SchedulerSettings settings;
2381 settings.main_frame_before_activation_enabled = true;
2382 StateMachine state(settings);
2383 SET_UP_STATE(state)
2384 state.SetHasPendingTree(true);
2385 state.SetNeedsRedraw(false);
2386 state.SetNeedsBeginMainFrameForTest(true);
2387 EXPECT_FALSE(state.RedrawPending());
2388 EXPECT_TRUE(state.NeedsCommit());
2389
2390 // OnBeginImplFrame() updates the sequence number, WillSendBeginMainFrame()
2391 // updates begin_main_frame_sent sequence number.
2392 state.OnBeginImplFrame(0, 10);
2393 EXPECT_ACTION_UPDATE_STATE(
2394 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
2395 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
2396 EXPECT_FALSE(state.NeedsCommit());
2397 EXPECT_TRUE(state.CommitPending());
2398 EXPECT_SEQUENCE_NUMBERS(10u, 10u, BeginFrameArgs::kInvalidFrameNumber,
2399 BeginFrameArgs::kInvalidFrameNumber,
2400 BeginFrameArgs::kInvalidFrameNumber);
2401
2402 // Pending tree freshness is updated when commit didn't have updates, but an
2403 // older pending tree is still pending.
2404 state.NotifyBeginMainFrameStarted();
2405 state.BeginMainFrameAborted(CommitEarlyOutReason::FINISHED_NO_UPDATES);
2406 EXPECT_SEQUENCE_NUMBERS(10u, 10u, 10u, BeginFrameArgs::kInvalidFrameNumber,
2407 BeginFrameArgs::kInvalidFrameNumber);
2408
2409 // As no further BeginMainFrame is needed, OnBeginFrameImplDeadline()
2410 // updates the pending tree's frame number, but without any visible change.
2411 state.OnBeginImplFrameDeadline();
2412 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
2413 EXPECT_SEQUENCE_NUMBERS(10u, 10u, 10u, BeginFrameArgs::kInvalidFrameNumber,
2414 BeginFrameArgs::kInvalidFrameNumber);
2415 state.OnBeginImplFrameIdle();
2416 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
2417 }
2418
2126 } // namespace 2419 } // namespace
2127 } // namespace cc 2420 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698