OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 GPU_COMMAND_BUFFER_SERVICE_IN_PROCESS_COMMAND_BUFFER_H_ | 5 #ifndef GPU_COMMAND_BUFFER_SERVICE_IN_PROCESS_COMMAND_BUFFER_H_ |
6 #define GPU_COMMAND_BUFFER_SERVICE_IN_PROCESS_COMMAND_BUFFER_H_ | 6 #define GPU_COMMAND_BUFFER_SERVICE_IN_PROCESS_COMMAND_BUFFER_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/callback.h" | 11 #include "base/callback.h" |
12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
13 #include "base/memory/linked_ptr.h" | 13 #include "base/containers/scoped_ptr_hash_map.h" |
14 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
15 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
16 #include "base/memory/weak_ptr.h" | 16 #include "base/memory/weak_ptr.h" |
17 #include "base/synchronization/lock.h" | 17 #include "base/synchronization/lock.h" |
18 #include "base/synchronization/waitable_event.h" | 18 #include "base/synchronization/waitable_event.h" |
19 #include "gpu/command_buffer/client/gpu_control.h" | 19 #include "gpu/command_buffer/client/gpu_control.h" |
20 #include "gpu/command_buffer/common/command_buffer.h" | 20 #include "gpu/command_buffer/common/command_buffer.h" |
21 #include "gpu/gpu_export.h" | 21 #include "gpu/gpu_export.h" |
22 #include "ui/gfx/gpu_memory_buffer.h" | 22 #include "ui/gfx/gpu_memory_buffer.h" |
23 #include "ui/gfx/native_widget_types.h" | 23 #include "ui/gfx/native_widget_types.h" |
(...skipping 21 matching lines...) Expand all Loading... |
45 #endif | 45 #endif |
46 | 46 |
47 namespace gpu { | 47 namespace gpu { |
48 | 48 |
49 namespace gles2 { | 49 namespace gles2 { |
50 class GLES2Decoder; | 50 class GLES2Decoder; |
51 class ShaderTranslatorCache; | 51 class ShaderTranslatorCache; |
52 } | 52 } |
53 | 53 |
54 class CommandBufferServiceBase; | 54 class CommandBufferServiceBase; |
55 class GpuControlService; | |
56 class GpuMemoryBufferFactory; | |
57 class GpuScheduler; | 55 class GpuScheduler; |
58 class TransferBufferManagerInterface; | 56 class TransferBufferManagerInterface; |
59 | 57 |
| 58 // TODO(reveman): Remove this interface when InProcessCommandBuffer doesn't need |
| 59 // a custom factory interface and android_webview implementation of GPU memory |
| 60 // buffers can use the same mechanism for buffer allocation as what's used for |
| 61 // out of process GPU service. |
| 62 class GPU_EXPORT InProcessGpuMemoryBufferFactory { |
| 63 public: |
| 64 virtual scoped_ptr<gfx::GpuMemoryBuffer> AllocateGpuMemoryBuffer( |
| 65 size_t width, |
| 66 size_t height, |
| 67 unsigned internalformat, |
| 68 unsigned usage) = 0; |
| 69 virtual scoped_refptr<gfx::GLImage> CreateImageForGpuMemoryBuffer( |
| 70 const gfx::GpuMemoryBufferHandle& handle, |
| 71 const gfx::Size& size, |
| 72 unsigned internalformat) = 0; |
| 73 |
| 74 protected: |
| 75 virtual ~InProcessGpuMemoryBufferFactory() {} |
| 76 }; |
| 77 |
60 // This class provides a thread-safe interface to the global GPU service (for | 78 // This class provides a thread-safe interface to the global GPU service (for |
61 // example GPU thread) when being run in single process mode. | 79 // example GPU thread) when being run in single process mode. |
62 // However, the behavior for accessing one context (i.e. one instance of this | 80 // However, the behavior for accessing one context (i.e. one instance of this |
63 // class) from different client threads is undefined. | 81 // class) from different client threads is undefined. |
64 class GPU_EXPORT InProcessCommandBuffer : public CommandBuffer, | 82 class GPU_EXPORT InProcessCommandBuffer : public CommandBuffer, |
65 public GpuControl { | 83 public GpuControl { |
66 public: | 84 public: |
67 class Service; | 85 class Service; |
68 explicit InProcessCommandBuffer(const scoped_refptr<Service>& service); | 86 explicit InProcessCommandBuffer(const scoped_refptr<Service>& service); |
69 virtual ~InProcessCommandBuffer(); | 87 virtual ~InProcessCommandBuffer(); |
70 | 88 |
71 static void SetGpuMemoryBufferFactory(GpuMemoryBufferFactory* factory); | 89 static void SetGpuMemoryBufferFactory( |
| 90 InProcessGpuMemoryBufferFactory* factory); |
72 | 91 |
73 // If |surface| is not NULL, use it directly; in this case, the command | 92 // If |surface| is not NULL, use it directly; in this case, the command |
74 // buffer gpu thread must be the same as the client thread. Otherwise create | 93 // buffer gpu thread must be the same as the client thread. Otherwise create |
75 // a new GLSurface. | 94 // a new GLSurface. |
76 bool Initialize(scoped_refptr<gfx::GLSurface> surface, | 95 bool Initialize(scoped_refptr<gfx::GLSurface> surface, |
77 bool is_offscreen, | 96 bool is_offscreen, |
78 gfx::AcceleratedWidget window, | 97 gfx::AcceleratedWidget window, |
79 const gfx::Size& size, | 98 const gfx::Size& size, |
80 const std::vector<int32>& attribs, | 99 const std::vector<int32>& attribs, |
81 gfx::GpuPreference gpu_preference, | 100 gfx::GpuPreference gpu_preference, |
(...skipping 20 matching lines...) Expand all Loading... |
102 size_t height, | 121 size_t height, |
103 unsigned internalformat, | 122 unsigned internalformat, |
104 unsigned usage, | 123 unsigned usage, |
105 int32* id) OVERRIDE; | 124 int32* id) OVERRIDE; |
106 virtual void DestroyGpuMemoryBuffer(int32 id) OVERRIDE; | 125 virtual void DestroyGpuMemoryBuffer(int32 id) OVERRIDE; |
107 virtual uint32 InsertSyncPoint() OVERRIDE; | 126 virtual uint32 InsertSyncPoint() OVERRIDE; |
108 virtual uint32 InsertFutureSyncPoint() OVERRIDE; | 127 virtual uint32 InsertFutureSyncPoint() OVERRIDE; |
109 virtual void RetireSyncPoint(uint32 sync_point) OVERRIDE; | 128 virtual void RetireSyncPoint(uint32 sync_point) OVERRIDE; |
110 virtual void SignalSyncPoint(uint32 sync_point, | 129 virtual void SignalSyncPoint(uint32 sync_point, |
111 const base::Closure& callback) OVERRIDE; | 130 const base::Closure& callback) OVERRIDE; |
112 virtual void SignalQuery(uint32 query, | 131 virtual void SignalQuery(uint32 query_id, |
113 const base::Closure& callback) OVERRIDE; | 132 const base::Closure& callback) OVERRIDE; |
114 virtual void SetSurfaceVisible(bool visible) OVERRIDE; | 133 virtual void SetSurfaceVisible(bool visible) OVERRIDE; |
115 virtual void Echo(const base::Closure& callback) OVERRIDE; | 134 virtual void Echo(const base::Closure& callback) OVERRIDE; |
116 virtual uint32 CreateStreamTexture(uint32 texture_id) OVERRIDE; | 135 virtual uint32 CreateStreamTexture(uint32 texture_id) OVERRIDE; |
117 | 136 |
118 // The serializer interface to the GPU service (i.e. thread). | 137 // The serializer interface to the GPU service (i.e. thread). |
119 class Service { | 138 class Service { |
120 public: | 139 public: |
121 Service(); | 140 Service(); |
122 virtual ~Service(); | 141 virtual ~Service(); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 void FlushOnGpuThread(int32 put_offset); | 191 void FlushOnGpuThread(int32 put_offset); |
173 uint32 CreateStreamTextureOnGpuThread(uint32 client_texture_id); | 192 uint32 CreateStreamTextureOnGpuThread(uint32 client_texture_id); |
174 bool MakeCurrent(); | 193 bool MakeCurrent(); |
175 base::Closure WrapCallback(const base::Closure& callback); | 194 base::Closure WrapCallback(const base::Closure& callback); |
176 State GetStateFast(); | 195 State GetStateFast(); |
177 void QueueTask(const base::Closure& task) { service_->ScheduleTask(task); } | 196 void QueueTask(const base::Closure& task) { service_->ScheduleTask(task); } |
178 void CheckSequencedThread(); | 197 void CheckSequencedThread(); |
179 void RetireSyncPointOnGpuThread(uint32 sync_point); | 198 void RetireSyncPointOnGpuThread(uint32 sync_point); |
180 void SignalSyncPointOnGpuThread(uint32 sync_point, | 199 void SignalSyncPointOnGpuThread(uint32 sync_point, |
181 const base::Closure& callback); | 200 const base::Closure& callback); |
182 void DestroyTransferBufferOnGputhread(int32 id); | 201 void SignalQueryOnGpuThread(unsigned query_id, const base::Closure& callback); |
| 202 void DestroyTransferBufferOnGpuThread(int32 id); |
| 203 void RegisterGpuMemoryBufferOnGpuThread( |
| 204 int32 id, |
| 205 const gfx::GpuMemoryBufferHandle& handle, |
| 206 size_t width, |
| 207 size_t height, |
| 208 unsigned internalformat); |
| 209 void UnregisterGpuMemoryBufferOnGpuThread(int32 id); |
183 | 210 |
184 // Callbacks: | 211 // Callbacks: |
185 void OnContextLost(); | 212 void OnContextLost(); |
186 void OnResizeView(gfx::Size size, float scale_factor); | 213 void OnResizeView(gfx::Size size, float scale_factor); |
187 bool GetBufferChanged(int32 transfer_buffer_id); | 214 bool GetBufferChanged(int32 transfer_buffer_id); |
188 void PumpCommands(); | 215 void PumpCommands(); |
189 void ScheduleMoreIdleWork(); | 216 void ScheduleMoreIdleWork(); |
190 | 217 |
191 static scoped_refptr<Service> GetDefaultService(); | 218 static scoped_refptr<Service> GetDefaultService(); |
192 | 219 |
193 // Members accessed on the gpu thread (possibly with the exception of | 220 // Members accessed on the gpu thread (possibly with the exception of |
194 // creation): | 221 // creation): |
195 bool context_lost_; | 222 bool context_lost_; |
196 scoped_ptr<TransferBufferManagerInterface> transfer_buffer_manager_; | 223 scoped_ptr<TransferBufferManagerInterface> transfer_buffer_manager_; |
197 scoped_ptr<GpuScheduler> gpu_scheduler_; | 224 scoped_ptr<GpuScheduler> gpu_scheduler_; |
198 scoped_ptr<gles2::GLES2Decoder> decoder_; | 225 scoped_ptr<gles2::GLES2Decoder> decoder_; |
199 scoped_refptr<gfx::GLContext> context_; | 226 scoped_refptr<gfx::GLContext> context_; |
200 scoped_refptr<gfx::GLSurface> surface_; | 227 scoped_refptr<gfx::GLSurface> surface_; |
201 base::Closure context_lost_callback_; | 228 base::Closure context_lost_callback_; |
202 | 229 |
203 // Members accessed on the client thread: | 230 // Members accessed on the client thread: |
204 State last_state_; | 231 State last_state_; |
205 int32 last_put_offset_; | 232 int32 last_put_offset_; |
206 gpu::Capabilities capabilities_; | 233 gpu::Capabilities capabilities_; |
207 typedef std::map<int32, linked_ptr<gfx::GpuMemoryBuffer> > GpuMemoryBufferMap; | 234 typedef base::ScopedPtrHashMap<int32, gfx::GpuMemoryBuffer> |
| 235 GpuMemoryBufferMap; |
208 GpuMemoryBufferMap gpu_memory_buffers_; | 236 GpuMemoryBufferMap gpu_memory_buffers_; |
209 | 237 |
210 // Accessed on both threads: | 238 // Accessed on both threads: |
211 scoped_ptr<CommandBufferServiceBase> command_buffer_; | 239 scoped_ptr<CommandBufferServiceBase> command_buffer_; |
212 base::Lock command_buffer_lock_; | 240 base::Lock command_buffer_lock_; |
213 base::WaitableEvent flush_event_; | 241 base::WaitableEvent flush_event_; |
214 scoped_refptr<Service> service_; | 242 scoped_refptr<Service> service_; |
215 State state_after_last_flush_; | 243 State state_after_last_flush_; |
216 base::Lock state_after_last_flush_lock_; | 244 base::Lock state_after_last_flush_lock_; |
217 scoped_ptr<GpuControlService> gpu_control_; | |
218 scoped_refptr<gfx::GLShareGroup> gl_share_group_; | 245 scoped_refptr<gfx::GLShareGroup> gl_share_group_; |
219 | 246 |
220 #if defined(OS_ANDROID) | 247 #if defined(OS_ANDROID) |
221 scoped_ptr<StreamTextureManagerInProcess> stream_texture_manager_; | 248 scoped_ptr<StreamTextureManagerInProcess> stream_texture_manager_; |
222 #endif | 249 #endif |
223 | 250 |
224 // Only used with explicit scheduling and the gpu thread is the same as | 251 // Only used with explicit scheduling and the gpu thread is the same as |
225 // the client thread. | 252 // the client thread. |
226 scoped_ptr<base::SequenceChecker> sequence_checker_; | 253 scoped_ptr<base::SequenceChecker> sequence_checker_; |
227 | 254 |
228 base::WeakPtr<InProcessCommandBuffer> gpu_thread_weak_ptr_; | 255 base::WeakPtr<InProcessCommandBuffer> gpu_thread_weak_ptr_; |
229 base::WeakPtrFactory<InProcessCommandBuffer> gpu_thread_weak_ptr_factory_; | 256 base::WeakPtrFactory<InProcessCommandBuffer> gpu_thread_weak_ptr_factory_; |
230 | 257 |
231 DISALLOW_COPY_AND_ASSIGN(InProcessCommandBuffer); | 258 DISALLOW_COPY_AND_ASSIGN(InProcessCommandBuffer); |
232 }; | 259 }; |
233 | 260 |
234 } // namespace gpu | 261 } // namespace gpu |
235 | 262 |
236 #endif // GPU_COMMAND_BUFFER_SERVICE_IN_PROCESS_COMMAND_BUFFER_H_ | 263 #endif // GPU_COMMAND_BUFFER_SERVICE_IN_PROCESS_COMMAND_BUFFER_H_ |
OLD | NEW |