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 COMPONENTS_SCHEDULER_RENDERER_RENDERER_SCHEDULER_H_ | |
6 #define COMPONENTS_SCHEDULER_RENDERER_RENDERER_SCHEDULER_H_ | |
7 | |
8 #include <memory> | |
9 | |
10 #include "base/macros.h" | |
11 #include "base/message_loop/message_loop.h" | |
12 #include "components/scheduler/child/child_scheduler.h" | |
13 #include "components/scheduler/child/single_thread_idle_task_runner.h" | |
14 #include "components/scheduler/renderer/render_widget_scheduling_state.h" | |
15 #include "components/scheduler/scheduler_export.h" | |
16 #include "third_party/WebKit/public/platform/WebScheduler.h" | |
17 #include "third_party/WebKit/public/web/WebInputEvent.h" | |
18 #include "v8/include/v8.h" | |
19 | |
20 namespace base { | |
21 namespace trace_event { | |
22 class BlameContext; | |
23 } | |
24 } | |
25 | |
26 namespace cc { | |
27 struct BeginFrameArgs; | |
28 } | |
29 | |
30 namespace blink { | |
31 class WebLocalFrame; | |
32 class WebThread; | |
33 } | |
34 | |
35 namespace scheduler { | |
36 | |
37 class RenderWidgetSchedulingState; | |
38 | |
39 class SCHEDULER_EXPORT RendererScheduler : public ChildScheduler { | |
40 public: | |
41 class SCHEDULER_EXPORT RAILModeObserver { | |
42 public: | |
43 virtual ~RAILModeObserver(); | |
44 virtual void OnRAILModeChanged(v8::RAILMode rail_mode) = 0; | |
45 }; | |
46 | |
47 ~RendererScheduler() override; | |
48 static std::unique_ptr<RendererScheduler> Create(); | |
49 | |
50 // Returns the compositor task runner. | |
51 virtual scoped_refptr<TaskQueue> CompositorTaskRunner() = 0; | |
52 | |
53 // Creates a WebThread implementation for the renderer main thread. | |
54 virtual std::unique_ptr<blink::WebThread> CreateMainThread() = 0; | |
55 | |
56 // Returns the loading task runner. This queue is intended for tasks related | |
57 // to resource dispatch, foreground HTML parsing, etc... | |
58 virtual scoped_refptr<TaskQueue> LoadingTaskRunner() = 0; | |
59 | |
60 // Returns the timer task runner. This queue is intended for DOM Timers. | |
61 // TODO(alexclarke): Get rid of this default timer queue. | |
62 virtual scoped_refptr<TaskQueue> TimerTaskRunner() = 0; | |
63 | |
64 // Returns a new loading task runner. This queue is intended for tasks related | |
65 // to resource dispatch, foreground HTML parsing, etc... | |
66 virtual scoped_refptr<TaskQueue> NewLoadingTaskRunner(const char* name) = 0; | |
67 | |
68 // Returns a new timer task runner. This queue is intended for DOM Timers. | |
69 virtual scoped_refptr<TaskQueue> NewTimerTaskRunner(const char* name) = 0; | |
70 | |
71 // Returns a task runner for tasks which should never get throttled. | |
72 virtual scoped_refptr<TaskQueue> NewUnthrottledTaskRunner( | |
73 const char* name) = 0; | |
74 | |
75 // Returns a new RenderWidgetSchedulingState. The signals from this will be | |
76 // used to make scheduling decisions. | |
77 virtual std::unique_ptr<RenderWidgetSchedulingState> | |
78 NewRenderWidgetSchedulingState() = 0; | |
79 | |
80 // Called to notify about the start of an extended period where no frames | |
81 // need to be drawn. Must be called from the main thread. | |
82 virtual void BeginFrameNotExpectedSoon() = 0; | |
83 | |
84 // Called to notify about the start of a new frame. Must be called from the | |
85 // main thread. | |
86 virtual void WillBeginFrame(const cc::BeginFrameArgs& args) = 0; | |
87 | |
88 // Called to notify that a previously begun frame was committed. Must be | |
89 // called from the main thread. | |
90 virtual void DidCommitFrameToCompositor() = 0; | |
91 | |
92 // Keep RendererScheduler::InputEventStateToString in sync with this enum. | |
93 enum class InputEventState { | |
94 EVENT_CONSUMED_BY_COMPOSITOR, | |
95 EVENT_FORWARDED_TO_MAIN_THREAD, | |
96 }; | |
97 static const char* InputEventStateToString(InputEventState input_event_state); | |
98 | |
99 // Tells the scheduler that the system processed an input event. Called by the | |
100 // compositor (impl) thread. Note it's expected that every call to | |
101 // DidHandleInputEventOnCompositorThread where |event_state| is | |
102 // EVENT_FORWARDED_TO_MAIN_THREAD will be followed by a corresponding call | |
103 // to DidHandleInputEventOnMainThread. | |
104 virtual void DidHandleInputEventOnCompositorThread( | |
105 const blink::WebInputEvent& web_input_event, | |
106 InputEventState event_state) = 0; | |
107 | |
108 // Tells the scheduler that the system processed an input event. Must be | |
109 // called from the main thread. | |
110 virtual void DidHandleInputEventOnMainThread( | |
111 const blink::WebInputEvent& web_input_event) = 0; | |
112 | |
113 // Tells the scheduler that the system is displaying an input animation (e.g. | |
114 // a fling). Called by the compositor (impl) thread. | |
115 virtual void DidAnimateForInputOnCompositorThread() = 0; | |
116 | |
117 // Tells the scheduler that the renderer process has been backgrounded, i.e., | |
118 // there are no critical, user facing activities (visual, audio, etc...) | |
119 // driven by this process. A stricter condition than |OnRendererHidden()|, the | |
120 // process is assumed to be foregrounded when the scheduler is constructed. | |
121 // Must be called on the main thread. | |
122 virtual void OnRendererBackgrounded() = 0; | |
123 | |
124 // Tells the scheduler that the renderer process has been foregrounded. | |
125 // This is the assumed state when the scheduler is constructed. | |
126 // Must be called on the main thread. | |
127 virtual void OnRendererForegrounded() = 0; | |
128 | |
129 // Tells the scheduler that the render process should be suspended. This can | |
130 // only be done when the renderer is backgrounded. The renderer will be | |
131 // automatically resumed when foregrounded. | |
132 virtual void SuspendRenderer() = 0; | |
133 | |
134 // Tells the scheduler that a navigation task is pending. While any main-frame | |
135 // navigation tasks are pending, the scheduler will ensure that loading tasks | |
136 // are not blocked even if they are expensive. Must be called on the main | |
137 // thread. | |
138 virtual void AddPendingNavigation( | |
139 blink::WebScheduler::NavigatingFrameType type) = 0; | |
140 | |
141 // Tells the scheduler that a navigation task is no longer pending. | |
142 // Must be called on the main thread. | |
143 virtual void RemovePendingNavigation( | |
144 blink::WebScheduler::NavigatingFrameType type) = 0; | |
145 | |
146 // Tells the scheduler that a navigation has started. The scheduler will | |
147 // prioritize loading tasks for a short duration afterwards. | |
148 // Must be called from the main thread. | |
149 virtual void OnNavigationStarted() = 0; | |
150 | |
151 // Returns true if the scheduler has reason to believe that high priority work | |
152 // may soon arrive on the main thread, e.g., if gesture events were observed | |
153 // recently. | |
154 // Must be called from the main thread. | |
155 virtual bool IsHighPriorityWorkAnticipated() = 0; | |
156 | |
157 // Suspends the timer queue and increments the timer queue suspension count. | |
158 // May only be called from the main thread. | |
159 virtual void SuspendTimerQueue() = 0; | |
160 | |
161 // Decrements the timer queue suspension count and re-enables the timer queue | |
162 // if the suspension count is zero and the current schduler policy allows it. | |
163 virtual void ResumeTimerQueue() = 0; | |
164 | |
165 // Sets whether to allow suspension of timers after the backgrounded signal is | |
166 // received via OnRendererBackgrounded. Defaults to disabled. | |
167 virtual void SetTimerQueueSuspensionWhenBackgroundedEnabled(bool enabled) = 0; | |
168 | |
169 // Sets the default blame context to which top level work should be | |
170 // attributed in this renderer. |blame_context| must outlive this scheduler. | |
171 virtual void SetTopLevelBlameContext( | |
172 base::trace_event::BlameContext* blame_context) = 0; | |
173 | |
174 // The renderer scheduler maintains an estimated RAIL mode[1]. This observer | |
175 // can be used to get notified when the mode changes. The observer will be | |
176 // called on the main thread and must outlive this class. | |
177 // [1] | |
178 // https://developers.google.com/web/tools/chrome-devtools/profile/evaluate-pe
rformance/rail | |
179 virtual void SetRAILModeObserver(RAILModeObserver* observer) = 0; | |
180 | |
181 protected: | |
182 RendererScheduler(); | |
183 DISALLOW_COPY_AND_ASSIGN(RendererScheduler); | |
184 }; | |
185 | |
186 } // namespace scheduler | |
187 | |
188 #endif // COMPONENTS_SCHEDULER_RENDERER_RENDERER_SCHEDULER_H_ | |
OLD | NEW |