Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(112)

Side by Side Diff: content/renderer/scheduler/renderer_scheduler_impl.h

Issue 664963002: content: Add RendererScheduler. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address Daniel and Jared's comments and move renderer_scheduler ownership to render_thread_impl Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 {
Sami 2014/11/04 17:46:35 It seems a little weird to have an anonymous names
no sievers 2014/11/04 20:41:41 Yea, can this just be a nested private class in Re
rmcilroy 2014/11/05 00:34:00 Good point - went with private class.
20
21 class PolicyNeedsUpdateFlag {
Sami 2014/11/04 17:46:35 Is it worth calling this something like NeedsUpdat
rmcilroy 2014/11/05 00:34:00 Done.
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 public:
44 RendererSchedulerImpl(
45 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner);
46 ~RendererSchedulerImpl() override;
47
48 // RendererScheduler implementation:
49 scoped_refptr<base::SingleThreadTaskRunner> DefaultTaskRunner() override;
50 scoped_refptr<base::SingleThreadTaskRunner> CompositorTaskRunner() override;
51 scoped_refptr<SingleThreadIdleTaskRunner> IdleTaskRunner() override;
52 void WillBeginFrame(const cc::BeginFrameArgs& args) override;
53 void DidCommitFrameToCompositor() override;
54 void DidReceiveInputEvent() override;
55 bool ShouldYieldForHighPriorityWork() override;
56 void Shutdown() override;
57
58 protected:
59 // Virtual for testing.
60 virtual base::TimeTicks Now() const;
61
62 private:
63 friend class RendererSchedulerImplTest;
64
65 enum QueueId {
66 DEFAULT_TASK_QUEUE,
67 COMPOSITOR_TASK_QUEUE,
68 IDLE_TASK_QUEUE,
69 CONTROL_TASK_QUEUE,
70 // Must be the last entry.
71 TASK_QUEUE_COUNT,
72 };
73
74 enum Policy {
75 NORMAL_PRIORITY_POLICY,
76 COMPOSITOR_PRIORITY_POLICY,
77 };
78
79 // The time we should stay in CompositorPriority mode for after a touch event.
80 static const int kCompositorPriorityAfterTouchMillis = 100;
81
82 // IdleTaskDeadlineSupplier Implementation:
83 void CurrentIdleTaskDeadlineCallback(base::TimeTicks* deadline_out) const;
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_;
101 scoped_ptr<RendererTaskQueueSelector> renderer_task_queue_selector_;
102 scoped_ptr<TaskQueueManager> task_queue_manager_;
103 scoped_refptr<base::SingleThreadTaskRunner> control_task_runner_;
104 scoped_refptr<base::SingleThreadTaskRunner> default_task_runner_;
105 scoped_refptr<base::SingleThreadTaskRunner> compositor_task_runner_;
106 scoped_refptr<SingleThreadIdleTaskRunner> idle_task_runner_;
107
108 base::Closure update_policy_closure_;
109 base::Closure end_idle_period_closure_;
110
111 // Don't access current_policy_ directly, instead use SchedulerPolicy().
112 Policy current_policy_;
113
114 base::TimeTicks estimated_next_frame_begin_;
115
116 // The incoming_signals_lock_ mutex protects access to last_input_time_
117 // and write access to policy_may_need_update_.
118 base::Lock incoming_signals_lock_;
119 base::TimeTicks last_input_time_;
120 PolicyNeedsUpdateFlag policy_may_need_update_;
121
122 base::WeakPtr<RendererSchedulerImpl> weak_renderer_scheduler_ptr_;
123 base::WeakPtrFactory<RendererSchedulerImpl> weak_factory_;
124
125 DISALLOW_COPY_AND_ASSIGN(RendererSchedulerImpl);
126 };
127
128 } // namespace content
129
130 #endif // CONTENT_RENDERER_SCHEDULER_RENDERER_SCHEDULER_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698