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

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

Issue 1265023005: cc: Add SchedulerStateMachine::DidDraw and use for forced draws (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@WillDidAction0
Patch Set: Sunny's comments Created 5 years 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"
(...skipping 10 matching lines...) Expand all
21 SchedulerStateMachine::SchedulerStateMachine(const SchedulerSettings& settings) 21 SchedulerStateMachine::SchedulerStateMachine(const SchedulerSettings& settings)
22 : settings_(settings), 22 : settings_(settings),
23 output_surface_state_(OUTPUT_SURFACE_NONE), 23 output_surface_state_(OUTPUT_SURFACE_NONE),
24 begin_impl_frame_state_(BEGIN_IMPL_FRAME_STATE_IDLE), 24 begin_impl_frame_state_(BEGIN_IMPL_FRAME_STATE_IDLE),
25 begin_main_frame_state_(BEGIN_MAIN_FRAME_STATE_IDLE), 25 begin_main_frame_state_(BEGIN_MAIN_FRAME_STATE_IDLE),
26 forced_redraw_state_(FORCED_REDRAW_STATE_IDLE), 26 forced_redraw_state_(FORCED_REDRAW_STATE_IDLE),
27 commit_count_(0), 27 commit_count_(0),
28 current_frame_number_(0), 28 current_frame_number_(0),
29 last_frame_number_animate_performed_(-1), 29 last_frame_number_animate_performed_(-1),
30 last_frame_number_swap_performed_(-1), 30 last_frame_number_swap_performed_(-1),
31 last_frame_number_swap_requested_(-1), 31 last_frame_number_draw_performed_(-1),
32 last_frame_number_begin_main_frame_sent_(-1), 32 last_frame_number_begin_main_frame_sent_(-1),
33 last_frame_number_invalidate_output_surface_performed_(-1), 33 last_frame_number_invalidate_output_surface_performed_(-1),
34 animate_funnel_(false), 34 animate_funnel_(false),
35 request_swap_funnel_(false), 35 draw_funnel_(false),
36 send_begin_main_frame_funnel_(true), 36 send_begin_main_frame_funnel_(true),
37 invalidate_output_surface_funnel_(false), 37 invalidate_output_surface_funnel_(false),
38 prepare_tiles_funnel_(0), 38 prepare_tiles_funnel_(0),
39 consecutive_checkerboard_animations_(0), 39 consecutive_checkerboard_animations_(0),
40 pending_swaps_(0), 40 pending_swaps_(0),
41 swaps_with_current_output_surface_(0), 41 swaps_with_current_output_surface_(0),
42 needs_redraw_(false), 42 needs_redraw_(false),
43 needs_animate_(false), 43 needs_animate_(false),
44 needs_prepare_tiles_(false), 44 needs_prepare_tiles_(false),
45 needs_begin_main_frame_(false), 45 needs_begin_main_frame_(false),
46 needs_one_begin_impl_frame_(false), 46 needs_one_begin_impl_frame_(false),
47 visible_(false), 47 visible_(false),
48 resourceless_draw_(false), 48 resourceless_draw_(false),
49 can_draw_(false), 49 can_draw_(false),
50 has_pending_tree_(false), 50 has_pending_tree_(false),
51 pending_tree_is_ready_for_activation_(false), 51 pending_tree_is_ready_for_activation_(false),
52 active_tree_needs_first_draw_(false), 52 active_tree_needs_first_draw_(false),
53 did_create_and_initialize_first_output_surface_(false), 53 did_create_and_initialize_first_output_surface_(false),
54 tree_priority_(NEW_CONTENT_TAKES_PRIORITY), 54 tree_priority_(NEW_CONTENT_TAKES_PRIORITY),
55 scroll_handler_state_( 55 scroll_handler_state_(
56 ScrollHandlerState::SCROLL_DOES_NOT_AFFECT_SCROLL_HANDLER), 56 ScrollHandlerState::SCROLL_DOES_NOT_AFFECT_SCROLL_HANDLER),
57 critical_begin_main_frame_to_activate_is_fast_(true), 57 critical_begin_main_frame_to_activate_is_fast_(true),
58 main_thread_missed_last_deadline_(false), 58 main_thread_missed_last_deadline_(false),
59 skip_next_begin_main_frame_to_reduce_latency_(false), 59 skip_next_begin_main_frame_to_reduce_latency_(false),
60 children_need_begin_frames_(false), 60 children_need_begin_frames_(false),
61 defer_commits_(false), 61 defer_commits_(false),
62 video_needs_begin_frames_(false), 62 video_needs_begin_frames_(false),
63 last_commit_had_no_updates_(false), 63 last_commit_had_no_updates_(false),
64 wait_for_ready_to_draw_(false), 64 wait_for_ready_to_draw_(false),
65 did_request_swap_in_last_frame_(false), 65 did_draw_in_last_frame_(false),
66 did_perform_swap_in_last_draw_(false) {} 66 did_swap_in_last_frame_(false) {}
67 67
68 const char* SchedulerStateMachine::OutputSurfaceStateToString( 68 const char* SchedulerStateMachine::OutputSurfaceStateToString(
69 OutputSurfaceState state) { 69 OutputSurfaceState state) {
70 switch (state) { 70 switch (state) {
71 case OUTPUT_SURFACE_NONE: 71 case OUTPUT_SURFACE_NONE:
72 return "OUTPUT_SURFACE_NONE"; 72 return "OUTPUT_SURFACE_NONE";
73 case OUTPUT_SURFACE_ACTIVE: 73 case OUTPUT_SURFACE_ACTIVE:
74 return "OUTPUT_SURFACE_ACTIVE"; 74 return "OUTPUT_SURFACE_ACTIVE";
75 case OUTPUT_SURFACE_CREATING: 75 case OUTPUT_SURFACE_CREATING:
76 return "OUTPUT_SURFACE_CREATING"; 76 return "OUTPUT_SURFACE_CREATING";
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 ForcedRedrawOnTimeoutStateToString(forced_redraw_state_)); 215 ForcedRedrawOnTimeoutStateToString(forced_redraw_state_));
216 state->EndDictionary(); 216 state->EndDictionary();
217 217
218 state->BeginDictionary("minor_state"); 218 state->BeginDictionary("minor_state");
219 state->SetInteger("commit_count", commit_count_); 219 state->SetInteger("commit_count", commit_count_);
220 state->SetInteger("current_frame_number", current_frame_number_); 220 state->SetInteger("current_frame_number", current_frame_number_);
221 state->SetInteger("last_frame_number_animate_performed", 221 state->SetInteger("last_frame_number_animate_performed",
222 last_frame_number_animate_performed_); 222 last_frame_number_animate_performed_);
223 state->SetInteger("last_frame_number_swap_performed", 223 state->SetInteger("last_frame_number_swap_performed",
224 last_frame_number_swap_performed_); 224 last_frame_number_swap_performed_);
225 state->SetInteger("last_frame_number_swap_requested", 225 state->SetInteger("last_frame_number_draw_performed",
226 last_frame_number_swap_requested_); 226 last_frame_number_draw_performed_);
227 state->SetInteger("last_frame_number_begin_main_frame_sent", 227 state->SetInteger("last_frame_number_begin_main_frame_sent",
228 last_frame_number_begin_main_frame_sent_); 228 last_frame_number_begin_main_frame_sent_);
229 state->SetBoolean("funnel: animate_funnel", animate_funnel_); 229 state->SetBoolean("funnel: animate_funnel", animate_funnel_);
230 state->SetBoolean("funnel: request_swap_funnel", request_swap_funnel_); 230 state->SetBoolean("funnel: draw_funnel", draw_funnel_);
231 state->SetBoolean("funnel: send_begin_main_frame_funnel", 231 state->SetBoolean("funnel: send_begin_main_frame_funnel",
232 send_begin_main_frame_funnel_); 232 send_begin_main_frame_funnel_);
233 state->SetInteger("funnel: prepare_tiles_funnel", prepare_tiles_funnel_); 233 state->SetInteger("funnel: prepare_tiles_funnel", prepare_tiles_funnel_);
234 state->SetBoolean("funnel: invalidate_output_surface_funnel", 234 state->SetBoolean("funnel: invalidate_output_surface_funnel",
235 invalidate_output_surface_funnel_); 235 invalidate_output_surface_funnel_);
236 state->SetInteger("consecutive_checkerboard_animations", 236 state->SetInteger("consecutive_checkerboard_animations",
237 consecutive_checkerboard_animations_); 237 consecutive_checkerboard_animations_);
238 state->SetInteger("pending_swaps_", pending_swaps_); 238 state->SetInteger("pending_swaps_", pending_swaps_);
239 state->SetInteger("swaps_with_current_output_surface", 239 state->SetInteger("swaps_with_current_output_surface",
240 swaps_with_current_output_surface_); 240 swaps_with_current_output_surface_);
(...skipping 19 matching lines...) Expand all
260 state->SetBoolean("critical_begin_main_frame_to_activate_is_fast_", 260 state->SetBoolean("critical_begin_main_frame_to_activate_is_fast_",
261 critical_begin_main_frame_to_activate_is_fast_); 261 critical_begin_main_frame_to_activate_is_fast_);
262 state->SetBoolean("main_thread_missed_last_deadline", 262 state->SetBoolean("main_thread_missed_last_deadline",
263 main_thread_missed_last_deadline_); 263 main_thread_missed_last_deadline_);
264 state->SetBoolean("skip_next_begin_main_frame_to_reduce_latency", 264 state->SetBoolean("skip_next_begin_main_frame_to_reduce_latency",
265 skip_next_begin_main_frame_to_reduce_latency_); 265 skip_next_begin_main_frame_to_reduce_latency_);
266 state->SetBoolean("children_need_begin_frames", children_need_begin_frames_); 266 state->SetBoolean("children_need_begin_frames", children_need_begin_frames_);
267 state->SetBoolean("video_needs_begin_frames", video_needs_begin_frames_); 267 state->SetBoolean("video_needs_begin_frames", video_needs_begin_frames_);
268 state->SetBoolean("defer_commits", defer_commits_); 268 state->SetBoolean("defer_commits", defer_commits_);
269 state->SetBoolean("last_commit_had_no_updates", last_commit_had_no_updates_); 269 state->SetBoolean("last_commit_had_no_updates", last_commit_had_no_updates_);
270 state->SetBoolean("did_request_swap_in_last_frame", 270 state->SetBoolean("did_draw_in_last_frame", did_draw_in_last_frame_);
271 did_request_swap_in_last_frame_); 271 state->SetBoolean("did_swap_in_last_frame", did_swap_in_last_frame_);
272 state->SetBoolean("did_perform_swap_in_last_draw",
273 did_perform_swap_in_last_draw_);
274 state->EndDictionary(); 272 state->EndDictionary();
275 } 273 }
276 274
277 bool SchedulerStateMachine::PendingDrawsShouldBeAborted() const { 275 bool SchedulerStateMachine::PendingDrawsShouldBeAborted() const {
278 // Normally when |visible_| is false, pending activations will be forced and 276 // Normally when |visible_| is false, pending activations will be forced and
279 // draws will be aborted. However, when the embedder is Android WebView, 277 // draws will be aborted. However, when the embedder is Android WebView,
280 // software draws could be scheduled by the Android OS at any time and draws 278 // software draws could be scheduled by the Android OS at any time and draws
281 // should not be aborted in this case. 279 // should not be aborted in this case.
282 bool is_output_surface_lost = (output_surface_state_ == OUTPUT_SURFACE_NONE); 280 bool is_output_surface_lost = (output_surface_state_ == OUTPUT_SURFACE_NONE);
283 if (resourceless_draw_) 281 if (resourceless_draw_)
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
343 // be blocking other important actions (like output surface initialization), 341 // be blocking other important actions (like output surface initialization),
344 // from occurring. If we are waiting for the first draw, then perform the 342 // from occurring. If we are waiting for the first draw, then perform the
345 // aborted draw to keep things moving. If we are not waiting for the first 343 // aborted draw to keep things moving. If we are not waiting for the first
346 // draw however, we don't want to abort for no reason. 344 // draw however, we don't want to abort for no reason.
347 if (PendingDrawsShouldBeAborted()) 345 if (PendingDrawsShouldBeAborted())
348 return active_tree_needs_first_draw_; 346 return active_tree_needs_first_draw_;
349 347
350 // Do not draw too many times in a single frame. It's okay that we don't check 348 // Do not draw too many times in a single frame. It's okay that we don't check
351 // this before checking for aborted draws because aborted draws do not request 349 // this before checking for aborted draws because aborted draws do not request
352 // a swap. 350 // a swap.
353 if (request_swap_funnel_) 351 if (draw_funnel_)
354 return false; 352 return false;
355 353
356 // Don't draw if we are waiting on the first commit after a surface. 354 // Don't draw if we are waiting on the first commit after a surface.
357 if (output_surface_state_ != OUTPUT_SURFACE_ACTIVE) 355 if (output_surface_state_ != OUTPUT_SURFACE_ACTIVE)
358 return false; 356 return false;
359 357
360 // Do not queue too many swaps. 358 // Do not queue too many swaps.
361 if (SwapThrottled()) 359 if (SwapThrottled())
362 return false; 360 return false;
363 361
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
485 if (SendingBeginMainFrameMightCauseDeadlock()) 483 if (SendingBeginMainFrameMightCauseDeadlock())
486 return false; 484 return false;
487 485
488 if (!settings_.main_frame_while_swap_throttled_enabled) { 486 if (!settings_.main_frame_while_swap_throttled_enabled) {
489 // SwapAck throttle the BeginMainFrames unless we just swapped to 487 // SwapAck throttle the BeginMainFrames unless we just swapped to
490 // potentially improve impl-thread latency over main-thread throughput. 488 // potentially improve impl-thread latency over main-thread throughput.
491 // TODO(brianderson): Remove this restriction to improve throughput or 489 // TODO(brianderson): Remove this restriction to improve throughput or
492 // make it conditional on ImplLatencyTakesPriority. 490 // make it conditional on ImplLatencyTakesPriority.
493 bool just_swapped_in_deadline = 491 bool just_swapped_in_deadline =
494 begin_impl_frame_state_ == BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE && 492 begin_impl_frame_state_ == BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE &&
495 did_perform_swap_in_last_draw_; 493 did_swap_in_last_frame_;
496 if (SwapThrottled() && !just_swapped_in_deadline) 494 if (SwapThrottled() && !just_swapped_in_deadline)
497 return false; 495 return false;
498 } 496 }
499 497
500 if (skip_next_begin_main_frame_to_reduce_latency_) 498 if (skip_next_begin_main_frame_to_reduce_latency_)
501 return false; 499 return false;
502 500
503 return true; 501 return true;
504 } 502 }
505 503
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
661 659
662 if (forced_redraw_state_ == FORCED_REDRAW_STATE_WAITING_FOR_ACTIVATION) 660 if (forced_redraw_state_ == FORCED_REDRAW_STATE_WAITING_FOR_ACTIVATION)
663 forced_redraw_state_ = FORCED_REDRAW_STATE_WAITING_FOR_DRAW; 661 forced_redraw_state_ = FORCED_REDRAW_STATE_WAITING_FOR_DRAW;
664 662
665 has_pending_tree_ = false; 663 has_pending_tree_ = false;
666 pending_tree_is_ready_for_activation_ = false; 664 pending_tree_is_ready_for_activation_ = false;
667 active_tree_needs_first_draw_ = true; 665 active_tree_needs_first_draw_ = true;
668 needs_redraw_ = true; 666 needs_redraw_ = true;
669 } 667 }
670 668
671 void SchedulerStateMachine::WillDraw(bool did_request_swap) { 669 void SchedulerStateMachine::WillDrawInternal() {
670 // We need to reset needs_redraw_ before we draw since the
671 // draw itself might request another draw.
672 needs_redraw_ = false;
673
674 draw_funnel_ = true;
675 active_tree_needs_first_draw_ = false;
676 did_draw_in_last_frame_ = true;
677 last_frame_number_draw_performed_ = current_frame_number_;
678
672 if (forced_redraw_state_ == FORCED_REDRAW_STATE_WAITING_FOR_DRAW) 679 if (forced_redraw_state_ == FORCED_REDRAW_STATE_WAITING_FOR_DRAW)
673 forced_redraw_state_ = FORCED_REDRAW_STATE_IDLE; 680 forced_redraw_state_ = FORCED_REDRAW_STATE_IDLE;
674 681
675 if (begin_main_frame_state_ == BEGIN_MAIN_FRAME_STATE_WAITING_FOR_DRAW) 682 if (begin_main_frame_state_ == BEGIN_MAIN_FRAME_STATE_WAITING_FOR_DRAW)
676 begin_main_frame_state_ = BEGIN_MAIN_FRAME_STATE_IDLE; 683 begin_main_frame_state_ = BEGIN_MAIN_FRAME_STATE_IDLE;
684 }
677 685
678 needs_redraw_ = false; 686 void SchedulerStateMachine::DidDrawInternal(DrawResult draw_result) {
679 active_tree_needs_first_draw_ = false; 687 switch (draw_result) {
688 case INVALID_RESULT:
689 case DRAW_ABORTED_CANT_DRAW:
690 case DRAW_ABORTED_CONTEXT_LOST:
691 NOTREACHED() << "Invalid return DrawResult:" << draw_result;
692 break;
693 case DRAW_ABORTED_DRAINING_PIPELINE:
694 case DRAW_SUCCESS:
695 consecutive_checkerboard_animations_ = 0;
696 forced_redraw_state_ = FORCED_REDRAW_STATE_IDLE;
697 break;
698 case DRAW_ABORTED_CHECKERBOARD_ANIMATIONS:
699 DCHECK(!did_swap_in_last_frame_);
700 needs_begin_main_frame_ = true;
701 needs_redraw_ = true;
702 consecutive_checkerboard_animations_++;
680 703
681 if (did_request_swap) { 704 if (consecutive_checkerboard_animations_ >=
682 DCHECK(!request_swap_funnel_); 705 settings_.maximum_number_of_failed_draws_before_draw_is_forced &&
683 request_swap_funnel_ = true; 706 forced_redraw_state_ == FORCED_REDRAW_STATE_IDLE &&
684 did_request_swap_in_last_frame_ = true; 707 settings_.timeout_and_draw_when_animation_checkerboards) {
685 last_frame_number_swap_requested_ = current_frame_number_; 708 // We need to force a draw, but it doesn't make sense to do this until
709 // we've committed and have new textures.
710 forced_redraw_state_ = FORCED_REDRAW_STATE_WAITING_FOR_COMMIT;
711 }
712 break;
713 case DRAW_ABORTED_MISSING_HIGH_RES_CONTENT:
714 DCHECK(!did_swap_in_last_frame_);
715 // It's not clear whether this missing content is because of missing
716 // pictures (which requires a commit) or because of memory pressure
717 // removing textures (which might not). To be safe, request a commit
718 // anyway.
719 needs_begin_main_frame_ = true;
720 break;
686 } 721 }
687 } 722 }
688 723
724 void SchedulerStateMachine::WillDraw() {
725 DCHECK(!draw_funnel_);
726 WillDrawInternal();
727 }
728
729 void SchedulerStateMachine::DidDraw(DrawResult draw_result) {
730 DidDrawInternal(draw_result);
731 }
732
733 void SchedulerStateMachine::AbortDrawAndSwap() {
734 // Pretend like the draw was successful.
735 // Note: We may abort at any time and cannot DCHECK that
736 // we haven't drawn in or swapped in the last frame here.
737 WillDrawInternal();
738 DidDrawInternal(DRAW_ABORTED_DRAINING_PIPELINE);
739 }
740
689 void SchedulerStateMachine::WillPrepareTiles() { 741 void SchedulerStateMachine::WillPrepareTiles() {
690 needs_prepare_tiles_ = false; 742 needs_prepare_tiles_ = false;
691 } 743 }
692 744
693 void SchedulerStateMachine::WillBeginOutputSurfaceCreation() { 745 void SchedulerStateMachine::WillBeginOutputSurfaceCreation() {
694 DCHECK_EQ(output_surface_state_, OUTPUT_SURFACE_NONE); 746 DCHECK_EQ(output_surface_state_, OUTPUT_SURFACE_NONE);
695 output_surface_state_ = OUTPUT_SURFACE_CREATING; 747 output_surface_state_ = OUTPUT_SURFACE_CREATING;
696 748
697 // The following DCHECKs make sure we are in the proper quiescent state. 749 // The following DCHECKs make sure we are in the proper quiescent state.
698 // The pipeline should be flushed entirely before we start output 750 // The pipeline should be flushed entirely before we start output
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
792 // If the pending tree activates quickly, we'll want a BeginImplFrame soon 844 // If the pending tree activates quickly, we'll want a BeginImplFrame soon
793 // to draw the new active tree. 845 // to draw the new active tree.
794 if (has_pending_tree_) 846 if (has_pending_tree_)
795 return true; 847 return true;
796 848
797 // Changing priorities may allow us to activate (given the new priorities), 849 // Changing priorities may allow us to activate (given the new priorities),
798 // which may result in a new frame. 850 // which may result in a new frame.
799 if (needs_prepare_tiles_) 851 if (needs_prepare_tiles_)
800 return true; 852 return true;
801 853
802 // If we just sent a swap request, it's likely that we are going to produce 854 // If we just tried to DrawAndSwap, it's likely that we are going to produce
803 // another frame soon. This helps avoid negative glitches in our 855 // another frame soon. This helps avoid negative glitches in our
804 // SetNeedsBeginFrame requests, which may propagate to the BeginImplFrame 856 // SetNeedsBeginFrame requests, which may propagate to the BeginImplFrame
805 // provider and get sampled at an inopportune time, delaying the next 857 // provider and get sampled at an inopportune time, delaying the next
806 // BeginImplFrame. 858 // BeginImplFrame.
807 if (did_request_swap_in_last_frame_) 859 if (did_draw_in_last_frame_)
808 return true; 860 return true;
809 861
810 // If the last commit was aborted because of early out (no updates), we should 862 // If the last commit was aborted because of early out (no updates), we should
811 // still want a begin frame in case there is a commit coming again. 863 // still want a begin frame in case there is a commit coming again.
812 if (last_commit_had_no_updates_) 864 if (last_commit_had_no_updates_)
813 return true; 865 return true;
814 866
815 return false; 867 return false;
816 } 868 }
817 869
818 void SchedulerStateMachine::OnBeginImplFrame() { 870 void SchedulerStateMachine::OnBeginImplFrame() {
819 begin_impl_frame_state_ = BEGIN_IMPL_FRAME_STATE_BEGIN_FRAME_STARTING; 871 begin_impl_frame_state_ = BEGIN_IMPL_FRAME_STATE_BEGIN_FRAME_STARTING;
820 current_frame_number_++; 872 current_frame_number_++;
821 873
822 last_commit_had_no_updates_ = false; 874 last_commit_had_no_updates_ = false;
823 did_request_swap_in_last_frame_ = false; 875 did_draw_in_last_frame_ = false;
876 did_swap_in_last_frame_ = false;
824 needs_one_begin_impl_frame_ = false; 877 needs_one_begin_impl_frame_ = false;
825 878
826 // Clear funnels for any actions we perform during the frame. 879 // Clear funnels for any actions we perform during the frame.
827 animate_funnel_ = false; 880 animate_funnel_ = false;
828 send_begin_main_frame_funnel_ = false; 881 send_begin_main_frame_funnel_ = false;
829 invalidate_output_surface_funnel_ = false; 882 invalidate_output_surface_funnel_ = false;
830 883
831 // "Drain" the PrepareTiles funnel. 884 // "Drain" the PrepareTiles funnel.
832 if (prepare_tiles_funnel_ > 0) 885 if (prepare_tiles_funnel_ > 0)
833 prepare_tiles_funnel_--; 886 prepare_tiles_funnel_--;
834 } 887 }
835 888
836 void SchedulerStateMachine::OnBeginImplFrameDeadlinePending() { 889 void SchedulerStateMachine::OnBeginImplFrameDeadlinePending() {
837 begin_impl_frame_state_ = BEGIN_IMPL_FRAME_STATE_INSIDE_BEGIN_FRAME; 890 begin_impl_frame_state_ = BEGIN_IMPL_FRAME_STATE_INSIDE_BEGIN_FRAME;
838 } 891 }
839 892
840 void SchedulerStateMachine::OnBeginImplFrameDeadline() { 893 void SchedulerStateMachine::OnBeginImplFrameDeadline() {
841 begin_impl_frame_state_ = BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE; 894 begin_impl_frame_state_ = BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE;
842 895
843 did_perform_swap_in_last_draw_ = false;
844
845 // Clear funnels for any actions we perform during the deadline. 896 // Clear funnels for any actions we perform during the deadline.
846 request_swap_funnel_ = false; 897 draw_funnel_ = false;
847 898
848 // Allow one PrepareTiles per draw for synchronous compositor. 899 // Allow one PrepareTiles per draw for synchronous compositor.
849 if (settings_.using_synchronous_renderer_compositor) { 900 if (settings_.using_synchronous_renderer_compositor) {
850 if (prepare_tiles_funnel_ > 0) 901 if (prepare_tiles_funnel_ > 0)
851 prepare_tiles_funnel_--; 902 prepare_tiles_funnel_--;
852 } 903 }
853 } 904 }
854 905
855 void SchedulerStateMachine::OnBeginImplFrameIdle() { 906 void SchedulerStateMachine::OnBeginImplFrameIdle() {
856 begin_impl_frame_state_ = BEGIN_IMPL_FRAME_STATE_IDLE; 907 begin_impl_frame_state_ = BEGIN_IMPL_FRAME_STATE_IDLE;
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
972 } 1023 }
973 1024
974 void SchedulerStateMachine::SetNeedsPrepareTiles() { 1025 void SchedulerStateMachine::SetNeedsPrepareTiles() {
975 if (!needs_prepare_tiles_) { 1026 if (!needs_prepare_tiles_) {
976 TRACE_EVENT0("cc", "SchedulerStateMachine::SetNeedsPrepareTiles"); 1027 TRACE_EVENT0("cc", "SchedulerStateMachine::SetNeedsPrepareTiles");
977 needs_prepare_tiles_ = true; 1028 needs_prepare_tiles_ = true;
978 } 1029 }
979 } 1030 }
980 void SchedulerStateMachine::DidSwapBuffers() { 1031 void SchedulerStateMachine::DidSwapBuffers() {
981 TRACE_EVENT_ASYNC_BEGIN0("cc", "Scheduler:pending_swaps", this); 1032 TRACE_EVENT_ASYNC_BEGIN0("cc", "Scheduler:pending_swaps", this);
1033 DCHECK_LT(pending_swaps_, kMaxPendingSwaps);
1034
982 pending_swaps_++; 1035 pending_swaps_++;
983 swaps_with_current_output_surface_++; 1036 swaps_with_current_output_surface_++;
984 1037
985 DCHECK_LE(pending_swaps_, kMaxPendingSwaps); 1038 did_swap_in_last_frame_ = true;
986
987 did_perform_swap_in_last_draw_ = true;
988 last_frame_number_swap_performed_ = current_frame_number_; 1039 last_frame_number_swap_performed_ = current_frame_number_;
989 } 1040 }
990 1041
991 void SchedulerStateMachine::DidSwapBuffersComplete() { 1042 void SchedulerStateMachine::DidSwapBuffersComplete() {
992 TRACE_EVENT_ASYNC_END0("cc", "Scheduler:pending_swaps", this); 1043 TRACE_EVENT_ASYNC_END0("cc", "Scheduler:pending_swaps", this);
993 pending_swaps_--; 1044 pending_swaps_--;
994 } 1045 }
995 1046
996 void SchedulerStateMachine::SetTreePrioritiesAndScrollState( 1047 void SchedulerStateMachine::SetTreePrioritiesAndScrollState(
997 TreePriority tree_priority, 1048 TreePriority tree_priority,
(...skipping 15 matching lines...) Expand all
1013 critical_begin_main_frame_to_activate_is_fast_) 1064 critical_begin_main_frame_to_activate_is_fast_)
1014 return false; 1065 return false;
1015 1066
1016 // Don't wait for the main thread if we are prioritizing smoothness. 1067 // Don't wait for the main thread if we are prioritizing smoothness.
1017 if (SMOOTHNESS_TAKES_PRIORITY == tree_priority_) 1068 if (SMOOTHNESS_TAKES_PRIORITY == tree_priority_)
1018 return true; 1069 return true;
1019 1070
1020 return false; 1071 return false;
1021 } 1072 }
1022 1073
1023 void SchedulerStateMachine::DidDrawIfPossibleCompleted(DrawResult result) {
1024 switch (result) {
1025 case INVALID_RESULT:
1026 NOTREACHED() << "Uninitialized DrawResult.";
1027 break;
1028 case DRAW_ABORTED_CANT_DRAW:
1029 case DRAW_ABORTED_CONTEXT_LOST:
1030 NOTREACHED() << "Invalid return value from DrawAndSwapIfPossible:"
1031 << result;
1032 break;
1033 case DRAW_SUCCESS:
1034 consecutive_checkerboard_animations_ = 0;
1035 forced_redraw_state_ = FORCED_REDRAW_STATE_IDLE;
1036 break;
1037 case DRAW_ABORTED_CHECKERBOARD_ANIMATIONS:
1038 needs_redraw_ = true;
1039
1040 // If we're already in the middle of a redraw, we don't need to
1041 // restart it.
1042 if (forced_redraw_state_ != FORCED_REDRAW_STATE_IDLE)
1043 return;
1044
1045 needs_begin_main_frame_ = true;
1046 consecutive_checkerboard_animations_++;
1047 if (settings_.timeout_and_draw_when_animation_checkerboards &&
1048 consecutive_checkerboard_animations_ >=
1049 settings_.maximum_number_of_failed_draws_before_draw_is_forced) {
1050 consecutive_checkerboard_animations_ = 0;
1051 // We need to force a draw, but it doesn't make sense to do this until
1052 // we've committed and have new textures.
1053 forced_redraw_state_ = FORCED_REDRAW_STATE_WAITING_FOR_COMMIT;
1054 }
1055 break;
1056 case DRAW_ABORTED_MISSING_HIGH_RES_CONTENT:
1057 // It's not clear whether this missing content is because of missing
1058 // pictures (which requires a commit) or because of memory pressure
1059 // removing textures (which might not). To be safe, request a commit
1060 // anyway.
1061 needs_begin_main_frame_ = true;
1062 break;
1063 }
1064 }
1065
1066 void SchedulerStateMachine::SetNeedsBeginMainFrame() { 1074 void SchedulerStateMachine::SetNeedsBeginMainFrame() {
1067 needs_begin_main_frame_ = true; 1075 needs_begin_main_frame_ = true;
1068 } 1076 }
1069 1077
1070 void SchedulerStateMachine::SetNeedsOneBeginImplFrame() { 1078 void SchedulerStateMachine::SetNeedsOneBeginImplFrame() {
1071 needs_one_begin_impl_frame_ = true; 1079 needs_one_begin_impl_frame_ = true;
1072 } 1080 }
1073 1081
1074 void SchedulerStateMachine::NotifyReadyToCommit() { 1082 void SchedulerStateMachine::NotifyReadyToCommit() {
1075 DCHECK_EQ(begin_main_frame_state_, BEGIN_MAIN_FRAME_STATE_STARTED) 1083 DCHECK_EQ(begin_main_frame_state_, BEGIN_MAIN_FRAME_STATE_STARTED)
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
1151 case OUTPUT_SURFACE_ACTIVE: 1159 case OUTPUT_SURFACE_ACTIVE:
1152 case OUTPUT_SURFACE_WAITING_FOR_FIRST_COMMIT: 1160 case OUTPUT_SURFACE_WAITING_FOR_FIRST_COMMIT:
1153 case OUTPUT_SURFACE_WAITING_FOR_FIRST_ACTIVATION: 1161 case OUTPUT_SURFACE_WAITING_FOR_FIRST_ACTIVATION:
1154 return true; 1162 return true;
1155 } 1163 }
1156 NOTREACHED(); 1164 NOTREACHED();
1157 return false; 1165 return false;
1158 } 1166 }
1159 1167
1160 } // namespace cc 1168 } // namespace cc
OLDNEW
« no previous file with comments | « cc/scheduler/scheduler_state_machine.h ('k') | cc/scheduler/scheduler_state_machine_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698