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

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

Issue 2339633003: Reland of cc: Remove frame queuing from the scheduler. (Closed)
Patch Set: prevent draw if commit is pending Created 4 years, 3 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
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 <stddef.h> 7 #include <stddef.h>
8 8
9 #include "base/trace_event/trace_event.h" 9 #include "base/trace_event/trace_event.h"
10 #include "cc/scheduler/scheduler.h" 10 #include "cc/scheduler/scheduler.h"
(...skipping 17 matching lines...) Expand all
28 << state.AsValue()->ToString() 28 << state.AsValue()->ToString()
29 29
30 #define EXPECT_MAIN_FRAME_STATE(expected) \ 30 #define EXPECT_MAIN_FRAME_STATE(expected) \
31 EXPECT_ENUM_EQ(BeginMainFrameStateToString, expected, \ 31 EXPECT_ENUM_EQ(BeginMainFrameStateToString, expected, \
32 state.BeginMainFrameState()) 32 state.BeginMainFrameState())
33 33
34 #define EXPECT_ACTION(expected) \ 34 #define EXPECT_ACTION(expected) \
35 EXPECT_ENUM_EQ(ActionToString, expected, state.NextAction()) \ 35 EXPECT_ENUM_EQ(ActionToString, expected, state.NextAction()) \
36 << state.AsValue()->ToString() 36 << state.AsValue()->ToString()
37 37
38 #define EXPECT_ACTION_UPDATE_STATE(action) \ 38 #define EXPECT_ACTION_UPDATE_STATE(action) \
39 EXPECT_ACTION(action); \ 39 EXPECT_ACTION(action); \
40 if (action == SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE || \ 40 if (action == SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE || \
41 action == SchedulerStateMachine::ACTION_DRAW_AND_SWAP_FORCED) { \ 41 action == SchedulerStateMachine::ACTION_DRAW_AND_SWAP_FORCED) { \
42 EXPECT_IMPL_FRAME_STATE( \ 42 EXPECT_IMPL_FRAME_STATE( \
43 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE); \ 43 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE); \
44 } \ 44 } \
45 PerformAction(&state, action); \ 45 PerformAction(&state, action); \
46 if (action == SchedulerStateMachine::ACTION_NONE) { \ 46 if (action == SchedulerStateMachine::ACTION_NONE) { \
47 if (state.begin_impl_frame_state() == \ 47 if (state.begin_impl_frame_state() == \
48 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE) \ 48 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE) \
49 state.OnBeginImplFrameIdle(); \ 49 state.OnBeginImplFrameIdle(); \
50 } 50 }
51 51
52 #define SET_UP_STATE(state) \ 52 #define SET_UP_STATE(state) \
53 state.SetVisible(true); \ 53 state.SetVisible(true); \
54 EXPECT_ACTION_UPDATE_STATE( \ 54 EXPECT_ACTION_UPDATE_STATE( \
55 SchedulerStateMachine::ACTION_BEGIN_COMPOSITOR_FRAME_SINK_CREATION); \ 55 SchedulerStateMachine::ACTION_BEGIN_COMPOSITOR_FRAME_SINK_CREATION); \
56 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); \ 56 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); \
57 state.CreateAndInitializeCompositorFrameSinkWithActivatedCommit(); \ 57 state.CreateAndInitializeCompositorFrameSinkWithActivatedCommit(); \
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 {
66 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_BEGIN_FRAME, 66 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE,
67 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE, }; 67 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_BEGIN_FRAME,
68 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE,
69 };
68 70
69 const SchedulerStateMachine::BeginMainFrameState begin_main_frame_states[] = { 71 const SchedulerStateMachine::BeginMainFrameState begin_main_frame_states[] = {
70 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_IDLE, 72 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_IDLE,
71 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_SENT, 73 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_SENT,
72 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_STARTED, 74 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_STARTED,
73 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_READY_TO_COMMIT, 75 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_READY_TO_COMMIT};
74 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_WAITING_FOR_ACTIVATION,
75 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_WAITING_FOR_DRAW};
76 76
77 // Exposes the protected state fields of the SchedulerStateMachine for testing 77 // Exposes the protected state fields of the SchedulerStateMachine for testing
78 class StateMachine : public SchedulerStateMachine { 78 class StateMachine : public SchedulerStateMachine {
79 public: 79 public:
80 explicit StateMachine(const SchedulerSettings& scheduler_settings) 80 explicit StateMachine(const SchedulerSettings& scheduler_settings)
81 : SchedulerStateMachine(scheduler_settings), 81 : SchedulerStateMachine(scheduler_settings),
82 draw_result_for_test_(DRAW_SUCCESS) {} 82 draw_result_for_test_(DRAW_SUCCESS) {}
83 83
84 void CreateAndInitializeCompositorFrameSinkWithActivatedCommit() { 84 void CreateAndInitializeCompositorFrameSinkWithActivatedCommit() {
85 DidCreateAndInitializeCompositorFrameSink(); 85 DidCreateAndInitializeCompositorFrameSink();
(...skipping 1019 matching lines...) Expand 10 before | Expand all | Expand 10 after
1105 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 1105 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
1106 EXPECT_MAIN_FRAME_STATE(SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_SENT); 1106 EXPECT_MAIN_FRAME_STATE(SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_SENT);
1107 EXPECT_FALSE(state.NeedsCommit()); 1107 EXPECT_FALSE(state.NeedsCommit());
1108 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1108 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1109 1109
1110 // Tell the scheduler the frame finished. 1110 // Tell the scheduler the frame finished.
1111 state.NotifyBeginMainFrameStarted(); 1111 state.NotifyBeginMainFrameStarted();
1112 state.NotifyReadyToCommit(); 1112 state.NotifyReadyToCommit();
1113 EXPECT_MAIN_FRAME_STATE( 1113 EXPECT_MAIN_FRAME_STATE(
1114 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_READY_TO_COMMIT); 1114 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_READY_TO_COMMIT);
1115
1116 // Commit. 1115 // Commit.
1117 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 1116 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
1117 // Commit always calls NotifyReadyToActivate in this mode.
1118 state.NotifyReadyToActivate();
1119 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE);
1120 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1118 1121
1119 // Now commit should wait for activation. 1122 // No draw because we haven't received NotifyReadyToDraw yet.
1120 EXPECT_MAIN_FRAME_STATE( 1123 state.OnBeginImplFrameDeadline();
1121 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_WAITING_FOR_ACTIVATION); 1124 EXPECT_TRUE(state.active_tree_needs_first_draw());
1125 EXPECT_TRUE(state.needs_redraw());
1126 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1122 1127
1123 // No activation yet, so this commit is not drawn yet. Force to draw this 1128 // Can't BeginMainFrame yet since last commit hasn't been drawn yet.
1124 // frame, and still block BeginMainFrame.
1125 state.SetNeedsRedraw(true);
1126 state.SetNeedsBeginMainFrame(); 1129 state.SetNeedsBeginMainFrame();
1130 state.OnBeginImplFrame();
1131 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1132
1133 // Now call ready to draw which will allow the draw to happen and
1134 // BeginMainFrame to be sent.
1135 state.NotifyReadyToDraw();
1136 state.OnBeginImplFrameDeadline();
1137 EXPECT_ACTION_UPDATE_STATE(
1138 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
1139 // Swap throttled from this point.
1140 state.DidSwapBuffers();
1141 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1142
1143 // Can't BeginMainFrame yet since we're swap throttled.
1144 state.OnBeginImplFrame();
1145 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1146
1147 // Swap ack unblocks BeginMainFrame.
1148 state.DidSwapBuffersComplete();
1149 EXPECT_ACTION_UPDATE_STATE(
1150 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
1151 state.NotifyBeginMainFrameStarted();
1152 state.NotifyReadyToCommit();
1153 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
1154 state.NotifyReadyToActivate();
1155 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE);
1156 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1157
1158 // Draw the newly activated tree.
1159 state.NotifyReadyToDraw();
1127 state.OnBeginImplFrameDeadline(); 1160 state.OnBeginImplFrameDeadline();
1128 EXPECT_ACTION_UPDATE_STATE( 1161 EXPECT_ACTION_UPDATE_STATE(
1129 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 1162 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
1130 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1163 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1131
1132 // Cannot BeginMainFrame yet since last commit is not yet activated and drawn.
1133 state.OnBeginImplFrame();
1134 EXPECT_MAIN_FRAME_STATE(
1135 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_WAITING_FOR_ACTIVATION);
1136 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1137
1138 // Now activate sync tree.
1139 state.NotifyReadyToActivate();
1140 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE);
1141 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1142 EXPECT_TRUE(state.active_tree_needs_first_draw());
1143 EXPECT_TRUE(state.needs_redraw());
1144 EXPECT_MAIN_FRAME_STATE(
1145 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_WAITING_FOR_DRAW);
1146
1147 // Swap throttled. Do not draw.
1148 state.DidSwapBuffers();
1149 state.OnBeginImplFrameDeadline();
1150 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1151 state.DidSwapBuffersComplete();
1152
1153 // Haven't draw since last commit, do not begin new main frame.
1154 state.OnBeginImplFrame();
1155 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1156
1157 // At BeginImplFrame deadline, draw. This draws unblocks BeginMainFrame.
1158 state.OnBeginImplFrameDeadline();
1159 EXPECT_ACTION_UPDATE_STATE(
1160 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
1161 state.DidSwapBuffers();
1162 state.DidSwapBuffersComplete();
1163
1164 // Now will be able to start main frame.
1165 EXPECT_MAIN_FRAME_STATE(SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_IDLE);
1166 EXPECT_FALSE(state.needs_redraw());
1167 EXPECT_ACTION_UPDATE_STATE(
1168 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
1169 } 1164 }
1170 1165
1171 TEST(SchedulerStateMachineTest, TestFullCycleWithCommitRequestInbetween) { 1166 TEST(SchedulerStateMachineTest, TestFullCycleWithCommitRequestInbetween) {
1172 SchedulerSettings default_scheduler_settings; 1167 SchedulerSettings default_scheduler_settings;
1173 StateMachine state(default_scheduler_settings); 1168 StateMachine state(default_scheduler_settings);
1174 SET_UP_STATE(state) 1169 SET_UP_STATE(state)
1175 1170
1176 // Start clean and set commit. 1171 // Start clean and set commit.
1177 state.SetNeedsBeginMainFrame(); 1172 state.SetNeedsBeginMainFrame();
1178 1173
(...skipping 997 matching lines...) Expand 10 before | Expand all | Expand 10 after
2176 state.OnBeginImplFrameDeadline(); 2171 state.OnBeginImplFrameDeadline();
2177 state.OnBeginImplFrameIdle(); 2172 state.OnBeginImplFrameIdle();
2178 2173
2179 // The scheduler should begin the CompositorFrameSink creation now. 2174 // The scheduler should begin the CompositorFrameSink creation now.
2180 EXPECT_ACTION_UPDATE_STATE( 2175 EXPECT_ACTION_UPDATE_STATE(
2181 SchedulerStateMachine::ACTION_BEGIN_COMPOSITOR_FRAME_SINK_CREATION); 2176 SchedulerStateMachine::ACTION_BEGIN_COMPOSITOR_FRAME_SINK_CREATION);
2182 } 2177 }
2183 2178
2184 } // namespace 2179 } // namespace
2185 } // namespace cc 2180 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698