OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_GPU_SCHEDULER_H_ | 5 #ifndef GPU_COMMAND_BUFFER_SERVICE_GPU_SCHEDULER_H_ |
6 #define GPU_COMMAND_BUFFER_SERVICE_GPU_SCHEDULER_H_ | 6 #define GPU_COMMAND_BUFFER_SERVICE_GPU_SCHEDULER_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <queue> | 9 #include <queue> |
10 #include <vector> | 10 #include <vector> |
(...skipping 25 matching lines...) Expand all Loading... |
36 | 36 |
37 namespace gpu { | 37 namespace gpu { |
38 namespace gles2 { | 38 namespace gles2 { |
39 class ContextGroup; | 39 class ContextGroup; |
40 } | 40 } |
41 | 41 |
42 // This class processes commands in a command buffer. It is event driven and | 42 // This class processes commands in a command buffer. It is event driven and |
43 // posts tasks to the current message loop to do additional work. | 43 // posts tasks to the current message loop to do additional work. |
44 class GpuScheduler : public CommandBufferEngine { | 44 class GpuScheduler : public CommandBufferEngine { |
45 public: | 45 public: |
46 // Scheduler quantum: makes ProcessCommands continue until the specified time | |
47 // has passed, or the command buffer yields or runs out of commands. | |
48 static const int kMinimumSchedulerQuantumMicros = 2000; | |
49 | |
50 // If a group is not passed in one will be created. | 46 // If a group is not passed in one will be created. |
51 GpuScheduler(CommandBuffer* command_buffer, | 47 static GpuScheduler* Create(CommandBuffer* command_buffer, |
52 SurfaceManager* surface_manager, | 48 SurfaceManager* surface_manager, |
53 gles2::ContextGroup* group); | 49 gles2::ContextGroup* group); |
54 | 50 |
55 // This constructor is for unit tests. | 51 // This constructor is for unit tests. |
56 GpuScheduler(CommandBuffer* command_buffer, | 52 static GpuScheduler* CreateForTests(CommandBuffer* command_buffer, |
57 gles2::GLES2Decoder* decoder, | 53 gles2::GLES2Decoder* decoder, |
58 CommandParser* parser, | 54 CommandParser* parser); |
59 int commands_per_update); | |
60 | 55 |
61 virtual ~GpuScheduler(); | 56 virtual ~GpuScheduler(); |
62 | 57 |
63 // Perform platform specific and common initialization. | 58 // Perform platform specific and common initialization. |
64 bool Initialize(gfx::PluginWindowHandle hwnd, | 59 bool Initialize(gfx::PluginWindowHandle hwnd, |
65 const gfx::Size& size, | 60 const gfx::Size& size, |
66 const gles2::DisallowedExtensions& disallowed_extensions, | 61 const gles2::DisallowedExtensions& disallowed_extensions, |
67 const char* allowed_extensions, | 62 const char* allowed_extensions, |
68 const std::vector<int32>& attribs, | 63 const std::vector<int32>& attribs, |
69 gfx::GLShareGroup* share_group); | 64 gfx::GLShareGroup* share_group); |
70 | 65 |
71 void Destroy(); | 66 void Destroy(); |
72 void DestroyCommon(); | 67 void DestroyCommon(); |
73 | 68 |
74 bool SetParent(GpuScheduler* parent_scheduler, uint32 parent_texture_id); | 69 bool SetParent(GpuScheduler* parent_scheduler, uint32 parent_texture_id); |
75 | 70 |
76 void PutChanged(bool sync); | 71 void PutChanged(); |
77 | 72 |
78 // Sets whether commands should be processed by this scheduler. Setting to | 73 // Sets whether commands should be processed by this scheduler. Setting to |
79 // false unschedules. Setting to true reschedules. Whether or not the | 74 // false unschedules. Setting to true reschedules. Whether or not the |
80 // scheduler is currently scheduled is "reference counted". Every call with | 75 // scheduler is currently scheduled is "reference counted". Every call with |
81 // false must eventually be paired by a call with true. | 76 // false must eventually be paired by a call with true. |
82 void SetScheduled(bool is_scheduled); | 77 void SetScheduled(bool is_scheduled); |
83 | 78 |
84 // Returns whether the scheduler is currently scheduled to process commands. | 79 // Returns whether the scheduler is currently scheduled to process commands. |
85 bool IsScheduled(); | 80 bool IsScheduled(); |
86 | 81 |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 // is processed. | 139 // is processed. |
145 void SetResizeCallback(Callback1<gfx::Size>::Type* callback); | 140 void SetResizeCallback(Callback1<gfx::Size>::Type* callback); |
146 | 141 |
147 // Sets a callback which is called when a SwapBuffers command is processed. | 142 // Sets a callback which is called when a SwapBuffers command is processed. |
148 // Must be called after Initialize(). | 143 // Must be called after Initialize(). |
149 // It is not defined on which thread this callback is called. | 144 // It is not defined on which thread this callback is called. |
150 void SetSwapBuffersCallback(Callback0::Type* callback); | 145 void SetSwapBuffersCallback(Callback0::Type* callback); |
151 | 146 |
152 void SetCommandProcessedCallback(Callback0::Type* callback); | 147 void SetCommandProcessedCallback(Callback0::Type* callback); |
153 | 148 |
154 // Sets a callback which is called after a Set/WaitLatch command is processed. | |
155 // The bool parameter will be true for SetLatch, and false for a WaitLatch | |
156 // that is blocked. An unblocked WaitLatch will not trigger a callback. | |
157 void SetLatchCallback(const base::Callback<void(bool)>& callback) { | |
158 decoder_->SetLatchCallback(callback); | |
159 } | |
160 | |
161 // Sets a callback which is called when set_token() is called, and passes the | 149 // Sets a callback which is called when set_token() is called, and passes the |
162 // just-set token to the callback. DCHECKs that no callback has previously | 150 // just-set token to the callback. DCHECKs that no callback has previously |
163 // been registered for this notification. | 151 // been registered for this notification. |
164 void SetTokenCallback(const base::Callback<void(int32)>& callback); | 152 void SetTokenCallback(const base::Callback<void(int32)>& callback); |
165 | 153 |
166 // Get the GLES2Decoder associated with this scheduler. | 154 // Get the GLES2Decoder associated with this scheduler. |
167 gles2::GLES2Decoder* decoder() const { return decoder_.get(); } | 155 gles2::GLES2Decoder* decoder() const { return decoder_.get(); } |
168 | 156 |
169 protected: | 157 protected: |
170 // Perform common initialization. Takes ownership of GLSurface and GLContext. | 158 // Perform common initialization. Takes ownership of GLSurface and GLContext. |
171 bool InitializeCommon( | 159 bool InitializeCommon( |
172 const scoped_refptr<gfx::GLSurface>& surface, | 160 const scoped_refptr<gfx::GLSurface>& surface, |
173 const scoped_refptr<gfx::GLContext>& context, | 161 const scoped_refptr<gfx::GLContext>& context, |
174 const gfx::Size& size, | 162 const gfx::Size& size, |
175 const gles2::DisallowedExtensions& disallowed_extensions, | 163 const gles2::DisallowedExtensions& disallowed_extensions, |
176 const char* allowed_extensions, | 164 const char* allowed_extensions, |
177 const std::vector<int32>& attribs); | 165 const std::vector<int32>& attribs); |
178 | 166 |
179 | 167 |
180 private: | 168 private: |
181 // Helper which causes a call to ProcessCommands to be scheduled later. | 169 // If a group is not passed in one will be created. |
182 void ScheduleProcessCommands(); | 170 GpuScheduler(CommandBuffer* command_buffer, |
| 171 gles2::GLES2Decoder* decoder, |
| 172 CommandParser* parser); |
183 | 173 |
184 // Called via a callback just before we are supposed to call the | 174 // Called via a callback just before we are supposed to call the |
185 // user's resize callback. | 175 // user's resize callback. |
186 void WillResize(gfx::Size size); | 176 void WillResize(gfx::Size size); |
187 | 177 |
188 // Called via a callback just before we are supposed to call the | 178 // Called via a callback just before we are supposed to call the |
189 // user's swap buffers callback. | 179 // user's swap buffers callback. |
190 void WillSwapBuffers(); | 180 void WillSwapBuffers(); |
191 void ProcessCommands(); | |
192 | 181 |
193 // The GpuScheduler holds a weak reference to the CommandBuffer. The | 182 // The GpuScheduler holds a weak reference to the CommandBuffer. The |
194 // CommandBuffer owns the GpuScheduler and holds a strong reference to it | 183 // CommandBuffer owns the GpuScheduler and holds a strong reference to it |
195 // through the ProcessCommands callback. | 184 // through the ProcessCommands callback. |
196 CommandBuffer* command_buffer_; | 185 CommandBuffer* command_buffer_; |
197 | 186 |
198 int commands_per_update_; | |
199 | |
200 scoped_ptr<gles2::GLES2Decoder> decoder_; | 187 scoped_ptr<gles2::GLES2Decoder> decoder_; |
201 scoped_ptr<CommandParser> parser_; | 188 scoped_ptr<CommandParser> parser_; |
202 | 189 |
203 // Greater than zero if this is waiting to be rescheduled before continuing. | 190 // Greater than zero if this is waiting to be rescheduled before continuing. |
204 int unscheduled_count_; | 191 int unscheduled_count_; |
205 | 192 |
206 scoped_ptr<Callback0::Type> scheduled_callback_; | 193 scoped_ptr<Callback0::Type> scheduled_callback_; |
207 | 194 |
208 #if defined(OS_MACOSX) || defined(TOUCH_UI) | 195 #if defined(OS_MACOSX) || defined(TOUCH_UI) |
209 uint64 swap_buffers_count_; | 196 uint64 swap_buffers_count_; |
(...skipping 12 matching lines...) Expand all Loading... |
222 ScopedRunnableMethodFactory<GpuScheduler> method_factory_; | 209 ScopedRunnableMethodFactory<GpuScheduler> method_factory_; |
223 scoped_ptr<Callback1<gfx::Size>::Type> wrapped_resize_callback_; | 210 scoped_ptr<Callback1<gfx::Size>::Type> wrapped_resize_callback_; |
224 scoped_ptr<Callback0::Type> wrapped_swap_buffers_callback_; | 211 scoped_ptr<Callback0::Type> wrapped_swap_buffers_callback_; |
225 scoped_ptr<Callback0::Type> command_processed_callback_; | 212 scoped_ptr<Callback0::Type> command_processed_callback_; |
226 base::Callback<void(int32)> set_token_callback_; | 213 base::Callback<void(int32)> set_token_callback_; |
227 }; | 214 }; |
228 | 215 |
229 } // namespace gpu | 216 } // namespace gpu |
230 | 217 |
231 #endif // GPU_COMMAND_BUFFER_SERVICE_GPU_SCHEDULER_H_ | 218 #endif // GPU_COMMAND_BUFFER_SERVICE_GPU_SCHEDULER_H_ |
OLD | NEW |