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

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

Issue 143023005: Support multiple service instances with GLInProcessContext (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 10 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 | Annotate | Revision Log
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 <vector> 8 #include <vector>
9 9
10 #include "base/callback.h" 10 #include "base/callback.h"
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 class GpuScheduler; 52 class GpuScheduler;
53 class TransferBufferManagerInterface; 53 class TransferBufferManagerInterface;
54 54
55 // This class provides a thread-safe interface to the global GPU service (for 55 // This class provides a thread-safe interface to the global GPU service (for
56 // example GPU thread) when being run in single process mode. 56 // example GPU thread) when being run in single process mode.
57 // However, the behavior for accessing one context (i.e. one instance of this 57 // However, the behavior for accessing one context (i.e. one instance of this
58 // class) from different client threads is undefined. 58 // class) from different client threads is undefined.
59 class GPU_EXPORT InProcessCommandBuffer : public CommandBuffer, 59 class GPU_EXPORT InProcessCommandBuffer : public CommandBuffer,
60 public GpuControl { 60 public GpuControl {
61 public: 61 public:
62 InProcessCommandBuffer(); 62 class Service;
63 InProcessCommandBuffer(const scoped_refptr<Service>& service);
piman 2014/02/12 04:10:42 nit: explicit
no sievers 2014/02/12 22:31:29 Done.
63 virtual ~InProcessCommandBuffer(); 64 virtual ~InProcessCommandBuffer();
64 65
65 // Used to override the GPU thread with explicit scheduling.
66 // (By default an internal GPU thread will be spawned to handle all GL work
67 // and the two functions are unused.)
68 // The callback will be called from different client threads. After the
69 // callback is issued, the client is expected to eventually call
70 // ProcessGpuWorkOnCurrentThread(). The latter cannot be called from different
71 // threads.
72 // The callback needs to be set before any context is created.
73 static void SetScheduleCallback(const base::Closure& callback);
74 static void ProcessGpuWorkOnCurrentThread();
75
76 static void EnableVirtualizedContext();
77 static void SetGpuMemoryBufferFactory(GpuMemoryBufferFactory* factory); 66 static void SetGpuMemoryBufferFactory(GpuMemoryBufferFactory* factory);
78 67
79 // If |surface| is not NULL, use it directly; in this case, the command 68 // If |surface| is not NULL, use it directly; in this case, the command
80 // buffer gpu thread must be the same as the client thread. Otherwise create 69 // buffer gpu thread must be the same as the client thread. Otherwise create
81 // a new GLSurface. 70 // a new GLSurface.
82 bool Initialize(scoped_refptr<gfx::GLSurface> surface, 71 bool Initialize(scoped_refptr<gfx::GLSurface> surface,
83 bool is_offscreen, 72 bool is_offscreen,
84 gfx::AcceleratedWidget window, 73 gfx::AcceleratedWidget window,
85 const gfx::Size& size, 74 const gfx::Size& size,
86 const std::vector<int32>& attribs, 75 const std::vector<int32>& attribs,
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 const base::Closure& callback) OVERRIDE; 111 const base::Closure& callback) OVERRIDE;
123 virtual void SignalQuery(uint32 query, 112 virtual void SignalQuery(uint32 query,
124 const base::Closure& callback) OVERRIDE; 113 const base::Closure& callback) OVERRIDE;
125 virtual void SetSurfaceVisible(bool visible) OVERRIDE; 114 virtual void SetSurfaceVisible(bool visible) OVERRIDE;
126 virtual void SendManagedMemoryStats(const gpu::ManagedMemoryStats& stats) 115 virtual void SendManagedMemoryStats(const gpu::ManagedMemoryStats& stats)
127 OVERRIDE; 116 OVERRIDE;
128 virtual void Echo(const base::Closure& callback) OVERRIDE; 117 virtual void Echo(const base::Closure& callback) OVERRIDE;
129 virtual uint32 CreateStreamTexture(uint32 texture_id) OVERRIDE; 118 virtual uint32 CreateStreamTexture(uint32 texture_id) OVERRIDE;
130 119
131 // The serializer interface to the GPU service (i.e. thread). 120 // The serializer interface to the GPU service (i.e. thread).
132 class SchedulerClient { 121 class Service : public base::RefCountedThreadSafe<Service> {
piman 2014/02/12 04:10:42 It isn't a great pattern to have an interface impl
no sievers 2014/02/12 22:31:29 Done.
133 public: 122 public:
134 virtual ~SchedulerClient() {} 123 // Queues a task to run as soon as possible.
124 virtual void ScheduleTask(const base::Closure& task) = 0;
135 125
136 // Queues a task to run as soon as possible. 126 // Schedules |callback| to run at an appropriate time for performing idle
137 virtual void QueueTask(const base::Closure& task) = 0; 127 // work.
128 virtual void ScheduleIdleWork(const base::Closure& task) = 0;
138 129
139 // Schedules |callback| to run at an appropriate time for performing idle 130 virtual bool UseVirtualizedGLContexts() = 0;
140 // work. 131
141 virtual void ScheduleIdleWork(const base::Closure& task) = 0; 132 protected:
133 Service();
134 virtual ~Service();
135 friend class base::RefCountedThreadSafe<Service>;
142 }; 136 };
143 137
144 #if defined(OS_ANDROID) 138 #if defined(OS_ANDROID)
145 scoped_refptr<gfx::SurfaceTexture> GetSurfaceTexture( 139 scoped_refptr<gfx::SurfaceTexture> GetSurfaceTexture(
146 uint32 stream_id); 140 uint32 stream_id);
147 #endif 141 #endif
148 142
149 private: 143 private:
150 struct InitializeOnGpuThreadParams { 144 struct InitializeOnGpuThreadParams {
151 bool is_offscreen; 145 bool is_offscreen;
(...skipping 20 matching lines...) Expand all
172 context_group(share_group) {} 166 context_group(share_group) {}
173 }; 167 };
174 168
175 bool InitializeOnGpuThread(const InitializeOnGpuThreadParams& params); 169 bool InitializeOnGpuThread(const InitializeOnGpuThreadParams& params);
176 bool DestroyOnGpuThread(); 170 bool DestroyOnGpuThread();
177 void FlushOnGpuThread(int32 put_offset); 171 void FlushOnGpuThread(int32 put_offset);
178 uint32 CreateStreamTextureOnGpuThread(uint32 client_texture_id); 172 uint32 CreateStreamTextureOnGpuThread(uint32 client_texture_id);
179 bool MakeCurrent(); 173 bool MakeCurrent();
180 base::Closure WrapCallback(const base::Closure& callback); 174 base::Closure WrapCallback(const base::Closure& callback);
181 State GetStateFast(); 175 State GetStateFast();
182 void QueueTask(const base::Closure& task) { queue_->QueueTask(task); } 176 void QueueTask(const base::Closure& task) { queue_->ScheduleTask(task); }
183 void CheckSequencedThread(); 177 void CheckSequencedThread();
184 178
185 // Callbacks: 179 // Callbacks:
186 void OnContextLost(); 180 void OnContextLost();
187 void OnResizeView(gfx::Size size, float scale_factor); 181 void OnResizeView(gfx::Size size, float scale_factor);
188 bool GetBufferChanged(int32 transfer_buffer_id); 182 bool GetBufferChanged(int32 transfer_buffer_id);
189 void PumpCommands(); 183 void PumpCommands();
190 void ScheduleMoreIdleWork(); 184 void ScheduleMoreIdleWork();
191 185
186 static scoped_refptr<Service> GetDefaultService();
187
192 // Members accessed on the gpu thread (possibly with the exception of 188 // Members accessed on the gpu thread (possibly with the exception of
193 // creation): 189 // creation):
194 bool context_lost_; 190 bool context_lost_;
195 scoped_ptr<TransferBufferManagerInterface> transfer_buffer_manager_; 191 scoped_ptr<TransferBufferManagerInterface> transfer_buffer_manager_;
196 scoped_ptr<GpuScheduler> gpu_scheduler_; 192 scoped_ptr<GpuScheduler> gpu_scheduler_;
197 scoped_ptr<gles2::GLES2Decoder> decoder_; 193 scoped_ptr<gles2::GLES2Decoder> decoder_;
198 scoped_refptr<gfx::GLContext> context_; 194 scoped_refptr<gfx::GLContext> context_;
199 scoped_refptr<gfx::GLSurface> surface_; 195 scoped_refptr<gfx::GLSurface> surface_;
200 base::Closure context_lost_callback_; 196 base::Closure context_lost_callback_;
201 197
202 // Members accessed on the client thread: 198 // Members accessed on the client thread:
203 State last_state_; 199 State last_state_;
204 int32 last_put_offset_; 200 int32 last_put_offset_;
205 gpu::Capabilities capabilities_; 201 gpu::Capabilities capabilities_;
206 202
207 // Accessed on both threads: 203 // Accessed on both threads:
208 scoped_ptr<CommandBuffer> command_buffer_; 204 scoped_ptr<CommandBuffer> command_buffer_;
209 base::Lock command_buffer_lock_; 205 base::Lock command_buffer_lock_;
210 base::WaitableEvent flush_event_; 206 base::WaitableEvent flush_event_;
211 scoped_ptr<SchedulerClient> queue_; 207 scoped_refptr<Service> queue_;
piman 2014/02/12 04:10:42 nit: s/queue_/service_/
no sievers 2014/02/12 22:31:29 Done.
212 State state_after_last_flush_; 208 State state_after_last_flush_;
213 base::Lock state_after_last_flush_lock_; 209 base::Lock state_after_last_flush_lock_;
214 scoped_ptr<GpuControl> gpu_control_; 210 scoped_ptr<GpuControl> gpu_control_;
215 scoped_refptr<gfx::GLShareGroup> gl_share_group_; 211 scoped_refptr<gfx::GLShareGroup> gl_share_group_;
216 212
217 #if defined(OS_ANDROID) 213 #if defined(OS_ANDROID)
218 scoped_ptr<StreamTextureManagerInProcess> stream_texture_manager_; 214 scoped_ptr<StreamTextureManagerInProcess> stream_texture_manager_;
219 #endif 215 #endif
220 216
221 // Only used with explicit scheduling and the gpu thread is the same as 217 // Only used with explicit scheduling and the gpu thread is the same as
222 // the client thread. 218 // the client thread.
223 scoped_ptr<base::SequenceChecker> sequence_checker_; 219 scoped_ptr<base::SequenceChecker> sequence_checker_;
224 220
225 base::WeakPtr<InProcessCommandBuffer> gpu_thread_weak_ptr_; 221 base::WeakPtr<InProcessCommandBuffer> gpu_thread_weak_ptr_;
226 base::WeakPtrFactory<InProcessCommandBuffer> gpu_thread_weak_ptr_factory_; 222 base::WeakPtrFactory<InProcessCommandBuffer> gpu_thread_weak_ptr_factory_;
227 223
228 DISALLOW_COPY_AND_ASSIGN(InProcessCommandBuffer); 224 DISALLOW_COPY_AND_ASSIGN(InProcessCommandBuffer);
229 }; 225 };
230 226
231 } // namespace gpu 227 } // namespace gpu
232 228
233 #endif // GPU_COMMAND_BUFFER_SERVICE_IN_PROCESS_COMMAND_BUFFER_H_ 229 #endif // GPU_COMMAND_BUFFER_SERVICE_IN_PROCESS_COMMAND_BUFFER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698