Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(217)

Side by Side Diff: cc/scheduler/scheduler_state_machine.cc

Issue 19106007: cc: Allow the main thread to cancel commits (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2011 The Chromium Authors. All rights reserved. 1 // Copyright 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "cc/scheduler/scheduler_state_machine.h" 5 #include "cc/scheduler/scheduler_state_machine.h"
6 6
7 #include "base/format_macros.h" 7 #include "base/format_macros.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/strings/stringprintf.h" 9 #include "base/strings/stringprintf.h"
10 10
11 namespace cc { 11 namespace cc {
12 12
13 SchedulerStateMachine::SchedulerStateMachine(const SchedulerSettings& settings) 13 SchedulerStateMachine::SchedulerStateMachine(const SchedulerSettings& settings)
14 : settings_(settings), 14 : settings_(settings),
15 commit_state_(COMMIT_STATE_IDLE), 15 commit_state_(COMMIT_STATE_IDLE),
16 commit_count_(0), 16 commit_count_(0),
17 current_frame_number_(0), 17 current_frame_number_(0),
18 last_frame_number_where_commit_was_aborted_(-1),
18 last_frame_number_where_draw_was_called_(-1), 19 last_frame_number_where_draw_was_called_(-1),
19 last_frame_number_where_tree_activation_attempted_(-1), 20 last_frame_number_where_tree_activation_attempted_(-1),
20 last_frame_number_where_check_for_completed_tile_uploads_called_(-1), 21 last_frame_number_where_check_for_completed_tile_uploads_called_(-1),
21 consecutive_failed_draws_(0), 22 consecutive_failed_draws_(0),
22 maximum_number_of_failed_draws_before_draw_is_forced_(3), 23 maximum_number_of_failed_draws_before_draw_is_forced_(3),
23 needs_redraw_(false), 24 needs_redraw_(false),
24 swap_used_incomplete_tile_(false), 25 swap_used_incomplete_tile_(false),
25 needs_forced_redraw_(false), 26 needs_forced_redraw_(false),
26 needs_forced_redraw_after_next_commit_(false), 27 needs_forced_redraw_after_next_commit_(false),
27 needs_commit_(false), 28 needs_commit_(false),
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 if (!BeginFrameNeededToDrawByImplThread()) 178 if (!BeginFrameNeededToDrawByImplThread())
178 return true; 179 return true;
179 return false; 180 return false;
180 } 181 }
181 182
182 SchedulerStateMachine::Action SchedulerStateMachine::NextAction() const { 183 SchedulerStateMachine::Action SchedulerStateMachine::NextAction() const {
183 if (ShouldAcquireLayerTexturesForMainThread()) 184 if (ShouldAcquireLayerTexturesForMainThread())
184 return ACTION_ACQUIRE_LAYER_TEXTURES_FOR_MAIN_THREAD; 185 return ACTION_ACQUIRE_LAYER_TEXTURES_FOR_MAIN_THREAD;
185 186
186 switch (commit_state_) { 187 switch (commit_state_) {
187 case COMMIT_STATE_IDLE: 188 case COMMIT_STATE_IDLE: {
188 if (output_surface_state_ != OUTPUT_SURFACE_ACTIVE && 189 if (output_surface_state_ != OUTPUT_SURFACE_ACTIVE &&
189 needs_forced_redraw_) 190 needs_forced_redraw_)
190 return ACTION_DRAW_FORCED; 191 return ACTION_DRAW_FORCED;
191 if (output_surface_state_ != OUTPUT_SURFACE_ACTIVE && 192 if (output_surface_state_ != OUTPUT_SURFACE_ACTIVE &&
192 needs_forced_commit_) 193 needs_forced_commit_)
193 // TODO(enne): Should probably drop the active tree on force commit. 194 // TODO(enne): Should probably drop the active tree on force commit.
194 return has_pending_tree_ ? ACTION_NONE 195 return has_pending_tree_ ? ACTION_NONE
195 : ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD; 196 : ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD;
196 if (output_surface_state_ == OUTPUT_SURFACE_LOST && can_start_) 197 if (output_surface_state_ == OUTPUT_SURFACE_LOST && can_start_)
197 return ACTION_BEGIN_OUTPUT_SURFACE_CREATION; 198 return ACTION_BEGIN_OUTPUT_SURFACE_CREATION;
198 if (output_surface_state_ == OUTPUT_SURFACE_CREATING) 199 if (output_surface_state_ == OUTPUT_SURFACE_CREATING)
199 return ACTION_NONE; 200 return ACTION_NONE;
200 if (ShouldCheckForCompletedTileUploads()) 201 if (ShouldCheckForCompletedTileUploads())
201 return ACTION_CHECK_FOR_COMPLETED_TILE_UPLOADS; 202 return ACTION_CHECK_FOR_COMPLETED_TILE_UPLOADS;
202 if (ShouldAttemptTreeActivation()) 203 if (ShouldAttemptTreeActivation())
203 return ACTION_ACTIVATE_PENDING_TREE_IF_NEEDED; 204 return ACTION_ACTIVATE_PENDING_TREE_IF_NEEDED;
204 if (ShouldDraw()) { 205 if (ShouldDraw()) {
205 return needs_forced_redraw_ ? ACTION_DRAW_FORCED 206 return needs_forced_redraw_ ? ACTION_DRAW_FORCED
206 : ACTION_DRAW_IF_POSSIBLE; 207 : ACTION_DRAW_IF_POSSIBLE;
207 } 208 }
208 if (needs_commit_ && 209 bool can_commit_this_frame = visible_ &&
209 ((visible_ && output_surface_state_ == OUTPUT_SURFACE_ACTIVE) 210 current_frame_number_ > last_frame_number_where_commit_was_aborted_;
210 || needs_forced_commit_)) 211 if (needs_commit_ && ((can_commit_this_frame &&
212 output_surface_state_ == OUTPUT_SURFACE_ACTIVE) ||
213 needs_forced_commit_))
211 // TODO(enne): Should probably drop the active tree on force commit. 214 // TODO(enne): Should probably drop the active tree on force commit.
212 return has_pending_tree_ ? ACTION_NONE 215 return has_pending_tree_ ? ACTION_NONE
213 : ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD; 216 : ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD;
214 return ACTION_NONE; 217 return ACTION_NONE;
215 218 }
216 case COMMIT_STATE_FRAME_IN_PROGRESS: 219 case COMMIT_STATE_FRAME_IN_PROGRESS:
217 if (ShouldCheckForCompletedTileUploads()) 220 if (ShouldCheckForCompletedTileUploads())
218 return ACTION_CHECK_FOR_COMPLETED_TILE_UPLOADS; 221 return ACTION_CHECK_FOR_COMPLETED_TILE_UPLOADS;
219 if (ShouldAttemptTreeActivation()) 222 if (ShouldAttemptTreeActivation())
220 return ACTION_ACTIVATE_PENDING_TREE_IF_NEEDED; 223 return ACTION_ACTIVATE_PENDING_TREE_IF_NEEDED;
221 if (ShouldDraw()) { 224 if (ShouldDraw()) {
222 return needs_forced_redraw_ ? ACTION_DRAW_FORCED 225 return needs_forced_redraw_ ? ACTION_DRAW_FORCED
223 : ACTION_DRAW_IF_POSSIBLE; 226 : ACTION_DRAW_IF_POSSIBLE;
224 } 227 }
225 return ACTION_NONE; 228 return ACTION_NONE;
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 current_frame_number_; 272 current_frame_number_;
270 return; 273 return;
271 274
272 case ACTION_ACTIVATE_PENDING_TREE_IF_NEEDED: 275 case ACTION_ACTIVATE_PENDING_TREE_IF_NEEDED:
273 last_frame_number_where_tree_activation_attempted_ = 276 last_frame_number_where_tree_activation_attempted_ =
274 current_frame_number_; 277 current_frame_number_;
275 return; 278 return;
276 279
277 case ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD: 280 case ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD:
278 DCHECK(!has_pending_tree_); 281 DCHECK(!has_pending_tree_);
279 DCHECK(visible_ || needs_forced_commit_); 282 if (!needs_forced_commit_) {
283 DCHECK(visible_);
284 DCHECK_GT(current_frame_number_,
285 last_frame_number_where_commit_was_aborted_);
286 }
280 commit_state_ = COMMIT_STATE_FRAME_IN_PROGRESS; 287 commit_state_ = COMMIT_STATE_FRAME_IN_PROGRESS;
281 needs_commit_ = false; 288 needs_commit_ = false;
282 needs_forced_commit_ = false; 289 needs_forced_commit_ = false;
283 return; 290 return;
284 291
285 case ACTION_COMMIT: 292 case ACTION_COMMIT:
286 commit_count_++; 293 commit_count_++;
287 if (expect_immediate_begin_frame_for_main_thread_) 294 if (expect_immediate_begin_frame_for_main_thread_)
288 commit_state_ = COMMIT_STATE_WAITING_FOR_FIRST_FORCED_DRAW; 295 commit_state_ = COMMIT_STATE_WAITING_FOR_FIRST_FORCED_DRAW;
289 else 296 else
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
415 } 422 }
416 423
417 void SchedulerStateMachine::FinishCommit() { 424 void SchedulerStateMachine::FinishCommit() {
418 DCHECK(commit_state_ == COMMIT_STATE_FRAME_IN_PROGRESS || 425 DCHECK(commit_state_ == COMMIT_STATE_FRAME_IN_PROGRESS ||
419 (expect_immediate_begin_frame_for_main_thread_ && 426 (expect_immediate_begin_frame_for_main_thread_ &&
420 commit_state_ != COMMIT_STATE_IDLE)) 427 commit_state_ != COMMIT_STATE_IDLE))
421 << ToString(); 428 << ToString();
422 commit_state_ = COMMIT_STATE_READY_TO_COMMIT; 429 commit_state_ = COMMIT_STATE_READY_TO_COMMIT;
423 } 430 }
424 431
425 void SchedulerStateMachine::BeginFrameAbortedByMainThread() { 432 void SchedulerStateMachine::BeginFrameAbortedByMainThread(bool cancel_commit) {
426 DCHECK_EQ(commit_state_, COMMIT_STATE_FRAME_IN_PROGRESS); 433 DCHECK_EQ(commit_state_, COMMIT_STATE_FRAME_IN_PROGRESS);
434 last_frame_number_where_commit_was_aborted_ = current_frame_number_;
427 if (expect_immediate_begin_frame_for_main_thread_) { 435 if (expect_immediate_begin_frame_for_main_thread_) {
428 expect_immediate_begin_frame_for_main_thread_ = false; 436 expect_immediate_begin_frame_for_main_thread_ = false;
437 } else if (cancel_commit) {
438 commit_state_ = COMMIT_STATE_IDLE;
429 } else { 439 } else {
430 commit_state_ = COMMIT_STATE_IDLE; 440 commit_state_ = COMMIT_STATE_IDLE;
431 SetNeedsCommit(); 441 SetNeedsCommit();
432 } 442 }
433 } 443 }
434 444
435 void SchedulerStateMachine::DidLoseOutputSurface() { 445 void SchedulerStateMachine::DidLoseOutputSurface() {
436 if (output_surface_state_ == OUTPUT_SURFACE_LOST || 446 if (output_surface_state_ == OUTPUT_SURFACE_LOST ||
437 output_surface_state_ == OUTPUT_SURFACE_CREATING) 447 output_surface_state_ == OUTPUT_SURFACE_CREATING)
438 return; 448 return;
(...skipping 25 matching lines...) Expand all
464 bool SchedulerStateMachine::HasInitializedOutputSurface() const { 474 bool SchedulerStateMachine::HasInitializedOutputSurface() const {
465 return output_surface_state_ == OUTPUT_SURFACE_ACTIVE; 475 return output_surface_state_ == OUTPUT_SURFACE_ACTIVE;
466 } 476 }
467 477
468 void SchedulerStateMachine::SetMaximumNumberOfFailedDrawsBeforeDrawIsForced( 478 void SchedulerStateMachine::SetMaximumNumberOfFailedDrawsBeforeDrawIsForced(
469 int num_draws) { 479 int num_draws) {
470 maximum_number_of_failed_draws_before_draw_is_forced_ = num_draws; 480 maximum_number_of_failed_draws_before_draw_is_forced_ = num_draws;
471 } 481 }
472 482
473 } // namespace cc 483 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698