OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef GPU_COMMAND_BUFFER_SERVICE_IN_PROCESS_COMMAND_BUFFER_H_ |
| 6 #define GPU_COMMAND_BUFFER_SERVICE_IN_PROCESS_COMMAND_BUFFER_H_ |
| 7 |
| 8 #include <vector> |
| 9 |
| 10 #include "base/callback.h" |
| 11 #include "base/compiler_specific.h" |
| 12 #include "base/synchronization/lock.h" |
| 13 #include "base/synchronization/waitable_event.h" |
| 14 #include "gpu/command_buffer/common/command_buffer.h" |
| 15 #include "gpu/gpu_export.h" |
| 16 #include "ui/gfx/native_widget_types.h" |
| 17 #include "ui/gl/gpu_preference.h" |
| 18 |
| 19 namespace gfx { |
| 20 class GLContext; |
| 21 class GLImage; |
| 22 class GLSurface; |
| 23 class Size; |
| 24 } |
| 25 |
| 26 namespace gpu { |
| 27 |
| 28 namespace gles2 { |
| 29 class GLES2Decoder; |
| 30 class ShareGroup; |
| 31 } |
| 32 |
| 33 class GpuScheduler; |
| 34 class TransferBufferManagerInterface; |
| 35 |
| 36 // This class provides a thread-safe interface to the global GPU service (for |
| 37 // example GPU thread) when being run in single process mode. |
| 38 // However, the behavior for accessing one context (i.e. one instance of this |
| 39 // class) from different client threads is undefined. |
| 40 class GPU_EXPORT InProcessCommandBuffer : public CommandBuffer { |
| 41 public: |
| 42 InProcessCommandBuffer(); |
| 43 virtual ~InProcessCommandBuffer(); |
| 44 |
| 45 // Used to override the GPU thread with explicit scheduling. |
| 46 // (By default an internal GPU thread will be spawned to handle all GL work |
| 47 // and the two functions are unused.) |
| 48 // The callback will be called from different client threads. After the |
| 49 // callback is issued, the client is expected to eventually call |
| 50 // ProcessGpuWorkOnCurrentThread(). The latter cannot be called from different |
| 51 // threads. |
| 52 static void SetScheduleCallback(const base::Closure& callback); |
| 53 static void ProcessGpuWorkOnCurrentThread(); |
| 54 |
| 55 static void EnableVirtualizedContext(); |
| 56 |
| 57 bool Initialize(bool is_offscreen, |
| 58 bool share_resources, |
| 59 gfx::AcceleratedWidget window, |
| 60 const gfx::Size& size, |
| 61 const char* allowed_extensions, |
| 62 const std::vector<int32>& attribs, |
| 63 gfx::GpuPreference gpu_preference, |
| 64 const base::Closure& context_lost_callback, |
| 65 scoped_refptr<gles2::ShareGroup>* share_group_for_client); |
| 66 void Destroy(); |
| 67 void SignalSyncPoint(unsigned sync_point, |
| 68 const base::Closure& callback); |
| 69 unsigned int CreateImageForGpuMemoryBuffer( |
| 70 gfx::GpuMemoryBufferHandle buffer, |
| 71 gfx::Size size); |
| 72 void RemoveImage(unsigned int image_id); |
| 73 |
| 74 // CommandBuffer implementation: |
| 75 virtual bool Initialize() OVERRIDE; |
| 76 virtual State GetState() OVERRIDE; |
| 77 virtual State GetLastState() OVERRIDE; |
| 78 virtual int32 GetLastToken() OVERRIDE; |
| 79 virtual void Flush(int32 put_offset) OVERRIDE; |
| 80 virtual State FlushSync(int32 put_offset, int32 last_known_get) OVERRIDE; |
| 81 virtual void SetGetBuffer(int32 shm_id) OVERRIDE; |
| 82 virtual void SetGetOffset(int32 get_offset) OVERRIDE; |
| 83 virtual gpu::Buffer CreateTransferBuffer(size_t size, int32* id) OVERRIDE; |
| 84 virtual void DestroyTransferBuffer(int32 id) OVERRIDE; |
| 85 virtual gpu::Buffer GetTransferBuffer(int32 id) OVERRIDE; |
| 86 virtual void SetToken(int32 token) OVERRIDE; |
| 87 virtual void SetParseError(gpu::error::Error error) OVERRIDE; |
| 88 virtual void SetContextLostReason( |
| 89 gpu::error::ContextLostReason reason) OVERRIDE; |
| 90 virtual uint32 InsertSyncPoint() OVERRIDE; |
| 91 virtual gpu::error::Error GetLastError() OVERRIDE; |
| 92 |
| 93 private: |
| 94 bool InitializeOnGpuThread(bool is_offscreen, |
| 95 gfx::AcceleratedWidget window, |
| 96 const gfx::Size& size, |
| 97 const char* allowed_extensions, |
| 98 const std::vector<int32>& attribs, |
| 99 gfx::GpuPreference gpu_preference); |
| 100 bool DestroyOnGpuThread(); |
| 101 void FlushOnGpuThread(int32 put_offset); |
| 102 void CreateImageOnGpuThread(gfx::GpuMemoryBufferHandle buffer, |
| 103 gfx::Size size, |
| 104 unsigned int image_id); |
| 105 void RemoveImageOnGpuThread(unsigned int image_id); |
| 106 bool MakeCurrent(); |
| 107 bool IsContextLost(); |
| 108 base::Closure WrapCallback(const base::Closure& callback); |
| 109 State GetStateFast(); |
| 110 |
| 111 // Callbacks: |
| 112 void OnContextLost(); |
| 113 void OnResizeView(gfx::Size size, float scale_factor); |
| 114 bool GetBufferChanged(int32 transfer_buffer_id); |
| 115 void PumpCommands(); |
| 116 |
| 117 // Members accessed on the gpu thread (possibly with the exception of |
| 118 // creation): |
| 119 bool context_lost_; |
| 120 bool share_resources_; |
| 121 scoped_ptr<TransferBufferManagerInterface> transfer_buffer_manager_; |
| 122 scoped_ptr<GpuScheduler> gpu_scheduler_; |
| 123 scoped_ptr<gles2::GLES2Decoder> decoder_; |
| 124 scoped_refptr<gfx::GLContext> context_; |
| 125 scoped_refptr<gfx::GLSurface> surface_; |
| 126 base::Closure context_lost_callback_; |
| 127 |
| 128 // Members accessed on the client thread: |
| 129 State last_state_; |
| 130 int32 last_put_offset_; |
| 131 |
| 132 // Accessed on both threads: |
| 133 scoped_ptr<CommandBuffer> command_buffer_; |
| 134 base::Lock command_buffer_lock_; |
| 135 base::WaitableEvent flush_event_; |
| 136 scoped_refptr<gles2::ShareGroup> client_share_group_; |
| 137 |
| 138 DISALLOW_COPY_AND_ASSIGN(InProcessCommandBuffer); |
| 139 }; |
| 140 |
| 141 } // namespace gpu |
| 142 |
| 143 #endif // GPU_COMMAND_BUFFER_SERVICE_IN_PROCESS_COMMAND_BUFFER_H_ |
OLD | NEW |