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

Side by Side Diff: cc/trees/thread_proxy.h

Issue 1417053005: cc: Split ThreadProxy into ProxyMain and ProxyImpl (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 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 2011 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 CC_TREES_THREAD_PROXY_H_
6 #define CC_TREES_THREAD_PROXY_H_
7
8 #include <string>
9
10 #include "base/memory/scoped_ptr.h"
11 #include "base/memory/weak_ptr.h"
12 #include "base/time/time.h"
13 #include "cc/animation/animation_events.h"
14 #include "cc/base/completion_event.h"
15 #include "cc/base/delayed_unique_notifier.h"
16 #include "cc/scheduler/commit_earlyout_reason.h"
17 #include "cc/scheduler/scheduler.h"
18 #include "cc/trees/layer_tree_host_impl.h"
19 #include "cc/trees/proxy.h"
20 #include "cc/trees/threaded_channel.h"
21
22 namespace base {
23 class SingleThreadTaskRunner;
24 }
25
26 namespace cc {
27
28 class BeginFrameSource;
29 class ChannelImpl;
30 class ChannelMain;
31 class ContextProvider;
32 class InputHandlerClient;
33 class LayerTreeHost;
34 class ProxyImpl;
35 class ProxyMain;
36 class Scheduler;
37 class ScopedThreadProxy;
38 class ThreadedChannel;
39
40 class CC_EXPORT ThreadProxy : public Proxy,
41 public ProxyMain,
42 public ProxyImpl,
43 NON_EXPORTED_BASE(LayerTreeHostImplClient),
44 NON_EXPORTED_BASE(SchedulerClient) {
45 public:
46 static scoped_ptr<Proxy> Create(
47 LayerTreeHost* layer_tree_host,
48 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner,
49 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner,
50 scoped_ptr<BeginFrameSource> external_begin_frame_source);
51
52 ~ThreadProxy() override;
53
54 // Commits between the main and impl threads are processed through a pipeline
55 // with the following stages. For efficiency we can early out at any stage if
56 // we decide that no further processing is necessary.
57 enum CommitPipelineStage {
58 NO_PIPELINE_STAGE,
59 ANIMATE_PIPELINE_STAGE,
60 UPDATE_LAYERS_PIPELINE_STAGE,
61 COMMIT_PIPELINE_STAGE,
62 };
63
64 struct MainThreadOnly {
65 MainThreadOnly(ThreadProxy* proxy, LayerTreeHost* layer_tree_host);
66 ~MainThreadOnly();
67
68 const int layer_tree_host_id;
69
70 LayerTreeHost* layer_tree_host;
71
72 // The furthest pipeline stage which has been requested for the next
73 // commit.
74 CommitPipelineStage max_requested_pipeline_stage;
75 // The commit pipeline stage that is currently being processed.
76 CommitPipelineStage current_pipeline_stage;
77 // The commit pipeline stage at which processing for the current commit
78 // will stop. Only valid while we are executing the pipeline (i.e.,
79 // |current_pipeline_stage| is set to a pipeline stage).
80 CommitPipelineStage final_pipeline_stage;
81
82 bool commit_waits_for_activation;
83
84 bool started;
85 bool prepare_tiles_pending;
86 bool defer_commits;
87
88 RendererCapabilities renderer_capabilities_main_thread_copy;
89
90 // TODO(khushalsagar): Make this scoped_ptr<ChannelMain> when ProxyMain
91 // and ProxyImpl are split.
92 ChannelMain* channel_main;
93
94 base::WeakPtrFactory<ThreadProxy> weak_factory;
95 };
96
97 // Accessed on the impl thread when the main thread is blocked for a commit.
98 struct BlockedMainCommitOnly {
99 BlockedMainCommitOnly();
100 ~BlockedMainCommitOnly();
101 LayerTreeHost* layer_tree_host;
102 };
103
104 struct CompositorThreadOnly {
105 CompositorThreadOnly(
106 ThreadProxy* proxy,
107 int layer_tree_host_id,
108 RenderingStatsInstrumentation* rendering_stats_instrumentation,
109 scoped_ptr<BeginFrameSource> external_begin_frame_source);
110 ~CompositorThreadOnly();
111
112 const int layer_tree_host_id;
113
114 scoped_ptr<Scheduler> scheduler;
115
116 // Set when the main thread is waiting on a pending tree activation.
117 bool next_commit_waits_for_activation;
118
119 // Set when the main thread is waiting on a commit to complete or on a
120 // pending tree activation.
121 CompletionEvent* commit_completion_event;
122
123 // Set when the next draw should post DidCommitAndDrawFrame to the main
124 // thread.
125 bool next_frame_is_newly_committed_frame;
126
127 bool inside_draw;
128
129 bool input_throttled_until_commit;
130
131 // Whether a commit has been completed since the last time animations were
132 // ticked. If this happens, we need to animate again.
133 bool did_commit_after_animating;
134
135 DelayedUniqueNotifier smoothness_priority_expiration_notifier;
136
137 scoped_ptr<BeginFrameSource> external_begin_frame_source;
138
139 RenderingStatsInstrumentation* rendering_stats_instrumentation;
140
141 // Values used to keep track of frame durations. Used only in frame timing.
142 BeginFrameArgs last_begin_main_frame_args;
143 BeginFrameArgs last_processed_begin_main_frame_args;
144
145 scoped_ptr<LayerTreeHostImpl> layer_tree_host_impl;
146
147 ChannelImpl* channel_impl;
148
149 base::WeakPtrFactory<ThreadProxy> weak_factory;
150 };
151
152 const MainThreadOnly& main() const;
153 const CompositorThreadOnly& impl() const;
154
155 // Proxy implementation
156 void FinishAllRendering() override;
157 bool IsStarted() const override;
158 bool CommitToActiveTree() const override;
159 void SetOutputSurface(OutputSurface* output_surface) override;
160 void SetVisible(bool visible) override;
161 void SetThrottleFrameProduction(bool throttle) override;
162 const RendererCapabilities& GetRendererCapabilities() const override;
163 void SetNeedsAnimate() override;
164 void SetNeedsUpdateLayers() override;
165 void SetNeedsCommit() override;
166 void SetNeedsRedraw(const gfx::Rect& damage_rect) override;
167 void SetNextCommitWaitsForActivation() override;
168 void NotifyInputThrottledUntilCommit() override;
169 void SetDeferCommits(bool defer_commits) override;
170 bool CommitRequested() const override;
171 bool BeginMainFrameRequested() const override;
172 void MainThreadHasStoppedFlinging() override;
173 void Start() override;
174 void Stop() override;
175 bool SupportsImplScrolling() const override;
176 bool MainFrameWillHappenForTesting() override;
177 void SetChildrenNeedBeginFrames(bool children_need_begin_frames) override;
178 void SetAuthoritativeVSyncInterval(const base::TimeDelta& interval) override;
179 void ReleaseOutputSurface() override;
180 void UpdateTopControlsState(TopControlsState constraints,
181 TopControlsState current,
182 bool animate) override;
183
184 // LayerTreeHostImplClient implementation
185 void UpdateRendererCapabilitiesOnImplThread() override;
186 void DidLoseOutputSurfaceOnImplThread() override;
187 void CommitVSyncParameters(base::TimeTicks timebase,
188 base::TimeDelta interval) override;
189 void SetEstimatedParentDrawTime(base::TimeDelta draw_time) override;
190 void SetMaxSwapsPendingOnImplThread(int max) override;
191 void DidSwapBuffersOnImplThread() override;
192 void DidSwapBuffersCompleteOnImplThread() override;
193 void OnResourcelessSoftareDrawStateChanged(bool resourceless_draw) override;
194 void OnCanDrawStateChanged(bool can_draw) override;
195 void NotifyReadyToActivate() override;
196 void NotifyReadyToDraw() override;
197 // Please call these 3 functions through
198 // LayerTreeHostImpl's SetNeedsRedraw(), SetNeedsRedrawRect() and
199 // SetNeedsAnimate().
200 void SetNeedsRedrawOnImplThread() override;
201 void SetNeedsRedrawRectOnImplThread(const gfx::Rect& dirty_rect) override;
202 void SetNeedsAnimateOnImplThread() override;
203 void SetNeedsPrepareTilesOnImplThread() override;
204 void SetNeedsCommitOnImplThread() override;
205 void SetVideoNeedsBeginFrames(bool needs_begin_frames) override;
206 void PostAnimationEventsToMainThreadOnImplThread(
207 scoped_ptr<AnimationEventsVector> queue) override;
208 bool IsInsideDraw() override;
209 void RenewTreePriority() override;
210 void PostDelayedAnimationTaskOnImplThread(const base::Closure& task,
211 base::TimeDelta delay) override;
212 void DidActivateSyncTree() override;
213 void WillPrepareTiles() override;
214 void DidPrepareTiles() override;
215 void DidCompletePageScaleAnimationOnImplThread() override;
216 void OnDrawForOutputSurface() override;
217 // This should only be called by LayerTreeHostImpl::PostFrameTimingEvents.
218 void PostFrameTimingEventsOnImplThread(
219 scoped_ptr<FrameTimingTracker::CompositeTimingSet> composite_events,
220 scoped_ptr<FrameTimingTracker::MainFrameTimingSet> main_frame_events)
221 override;
222
223 // SchedulerClient implementation
224 void WillBeginImplFrame(const BeginFrameArgs& args) override;
225 void DidFinishImplFrame() override;
226 void ScheduledActionSendBeginMainFrame() override;
227 DrawResult ScheduledActionDrawAndSwapIfPossible() override;
228 DrawResult ScheduledActionDrawAndSwapForced() override;
229 void ScheduledActionAnimate() override;
230 void ScheduledActionCommit() override;
231 void ScheduledActionActivateSyncTree() override;
232 void ScheduledActionBeginOutputSurfaceCreation() override;
233 void ScheduledActionPrepareTiles() override;
234 void ScheduledActionInvalidateOutputSurface() override;
235 void SendBeginFramesToChildren(const BeginFrameArgs& args) override;
236 void SendBeginMainFrameNotExpectedSoon() override;
237
238 // ProxyMain implementation
239 void SetChannel(scoped_ptr<ThreadedChannel> threaded_channel) override;
240
241 protected:
242 ThreadProxy(
243 LayerTreeHost* layer_tree_host,
244 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner,
245 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner,
246 scoped_ptr<BeginFrameSource> external_begin_frame_source);
247
248 private:
249 friend class ThreadProxyForTest;
250
251 // ProxyMain implementation.
252 base::WeakPtr<ProxyMain> GetMainWeakPtr() override;
253 void DidCompleteSwapBuffers() override;
254 void SetRendererCapabilitiesMainCopy(
255 const RendererCapabilities& capabilities) override;
256 void BeginMainFrameNotExpectedSoon() override;
257 void DidCommitAndDrawFrame() override;
258 void SetAnimationEvents(scoped_ptr<AnimationEventsVector> queue) override;
259 void DidLoseOutputSurface() override;
260 void RequestNewOutputSurface() override;
261 void DidInitializeOutputSurface(
262 bool success,
263 const RendererCapabilities& capabilities) override;
264 void DidCompletePageScaleAnimation() override;
265 void PostFrameTimingEventsOnMain(
266 scoped_ptr<FrameTimingTracker::CompositeTimingSet> composite_events,
267 scoped_ptr<FrameTimingTracker::MainFrameTimingSet> main_frame_events)
268 override;
269 void BeginMainFrame(
270 scoped_ptr<BeginMainFrameAndCommitState> begin_main_frame_state) override;
271
272 // ProxyImpl implementation
273 base::WeakPtr<ProxyImpl> GetImplWeakPtr() override;
274 void SetThrottleFrameProductionOnImpl(bool throttle) override;
275 void UpdateTopControlsStateOnImpl(TopControlsState constraints,
276 TopControlsState current,
277 bool animate) override;
278 void InitializeOutputSurfaceOnImpl(OutputSurface* output_surface) override;
279 void MainThreadHasStoppedFlingingOnImpl() override;
280 void SetInputThrottledUntilCommitOnImpl(bool is_throttled) override;
281 void SetDeferCommitsOnImpl(bool defer_commits) const override;
282 void FinishAllRenderingOnImpl(CompletionEvent* completion) override;
283 void SetVisibleOnImpl(bool visible) override;
284 void ReleaseOutputSurfaceOnImpl(CompletionEvent* completion) override;
285 void FinishGLOnImpl(CompletionEvent* completion) override;
286 void MainFrameWillHappenOnImplForTesting(
287 CompletionEvent* completion,
288 bool* main_frame_will_happen) override;
289 void SetNeedsCommitOnImpl() override;
290 void SetNeedsRedrawOnImpl(const gfx::Rect& damage_rect) override;
291 void BeginMainFrameAbortedOnImpl(CommitEarlyOutReason reason) override;
292 void StartCommitOnImpl(CompletionEvent* completion,
293 LayerTreeHost* layer_tree_host,
294 bool hold_commit_for_activation) override;
295 void InitializeImplOnImpl(CompletionEvent* completion,
296 LayerTreeHost* layer_tree_host) override;
297 void LayerTreeHostClosedOnImpl(CompletionEvent* completion) override;
298
299 // Returns |true| if the request was actually sent, |false| if one was
300 // already outstanding.
301 bool SendCommitRequestToImplThreadIfNeeded(
302 CommitPipelineStage required_stage);
303
304 // Called on impl thread.
305 struct SchedulerStateRequest;
306
307 DrawResult DrawSwapInternal(bool forced_draw);
308
309 // Use accessors instead of this variable directly.
310 MainThreadOnly main_thread_only_vars_unsafe_;
311 MainThreadOnly& main();
312
313 // Use accessors instead of this variable directly.
314 BlockedMainCommitOnly main_thread_blocked_commit_vars_unsafe_;
315 BlockedMainCommitOnly& blocked_main_commit();
316
317 // Use accessors instead of this variable directly.
318 CompositorThreadOnly compositor_thread_vars_unsafe_;
319 CompositorThreadOnly& impl();
320
321 // TODO(khushalsagar): Remove this. Temporary variable to hold the channel.
322 scoped_ptr<ThreadedChannel> threaded_channel_;
323
324 base::WeakPtr<ThreadProxy> main_thread_weak_ptr_;
325 base::WeakPtr<ThreadProxy> impl_thread_weak_ptr_;
326
327 DISALLOW_COPY_AND_ASSIGN(ThreadProxy);
328 };
329
330 } // namespace cc
331
332 #endif // CC_TREES_THREAD_PROXY_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698