OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #ifndef CONTENT_COMMON_GPU_CLIENT_GPU_CHANNEL_HOST_H_ | 5 #ifndef CONTENT_COMMON_GPU_CLIENT_GPU_CHANNEL_HOST_H_ |
6 #define CONTENT_COMMON_GPU_CLIENT_GPU_CHANNEL_HOST_H_ | 6 #define CONTENT_COMMON_GPU_CLIENT_GPU_CHANNEL_HOST_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/hash_tables.h" | 12 #include "base/hash_tables.h" |
13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
15 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
| 16 #include "base/process.h" |
16 #include "base/process_util.h" | 17 #include "base/process_util.h" |
17 #include "base/synchronization/lock.h" | 18 #include "base/synchronization/lock.h" |
18 #include "content/common/content_export.h" | 19 #include "content/common/content_export.h" |
19 #include "content/common/gpu/gpu_process_launch_causes.h" | 20 #include "content/common/gpu/gpu_process_launch_causes.h" |
20 #include "content/common/message_router.h" | 21 #include "content/common/message_router.h" |
21 #include "content/public/common/gpu_info.h" | 22 #include "content/public/common/gpu_info.h" |
22 #include "content/common/gpu/client/gpu_video_decode_accelerator_host.h" | 23 #include "content/common/gpu/client/gpu_video_decode_accelerator_host.h" |
23 #include "ipc/ipc_channel_handle.h" | 24 #include "ipc/ipc_channel_handle.h" |
24 #include "ipc/ipc_channel_proxy.h" | 25 #include "ipc/ipc_channel_proxy.h" |
25 #include "ipc/ipc_sync_channel.h" | 26 #include "ipc/ipc_sync_channel.h" |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 kUnconnected, | 77 kUnconnected, |
77 // Ready to use. | 78 // Ready to use. |
78 kConnected, | 79 kConnected, |
79 // An error caused the host to become disconnected. Recreate channel to | 80 // An error caused the host to become disconnected. Recreate channel to |
80 // reestablish connection. | 81 // reestablish connection. |
81 kLost | 82 kLost |
82 }; | 83 }; |
83 | 84 |
84 // Called on the render thread | 85 // Called on the render thread |
85 GpuChannelHost(GpuChannelHostFactory* factory, | 86 GpuChannelHost(GpuChannelHostFactory* factory, |
86 int gpu_process_id, | 87 int gpu_host_id, |
87 int client_id); | 88 int client_id); |
88 virtual ~GpuChannelHost(); | 89 virtual ~GpuChannelHost(); |
89 | 90 |
90 // Connect to GPU process channel. | 91 // Connect to GPU process channel. |
91 void Connect(const IPC::ChannelHandle& channel_handle, | 92 void Connect(const IPC::ChannelHandle& channel_handle); |
92 base::ProcessHandle client_process_for_gpu); | |
93 | 93 |
94 State state() const { return state_; } | 94 State state() const { return state_; } |
95 | 95 |
96 // Change state to kLost. | 96 // Change state to kLost. |
97 void SetStateLost(); | 97 void SetStateLost(); |
98 | 98 |
99 // The GPU stats reported by the GPU process. | 99 // The GPU stats reported by the GPU process. |
100 void set_gpu_info(const content::GPUInfo& gpu_info); | 100 void set_gpu_info(const content::GPUInfo& gpu_info); |
101 const content::GPUInfo& gpu_info() const; | 101 const content::GPUInfo& gpu_info() const; |
102 | 102 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 bool WillGpuSwitchOccur(bool is_creating_context, | 145 bool WillGpuSwitchOccur(bool is_creating_context, |
146 gfx::GpuPreference gpu_preference); | 146 gfx::GpuPreference gpu_preference); |
147 | 147 |
148 // Forcibly close the channel on the GPU process side. This will | 148 // Forcibly close the channel on the GPU process side. This will |
149 // cause all command buffers on this side to soon afterward start | 149 // cause all command buffers on this side to soon afterward start |
150 // registering lost contexts. It also has the side effect of setting | 150 // registering lost contexts. It also has the side effect of setting |
151 // the state on this side to lost. | 151 // the state on this side to lost. |
152 void ForciblyCloseChannel(); | 152 void ForciblyCloseChannel(); |
153 | 153 |
154 GpuChannelHostFactory* factory() const { return factory_; } | 154 GpuChannelHostFactory* factory() const { return factory_; } |
155 int gpu_process_id() const { return gpu_process_id_; } | 155 int gpu_host_id() const { return gpu_host_id_; } |
| 156 base::ProcessId gpu_pid() const { return channel_->peer_pid(); } |
156 int client_id() const { return client_id_; } | 157 int client_id() const { return client_id_; } |
157 | 158 |
158 private: | 159 private: |
159 // A filter used internally to route incoming messages from the IO thread | 160 // A filter used internally to route incoming messages from the IO thread |
160 // to the correct message loop. | 161 // to the correct message loop. |
161 class MessageFilter : public IPC::ChannelProxy::MessageFilter { | 162 class MessageFilter : public IPC::ChannelProxy::MessageFilter { |
162 public: | 163 public: |
163 explicit MessageFilter(GpuChannelHost* parent); | 164 explicit MessageFilter(GpuChannelHost* parent); |
164 virtual ~MessageFilter(); | 165 virtual ~MessageFilter(); |
165 | 166 |
166 void AddRoute(int route_id, | 167 void AddRoute(int route_id, |
167 base::WeakPtr<IPC::Channel::Listener> listener, | 168 base::WeakPtr<IPC::Channel::Listener> listener, |
168 scoped_refptr<base::MessageLoopProxy> loop); | 169 scoped_refptr<base::MessageLoopProxy> loop); |
169 void RemoveRoute(int route_id); | 170 void RemoveRoute(int route_id); |
170 | 171 |
171 // IPC::ChannelProxy::MessageFilter implementation: | 172 // IPC::ChannelProxy::MessageFilter implementation: |
172 virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE; | 173 virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE; |
173 virtual void OnChannelError() OVERRIDE; | 174 virtual void OnChannelError() OVERRIDE; |
174 | 175 |
175 private: | 176 private: |
176 GpuChannelHost* parent_; | 177 GpuChannelHost* parent_; |
177 | 178 |
178 typedef base::hash_map<int, GpuListenerInfo> ListenerMap; | 179 typedef base::hash_map<int, GpuListenerInfo> ListenerMap; |
179 ListenerMap listeners_; | 180 ListenerMap listeners_; |
180 }; | 181 }; |
181 | 182 |
182 GpuChannelHostFactory* factory_; | 183 GpuChannelHostFactory* factory_; |
183 int gpu_process_id_; | |
184 int client_id_; | 184 int client_id_; |
| 185 int gpu_host_id_; |
185 | 186 |
186 State state_; | 187 State state_; |
187 | 188 |
188 content::GPUInfo gpu_info_; | 189 content::GPUInfo gpu_info_; |
189 | 190 |
190 scoped_ptr<IPC::SyncChannel> channel_; | 191 scoped_ptr<IPC::SyncChannel> channel_; |
191 scoped_refptr<MessageFilter> channel_filter_; | 192 scoped_refptr<MessageFilter> channel_filter_; |
192 | 193 |
193 // Used to look up a proxy from its routing id. | 194 // Used to look up a proxy from its routing id. |
194 typedef base::hash_map<int, CommandBufferProxyImpl*> ProxyMap; | 195 typedef base::hash_map<int, CommandBufferProxyImpl*> ProxyMap; |
195 ProxyMap proxies_; | 196 ProxyMap proxies_; |
196 | 197 |
197 // A lock to guard against concurrent access to members like the proxies map | 198 // A lock to guard against concurrent access to members like the proxies map |
198 // for calls from contexts that may live on the compositor or main thread. | 199 // for calls from contexts that may live on the compositor or main thread. |
199 mutable base::Lock context_lock_; | 200 mutable base::Lock context_lock_; |
200 | 201 |
201 // A filter for sending messages from thread other than the main thread. | 202 // A filter for sending messages from thread other than the main thread. |
202 scoped_refptr<IPC::SyncMessageFilter> sync_filter_; | 203 scoped_refptr<IPC::SyncMessageFilter> sync_filter_; |
203 | 204 |
204 DISALLOW_COPY_AND_ASSIGN(GpuChannelHost); | 205 DISALLOW_COPY_AND_ASSIGN(GpuChannelHost); |
205 }; | 206 }; |
206 | 207 |
207 #endif // CONTENT_COMMON_GPU_CLIENT_GPU_CHANNEL_HOST_H_ | 208 #endif // CONTENT_COMMON_GPU_CLIENT_GPU_CHANNEL_HOST_H_ |
OLD | NEW |