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 namespace { |
| 20 |
| 21 class PolicyNeedsUpdateFlag { |
| 22 public: |
| 23 PolicyNeedsUpdateFlag(base::Lock* write_lock); |
| 24 ~PolicyNeedsUpdateFlag(); |
| 25 |
| 26 // Set the flag. May only be called if |write_lock| is held. |
| 27 void SetLocked(bool value); |
| 28 |
| 29 // Returns true iff the flag was set to true. |
| 30 bool IsSet() const; |
| 31 |
| 32 private: |
| 33 base::subtle::Atomic32 flag_; |
| 34 base::Lock* write_lock_; // Not owned. |
| 35 base::ThreadChecker thread_checker_; |
| 36 |
| 37 DISALLOW_COPY_AND_ASSIGN(PolicyNeedsUpdateFlag); |
| 38 }; |
| 39 |
| 40 } // namespace |
| 41 |
| 42 class CONTENT_EXPORT RendererSchedulerImpl : public RendererScheduler, |
| 43 private IdleTaskDeadlineSupplier { |
| 44 public: |
| 45 RendererSchedulerImpl( |
| 46 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner); |
| 47 ~RendererSchedulerImpl() override; |
| 48 |
| 49 // RendererScheduler implementation: |
| 50 scoped_refptr<base::SingleThreadTaskRunner> DefaultTaskRunner() override; |
| 51 scoped_refptr<base::SingleThreadTaskRunner> CompositorTaskRunner() override; |
| 52 scoped_refptr<SingleThreadIdleTaskRunner> IdleTaskRunner() override; |
| 53 void WillBeginFrame(const cc::BeginFrameArgs& args) override; |
| 54 void DidCommitFrameToCompositor() override; |
| 55 void DidReceiveInputEvent() override; |
| 56 bool ShouldYieldForHighPriorityWork() override; |
| 57 void Shutdown() override; |
| 58 |
| 59 protected: |
| 60 // Virtual for testing. |
| 61 virtual base::TimeTicks Now() const; |
| 62 |
| 63 private: |
| 64 friend base::WeakPtr<content::IdleTaskDeadlineSupplier>; |
| 65 friend class RendererSchedulerImplTest; |
| 66 |
| 67 enum QueueId { |
| 68 DEFAULT_TASK_QUEUE, |
| 69 COMPOSITOR_TASK_QUEUE, |
| 70 IDLE_TASK_QUEUE, |
| 71 CONTROL_TASK_QUEUE, |
| 72 // Must be the last entry. |
| 73 TASK_QUEUE_COUNT, |
| 74 }; |
| 75 |
| 76 enum Policy { |
| 77 NORMAL_PRIORITY_POLICY, |
| 78 COMPOSITOR_PRIORITY_POLICY, |
| 79 }; |
| 80 |
| 81 // The time we should stay in CompositorPriority mode for after a touch event. |
| 82 static const int kCompositorPriorityAfterTouchMillis = 100; |
| 83 |
| 84 // IdleTaskDeadlineSupplier Implementation: |
| 85 base::TimeTicks CurrentIdleTaskDeadline() const override; |
| 86 |
| 87 // Returns the current scheduler policy. This may involve updating the |
| 88 // current policy if a new signal has arrived. Must be called from the main |
| 89 // thread. |
| 90 Policy SchedulerPolicy(); |
| 91 |
| 92 // Posts a call to UpdatePolicy on the control runner to be run after |delay| |
| 93 void PostUpdatePolicyOnControlRunner(base::TimeDelta delay); |
| 94 |
| 95 // Updates the scheduler policy. Must be called from the main thread. |
| 96 void UpdatePolicy(); |
| 97 |
| 98 // Start and end an idle period. |
| 99 void StartIdlePeriod(); |
| 100 void EndIdlePeriod(); |
| 101 |
| 102 base::ThreadChecker main_thread_checker_; |
| 103 scoped_ptr<RendererTaskQueueSelector> renderer_task_queue_selector_; |
| 104 scoped_ptr<TaskQueueManager> task_queue_manager_; |
| 105 scoped_refptr<base::SingleThreadTaskRunner> control_task_runner_; |
| 106 scoped_refptr<base::SingleThreadTaskRunner> default_task_runner_; |
| 107 scoped_refptr<base::SingleThreadTaskRunner> compositor_task_runner_; |
| 108 scoped_refptr<SingleThreadIdleTaskRunner> idle_task_runner_; |
| 109 |
| 110 // Don't access current_policy_ directly, instead use SchedulerPolicy(). |
| 111 Policy current_policy_; |
| 112 |
| 113 base::TimeTicks estimated_next_frame_begin_; |
| 114 |
| 115 // The incoming_signals_lock_ mutex protects access to last_input_time_ |
| 116 // and write access to policy_may_need_update_. |
| 117 base::Lock incoming_signals_lock_; |
| 118 base::TimeTicks last_input_time_; |
| 119 PolicyNeedsUpdateFlag policy_may_need_update_; |
| 120 |
| 121 base::WeakPtr<RendererSchedulerImpl> weak_renderer_scheduler_ptr_; |
| 122 base::WeakPtrFactory<RendererSchedulerImpl> weak_factory_; |
| 123 |
| 124 DISALLOW_COPY_AND_ASSIGN(RendererSchedulerImpl); |
| 125 }; |
| 126 |
| 127 } // namespace content |
| 128 |
| 129 #endif // CONTENT_RENDERER_SCHEDULER_RENDERER_SCHEDULER_IMPL_H_ |
OLD | NEW |