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

Side by Side Diff: gpu/ipc/in_process_command_buffer.h

Issue 2498053004: Add InProcessContextProvider and update InProcessCommandBuffer (Closed)
Patch Set: 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
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_IPC_IN_PROCESS_COMMAND_BUFFER_H_ 5 #ifndef GPU_IPC_IN_PROCESS_COMMAND_BUFFER_H_
6 #define GPU_IPC_IN_PROCESS_COMMAND_BUFFER_H_ 6 #define GPU_IPC_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 <memory> 12 #include <memory>
13 #include <vector> 13 #include <vector>
14 14
15 #include "base/atomic_sequence_num.h" 15 #include "base/atomic_sequence_num.h"
16 #include "base/callback.h" 16 #include "base/callback.h"
17 #include "base/compiler_specific.h" 17 #include "base/compiler_specific.h"
18 #include "base/containers/scoped_ptr_hash_map.h" 18 #include "base/containers/scoped_ptr_hash_map.h"
19 #include "base/macros.h" 19 #include "base/macros.h"
20 #include "base/memory/ref_counted.h" 20 #include "base/memory/ref_counted.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/single_thread_task_runner.h"
23 #include "base/synchronization/lock.h" 23 #include "base/synchronization/lock.h"
24 #include "base/synchronization/waitable_event.h" 24 #include "base/synchronization/waitable_event.h"
25 #include "base/threading/thread.h" 25 #include "base/threading/thread.h"
26 #include "gpu/command_buffer/client/gpu_control.h" 26 #include "gpu/command_buffer/client/gpu_control.h"
27 #include "gpu/command_buffer/common/command_buffer.h" 27 #include "gpu/command_buffer/common/command_buffer.h"
28 #include "gpu/command_buffer/service/command_executor.h"
29 #include "gpu/command_buffer/service/context_group.h"
28 #include "gpu/command_buffer/service/gpu_preferences.h" 30 #include "gpu/command_buffer/service/gpu_preferences.h"
29 #include "gpu/config/gpu_driver_bug_workarounds.h" 31 #include "gpu/config/gpu_driver_bug_workarounds.h"
30 #include "gpu/gpu_export.h" 32 #include "gpu/gpu_export.h"
33 #include "gpu/ipc/service/image_transport_surface_delegate.h"
31 #include "ui/gfx/gpu_memory_buffer.h" 34 #include "ui/gfx/gpu_memory_buffer.h"
32 #include "ui/gfx/native_widget_types.h" 35 #include "ui/gfx/native_widget_types.h"
33 #include "ui/gl/gl_surface.h" 36 #include "ui/gl/gl_surface.h"
34 #include "ui/gl/gpu_preference.h" 37 #include "ui/gl/gpu_preference.h"
35 38
36 namespace base { 39 namespace base {
37 class SequenceChecker; 40 class SequenceChecker;
38 } 41 }
39 42
40 namespace gl { 43 namespace gl {
41 class GLContext; 44 class GLContext;
42 class GLShareGroup; 45 class GLShareGroup;
43 class GLSurface; 46 class GLSurface;
44 } 47 }
45 48
46 namespace gfx { 49 namespace gfx {
47 class Size; 50 class Size;
48 } 51 }
49 52
50 namespace gpu { 53 namespace gpu {
54
51 class SyncPointClient; 55 class SyncPointClient;
52 class SyncPointOrderData; 56 class SyncPointOrderData;
53 class SyncPointManager; 57 class SyncPointManager;
58 struct GpuProcessHostedCALayerTreeParamsMac;
54 59
55 namespace gles2 { 60 namespace gles2 {
56 struct ContextCreationAttribHelper; 61 struct ContextCreationAttribHelper;
57 class FramebufferCompletenessCache; 62 class FramebufferCompletenessCache;
58 class GLES2Decoder; 63 class GLES2Decoder;
59 class MailboxManager; 64 class MailboxManager;
60 class ProgramCache; 65 class ProgramCache;
61 class ShaderTranslatorCache; 66 class ShaderTranslatorCache;
62 } 67 }
63 68
64 class CommandBufferServiceBase; 69 class CommandBufferServiceBase;
65 class GpuMemoryBufferManager; 70 class GpuMemoryBufferManager;
66 class CommandExecutor; 71 class CommandExecutor;
67 class ImageFactory; 72 class ImageFactory;
68 class TransferBufferManagerInterface; 73 class TransferBufferManagerInterface;
69 74
70 // This class provides a thread-safe interface to the global GPU service (for 75 // This class provides a thread-safe interface to the global GPU service (for
71 // example GPU thread) when being run in single process mode. 76 // example GPU thread) when being run in single process mode.
72 // However, the behavior for accessing one context (i.e. one instance of this 77 // However, the behavior for accessing one context (i.e. one instance of this
73 // class) from different client threads is undefined. 78 // class) from different client threads is undefined.
74 class GPU_EXPORT InProcessCommandBuffer : public CommandBuffer, 79 class GPU_EXPORT InProcessCommandBuffer : public CommandBuffer,
75 public GpuControl { 80 public GpuControl,
81 public ImageTransportSurfaceDelegate {
76 public: 82 public:
77 class Service; 83 class Service;
78 explicit InProcessCommandBuffer(const scoped_refptr<Service>& service); 84 explicit InProcessCommandBuffer(const scoped_refptr<Service>& service);
79 ~InProcessCommandBuffer() override; 85 ~InProcessCommandBuffer() override;
80 86
81 // 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
82 // 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
83 // a new GLSurface. 89 // a new GLSurface.
84 bool Initialize(scoped_refptr<gl::GLSurface> surface, 90 bool Initialize(scoped_refptr<gl::GLSurface> surface,
85 bool is_offscreen, 91 bool is_offscreen,
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 CommandBufferId GetCommandBufferID() const override; 129 CommandBufferId GetCommandBufferID() const override;
124 int32_t GetExtraCommandBufferData() const override; 130 int32_t GetExtraCommandBufferData() const override;
125 uint64_t GenerateFenceSyncRelease() override; 131 uint64_t GenerateFenceSyncRelease() override;
126 bool IsFenceSyncRelease(uint64_t release) override; 132 bool IsFenceSyncRelease(uint64_t release) override;
127 bool IsFenceSyncFlushed(uint64_t release) override; 133 bool IsFenceSyncFlushed(uint64_t release) override;
128 bool IsFenceSyncFlushReceived(uint64_t release) override; 134 bool IsFenceSyncFlushReceived(uint64_t release) override;
129 void SignalSyncToken(const SyncToken& sync_token, 135 void SignalSyncToken(const SyncToken& sync_token,
130 const base::Closure& callback) override; 136 const base::Closure& callback) override;
131 bool CanWaitUnverifiedSyncToken(const SyncToken* sync_token) override; 137 bool CanWaitUnverifiedSyncToken(const SyncToken* sync_token) override;
132 138
139 // ImageTransportSurfaceDelegate implementation:
140 void DidSwapBuffersComplete(SwapBuffersCompleteParams params) override;
141 const gles2::FeatureInfo* GetFeatureInfo() const override;
142 void SetLatencyInfoCallback(const LatencyInfoCallback& callback) override;
143 void UpdateVSyncParameters(base::TimeTicks timebase,
144 base::TimeDelta interval) override;
145
146 using SwapBuffersCompletionCallback = base::Callback<void(
147 const std::vector<ui::LatencyInfo>& latency_info,
148 gfx::SwapResult result,
149 const gpu::GpuProcessHostedCALayerTreeParamsMac* params_mac)>;
150 void SetSwapBuffersCompletionCallback(
151 const SwapBuffersCompletionCallback& callback);
152
153 using UpdateVSyncParametersCallback =
154 base::Callback<void(base::TimeTicks timebase, base::TimeDelta interval)>;
155 void SetUpdateVSyncParametersCallback(
156 const UpdateVSyncParametersCallback& callback);
157
133 // The serializer interface to the GPU service (i.e. thread). 158 // The serializer interface to the GPU service (i.e. thread).
134 class Service { 159 class Service {
135 public: 160 public:
136 Service(); 161 Service();
137 Service(const gpu::GpuPreferences& gpu_preferences); 162 Service(const gpu::GpuPreferences& gpu_preferences);
138 virtual ~Service(); 163 virtual ~Service();
139 164
140 virtual void AddRef() const = 0; 165 virtual void AddRef() const = 0;
141 virtual void Release() const = 0; 166 virtual void Release() const = 0;
142 167
143 // Queues a task to run as soon as possible. 168 // Queues a task to run as soon as possible.
144 virtual void ScheduleTask(const base::Closure& task) = 0; 169 virtual void ScheduleTask(const base::Closure& task) = 0;
145 170
146 // Schedules |callback| to run at an appropriate time for performing delayed 171 // Schedules |callback| to run at an appropriate time for performing delayed
147 // work. 172 // work.
148 virtual void ScheduleDelayedWork(const base::Closure& task) = 0; 173 virtual void ScheduleDelayedWork(const base::Closure& task) = 0;
149 174
150 virtual bool UseVirtualizedGLContexts() = 0; 175 virtual bool UseVirtualizedGLContexts() = 0;
151 virtual scoped_refptr<gles2::ShaderTranslatorCache> 176 virtual scoped_refptr<gles2::ShaderTranslatorCache>
152 shader_translator_cache() = 0; 177 shader_translator_cache() = 0;
153 virtual scoped_refptr<gles2::FramebufferCompletenessCache> 178 virtual scoped_refptr<gles2::FramebufferCompletenessCache>
154 framebuffer_completeness_cache() = 0; 179 framebuffer_completeness_cache() = 0;
155 virtual SyncPointManager* sync_point_manager() = 0; 180 virtual SyncPointManager* sync_point_manager() = 0;
156 const GpuPreferences& gpu_preferences(); 181 const GpuPreferences& gpu_preferences();
157 const GpuDriverBugWorkarounds& gpu_driver_bug_workarounds(); 182 const GpuDriverBugWorkarounds& gpu_driver_bug_workarounds();
158 scoped_refptr<gl::GLShareGroup> share_group(); 183 // scoped_refptr<gl::GLShareGroup> share_group();
159 scoped_refptr<gles2::MailboxManager> mailbox_manager(); 184 scoped_refptr<gles2::MailboxManager> mailbox_manager();
160 gpu::gles2::ProgramCache* program_cache(); 185 gpu::gles2::ProgramCache* program_cache();
186 virtual const scoped_refptr<gl::GLShareGroup>& GetShareGroup() const = 0;
187 virtual bool BlockThreadOnWaitSyncToken() const = 0;
161 188
162 private: 189 protected:
163 const GpuPreferences gpu_preferences_; 190 const GpuPreferences gpu_preferences_;
164 const GpuDriverBugWorkarounds gpu_driver_bug_workarounds_; 191 const GpuDriverBugWorkarounds gpu_driver_bug_workarounds_;
165 scoped_refptr<gl::GLShareGroup> share_group_; 192 scoped_refptr<gl::GLShareGroup> share_group_;
166 scoped_refptr<gles2::MailboxManager> mailbox_manager_; 193 scoped_refptr<gles2::MailboxManager> mailbox_manager_;
167 std::unique_ptr<gpu::gles2::ProgramCache> program_cache_; 194 std::unique_ptr<gpu::gles2::ProgramCache> program_cache_;
168 }; 195 };
169 196
170 private: 197 private:
171 struct InitializeOnGpuThreadParams { 198 struct InitializeOnGpuThreadParams {
172 bool is_offscreen; 199 bool is_offscreen;
(...skipping 14 matching lines...) Expand all
187 window(window), 214 window(window),
188 attribs(attribs), 215 attribs(attribs),
189 capabilities(capabilities), 216 capabilities(capabilities),
190 context_group(share_group), 217 context_group(share_group),
191 image_factory(image_factory) {} 218 image_factory(image_factory) {}
192 }; 219 };
193 220
194 bool InitializeOnGpuThread(const InitializeOnGpuThreadParams& params); 221 bool InitializeOnGpuThread(const InitializeOnGpuThreadParams& params);
195 void Destroy(); 222 void Destroy();
196 bool DestroyOnGpuThread(); 223 bool DestroyOnGpuThread();
197 void FlushOnGpuThread(int32_t put_offset, uint32_t order_num); 224 void FlushOnGpuThread(int32_t put_offset);
198 void ScheduleDelayedWorkOnGpuThread(); 225 void ScheduleDelayedWorkOnGpuThread();
199 bool MakeCurrent(); 226 bool MakeCurrent();
200 base::Closure WrapCallback(const base::Closure& callback); 227 base::Closure WrapCallback(const base::Closure& callback);
201 State GetStateFast(); 228 State GetStateFast();
202 void QueueTask(const base::Closure& task) { service_->ScheduleTask(task); } 229 void QueueTask(bool out_of_order, const base::Closure& task);
230 void ProcessTasksOnGpuThread();
203 void CheckSequencedThread(); 231 void CheckSequencedThread();
204 void FenceSyncReleaseOnGpuThread(uint64_t release); 232 void FenceSyncReleaseOnGpuThread(uint64_t release);
205 bool WaitFenceSyncOnGpuThread(gpu::CommandBufferNamespace namespace_id, 233 bool WaitFenceSyncOnGpuThread(gpu::CommandBufferNamespace namespace_id,
206 gpu::CommandBufferId command_buffer_id, 234 gpu::CommandBufferId command_buffer_id,
207 uint64_t release); 235 uint64_t release);
236 void OnWaitFenceSyncCompleted(CommandBufferNamespace namespace_id,
237 CommandBufferId command_buffer_id,
238 uint64_t release);
208 void DescheduleUntilFinishedOnGpuThread(); 239 void DescheduleUntilFinishedOnGpuThread();
209 void RescheduleAfterFinishedOnGpuThread(); 240 void RescheduleAfterFinishedOnGpuThread();
210 void SignalSyncTokenOnGpuThread(const SyncToken& sync_token, 241 void SignalSyncTokenOnGpuThread(const SyncToken& sync_token,
211 const base::Closure& callback); 242 const base::Closure& callback);
212 void SignalQueryOnGpuThread(unsigned query_id, const base::Closure& callback); 243 void SignalQueryOnGpuThread(unsigned query_id, const base::Closure& callback);
213 void DestroyTransferBufferOnGpuThread(int32_t id); 244 void DestroyTransferBufferOnGpuThread(int32_t id);
214 void CreateImageOnGpuThread(int32_t id, 245 void CreateImageOnGpuThread(int32_t id,
215 const gfx::GpuMemoryBufferHandle& handle, 246 const gfx::GpuMemoryBufferHandle& handle,
216 const gfx::Size& size, 247 const gfx::Size& size,
217 gfx::BufferFormat format, 248 gfx::BufferFormat format,
218 uint32_t internalformat, 249 uint32_t internalformat,
219 uint32_t order_num, 250 // uint32_t order_num,
220 uint64_t fence_sync); 251 uint64_t fence_sync);
221 void DestroyImageOnGpuThread(int32_t id); 252 void DestroyImageOnGpuThread(int32_t id);
222 void SetGetBufferOnGpuThread(int32_t shm_id, base::WaitableEvent* completion); 253 void SetGetBufferOnGpuThread(int32_t shm_id, base::WaitableEvent* completion);
223 254
224 // Callbacks on the gpu thread. 255 // Callbacks on the gpu thread.
225 void OnContextLostOnGpuThread(); 256 void OnContextLostOnGpuThread();
226 void PumpCommandsOnGpuThread(); 257 void PumpCommandsOnGpuThread();
227 void PerformDelayedWorkOnGpuThread(); 258 void PerformDelayedWorkOnGpuThread();
228 // Callback implementations on the client thread. 259 // Callback implementations on the client thread.
229 void OnContextLost(); 260 void OnContextLost();
230 261
231 const CommandBufferId command_buffer_id_; 262 const CommandBufferId command_buffer_id_;
232 263
264 bool waiting_for_sync_point_ = false;
233 // Members accessed on the gpu thread (possibly with the exception of 265 // Members accessed on the gpu thread (possibly with the exception of
234 // creation): 266 // creation):
235 scoped_refptr<base::SingleThreadTaskRunner> origin_task_runner_; 267 scoped_refptr<base::SingleThreadTaskRunner> origin_task_runner_;
236 scoped_refptr<TransferBufferManagerInterface> transfer_buffer_manager_; 268 scoped_refptr<TransferBufferManagerInterface> transfer_buffer_manager_;
237 std::unique_ptr<CommandExecutor> executor_; 269 std::unique_ptr<CommandExecutor> executor_;
238 std::unique_ptr<gles2::GLES2Decoder> decoder_; 270 std::unique_ptr<gles2::GLES2Decoder> decoder_;
239 scoped_refptr<gl::GLContext> context_; 271 scoped_refptr<gl::GLContext> context_;
240 scoped_refptr<gl::GLSurface> surface_; 272 scoped_refptr<gl::GLSurface> surface_;
241 scoped_refptr<SyncPointOrderData> sync_point_order_data_; 273 scoped_refptr<SyncPointOrderData> sync_point_order_data_;
242 std::unique_ptr<SyncPointClient> sync_point_client_; 274 std::unique_ptr<SyncPointClient> sync_point_client_;
(...skipping 15 matching lines...) Expand all
258 uint64_t next_fence_sync_release_; 290 uint64_t next_fence_sync_release_;
259 uint64_t flushed_fence_sync_release_; 291 uint64_t flushed_fence_sync_release_;
260 292
261 // Accessed on both threads: 293 // Accessed on both threads:
262 std::unique_ptr<CommandBufferServiceBase> command_buffer_; 294 std::unique_ptr<CommandBufferServiceBase> command_buffer_;
263 base::Lock command_buffer_lock_; 295 base::Lock command_buffer_lock_;
264 base::WaitableEvent flush_event_; 296 base::WaitableEvent flush_event_;
265 scoped_refptr<Service> service_; 297 scoped_refptr<Service> service_;
266 State state_after_last_flush_; 298 State state_after_last_flush_;
267 base::Lock state_after_last_flush_lock_; 299 base::Lock state_after_last_flush_lock_;
300
301 // The group of contexts that share namespaces with this context.
302 scoped_refptr<gles2::ContextGroup> context_group_;
303
268 scoped_refptr<gl::GLShareGroup> gl_share_group_; 304 scoped_refptr<gl::GLShareGroup> gl_share_group_;
269 base::WaitableEvent fence_sync_wait_event_; 305 base::WaitableEvent fence_sync_wait_event_;
270 306
271 // Only used with explicit scheduling and the gpu thread is the same as 307 // Only used with explicit scheduling and the gpu thread is the same as
272 // the client thread. 308 // the client thread.
273 std::unique_ptr<base::SequenceChecker> sequence_checker_; 309 std::unique_ptr<base::SequenceChecker> sequence_checker_;
274 310
311 base::Lock task_queue_lock_;
312 struct GpuTask {
313 GpuTask(const base::Closure& callback, uint32_t order_number);
314 ~GpuTask();
315 base::Closure callback;
316 uint32_t order_number;
317 };
318 std::queue<std::unique_ptr<GpuTask>> task_queue_;
319
320 SwapBuffersCompletionCallback swap_buffers_completion_callback_;
321 UpdateVSyncParametersCallback update_vsync_parameters_completion_callback_;
322
275 base::WeakPtr<InProcessCommandBuffer> client_thread_weak_ptr_; 323 base::WeakPtr<InProcessCommandBuffer> client_thread_weak_ptr_;
276 base::WeakPtr<InProcessCommandBuffer> gpu_thread_weak_ptr_; 324 base::WeakPtr<InProcessCommandBuffer> gpu_thread_weak_ptr_;
277 base::WeakPtrFactory<InProcessCommandBuffer> client_thread_weak_ptr_factory_; 325 base::WeakPtrFactory<InProcessCommandBuffer> client_thread_weak_ptr_factory_;
278 base::WeakPtrFactory<InProcessCommandBuffer> gpu_thread_weak_ptr_factory_; 326 base::WeakPtrFactory<InProcessCommandBuffer> gpu_thread_weak_ptr_factory_;
279 327
280 DISALLOW_COPY_AND_ASSIGN(InProcessCommandBuffer); 328 DISALLOW_COPY_AND_ASSIGN(InProcessCommandBuffer);
281 }; 329 };
282 330
283 // Default Service class when a null service is used. 331 // Default Service class when a null service is used.
284 class GPU_EXPORT GpuInProcessThread 332 class GPU_EXPORT GpuInProcessThread
285 : public base::Thread, 333 : public base::Thread,
286 public NON_EXPORTED_BASE(InProcessCommandBuffer::Service), 334 public NON_EXPORTED_BASE(InProcessCommandBuffer::Service),
287 public base::RefCountedThreadSafe<GpuInProcessThread> { 335 public base::RefCountedThreadSafe<GpuInProcessThread> {
288 public: 336 public:
289 explicit GpuInProcessThread(SyncPointManager* sync_point_manager); 337 explicit GpuInProcessThread(SyncPointManager* sync_point_manager);
290 338
291 void AddRef() const override; 339 void AddRef() const override;
292 void Release() const override; 340 void Release() const override;
293 void ScheduleTask(const base::Closure& task) override; 341 void ScheduleTask(const base::Closure& task) override;
294 void ScheduleDelayedWork(const base::Closure& callback) override; 342 void ScheduleDelayedWork(const base::Closure& callback) override;
295 bool UseVirtualizedGLContexts() override; 343 bool UseVirtualizedGLContexts() override;
296 scoped_refptr<gles2::ShaderTranslatorCache> shader_translator_cache() 344 scoped_refptr<gles2::ShaderTranslatorCache> shader_translator_cache()
297 override; 345 override;
298 scoped_refptr<gles2::FramebufferCompletenessCache> 346 scoped_refptr<gles2::FramebufferCompletenessCache>
299 framebuffer_completeness_cache() override; 347 framebuffer_completeness_cache() override;
300 SyncPointManager* sync_point_manager() override; 348 SyncPointManager* sync_point_manager() override;
349 const scoped_refptr<gl::GLShareGroup>& GetShareGroup() const override;
350 bool BlockThreadOnWaitSyncToken() const override;
301 351
302 private: 352 private:
303 ~GpuInProcessThread() override; 353 ~GpuInProcessThread() override;
304 friend class base::RefCountedThreadSafe<GpuInProcessThread>; 354 friend class base::RefCountedThreadSafe<GpuInProcessThread>;
305 355
306 SyncPointManager* sync_point_manager_; // Non-owning. 356 SyncPointManager* sync_point_manager_; // Non-owning.
307 scoped_refptr<gpu::gles2::ShaderTranslatorCache> shader_translator_cache_; 357 scoped_refptr<gpu::gles2::ShaderTranslatorCache> shader_translator_cache_;
308 scoped_refptr<gpu::gles2::FramebufferCompletenessCache> 358 scoped_refptr<gpu::gles2::FramebufferCompletenessCache>
309 framebuffer_completeness_cache_; 359 framebuffer_completeness_cache_;
310 DISALLOW_COPY_AND_ASSIGN(GpuInProcessThread); 360 DISALLOW_COPY_AND_ASSIGN(GpuInProcessThread);
311 }; 361 };
312 362
313 } // namespace gpu 363 } // namespace gpu
314 364
315 #endif // GPU_IPC_IN_PROCESS_COMMAND_BUFFER_H_ 365 #endif // GPU_IPC_IN_PROCESS_COMMAND_BUFFER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698