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