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

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: Remove SetDrawResult and pass result as argument instead Created 5 years, 1 month 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 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 state->SetBoolean("main_thread_missed_last_deadline", 242 state->SetBoolean("main_thread_missed_last_deadline",
243 main_thread_missed_last_deadline_); 243 main_thread_missed_last_deadline_);
244 state->SetBoolean("skip_next_begin_main_frame_to_reduce_latency", 244 state->SetBoolean("skip_next_begin_main_frame_to_reduce_latency",
245 skip_next_begin_main_frame_to_reduce_latency_); 245 skip_next_begin_main_frame_to_reduce_latency_);
246 state->SetBoolean("children_need_begin_frames", children_need_begin_frames_); 246 state->SetBoolean("children_need_begin_frames", children_need_begin_frames_);
247 state->SetBoolean("video_needs_begin_frames", video_needs_begin_frames_); 247 state->SetBoolean("video_needs_begin_frames", video_needs_begin_frames_);
248 state->SetBoolean("defer_commits", defer_commits_); 248 state->SetBoolean("defer_commits", defer_commits_);
249 state->SetBoolean("last_commit_had_no_updates", last_commit_had_no_updates_); 249 state->SetBoolean("last_commit_had_no_updates", last_commit_had_no_updates_);
250 state->SetBoolean("did_request_swap_in_last_frame", 250 state->SetBoolean("did_request_swap_in_last_frame",
251 did_request_swap_in_last_frame_); 251 did_request_swap_in_last_frame_);
252 state->SetBoolean("did_perform_swap_in_last_draw", 252 state->SetBoolean("did_perform_swap_in_last_draw",
sunnyps 2015/11/24 22:42:44 nit: rename did_perform_swap_in_last_draw to did_s
brianderson 2015/11/24 23:19:38 Renamed to did_swap_in_last_frame to be consistent
253 did_perform_swap_in_last_draw_); 253 did_perform_swap_in_last_draw_);
254 state->EndDictionary(); 254 state->EndDictionary();
255 } 255 }
256 256
257 bool SchedulerStateMachine::PendingDrawsShouldBeAborted() const { 257 bool SchedulerStateMachine::PendingDrawsShouldBeAborted() const {
258 // Normally when |visible_| is false, pending activations will be forced and 258 // Normally when |visible_| is false, pending activations will be forced and
259 // draws will be aborted. However, when the embedder is Android WebView, 259 // draws will be aborted. However, when the embedder is Android WebView,
260 // software draws could be scheduled by the Android OS at any time and draws 260 // software draws could be scheduled by the Android OS at any time and draws
261 // should not be aborted in this case. 261 // should not be aborted in this case.
262 bool is_output_surface_lost = (output_surface_state_ == OUTPUT_SURFACE_NONE); 262 bool is_output_surface_lost = (output_surface_state_ == OUTPUT_SURFACE_NONE);
(...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after
641 641
642 if (forced_redraw_state_ == FORCED_REDRAW_STATE_WAITING_FOR_ACTIVATION) 642 if (forced_redraw_state_ == FORCED_REDRAW_STATE_WAITING_FOR_ACTIVATION)
643 forced_redraw_state_ = FORCED_REDRAW_STATE_WAITING_FOR_DRAW; 643 forced_redraw_state_ = FORCED_REDRAW_STATE_WAITING_FOR_DRAW;
644 644
645 has_pending_tree_ = false; 645 has_pending_tree_ = false;
646 pending_tree_is_ready_for_activation_ = false; 646 pending_tree_is_ready_for_activation_ = false;
647 active_tree_needs_first_draw_ = true; 647 active_tree_needs_first_draw_ = true;
648 needs_redraw_ = true; 648 needs_redraw_ = true;
649 } 649 }
650 650
651 void SchedulerStateMachine::WillDraw(bool did_request_swap) { 651 void SchedulerStateMachine::WillDraw() {
652 // We need to reset needs_redraw_ before we draw since the
653 // draw itself might request another draw.
654 needs_redraw_ = false;
655 }
656
657 void SchedulerStateMachine::DidDraw(bool did_request_swap,
658 DrawResult draw_result) {
659 active_tree_needs_first_draw_ = false;
660
652 if (forced_redraw_state_ == FORCED_REDRAW_STATE_WAITING_FOR_DRAW) 661 if (forced_redraw_state_ == FORCED_REDRAW_STATE_WAITING_FOR_DRAW)
653 forced_redraw_state_ = FORCED_REDRAW_STATE_IDLE; 662 forced_redraw_state_ = FORCED_REDRAW_STATE_IDLE;
654 663
655 if (begin_main_frame_state_ == BEGIN_MAIN_FRAME_STATE_WAITING_FOR_DRAW) 664 if (begin_main_frame_state_ == BEGIN_MAIN_FRAME_STATE_WAITING_FOR_DRAW)
656 begin_main_frame_state_ = BEGIN_MAIN_FRAME_STATE_IDLE; 665 begin_main_frame_state_ = BEGIN_MAIN_FRAME_STATE_IDLE;
657 666
658 needs_redraw_ = false;
659 active_tree_needs_first_draw_ = false;
660
661 if (did_request_swap) { 667 if (did_request_swap) {
sunnyps 2015/11/20 23:34:07 Doesn't draw_result != DRAW_SUCCESS imply that did
brianderson 2015/11/21 00:31:33 It's a bit confusing, and probably deserves some c
662 DCHECK(!request_swap_funnel_); 668 DCHECK(!request_swap_funnel_);
663 request_swap_funnel_ = true; 669 request_swap_funnel_ = true;
664 did_request_swap_in_last_frame_ = true; 670 did_request_swap_in_last_frame_ = true;
665 last_frame_number_swap_requested_ = current_frame_number_; 671 last_frame_number_swap_requested_ = current_frame_number_;
666 } 672 }
673
674 switch (draw_result) {
675 case INVALID_RESULT:
676 NOTREACHED() << "Uninitialized DrawResult.";
677 break;
678 case DRAW_ABORTED_CANT_DRAW:
679 case DRAW_ABORTED_CONTEXT_LOST:
680 NOTREACHED() << "Invalid return value from DrawAndSwapIfPossible:"
681 << draw_result;
682 break;
683 case DRAW_SUCCESS:
684 consecutive_checkerboard_animations_ = 0;
685 forced_redraw_state_ = FORCED_REDRAW_STATE_IDLE;
686 break;
687 case DRAW_ABORTED_CHECKERBOARD_ANIMATIONS:
688 needs_redraw_ = true;
689
690 // If we're already in the middle of a redraw, we don't need to
691 // restart it.
692 if (forced_redraw_state_ != FORCED_REDRAW_STATE_IDLE)
693 return;
694
695 needs_begin_main_frame_ = true;
696 consecutive_checkerboard_animations_++;
sunnyps 2015/11/20 23:34:07 nit: needs_begin_main_frame should be inside the i
brianderson 2015/11/21 00:31:33 Sg.
697 if (settings_.timeout_and_draw_when_animation_checkerboards &&
698 consecutive_checkerboard_animations_ >=
699 settings_.maximum_number_of_failed_draws_before_draw_is_forced) {
700 consecutive_checkerboard_animations_ = 0;
sunnyps 2015/11/20 23:34:07 nit: We shouldn't have to set consecutive_checkerb
brianderson 2015/11/21 00:31:33 Also sg.
701 // We need to force a draw, but it doesn't make sense to do this until
702 // we've committed and have new textures.
703 forced_redraw_state_ = FORCED_REDRAW_STATE_WAITING_FOR_COMMIT;
704 }
705 break;
706 case DRAW_ABORTED_MISSING_HIGH_RES_CONTENT:
707 // It's not clear whether this missing content is because of missing
708 // pictures (which requires a commit) or because of memory pressure
709 // removing textures (which might not). To be safe, request a commit
710 // anyway.
711 needs_begin_main_frame_ = true;
712 break;
713 }
667 } 714 }
668 715
669 void SchedulerStateMachine::WillPrepareTiles() { 716 void SchedulerStateMachine::WillPrepareTiles() {
670 needs_prepare_tiles_ = false; 717 needs_prepare_tiles_ = false;
671 } 718 }
672 719
673 void SchedulerStateMachine::WillBeginOutputSurfaceCreation() { 720 void SchedulerStateMachine::WillBeginOutputSurfaceCreation() {
674 DCHECK_EQ(output_surface_state_, OUTPUT_SURFACE_NONE); 721 DCHECK_EQ(output_surface_state_, OUTPUT_SURFACE_NONE);
675 output_surface_state_ = OUTPUT_SURFACE_CREATING; 722 output_surface_state_ = OUTPUT_SURFACE_CREATING;
676 723
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after
976 void SchedulerStateMachine::DidSwapBuffersComplete() { 1023 void SchedulerStateMachine::DidSwapBuffersComplete() {
977 TRACE_EVENT_ASYNC_END0("cc", "Scheduler:pending_swaps", this); 1024 TRACE_EVENT_ASYNC_END0("cc", "Scheduler:pending_swaps", this);
978 pending_swaps_--; 1025 pending_swaps_--;
979 } 1026 }
980 1027
981 void SchedulerStateMachine::SetImplLatencyTakesPriority( 1028 void SchedulerStateMachine::SetImplLatencyTakesPriority(
982 bool impl_latency_takes_priority) { 1029 bool impl_latency_takes_priority) {
983 impl_latency_takes_priority_ = impl_latency_takes_priority; 1030 impl_latency_takes_priority_ = impl_latency_takes_priority;
984 } 1031 }
985 1032
986 void SchedulerStateMachine::DidDrawIfPossibleCompleted(DrawResult result) {
987 switch (result) {
988 case INVALID_RESULT:
989 NOTREACHED() << "Uninitialized DrawResult.";
990 break;
991 case DRAW_ABORTED_CANT_DRAW:
992 case DRAW_ABORTED_CONTEXT_LOST:
993 NOTREACHED() << "Invalid return value from DrawAndSwapIfPossible:"
994 << result;
995 break;
996 case DRAW_SUCCESS:
997 consecutive_checkerboard_animations_ = 0;
998 forced_redraw_state_ = FORCED_REDRAW_STATE_IDLE;
999 break;
1000 case DRAW_ABORTED_CHECKERBOARD_ANIMATIONS:
1001 needs_redraw_ = true;
1002
1003 // If we're already in the middle of a redraw, we don't need to
1004 // restart it.
1005 if (forced_redraw_state_ != FORCED_REDRAW_STATE_IDLE)
1006 return;
1007
1008 needs_begin_main_frame_ = true;
1009 consecutive_checkerboard_animations_++;
1010 if (settings_.timeout_and_draw_when_animation_checkerboards &&
1011 consecutive_checkerboard_animations_ >=
1012 settings_.maximum_number_of_failed_draws_before_draw_is_forced) {
1013 consecutive_checkerboard_animations_ = 0;
1014 // We need to force a draw, but it doesn't make sense to do this until
1015 // we've committed and have new textures.
1016 forced_redraw_state_ = FORCED_REDRAW_STATE_WAITING_FOR_COMMIT;
1017 }
1018 break;
1019 case DRAW_ABORTED_MISSING_HIGH_RES_CONTENT:
1020 // It's not clear whether this missing content is because of missing
1021 // pictures (which requires a commit) or because of memory pressure
1022 // removing textures (which might not). To be safe, request a commit
1023 // anyway.
1024 needs_begin_main_frame_ = true;
1025 break;
1026 }
1027 }
1028
1029 void SchedulerStateMachine::SetNeedsBeginMainFrame() { 1033 void SchedulerStateMachine::SetNeedsBeginMainFrame() {
1030 needs_begin_main_frame_ = true; 1034 needs_begin_main_frame_ = true;
1031 } 1035 }
1032 1036
1033 void SchedulerStateMachine::SetNeedsOneBeginImplFrame() { 1037 void SchedulerStateMachine::SetNeedsOneBeginImplFrame() {
1034 needs_one_begin_impl_frame_ = true; 1038 needs_one_begin_impl_frame_ = true;
1035 } 1039 }
1036 1040
1037 void SchedulerStateMachine::NotifyReadyToCommit() { 1041 void SchedulerStateMachine::NotifyReadyToCommit() {
1038 DCHECK_EQ(begin_main_frame_state_, BEGIN_MAIN_FRAME_STATE_STARTED) 1042 DCHECK_EQ(begin_main_frame_state_, BEGIN_MAIN_FRAME_STATE_STARTED)
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
1114 case OUTPUT_SURFACE_ACTIVE: 1118 case OUTPUT_SURFACE_ACTIVE:
1115 case OUTPUT_SURFACE_WAITING_FOR_FIRST_COMMIT: 1119 case OUTPUT_SURFACE_WAITING_FOR_FIRST_COMMIT:
1116 case OUTPUT_SURFACE_WAITING_FOR_FIRST_ACTIVATION: 1120 case OUTPUT_SURFACE_WAITING_FOR_FIRST_ACTIVATION:
1117 return true; 1121 return true;
1118 } 1122 }
1119 NOTREACHED(); 1123 NOTREACHED();
1120 return false; 1124 return false;
1121 } 1125 }
1122 1126
1123 } // namespace cc 1127 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698