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 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
267 DCHECK(begin_impl_frame_deadline_task_.IsCancelled()); | 267 DCHECK(begin_impl_frame_deadline_task_.IsCancelled()); |
268 state_machine_.DidCreateAndInitializeOutputSurface(); | 268 state_machine_.DidCreateAndInitializeOutputSurface(); |
269 ProcessScheduledActions(); | 269 ProcessScheduledActions(); |
270 } | 270 } |
271 | 271 |
272 void Scheduler::NotifyBeginMainFrameStarted() { | 272 void Scheduler::NotifyBeginMainFrameStarted() { |
273 TRACE_EVENT0("cc", "Scheduler::NotifyBeginMainFrameStarted"); | 273 TRACE_EVENT0("cc", "Scheduler::NotifyBeginMainFrameStarted"); |
274 state_machine_.NotifyBeginMainFrameStarted(); | 274 state_machine_.NotifyBeginMainFrameStarted(); |
275 } | 275 } |
276 | 276 |
277 base::TimeTicks Scheduler::AnticipatedDrawTime() const { | |
278 if (!frame_source_->NeedsBeginFrames() || | |
279 begin_impl_frame_tracker_.DangerousMethodHasFinished()) | |
280 return base::TimeTicks(); | |
281 | |
282 base::TimeTicks now = Now(); | |
283 BeginFrameArgs args = begin_impl_frame_tracker_.Current(); | |
284 base::TimeTicks timebase = std::max(args.frame_time, args.deadline); | |
285 int64 intervals = | |
286 1 + ((now - timebase) / begin_impl_frame_tracker_.Interval()); | |
287 return timebase + (begin_impl_frame_tracker_.Interval() * intervals); | |
288 } | |
289 | |
290 base::TimeTicks Scheduler::LastBeginImplFrameTime() { | 277 base::TimeTicks Scheduler::LastBeginImplFrameTime() { |
291 return begin_impl_frame_tracker_.Current().frame_time; | 278 return begin_impl_frame_tracker_.Current().frame_time; |
292 } | 279 } |
293 | 280 |
294 void Scheduler::SetupNextBeginFrameIfNeeded() { | 281 void Scheduler::SetupNextBeginFrameIfNeeded() { |
295 // Never call SetNeedsBeginFrames if the frame source already has the right | 282 // Never call SetNeedsBeginFrames if the frame source already has the right |
296 // value. | 283 // value. |
297 if (frame_source_->NeedsBeginFrames() != state_machine_.BeginFrameNeeded()) { | 284 if (frame_source_->NeedsBeginFrames() != state_machine_.BeginFrameNeeded()) { |
298 if (state_machine_.BeginFrameNeeded()) { | 285 if (state_machine_.BeginFrameNeeded()) { |
299 // Call SetNeedsBeginFrames(true) as soon as possible. | 286 // Call SetNeedsBeginFrames(true) as soon as possible. |
(...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
729 break; | 716 break; |
730 case SchedulerStateMachine::ACTION_INVALIDATE_OUTPUT_SURFACE: { | 717 case SchedulerStateMachine::ACTION_INVALIDATE_OUTPUT_SURFACE: { |
731 client_->ScheduledActionInvalidateOutputSurface(); | 718 client_->ScheduledActionInvalidateOutputSurface(); |
732 break; | 719 break; |
733 } | 720 } |
734 } | 721 } |
735 } while (action != SchedulerStateMachine::ACTION_NONE); | 722 } while (action != SchedulerStateMachine::ACTION_NONE); |
736 | 723 |
737 SetupPollingMechanisms(); | 724 SetupPollingMechanisms(); |
738 | 725 |
739 client_->DidAnticipatedDrawTimeChange(AnticipatedDrawTime()); | |
740 | |
741 ScheduleBeginImplFrameDeadlineIfNeeded(); | 726 ScheduleBeginImplFrameDeadlineIfNeeded(); |
742 | 727 |
743 SetupNextBeginFrameIfNeeded(); | 728 SetupNextBeginFrameIfNeeded(); |
744 } | 729 } |
745 | 730 |
746 scoped_refptr<base::trace_event::ConvertableToTraceFormat> Scheduler::AsValue() | 731 scoped_refptr<base::trace_event::ConvertableToTraceFormat> Scheduler::AsValue() |
747 const { | 732 const { |
748 scoped_refptr<base::trace_event::TracedValue> state = | 733 scoped_refptr<base::trace_event::TracedValue> state = |
749 new base::trace_event::TracedValue(); | 734 new base::trace_event::TracedValue(); |
750 AsValueInto(state.get()); | 735 AsValueInto(state.get()); |
(...skipping 10 matching lines...) Expand all Loading... |
761 TRACE_EVENT_CATEGORY_GROUP_ENABLED( | 746 TRACE_EVENT_CATEGORY_GROUP_ENABLED( |
762 TRACE_DISABLED_BY_DEFAULT("cc.debug.scheduler.frames"), | 747 TRACE_DISABLED_BY_DEFAULT("cc.debug.scheduler.frames"), |
763 &frame_tracing_enabled); | 748 &frame_tracing_enabled); |
764 if (frame_tracing_enabled) { | 749 if (frame_tracing_enabled) { |
765 state->BeginDictionary("frame_source_"); | 750 state->BeginDictionary("frame_source_"); |
766 frame_source_->AsValueInto(state); | 751 frame_source_->AsValueInto(state); |
767 state->EndDictionary(); | 752 state->EndDictionary(); |
768 } | 753 } |
769 | 754 |
770 state->BeginDictionary("scheduler_state"); | 755 state->BeginDictionary("scheduler_state"); |
771 state->SetDouble("time_until_anticipated_draw_time_ms", | |
772 (AnticipatedDrawTime() - Now()).InMillisecondsF()); | |
773 state->SetDouble("estimated_parent_draw_time_ms", | 756 state->SetDouble("estimated_parent_draw_time_ms", |
774 estimated_parent_draw_time_.InMillisecondsF()); | 757 estimated_parent_draw_time_.InMillisecondsF()); |
775 state->SetBoolean("last_set_needs_begin_frame_", | 758 state->SetBoolean("last_set_needs_begin_frame_", |
776 frame_source_->NeedsBeginFrames()); | 759 frame_source_->NeedsBeginFrames()); |
777 state->SetInteger("begin_retro_frame_args", | 760 state->SetInteger("begin_retro_frame_args", |
778 static_cast<int>(begin_retro_frame_args_.size())); | 761 static_cast<int>(begin_retro_frame_args_.size())); |
779 state->SetBoolean("begin_retro_frame_task", | 762 state->SetBoolean("begin_retro_frame_task", |
780 !begin_retro_frame_task_.IsCancelled()); | 763 !begin_retro_frame_task_.IsCancelled()); |
781 state->SetBoolean("begin_impl_frame_deadline_task", | 764 state->SetBoolean("begin_impl_frame_deadline_task", |
782 !begin_impl_frame_deadline_task_.IsCancelled()); | 765 !begin_impl_frame_deadline_task_.IsCancelled()); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
821 } | 804 } |
822 | 805 |
823 bool Scheduler::IsBeginMainFrameSentOrStarted() const { | 806 bool Scheduler::IsBeginMainFrameSentOrStarted() const { |
824 return (state_machine_.commit_state() == | 807 return (state_machine_.commit_state() == |
825 SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT || | 808 SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT || |
826 state_machine_.commit_state() == | 809 state_machine_.commit_state() == |
827 SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_STARTED); | 810 SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_STARTED); |
828 } | 811 } |
829 | 812 |
830 } // namespace cc | 813 } // namespace cc |
OLD | NEW |