| 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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 // BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE | 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_IMMEDIATE, | 66 BEGIN_IMPL_FRAME_DEADLINE_MODE_IMMEDIATE_SYNCHRONOUS, |
| 67 BEGIN_IMPL_FRAME_DEADLINE_MODE_IMMEDIATE_ASYNCHRONOUS, |
| 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, |
| 76 COMMIT_STATE_BEGIN_MAIN_FRAME_STARTED, | 77 COMMIT_STATE_BEGIN_MAIN_FRAME_STARTED, |
| (...skipping 26 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::debug::ConvertableToTraceFormat> AsValue() const; | 118 scoped_refptr<base::debug::ConvertableToTraceFormat> AsValue() const; |
| 117 void AsValueInto(base::debug::TracedValue* dict, base::TimeTicks now) const; | 119 void AsValueInto(base::debug::TracedValue* dict, base::TimeTicks now) 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(const BeginFrameArgs& args); | 131 void OnBeginImplFrame(const BeginFrameArgs& args); |
| 136 void OnBeginImplFrameDeadlinePending(); | 132 void OnBeginImplFrameDeadlinePending(); |
| 137 void OnBeginImplFrameDeadline(); | 133 void OnBeginImplFrameDeadline(); |
| 138 void OnBeginImplFrameIdle(); | 134 void OnBeginImplFrameIdle(); |
| 139 BeginImplFrameState begin_impl_frame_state() const { | 135 BeginImplFrameState begin_impl_frame_state() const { |
| 140 return begin_impl_frame_state_; | 136 return begin_impl_frame_state_; |
| 141 } | 137 } |
| 142 BeginImplFrameDeadlineMode CurrentBeginImplFrameDeadlineMode() const; | 138 BeginImplFrameDeadlineMode CurrentBeginImplFrameDeadlineMode() const; |
| 143 | 139 |
| 144 // If the main thread didn't manage to produce a new frame in time for the | 140 // 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. | 141 // impl thread to draw, it is in a high latency mode. |
| 146 bool MainThreadIsInHighLatencyMode() const; | 142 bool MainThreadIsInHighLatencyMode() const; |
| 147 | 143 |
| 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. | 144 // Indicates whether the LayerTreeHostImpl is visible. |
| 158 void SetVisible(bool visible); | 145 void SetVisible(bool visible); |
| 159 | 146 |
| 160 // Indicates that a redraw is required, either due to the impl tree changing | 147 // Indicates that a redraw is required, either due to the impl tree changing |
| 161 // or the screen being damaged and simply needing redisplay. | 148 // or the screen being damaged and simply needing redisplay. |
| 162 void SetNeedsRedraw(); | 149 void SetNeedsRedraw(); |
| 163 bool needs_redraw() const { return needs_redraw_; } | 150 bool needs_redraw() const { return needs_redraw_; } |
| 164 | 151 |
| 152 void OutputSurfaceDidRequestDraw(); |
| 153 |
| 165 void SetNeedsAnimate(); | 154 void SetNeedsAnimate(); |
| 166 bool needs_animate() const { return needs_animate_; } | 155 bool needs_animate() const { return needs_animate_; } |
| 167 | 156 |
| 168 // Indicates that prepare-tiles is required. This guarantees another | 157 // Indicates that prepare-tiles is required. This guarantees another |
| 169 // PrepareTiles will occur shortly (even if no redraw is required). | 158 // PrepareTiles will occur shortly (even if no redraw is required). |
| 170 void SetNeedsPrepareTiles(); | 159 void SetNeedsPrepareTiles(); |
| 171 | 160 |
| 172 // Sets how many swaps can be pending to the OutputSurface. | 161 // Sets how many swaps can be pending to the OutputSurface. |
| 173 void SetMaxSwapsPending(int max); | 162 void SetMaxSwapsPending(int max); |
| 174 | 163 |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 } | 220 } |
| 232 | 221 |
| 233 void DidPrepareTiles(); | 222 void DidPrepareTiles(); |
| 234 void DidLoseOutputSurface(); | 223 void DidLoseOutputSurface(); |
| 235 void DidCreateAndInitializeOutputSurface(); | 224 void DidCreateAndInitializeOutputSurface(); |
| 236 bool HasInitializedOutputSurface() const; | 225 bool HasInitializedOutputSurface() const; |
| 237 | 226 |
| 238 // True if we need to abort draws to make forward progress. | 227 // True if we need to abort draws to make forward progress. |
| 239 bool PendingDrawsShouldBeAborted() const; | 228 bool PendingDrawsShouldBeAborted() const; |
| 240 | 229 |
| 241 bool SupportsProactiveBeginFrame() const; | |
| 242 | |
| 243 void SetContinuousPainting(bool continuous_painting) { | 230 void SetContinuousPainting(bool continuous_painting) { |
| 244 continuous_painting_ = continuous_painting; | 231 continuous_painting_ = continuous_painting; |
| 245 } | 232 } |
| 246 | 233 |
| 247 bool CouldSendBeginMainFrame() const; | 234 bool CouldSendBeginMainFrame() const; |
| 248 | 235 |
| 249 void SetImplLatencyTakesPriorityOnBattery( | 236 void SetImplLatencyTakesPriorityOnBattery( |
| 250 bool impl_latency_takes_priority_on_battery) { | 237 bool impl_latency_takes_priority_on_battery) { |
| 251 impl_latency_takes_priority_on_battery_ = | 238 impl_latency_takes_priority_on_battery_ = |
| 252 impl_latency_takes_priority_on_battery; | 239 impl_latency_takes_priority_on_battery; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 272 bool PendingActivationsShouldBeForced() const; | 259 bool PendingActivationsShouldBeForced() const; |
| 273 | 260 |
| 274 bool ShouldAnimate() const; | 261 bool ShouldAnimate() const; |
| 275 bool ShouldBeginOutputSurfaceCreation() const; | 262 bool ShouldBeginOutputSurfaceCreation() const; |
| 276 bool ShouldDrawForced() const; | 263 bool ShouldDrawForced() const; |
| 277 bool ShouldDraw() const; | 264 bool ShouldDraw() const; |
| 278 bool ShouldActivatePendingTree() const; | 265 bool ShouldActivatePendingTree() const; |
| 279 bool ShouldSendBeginMainFrame() const; | 266 bool ShouldSendBeginMainFrame() const; |
| 280 bool ShouldCommit() const; | 267 bool ShouldCommit() const; |
| 281 bool ShouldPrepareTiles() const; | 268 bool ShouldPrepareTiles() const; |
| 269 bool ShouldInvalidateOutputSurface() const; |
| 282 | 270 |
| 283 void AdvanceCurrentFrameNumber(); | 271 void AdvanceCurrentFrameNumber(); |
| 284 bool HasAnimatedThisFrame() const; | 272 bool HasAnimatedThisFrame() const; |
| 285 bool HasSentBeginMainFrameThisFrame() const; | 273 bool HasSentBeginMainFrameThisFrame() const; |
| 286 bool HasRequestedSwapThisFrame() const; | 274 bool HasRequestedSwapThisFrame() const; |
| 287 bool HasSwappedThisFrame() const; | 275 bool HasSwappedThisFrame() const; |
| 276 bool HasInvalidatedOutputSurfaceThisFrame() const; |
| 288 | 277 |
| 289 void UpdateStateOnCommit(bool commit_was_aborted); | 278 void UpdateStateOnCommit(bool commit_was_aborted); |
| 290 void UpdateStateOnActivation(); | 279 void UpdateStateOnActivation(); |
| 291 void UpdateStateOnDraw(bool did_request_swap); | 280 void UpdateStateOnDraw(bool did_request_swap); |
| 292 void UpdateStateOnPrepareTiles(); | 281 void UpdateStateOnPrepareTiles(); |
| 293 | 282 |
| 294 const SchedulerSettings settings_; | 283 const SchedulerSettings settings_; |
| 295 | 284 |
| 296 OutputSurfaceState output_surface_state_; | 285 OutputSurfaceState output_surface_state_; |
| 297 BeginImplFrameState begin_impl_frame_state_; | 286 BeginImplFrameState begin_impl_frame_state_; |
| 298 CommitState commit_state_; | 287 CommitState commit_state_; |
| 299 ForcedRedrawOnTimeoutState forced_redraw_state_; | 288 ForcedRedrawOnTimeoutState forced_redraw_state_; |
| 300 | 289 |
| 301 BeginFrameArgs begin_impl_frame_args_; | 290 BeginFrameArgs begin_impl_frame_args_; |
| 302 | 291 |
| 303 int commit_count_; | 292 int commit_count_; |
| 304 int current_frame_number_; | 293 int current_frame_number_; |
| 305 int last_frame_number_animate_performed_; | 294 int last_frame_number_animate_performed_; |
| 306 int last_frame_number_swap_performed_; | 295 int last_frame_number_swap_performed_; |
| 307 int last_frame_number_swap_requested_; | 296 int last_frame_number_swap_requested_; |
| 308 int last_frame_number_begin_main_frame_sent_; | 297 int last_frame_number_begin_main_frame_sent_; |
| 298 int last_frame_number_invalidate_output_surface_performed_; |
| 309 | 299 |
| 310 // prepare_tiles_funnel_ is "filled" each time PrepareTiles is called | 300 // prepare_tiles_funnel_ is "filled" each time PrepareTiles is called |
| 311 // and "drained" on each BeginImplFrame. If the funnel gets too full, | 301 // and "drained" on each BeginImplFrame. If the funnel gets too full, |
| 312 // we start throttling ACTION_PREPARE_TILES such that we average one | 302 // we start throttling ACTION_PREPARE_TILES such that we average one |
| 313 // PrepareTiles per BeginImplFrame. | 303 // PrepareTiles per BeginImplFrame. |
| 314 int prepare_tiles_funnel_; | 304 int prepare_tiles_funnel_; |
| 315 int consecutive_checkerboard_animations_; | 305 int consecutive_checkerboard_animations_; |
| 316 int max_pending_swaps_; | 306 int max_pending_swaps_; |
| 317 int pending_swaps_; | 307 int pending_swaps_; |
| 318 bool needs_redraw_; | 308 bool needs_redraw_; |
| 319 bool needs_animate_; | 309 bool needs_animate_; |
| 320 bool needs_prepare_tiles_; | 310 bool needs_prepare_tiles_; |
| 321 bool needs_commit_; | 311 bool needs_commit_; |
| 322 bool inside_poll_for_anticipated_draw_triggers_; | |
| 323 bool visible_; | 312 bool visible_; |
| 324 bool can_start_; | 313 bool can_start_; |
| 325 bool can_draw_; | 314 bool can_draw_; |
| 326 bool has_pending_tree_; | 315 bool has_pending_tree_; |
| 327 bool pending_tree_is_ready_for_activation_; | 316 bool pending_tree_is_ready_for_activation_; |
| 328 bool active_tree_needs_first_draw_; | 317 bool active_tree_needs_first_draw_; |
| 329 bool did_commit_after_animating_; | 318 bool did_commit_after_animating_; |
| 330 bool did_create_and_initialize_first_output_surface_; | 319 bool did_create_and_initialize_first_output_surface_; |
| 331 bool impl_latency_takes_priority_; | 320 bool impl_latency_takes_priority_; |
| 332 bool skip_next_begin_main_frame_to_reduce_latency_; | 321 bool skip_next_begin_main_frame_to_reduce_latency_; |
| 333 bool skip_begin_main_frame_to_reduce_latency_; | 322 bool skip_begin_main_frame_to_reduce_latency_; |
| 334 bool continuous_painting_; | 323 bool continuous_painting_; |
| 335 bool impl_latency_takes_priority_on_battery_; | 324 bool impl_latency_takes_priority_on_battery_; |
| 336 bool children_need_begin_frames_; | 325 bool children_need_begin_frames_; |
| 326 bool output_surface_did_request_draw_; |
| 337 | 327 |
| 338 private: | 328 private: |
| 339 DISALLOW_COPY_AND_ASSIGN(SchedulerStateMachine); | 329 DISALLOW_COPY_AND_ASSIGN(SchedulerStateMachine); |
| 340 }; | 330 }; |
| 341 | 331 |
| 342 } // namespace cc | 332 } // namespace cc |
| 343 | 333 |
| 344 #endif // CC_SCHEDULER_SCHEDULER_STATE_MACHINE_H_ | 334 #endif // CC_SCHEDULER_SCHEDULER_STATE_MACHINE_H_ |
| OLD | NEW |