OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 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/remote_channel_impl.h" |
| 6 |
| 7 #include "base/bind_helpers.h" |
| 8 #include "base/single_thread_task_runner.h" |
| 9 #include "cc/animation/animation_events.h" |
| 10 #include "cc/proto/compositor_message.pb.h" |
| 11 #include "cc/proto/compositor_message_to_impl.pb.h" |
| 12 #include "cc/proto/compositor_message_to_main.pb.h" |
| 13 #include "cc/trees/layer_tree_host.h" |
| 14 #include "cc/trees/layer_tree_settings.h" |
| 15 |
| 16 namespace cc { |
| 17 |
| 18 scoped_ptr<RemoteChannelImpl> RemoteChannelImpl::Create( |
| 19 LayerTreeHost* layer_tree_host, |
| 20 RemoteProtoChannel* remote_proto_channel, |
| 21 TaskRunnerProvider* task_runner_provider) { |
| 22 return make_scoped_ptr(new RemoteChannelImpl( |
| 23 layer_tree_host, remote_proto_channel, task_runner_provider)); |
| 24 } |
| 25 |
| 26 RemoteChannelImpl::RemoteChannelImpl(LayerTreeHost* layer_tree_host, |
| 27 RemoteProtoChannel* remote_proto_channel, |
| 28 TaskRunnerProvider* task_runner_provider) |
| 29 : main_thread_vars_unsafe_(layer_tree_host, remote_proto_channel), |
| 30 task_runner_provider_(task_runner_provider) { |
| 31 DCHECK(task_runner_provider_->IsMainThread()); |
| 32 |
| 33 main().remote_proto_channel->SetProtoReceiver(this); |
| 34 } |
| 35 |
| 36 RemoteChannelImpl::~RemoteChannelImpl() { |
| 37 DCHECK(task_runner_provider_->IsMainThread()); |
| 38 DCHECK(!main().started); |
| 39 |
| 40 main().remote_proto_channel->SetProtoReceiver(nullptr); |
| 41 } |
| 42 |
| 43 scoped_ptr<ProxyImpl> RemoteChannelImpl::CreateProxyImpl( |
| 44 ChannelImpl* channel_impl, |
| 45 LayerTreeHost* layer_tree_host, |
| 46 TaskRunnerProvider* task_runner_provider, |
| 47 scoped_ptr<BeginFrameSource> external_begin_frame_source) { |
| 48 DCHECK(task_runner_provider_->IsImplThread()); |
| 49 DCHECK(!external_begin_frame_source); |
| 50 return ProxyImpl::Create(channel_impl, layer_tree_host, task_runner_provider, |
| 51 std::move(external_begin_frame_source)); |
| 52 } |
| 53 |
| 54 void RemoteChannelImpl::OnProtoReceived( |
| 55 scoped_ptr<proto::CompositorMessage> proto) { |
| 56 DCHECK(task_runner_provider_->IsMainThread()); |
| 57 DCHECK(main().started); |
| 58 DCHECK(proto->has_to_impl()); |
| 59 |
| 60 HandleProto(proto->to_impl()); |
| 61 } |
| 62 |
| 63 void RemoteChannelImpl::HandleProto( |
| 64 const proto::CompositorMessageToImpl& proto) { |
| 65 DCHECK(task_runner_provider_->IsMainThread()); |
| 66 |
| 67 switch (proto.message_type()) { |
| 68 case proto::CompositorMessageToImpl:: |
| 69 MAIN_THREAD_HAS_STOPPED_FLINGING_ON_IMPL: |
| 70 ImplThreadTaskRunner()->PostTask( |
| 71 FROM_HERE, base::Bind(&ProxyImpl::MainThreadHasStoppedFlingingOnImpl, |
| 72 proxy_impl_weak_ptr_)); |
| 73 break; |
| 74 default: |
| 75 // TODO(khushalsagar): Add more types here. |
| 76 NOTIMPLEMENTED(); |
| 77 } |
| 78 } |
| 79 |
| 80 void RemoteChannelImpl::FinishAllRendering() { |
| 81 NOTREACHED() << "Should not be called on the remote client LayerTreeHost"; |
| 82 } |
| 83 |
| 84 bool RemoteChannelImpl::IsStarted() const { |
| 85 DCHECK(task_runner_provider_->IsMainThread()); |
| 86 return main().started; |
| 87 } |
| 88 |
| 89 bool RemoteChannelImpl::CommitToActiveTree() const { |
| 90 return false; |
| 91 } |
| 92 |
| 93 void RemoteChannelImpl::SetOutputSurface(OutputSurface* output_surface) { |
| 94 DCHECK(task_runner_provider_->IsMainThread()); |
| 95 ImplThreadTaskRunner()->PostTask( |
| 96 FROM_HERE, base::Bind(&ProxyImpl::InitializeOutputSurfaceOnImpl, |
| 97 proxy_impl_weak_ptr_, output_surface)); |
| 98 } |
| 99 |
| 100 void RemoteChannelImpl::ReleaseOutputSurface() { |
| 101 DCHECK(task_runner_provider_->IsMainThread()); |
| 102 CompletionEvent completion; |
| 103 DebugScopedSetMainThreadBlocked main_thread_blocked(task_runner_provider_); |
| 104 ImplThreadTaskRunner()->PostTask( |
| 105 FROM_HERE, base::Bind(&ProxyImpl::ReleaseOutputSurfaceOnImpl, |
| 106 proxy_impl_weak_ptr_, &completion)); |
| 107 completion.Wait(); |
| 108 } |
| 109 |
| 110 void RemoteChannelImpl::SetVisible(bool visible) { |
| 111 DCHECK(task_runner_provider_->IsMainThread()); |
| 112 ImplThreadTaskRunner()->PostTask( |
| 113 FROM_HERE, |
| 114 base::Bind(&ProxyImpl::SetVisibleOnImpl, proxy_impl_weak_ptr_, visible)); |
| 115 } |
| 116 |
| 117 void RemoteChannelImpl::SetThrottleFrameProduction(bool throttle) { |
| 118 NOTREACHED() << "Should not be called on the remote client LayerTreeHost"; |
| 119 } |
| 120 |
| 121 const RendererCapabilities& RemoteChannelImpl::GetRendererCapabilities() const { |
| 122 NOTREACHED() << "Should not be called on the remote client LayerTreeHost"; |
| 123 return main().renderer_capabilities; |
| 124 } |
| 125 |
| 126 void RemoteChannelImpl::SetNeedsAnimate() { |
| 127 NOTREACHED() << "Should not be called on the remote client LayerTreeHost"; |
| 128 } |
| 129 |
| 130 void RemoteChannelImpl::SetNeedsUpdateLayers() { |
| 131 NOTREACHED() << "Should not be called on the remote client LayerTreeHost"; |
| 132 } |
| 133 |
| 134 void RemoteChannelImpl::SetNeedsCommit() { |
| 135 NOTREACHED() << "Should not be called on the remote client LayerTreeHost"; |
| 136 } |
| 137 |
| 138 void RemoteChannelImpl::SetNeedsRedraw(const gfx::Rect& damage_rect) { |
| 139 NOTREACHED() << "Should not be called on the remote client LayerTreeHost"; |
| 140 } |
| 141 |
| 142 void RemoteChannelImpl::SetNextCommitWaitsForActivation() { |
| 143 NOTREACHED() << "Should not be called on the remote client LayerTreeHost"; |
| 144 } |
| 145 |
| 146 void RemoteChannelImpl::NotifyInputThrottledUntilCommit() { |
| 147 NOTREACHED() << "Should not be called on the remote client LayerTreeHost"; |
| 148 } |
| 149 |
| 150 void RemoteChannelImpl::SetDeferCommits(bool defer_commits) { |
| 151 NOTREACHED() << "Should not be called on the remote client LayerTreeHost"; |
| 152 } |
| 153 |
| 154 void RemoteChannelImpl::MainThreadHasStoppedFlinging() { |
| 155 NOTREACHED() << "Should not be called on the remote client LayerTreeHost"; |
| 156 } |
| 157 |
| 158 bool RemoteChannelImpl::CommitRequested() const { |
| 159 NOTREACHED() << "Should not be called on the remote client LayerTreeHost"; |
| 160 return false; |
| 161 } |
| 162 |
| 163 bool RemoteChannelImpl::BeginMainFrameRequested() const { |
| 164 NOTREACHED() << "Should not be called on the remote client LayerTreeHost"; |
| 165 return false; |
| 166 } |
| 167 |
| 168 void RemoteChannelImpl::Start( |
| 169 scoped_ptr<BeginFrameSource> external_begin_frame_source) { |
| 170 DCHECK(task_runner_provider_->IsMainThread()); |
| 171 DCHECK(!main().started); |
| 172 DCHECK(!external_begin_frame_source); |
| 173 |
| 174 CompletionEvent completion; |
| 175 { |
| 176 DebugScopedSetMainThreadBlocked main_thread_blocked(task_runner_provider_); |
| 177 ImplThreadTaskRunner()->PostTask( |
| 178 FROM_HERE, base::Bind(&RemoteChannelImpl::InitializeImplOnImpl, |
| 179 base::Unretained(this), &completion, |
| 180 main().layer_tree_host)); |
| 181 completion.Wait(); |
| 182 } |
| 183 main().started = true; |
| 184 } |
| 185 |
| 186 void RemoteChannelImpl::Stop() { |
| 187 DCHECK(task_runner_provider_->IsMainThread()); |
| 188 DCHECK(main().started); |
| 189 |
| 190 { |
| 191 CompletionEvent completion; |
| 192 DebugScopedSetMainThreadBlocked main_thread_blocked(task_runner_provider_); |
| 193 ImplThreadTaskRunner()->PostTask( |
| 194 FROM_HERE, base::Bind(&ProxyImpl::FinishGLOnImpl, proxy_impl_weak_ptr_, |
| 195 &completion)); |
| 196 completion.Wait(); |
| 197 } |
| 198 { |
| 199 CompletionEvent completion; |
| 200 DebugScopedSetMainThreadBlocked main_thread_blocked(task_runner_provider_); |
| 201 ImplThreadTaskRunner()->PostTask( |
| 202 FROM_HERE, base::Bind(&RemoteChannelImpl::ShutdownImplOnImpl, |
| 203 base::Unretained(this), &completion)); |
| 204 completion.Wait(); |
| 205 } |
| 206 |
| 207 main().started = false; |
| 208 } |
| 209 |
| 210 bool RemoteChannelImpl::SupportsImplScrolling() const { |
| 211 return true; |
| 212 } |
| 213 |
| 214 void RemoteChannelImpl::SetChildrenNeedBeginFrames( |
| 215 bool children_need_begin_frames) { |
| 216 NOTREACHED() << "Should not be called on the remote client LayerTreeHost"; |
| 217 } |
| 218 |
| 219 void RemoteChannelImpl::SetAuthoritativeVSyncInterval( |
| 220 const base::TimeDelta& interval) { |
| 221 NOTREACHED() << "Should not be called on the remote client LayerTreeHost"; |
| 222 } |
| 223 |
| 224 void RemoteChannelImpl::UpdateTopControlsState(TopControlsState constraints, |
| 225 TopControlsState current, |
| 226 bool animate) { |
| 227 NOTREACHED() << "Should not be called on the remote client LayerTreeHost"; |
| 228 } |
| 229 |
| 230 bool RemoteChannelImpl::MainFrameWillHappenForTesting() { |
| 231 DCHECK(task_runner_provider_->IsMainThread()); |
| 232 bool main_frame_will_happen; |
| 233 { |
| 234 CompletionEvent completion; |
| 235 DebugScopedSetMainThreadBlocked main_thread_blocked(task_runner_provider_); |
| 236 ImplThreadTaskRunner()->PostTask( |
| 237 FROM_HERE, |
| 238 base::Bind(&ProxyImpl::MainFrameWillHappenOnImplForTesting, |
| 239 proxy_impl_weak_ptr_, &completion, &main_frame_will_happen)); |
| 240 completion.Wait(); |
| 241 } |
| 242 return main_frame_will_happen; |
| 243 } |
| 244 |
| 245 void RemoteChannelImpl::DidCompleteSwapBuffers() {} |
| 246 |
| 247 void RemoteChannelImpl::SetRendererCapabilitiesMainCopy( |
| 248 const RendererCapabilities& capabilities) {} |
| 249 |
| 250 void RemoteChannelImpl::BeginMainFrameNotExpectedSoon() {} |
| 251 |
| 252 void RemoteChannelImpl::DidCommitAndDrawFrame() {} |
| 253 |
| 254 void RemoteChannelImpl::SetAnimationEvents(scoped_ptr<AnimationEvents> queue) {} |
| 255 |
| 256 void RemoteChannelImpl::DidLoseOutputSurface() {} |
| 257 |
| 258 void RemoteChannelImpl::RequestNewOutputSurface() {} |
| 259 |
| 260 void RemoteChannelImpl::DidInitializeOutputSurface( |
| 261 bool success, |
| 262 const RendererCapabilities& capabilities) {} |
| 263 |
| 264 void RemoteChannelImpl::DidCompletePageScaleAnimation() {} |
| 265 |
| 266 void RemoteChannelImpl::PostFrameTimingEventsOnMain( |
| 267 scoped_ptr<FrameTimingTracker::CompositeTimingSet> composite_events, |
| 268 scoped_ptr<FrameTimingTracker::MainFrameTimingSet> main_frame_events) {} |
| 269 |
| 270 void RemoteChannelImpl::BeginMainFrame( |
| 271 scoped_ptr<BeginMainFrameAndCommitState> begin_main_frame_state) {} |
| 272 |
| 273 void RemoteChannelImpl::InitializeImplOnImpl(CompletionEvent* completion, |
| 274 LayerTreeHost* layer_tree_host) { |
| 275 DCHECK(task_runner_provider_->IsMainThreadBlocked()); |
| 276 DCHECK(task_runner_provider_->IsImplThread()); |
| 277 |
| 278 impl().proxy_impl = |
| 279 CreateProxyImpl(this, layer_tree_host, task_runner_provider_, nullptr); |
| 280 impl().proxy_impl_weak_factory = make_scoped_ptr( |
| 281 new base::WeakPtrFactory<ProxyImpl>(impl().proxy_impl.get())); |
| 282 proxy_impl_weak_ptr_ = impl().proxy_impl_weak_factory->GetWeakPtr(); |
| 283 completion->Signal(); |
| 284 } |
| 285 |
| 286 void RemoteChannelImpl::ShutdownImplOnImpl(CompletionEvent* completion) { |
| 287 DCHECK(task_runner_provider_->IsMainThreadBlocked()); |
| 288 DCHECK(task_runner_provider_->IsImplThread()); |
| 289 |
| 290 // We must invalidate the proxy_impl weak ptrs and destroy the weak ptr |
| 291 // factory before destroying proxy_impl. |
| 292 impl().proxy_impl_weak_factory->InvalidateWeakPtrs(); |
| 293 impl().proxy_impl_weak_factory.reset(); |
| 294 |
| 295 impl().proxy_impl.reset(); |
| 296 completion->Signal(); |
| 297 } |
| 298 |
| 299 RemoteChannelImpl::MainThreadOnly& RemoteChannelImpl::main() { |
| 300 DCHECK(task_runner_provider_->IsMainThread()); |
| 301 return main_thread_vars_unsafe_; |
| 302 } |
| 303 |
| 304 const RemoteChannelImpl::MainThreadOnly& RemoteChannelImpl::main() const { |
| 305 DCHECK(task_runner_provider_->IsMainThread()); |
| 306 return main_thread_vars_unsafe_; |
| 307 } |
| 308 |
| 309 RemoteChannelImpl::CompositorThreadOnly& RemoteChannelImpl::impl() { |
| 310 DCHECK(task_runner_provider_->IsImplThread()); |
| 311 return compositor_thread_vars_unsafe_; |
| 312 } |
| 313 |
| 314 const RemoteChannelImpl::CompositorThreadOnly& RemoteChannelImpl::impl() const { |
| 315 DCHECK(task_runner_provider_->IsImplThread()); |
| 316 return compositor_thread_vars_unsafe_; |
| 317 } |
| 318 |
| 319 base::SingleThreadTaskRunner* RemoteChannelImpl::MainThreadTaskRunner() const { |
| 320 return task_runner_provider_->MainThreadTaskRunner(); |
| 321 } |
| 322 |
| 323 base::SingleThreadTaskRunner* RemoteChannelImpl::ImplThreadTaskRunner() const { |
| 324 return task_runner_provider_->ImplThreadTaskRunner(); |
| 325 } |
| 326 |
| 327 RemoteChannelImpl::MainThreadOnly::MainThreadOnly( |
| 328 LayerTreeHost* layer_tree_host, |
| 329 RemoteProtoChannel* remote_proto_channel) |
| 330 : layer_tree_host(layer_tree_host), |
| 331 remote_proto_channel(remote_proto_channel), |
| 332 started(false) { |
| 333 DCHECK(layer_tree_host); |
| 334 DCHECK(remote_proto_channel); |
| 335 } |
| 336 |
| 337 RemoteChannelImpl::MainThreadOnly::~MainThreadOnly() {} |
| 338 |
| 339 RemoteChannelImpl::CompositorThreadOnly::CompositorThreadOnly() |
| 340 : proxy_impl(nullptr), proxy_impl_weak_factory(nullptr) {} |
| 341 |
| 342 RemoteChannelImpl::CompositorThreadOnly::~CompositorThreadOnly() {} |
| 343 |
| 344 } // namespace cc |
OLD | NEW |