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" | |
17 #include "base/process_util.h" | 16 #include "base/process_util.h" |
18 #include "base/synchronization/lock.h" | 17 #include "base/synchronization/lock.h" |
19 #include "content/common/content_export.h" | 18 #include "content/common/content_export.h" |
20 #include "content/common/gpu/gpu_process_launch_causes.h" | 19 #include "content/common/gpu/gpu_process_launch_causes.h" |
21 #include "content/common/message_router.h" | 20 #include "content/common/message_router.h" |
22 #include "content/public/common/gpu_info.h" | 21 #include "content/public/common/gpu_info.h" |
23 #include "content/common/gpu/client/gpu_video_decode_accelerator_host.h" | 22 #include "content/common/gpu/client/gpu_video_decode_accelerator_host.h" |
24 #include "ipc/ipc_channel_handle.h" | 23 #include "ipc/ipc_channel_handle.h" |
25 #include "ipc/ipc_channel_proxy.h" | 24 #include "ipc/ipc_channel_proxy.h" |
26 #include "ipc/ipc_sync_channel.h" | 25 #include "ipc/ipc_sync_channel.h" |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 kUnconnected, | 76 kUnconnected, |
78 // Ready to use. | 77 // Ready to use. |
79 kConnected, | 78 kConnected, |
80 // An error caused the host to become disconnected. Recreate channel to | 79 // An error caused the host to become disconnected. Recreate channel to |
81 // reestablish connection. | 80 // reestablish connection. |
82 kLost | 81 kLost |
83 }; | 82 }; |
84 | 83 |
85 // Called on the render thread | 84 // Called on the render thread |
86 GpuChannelHost(GpuChannelHostFactory* factory, | 85 GpuChannelHost(GpuChannelHostFactory* factory, |
87 int gpu_host_id, | 86 int gpu_process_id, |
88 int client_id); | 87 int client_id); |
89 virtual ~GpuChannelHost(); | 88 virtual ~GpuChannelHost(); |
90 | 89 |
91 // Connect to GPU process channel. | 90 // Connect to GPU process channel. |
92 void Connect(const IPC::ChannelHandle& channel_handle); | 91 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_host_id() const { return gpu_host_id_; } | 155 int gpu_process_id() const { return gpu_process_id_; } |
156 base::ProcessId gpu_pid() const { return channel_->peer_pid(); } | |
157 int client_id() const { return client_id_; } | 156 int client_id() const { return client_id_; } |
158 | 157 |
159 private: | 158 private: |
160 // A filter used internally to route incoming messages from the IO thread | 159 // A filter used internally to route incoming messages from the IO thread |
161 // to the correct message loop. | 160 // to the correct message loop. |
162 class MessageFilter : public IPC::ChannelProxy::MessageFilter { | 161 class MessageFilter : public IPC::ChannelProxy::MessageFilter { |
163 public: | 162 public: |
164 explicit MessageFilter(GpuChannelHost* parent); | 163 explicit MessageFilter(GpuChannelHost* parent); |
165 virtual ~MessageFilter(); | 164 virtual ~MessageFilter(); |
166 | 165 |
167 void AddRoute(int route_id, | 166 void AddRoute(int route_id, |
168 base::WeakPtr<IPC::Channel::Listener> listener, | 167 base::WeakPtr<IPC::Channel::Listener> listener, |
169 scoped_refptr<base::MessageLoopProxy> loop); | 168 scoped_refptr<base::MessageLoopProxy> loop); |
170 void RemoveRoute(int route_id); | 169 void RemoveRoute(int route_id); |
171 | 170 |
172 // IPC::ChannelProxy::MessageFilter implementation: | 171 // IPC::ChannelProxy::MessageFilter implementation: |
173 virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE; | 172 virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE; |
174 virtual void OnChannelError() OVERRIDE; | 173 virtual void OnChannelError() OVERRIDE; |
175 | 174 |
176 private: | 175 private: |
177 GpuChannelHost* parent_; | 176 GpuChannelHost* parent_; |
178 | 177 |
179 typedef base::hash_map<int, GpuListenerInfo> ListenerMap; | 178 typedef base::hash_map<int, GpuListenerInfo> ListenerMap; |
180 ListenerMap listeners_; | 179 ListenerMap listeners_; |
181 }; | 180 }; |
182 | 181 |
183 GpuChannelHostFactory* factory_; | 182 GpuChannelHostFactory* factory_; |
| 183 int gpu_process_id_; |
184 int client_id_; | 184 int client_id_; |
185 int gpu_host_id_; | |
186 | 185 |
187 State state_; | 186 State state_; |
188 | 187 |
189 content::GPUInfo gpu_info_; | 188 content::GPUInfo gpu_info_; |
190 | 189 |
191 scoped_ptr<IPC::SyncChannel> channel_; | 190 scoped_ptr<IPC::SyncChannel> channel_; |
192 scoped_refptr<MessageFilter> channel_filter_; | 191 scoped_refptr<MessageFilter> channel_filter_; |
193 | 192 |
194 // Used to look up a proxy from its routing id. | 193 // Used to look up a proxy from its routing id. |
195 typedef base::hash_map<int, CommandBufferProxyImpl*> ProxyMap; | 194 typedef base::hash_map<int, CommandBufferProxyImpl*> ProxyMap; |
196 ProxyMap proxies_; | 195 ProxyMap proxies_; |
197 | 196 |
198 // A lock to guard against concurrent access to members like the proxies map | 197 // A lock to guard against concurrent access to members like the proxies map |
199 // for calls from contexts that may live on the compositor or main thread. | 198 // for calls from contexts that may live on the compositor or main thread. |
200 mutable base::Lock context_lock_; | 199 mutable base::Lock context_lock_; |
201 | 200 |
202 // A filter for sending messages from thread other than the main thread. | 201 // A filter for sending messages from thread other than the main thread. |
203 scoped_refptr<IPC::SyncMessageFilter> sync_filter_; | 202 scoped_refptr<IPC::SyncMessageFilter> sync_filter_; |
204 | 203 |
205 DISALLOW_COPY_AND_ASSIGN(GpuChannelHost); | 204 DISALLOW_COPY_AND_ASSIGN(GpuChannelHost); |
206 }; | 205 }; |
207 | 206 |
208 #endif // CONTENT_COMMON_GPU_CLIENT_GPU_CHANNEL_HOST_H_ | 207 #endif // CONTENT_COMMON_GPU_CLIENT_GPU_CHANNEL_HOST_H_ |
OLD | NEW |