Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(221)

Side by Side Diff: gpu/command_buffer/service/in_process_command_buffer.h

Issue 2493913002: Mus: Move InProcessCommandBuffer and GLInProcessContext to gpu/ipc (Closed)
Patch Set: Fixed casts on windows Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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
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 <stddef.h>
9 #include <stdint.h>
10
11 #include <map>
12 #include <memory>
13 #include <vector>
14
15 #include "base/atomic_sequence_num.h"
16 #include "base/callback.h"
17 #include "base/compiler_specific.h"
18 #include "base/containers/scoped_ptr_hash_map.h"
19 #include "base/macros.h"
20 #include "base/memory/ref_counted.h"
21 #include "base/memory/weak_ptr.h"
22 #include "base/single_thread_task_runner.h"
23 #include "base/synchronization/lock.h"
24 #include "base/synchronization/waitable_event.h"
25 #include "base/threading/thread.h"
26 #include "gpu/command_buffer/client/gpu_control.h"
27 #include "gpu/command_buffer/common/command_buffer.h"
28 #include "gpu/command_buffer/service/gpu_preferences.h"
29 #include "gpu/config/gpu_driver_bug_workarounds.h"
30 #include "gpu/gpu_export.h"
31 #include "ui/gfx/gpu_memory_buffer.h"
32 #include "ui/gfx/native_widget_types.h"
33 #include "ui/gl/gl_surface.h"
34 #include "ui/gl/gpu_preference.h"
35
36 namespace base {
37 class SequenceChecker;
38 }
39
40 namespace gl {
41 class GLContext;
42 class GLShareGroup;
43 class GLSurface;
44 }
45
46 namespace gfx {
47 class Size;
48 }
49
50 namespace gpu {
51 class SyncPointClient;
52 class SyncPointOrderData;
53 class SyncPointManager;
54
55 namespace gles2 {
56 struct ContextCreationAttribHelper;
57 class FramebufferCompletenessCache;
58 class GLES2Decoder;
59 class MailboxManager;
60 class ProgramCache;
61 class ShaderTranslatorCache;
62 }
63
64 class CommandBufferServiceBase;
65 class GpuMemoryBufferManager;
66 class CommandExecutor;
67 class ImageFactory;
68 class TransferBufferManagerInterface;
69
70 // This class provides a thread-safe interface to the global GPU service (for
71 // example GPU thread) when being run in single process mode.
72 // However, the behavior for accessing one context (i.e. one instance of this
73 // class) from different client threads is undefined.
74 class GPU_EXPORT InProcessCommandBuffer : public CommandBuffer,
75 public GpuControl {
76 public:
77 class Service;
78 explicit InProcessCommandBuffer(const scoped_refptr<Service>& service);
79 ~InProcessCommandBuffer() override;
80
81 // 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
83 // a new GLSurface.
84 bool Initialize(scoped_refptr<gl::GLSurface> surface,
85 bool is_offscreen,
86 gfx::AcceleratedWidget window,
87 const gles2::ContextCreationAttribHelper& attribs,
88 InProcessCommandBuffer* share_group,
89 GpuMemoryBufferManager* gpu_memory_buffer_manager,
90 ImageFactory* image_factory,
91 scoped_refptr<base::SingleThreadTaskRunner> task_runner);
92
93 // CommandBuffer implementation:
94 State GetLastState() override;
95 int32_t GetLastToken() override;
96 void Flush(int32_t put_offset) override;
97 void OrderingBarrier(int32_t put_offset) override;
98 void WaitForTokenInRange(int32_t start, int32_t end) override;
99 void WaitForGetOffsetInRange(int32_t start, int32_t end) override;
100 void SetGetBuffer(int32_t shm_id) override;
101 scoped_refptr<gpu::Buffer> CreateTransferBuffer(size_t size,
102 int32_t* id) override;
103 void DestroyTransferBuffer(int32_t id) override;
104 gpu::error::Error GetLastError() override;
105
106 // GpuControl implementation:
107 // NOTE: The GpuControlClient will be called on the client thread.
108 void SetGpuControlClient(GpuControlClient*) override;
109 gpu::Capabilities GetCapabilities() override;
110 int32_t CreateImage(ClientBuffer buffer,
111 size_t width,
112 size_t height,
113 unsigned internalformat) override;
114 void DestroyImage(int32_t id) override;
115 int32_t CreateGpuMemoryBufferImage(size_t width,
116 size_t height,
117 unsigned internalformat,
118 unsigned usage) override;
119 void SignalQuery(uint32_t query_id, const base::Closure& callback) override;
120 void SetLock(base::Lock*) override;
121 void EnsureWorkVisible() override;
122 CommandBufferNamespace GetNamespaceID() const override;
123 CommandBufferId GetCommandBufferID() const override;
124 int32_t GetExtraCommandBufferData() const override;
125 uint64_t GenerateFenceSyncRelease() override;
126 bool IsFenceSyncRelease(uint64_t release) override;
127 bool IsFenceSyncFlushed(uint64_t release) override;
128 bool IsFenceSyncFlushReceived(uint64_t release) override;
129 void SignalSyncToken(const SyncToken& sync_token,
130 const base::Closure& callback) override;
131 bool CanWaitUnverifiedSyncToken(const SyncToken* sync_token) override;
132
133 // The serializer interface to the GPU service (i.e. thread).
134 class Service {
135 public:
136 Service();
137 Service(const gpu::GpuPreferences& gpu_preferences);
138 virtual ~Service();
139
140 virtual void AddRef() const = 0;
141 virtual void Release() const = 0;
142
143 // Queues a task to run as soon as possible.
144 virtual void ScheduleTask(const base::Closure& task) = 0;
145
146 // Schedules |callback| to run at an appropriate time for performing delayed
147 // work.
148 virtual void ScheduleDelayedWork(const base::Closure& task) = 0;
149
150 virtual bool UseVirtualizedGLContexts() = 0;
151 virtual scoped_refptr<gles2::ShaderTranslatorCache>
152 shader_translator_cache() = 0;
153 virtual scoped_refptr<gles2::FramebufferCompletenessCache>
154 framebuffer_completeness_cache() = 0;
155 virtual SyncPointManager* sync_point_manager() = 0;
156 const GpuPreferences& gpu_preferences();
157 const GpuDriverBugWorkarounds& gpu_driver_bug_workarounds();
158 scoped_refptr<gl::GLShareGroup> share_group();
159 scoped_refptr<gles2::MailboxManager> mailbox_manager();
160 gpu::gles2::ProgramCache* program_cache();
161
162 private:
163 const GpuPreferences gpu_preferences_;
164 const GpuDriverBugWorkarounds gpu_driver_bug_workarounds_;
165 scoped_refptr<gl::GLShareGroup> share_group_;
166 scoped_refptr<gles2::MailboxManager> mailbox_manager_;
167 std::unique_ptr<gpu::gles2::ProgramCache> program_cache_;
168 };
169
170 private:
171 struct InitializeOnGpuThreadParams {
172 bool is_offscreen;
173 gfx::AcceleratedWidget window;
174 const gles2::ContextCreationAttribHelper& attribs;
175 gpu::Capabilities* capabilities; // Ouptut.
176 InProcessCommandBuffer* context_group;
177 ImageFactory* image_factory;
178
179 InitializeOnGpuThreadParams(
180 bool is_offscreen,
181 gfx::AcceleratedWidget window,
182 const gles2::ContextCreationAttribHelper& attribs,
183 gpu::Capabilities* capabilities,
184 InProcessCommandBuffer* share_group,
185 ImageFactory* image_factory)
186 : is_offscreen(is_offscreen),
187 window(window),
188 attribs(attribs),
189 capabilities(capabilities),
190 context_group(share_group),
191 image_factory(image_factory) {}
192 };
193
194 bool InitializeOnGpuThread(const InitializeOnGpuThreadParams& params);
195 void Destroy();
196 bool DestroyOnGpuThread();
197 void FlushOnGpuThread(int32_t put_offset, uint32_t order_num);
198 void ScheduleDelayedWorkOnGpuThread();
199 bool MakeCurrent();
200 base::Closure WrapCallback(const base::Closure& callback);
201 State GetStateFast();
202 void QueueTask(const base::Closure& task) { service_->ScheduleTask(task); }
203 void CheckSequencedThread();
204 void FenceSyncReleaseOnGpuThread(uint64_t release);
205 bool WaitFenceSyncOnGpuThread(gpu::CommandBufferNamespace namespace_id,
206 gpu::CommandBufferId command_buffer_id,
207 uint64_t release);
208 void DescheduleUntilFinishedOnGpuThread();
209 void RescheduleAfterFinishedOnGpuThread();
210 void SignalSyncTokenOnGpuThread(const SyncToken& sync_token,
211 const base::Closure& callback);
212 void SignalQueryOnGpuThread(unsigned query_id, const base::Closure& callback);
213 void DestroyTransferBufferOnGpuThread(int32_t id);
214 void CreateImageOnGpuThread(int32_t id,
215 const gfx::GpuMemoryBufferHandle& handle,
216 const gfx::Size& size,
217 gfx::BufferFormat format,
218 uint32_t internalformat,
219 uint32_t order_num,
220 uint64_t fence_sync);
221 void DestroyImageOnGpuThread(int32_t id);
222 void SetGetBufferOnGpuThread(int32_t shm_id, base::WaitableEvent* completion);
223
224 // Callbacks on the gpu thread.
225 void OnContextLostOnGpuThread();
226 void PumpCommandsOnGpuThread();
227 void PerformDelayedWorkOnGpuThread();
228 // Callback implementations on the client thread.
229 void OnContextLost();
230
231 const CommandBufferId command_buffer_id_;
232
233 // Members accessed on the gpu thread (possibly with the exception of
234 // creation):
235 scoped_refptr<base::SingleThreadTaskRunner> origin_task_runner_;
236 scoped_refptr<TransferBufferManagerInterface> transfer_buffer_manager_;
237 std::unique_ptr<CommandExecutor> executor_;
238 std::unique_ptr<gles2::GLES2Decoder> decoder_;
239 scoped_refptr<gl::GLContext> context_;
240 scoped_refptr<gl::GLSurface> surface_;
241 scoped_refptr<SyncPointOrderData> sync_point_order_data_;
242 std::unique_ptr<SyncPointClient> sync_point_client_;
243 base::Closure context_lost_callback_;
244 // Used to throttle PerformDelayedWorkOnGpuThread.
245 bool delayed_work_pending_;
246 ImageFactory* image_factory_;
247
248 // Members accessed on the client thread:
249 GpuControlClient* gpu_control_client_;
250 #if DCHECK_IS_ON()
251 bool context_lost_;
252 #endif
253 State last_state_;
254 int32_t last_put_offset_;
255 gpu::Capabilities capabilities_;
256 GpuMemoryBufferManager* gpu_memory_buffer_manager_;
257 base::AtomicSequenceNumber next_image_id_;
258 uint64_t next_fence_sync_release_;
259 uint64_t flushed_fence_sync_release_;
260
261 // Accessed on both threads:
262 std::unique_ptr<CommandBufferServiceBase> command_buffer_;
263 base::Lock command_buffer_lock_;
264 base::WaitableEvent flush_event_;
265 scoped_refptr<Service> service_;
266 State state_after_last_flush_;
267 base::Lock state_after_last_flush_lock_;
268 scoped_refptr<gl::GLShareGroup> gl_share_group_;
269 base::WaitableEvent fence_sync_wait_event_;
270
271 // Only used with explicit scheduling and the gpu thread is the same as
272 // the client thread.
273 std::unique_ptr<base::SequenceChecker> sequence_checker_;
274
275 base::WeakPtr<InProcessCommandBuffer> client_thread_weak_ptr_;
276 base::WeakPtr<InProcessCommandBuffer> gpu_thread_weak_ptr_;
277 base::WeakPtrFactory<InProcessCommandBuffer> client_thread_weak_ptr_factory_;
278 base::WeakPtrFactory<InProcessCommandBuffer> gpu_thread_weak_ptr_factory_;
279
280 DISALLOW_COPY_AND_ASSIGN(InProcessCommandBuffer);
281 };
282
283 // Default Service class when a null service is used.
284 class GPU_EXPORT GpuInProcessThread
285 : public base::Thread,
286 public NON_EXPORTED_BASE(InProcessCommandBuffer::Service),
287 public base::RefCountedThreadSafe<GpuInProcessThread> {
288 public:
289 explicit GpuInProcessThread(SyncPointManager* sync_point_manager);
290
291 void AddRef() const override;
292 void Release() const override;
293 void ScheduleTask(const base::Closure& task) override;
294 void ScheduleDelayedWork(const base::Closure& callback) override;
295 bool UseVirtualizedGLContexts() override;
296 scoped_refptr<gles2::ShaderTranslatorCache> shader_translator_cache()
297 override;
298 scoped_refptr<gles2::FramebufferCompletenessCache>
299 framebuffer_completeness_cache() override;
300 SyncPointManager* sync_point_manager() override;
301
302 private:
303 ~GpuInProcessThread() override;
304 friend class base::RefCountedThreadSafe<GpuInProcessThread>;
305
306 SyncPointManager* sync_point_manager_; // Non-owning.
307 scoped_refptr<gpu::gles2::ShaderTranslatorCache> shader_translator_cache_;
308 scoped_refptr<gpu::gles2::FramebufferCompletenessCache>
309 framebuffer_completeness_cache_;
310 DISALLOW_COPY_AND_ASSIGN(GpuInProcessThread);
311 };
312
313 } // namespace gpu
314
315 #endif // GPU_COMMAND_BUFFER_SERVICE_IN_PROCESS_COMMAND_BUFFER_H_
OLDNEW
« no previous file with comments | « gpu/command_buffer/service/BUILD.gn ('k') | gpu/command_buffer/service/in_process_command_buffer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698