OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "cc/trees/threaded_channel.h" | 5 #include "cc/trees/threaded_channel.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/single_thread_task_runner.h" | 8 #include "base/single_thread_task_runner.h" |
9 #include "base/trace_event/trace_event.h" | 9 #include "base/trace_event/trace_event.h" |
10 #include "cc/trees/layer_tree_host.h" | |
11 | 10 |
12 namespace cc { | 11 namespace cc { |
13 | 12 |
14 ThreadedChannel::ThreadedChannel(ProxyMain* proxy_main, | 13 scoped_ptr<ThreadedChannel> ThreadedChannel::Create( |
| 14 ThreadProxy* thread_proxy, |
| 15 TaskRunnerProvider* task_runner_provider) { |
| 16 return make_scoped_ptr( |
| 17 new ThreadedChannel(thread_proxy, task_runner_provider)); |
| 18 } |
| 19 |
| 20 ThreadedChannel::ThreadedChannel(ThreadProxy* thread_proxy, |
15 TaskRunnerProvider* task_runner_provider) | 21 TaskRunnerProvider* task_runner_provider) |
16 : task_runner_provider_(task_runner_provider), | 22 : proxy_main_(thread_proxy), |
17 main_thread_only_vars_unsafe_(proxy_main), | 23 proxy_impl_(thread_proxy), |
18 compositor_thread_vars_unsafe_( | 24 task_runner_provider_(task_runner_provider) {} |
19 main() | |
20 .proxy_main_weak_factory.GetWeakPtr()) { | |
21 DCHECK(IsMainThread()); | |
22 } | |
23 | |
24 ThreadedChannel::~ThreadedChannel() { | |
25 TRACE_EVENT0("cc", "ThreadChannel::~ThreadChannel"); | |
26 DCHECK(IsMainThread()); | |
27 DCHECK(!IsInitialized()); | |
28 } | |
29 | 25 |
30 void ThreadedChannel::SetThrottleFrameProductionOnImpl(bool throttle) { | 26 void ThreadedChannel::SetThrottleFrameProductionOnImpl(bool throttle) { |
31 DCHECK(IsMainThread()); | |
32 ImplThreadTaskRunner()->PostTask( | 27 ImplThreadTaskRunner()->PostTask( |
33 FROM_HERE, base::Bind(&ProxyImpl::SetThrottleFrameProductionOnImpl, | 28 FROM_HERE, base::Bind(&ProxyImpl::SetThrottleFrameProductionOnImpl, |
34 proxy_impl_weak_ptr_, throttle)); | 29 proxy_impl_->GetImplWeakPtr(), throttle)); |
35 } | 30 } |
36 | 31 |
37 void ThreadedChannel::UpdateTopControlsStateOnImpl(TopControlsState constraints, | 32 void ThreadedChannel::UpdateTopControlsStateOnImpl(TopControlsState constraints, |
38 TopControlsState current, | 33 TopControlsState current, |
39 bool animate) { | 34 bool animate) { |
40 DCHECK(IsMainThread()); | 35 ImplThreadTaskRunner()->PostTask( |
41 ImplThreadTaskRunner()->PostTask( | 36 FROM_HERE, |
42 FROM_HERE, | 37 base::Bind(&ProxyImpl::UpdateTopControlsStateOnImpl, |
43 base::Bind(&ProxyImpl::UpdateTopControlsStateOnImpl, proxy_impl_weak_ptr_, | 38 proxy_impl_->GetImplWeakPtr(), constraints, current, animate)); |
44 constraints, current, animate)); | |
45 } | 39 } |
46 | 40 |
47 void ThreadedChannel::InitializeOutputSurfaceOnImpl( | 41 void ThreadedChannel::InitializeOutputSurfaceOnImpl( |
48 OutputSurface* output_surface) { | 42 OutputSurface* output_surface) { |
49 DCHECK(IsMainThread()); | |
50 ImplThreadTaskRunner()->PostTask( | 43 ImplThreadTaskRunner()->PostTask( |
51 FROM_HERE, base::Bind(&ProxyImpl::InitializeOutputSurfaceOnImpl, | 44 FROM_HERE, base::Bind(&ProxyImpl::InitializeOutputSurfaceOnImpl, |
52 proxy_impl_weak_ptr_, output_surface)); | 45 proxy_impl_->GetImplWeakPtr(), output_surface)); |
53 } | 46 } |
54 | 47 |
55 void ThreadedChannel::MainThreadHasStoppedFlingingOnImpl() { | 48 void ThreadedChannel::MainThreadHasStoppedFlingingOnImpl() { |
56 DCHECK(IsMainThread()); | |
57 ImplThreadTaskRunner()->PostTask( | 49 ImplThreadTaskRunner()->PostTask( |
58 FROM_HERE, base::Bind(&ProxyImpl::MainThreadHasStoppedFlingingOnImpl, | 50 FROM_HERE, base::Bind(&ProxyImpl::MainThreadHasStoppedFlingingOnImpl, |
59 proxy_impl_weak_ptr_)); | 51 proxy_impl_->GetImplWeakPtr())); |
60 } | 52 } |
61 | 53 |
62 void ThreadedChannel::SetInputThrottledUntilCommitOnImpl(bool is_throttled) { | 54 void ThreadedChannel::SetInputThrottledUntilCommitOnImpl(bool is_throttled) { |
63 DCHECK(IsMainThread()); | |
64 ImplThreadTaskRunner()->PostTask( | 55 ImplThreadTaskRunner()->PostTask( |
65 FROM_HERE, base::Bind(&ProxyImpl::SetInputThrottledUntilCommitOnImpl, | 56 FROM_HERE, base::Bind(&ProxyImpl::SetInputThrottledUntilCommitOnImpl, |
66 proxy_impl_weak_ptr_, is_throttled)); | 57 proxy_impl_->GetImplWeakPtr(), is_throttled)); |
67 } | 58 } |
68 | 59 |
69 void ThreadedChannel::SetDeferCommitsOnImpl(bool defer_commits) { | 60 void ThreadedChannel::SetDeferCommitsOnImpl(bool defer_commits) { |
70 DCHECK(IsMainThread()); | |
71 ImplThreadTaskRunner()->PostTask( | 61 ImplThreadTaskRunner()->PostTask( |
72 FROM_HERE, base::Bind(&ProxyImpl::SetDeferCommitsOnImpl, | 62 FROM_HERE, base::Bind(&ProxyImpl::SetDeferCommitsOnImpl, |
73 proxy_impl_weak_ptr_, defer_commits)); | 63 proxy_impl_->GetImplWeakPtr(), defer_commits)); |
| 64 } |
| 65 |
| 66 void ThreadedChannel::FinishAllRenderingOnImpl(CompletionEvent* completion) { |
| 67 ImplThreadTaskRunner()->PostTask( |
| 68 FROM_HERE, base::Bind(&ProxyImpl::FinishAllRenderingOnImpl, |
| 69 proxy_impl_->GetImplWeakPtr(), completion)); |
74 } | 70 } |
75 | 71 |
76 void ThreadedChannel::SetNeedsCommitOnImpl() { | 72 void ThreadedChannel::SetNeedsCommitOnImpl() { |
77 DCHECK(IsMainThread()); | 73 ImplThreadTaskRunner()->PostTask(FROM_HERE, |
78 ImplThreadTaskRunner()->PostTask( | 74 base::Bind(&ProxyImpl::SetNeedsCommitOnImpl, |
79 FROM_HERE, | 75 proxy_impl_->GetImplWeakPtr())); |
80 base::Bind(&ProxyImpl::SetNeedsCommitOnImpl, proxy_impl_weak_ptr_)); | |
81 } | 76 } |
82 | 77 |
83 void ThreadedChannel::BeginMainFrameAbortedOnImpl( | 78 void ThreadedChannel::BeginMainFrameAbortedOnImpl( |
84 CommitEarlyOutReason reason, | 79 CommitEarlyOutReason reason, |
85 base::TimeTicks main_thread_start_time) { | 80 base::TimeTicks main_thread_start_time) { |
86 DCHECK(IsMainThread()); | 81 ImplThreadTaskRunner()->PostTask( |
87 ImplThreadTaskRunner()->PostTask( | 82 FROM_HERE, base::Bind(&ProxyImpl::BeginMainFrameAbortedOnImpl, |
88 FROM_HERE, | 83 proxy_impl_->GetImplWeakPtr(), reason, |
89 base::Bind(&ProxyImpl::BeginMainFrameAbortedOnImpl, proxy_impl_weak_ptr_, | 84 main_thread_start_time)); |
90 reason, main_thread_start_time)); | |
91 } | 85 } |
92 | 86 |
93 void ThreadedChannel::SetNeedsRedrawOnImpl(const gfx::Rect& damage_rect) { | 87 void ThreadedChannel::SetNeedsRedrawOnImpl(const gfx::Rect& damage_rect) { |
94 DCHECK(IsMainThread()); | |
95 ImplThreadTaskRunner()->PostTask( | 88 ImplThreadTaskRunner()->PostTask( |
96 FROM_HERE, base::Bind(&ProxyImpl::SetNeedsRedrawOnImpl, | 89 FROM_HERE, base::Bind(&ProxyImpl::SetNeedsRedrawOnImpl, |
97 proxy_impl_weak_ptr_, damage_rect)); | 90 proxy_impl_->GetImplWeakPtr(), damage_rect)); |
98 } | |
99 | |
100 void ThreadedChannel::SetVisibleOnImpl(bool visible) { | |
101 DCHECK(IsMainThread()); | |
102 ImplThreadTaskRunner()->PostTask( | |
103 FROM_HERE, | |
104 base::Bind(&ProxyImpl::SetVisibleOnImpl, proxy_impl_weak_ptr_, visible)); | |
105 } | |
106 | |
107 void ThreadedChannel::FinishAllRenderingOnImpl(CompletionEvent* completion) { | |
108 DCHECK(IsMainThread()); | |
109 ImplThreadTaskRunner()->PostTask( | |
110 FROM_HERE, base::Bind(&ProxyImpl::FinishAllRenderingOnImpl, | |
111 proxy_impl_weak_ptr_, completion)); | |
112 } | |
113 | |
114 void ThreadedChannel::ReleaseOutputSurfaceOnImpl(CompletionEvent* completion) { | |
115 DCHECK(IsMainThread()); | |
116 ImplThreadTaskRunner()->PostTask( | |
117 FROM_HERE, base::Bind(&ProxyImpl::ReleaseOutputSurfaceOnImpl, | |
118 proxy_impl_weak_ptr_, completion)); | |
119 } | |
120 | |
121 void ThreadedChannel::MainFrameWillHappenOnImplForTesting( | |
122 CompletionEvent* completion, | |
123 bool* main_frame_will_happen) { | |
124 DCHECK(IsMainThread()); | |
125 ImplThreadTaskRunner()->PostTask( | |
126 FROM_HERE, | |
127 base::Bind(&ProxyImpl::MainFrameWillHappenOnImplForTesting, | |
128 proxy_impl_weak_ptr_, completion, main_frame_will_happen)); | |
129 } | 91 } |
130 | 92 |
131 void ThreadedChannel::StartCommitOnImpl(CompletionEvent* completion, | 93 void ThreadedChannel::StartCommitOnImpl(CompletionEvent* completion, |
132 LayerTreeHost* layer_tree_host, | 94 LayerTreeHost* layer_tree_host, |
133 base::TimeTicks main_thread_start_time, | 95 base::TimeTicks main_thread_start_time, |
134 bool hold_commit_for_activation) { | 96 bool hold_commit_for_activation) { |
135 DCHECK(IsMainThread()); | 97 ImplThreadTaskRunner()->PostTask( |
136 ImplThreadTaskRunner()->PostTask( | 98 FROM_HERE, |
137 FROM_HERE, base::Bind(&ProxyImpl::StartCommitOnImpl, proxy_impl_weak_ptr_, | 99 base::Bind(&ProxyImpl::StartCommitOnImpl, proxy_impl_->GetImplWeakPtr(), |
138 completion, layer_tree_host, main_thread_start_time, | 100 completion, layer_tree_host, main_thread_start_time, |
139 hold_commit_for_activation)); | 101 hold_commit_for_activation)); |
140 } | 102 } |
141 | 103 |
142 void ThreadedChannel::SynchronouslyInitializeImpl( | 104 void ThreadedChannel::InitializeImplOnImpl(CompletionEvent* completion, |
143 LayerTreeHost* layer_tree_host, | 105 LayerTreeHost* layer_tree_host) { |
144 scoped_ptr<BeginFrameSource> external_begin_frame_source) { | 106 ImplThreadTaskRunner()->PostTask( |
145 TRACE_EVENT0("cc", "ThreadChannel::SynchronouslyInitializeImpl"); | 107 FROM_HERE, |
146 DCHECK(IsMainThread()); | 108 base::Bind(&ProxyImpl::InitializeImplOnImpl, |
147 { | 109 base::Unretained(proxy_impl_), completion, layer_tree_host)); |
148 DebugScopedSetMainThreadBlocked main_thread_blocked(task_runner_provider_); | 110 } |
149 CompletionEvent completion; | 111 |
150 ImplThreadTaskRunner()->PostTask( | 112 void ThreadedChannel::LayerTreeHostClosedOnImpl(CompletionEvent* completion) { |
151 FROM_HERE, | 113 ImplThreadTaskRunner()->PostTask( |
152 base::Bind(&ThreadedChannel::InitializeImplOnImpl, | 114 FROM_HERE, base::Bind(&ProxyImpl::LayerTreeHostClosedOnImpl, |
153 base::Unretained(this), &completion, layer_tree_host, | 115 proxy_impl_->GetImplWeakPtr(), completion)); |
154 base::Passed(&external_begin_frame_source))); | 116 proxy_impl_ = nullptr; |
155 completion.Wait(); | 117 } |
156 } | 118 |
157 main().initialized = true; | 119 void ThreadedChannel::SetVisibleOnImpl(bool visible) { |
158 } | 120 ImplThreadTaskRunner()->PostTask( |
159 | 121 FROM_HERE, base::Bind(&ProxyImpl::SetVisibleOnImpl, |
160 void ThreadedChannel::SynchronouslyCloseImpl() { | 122 proxy_impl_->GetImplWeakPtr(), visible)); |
161 TRACE_EVENT0("cc", "ThreadChannel::~SynchronouslyCloseImpl"); | 123 } |
162 DCHECK(IsMainThread()); | 124 |
163 | 125 void ThreadedChannel::ReleaseOutputSurfaceOnImpl(CompletionEvent* completion) { |
164 // Synchronously finishes pending GL operations and deletes the impl. | 126 ImplThreadTaskRunner()->PostTask( |
165 // The two steps are done as separate post tasks, so that tasks posted | 127 FROM_HERE, base::Bind(&ProxyImpl::ReleaseOutputSurfaceOnImpl, |
166 // by the GL implementation due to the Finish can be executed by the | 128 proxy_impl_->GetImplWeakPtr(), completion)); |
167 // renderer before shutting it down. | 129 } |
168 { | 130 |
169 DebugScopedSetMainThreadBlocked main_thread_blocked(task_runner_provider_); | 131 void ThreadedChannel::FinishGLOnImpl(CompletionEvent* completion) { |
170 CompletionEvent completion; | 132 ImplThreadTaskRunner()->PostTask( |
171 ImplThreadTaskRunner()->PostTask( | 133 FROM_HERE, base::Bind(&ProxyImpl::FinishGLOnImpl, |
172 FROM_HERE, base::Bind(&ProxyImpl::FinishGLOnImpl, proxy_impl_weak_ptr_, | 134 proxy_impl_->GetImplWeakPtr(), completion)); |
173 &completion)); | 135 } |
174 completion.Wait(); | 136 |
175 } | 137 void ThreadedChannel::MainFrameWillHappenOnImplForTesting( |
176 { | 138 CompletionEvent* completion, |
177 DebugScopedSetMainThreadBlocked main_thread_blocked(task_runner_provider_); | 139 bool* main_frame_will_happen) { |
178 CompletionEvent completion; | 140 ImplThreadTaskRunner()->PostTask( |
179 ImplThreadTaskRunner()->PostTask( | 141 FROM_HERE, base::Bind(&ProxyImpl::MainFrameWillHappenOnImplForTesting, |
180 FROM_HERE, base::Bind(&ThreadedChannel::CloseImplOnImpl, | 142 proxy_impl_->GetImplWeakPtr(), completion, |
181 base::Unretained(this), &completion)); | 143 main_frame_will_happen)); |
182 completion.Wait(); | |
183 } | |
184 main().proxy_main_weak_factory.InvalidateWeakPtrs(); | |
185 main().initialized = false; | |
186 } | 144 } |
187 | 145 |
188 void ThreadedChannel::DidCompleteSwapBuffers() { | 146 void ThreadedChannel::DidCompleteSwapBuffers() { |
189 DCHECK(IsImplThread()); | |
190 MainThreadTaskRunner()->PostTask( | 147 MainThreadTaskRunner()->PostTask( |
191 FROM_HERE, base::Bind(&ProxyMain::DidCompleteSwapBuffers, | 148 FROM_HERE, base::Bind(&ProxyMain::DidCompleteSwapBuffers, |
192 impl().proxy_main_weak_ptr)); | 149 proxy_main_->GetMainWeakPtr())); |
193 } | 150 } |
194 | 151 |
195 void ThreadedChannel::SetRendererCapabilitiesMainCopy( | 152 void ThreadedChannel::SetRendererCapabilitiesMainCopy( |
196 const RendererCapabilities& capabilities) { | 153 const RendererCapabilities& capabilities) { |
197 DCHECK(IsImplThread()); | 154 MainThreadTaskRunner()->PostTask( |
198 MainThreadTaskRunner()->PostTask( | 155 FROM_HERE, base::Bind(&ProxyMain::SetRendererCapabilitiesMainCopy, |
199 FROM_HERE, base::Bind(&ProxyMain::SetRendererCapabilities, | 156 proxy_main_->GetMainWeakPtr(), capabilities)); |
200 impl().proxy_main_weak_ptr, capabilities)); | |
201 } | 157 } |
202 | 158 |
203 void ThreadedChannel::BeginMainFrameNotExpectedSoon() { | 159 void ThreadedChannel::BeginMainFrameNotExpectedSoon() { |
204 DCHECK(IsImplThread()); | |
205 MainThreadTaskRunner()->PostTask( | 160 MainThreadTaskRunner()->PostTask( |
206 FROM_HERE, base::Bind(&ProxyMain::BeginMainFrameNotExpectedSoon, | 161 FROM_HERE, base::Bind(&ProxyMain::BeginMainFrameNotExpectedSoon, |
207 impl().proxy_main_weak_ptr)); | 162 proxy_main_->GetMainWeakPtr())); |
208 } | 163 } |
209 | 164 |
210 void ThreadedChannel::DidCommitAndDrawFrame() { | 165 void ThreadedChannel::DidCommitAndDrawFrame() { |
211 DCHECK(IsImplThread()); | |
212 MainThreadTaskRunner()->PostTask(FROM_HERE, | 166 MainThreadTaskRunner()->PostTask(FROM_HERE, |
213 base::Bind(&ProxyMain::DidCommitAndDrawFrame, | 167 base::Bind(&ProxyMain::DidCommitAndDrawFrame, |
214 impl().proxy_main_weak_ptr)); | 168 proxy_main_->GetMainWeakPtr())); |
215 } | 169 } |
216 | 170 |
217 void ThreadedChannel::SetAnimationEvents( | 171 void ThreadedChannel::SetAnimationEvents( |
218 scoped_ptr<AnimationEventsVector> queue) { | 172 scoped_ptr<AnimationEventsVector> queue) { |
219 DCHECK(IsImplThread()); | 173 MainThreadTaskRunner()->PostTask( |
220 MainThreadTaskRunner()->PostTask( | 174 FROM_HERE, |
221 FROM_HERE, base::Bind(&ProxyMain::SetAnimationEvents, | 175 base::Bind(&ProxyMain::SetAnimationEvents, proxy_main_->GetMainWeakPtr(), |
222 impl().proxy_main_weak_ptr, base::Passed(&queue))); | 176 base::Passed(&queue))); |
223 } | 177 } |
224 | 178 |
225 void ThreadedChannel::DidLoseOutputSurface() { | 179 void ThreadedChannel::DidLoseOutputSurface() { |
226 DCHECK(IsImplThread()); | 180 MainThreadTaskRunner()->PostTask(FROM_HERE, |
227 MainThreadTaskRunner()->PostTask( | 181 base::Bind(&ProxyMain::DidLoseOutputSurface, |
228 FROM_HERE, | 182 proxy_main_->GetMainWeakPtr())); |
229 base::Bind(&ProxyMain::DidLoseOutputSurface, impl().proxy_main_weak_ptr)); | |
230 } | 183 } |
231 | 184 |
232 void ThreadedChannel::RequestNewOutputSurface() { | 185 void ThreadedChannel::RequestNewOutputSurface() { |
233 DCHECK(IsImplThread()); | |
234 MainThreadTaskRunner()->PostTask( | 186 MainThreadTaskRunner()->PostTask( |
235 FROM_HERE, base::Bind(&ProxyMain::RequestNewOutputSurface, | 187 FROM_HERE, base::Bind(&ProxyMain::RequestNewOutputSurface, |
236 impl().proxy_main_weak_ptr)); | 188 proxy_main_->GetMainWeakPtr())); |
237 } | 189 } |
238 | 190 |
239 void ThreadedChannel::DidInitializeOutputSurface( | 191 void ThreadedChannel::DidInitializeOutputSurface( |
240 bool success, | 192 bool success, |
241 const RendererCapabilities& capabilities) { | 193 const RendererCapabilities& capabilities) { |
242 DCHECK(IsImplThread()); | 194 MainThreadTaskRunner()->PostTask( |
243 MainThreadTaskRunner()->PostTask( | 195 FROM_HERE, |
244 FROM_HERE, base::Bind(&ProxyMain::DidInitializeOutputSurface, | 196 base::Bind(&ProxyMain::DidInitializeOutputSurface, |
245 impl().proxy_main_weak_ptr, success, capabilities)); | 197 proxy_main_->GetMainWeakPtr(), success, capabilities)); |
246 } | 198 } |
247 | 199 |
248 void ThreadedChannel::DidCompletePageScaleAnimation() { | 200 void ThreadedChannel::DidCompletePageScaleAnimation() { |
249 DCHECK(IsImplThread()); | |
250 MainThreadTaskRunner()->PostTask( | 201 MainThreadTaskRunner()->PostTask( |
251 FROM_HERE, base::Bind(&ProxyMain::DidCompletePageScaleAnimation, | 202 FROM_HERE, base::Bind(&ProxyMain::DidCompletePageScaleAnimation, |
252 impl().proxy_main_weak_ptr)); | 203 proxy_main_->GetMainWeakPtr())); |
253 } | 204 } |
254 | 205 |
255 void ThreadedChannel::PostFrameTimingEventsOnMain( | 206 void ThreadedChannel::PostFrameTimingEventsOnMain( |
256 scoped_ptr<FrameTimingTracker::CompositeTimingSet> composite_events, | 207 scoped_ptr<FrameTimingTracker::CompositeTimingSet> composite_events, |
257 scoped_ptr<FrameTimingTracker::MainFrameTimingSet> main_frame_events) { | 208 scoped_ptr<FrameTimingTracker::MainFrameTimingSet> main_frame_events) { |
258 DCHECK(IsImplThread()); | |
259 MainThreadTaskRunner()->PostTask( | 209 MainThreadTaskRunner()->PostTask( |
260 FROM_HERE, base::Bind(&ProxyMain::PostFrameTimingEventsOnMain, | 210 FROM_HERE, base::Bind(&ProxyMain::PostFrameTimingEventsOnMain, |
261 impl().proxy_main_weak_ptr, | 211 proxy_main_->GetMainWeakPtr(), |
262 base::Passed(std::move(composite_events)), | 212 base::Passed(std::move(composite_events)), |
263 base::Passed(std::move(main_frame_events)))); | 213 base::Passed(std::move(main_frame_events)))); |
264 } | 214 } |
265 | 215 |
266 void ThreadedChannel::BeginMainFrame( | 216 void ThreadedChannel::BeginMainFrame( |
267 scoped_ptr<BeginMainFrameAndCommitState> begin_main_frame_state) { | 217 scoped_ptr<BeginMainFrameAndCommitState> begin_main_frame_state) { |
268 DCHECK(IsImplThread()); | 218 MainThreadTaskRunner()->PostTask( |
269 MainThreadTaskRunner()->PostTask( | 219 FROM_HERE, |
270 FROM_HERE, | 220 base::Bind(&ProxyMain::BeginMainFrame, proxy_main_->GetMainWeakPtr(), |
271 base::Bind(&ProxyMain::BeginMainFrame, impl().proxy_main_weak_ptr, | |
272 base::Passed(&begin_main_frame_state))); | 221 base::Passed(&begin_main_frame_state))); |
273 } | 222 } |
274 | 223 |
275 ProxyImpl* ThreadedChannel::GetProxyImplForTesting() const { | 224 ThreadedChannel::~ThreadedChannel() { |
276 return impl().proxy_impl.get(); | 225 TRACE_EVENT0("cc", "ThreadChannel::~ThreadChannel"); |
277 } | |
278 | |
279 scoped_ptr<ProxyImpl> ThreadedChannel::CreateProxyImpl( | |
280 ChannelImpl* channel_impl, | |
281 LayerTreeHost* layer_tree_host, | |
282 TaskRunnerProvider* task_runner_provider, | |
283 scoped_ptr<BeginFrameSource> external_begin_frame_source) { | |
284 DCHECK(IsImplThread()); | |
285 return ProxyImpl::Create(channel_impl, layer_tree_host, task_runner_provider, | |
286 std::move(external_begin_frame_source)); | |
287 } | |
288 | |
289 void ThreadedChannel::InitializeImplOnImpl( | |
290 CompletionEvent* completion, | |
291 LayerTreeHost* layer_tree_host, | |
292 scoped_ptr<BeginFrameSource> external_begin_frame_source) { | |
293 DCHECK(IsImplThread()); | |
294 impl().proxy_impl = | |
295 CreateProxyImpl(this, layer_tree_host, task_runner_provider_, | |
296 std::move(external_begin_frame_source)); | |
297 impl().proxy_impl_weak_factory = make_scoped_ptr( | |
298 new base::WeakPtrFactory<ProxyImpl>(impl().proxy_impl.get())); | |
299 proxy_impl_weak_ptr_ = impl().proxy_impl_weak_factory->GetWeakPtr(); | |
300 completion->Signal(); | |
301 } | |
302 | |
303 void ThreadedChannel::CloseImplOnImpl(CompletionEvent* completion) { | |
304 DCHECK(IsImplThread()); | |
305 | |
306 // We must destroy the factory and ensure that the ProxyImpl weak pointers are | |
307 // invalidated before destroying proxy_impl. | |
308 impl().proxy_impl_weak_factory.reset(); | |
309 | |
310 impl().proxy_impl.reset(); | |
311 completion->Signal(); | |
312 } | |
313 | |
314 bool ThreadedChannel::IsInitialized() const { | |
315 return main().initialized; | |
316 } | 226 } |
317 | 227 |
318 base::SingleThreadTaskRunner* ThreadedChannel::MainThreadTaskRunner() const { | 228 base::SingleThreadTaskRunner* ThreadedChannel::MainThreadTaskRunner() const { |
319 return task_runner_provider_->MainThreadTaskRunner(); | 229 return task_runner_provider_->MainThreadTaskRunner(); |
320 } | 230 } |
321 | 231 |
322 base::SingleThreadTaskRunner* ThreadedChannel::ImplThreadTaskRunner() const { | 232 base::SingleThreadTaskRunner* ThreadedChannel::ImplThreadTaskRunner() const { |
323 return task_runner_provider_->ImplThreadTaskRunner(); | 233 return task_runner_provider_->ImplThreadTaskRunner(); |
324 } | 234 } |
325 | 235 |
326 bool ThreadedChannel::IsMainThread() const { | |
327 return task_runner_provider_->IsMainThread(); | |
328 } | |
329 | |
330 bool ThreadedChannel::IsImplThread() const { | |
331 return task_runner_provider_->IsImplThread(); | |
332 } | |
333 | |
334 ThreadedChannel::MainThreadOnly& ThreadedChannel::main() { | |
335 DCHECK(task_runner_provider_->IsMainThread()); | |
336 return main_thread_only_vars_unsafe_; | |
337 } | |
338 | |
339 const ThreadedChannel::MainThreadOnly& ThreadedChannel::main() const { | |
340 DCHECK(task_runner_provider_->IsMainThread()); | |
341 return main_thread_only_vars_unsafe_; | |
342 } | |
343 | |
344 ThreadedChannel::CompositorThreadOnly& ThreadedChannel::impl() { | |
345 DCHECK(task_runner_provider_->IsImplThread()); | |
346 return compositor_thread_vars_unsafe_; | |
347 } | |
348 | |
349 const ThreadedChannel::CompositorThreadOnly& ThreadedChannel::impl() const { | |
350 DCHECK(task_runner_provider_->IsImplThread()); | |
351 return compositor_thread_vars_unsafe_; | |
352 } | |
353 | |
354 ThreadedChannel::MainThreadOnly::MainThreadOnly(ProxyMain* proxy_main) | |
355 : proxy_main_weak_factory(proxy_main), initialized(false) {} | |
356 | |
357 ThreadedChannel::MainThreadOnly::~MainThreadOnly() {} | |
358 | |
359 ThreadedChannel::CompositorThreadOnly::CompositorThreadOnly( | |
360 base::WeakPtr<ProxyMain> proxy_main_weak_ptr) | |
361 : proxy_main_weak_ptr(proxy_main_weak_ptr) {} | |
362 | |
363 ThreadedChannel::CompositorThreadOnly::~CompositorThreadOnly() {} | |
364 | |
365 scoped_ptr<ThreadedChannel> ThreadedChannel::Create( | |
366 ProxyMain* proxy_main, | |
367 TaskRunnerProvider* task_runner_provider) { | |
368 return make_scoped_ptr(new ThreadedChannel(proxy_main, task_runner_provider)); | |
369 } | |
370 | |
371 } // namespace cc | 236 } // namespace cc |
OLD | NEW |