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" |
11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
14 #include "base/synchronization/lock.h" | 14 #include "base/synchronization/lock.h" |
15 #include "base/synchronization/waitable_event.h" | 15 #include "base/synchronization/waitable_event.h" |
16 #include "gpu/command_buffer/common/command_buffer.h" | 16 #include "gpu/command_buffer/common/command_buffer.h" |
| 17 #include "gpu/command_buffer/common/gpu_control.h" |
17 #include "gpu/gpu_export.h" | 18 #include "gpu/gpu_export.h" |
18 #include "ui/gfx/gpu_memory_buffer.h" | 19 #include "ui/gfx/gpu_memory_buffer.h" |
19 #include "ui/gfx/native_widget_types.h" | 20 #include "ui/gfx/native_widget_types.h" |
20 #include "ui/gl/gl_surface.h" | 21 #include "ui/gl/gl_surface.h" |
21 #include "ui/gl/gpu_preference.h" | 22 #include "ui/gl/gpu_preference.h" |
22 | 23 |
23 namespace base { | 24 namespace base { |
24 class SequenceChecker; | 25 class SequenceChecker; |
25 } | 26 } |
26 | 27 |
27 namespace gfx { | 28 namespace gfx { |
28 class GLContext; | 29 class GLContext; |
29 class GLImage; | |
30 class GLSurface; | 30 class GLSurface; |
31 class Size; | 31 class Size; |
32 } | 32 } |
33 | 33 |
34 namespace gpu { | 34 namespace gpu { |
35 | 35 |
36 namespace gles2 { | 36 namespace gles2 { |
37 class GLES2Decoder; | 37 class GLES2Decoder; |
38 } | 38 } |
39 | 39 |
| 40 class GpuMemoryBufferFactory; |
40 class GpuScheduler; | 41 class GpuScheduler; |
41 class TransferBufferManagerInterface; | 42 class TransferBufferManagerInterface; |
42 | 43 |
43 // This class provides a thread-safe interface to the global GPU service (for | 44 // This class provides a thread-safe interface to the global GPU service (for |
44 // example GPU thread) when being run in single process mode. | 45 // example GPU thread) when being run in single process mode. |
45 // However, the behavior for accessing one context (i.e. one instance of this | 46 // However, the behavior for accessing one context (i.e. one instance of this |
46 // class) from different client threads is undefined. | 47 // class) from different client threads is undefined. |
47 class GPU_EXPORT InProcessCommandBuffer : public CommandBuffer { | 48 class GPU_EXPORT InProcessCommandBuffer : public CommandBuffer, |
| 49 public GpuControl { |
48 public: | 50 public: |
49 InProcessCommandBuffer(); | 51 InProcessCommandBuffer(); |
50 virtual ~InProcessCommandBuffer(); | 52 virtual ~InProcessCommandBuffer(); |
51 | 53 |
52 // Used to override the GPU thread with explicit scheduling. | 54 // Used to override the GPU thread with explicit scheduling. |
53 // (By default an internal GPU thread will be spawned to handle all GL work | 55 // (By default an internal GPU thread will be spawned to handle all GL work |
54 // and the two functions are unused.) | 56 // and the two functions are unused.) |
55 // The callback will be called from different client threads. After the | 57 // The callback will be called from different client threads. After the |
56 // callback is issued, the client is expected to eventually call | 58 // callback is issued, the client is expected to eventually call |
57 // ProcessGpuWorkOnCurrentThread(). The latter cannot be called from different | 59 // ProcessGpuWorkOnCurrentThread(). The latter cannot be called from different |
58 // threads. | 60 // threads. |
59 // The callback needs to be set before any context is created. | 61 // The callback needs to be set before any context is created. |
60 static void SetScheduleCallback(const base::Closure& callback); | 62 static void SetScheduleCallback(const base::Closure& callback); |
61 static void ProcessGpuWorkOnCurrentThread(); | 63 static void ProcessGpuWorkOnCurrentThread(); |
62 | 64 |
63 static void EnableVirtualizedContext(); | 65 static void EnableVirtualizedContext(); |
| 66 static void SetGpuMemoryBufferFactory(GpuMemoryBufferFactory* factory); |
64 | 67 |
65 // 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 |
66 // 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 |
67 // a new GLSurface. | 70 // a new GLSurface. |
68 bool Initialize(scoped_refptr<gfx::GLSurface> surface, | 71 bool Initialize(scoped_refptr<gfx::GLSurface> surface, |
69 bool is_offscreen, | 72 bool is_offscreen, |
70 bool share_resources, | 73 bool share_resources, |
71 gfx::AcceleratedWidget window, | 74 gfx::AcceleratedWidget window, |
72 const gfx::Size& size, | 75 const gfx::Size& size, |
73 const char* allowed_extensions, | 76 const char* allowed_extensions, |
74 const std::vector<int32>& attribs, | 77 const std::vector<int32>& attribs, |
75 gfx::GpuPreference gpu_preference, | 78 gfx::GpuPreference gpu_preference, |
76 const base::Closure& context_lost_callback, | 79 const base::Closure& context_lost_callback, |
77 unsigned int share_group_id); | 80 unsigned int share_group_id); |
78 void Destroy(); | 81 void Destroy(); |
79 void SignalSyncPoint(unsigned sync_point, | 82 void SignalSyncPoint(unsigned sync_point, |
80 const base::Closure& callback); | 83 const base::Closure& callback); |
81 unsigned int CreateImageForGpuMemoryBuffer( | |
82 gfx::GpuMemoryBufferHandle buffer, | |
83 gfx::Size size); | |
84 void RemoveImage(unsigned int image_id); | |
85 | 84 |
86 // CommandBuffer implementation: | 85 // CommandBuffer implementation: |
87 virtual bool Initialize() OVERRIDE; | 86 virtual bool Initialize() OVERRIDE; |
88 virtual State GetState() OVERRIDE; | 87 virtual State GetState() OVERRIDE; |
89 virtual State GetLastState() OVERRIDE; | 88 virtual State GetLastState() OVERRIDE; |
90 virtual int32 GetLastToken() OVERRIDE; | 89 virtual int32 GetLastToken() OVERRIDE; |
91 virtual void Flush(int32 put_offset) OVERRIDE; | 90 virtual void Flush(int32 put_offset) OVERRIDE; |
92 virtual State FlushSync(int32 put_offset, int32 last_known_get) OVERRIDE; | 91 virtual State FlushSync(int32 put_offset, int32 last_known_get) OVERRIDE; |
93 virtual void SetGetBuffer(int32 shm_id) OVERRIDE; | 92 virtual void SetGetBuffer(int32 shm_id) OVERRIDE; |
94 virtual void SetGetOffset(int32 get_offset) OVERRIDE; | 93 virtual void SetGetOffset(int32 get_offset) OVERRIDE; |
95 virtual gpu::Buffer CreateTransferBuffer(size_t size, int32* id) OVERRIDE; | 94 virtual gpu::Buffer CreateTransferBuffer(size_t size, int32* id) OVERRIDE; |
96 virtual void DestroyTransferBuffer(int32 id) OVERRIDE; | 95 virtual void DestroyTransferBuffer(int32 id) OVERRIDE; |
97 virtual gpu::Buffer GetTransferBuffer(int32 id) OVERRIDE; | 96 virtual gpu::Buffer GetTransferBuffer(int32 id) OVERRIDE; |
98 virtual void SetToken(int32 token) OVERRIDE; | 97 virtual void SetToken(int32 token) OVERRIDE; |
99 virtual void SetParseError(gpu::error::Error error) OVERRIDE; | 98 virtual void SetParseError(gpu::error::Error error) OVERRIDE; |
100 virtual void SetContextLostReason( | 99 virtual void SetContextLostReason( |
101 gpu::error::ContextLostReason reason) OVERRIDE; | 100 gpu::error::ContextLostReason reason) OVERRIDE; |
102 virtual uint32 InsertSyncPoint() OVERRIDE; | 101 virtual uint32 InsertSyncPoint() OVERRIDE; |
103 virtual gpu::error::Error GetLastError() OVERRIDE; | 102 virtual gpu::error::Error GetLastError() OVERRIDE; |
104 | 103 |
| 104 // GpuControl implementation: |
| 105 virtual gfx::GpuMemoryBuffer* CreateGpuMemoryBuffer( |
| 106 size_t width, |
| 107 size_t height, |
| 108 unsigned internalformat, |
| 109 int32* id) OVERRIDE; |
| 110 virtual void DestroyGpuMemoryBuffer(int32 id) OVERRIDE; |
| 111 |
105 // The serializer interface to the GPU service (i.e. thread). | 112 // The serializer interface to the GPU service (i.e. thread). |
106 class SchedulerClient { | 113 class SchedulerClient { |
107 public: | 114 public: |
108 virtual ~SchedulerClient() {} | 115 virtual ~SchedulerClient() {} |
109 virtual void QueueTask(const base::Closure& task) = 0; | 116 virtual void QueueTask(const base::Closure& task) = 0; |
110 }; | 117 }; |
111 | 118 |
112 private: | 119 private: |
113 bool InitializeOnGpuThread(bool is_offscreen, | 120 bool InitializeOnGpuThread(bool is_offscreen, |
114 gfx::AcceleratedWidget window, | 121 gfx::AcceleratedWidget window, |
115 const gfx::Size& size, | 122 const gfx::Size& size, |
116 const char* allowed_extensions, | 123 const char* allowed_extensions, |
117 const std::vector<int32>& attribs, | 124 const std::vector<int32>& attribs, |
118 gfx::GpuPreference gpu_preference); | 125 gfx::GpuPreference gpu_preference); |
119 bool DestroyOnGpuThread(); | 126 bool DestroyOnGpuThread(); |
120 void FlushOnGpuThread(int32 put_offset); | 127 void FlushOnGpuThread(int32 put_offset); |
121 void CreateImageOnGpuThread(gfx::GpuMemoryBufferHandle buffer, | |
122 gfx::Size size, | |
123 unsigned int image_id); | |
124 void RemoveImageOnGpuThread(unsigned int image_id); | |
125 bool MakeCurrent(); | 128 bool MakeCurrent(); |
126 bool IsContextLost(); | 129 bool IsContextLost(); |
127 base::Closure WrapCallback(const base::Closure& callback); | 130 base::Closure WrapCallback(const base::Closure& callback); |
128 State GetStateFast(); | 131 State GetStateFast(); |
129 void QueueTask(const base::Closure& task) { queue_->QueueTask(task); } | 132 void QueueTask(const base::Closure& task) { queue_->QueueTask(task); } |
130 void CheckSequencedThread(); | 133 void CheckSequencedThread(); |
131 | 134 |
132 // Callbacks: | 135 // Callbacks: |
133 void OnContextLost(); | 136 void OnContextLost(); |
134 void OnResizeView(gfx::Size size, float scale_factor); | 137 void OnResizeView(gfx::Size size, float scale_factor); |
(...skipping 16 matching lines...) Expand all Loading... |
151 State last_state_; | 154 State last_state_; |
152 int32 last_put_offset_; | 155 int32 last_put_offset_; |
153 | 156 |
154 // Accessed on both threads: | 157 // Accessed on both threads: |
155 scoped_ptr<CommandBuffer> command_buffer_; | 158 scoped_ptr<CommandBuffer> command_buffer_; |
156 base::Lock command_buffer_lock_; | 159 base::Lock command_buffer_lock_; |
157 base::WaitableEvent flush_event_; | 160 base::WaitableEvent flush_event_; |
158 scoped_ptr<SchedulerClient> queue_; | 161 scoped_ptr<SchedulerClient> queue_; |
159 State state_after_last_flush_; | 162 State state_after_last_flush_; |
160 base::Lock state_after_last_flush_lock_; | 163 base::Lock state_after_last_flush_lock_; |
| 164 scoped_ptr<GpuControl> gpu_control_; |
161 | 165 |
162 // Only used with explicit scheduling and the gpu thread is the same as | 166 // Only used with explicit scheduling and the gpu thread is the same as |
163 // the client thread. | 167 // the client thread. |
164 scoped_ptr<base::SequenceChecker> sequence_checker_; | 168 scoped_ptr<base::SequenceChecker> sequence_checker_; |
165 | 169 |
166 DISALLOW_COPY_AND_ASSIGN(InProcessCommandBuffer); | 170 DISALLOW_COPY_AND_ASSIGN(InProcessCommandBuffer); |
167 }; | 171 }; |
168 | 172 |
169 } // namespace gpu | 173 } // namespace gpu |
170 | 174 |
171 #endif // GPU_COMMAND_BUFFER_SERVICE_IN_PROCESS_COMMAND_BUFFER_H_ | 175 #endif // GPU_COMMAND_BUFFER_SERVICE_IN_PROCESS_COMMAND_BUFFER_H_ |
OLD | NEW |