| 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 | 10 |
| 11 namespace cc { | 11 namespace cc { |
| 12 | 12 |
| 13 SchedulerStateMachine::SchedulerStateMachine(const SchedulerSettings& settings) | 13 SchedulerStateMachine::SchedulerStateMachine(const SchedulerSettings& settings) |
| 14 : settings_(settings), | 14 : settings_(settings), |
| 15 commit_state_(COMMIT_STATE_IDLE), | 15 commit_state_(COMMIT_STATE_IDLE), |
| 16 commit_count_(0), | 16 commit_count_(0), |
| 17 current_frame_number_(0), | 17 begin_frame_count_(0), |
| 18 last_frame_number_where_draw_was_called_(-1), | 18 draw_attempt_count_(0), |
| 19 last_frame_number_where_tree_activation_attempted_(-1), | 19 last_begin_frame_count_draw_was_called_(-1), |
| 20 last_frame_number_where_check_for_completed_tile_uploads_called_(-1), | 20 last_begin_frame_count_begin_frame_sent_to_main_thread_(-1), |
| 21 last_draw_attempt_count_tree_activation_attempted_(-1), |
| 22 last_draw_attempt_count_completed_tile_uploads_checked_(-1), |
| 21 consecutive_failed_draws_(0), | 23 consecutive_failed_draws_(0), |
| 22 maximum_number_of_failed_draws_before_draw_is_forced_(3), | 24 maximum_number_of_failed_draws_before_draw_is_forced_(3), |
| 23 needs_redraw_(false), | 25 needs_redraw_(false), |
| 24 swap_used_incomplete_tile_(false), | 26 swap_used_incomplete_tile_(false), |
| 25 needs_forced_redraw_(false), | 27 needs_forced_redraw_(false), |
| 26 needs_forced_redraw_after_next_commit_(false), | 28 needs_forced_redraw_after_next_commit_(false), |
| 27 needs_commit_(false), | 29 needs_commit_(false), |
| 28 needs_forced_commit_(false), | 30 needs_forced_commit_(false), |
| 29 expect_immediate_begin_frame_for_main_thread_(false), | 31 expect_immediate_begin_frame_for_main_thread_(false), |
| 30 main_thread_needs_layer_textures_(false), | 32 main_thread_needs_layer_textures_(false), |
| 31 inside_begin_frame_(false), | 33 begin_frame_state_(BEGIN_FRAME_STATE_IDLE), |
| 34 commit_tree_has_been_drawn_or_null_(true), |
| 35 active_tree_has_been_drawn_or_null_(true), |
| 32 visible_(false), | 36 visible_(false), |
| 33 can_start_(false), | 37 can_start_(false), |
| 34 can_draw_(false), | 38 can_draw_(false), |
| 35 has_pending_tree_(false), | 39 has_pending_tree_(false), |
| 36 draw_if_possible_failed_(false), | 40 draw_if_possible_failed_(false), |
| 37 texture_state_(LAYER_TEXTURE_STATE_UNLOCKED), | 41 texture_state_(LAYER_TEXTURE_STATE_UNLOCKED), |
| 38 output_surface_state_(OUTPUT_SURFACE_LOST), | 42 output_surface_state_(OUTPUT_SURFACE_LOST), |
| 39 did_create_and_initialize_first_output_surface_(false) {} | 43 did_create_and_initialize_first_output_surface_(false) {} |
| 40 | 44 |
| 41 std::string SchedulerStateMachine::ToString() { | 45 std::string SchedulerStateMachine::ToString() { |
| 42 std::string str; | 46 std::string str; |
| 43 base::StringAppendF(&str, | 47 base::StringAppendF(&str, |
| 44 "settings_.impl_side_painting = %d; ", | 48 "settings_.impl_side_painting = %d; ", |
| 45 settings_.impl_side_painting); | 49 settings_.impl_side_painting); |
| 46 base::StringAppendF(&str, "commit_state_ = %d; ", commit_state_); | 50 base::StringAppendF(&str, "commit_state_ = %d; ", commit_state_); |
| 47 base::StringAppendF(&str, "commit_count_ = %d; ", commit_count_); | 51 base::StringAppendF(&str, "commit_count_ = %d; ", commit_count_); |
| 48 base::StringAppendF( | 52 base::StringAppendF(&str, "begin_frame_count_ = %d; ", |
| 49 &str, "current_frame_number_ = %d; ", current_frame_number_); | 53 begin_frame_count_); |
| 54 base::StringAppendF(&str, "draw_attempt_count_ = %d; ", |
| 55 draw_attempt_count_); |
| 50 base::StringAppendF(&str, | 56 base::StringAppendF(&str, |
| 51 "last_frame_number_where_draw_was_called_ = %d; ", | 57 "last_begin_frame_count_draw_was_called_ = %d; ", |
| 52 last_frame_number_where_draw_was_called_); | 58 last_begin_frame_count_draw_was_called_); |
| 53 base::StringAppendF( | 59 base::StringAppendF( |
| 54 &str, | 60 &str, |
| 55 "last_frame_number_where_tree_activation_attempted_ = %d; ", | 61 "last_draw_attempt_count_tree_activation_attempted_ = %d; ", |
| 56 last_frame_number_where_tree_activation_attempted_); | 62 last_draw_attempt_count_tree_activation_attempted_); |
| 57 base::StringAppendF( | 63 base::StringAppendF( |
| 58 &str, | 64 &str, |
| 59 "last_frame_number_where_check_for_completed_tile_uploads_called_ = %d; ", | 65 "last_draw_attempt_count_completed_tile_uploads_checked_ = %d; ", |
| 60 last_frame_number_where_check_for_completed_tile_uploads_called_); | 66 last_draw_attempt_count_completed_tile_uploads_checked_); |
| 61 base::StringAppendF( | 67 base::StringAppendF( |
| 62 &str, "consecutive_failed_draws_ = %d; ", consecutive_failed_draws_); | 68 &str, "consecutive_failed_draws_ = %d; ", consecutive_failed_draws_); |
| 63 base::StringAppendF( | 69 base::StringAppendF( |
| 64 &str, | 70 &str, |
| 65 "maximum_number_of_failed_draws_before_draw_is_forced_ = %d; ", | 71 "maximum_number_of_failed_draws_before_draw_is_forced_ = %d; ", |
| 66 maximum_number_of_failed_draws_before_draw_is_forced_); | 72 maximum_number_of_failed_draws_before_draw_is_forced_); |
| 67 base::StringAppendF(&str, "needs_redraw_ = %d; ", needs_redraw_); | 73 base::StringAppendF(&str, "needs_redraw_ = %d; ", needs_redraw_); |
| 68 base::StringAppendF( | 74 base::StringAppendF( |
| 69 &str, "swap_used_incomplete_tile_ = %d; ", swap_used_incomplete_tile_); | 75 &str, "swap_used_incomplete_tile_ = %d; ", swap_used_incomplete_tile_); |
| 70 base::StringAppendF( | 76 base::StringAppendF( |
| 71 &str, "needs_forced_redraw_ = %d; ", needs_forced_redraw_); | 77 &str, "needs_forced_redraw_ = %d; ", needs_forced_redraw_); |
| 72 base::StringAppendF(&str, | 78 base::StringAppendF(&str, |
| 73 "needs_forced_redraw_after_next_commit_ = %d; ", | 79 "needs_forced_redraw_after_next_commit_ = %d; ", |
| 74 needs_forced_redraw_after_next_commit_); | 80 needs_forced_redraw_after_next_commit_); |
| 75 base::StringAppendF(&str, "needs_commit_ = %d; ", needs_commit_); | 81 base::StringAppendF(&str, "needs_commit_ = %d; ", needs_commit_); |
| 76 base::StringAppendF( | 82 base::StringAppendF( |
| 77 &str, "needs_forced_commit_ = %d; ", needs_forced_commit_); | 83 &str, "needs_forced_commit_ = %d; ", needs_forced_commit_); |
| 78 base::StringAppendF(&str, | 84 base::StringAppendF(&str, |
| 79 "expect_immediate_begin_frame_for_main_thread_ = %d; ", | 85 "expect_immediate_begin_frame_for_main_thread_ = %d; ", |
| 80 expect_immediate_begin_frame_for_main_thread_); | 86 expect_immediate_begin_frame_for_main_thread_); |
| 81 base::StringAppendF(&str, | 87 base::StringAppendF(&str, |
| 82 "main_thread_needs_layer_textures_ = %d; ", | 88 "main_thread_needs_layer_textures_ = %d; ", |
| 83 main_thread_needs_layer_textures_); | 89 main_thread_needs_layer_textures_); |
| 84 base::StringAppendF(&str, "inside_begin_frame_ = %d; ", | 90 base::StringAppendF(&str, "begin_frame_state_ = %d; ", begin_frame_state_); |
| 85 inside_begin_frame_); | |
| 86 base::StringAppendF(&str, "last_frame_time_ = %"PRId64"; ", | 91 base::StringAppendF(&str, "last_frame_time_ = %"PRId64"; ", |
| 87 (last_begin_frame_args_.frame_time - base::TimeTicks()) | 92 (last_begin_frame_args_.frame_time - base::TimeTicks()) |
| 88 .InMilliseconds()); | 93 .InMilliseconds()); |
| 89 base::StringAppendF(&str, "last_deadline_ = %"PRId64"; ", | 94 base::StringAppendF(&str, "last_deadline_ = %"PRId64"; ", |
| 90 (last_begin_frame_args_.deadline - base::TimeTicks()).InMilliseconds()); | 95 (last_begin_frame_args_.deadline - base::TimeTicks()).InMilliseconds()); |
| 91 base::StringAppendF(&str, "last_interval_ = %"PRId64"; ", | 96 base::StringAppendF(&str, "last_interval_ = %"PRId64"; ", |
| 92 last_begin_frame_args_.interval.InMilliseconds()); | 97 last_begin_frame_args_.interval.InMilliseconds()); |
| 93 base::StringAppendF(&str, "visible_ = %d; ", visible_); | 98 base::StringAppendF(&str, "visible_ = %d; ", visible_); |
| 94 base::StringAppendF(&str, "can_start_ = %d; ", can_start_); | 99 base::StringAppendF(&str, "can_start_ = %d; ", can_start_); |
| 95 base::StringAppendF(&str, "can_draw_ = %d; ", can_draw_); | 100 base::StringAppendF(&str, "can_draw_ = %d; ", can_draw_); |
| 96 base::StringAppendF( | 101 base::StringAppendF( |
| 97 &str, "draw_if_possible_failed_ = %d; ", draw_if_possible_failed_); | 102 &str, "draw_if_possible_failed_ = %d; ", draw_if_possible_failed_); |
| 98 base::StringAppendF(&str, "has_pending_tree_ = %d; ", has_pending_tree_); | 103 base::StringAppendF(&str, "has_pending_tree_ = %d; ", has_pending_tree_); |
| 104 base::StringAppendF(&str, "commit_tree_has_been_drawn_or_null_ = %d; ", |
| 105 commit_tree_has_been_drawn_or_null_); |
| 106 base::StringAppendF(&str, "active_tree_has_been_drawn_or_null_ = %d; ", |
| 107 active_tree_has_been_drawn_or_null_); |
| 99 base::StringAppendF(&str, "texture_state_ = %d; ", texture_state_); | 108 base::StringAppendF(&str, "texture_state_ = %d; ", texture_state_); |
| 100 base::StringAppendF( | 109 base::StringAppendF( |
| 101 &str, "output_surface_state_ = %d; ", output_surface_state_); | 110 &str, "output_surface_state_ = %d; ", output_surface_state_); |
| 102 return str; | 111 return str; |
| 103 } | 112 } |
| 104 | 113 |
| 105 bool SchedulerStateMachine::HasDrawnThisFrame() const { | 114 bool SchedulerStateMachine::HasDrawnThisFrame() const { |
| 106 return current_frame_number_ == last_frame_number_where_draw_was_called_; | 115 return begin_frame_count_ == last_begin_frame_count_draw_was_called_; |
| 107 } | 116 } |
| 108 | 117 |
| 109 bool SchedulerStateMachine::HasAttemptedTreeActivationThisFrame() const { | 118 bool SchedulerStateMachine::HasSentBeginFrameToMainThreadThisFrame() const { |
| 110 return current_frame_number_ == | 119 return begin_frame_count_ == |
| 111 last_frame_number_where_tree_activation_attempted_; | 120 last_begin_frame_count_begin_frame_sent_to_main_thread_; |
| 112 } | 121 } |
| 113 | 122 |
| 114 bool SchedulerStateMachine::HasCheckedForCompletedTileUploadsThisFrame() const { | 123 bool SchedulerStateMachine::HasAttemptedTreeActivationThisDrawAttempt() const { |
| 115 return current_frame_number_ == | 124 return draw_attempt_count_ == |
| 116 last_frame_number_where_check_for_completed_tile_uploads_called_; | 125 last_draw_attempt_count_tree_activation_attempted_; |
| 126 } |
| 127 |
| 128 bool SchedulerStateMachine:: |
| 129 HasCheckedForCompletedTileUploadsThisDrawAttempt() const { |
| 130 return draw_attempt_count_ == |
| 131 last_draw_attempt_count_completed_tile_uploads_checked_; |
| 117 } | 132 } |
| 118 | 133 |
| 119 bool SchedulerStateMachine::DrawSuspendedUntilCommit() const { | 134 bool SchedulerStateMachine::DrawSuspendedUntilCommit() const { |
| 120 if (!can_draw_) | 135 if (!can_draw_) |
| 121 return true; | 136 return true; |
| 122 if (!visible_) | 137 if (!visible_) |
| 123 return true; | 138 return true; |
| 124 if (texture_state_ == LAYER_TEXTURE_STATE_ACQUIRED_BY_MAIN_THREAD) | 139 if (texture_state_ == LAYER_TEXTURE_STATE_ACQUIRED_BY_MAIN_THREAD) |
| 125 return true; | 140 return true; |
| 126 return false; | 141 return false; |
| 127 } | 142 } |
| 128 | 143 |
| 129 bool SchedulerStateMachine::ScheduledToDraw() const { | 144 bool SchedulerStateMachine::ScheduledToDraw() const { |
| 130 if (!needs_redraw_) | 145 if (!needs_redraw_) |
| 131 return false; | 146 return false; |
| 132 if (DrawSuspendedUntilCommit()) | 147 if (DrawSuspendedUntilCommit()) |
| 133 return false; | 148 return false; |
| 134 return true; | 149 return true; |
| 135 } | 150 } |
| 136 | 151 |
| 137 bool SchedulerStateMachine::ShouldDraw() const { | 152 bool SchedulerStateMachine::ShouldDraw() const { |
| 138 if (needs_forced_redraw_) | 153 if (needs_forced_redraw_) |
| 139 return true; | 154 return true; |
| 140 | 155 |
| 141 if (!ScheduledToDraw()) | 156 if (!ScheduledToDraw()) |
| 142 return false; | 157 return false; |
| 143 if (!inside_begin_frame_) | 158 if (begin_frame_state_ != BEGIN_FRAME_STATE_INSIDE_DEADLINE) |
| 144 return false; | 159 return false; |
| 145 if (HasDrawnThisFrame()) | 160 if (HasDrawnThisFrame()) |
| 146 return false; | 161 return false; |
| 147 if (output_surface_state_ != OUTPUT_SURFACE_ACTIVE) | 162 if (output_surface_state_ != OUTPUT_SURFACE_ACTIVE) |
| 148 return false; | 163 return false; |
| 149 return true; | 164 return true; |
| 150 } | 165 } |
| 151 | 166 |
| 152 bool SchedulerStateMachine::ShouldAttemptTreeActivation() const { | 167 bool SchedulerStateMachine::ShouldAttemptTreeActivation() const { |
| 153 return has_pending_tree_ && inside_begin_frame_ && | 168 return active_tree_has_been_drawn_or_null_ && |
| 154 !HasAttemptedTreeActivationThisFrame(); | 169 has_pending_tree_ && |
| 170 (begin_frame_state_ == BEGIN_FRAME_STATE_INSIDE_BEGIN_FRAME || |
| 171 begin_frame_state_ == BEGIN_FRAME_STATE_DEADLINE_PENDING || |
| 172 begin_frame_state_ == BEGIN_FRAME_STATE_INSIDE_DEADLINE) && |
| 173 !HasAttemptedTreeActivationThisDrawAttempt(); |
| 155 } | 174 } |
| 156 | 175 |
| 157 bool SchedulerStateMachine::ShouldCheckForCompletedTileUploads() const { | 176 bool SchedulerStateMachine::ShouldCheckForCompletedTileUploads() const { |
| 158 if (!settings_.impl_side_painting) | 177 if (!settings_.impl_side_painting) |
| 159 return false; | 178 return false; |
| 160 if (HasCheckedForCompletedTileUploadsThisFrame()) | 179 if (HasCheckedForCompletedTileUploadsThisDrawAttempt()) |
| 161 return false; | 180 return false; |
| 162 | 181 |
| 163 return ShouldAttemptTreeActivation() || ShouldDraw() || | 182 return ShouldAttemptTreeActivation() || ShouldDraw() || |
| 164 swap_used_incomplete_tile_; | 183 swap_used_incomplete_tile_; |
| 165 } | 184 } |
| 166 | 185 |
| 167 bool SchedulerStateMachine::ShouldAcquireLayerTexturesForMainThread() const { | 186 bool SchedulerStateMachine::ShouldAcquireLayerTexturesForMainThread() const { |
| 168 if (!main_thread_needs_layer_textures_) | 187 if (!main_thread_needs_layer_textures_) |
| 169 return false; | 188 return false; |
| 170 if (texture_state_ == LAYER_TEXTURE_STATE_UNLOCKED) | 189 if (texture_state_ == LAYER_TEXTURE_STATE_UNLOCKED) |
| 171 return true; | 190 return true; |
| 172 DCHECK_EQ(texture_state_, LAYER_TEXTURE_STATE_ACQUIRED_BY_IMPL_THREAD); | 191 DCHECK_EQ(texture_state_, LAYER_TEXTURE_STATE_ACQUIRED_BY_IMPL_THREAD); |
| 173 // Transfer the lock from impl thread to main thread immediately if the | 192 // Transfer the lock from impl thread to main thread immediately if the |
| 174 // impl thread is not even scheduled to draw. Guards against deadlocking. | 193 // impl thread is not even scheduled to draw. Guards against deadlocking. |
| 175 if (!ScheduledToDraw()) | 194 if (!ScheduledToDraw()) |
| 176 return true; | 195 return true; |
| 177 if (!BeginFrameNeededToDrawByImplThread()) | 196 if (!BeginFrameNeededToDrawByImplThread()) |
| 178 return true; | 197 return true; |
| 179 return false; | 198 return false; |
| 180 } | 199 } |
| 181 | 200 |
| 201 bool SchedulerStateMachine::ShouldSendBeginFrameToMainThread() const { |
| 202 if (HasSentBeginFrameToMainThreadThisFrame()) |
| 203 return false; |
| 204 |
| 205 // TODO(brianderson): Allow sending BeginFrame to main thread while idle when |
| 206 // the main thread isn't consuming user input? |
| 207 if (begin_frame_state_ == BEGIN_FRAME_STATE_IDLE || |
| 208 begin_frame_state_ == BEGIN_FRAME_STATE_INSIDE_DEADLINE) |
| 209 return false; |
| 210 |
| 211 // We can't accept a commit if we have a pending tree. |
| 212 if (has_pending_tree_) |
| 213 return false; |
| 214 |
| 215 bool can_commit = needs_commit_ && (visible_ || needs_forced_commit_); |
| 216 switch (commit_state_) { |
| 217 case COMMIT_STATE_IDLE: |
| 218 return can_commit && (needs_forced_commit_ || |
| 219 output_surface_state_ == OUTPUT_SURFACE_ACTIVE); |
| 220 |
| 221 // COMMIT_STATE_WAITING_FOR_ACTIVATION wants to enforce activation and |
| 222 // eventually a draw. |
| 223 // COMMIT_STATE_WAITING_FOR_FIRST_DRAW wants to enforce a draw. |
| 224 // If can_draw_ is false or textures are not available, proceed to the |
| 225 // next step (similar as in COMMIT_STATE_IDLE). |
| 226 case COMMIT_STATE_WAITING_FOR_ACTIVATION: |
| 227 case COMMIT_STATE_WAITING_FOR_FIRST_DRAW: |
| 228 return can_commit && DrawSuspendedUntilCommit(); |
| 229 default: |
| 230 return false; |
| 231 } |
| 232 |
| 233 return false; |
| 234 } |
| 235 |
| 182 SchedulerStateMachine::Action SchedulerStateMachine::NextAction() const { | 236 SchedulerStateMachine::Action SchedulerStateMachine::NextAction() const { |
| 183 if (ShouldAcquireLayerTexturesForMainThread()) | 237 if (ShouldAcquireLayerTexturesForMainThread()) |
| 184 return ACTION_ACQUIRE_LAYER_TEXTURES_FOR_MAIN_THREAD; | 238 return ACTION_ACQUIRE_LAYER_TEXTURES_FOR_MAIN_THREAD; |
| 185 | 239 |
| 186 switch (commit_state_) { | 240 switch (commit_state_) { |
| 187 case COMMIT_STATE_IDLE: | 241 case COMMIT_STATE_IDLE: |
| 188 if (output_surface_state_ != OUTPUT_SURFACE_ACTIVE && | 242 if (output_surface_state_ != OUTPUT_SURFACE_ACTIVE && |
| 189 needs_forced_redraw_) | 243 needs_forced_redraw_) |
| 190 return ACTION_DRAW_FORCED; | 244 return ACTION_DRAW_FORCED; |
| 191 if (output_surface_state_ != OUTPUT_SURFACE_ACTIVE && | 245 if (output_surface_state_ != OUTPUT_SURFACE_ACTIVE && |
| 192 needs_forced_commit_) | 246 needs_forced_commit_) |
| 193 // TODO(enne): Should probably drop the active tree on force commit. | 247 // TODO(enne): Should probably drop the active tree on force commit. |
| 194 return has_pending_tree_ ? ACTION_NONE | 248 return has_pending_tree_ ? ACTION_NONE |
| 195 : ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD; | 249 : ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD; |
| 196 if (output_surface_state_ == OUTPUT_SURFACE_LOST && can_start_) | 250 if (output_surface_state_ == OUTPUT_SURFACE_LOST && can_start_) |
| 197 return ACTION_BEGIN_OUTPUT_SURFACE_CREATION; | 251 return ACTION_BEGIN_OUTPUT_SURFACE_CREATION; |
| 198 if (output_surface_state_ == OUTPUT_SURFACE_CREATING) | 252 if (output_surface_state_ == OUTPUT_SURFACE_CREATING) |
| 199 return ACTION_NONE; | 253 return ACTION_NONE; |
| 200 if (ShouldCheckForCompletedTileUploads()) | 254 if (ShouldCheckForCompletedTileUploads()) |
| 201 return ACTION_CHECK_FOR_COMPLETED_TILE_UPLOADS; | 255 return ACTION_CHECK_FOR_COMPLETED_TILE_UPLOADS; |
| 202 if (ShouldAttemptTreeActivation()) | 256 if (ShouldAttemptTreeActivation()) |
| 203 return ACTION_ACTIVATE_PENDING_TREE_IF_NEEDED; | 257 return ACTION_ACTIVATE_PENDING_TREE_IF_NEEDED; |
| 204 if (ShouldDraw()) { | 258 if (ShouldDraw()) { |
| 205 return needs_forced_redraw_ ? ACTION_DRAW_FORCED | 259 return needs_forced_redraw_ ? ACTION_DRAW_FORCED |
| 206 : ACTION_DRAW_IF_POSSIBLE; | 260 : ACTION_DRAW_IF_POSSIBLE; |
| 207 } | 261 } |
| 208 if (needs_commit_ && | 262 if (ShouldSendBeginFrameToMainThread()) { |
| 209 ((visible_ && output_surface_state_ == OUTPUT_SURFACE_ACTIVE) | |
| 210 || needs_forced_commit_)) | |
| 211 // TODO(enne): Should probably drop the active tree on force commit. | 263 // TODO(enne): Should probably drop the active tree on force commit. |
| 212 return has_pending_tree_ ? ACTION_NONE | 264 return ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD; |
| 213 : ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD; | 265 } |
| 214 return ACTION_NONE; | 266 return ACTION_NONE; |
| 215 | 267 |
| 216 case COMMIT_STATE_FRAME_IN_PROGRESS: | 268 case COMMIT_STATE_FRAME_IN_PROGRESS: |
| 217 if (ShouldCheckForCompletedTileUploads()) | 269 if (ShouldCheckForCompletedTileUploads()) |
| 218 return ACTION_CHECK_FOR_COMPLETED_TILE_UPLOADS; | 270 return ACTION_CHECK_FOR_COMPLETED_TILE_UPLOADS; |
| 219 if (ShouldAttemptTreeActivation()) | 271 if (ShouldAttemptTreeActivation()) |
| 220 return ACTION_ACTIVATE_PENDING_TREE_IF_NEEDED; | 272 return ACTION_ACTIVATE_PENDING_TREE_IF_NEEDED; |
| 221 if (ShouldDraw()) { | 273 if (ShouldDraw()) { |
| 222 return needs_forced_redraw_ ? ACTION_DRAW_FORCED | 274 return needs_forced_redraw_ ? ACTION_DRAW_FORCED |
| 223 : ACTION_DRAW_IF_POSSIBLE; | 275 : ACTION_DRAW_IF_POSSIBLE; |
| 224 } | 276 } |
| 225 return ACTION_NONE; | 277 return ACTION_NONE; |
| 226 | 278 |
| 227 case COMMIT_STATE_READY_TO_COMMIT: | 279 case COMMIT_STATE_READY_TO_COMMIT: |
| 228 return ACTION_COMMIT; | 280 return ACTION_COMMIT; |
| 229 | 281 |
| 282 case COMMIT_STATE_WAITING_FOR_ACTIVATION: |
| 230 case COMMIT_STATE_WAITING_FOR_FIRST_DRAW: { | 283 case COMMIT_STATE_WAITING_FOR_FIRST_DRAW: { |
| 231 if (ShouldCheckForCompletedTileUploads()) | 284 if (ShouldCheckForCompletedTileUploads()) |
| 232 return ACTION_CHECK_FOR_COMPLETED_TILE_UPLOADS; | 285 return ACTION_CHECK_FOR_COMPLETED_TILE_UPLOADS; |
| 233 if (ShouldAttemptTreeActivation()) | 286 if (ShouldAttemptTreeActivation()) |
| 234 return ACTION_ACTIVATE_PENDING_TREE_IF_NEEDED; | 287 return ACTION_ACTIVATE_PENDING_TREE_IF_NEEDED; |
| 235 if (ShouldDraw() || output_surface_state_ == OUTPUT_SURFACE_LOST) { | 288 if (ShouldDraw() || output_surface_state_ == OUTPUT_SURFACE_LOST) { |
| 236 return needs_forced_redraw_ ? ACTION_DRAW_FORCED | 289 return needs_forced_redraw_ ? ACTION_DRAW_FORCED |
| 237 : ACTION_DRAW_IF_POSSIBLE; | 290 : ACTION_DRAW_IF_POSSIBLE; |
| 238 } | 291 } |
| 239 // COMMIT_STATE_WAITING_FOR_FIRST_DRAW wants to enforce a draw. If | 292 if (ShouldSendBeginFrameToMainThread()) |
| 240 // can_draw_ is false or textures are not available, proceed to the next | 293 return ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD; |
| 241 // step (similar as in COMMIT_STATE_IDLE). | |
| 242 bool can_commit = visible_ || needs_forced_commit_; | |
| 243 if (needs_commit_ && can_commit && DrawSuspendedUntilCommit()) | |
| 244 return has_pending_tree_ ? ACTION_NONE | |
| 245 : ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD; | |
| 246 return ACTION_NONE; | 294 return ACTION_NONE; |
| 247 } | 295 } |
| 248 | 296 |
| 249 case COMMIT_STATE_WAITING_FOR_FIRST_FORCED_DRAW: | 297 case COMMIT_STATE_WAITING_FOR_FIRST_FORCED_DRAW: |
| 250 if (ShouldCheckForCompletedTileUploads()) | 298 if (ShouldCheckForCompletedTileUploads()) |
| 251 return ACTION_CHECK_FOR_COMPLETED_TILE_UPLOADS; | 299 return ACTION_CHECK_FOR_COMPLETED_TILE_UPLOADS; |
| 252 if (ShouldAttemptTreeActivation()) | 300 if (ShouldAttemptTreeActivation()) |
| 253 return ACTION_ACTIVATE_PENDING_TREE_IF_NEEDED; | 301 return ACTION_ACTIVATE_PENDING_TREE_IF_NEEDED; |
| 254 if (needs_forced_redraw_) | 302 if (needs_forced_redraw_) |
| 255 return ACTION_DRAW_FORCED; | 303 return ACTION_DRAW_FORCED; |
| 256 return ACTION_NONE; | 304 return ACTION_NONE; |
| 257 } | 305 } |
| 258 NOTREACHED(); | 306 NOTREACHED(); |
| 259 return ACTION_NONE; | 307 return ACTION_NONE; |
| 260 } | 308 } |
| 261 | 309 |
| 262 void SchedulerStateMachine::UpdateState(Action action) { | 310 void SchedulerStateMachine::UpdateState(Action action) { |
| 263 switch (action) { | 311 switch (action) { |
| 264 case ACTION_NONE: | 312 case ACTION_NONE: |
| 313 if (begin_frame_state_ == BEGIN_FRAME_STATE_INSIDE_BEGIN_FRAME) |
| 314 begin_frame_state_ = BEGIN_FRAME_STATE_DEADLINE_PENDING; |
| 315 if (begin_frame_state_ == BEGIN_FRAME_STATE_INSIDE_DEADLINE) |
| 316 begin_frame_state_ = BEGIN_FRAME_STATE_IDLE; |
| 265 return; | 317 return; |
| 266 | 318 |
| 267 case ACTION_CHECK_FOR_COMPLETED_TILE_UPLOADS: | 319 case ACTION_CHECK_FOR_COMPLETED_TILE_UPLOADS: |
| 268 last_frame_number_where_check_for_completed_tile_uploads_called_ = | 320 last_draw_attempt_count_completed_tile_uploads_checked_ = |
| 269 current_frame_number_; | 321 draw_attempt_count_; |
| 270 return; | 322 return; |
| 271 | 323 |
| 272 case ACTION_ACTIVATE_PENDING_TREE_IF_NEEDED: | 324 case ACTION_ACTIVATE_PENDING_TREE_IF_NEEDED: |
| 273 last_frame_number_where_tree_activation_attempted_ = | 325 last_draw_attempt_count_tree_activation_attempted_ = |
| 274 current_frame_number_; | 326 draw_attempt_count_; |
| 275 return; | 327 return; |
| 276 | 328 |
| 277 case ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD: | 329 case ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD: |
| 278 DCHECK(!has_pending_tree_); | 330 DCHECK(!has_pending_tree_); |
| 279 DCHECK(visible_ || needs_forced_commit_); | 331 DCHECK(visible_ || needs_forced_commit_); |
| 280 commit_state_ = COMMIT_STATE_FRAME_IN_PROGRESS; | 332 commit_state_ = COMMIT_STATE_FRAME_IN_PROGRESS; |
| 281 needs_commit_ = false; | 333 needs_commit_ = false; |
| 282 needs_forced_commit_ = false; | 334 needs_forced_commit_ = false; |
| 335 last_begin_frame_count_begin_frame_sent_to_main_thread_ = |
| 336 begin_frame_count_; |
| 283 return; | 337 return; |
| 284 | 338 |
| 285 case ACTION_COMMIT: | 339 case ACTION_COMMIT: |
| 286 commit_count_++; | 340 commit_count_++; |
| 287 if (expect_immediate_begin_frame_for_main_thread_) | 341 if (expect_immediate_begin_frame_for_main_thread_) |
| 288 commit_state_ = COMMIT_STATE_WAITING_FOR_FIRST_FORCED_DRAW; | 342 commit_state_ = COMMIT_STATE_WAITING_FOR_FIRST_FORCED_DRAW; |
| 343 else if (settings_.impl_side_painting) |
| 344 commit_state_ = COMMIT_STATE_WAITING_FOR_ACTIVATION; |
| 289 else | 345 else |
| 290 commit_state_ = COMMIT_STATE_WAITING_FOR_FIRST_DRAW; | 346 commit_state_ = COMMIT_STATE_WAITING_FOR_FIRST_DRAW; |
| 291 // When impl-side painting, we draw on activation instead of on commit. | 347 // When impl-side painting, we draw on activation instead of on commit. |
| 292 if (!settings_.impl_side_painting) | 348 if (!settings_.impl_side_painting) |
| 293 needs_redraw_ = true; | 349 needs_redraw_ = true; |
| 294 if (draw_if_possible_failed_) | 350 if (draw_if_possible_failed_) |
| 295 last_frame_number_where_draw_was_called_ = -1; | 351 last_begin_frame_count_draw_was_called_ = -1; |
| 296 | 352 |
| 297 if (needs_forced_redraw_after_next_commit_) { | 353 if (needs_forced_redraw_after_next_commit_) { |
| 298 needs_forced_redraw_after_next_commit_ = false; | 354 needs_forced_redraw_after_next_commit_ = false; |
| 299 needs_forced_redraw_ = true; | 355 needs_forced_redraw_ = true; |
| 300 } | 356 } |
| 301 | 357 commit_tree_has_been_drawn_or_null_ = false; |
| 302 texture_state_ = LAYER_TEXTURE_STATE_ACQUIRED_BY_IMPL_THREAD; | 358 texture_state_ = LAYER_TEXTURE_STATE_ACQUIRED_BY_IMPL_THREAD; |
| 303 return; | 359 return; |
| 304 | 360 |
| 305 case ACTION_DRAW_FORCED: | 361 case ACTION_DRAW_FORCED: |
| 306 case ACTION_DRAW_IF_POSSIBLE: | 362 case ACTION_DRAW_IF_POSSIBLE: |
| 307 needs_redraw_ = false; | 363 needs_redraw_ = false; |
| 308 needs_forced_redraw_ = false; | 364 needs_forced_redraw_ = false; |
| 309 draw_if_possible_failed_ = false; | 365 draw_if_possible_failed_ = false; |
| 310 swap_used_incomplete_tile_ = false; | 366 swap_used_incomplete_tile_ = false; |
| 311 if (inside_begin_frame_) | 367 last_begin_frame_count_draw_was_called_ = begin_frame_count_; |
| 312 last_frame_number_where_draw_was_called_ = current_frame_number_; | |
| 313 if (commit_state_ == COMMIT_STATE_WAITING_FOR_FIRST_FORCED_DRAW) { | 368 if (commit_state_ == COMMIT_STATE_WAITING_FOR_FIRST_FORCED_DRAW) { |
| 314 DCHECK(expect_immediate_begin_frame_for_main_thread_); | 369 DCHECK(expect_immediate_begin_frame_for_main_thread_); |
| 315 commit_state_ = COMMIT_STATE_FRAME_IN_PROGRESS; | 370 commit_state_ = COMMIT_STATE_FRAME_IN_PROGRESS; |
| 316 expect_immediate_begin_frame_for_main_thread_ = false; | 371 expect_immediate_begin_frame_for_main_thread_ = false; |
| 317 } else if (commit_state_ == COMMIT_STATE_WAITING_FOR_FIRST_DRAW) { | 372 } else if (commit_state_ == COMMIT_STATE_WAITING_FOR_FIRST_DRAW) { |
| 318 commit_state_ = COMMIT_STATE_IDLE; | 373 commit_state_ = COMMIT_STATE_IDLE; |
| 319 } | 374 } |
| 320 if (texture_state_ == LAYER_TEXTURE_STATE_ACQUIRED_BY_IMPL_THREAD) | 375 if (texture_state_ == LAYER_TEXTURE_STATE_ACQUIRED_BY_IMPL_THREAD) |
| 321 texture_state_ = LAYER_TEXTURE_STATE_UNLOCKED; | 376 texture_state_ = LAYER_TEXTURE_STATE_UNLOCKED; |
| 377 active_tree_has_been_drawn_or_null_ = true; |
| 378 commit_tree_has_been_drawn_or_null_ = true; |
| 322 return; | 379 return; |
| 323 | 380 |
| 324 case ACTION_BEGIN_OUTPUT_SURFACE_CREATION: | 381 case ACTION_BEGIN_OUTPUT_SURFACE_CREATION: |
| 325 DCHECK_EQ(commit_state_, COMMIT_STATE_IDLE); | 382 DCHECK_EQ(commit_state_, COMMIT_STATE_IDLE); |
| 326 DCHECK_EQ(output_surface_state_, OUTPUT_SURFACE_LOST); | 383 DCHECK_EQ(output_surface_state_, OUTPUT_SURFACE_LOST); |
| 327 output_surface_state_ = OUTPUT_SURFACE_CREATING; | 384 output_surface_state_ = OUTPUT_SURFACE_CREATING; |
| 328 return; | 385 return; |
| 329 | 386 |
| 330 case ACTION_ACQUIRE_LAYER_TEXTURES_FOR_MAIN_THREAD: | 387 case ACTION_ACQUIRE_LAYER_TEXTURES_FOR_MAIN_THREAD: |
| 331 texture_state_ = LAYER_TEXTURE_STATE_ACQUIRED_BY_MAIN_THREAD; | 388 texture_state_ = LAYER_TEXTURE_STATE_ACQUIRED_BY_MAIN_THREAD; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 365 | 422 |
| 366 bool SchedulerStateMachine::ProactiveBeginFrameWantedByImplThread() const { | 423 bool SchedulerStateMachine::ProactiveBeginFrameWantedByImplThread() const { |
| 367 // We should proactively request a BeginFrame if a commit is pending. | 424 // We should proactively request a BeginFrame if a commit is pending. |
| 368 if (needs_commit_ || needs_forced_commit_ || | 425 if (needs_commit_ || needs_forced_commit_ || |
| 369 commit_state_ != COMMIT_STATE_IDLE) | 426 commit_state_ != COMMIT_STATE_IDLE) |
| 370 return true; | 427 return true; |
| 371 | 428 |
| 372 return false; | 429 return false; |
| 373 } | 430 } |
| 374 | 431 |
| 375 void SchedulerStateMachine::DidEnterBeginFrame(const BeginFrameArgs& args) { | 432 void SchedulerStateMachine::OnBeginFrame(const BeginFrameArgs& args) { |
| 376 inside_begin_frame_ = true; | 433 begin_frame_count_++; |
| 434 draw_attempt_count_++; |
| 377 last_begin_frame_args_ = args; | 435 last_begin_frame_args_ = args; |
| 436 begin_frame_state_ = BEGIN_FRAME_STATE_INSIDE_BEGIN_FRAME; |
| 378 } | 437 } |
| 379 | 438 |
| 380 void SchedulerStateMachine::DidLeaveBeginFrame() { | 439 bool SchedulerStateMachine::ShouldTriggerBeginFrameDeadlineEarly() const { |
| 381 current_frame_number_++; | 440 // TODO(brianderson): This should take into account multiple commit sources. |
| 382 inside_begin_frame_ = false; | 441 return begin_frame_state_ == BEGIN_FRAME_STATE_DEADLINE_PENDING && |
| 442 WillDrawNewTree(); |
| 383 } | 443 } |
| 384 | 444 |
| 385 void SchedulerStateMachine::SetVisible(bool visible) { visible_ = visible; } | 445 bool SchedulerStateMachine::InsideBeginFrame() const { |
| 446 return begin_frame_state_ != BEGIN_FRAME_STATE_IDLE; |
| 447 } |
| 448 |
| 449 bool SchedulerStateMachine::WillDrawNewTree() const { |
| 450 if (settings_.impl_side_painting) |
| 451 return !active_tree_has_been_drawn_or_null_; |
| 452 else |
| 453 return !commit_tree_has_been_drawn_or_null_; |
| 454 } |
| 455 |
| 456 void SchedulerStateMachine::OnBeginFrameDeadline() { |
| 457 draw_attempt_count_++; |
| 458 if (begin_frame_state_ == BEGIN_FRAME_STATE_DEADLINE_PENDING) |
| 459 begin_frame_state_ = BEGIN_FRAME_STATE_INSIDE_DEADLINE; |
| 460 } |
| 461 |
| 462 void SchedulerStateMachine::SetVisible(bool visible) { |
| 463 if (!visible_ && visible) |
| 464 active_tree_has_been_drawn_or_null_ = true; |
| 465 visible_ = visible; |
| 466 } |
| 386 | 467 |
| 387 void SchedulerStateMachine::SetNeedsRedraw() { needs_redraw_ = true; } | 468 void SchedulerStateMachine::SetNeedsRedraw() { needs_redraw_ = true; } |
| 388 | 469 |
| 389 void SchedulerStateMachine::DidSwapUseIncompleteTile() { | 470 void SchedulerStateMachine::DidSwapUseIncompleteTile() { |
| 390 swap_used_incomplete_tile_ = true; | 471 swap_used_incomplete_tile_ = true; |
| 391 } | 472 } |
| 392 | 473 |
| 393 void SchedulerStateMachine::SetNeedsForcedRedraw() { | 474 void SchedulerStateMachine::SetNeedsForcedRedraw() { |
| 394 needs_forced_redraw_ = true; | 475 needs_forced_redraw_ = true; |
| 395 } | 476 } |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 439 } | 520 } |
| 440 | 521 |
| 441 void SchedulerStateMachine::DidLoseOutputSurface() { | 522 void SchedulerStateMachine::DidLoseOutputSurface() { |
| 442 if (output_surface_state_ == OUTPUT_SURFACE_LOST || | 523 if (output_surface_state_ == OUTPUT_SURFACE_LOST || |
| 443 output_surface_state_ == OUTPUT_SURFACE_CREATING) | 524 output_surface_state_ == OUTPUT_SURFACE_CREATING) |
| 444 return; | 525 return; |
| 445 output_surface_state_ = OUTPUT_SURFACE_LOST; | 526 output_surface_state_ = OUTPUT_SURFACE_LOST; |
| 446 } | 527 } |
| 447 | 528 |
| 448 void SchedulerStateMachine::SetHasPendingTree(bool has_pending_tree) { | 529 void SchedulerStateMachine::SetHasPendingTree(bool has_pending_tree) { |
| 530 if (has_pending_tree_ && !has_pending_tree) { |
| 531 // This is a new activation. |
| 532 draw_attempt_count_++; |
| 533 active_tree_has_been_drawn_or_null_ = false; |
| 534 if (COMMIT_STATE_WAITING_FOR_ACTIVATION == commit_state_) |
| 535 commit_state_ = COMMIT_STATE_IDLE; |
| 536 } |
| 537 |
| 449 has_pending_tree_ = has_pending_tree; | 538 has_pending_tree_ = has_pending_tree; |
| 450 } | 539 } |
| 451 | 540 |
| 452 void SchedulerStateMachine::SetCanDraw(bool can) { can_draw_ = can; } | 541 void SchedulerStateMachine::SetCanDraw(bool can) { can_draw_ = can; } |
| 453 | 542 |
| 454 void SchedulerStateMachine::DidCreateAndInitializeOutputSurface() { | 543 void SchedulerStateMachine::DidCreateAndInitializeOutputSurface() { |
| 455 DCHECK_EQ(output_surface_state_, OUTPUT_SURFACE_CREATING); | 544 DCHECK_EQ(output_surface_state_, OUTPUT_SURFACE_CREATING); |
| 456 output_surface_state_ = OUTPUT_SURFACE_ACTIVE; | 545 output_surface_state_ = OUTPUT_SURFACE_ACTIVE; |
| 457 | 546 |
| 458 if (did_create_and_initialize_first_output_surface_) { | 547 if (did_create_and_initialize_first_output_surface_) { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 470 bool SchedulerStateMachine::HasInitializedOutputSurface() const { | 559 bool SchedulerStateMachine::HasInitializedOutputSurface() const { |
| 471 return output_surface_state_ == OUTPUT_SURFACE_ACTIVE; | 560 return output_surface_state_ == OUTPUT_SURFACE_ACTIVE; |
| 472 } | 561 } |
| 473 | 562 |
| 474 void SchedulerStateMachine::SetMaximumNumberOfFailedDrawsBeforeDrawIsForced( | 563 void SchedulerStateMachine::SetMaximumNumberOfFailedDrawsBeforeDrawIsForced( |
| 475 int num_draws) { | 564 int num_draws) { |
| 476 maximum_number_of_failed_draws_before_draw_is_forced_ = num_draws; | 565 maximum_number_of_failed_draws_before_draw_is_forced_ = num_draws; |
| 477 } | 566 } |
| 478 | 567 |
| 479 } // namespace cc | 568 } // namespace cc |
| OLD | NEW |