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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 SetBeginFrameSource(nullptr); | 77 SetBeginFrameSource(nullptr); |
78 } | 78 } |
79 | 79 |
80 base::TimeTicks Scheduler::Now() const { | 80 base::TimeTicks Scheduler::Now() const { |
81 base::TimeTicks now = base::TimeTicks::Now(); | 81 base::TimeTicks now = base::TimeTicks::Now(); |
82 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("cc.debug.scheduler.now"), | 82 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("cc.debug.scheduler.now"), |
83 "Scheduler::Now", "now", now); | 83 "Scheduler::Now", "now", now); |
84 return now; | 84 return now; |
85 } | 85 } |
86 | 86 |
87 void Scheduler::SetEstimatedParentDrawTime(base::TimeDelta draw_time) { | |
88 DCHECK_GE(draw_time.ToInternalValue(), 0); | |
89 estimated_parent_draw_time_ = draw_time; | |
90 } | |
91 | |
92 void Scheduler::SetVisible(bool visible) { | 87 void Scheduler::SetVisible(bool visible) { |
93 state_machine_.SetVisible(visible); | 88 state_machine_.SetVisible(visible); |
94 UpdateCompositorTimingHistoryRecordingEnabled(); | 89 UpdateCompositorTimingHistoryRecordingEnabled(); |
95 ProcessScheduledActions(); | 90 ProcessScheduledActions(); |
96 } | 91 } |
97 | 92 |
98 void Scheduler::SetCanDraw(bool can_draw) { | 93 void Scheduler::SetCanDraw(bool can_draw) { |
99 state_machine_.SetCanDraw(can_draw); | 94 state_machine_.SetCanDraw(can_draw); |
100 ProcessScheduledActions(); | 95 ProcessScheduledActions(); |
101 } | 96 } |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
277 // If the scheduler is busy, we queue the BeginFrame to be handled later as | 272 // If the scheduler is busy, we queue the BeginFrame to be handled later as |
278 // a BeginRetroFrame. | 273 // a BeginRetroFrame. |
279 bool Scheduler::OnBeginFrameDerivedImpl(const BeginFrameArgs& args) { | 274 bool Scheduler::OnBeginFrameDerivedImpl(const BeginFrameArgs& args) { |
280 TRACE_EVENT1("cc,benchmark", "Scheduler::BeginFrame", "args", args.AsValue()); | 275 TRACE_EVENT1("cc,benchmark", "Scheduler::BeginFrame", "args", args.AsValue()); |
281 | 276 |
282 // Trace this begin frame time through the Chrome stack | 277 // Trace this begin frame time through the Chrome stack |
283 TRACE_EVENT_FLOW_BEGIN0( | 278 TRACE_EVENT_FLOW_BEGIN0( |
284 TRACE_DISABLED_BY_DEFAULT("cc.debug.scheduler.frames"), "BeginFrameArgs", | 279 TRACE_DISABLED_BY_DEFAULT("cc.debug.scheduler.frames"), "BeginFrameArgs", |
285 args.frame_time.ToInternalValue()); | 280 args.frame_time.ToInternalValue()); |
286 | 281 |
287 // TODO(brianderson): Adjust deadline in the DisplayScheduler. | |
288 BeginFrameArgs adjusted_args(args); | |
289 adjusted_args.deadline -= EstimatedParentDrawTime(); | |
290 | |
291 if (settings_.using_synchronous_renderer_compositor) { | 282 if (settings_.using_synchronous_renderer_compositor) { |
292 BeginImplFrameSynchronous(adjusted_args); | 283 BeginImplFrameSynchronous(args); |
293 return true; | 284 return true; |
294 } | 285 } |
295 | 286 |
296 // We have just called SetNeedsBeginFrame(true) and the BeginFrameSource has | 287 // We have just called SetNeedsBeginFrame(true) and the BeginFrameSource has |
297 // sent us the last BeginFrame we have missed. As we might not be able to | 288 // sent us the last BeginFrame we have missed. As we might not be able to |
298 // actually make rendering for this call, handle it like a "retro frame". | 289 // actually make rendering for this call, handle it like a "retro frame". |
299 // TODO(brainderson): Add a test for this functionality ASAP! | 290 // TODO(brainderson): Add a test for this functionality ASAP! |
300 if (adjusted_args.type == BeginFrameArgs::MISSED) { | 291 if (args.type == BeginFrameArgs::MISSED) { |
301 begin_retro_frame_args_.push_back(adjusted_args); | 292 begin_retro_frame_args_.push_back(args); |
302 PostBeginRetroFrameIfNeeded(); | 293 PostBeginRetroFrameIfNeeded(); |
303 return true; | 294 return true; |
304 } | 295 } |
305 | 296 |
306 bool should_defer_begin_frame = | 297 bool should_defer_begin_frame = |
307 !begin_retro_frame_args_.empty() || | 298 !begin_retro_frame_args_.empty() || |
308 !begin_retro_frame_task_.IsCancelled() || | 299 !begin_retro_frame_task_.IsCancelled() || |
309 !observing_begin_frame_source_ || | 300 !observing_begin_frame_source_ || |
310 (state_machine_.begin_impl_frame_state() != | 301 (state_machine_.begin_impl_frame_state() != |
311 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE); | 302 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE); |
312 | 303 |
313 if (should_defer_begin_frame) { | 304 if (should_defer_begin_frame) { |
314 begin_retro_frame_args_.push_back(adjusted_args); | 305 begin_retro_frame_args_.push_back(args); |
315 TRACE_EVENT_INSTANT0("cc", "Scheduler::BeginFrame deferred", | 306 TRACE_EVENT_INSTANT0("cc", "Scheduler::BeginFrame deferred", |
316 TRACE_EVENT_SCOPE_THREAD); | 307 TRACE_EVENT_SCOPE_THREAD); |
317 // Queuing the frame counts as "using it", so we need to return true. | 308 // Queuing the frame counts as "using it", so we need to return true. |
318 } else { | 309 } else { |
319 BeginImplFrameWithDeadline(adjusted_args); | 310 BeginImplFrameWithDeadline(args); |
320 } | 311 } |
321 return true; | 312 return true; |
322 } | 313 } |
323 | 314 |
324 void Scheduler::SetVideoNeedsBeginFrames(bool video_needs_begin_frames) { | 315 void Scheduler::SetVideoNeedsBeginFrames(bool video_needs_begin_frames) { |
325 state_machine_.SetVideoNeedsBeginFrames(video_needs_begin_frames); | 316 state_machine_.SetVideoNeedsBeginFrames(video_needs_begin_frames); |
326 ProcessScheduledActions(); | 317 ProcessScheduledActions(); |
327 } | 318 } |
328 | 319 |
329 void Scheduler::OnDrawForCompositorFrameSink(bool resourceless_software_draw) { | 320 void Scheduler::OnDrawForCompositorFrameSink(bool resourceless_software_draw) { |
(...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
709 Scheduler::AsValue() const { | 700 Scheduler::AsValue() const { |
710 std::unique_ptr<base::trace_event::TracedValue> state( | 701 std::unique_ptr<base::trace_event::TracedValue> state( |
711 new base::trace_event::TracedValue()); | 702 new base::trace_event::TracedValue()); |
712 base::TimeTicks now = Now(); | 703 base::TimeTicks now = Now(); |
713 | 704 |
714 state->BeginDictionary("state_machine"); | 705 state->BeginDictionary("state_machine"); |
715 state_machine_.AsValueInto(state.get()); | 706 state_machine_.AsValueInto(state.get()); |
716 state->EndDictionary(); | 707 state->EndDictionary(); |
717 | 708 |
718 state->BeginDictionary("scheduler_state"); | 709 state->BeginDictionary("scheduler_state"); |
719 state->SetDouble("estimated_parent_draw_time_ms", | |
720 estimated_parent_draw_time_.InMillisecondsF()); | |
721 state->SetBoolean("observing_begin_frame_source", | 710 state->SetBoolean("observing_begin_frame_source", |
722 observing_begin_frame_source_); | 711 observing_begin_frame_source_); |
723 state->SetInteger("begin_retro_frame_args", | 712 state->SetInteger("begin_retro_frame_args", |
724 static_cast<int>(begin_retro_frame_args_.size())); | 713 static_cast<int>(begin_retro_frame_args_.size())); |
725 state->SetBoolean("begin_retro_frame_task", | 714 state->SetBoolean("begin_retro_frame_task", |
726 !begin_retro_frame_task_.IsCancelled()); | 715 !begin_retro_frame_task_.IsCancelled()); |
727 state->SetBoolean("begin_impl_frame_deadline_task", | 716 state->SetBoolean("begin_impl_frame_deadline_task", |
728 !begin_impl_frame_deadline_task_.IsCancelled()); | 717 !begin_impl_frame_deadline_task_.IsCancelled()); |
729 state->SetString("inside_action", | 718 state->SetString("inside_action", |
730 SchedulerStateMachine::ActionToString(inside_action_)); | 719 SchedulerStateMachine::ActionToString(inside_action_)); |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
823 } | 812 } |
824 | 813 |
825 bool Scheduler::IsBeginMainFrameSentOrStarted() const { | 814 bool Scheduler::IsBeginMainFrameSentOrStarted() const { |
826 return (state_machine_.begin_main_frame_state() == | 815 return (state_machine_.begin_main_frame_state() == |
827 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_SENT || | 816 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_SENT || |
828 state_machine_.begin_main_frame_state() == | 817 state_machine_.begin_main_frame_state() == |
829 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_STARTED); | 818 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_STARTED); |
830 } | 819 } |
831 | 820 |
832 } // namespace cc | 821 } // namespace cc |
OLD | NEW |