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