| 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 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 297 begin_impl_frame_args_.deadline); | 297 begin_impl_frame_args_.deadline); |
| 298 int64 intervals = 1 + ((now - timebase) / begin_impl_frame_args_.interval); | 298 int64 intervals = 1 + ((now - timebase) / begin_impl_frame_args_.interval); |
| 299 return timebase + (begin_impl_frame_args_.interval * intervals); | 299 return timebase + (begin_impl_frame_args_.interval * intervals); |
| 300 } | 300 } |
| 301 | 301 |
| 302 base::TimeTicks Scheduler::LastBeginImplFrameTime() { | 302 base::TimeTicks Scheduler::LastBeginImplFrameTime() { |
| 303 return begin_impl_frame_args_.frame_time; | 303 return begin_impl_frame_args_.frame_time; |
| 304 } | 304 } |
| 305 | 305 |
| 306 void Scheduler::SetupNextBeginFrameIfNeeded() { | 306 void Scheduler::SetupNextBeginFrameIfNeeded() { |
| 307 if (!task_runner_.get()) | 307 // Never call SetNeedsBeginFrames if the frame source already has the right |
| 308 return; | 308 // value. |
| 309 | 309 if (frame_source_->NeedsBeginFrames() != state_machine_.BeginFrameNeeded()) { |
| 310 if (state_machine_.ShouldSetNeedsBeginFrames( | 310 if (state_machine_.BeginFrameNeeded()) { |
| 311 frame_source_->NeedsBeginFrames())) { | 311 // Call SetNeedsBeginFrames(true) as soon as possible. |
| 312 frame_source_->SetNeedsBeginFrames(state_machine_.BeginFrameNeeded()); | 312 frame_source_->SetNeedsBeginFrames(true); |
| 313 if (!frame_source_->NeedsBeginFrames()) { | 313 } else if (state_machine_.begin_impl_frame_state() == |
| 314 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE) { |
| 315 // Call SetNeedsBeginFrames(false) in between frames only. |
| 316 frame_source_->SetNeedsBeginFrames(false); |
| 314 client_->SendBeginMainFrameNotExpectedSoon(); | 317 client_->SendBeginMainFrameNotExpectedSoon(); |
| 315 } | 318 } |
| 316 } | 319 } |
| 317 | 320 |
| 318 if (state_machine_.begin_impl_frame_state() == | |
| 319 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE) { | |
| 320 frame_source_->DidFinishFrame(begin_retro_frame_args_.size()); | |
| 321 } | |
| 322 | |
| 323 PostBeginRetroFrameIfNeeded(); | 321 PostBeginRetroFrameIfNeeded(); |
| 324 SetupPollingMechanisms(); | |
| 325 } | 322 } |
| 326 | 323 |
| 327 // We may need to poll when we can't rely on BeginFrame to advance certain | 324 // We may need to poll when we can't rely on BeginFrame to advance certain |
| 328 // state or to avoid deadlock. | 325 // state or to avoid deadlock. |
| 329 void Scheduler::SetupPollingMechanisms() { | 326 void Scheduler::SetupPollingMechanisms() { |
| 330 bool needs_advance_commit_state_timer = false; | 327 bool needs_advance_commit_state_timer = false; |
| 331 // Setup PollForAnticipatedDrawTriggers if we need to monitor state but | 328 // Setup PollForAnticipatedDrawTriggers if we need to monitor state but |
| 332 // aren't expecting any more BeginFrames. This should only be needed by | 329 // aren't expecting any more BeginFrames. This should only be needed by |
| 333 // the synchronous compositor when BeginFrameNeeded is false. | 330 // the synchronous compositor when BeginFrameNeeded is false. |
| 334 if (state_machine_.ShouldPollForAnticipatedDrawTriggers()) { | 331 if (state_machine_.ShouldPollForAnticipatedDrawTriggers()) { |
| (...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 633 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 630 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 634 "461509 Scheduler::OnBeginImplFrameDeadline2")); | 631 "461509 Scheduler::OnBeginImplFrameDeadline2")); |
| 635 state_machine_.OnBeginImplFrameIdle(); | 632 state_machine_.OnBeginImplFrameIdle(); |
| 636 ProcessScheduledActions(); | 633 ProcessScheduledActions(); |
| 637 | 634 |
| 638 // TODO(robliao): Remove ScopedTracker below once crbug.com/461509 is fixed. | 635 // TODO(robliao): Remove ScopedTracker below once crbug.com/461509 is fixed. |
| 639 tracked_objects::ScopedTracker tracking_profile3( | 636 tracked_objects::ScopedTracker tracking_profile3( |
| 640 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 637 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 641 "461509 Scheduler::OnBeginImplFrameDeadline3")); | 638 "461509 Scheduler::OnBeginImplFrameDeadline3")); |
| 642 client_->DidBeginImplFrameDeadline(); | 639 client_->DidBeginImplFrameDeadline(); |
| 640 frame_source_->DidFinishFrame(begin_retro_frame_args_.size()); |
| 643 } | 641 } |
| 644 | 642 |
| 645 void Scheduler::PollForAnticipatedDrawTriggers() { | 643 void Scheduler::PollForAnticipatedDrawTriggers() { |
| 646 TRACE_EVENT0("cc", "Scheduler::PollForAnticipatedDrawTriggers"); | 644 TRACE_EVENT0("cc", "Scheduler::PollForAnticipatedDrawTriggers"); |
| 647 poll_for_draw_triggers_task_.Cancel(); | 645 poll_for_draw_triggers_task_.Cancel(); |
| 648 state_machine_.DidEnterPollForAnticipatedDrawTriggers(); | 646 state_machine_.DidEnterPollForAnticipatedDrawTriggers(); |
| 649 ProcessScheduledActions(); | 647 ProcessScheduledActions(); |
| 650 state_machine_.DidLeavePollForAnticipatedDrawTriggers(); | 648 state_machine_.DidLeavePollForAnticipatedDrawTriggers(); |
| 651 } | 649 } |
| 652 | 650 |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 773 client_->ScheduledActionPrepareTiles(); | 771 client_->ScheduledActionPrepareTiles(); |
| 774 break; | 772 break; |
| 775 } | 773 } |
| 776 } | 774 } |
| 777 } while (action != SchedulerStateMachine::ACTION_NONE); | 775 } while (action != SchedulerStateMachine::ACTION_NONE); |
| 778 | 776 |
| 779 // TODO(robliao): Remove ScopedTracker below once crbug.com/461509 is fixed. | 777 // TODO(robliao): Remove ScopedTracker below once crbug.com/461509 is fixed. |
| 780 tracked_objects::ScopedTracker tracking_profile10( | 778 tracked_objects::ScopedTracker tracking_profile10( |
| 781 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 779 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 782 "461509 Scheduler::ProcessScheduledActions10")); | 780 "461509 Scheduler::ProcessScheduledActions10")); |
| 783 SetupNextBeginFrameIfNeeded(); | 781 |
| 782 SetupPollingMechanisms(); |
| 783 |
| 784 client_->DidAnticipatedDrawTimeChange(AnticipatedDrawTime()); | 784 client_->DidAnticipatedDrawTimeChange(AnticipatedDrawTime()); |
| 785 | 785 |
| 786 // TODO(robliao): Remove ScopedTracker below once crbug.com/461509 is fixed. | 786 // TODO(robliao): Remove ScopedTracker below once crbug.com/461509 is fixed. |
| 787 tracked_objects::ScopedTracker tracking_profile11( | 787 tracked_objects::ScopedTracker tracking_profile11( |
| 788 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 788 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 789 "461509 Scheduler::ProcessScheduledActions11")); | 789 "461509 Scheduler::ProcessScheduledActions11")); |
| 790 |
| 790 RescheduleBeginImplFrameDeadlineIfNeeded(); | 791 RescheduleBeginImplFrameDeadlineIfNeeded(); |
| 792 |
| 793 SetupNextBeginFrameIfNeeded(); |
| 791 } | 794 } |
| 792 | 795 |
| 793 scoped_refptr<base::trace_event::ConvertableToTraceFormat> Scheduler::AsValue() | 796 scoped_refptr<base::trace_event::ConvertableToTraceFormat> Scheduler::AsValue() |
| 794 const { | 797 const { |
| 795 scoped_refptr<base::trace_event::TracedValue> state = | 798 scoped_refptr<base::trace_event::TracedValue> state = |
| 796 new base::trace_event::TracedValue(); | 799 new base::trace_event::TracedValue(); |
| 797 AsValueInto(state.get()); | 800 AsValueInto(state.get()); |
| 798 return state; | 801 return state; |
| 799 } | 802 } |
| 800 | 803 |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 868 } | 871 } |
| 869 | 872 |
| 870 bool Scheduler::IsBeginMainFrameSentOrStarted() const { | 873 bool Scheduler::IsBeginMainFrameSentOrStarted() const { |
| 871 return (state_machine_.commit_state() == | 874 return (state_machine_.commit_state() == |
| 872 SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT || | 875 SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT || |
| 873 state_machine_.commit_state() == | 876 state_machine_.commit_state() == |
| 874 SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_STARTED); | 877 SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_STARTED); |
| 875 } | 878 } |
| 876 | 879 |
| 877 } // namespace cc | 880 } // namespace cc |
| OLD | NEW |