| 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 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 73 void UpdateState(Action action); | 85 void UpdateState(Action action); |
| 74 | 86 |
| 75 // Indicates whether the main thread needs a begin frame callback in order to | 87 // Indicates whether the main thread needs a begin frame callback in order to |
| 76 // make progress. | 88 // make progress. |
| 77 bool BeginFrameNeededToDrawByImplThread() const; | 89 bool BeginFrameNeededToDrawByImplThread() const; |
| 78 bool ProactiveBeginFrameWantedByImplThread() const; | 90 bool ProactiveBeginFrameWantedByImplThread() const; |
| 79 | 91 |
| 80 // Indicates that the system has entered and left a BeginFrame callback. | 92 // Indicates that the system has entered and left a BeginFrame callback. |
| 81 // The scheduler will not draw more than once in a given BeginFrame | 93 // The scheduler will not draw more than once in a given BeginFrame |
| 82 // callback. | 94 // callback. |
| 83 void DidEnterBeginFrame(const BeginFrameArgs& args); | 95 void OnBeginFrame(const BeginFrameArgs& args); |
| 84 void DidLeaveBeginFrame(); | 96 void OnBeginFrameDeadline(); |
| 85 bool inside_begin_frame() const { return inside_begin_frame_; } | 97 bool ShouldTriggerBeginFrameDeadlineEarly() const; |
| 98 bool InsideBeginFrame() const; |
| 86 | 99 |
| 87 // Indicates whether the LayerTreeHostImpl is visible. | 100 // Indicates whether the LayerTreeHostImpl is visible. |
| 88 void SetVisible(bool visible); | 101 void SetVisible(bool visible); |
| 89 | 102 |
| 90 // Indicates that a redraw is required, either due to the impl tree changing | 103 // Indicates that a redraw is required, either due to the impl tree changing |
| 91 // or the screen being damaged and simply needing redisplay. | 104 // or the screen being damaged and simply needing redisplay. |
| 92 void SetNeedsRedraw(); | 105 void SetNeedsRedraw(); |
| 93 | 106 |
| 94 // As SetNeedsRedraw(), but ensures the draw will definitely happen even if | 107 // As SetNeedsRedraw(), but ensures the draw will definitely happen even if |
| 95 // we are not visible. | 108 // we are not visible. |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 // ACTION_DRAW_IF_POSSIBLE will not draw until the main thread releases the | 141 // ACTION_DRAW_IF_POSSIBLE will not draw until the main thread releases the |
| 129 // textures to the impl thread by committing the layers. | 142 // textures to the impl thread by committing the layers. |
| 130 void SetMainThreadNeedsLayerTextures(); | 143 void SetMainThreadNeedsLayerTextures(); |
| 131 | 144 |
| 132 // Set that we can create the first OutputSurface and start the scheduler. | 145 // Set that we can create the first OutputSurface and start the scheduler. |
| 133 void SetCanStart() { can_start_ = true; } | 146 void SetCanStart() { can_start_ = true; } |
| 134 | 147 |
| 135 // Indicates whether drawing would, at this time, make sense. | 148 // Indicates whether drawing would, at this time, make sense. |
| 136 // CanDraw can be used to supress flashes or checkerboarding | 149 // CanDraw can be used to supress flashes or checkerboarding |
| 137 // when such behavior would be undesirable. | 150 // when such behavior would be undesirable. |
| 138 void SetCanDraw(bool can); | 151 void SetCanDraw(bool can_draw); |
| 139 | 152 |
| 140 // Indicates whether or not there is a pending tree. This influences | 153 // 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 | 154 // and whether the active tree is null or not. This |
| 155 // 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 | 156 // last commit is still being processed (but not blocking), it may not |
| 143 // be possible to take another commit yet. This overrides force commit, | 157 // be possible to take another commit yet. This overrides force commit, |
| 144 // as a commit is already still in flight. | 158 // as a commit is already still in flight. |
| 145 void SetHasPendingTree(bool has_pending_tree); | 159 void SetHasTrees(bool has_pending_tree, bool active_tree_is_null); |
| 146 bool has_pending_tree() const { return has_pending_tree_; } | 160 bool has_pending_tree() const { return has_pending_tree_; } |
| 147 | 161 |
| 148 void DidLoseOutputSurface(); | 162 void DidLoseOutputSurface(); |
| 149 void DidCreateAndInitializeOutputSurface(); | 163 void DidCreateAndInitializeOutputSurface(); |
| 150 bool HasInitializedOutputSurface() const; | 164 bool HasInitializedOutputSurface() const; |
| 151 | 165 |
| 152 // Exposed for testing purposes. | 166 // Exposed for testing purposes. |
| 153 void SetMaximumNumberOfFailedDrawsBeforeDrawIsForced(int num_draws); | 167 void SetMaximumNumberOfFailedDrawsBeforeDrawIsForced(int num_draws); |
| 154 | 168 |
| 155 // False if drawing is not being prevented, true if drawing won't happen | 169 // False if drawing is not being prevented, true if drawing won't happen |
| 156 // for some reason, such as not being visible. | 170 // for some reason, such as not being visible. |
| 157 bool DrawSuspendedUntilCommit() const; | 171 bool DrawSuspendedUntilCommit() const; |
| 158 | 172 |
| 159 std::string ToString(); | 173 std::string ToString(); |
| 160 | 174 |
| 161 protected: | 175 protected: |
| 162 bool ShouldDrawForced() const; | 176 bool ShouldDrawForced() const; |
| 163 bool ScheduledToDraw() const; | 177 bool ScheduledToDraw() const; |
| 178 bool WillDrawNewTree() const; |
| 164 bool ShouldDraw() const; | 179 bool ShouldDraw() const; |
| 180 bool ShouldDrawInternal(BeginFrameState begin_frame_state) const; |
| 165 bool ShouldAttemptTreeActivation() const; | 181 bool ShouldAttemptTreeActivation() const; |
| 166 bool ShouldAcquireLayerTexturesForMainThread() const; | 182 bool ShouldAcquireLayerTexturesForMainThread() const; |
| 167 bool ShouldCheckForCompletedTileUploads() const; | 183 bool ShouldCheckForCompletedTileUploads() const; |
| 184 bool ShouldSendBeginFrameToMainThread() const; |
| 168 bool HasDrawnThisFrame() const; | 185 bool HasDrawnThisFrame() const; |
| 169 bool HasAttemptedTreeActivationThisFrame() const; | 186 bool HasAttemptedTreeActivationThisDrawAttempt() const; |
| 170 bool HasCheckedForCompletedTileUploadsThisFrame() const; | 187 bool HasCheckedForCompletedTileUploadsThisDrawAttempt() const; |
| 188 bool HasSentBeginFrameToMainThreadThisFrame() const; |
| 171 | 189 |
| 172 const SchedulerSettings settings_; | 190 const SchedulerSettings settings_; |
| 173 | 191 |
| 174 CommitState commit_state_; | 192 CommitState commit_state_; |
| 175 int commit_count_; | 193 int commit_count_; |
| 176 | 194 |
| 177 int current_frame_number_; | 195 int begin_frame_count_; |
| 178 int last_frame_number_where_draw_was_called_; | 196 int begin_frame_deadline_count_; |
| 179 int last_frame_number_where_tree_activation_attempted_; | 197 int draw_attempt_count_; |
| 180 int last_frame_number_where_check_for_completed_tile_uploads_called_; | 198 int last_begin_frame_count_draw_was_called_; |
| 199 int last_begin_frame_count_begin_frame_sent_to_main_thread_; |
| 200 int last_draw_attempt_count_tree_activation_attempted_; |
| 201 int last_draw_attempt_count_completed_tile_uploads_checked_; |
| 181 int consecutive_failed_draws_; | 202 int consecutive_failed_draws_; |
| 182 int maximum_number_of_failed_draws_before_draw_is_forced_; | 203 int maximum_number_of_failed_draws_before_draw_is_forced_; |
| 183 bool needs_redraw_; | 204 bool needs_redraw_; |
| 184 bool swap_used_incomplete_tile_; | 205 bool swap_used_incomplete_tile_; |
| 185 bool needs_forced_redraw_; | 206 bool needs_forced_redraw_; |
| 186 bool needs_forced_redraw_after_next_commit_; | 207 bool needs_forced_redraw_after_next_commit_; |
| 187 bool needs_commit_; | 208 bool needs_commit_; |
| 188 bool needs_forced_commit_; | 209 bool needs_forced_commit_; |
| 189 bool expect_immediate_begin_frame_for_main_thread_; | 210 bool expect_immediate_begin_frame_for_main_thread_; |
| 190 bool main_thread_needs_layer_textures_; | 211 bool main_thread_needs_layer_textures_; |
| 191 bool inside_begin_frame_; | 212 BeginFrameState begin_frame_state_; |
| 213 bool commit_tree_has_been_drawn_; |
| 214 bool active_tree_has_been_drawn_; |
| 192 BeginFrameArgs last_begin_frame_args_; | 215 BeginFrameArgs last_begin_frame_args_; |
| 193 bool visible_; | 216 bool visible_; |
| 194 bool can_start_; | 217 bool can_start_; |
| 195 bool can_draw_; | 218 bool can_draw_; |
| 196 bool has_pending_tree_; | 219 bool has_pending_tree_; |
| 197 bool draw_if_possible_failed_; | 220 bool draw_if_possible_failed_; |
| 198 TextureState texture_state_; | 221 TextureState texture_state_; |
| 199 OutputSurfaceState output_surface_state_; | 222 OutputSurfaceState output_surface_state_; |
| 200 bool did_create_and_initialize_first_output_surface_; | 223 bool did_create_and_initialize_first_output_surface_; |
| 201 | 224 |
| 202 private: | 225 private: |
| 203 DISALLOW_COPY_AND_ASSIGN(SchedulerStateMachine); | 226 DISALLOW_COPY_AND_ASSIGN(SchedulerStateMachine); |
| 204 }; | 227 }; |
| 205 | 228 |
| 206 } // namespace cc | 229 } // namespace cc |
| 207 | 230 |
| 208 #endif // CC_SCHEDULER_SCHEDULER_STATE_MACHINE_H_ | 231 #endif // CC_SCHEDULER_SCHEDULER_STATE_MACHINE_H_ |
| OLD | NEW |