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