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 begin_frame_state_(BEGIN_FRAME_STATE_IDLE), | |
| 17 commit_state_(COMMIT_STATE_IDLE), | 18 commit_state_(COMMIT_STATE_IDLE), |
| 18 texture_state_(LAYER_TEXTURE_STATE_UNLOCKED), | 19 texture_state_(LAYER_TEXTURE_STATE_UNLOCKED), |
| 19 forced_redraw_state_(FORCED_REDRAW_STATE_IDLE), | 20 forced_redraw_state_(FORCED_REDRAW_STATE_IDLE), |
| 20 readback_state_(READBACK_STATE_IDLE), | 21 readback_state_(READBACK_STATE_IDLE), |
| 21 commit_count_(0), | 22 commit_count_(0), |
| 22 current_frame_number_(0), | 23 begin_frame_count_(0), |
| 23 last_frame_number_where_begin_frame_sent_to_main_thread_(-1), | 24 draw_attempt_count_(0), |
| 24 last_frame_number_swap_performed_(-1), | 25 last_begin_frame_count_swap_performed_(-1), |
| 25 last_frame_number_where_update_visible_tiles_was_called_(-1), | 26 last_draw_attempt_count_draw_was_called_(-1), |
| 27 last_begin_frame_count_begin_frame_sent_to_main_thread_(-1), | |
| 28 last_draw_attempt_count_tree_activation_attempted_(-1), | |
| 29 last_draw_attempt_count_update_visible_tiles_was_called_(-1), | |
| 26 consecutive_failed_draws_(0), | 30 consecutive_failed_draws_(0), |
| 27 needs_redraw_(false), | 31 needs_redraw_(false), |
| 28 swap_used_incomplete_tile_(false), | 32 swap_used_incomplete_tile_(false), |
| 29 needs_commit_(false), | 33 needs_commit_(false), |
| 30 main_thread_needs_layer_textures_(false), | 34 main_thread_needs_layer_textures_(false), |
| 31 inside_begin_frame_(false), | |
| 32 visible_(false), | 35 visible_(false), |
| 33 can_start_(false), | 36 can_start_(false), |
| 34 can_draw_(false), | 37 can_draw_(false), |
| 35 has_pending_tree_(false), | 38 has_pending_tree_(false), |
| 36 pending_tree_is_ready_for_activation_(false), | 39 pending_tree_is_ready_for_activation_(false), |
| 37 active_tree_needs_first_draw_(false), | 40 active_tree_needs_first_draw_(false), |
| 38 draw_if_possible_failed_(false), | 41 draw_if_possible_failed_(false), |
| 39 did_create_and_initialize_first_output_surface_(false) {} | 42 did_create_and_initialize_first_output_surface_(false) {} |
| 40 | 43 |
| 41 const char* SchedulerStateMachine::OutputSurfaceStateToString( | 44 const char* SchedulerStateMachine::OutputSurfaceStateToString( |
| 42 OutputSurfaceState state) { | 45 OutputSurfaceState state) { |
| 43 switch (state) { | 46 switch (state) { |
| 44 case OUTPUT_SURFACE_ACTIVE: | 47 case OUTPUT_SURFACE_ACTIVE: |
| 45 return "OUTPUT_SURFACE_ACTIVE"; | 48 return "OUTPUT_SURFACE_ACTIVE"; |
| 46 case OUTPUT_SURFACE_LOST: | 49 case OUTPUT_SURFACE_LOST: |
| 47 return "OUTPUT_SURFACE_LOST"; | 50 return "OUTPUT_SURFACE_LOST"; |
| 48 case OUTPUT_SURFACE_CREATING: | 51 case OUTPUT_SURFACE_CREATING: |
| 49 return "OUTPUT_SURFACE_CREATING"; | 52 return "OUTPUT_SURFACE_CREATING"; |
| 50 case OUTPUT_SURFACE_WAITING_FOR_FIRST_COMMIT: | 53 case OUTPUT_SURFACE_WAITING_FOR_FIRST_COMMIT: |
| 51 return "OUTPUT_SURFACE_WAITING_FOR_FIRST_COMMIT"; | 54 return "OUTPUT_SURFACE_WAITING_FOR_FIRST_COMMIT"; |
| 52 case OUTPUT_SURFACE_WAITING_FOR_FIRST_ACTIVATION: | 55 case OUTPUT_SURFACE_WAITING_FOR_FIRST_ACTIVATION: |
| 53 return "OUTPUT_SURFACE_WAITING_FOR_FIRST_ACTIVATION"; | 56 return "OUTPUT_SURFACE_WAITING_FOR_FIRST_ACTIVATION"; |
| 54 } | 57 } |
| 55 NOTREACHED(); | 58 NOTREACHED(); |
| 56 return "???"; | 59 return "???"; |
| 57 } | 60 } |
| 58 | 61 |
| 62 const char* SchedulerStateMachine::BeginFrameStateToString( | |
| 63 BeginFrameState state) { | |
| 64 switch (state) { | |
| 65 case BEGIN_FRAME_STATE_IDLE: | |
| 66 return "BEGIN_FRAME_STATE_IDLE"; | |
| 67 case BEGIN_FRAME_STATE_INSIDE_BEGIN_FRAME: | |
| 68 return "BEGIN_FRAME_STATE_INSIDE_BEGIN_FRAME"; | |
| 69 case BEGIN_FRAME_STATE_DEADLINE_PENDING: | |
| 70 return "BEGIN_FRAME_STATE_DEADLINE_PENDING"; | |
| 71 case BEGIN_FRAME_STATE_INSIDE_DEADLINE: | |
| 72 return "BEGIN_FRAME_STATE_INSIDE_DEADLINE"; | |
| 73 } | |
| 74 NOTREACHED(); | |
| 75 return "???"; | |
| 76 } | |
| 77 | |
| 59 const char* SchedulerStateMachine::CommitStateToString(CommitState state) { | 78 const char* SchedulerStateMachine::CommitStateToString(CommitState state) { |
| 60 switch (state) { | 79 switch (state) { |
| 61 case COMMIT_STATE_IDLE: | 80 case COMMIT_STATE_IDLE: |
| 62 return "COMMIT_STATE_IDLE"; | 81 return "COMMIT_STATE_IDLE"; |
| 63 case COMMIT_STATE_FRAME_IN_PROGRESS: | 82 case COMMIT_STATE_FRAME_IN_PROGRESS: |
| 64 return "COMMIT_STATE_FRAME_IN_PROGRESS"; | 83 return "COMMIT_STATE_FRAME_IN_PROGRESS"; |
| 65 case COMMIT_STATE_READY_TO_COMMIT: | 84 case COMMIT_STATE_READY_TO_COMMIT: |
| 66 return "COMMIT_STATE_READY_TO_COMMIT"; | 85 return "COMMIT_STATE_READY_TO_COMMIT"; |
| 67 case COMMIT_STATE_WAITING_FOR_FIRST_DRAW: | 86 case COMMIT_STATE_WAITING_FOR_FIRST_DRAW: |
| 68 return "COMMIT_STATE_WAITING_FOR_FIRST_DRAW"; | 87 return "COMMIT_STATE_WAITING_FOR_FIRST_DRAW"; |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 149 } | 168 } |
| 150 NOTREACHED(); | 169 NOTREACHED(); |
| 151 return "???"; | 170 return "???"; |
| 152 } | 171 } |
| 153 | 172 |
| 154 scoped_ptr<base::Value> SchedulerStateMachine::AsValue() const { | 173 scoped_ptr<base::Value> SchedulerStateMachine::AsValue() const { |
| 155 scoped_ptr<base::DictionaryValue> state(new base::DictionaryValue); | 174 scoped_ptr<base::DictionaryValue> state(new base::DictionaryValue); |
| 156 | 175 |
| 157 scoped_ptr<base::DictionaryValue> major_state(new base::DictionaryValue); | 176 scoped_ptr<base::DictionaryValue> major_state(new base::DictionaryValue); |
| 158 major_state->SetString("next_action", ActionToString(NextAction())); | 177 major_state->SetString("next_action", ActionToString(NextAction())); |
| 178 major_state->SetString("commit_state", | |
|
enne (OOO)
2013/09/10 03:35:44
begin_frame_state
brianderson
2013/09/10 21:16:56
Done.
| |
| 179 BeginFrameStateToString(begin_frame_state_)); | |
| 159 major_state->SetString("commit_state", CommitStateToString(commit_state_)); | 180 major_state->SetString("commit_state", CommitStateToString(commit_state_)); |
| 160 major_state->SetString("texture_state_", | 181 major_state->SetString("texture_state_", |
| 161 TextureStateToString(texture_state_)); | 182 TextureStateToString(texture_state_)); |
| 162 major_state->SetString("output_surface_state_", | 183 major_state->SetString("output_surface_state_", |
| 163 OutputSurfaceStateToString(output_surface_state_)); | 184 OutputSurfaceStateToString(output_surface_state_)); |
| 164 major_state->SetString( | 185 major_state->SetString( |
| 165 "forced_redraw_state", | 186 "forced_redraw_state", |
| 166 ForcedRedrawOnTimeoutStateToString(forced_redraw_state_)); | 187 ForcedRedrawOnTimeoutStateToString(forced_redraw_state_)); |
| 167 major_state->SetString("readback_state", | 188 major_state->SetString("readback_state", |
| 168 SynchronousReadbackStateToString(readback_state_)); | 189 SynchronousReadbackStateToString(readback_state_)); |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 190 (last_begin_frame_args_.frame_time - base::TimeTicks()).InMicroseconds() / | 211 (last_begin_frame_args_.frame_time - base::TimeTicks()).InMicroseconds() / |
| 191 1000.0L); | 212 1000.0L); |
| 192 timestamps_state->SetDouble( | 213 timestamps_state->SetDouble( |
| 193 "6_deadline", | 214 "6_deadline", |
| 194 (last_begin_frame_args_.deadline - base::TimeTicks()).InMicroseconds() / | 215 (last_begin_frame_args_.deadline - base::TimeTicks()).InMicroseconds() / |
| 195 1000.0L); | 216 1000.0L); |
| 196 state->Set("major_timestamps_in_ms", timestamps_state.release()); | 217 state->Set("major_timestamps_in_ms", timestamps_state.release()); |
| 197 | 218 |
| 198 scoped_ptr<base::DictionaryValue> minor_state(new base::DictionaryValue); | 219 scoped_ptr<base::DictionaryValue> minor_state(new base::DictionaryValue); |
| 199 minor_state->SetInteger("commit_count", commit_count_); | 220 minor_state->SetInteger("commit_count", commit_count_); |
| 200 minor_state->SetInteger("current_frame_number", current_frame_number_); | 221 minor_state->SetInteger("begin_frame_count_", begin_frame_count_); |
| 222 minor_state->SetInteger("draw_attempt_count_", draw_attempt_count_); | |
| 223 | |
| 224 minor_state->SetInteger("last_begin_frame_count_swap_performed_", | |
| 225 last_begin_frame_count_swap_performed_); | |
| 226 minor_state->SetInteger("last_draw_attempt_count_draw_was_called_", | |
| 227 last_draw_attempt_count_draw_was_called_); | |
| 201 minor_state->SetInteger( | 228 minor_state->SetInteger( |
| 202 "last_frame_number_where_begin_frame_sent_to_main_thread", | 229 "last_begin_frame_count_begin_frame_sent_to_main_thread_", |
| 203 last_frame_number_where_begin_frame_sent_to_main_thread_); | 230 last_begin_frame_count_begin_frame_sent_to_main_thread_); |
| 204 minor_state->SetInteger("last_frame_number_swap_performed_", | 231 minor_state->SetInteger("last_draw_attempt_count_tree_activation_attempted_", |
| 205 last_frame_number_swap_performed_); | 232 last_draw_attempt_count_tree_activation_attempted_); |
| 206 minor_state->SetInteger( | 233 minor_state->SetInteger( |
| 207 "last_frame_number_where_update_visible_tiles_was_called", | 234 "last_draw_attempt_count_update_visible_tiles_was_called_", |
| 208 last_frame_number_where_update_visible_tiles_was_called_); | 235 last_draw_attempt_count_update_visible_tiles_was_called_); |
| 209 minor_state->SetInteger("consecutive_failed_draws", | 236 |
| 237 minor_state->SetInteger("consecutive_failed_draws_", | |
| 210 consecutive_failed_draws_); | 238 consecutive_failed_draws_); |
| 211 minor_state->SetBoolean("needs_redraw", needs_redraw_); | 239 minor_state->SetBoolean("needs_redraw", needs_redraw_); |
| 212 minor_state->SetBoolean("swap_used_incomplete_tile", | 240 minor_state->SetBoolean("swap_used_incomplete_tile", |
| 213 swap_used_incomplete_tile_); | 241 swap_used_incomplete_tile_); |
| 214 minor_state->SetBoolean("needs_commit", needs_commit_); | 242 minor_state->SetBoolean("needs_commit", needs_commit_); |
| 215 minor_state->SetBoolean("main_thread_needs_layer_textures", | 243 minor_state->SetBoolean("main_thread_needs_layer_textures", |
| 216 main_thread_needs_layer_textures_); | 244 main_thread_needs_layer_textures_); |
| 217 minor_state->SetBoolean("inside_begin_frame", inside_begin_frame_); | |
| 218 minor_state->SetBoolean("visible", visible_); | 245 minor_state->SetBoolean("visible", visible_); |
| 219 minor_state->SetBoolean("can_start", can_start_); | 246 minor_state->SetBoolean("can_start", can_start_); |
| 220 minor_state->SetBoolean("can_draw", can_draw_); | 247 minor_state->SetBoolean("can_draw", can_draw_); |
| 221 minor_state->SetBoolean("has_pending_tree", has_pending_tree_); | 248 minor_state->SetBoolean("has_pending_tree", has_pending_tree_); |
| 222 minor_state->SetBoolean("pending_tree_is_ready_for_activation_", | 249 minor_state->SetBoolean("pending_tree_is_ready_for_activation_", |
| 223 pending_tree_is_ready_for_activation_); | 250 pending_tree_is_ready_for_activation_); |
| 224 minor_state->SetBoolean("active_tree_needs_first_draw_", | 251 minor_state->SetBoolean("active_tree_needs_first_draw_", |
| 225 active_tree_needs_first_draw_); | 252 active_tree_needs_first_draw_); |
| 226 minor_state->SetBoolean("draw_if_possible_failed", draw_if_possible_failed_); | 253 minor_state->SetBoolean("draw_if_possible_failed", draw_if_possible_failed_); |
| 227 minor_state->SetBoolean("did_create_and_initialize_first_output_surface", | 254 minor_state->SetBoolean("did_create_and_initialize_first_output_surface", |
| 228 did_create_and_initialize_first_output_surface_); | 255 did_create_and_initialize_first_output_surface_); |
| 229 state->Set("minor_state", minor_state.release()); | 256 state->Set("minor_state", minor_state.release()); |
| 230 | 257 |
| 231 return state.PassAs<base::Value>(); | 258 return state.PassAs<base::Value>(); |
| 232 } | 259 } |
| 233 | 260 |
| 234 bool SchedulerStateMachine::HasDrawnAndSwappedThisFrame() const { | 261 bool SchedulerStateMachine::HasSwappedThisFrame() const { |
| 235 return current_frame_number_ == last_frame_number_swap_performed_; | 262 return begin_frame_count_ == last_begin_frame_count_swap_performed_; |
| 236 } | 263 } |
| 237 | 264 |
| 238 bool SchedulerStateMachine::HasUpdatedVisibleTilesThisFrame() const { | 265 bool SchedulerStateMachine::HasDrawnThisDrawAttempt() const { |
| 239 return current_frame_number_ == | 266 return draw_attempt_count_ == last_draw_attempt_count_draw_was_called_; |
| 240 last_frame_number_where_update_visible_tiles_was_called_; | |
| 241 } | 267 } |
| 242 | 268 |
| 243 bool SchedulerStateMachine::HasSentBeginFrameToMainThreadThisFrame() const { | 269 bool SchedulerStateMachine::HasSentBeginFrameToMainThreadThisFrame() const { |
| 244 return current_frame_number_ == | 270 return begin_frame_count_ == |
| 245 last_frame_number_where_begin_frame_sent_to_main_thread_; | 271 last_begin_frame_count_begin_frame_sent_to_main_thread_; |
| 272 } | |
| 273 | |
| 274 bool SchedulerStateMachine::HasUpdatedVisibleTilesThisDrawAttempt() const { | |
| 275 return draw_attempt_count_ == | |
| 276 last_draw_attempt_count_update_visible_tiles_was_called_; | |
| 277 } | |
| 278 | |
| 279 bool SchedulerStateMachine::HasActivatedPendingTreeThisDrawAttempt() const { | |
| 280 return draw_attempt_count_ == | |
| 281 last_draw_attempt_count_tree_activation_attempted_; | |
| 246 } | 282 } |
| 247 | 283 |
| 248 bool SchedulerStateMachine::PendingDrawsShouldBeAborted() const { | 284 bool SchedulerStateMachine::PendingDrawsShouldBeAborted() const { |
| 249 // These are all the cases where we normally cannot or do not want to draw | 285 // These are all the cases where we normally cannot or do not want to draw |
| 250 // but, if needs_redraw_ is true and we do not draw to make forward progress, | 286 // but, if needs_redraw_ is true and we do not draw to make forward progress, |
| 251 // we might deadlock with the main thread. | 287 // we might deadlock with the main thread. |
| 252 // This should be a superset of PendingActivationsShouldBeForced() since | 288 // This should be a superset of PendingActivationsShouldBeForced() since |
| 253 // activation of the pending tree is blocked by drawing of the active tree and | 289 // activation of the pending tree is blocked by drawing of the active tree and |
| 254 // the main thread might be blocked on activation of the most recent commit. | 290 // the main thread might be blocked on activation of the most recent commit. |
| 255 if (PendingActivationsShouldBeForced()) | 291 if (PendingActivationsShouldBeForced()) |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 298 // readback. | 334 // readback. |
| 299 if (active_tree_needs_first_draw_ || has_pending_tree_) | 335 if (active_tree_needs_first_draw_ || has_pending_tree_) |
| 300 return false; | 336 return false; |
| 301 | 337 |
| 302 // We need to create the output surface if we don't have one and we haven't | 338 // We need to create the output surface if we don't have one and we haven't |
| 303 // started creating one yet. | 339 // started creating one yet. |
| 304 return output_surface_state_ == OUTPUT_SURFACE_LOST; | 340 return output_surface_state_ == OUTPUT_SURFACE_LOST; |
| 305 } | 341 } |
| 306 | 342 |
| 307 bool SchedulerStateMachine::ShouldDraw() const { | 343 bool SchedulerStateMachine::ShouldDraw() const { |
| 344 if (HasDrawnThisDrawAttempt()) | |
| 345 return false; | |
| 346 | |
| 308 // After a readback, make sure not to draw again until we've replaced the | 347 // After a readback, make sure not to draw again until we've replaced the |
| 309 // readback commit with a real one. | 348 // readback commit with a real one. |
| 310 if (readback_state_ == READBACK_STATE_WAITING_FOR_REPLACEMENT_COMMIT || | 349 if (readback_state_ == READBACK_STATE_WAITING_FOR_REPLACEMENT_COMMIT || |
| 311 readback_state_ == READBACK_STATE_WAITING_FOR_REPLACEMENT_ACTIVATION) | 350 readback_state_ == READBACK_STATE_WAITING_FOR_REPLACEMENT_ACTIVATION) |
| 312 return false; | 351 return false; |
| 313 | 352 |
| 314 // Draw immediately for readbacks to unblock the main thread quickly. | 353 // Draw immediately for readbacks to unblock the main thread quickly. |
| 315 if (readback_state_ == READBACK_STATE_WAITING_FOR_DRAW_AND_READBACK) { | 354 if (readback_state_ == READBACK_STATE_WAITING_FOR_DRAW_AND_READBACK) { |
| 316 DCHECK_EQ(commit_state_, COMMIT_STATE_WAITING_FOR_FIRST_DRAW); | 355 DCHECK_EQ(commit_state_, COMMIT_STATE_WAITING_FOR_FIRST_DRAW); |
| 317 return true; | 356 return true; |
| 318 } | 357 } |
| 319 | 358 |
| 320 // If we need to abort draws, we should do so ASAP since the draw could | 359 // If we need to abort draws, we should do so ASAP since the draw could |
| 321 // be blocking other important actions (like output surface initialization), | 360 // be blocking other important actions (like output surface initialization), |
| 322 // from occuring. If we are waiting for the first draw, then perfom the | 361 // from occuring. If we are waiting for the first draw, then perfom the |
| 323 // aborted draw to keep things moving. If we are not waiting for the first | 362 // aborted draw to keep things moving. If we are not waiting for the first |
| 324 // draw however, we don't want to abort for no reason. | 363 // draw however, we don't want to abort for no reason. |
| 325 if (PendingDrawsShouldBeAborted()) | 364 if (PendingDrawsShouldBeAborted()) |
| 326 return active_tree_needs_first_draw_; | 365 return active_tree_needs_first_draw_; |
| 327 | 366 |
| 328 // After this line, we only want to draw once per frame. | 367 // After this line, we only want to swap once per frame. |
| 329 if (HasDrawnAndSwappedThisFrame()) | 368 if (HasSwappedThisFrame()) |
| 330 return false; | 369 return false; |
| 331 | 370 |
| 332 // We currently only draw within the BeginFrame. | 371 // Except for the cases above, do not draw outside of the BeginFrame deadline. |
| 333 if (!inside_begin_frame_) | 372 if (begin_frame_state_ != BEGIN_FRAME_STATE_INSIDE_DEADLINE) |
| 334 return false; | 373 return false; |
| 335 | 374 |
| 336 // Only handle forced redraws due to timeouts on the regular deadline. | 375 // Only handle forced redraws due to timeouts on the regular deadline. |
| 337 if (forced_redraw_state_ == FORCED_REDRAW_STATE_WAITING_FOR_DRAW) { | 376 if (forced_redraw_state_ == FORCED_REDRAW_STATE_WAITING_FOR_DRAW) { |
| 338 DCHECK_EQ(commit_state_, COMMIT_STATE_WAITING_FOR_FIRST_DRAW); | 377 DCHECK_EQ(commit_state_, COMMIT_STATE_WAITING_FOR_FIRST_DRAW); |
| 339 return true; | 378 return true; |
| 340 } | 379 } |
| 341 | 380 |
| 342 return needs_redraw_; | 381 return needs_redraw_; |
| 343 } | 382 } |
| 344 | 383 |
| 345 bool SchedulerStateMachine::ShouldAcquireLayerTexturesForMainThread() const { | 384 bool SchedulerStateMachine::ShouldAcquireLayerTexturesForMainThread() const { |
| 346 if (!main_thread_needs_layer_textures_) | 385 if (!main_thread_needs_layer_textures_) |
| 347 return false; | 386 return false; |
| 348 if (texture_state_ == LAYER_TEXTURE_STATE_UNLOCKED) | 387 if (texture_state_ == LAYER_TEXTURE_STATE_UNLOCKED) |
| 349 return true; | 388 return true; |
| 350 DCHECK_EQ(texture_state_, LAYER_TEXTURE_STATE_ACQUIRED_BY_IMPL_THREAD); | 389 DCHECK_EQ(texture_state_, LAYER_TEXTURE_STATE_ACQUIRED_BY_IMPL_THREAD); |
| 351 return false; | 390 return false; |
| 352 } | 391 } |
| 353 | 392 |
| 354 bool SchedulerStateMachine::ShouldActivatePendingTree() const { | 393 bool SchedulerStateMachine::ShouldActivatePendingTree() const { |
| 355 // There is nothing to activate. | 394 // There is nothing to activate. |
| 356 if (!has_pending_tree_) | 395 if (!has_pending_tree_) |
| 357 return false; | 396 return false; |
| 397 if (HasActivatedPendingTreeThisDrawAttempt()) | |
| 398 return false; | |
| 358 | 399 |
| 359 // We should not activate a second tree before drawing the first one. | 400 // We should not activate a second tree before drawing the first one. |
| 360 // Even if we need to force activation of the pending tree, we should abort | 401 // Even if we need to force activation of the pending tree, we should abort |
| 361 // drawing the active tree first. | 402 // drawing the active tree first. |
| 362 if (active_tree_needs_first_draw_) | 403 if (active_tree_needs_first_draw_) |
| 363 return false; | 404 return false; |
| 364 | 405 |
| 365 // If we want to force activation, do so ASAP. | 406 // If we want to force activation, do so ASAP. |
| 366 if (PendingActivationsShouldBeForced()) | 407 if (PendingActivationsShouldBeForced()) |
| 367 return true; | 408 return true; |
| 368 | 409 |
| 369 // At this point, only activate if we are ready to activate. | 410 // At this point, only activate if we are ready to activate. |
| 370 return pending_tree_is_ready_for_activation_; | 411 return pending_tree_is_ready_for_activation_; |
| 371 } | 412 } |
| 372 | 413 |
| 373 bool SchedulerStateMachine::ShouldUpdateVisibleTiles() const { | 414 bool SchedulerStateMachine::ShouldUpdateVisibleTiles() const { |
| 374 if (!settings_.impl_side_painting) | 415 if (!settings_.impl_side_painting) |
| 375 return false; | 416 return false; |
| 376 if (HasUpdatedVisibleTilesThisFrame()) | 417 if (HasUpdatedVisibleTilesThisDrawAttempt()) |
| 377 return false; | 418 return false; |
| 378 | 419 |
| 379 // There's no reason to check for tiles if we don't have an output surface. | 420 // There's no reason to check for tiles if we don't have an output surface. |
| 380 if (!HasInitializedOutputSurface()) | 421 if (!HasInitializedOutputSurface()) |
| 381 return false; | 422 return false; |
| 382 | 423 |
| 383 // We always want to update the most recent visible tiles before drawing | 424 // We always want to update the most recent visible tiles before drawing |
| 384 // so we draw with fewer missing tiles. | 425 // so we draw with fewer missing tiles. |
| 385 if (ShouldDraw()) | 426 if (ShouldDraw()) |
| 386 return true; | 427 return true; |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 407 return false; | 448 return false; |
| 408 | 449 |
| 409 // We want to handle readback commits immediately to unblock the main thread. | 450 // We want to handle readback commits immediately to unblock the main thread. |
| 410 // Note: This BeginFrame will correspond to the replacement commit that comes | 451 // Note: This BeginFrame will correspond to the replacement commit that comes |
| 411 // after the readback commit itself, so we only send the BeginFrame if a | 452 // after the readback commit itself, so we only send the BeginFrame if a |
| 412 // commit isn't already pending behind the readback. | 453 // commit isn't already pending behind the readback. |
| 413 if (readback_state_ == READBACK_STATE_NEEDS_BEGIN_FRAME) | 454 if (readback_state_ == READBACK_STATE_NEEDS_BEGIN_FRAME) |
| 414 return !CommitPending(); | 455 return !CommitPending(); |
| 415 | 456 |
| 416 // We do not need commits if we are not visible, unless there's a | 457 // We do not need commits if we are not visible, unless there's a |
| 417 // request for a forced commit. | 458 // request for a readback. |
| 418 if (!visible_) | 459 if (!visible_) |
| 419 return false; | 460 return false; |
| 420 | 461 |
| 462 // We shouldn't normally accept commits if there isn't an OutputSurface. | |
| 463 if (!HasInitializedOutputSurface()) | |
| 464 return false; | |
| 465 | |
| 421 // We want to start the first commit after we get a new output surface ASAP. | 466 // We want to start the first commit after we get a new output surface ASAP. |
| 422 if (output_surface_state_ == OUTPUT_SURFACE_WAITING_FOR_FIRST_COMMIT) | 467 if (output_surface_state_ == OUTPUT_SURFACE_WAITING_FOR_FIRST_COMMIT) |
| 423 return true; | 468 return true; |
| 424 | 469 |
| 470 // We usually want to slave the main thread's BeginFrame to the impl thread's | |
| 471 // BeginFrame. However, if we aren't expecting a BeginFrame on the impl | |
| 472 // thread, we should send a BeginFrame to the main thread anyway to make | |
| 473 // progress. | |
| 474 // TODO(brianderson): Also allow sending BeginFrame to main thread while idle | |
| 475 // when the main thread isn't consuming user input. | |
| 476 if (begin_frame_state_ == BEGIN_FRAME_STATE_IDLE && | |
| 477 BeginFrameNeededByImplThread()) | |
| 478 return false; | |
|
enne (OOO)
2013/09/10 03:35:44
Can you rephrase this comment to refer to this "re
brianderson
2013/09/10 21:16:56
I will change the comment to refer to the "return
| |
| 479 | |
| 425 // We need a new commit for the forced redraw. This honors the | 480 // We need a new commit for the forced redraw. This honors the |
| 426 // single commit per interval because the result will be swapped to screen. | 481 // single commit per interval because the result will be swapped to screen. |
| 427 if (forced_redraw_state_ == FORCED_REDRAW_STATE_WAITING_FOR_COMMIT) | 482 if (forced_redraw_state_ == FORCED_REDRAW_STATE_WAITING_FOR_COMMIT) |
| 428 return true; | 483 return true; |
| 429 | 484 |
| 430 // After this point, we only start a commit once per frame. | 485 // After this point, we only start a commit once per frame. |
| 431 if (HasSentBeginFrameToMainThreadThisFrame()) | 486 if (HasSentBeginFrameToMainThreadThisFrame()) |
| 432 return false; | 487 return false; |
| 433 | 488 |
| 434 // We shouldn't normally accept commits if there isn't an OutputSurface. | |
| 435 if (!HasInitializedOutputSurface()) | |
| 436 return false; | |
| 437 | |
| 438 return true; | 489 return true; |
| 439 } | 490 } |
| 440 | 491 |
| 441 bool SchedulerStateMachine::ShouldCommit() const { | 492 bool SchedulerStateMachine::ShouldCommit() const { |
| 442 return commit_state_ == COMMIT_STATE_READY_TO_COMMIT; | 493 return commit_state_ == COMMIT_STATE_READY_TO_COMMIT; |
| 443 } | 494 } |
| 444 | 495 |
| 445 SchedulerStateMachine::Action SchedulerStateMachine::NextAction() const { | 496 SchedulerStateMachine::Action SchedulerStateMachine::NextAction() const { |
| 446 if (ShouldAcquireLayerTexturesForMainThread()) | 497 if (ShouldAcquireLayerTexturesForMainThread()) |
| 447 return ACTION_ACQUIRE_LAYER_TEXTURES_FOR_MAIN_THREAD; | 498 return ACTION_ACQUIRE_LAYER_TEXTURES_FOR_MAIN_THREAD; |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 474 DCHECK(!(forced_redraw_state_ == FORCED_REDRAW_STATE_WAITING_FOR_DRAW && | 525 DCHECK(!(forced_redraw_state_ == FORCED_REDRAW_STATE_WAITING_FOR_DRAW && |
| 475 readback_state_ == READBACK_STATE_WAITING_FOR_DRAW_AND_READBACK)); | 526 readback_state_ == READBACK_STATE_WAITING_FOR_DRAW_AND_READBACK)); |
| 476 } | 527 } |
| 477 | 528 |
| 478 void SchedulerStateMachine::UpdateState(Action action) { | 529 void SchedulerStateMachine::UpdateState(Action action) { |
| 479 switch (action) { | 530 switch (action) { |
| 480 case ACTION_NONE: | 531 case ACTION_NONE: |
| 481 return; | 532 return; |
| 482 | 533 |
| 483 case ACTION_UPDATE_VISIBLE_TILES: | 534 case ACTION_UPDATE_VISIBLE_TILES: |
| 484 last_frame_number_where_update_visible_tiles_was_called_ = | 535 last_draw_attempt_count_update_visible_tiles_was_called_ = |
| 485 current_frame_number_; | 536 draw_attempt_count_; |
| 486 return; | 537 return; |
| 487 | 538 |
| 488 case ACTION_ACTIVATE_PENDING_TREE: | 539 case ACTION_ACTIVATE_PENDING_TREE: |
| 489 UpdateStateOnActivation(); | 540 UpdateStateOnActivation(); |
| 490 return; | 541 return; |
| 491 | 542 |
| 492 case ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD: | 543 case ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD: |
| 493 DCHECK(!has_pending_tree_); | 544 DCHECK(!has_pending_tree_); |
| 494 DCHECK(visible_ || readback_state_ == READBACK_STATE_NEEDS_BEGIN_FRAME); | 545 DCHECK(visible_ || readback_state_ == READBACK_STATE_NEEDS_BEGIN_FRAME); |
| 495 commit_state_ = COMMIT_STATE_FRAME_IN_PROGRESS; | 546 commit_state_ = COMMIT_STATE_FRAME_IN_PROGRESS; |
| 496 needs_commit_ = false; | 547 needs_commit_ = false; |
| 497 if (readback_state_ == READBACK_STATE_NEEDS_BEGIN_FRAME) | 548 if (readback_state_ == READBACK_STATE_NEEDS_BEGIN_FRAME) |
| 498 readback_state_ = READBACK_STATE_WAITING_FOR_COMMIT; | 549 readback_state_ = READBACK_STATE_WAITING_FOR_COMMIT; |
| 499 last_frame_number_where_begin_frame_sent_to_main_thread_ = | 550 last_begin_frame_count_begin_frame_sent_to_main_thread_ = |
| 500 current_frame_number_; | 551 begin_frame_count_; |
| 501 return; | 552 return; |
| 502 | 553 |
| 503 case ACTION_COMMIT: { | 554 case ACTION_COMMIT: { |
| 504 bool commit_was_aborted = false; | 555 bool commit_was_aborted = false; |
| 505 UpdateStateOnCommit(commit_was_aborted); | 556 UpdateStateOnCommit(commit_was_aborted); |
| 506 return; | 557 return; |
| 507 } | 558 } |
| 508 | 559 |
| 509 case ACTION_DRAW_AND_SWAP_FORCED: | 560 case ACTION_DRAW_AND_SWAP_FORCED: |
| 510 case ACTION_DRAW_AND_SWAP_IF_POSSIBLE: { | 561 case ACTION_DRAW_AND_SWAP_IF_POSSIBLE: { |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 534 | 585 |
| 535 case ACTION_ACQUIRE_LAYER_TEXTURES_FOR_MAIN_THREAD: | 586 case ACTION_ACQUIRE_LAYER_TEXTURES_FOR_MAIN_THREAD: |
| 536 texture_state_ = LAYER_TEXTURE_STATE_ACQUIRED_BY_MAIN_THREAD; | 587 texture_state_ = LAYER_TEXTURE_STATE_ACQUIRED_BY_MAIN_THREAD; |
| 537 main_thread_needs_layer_textures_ = false; | 588 main_thread_needs_layer_textures_ = false; |
| 538 return; | 589 return; |
| 539 } | 590 } |
| 540 } | 591 } |
| 541 | 592 |
| 542 void SchedulerStateMachine::UpdateStateOnCommit(bool commit_was_aborted) { | 593 void SchedulerStateMachine::UpdateStateOnCommit(bool commit_was_aborted) { |
| 543 commit_count_++; | 594 commit_count_++; |
| 595 draw_attempt_count_++; | |
|
enne (OOO)
2013/09/10 03:35:44
What's the difference between "draw attempt" and "
brianderson
2013/09/10 21:16:56
Note: It is possible for a readback and a swap to
| |
| 544 | 596 |
| 545 // If we are impl-side-painting but the commit was aborted, then we behave | 597 // If we are impl-side-painting but the commit was aborted, then we behave |
| 546 // mostly as if we are not impl-side-painting since there is no pending tree. | 598 // mostly as if we are not impl-side-painting since there is no pending tree. |
| 547 has_pending_tree_ = settings_.impl_side_painting && !commit_was_aborted; | 599 has_pending_tree_ = settings_.impl_side_painting && !commit_was_aborted; |
| 548 | 600 |
| 549 // Update state related to readbacks. | 601 // Update state related to readbacks. |
| 550 if (readback_state_ == READBACK_STATE_WAITING_FOR_COMMIT) { | 602 if (readback_state_ == READBACK_STATE_WAITING_FOR_COMMIT) { |
| 551 // Update the state if this is the readback commit. | 603 // Update the state if this is the readback commit. |
| 552 readback_state_ = has_pending_tree_ | 604 readback_state_ = has_pending_tree_ |
| 553 ? READBACK_STATE_WAITING_FOR_ACTIVATION | 605 ? READBACK_STATE_WAITING_FOR_ACTIVATION |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 603 (!commit_was_aborted || | 655 (!commit_was_aborted || |
| 604 readback_state_ == READBACK_STATE_WAITING_FOR_DRAW_AND_READBACK || | 656 readback_state_ == READBACK_STATE_WAITING_FOR_DRAW_AND_READBACK || |
| 605 forced_redraw_state_ == FORCED_REDRAW_STATE_WAITING_FOR_DRAW)) { | 657 forced_redraw_state_ == FORCED_REDRAW_STATE_WAITING_FOR_DRAW)) { |
| 606 needs_redraw_ = true; | 658 needs_redraw_ = true; |
| 607 active_tree_needs_first_draw_ = true; | 659 active_tree_needs_first_draw_ = true; |
| 608 } | 660 } |
| 609 | 661 |
| 610 // This post-commit work is common to both completed and aborted commits. | 662 // This post-commit work is common to both completed and aborted commits. |
| 611 pending_tree_is_ready_for_activation_ = false; | 663 pending_tree_is_ready_for_activation_ = false; |
| 612 | 664 |
| 613 if (draw_if_possible_failed_) | 665 if (draw_if_possible_failed_) { |
| 614 last_frame_number_swap_performed_ = -1; | 666 last_begin_frame_count_swap_performed_ = -1; |
| 667 last_draw_attempt_count_draw_was_called_ = -1; | |
| 668 } | |
| 615 | 669 |
| 616 // If we are planing to draw with the new commit, lock the layer textures for | 670 // If we are planing to draw with the new commit, lock the layer textures for |
| 617 // use on the impl thread. Otherwise, leave them unlocked. | 671 // use on the impl thread. Otherwise, leave them unlocked. |
| 618 if (has_pending_tree_ || needs_redraw_) | 672 if (has_pending_tree_ || needs_redraw_) |
| 619 texture_state_ = LAYER_TEXTURE_STATE_ACQUIRED_BY_IMPL_THREAD; | 673 texture_state_ = LAYER_TEXTURE_STATE_ACQUIRED_BY_IMPL_THREAD; |
| 620 else | 674 else |
| 621 texture_state_ = LAYER_TEXTURE_STATE_UNLOCKED; | 675 texture_state_ = LAYER_TEXTURE_STATE_UNLOCKED; |
| 622 } | 676 } |
| 623 | 677 |
| 624 void SchedulerStateMachine::UpdateStateOnActivation() { | 678 void SchedulerStateMachine::UpdateStateOnActivation() { |
| 679 draw_attempt_count_++; | |
| 680 | |
| 625 // Update output surface state. | 681 // Update output surface state. |
| 626 if (output_surface_state_ == OUTPUT_SURFACE_WAITING_FOR_FIRST_ACTIVATION) | 682 if (output_surface_state_ == OUTPUT_SURFACE_WAITING_FOR_FIRST_ACTIVATION) |
| 627 output_surface_state_ = OUTPUT_SURFACE_ACTIVE; | 683 output_surface_state_ = OUTPUT_SURFACE_ACTIVE; |
| 628 | 684 |
| 629 // Update readback state | 685 // Update readback state |
| 630 if (forced_redraw_state_ == FORCED_REDRAW_STATE_WAITING_FOR_ACTIVATION) | 686 if (forced_redraw_state_ == FORCED_REDRAW_STATE_WAITING_FOR_ACTIVATION) |
| 631 forced_redraw_state_ = FORCED_REDRAW_STATE_WAITING_FOR_DRAW; | 687 forced_redraw_state_ = FORCED_REDRAW_STATE_WAITING_FOR_DRAW; |
| 632 | 688 |
| 633 // Update forced redraw state | 689 // Update forced redraw state |
| 634 if (readback_state_ == READBACK_STATE_WAITING_FOR_ACTIVATION) | 690 if (readback_state_ == READBACK_STATE_WAITING_FOR_ACTIVATION) |
| 635 readback_state_ = READBACK_STATE_WAITING_FOR_DRAW_AND_READBACK; | 691 readback_state_ = READBACK_STATE_WAITING_FOR_DRAW_AND_READBACK; |
| 636 else if (readback_state_ == READBACK_STATE_WAITING_FOR_REPLACEMENT_ACTIVATION) | 692 else if (readback_state_ == READBACK_STATE_WAITING_FOR_REPLACEMENT_ACTIVATION) |
| 637 readback_state_ = READBACK_STATE_IDLE; | 693 readback_state_ = READBACK_STATE_IDLE; |
| 638 | 694 |
| 639 has_pending_tree_ = false; | 695 has_pending_tree_ = false; |
| 640 pending_tree_is_ready_for_activation_ = false; | 696 pending_tree_is_ready_for_activation_ = false; |
| 641 active_tree_needs_first_draw_ = true; | 697 active_tree_needs_first_draw_ = true; |
| 642 needs_redraw_ = true; | 698 needs_redraw_ = true; |
| 699 last_draw_attempt_count_tree_activation_attempted_ = draw_attempt_count_; | |
| 643 } | 700 } |
| 644 | 701 |
| 645 void SchedulerStateMachine::UpdateStateOnDraw(bool did_swap) { | 702 void SchedulerStateMachine::UpdateStateOnDraw(bool did_swap) { |
| 646 DCHECK(readback_state_ != READBACK_STATE_WAITING_FOR_REPLACEMENT_COMMIT && | 703 DCHECK(readback_state_ != READBACK_STATE_WAITING_FOR_REPLACEMENT_COMMIT && |
| 647 readback_state_ != READBACK_STATE_WAITING_FOR_REPLACEMENT_ACTIVATION) | 704 readback_state_ != READBACK_STATE_WAITING_FOR_REPLACEMENT_ACTIVATION) |
| 648 << *AsValue(); | 705 << *AsValue(); |
| 649 | 706 |
| 650 if (readback_state_ == READBACK_STATE_WAITING_FOR_DRAW_AND_READBACK) { | 707 if (readback_state_ == READBACK_STATE_WAITING_FOR_DRAW_AND_READBACK) { |
| 651 // The draw correspons to a readback commit. | 708 // The draw correspons to a readback commit. |
| 652 DCHECK_EQ(commit_state_, COMMIT_STATE_WAITING_FOR_FIRST_DRAW); | 709 DCHECK_EQ(commit_state_, COMMIT_STATE_WAITING_FOR_FIRST_DRAW); |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 665 !has_pending_tree_) { | 722 !has_pending_tree_) { |
| 666 commit_state_ = COMMIT_STATE_IDLE; | 723 commit_state_ = COMMIT_STATE_IDLE; |
| 667 } | 724 } |
| 668 | 725 |
| 669 if (texture_state_ == LAYER_TEXTURE_STATE_ACQUIRED_BY_IMPL_THREAD) | 726 if (texture_state_ == LAYER_TEXTURE_STATE_ACQUIRED_BY_IMPL_THREAD) |
| 670 texture_state_ = LAYER_TEXTURE_STATE_UNLOCKED; | 727 texture_state_ = LAYER_TEXTURE_STATE_UNLOCKED; |
| 671 | 728 |
| 672 needs_redraw_ = false; | 729 needs_redraw_ = false; |
| 673 draw_if_possible_failed_ = false; | 730 draw_if_possible_failed_ = false; |
| 674 active_tree_needs_first_draw_ = false; | 731 active_tree_needs_first_draw_ = false; |
| 732 last_draw_attempt_count_draw_was_called_ = draw_attempt_count_; | |
| 675 | 733 |
| 676 if (did_swap) { | 734 if (did_swap) { |
| 677 swap_used_incomplete_tile_ = false; | 735 swap_used_incomplete_tile_ = false; |
| 678 last_frame_number_swap_performed_ = current_frame_number_; | 736 last_begin_frame_count_swap_performed_ = begin_frame_count_; |
| 679 } | 737 } |
| 680 } | 738 } |
| 681 | 739 |
| 740 void SchedulerStateMachine::AdvanceBeginFrameStateWhenNoActionsRemain() { | |
| 741 switch (begin_frame_state_) { | |
| 742 case BEGIN_FRAME_STATE_INSIDE_BEGIN_FRAME: | |
| 743 begin_frame_state_ = BEGIN_FRAME_STATE_DEADLINE_PENDING; | |
| 744 break; | |
| 745 case BEGIN_FRAME_STATE_INSIDE_DEADLINE: | |
| 746 begin_frame_state_ = BEGIN_FRAME_STATE_IDLE; | |
|
enne (OOO)
2013/09/10 03:35:44
Just so I understand this correctly, this is the n
brianderson
2013/09/10 21:16:56
Yes, this is the only way. We only transition out
| |
| 747 break; | |
| 748 case BEGIN_FRAME_STATE_IDLE: | |
| 749 case BEGIN_FRAME_STATE_DEADLINE_PENDING: | |
| 750 break; | |
| 751 } | |
| 752 } | |
| 753 | |
| 682 void SchedulerStateMachine::SetMainThreadNeedsLayerTextures() { | 754 void SchedulerStateMachine::SetMainThreadNeedsLayerTextures() { |
| 683 DCHECK(!main_thread_needs_layer_textures_); | 755 DCHECK(!main_thread_needs_layer_textures_); |
| 684 DCHECK_NE(texture_state_, LAYER_TEXTURE_STATE_ACQUIRED_BY_MAIN_THREAD); | 756 DCHECK_NE(texture_state_, LAYER_TEXTURE_STATE_ACQUIRED_BY_MAIN_THREAD); |
| 685 main_thread_needs_layer_textures_ = true; | 757 main_thread_needs_layer_textures_ = true; |
| 686 } | 758 } |
| 687 | 759 |
| 760 bool SchedulerStateMachine::BeginFrameNeededByImplThread() const { | |
| 761 return BeginFrameNeededToDrawByImplThread() || | |
| 762 ProactiveBeginFrameWantedByImplThread(); | |
| 763 } | |
| 764 | |
| 688 // These are the cases where we definitely (or almost definitely) have a | 765 // These are the cases where we definitely (or almost definitely) have a |
| 689 // new frame to draw and can draw. | 766 // new frame to draw and can draw. |
| 690 bool SchedulerStateMachine::BeginFrameNeededToDrawByImplThread() const { | 767 bool SchedulerStateMachine::BeginFrameNeededToDrawByImplThread() const { |
| 691 // The output surface is the provider of BeginFrames for the impl thread, | 768 // The output surface is the provider of BeginFrames for the impl thread, |
| 692 // so we are not going to get them even if we ask for them. | 769 // so we are not going to get them even if we ask for them. |
| 693 if (!HasInitializedOutputSurface()) | 770 if (!HasInitializedOutputSurface()) |
| 694 return false; | 771 return false; |
| 695 | 772 |
| 696 // If we can't draw, don't tick until we are notified that we can draw again. | 773 // If we can't draw, don't tick until we are notified that we can draw again. |
| 697 if (!can_draw_) | 774 if (!can_draw_) |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 712 if (swap_used_incomplete_tile_) | 789 if (swap_used_incomplete_tile_) |
| 713 return true; | 790 return true; |
| 714 | 791 |
| 715 return needs_redraw_; | 792 return needs_redraw_; |
| 716 } | 793 } |
| 717 | 794 |
| 718 // These are cases where we are very likely to draw soon, but might not | 795 // These are cases where we are very likely to draw soon, but might not |
| 719 // actually have a new frame to draw when we receive the next BeginFrame. | 796 // actually have a new frame to draw when we receive the next BeginFrame. |
| 720 // Proactively requesting the BeginFrame helps hide the round trip latency of | 797 // Proactively requesting the BeginFrame helps hide the round trip latency of |
| 721 // the SetNeedsBeginFrame request that has to go to the Browser. | 798 // the SetNeedsBeginFrame request that has to go to the Browser. |
| 722 // However, this is bad for the synchronous compositor because we have to | |
| 723 // draw when we get the BeginFrame and could end up drawing many duplicate | |
| 724 // frames. | |
| 725 bool SchedulerStateMachine::ProactiveBeginFrameWantedByImplThread() const { | 799 bool SchedulerStateMachine::ProactiveBeginFrameWantedByImplThread() const { |
| 726 // The output surface is the provider of BeginFrames for the impl thread, | 800 // The output surface is the provider of BeginFrames for the impl thread, |
| 727 // so we are not going to get them even if we ask for them. | 801 // so we are not going to get them even if we ask for them. |
| 728 if (!HasInitializedOutputSurface()) | 802 if (!HasInitializedOutputSurface()) |
| 729 return false; | 803 return false; |
| 730 | 804 |
| 805 // Proactive BeginFrames are bad for the synchronous compositor because we | |
| 806 // have to draw when we get the BeginFrame and could end up drawing many | |
| 807 // duplicate frames if our new frame isn't ready in time. | |
| 808 if (settings_.using_synchronous_renderer_compositor) | |
| 809 return false; | |
| 810 | |
| 811 // Do not be proactive if vsync is off. | |
| 812 if (!settings_.throttle_frame_production) | |
| 813 return false; | |
| 814 | |
| 731 // Do not be proactive when invisible. | 815 // Do not be proactive when invisible. |
| 732 if (!visible_) | 816 if (!visible_) |
| 733 return false; | 817 return false; |
| 734 | 818 |
| 735 // We should proactively request a BeginFrame if a commit is pending | 819 // We should proactively request a BeginFrame if a commit is pending |
| 736 // because we will want to draw if the commit completes quickly. | 820 // because we will want to draw if the commit completes quickly. |
| 737 if (needs_commit_ || commit_state_ != COMMIT_STATE_IDLE) | 821 if (needs_commit_ || commit_state_ != COMMIT_STATE_IDLE) |
| 738 return true; | 822 return true; |
| 739 | 823 |
| 740 // If the pending tree activates quickly, we'll want a BeginFrame soon | 824 // If the pending tree activates quickly, we'll want a BeginFrame soon |
| 741 // to draw the new active tree. | 825 // to draw the new active tree. |
| 742 if (has_pending_tree_) | 826 if (has_pending_tree_) |
| 743 return true; | 827 return true; |
| 744 | 828 |
| 745 return false; | 829 return false; |
| 746 } | 830 } |
| 747 | 831 |
| 748 void SchedulerStateMachine::DidEnterBeginFrame(const BeginFrameArgs& args) { | 832 void SchedulerStateMachine::OnBeginFrame(const BeginFrameArgs& args) { |
| 749 current_frame_number_++; | 833 begin_frame_count_++; |
| 750 inside_begin_frame_ = true; | 834 draw_attempt_count_++; |
| 751 last_begin_frame_args_ = args; | 835 last_begin_frame_args_ = args; |
| 836 begin_frame_state_ = BEGIN_FRAME_STATE_INSIDE_BEGIN_FRAME; | |
| 752 } | 837 } |
| 753 | 838 |
| 754 void SchedulerStateMachine::DidLeaveBeginFrame() { | 839 bool SchedulerStateMachine::ShouldTriggerBeginFrameDeadlineEarly() const { |
| 755 inside_begin_frame_ = false; | 840 // TODO(brianderson): This should take into account multiple commit sources. |
| 841 return begin_frame_state_ == BEGIN_FRAME_STATE_DEADLINE_PENDING && | |
| 842 active_tree_needs_first_draw_; | |
| 843 } | |
| 844 | |
| 845 bool SchedulerStateMachine::InsideBeginFrame() const { | |
| 846 return begin_frame_state_ != BEGIN_FRAME_STATE_IDLE; | |
| 847 } | |
| 848 | |
| 849 void SchedulerStateMachine::OnBeginFrameDeadline() { | |
| 850 DCHECK_EQ(begin_frame_state_, BEGIN_FRAME_STATE_DEADLINE_PENDING); | |
|
enne (OOO)
2013/09/10 03:35:44
What guarantees that this is true? It seems like y
brianderson
2013/09/10 21:16:56
In Scheduler::BeginFrame, we will always transitio
| |
| 851 draw_attempt_count_++; | |
| 852 begin_frame_state_ = BEGIN_FRAME_STATE_INSIDE_DEADLINE; | |
| 756 } | 853 } |
| 757 | 854 |
| 758 void SchedulerStateMachine::SetVisible(bool visible) { visible_ = visible; } | 855 void SchedulerStateMachine::SetVisible(bool visible) { visible_ = visible; } |
| 759 | 856 |
| 857 void SchedulerStateMachine::SetCanDraw(bool can_draw) { can_draw_ = can_draw; } | |
| 858 | |
| 760 void SchedulerStateMachine::SetNeedsRedraw() { needs_redraw_ = true; } | 859 void SchedulerStateMachine::SetNeedsRedraw() { needs_redraw_ = true; } |
| 761 | 860 |
| 762 void SchedulerStateMachine::DidSwapUseIncompleteTile() { | 861 void SchedulerStateMachine::DidSwapUseIncompleteTile() { |
| 763 swap_used_incomplete_tile_ = true; | 862 swap_used_incomplete_tile_ = true; |
| 764 } | 863 } |
| 765 | 864 |
| 766 void SchedulerStateMachine::DidDrawIfPossibleCompleted(bool success) { | 865 void SchedulerStateMachine::DidDrawIfPossibleCompleted(bool success) { |
| 767 draw_if_possible_failed_ = !success; | 866 draw_if_possible_failed_ = !success; |
| 768 if (draw_if_possible_failed_) { | 867 if (draw_if_possible_failed_) { |
| 769 needs_redraw_ = true; | 868 needs_redraw_ = true; |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 828 return; | 927 return; |
| 829 output_surface_state_ = OUTPUT_SURFACE_LOST; | 928 output_surface_state_ = OUTPUT_SURFACE_LOST; |
| 830 needs_redraw_ = false; | 929 needs_redraw_ = false; |
| 831 } | 930 } |
| 832 | 931 |
| 833 void SchedulerStateMachine::NotifyReadyToActivate() { | 932 void SchedulerStateMachine::NotifyReadyToActivate() { |
| 834 if (has_pending_tree_) | 933 if (has_pending_tree_) |
| 835 pending_tree_is_ready_for_activation_ = true; | 934 pending_tree_is_ready_for_activation_ = true; |
| 836 } | 935 } |
| 837 | 936 |
| 838 void SchedulerStateMachine::SetCanDraw(bool can) { can_draw_ = can; } | |
| 839 | |
| 840 void SchedulerStateMachine::DidCreateAndInitializeOutputSurface() { | 937 void SchedulerStateMachine::DidCreateAndInitializeOutputSurface() { |
| 841 DCHECK_EQ(output_surface_state_, OUTPUT_SURFACE_CREATING); | 938 DCHECK_EQ(output_surface_state_, OUTPUT_SURFACE_CREATING); |
| 842 output_surface_state_ = OUTPUT_SURFACE_WAITING_FOR_FIRST_COMMIT; | 939 output_surface_state_ = OUTPUT_SURFACE_WAITING_FOR_FIRST_COMMIT; |
| 843 | 940 |
| 844 if (did_create_and_initialize_first_output_surface_) { | 941 if (did_create_and_initialize_first_output_surface_) { |
| 845 // TODO(boliu): See if we can remove this when impl-side painting is always | 942 // TODO(boliu): See if we can remove this when impl-side painting is always |
| 846 // on. Does anything on the main thread need to update after recreate? | 943 // on. Does anything on the main thread need to update after recreate? |
| 847 needs_commit_ = true; | 944 needs_commit_ = true; |
| 848 } | 945 } |
| 849 did_create_and_initialize_first_output_surface_ = true; | 946 did_create_and_initialize_first_output_surface_ = true; |
| 850 } | 947 } |
| 851 | 948 |
| 852 bool SchedulerStateMachine::HasInitializedOutputSurface() const { | 949 bool SchedulerStateMachine::HasInitializedOutputSurface() const { |
| 853 switch (output_surface_state_) { | 950 switch (output_surface_state_) { |
| 854 case OUTPUT_SURFACE_LOST: | 951 case OUTPUT_SURFACE_LOST: |
| 855 case OUTPUT_SURFACE_CREATING: | 952 case OUTPUT_SURFACE_CREATING: |
| 856 return false; | 953 return false; |
| 857 | 954 |
| 858 case OUTPUT_SURFACE_ACTIVE: | 955 case OUTPUT_SURFACE_ACTIVE: |
| 859 case OUTPUT_SURFACE_WAITING_FOR_FIRST_COMMIT: | 956 case OUTPUT_SURFACE_WAITING_FOR_FIRST_COMMIT: |
| 860 case OUTPUT_SURFACE_WAITING_FOR_FIRST_ACTIVATION: | 957 case OUTPUT_SURFACE_WAITING_FOR_FIRST_ACTIVATION: |
| 861 return true; | 958 return true; |
| 862 } | 959 } |
| 863 NOTREACHED(); | 960 NOTREACHED(); |
| 864 return false; | 961 return false; |
| 865 } | 962 } |
| 866 | 963 |
| 867 } // namespace cc | 964 } // namespace cc |
| OLD | NEW |