| 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.h" | 5 #include "cc/scheduler/scheduler.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include "base/auto_reset.h" | 8 #include "base/auto_reset.h" |
| 9 #include "base/debug/trace_event.h" | 9 #include "base/debug/trace_event.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 // will not give us a BeginImplFrame until the commit completes. See | 194 // will not give us a BeginImplFrame until the commit completes. See |
| 195 // crbug.com/317430 for an example of a swap ack being held on commit. Thus | 195 // crbug.com/317430 for an example of a swap ack being held on commit. Thus |
| 196 // we set a repeating timer to poll on ProcessScheduledActions until we | 196 // we set a repeating timer to poll on ProcessScheduledActions until we |
| 197 // successfully reach BeginImplFrame. Synchronous compositor does not use | 197 // successfully reach BeginImplFrame. Synchronous compositor does not use |
| 198 // frame rate controller or have the circular wait in the bug. | 198 // frame rate controller or have the circular wait in the bug. |
| 199 if (IsBeginMainFrameSentOrStarted() && | 199 if (IsBeginMainFrameSentOrStarted() && |
| 200 !settings_.using_synchronous_renderer_compositor) { | 200 !settings_.using_synchronous_renderer_compositor) { |
| 201 needs_advance_commit_state_timer = true; | 201 needs_advance_commit_state_timer = true; |
| 202 } | 202 } |
| 203 } | 203 } |
| 204 if (needs_advance_commit_state_timer != | 204 |
| 205 advance_commit_state_timer_.IsRunning()) { | 205 if (needs_advance_commit_state_timer) { |
| 206 if (needs_advance_commit_state_timer && | 206 if (advance_commit_state_closure_.IsCancelled() && |
| 207 last_begin_impl_frame_args_.IsValid()) { | 207 last_begin_impl_frame_args_.IsValid()) { |
| 208 // Since we'd rather get a BeginImplFrame by the normal mechanism, we | 208 // Since we'd rather get a BeginImplFrame by the normal mechanism, we |
| 209 // set the interval to twice the interval from the previous frame. | 209 // set the interval to twice the interval from the previous frame. |
| 210 advance_commit_state_timer_.Start( | 210 advance_commit_state_closure_.Reset(base::Bind( |
| 211 &Scheduler::PollToAdvanceCommitState, weak_factory_.GetWeakPtr())); |
| 212 impl_task_runner_->PostDelayedTask( |
| 211 FROM_HERE, | 213 FROM_HERE, |
| 212 last_begin_impl_frame_args_.interval * 2, | 214 advance_commit_state_closure_.callback(), |
| 213 base::Bind(&Scheduler::ProcessScheduledActions, | 215 last_begin_impl_frame_args_.interval * 2); |
| 214 base::Unretained(this))); | |
| 215 } else { | |
| 216 advance_commit_state_timer_.Stop(); | |
| 217 } | 216 } |
| 217 } else { |
| 218 advance_commit_state_closure_.Cancel(); |
| 218 } | 219 } |
| 219 } | 220 } |
| 220 | 221 |
| 221 void Scheduler::BeginImplFrame(const BeginFrameArgs& args) { | 222 void Scheduler::BeginImplFrame(const BeginFrameArgs& args) { |
| 222 TRACE_EVENT0("cc", "Scheduler::BeginImplFrame"); | 223 TRACE_EVENT0("cc", "Scheduler::BeginImplFrame"); |
| 223 DCHECK(state_machine_.begin_impl_frame_state() == | 224 DCHECK(state_machine_.begin_impl_frame_state() == |
| 224 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE); | 225 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE); |
| 225 DCHECK(state_machine_.HasInitializedOutputSurface()); | 226 DCHECK(state_machine_.HasInitializedOutputSurface()); |
| 226 | 227 |
| 228 advance_commit_state_closure_.Cancel(); |
| 229 |
| 227 last_begin_impl_frame_args_ = args; | 230 last_begin_impl_frame_args_ = args; |
| 228 last_begin_impl_frame_args_.deadline -= client_->DrawDurationEstimate(); | 231 last_begin_impl_frame_args_.deadline -= client_->DrawDurationEstimate(); |
| 229 | 232 |
| 230 if (!state_machine_.smoothness_takes_priority() && | 233 if (!state_machine_.smoothness_takes_priority() && |
| 231 state_machine_.MainThreadIsInHighLatencyMode() && | 234 state_machine_.MainThreadIsInHighLatencyMode() && |
| 232 CanCommitAndActivateBeforeDeadline()) { | 235 CanCommitAndActivateBeforeDeadline()) { |
| 233 state_machine_.SetSkipNextBeginMainFrameToReduceLatency(); | 236 state_machine_.SetSkipNextBeginMainFrameToReduceLatency(); |
| 234 } | 237 } |
| 235 | 238 |
| 236 state_machine_.OnBeginImplFrame(last_begin_impl_frame_args_); | 239 state_machine_.OnBeginImplFrame(last_begin_impl_frame_args_); |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 312 } | 315 } |
| 313 | 316 |
| 314 void Scheduler::PollForAnticipatedDrawTriggers() { | 317 void Scheduler::PollForAnticipatedDrawTriggers() { |
| 315 TRACE_EVENT0("cc", "Scheduler::PollForAnticipatedDrawTriggers"); | 318 TRACE_EVENT0("cc", "Scheduler::PollForAnticipatedDrawTriggers"); |
| 316 poll_for_draw_triggers_closure_.Cancel(); | 319 poll_for_draw_triggers_closure_.Cancel(); |
| 317 state_machine_.DidEnterPollForAnticipatedDrawTriggers(); | 320 state_machine_.DidEnterPollForAnticipatedDrawTriggers(); |
| 318 ProcessScheduledActions(); | 321 ProcessScheduledActions(); |
| 319 state_machine_.DidLeavePollForAnticipatedDrawTriggers(); | 322 state_machine_.DidLeavePollForAnticipatedDrawTriggers(); |
| 320 } | 323 } |
| 321 | 324 |
| 325 void Scheduler::PollToAdvanceCommitState() { |
| 326 TRACE_EVENT0("cc", "Scheduler::PollToAdvanceCommitState"); |
| 327 advance_commit_state_closure_.Cancel(); |
| 328 ProcessScheduledActions(); |
| 329 } |
| 330 |
| 322 bool Scheduler::IsBeginMainFrameSent() const { | 331 bool Scheduler::IsBeginMainFrameSent() const { |
| 323 return state_machine_.commit_state() == | 332 return state_machine_.commit_state() == |
| 324 SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT; | 333 SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT; |
| 325 } | 334 } |
| 326 | 335 |
| 327 void Scheduler::DrawAndSwapIfPossible() { | 336 void Scheduler::DrawAndSwapIfPossible() { |
| 328 DrawSwapReadbackResult result = | 337 DrawSwapReadbackResult result = |
| 329 client_->ScheduledActionDrawAndSwapIfPossible(); | 338 client_->ScheduledActionDrawAndSwapIfPossible(); |
| 330 state_machine_.DidDrawIfPossibleCompleted(result.draw_result); | 339 state_machine_.DidDrawIfPossibleCompleted(result.draw_result); |
| 331 } | 340 } |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 419 scheduler_state->SetDouble( | 428 scheduler_state->SetDouble( |
| 420 "time_until_anticipated_draw_time_ms", | 429 "time_until_anticipated_draw_time_ms", |
| 421 (AnticipatedDrawTime() - base::TimeTicks::Now()).InMillisecondsF()); | 430 (AnticipatedDrawTime() - base::TimeTicks::Now()).InMillisecondsF()); |
| 422 scheduler_state->SetBoolean("last_set_needs_begin_impl_frame_", | 431 scheduler_state->SetBoolean("last_set_needs_begin_impl_frame_", |
| 423 last_set_needs_begin_impl_frame_); | 432 last_set_needs_begin_impl_frame_); |
| 424 scheduler_state->SetBoolean( | 433 scheduler_state->SetBoolean( |
| 425 "begin_impl_frame_deadline_closure_", | 434 "begin_impl_frame_deadline_closure_", |
| 426 !begin_impl_frame_deadline_closure_.IsCancelled()); | 435 !begin_impl_frame_deadline_closure_.IsCancelled()); |
| 427 scheduler_state->SetBoolean("poll_for_draw_triggers_closure_", | 436 scheduler_state->SetBoolean("poll_for_draw_triggers_closure_", |
| 428 !poll_for_draw_triggers_closure_.IsCancelled()); | 437 !poll_for_draw_triggers_closure_.IsCancelled()); |
| 429 scheduler_state->SetBoolean("advance_commit_state_timer_", | 438 scheduler_state->SetBoolean("advance_commit_state_closure_", |
| 430 advance_commit_state_timer_.IsRunning()); | 439 !advance_commit_state_closure_.IsCancelled()); |
| 431 state->Set("scheduler_state", scheduler_state.release()); | 440 state->Set("scheduler_state", scheduler_state.release()); |
| 432 | 441 |
| 433 scoped_ptr<base::DictionaryValue> client_state(new base::DictionaryValue); | 442 scoped_ptr<base::DictionaryValue> client_state(new base::DictionaryValue); |
| 434 client_state->SetDouble("draw_duration_estimate_ms", | 443 client_state->SetDouble("draw_duration_estimate_ms", |
| 435 client_->DrawDurationEstimate().InMillisecondsF()); | 444 client_->DrawDurationEstimate().InMillisecondsF()); |
| 436 client_state->SetDouble( | 445 client_state->SetDouble( |
| 437 "begin_main_frame_to_commit_duration_estimate_ms", | 446 "begin_main_frame_to_commit_duration_estimate_ms", |
| 438 client_->BeginMainFrameToCommitDurationEstimate().InMillisecondsF()); | 447 client_->BeginMainFrameToCommitDurationEstimate().InMillisecondsF()); |
| 439 client_state->SetDouble( | 448 client_state->SetDouble( |
| 440 "commit_to_activate_duration_estimate_ms", | 449 "commit_to_activate_duration_estimate_ms", |
| (...skipping 22 matching lines...) Expand all Loading... |
| 463 } | 472 } |
| 464 | 473 |
| 465 bool Scheduler::IsBeginMainFrameSentOrStarted() const { | 474 bool Scheduler::IsBeginMainFrameSentOrStarted() const { |
| 466 return (state_machine_.commit_state() == | 475 return (state_machine_.commit_state() == |
| 467 SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT || | 476 SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT || |
| 468 state_machine_.commit_state() == | 477 state_machine_.commit_state() == |
| 469 SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_STARTED); | 478 SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_STARTED); |
| 470 } | 479 } |
| 471 | 480 |
| 472 } // namespace cc | 481 } // namespace cc |
| OLD | NEW |