| 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/strings/stringprintf.h" | 7 #include "base/strings/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/framebuffer_completeness_cache.h" | 9 #include "gpu/command_buffer/service/framebuffer_completeness_cache.h" |
| 10 #include "gpu/command_buffer/service/renderbuffer_manager.h" | 10 #include "gpu/command_buffer/service/renderbuffer_manager.h" |
| (...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 352 return false; | 352 return false; |
| 353 } | 353 } |
| 354 | 354 |
| 355 void Framebuffer::ChangeDrawBuffersHelper(bool recover) const { | 355 void Framebuffer::ChangeDrawBuffersHelper(bool recover) const { |
| 356 scoped_ptr<GLenum[]> buffers(new GLenum[manager_->max_draw_buffers_]); | 356 scoped_ptr<GLenum[]> buffers(new GLenum[manager_->max_draw_buffers_]); |
| 357 for (uint32 i = 0; i < manager_->max_draw_buffers_; ++i) | 357 for (uint32 i = 0; i < manager_->max_draw_buffers_; ++i) |
| 358 buffers[i] = GL_NONE; | 358 buffers[i] = GL_NONE; |
| 359 for (AttachmentMap::const_iterator it = attachments_.begin(); | 359 for (AttachmentMap::const_iterator it = attachments_.begin(); |
| 360 it != attachments_.end(); ++it) { | 360 it != attachments_.end(); ++it) { |
| 361 if (it->first >= GL_COLOR_ATTACHMENT0 && | 361 if (it->first >= GL_COLOR_ATTACHMENT0 && |
| 362 it->first < GL_COLOR_ATTACHMENT0 + manager_->max_draw_buffers_) { | 362 it->first < GL_COLOR_ATTACHMENT0 + manager_->max_draw_buffers_ && |
| 363 !GLES2Util::IsIntegerFormat(it->second->internal_format())) { |
| 363 buffers[it->first - GL_COLOR_ATTACHMENT0] = it->first; | 364 buffers[it->first - GL_COLOR_ATTACHMENT0] = it->first; |
| 364 } | 365 } |
| 365 } | 366 } |
| 366 bool different = false; | 367 bool different = false; |
| 367 for (uint32 i = 0; i < manager_->max_draw_buffers_; ++i) { | 368 for (uint32 i = 0; i < manager_->max_draw_buffers_; ++i) { |
| 368 if (buffers[i] != draw_buffers_[i]) { | 369 if (buffers[i] != draw_buffers_[i]) { |
| 369 different = true; | 370 different = true; |
| 370 break; | 371 break; |
| 371 } | 372 } |
| 372 } | 373 } |
| 373 if (different) { | 374 if (different) { |
| 374 if (recover) | 375 if (recover) |
| 375 glDrawBuffersARB(manager_->max_draw_buffers_, draw_buffers_.get()); | 376 glDrawBuffersARB(manager_->max_draw_buffers_, draw_buffers_.get()); |
| 376 else | 377 else |
| 377 glDrawBuffersARB(manager_->max_draw_buffers_, buffers.get()); | 378 glDrawBuffersARB(manager_->max_draw_buffers_, buffers.get()); |
| 378 } | 379 } |
| 379 } | 380 } |
| 380 | 381 |
| 381 void Framebuffer::PrepareDrawBuffersForClear() const { | 382 void Framebuffer::PrepareDrawBuffersForClear() const { |
| 382 bool recover = false; | 383 bool recover = false; |
| 383 ChangeDrawBuffersHelper(recover); | 384 ChangeDrawBuffersHelper(recover); |
| 384 } | 385 } |
| 385 | 386 |
| 386 void Framebuffer::RestoreDrawBuffersAfterClear() const { | 387 void Framebuffer::RestoreDrawBuffersAfterClear() const { |
| 387 bool recover = true; | 388 bool recover = true; |
| 388 ChangeDrawBuffersHelper(recover); | 389 ChangeDrawBuffersHelper(recover); |
| 389 } | 390 } |
| 390 | 391 |
| 392 void Framebuffer::ClearIntegerBuffers() { |
| 393 for (AttachmentMap::const_iterator it = attachments_.begin(); |
| 394 it != attachments_.end(); ++it) { |
| 395 GLenum internal_format = it->second->internal_format(); |
| 396 if (it->first >= GL_COLOR_ATTACHMENT0 && |
| 397 it->first < GL_COLOR_ATTACHMENT0 + manager_->max_draw_buffers_ && |
| 398 !it->second->cleared() && |
| 399 GLES2Util::IsIntegerFormat(internal_format)) { |
| 400 GLint drawbuffer = it->first - GL_COLOR_ATTACHMENT0; |
| 401 if (GLES2Util::IsUnsignedIntegerFormat(internal_format)) { |
| 402 const static GLuint kZero[] = { 0u, 0u, 0u, 0u }; |
| 403 glClearBufferuiv(GL_COLOR, drawbuffer, kZero); |
| 404 } else { // IsUnsignedIntegerFormat(internal_format) |
| 405 const static GLint kZero[] = { 0, 0, 0, 0 }; |
| 406 glClearBufferiv(GL_COLOR, drawbuffer, kZero); |
| 407 } |
| 408 } |
| 409 } |
| 410 } |
| 411 |
| 391 void Framebuffer::MarkAttachmentAsCleared( | 412 void Framebuffer::MarkAttachmentAsCleared( |
| 392 RenderbufferManager* renderbuffer_manager, | 413 RenderbufferManager* renderbuffer_manager, |
| 393 TextureManager* texture_manager, | 414 TextureManager* texture_manager, |
| 394 GLenum attachment, | 415 GLenum attachment, |
| 395 bool cleared) { | 416 bool cleared) { |
| 396 AttachmentMap::iterator it = attachments_.find(attachment); | 417 AttachmentMap::iterator it = attachments_.find(attachment); |
| 397 if (it != attachments_.end()) { | 418 if (it != attachments_.end()) { |
| 398 Attachment* a = it->second.get(); | 419 Attachment* a = it->second.get(); |
| 399 if (a->cleared() != cleared) { | 420 if (a->cleared() != cleared) { |
| 400 a->SetCleared(renderbuffer_manager, | 421 a->SetCleared(renderbuffer_manager, |
| (...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 689 const Framebuffer::Attachment* Framebuffer::GetReadBufferAttachment() const { | 710 const Framebuffer::Attachment* Framebuffer::GetReadBufferAttachment() const { |
| 690 if (read_buffer_ == GL_NONE) | 711 if (read_buffer_ == GL_NONE) |
| 691 return nullptr; | 712 return nullptr; |
| 692 return GetAttachment(read_buffer_); | 713 return GetAttachment(read_buffer_); |
| 693 } | 714 } |
| 694 | 715 |
| 695 void Framebuffer::OnTextureRefDetached(TextureRef* texture) { | 716 void Framebuffer::OnTextureRefDetached(TextureRef* texture) { |
| 696 manager_->OnTextureRefDetached(texture); | 717 manager_->OnTextureRefDetached(texture); |
| 697 } | 718 } |
| 698 | 719 |
| 699 void Framebuffer::OnWillRenderTo() const { | 720 void Framebuffer::OnWillRenderTo(GLenum attachment) const { |
| 700 for (AttachmentMap::const_iterator it = attachments_.begin(); | 721 for (AttachmentMap::const_iterator it = attachments_.begin(); |
| 701 it != attachments_.end(); ++it) { | 722 it != attachments_.end(); ++it) { |
| 702 it->second->OnWillRenderTo(); | 723 if (attachment == 0 || attachment == it->first) { |
| 724 it->second->OnWillRenderTo(); |
| 725 } |
| 703 } | 726 } |
| 704 } | 727 } |
| 705 | 728 |
| 706 void Framebuffer::OnDidRenderTo() const { | 729 void Framebuffer::OnDidRenderTo(GLenum attachment) const { |
| 707 for (AttachmentMap::const_iterator it = attachments_.begin(); | 730 for (AttachmentMap::const_iterator it = attachments_.begin(); |
| 708 it != attachments_.end(); ++it) { | 731 it != attachments_.end(); ++it) { |
| 709 it->second->OnDidRenderTo(); | 732 if (attachment == 0 || attachment == it->first) { |
| 733 it->second->OnDidRenderTo(); |
| 734 } |
| 710 } | 735 } |
| 711 } | 736 } |
| 712 | 737 |
| 713 bool FramebufferManager::GetClientId( | 738 bool FramebufferManager::GetClientId( |
| 714 GLuint service_id, GLuint* client_id) const { | 739 GLuint service_id, GLuint* client_id) const { |
| 715 // This doesn't need to be fast. It's only used during slow queries. | 740 // This doesn't need to be fast. It's only used during slow queries. |
| 716 for (FramebufferMap::const_iterator it = framebuffers_.begin(); | 741 for (FramebufferMap::const_iterator it = framebuffers_.begin(); |
| 717 it != framebuffers_.end(); ++it) { | 742 it != framebuffers_.end(); ++it) { |
| 718 if (it->second->service_id() == service_id) { | 743 if (it->second->service_id() == service_id) { |
| 719 *client_id = it->first; | 744 *client_id = it->first; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 752 texture_detach_observers_.begin(); | 777 texture_detach_observers_.begin(); |
| 753 it != texture_detach_observers_.end(); | 778 it != texture_detach_observers_.end(); |
| 754 ++it) { | 779 ++it) { |
| 755 TextureDetachObserver* observer = *it; | 780 TextureDetachObserver* observer = *it; |
| 756 observer->OnTextureRefDetachedFromFramebuffer(texture); | 781 observer->OnTextureRefDetachedFromFramebuffer(texture); |
| 757 } | 782 } |
| 758 } | 783 } |
| 759 | 784 |
| 760 } // namespace gles2 | 785 } // namespace gles2 |
| 761 } // namespace gpu | 786 } // namespace gpu |
| OLD | NEW |