| 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/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/stringprintf.h" | 8 #include "base/stringprintf.h" |
| 9 | 9 |
| 10 namespace cc { | 10 namespace cc { |
| 11 | 11 |
| 12 SchedulerStateMachine::SchedulerStateMachine(const SchedulerSettings& settings) | 12 SchedulerStateMachine::SchedulerStateMachine(const SchedulerSettings& settings) |
| 13 : settings_(settings), | 13 : settings_(settings), |
| 14 commit_state_(COMMIT_STATE_IDLE), | 14 commit_state_(COMMIT_STATE_IDLE), |
| 15 current_frame_number_(0), | 15 current_frame_number_(0), |
| 16 last_frame_number_where_draw_was_called_(-1), | 16 last_frame_number_where_draw_was_called_(-1), |
| 17 last_frame_number_where_tree_activation_attempted_(-1), | 17 last_frame_number_where_tree_activation_attempted_(-1), |
| 18 last_frame_number_where_check_for_completed_tile_uploads_called_(-1), | 18 last_frame_number_where_check_for_completed_tile_uploads_called_(-1), |
| 19 consecutive_failed_draws_(0), | 19 consecutive_failed_draws_(0), |
| 20 maximum_number_of_failed_draws_before_draw_is_forced_(3), | 20 maximum_number_of_failed_draws_before_draw_is_forced_(3), |
| 21 needs_redraw_(false), | 21 needs_redraw_(false), |
| 22 swap_used_incomplete_tile_(false), | 22 swap_used_incomplete_tile_(false), |
| 23 needs_forced_redraw_(false), | 23 needs_forced_redraw_(false), |
| 24 needs_forced_redraw_after_next_commit_(false), | 24 needs_forced_redraw_after_next_commit_(false), |
| 25 needs_commit_(false), | 25 needs_commit_(false), |
| 26 needs_forced_commit_(false), | 26 needs_forced_commit_(false), |
| 27 expect_immediate_begin_frame_(false), | 27 expect_immediate_begin_main_fame_(false), |
| 28 main_thread_needs_layer_textures_(false), | 28 main_thread_needs_layer_textures_(false), |
| 29 inside_vsync_(false), | 29 inside_begin_impl_frame_(false), |
| 30 visible_(false), | 30 visible_(false), |
| 31 can_start_(false), | 31 can_start_(false), |
| 32 can_draw_(false), | 32 can_draw_(false), |
| 33 has_pending_tree_(false), | 33 has_pending_tree_(false), |
| 34 draw_if_possible_failed_(false), | 34 draw_if_possible_failed_(false), |
| 35 texture_state_(LAYER_TEXTURE_STATE_UNLOCKED), | 35 texture_state_(LAYER_TEXTURE_STATE_UNLOCKED), |
| 36 output_surface_state_(OUTPUT_SURFACE_LOST), | 36 output_surface_state_(OUTPUT_SURFACE_LOST), |
| 37 did_create_and_initialize_first_output_surface_(false) {} | 37 did_create_and_initialize_first_output_surface_(false) {} |
| 38 | 38 |
| 39 std::string SchedulerStateMachine::ToString() { | 39 std::string SchedulerStateMachine::ToString() { |
| (...skipping 26 matching lines...) Expand all Loading... |
| 66 &str, "swap_used_incomplete_tile_ = %d; ", swap_used_incomplete_tile_); | 66 &str, "swap_used_incomplete_tile_ = %d; ", swap_used_incomplete_tile_); |
| 67 base::StringAppendF( | 67 base::StringAppendF( |
| 68 &str, "needs_forced_redraw_ = %d; ", needs_forced_redraw_); | 68 &str, "needs_forced_redraw_ = %d; ", needs_forced_redraw_); |
| 69 base::StringAppendF(&str, | 69 base::StringAppendF(&str, |
| 70 "needs_forced_redraw_after_next_commit_ = %d; ", | 70 "needs_forced_redraw_after_next_commit_ = %d; ", |
| 71 needs_forced_redraw_after_next_commit_); | 71 needs_forced_redraw_after_next_commit_); |
| 72 base::StringAppendF(&str, "needs_commit_ = %d; ", needs_commit_); | 72 base::StringAppendF(&str, "needs_commit_ = %d; ", needs_commit_); |
| 73 base::StringAppendF( | 73 base::StringAppendF( |
| 74 &str, "needs_forced_commit_ = %d; ", needs_forced_commit_); | 74 &str, "needs_forced_commit_ = %d; ", needs_forced_commit_); |
| 75 base::StringAppendF(&str, | 75 base::StringAppendF(&str, |
| 76 "expect_immediate_begin_frame_ = %d; ", | 76 "expect_immediate_begin_main_fame_ = %d; ", |
| 77 expect_immediate_begin_frame_); | 77 expect_immediate_begin_main_fame_); |
| 78 base::StringAppendF(&str, | 78 base::StringAppendF(&str, |
| 79 "main_thread_needs_layer_textures_ = %d; ", | 79 "main_thread_needs_layer_textures_ = %d; ", |
| 80 main_thread_needs_layer_textures_); | 80 main_thread_needs_layer_textures_); |
| 81 base::StringAppendF(&str, "inside_vsync_ = %d; ", inside_vsync_); | 81 base::StringAppendF(&str, "inside_begin_impl_frame_ = %d; ", |
| 82 inside_begin_impl_frame_); |
| 82 base::StringAppendF(&str, "visible_ = %d; ", visible_); | 83 base::StringAppendF(&str, "visible_ = %d; ", visible_); |
| 83 base::StringAppendF(&str, "can_start_ = %d; ", can_start_); | 84 base::StringAppendF(&str, "can_start_ = %d; ", can_start_); |
| 84 base::StringAppendF(&str, "can_draw_ = %d; ", can_draw_); | 85 base::StringAppendF(&str, "can_draw_ = %d; ", can_draw_); |
| 85 base::StringAppendF( | 86 base::StringAppendF( |
| 86 &str, "draw_if_possible_failed_ = %d; ", draw_if_possible_failed_); | 87 &str, "draw_if_possible_failed_ = %d; ", draw_if_possible_failed_); |
| 87 base::StringAppendF(&str, "has_pending_tree_ = %d; ", has_pending_tree_); | 88 base::StringAppendF(&str, "has_pending_tree_ = %d; ", has_pending_tree_); |
| 88 base::StringAppendF(&str, "texture_state_ = %d; ", texture_state_); | 89 base::StringAppendF(&str, "texture_state_ = %d; ", texture_state_); |
| 89 base::StringAppendF( | 90 base::StringAppendF( |
| 90 &str, "output_surface_state_ = %d; ", output_surface_state_); | 91 &str, "output_surface_state_ = %d; ", output_surface_state_); |
| 91 return str; | 92 return str; |
| (...skipping 30 matching lines...) Expand all Loading... |
| 122 return false; | 123 return false; |
| 123 return true; | 124 return true; |
| 124 } | 125 } |
| 125 | 126 |
| 126 bool SchedulerStateMachine::ShouldDraw() const { | 127 bool SchedulerStateMachine::ShouldDraw() const { |
| 127 if (needs_forced_redraw_) | 128 if (needs_forced_redraw_) |
| 128 return true; | 129 return true; |
| 129 | 130 |
| 130 if (!ScheduledToDraw()) | 131 if (!ScheduledToDraw()) |
| 131 return false; | 132 return false; |
| 132 if (!inside_vsync_) | 133 if (!inside_begin_impl_frame_) |
| 133 return false; | 134 return false; |
| 134 if (HasDrawnThisFrame()) | 135 if (HasDrawnThisFrame()) |
| 135 return false; | 136 return false; |
| 136 if (output_surface_state_ != OUTPUT_SURFACE_ACTIVE) | 137 if (output_surface_state_ != OUTPUT_SURFACE_ACTIVE) |
| 137 return false; | 138 return false; |
| 138 return true; | 139 return true; |
| 139 } | 140 } |
| 140 | 141 |
| 141 bool SchedulerStateMachine::ShouldAttemptTreeActivation() const { | 142 bool SchedulerStateMachine::ShouldAttemptTreeActivation() const { |
| 142 return has_pending_tree_ && inside_vsync_ && | 143 return has_pending_tree_ && inside_begin_impl_frame_ && |
| 143 !HasAttemptedTreeActivationThisFrame(); | 144 !HasAttemptedTreeActivationThisFrame(); |
| 144 } | 145 } |
| 145 | 146 |
| 146 bool SchedulerStateMachine::ShouldCheckForCompletedTileUploads() const { | 147 bool SchedulerStateMachine::ShouldCheckForCompletedTileUploads() const { |
| 147 if (!settings_.impl_side_painting) | 148 if (!settings_.impl_side_painting) |
| 148 return false; | 149 return false; |
| 149 if (HasCheckedForCompletedTileUploadsThisFrame()) | 150 if (HasCheckedForCompletedTileUploadsThisFrame()) |
| 150 return false; | 151 return false; |
| 151 | 152 |
| 152 return ShouldAttemptTreeActivation() || ShouldDraw() || | 153 return ShouldAttemptTreeActivation() || ShouldDraw() || |
| 153 swap_used_incomplete_tile_; | 154 swap_used_incomplete_tile_; |
| 154 } | 155 } |
| 155 | 156 |
| 156 bool SchedulerStateMachine::ShouldAcquireLayerTexturesForMainThread() const { | 157 bool SchedulerStateMachine::ShouldAcquireLayerTexturesForMainThread() const { |
| 157 if (!main_thread_needs_layer_textures_) | 158 if (!main_thread_needs_layer_textures_) |
| 158 return false; | 159 return false; |
| 159 if (texture_state_ == LAYER_TEXTURE_STATE_UNLOCKED) | 160 if (texture_state_ == LAYER_TEXTURE_STATE_UNLOCKED) |
| 160 return true; | 161 return true; |
| 161 DCHECK_EQ(texture_state_, LAYER_TEXTURE_STATE_ACQUIRED_BY_IMPL_THREAD); | 162 DCHECK_EQ(texture_state_, LAYER_TEXTURE_STATE_ACQUIRED_BY_IMPL_THREAD); |
| 162 // Transfer the lock from impl thread to main thread immediately if the | 163 // Transfer the lock from impl thread to main thread immediately if the |
| 163 // impl thread is not even scheduled to draw. Guards against deadlocking. | 164 // impl thread is not even scheduled to draw. Guards against deadlocking. |
| 164 if (!ScheduledToDraw()) | 165 if (!ScheduledToDraw()) |
| 165 return true; | 166 return true; |
| 166 if (!VSyncCallbackNeeded()) | 167 if (!BeginMainFrameCallbackNeeded()) |
| 167 return true; | 168 return true; |
| 168 return false; | 169 return false; |
| 169 } | 170 } |
| 170 | 171 |
| 171 SchedulerStateMachine::Action SchedulerStateMachine::NextAction() const { | 172 SchedulerStateMachine::Action SchedulerStateMachine::NextAction() const { |
| 172 if (ShouldAcquireLayerTexturesForMainThread()) | 173 if (ShouldAcquireLayerTexturesForMainThread()) |
| 173 return ACTION_ACQUIRE_LAYER_TEXTURES_FOR_MAIN_THREAD; | 174 return ACTION_ACQUIRE_LAYER_TEXTURES_FOR_MAIN_THREAD; |
| 174 | 175 |
| 175 switch (commit_state_) { | 176 switch (commit_state_) { |
| 176 case COMMIT_STATE_IDLE: | 177 case COMMIT_STATE_IDLE: |
| 177 if (output_surface_state_ != OUTPUT_SURFACE_ACTIVE && | 178 if (output_surface_state_ != OUTPUT_SURFACE_ACTIVE && |
| 178 needs_forced_redraw_) | 179 needs_forced_redraw_) |
| 179 return ACTION_DRAW_FORCED; | 180 return ACTION_DRAW_FORCED; |
| 180 if (output_surface_state_ != OUTPUT_SURFACE_ACTIVE && | 181 if (output_surface_state_ != OUTPUT_SURFACE_ACTIVE && |
| 181 needs_forced_commit_) | 182 needs_forced_commit_) |
| 182 // TODO(enne): Should probably drop the active tree on force commit. | 183 // TODO(enne): Should probably drop the active tree on force commit. |
| 183 return has_pending_tree_ ? ACTION_NONE : ACTION_BEGIN_FRAME; | 184 return has_pending_tree_ ? ACTION_NONE : ACTION_BEGIN_MAIN_FRAME; |
| 184 if (output_surface_state_ == OUTPUT_SURFACE_LOST && can_start_) | 185 if (output_surface_state_ == OUTPUT_SURFACE_LOST && can_start_) |
| 185 return ACTION_BEGIN_OUTPUT_SURFACE_CREATION; | 186 return ACTION_BEGIN_OUTPUT_SURFACE_CREATION; |
| 186 if (output_surface_state_ == OUTPUT_SURFACE_CREATING) | 187 if (output_surface_state_ == OUTPUT_SURFACE_CREATING) |
| 187 return ACTION_NONE; | 188 return ACTION_NONE; |
| 188 if (ShouldCheckForCompletedTileUploads()) | 189 if (ShouldCheckForCompletedTileUploads()) |
| 189 return ACTION_CHECK_FOR_COMPLETED_TILE_UPLOADS; | 190 return ACTION_CHECK_FOR_COMPLETED_TILE_UPLOADS; |
| 190 if (ShouldAttemptTreeActivation()) | 191 if (ShouldAttemptTreeActivation()) |
| 191 return ACTION_ACTIVATE_PENDING_TREE_IF_NEEDED; | 192 return ACTION_ACTIVATE_PENDING_TREE_IF_NEEDED; |
| 192 if (ShouldDraw()) { | 193 if (ShouldDraw()) { |
| 193 return needs_forced_redraw_ ? ACTION_DRAW_FORCED | 194 return needs_forced_redraw_ ? ACTION_DRAW_FORCED |
| 194 : ACTION_DRAW_IF_POSSIBLE; | 195 : ACTION_DRAW_IF_POSSIBLE; |
| 195 } | 196 } |
| 196 if (needs_commit_ && | 197 if (needs_commit_ && |
| 197 ((visible_ && output_surface_state_ == OUTPUT_SURFACE_ACTIVE) | 198 ((visible_ && output_surface_state_ == OUTPUT_SURFACE_ACTIVE) |
| 198 || needs_forced_commit_)) | 199 || needs_forced_commit_)) |
| 199 // TODO(enne): Should probably drop the active tree on force commit. | 200 // TODO(enne): Should probably drop the active tree on force commit. |
| 200 return has_pending_tree_ ? ACTION_NONE : ACTION_BEGIN_FRAME; | 201 return has_pending_tree_ ? ACTION_NONE : ACTION_BEGIN_MAIN_FRAME; |
| 201 return ACTION_NONE; | 202 return ACTION_NONE; |
| 202 | 203 |
| 203 case COMMIT_STATE_FRAME_IN_PROGRESS: | 204 case COMMIT_STATE_FRAME_IN_PROGRESS: |
| 204 if (ShouldCheckForCompletedTileUploads()) | 205 if (ShouldCheckForCompletedTileUploads()) |
| 205 return ACTION_CHECK_FOR_COMPLETED_TILE_UPLOADS; | 206 return ACTION_CHECK_FOR_COMPLETED_TILE_UPLOADS; |
| 206 if (ShouldAttemptTreeActivation()) | 207 if (ShouldAttemptTreeActivation()) |
| 207 return ACTION_ACTIVATE_PENDING_TREE_IF_NEEDED; | 208 return ACTION_ACTIVATE_PENDING_TREE_IF_NEEDED; |
| 208 if (ShouldDraw()) { | 209 if (ShouldDraw()) { |
| 209 return needs_forced_redraw_ ? ACTION_DRAW_FORCED | 210 return needs_forced_redraw_ ? ACTION_DRAW_FORCED |
| 210 : ACTION_DRAW_IF_POSSIBLE; | 211 : ACTION_DRAW_IF_POSSIBLE; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 221 return ACTION_ACTIVATE_PENDING_TREE_IF_NEEDED; | 222 return ACTION_ACTIVATE_PENDING_TREE_IF_NEEDED; |
| 222 if (ShouldDraw() || output_surface_state_ == OUTPUT_SURFACE_LOST) { | 223 if (ShouldDraw() || output_surface_state_ == OUTPUT_SURFACE_LOST) { |
| 223 return needs_forced_redraw_ ? ACTION_DRAW_FORCED | 224 return needs_forced_redraw_ ? ACTION_DRAW_FORCED |
| 224 : ACTION_DRAW_IF_POSSIBLE; | 225 : ACTION_DRAW_IF_POSSIBLE; |
| 225 } | 226 } |
| 226 // COMMIT_STATE_WAITING_FOR_FIRST_DRAW wants to enforce a draw. If | 227 // COMMIT_STATE_WAITING_FOR_FIRST_DRAW wants to enforce a draw. If |
| 227 // can_draw_ is false or textures are not available, proceed to the next | 228 // can_draw_ is false or textures are not available, proceed to the next |
| 228 // step (similar as in COMMIT_STATE_IDLE). | 229 // step (similar as in COMMIT_STATE_IDLE). |
| 229 bool can_commit = visible_ || needs_forced_commit_; | 230 bool can_commit = visible_ || needs_forced_commit_; |
| 230 if (needs_commit_ && can_commit && DrawSuspendedUntilCommit()) | 231 if (needs_commit_ && can_commit && DrawSuspendedUntilCommit()) |
| 231 return has_pending_tree_ ? ACTION_NONE : ACTION_BEGIN_FRAME; | 232 return has_pending_tree_ ? ACTION_NONE : ACTION_BEGIN_MAIN_FRAME; |
| 232 return ACTION_NONE; | 233 return ACTION_NONE; |
| 233 } | 234 } |
| 234 | 235 |
| 235 case COMMIT_STATE_WAITING_FOR_FIRST_FORCED_DRAW: | 236 case COMMIT_STATE_WAITING_FOR_FIRST_FORCED_DRAW: |
| 236 if (ShouldCheckForCompletedTileUploads()) | 237 if (ShouldCheckForCompletedTileUploads()) |
| 237 return ACTION_CHECK_FOR_COMPLETED_TILE_UPLOADS; | 238 return ACTION_CHECK_FOR_COMPLETED_TILE_UPLOADS; |
| 238 if (ShouldAttemptTreeActivation()) | 239 if (ShouldAttemptTreeActivation()) |
| 239 return ACTION_ACTIVATE_PENDING_TREE_IF_NEEDED; | 240 return ACTION_ACTIVATE_PENDING_TREE_IF_NEEDED; |
| 240 if (needs_forced_redraw_) | 241 if (needs_forced_redraw_) |
| 241 return ACTION_DRAW_FORCED; | 242 return ACTION_DRAW_FORCED; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 253 case ACTION_CHECK_FOR_COMPLETED_TILE_UPLOADS: | 254 case ACTION_CHECK_FOR_COMPLETED_TILE_UPLOADS: |
| 254 last_frame_number_where_check_for_completed_tile_uploads_called_ = | 255 last_frame_number_where_check_for_completed_tile_uploads_called_ = |
| 255 current_frame_number_; | 256 current_frame_number_; |
| 256 return; | 257 return; |
| 257 | 258 |
| 258 case ACTION_ACTIVATE_PENDING_TREE_IF_NEEDED: | 259 case ACTION_ACTIVATE_PENDING_TREE_IF_NEEDED: |
| 259 last_frame_number_where_tree_activation_attempted_ = | 260 last_frame_number_where_tree_activation_attempted_ = |
| 260 current_frame_number_; | 261 current_frame_number_; |
| 261 return; | 262 return; |
| 262 | 263 |
| 263 case ACTION_BEGIN_FRAME: | 264 case ACTION_BEGIN_MAIN_FRAME: |
| 264 DCHECK(!has_pending_tree_); | 265 DCHECK(!has_pending_tree_); |
| 265 DCHECK(visible_ || needs_forced_commit_); | 266 DCHECK(visible_ || needs_forced_commit_); |
| 266 commit_state_ = COMMIT_STATE_FRAME_IN_PROGRESS; | 267 commit_state_ = COMMIT_STATE_FRAME_IN_PROGRESS; |
| 267 needs_commit_ = false; | 268 needs_commit_ = false; |
| 268 needs_forced_commit_ = false; | 269 needs_forced_commit_ = false; |
| 269 return; | 270 return; |
| 270 | 271 |
| 271 case ACTION_COMMIT: | 272 case ACTION_COMMIT: |
| 272 if (expect_immediate_begin_frame_) | 273 if (expect_immediate_begin_main_fame_) |
| 273 commit_state_ = COMMIT_STATE_WAITING_FOR_FIRST_FORCED_DRAW; | 274 commit_state_ = COMMIT_STATE_WAITING_FOR_FIRST_FORCED_DRAW; |
| 274 else | 275 else |
| 275 commit_state_ = COMMIT_STATE_WAITING_FOR_FIRST_DRAW; | 276 commit_state_ = COMMIT_STATE_WAITING_FOR_FIRST_DRAW; |
| 276 // When impl-side painting, we draw on activation instead of on commit. | 277 // When impl-side painting, we draw on activation instead of on commit. |
| 277 if (!settings_.impl_side_painting) | 278 if (!settings_.impl_side_painting) |
| 278 needs_redraw_ = true; | 279 needs_redraw_ = true; |
| 279 if (draw_if_possible_failed_) | 280 if (draw_if_possible_failed_) |
| 280 last_frame_number_where_draw_was_called_ = -1; | 281 last_frame_number_where_draw_was_called_ = -1; |
| 281 | 282 |
| 282 if (needs_forced_redraw_after_next_commit_) { | 283 if (needs_forced_redraw_after_next_commit_) { |
| 283 needs_forced_redraw_after_next_commit_ = false; | 284 needs_forced_redraw_after_next_commit_ = false; |
| 284 needs_forced_redraw_ = true; | 285 needs_forced_redraw_ = true; |
| 285 } | 286 } |
| 286 | 287 |
| 287 texture_state_ = LAYER_TEXTURE_STATE_ACQUIRED_BY_IMPL_THREAD; | 288 texture_state_ = LAYER_TEXTURE_STATE_ACQUIRED_BY_IMPL_THREAD; |
| 288 return; | 289 return; |
| 289 | 290 |
| 290 case ACTION_DRAW_FORCED: | 291 case ACTION_DRAW_FORCED: |
| 291 case ACTION_DRAW_IF_POSSIBLE: | 292 case ACTION_DRAW_IF_POSSIBLE: |
| 292 needs_redraw_ = false; | 293 needs_redraw_ = false; |
| 293 needs_forced_redraw_ = false; | 294 needs_forced_redraw_ = false; |
| 294 draw_if_possible_failed_ = false; | 295 draw_if_possible_failed_ = false; |
| 295 swap_used_incomplete_tile_ = false; | 296 swap_used_incomplete_tile_ = false; |
| 296 if (inside_vsync_) | 297 if (inside_begin_impl_frame_) |
| 297 last_frame_number_where_draw_was_called_ = current_frame_number_; | 298 last_frame_number_where_draw_was_called_ = current_frame_number_; |
| 298 if (commit_state_ == COMMIT_STATE_WAITING_FOR_FIRST_FORCED_DRAW) { | 299 if (commit_state_ == COMMIT_STATE_WAITING_FOR_FIRST_FORCED_DRAW) { |
| 299 DCHECK(expect_immediate_begin_frame_); | 300 DCHECK(expect_immediate_begin_main_fame_); |
| 300 commit_state_ = COMMIT_STATE_FRAME_IN_PROGRESS; | 301 commit_state_ = COMMIT_STATE_FRAME_IN_PROGRESS; |
| 301 expect_immediate_begin_frame_ = false; | 302 expect_immediate_begin_main_fame_ = false; |
| 302 } else if (commit_state_ == COMMIT_STATE_WAITING_FOR_FIRST_DRAW) { | 303 } else if (commit_state_ == COMMIT_STATE_WAITING_FOR_FIRST_DRAW) { |
| 303 commit_state_ = COMMIT_STATE_IDLE; | 304 commit_state_ = COMMIT_STATE_IDLE; |
| 304 } | 305 } |
| 305 if (texture_state_ == LAYER_TEXTURE_STATE_ACQUIRED_BY_IMPL_THREAD) | 306 if (texture_state_ == LAYER_TEXTURE_STATE_ACQUIRED_BY_IMPL_THREAD) |
| 306 texture_state_ = LAYER_TEXTURE_STATE_UNLOCKED; | 307 texture_state_ = LAYER_TEXTURE_STATE_UNLOCKED; |
| 307 return; | 308 return; |
| 308 | 309 |
| 309 case ACTION_BEGIN_OUTPUT_SURFACE_CREATION: | 310 case ACTION_BEGIN_OUTPUT_SURFACE_CREATION: |
| 310 DCHECK_EQ(commit_state_, COMMIT_STATE_IDLE); | 311 DCHECK_EQ(commit_state_, COMMIT_STATE_IDLE); |
| 311 DCHECK_EQ(output_surface_state_, OUTPUT_SURFACE_LOST); | 312 DCHECK_EQ(output_surface_state_, OUTPUT_SURFACE_LOST); |
| 312 output_surface_state_ = OUTPUT_SURFACE_CREATING; | 313 output_surface_state_ = OUTPUT_SURFACE_CREATING; |
| 313 return; | 314 return; |
| 314 | 315 |
| 315 case ACTION_ACQUIRE_LAYER_TEXTURES_FOR_MAIN_THREAD: | 316 case ACTION_ACQUIRE_LAYER_TEXTURES_FOR_MAIN_THREAD: |
| 316 texture_state_ = LAYER_TEXTURE_STATE_ACQUIRED_BY_MAIN_THREAD; | 317 texture_state_ = LAYER_TEXTURE_STATE_ACQUIRED_BY_MAIN_THREAD; |
| 317 main_thread_needs_layer_textures_ = false; | 318 main_thread_needs_layer_textures_ = false; |
| 318 if (commit_state_ != COMMIT_STATE_FRAME_IN_PROGRESS) | 319 if (commit_state_ != COMMIT_STATE_FRAME_IN_PROGRESS) |
| 319 needs_commit_ = true; | 320 needs_commit_ = true; |
| 320 return; | 321 return; |
| 321 } | 322 } |
| 322 } | 323 } |
| 323 | 324 |
| 324 void SchedulerStateMachine::SetMainThreadNeedsLayerTextures() { | 325 void SchedulerStateMachine::SetMainThreadNeedsLayerTextures() { |
| 325 DCHECK(!main_thread_needs_layer_textures_); | 326 DCHECK(!main_thread_needs_layer_textures_); |
| 326 DCHECK_NE(texture_state_, LAYER_TEXTURE_STATE_ACQUIRED_BY_MAIN_THREAD); | 327 DCHECK_NE(texture_state_, LAYER_TEXTURE_STATE_ACQUIRED_BY_MAIN_THREAD); |
| 327 main_thread_needs_layer_textures_ = true; | 328 main_thread_needs_layer_textures_ = true; |
| 328 } | 329 } |
| 329 | 330 |
| 330 bool SchedulerStateMachine::VSyncCallbackNeeded() const { | 331 bool SchedulerStateMachine::BeginMainFrameCallbackNeeded() const { |
| 331 // If we have a pending tree, need to keep getting notifications until | 332 // If we have a pending tree, need to keep getting notifications until |
| 332 // the tree is ready to be swapped. | 333 // the tree is ready to be swapped. |
| 333 if (has_pending_tree_) | 334 if (has_pending_tree_) |
| 334 return true; | 335 return true; |
| 335 | 336 |
| 336 // If we can't draw, don't tick until we are notified that we can draw again. | 337 // If we can't draw, don't tick until we are notified that we can draw again. |
| 337 if (!can_draw_) | 338 if (!can_draw_) |
| 338 return false; | 339 return false; |
| 339 | 340 |
| 340 if (needs_forced_redraw_) | 341 if (needs_forced_redraw_) |
| 341 return true; | 342 return true; |
| 342 | 343 |
| 343 if (visible_ && swap_used_incomplete_tile_) | 344 if (visible_ && swap_used_incomplete_tile_) |
| 344 return true; | 345 return true; |
| 345 | 346 |
| 346 return needs_redraw_ && visible_ && | 347 return needs_redraw_ && visible_ && |
| 347 output_surface_state_ == OUTPUT_SURFACE_ACTIVE; | 348 output_surface_state_ == OUTPUT_SURFACE_ACTIVE; |
| 348 } | 349 } |
| 349 | 350 |
| 350 void SchedulerStateMachine::DidEnterVSync() { inside_vsync_ = true; } | 351 void SchedulerStateMachine::DidEnterBeginImplFrame() { |
| 352 inside_begin_impl_frame_ = true; |
| 353 } |
| 351 | 354 |
| 352 void SchedulerStateMachine::DidLeaveVSync() { | 355 void SchedulerStateMachine::DidLeaveBeginImplFrame() { |
| 353 current_frame_number_++; | 356 current_frame_number_++; |
| 354 inside_vsync_ = false; | 357 inside_begin_impl_frame_ = false; |
| 355 } | 358 } |
| 356 | 359 |
| 357 void SchedulerStateMachine::SetVisible(bool visible) { visible_ = visible; } | 360 void SchedulerStateMachine::SetVisible(bool visible) { visible_ = visible; } |
| 358 | 361 |
| 359 void SchedulerStateMachine::SetNeedsRedraw() { needs_redraw_ = true; } | 362 void SchedulerStateMachine::SetNeedsRedraw() { needs_redraw_ = true; } |
| 360 | 363 |
| 361 void SchedulerStateMachine::DidSwapUseIncompleteTile() { | 364 void SchedulerStateMachine::DidSwapUseIncompleteTile() { |
| 362 swap_used_incomplete_tile_ = true; | 365 swap_used_incomplete_tile_ = true; |
| 363 } | 366 } |
| 364 | 367 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 382 } | 385 } |
| 383 } else { | 386 } else { |
| 384 consecutive_failed_draws_ = 0; | 387 consecutive_failed_draws_ = 0; |
| 385 } | 388 } |
| 386 } | 389 } |
| 387 | 390 |
| 388 void SchedulerStateMachine::SetNeedsCommit() { needs_commit_ = true; } | 391 void SchedulerStateMachine::SetNeedsCommit() { needs_commit_ = true; } |
| 389 | 392 |
| 390 void SchedulerStateMachine::SetNeedsForcedCommit() { | 393 void SchedulerStateMachine::SetNeedsForcedCommit() { |
| 391 needs_forced_commit_ = true; | 394 needs_forced_commit_ = true; |
| 392 expect_immediate_begin_frame_ = true; | 395 expect_immediate_begin_main_fame_ = true; |
| 393 } | 396 } |
| 394 | 397 |
| 395 void SchedulerStateMachine::BeginFrameComplete() { | 398 void SchedulerStateMachine::BeginMainFrameComplete() { |
| 396 DCHECK(commit_state_ == COMMIT_STATE_FRAME_IN_PROGRESS || | 399 DCHECK(commit_state_ == COMMIT_STATE_FRAME_IN_PROGRESS || |
| 397 (expect_immediate_begin_frame_ && commit_state_ != COMMIT_STATE_IDLE)) | 400 (expect_immediate_begin_main_fame_ && |
| 401 commit_state_ != COMMIT_STATE_IDLE)) |
| 398 << ToString(); | 402 << ToString(); |
| 399 commit_state_ = COMMIT_STATE_READY_TO_COMMIT; | 403 commit_state_ = COMMIT_STATE_READY_TO_COMMIT; |
| 400 } | 404 } |
| 401 | 405 |
| 402 void SchedulerStateMachine::BeginFrameAborted() { | 406 void SchedulerStateMachine::BeginMainFrameAborted() { |
| 403 DCHECK_EQ(commit_state_, COMMIT_STATE_FRAME_IN_PROGRESS); | 407 DCHECK_EQ(commit_state_, COMMIT_STATE_FRAME_IN_PROGRESS); |
| 404 if (expect_immediate_begin_frame_) { | 408 if (expect_immediate_begin_main_fame_) { |
| 405 expect_immediate_begin_frame_ = false; | 409 expect_immediate_begin_main_fame_ = false; |
| 406 } else { | 410 } else { |
| 407 commit_state_ = COMMIT_STATE_IDLE; | 411 commit_state_ = COMMIT_STATE_IDLE; |
| 408 SetNeedsCommit(); | 412 SetNeedsCommit(); |
| 409 } | 413 } |
| 410 } | 414 } |
| 411 | 415 |
| 412 void SchedulerStateMachine::DidLoseOutputSurface() { | 416 void SchedulerStateMachine::DidLoseOutputSurface() { |
| 413 if (output_surface_state_ == OUTPUT_SURFACE_LOST || | 417 if (output_surface_state_ == OUTPUT_SURFACE_LOST || |
| 414 output_surface_state_ == OUTPUT_SURFACE_CREATING) | 418 output_surface_state_ == OUTPUT_SURFACE_CREATING) |
| 415 return; | 419 return; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 441 bool SchedulerStateMachine::HasInitializedOutputSurface() const { | 445 bool SchedulerStateMachine::HasInitializedOutputSurface() const { |
| 442 return output_surface_state_ == OUTPUT_SURFACE_ACTIVE; | 446 return output_surface_state_ == OUTPUT_SURFACE_ACTIVE; |
| 443 } | 447 } |
| 444 | 448 |
| 445 void SchedulerStateMachine::SetMaximumNumberOfFailedDrawsBeforeDrawIsForced( | 449 void SchedulerStateMachine::SetMaximumNumberOfFailedDrawsBeforeDrawIsForced( |
| 446 int num_draws) { | 450 int num_draws) { |
| 447 maximum_number_of_failed_draws_before_draw_is_forced_ = num_draws; | 451 maximum_number_of_failed_draws_before_draw_is_forced_ = num_draws; |
| 448 } | 452 } |
| 449 | 453 |
| 450 } // namespace cc | 454 } // namespace cc |
| OLD | NEW |