Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(80)

Side by Side Diff: cc/scheduler/scheduler_state_machine.cc

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

Powered by Google App Engine
This is Rietveld 408576698