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" |
10 | 11 |
11 namespace cc { | 12 namespace cc { |
12 | 13 |
13 scoped_ptr<ThreadedChannel> ThreadedChannel::Create( | 14 ThreadedChannel::ThreadedChannel(ProxyMain* proxy_main, |
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, | |
21 TaskRunnerProvider* task_runner_provider) | 15 TaskRunnerProvider* task_runner_provider) |
22 : proxy_main_(thread_proxy), | 16 : task_runner_provider_(task_runner_provider), |
23 proxy_impl_(thread_proxy), | 17 main_thread_only_vars_unsafe_(proxy_main), |
24 task_runner_provider_(task_runner_provider) {} | 18 compositor_thread_vars_unsafe_( |
| 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 } |
25 | 29 |
26 void ThreadedChannel::SetThrottleFrameProductionOnImpl(bool throttle) { | 30 void ThreadedChannel::SetThrottleFrameProductionOnImpl(bool throttle) { |
| 31 DCHECK(IsMainThread()); |
27 ImplThreadTaskRunner()->PostTask( | 32 ImplThreadTaskRunner()->PostTask( |
28 FROM_HERE, base::Bind(&ProxyImpl::SetThrottleFrameProductionOnImpl, | 33 FROM_HERE, base::Bind(&ProxyImpl::SetThrottleFrameProductionOnImpl, |
29 proxy_impl_->GetImplWeakPtr(), throttle)); | 34 proxy_impl_weak_ptr_, throttle)); |
30 } | 35 } |
31 | 36 |
32 void ThreadedChannel::UpdateTopControlsStateOnImpl(TopControlsState constraints, | 37 void ThreadedChannel::UpdateTopControlsStateOnImpl(TopControlsState constraints, |
33 TopControlsState current, | 38 TopControlsState current, |
34 bool animate) { | 39 bool animate) { |
35 ImplThreadTaskRunner()->PostTask( | 40 DCHECK(IsMainThread()); |
36 FROM_HERE, | 41 ImplThreadTaskRunner()->PostTask( |
37 base::Bind(&ProxyImpl::UpdateTopControlsStateOnImpl, | 42 FROM_HERE, |
38 proxy_impl_->GetImplWeakPtr(), constraints, current, animate)); | 43 base::Bind(&ProxyImpl::UpdateTopControlsStateOnImpl, proxy_impl_weak_ptr_, |
| 44 constraints, current, animate)); |
39 } | 45 } |
40 | 46 |
41 void ThreadedChannel::InitializeOutputSurfaceOnImpl( | 47 void ThreadedChannel::InitializeOutputSurfaceOnImpl( |
42 OutputSurface* output_surface) { | 48 OutputSurface* output_surface) { |
| 49 DCHECK(IsMainThread()); |
43 ImplThreadTaskRunner()->PostTask( | 50 ImplThreadTaskRunner()->PostTask( |
44 FROM_HERE, base::Bind(&ProxyImpl::InitializeOutputSurfaceOnImpl, | 51 FROM_HERE, base::Bind(&ProxyImpl::InitializeOutputSurfaceOnImpl, |
45 proxy_impl_->GetImplWeakPtr(), output_surface)); | 52 proxy_impl_weak_ptr_, output_surface)); |
46 } | 53 } |
47 | 54 |
48 void ThreadedChannel::MainThreadHasStoppedFlingingOnImpl() { | 55 void ThreadedChannel::MainThreadHasStoppedFlingingOnImpl() { |
| 56 DCHECK(IsMainThread()); |
49 ImplThreadTaskRunner()->PostTask( | 57 ImplThreadTaskRunner()->PostTask( |
50 FROM_HERE, base::Bind(&ProxyImpl::MainThreadHasStoppedFlingingOnImpl, | 58 FROM_HERE, base::Bind(&ProxyImpl::MainThreadHasStoppedFlingingOnImpl, |
51 proxy_impl_->GetImplWeakPtr())); | 59 proxy_impl_weak_ptr_)); |
52 } | 60 } |
53 | 61 |
54 void ThreadedChannel::SetInputThrottledUntilCommitOnImpl(bool is_throttled) { | 62 void ThreadedChannel::SetInputThrottledUntilCommitOnImpl(bool is_throttled) { |
| 63 DCHECK(IsMainThread()); |
55 ImplThreadTaskRunner()->PostTask( | 64 ImplThreadTaskRunner()->PostTask( |
56 FROM_HERE, base::Bind(&ProxyImpl::SetInputThrottledUntilCommitOnImpl, | 65 FROM_HERE, base::Bind(&ProxyImpl::SetInputThrottledUntilCommitOnImpl, |
57 proxy_impl_->GetImplWeakPtr(), is_throttled)); | 66 proxy_impl_weak_ptr_, is_throttled)); |
58 } | 67 } |
59 | 68 |
60 void ThreadedChannel::SetDeferCommitsOnImpl(bool defer_commits) { | 69 void ThreadedChannel::SetDeferCommitsOnImpl(bool defer_commits) { |
| 70 DCHECK(IsMainThread()); |
61 ImplThreadTaskRunner()->PostTask( | 71 ImplThreadTaskRunner()->PostTask( |
62 FROM_HERE, base::Bind(&ProxyImpl::SetDeferCommitsOnImpl, | 72 FROM_HERE, base::Bind(&ProxyImpl::SetDeferCommitsOnImpl, |
63 proxy_impl_->GetImplWeakPtr(), defer_commits)); | 73 proxy_impl_weak_ptr_, 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)); | |
70 } | 74 } |
71 | 75 |
72 void ThreadedChannel::SetNeedsCommitOnImpl() { | 76 void ThreadedChannel::SetNeedsCommitOnImpl() { |
73 ImplThreadTaskRunner()->PostTask(FROM_HERE, | 77 DCHECK(IsMainThread()); |
74 base::Bind(&ProxyImpl::SetNeedsCommitOnImpl, | 78 ImplThreadTaskRunner()->PostTask( |
75 proxy_impl_->GetImplWeakPtr())); | 79 FROM_HERE, |
| 80 base::Bind(&ProxyImpl::SetNeedsCommitOnImpl, proxy_impl_weak_ptr_)); |
76 } | 81 } |
77 | 82 |
78 void ThreadedChannel::BeginMainFrameAbortedOnImpl( | 83 void ThreadedChannel::BeginMainFrameAbortedOnImpl( |
79 CommitEarlyOutReason reason, | 84 CommitEarlyOutReason reason, |
80 base::TimeTicks main_thread_start_time) { | 85 base::TimeTicks main_thread_start_time) { |
81 ImplThreadTaskRunner()->PostTask( | 86 DCHECK(IsMainThread()); |
82 FROM_HERE, base::Bind(&ProxyImpl::BeginMainFrameAbortedOnImpl, | 87 ImplThreadTaskRunner()->PostTask( |
83 proxy_impl_->GetImplWeakPtr(), reason, | 88 FROM_HERE, |
84 main_thread_start_time)); | 89 base::Bind(&ProxyImpl::BeginMainFrameAbortedOnImpl, proxy_impl_weak_ptr_, |
| 90 reason, main_thread_start_time)); |
85 } | 91 } |
86 | 92 |
87 void ThreadedChannel::SetNeedsRedrawOnImpl(const gfx::Rect& damage_rect) { | 93 void ThreadedChannel::SetNeedsRedrawOnImpl(const gfx::Rect& damage_rect) { |
| 94 DCHECK(IsMainThread()); |
88 ImplThreadTaskRunner()->PostTask( | 95 ImplThreadTaskRunner()->PostTask( |
89 FROM_HERE, base::Bind(&ProxyImpl::SetNeedsRedrawOnImpl, | 96 FROM_HERE, base::Bind(&ProxyImpl::SetNeedsRedrawOnImpl, |
90 proxy_impl_->GetImplWeakPtr(), damage_rect)); | 97 proxy_impl_weak_ptr_, 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)); |
91 } | 129 } |
92 | 130 |
93 void ThreadedChannel::StartCommitOnImpl(CompletionEvent* completion, | 131 void ThreadedChannel::StartCommitOnImpl(CompletionEvent* completion, |
94 LayerTreeHost* layer_tree_host, | 132 LayerTreeHost* layer_tree_host, |
95 base::TimeTicks main_thread_start_time, | 133 base::TimeTicks main_thread_start_time, |
96 bool hold_commit_for_activation) { | 134 bool hold_commit_for_activation) { |
97 ImplThreadTaskRunner()->PostTask( | 135 DCHECK(IsMainThread()); |
98 FROM_HERE, | 136 ImplThreadTaskRunner()->PostTask( |
99 base::Bind(&ProxyImpl::StartCommitOnImpl, proxy_impl_->GetImplWeakPtr(), | 137 FROM_HERE, base::Bind(&ProxyImpl::StartCommitOnImpl, proxy_impl_weak_ptr_, |
100 completion, layer_tree_host, main_thread_start_time, | 138 completion, layer_tree_host, main_thread_start_time, |
101 hold_commit_for_activation)); | 139 hold_commit_for_activation)); |
102 } | 140 } |
103 | 141 |
104 void ThreadedChannel::InitializeImplOnImpl(CompletionEvent* completion, | 142 void ThreadedChannel::SynchronouslyInitializeImpl( |
105 LayerTreeHost* layer_tree_host) { | 143 LayerTreeHost* layer_tree_host, |
106 ImplThreadTaskRunner()->PostTask( | 144 scoped_ptr<BeginFrameSource> external_begin_frame_source) { |
107 FROM_HERE, | 145 TRACE_EVENT0("cc", "ThreadChannel::SynchronouslyInitializeImpl"); |
108 base::Bind(&ProxyImpl::InitializeImplOnImpl, | 146 DCHECK(IsMainThread()); |
109 base::Unretained(proxy_impl_), completion, layer_tree_host)); | 147 { |
110 } | 148 DebugScopedSetMainThreadBlocked main_thread_blocked(task_runner_provider_); |
111 | 149 CompletionEvent completion; |
112 void ThreadedChannel::LayerTreeHostClosedOnImpl(CompletionEvent* completion) { | 150 ImplThreadTaskRunner()->PostTask( |
113 ImplThreadTaskRunner()->PostTask( | 151 FROM_HERE, |
114 FROM_HERE, base::Bind(&ProxyImpl::LayerTreeHostClosedOnImpl, | 152 base::Bind(&ThreadedChannel::InitializeImplOnImpl, |
115 proxy_impl_->GetImplWeakPtr(), completion)); | 153 base::Unretained(this), &completion, layer_tree_host, |
116 proxy_impl_ = nullptr; | 154 base::Passed(&external_begin_frame_source))); |
117 } | 155 completion.Wait(); |
118 | 156 } |
119 void ThreadedChannel::SetVisibleOnImpl(bool visible) { | 157 main().initialized = true; |
120 ImplThreadTaskRunner()->PostTask( | 158 } |
121 FROM_HERE, base::Bind(&ProxyImpl::SetVisibleOnImpl, | 159 |
122 proxy_impl_->GetImplWeakPtr(), visible)); | 160 void ThreadedChannel::SynchronouslyCloseImpl() { |
123 } | 161 TRACE_EVENT0("cc", "ThreadChannel::~SynchronouslyCloseImpl"); |
124 | 162 DCHECK(IsMainThread()); |
125 void ThreadedChannel::ReleaseOutputSurfaceOnImpl(CompletionEvent* completion) { | 163 |
126 ImplThreadTaskRunner()->PostTask( | 164 // Synchronously finishes pending GL operations and deletes the impl. |
127 FROM_HERE, base::Bind(&ProxyImpl::ReleaseOutputSurfaceOnImpl, | 165 // The two steps are done as separate post tasks, so that tasks posted |
128 proxy_impl_->GetImplWeakPtr(), completion)); | 166 // by the GL implementation due to the Finish can be executed by the |
129 } | 167 // renderer before shutting it down. |
130 | 168 { |
131 void ThreadedChannel::FinishGLOnImpl(CompletionEvent* completion) { | 169 DebugScopedSetMainThreadBlocked main_thread_blocked(task_runner_provider_); |
132 ImplThreadTaskRunner()->PostTask( | 170 CompletionEvent completion; |
133 FROM_HERE, base::Bind(&ProxyImpl::FinishGLOnImpl, | 171 ImplThreadTaskRunner()->PostTask( |
134 proxy_impl_->GetImplWeakPtr(), completion)); | 172 FROM_HERE, base::Bind(&ProxyImpl::FinishGLOnImpl, proxy_impl_weak_ptr_, |
135 } | 173 &completion)); |
136 | 174 completion.Wait(); |
137 void ThreadedChannel::MainFrameWillHappenOnImplForTesting( | 175 } |
138 CompletionEvent* completion, | 176 { |
139 bool* main_frame_will_happen) { | 177 DebugScopedSetMainThreadBlocked main_thread_blocked(task_runner_provider_); |
140 ImplThreadTaskRunner()->PostTask( | 178 CompletionEvent completion; |
141 FROM_HERE, base::Bind(&ProxyImpl::MainFrameWillHappenOnImplForTesting, | 179 ImplThreadTaskRunner()->PostTask( |
142 proxy_impl_->GetImplWeakPtr(), completion, | 180 FROM_HERE, base::Bind(&ThreadedChannel::CloseImplOnImpl, |
143 main_frame_will_happen)); | 181 base::Unretained(this), &completion)); |
| 182 completion.Wait(); |
| 183 } |
| 184 main().proxy_main_weak_factory.InvalidateWeakPtrs(); |
| 185 main().initialized = false; |
144 } | 186 } |
145 | 187 |
146 void ThreadedChannel::DidCompleteSwapBuffers() { | 188 void ThreadedChannel::DidCompleteSwapBuffers() { |
| 189 DCHECK(IsImplThread()); |
147 MainThreadTaskRunner()->PostTask( | 190 MainThreadTaskRunner()->PostTask( |
148 FROM_HERE, base::Bind(&ProxyMain::DidCompleteSwapBuffers, | 191 FROM_HERE, base::Bind(&ProxyMain::DidCompleteSwapBuffers, |
149 proxy_main_->GetMainWeakPtr())); | 192 impl().proxy_main_weak_ptr)); |
150 } | 193 } |
151 | 194 |
152 void ThreadedChannel::SetRendererCapabilitiesMainCopy( | 195 void ThreadedChannel::SetRendererCapabilitiesMainCopy( |
153 const RendererCapabilities& capabilities) { | 196 const RendererCapabilities& capabilities) { |
154 MainThreadTaskRunner()->PostTask( | 197 DCHECK(IsImplThread()); |
155 FROM_HERE, base::Bind(&ProxyMain::SetRendererCapabilitiesMainCopy, | 198 MainThreadTaskRunner()->PostTask( |
156 proxy_main_->GetMainWeakPtr(), capabilities)); | 199 FROM_HERE, base::Bind(&ProxyMain::SetRendererCapabilities, |
| 200 impl().proxy_main_weak_ptr, capabilities)); |
157 } | 201 } |
158 | 202 |
159 void ThreadedChannel::BeginMainFrameNotExpectedSoon() { | 203 void ThreadedChannel::BeginMainFrameNotExpectedSoon() { |
| 204 DCHECK(IsImplThread()); |
160 MainThreadTaskRunner()->PostTask( | 205 MainThreadTaskRunner()->PostTask( |
161 FROM_HERE, base::Bind(&ProxyMain::BeginMainFrameNotExpectedSoon, | 206 FROM_HERE, base::Bind(&ProxyMain::BeginMainFrameNotExpectedSoon, |
162 proxy_main_->GetMainWeakPtr())); | 207 impl().proxy_main_weak_ptr)); |
163 } | 208 } |
164 | 209 |
165 void ThreadedChannel::DidCommitAndDrawFrame() { | 210 void ThreadedChannel::DidCommitAndDrawFrame() { |
| 211 DCHECK(IsImplThread()); |
166 MainThreadTaskRunner()->PostTask(FROM_HERE, | 212 MainThreadTaskRunner()->PostTask(FROM_HERE, |
167 base::Bind(&ProxyMain::DidCommitAndDrawFrame, | 213 base::Bind(&ProxyMain::DidCommitAndDrawFrame, |
168 proxy_main_->GetMainWeakPtr())); | 214 impl().proxy_main_weak_ptr)); |
169 } | 215 } |
170 | 216 |
171 void ThreadedChannel::SetAnimationEvents( | 217 void ThreadedChannel::SetAnimationEvents( |
172 scoped_ptr<AnimationEventsVector> queue) { | 218 scoped_ptr<AnimationEventsVector> queue) { |
173 MainThreadTaskRunner()->PostTask( | 219 DCHECK(IsImplThread()); |
174 FROM_HERE, | 220 MainThreadTaskRunner()->PostTask( |
175 base::Bind(&ProxyMain::SetAnimationEvents, proxy_main_->GetMainWeakPtr(), | 221 FROM_HERE, base::Bind(&ProxyMain::SetAnimationEvents, |
176 base::Passed(&queue))); | 222 impl().proxy_main_weak_ptr, base::Passed(&queue))); |
177 } | 223 } |
178 | 224 |
179 void ThreadedChannel::DidLoseOutputSurface() { | 225 void ThreadedChannel::DidLoseOutputSurface() { |
180 MainThreadTaskRunner()->PostTask(FROM_HERE, | 226 DCHECK(IsImplThread()); |
181 base::Bind(&ProxyMain::DidLoseOutputSurface, | 227 MainThreadTaskRunner()->PostTask( |
182 proxy_main_->GetMainWeakPtr())); | 228 FROM_HERE, |
| 229 base::Bind(&ProxyMain::DidLoseOutputSurface, impl().proxy_main_weak_ptr)); |
183 } | 230 } |
184 | 231 |
185 void ThreadedChannel::RequestNewOutputSurface() { | 232 void ThreadedChannel::RequestNewOutputSurface() { |
| 233 DCHECK(IsImplThread()); |
186 MainThreadTaskRunner()->PostTask( | 234 MainThreadTaskRunner()->PostTask( |
187 FROM_HERE, base::Bind(&ProxyMain::RequestNewOutputSurface, | 235 FROM_HERE, base::Bind(&ProxyMain::RequestNewOutputSurface, |
188 proxy_main_->GetMainWeakPtr())); | 236 impl().proxy_main_weak_ptr)); |
189 } | 237 } |
190 | 238 |
191 void ThreadedChannel::DidInitializeOutputSurface( | 239 void ThreadedChannel::DidInitializeOutputSurface( |
192 bool success, | 240 bool success, |
193 const RendererCapabilities& capabilities) { | 241 const RendererCapabilities& capabilities) { |
194 MainThreadTaskRunner()->PostTask( | 242 DCHECK(IsImplThread()); |
195 FROM_HERE, | 243 MainThreadTaskRunner()->PostTask( |
196 base::Bind(&ProxyMain::DidInitializeOutputSurface, | 244 FROM_HERE, base::Bind(&ProxyMain::DidInitializeOutputSurface, |
197 proxy_main_->GetMainWeakPtr(), success, capabilities)); | 245 impl().proxy_main_weak_ptr, success, capabilities)); |
198 } | 246 } |
199 | 247 |
200 void ThreadedChannel::DidCompletePageScaleAnimation() { | 248 void ThreadedChannel::DidCompletePageScaleAnimation() { |
| 249 DCHECK(IsImplThread()); |
201 MainThreadTaskRunner()->PostTask( | 250 MainThreadTaskRunner()->PostTask( |
202 FROM_HERE, base::Bind(&ProxyMain::DidCompletePageScaleAnimation, | 251 FROM_HERE, base::Bind(&ProxyMain::DidCompletePageScaleAnimation, |
203 proxy_main_->GetMainWeakPtr())); | 252 impl().proxy_main_weak_ptr)); |
204 } | 253 } |
205 | 254 |
206 void ThreadedChannel::PostFrameTimingEventsOnMain( | 255 void ThreadedChannel::PostFrameTimingEventsOnMain( |
207 scoped_ptr<FrameTimingTracker::CompositeTimingSet> composite_events, | 256 scoped_ptr<FrameTimingTracker::CompositeTimingSet> composite_events, |
208 scoped_ptr<FrameTimingTracker::MainFrameTimingSet> main_frame_events) { | 257 scoped_ptr<FrameTimingTracker::MainFrameTimingSet> main_frame_events) { |
| 258 DCHECK(IsImplThread()); |
209 MainThreadTaskRunner()->PostTask( | 259 MainThreadTaskRunner()->PostTask( |
210 FROM_HERE, base::Bind(&ProxyMain::PostFrameTimingEventsOnMain, | 260 FROM_HERE, base::Bind(&ProxyMain::PostFrameTimingEventsOnMain, |
211 proxy_main_->GetMainWeakPtr(), | 261 impl().proxy_main_weak_ptr, |
212 base::Passed(std::move(composite_events)), | 262 base::Passed(std::move(composite_events)), |
213 base::Passed(std::move(main_frame_events)))); | 263 base::Passed(std::move(main_frame_events)))); |
214 } | 264 } |
215 | 265 |
216 void ThreadedChannel::BeginMainFrame( | 266 void ThreadedChannel::BeginMainFrame( |
217 scoped_ptr<BeginMainFrameAndCommitState> begin_main_frame_state) { | 267 scoped_ptr<BeginMainFrameAndCommitState> begin_main_frame_state) { |
218 MainThreadTaskRunner()->PostTask( | 268 DCHECK(IsImplThread()); |
219 FROM_HERE, | 269 MainThreadTaskRunner()->PostTask( |
220 base::Bind(&ProxyMain::BeginMainFrame, proxy_main_->GetMainWeakPtr(), | 270 FROM_HERE, |
| 271 base::Bind(&ProxyMain::BeginMainFrame, impl().proxy_main_weak_ptr, |
221 base::Passed(&begin_main_frame_state))); | 272 base::Passed(&begin_main_frame_state))); |
222 } | 273 } |
223 | 274 |
224 ThreadedChannel::~ThreadedChannel() { | 275 ProxyImpl* ThreadedChannel::GetProxyImplForTesting() const { |
225 TRACE_EVENT0("cc", "ThreadChannel::~ThreadChannel"); | 276 return impl().proxy_impl.get(); |
| 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; |
226 } | 316 } |
227 | 317 |
228 base::SingleThreadTaskRunner* ThreadedChannel::MainThreadTaskRunner() const { | 318 base::SingleThreadTaskRunner* ThreadedChannel::MainThreadTaskRunner() const { |
229 return task_runner_provider_->MainThreadTaskRunner(); | 319 return task_runner_provider_->MainThreadTaskRunner(); |
230 } | 320 } |
231 | 321 |
232 base::SingleThreadTaskRunner* ThreadedChannel::ImplThreadTaskRunner() const { | 322 base::SingleThreadTaskRunner* ThreadedChannel::ImplThreadTaskRunner() const { |
233 return task_runner_provider_->ImplThreadTaskRunner(); | 323 return task_runner_provider_->ImplThreadTaskRunner(); |
234 } | 324 } |
235 | 325 |
| 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 |
236 } // namespace cc | 371 } // namespace cc |
OLD | NEW |