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

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

Issue 1131633003: cc: Use multiple PrepareTiles approaches Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 7 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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 BEGIN_IMPL_FRAME_STATE_INSIDE_BEGIN_FRAME, 60 BEGIN_IMPL_FRAME_STATE_INSIDE_BEGIN_FRAME,
61 BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE, 61 BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE,
62 }; 62 };
63 static const char* BeginImplFrameStateToString(BeginImplFrameState state); 63 static const char* BeginImplFrameStateToString(BeginImplFrameState state);
64 64
65 enum BeginImplFrameDeadlineMode { 65 enum BeginImplFrameDeadlineMode {
66 BEGIN_IMPL_FRAME_DEADLINE_MODE_NONE, 66 BEGIN_IMPL_FRAME_DEADLINE_MODE_NONE,
67 BEGIN_IMPL_FRAME_DEADLINE_MODE_IMMEDIATE, 67 BEGIN_IMPL_FRAME_DEADLINE_MODE_IMMEDIATE,
68 BEGIN_IMPL_FRAME_DEADLINE_MODE_REGULAR, 68 BEGIN_IMPL_FRAME_DEADLINE_MODE_REGULAR,
69 BEGIN_IMPL_FRAME_DEADLINE_MODE_LATE, 69 BEGIN_IMPL_FRAME_DEADLINE_MODE_LATE,
70 BEGIN_IMPL_FRAME_DEADLINE_MODE_TRY_TO_AVOID_CHECKERBOARD,
70 BEGIN_IMPL_FRAME_DEADLINE_MODE_BLOCKED_ON_READY_TO_DRAW, 71 BEGIN_IMPL_FRAME_DEADLINE_MODE_BLOCKED_ON_READY_TO_DRAW,
71 }; 72 };
72 static const char* BeginImplFrameDeadlineModeToString( 73 static const char* BeginImplFrameDeadlineModeToString(
73 BeginImplFrameDeadlineMode mode); 74 BeginImplFrameDeadlineMode mode);
74 75
75 enum CommitState { 76 enum CommitState {
76 COMMIT_STATE_IDLE, 77 COMMIT_STATE_IDLE,
77 COMMIT_STATE_BEGIN_MAIN_FRAME_SENT, 78 COMMIT_STATE_BEGIN_MAIN_FRAME_SENT,
78 COMMIT_STATE_BEGIN_MAIN_FRAME_STARTED, 79 COMMIT_STATE_BEGIN_MAIN_FRAME_STARTED,
79 COMMIT_STATE_READY_TO_COMMIT, 80 COMMIT_STATE_READY_TO_COMMIT,
80 COMMIT_STATE_WAITING_FOR_ACTIVATION, 81 COMMIT_STATE_WAITING_FOR_ACTIVATION,
81 COMMIT_STATE_WAITING_FOR_DRAW, 82 COMMIT_STATE_WAITING_FOR_DRAW,
82 }; 83 };
83 static const char* CommitStateToString(CommitState state); 84 static const char* CommitStateToString(CommitState state);
84 85
85 enum ForcedRedrawOnTimeoutState { 86 enum PrepareTilesApproach {
86 FORCED_REDRAW_STATE_IDLE, 87 // This approach calls PrepareTiles after every commit and after draws if
87 FORCED_REDRAW_STATE_WAITING_FOR_COMMIT, 88 // there wasn't a commit for that frame. With this approach, we cannot trust
88 FORCED_REDRAW_STATE_WAITING_FOR_ACTIVATION, 89 // NotifyReadyToActivate and NotifyReadyToDraw and they should only be used
89 FORCED_REDRAW_STATE_WAITING_FOR_DRAW, 90 // as hints. All other approaches have trustworthy NotifyReadyToActivate's
91 // and NotifyReadyToDraw's.
92 PREPARE_TILES_APPROACH_PRIORITIZE_LATENCY,
93 // This approach only calls PrepareTiles at the start of a frame so new
94 // active tree work starts ASAP, but the pending tree work doesn't.
95 PREPARE_TILES_APPROACH_ACCURATE_ACTIVE_WORK,
96 // This approach calls PrepareTiles at the start of every frame and after
97 // every commit so any new work starts ASAP.
98 PREPARE_TILES_APPROACH_ACCURATE_ACTIVE_PENDING_WORK,
99 // This approach calls PrepareTiles at the start of every frame, after every
100 // commit, and after every activation so any new or canceled work is
101 // reflected immediately.
102 PREPARE_TILES_APPROACH_ACCURATE_ACTIVE_PENDING_CANCELED_WORK,
90 }; 103 };
91 static const char* ForcedRedrawOnTimeoutStateToString( 104 static const char* PrepareTilesApproachToString(
92 ForcedRedrawOnTimeoutState state); 105 PrepareTilesApproach approach);
106
107 enum PrepareTilesReason {
108 PREPARE_TILES_NOT_NEEDED,
109 PREPARE_TILES_REQUESTED,
110 PREPARE_TILES_NEEDED_FOR_COMMIT,
111 PREPARE_TILES_NEEDED_FOR_ACTIVATION,
112 PREPARE_TILES_NEEDED_FOR_ABORTED_DRAW,
113 PREPARE_TILES_NEEDED_TO_EVICT_TILES,
114 };
115 static const char* PrepareTilesReasonToString(PrepareTilesReason reason);
93 116
94 bool CommitPending() const { 117 bool CommitPending() const {
95 return commit_state_ == COMMIT_STATE_BEGIN_MAIN_FRAME_SENT || 118 return commit_state_ == COMMIT_STATE_BEGIN_MAIN_FRAME_SENT ||
96 commit_state_ == COMMIT_STATE_BEGIN_MAIN_FRAME_STARTED || 119 commit_state_ == COMMIT_STATE_BEGIN_MAIN_FRAME_STARTED ||
97 commit_state_ == COMMIT_STATE_READY_TO_COMMIT; 120 commit_state_ == COMMIT_STATE_READY_TO_COMMIT;
98 } 121 }
99 CommitState commit_state() const { return commit_state_; } 122 CommitState commit_state() const { return commit_state_; }
100 123
101 bool RedrawPending() const { return needs_redraw_; } 124 bool RedrawPending() const { return needs_redraw_; }
102 bool PrepareTilesPending() const { return needs_prepare_tiles_; } 125 bool PrepareTilesPending() const {
126 return prepare_tiles_reason_ != PREPARE_TILES_NOT_NEEDED;
127 }
103 128
104 enum Action { 129 enum Action {
105 ACTION_NONE, 130 ACTION_NONE,
106 ACTION_ANIMATE, 131 ACTION_ANIMATE,
107 ACTION_SEND_BEGIN_MAIN_FRAME, 132 ACTION_SEND_BEGIN_MAIN_FRAME,
108 ACTION_COMMIT, 133 ACTION_COMMIT,
109 ACTION_ACTIVATE_SYNC_TREE, 134 ACTION_ACTIVATE_SYNC_TREE,
110 ACTION_DRAW_AND_SWAP_IF_POSSIBLE, 135 ACTION_DRAW_AND_SWAP_IF_POSSIBLE,
111 ACTION_DRAW_AND_SWAP_FORCED, 136 ACTION_DRAW_AND_SWAP_FORCED,
112 ACTION_DRAW_AND_SWAP_ABORT, 137 ACTION_DRAW_AND_SWAP_ABORT,
113 ACTION_BEGIN_OUTPUT_SURFACE_CREATION, 138 ACTION_BEGIN_OUTPUT_SURFACE_CREATION,
114 ACTION_PREPARE_TILES, 139 ACTION_PREPARE_TILES,
115 ACTION_INVALIDATE_OUTPUT_SURFACE, 140 ACTION_INVALIDATE_OUTPUT_SURFACE,
116 }; 141 };
117 static const char* ActionToString(Action action); 142 static const char* ActionToString(Action action);
118 143
119 scoped_refptr<base::trace_event::ConvertableToTraceFormat> AsValue() const; 144 scoped_refptr<base::trace_event::ConvertableToTraceFormat> AsValue() const;
120 void AsValueInto(base::trace_event::TracedValue* dict) const; 145 void AsValueInto(base::trace_event::TracedValue* dict) const;
121 146
122 Action NextAction() const; 147 Action NextAction() const;
123 void UpdateState(Action action); 148 void UpdateState(Action action);
124 149
125 // Indicates whether the impl thread needs a BeginImplFrame callback in order 150 // Indicates whether the impl thread needs a BeginImplFrame callback in order
126 // to make progress. 151 // to make progress.
127 bool BeginFrameNeeded() const; 152 bool BeginFrameNeeded() const;
128 153
154 // This reflects the actual state of the BeginFrameSource, not just whether
155 // the SchedulerStateMachine wants BeginFrames at this instance.
156 void NotifyBeginFrameSourceActive(bool active);
157
129 // Indicates that the system has entered and left a BeginImplFrame callback. 158 // Indicates that the system has entered and left a BeginImplFrame callback.
130 // The scheduler will not draw more than once in a given BeginImplFrame 159 // The scheduler will not draw more than once in a given BeginImplFrame
131 // callback nor send more than one BeginMainFrame message. 160 // callback nor send more than one BeginMainFrame message.
132 void OnBeginImplFrame(); 161 void OnBeginImplFrame();
133 void OnBeginImplFrameDeadlinePending(); 162 void OnBeginImplFrameDeadlinePending();
134 // Indicates that the scheduler has entered the draw phase. The scheduler 163 // Indicates that the scheduler has entered the draw phase. The scheduler
135 // will not draw more than once in a single draw phase. 164 // will not draw more than once in a single draw phase.
136 // TODO(sunnyps): Rename OnBeginImplFrameDeadline to OnDraw or similar. 165 // TODO(sunnyps): Rename OnBeginImplFrameDeadline to OnDraw or similar.
137 void OnBeginImplFrameDeadline(); 166 void OnBeginImplFrameDeadline();
138 void OnBeginImplFrameIdle(); 167 void OnBeginImplFrameIdle();
(...skipping 13 matching lines...) Expand all
152 // Indicates that a redraw is required, either due to the impl tree changing 181 // Indicates that a redraw is required, either due to the impl tree changing
153 // or the screen being damaged and simply needing redisplay. 182 // or the screen being damaged and simply needing redisplay.
154 void SetNeedsRedraw(); 183 void SetNeedsRedraw();
155 bool needs_redraw() const { return needs_redraw_; } 184 bool needs_redraw() const { return needs_redraw_; }
156 185
157 void SetNeedsAnimate(); 186 void SetNeedsAnimate();
158 bool needs_animate() const { return needs_animate_; } 187 bool needs_animate() const { return needs_animate_; }
159 188
160 // Indicates that prepare-tiles is required. This guarantees another 189 // Indicates that prepare-tiles is required. This guarantees another
161 // PrepareTiles will occur shortly (even if no redraw is required). 190 // PrepareTiles will occur shortly (even if no redraw is required).
162 void SetNeedsPrepareTiles(); 191 void SetNeedsPrepareTiles(bool for_commit);
163 192
164 // Make deadline wait for ReadyToDraw signal. 193 // Make deadline wait for ReadyToDraw signal.
165 void SetWaitForReadyToDraw(); 194 void SetWaitForReadyToDraw();
166 195
167 // Sets how many swaps can be pending to the OutputSurface. 196 // Sets how many swaps can be pending to the OutputSurface.
168 void SetMaxSwapsPending(int max); 197 void SetMaxSwapsPending(int max);
169 198
170 // If the scheduler attempted to draw and swap, this provides feedback 199 // If the scheduler attempted to draw and swap, this provides feedback
171 // regarding whether or not the swap actually occured. We might skip the 200 // regarding whether or not the swap actually occured. We might skip the
172 // swap when there is not damage, for example. 201 // swap when there is not damage, for example.
173 void DidSwapBuffers(); 202 void DidSwapBuffers();
174 203
175 // Indicates whether a redraw is required because we are currently rendering 204 // Indicates whether a redraw is required because we are currently rendering
176 // with a low resolution or checkerboarded tile. 205 // with a low resolution or checkerboarded tile.
177 void SetSwapUsedIncompleteTile(bool used_incomplete_tile); 206 void SetSwapUsedIncompleteTile(bool used_incomplete_tile);
178 207
179 // Notification from the OutputSurface that a swap has been consumed. 208 // Notification from the OutputSurface that a swap has been consumed.
180 void DidSwapBuffersComplete(); 209 void DidSwapBuffersComplete();
181 210
182 // Indicates whether to prioritize impl thread latency (i.e., animation 211 // Indicates whether to prioritize impl thread latency (i.e., animation
183 // smoothness) over new content activation. 212 // smoothness) over new content activation.
184 void SetImplLatencyTakesPriority(bool impl_latency_takes_priority); 213 void SetImplLatencyTakesPriority(bool impl_latency_takes_priority);
185 bool impl_latency_takes_priority() const { 214 bool impl_latency_takes_priority() const {
186 return impl_latency_takes_priority_; 215 return impl_latency_takes_priority_;
187 } 216 }
188 217
189 // Indicates whether ACTION_DRAW_AND_SWAP_IF_POSSIBLE drew to the screen. 218 // Indicates whether a draw request succeeded or not.
190 void DidDrawIfPossibleCompleted(DrawResult result); 219 void SetDrawResult(DrawResult result);
191 220
192 // Indicates that a new commit flow needs to be performed, either to pull 221 // Indicates that a new commit flow needs to be performed, either to pull
193 // updates from the main thread to the impl, or to push deltas from the impl 222 // updates from the main thread to the impl, or to push deltas from the impl
194 // thread to main. 223 // thread to main.
195 void SetNeedsCommit(); 224 void SetNeedsCommit();
196 225
197 // Call this only in response to receiving an ACTION_SEND_BEGIN_MAIN_FRAME 226 // Call this only in response to receiving an ACTION_SEND_BEGIN_MAIN_FRAME
198 // from NextAction. 227 // from NextAction.
199 // Indicates that all painting is complete. 228 // Indicates that all painting is complete.
200 void NotifyReadyToCommit(); 229 void NotifyReadyToCommit();
(...skipping 16 matching lines...) Expand all
217 246
218 // Indicates that scheduled BeginMainFrame is started. 247 // Indicates that scheduled BeginMainFrame is started.
219 void NotifyBeginMainFrameStarted(); 248 void NotifyBeginMainFrameStarted();
220 249
221 // Indicates that the pending tree is ready for activation. 250 // Indicates that the pending tree is ready for activation.
222 void NotifyReadyToActivate(); 251 void NotifyReadyToActivate();
223 252
224 // Indicates the active tree's visible tiles are ready to be drawn. 253 // Indicates the active tree's visible tiles are ready to be drawn.
225 void NotifyReadyToDraw(); 254 void NotifyReadyToDraw();
226 255
256 // Indicates we shouldn't draw the active tree until we won't checkerboard.
257 void SetRequiresHighResToDraw(bool required);
258
227 bool has_pending_tree() const { return has_pending_tree_; } 259 bool has_pending_tree() const { return has_pending_tree_; }
228 bool active_tree_needs_first_draw() const { 260 bool active_tree_needs_first_draw() const {
229 return active_tree_needs_first_draw_; 261 return active_tree_needs_first_draw_;
230 } 262 }
231 263
232 void DidPrepareTiles();
233 void DidLoseOutputSurface(); 264 void DidLoseOutputSurface();
234 void DidCreateAndInitializeOutputSurface(); 265 void DidCreateAndInitializeOutputSurface();
235 bool HasInitializedOutputSurface() const; 266 bool HasInitializedOutputSurface() const;
236 267
237 // True if we need to abort draws to make forward progress. 268 // True if we need to abort draws to make forward progress.
238 bool PendingDrawsShouldBeAborted() const; 269 bool PendingDrawsShouldBeAborted() const;
239 270
240 void SetContinuousPainting(bool continuous_painting) { 271 void SetContinuousPainting(bool continuous_painting) {
241 continuous_painting_ = continuous_painting; 272 continuous_painting_ = continuous_painting;
242 } 273 }
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 void UpdateStateOnDraw(bool did_request_swap); 315 void UpdateStateOnDraw(bool did_request_swap);
285 void UpdateStateOnBeginOutputSurfaceCreation(); 316 void UpdateStateOnBeginOutputSurfaceCreation();
286 void UpdateStateOnPrepareTiles(); 317 void UpdateStateOnPrepareTiles();
287 void UpdateStateOnInvalidateOutputSurface(); 318 void UpdateStateOnInvalidateOutputSurface();
288 319
289 const SchedulerSettings settings_; 320 const SchedulerSettings settings_;
290 321
291 OutputSurfaceState output_surface_state_; 322 OutputSurfaceState output_surface_state_;
292 BeginImplFrameState begin_impl_frame_state_; 323 BeginImplFrameState begin_impl_frame_state_;
293 CommitState commit_state_; 324 CommitState commit_state_;
294 ForcedRedrawOnTimeoutState forced_redraw_state_; 325 PrepareTilesApproach prepare_tiles_approach_;
326 PrepareTilesReason prepare_tiles_reason_;
295 327
296 // These are used for tracing only. 328 // These are used for tracing only.
297 int commit_count_; 329 int commit_count_;
298 int current_frame_number_; 330 int current_frame_number_;
299 int last_frame_number_animate_performed_; 331 int last_frame_number_animate_performed_;
300 int last_frame_number_swap_performed_; 332 int last_frame_number_swap_performed_;
301 int last_frame_number_swap_requested_; 333 int last_frame_number_swap_requested_;
302 int last_frame_number_begin_main_frame_sent_; 334 int last_frame_number_begin_main_frame_sent_;
303 int last_frame_number_invalidate_output_surface_performed_; 335 int last_frame_number_invalidate_output_surface_performed_;
304 336
305 // These are used to ensure that an action only happens once per frame, 337 // These are used to ensure that an action only happens once per frame,
306 // deadline, etc. 338 // deadline, etc.
307 bool animate_funnel_; 339 bool animate_funnel_;
308 bool request_swap_funnel_; 340 bool request_swap_funnel_;
309 bool send_begin_main_frame_funnel_; 341 bool send_begin_main_frame_funnel_;
310 bool invalidate_output_surface_funnel_; 342 bool invalidate_output_surface_funnel_;
343 // TODO(brianderson): Update the comment below.
311 // prepare_tiles_funnel_ is "filled" each time PrepareTiles is called 344 // prepare_tiles_funnel_ is "filled" each time PrepareTiles is called
312 // and "drained" on each BeginImplFrame. If the funnel gets too full, 345 // and "drained" on each BeginImplFrame. If the funnel gets too full,
313 // we start throttling ACTION_PREPARE_TILES such that we average one 346 // we start throttling ACTION_PREPARE_TILES such that we average one
314 // PrepareTiles per BeginImplFrame. 347 // PrepareTiles per BeginImplFrame.
315 int prepare_tiles_funnel_; 348 int prepare_tiles_funnel_;
316 349
317 int consecutive_checkerboard_animations_;
318 int max_pending_swaps_; 350 int max_pending_swaps_;
319 int pending_swaps_; 351 int pending_swaps_;
320 bool needs_redraw_; 352 bool needs_redraw_;
353 DrawResult last_draw_result_;
321 bool needs_animate_; 354 bool needs_animate_;
322 bool needs_prepare_tiles_;
323 bool needs_commit_; 355 bool needs_commit_;
324 bool visible_; 356 bool visible_;
325 bool can_start_; 357 bool can_start_;
326 bool can_draw_; 358 bool can_draw_;
327 bool has_pending_tree_; 359 bool has_pending_tree_;
328 bool pending_tree_is_ready_for_activation_; 360 bool pending_tree_is_ready_for_activation_;
361 bool requires_high_res_to_draw_;
329 bool active_tree_needs_first_draw_; 362 bool active_tree_needs_first_draw_;
363 bool active_tree_ready_to_draw_;
330 bool did_create_and_initialize_first_output_surface_; 364 bool did_create_and_initialize_first_output_surface_;
331 bool impl_latency_takes_priority_; 365 bool impl_latency_takes_priority_;
332 bool skip_next_begin_main_frame_to_reduce_latency_; 366 bool skip_next_begin_main_frame_to_reduce_latency_;
333 bool skip_begin_main_frame_to_reduce_latency_; 367 bool skip_begin_main_frame_to_reduce_latency_;
334 bool continuous_painting_; 368 bool continuous_painting_;
335 bool children_need_begin_frames_; 369 bool children_need_begin_frames_;
336 bool defer_commits_; 370 bool defer_commits_;
337 bool video_needs_begin_frames_; 371 bool video_needs_begin_frames_;
338 bool last_commit_had_no_updates_; 372 bool last_commit_had_no_updates_;
339 bool wait_for_active_tree_ready_to_draw_; 373 bool wait_for_active_tree_ready_to_draw_;
340 bool did_request_swap_in_last_frame_; 374 bool did_request_swap_in_last_frame_;
341 bool did_perform_swap_in_last_draw_; 375 bool did_perform_swap_in_last_draw_;
342 376
343 private: 377 private:
344 DISALLOW_COPY_AND_ASSIGN(SchedulerStateMachine); 378 DISALLOW_COPY_AND_ASSIGN(SchedulerStateMachine);
345 }; 379 };
346 380
347 } // namespace cc 381 } // namespace cc
348 382
349 #endif // CC_SCHEDULER_SCHEDULER_STATE_MACHINE_H_ 383 #endif // CC_SCHEDULER_SCHEDULER_STATE_MACHINE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698