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

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

Issue 27200003: Trigger deadline immediately after an aborted main thread commit (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix unit test DCHECK failure. Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « cc/scheduler/scheduler_state_machine.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2011 The Chromium Authors. All rights reserved. 1 // Copyright 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "cc/scheduler/scheduler_state_machine.h" 5 #include "cc/scheduler/scheduler_state_machine.h"
6 6
7 #include "cc/scheduler/scheduler.h" 7 #include "cc/scheduler/scheduler.h"
8 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
9 9
10 #define EXPECT_ACTION_UPDATE_STATE(action) \ 10 #define EXPECT_ACTION_UPDATE_STATE(action) \
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 64
65 BeginFrameState begin_frame_state() const { return begin_frame_state_; } 65 BeginFrameState begin_frame_state() const { return begin_frame_state_; }
66 66
67 OutputSurfaceState output_surface_state() const { 67 OutputSurfaceState output_surface_state() const {
68 return output_surface_state_; 68 return output_surface_state_;
69 } 69 }
70 70
71 bool NeedsCommit() const { return needs_commit_; } 71 bool NeedsCommit() const { return needs_commit_; }
72 72
73 void SetNeedsRedraw(bool b) { needs_redraw_ = b; } 73 void SetNeedsRedraw(bool b) { needs_redraw_ = b; }
74 bool NeedsRedraw() const { return needs_redraw_; }
75 74
76 void SetNeedsForcedRedrawForTimeout(bool b) { 75 void SetNeedsForcedRedrawForTimeout(bool b) {
77 forced_redraw_state_ = FORCED_REDRAW_STATE_WAITING_FOR_COMMIT; 76 forced_redraw_state_ = FORCED_REDRAW_STATE_WAITING_FOR_COMMIT;
78 commit_state_ = COMMIT_STATE_WAITING_FOR_FIRST_DRAW; 77 commit_state_ = COMMIT_STATE_WAITING_FOR_FIRST_DRAW;
79 } 78 }
80 bool NeedsForcedRedrawForTimeout() const { 79 bool NeedsForcedRedrawForTimeout() const {
81 return forced_redraw_state_ != FORCED_REDRAW_STATE_IDLE; 80 return forced_redraw_state_ != FORCED_REDRAW_STATE_IDLE;
82 } 81 }
83 82
84 void SetNeedsForcedRedrawForReadback() { 83 void SetNeedsForcedRedrawForReadback() {
(...skipping 572 matching lines...) Expand 10 before | Expand all | Expand 10 after
657 656
658 // Tell the scheduler the frame finished. 657 // Tell the scheduler the frame finished.
659 state.FinishCommit(); 658 state.FinishCommit();
660 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT, 659 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT,
661 state.CommitState()); 660 state.CommitState());
662 661
663 // Commit. 662 // Commit.
664 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 663 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
665 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW, 664 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW,
666 state.CommitState()); 665 state.CommitState());
667 EXPECT_TRUE(state.NeedsRedraw()); 666 EXPECT_TRUE(state.needs_redraw());
668 667
669 // Expect to do nothing until BeginFrame deadline 668 // Expect to do nothing until BeginFrame deadline
670 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 669 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
671 670
672 // At BeginFrame deadline, draw. 671 // At BeginFrame deadline, draw.
673 state.OnBeginFrameDeadline(); 672 state.OnBeginFrameDeadline();
674 EXPECT_ACTION_UPDATE_STATE( 673 EXPECT_ACTION_UPDATE_STATE(
675 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 674 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
676 state.DidDrawIfPossibleCompleted(true); 675 state.DidDrawIfPossibleCompleted(true);
677 676
678 // Should be synchronized, no draw needed, no action needed. 677 // Should be synchronized, no draw needed, no action needed.
679 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 678 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
680 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState()); 679 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState());
681 EXPECT_FALSE(state.NeedsRedraw()); 680 EXPECT_FALSE(state.needs_redraw());
682 } 681 }
683 682
684 TEST(SchedulerStateMachineTest, TestFullCycleWithCommitRequestInbetween) { 683 TEST(SchedulerStateMachineTest, TestFullCycleWithCommitRequestInbetween) {
685 SchedulerSettings default_scheduler_settings; 684 SchedulerSettings default_scheduler_settings;
686 StateMachine state(default_scheduler_settings); 685 StateMachine state(default_scheduler_settings);
687 state.SetCanStart(); 686 state.SetCanStart();
688 state.UpdateState(state.NextAction()); 687 state.UpdateState(state.NextAction());
689 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 688 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
690 state.SetVisible(true); 689 state.SetVisible(true);
691 state.SetCanDraw(true); 690 state.SetCanDraw(true);
(...skipping 16 matching lines...) Expand all
708 707
709 // Tell the scheduler the frame finished. 708 // Tell the scheduler the frame finished.
710 state.FinishCommit(); 709 state.FinishCommit();
711 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT, 710 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT,
712 state.CommitState()); 711 state.CommitState());
713 712
714 // First commit. 713 // First commit.
715 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 714 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
716 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW, 715 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW,
717 state.CommitState()); 716 state.CommitState());
718 EXPECT_TRUE(state.NeedsRedraw()); 717 EXPECT_TRUE(state.needs_redraw());
719 718
720 // Expect to do nothing until BeginFrame deadline. 719 // Expect to do nothing until BeginFrame deadline.
721 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 720 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
722 721
723 // At BeginFrame deadline, draw. 722 // At BeginFrame deadline, draw.
724 state.OnBeginFrameDeadline(); 723 state.OnBeginFrameDeadline();
725 EXPECT_ACTION_UPDATE_STATE( 724 EXPECT_ACTION_UPDATE_STATE(
726 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 725 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
727 state.DidDrawIfPossibleCompleted(true); 726 state.DidDrawIfPossibleCompleted(true);
728 727
729 // Should be synchronized, no draw needed, no action needed. 728 // Should be synchronized, no draw needed, no action needed.
730 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 729 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
731 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState()); 730 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState());
732 EXPECT_FALSE(state.NeedsRedraw()); 731 EXPECT_FALSE(state.needs_redraw());
733 732
734 // Next BeginFrame should initiate second commit. 733 // Next BeginFrame should initiate second commit.
735 state.OnBeginFrame(BeginFrameArgs::CreateForTesting()); 734 state.OnBeginFrame(BeginFrameArgs::CreateForTesting());
736 EXPECT_ACTION_UPDATE_STATE( 735 EXPECT_ACTION_UPDATE_STATE(
737 SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD); 736 SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD);
738 } 737 }
739 738
740 TEST(SchedulerStateMachineTest, TestRequestCommitInvisible) { 739 TEST(SchedulerStateMachineTest, TestRequestCommitInvisible) {
741 SchedulerSettings default_scheduler_settings; 740 SchedulerSettings default_scheduler_settings;
742 StateMachine state(default_scheduler_settings); 741 StateMachine state(default_scheduler_settings);
(...skipping 864 matching lines...) Expand 10 before | Expand all | Expand 10 after
1607 EXPECT_TRUE(state.PendingDrawsShouldBeAborted()); 1606 EXPECT_TRUE(state.PendingDrawsShouldBeAborted());
1608 1607
1609 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); 1608 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction());
1610 1609
1611 state.BeginFrameAbortedByMainThread(true); 1610 state.BeginFrameAbortedByMainThread(true);
1612 1611
1613 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); 1612 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction());
1614 EXPECT_FALSE(state.PendingDrawsShouldBeAborted()); 1613 EXPECT_FALSE(state.PendingDrawsShouldBeAborted());
1615 } 1614 }
1616 1615
1616 TEST(SchedulerStateMachineTest,
1617 TestTriggerDeadlineEarlyAfterAbortedCommit) {
1618 SchedulerSettings settings;
1619 settings.deadline_scheduling_enabled = true;
1620 settings.impl_side_painting = true;
1621 StateMachine state(settings);
1622 state.SetCanStart();
1623 state.UpdateState(state.NextAction());
1624 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
1625 state.SetVisible(true);
1626 state.SetCanDraw(true);
1627
1628 // This test mirrors what happens during the first frame of a scroll gesture.
1629 // First we get the input event and a BeginFrame.
1630 state.OnBeginFrame(BeginFrameArgs::CreateForTesting());
1631
1632 // As a response the compositor requests a redraw and a commit to tell the
1633 // main thread about the new scroll offset.
1634 state.SetNeedsRedraw(true);
1635 state.SetNeedsCommit();
1636
1637 // We should start the commit normally.
1638 EXPECT_ACTION_UPDATE_STATE(
1639 SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD);
1640 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1641
1642 // Since only the scroll offset changed, the main thread will abort the
1643 // commit.
1644 state.BeginFrameAbortedByMainThread(true);
1645
1646 // Since the commit was aborted, we should draw right away instead of waiting
1647 // for the deadline.
1648 EXPECT_TRUE(state.ShouldTriggerBeginFrameDeadlineEarly());
1649 }
1650
1617 } // namespace 1651 } // namespace
1618 } // namespace cc 1652 } // namespace cc
OLDNEW
« no previous file with comments | « cc/scheduler/scheduler_state_machine.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698