| 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" |
| 11 #include "base/trace_event/trace_event_argument.h" | 11 #include "base/trace_event/trace_event_argument.h" |
| 12 #include "base/values.h" | 12 #include "base/values.h" |
| 13 #include "ui/gfx/frame_time.h" | 13 #include "ui/gfx/frame_time.h" |
| 14 | 14 |
| 15 namespace cc { | 15 namespace cc { |
| 16 | 16 |
| 17 SchedulerStateMachine::SchedulerStateMachine(const SchedulerSettings& settings) | 17 SchedulerStateMachine::SchedulerStateMachine(const SchedulerSettings& settings) |
| 18 : settings_(settings), | 18 : settings_(settings), |
| 19 output_surface_state_(OUTPUT_SURFACE_LOST), | 19 output_surface_state_(OUTPUT_SURFACE_LOST), |
| 20 begin_impl_frame_state_(BEGIN_IMPL_FRAME_STATE_IDLE), | 20 begin_impl_frame_state_(BEGIN_IMPL_FRAME_STATE_IDLE), |
| 21 commit_state_(COMMIT_STATE_IDLE), | 21 commit_state_(COMMIT_STATE_IDLE), |
| 22 forced_redraw_state_(FORCED_REDRAW_STATE_IDLE), | 22 forced_redraw_state_(FORCED_REDRAW_STATE_IDLE), |
| 23 commit_count_(0), | 23 commit_count_(0), |
| 24 current_frame_number_(0), | 24 current_frame_number_(0), |
| 25 last_frame_number_animate_performed_(-1), | 25 last_frame_number_animate_performed_(-1), |
| 26 last_frame_number_swap_performed_(-1), | 26 last_frame_number_swap_performed_(-1), |
| 27 last_frame_number_swap_requested_(-1), | 27 last_frame_number_swap_requested_(-1), |
| 28 last_frame_number_begin_main_frame_sent_(-1), | 28 last_frame_number_begin_main_frame_sent_(-1), |
| 29 last_frame_number_invalidate_output_surface_performed_(-1), | |
| 30 animate_funnel_(false), | 29 animate_funnel_(false), |
| 30 perform_swap_funnel_(false), |
| 31 request_swap_funnel_(false), | 31 request_swap_funnel_(false), |
| 32 send_begin_main_frame_funnel_(false), | 32 send_begin_main_frame_funnel_(false), |
| 33 invalidate_output_surface_funnel_(false), | |
| 34 prepare_tiles_funnel_(0), | 33 prepare_tiles_funnel_(0), |
| 35 consecutive_checkerboard_animations_(0), | 34 consecutive_checkerboard_animations_(0), |
| 36 max_pending_swaps_(1), | 35 max_pending_swaps_(1), |
| 37 pending_swaps_(0), | 36 pending_swaps_(0), |
| 38 needs_redraw_(false), | 37 needs_redraw_(false), |
| 39 needs_animate_(false), | 38 needs_animate_(false), |
| 40 needs_prepare_tiles_(false), | 39 needs_prepare_tiles_(false), |
| 41 needs_commit_(false), | 40 needs_commit_(false), |
| 41 inside_poll_for_anticipated_draw_triggers_(false), |
| 42 visible_(false), | 42 visible_(false), |
| 43 can_start_(false), | 43 can_start_(false), |
| 44 can_draw_(false), | 44 can_draw_(false), |
| 45 has_pending_tree_(false), | 45 has_pending_tree_(false), |
| 46 pending_tree_is_ready_for_activation_(false), | 46 pending_tree_is_ready_for_activation_(false), |
| 47 active_tree_needs_first_draw_(false), | 47 active_tree_needs_first_draw_(false), |
| 48 did_create_and_initialize_first_output_surface_(false), | 48 did_create_and_initialize_first_output_surface_(false), |
| 49 impl_latency_takes_priority_(false), | 49 impl_latency_takes_priority_(false), |
| 50 skip_next_begin_main_frame_to_reduce_latency_(false), | 50 skip_next_begin_main_frame_to_reduce_latency_(false), |
| 51 skip_begin_main_frame_to_reduce_latency_(false), | 51 skip_begin_main_frame_to_reduce_latency_(false), |
| 52 continuous_painting_(false), | 52 continuous_painting_(false), |
| 53 children_need_begin_frames_(false), | 53 children_need_begin_frames_(false), |
| 54 defer_commits_(false), | 54 defer_commits_(false), |
| 55 last_commit_had_no_updates_(false), | 55 last_commit_had_no_updates_(false) { |
| 56 did_request_swap_in_last_frame_(false), | |
| 57 did_perform_swap_in_last_draw_(false) { | |
| 58 } | 56 } |
| 59 | 57 |
| 60 const char* SchedulerStateMachine::OutputSurfaceStateToString( | 58 const char* SchedulerStateMachine::OutputSurfaceStateToString( |
| 61 OutputSurfaceState state) { | 59 OutputSurfaceState state) { |
| 62 switch (state) { | 60 switch (state) { |
| 63 case OUTPUT_SURFACE_ACTIVE: | 61 case OUTPUT_SURFACE_ACTIVE: |
| 64 return "OUTPUT_SURFACE_ACTIVE"; | 62 return "OUTPUT_SURFACE_ACTIVE"; |
| 65 case OUTPUT_SURFACE_LOST: | 63 case OUTPUT_SURFACE_LOST: |
| 66 return "OUTPUT_SURFACE_LOST"; | 64 return "OUTPUT_SURFACE_LOST"; |
| 67 case OUTPUT_SURFACE_CREATING: | 65 case OUTPUT_SURFACE_CREATING: |
| (...skipping 14 matching lines...) Expand all Loading... |
| 82 return "BEGIN_IMPL_FRAME_STATE_IDLE"; | 80 return "BEGIN_IMPL_FRAME_STATE_IDLE"; |
| 83 case BEGIN_IMPL_FRAME_STATE_BEGIN_FRAME_STARTING: | 81 case BEGIN_IMPL_FRAME_STATE_BEGIN_FRAME_STARTING: |
| 84 return "BEGIN_IMPL_FRAME_STATE_BEGIN_FRAME_STARTING"; | 82 return "BEGIN_IMPL_FRAME_STATE_BEGIN_FRAME_STARTING"; |
| 85 case BEGIN_IMPL_FRAME_STATE_INSIDE_BEGIN_FRAME: | 83 case BEGIN_IMPL_FRAME_STATE_INSIDE_BEGIN_FRAME: |
| 86 return "BEGIN_IMPL_FRAME_STATE_INSIDE_BEGIN_FRAME"; | 84 return "BEGIN_IMPL_FRAME_STATE_INSIDE_BEGIN_FRAME"; |
| 87 case BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE: | 85 case BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE: |
| 88 return "BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE"; | 86 return "BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE"; |
| 89 } | 87 } |
| 90 NOTREACHED(); | 88 NOTREACHED(); |
| 91 return "???"; | 89 return "???"; |
| 92 } | |
| 93 | |
| 94 const char* SchedulerStateMachine::BeginImplFrameDeadlineModeToString( | |
| 95 BeginImplFrameDeadlineMode mode) { | |
| 96 switch (mode) { | |
| 97 case BEGIN_IMPL_FRAME_DEADLINE_MODE_NONE: | |
| 98 return "BEGIN_IMPL_FRAME_DEADLINE_MODE_NONE"; | |
| 99 case BEGIN_IMPL_FRAME_DEADLINE_MODE_IMMEDIATE: | |
| 100 return "BEGIN_IMPL_FRAME_DEADLINE_MODE_IMMEDIATE"; | |
| 101 case BEGIN_IMPL_FRAME_DEADLINE_MODE_REGULAR: | |
| 102 return "BEGIN_IMPL_FRAME_DEADLINE_MODE_REGULAR"; | |
| 103 case BEGIN_IMPL_FRAME_DEADLINE_MODE_LATE: | |
| 104 return "BEGIN_IMPL_FRAME_DEADLINE_MODE_LATE"; | |
| 105 } | |
| 106 NOTREACHED(); | |
| 107 return "???"; | |
| 108 } | 90 } |
| 109 | 91 |
| 110 const char* SchedulerStateMachine::CommitStateToString(CommitState state) { | 92 const char* SchedulerStateMachine::CommitStateToString(CommitState state) { |
| 111 switch (state) { | 93 switch (state) { |
| 112 case COMMIT_STATE_IDLE: | 94 case COMMIT_STATE_IDLE: |
| 113 return "COMMIT_STATE_IDLE"; | 95 return "COMMIT_STATE_IDLE"; |
| 114 case COMMIT_STATE_BEGIN_MAIN_FRAME_SENT: | 96 case COMMIT_STATE_BEGIN_MAIN_FRAME_SENT: |
| 115 return "COMMIT_STATE_BEGIN_MAIN_FRAME_SENT"; | 97 return "COMMIT_STATE_BEGIN_MAIN_FRAME_SENT"; |
| 116 case COMMIT_STATE_BEGIN_MAIN_FRAME_STARTED: | 98 case COMMIT_STATE_BEGIN_MAIN_FRAME_STARTED: |
| 117 return "COMMIT_STATE_BEGIN_MAIN_FRAME_STARTED"; | 99 return "COMMIT_STATE_BEGIN_MAIN_FRAME_STARTED"; |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 case ACTION_DRAW_AND_SWAP_IF_POSSIBLE: | 139 case ACTION_DRAW_AND_SWAP_IF_POSSIBLE: |
| 158 return "ACTION_DRAW_AND_SWAP_IF_POSSIBLE"; | 140 return "ACTION_DRAW_AND_SWAP_IF_POSSIBLE"; |
| 159 case ACTION_DRAW_AND_SWAP_FORCED: | 141 case ACTION_DRAW_AND_SWAP_FORCED: |
| 160 return "ACTION_DRAW_AND_SWAP_FORCED"; | 142 return "ACTION_DRAW_AND_SWAP_FORCED"; |
| 161 case ACTION_DRAW_AND_SWAP_ABORT: | 143 case ACTION_DRAW_AND_SWAP_ABORT: |
| 162 return "ACTION_DRAW_AND_SWAP_ABORT"; | 144 return "ACTION_DRAW_AND_SWAP_ABORT"; |
| 163 case ACTION_BEGIN_OUTPUT_SURFACE_CREATION: | 145 case ACTION_BEGIN_OUTPUT_SURFACE_CREATION: |
| 164 return "ACTION_BEGIN_OUTPUT_SURFACE_CREATION"; | 146 return "ACTION_BEGIN_OUTPUT_SURFACE_CREATION"; |
| 165 case ACTION_PREPARE_TILES: | 147 case ACTION_PREPARE_TILES: |
| 166 return "ACTION_PREPARE_TILES"; | 148 return "ACTION_PREPARE_TILES"; |
| 167 case ACTION_INVALIDATE_OUTPUT_SURFACE: | |
| 168 return "ACTION_INVALIDATE_OUTPUT_SURFACE"; | |
| 169 } | 149 } |
| 170 NOTREACHED(); | 150 NOTREACHED(); |
| 171 return "???"; | 151 return "???"; |
| 172 } | 152 } |
| 173 | 153 |
| 174 scoped_refptr<base::trace_event::ConvertableToTraceFormat> | 154 scoped_refptr<base::trace_event::ConvertableToTraceFormat> |
| 175 SchedulerStateMachine::AsValue() const { | 155 SchedulerStateMachine::AsValue() const { |
| 176 scoped_refptr<base::trace_event::TracedValue> state = | 156 scoped_refptr<base::trace_event::TracedValue> state = |
| 177 new base::trace_event::TracedValue(); | 157 new base::trace_event::TracedValue(); |
| 178 AsValueInto(state.get()); | 158 AsValueInto(state.get()); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 197 state->SetInteger("current_frame_number", current_frame_number_); | 177 state->SetInteger("current_frame_number", current_frame_number_); |
| 198 state->SetInteger("last_frame_number_animate_performed", | 178 state->SetInteger("last_frame_number_animate_performed", |
| 199 last_frame_number_animate_performed_); | 179 last_frame_number_animate_performed_); |
| 200 state->SetInteger("last_frame_number_swap_performed", | 180 state->SetInteger("last_frame_number_swap_performed", |
| 201 last_frame_number_swap_performed_); | 181 last_frame_number_swap_performed_); |
| 202 state->SetInteger("last_frame_number_swap_requested", | 182 state->SetInteger("last_frame_number_swap_requested", |
| 203 last_frame_number_swap_requested_); | 183 last_frame_number_swap_requested_); |
| 204 state->SetInteger("last_frame_number_begin_main_frame_sent", | 184 state->SetInteger("last_frame_number_begin_main_frame_sent", |
| 205 last_frame_number_begin_main_frame_sent_); | 185 last_frame_number_begin_main_frame_sent_); |
| 206 state->SetBoolean("funnel: animate_funnel", animate_funnel_); | 186 state->SetBoolean("funnel: animate_funnel", animate_funnel_); |
| 187 state->SetBoolean("funnel: perform_swap_funnel", perform_swap_funnel_); |
| 207 state->SetBoolean("funnel: request_swap_funnel", request_swap_funnel_); | 188 state->SetBoolean("funnel: request_swap_funnel", request_swap_funnel_); |
| 208 state->SetBoolean("funnel: send_begin_main_frame_funnel", | 189 state->SetBoolean("funnel: send_begin_main_frame_funnel", |
| 209 send_begin_main_frame_funnel_); | 190 send_begin_main_frame_funnel_); |
| 210 state->SetInteger("funnel: prepare_tiles_funnel", prepare_tiles_funnel_); | 191 state->SetInteger("funnel: prepare_tiles_funnel", prepare_tiles_funnel_); |
| 211 state->SetBoolean("funnel: invalidate_output_surface_funnel", | |
| 212 invalidate_output_surface_funnel_); | |
| 213 state->SetInteger("consecutive_checkerboard_animations", | 192 state->SetInteger("consecutive_checkerboard_animations", |
| 214 consecutive_checkerboard_animations_); | 193 consecutive_checkerboard_animations_); |
| 215 state->SetInteger("max_pending_swaps_", max_pending_swaps_); | 194 state->SetInteger("max_pending_swaps_", max_pending_swaps_); |
| 216 state->SetInteger("pending_swaps_", pending_swaps_); | 195 state->SetInteger("pending_swaps_", pending_swaps_); |
| 217 state->SetBoolean("needs_redraw", needs_redraw_); | 196 state->SetBoolean("needs_redraw", needs_redraw_); |
| 218 state->SetBoolean("needs_animate_", needs_animate_); | 197 state->SetBoolean("needs_animate_", needs_animate_); |
| 219 state->SetBoolean("needs_prepare_tiles", needs_prepare_tiles_); | 198 state->SetBoolean("needs_prepare_tiles", needs_prepare_tiles_); |
| 220 state->SetBoolean("needs_commit", needs_commit_); | 199 state->SetBoolean("needs_commit", needs_commit_); |
| 221 state->SetBoolean("visible", visible_); | 200 state->SetBoolean("visible", visible_); |
| 222 state->SetBoolean("can_start", can_start_); | 201 state->SetBoolean("can_start", can_start_); |
| 223 state->SetBoolean("can_draw", can_draw_); | 202 state->SetBoolean("can_draw", can_draw_); |
| 224 state->SetBoolean("has_pending_tree", has_pending_tree_); | 203 state->SetBoolean("has_pending_tree", has_pending_tree_); |
| 225 state->SetBoolean("pending_tree_is_ready_for_activation", | 204 state->SetBoolean("pending_tree_is_ready_for_activation", |
| 226 pending_tree_is_ready_for_activation_); | 205 pending_tree_is_ready_for_activation_); |
| 227 state->SetBoolean("active_tree_needs_first_draw", | 206 state->SetBoolean("active_tree_needs_first_draw", |
| 228 active_tree_needs_first_draw_); | 207 active_tree_needs_first_draw_); |
| 229 state->SetBoolean("did_create_and_initialize_first_output_surface", | 208 state->SetBoolean("did_create_and_initialize_first_output_surface", |
| 230 did_create_and_initialize_first_output_surface_); | 209 did_create_and_initialize_first_output_surface_); |
| 231 state->SetBoolean("impl_latency_takes_priority", | 210 state->SetBoolean("impl_latency_takes_priority", |
| 232 impl_latency_takes_priority_); | 211 impl_latency_takes_priority_); |
| 233 state->SetBoolean("main_thread_is_in_high_latency_mode", | 212 state->SetBoolean("main_thread_is_in_high_latency_mode", |
| 234 MainThreadIsInHighLatencyMode()); | 213 MainThreadIsInHighLatencyMode()); |
| 235 state->SetBoolean("skip_begin_main_frame_to_reduce_latency", | 214 state->SetBoolean("skip_begin_main_frame_to_reduce_latency", |
| 236 skip_begin_main_frame_to_reduce_latency_); | 215 skip_begin_main_frame_to_reduce_latency_); |
| 237 state->SetBoolean("skip_next_begin_main_frame_to_reduce_latency", | 216 state->SetBoolean("skip_next_begin_main_frame_to_reduce_latency", |
| 238 skip_next_begin_main_frame_to_reduce_latency_); | 217 skip_next_begin_main_frame_to_reduce_latency_); |
| 239 state->SetBoolean("continuous_painting", continuous_painting_); | 218 state->SetBoolean("continuous_painting", continuous_painting_); |
| 240 state->SetBoolean("children_need_begin_frames", children_need_begin_frames_); | 219 state->SetBoolean("children_need_begin_frames", children_need_begin_frames_); |
| 241 state->SetBoolean("defer_commits", defer_commits_); | 220 state->SetBoolean("defer_commits", defer_commits_); |
| 242 state->SetBoolean("last_commit_had_no_updates", last_commit_had_no_updates_); | |
| 243 state->SetBoolean("did_request_swap_in_last_frame", | |
| 244 did_request_swap_in_last_frame_); | |
| 245 state->SetBoolean("did_perform_swap_in_last_draw", | |
| 246 did_perform_swap_in_last_draw_); | |
| 247 state->EndDictionary(); | 221 state->EndDictionary(); |
| 248 } | 222 } |
| 249 | 223 |
| 224 void SchedulerStateMachine::AdvanceCurrentFrameNumber() { |
| 225 current_frame_number_++; |
| 226 |
| 227 animate_funnel_ = false; |
| 228 perform_swap_funnel_ = false; |
| 229 request_swap_funnel_ = false; |
| 230 send_begin_main_frame_funnel_ = false; |
| 231 |
| 232 // "Drain" the PrepareTiles funnel. |
| 233 if (prepare_tiles_funnel_ > 0) |
| 234 prepare_tiles_funnel_--; |
| 235 |
| 236 skip_begin_main_frame_to_reduce_latency_ = |
| 237 skip_next_begin_main_frame_to_reduce_latency_; |
| 238 skip_next_begin_main_frame_to_reduce_latency_ = false; |
| 239 } |
| 240 |
| 250 bool SchedulerStateMachine::PendingDrawsShouldBeAborted() const { | 241 bool SchedulerStateMachine::PendingDrawsShouldBeAborted() const { |
| 251 // These are all the cases where we normally cannot or do not want to draw | 242 // These are all the cases where we normally cannot or do not want to draw |
| 252 // but, if needs_redraw_ is true and we do not draw to make forward progress, | 243 // but, if needs_redraw_ is true and we do not draw to make forward progress, |
| 253 // we might deadlock with the main thread. | 244 // we might deadlock with the main thread. |
| 254 // This should be a superset of PendingActivationsShouldBeForced() since | 245 // This should be a superset of PendingActivationsShouldBeForced() since |
| 255 // activation of the pending tree is blocked by drawing of the active tree and | 246 // activation of the pending tree is blocked by drawing of the active tree and |
| 256 // the main thread might be blocked on activation of the most recent commit. | 247 // the main thread might be blocked on activation of the most recent commit. |
| 257 if (PendingActivationsShouldBeForced()) | 248 if (PendingActivationsShouldBeForced()) |
| 258 return true; | 249 return true; |
| 259 | 250 |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 429 return true; | 420 return true; |
| 430 | 421 |
| 431 // We shouldn't normally accept commits if there isn't an OutputSurface. | 422 // We shouldn't normally accept commits if there isn't an OutputSurface. |
| 432 if (!HasInitializedOutputSurface()) | 423 if (!HasInitializedOutputSurface()) |
| 433 return false; | 424 return false; |
| 434 | 425 |
| 435 // SwapAck throttle the BeginMainFrames unless we just swapped. | 426 // SwapAck throttle the BeginMainFrames unless we just swapped. |
| 436 // TODO(brianderson): Remove this restriction to improve throughput. | 427 // TODO(brianderson): Remove this restriction to improve throughput. |
| 437 bool just_swapped_in_deadline = | 428 bool just_swapped_in_deadline = |
| 438 begin_impl_frame_state_ == BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE && | 429 begin_impl_frame_state_ == BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE && |
| 439 did_perform_swap_in_last_draw_; | 430 perform_swap_funnel_; |
| 440 if (pending_swaps_ >= max_pending_swaps_ && !just_swapped_in_deadline) | 431 if (pending_swaps_ >= max_pending_swaps_ && !just_swapped_in_deadline) |
| 441 return false; | 432 return false; |
| 442 | 433 |
| 443 if (skip_begin_main_frame_to_reduce_latency_) | 434 if (skip_begin_main_frame_to_reduce_latency_) |
| 444 return false; | 435 return false; |
| 445 | 436 |
| 446 return true; | 437 return true; |
| 447 } | 438 } |
| 448 | 439 |
| 449 bool SchedulerStateMachine::ShouldCommit() const { | 440 bool SchedulerStateMachine::ShouldCommit() const { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 464 } | 455 } |
| 465 | 456 |
| 466 bool SchedulerStateMachine::ShouldPrepareTiles() const { | 457 bool SchedulerStateMachine::ShouldPrepareTiles() const { |
| 467 // PrepareTiles only really needs to be called immediately after commit | 458 // PrepareTiles only really needs to be called immediately after commit |
| 468 // and then periodically after that. Use a funnel to make sure we average | 459 // and then periodically after that. Use a funnel to make sure we average |
| 469 // one PrepareTiles per BeginImplFrame in the long run. | 460 // one PrepareTiles per BeginImplFrame in the long run. |
| 470 if (prepare_tiles_funnel_ > 0) | 461 if (prepare_tiles_funnel_ > 0) |
| 471 return false; | 462 return false; |
| 472 | 463 |
| 473 // Limiting to once per-frame is not enough, since we only want to | 464 // Limiting to once per-frame is not enough, since we only want to |
| 474 // prepare tiles _after_ draws. | 465 // prepare tiles _after_ draws. Polling for draw triggers and |
| 475 if (begin_impl_frame_state_ != BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE) | 466 // begin-frame are mutually exclusive, so we limit to these two cases. |
| 467 if (begin_impl_frame_state_ != BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE && |
| 468 !inside_poll_for_anticipated_draw_triggers_) |
| 476 return false; | 469 return false; |
| 477 | |
| 478 return needs_prepare_tiles_; | 470 return needs_prepare_tiles_; |
| 479 } | 471 } |
| 480 | 472 |
| 481 bool SchedulerStateMachine::ShouldInvalidateOutputSurface() const { | |
| 482 // Do not invalidate too many times in a frame. | |
| 483 if (invalidate_output_surface_funnel_) | |
| 484 return false; | |
| 485 | |
| 486 // Only the synchronous compositor requires invalidations. | |
| 487 if (!settings_.using_synchronous_renderer_compositor) | |
| 488 return false; | |
| 489 | |
| 490 // Invalidations are only performed inside a BeginFrame. | |
| 491 if (begin_impl_frame_state_ != BEGIN_IMPL_FRAME_STATE_BEGIN_FRAME_STARTING) | |
| 492 return false; | |
| 493 | |
| 494 // TODO(sunnyps): needs_prepare_tiles_ is needed here because PrepareTiles is | |
| 495 // called only inside the deadline / draw phase. We could remove this if we | |
| 496 // allowed PrepareTiles to happen in OnBeginImplFrame. | |
| 497 return needs_redraw_ || needs_prepare_tiles_; | |
| 498 } | |
| 499 | |
| 500 SchedulerStateMachine::Action SchedulerStateMachine::NextAction() const { | 473 SchedulerStateMachine::Action SchedulerStateMachine::NextAction() const { |
| 501 if (ShouldActivatePendingTree()) | 474 if (ShouldActivatePendingTree()) |
| 502 return ACTION_ACTIVATE_SYNC_TREE; | 475 return ACTION_ACTIVATE_SYNC_TREE; |
| 503 if (ShouldCommit()) | 476 if (ShouldCommit()) |
| 504 return ACTION_COMMIT; | 477 return ACTION_COMMIT; |
| 505 if (ShouldAnimate()) | 478 if (ShouldAnimate()) |
| 506 return ACTION_ANIMATE; | 479 return ACTION_ANIMATE; |
| 507 if (ShouldDraw()) { | 480 if (ShouldDraw()) { |
| 508 if (PendingDrawsShouldBeAborted()) | 481 if (PendingDrawsShouldBeAborted()) |
| 509 return ACTION_DRAW_AND_SWAP_ABORT; | 482 return ACTION_DRAW_AND_SWAP_ABORT; |
| 510 else if (forced_redraw_state_ == FORCED_REDRAW_STATE_WAITING_FOR_DRAW) | 483 else if (forced_redraw_state_ == FORCED_REDRAW_STATE_WAITING_FOR_DRAW) |
| 511 return ACTION_DRAW_AND_SWAP_FORCED; | 484 return ACTION_DRAW_AND_SWAP_FORCED; |
| 512 else | 485 else |
| 513 return ACTION_DRAW_AND_SWAP_IF_POSSIBLE; | 486 return ACTION_DRAW_AND_SWAP_IF_POSSIBLE; |
| 514 } | 487 } |
| 515 if (ShouldPrepareTiles()) | 488 if (ShouldPrepareTiles()) |
| 516 return ACTION_PREPARE_TILES; | 489 return ACTION_PREPARE_TILES; |
| 517 if (ShouldSendBeginMainFrame()) | 490 if (ShouldSendBeginMainFrame()) |
| 518 return ACTION_SEND_BEGIN_MAIN_FRAME; | 491 return ACTION_SEND_BEGIN_MAIN_FRAME; |
| 519 if (ShouldInvalidateOutputSurface()) | |
| 520 return ACTION_INVALIDATE_OUTPUT_SURFACE; | |
| 521 if (ShouldBeginOutputSurfaceCreation()) | 492 if (ShouldBeginOutputSurfaceCreation()) |
| 522 return ACTION_BEGIN_OUTPUT_SURFACE_CREATION; | 493 return ACTION_BEGIN_OUTPUT_SURFACE_CREATION; |
| 523 return ACTION_NONE; | 494 return ACTION_NONE; |
| 524 } | 495 } |
| 525 | 496 |
| 526 void SchedulerStateMachine::UpdateState(Action action) { | 497 void SchedulerStateMachine::UpdateState(Action action) { |
| 527 switch (action) { | 498 switch (action) { |
| 528 case ACTION_NONE: | 499 case ACTION_NONE: |
| 529 return; | 500 return; |
| 530 | 501 |
| 531 case ACTION_ACTIVATE_SYNC_TREE: | 502 case ACTION_ACTIVATE_SYNC_TREE: |
| 532 UpdateStateOnActivation(); | 503 UpdateStateOnActivation(); |
| 533 return; | 504 return; |
| 534 | 505 |
| 535 case ACTION_ANIMATE: | 506 case ACTION_ANIMATE: |
| 536 UpdateStateOnAnimate(); | 507 DCHECK(!animate_funnel_); |
| 508 last_frame_number_animate_performed_ = current_frame_number_; |
| 509 animate_funnel_ = true; |
| 510 needs_animate_ = false; |
| 511 // TODO(skyostil): Instead of assuming this, require the client to tell |
| 512 // us. |
| 513 SetNeedsRedraw(); |
| 537 return; | 514 return; |
| 538 | 515 |
| 539 case ACTION_SEND_BEGIN_MAIN_FRAME: | 516 case ACTION_SEND_BEGIN_MAIN_FRAME: |
| 540 UpdateStateOnSendBeginMainFrame(); | 517 DCHECK(!has_pending_tree_ || |
| 518 settings_.main_frame_before_activation_enabled); |
| 519 DCHECK(visible_); |
| 520 DCHECK(!send_begin_main_frame_funnel_); |
| 521 commit_state_ = COMMIT_STATE_BEGIN_MAIN_FRAME_SENT; |
| 522 needs_commit_ = false; |
| 523 send_begin_main_frame_funnel_ = true; |
| 524 last_frame_number_begin_main_frame_sent_ = |
| 525 current_frame_number_; |
| 541 return; | 526 return; |
| 542 | 527 |
| 543 case ACTION_COMMIT: { | 528 case ACTION_COMMIT: { |
| 544 bool commit_has_no_updates = false; | 529 bool commit_has_no_updates = false; |
| 545 UpdateStateOnCommit(commit_has_no_updates); | 530 UpdateStateOnCommit(commit_has_no_updates); |
| 546 return; | 531 return; |
| 547 } | 532 } |
| 548 | 533 |
| 549 case ACTION_DRAW_AND_SWAP_FORCED: | 534 case ACTION_DRAW_AND_SWAP_FORCED: |
| 550 case ACTION_DRAW_AND_SWAP_IF_POSSIBLE: { | 535 case ACTION_DRAW_AND_SWAP_IF_POSSIBLE: { |
| 551 bool did_request_swap = true; | 536 bool did_request_swap = true; |
| 552 UpdateStateOnDraw(did_request_swap); | 537 UpdateStateOnDraw(did_request_swap); |
| 553 return; | 538 return; |
| 554 } | 539 } |
| 555 | 540 |
| 556 case ACTION_DRAW_AND_SWAP_ABORT: { | 541 case ACTION_DRAW_AND_SWAP_ABORT: { |
| 557 bool did_request_swap = false; | 542 bool did_request_swap = false; |
| 558 UpdateStateOnDraw(did_request_swap); | 543 UpdateStateOnDraw(did_request_swap); |
| 559 return; | 544 return; |
| 560 } | 545 } |
| 561 | 546 |
| 562 case ACTION_BEGIN_OUTPUT_SURFACE_CREATION: | 547 case ACTION_BEGIN_OUTPUT_SURFACE_CREATION: |
| 563 UpdateStateOnBeginOutputSurfaceCreation(); | 548 DCHECK_EQ(output_surface_state_, OUTPUT_SURFACE_LOST); |
| 549 output_surface_state_ = OUTPUT_SURFACE_CREATING; |
| 550 |
| 551 // The following DCHECKs make sure we are in the proper quiescent state. |
| 552 // The pipeline should be flushed entirely before we start output |
| 553 // surface creation to avoid complicated corner cases. |
| 554 DCHECK_EQ(commit_state_, COMMIT_STATE_IDLE); |
| 555 DCHECK(!has_pending_tree_); |
| 556 DCHECK(!active_tree_needs_first_draw_); |
| 564 return; | 557 return; |
| 565 | 558 |
| 566 case ACTION_PREPARE_TILES: | 559 case ACTION_PREPARE_TILES: |
| 567 UpdateStateOnPrepareTiles(); | 560 UpdateStateOnPrepareTiles(); |
| 568 return; | 561 return; |
| 569 | |
| 570 case ACTION_INVALIDATE_OUTPUT_SURFACE: | |
| 571 UpdateStateOnInvalidateOutputSurface(); | |
| 572 return; | |
| 573 } | 562 } |
| 574 } | 563 } |
| 575 | 564 |
| 576 void SchedulerStateMachine::UpdateStateOnAnimate() { | |
| 577 DCHECK(!animate_funnel_); | |
| 578 last_frame_number_animate_performed_ = current_frame_number_; | |
| 579 animate_funnel_ = true; | |
| 580 needs_animate_ = false; | |
| 581 // TODO(skyostil): Instead of assuming this, require the client to tell us. | |
| 582 SetNeedsRedraw(); | |
| 583 } | |
| 584 | |
| 585 void SchedulerStateMachine::UpdateStateOnSendBeginMainFrame() { | |
| 586 DCHECK(!has_pending_tree_ || settings_.main_frame_before_activation_enabled); | |
| 587 DCHECK(visible_); | |
| 588 DCHECK(!send_begin_main_frame_funnel_); | |
| 589 commit_state_ = COMMIT_STATE_BEGIN_MAIN_FRAME_SENT; | |
| 590 needs_commit_ = false; | |
| 591 send_begin_main_frame_funnel_ = true; | |
| 592 last_frame_number_begin_main_frame_sent_ = current_frame_number_; | |
| 593 } | |
| 594 | |
| 595 void SchedulerStateMachine::UpdateStateOnCommit(bool commit_has_no_updates) { | 565 void SchedulerStateMachine::UpdateStateOnCommit(bool commit_has_no_updates) { |
| 596 commit_count_++; | 566 commit_count_++; |
| 597 | 567 |
| 598 // Animate after commit even if we've already animated. | |
| 599 if (!commit_has_no_updates) | 568 if (!commit_has_no_updates) |
| 600 animate_funnel_ = false; | 569 animate_funnel_ = false; |
| 601 | 570 |
| 602 if (commit_has_no_updates || settings_.main_frame_before_activation_enabled) { | 571 if (commit_has_no_updates || settings_.main_frame_before_activation_enabled) { |
| 603 commit_state_ = COMMIT_STATE_IDLE; | 572 commit_state_ = COMMIT_STATE_IDLE; |
| 604 } else if (settings_.impl_side_painting) { | 573 } else if (settings_.impl_side_painting) { |
| 605 commit_state_ = COMMIT_STATE_WAITING_FOR_ACTIVATION; | 574 commit_state_ = COMMIT_STATE_WAITING_FOR_ACTIVATION; |
| 606 } else { | 575 } else { |
| 607 commit_state_ = settings_.main_thread_should_always_be_low_latency | 576 commit_state_ = settings_.main_thread_should_always_be_low_latency |
| 608 ? COMMIT_STATE_WAITING_FOR_DRAW | 577 ? COMMIT_STATE_WAITING_FOR_DRAW |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 673 | 642 |
| 674 if (commit_state_ == COMMIT_STATE_WAITING_FOR_DRAW) | 643 if (commit_state_ == COMMIT_STATE_WAITING_FOR_DRAW) |
| 675 commit_state_ = COMMIT_STATE_IDLE; | 644 commit_state_ = COMMIT_STATE_IDLE; |
| 676 | 645 |
| 677 needs_redraw_ = false; | 646 needs_redraw_ = false; |
| 678 active_tree_needs_first_draw_ = false; | 647 active_tree_needs_first_draw_ = false; |
| 679 | 648 |
| 680 if (did_request_swap) { | 649 if (did_request_swap) { |
| 681 DCHECK(!request_swap_funnel_); | 650 DCHECK(!request_swap_funnel_); |
| 682 request_swap_funnel_ = true; | 651 request_swap_funnel_ = true; |
| 683 did_request_swap_in_last_frame_ = true; | |
| 684 last_frame_number_swap_requested_ = current_frame_number_; | 652 last_frame_number_swap_requested_ = current_frame_number_; |
| 685 } | 653 } |
| 686 } | 654 } |
| 687 | 655 |
| 688 void SchedulerStateMachine::UpdateStateOnPrepareTiles() { | 656 void SchedulerStateMachine::UpdateStateOnPrepareTiles() { |
| 689 needs_prepare_tiles_ = false; | 657 needs_prepare_tiles_ = false; |
| 690 } | 658 } |
| 691 | 659 |
| 692 void SchedulerStateMachine::UpdateStateOnBeginOutputSurfaceCreation() { | |
| 693 DCHECK_EQ(output_surface_state_, OUTPUT_SURFACE_LOST); | |
| 694 output_surface_state_ = OUTPUT_SURFACE_CREATING; | |
| 695 | |
| 696 // The following DCHECKs make sure we are in the proper quiescent state. | |
| 697 // The pipeline should be flushed entirely before we start output | |
| 698 // surface creation to avoid complicated corner cases. | |
| 699 DCHECK_EQ(commit_state_, COMMIT_STATE_IDLE); | |
| 700 DCHECK(!has_pending_tree_); | |
| 701 DCHECK(!active_tree_needs_first_draw_); | |
| 702 } | |
| 703 | |
| 704 void SchedulerStateMachine::UpdateStateOnInvalidateOutputSurface() { | |
| 705 DCHECK(!invalidate_output_surface_funnel_); | |
| 706 invalidate_output_surface_funnel_ = true; | |
| 707 last_frame_number_invalidate_output_surface_performed_ = | |
| 708 current_frame_number_; | |
| 709 } | |
| 710 | |
| 711 void SchedulerStateMachine::SetSkipNextBeginMainFrameToReduceLatency() { | 660 void SchedulerStateMachine::SetSkipNextBeginMainFrameToReduceLatency() { |
| 712 TRACE_EVENT_INSTANT0("cc", | 661 TRACE_EVENT_INSTANT0("cc", |
| 713 "Scheduler: SkipNextBeginMainFrameToReduceLatency", | 662 "Scheduler: SkipNextBeginMainFrameToReduceLatency", |
| 714 TRACE_EVENT_SCOPE_THREAD); | 663 TRACE_EVENT_SCOPE_THREAD); |
| 715 skip_next_begin_main_frame_to_reduce_latency_ = true; | 664 skip_next_begin_main_frame_to_reduce_latency_ = true; |
| 716 } | 665 } |
| 717 | 666 |
| 718 bool SchedulerStateMachine::BeginFrameNeededForChildren() const { | 667 bool SchedulerStateMachine::BeginFrameNeededForChildren() const { |
| 719 return children_need_begin_frames_; | 668 if (HasInitializedOutputSurface()) |
| 669 return children_need_begin_frames_; |
| 670 |
| 671 return false; |
| 720 } | 672 } |
| 721 | 673 |
| 722 bool SchedulerStateMachine::BeginFrameNeeded() const { | 674 bool SchedulerStateMachine::BeginFrameNeeded() const { |
| 723 // We can't handle BeginFrames when output surface isn't initialized. | 675 // We can't handle BeginFrames when output surface isn't initialized. |
| 724 // TODO(brianderson): Support output surface creation inside a BeginFrame. | 676 // TODO(brianderson): Support output surface creation inside a BeginFrame. |
| 725 if (!HasInitializedOutputSurface()) | 677 if (!HasInitializedOutputSurface()) |
| 726 return false; | 678 return false; |
| 727 return (BeginFrameNeededToAnimateOrDraw() || BeginFrameNeededForChildren() || | 679 |
| 728 ProactiveBeginFrameWanted()); | 680 if (SupportsProactiveBeginFrame()) { |
| 681 return (BeginFrameNeededToAnimateOrDraw() || |
| 682 BeginFrameNeededForChildren() || |
| 683 ProactiveBeginFrameWanted()); |
| 684 } |
| 685 |
| 686 // Proactive BeginFrames are bad for the synchronous compositor because we |
| 687 // have to draw when we get the BeginFrame and could end up drawing many |
| 688 // duplicate frames if our new frame isn't ready in time. |
| 689 // To poll for state with the synchronous compositor without having to draw, |
| 690 // we rely on ShouldPollForAnticipatedDrawTriggers instead. |
| 691 // Synchronous compositor doesn't have a browser. |
| 692 DCHECK(!children_need_begin_frames_); |
| 693 return BeginFrameNeededToAnimateOrDraw(); |
| 694 } |
| 695 |
| 696 bool SchedulerStateMachine::ShouldPollForAnticipatedDrawTriggers() const { |
| 697 // ShouldPollForAnticipatedDrawTriggers is what we use in place of |
| 698 // ProactiveBeginFrameWanted when we are using the synchronous |
| 699 // compositor. |
| 700 if (!SupportsProactiveBeginFrame()) { |
| 701 return !BeginFrameNeededToAnimateOrDraw() && ProactiveBeginFrameWanted(); |
| 702 } |
| 703 |
| 704 // Non synchronous compositors should rely on |
| 705 // ProactiveBeginFrameWanted to poll for state instead. |
| 706 return false; |
| 707 } |
| 708 |
| 709 // Note: If SupportsProactiveBeginFrame is false, the scheduler should poll |
| 710 // for changes in it's draw state so it can request a BeginFrame when it's |
| 711 // actually ready. |
| 712 bool SchedulerStateMachine::SupportsProactiveBeginFrame() const { |
| 713 // It is undesirable to proactively request BeginFrames if we are |
| 714 // using a synchronous compositor because we *must* draw for every |
| 715 // BeginFrame, which could cause duplicate draws. |
| 716 return !settings_.using_synchronous_renderer_compositor; |
| 729 } | 717 } |
| 730 | 718 |
| 731 void SchedulerStateMachine::SetChildrenNeedBeginFrames( | 719 void SchedulerStateMachine::SetChildrenNeedBeginFrames( |
| 732 bool children_need_begin_frames) { | 720 bool children_need_begin_frames) { |
| 733 children_need_begin_frames_ = children_need_begin_frames; | 721 children_need_begin_frames_ = children_need_begin_frames; |
| 734 } | 722 } |
| 735 | 723 |
| 736 void SchedulerStateMachine::SetDeferCommits(bool defer_commits) { | 724 void SchedulerStateMachine::SetDeferCommits(bool defer_commits) { |
| 737 defer_commits_ = defer_commits; | 725 defer_commits_ = defer_commits; |
| 738 } | 726 } |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 773 // Changing priorities may allow us to activate (given the new priorities), | 761 // Changing priorities may allow us to activate (given the new priorities), |
| 774 // which may result in a new frame. | 762 // which may result in a new frame. |
| 775 if (needs_prepare_tiles_) | 763 if (needs_prepare_tiles_) |
| 776 return true; | 764 return true; |
| 777 | 765 |
| 778 // If we just sent a swap request, it's likely that we are going to produce | 766 // If we just sent a swap request, it's likely that we are going to produce |
| 779 // another frame soon. This helps avoid negative glitches in our | 767 // another frame soon. This helps avoid negative glitches in our |
| 780 // SetNeedsBeginFrame requests, which may propagate to the BeginImplFrame | 768 // SetNeedsBeginFrame requests, which may propagate to the BeginImplFrame |
| 781 // provider and get sampled at an inopportune time, delaying the next | 769 // provider and get sampled at an inopportune time, delaying the next |
| 782 // BeginImplFrame. | 770 // BeginImplFrame. |
| 783 if (did_request_swap_in_last_frame_) | 771 if (request_swap_funnel_) |
| 784 return true; | 772 return true; |
| 785 | 773 |
| 786 // If the last commit was aborted because of early out (no updates), we should | 774 // If the last commit was aborted because of early out (no updates), we should |
| 787 // still want a begin frame in case there is a commit coming again. | 775 // still want a begin frame in case there is a commit coming again. |
| 788 if (last_commit_had_no_updates_) | 776 if (last_commit_had_no_updates_) |
| 789 return true; | 777 return true; |
| 790 | 778 |
| 791 return false; | 779 return false; |
| 792 } | 780 } |
| 793 | 781 |
| 794 void SchedulerStateMachine::OnBeginImplFrame() { | 782 void SchedulerStateMachine::OnBeginImplFrame() { |
| 783 AdvanceCurrentFrameNumber(); |
| 784 DCHECK_EQ(begin_impl_frame_state_, BEGIN_IMPL_FRAME_STATE_IDLE) |
| 785 << AsValue()->ToString(); |
| 795 begin_impl_frame_state_ = BEGIN_IMPL_FRAME_STATE_BEGIN_FRAME_STARTING; | 786 begin_impl_frame_state_ = BEGIN_IMPL_FRAME_STATE_BEGIN_FRAME_STARTING; |
| 796 current_frame_number_++; | |
| 797 | |
| 798 last_commit_had_no_updates_ = false; | 787 last_commit_had_no_updates_ = false; |
| 799 did_request_swap_in_last_frame_ = false; | |
| 800 | |
| 801 // Clear funnels for any actions we perform during the frame. | |
| 802 animate_funnel_ = false; | |
| 803 send_begin_main_frame_funnel_ = false; | |
| 804 invalidate_output_surface_funnel_ = false; | |
| 805 | |
| 806 // "Drain" the PrepareTiles funnel. | |
| 807 if (prepare_tiles_funnel_ > 0) | |
| 808 prepare_tiles_funnel_--; | |
| 809 | |
| 810 skip_begin_main_frame_to_reduce_latency_ = | |
| 811 skip_next_begin_main_frame_to_reduce_latency_; | |
| 812 skip_next_begin_main_frame_to_reduce_latency_ = false; | |
| 813 } | 788 } |
| 814 | 789 |
| 815 void SchedulerStateMachine::OnBeginImplFrameDeadlinePending() { | 790 void SchedulerStateMachine::OnBeginImplFrameDeadlinePending() { |
| 791 DCHECK_EQ(begin_impl_frame_state_, |
| 792 BEGIN_IMPL_FRAME_STATE_BEGIN_FRAME_STARTING) |
| 793 << AsValue()->ToString(); |
| 816 begin_impl_frame_state_ = BEGIN_IMPL_FRAME_STATE_INSIDE_BEGIN_FRAME; | 794 begin_impl_frame_state_ = BEGIN_IMPL_FRAME_STATE_INSIDE_BEGIN_FRAME; |
| 817 } | 795 } |
| 818 | 796 |
| 819 void SchedulerStateMachine::OnBeginImplFrameDeadline() { | 797 void SchedulerStateMachine::OnBeginImplFrameDeadline() { |
| 798 DCHECK_EQ(begin_impl_frame_state_, BEGIN_IMPL_FRAME_STATE_INSIDE_BEGIN_FRAME) |
| 799 << AsValue()->ToString(); |
| 820 begin_impl_frame_state_ = BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE; | 800 begin_impl_frame_state_ = BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE; |
| 821 | |
| 822 did_perform_swap_in_last_draw_ = false; | |
| 823 | |
| 824 // Clear funnels for any actions we perform during the deadline. | |
| 825 request_swap_funnel_ = false; | |
| 826 } | 801 } |
| 827 | 802 |
| 828 void SchedulerStateMachine::OnBeginImplFrameIdle() { | 803 void SchedulerStateMachine::OnBeginImplFrameIdle() { |
| 804 DCHECK_EQ(begin_impl_frame_state_, BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE) |
| 805 << AsValue()->ToString(); |
| 829 begin_impl_frame_state_ = BEGIN_IMPL_FRAME_STATE_IDLE; | 806 begin_impl_frame_state_ = BEGIN_IMPL_FRAME_STATE_IDLE; |
| 830 } | 807 } |
| 831 | 808 |
| 832 SchedulerStateMachine::BeginImplFrameDeadlineMode | 809 SchedulerStateMachine::BeginImplFrameDeadlineMode |
| 833 SchedulerStateMachine::CurrentBeginImplFrameDeadlineMode() const { | 810 SchedulerStateMachine::CurrentBeginImplFrameDeadlineMode() const { |
| 834 if (settings_.using_synchronous_renderer_compositor) { | 811 if (ShouldTriggerBeginImplFrameDeadlineImmediately()) { |
| 835 // No deadline for synchronous compositor. | |
| 836 return BEGIN_IMPL_FRAME_DEADLINE_MODE_NONE; | |
| 837 } else if (ShouldTriggerBeginImplFrameDeadlineImmediately()) { | |
| 838 return BEGIN_IMPL_FRAME_DEADLINE_MODE_IMMEDIATE; | 812 return BEGIN_IMPL_FRAME_DEADLINE_MODE_IMMEDIATE; |
| 839 } else if (needs_redraw_ && pending_swaps_ < max_pending_swaps_) { | 813 } else if (needs_redraw_ && pending_swaps_ < max_pending_swaps_) { |
| 840 // We have an animation or fast input path on the impl thread that wants | 814 // We have an animation or fast input path on the impl thread that wants |
| 841 // to draw, so don't wait too long for a new active tree. | 815 // to draw, so don't wait too long for a new active tree. |
| 842 // If we are swap throttled we should wait until we are unblocked. | 816 // If we are swap throttled we should wait until we are unblocked. |
| 843 return BEGIN_IMPL_FRAME_DEADLINE_MODE_REGULAR; | 817 return BEGIN_IMPL_FRAME_DEADLINE_MODE_REGULAR; |
| 844 } else { | 818 } else { |
| 845 // The impl thread doesn't have anything it wants to draw and we are just | 819 // The impl thread doesn't have anything it wants to draw and we are just |
| 846 // waiting for a new active tree or we are swap throttled. In short we are | 820 // waiting for a new active tree or we are swap throttled. In short we are |
| 847 // blocked. | 821 // blocked. |
| 848 return BEGIN_IMPL_FRAME_DEADLINE_MODE_LATE; | 822 return BEGIN_IMPL_FRAME_DEADLINE_MODE_LATE; |
| 849 } | 823 } |
| 850 } | 824 } |
| 851 | 825 |
| 852 bool SchedulerStateMachine::ShouldTriggerBeginImplFrameDeadlineImmediately() | 826 bool SchedulerStateMachine::ShouldTriggerBeginImplFrameDeadlineImmediately() |
| 853 const { | 827 const { |
| 854 // TODO(brianderson): This should take into account multiple commit sources. | 828 // TODO(brianderson): This should take into account multiple commit sources. |
| 829 |
| 855 if (begin_impl_frame_state_ != BEGIN_IMPL_FRAME_STATE_INSIDE_BEGIN_FRAME) | 830 if (begin_impl_frame_state_ != BEGIN_IMPL_FRAME_STATE_INSIDE_BEGIN_FRAME) |
| 856 return false; | 831 return false; |
| 857 | 832 |
| 858 // If we've lost the output surface, end the current BeginImplFrame ASAP | 833 // If we've lost the output surface, end the current BeginImplFrame ASAP |
| 859 // so we can start creating the next output surface. | 834 // so we can start creating the next output surface. |
| 860 if (output_surface_state_ == OUTPUT_SURFACE_LOST) | 835 if (output_surface_state_ == OUTPUT_SURFACE_LOST) |
| 861 return true; | 836 return true; |
| 862 | 837 |
| 863 // SwapAck throttle the deadline since we wont draw and swap anyway. | 838 // SwapAck throttle the deadline since we wont draw and swap anyway. |
| 864 if (pending_swaps_ >= max_pending_swaps_) | 839 if (pending_swaps_ >= max_pending_swaps_) |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 910 // or | 885 // or |
| 911 // we're currently drawing the active tree and the pending tree will thus | 886 // we're currently drawing the active tree and the pending tree will thus |
| 912 // only be drawn in the next frame. | 887 // only be drawn in the next frame. |
| 913 if (has_pending_tree_) | 888 if (has_pending_tree_) |
| 914 return true; | 889 return true; |
| 915 | 890 |
| 916 if (begin_impl_frame_state_ == BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE) { | 891 if (begin_impl_frame_state_ == BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE) { |
| 917 // Even if there's a new active tree to draw at the deadline or we've just | 892 // Even if there's a new active tree to draw at the deadline or we've just |
| 918 // swapped it, it may have been triggered by a previous BeginImplFrame, in | 893 // swapped it, it may have been triggered by a previous BeginImplFrame, in |
| 919 // which case the main thread is in a high latency mode. | 894 // which case the main thread is in a high latency mode. |
| 920 return (active_tree_needs_first_draw_ || did_perform_swap_in_last_draw_) && | 895 return (active_tree_needs_first_draw_ || perform_swap_funnel_) && |
| 921 !send_begin_main_frame_funnel_; | 896 !send_begin_main_frame_funnel_; |
| 922 } | 897 } |
| 923 | 898 |
| 924 // If the active tree needs its first draw in any other state, we know the | 899 // If the active tree needs its first draw in any other state, we know the |
| 925 // main thread is in a high latency mode. | 900 // main thread is in a high latency mode. |
| 926 return active_tree_needs_first_draw_; | 901 return active_tree_needs_first_draw_; |
| 927 } | 902 } |
| 928 | 903 |
| 904 void SchedulerStateMachine::DidEnterPollForAnticipatedDrawTriggers() { |
| 905 AdvanceCurrentFrameNumber(); |
| 906 inside_poll_for_anticipated_draw_triggers_ = true; |
| 907 } |
| 908 |
| 909 void SchedulerStateMachine::DidLeavePollForAnticipatedDrawTriggers() { |
| 910 inside_poll_for_anticipated_draw_triggers_ = false; |
| 911 } |
| 912 |
| 929 void SchedulerStateMachine::SetVisible(bool visible) { visible_ = visible; } | 913 void SchedulerStateMachine::SetVisible(bool visible) { visible_ = visible; } |
| 930 | 914 |
| 931 void SchedulerStateMachine::SetCanDraw(bool can_draw) { can_draw_ = can_draw; } | 915 void SchedulerStateMachine::SetCanDraw(bool can_draw) { can_draw_ = can_draw; } |
| 932 | 916 |
| 933 void SchedulerStateMachine::SetNeedsRedraw() { needs_redraw_ = true; } | 917 void SchedulerStateMachine::SetNeedsRedraw() { needs_redraw_ = true; } |
| 934 | 918 |
| 935 void SchedulerStateMachine::SetNeedsAnimate() { | 919 void SchedulerStateMachine::SetNeedsAnimate() { |
| 936 needs_animate_ = true; | 920 needs_animate_ = true; |
| 937 } | 921 } |
| 938 | 922 |
| 939 void SchedulerStateMachine::SetNeedsPrepareTiles() { | 923 void SchedulerStateMachine::SetNeedsPrepareTiles() { |
| 940 if (!needs_prepare_tiles_) { | 924 if (!needs_prepare_tiles_) { |
| 941 TRACE_EVENT0("cc", "SchedulerStateMachine::SetNeedsPrepareTiles"); | 925 TRACE_EVENT0("cc", "SchedulerStateMachine::SetNeedsPrepareTiles"); |
| 942 needs_prepare_tiles_ = true; | 926 needs_prepare_tiles_ = true; |
| 943 } | 927 } |
| 944 } | 928 } |
| 945 | 929 |
| 946 void SchedulerStateMachine::SetMaxSwapsPending(int max) { | 930 void SchedulerStateMachine::SetMaxSwapsPending(int max) { |
| 947 max_pending_swaps_ = max; | 931 max_pending_swaps_ = max; |
| 948 } | 932 } |
| 949 | 933 |
| 950 void SchedulerStateMachine::DidSwapBuffers() { | 934 void SchedulerStateMachine::DidSwapBuffers() { |
| 951 pending_swaps_++; | 935 pending_swaps_++; |
| 952 DCHECK_LE(pending_swaps_, max_pending_swaps_); | 936 DCHECK_LE(pending_swaps_, max_pending_swaps_); |
| 937 DCHECK(!perform_swap_funnel_); |
| 953 | 938 |
| 954 did_perform_swap_in_last_draw_ = true; | 939 perform_swap_funnel_ = true; |
| 955 last_frame_number_swap_performed_ = current_frame_number_; | 940 last_frame_number_swap_performed_ = current_frame_number_; |
| 956 } | 941 } |
| 957 | 942 |
| 958 void SchedulerStateMachine::DidSwapBuffersComplete() { | 943 void SchedulerStateMachine::DidSwapBuffersComplete() { |
| 959 DCHECK_GT(pending_swaps_, 0); | 944 DCHECK_GT(pending_swaps_, 0); |
| 960 pending_swaps_--; | 945 pending_swaps_--; |
| 961 } | 946 } |
| 962 | 947 |
| 963 void SchedulerStateMachine::SetImplLatencyTakesPriority( | 948 void SchedulerStateMachine::SetImplLatencyTakesPriority( |
| 964 bool impl_latency_takes_priority) { | 949 bool impl_latency_takes_priority) { |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1098 static_cast<int>(begin_impl_frame_state_), | 1083 static_cast<int>(begin_impl_frame_state_), |
| 1099 static_cast<int>(commit_state_), | 1084 static_cast<int>(commit_state_), |
| 1100 has_pending_tree_ ? 'T' : 'F', | 1085 has_pending_tree_ ? 'T' : 'F', |
| 1101 pending_tree_is_ready_for_activation_ ? 'T' : 'F', | 1086 pending_tree_is_ready_for_activation_ ? 'T' : 'F', |
| 1102 active_tree_needs_first_draw_ ? 'T' : 'F', | 1087 active_tree_needs_first_draw_ ? 'T' : 'F', |
| 1103 max_pending_swaps_, | 1088 max_pending_swaps_, |
| 1104 pending_swaps_); | 1089 pending_swaps_); |
| 1105 } | 1090 } |
| 1106 | 1091 |
| 1107 } // namespace cc | 1092 } // namespace cc |
| OLD | NEW |