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

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: Rebase Created 5 years, 9 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
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 perform_swap_funnel_(false),
31 request_swap_funnel_(false), 32 request_swap_funnel_(false),
32 send_begin_main_frame_funnel_(false), 33 send_begin_main_frame_funnel_(false),
34 invalidate_output_surface_funnel_(false),
33 prepare_tiles_funnel_(0), 35 prepare_tiles_funnel_(0),
34 consecutive_checkerboard_animations_(0), 36 consecutive_checkerboard_animations_(0),
35 max_pending_swaps_(1), 37 max_pending_swaps_(1),
36 pending_swaps_(0), 38 pending_swaps_(0),
37 needs_redraw_(false), 39 needs_redraw_(false),
38 needs_animate_(false), 40 needs_animate_(false),
39 needs_prepare_tiles_(false), 41 needs_prepare_tiles_(false),
40 needs_commit_(false), 42 needs_commit_(false),
41 inside_poll_for_anticipated_draw_triggers_(false),
42 visible_(false), 43 visible_(false),
43 can_start_(false), 44 can_start_(false),
44 can_draw_(false), 45 can_draw_(false),
45 has_pending_tree_(false), 46 has_pending_tree_(false),
46 pending_tree_is_ready_for_activation_(false), 47 pending_tree_is_ready_for_activation_(false),
47 active_tree_needs_first_draw_(false), 48 active_tree_needs_first_draw_(false),
48 did_create_and_initialize_first_output_surface_(false), 49 did_create_and_initialize_first_output_surface_(false),
49 impl_latency_takes_priority_(false), 50 impl_latency_takes_priority_(false),
50 skip_next_begin_main_frame_to_reduce_latency_(false), 51 skip_next_begin_main_frame_to_reduce_latency_(false),
51 skip_begin_main_frame_to_reduce_latency_(false), 52 skip_begin_main_frame_to_reduce_latency_(false),
(...skipping 30 matching lines...) Expand all
82 return "BEGIN_IMPL_FRAME_STATE_BEGIN_FRAME_STARTING"; 83 return "BEGIN_IMPL_FRAME_STATE_BEGIN_FRAME_STARTING";
83 case BEGIN_IMPL_FRAME_STATE_INSIDE_BEGIN_FRAME: 84 case BEGIN_IMPL_FRAME_STATE_INSIDE_BEGIN_FRAME:
84 return "BEGIN_IMPL_FRAME_STATE_INSIDE_BEGIN_FRAME"; 85 return "BEGIN_IMPL_FRAME_STATE_INSIDE_BEGIN_FRAME";
85 case BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE: 86 case BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE:
86 return "BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE"; 87 return "BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE";
87 } 88 }
88 NOTREACHED(); 89 NOTREACHED();
89 return "???"; 90 return "???";
90 } 91 }
91 92
93 const char* SchedulerStateMachine::BeginImplFrameDeadlineModeToString(
94 BeginImplFrameDeadlineMode mode) {
95 switch (mode) {
96 case BEGIN_IMPL_FRAME_DEADLINE_MODE_NONE:
97 return "BEGIN_IMPL_FRAME_DEADLINE_MODE_NONE";
98 case BEGIN_IMPL_FRAME_DEADLINE_MODE_IMMEDIATE:
99 return "BEGIN_IMPL_FRAME_DEADLINE_MODE_IMMEDIATE";
100 case BEGIN_IMPL_FRAME_DEADLINE_MODE_REGULAR:
101 return "BEGIN_IMPL_FRAME_DEADLINE_MODE_REGULAR";
102 case BEGIN_IMPL_FRAME_DEADLINE_MODE_LATE:
103 return "BEGIN_IMPL_FRAME_DEADLINE_MODE_LATE";
104 }
105 NOTREACHED();
106 return "???";
107 }
108
92 const char* SchedulerStateMachine::CommitStateToString(CommitState state) { 109 const char* SchedulerStateMachine::CommitStateToString(CommitState state) {
93 switch (state) { 110 switch (state) {
94 case COMMIT_STATE_IDLE: 111 case COMMIT_STATE_IDLE:
95 return "COMMIT_STATE_IDLE"; 112 return "COMMIT_STATE_IDLE";
96 case COMMIT_STATE_BEGIN_MAIN_FRAME_SENT: 113 case COMMIT_STATE_BEGIN_MAIN_FRAME_SENT:
97 return "COMMIT_STATE_BEGIN_MAIN_FRAME_SENT"; 114 return "COMMIT_STATE_BEGIN_MAIN_FRAME_SENT";
98 case COMMIT_STATE_BEGIN_MAIN_FRAME_STARTED: 115 case COMMIT_STATE_BEGIN_MAIN_FRAME_STARTED:
99 return "COMMIT_STATE_BEGIN_MAIN_FRAME_STARTED"; 116 return "COMMIT_STATE_BEGIN_MAIN_FRAME_STARTED";
100 case COMMIT_STATE_READY_TO_COMMIT: 117 case COMMIT_STATE_READY_TO_COMMIT:
101 return "COMMIT_STATE_READY_TO_COMMIT"; 118 return "COMMIT_STATE_READY_TO_COMMIT";
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 case ACTION_DRAW_AND_SWAP_IF_POSSIBLE: 156 case ACTION_DRAW_AND_SWAP_IF_POSSIBLE:
140 return "ACTION_DRAW_AND_SWAP_IF_POSSIBLE"; 157 return "ACTION_DRAW_AND_SWAP_IF_POSSIBLE";
141 case ACTION_DRAW_AND_SWAP_FORCED: 158 case ACTION_DRAW_AND_SWAP_FORCED:
142 return "ACTION_DRAW_AND_SWAP_FORCED"; 159 return "ACTION_DRAW_AND_SWAP_FORCED";
143 case ACTION_DRAW_AND_SWAP_ABORT: 160 case ACTION_DRAW_AND_SWAP_ABORT:
144 return "ACTION_DRAW_AND_SWAP_ABORT"; 161 return "ACTION_DRAW_AND_SWAP_ABORT";
145 case ACTION_BEGIN_OUTPUT_SURFACE_CREATION: 162 case ACTION_BEGIN_OUTPUT_SURFACE_CREATION:
146 return "ACTION_BEGIN_OUTPUT_SURFACE_CREATION"; 163 return "ACTION_BEGIN_OUTPUT_SURFACE_CREATION";
147 case ACTION_PREPARE_TILES: 164 case ACTION_PREPARE_TILES:
148 return "ACTION_PREPARE_TILES"; 165 return "ACTION_PREPARE_TILES";
166 case ACTION_INVALIDATE_OUTPUT_SURFACE:
167 return "ACTION_INVALIDATE_OUTPUT_SURFACE";
149 } 168 }
150 NOTREACHED(); 169 NOTREACHED();
151 return "???"; 170 return "???";
152 } 171 }
153 172
154 scoped_refptr<base::trace_event::ConvertableToTraceFormat> 173 scoped_refptr<base::trace_event::ConvertableToTraceFormat>
155 SchedulerStateMachine::AsValue() const { 174 SchedulerStateMachine::AsValue() const {
156 scoped_refptr<base::trace_event::TracedValue> state = 175 scoped_refptr<base::trace_event::TracedValue> state =
157 new base::trace_event::TracedValue(); 176 new base::trace_event::TracedValue();
158 AsValueInto(state.get()); 177 AsValueInto(state.get());
(...skipping 23 matching lines...) Expand all
182 state->SetInteger("last_frame_number_swap_requested", 201 state->SetInteger("last_frame_number_swap_requested",
183 last_frame_number_swap_requested_); 202 last_frame_number_swap_requested_);
184 state->SetInteger("last_frame_number_begin_main_frame_sent", 203 state->SetInteger("last_frame_number_begin_main_frame_sent",
185 last_frame_number_begin_main_frame_sent_); 204 last_frame_number_begin_main_frame_sent_);
186 state->SetBoolean("funnel: animate_funnel", animate_funnel_); 205 state->SetBoolean("funnel: animate_funnel", animate_funnel_);
187 state->SetBoolean("funnel: perform_swap_funnel", perform_swap_funnel_); 206 state->SetBoolean("funnel: perform_swap_funnel", perform_swap_funnel_);
188 state->SetBoolean("funnel: request_swap_funnel", request_swap_funnel_); 207 state->SetBoolean("funnel: request_swap_funnel", request_swap_funnel_);
189 state->SetBoolean("funnel: send_begin_main_frame_funnel", 208 state->SetBoolean("funnel: send_begin_main_frame_funnel",
190 send_begin_main_frame_funnel_); 209 send_begin_main_frame_funnel_);
191 state->SetInteger("funnel: prepare_tiles_funnel", prepare_tiles_funnel_); 210 state->SetInteger("funnel: prepare_tiles_funnel", prepare_tiles_funnel_);
211 state->SetBoolean("funnel: invalidate_output_surface_funnel",
212 invalidate_output_surface_funnel_);
192 state->SetInteger("consecutive_checkerboard_animations", 213 state->SetInteger("consecutive_checkerboard_animations",
193 consecutive_checkerboard_animations_); 214 consecutive_checkerboard_animations_);
194 state->SetInteger("max_pending_swaps_", max_pending_swaps_); 215 state->SetInteger("max_pending_swaps_", max_pending_swaps_);
195 state->SetInteger("pending_swaps_", pending_swaps_); 216 state->SetInteger("pending_swaps_", pending_swaps_);
196 state->SetBoolean("needs_redraw", needs_redraw_); 217 state->SetBoolean("needs_redraw", needs_redraw_);
197 state->SetBoolean("needs_animate_", needs_animate_); 218 state->SetBoolean("needs_animate_", needs_animate_);
198 state->SetBoolean("needs_prepare_tiles", needs_prepare_tiles_); 219 state->SetBoolean("needs_prepare_tiles", needs_prepare_tiles_);
199 state->SetBoolean("needs_commit", needs_commit_); 220 state->SetBoolean("needs_commit", needs_commit_);
200 state->SetBoolean("visible", visible_); 221 state->SetBoolean("visible", visible_);
201 state->SetBoolean("can_start", can_start_); 222 state->SetBoolean("can_start", can_start_);
(...skipping 12 matching lines...) Expand all
214 state->SetBoolean("skip_begin_main_frame_to_reduce_latency", 235 state->SetBoolean("skip_begin_main_frame_to_reduce_latency",
215 skip_begin_main_frame_to_reduce_latency_); 236 skip_begin_main_frame_to_reduce_latency_);
216 state->SetBoolean("skip_next_begin_main_frame_to_reduce_latency", 237 state->SetBoolean("skip_next_begin_main_frame_to_reduce_latency",
217 skip_next_begin_main_frame_to_reduce_latency_); 238 skip_next_begin_main_frame_to_reduce_latency_);
218 state->SetBoolean("continuous_painting", continuous_painting_); 239 state->SetBoolean("continuous_painting", continuous_painting_);
219 state->SetBoolean("children_need_begin_frames", children_need_begin_frames_); 240 state->SetBoolean("children_need_begin_frames", children_need_begin_frames_);
220 state->SetBoolean("defer_commits", defer_commits_); 241 state->SetBoolean("defer_commits", defer_commits_);
221 state->EndDictionary(); 242 state->EndDictionary();
222 } 243 }
223 244
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
241 bool SchedulerStateMachine::PendingDrawsShouldBeAborted() const { 245 bool SchedulerStateMachine::PendingDrawsShouldBeAborted() const {
242 // These are all the cases where we normally cannot or do not want to draw 246 // These are all the cases where we normally cannot or do not want to draw
243 // but, if needs_redraw_ is true and we do not draw to make forward progress, 247 // but, if needs_redraw_ is true and we do not draw to make forward progress,
244 // we might deadlock with the main thread. 248 // we might deadlock with the main thread.
245 // This should be a superset of PendingActivationsShouldBeForced() since 249 // This should be a superset of PendingActivationsShouldBeForced() since
246 // activation of the pending tree is blocked by drawing of the active tree and 250 // activation of the pending tree is blocked by drawing of the active tree and
247 // the main thread might be blocked on activation of the most recent commit. 251 // the main thread might be blocked on activation of the most recent commit.
248 if (PendingActivationsShouldBeForced()) 252 if (PendingActivationsShouldBeForced())
249 return true; 253 return true;
250 254
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
455 } 459 }
456 460
457 bool SchedulerStateMachine::ShouldPrepareTiles() const { 461 bool SchedulerStateMachine::ShouldPrepareTiles() const {
458 // PrepareTiles only really needs to be called immediately after commit 462 // PrepareTiles only really needs to be called immediately after commit
459 // and then periodically after that. Use a funnel to make sure we average 463 // and then periodically after that. Use a funnel to make sure we average
460 // one PrepareTiles per BeginImplFrame in the long run. 464 // one PrepareTiles per BeginImplFrame in the long run.
461 if (prepare_tiles_funnel_ > 0) 465 if (prepare_tiles_funnel_ > 0)
462 return false; 466 return false;
463 467
464 // Limiting to once per-frame is not enough, since we only want to 468 // Limiting to once per-frame is not enough, since we only want to
465 // prepare tiles _after_ draws. Polling for draw triggers and 469 // prepare tiles _after_ draws.
466 // begin-frame are mutually exclusive, so we limit to these two cases. 470 if (begin_impl_frame_state_ != BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE)
467 if (begin_impl_frame_state_ != BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE &&
468 !inside_poll_for_anticipated_draw_triggers_)
469 return false; 471 return false;
472
470 return needs_prepare_tiles_; 473 return needs_prepare_tiles_;
471 } 474 }
472 475
476 bool SchedulerStateMachine::ShouldInvalidateOutputSurface() const {
477 // Do not invalidate too many times in a frame.
478 if (invalidate_output_surface_funnel_)
479 return false;
480
481 // Only the synchronous compositor requires invalidations.
482 if (!settings_.using_synchronous_renderer_compositor)
483 return false;
484
485 // Invalidations are only performed inside a BeginFrame or inside deadline.
486 if (begin_impl_frame_state_ != BEGIN_IMPL_FRAME_STATE_BEGIN_FRAME_STARTING &&
487 begin_impl_frame_state_ != BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE)
488 return false;
489
490 return needs_redraw_ || needs_prepare_tiles_;
brianderson 2015/03/25 23:10:37 Why needs_prepare_tiles_?
sunnyps 2015/03/27 00:52:48 The previous draw might have caused tile propertie
brianderson 2015/03/27 21:24:24 I think you can remove needs_prepare_tiles_ from h
sunnyps 2015/03/27 22:38:24 I moved the prepare_tiles_funnel_ decrement to OnB
491 }
492
473 SchedulerStateMachine::Action SchedulerStateMachine::NextAction() const { 493 SchedulerStateMachine::Action SchedulerStateMachine::NextAction() const {
474 if (ShouldActivatePendingTree()) 494 if (ShouldActivatePendingTree())
475 return ACTION_ACTIVATE_SYNC_TREE; 495 return ACTION_ACTIVATE_SYNC_TREE;
476 if (ShouldCommit()) 496 if (ShouldCommit())
477 return ACTION_COMMIT; 497 return ACTION_COMMIT;
478 if (ShouldAnimate()) 498 if (ShouldAnimate())
479 return ACTION_ANIMATE; 499 return ACTION_ANIMATE;
480 if (ShouldDraw()) { 500 if (ShouldDraw()) {
481 if (PendingDrawsShouldBeAborted()) 501 if (PendingDrawsShouldBeAborted())
482 return ACTION_DRAW_AND_SWAP_ABORT; 502 return ACTION_DRAW_AND_SWAP_ABORT;
483 else if (forced_redraw_state_ == FORCED_REDRAW_STATE_WAITING_FOR_DRAW) 503 else if (forced_redraw_state_ == FORCED_REDRAW_STATE_WAITING_FOR_DRAW)
484 return ACTION_DRAW_AND_SWAP_FORCED; 504 return ACTION_DRAW_AND_SWAP_FORCED;
485 else 505 else
486 return ACTION_DRAW_AND_SWAP_IF_POSSIBLE; 506 return ACTION_DRAW_AND_SWAP_IF_POSSIBLE;
487 } 507 }
488 if (ShouldPrepareTiles()) 508 if (ShouldPrepareTiles())
489 return ACTION_PREPARE_TILES; 509 return ACTION_PREPARE_TILES;
490 if (ShouldSendBeginMainFrame()) 510 if (ShouldSendBeginMainFrame())
491 return ACTION_SEND_BEGIN_MAIN_FRAME; 511 return ACTION_SEND_BEGIN_MAIN_FRAME;
512 if (ShouldInvalidateOutputSurface())
513 return ACTION_INVALIDATE_OUTPUT_SURFACE;
492 if (ShouldBeginOutputSurfaceCreation()) 514 if (ShouldBeginOutputSurfaceCreation())
493 return ACTION_BEGIN_OUTPUT_SURFACE_CREATION; 515 return ACTION_BEGIN_OUTPUT_SURFACE_CREATION;
494 return ACTION_NONE; 516 return ACTION_NONE;
495 } 517 }
496 518
497 void SchedulerStateMachine::UpdateState(Action action) { 519 void SchedulerStateMachine::UpdateState(Action action) {
498 switch (action) { 520 switch (action) {
499 case ACTION_NONE: 521 case ACTION_NONE:
500 return; 522 return;
501 523
502 case ACTION_ACTIVATE_SYNC_TREE: 524 case ACTION_ACTIVATE_SYNC_TREE:
503 UpdateStateOnActivation(); 525 UpdateStateOnActivation();
504 return; 526 return;
505 527
506 case ACTION_ANIMATE: 528 case ACTION_ANIMATE:
507 DCHECK(!animate_funnel_); 529 UpdateStateOnAnimate();
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();
514 return; 530 return;
515 531
516 case ACTION_SEND_BEGIN_MAIN_FRAME: 532 case ACTION_SEND_BEGIN_MAIN_FRAME:
517 DCHECK(!has_pending_tree_ || 533 UpdateStateOnSendBeginMainFrame();
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_;
526 return; 534 return;
527 535
528 case ACTION_COMMIT: { 536 case ACTION_COMMIT: {
529 bool commit_has_no_updates = false; 537 bool commit_has_no_updates = false;
530 UpdateStateOnCommit(commit_has_no_updates); 538 UpdateStateOnCommit(commit_has_no_updates);
531 return; 539 return;
532 } 540 }
533 541
534 case ACTION_DRAW_AND_SWAP_FORCED: 542 case ACTION_DRAW_AND_SWAP_FORCED:
535 case ACTION_DRAW_AND_SWAP_IF_POSSIBLE: { 543 case ACTION_DRAW_AND_SWAP_IF_POSSIBLE: {
536 bool did_request_swap = true; 544 bool did_request_swap = true;
537 UpdateStateOnDraw(did_request_swap); 545 UpdateStateOnDraw(did_request_swap);
538 return; 546 return;
539 } 547 }
540 548
541 case ACTION_DRAW_AND_SWAP_ABORT: { 549 case ACTION_DRAW_AND_SWAP_ABORT: {
542 bool did_request_swap = false; 550 bool did_request_swap = false;
543 UpdateStateOnDraw(did_request_swap); 551 UpdateStateOnDraw(did_request_swap);
544 return; 552 return;
545 } 553 }
546 554
547 case ACTION_BEGIN_OUTPUT_SURFACE_CREATION: 555 case ACTION_BEGIN_OUTPUT_SURFACE_CREATION:
548 DCHECK_EQ(output_surface_state_, OUTPUT_SURFACE_LOST); 556 UpdateStateOnBeginOutputSurfaceCreation();
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_);
557 return; 557 return;
558 558
559 case ACTION_PREPARE_TILES: 559 case ACTION_PREPARE_TILES:
560 UpdateStateOnPrepareTiles(); 560 UpdateStateOnPrepareTiles();
561 return; 561 return;
562
563 case ACTION_INVALIDATE_OUTPUT_SURFACE:
brianderson 2015/03/25 23:10:37 Thanks for making UpdateStateOn* method usage cons
564 UpdateStateOnInvalidateOutputSurface();
565 return;
562 } 566 }
563 } 567 }
564 568
569 void SchedulerStateMachine::UpdateStateOnAnimate() {
570 DCHECK(!animate_funnel_);
571 last_frame_number_animate_performed_ = current_frame_number_;
572 animate_funnel_ = true;
573 needs_animate_ = false;
574 // TODO(skyostil): Instead of assuming this, require the client to tell
575 // us.
brianderson 2015/03/25 23:10:37 Comment can be one line now.
sunnyps 2015/03/27 00:52:48 Done.
576 SetNeedsRedraw();
577 }
578
579 void SchedulerStateMachine::UpdateStateOnSendBeginMainFrame() {
580 DCHECK(!has_pending_tree_ || settings_.main_frame_before_activation_enabled);
581 DCHECK(visible_);
582 DCHECK(!send_begin_main_frame_funnel_);
583 commit_state_ = COMMIT_STATE_BEGIN_MAIN_FRAME_SENT;
584 needs_commit_ = false;
585 send_begin_main_frame_funnel_ = true;
586 last_frame_number_begin_main_frame_sent_ = current_frame_number_;
587 }
588
565 void SchedulerStateMachine::UpdateStateOnCommit(bool commit_has_no_updates) { 589 void SchedulerStateMachine::UpdateStateOnCommit(bool commit_has_no_updates) {
566 commit_count_++; 590 commit_count_++;
567 591
568 if (!commit_has_no_updates) 592 if (!commit_has_no_updates)
569 animate_funnel_ = false; 593 animate_funnel_ = false;
570 594
571 if (commit_has_no_updates || settings_.main_frame_before_activation_enabled) { 595 if (commit_has_no_updates || settings_.main_frame_before_activation_enabled) {
572 commit_state_ = COMMIT_STATE_IDLE; 596 commit_state_ = COMMIT_STATE_IDLE;
573 } else if (settings_.impl_side_painting) { 597 } else if (settings_.impl_side_painting) {
574 commit_state_ = COMMIT_STATE_WAITING_FOR_ACTIVATION; 598 commit_state_ = COMMIT_STATE_WAITING_FOR_ACTIVATION;
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
650 DCHECK(!request_swap_funnel_); 674 DCHECK(!request_swap_funnel_);
651 request_swap_funnel_ = true; 675 request_swap_funnel_ = true;
652 last_frame_number_swap_requested_ = current_frame_number_; 676 last_frame_number_swap_requested_ = current_frame_number_;
653 } 677 }
654 } 678 }
655 679
656 void SchedulerStateMachine::UpdateStateOnPrepareTiles() { 680 void SchedulerStateMachine::UpdateStateOnPrepareTiles() {
657 needs_prepare_tiles_ = false; 681 needs_prepare_tiles_ = false;
658 } 682 }
659 683
684 void SchedulerStateMachine::UpdateStateOnBeginOutputSurfaceCreation() {
685 DCHECK_EQ(output_surface_state_, OUTPUT_SURFACE_LOST);
686 output_surface_state_ = OUTPUT_SURFACE_CREATING;
687
688 // The following DCHECKs make sure we are in the proper quiescent state.
689 // The pipeline should be flushed entirely before we start output
690 // surface creation to avoid complicated corner cases.
691 DCHECK_EQ(commit_state_, COMMIT_STATE_IDLE);
692 DCHECK(!has_pending_tree_);
693 DCHECK(!active_tree_needs_first_draw_);
694 }
695
696 void SchedulerStateMachine::UpdateStateOnInvalidateOutputSurface() {
697 DCHECK(!invalidate_output_surface_funnel_);
698 invalidate_output_surface_funnel_ = true;
699 last_frame_number_invalidate_output_surface_performed_ =
700 current_frame_number_;
701 // There is no guarantee that a draw will arrive from the synchronous
702 // compositor. We clear this flag here so that the pipeline isn't blocked.
703 active_tree_needs_first_draw_ = false;
brianderson 2015/03/25 23:10:37 I'm worried that this will make us skip frames or
sunnyps 2015/03/27 00:52:48 Webview can't even tell if it's in this state. Sin
brianderson 2015/03/27 21:24:24 Is the problem that we are blocking the main threa
sunnyps 2015/03/27 22:38:24 The problem is that the main thread is blocked ind
sunnyps 2015/03/30 21:49:18 I removed this piece of code and found that I coul
704 }
705
660 void SchedulerStateMachine::SetSkipNextBeginMainFrameToReduceLatency() { 706 void SchedulerStateMachine::SetSkipNextBeginMainFrameToReduceLatency() {
661 TRACE_EVENT_INSTANT0("cc", 707 TRACE_EVENT_INSTANT0("cc",
662 "Scheduler: SkipNextBeginMainFrameToReduceLatency", 708 "Scheduler: SkipNextBeginMainFrameToReduceLatency",
663 TRACE_EVENT_SCOPE_THREAD); 709 TRACE_EVENT_SCOPE_THREAD);
664 skip_next_begin_main_frame_to_reduce_latency_ = true; 710 skip_next_begin_main_frame_to_reduce_latency_ = true;
665 } 711 }
666 712
667 bool SchedulerStateMachine::BeginFrameNeededForChildren() const { 713 bool SchedulerStateMachine::BeginFrameNeededForChildren() const {
668 if (HasInitializedOutputSurface()) 714 if (HasInitializedOutputSurface())
brianderson 2015/03/25 23:10:37 The other BeginFrameNeeded* methods don't check Ha
sunnyps 2015/03/27 00:52:48 Done.
669 return children_need_begin_frames_; 715 return children_need_begin_frames_;
670 716
671 return false; 717 return false;
672 } 718 }
673 719
674 bool SchedulerStateMachine::BeginFrameNeeded() const { 720 bool SchedulerStateMachine::BeginFrameNeeded() const {
675 // We can't handle BeginFrames when output surface isn't initialized. 721 // We can't handle BeginFrames when output surface isn't initialized.
676 // TODO(brianderson): Support output surface creation inside a BeginFrame. 722 // TODO(brianderson): Support output surface creation inside a BeginFrame.
677 if (!HasInitializedOutputSurface()) 723 if (!HasInitializedOutputSurface())
678 return false; 724 return false;
679 725 return (BeginFrameNeededToAnimateOrDraw() || BeginFrameNeededForChildren() ||
brianderson 2015/03/25 23:10:37 So much easier to understand!
680 if (SupportsProactiveBeginFrame()) { 726 ProactiveBeginFrameWanted());
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;
717 } 727 }
718 728
719 void SchedulerStateMachine::SetChildrenNeedBeginFrames( 729 void SchedulerStateMachine::SetChildrenNeedBeginFrames(
720 bool children_need_begin_frames) { 730 bool children_need_begin_frames) {
721 children_need_begin_frames_ = children_need_begin_frames; 731 children_need_begin_frames_ = children_need_begin_frames;
722 } 732 }
723 733
724 void SchedulerStateMachine::SetDeferCommits(bool defer_commits) { 734 void SchedulerStateMachine::SetDeferCommits(bool defer_commits) {
725 defer_commits_ = defer_commits; 735 defer_commits_ = defer_commits;
726 } 736 }
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
770 780
771 // If the last commit was aborted because of early out (no updates), we should 781 // If the last commit was aborted because of early out (no updates), we should
772 // still want a begin frame in case there is a commit coming again. 782 // still want a begin frame in case there is a commit coming again.
773 if (last_commit_had_no_updates_) 783 if (last_commit_had_no_updates_)
774 return true; 784 return true;
775 785
776 return false; 786 return false;
777 } 787 }
778 788
779 void SchedulerStateMachine::OnBeginImplFrame() { 789 void SchedulerStateMachine::OnBeginImplFrame() {
780 AdvanceCurrentFrameNumber();
781 DCHECK_EQ(begin_impl_frame_state_, BEGIN_IMPL_FRAME_STATE_IDLE)
782 << AsValue()->ToString();
783 begin_impl_frame_state_ = BEGIN_IMPL_FRAME_STATE_BEGIN_FRAME_STARTING; 790 begin_impl_frame_state_ = BEGIN_IMPL_FRAME_STATE_BEGIN_FRAME_STARTING;
791 current_frame_number_++;
792
784 last_commit_had_no_updates_ = false; 793 last_commit_had_no_updates_ = false;
794
795 // Clear funnels for any actions we perform during the frame.
796 animate_funnel_ = false;
797 perform_swap_funnel_ = false;
798 request_swap_funnel_ = false;
799 send_begin_main_frame_funnel_ = false;
800 invalidate_output_surface_funnel_ = false;
801
802 skip_begin_main_frame_to_reduce_latency_ =
803 skip_next_begin_main_frame_to_reduce_latency_;
804 skip_next_begin_main_frame_to_reduce_latency_ = false;
785 } 805 }
786 806
787 void SchedulerStateMachine::OnBeginImplFrameDeadlinePending() { 807 void SchedulerStateMachine::OnBeginImplFrameDeadlinePending() {
788 DCHECK_EQ(begin_impl_frame_state_,
789 BEGIN_IMPL_FRAME_STATE_BEGIN_FRAME_STARTING)
790 << AsValue()->ToString();
791 begin_impl_frame_state_ = BEGIN_IMPL_FRAME_STATE_INSIDE_BEGIN_FRAME; 808 begin_impl_frame_state_ = BEGIN_IMPL_FRAME_STATE_INSIDE_BEGIN_FRAME;
792 } 809 }
793 810
794 void SchedulerStateMachine::OnBeginImplFrameDeadline() { 811 void SchedulerStateMachine::OnBeginImplFrameDeadline() {
795 DCHECK_EQ(begin_impl_frame_state_, BEGIN_IMPL_FRAME_STATE_INSIDE_BEGIN_FRAME)
796 << AsValue()->ToString();
797 begin_impl_frame_state_ = BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE; 812 begin_impl_frame_state_ = BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE;
813
814 // Clear funnels for any actions we perform during the deadline.
brianderson 2015/03/25 23:10:37 Why are these cleared in both the deadline and Beg
sunnyps 2015/03/27 00:52:48 For invalidate_output_surface_funnel_ the reason i
brianderson 2015/03/27 21:24:24 Can add a comment about that and also explain in w
sunnyps 2015/03/27 22:38:24 I changed this so that it's invalidated only once,
815 perform_swap_funnel_ = false;
816 request_swap_funnel_ = false;
817 invalidate_output_surface_funnel_ = false;
818
819 // "Drain" the PrepareTiles funnel.
brianderson 2015/03/25 23:10:37 Why is this moved to the deadline rather than the
sunnyps 2015/03/27 00:52:48 Because prepare tiles (when initiated by the sched
brianderson 2015/03/27 21:24:24 Was the intent not to have a functional change by
sunnyps 2015/03/27 22:38:24 Good catch. Done.
820 if (prepare_tiles_funnel_ > 0)
821 prepare_tiles_funnel_--;
798 } 822 }
799 823
800 void SchedulerStateMachine::OnBeginImplFrameIdle() { 824 void SchedulerStateMachine::OnBeginImplFrameIdle() {
801 DCHECK_EQ(begin_impl_frame_state_, BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE)
802 << AsValue()->ToString();
803 begin_impl_frame_state_ = BEGIN_IMPL_FRAME_STATE_IDLE; 825 begin_impl_frame_state_ = BEGIN_IMPL_FRAME_STATE_IDLE;
804 } 826 }
805 827
806 SchedulerStateMachine::BeginImplFrameDeadlineMode 828 SchedulerStateMachine::BeginImplFrameDeadlineMode
807 SchedulerStateMachine::CurrentBeginImplFrameDeadlineMode() const { 829 SchedulerStateMachine::CurrentBeginImplFrameDeadlineMode() const {
808 if (ShouldTriggerBeginImplFrameDeadlineImmediately()) { 830 if (settings_.using_synchronous_renderer_compositor) {
831 // No deadline for synchronous compositor.
832 return BEGIN_IMPL_FRAME_DEADLINE_MODE_NONE;
833 } else if (ShouldTriggerBeginImplFrameDeadlineImmediately()) {
809 return BEGIN_IMPL_FRAME_DEADLINE_MODE_IMMEDIATE; 834 return BEGIN_IMPL_FRAME_DEADLINE_MODE_IMMEDIATE;
810 } else if (needs_redraw_ && pending_swaps_ < max_pending_swaps_) { 835 } else if (needs_redraw_ && pending_swaps_ < max_pending_swaps_) {
811 // We have an animation or fast input path on the impl thread that wants 836 // We have an animation or fast input path on the impl thread that wants
812 // to draw, so don't wait too long for a new active tree. 837 // to draw, so don't wait too long for a new active tree.
813 // If we are swap throttled we should wait until we are unblocked. 838 // If we are swap throttled we should wait until we are unblocked.
814 return BEGIN_IMPL_FRAME_DEADLINE_MODE_REGULAR; 839 return BEGIN_IMPL_FRAME_DEADLINE_MODE_REGULAR;
815 } else { 840 } else {
816 // The impl thread doesn't have anything it wants to draw and we are just 841 // The impl thread doesn't have anything it wants to draw and we are just
817 // waiting for a new active tree or we are swap throttled. In short we are 842 // waiting for a new active tree or we are swap throttled. In short we are
818 // blocked. 843 // blocked.
819 return BEGIN_IMPL_FRAME_DEADLINE_MODE_LATE; 844 return BEGIN_IMPL_FRAME_DEADLINE_MODE_LATE;
820 } 845 }
821 } 846 }
822 847
823 bool SchedulerStateMachine::ShouldTriggerBeginImplFrameDeadlineImmediately() 848 bool SchedulerStateMachine::ShouldTriggerBeginImplFrameDeadlineImmediately()
824 const { 849 const {
825 // TODO(brianderson): This should take into account multiple commit sources. 850 // TODO(brianderson): This should take into account multiple commit sources.
826
827 if (begin_impl_frame_state_ != BEGIN_IMPL_FRAME_STATE_INSIDE_BEGIN_FRAME) 851 if (begin_impl_frame_state_ != BEGIN_IMPL_FRAME_STATE_INSIDE_BEGIN_FRAME)
828 return false; 852 return false;
829 853
830 // If we've lost the output surface, end the current BeginImplFrame ASAP 854 // If we've lost the output surface, end the current BeginImplFrame ASAP
831 // so we can start creating the next output surface. 855 // so we can start creating the next output surface.
832 if (output_surface_state_ == OUTPUT_SURFACE_LOST) 856 if (output_surface_state_ == OUTPUT_SURFACE_LOST)
833 return true; 857 return true;
834 858
835 // SwapAck throttle the deadline since we wont draw and swap anyway. 859 // SwapAck throttle the deadline since we wont draw and swap anyway.
836 if (pending_swaps_ >= max_pending_swaps_) 860 if (pending_swaps_ >= max_pending_swaps_)
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
891 // which case the main thread is in a high latency mode. 915 // which case the main thread is in a high latency mode.
892 return (active_tree_needs_first_draw_ || perform_swap_funnel_) && 916 return (active_tree_needs_first_draw_ || perform_swap_funnel_) &&
893 !send_begin_main_frame_funnel_; 917 !send_begin_main_frame_funnel_;
894 } 918 }
895 919
896 // If the active tree needs its first draw in any other state, we know the 920 // If the active tree needs its first draw in any other state, we know the
897 // main thread is in a high latency mode. 921 // main thread is in a high latency mode.
898 return active_tree_needs_first_draw_; 922 return active_tree_needs_first_draw_;
899 } 923 }
900 924
901 void SchedulerStateMachine::DidEnterPollForAnticipatedDrawTriggers() {
902 AdvanceCurrentFrameNumber();
903 inside_poll_for_anticipated_draw_triggers_ = true;
904 }
905
906 void SchedulerStateMachine::DidLeavePollForAnticipatedDrawTriggers() {
907 inside_poll_for_anticipated_draw_triggers_ = false;
908 }
909
910 void SchedulerStateMachine::SetVisible(bool visible) { visible_ = visible; } 925 void SchedulerStateMachine::SetVisible(bool visible) { visible_ = visible; }
911 926
912 void SchedulerStateMachine::SetCanDraw(bool can_draw) { can_draw_ = can_draw; } 927 void SchedulerStateMachine::SetCanDraw(bool can_draw) { can_draw_ = can_draw; }
913 928
914 void SchedulerStateMachine::SetNeedsRedraw() { needs_redraw_ = true; } 929 void SchedulerStateMachine::SetNeedsRedraw() { needs_redraw_ = true; }
915 930
916 void SchedulerStateMachine::SetNeedsAnimate() { 931 void SchedulerStateMachine::SetNeedsAnimate() {
917 needs_animate_ = true; 932 needs_animate_ = true;
918 } 933 }
919 934
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
1080 static_cast<int>(begin_impl_frame_state_), 1095 static_cast<int>(begin_impl_frame_state_),
1081 static_cast<int>(commit_state_), 1096 static_cast<int>(commit_state_),
1082 has_pending_tree_ ? 'T' : 'F', 1097 has_pending_tree_ ? 'T' : 'F',
1083 pending_tree_is_ready_for_activation_ ? 'T' : 'F', 1098 pending_tree_is_ready_for_activation_ ? 'T' : 'F',
1084 active_tree_needs_first_draw_ ? 'T' : 'F', 1099 active_tree_needs_first_draw_ ? 'T' : 'F',
1085 max_pending_swaps_, 1100 max_pending_swaps_,
1086 pending_swaps_); 1101 pending_swaps_);
1087 } 1102 }
1088 1103
1089 } // namespace cc 1104 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698