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

Side by Side Diff: cc/scheduler_state_machine_unittest.cc

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

Powered by Google App Engine
This is Rietveld 408576698