OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CONTENT_RENDERER_SCHEDULER_RENDERER_SCHEDULER_IMPL_H_ |
| 6 #define CONTENT_RENDERER_SCHEDULER_RENDERER_SCHEDULER_IMPL_H_ |
| 7 |
| 8 #include "base/atomicops.h" |
| 9 #include "base/synchronization/lock.h" |
| 10 #include "base/threading/thread_checker.h" |
| 11 #include "content/renderer/scheduler/renderer_scheduler.h" |
| 12 #include "content/renderer/scheduler/single_thread_idle_task_runner.h" |
| 13 #include "content/renderer/scheduler/task_queue_manager.h" |
| 14 |
| 15 namespace content { |
| 16 |
| 17 class RendererTaskQueueSelector; |
| 18 |
| 19 class CONTENT_EXPORT RendererSchedulerImpl : public RendererScheduler { |
| 20 public: |
| 21 RendererSchedulerImpl( |
| 22 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner); |
| 23 ~RendererSchedulerImpl() override; |
| 24 |
| 25 // RendererScheduler implementation: |
| 26 scoped_refptr<base::SingleThreadTaskRunner> DefaultTaskRunner() override; |
| 27 scoped_refptr<base::SingleThreadTaskRunner> CompositorTaskRunner() override; |
| 28 scoped_refptr<SingleThreadIdleTaskRunner> IdleTaskRunner() override; |
| 29 void WillBeginFrame(const cc::BeginFrameArgs& args) override; |
| 30 void DidCommitFrameToCompositor() override; |
| 31 void DidReceiveInputEventOnCompositorThread() override; |
| 32 bool ShouldYieldForHighPriorityWork() override; |
| 33 void Shutdown() override; |
| 34 |
| 35 protected: |
| 36 // Virtual for testing. |
| 37 virtual base::TimeTicks Now() const; |
| 38 |
| 39 private: |
| 40 friend class RendererSchedulerImplTest; |
| 41 |
| 42 enum QueueId { |
| 43 DEFAULT_TASK_QUEUE, |
| 44 COMPOSITOR_TASK_QUEUE, |
| 45 IDLE_TASK_QUEUE, |
| 46 CONTROL_TASK_QUEUE, |
| 47 // Must be the last entry. |
| 48 TASK_QUEUE_COUNT, |
| 49 }; |
| 50 |
| 51 enum Policy { |
| 52 NORMAL_PRIORITY_POLICY, |
| 53 COMPOSITOR_PRIORITY_POLICY, |
| 54 }; |
| 55 |
| 56 class PollableNeedsUpdateFlag { |
| 57 public: |
| 58 PollableNeedsUpdateFlag(base::Lock* write_lock); |
| 59 ~PollableNeedsUpdateFlag(); |
| 60 |
| 61 // Set the flag. May only be called if |write_lock| is held. |
| 62 void SetLocked(bool value); |
| 63 |
| 64 // Returns true iff the flag was set to true. |
| 65 bool IsSet() const; |
| 66 |
| 67 private: |
| 68 base::subtle::Atomic32 flag_; |
| 69 base::Lock* write_lock_; // Not owned. |
| 70 base::ThreadChecker thread_checker_; |
| 71 |
| 72 DISALLOW_COPY_AND_ASSIGN(PollableNeedsUpdateFlag); |
| 73 }; |
| 74 |
| 75 // The time we should stay in CompositorPriority mode for after a touch event. |
| 76 static const int kCompositorPriorityAfterTouchMillis = 100; |
| 77 |
| 78 // IdleTaskDeadlineSupplier Implementation: |
| 79 void CurrentIdleTaskDeadlineCallback(base::TimeTicks* deadline_out) const; |
| 80 |
| 81 // Returns the current scheduler policy. Must be called from the main thread. |
| 82 Policy SchedulerPolicy() const; |
| 83 |
| 84 // Posts a call to UpdatePolicy on the control runner to be run after |delay| |
| 85 void PostUpdatePolicyOnControlRunner(base::TimeDelta delay); |
| 86 |
| 87 // Update the policy if a new signal has arrived. Must be called from the main |
| 88 // thread. |
| 89 void MaybeUpdatePolicy(); |
| 90 |
| 91 // Updates the scheduler policy. Must be called from the main thread. |
| 92 void UpdatePolicy(); |
| 93 |
| 94 // Start and end an idle period. |
| 95 void StartIdlePeriod(); |
| 96 void EndIdlePeriod(); |
| 97 |
| 98 base::ThreadChecker main_thread_checker_; |
| 99 scoped_ptr<RendererTaskQueueSelector> renderer_task_queue_selector_; |
| 100 scoped_ptr<TaskQueueManager> task_queue_manager_; |
| 101 scoped_refptr<base::SingleThreadTaskRunner> control_task_runner_; |
| 102 scoped_refptr<base::SingleThreadTaskRunner> default_task_runner_; |
| 103 scoped_refptr<base::SingleThreadTaskRunner> compositor_task_runner_; |
| 104 scoped_refptr<SingleThreadIdleTaskRunner> idle_task_runner_; |
| 105 |
| 106 base::Closure update_policy_closure_; |
| 107 base::Closure end_idle_period_closure_; |
| 108 |
| 109 // Don't access current_policy_ directly, instead use SchedulerPolicy(). |
| 110 Policy current_policy_; |
| 111 |
| 112 base::TimeTicks estimated_next_frame_begin_; |
| 113 |
| 114 // The incoming_signals_lock_ mutex protects access to last_input_time_ |
| 115 // and write access to policy_may_need_update_. |
| 116 base::Lock incoming_signals_lock_; |
| 117 base::TimeTicks last_input_time_; |
| 118 PollableNeedsUpdateFlag policy_may_need_update_; |
| 119 |
| 120 base::WeakPtr<RendererSchedulerImpl> weak_renderer_scheduler_ptr_; |
| 121 base::WeakPtrFactory<RendererSchedulerImpl> weak_factory_; |
| 122 |
| 123 DISALLOW_COPY_AND_ASSIGN(RendererSchedulerImpl); |
| 124 }; |
| 125 |
| 126 } // namespace content |
| 127 |
| 128 #endif // CONTENT_RENDERER_SCHEDULER_RENDERER_SCHEDULER_IMPL_H_ |
OLD | NEW |