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

Side by Side Diff: cc/scheduler/scheduler_state_machine.h

Issue 23796002: cc: Implement deadine scheduling disabled by default (Closed) Base URL: http://git.chromium.org/chromium/src.git@schedReadback4
Patch Set: address enne's comments Created 7 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 #ifndef CC_SCHEDULER_SCHEDULER_STATE_MACHINE_H_ 5 #ifndef CC_SCHEDULER_SCHEDULER_STATE_MACHINE_H_
6 #define CC_SCHEDULER_SCHEDULER_STATE_MACHINE_H_ 6 #define CC_SCHEDULER_SCHEDULER_STATE_MACHINE_H_
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
(...skipping 27 matching lines...) Expand all
38 38
39 enum OutputSurfaceState { 39 enum OutputSurfaceState {
40 OUTPUT_SURFACE_ACTIVE, 40 OUTPUT_SURFACE_ACTIVE,
41 OUTPUT_SURFACE_LOST, 41 OUTPUT_SURFACE_LOST,
42 OUTPUT_SURFACE_CREATING, 42 OUTPUT_SURFACE_CREATING,
43 OUTPUT_SURFACE_WAITING_FOR_FIRST_COMMIT, 43 OUTPUT_SURFACE_WAITING_FOR_FIRST_COMMIT,
44 OUTPUT_SURFACE_WAITING_FOR_FIRST_ACTIVATION, 44 OUTPUT_SURFACE_WAITING_FOR_FIRST_ACTIVATION,
45 }; 45 };
46 static const char* OutputSurfaceStateToString(OutputSurfaceState state); 46 static const char* OutputSurfaceStateToString(OutputSurfaceState state);
47 47
48 // Note: BeginFrameState will always cycle through all the states in order.
49 // Whether or not it actually waits or draws, it will at least try to wait in
50 // BEGIN_FRAME_STATE_DEADLINE_PENDING and try to draw in
51 // BEGIN_FRAME_STATE_INSIDE_DEADLINE
52 enum BeginFrameState {
53 BEGIN_FRAME_STATE_IDLE,
54 BEGIN_FRAME_STATE_INSIDE_BEGIN_FRAME,
55 BEGIN_FRAME_STATE_DEADLINE_PENDING,
56 BEGIN_FRAME_STATE_INSIDE_DEADLINE,
57 };
58 static const char* BeginFrameStateToString(BeginFrameState state);
59
48 enum CommitState { 60 enum CommitState {
49 COMMIT_STATE_IDLE, 61 COMMIT_STATE_IDLE,
50 COMMIT_STATE_FRAME_IN_PROGRESS, 62 COMMIT_STATE_FRAME_IN_PROGRESS,
51 COMMIT_STATE_READY_TO_COMMIT, 63 COMMIT_STATE_READY_TO_COMMIT,
52 COMMIT_STATE_WAITING_FOR_FIRST_DRAW, 64 COMMIT_STATE_WAITING_FOR_FIRST_DRAW,
53 }; 65 };
54 static const char* CommitStateToString(CommitState state); 66 static const char* CommitStateToString(CommitState state);
55 67
56 enum TextureState { 68 enum TextureState {
57 LAYER_TEXTURE_STATE_UNLOCKED, 69 LAYER_TEXTURE_STATE_UNLOCKED,
(...skipping 17 matching lines...) Expand all
75 enum ForcedRedrawOnTimeoutState { 87 enum ForcedRedrawOnTimeoutState {
76 FORCED_REDRAW_STATE_IDLE, 88 FORCED_REDRAW_STATE_IDLE,
77 FORCED_REDRAW_STATE_WAITING_FOR_COMMIT, 89 FORCED_REDRAW_STATE_WAITING_FOR_COMMIT,
78 FORCED_REDRAW_STATE_WAITING_FOR_ACTIVATION, 90 FORCED_REDRAW_STATE_WAITING_FOR_ACTIVATION,
79 FORCED_REDRAW_STATE_WAITING_FOR_DRAW, 91 FORCED_REDRAW_STATE_WAITING_FOR_DRAW,
80 }; 92 };
81 static const char* ForcedRedrawOnTimeoutStateToString( 93 static const char* ForcedRedrawOnTimeoutStateToString(
82 ForcedRedrawOnTimeoutState state); 94 ForcedRedrawOnTimeoutState state);
83 95
84 bool CommitPending() const { 96 bool CommitPending() const {
85 return commit_state_ == COMMIT_STATE_FRAME_IN_PROGRESS || 97 return commit_state_ == COMMIT_STATE_FRAME_IN_PROGRESS;
86 commit_state_ == COMMIT_STATE_READY_TO_COMMIT;
87 } 98 }
88 99
89 bool RedrawPending() const { return needs_redraw_; } 100 bool RedrawPending() const { return needs_redraw_; }
90 101
91 enum Action { 102 enum Action {
92 ACTION_NONE, 103 ACTION_NONE,
93 ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD, 104 ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD,
94 ACTION_COMMIT, 105 ACTION_COMMIT,
95 ACTION_UPDATE_VISIBLE_TILES, 106 ACTION_UPDATE_VISIBLE_TILES,
96 ACTION_ACTIVATE_PENDING_TREE, 107 ACTION_ACTIVATE_PENDING_TREE,
97 ACTION_DRAW_AND_SWAP_IF_POSSIBLE, 108 ACTION_DRAW_AND_SWAP_IF_POSSIBLE,
98 ACTION_DRAW_AND_SWAP_FORCED, 109 ACTION_DRAW_AND_SWAP_FORCED,
99 ACTION_DRAW_AND_SWAP_ABORT, 110 ACTION_DRAW_AND_SWAP_ABORT,
100 ACTION_DRAW_AND_READBACK, 111 ACTION_DRAW_AND_READBACK,
101 ACTION_BEGIN_OUTPUT_SURFACE_CREATION, 112 ACTION_BEGIN_OUTPUT_SURFACE_CREATION,
102 ACTION_ACQUIRE_LAYER_TEXTURES_FOR_MAIN_THREAD, 113 ACTION_ACQUIRE_LAYER_TEXTURES_FOR_MAIN_THREAD,
103 }; 114 };
104 static const char* ActionToString(Action action); 115 static const char* ActionToString(Action action);
105 116
106 scoped_ptr<base::Value> AsValue() const; 117 scoped_ptr<base::Value> AsValue() const;
107 118
108 Action NextAction() const; 119 Action NextAction() const;
109 void UpdateState(Action action); 120 void UpdateState(Action action);
121
110 void CheckInvariants(); 122 void CheckInvariants();
111 123
112 // Indicates whether the main thread needs a begin frame callback in order to 124 // Indicates whether the main thread needs a begin frame callback in order to
113 // make progress. 125 // make progress.
114 bool BeginFrameNeededToDrawByImplThread() const; 126 bool BeginFrameNeededByImplThread() const;
115 bool ProactiveBeginFrameWantedByImplThread() const; 127
128 // Idicates that we need to independently poll for new state and actions
129 // because we can't expect a BeginFrame. This is mostly used to avoid
130 // drawing repeat frames with the synchronous compositor without dropping
131 // necessary actions on the floor.
132 bool ShouldPollForAnticipatedDrawTriggers() const;
116 133
117 // Indicates that the system has entered and left a BeginFrame callback. 134 // Indicates that the system has entered and left a BeginFrame callback.
118 // The scheduler will not draw more than once in a given BeginFrame 135 // The scheduler will not draw more than once in a given BeginFrame
119 // callback nor send more than one BeginFrame message. 136 // callback nor send more than one BeginFrame message.
120 void DidEnterBeginFrame(const BeginFrameArgs& args); 137 void OnBeginFrame(const BeginFrameArgs& args);
121 void DidLeaveBeginFrame(); 138 void OnBeginFrameDeadlinePending();
122 bool inside_begin_frame() const { return inside_begin_frame_; } 139 void OnBeginFrameDeadline();
140 void OnBeginFrameIdle();
141 bool ShouldTriggerBeginFrameDeadlineEarly() const;
142 BeginFrameState begin_frame_state() const {
143 return begin_frame_state_;
144 }
123 145
124 // PollForAnticipatedDrawTriggers is used by the synchronous compositor to 146 // PollForAnticipatedDrawTriggers is used by the synchronous compositor to
125 // avoid requesting BeginImplFrames when we won't actually draw but still 147 // avoid requesting BeginImplFrames when we won't actually draw but still
126 // need to advance our state at vsync intervals. 148 // need to advance our state at vsync intervals.
127 void PollForAnticipatedDrawTriggers(); 149 void PollForAnticipatedDrawTriggers();
128 150
129 // Indicates whether the LayerTreeHostImpl is visible. 151 // Indicates whether the LayerTreeHostImpl is visible.
130 void SetVisible(bool visible); 152 void SetVisible(bool visible);
131 153
132 // Indicates that a redraw is required, either due to the impl tree changing 154 // Indicates that a redraw is required, either due to the impl tree changing
133 // or the screen being damaged and simply needing redisplay. 155 // or the screen being damaged and simply needing redisplay.
134 void SetNeedsRedraw(); 156 void SetNeedsRedraw();
157 bool needs_redraw() const { return needs_redraw_; }
135 158
136 // Indicates whether a redraw is required because we are currently rendering 159 // Indicates whether a redraw is required because we are currently rendering
137 // with a low resolution or checkerboarded tile. 160 // with a low resolution or checkerboarded tile.
138 void SetSwapUsedIncompleteTile(bool used_incomplete_tile); 161 void SetSwapUsedIncompleteTile(bool used_incomplete_tile);
139 162
140 // Indicates whether ACTION_DRAW_AND_SWAP_IF_POSSIBLE drew to the screen or 163 // Indicates whether ACTION_DRAW_AND_SWAP_IF_POSSIBLE drew to the screen.
141 // not.
142 void DidDrawIfPossibleCompleted(bool success); 164 void DidDrawIfPossibleCompleted(bool success);
143 165
144 // Indicates that a new commit flow needs to be performed, either to pull 166 // Indicates that a new commit flow needs to be performed, either to pull
145 // updates from the main thread to the impl, or to push deltas from the impl 167 // updates from the main thread to the impl, or to push deltas from the impl
146 // thread to main. 168 // thread to main.
147 void SetNeedsCommit(); 169 void SetNeedsCommit();
148 170
149 // As SetNeedsCommit(), but ensures the begin frame will be sent to the main 171 // As SetNeedsCommit(), but ensures the begin frame will be sent to the main
150 // thread even if we are not visible. After this call we expect to go through 172 // thread even if we are not visible. After this call we expect to go through
151 // the forced commit flow and then return to waiting for a non-forced 173 // the forced commit flow and then return to waiting for a non-forced
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 bool has_pending_tree() const { return has_pending_tree_; } 206 bool has_pending_tree() const { return has_pending_tree_; }
185 207
186 void DidLoseOutputSurface(); 208 void DidLoseOutputSurface();
187 void DidCreateAndInitializeOutputSurface(); 209 void DidCreateAndInitializeOutputSurface();
188 bool HasInitializedOutputSurface() const; 210 bool HasInitializedOutputSurface() const;
189 211
190 // True if we need to abort draws to make forward progress. 212 // True if we need to abort draws to make forward progress.
191 bool PendingDrawsShouldBeAborted() const; 213 bool PendingDrawsShouldBeAborted() const;
192 214
193 protected: 215 protected:
216 bool BeginFrameNeededToDrawByImplThread() const;
217 bool ProactiveBeginFrameWantedByImplThread() const;
218
194 // True if we need to force activations to make forward progress. 219 // True if we need to force activations to make forward progress.
195 bool PendingActivationsShouldBeForced() const; 220 bool PendingActivationsShouldBeForced() const;
196 221
197 bool ShouldBeginOutputSurfaceCreation() const; 222 bool ShouldBeginOutputSurfaceCreation() const;
198 bool ShouldDrawForced() const; 223 bool ShouldDrawForced() const;
199 bool ShouldDraw() const; 224 bool ShouldDraw() const;
200 bool ShouldActivatePendingTree() const; 225 bool ShouldActivatePendingTree() const;
201 bool ShouldAcquireLayerTexturesForMainThread() const; 226 bool ShouldAcquireLayerTexturesForMainThread() const;
202 bool ShouldUpdateVisibleTiles() const; 227 bool ShouldUpdateVisibleTiles() const;
203 bool ShouldSendBeginFrameToMainThread() const; 228 bool ShouldSendBeginFrameToMainThread() const;
204 bool ShouldCommit() const; 229 bool ShouldCommit() const;
205 230
206 bool HasDrawnAndSwappedThisFrame() const; 231 bool HasSentBeginFrameToMainThreadThisFrame() const;
207 bool HasActivatedPendingTreeThisFrame() const;
208 bool HasUpdatedVisibleTilesThisFrame() const; 232 bool HasUpdatedVisibleTilesThisFrame() const;
209 bool HasSentBeginFrameToMainThreadThisFrame() const; 233 bool HasSwappedThisFrame() const;
210 234
211 void UpdateStateOnCommit(bool commit_was_aborted); 235 void UpdateStateOnCommit(bool commit_was_aborted);
212 void UpdateStateOnActivation(); 236 void UpdateStateOnActivation();
213 void UpdateStateOnDraw(bool did_swap); 237 void UpdateStateOnDraw(bool did_swap);
214 238
215 const SchedulerSettings settings_; 239 const SchedulerSettings settings_;
216 240
217 OutputSurfaceState output_surface_state_; 241 OutputSurfaceState output_surface_state_;
242 BeginFrameState begin_frame_state_;
218 CommitState commit_state_; 243 CommitState commit_state_;
219 TextureState texture_state_; 244 TextureState texture_state_;
220 ForcedRedrawOnTimeoutState forced_redraw_state_; 245 ForcedRedrawOnTimeoutState forced_redraw_state_;
221 SynchronousReadbackState readback_state_; 246 SynchronousReadbackState readback_state_;
222 247
248 BeginFrameArgs last_begin_frame_args_;
249
223 int commit_count_; 250 int commit_count_;
224 int current_frame_number_; 251 int current_frame_number_;
225 int last_frame_number_where_begin_frame_sent_to_main_thread_;
226 int last_frame_number_swap_performed_; 252 int last_frame_number_swap_performed_;
227 int last_frame_number_where_update_visible_tiles_was_called_; 253 int last_frame_number_begin_frame_sent_to_main_thread_;
254 int last_frame_number_update_visible_tiles_was_called_;
255
228 int consecutive_failed_draws_; 256 int consecutive_failed_draws_;
229 bool needs_redraw_; 257 bool needs_redraw_;
230 bool swap_used_incomplete_tile_; 258 bool swap_used_incomplete_tile_;
231 bool needs_commit_; 259 bool needs_commit_;
232 bool main_thread_needs_layer_textures_; 260 bool main_thread_needs_layer_textures_;
233 bool inside_begin_frame_;
234 BeginFrameArgs last_begin_frame_args_;
235 bool visible_; 261 bool visible_;
236 bool can_start_; 262 bool can_start_;
237 bool can_draw_; 263 bool can_draw_;
238 bool has_pending_tree_; 264 bool has_pending_tree_;
239 bool pending_tree_is_ready_for_activation_; 265 bool pending_tree_is_ready_for_activation_;
240 bool active_tree_needs_first_draw_; 266 bool active_tree_needs_first_draw_;
241 bool draw_if_possible_failed_; 267 bool draw_if_possible_failed_;
242 bool did_create_and_initialize_first_output_surface_; 268 bool did_create_and_initialize_first_output_surface_;
243 269
244 private: 270 private:
245 DISALLOW_COPY_AND_ASSIGN(SchedulerStateMachine); 271 DISALLOW_COPY_AND_ASSIGN(SchedulerStateMachine);
246 }; 272 };
247 273
248 } // namespace cc 274 } // namespace cc
249 275
250 #endif // CC_SCHEDULER_SCHEDULER_STATE_MACHINE_H_ 276 #endif // CC_SCHEDULER_SCHEDULER_STATE_MACHINE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698