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/values.h" | 10 #include "base/values.h" |
| 11 | 11 |
| 12 namespace cc { | 12 namespace cc { |
| 13 | 13 |
| 14 SchedulerStateMachine::SchedulerStateMachine(const SchedulerSettings& settings) | 14 SchedulerStateMachine::SchedulerStateMachine(const SchedulerSettings& settings) |
| 15 : settings_(settings), | 15 : settings_(settings), |
| 16 output_surface_state_(OUTPUT_SURFACE_LOST), | 16 output_surface_state_(OUTPUT_SURFACE_LOST), |
| 17 commit_state_(COMMIT_STATE_IDLE), | 17 commit_state_(COMMIT_STATE_IDLE), |
| 18 commit_count_(0), | 18 commit_count_(0), |
| 19 current_frame_number_(0), | 19 current_frame_number_(0), |
| 20 last_frame_number_where_begin_frame_sent_to_main_thread_(-1), | 20 last_frame_number_where_begin_frame_sent_to_main_thread_(-1), |
| 21 last_frame_number_where_draw_was_called_(-1), | 21 last_frame_number_where_draw_was_called_(-1), |
| 22 last_frame_number_where_tree_activation_attempted_(-1), | 22 last_frame_number_pending_tree_activated_(-1), |
| 23 last_frame_number_where_update_visible_tiles_was_called_(-1), | 23 last_frame_number_where_update_visible_tiles_was_called_(-1), |
| 24 consecutive_failed_draws_(0), | 24 consecutive_failed_draws_(0), |
| 25 maximum_number_of_failed_draws_before_draw_is_forced_(3), | 25 maximum_number_of_failed_draws_before_draw_is_forced_(3), |
| 26 needs_redraw_(false), | 26 needs_redraw_(false), |
| 27 swap_used_incomplete_tile_(false), | 27 swap_used_incomplete_tile_(false), |
| 28 needs_forced_redraw_(false), | 28 needs_forced_redraw_(false), |
| 29 needs_forced_redraw_after_next_commit_(false), | 29 needs_forced_redraw_after_next_commit_(false), |
| 30 needs_commit_(false), | 30 needs_commit_(false), |
| 31 needs_forced_commit_(false), | 31 needs_forced_commit_(false), |
| 32 expect_immediate_begin_frame_for_main_thread_(false), | 32 expect_immediate_begin_frame_for_main_thread_(false), |
| 33 main_thread_needs_layer_textures_(false), | 33 main_thread_needs_layer_textures_(false), |
| 34 inside_begin_frame_(false), | 34 inside_begin_frame_(false), |
| 35 active_tree_has_been_drawn_(false), | |
| 36 active_tree_is_null_(true), | |
| 35 visible_(false), | 37 visible_(false), |
| 36 can_start_(false), | 38 can_start_(false), |
| 37 can_draw_(false), | 39 can_draw_(false), |
| 38 has_pending_tree_(false), | 40 has_pending_tree_(false), |
| 41 pending_tree_is_ready_for_activation_(false), | |
| 39 draw_if_possible_failed_(false), | 42 draw_if_possible_failed_(false), |
| 40 texture_state_(LAYER_TEXTURE_STATE_UNLOCKED), | 43 texture_state_(LAYER_TEXTURE_STATE_UNLOCKED), |
| 41 did_create_and_initialize_first_output_surface_(false) {} | 44 did_create_and_initialize_first_output_surface_(false) {} |
| 42 | 45 |
| 43 const char* SchedulerStateMachine::OutputSurfaceStateToString( | 46 const char* SchedulerStateMachine::OutputSurfaceStateToString( |
| 44 OutputSurfaceState state) { | 47 OutputSurfaceState state) { |
| 45 switch (state) { | 48 switch (state) { |
| 46 case OUTPUT_SURFACE_ACTIVE: | 49 case OUTPUT_SURFACE_ACTIVE: |
| 47 return "OUTPUT_SURFACE_ACTIVE"; | 50 return "OUTPUT_SURFACE_ACTIVE"; |
| 48 case OUTPUT_SURFACE_LOST: | 51 case OUTPUT_SURFACE_LOST: |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 91 const char* SchedulerStateMachine::ActionToString(Action action) { | 94 const char* SchedulerStateMachine::ActionToString(Action action) { |
| 92 switch (action) { | 95 switch (action) { |
| 93 case ACTION_NONE: | 96 case ACTION_NONE: |
| 94 return "ACTION_NONE"; | 97 return "ACTION_NONE"; |
| 95 case ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD: | 98 case ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD: |
| 96 return "ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD"; | 99 return "ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD"; |
| 97 case ACTION_COMMIT: | 100 case ACTION_COMMIT: |
| 98 return "ACTION_COMMIT"; | 101 return "ACTION_COMMIT"; |
| 99 case ACTION_UPDATE_VISIBLE_TILES: | 102 case ACTION_UPDATE_VISIBLE_TILES: |
| 100 return "ACTION_UPDATE_VISIBLE_TILES"; | 103 return "ACTION_UPDATE_VISIBLE_TILES"; |
| 101 case ACTION_ACTIVATE_PENDING_TREE_IF_NEEDED: | 104 case ACTION_ACTIVATE_PENDING_TREE: |
| 102 return "ACTION_ACTIVATE_PENDING_TREE_IF_NEEDED"; | 105 return "ACTION_ACTIVATE_PENDING_TREE"; |
| 103 case ACTION_DRAW_IF_POSSIBLE: | 106 case ACTION_DRAW_IF_POSSIBLE: |
| 104 return "ACTION_DRAW_IF_POSSIBLE"; | 107 return "ACTION_DRAW_IF_POSSIBLE"; |
| 105 case ACTION_DRAW_FORCED: | 108 case ACTION_DRAW_FORCED: |
| 106 return "ACTION_DRAW_FORCED"; | 109 return "ACTION_DRAW_FORCED"; |
| 107 case ACTION_DRAW_AND_SWAP_ABORT: | 110 case ACTION_DRAW_AND_SWAP_ABORT: |
| 108 return "ACTION_DRAW_AND_SWAP_ABORT"; | 111 return "ACTION_DRAW_AND_SWAP_ABORT"; |
| 109 case ACTION_BEGIN_OUTPUT_SURFACE_CREATION: | 112 case ACTION_BEGIN_OUTPUT_SURFACE_CREATION: |
| 110 return "ACTION_BEGIN_OUTPUT_SURFACE_CREATION"; | 113 return "ACTION_BEGIN_OUTPUT_SURFACE_CREATION"; |
| 111 case ACTION_ACQUIRE_LAYER_TEXTURES_FOR_MAIN_THREAD: | 114 case ACTION_ACQUIRE_LAYER_TEXTURES_FOR_MAIN_THREAD: |
| 112 return "ACTION_ACQUIRE_LAYER_TEXTURES_FOR_MAIN_THREAD"; | 115 return "ACTION_ACQUIRE_LAYER_TEXTURES_FOR_MAIN_THREAD"; |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 155 state->Set("major_timestamps_in_ms", timestamps_state.release()); | 158 state->Set("major_timestamps_in_ms", timestamps_state.release()); |
| 156 | 159 |
| 157 scoped_ptr<base::DictionaryValue> minor_state(new base::DictionaryValue); | 160 scoped_ptr<base::DictionaryValue> minor_state(new base::DictionaryValue); |
| 158 minor_state->SetInteger("commit_count", commit_count_); | 161 minor_state->SetInteger("commit_count", commit_count_); |
| 159 minor_state->SetInteger("current_frame_number", current_frame_number_); | 162 minor_state->SetInteger("current_frame_number", current_frame_number_); |
| 160 minor_state->SetInteger( | 163 minor_state->SetInteger( |
| 161 "last_frame_number_where_begin_frame_sent_to_main_thread", | 164 "last_frame_number_where_begin_frame_sent_to_main_thread", |
| 162 last_frame_number_where_begin_frame_sent_to_main_thread_); | 165 last_frame_number_where_begin_frame_sent_to_main_thread_); |
| 163 minor_state->SetInteger("last_frame_number_where_draw_was_called", | 166 minor_state->SetInteger("last_frame_number_where_draw_was_called", |
| 164 last_frame_number_where_draw_was_called_); | 167 last_frame_number_where_draw_was_called_); |
| 165 minor_state->SetInteger("last_frame_number_where_tree_activation_attempted", | 168 minor_state->SetInteger("last_frame_number_pending_tree_activated_", |
| 166 last_frame_number_where_tree_activation_attempted_); | 169 last_frame_number_pending_tree_activated_); |
| 167 minor_state->SetInteger( | 170 minor_state->SetInteger( |
| 168 "last_frame_number_where_update_visible_tiles_was_called", | 171 "last_frame_number_where_update_visible_tiles_was_called", |
| 169 last_frame_number_where_update_visible_tiles_was_called_); | 172 last_frame_number_where_update_visible_tiles_was_called_); |
| 170 minor_state->SetInteger("consecutive_failed_draws", | 173 minor_state->SetInteger("consecutive_failed_draws", |
| 171 consecutive_failed_draws_); | 174 consecutive_failed_draws_); |
| 172 minor_state->SetInteger( | 175 minor_state->SetInteger( |
| 173 "maximum_number_of_failed_draws_before_draw_is_forced", | 176 "maximum_number_of_failed_draws_before_draw_is_forced", |
| 174 maximum_number_of_failed_draws_before_draw_is_forced_); | 177 maximum_number_of_failed_draws_before_draw_is_forced_); |
| 178 minor_state->SetBoolean("active_tree_has_been_drawn_", | |
| 179 active_tree_has_been_drawn_); | |
| 180 minor_state->SetBoolean("active_tree_is_null_", active_tree_is_null_); | |
| 175 minor_state->SetBoolean("needs_redraw", needs_redraw_); | 181 minor_state->SetBoolean("needs_redraw", needs_redraw_); |
| 176 minor_state->SetBoolean("swap_used_incomplete_tile", | 182 minor_state->SetBoolean("swap_used_incomplete_tile", |
| 177 swap_used_incomplete_tile_); | 183 swap_used_incomplete_tile_); |
| 178 minor_state->SetBoolean("needs_forced_redraw", needs_forced_redraw_); | 184 minor_state->SetBoolean("needs_forced_redraw", needs_forced_redraw_); |
| 179 minor_state->SetBoolean("needs_forced_redraw_after_next_commit", | 185 minor_state->SetBoolean("needs_forced_redraw_after_next_commit", |
| 180 needs_forced_redraw_after_next_commit_); | 186 needs_forced_redraw_after_next_commit_); |
| 181 minor_state->SetBoolean("needs_commit", needs_commit_); | 187 minor_state->SetBoolean("needs_commit", needs_commit_); |
| 182 minor_state->SetBoolean("needs_forced_commit", needs_forced_commit_); | 188 minor_state->SetBoolean("needs_forced_commit", needs_forced_commit_); |
| 183 minor_state->SetBoolean("expect_immediate_begin_frame_for_main_thread", | 189 minor_state->SetBoolean("expect_immediate_begin_frame_for_main_thread", |
| 184 expect_immediate_begin_frame_for_main_thread_); | 190 expect_immediate_begin_frame_for_main_thread_); |
| 185 minor_state->SetBoolean("main_thread_needs_layer_textures", | 191 minor_state->SetBoolean("main_thread_needs_layer_textures", |
| 186 main_thread_needs_layer_textures_); | 192 main_thread_needs_layer_textures_); |
| 187 minor_state->SetBoolean("inside_begin_frame", inside_begin_frame_); | 193 minor_state->SetBoolean("inside_begin_frame", inside_begin_frame_); |
| 188 minor_state->SetBoolean("visible", visible_); | 194 minor_state->SetBoolean("visible", visible_); |
| 189 minor_state->SetBoolean("can_start", can_start_); | 195 minor_state->SetBoolean("can_start", can_start_); |
| 190 minor_state->SetBoolean("can_draw", can_draw_); | 196 minor_state->SetBoolean("can_draw", can_draw_); |
| 191 minor_state->SetBoolean("has_pending_tree", has_pending_tree_); | 197 minor_state->SetBoolean("has_pending_tree", has_pending_tree_); |
| 198 minor_state->SetBoolean("pending_tree_is_ready_for_activation_", | |
| 199 pending_tree_is_ready_for_activation_); | |
| 192 minor_state->SetBoolean("draw_if_possible_failed", draw_if_possible_failed_); | 200 minor_state->SetBoolean("draw_if_possible_failed", draw_if_possible_failed_); |
| 193 minor_state->SetBoolean("did_create_and_initialize_first_output_surface", | 201 minor_state->SetBoolean("did_create_and_initialize_first_output_surface", |
| 194 did_create_and_initialize_first_output_surface_); | 202 did_create_and_initialize_first_output_surface_); |
| 195 state->Set("minor_state", minor_state.release()); | 203 state->Set("minor_state", minor_state.release()); |
| 196 | 204 |
| 197 return state.PassAs<base::Value>(); | 205 return state.PassAs<base::Value>(); |
| 198 } | 206 } |
| 199 | 207 |
| 200 bool SchedulerStateMachine::HasDrawnThisFrame() const { | 208 bool SchedulerStateMachine::HasDrawnThisFrame() const { |
| 201 return current_frame_number_ == last_frame_number_where_draw_was_called_; | 209 return current_frame_number_ == last_frame_number_where_draw_was_called_; |
| 202 } | 210 } |
| 203 | 211 |
| 204 bool SchedulerStateMachine::HasAttemptedTreeActivationThisFrame() const { | 212 bool SchedulerStateMachine::HasActivatedPendingTreeThisFrame() const { |
| 205 return current_frame_number_ == | 213 return current_frame_number_ == |
| 206 last_frame_number_where_tree_activation_attempted_; | 214 last_frame_number_pending_tree_activated_; |
| 207 } | 215 } |
| 208 | 216 |
| 209 bool SchedulerStateMachine::HasUpdatedVisibleTilesThisFrame() const { | 217 bool SchedulerStateMachine::HasUpdatedVisibleTilesThisFrame() const { |
| 210 return current_frame_number_ == | 218 return current_frame_number_ == |
| 211 last_frame_number_where_update_visible_tiles_was_called_; | 219 last_frame_number_where_update_visible_tiles_was_called_; |
| 212 } | 220 } |
| 213 | 221 |
| 214 bool SchedulerStateMachine::HasSentBeginFrameToMainThreadThisFrame() const { | 222 bool SchedulerStateMachine::HasSentBeginFrameToMainThreadThisFrame() const { |
| 215 return current_frame_number_ == | 223 return current_frame_number_ == |
| 216 last_frame_number_where_begin_frame_sent_to_main_thread_; | 224 last_frame_number_where_begin_frame_sent_to_main_thread_; |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 237 OUTPUT_SURFACE_WAITING_FOR_FIRST_ACTIVATION); | 245 OUTPUT_SURFACE_WAITING_FOR_FIRST_ACTIVATION); |
| 238 if (output_surface_state_ == OUTPUT_SURFACE_WAITING_FOR_FIRST_COMMIT) { | 246 if (output_surface_state_ == OUTPUT_SURFACE_WAITING_FOR_FIRST_COMMIT) { |
| 239 if (commit_results_in_pending_tree) { | 247 if (commit_results_in_pending_tree) { |
| 240 output_surface_state_ = OUTPUT_SURFACE_WAITING_FOR_FIRST_ACTIVATION; | 248 output_surface_state_ = OUTPUT_SURFACE_WAITING_FOR_FIRST_ACTIVATION; |
| 241 } else { | 249 } else { |
| 242 output_surface_state_ = OUTPUT_SURFACE_ACTIVE; | 250 output_surface_state_ = OUTPUT_SURFACE_ACTIVE; |
| 243 needs_redraw_ = true; | 251 needs_redraw_ = true; |
| 244 } | 252 } |
| 245 } | 253 } |
| 246 | 254 |
| 247 // if we don't have to wait for activation, update needs_redraw now. | 255 // Update state if we have a new active tree to draw. |
| 248 if (!commit_results_in_pending_tree) { | 256 if (!commit_results_in_pending_tree && |
| 249 if (!commit_was_aborted) | 257 (!commit_was_aborted || expect_immediate_begin_frame_for_main_thread_)) { |
| 250 needs_redraw_ = true; | 258 needs_redraw_ = true; |
| 251 if (expect_immediate_begin_frame_for_main_thread_) | 259 active_tree_has_been_drawn_ = false; |
| 252 needs_redraw_ = true; | |
| 253 } | 260 } |
| 254 | 261 |
| 255 // This post-commit work is common to both completed and aborted commits. | 262 // This post-commit work is common to both completed and aborted commits. |
| 256 if (draw_if_possible_failed_) | 263 if (draw_if_possible_failed_) |
| 257 last_frame_number_where_draw_was_called_ = -1; | 264 last_frame_number_where_draw_was_called_ = -1; |
| 258 | 265 |
| 259 if (needs_forced_redraw_after_next_commit_) { | 266 if (needs_forced_redraw_after_next_commit_) { |
| 260 needs_forced_redraw_after_next_commit_ = false; | 267 needs_forced_redraw_after_next_commit_ = false; |
| 261 needs_forced_redraw_ = true; | 268 needs_forced_redraw_ = true; |
| 262 } | 269 } |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 301 if (HasDrawnThisFrame()) | 308 if (HasDrawnThisFrame()) |
| 302 return false; | 309 return false; |
| 303 | 310 |
| 304 // We currently only draw within the BeginFrame. | 311 // We currently only draw within the BeginFrame. |
| 305 if (!inside_begin_frame_) | 312 if (!inside_begin_frame_) |
| 306 return false; | 313 return false; |
| 307 | 314 |
| 308 return needs_redraw_; | 315 return needs_redraw_; |
| 309 } | 316 } |
| 310 | 317 |
| 311 bool SchedulerStateMachine::ShouldAttemptTreeActivation() const { | 318 bool SchedulerStateMachine::ShouldActivatePendingTree() const { |
| 312 return has_pending_tree_ && inside_begin_frame_ && | 319 // Some quick early outs. |
| 313 !HasAttemptedTreeActivationThisFrame(); | 320 if (!inside_begin_frame_) |
| 321 return false; | |
| 322 if (!has_pending_tree_) | |
| 323 return false; | |
| 324 if (HasActivatedPendingTreeThisFrame()) | |
| 325 return false; | |
| 326 | |
| 327 if (!pending_tree_is_ready_for_activation_) | |
| 328 return false; | |
| 329 | |
| 330 // We do not want to activate a second tree before drawing the first one. | |
|
enne (OOO)
2013/08/23 17:54:09
Is this handled by the HasActivatedPendingTreeThis
brianderson
2013/08/23 20:51:59
There's some overlap, but there are cases where Ha
| |
| 331 return active_tree_has_been_drawn_ || active_tree_is_null_; | |
| 314 } | 332 } |
| 315 | 333 |
| 316 bool SchedulerStateMachine::ShouldUpdateVisibleTiles() const { | 334 bool SchedulerStateMachine::ShouldUpdateVisibleTiles() const { |
| 317 if (!settings_.impl_side_painting) | 335 if (!settings_.impl_side_painting) |
| 318 return false; | 336 return false; |
| 319 if (HasUpdatedVisibleTilesThisFrame()) | 337 if (HasUpdatedVisibleTilesThisFrame()) |
| 320 return false; | 338 return false; |
| 321 | 339 |
| 322 return ShouldAttemptTreeActivation() || ShouldDraw() || | 340 return ShouldActivatePendingTree() || ShouldDraw() || |
| 323 swap_used_incomplete_tile_; | 341 swap_used_incomplete_tile_; |
| 324 } | 342 } |
| 325 | 343 |
| 326 bool SchedulerStateMachine::ShouldSendBeginFrameToMainThread() const { | 344 bool SchedulerStateMachine::ShouldSendBeginFrameToMainThread() const { |
| 327 if (!needs_commit_) | 345 if (!needs_commit_) |
| 328 return false; | 346 return false; |
| 329 | 347 |
| 330 // Only send BeginFrame to the main thread when idle. | 348 // Only send BeginFrame to the main thread when idle. |
| 331 if (commit_state_ != COMMIT_STATE_IDLE) | 349 if (commit_state_ != COMMIT_STATE_IDLE) |
| 332 return false; | 350 return false; |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 381 needs_forced_commit_) | 399 needs_forced_commit_) |
| 382 // TODO(enne): Should probably drop the active tree on force commit. | 400 // TODO(enne): Should probably drop the active tree on force commit. |
| 383 return has_pending_tree_ ? ACTION_NONE | 401 return has_pending_tree_ ? ACTION_NONE |
| 384 : ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD; | 402 : ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD; |
| 385 if (output_surface_state_ == OUTPUT_SURFACE_LOST && can_start_) | 403 if (output_surface_state_ == OUTPUT_SURFACE_LOST && can_start_) |
| 386 return ACTION_BEGIN_OUTPUT_SURFACE_CREATION; | 404 return ACTION_BEGIN_OUTPUT_SURFACE_CREATION; |
| 387 if (output_surface_state_ == OUTPUT_SURFACE_CREATING) | 405 if (output_surface_state_ == OUTPUT_SURFACE_CREATING) |
| 388 return ACTION_NONE; | 406 return ACTION_NONE; |
| 389 if (ShouldUpdateVisibleTiles()) | 407 if (ShouldUpdateVisibleTiles()) |
| 390 return ACTION_UPDATE_VISIBLE_TILES; | 408 return ACTION_UPDATE_VISIBLE_TILES; |
| 391 if (ShouldAttemptTreeActivation()) | 409 if (ShouldActivatePendingTree()) |
| 392 return ACTION_ACTIVATE_PENDING_TREE_IF_NEEDED; | 410 return ACTION_ACTIVATE_PENDING_TREE; |
| 393 if (ShouldDraw()) { | 411 if (ShouldDraw()) { |
| 394 return needs_forced_redraw_ ? ACTION_DRAW_FORCED | 412 return needs_forced_redraw_ ? ACTION_DRAW_FORCED |
| 395 : ACTION_DRAW_IF_POSSIBLE; | 413 : ACTION_DRAW_IF_POSSIBLE; |
| 396 } | 414 } |
| 397 if (ShouldSendBeginFrameToMainThread()) | 415 if (ShouldSendBeginFrameToMainThread()) |
| 398 return ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD; | 416 return ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD; |
| 399 return ACTION_NONE; | 417 return ACTION_NONE; |
| 400 } | 418 } |
| 401 case COMMIT_STATE_FRAME_IN_PROGRESS: | 419 case COMMIT_STATE_FRAME_IN_PROGRESS: |
| 402 if (ShouldUpdateVisibleTiles()) | 420 if (ShouldUpdateVisibleTiles()) |
| 403 return ACTION_UPDATE_VISIBLE_TILES; | 421 return ACTION_UPDATE_VISIBLE_TILES; |
| 404 if (ShouldAttemptTreeActivation()) | 422 if (ShouldActivatePendingTree()) |
| 405 return ACTION_ACTIVATE_PENDING_TREE_IF_NEEDED; | 423 return ACTION_ACTIVATE_PENDING_TREE; |
| 406 if (ShouldDraw()) { | 424 if (ShouldDraw()) { |
| 407 return needs_forced_redraw_ ? ACTION_DRAW_FORCED | 425 return needs_forced_redraw_ ? ACTION_DRAW_FORCED |
| 408 : ACTION_DRAW_IF_POSSIBLE; | 426 : ACTION_DRAW_IF_POSSIBLE; |
| 409 } | 427 } |
| 410 return ACTION_NONE; | 428 return ACTION_NONE; |
| 411 | 429 |
| 412 case COMMIT_STATE_READY_TO_COMMIT: | 430 case COMMIT_STATE_READY_TO_COMMIT: |
| 413 return ACTION_COMMIT; | 431 return ACTION_COMMIT; |
| 414 | 432 |
| 415 case COMMIT_STATE_WAITING_FOR_FIRST_DRAW: { | 433 case COMMIT_STATE_WAITING_FOR_FIRST_DRAW: { |
| 416 if (ShouldUpdateVisibleTiles()) | 434 if (ShouldUpdateVisibleTiles()) |
| 417 return ACTION_UPDATE_VISIBLE_TILES; | 435 return ACTION_UPDATE_VISIBLE_TILES; |
| 418 if (ShouldAttemptTreeActivation()) | 436 if (ShouldActivatePendingTree()) |
| 419 return ACTION_ACTIVATE_PENDING_TREE_IF_NEEDED; | 437 return ACTION_ACTIVATE_PENDING_TREE; |
| 420 if (ShouldDraw()) { | 438 if (ShouldDraw()) { |
| 421 if (needs_forced_redraw_) | 439 if (needs_forced_redraw_) |
| 422 return ACTION_DRAW_FORCED; | 440 return ACTION_DRAW_FORCED; |
| 423 else if (PendingDrawsShouldBeAborted()) | 441 else if (PendingDrawsShouldBeAborted()) |
| 424 return ACTION_DRAW_AND_SWAP_ABORT; | 442 return ACTION_DRAW_AND_SWAP_ABORT; |
| 425 else | 443 else |
| 426 return ACTION_DRAW_IF_POSSIBLE; | 444 return ACTION_DRAW_IF_POSSIBLE; |
| 427 } | 445 } |
| 428 return ACTION_NONE; | 446 return ACTION_NONE; |
| 429 } | 447 } |
| 430 | 448 |
| 431 case COMMIT_STATE_WAITING_FOR_FIRST_FORCED_DRAW: | 449 case COMMIT_STATE_WAITING_FOR_FIRST_FORCED_DRAW: |
| 432 if (ShouldUpdateVisibleTiles()) | 450 if (ShouldUpdateVisibleTiles()) |
| 433 return ACTION_UPDATE_VISIBLE_TILES; | 451 return ACTION_UPDATE_VISIBLE_TILES; |
| 434 if (ShouldAttemptTreeActivation()) | 452 if (ShouldActivatePendingTree()) |
| 435 return ACTION_ACTIVATE_PENDING_TREE_IF_NEEDED; | 453 return ACTION_ACTIVATE_PENDING_TREE; |
| 436 if (needs_forced_redraw_) | 454 if (needs_forced_redraw_) |
| 437 return ACTION_DRAW_FORCED; | 455 return ACTION_DRAW_FORCED; |
| 438 return ACTION_NONE; | 456 return ACTION_NONE; |
| 439 } | 457 } |
| 440 NOTREACHED(); | 458 NOTREACHED(); |
| 441 return ACTION_NONE; | 459 return ACTION_NONE; |
| 442 } | 460 } |
| 443 | 461 |
| 444 void SchedulerStateMachine::UpdateState(Action action) { | 462 void SchedulerStateMachine::UpdateState(Action action) { |
| 445 switch (action) { | 463 switch (action) { |
| 446 case ACTION_NONE: | 464 case ACTION_NONE: |
| 447 return; | 465 return; |
| 448 | 466 |
| 449 case ACTION_UPDATE_VISIBLE_TILES: | 467 case ACTION_UPDATE_VISIBLE_TILES: |
| 450 last_frame_number_where_update_visible_tiles_was_called_ = | 468 last_frame_number_where_update_visible_tiles_was_called_ = |
| 451 current_frame_number_; | 469 current_frame_number_; |
| 452 return; | 470 return; |
| 453 | 471 |
| 454 case ACTION_ACTIVATE_PENDING_TREE_IF_NEEDED: | 472 case ACTION_ACTIVATE_PENDING_TREE: |
| 455 last_frame_number_where_tree_activation_attempted_ = | 473 last_frame_number_pending_tree_activated_ = current_frame_number_; |
| 456 current_frame_number_; | |
| 457 return; | 474 return; |
| 458 | 475 |
| 459 case ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD: | 476 case ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD: |
| 460 DCHECK(!has_pending_tree_); | 477 DCHECK(!has_pending_tree_); |
| 461 if (!needs_forced_commit_ && | 478 if (!needs_forced_commit_ && |
| 462 output_surface_state_ != OUTPUT_SURFACE_WAITING_FOR_FIRST_COMMIT) { | 479 output_surface_state_ != OUTPUT_SURFACE_WAITING_FOR_FIRST_COMMIT) { |
| 463 DCHECK(visible_); | 480 DCHECK(visible_); |
| 464 DCHECK_GT(current_frame_number_, | 481 DCHECK_GT(current_frame_number_, |
| 465 last_frame_number_where_begin_frame_sent_to_main_thread_); | 482 last_frame_number_where_begin_frame_sent_to_main_thread_); |
| 466 } | 483 } |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 512 expect_immediate_begin_frame_for_main_thread_ = false; | 529 expect_immediate_begin_frame_for_main_thread_ = false; |
| 513 } else if (commit_state_ == COMMIT_STATE_WAITING_FOR_FIRST_DRAW) { | 530 } else if (commit_state_ == COMMIT_STATE_WAITING_FOR_FIRST_DRAW) { |
| 514 commit_state_ = COMMIT_STATE_IDLE; | 531 commit_state_ = COMMIT_STATE_IDLE; |
| 515 } | 532 } |
| 516 if (texture_state_ == LAYER_TEXTURE_STATE_ACQUIRED_BY_IMPL_THREAD) | 533 if (texture_state_ == LAYER_TEXTURE_STATE_ACQUIRED_BY_IMPL_THREAD) |
| 517 texture_state_ = LAYER_TEXTURE_STATE_UNLOCKED; | 534 texture_state_ = LAYER_TEXTURE_STATE_UNLOCKED; |
| 518 | 535 |
| 519 needs_redraw_ = false; | 536 needs_redraw_ = false; |
| 520 needs_forced_redraw_ = false; | 537 needs_forced_redraw_ = false; |
| 521 draw_if_possible_failed_ = false; | 538 draw_if_possible_failed_ = false; |
| 539 active_tree_has_been_drawn_ = true; | |
| 522 | 540 |
| 523 if (did_swap) | 541 if (did_swap) |
| 524 swap_used_incomplete_tile_ = false; | 542 swap_used_incomplete_tile_ = false; |
| 525 } | 543 } |
| 526 | 544 |
| 527 void SchedulerStateMachine::SetMainThreadNeedsLayerTextures() { | 545 void SchedulerStateMachine::SetMainThreadNeedsLayerTextures() { |
| 528 DCHECK(!main_thread_needs_layer_textures_); | 546 DCHECK(!main_thread_needs_layer_textures_); |
| 529 DCHECK_NE(texture_state_, LAYER_TEXTURE_STATE_ACQUIRED_BY_MAIN_THREAD); | 547 DCHECK_NE(texture_state_, LAYER_TEXTURE_STATE_ACQUIRED_BY_MAIN_THREAD); |
| 530 main_thread_needs_layer_textures_ = true; | 548 main_thread_needs_layer_textures_ = true; |
| 531 } | 549 } |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 629 } | 647 } |
| 630 | 648 |
| 631 void SchedulerStateMachine::DidLoseOutputSurface() { | 649 void SchedulerStateMachine::DidLoseOutputSurface() { |
| 632 if (output_surface_state_ == OUTPUT_SURFACE_LOST || | 650 if (output_surface_state_ == OUTPUT_SURFACE_LOST || |
| 633 output_surface_state_ == OUTPUT_SURFACE_CREATING) | 651 output_surface_state_ == OUTPUT_SURFACE_CREATING) |
| 634 return; | 652 return; |
| 635 output_surface_state_ = OUTPUT_SURFACE_LOST; | 653 output_surface_state_ = OUTPUT_SURFACE_LOST; |
| 636 needs_redraw_ = false; | 654 needs_redraw_ = false; |
| 637 } | 655 } |
| 638 | 656 |
| 639 void SchedulerStateMachine::SetHasPendingTree(bool has_pending_tree) { | 657 void SchedulerStateMachine::NotifyReadyToActivate() { |
| 658 if (has_pending_tree_) | |
| 659 pending_tree_is_ready_for_activation_ = true; | |
| 660 } | |
| 661 | |
| 662 void SchedulerStateMachine::SetHasTrees(bool has_pending_tree, | |
| 663 bool active_tree_is_null) { | |
| 664 active_tree_is_null_ = active_tree_is_null; | |
| 640 if (has_pending_tree_ && !has_pending_tree) { | 665 if (has_pending_tree_ && !has_pending_tree) { |
| 641 // There is a new active tree. | 666 // There is a new active tree. |
| 667 pending_tree_is_ready_for_activation_ = false; | |
| 668 active_tree_has_been_drawn_ = false; | |
| 669 needs_redraw_ = true; | |
| 670 | |
| 642 if (output_surface_state_ == OUTPUT_SURFACE_WAITING_FOR_FIRST_ACTIVATION) | 671 if (output_surface_state_ == OUTPUT_SURFACE_WAITING_FOR_FIRST_ACTIVATION) |
| 643 output_surface_state_ = OUTPUT_SURFACE_ACTIVE; | 672 output_surface_state_ = OUTPUT_SURFACE_ACTIVE; |
| 644 | 673 } else if (!has_pending_tree_ && has_pending_tree) { |
| 645 needs_redraw_ = true; | 674 // There is a new pending tree. |
| 675 pending_tree_is_ready_for_activation_ = false; | |
| 646 } | 676 } |
| 647 has_pending_tree_ = has_pending_tree; | 677 has_pending_tree_ = has_pending_tree; |
| 648 } | 678 } |
| 649 | 679 |
| 650 void SchedulerStateMachine::SetCanDraw(bool can) { can_draw_ = can; } | 680 void SchedulerStateMachine::SetCanDraw(bool can) { can_draw_ = can; } |
| 651 | 681 |
| 652 void SchedulerStateMachine::DidCreateAndInitializeOutputSurface() { | 682 void SchedulerStateMachine::DidCreateAndInitializeOutputSurface() { |
| 653 DCHECK_EQ(output_surface_state_, OUTPUT_SURFACE_CREATING); | 683 DCHECK_EQ(output_surface_state_, OUTPUT_SURFACE_CREATING); |
| 654 output_surface_state_ = OUTPUT_SURFACE_WAITING_FOR_FIRST_COMMIT; | 684 output_surface_state_ = OUTPUT_SURFACE_WAITING_FOR_FIRST_COMMIT; |
| 655 | 685 |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 675 NOTREACHED(); | 705 NOTREACHED(); |
| 676 return false; | 706 return false; |
| 677 } | 707 } |
| 678 | 708 |
| 679 void SchedulerStateMachine::SetMaximumNumberOfFailedDrawsBeforeDrawIsForced( | 709 void SchedulerStateMachine::SetMaximumNumberOfFailedDrawsBeforeDrawIsForced( |
| 680 int num_draws) { | 710 int num_draws) { |
| 681 maximum_number_of_failed_draws_before_draw_is_forced_ = num_draws; | 711 maximum_number_of_failed_draws_before_draw_is_forced_ = num_draws; |
| 682 } | 712 } |
| 683 | 713 |
| 684 } // namespace cc | 714 } // namespace cc |
| OLD | NEW |