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 #include "base/trace_event/trace_event.h" | 10 #include "base/trace_event/trace_event.h" |
(...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
395 if (!visible_) | 395 if (!visible_) |
396 return false; | 396 return false; |
397 | 397 |
398 // Do not make a new commits when it is deferred. | 398 // Do not make a new commits when it is deferred. |
399 if (defer_commits_) | 399 if (defer_commits_) |
400 return false; | 400 return false; |
401 | 401 |
402 return true; | 402 return true; |
403 } | 403 } |
404 | 404 |
405 bool SchedulerStateMachine::SendingBeginMainFrameMightCauseDeadlock() const { | |
406 // NPAPI is the only case where the UI thread makes synchronous calls to the | |
407 // Renderer main thread. During that synchronous call, we may not get a | |
408 // SwapAck for the UI thread, which may prevent BeginMainFrame's from | |
409 // completing if there's enough back pressure. If the BeginMainFrame can't | |
410 // make progress, the Renderer can't service the UI thread's synchronous call | |
411 // and we have deadlock. | |
412 // This returns true if there's too much backpressure to finish a | |
413 // BeginMainFrame if we were to initiate one. | |
sunnyps
2015/05/20 19:26:51
nit: finish a commit if we were to initiate a Begi
brianderson
2015/05/20 19:49:47
Done.
| |
414 // TODO(brianderson): Remove this once NPAPI support is removed. | |
sunnyps
2015/05/20 19:26:51
nit: Move this TODO to the header.
brianderson
2015/05/20 19:49:46
Done.
| |
415 return has_pending_tree_ && active_tree_needs_first_draw_ && | |
416 pending_swaps_ >= max_pending_swaps_; | |
417 } | |
418 | |
405 bool SchedulerStateMachine::ShouldSendBeginMainFrame() const { | 419 bool SchedulerStateMachine::ShouldSendBeginMainFrame() const { |
406 if (!CouldSendBeginMainFrame()) | 420 if (!CouldSendBeginMainFrame()) |
407 return false; | 421 return false; |
408 | 422 |
409 // Do not send begin main frame too many times in a single frame. | 423 // Do not send begin main frame too many times in a single frame. |
410 if (send_begin_main_frame_funnel_) | 424 if (send_begin_main_frame_funnel_) |
411 return false; | 425 return false; |
412 | 426 |
413 // Only send BeginMainFrame when there isn't another commit pending already. | 427 // Only send BeginMainFrame when there isn't another commit pending already. |
428 // Other parts of the state machine indirectly defer the BeginMainFrame | |
429 // by transitioning to WAITING commit states rather than going | |
430 // immediately to IDLE. | |
414 if (commit_state_ != COMMIT_STATE_IDLE) | 431 if (commit_state_ != COMMIT_STATE_IDLE) |
415 return false; | 432 return false; |
416 | 433 |
417 // Don't send BeginMainFrame early if we are prioritizing the active tree | 434 // Don't send BeginMainFrame early if we are prioritizing the active tree |
418 // because of impl_latency_takes_priority_. | 435 // because of impl_latency_takes_priority_. |
419 if (impl_latency_takes_priority_ && | 436 if (impl_latency_takes_priority_ && |
420 (has_pending_tree_ || active_tree_needs_first_draw_)) { | 437 (has_pending_tree_ || active_tree_needs_first_draw_)) { |
421 return false; | 438 return false; |
422 } | 439 } |
423 | 440 |
424 // We should not send BeginMainFrame while we are in | 441 // We should not send BeginMainFrame while we are in |
425 // BEGIN_IMPL_FRAME_STATE_IDLE since we might have new | 442 // BEGIN_IMPL_FRAME_STATE_IDLE since we might have new |
426 // user input arriving soon. | 443 // user input arriving soon. |
427 // TODO(brianderson): Allow sending BeginMainFrame while idle when the main | 444 // TODO(brianderson): Allow sending BeginMainFrame while idle when the main |
428 // thread isn't consuming user input. | 445 // thread isn't consuming user input. |
429 if (begin_impl_frame_state_ == BEGIN_IMPL_FRAME_STATE_IDLE && | 446 if (begin_impl_frame_state_ == BEGIN_IMPL_FRAME_STATE_IDLE && |
430 BeginFrameNeeded()) | 447 BeginFrameNeeded()) |
431 return false; | 448 return false; |
432 | 449 |
433 // We need a new commit for the forced redraw. This honors the | 450 // We need a new commit for the forced redraw. This honors the |
434 // single commit per interval because the result will be swapped to screen. | 451 // single commit per interval because the result will be swapped to screen. |
452 // TODO(brianderson): Remove this or move it below the deadlock check. | |
sunnyps
2015/05/20 19:26:50
nit: Why?
brianderson
2015/05/20 19:49:47
Updated comment. We never want to return true from
| |
435 if (forced_redraw_state_ == FORCED_REDRAW_STATE_WAITING_FOR_COMMIT) | 453 if (forced_redraw_state_ == FORCED_REDRAW_STATE_WAITING_FOR_COMMIT) |
436 return true; | 454 return true; |
437 | 455 |
438 // We shouldn't normally accept commits if there isn't an OutputSurface. | 456 // We shouldn't normally accept commits if there isn't an OutputSurface. |
439 if (!HasInitializedOutputSurface()) | 457 if (!HasInitializedOutputSurface()) |
440 return false; | 458 return false; |
441 | 459 |
442 // SwapAck throttle the BeginMainFrames unless we just swapped. | 460 // Make sure the BeginMainFrame will finish eventually if we start it. |
443 // TODO(brianderson): Remove this restriction to improve throughput. | 461 if (SendingBeginMainFrameMightCauseDeadlock()) |
444 bool just_swapped_in_deadline = | |
445 begin_impl_frame_state_ == BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE && | |
446 did_perform_swap_in_last_draw_; | |
447 if (pending_swaps_ >= max_pending_swaps_ && !just_swapped_in_deadline) | |
448 return false; | 462 return false; |
449 | 463 |
464 if (!settings_.main_frame_while_swap_throttled_enabled) { | |
465 // SwapAck throttle the BeginMainFrames unless we just swapped to | |
466 // potentially improve impl-thread latency over main-thread throughput. | |
467 // TODO(brianderson): Remove this restriction to improve throughput or | |
468 // make it conditional on impl_latency_takes_priority_. | |
469 bool just_swapped_in_deadline = | |
470 begin_impl_frame_state_ == BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE && | |
471 did_perform_swap_in_last_draw_; | |
472 if (pending_swaps_ >= max_pending_swaps_ && !just_swapped_in_deadline) | |
473 return false; | |
474 } | |
475 | |
450 if (skip_begin_main_frame_to_reduce_latency_) | 476 if (skip_begin_main_frame_to_reduce_latency_) |
451 return false; | 477 return false; |
452 | 478 |
453 return true; | 479 return true; |
454 } | 480 } |
455 | 481 |
456 bool SchedulerStateMachine::ShouldCommit() const { | 482 bool SchedulerStateMachine::ShouldCommit() const { |
457 if (commit_state_ != COMMIT_STATE_READY_TO_COMMIT) | 483 if (commit_state_ != COMMIT_STATE_READY_TO_COMMIT) |
458 return false; | 484 return false; |
459 | 485 |
460 // We must not finish the commit until the pending tree is free. | 486 // We must not finish the commit until the pending tree is free. |
461 if (has_pending_tree_) { | 487 if (has_pending_tree_) { |
462 DCHECK(settings_.main_frame_before_activation_enabled); | 488 DCHECK(settings_.main_frame_before_activation_enabled); |
463 return false; | 489 return false; |
464 } | 490 } |
465 | 491 |
466 // Prioritize drawing the previous commit before finishing the next commit. | 492 if (settings_.impl_side_painting) { |
467 if (active_tree_needs_first_draw_) | 493 return true; |
494 } else if (active_tree_needs_first_draw_) { | |
sunnyps
2015/05/20 19:26:50
nit:
if (!settings_.impl_side_painting && active_t
brianderson
2015/05/20 19:49:46
Changed the organization a bit, but not exactly su
| |
495 // If we only have an active tree, it is incorrect to replace it | |
496 // before we've drawn it. | |
468 return false; | 497 return false; |
498 } | |
469 | 499 |
470 return true; | 500 return true; |
471 } | 501 } |
472 | 502 |
473 bool SchedulerStateMachine::ShouldPrepareTiles() const { | 503 bool SchedulerStateMachine::ShouldPrepareTiles() const { |
474 // PrepareTiles only really needs to be called immediately after commit | 504 // PrepareTiles only really needs to be called immediately after commit |
475 // and then periodically after that. Use a funnel to make sure we average | 505 // and then periodically after that. Use a funnel to make sure we average |
476 // one PrepareTiles per BeginImplFrame in the long run. | 506 // one PrepareTiles per BeginImplFrame in the long run. |
477 if (prepare_tiles_funnel_ > 0) | 507 if (prepare_tiles_funnel_ > 0) |
478 return false; | 508 return false; |
(...skipping 659 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1138 static_cast<int>(begin_impl_frame_state_), | 1168 static_cast<int>(begin_impl_frame_state_), |
1139 static_cast<int>(commit_state_), | 1169 static_cast<int>(commit_state_), |
1140 has_pending_tree_ ? 'T' : 'F', | 1170 has_pending_tree_ ? 'T' : 'F', |
1141 pending_tree_is_ready_for_activation_ ? 'T' : 'F', | 1171 pending_tree_is_ready_for_activation_ ? 'T' : 'F', |
1142 active_tree_needs_first_draw_ ? 'T' : 'F', | 1172 active_tree_needs_first_draw_ ? 'T' : 'F', |
1143 max_pending_swaps_, | 1173 max_pending_swaps_, |
1144 pending_swaps_); | 1174 pending_swaps_); |
1145 } | 1175 } |
1146 | 1176 |
1147 } // namespace cc | 1177 } // namespace cc |
OLD | NEW |