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 | 8 |
9 #include "base/auto_reset.h" | 9 #include "base/auto_reset.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 SchedulerStateMachine::BEGIN_IMPL_FRAME_DEADLINE_MODE_NONE), | 57 SchedulerStateMachine::BEGIN_IMPL_FRAME_DEADLINE_MODE_NONE), |
58 begin_impl_frame_tracker_(BEGINFRAMETRACKER_FROM_HERE), | 58 begin_impl_frame_tracker_(BEGINFRAMETRACKER_FROM_HERE), |
59 state_machine_(settings), | 59 state_machine_(settings), |
60 inside_process_scheduled_actions_(false), | 60 inside_process_scheduled_actions_(false), |
61 inside_action_(SchedulerStateMachine::ACTION_NONE), | 61 inside_action_(SchedulerStateMachine::ACTION_NONE), |
62 weak_factory_(this) { | 62 weak_factory_(this) { |
63 TRACE_EVENT1("cc", "Scheduler::Scheduler", "settings", settings_.AsValue()); | 63 TRACE_EVENT1("cc", "Scheduler::Scheduler", "settings", settings_.AsValue()); |
64 DCHECK(client_); | 64 DCHECK(client_); |
65 DCHECK(!state_machine_.BeginFrameNeeded()); | 65 DCHECK(!state_machine_.BeginFrameNeeded()); |
66 | 66 |
| 67 begin_retro_frame_closure_ = |
| 68 base::Bind(&Scheduler::BeginRetroFrame, weak_factory_.GetWeakPtr()); |
67 begin_impl_frame_deadline_closure_ = base::Bind( | 69 begin_impl_frame_deadline_closure_ = base::Bind( |
68 &Scheduler::OnBeginImplFrameDeadline, weak_factory_.GetWeakPtr()); | 70 &Scheduler::OnBeginImplFrameDeadline, weak_factory_.GetWeakPtr()); |
69 | 71 |
70 SetBeginFrameSource(begin_frame_source); | 72 SetBeginFrameSource(begin_frame_source); |
71 ProcessScheduledActions(); | 73 ProcessScheduledActions(); |
72 } | 74 } |
73 | 75 |
74 Scheduler::~Scheduler() { | 76 Scheduler::~Scheduler() { |
75 SetBeginFrameSource(nullptr); | 77 SetBeginFrameSource(nullptr); |
76 } | 78 } |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 compositor_timing_history_->WillPrepareTiles(); | 193 compositor_timing_history_->WillPrepareTiles(); |
192 } | 194 } |
193 | 195 |
194 void Scheduler::DidPrepareTiles() { | 196 void Scheduler::DidPrepareTiles() { |
195 compositor_timing_history_->DidPrepareTiles(); | 197 compositor_timing_history_->DidPrepareTiles(); |
196 state_machine_.DidPrepareTiles(); | 198 state_machine_.DidPrepareTiles(); |
197 } | 199 } |
198 | 200 |
199 void Scheduler::DidLoseOutputSurface() { | 201 void Scheduler::DidLoseOutputSurface() { |
200 TRACE_EVENT0("cc", "Scheduler::DidLoseOutputSurface"); | 202 TRACE_EVENT0("cc", "Scheduler::DidLoseOutputSurface"); |
| 203 begin_retro_frame_args_.clear(); |
| 204 begin_retro_frame_task_.Cancel(); |
201 state_machine_.DidLoseOutputSurface(); | 205 state_machine_.DidLoseOutputSurface(); |
202 UpdateCompositorTimingHistoryRecordingEnabled(); | 206 UpdateCompositorTimingHistoryRecordingEnabled(); |
203 ProcessScheduledActions(); | 207 ProcessScheduledActions(); |
204 } | 208 } |
205 | 209 |
206 void Scheduler::DidCreateAndInitializeOutputSurface() { | 210 void Scheduler::DidCreateAndInitializeOutputSurface() { |
207 TRACE_EVENT0("cc", "Scheduler::DidCreateAndInitializeOutputSurface"); | 211 TRACE_EVENT0("cc", "Scheduler::DidCreateAndInitializeOutputSurface"); |
208 DCHECK(!observing_begin_frame_source_); | 212 DCHECK(!observing_begin_frame_source_); |
209 DCHECK(begin_impl_frame_deadline_task_.IsCancelled()); | 213 DCHECK(begin_impl_frame_deadline_task_.IsCancelled()); |
210 state_machine_.DidCreateAndInitializeOutputSurface(); | 214 state_machine_.DidCreateAndInitializeOutputSurface(); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
243 if (begin_frame_source_) | 247 if (begin_frame_source_) |
244 begin_frame_source_->AddObserver(this); | 248 begin_frame_source_->AddObserver(this); |
245 devtools_instrumentation::NeedsBeginFrameChanged(layer_tree_host_id_, | 249 devtools_instrumentation::NeedsBeginFrameChanged(layer_tree_host_id_, |
246 true); | 250 true); |
247 } else if (state_machine_.begin_impl_frame_state() == | 251 } else if (state_machine_.begin_impl_frame_state() == |
248 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE) { | 252 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE) { |
249 // Call RemoveObserver in between frames only. | 253 // Call RemoveObserver in between frames only. |
250 observing_begin_frame_source_ = false; | 254 observing_begin_frame_source_ = false; |
251 if (begin_frame_source_) | 255 if (begin_frame_source_) |
252 begin_frame_source_->RemoveObserver(this); | 256 begin_frame_source_->RemoveObserver(this); |
253 missed_begin_frame_task_.Cancel(); | |
254 BeginImplFrameNotExpectedSoon(); | 257 BeginImplFrameNotExpectedSoon(); |
255 devtools_instrumentation::NeedsBeginFrameChanged(layer_tree_host_id_, | 258 devtools_instrumentation::NeedsBeginFrameChanged(layer_tree_host_id_, |
256 false); | 259 false); |
257 } | 260 } |
258 } | 261 } |
| 262 |
| 263 PostBeginRetroFrameIfNeeded(); |
259 } | 264 } |
260 | 265 |
261 void Scheduler::OnBeginFrameSourcePausedChanged(bool paused) { | 266 void Scheduler::OnBeginFrameSourcePausedChanged(bool paused) { |
262 if (state_machine_.begin_frame_source_paused() == paused) | 267 if (state_machine_.begin_frame_source_paused() == paused) |
263 return; | 268 return; |
264 TRACE_EVENT_INSTANT1("cc", "Scheduler::SetBeginFrameSourcePaused", | 269 TRACE_EVENT_INSTANT1("cc", "Scheduler::SetBeginFrameSourcePaused", |
265 TRACE_EVENT_SCOPE_THREAD, "paused", paused); | 270 TRACE_EVENT_SCOPE_THREAD, "paused", paused); |
266 state_machine_.SetBeginFrameSourcePaused(paused); | 271 state_machine_.SetBeginFrameSourcePaused(paused); |
267 ProcessScheduledActions(); | 272 ProcessScheduledActions(); |
268 } | 273 } |
269 | 274 |
270 // BeginFrame is the mechanism that tells us that now is a good time to start | 275 // BeginFrame is the mechanism that tells us that now is a good time to start |
271 // making a frame. Usually this means that user input for the frame is complete. | 276 // making a frame. Usually this means that user input for the frame is complete. |
272 // If the scheduler is busy, we queue the BeginFrame to be handled later as | 277 // If the scheduler is busy, we queue the BeginFrame to be handled later as |
273 // a BeginRetroFrame. | 278 // a BeginRetroFrame. |
274 bool Scheduler::OnBeginFrameDerivedImpl(const BeginFrameArgs& args) { | 279 bool Scheduler::OnBeginFrameDerivedImpl(const BeginFrameArgs& args) { |
275 TRACE_EVENT1("cc,benchmark", "Scheduler::BeginFrame", "args", args.AsValue()); | 280 TRACE_EVENT1("cc,benchmark", "Scheduler::BeginFrame", "args", args.AsValue()); |
276 | 281 |
277 if (!state_machine_.BeginFrameNeeded()) { | |
278 TRACE_EVENT_INSTANT0("cc", "Scheduler::BeginFrameDropped", | |
279 TRACE_EVENT_SCOPE_THREAD); | |
280 return false; | |
281 } | |
282 | |
283 // Trace this begin frame time through the Chrome stack | 282 // Trace this begin frame time through the Chrome stack |
284 TRACE_EVENT_FLOW_BEGIN0( | 283 TRACE_EVENT_FLOW_BEGIN0( |
285 TRACE_DISABLED_BY_DEFAULT("cc.debug.scheduler.frames"), "BeginFrameArgs", | 284 TRACE_DISABLED_BY_DEFAULT("cc.debug.scheduler.frames"), "BeginFrameArgs", |
286 args.frame_time.ToInternalValue()); | 285 args.frame_time.ToInternalValue()); |
287 | 286 |
288 // TODO(brianderson): Adjust deadline in the DisplayScheduler. | 287 // TODO(brianderson): Adjust deadline in the DisplayScheduler. |
289 BeginFrameArgs adjusted_args(args); | 288 BeginFrameArgs adjusted_args(args); |
290 adjusted_args.deadline -= EstimatedParentDrawTime(); | 289 adjusted_args.deadline -= EstimatedParentDrawTime(); |
291 | 290 |
292 if (settings_.using_synchronous_renderer_compositor) { | 291 if (settings_.using_synchronous_renderer_compositor) { |
293 BeginImplFrameSynchronous(adjusted_args); | 292 BeginImplFrameSynchronous(adjusted_args); |
294 return true; | 293 return true; |
295 } | 294 } |
296 | 295 |
297 // We have just called SetNeedsBeginFrame(true) and the BeginFrameSource has | 296 // We have just called SetNeedsBeginFrame(true) and the BeginFrameSource has |
298 // sent us the last BeginFrame we have missed. As we might not be able to | 297 // sent us the last BeginFrame we have missed. As we might not be able to |
299 // actually make rendering for this call, handle it like a "retro frame". | 298 // actually make rendering for this call, handle it like a "retro frame". |
300 // TODO(brainderson): Add a test for this functionality ASAP! | 299 // TODO(brainderson): Add a test for this functionality ASAP! |
301 if (adjusted_args.type == BeginFrameArgs::MISSED) { | 300 if (adjusted_args.type == BeginFrameArgs::MISSED) { |
302 DCHECK(missed_begin_frame_task_.IsCancelled()); | 301 begin_retro_frame_args_.push_back(adjusted_args); |
303 missed_begin_frame_task_.Reset( | 302 PostBeginRetroFrameIfNeeded(); |
304 base::Bind(&Scheduler::BeginImplFrameWithDeadline, | |
305 base::Unretained(this), adjusted_args)); | |
306 task_runner_->PostTask(FROM_HERE, missed_begin_frame_task_.callback()); | |
307 return true; | 303 return true; |
308 } | 304 } |
309 | 305 |
310 BeginImplFrameWithDeadline(adjusted_args); | 306 bool should_defer_begin_frame = |
| 307 !begin_retro_frame_args_.empty() || |
| 308 !begin_retro_frame_task_.IsCancelled() || |
| 309 !observing_begin_frame_source_ || |
| 310 (state_machine_.begin_impl_frame_state() != |
| 311 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE); |
| 312 |
| 313 if (should_defer_begin_frame) { |
| 314 begin_retro_frame_args_.push_back(adjusted_args); |
| 315 TRACE_EVENT_INSTANT0("cc", "Scheduler::BeginFrame deferred", |
| 316 TRACE_EVENT_SCOPE_THREAD); |
| 317 // Queuing the frame counts as "using it", so we need to return true. |
| 318 } else { |
| 319 BeginImplFrameWithDeadline(adjusted_args); |
| 320 } |
311 return true; | 321 return true; |
312 } | 322 } |
313 | 323 |
314 void Scheduler::SetVideoNeedsBeginFrames(bool video_needs_begin_frames) { | 324 void Scheduler::SetVideoNeedsBeginFrames(bool video_needs_begin_frames) { |
315 state_machine_.SetVideoNeedsBeginFrames(video_needs_begin_frames); | 325 state_machine_.SetVideoNeedsBeginFrames(video_needs_begin_frames); |
316 ProcessScheduledActions(); | 326 ProcessScheduledActions(); |
317 } | 327 } |
318 | 328 |
319 void Scheduler::OnDrawForOutputSurface(bool resourceless_software_draw) { | 329 void Scheduler::OnDrawForOutputSurface(bool resourceless_software_draw) { |
320 DCHECK(settings_.using_synchronous_renderer_compositor); | 330 DCHECK(settings_.using_synchronous_renderer_compositor); |
321 DCHECK_EQ(state_machine_.begin_impl_frame_state(), | 331 DCHECK_EQ(state_machine_.begin_impl_frame_state(), |
322 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE); | 332 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE); |
323 DCHECK(begin_impl_frame_deadline_task_.IsCancelled()); | 333 DCHECK(begin_impl_frame_deadline_task_.IsCancelled()); |
324 | 334 |
325 state_machine_.SetResourcelessSoftwareDraw(resourceless_software_draw); | 335 state_machine_.SetResourcelessSoftwareDraw(resourceless_software_draw); |
326 state_machine_.OnBeginImplFrameDeadline(); | 336 state_machine_.OnBeginImplFrameDeadline(); |
327 ProcessScheduledActions(); | 337 ProcessScheduledActions(); |
328 | 338 |
329 state_machine_.OnBeginImplFrameIdle(); | 339 state_machine_.OnBeginImplFrameIdle(); |
330 ProcessScheduledActions(); | 340 ProcessScheduledActions(); |
331 state_machine_.SetResourcelessSoftwareDraw(false); | 341 state_machine_.SetResourcelessSoftwareDraw(false); |
332 } | 342 } |
333 | 343 |
| 344 // BeginRetroFrame is called for BeginFrames that we've deferred because |
| 345 // the scheduler was in the middle of processing a previous BeginFrame. |
| 346 void Scheduler::BeginRetroFrame() { |
| 347 TRACE_EVENT0("cc,benchmark", "Scheduler::BeginRetroFrame"); |
| 348 DCHECK(!settings_.using_synchronous_renderer_compositor); |
| 349 DCHECK(!begin_retro_frame_args_.empty()); |
| 350 DCHECK(!begin_retro_frame_task_.IsCancelled()); |
| 351 DCHECK_EQ(state_machine_.begin_impl_frame_state(), |
| 352 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE); |
| 353 |
| 354 begin_retro_frame_task_.Cancel(); |
| 355 |
| 356 // Discard expired BeginRetroFrames |
| 357 // Today, we should always end up with at most one un-expired BeginRetroFrame |
| 358 // because deadlines will not be greater than the next frame time. We don't |
| 359 // DCHECK though because some systems don't always have monotonic timestamps. |
| 360 // TODO(brianderson): In the future, long deadlines could result in us not |
| 361 // draining the queue if we don't catch up. If we consistently can't catch |
| 362 // up, our fallback should be to lower our frame rate. |
| 363 base::TimeTicks now = Now(); |
| 364 |
| 365 while (!begin_retro_frame_args_.empty()) { |
| 366 const BeginFrameArgs& args = begin_retro_frame_args_.front(); |
| 367 base::TimeTicks expiration_time = args.deadline; |
| 368 if (now <= expiration_time) |
| 369 break; |
| 370 TRACE_EVENT_INSTANT2( |
| 371 "cc", "Scheduler::BeginRetroFrame discarding", TRACE_EVENT_SCOPE_THREAD, |
| 372 "expiration_time - now", (expiration_time - now).InMillisecondsF(), |
| 373 "BeginFrameArgs", begin_retro_frame_args_.front().AsValue()); |
| 374 begin_retro_frame_args_.pop_front(); |
| 375 if (begin_frame_source_) |
| 376 begin_frame_source_->DidFinishFrame(this, begin_retro_frame_args_.size()); |
| 377 } |
| 378 |
| 379 if (begin_retro_frame_args_.empty()) { |
| 380 TRACE_EVENT_INSTANT0("cc", "Scheduler::BeginRetroFrames all expired", |
| 381 TRACE_EVENT_SCOPE_THREAD); |
| 382 } else { |
| 383 BeginFrameArgs front = begin_retro_frame_args_.front(); |
| 384 begin_retro_frame_args_.pop_front(); |
| 385 BeginImplFrameWithDeadline(front); |
| 386 } |
| 387 } |
| 388 |
| 389 // There could be a race between the posted BeginRetroFrame and a new |
| 390 // BeginFrame arriving via the normal mechanism. Scheduler::BeginFrame |
| 391 // will check if there is a pending BeginRetroFrame to ensure we handle |
| 392 // BeginFrames in FIFO order. |
| 393 void Scheduler::PostBeginRetroFrameIfNeeded() { |
| 394 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("cc.debug.scheduler"), |
| 395 "Scheduler::PostBeginRetroFrameIfNeeded", "state", AsValue()); |
| 396 if (!observing_begin_frame_source_) |
| 397 return; |
| 398 |
| 399 if (begin_retro_frame_args_.empty() || !begin_retro_frame_task_.IsCancelled()) |
| 400 return; |
| 401 |
| 402 // begin_retro_frame_args_ should always be empty for the |
| 403 // synchronous compositor. |
| 404 DCHECK(!settings_.using_synchronous_renderer_compositor); |
| 405 |
| 406 if (state_machine_.begin_impl_frame_state() != |
| 407 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE) |
| 408 return; |
| 409 |
| 410 begin_retro_frame_task_.Reset(begin_retro_frame_closure_); |
| 411 |
| 412 task_runner_->PostTask(FROM_HERE, begin_retro_frame_task_.callback()); |
| 413 } |
| 414 |
334 void Scheduler::BeginImplFrameWithDeadline(const BeginFrameArgs& args) { | 415 void Scheduler::BeginImplFrameWithDeadline(const BeginFrameArgs& args) { |
335 bool main_thread_is_in_high_latency_mode = | 416 bool main_thread_is_in_high_latency_mode = |
336 state_machine_.main_thread_missed_last_deadline(); | 417 state_machine_.main_thread_missed_last_deadline(); |
337 TRACE_EVENT2("cc,benchmark", "Scheduler::BeginImplFrame", "args", | 418 TRACE_EVENT2("cc,benchmark", "Scheduler::BeginImplFrame", "args", |
338 args.AsValue(), "main_thread_missed_last_deadline", | 419 args.AsValue(), "main_thread_missed_last_deadline", |
339 main_thread_is_in_high_latency_mode); | 420 main_thread_is_in_high_latency_mode); |
340 TRACE_COUNTER1(TRACE_DISABLED_BY_DEFAULT("cc.debug.scheduler"), | 421 TRACE_COUNTER1(TRACE_DISABLED_BY_DEFAULT("cc.debug.scheduler"), |
341 "MainThreadLatency", main_thread_is_in_high_latency_mode); | 422 "MainThreadLatency", main_thread_is_in_high_latency_mode); |
342 | 423 |
343 if (state_machine_.begin_impl_frame_state() == | |
344 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_BEGIN_FRAME) { | |
345 OnBeginImplFrameDeadline(); | |
346 } | |
347 | |
348 DCHECK_EQ(state_machine_.begin_impl_frame_state(), | |
349 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE); | |
350 | |
351 BeginFrameArgs adjusted_args = args; | 424 BeginFrameArgs adjusted_args = args; |
352 | |
353 // Cancel the missed begin frame task in case the BFS sends a normal begin | |
354 // frame before the missed frame task runs. This should be done after |args| | |
355 // is copied because destroying the task also destroys the storage for |args|. | |
356 missed_begin_frame_task_.Cancel(); | |
357 | |
358 adjusted_args.deadline -= compositor_timing_history_->DrawDurationEstimate(); | 425 adjusted_args.deadline -= compositor_timing_history_->DrawDurationEstimate(); |
359 adjusted_args.deadline -= kDeadlineFudgeFactor; | 426 adjusted_args.deadline -= kDeadlineFudgeFactor; |
360 | 427 |
361 base::TimeDelta bmf_start_to_activate = | 428 base::TimeDelta bmf_start_to_activate = |
362 compositor_timing_history_ | 429 compositor_timing_history_ |
363 ->BeginMainFrameStartToCommitDurationEstimate() + | 430 ->BeginMainFrameStartToCommitDurationEstimate() + |
364 compositor_timing_history_->CommitToReadyToActivateDurationEstimate() + | 431 compositor_timing_history_->CommitToReadyToActivateDurationEstimate() + |
365 compositor_timing_history_->ActivateDurationEstimate(); | 432 compositor_timing_history_->ActivateDurationEstimate(); |
366 | 433 |
367 base::TimeDelta bmf_to_activate_estimate_critical = | 434 base::TimeDelta bmf_to_activate_estimate_critical = |
368 bmf_start_to_activate + | 435 bmf_start_to_activate + |
369 compositor_timing_history_->BeginMainFrameQueueDurationCriticalEstimate(); | 436 compositor_timing_history_->BeginMainFrameQueueDurationCriticalEstimate(); |
370 | 437 |
371 state_machine_.SetCriticalBeginMainFrameToActivateIsFast( | 438 state_machine_.SetCriticalBeginMainFrameToActivateIsFast( |
372 bmf_to_activate_estimate_critical < adjusted_args.interval); | 439 bmf_to_activate_estimate_critical < args.interval); |
373 | 440 |
374 // Update the BeginMainFrame args now that we know whether the main | 441 // Update the BeginMainFrame args now that we know whether the main |
375 // thread will be on the critical path or not. | 442 // thread will be on the critical path or not. |
376 begin_main_frame_args_ = adjusted_args; | 443 begin_main_frame_args_ = adjusted_args; |
377 begin_main_frame_args_.on_critical_path = !ImplLatencyTakesPriority(); | 444 begin_main_frame_args_.on_critical_path = !ImplLatencyTakesPriority(); |
378 | 445 |
379 base::TimeDelta bmf_to_activate_estimate = bmf_to_activate_estimate_critical; | 446 base::TimeDelta bmf_to_activate_estimate = bmf_to_activate_estimate_critical; |
380 if (!begin_main_frame_args_.on_critical_path) { | 447 if (!begin_main_frame_args_.on_critical_path) { |
381 bmf_to_activate_estimate = | 448 bmf_to_activate_estimate = |
382 bmf_start_to_activate + | 449 bmf_start_to_activate + |
383 compositor_timing_history_ | 450 compositor_timing_history_ |
384 ->BeginMainFrameQueueDurationNotCriticalEstimate(); | 451 ->BeginMainFrameQueueDurationNotCriticalEstimate(); |
385 } | 452 } |
386 | 453 |
387 bool can_activate_before_deadline = | 454 bool can_activate_before_deadline = |
388 CanBeginMainFrameAndActivateBeforeDeadline(adjusted_args, | 455 CanBeginMainFrameAndActivateBeforeDeadline(adjusted_args, |
389 bmf_to_activate_estimate); | 456 bmf_to_activate_estimate); |
390 | 457 |
391 if (ShouldRecoverMainLatency(adjusted_args, can_activate_before_deadline)) { | 458 if (ShouldRecoverMainLatency(adjusted_args, can_activate_before_deadline)) { |
392 TRACE_EVENT_INSTANT0("cc", "SkipBeginMainFrameToReduceLatency", | 459 TRACE_EVENT_INSTANT0("cc", "SkipBeginMainFrameToReduceLatency", |
393 TRACE_EVENT_SCOPE_THREAD); | 460 TRACE_EVENT_SCOPE_THREAD); |
394 state_machine_.SetSkipNextBeginMainFrameToReduceLatency(); | 461 state_machine_.SetSkipNextBeginMainFrameToReduceLatency(); |
395 } else if (ShouldRecoverImplLatency(adjusted_args, | 462 } else if (ShouldRecoverImplLatency(adjusted_args, |
396 can_activate_before_deadline)) { | 463 can_activate_before_deadline)) { |
397 TRACE_EVENT_INSTANT0("cc", "SkipBeginImplFrameToReduceLatency", | 464 TRACE_EVENT_INSTANT0("cc", "SkipBeginImplFrameToReduceLatency", |
398 TRACE_EVENT_SCOPE_THREAD); | 465 TRACE_EVENT_SCOPE_THREAD); |
399 if (begin_frame_source_) | 466 if (begin_frame_source_) |
400 begin_frame_source_->DidFinishFrame(this, 0); | 467 begin_frame_source_->DidFinishFrame(this, begin_retro_frame_args_.size()); |
401 return; | 468 return; |
402 } | 469 } |
403 | 470 |
404 BeginImplFrame(adjusted_args); | 471 BeginImplFrame(adjusted_args); |
405 } | 472 } |
406 | 473 |
407 void Scheduler::BeginImplFrameSynchronous(const BeginFrameArgs& args) { | 474 void Scheduler::BeginImplFrameSynchronous(const BeginFrameArgs& args) { |
408 TRACE_EVENT1("cc,benchmark", "Scheduler::BeginImplFrame", "args", | 475 TRACE_EVENT1("cc,benchmark", "Scheduler::BeginImplFrame", "args", |
409 args.AsValue()); | 476 args.AsValue()); |
410 | 477 |
411 // The main thread currently can't commit before we draw with the | 478 // The main thread currently can't commit before we draw with the |
412 // synchronous compositor, so never consider the BeginMainFrame fast. | 479 // synchronous compositor, so never consider the BeginMainFrame fast. |
413 state_machine_.SetCriticalBeginMainFrameToActivateIsFast(false); | 480 state_machine_.SetCriticalBeginMainFrameToActivateIsFast(false); |
414 begin_main_frame_args_ = args; | 481 begin_main_frame_args_ = args; |
415 begin_main_frame_args_.on_critical_path = !ImplLatencyTakesPriority(); | 482 begin_main_frame_args_.on_critical_path = !ImplLatencyTakesPriority(); |
416 | 483 |
417 BeginImplFrame(args); | 484 BeginImplFrame(args); |
418 compositor_timing_history_->WillFinishImplFrame( | 485 compositor_timing_history_->WillFinishImplFrame( |
419 state_machine_.needs_redraw()); | 486 state_machine_.needs_redraw()); |
420 FinishImplFrame(); | 487 FinishImplFrame(); |
421 } | 488 } |
422 | 489 |
423 void Scheduler::FinishImplFrame() { | 490 void Scheduler::FinishImplFrame() { |
424 state_machine_.OnBeginImplFrameIdle(); | 491 state_machine_.OnBeginImplFrameIdle(); |
425 ProcessScheduledActions(); | 492 ProcessScheduledActions(); |
426 | 493 |
427 client_->DidFinishImplFrame(); | 494 client_->DidFinishImplFrame(); |
428 if (begin_frame_source_) | 495 if (begin_frame_source_) |
429 begin_frame_source_->DidFinishFrame(this, 0); | 496 begin_frame_source_->DidFinishFrame(this, begin_retro_frame_args_.size()); |
430 begin_impl_frame_tracker_.Finish(); | 497 begin_impl_frame_tracker_.Finish(); |
431 } | 498 } |
432 | 499 |
433 // BeginImplFrame starts a compositor frame that will wait up until a deadline | 500 // BeginImplFrame starts a compositor frame that will wait up until a deadline |
434 // for a BeginMainFrame+activation to complete before it times out and draws | 501 // for a BeginMainFrame+activation to complete before it times out and draws |
435 // any asynchronous animation and scroll/pinch updates. | 502 // any asynchronous animation and scroll/pinch updates. |
436 void Scheduler::BeginImplFrame(const BeginFrameArgs& args) { | 503 void Scheduler::BeginImplFrame(const BeginFrameArgs& args) { |
437 DCHECK_EQ(state_machine_.begin_impl_frame_state(), | 504 DCHECK_EQ(state_machine_.begin_impl_frame_state(), |
438 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE); | 505 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE); |
439 DCHECK(begin_impl_frame_deadline_task_.IsCancelled()); | 506 DCHECK(begin_impl_frame_deadline_task_.IsCancelled()); |
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
648 state_machine_.AsValueInto(state.get()); | 715 state_machine_.AsValueInto(state.get()); |
649 state->EndDictionary(); | 716 state->EndDictionary(); |
650 | 717 |
651 state->BeginDictionary("scheduler_state"); | 718 state->BeginDictionary("scheduler_state"); |
652 state->SetBoolean("throttle_frame_production_", | 719 state->SetBoolean("throttle_frame_production_", |
653 settings_.throttle_frame_production); | 720 settings_.throttle_frame_production); |
654 state->SetDouble("estimated_parent_draw_time_ms", | 721 state->SetDouble("estimated_parent_draw_time_ms", |
655 estimated_parent_draw_time_.InMillisecondsF()); | 722 estimated_parent_draw_time_.InMillisecondsF()); |
656 state->SetBoolean("observing_begin_frame_source", | 723 state->SetBoolean("observing_begin_frame_source", |
657 observing_begin_frame_source_); | 724 observing_begin_frame_source_); |
| 725 state->SetInteger("begin_retro_frame_args", |
| 726 static_cast<int>(begin_retro_frame_args_.size())); |
| 727 state->SetBoolean("begin_retro_frame_task", |
| 728 !begin_retro_frame_task_.IsCancelled()); |
658 state->SetBoolean("begin_impl_frame_deadline_task", | 729 state->SetBoolean("begin_impl_frame_deadline_task", |
659 !begin_impl_frame_deadline_task_.IsCancelled()); | 730 !begin_impl_frame_deadline_task_.IsCancelled()); |
660 state->SetBoolean("missed_begin_frame_task", | |
661 !missed_begin_frame_task_.IsCancelled()); | |
662 state->SetString("inside_action", | 731 state->SetString("inside_action", |
663 SchedulerStateMachine::ActionToString(inside_action_)); | 732 SchedulerStateMachine::ActionToString(inside_action_)); |
664 | 733 |
665 state->BeginDictionary("begin_impl_frame_args"); | 734 state->BeginDictionary("begin_impl_frame_args"); |
666 begin_impl_frame_tracker_.AsValueInto(now, state.get()); | 735 begin_impl_frame_tracker_.AsValueInto(now, state.get()); |
667 state->EndDictionary(); | 736 state->EndDictionary(); |
668 | 737 |
669 state->SetString("begin_impl_frame_deadline_mode_", | 738 state->SetString("begin_impl_frame_deadline_mode_", |
670 SchedulerStateMachine::BeginImplFrameDeadlineModeToString( | 739 SchedulerStateMachine::BeginImplFrameDeadlineModeToString( |
671 begin_impl_frame_deadline_mode_)); | 740 begin_impl_frame_deadline_mode_)); |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
749 } | 818 } |
750 | 819 |
751 bool Scheduler::IsBeginMainFrameSentOrStarted() const { | 820 bool Scheduler::IsBeginMainFrameSentOrStarted() const { |
752 return (state_machine_.begin_main_frame_state() == | 821 return (state_machine_.begin_main_frame_state() == |
753 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_SENT || | 822 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_SENT || |
754 state_machine_.begin_main_frame_state() == | 823 state_machine_.begin_main_frame_state() == |
755 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_STARTED); | 824 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_STARTED); |
756 } | 825 } |
757 | 826 |
758 } // namespace cc | 827 } // namespace cc |
OLD | NEW |