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

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

Issue 1131633003: cc: Use multiple PrepareTiles approaches Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 5 years, 6 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/test/fake_layer_tree_host_impl_client.h » ('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 13
14 namespace cc { 14 namespace cc {
15 15
16 SchedulerStateMachine::SchedulerStateMachine(const SchedulerSettings& settings) 16 SchedulerStateMachine::SchedulerStateMachine(const SchedulerSettings& settings)
17 : settings_(settings), 17 : settings_(settings),
18 output_surface_state_(OUTPUT_SURFACE_LOST), 18 output_surface_state_(OUTPUT_SURFACE_LOST),
19 begin_impl_frame_state_(BEGIN_IMPL_FRAME_STATE_IDLE), 19 begin_impl_frame_state_(BEGIN_IMPL_FRAME_STATE_IDLE),
20 commit_state_(COMMIT_STATE_IDLE), 20 commit_state_(COMMIT_STATE_IDLE),
21 forced_redraw_state_(FORCED_REDRAW_STATE_IDLE), 21 prepare_tiles_approach_(PREPARE_TILES_APPROACH_PRIORITIZE_LATENCY),
22 prepare_tiles_reason_(PREPARE_TILES_NOT_NEEDED),
22 commit_count_(0), 23 commit_count_(0),
23 current_frame_number_(0), 24 current_frame_number_(0),
24 last_frame_number_animate_performed_(-1), 25 last_frame_number_animate_performed_(-1),
25 last_frame_number_swap_performed_(-1), 26 last_frame_number_swap_performed_(-1),
26 last_frame_number_swap_requested_(-1), 27 last_frame_number_swap_requested_(-1),
27 last_frame_number_begin_main_frame_sent_(-1), 28 last_frame_number_begin_main_frame_sent_(-1),
28 last_frame_number_invalidate_output_surface_performed_(-1), 29 last_frame_number_invalidate_output_surface_performed_(-1),
29 animate_funnel_(false), 30 animate_funnel_(false),
30 request_swap_funnel_(false), 31 request_swap_funnel_(false),
31 send_begin_main_frame_funnel_(false), 32 send_begin_main_frame_funnel_(false),
32 invalidate_output_surface_funnel_(false), 33 invalidate_output_surface_funnel_(false),
33 prepare_tiles_funnel_(0), 34 prepare_tiles_funnel_(0),
34 consecutive_checkerboard_animations_(0),
35 max_pending_swaps_(1), 35 max_pending_swaps_(1),
36 pending_swaps_(0), 36 pending_swaps_(0),
37 needs_redraw_(false), 37 needs_redraw_(false),
38 last_draw_result_(DRAW_SUCCESS),
39 retry_begin_impl_frame_(false),
40 retry_begin_impl_frame_deadline_(false),
38 needs_animate_(false), 41 needs_animate_(false),
39 needs_prepare_tiles_(false),
40 needs_commit_(false), 42 needs_commit_(false),
41 visible_(false), 43 visible_(false),
42 can_start_(false), 44 can_start_(false),
43 can_draw_(false), 45 can_draw_(false),
44 has_pending_tree_(false), 46 has_pending_tree_(false),
45 pending_tree_is_ready_for_activation_(false), 47 pending_tree_is_ready_for_activation_(false),
48 requires_high_res_to_draw_(false),
46 active_tree_needs_first_draw_(false), 49 active_tree_needs_first_draw_(false),
47 did_create_and_initialize_first_output_surface_(false), 50 did_create_and_initialize_first_output_surface_(false),
48 impl_latency_takes_priority_(false), 51 impl_latency_takes_priority_(false),
49 skip_next_begin_main_frame_to_reduce_latency_(false), 52 skip_next_begin_main_frame_to_reduce_latency_(false),
50 skip_begin_main_frame_to_reduce_latency_(false), 53 skip_begin_main_frame_to_reduce_latency_(false),
51 continuous_painting_(false), 54 continuous_painting_(false),
52 children_need_begin_frames_(false), 55 children_need_begin_frames_(false),
53 defer_commits_(false), 56 defer_commits_(false),
54 video_needs_begin_frames_(false), 57 video_needs_begin_frames_(false),
55 last_commit_had_no_updates_(false), 58 last_commit_had_no_updates_(false),
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 BeginImplFrameDeadlineMode mode) { 99 BeginImplFrameDeadlineMode mode) {
97 switch (mode) { 100 switch (mode) {
98 case BEGIN_IMPL_FRAME_DEADLINE_MODE_NONE: 101 case BEGIN_IMPL_FRAME_DEADLINE_MODE_NONE:
99 return "BEGIN_IMPL_FRAME_DEADLINE_MODE_NONE"; 102 return "BEGIN_IMPL_FRAME_DEADLINE_MODE_NONE";
100 case BEGIN_IMPL_FRAME_DEADLINE_MODE_IMMEDIATE: 103 case BEGIN_IMPL_FRAME_DEADLINE_MODE_IMMEDIATE:
101 return "BEGIN_IMPL_FRAME_DEADLINE_MODE_IMMEDIATE"; 104 return "BEGIN_IMPL_FRAME_DEADLINE_MODE_IMMEDIATE";
102 case BEGIN_IMPL_FRAME_DEADLINE_MODE_REGULAR: 105 case BEGIN_IMPL_FRAME_DEADLINE_MODE_REGULAR:
103 return "BEGIN_IMPL_FRAME_DEADLINE_MODE_REGULAR"; 106 return "BEGIN_IMPL_FRAME_DEADLINE_MODE_REGULAR";
104 case BEGIN_IMPL_FRAME_DEADLINE_MODE_LATE: 107 case BEGIN_IMPL_FRAME_DEADLINE_MODE_LATE:
105 return "BEGIN_IMPL_FRAME_DEADLINE_MODE_LATE"; 108 return "BEGIN_IMPL_FRAME_DEADLINE_MODE_LATE";
109 case BEGIN_IMPL_FRAME_DEADLINE_MODE_TRY_TO_AVOID_CHECKERBOARD:
110 return "BEGIN_IMPL_FRAME_DEADLINE_MODE_TRY_TO_AVOID_CHECKERBOARD";
106 case BEGIN_IMPL_FRAME_DEADLINE_MODE_BLOCKED_ON_READY_TO_DRAW: 111 case BEGIN_IMPL_FRAME_DEADLINE_MODE_BLOCKED_ON_READY_TO_DRAW:
107 return "BEGIN_IMPL_FRAME_DEADLINE_MODE_BLOCKED_ON_READY_TO_DRAW"; 112 return "BEGIN_IMPL_FRAME_DEADLINE_MODE_BLOCKED_ON_READY_TO_DRAW";
108 } 113 }
109 NOTREACHED(); 114 NOTREACHED();
110 return "???"; 115 return "???";
111 } 116 }
112 117
113 const char* SchedulerStateMachine::CommitStateToString(CommitState state) { 118 const char* SchedulerStateMachine::CommitStateToString(CommitState state) {
114 switch (state) { 119 switch (state) {
115 case COMMIT_STATE_IDLE: 120 case COMMIT_STATE_IDLE:
116 return "COMMIT_STATE_IDLE"; 121 return "COMMIT_STATE_IDLE";
117 case COMMIT_STATE_BEGIN_MAIN_FRAME_SENT: 122 case COMMIT_STATE_BEGIN_MAIN_FRAME_SENT:
118 return "COMMIT_STATE_BEGIN_MAIN_FRAME_SENT"; 123 return "COMMIT_STATE_BEGIN_MAIN_FRAME_SENT";
119 case COMMIT_STATE_BEGIN_MAIN_FRAME_STARTED: 124 case COMMIT_STATE_BEGIN_MAIN_FRAME_STARTED:
120 return "COMMIT_STATE_BEGIN_MAIN_FRAME_STARTED"; 125 return "COMMIT_STATE_BEGIN_MAIN_FRAME_STARTED";
121 case COMMIT_STATE_READY_TO_COMMIT: 126 case COMMIT_STATE_READY_TO_COMMIT:
122 return "COMMIT_STATE_READY_TO_COMMIT"; 127 return "COMMIT_STATE_READY_TO_COMMIT";
123 case COMMIT_STATE_WAITING_FOR_ACTIVATION: 128 case COMMIT_STATE_WAITING_FOR_ACTIVATION:
124 return "COMMIT_STATE_WAITING_FOR_ACTIVATION"; 129 return "COMMIT_STATE_WAITING_FOR_ACTIVATION";
125 case COMMIT_STATE_WAITING_FOR_DRAW: 130 case COMMIT_STATE_WAITING_FOR_DRAW:
126 return "COMMIT_STATE_WAITING_FOR_DRAW"; 131 return "COMMIT_STATE_WAITING_FOR_DRAW";
127 } 132 }
128 NOTREACHED(); 133 NOTREACHED();
129 return "???"; 134 return "???";
130 } 135 }
131 136
132 const char* SchedulerStateMachine::ForcedRedrawOnTimeoutStateToString( 137 const char* SchedulerStateMachine::PrepareTilesApproachToString(
133 ForcedRedrawOnTimeoutState state) { 138 PrepareTilesApproach approach) {
134 switch (state) { 139 switch (approach) {
135 case FORCED_REDRAW_STATE_IDLE: 140 case PREPARE_TILES_APPROACH_PRIORITIZE_LATENCY:
136 return "FORCED_REDRAW_STATE_IDLE"; 141 return "PREPARE_TILES_APPROACH_PRIORITIZE_LATENCY";
137 case FORCED_REDRAW_STATE_WAITING_FOR_COMMIT: 142 case PREPARE_TILES_APPROACH_ACCURATE_ACTIVE_WORK:
138 return "FORCED_REDRAW_STATE_WAITING_FOR_COMMIT"; 143 return "PREPARE_TILES_APPROACH_ACCURATE_ACTIVE_WORK";
139 case FORCED_REDRAW_STATE_WAITING_FOR_ACTIVATION:
140 return "FORCED_REDRAW_STATE_WAITING_FOR_ACTIVATION";
141 case FORCED_REDRAW_STATE_WAITING_FOR_DRAW:
142 return "FORCED_REDRAW_STATE_WAITING_FOR_DRAW";
143 } 144 }
144 NOTREACHED(); 145 NOTREACHED();
145 return "???"; 146 return "???";
147 }
148
149 const char* SchedulerStateMachine::PrepareTilesReasonToString(
150 PrepareTilesReason reason) {
151 switch (reason) {
152 case PREPARE_TILES_NOT_NEEDED:
153 return "PREPARE_TILES_NOT_NEEDED";
154 case PREPARE_TILES_REQUESTED:
155 return "PREPARE_TILES_REQUESTED";
156 case PREPARE_TILES_NEEDED_FOR_COMMIT:
157 return "PREPARE_TILES_NEEDED_FOR_COMMIT";
158 case PREPARE_TILES_NEEDED_FOR_ABORTED_DRAW:
159 return "PREPARE_TILES_NEEDED_FOR_ABORTED_DRAW";
160 case PREPARE_TILES_NEEDED_TO_EVICT_TILES:
161 return "PREPARE_TILES_NEEDED_TO_EVICT_TILES";
162 }
163 NOTREACHED();
164 return "???";
146 } 165 }
147 166
148 const char* SchedulerStateMachine::ActionToString(Action action) { 167 const char* SchedulerStateMachine::ActionToString(Action action) {
149 switch (action) { 168 switch (action) {
150 case ACTION_NONE: 169 case ACTION_NONE:
151 return "ACTION_NONE"; 170 return "ACTION_NONE";
152 case ACTION_ANIMATE: 171 case ACTION_ANIMATE:
153 return "ACTION_ANIMATE"; 172 return "ACTION_ANIMATE";
154 case ACTION_SEND_BEGIN_MAIN_FRAME: 173 case ACTION_SEND_BEGIN_MAIN_FRAME:
155 return "ACTION_SEND_BEGIN_MAIN_FRAME"; 174 return "ACTION_SEND_BEGIN_MAIN_FRAME";
(...skipping 26 matching lines...) Expand all
182 return state; 201 return state;
183 } 202 }
184 203
185 void SchedulerStateMachine::AsValueInto( 204 void SchedulerStateMachine::AsValueInto(
186 base::trace_event::TracedValue* state) const { 205 base::trace_event::TracedValue* state) const {
187 state->BeginDictionary("major_state"); 206 state->BeginDictionary("major_state");
188 state->SetString("next_action", ActionToString(NextAction())); 207 state->SetString("next_action", ActionToString(NextAction()));
189 state->SetString("begin_impl_frame_state", 208 state->SetString("begin_impl_frame_state",
190 BeginImplFrameStateToString(begin_impl_frame_state_)); 209 BeginImplFrameStateToString(begin_impl_frame_state_));
191 state->SetString("commit_state", CommitStateToString(commit_state_)); 210 state->SetString("commit_state", CommitStateToString(commit_state_));
192 state->SetString("output_surface_state_", 211 state->SetString("prepare_tiles_approach",
212 PrepareTilesApproachToString(prepare_tiles_approach_));
213 state->SetString("prepare_tiles_reason",
214 PrepareTilesReasonToString(prepare_tiles_reason_));
215 state->SetString("output_surface_state",
193 OutputSurfaceStateToString(output_surface_state_)); 216 OutputSurfaceStateToString(output_surface_state_));
194 state->SetString("forced_redraw_state",
195 ForcedRedrawOnTimeoutStateToString(forced_redraw_state_));
196 state->EndDictionary(); 217 state->EndDictionary();
197 218
198 state->BeginDictionary("minor_state"); 219 state->BeginDictionary("minor_state");
199 state->SetInteger("commit_count", commit_count_); 220 state->SetInteger("commit_count", commit_count_);
200 state->SetInteger("current_frame_number", current_frame_number_); 221 state->SetInteger("current_frame_number", current_frame_number_);
201 state->SetInteger("last_frame_number_animate_performed", 222 state->SetInteger("last_frame_number_animate_performed",
202 last_frame_number_animate_performed_); 223 last_frame_number_animate_performed_);
203 state->SetInteger("last_frame_number_swap_performed", 224 state->SetInteger("last_frame_number_swap_performed",
204 last_frame_number_swap_performed_); 225 last_frame_number_swap_performed_);
205 state->SetInteger("last_frame_number_swap_requested", 226 state->SetInteger("last_frame_number_swap_requested",
206 last_frame_number_swap_requested_); 227 last_frame_number_swap_requested_);
207 state->SetInteger("last_frame_number_begin_main_frame_sent", 228 state->SetInteger("last_frame_number_begin_main_frame_sent",
208 last_frame_number_begin_main_frame_sent_); 229 last_frame_number_begin_main_frame_sent_);
209 state->SetBoolean("funnel: animate_funnel", animate_funnel_); 230 state->SetBoolean("funnel: animate_funnel", animate_funnel_);
210 state->SetBoolean("funnel: request_swap_funnel", request_swap_funnel_); 231 state->SetBoolean("funnel: request_swap_funnel", request_swap_funnel_);
211 state->SetBoolean("funnel: send_begin_main_frame_funnel", 232 state->SetBoolean("funnel: send_begin_main_frame_funnel",
212 send_begin_main_frame_funnel_); 233 send_begin_main_frame_funnel_);
213 state->SetInteger("funnel: prepare_tiles_funnel", prepare_tiles_funnel_); 234 state->SetInteger("funnel: prepare_tiles_funnel", prepare_tiles_funnel_);
214 state->SetBoolean("funnel: invalidate_output_surface_funnel", 235 state->SetBoolean("funnel: invalidate_output_surface_funnel",
215 invalidate_output_surface_funnel_); 236 invalidate_output_surface_funnel_);
216 state->SetInteger("consecutive_checkerboard_animations",
217 consecutive_checkerboard_animations_);
218 state->SetInteger("max_pending_swaps_", max_pending_swaps_); 237 state->SetInteger("max_pending_swaps_", max_pending_swaps_);
219 state->SetInteger("pending_swaps_", pending_swaps_); 238 state->SetInteger("pending_swaps_", pending_swaps_);
220 state->SetBoolean("needs_redraw", needs_redraw_); 239 state->SetBoolean("needs_redraw", needs_redraw_);
221 state->SetBoolean("needs_animate_", needs_animate_); 240 state->SetBoolean("needs_animate_", needs_animate_);
222 state->SetBoolean("needs_prepare_tiles", needs_prepare_tiles_);
223 state->SetBoolean("needs_commit", needs_commit_); 241 state->SetBoolean("needs_commit", needs_commit_);
224 state->SetBoolean("visible", visible_); 242 state->SetBoolean("visible", visible_);
225 state->SetBoolean("can_start", can_start_); 243 state->SetBoolean("can_start", can_start_);
226 state->SetBoolean("can_draw", can_draw_); 244 state->SetBoolean("can_draw", can_draw_);
227 state->SetBoolean("has_pending_tree", has_pending_tree_); 245 state->SetBoolean("has_pending_tree", has_pending_tree_);
228 state->SetBoolean("pending_tree_is_ready_for_activation", 246 state->SetBoolean("pending_tree_is_ready_for_activation",
229 pending_tree_is_ready_for_activation_); 247 pending_tree_is_ready_for_activation_);
230 state->SetBoolean("active_tree_needs_first_draw", 248 state->SetBoolean("active_tree_needs_first_draw",
231 active_tree_needs_first_draw_); 249 active_tree_needs_first_draw_);
232 state->SetBoolean("wait_for_active_tree_ready_to_draw", 250 state->SetBoolean("wait_for_active_tree_ready_to_draw",
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
337 355
338 // Do not queue too many swaps. 356 // Do not queue too many swaps.
339 if (pending_swaps_ >= max_pending_swaps_) 357 if (pending_swaps_ >= max_pending_swaps_)
340 return false; 358 return false;
341 359
342 // Except for the cases above, do not draw outside of the BeginImplFrame 360 // Except for the cases above, do not draw outside of the BeginImplFrame
343 // deadline. 361 // deadline.
344 if (begin_impl_frame_state_ != BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE) 362 if (begin_impl_frame_state_ != BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE)
345 return false; 363 return false;
346 364
347 // Only handle forced redraws due to timeouts on the regular deadline.
348 if (forced_redraw_state_ == FORCED_REDRAW_STATE_WAITING_FOR_DRAW)
349 return true;
350
351 return needs_redraw_; 365 return needs_redraw_;
352 } 366 }
353 367
354 bool SchedulerStateMachine::ShouldActivatePendingTree() const { 368 bool SchedulerStateMachine::ShouldActivatePendingTree() const {
355 // There is nothing to activate. 369 // There is nothing to activate.
356 if (!has_pending_tree_) 370 if (!has_pending_tree_)
357 return false; 371 return false;
358 372
359 // We should not activate a second tree before drawing the first one. 373 // We should not activate a second tree before drawing the first one.
360 // Even if we need to force activation of the pending tree, we should abort 374 // Even if we need to force activation of the pending tree, we should abort
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
438 452
439 // We should not send BeginMainFrame while we are in 453 // We should not send BeginMainFrame while we are in
440 // BEGIN_IMPL_FRAME_STATE_IDLE since we might have new 454 // BEGIN_IMPL_FRAME_STATE_IDLE since we might have new
441 // user input arriving soon. 455 // user input arriving soon.
442 // TODO(brianderson): Allow sending BeginMainFrame while idle when the main 456 // TODO(brianderson): Allow sending BeginMainFrame while idle when the main
443 // thread isn't consuming user input. 457 // thread isn't consuming user input.
444 if (begin_impl_frame_state_ == BEGIN_IMPL_FRAME_STATE_IDLE && 458 if (begin_impl_frame_state_ == BEGIN_IMPL_FRAME_STATE_IDLE &&
445 BeginFrameNeeded()) 459 BeginFrameNeeded())
446 return false; 460 return false;
447 461
448 // We need a new commit for the forced redraw. This honors the
449 // single commit per interval because the result will be swapped to screen.
450 // TODO(brianderson): Remove this or move it below the
451 // SendingBeginMainFrameMightCauseDeadlock check since we want to avoid
452 // ever returning true from this method if we might cause deadlock.
453 if (forced_redraw_state_ == FORCED_REDRAW_STATE_WAITING_FOR_COMMIT)
454 return true;
455
456 // We shouldn't normally accept commits if there isn't an OutputSurface. 462 // We shouldn't normally accept commits if there isn't an OutputSurface.
457 if (!HasInitializedOutputSurface()) 463 if (!HasInitializedOutputSurface())
458 return false; 464 return false;
459 465
460 // Make sure the BeginMainFrame can finish eventually if we start it. 466 // Make sure the BeginMainFrame can finish eventually if we start it.
461 if (SendingBeginMainFrameMightCauseDeadlock()) 467 if (SendingBeginMainFrameMightCauseDeadlock())
462 return false; 468 return false;
463 469
464 if (!settings_.main_frame_while_swap_throttled_enabled) { 470 if (!settings_.main_frame_while_swap_throttled_enabled) {
465 // SwapAck throttle the BeginMainFrames unless we just swapped to 471 // SwapAck throttle the BeginMainFrames unless we just swapped to
(...skipping 27 matching lines...) Expand all
493 if (settings_.impl_side_painting) 499 if (settings_.impl_side_painting)
494 return true; 500 return true;
495 501
496 // If we only have an active tree, it is incorrect to replace it 502 // If we only have an active tree, it is incorrect to replace it
497 // before we've drawn it when we aren't impl-side-painting. 503 // before we've drawn it when we aren't impl-side-painting.
498 DCHECK(!settings_.impl_side_painting); 504 DCHECK(!settings_.impl_side_painting);
499 return !active_tree_needs_first_draw_; 505 return !active_tree_needs_first_draw_;
500 } 506 }
501 507
502 bool SchedulerStateMachine::ShouldPrepareTiles() const { 508 bool SchedulerStateMachine::ShouldPrepareTiles() const {
503 // PrepareTiles only really needs to be called immediately after commit 509 // Handle the clear cut cases.
504 // and then periodically after that. Use a funnel to make sure we average 510 switch (prepare_tiles_reason_) {
505 // one PrepareTiles per BeginImplFrame in the long run. 511 case PREPARE_TILES_NOT_NEEDED:
506 if (prepare_tiles_funnel_ > 0) 512 return false;
507 return false; 513 case PREPARE_TILES_NEEDED_FOR_COMMIT:
514 case PREPARE_TILES_NEEDED_FOR_ABORTED_DRAW:
515 case PREPARE_TILES_NEEDED_TO_EVICT_TILES:
516 return true;
517 case PREPARE_TILES_REQUESTED:
518 break;
519 }
508 520
509 // Limiting to once per-frame is not enough, since we only want to 521 switch (prepare_tiles_approach_) {
510 // prepare tiles _after_ draws. 522 case PREPARE_TILES_APPROACH_ACCURATE_ACTIVE_WORK:
511 if (begin_impl_frame_state_ != BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE) 523 return begin_impl_frame_state_ ==
512 return false; 524 BEGIN_IMPL_FRAME_STATE_BEGIN_FRAME_STARTING;
525 case PREPARE_TILES_APPROACH_PRIORITIZE_LATENCY:
526 break;
527 }
513 528
514 return needs_prepare_tiles_; 529 DCHECK_EQ(PREPARE_TILES_APPROACH_PRIORITIZE_LATENCY, prepare_tiles_approach_);
530 DCHECK_EQ(PREPARE_TILES_REQUESTED, prepare_tiles_reason_);
531
532 // Only PrepareTiles after a draw if we haven't already PreparedTiles this
533 // frame. This takes PrepareTiles out of the critical path, but wil make the
534 // NotifyReadyToDraw and NotifyReadyToActivate signals liars.
535 bool did_not_prepare_tiles_at_end_of_frame =
536 prepare_tiles_funnel_ == 0 &&
537 begin_impl_frame_state_ == BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE;
538 return did_not_prepare_tiles_at_end_of_frame;
515 } 539 }
516 540
517 bool SchedulerStateMachine::ShouldInvalidateOutputSurface() const { 541 bool SchedulerStateMachine::ShouldInvalidateOutputSurface() const {
518 // Do not invalidate too many times in a frame. 542 // Do not invalidate too many times in a frame.
519 if (invalidate_output_surface_funnel_) 543 if (invalidate_output_surface_funnel_)
520 return false; 544 return false;
521 545
522 // Only the synchronous compositor requires invalidations. 546 // Only the synchronous compositor requires invalidations.
523 if (!settings_.using_synchronous_renderer_compositor) 547 if (!settings_.using_synchronous_renderer_compositor)
524 return false; 548 return false;
525 549
526 // Invalidations are only performed inside a BeginFrame. 550 // Invalidations are only performed inside a BeginFrame.
527 if (begin_impl_frame_state_ != BEGIN_IMPL_FRAME_STATE_BEGIN_FRAME_STARTING) 551 if (begin_impl_frame_state_ != BEGIN_IMPL_FRAME_STATE_BEGIN_FRAME_STARTING)
528 return false; 552 return false;
529 553
554 // TODO(brianderson): Figure out what to do with this.
530 // TODO(sunnyps): needs_prepare_tiles_ is needed here because PrepareTiles is 555 // TODO(sunnyps): needs_prepare_tiles_ is needed here because PrepareTiles is
531 // called only inside the deadline / draw phase. We could remove this if we 556 // called only inside the deadline / draw phase. We could remove this if we
532 // allowed PrepareTiles to happen in OnBeginImplFrame. 557 // allowed PrepareTiles to happen in OnBeginImplFrame.
533 return needs_redraw_ || needs_prepare_tiles_; 558 return needs_redraw_ || PrepareTilesPending();
534 } 559 }
535 560
536 SchedulerStateMachine::Action SchedulerStateMachine::NextAction() const { 561 SchedulerStateMachine::Action SchedulerStateMachine::NextAction() const {
537 if (ShouldActivatePendingTree()) 562 if (ShouldActivatePendingTree())
538 return ACTION_ACTIVATE_SYNC_TREE; 563 return ACTION_ACTIVATE_SYNC_TREE;
539 if (ShouldCommit()) 564 if (ShouldCommit())
540 return ACTION_COMMIT; 565 return ACTION_COMMIT;
541 if (ShouldAnimate()) 566 if (ShouldAnimate())
542 return ACTION_ANIMATE; 567 return ACTION_ANIMATE;
543 if (ShouldDraw()) { 568 if (ShouldDraw()) {
544 if (PendingDrawsShouldBeAborted()) 569 if (PendingDrawsShouldBeAborted())
545 return ACTION_DRAW_AND_SWAP_ABORT; 570 return ACTION_DRAW_AND_SWAP_ABORT;
546 else if (forced_redraw_state_ == FORCED_REDRAW_STATE_WAITING_FOR_DRAW) 571 else if (requires_high_res_to_draw_ ||
572 prepare_tiles_approach_ ==
573 PREPARE_TILES_APPROACH_PRIORITIZE_LATENCY)
574 return ACTION_DRAW_AND_SWAP_IF_POSSIBLE;
575 else
547 return ACTION_DRAW_AND_SWAP_FORCED; 576 return ACTION_DRAW_AND_SWAP_FORCED;
548 else
549 return ACTION_DRAW_AND_SWAP_IF_POSSIBLE;
550 } 577 }
551 if (ShouldPrepareTiles()) 578 if (ShouldPrepareTiles())
552 return ACTION_PREPARE_TILES; 579 return ACTION_PREPARE_TILES;
553 if (ShouldSendBeginMainFrame()) 580 if (ShouldSendBeginMainFrame())
554 return ACTION_SEND_BEGIN_MAIN_FRAME; 581 return ACTION_SEND_BEGIN_MAIN_FRAME;
555 if (ShouldInvalidateOutputSurface()) 582 if (ShouldInvalidateOutputSurface())
556 return ACTION_INVALIDATE_OUTPUT_SURFACE; 583 return ACTION_INVALIDATE_OUTPUT_SURFACE;
557 if (ShouldBeginOutputSurfaceCreation()) 584 if (ShouldBeginOutputSurfaceCreation())
558 return ACTION_BEGIN_OUTPUT_SURFACE_CREATION; 585 return ACTION_BEGIN_OUTPUT_SURFACE_CREATION;
559 return ACTION_NONE; 586 return ACTION_NONE;
560 } 587 }
561 588
562 void SchedulerStateMachine::UpdateState(Action action) { 589 void SchedulerStateMachine::WillAction(Action action) {
563 switch (action) { 590 switch (action) {
564 case ACTION_NONE: 591 case ACTION_NONE:
565 return; 592 return;
566 593
594 case ACTION_COMMIT:
595 WillCommit();
596 return;
597
567 case ACTION_ACTIVATE_SYNC_TREE: 598 case ACTION_ACTIVATE_SYNC_TREE:
568 UpdateStateOnActivation(); 599 WillActivateSyncTree();
569 return; 600 return;
570 601
571 case ACTION_ANIMATE: 602 case ACTION_ANIMATE:
572 UpdateStateOnAnimate(); 603 WillAnimate();
573 return; 604 return;
574 605
575 case ACTION_SEND_BEGIN_MAIN_FRAME: 606 case ACTION_SEND_BEGIN_MAIN_FRAME:
576 UpdateStateOnSendBeginMainFrame(); 607 WillSendBeginMainFrame();
608 return;
609
610 case ACTION_DRAW_AND_SWAP_FORCED:
611 case ACTION_DRAW_AND_SWAP_IF_POSSIBLE:
612 case ACTION_DRAW_AND_SWAP_ABORT:
613 return;
614
615 case ACTION_BEGIN_OUTPUT_SURFACE_CREATION:
616 WillBeginOutputSurfaceCreation();
617 return;
618
619 case ACTION_PREPARE_TILES:
620 return;
621
622 case ACTION_INVALIDATE_OUTPUT_SURFACE:
623 WillInvalidateOutputSurface();
624 return;
625 }
626 }
627
628 void SchedulerStateMachine::DidAction(Action action) {
629 switch (action) {
630 case ACTION_NONE:
577 return; 631 return;
578 632
579 case ACTION_COMMIT: { 633 case ACTION_COMMIT: {
580 bool commit_has_no_updates = false; 634 bool commit_has_no_updates = false;
581 UpdateStateOnCommit(commit_has_no_updates); 635 DidCommit(commit_has_no_updates);
582 return; 636 return;
583 } 637 }
584 638
639 case ACTION_ACTIVATE_SYNC_TREE:
640 return;
641
642 case ACTION_ANIMATE:
643 return;
644
645 case ACTION_SEND_BEGIN_MAIN_FRAME:
646 return;
647
585 case ACTION_DRAW_AND_SWAP_FORCED: 648 case ACTION_DRAW_AND_SWAP_FORCED:
586 case ACTION_DRAW_AND_SWAP_IF_POSSIBLE: { 649 case ACTION_DRAW_AND_SWAP_IF_POSSIBLE: {
587 bool did_request_swap = true; 650 bool did_request_swap = true;
588 UpdateStateOnDraw(did_request_swap); 651 DidDraw(did_request_swap);
589 return; 652 return;
590 } 653 }
591 654
592 case ACTION_DRAW_AND_SWAP_ABORT: { 655 case ACTION_DRAW_AND_SWAP_ABORT: {
593 bool did_request_swap = false; 656 bool did_request_swap = false;
594 UpdateStateOnDraw(did_request_swap); 657 DidDraw(did_request_swap);
595 return; 658 return;
596 } 659 }
597 660
598 case ACTION_BEGIN_OUTPUT_SURFACE_CREATION: 661 case ACTION_BEGIN_OUTPUT_SURFACE_CREATION:
599 UpdateStateOnBeginOutputSurfaceCreation();
600 return; 662 return;
601 663
602 case ACTION_PREPARE_TILES: 664 case ACTION_PREPARE_TILES:
603 UpdateStateOnPrepareTiles(); 665 DidPrepareTiles();
604 return; 666 return;
605 667
606 case ACTION_INVALIDATE_OUTPUT_SURFACE: 668 case ACTION_INVALIDATE_OUTPUT_SURFACE:
607 UpdateStateOnInvalidateOutputSurface();
608 return; 669 return;
609 } 670 }
610 } 671 }
611 672
612 void SchedulerStateMachine::UpdateStateOnAnimate() { 673 void SchedulerStateMachine::WillAnimate() {
613 DCHECK(!animate_funnel_); 674 DCHECK(!animate_funnel_);
614 last_frame_number_animate_performed_ = current_frame_number_; 675 last_frame_number_animate_performed_ = current_frame_number_;
615 animate_funnel_ = true; 676 animate_funnel_ = true;
616 needs_animate_ = false; 677 needs_animate_ = false;
617 // TODO(skyostil): Instead of assuming this, require the client to tell us. 678 // TODO(skyostil): Instead of assuming this, require the client to tell us.
618 SetNeedsRedraw(); 679 SetNeedsRedraw();
619 } 680 }
620 681
621 void SchedulerStateMachine::UpdateStateOnSendBeginMainFrame() { 682 void SchedulerStateMachine::WillSendBeginMainFrame() {
622 DCHECK(!has_pending_tree_ || settings_.main_frame_before_activation_enabled); 683 DCHECK(!has_pending_tree_ || settings_.main_frame_before_activation_enabled);
623 DCHECK(visible_); 684 DCHECK(visible_);
624 DCHECK(!send_begin_main_frame_funnel_); 685 DCHECK(!send_begin_main_frame_funnel_);
625 commit_state_ = COMMIT_STATE_BEGIN_MAIN_FRAME_SENT; 686 commit_state_ = COMMIT_STATE_BEGIN_MAIN_FRAME_SENT;
626 needs_commit_ = false; 687 needs_commit_ = false;
627 send_begin_main_frame_funnel_ = true; 688 send_begin_main_frame_funnel_ = true;
628 last_frame_number_begin_main_frame_sent_ = current_frame_number_; 689 last_frame_number_begin_main_frame_sent_ = current_frame_number_;
629 } 690 }
630 691
631 void SchedulerStateMachine::UpdateStateOnCommit(bool commit_has_no_updates) { 692 void SchedulerStateMachine::WillCommit() {
693 // The commit may set this synchronously if the new pending tree is
694 // ready for activation immediately.
695 pending_tree_is_ready_for_activation_ = false;
696 }
697
698 void SchedulerStateMachine::DidCommit(bool commit_has_no_updates) {
632 commit_count_++; 699 commit_count_++;
633 700
634 // Animate after commit even if we've already animated. 701 // Animate after commit even if we've already animated.
635 if (!commit_has_no_updates) 702 if (!commit_has_no_updates)
636 animate_funnel_ = false; 703 animate_funnel_ = false;
637 704
638 if (commit_has_no_updates || settings_.main_frame_before_activation_enabled) { 705 if (commit_has_no_updates || settings_.main_frame_before_activation_enabled) {
639 commit_state_ = COMMIT_STATE_IDLE; 706 commit_state_ = COMMIT_STATE_IDLE;
640 } else if (settings_.impl_side_painting) { 707 } else if (settings_.impl_side_painting) {
641 commit_state_ = COMMIT_STATE_WAITING_FOR_ACTIVATION; 708 commit_state_ = COMMIT_STATE_WAITING_FOR_ACTIVATION;
642 } else { 709 } else {
643 commit_state_ = settings_.main_thread_should_always_be_low_latency 710 commit_state_ = settings_.main_thread_should_always_be_low_latency
644 ? COMMIT_STATE_WAITING_FOR_DRAW 711 ? COMMIT_STATE_WAITING_FOR_DRAW
645 : COMMIT_STATE_IDLE; 712 : COMMIT_STATE_IDLE;
646 } 713 }
647 714
648 // If we are impl-side-painting but the commit was aborted, then we behave 715 // If we are impl-side-painting but the commit was aborted, then we behave
649 // mostly as if we are not impl-side-painting since there is no pending tree. 716 // mostly as if we are not impl-side-painting since there is no pending tree.
650 has_pending_tree_ = settings_.impl_side_painting && !commit_has_no_updates; 717 has_pending_tree_ = settings_.impl_side_painting && !commit_has_no_updates;
651 718
652 // Update state related to forced draws.
653 if (forced_redraw_state_ == FORCED_REDRAW_STATE_WAITING_FOR_COMMIT) {
654 forced_redraw_state_ = has_pending_tree_
655 ? FORCED_REDRAW_STATE_WAITING_FOR_ACTIVATION
656 : FORCED_REDRAW_STATE_WAITING_FOR_DRAW;
657 }
658
659 // Update the output surface state. 719 // Update the output surface state.
660 DCHECK_NE(output_surface_state_, OUTPUT_SURFACE_WAITING_FOR_FIRST_ACTIVATION); 720 DCHECK_NE(output_surface_state_, OUTPUT_SURFACE_WAITING_FOR_FIRST_ACTIVATION);
661 if (output_surface_state_ == OUTPUT_SURFACE_WAITING_FOR_FIRST_COMMIT) { 721 if (output_surface_state_ == OUTPUT_SURFACE_WAITING_FOR_FIRST_COMMIT) {
662 if (has_pending_tree_) { 722 if (has_pending_tree_) {
663 output_surface_state_ = OUTPUT_SURFACE_WAITING_FOR_FIRST_ACTIVATION; 723 output_surface_state_ = OUTPUT_SURFACE_WAITING_FOR_FIRST_ACTIVATION;
664 } else { 724 } else {
665 output_surface_state_ = OUTPUT_SURFACE_ACTIVE; 725 output_surface_state_ = OUTPUT_SURFACE_ACTIVE;
666 needs_redraw_ = true; 726 needs_redraw_ = true;
667 } 727 }
668 } 728 }
669 729
670 // Update state if we have a new active tree to draw, or if the active tree 730 // Update state if we have a new active tree to draw.
671 // was unchanged but we need to do a forced draw. 731 if (!has_pending_tree_) {
672 if (!has_pending_tree_ &&
673 (!commit_has_no_updates ||
674 forced_redraw_state_ == FORCED_REDRAW_STATE_WAITING_FOR_DRAW)) {
675 needs_redraw_ = true; 732 needs_redraw_ = true;
676 active_tree_needs_first_draw_ = true; 733 active_tree_needs_first_draw_ = true;
677 } 734 }
678 735
679 // This post-commit work is common to both completed and aborted commits. 736 // This post-commit work is common to both completed and aborted commits.
680 pending_tree_is_ready_for_activation_ = false;
681
682 if (continuous_painting_) 737 if (continuous_painting_)
683 needs_commit_ = true; 738 needs_commit_ = true;
684 last_commit_had_no_updates_ = commit_has_no_updates; 739 last_commit_had_no_updates_ = commit_has_no_updates;
685 } 740 }
686 741
687 void SchedulerStateMachine::UpdateStateOnActivation() { 742 void SchedulerStateMachine::WillActivateSyncTree() {
688 if (commit_state_ == COMMIT_STATE_WAITING_FOR_ACTIVATION) { 743 if (commit_state_ == COMMIT_STATE_WAITING_FOR_ACTIVATION) {
689 commit_state_ = settings_.main_thread_should_always_be_low_latency 744 commit_state_ = settings_.main_thread_should_always_be_low_latency
690 ? COMMIT_STATE_WAITING_FOR_DRAW 745 ? COMMIT_STATE_WAITING_FOR_DRAW
691 : COMMIT_STATE_IDLE; 746 : COMMIT_STATE_IDLE;
692 } 747 }
693 748
694 if (output_surface_state_ == OUTPUT_SURFACE_WAITING_FOR_FIRST_ACTIVATION) 749 if (output_surface_state_ == OUTPUT_SURFACE_WAITING_FOR_FIRST_ACTIVATION)
695 output_surface_state_ = OUTPUT_SURFACE_ACTIVE; 750 output_surface_state_ = OUTPUT_SURFACE_ACTIVE;
696 751
697 if (forced_redraw_state_ == FORCED_REDRAW_STATE_WAITING_FOR_ACTIVATION)
698 forced_redraw_state_ = FORCED_REDRAW_STATE_WAITING_FOR_DRAW;
699
700 has_pending_tree_ = false; 752 has_pending_tree_ = false;
701 pending_tree_is_ready_for_activation_ = false; 753 pending_tree_is_ready_for_activation_ = false;
702 active_tree_needs_first_draw_ = true; 754 active_tree_needs_first_draw_ = true;
703 needs_redraw_ = true; 755 needs_redraw_ = true;
704 } 756 }
705 757
706 void SchedulerStateMachine::UpdateStateOnDraw(bool did_request_swap) { 758 void SchedulerStateMachine::DidDraw(bool did_request_swap) {
707 if (forced_redraw_state_ == FORCED_REDRAW_STATE_WAITING_FOR_DRAW)
708 forced_redraw_state_ = FORCED_REDRAW_STATE_IDLE;
709
710 if (commit_state_ == COMMIT_STATE_WAITING_FOR_DRAW) 759 if (commit_state_ == COMMIT_STATE_WAITING_FOR_DRAW)
711 commit_state_ = COMMIT_STATE_IDLE; 760 commit_state_ = COMMIT_STATE_IDLE;
712 761
713 needs_redraw_ = false; 762 needs_redraw_ = false;
714 active_tree_needs_first_draw_ = false; 763 active_tree_needs_first_draw_ = false;
715 764
716 if (did_request_swap) { 765 if (did_request_swap) {
717 DCHECK(!request_swap_funnel_); 766 DCHECK(!request_swap_funnel_);
718 request_swap_funnel_ = true; 767 request_swap_funnel_ = true;
719 did_request_swap_in_last_frame_ = true; 768 did_request_swap_in_last_frame_ = true;
720 last_frame_number_swap_requested_ = current_frame_number_; 769 last_frame_number_swap_requested_ = current_frame_number_;
721 } 770 }
771
772 switch (last_draw_result_) {
773 case INVALID_RESULT:
774 NOTREACHED() << "Uninitialized DrawResult.";
775 break;
776
777 case DRAW_ABORTED_CANT_DRAW:
778 case DRAW_ABORTED_CONTEXT_LOST:
779 NOTREACHED() << "Invalid return value from DrawAndSwapIfPossible:"
780 << last_draw_result_;
781 break;
782
783 case DRAW_SUCCESS:
784 break;
785
786 case DRAW_ABORTED_MISSING_RASTER_OUTPUT_HIGH_RES:
787 case DRAW_ABORTED_MISSING_RASTER_OUTPUT_ANY_RES:
788 prepare_tiles_reason_ = PREPARE_TILES_NEEDED_FOR_ABORTED_DRAW;
789 if (prepare_tiles_approach_ ==
790 PREPARE_TILES_APPROACH_PRIORITIZE_LATENCY) {
791 prepare_tiles_approach_ = PREPARE_TILES_APPROACH_ACCURATE_ACTIVE_WORK;
792 }
793 retry_begin_impl_frame_deadline_ = true;
794 needs_redraw_ = true;
795 break;
796
797 case DRAW_ABORTED_MISSING_RASTER_SOURCE:
798 prepare_tiles_reason_ = PREPARE_TILES_NEEDED_FOR_ABORTED_DRAW;
799 if (prepare_tiles_approach_ ==
800 PREPARE_TILES_APPROACH_PRIORITIZE_LATENCY) {
801 prepare_tiles_approach_ = PREPARE_TILES_APPROACH_ACCURATE_ACTIVE_WORK;
802 }
803
804 if (CommitPending() || has_pending_tree_) {
805 // The new active tree in flight might have an updated raster source,
806 // so wait and see.
807 retry_begin_impl_frame_deadline_ = true;
808 } else {
809 // We need a new active tree to get an updated raster source.
810 needs_commit_ = true;
811 retry_begin_impl_frame_ = true;
812 }
813
814 // This is one of the few cases where we actively avoid drawing a commit.
815 // Skipping draw of the commit can be better than a flash of checkerboard.
816 active_tree_needs_first_draw_ = false;
817 break;
818 }
722 } 819 }
723 820
724 void SchedulerStateMachine::UpdateStateOnPrepareTiles() { 821 void SchedulerStateMachine::DidPrepareTiles() {
725 needs_prepare_tiles_ = false; 822 prepare_tiles_reason_ = PREPARE_TILES_NOT_NEEDED;
823
824 active_tree_ready_to_draw_ = false;
825
826 if (prepare_tiles_approach_ == PREPARE_TILES_APPROACH_PRIORITIZE_LATENCY)
827 prepare_tiles_funnel_++;
828 else
829 prepare_tiles_funnel_ = 0;
726 } 830 }
727 831
728 void SchedulerStateMachine::UpdateStateOnBeginOutputSurfaceCreation() { 832 void SchedulerStateMachine::WillBeginOutputSurfaceCreation() {
729 DCHECK_EQ(output_surface_state_, OUTPUT_SURFACE_LOST); 833 DCHECK_EQ(output_surface_state_, OUTPUT_SURFACE_LOST);
730 output_surface_state_ = OUTPUT_SURFACE_CREATING; 834 output_surface_state_ = OUTPUT_SURFACE_CREATING;
731 835
732 // The following DCHECKs make sure we are in the proper quiescent state. 836 // The following DCHECKs make sure we are in the proper quiescent state.
733 // The pipeline should be flushed entirely before we start output 837 // The pipeline should be flushed entirely before we start output
734 // surface creation to avoid complicated corner cases. 838 // surface creation to avoid complicated corner cases.
735 DCHECK_EQ(commit_state_, COMMIT_STATE_IDLE); 839 DCHECK_EQ(commit_state_, COMMIT_STATE_IDLE);
736 DCHECK(!has_pending_tree_); 840 DCHECK(!has_pending_tree_);
737 DCHECK(!active_tree_needs_first_draw_); 841 DCHECK(!active_tree_needs_first_draw_);
738 } 842 }
739 843
740 void SchedulerStateMachine::UpdateStateOnInvalidateOutputSurface() { 844 void SchedulerStateMachine::WillInvalidateOutputSurface() {
741 DCHECK(!invalidate_output_surface_funnel_); 845 DCHECK(!invalidate_output_surface_funnel_);
742 invalidate_output_surface_funnel_ = true; 846 invalidate_output_surface_funnel_ = true;
743 last_frame_number_invalidate_output_surface_performed_ = 847 last_frame_number_invalidate_output_surface_performed_ =
744 current_frame_number_; 848 current_frame_number_;
745 849
746 // The synchronous compositor makes no guarantees about a draw coming in after 850 // The synchronous compositor makes no guarantees about a draw coming in after
747 // an invalidate so clear any flags that would cause the compositor's pipeline 851 // an invalidate so clear any flags that would cause the compositor's pipeline
748 // to stall. 852 // to stall.
749 active_tree_needs_first_draw_ = false; // blocks commit if true 853 active_tree_needs_first_draw_ = false; // blocks commit if true
750 } 854 }
(...skipping 29 matching lines...) Expand all
780 void SchedulerStateMachine::SetChildrenNeedBeginFrames( 884 void SchedulerStateMachine::SetChildrenNeedBeginFrames(
781 bool children_need_begin_frames) { 885 bool children_need_begin_frames) {
782 children_need_begin_frames_ = children_need_begin_frames; 886 children_need_begin_frames_ = children_need_begin_frames;
783 } 887 }
784 888
785 void SchedulerStateMachine::SetVideoNeedsBeginFrames( 889 void SchedulerStateMachine::SetVideoNeedsBeginFrames(
786 bool video_needs_begin_frames) { 890 bool video_needs_begin_frames) {
787 video_needs_begin_frames_ = video_needs_begin_frames; 891 video_needs_begin_frames_ = video_needs_begin_frames;
788 } 892 }
789 893
894 void SchedulerStateMachine::NotifyBeginFrameSourceActive(bool active) {
895 // Upon becoming inactive, switch back to prioritizing latency.
896 if (!active &&
897 prepare_tiles_approach_ == PREPARE_TILES_APPROACH_ACCURATE_ACTIVE_WORK)
898 prepare_tiles_approach_ = PREPARE_TILES_APPROACH_PRIORITIZE_LATENCY;
899 }
900
790 void SchedulerStateMachine::SetDeferCommits(bool defer_commits) { 901 void SchedulerStateMachine::SetDeferCommits(bool defer_commits) {
791 defer_commits_ = defer_commits; 902 defer_commits_ = defer_commits;
792 } 903 }
793 904
794 // These are the cases where we require a BeginFrame message to make progress 905 // These are the cases where we require a BeginFrame message to make progress
795 // on requested actions. 906 // on requested actions.
796 bool SchedulerStateMachine::BeginFrameRequiredForAction() const { 907 bool SchedulerStateMachine::BeginFrameRequiredForAction() const {
797 // The forced draw respects our normal draw scheduling, so we need to
798 // request a BeginImplFrame for it.
799 if (forced_redraw_state_ == FORCED_REDRAW_STATE_WAITING_FOR_DRAW)
800 return true;
801
802 return needs_animate_ || needs_redraw_ || (needs_commit_ && !defer_commits_); 908 return needs_animate_ || needs_redraw_ || (needs_commit_ && !defer_commits_);
803 } 909 }
804 910
805 // These are cases where we are very likely want a BeginFrame message in the 911 // These are cases where we are very likely want a BeginFrame message in the
806 // near future. Proactively requesting the BeginImplFrame helps hide the round 912 // near future. Proactively requesting the BeginImplFrame helps hide the round
807 // trip latency of the SetNeedsBeginFrame request that has to go to the 913 // trip latency of the SetNeedsBeginFrame request that has to go to the
808 // Browser. 914 // Browser.
809 // This includes things like drawing soon, but might not actually have a new 915 // This includes things like drawing soon, but might not actually have a new
810 // frame to draw when we receive the next BeginImplFrame. 916 // frame to draw when we receive the next BeginImplFrame.
811 bool SchedulerStateMachine::ProactiveBeginFrameWanted() const { 917 bool SchedulerStateMachine::ProactiveBeginFrameWanted() const {
812 // Do not be proactive when invisible. 918 // Do not be proactive when invisible.
813 if (!visible_) 919 if (!visible_)
814 return false; 920 return false;
815 921
816 // We should proactively request a BeginImplFrame if a commit is pending 922 // We should proactively request a BeginImplFrame if a commit is pending
817 // because we will want to draw if the commit completes quickly. Do not 923 // because we will want to draw if the commit completes quickly. Do not
818 // request frames when commits are disabled, because the frame requests will 924 // request frames when commits are disabled, because the frame requests will
819 // not provide the needed commit (and will wake up the process when it could 925 // not provide the needed commit (and will wake up the process when it could
820 // stay idle). 926 // stay idle).
821 if ((commit_state_ != COMMIT_STATE_IDLE) && !defer_commits_) 927 if ((commit_state_ != COMMIT_STATE_IDLE) && !defer_commits_)
822 return true; 928 return true;
823 929
824 // If the pending tree activates quickly, we'll want a BeginImplFrame soon 930 // If the pending tree activates quickly, we'll want a BeginImplFrame soon
825 // to draw the new active tree. 931 // to draw the new active tree.
826 if (has_pending_tree_) 932 if (has_pending_tree_)
827 return true; 933 return true;
828 934
829 // Changing priorities may allow us to activate (given the new priorities), 935 // Changing priorities may allow us to activate (given the new priorities),
830 // which may result in a new frame. 936 // which may result in a new frame.
831 if (needs_prepare_tiles_) 937 if (PrepareTilesPending())
832 return true; 938 return true;
833 939
834 // If we just sent a swap request, it's likely that we are going to produce 940 // If we just sent a swap request, it's likely that we are going to produce
835 // another frame soon. This helps avoid negative glitches in our 941 // another frame soon. This helps avoid negative glitches in our
836 // SetNeedsBeginFrame requests, which may propagate to the BeginImplFrame 942 // SetNeedsBeginFrame requests, which may propagate to the BeginImplFrame
837 // provider and get sampled at an inopportune time, delaying the next 943 // provider and get sampled at an inopportune time, delaying the next
838 // BeginImplFrame. 944 // BeginImplFrame.
839 if (did_request_swap_in_last_frame_) 945 if (did_request_swap_in_last_frame_)
840 return true; 946 return true;
841 947
842 // If the last commit was aborted because of early out (no updates), we should 948 // If the last commit was aborted because of early out (no updates), we should
843 // still want a begin frame in case there is a commit coming again. 949 // still want a begin frame in case there is a commit coming again.
844 if (last_commit_had_no_updates_) 950 if (last_commit_had_no_updates_)
845 return true; 951 return true;
846 952
847 return false; 953 return false;
848 } 954 }
849 955
850 void SchedulerStateMachine::OnBeginImplFrame() { 956 void SchedulerStateMachine::OnBeginImplFrame() {
851 begin_impl_frame_state_ = BEGIN_IMPL_FRAME_STATE_BEGIN_FRAME_STARTING; 957 begin_impl_frame_state_ = BEGIN_IMPL_FRAME_STATE_BEGIN_FRAME_STARTING;
852 current_frame_number_++; 958 current_frame_number_++;
853 959
960 retry_begin_impl_frame_ = false;
961 retry_begin_impl_frame_deadline_ = false;
962
854 last_commit_had_no_updates_ = false; 963 last_commit_had_no_updates_ = false;
855 did_request_swap_in_last_frame_ = false; 964 did_request_swap_in_last_frame_ = false;
856 965
857 // Clear funnels for any actions we perform during the frame. 966 // Clear funnels for any actions we perform during the frame.
858 animate_funnel_ = false; 967 animate_funnel_ = false;
859 send_begin_main_frame_funnel_ = false; 968 send_begin_main_frame_funnel_ = false;
860 invalidate_output_surface_funnel_ = false; 969 invalidate_output_surface_funnel_ = false;
861 970
862 // "Drain" the PrepareTiles funnel. 971 // "Drain" the PrepareTiles funnel.
863 if (prepare_tiles_funnel_ > 0) 972 if (prepare_tiles_funnel_ > 0)
864 prepare_tiles_funnel_--; 973 prepare_tiles_funnel_--;
865 974
975 // PREPARE_TILES_APPROACH_ACCURATE_ACTIVE_WORK doesn't work well in
976 // main thread low-latency mode. Transition back to
977 // PREPARE_TILES_APPROACH_PRIORITIZE_LATENCY if we just recovered
978 // main-thread latency.
979 if (skip_begin_main_frame_to_reduce_latency_ &&
980 prepare_tiles_approach_ == PREPARE_TILES_APPROACH_ACCURATE_ACTIVE_WORK) {
981 prepare_tiles_approach_ = PREPARE_TILES_APPROACH_PRIORITIZE_LATENCY;
982 }
983
866 skip_begin_main_frame_to_reduce_latency_ = 984 skip_begin_main_frame_to_reduce_latency_ =
867 skip_next_begin_main_frame_to_reduce_latency_; 985 skip_next_begin_main_frame_to_reduce_latency_;
868 skip_next_begin_main_frame_to_reduce_latency_ = false; 986 skip_next_begin_main_frame_to_reduce_latency_ = false;
869 } 987 }
870 988
871 void SchedulerStateMachine::OnBeginImplFrameDeadlinePending() { 989 void SchedulerStateMachine::OnBeginImplFrameDeadlinePending() {
872 begin_impl_frame_state_ = BEGIN_IMPL_FRAME_STATE_INSIDE_BEGIN_FRAME; 990 begin_impl_frame_state_ = BEGIN_IMPL_FRAME_STATE_INSIDE_BEGIN_FRAME;
873 } 991 }
874 992
875 void SchedulerStateMachine::OnBeginImplFrameDeadline() { 993 void SchedulerStateMachine::OnBeginImplFrameDeadline() {
(...skipping 13 matching lines...) Expand all
889 SchedulerStateMachine::CurrentBeginImplFrameDeadlineMode() const { 1007 SchedulerStateMachine::CurrentBeginImplFrameDeadlineMode() const {
890 if (settings_.using_synchronous_renderer_compositor) { 1008 if (settings_.using_synchronous_renderer_compositor) {
891 // No deadline for synchronous compositor. 1009 // No deadline for synchronous compositor.
892 return BEGIN_IMPL_FRAME_DEADLINE_MODE_NONE; 1010 return BEGIN_IMPL_FRAME_DEADLINE_MODE_NONE;
893 } else if (wait_for_active_tree_ready_to_draw_) { 1011 } else if (wait_for_active_tree_ready_to_draw_) {
894 // When we are waiting for ready to draw signal, we do not wait to post a 1012 // When we are waiting for ready to draw signal, we do not wait to post a
895 // deadline yet. 1013 // deadline yet.
896 return BEGIN_IMPL_FRAME_DEADLINE_MODE_BLOCKED_ON_READY_TO_DRAW; 1014 return BEGIN_IMPL_FRAME_DEADLINE_MODE_BLOCKED_ON_READY_TO_DRAW;
897 } else if (ShouldTriggerBeginImplFrameDeadlineImmediately()) { 1015 } else if (ShouldTriggerBeginImplFrameDeadlineImmediately()) {
898 return BEGIN_IMPL_FRAME_DEADLINE_MODE_IMMEDIATE; 1016 return BEGIN_IMPL_FRAME_DEADLINE_MODE_IMMEDIATE;
899 } else if (needs_redraw_ && pending_swaps_ < max_pending_swaps_) {
900 // We have an animation or fast input path on the impl thread that wants
901 // to draw, so don't wait too long for a new active tree.
902 // If we are swap throttled we should wait until we are unblocked.
903 return BEGIN_IMPL_FRAME_DEADLINE_MODE_REGULAR;
904 } else {
905 // The impl thread doesn't have anything it wants to draw and we are just
906 // waiting for a new active tree or we are swap throttled. In short we are
907 // blocked.
908 return BEGIN_IMPL_FRAME_DEADLINE_MODE_LATE;
909 } 1017 }
1018
1019 if (prepare_tiles_approach_ == PREPARE_TILES_APPROACH_PRIORITIZE_LATENCY) {
1020 if (needs_redraw_ && pending_swaps_ < max_pending_swaps_) {
1021 // We have an animation or fast input path on the impl thread that wants
1022 // to draw, so don't wait too long for a new active tree.
1023 // If we are swap throttled we should wait until we are unblocked.
1024 return BEGIN_IMPL_FRAME_DEADLINE_MODE_REGULAR;
1025 } else {
1026 // The impl thread doesn't have anything it wants to draw and we are just
1027 // waiting for a new active tree or we are swap throttled. In short we are
1028 // blocked.
1029 return BEGIN_IMPL_FRAME_DEADLINE_MODE_LATE;
1030 }
1031 }
1032
1033 return BEGIN_IMPL_FRAME_DEADLINE_MODE_TRY_TO_AVOID_CHECKERBOARD;
910 } 1034 }
911 1035
912 bool SchedulerStateMachine::ShouldTriggerBeginImplFrameDeadlineImmediately() 1036 bool SchedulerStateMachine::ShouldTriggerBeginImplFrameDeadlineImmediately()
913 const { 1037 const {
914 // TODO(brianderson): This should take into account multiple commit sources. 1038 // TODO(brianderson): This should take into account multiple commit sources.
915 if (begin_impl_frame_state_ != BEGIN_IMPL_FRAME_STATE_INSIDE_BEGIN_FRAME) 1039 if (begin_impl_frame_state_ != BEGIN_IMPL_FRAME_STATE_INSIDE_BEGIN_FRAME)
916 return false; 1040 return false;
917 1041
918 // If we just forced activation, we should end the deadline right now. 1042 // If we just forced activation, we should end the deadline right now.
919 if (PendingActivationsShouldBeForced() && !has_pending_tree_) 1043 if (PendingActivationsShouldBeForced() && !has_pending_tree_)
920 return true; 1044 return true;
921 1045
922 // SwapAck throttle the deadline since we wont draw and swap anyway. 1046 // SwapAck throttle the deadline since we wont draw and swap anyway.
923 if (pending_swaps_ >= max_pending_swaps_) 1047 if (pending_swaps_ >= max_pending_swaps_)
924 return false; 1048 return false;
925 1049
1050 // PREPARE_TILES_APPROACH_PRIORITIZE_LATENCY is the only approach
1051 // where we want to trigger the deadline before NotifyReadyToDraw.
1052 if (prepare_tiles_approach_ != PREPARE_TILES_APPROACH_PRIORITIZE_LATENCY)
1053 return active_tree_ready_to_draw_;
1054
926 if (active_tree_needs_first_draw_) 1055 if (active_tree_needs_first_draw_)
927 return true; 1056 return true;
928 1057
929 if (!needs_redraw_) 1058 if (!needs_redraw_)
930 return false; 1059 return false;
931 1060
932 // This is used to prioritize impl-thread draws when the main thread isn't 1061 // This is used to prioritize impl-thread draws when the main thread isn't
933 // producing anything, e.g., after an aborted commit. We also check that we 1062 // producing anything, e.g., after an aborted commit. We also check that we
934 // don't have a pending tree -- otherwise we should give it a chance to 1063 // don't have a pending tree -- otherwise we should give it a chance to
935 // activate. 1064 // activate.
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
978 // which case the main thread is in a high latency mode. 1107 // which case the main thread is in a high latency mode.
979 return (active_tree_needs_first_draw_ || did_perform_swap_in_last_draw_) && 1108 return (active_tree_needs_first_draw_ || did_perform_swap_in_last_draw_) &&
980 !send_begin_main_frame_funnel_; 1109 !send_begin_main_frame_funnel_;
981 } 1110 }
982 1111
983 // If the active tree needs its first draw in any other state, we know the 1112 // If the active tree needs its first draw in any other state, we know the
984 // main thread is in a high latency mode. 1113 // main thread is in a high latency mode.
985 return active_tree_needs_first_draw_; 1114 return active_tree_needs_first_draw_;
986 } 1115 }
987 1116
988 void SchedulerStateMachine::SetVisible(bool visible) { visible_ = visible; } 1117 void SchedulerStateMachine::SetVisible(bool visible) {
1118 visible_ = visible;
1119 if (!visible)
1120 prepare_tiles_reason_ = PREPARE_TILES_NEEDED_TO_EVICT_TILES;
1121 }
989 1122
990 void SchedulerStateMachine::SetCanDraw(bool can_draw) { can_draw_ = can_draw; } 1123 void SchedulerStateMachine::SetCanDraw(bool can_draw) { can_draw_ = can_draw; }
991 1124
992 void SchedulerStateMachine::SetNeedsRedraw() { needs_redraw_ = true; } 1125 void SchedulerStateMachine::SetNeedsRedraw() { needs_redraw_ = true; }
993 1126
994 void SchedulerStateMachine::SetNeedsAnimate() { 1127 void SchedulerStateMachine::SetNeedsAnimate() {
995 needs_animate_ = true; 1128 needs_animate_ = true;
996 } 1129 }
997 1130
998 void SchedulerStateMachine::SetWaitForReadyToDraw() { 1131 void SchedulerStateMachine::SetWaitForReadyToDraw() {
999 DCHECK(settings_.impl_side_painting); 1132 DCHECK(settings_.impl_side_painting);
1000 wait_for_active_tree_ready_to_draw_ = true; 1133 wait_for_active_tree_ready_to_draw_ = true;
1001 } 1134 }
1002 1135
1003 void SchedulerStateMachine::SetNeedsPrepareTiles() { 1136 void SchedulerStateMachine::SetNeedsPrepareTiles(bool for_commit) {
1004 if (!needs_prepare_tiles_) { 1137 TRACE_EVENT0("cc", "SchedulerStateMachine::SetNeedsPrepareTiles");
1005 TRACE_EVENT0("cc", "SchedulerStateMachine::SetNeedsPrepareTiles"); 1138 switch (prepare_tiles_approach_) {
1006 needs_prepare_tiles_ = true; 1139 case PREPARE_TILES_APPROACH_PRIORITIZE_LATENCY:
1140 if (for_commit)
1141 prepare_tiles_reason_ = PREPARE_TILES_NEEDED_FOR_COMMIT;
1142 else if (prepare_tiles_reason_ == PREPARE_TILES_NOT_NEEDED)
1143 prepare_tiles_reason_ = PREPARE_TILES_REQUESTED;
1144 break;
1145
1146 case PREPARE_TILES_APPROACH_ACCURATE_ACTIVE_WORK:
1147 // We don't uncondititionally PrepareTiles immediately after a commit with
1148 // this approach.
1149 if (prepare_tiles_reason_ == PREPARE_TILES_NOT_NEEDED)
1150 prepare_tiles_reason_ = PREPARE_TILES_REQUESTED;
1151 break;
1007 } 1152 }
1008 } 1153 }
1009 1154
1010 void SchedulerStateMachine::SetMaxSwapsPending(int max) { 1155 void SchedulerStateMachine::SetMaxSwapsPending(int max) {
1011 max_pending_swaps_ = max; 1156 max_pending_swaps_ = max;
1012 } 1157 }
1013 1158
1014 void SchedulerStateMachine::DidSwapBuffers() { 1159 void SchedulerStateMachine::DidSwapBuffers() {
1015 pending_swaps_++; 1160 pending_swaps_++;
1016 DCHECK_LE(pending_swaps_, max_pending_swaps_); 1161 DCHECK_LE(pending_swaps_, max_pending_swaps_);
1017 1162
1018 did_perform_swap_in_last_draw_ = true; 1163 did_perform_swap_in_last_draw_ = true;
1019 last_frame_number_swap_performed_ = current_frame_number_; 1164 last_frame_number_swap_performed_ = current_frame_number_;
1020 } 1165 }
1021 1166
1022 void SchedulerStateMachine::DidSwapBuffersComplete() { 1167 void SchedulerStateMachine::DidSwapBuffersComplete() {
1023 DCHECK_GT(pending_swaps_, 0); 1168 DCHECK_GT(pending_swaps_, 0);
1024 pending_swaps_--; 1169 pending_swaps_--;
1025 } 1170 }
1026 1171
1027 void SchedulerStateMachine::SetImplLatencyTakesPriority( 1172 void SchedulerStateMachine::SetImplLatencyTakesPriority(
1028 bool impl_latency_takes_priority) { 1173 bool impl_latency_takes_priority) {
1029 impl_latency_takes_priority_ = impl_latency_takes_priority; 1174 impl_latency_takes_priority_ = impl_latency_takes_priority;
1030 } 1175 }
1031 1176
1032 void SchedulerStateMachine::DidDrawIfPossibleCompleted(DrawResult result) { 1177 void SchedulerStateMachine::SetDrawResult(DrawResult result) {
1033 switch (result) { 1178 last_draw_result_ = result;
1034 case INVALID_RESULT:
1035 NOTREACHED() << "Uninitialized DrawResult.";
1036 break;
1037 case DRAW_ABORTED_CANT_DRAW:
1038 case DRAW_ABORTED_CONTEXT_LOST:
1039 NOTREACHED() << "Invalid return value from DrawAndSwapIfPossible:"
1040 << result;
1041 break;
1042 case DRAW_SUCCESS:
1043 consecutive_checkerboard_animations_ = 0;
1044 forced_redraw_state_ = FORCED_REDRAW_STATE_IDLE;
1045 break;
1046 case DRAW_ABORTED_CHECKERBOARD_ANIMATIONS:
1047 needs_redraw_ = true;
1048
1049 // If we're already in the middle of a redraw, we don't need to
1050 // restart it.
1051 if (forced_redraw_state_ != FORCED_REDRAW_STATE_IDLE)
1052 return;
1053
1054 needs_commit_ = true;
1055 consecutive_checkerboard_animations_++;
1056 if (settings_.timeout_and_draw_when_animation_checkerboards &&
1057 consecutive_checkerboard_animations_ >=
1058 settings_.maximum_number_of_failed_draws_before_draw_is_forced_) {
1059 consecutive_checkerboard_animations_ = 0;
1060 // We need to force a draw, but it doesn't make sense to do this until
1061 // we've committed and have new textures.
1062 forced_redraw_state_ = FORCED_REDRAW_STATE_WAITING_FOR_COMMIT;
1063 }
1064 break;
1065 case DRAW_ABORTED_MISSING_HIGH_RES_CONTENT:
1066 // It's not clear whether this missing content is because of missing
1067 // pictures (which requires a commit) or because of memory pressure
1068 // removing textures (which might not). To be safe, request a commit
1069 // anyway.
1070 needs_commit_ = true;
1071 break;
1072 }
1073 } 1179 }
1074 1180
1075 void SchedulerStateMachine::SetNeedsCommit() { 1181 void SchedulerStateMachine::SetNeedsCommit() {
1076 needs_commit_ = true; 1182 needs_commit_ = true;
1077 } 1183 }
1078 1184
1079 void SchedulerStateMachine::NotifyReadyToCommit() { 1185 void SchedulerStateMachine::NotifyReadyToCommit() {
1080 DCHECK(commit_state_ == COMMIT_STATE_BEGIN_MAIN_FRAME_STARTED) 1186 DCHECK(commit_state_ == COMMIT_STATE_BEGIN_MAIN_FRAME_STARTED)
1081 << AsValue()->ToString(); 1187 << AsValue()->ToString();
1082 commit_state_ = COMMIT_STATE_READY_TO_COMMIT; 1188 commit_state_ = COMMIT_STATE_READY_TO_COMMIT;
1083 // In main thread low latency mode, commit should happen right after 1189 // In main thread low latency mode, commit should happen right after
1084 // BeginFrame, meaning when this function is called, next action should be 1190 // BeginFrame, meaning when this function is called, next action should be
1085 // commit. 1191 // commit.
1086 if (settings_.main_thread_should_always_be_low_latency) 1192 if (settings_.main_thread_should_always_be_low_latency)
1087 DCHECK(ShouldCommit()); 1193 DCHECK(ShouldCommit());
1088 } 1194 }
1089 1195
1090 void SchedulerStateMachine::BeginMainFrameAborted(CommitEarlyOutReason reason) { 1196 void SchedulerStateMachine::BeginMainFrameAborted(CommitEarlyOutReason reason) {
1091 DCHECK_EQ(commit_state_, COMMIT_STATE_BEGIN_MAIN_FRAME_SENT); 1197 DCHECK_EQ(commit_state_, COMMIT_STATE_BEGIN_MAIN_FRAME_SENT);
1092 switch (reason) { 1198 switch (reason) {
1093 case CommitEarlyOutReason::ABORTED_OUTPUT_SURFACE_LOST: 1199 case CommitEarlyOutReason::ABORTED_OUTPUT_SURFACE_LOST:
1094 case CommitEarlyOutReason::ABORTED_NOT_VISIBLE: 1200 case CommitEarlyOutReason::ABORTED_NOT_VISIBLE:
1095 case CommitEarlyOutReason::ABORTED_DEFERRED_COMMIT: 1201 case CommitEarlyOutReason::ABORTED_DEFERRED_COMMIT:
1096 commit_state_ = COMMIT_STATE_IDLE; 1202 commit_state_ = COMMIT_STATE_IDLE;
1097 SetNeedsCommit(); 1203 SetNeedsCommit();
1098 return; 1204 return;
1099 case CommitEarlyOutReason::FINISHED_NO_UPDATES: 1205 case CommitEarlyOutReason::FINISHED_NO_UPDATES:
1100 bool commit_has_no_updates = true; 1206 bool commit_has_no_updates = true;
1101 UpdateStateOnCommit(commit_has_no_updates); 1207 DidCommit(commit_has_no_updates);
1102 return; 1208 return;
1103 } 1209 }
1104 } 1210 }
1105 1211
1106 void SchedulerStateMachine::DidPrepareTiles() {
1107 needs_prepare_tiles_ = false;
1108 // "Fill" the PrepareTiles funnel.
1109 prepare_tiles_funnel_++;
1110 }
1111
1112 void SchedulerStateMachine::DidLoseOutputSurface() { 1212 void SchedulerStateMachine::DidLoseOutputSurface() {
1113 if (output_surface_state_ == OUTPUT_SURFACE_LOST || 1213 if (output_surface_state_ == OUTPUT_SURFACE_LOST ||
1114 output_surface_state_ == OUTPUT_SURFACE_CREATING) 1214 output_surface_state_ == OUTPUT_SURFACE_CREATING)
1115 return; 1215 return;
1116 output_surface_state_ = OUTPUT_SURFACE_LOST; 1216 output_surface_state_ = OUTPUT_SURFACE_LOST;
1117 needs_redraw_ = false; 1217 needs_redraw_ = false;
1118 wait_for_active_tree_ready_to_draw_ = false; 1218 wait_for_active_tree_ready_to_draw_ = false;
1119 } 1219 }
1120 1220
1121 void SchedulerStateMachine::NotifyReadyToActivate() { 1221 void SchedulerStateMachine::NotifyReadyToActivate() {
1122 if (has_pending_tree_) 1222 pending_tree_is_ready_for_activation_ = true;
1123 pending_tree_is_ready_for_activation_ = true;
1124 } 1223 }
1125 1224
1126 void SchedulerStateMachine::NotifyReadyToDraw() { 1225 void SchedulerStateMachine::NotifyReadyToDraw() {
1127 wait_for_active_tree_ready_to_draw_ = false; 1226 wait_for_active_tree_ready_to_draw_ = false;
1227 active_tree_ready_to_draw_ = true;
1228 }
1229
1230 void SchedulerStateMachine::SetRequiresHighResToDraw(bool required) {
1231 if (requires_high_res_to_draw_ == required)
1232 return;
1233 requires_high_res_to_draw_ = required;
1128 } 1234 }
1129 1235
1130 void SchedulerStateMachine::DidCreateAndInitializeOutputSurface() { 1236 void SchedulerStateMachine::DidCreateAndInitializeOutputSurface() {
1131 DCHECK_EQ(output_surface_state_, OUTPUT_SURFACE_CREATING); 1237 DCHECK_EQ(output_surface_state_, OUTPUT_SURFACE_CREATING);
1132 output_surface_state_ = OUTPUT_SURFACE_WAITING_FOR_FIRST_COMMIT; 1238 output_surface_state_ = OUTPUT_SURFACE_WAITING_FOR_FIRST_COMMIT;
1133 1239
1134 if (did_create_and_initialize_first_output_surface_) { 1240 if (did_create_and_initialize_first_output_surface_) {
1135 // TODO(boliu): See if we can remove this when impl-side painting is always 1241 // TODO(boliu): See if we can remove this when impl-side painting is always
1136 // on. Does anything on the main thread need to update after recreate? 1242 // on. Does anything on the main thread need to update after recreate?
1137 needs_commit_ = true; 1243 needs_commit_ = true;
(...skipping 29 matching lines...) Expand all
1167 static_cast<int>(begin_impl_frame_state_), 1273 static_cast<int>(begin_impl_frame_state_),
1168 static_cast<int>(commit_state_), 1274 static_cast<int>(commit_state_),
1169 has_pending_tree_ ? 'T' : 'F', 1275 has_pending_tree_ ? 'T' : 'F',
1170 pending_tree_is_ready_for_activation_ ? 'T' : 'F', 1276 pending_tree_is_ready_for_activation_ ? 'T' : 'F',
1171 active_tree_needs_first_draw_ ? 'T' : 'F', 1277 active_tree_needs_first_draw_ ? 'T' : 'F',
1172 max_pending_swaps_, 1278 max_pending_swaps_,
1173 pending_swaps_); 1279 pending_swaps_);
1174 } 1280 }
1175 1281
1176 } // namespace cc 1282 } // namespace cc
OLDNEW
« no previous file with comments | « cc/scheduler/scheduler_state_machine.h ('k') | cc/test/fake_layer_tree_host_impl_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698