| 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 #include "gpu/command_buffer/service/framebuffer_manager.h" |    5 #include "gpu/command_buffer/service/framebuffer_manager.h" | 
|    6 #include "base/logging.h" |    6 #include "base/logging.h" | 
|    7 #include "base/stringprintf.h" |    7 #include "base/stringprintf.h" | 
|    8 #include "gpu/command_buffer/common/gles2_cmd_utils.h" |    8 #include "gpu/command_buffer/common/gles2_cmd_utils.h" | 
|    9 #include "gpu/command_buffer/service/renderbuffer_manager.h" |    9 #include "gpu/command_buffer/service/renderbuffer_manager.h" | 
|   10 #include "gpu/command_buffer/service/texture_manager.h" |   10 #include "gpu/command_buffer/service/texture_manager.h" | 
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   60   } |   60   } | 
|   61  |   61  | 
|   62   virtual void SetCleared( |   62   virtual void SetCleared( | 
|   63       RenderbufferManager* renderbuffer_manager, |   63       RenderbufferManager* renderbuffer_manager, | 
|   64       TextureManager* /* texture_manager */, |   64       TextureManager* /* texture_manager */, | 
|   65       bool cleared) OVERRIDE { |   65       bool cleared) OVERRIDE { | 
|   66     renderbuffer_manager->SetCleared(renderbuffer_, cleared); |   66     renderbuffer_manager->SetCleared(renderbuffer_, cleared); | 
|   67   } |   67   } | 
|   68  |   68  | 
|   69   virtual bool IsTexture( |   69   virtual bool IsTexture( | 
|   70       Texture* /* texture */) const OVERRIDE { |   70       TextureRef* /* texture */) const OVERRIDE { | 
|   71     return false; |   71     return false; | 
|   72   } |   72   } | 
|   73  |   73  | 
|   74   virtual bool IsRenderbuffer( |   74   virtual bool IsRenderbuffer( | 
|   75        Renderbuffer* renderbuffer) const OVERRIDE { |   75        Renderbuffer* renderbuffer) const OVERRIDE { | 
|   76      return renderbuffer_ == renderbuffer; |   76      return renderbuffer_ == renderbuffer; | 
|   77   } |   77   } | 
|   78  |   78  | 
|   79   virtual bool CanRenderTo() const OVERRIDE { |   79   virtual bool CanRenderTo() const OVERRIDE { | 
|   80     return true; |   80     return true; | 
| (...skipping 27 matching lines...) Expand all  Loading... | 
|  108  private: |  108  private: | 
|  109   scoped_refptr<Renderbuffer> renderbuffer_; |  109   scoped_refptr<Renderbuffer> renderbuffer_; | 
|  110  |  110  | 
|  111   DISALLOW_COPY_AND_ASSIGN(RenderbufferAttachment); |  111   DISALLOW_COPY_AND_ASSIGN(RenderbufferAttachment); | 
|  112 }; |  112 }; | 
|  113  |  113  | 
|  114 class TextureAttachment |  114 class TextureAttachment | 
|  115     : public Framebuffer::Attachment { |  115     : public Framebuffer::Attachment { | 
|  116  public: |  116  public: | 
|  117   TextureAttachment( |  117   TextureAttachment( | 
|  118       Texture* texture, GLenum target, GLint level) |  118       TextureRef* texture_ref, GLenum target, GLint level) | 
|  119       : texture_(texture), |  119       : texture_ref_(texture_ref), | 
|  120         target_(target), |  120         target_(target), | 
|  121         level_(level) { |  121         level_(level) { | 
|  122   } |  122   } | 
|  123  |  123  | 
|  124   virtual GLsizei width() const OVERRIDE { |  124   virtual GLsizei width() const OVERRIDE { | 
|  125     GLsizei temp_width = 0; |  125     GLsizei temp_width = 0; | 
|  126     GLsizei temp_height = 0; |  126     GLsizei temp_height = 0; | 
|  127     texture_->GetLevelSize(target_, level_, &temp_width, &temp_height); |  127     texture_ref_->texture()->GetLevelSize( | 
 |  128         target_, level_, &temp_width, &temp_height); | 
|  128     return temp_width; |  129     return temp_width; | 
|  129   } |  130   } | 
|  130  |  131  | 
|  131   virtual GLsizei height() const OVERRIDE { |  132   virtual GLsizei height() const OVERRIDE { | 
|  132     GLsizei temp_width = 0; |  133     GLsizei temp_width = 0; | 
|  133     GLsizei temp_height = 0; |  134     GLsizei temp_height = 0; | 
|  134     texture_->GetLevelSize(target_, level_, &temp_width, &temp_height); |  135     texture_ref_->texture()->GetLevelSize( | 
 |  136         target_, level_, &temp_width, &temp_height); | 
|  135     return temp_height; |  137     return temp_height; | 
|  136   } |  138   } | 
|  137  |  139  | 
|  138   virtual GLenum internal_format() const OVERRIDE { |  140   virtual GLenum internal_format() const OVERRIDE { | 
|  139     GLenum temp_type = 0; |  141     GLenum temp_type = 0; | 
|  140     GLenum temp_internal_format = 0; |  142     GLenum temp_internal_format = 0; | 
|  141     texture_->GetLevelType(target_, level_, &temp_type, &temp_internal_format); |  143     texture_ref_->texture()->GetLevelType( | 
 |  144         target_, level_, &temp_type, &temp_internal_format); | 
|  142     return temp_internal_format; |  145     return temp_internal_format; | 
|  143   } |  146   } | 
|  144  |  147  | 
|  145   virtual GLsizei samples() const OVERRIDE { |  148   virtual GLsizei samples() const OVERRIDE { | 
|  146     return 0; |  149     return 0; | 
|  147   } |  150   } | 
|  148  |  151  | 
|  149   virtual bool cleared() const OVERRIDE { |  152   virtual bool cleared() const OVERRIDE { | 
|  150     return texture_->IsLevelCleared(target_, level_); |  153     return texture_ref_->texture()->IsLevelCleared(target_, level_); | 
|  151   } |  154   } | 
|  152  |  155  | 
|  153   virtual void SetCleared( |  156   virtual void SetCleared( | 
|  154       RenderbufferManager* /* renderbuffer_manager */, |  157       RenderbufferManager* /* renderbuffer_manager */, | 
|  155       TextureManager* texture_manager, |  158       TextureManager* texture_manager, | 
|  156       bool cleared) OVERRIDE { |  159       bool cleared) OVERRIDE { | 
|  157     texture_manager->SetLevelCleared(texture_, target_, level_, cleared); |  160     texture_manager->SetLevelCleared(texture_ref_, target_, level_, cleared); | 
|  158   } |  161   } | 
|  159  |  162  | 
|  160   virtual bool IsTexture(Texture* texture) const OVERRIDE { |  163   virtual bool IsTexture(TextureRef* texture) const OVERRIDE { | 
|  161     return texture == texture_.get(); |  164     return texture == texture_ref_.get(); | 
|  162   } |  165   } | 
|  163  |  166  | 
|  164   virtual bool IsRenderbuffer( |  167   virtual bool IsRenderbuffer( | 
|  165        Renderbuffer* /* renderbuffer */) |  168        Renderbuffer* /* renderbuffer */) | 
|  166           const OVERRIDE { |  169           const OVERRIDE { | 
|  167     return false; |  170     return false; | 
|  168   } |  171   } | 
|  169  |  172  | 
|  170   Texture* texture() const { |  173   TextureRef* texture() const { | 
|  171     return texture_.get(); |  174     return texture_ref_.get(); | 
|  172   } |  175   } | 
|  173  |  176  | 
|  174   virtual bool CanRenderTo() const OVERRIDE { |  177   virtual bool CanRenderTo() const OVERRIDE { | 
|  175     return texture_->CanRenderTo(); |  178     return texture_ref_->texture()->CanRenderTo(); | 
|  176   } |  179   } | 
|  177  |  180  | 
|  178   virtual void DetachFromFramebuffer() const OVERRIDE { |  181   virtual void DetachFromFramebuffer() const OVERRIDE { | 
|  179     texture_->DetachFromFramebuffer(); |  182     texture_ref_->texture()->DetachFromFramebuffer(); | 
|  180   } |  183   } | 
|  181  |  184  | 
|  182   virtual bool ValidForAttachmentType( |  185   virtual bool ValidForAttachmentType( | 
|  183       GLenum attachment_type, uint32 max_color_attachments) OVERRIDE { |  186       GLenum attachment_type, uint32 max_color_attachments) OVERRIDE { | 
|  184     GLenum type = 0; |  187     GLenum type = 0; | 
|  185     GLenum internal_format = 0; |  188     GLenum internal_format = 0; | 
|  186     if (!texture_->GetLevelType(target_, level_, &type, &internal_format)) { |  189     if (!texture_ref_->texture()->GetLevelType( | 
 |  190         target_, level_, &type, &internal_format)) { | 
|  187       return false; |  191       return false; | 
|  188     } |  192     } | 
|  189     uint32 need = GLES2Util::GetChannelsNeededForAttachmentType( |  193     uint32 need = GLES2Util::GetChannelsNeededForAttachmentType( | 
|  190         attachment_type, max_color_attachments); |  194         attachment_type, max_color_attachments); | 
|  191     uint32 have = GLES2Util::GetChannelsForFormat(internal_format); |  195     uint32 have = GLES2Util::GetChannelsForFormat(internal_format); | 
|  192     return (need & have) != 0; |  196     return (need & have) != 0; | 
|  193   } |  197   } | 
|  194  |  198  | 
|  195   virtual void AddToSignature( |  199   virtual void AddToSignature( | 
|  196       TextureManager* texture_manager, std::string* signature) const OVERRIDE { |  200       TextureManager* texture_manager, std::string* signature) const OVERRIDE { | 
|  197     DCHECK(signature); |  201     DCHECK(signature); | 
|  198     texture_manager->AddToSignature(texture_, target_, level_, signature); |  202     texture_manager->AddToSignature(texture_ref_, target_, level_, signature); | 
|  199   } |  203   } | 
|  200  |  204  | 
|  201  protected: |  205  protected: | 
|  202   virtual ~TextureAttachment() {} |  206   virtual ~TextureAttachment() {} | 
|  203  |  207  | 
|  204  private: |  208  private: | 
|  205   scoped_refptr<Texture> texture_; |  209   scoped_refptr<TextureRef> texture_ref_; | 
|  206   GLenum target_; |  210   GLenum target_; | 
|  207   GLint level_; |  211   GLint level_; | 
|  208  |  212  | 
|  209   DISALLOW_COPY_AND_ASSIGN(TextureAttachment); |  213   DISALLOW_COPY_AND_ASSIGN(TextureAttachment); | 
|  210 }; |  214 }; | 
|  211  |  215  | 
|  212 FramebufferManager::FramebufferManager( |  216 FramebufferManager::FramebufferManager( | 
|  213     uint32 max_draw_buffers, uint32 max_color_attachments) |  217     uint32 max_draw_buffers, uint32 max_color_attachments) | 
|  214     : framebuffer_state_change_count_(1), |  218     : framebuffer_state_change_count_(1), | 
|  215       framebuffer_count_(0), |  219       framebuffer_count_(0), | 
| (...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  459         // glFramebufferRenderbufferEXT(target, it->first, GL_RENDERBUFFER, 0); |  463         // glFramebufferRenderbufferEXT(target, it->first, GL_RENDERBUFFER, 0); | 
|  460         AttachRenderbuffer(it->first, NULL); |  464         AttachRenderbuffer(it->first, NULL); | 
|  461         done = false; |  465         done = false; | 
|  462         break; |  466         break; | 
|  463       } |  467       } | 
|  464     } |  468     } | 
|  465   } while (!done); |  469   } while (!done); | 
|  466 } |  470 } | 
|  467  |  471  | 
|  468 void Framebuffer::UnbindTexture( |  472 void Framebuffer::UnbindTexture( | 
|  469     GLenum target, Texture* texture) { |  473     GLenum target, TextureRef* texture_ref) { | 
|  470   bool done; |  474   bool done; | 
|  471   do { |  475   do { | 
|  472     done = true; |  476     done = true; | 
|  473     for (AttachmentMap::const_iterator it = attachments_.begin(); |  477     for (AttachmentMap::const_iterator it = attachments_.begin(); | 
|  474          it != attachments_.end(); ++it) { |  478          it != attachments_.end(); ++it) { | 
|  475       Attachment* attachment = it->second; |  479       Attachment* attachment = it->second; | 
|  476       if (attachment->IsTexture(texture)) { |  480       if (attachment->IsTexture(texture_ref)) { | 
|  477         // TODO(gman): manually detach texture. |  481         // TODO(gman): manually detach texture. | 
|  478         // glFramebufferTexture2DEXT(target, it->first, GL_TEXTURE_2D, 0, 0); |  482         // glFramebufferTexture2DEXT(target, it->first, GL_TEXTURE_2D, 0, 0); | 
|  479         AttachTexture(it->first, NULL, GL_TEXTURE_2D, 0); |  483         AttachTexture(it->first, NULL, GL_TEXTURE_2D, 0); | 
|  480         done = false; |  484         done = false; | 
|  481         break; |  485         break; | 
|  482       } |  486       } | 
|  483     } |  487     } | 
|  484   } while (!done); |  488   } while (!done); | 
|  485 } |  489 } | 
|  486  |  490  | 
| (...skipping 19 matching lines...) Expand all  Loading... | 
|  506   if (renderbuffer) { |  510   if (renderbuffer) { | 
|  507     attachments_[attachment] = scoped_refptr<Attachment>( |  511     attachments_[attachment] = scoped_refptr<Attachment>( | 
|  508         new RenderbufferAttachment(renderbuffer)); |  512         new RenderbufferAttachment(renderbuffer)); | 
|  509   } else { |  513   } else { | 
|  510     attachments_.erase(attachment); |  514     attachments_.erase(attachment); | 
|  511   } |  515   } | 
|  512   framebuffer_complete_state_count_id_ = 0; |  516   framebuffer_complete_state_count_id_ = 0; | 
|  513 } |  517 } | 
|  514  |  518  | 
|  515 void Framebuffer::AttachTexture( |  519 void Framebuffer::AttachTexture( | 
|  516     GLenum attachment, Texture* texture, GLenum target, |  520     GLenum attachment, TextureRef* texture_ref, GLenum target, | 
|  517     GLint level) { |  521     GLint level) { | 
|  518   const Attachment* a = GetAttachment(attachment); |  522   const Attachment* a = GetAttachment(attachment); | 
|  519   if (a) |  523   if (a) | 
|  520     a->DetachFromFramebuffer(); |  524     a->DetachFromFramebuffer(); | 
|  521   if (texture) { |  525   if (texture_ref) { | 
|  522     attachments_[attachment] = scoped_refptr<Attachment>( |  526     attachments_[attachment] = scoped_refptr<Attachment>( | 
|  523         new TextureAttachment(texture, target, level)); |  527         new TextureAttachment(texture_ref, target, level)); | 
|  524     texture->AttachToFramebuffer(); |  528     texture_ref->texture()->AttachToFramebuffer(); | 
|  525   } else { |  529   } else { | 
|  526     attachments_.erase(attachment); |  530     attachments_.erase(attachment); | 
|  527   } |  531   } | 
|  528   framebuffer_complete_state_count_id_ = 0; |  532   framebuffer_complete_state_count_id_ = 0; | 
|  529 } |  533 } | 
|  530  |  534  | 
|  531 const Framebuffer::Attachment* |  535 const Framebuffer::Attachment* | 
|  532     Framebuffer::GetAttachment( |  536     Framebuffer::GetAttachment( | 
|  533         GLenum attachment) const { |  537         GLenum attachment) const { | 
|  534   AttachmentMap::const_iterator it = attachments_.find(attachment); |  538   AttachmentMap::const_iterator it = attachments_.find(attachment); | 
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  572     Framebuffer* framebuffer) { |  576     Framebuffer* framebuffer) { | 
|  573   DCHECK(framebuffer); |  577   DCHECK(framebuffer); | 
|  574   return framebuffer->framebuffer_complete_state_count_id() == |  578   return framebuffer->framebuffer_complete_state_count_id() == | 
|  575       framebuffer_state_change_count_; |  579       framebuffer_state_change_count_; | 
|  576 } |  580 } | 
|  577  |  581  | 
|  578 }  // namespace gles2 |  582 }  // namespace gles2 | 
|  579 }  // namespace gpu |  583 }  // namespace gpu | 
|  580  |  584  | 
|  581  |  585  | 
| OLD | NEW |