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 RendererSchedulerSelector; | |
18 | |
19 class RendererSchedulerImpl : public RendererScheduler, | |
20 private IdleTaskDeadlineSupplier { | |
21 public: | |
22 RendererSchedulerImpl(); | |
23 virtual ~RendererSchedulerImpl(); | |
24 | |
25 // Returns the default task runner. | |
26 scoped_refptr<base::SingleThreadTaskRunner> DefaultTaskRunner() override; | |
27 | |
28 // Returns the compositor task runner. | |
29 scoped_refptr<base::SingleThreadTaskRunner> CompositorTaskRunner() override; | |
30 | |
31 // Returns the idle task runner. Tasks posted to this runner may be reordered | |
32 // relative to other task types and may be starved for an arbitrarily long | |
33 // time if no idle time is available. | |
34 scoped_refptr<SingleThreadIdleTaskRunner> IdleTaskRunner() override; | |
35 | |
36 // Called to notify about the start of a new frame. Must be called from the | |
37 // main thread. | |
38 void WillBeginFrame(const cc::BeginFrameArgs& args) override; | |
39 | |
40 // Called to notify that a previously begun frame was committed. Must be | |
41 // called from the main thread. | |
42 void DidCommitFrameToCompositor() override; | |
43 | |
44 // Tells the scheduler that the system received an input event. Can be called | |
45 // on any thread. | |
46 void DidReceiveInputEvent() override; | |
47 | |
48 // Returns true if there is high priority work pending on the main thread | |
49 // and the caller should yield to let the scheduler service that work. | |
50 // Must be called from the main thread. | |
51 bool ShouldYieldForHighPriorityWork() override; | |
52 | |
53 protected: | |
54 RendererSchedulerImpl( | |
55 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner); | |
56 | |
57 // Virtual for testing. | |
58 virtual base::TimeTicks Now() const; | |
59 | |
60 private: | |
61 DISALLOW_COPY_AND_ASSIGN(RendererSchedulerImpl); | |
62 friend base::WeakPtr<content::IdleTaskDeadlineSupplier>; | |
63 friend class RendererSchedulerImplTest; | |
64 | |
65 enum QueueId { | |
66 kDefaultTaskQueue, | |
67 kCompositorTaskQueue, | |
68 kIdleTaskQueue, | |
69 kControlTaskQueue, | |
70 // Must be the last entry. | |
71 kTaskQueueCount, | |
72 }; | |
73 | |
74 enum Policy { | |
75 kNormalPriorityPolicy, | |
76 kCompositorPriorityPolicy, | |
77 }; | |
78 | |
79 // The time we should stay in CompositorPriority mode for after a touch event. | |
80 static const int kCompositorPriorityAfterTouchMillis = 100; | |
81 | |
82 // Implementation of IdleTaskDeadlineSupplier | |
83 virtual base::TimeTicks CurrentIdleTaskDeadline() const override; | |
84 | |
85 // Returns the current scheduler policy. This may involve updating the | |
86 // current policy if a new signal has arrived. Must be called from the main | |
87 // thread. | |
88 Policy SchedulerPolicy(); | |
89 | |
90 // Posts a call to UpdatePolicy on the control runner to be run after |delay| | |
91 void PostUpdatePolicyOnControlRunner(base::TimeDelta delay); | |
92 | |
93 // Updates the scheduler policy. Must be called from the main thread. | |
94 void UpdatePolicy(); | |
95 | |
96 // Start and end an idle period. | |
97 void StartIdlePeriod(); | |
98 void EndIdlePeriod(); | |
99 | |
100 base::ThreadChecker main_thread_checker_; | |
alexclarke
2014/10/24 15:56:30
I think it might be useful to group these by which
rmcilroy
2014/10/27 16:25:01
It's not easy to do this and still maintain constr
| |
101 scoped_ptr<RendererSchedulerSelector> renderer_scheduler_selector_; | |
102 TaskQueueManager task_queue_manager_; | |
103 scoped_refptr<base::SingleThreadTaskRunner> control_task_runner_; | |
104 scoped_refptr<SingleThreadIdleTaskRunner> idle_task_runner_; | |
105 | |
106 // Don't access current_policy_ directly, instead use SchedulerPolicy(). | |
107 base::subtle::AtomicWord policy_may_need_update_; | |
108 Policy current_policy_; | |
109 | |
110 base::TimeTicks estimated_next_frame_begin_; | |
111 | |
112 // The incoming_signals_lock_ mutex protects access to last_input_time_ | |
113 // and write access to policy_may_need_update_. | |
114 base::Lock incoming_signals_lock_; | |
115 base::TimeTicks last_input_time_; | |
116 | |
117 base::WeakPtr<RendererSchedulerImpl> weak_renderer_scheduler_ptr_; | |
118 base::WeakPtrFactory<RendererSchedulerImpl> weak_factory_; | |
119 }; | |
120 | |
121 } // namespace content | |
122 | |
123 #endif // CONTENT_RENDERER_SCHEDULER_RENDERER_SCHEDULER_IMPL_H_ | |
OLD | NEW |