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/debug/trace_event.h" | 7 #include "base/debug/trace_event.h" |
8 #include "base/format_macros.h" | 8 #include "base/format_macros.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
(...skipping 23 matching lines...) Expand all Loading... | |
34 main_thread_needs_layer_textures_(false), | 34 main_thread_needs_layer_textures_(false), |
35 inside_poll_for_anticipated_draw_triggers_(false), | 35 inside_poll_for_anticipated_draw_triggers_(false), |
36 visible_(false), | 36 visible_(false), |
37 can_start_(false), | 37 can_start_(false), |
38 can_draw_(false), | 38 can_draw_(false), |
39 has_pending_tree_(false), | 39 has_pending_tree_(false), |
40 pending_tree_is_ready_for_activation_(false), | 40 pending_tree_is_ready_for_activation_(false), |
41 active_tree_needs_first_draw_(false), | 41 active_tree_needs_first_draw_(false), |
42 draw_if_possible_failed_(false), | 42 draw_if_possible_failed_(false), |
43 did_create_and_initialize_first_output_surface_(false), | 43 did_create_and_initialize_first_output_surface_(false), |
44 smoothness_takes_priority_(false) {} | 44 smoothness_takes_priority_(false), |
45 skip_begin_main_frame_to_reduce_latency_(false) {} | |
45 | 46 |
46 const char* SchedulerStateMachine::OutputSurfaceStateToString( | 47 const char* SchedulerStateMachine::OutputSurfaceStateToString( |
47 OutputSurfaceState state) { | 48 OutputSurfaceState state) { |
48 switch (state) { | 49 switch (state) { |
49 case OUTPUT_SURFACE_ACTIVE: | 50 case OUTPUT_SURFACE_ACTIVE: |
50 return "OUTPUT_SURFACE_ACTIVE"; | 51 return "OUTPUT_SURFACE_ACTIVE"; |
51 case OUTPUT_SURFACE_LOST: | 52 case OUTPUT_SURFACE_LOST: |
52 return "OUTPUT_SURFACE_LOST"; | 53 return "OUTPUT_SURFACE_LOST"; |
53 case OUTPUT_SURFACE_CREATING: | 54 case OUTPUT_SURFACE_CREATING: |
54 return "OUTPUT_SURFACE_CREATING"; | 55 return "OUTPUT_SURFACE_CREATING"; |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
252 minor_state->SetBoolean("has_pending_tree", has_pending_tree_); | 253 minor_state->SetBoolean("has_pending_tree", has_pending_tree_); |
253 minor_state->SetBoolean("pending_tree_is_ready_for_activation", | 254 minor_state->SetBoolean("pending_tree_is_ready_for_activation", |
254 pending_tree_is_ready_for_activation_); | 255 pending_tree_is_ready_for_activation_); |
255 minor_state->SetBoolean("active_tree_needs_first_draw", | 256 minor_state->SetBoolean("active_tree_needs_first_draw", |
256 active_tree_needs_first_draw_); | 257 active_tree_needs_first_draw_); |
257 minor_state->SetBoolean("draw_if_possible_failed", draw_if_possible_failed_); | 258 minor_state->SetBoolean("draw_if_possible_failed", draw_if_possible_failed_); |
258 minor_state->SetBoolean("did_create_and_initialize_first_output_surface", | 259 minor_state->SetBoolean("did_create_and_initialize_first_output_surface", |
259 did_create_and_initialize_first_output_surface_); | 260 did_create_and_initialize_first_output_surface_); |
260 minor_state->SetBoolean("smoothness_takes_priority", | 261 minor_state->SetBoolean("smoothness_takes_priority", |
261 smoothness_takes_priority_); | 262 smoothness_takes_priority_); |
263 minor_state->SetBoolean("skip_begin_main_frame_to_reduce_latency", | |
264 skip_begin_main_frame_to_reduce_latency_); | |
262 state->Set("minor_state", minor_state.release()); | 265 state->Set("minor_state", minor_state.release()); |
263 | 266 |
264 return state.PassAs<base::Value>(); | 267 return state.PassAs<base::Value>(); |
265 } | 268 } |
266 | 269 |
267 bool SchedulerStateMachine::HasSentBeginMainFrameThisFrame() const { | 270 bool SchedulerStateMachine::HasSentBeginMainFrameThisFrame() const { |
268 return current_frame_number_ == | 271 return current_frame_number_ == |
269 last_frame_number_begin_main_frame_sent_; | 272 last_frame_number_begin_main_frame_sent_; |
270 } | 273 } |
271 | 274 |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
478 return true; | 481 return true; |
479 | 482 |
480 // After this point, we only start a commit once per frame. | 483 // After this point, we only start a commit once per frame. |
481 if (HasSentBeginMainFrameThisFrame()) | 484 if (HasSentBeginMainFrameThisFrame()) |
482 return false; | 485 return false; |
483 | 486 |
484 // We shouldn't normally accept commits if there isn't an OutputSurface. | 487 // We shouldn't normally accept commits if there isn't an OutputSurface. |
485 if (!HasInitializedOutputSurface()) | 488 if (!HasInitializedOutputSurface()) |
486 return false; | 489 return false; |
487 | 490 |
491 if (skip_begin_main_frame_to_reduce_latency_) | |
492 return false; | |
493 | |
488 return true; | 494 return true; |
489 } | 495 } |
490 | 496 |
491 bool SchedulerStateMachine::ShouldCommit() const { | 497 bool SchedulerStateMachine::ShouldCommit() const { |
492 return commit_state_ == COMMIT_STATE_READY_TO_COMMIT; | 498 return commit_state_ == COMMIT_STATE_READY_TO_COMMIT; |
493 } | 499 } |
494 | 500 |
495 bool SchedulerStateMachine::ShouldManageTiles() const { | 501 bool SchedulerStateMachine::ShouldManageTiles() const { |
496 // Limiting to once per-frame is not enough, since we only want to | 502 // Limiting to once per-frame is not enough, since we only want to |
497 // manage tiles _after_ draws. Polling for draw triggers and | 503 // manage tiles _after_ draws. Polling for draw triggers and |
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
749 void SchedulerStateMachine::UpdateStateOnManageTiles() { | 755 void SchedulerStateMachine::UpdateStateOnManageTiles() { |
750 needs_manage_tiles_ = false; | 756 needs_manage_tiles_ = false; |
751 } | 757 } |
752 | 758 |
753 void SchedulerStateMachine::SetMainThreadNeedsLayerTextures() { | 759 void SchedulerStateMachine::SetMainThreadNeedsLayerTextures() { |
754 DCHECK(!main_thread_needs_layer_textures_); | 760 DCHECK(!main_thread_needs_layer_textures_); |
755 DCHECK_NE(texture_state_, LAYER_TEXTURE_STATE_ACQUIRED_BY_MAIN_THREAD); | 761 DCHECK_NE(texture_state_, LAYER_TEXTURE_STATE_ACQUIRED_BY_MAIN_THREAD); |
756 main_thread_needs_layer_textures_ = true; | 762 main_thread_needs_layer_textures_ = true; |
757 } | 763 } |
758 | 764 |
765 void SchedulerStateMachine::SetSkipBeginMainFrameToReduceLatency(bool skip) { | |
766 skip_begin_main_frame_to_reduce_latency_ = skip; | |
767 } | |
768 | |
759 bool SchedulerStateMachine::BeginImplFrameNeeded() const { | 769 bool SchedulerStateMachine::BeginImplFrameNeeded() const { |
760 // Proactive BeginImplFrames are bad for the synchronous compositor because we | 770 // Proactive BeginImplFrames are bad for the synchronous compositor because we |
761 // have to draw when we get the BeginImplFrame and could end up drawing many | 771 // have to draw when we get the BeginImplFrame and could end up drawing many |
762 // duplicate frames if our new frame isn't ready in time. | 772 // duplicate frames if our new frame isn't ready in time. |
763 // To poll for state with the synchronous compositor without having to draw, | 773 // To poll for state with the synchronous compositor without having to draw, |
764 // we rely on ShouldPollForAnticipatedDrawTriggers instead. | 774 // we rely on ShouldPollForAnticipatedDrawTriggers instead. |
765 if (!SupportsProactiveBeginImplFrame()) | 775 if (!SupportsProactiveBeginImplFrame()) |
766 return BeginImplFrameNeededToDraw(); | 776 return BeginImplFrameNeededToDraw(); |
767 | 777 |
768 return BeginImplFrameNeededToDraw() || | 778 return BeginImplFrameNeededToDraw() || |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
912 if (commit_state_ == COMMIT_STATE_IDLE && !has_pending_tree_) | 922 if (commit_state_ == COMMIT_STATE_IDLE && !has_pending_tree_) |
913 return true; | 923 return true; |
914 | 924 |
915 // Prioritize impl-thread draws in smoothness mode. | 925 // Prioritize impl-thread draws in smoothness mode. |
916 if (smoothness_takes_priority_) | 926 if (smoothness_takes_priority_) |
917 return true; | 927 return true; |
918 | 928 |
919 return false; | 929 return false; |
920 } | 930 } |
921 | 931 |
932 bool SchedulerStateMachine::InHighLatencyMode() const { | |
brianderson
2013/11/01 21:18:30
Maybe rename this to MainThreadIsInHighLatencyMode
| |
933 // We're in high latency mode if there's something to draw from the previous | |
934 // frame at the start of BeginImplFrame. | |
935 if (begin_impl_frame_state_ != BEGIN_IMPL_FRAME_STATE_BEGIN_FRAME_STARTING) | |
brianderson
2013/11/01 21:18:30
Can you add the result of this method to the outpu
| |
936 return false; | |
937 | |
938 // There's an ongoing commit at the start of BeginImplFrame whose output needs | |
939 // to be drawn before another commit from the main thread. | |
940 if (commit_state_ != COMMIT_STATE_IDLE) | |
941 return true; | |
942 | |
943 // There is a pending tree from the previous frame which needs to be activated | |
944 // and drawn before producing a new tree. | |
945 if (has_pending_tree_ ) | |
946 return true; | |
947 | |
948 // A newly activated tree from the previous frame needs to be drawn. | |
949 if (active_tree_needs_first_draw_) | |
brianderson
2013/11/01 21:18:30
To make this method valid regardless of the state
| |
950 return true; | |
951 | |
952 return false; | |
953 } | |
954 | |
922 void SchedulerStateMachine::DidEnterPollForAnticipatedDrawTriggers() { | 955 void SchedulerStateMachine::DidEnterPollForAnticipatedDrawTriggers() { |
923 current_frame_number_++; | 956 current_frame_number_++; |
924 inside_poll_for_anticipated_draw_triggers_ = true; | 957 inside_poll_for_anticipated_draw_triggers_ = true; |
925 } | 958 } |
926 | 959 |
927 void SchedulerStateMachine::DidLeavePollForAnticipatedDrawTriggers() { | 960 void SchedulerStateMachine::DidLeavePollForAnticipatedDrawTriggers() { |
928 inside_poll_for_anticipated_draw_triggers_ = false; | 961 inside_poll_for_anticipated_draw_triggers_ = false; |
929 } | 962 } |
930 | 963 |
931 void SchedulerStateMachine::SetVisible(bool visible) { visible_ = visible; } | 964 void SchedulerStateMachine::SetVisible(bool visible) { visible_ = visible; } |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1053 case OUTPUT_SURFACE_ACTIVE: | 1086 case OUTPUT_SURFACE_ACTIVE: |
1054 case OUTPUT_SURFACE_WAITING_FOR_FIRST_COMMIT: | 1087 case OUTPUT_SURFACE_WAITING_FOR_FIRST_COMMIT: |
1055 case OUTPUT_SURFACE_WAITING_FOR_FIRST_ACTIVATION: | 1088 case OUTPUT_SURFACE_WAITING_FOR_FIRST_ACTIVATION: |
1056 return true; | 1089 return true; |
1057 } | 1090 } |
1058 NOTREACHED(); | 1091 NOTREACHED(); |
1059 return false; | 1092 return false; |
1060 } | 1093 } |
1061 | 1094 |
1062 } // namespace cc | 1095 } // namespace cc |
OLD | NEW |