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 #include "cc/scheduler/scheduler_state_machine.h" | 5 #include "cc/scheduler/scheduler_state_machine.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/stringprintf.h" | 8 #include "base/stringprintf.h" |
9 | 9 |
10 namespace cc { | 10 namespace cc { |
11 | 11 |
12 SchedulerStateMachine::SchedulerStateMachine(const SchedulerSettings& settings) | 12 SchedulerStateMachine::SchedulerStateMachine(const SchedulerSettings& settings) |
13 : settings_(settings), | 13 : settings_(settings), |
14 commit_state_(COMMIT_STATE_IDLE), | 14 commit_state_(COMMIT_STATE_IDLE), |
15 current_frame_number_(0), | 15 current_frame_number_(0), |
16 last_frame_number_where_draw_was_called_(-1), | 16 last_frame_number_where_draw_was_called_(-1), |
17 last_frame_number_where_tree_activation_attempted_(-1), | 17 last_frame_number_where_tree_activation_attempted_(-1), |
18 last_frame_number_where_check_for_completed_tile_uploads_called_(-1), | 18 last_frame_number_where_check_for_completed_tile_uploads_called_(-1), |
19 consecutive_failed_draws_(0), | 19 consecutive_failed_draws_(0), |
20 maximum_number_of_failed_draws_before_draw_is_forced_(3), | 20 maximum_number_of_failed_draws_before_draw_is_forced_(3), |
21 needs_redraw_(false), | 21 needs_redraw_(false), |
22 swap_used_incomplete_tile_(false), | 22 swap_used_incomplete_tile_(false), |
23 needs_forced_redraw_(false), | 23 needs_forced_redraw_(false), |
24 needs_forced_redraw_after_next_commit_(false), | 24 needs_forced_redraw_after_next_commit_(false), |
25 needs_commit_(false), | 25 needs_commit_(false), |
26 needs_forced_commit_(false), | 26 needs_forced_commit_(false), |
27 expect_immediate_begin_frame_(false), | 27 expect_immediate_begin_frame_for_main_thread_(false), |
28 main_thread_needs_layer_textures_(false), | 28 main_thread_needs_layer_textures_(false), |
29 inside_vsync_(false), | 29 inside_begin_frame_(false), |
30 visible_(false), | 30 visible_(false), |
31 can_start_(false), | 31 can_start_(false), |
32 can_draw_(false), | 32 can_draw_(false), |
33 has_pending_tree_(false), | 33 has_pending_tree_(false), |
34 draw_if_possible_failed_(false), | 34 draw_if_possible_failed_(false), |
35 texture_state_(LAYER_TEXTURE_STATE_UNLOCKED), | 35 texture_state_(LAYER_TEXTURE_STATE_UNLOCKED), |
36 output_surface_state_(OUTPUT_SURFACE_LOST), | 36 output_surface_state_(OUTPUT_SURFACE_LOST), |
37 did_create_and_initialize_first_output_surface_(false) {} | 37 did_create_and_initialize_first_output_surface_(false) {} |
38 | 38 |
39 std::string SchedulerStateMachine::ToString() { | 39 std::string SchedulerStateMachine::ToString() { |
(...skipping 26 matching lines...) Expand all Loading... |
66 &str, "swap_used_incomplete_tile_ = %d; ", swap_used_incomplete_tile_); | 66 &str, "swap_used_incomplete_tile_ = %d; ", swap_used_incomplete_tile_); |
67 base::StringAppendF( | 67 base::StringAppendF( |
68 &str, "needs_forced_redraw_ = %d; ", needs_forced_redraw_); | 68 &str, "needs_forced_redraw_ = %d; ", needs_forced_redraw_); |
69 base::StringAppendF(&str, | 69 base::StringAppendF(&str, |
70 "needs_forced_redraw_after_next_commit_ = %d; ", | 70 "needs_forced_redraw_after_next_commit_ = %d; ", |
71 needs_forced_redraw_after_next_commit_); | 71 needs_forced_redraw_after_next_commit_); |
72 base::StringAppendF(&str, "needs_commit_ = %d; ", needs_commit_); | 72 base::StringAppendF(&str, "needs_commit_ = %d; ", needs_commit_); |
73 base::StringAppendF( | 73 base::StringAppendF( |
74 &str, "needs_forced_commit_ = %d; ", needs_forced_commit_); | 74 &str, "needs_forced_commit_ = %d; ", needs_forced_commit_); |
75 base::StringAppendF(&str, | 75 base::StringAppendF(&str, |
76 "expect_immediate_begin_frame_ = %d; ", | 76 "expect_immediate_begin_frame_for_main_thread_ = %d; ", |
77 expect_immediate_begin_frame_); | 77 expect_immediate_begin_frame_for_main_thread_); |
78 base::StringAppendF(&str, | 78 base::StringAppendF(&str, |
79 "main_thread_needs_layer_textures_ = %d; ", | 79 "main_thread_needs_layer_textures_ = %d; ", |
80 main_thread_needs_layer_textures_); | 80 main_thread_needs_layer_textures_); |
81 base::StringAppendF(&str, "inside_vsync_ = %d; ", inside_vsync_); | 81 base::StringAppendF(&str, "inside_begin_frame_ = %d; ", |
| 82 inside_begin_frame_); |
82 base::StringAppendF(&str, "visible_ = %d; ", visible_); | 83 base::StringAppendF(&str, "visible_ = %d; ", visible_); |
83 base::StringAppendF(&str, "can_start_ = %d; ", can_start_); | 84 base::StringAppendF(&str, "can_start_ = %d; ", can_start_); |
84 base::StringAppendF(&str, "can_draw_ = %d; ", can_draw_); | 85 base::StringAppendF(&str, "can_draw_ = %d; ", can_draw_); |
85 base::StringAppendF( | 86 base::StringAppendF( |
86 &str, "draw_if_possible_failed_ = %d; ", draw_if_possible_failed_); | 87 &str, "draw_if_possible_failed_ = %d; ", draw_if_possible_failed_); |
87 base::StringAppendF(&str, "has_pending_tree_ = %d; ", has_pending_tree_); | 88 base::StringAppendF(&str, "has_pending_tree_ = %d; ", has_pending_tree_); |
88 base::StringAppendF(&str, "texture_state_ = %d; ", texture_state_); | 89 base::StringAppendF(&str, "texture_state_ = %d; ", texture_state_); |
89 base::StringAppendF( | 90 base::StringAppendF( |
90 &str, "output_surface_state_ = %d; ", output_surface_state_); | 91 &str, "output_surface_state_ = %d; ", output_surface_state_); |
91 return str; | 92 return str; |
(...skipping 30 matching lines...) Expand all Loading... |
122 return false; | 123 return false; |
123 return true; | 124 return true; |
124 } | 125 } |
125 | 126 |
126 bool SchedulerStateMachine::ShouldDraw() const { | 127 bool SchedulerStateMachine::ShouldDraw() const { |
127 if (needs_forced_redraw_) | 128 if (needs_forced_redraw_) |
128 return true; | 129 return true; |
129 | 130 |
130 if (!ScheduledToDraw()) | 131 if (!ScheduledToDraw()) |
131 return false; | 132 return false; |
132 if (!inside_vsync_) | 133 if (!inside_begin_frame_) |
133 return false; | 134 return false; |
134 if (HasDrawnThisFrame()) | 135 if (HasDrawnThisFrame()) |
135 return false; | 136 return false; |
136 if (output_surface_state_ != OUTPUT_SURFACE_ACTIVE) | 137 if (output_surface_state_ != OUTPUT_SURFACE_ACTIVE) |
137 return false; | 138 return false; |
138 return true; | 139 return true; |
139 } | 140 } |
140 | 141 |
141 bool SchedulerStateMachine::ShouldAttemptTreeActivation() const { | 142 bool SchedulerStateMachine::ShouldAttemptTreeActivation() const { |
142 return has_pending_tree_ && inside_vsync_ && | 143 return has_pending_tree_ && inside_begin_frame_ && |
143 !HasAttemptedTreeActivationThisFrame(); | 144 !HasAttemptedTreeActivationThisFrame(); |
144 } | 145 } |
145 | 146 |
146 bool SchedulerStateMachine::ShouldCheckForCompletedTileUploads() const { | 147 bool SchedulerStateMachine::ShouldCheckForCompletedTileUploads() const { |
147 if (!settings_.impl_side_painting) | 148 if (!settings_.impl_side_painting) |
148 return false; | 149 return false; |
149 if (HasCheckedForCompletedTileUploadsThisFrame()) | 150 if (HasCheckedForCompletedTileUploadsThisFrame()) |
150 return false; | 151 return false; |
151 | 152 |
152 return ShouldAttemptTreeActivation() || ShouldDraw() || | 153 return ShouldAttemptTreeActivation() || ShouldDraw() || |
153 swap_used_incomplete_tile_; | 154 swap_used_incomplete_tile_; |
154 } | 155 } |
155 | 156 |
156 bool SchedulerStateMachine::ShouldAcquireLayerTexturesForMainThread() const { | 157 bool SchedulerStateMachine::ShouldAcquireLayerTexturesForMainThread() const { |
157 if (!main_thread_needs_layer_textures_) | 158 if (!main_thread_needs_layer_textures_) |
158 return false; | 159 return false; |
159 if (texture_state_ == LAYER_TEXTURE_STATE_UNLOCKED) | 160 if (texture_state_ == LAYER_TEXTURE_STATE_UNLOCKED) |
160 return true; | 161 return true; |
161 DCHECK_EQ(texture_state_, LAYER_TEXTURE_STATE_ACQUIRED_BY_IMPL_THREAD); | 162 DCHECK_EQ(texture_state_, LAYER_TEXTURE_STATE_ACQUIRED_BY_IMPL_THREAD); |
162 // Transfer the lock from impl thread to main thread immediately if the | 163 // Transfer the lock from impl thread to main thread immediately if the |
163 // impl thread is not even scheduled to draw. Guards against deadlocking. | 164 // impl thread is not even scheduled to draw. Guards against deadlocking. |
164 if (!ScheduledToDraw()) | 165 if (!ScheduledToDraw()) |
165 return true; | 166 return true; |
166 if (!VSyncCallbackNeeded()) | 167 if (!BeginFrameNeededByImplThread()) |
167 return true; | 168 return true; |
168 return false; | 169 return false; |
169 } | 170 } |
170 | 171 |
171 SchedulerStateMachine::Action SchedulerStateMachine::NextAction() const { | 172 SchedulerStateMachine::Action SchedulerStateMachine::NextAction() const { |
172 if (ShouldAcquireLayerTexturesForMainThread()) | 173 if (ShouldAcquireLayerTexturesForMainThread()) |
173 return ACTION_ACQUIRE_LAYER_TEXTURES_FOR_MAIN_THREAD; | 174 return ACTION_ACQUIRE_LAYER_TEXTURES_FOR_MAIN_THREAD; |
174 | 175 |
175 switch (commit_state_) { | 176 switch (commit_state_) { |
176 case COMMIT_STATE_IDLE: | 177 case COMMIT_STATE_IDLE: |
177 if (output_surface_state_ != OUTPUT_SURFACE_ACTIVE && | 178 if (output_surface_state_ != OUTPUT_SURFACE_ACTIVE && |
178 needs_forced_redraw_) | 179 needs_forced_redraw_) |
179 return ACTION_DRAW_FORCED; | 180 return ACTION_DRAW_FORCED; |
180 if (output_surface_state_ != OUTPUT_SURFACE_ACTIVE && | 181 if (output_surface_state_ != OUTPUT_SURFACE_ACTIVE && |
181 needs_forced_commit_) | 182 needs_forced_commit_) |
182 // TODO(enne): Should probably drop the active tree on force commit. | 183 // TODO(enne): Should probably drop the active tree on force commit. |
183 return has_pending_tree_ ? ACTION_NONE : ACTION_BEGIN_FRAME; | 184 return has_pending_tree_ ? ACTION_NONE |
| 185 : ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD; |
184 if (output_surface_state_ == OUTPUT_SURFACE_LOST && can_start_) | 186 if (output_surface_state_ == OUTPUT_SURFACE_LOST && can_start_) |
185 return ACTION_BEGIN_OUTPUT_SURFACE_CREATION; | 187 return ACTION_BEGIN_OUTPUT_SURFACE_CREATION; |
186 if (output_surface_state_ == OUTPUT_SURFACE_CREATING) | 188 if (output_surface_state_ == OUTPUT_SURFACE_CREATING) |
187 return ACTION_NONE; | 189 return ACTION_NONE; |
188 if (ShouldCheckForCompletedTileUploads()) | 190 if (ShouldCheckForCompletedTileUploads()) |
189 return ACTION_CHECK_FOR_COMPLETED_TILE_UPLOADS; | 191 return ACTION_CHECK_FOR_COMPLETED_TILE_UPLOADS; |
190 if (ShouldAttemptTreeActivation()) | 192 if (ShouldAttemptTreeActivation()) |
191 return ACTION_ACTIVATE_PENDING_TREE_IF_NEEDED; | 193 return ACTION_ACTIVATE_PENDING_TREE_IF_NEEDED; |
192 if (ShouldDraw()) { | 194 if (ShouldDraw()) { |
193 return needs_forced_redraw_ ? ACTION_DRAW_FORCED | 195 return needs_forced_redraw_ ? ACTION_DRAW_FORCED |
194 : ACTION_DRAW_IF_POSSIBLE; | 196 : ACTION_DRAW_IF_POSSIBLE; |
195 } | 197 } |
196 if (needs_commit_ && | 198 if (needs_commit_ && |
197 ((visible_ && output_surface_state_ == OUTPUT_SURFACE_ACTIVE) | 199 ((visible_ && output_surface_state_ == OUTPUT_SURFACE_ACTIVE) |
198 || needs_forced_commit_)) | 200 || needs_forced_commit_)) |
199 // TODO(enne): Should probably drop the active tree on force commit. | 201 // TODO(enne): Should probably drop the active tree on force commit. |
200 return has_pending_tree_ ? ACTION_NONE : ACTION_BEGIN_FRAME; | 202 return has_pending_tree_ ? ACTION_NONE |
| 203 : ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD; |
201 return ACTION_NONE; | 204 return ACTION_NONE; |
202 | 205 |
203 case COMMIT_STATE_FRAME_IN_PROGRESS: | 206 case COMMIT_STATE_FRAME_IN_PROGRESS: |
204 if (ShouldCheckForCompletedTileUploads()) | 207 if (ShouldCheckForCompletedTileUploads()) |
205 return ACTION_CHECK_FOR_COMPLETED_TILE_UPLOADS; | 208 return ACTION_CHECK_FOR_COMPLETED_TILE_UPLOADS; |
206 if (ShouldAttemptTreeActivation()) | 209 if (ShouldAttemptTreeActivation()) |
207 return ACTION_ACTIVATE_PENDING_TREE_IF_NEEDED; | 210 return ACTION_ACTIVATE_PENDING_TREE_IF_NEEDED; |
208 if (ShouldDraw()) { | 211 if (ShouldDraw()) { |
209 return needs_forced_redraw_ ? ACTION_DRAW_FORCED | 212 return needs_forced_redraw_ ? ACTION_DRAW_FORCED |
210 : ACTION_DRAW_IF_POSSIBLE; | 213 : ACTION_DRAW_IF_POSSIBLE; |
(...skipping 10 matching lines...) Expand all Loading... |
221 return ACTION_ACTIVATE_PENDING_TREE_IF_NEEDED; | 224 return ACTION_ACTIVATE_PENDING_TREE_IF_NEEDED; |
222 if (ShouldDraw() || output_surface_state_ == OUTPUT_SURFACE_LOST) { | 225 if (ShouldDraw() || output_surface_state_ == OUTPUT_SURFACE_LOST) { |
223 return needs_forced_redraw_ ? ACTION_DRAW_FORCED | 226 return needs_forced_redraw_ ? ACTION_DRAW_FORCED |
224 : ACTION_DRAW_IF_POSSIBLE; | 227 : ACTION_DRAW_IF_POSSIBLE; |
225 } | 228 } |
226 // COMMIT_STATE_WAITING_FOR_FIRST_DRAW wants to enforce a draw. If | 229 // COMMIT_STATE_WAITING_FOR_FIRST_DRAW wants to enforce a draw. If |
227 // can_draw_ is false or textures are not available, proceed to the next | 230 // can_draw_ is false or textures are not available, proceed to the next |
228 // step (similar as in COMMIT_STATE_IDLE). | 231 // step (similar as in COMMIT_STATE_IDLE). |
229 bool can_commit = visible_ || needs_forced_commit_; | 232 bool can_commit = visible_ || needs_forced_commit_; |
230 if (needs_commit_ && can_commit && DrawSuspendedUntilCommit()) | 233 if (needs_commit_ && can_commit && DrawSuspendedUntilCommit()) |
231 return has_pending_tree_ ? ACTION_NONE : ACTION_BEGIN_FRAME; | 234 return has_pending_tree_ ? ACTION_NONE |
| 235 : ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD; |
232 return ACTION_NONE; | 236 return ACTION_NONE; |
233 } | 237 } |
234 | 238 |
235 case COMMIT_STATE_WAITING_FOR_FIRST_FORCED_DRAW: | 239 case COMMIT_STATE_WAITING_FOR_FIRST_FORCED_DRAW: |
236 if (ShouldCheckForCompletedTileUploads()) | 240 if (ShouldCheckForCompletedTileUploads()) |
237 return ACTION_CHECK_FOR_COMPLETED_TILE_UPLOADS; | 241 return ACTION_CHECK_FOR_COMPLETED_TILE_UPLOADS; |
238 if (ShouldAttemptTreeActivation()) | 242 if (ShouldAttemptTreeActivation()) |
239 return ACTION_ACTIVATE_PENDING_TREE_IF_NEEDED; | 243 return ACTION_ACTIVATE_PENDING_TREE_IF_NEEDED; |
240 if (needs_forced_redraw_) | 244 if (needs_forced_redraw_) |
241 return ACTION_DRAW_FORCED; | 245 return ACTION_DRAW_FORCED; |
(...skipping 11 matching lines...) Expand all Loading... |
253 case ACTION_CHECK_FOR_COMPLETED_TILE_UPLOADS: | 257 case ACTION_CHECK_FOR_COMPLETED_TILE_UPLOADS: |
254 last_frame_number_where_check_for_completed_tile_uploads_called_ = | 258 last_frame_number_where_check_for_completed_tile_uploads_called_ = |
255 current_frame_number_; | 259 current_frame_number_; |
256 return; | 260 return; |
257 | 261 |
258 case ACTION_ACTIVATE_PENDING_TREE_IF_NEEDED: | 262 case ACTION_ACTIVATE_PENDING_TREE_IF_NEEDED: |
259 last_frame_number_where_tree_activation_attempted_ = | 263 last_frame_number_where_tree_activation_attempted_ = |
260 current_frame_number_; | 264 current_frame_number_; |
261 return; | 265 return; |
262 | 266 |
263 case ACTION_BEGIN_FRAME: | 267 case ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD: |
264 DCHECK(!has_pending_tree_); | 268 DCHECK(!has_pending_tree_); |
265 DCHECK(visible_ || needs_forced_commit_); | 269 DCHECK(visible_ || needs_forced_commit_); |
266 commit_state_ = COMMIT_STATE_FRAME_IN_PROGRESS; | 270 commit_state_ = COMMIT_STATE_FRAME_IN_PROGRESS; |
267 needs_commit_ = false; | 271 needs_commit_ = false; |
268 needs_forced_commit_ = false; | 272 needs_forced_commit_ = false; |
269 return; | 273 return; |
270 | 274 |
271 case ACTION_COMMIT: | 275 case ACTION_COMMIT: |
272 if (expect_immediate_begin_frame_) | 276 if (expect_immediate_begin_frame_for_main_thread_) |
273 commit_state_ = COMMIT_STATE_WAITING_FOR_FIRST_FORCED_DRAW; | 277 commit_state_ = COMMIT_STATE_WAITING_FOR_FIRST_FORCED_DRAW; |
274 else | 278 else |
275 commit_state_ = COMMIT_STATE_WAITING_FOR_FIRST_DRAW; | 279 commit_state_ = COMMIT_STATE_WAITING_FOR_FIRST_DRAW; |
276 // When impl-side painting, we draw on activation instead of on commit. | 280 // When impl-side painting, we draw on activation instead of on commit. |
277 if (!settings_.impl_side_painting) | 281 if (!settings_.impl_side_painting) |
278 needs_redraw_ = true; | 282 needs_redraw_ = true; |
279 if (draw_if_possible_failed_) | 283 if (draw_if_possible_failed_) |
280 last_frame_number_where_draw_was_called_ = -1; | 284 last_frame_number_where_draw_was_called_ = -1; |
281 | 285 |
282 if (needs_forced_redraw_after_next_commit_) { | 286 if (needs_forced_redraw_after_next_commit_) { |
283 needs_forced_redraw_after_next_commit_ = false; | 287 needs_forced_redraw_after_next_commit_ = false; |
284 needs_forced_redraw_ = true; | 288 needs_forced_redraw_ = true; |
285 } | 289 } |
286 | 290 |
287 texture_state_ = LAYER_TEXTURE_STATE_ACQUIRED_BY_IMPL_THREAD; | 291 texture_state_ = LAYER_TEXTURE_STATE_ACQUIRED_BY_IMPL_THREAD; |
288 return; | 292 return; |
289 | 293 |
290 case ACTION_DRAW_FORCED: | 294 case ACTION_DRAW_FORCED: |
291 case ACTION_DRAW_IF_POSSIBLE: | 295 case ACTION_DRAW_IF_POSSIBLE: |
292 needs_redraw_ = false; | 296 needs_redraw_ = false; |
293 needs_forced_redraw_ = false; | 297 needs_forced_redraw_ = false; |
294 draw_if_possible_failed_ = false; | 298 draw_if_possible_failed_ = false; |
295 swap_used_incomplete_tile_ = false; | 299 swap_used_incomplete_tile_ = false; |
296 if (inside_vsync_) | 300 if (inside_begin_frame_) |
297 last_frame_number_where_draw_was_called_ = current_frame_number_; | 301 last_frame_number_where_draw_was_called_ = current_frame_number_; |
298 if (commit_state_ == COMMIT_STATE_WAITING_FOR_FIRST_FORCED_DRAW) { | 302 if (commit_state_ == COMMIT_STATE_WAITING_FOR_FIRST_FORCED_DRAW) { |
299 DCHECK(expect_immediate_begin_frame_); | 303 DCHECK(expect_immediate_begin_frame_for_main_thread_); |
300 commit_state_ = COMMIT_STATE_FRAME_IN_PROGRESS; | 304 commit_state_ = COMMIT_STATE_FRAME_IN_PROGRESS; |
301 expect_immediate_begin_frame_ = false; | 305 expect_immediate_begin_frame_for_main_thread_ = false; |
302 } else if (commit_state_ == COMMIT_STATE_WAITING_FOR_FIRST_DRAW) { | 306 } else if (commit_state_ == COMMIT_STATE_WAITING_FOR_FIRST_DRAW) { |
303 commit_state_ = COMMIT_STATE_IDLE; | 307 commit_state_ = COMMIT_STATE_IDLE; |
304 } | 308 } |
305 if (texture_state_ == LAYER_TEXTURE_STATE_ACQUIRED_BY_IMPL_THREAD) | 309 if (texture_state_ == LAYER_TEXTURE_STATE_ACQUIRED_BY_IMPL_THREAD) |
306 texture_state_ = LAYER_TEXTURE_STATE_UNLOCKED; | 310 texture_state_ = LAYER_TEXTURE_STATE_UNLOCKED; |
307 return; | 311 return; |
308 | 312 |
309 case ACTION_BEGIN_OUTPUT_SURFACE_CREATION: | 313 case ACTION_BEGIN_OUTPUT_SURFACE_CREATION: |
310 DCHECK_EQ(commit_state_, COMMIT_STATE_IDLE); | 314 DCHECK_EQ(commit_state_, COMMIT_STATE_IDLE); |
311 DCHECK_EQ(output_surface_state_, OUTPUT_SURFACE_LOST); | 315 DCHECK_EQ(output_surface_state_, OUTPUT_SURFACE_LOST); |
312 output_surface_state_ = OUTPUT_SURFACE_CREATING; | 316 output_surface_state_ = OUTPUT_SURFACE_CREATING; |
313 return; | 317 return; |
314 | 318 |
315 case ACTION_ACQUIRE_LAYER_TEXTURES_FOR_MAIN_THREAD: | 319 case ACTION_ACQUIRE_LAYER_TEXTURES_FOR_MAIN_THREAD: |
316 texture_state_ = LAYER_TEXTURE_STATE_ACQUIRED_BY_MAIN_THREAD; | 320 texture_state_ = LAYER_TEXTURE_STATE_ACQUIRED_BY_MAIN_THREAD; |
317 main_thread_needs_layer_textures_ = false; | 321 main_thread_needs_layer_textures_ = false; |
318 if (commit_state_ != COMMIT_STATE_FRAME_IN_PROGRESS) | 322 if (commit_state_ != COMMIT_STATE_FRAME_IN_PROGRESS) |
319 needs_commit_ = true; | 323 needs_commit_ = true; |
320 return; | 324 return; |
321 } | 325 } |
322 } | 326 } |
323 | 327 |
324 void SchedulerStateMachine::SetMainThreadNeedsLayerTextures() { | 328 void SchedulerStateMachine::SetMainThreadNeedsLayerTextures() { |
325 DCHECK(!main_thread_needs_layer_textures_); | 329 DCHECK(!main_thread_needs_layer_textures_); |
326 DCHECK_NE(texture_state_, LAYER_TEXTURE_STATE_ACQUIRED_BY_MAIN_THREAD); | 330 DCHECK_NE(texture_state_, LAYER_TEXTURE_STATE_ACQUIRED_BY_MAIN_THREAD); |
327 main_thread_needs_layer_textures_ = true; | 331 main_thread_needs_layer_textures_ = true; |
328 } | 332 } |
329 | 333 |
330 bool SchedulerStateMachine::VSyncCallbackNeeded() const { | 334 bool SchedulerStateMachine::BeginFrameNeededByImplThread() const { |
331 // If we have a pending tree, need to keep getting notifications until | 335 // If we have a pending tree, need to keep getting notifications until |
332 // the tree is ready to be swapped. | 336 // the tree is ready to be swapped. |
333 if (has_pending_tree_) | 337 if (has_pending_tree_) |
334 return true; | 338 return true; |
335 | 339 |
336 // If we can't draw, don't tick until we are notified that we can draw again. | 340 // If we can't draw, don't tick until we are notified that we can draw again. |
337 if (!can_draw_) | 341 if (!can_draw_) |
338 return false; | 342 return false; |
339 | 343 |
340 if (needs_forced_redraw_) | 344 if (needs_forced_redraw_) |
341 return true; | 345 return true; |
342 | 346 |
343 if (visible_ && swap_used_incomplete_tile_) | 347 if (visible_ && swap_used_incomplete_tile_) |
344 return true; | 348 return true; |
345 | 349 |
346 return needs_redraw_ && visible_ && | 350 return needs_redraw_ && visible_ && |
347 output_surface_state_ == OUTPUT_SURFACE_ACTIVE; | 351 output_surface_state_ == OUTPUT_SURFACE_ACTIVE; |
348 } | 352 } |
349 | 353 |
350 void SchedulerStateMachine::DidEnterVSync() { inside_vsync_ = true; } | 354 void SchedulerStateMachine::DidEnterBeginFrame() { |
| 355 inside_begin_frame_ = true; |
| 356 } |
351 | 357 |
352 void SchedulerStateMachine::DidLeaveVSync() { | 358 void SchedulerStateMachine::DidLeaveBeginFrame() { |
353 current_frame_number_++; | 359 current_frame_number_++; |
354 inside_vsync_ = false; | 360 inside_begin_frame_ = false; |
355 } | 361 } |
356 | 362 |
357 void SchedulerStateMachine::SetVisible(bool visible) { visible_ = visible; } | 363 void SchedulerStateMachine::SetVisible(bool visible) { visible_ = visible; } |
358 | 364 |
359 void SchedulerStateMachine::SetNeedsRedraw() { needs_redraw_ = true; } | 365 void SchedulerStateMachine::SetNeedsRedraw() { needs_redraw_ = true; } |
360 | 366 |
361 void SchedulerStateMachine::DidSwapUseIncompleteTile() { | 367 void SchedulerStateMachine::DidSwapUseIncompleteTile() { |
362 swap_used_incomplete_tile_ = true; | 368 swap_used_incomplete_tile_ = true; |
363 } | 369 } |
364 | 370 |
(...skipping 17 matching lines...) Expand all Loading... |
382 } | 388 } |
383 } else { | 389 } else { |
384 consecutive_failed_draws_ = 0; | 390 consecutive_failed_draws_ = 0; |
385 } | 391 } |
386 } | 392 } |
387 | 393 |
388 void SchedulerStateMachine::SetNeedsCommit() { needs_commit_ = true; } | 394 void SchedulerStateMachine::SetNeedsCommit() { needs_commit_ = true; } |
389 | 395 |
390 void SchedulerStateMachine::SetNeedsForcedCommit() { | 396 void SchedulerStateMachine::SetNeedsForcedCommit() { |
391 needs_forced_commit_ = true; | 397 needs_forced_commit_ = true; |
392 expect_immediate_begin_frame_ = true; | 398 expect_immediate_begin_frame_for_main_thread_ = true; |
393 } | 399 } |
394 | 400 |
395 void SchedulerStateMachine::BeginFrameComplete() { | 401 void SchedulerStateMachine::FinishCommit() { |
396 DCHECK(commit_state_ == COMMIT_STATE_FRAME_IN_PROGRESS || | 402 DCHECK(commit_state_ == COMMIT_STATE_FRAME_IN_PROGRESS || |
397 (expect_immediate_begin_frame_ && commit_state_ != COMMIT_STATE_IDLE)) | 403 (expect_immediate_begin_frame_for_main_thread_ && |
| 404 commit_state_ != COMMIT_STATE_IDLE)) |
398 << ToString(); | 405 << ToString(); |
399 commit_state_ = COMMIT_STATE_READY_TO_COMMIT; | 406 commit_state_ = COMMIT_STATE_READY_TO_COMMIT; |
400 } | 407 } |
401 | 408 |
402 void SchedulerStateMachine::BeginFrameAborted() { | 409 void SchedulerStateMachine::BeginFrameAbortedByMainThread() { |
403 DCHECK_EQ(commit_state_, COMMIT_STATE_FRAME_IN_PROGRESS); | 410 DCHECK_EQ(commit_state_, COMMIT_STATE_FRAME_IN_PROGRESS); |
404 if (expect_immediate_begin_frame_) { | 411 if (expect_immediate_begin_frame_for_main_thread_) { |
405 expect_immediate_begin_frame_ = false; | 412 expect_immediate_begin_frame_for_main_thread_ = false; |
406 } else { | 413 } else { |
407 commit_state_ = COMMIT_STATE_IDLE; | 414 commit_state_ = COMMIT_STATE_IDLE; |
408 SetNeedsCommit(); | 415 SetNeedsCommit(); |
409 } | 416 } |
410 } | 417 } |
411 | 418 |
412 void SchedulerStateMachine::DidLoseOutputSurface() { | 419 void SchedulerStateMachine::DidLoseOutputSurface() { |
413 if (output_surface_state_ == OUTPUT_SURFACE_LOST || | 420 if (output_surface_state_ == OUTPUT_SURFACE_LOST || |
414 output_surface_state_ == OUTPUT_SURFACE_CREATING) | 421 output_surface_state_ == OUTPUT_SURFACE_CREATING) |
415 return; | 422 return; |
(...skipping 25 matching lines...) Expand all Loading... |
441 bool SchedulerStateMachine::HasInitializedOutputSurface() const { | 448 bool SchedulerStateMachine::HasInitializedOutputSurface() const { |
442 return output_surface_state_ == OUTPUT_SURFACE_ACTIVE; | 449 return output_surface_state_ == OUTPUT_SURFACE_ACTIVE; |
443 } | 450 } |
444 | 451 |
445 void SchedulerStateMachine::SetMaximumNumberOfFailedDrawsBeforeDrawIsForced( | 452 void SchedulerStateMachine::SetMaximumNumberOfFailedDrawsBeforeDrawIsForced( |
446 int num_draws) { | 453 int num_draws) { |
447 maximum_number_of_failed_draws_before_draw_is_forced_ = num_draws; | 454 maximum_number_of_failed_draws_before_draw_is_forced_ = num_draws; |
448 } | 455 } |
449 | 456 |
450 } // namespace cc | 457 } // namespace cc |
OLD | NEW |