Chromium Code Reviews| OLD | NEW |
|---|---|
| 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), |
| 27 commit_count_(0), | 28 commit_count_(0), |
| 28 current_frame_number_(0), | 29 begin_frame_source_id_(0), |
| 29 last_frame_number_submit_performed_(-1), | 30 current_frame_number_(BeginFrameArgs::kStartingFrameNumber), |
| 30 last_frame_number_draw_performed_(-1), | 31 last_frame_number_submit_performed_(BeginFrameArgs::kInvalidFrameNumber), |
| 31 last_frame_number_begin_main_frame_sent_(-1), | 32 last_frame_number_draw_performed_(BeginFrameArgs::kInvalidFrameNumber), |
| 32 last_frame_number_invalidate_compositor_frame_sink_performed_(-1), | 33 last_frame_number_begin_main_frame_sent_( |
| 34 BeginFrameArgs::kInvalidFrameNumber), | |
| 35 last_frame_number_invalidate_compositor_frame_sink_performed_( | |
| 36 BeginFrameArgs::kInvalidFrameNumber), | |
| 37 last_frame_number_pending_tree_was_fresh_( | |
| 38 BeginFrameArgs::kInvalidFrameNumber), | |
| 39 last_frame_number_active_tree_was_fresh_( | |
| 40 BeginFrameArgs::kInvalidFrameNumber), | |
| 41 last_frame_number_compositor_frame_was_fresh_( | |
| 42 BeginFrameArgs::kInvalidFrameNumber), | |
| 33 draw_funnel_(false), | 43 draw_funnel_(false), |
| 34 send_begin_main_frame_funnel_(true), | 44 send_begin_main_frame_funnel_(true), |
| 35 invalidate_compositor_frame_sink_funnel_(false), | 45 invalidate_compositor_frame_sink_funnel_(false), |
| 36 prepare_tiles_funnel_(0), | 46 prepare_tiles_funnel_(0), |
| 37 consecutive_checkerboard_animations_(0), | 47 consecutive_checkerboard_animations_(0), |
| 38 pending_submit_frames_(0), | 48 pending_submit_frames_(0), |
| 39 submit_frames_with_current_compositor_frame_sink_(0), | 49 submit_frames_with_current_compositor_frame_sink_(0), |
| 40 needs_redraw_(false), | 50 needs_redraw_(false), |
| 41 needs_prepare_tiles_(false), | 51 needs_prepare_tiles_(false), |
| 42 needs_begin_main_frame_(false), | 52 needs_begin_main_frame_(false), |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 200 BeginMainFrameStateToString(begin_main_frame_state_)); | 210 BeginMainFrameStateToString(begin_main_frame_state_)); |
| 201 state->SetString( | 211 state->SetString( |
| 202 "compositor_frame_sink_state_", | 212 "compositor_frame_sink_state_", |
| 203 CompositorFrameSinkStateToString(compositor_frame_sink_state_)); | 213 CompositorFrameSinkStateToString(compositor_frame_sink_state_)); |
| 204 state->SetString("forced_redraw_state", | 214 state->SetString("forced_redraw_state", |
| 205 ForcedRedrawOnTimeoutStateToString(forced_redraw_state_)); | 215 ForcedRedrawOnTimeoutStateToString(forced_redraw_state_)); |
| 206 state->EndDictionary(); | 216 state->EndDictionary(); |
| 207 | 217 |
| 208 state->BeginDictionary("minor_state"); | 218 state->BeginDictionary("minor_state"); |
| 209 state->SetInteger("commit_count", commit_count_); | 219 state->SetInteger("commit_count", commit_count_); |
| 220 state->SetInteger("begin_frame_source_id", begin_frame_source_id_); | |
| 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("last_frame_number_pending_tree_was_fresh", | |
| 229 last_frame_number_pending_tree_was_fresh_); | |
| 230 state->SetInteger("last_frame_number_active_tree_was_fresh", | |
| 231 last_frame_number_active_tree_was_fresh_); | |
| 232 state->SetInteger("last_frame_number_compositor_frame_was_fresh", | |
| 233 last_frame_number_compositor_frame_was_fresh_); | |
| 217 state->SetBoolean("funnel: draw_funnel", draw_funnel_); | 234 state->SetBoolean("funnel: draw_funnel", draw_funnel_); |
| 218 state->SetBoolean("funnel: send_begin_main_frame_funnel", | 235 state->SetBoolean("funnel: send_begin_main_frame_funnel", |
| 219 send_begin_main_frame_funnel_); | 236 send_begin_main_frame_funnel_); |
| 220 state->SetInteger("funnel: prepare_tiles_funnel", prepare_tiles_funnel_); | 237 state->SetInteger("funnel: prepare_tiles_funnel", prepare_tiles_funnel_); |
| 221 state->SetBoolean("funnel: invalidate_compositor_frame_sink_funnel", | 238 state->SetBoolean("funnel: invalidate_compositor_frame_sink_funnel", |
| 222 invalidate_compositor_frame_sink_funnel_); | 239 invalidate_compositor_frame_sink_funnel_); |
| 223 state->SetInteger("consecutive_checkerboard_animations", | 240 state->SetInteger("consecutive_checkerboard_animations", |
| 224 consecutive_checkerboard_animations_); | 241 consecutive_checkerboard_animations_); |
| 225 state->SetInteger("pending_submit_frames_", pending_submit_frames_); | 242 state->SetInteger("pending_submit_frames_", pending_submit_frames_); |
| 226 state->SetInteger("submit_frames_with_current_compositor_frame_sink", | 243 state->SetInteger("submit_frames_with_current_compositor_frame_sink", |
| (...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 582 } | 599 } |
| 583 | 600 |
| 584 void SchedulerStateMachine::WillCommit(bool commit_has_no_updates) { | 601 void SchedulerStateMachine::WillCommit(bool commit_has_no_updates) { |
| 585 DCHECK(!has_pending_tree_ || | 602 DCHECK(!has_pending_tree_ || |
| 586 (settings_.main_frame_before_activation_enabled && | 603 (settings_.main_frame_before_activation_enabled && |
| 587 commit_has_no_updates)); | 604 commit_has_no_updates)); |
| 588 commit_count_++; | 605 commit_count_++; |
| 589 last_commit_had_no_updates_ = commit_has_no_updates; | 606 last_commit_had_no_updates_ = commit_has_no_updates; |
| 590 begin_main_frame_state_ = BEGIN_MAIN_FRAME_STATE_IDLE; | 607 begin_main_frame_state_ = BEGIN_MAIN_FRAME_STATE_IDLE; |
| 591 | 608 |
| 592 if (!commit_has_no_updates) { | 609 if (commit_has_no_updates) { |
| 593 // Pending tree only exists if commit had updates. | 610 // Pending tree might still exist from prior commit. |
| 611 if (has_pending_tree_) { | |
| 612 DCHECK(settings_.main_frame_before_activation_enabled); | |
| 613 last_frame_number_pending_tree_was_fresh_ = | |
| 614 last_frame_number_begin_main_frame_sent_; | |
| 615 } else { | |
| 616 last_frame_number_active_tree_was_fresh_ = | |
| 617 last_frame_number_begin_main_frame_sent_; | |
| 618 } | |
| 619 } else { | |
| 620 // We have a new pending tree. | |
| 594 has_pending_tree_ = true; | 621 has_pending_tree_ = true; |
| 595 pending_tree_is_ready_for_activation_ = false; | 622 pending_tree_is_ready_for_activation_ = false; |
| 623 last_frame_number_pending_tree_was_fresh_ = | |
| 624 last_frame_number_begin_main_frame_sent_; | |
| 596 wait_for_ready_to_draw_ = settings_.commit_to_active_tree; | 625 wait_for_ready_to_draw_ = settings_.commit_to_active_tree; |
| 597 } | 626 } |
| 598 | 627 |
| 599 // Update state related to forced draws. | 628 // Update state related to forced draws. |
| 600 if (forced_redraw_state_ == FORCED_REDRAW_STATE_WAITING_FOR_COMMIT) { | 629 if (forced_redraw_state_ == FORCED_REDRAW_STATE_WAITING_FOR_COMMIT) { |
| 601 forced_redraw_state_ = has_pending_tree_ | 630 forced_redraw_state_ = has_pending_tree_ |
| 602 ? FORCED_REDRAW_STATE_WAITING_FOR_ACTIVATION | 631 ? FORCED_REDRAW_STATE_WAITING_FOR_ACTIVATION |
| 603 : FORCED_REDRAW_STATE_WAITING_FOR_DRAW; | 632 : FORCED_REDRAW_STATE_WAITING_FOR_DRAW; |
| 604 } | 633 } |
| 605 | 634 |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 617 COMPOSITOR_FRAME_SINK_WAITING_FOR_FIRST_ACTIVATION) | 646 COMPOSITOR_FRAME_SINK_WAITING_FOR_FIRST_ACTIVATION) |
| 618 compositor_frame_sink_state_ = COMPOSITOR_FRAME_SINK_ACTIVE; | 647 compositor_frame_sink_state_ = COMPOSITOR_FRAME_SINK_ACTIVE; |
| 619 | 648 |
| 620 if (forced_redraw_state_ == FORCED_REDRAW_STATE_WAITING_FOR_ACTIVATION) | 649 if (forced_redraw_state_ == FORCED_REDRAW_STATE_WAITING_FOR_ACTIVATION) |
| 621 forced_redraw_state_ = FORCED_REDRAW_STATE_WAITING_FOR_DRAW; | 650 forced_redraw_state_ = FORCED_REDRAW_STATE_WAITING_FOR_DRAW; |
| 622 | 651 |
| 623 has_pending_tree_ = false; | 652 has_pending_tree_ = false; |
| 624 pending_tree_is_ready_for_activation_ = false; | 653 pending_tree_is_ready_for_activation_ = false; |
| 625 active_tree_needs_first_draw_ = true; | 654 active_tree_needs_first_draw_ = true; |
| 626 needs_redraw_ = true; | 655 needs_redraw_ = true; |
| 656 last_frame_number_active_tree_was_fresh_ = | |
| 657 last_frame_number_pending_tree_was_fresh_; | |
| 627 } | 658 } |
| 628 | 659 |
| 629 void SchedulerStateMachine::WillDrawInternal() { | 660 void SchedulerStateMachine::WillDrawInternal() { |
| 630 // If a new active tree is pending after the one we are about to draw, | 661 // 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. | 662 // the main thread is in a high latency mode. |
| 632 // main_thread_missed_last_deadline_ is here in addition to | 663 // main_thread_missed_last_deadline_ is here in addition to |
| 633 // OnBeginImplFrameIdle for cases where the scheduler aborts draws outside | 664 // OnBeginImplFrameIdle for cases where the scheduler aborts draws outside |
| 634 // of the deadline. | 665 // of the deadline. |
| 635 main_thread_missed_last_deadline_ = CommitPending() || has_pending_tree_; | 666 main_thread_missed_last_deadline_ = CommitPending() || has_pending_tree_; |
| 636 | 667 |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 817 return true; | 848 return true; |
| 818 | 849 |
| 819 // If the last commit was aborted because of early out (no updates), we should | 850 // 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. | 851 // still want a begin frame in case there is a commit coming again. |
| 821 if (last_commit_had_no_updates_) | 852 if (last_commit_had_no_updates_) |
| 822 return true; | 853 return true; |
| 823 | 854 |
| 824 return false; | 855 return false; |
| 825 } | 856 } |
| 826 | 857 |
| 827 void SchedulerStateMachine::OnBeginImplFrame() { | 858 void SchedulerStateMachine::OnBeginImplFrame(uint32_t source_id, |
| 859 uint64_t sequence_number) { | |
| 860 if (source_id != begin_frame_source_id_) { | |
| 861 begin_frame_source_id_ = source_id; | |
| 862 current_frame_number_ = sequence_number; | |
|
brianderson
2017/01/13 19:13:49
I think it would be nice to keep the frame_number
Eric Seckler
2017/01/16 14:33:01
Tracking BeginFrame sequence numbers separately fr
| |
| 863 | |
| 864 // Consider us up to date up to the previous BeginFrame. | |
| 865 DCHECK_LE(BeginFrameArgs::kStartingFrameNumber, current_frame_number_); | |
| 866 last_frame_number_active_tree_was_fresh_ = current_frame_number_ - 1; | |
| 867 last_frame_number_pending_tree_was_fresh_ = | |
| 868 last_frame_number_active_tree_was_fresh_; | |
| 869 last_frame_number_compositor_frame_was_fresh_ = | |
| 870 last_frame_number_active_tree_was_fresh_; | |
| 871 } | |
| 872 | |
| 873 DCHECK_GE(sequence_number, current_frame_number_); | |
| 828 begin_impl_frame_state_ = BEGIN_IMPL_FRAME_STATE_INSIDE_BEGIN_FRAME; | 874 begin_impl_frame_state_ = BEGIN_IMPL_FRAME_STATE_INSIDE_BEGIN_FRAME; |
| 829 current_frame_number_++; | 875 current_frame_number_ = sequence_number; |
| 830 | 876 |
| 831 last_commit_had_no_updates_ = false; | 877 last_commit_had_no_updates_ = false; |
| 832 did_draw_in_last_frame_ = false; | 878 did_draw_in_last_frame_ = false; |
| 833 did_submit_in_last_frame_ = false; | 879 did_submit_in_last_frame_ = false; |
| 834 needs_one_begin_impl_frame_ = false; | 880 needs_one_begin_impl_frame_ = false; |
| 835 | 881 |
| 836 // Clear funnels for any actions we perform during the frame. | 882 // Clear funnels for any actions we perform during the frame. |
| 837 send_begin_main_frame_funnel_ = false; | 883 send_begin_main_frame_funnel_ = false; |
| 838 invalidate_compositor_frame_sink_funnel_ = false; | 884 invalidate_compositor_frame_sink_funnel_ = false; |
| 839 | 885 |
| 840 // "Drain" the PrepareTiles funnel. | 886 // "Drain" the PrepareTiles funnel. |
| 841 if (prepare_tiles_funnel_ > 0) | 887 if (prepare_tiles_funnel_ > 0) |
| 842 prepare_tiles_funnel_--; | 888 prepare_tiles_funnel_--; |
| 843 } | 889 } |
| 844 | 890 |
| 845 void SchedulerStateMachine::OnBeginImplFrameDeadline() { | 891 void SchedulerStateMachine::OnBeginImplFrameDeadline() { |
| 846 begin_impl_frame_state_ = BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE; | 892 begin_impl_frame_state_ = BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE; |
| 847 | 893 |
| 848 // Clear funnels for any actions we perform during the deadline. | 894 // Clear funnels for any actions we perform during the deadline. |
| 849 draw_funnel_ = false; | 895 draw_funnel_ = false; |
| 850 | 896 |
| 851 // Allow one PrepareTiles per draw for synchronous compositor. | 897 // Allow one PrepareTiles per draw for synchronous compositor. |
| 852 if (settings_.using_synchronous_renderer_compositor) { | 898 if (settings_.using_synchronous_renderer_compositor) { |
| 853 if (prepare_tiles_funnel_ > 0) | 899 if (prepare_tiles_funnel_ > 0) |
| 854 prepare_tiles_funnel_--; | 900 prepare_tiles_funnel_--; |
| 855 } | 901 } |
| 902 | |
| 903 // Update frame numbers for freshness in case no updates were necessary. | |
| 904 if (begin_main_frame_state_ == BEGIN_MAIN_FRAME_STATE_IDLE && | |
| 905 !needs_begin_main_frame_) { | |
| 906 if (has_pending_tree_) { | |
| 907 last_frame_number_pending_tree_was_fresh_ = current_frame_number_; | |
| 908 } else { | |
| 909 last_frame_number_active_tree_was_fresh_ = current_frame_number_; | |
| 910 | |
| 911 if (!needs_redraw_) | |
| 912 last_frame_number_compositor_frame_was_fresh_ = current_frame_number_; | |
| 913 } | |
| 914 } | |
| 856 } | 915 } |
| 857 | 916 |
| 858 void SchedulerStateMachine::OnBeginImplFrameIdle() { | 917 void SchedulerStateMachine::OnBeginImplFrameIdle() { |
| 859 begin_impl_frame_state_ = BEGIN_IMPL_FRAME_STATE_IDLE; | 918 begin_impl_frame_state_ = BEGIN_IMPL_FRAME_STATE_IDLE; |
| 860 | 919 |
| 861 skip_next_begin_main_frame_to_reduce_latency_ = false; | 920 skip_next_begin_main_frame_to_reduce_latency_ = false; |
| 862 | 921 |
| 863 // If a new or undrawn active tree is pending after the deadline, | 922 // If a new or undrawn active tree is pending after the deadline, |
| 864 // then the main thread is in a high latency mode. | 923 // then the main thread is in a high latency mode. |
| 865 main_thread_missed_last_deadline_ = | 924 main_thread_missed_last_deadline_ = |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 978 void SchedulerStateMachine::DidSubmitCompositorFrame() { | 1037 void SchedulerStateMachine::DidSubmitCompositorFrame() { |
| 979 TRACE_EVENT_ASYNC_BEGIN1("cc", "Scheduler:pending_submit_frames", this, | 1038 TRACE_EVENT_ASYNC_BEGIN1("cc", "Scheduler:pending_submit_frames", this, |
| 980 "pending_frames", pending_submit_frames_); | 1039 "pending_frames", pending_submit_frames_); |
| 981 DCHECK_LT(pending_submit_frames_, kMaxPendingSubmitFrames); | 1040 DCHECK_LT(pending_submit_frames_, kMaxPendingSubmitFrames); |
| 982 | 1041 |
| 983 pending_submit_frames_++; | 1042 pending_submit_frames_++; |
| 984 submit_frames_with_current_compositor_frame_sink_++; | 1043 submit_frames_with_current_compositor_frame_sink_++; |
| 985 | 1044 |
| 986 did_submit_in_last_frame_ = true; | 1045 did_submit_in_last_frame_ = true; |
| 987 last_frame_number_submit_performed_ = current_frame_number_; | 1046 last_frame_number_submit_performed_ = current_frame_number_; |
| 1047 last_frame_number_compositor_frame_was_fresh_ = | |
| 1048 last_frame_number_active_tree_was_fresh_; | |
| 988 } | 1049 } |
| 989 | 1050 |
| 990 void SchedulerStateMachine::DidReceiveCompositorFrameAck() { | 1051 void SchedulerStateMachine::DidReceiveCompositorFrameAck() { |
| 991 TRACE_EVENT_ASYNC_END1("cc", "Scheduler:pending_submit_frames", this, | 1052 TRACE_EVENT_ASYNC_END1("cc", "Scheduler:pending_submit_frames", this, |
| 992 "pending_frames", pending_submit_frames_); | 1053 "pending_frames", pending_submit_frames_); |
| 993 pending_submit_frames_--; | 1054 pending_submit_frames_--; |
| 994 } | 1055 } |
| 995 | 1056 |
| 996 void SchedulerStateMachine::SetTreePrioritiesAndScrollState( | 1057 void SchedulerStateMachine::SetTreePrioritiesAndScrollState( |
| 997 TreePriority tree_priority, | 1058 TreePriority tree_priority, |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1112 case COMPOSITOR_FRAME_SINK_ACTIVE: | 1173 case COMPOSITOR_FRAME_SINK_ACTIVE: |
| 1113 case COMPOSITOR_FRAME_SINK_WAITING_FOR_FIRST_COMMIT: | 1174 case COMPOSITOR_FRAME_SINK_WAITING_FOR_FIRST_COMMIT: |
| 1114 case COMPOSITOR_FRAME_SINK_WAITING_FOR_FIRST_ACTIVATION: | 1175 case COMPOSITOR_FRAME_SINK_WAITING_FOR_FIRST_ACTIVATION: |
| 1115 return true; | 1176 return true; |
| 1116 } | 1177 } |
| 1117 NOTREACHED(); | 1178 NOTREACHED(); |
| 1118 return false; | 1179 return false; |
| 1119 } | 1180 } |
| 1120 | 1181 |
| 1121 } // namespace cc | 1182 } // namespace cc |
| OLD | NEW |