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

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

Issue 23503003: cc: Add readback and forced draw states to the Scheduler (Closed) Base URL: http://git.chromium.org/chromium/src.git@schedReorg3
Patch Set: Fix all the tests Created 7 years, 3 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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
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_FORCED_COMMIT_REQUESTED,
66 READBACK_STATE_FORCED_COMMIT_PENDING,
danakj 2013/08/30 15:56:41 This state enums are all different from each other
brianderson 2013/09/03 22:41:12 I like your names, it is clearer what each state i
67 READBACK_STATE_WAITING_FOR_ACTIVATION,
68 READBACK_STATE_WAITING_FOR_DRAW_AND_READBACK,
69 READBACK_STATE_REPLACEMENT_COMMIT_PENDING,
70 READBACK_STATE_REPLACEMENT_COMMIT_ACTIVATING,
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);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 bool HasSentBeginFrameToMainThreadThisFrame() const; 207 bool HasSentBeginFrameToMainThreadThisFrame() const;
188 208
189 void UpdateStateOnCommit(bool commit_was_aborted); 209 void UpdateStateOnCommit(bool commit_was_aborted);
190 void UpdateStateOnActivation(); 210 void UpdateStateOnActivation();
191 void UpdateStateOnDraw(bool did_swap); 211 void UpdateStateOnDraw(bool did_swap);
192 212
193 const SchedulerSettings settings_; 213 const SchedulerSettings settings_;
194 214
195 OutputSurfaceState output_surface_state_; 215 OutputSurfaceState output_surface_state_;
196 CommitState commit_state_; 216 CommitState commit_state_;
217 TextureState texture_state_;
218 ForcedRedrawOnTimeoutState forced_redraw_state_;
219 SynchronousReadbackState readback_state_;
197 220
198 int commit_count_; 221 int commit_count_;
199 int current_frame_number_; 222 int current_frame_number_;
200 int last_frame_number_where_begin_frame_sent_to_main_thread_; 223 int last_frame_number_where_begin_frame_sent_to_main_thread_;
201 int last_frame_number_where_draw_was_called_; 224 int last_frame_number_swap_performed_;
202 int last_frame_number_where_update_visible_tiles_was_called_; 225 int last_frame_number_where_update_visible_tiles_was_called_;
203 int consecutive_failed_draws_; 226 int consecutive_failed_draws_;
204 int maximum_number_of_failed_draws_before_draw_is_forced_; 227 int maximum_number_of_failed_draws_before_draw_is_forced_;
205 bool needs_redraw_; 228 bool needs_redraw_;
206 bool swap_used_incomplete_tile_; 229 bool swap_used_incomplete_tile_;
207 bool needs_forced_redraw_;
208 bool needs_forced_redraw_after_next_commit_;
209 bool needs_commit_; 230 bool needs_commit_;
210 bool needs_forced_commit_;
211 bool expect_immediate_begin_frame_for_main_thread_;
212 bool main_thread_needs_layer_textures_; 231 bool main_thread_needs_layer_textures_;
213 bool inside_begin_frame_; 232 bool inside_begin_frame_;
214 BeginFrameArgs last_begin_frame_args_; 233 BeginFrameArgs last_begin_frame_args_;
215 bool visible_; 234 bool visible_;
216 bool can_start_; 235 bool can_start_;
217 bool can_draw_; 236 bool can_draw_;
218 bool has_pending_tree_; 237 bool has_pending_tree_;
219 bool pending_tree_is_ready_for_activation_; 238 bool pending_tree_is_ready_for_activation_;
220 bool active_tree_has_been_drawn_; 239 bool active_tree_has_been_drawn_;
221 bool draw_if_possible_failed_; 240 bool draw_if_possible_failed_;
222 TextureState texture_state_;
223 bool did_create_and_initialize_first_output_surface_; 241 bool did_create_and_initialize_first_output_surface_;
224 242
225 private: 243 private:
226 DISALLOW_COPY_AND_ASSIGN(SchedulerStateMachine); 244 DISALLOW_COPY_AND_ASSIGN(SchedulerStateMachine);
227 }; 245 };
228 246
229 } // namespace cc 247 } // namespace cc
230 248
231 #endif // CC_SCHEDULER_SCHEDULER_STATE_MACHINE_H_ 249 #endif // CC_SCHEDULER_SCHEDULER_STATE_MACHINE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698