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 #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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 | 43 |
44 enum OutputSurfaceState { | 44 enum OutputSurfaceState { |
45 OUTPUT_SURFACE_ACTIVE, | 45 OUTPUT_SURFACE_ACTIVE, |
46 OUTPUT_SURFACE_LOST, | 46 OUTPUT_SURFACE_LOST, |
47 OUTPUT_SURFACE_CREATING, | 47 OUTPUT_SURFACE_CREATING, |
48 OUTPUT_SURFACE_WAITING_FOR_FIRST_COMMIT, | 48 OUTPUT_SURFACE_WAITING_FOR_FIRST_COMMIT, |
49 OUTPUT_SURFACE_WAITING_FOR_FIRST_ACTIVATION, | 49 OUTPUT_SURFACE_WAITING_FOR_FIRST_ACTIVATION, |
50 }; | 50 }; |
51 static const char* OutputSurfaceStateToString(OutputSurfaceState state); | 51 static const char* OutputSurfaceStateToString(OutputSurfaceState state); |
52 | 52 |
53 // Note: BeginImplFrameState will always cycle through all the states in | 53 // Note: BeginImplFrameState does not cycle through these states in a fixed |
54 // order. Whether or not it actually waits or draws, it will at least try to | 54 // order on all platforms. It's up to the scheduler to set these correctly. |
55 // wait in BEGIN_IMPL_FRAME_STATE_INSIDE_BEGIN_FRAME and try to draw in | 55 // TODO(sunnyps): Rename the states to IDLE, ANIMATE, WAITING_FOR_DEADLINE and |
56 // BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE | 56 // DRAW. |
57 enum BeginImplFrameState { | 57 enum BeginImplFrameState { |
58 BEGIN_IMPL_FRAME_STATE_IDLE, | 58 BEGIN_IMPL_FRAME_STATE_IDLE, |
59 BEGIN_IMPL_FRAME_STATE_BEGIN_FRAME_STARTING, | 59 BEGIN_IMPL_FRAME_STATE_BEGIN_FRAME_STARTING, |
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_IMMEDIATE, | 67 BEGIN_IMPL_FRAME_DEADLINE_MODE_IMMEDIATE, |
67 BEGIN_IMPL_FRAME_DEADLINE_MODE_REGULAR, | 68 BEGIN_IMPL_FRAME_DEADLINE_MODE_REGULAR, |
68 BEGIN_IMPL_FRAME_DEADLINE_MODE_LATE, | 69 BEGIN_IMPL_FRAME_DEADLINE_MODE_LATE, |
69 }; | 70 }; |
70 static const char* BeginImplFrameDeadlineModeToString( | 71 static const char* BeginImplFrameDeadlineModeToString( |
71 BeginImplFrameDeadlineMode mode); | 72 BeginImplFrameDeadlineMode mode); |
72 | 73 |
73 enum CommitState { | 74 enum CommitState { |
74 COMMIT_STATE_IDLE, | 75 COMMIT_STATE_IDLE, |
75 COMMIT_STATE_BEGIN_MAIN_FRAME_SENT, | 76 COMMIT_STATE_BEGIN_MAIN_FRAME_SENT, |
(...skipping 27 matching lines...) Expand all Loading... |
103 ACTION_NONE, | 104 ACTION_NONE, |
104 ACTION_ANIMATE, | 105 ACTION_ANIMATE, |
105 ACTION_SEND_BEGIN_MAIN_FRAME, | 106 ACTION_SEND_BEGIN_MAIN_FRAME, |
106 ACTION_COMMIT, | 107 ACTION_COMMIT, |
107 ACTION_ACTIVATE_SYNC_TREE, | 108 ACTION_ACTIVATE_SYNC_TREE, |
108 ACTION_DRAW_AND_SWAP_IF_POSSIBLE, | 109 ACTION_DRAW_AND_SWAP_IF_POSSIBLE, |
109 ACTION_DRAW_AND_SWAP_FORCED, | 110 ACTION_DRAW_AND_SWAP_FORCED, |
110 ACTION_DRAW_AND_SWAP_ABORT, | 111 ACTION_DRAW_AND_SWAP_ABORT, |
111 ACTION_BEGIN_OUTPUT_SURFACE_CREATION, | 112 ACTION_BEGIN_OUTPUT_SURFACE_CREATION, |
112 ACTION_PREPARE_TILES, | 113 ACTION_PREPARE_TILES, |
| 114 ACTION_INVALIDATE_OUTPUT_SURFACE, |
113 }; | 115 }; |
114 static const char* ActionToString(Action action); | 116 static const char* ActionToString(Action action); |
115 | 117 |
116 scoped_refptr<base::trace_event::ConvertableToTraceFormat> AsValue() const; | 118 scoped_refptr<base::trace_event::ConvertableToTraceFormat> AsValue() const; |
117 void AsValueInto(base::trace_event::TracedValue* dict) const; | 119 void AsValueInto(base::trace_event::TracedValue* dict) const; |
118 | 120 |
119 Action NextAction() const; | 121 Action NextAction() const; |
120 void UpdateState(Action action); | 122 void UpdateState(Action action); |
121 | 123 |
122 // Indicates whether the impl thread needs a BeginImplFrame callback in order | 124 // Indicates whether the impl thread needs a BeginImplFrame callback in order |
123 // to make progress. | 125 // to make progress. |
124 bool BeginFrameNeeded() const; | 126 bool BeginFrameNeeded() const; |
125 | 127 |
126 // Indicates that we need to independently poll for new state and actions | |
127 // because we can't expect a BeginImplFrame. This is mostly used to avoid | |
128 // drawing repeat frames with the synchronous compositor without dropping | |
129 // necessary actions on the floor. | |
130 bool ShouldPollForAnticipatedDrawTriggers() const; | |
131 | |
132 // Indicates that the system has entered and left a BeginImplFrame callback. | 128 // Indicates that the system has entered and left a BeginImplFrame callback. |
133 // The scheduler will not draw more than once in a given BeginImplFrame | 129 // The scheduler will not draw more than once in a given BeginImplFrame |
134 // callback nor send more than one BeginMainFrame message. | 130 // callback nor send more than one BeginMainFrame message. |
135 void OnBeginImplFrame(); | 131 void OnBeginImplFrame(); |
136 void OnBeginImplFrameDeadlinePending(); | 132 void OnBeginImplFrameDeadlinePending(); |
| 133 // Indicates that the scheduler has entered the draw phase. The scheduler |
| 134 // will not draw more than once in a single draw phase. |
| 135 // TODO(sunnyps): Rename OnBeginImplFrameDeadline to OnDraw or similar. |
137 void OnBeginImplFrameDeadline(); | 136 void OnBeginImplFrameDeadline(); |
138 void OnBeginImplFrameIdle(); | 137 void OnBeginImplFrameIdle(); |
139 BeginImplFrameState begin_impl_frame_state() const { | 138 BeginImplFrameState begin_impl_frame_state() const { |
140 return begin_impl_frame_state_; | 139 return begin_impl_frame_state_; |
141 } | 140 } |
142 BeginImplFrameDeadlineMode CurrentBeginImplFrameDeadlineMode() const; | 141 BeginImplFrameDeadlineMode CurrentBeginImplFrameDeadlineMode() const; |
143 | 142 |
144 // If the main thread didn't manage to produce a new frame in time for the | 143 // If the main thread didn't manage to produce a new frame in time for the |
145 // impl thread to draw, it is in a high latency mode. | 144 // impl thread to draw, it is in a high latency mode. |
146 bool MainThreadIsInHighLatencyMode() const; | 145 bool MainThreadIsInHighLatencyMode() const; |
147 | 146 |
148 // PollForAnticipatedDrawTriggers is used by the synchronous compositor to | |
149 // avoid requesting BeginImplFrames when we won't actually draw but still | |
150 // need to advance our state at vsync intervals. | |
151 void DidEnterPollForAnticipatedDrawTriggers(); | |
152 void DidLeavePollForAnticipatedDrawTriggers(); | |
153 bool inside_poll_for_anticipated_draw_triggers() const { | |
154 return inside_poll_for_anticipated_draw_triggers_; | |
155 } | |
156 | |
157 // Indicates whether the LayerTreeHostImpl is visible. | 147 // Indicates whether the LayerTreeHostImpl is visible. |
158 void SetVisible(bool visible); | 148 void SetVisible(bool visible); |
159 bool visible() const { return visible_; } | 149 bool visible() const { return visible_; } |
160 | 150 |
161 // Indicates that a redraw is required, either due to the impl tree changing | 151 // Indicates that a redraw is required, either due to the impl tree changing |
162 // or the screen being damaged and simply needing redisplay. | 152 // or the screen being damaged and simply needing redisplay. |
163 void SetNeedsRedraw(); | 153 void SetNeedsRedraw(); |
164 bool needs_redraw() const { return needs_redraw_; } | 154 bool needs_redraw() const { return needs_redraw_; } |
165 | 155 |
166 void SetNeedsAnimate(); | 156 void SetNeedsAnimate(); |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
233 } | 223 } |
234 | 224 |
235 void DidPrepareTiles(); | 225 void DidPrepareTiles(); |
236 void DidLoseOutputSurface(); | 226 void DidLoseOutputSurface(); |
237 void DidCreateAndInitializeOutputSurface(); | 227 void DidCreateAndInitializeOutputSurface(); |
238 bool HasInitializedOutputSurface() const; | 228 bool HasInitializedOutputSurface() const; |
239 | 229 |
240 // True if we need to abort draws to make forward progress. | 230 // True if we need to abort draws to make forward progress. |
241 bool PendingDrawsShouldBeAborted() const; | 231 bool PendingDrawsShouldBeAborted() const; |
242 | 232 |
243 bool SupportsProactiveBeginFrame() const; | |
244 | |
245 void SetContinuousPainting(bool continuous_painting) { | 233 void SetContinuousPainting(bool continuous_painting) { |
246 continuous_painting_ = continuous_painting; | 234 continuous_painting_ = continuous_painting; |
247 } | 235 } |
248 | 236 |
249 bool CouldSendBeginMainFrame() const; | 237 bool CouldSendBeginMainFrame() const; |
250 | 238 |
251 void SetDeferCommits(bool defer_commits); | 239 void SetDeferCommits(bool defer_commits); |
252 | 240 |
253 // TODO(zmo): This is temporary for debugging crbug.com/393331. | 241 // TODO(zmo): This is temporary for debugging crbug.com/393331. |
254 // We should remove it afterwards. | 242 // We should remove it afterwards. |
(...skipping 14 matching lines...) Expand all Loading... |
269 // True if we need to force activations to make forward progress. | 257 // True if we need to force activations to make forward progress. |
270 bool PendingActivationsShouldBeForced() const; | 258 bool PendingActivationsShouldBeForced() const; |
271 | 259 |
272 bool ShouldAnimate() const; | 260 bool ShouldAnimate() const; |
273 bool ShouldBeginOutputSurfaceCreation() const; | 261 bool ShouldBeginOutputSurfaceCreation() const; |
274 bool ShouldDraw() const; | 262 bool ShouldDraw() const; |
275 bool ShouldActivatePendingTree() const; | 263 bool ShouldActivatePendingTree() const; |
276 bool ShouldSendBeginMainFrame() const; | 264 bool ShouldSendBeginMainFrame() const; |
277 bool ShouldCommit() const; | 265 bool ShouldCommit() const; |
278 bool ShouldPrepareTiles() const; | 266 bool ShouldPrepareTiles() const; |
| 267 bool ShouldInvalidateOutputSurface() const; |
279 | 268 |
280 void AdvanceCurrentFrameNumber(); | 269 void UpdateStateOnAnimate(); |
281 | 270 void UpdateStateOnSendBeginMainFrame(); |
282 void UpdateStateOnCommit(bool commit_had_no_updates); | 271 void UpdateStateOnCommit(bool commit_had_no_updates); |
283 void UpdateStateOnActivation(); | 272 void UpdateStateOnActivation(); |
284 void UpdateStateOnDraw(bool did_request_swap); | 273 void UpdateStateOnDraw(bool did_request_swap); |
| 274 void UpdateStateOnBeginOutputSurfaceCreation(); |
285 void UpdateStateOnPrepareTiles(); | 275 void UpdateStateOnPrepareTiles(); |
| 276 void UpdateStateOnInvalidateOutputSurface(); |
286 | 277 |
287 const SchedulerSettings settings_; | 278 const SchedulerSettings settings_; |
288 | 279 |
289 OutputSurfaceState output_surface_state_; | 280 OutputSurfaceState output_surface_state_; |
290 BeginImplFrameState begin_impl_frame_state_; | 281 BeginImplFrameState begin_impl_frame_state_; |
291 CommitState commit_state_; | 282 CommitState commit_state_; |
292 ForcedRedrawOnTimeoutState forced_redraw_state_; | 283 ForcedRedrawOnTimeoutState forced_redraw_state_; |
293 | 284 |
294 // These are used for tracing only. | 285 // These are used for tracing only. |
295 int commit_count_; | 286 int commit_count_; |
296 int current_frame_number_; | 287 int current_frame_number_; |
297 int last_frame_number_animate_performed_; | 288 int last_frame_number_animate_performed_; |
298 int last_frame_number_swap_performed_; | 289 int last_frame_number_swap_performed_; |
299 int last_frame_number_swap_requested_; | 290 int last_frame_number_swap_requested_; |
300 int last_frame_number_begin_main_frame_sent_; | 291 int last_frame_number_begin_main_frame_sent_; |
| 292 int last_frame_number_invalidate_output_surface_performed_; |
301 | 293 |
302 // These are used to ensure that an action only happens once per frame, | 294 // These are used to ensure that an action only happens once per frame, |
303 // deadline, etc. | 295 // deadline, etc. |
304 bool animate_funnel_; | 296 bool animate_funnel_; |
305 bool perform_swap_funnel_; | 297 bool perform_swap_funnel_; |
306 bool request_swap_funnel_; | 298 bool request_swap_funnel_; |
307 bool send_begin_main_frame_funnel_; | 299 bool send_begin_main_frame_funnel_; |
| 300 bool invalidate_output_surface_funnel_; |
308 // prepare_tiles_funnel_ is "filled" each time PrepareTiles is called | 301 // prepare_tiles_funnel_ is "filled" each time PrepareTiles is called |
309 // and "drained" on each BeginImplFrame. If the funnel gets too full, | 302 // and "drained" on each BeginImplFrame. If the funnel gets too full, |
310 // we start throttling ACTION_PREPARE_TILES such that we average one | 303 // we start throttling ACTION_PREPARE_TILES such that we average one |
311 // PrepareTiles per BeginImplFrame. | 304 // PrepareTiles per BeginImplFrame. |
312 int prepare_tiles_funnel_; | 305 int prepare_tiles_funnel_; |
313 | 306 |
314 int consecutive_checkerboard_animations_; | 307 int consecutive_checkerboard_animations_; |
315 int max_pending_swaps_; | 308 int max_pending_swaps_; |
316 int pending_swaps_; | 309 int pending_swaps_; |
317 bool needs_redraw_; | 310 bool needs_redraw_; |
318 bool needs_animate_; | 311 bool needs_animate_; |
319 bool needs_prepare_tiles_; | 312 bool needs_prepare_tiles_; |
320 bool needs_commit_; | 313 bool needs_commit_; |
321 bool inside_poll_for_anticipated_draw_triggers_; | |
322 bool visible_; | 314 bool visible_; |
323 bool can_start_; | 315 bool can_start_; |
324 bool can_draw_; | 316 bool can_draw_; |
325 bool has_pending_tree_; | 317 bool has_pending_tree_; |
326 bool pending_tree_is_ready_for_activation_; | 318 bool pending_tree_is_ready_for_activation_; |
327 bool active_tree_needs_first_draw_; | 319 bool active_tree_needs_first_draw_; |
328 bool did_create_and_initialize_first_output_surface_; | 320 bool did_create_and_initialize_first_output_surface_; |
329 bool impl_latency_takes_priority_; | 321 bool impl_latency_takes_priority_; |
330 bool skip_next_begin_main_frame_to_reduce_latency_; | 322 bool skip_next_begin_main_frame_to_reduce_latency_; |
331 bool skip_begin_main_frame_to_reduce_latency_; | 323 bool skip_begin_main_frame_to_reduce_latency_; |
332 bool continuous_painting_; | 324 bool continuous_painting_; |
333 bool children_need_begin_frames_; | 325 bool children_need_begin_frames_; |
334 bool defer_commits_; | 326 bool defer_commits_; |
335 bool last_commit_had_no_updates_; | 327 bool last_commit_had_no_updates_; |
336 | 328 |
337 private: | 329 private: |
338 DISALLOW_COPY_AND_ASSIGN(SchedulerStateMachine); | 330 DISALLOW_COPY_AND_ASSIGN(SchedulerStateMachine); |
339 }; | 331 }; |
340 | 332 |
341 } // namespace cc | 333 } // namespace cc |
342 | 334 |
343 #endif // CC_SCHEDULER_SCHEDULER_STATE_MACHINE_H_ | 335 #endif // CC_SCHEDULER_SCHEDULER_STATE_MACHINE_H_ |
OLD | NEW |