| 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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 309 } | 301 } |
| 310 | 302 |
| 311 private: | 303 private: |
| 312 friend class Framebuffer; | 304 friend class Framebuffer; |
| 313 | 305 |
| 314 void StartTracking(Framebuffer* framebuffer); | 306 void StartTracking(Framebuffer* framebuffer); |
| 315 void StopTracking(Framebuffer* framebuffer); | 307 void StopTracking(Framebuffer* framebuffer); |
| 316 | 308 |
| 317 void OnTextureRefDetached(TextureRef* texture); | 309 void OnTextureRefDetached(TextureRef* texture); |
| 318 | 310 |
| 311 FramebufferCompletenessCache* GetFramebufferComboCompleteCache() { |
| 312 return framebuffer_combo_complete_cache_.get(); |
| 313 } |
| 314 |
| 319 // Info for each framebuffer in the system. | 315 // Info for each framebuffer in the system. |
| 320 typedef base::hash_map<GLuint, scoped_refptr<Framebuffer> > | 316 typedef base::hash_map<GLuint, scoped_refptr<Framebuffer> > |
| 321 FramebufferMap; | 317 FramebufferMap; |
| 322 FramebufferMap framebuffers_; | 318 FramebufferMap framebuffers_; |
| 323 | 319 |
| 324 // Incremented anytime anything changes that might effect framebuffer | 320 // Incremented anytime anything changes that might effect framebuffer |
| 325 // state. | 321 // state. |
| 326 unsigned framebuffer_state_change_count_; | 322 unsigned framebuffer_state_change_count_; |
| 327 | 323 |
| 328 // Counts the number of Framebuffer allocated with 'this' as its manager. | 324 // Counts the number of Framebuffer allocated with 'this' as its manager. |
| 329 // Allows to check no Framebuffer will outlive this. | 325 // Allows to check no Framebuffer will outlive this. |
| 330 unsigned int framebuffer_count_; | 326 unsigned int framebuffer_count_; |
| 331 | 327 |
| 332 bool have_context_; | 328 bool have_context_; |
| 333 | 329 |
| 334 uint32 max_draw_buffers_; | 330 uint32 max_draw_buffers_; |
| 335 uint32 max_color_attachments_; | 331 uint32 max_color_attachments_; |
| 336 | 332 |
| 337 ContextGroup::ContextType context_type_; | 333 ContextGroup::ContextType context_type_; |
| 338 | 334 |
| 339 typedef std::vector<TextureDetachObserver*> TextureDetachObserverVector; | 335 typedef std::vector<TextureDetachObserver*> TextureDetachObserverVector; |
| 340 TextureDetachObserverVector texture_detach_observers_; | 336 TextureDetachObserverVector texture_detach_observers_; |
| 341 | 337 |
| 338 scoped_refptr<FramebufferCompletenessCache> framebuffer_combo_complete_cache_; |
| 339 |
| 342 DISALLOW_COPY_AND_ASSIGN(FramebufferManager); | 340 DISALLOW_COPY_AND_ASSIGN(FramebufferManager); |
| 343 }; | 341 }; |
| 344 | 342 |
| 345 } // namespace gles2 | 343 } // namespace gles2 |
| 346 } // namespace gpu | 344 } // namespace gpu |
| 347 | 345 |
| 348 #endif // GPU_COMMAND_BUFFER_SERVICE_FRAMEBUFFER_MANAGER_H_ | 346 #endif // GPU_COMMAND_BUFFER_SERVICE_FRAMEBUFFER_MANAGER_H_ |
| OLD | NEW |