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

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: Change ThreadedChannel::GetProxyImpl to GetProxyImplForTesting 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 TaskRunnerProvider* task_runner_provider,
49 scoped_ptr<BeginFrameSource> external_begin_frame_source);
50
51 ~ThreadProxy() override;
52
53 // Commits between the main and impl threads are processed through a pipeline
54 // with the following stages. For efficiency we can early out at any stage if
55 // we decide that no further processing is necessary.
56 enum CommitPipelineStage {
57 NO_PIPELINE_STAGE,
58 ANIMATE_PIPELINE_STAGE,
59 UPDATE_LAYERS_PIPELINE_STAGE,
60 COMMIT_PIPELINE_STAGE,
61 };
62
63 struct MainThreadOnly {
64 MainThreadOnly(ThreadProxy* proxy, LayerTreeHost* layer_tree_host);
65 ~MainThreadOnly();
66
67 const int layer_tree_host_id;
68
69 LayerTreeHost* layer_tree_host;
70
71 // The furthest pipeline stage which has been requested for the next
72 // commit.
73 CommitPipelineStage max_requested_pipeline_stage;
74 // The commit pipeline stage that is currently being processed.
75 CommitPipelineStage current_pipeline_stage;
76 // The commit pipeline stage at which processing for the current commit
77 // will stop. Only valid while we are executing the pipeline (i.e.,
78 // |current_pipeline_stage| is set to a pipeline stage).
79 CommitPipelineStage final_pipeline_stage;
80
81 bool commit_waits_for_activation;
82
83 bool started;
84 bool prepare_tiles_pending;
85 bool defer_commits;
86
87 RendererCapabilities renderer_capabilities_main_thread_copy;
88
89 // TODO(khushalsagar): Make this scoped_ptr<ChannelMain> when ProxyMain
90 // and ProxyImpl are split.
91 ChannelMain* channel_main;
92
93 base::WeakPtrFactory<ThreadProxy> weak_factory;
94 };
95
96 // Accessed on the impl thread when the main thread is blocked for a commit.
97 struct BlockedMainCommitOnly {
98 BlockedMainCommitOnly();
99 ~BlockedMainCommitOnly();
100 LayerTreeHost* layer_tree_host;
101 };
102
103 struct CompositorThreadOnly {
104 CompositorThreadOnly(
105 ThreadProxy* proxy,
106 int layer_tree_host_id,
107 RenderingStatsInstrumentation* rendering_stats_instrumentation,
108 scoped_ptr<BeginFrameSource> external_begin_frame_source);
109 ~CompositorThreadOnly();
110
111 const int layer_tree_host_id;
112
113 scoped_ptr<Scheduler> scheduler;
114
115 // Set when the main thread is waiting on a pending tree activation.
116 bool next_commit_waits_for_activation;
117
118 // Set when the main thread is waiting on a commit to complete or on a
119 // pending tree activation.
120 CompletionEvent* commit_completion_event;
121
122 // Set when the next draw should post DidCommitAndDrawFrame to the main
123 // thread.
124 bool next_frame_is_newly_committed_frame;
125
126 bool inside_draw;
127
128 bool input_throttled_until_commit;
129
130 // Whether a commit has been completed since the last time animations were
131 // ticked. If this happens, we need to animate again.
132 bool did_commit_after_animating;
133
134 DelayedUniqueNotifier smoothness_priority_expiration_notifier;
135
136 scoped_ptr<BeginFrameSource> external_begin_frame_source;
137
138 RenderingStatsInstrumentation* rendering_stats_instrumentation;
139
140 // Values used to keep track of frame durations. Used only in frame timing.
141 BeginFrameArgs last_begin_main_frame_args;
142 BeginFrameArgs last_processed_begin_main_frame_args;
143
144 scoped_ptr<LayerTreeHostImpl> layer_tree_host_impl;
145
146 ChannelImpl* channel_impl;
147
148 base::WeakPtrFactory<ThreadProxy> weak_factory;
149 };
150
151 const MainThreadOnly& main() const;
152 const CompositorThreadOnly& impl() const;
153 TaskRunnerProvider* task_runner_provider() { return task_runner_provider_; }
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(const BeginFrameArgs& args) 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(LayerTreeHost* layer_tree_host,
243 TaskRunnerProvider* task_runner_provider,
244 scoped_ptr<BeginFrameSource> external_begin_frame_source);
245
246 private:
247 friend class ThreadProxyForTest;
248
249 // ProxyMain implementation.
250 base::WeakPtr<ProxyMain> GetMainWeakPtr() override;
251 void DidCompleteSwapBuffers() override;
252 void SetRendererCapabilitiesMainCopy(
253 const RendererCapabilities& capabilities) override;
254 void BeginMainFrameNotExpectedSoon() override;
255 void DidCommitAndDrawFrame() override;
256 void SetAnimationEvents(scoped_ptr<AnimationEventsVector> queue) override;
257 void DidLoseOutputSurface() override;
258 void RequestNewOutputSurface() override;
259 void DidInitializeOutputSurface(
260 bool success,
261 const RendererCapabilities& capabilities) override;
262 void DidCompletePageScaleAnimation() override;
263 void PostFrameTimingEventsOnMain(
264 scoped_ptr<FrameTimingTracker::CompositeTimingSet> composite_events,
265 scoped_ptr<FrameTimingTracker::MainFrameTimingSet> main_frame_events)
266 override;
267 void BeginMainFrame(
268 scoped_ptr<BeginMainFrameAndCommitState> begin_main_frame_state) override;
269
270 // ProxyImpl implementation
271 base::WeakPtr<ProxyImpl> GetImplWeakPtr() override;
272 void SetThrottleFrameProductionOnImpl(bool throttle) override;
273 void UpdateTopControlsStateOnImpl(TopControlsState constraints,
274 TopControlsState current,
275 bool animate) override;
276 void InitializeOutputSurfaceOnImpl(OutputSurface* output_surface) override;
277 void MainThreadHasStoppedFlingingOnImpl() override;
278 void SetInputThrottledUntilCommitOnImpl(bool is_throttled) override;
279 void SetDeferCommitsOnImpl(bool defer_commits) const override;
280 void FinishAllRenderingOnImpl(CompletionEvent* completion) override;
281 void SetVisibleOnImpl(bool visible) override;
282 void ReleaseOutputSurfaceOnImpl(CompletionEvent* completion) override;
283 void FinishGLOnImpl(CompletionEvent* completion) override;
284 void MainFrameWillHappenOnImplForTesting(
285 CompletionEvent* completion,
286 bool* main_frame_will_happen) override;
287 void SetNeedsCommitOnImpl() override;
288 void SetNeedsRedrawOnImpl(const gfx::Rect& damage_rect) override;
289 void BeginMainFrameAbortedOnImpl(
290 CommitEarlyOutReason reason,
291 base::TimeTicks main_thread_start_time) override;
292 void StartCommitOnImpl(CompletionEvent* completion,
293 LayerTreeHost* layer_tree_host,
294 base::TimeTicks main_thread_start_time,
295 bool hold_commit_for_activation) override;
296 void InitializeImplOnImpl(CompletionEvent* completion,
297 LayerTreeHost* layer_tree_host) override;
298 void LayerTreeHostClosedOnImpl(CompletionEvent* completion) override;
299
300 // Returns |true| if the request was actually sent, |false| if one was
301 // already outstanding.
302 bool SendCommitRequestToImplThreadIfNeeded(
303 CommitPipelineStage required_stage);
304
305 // Called on impl thread.
306 struct SchedulerStateRequest;
307
308 DrawResult DrawSwapInternal(bool forced_draw);
309
310 TaskRunnerProvider* task_runner_provider_;
311
312 // Use accessors instead of this variable directly.
313 MainThreadOnly main_thread_only_vars_unsafe_;
314 MainThreadOnly& main();
315
316 // Use accessors instead of this variable directly.
317 BlockedMainCommitOnly main_thread_blocked_commit_vars_unsafe_;
318 BlockedMainCommitOnly& blocked_main_commit();
319
320 // Use accessors instead of this variable directly.
321 CompositorThreadOnly compositor_thread_vars_unsafe_;
322 CompositorThreadOnly& impl();
323
324 // TODO(khushalsagar): Remove this. Temporary variable to hold the channel.
325 scoped_ptr<ThreadedChannel> threaded_channel_;
326
327 base::WeakPtr<ThreadProxy> main_thread_weak_ptr_;
328 base::WeakPtr<ThreadProxy> impl_thread_weak_ptr_;
329
330 DISALLOW_COPY_AND_ASSIGN(ThreadProxy);
331 };
332
333 } // namespace cc
334
335 #endif // CC_TREES_THREAD_PROXY_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698