Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(398)

Side by Side Diff: gpu/command_buffer/service/framebuffer_manager.cc

Issue 2142353002: Validate fbo color image format and fragment shader output variable type. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 359 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 : manager_(manager), 370 : manager_(manager),
371 deleted_(false), 371 deleted_(false),
372 service_id_(service_id), 372 service_id_(service_id),
373 has_been_bound_(false), 373 has_been_bound_(false),
374 framebuffer_complete_state_count_id_(0), 374 framebuffer_complete_state_count_id_(0),
375 read_buffer_(GL_COLOR_ATTACHMENT0) { 375 read_buffer_(GL_COLOR_ATTACHMENT0) {
376 manager->StartTracking(this); 376 manager->StartTracking(this);
377 DCHECK_GT(manager->max_draw_buffers_, 0u); 377 DCHECK_GT(manager->max_draw_buffers_, 0u);
378 draw_buffers_.reset(new GLenum[manager->max_draw_buffers_]); 378 draw_buffers_.reset(new GLenum[manager->max_draw_buffers_]);
379 draw_buffers_[0] = GL_COLOR_ATTACHMENT0; 379 draw_buffers_[0] = GL_COLOR_ATTACHMENT0;
380 for (uint32_t i = 1; i < manager->max_draw_buffers_; ++i) 380 for (uint32_t ii = 1; ii < manager->max_draw_buffers_; ++ii) {
381 draw_buffers_[i] = GL_NONE; 381 draw_buffers_[ii] = GL_NONE;
382 }
383
384 color_attachment_base_types_.resize(manager->max_draw_buffers_);
385 ResetColorAttachmentBaseTypes();
382 } 386 }
383 387
384 Framebuffer::~Framebuffer() { 388 Framebuffer::~Framebuffer() {
385 if (manager_) { 389 if (manager_) {
386 if (manager_->have_context_) { 390 if (manager_->have_context_) {
387 GLuint id = service_id(); 391 GLuint id = service_id();
388 glDeleteFramebuffersEXT(1, &id); 392 glDeleteFramebuffersEXT(1, &id);
389 } 393 }
390 manager_->StopTracking(this); 394 manager_->StopTracking(this);
391 manager_ = NULL; 395 manager_ = NULL;
392 } 396 }
393 } 397 }
394 398
399 void Framebuffer::ResetColorAttachmentBaseTypes() {
400 for (size_t ii = 1; ii < color_attachment_base_types_.size(); ++ii) {
401 color_attachment_base_types_[ii] = SHADER_VARIABLE_UNDEFINED_TYPE;
402 }
403 }
404
395 bool Framebuffer::HasUnclearedAttachment( 405 bool Framebuffer::HasUnclearedAttachment(
396 GLenum attachment) const { 406 GLenum attachment) const {
397 AttachmentMap::const_iterator it = 407 AttachmentMap::const_iterator it =
398 attachments_.find(attachment); 408 attachments_.find(attachment);
399 if (it != attachments_.end()) { 409 if (it != attachments_.end()) {
400 const Attachment* attachment = it->second.get(); 410 const Attachment* attachment = it->second.get();
401 return !attachment->cleared(); 411 return !attachment->cleared();
402 } 412 }
403 return false; 413 return false;
404 } 414 }
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
493 if (buffers[i] != draw_buffers_[i]) { 503 if (buffers[i] != draw_buffers_[i]) {
494 different = true; 504 different = true;
495 break; 505 break;
496 } 506 }
497 } 507 }
498 if (different) 508 if (different)
499 glDrawBuffersARB(manager_->max_draw_buffers_, buffers.get()); 509 glDrawBuffersARB(manager_->max_draw_buffers_, buffers.get());
500 return different; 510 return different;
501 } 511 }
502 512
503 void Framebuffer::RestoreDrawBuffersAfterClear() const { 513 void Framebuffer::RestoreDrawBuffers() const {
504 glDrawBuffersARB(manager_->max_draw_buffers_, draw_buffers_.get()); 514 glDrawBuffersARB(manager_->max_draw_buffers_, draw_buffers_.get());
505 } 515 }
506 516
507 void Framebuffer::ClearUnclearedIntOr3DTexturesOrPartiallyClearedTextures( 517 void Framebuffer::ClearUnclearedIntOr3DTexturesOrPartiallyClearedTextures(
508 GLES2Decoder* decoder, 518 GLES2Decoder* decoder,
509 TextureManager* texture_manager) { 519 TextureManager* texture_manager) {
510 for (AttachmentMap::const_iterator it = attachments_.begin(); 520 for (AttachmentMap::const_iterator it = attachments_.begin();
511 it != attachments_.end(); ++it) { 521 it != attachments_.end(); ++it) {
512 if (!it->second->IsTextureAttachment() || it->second->cleared()) 522 if (!it->second->IsTextureAttachment() || it->second->cleared())
513 continue; 523 continue;
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after
811 // TODO(gman): manually detach texture. 821 // TODO(gman): manually detach texture.
812 // glFramebufferTexture2DEXT(target, it->first, GL_TEXTURE_2D, 0, 0); 822 // glFramebufferTexture2DEXT(target, it->first, GL_TEXTURE_2D, 0, 0);
813 AttachTexture(it->first, NULL, GL_TEXTURE_2D, 0, 0); 823 AttachTexture(it->first, NULL, GL_TEXTURE_2D, 0, 0);
814 done = false; 824 done = false;
815 break; 825 break;
816 } 826 }
817 } 827 }
818 } while (!done); 828 } while (!done);
819 } 829 }
820 830
831 void Framebuffer::UpdateColorAttachmentBaseTypes() {
832 ResetColorAttachmentBaseTypes();
833 for (AttachmentMap::const_iterator it = attachments_.begin();
834 it != attachments_.end(); ++it) {
835 if (it->first < GL_COLOR_ATTACHMENT0 ||
836 it->first >= GL_COLOR_ATTACHMENT0 + manager_->max_draw_buffers_) {
837 continue;
838 }
839 size_t index = it->first - GL_COLOR_ATTACHMENT0;
840 Attachment* attachment = it->second.get();
841 GLenum internal_format = attachment->internal_format();
842 if (GLES2Util::IsSignedIntegerFormat(internal_format)) {
843 color_attachment_base_types_[index] = SHADER_VARIABLE_INT;
844 } else if (GLES2Util::IsUnsignedIntegerFormat(internal_format)) {
845 color_attachment_base_types_[index] = SHADER_VARIABLE_UINT;
846 } else {
847 color_attachment_base_types_[index] = SHADER_VARIABLE_FLOAT;
848 }
849 }
850 }
851
821 Framebuffer* FramebufferManager::GetFramebuffer( 852 Framebuffer* FramebufferManager::GetFramebuffer(
822 GLuint client_id) { 853 GLuint client_id) {
823 FramebufferMap::iterator it = framebuffers_.find(client_id); 854 FramebufferMap::iterator it = framebuffers_.find(client_id);
824 return it != framebuffers_.end() ? it->second.get() : NULL; 855 return it != framebuffers_.end() ? it->second.get() : NULL;
825 } 856 }
826 857
827 void FramebufferManager::RemoveFramebuffer(GLuint client_id) { 858 void FramebufferManager::RemoveFramebuffer(GLuint client_id) {
828 FramebufferMap::iterator it = framebuffers_.find(client_id); 859 FramebufferMap::iterator it = framebuffers_.find(client_id);
829 if (it != framebuffers_.end()) { 860 if (it != framebuffers_.end()) {
830 it->second->MarkAsDeleted(); 861 it->second->MarkAsDeleted();
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
934 965
935 bool FramebufferManager::IsComplete( 966 bool FramebufferManager::IsComplete(
936 Framebuffer* framebuffer) { 967 Framebuffer* framebuffer) {
937 DCHECK(framebuffer); 968 DCHECK(framebuffer);
938 return framebuffer->framebuffer_complete_state_count_id() == 969 return framebuffer->framebuffer_complete_state_count_id() ==
939 framebuffer_state_change_count_; 970 framebuffer_state_change_count_;
940 } 971 }
941 972
942 } // namespace gles2 973 } // namespace gles2
943 } // namespace gpu 974 } // namespace gpu
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698