Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(24)

Side by Side Diff: content/common/gpu/client/gpu_channel_host.h

Issue 19762004: Add multi-process GpuMemoryBuffer framework. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
11 #include "base/atomic_sequence_num.h" 11 #include "base/atomic_sequence_num.h"
12 #include "base/containers/hash_tables.h" 12 #include "base/containers/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/process.h" 16 #include "base/process/process.h"
17 #include "base/synchronization/lock.h" 17 #include "base/synchronization/lock.h"
18 #include "content/common/content_export.h" 18 #include "content/common/content_export.h"
19 #include "content/common/gpu/gpu_process_launch_causes.h" 19 #include "content/common/gpu/gpu_process_launch_causes.h"
20 #include "content/common/message_router.h" 20 #include "content/common/message_router.h"
21 #include "gpu/config/gpu_info.h" 21 #include "gpu/config/gpu_info.h"
22 #include "ipc/ipc_channel_handle.h" 22 #include "ipc/ipc_channel_handle.h"
23 #include "ipc/ipc_channel_proxy.h" 23 #include "ipc/ipc_channel_proxy.h"
24 #include "ipc/ipc_sync_channel.h" 24 #include "ipc/ipc_sync_channel.h"
25 #include "media/video/video_decode_accelerator.h" 25 #include "media/video/video_decode_accelerator.h"
26 #include "media/video/video_encode_accelerator.h" 26 #include "media/video/video_encode_accelerator.h"
27 #include "ui/gfx/gpu_memory_buffer.h"
27 #include "ui/gfx/native_widget_types.h" 28 #include "ui/gfx/native_widget_types.h"
28 #include "ui/gfx/size.h" 29 #include "ui/gfx/size.h"
29 #include "ui/gl/gpu_preference.h" 30 #include "ui/gl/gpu_preference.h"
30 31
31 class GURL; 32 class GURL;
32 class TransportTextureService; 33 class TransportTextureService;
33 struct GPUCreateCommandBufferConfig; 34 struct GPUCreateCommandBufferConfig;
34 35
35 namespace base { 36 namespace base {
36 class MessageLoop; 37 class MessageLoop;
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 virtual base::WaitableEvent* GetShutDownEvent() = 0; 71 virtual base::WaitableEvent* GetShutDownEvent() = 0;
71 virtual scoped_ptr<base::SharedMemory> AllocateSharedMemory(size_t size) = 0; 72 virtual scoped_ptr<base::SharedMemory> AllocateSharedMemory(size_t size) = 0;
72 virtual int32 CreateViewCommandBuffer( 73 virtual int32 CreateViewCommandBuffer(
73 int32 surface_id, const GPUCreateCommandBufferConfig& init_params) = 0; 74 int32 surface_id, const GPUCreateCommandBufferConfig& init_params) = 0;
74 virtual GpuChannelHost* EstablishGpuChannelSync(CauseForGpuLaunch) = 0; 75 virtual GpuChannelHost* EstablishGpuChannelSync(CauseForGpuLaunch) = 0;
75 virtual void CreateImage( 76 virtual void CreateImage(
76 gfx::PluginWindowHandle window, 77 gfx::PluginWindowHandle window,
77 int32 image_id, 78 int32 image_id,
78 const CreateImageCallback& callback) = 0; 79 const CreateImageCallback& callback) = 0;
79 virtual void DeleteImage(int32 image_id, int32 sync_point) = 0; 80 virtual void DeleteImage(int32 image_id, int32 sync_point) = 0;
81 virtual scoped_ptr<gfx::GpuMemoryBuffer> AllocateGpuMemoryBuffer(
82 size_t width,
83 size_t height,
84 unsigned internalformat) = 0;
80 }; 85 };
81 86
82 // Encapsulates an IPC channel between the client and one GPU process. 87 // Encapsulates an IPC channel between the client and one GPU process.
83 // On the GPU process side there's a corresponding GpuChannel. 88 // On the GPU process side there's a corresponding GpuChannel.
84 // Every method can be called on any thread with a message loop, except for the 89 // Every method can be called on any thread with a message loop, except for the
85 // IO thread. 90 // IO thread.
86 class GpuChannelHost : public IPC::Sender, 91 class GpuChannelHost : public IPC::Sender,
87 public base::RefCountedThreadSafe<GpuChannelHost> { 92 public base::RefCountedThreadSafe<GpuChannelHost> {
88 public: 93 public:
89 // Must be called on the main thread (as defined by the factory). 94 // Must be called on the main thread (as defined by the factory).
90 static scoped_refptr<GpuChannelHost> Create( 95 static scoped_refptr<GpuChannelHost> Create(
91 GpuChannelHostFactory* factory, 96 GpuChannelHostFactory* factory,
92 int gpu_host_id, 97 int gpu_host_id,
93 int client_id, 98 int client_id,
94 const gpu::GPUInfo& gpu_info, 99 const gpu::GPUInfo& gpu_info,
95 const IPC::ChannelHandle& channel_handle); 100 const IPC::ChannelHandle& channel_handle);
96 101
102 // Returns true if |handle| is a valid GpuMemoryBuffer handle that
103 // can be shared to the GPU process.
104 static bool IsValidGpuMemoryBuffer(gfx::GpuMemoryBufferHandle handle);
105
97 bool IsLost() const { 106 bool IsLost() const {
98 DCHECK(channel_filter_.get()); 107 DCHECK(channel_filter_.get());
99 return channel_filter_->IsLost(); 108 return channel_filter_->IsLost();
100 } 109 }
101 110
102 // The GPU stats reported by the GPU process. 111 // The GPU stats reported by the GPU process.
103 const gpu::GPUInfo& gpu_info() const { return gpu_info_; } 112 const gpu::GPUInfo& gpu_info() const { return gpu_info_; }
104 113
105 // IPC::Sender implementation: 114 // IPC::Sender implementation:
106 virtual bool Send(IPC::Message* msg) OVERRIDE; 115 virtual bool Send(IPC::Message* msg) OVERRIDE;
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 164
156 // Generates |num| unique mailbox names that can be used with 165 // Generates |num| unique mailbox names that can be used with
157 // GL_texture_mailbox_CHROMIUM. Unlike genMailboxCHROMIUM, this IPC is 166 // GL_texture_mailbox_CHROMIUM. Unlike genMailboxCHROMIUM, this IPC is
158 // handled only on the GPU process' IO thread, and so is not effectively 167 // handled only on the GPU process' IO thread, and so is not effectively
159 // a finish. 168 // a finish.
160 bool GenerateMailboxNames(unsigned num, std::vector<gpu::Mailbox>* names); 169 bool GenerateMailboxNames(unsigned num, std::vector<gpu::Mailbox>* names);
161 170
162 // Reserve one unused transfer buffer ID. 171 // Reserve one unused transfer buffer ID.
163 int32 ReserveTransferBufferId(); 172 int32 ReserveTransferBufferId();
164 173
174 // Returns a GPU memory buffer handle to the buffer that can be sent via
175 // IPC to the GPU process. The caller is responsible for ensuring it is
176 // closed. Returns an invalid handle on failure.
177 gfx::GpuMemoryBufferHandle ShareGpuMemoryBufferToGpuProcess(
178 gfx::GpuMemoryBufferHandle source_handle);
179
180 // Reserve one unused gpu memory buffer ID.
181 int32 ReserveGpuMemoryBufferId();
182
165 private: 183 private:
166 friend class base::RefCountedThreadSafe<GpuChannelHost>; 184 friend class base::RefCountedThreadSafe<GpuChannelHost>;
167 GpuChannelHost(GpuChannelHostFactory* factory, 185 GpuChannelHost(GpuChannelHostFactory* factory,
168 int gpu_host_id, 186 int gpu_host_id,
169 int client_id, 187 int client_id,
170 const gpu::GPUInfo& gpu_info); 188 const gpu::GPUInfo& gpu_info);
171 virtual ~GpuChannelHost(); 189 virtual ~GpuChannelHost();
172 void Connect(const IPC::ChannelHandle& channel_handle); 190 void Connect(const IPC::ChannelHandle& channel_handle);
173 191
174 // A filter used internally to route incoming messages from the IO thread 192 // A filter used internally to route incoming messages from the IO thread
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 // A pool of valid mailbox names. 239 // A pool of valid mailbox names.
222 std::vector<gpu::Mailbox> mailbox_name_pool_; 240 std::vector<gpu::Mailbox> mailbox_name_pool_;
223 241
224 // Number of pending mailbox requested from the GPU process. 242 // Number of pending mailbox requested from the GPU process.
225 size_t requested_mailboxes_; 243 size_t requested_mailboxes_;
226 }; 244 };
227 245
228 // Threading notes: all fields are constant during the lifetime of |this| 246 // Threading notes: all fields are constant during the lifetime of |this|
229 // except: 247 // except:
230 // - |next_transfer_buffer_id_|, atomic type 248 // - |next_transfer_buffer_id_|, atomic type
249 // - |next_gpu_memory_buffer_id_|, atomic type
231 // - |proxies_|, protected by |context_lock_| 250 // - |proxies_|, protected by |context_lock_|
232 GpuChannelHostFactory* const factory_; 251 GpuChannelHostFactory* const factory_;
233 const int client_id_; 252 const int client_id_;
234 const int gpu_host_id_; 253 const int gpu_host_id_;
235 254
236 const gpu::GPUInfo gpu_info_; 255 const gpu::GPUInfo gpu_info_;
237 256
238 scoped_ptr<IPC::SyncChannel> channel_; 257 scoped_ptr<IPC::SyncChannel> channel_;
239 scoped_refptr<MessageFilter> channel_filter_; 258 scoped_refptr<MessageFilter> channel_filter_;
240 259
241 // A filter for sending messages from thread other than the main thread. 260 // A filter for sending messages from thread other than the main thread.
242 scoped_refptr<IPC::SyncMessageFilter> sync_filter_; 261 scoped_refptr<IPC::SyncMessageFilter> sync_filter_;
243 262
244 // Transfer buffer IDs are allocated in sequence. 263 // Transfer buffer IDs are allocated in sequence.
245 base::AtomicSequenceNumber next_transfer_buffer_id_; 264 base::AtomicSequenceNumber next_transfer_buffer_id_;
246 265
266 // Gpu memory buffer IDs are allocated in sequence.
267 base::AtomicSequenceNumber next_gpu_memory_buffer_id_;
268
247 // Protects proxies_. 269 // Protects proxies_.
248 mutable base::Lock context_lock_; 270 mutable base::Lock context_lock_;
249 // Used to look up a proxy from its routing id. 271 // Used to look up a proxy from its routing id.
250 typedef base::hash_map<int, CommandBufferProxyImpl*> ProxyMap; 272 typedef base::hash_map<int, CommandBufferProxyImpl*> ProxyMap;
251 ProxyMap proxies_; 273 ProxyMap proxies_;
252 274
253 DISALLOW_COPY_AND_ASSIGN(GpuChannelHost); 275 DISALLOW_COPY_AND_ASSIGN(GpuChannelHost);
254 }; 276 };
255 277
256 } // namespace content 278 } // namespace content
257 279
258 #endif // CONTENT_COMMON_GPU_CLIENT_GPU_CHANNEL_HOST_H_ 280 #endif // CONTENT_COMMON_GPU_CLIENT_GPU_CHANNEL_HOST_H_
OLDNEW
« no previous file with comments | « content/common/gpu/client/command_buffer_proxy_impl.cc ('k') | content/common/gpu/client/gpu_channel_host.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698