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

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

Issue 2632563003: [cc] Calculate the correct latest_confirmed_sequence_number in cc::Scheduler. (Closed)
Patch Set: Fix handling of source_id changes and add some Scheduler tests. Created 3 years, 11 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 "cc/output/begin_frame_args.h"
13 14
14 namespace cc { 15 namespace cc {
15 16
16 namespace { 17 namespace {
17 // Surfaces and CompositorTimingHistory don't support more than 1 pending swap. 18 // Surfaces and CompositorTimingHistory don't support more than 1 pending swap.
18 const int kMaxPendingSubmitFrames = 1; 19 const int kMaxPendingSubmitFrames = 1;
19 } // namespace 20 } // namespace
20 21
21 SchedulerStateMachine::SchedulerStateMachine(const SchedulerSettings& settings) 22 SchedulerStateMachine::SchedulerStateMachine(const SchedulerSettings& settings)
22 : settings_(settings), 23 : settings_(settings),
23 compositor_frame_sink_state_(COMPOSITOR_FRAME_SINK_NONE), 24 compositor_frame_sink_state_(COMPOSITOR_FRAME_SINK_NONE),
24 begin_impl_frame_state_(BEGIN_IMPL_FRAME_STATE_IDLE), 25 begin_impl_frame_state_(BEGIN_IMPL_FRAME_STATE_IDLE),
25 begin_main_frame_state_(BEGIN_MAIN_FRAME_STATE_IDLE), 26 begin_main_frame_state_(BEGIN_MAIN_FRAME_STATE_IDLE),
26 forced_redraw_state_(FORCED_REDRAW_STATE_IDLE), 27 forced_redraw_state_(FORCED_REDRAW_STATE_IDLE),
28 begin_frame_source_id_(0),
29 begin_frame_sequence_number_(BeginFrameArgs::kStartingFrameNumber),
30 last_begin_frame_sequence_number_begin_main_frame_sent_(
31 BeginFrameArgs::kInvalidFrameNumber),
32 last_begin_frame_sequence_number_pending_tree_was_fresh_(
33 BeginFrameArgs::kInvalidFrameNumber),
34 last_begin_frame_sequence_number_active_tree_was_fresh_(
35 BeginFrameArgs::kInvalidFrameNumber),
36 last_begin_frame_sequence_number_compositor_frame_was_fresh_(
37 BeginFrameArgs::kInvalidFrameNumber),
27 commit_count_(0), 38 commit_count_(0),
28 current_frame_number_(0), 39 current_frame_number_(0),
29 last_frame_number_submit_performed_(-1), 40 last_frame_number_submit_performed_(-1),
30 last_frame_number_draw_performed_(-1), 41 last_frame_number_draw_performed_(-1),
31 last_frame_number_begin_main_frame_sent_(-1), 42 last_frame_number_begin_main_frame_sent_(-1),
32 last_frame_number_invalidate_compositor_frame_sink_performed_(-1), 43 last_frame_number_invalidate_compositor_frame_sink_performed_(-1),
33 draw_funnel_(false), 44 draw_funnel_(false),
34 send_begin_main_frame_funnel_(true), 45 send_begin_main_frame_funnel_(true),
35 invalidate_compositor_frame_sink_funnel_(false), 46 invalidate_compositor_frame_sink_funnel_(false),
36 prepare_tiles_funnel_(0), 47 prepare_tiles_funnel_(0),
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 218
208 state->BeginDictionary("minor_state"); 219 state->BeginDictionary("minor_state");
209 state->SetInteger("commit_count", commit_count_); 220 state->SetInteger("commit_count", commit_count_);
210 state->SetInteger("current_frame_number", current_frame_number_); 221 state->SetInteger("current_frame_number", current_frame_number_);
211 state->SetInteger("last_frame_number_submit_performed", 222 state->SetInteger("last_frame_number_submit_performed",
212 last_frame_number_submit_performed_); 223 last_frame_number_submit_performed_);
213 state->SetInteger("last_frame_number_draw_performed", 224 state->SetInteger("last_frame_number_draw_performed",
214 last_frame_number_draw_performed_); 225 last_frame_number_draw_performed_);
215 state->SetInteger("last_frame_number_begin_main_frame_sent", 226 state->SetInteger("last_frame_number_begin_main_frame_sent",
216 last_frame_number_begin_main_frame_sent_); 227 last_frame_number_begin_main_frame_sent_);
228 state->SetInteger("begin_frame_source_id", begin_frame_source_id_);
229 state->SetInteger("begin_frame_sequence_number",
230 begin_frame_sequence_number_);
231 state->SetInteger("last_begin_frame_sequence_number_begin_main_frame_sent",
232 last_begin_frame_sequence_number_begin_main_frame_sent_);
233 state->SetInteger("last_begin_frame_sequence_number_pending_tree_was_fresh",
234 last_begin_frame_sequence_number_pending_tree_was_fresh_);
235 state->SetInteger("last_begin_frame_sequence_number_active_tree_was_fresh",
236 last_begin_frame_sequence_number_active_tree_was_fresh_);
237 state->SetInteger(
238 "last_begin_frame_sequence_number_compositor_frame_was_fresh",
239 last_begin_frame_sequence_number_compositor_frame_was_fresh_);
217 state->SetBoolean("funnel: draw_funnel", draw_funnel_); 240 state->SetBoolean("funnel: draw_funnel", draw_funnel_);
218 state->SetBoolean("funnel: send_begin_main_frame_funnel", 241 state->SetBoolean("funnel: send_begin_main_frame_funnel",
219 send_begin_main_frame_funnel_); 242 send_begin_main_frame_funnel_);
220 state->SetInteger("funnel: prepare_tiles_funnel", prepare_tiles_funnel_); 243 state->SetInteger("funnel: prepare_tiles_funnel", prepare_tiles_funnel_);
221 state->SetBoolean("funnel: invalidate_compositor_frame_sink_funnel", 244 state->SetBoolean("funnel: invalidate_compositor_frame_sink_funnel",
222 invalidate_compositor_frame_sink_funnel_); 245 invalidate_compositor_frame_sink_funnel_);
223 state->SetInteger("consecutive_checkerboard_animations", 246 state->SetInteger("consecutive_checkerboard_animations",
224 consecutive_checkerboard_animations_); 247 consecutive_checkerboard_animations_);
225 state->SetInteger("pending_submit_frames_", pending_submit_frames_); 248 state->SetInteger("pending_submit_frames_", pending_submit_frames_);
226 state->SetInteger("submit_frames_with_current_compositor_frame_sink", 249 state->SetInteger("submit_frames_with_current_compositor_frame_sink",
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after
572 595
573 void SchedulerStateMachine::WillSendBeginMainFrame() { 596 void SchedulerStateMachine::WillSendBeginMainFrame() {
574 DCHECK(!has_pending_tree_ || settings_.main_frame_before_activation_enabled); 597 DCHECK(!has_pending_tree_ || settings_.main_frame_before_activation_enabled);
575 DCHECK(visible_); 598 DCHECK(visible_);
576 DCHECK(!begin_frame_source_paused_); 599 DCHECK(!begin_frame_source_paused_);
577 DCHECK(!send_begin_main_frame_funnel_); 600 DCHECK(!send_begin_main_frame_funnel_);
578 begin_main_frame_state_ = BEGIN_MAIN_FRAME_STATE_SENT; 601 begin_main_frame_state_ = BEGIN_MAIN_FRAME_STATE_SENT;
579 needs_begin_main_frame_ = false; 602 needs_begin_main_frame_ = false;
580 send_begin_main_frame_funnel_ = true; 603 send_begin_main_frame_funnel_ = true;
581 last_frame_number_begin_main_frame_sent_ = current_frame_number_; 604 last_frame_number_begin_main_frame_sent_ = current_frame_number_;
605 last_begin_frame_sequence_number_begin_main_frame_sent_ =
606 begin_frame_sequence_number_;
582 } 607 }
583 608
584 void SchedulerStateMachine::WillCommit(bool commit_has_no_updates) { 609 void SchedulerStateMachine::WillCommit(bool commit_has_no_updates) {
585 DCHECK(!has_pending_tree_ || 610 DCHECK(!has_pending_tree_ ||
586 (settings_.main_frame_before_activation_enabled && 611 (settings_.main_frame_before_activation_enabled &&
587 commit_has_no_updates)); 612 commit_has_no_updates));
588 commit_count_++; 613 commit_count_++;
589 last_commit_had_no_updates_ = commit_has_no_updates; 614 last_commit_had_no_updates_ = commit_has_no_updates;
590 begin_main_frame_state_ = BEGIN_MAIN_FRAME_STATE_IDLE; 615 begin_main_frame_state_ = BEGIN_MAIN_FRAME_STATE_IDLE;
591 616
592 if (!commit_has_no_updates) { 617 if (commit_has_no_updates) {
593 // Pending tree only exists if commit had updates. 618 // Pending tree might still exist from prior commit.
619 if (has_pending_tree_) {
620 DCHECK(settings_.main_frame_before_activation_enabled);
621 last_begin_frame_sequence_number_pending_tree_was_fresh_ =
622 last_begin_frame_sequence_number_begin_main_frame_sent_;
623 } else {
624 last_begin_frame_sequence_number_active_tree_was_fresh_ =
625 last_begin_frame_sequence_number_begin_main_frame_sent_;
626 }
627 } else {
628 // We have a new pending tree.
594 has_pending_tree_ = true; 629 has_pending_tree_ = true;
595 pending_tree_is_ready_for_activation_ = false; 630 pending_tree_is_ready_for_activation_ = false;
631 last_begin_frame_sequence_number_pending_tree_was_fresh_ =
632 last_begin_frame_sequence_number_begin_main_frame_sent_;
596 wait_for_ready_to_draw_ = settings_.commit_to_active_tree; 633 wait_for_ready_to_draw_ = settings_.commit_to_active_tree;
597 } 634 }
598 635
599 // Update state related to forced draws. 636 // Update state related to forced draws.
600 if (forced_redraw_state_ == FORCED_REDRAW_STATE_WAITING_FOR_COMMIT) { 637 if (forced_redraw_state_ == FORCED_REDRAW_STATE_WAITING_FOR_COMMIT) {
601 forced_redraw_state_ = has_pending_tree_ 638 forced_redraw_state_ = has_pending_tree_
602 ? FORCED_REDRAW_STATE_WAITING_FOR_ACTIVATION 639 ? FORCED_REDRAW_STATE_WAITING_FOR_ACTIVATION
603 : FORCED_REDRAW_STATE_WAITING_FOR_DRAW; 640 : FORCED_REDRAW_STATE_WAITING_FOR_DRAW;
604 } 641 }
605 642
(...skipping 11 matching lines...) Expand all
617 COMPOSITOR_FRAME_SINK_WAITING_FOR_FIRST_ACTIVATION) 654 COMPOSITOR_FRAME_SINK_WAITING_FOR_FIRST_ACTIVATION)
618 compositor_frame_sink_state_ = COMPOSITOR_FRAME_SINK_ACTIVE; 655 compositor_frame_sink_state_ = COMPOSITOR_FRAME_SINK_ACTIVE;
619 656
620 if (forced_redraw_state_ == FORCED_REDRAW_STATE_WAITING_FOR_ACTIVATION) 657 if (forced_redraw_state_ == FORCED_REDRAW_STATE_WAITING_FOR_ACTIVATION)
621 forced_redraw_state_ = FORCED_REDRAW_STATE_WAITING_FOR_DRAW; 658 forced_redraw_state_ = FORCED_REDRAW_STATE_WAITING_FOR_DRAW;
622 659
623 has_pending_tree_ = false; 660 has_pending_tree_ = false;
624 pending_tree_is_ready_for_activation_ = false; 661 pending_tree_is_ready_for_activation_ = false;
625 active_tree_needs_first_draw_ = true; 662 active_tree_needs_first_draw_ = true;
626 needs_redraw_ = true; 663 needs_redraw_ = true;
664 last_begin_frame_sequence_number_active_tree_was_fresh_ =
665 last_begin_frame_sequence_number_pending_tree_was_fresh_;
627 } 666 }
628 667
629 void SchedulerStateMachine::WillDrawInternal() { 668 void SchedulerStateMachine::WillDrawInternal() {
630 // If a new active tree is pending after the one we are about to draw, 669 // If a new active tree is pending after the one we are about to draw,
631 // the main thread is in a high latency mode. 670 // the main thread is in a high latency mode.
632 // main_thread_missed_last_deadline_ is here in addition to 671 // main_thread_missed_last_deadline_ is here in addition to
633 // OnBeginImplFrameIdle for cases where the scheduler aborts draws outside 672 // OnBeginImplFrameIdle for cases where the scheduler aborts draws outside
634 // of the deadline. 673 // of the deadline.
635 main_thread_missed_last_deadline_ = CommitPending() || has_pending_tree_; 674 main_thread_missed_last_deadline_ = CommitPending() || has_pending_tree_;
636 675
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
817 return true; 856 return true;
818 857
819 // If the last commit was aborted because of early out (no updates), we should 858 // If the last commit was aborted because of early out (no updates), we should
820 // still want a begin frame in case there is a commit coming again. 859 // still want a begin frame in case there is a commit coming again.
821 if (last_commit_had_no_updates_) 860 if (last_commit_had_no_updates_)
822 return true; 861 return true;
823 862
824 return false; 863 return false;
825 } 864 }
826 865
827 void SchedulerStateMachine::OnBeginImplFrame() { 866 void SchedulerStateMachine::OnBeginFrameDroppedNotObserving(
867 uint32_t source_id,
868 uint64_t sequence_number) {
869 DCHECK(!BeginFrameNeeded());
870 DCHECK_EQ(BEGIN_IMPL_FRAME_STATE_IDLE, begin_impl_frame_state_);
871
872 // Confirms the dropped BeginFrame, since we don't have updates.
873 UpdateBeginFrameSequenceNumbersForBeginFrame(source_id, sequence_number);
874 UpdateBeginFrameSequenceNumbersForBeginFrameDeadline();
875 }
876
877 void SchedulerStateMachine::UpdateBeginFrameSequenceNumbersForBeginFrame(
878 uint32_t source_id,
879 uint64_t sequence_number) {
880 if (source_id != begin_frame_source_id_) {
881 begin_frame_source_id_ = source_id;
882 begin_frame_sequence_number_ = sequence_number;
883
884 // Reset freshness sequence numbers.
885 last_begin_frame_sequence_number_begin_main_frame_sent_ =
886 BeginFrameArgs::kInvalidFrameNumber;
887 last_begin_frame_sequence_number_active_tree_was_fresh_ =
888 BeginFrameArgs::kInvalidFrameNumber;
889 last_begin_frame_sequence_number_pending_tree_was_fresh_ =
890 BeginFrameArgs::kInvalidFrameNumber;
891 last_begin_frame_sequence_number_compositor_frame_was_fresh_ =
892 BeginFrameArgs::kInvalidFrameNumber;
893 } else {
894 DCHECK_GE(sequence_number, begin_frame_sequence_number_);
895 begin_frame_sequence_number_ = sequence_number;
896 }
897 }
898
899 void SchedulerStateMachine::
900 UpdateBeginFrameSequenceNumbersForBeginFrameDeadline() {
901 // Update frame numbers for freshness in case no updates were necessary.
902 if (begin_main_frame_state_ == BEGIN_MAIN_FRAME_STATE_IDLE &&
903 !needs_begin_main_frame_) {
904 if (has_pending_tree_) {
905 last_begin_frame_sequence_number_pending_tree_was_fresh_ =
906 begin_frame_sequence_number_;
907 } else {
908 last_begin_frame_sequence_number_active_tree_was_fresh_ =
909 begin_frame_sequence_number_;
910
911 if (!needs_redraw_)
912 last_begin_frame_sequence_number_compositor_frame_was_fresh_ =
913 begin_frame_sequence_number_;
914 }
915 }
916 }
917
918 void SchedulerStateMachine::OnBeginImplFrame(uint32_t source_id,
919 uint64_t sequence_number) {
920 UpdateBeginFrameSequenceNumbersForBeginFrame(source_id, sequence_number);
921
828 begin_impl_frame_state_ = BEGIN_IMPL_FRAME_STATE_INSIDE_BEGIN_FRAME; 922 begin_impl_frame_state_ = BEGIN_IMPL_FRAME_STATE_INSIDE_BEGIN_FRAME;
829 current_frame_number_++; 923 current_frame_number_++;
830 924
831 last_commit_had_no_updates_ = false; 925 last_commit_had_no_updates_ = false;
832 did_draw_in_last_frame_ = false; 926 did_draw_in_last_frame_ = false;
833 did_submit_in_last_frame_ = false; 927 did_submit_in_last_frame_ = false;
834 needs_one_begin_impl_frame_ = false; 928 needs_one_begin_impl_frame_ = false;
835 929
836 // Clear funnels for any actions we perform during the frame. 930 // Clear funnels for any actions we perform during the frame.
837 send_begin_main_frame_funnel_ = false; 931 send_begin_main_frame_funnel_ = false;
838 invalidate_compositor_frame_sink_funnel_ = false; 932 invalidate_compositor_frame_sink_funnel_ = false;
839 933
840 // "Drain" the PrepareTiles funnel. 934 // "Drain" the PrepareTiles funnel.
841 if (prepare_tiles_funnel_ > 0) 935 if (prepare_tiles_funnel_ > 0)
842 prepare_tiles_funnel_--; 936 prepare_tiles_funnel_--;
843 } 937 }
844 938
845 void SchedulerStateMachine::OnBeginImplFrameDeadline() { 939 void SchedulerStateMachine::OnBeginImplFrameDeadline() {
846 begin_impl_frame_state_ = BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE; 940 begin_impl_frame_state_ = BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE;
847 941
848 // Clear funnels for any actions we perform during the deadline. 942 // Clear funnels for any actions we perform during the deadline.
849 draw_funnel_ = false; 943 draw_funnel_ = false;
850 944
851 // Allow one PrepareTiles per draw for synchronous compositor. 945 // Allow one PrepareTiles per draw for synchronous compositor.
852 if (settings_.using_synchronous_renderer_compositor) { 946 if (settings_.using_synchronous_renderer_compositor) {
853 if (prepare_tiles_funnel_ > 0) 947 if (prepare_tiles_funnel_ > 0)
854 prepare_tiles_funnel_--; 948 prepare_tiles_funnel_--;
855 } 949 }
950
951 UpdateBeginFrameSequenceNumbersForBeginFrameDeadline();
856 } 952 }
857 953
858 void SchedulerStateMachine::OnBeginImplFrameIdle() { 954 void SchedulerStateMachine::OnBeginImplFrameIdle() {
859 begin_impl_frame_state_ = BEGIN_IMPL_FRAME_STATE_IDLE; 955 begin_impl_frame_state_ = BEGIN_IMPL_FRAME_STATE_IDLE;
860 956
861 skip_next_begin_main_frame_to_reduce_latency_ = false; 957 skip_next_begin_main_frame_to_reduce_latency_ = false;
862 958
863 // If a new or undrawn active tree is pending after the deadline, 959 // If a new or undrawn active tree is pending after the deadline,
864 // then the main thread is in a high latency mode. 960 // then the main thread is in a high latency mode.
865 main_thread_missed_last_deadline_ = 961 main_thread_missed_last_deadline_ =
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
978 void SchedulerStateMachine::DidSubmitCompositorFrame() { 1074 void SchedulerStateMachine::DidSubmitCompositorFrame() {
979 TRACE_EVENT_ASYNC_BEGIN1("cc", "Scheduler:pending_submit_frames", this, 1075 TRACE_EVENT_ASYNC_BEGIN1("cc", "Scheduler:pending_submit_frames", this,
980 "pending_frames", pending_submit_frames_); 1076 "pending_frames", pending_submit_frames_);
981 DCHECK_LT(pending_submit_frames_, kMaxPendingSubmitFrames); 1077 DCHECK_LT(pending_submit_frames_, kMaxPendingSubmitFrames);
982 1078
983 pending_submit_frames_++; 1079 pending_submit_frames_++;
984 submit_frames_with_current_compositor_frame_sink_++; 1080 submit_frames_with_current_compositor_frame_sink_++;
985 1081
986 did_submit_in_last_frame_ = true; 1082 did_submit_in_last_frame_ = true;
987 last_frame_number_submit_performed_ = current_frame_number_; 1083 last_frame_number_submit_performed_ = current_frame_number_;
1084 last_begin_frame_sequence_number_compositor_frame_was_fresh_ =
1085 last_begin_frame_sequence_number_active_tree_was_fresh_;
988 } 1086 }
989 1087
990 void SchedulerStateMachine::DidReceiveCompositorFrameAck() { 1088 void SchedulerStateMachine::DidReceiveCompositorFrameAck() {
991 TRACE_EVENT_ASYNC_END1("cc", "Scheduler:pending_submit_frames", this, 1089 TRACE_EVENT_ASYNC_END1("cc", "Scheduler:pending_submit_frames", this,
992 "pending_frames", pending_submit_frames_); 1090 "pending_frames", pending_submit_frames_);
993 pending_submit_frames_--; 1091 pending_submit_frames_--;
994 } 1092 }
995 1093
996 void SchedulerStateMachine::SetTreePrioritiesAndScrollState( 1094 void SchedulerStateMachine::SetTreePrioritiesAndScrollState(
997 TreePriority tree_priority, 1095 TreePriority tree_priority,
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
1112 case COMPOSITOR_FRAME_SINK_ACTIVE: 1210 case COMPOSITOR_FRAME_SINK_ACTIVE:
1113 case COMPOSITOR_FRAME_SINK_WAITING_FOR_FIRST_COMMIT: 1211 case COMPOSITOR_FRAME_SINK_WAITING_FOR_FIRST_COMMIT:
1114 case COMPOSITOR_FRAME_SINK_WAITING_FOR_FIRST_ACTIVATION: 1212 case COMPOSITOR_FRAME_SINK_WAITING_FOR_FIRST_ACTIVATION:
1115 return true; 1213 return true;
1116 } 1214 }
1117 NOTREACHED(); 1215 NOTREACHED();
1118 return false; 1216 return false;
1119 } 1217 }
1120 1218
1121 } // namespace cc 1219 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698