OLD | NEW |
1 // Copyright 2011 The Chromium Authors. All rights reserved. | 1 // Copyright 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "config.h" | 5 #include "config.h" |
6 | 6 |
7 #include "cc/scheduler_state_machine.h" | 7 #include "cc/scheduler_state_machine.h" |
8 | 8 |
9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 | 10 |
11 using namespace cc; | 11 using namespace cc; |
12 | 12 |
13 namespace { | 13 namespace { |
14 | 14 |
15 const SchedulerStateMachine::CommitState allCommitStates[] = { | 15 const SchedulerStateMachine::CommitState allCommitStates[] = { |
16 SchedulerStateMachine::COMMIT_STATE_IDLE, | 16 SchedulerStateMachine::COMMIT_STATE_IDLE, |
17 SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, | 17 SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, |
18 SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT, | 18 SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT, |
19 SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW | 19 SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW |
20 }; | 20 }; |
21 | 21 |
22 // Exposes the protected state fields of the SchedulerStateMachine for testing | 22 // Exposes the protected state fields of the SchedulerStateMachine for testing |
23 class StateMachine : public SchedulerStateMachine { | 23 class StateMachine : public SchedulerStateMachine { |
24 public: | 24 public: |
25 void setCommitState(CommitState cs) { m_commitState = cs; } | 25 void setCommitState(CommitState cs) { m_commitState = cs; } |
26 CommitState commitState() const { return m_commitState; } | 26 CommitState commitState() const { return m_commitState; } |
27 | 27 |
28 void setNeedsCommit(bool b) { m_needsCommit = b; } | |
29 bool needsCommit() const { return m_needsCommit; } | 28 bool needsCommit() const { return m_needsCommit; } |
30 | 29 |
31 void setNeedsForcedCommit(bool b) { m_needsForcedCommit = b; } | |
32 bool needsForcedCommit() const { return m_needsForcedCommit; } | |
33 | |
34 void setNeedsRedraw(bool b) { m_needsRedraw = b; } | 30 void setNeedsRedraw(bool b) { m_needsRedraw = b; } |
35 bool needsRedraw() const { return m_needsRedraw; } | 31 bool needsRedraw() const { return m_needsRedraw; } |
36 | 32 |
37 void setNeedsForcedRedraw(bool b) { m_needsForcedRedraw = b; } | 33 void setNeedsForcedRedraw(bool b) { m_needsForcedRedraw = b; } |
38 bool needsForcedRedraw() const { return m_needsForcedRedraw; } | 34 bool needsForcedRedraw() const { return m_needsForcedRedraw; } |
39 | 35 |
40 bool canDraw() const { return m_canDraw; } | 36 bool canDraw() const { return m_canDraw; } |
41 bool insideVSync() const { return m_insideVSync; } | 37 bool insideVSync() const { return m_insideVSync; } |
42 bool visible() const { return m_visible; } | 38 bool visible() const { return m_visible; } |
43 }; | 39 }; |
44 | 40 |
45 TEST(SchedulerStateMachineTest, TestNextActionBeginsFrameIfNeeded) | 41 TEST(SchedulerStateMachineTest, TestNextActionBeginsFrameIfNeeded) |
46 { | 42 { |
47 // If no commit needed, do nothing | 43 // If no commit needed, do nothing |
48 { | 44 { |
49 StateMachine state; | 45 StateMachine state; |
50 state.setCommitState(SchedulerStateMachine::COMMIT_STATE_IDLE); | 46 state.setCommitState(SchedulerStateMachine::COMMIT_STATE_IDLE); |
51 state.setCanBeginFrame(true); | 47 state.setCanBeginFrame(true); |
52 state.setNeedsRedraw(false); | 48 state.setNeedsRedraw(false); |
53 state.setNeedsCommit(false); | |
54 state.setVisible(true); | 49 state.setVisible(true); |
55 | 50 |
56 EXPECT_FALSE(state.vsyncCallbackNeeded()); | 51 EXPECT_FALSE(state.vsyncCallbackNeeded()); |
57 | 52 |
58 state.didLeaveVSync(); | 53 state.didLeaveVSync(); |
59 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.nextAction()); | 54 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.nextAction()); |
60 EXPECT_FALSE(state.vsyncCallbackNeeded()); | 55 EXPECT_FALSE(state.vsyncCallbackNeeded()); |
61 state.didEnterVSync(); | 56 state.didEnterVSync(); |
62 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.nextAction()); | 57 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.nextAction()); |
63 } | 58 } |
64 | 59 |
65 // If commit requested but canBeginFrame is still false, do nothing. | 60 // If commit requested but canBeginFrame is still false, do nothing. |
66 { | 61 { |
67 StateMachine state; | 62 StateMachine state; |
68 state.setCommitState(SchedulerStateMachine::COMMIT_STATE_IDLE); | 63 state.setCommitState(SchedulerStateMachine::COMMIT_STATE_IDLE); |
69 state.setNeedsRedraw(false); | 64 state.setNeedsRedraw(false); |
70 state.setNeedsCommit(false); | |
71 state.setVisible(true); | 65 state.setVisible(true); |
72 | 66 |
73 EXPECT_FALSE(state.vsyncCallbackNeeded()); | 67 EXPECT_FALSE(state.vsyncCallbackNeeded()); |
74 | 68 |
75 state.didLeaveVSync(); | 69 state.didLeaveVSync(); |
76 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.nextAction()); | 70 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.nextAction()); |
77 EXPECT_FALSE(state.vsyncCallbackNeeded()); | 71 EXPECT_FALSE(state.vsyncCallbackNeeded()); |
78 state.didEnterVSync(); | 72 state.didEnterVSync(); |
79 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.nextAction()); | 73 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.nextAction()); |
80 } | 74 } |
81 | 75 |
82 | 76 |
83 // If commit requested, begin a frame | 77 // If commit requested, begin a frame |
84 { | 78 { |
85 StateMachine state; | 79 StateMachine state; |
86 state.setCommitState(SchedulerStateMachine::COMMIT_STATE_IDLE); | 80 state.setCommitState(SchedulerStateMachine::COMMIT_STATE_IDLE); |
87 state.setCanBeginFrame(true); | 81 state.setCanBeginFrame(true); |
88 state.setNeedsRedraw(false); | 82 state.setNeedsRedraw(false); |
89 state.setNeedsCommit(true); | |
90 state.setVisible(true); | 83 state.setVisible(true); |
91 EXPECT_FALSE(state.vsyncCallbackNeeded()); | 84 EXPECT_FALSE(state.vsyncCallbackNeeded()); |
92 } | 85 } |
93 | 86 |
94 // Begin the frame, make sure needsCommit and commitState update correctly. | 87 // Begin the frame, make sure needsCommit and commitState update correctly. |
95 { | 88 { |
96 StateMachine state; | 89 StateMachine state; |
97 state.setCanBeginFrame(true); | 90 state.setCanBeginFrame(true); |
98 state.setVisible(true); | 91 state.setVisible(true); |
99 state.updateState(SchedulerStateMachine::ACTION_BEGIN_FRAME); | 92 state.updateState(SchedulerStateMachine::ACTION_BEGIN_FRAME); |
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
362 StateMachine state; | 355 StateMachine state; |
363 state.setCommitState(allCommitStates[i]); | 356 state.setCommitState(allCommitStates[i]); |
364 bool visible = j; | 357 bool visible = j; |
365 if (!visible) { | 358 if (!visible) { |
366 state.didEnterVSync(); | 359 state.didEnterVSync(); |
367 state.setVisible(false); | 360 state.setVisible(false); |
368 } else | 361 } else |
369 state.setVisible(true); | 362 state.setVisible(true); |
370 | 363 |
371 // Case 1: needsCommit=false | 364 // Case 1: needsCommit=false |
372 state.setNeedsCommit(false); | |
373 EXPECT_NE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.next
Action()); | 365 EXPECT_NE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.next
Action()); |
374 | 366 |
375 // Case 2: needsCommit=true | 367 // Case 2: needsCommit=true |
376 state.setNeedsCommit(true); | 368 state.setNeedsCommit(); |
377 EXPECT_NE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.next
Action()); | 369 EXPECT_NE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.next
Action()); |
378 } | 370 } |
379 } | 371 } |
380 | 372 |
381 // When on vsync, or not on vsync but needsForcedRedraw set, should always d
raw except if you're ready to commit, in which case commit. | 373 // When on vsync, or not on vsync but needsForcedRedraw set, should always d
raw except if you're ready to commit, in which case commit. |
382 for (size_t i = 0; i < numCommitStates; ++i) { | 374 for (size_t i = 0; i < numCommitStates; ++i) { |
383 for (unsigned j = 0; j < 2; ++j) { | 375 for (unsigned j = 0; j < 2; ++j) { |
384 StateMachine state; | 376 StateMachine state; |
385 state.setCanDraw(true); | 377 state.setCanDraw(true); |
386 state.setCommitState(allCommitStates[i]); | 378 state.setCommitState(allCommitStates[i]); |
387 bool forcedDraw = j; | 379 bool forcedDraw = j; |
388 if (!forcedDraw) { | 380 if (!forcedDraw) { |
389 state.didEnterVSync(); | 381 state.didEnterVSync(); |
390 state.setNeedsRedraw(true); | 382 state.setNeedsRedraw(true); |
391 state.setVisible(true); | 383 state.setVisible(true); |
392 } else | 384 } else |
393 state.setNeedsForcedRedraw(true); | 385 state.setNeedsForcedRedraw(true); |
394 | 386 |
395 SchedulerStateMachine::Action expectedAction; | 387 SchedulerStateMachine::Action expectedAction; |
396 if (allCommitStates[i] != SchedulerStateMachine::COMMIT_STATE_READY_
TO_COMMIT) | 388 if (allCommitStates[i] != SchedulerStateMachine::COMMIT_STATE_READY_
TO_COMMIT) |
397 expectedAction = forcedDraw ? SchedulerStateMachine::ACTION_DRAW
_FORCED : SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE; | 389 expectedAction = forcedDraw ? SchedulerStateMachine::ACTION_DRAW
_FORCED : SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE; |
398 else | 390 else |
399 expectedAction = SchedulerStateMachine::ACTION_COMMIT; | 391 expectedAction = SchedulerStateMachine::ACTION_COMMIT; |
400 | 392 |
401 // Case 1: needsCommit=false. | 393 // Case 1: needsCommit=false. |
402 state.setNeedsCommit(false); | |
403 EXPECT_TRUE(state.vsyncCallbackNeeded()); | 394 EXPECT_TRUE(state.vsyncCallbackNeeded()); |
404 EXPECT_EQ(expectedAction, state.nextAction()); | 395 EXPECT_EQ(expectedAction, state.nextAction()); |
405 | 396 |
406 // Case 2: needsCommit=true. | 397 // Case 2: needsCommit=true. |
407 state.setNeedsCommit(true); | 398 state.setNeedsCommit(); |
408 EXPECT_TRUE(state.vsyncCallbackNeeded()); | 399 EXPECT_TRUE(state.vsyncCallbackNeeded()); |
409 EXPECT_EQ(expectedAction, state.nextAction()); | 400 EXPECT_EQ(expectedAction, state.nextAction()); |
410 } | 401 } |
411 } | 402 } |
412 } | 403 } |
413 | 404 |
414 TEST(SchedulerStateMachineTest, TestNoCommitStatesRedrawWhenInvisible) | 405 TEST(SchedulerStateMachineTest, TestNoCommitStatesRedrawWhenInvisible) |
415 { | 406 { |
416 size_t numCommitStates = sizeof(allCommitStates) / sizeof(SchedulerStateMach
ine::CommitState); | 407 size_t numCommitStates = sizeof(allCommitStates) / sizeof(SchedulerStateMach
ine::CommitState); |
417 for (size_t i = 0; i < numCommitStates; ++i) { | 408 for (size_t i = 0; i < numCommitStates; ++i) { |
418 // There shouldn't be any drawing regardless of vsync. | 409 // There shouldn't be any drawing regardless of vsync. |
419 for (unsigned j = 0; j < 2; ++j) { | 410 for (unsigned j = 0; j < 2; ++j) { |
420 StateMachine state; | 411 StateMachine state; |
421 state.setCommitState(allCommitStates[i]); | 412 state.setCommitState(allCommitStates[i]); |
422 state.setVisible(false); | 413 state.setVisible(false); |
423 state.setNeedsRedraw(true); | 414 state.setNeedsRedraw(true); |
424 state.setNeedsForcedRedraw(false); | 415 state.setNeedsForcedRedraw(false); |
425 if (j == 1) | 416 if (j == 1) |
426 state.didEnterVSync(); | 417 state.didEnterVSync(); |
427 | 418 |
428 // Case 1: needsCommit=false. | 419 // Case 1: needsCommit=false. |
429 state.setNeedsCommit(false); | |
430 EXPECT_NE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.next
Action()); | 420 EXPECT_NE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.next
Action()); |
431 | 421 |
432 // Case 2: needsCommit=true. | 422 // Case 2: needsCommit=true. |
433 state.setNeedsCommit(true); | 423 state.setNeedsCommit(); |
434 EXPECT_NE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.next
Action()); | 424 EXPECT_NE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.next
Action()); |
435 } | 425 } |
436 } | 426 } |
437 } | 427 } |
438 | 428 |
439 TEST(SchedulerStateMachineTest, TestCanRedraw_StopsDraw) | 429 TEST(SchedulerStateMachineTest, TestCanRedraw_StopsDraw) |
440 { | 430 { |
441 size_t numCommitStates = sizeof(allCommitStates) / sizeof(SchedulerStateMach
ine::CommitState); | 431 size_t numCommitStates = sizeof(allCommitStates) / sizeof(SchedulerStateMach
ine::CommitState); |
442 for (size_t i = 0; i < numCommitStates; ++i) { | 432 for (size_t i = 0; i < numCommitStates; ++i) { |
443 // There shouldn't be any drawing regardless of vsync. | 433 // There shouldn't be any drawing regardless of vsync. |
(...skipping 10 matching lines...) Expand all Loading... |
454 EXPECT_NE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.next
Action()); | 444 EXPECT_NE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.next
Action()); |
455 } | 445 } |
456 } | 446 } |
457 } | 447 } |
458 | 448 |
459 TEST(SchedulerStateMachineTest, TestCanRedrawWithWaitingForFirstDrawMakesProgres
s) | 449 TEST(SchedulerStateMachineTest, TestCanRedrawWithWaitingForFirstDrawMakesProgres
s) |
460 { | 450 { |
461 StateMachine state; | 451 StateMachine state; |
462 state.setCommitState(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_D
RAW); | 452 state.setCommitState(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_D
RAW); |
463 state.setCanBeginFrame(true); | 453 state.setCanBeginFrame(true); |
464 state.setNeedsCommit(true); | 454 state.setNeedsCommit(); |
465 state.setNeedsRedraw(true); | 455 state.setNeedsRedraw(true); |
466 state.setVisible(true); | 456 state.setVisible(true); |
467 state.setCanDraw(false); | 457 state.setCanDraw(false); |
468 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction()); | 458 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction()); |
469 } | 459 } |
470 | 460 |
471 TEST(SchedulerStateMachineTest, TestSetNeedsCommitIsNotLost) | 461 TEST(SchedulerStateMachineTest, TestSetNeedsCommitIsNotLost) |
472 { | 462 { |
473 StateMachine state; | 463 StateMachine state; |
474 state.setCanBeginFrame(true); | 464 state.setCanBeginFrame(true); |
475 state.setNeedsCommit(true); | 465 state.setNeedsCommit(); |
476 state.setVisible(true); | 466 state.setVisible(true); |
477 state.setCanDraw(true); | 467 state.setCanDraw(true); |
478 | 468 |
479 // Begin the frame. | 469 // Begin the frame. |
480 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction()); | 470 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction()); |
481 state.updateState(state.nextAction()); | 471 state.updateState(state.nextAction()); |
482 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, state.commi
tState()); | 472 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, state.commi
tState()); |
483 | 473 |
484 // Now, while the frame is in progress, set another commit. | 474 // Now, while the frame is in progress, set another commit. |
485 state.setNeedsCommit(true); | 475 state.setNeedsCommit(); |
486 EXPECT_TRUE(state.needsCommit()); | 476 EXPECT_TRUE(state.needsCommit()); |
487 | 477 |
488 // Let the frame finish. | 478 // Let the frame finish. |
489 state.beginFrameComplete(); | 479 state.beginFrameComplete(); |
490 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT, state.commitS
tate()); | 480 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT, state.commitS
tate()); |
491 | 481 |
492 // Expect to commit regardless of vsync state. | 482 // Expect to commit regardless of vsync state. |
493 state.didLeaveVSync(); | 483 state.didLeaveVSync(); |
494 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.nextAction()); | 484 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.nextAction()); |
495 state.didEnterVSync(); | 485 state.didEnterVSync(); |
(...skipping 12 matching lines...) Expand all Loading... |
508 } | 498 } |
509 | 499 |
510 TEST(SchedulerStateMachineTest, TestFullCycle) | 500 TEST(SchedulerStateMachineTest, TestFullCycle) |
511 { | 501 { |
512 StateMachine state; | 502 StateMachine state; |
513 state.setCanBeginFrame(true); | 503 state.setCanBeginFrame(true); |
514 state.setVisible(true); | 504 state.setVisible(true); |
515 state.setCanDraw(true); | 505 state.setCanDraw(true); |
516 | 506 |
517 // Start clean and set commit. | 507 // Start clean and set commit. |
518 state.setNeedsCommit(true); | 508 state.setNeedsCommit(); |
519 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction()); | 509 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction()); |
520 | 510 |
521 // Begin the frame. | 511 // Begin the frame. |
522 state.updateState(SchedulerStateMachine::ACTION_BEGIN_FRAME); | 512 state.updateState(SchedulerStateMachine::ACTION_BEGIN_FRAME); |
523 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, state.commi
tState()); | 513 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, state.commi
tState()); |
524 EXPECT_FALSE(state.needsCommit()); | 514 EXPECT_FALSE(state.needsCommit()); |
525 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.nextAction()); | 515 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.nextAction()); |
526 | 516 |
527 // Tell the scheduler the frame finished. | 517 // Tell the scheduler the frame finished. |
528 state.beginFrameComplete(); | 518 state.beginFrameComplete(); |
(...skipping 22 matching lines...) Expand all Loading... |
551 } | 541 } |
552 | 542 |
553 TEST(SchedulerStateMachineTest, TestFullCycleWithCommitRequestInbetween) | 543 TEST(SchedulerStateMachineTest, TestFullCycleWithCommitRequestInbetween) |
554 { | 544 { |
555 StateMachine state; | 545 StateMachine state; |
556 state.setCanBeginFrame(true); | 546 state.setCanBeginFrame(true); |
557 state.setVisible(true); | 547 state.setVisible(true); |
558 state.setCanDraw(true); | 548 state.setCanDraw(true); |
559 | 549 |
560 // Start clean and set commit. | 550 // Start clean and set commit. |
561 state.setNeedsCommit(true); | 551 state.setNeedsCommit(); |
562 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction()); | 552 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction()); |
563 | 553 |
564 // Begin the frame. | 554 // Begin the frame. |
565 state.updateState(SchedulerStateMachine::ACTION_BEGIN_FRAME); | 555 state.updateState(SchedulerStateMachine::ACTION_BEGIN_FRAME); |
566 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, state.commi
tState()); | 556 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, state.commi
tState()); |
567 EXPECT_FALSE(state.needsCommit()); | 557 EXPECT_FALSE(state.needsCommit()); |
568 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.nextAction()); | 558 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.nextAction()); |
569 | 559 |
570 // Request another commit while the commit is in flight. | 560 // Request another commit while the commit is in flight. |
571 state.setNeedsCommit(true); | 561 state.setNeedsCommit(); |
572 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.nextAction()); | 562 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.nextAction()); |
573 | 563 |
574 // Tell the scheduler the frame finished. | 564 // Tell the scheduler the frame finished. |
575 state.beginFrameComplete(); | 565 state.beginFrameComplete(); |
576 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT, state.commitS
tate()); | 566 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT, state.commitS
tate()); |
577 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.nextAction()); | 567 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.nextAction()); |
578 | 568 |
579 // Commit. | 569 // Commit. |
580 state.updateState(SchedulerStateMachine::ACTION_COMMIT); | 570 state.updateState(SchedulerStateMachine::ACTION_COMMIT); |
581 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW, state.
commitState()); | 571 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW, state.
commitState()); |
(...skipping 11 matching lines...) Expand all Loading... |
593 | 583 |
594 // Should be synchronized, no draw needed, no action needed. | 584 // Should be synchronized, no draw needed, no action needed. |
595 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.commitState()); | 585 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.commitState()); |
596 EXPECT_FALSE(state.needsRedraw()); | 586 EXPECT_FALSE(state.needsRedraw()); |
597 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction()); | 587 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction()); |
598 } | 588 } |
599 | 589 |
600 TEST(SchedulerStateMachineTest, TestRequestCommitInvisible) | 590 TEST(SchedulerStateMachineTest, TestRequestCommitInvisible) |
601 { | 591 { |
602 StateMachine state; | 592 StateMachine state; |
603 state.setNeedsCommit(true); | 593 state.setNeedsCommit(); |
604 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.nextAction()); | 594 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.nextAction()); |
605 } | 595 } |
606 | 596 |
607 TEST(SchedulerStateMachineTest, TestGoesInvisibleBeforeBeginFrameCompletes) | 597 TEST(SchedulerStateMachineTest, TestGoesInvisibleBeforeBeginFrameCompletes) |
608 { | 598 { |
609 StateMachine state; | 599 StateMachine state; |
610 state.setCanBeginFrame(true); | 600 state.setCanBeginFrame(true); |
611 state.setVisible(true); | 601 state.setVisible(true); |
612 state.setCanDraw(true); | 602 state.setCanDraw(true); |
613 | 603 |
614 // Start clean and set commit. | 604 // Start clean and set commit. |
615 state.setNeedsCommit(true); | 605 state.setNeedsCommit(); |
616 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction()); | 606 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction()); |
617 | 607 |
618 // Begin the frame while visible. | 608 // Begin the frame while visible. |
619 state.updateState(SchedulerStateMachine::ACTION_BEGIN_FRAME); | 609 state.updateState(SchedulerStateMachine::ACTION_BEGIN_FRAME); |
620 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, state.commi
tState()); | 610 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, state.commi
tState()); |
621 EXPECT_FALSE(state.needsCommit()); | 611 EXPECT_FALSE(state.needsCommit()); |
622 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.nextAction()); | 612 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.nextAction()); |
623 | 613 |
624 // Become invisible and abort the beginFrame. | 614 // Become invisible and abort the beginFrame. |
625 state.setVisible(false); | 615 state.setVisible(false); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
675 | 665 |
676 state.didLoseContext(); | 666 state.didLoseContext(); |
677 | 667 |
678 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_CONTEXT_RECREATION, state.next
Action()); | 668 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_CONTEXT_RECREATION, state.next
Action()); |
679 state.updateState(state.nextAction()); | 669 state.updateState(state.nextAction()); |
680 | 670 |
681 // Once context recreation begins, nothing should happen. | 671 // Once context recreation begins, nothing should happen. |
682 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.nextAction()); | 672 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.nextAction()); |
683 | 673 |
684 // While context is recreating, commits shouldn't begin. | 674 // While context is recreating, commits shouldn't begin. |
685 state.setNeedsCommit(true); | 675 state.setNeedsCommit(); |
686 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.nextAction()); | 676 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.nextAction()); |
687 | 677 |
688 // Recreate the context | 678 // Recreate the context |
689 state.didRecreateContext(); | 679 state.didRecreateContext(); |
690 | 680 |
691 // When the context is recreated, we should begin a commit | 681 // When the context is recreated, we should begin a commit |
692 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction()); | 682 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction()); |
693 state.updateState(state.nextAction()); | 683 state.updateState(state.nextAction()); |
694 | 684 |
695 // Once the context is recreated, whether we draw should be based on | 685 // Once the context is recreated, whether we draw should be based on |
696 // setCanDraw. | 686 // setCanDraw. |
697 state.setNeedsRedraw(true); | 687 state.setNeedsRedraw(true); |
698 state.didEnterVSync(); | 688 state.didEnterVSync(); |
699 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.nextAction()
); | 689 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.nextAction()
); |
700 state.setCanDraw(false); | 690 state.setCanDraw(false); |
701 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.nextAction()); | 691 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.nextAction()); |
702 state.setCanDraw(true); | 692 state.setCanDraw(true); |
703 state.didLeaveVSync(); | 693 state.didLeaveVSync(); |
704 } | 694 } |
705 | 695 |
706 TEST(SchedulerStateMachineTest, TestContextLostWhileCommitInProgress) | 696 TEST(SchedulerStateMachineTest, TestContextLostWhileCommitInProgress) |
707 { | 697 { |
708 StateMachine state; | 698 StateMachine state; |
709 state.setCanBeginFrame(true); | 699 state.setCanBeginFrame(true); |
710 state.setVisible(true); | 700 state.setVisible(true); |
711 state.setCanDraw(true); | 701 state.setCanDraw(true); |
712 | 702 |
713 // Get a commit in flight. | 703 // Get a commit in flight. |
714 state.setNeedsCommit(true); | 704 state.setNeedsCommit(); |
715 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction()); | 705 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction()); |
716 state.updateState(state.nextAction()); | 706 state.updateState(state.nextAction()); |
717 | 707 |
718 // Set damage and expect a draw. | 708 // Set damage and expect a draw. |
719 state.setNeedsRedraw(true); | 709 state.setNeedsRedraw(true); |
720 state.didEnterVSync(); | 710 state.didEnterVSync(); |
721 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.nextAction()
); | 711 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.nextAction()
); |
722 state.updateState(state.nextAction()); | 712 state.updateState(state.nextAction()); |
723 state.didLeaveVSync(); | 713 state.didLeaveVSync(); |
724 | 714 |
(...skipping 22 matching lines...) Expand all Loading... |
747 } | 737 } |
748 | 738 |
749 TEST(SchedulerStateMachineTest, TestContextLostWhileCommitInProgressAndAnotherCo
mmitRequested) | 739 TEST(SchedulerStateMachineTest, TestContextLostWhileCommitInProgressAndAnotherCo
mmitRequested) |
750 { | 740 { |
751 StateMachine state; | 741 StateMachine state; |
752 state.setCanBeginFrame(true); | 742 state.setCanBeginFrame(true); |
753 state.setVisible(true); | 743 state.setVisible(true); |
754 state.setCanDraw(true); | 744 state.setCanDraw(true); |
755 | 745 |
756 // Get a commit in flight. | 746 // Get a commit in flight. |
757 state.setNeedsCommit(true); | 747 state.setNeedsCommit(); |
758 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction()); | 748 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction()); |
759 state.updateState(state.nextAction()); | 749 state.updateState(state.nextAction()); |
760 | 750 |
761 // Set damage and expect a draw. | 751 // Set damage and expect a draw. |
762 state.setNeedsRedraw(true); | 752 state.setNeedsRedraw(true); |
763 state.didEnterVSync(); | 753 state.didEnterVSync(); |
764 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.nextAction()
); | 754 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.nextAction()
); |
765 state.updateState(state.nextAction()); | 755 state.updateState(state.nextAction()); |
766 state.didLeaveVSync(); | 756 state.didLeaveVSync(); |
767 | 757 |
768 // Cause a lost context while the begin frame is in flight. | 758 // Cause a lost context while the begin frame is in flight. |
769 state.didLoseContext(); | 759 state.didLoseContext(); |
770 | 760 |
771 // Ask for another draw and also set needs commit. Expect nothing happens. | 761 // Ask for another draw and also set needs commit. Expect nothing happens. |
772 state.setNeedsRedraw(true); | 762 state.setNeedsRedraw(true); |
773 state.setNeedsCommit(true); | 763 state.setNeedsCommit(); |
774 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.nextAction()); | 764 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.nextAction()); |
775 | 765 |
776 // Finish the frame, and commit. | 766 // Finish the frame, and commit. |
777 state.beginFrameComplete(); | 767 state.beginFrameComplete(); |
778 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.nextAction()); | 768 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.nextAction()); |
779 state.updateState(state.nextAction()); | 769 state.updateState(state.nextAction()); |
780 | 770 |
781 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW, state.
commitState()); | 771 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW, state.
commitState()); |
782 | 772 |
783 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.nextAction()
); | 773 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.nextAction()
); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
818 state.didEnterVSync(); | 808 state.didEnterVSync(); |
819 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_FORCED, state.nextAction()); | 809 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_FORCED, state.nextAction()); |
820 state.didLeaveVSync(); | 810 state.didLeaveVSync(); |
821 } | 811 } |
822 | 812 |
823 TEST(SchedulerStateMachineTest, TestBeginFrameWhenInvisibleAndForceCommit) | 813 TEST(SchedulerStateMachineTest, TestBeginFrameWhenInvisibleAndForceCommit) |
824 { | 814 { |
825 StateMachine state; | 815 StateMachine state; |
826 state.setCanBeginFrame(true); | 816 state.setCanBeginFrame(true); |
827 state.setVisible(false); | 817 state.setVisible(false); |
828 state.setNeedsCommit(true); | 818 state.setNeedsCommit(); |
829 state.setNeedsForcedCommit(true); | 819 state.setNeedsForcedCommit(); |
830 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction()); | 820 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction()); |
831 } | 821 } |
832 | 822 |
833 TEST(SchedulerStateMachineTest, TestBeginFrameWhenCanBeginFrameFalseAndForceComm
it) | 823 TEST(SchedulerStateMachineTest, TestBeginFrameWhenCanBeginFrameFalseAndForceComm
it) |
834 { | 824 { |
835 StateMachine state; | 825 StateMachine state; |
836 state.setVisible(true); | 826 state.setVisible(true); |
837 state.setCanDraw(true); | 827 state.setCanDraw(true); |
838 state.setNeedsCommit(true); | 828 state.setNeedsCommit(); |
839 state.setNeedsForcedCommit(true); | 829 state.setNeedsForcedCommit(); |
840 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction()); | 830 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction()); |
841 } | 831 } |
842 | 832 |
843 TEST(SchedulerStateMachineTest, TestBeginFrameWhenCommitInProgress) | 833 TEST(SchedulerStateMachineTest, TestBeginFrameWhenCommitInProgress) |
844 { | 834 { |
845 StateMachine state; | 835 StateMachine state; |
846 state.setCanBeginFrame(true); | 836 state.setCanBeginFrame(true); |
847 state.setVisible(false); | 837 state.setVisible(false); |
848 state.setCommitState(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS); | 838 state.setCommitState(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS); |
849 state.setNeedsCommit(true); | 839 state.setNeedsCommit(); |
850 state.setNeedsForcedCommit(true); | 840 state.setNeedsForcedCommit(); |
851 | 841 |
852 state.beginFrameComplete(); | 842 state.beginFrameComplete(); |
853 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.nextAction()); | 843 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.nextAction()); |
854 state.updateState(state.nextAction()); | 844 state.updateState(state.nextAction()); |
855 | 845 |
856 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW, state.
commitState()); | 846 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW, state.
commitState()); |
857 | 847 |
858 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction()); | 848 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction()); |
859 } | 849 } |
860 | 850 |
861 TEST(SchedulerStateMachineTest, TestBeginFrameWhenContextLost) | 851 TEST(SchedulerStateMachineTest, TestBeginFrameWhenContextLost) |
862 { | 852 { |
863 StateMachine state; | 853 StateMachine state; |
864 state.setCanBeginFrame(true); | 854 state.setCanBeginFrame(true); |
865 state.setVisible(true); | 855 state.setVisible(true); |
866 state.setCanDraw(true); | 856 state.setCanDraw(true); |
867 state.setNeedsCommit(true); | 857 state.setNeedsCommit(); |
868 state.setNeedsForcedCommit(true); | 858 state.setNeedsForcedCommit(); |
869 state.didLoseContext(); | 859 state.didLoseContext(); |
870 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction()); | 860 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction()); |
871 } | 861 } |
872 | 862 |
| 863 TEST(SchedulerStateMachineTest, TestImmediateBeginFrame) |
| 864 { |
| 865 StateMachine state; |
| 866 state.setCanBeginFrame(true); |
| 867 state.setVisible(true); |
| 868 state.setCanDraw(true); |
| 869 |
| 870 // Schedule a forced frame, commit it, draw it. |
| 871 state.setNeedsCommit(); |
| 872 state.setNeedsForcedCommit(); |
| 873 state.updateState(state.nextAction()); |
| 874 state.beginFrameComplete(); |
| 875 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.nextAction()); |
| 876 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT, state.commitS
tate()); |
| 877 state.updateState(state.nextAction()); |
| 878 |
| 879 state.didEnterVSync(); |
| 880 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.nextAction()
); |
| 881 state.updateState(state.nextAction()); |
| 882 state.didDrawIfPossibleCompleted(true); |
| 883 state.didLeaveVSync(); |
| 884 |
| 885 // Should be waiting for the normal begin frame |
| 886 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, state.commit
State()); |
873 } | 887 } |
| 888 |
| 889 TEST(SchedulerStateMachineTest, TestImmediateBeginFrameDuringCommit) |
| 890 { |
| 891 StateMachine state; |
| 892 state.setCanBeginFrame(true); |
| 893 state.setVisible(true); |
| 894 state.setCanDraw(true); |
| 895 |
| 896 // Start a normal commit. |
| 897 state.setNeedsCommit(); |
| 898 state.updateState(state.nextAction()); |
| 899 |
| 900 // Schedule a forced frame, commit it, draw it. |
| 901 state.setNeedsCommit(); |
| 902 state.setNeedsForcedCommit(); |
| 903 state.updateState(state.nextAction()); |
| 904 state.beginFrameComplete(); |
| 905 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.nextAction()); |
| 906 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT, state.commitSt
ate()); |
| 907 state.updateState(state.nextAction()); |
| 908 |
| 909 state.didEnterVSync(); |
| 910 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.nextAction())
; |
| 911 state.updateState(state.nextAction()); |
| 912 state.didDrawIfPossibleCompleted(true); |
| 913 state.didLeaveVSync(); |
| 914 |
| 915 // Should be waiting for the normal begin frame |
| 916 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, state.commit
State()) << state.toString(); |
| 917 } |
| 918 |
| 919 TEST(SchedulerStateMachineTest, ImmediateBeginFrameWhileInvisible) |
| 920 { |
| 921 StateMachine state; |
| 922 state.setCanBeginFrame(true); |
| 923 state.setVisible(true); |
| 924 state.setCanDraw(true); |
| 925 |
| 926 state.setNeedsCommit(); |
| 927 state.updateState(state.nextAction()); |
| 928 |
| 929 state.setNeedsCommit(); |
| 930 state.setNeedsForcedCommit(); |
| 931 state.updateState(state.nextAction()); |
| 932 state.beginFrameComplete(); |
| 933 |
| 934 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.nextAction()); |
| 935 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT, state.commitSt
ate()); |
| 936 state.updateState(state.nextAction()); |
| 937 |
| 938 state.didEnterVSync(); |
| 939 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.nextAction())
; |
| 940 state.updateState(state.nextAction()); |
| 941 state.didDrawIfPossibleCompleted(true); |
| 942 state.didLeaveVSync(); |
| 943 |
| 944 // Should be waiting for the normal begin frame |
| 945 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, state.commit
State()) << state.toString(); |
| 946 |
| 947 |
| 948 // Become invisible and abort the "normal" begin frame. |
| 949 state.setVisible(false); |
| 950 state.beginFrameAborted(); |
| 951 |
| 952 // Should be back in the idle state, but needing a commit. |
| 953 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.commitState()); |
| 954 EXPECT_TRUE(state.needsCommit()); |
| 955 } |
| 956 |
| 957 } // namespace |
OLD | NEW |