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