| 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 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 enum CommitState { | 48 enum CommitState { |
| 49 COMMIT_STATE_IDLE, | 49 COMMIT_STATE_IDLE, |
| 50 COMMIT_STATE_FRAME_IN_PROGRESS, | 50 COMMIT_STATE_FRAME_IN_PROGRESS, |
| 51 COMMIT_STATE_READY_TO_COMMIT, | 51 COMMIT_STATE_READY_TO_COMMIT, |
| 52 COMMIT_STATE_WAITING_FOR_FIRST_DRAW, | 52 COMMIT_STATE_WAITING_FOR_FIRST_DRAW, |
| 53 COMMIT_STATE_WAITING_FOR_FIRST_FORCED_DRAW, | |
| 54 }; | 53 }; |
| 55 static const char* CommitStateToString(CommitState state); | 54 static const char* CommitStateToString(CommitState state); |
| 56 | 55 |
| 57 enum TextureState { | 56 enum TextureState { |
| 58 LAYER_TEXTURE_STATE_UNLOCKED, | 57 LAYER_TEXTURE_STATE_UNLOCKED, |
| 59 LAYER_TEXTURE_STATE_ACQUIRED_BY_MAIN_THREAD, | 58 LAYER_TEXTURE_STATE_ACQUIRED_BY_MAIN_THREAD, |
| 60 LAYER_TEXTURE_STATE_ACQUIRED_BY_IMPL_THREAD, | 59 LAYER_TEXTURE_STATE_ACQUIRED_BY_IMPL_THREAD, |
| 61 }; | 60 }; |
| 62 static const char* TextureStateToString(TextureState state); | 61 static const char* TextureStateToString(TextureState state); |
| 63 | 62 |
| 63 enum SynchronousReadbackState { |
| 64 READBACK_STATE_IDLE, |
| 65 READBACK_STATE_NEEDS_BEGIN_FRAME, |
| 66 READBACK_STATE_WAITING_FOR_COMMIT, |
| 67 READBACK_STATE_WAITING_FOR_ACTIVATION, |
| 68 READBACK_STATE_WAITING_FOR_DRAW_AND_READBACK, |
| 69 READBACK_STATE_WAITING_FOR_REPLACEMENT_COMMIT, |
| 70 READBACK_STATE_WAITING_FOR_REPLACEMENT_ACTIVATION, |
| 71 }; |
| 72 static const char* SynchronousReadbackStateToString( |
| 73 SynchronousReadbackState state); |
| 74 |
| 75 enum ForcedRedrawOnTimeoutState { |
| 76 FORCED_REDRAW_STATE_IDLE, |
| 77 FORCED_REDRAW_STATE_WAITING_FOR_COMMIT, |
| 78 FORCED_REDRAW_STATE_WAITING_FOR_ACTIVATION, |
| 79 FORCED_REDRAW_STATE_WAITING_FOR_DRAW, |
| 80 }; |
| 81 static const char* ForcedRedrawOnTimeoutStateToString( |
| 82 ForcedRedrawOnTimeoutState state); |
| 83 |
| 64 bool CommitPending() const { | 84 bool CommitPending() const { |
| 65 return commit_state_ == COMMIT_STATE_FRAME_IN_PROGRESS || | 85 return commit_state_ == COMMIT_STATE_FRAME_IN_PROGRESS || |
| 66 commit_state_ == COMMIT_STATE_READY_TO_COMMIT; | 86 commit_state_ == COMMIT_STATE_READY_TO_COMMIT; |
| 67 } | 87 } |
| 68 | 88 |
| 69 bool RedrawPending() const { return needs_redraw_; } | 89 bool RedrawPending() const { return needs_redraw_; } |
| 70 | 90 |
| 71 enum Action { | 91 enum Action { |
| 72 ACTION_NONE, | 92 ACTION_NONE, |
| 73 ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD, | 93 ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD, |
| 74 ACTION_COMMIT, | 94 ACTION_COMMIT, |
| 75 ACTION_UPDATE_VISIBLE_TILES, | 95 ACTION_UPDATE_VISIBLE_TILES, |
| 76 ACTION_ACTIVATE_PENDING_TREE, | 96 ACTION_ACTIVATE_PENDING_TREE, |
| 77 ACTION_DRAW_IF_POSSIBLE, | 97 ACTION_DRAW_AND_SWAP_IF_POSSIBLE, |
| 78 ACTION_DRAW_FORCED, | 98 ACTION_DRAW_AND_SWAP_FORCED, |
| 79 ACTION_DRAW_AND_SWAP_ABORT, | 99 ACTION_DRAW_AND_SWAP_ABORT, |
| 100 ACTION_DRAW_AND_READBACK, |
| 80 ACTION_BEGIN_OUTPUT_SURFACE_CREATION, | 101 ACTION_BEGIN_OUTPUT_SURFACE_CREATION, |
| 81 ACTION_ACQUIRE_LAYER_TEXTURES_FOR_MAIN_THREAD, | 102 ACTION_ACQUIRE_LAYER_TEXTURES_FOR_MAIN_THREAD, |
| 82 }; | 103 }; |
| 83 static const char* ActionToString(Action action); | 104 static const char* ActionToString(Action action); |
| 84 | 105 |
| 85 scoped_ptr<base::Value> AsValue() const; | 106 scoped_ptr<base::Value> AsValue() const; |
| 86 | 107 |
| 87 Action NextAction() const; | 108 Action NextAction() const; |
| 88 void UpdateState(Action action); | 109 void UpdateState(Action action); |
| 110 void CheckInvariants(); |
| 89 | 111 |
| 90 // Indicates whether the main thread needs a begin frame callback in order to | 112 // Indicates whether the main thread needs a begin frame callback in order to |
| 91 // make progress. | 113 // make progress. |
| 92 bool BeginFrameNeededToDrawByImplThread() const; | 114 bool BeginFrameNeededToDrawByImplThread() const; |
| 93 bool ProactiveBeginFrameWantedByImplThread() const; | 115 bool ProactiveBeginFrameWantedByImplThread() const; |
| 94 | 116 |
| 95 // Indicates that the system has entered and left a BeginFrame callback. | 117 // Indicates that the system has entered and left a BeginFrame callback. |
| 96 // The scheduler will not draw more than once in a given BeginFrame | 118 // The scheduler will not draw more than once in a given BeginFrame |
| 97 // callback nor send more than one BeginFrame message. | 119 // callback nor send more than one BeginFrame message. |
| 98 void DidEnterBeginFrame(const BeginFrameArgs& args); | 120 void DidEnterBeginFrame(const BeginFrameArgs& args); |
| 99 void DidLeaveBeginFrame(); | 121 void DidLeaveBeginFrame(); |
| 100 bool inside_begin_frame() const { return inside_begin_frame_; } | 122 bool inside_begin_frame() const { return inside_begin_frame_; } |
| 101 | 123 |
| 102 // Indicates whether the LayerTreeHostImpl is visible. | 124 // Indicates whether the LayerTreeHostImpl is visible. |
| 103 void SetVisible(bool visible); | 125 void SetVisible(bool visible); |
| 104 | 126 |
| 105 // Indicates that a redraw is required, either due to the impl tree changing | 127 // Indicates that a redraw is required, either due to the impl tree changing |
| 106 // or the screen being damaged and simply needing redisplay. | 128 // or the screen being damaged and simply needing redisplay. |
| 107 void SetNeedsRedraw(); | 129 void SetNeedsRedraw(); |
| 108 | 130 |
| 109 // As SetNeedsRedraw(), but ensures the draw will definitely happen even if | |
| 110 // we are not visible. | |
| 111 void SetNeedsForcedRedraw(); | |
| 112 | |
| 113 // Indicates that a redraw is required because we are currently rendering | 131 // Indicates that a redraw is required because we are currently rendering |
| 114 // with a low resolution or checkerboarded tile. | 132 // with a low resolution or checkerboarded tile. |
| 115 void DidSwapUseIncompleteTile(); | 133 void DidSwapUseIncompleteTile(); |
| 116 | 134 |
| 117 // Indicates whether ACTION_DRAW_IF_POSSIBLE drew to the screen or not. | 135 // Indicates whether ACTION_DRAW_AND_SWAP_IF_POSSIBLE drew to the screen or |
| 136 // not. |
| 118 void DidDrawIfPossibleCompleted(bool success); | 137 void DidDrawIfPossibleCompleted(bool success); |
| 119 | 138 |
| 120 // Indicates that a new commit flow needs to be performed, either to pull | 139 // Indicates that a new commit flow needs to be performed, either to pull |
| 121 // updates from the main thread to the impl, or to push deltas from the impl | 140 // updates from the main thread to the impl, or to push deltas from the impl |
| 122 // thread to main. | 141 // thread to main. |
| 123 void SetNeedsCommit(); | 142 void SetNeedsCommit(); |
| 124 | 143 |
| 125 // As SetNeedsCommit(), but ensures the begin frame will be sent to the main | 144 // As SetNeedsCommit(), but ensures the begin frame will be sent to the main |
| 126 // thread even if we are not visible. After this call we expect to go through | 145 // thread even if we are not visible. After this call we expect to go through |
| 127 // the forced commit flow and then return to waiting for a non-forced | 146 // the forced commit flow and then return to waiting for a non-forced |
| 128 // begin frame to finish. | 147 // begin frame to finish. |
| 129 void SetNeedsForcedCommit(); | 148 void SetNeedsForcedCommitForReadback(); |
| 130 | 149 |
| 131 // Call this only in response to receiving an | 150 // Call this only in response to receiving an |
| 132 // ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD from NextAction. | 151 // ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD from NextAction. |
| 133 // Indicates that all painting is complete. | 152 // Indicates that all painting is complete. |
| 134 void FinishCommit(); | 153 void FinishCommit(); |
| 135 | 154 |
| 136 // Call this only in response to receiving an | 155 // Call this only in response to receiving an |
| 137 // ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD from NextAction if the client | 156 // ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD from NextAction if the client |
| 138 // rejects the begin frame message. If did_handle is false, then | 157 // rejects the begin frame message. If did_handle is false, then |
| 139 // another commit will be retried soon. | 158 // another commit will be retried soon. |
| 140 void BeginFrameAbortedByMainThread(bool did_handle); | 159 void BeginFrameAbortedByMainThread(bool did_handle); |
| 141 | 160 |
| 142 // Request exclusive access to the textures that back single buffered | 161 // Request exclusive access to the textures that back single buffered |
| 143 // layers on behalf of the main thread. Upon acquisition, | 162 // layers on behalf of the main thread. Upon acquisition, |
| 144 // ACTION_DRAW_IF_POSSIBLE will not draw until the main thread releases the | 163 // ACTION_DRAW_AND_SWAP_IF_POSSIBLE will not draw until the main thread |
| 164 // releases the |
| 145 // textures to the impl thread by committing the layers. | 165 // textures to the impl thread by committing the layers. |
| 146 void SetMainThreadNeedsLayerTextures(); | 166 void SetMainThreadNeedsLayerTextures(); |
| 147 | 167 |
| 148 // Set that we can create the first OutputSurface and start the scheduler. | 168 // Set that we can create the first OutputSurface and start the scheduler. |
| 149 void SetCanStart() { can_start_ = true; } | 169 void SetCanStart() { can_start_ = true; } |
| 150 | 170 |
| 151 // Indicates whether drawing would, at this time, make sense. | 171 // Indicates whether drawing would, at this time, make sense. |
| 152 // CanDraw can be used to supress flashes or checkerboarding | 172 // CanDraw can be used to supress flashes or checkerboarding |
| 153 // when such behavior would be undesirable. | 173 // when such behavior would be undesirable. |
| 154 void SetCanDraw(bool can); | 174 void SetCanDraw(bool can); |
| 155 | 175 |
| 156 // Indicates that the pending tree is ready for activation. | 176 // Indicates that the pending tree is ready for activation. |
| 157 void NotifyReadyToActivate(); | 177 void NotifyReadyToActivate(); |
| 158 | 178 |
| 159 bool has_pending_tree() const { return has_pending_tree_; } | 179 bool has_pending_tree() const { return has_pending_tree_; } |
| 160 | 180 |
| 161 void DidLoseOutputSurface(); | 181 void DidLoseOutputSurface(); |
| 162 void DidCreateAndInitializeOutputSurface(); | 182 void DidCreateAndInitializeOutputSurface(); |
| 163 bool HasInitializedOutputSurface() const; | 183 bool HasInitializedOutputSurface() const; |
| 164 | 184 |
| 165 // Exposed for testing purposes. | |
| 166 void SetMaximumNumberOfFailedDrawsBeforeDrawIsForced(int num_draws); | |
| 167 | |
| 168 // True if we need to abort draws to make forward progress. | 185 // True if we need to abort draws to make forward progress. |
| 169 bool PendingDrawsShouldBeAborted() const; | 186 bool PendingDrawsShouldBeAborted() const; |
| 170 | 187 |
| 171 protected: | 188 protected: |
| 172 // True if we need to force activations to make forward progress. | 189 // True if we need to force activations to make forward progress. |
| 173 bool PendingActivationsShouldBeForced() const; | 190 bool PendingActivationsShouldBeForced() const; |
| 174 | 191 |
| 175 bool ShouldBeginOutputSurfaceCreation() const; | 192 bool ShouldBeginOutputSurfaceCreation() const; |
| 176 bool ShouldDrawForced() const; | 193 bool ShouldDrawForced() const; |
| 177 bool ShouldDraw() const; | 194 bool ShouldDraw() const; |
| 178 bool ShouldActivatePendingTree() const; | 195 bool ShouldActivatePendingTree() const; |
| 179 bool ShouldAcquireLayerTexturesForMainThread() const; | 196 bool ShouldAcquireLayerTexturesForMainThread() const; |
| 180 bool ShouldUpdateVisibleTiles() const; | 197 bool ShouldUpdateVisibleTiles() const; |
| 181 bool ShouldSendBeginFrameToMainThread() const; | 198 bool ShouldSendBeginFrameToMainThread() const; |
| 182 bool ShouldCommit() const; | 199 bool ShouldCommit() const; |
| 183 | 200 |
| 184 bool HasDrawnThisFrame() const; | 201 bool HasDrawnAndSwappedThisFrame() const; |
| 185 bool HasActivatedPendingTreeThisFrame() const; | 202 bool HasActivatedPendingTreeThisFrame() const; |
| 186 bool HasUpdatedVisibleTilesThisFrame() const; | 203 bool HasUpdatedVisibleTilesThisFrame() const; |
| 187 bool HasSentBeginFrameToMainThreadThisFrame() const; | 204 bool HasSentBeginFrameToMainThreadThisFrame() const; |
| 188 | 205 |
| 189 void UpdateStateOnCommit(bool commit_was_aborted); | 206 void UpdateStateOnCommit(bool commit_was_aborted); |
| 190 void UpdateStateOnActivation(); | 207 void UpdateStateOnActivation(); |
| 191 void UpdateStateOnDraw(bool did_swap); | 208 void UpdateStateOnDraw(bool did_swap); |
| 192 | 209 |
| 193 const SchedulerSettings settings_; | 210 const SchedulerSettings settings_; |
| 194 | 211 |
| 195 OutputSurfaceState output_surface_state_; | 212 OutputSurfaceState output_surface_state_; |
| 196 CommitState commit_state_; | 213 CommitState commit_state_; |
| 214 TextureState texture_state_; |
| 215 ForcedRedrawOnTimeoutState forced_redraw_state_; |
| 216 SynchronousReadbackState readback_state_; |
| 197 | 217 |
| 198 int commit_count_; | 218 int commit_count_; |
| 199 int current_frame_number_; | 219 int current_frame_number_; |
| 200 int last_frame_number_where_begin_frame_sent_to_main_thread_; | 220 int last_frame_number_where_begin_frame_sent_to_main_thread_; |
| 201 int last_frame_number_where_draw_was_called_; | 221 int last_frame_number_swap_performed_; |
| 202 int last_frame_number_where_update_visible_tiles_was_called_; | 222 int last_frame_number_where_update_visible_tiles_was_called_; |
| 203 int consecutive_failed_draws_; | 223 int consecutive_failed_draws_; |
| 204 int maximum_number_of_failed_draws_before_draw_is_forced_; | |
| 205 bool needs_redraw_; | 224 bool needs_redraw_; |
| 206 bool swap_used_incomplete_tile_; | 225 bool swap_used_incomplete_tile_; |
| 207 bool needs_forced_redraw_; | |
| 208 bool needs_forced_redraw_after_next_commit_; | |
| 209 bool needs_commit_; | 226 bool needs_commit_; |
| 210 bool needs_forced_commit_; | |
| 211 bool expect_immediate_begin_frame_for_main_thread_; | |
| 212 bool main_thread_needs_layer_textures_; | 227 bool main_thread_needs_layer_textures_; |
| 213 bool inside_begin_frame_; | 228 bool inside_begin_frame_; |
| 214 BeginFrameArgs last_begin_frame_args_; | 229 BeginFrameArgs last_begin_frame_args_; |
| 215 bool visible_; | 230 bool visible_; |
| 216 bool can_start_; | 231 bool can_start_; |
| 217 bool can_draw_; | 232 bool can_draw_; |
| 218 bool has_pending_tree_; | 233 bool has_pending_tree_; |
| 219 bool pending_tree_is_ready_for_activation_; | 234 bool pending_tree_is_ready_for_activation_; |
| 220 bool active_tree_has_been_drawn_; | 235 bool active_tree_needs_first_draw_; |
| 221 bool draw_if_possible_failed_; | 236 bool draw_if_possible_failed_; |
| 222 TextureState texture_state_; | |
| 223 bool did_create_and_initialize_first_output_surface_; | 237 bool did_create_and_initialize_first_output_surface_; |
| 224 | 238 |
| 225 private: | 239 private: |
| 226 DISALLOW_COPY_AND_ASSIGN(SchedulerStateMachine); | 240 DISALLOW_COPY_AND_ASSIGN(SchedulerStateMachine); |
| 227 }; | 241 }; |
| 228 | 242 |
| 229 } // namespace cc | 243 } // namespace cc |
| 230 | 244 |
| 231 #endif // CC_SCHEDULER_SCHEDULER_STATE_MACHINE_H_ | 245 #endif // CC_SCHEDULER_SCHEDULER_STATE_MACHINE_H_ |
| OLD | NEW |