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 13 matching lines...) Expand all Loading... | |
| 24 // requested, while external state includes things like the current time being | 24 // requested, while external state includes things like the current time being |
| 25 // near to the vblank time. | 25 // near to the vblank time. |
| 26 // | 26 // |
| 27 // The scheduler seperates "what to do next" from the updating of its internal | 27 // The scheduler seperates "what to do next" from the updating of its internal |
| 28 // state to make testing cleaner. | 28 // state to make testing cleaner. |
| 29 class CC_EXPORT SchedulerStateMachine { | 29 class CC_EXPORT SchedulerStateMachine { |
| 30 public: | 30 public: |
| 31 // settings must be valid for the lifetime of this class. | 31 // settings must be valid for the lifetime of this class. |
| 32 explicit SchedulerStateMachine(const SchedulerSettings& settings); | 32 explicit SchedulerStateMachine(const SchedulerSettings& settings); |
| 33 | 33 |
| 34 // Note: BeginFrameState will always cycle through all the states in order. | |
| 35 // Whether or not it actually waits or draws, it will at least try to wait in | |
| 36 // BEGIN_FRAME_STATE_DEADLINE_PENDING and try to draw in | |
| 37 // BEGIN_FRAME_STATE_INSIDE_DEADLINE | |
| 38 enum BeginFrameState { | |
| 39 BEGIN_FRAME_STATE_IDLE, | |
| 40 BEGIN_FRAME_STATE_INSIDE_BEGIN_FRAME, | |
| 41 BEGIN_FRAME_STATE_DEADLINE_PENDING, | |
| 42 BEGIN_FRAME_STATE_INSIDE_DEADLINE, | |
| 43 }; | |
| 44 | |
| 34 enum CommitState { | 45 enum CommitState { |
| 35 COMMIT_STATE_IDLE, | 46 COMMIT_STATE_IDLE, |
| 36 COMMIT_STATE_FRAME_IN_PROGRESS, | 47 COMMIT_STATE_FRAME_IN_PROGRESS, |
| 37 COMMIT_STATE_READY_TO_COMMIT, | 48 COMMIT_STATE_READY_TO_COMMIT, |
| 49 COMMIT_STATE_WAITING_FOR_ACTIVATION, | |
| 38 COMMIT_STATE_WAITING_FOR_FIRST_DRAW, | 50 COMMIT_STATE_WAITING_FOR_FIRST_DRAW, |
| 39 COMMIT_STATE_WAITING_FOR_FIRST_FORCED_DRAW, | 51 COMMIT_STATE_WAITING_FOR_FIRST_FORCED_DRAW, |
| 40 }; | 52 }; |
| 41 | 53 |
| 42 enum TextureState { | 54 enum TextureState { |
| 43 LAYER_TEXTURE_STATE_UNLOCKED, | 55 LAYER_TEXTURE_STATE_UNLOCKED, |
| 44 LAYER_TEXTURE_STATE_ACQUIRED_BY_MAIN_THREAD, | 56 LAYER_TEXTURE_STATE_ACQUIRED_BY_MAIN_THREAD, |
| 45 LAYER_TEXTURE_STATE_ACQUIRED_BY_IMPL_THREAD, | 57 LAYER_TEXTURE_STATE_ACQUIRED_BY_IMPL_THREAD, |
| 46 }; | 58 }; |
| 47 | 59 |
| 60 enum SynchronousReadbackState { | |
|
brianderson
2013/07/17 02:31:01
Would like feedback on new readback states. It was
| |
| 61 READBACK_STATE_IDLE, | |
| 62 READBACK_STATE_FORCED_COMMIT_REQUESTED, | |
| 63 READBACK_STATE_FORCED_COMMIT_PENDING, | |
| 64 READBACK_STATE_WAITING_FOR_ACTIVATION, | |
| 65 READBACK_STATE_WAITING_FOR_DRAW_AND_READBACK, | |
| 66 READBACK_STATE_REPLACEMENT_COMMIT_PENDING, | |
| 67 READBACK_STATE_REPLACEMENT_COMMIT_ACTIVATING, | |
| 68 }; | |
| 69 | |
| 70 enum ForcedRedrawOnTimeoutState { | |
| 71 FORCED_REDRAW_STATE_IDLE, | |
| 72 FORCED_REDRAW_STATE_WAITING_FOR_COMMIT, | |
| 73 FORCED_REDRAW_STATE_WAITING_FOR_ACTIVATION, | |
| 74 FORCED_REDRAW_STATE_WAITING_FOR_DRAW, | |
| 75 }; | |
| 76 | |
| 48 enum OutputSurfaceState { | 77 enum OutputSurfaceState { |
| 49 OUTPUT_SURFACE_ACTIVE, | 78 OUTPUT_SURFACE_ACTIVE, |
| 50 OUTPUT_SURFACE_LOST, | 79 OUTPUT_SURFACE_LOST, |
| 51 OUTPUT_SURFACE_CREATING, | 80 OUTPUT_SURFACE_CREATING, |
| 52 }; | 81 }; |
| 53 | 82 |
| 54 bool CommitPending() const { | 83 bool CommitPending() const { |
| 55 return commit_state_ == COMMIT_STATE_FRAME_IN_PROGRESS || | 84 return commit_state_ == COMMIT_STATE_FRAME_IN_PROGRESS; |
| 56 commit_state_ == COMMIT_STATE_READY_TO_COMMIT; | |
| 57 } | 85 } |
| 58 | 86 |
| 59 bool RedrawPending() const { return needs_redraw_; } | 87 bool RedrawPending() const { return needs_redraw_; } |
| 60 | 88 |
| 61 enum Action { | 89 enum Action { |
| 62 ACTION_NONE, | 90 ACTION_NONE, |
| 63 ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD, | 91 ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD, |
| 64 ACTION_COMMIT, | 92 ACTION_COMMIT, |
| 65 ACTION_CHECK_FOR_COMPLETED_TILE_UPLOADS, | 93 ACTION_CHECK_FOR_COMPLETED_TILE_UPLOADS, |
| 66 ACTION_ACTIVATE_PENDING_TREE_IF_NEEDED, | 94 ACTION_ACTIVATE_PENDING_TREE_IF_NEEDED, |
| 67 ACTION_DRAW_IF_POSSIBLE, | 95 ACTION_DRAW_IF_POSSIBLE, |
| 68 ACTION_DRAW_FORCED, | 96 ACTION_DRAW_FORCED, |
| 97 ACTION_DRAW_AND_READBACK, | |
| 69 ACTION_BEGIN_OUTPUT_SURFACE_CREATION, | 98 ACTION_BEGIN_OUTPUT_SURFACE_CREATION, |
| 70 ACTION_ACQUIRE_LAYER_TEXTURES_FOR_MAIN_THREAD, | 99 ACTION_ACQUIRE_LAYER_TEXTURES_FOR_MAIN_THREAD, |
| 71 }; | 100 }; |
| 72 Action NextAction() const; | 101 Action NextAction() const; |
| 73 void UpdateState(Action action); | 102 void UpdateState(Action action); |
| 103 void AdvanceBeginFrameStateWhenNoActionsRemain(); | |
| 74 | 104 |
| 75 // Indicates whether the main thread needs a begin frame callback in order to | 105 // Indicates whether the main thread needs a begin frame callback in order to |
| 76 // make progress. | 106 // make progress. |
| 107 bool BeginFrameNeededByImplThread() const; | |
| 77 bool BeginFrameNeededToDrawByImplThread() const; | 108 bool BeginFrameNeededToDrawByImplThread() const; |
| 78 bool ProactiveBeginFrameWantedByImplThread() const; | 109 bool BeginFrameProactivelyNeededByImplThread() const; |
| 79 | 110 |
| 80 // Indicates that the system has entered and left a BeginFrame callback. | 111 // Indicates that the system has entered and left a BeginFrame callback. |
| 81 // The scheduler will not draw more than once in a given BeginFrame | 112 // The scheduler will not draw more than once in a given BeginFrame |
| 82 // callback. | 113 // callback. |
| 83 void DidEnterBeginFrame(const BeginFrameArgs& args); | 114 void OnBeginFrame(const BeginFrameArgs& args); |
| 84 void DidLeaveBeginFrame(); | 115 void OnBeginFrameDeadline(); |
| 85 bool inside_begin_frame() const { return inside_begin_frame_; } | 116 bool ShouldTriggerBeginFrameDeadlineEarly() const; |
| 117 bool InsideBeginFrame() const; | |
| 86 | 118 |
| 87 // Indicates whether the LayerTreeHostImpl is visible. | 119 // Indicates whether the LayerTreeHostImpl is visible. |
| 88 void SetVisible(bool visible); | 120 void SetVisible(bool visible); |
| 89 | 121 |
| 90 // Indicates that a redraw is required, either due to the impl tree changing | 122 // Indicates that a redraw is required, either due to the impl tree changing |
| 91 // or the screen being damaged and simply needing redisplay. | 123 // or the screen being damaged and simply needing redisplay. |
| 92 void SetNeedsRedraw(); | 124 void SetNeedsRedraw(); |
| 93 | 125 |
| 94 // As SetNeedsRedraw(), but ensures the draw will definitely happen even if | |
| 95 // we are not visible. | |
| 96 void SetNeedsForcedRedraw(); | |
| 97 | |
| 98 // Indicates that a redraw is required because we are currently rendering | 126 // Indicates that a redraw is required because we are currently rendering |
| 99 // with a low resolution or checkerboarded tile. | 127 // with a low resolution or checkerboarded tile. |
| 100 void DidSwapUseIncompleteTile(); | 128 void DidSwapUseIncompleteTile(); |
| 101 | 129 |
| 102 // Indicates whether ACTION_DRAW_IF_POSSIBLE drew to the screen or not. | 130 // Indicates whether ACTION_DRAW_IF_POSSIBLE drew to the screen or not. |
| 103 void DidDrawIfPossibleCompleted(bool success); | 131 void DidDrawIfPossibleCompleted(bool success); |
| 104 | 132 |
| 105 // Indicates that a new commit flow needs to be performed, either to pull | 133 // Indicates that a new commit flow needs to be performed, either to pull |
| 106 // updates from the main thread to the impl, or to push deltas from the impl | 134 // updates from the main thread to the impl, or to push deltas from the impl |
| 107 // thread to main. | 135 // thread to main. |
| 108 void SetNeedsCommit(); | 136 void SetNeedsCommit(); |
| 109 | 137 |
| 110 // As SetNeedsCommit(), but ensures the begin frame will be sent to the main | 138 // As SetNeedsCommit(), but ensures the begin frame will be sent to the main |
| 111 // thread even if we are not visible. After this call we expect to go through | 139 // thread even if we are not visible. After this call we expect to go through |
| 112 // the forced commit flow and then return to waiting for a non-forced | 140 // the forced commit flow and then return to waiting for a non-forced |
| 113 // begin frame to finish. | 141 // begin frame to finish. |
| 114 void SetNeedsForcedCommit(); | 142 void SetNeedsForcedCommitForReadback(); |
| 115 | 143 |
| 116 // Call this only in response to receiving an | 144 // Call this only in response to receiving an |
| 117 // ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD from NextAction. | 145 // ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD from NextAction. |
| 118 // Indicates that all painting is complete. | 146 // Indicates that all painting is complete. |
| 119 void FinishCommit(); | 147 void FinishCommit(); |
| 120 | 148 |
| 121 // Call this only in response to receiving an | 149 // Call this only in response to receiving an |
| 122 // ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD from NextAction if the client | 150 // ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD from NextAction if the client |
| 123 // rejects the begin frame message. | 151 // rejects the begin frame message. |
| 124 void BeginFrameAbortedByMainThread(); | 152 void BeginFrameAbortedByMainThread(); |
| 125 | 153 |
| 126 // Request exclusive access to the textures that back single buffered | 154 // Request exclusive access to the textures that back single buffered |
| 127 // layers on behalf of the main thread. Upon acquisition, | 155 // layers on behalf of the main thread. Upon acquisition, |
| 128 // ACTION_DRAW_IF_POSSIBLE will not draw until the main thread releases the | 156 // ACTION_DRAW_IF_POSSIBLE will not draw until the main thread releases the |
| 129 // textures to the impl thread by committing the layers. | 157 // textures to the impl thread by committing the layers. |
| 130 void SetMainThreadNeedsLayerTextures(); | 158 void SetMainThreadNeedsLayerTextures(); |
| 131 | 159 |
| 132 // Set that we can create the first OutputSurface and start the scheduler. | 160 // Set that we can create the first OutputSurface and start the scheduler. |
| 133 void SetCanStart() { can_start_ = true; } | 161 void SetCanStart() { can_start_ = true; } |
| 134 | 162 |
| 135 // Indicates whether drawing would, at this time, make sense. | 163 // Indicates whether drawing would, at this time, make sense. |
| 136 // CanDraw can be used to supress flashes or checkerboarding | 164 // CanDraw can be used to supress flashes or checkerboarding |
| 137 // when such behavior would be undesirable. | 165 // when such behavior would be undesirable. |
| 138 void SetCanDraw(bool can); | 166 void SetCanDraw(bool can_draw); |
| 139 | 167 |
| 140 // Indicates whether or not there is a pending tree. This influences | 168 // Indicates whether or not there is a pending tree (which may be null) |
| 141 // whether or not we can succesfully commit at this time. If the | 169 // and whether the active tree is null or not. This |
| 170 // influences whether or not we can succesfully commit at this time. If the | |
| 142 // last commit is still being processed (but not blocking), it may not | 171 // last commit is still being processed (but not blocking), it may not |
| 143 // be possible to take another commit yet. This overrides force commit, | 172 // be possible to take another commit yet. This overrides force commit, |
| 144 // as a commit is already still in flight. | 173 // as a commit is already still in flight. |
| 145 void SetHasPendingTree(bool has_pending_tree); | 174 void SetHasTrees(bool has_pending_tree, bool active_tree_is_null); |
| 146 bool has_pending_tree() const { return has_pending_tree_; } | 175 bool has_pending_tree() const { return has_pending_tree_; } |
| 147 | 176 |
| 148 void DidLoseOutputSurface(); | 177 void DidLoseOutputSurface(); |
| 149 void DidCreateAndInitializeOutputSurface(); | 178 void DidCreateAndInitializeOutputSurface(); |
| 150 bool HasInitializedOutputSurface() const; | 179 bool HasInitializedOutputSurface() const; |
| 151 | 180 |
| 152 // Exposed for testing purposes. | 181 // Exposed for testing purposes. |
| 153 void SetMaximumNumberOfFailedDrawsBeforeDrawIsForced(int num_draws); | 182 void SetMaximumNumberOfFailedDrawsBeforeDrawIsForced(int num_draws); |
| 154 | 183 |
| 155 // False if drawing is not being prevented, true if drawing won't happen | 184 // False if drawing is not being prevented, true if drawing won't happen |
| 156 // for some reason, such as not being visible. | 185 // for some reason, such as not being visible. |
| 157 bool DrawSuspendedUntilCommit() const; | 186 bool DrawSuspendedUntilCommit() const; |
| 158 | 187 |
| 159 std::string ToString(); | 188 std::string ToString(); |
| 160 | 189 |
| 161 protected: | 190 protected: |
| 162 bool ShouldDrawForced() const; | 191 bool ShouldDrawForced() const; |
| 163 bool ScheduledToDraw() const; | 192 bool ScheduledToDraw() const; |
| 193 bool WillDrawNewTree() const; | |
| 164 bool ShouldDraw() const; | 194 bool ShouldDraw() const; |
| 195 bool ShouldDrawInternal(BeginFrameState begin_frame_state) const; | |
| 165 bool ShouldAttemptTreeActivation() const; | 196 bool ShouldAttemptTreeActivation() const; |
| 166 bool ShouldAcquireLayerTexturesForMainThread() const; | 197 bool ShouldAcquireLayerTexturesForMainThread() const; |
| 167 bool ShouldCheckForCompletedTileUploads() const; | 198 bool ShouldCheckForCompletedTileUploads() const; |
| 199 bool ShouldSendBeginFrameToMainThread() const; | |
| 168 bool HasDrawnThisFrame() const; | 200 bool HasDrawnThisFrame() const; |
| 169 bool HasAttemptedTreeActivationThisFrame() const; | 201 bool HasAttemptedTreeActivationThisDrawAttempt() const; |
| 170 bool HasCheckedForCompletedTileUploadsThisFrame() const; | 202 bool HasCheckedForCompletedTileUploadsThisDrawAttempt() const; |
| 203 bool HasSentBeginFrameToMainThreadThisFrame() const; | |
| 171 | 204 |
| 172 const SchedulerSettings settings_; | 205 const SchedulerSettings settings_; |
| 173 | 206 |
| 174 CommitState commit_state_; | 207 CommitState commit_state_; |
| 175 int commit_count_; | 208 int commit_count_; |
| 176 | 209 |
| 177 int current_frame_number_; | 210 int begin_frame_count_; |
| 178 int last_frame_number_where_draw_was_called_; | 211 int begin_frame_deadline_count_; |
| 179 int last_frame_number_where_tree_activation_attempted_; | 212 int draw_attempt_count_; |
| 180 int last_frame_number_where_check_for_completed_tile_uploads_called_; | 213 int last_begin_frame_count_draw_was_called_; |
| 214 int last_begin_frame_count_begin_frame_sent_to_main_thread_; | |
| 215 int last_draw_attempt_count_tree_activation_attempted_; | |
| 216 int last_draw_attempt_count_completed_tile_uploads_checked_; | |
| 181 int consecutive_failed_draws_; | 217 int consecutive_failed_draws_; |
| 182 int maximum_number_of_failed_draws_before_draw_is_forced_; | 218 int maximum_number_of_failed_draws_before_draw_is_forced_; |
| 183 bool needs_redraw_; | 219 bool needs_redraw_; |
| 184 bool swap_used_incomplete_tile_; | 220 bool swap_used_incomplete_tile_; |
| 185 bool needs_forced_redraw_; | 221 SynchronousReadbackState readback_state_; |
| 186 bool needs_forced_redraw_after_next_commit_; | 222 ForcedRedrawOnTimeoutState forced_redraw_state_; |
| 187 bool needs_commit_; | 223 bool needs_commit_; |
| 188 bool needs_forced_commit_; | |
| 189 bool expect_immediate_begin_frame_for_main_thread_; | |
| 190 bool main_thread_needs_layer_textures_; | 224 bool main_thread_needs_layer_textures_; |
| 191 bool inside_begin_frame_; | 225 BeginFrameState begin_frame_state_; |
| 226 bool commit_tree_has_been_drawn_; | |
| 227 bool active_tree_has_been_drawn_; | |
| 228 bool active_tree_is_null_; | |
| 192 BeginFrameArgs last_begin_frame_args_; | 229 BeginFrameArgs last_begin_frame_args_; |
| 193 bool visible_; | 230 bool visible_; |
| 194 bool can_start_; | 231 bool can_start_; |
| 195 bool can_draw_; | 232 bool can_draw_; |
| 196 bool has_pending_tree_; | 233 bool has_pending_tree_; |
| 197 bool draw_if_possible_failed_; | 234 bool draw_if_possible_failed_; |
| 198 TextureState texture_state_; | 235 TextureState texture_state_; |
| 199 OutputSurfaceState output_surface_state_; | 236 OutputSurfaceState output_surface_state_; |
| 200 bool did_create_and_initialize_first_output_surface_; | 237 bool did_create_and_initialize_first_output_surface_; |
| 201 | 238 |
| 202 private: | 239 private: |
| 203 DISALLOW_COPY_AND_ASSIGN(SchedulerStateMachine); | 240 DISALLOW_COPY_AND_ASSIGN(SchedulerStateMachine); |
| 204 }; | 241 }; |
| 205 | 242 |
| 206 } // namespace cc | 243 } // namespace cc |
| 207 | 244 |
| 208 #endif // CC_SCHEDULER_SCHEDULER_STATE_MACHINE_H_ | 245 #endif // CC_SCHEDULER_SCHEDULER_STATE_MACHINE_H_ |
| OLD | NEW |