Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(32)

Side by Side Diff: cc/scheduler/scheduler_state_machine.h

Issue 16871016: cc: Use BeginFrameArgs (Closed) Base URL: http://git.chromium.org/chromium/src.git@bfargs2
Patch Set: Rebase; Avoid double activate; Fix OutputSurface init and page scroll delta; Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 enum OutputSurfaceState {
35 OUTPUT_SURFACE_ACTIVE,
36 OUTPUT_SURFACE_LOST,
37 OUTPUT_SURFACE_CREATING,
38 OUTPUT_SURFACE_WAITING_FOR_FIRST_COMMIT,
39 OUTPUT_SURFACE_WAITING_FOR_FIRST_ACTIVATION,
40 };
41
42 // Note: BeginFrameState will always cycle through all the states in order.
43 // Whether or not it actually waits or draws, it will at least try to wait in
44 // BEGIN_FRAME_STATE_DEADLINE_PENDING and try to draw in
45 // BEGIN_FRAME_STATE_INSIDE_DEADLINE
46 enum BeginFrameState {
47 BEGIN_FRAME_STATE_IDLE,
48 BEGIN_FRAME_STATE_INSIDE_BEGIN_FRAME,
49 BEGIN_FRAME_STATE_DEADLINE_PENDING,
50 BEGIN_FRAME_STATE_INSIDE_DEADLINE,
51 };
52
34 enum CommitState { 53 enum CommitState {
35 COMMIT_STATE_IDLE, 54 COMMIT_STATE_IDLE,
36 COMMIT_STATE_FRAME_IN_PROGRESS, 55 COMMIT_STATE_FRAME_IN_PROGRESS,
37 COMMIT_STATE_READY_TO_COMMIT, 56 COMMIT_STATE_READY_TO_COMMIT,
57 COMMIT_STATE_WAITING_FOR_ACTIVATION,
38 COMMIT_STATE_WAITING_FOR_FIRST_DRAW, 58 COMMIT_STATE_WAITING_FOR_FIRST_DRAW,
39 COMMIT_STATE_WAITING_FOR_FIRST_FORCED_DRAW,
40 }; 59 };
41 60
42 enum TextureState { 61 enum TextureState {
43 LAYER_TEXTURE_STATE_UNLOCKED, 62 LAYER_TEXTURE_STATE_UNLOCKED,
44 LAYER_TEXTURE_STATE_ACQUIRED_BY_MAIN_THREAD, 63 LAYER_TEXTURE_STATE_ACQUIRED_BY_MAIN_THREAD,
45 LAYER_TEXTURE_STATE_ACQUIRED_BY_IMPL_THREAD, 64 LAYER_TEXTURE_STATE_ACQUIRED_BY_IMPL_THREAD,
46 }; 65 };
47 66
48 enum OutputSurfaceState { 67 enum SynchronousReadbackState {
49 OUTPUT_SURFACE_ACTIVE, 68 READBACK_STATE_IDLE,
50 OUTPUT_SURFACE_LOST, 69 READBACK_STATE_FORCED_COMMIT_REQUESTED,
51 OUTPUT_SURFACE_CREATING, 70 READBACK_STATE_FORCED_COMMIT_PENDING,
71 READBACK_STATE_WAITING_FOR_ACTIVATION,
72 READBACK_STATE_WAITING_FOR_DRAW_AND_READBACK,
73 READBACK_STATE_REPLACEMENT_COMMIT_PENDING,
74 READBACK_STATE_REPLACEMENT_COMMIT_ACTIVATING,
75 };
76
77 enum ForcedRedrawOnTimeoutState {
78 FORCED_REDRAW_STATE_IDLE,
79 FORCED_REDRAW_STATE_WAITING_FOR_COMMIT,
80 FORCED_REDRAW_STATE_WAITING_FOR_ACTIVATION,
81 FORCED_REDRAW_STATE_WAITING_FOR_DRAW,
52 }; 82 };
53 83
54 bool CommitPending() const { 84 bool CommitPending() const {
55 return commit_state_ == COMMIT_STATE_FRAME_IN_PROGRESS || 85 return commit_state_ == COMMIT_STATE_FRAME_IN_PROGRESS;
56 commit_state_ == COMMIT_STATE_READY_TO_COMMIT;
57 } 86 }
58 87
59 bool RedrawPending() const { return needs_redraw_; } 88 bool RedrawPending() const { return needs_redraw_; }
60 89
61 enum Action { 90 enum Action {
62 ACTION_NONE, 91 ACTION_NONE,
63 ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD, 92 ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD,
64 ACTION_COMMIT, 93 ACTION_COMMIT,
65 ACTION_UPDATE_VISIBLE_TILES, 94 ACTION_UPDATE_VISIBLE_TILES,
66 ACTION_ACTIVATE_PENDING_TREE_IF_NEEDED, 95 ACTION_ACTIVATE_PENDING_TREE,
67 ACTION_DRAW_IF_POSSIBLE, 96 ACTION_DRAW_AND_SWAP_IF_POSSIBLE,
68 ACTION_DRAW_FORCED, 97 ACTION_DRAW_AND_SWAP_FORCED,
98 ACTION_DRAW_AND_SWAP_ABORT,
99 ACTION_DRAW_AND_READBACK,
69 ACTION_BEGIN_OUTPUT_SURFACE_CREATION, 100 ACTION_BEGIN_OUTPUT_SURFACE_CREATION,
70 ACTION_ACQUIRE_LAYER_TEXTURES_FOR_MAIN_THREAD, 101 ACTION_ACQUIRE_LAYER_TEXTURES_FOR_MAIN_THREAD,
71 }; 102 };
72 Action NextAction() const; 103 Action NextAction() const;
73 void UpdateState(Action action); 104 void UpdateState(Action action);
105 void AdvanceBeginFrameStateWhenNoActionsRemain();
74 106
75 // Indicates whether the main thread needs a begin frame callback in order to 107 // Indicates whether the main thread needs a begin frame callback in order to
76 // make progress. 108 // make progress.
109 bool BeginFrameNeededByImplThread() const;
77 bool BeginFrameNeededToDrawByImplThread() const; 110 bool BeginFrameNeededToDrawByImplThread() const;
78 bool ProactiveBeginFrameWantedByImplThread() const; 111 bool BeginFrameProactivelyNeededByImplThread() const;
79 112
80 // Indicates that the system has entered and left a BeginFrame callback. 113 // Indicates that the system has entered and left a BeginFrame callback.
81 // The scheduler will not draw more than once in a given BeginFrame 114 // The scheduler will not draw more than once in a given BeginFrame
82 // callback nor send more than one BeginFrame message. 115 // callback nor send more than one BeginFrame message.
83 void DidEnterBeginFrame(const BeginFrameArgs& args); 116 void OnBeginFrame(const BeginFrameArgs& args);
84 void DidLeaveBeginFrame(); 117 void OnBeginFrameDeadline();
85 bool inside_begin_frame() const { return inside_begin_frame_; } 118 bool ShouldTriggerBeginFrameDeadlineEarly() const;
119 bool InsideBeginFrame() const;
86 120
87 // Indicates whether the LayerTreeHostImpl is visible. 121 // Indicates whether the LayerTreeHostImpl is visible.
88 void SetVisible(bool visible); 122 void SetVisible(bool visible);
89 123
90 // Indicates that a redraw is required, either due to the impl tree changing 124 // Indicates that a redraw is required, either due to the impl tree changing
91 // or the screen being damaged and simply needing redisplay. 125 // or the screen being damaged and simply needing redisplay.
92 void SetNeedsRedraw(); 126 void SetNeedsRedraw();
93 127
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 128 // Indicates that a redraw is required because we are currently rendering
99 // with a low resolution or checkerboarded tile. 129 // with a low resolution or checkerboarded tile.
100 void DidSwapUseIncompleteTile(); 130 void DidSwapUseIncompleteTile();
101 131
102 // Indicates whether ACTION_DRAW_IF_POSSIBLE drew to the screen or not. 132 // Indicates whether ACTION_DRAW_AND_SWAP_IF_POSSIBLE drew to the screen.
103 void DidDrawIfPossibleCompleted(bool success); 133 void DidDrawIfPossibleCompleted(bool success);
104 134
105 // Indicates that a new commit flow needs to be performed, either to pull 135 // 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 136 // updates from the main thread to the impl, or to push deltas from the impl
107 // thread to main. 137 // thread to main.
108 void SetNeedsCommit(); 138 void SetNeedsCommit();
109 139
110 // As SetNeedsCommit(), but ensures the begin frame will be sent to the main 140 // 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 141 // 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 142 // the forced commit flow and then return to waiting for a non-forced
113 // begin frame to finish. 143 // begin frame to finish.
114 void SetNeedsForcedCommit(); 144 void SetNeedsForcedCommitForReadback();
115 145
116 // Call this only in response to receiving an 146 // Call this only in response to receiving an
117 // ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD from NextAction. 147 // ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD from NextAction.
118 // Indicates that all painting is complete. 148 // Indicates that all painting is complete.
119 void FinishCommit(); 149 void FinishCommit();
120 150
121 // Call this only in response to receiving an 151 // Call this only in response to receiving an
122 // ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD from NextAction if the client 152 // ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD from NextAction if the client
123 // rejects the begin frame message. If did_handle is false, then 153 // rejects the begin frame message. If did_handle is false, then
124 // another commit will be retried soon. 154 // another commit will be retried soon.
125 void BeginFrameAbortedByMainThread(bool did_handle); 155 void BeginFrameAbortedByMainThread(bool did_handle);
126 156
127 // Request exclusive access to the textures that back single buffered 157 // Request exclusive access to the textures that back single buffered
128 // layers on behalf of the main thread. Upon acquisition, 158 // layers on behalf of the main thread. Upon acquisition,
129 // ACTION_DRAW_IF_POSSIBLE will not draw until the main thread releases the 159 // ACTION_DRAW_AND_SWAP_IF_POSSIBLE will not draw until the main thread
130 // textures to the impl thread by committing the layers. 160 // releases the textures to the impl thread by committing the layers.
131 void SetMainThreadNeedsLayerTextures(); 161 void SetMainThreadNeedsLayerTextures();
132 162
133 // Set that we can create the first OutputSurface and start the scheduler. 163 // Set that we can create the first OutputSurface and start the scheduler.
134 void SetCanStart() { can_start_ = true; } 164 void SetCanStart() { can_start_ = true; }
135 165
136 // Indicates whether drawing would, at this time, make sense. 166 // Indicates whether drawing would, at this time, make sense.
137 // CanDraw can be used to supress flashes or checkerboarding 167 // CanDraw can be used to supress flashes or checkerboarding
138 // when such behavior would be undesirable. 168 // when such behavior would be undesirable.
139 void SetCanDraw(bool can); 169 void SetCanDraw(bool can_draw);
140 170
141 // Indicates whether or not there is a pending tree. This influences 171 // Indicates that the pending tree is ready for activation.
142 // whether or not we can succesfully commit at this time. If the 172 void NotifyReadyToActivate();
173
174 // Indicates whether or not there is a pending tree (which may be null)
175 // and whether the active tree is null or not. This
176 // influences whether or not we can succesfully commit at this time. If the
143 // last commit is still being processed (but not blocking), it may not 177 // last commit is still being processed (but not blocking), it may not
144 // be possible to take another commit yet. This overrides force commit, 178 // be possible to take another commit yet. This overrides force commit,
145 // as a commit is already still in flight. 179 // as a commit is already still in flight.
146 void SetHasPendingTree(bool has_pending_tree); 180 void SetHasTrees(bool has_pending_tree, bool active_tree_is_null);
147 bool has_pending_tree() const { return has_pending_tree_; } 181 bool has_pending_tree() const { return has_pending_tree_; }
148 182
149 void DidLoseOutputSurface(); 183 void DidLoseOutputSurface();
150 void DidCreateAndInitializeOutputSurface(); 184 void DidCreateAndInitializeOutputSurface();
151 bool HasInitializedOutputSurface() const; 185 bool HasInitializedOutputSurface() const;
152 186
153 // Exposed for testing purposes. 187 // Exposed for testing purposes.
154 void SetMaximumNumberOfFailedDrawsBeforeDrawIsForced(int num_draws); 188 void SetMaximumNumberOfFailedDrawsBeforeDrawIsForced(int num_draws);
155 189
156 // False if drawing is not being prevented, true if drawing won't happen 190 // False if drawing is not being prevented, true if drawing won't happen
157 // for some reason, such as not being visible. 191 // for some reason, such as not being visible.
158 bool DrawSuspendedUntilCommit() const; 192 bool DrawSuspendedUntilCommit() const;
159 193
160 std::string ToString(); 194 std::string ToString();
161 195
162 protected: 196 protected:
163 bool ShouldDrawForced() const; 197 bool ShouldDrawForced() const;
164 bool ScheduledToDraw() const; 198 bool ScheduledToDraw() const;
165 bool ShouldDraw() const; 199 bool ShouldDraw() const;
166 bool ShouldAttemptTreeActivation() const; 200 bool ShouldDrawInternal(BeginFrameState begin_frame_state) const;
201 bool ShouldActivatePendingTree() const;
167 bool ShouldAcquireLayerTexturesForMainThread() const; 202 bool ShouldAcquireLayerTexturesForMainThread() const;
168 bool ShouldUpdateVisibleTiles() const; 203 bool ShouldUpdateVisibleTiles() const;
204 bool ShouldSendBeginFrameToMainThread() const;
169 bool HasDrawnThisFrame() const; 205 bool HasDrawnThisFrame() const;
170 bool HasAttemptedTreeActivationThisFrame() const; 206 bool HasDrawnThisDrawAttempt() const;
171 bool HasUpdatedVisibleTilesThisFrame() const; 207 bool HasUpdatedVisibleTilesThisDrawAttempt() const;
172 void SetPostCommitFlags(); 208 bool HasSentBeginFrameToMainThreadThisFrame() const;
209 bool HasActivatedPendingTreeThisDrawAttempt() const;
210
211 void HandleCommitInternal(bool commit_was_aborted);
173 212
174 const SchedulerSettings settings_; 213 const SchedulerSettings settings_;
175 214
215 OutputSurfaceState output_surface_state_;
216 BeginFrameState begin_frame_state_;
176 CommitState commit_state_; 217 CommitState commit_state_;
218 TextureState texture_state_;
219 SynchronousReadbackState readback_state_;
220 ForcedRedrawOnTimeoutState forced_redraw_state_;
221
222 BeginFrameArgs last_begin_frame_args_;
223
177 int commit_count_; 224 int commit_count_;
225 int begin_frame_count_;
226 int draw_attempt_count_;
227 int last_begin_frame_count_draw_was_called_;
228 int last_draw_attempt_count_draw_was_called_;
229 int last_begin_frame_count_begin_frame_sent_to_main_thread_;
230 int last_draw_attempt_count_tree_activation_attempted_;
231 int last_draw_attempt_count_completed_tile_uploads_checked_;
232 int last_draw_attempt_count_update_visible_tiles_was_called_;
178 233
179 int current_frame_number_;
180 int last_frame_number_where_begin_frame_sent_to_main_thread_;
181 int last_frame_number_where_draw_was_called_;
182 int last_frame_number_where_tree_activation_attempted_;
183 int last_frame_number_where_update_visible_tiles_was_called_;
184 int consecutive_failed_draws_; 234 int consecutive_failed_draws_;
185 int maximum_number_of_failed_draws_before_draw_is_forced_; 235 int maximum_number_of_failed_draws_before_draw_is_forced_;
236
186 bool needs_redraw_; 237 bool needs_redraw_;
187 bool swap_used_incomplete_tile_; 238 bool swap_used_incomplete_tile_;
188 bool needs_forced_redraw_;
189 bool needs_forced_redraw_after_next_commit_;
190 bool needs_redraw_after_next_commit_;
191 bool needs_commit_; 239 bool needs_commit_;
192 bool needs_forced_commit_;
193 bool expect_immediate_begin_frame_for_main_thread_;
194 bool main_thread_needs_layer_textures_; 240 bool main_thread_needs_layer_textures_;
195 bool inside_begin_frame_; 241 bool active_tree_has_been_drawn_;
196 BeginFrameArgs last_begin_frame_args_; 242 bool active_tree_is_null_;
197 bool visible_; 243 bool visible_;
198 bool can_start_; 244 bool can_start_;
199 bool can_draw_; 245 bool can_draw_;
200 bool has_pending_tree_; 246 bool has_pending_tree_;
247 bool pending_tree_is_ready_for_activation_;
201 bool draw_if_possible_failed_; 248 bool draw_if_possible_failed_;
202 TextureState texture_state_;
203 OutputSurfaceState output_surface_state_;
204 bool did_create_and_initialize_first_output_surface_; 249 bool did_create_and_initialize_first_output_surface_;
205 250
206 private: 251 private:
207 DISALLOW_COPY_AND_ASSIGN(SchedulerStateMachine); 252 DISALLOW_COPY_AND_ASSIGN(SchedulerStateMachine);
208 }; 253 };
209 254
210 } // namespace cc 255 } // namespace cc
211 256
212 #endif // CC_SCHEDULER_SCHEDULER_STATE_MACHINE_H_ 257 #endif // CC_SCHEDULER_SCHEDULER_STATE_MACHINE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698