| 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 |
| 7 #include <stddef.h> |
| 8 #include <stdint.h> |
| 9 |
| 6 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/macros.h" |
| 7 #include "base/strings/stringprintf.h" | 12 #include "base/strings/stringprintf.h" |
| 8 #include "gpu/command_buffer/common/gles2_cmd_utils.h" | 13 #include "gpu/command_buffer/common/gles2_cmd_utils.h" |
| 9 #include "gpu/command_buffer/service/framebuffer_completeness_cache.h" | 14 #include "gpu/command_buffer/service/framebuffer_completeness_cache.h" |
| 10 #include "gpu/command_buffer/service/renderbuffer_manager.h" | 15 #include "gpu/command_buffer/service/renderbuffer_manager.h" |
| 11 #include "gpu/command_buffer/service/texture_manager.h" | 16 #include "gpu/command_buffer/service/texture_manager.h" |
| 12 #include "ui/gl/gl_bindings.h" | 17 #include "ui/gl/gl_bindings.h" |
| 13 | 18 |
| 14 namespace gpu { | 19 namespace gpu { |
| 15 namespace gles2 { | 20 namespace gles2 { |
| 16 | 21 |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 return renderbuffer_.get() == renderbuffer; | 67 return renderbuffer_.get() == renderbuffer; |
| 63 } | 68 } |
| 64 | 69 |
| 65 bool CanRenderTo() const override { return true; } | 70 bool CanRenderTo() const override { return true; } |
| 66 | 71 |
| 67 void DetachFromFramebuffer(Framebuffer* framebuffer) const override { | 72 void DetachFromFramebuffer(Framebuffer* framebuffer) const override { |
| 68 // Nothing to do for renderbuffers. | 73 // Nothing to do for renderbuffers. |
| 69 } | 74 } |
| 70 | 75 |
| 71 bool ValidForAttachmentType(GLenum attachment_type, | 76 bool ValidForAttachmentType(GLenum attachment_type, |
| 72 uint32 max_color_attachments) override { | 77 uint32_t max_color_attachments) override { |
| 73 uint32 need = GLES2Util::GetChannelsNeededForAttachmentType( | 78 uint32_t need = GLES2Util::GetChannelsNeededForAttachmentType( |
| 74 attachment_type, max_color_attachments); | 79 attachment_type, max_color_attachments); |
| 75 uint32 have = GLES2Util::GetChannelsForFormat(internal_format()); | 80 uint32_t have = GLES2Util::GetChannelsForFormat(internal_format()); |
| 76 return (need & have) != 0; | 81 return (need & have) != 0; |
| 77 } | 82 } |
| 78 | 83 |
| 79 Renderbuffer* renderbuffer() const { | 84 Renderbuffer* renderbuffer() const { |
| 80 return renderbuffer_.get(); | 85 return renderbuffer_.get(); |
| 81 } | 86 } |
| 82 | 87 |
| 83 size_t GetSignatureSize(TextureManager* texture_manager) const override { | 88 size_t GetSignatureSize(TextureManager* texture_manager) const override { |
| 84 return renderbuffer_->GetSignatureSize(); | 89 return renderbuffer_->GetSignatureSize(); |
| 85 } | 90 } |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 | 185 |
| 181 bool CanRenderTo() const override { | 186 bool CanRenderTo() const override { |
| 182 return texture_ref_->texture()->CanRenderTo(); | 187 return texture_ref_->texture()->CanRenderTo(); |
| 183 } | 188 } |
| 184 | 189 |
| 185 void DetachFromFramebuffer(Framebuffer* framebuffer) const override { | 190 void DetachFromFramebuffer(Framebuffer* framebuffer) const override { |
| 186 texture_ref_->texture()->DetachFromFramebuffer(); | 191 texture_ref_->texture()->DetachFromFramebuffer(); |
| 187 } | 192 } |
| 188 | 193 |
| 189 bool ValidForAttachmentType(GLenum attachment_type, | 194 bool ValidForAttachmentType(GLenum attachment_type, |
| 190 uint32 max_color_attachments) override { | 195 uint32_t max_color_attachments) override { |
| 191 GLenum type = 0; | 196 GLenum type = 0; |
| 192 GLenum internal_format = 0; | 197 GLenum internal_format = 0; |
| 193 if (!texture_ref_->texture()->GetLevelType( | 198 if (!texture_ref_->texture()->GetLevelType( |
| 194 target_, level_, &type, &internal_format)) { | 199 target_, level_, &type, &internal_format)) { |
| 195 return false; | 200 return false; |
| 196 } | 201 } |
| 197 uint32 need = GLES2Util::GetChannelsNeededForAttachmentType( | 202 uint32_t need = GLES2Util::GetChannelsNeededForAttachmentType( |
| 198 attachment_type, max_color_attachments); | 203 attachment_type, max_color_attachments); |
| 199 uint32 have = GLES2Util::GetChannelsForFormat(internal_format); | 204 uint32_t have = GLES2Util::GetChannelsForFormat(internal_format); |
| 200 | 205 |
| 201 // Workaround for NVIDIA drivers that incorrectly expose these formats as | 206 // Workaround for NVIDIA drivers that incorrectly expose these formats as |
| 202 // renderable: | 207 // renderable: |
| 203 if (internal_format == GL_LUMINANCE || internal_format == GL_ALPHA || | 208 if (internal_format == GL_LUMINANCE || internal_format == GL_ALPHA || |
| 204 internal_format == GL_LUMINANCE_ALPHA) { | 209 internal_format == GL_LUMINANCE_ALPHA) { |
| 205 return false; | 210 return false; |
| 206 } | 211 } |
| 207 return (need & have) != 0; | 212 return (need & have) != 0; |
| 208 } | 213 } |
| 209 | 214 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 229 scoped_refptr<TextureRef> texture_ref_; | 234 scoped_refptr<TextureRef> texture_ref_; |
| 230 GLenum target_; | 235 GLenum target_; |
| 231 GLint level_; | 236 GLint level_; |
| 232 GLsizei samples_; | 237 GLsizei samples_; |
| 233 GLint layer_; | 238 GLint layer_; |
| 234 | 239 |
| 235 DISALLOW_COPY_AND_ASSIGN(TextureAttachment); | 240 DISALLOW_COPY_AND_ASSIGN(TextureAttachment); |
| 236 }; | 241 }; |
| 237 | 242 |
| 238 FramebufferManager::FramebufferManager( | 243 FramebufferManager::FramebufferManager( |
| 239 uint32 max_draw_buffers, | 244 uint32_t max_draw_buffers, |
| 240 uint32 max_color_attachments, | 245 uint32_t max_color_attachments, |
| 241 ContextType context_type, | 246 ContextType context_type, |
| 242 const scoped_refptr<FramebufferCompletenessCache>& | 247 const scoped_refptr<FramebufferCompletenessCache>& |
| 243 framebuffer_combo_complete_cache) | 248 framebuffer_combo_complete_cache) |
| 244 : framebuffer_state_change_count_(1), | 249 : framebuffer_state_change_count_(1), |
| 245 framebuffer_count_(0), | 250 framebuffer_count_(0), |
| 246 have_context_(true), | 251 have_context_(true), |
| 247 max_draw_buffers_(max_draw_buffers), | 252 max_draw_buffers_(max_draw_buffers), |
| 248 max_color_attachments_(max_color_attachments), | 253 max_color_attachments_(max_color_attachments), |
| 249 context_type_(context_type), | 254 context_type_(context_type), |
| 250 framebuffer_combo_complete_cache_(framebuffer_combo_complete_cache) { | 255 framebuffer_combo_complete_cache_(framebuffer_combo_complete_cache) { |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 299 : manager_(manager), | 304 : manager_(manager), |
| 300 deleted_(false), | 305 deleted_(false), |
| 301 service_id_(service_id), | 306 service_id_(service_id), |
| 302 has_been_bound_(false), | 307 has_been_bound_(false), |
| 303 framebuffer_complete_state_count_id_(0), | 308 framebuffer_complete_state_count_id_(0), |
| 304 read_buffer_(GL_COLOR_ATTACHMENT0) { | 309 read_buffer_(GL_COLOR_ATTACHMENT0) { |
| 305 manager->StartTracking(this); | 310 manager->StartTracking(this); |
| 306 DCHECK_GT(manager->max_draw_buffers_, 0u); | 311 DCHECK_GT(manager->max_draw_buffers_, 0u); |
| 307 draw_buffers_.reset(new GLenum[manager->max_draw_buffers_]); | 312 draw_buffers_.reset(new GLenum[manager->max_draw_buffers_]); |
| 308 draw_buffers_[0] = GL_COLOR_ATTACHMENT0; | 313 draw_buffers_[0] = GL_COLOR_ATTACHMENT0; |
| 309 for (uint32 i = 1; i < manager->max_draw_buffers_; ++i) | 314 for (uint32_t i = 1; i < manager->max_draw_buffers_; ++i) |
| 310 draw_buffers_[i] = GL_NONE; | 315 draw_buffers_[i] = GL_NONE; |
| 311 } | 316 } |
| 312 | 317 |
| 313 Framebuffer::~Framebuffer() { | 318 Framebuffer::~Framebuffer() { |
| 314 if (manager_) { | 319 if (manager_) { |
| 315 if (manager_->have_context_) { | 320 if (manager_->have_context_) { |
| 316 GLuint id = service_id(); | 321 GLuint id = service_id(); |
| 317 glDeleteFramebuffersEXT(1, &id); | 322 glDeleteFramebuffersEXT(1, &id); |
| 318 } | 323 } |
| 319 manager_->StopTracking(this); | 324 manager_->StopTracking(this); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 340 const Attachment* attachment = it->second.get(); | 345 const Attachment* attachment = it->second.get(); |
| 341 if (!attachment->cleared()) | 346 if (!attachment->cleared()) |
| 342 return true; | 347 return true; |
| 343 } | 348 } |
| 344 } | 349 } |
| 345 return false; | 350 return false; |
| 346 } | 351 } |
| 347 | 352 |
| 348 void Framebuffer::ChangeDrawBuffersHelper(bool recover) const { | 353 void Framebuffer::ChangeDrawBuffersHelper(bool recover) const { |
| 349 scoped_ptr<GLenum[]> buffers(new GLenum[manager_->max_draw_buffers_]); | 354 scoped_ptr<GLenum[]> buffers(new GLenum[manager_->max_draw_buffers_]); |
| 350 for (uint32 i = 0; i < manager_->max_draw_buffers_; ++i) | 355 for (uint32_t i = 0; i < manager_->max_draw_buffers_; ++i) |
| 351 buffers[i] = GL_NONE; | 356 buffers[i] = GL_NONE; |
| 352 for (AttachmentMap::const_iterator it = attachments_.begin(); | 357 for (AttachmentMap::const_iterator it = attachments_.begin(); |
| 353 it != attachments_.end(); ++it) { | 358 it != attachments_.end(); ++it) { |
| 354 if (it->first >= GL_COLOR_ATTACHMENT0 && | 359 if (it->first >= GL_COLOR_ATTACHMENT0 && |
| 355 it->first < GL_COLOR_ATTACHMENT0 + manager_->max_draw_buffers_ && | 360 it->first < GL_COLOR_ATTACHMENT0 + manager_->max_draw_buffers_ && |
| 356 !GLES2Util::IsIntegerFormat(it->second->internal_format())) { | 361 !GLES2Util::IsIntegerFormat(it->second->internal_format())) { |
| 357 buffers[it->first - GL_COLOR_ATTACHMENT0] = it->first; | 362 buffers[it->first - GL_COLOR_ATTACHMENT0] = it->first; |
| 358 } | 363 } |
| 359 } | 364 } |
| 360 bool different = false; | 365 bool different = false; |
| 361 for (uint32 i = 0; i < manager_->max_draw_buffers_; ++i) { | 366 for (uint32_t i = 0; i < manager_->max_draw_buffers_; ++i) { |
| 362 if (buffers[i] != draw_buffers_[i]) { | 367 if (buffers[i] != draw_buffers_[i]) { |
| 363 different = true; | 368 different = true; |
| 364 break; | 369 break; |
| 365 } | 370 } |
| 366 } | 371 } |
| 367 if (different) { | 372 if (different) { |
| 368 if (recover) | 373 if (recover) |
| 369 glDrawBuffersARB(manager_->max_draw_buffers_, draw_buffers_.get()); | 374 glDrawBuffersARB(manager_->max_draw_buffers_, draw_buffers_.get()); |
| 370 else | 375 else |
| 371 glDrawBuffersARB(manager_->max_draw_buffers_, buffers.get()); | 376 glDrawBuffersARB(manager_->max_draw_buffers_, buffers.get()); |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 563 return draw_buffers_[index]; | 568 return draw_buffers_[index]; |
| 564 } | 569 } |
| 565 | 570 |
| 566 void Framebuffer::SetDrawBuffers(GLsizei n, const GLenum* bufs) { | 571 void Framebuffer::SetDrawBuffers(GLsizei n, const GLenum* bufs) { |
| 567 DCHECK(n <= static_cast<GLsizei>(manager_->max_draw_buffers_)); | 572 DCHECK(n <= static_cast<GLsizei>(manager_->max_draw_buffers_)); |
| 568 for (GLsizei i = 0; i < n; ++i) | 573 for (GLsizei i = 0; i < n; ++i) |
| 569 draw_buffers_[i] = bufs[i]; | 574 draw_buffers_[i] = bufs[i]; |
| 570 } | 575 } |
| 571 | 576 |
| 572 bool Framebuffer::HasAlphaMRT() const { | 577 bool Framebuffer::HasAlphaMRT() const { |
| 573 for (uint32 i = 0; i < manager_->max_draw_buffers_; ++i) { | 578 for (uint32_t i = 0; i < manager_->max_draw_buffers_; ++i) { |
| 574 if (draw_buffers_[i] != GL_NONE) { | 579 if (draw_buffers_[i] != GL_NONE) { |
| 575 const Attachment* attachment = GetAttachment(draw_buffers_[i]); | 580 const Attachment* attachment = GetAttachment(draw_buffers_[i]); |
| 576 if (!attachment) | 581 if (!attachment) |
| 577 continue; | 582 continue; |
| 578 if ((GLES2Util::GetChannelsForFormat( | 583 if ((GLES2Util::GetChannelsForFormat( |
| 579 attachment->internal_format()) & 0x0008) != 0) | 584 attachment->internal_format()) & 0x0008) != 0) |
| 580 return true; | 585 return true; |
| 581 } | 586 } |
| 582 } | 587 } |
| 583 return false; | 588 return false; |
| 584 } | 589 } |
| 585 | 590 |
| 586 bool Framebuffer::HasSameInternalFormatsMRT() const { | 591 bool Framebuffer::HasSameInternalFormatsMRT() const { |
| 587 GLenum internal_format = 0; | 592 GLenum internal_format = 0; |
| 588 for (uint32 i = 0; i < manager_->max_draw_buffers_; ++i) { | 593 for (uint32_t i = 0; i < manager_->max_draw_buffers_; ++i) { |
| 589 if (draw_buffers_[i] != GL_NONE) { | 594 if (draw_buffers_[i] != GL_NONE) { |
| 590 const Attachment* attachment = GetAttachment(draw_buffers_[i]); | 595 const Attachment* attachment = GetAttachment(draw_buffers_[i]); |
| 591 if (!attachment) | 596 if (!attachment) |
| 592 continue; | 597 continue; |
| 593 if (!internal_format) { | 598 if (!internal_format) { |
| 594 internal_format = attachment->internal_format(); | 599 internal_format = attachment->internal_format(); |
| 595 } else if (internal_format != attachment->internal_format()) { | 600 } else if (internal_format != attachment->internal_format()) { |
| 596 return false; | 601 return false; |
| 597 } | 602 } |
| 598 } | 603 } |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 754 | 759 |
| 755 bool FramebufferManager::IsComplete( | 760 bool FramebufferManager::IsComplete( |
| 756 Framebuffer* framebuffer) { | 761 Framebuffer* framebuffer) { |
| 757 DCHECK(framebuffer); | 762 DCHECK(framebuffer); |
| 758 return framebuffer->framebuffer_complete_state_count_id() == | 763 return framebuffer->framebuffer_complete_state_count_id() == |
| 759 framebuffer_state_change_count_; | 764 framebuffer_state_change_count_; |
| 760 } | 765 } |
| 761 | 766 |
| 762 } // namespace gles2 | 767 } // namespace gles2 |
| 763 } // namespace gpu | 768 } // namespace gpu |
| OLD | NEW |