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 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 29 matching lines...) Expand all Loading... |
40 | 40 |
41 namespace IPC { | 41 namespace IPC { |
42 class SyncMessageFilter; | 42 class SyncMessageFilter; |
43 } | 43 } |
44 | 44 |
45 namespace media { | 45 namespace media { |
46 class VideoDecodeAccelerator; | 46 class VideoDecodeAccelerator; |
47 class VideoEncodeAccelerator; | 47 class VideoEncodeAccelerator; |
48 } | 48 } |
49 | 49 |
| 50 namespace cc { |
| 51 class GpuMemoryBufferManager; |
| 52 } |
| 53 |
50 namespace content { | 54 namespace content { |
51 class CommandBufferProxyImpl; | 55 class CommandBufferProxyImpl; |
52 class GpuChannelHost; | 56 class GpuChannelHost; |
53 | 57 |
54 struct GpuListenerInfo { | 58 struct GpuListenerInfo { |
55 GpuListenerInfo(); | 59 GpuListenerInfo(); |
56 ~GpuListenerInfo(); | 60 ~GpuListenerInfo(); |
57 | 61 |
58 base::WeakPtr<IPC::Listener> listener; | 62 base::WeakPtr<IPC::Listener> listener; |
59 scoped_refptr<base::MessageLoopProxy> loop; | 63 scoped_refptr<base::MessageLoopProxy> loop; |
60 }; | 64 }; |
61 | 65 |
62 class CONTENT_EXPORT GpuChannelHostFactory { | 66 class CONTENT_EXPORT GpuChannelHostFactory { |
63 public: | 67 public: |
64 virtual ~GpuChannelHostFactory() {} | 68 virtual ~GpuChannelHostFactory() {} |
65 | 69 |
66 virtual bool IsMainThread() = 0; | 70 virtual bool IsMainThread() = 0; |
67 virtual base::MessageLoop* GetMainLoop() = 0; | 71 virtual base::MessageLoop* GetMainLoop() = 0; |
68 virtual scoped_refptr<base::MessageLoopProxy> GetIOLoopProxy() = 0; | 72 virtual scoped_refptr<base::MessageLoopProxy> GetIOLoopProxy() = 0; |
69 virtual scoped_ptr<base::SharedMemory> AllocateSharedMemory(size_t size) = 0; | 73 virtual scoped_ptr<base::SharedMemory> AllocateSharedMemory(size_t size) = 0; |
70 virtual CreateCommandBufferResult CreateViewCommandBuffer( | 74 virtual CreateCommandBufferResult CreateViewCommandBuffer( |
71 int32 surface_id, | 75 int32 surface_id, |
72 const GPUCreateCommandBufferConfig& init_params, | 76 const GPUCreateCommandBufferConfig& init_params, |
73 int32 route_id) = 0; | 77 int32 route_id) = 0; |
74 virtual scoped_ptr<gfx::GpuMemoryBuffer> AllocateGpuMemoryBuffer( | |
75 size_t width, | |
76 size_t height, | |
77 unsigned internalformat, | |
78 unsigned usage) = 0; | |
79 }; | 78 }; |
80 | 79 |
81 // Encapsulates an IPC channel between the client and one GPU process. | 80 // Encapsulates an IPC channel between the client and one GPU process. |
82 // On the GPU process side there's a corresponding GpuChannel. | 81 // On the GPU process side there's a corresponding GpuChannel. |
83 // Every method can be called on any thread with a message loop, except for the | 82 // Every method can be called on any thread with a message loop, except for the |
84 // IO thread. | 83 // IO thread. |
85 class GpuChannelHost : public IPC::Sender, | 84 class GpuChannelHost : public IPC::Sender, |
86 public base::RefCountedThreadSafe<GpuChannelHost> { | 85 public base::RefCountedThreadSafe<GpuChannelHost> { |
87 public: | 86 public: |
88 // Must be called on the main thread (as defined by the factory). | 87 // Must be called on the main thread (as defined by the factory). |
89 static scoped_refptr<GpuChannelHost> Create( | 88 static scoped_refptr<GpuChannelHost> Create( |
90 GpuChannelHostFactory* factory, | 89 GpuChannelHostFactory* factory, |
91 const gpu::GPUInfo& gpu_info, | 90 const gpu::GPUInfo& gpu_info, |
92 const IPC::ChannelHandle& channel_handle, | 91 const IPC::ChannelHandle& channel_handle, |
93 base::WaitableEvent* shutdown_event); | 92 base::WaitableEvent* shutdown_event, |
94 | 93 cc::GpuMemoryBufferManager* gpu_memory_buffer_manager); |
95 // Returns true if |handle| is a valid GpuMemoryBuffer handle that | |
96 // can be shared to the GPU process. | |
97 static bool IsValidGpuMemoryBuffer(gfx::GpuMemoryBufferHandle handle); | |
98 | 94 |
99 bool IsLost() const { | 95 bool IsLost() const { |
100 DCHECK(channel_filter_.get()); | 96 DCHECK(channel_filter_.get()); |
101 return channel_filter_->IsLost(); | 97 return channel_filter_->IsLost(); |
102 } | 98 } |
103 | 99 |
104 // The GPU stats reported by the GPU process. | 100 // The GPU stats reported by the GPU process. |
105 const gpu::GPUInfo& gpu_info() const { return gpu_info_; } | 101 const gpu::GPUInfo& gpu_info() const { return gpu_info_; } |
106 | 102 |
107 // IPC::Sender implementation: | 103 // IPC::Sender implementation: |
(...skipping 25 matching lines...) Expand all Loading... |
133 | 129 |
134 // Destroy a command buffer created by this channel. | 130 // Destroy a command buffer created by this channel. |
135 void DestroyCommandBuffer(CommandBufferProxyImpl* command_buffer); | 131 void DestroyCommandBuffer(CommandBufferProxyImpl* command_buffer); |
136 | 132 |
137 // Add a route for the current message loop. | 133 // Add a route for the current message loop. |
138 void AddRoute(int route_id, base::WeakPtr<IPC::Listener> listener); | 134 void AddRoute(int route_id, base::WeakPtr<IPC::Listener> listener); |
139 void RemoveRoute(int route_id); | 135 void RemoveRoute(int route_id); |
140 | 136 |
141 GpuChannelHostFactory* factory() const { return factory_; } | 137 GpuChannelHostFactory* factory() const { return factory_; } |
142 | 138 |
| 139 cc::GpuMemoryBufferManager* gpu_memory_buffer_manager() const { |
| 140 return gpu_memory_buffer_manager_; |
| 141 } |
| 142 |
143 // Returns a handle to the shared memory that can be sent via IPC to the | 143 // Returns a handle to the shared memory that can be sent via IPC to the |
144 // GPU process. The caller is responsible for ensuring it is closed. Returns | 144 // GPU process. The caller is responsible for ensuring it is closed. Returns |
145 // an invalid handle on failure. | 145 // an invalid handle on failure. |
146 base::SharedMemoryHandle ShareToGpuProcess( | 146 base::SharedMemoryHandle ShareToGpuProcess( |
147 base::SharedMemoryHandle source_handle); | 147 base::SharedMemoryHandle source_handle); |
148 | 148 |
149 // Reserve one unused transfer buffer ID. | 149 // Reserve one unused transfer buffer ID. |
150 int32 ReserveTransferBufferId(); | 150 int32 ReserveTransferBufferId(); |
151 | 151 |
152 // Returns a GPU memory buffer handle to the buffer that can be sent via | 152 // Returns a GPU memory buffer handle to the buffer that can be sent via |
153 // IPC to the GPU process. The caller is responsible for ensuring it is | 153 // IPC to the GPU process. The caller is responsible for ensuring it is |
154 // closed. Returns an invalid handle on failure. | 154 // closed. Returns an invalid handle on failure. |
155 gfx::GpuMemoryBufferHandle ShareGpuMemoryBufferToGpuProcess( | 155 gfx::GpuMemoryBufferHandle ShareGpuMemoryBufferToGpuProcess( |
156 gfx::GpuMemoryBufferHandle source_handle); | 156 gfx::GpuMemoryBufferHandle source_handle); |
157 | 157 |
158 // Reserve one unused gpu memory buffer ID. | 158 // Reserve one unused image ID. |
159 int32 ReserveGpuMemoryBufferId(); | 159 int32 ReserveImageId(); |
160 | 160 |
161 // Generate a route ID guaranteed to be unique for this channel. | 161 // Generate a route ID guaranteed to be unique for this channel. |
162 int32 GenerateRouteID(); | 162 int32 GenerateRouteID(); |
163 | 163 |
164 private: | 164 private: |
165 friend class base::RefCountedThreadSafe<GpuChannelHost>; | 165 friend class base::RefCountedThreadSafe<GpuChannelHost>; |
166 GpuChannelHost(GpuChannelHostFactory* factory, | 166 GpuChannelHost(GpuChannelHostFactory* factory, |
167 const gpu::GPUInfo& gpu_info); | 167 const gpu::GPUInfo& gpu_info, |
| 168 cc::GpuMemoryBufferManager* gpu_memory_buffer_manager); |
168 virtual ~GpuChannelHost(); | 169 virtual ~GpuChannelHost(); |
169 void Connect(const IPC::ChannelHandle& channel_handle, | 170 void Connect(const IPC::ChannelHandle& channel_handle, |
170 base::WaitableEvent* shutdown_event); | 171 base::WaitableEvent* shutdown_event); |
171 | 172 |
172 // A filter used internally to route incoming messages from the IO thread | 173 // A filter used internally to route incoming messages from the IO thread |
173 // to the correct message loop. It also maintains some shared state between | 174 // to the correct message loop. It also maintains some shared state between |
174 // all the contexts. | 175 // all the contexts. |
175 class MessageFilter : public IPC::MessageFilter { | 176 class MessageFilter : public IPC::MessageFilter { |
176 public: | 177 public: |
177 MessageFilter(); | 178 MessageFilter(); |
(...skipping 26 matching lines...) Expand all Loading... |
204 // Protects all fields below this one. | 205 // Protects all fields below this one. |
205 mutable base::Lock lock_; | 206 mutable base::Lock lock_; |
206 | 207 |
207 // Whether the channel has been lost. | 208 // Whether the channel has been lost. |
208 bool lost_; | 209 bool lost_; |
209 }; | 210 }; |
210 | 211 |
211 // Threading notes: all fields are constant during the lifetime of |this| | 212 // Threading notes: all fields are constant during the lifetime of |this| |
212 // except: | 213 // except: |
213 // - |next_transfer_buffer_id_|, atomic type | 214 // - |next_transfer_buffer_id_|, atomic type |
214 // - |next_gpu_memory_buffer_id_|, atomic type | 215 // - |next_image_id_|, atomic type |
215 // - |next_route_id_|, atomic type | 216 // - |next_route_id_|, atomic type |
216 // - |proxies_|, protected by |context_lock_| | 217 // - |proxies_|, protected by |context_lock_| |
217 GpuChannelHostFactory* const factory_; | 218 GpuChannelHostFactory* const factory_; |
218 | 219 |
219 const gpu::GPUInfo gpu_info_; | 220 const gpu::GPUInfo gpu_info_; |
220 | 221 |
221 scoped_ptr<IPC::SyncChannel> channel_; | 222 scoped_ptr<IPC::SyncChannel> channel_; |
222 scoped_refptr<MessageFilter> channel_filter_; | 223 scoped_refptr<MessageFilter> channel_filter_; |
223 | 224 |
| 225 cc::GpuMemoryBufferManager* gpu_memory_buffer_manager_; |
| 226 |
224 // A filter for sending messages from thread other than the main thread. | 227 // A filter for sending messages from thread other than the main thread. |
225 scoped_refptr<IPC::SyncMessageFilter> sync_filter_; | 228 scoped_refptr<IPC::SyncMessageFilter> sync_filter_; |
226 | 229 |
227 // Transfer buffer IDs are allocated in sequence. | 230 // Transfer buffer IDs are allocated in sequence. |
228 base::AtomicSequenceNumber next_transfer_buffer_id_; | 231 base::AtomicSequenceNumber next_transfer_buffer_id_; |
229 | 232 |
230 // Gpu memory buffer IDs are allocated in sequence. | 233 // Image IDs are allocated in sequence. |
231 base::AtomicSequenceNumber next_gpu_memory_buffer_id_; | 234 base::AtomicSequenceNumber next_image_id_; |
232 | 235 |
233 // Route IDs are allocated in sequence. | 236 // Route IDs are allocated in sequence. |
234 base::AtomicSequenceNumber next_route_id_; | 237 base::AtomicSequenceNumber next_route_id_; |
235 | 238 |
236 // Protects proxies_. | 239 // Protects proxies_. |
237 mutable base::Lock context_lock_; | 240 mutable base::Lock context_lock_; |
238 // Used to look up a proxy from its routing id. | 241 // Used to look up a proxy from its routing id. |
239 typedef base::hash_map<int, CommandBufferProxyImpl*> ProxyMap; | 242 typedef base::hash_map<int, CommandBufferProxyImpl*> ProxyMap; |
240 ProxyMap proxies_; | 243 ProxyMap proxies_; |
241 | 244 |
242 DISALLOW_COPY_AND_ASSIGN(GpuChannelHost); | 245 DISALLOW_COPY_AND_ASSIGN(GpuChannelHost); |
243 }; | 246 }; |
244 | 247 |
245 } // namespace content | 248 } // namespace content |
246 | 249 |
247 #endif // CONTENT_COMMON_GPU_CLIENT_GPU_CHANNEL_HOST_H_ | 250 #endif // CONTENT_COMMON_GPU_CLIENT_GPU_CHANNEL_HOST_H_ |
OLD | NEW |