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/memory/ptr_util.h" |
8 #include "base/single_thread_task_runner.h" | 9 #include "base/single_thread_task_runner.h" |
9 #include "base/trace_event/trace_event.h" | 10 #include "base/trace_event/trace_event.h" |
10 #include "cc/animation/animation_events.h" | 11 #include "cc/animation/animation_events.h" |
11 #include "cc/trees/layer_tree_host.h" | 12 #include "cc/trees/layer_tree_host.h" |
12 | 13 |
13 namespace cc { | 14 namespace cc { |
14 | 15 |
15 scoped_ptr<ThreadedChannel> ThreadedChannel::Create( | 16 std::unique_ptr<ThreadedChannel> ThreadedChannel::Create( |
16 ProxyMain* proxy_main, | 17 ProxyMain* proxy_main, |
17 TaskRunnerProvider* task_runner_provider) { | 18 TaskRunnerProvider* task_runner_provider) { |
18 return make_scoped_ptr(new ThreadedChannel(proxy_main, task_runner_provider)); | 19 return base::WrapUnique( |
| 20 new ThreadedChannel(proxy_main, task_runner_provider)); |
19 } | 21 } |
20 | 22 |
21 ThreadedChannel::ThreadedChannel(ProxyMain* proxy_main, | 23 ThreadedChannel::ThreadedChannel(ProxyMain* proxy_main, |
22 TaskRunnerProvider* task_runner_provider) | 24 TaskRunnerProvider* task_runner_provider) |
23 : task_runner_provider_(task_runner_provider), | 25 : task_runner_provider_(task_runner_provider), |
24 main_thread_only_vars_unsafe_(proxy_main), | 26 main_thread_only_vars_unsafe_(proxy_main), |
25 compositor_thread_vars_unsafe_( | 27 compositor_thread_vars_unsafe_( |
26 main() | 28 main() |
27 .proxy_main_weak_factory.GetWeakPtr()) { | 29 .proxy_main_weak_factory.GetWeakPtr()) { |
28 DCHECK(IsMainThread()); | 30 DCHECK(IsMainThread()); |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 bool hold_commit_for_activation) { | 136 bool hold_commit_for_activation) { |
135 DCHECK(IsMainThread()); | 137 DCHECK(IsMainThread()); |
136 ImplThreadTaskRunner()->PostTask( | 138 ImplThreadTaskRunner()->PostTask( |
137 FROM_HERE, base::Bind(&ProxyImpl::StartCommitOnImpl, proxy_impl_weak_ptr_, | 139 FROM_HERE, base::Bind(&ProxyImpl::StartCommitOnImpl, proxy_impl_weak_ptr_, |
138 completion, layer_tree_host, main_thread_start_time, | 140 completion, layer_tree_host, main_thread_start_time, |
139 hold_commit_for_activation)); | 141 hold_commit_for_activation)); |
140 } | 142 } |
141 | 143 |
142 void ThreadedChannel::SynchronouslyInitializeImpl( | 144 void ThreadedChannel::SynchronouslyInitializeImpl( |
143 LayerTreeHost* layer_tree_host, | 145 LayerTreeHost* layer_tree_host, |
144 scoped_ptr<BeginFrameSource> external_begin_frame_source) { | 146 std::unique_ptr<BeginFrameSource> external_begin_frame_source) { |
145 TRACE_EVENT0("cc", "ThreadChannel::SynchronouslyInitializeImpl"); | 147 TRACE_EVENT0("cc", "ThreadChannel::SynchronouslyInitializeImpl"); |
146 DCHECK(IsMainThread()); | 148 DCHECK(IsMainThread()); |
147 { | 149 { |
148 DebugScopedSetMainThreadBlocked main_thread_blocked(task_runner_provider_); | 150 DebugScopedSetMainThreadBlocked main_thread_blocked(task_runner_provider_); |
149 CompletionEvent completion; | 151 CompletionEvent completion; |
150 ImplThreadTaskRunner()->PostTask( | 152 ImplThreadTaskRunner()->PostTask( |
151 FROM_HERE, | 153 FROM_HERE, |
152 base::Bind(&ThreadedChannel::InitializeImplOnImpl, | 154 base::Bind(&ThreadedChannel::InitializeImplOnImpl, |
153 base::Unretained(this), &completion, layer_tree_host, | 155 base::Unretained(this), &completion, layer_tree_host, |
154 base::Passed(&external_begin_frame_source))); | 156 base::Passed(&external_begin_frame_source))); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 impl().proxy_main_weak_ptr)); | 209 impl().proxy_main_weak_ptr)); |
208 } | 210 } |
209 | 211 |
210 void ThreadedChannel::DidCommitAndDrawFrame() { | 212 void ThreadedChannel::DidCommitAndDrawFrame() { |
211 DCHECK(IsImplThread()); | 213 DCHECK(IsImplThread()); |
212 MainThreadTaskRunner()->PostTask(FROM_HERE, | 214 MainThreadTaskRunner()->PostTask(FROM_HERE, |
213 base::Bind(&ProxyMain::DidCommitAndDrawFrame, | 215 base::Bind(&ProxyMain::DidCommitAndDrawFrame, |
214 impl().proxy_main_weak_ptr)); | 216 impl().proxy_main_weak_ptr)); |
215 } | 217 } |
216 | 218 |
217 void ThreadedChannel::SetAnimationEvents(scoped_ptr<AnimationEvents> events) { | 219 void ThreadedChannel::SetAnimationEvents( |
| 220 std::unique_ptr<AnimationEvents> events) { |
218 DCHECK(IsImplThread()); | 221 DCHECK(IsImplThread()); |
219 MainThreadTaskRunner()->PostTask( | 222 MainThreadTaskRunner()->PostTask( |
220 FROM_HERE, base::Bind(&ProxyMain::SetAnimationEvents, | 223 FROM_HERE, base::Bind(&ProxyMain::SetAnimationEvents, |
221 impl().proxy_main_weak_ptr, base::Passed(&events))); | 224 impl().proxy_main_weak_ptr, base::Passed(&events))); |
222 } | 225 } |
223 | 226 |
224 void ThreadedChannel::DidLoseOutputSurface() { | 227 void ThreadedChannel::DidLoseOutputSurface() { |
225 DCHECK(IsImplThread()); | 228 DCHECK(IsImplThread()); |
226 MainThreadTaskRunner()->PostTask( | 229 MainThreadTaskRunner()->PostTask( |
227 FROM_HERE, | 230 FROM_HERE, |
(...skipping 17 matching lines...) Expand all Loading... |
245 } | 248 } |
246 | 249 |
247 void ThreadedChannel::DidCompletePageScaleAnimation() { | 250 void ThreadedChannel::DidCompletePageScaleAnimation() { |
248 DCHECK(IsImplThread()); | 251 DCHECK(IsImplThread()); |
249 MainThreadTaskRunner()->PostTask( | 252 MainThreadTaskRunner()->PostTask( |
250 FROM_HERE, base::Bind(&ProxyMain::DidCompletePageScaleAnimation, | 253 FROM_HERE, base::Bind(&ProxyMain::DidCompletePageScaleAnimation, |
251 impl().proxy_main_weak_ptr)); | 254 impl().proxy_main_weak_ptr)); |
252 } | 255 } |
253 | 256 |
254 void ThreadedChannel::PostFrameTimingEventsOnMain( | 257 void ThreadedChannel::PostFrameTimingEventsOnMain( |
255 scoped_ptr<FrameTimingTracker::CompositeTimingSet> composite_events, | 258 std::unique_ptr<FrameTimingTracker::CompositeTimingSet> composite_events, |
256 scoped_ptr<FrameTimingTracker::MainFrameTimingSet> main_frame_events) { | 259 std::unique_ptr<FrameTimingTracker::MainFrameTimingSet> main_frame_events) { |
257 DCHECK(IsImplThread()); | 260 DCHECK(IsImplThread()); |
258 MainThreadTaskRunner()->PostTask( | 261 MainThreadTaskRunner()->PostTask( |
259 FROM_HERE, base::Bind(&ProxyMain::PostFrameTimingEventsOnMain, | 262 FROM_HERE, base::Bind(&ProxyMain::PostFrameTimingEventsOnMain, |
260 impl().proxy_main_weak_ptr, | 263 impl().proxy_main_weak_ptr, |
261 base::Passed(std::move(composite_events)), | 264 base::Passed(std::move(composite_events)), |
262 base::Passed(std::move(main_frame_events)))); | 265 base::Passed(std::move(main_frame_events)))); |
263 } | 266 } |
264 | 267 |
265 void ThreadedChannel::BeginMainFrame( | 268 void ThreadedChannel::BeginMainFrame( |
266 scoped_ptr<BeginMainFrameAndCommitState> begin_main_frame_state) { | 269 std::unique_ptr<BeginMainFrameAndCommitState> begin_main_frame_state) { |
267 DCHECK(IsImplThread()); | 270 DCHECK(IsImplThread()); |
268 MainThreadTaskRunner()->PostTask( | 271 MainThreadTaskRunner()->PostTask( |
269 FROM_HERE, | 272 FROM_HERE, |
270 base::Bind(&ProxyMain::BeginMainFrame, impl().proxy_main_weak_ptr, | 273 base::Bind(&ProxyMain::BeginMainFrame, impl().proxy_main_weak_ptr, |
271 base::Passed(&begin_main_frame_state))); | 274 base::Passed(&begin_main_frame_state))); |
272 } | 275 } |
273 | 276 |
274 scoped_ptr<ProxyImpl> ThreadedChannel::CreateProxyImpl( | 277 std::unique_ptr<ProxyImpl> ThreadedChannel::CreateProxyImpl( |
275 ChannelImpl* channel_impl, | 278 ChannelImpl* channel_impl, |
276 LayerTreeHost* layer_tree_host, | 279 LayerTreeHost* layer_tree_host, |
277 TaskRunnerProvider* task_runner_provider, | 280 TaskRunnerProvider* task_runner_provider, |
278 scoped_ptr<BeginFrameSource> external_begin_frame_source) { | 281 std::unique_ptr<BeginFrameSource> external_begin_frame_source) { |
279 DCHECK(IsImplThread()); | 282 DCHECK(IsImplThread()); |
280 return ProxyImpl::Create(channel_impl, layer_tree_host, task_runner_provider, | 283 return ProxyImpl::Create(channel_impl, layer_tree_host, task_runner_provider, |
281 std::move(external_begin_frame_source)); | 284 std::move(external_begin_frame_source)); |
282 } | 285 } |
283 | 286 |
284 void ThreadedChannel::InitializeImplOnImpl( | 287 void ThreadedChannel::InitializeImplOnImpl( |
285 CompletionEvent* completion, | 288 CompletionEvent* completion, |
286 LayerTreeHost* layer_tree_host, | 289 LayerTreeHost* layer_tree_host, |
287 scoped_ptr<BeginFrameSource> external_begin_frame_source) { | 290 std::unique_ptr<BeginFrameSource> external_begin_frame_source) { |
288 DCHECK(IsImplThread()); | 291 DCHECK(IsImplThread()); |
289 impl().proxy_impl = | 292 impl().proxy_impl = |
290 CreateProxyImpl(this, layer_tree_host, task_runner_provider_, | 293 CreateProxyImpl(this, layer_tree_host, task_runner_provider_, |
291 std::move(external_begin_frame_source)); | 294 std::move(external_begin_frame_source)); |
292 impl().proxy_impl_weak_factory = make_scoped_ptr( | 295 impl().proxy_impl_weak_factory = base::WrapUnique( |
293 new base::WeakPtrFactory<ProxyImpl>(impl().proxy_impl.get())); | 296 new base::WeakPtrFactory<ProxyImpl>(impl().proxy_impl.get())); |
294 proxy_impl_weak_ptr_ = impl().proxy_impl_weak_factory->GetWeakPtr(); | 297 proxy_impl_weak_ptr_ = impl().proxy_impl_weak_factory->GetWeakPtr(); |
295 completion->Signal(); | 298 completion->Signal(); |
296 } | 299 } |
297 | 300 |
298 void ThreadedChannel::CloseImplOnImpl(CompletionEvent* completion) { | 301 void ThreadedChannel::CloseImplOnImpl(CompletionEvent* completion) { |
299 DCHECK(IsImplThread()); | 302 DCHECK(IsImplThread()); |
300 | 303 |
301 // We must destroy the factory and ensure that the ProxyImpl weak pointers are | 304 // We must destroy the factory and ensure that the ProxyImpl weak pointers are |
302 // invalidated before destroying proxy_impl. | 305 // invalidated before destroying proxy_impl. |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
351 | 354 |
352 ThreadedChannel::MainThreadOnly::~MainThreadOnly() {} | 355 ThreadedChannel::MainThreadOnly::~MainThreadOnly() {} |
353 | 356 |
354 ThreadedChannel::CompositorThreadOnly::CompositorThreadOnly( | 357 ThreadedChannel::CompositorThreadOnly::CompositorThreadOnly( |
355 base::WeakPtr<ProxyMain> proxy_main_weak_ptr) | 358 base::WeakPtr<ProxyMain> proxy_main_weak_ptr) |
356 : proxy_main_weak_ptr(proxy_main_weak_ptr) {} | 359 : proxy_main_weak_ptr(proxy_main_weak_ptr) {} |
357 | 360 |
358 ThreadedChannel::CompositorThreadOnly::~CompositorThreadOnly() {} | 361 ThreadedChannel::CompositorThreadOnly::~CompositorThreadOnly() {} |
359 | 362 |
360 } // namespace cc | 363 } // namespace cc |
OLD | NEW |