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

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: add todo for impl-side invalidations. 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
« no previous file with comments | « cc/scheduler/scheduler_state_machine.cc ('k') | cc/scheduler/scheduler_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2011 The Chromium Authors. All rights reserved. 1 // Copyright 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
153 bool needs_impl_side_invalidation() const { 171 bool needs_impl_side_invalidation() const {
154 return needs_impl_side_invalidation_; 172 return needs_impl_side_invalidation_;
155 } 173 }
156 174
175 uint64_t begin_frame_sequence_number() const {
176 return begin_frame_sequence_number_;
177 }
178 uint64_t last_begin_frame_sequence_number_begin_main_frame_sent() const {
179 return last_begin_frame_sequence_number_begin_main_frame_sent_;
180 }
181 uint64_t last_begin_frame_sequence_number_pending_tree_was_fresh() const {
182 return last_begin_frame_sequence_number_pending_tree_was_fresh_;
183 }
184 uint64_t last_begin_frame_sequence_number_active_tree_was_fresh() const {
185 return last_begin_frame_sequence_number_active_tree_was_fresh_;
186 }
187
157 using SchedulerStateMachine::ShouldTriggerBeginImplFrameDeadlineImmediately; 188 using SchedulerStateMachine::ShouldTriggerBeginImplFrameDeadlineImmediately;
158 using SchedulerStateMachine::ProactiveBeginFrameWanted; 189 using SchedulerStateMachine::ProactiveBeginFrameWanted;
159 using SchedulerStateMachine::WillCommit; 190 using SchedulerStateMachine::WillCommit;
160 191
161 protected: 192 protected:
162 DrawResult draw_result_for_test_; 193 DrawResult draw_result_for_test_;
194 uint64_t next_begin_frame_number_ = BeginFrameArgs::kStartingFrameNumber;
163 }; 195 };
164 196
165 void PerformAction(StateMachine* sm, SchedulerStateMachine::Action action) { 197 void PerformAction(StateMachine* sm, SchedulerStateMachine::Action action) {
166 switch (action) { 198 switch (action) {
167 case SchedulerStateMachine::ACTION_NONE: 199 case SchedulerStateMachine::ACTION_NONE:
168 return; 200 return;
169 201
170 case SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE: 202 case SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE:
171 sm->WillActivate(); 203 sm->WillActivate();
172 return; 204 return;
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 SchedulerStateMachine::ACTION_BEGIN_COMPOSITOR_FRAME_SINK_CREATION); 304 SchedulerStateMachine::ACTION_BEGIN_COMPOSITOR_FRAME_SINK_CREATION);
273 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 305 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
274 state.CreateAndInitializeCompositorFrameSinkWithActivatedCommit(); 306 state.CreateAndInitializeCompositorFrameSinkWithActivatedCommit();
275 state.SetBeginMainFrameState( 307 state.SetBeginMainFrameState(
276 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_IDLE); 308 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_IDLE);
277 state.SetNeedsRedraw(false); 309 state.SetNeedsRedraw(false);
278 310
279 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 311 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
280 EXPECT_FALSE(state.NeedsCommit()); 312 EXPECT_FALSE(state.NeedsCommit());
281 313
282 state.OnBeginImplFrame(); 314 state.IssueNextBeginImplFrame();
283 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 315 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
284 316
285 state.OnBeginImplFrameDeadline(); 317 state.OnBeginImplFrameDeadline();
286 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 318 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
287 EXPECT_FALSE(state.NeedsCommit()); 319 EXPECT_FALSE(state.NeedsCommit());
288 } 320 }
289 321
290 // If commit requested but not visible yet, do nothing. 322 // If commit requested but not visible yet, do nothing.
291 { 323 {
292 StateMachine state(default_scheduler_settings); 324 StateMachine state(default_scheduler_settings);
293 state.SetBeginMainFrameState( 325 state.SetBeginMainFrameState(
294 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_IDLE); 326 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_IDLE);
295 state.SetNeedsRedraw(false); 327 state.SetNeedsRedraw(false);
296 state.SetNeedsBeginMainFrame(); 328 state.SetNeedsBeginMainFrame();
297 329
298 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 330 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
299 EXPECT_TRUE(state.NeedsCommit()); 331 EXPECT_TRUE(state.NeedsCommit());
300 332
301 state.OnBeginImplFrame(); 333 state.IssueNextBeginImplFrame();
302 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 334 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
303 335
304 state.OnBeginImplFrameDeadline(); 336 state.OnBeginImplFrameDeadline();
305 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 337 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
306 EXPECT_TRUE(state.NeedsCommit()); 338 EXPECT_TRUE(state.NeedsCommit());
307 } 339 }
308 340
309 // If commit requested, begin a main frame. 341 // If commit requested, begin a main frame.
310 { 342 {
311 StateMachine state(default_scheduler_settings); 343 StateMachine state(default_scheduler_settings);
312 state.SetBeginMainFrameState( 344 state.SetBeginMainFrameState(
313 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_IDLE); 345 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_IDLE);
314 state.SetVisible(true); 346 state.SetVisible(true);
315 EXPECT_ACTION_UPDATE_STATE( 347 EXPECT_ACTION_UPDATE_STATE(
316 SchedulerStateMachine::ACTION_BEGIN_COMPOSITOR_FRAME_SINK_CREATION); 348 SchedulerStateMachine::ACTION_BEGIN_COMPOSITOR_FRAME_SINK_CREATION);
317 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 349 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
318 state.CreateAndInitializeCompositorFrameSinkWithActivatedCommit(); 350 state.CreateAndInitializeCompositorFrameSinkWithActivatedCommit();
319 state.SetNeedsRedraw(false); 351 state.SetNeedsRedraw(false);
320 state.SetNeedsBeginMainFrame(); 352 state.SetNeedsBeginMainFrame();
321 353
322 // Expect nothing to happen until after OnBeginImplFrame. 354 // Expect nothing to happen until after OnBeginImplFrame.
323 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 355 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
324 EXPECT_MAIN_FRAME_STATE(SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_IDLE); 356 EXPECT_MAIN_FRAME_STATE(SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_IDLE);
325 EXPECT_IMPL_FRAME_STATE(SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE); 357 EXPECT_IMPL_FRAME_STATE(SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE);
326 EXPECT_TRUE(state.NeedsCommit()); 358 EXPECT_TRUE(state.NeedsCommit());
327 EXPECT_TRUE(state.BeginFrameNeeded()); 359 EXPECT_TRUE(state.BeginFrameNeeded());
328 360
329 state.OnBeginImplFrame(); 361 state.IssueNextBeginImplFrame();
330 EXPECT_ACTION_UPDATE_STATE( 362 EXPECT_ACTION_UPDATE_STATE(
331 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 363 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
332 EXPECT_MAIN_FRAME_STATE(SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_SENT); 364 EXPECT_MAIN_FRAME_STATE(SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_SENT);
333 EXPECT_FALSE(state.NeedsCommit()); 365 EXPECT_FALSE(state.NeedsCommit());
334 } 366 }
335 367
336 // If commit requested and can't draw, still begin a main frame. 368 // If commit requested and can't draw, still begin a main frame.
337 { 369 {
338 StateMachine state(default_scheduler_settings); 370 StateMachine state(default_scheduler_settings);
339 state.SetBeginMainFrameState( 371 state.SetBeginMainFrameState(
340 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_IDLE); 372 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_IDLE);
341 state.SetVisible(true); 373 state.SetVisible(true);
342 EXPECT_ACTION_UPDATE_STATE( 374 EXPECT_ACTION_UPDATE_STATE(
343 SchedulerStateMachine::ACTION_BEGIN_COMPOSITOR_FRAME_SINK_CREATION); 375 SchedulerStateMachine::ACTION_BEGIN_COMPOSITOR_FRAME_SINK_CREATION);
344 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 376 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
345 state.CreateAndInitializeCompositorFrameSinkWithActivatedCommit(); 377 state.CreateAndInitializeCompositorFrameSinkWithActivatedCommit();
346 state.SetNeedsRedraw(false); 378 state.SetNeedsRedraw(false);
347 state.SetNeedsBeginMainFrame(); 379 state.SetNeedsBeginMainFrame();
348 state.SetCanDraw(false); 380 state.SetCanDraw(false);
349 381
350 // Expect nothing to happen until after OnBeginImplFrame. 382 // Expect nothing to happen until after OnBeginImplFrame.
351 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 383 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
352 EXPECT_MAIN_FRAME_STATE(SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_IDLE); 384 EXPECT_MAIN_FRAME_STATE(SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_IDLE);
353 EXPECT_IMPL_FRAME_STATE(SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE); 385 EXPECT_IMPL_FRAME_STATE(SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE);
354 EXPECT_TRUE(state.BeginFrameNeeded()); 386 EXPECT_TRUE(state.BeginFrameNeeded());
355 387
356 state.OnBeginImplFrame(); 388 state.IssueNextBeginImplFrame();
357 EXPECT_ACTION_UPDATE_STATE( 389 EXPECT_ACTION_UPDATE_STATE(
358 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 390 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
359 EXPECT_MAIN_FRAME_STATE(SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_SENT); 391 EXPECT_MAIN_FRAME_STATE(SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_SENT);
360 EXPECT_FALSE(state.NeedsCommit()); 392 EXPECT_FALSE(state.NeedsCommit());
361 } 393 }
362 } 394 }
363 395
364 // Explicitly test main_frame_before_activation_enabled = true 396 // Explicitly test main_frame_before_activation_enabled = true
365 TEST(SchedulerStateMachineTest, MainFrameBeforeActivationEnabled) { 397 TEST(SchedulerStateMachineTest, MainFrameBeforeActivationEnabled) {
366 SchedulerSettings scheduler_settings; 398 SchedulerSettings scheduler_settings;
367 scheduler_settings.main_frame_before_activation_enabled = true; 399 scheduler_settings.main_frame_before_activation_enabled = true;
368 StateMachine state(scheduler_settings); 400 StateMachine state(scheduler_settings);
369 state.SetBeginMainFrameState( 401 state.SetBeginMainFrameState(
370 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_IDLE); 402 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_IDLE);
371 SET_UP_STATE(state) 403 SET_UP_STATE(state)
372 state.SetNeedsRedraw(false); 404 state.SetNeedsRedraw(false);
373 state.SetNeedsBeginMainFrame(); 405 state.SetNeedsBeginMainFrame();
374 406
375 EXPECT_TRUE(state.BeginFrameNeeded()); 407 EXPECT_TRUE(state.BeginFrameNeeded());
376 408
377 // Commit to the pending tree. 409 // Commit to the pending tree.
378 state.OnBeginImplFrame(); 410 state.IssueNextBeginImplFrame();
379 EXPECT_ACTION_UPDATE_STATE( 411 EXPECT_ACTION_UPDATE_STATE(
380 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 412 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
381 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 413 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
382 414
383 state.NotifyBeginMainFrameStarted(); 415 state.NotifyBeginMainFrameStarted();
384 state.NotifyReadyToCommit(); 416 state.NotifyReadyToCommit();
385 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 417 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
386 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 418 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
387 EXPECT_MAIN_FRAME_STATE(SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_IDLE); 419 EXPECT_MAIN_FRAME_STATE(SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_IDLE);
388 420
389 state.OnBeginImplFrameDeadline(); 421 state.OnBeginImplFrameDeadline();
390 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 422 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
391 423
392 // Verify that the next commit starts while there is still a pending tree. 424 // Verify that the next commit starts while there is still a pending tree.
393 state.SetNeedsBeginMainFrame(); 425 state.SetNeedsBeginMainFrame();
394 state.OnBeginImplFrame(); 426 state.IssueNextBeginImplFrame();
395 EXPECT_ACTION_UPDATE_STATE( 427 EXPECT_ACTION_UPDATE_STATE(
396 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 428 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
397 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 429 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
398 430
399 // Verify the pending commit doesn't overwrite the pending 431 // Verify the pending commit doesn't overwrite the pending
400 // tree until the pending tree has been activated. 432 // tree until the pending tree has been activated.
401 state.NotifyBeginMainFrameStarted(); 433 state.NotifyBeginMainFrameStarted();
402 state.NotifyReadyToCommit(); 434 state.NotifyReadyToCommit();
403 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 435 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
404 436
(...skipping 16 matching lines...) Expand all
421 TEST(SchedulerStateMachineTest, 453 TEST(SchedulerStateMachineTest,
422 FailedDrawForAnimationCheckerboardSetsNeedsCommitAndRetriesDraw) { 454 FailedDrawForAnimationCheckerboardSetsNeedsCommitAndRetriesDraw) {
423 SchedulerSettings default_scheduler_settings; 455 SchedulerSettings default_scheduler_settings;
424 StateMachine state(default_scheduler_settings); 456 StateMachine state(default_scheduler_settings);
425 SET_UP_STATE(state) 457 SET_UP_STATE(state)
426 state.SetNeedsRedraw(true); 458 state.SetNeedsRedraw(true);
427 EXPECT_TRUE(state.RedrawPending()); 459 EXPECT_TRUE(state.RedrawPending());
428 EXPECT_TRUE(state.BeginFrameNeeded()); 460 EXPECT_TRUE(state.BeginFrameNeeded());
429 461
430 // Start a frame. 462 // Start a frame.
431 state.OnBeginImplFrame(); 463 state.IssueNextBeginImplFrame();
432 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 464 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
433 EXPECT_FALSE(state.CommitPending()); 465 EXPECT_FALSE(state.CommitPending());
434 466
435 // Failing a draw triggers request for a new BeginMainFrame. 467 // Failing a draw triggers request for a new BeginMainFrame.
436 state.OnBeginImplFrameDeadline(); 468 state.OnBeginImplFrameDeadline();
437 state.SetDrawResultForTest(DRAW_ABORTED_CHECKERBOARD_ANIMATIONS); 469 state.SetDrawResultForTest(DRAW_ABORTED_CHECKERBOARD_ANIMATIONS);
438 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE); 470 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE);
439 EXPECT_ACTION_UPDATE_STATE( 471 EXPECT_ACTION_UPDATE_STATE(
440 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 472 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
441 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 473 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
442 state.OnBeginImplFrameIdle(); 474 state.OnBeginImplFrameIdle();
443 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 475 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
444 476
445 // It's okay to attempt more draws just in case additional raster 477 // It's okay to attempt more draws just in case additional raster
446 // finishes and the requested commit wasn't actually necessary. 478 // finishes and the requested commit wasn't actually necessary.
447 EXPECT_TRUE(state.CommitPending()); 479 EXPECT_TRUE(state.CommitPending());
448 EXPECT_TRUE(state.RedrawPending()); 480 EXPECT_TRUE(state.RedrawPending());
449 state.OnBeginImplFrame(); 481 state.IssueNextBeginImplFrame();
450 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 482 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
451 state.OnBeginImplFrameDeadline(); 483 state.OnBeginImplFrameDeadline();
452 state.SetDrawResultForTest(DRAW_ABORTED_CHECKERBOARD_ANIMATIONS); 484 state.SetDrawResultForTest(DRAW_ABORTED_CHECKERBOARD_ANIMATIONS);
453 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE); 485 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE);
454 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 486 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
455 state.OnBeginImplFrameIdle(); 487 state.OnBeginImplFrameIdle();
456 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 488 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
457 } 489 }
458 490
459 TEST(SchedulerStateMachineTest, FailedDrawForMissingHighResNeedsCommit) { 491 TEST(SchedulerStateMachineTest, FailedDrawForMissingHighResNeedsCommit) {
460 SchedulerSettings default_scheduler_settings; 492 SchedulerSettings default_scheduler_settings;
461 StateMachine state(default_scheduler_settings); 493 StateMachine state(default_scheduler_settings);
462 SET_UP_STATE(state) 494 SET_UP_STATE(state)
463 state.SetNeedsRedraw(true); 495 state.SetNeedsRedraw(true);
464 EXPECT_TRUE(state.RedrawPending()); 496 EXPECT_TRUE(state.RedrawPending());
465 EXPECT_TRUE(state.BeginFrameNeeded()); 497 EXPECT_TRUE(state.BeginFrameNeeded());
466 498
467 // Start a frame. 499 // Start a frame.
468 state.OnBeginImplFrame(); 500 state.IssueNextBeginImplFrame();
469 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 501 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
470 EXPECT_FALSE(state.CommitPending()); 502 EXPECT_FALSE(state.CommitPending());
471 503
472 // Failing a draw triggers because of high res tiles missing 504 // Failing a draw triggers because of high res tiles missing
473 // request for a new BeginMainFrame. 505 // request for a new BeginMainFrame.
474 state.OnBeginImplFrameDeadline(); 506 state.OnBeginImplFrameDeadline();
475 state.SetDrawResultForTest(DRAW_ABORTED_MISSING_HIGH_RES_CONTENT); 507 state.SetDrawResultForTest(DRAW_ABORTED_MISSING_HIGH_RES_CONTENT);
476 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE); 508 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE);
477 EXPECT_ACTION_UPDATE_STATE( 509 EXPECT_ACTION_UPDATE_STATE(
478 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 510 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
479 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 511 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
480 state.OnBeginImplFrameIdle(); 512 state.OnBeginImplFrameIdle();
481 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 513 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
482 514
483 // It doesn't request a draw until we get a new commit though. 515 // It doesn't request a draw until we get a new commit though.
484 EXPECT_TRUE(state.CommitPending()); 516 EXPECT_TRUE(state.CommitPending());
485 EXPECT_FALSE(state.RedrawPending()); 517 EXPECT_FALSE(state.RedrawPending());
486 state.OnBeginImplFrame(); 518 state.IssueNextBeginImplFrame();
487 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 519 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
488 state.OnBeginImplFrameDeadline(); 520 state.OnBeginImplFrameDeadline();
489 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 521 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
490 state.OnBeginImplFrameIdle(); 522 state.OnBeginImplFrameIdle();
491 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 523 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
492 524
493 // Finish the commit and activation. 525 // Finish the commit and activation.
494 state.NotifyBeginMainFrameStarted(); 526 state.NotifyBeginMainFrameStarted();
495 state.NotifyReadyToCommit(); 527 state.NotifyReadyToCommit();
496 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 528 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
497 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 529 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
498 state.NotifyReadyToActivate(); 530 state.NotifyReadyToActivate();
499 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE); 531 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE);
500 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 532 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
501 EXPECT_TRUE(state.RedrawPending()); 533 EXPECT_TRUE(state.RedrawPending());
502 534
503 // Verify we draw with the new frame. 535 // Verify we draw with the new frame.
504 state.OnBeginImplFrame(); 536 state.IssueNextBeginImplFrame();
505 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 537 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
506 state.OnBeginImplFrameDeadline(); 538 state.OnBeginImplFrameDeadline();
507 state.SetDrawResultForTest(DRAW_SUCCESS); 539 state.SetDrawResultForTest(DRAW_SUCCESS);
508 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE); 540 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE);
509 state.DidSubmitCompositorFrame(); 541 state.DidSubmitCompositorFrame();
510 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 542 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
511 state.OnBeginImplFrameIdle(); 543 state.OnBeginImplFrameIdle();
512 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 544 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
513 } 545 }
514 546
515 TEST(SchedulerStateMachineTest, 547 TEST(SchedulerStateMachineTest,
516 TestFailedDrawsEventuallyForceDrawAfterNextCommit) { 548 TestFailedDrawsEventuallyForceDrawAfterNextCommit) {
517 SchedulerSettings scheduler_settings; 549 SchedulerSettings scheduler_settings;
518 scheduler_settings.maximum_number_of_failed_draws_before_draw_is_forced = 1; 550 scheduler_settings.maximum_number_of_failed_draws_before_draw_is_forced = 1;
519 StateMachine state(scheduler_settings); 551 StateMachine state(scheduler_settings);
520 SET_UP_STATE(state) 552 SET_UP_STATE(state)
521 553
522 // Start a commit. 554 // Start a commit.
523 state.SetNeedsBeginMainFrame(); 555 state.SetNeedsBeginMainFrame();
524 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 556 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
525 state.OnBeginImplFrame(); 557 state.IssueNextBeginImplFrame();
526 EXPECT_ACTION_UPDATE_STATE( 558 EXPECT_ACTION_UPDATE_STATE(
527 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 559 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
528 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 560 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
529 EXPECT_TRUE(state.CommitPending()); 561 EXPECT_TRUE(state.CommitPending());
530 562
531 // Then initiate a draw that fails. 563 // Then initiate a draw that fails.
532 state.SetNeedsRedraw(true); 564 state.SetNeedsRedraw(true);
533 state.OnBeginImplFrameDeadline(); 565 state.OnBeginImplFrameDeadline();
534 state.SetDrawResultForTest(DRAW_ABORTED_CHECKERBOARD_ANIMATIONS); 566 state.SetDrawResultForTest(DRAW_ABORTED_CHECKERBOARD_ANIMATIONS);
535 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE); 567 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE);
(...skipping 10 matching lines...) Expand all
546 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 578 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
547 EXPECT_TRUE(state.RedrawPending()); 579 EXPECT_TRUE(state.RedrawPending());
548 580
549 // Activate so we're ready for a new main frame. 581 // Activate so we're ready for a new main frame.
550 state.NotifyReadyToActivate(); 582 state.NotifyReadyToActivate();
551 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE); 583 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE);
552 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 584 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
553 EXPECT_TRUE(state.RedrawPending()); 585 EXPECT_TRUE(state.RedrawPending());
554 586
555 // The redraw should be forced at the end of the next BeginImplFrame. 587 // The redraw should be forced at the end of the next BeginImplFrame.
556 state.OnBeginImplFrame(); 588 state.IssueNextBeginImplFrame();
557 EXPECT_ACTION_UPDATE_STATE( 589 EXPECT_ACTION_UPDATE_STATE(
558 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 590 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
559 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 591 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
560 state.OnBeginImplFrameDeadline(); 592 state.OnBeginImplFrameDeadline();
561 state.SetDrawResultForTest(DRAW_SUCCESS); 593 state.SetDrawResultForTest(DRAW_SUCCESS);
562 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_FORCED); 594 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_FORCED);
563 state.DidSubmitCompositorFrame(); 595 state.DidSubmitCompositorFrame();
564 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 596 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
565 state.DidReceiveCompositorFrameAck(); 597 state.DidReceiveCompositorFrameAck();
566 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 598 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
567 } 599 }
568 600
569 TEST(SchedulerStateMachineTest, TestFailedDrawsDoNotRestartForcedDraw) { 601 TEST(SchedulerStateMachineTest, TestFailedDrawsDoNotRestartForcedDraw) {
570 SchedulerSettings scheduler_settings; 602 SchedulerSettings scheduler_settings;
571 int draw_limit = 2; 603 int draw_limit = 2;
572 scheduler_settings.maximum_number_of_failed_draws_before_draw_is_forced = 604 scheduler_settings.maximum_number_of_failed_draws_before_draw_is_forced =
573 draw_limit; 605 draw_limit;
574 StateMachine state(scheduler_settings); 606 StateMachine state(scheduler_settings);
575 SET_UP_STATE(state) 607 SET_UP_STATE(state)
576 608
577 // Start a commit. 609 // Start a commit.
578 state.SetNeedsBeginMainFrame(); 610 state.SetNeedsBeginMainFrame();
579 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 611 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
580 state.OnBeginImplFrame(); 612 state.IssueNextBeginImplFrame();
581 EXPECT_ACTION_UPDATE_STATE( 613 EXPECT_ACTION_UPDATE_STATE(
582 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 614 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
583 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 615 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
584 EXPECT_TRUE(state.CommitPending()); 616 EXPECT_TRUE(state.CommitPending());
585 617
586 // Then initiate a draw. 618 // Then initiate a draw.
587 state.SetNeedsRedraw(true); 619 state.SetNeedsRedraw(true);
588 state.OnBeginImplFrameDeadline(); 620 state.OnBeginImplFrameDeadline();
589 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE); 621 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE);
590 622
591 // Fail the draw enough times to force a redraw. 623 // Fail the draw enough times to force a redraw.
592 for (int i = 0; i < draw_limit; ++i) { 624 for (int i = 0; i < draw_limit; ++i) {
593 state.SetNeedsRedraw(true); 625 state.SetNeedsRedraw(true);
594 state.OnBeginImplFrame(); 626 state.IssueNextBeginImplFrame();
595 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 627 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
596 state.OnBeginImplFrameDeadline(); 628 state.OnBeginImplFrameDeadline();
597 state.SetDrawResultForTest(DRAW_ABORTED_CHECKERBOARD_ANIMATIONS); 629 state.SetDrawResultForTest(DRAW_ABORTED_CHECKERBOARD_ANIMATIONS);
598 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE); 630 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE);
599 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 631 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
600 state.OnBeginImplFrameIdle(); 632 state.OnBeginImplFrameIdle();
601 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 633 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
602 } 634 }
603 635
604 EXPECT_TRUE(state.BeginFrameNeeded()); 636 EXPECT_TRUE(state.BeginFrameNeeded());
605 EXPECT_TRUE(state.RedrawPending()); 637 EXPECT_TRUE(state.RedrawPending());
606 // But the commit is ongoing. 638 // But the commit is ongoing.
607 EXPECT_TRUE(state.CommitPending()); 639 EXPECT_TRUE(state.CommitPending());
608 EXPECT_TRUE(state.ForcedRedrawState() == 640 EXPECT_TRUE(state.ForcedRedrawState() ==
609 SchedulerStateMachine::FORCED_REDRAW_STATE_WAITING_FOR_COMMIT); 641 SchedulerStateMachine::FORCED_REDRAW_STATE_WAITING_FOR_COMMIT);
610 642
611 // After failing additional draws, we should still be in a forced 643 // After failing additional draws, we should still be in a forced
612 // redraw, but not back in IDLE. 644 // redraw, but not back in IDLE.
613 for (int i = 0; i < draw_limit; ++i) { 645 for (int i = 0; i < draw_limit; ++i) {
614 state.SetNeedsRedraw(true); 646 state.SetNeedsRedraw(true);
615 state.OnBeginImplFrame(); 647 state.IssueNextBeginImplFrame();
616 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 648 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
617 state.OnBeginImplFrameDeadline(); 649 state.OnBeginImplFrameDeadline();
618 state.SetDrawResultForTest(DRAW_ABORTED_CHECKERBOARD_ANIMATIONS); 650 state.SetDrawResultForTest(DRAW_ABORTED_CHECKERBOARD_ANIMATIONS);
619 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE); 651 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE);
620 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 652 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
621 state.OnBeginImplFrameIdle(); 653 state.OnBeginImplFrameIdle();
622 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 654 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
623 } 655 }
624 EXPECT_TRUE(state.RedrawPending()); 656 EXPECT_TRUE(state.RedrawPending());
625 EXPECT_TRUE(state.ForcedRedrawState() == 657 EXPECT_TRUE(state.ForcedRedrawState() ==
626 SchedulerStateMachine::FORCED_REDRAW_STATE_WAITING_FOR_COMMIT); 658 SchedulerStateMachine::FORCED_REDRAW_STATE_WAITING_FOR_COMMIT);
627 } 659 }
628 660
629 TEST(SchedulerStateMachineTest, TestFailedDrawIsRetriedInNextBeginImplFrame) { 661 TEST(SchedulerStateMachineTest, TestFailedDrawIsRetriedInNextBeginImplFrame) {
630 SchedulerSettings default_scheduler_settings; 662 SchedulerSettings default_scheduler_settings;
631 StateMachine state(default_scheduler_settings); 663 StateMachine state(default_scheduler_settings);
632 SET_UP_STATE(state) 664 SET_UP_STATE(state)
633 665
634 // Start a draw. 666 // Start a draw.
635 state.SetNeedsRedraw(true); 667 state.SetNeedsRedraw(true);
636 EXPECT_TRUE(state.BeginFrameNeeded()); 668 EXPECT_TRUE(state.BeginFrameNeeded());
637 state.OnBeginImplFrame(); 669 state.IssueNextBeginImplFrame();
638 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 670 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
639 state.OnBeginImplFrameDeadline(); 671 state.OnBeginImplFrameDeadline();
640 EXPECT_TRUE(state.RedrawPending()); 672 EXPECT_TRUE(state.RedrawPending());
641 state.SetDrawResultForTest(DRAW_ABORTED_CHECKERBOARD_ANIMATIONS); 673 state.SetDrawResultForTest(DRAW_ABORTED_CHECKERBOARD_ANIMATIONS);
642 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE); 674 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE);
643 675
644 // Failing the draw for animation checkerboards makes us require a commit. 676 // Failing the draw for animation checkerboards makes us require a commit.
645 EXPECT_ACTION_UPDATE_STATE( 677 EXPECT_ACTION_UPDATE_STATE(
646 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 678 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
647 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 679 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
648 EXPECT_TRUE(state.RedrawPending()); 680 EXPECT_TRUE(state.RedrawPending());
649 681
650 // We should not be trying to draw again now, but we have a commit pending. 682 // We should not be trying to draw again now, but we have a commit pending.
651 EXPECT_TRUE(state.BeginFrameNeeded()); 683 EXPECT_TRUE(state.BeginFrameNeeded());
652 state.OnBeginImplFrame(); 684 state.IssueNextBeginImplFrame();
653 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 685 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
654 686
655 // We should try to draw again at the end of the next BeginImplFrame on 687 // We should try to draw again at the end of the next BeginImplFrame on
656 // the impl thread. 688 // the impl thread.
657 state.OnBeginImplFrameDeadline(); 689 state.OnBeginImplFrameDeadline();
658 state.SetDrawResultForTest(DRAW_SUCCESS); 690 state.SetDrawResultForTest(DRAW_SUCCESS);
659 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE); 691 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE);
660 state.DidSubmitCompositorFrame(); 692 state.DidSubmitCompositorFrame();
661 state.DidReceiveCompositorFrameAck(); 693 state.DidReceiveCompositorFrameAck();
662 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 694 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
663 } 695 }
664 696
665 TEST(SchedulerStateMachineTest, TestDoestDrawTwiceInSameFrame) { 697 TEST(SchedulerStateMachineTest, TestDoestDrawTwiceInSameFrame) {
666 SchedulerSettings default_scheduler_settings; 698 SchedulerSettings default_scheduler_settings;
667 StateMachine state(default_scheduler_settings); 699 StateMachine state(default_scheduler_settings);
668 SET_UP_STATE(state) 700 SET_UP_STATE(state)
669 state.SetNeedsRedraw(true); 701 state.SetNeedsRedraw(true);
670 702
671 // Draw the first frame. 703 // Draw the first frame.
672 EXPECT_TRUE(state.BeginFrameNeeded()); 704 EXPECT_TRUE(state.BeginFrameNeeded());
673 state.OnBeginImplFrame(); 705 state.IssueNextBeginImplFrame();
674 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 706 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
675 707
676 state.OnBeginImplFrameDeadline(); 708 state.OnBeginImplFrameDeadline();
677 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE); 709 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE);
678 state.DidSubmitCompositorFrame(); 710 state.DidSubmitCompositorFrame();
679 state.DidReceiveCompositorFrameAck(); 711 state.DidReceiveCompositorFrameAck();
680 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 712 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
681 713
682 // Before the next BeginImplFrame, set needs redraw again. 714 // Before the next BeginImplFrame, set needs redraw again.
683 // This should not redraw until the next BeginImplFrame. 715 // This should not redraw until the next BeginImplFrame.
684 state.SetNeedsRedraw(true); 716 state.SetNeedsRedraw(true);
685 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 717 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
686 718
687 // Move to another frame. This should now draw. 719 // Move to another frame. This should now draw.
688 EXPECT_TRUE(state.BeginFrameNeeded()); 720 EXPECT_TRUE(state.BeginFrameNeeded());
689 state.OnBeginImplFrame(); 721 state.IssueNextBeginImplFrame();
690 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 722 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
691 state.OnBeginImplFrameDeadline(); 723 state.OnBeginImplFrameDeadline();
692 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE); 724 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE);
693 state.DidSubmitCompositorFrame(); 725 state.DidSubmitCompositorFrame();
694 state.DidReceiveCompositorFrameAck(); 726 state.DidReceiveCompositorFrameAck();
695 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 727 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
696 728
697 // We just submitted, so we should proactively request another BeginImplFrame. 729 // We just submitted, so we should proactively request another BeginImplFrame.
698 EXPECT_TRUE(state.BeginFrameNeeded()); 730 EXPECT_TRUE(state.BeginFrameNeeded());
699 } 731 }
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
817 StateMachine state(default_scheduler_settings); 849 StateMachine state(default_scheduler_settings);
818 state.SetVisible(true); 850 state.SetVisible(true);
819 EXPECT_ACTION_UPDATE_STATE( 851 EXPECT_ACTION_UPDATE_STATE(
820 SchedulerStateMachine::ACTION_BEGIN_COMPOSITOR_FRAME_SINK_CREATION); 852 SchedulerStateMachine::ACTION_BEGIN_COMPOSITOR_FRAME_SINK_CREATION);
821 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 853 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
822 state.CreateAndInitializeCompositorFrameSinkWithActivatedCommit(); 854 state.CreateAndInitializeCompositorFrameSinkWithActivatedCommit();
823 state.SetBeginMainFrameState(begin_main_frame_states[i]); 855 state.SetBeginMainFrameState(begin_main_frame_states[i]);
824 state.SetVisible(false); 856 state.SetVisible(false);
825 state.SetNeedsRedraw(true); 857 state.SetNeedsRedraw(true);
826 if (j == 1) 858 if (j == 1)
827 state.OnBeginImplFrame(); 859 state.IssueNextBeginImplFrame();
828 860
829 state.SetCanDraw(false); 861 state.SetCanDraw(false);
830 EXPECT_NE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, 862 EXPECT_NE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE,
831 state.NextAction()); 863 state.NextAction());
832 } 864 }
833 } 865 }
834 } 866 }
835 867
836 TEST(SchedulerStateMachineTest, 868 TEST(SchedulerStateMachineTest,
837 TestCanRedrawWithWaitingForFirstDrawMakesProgress) { 869 TestCanRedrawWithWaitingForFirstDrawMakesProgress) {
838 SchedulerSettings default_scheduler_settings; 870 SchedulerSettings default_scheduler_settings;
839 StateMachine state(default_scheduler_settings); 871 StateMachine state(default_scheduler_settings);
840 state.SetVisible(true); 872 state.SetVisible(true);
841 EXPECT_ACTION_UPDATE_STATE( 873 EXPECT_ACTION_UPDATE_STATE(
842 SchedulerStateMachine::ACTION_BEGIN_COMPOSITOR_FRAME_SINK_CREATION); 874 SchedulerStateMachine::ACTION_BEGIN_COMPOSITOR_FRAME_SINK_CREATION);
843 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 875 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
844 state.CreateAndInitializeCompositorFrameSinkWithActivatedCommit(); 876 state.CreateAndInitializeCompositorFrameSinkWithActivatedCommit();
845 877
846 state.SetActiveTreeNeedsFirstDraw(true); 878 state.SetActiveTreeNeedsFirstDraw(true);
847 state.SetNeedsBeginMainFrame(); 879 state.SetNeedsBeginMainFrame();
848 state.SetNeedsRedraw(true); 880 state.SetNeedsRedraw(true);
849 state.SetCanDraw(false); 881 state.SetCanDraw(false);
850 state.OnBeginImplFrame(); 882 state.IssueNextBeginImplFrame();
851 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_ABORT); 883 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_ABORT);
852 EXPECT_ACTION_UPDATE_STATE( 884 EXPECT_ACTION_UPDATE_STATE(
853 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 885 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
854 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 886 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
855 state.NotifyBeginMainFrameStarted(); 887 state.NotifyBeginMainFrameStarted();
856 state.NotifyReadyToCommit(); 888 state.NotifyReadyToCommit();
857 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 889 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
858 state.NotifyReadyToActivate(); 890 state.NotifyReadyToActivate();
859 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE); 891 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE);
860 state.OnBeginImplFrameDeadline(); 892 state.OnBeginImplFrameDeadline();
861 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_ABORT); 893 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_ABORT);
862 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 894 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
863 } 895 }
864 896
865 TEST(SchedulerStateMachineTest, TestSetNeedsBeginMainFrameIsNotLost) { 897 TEST(SchedulerStateMachineTest, TestSetNeedsBeginMainFrameIsNotLost) {
866 SchedulerSettings scheduler_settings; 898 SchedulerSettings scheduler_settings;
867 StateMachine state(scheduler_settings); 899 StateMachine state(scheduler_settings);
868 SET_UP_STATE(state) 900 SET_UP_STATE(state)
869 state.SetNeedsBeginMainFrame(); 901 state.SetNeedsBeginMainFrame();
870 902
871 EXPECT_TRUE(state.BeginFrameNeeded()); 903 EXPECT_TRUE(state.BeginFrameNeeded());
872 904
873 // Begin the frame. 905 // Begin the frame.
874 state.OnBeginImplFrame(); 906 state.IssueNextBeginImplFrame();
875 EXPECT_ACTION_UPDATE_STATE( 907 EXPECT_ACTION_UPDATE_STATE(
876 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 908 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
877 EXPECT_MAIN_FRAME_STATE(SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_SENT); 909 EXPECT_MAIN_FRAME_STATE(SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_SENT);
878 910
879 // Now, while the frame is in progress, set another commit. 911 // Now, while the frame is in progress, set another commit.
880 state.SetNeedsBeginMainFrame(); 912 state.SetNeedsBeginMainFrame();
881 EXPECT_TRUE(state.NeedsCommit()); 913 EXPECT_TRUE(state.NeedsCommit());
882 914
883 // Let the frame finish. 915 // Let the frame finish.
884 state.NotifyBeginMainFrameStarted(); 916 state.NotifyBeginMainFrameStarted();
885 state.NotifyReadyToCommit(); 917 state.NotifyReadyToCommit();
886 EXPECT_MAIN_FRAME_STATE( 918 EXPECT_MAIN_FRAME_STATE(
887 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_READY_TO_COMMIT); 919 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_READY_TO_COMMIT);
888 920
889 // Expect to commit regardless of BeginImplFrame state. 921 // Expect to commit regardless of BeginImplFrame state.
890 EXPECT_IMPL_FRAME_STATE( 922 EXPECT_IMPL_FRAME_STATE(
891 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_BEGIN_FRAME); 923 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_BEGIN_FRAME);
892 EXPECT_ACTION(SchedulerStateMachine::ACTION_COMMIT); 924 EXPECT_ACTION(SchedulerStateMachine::ACTION_COMMIT);
893 925
894 state.OnBeginImplFrameDeadline(); 926 state.OnBeginImplFrameDeadline();
895 EXPECT_IMPL_FRAME_STATE( 927 EXPECT_IMPL_FRAME_STATE(
896 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE); 928 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE);
897 EXPECT_ACTION(SchedulerStateMachine::ACTION_COMMIT); 929 EXPECT_ACTION(SchedulerStateMachine::ACTION_COMMIT);
898 930
899 state.OnBeginImplFrameIdle(); 931 state.OnBeginImplFrameIdle();
900 EXPECT_IMPL_FRAME_STATE(SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE); 932 EXPECT_IMPL_FRAME_STATE(SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE);
901 EXPECT_ACTION(SchedulerStateMachine::ACTION_COMMIT); 933 EXPECT_ACTION(SchedulerStateMachine::ACTION_COMMIT);
902 934
903 state.OnBeginImplFrame(); 935 state.IssueNextBeginImplFrame();
904 EXPECT_IMPL_FRAME_STATE( 936 EXPECT_IMPL_FRAME_STATE(
905 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_BEGIN_FRAME); 937 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_BEGIN_FRAME);
906 EXPECT_ACTION(SchedulerStateMachine::ACTION_COMMIT); 938 EXPECT_ACTION(SchedulerStateMachine::ACTION_COMMIT);
907 939
908 // Finish the commit and activate, then make sure we start the next commit 940 // Finish the commit and activate, then make sure we start the next commit
909 // immediately and draw on the next BeginImplFrame. 941 // immediately and draw on the next BeginImplFrame.
910 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 942 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
911 state.NotifyReadyToActivate(); 943 state.NotifyReadyToActivate();
912 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE); 944 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE);
913 EXPECT_ACTION_UPDATE_STATE( 945 EXPECT_ACTION_UPDATE_STATE(
(...skipping 11 matching lines...) Expand all
925 957
926 TEST(SchedulerStateMachineTest, TestFullCycle) { 958 TEST(SchedulerStateMachineTest, TestFullCycle) {
927 SchedulerSettings default_scheduler_settings; 959 SchedulerSettings default_scheduler_settings;
928 StateMachine state(default_scheduler_settings); 960 StateMachine state(default_scheduler_settings);
929 SET_UP_STATE(state) 961 SET_UP_STATE(state)
930 962
931 // Start clean and set commit. 963 // Start clean and set commit.
932 state.SetNeedsBeginMainFrame(); 964 state.SetNeedsBeginMainFrame();
933 965
934 // Begin the frame. 966 // Begin the frame.
935 state.OnBeginImplFrame(); 967 state.IssueNextBeginImplFrame();
936 EXPECT_ACTION_UPDATE_STATE( 968 EXPECT_ACTION_UPDATE_STATE(
937 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 969 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
938 EXPECT_MAIN_FRAME_STATE(SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_SENT); 970 EXPECT_MAIN_FRAME_STATE(SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_SENT);
939 EXPECT_FALSE(state.NeedsCommit()); 971 EXPECT_FALSE(state.NeedsCommit());
940 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 972 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
941 973
942 // Tell the scheduler the frame finished. 974 // Tell the scheduler the frame finished.
943 state.NotifyBeginMainFrameStarted(); 975 state.NotifyBeginMainFrameStarted();
944 state.NotifyReadyToCommit(); 976 state.NotifyReadyToCommit();
945 EXPECT_MAIN_FRAME_STATE( 977 EXPECT_MAIN_FRAME_STATE(
(...skipping 25 matching lines...) Expand all
971 1003
972 TEST(SchedulerStateMachineTest, CommitWithoutDrawWithPendingTree) { 1004 TEST(SchedulerStateMachineTest, CommitWithoutDrawWithPendingTree) {
973 SchedulerSettings default_scheduler_settings; 1005 SchedulerSettings default_scheduler_settings;
974 StateMachine state(default_scheduler_settings); 1006 StateMachine state(default_scheduler_settings);
975 SET_UP_STATE(state) 1007 SET_UP_STATE(state)
976 1008
977 // Start clean and set commit. 1009 // Start clean and set commit.
978 state.SetNeedsBeginMainFrame(); 1010 state.SetNeedsBeginMainFrame();
979 1011
980 // Make a main frame, commit and activate it. But don't draw it. 1012 // Make a main frame, commit and activate it. But don't draw it.
981 state.OnBeginImplFrame(); 1013 state.IssueNextBeginImplFrame();
982 EXPECT_ACTION_UPDATE_STATE( 1014 EXPECT_ACTION_UPDATE_STATE(
983 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 1015 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
984 state.NotifyBeginMainFrameStarted(); 1016 state.NotifyBeginMainFrameStarted();
985 state.NotifyReadyToCommit(); 1017 state.NotifyReadyToCommit();
986 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 1018 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
987 state.NotifyReadyToActivate(); 1019 state.NotifyReadyToActivate();
988 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE); 1020 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE);
989 1021
990 // Try to make a new main frame before drawing. Since we will commit it to a 1022 // Try to make a new main frame before drawing. Since we will commit it to a
991 // pending tree and not clobber the active tree, we're able to start a new 1023 // pending tree and not clobber the active tree, we're able to start a new
992 // begin frame and commit it. 1024 // begin frame and commit it.
993 state.SetNeedsBeginMainFrame(); 1025 state.SetNeedsBeginMainFrame();
994 state.OnBeginImplFrame(); 1026 state.IssueNextBeginImplFrame();
995 EXPECT_ACTION_UPDATE_STATE( 1027 EXPECT_ACTION_UPDATE_STATE(
996 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 1028 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
997 state.NotifyBeginMainFrameStarted(); 1029 state.NotifyBeginMainFrameStarted();
998 state.NotifyReadyToCommit(); 1030 state.NotifyReadyToCommit();
999 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 1031 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
1000 } 1032 }
1001 1033
1002 TEST(SchedulerStateMachineTest, DontCommitWithoutDrawWithoutPendingTree) { 1034 TEST(SchedulerStateMachineTest, DontCommitWithoutDrawWithoutPendingTree) {
1003 SchedulerSettings scheduler_settings; 1035 SchedulerSettings scheduler_settings;
1004 scheduler_settings.commit_to_active_tree = true; 1036 scheduler_settings.commit_to_active_tree = true;
1005 scheduler_settings.main_frame_before_activation_enabled = false; 1037 scheduler_settings.main_frame_before_activation_enabled = false;
1006 StateMachine state(scheduler_settings); 1038 StateMachine state(scheduler_settings);
1007 SET_UP_STATE(state) 1039 SET_UP_STATE(state)
1008 1040
1009 // Start clean and set commit. 1041 // Start clean and set commit.
1010 state.SetNeedsBeginMainFrame(); 1042 state.SetNeedsBeginMainFrame();
1011 1043
1012 // Make a main frame, commit and activate it. But don't draw it. 1044 // Make a main frame, commit and activate it. But don't draw it.
1013 state.OnBeginImplFrame(); 1045 state.OnBeginImplFrame(0, 10);
1014 EXPECT_ACTION_UPDATE_STATE( 1046 EXPECT_ACTION_UPDATE_STATE(
1015 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 1047 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
1048 EXPECT_SEQUENCE_NUMBERS(10u, 10u, BeginFrameArgs::kInvalidFrameNumber,
1049 BeginFrameArgs::kInvalidFrameNumber,
1050 BeginFrameArgs::kInvalidFrameNumber);
1016 state.NotifyBeginMainFrameStarted(); 1051 state.NotifyBeginMainFrameStarted();
1017 state.NotifyReadyToCommit(); 1052 state.NotifyReadyToCommit();
1018 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 1053 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
1054 EXPECT_SEQUENCE_NUMBERS(10u, 10u, 10u, BeginFrameArgs::kInvalidFrameNumber,
1055 BeginFrameArgs::kInvalidFrameNumber);
1019 state.NotifyReadyToActivate(); 1056 state.NotifyReadyToActivate();
1020 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE); 1057 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE);
1058 EXPECT_SEQUENCE_NUMBERS(10u, 10u, 10u, 10u,
1059 BeginFrameArgs::kInvalidFrameNumber);
1021 1060
1022 // Try to make a new main frame before drawing, but since we would clobber the 1061 // Try to make a new main frame before drawing, but since we would clobber the
1023 // active tree, we will not do so. 1062 // active tree, we will not do so.
1024 state.SetNeedsBeginMainFrame(); 1063 state.SetNeedsBeginMainFrame();
1025 state.OnBeginImplFrame(); 1064 state.OnBeginImplFrame(0, 11);
1026 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1065 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1066 EXPECT_SEQUENCE_NUMBERS(11u, 10u, 10u, 10u,
1067 BeginFrameArgs::kInvalidFrameNumber);
1027 } 1068 }
1028 1069
1029 TEST(SchedulerStateMachineTest, AbortedMainFrameDoesNotResetPendingTree) { 1070 TEST(SchedulerStateMachineTest, AbortedMainFrameDoesNotResetPendingTree) {
1030 SchedulerSettings scheduler_settings; 1071 SchedulerSettings scheduler_settings;
1031 scheduler_settings.main_frame_before_activation_enabled = true; 1072 scheduler_settings.main_frame_before_activation_enabled = true;
1032 StateMachine state(scheduler_settings); 1073 StateMachine state(scheduler_settings);
1033 SET_UP_STATE(state); 1074 SET_UP_STATE(state);
1034 1075
1035 // Perform a commit so that we have an active tree. 1076 // Perform a commit so that we have an active tree.
1036 state.SetNeedsBeginMainFrame(); 1077 state.SetNeedsBeginMainFrame();
1037 state.OnBeginImplFrame(); 1078 state.IssueNextBeginImplFrame();
1038 EXPECT_ACTION_UPDATE_STATE( 1079 EXPECT_ACTION_UPDATE_STATE(
1039 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 1080 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
1040 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1081 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1041 state.NotifyBeginMainFrameStarted(); 1082 state.NotifyBeginMainFrameStarted();
1042 state.NotifyReadyToCommit(); 1083 state.NotifyReadyToCommit();
1043 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 1084 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
1044 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1085 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1045 EXPECT_TRUE(state.has_pending_tree()); 1086 EXPECT_TRUE(state.has_pending_tree());
1046 state.OnBeginImplFrameDeadline(); 1087 state.OnBeginImplFrameDeadline();
1047 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1088 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1048 1089
1049 // Ask for another commit but abort it. Verify that we didn't reset pending 1090 // Ask for another commit but abort it. Verify that we didn't reset pending
1050 // tree state. 1091 // tree state.
1051 state.SetNeedsBeginMainFrame(); 1092 state.SetNeedsBeginMainFrame();
1052 state.OnBeginImplFrame(); 1093 state.IssueNextBeginImplFrame();
1053 EXPECT_ACTION_UPDATE_STATE( 1094 EXPECT_ACTION_UPDATE_STATE(
1054 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 1095 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
1055 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1096 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1056 EXPECT_TRUE(state.has_pending_tree()); 1097 EXPECT_TRUE(state.has_pending_tree());
1057 state.NotifyBeginMainFrameStarted(); 1098 state.NotifyBeginMainFrameStarted();
1058 state.BeginMainFrameAborted(CommitEarlyOutReason::FINISHED_NO_UPDATES); 1099 state.BeginMainFrameAborted(CommitEarlyOutReason::FINISHED_NO_UPDATES);
1059 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1100 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1060 EXPECT_TRUE(state.has_pending_tree()); 1101 EXPECT_TRUE(state.has_pending_tree());
1061 state.OnBeginImplFrameDeadline(); 1102 state.OnBeginImplFrameDeadline();
1062 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1103 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1063 1104
1064 // Ask for another commit that doesn't abort. 1105 // Ask for another commit that doesn't abort.
1065 state.SetNeedsBeginMainFrame(); 1106 state.SetNeedsBeginMainFrame();
1066 state.OnBeginImplFrame(); 1107 state.IssueNextBeginImplFrame();
1067 EXPECT_ACTION_UPDATE_STATE( 1108 EXPECT_ACTION_UPDATE_STATE(
1068 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 1109 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
1069 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1110 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1070 state.NotifyBeginMainFrameStarted(); 1111 state.NotifyBeginMainFrameStarted();
1071 state.NotifyReadyToCommit(); 1112 state.NotifyReadyToCommit();
1072 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1113 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1073 EXPECT_TRUE(state.has_pending_tree()); 1114 EXPECT_TRUE(state.has_pending_tree());
1074 1115
1075 // Verify that commit is delayed until the pending tree is activated. 1116 // Verify that commit is delayed until the pending tree is activated.
1076 state.NotifyReadyToActivate(); 1117 state.NotifyReadyToActivate();
1077 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE); 1118 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE);
1078 EXPECT_FALSE(state.has_pending_tree()); 1119 EXPECT_FALSE(state.has_pending_tree());
1079 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 1120 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
1080 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1121 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1081 EXPECT_TRUE(state.has_pending_tree()); 1122 EXPECT_TRUE(state.has_pending_tree());
1082 } 1123 }
1083 1124
1084 TEST(SchedulerStateMachineTest, TestFullCycleWithCommitToActive) { 1125 TEST(SchedulerStateMachineTest, TestFullCycleWithCommitToActive) {
1085 SchedulerSettings scheduler_settings; 1126 SchedulerSettings scheduler_settings;
1086 scheduler_settings.commit_to_active_tree = true; 1127 scheduler_settings.commit_to_active_tree = true;
1087 scheduler_settings.main_frame_before_activation_enabled = false; 1128 scheduler_settings.main_frame_before_activation_enabled = false;
1088 StateMachine state(scheduler_settings); 1129 StateMachine state(scheduler_settings);
1089 SET_UP_STATE(state) 1130 SET_UP_STATE(state)
1090 1131
1091 // Start clean and set commit. 1132 // Start clean and set commit.
1092 state.SetNeedsBeginMainFrame(); 1133 state.SetNeedsBeginMainFrame();
1093 1134
1094 // Begin the frame. 1135 // Begin the frame.
1095 state.OnBeginImplFrame(); 1136 state.OnBeginImplFrame(0, 10);
1096 EXPECT_ACTION_UPDATE_STATE( 1137 EXPECT_ACTION_UPDATE_STATE(
1097 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 1138 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
1098 EXPECT_MAIN_FRAME_STATE(SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_SENT); 1139 EXPECT_MAIN_FRAME_STATE(SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_SENT);
1099 EXPECT_FALSE(state.NeedsCommit()); 1140 EXPECT_FALSE(state.NeedsCommit());
1100 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1141 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1142 EXPECT_SEQUENCE_NUMBERS(10u, 10u, BeginFrameArgs::kInvalidFrameNumber,
1143 BeginFrameArgs::kInvalidFrameNumber,
1144 BeginFrameArgs::kInvalidFrameNumber);
1101 1145
1102 // Tell the scheduler the frame finished. 1146 // Tell the scheduler the frame finished.
1103 state.NotifyBeginMainFrameStarted(); 1147 state.NotifyBeginMainFrameStarted();
1104 state.NotifyReadyToCommit(); 1148 state.NotifyReadyToCommit();
1105 EXPECT_MAIN_FRAME_STATE( 1149 EXPECT_MAIN_FRAME_STATE(
1106 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_READY_TO_COMMIT); 1150 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_READY_TO_COMMIT);
1107 // Commit. 1151 // Commit.
1108 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 1152 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
1153 EXPECT_SEQUENCE_NUMBERS(10u, 10u, 10u, BeginFrameArgs::kInvalidFrameNumber,
1154 BeginFrameArgs::kInvalidFrameNumber);
1109 // Commit always calls NotifyReadyToActivate in this mode. 1155 // Commit always calls NotifyReadyToActivate in this mode.
1110 state.NotifyReadyToActivate(); 1156 state.NotifyReadyToActivate();
1111 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE); 1157 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE);
1112 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1158 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1159 EXPECT_SEQUENCE_NUMBERS(10u, 10u, 10u, 10u,
1160 BeginFrameArgs::kInvalidFrameNumber);
1113 1161
1114 // No draw because we haven't received NotifyReadyToDraw yet. 1162 // No draw because we haven't received NotifyReadyToDraw yet.
1115 state.OnBeginImplFrameDeadline(); 1163 state.OnBeginImplFrameDeadline();
1116 EXPECT_TRUE(state.active_tree_needs_first_draw()); 1164 EXPECT_TRUE(state.active_tree_needs_first_draw());
1117 EXPECT_TRUE(state.needs_redraw()); 1165 EXPECT_TRUE(state.needs_redraw());
1118 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1166 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1167 EXPECT_SEQUENCE_NUMBERS(10u, 10u, 10u, 10u,
1168 BeginFrameArgs::kInvalidFrameNumber);
1119 1169
1120 // Can't BeginMainFrame yet since last commit hasn't been drawn yet. 1170 // Can't BeginMainFrame yet since last commit hasn't been drawn yet.
1121 state.SetNeedsBeginMainFrame(); 1171 state.SetNeedsBeginMainFrame();
1122 state.OnBeginImplFrame(); 1172 state.OnBeginImplFrame(0, 11);
1123 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1173 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1174 EXPECT_SEQUENCE_NUMBERS(11u, 10u, 10u, 10u,
1175 BeginFrameArgs::kInvalidFrameNumber);
1124 1176
1125 // Now call ready to draw which will allow the draw to happen and 1177 // Now call ready to draw which will allow the draw to happen and
1126 // BeginMainFrame to be sent. 1178 // BeginMainFrame to be sent.
1127 state.NotifyReadyToDraw(); 1179 state.NotifyReadyToDraw();
1128 state.OnBeginImplFrameDeadline(); 1180 state.OnBeginImplFrameDeadline();
1129 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE); 1181 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE);
1182 EXPECT_SEQUENCE_NUMBERS(11u, 10u, 10u, 10u, 10u);
1130 // Submit throttled from this point. 1183 // Submit throttled from this point.
1131 state.DidSubmitCompositorFrame(); 1184 state.DidSubmitCompositorFrame();
1132 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1185 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1133 1186
1134 // Can't BeginMainFrame yet since we're submit-frame throttled. 1187 // Can't BeginMainFrame yet since we're submit-frame throttled.
1135 state.OnBeginImplFrame(); 1188 state.OnBeginImplFrame(0, 12);
1136 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1189 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1190 EXPECT_SEQUENCE_NUMBERS(12u, 10u, 10u, 10u, 10u);
1137 1191
1138 // CompositorFrameAck unblocks BeginMainFrame. 1192 // CompositorFrameAck unblocks BeginMainFrame.
1139 state.DidReceiveCompositorFrameAck(); 1193 state.DidReceiveCompositorFrameAck();
1140 EXPECT_ACTION_UPDATE_STATE( 1194 EXPECT_ACTION_UPDATE_STATE(
1141 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 1195 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
1196 EXPECT_SEQUENCE_NUMBERS(12u, 12u, 10u, 10u, 10u);
1142 state.NotifyBeginMainFrameStarted(); 1197 state.NotifyBeginMainFrameStarted();
1143 state.NotifyReadyToCommit(); 1198 state.NotifyReadyToCommit();
1144 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 1199 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
1200 EXPECT_SEQUENCE_NUMBERS(12u, 12u, 12u, 10u, 10u);
1145 state.NotifyReadyToActivate(); 1201 state.NotifyReadyToActivate();
1146 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE); 1202 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE);
1147 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1203 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1204 EXPECT_SEQUENCE_NUMBERS(12u, 12u, 12u, 12u, 10u);
1148 1205
1149 // Draw the newly activated tree. 1206 // Draw the newly activated tree.
1150 state.NotifyReadyToDraw(); 1207 state.NotifyReadyToDraw();
1151 state.OnBeginImplFrameDeadline(); 1208 state.OnBeginImplFrameDeadline();
1152 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE); 1209 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE);
1153 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1210 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1211 EXPECT_SEQUENCE_NUMBERS(12u, 12u, 12u, 12u, 12u);
1154 } 1212 }
1155 1213
1156 TEST(SchedulerStateMachineTest, TestFullCycleWithCommitRequestInbetween) { 1214 TEST(SchedulerStateMachineTest, TestFullCycleWithCommitRequestInbetween) {
1157 SchedulerSettings default_scheduler_settings; 1215 SchedulerSettings default_scheduler_settings;
1158 StateMachine state(default_scheduler_settings); 1216 StateMachine state(default_scheduler_settings);
1159 SET_UP_STATE(state) 1217 SET_UP_STATE(state)
1160 1218
1161 // Start clean and set commit. 1219 // Start clean and set commit.
1162 state.SetNeedsBeginMainFrame(); 1220 state.SetNeedsBeginMainFrame();
1163 1221
1164 // Begin the frame. 1222 // Begin the frame.
1165 state.OnBeginImplFrame(); 1223 state.IssueNextBeginImplFrame();
1166 EXPECT_ACTION_UPDATE_STATE( 1224 EXPECT_ACTION_UPDATE_STATE(
1167 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 1225 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
1168 EXPECT_MAIN_FRAME_STATE(SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_SENT); 1226 EXPECT_MAIN_FRAME_STATE(SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_SENT);
1169 EXPECT_FALSE(state.NeedsCommit()); 1227 EXPECT_FALSE(state.NeedsCommit());
1170 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1228 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1171 1229
1172 // Request another commit while the commit is in flight. 1230 // Request another commit while the commit is in flight.
1173 state.SetNeedsBeginMainFrame(); 1231 state.SetNeedsBeginMainFrame();
1174 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1232 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1175 1233
(...skipping 18 matching lines...) Expand all
1194 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE); 1252 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE);
1195 state.DidSubmitCompositorFrame(); 1253 state.DidSubmitCompositorFrame();
1196 state.DidReceiveCompositorFrameAck(); 1254 state.DidReceiveCompositorFrameAck();
1197 1255
1198 // Should be synchronized, no draw needed, no action needed. 1256 // Should be synchronized, no draw needed, no action needed.
1199 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1257 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1200 EXPECT_MAIN_FRAME_STATE(SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_IDLE); 1258 EXPECT_MAIN_FRAME_STATE(SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_IDLE);
1201 EXPECT_FALSE(state.needs_redraw()); 1259 EXPECT_FALSE(state.needs_redraw());
1202 1260
1203 // Next BeginImplFrame should initiate second commit. 1261 // Next BeginImplFrame should initiate second commit.
1204 state.OnBeginImplFrame(); 1262 state.IssueNextBeginImplFrame();
1205 EXPECT_ACTION_UPDATE_STATE( 1263 EXPECT_ACTION_UPDATE_STATE(
1206 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 1264 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
1207 } 1265 }
1208 1266
1209 TEST(SchedulerStateMachineTest, TestNoRequestCommitWhenInvisible) { 1267 TEST(SchedulerStateMachineTest, TestNoRequestCommitWhenInvisible) {
1210 SchedulerSettings default_scheduler_settings; 1268 SchedulerSettings default_scheduler_settings;
1211 StateMachine state(default_scheduler_settings); 1269 StateMachine state(default_scheduler_settings);
1212 state.SetVisible(true); 1270 state.SetVisible(true);
1213 EXPECT_ACTION_UPDATE_STATE( 1271 EXPECT_ACTION_UPDATE_STATE(
1214 SchedulerStateMachine::ACTION_BEGIN_COMPOSITOR_FRAME_SINK_CREATION); 1272 SchedulerStateMachine::ACTION_BEGIN_COMPOSITOR_FRAME_SINK_CREATION);
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
1257 // "EarlyOut_CompositorFrameSinkLost" cases. 1315 // "EarlyOut_CompositorFrameSinkLost" cases.
1258 TEST(SchedulerStateMachineTest, TestAbortBeginMainFrameBecauseInvisible) { 1316 TEST(SchedulerStateMachineTest, TestAbortBeginMainFrameBecauseInvisible) {
1259 SchedulerSettings default_scheduler_settings; 1317 SchedulerSettings default_scheduler_settings;
1260 StateMachine state(default_scheduler_settings); 1318 StateMachine state(default_scheduler_settings);
1261 SET_UP_STATE(state) 1319 SET_UP_STATE(state)
1262 1320
1263 // Start clean and set commit. 1321 // Start clean and set commit.
1264 state.SetNeedsBeginMainFrame(); 1322 state.SetNeedsBeginMainFrame();
1265 1323
1266 // Begin the frame while visible. 1324 // Begin the frame while visible.
1267 state.OnBeginImplFrame(); 1325 state.IssueNextBeginImplFrame();
1268 EXPECT_ACTION_UPDATE_STATE( 1326 EXPECT_ACTION_UPDATE_STATE(
1269 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 1327 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
1270 EXPECT_MAIN_FRAME_STATE(SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_SENT); 1328 EXPECT_MAIN_FRAME_STATE(SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_SENT);
1271 EXPECT_FALSE(state.NeedsCommit()); 1329 EXPECT_FALSE(state.NeedsCommit());
1272 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1330 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1273 1331
1274 // Become invisible and abort BeginMainFrame. 1332 // Become invisible and abort BeginMainFrame.
1275 state.SetVisible(false); 1333 state.SetVisible(false);
1276 state.NotifyBeginMainFrameStarted(); 1334 state.NotifyBeginMainFrameStarted();
1277 state.BeginMainFrameAborted(CommitEarlyOutReason::ABORTED_NOT_VISIBLE); 1335 state.BeginMainFrameAborted(CommitEarlyOutReason::ABORTED_NOT_VISIBLE);
(...skipping 13 matching lines...) Expand all
1291 // Become visible again. 1349 // Become visible again.
1292 state.SetVisible(true); 1350 state.SetVisible(true);
1293 1351
1294 // Although we have aborted on this frame and haven't cancelled the commit 1352 // Although we have aborted on this frame and haven't cancelled the commit
1295 // (i.e. need another), don't send another BeginMainFrame yet. 1353 // (i.e. need another), don't send another BeginMainFrame yet.
1296 EXPECT_MAIN_FRAME_STATE(SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_IDLE); 1354 EXPECT_MAIN_FRAME_STATE(SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_IDLE);
1297 EXPECT_ACTION(SchedulerStateMachine::ACTION_NONE); 1355 EXPECT_ACTION(SchedulerStateMachine::ACTION_NONE);
1298 EXPECT_TRUE(state.NeedsCommit()); 1356 EXPECT_TRUE(state.NeedsCommit());
1299 1357
1300 // Start a new frame. 1358 // Start a new frame.
1301 state.OnBeginImplFrame(); 1359 state.IssueNextBeginImplFrame();
1302 EXPECT_ACTION_UPDATE_STATE( 1360 EXPECT_ACTION_UPDATE_STATE(
1303 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 1361 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
1304 1362
1305 // We should be starting the commit now. 1363 // We should be starting the commit now.
1306 EXPECT_MAIN_FRAME_STATE(SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_SENT); 1364 EXPECT_MAIN_FRAME_STATE(SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_SENT);
1307 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1365 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1308 } 1366 }
1309 1367
1310 // See ProxyMain::BeginMainFrame "EarlyOut_NoUpdates" case. 1368 // See ProxyMain::BeginMainFrame "EarlyOut_NoUpdates" case.
1311 TEST(SchedulerStateMachineTest, TestAbortBeginMainFrameBecauseCommitNotNeeded) { 1369 TEST(SchedulerStateMachineTest, TestAbortBeginMainFrameBecauseCommitNotNeeded) {
1312 SchedulerSettings default_scheduler_settings; 1370 SchedulerSettings default_scheduler_settings;
1313 StateMachine state(default_scheduler_settings); 1371 StateMachine state(default_scheduler_settings);
1314 state.SetVisible(true); 1372 state.SetVisible(true);
1315 EXPECT_ACTION_UPDATE_STATE( 1373 EXPECT_ACTION_UPDATE_STATE(
1316 SchedulerStateMachine::ACTION_BEGIN_COMPOSITOR_FRAME_SINK_CREATION); 1374 SchedulerStateMachine::ACTION_BEGIN_COMPOSITOR_FRAME_SINK_CREATION);
1317 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1375 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1318 state.DidCreateAndInitializeCompositorFrameSink(); 1376 state.DidCreateAndInitializeCompositorFrameSink();
1319 state.SetCanDraw(true); 1377 state.SetCanDraw(true);
1320 1378
1321 // Get into a begin frame / commit state. 1379 // Get into a begin frame / commit state.
1322 state.SetNeedsBeginMainFrame(); 1380 state.SetNeedsBeginMainFrame();
1323 state.OnBeginImplFrame(); 1381 state.IssueNextBeginImplFrame();
1324 EXPECT_ACTION_UPDATE_STATE( 1382 EXPECT_ACTION_UPDATE_STATE(
1325 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 1383 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
1326 EXPECT_MAIN_FRAME_STATE(SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_SENT); 1384 EXPECT_MAIN_FRAME_STATE(SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_SENT);
1327 EXPECT_FALSE(state.NeedsCommit()); 1385 EXPECT_FALSE(state.NeedsCommit());
1328 EXPECT_ACTION(SchedulerStateMachine::ACTION_NONE); 1386 EXPECT_ACTION(SchedulerStateMachine::ACTION_NONE);
1329 1387
1330 // Abort the commit, true means that the BeginMainFrame was sent but there 1388 // Abort the commit, true means that the BeginMainFrame was sent but there
1331 // was no work to do on the main thread. 1389 // was no work to do on the main thread.
1332 state.NotifyBeginMainFrameStarted(); 1390 state.NotifyBeginMainFrameStarted();
1333 state.BeginMainFrameAborted(CommitEarlyOutReason::FINISHED_NO_UPDATES); 1391 state.BeginMainFrameAborted(CommitEarlyOutReason::FINISHED_NO_UPDATES);
1334 1392
1335 // NeedsCommit should now be false because the commit was actually handled. 1393 // NeedsCommit should now be false because the commit was actually handled.
1336 EXPECT_FALSE(state.NeedsCommit()); 1394 EXPECT_FALSE(state.NeedsCommit());
1337 1395
1338 // Since the commit was aborted, we don't need to try and draw. 1396 // Since the commit was aborted, we don't need to try and draw.
1339 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1397 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1340 state.OnBeginImplFrameDeadline(); 1398 state.OnBeginImplFrameDeadline();
1341 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1399 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1342 1400
1343 // Verify another commit doesn't start on another frame either. 1401 // Verify another commit doesn't start on another frame either.
1344 EXPECT_FALSE(state.NeedsCommit()); 1402 EXPECT_FALSE(state.NeedsCommit());
1345 EXPECT_MAIN_FRAME_STATE(SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_IDLE); 1403 EXPECT_MAIN_FRAME_STATE(SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_IDLE);
1346 1404
1347 state.OnBeginImplFrame(); 1405 state.IssueNextBeginImplFrame();
1348 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1406 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1349 state.OnBeginImplFrameDeadline(); 1407 state.OnBeginImplFrameDeadline();
1350 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1408 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1351 1409
1352 // Verify another commit can start if requested, though. 1410 // Verify another commit can start if requested, though.
1353 state.SetNeedsBeginMainFrame(); 1411 state.SetNeedsBeginMainFrame();
1354 EXPECT_MAIN_FRAME_STATE(SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_IDLE); 1412 EXPECT_MAIN_FRAME_STATE(SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_IDLE);
1355 state.OnBeginImplFrame(); 1413 state.IssueNextBeginImplFrame();
1356 EXPECT_ACTION(SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 1414 EXPECT_ACTION(SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
1357 } 1415 }
1358 1416
1359 TEST(SchedulerStateMachineTest, TestFirstContextCreation) { 1417 TEST(SchedulerStateMachineTest, TestFirstContextCreation) {
1360 SchedulerSettings default_scheduler_settings; 1418 SchedulerSettings default_scheduler_settings;
1361 StateMachine state(default_scheduler_settings); 1419 StateMachine state(default_scheduler_settings);
1362 state.SetVisible(true); 1420 state.SetVisible(true);
1363 state.SetCanDraw(true); 1421 state.SetCanDraw(true);
1364 1422
1365 EXPECT_ACTION_UPDATE_STATE( 1423 EXPECT_ACTION_UPDATE_STATE(
1366 SchedulerStateMachine::ACTION_BEGIN_COMPOSITOR_FRAME_SINK_CREATION); 1424 SchedulerStateMachine::ACTION_BEGIN_COMPOSITOR_FRAME_SINK_CREATION);
1367 state.CreateAndInitializeCompositorFrameSinkWithActivatedCommit(); 1425 state.CreateAndInitializeCompositorFrameSinkWithActivatedCommit();
1368 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1426 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1369 1427
1370 // Check that the first init does not SetNeedsBeginMainFrame. 1428 // Check that the first init does not SetNeedsBeginMainFrame.
1371 state.OnBeginImplFrame(); 1429 state.IssueNextBeginImplFrame();
1372 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1430 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1373 state.OnBeginImplFrameDeadline(); 1431 state.OnBeginImplFrameDeadline();
1374 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1432 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1375 1433
1376 // Check that a needs commit initiates a BeginMainFrame. 1434 // Check that a needs commit initiates a BeginMainFrame.
1377 state.SetNeedsBeginMainFrame(); 1435 state.SetNeedsBeginMainFrame();
1378 state.OnBeginImplFrame(); 1436 state.IssueNextBeginImplFrame();
1379 EXPECT_ACTION_UPDATE_STATE( 1437 EXPECT_ACTION_UPDATE_STATE(
1380 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 1438 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
1381 } 1439 }
1382 1440
1383 TEST(SchedulerStateMachineTest, TestContextLostWhenCompletelyIdle) { 1441 TEST(SchedulerStateMachineTest, TestContextLostWhenCompletelyIdle) {
1384 SchedulerSettings default_scheduler_settings; 1442 SchedulerSettings default_scheduler_settings;
1385 StateMachine state(default_scheduler_settings); 1443 StateMachine state(default_scheduler_settings);
1386 SET_UP_STATE(state) 1444 SET_UP_STATE(state)
1387 1445
1388 EXPECT_NE(SchedulerStateMachine::ACTION_BEGIN_COMPOSITOR_FRAME_SINK_CREATION, 1446 EXPECT_NE(SchedulerStateMachine::ACTION_BEGIN_COMPOSITOR_FRAME_SINK_CREATION,
1389 state.NextAction()); 1447 state.NextAction());
1390 state.DidLoseCompositorFrameSink(); 1448 state.DidLoseCompositorFrameSink();
1391 1449
1392 EXPECT_ACTION_UPDATE_STATE( 1450 EXPECT_ACTION_UPDATE_STATE(
1393 SchedulerStateMachine::ACTION_BEGIN_COMPOSITOR_FRAME_SINK_CREATION); 1451 SchedulerStateMachine::ACTION_BEGIN_COMPOSITOR_FRAME_SINK_CREATION);
1394 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1452 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1395 1453
1396 // Once context recreation begins, nothing should happen. 1454 // Once context recreation begins, nothing should happen.
1397 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1455 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1398 1456
1399 // Recreate the context. 1457 // Recreate the context.
1400 state.CreateAndInitializeCompositorFrameSinkWithActivatedCommit(); 1458 state.CreateAndInitializeCompositorFrameSinkWithActivatedCommit();
1401 1459
1402 // When the context is recreated, we should begin a commit. 1460 // When the context is recreated, we should begin a commit.
1403 state.OnBeginImplFrame(); 1461 state.IssueNextBeginImplFrame();
1404 EXPECT_ACTION_UPDATE_STATE( 1462 EXPECT_ACTION_UPDATE_STATE(
1405 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 1463 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
1406 } 1464 }
1407 1465
1408 TEST(SchedulerStateMachineTest, 1466 TEST(SchedulerStateMachineTest,
1409 TestContextLostWhenIdleAndCommitRequestedWhileRecreating) { 1467 TestContextLostWhenIdleAndCommitRequestedWhileRecreating) {
1410 SchedulerSettings default_scheduler_settings; 1468 SchedulerSettings default_scheduler_settings;
1411 StateMachine state(default_scheduler_settings); 1469 StateMachine state(default_scheduler_settings);
1412 SET_UP_STATE(state) 1470 SET_UP_STATE(state)
1413 1471
1414 EXPECT_NE(SchedulerStateMachine::ACTION_BEGIN_COMPOSITOR_FRAME_SINK_CREATION, 1472 EXPECT_NE(SchedulerStateMachine::ACTION_BEGIN_COMPOSITOR_FRAME_SINK_CREATION,
1415 state.NextAction()); 1473 state.NextAction());
1416 state.DidLoseCompositorFrameSink(); 1474 state.DidLoseCompositorFrameSink();
1417 EXPECT_EQ(state.compositor_frame_sink_state(), 1475 EXPECT_EQ(state.compositor_frame_sink_state(),
1418 SchedulerStateMachine::COMPOSITOR_FRAME_SINK_NONE); 1476 SchedulerStateMachine::COMPOSITOR_FRAME_SINK_NONE);
1419 1477
1420 EXPECT_ACTION_UPDATE_STATE( 1478 EXPECT_ACTION_UPDATE_STATE(
1421 SchedulerStateMachine::ACTION_BEGIN_COMPOSITOR_FRAME_SINK_CREATION); 1479 SchedulerStateMachine::ACTION_BEGIN_COMPOSITOR_FRAME_SINK_CREATION);
1422 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1480 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1423 1481
1424 // Once context recreation begins, nothing should happen. 1482 // Once context recreation begins, nothing should happen.
1425 state.OnBeginImplFrame(); 1483 state.IssueNextBeginImplFrame();
1426 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1484 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1427 state.OnBeginImplFrameDeadline(); 1485 state.OnBeginImplFrameDeadline();
1428 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1486 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1429 1487
1430 // While context is recreating, commits shouldn't begin. 1488 // While context is recreating, commits shouldn't begin.
1431 state.SetNeedsBeginMainFrame(); 1489 state.SetNeedsBeginMainFrame();
1432 state.OnBeginImplFrame(); 1490 state.IssueNextBeginImplFrame();
1433 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1491 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1434 state.OnBeginImplFrameDeadline(); 1492 state.OnBeginImplFrameDeadline();
1435 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1493 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1436 1494
1437 // Recreate the context 1495 // Recreate the context
1438 state.DidCreateAndInitializeCompositorFrameSink(); 1496 state.DidCreateAndInitializeCompositorFrameSink();
1439 EXPECT_EQ( 1497 EXPECT_EQ(
1440 state.compositor_frame_sink_state(), 1498 state.compositor_frame_sink_state(),
1441 SchedulerStateMachine::COMPOSITOR_FRAME_SINK_WAITING_FOR_FIRST_COMMIT); 1499 SchedulerStateMachine::COMPOSITOR_FRAME_SINK_WAITING_FOR_FIRST_COMMIT);
1442 EXPECT_FALSE(state.RedrawPending()); 1500 EXPECT_FALSE(state.RedrawPending());
1443 1501
1444 // When the context is recreated, we wait until the next BeginImplFrame 1502 // When the context is recreated, we wait until the next BeginImplFrame
1445 // before starting. 1503 // before starting.
1446 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1504 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1447 1505
1448 // When the BeginFrame comes in we should begin a commit 1506 // When the BeginFrame comes in we should begin a commit
1449 state.OnBeginImplFrame(); 1507 state.IssueNextBeginImplFrame();
1450 EXPECT_ACTION_UPDATE_STATE( 1508 EXPECT_ACTION_UPDATE_STATE(
1451 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 1509 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
1452 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1510 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1453 EXPECT_MAIN_FRAME_STATE(SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_SENT); 1511 EXPECT_MAIN_FRAME_STATE(SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_SENT);
1454 1512
1455 // Until that commit finishes, we shouldn't be drawing. 1513 // Until that commit finishes, we shouldn't be drawing.
1456 state.OnBeginImplFrameDeadline(); 1514 state.OnBeginImplFrameDeadline();
1457 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1515 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1458 1516
1459 // Finish the commit, which should make the surface active. 1517 // Finish the commit, which should make the surface active.
1460 state.NotifyBeginMainFrameStarted(); 1518 state.NotifyBeginMainFrameStarted();
1461 state.NotifyReadyToCommit(); 1519 state.NotifyReadyToCommit();
1462 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 1520 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
1463 EXPECT_EQ(state.compositor_frame_sink_state(), 1521 EXPECT_EQ(state.compositor_frame_sink_state(),
1464 SchedulerStateMachine:: 1522 SchedulerStateMachine::
1465 COMPOSITOR_FRAME_SINK_WAITING_FOR_FIRST_ACTIVATION); 1523 COMPOSITOR_FRAME_SINK_WAITING_FOR_FIRST_ACTIVATION);
1466 state.NotifyReadyToActivate(); 1524 state.NotifyReadyToActivate();
1467 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE); 1525 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE);
1468 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1526 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1469 EXPECT_EQ(state.compositor_frame_sink_state(), 1527 EXPECT_EQ(state.compositor_frame_sink_state(),
1470 SchedulerStateMachine::COMPOSITOR_FRAME_SINK_ACTIVE); 1528 SchedulerStateMachine::COMPOSITOR_FRAME_SINK_ACTIVE);
1471 1529
1472 // Finishing the first commit after initializing an CompositorFrameSink should 1530 // Finishing the first commit after initializing an CompositorFrameSink should
1473 // automatically cause a redraw. 1531 // automatically cause a redraw.
1474 EXPECT_TRUE(state.RedrawPending()); 1532 EXPECT_TRUE(state.RedrawPending());
1475 state.OnBeginImplFrame(); 1533 state.IssueNextBeginImplFrame();
1476 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1534 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1477 state.OnBeginImplFrameDeadline(); 1535 state.OnBeginImplFrameDeadline();
1478 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE); 1536 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE);
1479 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1537 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1480 EXPECT_FALSE(state.RedrawPending()); 1538 EXPECT_FALSE(state.RedrawPending());
1481 1539
1482 // Next frame as no work to do. 1540 // Next frame as no work to do.
1483 state.OnBeginImplFrame(); 1541 state.IssueNextBeginImplFrame();
1484 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1542 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1485 state.OnBeginImplFrameDeadline(); 1543 state.OnBeginImplFrameDeadline();
1486 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1544 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1487 1545
1488 // Once the context is recreated, whether we draw should be based on 1546 // Once the context is recreated, whether we draw should be based on
1489 // SetCanDraw if waiting on first draw after activate. 1547 // SetCanDraw if waiting on first draw after activate.
1490 state.SetNeedsRedraw(true); 1548 state.SetNeedsRedraw(true);
1491 state.OnBeginImplFrame(); 1549 state.IssueNextBeginImplFrame();
1492 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1550 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1493 state.OnBeginImplFrameDeadline(); 1551 state.OnBeginImplFrameDeadline();
1494 EXPECT_ACTION(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE); 1552 EXPECT_ACTION(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE);
1495 state.SetCanDraw(false); 1553 state.SetCanDraw(false);
1496 EXPECT_ACTION(SchedulerStateMachine::ACTION_NONE); 1554 EXPECT_ACTION(SchedulerStateMachine::ACTION_NONE);
1497 state.SetCanDraw(true); 1555 state.SetCanDraw(true);
1498 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE); 1556 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE);
1499 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1557 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1500 1558
1501 // Once the context is recreated, whether we draw should be based on 1559 // Once the context is recreated, whether we draw should be based on
1502 // SetCanDraw if waiting on first draw after activate. 1560 // SetCanDraw if waiting on first draw after activate.
1503 state.SetNeedsRedraw(true); 1561 state.SetNeedsRedraw(true);
1504 state.SetNeedsBeginMainFrame(); 1562 state.SetNeedsBeginMainFrame();
1505 state.OnBeginImplFrame(); 1563 state.IssueNextBeginImplFrame();
1506 EXPECT_ACTION_UPDATE_STATE( 1564 EXPECT_ACTION_UPDATE_STATE(
1507 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 1565 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
1508 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1566 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1509 // Activate so we need the first draw 1567 // Activate so we need the first draw
1510 state.NotifyBeginMainFrameStarted(); 1568 state.NotifyBeginMainFrameStarted();
1511 state.NotifyReadyToCommit(); 1569 state.NotifyReadyToCommit();
1512 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 1570 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
1513 state.NotifyReadyToActivate(); 1571 state.NotifyReadyToActivate();
1514 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE); 1572 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE);
1515 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1573 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
(...skipping 11 matching lines...) Expand all
1527 TEST(SchedulerStateMachineTest, TestContextLostWhileCommitInProgress) { 1585 TEST(SchedulerStateMachineTest, TestContextLostWhileCommitInProgress) {
1528 SchedulerSettings scheduler_settings; 1586 SchedulerSettings scheduler_settings;
1529 StateMachine state(scheduler_settings); 1587 StateMachine state(scheduler_settings);
1530 SET_UP_STATE(state) 1588 SET_UP_STATE(state)
1531 1589
1532 // Get a commit in flight. 1590 // Get a commit in flight.
1533 state.SetNeedsBeginMainFrame(); 1591 state.SetNeedsBeginMainFrame();
1534 1592
1535 // Set damage and expect a draw. 1593 // Set damage and expect a draw.
1536 state.SetNeedsRedraw(true); 1594 state.SetNeedsRedraw(true);
1537 state.OnBeginImplFrame(); 1595 state.OnBeginImplFrame(0, 10);
1538 EXPECT_ACTION_UPDATE_STATE( 1596 EXPECT_ACTION_UPDATE_STATE(
1539 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 1597 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
1540 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1598 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1541 state.OnBeginImplFrameDeadline(); 1599 state.OnBeginImplFrameDeadline();
1542 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE); 1600 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE);
1543 state.DidSubmitCompositorFrame(); 1601 state.DidSubmitCompositorFrame();
1544 state.DidReceiveCompositorFrameAck(); 1602 state.DidReceiveCompositorFrameAck();
1545 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1603 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1604 EXPECT_SEQUENCE_NUMBERS(10u, 10u, BeginFrameArgs::kInvalidFrameNumber,
1605 BeginFrameArgs::kInvalidFrameNumber,
1606 BeginFrameArgs::kInvalidFrameNumber);
1546 1607
1547 // Cause a lost context while the BeginMainFrame is in flight. 1608 // Cause a lost context while the BeginMainFrame is in flight.
1548 state.DidLoseCompositorFrameSink(); 1609 state.DidLoseCompositorFrameSink();
1610 EXPECT_FALSE(state.BeginFrameNeeded());
1549 1611
1550 // Ask for another draw. Expect nothing happens. 1612 // Ask for another draw. Expect nothing happens.
1551 state.SetNeedsRedraw(true); 1613 state.SetNeedsRedraw(true);
1552 EXPECT_ACTION(SchedulerStateMachine::ACTION_NONE); 1614 EXPECT_ACTION(SchedulerStateMachine::ACTION_NONE);
1553 1615
1554 // Finish the frame, commit and activate. 1616 // Finish the frame, commit and activate.
1555 state.NotifyBeginMainFrameStarted(); 1617 state.NotifyBeginMainFrameStarted();
1556 state.NotifyReadyToCommit(); 1618 state.NotifyReadyToCommit();
1557 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 1619 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
1620 EXPECT_SEQUENCE_NUMBERS(10u, 10u, 10u, BeginFrameArgs::kInvalidFrameNumber,
1621 BeginFrameArgs::kInvalidFrameNumber);
1558 state.NotifyReadyToActivate(); 1622 state.NotifyReadyToActivate();
1559 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE); 1623 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE);
1624 EXPECT_SEQUENCE_NUMBERS(10u, 10u, 10u, 10u,
1625 BeginFrameArgs::kInvalidFrameNumber);
1560 1626
1561 // We will abort the draw when the CompositorFrameSink is lost if we are 1627 // We will abort the draw when the CompositorFrameSink is lost if we are
1562 // waiting for the first draw to unblock the main thread. 1628 // waiting for the first draw to unblock the main thread.
1563 EXPECT_TRUE(state.active_tree_needs_first_draw()); 1629 EXPECT_TRUE(state.active_tree_needs_first_draw());
1564 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_ABORT); 1630 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_ABORT);
1631 EXPECT_SEQUENCE_NUMBERS(10u, 10u, 10u, 10u,
1632 BeginFrameArgs::kInvalidFrameNumber);
1565 1633
1566 // Expect to begin context recreation only in BEGIN_IMPL_FRAME_STATE_IDLE 1634 // Expect to begin context recreation only in BEGIN_IMPL_FRAME_STATE_IDLE
1567 EXPECT_IMPL_FRAME_STATE(SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE); 1635 EXPECT_IMPL_FRAME_STATE(SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE);
1568 EXPECT_ACTION( 1636 EXPECT_ACTION(
1569 SchedulerStateMachine::ACTION_BEGIN_COMPOSITOR_FRAME_SINK_CREATION); 1637 SchedulerStateMachine::ACTION_BEGIN_COMPOSITOR_FRAME_SINK_CREATION);
1570 1638
1571 state.OnBeginImplFrame(); 1639 state.OnBeginImplFrame(0, 11);
1572 EXPECT_IMPL_FRAME_STATE( 1640 EXPECT_IMPL_FRAME_STATE(
1573 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_BEGIN_FRAME); 1641 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_BEGIN_FRAME);
1574 EXPECT_ACTION(SchedulerStateMachine::ACTION_NONE); 1642 EXPECT_ACTION(SchedulerStateMachine::ACTION_NONE);
1643 EXPECT_SEQUENCE_NUMBERS(11u, 10u, 10u, 10u,
1644 BeginFrameArgs::kInvalidFrameNumber);
1575 1645
1576 state.OnBeginImplFrameDeadline(); 1646 state.OnBeginImplFrameDeadline();
1577 EXPECT_IMPL_FRAME_STATE( 1647 EXPECT_IMPL_FRAME_STATE(
1578 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE); 1648 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE);
1579 EXPECT_ACTION(SchedulerStateMachine::ACTION_NONE); 1649 EXPECT_ACTION(SchedulerStateMachine::ACTION_NONE);
1650 EXPECT_SEQUENCE_NUMBERS(11u, 10u, 10u, 11u, 11u);
1580 } 1651 }
1581 1652
1582 TEST(SchedulerStateMachineTest, 1653 TEST(SchedulerStateMachineTest,
1583 TestContextLostWhileCommitInProgressAndAnotherCommitRequested) { 1654 TestContextLostWhileCommitInProgressAndAnotherCommitRequested) {
1584 SchedulerSettings scheduler_settings; 1655 SchedulerSettings scheduler_settings;
1585 StateMachine state(scheduler_settings); 1656 StateMachine state(scheduler_settings);
1586 SET_UP_STATE(state) 1657 SET_UP_STATE(state)
1587 1658
1588 // Get a commit in flight. 1659 // Get a commit in flight.
1589 state.SetNeedsBeginMainFrame(); 1660 state.SetNeedsBeginMainFrame();
1590 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1661 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1591 1662
1592 // Set damage and expect a draw. 1663 // Set damage and expect a draw.
1593 state.SetNeedsRedraw(true); 1664 state.SetNeedsRedraw(true);
1594 state.OnBeginImplFrame(); 1665 state.IssueNextBeginImplFrame();
1595 EXPECT_ACTION_UPDATE_STATE( 1666 EXPECT_ACTION_UPDATE_STATE(
1596 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 1667 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
1597 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1668 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1598 state.OnBeginImplFrameDeadline(); 1669 state.OnBeginImplFrameDeadline();
1599 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE); 1670 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE);
1600 state.DidSubmitCompositorFrame(); 1671 state.DidSubmitCompositorFrame();
1601 state.DidReceiveCompositorFrameAck(); 1672 state.DidReceiveCompositorFrameAck();
1602 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1673 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1603 1674
1604 // Cause a lost context while the BeginMainFrame is in flight. 1675 // Cause a lost context while the BeginMainFrame is in flight.
(...skipping 13 matching lines...) Expand all
1618 EXPECT_TRUE(state.active_tree_needs_first_draw()); 1689 EXPECT_TRUE(state.active_tree_needs_first_draw());
1619 1690
1620 // Because the CompositorFrameSink is missing, we expect the draw to abort. 1691 // Because the CompositorFrameSink is missing, we expect the draw to abort.
1621 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_ABORT); 1692 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_ABORT);
1622 1693
1623 // Expect to begin context recreation only in BEGIN_IMPL_FRAME_STATE_IDLE 1694 // Expect to begin context recreation only in BEGIN_IMPL_FRAME_STATE_IDLE
1624 EXPECT_IMPL_FRAME_STATE(SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE); 1695 EXPECT_IMPL_FRAME_STATE(SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE);
1625 EXPECT_ACTION( 1696 EXPECT_ACTION(
1626 SchedulerStateMachine::ACTION_BEGIN_COMPOSITOR_FRAME_SINK_CREATION); 1697 SchedulerStateMachine::ACTION_BEGIN_COMPOSITOR_FRAME_SINK_CREATION);
1627 1698
1628 state.OnBeginImplFrame(); 1699 state.IssueNextBeginImplFrame();
1629 EXPECT_IMPL_FRAME_STATE( 1700 EXPECT_IMPL_FRAME_STATE(
1630 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_BEGIN_FRAME); 1701 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_BEGIN_FRAME);
1631 EXPECT_ACTION(SchedulerStateMachine::ACTION_NONE); 1702 EXPECT_ACTION(SchedulerStateMachine::ACTION_NONE);
1632 1703
1633 state.OnBeginImplFrameDeadline(); 1704 state.OnBeginImplFrameDeadline();
1634 EXPECT_IMPL_FRAME_STATE( 1705 EXPECT_IMPL_FRAME_STATE(
1635 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE); 1706 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE);
1636 EXPECT_ACTION(SchedulerStateMachine::ACTION_NONE); 1707 EXPECT_ACTION(SchedulerStateMachine::ACTION_NONE);
1637 1708
1638 state.OnBeginImplFrameIdle(); 1709 state.OnBeginImplFrameIdle();
1639 EXPECT_ACTION_UPDATE_STATE( 1710 EXPECT_ACTION_UPDATE_STATE(
1640 SchedulerStateMachine::ACTION_BEGIN_COMPOSITOR_FRAME_SINK_CREATION); 1711 SchedulerStateMachine::ACTION_BEGIN_COMPOSITOR_FRAME_SINK_CREATION);
1641 1712
1642 // After we get a new CompositorFrameSink, the commit flow should start. 1713 // After we get a new CompositorFrameSink, the commit flow should start.
1643 state.CreateAndInitializeCompositorFrameSinkWithActivatedCommit(); 1714 state.CreateAndInitializeCompositorFrameSinkWithActivatedCommit();
1644 state.OnBeginImplFrame(); 1715 state.IssueNextBeginImplFrame();
1645 EXPECT_ACTION_UPDATE_STATE( 1716 EXPECT_ACTION_UPDATE_STATE(
1646 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 1717 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
1647 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1718 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1648 state.NotifyBeginMainFrameStarted(); 1719 state.NotifyBeginMainFrameStarted();
1649 state.NotifyReadyToCommit(); 1720 state.NotifyReadyToCommit();
1650 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 1721 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
1651 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1722 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1652 state.NotifyReadyToActivate(); 1723 state.NotifyReadyToActivate();
1653 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE); 1724 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE);
1654 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1725 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
(...skipping 13 matching lines...) Expand all
1668 state.SetNeedsRedraw(true); 1739 state.SetNeedsRedraw(true);
1669 1740
1670 // Cause a lost CompositorFrameSink, and restore it. 1741 // Cause a lost CompositorFrameSink, and restore it.
1671 state.DidLoseCompositorFrameSink(); 1742 state.DidLoseCompositorFrameSink();
1672 EXPECT_ACTION_UPDATE_STATE( 1743 EXPECT_ACTION_UPDATE_STATE(
1673 SchedulerStateMachine::ACTION_BEGIN_COMPOSITOR_FRAME_SINK_CREATION); 1744 SchedulerStateMachine::ACTION_BEGIN_COMPOSITOR_FRAME_SINK_CREATION);
1674 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1745 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1675 state.DidCreateAndInitializeCompositorFrameSink(); 1746 state.DidCreateAndInitializeCompositorFrameSink();
1676 1747
1677 EXPECT_FALSE(state.RedrawPending()); 1748 EXPECT_FALSE(state.RedrawPending());
1678 state.OnBeginImplFrame(); 1749 state.IssueNextBeginImplFrame();
1679 EXPECT_ACTION(SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 1750 EXPECT_ACTION(SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
1680 } 1751 }
1681 1752
1682 TEST(SchedulerStateMachineTest, 1753 TEST(SchedulerStateMachineTest,
1683 TestPendingActivationsShouldBeForcedAfterLostCompositorFrameSink) { 1754 TestPendingActivationsShouldBeForcedAfterLostCompositorFrameSink) {
1684 SchedulerSettings default_scheduler_settings; 1755 SchedulerSettings default_scheduler_settings;
1685 StateMachine state(default_scheduler_settings); 1756 StateMachine state(default_scheduler_settings);
1686 SET_UP_STATE(state) 1757 SET_UP_STATE(state)
1687 1758
1688 state.SetBeginMainFrameState( 1759 state.SetBeginMainFrameState(
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
1731 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1802 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1732 state.CreateAndInitializeCompositorFrameSinkWithActivatedCommit(); 1803 state.CreateAndInitializeCompositorFrameSinkWithActivatedCommit();
1733 state.SetVisible(false); 1804 state.SetVisible(false);
1734 state.SetNeedsBeginMainFrame(); 1805 state.SetNeedsBeginMainFrame();
1735 EXPECT_ACTION(SchedulerStateMachine::ACTION_NONE); 1806 EXPECT_ACTION(SchedulerStateMachine::ACTION_NONE);
1736 EXPECT_FALSE(state.BeginFrameNeeded()); 1807 EXPECT_FALSE(state.BeginFrameNeeded());
1737 1808
1738 // When become visible again, the needs commit should still be pending. 1809 // When become visible again, the needs commit should still be pending.
1739 state.SetVisible(true); 1810 state.SetVisible(true);
1740 EXPECT_TRUE(state.BeginFrameNeeded()); 1811 EXPECT_TRUE(state.BeginFrameNeeded());
1741 state.OnBeginImplFrame(); 1812 state.IssueNextBeginImplFrame();
1742 EXPECT_ACTION_UPDATE_STATE( 1813 EXPECT_ACTION_UPDATE_STATE(
1743 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 1814 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
1744 } 1815 }
1745 1816
1746 TEST(SchedulerStateMachineTest, TestFinishCommitWhenCommitInProgress) { 1817 TEST(SchedulerStateMachineTest, TestFinishCommitWhenCommitInProgress) {
1747 SchedulerSettings default_scheduler_settings; 1818 SchedulerSettings default_scheduler_settings;
1748 StateMachine state(default_scheduler_settings); 1819 StateMachine state(default_scheduler_settings);
1749 state.SetVisible(true); 1820 state.SetVisible(true);
1750 EXPECT_ACTION_UPDATE_STATE( 1821 EXPECT_ACTION_UPDATE_STATE(
1751 SchedulerStateMachine::ACTION_BEGIN_COMPOSITOR_FRAME_SINK_CREATION); 1822 SchedulerStateMachine::ACTION_BEGIN_COMPOSITOR_FRAME_SINK_CREATION);
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
1895 } 1966 }
1896 1967
1897 TEST(SchedulerStateMachineTest, 1968 TEST(SchedulerStateMachineTest,
1898 TestTriggerDeadlineImmediatelyAfterAbortedCommit) { 1969 TestTriggerDeadlineImmediatelyAfterAbortedCommit) {
1899 SchedulerSettings default_scheduler_settings; 1970 SchedulerSettings default_scheduler_settings;
1900 StateMachine state(default_scheduler_settings); 1971 StateMachine state(default_scheduler_settings);
1901 SET_UP_STATE(state) 1972 SET_UP_STATE(state)
1902 1973
1903 // This test mirrors what happens during the first frame of a scroll gesture. 1974 // This test mirrors what happens during the first frame of a scroll gesture.
1904 // First we get the input event and a BeginFrame. 1975 // First we get the input event and a BeginFrame.
1905 state.OnBeginImplFrame(); 1976 state.IssueNextBeginImplFrame();
1906 1977
1907 // As a response the compositor requests a redraw and a commit to tell the 1978 // As a response the compositor requests a redraw and a commit to tell the
1908 // main thread about the new scroll offset. 1979 // main thread about the new scroll offset.
1909 state.SetNeedsRedraw(true); 1980 state.SetNeedsRedraw(true);
1910 state.SetNeedsBeginMainFrame(); 1981 state.SetNeedsBeginMainFrame();
1911 1982
1912 // We should start the commit normally. 1983 // We should start the commit normally.
1913 EXPECT_ACTION_UPDATE_STATE( 1984 EXPECT_ACTION_UPDATE_STATE(
1914 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 1985 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
1915 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1986 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
(...skipping 14 matching lines...) Expand all
1930 StateMachine& state = *state_ptr; 2001 StateMachine& state = *state_ptr;
1931 2002
1932 state.NotifyBeginMainFrameStarted(); 2003 state.NotifyBeginMainFrameStarted();
1933 state.NotifyReadyToCommit(); 2004 state.NotifyReadyToCommit();
1934 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 2005 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
1935 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 2006 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1936 state.NotifyReadyToActivate(); 2007 state.NotifyReadyToActivate();
1937 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE); 2008 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE);
1938 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 2009 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1939 2010
1940 state.OnBeginImplFrame(); 2011 state.IssueNextBeginImplFrame();
1941 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 2012 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1942 2013
1943 EXPECT_TRUE(state.ShouldTriggerBeginImplFrameDeadlineImmediately()); 2014 EXPECT_TRUE(state.ShouldTriggerBeginImplFrameDeadlineImmediately());
1944 state.OnBeginImplFrameDeadline(); 2015 state.OnBeginImplFrameDeadline();
1945 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE); 2016 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE);
1946 state.DidSubmitCompositorFrame(); 2017 state.DidSubmitCompositorFrame();
1947 } 2018 }
1948 2019
1949 TEST(SchedulerStateMachineTest, TestImplLatencyTakesPriority) { 2020 TEST(SchedulerStateMachineTest, TestImplLatencyTakesPriority) {
1950 SchedulerSettings default_scheduler_settings; 2021 SchedulerSettings default_scheduler_settings;
1951 StateMachine state(default_scheduler_settings); 2022 StateMachine state(default_scheduler_settings);
1952 SET_UP_STATE(state) 2023 SET_UP_STATE(state)
1953 2024
1954 // This test ensures that impl-draws are prioritized over main thread updates 2025 // This test ensures that impl-draws are prioritized over main thread updates
1955 // in prefer impl latency mode. 2026 // in prefer impl latency mode.
1956 state.SetNeedsRedraw(true); 2027 state.SetNeedsRedraw(true);
1957 state.SetNeedsBeginMainFrame(); 2028 state.SetNeedsBeginMainFrame();
1958 state.OnBeginImplFrame(); 2029 state.IssueNextBeginImplFrame();
1959 EXPECT_ACTION_UPDATE_STATE( 2030 EXPECT_ACTION_UPDATE_STATE(
1960 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 2031 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
1961 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 2032 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1962 2033
1963 // Verify the deadline is not triggered early until we enter 2034 // Verify the deadline is not triggered early until we enter
1964 // prefer impl latency mode. 2035 // prefer impl latency mode.
1965 EXPECT_FALSE(state.ShouldTriggerBeginImplFrameDeadlineImmediately()); 2036 EXPECT_FALSE(state.ShouldTriggerBeginImplFrameDeadlineImmediately());
1966 state.SetTreePrioritiesAndScrollState( 2037 state.SetTreePrioritiesAndScrollState(
1967 SMOOTHNESS_TAKES_PRIORITY, 2038 SMOOTHNESS_TAKES_PRIORITY,
1968 ScrollHandlerState::SCROLL_DOES_NOT_AFFECT_SCROLL_HANDLER); 2039 ScrollHandlerState::SCROLL_DOES_NOT_AFFECT_SCROLL_HANDLER);
(...skipping 16 matching lines...) Expand all
1985 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 2056 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1986 2057
1987 // Finish the previous commit and draw it. 2058 // Finish the previous commit and draw it.
1988 FinishPreviousCommitAndDrawWithoutExitingDeadline(&state); 2059 FinishPreviousCommitAndDrawWithoutExitingDeadline(&state);
1989 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 2060 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1990 2061
1991 // Verify we do not send another BeginMainFrame if was are submit-frame 2062 // Verify we do not send another BeginMainFrame if was are submit-frame
1992 // throttled and did not just submit one. 2063 // throttled and did not just submit one.
1993 state.SetNeedsBeginMainFrame(); 2064 state.SetNeedsBeginMainFrame();
1994 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 2065 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1995 state.OnBeginImplFrame(); 2066 state.IssueNextBeginImplFrame();
1996 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 2067 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1997 EXPECT_FALSE(state.ShouldTriggerBeginImplFrameDeadlineImmediately()); 2068 EXPECT_FALSE(state.ShouldTriggerBeginImplFrameDeadlineImmediately());
1998 state.OnBeginImplFrameDeadline(); 2069 state.OnBeginImplFrameDeadline();
1999 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 2070 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
2000 } 2071 }
2001 2072
2002 TEST(SchedulerStateMachineTest, 2073 TEST(SchedulerStateMachineTest,
2003 TestTriggerDeadlineImmediatelyOnLostCompositorFrameSink) { 2074 TestTriggerDeadlineImmediatelyOnLostCompositorFrameSink) {
2004 SchedulerSettings default_scheduler_settings; 2075 SchedulerSettings default_scheduler_settings;
2005 StateMachine state(default_scheduler_settings); 2076 StateMachine state(default_scheduler_settings);
2006 SET_UP_STATE(state) 2077 SET_UP_STATE(state)
2007 2078
2008 state.SetNeedsBeginMainFrame(); 2079 state.SetNeedsBeginMainFrame();
2009 2080
2010 state.OnBeginImplFrame(); 2081 state.IssueNextBeginImplFrame();
2011 EXPECT_ACTION_UPDATE_STATE( 2082 EXPECT_ACTION_UPDATE_STATE(
2012 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 2083 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
2013 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 2084 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
2014 EXPECT_FALSE(state.ShouldTriggerBeginImplFrameDeadlineImmediately()); 2085 EXPECT_FALSE(state.ShouldTriggerBeginImplFrameDeadlineImmediately());
2015 2086
2016 state.DidLoseCompositorFrameSink(); 2087 state.DidLoseCompositorFrameSink();
2017 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 2088 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
2018 // The deadline should be triggered immediately when CompositorFrameSink is 2089 // The deadline should be triggered immediately when CompositorFrameSink is
2019 // lost. 2090 // lost.
2020 EXPECT_TRUE(state.ShouldTriggerBeginImplFrameDeadlineImmediately()); 2091 EXPECT_TRUE(state.ShouldTriggerBeginImplFrameDeadlineImmediately());
2021 } 2092 }
2022 2093
2023 TEST(SchedulerStateMachineTest, TestTriggerDeadlineImmediatelyWhenInvisible) { 2094 TEST(SchedulerStateMachineTest, TestTriggerDeadlineImmediatelyWhenInvisible) {
2024 SchedulerSettings default_scheduler_settings; 2095 SchedulerSettings default_scheduler_settings;
2025 StateMachine state(default_scheduler_settings); 2096 StateMachine state(default_scheduler_settings);
2026 SET_UP_STATE(state) 2097 SET_UP_STATE(state)
2027 2098
2028 state.SetNeedsBeginMainFrame(); 2099 state.SetNeedsBeginMainFrame();
2029 2100
2030 state.OnBeginImplFrame(); 2101 state.IssueNextBeginImplFrame();
2031 EXPECT_ACTION_UPDATE_STATE( 2102 EXPECT_ACTION_UPDATE_STATE(
2032 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 2103 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
2033 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 2104 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
2034 EXPECT_FALSE(state.ShouldTriggerBeginImplFrameDeadlineImmediately()); 2105 EXPECT_FALSE(state.ShouldTriggerBeginImplFrameDeadlineImmediately());
2035 2106
2036 state.SetVisible(false); 2107 state.SetVisible(false);
2037 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 2108 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
2038 EXPECT_TRUE(state.PendingActivationsShouldBeForced()); 2109 EXPECT_TRUE(state.PendingActivationsShouldBeForced());
2039 EXPECT_TRUE(state.ShouldTriggerBeginImplFrameDeadlineImmediately()); 2110 EXPECT_TRUE(state.ShouldTriggerBeginImplFrameDeadlineImmediately());
2040 } 2111 }
2041 2112
2042 TEST(SchedulerStateMachineTest, 2113 TEST(SchedulerStateMachineTest,
2043 TestTriggerDeadlineImmediatelyWhenBeginFrameSourcePaused) { 2114 TestTriggerDeadlineImmediatelyWhenBeginFrameSourcePaused) {
2044 SchedulerSettings default_scheduler_settings; 2115 SchedulerSettings default_scheduler_settings;
2045 StateMachine state(default_scheduler_settings); 2116 StateMachine state(default_scheduler_settings);
2046 SET_UP_STATE(state) 2117 SET_UP_STATE(state)
2047 2118
2048 state.SetNeedsBeginMainFrame(); 2119 state.SetNeedsBeginMainFrame();
2049 2120
2050 state.OnBeginImplFrame(); 2121 state.IssueNextBeginImplFrame();
2051 EXPECT_ACTION_UPDATE_STATE( 2122 EXPECT_ACTION_UPDATE_STATE(
2052 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 2123 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
2053 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 2124 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
2054 EXPECT_FALSE(state.ShouldTriggerBeginImplFrameDeadlineImmediately()); 2125 EXPECT_FALSE(state.ShouldTriggerBeginImplFrameDeadlineImmediately());
2055 2126
2056 state.SetBeginFrameSourcePaused(true); 2127 state.SetBeginFrameSourcePaused(true);
2057 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 2128 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
2058 EXPECT_TRUE(state.PendingActivationsShouldBeForced()); 2129 EXPECT_TRUE(state.PendingActivationsShouldBeForced());
2059 EXPECT_TRUE(state.ShouldTriggerBeginImplFrameDeadlineImmediately()); 2130 EXPECT_TRUE(state.ShouldTriggerBeginImplFrameDeadlineImmediately());
2060 } 2131 }
2061 2132
2062 TEST(SchedulerStateMachineTest, TestDeferCommit) { 2133 TEST(SchedulerStateMachineTest, TestDeferCommit) {
2063 SchedulerSettings settings; 2134 SchedulerSettings settings;
2064 StateMachine state(settings); 2135 StateMachine state(settings);
2065 SET_UP_STATE(state) 2136 SET_UP_STATE(state)
2066 2137
2067 state.SetDeferCommits(true); 2138 state.SetDeferCommits(true);
2068 2139
2069 state.SetNeedsBeginMainFrame(); 2140 state.SetNeedsBeginMainFrame();
2070 EXPECT_FALSE(state.BeginFrameNeeded()); 2141 EXPECT_FALSE(state.BeginFrameNeeded());
2071 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 2142 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
2072 2143
2073 state.OnBeginImplFrame(); 2144 state.IssueNextBeginImplFrame();
2074 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 2145 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
2075 2146
2076 state.OnBeginImplFrameDeadline(); 2147 state.OnBeginImplFrameDeadline();
2077 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 2148 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
2078 2149
2079 state.SetDeferCommits(false); 2150 state.SetDeferCommits(false);
2080 state.OnBeginImplFrame(); 2151 state.IssueNextBeginImplFrame();
2081 EXPECT_ACTION_UPDATE_STATE( 2152 EXPECT_ACTION_UPDATE_STATE(
2082 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 2153 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
2083 } 2154 }
2084 2155
2085 TEST(SchedulerStateMachineTest, EarlyOutCommitWantsProactiveBeginFrame) { 2156 TEST(SchedulerStateMachineTest, EarlyOutCommitWantsProactiveBeginFrame) {
2086 SchedulerSettings settings; 2157 SchedulerSettings settings;
2087 StateMachine state(settings); 2158 StateMachine state(settings);
2088 SET_UP_STATE(state); 2159 SET_UP_STATE(state);
2089 2160
2090 EXPECT_FALSE(state.ProactiveBeginFrameWanted()); 2161 EXPECT_FALSE(state.ProactiveBeginFrameWanted());
2091 bool commit_has_no_updates = true; 2162 bool commit_has_no_updates = true;
2092 state.WillCommit(commit_has_no_updates); 2163 state.WillCommit(commit_has_no_updates);
2093 EXPECT_TRUE(state.ProactiveBeginFrameWanted()); 2164 EXPECT_TRUE(state.ProactiveBeginFrameWanted());
2094 state.OnBeginImplFrame(); 2165 state.IssueNextBeginImplFrame();
2095 EXPECT_FALSE(state.ProactiveBeginFrameWanted()); 2166 EXPECT_FALSE(state.ProactiveBeginFrameWanted());
2096 } 2167 }
2097 2168
2098 TEST(SchedulerStateMachineTest, 2169 TEST(SchedulerStateMachineTest,
2099 NoCompositorFrameSinkCreationWhileCommitPending) { 2170 NoCompositorFrameSinkCreationWhileCommitPending) {
2100 SchedulerSettings settings; 2171 SchedulerSettings settings;
2101 StateMachine state(settings); 2172 StateMachine state(settings);
2102 SET_UP_STATE(state); 2173 SET_UP_STATE(state);
2103 2174
2104 // Set up the request for a commit and start a frame. 2175 // Set up the request for a commit and start a frame.
2105 state.SetNeedsBeginMainFrame(); 2176 state.SetNeedsBeginMainFrame();
2106 state.OnBeginImplFrame(); 2177 state.IssueNextBeginImplFrame();
2107 PerformAction(&state, SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 2178 PerformAction(&state, SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
2108 2179
2109 // Lose the CompositorFrameSink. 2180 // Lose the CompositorFrameSink.
2110 state.DidLoseCompositorFrameSink(); 2181 state.DidLoseCompositorFrameSink();
2111 2182
2112 // The scheduler shouldn't trigger the CompositorFrameSink creation till the 2183 // The scheduler shouldn't trigger the CompositorFrameSink creation till the
2113 // previous commit has been cleared. 2184 // previous commit has been cleared.
2114 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 2185 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
2115 2186
2116 // Trigger the deadline and ensure that the scheduler does not trigger any 2187 // Trigger the deadline and ensure that the scheduler does not trigger any
(...skipping 15 matching lines...) Expand all
2132 } 2203 }
2133 2204
2134 TEST(SchedulerStateMachineTest, NoImplSideInvalidationsWhileInvisible) { 2205 TEST(SchedulerStateMachineTest, NoImplSideInvalidationsWhileInvisible) {
2135 SchedulerSettings settings; 2206 SchedulerSettings settings;
2136 StateMachine state(settings); 2207 StateMachine state(settings);
2137 SET_UP_STATE(state); 2208 SET_UP_STATE(state);
2138 2209
2139 // No impl-side invalidations should be performed while we are not visible. 2210 // No impl-side invalidations should be performed while we are not visible.
2140 state.SetVisible(false); 2211 state.SetVisible(false);
2141 state.SetNeedsImplSideInvalidation(); 2212 state.SetNeedsImplSideInvalidation();
2142 state.OnBeginImplFrame(); 2213 state.IssueNextBeginImplFrame();
2143 state.OnBeginImplFrameDeadline(); 2214 state.OnBeginImplFrameDeadline();
2144 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 2215 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
2145 } 2216 }
2146 2217
2147 TEST(SchedulerStateMachineTest, 2218 TEST(SchedulerStateMachineTest,
2148 NoImplSideInvalidationsWhenBeginFrameSourcePaused) { 2219 NoImplSideInvalidationsWhenBeginFrameSourcePaused) {
2149 SchedulerSettings settings; 2220 SchedulerSettings settings;
2150 StateMachine state(settings); 2221 StateMachine state(settings);
2151 SET_UP_STATE(state); 2222 SET_UP_STATE(state);
2152 2223
2153 // No impl-side invalidations should be performed while we can not make impl 2224 // No impl-side invalidations should be performed while we can not make impl
2154 // frames. 2225 // frames.
2155 state.SetBeginFrameSourcePaused(true); 2226 state.SetBeginFrameSourcePaused(true);
2156 state.SetNeedsImplSideInvalidation(); 2227 state.SetNeedsImplSideInvalidation();
2157 state.OnBeginImplFrame(); 2228 state.IssueNextBeginImplFrame();
2158 state.OnBeginImplFrameDeadline(); 2229 state.OnBeginImplFrameDeadline();
2159 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 2230 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
2160 } 2231 }
2161 2232
2162 TEST(SchedulerStateMachineTest, ImplSideInvalidationOnlyInsideDeadline) { 2233 TEST(SchedulerStateMachineTest, ImplSideInvalidationOnlyInsideDeadline) {
2163 SchedulerSettings settings; 2234 SchedulerSettings settings;
2164 StateMachine state(settings); 2235 StateMachine state(settings);
2165 SET_UP_STATE(state); 2236 SET_UP_STATE(state);
2166 2237
2167 state.SetNeedsImplSideInvalidation(); 2238 state.SetNeedsImplSideInvalidation();
2168 state.OnBeginImplFrame(); 2239 state.IssueNextBeginImplFrame();
2169 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 2240 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
2170 state.OnBeginImplFrameDeadline(); 2241 state.OnBeginImplFrameDeadline();
2171 EXPECT_ACTION_UPDATE_STATE( 2242 EXPECT_ACTION_UPDATE_STATE(
2172 SchedulerStateMachine::ACTION_PERFORM_IMPL_SIDE_INVALIDATION); 2243 SchedulerStateMachine::ACTION_PERFORM_IMPL_SIDE_INVALIDATION);
2173 } 2244 }
2174 2245
2175 TEST(SchedulerStateMachineTest, 2246 TEST(SchedulerStateMachineTest,
2176 NoImplSideInvalidationWithoutCompositorFrameSink) { 2247 NoImplSideInvalidationWithoutCompositorFrameSink) {
2177 SchedulerSettings settings; 2248 SchedulerSettings settings;
2178 StateMachine state(settings); 2249 StateMachine state(settings);
2179 SET_UP_STATE(state); 2250 SET_UP_STATE(state);
2180 2251
2181 // Impl-side invalidations should not be triggered till the frame sink is 2252 // Impl-side invalidations should not be triggered till the frame sink is
2182 // initialized. 2253 // initialized.
2183 state.DidLoseCompositorFrameSink(); 2254 state.DidLoseCompositorFrameSink();
2184 EXPECT_ACTION_UPDATE_STATE( 2255 EXPECT_ACTION_UPDATE_STATE(
2185 SchedulerStateMachine::ACTION_BEGIN_COMPOSITOR_FRAME_SINK_CREATION); 2256 SchedulerStateMachine::ACTION_BEGIN_COMPOSITOR_FRAME_SINK_CREATION);
2186 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 2257 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
2187 2258
2188 // No impl-side invalidations should be performed during frame sink creation. 2259 // No impl-side invalidations should be performed during frame sink creation.
2189 state.SetNeedsImplSideInvalidation(); 2260 state.SetNeedsImplSideInvalidation();
2190 state.OnBeginImplFrame(); 2261 state.IssueNextBeginImplFrame();
2191 state.OnBeginImplFrameDeadline(); 2262 state.OnBeginImplFrameDeadline();
2192 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 2263 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
2193 2264
2194 // Initializing the CompositorFrameSink puts us in a state waiting for the 2265 // Initializing the CompositorFrameSink puts us in a state waiting for the
2195 // first commit. 2266 // first commit.
2196 state.DidCreateAndInitializeCompositorFrameSink(); 2267 state.DidCreateAndInitializeCompositorFrameSink();
2197 state.OnBeginImplFrame(); 2268 state.IssueNextBeginImplFrame();
2198 EXPECT_ACTION_UPDATE_STATE( 2269 EXPECT_ACTION_UPDATE_STATE(
2199 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 2270 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
2200 state.NotifyBeginMainFrameStarted(); 2271 state.NotifyBeginMainFrameStarted();
2201 state.BeginMainFrameAborted(CommitEarlyOutReason::FINISHED_NO_UPDATES); 2272 state.BeginMainFrameAborted(CommitEarlyOutReason::FINISHED_NO_UPDATES);
2202 state.OnBeginImplFrameDeadline(); 2273 state.OnBeginImplFrameDeadline();
2203 EXPECT_ACTION_UPDATE_STATE( 2274 EXPECT_ACTION_UPDATE_STATE(
2204 SchedulerStateMachine::ACTION_PERFORM_IMPL_SIDE_INVALIDATION); 2275 SchedulerStateMachine::ACTION_PERFORM_IMPL_SIDE_INVALIDATION);
2205 } 2276 }
2206 2277
2207 TEST(SchedulerStateMachineTest, ImplSideInvalidationWhenPendingTreeExists) { 2278 TEST(SchedulerStateMachineTest, ImplSideInvalidationWhenPendingTreeExists) {
2208 SchedulerSettings settings; 2279 SchedulerSettings settings;
2209 StateMachine state(settings); 2280 StateMachine state(settings);
2210 SET_UP_STATE(state); 2281 SET_UP_STATE(state);
2211 2282
2212 // Set up request for the main frame, commit and create the pending tree. 2283 // Set up request for the main frame, commit and create the pending tree.
2213 state.SetNeedsBeginMainFrame(); 2284 state.SetNeedsBeginMainFrame();
2214 state.OnBeginImplFrame(); 2285 state.IssueNextBeginImplFrame();
2215 EXPECT_ACTION_UPDATE_STATE( 2286 EXPECT_ACTION_UPDATE_STATE(
2216 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 2287 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
2217 state.NotifyBeginMainFrameStarted(); 2288 state.NotifyBeginMainFrameStarted();
2218 state.NotifyReadyToCommit(); 2289 state.NotifyReadyToCommit();
2219 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 2290 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
2220 2291
2221 // Request an impl-side invalidation after the commit. The request should wait 2292 // Request an impl-side invalidation after the commit. The request should wait
2222 // till the current pending tree is activated. 2293 // till the current pending tree is activated.
2223 state.SetNeedsImplSideInvalidation(); 2294 state.SetNeedsImplSideInvalidation();
2224 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 2295 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
2225 2296
2226 // Activate the pending tree. Since the commit fills the impl-side 2297 // Activate the pending tree. Since the commit fills the impl-side
2227 // invalidation funnel as well, the request should wait until the next 2298 // invalidation funnel as well, the request should wait until the next
2228 // BeginFrame. 2299 // BeginFrame.
2229 state.NotifyReadyToActivate(); 2300 state.NotifyReadyToActivate();
2230 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE); 2301 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE);
2231 state.OnBeginImplFrameDeadline(); 2302 state.OnBeginImplFrameDeadline();
2232 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE); 2303 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE);
2233 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 2304 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
2234 2305
2235 // Since there is no main frame request, this should perform impl-side 2306 // Since there is no main frame request, this should perform impl-side
2236 // invalidations. 2307 // invalidations.
2237 state.OnBeginImplFrame(); 2308 state.IssueNextBeginImplFrame();
2238 state.OnBeginImplFrameDeadline(); 2309 state.OnBeginImplFrameDeadline();
2239 EXPECT_ACTION_UPDATE_STATE( 2310 EXPECT_ACTION_UPDATE_STATE(
2240 SchedulerStateMachine::ACTION_PERFORM_IMPL_SIDE_INVALIDATION); 2311 SchedulerStateMachine::ACTION_PERFORM_IMPL_SIDE_INVALIDATION);
2241 } 2312 }
2242 2313
2243 TEST(SchedulerStateMachineTest, ImplSideInvalidationWhileReadyToCommit) { 2314 TEST(SchedulerStateMachineTest, ImplSideInvalidationWhileReadyToCommit) {
2244 SchedulerSettings settings; 2315 SchedulerSettings settings;
2245 StateMachine state(settings); 2316 StateMachine state(settings);
2246 SET_UP_STATE(state); 2317 SET_UP_STATE(state);
2247 2318
2248 // Set up request for the main frame. 2319 // Set up request for the main frame.
2249 state.SetNeedsBeginMainFrame(); 2320 state.SetNeedsBeginMainFrame();
2250 state.OnBeginImplFrame(); 2321 state.IssueNextBeginImplFrame();
2322
2251 EXPECT_ACTION_UPDATE_STATE( 2323 EXPECT_ACTION_UPDATE_STATE(
2252 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 2324 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
2253 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 2325 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
2254 2326
2255 // Request an impl-side invalidation. The request should wait till a response 2327 // Request an impl-side invalidation. The request should wait till a response
2256 // is received from the main thread. 2328 // is received from the main thread.
2257 state.SetNeedsImplSideInvalidation(); 2329 state.SetNeedsImplSideInvalidation();
2258 EXPECT_TRUE(state.needs_impl_side_invalidation()); 2330 EXPECT_TRUE(state.needs_impl_side_invalidation());
2259 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 2331 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
2260 2332
(...skipping 10 matching lines...) Expand all
2271 } 2343 }
2272 2344
2273 TEST(SchedulerStateMachineTest, 2345 TEST(SchedulerStateMachineTest,
2274 ConsecutiveImplSideInvalidationsWaitForBeginFrame) { 2346 ConsecutiveImplSideInvalidationsWaitForBeginFrame) {
2275 SchedulerSettings settings; 2347 SchedulerSettings settings;
2276 StateMachine state(settings); 2348 StateMachine state(settings);
2277 SET_UP_STATE(state); 2349 SET_UP_STATE(state);
2278 2350
2279 // Set up a request for impl-side invalidation. 2351 // Set up a request for impl-side invalidation.
2280 state.SetNeedsImplSideInvalidation(); 2352 state.SetNeedsImplSideInvalidation();
2281 state.OnBeginImplFrame(); 2353 state.IssueNextBeginImplFrame();
2282 state.OnBeginImplFrameDeadline(); 2354 state.OnBeginImplFrameDeadline();
2283 EXPECT_ACTION_UPDATE_STATE( 2355 EXPECT_ACTION_UPDATE_STATE(
2284 SchedulerStateMachine::ACTION_PERFORM_IMPL_SIDE_INVALIDATION); 2356 SchedulerStateMachine::ACTION_PERFORM_IMPL_SIDE_INVALIDATION);
2285 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 2357 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
2286 2358
2287 // Request another invalidation, which should wait until the pending tree is 2359 // Request another invalidation, which should wait until the pending tree is
2288 // activated *and* we start the next BeginFrame. 2360 // activated *and* we start the next BeginFrame.
2289 state.SetNeedsImplSideInvalidation(); 2361 state.SetNeedsImplSideInvalidation();
2290 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 2362 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
2291 state.NotifyReadyToActivate(); 2363 state.NotifyReadyToActivate();
2292 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE); 2364 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE);
2293 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 2365 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
2294 2366
2295 // Now start the next frame, which will first draw the active tree and then 2367 // Now start the next frame, which will first draw the active tree and then
2296 // perform the pending impl-side invalidation request. 2368 // perform the pending impl-side invalidation request.
2297 state.OnBeginImplFrame(); 2369 state.IssueNextBeginImplFrame();
2298 state.OnBeginImplFrameDeadline(); 2370 state.OnBeginImplFrameDeadline();
2299 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE); 2371 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE);
2300 EXPECT_ACTION_UPDATE_STATE( 2372 EXPECT_ACTION_UPDATE_STATE(
2301 SchedulerStateMachine::ACTION_PERFORM_IMPL_SIDE_INVALIDATION); 2373 SchedulerStateMachine::ACTION_PERFORM_IMPL_SIDE_INVALIDATION);
2302 } 2374 }
2303 2375
2304 TEST(SchedulerStateMachineTest, ImplSideInvalidationsThrottledOnDraw) { 2376 TEST(SchedulerStateMachineTest, ImplSideInvalidationsThrottledOnDraw) {
2305 // In commit_to_active_tree mode, performing the next invalidation should be 2377 // In commit_to_active_tree mode, performing the next invalidation should be
2306 // throttled on the active tree being drawn. 2378 // throttled on the active tree being drawn.
2307 SchedulerSettings settings; 2379 SchedulerSettings settings;
2308 settings.commit_to_active_tree = true; 2380 settings.commit_to_active_tree = true;
2309 StateMachine state(settings); 2381 StateMachine state(settings);
2310 SET_UP_STATE(state); 2382 SET_UP_STATE(state);
2311 2383
2312 // Commit to the sync tree, activate and draw. 2384 // Commit to the sync tree, activate and draw.
2313 state.SetNeedsBeginMainFrame(); 2385 state.SetNeedsBeginMainFrame();
2314 state.OnBeginImplFrame(); 2386 state.IssueNextBeginImplFrame();
2315 EXPECT_ACTION_UPDATE_STATE( 2387 EXPECT_ACTION_UPDATE_STATE(
2316 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 2388 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
2317 state.NotifyBeginMainFrameStarted(); 2389 state.NotifyBeginMainFrameStarted();
2318 state.NotifyReadyToCommit(); 2390 state.NotifyReadyToCommit();
2319 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 2391 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
2320 state.NotifyReadyToActivate(); 2392 state.NotifyReadyToActivate();
2321 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE); 2393 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE);
2322 state.NotifyReadyToDraw(); 2394 state.NotifyReadyToDraw();
2323 state.OnBeginImplFrameDeadline(); 2395 state.OnBeginImplFrameDeadline();
2324 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE); 2396 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE);
2325 state.DidSubmitCompositorFrame(); 2397 state.DidSubmitCompositorFrame();
2326 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 2398 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
2327 2399
2328 // Request impl-side invalidation and start a new frame, which should be 2400 // Request impl-side invalidation and start a new frame, which should be
2329 // blocked on the ack for the previous frame. 2401 // blocked on the ack for the previous frame.
2330 state.SetNeedsImplSideInvalidation(); 2402 state.SetNeedsImplSideInvalidation();
2331 state.OnBeginImplFrame(); 2403 state.IssueNextBeginImplFrame();
2332 state.OnBeginImplFrameDeadline(); 2404 state.OnBeginImplFrameDeadline();
2333 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 2405 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
2334 2406
2335 // Ack the previous frame and begin impl frame, which should perform the 2407 // Ack the previous frame and begin impl frame, which should perform the
2336 // invalidation now. 2408 // invalidation now.
2337 state.DidReceiveCompositorFrameAck(); 2409 state.DidReceiveCompositorFrameAck();
2338 state.OnBeginImplFrame(); 2410 state.IssueNextBeginImplFrame();
2339 state.OnBeginImplFrameDeadline(); 2411 state.OnBeginImplFrameDeadline();
2340 EXPECT_ACTION_UPDATE_STATE( 2412 EXPECT_ACTION_UPDATE_STATE(
2341 SchedulerStateMachine::ACTION_PERFORM_IMPL_SIDE_INVALIDATION); 2413 SchedulerStateMachine::ACTION_PERFORM_IMPL_SIDE_INVALIDATION);
2342 } 2414 }
2343 2415
2344 TEST(SchedulerStateMachineTest, 2416 TEST(SchedulerStateMachineTest,
2345 ImplSideInvalidationsWhenMainFrameRequestIsPending) { 2417 ImplSideInvalidationsWhenMainFrameRequestIsPending) {
2346 SchedulerSettings settings; 2418 SchedulerSettings settings;
2347 StateMachine state(settings); 2419 StateMachine state(settings);
2348 SET_UP_STATE(state); 2420 SET_UP_STATE(state);
2349 2421
2350 // Set up request for the main frame. 2422 // Set up request for the main frame.
2351 state.SetNeedsBeginMainFrame(); 2423 state.SetNeedsBeginMainFrame();
2352 state.OnBeginImplFrame(); 2424 state.IssueNextBeginImplFrame();
2353 EXPECT_ACTION_UPDATE_STATE( 2425 EXPECT_ACTION_UPDATE_STATE(
2354 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 2426 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
2355 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 2427 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
2356 2428
2357 // Request an impl-side invalidation and trigger the deadline, the 2429 // Request an impl-side invalidation and trigger the deadline, the
2358 // invalidation should run if the request is still pending when we enter the 2430 // invalidation should run if the request is still pending when we enter the
2359 // deadline. 2431 // deadline.
2360 state.SetNeedsImplSideInvalidation(); 2432 state.SetNeedsImplSideInvalidation();
2361 state.OnBeginImplFrameDeadline(); 2433 state.OnBeginImplFrameDeadline();
2362 EXPECT_ACTION_UPDATE_STATE( 2434 EXPECT_ACTION_UPDATE_STATE(
2363 SchedulerStateMachine::ACTION_PERFORM_IMPL_SIDE_INVALIDATION); 2435 SchedulerStateMachine::ACTION_PERFORM_IMPL_SIDE_INVALIDATION);
2364 } 2436 }
2365 2437
2366 TEST(SchedulerStateMachineTest, PrepareTilesWaitForImplSideInvalidation) { 2438 TEST(SchedulerStateMachineTest, PrepareTilesWaitForImplSideInvalidation) {
2367 // PrepareTiles 2439 // PrepareTiles
2368 SchedulerSettings settings; 2440 SchedulerSettings settings;
2369 StateMachine state(settings); 2441 StateMachine state(settings);
2370 SET_UP_STATE(state); 2442 SET_UP_STATE(state);
2371 2443
2372 // Request a PrepareTiles and impl-side invalidation. The impl-side 2444 // Request a PrepareTiles and impl-side invalidation. The impl-side
2373 // invalidation should run first, since it will perform PrepareTiles as well. 2445 // invalidation should run first, since it will perform PrepareTiles as well.
2374 state.SetNeedsImplSideInvalidation(); 2446 state.SetNeedsImplSideInvalidation();
2375 state.SetNeedsPrepareTiles(); 2447 state.SetNeedsPrepareTiles();
2376 state.OnBeginImplFrame(); 2448 state.IssueNextBeginImplFrame();
2377 state.OnBeginImplFrameDeadline(); 2449 state.OnBeginImplFrameDeadline();
2378 EXPECT_ACTION_UPDATE_STATE( 2450 EXPECT_ACTION_UPDATE_STATE(
2379 SchedulerStateMachine::ACTION_PERFORM_IMPL_SIDE_INVALIDATION); 2451 SchedulerStateMachine::ACTION_PERFORM_IMPL_SIDE_INVALIDATION);
2380 state.DidPrepareTiles(); 2452 state.DidPrepareTiles();
2381 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 2453 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
2382 } 2454 }
2383 2455
2456 TEST(SchedulerStateMachineTest, TestBeginFrameFreshnessInitialState) {
2457 SchedulerSettings default_scheduler_settings;
2458 StateMachine state(default_scheduler_settings);
2459 SET_UP_STATE(state)
2460
2461 // Initially, we report invalid frame numbers.
2462 EXPECT_SEQUENCE_NUMBERS(
2463 BeginFrameArgs::kInvalidFrameNumber, BeginFrameArgs::kInvalidFrameNumber,
2464 BeginFrameArgs::kInvalidFrameNumber, BeginFrameArgs::kInvalidFrameNumber,
2465 BeginFrameArgs::kInvalidFrameNumber);
2466 }
2467
2468 TEST(SchedulerStateMachineTest, TestBeginFrameFreshnessWithoutUpdates) {
2469 // Setup without any requested updates.
2470 SchedulerSettings default_scheduler_settings;
2471 StateMachine state(default_scheduler_settings);
2472 SET_UP_STATE(state)
2473 state.SetNeedsRedraw(false);
2474 EXPECT_FALSE(state.RedrawPending());
2475 EXPECT_FALSE(state.NeedsCommit());
2476
2477 // OnBeginImplFrame() updates the sequence number.
2478 state.OnBeginImplFrame(0, 10);
2479 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
2480 EXPECT_SEQUENCE_NUMBERS(10u, BeginFrameArgs::kInvalidFrameNumber,
2481 BeginFrameArgs::kInvalidFrameNumber,
2482 BeginFrameArgs::kInvalidFrameNumber,
2483 BeginFrameArgs::kInvalidFrameNumber);
2484
2485 // When no updates are required, OnBeginImplFrameDeadline() updates active
2486 // tree and compositor frame freshness.
2487 state.OnBeginImplFrameDeadline();
2488 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
2489 EXPECT_SEQUENCE_NUMBERS(10u, BeginFrameArgs::kInvalidFrameNumber,
2490 BeginFrameArgs::kInvalidFrameNumber, 10u, 10u);
2491 state.OnBeginImplFrameIdle();
2492 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
2493 }
2494
2495 TEST(SchedulerStateMachineTest, TestBeginFrameFreshnessWithImplFrameUpdates) {
2496 // Setup with an impl-thread draw requested.
2497 SchedulerSettings default_scheduler_settings;
2498 StateMachine state(default_scheduler_settings);
2499 SET_UP_STATE(state)
2500 state.SetNeedsRedraw(true);
2501 EXPECT_TRUE(state.RedrawPending());
2502 EXPECT_FALSE(state.NeedsCommit());
2503
2504 // OnBeginImplFrame() updates the sequence number.
2505 state.OnBeginImplFrame(0, 10);
2506 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
2507 EXPECT_SEQUENCE_NUMBERS(10u, BeginFrameArgs::kInvalidFrameNumber,
2508 BeginFrameArgs::kInvalidFrameNumber,
2509 BeginFrameArgs::kInvalidFrameNumber,
2510 BeginFrameArgs::kInvalidFrameNumber);
2511
2512 // With only an impl-thread draw requested, OnBeginImplFrameDeadline()
2513 // updates the active tree freshness.
2514 state.OnBeginImplFrameDeadline();
2515 EXPECT_SEQUENCE_NUMBERS(10u, BeginFrameArgs::kInvalidFrameNumber,
2516 BeginFrameArgs::kInvalidFrameNumber, 10u,
2517 BeginFrameArgs::kInvalidFrameNumber);
2518
2519 // Compositor frame freshness is updated when active tree is drawn.
2520 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE);
2521 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
2522 EXPECT_FALSE(state.RedrawPending());
2523 state.DidSubmitCompositorFrame();
2524 state.DidReceiveCompositorFrameAck();
2525 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
2526 EXPECT_SEQUENCE_NUMBERS(10u, BeginFrameArgs::kInvalidFrameNumber,
2527 BeginFrameArgs::kInvalidFrameNumber, 10u, 10u);
2528 state.OnBeginImplFrameIdle();
2529 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
2530 }
2531
2532 TEST(SchedulerStateMachineTest, TestBeginFrameFreshnessWithMainFrameUpdates) {
2533 // Setup with a BeginMainFrame requested.
2534 SchedulerSettings default_scheduler_settings;
2535 StateMachine state(default_scheduler_settings);
2536 SET_UP_STATE(state)
2537 state.SetNeedsRedraw(false);
2538 state.SetNeedsBeginMainFrameForTest(true);
2539 EXPECT_FALSE(state.RedrawPending());
2540 EXPECT_TRUE(state.NeedsCommit());
2541
2542 // OnBeginImplFrame() updates the sequence number, WillSendBeginMainFrame()
2543 // updates begin_main_frame_sent sequence number.
2544 state.OnBeginImplFrame(0, 10);
2545 EXPECT_ACTION_UPDATE_STATE(
2546 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
2547 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
2548 EXPECT_FALSE(state.NeedsCommit());
2549 EXPECT_TRUE(state.CommitPending());
2550 EXPECT_SEQUENCE_NUMBERS(10u, 10u, BeginFrameArgs::kInvalidFrameNumber,
2551 BeginFrameArgs::kInvalidFrameNumber,
2552 BeginFrameArgs::kInvalidFrameNumber);
2553
2554 // When a BeginMainFrame is needed, OnBeginImplFrameDeadline() updates no
2555 // freshness numbers.
2556 state.OnBeginImplFrameDeadline();
2557 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
2558 EXPECT_SEQUENCE_NUMBERS(10u, 10u, BeginFrameArgs::kInvalidFrameNumber,
2559 BeginFrameArgs::kInvalidFrameNumber,
2560 BeginFrameArgs::kInvalidFrameNumber);
2561 state.OnBeginImplFrameIdle();
2562 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
2563
2564 // When a main frame is in progress, OnBeginImplFrameDeadline() updates no
2565 // freshness numbers.
2566 state.NotifyBeginMainFrameStarted();
2567 state.OnBeginImplFrame(0, 11);
2568 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
2569 state.OnBeginImplFrameDeadline();
2570 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
2571 EXPECT_SEQUENCE_NUMBERS(11u, 10u, BeginFrameArgs::kInvalidFrameNumber,
2572 BeginFrameArgs::kInvalidFrameNumber,
2573 BeginFrameArgs::kInvalidFrameNumber);
2574 state.OnBeginImplFrameIdle();
2575 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
2576
2577 // Pending tree freshness is updated when the new pending tree is committed.
2578 state.NotifyReadyToCommit();
2579 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
2580 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
2581 EXPECT_FALSE(state.CommitPending());
2582 EXPECT_TRUE(state.has_pending_tree());
2583 EXPECT_SEQUENCE_NUMBERS(11u, 10u, 10u, BeginFrameArgs::kInvalidFrameNumber,
2584 BeginFrameArgs::kInvalidFrameNumber);
2585
2586 // If no further BeginMainFrame is needed, OnBeginFrameImplDeadline()
2587 // updates the pending tree's frame number.
2588 state.OnBeginImplFrame(0, 12);
2589 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
2590 EXPECT_SEQUENCE_NUMBERS(12u, 10u, 10u, BeginFrameArgs::kInvalidFrameNumber,
2591 BeginFrameArgs::kInvalidFrameNumber);
2592 state.OnBeginImplFrameDeadline();
2593 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
2594 EXPECT_SEQUENCE_NUMBERS(12u, 10u, 12u, BeginFrameArgs::kInvalidFrameNumber,
2595 BeginFrameArgs::kInvalidFrameNumber);
2596 state.OnBeginImplFrameIdle();
2597 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
2598
2599 // If a further BeginMainFrame is needed, OnBeginFrameImplDeadline()
2600 // updates no freshness numbers.
2601 state.SetNeedsBeginMainFrameForTest(true);
2602 EXPECT_TRUE(state.NeedsCommit());
2603 state.OnBeginImplFrame(0, 13);
2604 // BMF will be sent only after pending_tree activation.
2605 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
2606 state.OnBeginImplFrameDeadline();
2607 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
2608 EXPECT_SEQUENCE_NUMBERS(13u, 10u, 12u, BeginFrameArgs::kInvalidFrameNumber,
2609 BeginFrameArgs::kInvalidFrameNumber);
2610 state.OnBeginImplFrameIdle();
2611 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
2612
2613 // Active tree freshness is updated when pending frame is activated.
2614 state.NotifyReadyToActivate();
2615 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE);
2616 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
2617 EXPECT_FALSE(state.has_pending_tree());
2618 EXPECT_SEQUENCE_NUMBERS(13u, 10u, 12u, 12u,
2619 BeginFrameArgs::kInvalidFrameNumber);
2620 EXPECT_TRUE(state.RedrawPending());
2621
2622 // BMF requested above will be sent after activation.
2623 state.OnBeginImplFrame(0, 14);
2624 EXPECT_ACTION_UPDATE_STATE(
2625 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
2626 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
2627
2628 // Active tree freshness is updated when commit didn't have updates, but
2629 // compositor frame freshness is not updated.
2630 state.NotifyBeginMainFrameStarted();
2631 state.BeginMainFrameAborted(CommitEarlyOutReason::FINISHED_NO_UPDATES);
2632 EXPECT_SEQUENCE_NUMBERS(14u, 14u, 12u, 14u,
2633 BeginFrameArgs::kInvalidFrameNumber);
2634
2635 // Compositor frame freshness is updated when active tree is drawn.
2636 state.OnBeginImplFrameDeadline();
2637 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE);
2638 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
2639 EXPECT_FALSE(state.RedrawPending());
2640 state.DidSubmitCompositorFrame();
2641 state.DidReceiveCompositorFrameAck();
2642 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
2643 EXPECT_SEQUENCE_NUMBERS(14u, 14u, 12u, 14u, 14u);
2644 state.OnBeginImplFrameIdle();
2645 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
2646
2647 // When no updates are required, OnBeginImplFrameDeadline() updates active
2648 // tree and compositor frame freshness.
2649 state.OnBeginImplFrame(0, 15);
2650 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
2651 state.OnBeginImplFrameDeadline();
2652 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
2653 EXPECT_SEQUENCE_NUMBERS(15u, 14u, 12u, 15u, 15u);
2654 state.OnBeginImplFrameIdle();
2655 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
2656
2657 // Active tree and compositor frame freshness are updated when commit doesn't
2658 // have updates and compositor frame was fresh before.
2659 state.SetNeedsBeginMainFrameForTest(true);
2660 EXPECT_TRUE(state.NeedsCommit());
2661 state.OnBeginImplFrame(0, 16);
2662 EXPECT_ACTION_UPDATE_STATE(
2663 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
2664 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
2665 EXPECT_FALSE(state.NeedsCommit());
2666 EXPECT_TRUE(state.CommitPending());
2667 state.NotifyBeginMainFrameStarted();
2668 state.BeginMainFrameAborted(CommitEarlyOutReason::FINISHED_NO_UPDATES);
2669 EXPECT_SEQUENCE_NUMBERS(16u, 16u, 12u, 16u, 16u);
2670 state.OnBeginImplFrameDeadline();
2671 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
2672 EXPECT_SEQUENCE_NUMBERS(16u, 16u, 12u, 16u, 16u);
2673 state.OnBeginImplFrameIdle();
2674 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
2675
2676 // When the source changes, the current frame number is updated and frame
2677 // numbers for freshness are reset to invalid numbers.
2678 state.OnBeginImplFrame(1, 5);
2679 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
2680 EXPECT_SEQUENCE_NUMBERS(5u, BeginFrameArgs::kInvalidFrameNumber,
2681 BeginFrameArgs::kInvalidFrameNumber,
2682 BeginFrameArgs::kInvalidFrameNumber,
2683 BeginFrameArgs::kInvalidFrameNumber);
2684
2685 // When no updates are required, OnBeginImplFrameDeadline() updates active
2686 // tree and compositor frame freshness.
2687 state.OnBeginImplFrameDeadline();
2688 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
2689 EXPECT_SEQUENCE_NUMBERS(5u, BeginFrameArgs::kInvalidFrameNumber,
2690 BeginFrameArgs::kInvalidFrameNumber, 5u, 5u);
2691 state.OnBeginImplFrameIdle();
2692 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
2693 }
2694
2695 TEST(SchedulerStateMachineTest,
2696 TestBeginFrameFreshnessWithNoUpdatesCommitAndPendingTree) {
2697 // Setup with main_frame_before_activation_enabled, a pending tree, and a
2698 // new BeginMainFrame requested.
2699 SchedulerSettings settings;
2700 settings.main_frame_before_activation_enabled = true;
2701 StateMachine state(settings);
2702 SET_UP_STATE(state)
2703 state.SetHasPendingTree(true);
2704 state.SetNeedsRedraw(false);
2705 state.SetNeedsBeginMainFrameForTest(true);
2706 EXPECT_FALSE(state.RedrawPending());
2707 EXPECT_TRUE(state.NeedsCommit());
2708
2709 // OnBeginImplFrame() updates the sequence number, WillSendBeginMainFrame()
2710 // updates begin_main_frame_sent sequence number.
2711 state.OnBeginImplFrame(0, 10);
2712 EXPECT_ACTION_UPDATE_STATE(
2713 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
2714 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
2715 EXPECT_FALSE(state.NeedsCommit());
2716 EXPECT_TRUE(state.CommitPending());
2717 EXPECT_SEQUENCE_NUMBERS(10u, 10u, BeginFrameArgs::kInvalidFrameNumber,
2718 BeginFrameArgs::kInvalidFrameNumber,
2719 BeginFrameArgs::kInvalidFrameNumber);
2720
2721 // Pending tree freshness is updated when commit didn't have updates, but an
2722 // older pending tree is still pending.
2723 state.NotifyBeginMainFrameStarted();
2724 state.BeginMainFrameAborted(CommitEarlyOutReason::FINISHED_NO_UPDATES);
2725 EXPECT_SEQUENCE_NUMBERS(10u, 10u, 10u, BeginFrameArgs::kInvalidFrameNumber,
2726 BeginFrameArgs::kInvalidFrameNumber);
2727
2728 // As no further BeginMainFrame is needed, OnBeginFrameImplDeadline()
2729 // updates the pending tree's frame number, but without any visible change.
2730 state.OnBeginImplFrameDeadline();
2731 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
2732 EXPECT_SEQUENCE_NUMBERS(10u, 10u, 10u, BeginFrameArgs::kInvalidFrameNumber,
2733 BeginFrameArgs::kInvalidFrameNumber);
2734 state.OnBeginImplFrameIdle();
2735 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
2736 }
2737
2384 } // namespace 2738 } // namespace
2385 } // namespace cc 2739 } // namespace cc
OLDNEW
« no previous file with comments | « cc/scheduler/scheduler_state_machine.cc ('k') | cc/scheduler/scheduler_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698