Chromium Code Reviews| Index: cc/trees/remote_channel_host.cc |
| diff --git a/cc/trees/remote_channel_host.cc b/cc/trees/remote_channel_host.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..c4fc98bffdad6e7a1e0bb16dbc4e73b628c793bb |
| --- /dev/null |
| +++ b/cc/trees/remote_channel_host.cc |
| @@ -0,0 +1,114 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "cc/trees/remote_channel_host.h" |
| + |
| +#include "cc/proto/compositor_message.pb.h" |
| +#include "cc/proto/compositor_message_to_impl.pb.h" |
| + |
| +namespace cc { |
| + |
| +scoped_ptr<RemoteChannelHost> RemoteChannelHost::Create( |
| + RemoteProtoChannel* remote_proto_channel, |
| + RemoteChannelHostClient* client, |
| + TaskGraphRunner* task_graph_runner, |
| + scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, |
| + scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner) { |
| + return make_scoped_ptr( |
| + new RemoteChannelHost(remote_proto_channel, client, task_graph_runner, |
| + main_task_runner, impl_task_runner)); |
| +} |
| + |
| +RemoteChannelHost::RemoteChannelHost( |
| + RemoteProtoChannel* remote_proto_channel, |
| + RemoteChannelHostClient* client, |
| + TaskGraphRunner* task_graph_runner, |
| + scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, |
| + scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner) |
| + : remote_proto_channel_(remote_proto_channel), |
| + client_(client), |
| + task_graph_runner_(task_graph_runner), |
| + main_task_runner_(main_task_runner), |
| + impl_task_runner_(impl_task_runner), |
| + did_shutdown_(false) { |
| + DCHECK(main_thread_checker_.CalledOnValidThread()); |
| + DCHECK(remote_proto_channel_); |
| + DCHECK(client_); |
| + DCHECK(task_graph_runner_); |
| + remote_proto_channel_->SetProtoReceiver(this); |
| +} |
| + |
| +RemoteChannelHost::~RemoteChannelHost() { |
|
David Trainor- moved to gerrit
2015/12/11 17:13:44
remote_proto_channel_->SetProtoReceiver(nullptr) h
Khushal
2015/12/11 22:49:37
Done.
I was unsure about this too. But I think its
|
| + DCHECK(main_thread_checker_.CalledOnValidThread()); |
| + if (remote_channel_impl_) |
| + remote_channel_impl_.reset(); |
| +} |
| + |
| +scoped_ptr<RemoteChannelImpl> RemoteChannelHost::CreateRemoteChannelImpl( |
| + RemoteChannelHost* remote_channel_host, |
| + TaskGraphRunner* task_graph_runner, |
| + const LayerTreeSettings& settings, |
| + scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, |
| + scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner) { |
| + return RemoteChannelImpl::Create(remote_channel_host, task_graph_runner, |
| + settings, main_task_runner, |
| + impl_task_runner); |
| +} |
| + |
| +void RemoteChannelHost::SendProto(const proto::CompositorMessage& proto) { |
| + DCHECK(main_thread_checker_.CalledOnValidThread()); |
| + remote_proto_channel_->SendCompositorProto(proto); |
| +} |
| + |
| +void RemoteChannelHost::OnProtoReceived( |
| + scoped_ptr<proto::CompositorMessage> proto) { |
| + DCHECK(main_thread_checker_.CalledOnValidThread()); |
| + DCHECK(!did_shutdown_); |
| + DCHECK(proto->has_to_impl()); |
| + proto::CompositorMessageToImpl to_impl_proto = proto->to_impl(); |
| + switch (to_impl_proto.message_type()) { |
| + case proto::CompositorMessageToImpl::Unknown: |
| + return; |
| + case proto::CompositorMessageToImpl::InitializeImpl: |
| + InitializeImpl(to_impl_proto.initialize_impl_message()); |
| + return; |
| + case proto::CompositorMessageToImpl::CloseImpl: |
| + DCHECK(remote_channel_impl_); |
| + remote_channel_impl_.reset(); |
| + |
| + did_shutdown_ = true; |
| + |
| + // It is not safe to access any variables after this method is called. The |
| + // client may destroy us now so |this| will not be there anymore. |
| + client_->DidShutdown(); |
| + return; |
| + default: |
| + DCHECK(remote_channel_impl_); |
| + remote_channel_impl_->HandleProto(to_impl_proto); |
| + } |
| +} |
| + |
| +void RemoteChannelHost::InitializeImpl(const proto::InitializeImpl& proto) { |
| + DCHECK(main_thread_checker_.CalledOnValidThread()); |
| + DCHECK(!remote_channel_impl_); |
| + proto::LayerTreeSettings settings_proto = proto.layer_tree_settings(); |
| + |
| + // TODO(khushalsagar, nyquist): Deserialize using |
| + // LayerTreeSettings:FromProtobuf. |
| + LayerTreeSettings settings; |
| + settings.single_thread_proxy_scheduler = |
| + settings_proto.single_thread_proxy_scheduler(); |
| + |
| + client_->OverrideLayerTreeSettings(&settings); |
| + |
| + remote_channel_impl_ = CreateRemoteChannelImpl( |
| + this, task_graph_runner_, settings, main_task_runner_, impl_task_runner_); |
| + remote_channel_impl_->Initialize(); |
| + |
| + task_graph_runner_ = nullptr; |
| + main_task_runner_ = nullptr; |
| + impl_task_runner_ = nullptr; |
| +} |
| + |
| +} // namespace cc |