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

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 explicit InProcessCommandBuffer(const scoped_refptr<Service>& service);
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 {
133 public: 122 public:
134 virtual ~SchedulerClient() {} 123 Service();
124 virtual ~Service();
135 125
136 // Queues a task to run as soon as possible. 126 virtual void AddRef() const = 0;
137 virtual void QueueTask(const base::Closure& task) = 0; 127 virtual void Release() const = 0;
138 128
139 // Schedules |callback| to run at an appropriate time for performing idle 129 // Queues a task to run as soon as possible.
140 // work. 130 virtual void ScheduleTask(const base::Closure& task) = 0;
141 virtual void ScheduleIdleWork(const base::Closure& task) = 0; 131
132 // Schedules |callback| to run at an appropriate time for performing idle
133 // work.
134 virtual void ScheduleIdleWork(const base::Closure& task) = 0;
135
136 virtual bool UseVirtualizedGLContexts() = 0;
142 }; 137 };
143 138
144 #if defined(OS_ANDROID) 139 #if defined(OS_ANDROID)
145 scoped_refptr<gfx::SurfaceTexture> GetSurfaceTexture( 140 scoped_refptr<gfx::SurfaceTexture> GetSurfaceTexture(
146 uint32 stream_id); 141 uint32 stream_id);
147 #endif 142 #endif
148 143
149 private: 144 private:
150 struct InitializeOnGpuThreadParams { 145 struct InitializeOnGpuThreadParams {
151 bool is_offscreen; 146 bool is_offscreen;
(...skipping 20 matching lines...) Expand all
172 context_group(share_group) {} 167 context_group(share_group) {}
173 }; 168 };
174 169
175 bool InitializeOnGpuThread(const InitializeOnGpuThreadParams& params); 170 bool InitializeOnGpuThread(const InitializeOnGpuThreadParams& params);
176 bool DestroyOnGpuThread(); 171 bool DestroyOnGpuThread();
177 void FlushOnGpuThread(int32 put_offset); 172 void FlushOnGpuThread(int32 put_offset);
178 uint32 CreateStreamTextureOnGpuThread(uint32 client_texture_id); 173 uint32 CreateStreamTextureOnGpuThread(uint32 client_texture_id);
179 bool MakeCurrent(); 174 bool MakeCurrent();
180 base::Closure WrapCallback(const base::Closure& callback); 175 base::Closure WrapCallback(const base::Closure& callback);
181 State GetStateFast(); 176 State GetStateFast();
182 void QueueTask(const base::Closure& task) { queue_->QueueTask(task); } 177 void QueueTask(const base::Closure& task) { service_->ScheduleTask(task); }
183 void CheckSequencedThread(); 178 void CheckSequencedThread();
184 179
185 // Callbacks: 180 // Callbacks:
186 void OnContextLost(); 181 void OnContextLost();
187 void OnResizeView(gfx::Size size, float scale_factor); 182 void OnResizeView(gfx::Size size, float scale_factor);
188 bool GetBufferChanged(int32 transfer_buffer_id); 183 bool GetBufferChanged(int32 transfer_buffer_id);
189 void PumpCommands(); 184 void PumpCommands();
190 void ScheduleMoreIdleWork(); 185 void ScheduleMoreIdleWork();
191 186
187 static scoped_refptr<Service> GetDefaultService();
188
192 // Members accessed on the gpu thread (possibly with the exception of 189 // Members accessed on the gpu thread (possibly with the exception of
193 // creation): 190 // creation):
194 bool context_lost_; 191 bool context_lost_;
195 scoped_ptr<TransferBufferManagerInterface> transfer_buffer_manager_; 192 scoped_ptr<TransferBufferManagerInterface> transfer_buffer_manager_;
196 scoped_ptr<GpuScheduler> gpu_scheduler_; 193 scoped_ptr<GpuScheduler> gpu_scheduler_;
197 scoped_ptr<gles2::GLES2Decoder> decoder_; 194 scoped_ptr<gles2::GLES2Decoder> decoder_;
198 scoped_refptr<gfx::GLContext> context_; 195 scoped_refptr<gfx::GLContext> context_;
199 scoped_refptr<gfx::GLSurface> surface_; 196 scoped_refptr<gfx::GLSurface> surface_;
200 base::Closure context_lost_callback_; 197 base::Closure context_lost_callback_;
201 198
202 // Members accessed on the client thread: 199 // Members accessed on the client thread:
203 State last_state_; 200 State last_state_;
204 int32 last_put_offset_; 201 int32 last_put_offset_;
205 gpu::Capabilities capabilities_; 202 gpu::Capabilities capabilities_;
206 203
207 // Accessed on both threads: 204 // Accessed on both threads:
208 scoped_ptr<CommandBuffer> command_buffer_; 205 scoped_ptr<CommandBuffer> command_buffer_;
209 base::Lock command_buffer_lock_; 206 base::Lock command_buffer_lock_;
210 base::WaitableEvent flush_event_; 207 base::WaitableEvent flush_event_;
211 scoped_ptr<SchedulerClient> queue_; 208 scoped_refptr<Service> service_;
212 State state_after_last_flush_; 209 State state_after_last_flush_;
213 base::Lock state_after_last_flush_lock_; 210 base::Lock state_after_last_flush_lock_;
214 scoped_ptr<GpuControl> gpu_control_; 211 scoped_ptr<GpuControl> gpu_control_;
215 scoped_refptr<gfx::GLShareGroup> gl_share_group_; 212 scoped_refptr<gfx::GLShareGroup> gl_share_group_;
216 213
217 #if defined(OS_ANDROID) 214 #if defined(OS_ANDROID)
218 scoped_ptr<StreamTextureManagerInProcess> stream_texture_manager_; 215 scoped_ptr<StreamTextureManagerInProcess> stream_texture_manager_;
219 #endif 216 #endif
220 217
221 // Only used with explicit scheduling and the gpu thread is the same as 218 // Only used with explicit scheduling and the gpu thread is the same as
222 // the client thread. 219 // the client thread.
223 scoped_ptr<base::SequenceChecker> sequence_checker_; 220 scoped_ptr<base::SequenceChecker> sequence_checker_;
224 221
225 base::WeakPtr<InProcessCommandBuffer> gpu_thread_weak_ptr_; 222 base::WeakPtr<InProcessCommandBuffer> gpu_thread_weak_ptr_;
226 base::WeakPtrFactory<InProcessCommandBuffer> gpu_thread_weak_ptr_factory_; 223 base::WeakPtrFactory<InProcessCommandBuffer> gpu_thread_weak_ptr_factory_;
227 224
228 DISALLOW_COPY_AND_ASSIGN(InProcessCommandBuffer); 225 DISALLOW_COPY_AND_ASSIGN(InProcessCommandBuffer);
229 }; 226 };
230 227
231 } // namespace gpu 228 } // namespace gpu
232 229
233 #endif // GPU_COMMAND_BUFFER_SERVICE_IN_PROCESS_COMMAND_BUFFER_H_ 230 #endif // GPU_COMMAND_BUFFER_SERVICE_IN_PROCESS_COMMAND_BUFFER_H_
OLDNEW
« no previous file with comments | « gpu/command_buffer/client/gl_in_process_context.cc ('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