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

Side by Side Diff: cc/scheduler_state_machine_unittest.cc

Issue 11348083: Revert 168095 - Merge 167537 - Use message passing for BeginFrameAndCommitState and clean up forced… (Closed) Base URL: svn://svn.chromium.org/chrome/branches/1312/src/
Patch Set: 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 "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; }
28 bool needsCommit() const { return m_needsCommit; } 29 bool needsCommit() const { return m_needsCommit; }
29 30
31 void setNeedsForcedCommit(bool b) { m_needsForcedCommit = b; }
32 bool needsForcedCommit() const { return m_needsForcedCommit; }
33
30 void setNeedsRedraw(bool b) { m_needsRedraw = b; } 34 void setNeedsRedraw(bool b) { m_needsRedraw = b; }
31 bool needsRedraw() const { return m_needsRedraw; } 35 bool needsRedraw() const { return m_needsRedraw; }
32 36
33 void setNeedsForcedRedraw(bool b) { m_needsForcedRedraw = b; } 37 void setNeedsForcedRedraw(bool b) { m_needsForcedRedraw = b; }
34 bool needsForcedRedraw() const { return m_needsForcedRedraw; } 38 bool needsForcedRedraw() const { return m_needsForcedRedraw; }
35 39
36 bool canDraw() const { return m_canDraw; } 40 bool canDraw() const { return m_canDraw; }
37 bool insideVSync() const { return m_insideVSync; } 41 bool insideVSync() const { return m_insideVSync; }
38 bool visible() const { return m_visible; } 42 bool visible() const { return m_visible; }
39 }; 43 };
40 44
41 TEST(SchedulerStateMachineTest, TestNextActionBeginsFrameIfNeeded) 45 TEST(SchedulerStateMachineTest, TestNextActionBeginsFrameIfNeeded)
42 { 46 {
43 // If no commit needed, do nothing 47 // If no commit needed, do nothing
44 { 48 {
45 StateMachine state; 49 StateMachine state;
46 state.setCommitState(SchedulerStateMachine::COMMIT_STATE_IDLE); 50 state.setCommitState(SchedulerStateMachine::COMMIT_STATE_IDLE);
47 state.setCanBeginFrame(true); 51 state.setCanBeginFrame(true);
48 state.setNeedsRedraw(false); 52 state.setNeedsRedraw(false);
53 state.setNeedsCommit(false);
49 state.setVisible(true); 54 state.setVisible(true);
50 55
51 EXPECT_FALSE(state.vsyncCallbackNeeded()); 56 EXPECT_FALSE(state.vsyncCallbackNeeded());
52 57
53 state.didLeaveVSync(); 58 state.didLeaveVSync();
54 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.nextAction()); 59 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.nextAction());
55 EXPECT_FALSE(state.vsyncCallbackNeeded()); 60 EXPECT_FALSE(state.vsyncCallbackNeeded());
56 state.didEnterVSync(); 61 state.didEnterVSync();
57 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.nextAction()); 62 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.nextAction());
58 } 63 }
59 64
60 // If commit requested but canBeginFrame is still false, do nothing. 65 // If commit requested but canBeginFrame is still false, do nothing.
61 { 66 {
62 StateMachine state; 67 StateMachine state;
63 state.setCommitState(SchedulerStateMachine::COMMIT_STATE_IDLE); 68 state.setCommitState(SchedulerStateMachine::COMMIT_STATE_IDLE);
64 state.setNeedsRedraw(false); 69 state.setNeedsRedraw(false);
70 state.setNeedsCommit(false);
65 state.setVisible(true); 71 state.setVisible(true);
66 72
67 EXPECT_FALSE(state.vsyncCallbackNeeded()); 73 EXPECT_FALSE(state.vsyncCallbackNeeded());
68 74
69 state.didLeaveVSync(); 75 state.didLeaveVSync();
70 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.nextAction()); 76 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.nextAction());
71 EXPECT_FALSE(state.vsyncCallbackNeeded()); 77 EXPECT_FALSE(state.vsyncCallbackNeeded());
72 state.didEnterVSync(); 78 state.didEnterVSync();
73 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.nextAction()); 79 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.nextAction());
74 } 80 }
75 81
76 82
77 // If commit requested, begin a frame 83 // If commit requested, begin a frame
78 { 84 {
79 StateMachine state; 85 StateMachine state;
80 state.setCommitState(SchedulerStateMachine::COMMIT_STATE_IDLE); 86 state.setCommitState(SchedulerStateMachine::COMMIT_STATE_IDLE);
81 state.setCanBeginFrame(true); 87 state.setCanBeginFrame(true);
82 state.setNeedsRedraw(false); 88 state.setNeedsRedraw(false);
89 state.setNeedsCommit(true);
83 state.setVisible(true); 90 state.setVisible(true);
84 EXPECT_FALSE(state.vsyncCallbackNeeded()); 91 EXPECT_FALSE(state.vsyncCallbackNeeded());
85 } 92 }
86 93
87 // Begin the frame, make sure needsCommit and commitState update correctly. 94 // Begin the frame, make sure needsCommit and commitState update correctly.
88 { 95 {
89 StateMachine state; 96 StateMachine state;
90 state.setCanBeginFrame(true); 97 state.setCanBeginFrame(true);
91 state.setVisible(true); 98 state.setVisible(true);
92 state.updateState(SchedulerStateMachine::ACTION_BEGIN_FRAME); 99 state.updateState(SchedulerStateMachine::ACTION_BEGIN_FRAME);
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after
355 StateMachine state; 362 StateMachine state;
356 state.setCommitState(allCommitStates[i]); 363 state.setCommitState(allCommitStates[i]);
357 bool visible = j; 364 bool visible = j;
358 if (!visible) { 365 if (!visible) {
359 state.didEnterVSync(); 366 state.didEnterVSync();
360 state.setVisible(false); 367 state.setVisible(false);
361 } else 368 } else
362 state.setVisible(true); 369 state.setVisible(true);
363 370
364 // Case 1: needsCommit=false 371 // Case 1: needsCommit=false
372 state.setNeedsCommit(false);
365 EXPECT_NE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.next Action()); 373 EXPECT_NE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.next Action());
366 374
367 // Case 2: needsCommit=true 375 // Case 2: needsCommit=true
368 state.setNeedsCommit(); 376 state.setNeedsCommit(true);
369 EXPECT_NE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.next Action()); 377 EXPECT_NE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.next Action());
370 } 378 }
371 } 379 }
372 380
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. 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.
374 for (size_t i = 0; i < numCommitStates; ++i) { 382 for (size_t i = 0; i < numCommitStates; ++i) {
375 for (unsigned j = 0; j < 2; ++j) { 383 for (unsigned j = 0; j < 2; ++j) {
376 StateMachine state; 384 StateMachine state;
377 state.setCanDraw(true); 385 state.setCanDraw(true);
378 state.setCommitState(allCommitStates[i]); 386 state.setCommitState(allCommitStates[i]);
379 bool forcedDraw = j; 387 bool forcedDraw = j;
380 if (!forcedDraw) { 388 if (!forcedDraw) {
381 state.didEnterVSync(); 389 state.didEnterVSync();
382 state.setNeedsRedraw(true); 390 state.setNeedsRedraw(true);
383 state.setVisible(true); 391 state.setVisible(true);
384 } else 392 } else
385 state.setNeedsForcedRedraw(true); 393 state.setNeedsForcedRedraw(true);
386 394
387 SchedulerStateMachine::Action expectedAction; 395 SchedulerStateMachine::Action expectedAction;
388 if (allCommitStates[i] != SchedulerStateMachine::COMMIT_STATE_READY_ TO_COMMIT) 396 if (allCommitStates[i] != SchedulerStateMachine::COMMIT_STATE_READY_ TO_COMMIT)
389 expectedAction = forcedDraw ? SchedulerStateMachine::ACTION_DRAW _FORCED : SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE; 397 expectedAction = forcedDraw ? SchedulerStateMachine::ACTION_DRAW _FORCED : SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE;
390 else 398 else
391 expectedAction = SchedulerStateMachine::ACTION_COMMIT; 399 expectedAction = SchedulerStateMachine::ACTION_COMMIT;
392 400
393 // Case 1: needsCommit=false. 401 // Case 1: needsCommit=false.
402 state.setNeedsCommit(false);
394 EXPECT_TRUE(state.vsyncCallbackNeeded()); 403 EXPECT_TRUE(state.vsyncCallbackNeeded());
395 EXPECT_EQ(expectedAction, state.nextAction()); 404 EXPECT_EQ(expectedAction, state.nextAction());
396 405
397 // Case 2: needsCommit=true. 406 // Case 2: needsCommit=true.
398 state.setNeedsCommit(); 407 state.setNeedsCommit(true);
399 EXPECT_TRUE(state.vsyncCallbackNeeded()); 408 EXPECT_TRUE(state.vsyncCallbackNeeded());
400 EXPECT_EQ(expectedAction, state.nextAction()); 409 EXPECT_EQ(expectedAction, state.nextAction());
401 } 410 }
402 } 411 }
403 } 412 }
404 413
405 TEST(SchedulerStateMachineTest, TestNoCommitStatesRedrawWhenInvisible) 414 TEST(SchedulerStateMachineTest, TestNoCommitStatesRedrawWhenInvisible)
406 { 415 {
407 size_t numCommitStates = sizeof(allCommitStates) / sizeof(SchedulerStateMach ine::CommitState); 416 size_t numCommitStates = sizeof(allCommitStates) / sizeof(SchedulerStateMach ine::CommitState);
408 for (size_t i = 0; i < numCommitStates; ++i) { 417 for (size_t i = 0; i < numCommitStates; ++i) {
409 // There shouldn't be any drawing regardless of vsync. 418 // There shouldn't be any drawing regardless of vsync.
410 for (unsigned j = 0; j < 2; ++j) { 419 for (unsigned j = 0; j < 2; ++j) {
411 StateMachine state; 420 StateMachine state;
412 state.setCommitState(allCommitStates[i]); 421 state.setCommitState(allCommitStates[i]);
413 state.setVisible(false); 422 state.setVisible(false);
414 state.setNeedsRedraw(true); 423 state.setNeedsRedraw(true);
415 state.setNeedsForcedRedraw(false); 424 state.setNeedsForcedRedraw(false);
416 if (j == 1) 425 if (j == 1)
417 state.didEnterVSync(); 426 state.didEnterVSync();
418 427
419 // Case 1: needsCommit=false. 428 // Case 1: needsCommit=false.
429 state.setNeedsCommit(false);
420 EXPECT_NE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.next Action()); 430 EXPECT_NE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.next Action());
421 431
422 // Case 2: needsCommit=true. 432 // Case 2: needsCommit=true.
423 state.setNeedsCommit(); 433 state.setNeedsCommit(true);
424 EXPECT_NE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.next Action()); 434 EXPECT_NE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.next Action());
425 } 435 }
426 } 436 }
427 } 437 }
428 438
429 TEST(SchedulerStateMachineTest, TestCanRedraw_StopsDraw) 439 TEST(SchedulerStateMachineTest, TestCanRedraw_StopsDraw)
430 { 440 {
431 size_t numCommitStates = sizeof(allCommitStates) / sizeof(SchedulerStateMach ine::CommitState); 441 size_t numCommitStates = sizeof(allCommitStates) / sizeof(SchedulerStateMach ine::CommitState);
432 for (size_t i = 0; i < numCommitStates; ++i) { 442 for (size_t i = 0; i < numCommitStates; ++i) {
433 // There shouldn't be any drawing regardless of vsync. 443 // There shouldn't be any drawing regardless of vsync.
(...skipping 10 matching lines...) Expand all
444 EXPECT_NE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.next Action()); 454 EXPECT_NE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.next Action());
445 } 455 }
446 } 456 }
447 } 457 }
448 458
449 TEST(SchedulerStateMachineTest, TestCanRedrawWithWaitingForFirstDrawMakesProgres s) 459 TEST(SchedulerStateMachineTest, TestCanRedrawWithWaitingForFirstDrawMakesProgres s)
450 { 460 {
451 StateMachine state; 461 StateMachine state;
452 state.setCommitState(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_D RAW); 462 state.setCommitState(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_D RAW);
453 state.setCanBeginFrame(true); 463 state.setCanBeginFrame(true);
454 state.setNeedsCommit(); 464 state.setNeedsCommit(true);
455 state.setNeedsRedraw(true); 465 state.setNeedsRedraw(true);
456 state.setVisible(true); 466 state.setVisible(true);
457 state.setCanDraw(false); 467 state.setCanDraw(false);
458 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction()); 468 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction());
459 } 469 }
460 470
461 TEST(SchedulerStateMachineTest, TestSetNeedsCommitIsNotLost) 471 TEST(SchedulerStateMachineTest, TestSetNeedsCommitIsNotLost)
462 { 472 {
463 StateMachine state; 473 StateMachine state;
464 state.setCanBeginFrame(true); 474 state.setCanBeginFrame(true);
465 state.setNeedsCommit(); 475 state.setNeedsCommit(true);
466 state.setVisible(true); 476 state.setVisible(true);
467 state.setCanDraw(true); 477 state.setCanDraw(true);
468 478
469 // Begin the frame. 479 // Begin the frame.
470 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction()); 480 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction());
471 state.updateState(state.nextAction()); 481 state.updateState(state.nextAction());
472 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, state.commi tState()); 482 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, state.commi tState());
473 483
474 // Now, while the frame is in progress, set another commit. 484 // Now, while the frame is in progress, set another commit.
475 state.setNeedsCommit(); 485 state.setNeedsCommit(true);
476 EXPECT_TRUE(state.needsCommit()); 486 EXPECT_TRUE(state.needsCommit());
477 487
478 // Let the frame finish. 488 // Let the frame finish.
479 state.beginFrameComplete(); 489 state.beginFrameComplete();
480 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT, state.commitS tate()); 490 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT, state.commitS tate());
481 491
482 // Expect to commit regardless of vsync state. 492 // Expect to commit regardless of vsync state.
483 state.didLeaveVSync(); 493 state.didLeaveVSync();
484 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.nextAction()); 494 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.nextAction());
485 state.didEnterVSync(); 495 state.didEnterVSync();
(...skipping 12 matching lines...) Expand all
498 } 508 }
499 509
500 TEST(SchedulerStateMachineTest, TestFullCycle) 510 TEST(SchedulerStateMachineTest, TestFullCycle)
501 { 511 {
502 StateMachine state; 512 StateMachine state;
503 state.setCanBeginFrame(true); 513 state.setCanBeginFrame(true);
504 state.setVisible(true); 514 state.setVisible(true);
505 state.setCanDraw(true); 515 state.setCanDraw(true);
506 516
507 // Start clean and set commit. 517 // Start clean and set commit.
508 state.setNeedsCommit(); 518 state.setNeedsCommit(true);
509 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction()); 519 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction());
510 520
511 // Begin the frame. 521 // Begin the frame.
512 state.updateState(SchedulerStateMachine::ACTION_BEGIN_FRAME); 522 state.updateState(SchedulerStateMachine::ACTION_BEGIN_FRAME);
513 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, state.commi tState()); 523 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, state.commi tState());
514 EXPECT_FALSE(state.needsCommit()); 524 EXPECT_FALSE(state.needsCommit());
515 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.nextAction()); 525 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.nextAction());
516 526
517 // Tell the scheduler the frame finished. 527 // Tell the scheduler the frame finished.
518 state.beginFrameComplete(); 528 state.beginFrameComplete();
(...skipping 22 matching lines...) Expand all
541 } 551 }
542 552
543 TEST(SchedulerStateMachineTest, TestFullCycleWithCommitRequestInbetween) 553 TEST(SchedulerStateMachineTest, TestFullCycleWithCommitRequestInbetween)
544 { 554 {
545 StateMachine state; 555 StateMachine state;
546 state.setCanBeginFrame(true); 556 state.setCanBeginFrame(true);
547 state.setVisible(true); 557 state.setVisible(true);
548 state.setCanDraw(true); 558 state.setCanDraw(true);
549 559
550 // Start clean and set commit. 560 // Start clean and set commit.
551 state.setNeedsCommit(); 561 state.setNeedsCommit(true);
552 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction()); 562 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction());
553 563
554 // Begin the frame. 564 // Begin the frame.
555 state.updateState(SchedulerStateMachine::ACTION_BEGIN_FRAME); 565 state.updateState(SchedulerStateMachine::ACTION_BEGIN_FRAME);
556 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, state.commi tState()); 566 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, state.commi tState());
557 EXPECT_FALSE(state.needsCommit()); 567 EXPECT_FALSE(state.needsCommit());
558 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.nextAction()); 568 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.nextAction());
559 569
560 // Request another commit while the commit is in flight. 570 // Request another commit while the commit is in flight.
561 state.setNeedsCommit(); 571 state.setNeedsCommit(true);
562 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.nextAction()); 572 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.nextAction());
563 573
564 // Tell the scheduler the frame finished. 574 // Tell the scheduler the frame finished.
565 state.beginFrameComplete(); 575 state.beginFrameComplete();
566 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT, state.commitS tate()); 576 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT, state.commitS tate());
567 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.nextAction()); 577 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.nextAction());
568 578
569 // Commit. 579 // Commit.
570 state.updateState(SchedulerStateMachine::ACTION_COMMIT); 580 state.updateState(SchedulerStateMachine::ACTION_COMMIT);
571 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW, state. commitState()); 581 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW, state. commitState());
(...skipping 11 matching lines...) Expand all
583 593
584 // Should be synchronized, no draw needed, no action needed. 594 // Should be synchronized, no draw needed, no action needed.
585 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.commitState()); 595 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.commitState());
586 EXPECT_FALSE(state.needsRedraw()); 596 EXPECT_FALSE(state.needsRedraw());
587 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction()); 597 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction());
588 } 598 }
589 599
590 TEST(SchedulerStateMachineTest, TestRequestCommitInvisible) 600 TEST(SchedulerStateMachineTest, TestRequestCommitInvisible)
591 { 601 {
592 StateMachine state; 602 StateMachine state;
593 state.setNeedsCommit(); 603 state.setNeedsCommit(true);
594 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.nextAction()); 604 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.nextAction());
595 } 605 }
596 606
597 TEST(SchedulerStateMachineTest, TestGoesInvisibleBeforeBeginFrameCompletes) 607 TEST(SchedulerStateMachineTest, TestGoesInvisibleBeforeBeginFrameCompletes)
598 { 608 {
599 StateMachine state; 609 StateMachine state;
600 state.setCanBeginFrame(true); 610 state.setCanBeginFrame(true);
601 state.setVisible(true); 611 state.setVisible(true);
602 state.setCanDraw(true); 612 state.setCanDraw(true);
603 613
604 // Start clean and set commit. 614 // Start clean and set commit.
605 state.setNeedsCommit(); 615 state.setNeedsCommit(true);
606 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction()); 616 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction());
607 617
608 // Begin the frame while visible. 618 // Begin the frame while visible.
609 state.updateState(SchedulerStateMachine::ACTION_BEGIN_FRAME); 619 state.updateState(SchedulerStateMachine::ACTION_BEGIN_FRAME);
610 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, state.commi tState()); 620 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, state.commi tState());
611 EXPECT_FALSE(state.needsCommit()); 621 EXPECT_FALSE(state.needsCommit());
612 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.nextAction()); 622 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.nextAction());
613 623
614 // Become invisible and abort the beginFrame. 624 // Become invisible and abort the beginFrame.
615 state.setVisible(false); 625 state.setVisible(false);
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
665 675
666 state.didLoseContext(); 676 state.didLoseContext();
667 677
668 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_CONTEXT_RECREATION, state.next Action()); 678 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_CONTEXT_RECREATION, state.next Action());
669 state.updateState(state.nextAction()); 679 state.updateState(state.nextAction());
670 680
671 // Once context recreation begins, nothing should happen. 681 // Once context recreation begins, nothing should happen.
672 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.nextAction()); 682 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.nextAction());
673 683
674 // While context is recreating, commits shouldn't begin. 684 // While context is recreating, commits shouldn't begin.
675 state.setNeedsCommit(); 685 state.setNeedsCommit(true);
676 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.nextAction()); 686 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.nextAction());
677 687
678 // Recreate the context 688 // Recreate the context
679 state.didRecreateContext(); 689 state.didRecreateContext();
680 690
681 // When the context is recreated, we should begin a commit 691 // When the context is recreated, we should begin a commit
682 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction()); 692 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction());
683 state.updateState(state.nextAction()); 693 state.updateState(state.nextAction());
684 694
685 // Once the context is recreated, whether we draw should be based on 695 // Once the context is recreated, whether we draw should be based on
686 // setCanDraw. 696 // setCanDraw.
687 state.setNeedsRedraw(true); 697 state.setNeedsRedraw(true);
688 state.didEnterVSync(); 698 state.didEnterVSync();
689 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.nextAction() ); 699 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.nextAction() );
690 state.setCanDraw(false); 700 state.setCanDraw(false);
691 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.nextAction()); 701 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.nextAction());
692 state.setCanDraw(true); 702 state.setCanDraw(true);
693 state.didLeaveVSync(); 703 state.didLeaveVSync();
694 } 704 }
695 705
696 TEST(SchedulerStateMachineTest, TestContextLostWhileCommitInProgress) 706 TEST(SchedulerStateMachineTest, TestContextLostWhileCommitInProgress)
697 { 707 {
698 StateMachine state; 708 StateMachine state;
699 state.setCanBeginFrame(true); 709 state.setCanBeginFrame(true);
700 state.setVisible(true); 710 state.setVisible(true);
701 state.setCanDraw(true); 711 state.setCanDraw(true);
702 712
703 // Get a commit in flight. 713 // Get a commit in flight.
704 state.setNeedsCommit(); 714 state.setNeedsCommit(true);
705 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction()); 715 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction());
706 state.updateState(state.nextAction()); 716 state.updateState(state.nextAction());
707 717
708 // Set damage and expect a draw. 718 // Set damage and expect a draw.
709 state.setNeedsRedraw(true); 719 state.setNeedsRedraw(true);
710 state.didEnterVSync(); 720 state.didEnterVSync();
711 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.nextAction() ); 721 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.nextAction() );
712 state.updateState(state.nextAction()); 722 state.updateState(state.nextAction());
713 state.didLeaveVSync(); 723 state.didLeaveVSync();
714 724
(...skipping 22 matching lines...) Expand all
737 } 747 }
738 748
739 TEST(SchedulerStateMachineTest, TestContextLostWhileCommitInProgressAndAnotherCo mmitRequested) 749 TEST(SchedulerStateMachineTest, TestContextLostWhileCommitInProgressAndAnotherCo mmitRequested)
740 { 750 {
741 StateMachine state; 751 StateMachine state;
742 state.setCanBeginFrame(true); 752 state.setCanBeginFrame(true);
743 state.setVisible(true); 753 state.setVisible(true);
744 state.setCanDraw(true); 754 state.setCanDraw(true);
745 755
746 // Get a commit in flight. 756 // Get a commit in flight.
747 state.setNeedsCommit(); 757 state.setNeedsCommit(true);
748 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction()); 758 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction());
749 state.updateState(state.nextAction()); 759 state.updateState(state.nextAction());
750 760
751 // Set damage and expect a draw. 761 // Set damage and expect a draw.
752 state.setNeedsRedraw(true); 762 state.setNeedsRedraw(true);
753 state.didEnterVSync(); 763 state.didEnterVSync();
754 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.nextAction() ); 764 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.nextAction() );
755 state.updateState(state.nextAction()); 765 state.updateState(state.nextAction());
756 state.didLeaveVSync(); 766 state.didLeaveVSync();
757 767
758 // Cause a lost context while the begin frame is in flight. 768 // Cause a lost context while the begin frame is in flight.
759 state.didLoseContext(); 769 state.didLoseContext();
760 770
761 // Ask for another draw and also set needs commit. Expect nothing happens. 771 // Ask for another draw and also set needs commit. Expect nothing happens.
762 state.setNeedsRedraw(true); 772 state.setNeedsRedraw(true);
763 state.setNeedsCommit(); 773 state.setNeedsCommit(true);
764 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.nextAction()); 774 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.nextAction());
765 775
766 // Finish the frame, and commit. 776 // Finish the frame, and commit.
767 state.beginFrameComplete(); 777 state.beginFrameComplete();
768 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.nextAction()); 778 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.nextAction());
769 state.updateState(state.nextAction()); 779 state.updateState(state.nextAction());
770 780
771 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW, state. commitState()); 781 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW, state. commitState());
772 782
773 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.nextAction() ); 783 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.nextAction() );
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
808 state.didEnterVSync(); 818 state.didEnterVSync();
809 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_FORCED, state.nextAction()); 819 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_FORCED, state.nextAction());
810 state.didLeaveVSync(); 820 state.didLeaveVSync();
811 } 821 }
812 822
813 TEST(SchedulerStateMachineTest, TestBeginFrameWhenInvisibleAndForceCommit) 823 TEST(SchedulerStateMachineTest, TestBeginFrameWhenInvisibleAndForceCommit)
814 { 824 {
815 StateMachine state; 825 StateMachine state;
816 state.setCanBeginFrame(true); 826 state.setCanBeginFrame(true);
817 state.setVisible(false); 827 state.setVisible(false);
818 state.setNeedsCommit(); 828 state.setNeedsCommit(true);
819 state.setNeedsForcedCommit(); 829 state.setNeedsForcedCommit(true);
820 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction()); 830 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction());
821 } 831 }
822 832
823 TEST(SchedulerStateMachineTest, TestBeginFrameWhenCanBeginFrameFalseAndForceComm it) 833 TEST(SchedulerStateMachineTest, TestBeginFrameWhenCanBeginFrameFalseAndForceComm it)
824 { 834 {
825 StateMachine state; 835 StateMachine state;
826 state.setVisible(true); 836 state.setVisible(true);
827 state.setCanDraw(true); 837 state.setCanDraw(true);
828 state.setNeedsCommit(); 838 state.setNeedsCommit(true);
829 state.setNeedsForcedCommit(); 839 state.setNeedsForcedCommit(true);
830 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction()); 840 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction());
831 } 841 }
832 842
833 TEST(SchedulerStateMachineTest, TestBeginFrameWhenCommitInProgress) 843 TEST(SchedulerStateMachineTest, TestBeginFrameWhenCommitInProgress)
834 { 844 {
835 StateMachine state; 845 StateMachine state;
836 state.setCanBeginFrame(true); 846 state.setCanBeginFrame(true);
837 state.setVisible(false); 847 state.setVisible(false);
838 state.setCommitState(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS); 848 state.setCommitState(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS);
839 state.setNeedsCommit(); 849 state.setNeedsCommit(true);
840 state.setNeedsForcedCommit(); 850 state.setNeedsForcedCommit(true);
841 851
842 state.beginFrameComplete(); 852 state.beginFrameComplete();
843 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.nextAction()); 853 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.nextAction());
844 state.updateState(state.nextAction()); 854 state.updateState(state.nextAction());
845 855
846 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW, state. commitState()); 856 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW, state. commitState());
847 857
848 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction()); 858 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction());
849 } 859 }
850 860
851 TEST(SchedulerStateMachineTest, TestBeginFrameWhenContextLost) 861 TEST(SchedulerStateMachineTest, TestBeginFrameWhenContextLost)
852 { 862 {
853 StateMachine state; 863 StateMachine state;
854 state.setCanBeginFrame(true); 864 state.setCanBeginFrame(true);
855 state.setVisible(true); 865 state.setVisible(true);
856 state.setCanDraw(true); 866 state.setCanDraw(true);
857 state.setNeedsCommit(); 867 state.setNeedsCommit(true);
858 state.setNeedsForcedCommit(); 868 state.setNeedsForcedCommit(true);
859 state.didLoseContext(); 869 state.didLoseContext();
860 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction()); 870 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction());
861 } 871 }
862 872
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());
887 } 873 }
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
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