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> |
| 9 #include <stdint.h> |
| 10 |
8 #include <map> | 11 #include <map> |
9 #include <vector> | 12 #include <vector> |
10 | 13 |
11 #include "base/atomic_sequence_num.h" | 14 #include "base/atomic_sequence_num.h" |
12 #include "base/callback.h" | 15 #include "base/callback.h" |
13 #include "base/compiler_specific.h" | 16 #include "base/compiler_specific.h" |
14 #include "base/containers/scoped_ptr_hash_map.h" | 17 #include "base/containers/scoped_ptr_hash_map.h" |
| 18 #include "base/macros.h" |
15 #include "base/memory/ref_counted.h" | 19 #include "base/memory/ref_counted.h" |
16 #include "base/memory/scoped_ptr.h" | 20 #include "base/memory/scoped_ptr.h" |
17 #include "base/memory/weak_ptr.h" | 21 #include "base/memory/weak_ptr.h" |
18 #include "base/synchronization/lock.h" | 22 #include "base/synchronization/lock.h" |
19 #include "base/synchronization/waitable_event.h" | 23 #include "base/synchronization/waitable_event.h" |
20 #include "base/threading/thread.h" | 24 #include "base/threading/thread.h" |
21 #include "gpu/command_buffer/client/gpu_control.h" | 25 #include "gpu/command_buffer/client/gpu_control.h" |
22 #include "gpu/command_buffer/common/command_buffer.h" | 26 #include "gpu/command_buffer/common/command_buffer.h" |
23 #include "gpu/gpu_export.h" | 27 #include "gpu/gpu_export.h" |
24 #include "ui/gfx/gpu_memory_buffer.h" | 28 #include "ui/gfx/gpu_memory_buffer.h" |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 explicit InProcessCommandBuffer(const scoped_refptr<Service>& service); | 82 explicit InProcessCommandBuffer(const scoped_refptr<Service>& service); |
79 ~InProcessCommandBuffer() override; | 83 ~InProcessCommandBuffer() override; |
80 | 84 |
81 // If |surface| is not NULL, use it directly; in this case, the command | 85 // If |surface| is not NULL, use it directly; in this case, the command |
82 // buffer gpu thread must be the same as the client thread. Otherwise create | 86 // buffer gpu thread must be the same as the client thread. Otherwise create |
83 // a new GLSurface. | 87 // a new GLSurface. |
84 bool Initialize(scoped_refptr<gfx::GLSurface> surface, | 88 bool Initialize(scoped_refptr<gfx::GLSurface> surface, |
85 bool is_offscreen, | 89 bool is_offscreen, |
86 gfx::AcceleratedWidget window, | 90 gfx::AcceleratedWidget window, |
87 const gfx::Size& size, | 91 const gfx::Size& size, |
88 const std::vector<int32>& attribs, | 92 const std::vector<int32_t>& attribs, |
89 gfx::GpuPreference gpu_preference, | 93 gfx::GpuPreference gpu_preference, |
90 const base::Closure& context_lost_callback, | 94 const base::Closure& context_lost_callback, |
91 InProcessCommandBuffer* share_group, | 95 InProcessCommandBuffer* share_group, |
92 GpuMemoryBufferManager* gpu_memory_buffer_manager, | 96 GpuMemoryBufferManager* gpu_memory_buffer_manager, |
93 ImageFactory* image_factory); | 97 ImageFactory* image_factory); |
94 void Destroy(); | 98 void Destroy(); |
95 | 99 |
96 // CommandBuffer implementation: | 100 // CommandBuffer implementation: |
97 bool Initialize() override; | 101 bool Initialize() override; |
98 State GetLastState() override; | 102 State GetLastState() override; |
99 int32 GetLastToken() override; | 103 int32_t GetLastToken() override; |
100 void Flush(int32 put_offset) override; | 104 void Flush(int32_t put_offset) override; |
101 void OrderingBarrier(int32 put_offset) override; | 105 void OrderingBarrier(int32_t put_offset) override; |
102 void WaitForTokenInRange(int32 start, int32 end) override; | 106 void WaitForTokenInRange(int32_t start, int32_t end) override; |
103 void WaitForGetOffsetInRange(int32 start, int32 end) override; | 107 void WaitForGetOffsetInRange(int32_t start, int32_t end) override; |
104 void SetGetBuffer(int32 shm_id) override; | 108 void SetGetBuffer(int32_t shm_id) override; |
105 scoped_refptr<gpu::Buffer> CreateTransferBuffer(size_t size, | 109 scoped_refptr<gpu::Buffer> CreateTransferBuffer(size_t size, |
106 int32* id) override; | 110 int32_t* id) override; |
107 void DestroyTransferBuffer(int32 id) override; | 111 void DestroyTransferBuffer(int32_t id) override; |
108 gpu::error::Error GetLastError() override; | 112 gpu::error::Error GetLastError() override; |
109 | 113 |
110 // GpuControl implementation: | 114 // GpuControl implementation: |
111 gpu::Capabilities GetCapabilities() override; | 115 gpu::Capabilities GetCapabilities() override; |
112 int32 CreateImage(ClientBuffer buffer, | 116 int32_t CreateImage(ClientBuffer buffer, |
113 size_t width, | 117 size_t width, |
114 size_t height, | 118 size_t height, |
115 unsigned internalformat) override; | 119 unsigned internalformat) override; |
116 void DestroyImage(int32 id) override; | 120 void DestroyImage(int32_t id) override; |
117 int32 CreateGpuMemoryBufferImage(size_t width, | 121 int32_t CreateGpuMemoryBufferImage(size_t width, |
118 size_t height, | 122 size_t height, |
119 unsigned internalformat, | 123 unsigned internalformat, |
120 unsigned usage) override; | 124 unsigned usage) override; |
121 uint32 InsertSyncPoint() override; | 125 uint32_t InsertSyncPoint() override; |
122 uint32 InsertFutureSyncPoint() override; | 126 uint32_t InsertFutureSyncPoint() override; |
123 void RetireSyncPoint(uint32 sync_point) override; | 127 void RetireSyncPoint(uint32_t sync_point) override; |
124 void SignalSyncPoint(uint32 sync_point, | 128 void SignalSyncPoint(uint32_t sync_point, |
125 const base::Closure& callback) override; | 129 const base::Closure& callback) override; |
126 void SignalQuery(uint32 query_id, const base::Closure& callback) override; | 130 void SignalQuery(uint32_t query_id, const base::Closure& callback) override; |
127 void SetLock(base::Lock*) override; | 131 void SetLock(base::Lock*) override; |
128 bool IsGpuChannelLost() override; | 132 bool IsGpuChannelLost() override; |
129 CommandBufferNamespace GetNamespaceID() const override; | 133 CommandBufferNamespace GetNamespaceID() const override; |
130 uint64_t GetCommandBufferID() const override; | 134 uint64_t GetCommandBufferID() const override; |
131 int32_t GetExtraCommandBufferData() const override; | 135 int32_t GetExtraCommandBufferData() const override; |
132 uint64_t GenerateFenceSyncRelease() override; | 136 uint64_t GenerateFenceSyncRelease() override; |
133 bool IsFenceSyncRelease(uint64_t release) override; | 137 bool IsFenceSyncRelease(uint64_t release) override; |
134 bool IsFenceSyncFlushed(uint64_t release) override; | 138 bool IsFenceSyncFlushed(uint64_t release) override; |
135 bool IsFenceSyncFlushReceived(uint64_t release) override; | 139 bool IsFenceSyncFlushReceived(uint64_t release) override; |
136 void SignalSyncToken(const SyncToken& sync_token, | 140 void SignalSyncToken(const SyncToken& sync_token, |
(...skipping 30 matching lines...) Expand all Loading... |
167 | 171 |
168 private: | 172 private: |
169 scoped_refptr<gfx::GLShareGroup> share_group_; | 173 scoped_refptr<gfx::GLShareGroup> share_group_; |
170 scoped_refptr<gles2::MailboxManager> mailbox_manager_; | 174 scoped_refptr<gles2::MailboxManager> mailbox_manager_; |
171 scoped_refptr<gles2::SubscriptionRefSet> subscription_ref_set_; | 175 scoped_refptr<gles2::SubscriptionRefSet> subscription_ref_set_; |
172 scoped_refptr<gpu::ValueStateMap> pending_valuebuffer_state_; | 176 scoped_refptr<gpu::ValueStateMap> pending_valuebuffer_state_; |
173 scoped_ptr<gpu::gles2::ProgramCache> program_cache_; | 177 scoped_ptr<gpu::gles2::ProgramCache> program_cache_; |
174 }; | 178 }; |
175 | 179 |
176 #if defined(OS_ANDROID) | 180 #if defined(OS_ANDROID) |
177 scoped_refptr<gfx::SurfaceTexture> GetSurfaceTexture( | 181 scoped_refptr<gfx::SurfaceTexture> GetSurfaceTexture(uint32_t stream_id); |
178 uint32 stream_id); | 182 uint32_t CreateStreamTexture(uint32_t texture_id); |
179 uint32 CreateStreamTexture(uint32 texture_id); | |
180 #endif | 183 #endif |
181 | 184 |
182 private: | 185 private: |
183 struct InitializeOnGpuThreadParams { | 186 struct InitializeOnGpuThreadParams { |
184 bool is_offscreen; | 187 bool is_offscreen; |
185 gfx::AcceleratedWidget window; | 188 gfx::AcceleratedWidget window; |
186 const gfx::Size& size; | 189 const gfx::Size& size; |
187 const std::vector<int32>& attribs; | 190 const std::vector<int32_t>& attribs; |
188 gfx::GpuPreference gpu_preference; | 191 gfx::GpuPreference gpu_preference; |
189 gpu::Capabilities* capabilities; // Ouptut. | 192 gpu::Capabilities* capabilities; // Ouptut. |
190 InProcessCommandBuffer* context_group; | 193 InProcessCommandBuffer* context_group; |
191 ImageFactory* image_factory; | 194 ImageFactory* image_factory; |
192 | 195 |
193 InitializeOnGpuThreadParams(bool is_offscreen, | 196 InitializeOnGpuThreadParams(bool is_offscreen, |
194 gfx::AcceleratedWidget window, | 197 gfx::AcceleratedWidget window, |
195 const gfx::Size& size, | 198 const gfx::Size& size, |
196 const std::vector<int32>& attribs, | 199 const std::vector<int32_t>& attribs, |
197 gfx::GpuPreference gpu_preference, | 200 gfx::GpuPreference gpu_preference, |
198 gpu::Capabilities* capabilities, | 201 gpu::Capabilities* capabilities, |
199 InProcessCommandBuffer* share_group, | 202 InProcessCommandBuffer* share_group, |
200 ImageFactory* image_factory) | 203 ImageFactory* image_factory) |
201 : is_offscreen(is_offscreen), | 204 : is_offscreen(is_offscreen), |
202 window(window), | 205 window(window), |
203 size(size), | 206 size(size), |
204 attribs(attribs), | 207 attribs(attribs), |
205 gpu_preference(gpu_preference), | 208 gpu_preference(gpu_preference), |
206 capabilities(capabilities), | 209 capabilities(capabilities), |
207 context_group(share_group), | 210 context_group(share_group), |
208 image_factory(image_factory) {} | 211 image_factory(image_factory) {} |
209 }; | 212 }; |
210 | 213 |
211 bool InitializeOnGpuThread(const InitializeOnGpuThreadParams& params); | 214 bool InitializeOnGpuThread(const InitializeOnGpuThreadParams& params); |
212 bool DestroyOnGpuThread(); | 215 bool DestroyOnGpuThread(); |
213 void FlushOnGpuThread(int32 put_offset, uint32_t order_num); | 216 void FlushOnGpuThread(int32_t put_offset, uint32_t order_num); |
214 void ScheduleDelayedWorkOnGpuThread(); | 217 void ScheduleDelayedWorkOnGpuThread(); |
215 uint32 CreateStreamTextureOnGpuThread(uint32 client_texture_id); | 218 uint32_t CreateStreamTextureOnGpuThread(uint32_t client_texture_id); |
216 bool MakeCurrent(); | 219 bool MakeCurrent(); |
217 base::Closure WrapCallback(const base::Closure& callback); | 220 base::Closure WrapCallback(const base::Closure& callback); |
218 State GetStateFast(); | 221 State GetStateFast(); |
219 void QueueTask(const base::Closure& task) { service_->ScheduleTask(task); } | 222 void QueueTask(const base::Closure& task) { service_->ScheduleTask(task); } |
220 void CheckSequencedThread(); | 223 void CheckSequencedThread(); |
221 void RetireSyncPointOnGpuThread(uint32 sync_point); | 224 void RetireSyncPointOnGpuThread(uint32_t sync_point); |
222 bool WaitSyncPointOnGpuThread(uint32 sync_point); | 225 bool WaitSyncPointOnGpuThread(uint32_t sync_point); |
223 void FenceSyncReleaseOnGpuThread(uint64_t release); | 226 void FenceSyncReleaseOnGpuThread(uint64_t release); |
224 bool WaitFenceSyncOnGpuThread(gpu::CommandBufferNamespace namespace_id, | 227 bool WaitFenceSyncOnGpuThread(gpu::CommandBufferNamespace namespace_id, |
225 uint64_t command_buffer_id, | 228 uint64_t command_buffer_id, |
226 uint64_t release); | 229 uint64_t release); |
227 void SignalSyncTokenOnGpuThread(const SyncToken& sync_token, | 230 void SignalSyncTokenOnGpuThread(const SyncToken& sync_token, |
228 const base::Closure& callback); | 231 const base::Closure& callback); |
229 void SignalQueryOnGpuThread(unsigned query_id, const base::Closure& callback); | 232 void SignalQueryOnGpuThread(unsigned query_id, const base::Closure& callback); |
230 void DestroyTransferBufferOnGpuThread(int32 id); | 233 void DestroyTransferBufferOnGpuThread(int32_t id); |
231 void CreateImageOnGpuThread(int32 id, | 234 void CreateImageOnGpuThread(int32_t id, |
232 const gfx::GpuMemoryBufferHandle& handle, | 235 const gfx::GpuMemoryBufferHandle& handle, |
233 const gfx::Size& size, | 236 const gfx::Size& size, |
234 gfx::BufferFormat format, | 237 gfx::BufferFormat format, |
235 uint32 internalformat, | 238 uint32_t internalformat, |
236 uint32_t order_num, | 239 uint32_t order_num, |
237 uint64_t fence_sync); | 240 uint64_t fence_sync); |
238 void DestroyImageOnGpuThread(int32 id); | 241 void DestroyImageOnGpuThread(int32_t id); |
239 void SetGetBufferOnGpuThread(int32 shm_id, base::WaitableEvent* completion); | 242 void SetGetBufferOnGpuThread(int32_t shm_id, base::WaitableEvent* completion); |
240 | 243 |
241 // Callbacks: | 244 // Callbacks: |
242 void OnContextLost(); | 245 void OnContextLost(); |
243 bool GetBufferChanged(int32 transfer_buffer_id); | 246 bool GetBufferChanged(int32_t transfer_buffer_id); |
244 void PumpCommands(); | 247 void PumpCommands(); |
245 void PerformDelayedWork(); | 248 void PerformDelayedWork(); |
246 | 249 |
247 const uint64_t command_buffer_id_; | 250 const uint64_t command_buffer_id_; |
248 | 251 |
249 // Members accessed on the gpu thread (possibly with the exception of | 252 // Members accessed on the gpu thread (possibly with the exception of |
250 // creation): | 253 // creation): |
251 bool context_lost_; | 254 bool context_lost_; |
252 scoped_refptr<TransferBufferManagerInterface> transfer_buffer_manager_; | 255 scoped_refptr<TransferBufferManagerInterface> transfer_buffer_manager_; |
253 scoped_ptr<GpuScheduler> gpu_scheduler_; | 256 scoped_ptr<GpuScheduler> gpu_scheduler_; |
254 scoped_ptr<gles2::GLES2Decoder> decoder_; | 257 scoped_ptr<gles2::GLES2Decoder> decoder_; |
255 scoped_refptr<gfx::GLContext> context_; | 258 scoped_refptr<gfx::GLContext> context_; |
256 scoped_refptr<gfx::GLSurface> surface_; | 259 scoped_refptr<gfx::GLSurface> surface_; |
257 scoped_refptr<SyncPointOrderData> sync_point_order_data_; | 260 scoped_refptr<SyncPointOrderData> sync_point_order_data_; |
258 scoped_ptr<SyncPointClient> sync_point_client_; | 261 scoped_ptr<SyncPointClient> sync_point_client_; |
259 base::Closure context_lost_callback_; | 262 base::Closure context_lost_callback_; |
260 bool delayed_work_pending_; // Used to throttle PerformDelayedWork. | 263 bool delayed_work_pending_; // Used to throttle PerformDelayedWork. |
261 ImageFactory* image_factory_; | 264 ImageFactory* image_factory_; |
262 | 265 |
263 // Members accessed on the client thread: | 266 // Members accessed on the client thread: |
264 State last_state_; | 267 State last_state_; |
265 int32 last_put_offset_; | 268 int32_t last_put_offset_; |
266 gpu::Capabilities capabilities_; | 269 gpu::Capabilities capabilities_; |
267 GpuMemoryBufferManager* gpu_memory_buffer_manager_; | 270 GpuMemoryBufferManager* gpu_memory_buffer_manager_; |
268 base::AtomicSequenceNumber next_image_id_; | 271 base::AtomicSequenceNumber next_image_id_; |
269 uint64_t next_fence_sync_release_; | 272 uint64_t next_fence_sync_release_; |
270 uint64_t flushed_fence_sync_release_; | 273 uint64_t flushed_fence_sync_release_; |
271 | 274 |
272 // Accessed on both threads: | 275 // Accessed on both threads: |
273 scoped_ptr<CommandBufferServiceBase> command_buffer_; | 276 scoped_ptr<CommandBufferServiceBase> command_buffer_; |
274 base::Lock command_buffer_lock_; | 277 base::Lock command_buffer_lock_; |
275 base::WaitableEvent flush_event_; | 278 base::WaitableEvent flush_event_; |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
319 SyncPointManager* sync_point_manager_; // Non-owning. | 322 SyncPointManager* sync_point_manager_; // Non-owning. |
320 scoped_refptr<gpu::gles2::ShaderTranslatorCache> shader_translator_cache_; | 323 scoped_refptr<gpu::gles2::ShaderTranslatorCache> shader_translator_cache_; |
321 scoped_refptr<gpu::gles2::FramebufferCompletenessCache> | 324 scoped_refptr<gpu::gles2::FramebufferCompletenessCache> |
322 framebuffer_completeness_cache_; | 325 framebuffer_completeness_cache_; |
323 DISALLOW_COPY_AND_ASSIGN(GpuInProcessThread); | 326 DISALLOW_COPY_AND_ASSIGN(GpuInProcessThread); |
324 }; | 327 }; |
325 | 328 |
326 } // namespace gpu | 329 } // namespace gpu |
327 | 330 |
328 #endif // GPU_COMMAND_BUFFER_SERVICE_IN_PROCESS_COMMAND_BUFFER_H_ | 331 #endif // GPU_COMMAND_BUFFER_SERVICE_IN_PROCESS_COMMAND_BUFFER_H_ |
OLD | NEW |