Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 51 class GpuScheduler; | 51 class GpuScheduler; |
| 52 class TransferBufferManagerInterface; | 52 class TransferBufferManagerInterface; |
| 53 | 53 |
| 54 // This class provides a thread-safe interface to the global GPU service (for | 54 // This class provides a thread-safe interface to the global GPU service (for |
| 55 // example GPU thread) when being run in single process mode. | 55 // example GPU thread) when being run in single process mode. |
| 56 // However, the behavior for accessing one context (i.e. one instance of this | 56 // However, the behavior for accessing one context (i.e. one instance of this |
| 57 // class) from different client threads is undefined. | 57 // class) from different client threads is undefined. |
| 58 class GPU_EXPORT InProcessCommandBuffer : public CommandBuffer, | 58 class GPU_EXPORT InProcessCommandBuffer : public CommandBuffer, |
| 59 public GpuControl { | 59 public GpuControl { |
| 60 public: | 60 public: |
| 61 InProcessCommandBuffer(); | 61 class Service; |
| 62 InProcessCommandBuffer(const scoped_refptr<Service>& service); | |
| 62 virtual ~InProcessCommandBuffer(); | 63 virtual ~InProcessCommandBuffer(); |
| 63 | 64 |
| 64 // Used to override the GPU thread with explicit scheduling. | |
| 65 // (By default an internal GPU thread will be spawned to handle all GL work | |
| 66 // and the two functions are unused.) | |
| 67 // The callback will be called from different client threads. After the | |
| 68 // callback is issued, the client is expected to eventually call | |
| 69 // ProcessGpuWorkOnCurrentThread(). The latter cannot be called from different | |
| 70 // threads. | |
| 71 // The callback needs to be set before any context is created. | |
| 72 static void SetScheduleCallback(const base::Closure& callback); | |
| 73 static void ProcessGpuWorkOnCurrentThread(); | |
| 74 | |
| 75 static void EnableVirtualizedContext(); | 65 static void EnableVirtualizedContext(); |
| 76 static void SetGpuMemoryBufferFactory(GpuMemoryBufferFactory* factory); | 66 static void SetGpuMemoryBufferFactory(GpuMemoryBufferFactory* factory); |
| 77 | 67 |
| 78 // 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 |
| 79 // 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 |
| 80 // a new GLSurface. | 70 // a new GLSurface. |
| 81 bool Initialize(scoped_refptr<gfx::GLSurface> surface, | 71 bool Initialize(scoped_refptr<gfx::GLSurface> surface, |
| 82 bool is_offscreen, | 72 bool is_offscreen, |
| 83 bool share_resources, | 73 bool share_resources, |
| 84 gfx::AcceleratedWidget window, | 74 gfx::AcceleratedWidget window, |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 122 const base::Closure& callback) OVERRIDE; | 112 const base::Closure& callback) OVERRIDE; |
| 123 virtual void SignalQuery(uint32 query, | 113 virtual void SignalQuery(uint32 query, |
| 124 const base::Closure& callback) OVERRIDE; | 114 const base::Closure& callback) OVERRIDE; |
| 125 virtual void SetSurfaceVisible(bool visible) OVERRIDE; | 115 virtual void SetSurfaceVisible(bool visible) OVERRIDE; |
| 126 virtual void SendManagedMemoryStats(const gpu::ManagedMemoryStats& stats) | 116 virtual void SendManagedMemoryStats(const gpu::ManagedMemoryStats& stats) |
| 127 OVERRIDE; | 117 OVERRIDE; |
| 128 virtual void Echo(const base::Closure& callback) OVERRIDE; | 118 virtual void Echo(const base::Closure& callback) OVERRIDE; |
| 129 virtual uint32 CreateStreamTexture(uint32 texture_id) OVERRIDE; | 119 virtual uint32 CreateStreamTexture(uint32 texture_id) OVERRIDE; |
| 130 | 120 |
| 131 // The serializer interface to the GPU service (i.e. thread). | 121 // The serializer interface to the GPU service (i.e. thread). |
| 132 class SchedulerClient { | 122 class Service : public base::RefCountedThreadSafe<Service> { |
| 133 public: | 123 public: |
| 134 virtual ~SchedulerClient() {} | 124 // Queues a task to run as soon as possible. |
| 125 virtual void ScheduleTask(const base::Closure& task) = 0; | |
| 135 | 126 |
| 136 // Queues a task to run as soon as possible. | 127 // Schedules |callback| to run at an appropriate time for performing idle |
| 137 virtual void QueueTask(const base::Closure& task) = 0; | 128 // work. |
| 129 virtual void ScheduleIdleWork(const base::Closure& task) = 0; | |
| 138 | 130 |
| 139 // Schedules |callback| to run at an appropriate time for performing idle | 131 InProcessCommandBuffer* GetShareGroup(unsigned int group_id); |
| 140 // work. | 132 void AddToShareGroup(InProcessCommandBuffer* context); |
| 141 virtual void ScheduleIdleWork(const base::Closure& task) = 0; | 133 void RemoveFromShareGroup(InProcessCommandBuffer* context); |
| 134 void MarkShareGroupAsLost(); | |
| 135 | |
| 136 protected: | |
| 137 Service(); | |
| 138 virtual ~Service(); | |
| 139 friend class base::RefCountedThreadSafe<Service>; | |
| 140 | |
| 141 private: | |
| 142 base::SequenceChecker share_group_sequence_checker_; | |
|
boliu
2014/02/08 18:55:54
I think this needs can be generalized for all gpu
no sievers
2014/02/12 03:09:15
This is obsolete now.
| |
| 143 std::set<InProcessCommandBuffer*> all_shared_contexts_; | |
| 142 }; | 144 }; |
| 143 | 145 |
| 144 #if defined(OS_ANDROID) | 146 #if defined(OS_ANDROID) |
| 145 scoped_refptr<gfx::SurfaceTexture> GetSurfaceTexture( | 147 scoped_refptr<gfx::SurfaceTexture> GetSurfaceTexture( |
| 146 uint32 stream_id); | 148 uint32 stream_id); |
| 147 #endif | 149 #endif |
| 148 | 150 |
| 149 private: | 151 private: |
| 150 struct InitializeOnGpuThreadParams { | 152 struct InitializeOnGpuThreadParams { |
| 151 bool is_offscreen; | 153 bool is_offscreen; |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 170 }; | 172 }; |
| 171 | 173 |
| 172 bool InitializeOnGpuThread(const InitializeOnGpuThreadParams& params); | 174 bool InitializeOnGpuThread(const InitializeOnGpuThreadParams& params); |
| 173 bool DestroyOnGpuThread(); | 175 bool DestroyOnGpuThread(); |
| 174 void FlushOnGpuThread(int32 put_offset); | 176 void FlushOnGpuThread(int32 put_offset); |
| 175 uint32 CreateStreamTextureOnGpuThread(uint32 client_texture_id); | 177 uint32 CreateStreamTextureOnGpuThread(uint32 client_texture_id); |
| 176 bool MakeCurrent(); | 178 bool MakeCurrent(); |
| 177 bool IsContextLost(); | 179 bool IsContextLost(); |
| 178 base::Closure WrapCallback(const base::Closure& callback); | 180 base::Closure WrapCallback(const base::Closure& callback); |
| 179 State GetStateFast(); | 181 State GetStateFast(); |
| 180 void QueueTask(const base::Closure& task) { queue_->QueueTask(task); } | 182 void QueueTask(const base::Closure& task) { queue_->ScheduleTask(task); } |
| 181 void CheckSequencedThread(); | 183 void CheckSequencedThread(); |
| 182 | 184 |
| 183 // Callbacks: | 185 // Callbacks: |
| 184 void OnContextLost(); | 186 void OnContextLost(); |
| 185 void OnResizeView(gfx::Size size, float scale_factor); | 187 void OnResizeView(gfx::Size size, float scale_factor); |
| 186 bool GetBufferChanged(int32 transfer_buffer_id); | 188 bool GetBufferChanged(int32 transfer_buffer_id); |
| 187 void PumpCommands(); | 189 void PumpCommands(); |
| 188 void ScheduleMoreIdleWork(); | 190 void ScheduleMoreIdleWork(); |
| 189 | 191 |
| 192 static scoped_refptr<Service> GetDefaultService(); | |
| 193 | |
| 190 // Members accessed on the gpu thread (possibly with the exception of | 194 // Members accessed on the gpu thread (possibly with the exception of |
| 191 // creation): | 195 // creation): |
| 192 bool context_lost_; | 196 bool context_lost_; |
| 193 bool share_resources_; | 197 bool share_resources_; |
| 194 scoped_ptr<TransferBufferManagerInterface> transfer_buffer_manager_; | 198 scoped_ptr<TransferBufferManagerInterface> transfer_buffer_manager_; |
| 195 scoped_ptr<GpuScheduler> gpu_scheduler_; | 199 scoped_ptr<GpuScheduler> gpu_scheduler_; |
| 196 scoped_ptr<gles2::GLES2Decoder> decoder_; | 200 scoped_ptr<gles2::GLES2Decoder> decoder_; |
| 197 scoped_refptr<gfx::GLContext> context_; | 201 scoped_refptr<gfx::GLContext> context_; |
| 198 scoped_refptr<gfx::GLSurface> surface_; | 202 scoped_refptr<gfx::GLSurface> surface_; |
| 199 base::Closure context_lost_callback_; | 203 base::Closure context_lost_callback_; |
| 200 unsigned int share_group_id_; | 204 unsigned int share_group_id_; |
| 201 | 205 |
| 202 // Members accessed on the client thread: | 206 // Members accessed on the client thread: |
| 203 State last_state_; | 207 State last_state_; |
| 204 int32 last_put_offset_; | 208 int32 last_put_offset_; |
| 205 gpu::Capabilities capabilities_; | 209 gpu::Capabilities capabilities_; |
| 206 | 210 |
| 207 // Accessed on both threads: | 211 // Accessed on both threads: |
| 208 scoped_ptr<CommandBuffer> command_buffer_; | 212 scoped_ptr<CommandBuffer> command_buffer_; |
| 209 base::Lock command_buffer_lock_; | 213 base::Lock command_buffer_lock_; |
| 210 base::WaitableEvent flush_event_; | 214 base::WaitableEvent flush_event_; |
| 211 scoped_ptr<SchedulerClient> queue_; | 215 scoped_refptr<Service> queue_; |
| 212 State state_after_last_flush_; | 216 State state_after_last_flush_; |
| 213 base::Lock state_after_last_flush_lock_; | 217 base::Lock state_after_last_flush_lock_; |
| 214 scoped_ptr<GpuControl> gpu_control_; | 218 scoped_ptr<GpuControl> gpu_control_; |
| 215 | 219 |
| 216 #if defined(OS_ANDROID) | 220 #if defined(OS_ANDROID) |
| 217 scoped_ptr<StreamTextureManagerInProcess> stream_texture_manager_; | 221 scoped_ptr<StreamTextureManagerInProcess> stream_texture_manager_; |
| 218 #endif | 222 #endif |
| 219 | 223 |
| 220 // Only used with explicit scheduling and the gpu thread is the same as | 224 // Only used with explicit scheduling and the gpu thread is the same as |
| 221 // the client thread. | 225 // the client thread. |
| 222 scoped_ptr<base::SequenceChecker> sequence_checker_; | 226 scoped_ptr<base::SequenceChecker> sequence_checker_; |
| 223 | 227 |
| 224 base::WeakPtr<InProcessCommandBuffer> gpu_thread_weak_ptr_; | 228 base::WeakPtr<InProcessCommandBuffer> gpu_thread_weak_ptr_; |
| 225 base::WeakPtrFactory<InProcessCommandBuffer> gpu_thread_weak_ptr_factory_; | 229 base::WeakPtrFactory<InProcessCommandBuffer> gpu_thread_weak_ptr_factory_; |
| 226 | 230 |
| 227 DISALLOW_COPY_AND_ASSIGN(InProcessCommandBuffer); | 231 DISALLOW_COPY_AND_ASSIGN(InProcessCommandBuffer); |
| 228 }; | 232 }; |
| 229 | 233 |
| 230 } // namespace gpu | 234 } // namespace gpu |
| 231 | 235 |
| 232 #endif // GPU_COMMAND_BUFFER_SERVICE_IN_PROCESS_COMMAND_BUFFER_H_ | 236 #endif // GPU_COMMAND_BUFFER_SERVICE_IN_PROCESS_COMMAND_BUFFER_H_ |
| OLD | NEW |