| 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 393 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 404 if (begin_frame_source_paused_) | 404 if (begin_frame_source_paused_) |
| 405 return false; | 405 return false; |
| 406 | 406 |
| 407 // Do not make a new commits when it is deferred. | 407 // Do not make a new commits when it is deferred. |
| 408 if (defer_commits_) | 408 if (defer_commits_) |
| 409 return false; | 409 return false; |
| 410 | 410 |
| 411 return true; | 411 return true; |
| 412 } | 412 } |
| 413 | 413 |
| 414 bool SchedulerStateMachine::SendingBeginMainFrameMightCauseDeadlock() const { | |
| 415 // NPAPI is the only case where the UI thread makes synchronous calls to the | |
| 416 // Renderer main thread. During that synchronous call, we may not get a | |
| 417 // SwapAck for the UI thread, which may prevent BeginMainFrame's from | |
| 418 // completing if there's enough back pressure. If the BeginMainFrame can't | |
| 419 // make progress, the Renderer can't service the UI thread's synchronous call | |
| 420 // and we have deadlock. | |
| 421 // This returns true if there's too much backpressure to finish a commit | |
| 422 // if we were to initiate a BeginMainFrame. | |
| 423 return has_pending_tree_ && active_tree_needs_first_draw_ && SwapThrottled(); | |
| 424 } | |
| 425 | |
| 426 bool SchedulerStateMachine::ShouldSendBeginMainFrame() const { | 414 bool SchedulerStateMachine::ShouldSendBeginMainFrame() const { |
| 427 if (!CouldSendBeginMainFrame()) | 415 if (!CouldSendBeginMainFrame()) |
| 428 return false; | 416 return false; |
| 429 | 417 |
| 430 // Do not send begin main frame too many times in a single frame or before | 418 // Do not send begin main frame too many times in a single frame or before |
| 431 // the first BeginFrame. | 419 // the first BeginFrame. |
| 432 if (send_begin_main_frame_funnel_) | 420 if (send_begin_main_frame_funnel_) |
| 433 return false; | 421 return false; |
| 434 | 422 |
| 435 // Only send BeginMainFrame when there isn't another commit pending already. | 423 // Only send BeginMainFrame when there isn't another commit pending already. |
| (...skipping 16 matching lines...) Expand all Loading... |
| 452 // latency in that case. | 440 // latency in that case. |
| 453 // TODO(brianderson): Allow sending BeginMainFrame while idle when the main | 441 // TODO(brianderson): Allow sending BeginMainFrame while idle when the main |
| 454 // thread isn't consuming user input for non-synchronous compositor. | 442 // thread isn't consuming user input for non-synchronous compositor. |
| 455 if (!settings_.using_synchronous_renderer_compositor && | 443 if (!settings_.using_synchronous_renderer_compositor && |
| 456 begin_impl_frame_state_ == BEGIN_IMPL_FRAME_STATE_IDLE) { | 444 begin_impl_frame_state_ == BEGIN_IMPL_FRAME_STATE_IDLE) { |
| 457 return false; | 445 return false; |
| 458 } | 446 } |
| 459 | 447 |
| 460 // We need a new commit for the forced redraw. This honors the | 448 // We need a new commit for the forced redraw. This honors the |
| 461 // single commit per interval because the result will be swapped to screen. | 449 // single commit per interval because the result will be swapped to screen. |
| 462 // TODO(brianderson): Remove this or move it below the | |
| 463 // SendingBeginMainFrameMightCauseDeadlock check since we want to avoid | |
| 464 // ever returning true from this method if we might cause deadlock. | |
| 465 if (forced_redraw_state_ == FORCED_REDRAW_STATE_WAITING_FOR_COMMIT) | 450 if (forced_redraw_state_ == FORCED_REDRAW_STATE_WAITING_FOR_COMMIT) |
| 466 return true; | 451 return true; |
| 467 | 452 |
| 468 // We shouldn't normally accept commits if there isn't an OutputSurface. | 453 // We shouldn't normally accept commits if there isn't an OutputSurface. |
| 469 if (!HasInitializedOutputSurface()) | 454 if (!HasInitializedOutputSurface()) |
| 470 return false; | 455 return false; |
| 471 | 456 |
| 472 // Make sure the BeginMainFrame can finish eventually if we start it. | |
| 473 if (SendingBeginMainFrameMightCauseDeadlock()) | |
| 474 return false; | |
| 475 | |
| 476 if (!settings_.main_frame_while_swap_throttled_enabled) { | 457 if (!settings_.main_frame_while_swap_throttled_enabled) { |
| 477 // SwapAck throttle the BeginMainFrames unless we just swapped to | 458 // SwapAck throttle the BeginMainFrames unless we just swapped to |
| 478 // potentially improve impl-thread latency over main-thread throughput. | 459 // potentially improve impl-thread latency over main-thread throughput. |
| 479 // TODO(brianderson): Remove this restriction to improve throughput or | 460 // TODO(brianderson): Remove this restriction to improve throughput or |
| 480 // make it conditional on ImplLatencyTakesPriority. | 461 // make it conditional on ImplLatencyTakesPriority. |
| 481 bool just_swapped_in_deadline = | 462 bool just_swapped_in_deadline = |
| 482 begin_impl_frame_state_ == BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE && | 463 begin_impl_frame_state_ == BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE && |
| 483 did_swap_in_last_frame_; | 464 did_swap_in_last_frame_; |
| 484 if (SwapThrottled() && !just_swapped_in_deadline) | 465 if (SwapThrottled() && !just_swapped_in_deadline) |
| 485 return false; | 466 return false; |
| (...skipping 649 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1135 case OUTPUT_SURFACE_ACTIVE: | 1116 case OUTPUT_SURFACE_ACTIVE: |
| 1136 case OUTPUT_SURFACE_WAITING_FOR_FIRST_COMMIT: | 1117 case OUTPUT_SURFACE_WAITING_FOR_FIRST_COMMIT: |
| 1137 case OUTPUT_SURFACE_WAITING_FOR_FIRST_ACTIVATION: | 1118 case OUTPUT_SURFACE_WAITING_FOR_FIRST_ACTIVATION: |
| 1138 return true; | 1119 return true; |
| 1139 } | 1120 } |
| 1140 NOTREACHED(); | 1121 NOTREACHED(); |
| 1141 return false; | 1122 return false; |
| 1142 } | 1123 } |
| 1143 | 1124 |
| 1144 } // namespace cc | 1125 } // namespace cc |
| OLD | NEW |