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_host.h" | |
6 | |
7 #include "cc/proto/compositor_message.pb.h" | |
8 #include "cc/proto/compositor_message_to_impl.pb.h" | |
9 | |
10 namespace cc { | |
11 | |
12 scoped_ptr<RemoteChannelHost> RemoteChannelHost::Create( | |
13 RemoteProtoChannel* remote_proto_channel, | |
14 RemoteChannelHostClient* client, | |
15 TaskGraphRunner* task_graph_runner, | |
16 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, | |
17 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner) { | |
18 return make_scoped_ptr( | |
19 new RemoteChannelHost(remote_proto_channel, client, task_graph_runner, | |
20 main_task_runner, impl_task_runner)); | |
21 } | |
22 | |
23 RemoteChannelHost::RemoteChannelHost( | |
24 RemoteProtoChannel* remote_proto_channel, | |
25 RemoteChannelHostClient* client, | |
26 TaskGraphRunner* task_graph_runner, | |
27 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, | |
28 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner) | |
29 : remote_proto_channel_(remote_proto_channel), | |
30 client_(client), | |
31 task_graph_runner_(task_graph_runner), | |
32 main_task_runner_(main_task_runner), | |
33 impl_task_runner_(impl_task_runner), | |
34 did_shutdown_(false) { | |
35 DCHECK(main_thread_checker_.CalledOnValidThread()); | |
36 DCHECK(remote_proto_channel_); | |
37 DCHECK(client_); | |
38 DCHECK(task_graph_runner_); | |
39 remote_proto_channel_->SetProtoReceiver(this); | |
40 } | |
41 | |
42 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
| |
43 DCHECK(main_thread_checker_.CalledOnValidThread()); | |
44 if (remote_channel_impl_) | |
45 remote_channel_impl_.reset(); | |
46 } | |
47 | |
48 scoped_ptr<RemoteChannelImpl> RemoteChannelHost::CreateRemoteChannelImpl( | |
49 RemoteChannelHost* remote_channel_host, | |
50 TaskGraphRunner* task_graph_runner, | |
51 const LayerTreeSettings& settings, | |
52 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, | |
53 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner) { | |
54 return RemoteChannelImpl::Create(remote_channel_host, task_graph_runner, | |
55 settings, main_task_runner, | |
56 impl_task_runner); | |
57 } | |
58 | |
59 void RemoteChannelHost::SendProto(const proto::CompositorMessage& proto) { | |
60 DCHECK(main_thread_checker_.CalledOnValidThread()); | |
61 remote_proto_channel_->SendCompositorProto(proto); | |
62 } | |
63 | |
64 void RemoteChannelHost::OnProtoReceived( | |
65 scoped_ptr<proto::CompositorMessage> proto) { | |
66 DCHECK(main_thread_checker_.CalledOnValidThread()); | |
67 DCHECK(!did_shutdown_); | |
68 DCHECK(proto->has_to_impl()); | |
69 proto::CompositorMessageToImpl to_impl_proto = proto->to_impl(); | |
70 switch (to_impl_proto.message_type()) { | |
71 case proto::CompositorMessageToImpl::Unknown: | |
72 return; | |
73 case proto::CompositorMessageToImpl::InitializeImpl: | |
74 InitializeImpl(to_impl_proto.initialize_impl_message()); | |
75 return; | |
76 case proto::CompositorMessageToImpl::CloseImpl: | |
77 DCHECK(remote_channel_impl_); | |
78 remote_channel_impl_.reset(); | |
79 | |
80 did_shutdown_ = true; | |
81 | |
82 // It is not safe to access any variables after this method is called. The | |
83 // client may destroy us now so |this| will not be there anymore. | |
84 client_->DidShutdown(); | |
85 return; | |
86 default: | |
87 DCHECK(remote_channel_impl_); | |
88 remote_channel_impl_->HandleProto(to_impl_proto); | |
89 } | |
90 } | |
91 | |
92 void RemoteChannelHost::InitializeImpl(const proto::InitializeImpl& proto) { | |
93 DCHECK(main_thread_checker_.CalledOnValidThread()); | |
94 DCHECK(!remote_channel_impl_); | |
95 proto::LayerTreeSettings settings_proto = proto.layer_tree_settings(); | |
96 | |
97 // TODO(khushalsagar, nyquist): Deserialize using | |
98 // LayerTreeSettings:FromProtobuf. | |
99 LayerTreeSettings settings; | |
100 settings.single_thread_proxy_scheduler = | |
101 settings_proto.single_thread_proxy_scheduler(); | |
102 | |
103 client_->OverrideLayerTreeSettings(&settings); | |
104 | |
105 remote_channel_impl_ = CreateRemoteChannelImpl( | |
106 this, task_graph_runner_, settings, main_task_runner_, impl_task_runner_); | |
107 remote_channel_impl_->Initialize(); | |
108 | |
109 task_graph_runner_ = nullptr; | |
110 main_task_runner_ = nullptr; | |
111 impl_task_runner_ = nullptr; | |
112 } | |
113 | |
114 } // namespace cc | |
OLD | NEW |