| 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 27 matching lines...) Expand all Loading... |
| 38 | 38 |
| 39 enum OutputSurfaceState { | 39 enum OutputSurfaceState { |
| 40 OUTPUT_SURFACE_ACTIVE, | 40 OUTPUT_SURFACE_ACTIVE, |
| 41 OUTPUT_SURFACE_LOST, | 41 OUTPUT_SURFACE_LOST, |
| 42 OUTPUT_SURFACE_CREATING, | 42 OUTPUT_SURFACE_CREATING, |
| 43 OUTPUT_SURFACE_WAITING_FOR_FIRST_COMMIT, | 43 OUTPUT_SURFACE_WAITING_FOR_FIRST_COMMIT, |
| 44 OUTPUT_SURFACE_WAITING_FOR_FIRST_ACTIVATION, | 44 OUTPUT_SURFACE_WAITING_FOR_FIRST_ACTIVATION, |
| 45 }; | 45 }; |
| 46 static const char* OutputSurfaceStateToString(OutputSurfaceState state); | 46 static const char* OutputSurfaceStateToString(OutputSurfaceState state); |
| 47 | 47 |
| 48 // Note: BeginFrameState will always cycle through all the states in order. |
| 49 // Whether or not it actually waits or draws, it will at least try to wait in |
| 50 // BEGIN_FRAME_STATE_DEADLINE_PENDING and try to draw in |
| 51 // BEGIN_FRAME_STATE_INSIDE_DEADLINE |
| 52 enum BeginFrameState { |
| 53 BEGIN_FRAME_STATE_IDLE, |
| 54 BEGIN_FRAME_STATE_INSIDE_BEGIN_FRAME, |
| 55 BEGIN_FRAME_STATE_DEADLINE_PENDING, |
| 56 BEGIN_FRAME_STATE_INSIDE_DEADLINE, |
| 57 }; |
| 58 static const char* BeginFrameStateToString(BeginFrameState state); |
| 59 |
| 48 enum CommitState { | 60 enum CommitState { |
| 49 COMMIT_STATE_IDLE, | 61 COMMIT_STATE_IDLE, |
| 50 COMMIT_STATE_FRAME_IN_PROGRESS, | 62 COMMIT_STATE_FRAME_IN_PROGRESS, |
| 51 COMMIT_STATE_READY_TO_COMMIT, | 63 COMMIT_STATE_READY_TO_COMMIT, |
| 52 COMMIT_STATE_WAITING_FOR_FIRST_DRAW, | 64 COMMIT_STATE_WAITING_FOR_FIRST_DRAW, |
| 53 }; | 65 }; |
| 54 static const char* CommitStateToString(CommitState state); | 66 static const char* CommitStateToString(CommitState state); |
| 55 | 67 |
| 56 enum TextureState { | 68 enum TextureState { |
| 57 LAYER_TEXTURE_STATE_UNLOCKED, | 69 LAYER_TEXTURE_STATE_UNLOCKED, |
| (...skipping 17 matching lines...) Expand all Loading... |
| 75 enum ForcedRedrawOnTimeoutState { | 87 enum ForcedRedrawOnTimeoutState { |
| 76 FORCED_REDRAW_STATE_IDLE, | 88 FORCED_REDRAW_STATE_IDLE, |
| 77 FORCED_REDRAW_STATE_WAITING_FOR_COMMIT, | 89 FORCED_REDRAW_STATE_WAITING_FOR_COMMIT, |
| 78 FORCED_REDRAW_STATE_WAITING_FOR_ACTIVATION, | 90 FORCED_REDRAW_STATE_WAITING_FOR_ACTIVATION, |
| 79 FORCED_REDRAW_STATE_WAITING_FOR_DRAW, | 91 FORCED_REDRAW_STATE_WAITING_FOR_DRAW, |
| 80 }; | 92 }; |
| 81 static const char* ForcedRedrawOnTimeoutStateToString( | 93 static const char* ForcedRedrawOnTimeoutStateToString( |
| 82 ForcedRedrawOnTimeoutState state); | 94 ForcedRedrawOnTimeoutState state); |
| 83 | 95 |
| 84 bool CommitPending() const { | 96 bool CommitPending() const { |
| 85 return commit_state_ == COMMIT_STATE_FRAME_IN_PROGRESS || | 97 return commit_state_ == COMMIT_STATE_FRAME_IN_PROGRESS; |
| 86 commit_state_ == COMMIT_STATE_READY_TO_COMMIT; | |
| 87 } | 98 } |
| 88 | 99 |
| 89 bool RedrawPending() const { return needs_redraw_; } | 100 bool RedrawPending() const { return needs_redraw_; } |
| 90 | 101 |
| 91 enum Action { | 102 enum Action { |
| 92 ACTION_NONE, | 103 ACTION_NONE, |
| 93 ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD, | 104 ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD, |
| 94 ACTION_COMMIT, | 105 ACTION_COMMIT, |
| 95 ACTION_UPDATE_VISIBLE_TILES, | 106 ACTION_UPDATE_VISIBLE_TILES, |
| 96 ACTION_ACTIVATE_PENDING_TREE, | 107 ACTION_ACTIVATE_PENDING_TREE, |
| 97 ACTION_DRAW_AND_SWAP_IF_POSSIBLE, | 108 ACTION_DRAW_AND_SWAP_IF_POSSIBLE, |
| 98 ACTION_DRAW_AND_SWAP_FORCED, | 109 ACTION_DRAW_AND_SWAP_FORCED, |
| 99 ACTION_DRAW_AND_SWAP_ABORT, | 110 ACTION_DRAW_AND_SWAP_ABORT, |
| 100 ACTION_DRAW_AND_READBACK, | 111 ACTION_DRAW_AND_READBACK, |
| 101 ACTION_BEGIN_OUTPUT_SURFACE_CREATION, | 112 ACTION_BEGIN_OUTPUT_SURFACE_CREATION, |
| 102 ACTION_ACQUIRE_LAYER_TEXTURES_FOR_MAIN_THREAD, | 113 ACTION_ACQUIRE_LAYER_TEXTURES_FOR_MAIN_THREAD, |
| 103 }; | 114 }; |
| 104 static const char* ActionToString(Action action); | 115 static const char* ActionToString(Action action); |
| 105 | 116 |
| 106 scoped_ptr<base::Value> AsValue() const; | 117 scoped_ptr<base::Value> AsValue() const; |
| 107 | 118 |
| 108 Action NextAction() const; | 119 Action NextAction() const; |
| 109 void UpdateState(Action action); | 120 void UpdateState(Action action); |
| 121 void AdvanceBeginFrameStateWhenNoActionsRemain(); |
| 122 |
| 110 void CheckInvariants(); | 123 void CheckInvariants(); |
| 111 | 124 |
| 112 // Indicates whether the main thread needs a begin frame callback in order to | 125 // Indicates whether the main thread needs a begin frame callback in order to |
| 113 // make progress. | 126 // make progress. |
| 127 bool BeginFrameNeededByImplThread() const; |
| 114 bool BeginFrameNeededToDrawByImplThread() const; | 128 bool BeginFrameNeededToDrawByImplThread() const; |
| 115 bool ProactiveBeginFrameWantedByImplThread() const; | 129 bool ProactiveBeginFrameWantedByImplThread() const; |
| 116 | 130 |
| 117 // Indicates that the system has entered and left a BeginFrame callback. | 131 // Indicates that the system has entered and left a BeginFrame callback. |
| 118 // The scheduler will not draw more than once in a given BeginFrame | 132 // The scheduler will not draw more than once in a given BeginFrame |
| 119 // callback nor send more than one BeginFrame message. | 133 // callback nor send more than one BeginFrame message. |
| 120 void DidEnterBeginFrame(const BeginFrameArgs& args); | 134 void OnBeginFrame(const BeginFrameArgs& args); |
| 121 void DidLeaveBeginFrame(); | 135 void OnBeginFrameDeadline(); |
| 122 bool inside_begin_frame() const { return inside_begin_frame_; } | 136 bool ShouldTriggerBeginFrameDeadlineEarly() const; |
| 137 bool InsideBeginFrame() const; |
| 123 | 138 |
| 124 // Indicates whether the LayerTreeHostImpl is visible. | 139 // Indicates whether the LayerTreeHostImpl is visible. |
| 125 void SetVisible(bool visible); | 140 void SetVisible(bool visible); |
| 126 | 141 |
| 127 // Indicates that a redraw is required, either due to the impl tree changing | 142 // Indicates that a redraw is required, either due to the impl tree changing |
| 128 // or the screen being damaged and simply needing redisplay. | 143 // or the screen being damaged and simply needing redisplay. |
| 129 void SetNeedsRedraw(); | 144 void SetNeedsRedraw(); |
| 145 bool needs_redraw() const { return needs_redraw_; } |
| 130 | 146 |
| 131 // Indicates that a redraw is required because we are currently rendering | 147 // Indicates that a redraw is required because we are currently rendering |
| 132 // with a low resolution or checkerboarded tile. | 148 // with a low resolution or checkerboarded tile. |
| 133 void DidSwapUseIncompleteTile(); | 149 void DidSwapUseIncompleteTile(); |
| 134 | 150 |
| 135 // Indicates whether ACTION_DRAW_AND_SWAP_IF_POSSIBLE drew to the screen or | 151 // Indicates whether ACTION_DRAW_AND_SWAP_IF_POSSIBLE drew to the screen. |
| 136 // not. | |
| 137 void DidDrawIfPossibleCompleted(bool success); | 152 void DidDrawIfPossibleCompleted(bool success); |
| 138 | 153 |
| 139 // Indicates that a new commit flow needs to be performed, either to pull | 154 // Indicates that a new commit flow needs to be performed, either to pull |
| 140 // updates from the main thread to the impl, or to push deltas from the impl | 155 // updates from the main thread to the impl, or to push deltas from the impl |
| 141 // thread to main. | 156 // thread to main. |
| 142 void SetNeedsCommit(); | 157 void SetNeedsCommit(); |
| 143 | 158 |
| 144 // As SetNeedsCommit(), but ensures the begin frame will be sent to the main | 159 // As SetNeedsCommit(), but ensures the begin frame will be sent to the main |
| 145 // thread even if we are not visible. After this call we expect to go through | 160 // thread even if we are not visible. After this call we expect to go through |
| 146 // the forced commit flow and then return to waiting for a non-forced | 161 // the forced commit flow and then return to waiting for a non-forced |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 bool ShouldBeginOutputSurfaceCreation() const; | 210 bool ShouldBeginOutputSurfaceCreation() const; |
| 196 bool ShouldDrawForced() const; | 211 bool ShouldDrawForced() const; |
| 197 bool ShouldDraw() const; | 212 bool ShouldDraw() const; |
| 198 bool ShouldActivatePendingTree() const; | 213 bool ShouldActivatePendingTree() const; |
| 199 bool ShouldAcquireLayerTexturesForMainThread() const; | 214 bool ShouldAcquireLayerTexturesForMainThread() const; |
| 200 bool ShouldUpdateVisibleTiles() const; | 215 bool ShouldUpdateVisibleTiles() const; |
| 201 bool ShouldSendBeginFrameToMainThread() const; | 216 bool ShouldSendBeginFrameToMainThread() const; |
| 202 bool ShouldCommit() const; | 217 bool ShouldCommit() const; |
| 203 | 218 |
| 204 bool HasDrawnThisFrame() const; | 219 bool HasDrawnThisFrame() const; |
| 220 bool HasDrawnThisDrawAttempt() const; |
| 205 bool HasActivatedPendingTreeThisFrame() const; | 221 bool HasActivatedPendingTreeThisFrame() const; |
| 206 bool HasUpdatedVisibleTilesThisFrame() const; | 222 bool HasUpdatedVisibleTilesThisDrawAttempt() const; |
| 207 bool HasSentBeginFrameToMainThreadThisFrame() const; | 223 bool HasSentBeginFrameToMainThreadThisFrame() const; |
| 224 bool HasActivatedPendingTreeThisDrawAttempt() const; |
| 208 | 225 |
| 209 void UpdateStateOnCommit(bool commit_was_aborted); | 226 void UpdateStateOnCommit(bool commit_was_aborted); |
| 210 void UpdateStateOnActivation(); | 227 void UpdateStateOnActivation(); |
| 211 void UpdateStateOnDraw(bool did_swap); | 228 void UpdateStateOnDraw(bool did_swap); |
| 212 | 229 |
| 213 const SchedulerSettings settings_; | 230 const SchedulerSettings settings_; |
| 214 | 231 |
| 215 OutputSurfaceState output_surface_state_; | 232 OutputSurfaceState output_surface_state_; |
| 233 BeginFrameState begin_frame_state_; |
| 216 CommitState commit_state_; | 234 CommitState commit_state_; |
| 217 TextureState texture_state_; | 235 TextureState texture_state_; |
| 218 ForcedRedrawOnTimeoutState forced_redraw_state_; | 236 ForcedRedrawOnTimeoutState forced_redraw_state_; |
| 219 SynchronousReadbackState readback_state_; | 237 SynchronousReadbackState readback_state_; |
| 220 | 238 |
| 239 BeginFrameArgs last_begin_frame_args_; |
| 240 |
| 221 int commit_count_; | 241 int commit_count_; |
| 222 int current_frame_number_; | 242 int begin_frame_count_; |
| 223 int last_frame_number_where_begin_frame_sent_to_main_thread_; | 243 int draw_attempt_count_; |
| 224 int last_frame_number_swap_performed_; | 244 int last_begin_frame_count_swap_performed_; |
| 225 int last_frame_number_where_update_visible_tiles_was_called_; | 245 int last_draw_attempt_count_draw_was_called_; |
| 246 int last_begin_frame_count_begin_frame_sent_to_main_thread_; |
| 247 int last_draw_attempt_count_tree_activation_attempted_; |
| 248 int last_draw_attempt_count_completed_tile_uploads_checked_; |
| 249 int last_draw_attempt_count_update_visible_tiles_was_called_; |
| 250 |
| 226 int consecutive_failed_draws_; | 251 int consecutive_failed_draws_; |
| 227 int maximum_number_of_failed_draws_before_draw_is_forced_; | 252 int maximum_number_of_failed_draws_before_draw_is_forced_; |
| 253 |
| 228 bool needs_redraw_; | 254 bool needs_redraw_; |
| 229 bool swap_used_incomplete_tile_; | 255 bool swap_used_incomplete_tile_; |
| 230 bool needs_commit_; | 256 bool needs_commit_; |
| 231 bool main_thread_needs_layer_textures_; | 257 bool main_thread_needs_layer_textures_; |
| 232 bool inside_begin_frame_; | |
| 233 BeginFrameArgs last_begin_frame_args_; | |
| 234 bool visible_; | 258 bool visible_; |
| 235 bool can_start_; | 259 bool can_start_; |
| 236 bool can_draw_; | 260 bool can_draw_; |
| 237 bool has_pending_tree_; | 261 bool has_pending_tree_; |
| 238 bool pending_tree_is_ready_for_activation_; | 262 bool pending_tree_is_ready_for_activation_; |
| 239 bool active_tree_has_been_drawn_; | 263 bool active_tree_has_been_drawn_; |
| 240 bool draw_if_possible_failed_; | 264 bool draw_if_possible_failed_; |
| 241 bool did_create_and_initialize_first_output_surface_; | 265 bool did_create_and_initialize_first_output_surface_; |
| 242 | 266 |
| 243 private: | 267 private: |
| 244 DISALLOW_COPY_AND_ASSIGN(SchedulerStateMachine); | 268 DISALLOW_COPY_AND_ASSIGN(SchedulerStateMachine); |
| 245 }; | 269 }; |
| 246 | 270 |
| 247 } // namespace cc | 271 } // namespace cc |
| 248 | 272 |
| 249 #endif // CC_SCHEDULER_SCHEDULER_STATE_MACHINE_H_ | 273 #endif // CC_SCHEDULER_SCHEDULER_STATE_MACHINE_H_ |
| OLD | NEW |