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

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 dana's commetns 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_INSIDE_BEGIN_FRAME and try to draw in
51 // BEGIN_FRAME_STATE_INSIDE_DEADLINE
52 enum BeginFrameState {
53 BEGIN_FRAME_STATE_IDLE,
54 BEGIN_FRAME_STATE_BEGIN_FRAME_STARTING,
55 BEGIN_FRAME_STATE_INSIDE_BEGIN_FRAME,
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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 ACTION_BEGIN_OUTPUT_SURFACE_CREATION, 114 ACTION_BEGIN_OUTPUT_SURFACE_CREATION,
103 ACTION_ACQUIRE_LAYER_TEXTURES_FOR_MAIN_THREAD, 115 ACTION_ACQUIRE_LAYER_TEXTURES_FOR_MAIN_THREAD,
104 ACTION_MANAGE_TILES, 116 ACTION_MANAGE_TILES,
105 }; 117 };
106 static const char* ActionToString(Action action); 118 static const char* ActionToString(Action action);
107 119
108 scoped_ptr<base::Value> AsValue() const; 120 scoped_ptr<base::Value> AsValue() const;
109 121
110 Action NextAction() const; 122 Action NextAction() const;
111 void UpdateState(Action action); 123 void UpdateState(Action action);
124
112 void CheckInvariants(); 125 void CheckInvariants();
113 126
114 // Indicates whether the main thread needs a begin frame callback in order to 127 // Indicates whether the main thread needs a begin frame callback in order to
115 // make progress. 128 // make progress.
116 bool BeginFrameNeededToDrawByImplThread() const; 129 bool BeginFrameNeededByImplThread() const;
117 bool ProactiveBeginFrameWantedByImplThread() const; 130
131 // Idicates that we need to independently poll for new state and actions
132 // because we can't expect a BeginFrame. This is mostly used to avoid
133 // drawing repeat frames with the synchronous compositor without dropping
134 // necessary actions on the floor.
135 bool ShouldPollForAnticipatedDrawTriggers() const;
118 136
119 // Indicates that the system has entered and left a BeginFrame callback. 137 // Indicates that the system has entered and left a BeginFrame callback.
120 // The scheduler will not draw more than once in a given BeginFrame 138 // The scheduler will not draw more than once in a given BeginFrame
121 // callback nor send more than one BeginFrame message. 139 // callback nor send more than one BeginFrame message.
122 void DidEnterBeginFrame(const BeginFrameArgs& args); 140 void OnBeginFrame(const BeginFrameArgs& args);
123 void DidLeaveBeginFrame(); 141 void OnBeginFrameDeadlinePending();
124 bool inside_begin_frame() const { return inside_begin_frame_; } 142 void OnBeginFrameDeadline();
143 void OnBeginFrameIdle();
144 bool ShouldTriggerBeginFrameDeadlineEarly() const;
145 BeginFrameState begin_frame_state() const {
146 return begin_frame_state_;
147 }
125 148
126 // PollForAnticipatedDrawTriggers is used by the synchronous compositor to 149 // PollForAnticipatedDrawTriggers is used by the synchronous compositor to
127 // avoid requesting BeginImplFrames when we won't actually draw but still 150 // avoid requesting BeginImplFrames when we won't actually draw but still
128 // need to advance our state at vsync intervals. 151 // need to advance our state at vsync intervals.
129 void DidEnterPollForAnticipatedDrawTriggers(); 152 void DidEnterPollForAnticipatedDrawTriggers();
130 void DidLeavePollForAnticipatedDrawTriggers(); 153 void DidLeavePollForAnticipatedDrawTriggers();
131 bool inside_poll_for_anticipated_draw_triggers() const { 154 bool inside_poll_for_anticipated_draw_triggers() const {
132 return inside_poll_for_anticipated_draw_triggers_; 155 return inside_poll_for_anticipated_draw_triggers_;
133 } 156 }
134 157
135 // Indicates whether the LayerTreeHostImpl is visible. 158 // Indicates whether the LayerTreeHostImpl is visible.
136 void SetVisible(bool visible); 159 void SetVisible(bool visible);
137 160
138 // Indicates that a redraw is required, either due to the impl tree changing 161 // Indicates that a redraw is required, either due to the impl tree changing
139 // or the screen being damaged and simply needing redisplay. 162 // or the screen being damaged and simply needing redisplay.
140 void SetNeedsRedraw(); 163 void SetNeedsRedraw();
164 bool needs_redraw() const { return needs_redraw_; }
141 165
142 // Indicates that manage-tiles is required. This guarantees another 166 // Indicates that manage-tiles is required. This guarantees another
143 // ManageTiles will occur shortly (even if no redraw is required). 167 // ManageTiles will occur shortly (even if no redraw is required).
144 void SetNeedsManageTiles(); 168 void SetNeedsManageTiles();
145 169
146 // Indicates whether a redraw is required because we are currently rendering 170 // Indicates whether a redraw is required because we are currently rendering
147 // with a low resolution or checkerboarded tile. 171 // with a low resolution or checkerboarded tile.
148 void SetSwapUsedIncompleteTile(bool used_incomplete_tile); 172 void SetSwapUsedIncompleteTile(bool used_incomplete_tile);
149 173
150 // Indicates whether ACTION_DRAW_AND_SWAP_IF_POSSIBLE drew to the screen or 174 // Indicates whether ACTION_DRAW_AND_SWAP_IF_POSSIBLE drew to the screen.
151 // not.
152 void DidDrawIfPossibleCompleted(bool success); 175 void DidDrawIfPossibleCompleted(bool success);
153 176
154 // Indicates that a new commit flow needs to be performed, either to pull 177 // Indicates that a new commit flow needs to be performed, either to pull
155 // updates from the main thread to the impl, or to push deltas from the impl 178 // updates from the main thread to the impl, or to push deltas from the impl
156 // thread to main. 179 // thread to main.
157 void SetNeedsCommit(); 180 void SetNeedsCommit();
158 181
159 // As SetNeedsCommit(), but ensures the begin frame will be sent to the main 182 // As SetNeedsCommit(), but ensures the begin frame will be sent to the main
160 // thread even if we are not visible. After this call we expect to go through 183 // thread even if we are not visible. After this call we expect to go through
161 // the forced commit flow and then return to waiting for a non-forced 184 // 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
194 bool has_pending_tree() const { return has_pending_tree_; } 217 bool has_pending_tree() const { return has_pending_tree_; }
195 218
196 void DidLoseOutputSurface(); 219 void DidLoseOutputSurface();
197 void DidCreateAndInitializeOutputSurface(); 220 void DidCreateAndInitializeOutputSurface();
198 bool HasInitializedOutputSurface() const; 221 bool HasInitializedOutputSurface() const;
199 222
200 // True if we need to abort draws to make forward progress. 223 // True if we need to abort draws to make forward progress.
201 bool PendingDrawsShouldBeAborted() const; 224 bool PendingDrawsShouldBeAborted() const;
202 225
203 protected: 226 protected:
227 bool BeginFrameNeededToDrawByImplThread() const;
228 bool ProactiveBeginFrameWantedByImplThread() const;
229
204 // True if we need to force activations to make forward progress. 230 // True if we need to force activations to make forward progress.
205 bool PendingActivationsShouldBeForced() const; 231 bool PendingActivationsShouldBeForced() const;
206 232
207 bool ShouldBeginOutputSurfaceCreation() const; 233 bool ShouldBeginOutputSurfaceCreation() const;
208 bool ShouldDrawForced() const; 234 bool ShouldDrawForced() const;
209 bool ShouldDraw() const; 235 bool ShouldDraw() const;
210 bool ShouldActivatePendingTree() const; 236 bool ShouldActivatePendingTree() const;
211 bool ShouldAcquireLayerTexturesForMainThread() const; 237 bool ShouldAcquireLayerTexturesForMainThread() const;
212 bool ShouldUpdateVisibleTiles() const; 238 bool ShouldUpdateVisibleTiles() const;
213 bool ShouldSendBeginFrameToMainThread() const; 239 bool ShouldSendBeginFrameToMainThread() const;
214 bool ShouldCommit() const; 240 bool ShouldCommit() const;
215 bool ShouldManageTiles() const; 241 bool ShouldManageTiles() const;
216 242
217 bool HasDrawnAndSwappedThisFrame() const;
218 bool HasActivatedPendingTreeThisFrame() const;
219 bool HasUpdatedVisibleTilesThisFrame() const;
220 bool HasSentBeginFrameToMainThreadThisFrame() const; 243 bool HasSentBeginFrameToMainThreadThisFrame() const;
221 bool HasScheduledManageTilesThisFrame() const; 244 bool HasScheduledManageTilesThisFrame() const;
245 bool HasUpdatedVisibleTilesThisFrame() const;
246 bool HasSwappedThisFrame() const;
222 247
223 void UpdateStateOnCommit(bool commit_was_aborted); 248 void UpdateStateOnCommit(bool commit_was_aborted);
224 void UpdateStateOnActivation(); 249 void UpdateStateOnActivation();
225 void UpdateStateOnDraw(bool did_swap); 250 void UpdateStateOnDraw(bool did_swap);
226 void UpdateStateOnManageTiles(); 251 void UpdateStateOnManageTiles();
227 252
228 const SchedulerSettings settings_; 253 const SchedulerSettings settings_;
229 254
230 OutputSurfaceState output_surface_state_; 255 OutputSurfaceState output_surface_state_;
256 BeginFrameState begin_frame_state_;
231 CommitState commit_state_; 257 CommitState commit_state_;
232 TextureState texture_state_; 258 TextureState texture_state_;
233 ForcedRedrawOnTimeoutState forced_redraw_state_; 259 ForcedRedrawOnTimeoutState forced_redraw_state_;
234 SynchronousReadbackState readback_state_; 260 SynchronousReadbackState readback_state_;
235 261
262 BeginFrameArgs last_begin_frame_args_;
263
236 int commit_count_; 264 int commit_count_;
237 int current_frame_number_; 265 int current_frame_number_;
238 int last_frame_number_where_begin_frame_sent_to_main_thread_;
239 int last_frame_number_swap_performed_; 266 int last_frame_number_swap_performed_;
240 int last_frame_number_where_update_visible_tiles_was_called_; 267 int last_frame_number_begin_frame_sent_to_main_thread_;
268 int last_frame_number_update_visible_tiles_was_called_;
269
241 int consecutive_failed_draws_; 270 int consecutive_failed_draws_;
242 bool needs_redraw_; 271 bool needs_redraw_;
243 bool needs_manage_tiles_; 272 bool needs_manage_tiles_;
244 bool swap_used_incomplete_tile_; 273 bool swap_used_incomplete_tile_;
245 bool needs_commit_; 274 bool needs_commit_;
246 bool main_thread_needs_layer_textures_; 275 bool main_thread_needs_layer_textures_;
247 bool inside_begin_frame_;
248 bool inside_poll_for_anticipated_draw_triggers_; 276 bool inside_poll_for_anticipated_draw_triggers_;
249
250 BeginFrameArgs last_begin_frame_args_;
251 bool visible_; 277 bool visible_;
252 bool can_start_; 278 bool can_start_;
253 bool can_draw_; 279 bool can_draw_;
254 bool has_pending_tree_; 280 bool has_pending_tree_;
255 bool pending_tree_is_ready_for_activation_; 281 bool pending_tree_is_ready_for_activation_;
256 bool active_tree_needs_first_draw_; 282 bool active_tree_needs_first_draw_;
257 bool draw_if_possible_failed_; 283 bool draw_if_possible_failed_;
258 bool did_create_and_initialize_first_output_surface_; 284 bool did_create_and_initialize_first_output_surface_;
259 285
260 private: 286 private:
261 DISALLOW_COPY_AND_ASSIGN(SchedulerStateMachine); 287 DISALLOW_COPY_AND_ASSIGN(SchedulerStateMachine);
262 }; 288 };
263 289
264 } // namespace cc 290 } // namespace cc
265 291
266 #endif // CC_SCHEDULER_SCHEDULER_STATE_MACHINE_H_ 292 #endif // CC_SCHEDULER_SCHEDULER_STATE_MACHINE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698