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 | |
110 void CheckInvariants(); | 122 void CheckInvariants(); |
111 | 123 |
112 // Indicates whether the main thread needs a begin frame callback in order to | 124 // Indicates whether the main thread needs a begin frame callback in order to |
113 // make progress. | 125 // make progress. |
126 bool BeginFrameNeededByImplThread() const; | |
114 bool BeginFrameNeededToDrawByImplThread() const; | 127 bool BeginFrameNeededToDrawByImplThread() const; |
115 bool ProactiveBeginFrameWantedByImplThread() const; | 128 bool ProactiveBeginFrameWantedByImplThread() const; |
116 | 129 |
117 // Indicates that the system has entered and left a BeginFrame callback. | 130 // Indicates that the system has entered and left a BeginFrame callback. |
118 // The scheduler will not draw more than once in a given BeginFrame | 131 // The scheduler will not draw more than once in a given BeginFrame |
119 // callback nor send more than one BeginFrame message. | 132 // callback nor send more than one BeginFrame message. |
120 void DidEnterBeginFrame(const BeginFrameArgs& args); | 133 void OnBeginFrame(const BeginFrameArgs& args); |
121 void DidLeaveBeginFrame(); | 134 void OnBeginFrameDeadlinePending(); |
122 bool inside_begin_frame() const { return inside_begin_frame_; } | 135 void OnBeginFrameDeadline(); |
136 void OnBeginFrameIdle(); | |
137 bool ShouldTriggerBeginFrameDeadlineEarly() const; | |
138 bool InsideBeginFrame() const; | |
123 | 139 |
124 // Indicates whether the LayerTreeHostImpl is visible. | 140 // Indicates whether the LayerTreeHostImpl is visible. |
125 void SetVisible(bool visible); | 141 void SetVisible(bool visible); |
126 | 142 |
127 // Indicates that a redraw is required, either due to the impl tree changing | 143 // Indicates that a redraw is required, either due to the impl tree changing |
128 // or the screen being damaged and simply needing redisplay. | 144 // or the screen being damaged and simply needing redisplay. |
129 void SetNeedsRedraw(); | 145 void SetNeedsRedraw(); |
146 bool needs_redraw() const { return needs_redraw_; } | |
130 | 147 |
131 // Indicates whether a redraw is required because we are currently rendering | 148 // Indicates whether a redraw is required because we are currently rendering |
132 // with a low resolution or checkerboarded tile. | 149 // with a low resolution or checkerboarded tile. |
133 void SetSwapUsedIncompleteTile(bool used_incomplete_tile); | 150 void SetSwapUsedIncompleteTile(bool used_incomplete_tile); |
134 | 151 |
135 // Indicates whether ACTION_DRAW_AND_SWAP_IF_POSSIBLE drew to the screen or | 152 // Indicates whether ACTION_DRAW_AND_SWAP_IF_POSSIBLE drew to the screen. |
136 // not. | |
137 void DidDrawIfPossibleCompleted(bool success); | 153 void DidDrawIfPossibleCompleted(bool success); |
138 | 154 |
139 // Indicates that a new commit flow needs to be performed, either to pull | 155 // 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 | 156 // updates from the main thread to the impl, or to push deltas from the impl |
141 // thread to main. | 157 // thread to main. |
142 void SetNeedsCommit(); | 158 void SetNeedsCommit(); |
143 | 159 |
144 // As SetNeedsCommit(), but ensures the begin frame will be sent to the main | 160 // 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 | 161 // 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 | 162 // the forced commit flow and then return to waiting for a non-forced |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
191 | 207 |
192 bool ShouldBeginOutputSurfaceCreation() const; | 208 bool ShouldBeginOutputSurfaceCreation() const; |
193 bool ShouldDrawForced() const; | 209 bool ShouldDrawForced() const; |
194 bool ShouldDraw() const; | 210 bool ShouldDraw() const; |
195 bool ShouldActivatePendingTree() const; | 211 bool ShouldActivatePendingTree() const; |
196 bool ShouldAcquireLayerTexturesForMainThread() const; | 212 bool ShouldAcquireLayerTexturesForMainThread() const; |
197 bool ShouldUpdateVisibleTiles() const; | 213 bool ShouldUpdateVisibleTiles() const; |
198 bool ShouldSendBeginFrameToMainThread() const; | 214 bool ShouldSendBeginFrameToMainThread() const; |
199 bool ShouldCommit() const; | 215 bool ShouldCommit() const; |
200 | 216 |
201 bool HasDrawnAndSwappedThisFrame() const; | 217 bool HasSentBeginFrameToMainThreadThisFrame() const; |
202 bool HasActivatedPendingTreeThisFrame() const; | |
203 bool HasUpdatedVisibleTilesThisFrame() const; | 218 bool HasUpdatedVisibleTilesThisFrame() const; |
204 bool HasSentBeginFrameToMainThreadThisFrame() const; | 219 bool HasSwappedThisFrame() const; |
205 | 220 |
206 void UpdateStateOnCommit(bool commit_was_aborted); | 221 void UpdateStateOnCommit(bool commit_was_aborted); |
207 void UpdateStateOnActivation(); | 222 void UpdateStateOnActivation(); |
208 void UpdateStateOnDraw(bool did_swap); | 223 void UpdateStateOnDraw(bool did_swap); |
209 | 224 |
210 const SchedulerSettings settings_; | 225 const SchedulerSettings settings_; |
211 | 226 |
212 OutputSurfaceState output_surface_state_; | 227 OutputSurfaceState output_surface_state_; |
228 BeginFrameState begin_frame_state_; | |
213 CommitState commit_state_; | 229 CommitState commit_state_; |
214 TextureState texture_state_; | 230 TextureState texture_state_; |
215 ForcedRedrawOnTimeoutState forced_redraw_state_; | 231 ForcedRedrawOnTimeoutState forced_redraw_state_; |
216 SynchronousReadbackState readback_state_; | 232 SynchronousReadbackState readback_state_; |
217 | 233 |
234 BeginFrameArgs last_begin_frame_args_; | |
235 | |
218 int commit_count_; | 236 int commit_count_; |
219 int current_frame_number_; | 237 int begin_frame_count_; |
220 int last_frame_number_where_begin_frame_sent_to_main_thread_; | 238 int last_begin_frame_count_swap_performed_; |
221 int last_frame_number_swap_performed_; | 239 int last_begin_frame_count_begin_frame_sent_to_main_thread_; |
enne (OOO)
2013/09/11 22:30:47
I like this a million times better than draw attem
brianderson
2013/09/12 00:12:34
I'll change it back to current_frame_number now th
| |
222 int last_frame_number_where_update_visible_tiles_was_called_; | 240 int last_begin_frame_count_update_visible_tiles_was_called_; |
241 | |
223 int consecutive_failed_draws_; | 242 int consecutive_failed_draws_; |
224 bool needs_redraw_; | 243 bool needs_redraw_; |
225 bool swap_used_incomplete_tile_; | 244 bool swap_used_incomplete_tile_; |
226 bool needs_commit_; | 245 bool needs_commit_; |
227 bool main_thread_needs_layer_textures_; | 246 bool main_thread_needs_layer_textures_; |
228 bool inside_begin_frame_; | |
229 BeginFrameArgs last_begin_frame_args_; | |
230 bool visible_; | 247 bool visible_; |
231 bool can_start_; | 248 bool can_start_; |
232 bool can_draw_; | 249 bool can_draw_; |
233 bool has_pending_tree_; | 250 bool has_pending_tree_; |
234 bool pending_tree_is_ready_for_activation_; | 251 bool pending_tree_is_ready_for_activation_; |
235 bool active_tree_needs_first_draw_; | 252 bool active_tree_needs_first_draw_; |
236 bool draw_if_possible_failed_; | 253 bool draw_if_possible_failed_; |
237 bool did_create_and_initialize_first_output_surface_; | 254 bool did_create_and_initialize_first_output_surface_; |
238 | 255 |
239 private: | 256 private: |
240 DISALLOW_COPY_AND_ASSIGN(SchedulerStateMachine); | 257 DISALLOW_COPY_AND_ASSIGN(SchedulerStateMachine); |
241 }; | 258 }; |
242 | 259 |
243 } // namespace cc | 260 } // namespace cc |
244 | 261 |
245 #endif // CC_SCHEDULER_SCHEDULER_STATE_MACHINE_H_ | 262 #endif // CC_SCHEDULER_SCHEDULER_STATE_MACHINE_H_ |
OLD | NEW |