| 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 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 // Encapsulates an IPC channel between the client and one GPU process. | 86 // Encapsulates an IPC channel between the client and one GPU process. |
| 87 // On the GPU process side there's a corresponding GpuChannel. | 87 // On the GPU process side there's a corresponding GpuChannel. |
| 88 // Every method can be called on any thread with a message loop, except for the | 88 // Every method can be called on any thread with a message loop, except for the |
| 89 // IO thread. | 89 // IO thread. |
| 90 class GpuChannelHost : public IPC::Sender, | 90 class GpuChannelHost : public IPC::Sender, |
| 91 public base::RefCountedThreadSafe<GpuChannelHost> { | 91 public base::RefCountedThreadSafe<GpuChannelHost> { |
| 92 public: | 92 public: |
| 93 // Must be called on the main thread (as defined by the factory). | 93 // Must be called on the main thread (as defined by the factory). |
| 94 static scoped_refptr<GpuChannelHost> Create( | 94 static scoped_refptr<GpuChannelHost> Create( |
| 95 GpuChannelHostFactory* factory, | 95 GpuChannelHostFactory* factory, |
| 96 int gpu_host_id, | |
| 97 const gpu::GPUInfo& gpu_info, | 96 const gpu::GPUInfo& gpu_info, |
| 98 const IPC::ChannelHandle& channel_handle); | 97 const IPC::ChannelHandle& channel_handle); |
| 99 | 98 |
| 100 // Returns true if |handle| is a valid GpuMemoryBuffer handle that | 99 // Returns true if |handle| is a valid GpuMemoryBuffer handle that |
| 101 // can be shared to the GPU process. | 100 // can be shared to the GPU process. |
| 102 static bool IsValidGpuMemoryBuffer(gfx::GpuMemoryBufferHandle handle); | 101 static bool IsValidGpuMemoryBuffer(gfx::GpuMemoryBufferHandle handle); |
| 103 | 102 |
| 104 bool IsLost() const { | 103 bool IsLost() const { |
| 105 DCHECK(channel_filter_.get()); | 104 DCHECK(channel_filter_.get()); |
| 106 return channel_filter_->IsLost(); | 105 return channel_filter_->IsLost(); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 | 142 |
| 144 // Collect rendering stats from GPU process. | 143 // Collect rendering stats from GPU process. |
| 145 bool CollectRenderingStatsForSurface( | 144 bool CollectRenderingStatsForSurface( |
| 146 int surface_id, GpuRenderingStats* stats); | 145 int surface_id, GpuRenderingStats* stats); |
| 147 | 146 |
| 148 // Add a route for the current message loop. | 147 // Add a route for the current message loop. |
| 149 void AddRoute(int route_id, base::WeakPtr<IPC::Listener> listener); | 148 void AddRoute(int route_id, base::WeakPtr<IPC::Listener> listener); |
| 150 void RemoveRoute(int route_id); | 149 void RemoveRoute(int route_id); |
| 151 | 150 |
| 152 GpuChannelHostFactory* factory() const { return factory_; } | 151 GpuChannelHostFactory* factory() const { return factory_; } |
| 153 int gpu_host_id() const { return gpu_host_id_; } | |
| 154 | 152 |
| 155 // Returns a handle to the shared memory that can be sent via IPC to the | 153 // Returns a handle to the shared memory that can be sent via IPC to the |
| 156 // GPU process. The caller is responsible for ensuring it is closed. Returns | 154 // GPU process. The caller is responsible for ensuring it is closed. Returns |
| 157 // an invalid handle on failure. | 155 // an invalid handle on failure. |
| 158 base::SharedMemoryHandle ShareToGpuProcess( | 156 base::SharedMemoryHandle ShareToGpuProcess( |
| 159 base::SharedMemoryHandle source_handle); | 157 base::SharedMemoryHandle source_handle); |
| 160 | 158 |
| 161 // Generates |num| unique mailbox names that can be used with | 159 // Generates |num| unique mailbox names that can be used with |
| 162 // GL_texture_mailbox_CHROMIUM. Unlike genMailboxCHROMIUM, this IPC is | 160 // GL_texture_mailbox_CHROMIUM. Unlike genMailboxCHROMIUM, this IPC is |
| 163 // handled only on the GPU process' IO thread, and so is not effectively | 161 // handled only on the GPU process' IO thread, and so is not effectively |
| 164 // a finish. | 162 // a finish. |
| 165 bool GenerateMailboxNames(unsigned num, std::vector<gpu::Mailbox>* names); | 163 bool GenerateMailboxNames(unsigned num, std::vector<gpu::Mailbox>* names); |
| 166 | 164 |
| 167 // Reserve one unused transfer buffer ID. | 165 // Reserve one unused transfer buffer ID. |
| 168 int32 ReserveTransferBufferId(); | 166 int32 ReserveTransferBufferId(); |
| 169 | 167 |
| 170 // Returns a GPU memory buffer handle to the buffer that can be sent via | 168 // Returns a GPU memory buffer handle to the buffer that can be sent via |
| 171 // IPC to the GPU process. The caller is responsible for ensuring it is | 169 // IPC to the GPU process. The caller is responsible for ensuring it is |
| 172 // closed. Returns an invalid handle on failure. | 170 // closed. Returns an invalid handle on failure. |
| 173 gfx::GpuMemoryBufferHandle ShareGpuMemoryBufferToGpuProcess( | 171 gfx::GpuMemoryBufferHandle ShareGpuMemoryBufferToGpuProcess( |
| 174 gfx::GpuMemoryBufferHandle source_handle); | 172 gfx::GpuMemoryBufferHandle source_handle); |
| 175 | 173 |
| 176 // Reserve one unused gpu memory buffer ID. | 174 // Reserve one unused gpu memory buffer ID. |
| 177 int32 ReserveGpuMemoryBufferId(); | 175 int32 ReserveGpuMemoryBufferId(); |
| 178 | 176 |
| 179 private: | 177 private: |
| 180 friend class base::RefCountedThreadSafe<GpuChannelHost>; | 178 friend class base::RefCountedThreadSafe<GpuChannelHost>; |
| 181 GpuChannelHost(GpuChannelHostFactory* factory, | 179 GpuChannelHost(GpuChannelHostFactory* factory, |
| 182 int gpu_host_id, | |
| 183 const gpu::GPUInfo& gpu_info); | 180 const gpu::GPUInfo& gpu_info); |
| 184 virtual ~GpuChannelHost(); | 181 virtual ~GpuChannelHost(); |
| 185 void Connect(const IPC::ChannelHandle& channel_handle); | 182 void Connect(const IPC::ChannelHandle& channel_handle); |
| 186 | 183 |
| 187 // A filter used internally to route incoming messages from the IO thread | 184 // A filter used internally to route incoming messages from the IO thread |
| 188 // to the correct message loop. It also maintains some shared state between | 185 // to the correct message loop. It also maintains some shared state between |
| 189 // all the contexts. | 186 // all the contexts. |
| 190 class MessageFilter : public IPC::ChannelProxy::MessageFilter { | 187 class MessageFilter : public IPC::ChannelProxy::MessageFilter { |
| 191 public: | 188 public: |
| 192 MessageFilter(); | 189 MessageFilter(); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 237 // Number of pending mailbox requested from the GPU process. | 234 // Number of pending mailbox requested from the GPU process. |
| 238 size_t requested_mailboxes_; | 235 size_t requested_mailboxes_; |
| 239 }; | 236 }; |
| 240 | 237 |
| 241 // Threading notes: all fields are constant during the lifetime of |this| | 238 // Threading notes: all fields are constant during the lifetime of |this| |
| 242 // except: | 239 // except: |
| 243 // - |next_transfer_buffer_id_|, atomic type | 240 // - |next_transfer_buffer_id_|, atomic type |
| 244 // - |next_gpu_memory_buffer_id_|, atomic type | 241 // - |next_gpu_memory_buffer_id_|, atomic type |
| 245 // - |proxies_|, protected by |context_lock_| | 242 // - |proxies_|, protected by |context_lock_| |
| 246 GpuChannelHostFactory* const factory_; | 243 GpuChannelHostFactory* const factory_; |
| 247 const int gpu_host_id_; | |
| 248 | 244 |
| 249 const gpu::GPUInfo gpu_info_; | 245 const gpu::GPUInfo gpu_info_; |
| 250 | 246 |
| 251 scoped_ptr<IPC::SyncChannel> channel_; | 247 scoped_ptr<IPC::SyncChannel> channel_; |
| 252 scoped_refptr<MessageFilter> channel_filter_; | 248 scoped_refptr<MessageFilter> channel_filter_; |
| 253 | 249 |
| 254 // A filter for sending messages from thread other than the main thread. | 250 // A filter for sending messages from thread other than the main thread. |
| 255 scoped_refptr<IPC::SyncMessageFilter> sync_filter_; | 251 scoped_refptr<IPC::SyncMessageFilter> sync_filter_; |
| 256 | 252 |
| 257 // Transfer buffer IDs are allocated in sequence. | 253 // Transfer buffer IDs are allocated in sequence. |
| 258 base::AtomicSequenceNumber next_transfer_buffer_id_; | 254 base::AtomicSequenceNumber next_transfer_buffer_id_; |
| 259 | 255 |
| 260 // Gpu memory buffer IDs are allocated in sequence. | 256 // Gpu memory buffer IDs are allocated in sequence. |
| 261 base::AtomicSequenceNumber next_gpu_memory_buffer_id_; | 257 base::AtomicSequenceNumber next_gpu_memory_buffer_id_; |
| 262 | 258 |
| 263 // Protects proxies_. | 259 // Protects proxies_. |
| 264 mutable base::Lock context_lock_; | 260 mutable base::Lock context_lock_; |
| 265 // Used to look up a proxy from its routing id. | 261 // Used to look up a proxy from its routing id. |
| 266 typedef base::hash_map<int, CommandBufferProxyImpl*> ProxyMap; | 262 typedef base::hash_map<int, CommandBufferProxyImpl*> ProxyMap; |
| 267 ProxyMap proxies_; | 263 ProxyMap proxies_; |
| 268 | 264 |
| 269 DISALLOW_COPY_AND_ASSIGN(GpuChannelHost); | 265 DISALLOW_COPY_AND_ASSIGN(GpuChannelHost); |
| 270 }; | 266 }; |
| 271 | 267 |
| 272 } // namespace content | 268 } // namespace content |
| 273 | 269 |
| 274 #endif // CONTENT_COMMON_GPU_CLIENT_GPU_CHANNEL_HOST_H_ | 270 #endif // CONTENT_COMMON_GPU_CLIENT_GPU_CHANNEL_HOST_H_ |
| OLD | NEW |