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