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