| 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" |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 invalidate_output_surface_funnel_(false), | 32 invalidate_output_surface_funnel_(false), |
| 33 prepare_tiles_funnel_(0), | 33 prepare_tiles_funnel_(0), |
| 34 consecutive_checkerboard_animations_(0), | 34 consecutive_checkerboard_animations_(0), |
| 35 max_pending_swaps_(1), | 35 max_pending_swaps_(1), |
| 36 pending_swaps_(0), | 36 pending_swaps_(0), |
| 37 swaps_with_current_output_surface_(0), | 37 swaps_with_current_output_surface_(0), |
| 38 needs_redraw_(false), | 38 needs_redraw_(false), |
| 39 needs_animate_(false), | 39 needs_animate_(false), |
| 40 needs_prepare_tiles_(false), | 40 needs_prepare_tiles_(false), |
| 41 needs_begin_main_frame_(false), | 41 needs_begin_main_frame_(false), |
| 42 needs_one_begin_impl_frame_(false), |
| 42 visible_(false), | 43 visible_(false), |
| 43 resourceless_draw_(false), | 44 resourceless_draw_(false), |
| 44 can_draw_(false), | 45 can_draw_(false), |
| 45 has_pending_tree_(false), | 46 has_pending_tree_(false), |
| 46 pending_tree_is_ready_for_activation_(false), | 47 pending_tree_is_ready_for_activation_(false), |
| 47 active_tree_needs_first_draw_(false), | 48 active_tree_needs_first_draw_(false), |
| 48 did_create_and_initialize_first_output_surface_(false), | 49 did_create_and_initialize_first_output_surface_(false), |
| 49 impl_latency_takes_priority_(false), | 50 impl_latency_takes_priority_(false), |
| 50 main_thread_missed_last_deadline_(false), | 51 main_thread_missed_last_deadline_(false), |
| 51 skip_next_begin_main_frame_to_reduce_latency_(false), | 52 skip_next_begin_main_frame_to_reduce_latency_(false), |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 state->SetInteger("consecutive_checkerboard_animations", | 218 state->SetInteger("consecutive_checkerboard_animations", |
| 218 consecutive_checkerboard_animations_); | 219 consecutive_checkerboard_animations_); |
| 219 state->SetInteger("max_pending_swaps_", max_pending_swaps_); | 220 state->SetInteger("max_pending_swaps_", max_pending_swaps_); |
| 220 state->SetInteger("pending_swaps_", pending_swaps_); | 221 state->SetInteger("pending_swaps_", pending_swaps_); |
| 221 state->SetInteger("swaps_with_current_output_surface", | 222 state->SetInteger("swaps_with_current_output_surface", |
| 222 swaps_with_current_output_surface_); | 223 swaps_with_current_output_surface_); |
| 223 state->SetBoolean("needs_redraw", needs_redraw_); | 224 state->SetBoolean("needs_redraw", needs_redraw_); |
| 224 state->SetBoolean("needs_animate_", needs_animate_); | 225 state->SetBoolean("needs_animate_", needs_animate_); |
| 225 state->SetBoolean("needs_prepare_tiles", needs_prepare_tiles_); | 226 state->SetBoolean("needs_prepare_tiles", needs_prepare_tiles_); |
| 226 state->SetBoolean("needs_begin_main_frame", needs_begin_main_frame_); | 227 state->SetBoolean("needs_begin_main_frame", needs_begin_main_frame_); |
| 228 state->SetBoolean("needs_one_begin_impl_frame", needs_one_begin_impl_frame_); |
| 227 state->SetBoolean("visible", visible_); | 229 state->SetBoolean("visible", visible_); |
| 228 state->SetBoolean("can_draw", can_draw_); | 230 state->SetBoolean("can_draw", can_draw_); |
| 229 state->SetBoolean("resourceless_draw", resourceless_draw_); | 231 state->SetBoolean("resourceless_draw", resourceless_draw_); |
| 230 state->SetBoolean("has_pending_tree", has_pending_tree_); | 232 state->SetBoolean("has_pending_tree", has_pending_tree_); |
| 231 state->SetBoolean("pending_tree_is_ready_for_activation", | 233 state->SetBoolean("pending_tree_is_ready_for_activation", |
| 232 pending_tree_is_ready_for_activation_); | 234 pending_tree_is_ready_for_activation_); |
| 233 state->SetBoolean("active_tree_needs_first_draw", | 235 state->SetBoolean("active_tree_needs_first_draw", |
| 234 active_tree_needs_first_draw_); | 236 active_tree_needs_first_draw_); |
| 235 state->SetBoolean("wait_for_ready_to_draw", wait_for_ready_to_draw_); | 237 state->SetBoolean("wait_for_ready_to_draw", wait_for_ready_to_draw_); |
| 236 state->SetBoolean("did_create_and_initialize_first_output_surface", | 238 state->SetBoolean("did_create_and_initialize_first_output_surface", |
| (...skipping 499 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 736 } | 738 } |
| 737 | 739 |
| 738 // These are the cases where we require a BeginFrame message to make progress | 740 // These are the cases where we require a BeginFrame message to make progress |
| 739 // on requested actions. | 741 // on requested actions. |
| 740 bool SchedulerStateMachine::BeginFrameRequiredForAction() const { | 742 bool SchedulerStateMachine::BeginFrameRequiredForAction() const { |
| 741 // The forced draw respects our normal draw scheduling, so we need to | 743 // The forced draw respects our normal draw scheduling, so we need to |
| 742 // request a BeginImplFrame for it. | 744 // request a BeginImplFrame for it. |
| 743 if (forced_redraw_state_ == FORCED_REDRAW_STATE_WAITING_FOR_DRAW) | 745 if (forced_redraw_state_ == FORCED_REDRAW_STATE_WAITING_FOR_DRAW) |
| 744 return true; | 746 return true; |
| 745 | 747 |
| 746 return needs_animate_ || needs_redraw_ || | 748 return needs_animate_ || needs_redraw_ || needs_one_begin_impl_frame_ || |
| 747 (needs_begin_main_frame_ && !defer_commits_); | 749 (needs_begin_main_frame_ && !defer_commits_); |
| 748 } | 750 } |
| 749 | 751 |
| 750 // These are cases where we are very likely want a BeginFrame message in the | 752 // These are cases where we are very likely want a BeginFrame message in the |
| 751 // near future. Proactively requesting the BeginImplFrame helps hide the round | 753 // near future. Proactively requesting the BeginImplFrame helps hide the round |
| 752 // trip latency of the SetNeedsBeginFrame request that has to go to the | 754 // trip latency of the SetNeedsBeginFrame request that has to go to the |
| 753 // Browser. | 755 // Browser. |
| 754 // This includes things like drawing soon, but might not actually have a new | 756 // This includes things like drawing soon, but might not actually have a new |
| 755 // frame to draw when we receive the next BeginImplFrame. | 757 // frame to draw when we receive the next BeginImplFrame. |
| 756 bool SchedulerStateMachine::ProactiveBeginFrameWanted() const { | 758 bool SchedulerStateMachine::ProactiveBeginFrameWanted() const { |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 792 | 794 |
| 793 return false; | 795 return false; |
| 794 } | 796 } |
| 795 | 797 |
| 796 void SchedulerStateMachine::OnBeginImplFrame() { | 798 void SchedulerStateMachine::OnBeginImplFrame() { |
| 797 begin_impl_frame_state_ = BEGIN_IMPL_FRAME_STATE_BEGIN_FRAME_STARTING; | 799 begin_impl_frame_state_ = BEGIN_IMPL_FRAME_STATE_BEGIN_FRAME_STARTING; |
| 798 current_frame_number_++; | 800 current_frame_number_++; |
| 799 | 801 |
| 800 last_commit_had_no_updates_ = false; | 802 last_commit_had_no_updates_ = false; |
| 801 did_request_swap_in_last_frame_ = false; | 803 did_request_swap_in_last_frame_ = false; |
| 804 needs_one_begin_impl_frame_ = false; |
| 802 | 805 |
| 803 // Clear funnels for any actions we perform during the frame. | 806 // Clear funnels for any actions we perform during the frame. |
| 804 animate_funnel_ = false; | 807 animate_funnel_ = false; |
| 805 send_begin_main_frame_funnel_ = false; | 808 send_begin_main_frame_funnel_ = false; |
| 806 invalidate_output_surface_funnel_ = false; | 809 invalidate_output_surface_funnel_ = false; |
| 807 | 810 |
| 808 // "Drain" the PrepareTiles funnel. | 811 // "Drain" the PrepareTiles funnel. |
| 809 if (prepare_tiles_funnel_ > 0) | 812 if (prepare_tiles_funnel_ > 0) |
| 810 prepare_tiles_funnel_--; | 813 prepare_tiles_funnel_--; |
| 811 } | 814 } |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 932 | 935 |
| 933 void SchedulerStateMachine::SetCanDraw(bool can_draw) { can_draw_ = can_draw; } | 936 void SchedulerStateMachine::SetCanDraw(bool can_draw) { can_draw_ = can_draw; } |
| 934 | 937 |
| 935 void SchedulerStateMachine::SetNeedsRedraw() { needs_redraw_ = true; } | 938 void SchedulerStateMachine::SetNeedsRedraw() { needs_redraw_ = true; } |
| 936 | 939 |
| 937 void SchedulerStateMachine::SetNeedsAnimate() { | 940 void SchedulerStateMachine::SetNeedsAnimate() { |
| 938 needs_animate_ = true; | 941 needs_animate_ = true; |
| 939 } | 942 } |
| 940 | 943 |
| 941 bool SchedulerStateMachine::OnlyImplSideUpdatesExpected() const { | 944 bool SchedulerStateMachine::OnlyImplSideUpdatesExpected() const { |
| 942 bool has_impl_updates = needs_redraw_ || needs_animate_; | 945 bool has_impl_updates = |
| 946 needs_redraw_ || needs_animate_ || needs_one_begin_impl_frame_; |
| 943 bool main_updates_expected = | 947 bool main_updates_expected = |
| 944 needs_begin_main_frame_ || | 948 needs_begin_main_frame_ || |
| 945 begin_main_frame_state_ != BEGIN_MAIN_FRAME_STATE_IDLE || | 949 begin_main_frame_state_ != BEGIN_MAIN_FRAME_STATE_IDLE || |
| 946 has_pending_tree_; | 950 has_pending_tree_; |
| 947 return has_impl_updates && !main_updates_expected; | 951 return has_impl_updates && !main_updates_expected; |
| 948 } | 952 } |
| 949 | 953 |
| 950 void SchedulerStateMachine::SetNeedsPrepareTiles() { | 954 void SchedulerStateMachine::SetNeedsPrepareTiles() { |
| 951 if (!needs_prepare_tiles_) { | 955 if (!needs_prepare_tiles_) { |
| 952 TRACE_EVENT0("cc", "SchedulerStateMachine::SetNeedsPrepareTiles"); | 956 TRACE_EVENT0("cc", "SchedulerStateMachine::SetNeedsPrepareTiles"); |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1017 // anyway. | 1021 // anyway. |
| 1018 needs_begin_main_frame_ = true; | 1022 needs_begin_main_frame_ = true; |
| 1019 break; | 1023 break; |
| 1020 } | 1024 } |
| 1021 } | 1025 } |
| 1022 | 1026 |
| 1023 void SchedulerStateMachine::SetNeedsBeginMainFrame() { | 1027 void SchedulerStateMachine::SetNeedsBeginMainFrame() { |
| 1024 needs_begin_main_frame_ = true; | 1028 needs_begin_main_frame_ = true; |
| 1025 } | 1029 } |
| 1026 | 1030 |
| 1031 void SchedulerStateMachine::SetNeedsOneBeginImplFrame() { |
| 1032 needs_one_begin_impl_frame_ = true; |
| 1033 } |
| 1034 |
| 1027 void SchedulerStateMachine::NotifyReadyToCommit() { | 1035 void SchedulerStateMachine::NotifyReadyToCommit() { |
| 1028 DCHECK(begin_main_frame_state_ == BEGIN_MAIN_FRAME_STATE_STARTED) | 1036 DCHECK(begin_main_frame_state_ == BEGIN_MAIN_FRAME_STATE_STARTED) |
| 1029 << AsValue()->ToString(); | 1037 << AsValue()->ToString(); |
| 1030 begin_main_frame_state_ = BEGIN_MAIN_FRAME_STATE_READY_TO_COMMIT; | 1038 begin_main_frame_state_ = BEGIN_MAIN_FRAME_STATE_READY_TO_COMMIT; |
| 1031 // In commit_to_active_tree mode, commit should happen right after | 1039 // In commit_to_active_tree mode, commit should happen right after |
| 1032 // BeginFrame, meaning when this function is called, next action should be | 1040 // BeginFrame, meaning when this function is called, next action should be |
| 1033 // commit. | 1041 // commit. |
| 1034 if (settings_.commit_to_active_tree) | 1042 if (settings_.commit_to_active_tree) |
| 1035 DCHECK(ShouldCommit()); | 1043 DCHECK(ShouldCommit()); |
| 1036 } | 1044 } |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1104 case OUTPUT_SURFACE_ACTIVE: | 1112 case OUTPUT_SURFACE_ACTIVE: |
| 1105 case OUTPUT_SURFACE_WAITING_FOR_FIRST_COMMIT: | 1113 case OUTPUT_SURFACE_WAITING_FOR_FIRST_COMMIT: |
| 1106 case OUTPUT_SURFACE_WAITING_FOR_FIRST_ACTIVATION: | 1114 case OUTPUT_SURFACE_WAITING_FOR_FIRST_ACTIVATION: |
| 1107 return true; | 1115 return true; |
| 1108 } | 1116 } |
| 1109 NOTREACHED(); | 1117 NOTREACHED(); |
| 1110 return false; | 1118 return false; |
| 1111 } | 1119 } |
| 1112 | 1120 |
| 1113 } // namespace cc | 1121 } // namespace cc |
| OLD | NEW |