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

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

Issue 1002493006: cc: Do not use current frame number in state machine decisions. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@no_begin_impl_frame_args_in_state_machine
Patch Set: 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 animate_funnel_(false),
30 perform_swap_funnel_(false),
31 request_swap_funnel_(false),
32 send_begin_main_frame_funnel_(false),
29 prepare_tiles_funnel_(0), 33 prepare_tiles_funnel_(0),
30 consecutive_checkerboard_animations_(0), 34 consecutive_checkerboard_animations_(0),
31 max_pending_swaps_(1), 35 max_pending_swaps_(1),
32 pending_swaps_(0), 36 pending_swaps_(0),
33 needs_redraw_(false), 37 needs_redraw_(false),
34 needs_animate_(false), 38 needs_animate_(false),
35 needs_prepare_tiles_(false), 39 needs_prepare_tiles_(false),
36 needs_commit_(false), 40 needs_commit_(false),
37 inside_poll_for_anticipated_draw_triggers_(false), 41 inside_poll_for_anticipated_draw_triggers_(false),
38 visible_(false), 42 visible_(false),
39 can_start_(false), 43 can_start_(false),
40 can_draw_(false), 44 can_draw_(false),
41 has_pending_tree_(false), 45 has_pending_tree_(false),
42 pending_tree_is_ready_for_activation_(false), 46 pending_tree_is_ready_for_activation_(false),
43 active_tree_needs_first_draw_(false), 47 active_tree_needs_first_draw_(false),
44 did_commit_after_animating_(false),
45 did_create_and_initialize_first_output_surface_(false), 48 did_create_and_initialize_first_output_surface_(false),
46 impl_latency_takes_priority_(false), 49 impl_latency_takes_priority_(false),
47 skip_next_begin_main_frame_to_reduce_latency_(false), 50 skip_next_begin_main_frame_to_reduce_latency_(false),
48 skip_begin_main_frame_to_reduce_latency_(false), 51 skip_begin_main_frame_to_reduce_latency_(false),
49 continuous_painting_(false), 52 continuous_painting_(false),
50 children_need_begin_frames_(false), 53 children_need_begin_frames_(false),
51 defer_commits_(false) { 54 defer_commits_(false) {
52 } 55 }
53 56
54 const char* SchedulerStateMachine::OutputSurfaceStateToString( 57 const char* SchedulerStateMachine::OutputSurfaceStateToString(
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 state->SetInteger("current_frame_number", current_frame_number_); 176 state->SetInteger("current_frame_number", current_frame_number_);
174 177
175 state->SetInteger("last_frame_number_animate_performed", 178 state->SetInteger("last_frame_number_animate_performed",
176 last_frame_number_animate_performed_); 179 last_frame_number_animate_performed_);
177 state->SetInteger("last_frame_number_swap_performed", 180 state->SetInteger("last_frame_number_swap_performed",
178 last_frame_number_swap_performed_); 181 last_frame_number_swap_performed_);
179 state->SetInteger("last_frame_number_swap_requested", 182 state->SetInteger("last_frame_number_swap_requested",
180 last_frame_number_swap_requested_); 183 last_frame_number_swap_requested_);
181 state->SetInteger("last_frame_number_begin_main_frame_sent", 184 state->SetInteger("last_frame_number_begin_main_frame_sent",
182 last_frame_number_begin_main_frame_sent_); 185 last_frame_number_begin_main_frame_sent_);
183 186 state->SetBoolean("animate_funnel", animate_funnel_);
187 state->SetBoolean("perform_swap_funnel", perform_swap_funnel_);
188 state->SetBoolean("request_swap_funnel", request_swap_funnel_);
189 state->SetBoolean("send_begin_main_frame_funnel",
190 send_begin_main_frame_funnel_);
184 state->SetInteger("prepare_tiles_funnel", prepare_tiles_funnel_); 191 state->SetInteger("prepare_tiles_funnel", prepare_tiles_funnel_);
185 state->SetInteger("consecutive_checkerboard_animations", 192 state->SetInteger("consecutive_checkerboard_animations",
186 consecutive_checkerboard_animations_); 193 consecutive_checkerboard_animations_);
187 state->SetInteger("max_pending_swaps_", max_pending_swaps_); 194 state->SetInteger("max_pending_swaps_", max_pending_swaps_);
188 state->SetInteger("pending_swaps_", pending_swaps_); 195 state->SetInteger("pending_swaps_", pending_swaps_);
189 state->SetBoolean("needs_redraw", needs_redraw_); 196 state->SetBoolean("needs_redraw", needs_redraw_);
190 state->SetBoolean("needs_animate_", needs_animate_); 197 state->SetBoolean("needs_animate_", needs_animate_);
191 state->SetBoolean("needs_prepare_tiles", needs_prepare_tiles_); 198 state->SetBoolean("needs_prepare_tiles", needs_prepare_tiles_);
192 state->SetBoolean("needs_commit", needs_commit_); 199 state->SetBoolean("needs_commit", needs_commit_);
193 state->SetBoolean("visible", visible_); 200 state->SetBoolean("visible", visible_);
194 state->SetBoolean("can_start", can_start_); 201 state->SetBoolean("can_start", can_start_);
195 state->SetBoolean("can_draw", can_draw_); 202 state->SetBoolean("can_draw", can_draw_);
196 state->SetBoolean("has_pending_tree", has_pending_tree_); 203 state->SetBoolean("has_pending_tree", has_pending_tree_);
197 state->SetBoolean("pending_tree_is_ready_for_activation", 204 state->SetBoolean("pending_tree_is_ready_for_activation",
198 pending_tree_is_ready_for_activation_); 205 pending_tree_is_ready_for_activation_);
199 state->SetBoolean("active_tree_needs_first_draw", 206 state->SetBoolean("active_tree_needs_first_draw",
200 active_tree_needs_first_draw_); 207 active_tree_needs_first_draw_);
201 state->SetBoolean("did_commit_after_animating", did_commit_after_animating_);
202 state->SetBoolean("did_create_and_initialize_first_output_surface", 208 state->SetBoolean("did_create_and_initialize_first_output_surface",
203 did_create_and_initialize_first_output_surface_); 209 did_create_and_initialize_first_output_surface_);
204 state->SetBoolean("impl_latency_takes_priority", 210 state->SetBoolean("impl_latency_takes_priority",
205 impl_latency_takes_priority_); 211 impl_latency_takes_priority_);
206 state->SetBoolean("main_thread_is_in_high_latency_mode", 212 state->SetBoolean("main_thread_is_in_high_latency_mode",
207 MainThreadIsInHighLatencyMode()); 213 MainThreadIsInHighLatencyMode());
208 state->SetBoolean("skip_begin_main_frame_to_reduce_latency", 214 state->SetBoolean("skip_begin_main_frame_to_reduce_latency",
209 skip_begin_main_frame_to_reduce_latency_); 215 skip_begin_main_frame_to_reduce_latency_);
210 state->SetBoolean("skip_next_begin_main_frame_to_reduce_latency", 216 state->SetBoolean("skip_next_begin_main_frame_to_reduce_latency",
211 skip_next_begin_main_frame_to_reduce_latency_); 217 skip_next_begin_main_frame_to_reduce_latency_);
212 state->SetBoolean("continuous_painting", continuous_painting_); 218 state->SetBoolean("continuous_painting", continuous_painting_);
213 state->SetBoolean("children_need_begin_frames", children_need_begin_frames_); 219 state->SetBoolean("children_need_begin_frames", children_need_begin_frames_);
214 state->SetBoolean("defer_commits", defer_commits_); 220 state->SetBoolean("defer_commits", defer_commits_);
215 state->EndDictionary(); 221 state->EndDictionary();
216 } 222 }
217 223
218 void SchedulerStateMachine::AdvanceCurrentFrameNumber() { 224 void SchedulerStateMachine::AdvanceCurrentFrameNumber() {
219 current_frame_number_++; 225 current_frame_number_++;
220 226
227 animate_funnel_ = false;
228 perform_swap_funnel_ = false;
229 request_swap_funnel_ = false;
230 send_begin_main_frame_funnel_ = false;
231
221 // "Drain" the PrepareTiles funnel. 232 // "Drain" the PrepareTiles funnel.
222 if (prepare_tiles_funnel_ > 0) 233 if (prepare_tiles_funnel_ > 0)
223 prepare_tiles_funnel_--; 234 prepare_tiles_funnel_--;
224 235
225 skip_begin_main_frame_to_reduce_latency_ = 236 skip_begin_main_frame_to_reduce_latency_ =
226 skip_next_begin_main_frame_to_reduce_latency_; 237 skip_next_begin_main_frame_to_reduce_latency_;
227 skip_next_begin_main_frame_to_reduce_latency_ = false; 238 skip_next_begin_main_frame_to_reduce_latency_ = false;
228 } 239 }
229 240
230 bool SchedulerStateMachine::HasAnimatedThisFrame() const {
231 return last_frame_number_animate_performed_ == current_frame_number_;
232 }
233
234 bool SchedulerStateMachine::HasSentBeginMainFrameThisFrame() const {
235 return current_frame_number_ ==
236 last_frame_number_begin_main_frame_sent_;
237 }
238
239 bool SchedulerStateMachine::HasSwappedThisFrame() const {
240 return current_frame_number_ == last_frame_number_swap_performed_;
241 }
242
243 bool SchedulerStateMachine::HasRequestedSwapThisFrame() const {
244 return current_frame_number_ == last_frame_number_swap_requested_;
245 }
246
247 bool SchedulerStateMachine::PendingDrawsShouldBeAborted() const { 241 bool SchedulerStateMachine::PendingDrawsShouldBeAborted() const {
248 // These are all the cases where we normally cannot or do not want to draw 242 // These are all the cases where we normally cannot or do not want to draw
249 // but, if needs_redraw_ is true and we do not draw to make forward progress, 243 // but, if needs_redraw_ is true and we do not draw to make forward progress,
250 // we might deadlock with the main thread. 244 // we might deadlock with the main thread.
251 // This should be a superset of PendingActivationsShouldBeForced() since 245 // This should be a superset of PendingActivationsShouldBeForced() since
252 // activation of the pending tree is blocked by drawing of the active tree and 246 // activation of the pending tree is blocked by drawing of the active tree and
253 // the main thread might be blocked on activation of the most recent commit. 247 // the main thread might be blocked on activation of the most recent commit.
254 if (PendingActivationsShouldBeForced()) 248 if (PendingActivationsShouldBeForced())
255 return true; 249 return true;
256 250
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 // from occuring. If we are waiting for the first draw, then perfom the 307 // from occuring. If we are waiting for the first draw, then perfom the
314 // aborted draw to keep things moving. If we are not waiting for the first 308 // aborted draw to keep things moving. If we are not waiting for the first
315 // draw however, we don't want to abort for no reason. 309 // draw however, we don't want to abort for no reason.
316 if (PendingDrawsShouldBeAborted()) 310 if (PendingDrawsShouldBeAborted())
317 return active_tree_needs_first_draw_; 311 return active_tree_needs_first_draw_;
318 312
319 // Don't draw if we are waiting on the first commit after a surface. 313 // Don't draw if we are waiting on the first commit after a surface.
320 if (output_surface_state_ != OUTPUT_SURFACE_ACTIVE) 314 if (output_surface_state_ != OUTPUT_SURFACE_ACTIVE)
321 return false; 315 return false;
322 316
323 // If a commit has occurred after the animate call, we need to call animate
324 // again before we should draw.
325 if (did_commit_after_animating_)
326 return false;
327
328 // After this line, we only want to send a swap request once per frame. 317 // After this line, we only want to send a swap request once per frame.
329 if (HasRequestedSwapThisFrame()) 318 if (request_swap_funnel_)
330 return false; 319 return false;
331 320
332 // Do not queue too many swaps. 321 // Do not queue too many swaps.
333 if (pending_swaps_ >= max_pending_swaps_) 322 if (pending_swaps_ >= max_pending_swaps_)
334 return false; 323 return false;
335 324
336 // Except for the cases above, do not draw outside of the BeginImplFrame 325 // Except for the cases above, do not draw outside of the BeginImplFrame
337 // deadline. 326 // deadline.
338 if (begin_impl_frame_state_ != BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE) 327 if (begin_impl_frame_state_ != BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE)
339 return false; 328 return false;
(...skipping 23 matching lines...) Expand all
363 // At this point, only activate if we are ready to activate. 352 // At this point, only activate if we are ready to activate.
364 return pending_tree_is_ready_for_activation_; 353 return pending_tree_is_ready_for_activation_;
365 } 354 }
366 355
367 bool SchedulerStateMachine::ShouldAnimate() const { 356 bool SchedulerStateMachine::ShouldAnimate() const {
368 // Don't animate if we are waiting on the first commit after a surface. 357 // Don't animate if we are waiting on the first commit after a surface.
369 if (output_surface_state_ != OUTPUT_SURFACE_ACTIVE) 358 if (output_surface_state_ != OUTPUT_SURFACE_ACTIVE)
370 return false; 359 return false;
371 360
372 // If a commit occurred after our last call, we need to do animation again. 361 // If a commit occurred after our last call, we need to do animation again.
373 if (HasAnimatedThisFrame() && !did_commit_after_animating_) 362 if (animate_funnel_)
374 return false; 363 return false;
375 364
376 if (begin_impl_frame_state_ != BEGIN_IMPL_FRAME_STATE_BEGIN_FRAME_STARTING && 365 if (begin_impl_frame_state_ != BEGIN_IMPL_FRAME_STATE_BEGIN_FRAME_STARTING &&
377 begin_impl_frame_state_ != BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE) 366 begin_impl_frame_state_ != BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE)
378 return false; 367 return false;
379 368
380 return needs_redraw_ || needs_animate_; 369 return needs_redraw_ || needs_animate_;
381 } 370 }
382 371
383 bool SchedulerStateMachine::CouldSendBeginMainFrame() const { 372 bool SchedulerStateMachine::CouldSendBeginMainFrame() const {
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
418 if (begin_impl_frame_state_ == BEGIN_IMPL_FRAME_STATE_IDLE && 407 if (begin_impl_frame_state_ == BEGIN_IMPL_FRAME_STATE_IDLE &&
419 BeginFrameNeeded()) 408 BeginFrameNeeded())
420 return false; 409 return false;
421 410
422 // We need a new commit for the forced redraw. This honors the 411 // We need a new commit for the forced redraw. This honors the
423 // single commit per interval because the result will be swapped to screen. 412 // single commit per interval because the result will be swapped to screen.
424 if (forced_redraw_state_ == FORCED_REDRAW_STATE_WAITING_FOR_COMMIT) 413 if (forced_redraw_state_ == FORCED_REDRAW_STATE_WAITING_FOR_COMMIT)
425 return true; 414 return true;
426 415
427 // After this point, we only start a commit once per frame. 416 // After this point, we only start a commit once per frame.
428 if (HasSentBeginMainFrameThisFrame()) 417 if (send_begin_main_frame_funnel_)
429 return false; 418 return false;
430 419
431 // We shouldn't normally accept commits if there isn't an OutputSurface. 420 // We shouldn't normally accept commits if there isn't an OutputSurface.
432 if (!HasInitializedOutputSurface()) 421 if (!HasInitializedOutputSurface())
433 return false; 422 return false;
434 423
435 // SwapAck throttle the BeginMainFrames unless we just swapped. 424 // SwapAck throttle the BeginMainFrames unless we just swapped.
436 // TODO(brianderson): Remove this restriction to improve throughput. 425 // TODO(brianderson): Remove this restriction to improve throughput.
437 bool just_swapped_in_deadline = 426 bool just_swapped_in_deadline =
438 begin_impl_frame_state_ == BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE && 427 begin_impl_frame_state_ == BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE &&
439 HasSwappedThisFrame(); 428 perform_swap_funnel_;
440 if (pending_swaps_ >= max_pending_swaps_ && !just_swapped_in_deadline) 429 if (pending_swaps_ >= max_pending_swaps_ && !just_swapped_in_deadline)
441 return false; 430 return false;
442 431
443 if (skip_begin_main_frame_to_reduce_latency_) 432 if (skip_begin_main_frame_to_reduce_latency_)
444 return false; 433 return false;
445 434
446 return true; 435 return true;
447 } 436 }
448 437
449 bool SchedulerStateMachine::ShouldCommit() const { 438 bool SchedulerStateMachine::ShouldCommit() const {
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
507 switch (action) { 496 switch (action) {
508 case ACTION_NONE: 497 case ACTION_NONE:
509 return; 498 return;
510 499
511 case ACTION_ACTIVATE_SYNC_TREE: 500 case ACTION_ACTIVATE_SYNC_TREE:
512 UpdateStateOnActivation(); 501 UpdateStateOnActivation();
513 return; 502 return;
514 503
515 case ACTION_ANIMATE: 504 case ACTION_ANIMATE:
516 last_frame_number_animate_performed_ = current_frame_number_; 505 last_frame_number_animate_performed_ = current_frame_number_;
506 animate_funnel_ = true;
517 needs_animate_ = false; 507 needs_animate_ = false;
518 did_commit_after_animating_ = false;
519 // TODO(skyostil): Instead of assuming this, require the client to tell 508 // TODO(skyostil): Instead of assuming this, require the client to tell
520 // us. 509 // us.
521 SetNeedsRedraw(); 510 SetNeedsRedraw();
522 return; 511 return;
523 512
524 case ACTION_SEND_BEGIN_MAIN_FRAME: 513 case ACTION_SEND_BEGIN_MAIN_FRAME:
525 DCHECK(!has_pending_tree_ || 514 DCHECK(!has_pending_tree_ ||
526 settings_.main_frame_before_activation_enabled); 515 settings_.main_frame_before_activation_enabled);
527 DCHECK(visible_); 516 DCHECK(visible_);
528 commit_state_ = COMMIT_STATE_BEGIN_MAIN_FRAME_SENT; 517 commit_state_ = COMMIT_STATE_BEGIN_MAIN_FRAME_SENT;
529 needs_commit_ = false; 518 needs_commit_ = false;
519 send_begin_main_frame_funnel_ = true;
530 last_frame_number_begin_main_frame_sent_ = 520 last_frame_number_begin_main_frame_sent_ =
531 current_frame_number_; 521 current_frame_number_;
532 return; 522 return;
533 523
534 case ACTION_COMMIT: { 524 case ACTION_COMMIT: {
535 bool commit_has_no_updates = false; 525 bool commit_has_no_updates = false;
536 UpdateStateOnCommit(commit_has_no_updates); 526 UpdateStateOnCommit(commit_has_no_updates);
537 return; 527 return;
538 } 528 }
539 529
(...skipping 24 matching lines...) Expand all
564 554
565 case ACTION_PREPARE_TILES: 555 case ACTION_PREPARE_TILES:
566 UpdateStateOnPrepareTiles(); 556 UpdateStateOnPrepareTiles();
567 return; 557 return;
568 } 558 }
569 } 559 }
570 560
571 void SchedulerStateMachine::UpdateStateOnCommit(bool commit_has_no_updates) { 561 void SchedulerStateMachine::UpdateStateOnCommit(bool commit_has_no_updates) {
572 commit_count_++; 562 commit_count_++;
573 563
574 if (!commit_has_no_updates && HasAnimatedThisFrame()) 564 if (!commit_has_no_updates)
575 did_commit_after_animating_ = true; 565 animate_funnel_ = false;
brianderson 2015/03/19 23:31:43 Neat way of getting rid of did_commit_after_animat
sunnyps 2015/03/20 01:13:44 Acknowledged.
576 566
577 if (commit_has_no_updates || settings_.main_frame_before_activation_enabled) { 567 if (commit_has_no_updates || settings_.main_frame_before_activation_enabled) {
578 commit_state_ = COMMIT_STATE_IDLE; 568 commit_state_ = COMMIT_STATE_IDLE;
579 } else if (settings_.impl_side_painting) { 569 } else if (settings_.impl_side_painting) {
580 commit_state_ = COMMIT_STATE_WAITING_FOR_ACTIVATION; 570 commit_state_ = COMMIT_STATE_WAITING_FOR_ACTIVATION;
581 } else { 571 } else {
582 commit_state_ = settings_.main_thread_should_always_be_low_latency 572 commit_state_ = settings_.main_thread_should_always_be_low_latency
583 ? COMMIT_STATE_WAITING_FOR_DRAW 573 ? COMMIT_STATE_WAITING_FOR_DRAW
584 : COMMIT_STATE_IDLE; 574 : COMMIT_STATE_IDLE;
585 } 575 }
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
644 void SchedulerStateMachine::UpdateStateOnDraw(bool did_request_swap) { 634 void SchedulerStateMachine::UpdateStateOnDraw(bool did_request_swap) {
645 if (forced_redraw_state_ == FORCED_REDRAW_STATE_WAITING_FOR_DRAW) 635 if (forced_redraw_state_ == FORCED_REDRAW_STATE_WAITING_FOR_DRAW)
646 forced_redraw_state_ = FORCED_REDRAW_STATE_IDLE; 636 forced_redraw_state_ = FORCED_REDRAW_STATE_IDLE;
647 637
648 if (commit_state_ == COMMIT_STATE_WAITING_FOR_DRAW) 638 if (commit_state_ == COMMIT_STATE_WAITING_FOR_DRAW)
649 commit_state_ = COMMIT_STATE_IDLE; 639 commit_state_ = COMMIT_STATE_IDLE;
650 640
651 needs_redraw_ = false; 641 needs_redraw_ = false;
652 active_tree_needs_first_draw_ = false; 642 active_tree_needs_first_draw_ = false;
653 643
654 if (did_request_swap) 644 if (did_request_swap) {
645 request_swap_funnel_ = true;
brianderson 2015/03/19 23:31:43 For all the places where we set the funnels to tru
sunnyps 2015/03/20 01:13:44 Done.
655 last_frame_number_swap_requested_ = current_frame_number_; 646 last_frame_number_swap_requested_ = current_frame_number_;
647 }
656 } 648 }
657 649
658 void SchedulerStateMachine::UpdateStateOnPrepareTiles() { 650 void SchedulerStateMachine::UpdateStateOnPrepareTiles() {
659 needs_prepare_tiles_ = false; 651 needs_prepare_tiles_ = false;
660 } 652 }
661 653
662 void SchedulerStateMachine::SetSkipNextBeginMainFrameToReduceLatency() { 654 void SchedulerStateMachine::SetSkipNextBeginMainFrameToReduceLatency() {
663 TRACE_EVENT_INSTANT0("cc", 655 TRACE_EVENT_INSTANT0("cc",
664 "Scheduler: SkipNextBeginMainFrameToReduceLatency", 656 "Scheduler: SkipNextBeginMainFrameToReduceLatency",
665 TRACE_EVENT_SCOPE_THREAD); 657 TRACE_EVENT_SCOPE_THREAD);
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
783 // Changing priorities may allow us to activate (given the new priorities), 775 // Changing priorities may allow us to activate (given the new priorities),
784 // which may result in a new frame. 776 // which may result in a new frame.
785 if (needs_prepare_tiles_) 777 if (needs_prepare_tiles_)
786 return true; 778 return true;
787 779
788 // If we just sent a swap request, it's likely that we are going to produce 780 // If we just sent a swap request, it's likely that we are going to produce
789 // another frame soon. This helps avoid negative glitches in our 781 // another frame soon. This helps avoid negative glitches in our
790 // SetNeedsBeginFrame requests, which may propagate to the BeginImplFrame 782 // SetNeedsBeginFrame requests, which may propagate to the BeginImplFrame
791 // provider and get sampled at an inopportune time, delaying the next 783 // provider and get sampled at an inopportune time, delaying the next
792 // BeginImplFrame. 784 // BeginImplFrame.
793 if (HasRequestedSwapThisFrame()) 785 if (request_swap_funnel_)
794 return true; 786 return true;
795 787
796 return false; 788 return false;
797 } 789 }
798 790
799 void SchedulerStateMachine::OnBeginImplFrame() { 791 void SchedulerStateMachine::OnBeginImplFrame() {
800 AdvanceCurrentFrameNumber(); 792 AdvanceCurrentFrameNumber();
801 DCHECK_EQ(begin_impl_frame_state_, BEGIN_IMPL_FRAME_STATE_IDLE) 793 DCHECK_EQ(begin_impl_frame_state_, BEGIN_IMPL_FRAME_STATE_IDLE)
802 << AsValue()->ToString(); 794 << AsValue()->ToString();
803 begin_impl_frame_state_ = BEGIN_IMPL_FRAME_STATE_BEGIN_FRAME_STARTING; 795 begin_impl_frame_state_ = BEGIN_IMPL_FRAME_STATE_BEGIN_FRAME_STARTING;
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
877 } 869 }
878 870
879 bool SchedulerStateMachine::MainThreadIsInHighLatencyMode() const { 871 bool SchedulerStateMachine::MainThreadIsInHighLatencyMode() const {
880 // If a commit is pending before the previous commit has been drawn, we 872 // If a commit is pending before the previous commit has been drawn, we
881 // are definitely in a high latency mode. 873 // are definitely in a high latency mode.
882 if (CommitPending() && (active_tree_needs_first_draw_ || has_pending_tree_)) 874 if (CommitPending() && (active_tree_needs_first_draw_ || has_pending_tree_))
883 return true; 875 return true;
884 876
885 // If we just sent a BeginMainFrame and haven't hit the deadline yet, the main 877 // If we just sent a BeginMainFrame and haven't hit the deadline yet, the main
886 // thread is in a low latency mode. 878 // thread is in a low latency mode.
887 if (HasSentBeginMainFrameThisFrame() && 879 if (send_begin_main_frame_funnel_ &&
888 (begin_impl_frame_state_ == BEGIN_IMPL_FRAME_STATE_BEGIN_FRAME_STARTING || 880 (begin_impl_frame_state_ == BEGIN_IMPL_FRAME_STATE_BEGIN_FRAME_STARTING ||
889 begin_impl_frame_state_ == BEGIN_IMPL_FRAME_STATE_INSIDE_BEGIN_FRAME)) 881 begin_impl_frame_state_ == BEGIN_IMPL_FRAME_STATE_INSIDE_BEGIN_FRAME))
890 return false; 882 return false;
891 883
892 // If there's a commit in progress it must either be from the previous frame 884 // If there's a commit in progress it must either be from the previous frame
893 // or it started after the impl thread's deadline. In either case the main 885 // or it started after the impl thread's deadline. In either case the main
894 // thread is in high latency mode. 886 // thread is in high latency mode.
895 if (CommitPending()) 887 if (CommitPending())
896 return true; 888 return true;
897 889
898 // Similarly, if there's a pending tree the main thread is in high latency 890 // Similarly, if there's a pending tree the main thread is in high latency
899 // mode, because either 891 // mode, because either
900 // it's from the previous frame 892 // it's from the previous frame
901 // or 893 // or
902 // we're currently drawing the active tree and the pending tree will thus 894 // we're currently drawing the active tree and the pending tree will thus
903 // only be drawn in the next frame. 895 // only be drawn in the next frame.
904 if (has_pending_tree_) 896 if (has_pending_tree_)
905 return true; 897 return true;
906 898
907 if (begin_impl_frame_state_ == BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE) { 899 if (begin_impl_frame_state_ == BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE) {
908 // Even if there's a new active tree to draw at the deadline or we've just 900 // Even if there's a new active tree to draw at the deadline or we've just
909 // swapped it, it may have been triggered by a previous BeginImplFrame, in 901 // swapped it, it may have been triggered by a previous BeginImplFrame, in
910 // which case the main thread is in a high latency mode. 902 // which case the main thread is in a high latency mode.
911 return (active_tree_needs_first_draw_ || HasSwappedThisFrame()) && 903 return (active_tree_needs_first_draw_ || perform_swap_funnel_) &&
912 !HasSentBeginMainFrameThisFrame(); 904 !send_begin_main_frame_funnel_;
913 } 905 }
914 906
915 // If the active tree needs its first draw in any other state, we know the 907 // If the active tree needs its first draw in any other state, we know the
916 // main thread is in a high latency mode. 908 // main thread is in a high latency mode.
917 return active_tree_needs_first_draw_; 909 return active_tree_needs_first_draw_;
918 } 910 }
919 911
920 void SchedulerStateMachine::DidEnterPollForAnticipatedDrawTriggers() { 912 void SchedulerStateMachine::DidEnterPollForAnticipatedDrawTriggers() {
921 AdvanceCurrentFrameNumber(); 913 AdvanceCurrentFrameNumber();
922 inside_poll_for_anticipated_draw_triggers_ = true; 914 inside_poll_for_anticipated_draw_triggers_ = true;
(...skipping 21 matching lines...) Expand all
944 } 936 }
945 937
946 void SchedulerStateMachine::SetMaxSwapsPending(int max) { 938 void SchedulerStateMachine::SetMaxSwapsPending(int max) {
947 max_pending_swaps_ = max; 939 max_pending_swaps_ = max;
948 } 940 }
949 941
950 void SchedulerStateMachine::DidSwapBuffers() { 942 void SchedulerStateMachine::DidSwapBuffers() {
951 pending_swaps_++; 943 pending_swaps_++;
952 DCHECK_LE(pending_swaps_, max_pending_swaps_); 944 DCHECK_LE(pending_swaps_, max_pending_swaps_);
953 945
946 perform_swap_funnel_ = true;
954 last_frame_number_swap_performed_ = current_frame_number_; 947 last_frame_number_swap_performed_ = current_frame_number_;
955 } 948 }
956 949
957 void SchedulerStateMachine::DidSwapBuffersComplete() { 950 void SchedulerStateMachine::DidSwapBuffersComplete() {
958 DCHECK_GT(pending_swaps_, 0); 951 DCHECK_GT(pending_swaps_, 0);
959 pending_swaps_--; 952 pending_swaps_--;
960 } 953 }
961 954
962 void SchedulerStateMachine::SetImplLatencyTakesPriority( 955 void SchedulerStateMachine::SetImplLatencyTakesPriority(
963 bool impl_latency_takes_priority) { 956 bool impl_latency_takes_priority) {
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
1097 static_cast<int>(begin_impl_frame_state_), 1090 static_cast<int>(begin_impl_frame_state_),
1098 static_cast<int>(commit_state_), 1091 static_cast<int>(commit_state_),
1099 has_pending_tree_ ? 'T' : 'F', 1092 has_pending_tree_ ? 'T' : 'F',
1100 pending_tree_is_ready_for_activation_ ? 'T' : 'F', 1093 pending_tree_is_ready_for_activation_ ? 'T' : 'F',
1101 active_tree_needs_first_draw_ ? 'T' : 'F', 1094 active_tree_needs_first_draw_ ? 'T' : 'F',
1102 max_pending_swaps_, 1095 max_pending_swaps_,
1103 pending_swaps_); 1096 pending_swaps_);
1104 } 1097 }
1105 1098
1106 } // namespace cc 1099 } // namespace cc
OLDNEW
« cc/scheduler/scheduler_state_machine.h ('K') | « cc/scheduler/scheduler_state_machine.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698