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

Side by Side Diff: cc/trees/threaded_channel.cc

Issue 2513863002: cc: Delete channel abstraction between proxies. (Closed)
Patch Set: Rebase Created 4 years 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
« no previous file with comments | « cc/trees/threaded_channel.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2015 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 #include "cc/trees/threaded_channel.h"
6
7 #include "base/bind.h"
8 #include "base/bind_helpers.h"
9 #include "base/memory/ptr_util.h"
10 #include "base/single_thread_task_runner.h"
11 #include "base/trace_event/trace_event.h"
12 #include "cc/trees/layer_tree_host.h"
13 #include "cc/trees/layer_tree_mutator.h"
14 #include "cc/trees/mutator_host.h"
15
16 namespace cc {
17
18 std::unique_ptr<ThreadedChannel> ThreadedChannel::Create(
19 ProxyMain* proxy_main,
20 TaskRunnerProvider* task_runner_provider) {
21 return base::WrapUnique(
22 new ThreadedChannel(proxy_main, task_runner_provider));
23 }
24
25 ThreadedChannel::ThreadedChannel(ProxyMain* proxy_main,
26 TaskRunnerProvider* task_runner_provider)
27 : task_runner_provider_(task_runner_provider),
28 main_thread_only_vars_unsafe_(proxy_main),
29 compositor_thread_vars_unsafe_(
30 main().proxy_main_weak_factory.GetWeakPtr()) {
31 DCHECK(IsMainThread());
32 }
33
34 ThreadedChannel::~ThreadedChannel() {
35 TRACE_EVENT0("cc", "ThreadChannel::~ThreadChannel");
36 DCHECK(IsMainThread());
37 DCHECK(!IsInitialized());
38 }
39
40 void ThreadedChannel::UpdateBrowserControlsStateOnImpl(
41 BrowserControlsState constraints,
42 BrowserControlsState current,
43 bool animate) {
44 DCHECK(IsMainThread());
45 ImplThreadTaskRunner()->PostTask(
46 FROM_HERE,
47 base::Bind(&ProxyImpl::UpdateBrowserControlsStateOnImpl,
48 proxy_impl_weak_ptr_, constraints, current, animate));
49 }
50
51 void ThreadedChannel::InitializeCompositorFrameSinkOnImpl(
52 CompositorFrameSink* output_surface) {
53 DCHECK(IsMainThread());
54 ImplThreadTaskRunner()->PostTask(
55 FROM_HERE, base::Bind(&ProxyImpl::InitializeCompositorFrameSinkOnImpl,
56 proxy_impl_weak_ptr_, output_surface));
57 }
58
59 void ThreadedChannel::InitializeMutatorOnImpl(
60 std::unique_ptr<LayerTreeMutator> mutator) {
61 ImplThreadTaskRunner()->PostTask(
62 FROM_HERE,
63 base::Bind(&ProxyImpl::InitializeMutatorOnImpl, proxy_impl_weak_ptr_,
64 base::Passed(std::move(mutator))));
65 }
66
67 void ThreadedChannel::MainThreadHasStoppedFlingingOnImpl() {
68 DCHECK(IsMainThread());
69 ImplThreadTaskRunner()->PostTask(
70 FROM_HERE, base::Bind(&ProxyImpl::MainThreadHasStoppedFlingingOnImpl,
71 proxy_impl_weak_ptr_));
72 }
73
74 void ThreadedChannel::SetInputThrottledUntilCommitOnImpl(bool is_throttled) {
75 DCHECK(IsMainThread());
76 ImplThreadTaskRunner()->PostTask(
77 FROM_HERE, base::Bind(&ProxyImpl::SetInputThrottledUntilCommitOnImpl,
78 proxy_impl_weak_ptr_, is_throttled));
79 }
80
81 void ThreadedChannel::SetDeferCommitsOnImpl(bool defer_commits) {
82 DCHECK(IsMainThread());
83 ImplThreadTaskRunner()->PostTask(
84 FROM_HERE, base::Bind(&ProxyImpl::SetDeferCommitsOnImpl,
85 proxy_impl_weak_ptr_, defer_commits));
86 }
87
88 void ThreadedChannel::SetNeedsCommitOnImpl() {
89 DCHECK(IsMainThread());
90 ImplThreadTaskRunner()->PostTask(
91 FROM_HERE,
92 base::Bind(&ProxyImpl::SetNeedsCommitOnImpl, proxy_impl_weak_ptr_));
93 }
94
95 void ThreadedChannel::BeginMainFrameAbortedOnImpl(
96 CommitEarlyOutReason reason,
97 base::TimeTicks main_thread_start_time,
98 std::vector<std::unique_ptr<SwapPromise>> swap_promises) {
99 DCHECK(IsMainThread());
100 ImplThreadTaskRunner()->PostTask(
101 FROM_HERE,
102 base::Bind(&ProxyImpl::BeginMainFrameAbortedOnImpl, proxy_impl_weak_ptr_,
103 reason, main_thread_start_time, base::Passed(&swap_promises)));
104 }
105
106 void ThreadedChannel::SetNeedsRedrawOnImpl(const gfx::Rect& damage_rect) {
107 DCHECK(IsMainThread());
108 ImplThreadTaskRunner()->PostTask(
109 FROM_HERE, base::Bind(&ProxyImpl::SetNeedsRedrawOnImpl,
110 proxy_impl_weak_ptr_, damage_rect));
111 }
112
113 void ThreadedChannel::SetVisibleOnImpl(bool visible) {
114 DCHECK(IsMainThread());
115 ImplThreadTaskRunner()->PostTask(
116 FROM_HERE,
117 base::Bind(&ProxyImpl::SetVisibleOnImpl, proxy_impl_weak_ptr_, visible));
118 }
119
120 void ThreadedChannel::ReleaseCompositorFrameSinkOnImpl(
121 CompletionEvent* completion) {
122 DCHECK(IsMainThread());
123 ImplThreadTaskRunner()->PostTask(
124 FROM_HERE, base::Bind(&ProxyImpl::ReleaseCompositorFrameSinkOnImpl,
125 proxy_impl_weak_ptr_, completion));
126 }
127
128 void ThreadedChannel::MainFrameWillHappenOnImplForTesting(
129 CompletionEvent* completion,
130 bool* main_frame_will_happen) {
131 DCHECK(IsMainThread());
132 ImplThreadTaskRunner()->PostTask(
133 FROM_HERE,
134 base::Bind(&ProxyImpl::MainFrameWillHappenOnImplForTesting,
135 proxy_impl_weak_ptr_, completion, main_frame_will_happen));
136 }
137
138 void ThreadedChannel::NotifyReadyToCommitOnImpl(
139 CompletionEvent* completion,
140 LayerTreeHostInProcess* layer_tree_host,
141 base::TimeTicks main_thread_start_time,
142 bool hold_commit_for_activation) {
143 DCHECK(IsMainThread());
144 ImplThreadTaskRunner()->PostTask(
145 FROM_HERE,
146 base::Bind(&ProxyImpl::NotifyReadyToCommitOnImpl, proxy_impl_weak_ptr_,
147 completion, layer_tree_host, main_thread_start_time,
148 hold_commit_for_activation));
149 }
150
151 void ThreadedChannel::SynchronouslyInitializeImpl(
152 LayerTreeHostInProcess* layer_tree_host) {
153 TRACE_EVENT0("cc", "ThreadChannel::SynchronouslyInitializeImpl");
154 DCHECK(IsMainThread());
155 {
156 DebugScopedSetMainThreadBlocked main_thread_blocked(task_runner_provider_);
157 CompletionEvent completion;
158 ImplThreadTaskRunner()->PostTask(
159 FROM_HERE,
160 base::Bind(&ThreadedChannel::InitializeImplOnImpl,
161 base::Unretained(this), &completion, layer_tree_host));
162 completion.Wait();
163 }
164 main().initialized = true;
165 }
166
167 void ThreadedChannel::SynchronouslyCloseImpl() {
168 TRACE_EVENT0("cc", "ThreadChannel::~SynchronouslyCloseImpl");
169 DCHECK(IsMainThread());
170
171 // Synchronously finishes pending GL operations and deletes the impl.
172 // The two steps are done as separate post tasks, so that tasks posted
173 // by the GL implementation due to the Finish can be executed by the
174 // renderer before shutting it down.
175 {
176 DebugScopedSetMainThreadBlocked main_thread_blocked(task_runner_provider_);
177 CompletionEvent completion;
178 ImplThreadTaskRunner()->PostTask(
179 FROM_HERE, base::Bind(&ProxyImpl::FinishGLOnImpl, proxy_impl_weak_ptr_,
180 &completion));
181 completion.Wait();
182 }
183 {
184 DebugScopedSetMainThreadBlocked main_thread_blocked(task_runner_provider_);
185 CompletionEvent completion;
186 ImplThreadTaskRunner()->PostTask(
187 FROM_HERE, base::Bind(&ThreadedChannel::CloseImplOnImpl,
188 base::Unretained(this), &completion));
189 completion.Wait();
190 }
191 main().proxy_main_weak_factory.InvalidateWeakPtrs();
192 main().initialized = false;
193 }
194
195 void ThreadedChannel::DidReceiveCompositorFrameAck() {
196 DCHECK(IsImplThread());
197 MainThreadTaskRunner()->PostTask(
198 FROM_HERE, base::Bind(&ProxyMain::DidReceiveCompositorFrameAck,
199 impl().proxy_main_weak_ptr));
200 }
201
202 void ThreadedChannel::BeginMainFrameNotExpectedSoon() {
203 DCHECK(IsImplThread());
204 MainThreadTaskRunner()->PostTask(
205 FROM_HERE, base::Bind(&ProxyMain::BeginMainFrameNotExpectedSoon,
206 impl().proxy_main_weak_ptr));
207 }
208
209 void ThreadedChannel::DidCommitAndDrawFrame() {
210 DCHECK(IsImplThread());
211 MainThreadTaskRunner()->PostTask(FROM_HERE,
212 base::Bind(&ProxyMain::DidCommitAndDrawFrame,
213 impl().proxy_main_weak_ptr));
214 }
215
216 void ThreadedChannel::SetAnimationEvents(
217 std::unique_ptr<MutatorEvents> events) {
218 DCHECK(IsImplThread());
219 MainThreadTaskRunner()->PostTask(
220 FROM_HERE, base::Bind(&ProxyMain::SetAnimationEvents,
221 impl().proxy_main_weak_ptr, base::Passed(&events)));
222 }
223
224 void ThreadedChannel::DidLoseCompositorFrameSink() {
225 DCHECK(IsImplThread());
226 MainThreadTaskRunner()->PostTask(
227 FROM_HERE, base::Bind(&ProxyMain::DidLoseCompositorFrameSink,
228 impl().proxy_main_weak_ptr));
229 }
230
231 void ThreadedChannel::RequestNewCompositorFrameSink() {
232 DCHECK(IsImplThread());
233 MainThreadTaskRunner()->PostTask(
234 FROM_HERE, base::Bind(&ProxyMain::RequestNewCompositorFrameSink,
235 impl().proxy_main_weak_ptr));
236 }
237
238 void ThreadedChannel::DidInitializeCompositorFrameSink(bool success) {
239 DCHECK(IsImplThread());
240 MainThreadTaskRunner()->PostTask(
241 FROM_HERE, base::Bind(&ProxyMain::DidInitializeCompositorFrameSink,
242 impl().proxy_main_weak_ptr, success));
243 }
244
245 void ThreadedChannel::DidCompletePageScaleAnimation() {
246 DCHECK(IsImplThread());
247 MainThreadTaskRunner()->PostTask(
248 FROM_HERE, base::Bind(&ProxyMain::DidCompletePageScaleAnimation,
249 impl().proxy_main_weak_ptr));
250 }
251
252 void ThreadedChannel::BeginMainFrame(
253 std::unique_ptr<BeginMainFrameAndCommitState> begin_main_frame_state) {
254 DCHECK(IsImplThread());
255 MainThreadTaskRunner()->PostTask(
256 FROM_HERE,
257 base::Bind(&ProxyMain::BeginMainFrame, impl().proxy_main_weak_ptr,
258 base::Passed(&begin_main_frame_state)));
259 }
260
261 std::unique_ptr<ProxyImpl> ThreadedChannel::CreateProxyImpl(
262 ChannelImpl* channel_impl,
263 LayerTreeHostInProcess* layer_tree_host,
264 TaskRunnerProvider* task_runner_provider) {
265 DCHECK(IsImplThread());
266 return base::MakeUnique<ProxyImpl>(channel_impl, layer_tree_host,
267 task_runner_provider);
268 }
269
270 void ThreadedChannel::InitializeImplOnImpl(
271 CompletionEvent* completion,
272 LayerTreeHostInProcess* layer_tree_host) {
273 DCHECK(IsImplThread());
274 impl().proxy_impl =
275 CreateProxyImpl(this, layer_tree_host, task_runner_provider_);
276 impl().proxy_impl_weak_factory =
277 base::MakeUnique<base::WeakPtrFactory<ProxyImpl>>(
278 impl().proxy_impl.get());
279 proxy_impl_weak_ptr_ = impl().proxy_impl_weak_factory->GetWeakPtr();
280 completion->Signal();
281 }
282
283 void ThreadedChannel::CloseImplOnImpl(CompletionEvent* completion) {
284 DCHECK(IsImplThread());
285
286 // We must destroy the factory and ensure that the ProxyImpl weak pointers are
287 // invalidated before destroying proxy_impl.
288 impl().proxy_impl_weak_factory.reset();
289
290 impl().proxy_impl.reset();
291 completion->Signal();
292 }
293
294 bool ThreadedChannel::IsInitialized() const {
295 return main().initialized;
296 }
297
298 base::SingleThreadTaskRunner* ThreadedChannel::MainThreadTaskRunner() const {
299 return task_runner_provider_->MainThreadTaskRunner();
300 }
301
302 base::SingleThreadTaskRunner* ThreadedChannel::ImplThreadTaskRunner() const {
303 return task_runner_provider_->ImplThreadTaskRunner();
304 }
305
306 bool ThreadedChannel::IsMainThread() const {
307 return task_runner_provider_->IsMainThread();
308 }
309
310 bool ThreadedChannel::IsImplThread() const {
311 return task_runner_provider_->IsImplThread();
312 }
313
314 ThreadedChannel::MainThreadOnly& ThreadedChannel::main() {
315 DCHECK(task_runner_provider_->IsMainThread());
316 return main_thread_only_vars_unsafe_;
317 }
318
319 const ThreadedChannel::MainThreadOnly& ThreadedChannel::main() const {
320 DCHECK(task_runner_provider_->IsMainThread());
321 return main_thread_only_vars_unsafe_;
322 }
323
324 ThreadedChannel::CompositorThreadOnly& ThreadedChannel::impl() {
325 DCHECK(task_runner_provider_->IsImplThread());
326 return compositor_thread_vars_unsafe_;
327 }
328
329 const ThreadedChannel::CompositorThreadOnly& ThreadedChannel::impl() const {
330 DCHECK(task_runner_provider_->IsImplThread());
331 return compositor_thread_vars_unsafe_;
332 }
333
334 ThreadedChannel::MainThreadOnly::MainThreadOnly(ProxyMain* proxy_main)
335 : proxy_main_weak_factory(proxy_main), initialized(false) {}
336
337 ThreadedChannel::MainThreadOnly::~MainThreadOnly() {}
338
339 ThreadedChannel::CompositorThreadOnly::CompositorThreadOnly(
340 base::WeakPtr<ProxyMain> proxy_main_weak_ptr)
341 : proxy_main_weak_ptr(proxy_main_weak_ptr) {}
342
343 ThreadedChannel::CompositorThreadOnly::~CompositorThreadOnly() {}
344
345 } // namespace cc
OLDNEW
« no previous file with comments | « cc/trees/threaded_channel.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698