| 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 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 | 99 |
| 100 bool IsLayerValid() const override { return true; } | 100 bool IsLayerValid() const override { return true; } |
| 101 | 101 |
| 102 bool ValidForAttachmentType(GLenum attachment_type, | 102 bool ValidForAttachmentType(GLenum attachment_type, |
| 103 ContextType context_type, | 103 ContextType context_type, |
| 104 uint32_t max_color_attachments) override { | 104 uint32_t max_color_attachments) override { |
| 105 uint32_t need = GLES2Util::GetChannelsNeededForAttachmentType( | 105 uint32_t need = GLES2Util::GetChannelsNeededForAttachmentType( |
| 106 attachment_type, max_color_attachments); | 106 attachment_type, max_color_attachments); |
| 107 DCHECK_NE(0u, need); | 107 DCHECK_NE(0u, need); |
| 108 uint32_t have = GLES2Util::GetChannelsForFormat(internal_format()); | 108 uint32_t have = GLES2Util::GetChannelsForFormat(internal_format()); |
| 109 if (context_type == CONTEXT_TYPE_WEBGL1 && | 109 if (0 && context_type == CONTEXT_TYPE_WEBGL1 && |
| 110 DetectWebGL1DepthStencilAttachmentConflicts(need, have)) | 110 DetectWebGL1DepthStencilAttachmentConflicts(need, have)) |
| 111 return false; | 111 return false; |
| 112 return (need & have) != 0; | 112 return (need & have) != 0; |
| 113 } | 113 } |
| 114 | 114 |
| 115 Renderbuffer* renderbuffer() const { | 115 Renderbuffer* renderbuffer() const { |
| 116 return renderbuffer_.get(); | 116 return renderbuffer_.get(); |
| 117 } | 117 } |
| 118 | 118 |
| 119 size_t GetSignatureSize(TextureManager* texture_manager) const override { | 119 size_t GetSignatureSize(TextureManager* texture_manager) const override { |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 261 attachment_type, max_color_attachments); | 261 attachment_type, max_color_attachments); |
| 262 DCHECK_NE(0u, need); | 262 DCHECK_NE(0u, need); |
| 263 uint32_t have = GLES2Util::GetChannelsForFormat(internal_format); | 263 uint32_t have = GLES2Util::GetChannelsForFormat(internal_format); |
| 264 | 264 |
| 265 // Workaround for NVIDIA drivers that incorrectly expose these formats as | 265 // Workaround for NVIDIA drivers that incorrectly expose these formats as |
| 266 // renderable: | 266 // renderable: |
| 267 if (internal_format == GL_LUMINANCE || internal_format == GL_ALPHA || | 267 if (internal_format == GL_LUMINANCE || internal_format == GL_ALPHA || |
| 268 internal_format == GL_LUMINANCE_ALPHA) { | 268 internal_format == GL_LUMINANCE_ALPHA) { |
| 269 return false; | 269 return false; |
| 270 } | 270 } |
| 271 if (context_type == CONTEXT_TYPE_WEBGL1 && | 271 if (0 && context_type == CONTEXT_TYPE_WEBGL1 && |
| 272 DetectWebGL1DepthStencilAttachmentConflicts(need, have)) | 272 DetectWebGL1DepthStencilAttachmentConflicts(need, have)) |
| 273 return need == have; | 273 return need == have; |
| 274 return (need & have) != 0; | 274 return (need & have) != 0; |
| 275 } | 275 } |
| 276 | 276 |
| 277 size_t GetSignatureSize(TextureManager* texture_manager) const override { | 277 size_t GetSignatureSize(TextureManager* texture_manager) const override { |
| 278 return texture_manager->GetSignatureSize(); | 278 return texture_manager->GetSignatureSize(); |
| 279 } | 279 } |
| 280 | 280 |
| 281 void AddToSignature(TextureManager* texture_manager, | 281 void AddToSignature(TextureManager* texture_manager, |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 394 GLuint id = service_id(); | 394 GLuint id = service_id(); |
| 395 glDeleteFramebuffersEXT(1, &id); | 395 glDeleteFramebuffersEXT(1, &id); |
| 396 } | 396 } |
| 397 manager_->StopTracking(this); | 397 manager_->StopTracking(this); |
| 398 manager_ = NULL; | 398 manager_ = NULL; |
| 399 } | 399 } |
| 400 } | 400 } |
| 401 | 401 |
| 402 bool Framebuffer::HasUnclearedAttachment( | 402 bool Framebuffer::HasUnclearedAttachment( |
| 403 GLenum attachment) const { | 403 GLenum attachment) const { |
| 404 DCHECK(attachment != GL_DEPTH_STENCIL_ATTACHMENT); |
| 404 AttachmentMap::const_iterator it = | 405 AttachmentMap::const_iterator it = |
| 405 attachments_.find(attachment); | 406 attachments_.find(attachment); |
| 406 if (it != attachments_.end()) { | 407 if (it != attachments_.end()) { |
| 407 const Attachment* attachment = it->second.get(); | 408 const Attachment* attachment = it->second.get(); |
| 408 return !attachment->cleared(); | 409 return !attachment->cleared(); |
| 409 } | 410 } |
| 410 return false; | 411 return false; |
| 411 } | 412 } |
| 412 | 413 |
| 413 bool Framebuffer::HasUnclearedColorAttachments() const { | 414 bool Framebuffer::HasUnclearedColorAttachments() const { |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 557 attachment->level()); | 558 attachment->level()); |
| 558 } | 559 } |
| 559 } | 560 } |
| 560 } | 561 } |
| 561 | 562 |
| 562 void Framebuffer::MarkAttachmentAsCleared( | 563 void Framebuffer::MarkAttachmentAsCleared( |
| 563 RenderbufferManager* renderbuffer_manager, | 564 RenderbufferManager* renderbuffer_manager, |
| 564 TextureManager* texture_manager, | 565 TextureManager* texture_manager, |
| 565 GLenum attachment, | 566 GLenum attachment, |
| 566 bool cleared) { | 567 bool cleared) { |
| 568 DCHECK(attachment != GL_DEPTH_STENCIL_ATTACHMENT); |
| 567 AttachmentMap::iterator it = attachments_.find(attachment); | 569 AttachmentMap::iterator it = attachments_.find(attachment); |
| 568 if (it != attachments_.end()) { | 570 if (it != attachments_.end()) { |
| 569 Attachment* a = it->second.get(); | 571 Attachment* a = it->second.get(); |
| 570 if (a->cleared() != cleared) { | 572 if (a->cleared() != cleared) { |
| 571 a->SetCleared(renderbuffer_manager, | 573 a->SetCleared(renderbuffer_manager, |
| 572 texture_manager, | 574 texture_manager, |
| 573 cleared); | 575 cleared); |
| 574 } | 576 } |
| 575 } | 577 } |
| 576 } | 578 } |
| 577 | 579 |
| 578 void Framebuffer::MarkAttachmentsAsCleared( | 580 void Framebuffer::MarkAttachmentsAsCleared( |
| 579 RenderbufferManager* renderbuffer_manager, | 581 RenderbufferManager* renderbuffer_manager, |
| 580 TextureManager* texture_manager, | 582 TextureManager* texture_manager, |
| 581 bool cleared) { | 583 bool cleared) { |
| 582 for (AttachmentMap::iterator it = attachments_.begin(); | 584 for (AttachmentMap::iterator it = attachments_.begin(); |
| 583 it != attachments_.end(); ++it) { | 585 it != attachments_.end(); ++it) { |
| 586 DCHECK(it->first != GL_DEPTH_STENCIL_ATTACHMENT); |
| 584 Attachment* attachment = it->second.get(); | 587 Attachment* attachment = it->second.get(); |
| 585 if (attachment->cleared() != cleared) { | 588 if (attachment->cleared() != cleared) { |
| 586 attachment->SetCleared(renderbuffer_manager, texture_manager, cleared); | 589 attachment->SetCleared(renderbuffer_manager, texture_manager, cleared); |
| 587 } | 590 } |
| 588 } | 591 } |
| 589 } | 592 } |
| 590 | 593 |
| 591 bool Framebuffer::HasColorAttachment(int index) const { | 594 bool Framebuffer::HasColorAttachment(int index) const { |
| 592 return attachments_.find(GL_COLOR_ATTACHMENT0 + index) != attachments_.end(); | 595 return attachments_.find(GL_COLOR_ATTACHMENT0 + index) != attachments_.end(); |
| 593 } | 596 } |
| 594 | 597 |
| 595 bool Framebuffer::HasDepthAttachment() const { | 598 bool Framebuffer::HasDepthAttachment() const { |
| 596 return attachments_.find(GL_DEPTH_STENCIL_ATTACHMENT) != attachments_.end() || | 599 return attachments_.find(GL_DEPTH_ATTACHMENT) != attachments_.end(); |
| 597 attachments_.find(GL_DEPTH_ATTACHMENT) != attachments_.end(); | |
| 598 } | 600 } |
| 599 | 601 |
| 600 bool Framebuffer::HasStencilAttachment() const { | 602 bool Framebuffer::HasStencilAttachment() const { |
| 601 return attachments_.find(GL_DEPTH_STENCIL_ATTACHMENT) != attachments_.end() || | 603 return attachments_.find(GL_STENCIL_ATTACHMENT) != attachments_.end(); |
| 602 attachments_.find(GL_STENCIL_ATTACHMENT) != attachments_.end(); | |
| 603 } | 604 } |
| 604 | 605 |
| 605 GLenum Framebuffer::GetReadBufferInternalFormat() const { | 606 GLenum Framebuffer::GetReadBufferInternalFormat() const { |
| 606 if (read_buffer_ == GL_NONE) | 607 if (read_buffer_ == GL_NONE) |
| 607 return 0; | 608 return 0; |
| 608 AttachmentMap::const_iterator it = attachments_.find(read_buffer_); | 609 AttachmentMap::const_iterator it = attachments_.find(read_buffer_); |
| 609 if (it == attachments_.end()) { | 610 if (it == attachments_.end()) { |
| 610 return 0; | 611 return 0; |
| 611 } | 612 } |
| 612 const Attachment* attachment = it->second.get(); | 613 const Attachment* attachment = it->second.get(); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 632 // Assume the framebuffer is complete, so return any attachment's samples. | 633 // Assume the framebuffer is complete, so return any attachment's samples. |
| 633 auto iter = attachments_.begin(); | 634 auto iter = attachments_.begin(); |
| 634 if (iter == attachments_.end()) | 635 if (iter == attachments_.end()) |
| 635 return -1; | 636 return -1; |
| 636 Attachment* attachment = iter->second.get(); | 637 Attachment* attachment = iter->second.get(); |
| 637 DCHECK(attachment); | 638 DCHECK(attachment); |
| 638 return attachment->samples(); | 639 return attachment->samples(); |
| 639 } | 640 } |
| 640 | 641 |
| 641 GLenum Framebuffer::GetDepthFormat() const { | 642 GLenum Framebuffer::GetDepthFormat() const { |
| 642 auto iter = attachments_.find(GL_DEPTH_STENCIL_ATTACHMENT); | 643 auto iter = attachments_.find(GL_DEPTH_ATTACHMENT); |
| 643 if (iter == attachments_.end()) | |
| 644 iter = attachments_.find(GL_DEPTH_ATTACHMENT); | |
| 645 if (iter == attachments_.end()) | 644 if (iter == attachments_.end()) |
| 646 return 0; | 645 return 0; |
| 647 Attachment* attachment = iter->second.get(); | 646 Attachment* attachment = iter->second.get(); |
| 648 DCHECK(attachment); | 647 DCHECK(attachment); |
| 649 return attachment->internal_format(); | 648 return attachment->internal_format(); |
| 650 } | 649 } |
| 651 | 650 |
| 652 GLenum Framebuffer::GetStencilFormat() const { | 651 GLenum Framebuffer::GetStencilFormat() const { |
| 653 auto iter = attachments_.find(GL_DEPTH_STENCIL_ATTACHMENT); | 652 auto iter = attachments_.find(GL_STENCIL_ATTACHMENT); |
| 654 if (iter == attachments_.end()) | |
| 655 iter = attachments_.find(GL_STENCIL_ATTACHMENT); | |
| 656 if (iter == attachments_.end()) | 653 if (iter == attachments_.end()) |
| 657 return 0; | 654 return 0; |
| 658 Attachment* attachment = iter->second.get(); | 655 Attachment* attachment = iter->second.get(); |
| 659 DCHECK(attachment); | 656 DCHECK(attachment); |
| 660 return attachment->internal_format(); | 657 return attachment->internal_format(); |
| 661 } | 658 } |
| 662 | 659 |
| 663 GLenum Framebuffer::IsPossiblyComplete(const FeatureInfo* feature_info) const { | 660 GLenum Framebuffer::IsPossiblyComplete(const FeatureInfo* feature_info) const { |
| 664 if (attachments_.empty()) { | 661 if (attachments_.empty()) { |
| 665 return GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT; | 662 return GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT; |
| (...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 905 void Framebuffer::DoUnbindGLAttachmentsForWorkaround(GLenum target) { | 902 void Framebuffer::DoUnbindGLAttachmentsForWorkaround(GLenum target) { |
| 906 // Replace all attachments with the default Renderbuffer. | 903 // Replace all attachments with the default Renderbuffer. |
| 907 for (AttachmentMap::const_iterator it = attachments_.begin(); | 904 for (AttachmentMap::const_iterator it = attachments_.begin(); |
| 908 it != attachments_.end(); ++it) { | 905 it != attachments_.end(); ++it) { |
| 909 glFramebufferRenderbufferEXT(target, it->first, GL_RENDERBUFFER, 0); | 906 glFramebufferRenderbufferEXT(target, it->first, GL_RENDERBUFFER, 0); |
| 910 } | 907 } |
| 911 } | 908 } |
| 912 | 909 |
| 913 void Framebuffer::AttachRenderbuffer( | 910 void Framebuffer::AttachRenderbuffer( |
| 914 GLenum attachment, Renderbuffer* renderbuffer) { | 911 GLenum attachment, Renderbuffer* renderbuffer) { |
| 912 DCHECK(attachment != GL_DEPTH_STENCIL_ATTACHMENT); |
| 915 const Attachment* a = GetAttachment(attachment); | 913 const Attachment* a = GetAttachment(attachment); |
| 916 if (a) | 914 if (a) |
| 917 a->DetachFromFramebuffer(this); | 915 a->DetachFromFramebuffer(this); |
| 918 if (renderbuffer) { | 916 if (renderbuffer) { |
| 919 attachments_[attachment] = scoped_refptr<Attachment>( | 917 attachments_[attachment] = scoped_refptr<Attachment>( |
| 920 new RenderbufferAttachment(renderbuffer)); | 918 new RenderbufferAttachment(renderbuffer)); |
| 921 } else { | 919 } else { |
| 922 attachments_.erase(attachment); | 920 attachments_.erase(attachment); |
| 923 } | 921 } |
| 924 framebuffer_complete_state_count_id_ = 0; | 922 framebuffer_complete_state_count_id_ = 0; |
| 925 } | 923 } |
| 926 | 924 |
| 927 void Framebuffer::AttachTexture( | 925 void Framebuffer::AttachTexture( |
| 928 GLenum attachment, TextureRef* texture_ref, GLenum target, | 926 GLenum attachment, TextureRef* texture_ref, GLenum target, |
| 929 GLint level, GLsizei samples) { | 927 GLint level, GLsizei samples) { |
| 928 DCHECK(attachment != GL_DEPTH_STENCIL_ATTACHMENT); |
| 930 const Attachment* a = GetAttachment(attachment); | 929 const Attachment* a = GetAttachment(attachment); |
| 931 if (a) | 930 if (a) |
| 932 a->DetachFromFramebuffer(this); | 931 a->DetachFromFramebuffer(this); |
| 933 if (texture_ref) { | 932 if (texture_ref) { |
| 934 attachments_[attachment] = scoped_refptr<Attachment>( | 933 attachments_[attachment] = scoped_refptr<Attachment>( |
| 935 new TextureAttachment(texture_ref, target, level, samples, 0)); | 934 new TextureAttachment(texture_ref, target, level, samples, 0)); |
| 936 texture_ref->texture()->AttachToFramebuffer(); | 935 texture_ref->texture()->AttachToFramebuffer(); |
| 937 } else { | 936 } else { |
| 938 attachments_.erase(attachment); | 937 attachments_.erase(attachment); |
| 939 } | 938 } |
| 940 framebuffer_complete_state_count_id_ = 0; | 939 framebuffer_complete_state_count_id_ = 0; |
| 941 } | 940 } |
| 942 | 941 |
| 943 void Framebuffer::AttachTextureLayer( | 942 void Framebuffer::AttachTextureLayer( |
| 944 GLenum attachment, TextureRef* texture_ref, GLenum target, | 943 GLenum attachment, TextureRef* texture_ref, GLenum target, |
| 945 GLint level, GLint layer) { | 944 GLint level, GLint layer) { |
| 945 DCHECK(attachment != GL_DEPTH_STENCIL_ATTACHMENT); |
| 946 const Attachment* a = GetAttachment(attachment); | 946 const Attachment* a = GetAttachment(attachment); |
| 947 if (a) | 947 if (a) |
| 948 a->DetachFromFramebuffer(this); | 948 a->DetachFromFramebuffer(this); |
| 949 if (texture_ref) { | 949 if (texture_ref) { |
| 950 attachments_[attachment] = scoped_refptr<Attachment>( | 950 attachments_[attachment] = scoped_refptr<Attachment>( |
| 951 new TextureAttachment(texture_ref, target, level, 0, layer)); | 951 new TextureAttachment(texture_ref, target, level, 0, layer)); |
| 952 texture_ref->texture()->AttachToFramebuffer(); | 952 texture_ref->texture()->AttachToFramebuffer(); |
| 953 } else { | 953 } else { |
| 954 attachments_.erase(attachment); | 954 attachments_.erase(attachment); |
| 955 } | 955 } |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1004 | 1004 |
| 1005 bool FramebufferManager::IsComplete( | 1005 bool FramebufferManager::IsComplete( |
| 1006 Framebuffer* framebuffer) { | 1006 Framebuffer* framebuffer) { |
| 1007 DCHECK(framebuffer); | 1007 DCHECK(framebuffer); |
| 1008 return framebuffer->framebuffer_complete_state_count_id() == | 1008 return framebuffer->framebuffer_complete_state_count_id() == |
| 1009 framebuffer_state_change_count_; | 1009 framebuffer_state_change_count_; |
| 1010 } | 1010 } |
| 1011 | 1011 |
| 1012 } // namespace gles2 | 1012 } // namespace gles2 |
| 1013 } // namespace gpu | 1013 } // namespace gpu |
| OLD | NEW |