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

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

Issue 665463003: gpu: Add CHROMIUM_image support to in-process command buffer. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@move-gpu-memory-buffer-factory-to-gpu-image-factory
Patch Set: make code more consistent with command buffer proxy Created 6 years, 2 months 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_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 <map> 8 #include <map>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/atomic_sequence_num.h"
11 #include "base/callback.h" 12 #include "base/callback.h"
12 #include "base/compiler_specific.h" 13 #include "base/compiler_specific.h"
13 #include "base/containers/scoped_ptr_hash_map.h" 14 #include "base/containers/scoped_ptr_hash_map.h"
14 #include "base/memory/ref_counted.h" 15 #include "base/memory/ref_counted.h"
15 #include "base/memory/scoped_ptr.h" 16 #include "base/memory/scoped_ptr.h"
16 #include "base/memory/weak_ptr.h" 17 #include "base/memory/weak_ptr.h"
17 #include "base/synchronization/lock.h" 18 #include "base/synchronization/lock.h"
18 #include "base/synchronization/waitable_event.h" 19 #include "base/synchronization/waitable_event.h"
19 #include "gpu/command_buffer/client/gpu_control.h" 20 #include "gpu/command_buffer/client/gpu_control.h"
20 #include "gpu/command_buffer/common/command_buffer.h" 21 #include "gpu/command_buffer/common/command_buffer.h"
21 #include "gpu/gpu_export.h" 22 #include "gpu/gpu_export.h"
23 #include "ui/gfx/gpu_memory_buffer.h"
22 #include "ui/gfx/native_widget_types.h" 24 #include "ui/gfx/native_widget_types.h"
23 #include "ui/gl/gl_surface.h" 25 #include "ui/gl/gl_surface.h"
24 #include "ui/gl/gpu_preference.h" 26 #include "ui/gl/gpu_preference.h"
25 27
26 namespace base { 28 namespace base {
27 class SequenceChecker; 29 class SequenceChecker;
28 } 30 }
29 31
30 namespace gfx { 32 namespace gfx {
31 class GLContext; 33 class GLContext;
(...skipping 13 matching lines...) Expand all
45 47
46 namespace gpu { 48 namespace gpu {
47 49
48 namespace gles2 { 50 namespace gles2 {
49 class GLES2Decoder; 51 class GLES2Decoder;
50 class MailboxManager; 52 class MailboxManager;
51 class ShaderTranslatorCache; 53 class ShaderTranslatorCache;
52 } 54 }
53 55
54 class CommandBufferServiceBase; 56 class CommandBufferServiceBase;
57 class GpuMemoryBufferManager;
55 class GpuScheduler; 58 class GpuScheduler;
59 class ImageFactory;
56 class TransferBufferManagerInterface; 60 class TransferBufferManagerInterface;
57 61
58 // This class provides a thread-safe interface to the global GPU service (for 62 // This class provides a thread-safe interface to the global GPU service (for
59 // example GPU thread) when being run in single process mode. 63 // example GPU thread) when being run in single process mode.
60 // However, the behavior for accessing one context (i.e. one instance of this 64 // However, the behavior for accessing one context (i.e. one instance of this
61 // class) from different client threads is undefined. 65 // class) from different client threads is undefined.
62 class GPU_EXPORT InProcessCommandBuffer : public CommandBuffer, 66 class GPU_EXPORT InProcessCommandBuffer : public CommandBuffer,
63 public GpuControl { 67 public GpuControl {
64 public: 68 public:
65 class Service; 69 class Service;
66 explicit InProcessCommandBuffer(const scoped_refptr<Service>& service); 70 explicit InProcessCommandBuffer(const scoped_refptr<Service>& service);
67 virtual ~InProcessCommandBuffer(); 71 virtual ~InProcessCommandBuffer();
68 72
69 // If |surface| is not NULL, use it directly; in this case, the command 73 // If |surface| is not NULL, use it directly; in this case, the command
70 // buffer gpu thread must be the same as the client thread. Otherwise create 74 // buffer gpu thread must be the same as the client thread. Otherwise create
71 // a new GLSurface. 75 // a new GLSurface.
72 bool Initialize(scoped_refptr<gfx::GLSurface> surface, 76 bool Initialize(scoped_refptr<gfx::GLSurface> surface,
73 bool is_offscreen, 77 bool is_offscreen,
74 gfx::AcceleratedWidget window, 78 gfx::AcceleratedWidget window,
75 const gfx::Size& size, 79 const gfx::Size& size,
76 const std::vector<int32>& attribs, 80 const std::vector<int32>& attribs,
77 gfx::GpuPreference gpu_preference, 81 gfx::GpuPreference gpu_preference,
78 const base::Closure& context_lost_callback, 82 const base::Closure& context_lost_callback,
79 InProcessCommandBuffer* share_group); 83 InProcessCommandBuffer* share_group,
84 GpuMemoryBufferManager* gpu_memory_buffer_manager,
85 ImageFactory* image_factory);
80 void Destroy(); 86 void Destroy();
81 87
82 // CommandBuffer implementation: 88 // CommandBuffer implementation:
83 virtual bool Initialize() override; 89 virtual bool Initialize() override;
84 virtual State GetLastState() override; 90 virtual State GetLastState() override;
85 virtual int32 GetLastToken() override; 91 virtual int32 GetLastToken() override;
86 virtual void Flush(int32 put_offset) override; 92 virtual void Flush(int32 put_offset) override;
87 virtual void WaitForTokenInRange(int32 start, int32 end) override; 93 virtual void WaitForTokenInRange(int32 start, int32 end) override;
88 virtual void WaitForGetOffsetInRange(int32 start, int32 end) override; 94 virtual void WaitForGetOffsetInRange(int32 start, int32 end) override;
89 virtual void SetGetBuffer(int32 shm_id) override; 95 virtual void SetGetBuffer(int32 shm_id) override;
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 151
146 private: 152 private:
147 struct InitializeOnGpuThreadParams { 153 struct InitializeOnGpuThreadParams {
148 bool is_offscreen; 154 bool is_offscreen;
149 gfx::AcceleratedWidget window; 155 gfx::AcceleratedWidget window;
150 const gfx::Size& size; 156 const gfx::Size& size;
151 const std::vector<int32>& attribs; 157 const std::vector<int32>& attribs;
152 gfx::GpuPreference gpu_preference; 158 gfx::GpuPreference gpu_preference;
153 gpu::Capabilities* capabilities; // Ouptut. 159 gpu::Capabilities* capabilities; // Ouptut.
154 InProcessCommandBuffer* context_group; 160 InProcessCommandBuffer* context_group;
161 ImageFactory* image_factory;
155 162
156 InitializeOnGpuThreadParams(bool is_offscreen, 163 InitializeOnGpuThreadParams(bool is_offscreen,
157 gfx::AcceleratedWidget window, 164 gfx::AcceleratedWidget window,
158 const gfx::Size& size, 165 const gfx::Size& size,
159 const std::vector<int32>& attribs, 166 const std::vector<int32>& attribs,
160 gfx::GpuPreference gpu_preference, 167 gfx::GpuPreference gpu_preference,
161 gpu::Capabilities* capabilities, 168 gpu::Capabilities* capabilities,
162 InProcessCommandBuffer* share_group) 169 InProcessCommandBuffer* share_group,
170 ImageFactory* image_factory)
163 : is_offscreen(is_offscreen), 171 : is_offscreen(is_offscreen),
164 window(window), 172 window(window),
165 size(size), 173 size(size),
166 attribs(attribs), 174 attribs(attribs),
167 gpu_preference(gpu_preference), 175 gpu_preference(gpu_preference),
168 capabilities(capabilities), 176 capabilities(capabilities),
169 context_group(share_group) {} 177 context_group(share_group),
178 image_factory(image_factory) {}
170 }; 179 };
171 180
172 bool InitializeOnGpuThread(const InitializeOnGpuThreadParams& params); 181 bool InitializeOnGpuThread(const InitializeOnGpuThreadParams& params);
173 bool DestroyOnGpuThread(); 182 bool DestroyOnGpuThread();
174 void FlushOnGpuThread(int32 put_offset); 183 void FlushOnGpuThread(int32 put_offset);
175 void ScheduleIdleWorkOnGpuThread(); 184 void ScheduleIdleWorkOnGpuThread();
176 uint32 CreateStreamTextureOnGpuThread(uint32 client_texture_id); 185 uint32 CreateStreamTextureOnGpuThread(uint32 client_texture_id);
177 bool MakeCurrent(); 186 bool MakeCurrent();
178 base::Closure WrapCallback(const base::Closure& callback); 187 base::Closure WrapCallback(const base::Closure& callback);
179 State GetStateFast(); 188 State GetStateFast();
180 void QueueTask(const base::Closure& task) { service_->ScheduleTask(task); } 189 void QueueTask(const base::Closure& task) { service_->ScheduleTask(task); }
181 void CheckSequencedThread(); 190 void CheckSequencedThread();
182 void RetireSyncPointOnGpuThread(uint32 sync_point); 191 void RetireSyncPointOnGpuThread(uint32 sync_point);
183 void SignalSyncPointOnGpuThread(uint32 sync_point, 192 void SignalSyncPointOnGpuThread(uint32 sync_point,
184 const base::Closure& callback); 193 const base::Closure& callback);
185 void SignalQueryOnGpuThread(unsigned query_id, const base::Closure& callback); 194 void SignalQueryOnGpuThread(unsigned query_id, const base::Closure& callback);
186 void DestroyTransferBufferOnGpuThread(int32 id); 195 void DestroyTransferBufferOnGpuThread(int32 id);
196 void CreateImageOnGpuThread(int32 id,
197 const gfx::GpuMemoryBufferHandle& handle,
198 const gfx::Size& size,
199 gfx::GpuMemoryBuffer::Format format,
200 uint32 internalformat);
201 void DestroyImageOnGpuThread(int32 id);
187 202
188 // Callbacks: 203 // Callbacks:
189 void OnContextLost(); 204 void OnContextLost();
190 void OnResizeView(gfx::Size size, float scale_factor); 205 void OnResizeView(gfx::Size size, float scale_factor);
191 bool GetBufferChanged(int32 transfer_buffer_id); 206 bool GetBufferChanged(int32 transfer_buffer_id);
192 void PumpCommands(); 207 void PumpCommands();
193 void PerformIdleWork(); 208 void PerformIdleWork();
194 209
195 static scoped_refptr<Service> GetDefaultService(); 210 static scoped_refptr<Service> GetDefaultService();
196 211
197 // Members accessed on the gpu thread (possibly with the exception of 212 // Members accessed on the gpu thread (possibly with the exception of
198 // creation): 213 // creation):
199 bool context_lost_; 214 bool context_lost_;
200 scoped_ptr<TransferBufferManagerInterface> transfer_buffer_manager_; 215 scoped_ptr<TransferBufferManagerInterface> transfer_buffer_manager_;
201 scoped_ptr<GpuScheduler> gpu_scheduler_; 216 scoped_ptr<GpuScheduler> gpu_scheduler_;
202 scoped_ptr<gles2::GLES2Decoder> decoder_; 217 scoped_ptr<gles2::GLES2Decoder> decoder_;
203 scoped_refptr<gfx::GLContext> context_; 218 scoped_refptr<gfx::GLContext> context_;
204 scoped_refptr<gfx::GLSurface> surface_; 219 scoped_refptr<gfx::GLSurface> surface_;
205 base::Closure context_lost_callback_; 220 base::Closure context_lost_callback_;
206 bool idle_work_pending_; // Used to throttle PerformIdleWork. 221 bool idle_work_pending_; // Used to throttle PerformIdleWork.
222 ImageFactory* image_factory_;
207 223
208 // Members accessed on the client thread: 224 // Members accessed on the client thread:
209 State last_state_; 225 State last_state_;
210 int32 last_put_offset_; 226 int32 last_put_offset_;
211 gpu::Capabilities capabilities_; 227 gpu::Capabilities capabilities_;
228 GpuMemoryBufferManager* gpu_memory_buffer_manager_;
229 base::AtomicSequenceNumber next_image_id_;
212 230
213 // Accessed on both threads: 231 // Accessed on both threads:
214 scoped_ptr<CommandBufferServiceBase> command_buffer_; 232 scoped_ptr<CommandBufferServiceBase> command_buffer_;
215 base::Lock command_buffer_lock_; 233 base::Lock command_buffer_lock_;
216 base::WaitableEvent flush_event_; 234 base::WaitableEvent flush_event_;
217 scoped_refptr<Service> service_; 235 scoped_refptr<Service> service_;
218 State state_after_last_flush_; 236 State state_after_last_flush_;
219 base::Lock state_after_last_flush_lock_; 237 base::Lock state_after_last_flush_lock_;
220 scoped_refptr<gfx::GLShareGroup> gl_share_group_; 238 scoped_refptr<gfx::GLShareGroup> gl_share_group_;
221 239
222 #if defined(OS_ANDROID) 240 #if defined(OS_ANDROID)
223 scoped_ptr<StreamTextureManagerInProcess> stream_texture_manager_; 241 scoped_ptr<StreamTextureManagerInProcess> stream_texture_manager_;
224 #endif 242 #endif
225 243
226 // Only used with explicit scheduling and the gpu thread is the same as 244 // Only used with explicit scheduling and the gpu thread is the same as
227 // the client thread. 245 // the client thread.
228 scoped_ptr<base::SequenceChecker> sequence_checker_; 246 scoped_ptr<base::SequenceChecker> sequence_checker_;
229 247
230 base::WeakPtr<InProcessCommandBuffer> gpu_thread_weak_ptr_; 248 base::WeakPtr<InProcessCommandBuffer> gpu_thread_weak_ptr_;
231 base::WeakPtrFactory<InProcessCommandBuffer> gpu_thread_weak_ptr_factory_; 249 base::WeakPtrFactory<InProcessCommandBuffer> gpu_thread_weak_ptr_factory_;
232 250
233 DISALLOW_COPY_AND_ASSIGN(InProcessCommandBuffer); 251 DISALLOW_COPY_AND_ASSIGN(InProcessCommandBuffer);
234 }; 252 };
235 253
236 } // namespace gpu 254 } // namespace gpu
237 255
238 #endif // GPU_COMMAND_BUFFER_SERVICE_IN_PROCESS_COMMAND_BUFFER_H_ 256 #endif // GPU_COMMAND_BUFFER_SERVICE_IN_PROCESS_COMMAND_BUFFER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698