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