| 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 "cc/scheduler/scheduler_state_machine.h" | 5 #include "cc/scheduler/scheduler_state_machine.h" |
| 6 | 6 |
| 7 #include "base/trace_event/trace_event.h" | 7 #include "base/trace_event/trace_event.h" |
| 8 #include "cc/scheduler/scheduler.h" | 8 #include "cc/scheduler/scheduler.h" |
| 9 #include "cc/test/begin_frame_args_test.h" | 9 #include "cc/test/begin_frame_args_test.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 EXPECT_ENUM_EQ(ActionToString, expected, state.NextAction()) \ | 33 EXPECT_ENUM_EQ(ActionToString, expected, state.NextAction()) \ |
| 34 << state.AsValue()->ToString() | 34 << state.AsValue()->ToString() |
| 35 | 35 |
| 36 #define EXPECT_ACTION_UPDATE_STATE(action) \ | 36 #define EXPECT_ACTION_UPDATE_STATE(action) \ |
| 37 EXPECT_ACTION(action); \ | 37 EXPECT_ACTION(action); \ |
| 38 if (action == SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE || \ | 38 if (action == SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE || \ |
| 39 action == SchedulerStateMachine::ACTION_DRAW_AND_SWAP_FORCED) { \ | 39 action == SchedulerStateMachine::ACTION_DRAW_AND_SWAP_FORCED) { \ |
| 40 EXPECT_IMPL_FRAME_STATE( \ | 40 EXPECT_IMPL_FRAME_STATE( \ |
| 41 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE); \ | 41 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE); \ |
| 42 } \ | 42 } \ |
| 43 state.UpdateState(action); \ | 43 state.WillAction(action); \ |
| 44 if (action == SchedulerStateMachine::ACTION_NONE) { \ | 44 if (action == SchedulerStateMachine::ACTION_NONE) { \ |
| 45 if (state.begin_impl_frame_state() == \ | 45 if (state.begin_impl_frame_state() == \ |
| 46 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_BEGIN_FRAME_STARTING) \ | 46 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_BEGIN_FRAME_STARTING) \ |
| 47 state.OnBeginImplFrameDeadlinePending(); \ | 47 state.OnBeginImplFrameDeadlinePending(); \ |
| 48 if (state.begin_impl_frame_state() == \ | 48 if (state.begin_impl_frame_state() == \ |
| 49 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE) \ | 49 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE) \ |
| 50 state.OnBeginImplFrameIdle(); \ | 50 state.OnBeginImplFrameIdle(); \ |
| 51 } | 51 } |
| 52 | 52 |
| 53 #define SET_UP_STATE(state) \ | 53 #define SET_UP_STATE(state) \ |
| 54 state.SetCanStart(); \ | 54 state.SetCanStart(); \ |
| 55 state.UpdateState(state.NextAction()); \ | 55 state.WillAction(state.NextAction()); \ |
| 56 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); \ | 56 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); \ |
| 57 state.SetVisible(true); \ | 57 state.SetVisible(true); \ |
| 58 state.SetCanDraw(true); | 58 state.SetCanDraw(true); |
| 59 | 59 |
| 60 namespace cc { | 60 namespace cc { |
| 61 | 61 |
| 62 namespace { | 62 namespace { |
| 63 | 63 |
| 64 const SchedulerStateMachine::BeginImplFrameState all_begin_impl_frame_states[] = | 64 const SchedulerStateMachine::BeginImplFrameState all_begin_impl_frame_states[] = |
| 65 {SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE, | 65 {SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE, |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 bool PendingActivationsShouldBeForced() const { | 139 bool PendingActivationsShouldBeForced() const { |
| 140 return SchedulerStateMachine::PendingActivationsShouldBeForced(); | 140 return SchedulerStateMachine::PendingActivationsShouldBeForced(); |
| 141 } | 141 } |
| 142 | 142 |
| 143 void SetHasPendingTree(bool has_pending_tree) { | 143 void SetHasPendingTree(bool has_pending_tree) { |
| 144 has_pending_tree_ = has_pending_tree; | 144 has_pending_tree_ = has_pending_tree; |
| 145 } | 145 } |
| 146 | 146 |
| 147 using SchedulerStateMachine::ShouldTriggerBeginImplFrameDeadlineImmediately; | 147 using SchedulerStateMachine::ShouldTriggerBeginImplFrameDeadlineImmediately; |
| 148 using SchedulerStateMachine::ProactiveBeginFrameWanted; | 148 using SchedulerStateMachine::ProactiveBeginFrameWanted; |
| 149 using SchedulerStateMachine::UpdateStateOnCommit; | 149 using SchedulerStateMachine::WillCommit; |
| 150 }; | 150 }; |
| 151 | 151 |
| 152 TEST(SchedulerStateMachineTest, BeginFrameNeeded) { | 152 TEST(SchedulerStateMachineTest, BeginFrameNeeded) { |
| 153 SchedulerSettings default_scheduler_settings; | 153 SchedulerSettings default_scheduler_settings; |
| 154 StateMachine state(default_scheduler_settings); | 154 StateMachine state(default_scheduler_settings); |
| 155 state.SetCanStart(); | 155 state.SetCanStart(); |
| 156 EXPECT_ACTION_UPDATE_STATE( | 156 EXPECT_ACTION_UPDATE_STATE( |
| 157 SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION) | 157 SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION) |
| 158 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); | 158 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); |
| 159 state.SetBeginMainFrameState( | 159 state.SetBeginMainFrameState( |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 239 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | 239 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 240 EXPECT_TRUE(state.NeedsCommit()); | 240 EXPECT_TRUE(state.NeedsCommit()); |
| 241 } | 241 } |
| 242 | 242 |
| 243 // If commit requested, begin a main frame. | 243 // If commit requested, begin a main frame. |
| 244 { | 244 { |
| 245 StateMachine state(default_scheduler_settings); | 245 StateMachine state(default_scheduler_settings); |
| 246 state.SetBeginMainFrameState( | 246 state.SetBeginMainFrameState( |
| 247 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_IDLE); | 247 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_IDLE); |
| 248 state.SetCanStart(); | 248 state.SetCanStart(); |
| 249 state.UpdateState(state.NextAction()); | 249 state.WillAction(state.NextAction()); |
| 250 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); | 250 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); |
| 251 state.SetNeedsRedraw(false); | 251 state.SetNeedsRedraw(false); |
| 252 state.SetVisible(true); | 252 state.SetVisible(true); |
| 253 state.SetNeedsBeginMainFrame(); | 253 state.SetNeedsBeginMainFrame(); |
| 254 | 254 |
| 255 // Expect nothing to happen until after OnBeginImplFrame. | 255 // Expect nothing to happen until after OnBeginImplFrame. |
| 256 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | 256 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 257 EXPECT_MAIN_FRAME_STATE(SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_IDLE); | 257 EXPECT_MAIN_FRAME_STATE(SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_IDLE); |
| 258 EXPECT_IMPL_FRAME_STATE(SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE); | 258 EXPECT_IMPL_FRAME_STATE(SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE); |
| 259 EXPECT_TRUE(state.NeedsCommit()); | 259 EXPECT_TRUE(state.NeedsCommit()); |
| 260 EXPECT_TRUE(state.BeginFrameNeeded()); | 260 EXPECT_TRUE(state.BeginFrameNeeded()); |
| 261 | 261 |
| 262 state.OnBeginImplFrame(); | 262 state.OnBeginImplFrame(); |
| 263 EXPECT_ACTION_UPDATE_STATE( | 263 EXPECT_ACTION_UPDATE_STATE( |
| 264 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); | 264 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); |
| 265 EXPECT_MAIN_FRAME_STATE(SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_SENT); | 265 EXPECT_MAIN_FRAME_STATE(SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_SENT); |
| 266 EXPECT_FALSE(state.NeedsCommit()); | 266 EXPECT_FALSE(state.NeedsCommit()); |
| 267 } | 267 } |
| 268 | 268 |
| 269 // If commit requested and can't draw, still begin a main frame. | 269 // If commit requested and can't draw, still begin a main frame. |
| 270 { | 270 { |
| 271 StateMachine state(default_scheduler_settings); | 271 StateMachine state(default_scheduler_settings); |
| 272 state.SetBeginMainFrameState( | 272 state.SetBeginMainFrameState( |
| 273 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_IDLE); | 273 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_IDLE); |
| 274 state.SetCanStart(); | 274 state.SetCanStart(); |
| 275 state.UpdateState(state.NextAction()); | 275 state.WillAction(state.NextAction()); |
| 276 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); | 276 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); |
| 277 state.SetNeedsRedraw(false); | 277 state.SetNeedsRedraw(false); |
| 278 state.SetVisible(true); | 278 state.SetVisible(true); |
| 279 state.SetNeedsBeginMainFrame(); | 279 state.SetNeedsBeginMainFrame(); |
| 280 state.SetCanDraw(false); | 280 state.SetCanDraw(false); |
| 281 | 281 |
| 282 // Expect nothing to happen until after OnBeginImplFrame. | 282 // Expect nothing to happen until after OnBeginImplFrame. |
| 283 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | 283 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 284 EXPECT_MAIN_FRAME_STATE(SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_IDLE); | 284 EXPECT_MAIN_FRAME_STATE(SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_IDLE); |
| 285 EXPECT_IMPL_FRAME_STATE(SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE); | 285 EXPECT_IMPL_FRAME_STATE(SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE); |
| (...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 655 size_t num_begin_main_frame_states = | 655 size_t num_begin_main_frame_states = |
| 656 sizeof(begin_main_frame_states) / | 656 sizeof(begin_main_frame_states) / |
| 657 sizeof(SchedulerStateMachine::BeginMainFrameState); | 657 sizeof(SchedulerStateMachine::BeginMainFrameState); |
| 658 size_t num_begin_impl_frame_states = | 658 size_t num_begin_impl_frame_states = |
| 659 sizeof(all_begin_impl_frame_states) / | 659 sizeof(all_begin_impl_frame_states) / |
| 660 sizeof(SchedulerStateMachine::BeginImplFrameState); | 660 sizeof(SchedulerStateMachine::BeginImplFrameState); |
| 661 for (size_t i = 0; i < num_begin_main_frame_states; ++i) { | 661 for (size_t i = 0; i < num_begin_main_frame_states; ++i) { |
| 662 for (size_t j = 0; j < num_begin_impl_frame_states; ++j) { | 662 for (size_t j = 0; j < num_begin_impl_frame_states; ++j) { |
| 663 StateMachine state(default_scheduler_settings); | 663 StateMachine state(default_scheduler_settings); |
| 664 state.SetCanStart(); | 664 state.SetCanStart(); |
| 665 state.UpdateState(state.NextAction()); | 665 state.WillAction(state.NextAction()); |
| 666 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); | 666 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); |
| 667 state.SetBeginMainFrameState(begin_main_frame_states[i]); | 667 state.SetBeginMainFrameState(begin_main_frame_states[i]); |
| 668 state.SetBeginImplFrameState(all_begin_impl_frame_states[j]); | 668 state.SetBeginImplFrameState(all_begin_impl_frame_states[j]); |
| 669 bool visible = | 669 bool visible = |
| 670 (all_begin_impl_frame_states[j] != | 670 (all_begin_impl_frame_states[j] != |
| 671 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE); | 671 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE); |
| 672 state.SetVisible(visible); | 672 state.SetVisible(visible); |
| 673 | 673 |
| 674 // Case 1: needs_begin_main_frame=false | 674 // Case 1: needs_begin_main_frame=false |
| 675 EXPECT_NE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE, | 675 EXPECT_NE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE, |
| 676 state.NextAction()); | 676 state.NextAction()); |
| 677 | 677 |
| 678 // Case 2: needs_begin_main_frame=true | 678 // Case 2: needs_begin_main_frame=true |
| 679 state.SetNeedsBeginMainFrame(); | 679 state.SetNeedsBeginMainFrame(); |
| 680 EXPECT_NE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE, | 680 EXPECT_NE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE, |
| 681 state.NextAction()) | 681 state.NextAction()) |
| 682 << state.AsValue()->ToString(); | 682 << state.AsValue()->ToString(); |
| 683 } | 683 } |
| 684 } | 684 } |
| 685 | 685 |
| 686 // When in BeginImplFrame deadline we should always draw for SetNeedsRedraw | 686 // When in BeginImplFrame deadline we should always draw for SetNeedsRedraw |
| 687 // except if we're ready to commit, in which case we expect a commit first. | 687 // except if we're ready to commit, in which case we expect a commit first. |
| 688 for (size_t i = 0; i < num_begin_main_frame_states; ++i) { | 688 for (size_t i = 0; i < num_begin_main_frame_states; ++i) { |
| 689 StateMachine state(default_scheduler_settings); | 689 StateMachine state(default_scheduler_settings); |
| 690 state.SetCanStart(); | 690 state.SetCanStart(); |
| 691 state.UpdateState(state.NextAction()); | 691 state.WillAction(state.NextAction()); |
| 692 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); | 692 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); |
| 693 state.SetCanDraw(true); | 693 state.SetCanDraw(true); |
| 694 state.SetBeginMainFrameState(begin_main_frame_states[i]); | 694 state.SetBeginMainFrameState(begin_main_frame_states[i]); |
| 695 state.SetBeginImplFrameState( | 695 state.SetBeginImplFrameState( |
| 696 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE); | 696 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE); |
| 697 | 697 |
| 698 state.SetNeedsRedraw(true); | 698 state.SetNeedsRedraw(true); |
| 699 state.SetVisible(true); | 699 state.SetVisible(true); |
| 700 | 700 |
| 701 SchedulerStateMachine::Action expected_action; | 701 SchedulerStateMachine::Action expected_action; |
| 702 if (begin_main_frame_states[i] == | 702 if (begin_main_frame_states[i] == |
| 703 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_READY_TO_COMMIT) { | 703 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_READY_TO_COMMIT) { |
| 704 expected_action = SchedulerStateMachine::ACTION_COMMIT; | 704 expected_action = SchedulerStateMachine::ACTION_COMMIT; |
| 705 } else { | 705 } else { |
| 706 expected_action = SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE; | 706 expected_action = SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE; |
| 707 EXPECT_ACTION(SchedulerStateMachine::ACTION_ANIMATE); | 707 EXPECT_ACTION(SchedulerStateMachine::ACTION_ANIMATE); |
| 708 state.UpdateState(state.NextAction()); | 708 state.WillAction(state.NextAction()); |
| 709 } | 709 } |
| 710 | 710 |
| 711 // Case 1: needs_begin_main_frame=false. | 711 // Case 1: needs_begin_main_frame=false. |
| 712 EXPECT_ACTION(expected_action); | 712 EXPECT_ACTION(expected_action); |
| 713 | 713 |
| 714 // Case 2: needs_begin_main_frame=true. | 714 // Case 2: needs_begin_main_frame=true. |
| 715 state.SetNeedsBeginMainFrame(); | 715 state.SetNeedsBeginMainFrame(); |
| 716 EXPECT_ACTION(expected_action); | 716 EXPECT_ACTION(expected_action); |
| 717 } | 717 } |
| 718 } | 718 } |
| 719 | 719 |
| 720 TEST(SchedulerStateMachineTest, TestNoBeginMainFrameStatesRedrawWhenInvisible) { | 720 TEST(SchedulerStateMachineTest, TestNoBeginMainFrameStatesRedrawWhenInvisible) { |
| 721 SchedulerSettings default_scheduler_settings; | 721 SchedulerSettings default_scheduler_settings; |
| 722 | 722 |
| 723 size_t num_begin_main_frame_states = | 723 size_t num_begin_main_frame_states = |
| 724 sizeof(begin_main_frame_states) / | 724 sizeof(begin_main_frame_states) / |
| 725 sizeof(SchedulerStateMachine::BeginMainFrameState); | 725 sizeof(SchedulerStateMachine::BeginMainFrameState); |
| 726 for (size_t i = 0; i < num_begin_main_frame_states; ++i) { | 726 for (size_t i = 0; i < num_begin_main_frame_states; ++i) { |
| 727 // There shouldn't be any drawing regardless of BeginImplFrame. | 727 // There shouldn't be any drawing regardless of BeginImplFrame. |
| 728 for (size_t j = 0; j < 2; ++j) { | 728 for (size_t j = 0; j < 2; ++j) { |
| 729 StateMachine state(default_scheduler_settings); | 729 StateMachine state(default_scheduler_settings); |
| 730 state.SetCanStart(); | 730 state.SetCanStart(); |
| 731 state.UpdateState(state.NextAction()); | 731 state.WillAction(state.NextAction()); |
| 732 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); | 732 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); |
| 733 state.SetBeginMainFrameState(begin_main_frame_states[i]); | 733 state.SetBeginMainFrameState(begin_main_frame_states[i]); |
| 734 state.SetVisible(false); | 734 state.SetVisible(false); |
| 735 state.SetNeedsRedraw(true); | 735 state.SetNeedsRedraw(true); |
| 736 if (j == 1) { | 736 if (j == 1) { |
| 737 state.SetBeginImplFrameState( | 737 state.SetBeginImplFrameState( |
| 738 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE); | 738 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE); |
| 739 } | 739 } |
| 740 | 740 |
| 741 // Case 1: needs_begin_main_frame=false. | 741 // Case 1: needs_begin_main_frame=false. |
| (...skipping 13 matching lines...) Expand all Loading... |
| 755 SchedulerSettings default_scheduler_settings; | 755 SchedulerSettings default_scheduler_settings; |
| 756 | 756 |
| 757 size_t num_begin_main_frame_states = | 757 size_t num_begin_main_frame_states = |
| 758 sizeof(begin_main_frame_states) / | 758 sizeof(begin_main_frame_states) / |
| 759 sizeof(SchedulerStateMachine::BeginMainFrameState); | 759 sizeof(SchedulerStateMachine::BeginMainFrameState); |
| 760 for (size_t i = 0; i < num_begin_main_frame_states; ++i) { | 760 for (size_t i = 0; i < num_begin_main_frame_states; ++i) { |
| 761 // There shouldn't be any drawing regardless of BeginImplFrame. | 761 // There shouldn't be any drawing regardless of BeginImplFrame. |
| 762 for (size_t j = 0; j < 2; ++j) { | 762 for (size_t j = 0; j < 2; ++j) { |
| 763 StateMachine state(default_scheduler_settings); | 763 StateMachine state(default_scheduler_settings); |
| 764 state.SetCanStart(); | 764 state.SetCanStart(); |
| 765 state.UpdateState(state.NextAction()); | 765 state.WillAction(state.NextAction()); |
| 766 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); | 766 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); |
| 767 state.SetBeginMainFrameState(begin_main_frame_states[i]); | 767 state.SetBeginMainFrameState(begin_main_frame_states[i]); |
| 768 state.SetVisible(false); | 768 state.SetVisible(false); |
| 769 state.SetNeedsRedraw(true); | 769 state.SetNeedsRedraw(true); |
| 770 if (j == 1) | 770 if (j == 1) |
| 771 state.OnBeginImplFrame(); | 771 state.OnBeginImplFrame(); |
| 772 | 772 |
| 773 state.SetCanDraw(false); | 773 state.SetCanDraw(false); |
| 774 EXPECT_NE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE, | 774 EXPECT_NE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE, |
| 775 state.NextAction()); | 775 state.NextAction()); |
| 776 } | 776 } |
| 777 } | 777 } |
| 778 } | 778 } |
| 779 | 779 |
| 780 TEST(SchedulerStateMachineTest, | 780 TEST(SchedulerStateMachineTest, |
| 781 TestCanRedrawWithWaitingForFirstDrawMakesProgress) { | 781 TestCanRedrawWithWaitingForFirstDrawMakesProgress) { |
| 782 SchedulerSettings default_scheduler_settings; | 782 SchedulerSettings default_scheduler_settings; |
| 783 StateMachine state(default_scheduler_settings); | 783 StateMachine state(default_scheduler_settings); |
| 784 state.SetCanStart(); | 784 state.SetCanStart(); |
| 785 state.UpdateState(state.NextAction()); | 785 state.WillAction(state.NextAction()); |
| 786 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); | 786 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); |
| 787 | 787 |
| 788 state.SetActiveTreeNeedsFirstDraw(true); | 788 state.SetActiveTreeNeedsFirstDraw(true); |
| 789 state.SetNeedsBeginMainFrame(); | 789 state.SetNeedsBeginMainFrame(); |
| 790 state.SetNeedsRedraw(true); | 790 state.SetNeedsRedraw(true); |
| 791 state.SetVisible(true); | 791 state.SetVisible(true); |
| 792 state.SetCanDraw(false); | 792 state.SetCanDraw(false); |
| 793 state.OnBeginImplFrame(); | 793 state.OnBeginImplFrame(); |
| 794 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE); | 794 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE); |
| 795 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT); | 795 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT); |
| (...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1118 // Next BeginImplFrame should initiate second commit. | 1118 // Next BeginImplFrame should initiate second commit. |
| 1119 state.OnBeginImplFrame(); | 1119 state.OnBeginImplFrame(); |
| 1120 EXPECT_ACTION_UPDATE_STATE( | 1120 EXPECT_ACTION_UPDATE_STATE( |
| 1121 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); | 1121 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); |
| 1122 } | 1122 } |
| 1123 | 1123 |
| 1124 TEST(SchedulerStateMachineTest, TestRequestCommitInvisible) { | 1124 TEST(SchedulerStateMachineTest, TestRequestCommitInvisible) { |
| 1125 SchedulerSettings default_scheduler_settings; | 1125 SchedulerSettings default_scheduler_settings; |
| 1126 StateMachine state(default_scheduler_settings); | 1126 StateMachine state(default_scheduler_settings); |
| 1127 state.SetCanStart(); | 1127 state.SetCanStart(); |
| 1128 state.UpdateState(state.NextAction()); | 1128 state.WillAction(state.NextAction()); |
| 1129 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); | 1129 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); |
| 1130 state.SetNeedsBeginMainFrame(); | 1130 state.SetNeedsBeginMainFrame(); |
| 1131 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | 1131 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 1132 } | 1132 } |
| 1133 | 1133 |
| 1134 // See ThreadProxy::BeginMainFrame "EarlyOut_NotVisible" / | 1134 // See ThreadProxy::BeginMainFrame "EarlyOut_NotVisible" / |
| 1135 // "EarlyOut_OutputSurfaceLost" cases. | 1135 // "EarlyOut_OutputSurfaceLost" cases. |
| 1136 TEST(SchedulerStateMachineTest, TestAbortBeginMainFrameBecauseInvisible) { | 1136 TEST(SchedulerStateMachineTest, TestAbortBeginMainFrameBecauseInvisible) { |
| 1137 SchedulerSettings default_scheduler_settings; | 1137 SchedulerSettings default_scheduler_settings; |
| 1138 StateMachine state(default_scheduler_settings); | 1138 StateMachine state(default_scheduler_settings); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1182 // We should be starting the commit now. | 1182 // We should be starting the commit now. |
| 1183 EXPECT_MAIN_FRAME_STATE(SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_SENT); | 1183 EXPECT_MAIN_FRAME_STATE(SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_SENT); |
| 1184 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | 1184 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 1185 } | 1185 } |
| 1186 | 1186 |
| 1187 // See ThreadProxy::BeginMainFrame "EarlyOut_NoUpdates" case. | 1187 // See ThreadProxy::BeginMainFrame "EarlyOut_NoUpdates" case. |
| 1188 TEST(SchedulerStateMachineTest, TestAbortBeginMainFrameBecauseCommitNotNeeded) { | 1188 TEST(SchedulerStateMachineTest, TestAbortBeginMainFrameBecauseCommitNotNeeded) { |
| 1189 SchedulerSettings default_scheduler_settings; | 1189 SchedulerSettings default_scheduler_settings; |
| 1190 StateMachine state(default_scheduler_settings); | 1190 StateMachine state(default_scheduler_settings); |
| 1191 state.SetCanStart(); | 1191 state.SetCanStart(); |
| 1192 state.UpdateState(state.NextAction()); | 1192 state.WillAction(state.NextAction()); |
| 1193 state.DidCreateAndInitializeOutputSurface(); | 1193 state.DidCreateAndInitializeOutputSurface(); |
| 1194 state.SetVisible(true); | 1194 state.SetVisible(true); |
| 1195 state.SetCanDraw(true); | 1195 state.SetCanDraw(true); |
| 1196 | 1196 |
| 1197 // Get into a begin frame / commit state. | 1197 // Get into a begin frame / commit state. |
| 1198 state.SetNeedsBeginMainFrame(); | 1198 state.SetNeedsBeginMainFrame(); |
| 1199 state.OnBeginImplFrame(); | 1199 state.OnBeginImplFrame(); |
| 1200 EXPECT_ACTION_UPDATE_STATE( | 1200 EXPECT_ACTION_UPDATE_STATE( |
| 1201 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); | 1201 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); |
| 1202 EXPECT_MAIN_FRAME_STATE(SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_SENT); | 1202 EXPECT_MAIN_FRAME_STATE(SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_SENT); |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1264 TEST(SchedulerStateMachineTest, TestContextLostWhenCompletelyIdle) { | 1264 TEST(SchedulerStateMachineTest, TestContextLostWhenCompletelyIdle) { |
| 1265 SchedulerSettings default_scheduler_settings; | 1265 SchedulerSettings default_scheduler_settings; |
| 1266 StateMachine state(default_scheduler_settings); | 1266 StateMachine state(default_scheduler_settings); |
| 1267 SET_UP_STATE(state) | 1267 SET_UP_STATE(state) |
| 1268 | 1268 |
| 1269 EXPECT_NE(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION, | 1269 EXPECT_NE(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION, |
| 1270 state.NextAction()); | 1270 state.NextAction()); |
| 1271 state.DidLoseOutputSurface(); | 1271 state.DidLoseOutputSurface(); |
| 1272 | 1272 |
| 1273 EXPECT_ACTION(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION); | 1273 EXPECT_ACTION(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION); |
| 1274 state.UpdateState(state.NextAction()); | 1274 state.WillAction(state.NextAction()); |
| 1275 | 1275 |
| 1276 // Once context recreation begins, nothing should happen. | 1276 // Once context recreation begins, nothing should happen. |
| 1277 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | 1277 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 1278 | 1278 |
| 1279 // Recreate the context. | 1279 // Recreate the context. |
| 1280 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); | 1280 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); |
| 1281 | 1281 |
| 1282 // When the context is recreated, we should begin a commit. | 1282 // When the context is recreated, we should begin a commit. |
| 1283 state.OnBeginImplFrame(); | 1283 state.OnBeginImplFrame(); |
| 1284 EXPECT_ACTION_UPDATE_STATE( | 1284 EXPECT_ACTION_UPDATE_STATE( |
| (...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1560 TEST(SchedulerStateMachineTest, DontDrawBeforeCommitAfterLostOutputSurface) { | 1560 TEST(SchedulerStateMachineTest, DontDrawBeforeCommitAfterLostOutputSurface) { |
| 1561 SchedulerSettings default_scheduler_settings; | 1561 SchedulerSettings default_scheduler_settings; |
| 1562 StateMachine state(default_scheduler_settings); | 1562 StateMachine state(default_scheduler_settings); |
| 1563 SET_UP_STATE(state) | 1563 SET_UP_STATE(state) |
| 1564 | 1564 |
| 1565 state.SetNeedsRedraw(true); | 1565 state.SetNeedsRedraw(true); |
| 1566 | 1566 |
| 1567 // Cause a lost output surface, and restore it. | 1567 // Cause a lost output surface, and restore it. |
| 1568 state.DidLoseOutputSurface(); | 1568 state.DidLoseOutputSurface(); |
| 1569 EXPECT_ACTION(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION); | 1569 EXPECT_ACTION(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION); |
| 1570 state.UpdateState(state.NextAction()); | 1570 state.WillAction(state.NextAction()); |
| 1571 state.DidCreateAndInitializeOutputSurface(); | 1571 state.DidCreateAndInitializeOutputSurface(); |
| 1572 | 1572 |
| 1573 EXPECT_FALSE(state.RedrawPending()); | 1573 EXPECT_FALSE(state.RedrawPending()); |
| 1574 state.OnBeginImplFrame(); | 1574 state.OnBeginImplFrame(); |
| 1575 EXPECT_ACTION(SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); | 1575 EXPECT_ACTION(SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); |
| 1576 } | 1576 } |
| 1577 | 1577 |
| 1578 TEST(SchedulerStateMachineTest, | 1578 TEST(SchedulerStateMachineTest, |
| 1579 TestPendingActivationsShouldBeForcedAfterLostOutputSurface) { | 1579 TestPendingActivationsShouldBeForcedAfterLostOutputSurface) { |
| 1580 SchedulerSettings default_scheduler_settings; | 1580 SchedulerSettings default_scheduler_settings; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1595 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE); | 1595 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE); |
| 1596 | 1596 |
| 1597 EXPECT_TRUE(state.PendingDrawsShouldBeAborted()); | 1597 EXPECT_TRUE(state.PendingDrawsShouldBeAborted()); |
| 1598 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT); | 1598 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT); |
| 1599 } | 1599 } |
| 1600 | 1600 |
| 1601 TEST(SchedulerStateMachineTest, TestNoBeginFrameNeededWhenInvisible) { | 1601 TEST(SchedulerStateMachineTest, TestNoBeginFrameNeededWhenInvisible) { |
| 1602 SchedulerSettings default_scheduler_settings; | 1602 SchedulerSettings default_scheduler_settings; |
| 1603 StateMachine state(default_scheduler_settings); | 1603 StateMachine state(default_scheduler_settings); |
| 1604 state.SetCanStart(); | 1604 state.SetCanStart(); |
| 1605 state.UpdateState(state.NextAction()); | 1605 state.WillAction(state.NextAction()); |
| 1606 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); | 1606 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); |
| 1607 state.SetVisible(true); | 1607 state.SetVisible(true); |
| 1608 | 1608 |
| 1609 EXPECT_FALSE(state.BeginFrameNeeded()); | 1609 EXPECT_FALSE(state.BeginFrameNeeded()); |
| 1610 state.SetNeedsRedraw(true); | 1610 state.SetNeedsRedraw(true); |
| 1611 EXPECT_TRUE(state.BeginFrameNeeded()); | 1611 EXPECT_TRUE(state.BeginFrameNeeded()); |
| 1612 | 1612 |
| 1613 state.SetVisible(false); | 1613 state.SetVisible(false); |
| 1614 EXPECT_FALSE(state.BeginFrameNeeded()); | 1614 EXPECT_FALSE(state.BeginFrameNeeded()); |
| 1615 | 1615 |
| 1616 state.SetVisible(true); | 1616 state.SetVisible(true); |
| 1617 EXPECT_TRUE(state.BeginFrameNeeded()); | 1617 EXPECT_TRUE(state.BeginFrameNeeded()); |
| 1618 } | 1618 } |
| 1619 | 1619 |
| 1620 TEST(SchedulerStateMachineTest, TestNoBeginMainFrameWhenInvisible) { | 1620 TEST(SchedulerStateMachineTest, TestNoBeginMainFrameWhenInvisible) { |
| 1621 SchedulerSettings default_scheduler_settings; | 1621 SchedulerSettings default_scheduler_settings; |
| 1622 StateMachine state(default_scheduler_settings); | 1622 StateMachine state(default_scheduler_settings); |
| 1623 state.SetCanStart(); | 1623 state.SetCanStart(); |
| 1624 state.UpdateState(state.NextAction()); | 1624 state.WillAction(state.NextAction()); |
| 1625 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); | 1625 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); |
| 1626 state.SetVisible(false); | 1626 state.SetVisible(false); |
| 1627 state.SetNeedsBeginMainFrame(); | 1627 state.SetNeedsBeginMainFrame(); |
| 1628 EXPECT_ACTION(SchedulerStateMachine::ACTION_NONE); | 1628 EXPECT_ACTION(SchedulerStateMachine::ACTION_NONE); |
| 1629 EXPECT_FALSE(state.BeginFrameNeeded()); | 1629 EXPECT_FALSE(state.BeginFrameNeeded()); |
| 1630 | 1630 |
| 1631 // When become visible again, the needs commit should still be pending. | 1631 // When become visible again, the needs commit should still be pending. |
| 1632 state.SetVisible(true); | 1632 state.SetVisible(true); |
| 1633 EXPECT_TRUE(state.BeginFrameNeeded()); | 1633 EXPECT_TRUE(state.BeginFrameNeeded()); |
| 1634 state.OnBeginImplFrame(); | 1634 state.OnBeginImplFrame(); |
| 1635 EXPECT_ACTION_UPDATE_STATE( | 1635 EXPECT_ACTION_UPDATE_STATE( |
| 1636 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); | 1636 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); |
| 1637 } | 1637 } |
| 1638 | 1638 |
| 1639 TEST(SchedulerStateMachineTest, TestFinishCommitWhenCommitInProgress) { | 1639 TEST(SchedulerStateMachineTest, TestFinishCommitWhenCommitInProgress) { |
| 1640 SchedulerSettings default_scheduler_settings; | 1640 SchedulerSettings default_scheduler_settings; |
| 1641 StateMachine state(default_scheduler_settings); | 1641 StateMachine state(default_scheduler_settings); |
| 1642 state.SetCanStart(); | 1642 state.SetCanStart(); |
| 1643 state.UpdateState(state.NextAction()); | 1643 state.WillAction(state.NextAction()); |
| 1644 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); | 1644 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); |
| 1645 state.SetVisible(false); | 1645 state.SetVisible(false); |
| 1646 state.SetBeginMainFrameState( | 1646 state.SetBeginMainFrameState( |
| 1647 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_SENT); | 1647 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_SENT); |
| 1648 state.SetNeedsBeginMainFrame(); | 1648 state.SetNeedsBeginMainFrame(); |
| 1649 | 1649 |
| 1650 state.NotifyBeginMainFrameStarted(); | 1650 state.NotifyBeginMainFrameStarted(); |
| 1651 state.NotifyReadyToCommit(); | 1651 state.NotifyReadyToCommit(); |
| 1652 EXPECT_ACTION(SchedulerStateMachine::ACTION_COMMIT); | 1652 EXPECT_ACTION(SchedulerStateMachine::ACTION_COMMIT); |
| 1653 state.UpdateState(state.NextAction()); | 1653 state.WillAction(state.NextAction()); |
| 1654 state.NotifyReadyToActivate(); | 1654 state.NotifyReadyToActivate(); |
| 1655 EXPECT_ACTION(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE); | 1655 EXPECT_ACTION(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE); |
| 1656 state.UpdateState(state.NextAction()); | 1656 state.WillAction(state.NextAction()); |
| 1657 | 1657 |
| 1658 EXPECT_TRUE(state.active_tree_needs_first_draw()); | 1658 EXPECT_TRUE(state.active_tree_needs_first_draw()); |
| 1659 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT); | 1659 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT); |
| 1660 } | 1660 } |
| 1661 | 1661 |
| 1662 TEST(SchedulerStateMachineTest, TestInitialActionsWhenContextLost) { | 1662 TEST(SchedulerStateMachineTest, TestInitialActionsWhenContextLost) { |
| 1663 SchedulerSettings default_scheduler_settings; | 1663 SchedulerSettings default_scheduler_settings; |
| 1664 StateMachine state(default_scheduler_settings); | 1664 StateMachine state(default_scheduler_settings); |
| 1665 SET_UP_STATE(state) | 1665 SET_UP_STATE(state) |
| 1666 state.SetNeedsBeginMainFrame(); | 1666 state.SetNeedsBeginMainFrame(); |
| (...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1975 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); | 1975 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); |
| 1976 } | 1976 } |
| 1977 | 1977 |
| 1978 TEST(SchedulerStateMachineTest, EarlyOutCommitWantsProactiveBeginFrame) { | 1978 TEST(SchedulerStateMachineTest, EarlyOutCommitWantsProactiveBeginFrame) { |
| 1979 SchedulerSettings settings; | 1979 SchedulerSettings settings; |
| 1980 StateMachine state(settings); | 1980 StateMachine state(settings); |
| 1981 SET_UP_STATE(state); | 1981 SET_UP_STATE(state); |
| 1982 | 1982 |
| 1983 EXPECT_FALSE(state.ProactiveBeginFrameWanted()); | 1983 EXPECT_FALSE(state.ProactiveBeginFrameWanted()); |
| 1984 bool commit_has_no_updates = true; | 1984 bool commit_has_no_updates = true; |
| 1985 state.UpdateStateOnCommit(commit_has_no_updates); | 1985 state.WillCommit(commit_has_no_updates); |
| 1986 EXPECT_TRUE(state.ProactiveBeginFrameWanted()); | 1986 EXPECT_TRUE(state.ProactiveBeginFrameWanted()); |
| 1987 state.OnBeginImplFrame(); | 1987 state.OnBeginImplFrame(); |
| 1988 EXPECT_FALSE(state.ProactiveBeginFrameWanted()); | 1988 EXPECT_FALSE(state.ProactiveBeginFrameWanted()); |
| 1989 } | 1989 } |
| 1990 | 1990 |
| 1991 } // namespace | 1991 } // namespace |
| 1992 } // namespace cc | 1992 } // namespace cc |
| OLD | NEW |