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/logging.h" | 8 #include "base/logging.h" |
8 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
9 | 10 |
10 namespace cc { | 11 namespace cc { |
11 | 12 |
12 SchedulerStateMachine::SchedulerStateMachine(const SchedulerSettings& settings) | 13 SchedulerStateMachine::SchedulerStateMachine(const SchedulerSettings& settings) |
13 : settings_(settings), | 14 : settings_(settings), |
14 commit_state_(COMMIT_STATE_IDLE), | 15 commit_state_(COMMIT_STATE_IDLE), |
| 16 commit_count_(0), |
15 current_frame_number_(0), | 17 current_frame_number_(0), |
16 last_frame_number_where_draw_was_called_(-1), | 18 last_frame_number_where_draw_was_called_(-1), |
17 last_frame_number_where_tree_activation_attempted_(-1), | 19 last_frame_number_where_tree_activation_attempted_(-1), |
18 last_frame_number_where_check_for_completed_tile_uploads_called_(-1), | 20 last_frame_number_where_check_for_completed_tile_uploads_called_(-1), |
19 consecutive_failed_draws_(0), | 21 consecutive_failed_draws_(0), |
20 maximum_number_of_failed_draws_before_draw_is_forced_(3), | 22 maximum_number_of_failed_draws_before_draw_is_forced_(3), |
21 needs_redraw_(false), | 23 needs_redraw_(false), |
22 swap_used_incomplete_tile_(false), | 24 swap_used_incomplete_tile_(false), |
23 needs_forced_redraw_(false), | 25 needs_forced_redraw_(false), |
24 needs_forced_redraw_after_next_commit_(false), | 26 needs_forced_redraw_after_next_commit_(false), |
(...skipping 10 matching lines...) Expand all Loading... |
35 texture_state_(LAYER_TEXTURE_STATE_UNLOCKED), | 37 texture_state_(LAYER_TEXTURE_STATE_UNLOCKED), |
36 output_surface_state_(OUTPUT_SURFACE_LOST), | 38 output_surface_state_(OUTPUT_SURFACE_LOST), |
37 did_create_and_initialize_first_output_surface_(false) {} | 39 did_create_and_initialize_first_output_surface_(false) {} |
38 | 40 |
39 std::string SchedulerStateMachine::ToString() { | 41 std::string SchedulerStateMachine::ToString() { |
40 std::string str; | 42 std::string str; |
41 base::StringAppendF(&str, | 43 base::StringAppendF(&str, |
42 "settings_.impl_side_painting = %d; ", | 44 "settings_.impl_side_painting = %d; ", |
43 settings_.impl_side_painting); | 45 settings_.impl_side_painting); |
44 base::StringAppendF(&str, "commit_state_ = %d; ", commit_state_); | 46 base::StringAppendF(&str, "commit_state_ = %d; ", commit_state_); |
| 47 base::StringAppendF(&str, "commit_count_ = %d; ", commit_count_); |
45 base::StringAppendF( | 48 base::StringAppendF( |
46 &str, "current_frame_number_ = %d; ", current_frame_number_); | 49 &str, "current_frame_number_ = %d; ", current_frame_number_); |
47 base::StringAppendF(&str, | 50 base::StringAppendF(&str, |
48 "last_frame_number_where_draw_was_called_ = %d; ", | 51 "last_frame_number_where_draw_was_called_ = %d; ", |
49 last_frame_number_where_draw_was_called_); | 52 last_frame_number_where_draw_was_called_); |
50 base::StringAppendF( | 53 base::StringAppendF( |
51 &str, | 54 &str, |
52 "last_frame_number_where_tree_activation_attempted_ = %d; ", | 55 "last_frame_number_where_tree_activation_attempted_ = %d; ", |
53 last_frame_number_where_tree_activation_attempted_); | 56 last_frame_number_where_tree_activation_attempted_); |
54 base::StringAppendF( | 57 base::StringAppendF( |
(...skipping 18 matching lines...) Expand all Loading... |
73 base::StringAppendF( | 76 base::StringAppendF( |
74 &str, "needs_forced_commit_ = %d; ", needs_forced_commit_); | 77 &str, "needs_forced_commit_ = %d; ", needs_forced_commit_); |
75 base::StringAppendF(&str, | 78 base::StringAppendF(&str, |
76 "expect_immediate_begin_frame_for_main_thread_ = %d; ", | 79 "expect_immediate_begin_frame_for_main_thread_ = %d; ", |
77 expect_immediate_begin_frame_for_main_thread_); | 80 expect_immediate_begin_frame_for_main_thread_); |
78 base::StringAppendF(&str, | 81 base::StringAppendF(&str, |
79 "main_thread_needs_layer_textures_ = %d; ", | 82 "main_thread_needs_layer_textures_ = %d; ", |
80 main_thread_needs_layer_textures_); | 83 main_thread_needs_layer_textures_); |
81 base::StringAppendF(&str, "inside_begin_frame_ = %d; ", | 84 base::StringAppendF(&str, "inside_begin_frame_ = %d; ", |
82 inside_begin_frame_); | 85 inside_begin_frame_); |
| 86 base::StringAppendF(&str, "last_frame_time_ = %"PRId64"; ", |
| 87 (last_frame_time_ - base::TimeTicks()).InMilliseconds()); |
83 base::StringAppendF(&str, "visible_ = %d; ", visible_); | 88 base::StringAppendF(&str, "visible_ = %d; ", visible_); |
84 base::StringAppendF(&str, "can_start_ = %d; ", can_start_); | 89 base::StringAppendF(&str, "can_start_ = %d; ", can_start_); |
85 base::StringAppendF(&str, "can_draw_ = %d; ", can_draw_); | 90 base::StringAppendF(&str, "can_draw_ = %d; ", can_draw_); |
86 base::StringAppendF( | 91 base::StringAppendF( |
87 &str, "draw_if_possible_failed_ = %d; ", draw_if_possible_failed_); | 92 &str, "draw_if_possible_failed_ = %d; ", draw_if_possible_failed_); |
88 base::StringAppendF(&str, "has_pending_tree_ = %d; ", has_pending_tree_); | 93 base::StringAppendF(&str, "has_pending_tree_ = %d; ", has_pending_tree_); |
89 base::StringAppendF(&str, "texture_state_ = %d; ", texture_state_); | 94 base::StringAppendF(&str, "texture_state_ = %d; ", texture_state_); |
90 base::StringAppendF( | 95 base::StringAppendF( |
91 &str, "output_surface_state_ = %d; ", output_surface_state_); | 96 &str, "output_surface_state_ = %d; ", output_surface_state_); |
92 return str; | 97 return str; |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
266 | 271 |
267 case ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD: | 272 case ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD: |
268 DCHECK(!has_pending_tree_); | 273 DCHECK(!has_pending_tree_); |
269 DCHECK(visible_ || needs_forced_commit_); | 274 DCHECK(visible_ || needs_forced_commit_); |
270 commit_state_ = COMMIT_STATE_FRAME_IN_PROGRESS; | 275 commit_state_ = COMMIT_STATE_FRAME_IN_PROGRESS; |
271 needs_commit_ = false; | 276 needs_commit_ = false; |
272 needs_forced_commit_ = false; | 277 needs_forced_commit_ = false; |
273 return; | 278 return; |
274 | 279 |
275 case ACTION_COMMIT: | 280 case ACTION_COMMIT: |
| 281 commit_count_++; |
276 if (expect_immediate_begin_frame_for_main_thread_) | 282 if (expect_immediate_begin_frame_for_main_thread_) |
277 commit_state_ = COMMIT_STATE_WAITING_FOR_FIRST_FORCED_DRAW; | 283 commit_state_ = COMMIT_STATE_WAITING_FOR_FIRST_FORCED_DRAW; |
278 else | 284 else |
279 commit_state_ = COMMIT_STATE_WAITING_FOR_FIRST_DRAW; | 285 commit_state_ = COMMIT_STATE_WAITING_FOR_FIRST_DRAW; |
280 // When impl-side painting, we draw on activation instead of on commit. | 286 // When impl-side painting, we draw on activation instead of on commit. |
281 if (!settings_.impl_side_painting) | 287 if (!settings_.impl_side_painting) |
282 needs_redraw_ = true; | 288 needs_redraw_ = true; |
283 if (draw_if_possible_failed_) | 289 if (draw_if_possible_failed_) |
284 last_frame_number_where_draw_was_called_ = -1; | 290 last_frame_number_where_draw_was_called_ = -1; |
285 | 291 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
325 } | 331 } |
326 } | 332 } |
327 | 333 |
328 void SchedulerStateMachine::SetMainThreadNeedsLayerTextures() { | 334 void SchedulerStateMachine::SetMainThreadNeedsLayerTextures() { |
329 DCHECK(!main_thread_needs_layer_textures_); | 335 DCHECK(!main_thread_needs_layer_textures_); |
330 DCHECK_NE(texture_state_, LAYER_TEXTURE_STATE_ACQUIRED_BY_MAIN_THREAD); | 336 DCHECK_NE(texture_state_, LAYER_TEXTURE_STATE_ACQUIRED_BY_MAIN_THREAD); |
331 main_thread_needs_layer_textures_ = true; | 337 main_thread_needs_layer_textures_ = true; |
332 } | 338 } |
333 | 339 |
334 bool SchedulerStateMachine::BeginFrameNeededByImplThread() const { | 340 bool SchedulerStateMachine::BeginFrameNeededByImplThread() const { |
| 341 // We should proactively request a BeginFrame if a commit is pending. |
| 342 if (needs_commit_ || needs_forced_commit_ || |
| 343 commit_state_ != COMMIT_STATE_IDLE) |
| 344 return true; |
| 345 |
335 // If we have a pending tree, need to keep getting notifications until | 346 // If we have a pending tree, need to keep getting notifications until |
336 // the tree is ready to be swapped. | 347 // the tree is ready to be swapped. |
337 if (has_pending_tree_) | 348 if (has_pending_tree_) |
338 return true; | 349 return true; |
339 | 350 |
340 // If we can't draw, don't tick until we are notified that we can draw again. | 351 // If we can't draw, don't tick until we are notified that we can draw again. |
341 if (!can_draw_) | 352 if (!can_draw_) |
342 return false; | 353 return false; |
343 | 354 |
344 if (needs_forced_redraw_) | 355 if (needs_forced_redraw_) |
345 return true; | 356 return true; |
346 | 357 |
347 if (visible_ && swap_used_incomplete_tile_) | 358 if (visible_ && swap_used_incomplete_tile_) |
348 return true; | 359 return true; |
349 | 360 |
350 return needs_redraw_ && visible_ && | 361 return needs_redraw_ && visible_ && |
351 output_surface_state_ == OUTPUT_SURFACE_ACTIVE; | 362 output_surface_state_ == OUTPUT_SURFACE_ACTIVE; |
352 } | 363 } |
353 | 364 |
354 void SchedulerStateMachine::DidEnterBeginFrame() { | 365 void SchedulerStateMachine::DidEnterBeginFrame() { |
355 inside_begin_frame_ = true; | 366 inside_begin_frame_ = true; |
356 } | 367 } |
357 | 368 |
| 369 void SchedulerStateMachine::SetFrameTime(base::TimeTicks frame_time) { |
| 370 last_frame_time_ = frame_time; |
| 371 } |
| 372 |
358 void SchedulerStateMachine::DidLeaveBeginFrame() { | 373 void SchedulerStateMachine::DidLeaveBeginFrame() { |
359 current_frame_number_++; | 374 current_frame_number_++; |
360 inside_begin_frame_ = false; | 375 inside_begin_frame_ = false; |
361 } | 376 } |
362 | 377 |
363 void SchedulerStateMachine::SetVisible(bool visible) { visible_ = visible; } | 378 void SchedulerStateMachine::SetVisible(bool visible) { visible_ = visible; } |
364 | 379 |
365 void SchedulerStateMachine::SetNeedsRedraw() { needs_redraw_ = true; } | 380 void SchedulerStateMachine::SetNeedsRedraw() { needs_redraw_ = true; } |
366 | 381 |
367 void SchedulerStateMachine::DidSwapUseIncompleteTile() { | 382 void SchedulerStateMachine::DidSwapUseIncompleteTile() { |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
448 bool SchedulerStateMachine::HasInitializedOutputSurface() const { | 463 bool SchedulerStateMachine::HasInitializedOutputSurface() const { |
449 return output_surface_state_ == OUTPUT_SURFACE_ACTIVE; | 464 return output_surface_state_ == OUTPUT_SURFACE_ACTIVE; |
450 } | 465 } |
451 | 466 |
452 void SchedulerStateMachine::SetMaximumNumberOfFailedDrawsBeforeDrawIsForced( | 467 void SchedulerStateMachine::SetMaximumNumberOfFailedDrawsBeforeDrawIsForced( |
453 int num_draws) { | 468 int num_draws) { |
454 maximum_number_of_failed_draws_before_draw_is_forced_ = num_draws; | 469 maximum_number_of_failed_draws_before_draw_is_forced_ = num_draws; |
455 } | 470 } |
456 | 471 |
457 } // namespace cc | 472 } // namespace cc |
OLD | NEW |