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 <stddef.h> | 8 #include <stddef.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 | 10 |
11 #include <map> | 11 #include <map> |
12 #include <vector> | 12 #include <vector> |
13 | 13 |
14 #include "base/atomic_sequence_num.h" | 14 #include "base/atomic_sequence_num.h" |
15 #include "base/callback.h" | 15 #include "base/callback.h" |
16 #include "base/compiler_specific.h" | 16 #include "base/compiler_specific.h" |
17 #include "base/containers/scoped_ptr_hash_map.h" | 17 #include "base/containers/scoped_ptr_hash_map.h" |
18 #include "base/macros.h" | 18 #include "base/macros.h" |
19 #include "base/memory/ref_counted.h" | 19 #include "base/memory/ref_counted.h" |
20 #include "base/memory/scoped_ptr.h" | 20 #include "base/memory/scoped_ptr.h" |
21 #include "base/memory/weak_ptr.h" | 21 #include "base/memory/weak_ptr.h" |
| 22 #include "base/single_thread_task_runner.h" |
22 #include "base/synchronization/lock.h" | 23 #include "base/synchronization/lock.h" |
23 #include "base/synchronization/waitable_event.h" | 24 #include "base/synchronization/waitable_event.h" |
24 #include "base/threading/thread.h" | 25 #include "base/threading/thread.h" |
25 #include "gpu/command_buffer/client/gpu_control.h" | 26 #include "gpu/command_buffer/client/gpu_control.h" |
26 #include "gpu/command_buffer/common/command_buffer.h" | 27 #include "gpu/command_buffer/common/command_buffer.h" |
27 #include "gpu/command_buffer/service/gpu_preferences.h" | 28 #include "gpu/command_buffer/service/gpu_preferences.h" |
28 #include "gpu/gpu_export.h" | 29 #include "gpu/gpu_export.h" |
29 #include "ui/gfx/gpu_memory_buffer.h" | 30 #include "ui/gfx/gpu_memory_buffer.h" |
30 #include "ui/gfx/native_widget_types.h" | 31 #include "ui/gfx/native_widget_types.h" |
31 #include "ui/gl/gl_surface.h" | 32 #include "ui/gl/gl_surface.h" |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 | 86 |
86 // If |surface| is not null, use it directly; in this case, the command | 87 // If |surface| is not null, use it directly; in this case, the command |
87 // buffer gpu thread must be the same as the client thread. Otherwise create | 88 // buffer gpu thread must be the same as the client thread. Otherwise create |
88 // a new GLSurface. | 89 // a new GLSurface. |
89 bool Initialize(scoped_refptr<gfx::GLSurface> surface, | 90 bool Initialize(scoped_refptr<gfx::GLSurface> surface, |
90 bool is_offscreen, | 91 bool is_offscreen, |
91 gfx::AcceleratedWidget window, | 92 gfx::AcceleratedWidget window, |
92 const gfx::Size& size, | 93 const gfx::Size& size, |
93 const std::vector<int32_t>& attribs, | 94 const std::vector<int32_t>& attribs, |
94 gfx::GpuPreference gpu_preference, | 95 gfx::GpuPreference gpu_preference, |
95 const base::Closure& context_lost_callback, | |
96 InProcessCommandBuffer* share_group, | 96 InProcessCommandBuffer* share_group, |
97 GpuMemoryBufferManager* gpu_memory_buffer_manager, | 97 GpuMemoryBufferManager* gpu_memory_buffer_manager, |
98 ImageFactory* image_factory); | 98 ImageFactory* image_factory); |
99 void Destroy(); | 99 void Destroy(); |
100 | 100 |
101 // CommandBuffer implementation: | 101 // CommandBuffer implementation: |
102 bool Initialize() override; | 102 bool Initialize() override; |
103 State GetLastState() override; | 103 State GetLastState() override; |
104 int32_t GetLastToken() override; | 104 int32_t GetLastToken() override; |
105 void Flush(int32_t put_offset) override; | 105 void Flush(int32_t put_offset) override; |
106 void OrderingBarrier(int32_t put_offset) override; | 106 void OrderingBarrier(int32_t put_offset) override; |
107 void WaitForTokenInRange(int32_t start, int32_t end) override; | 107 void WaitForTokenInRange(int32_t start, int32_t end) override; |
108 void WaitForGetOffsetInRange(int32_t start, int32_t end) override; | 108 void WaitForGetOffsetInRange(int32_t start, int32_t end) override; |
109 void SetGetBuffer(int32_t shm_id) override; | 109 void SetGetBuffer(int32_t shm_id) override; |
110 scoped_refptr<gpu::Buffer> CreateTransferBuffer(size_t size, | 110 scoped_refptr<gpu::Buffer> CreateTransferBuffer(size_t size, |
111 int32_t* id) override; | 111 int32_t* id) override; |
112 void DestroyTransferBuffer(int32_t id) override; | 112 void DestroyTransferBuffer(int32_t id) override; |
113 gpu::error::Error GetLastError() override; | 113 gpu::error::Error GetLastError() override; |
114 | 114 |
115 // GpuControl implementation: | 115 // GpuControl implementation: |
| 116 // NOTE: The GpuControlClient will be called on the GPU thread. |
| 117 void SetGpuControlClient(GpuControlClient*) override; |
116 gpu::Capabilities GetCapabilities() override; | 118 gpu::Capabilities GetCapabilities() override; |
117 int32_t CreateImage(ClientBuffer buffer, | 119 int32_t CreateImage(ClientBuffer buffer, |
118 size_t width, | 120 size_t width, |
119 size_t height, | 121 size_t height, |
120 unsigned internalformat) override; | 122 unsigned internalformat) override; |
121 void DestroyImage(int32_t id) override; | 123 void DestroyImage(int32_t id) override; |
122 int32_t CreateGpuMemoryBufferImage(size_t width, | 124 int32_t CreateGpuMemoryBufferImage(size_t width, |
123 size_t height, | 125 size_t height, |
124 unsigned internalformat, | 126 unsigned internalformat, |
125 unsigned usage) override; | 127 unsigned usage) override; |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
232 void CreateImageOnGpuThread(int32_t id, | 234 void CreateImageOnGpuThread(int32_t id, |
233 const gfx::GpuMemoryBufferHandle& handle, | 235 const gfx::GpuMemoryBufferHandle& handle, |
234 const gfx::Size& size, | 236 const gfx::Size& size, |
235 gfx::BufferFormat format, | 237 gfx::BufferFormat format, |
236 uint32_t internalformat, | 238 uint32_t internalformat, |
237 uint32_t order_num, | 239 uint32_t order_num, |
238 uint64_t fence_sync); | 240 uint64_t fence_sync); |
239 void DestroyImageOnGpuThread(int32_t id); | 241 void DestroyImageOnGpuThread(int32_t id); |
240 void SetGetBufferOnGpuThread(int32_t shm_id, base::WaitableEvent* completion); | 242 void SetGetBufferOnGpuThread(int32_t shm_id, base::WaitableEvent* completion); |
241 | 243 |
242 // Callbacks: | 244 // Callbacks on the gpu thread. |
| 245 void OnContextLostOnGpuThread(); |
| 246 void PumpCommandsOnGpuThread(); |
| 247 void PerformDelayedWorkOnGpuThread(); |
| 248 // Callback implementations on the client thread. |
243 void OnContextLost(); | 249 void OnContextLost(); |
244 bool GetBufferChanged(int32_t transfer_buffer_id); | |
245 void PumpCommands(); | |
246 void PerformDelayedWork(); | |
247 | 250 |
248 const CommandBufferId command_buffer_id_; | 251 const CommandBufferId command_buffer_id_; |
249 | 252 |
250 // Members accessed on the gpu thread (possibly with the exception of | 253 // Members accessed on the gpu thread (possibly with the exception of |
251 // creation): | 254 // creation): |
| 255 scoped_refptr<base::SingleThreadTaskRunner> origin_task_runner_; |
| 256 GpuControlClient* gpu_control_client_; |
252 bool context_lost_; | 257 bool context_lost_; |
253 scoped_refptr<TransferBufferManagerInterface> transfer_buffer_manager_; | 258 scoped_refptr<TransferBufferManagerInterface> transfer_buffer_manager_; |
254 scoped_ptr<CommandExecutor> executor_; | 259 scoped_ptr<CommandExecutor> executor_; |
255 scoped_ptr<gles2::GLES2Decoder> decoder_; | 260 scoped_ptr<gles2::GLES2Decoder> decoder_; |
256 scoped_refptr<gfx::GLContext> context_; | 261 scoped_refptr<gfx::GLContext> context_; |
257 scoped_refptr<gfx::GLSurface> surface_; | 262 scoped_refptr<gfx::GLSurface> surface_; |
258 scoped_refptr<SyncPointOrderData> sync_point_order_data_; | 263 scoped_refptr<SyncPointOrderData> sync_point_order_data_; |
259 scoped_ptr<SyncPointClient> sync_point_client_; | 264 scoped_ptr<SyncPointClient> sync_point_client_; |
260 base::Closure context_lost_callback_; | 265 base::Closure context_lost_callback_; |
261 bool delayed_work_pending_; // Used to throttle PerformDelayedWork. | 266 // Used to throttle PerformDelayedWorkOnGpuThread. |
| 267 bool delayed_work_pending_; |
262 ImageFactory* image_factory_; | 268 ImageFactory* image_factory_; |
263 | 269 |
264 // Members accessed on the client thread: | 270 // Members accessed on the client thread: |
265 State last_state_; | 271 State last_state_; |
266 int32_t last_put_offset_; | 272 int32_t last_put_offset_; |
267 gpu::Capabilities capabilities_; | 273 gpu::Capabilities capabilities_; |
268 GpuMemoryBufferManager* gpu_memory_buffer_manager_; | 274 GpuMemoryBufferManager* gpu_memory_buffer_manager_; |
269 base::AtomicSequenceNumber next_image_id_; | 275 base::AtomicSequenceNumber next_image_id_; |
270 uint64_t next_fence_sync_release_; | 276 uint64_t next_fence_sync_release_; |
271 uint64_t flushed_fence_sync_release_; | 277 uint64_t flushed_fence_sync_release_; |
272 | 278 |
273 // Accessed on both threads: | 279 // Accessed on both threads: |
274 scoped_ptr<CommandBufferServiceBase> command_buffer_; | 280 scoped_ptr<CommandBufferServiceBase> command_buffer_; |
275 base::Lock command_buffer_lock_; | 281 base::Lock command_buffer_lock_; |
276 base::WaitableEvent flush_event_; | 282 base::WaitableEvent flush_event_; |
277 scoped_refptr<Service> service_; | 283 scoped_refptr<Service> service_; |
278 State state_after_last_flush_; | 284 State state_after_last_flush_; |
279 base::Lock state_after_last_flush_lock_; | 285 base::Lock state_after_last_flush_lock_; |
280 scoped_refptr<gfx::GLShareGroup> gl_share_group_; | 286 scoped_refptr<gfx::GLShareGroup> gl_share_group_; |
281 base::WaitableEvent fence_sync_wait_event_; | 287 base::WaitableEvent fence_sync_wait_event_; |
282 | 288 |
283 #if defined(OS_ANDROID) | 289 #if defined(OS_ANDROID) |
284 scoped_ptr<StreamTextureManagerInProcess> stream_texture_manager_; | 290 scoped_ptr<StreamTextureManagerInProcess> stream_texture_manager_; |
285 #endif | 291 #endif |
286 | 292 |
287 // Only used with explicit scheduling and the gpu thread is the same as | 293 // Only used with explicit scheduling and the gpu thread is the same as |
288 // the client thread. | 294 // the client thread. |
289 scoped_ptr<base::SequenceChecker> sequence_checker_; | 295 scoped_ptr<base::SequenceChecker> sequence_checker_; |
290 | 296 |
| 297 base::WeakPtr<InProcessCommandBuffer> client_thread_weak_ptr_; |
291 base::WeakPtr<InProcessCommandBuffer> gpu_thread_weak_ptr_; | 298 base::WeakPtr<InProcessCommandBuffer> gpu_thread_weak_ptr_; |
| 299 base::WeakPtrFactory<InProcessCommandBuffer> client_thread_weak_ptr_factory_; |
292 base::WeakPtrFactory<InProcessCommandBuffer> gpu_thread_weak_ptr_factory_; | 300 base::WeakPtrFactory<InProcessCommandBuffer> gpu_thread_weak_ptr_factory_; |
293 | 301 |
294 DISALLOW_COPY_AND_ASSIGN(InProcessCommandBuffer); | 302 DISALLOW_COPY_AND_ASSIGN(InProcessCommandBuffer); |
295 }; | 303 }; |
296 | 304 |
297 // Default Service class when a null service is used. | 305 // Default Service class when a null service is used. |
298 class GPU_EXPORT GpuInProcessThread | 306 class GPU_EXPORT GpuInProcessThread |
299 : public base::Thread, | 307 : public base::Thread, |
300 public NON_EXPORTED_BASE(InProcessCommandBuffer::Service), | 308 public NON_EXPORTED_BASE(InProcessCommandBuffer::Service), |
301 public base::RefCountedThreadSafe<GpuInProcessThread> { | 309 public base::RefCountedThreadSafe<GpuInProcessThread> { |
(...skipping 18 matching lines...) Expand all Loading... |
320 SyncPointManager* sync_point_manager_; // Non-owning. | 328 SyncPointManager* sync_point_manager_; // Non-owning. |
321 scoped_refptr<gpu::gles2::ShaderTranslatorCache> shader_translator_cache_; | 329 scoped_refptr<gpu::gles2::ShaderTranslatorCache> shader_translator_cache_; |
322 scoped_refptr<gpu::gles2::FramebufferCompletenessCache> | 330 scoped_refptr<gpu::gles2::FramebufferCompletenessCache> |
323 framebuffer_completeness_cache_; | 331 framebuffer_completeness_cache_; |
324 DISALLOW_COPY_AND_ASSIGN(GpuInProcessThread); | 332 DISALLOW_COPY_AND_ASSIGN(GpuInProcessThread); |
325 }; | 333 }; |
326 | 334 |
327 } // namespace gpu | 335 } // namespace gpu |
328 | 336 |
329 #endif // GPU_COMMAND_BUFFER_SERVICE_IN_PROCESS_COMMAND_BUFFER_H_ | 337 #endif // GPU_COMMAND_BUFFER_SERVICE_IN_PROCESS_COMMAND_BUFFER_H_ |
OLD | NEW |