OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_FRAMEBUFFER_MANAGER_H_ | 5 #ifndef GPU_COMMAND_BUFFER_SERVICE_FRAMEBUFFER_MANAGER_H_ |
6 #define GPU_COMMAND_BUFFER_SERVICE_FRAMEBUFFER_MANAGER_H_ | 6 #define GPU_COMMAND_BUFFER_SERVICE_FRAMEBUFFER_MANAGER_H_ |
7 | 7 |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/containers/hash_tables.h" | 11 #include "base/containers/hash_tables.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 "gpu/command_buffer/service/context_group.h" | 14 #include "gpu/command_buffer/service/context_group.h" |
15 #include "gpu/command_buffer/service/gl_utils.h" | 15 #include "gpu/command_buffer/service/gl_utils.h" |
16 #include "gpu/gpu_export.h" | 16 #include "gpu/gpu_export.h" |
17 | 17 |
18 namespace gpu { | 18 namespace gpu { |
19 namespace gles2 { | 19 namespace gles2 { |
20 | 20 |
| 21 class FramebufferCompletenessCache; |
21 class FramebufferManager; | 22 class FramebufferManager; |
22 class Renderbuffer; | 23 class Renderbuffer; |
23 class RenderbufferManager; | 24 class RenderbufferManager; |
24 class Texture; | 25 class Texture; |
25 class TextureRef; | 26 class TextureRef; |
26 class TextureManager; | 27 class TextureManager; |
27 | 28 |
28 // Info about a particular Framebuffer. | 29 // Info about a particular Framebuffer. |
29 class GPU_EXPORT Framebuffer : public base::RefCounted<Framebuffer> { | 30 class GPU_EXPORT Framebuffer : public base::RefCounted<Framebuffer> { |
30 public: | 31 public: |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 // PrepareDrawBuffersForClear(). | 150 // PrepareDrawBuffersForClear(). |
150 void RestoreDrawBuffersAfterClear() const; | 151 void RestoreDrawBuffersAfterClear() const; |
151 | 152 |
152 // Return true if any draw buffers has an alpha channel. | 153 // Return true if any draw buffers has an alpha channel. |
153 bool HasAlphaMRT() const; | 154 bool HasAlphaMRT() const; |
154 | 155 |
155 // Return false if any two active color attachments have different internal | 156 // Return false if any two active color attachments have different internal |
156 // formats. | 157 // formats. |
157 bool HasSameInternalFormatsMRT() const; | 158 bool HasSameInternalFormatsMRT() const; |
158 | 159 |
159 static void ClearFramebufferCompleteComboMap(); | |
160 | |
161 static bool AllowFramebufferComboCompleteMapForTesting() { | |
162 return allow_framebuffer_combo_complete_map_; | |
163 } | |
164 | |
165 void OnTextureRefDetached(TextureRef* texture); | 160 void OnTextureRefDetached(TextureRef* texture); |
166 void OnWillRenderTo() const; | 161 void OnWillRenderTo() const; |
167 void OnDidRenderTo() const; | 162 void OnDidRenderTo() const; |
168 | 163 |
169 void set_read_buffer(GLenum read_buffer) { | 164 void set_read_buffer(GLenum read_buffer) { |
170 read_buffer_ = read_buffer; | 165 read_buffer_ = read_buffer; |
171 } | 166 } |
172 | 167 |
173 GLenum read_buffer() const { | 168 GLenum read_buffer() const { |
174 return read_buffer_; | 169 return read_buffer_; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
210 // Whether this framebuffer has ever been bound. | 205 // Whether this framebuffer has ever been bound. |
211 bool has_been_bound_; | 206 bool has_been_bound_; |
212 | 207 |
213 // state count when this framebuffer was last checked for completeness. | 208 // state count when this framebuffer was last checked for completeness. |
214 unsigned framebuffer_complete_state_count_id_; | 209 unsigned framebuffer_complete_state_count_id_; |
215 | 210 |
216 // A map of attachments. | 211 // A map of attachments. |
217 typedef base::hash_map<GLenum, scoped_refptr<Attachment> > AttachmentMap; | 212 typedef base::hash_map<GLenum, scoped_refptr<Attachment> > AttachmentMap; |
218 AttachmentMap attachments_; | 213 AttachmentMap attachments_; |
219 | 214 |
220 // A map of successful frame buffer combos. If it's in the map | |
221 // it should be FRAMEBUFFER_COMPLETE. | |
222 typedef base::hash_map<std::string, bool> FramebufferComboCompleteMap; | |
223 static FramebufferComboCompleteMap* framebuffer_combo_complete_map_; | |
224 static bool allow_framebuffer_combo_complete_map_; | |
225 | |
226 scoped_ptr<GLenum[]> draw_buffers_; | 215 scoped_ptr<GLenum[]> draw_buffers_; |
227 | 216 |
228 GLenum read_buffer_; | 217 GLenum read_buffer_; |
229 | 218 |
230 DISALLOW_COPY_AND_ASSIGN(Framebuffer); | 219 DISALLOW_COPY_AND_ASSIGN(Framebuffer); |
231 }; | 220 }; |
232 | 221 |
233 struct DecoderFramebufferState { | 222 struct DecoderFramebufferState { |
234 DecoderFramebufferState(); | 223 DecoderFramebufferState(); |
235 ~DecoderFramebufferState(); | 224 ~DecoderFramebufferState(); |
(...skipping 15 matching lines...) Expand all Loading... |
251 public: | 240 public: |
252 TextureDetachObserver(); | 241 TextureDetachObserver(); |
253 virtual ~TextureDetachObserver(); | 242 virtual ~TextureDetachObserver(); |
254 | 243 |
255 virtual void OnTextureRefDetachedFromFramebuffer(TextureRef* texture) = 0; | 244 virtual void OnTextureRefDetachedFromFramebuffer(TextureRef* texture) = 0; |
256 | 245 |
257 private: | 246 private: |
258 DISALLOW_COPY_AND_ASSIGN(TextureDetachObserver); | 247 DISALLOW_COPY_AND_ASSIGN(TextureDetachObserver); |
259 }; | 248 }; |
260 | 249 |
261 FramebufferManager(uint32 max_draw_buffers, uint32 max_color_attachments, | 250 FramebufferManager(uint32 max_draw_buffers, |
262 ContextGroup::ContextType context_type); | 251 uint32 max_color_attachments, |
| 252 ContextGroup::ContextType context_type, |
| 253 const scoped_refptr<FramebufferCompletenessCache>& |
| 254 framebuffer_combo_complete_cache); |
263 ~FramebufferManager(); | 255 ~FramebufferManager(); |
264 | 256 |
265 // Must call before destruction. | 257 // Must call before destruction. |
266 void Destroy(bool have_context); | 258 void Destroy(bool have_context); |
267 | 259 |
268 // Creates a Framebuffer for the given framebuffer. | 260 // Creates a Framebuffer for the given framebuffer. |
269 void CreateFramebuffer(GLuint client_id, GLuint service_id); | 261 void CreateFramebuffer(GLuint client_id, GLuint service_id); |
270 | 262 |
271 // Gets the framebuffer info for the given framebuffer. | 263 // Gets the framebuffer info for the given framebuffer. |
272 Framebuffer* GetFramebuffer(GLuint client_id); | 264 Framebuffer* GetFramebuffer(GLuint client_id); |
(...skipping 28 matching lines...) Expand all Loading... |
301 std::remove(texture_detach_observers_.begin(), | 293 std::remove(texture_detach_observers_.begin(), |
302 texture_detach_observers_.end(), | 294 texture_detach_observers_.end(), |
303 observer), | 295 observer), |
304 texture_detach_observers_.end()); | 296 texture_detach_observers_.end()); |
305 } | 297 } |
306 | 298 |
307 ContextGroup::ContextType context_type() const { | 299 ContextGroup::ContextType context_type() const { |
308 return context_type_; | 300 return context_type_; |
309 } | 301 } |
310 | 302 |
| 303 void SetFramebufferComboCompleteCacheForTesting( |
| 304 const scoped_refptr<FramebufferCompletenessCache>& |
| 305 framebuffer_combo_complete_cache) { |
| 306 framebuffer_combo_complete_cache_ = framebuffer_combo_complete_cache; |
| 307 } |
| 308 |
311 private: | 309 private: |
312 friend class Framebuffer; | 310 friend class Framebuffer; |
313 | 311 |
314 void StartTracking(Framebuffer* framebuffer); | 312 void StartTracking(Framebuffer* framebuffer); |
315 void StopTracking(Framebuffer* framebuffer); | 313 void StopTracking(Framebuffer* framebuffer); |
316 | 314 |
317 void OnTextureRefDetached(TextureRef* texture); | 315 void OnTextureRefDetached(TextureRef* texture); |
318 | 316 |
| 317 FramebufferCompletenessCache* GetFramebufferComboCompleteCache() { |
| 318 return framebuffer_combo_complete_cache_.get(); |
| 319 } |
| 320 |
319 // Info for each framebuffer in the system. | 321 // Info for each framebuffer in the system. |
320 typedef base::hash_map<GLuint, scoped_refptr<Framebuffer> > | 322 typedef base::hash_map<GLuint, scoped_refptr<Framebuffer> > |
321 FramebufferMap; | 323 FramebufferMap; |
322 FramebufferMap framebuffers_; | 324 FramebufferMap framebuffers_; |
323 | 325 |
324 // Incremented anytime anything changes that might effect framebuffer | 326 // Incremented anytime anything changes that might effect framebuffer |
325 // state. | 327 // state. |
326 unsigned framebuffer_state_change_count_; | 328 unsigned framebuffer_state_change_count_; |
327 | 329 |
328 // Counts the number of Framebuffer allocated with 'this' as its manager. | 330 // Counts the number of Framebuffer allocated with 'this' as its manager. |
329 // Allows to check no Framebuffer will outlive this. | 331 // Allows to check no Framebuffer will outlive this. |
330 unsigned int framebuffer_count_; | 332 unsigned int framebuffer_count_; |
331 | 333 |
332 bool have_context_; | 334 bool have_context_; |
333 | 335 |
334 uint32 max_draw_buffers_; | 336 uint32 max_draw_buffers_; |
335 uint32 max_color_attachments_; | 337 uint32 max_color_attachments_; |
336 | 338 |
337 ContextGroup::ContextType context_type_; | 339 ContextGroup::ContextType context_type_; |
338 | 340 |
339 typedef std::vector<TextureDetachObserver*> TextureDetachObserverVector; | 341 typedef std::vector<TextureDetachObserver*> TextureDetachObserverVector; |
340 TextureDetachObserverVector texture_detach_observers_; | 342 TextureDetachObserverVector texture_detach_observers_; |
341 | 343 |
| 344 scoped_refptr<FramebufferCompletenessCache> framebuffer_combo_complete_cache_; |
| 345 |
342 DISALLOW_COPY_AND_ASSIGN(FramebufferManager); | 346 DISALLOW_COPY_AND_ASSIGN(FramebufferManager); |
343 }; | 347 }; |
344 | 348 |
345 } // namespace gles2 | 349 } // namespace gles2 |
346 } // namespace gpu | 350 } // namespace gpu |
347 | 351 |
348 #endif // GPU_COMMAND_BUFFER_SERVICE_FRAMEBUFFER_MANAGER_H_ | 352 #endif // GPU_COMMAND_BUFFER_SERVICE_FRAMEBUFFER_MANAGER_H_ |
OLD | NEW |