Chromium Code Reviews| 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, | |
|
danakj
2013/09/17 20:26:19
I am anti-"pending" in these names as they are not
brianderson
2013/09/17 21:08:24
Done.
| |
| 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; | |
|
danakj
2013/09/17 20:26:19
This is going to affect the unit tests that do not
brianderson
2013/09/17 21:08:24
Ok. To recap offline discussions: I thought I need
| |
| 87 } | 98 } |
| 88 | 99 |
| 89 bool RedrawPending() const { return needs_redraw_; } | 100 bool RedrawPending() const { return needs_redraw_; } |
| 90 bool ManageTilesPending() const { return needs_manage_tiles_; } | 101 bool ManageTilesPending() const { return needs_manage_tiles_; } |
| 91 | 102 |
| 92 enum Action { | 103 enum Action { |
| 93 ACTION_NONE, | 104 ACTION_NONE, |
| 94 ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD, | 105 ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD, |
| 95 ACTION_COMMIT, | 106 ACTION_COMMIT, |
| 96 ACTION_UPDATE_VISIBLE_TILES, | 107 ACTION_UPDATE_VISIBLE_TILES, |
| 97 ACTION_ACTIVATE_PENDING_TREE, | 108 ACTION_ACTIVATE_PENDING_TREE, |
| 98 ACTION_DRAW_AND_SWAP_IF_POSSIBLE, | 109 ACTION_DRAW_AND_SWAP_IF_POSSIBLE, |
| 99 ACTION_DRAW_AND_SWAP_FORCED, | 110 ACTION_DRAW_AND_SWAP_FORCED, |
| 100 ACTION_DRAW_AND_SWAP_ABORT, | 111 ACTION_DRAW_AND_SWAP_ABORT, |
| 101 ACTION_DRAW_AND_READBACK, | 112 ACTION_DRAW_AND_READBACK, |
| 102 ACTION_BEGIN_OUTPUT_SURFACE_CREATION, | 113 ACTION_BEGIN_OUTPUT_SURFACE_CREATION, |
| 103 ACTION_ACQUIRE_LAYER_TEXTURES_FOR_MAIN_THREAD, | 114 ACTION_ACQUIRE_LAYER_TEXTURES_FOR_MAIN_THREAD, |
| 104 ACTION_MANAGE_TILES, | 115 ACTION_MANAGE_TILES, |
| 105 }; | 116 }; |
| 106 static const char* ActionToString(Action action); | 117 static const char* ActionToString(Action action); |
| 107 | 118 |
| 108 scoped_ptr<base::Value> AsValue() const; | 119 scoped_ptr<base::Value> AsValue() const; |
| 109 | 120 |
| 110 Action NextAction() const; | 121 Action NextAction() const; |
| 111 void UpdateState(Action action); | 122 void UpdateState(Action action); |
| 123 | |
| 112 void CheckInvariants(); | 124 void CheckInvariants(); |
| 113 | 125 |
| 114 // Indicates whether the main thread needs a begin frame callback in order to | 126 // Indicates whether the main thread needs a begin frame callback in order to |
| 115 // make progress. | 127 // make progress. |
| 116 bool BeginFrameNeededToDrawByImplThread() const; | 128 bool BeginFrameNeededByImplThread() const; |
| 117 bool ProactiveBeginFrameWantedByImplThread() const; | 129 |
| 130 // Idicates that we need to independently poll for new state and actions | |
| 131 // because we can't expect a BeginFrame. This is mostly used to avoid | |
| 132 // drawing repeat frames with the synchronous compositor without dropping | |
| 133 // necessary actions on the floor. | |
| 134 bool ShouldPollForAnticipatedDrawTriggers() const; | |
| 118 | 135 |
| 119 // Indicates that the system has entered and left a BeginFrame callback. | 136 // Indicates that the system has entered and left a BeginFrame callback. |
| 120 // The scheduler will not draw more than once in a given BeginFrame | 137 // The scheduler will not draw more than once in a given BeginFrame |
| 121 // callback nor send more than one BeginFrame message. | 138 // callback nor send more than one BeginFrame message. |
| 122 void DidEnterBeginFrame(const BeginFrameArgs& args); | 139 void OnBeginFrame(const BeginFrameArgs& args); |
| 123 void DidLeaveBeginFrame(); | 140 void OnBeginFrameDeadlinePending(); |
| 124 bool inside_begin_frame() const { return inside_begin_frame_; } | 141 void OnBeginFrameDeadline(); |
| 142 void OnBeginFrameIdle(); | |
| 143 bool ShouldTriggerBeginFrameDeadlineEarly() const; | |
| 144 BeginFrameState begin_frame_state() const { | |
| 145 return begin_frame_state_; | |
| 146 } | |
| 125 | 147 |
| 126 // PollForAnticipatedDrawTriggers is used by the synchronous compositor to | 148 // PollForAnticipatedDrawTriggers is used by the synchronous compositor to |
| 127 // avoid requesting BeginImplFrames when we won't actually draw but still | 149 // avoid requesting BeginImplFrames when we won't actually draw but still |
| 128 // need to advance our state at vsync intervals. | 150 // need to advance our state at vsync intervals. |
| 129 void DidEnterPollForAnticipatedDrawTriggers(); | 151 void DidEnterPollForAnticipatedDrawTriggers(); |
| 130 void DidLeavePollForAnticipatedDrawTriggers(); | 152 void DidLeavePollForAnticipatedDrawTriggers(); |
| 131 bool inside_poll_for_anticipated_draw_triggers() const { | 153 bool inside_poll_for_anticipated_draw_triggers() const { |
| 132 return inside_poll_for_anticipated_draw_triggers_; | 154 return inside_poll_for_anticipated_draw_triggers_; |
| 133 } | 155 } |
| 134 | 156 |
| 135 // Indicates whether the LayerTreeHostImpl is visible. | 157 // Indicates whether the LayerTreeHostImpl is visible. |
| 136 void SetVisible(bool visible); | 158 void SetVisible(bool visible); |
| 137 | 159 |
| 138 // Indicates that a redraw is required, either due to the impl tree changing | 160 // Indicates that a redraw is required, either due to the impl tree changing |
| 139 // or the screen being damaged and simply needing redisplay. | 161 // or the screen being damaged and simply needing redisplay. |
| 140 void SetNeedsRedraw(); | 162 void SetNeedsRedraw(); |
| 163 bool needs_redraw() const { return needs_redraw_; } | |
| 141 | 164 |
| 142 // Indicates that manage-tiles is required. This guarantees another | 165 // Indicates that manage-tiles is required. This guarantees another |
| 143 // ManageTiles will occur shortly (even if no redraw is required). | 166 // ManageTiles will occur shortly (even if no redraw is required). |
| 144 void SetNeedsManageTiles(); | 167 void SetNeedsManageTiles(); |
| 145 | 168 |
| 146 // Indicates whether a redraw is required because we are currently rendering | 169 // Indicates whether a redraw is required because we are currently rendering |
| 147 // with a low resolution or checkerboarded tile. | 170 // with a low resolution or checkerboarded tile. |
| 148 void SetSwapUsedIncompleteTile(bool used_incomplete_tile); | 171 void SetSwapUsedIncompleteTile(bool used_incomplete_tile); |
| 149 | 172 |
| 150 // Indicates whether ACTION_DRAW_AND_SWAP_IF_POSSIBLE drew to the screen or | 173 // Indicates whether ACTION_DRAW_AND_SWAP_IF_POSSIBLE drew to the screen. |
| 151 // not. | |
| 152 void DidDrawIfPossibleCompleted(bool success); | 174 void DidDrawIfPossibleCompleted(bool success); |
| 153 | 175 |
| 154 // Indicates that a new commit flow needs to be performed, either to pull | 176 // Indicates that a new commit flow needs to be performed, either to pull |
| 155 // updates from the main thread to the impl, or to push deltas from the impl | 177 // updates from the main thread to the impl, or to push deltas from the impl |
| 156 // thread to main. | 178 // thread to main. |
| 157 void SetNeedsCommit(); | 179 void SetNeedsCommit(); |
| 158 | 180 |
| 159 // As SetNeedsCommit(), but ensures the begin frame will be sent to the main | 181 // As SetNeedsCommit(), but ensures the begin frame will be sent to the main |
| 160 // thread even if we are not visible. After this call we expect to go through | 182 // thread even if we are not visible. After this call we expect to go through |
| 161 // the forced commit flow and then return to waiting for a non-forced | 183 // the forced commit flow and then return to waiting for a non-forced |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 194 bool has_pending_tree() const { return has_pending_tree_; } | 216 bool has_pending_tree() const { return has_pending_tree_; } |
| 195 | 217 |
| 196 void DidLoseOutputSurface(); | 218 void DidLoseOutputSurface(); |
| 197 void DidCreateAndInitializeOutputSurface(); | 219 void DidCreateAndInitializeOutputSurface(); |
| 198 bool HasInitializedOutputSurface() const; | 220 bool HasInitializedOutputSurface() const; |
| 199 | 221 |
| 200 // True if we need to abort draws to make forward progress. | 222 // True if we need to abort draws to make forward progress. |
| 201 bool PendingDrawsShouldBeAborted() const; | 223 bool PendingDrawsShouldBeAborted() const; |
| 202 | 224 |
| 203 protected: | 225 protected: |
| 226 bool BeginFrameNeededToDrawByImplThread() const; | |
| 227 bool ProactiveBeginFrameWantedByImplThread() const; | |
| 228 | |
| 204 // True if we need to force activations to make forward progress. | 229 // True if we need to force activations to make forward progress. |
| 205 bool PendingActivationsShouldBeForced() const; | 230 bool PendingActivationsShouldBeForced() const; |
| 206 | 231 |
| 207 bool ShouldBeginOutputSurfaceCreation() const; | 232 bool ShouldBeginOutputSurfaceCreation() const; |
| 208 bool ShouldDrawForced() const; | 233 bool ShouldDrawForced() const; |
| 209 bool ShouldDraw() const; | 234 bool ShouldDraw() const; |
| 210 bool ShouldActivatePendingTree() const; | 235 bool ShouldActivatePendingTree() const; |
| 211 bool ShouldAcquireLayerTexturesForMainThread() const; | 236 bool ShouldAcquireLayerTexturesForMainThread() const; |
| 212 bool ShouldUpdateVisibleTiles() const; | 237 bool ShouldUpdateVisibleTiles() const; |
| 213 bool ShouldSendBeginFrameToMainThread() const; | 238 bool ShouldSendBeginFrameToMainThread() const; |
| 214 bool ShouldCommit() const; | 239 bool ShouldCommit() const; |
| 215 bool ShouldManageTiles() const; | 240 bool ShouldManageTiles() const; |
| 216 | 241 |
| 217 bool HasDrawnAndSwappedThisFrame() const; | |
| 218 bool HasActivatedPendingTreeThisFrame() const; | |
| 219 bool HasUpdatedVisibleTilesThisFrame() const; | |
| 220 bool HasSentBeginFrameToMainThreadThisFrame() const; | 242 bool HasSentBeginFrameToMainThreadThisFrame() const; |
| 221 bool HasScheduledManageTilesThisFrame() const; | 243 bool HasScheduledManageTilesThisFrame() const; |
| 244 bool HasUpdatedVisibleTilesThisFrame() const; | |
| 245 bool HasSwappedThisFrame() const; | |
| 222 | 246 |
| 223 void UpdateStateOnCommit(bool commit_was_aborted); | 247 void UpdateStateOnCommit(bool commit_was_aborted); |
| 224 void UpdateStateOnActivation(); | 248 void UpdateStateOnActivation(); |
| 225 void UpdateStateOnDraw(bool did_swap); | 249 void UpdateStateOnDraw(bool did_swap); |
| 226 void UpdateStateOnManageTiles(); | 250 void UpdateStateOnManageTiles(); |
| 227 | 251 |
| 228 const SchedulerSettings settings_; | 252 const SchedulerSettings settings_; |
| 229 | 253 |
| 230 OutputSurfaceState output_surface_state_; | 254 OutputSurfaceState output_surface_state_; |
| 255 BeginFrameState begin_frame_state_; | |
| 231 CommitState commit_state_; | 256 CommitState commit_state_; |
| 232 TextureState texture_state_; | 257 TextureState texture_state_; |
| 233 ForcedRedrawOnTimeoutState forced_redraw_state_; | 258 ForcedRedrawOnTimeoutState forced_redraw_state_; |
| 234 SynchronousReadbackState readback_state_; | 259 SynchronousReadbackState readback_state_; |
| 235 | 260 |
| 261 BeginFrameArgs last_begin_frame_args_; | |
| 262 | |
| 236 int commit_count_; | 263 int commit_count_; |
| 237 int current_frame_number_; | 264 int current_frame_number_; |
| 238 int last_frame_number_where_begin_frame_sent_to_main_thread_; | |
| 239 int last_frame_number_swap_performed_; | 265 int last_frame_number_swap_performed_; |
| 240 int last_frame_number_where_update_visible_tiles_was_called_; | 266 int last_frame_number_begin_frame_sent_to_main_thread_; |
| 267 int last_frame_number_update_visible_tiles_was_called_; | |
| 268 | |
| 241 int consecutive_failed_draws_; | 269 int consecutive_failed_draws_; |
| 242 bool needs_redraw_; | 270 bool needs_redraw_; |
| 243 bool needs_manage_tiles_; | 271 bool needs_manage_tiles_; |
| 244 bool swap_used_incomplete_tile_; | 272 bool swap_used_incomplete_tile_; |
| 245 bool needs_commit_; | 273 bool needs_commit_; |
| 246 bool main_thread_needs_layer_textures_; | 274 bool main_thread_needs_layer_textures_; |
| 247 bool inside_begin_frame_; | |
| 248 bool inside_poll_for_anticipated_draw_triggers_; | 275 bool inside_poll_for_anticipated_draw_triggers_; |
| 249 | |
| 250 BeginFrameArgs last_begin_frame_args_; | |
| 251 bool visible_; | 276 bool visible_; |
| 252 bool can_start_; | 277 bool can_start_; |
| 253 bool can_draw_; | 278 bool can_draw_; |
| 254 bool has_pending_tree_; | 279 bool has_pending_tree_; |
| 255 bool pending_tree_is_ready_for_activation_; | 280 bool pending_tree_is_ready_for_activation_; |
| 256 bool active_tree_needs_first_draw_; | 281 bool active_tree_needs_first_draw_; |
| 257 bool draw_if_possible_failed_; | 282 bool draw_if_possible_failed_; |
| 258 bool did_create_and_initialize_first_output_surface_; | 283 bool did_create_and_initialize_first_output_surface_; |
| 259 | 284 |
| 260 private: | 285 private: |
| 261 DISALLOW_COPY_AND_ASSIGN(SchedulerStateMachine); | 286 DISALLOW_COPY_AND_ASSIGN(SchedulerStateMachine); |
| 262 }; | 287 }; |
| 263 | 288 |
| 264 } // namespace cc | 289 } // namespace cc |
| 265 | 290 |
| 266 #endif // CC_SCHEDULER_SCHEDULER_STATE_MACHINE_H_ | 291 #endif // CC_SCHEDULER_SCHEDULER_STATE_MACHINE_H_ |
| OLD | NEW |