| 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" |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 virtual bool IsTexture(TextureRef* texture) const = 0; | 45 virtual bool IsTexture(TextureRef* texture) const = 0; |
| 46 virtual bool IsRenderbuffer( | 46 virtual bool IsRenderbuffer( |
| 47 Renderbuffer* renderbuffer) const = 0; | 47 Renderbuffer* renderbuffer) const = 0; |
| 48 virtual bool CanRenderTo() const = 0; | 48 virtual bool CanRenderTo() const = 0; |
| 49 virtual void DetachFromFramebuffer(Framebuffer* framebuffer) const = 0; | 49 virtual void DetachFromFramebuffer(Framebuffer* framebuffer) const = 0; |
| 50 virtual bool ValidForAttachmentType( | 50 virtual bool ValidForAttachmentType( |
| 51 GLenum attachment_type, uint32 max_color_attachments) = 0; | 51 GLenum attachment_type, uint32 max_color_attachments) = 0; |
| 52 virtual size_t GetSignatureSize(TextureManager* texture_manager) const = 0; | 52 virtual size_t GetSignatureSize(TextureManager* texture_manager) const = 0; |
| 53 virtual void AddToSignature( | 53 virtual void AddToSignature( |
| 54 TextureManager* texture_manager, std::string* signature) const = 0; | 54 TextureManager* texture_manager, std::string* signature) const = 0; |
| 55 virtual void OnWillRenderTo() const = 0; |
| 56 virtual void OnDidRenderTo() const = 0; |
| 55 virtual bool FormsFeedbackLoop(TextureRef* texture, GLint level) const = 0; | 57 virtual bool FormsFeedbackLoop(TextureRef* texture, GLint level) const = 0; |
| 56 | 58 |
| 57 protected: | 59 protected: |
| 58 friend class base::RefCounted<Attachment>; | 60 friend class base::RefCounted<Attachment>; |
| 59 virtual ~Attachment() {} | 61 virtual ~Attachment() {} |
| 60 }; | 62 }; |
| 61 | 63 |
| 62 Framebuffer(FramebufferManager* manager, GLuint service_id); | 64 Framebuffer(FramebufferManager* manager, GLuint service_id); |
| 63 | 65 |
| 64 GLuint service_id() const { | 66 GLuint service_id() const { |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 // Clear all the active INT or UINT type color buffers to (0, 0, 0, 0). | 153 // Clear all the active INT or UINT type color buffers to (0, 0, 0, 0). |
| 152 void ClearIntegerBuffers(); | 154 void ClearIntegerBuffers(); |
| 153 | 155 |
| 154 // Return true if any draw buffers has an alpha channel. | 156 // Return true if any draw buffers has an alpha channel. |
| 155 bool HasAlphaMRT() const; | 157 bool HasAlphaMRT() const; |
| 156 | 158 |
| 157 // Return false if any two active color attachments have different internal | 159 // Return false if any two active color attachments have different internal |
| 158 // formats. | 160 // formats. |
| 159 bool HasSameInternalFormatsMRT() const; | 161 bool HasSameInternalFormatsMRT() const; |
| 160 | 162 |
| 163 void OnTextureRefDetached(TextureRef* texture); |
| 164 |
| 165 // If attachment is 0, apply to all attachments; otherwise, apply only to |
| 166 // the specified attachment. |
| 167 void OnWillRenderTo(GLenum attachment) const; |
| 168 void OnDidRenderTo(GLenum attachment) const; |
| 169 |
| 161 void set_read_buffer(GLenum read_buffer) { | 170 void set_read_buffer(GLenum read_buffer) { |
| 162 read_buffer_ = read_buffer; | 171 read_buffer_ = read_buffer; |
| 163 } | 172 } |
| 164 | 173 |
| 165 GLenum read_buffer() const { | 174 GLenum read_buffer() const { |
| 166 return read_buffer_; | 175 return read_buffer_; |
| 167 } | 176 } |
| 168 | 177 |
| 169 private: | 178 private: |
| 170 friend class FramebufferManager; | 179 friend class FramebufferManager; |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 226 | 235 |
| 227 // The currently bound framebuffers | 236 // The currently bound framebuffers |
| 228 scoped_refptr<Framebuffer> bound_read_framebuffer; | 237 scoped_refptr<Framebuffer> bound_read_framebuffer; |
| 229 scoped_refptr<Framebuffer> bound_draw_framebuffer; | 238 scoped_refptr<Framebuffer> bound_draw_framebuffer; |
| 230 }; | 239 }; |
| 231 | 240 |
| 232 // This class keeps track of the frambebuffers and their attached renderbuffers | 241 // This class keeps track of the frambebuffers and their attached renderbuffers |
| 233 // so we can correctly clear them. | 242 // so we can correctly clear them. |
| 234 class GPU_EXPORT FramebufferManager { | 243 class GPU_EXPORT FramebufferManager { |
| 235 public: | 244 public: |
| 245 class GPU_EXPORT TextureDetachObserver { |
| 246 public: |
| 247 TextureDetachObserver(); |
| 248 virtual ~TextureDetachObserver(); |
| 249 |
| 250 virtual void OnTextureRefDetachedFromFramebuffer(TextureRef* texture) = 0; |
| 251 |
| 252 private: |
| 253 DISALLOW_COPY_AND_ASSIGN(TextureDetachObserver); |
| 254 }; |
| 255 |
| 236 FramebufferManager(uint32 max_draw_buffers, | 256 FramebufferManager(uint32 max_draw_buffers, |
| 237 uint32 max_color_attachments, | 257 uint32 max_color_attachments, |
| 238 ContextType context_type, | 258 ContextType context_type, |
| 239 const scoped_refptr<FramebufferCompletenessCache>& | 259 const scoped_refptr<FramebufferCompletenessCache>& |
| 240 framebuffer_combo_complete_cache); | 260 framebuffer_combo_complete_cache); |
| 241 ~FramebufferManager(); | 261 ~FramebufferManager(); |
| 242 | 262 |
| 243 // Must call before destruction. | 263 // Must call before destruction. |
| 244 void Destroy(bool have_context); | 264 void Destroy(bool have_context); |
| 245 | 265 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 263 void MarkAsComplete(Framebuffer* framebuffer); | 283 void MarkAsComplete(Framebuffer* framebuffer); |
| 264 | 284 |
| 265 bool IsComplete(Framebuffer* framebuffer); | 285 bool IsComplete(Framebuffer* framebuffer); |
| 266 | 286 |
| 267 void IncFramebufferStateChangeCount() { | 287 void IncFramebufferStateChangeCount() { |
| 268 // make sure this is never 0. | 288 // make sure this is never 0. |
| 269 framebuffer_state_change_count_ = | 289 framebuffer_state_change_count_ = |
| 270 (framebuffer_state_change_count_ + 1) | 0x80000000U; | 290 (framebuffer_state_change_count_ + 1) | 0x80000000U; |
| 271 } | 291 } |
| 272 | 292 |
| 293 void AddObserver(TextureDetachObserver* observer) { |
| 294 texture_detach_observers_.push_back(observer); |
| 295 } |
| 296 |
| 297 void RemoveObserver(TextureDetachObserver* observer) { |
| 298 texture_detach_observers_.erase( |
| 299 std::remove(texture_detach_observers_.begin(), |
| 300 texture_detach_observers_.end(), |
| 301 observer), |
| 302 texture_detach_observers_.end()); |
| 303 } |
| 304 |
| 273 ContextType context_type() const { return context_type_; } | 305 ContextType context_type() const { return context_type_; } |
| 274 | 306 |
| 275 private: | 307 private: |
| 276 friend class Framebuffer; | 308 friend class Framebuffer; |
| 277 | 309 |
| 278 void StartTracking(Framebuffer* framebuffer); | 310 void StartTracking(Framebuffer* framebuffer); |
| 279 void StopTracking(Framebuffer* framebuffer); | 311 void StopTracking(Framebuffer* framebuffer); |
| 280 | 312 |
| 313 void OnTextureRefDetached(TextureRef* texture); |
| 314 |
| 281 FramebufferCompletenessCache* GetFramebufferComboCompleteCache() { | 315 FramebufferCompletenessCache* GetFramebufferComboCompleteCache() { |
| 282 return framebuffer_combo_complete_cache_.get(); | 316 return framebuffer_combo_complete_cache_.get(); |
| 283 } | 317 } |
| 284 | 318 |
| 285 // Info for each framebuffer in the system. | 319 // Info for each framebuffer in the system. |
| 286 typedef base::hash_map<GLuint, scoped_refptr<Framebuffer> > | 320 typedef base::hash_map<GLuint, scoped_refptr<Framebuffer> > |
| 287 FramebufferMap; | 321 FramebufferMap; |
| 288 FramebufferMap framebuffers_; | 322 FramebufferMap framebuffers_; |
| 289 | 323 |
| 290 // Incremented anytime anything changes that might effect framebuffer | 324 // Incremented anytime anything changes that might effect framebuffer |
| 291 // state. | 325 // state. |
| 292 unsigned framebuffer_state_change_count_; | 326 unsigned framebuffer_state_change_count_; |
| 293 | 327 |
| 294 // Counts the number of Framebuffer allocated with 'this' as its manager. | 328 // Counts the number of Framebuffer allocated with 'this' as its manager. |
| 295 // Allows to check no Framebuffer will outlive this. | 329 // Allows to check no Framebuffer will outlive this. |
| 296 unsigned int framebuffer_count_; | 330 unsigned int framebuffer_count_; |
| 297 | 331 |
| 298 bool have_context_; | 332 bool have_context_; |
| 299 | 333 |
| 300 uint32 max_draw_buffers_; | 334 uint32 max_draw_buffers_; |
| 301 uint32 max_color_attachments_; | 335 uint32 max_color_attachments_; |
| 302 | 336 |
| 303 ContextType context_type_; | 337 ContextType context_type_; |
| 304 | 338 |
| 339 typedef std::vector<TextureDetachObserver*> TextureDetachObserverVector; |
| 340 TextureDetachObserverVector texture_detach_observers_; |
| 341 |
| 305 scoped_refptr<FramebufferCompletenessCache> framebuffer_combo_complete_cache_; | 342 scoped_refptr<FramebufferCompletenessCache> framebuffer_combo_complete_cache_; |
| 306 | 343 |
| 307 DISALLOW_COPY_AND_ASSIGN(FramebufferManager); | 344 DISALLOW_COPY_AND_ASSIGN(FramebufferManager); |
| 308 }; | 345 }; |
| 309 | 346 |
| 310 } // namespace gles2 | 347 } // namespace gles2 |
| 311 } // namespace gpu | 348 } // namespace gpu |
| 312 | 349 |
| 313 #endif // GPU_COMMAND_BUFFER_SERVICE_FRAMEBUFFER_MANAGER_H_ | 350 #endif // GPU_COMMAND_BUFFER_SERVICE_FRAMEBUFFER_MANAGER_H_ |
| OLD | NEW |