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/format_macros.h" | 7 #include "base/format_macros.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
10 | 10 |
11 namespace cc { | 11 namespace cc { |
12 | 12 |
13 SchedulerStateMachine::SchedulerStateMachine(const SchedulerSettings& settings) | 13 SchedulerStateMachine::SchedulerStateMachine(const SchedulerSettings& settings) |
14 : settings_(settings), | 14 : settings_(settings), |
15 commit_state_(COMMIT_STATE_IDLE), | 15 commit_state_(COMMIT_STATE_IDLE), |
16 commit_count_(0), | 16 commit_count_(0), |
17 current_frame_number_(0), | 17 current_frame_number_(0), |
18 last_frame_number_where_begin_frame_sent_to_main_thread_(-1), | |
18 last_frame_number_where_draw_was_called_(-1), | 19 last_frame_number_where_draw_was_called_(-1), |
19 last_frame_number_where_tree_activation_attempted_(-1), | 20 last_frame_number_where_tree_activation_attempted_(-1), |
20 last_frame_number_where_check_for_completed_tile_uploads_called_(-1), | 21 last_frame_number_where_check_for_completed_tile_uploads_called_(-1), |
21 consecutive_failed_draws_(0), | 22 consecutive_failed_draws_(0), |
22 maximum_number_of_failed_draws_before_draw_is_forced_(3), | 23 maximum_number_of_failed_draws_before_draw_is_forced_(3), |
23 needs_redraw_(false), | 24 needs_redraw_(false), |
24 swap_used_incomplete_tile_(false), | 25 swap_used_incomplete_tile_(false), |
25 needs_forced_redraw_(false), | 26 needs_forced_redraw_(false), |
26 needs_forced_redraw_after_next_commit_(false), | 27 needs_forced_redraw_after_next_commit_(false), |
27 needs_commit_(false), | 28 needs_commit_(false), |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
177 if (!BeginFrameNeededToDrawByImplThread()) | 178 if (!BeginFrameNeededToDrawByImplThread()) |
178 return true; | 179 return true; |
179 return false; | 180 return false; |
180 } | 181 } |
181 | 182 |
182 SchedulerStateMachine::Action SchedulerStateMachine::NextAction() const { | 183 SchedulerStateMachine::Action SchedulerStateMachine::NextAction() const { |
183 if (ShouldAcquireLayerTexturesForMainThread()) | 184 if (ShouldAcquireLayerTexturesForMainThread()) |
184 return ACTION_ACQUIRE_LAYER_TEXTURES_FOR_MAIN_THREAD; | 185 return ACTION_ACQUIRE_LAYER_TEXTURES_FOR_MAIN_THREAD; |
185 | 186 |
186 switch (commit_state_) { | 187 switch (commit_state_) { |
187 case COMMIT_STATE_IDLE: | 188 case COMMIT_STATE_IDLE: { |
188 if (output_surface_state_ != OUTPUT_SURFACE_ACTIVE && | 189 if (output_surface_state_ != OUTPUT_SURFACE_ACTIVE && |
189 needs_forced_redraw_) | 190 needs_forced_redraw_) |
190 return ACTION_DRAW_FORCED; | 191 return ACTION_DRAW_FORCED; |
191 if (output_surface_state_ != OUTPUT_SURFACE_ACTIVE && | 192 if (output_surface_state_ != OUTPUT_SURFACE_ACTIVE && |
192 needs_forced_commit_) | 193 needs_forced_commit_) |
193 // TODO(enne): Should probably drop the active tree on force commit. | 194 // TODO(enne): Should probably drop the active tree on force commit. |
194 return has_pending_tree_ ? ACTION_NONE | 195 return has_pending_tree_ ? ACTION_NONE |
195 : ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD; | 196 : ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD; |
196 if (output_surface_state_ == OUTPUT_SURFACE_LOST && can_start_) | 197 if (output_surface_state_ == OUTPUT_SURFACE_LOST && can_start_) |
197 return ACTION_BEGIN_OUTPUT_SURFACE_CREATION; | 198 return ACTION_BEGIN_OUTPUT_SURFACE_CREATION; |
198 if (output_surface_state_ == OUTPUT_SURFACE_CREATING) | 199 if (output_surface_state_ == OUTPUT_SURFACE_CREATING) |
199 return ACTION_NONE; | 200 return ACTION_NONE; |
200 if (ShouldCheckForCompletedTileUploads()) | 201 if (ShouldCheckForCompletedTileUploads()) |
201 return ACTION_CHECK_FOR_COMPLETED_TILE_UPLOADS; | 202 return ACTION_CHECK_FOR_COMPLETED_TILE_UPLOADS; |
202 if (ShouldAttemptTreeActivation()) | 203 if (ShouldAttemptTreeActivation()) |
203 return ACTION_ACTIVATE_PENDING_TREE_IF_NEEDED; | 204 return ACTION_ACTIVATE_PENDING_TREE_IF_NEEDED; |
204 if (ShouldDraw()) { | 205 if (ShouldDraw()) { |
205 return needs_forced_redraw_ ? ACTION_DRAW_FORCED | 206 return needs_forced_redraw_ ? ACTION_DRAW_FORCED |
206 : ACTION_DRAW_IF_POSSIBLE; | 207 : ACTION_DRAW_IF_POSSIBLE; |
207 } | 208 } |
208 if (needs_commit_ && | 209 bool can_commit_this_frame = |
209 ((visible_ && output_surface_state_ == OUTPUT_SURFACE_ACTIVE) | 210 visible_ && |
210 || needs_forced_commit_)) | 211 current_frame_number_ > |
212 last_frame_number_where_begin_frame_sent_to_main_thread_; | |
213 if (needs_commit_ && ((can_commit_this_frame && | |
214 output_surface_state_ == OUTPUT_SURFACE_ACTIVE) || | |
215 needs_forced_commit_)) | |
211 // TODO(enne): Should probably drop the active tree on force commit. | 216 // TODO(enne): Should probably drop the active tree on force commit. |
212 return has_pending_tree_ ? ACTION_NONE | 217 return has_pending_tree_ ? ACTION_NONE |
213 : ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD; | 218 : ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD; |
214 return ACTION_NONE; | 219 return ACTION_NONE; |
215 | 220 } |
216 case COMMIT_STATE_FRAME_IN_PROGRESS: | 221 case COMMIT_STATE_FRAME_IN_PROGRESS: |
217 if (ShouldCheckForCompletedTileUploads()) | 222 if (ShouldCheckForCompletedTileUploads()) |
218 return ACTION_CHECK_FOR_COMPLETED_TILE_UPLOADS; | 223 return ACTION_CHECK_FOR_COMPLETED_TILE_UPLOADS; |
219 if (ShouldAttemptTreeActivation()) | 224 if (ShouldAttemptTreeActivation()) |
220 return ACTION_ACTIVATE_PENDING_TREE_IF_NEEDED; | 225 return ACTION_ACTIVATE_PENDING_TREE_IF_NEEDED; |
221 if (ShouldDraw()) { | 226 if (ShouldDraw()) { |
222 return needs_forced_redraw_ ? ACTION_DRAW_FORCED | 227 return needs_forced_redraw_ ? ACTION_DRAW_FORCED |
223 : ACTION_DRAW_IF_POSSIBLE; | 228 : ACTION_DRAW_IF_POSSIBLE; |
224 } | 229 } |
225 return ACTION_NONE; | 230 return ACTION_NONE; |
226 | 231 |
227 case COMMIT_STATE_READY_TO_COMMIT: | 232 case COMMIT_STATE_READY_TO_COMMIT: |
228 return ACTION_COMMIT; | 233 return ACTION_COMMIT; |
229 | 234 |
230 case COMMIT_STATE_WAITING_FOR_FIRST_DRAW: { | 235 case COMMIT_STATE_WAITING_FOR_FIRST_DRAW: { |
231 if (ShouldCheckForCompletedTileUploads()) | 236 if (ShouldCheckForCompletedTileUploads()) |
232 return ACTION_CHECK_FOR_COMPLETED_TILE_UPLOADS; | 237 return ACTION_CHECK_FOR_COMPLETED_TILE_UPLOADS; |
233 if (ShouldAttemptTreeActivation()) | 238 if (ShouldAttemptTreeActivation()) |
234 return ACTION_ACTIVATE_PENDING_TREE_IF_NEEDED; | 239 return ACTION_ACTIVATE_PENDING_TREE_IF_NEEDED; |
235 if (ShouldDraw() || output_surface_state_ == OUTPUT_SURFACE_LOST) { | 240 if (ShouldDraw() || output_surface_state_ == OUTPUT_SURFACE_LOST) { |
236 return needs_forced_redraw_ ? ACTION_DRAW_FORCED | 241 return needs_forced_redraw_ ? ACTION_DRAW_FORCED |
237 : ACTION_DRAW_IF_POSSIBLE; | 242 : ACTION_DRAW_IF_POSSIBLE; |
238 } | 243 } |
239 // COMMIT_STATE_WAITING_FOR_FIRST_DRAW wants to enforce a draw. If | 244 // COMMIT_STATE_WAITING_FOR_FIRST_DRAW wants to enforce a draw. If |
240 // can_draw_ is false or textures are not available, proceed to the next | 245 // can_draw_ is false or textures are not available, proceed to the next |
241 // step (similar as in COMMIT_STATE_IDLE). | 246 // step (similar as in COMMIT_STATE_IDLE). |
242 bool can_commit = visible_ || needs_forced_commit_; | 247 bool can_commit = |
248 needs_forced_commit_ || | |
249 (visible_ && | |
250 current_frame_number_ > | |
251 last_frame_number_where_begin_frame_sent_to_main_thread_); | |
243 if (needs_commit_ && can_commit && DrawSuspendedUntilCommit()) | 252 if (needs_commit_ && can_commit && DrawSuspendedUntilCommit()) |
244 return has_pending_tree_ ? ACTION_NONE | 253 return has_pending_tree_ ? ACTION_NONE |
245 : ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD; | 254 : ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD; |
246 return ACTION_NONE; | 255 return ACTION_NONE; |
247 } | 256 } |
248 | 257 |
249 case COMMIT_STATE_WAITING_FOR_FIRST_FORCED_DRAW: | 258 case COMMIT_STATE_WAITING_FOR_FIRST_FORCED_DRAW: |
250 if (ShouldCheckForCompletedTileUploads()) | 259 if (ShouldCheckForCompletedTileUploads()) |
251 return ACTION_CHECK_FOR_COMPLETED_TILE_UPLOADS; | 260 return ACTION_CHECK_FOR_COMPLETED_TILE_UPLOADS; |
252 if (ShouldAttemptTreeActivation()) | 261 if (ShouldAttemptTreeActivation()) |
(...skipping 16 matching lines...) Expand all Loading... | |
269 current_frame_number_; | 278 current_frame_number_; |
270 return; | 279 return; |
271 | 280 |
272 case ACTION_ACTIVATE_PENDING_TREE_IF_NEEDED: | 281 case ACTION_ACTIVATE_PENDING_TREE_IF_NEEDED: |
273 last_frame_number_where_tree_activation_attempted_ = | 282 last_frame_number_where_tree_activation_attempted_ = |
274 current_frame_number_; | 283 current_frame_number_; |
275 return; | 284 return; |
276 | 285 |
277 case ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD: | 286 case ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD: |
278 DCHECK(!has_pending_tree_); | 287 DCHECK(!has_pending_tree_); |
279 DCHECK(visible_ || needs_forced_commit_); | 288 if (!needs_forced_commit_) { |
289 DCHECK(visible_); | |
290 DCHECK_GT(current_frame_number_, | |
291 last_frame_number_where_begin_frame_sent_to_main_thread_); | |
292 } | |
280 commit_state_ = COMMIT_STATE_FRAME_IN_PROGRESS; | 293 commit_state_ = COMMIT_STATE_FRAME_IN_PROGRESS; |
281 needs_commit_ = false; | 294 needs_commit_ = false; |
282 needs_forced_commit_ = false; | 295 needs_forced_commit_ = false; |
296 last_frame_number_where_begin_frame_sent_to_main_thread_ = | |
297 current_frame_number_; | |
283 return; | 298 return; |
284 | 299 |
285 case ACTION_COMMIT: | 300 case ACTION_COMMIT: |
286 commit_count_++; | 301 commit_count_++; |
287 if (expect_immediate_begin_frame_for_main_thread_) | 302 if (expect_immediate_begin_frame_for_main_thread_) |
288 commit_state_ = COMMIT_STATE_WAITING_FOR_FIRST_FORCED_DRAW; | 303 commit_state_ = COMMIT_STATE_WAITING_FOR_FIRST_FORCED_DRAW; |
289 else | 304 else |
290 commit_state_ = COMMIT_STATE_WAITING_FOR_FIRST_DRAW; | 305 commit_state_ = COMMIT_STATE_WAITING_FOR_FIRST_DRAW; |
291 // When impl-side painting, we draw on activation instead of on commit. | 306 // When impl-side painting, we draw on activation instead of on commit. |
292 if (!settings_.impl_side_painting) | 307 if (!settings_.impl_side_painting) |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
360 if (!visible_ || output_surface_state_ != OUTPUT_SURFACE_ACTIVE) | 375 if (!visible_ || output_surface_state_ != OUTPUT_SURFACE_ACTIVE) |
361 return false; | 376 return false; |
362 | 377 |
363 // We should proactively request a BeginFrame if a commit or a tree activation | 378 // We should proactively request a BeginFrame if a commit or a tree activation |
364 // is pending. | 379 // is pending. |
365 return (needs_commit_ || needs_forced_commit_ || | 380 return (needs_commit_ || needs_forced_commit_ || |
366 commit_state_ != COMMIT_STATE_IDLE || has_pending_tree_); | 381 commit_state_ != COMMIT_STATE_IDLE || has_pending_tree_); |
367 } | 382 } |
368 | 383 |
369 void SchedulerStateMachine::DidEnterBeginFrame(const BeginFrameArgs& args) { | 384 void SchedulerStateMachine::DidEnterBeginFrame(const BeginFrameArgs& args) { |
385 current_frame_number_++; | |
370 inside_begin_frame_ = true; | 386 inside_begin_frame_ = true; |
371 last_begin_frame_args_ = args; | 387 last_begin_frame_args_ = args; |
372 } | 388 } |
373 | 389 |
374 void SchedulerStateMachine::DidLeaveBeginFrame() { | 390 void SchedulerStateMachine::DidLeaveBeginFrame() { |
375 current_frame_number_++; | |
376 inside_begin_frame_ = false; | 391 inside_begin_frame_ = false; |
377 } | 392 } |
378 | 393 |
379 void SchedulerStateMachine::SetVisible(bool visible) { visible_ = visible; } | 394 void SchedulerStateMachine::SetVisible(bool visible) { visible_ = visible; } |
380 | 395 |
381 void SchedulerStateMachine::SetNeedsRedraw() { needs_redraw_ = true; } | 396 void SchedulerStateMachine::SetNeedsRedraw() { needs_redraw_ = true; } |
382 | 397 |
383 void SchedulerStateMachine::DidSwapUseIncompleteTile() { | 398 void SchedulerStateMachine::DidSwapUseIncompleteTile() { |
384 swap_used_incomplete_tile_ = true; | 399 swap_used_incomplete_tile_ = true; |
385 } | 400 } |
(...skipping 29 matching lines...) Expand all Loading... | |
415 } | 430 } |
416 | 431 |
417 void SchedulerStateMachine::FinishCommit() { | 432 void SchedulerStateMachine::FinishCommit() { |
418 DCHECK(commit_state_ == COMMIT_STATE_FRAME_IN_PROGRESS || | 433 DCHECK(commit_state_ == COMMIT_STATE_FRAME_IN_PROGRESS || |
419 (expect_immediate_begin_frame_for_main_thread_ && | 434 (expect_immediate_begin_frame_for_main_thread_ && |
420 commit_state_ != COMMIT_STATE_IDLE)) | 435 commit_state_ != COMMIT_STATE_IDLE)) |
421 << ToString(); | 436 << ToString(); |
422 commit_state_ = COMMIT_STATE_READY_TO_COMMIT; | 437 commit_state_ = COMMIT_STATE_READY_TO_COMMIT; |
423 } | 438 } |
424 | 439 |
425 void SchedulerStateMachine::BeginFrameAbortedByMainThread() { | 440 void SchedulerStateMachine::BeginFrameAbortedByMainThread(bool did_handle) { |
426 DCHECK_EQ(commit_state_, COMMIT_STATE_FRAME_IN_PROGRESS); | 441 DCHECK_EQ(commit_state_, COMMIT_STATE_FRAME_IN_PROGRESS); |
427 if (expect_immediate_begin_frame_for_main_thread_) { | 442 if (expect_immediate_begin_frame_for_main_thread_) { |
428 expect_immediate_begin_frame_for_main_thread_ = false; | 443 expect_immediate_begin_frame_for_main_thread_ = false; |
444 } else if (did_handle) { | |
445 commit_state_ = COMMIT_STATE_IDLE; | |
446 if (needs_forced_redraw_after_next_commit_) { | |
447 needs_forced_redraw_after_next_commit_ = false; | |
danakj
2013/07/18 21:57:23
What about the other states changed in ACTION_COMM
enne (OOO)
2013/07/19 01:23:51
Unfortunately, there's not that much sharing.
Abo
danakj
2013/07/22 17:16:20
I'd say they are different, because drawing is blo
enne (OOO)
2013/07/22 19:02:43
Done.
| |
448 needs_forced_redraw_ = true; | |
449 } | |
429 } else { | 450 } else { |
430 commit_state_ = COMMIT_STATE_IDLE; | 451 commit_state_ = COMMIT_STATE_IDLE; |
431 SetNeedsCommit(); | 452 SetNeedsCommit(); |
432 } | 453 } |
433 } | 454 } |
434 | 455 |
435 void SchedulerStateMachine::DidLoseOutputSurface() { | 456 void SchedulerStateMachine::DidLoseOutputSurface() { |
436 if (output_surface_state_ == OUTPUT_SURFACE_LOST || | 457 if (output_surface_state_ == OUTPUT_SURFACE_LOST || |
437 output_surface_state_ == OUTPUT_SURFACE_CREATING) | 458 output_surface_state_ == OUTPUT_SURFACE_CREATING) |
438 return; | 459 return; |
(...skipping 25 matching lines...) Expand all Loading... | |
464 bool SchedulerStateMachine::HasInitializedOutputSurface() const { | 485 bool SchedulerStateMachine::HasInitializedOutputSurface() const { |
465 return output_surface_state_ == OUTPUT_SURFACE_ACTIVE; | 486 return output_surface_state_ == OUTPUT_SURFACE_ACTIVE; |
466 } | 487 } |
467 | 488 |
468 void SchedulerStateMachine::SetMaximumNumberOfFailedDrawsBeforeDrawIsForced( | 489 void SchedulerStateMachine::SetMaximumNumberOfFailedDrawsBeforeDrawIsForced( |
469 int num_draws) { | 490 int num_draws) { |
470 maximum_number_of_failed_draws_before_draw_is_forced_ = num_draws; | 491 maximum_number_of_failed_draws_before_draw_is_forced_ = num_draws; |
471 } | 492 } |
472 | 493 |
473 } // namespace cc | 494 } // namespace cc |
OLD | NEW |