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