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

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

Issue 1605323004: Check if internal_format is valid for GenerateMipmap(). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 11 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/texture_manager.h" 5 #include "gpu/command_buffer/service/texture_manager.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
(...skipping 511 matching lines...) Expand 10 before | Expand all | Expand 10 after
522 signature->append(TextureTag, sizeof(TextureTag)); 522 signature->append(TextureTag, sizeof(TextureTag));
523 signature->append(reinterpret_cast<const char*>(&signature_data), 523 signature->append(reinterpret_cast<const char*>(&signature_data),
524 sizeof(signature_data)); 524 sizeof(signature_data));
525 } 525 }
526 526
527 void Texture::SetMailboxManager(MailboxManager* mailbox_manager) { 527 void Texture::SetMailboxManager(MailboxManager* mailbox_manager) {
528 DCHECK(!mailbox_manager_ || mailbox_manager_ == mailbox_manager); 528 DCHECK(!mailbox_manager_ || mailbox_manager_ == mailbox_manager);
529 mailbox_manager_ = mailbox_manager; 529 mailbox_manager_ = mailbox_manager;
530 } 530 }
531 531
532 bool Texture::MarkMipmapsGenerated( 532 void Texture::MarkMipmapsGenerated(
533 const FeatureInfo* feature_info) { 533 const FeatureInfo* feature_info) {
534 if (!CanGenerateMipmaps(feature_info)) { 534 DCHECK(CanGenerateMipmaps(feature_info));
535 return false;
536 }
537 for (size_t ii = 0; ii < face_infos_.size(); ++ii) { 535 for (size_t ii = 0; ii < face_infos_.size(); ++ii) {
538 const Texture::FaceInfo& face_info = face_infos_[ii]; 536 const Texture::FaceInfo& face_info = face_infos_[ii];
539 const Texture::LevelInfo& level0_info = face_info.level_infos[base_level_]; 537 const Texture::LevelInfo& level0_info = face_info.level_infos[base_level_];
540 GLsizei width = level0_info.width; 538 GLsizei width = level0_info.width;
541 GLsizei height = level0_info.height; 539 GLsizei height = level0_info.height;
542 GLsizei depth = level0_info.depth; 540 GLsizei depth = level0_info.depth;
543 GLenum target = target_ == GL_TEXTURE_2D ? GL_TEXTURE_2D : 541 GLenum target = target_ == GL_TEXTURE_2D ? GL_TEXTURE_2D :
544 GLES2Util::IndexToGLFaceTarget(ii); 542 GLES2Util::IndexToGLFaceTarget(ii);
545 543
546 const GLsizei num_mips = face_info.num_mip_levels; 544 const GLsizei num_mips = face_info.num_mip_levels;
547 for (GLsizei level = base_level_ + 1; 545 for (GLsizei level = base_level_ + 1;
548 level < base_level_ + num_mips; ++level) { 546 level < base_level_ + num_mips; ++level) {
549 width = std::max(1, width >> 1); 547 width = std::max(1, width >> 1);
550 height = std::max(1, height >> 1); 548 height = std::max(1, height >> 1);
551 depth = std::max(1, depth >> 1); 549 depth = std::max(1, depth >> 1);
552 SetLevelInfo(feature_info, target, level, level0_info.internal_format, 550 SetLevelInfo(feature_info, target, level, level0_info.internal_format,
553 width, height, depth, level0_info.border, level0_info.format, 551 width, height, depth, level0_info.border, level0_info.format,
554 level0_info.type, gfx::Rect(width, height)); 552 level0_info.type, gfx::Rect(width, height));
555 } 553 }
556 } 554 }
557
558 return true;
559 } 555 }
560 556
561 void Texture::SetTarget( 557 void Texture::SetTarget(
562 const FeatureInfo* feature_info, GLenum target, GLint max_levels) { 558 const FeatureInfo* feature_info, GLenum target, GLint max_levels) {
563 DCHECK_EQ(0u, target_); // you can only set this once. 559 DCHECK_EQ(0u, target_); // you can only set this once.
564 target_ = target; 560 target_ = target;
565 size_t num_faces = (target == GL_TEXTURE_CUBE_MAP) ? 6 : 1; 561 size_t num_faces = (target == GL_TEXTURE_CUBE_MAP) ? 6 : 1;
566 face_infos_.resize(num_faces); 562 face_infos_.resize(num_faces);
567 for (size_t ii = 0; ii < num_faces; ++ii) { 563 for (size_t ii = 0; ii < num_faces; ++ii) {
568 face_infos_[ii].level_infos.resize(max_levels); 564 face_infos_[ii].level_infos.resize(max_levels);
(...skipping 24 matching lines...) Expand all
593 return false; 589 return false;
594 } 590 }
595 591
596 // Can't generate mips for depth or stencil textures. 592 // Can't generate mips for depth or stencil textures.
597 const Texture::LevelInfo& base = face_infos_[0].level_infos[base_level_]; 593 const Texture::LevelInfo& base = face_infos_[0].level_infos[base_level_];
598 uint32_t channels = GLES2Util::GetChannelsForFormat(base.format); 594 uint32_t channels = GLES2Util::GetChannelsForFormat(base.format);
599 if (channels & (GLES2Util::kDepth | GLES2Util::kStencil)) { 595 if (channels & (GLES2Util::kDepth | GLES2Util::kStencil)) {
600 return false; 596 return false;
601 } 597 }
602 598
603 // TODO(gman): Check internal_format, format and type. 599 bool valid_internal_format = false;
600 if (feature_info->validators()->texture_unsized_internal_format.IsValid(
601 base.internal_format)) {
602 valid_internal_format = true;
603 } else if (feature_info->validators()->
604 texture_sized_color_renderable_internal_format.IsValid(
605 base.internal_format) && feature_info->validators()->
606 texture_sized_texture_filterable_internal_format.IsValid(
607 base.internal_format)) {
608 valid_internal_format = true;
609 }
610 if (!valid_internal_format) {
611 return false;
612 }
613
604 for (size_t ii = 0; ii < face_infos_.size(); ++ii) { 614 for (size_t ii = 0; ii < face_infos_.size(); ++ii) {
605 const LevelInfo& info = face_infos_[ii].level_infos[base_level_]; 615 const LevelInfo& info = face_infos_[ii].level_infos[base_level_];
606 if ((info.target == 0) || (info.width != base.width) || 616 if ((info.target == 0) ||
607 (info.height != base.height) || (info.depth != base.depth) ||
608 (info.format != base.format) ||
609 (info.internal_format != base.internal_format) ||
610 (info.type != base.type) ||
611 feature_info->validators()->compressed_texture_format.IsValid( 617 feature_info->validators()->compressed_texture_format.IsValid(
612 info.internal_format) || 618 info.internal_format) ||
613 info.image.get()) { 619 info.image.get()) {
614 return false; 620 return false;
615 } 621 }
616 } 622 }
623 if (face_infos_.size() == 6 && !cube_complete_) {
624 return false;
625 }
617 return true; 626 return true;
618 } 627 }
619 628
620 bool Texture::TextureIsNPOT(GLsizei width, 629 bool Texture::TextureIsNPOT(GLsizei width,
621 GLsizei height, 630 GLsizei height,
622 GLsizei depth) { 631 GLsizei depth) {
623 return (GLES2Util::IsNPOT(width) || 632 return (GLES2Util::IsNPOT(width) ||
624 GLES2Util::IsNPOT(height) || 633 GLES2Util::IsNPOT(height) ||
625 GLES2Util::IsNPOT(depth)); 634 GLES2Util::IsNPOT(depth));
626 } 635 }
(...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after
1105 } 1114 }
1106 1115
1107 // Update texture_complete and cube_complete status. 1116 // Update texture_complete and cube_complete status.
1108 const Texture::FaceInfo& first_face = face_infos_[0]; 1117 const Texture::FaceInfo& first_face = face_infos_[0];
1109 const Texture::LevelInfo& first_level = first_face.level_infos[base_level_]; 1118 const Texture::LevelInfo& first_level = first_face.level_infos[base_level_];
1110 const GLsizei levels_needed = first_face.num_mip_levels; 1119 const GLsizei levels_needed = first_face.num_mip_levels;
1111 1120
1112 texture_complete_ = 1121 texture_complete_ =
1113 max_level_set_ >= (levels_needed - 1) && max_level_set_ >= 0; 1122 max_level_set_ >= (levels_needed - 1) && max_level_set_ >= 0;
1114 cube_complete_ = (face_infos_.size() == 6) && 1123 cube_complete_ = (face_infos_.size() == 6) &&
1115 (first_level.width == first_level.height); 1124 (first_level.width == first_level.height) &&
1125 (first_level.width > 0);
1116 1126
1117 if (first_level.width == 0 || first_level.height == 0) { 1127 if (first_level.width == 0 || first_level.height == 0) {
1118 texture_complete_ = false; 1128 texture_complete_ = false;
1119 } else if (first_level.type == GL_FLOAT && 1129 } else if (first_level.type == GL_FLOAT &&
1120 !feature_info->feature_flags().enable_texture_float_linear && 1130 !feature_info->feature_flags().enable_texture_float_linear &&
1121 (min_filter_ != GL_NEAREST_MIPMAP_NEAREST || 1131 (min_filter_ != GL_NEAREST_MIPMAP_NEAREST ||
1122 mag_filter_ != GL_NEAREST)) { 1132 mag_filter_ != GL_NEAREST)) {
1123 texture_complete_ = false; 1133 texture_complete_ = false;
1124 } else if (first_level.type == GL_HALF_FLOAT_OES && 1134 } else if (first_level.type == GL_HALF_FLOAT_OES &&
1125 !feature_info->feature_flags().enable_texture_half_float_linear && 1135 !feature_info->feature_flags().enable_texture_half_float_linear &&
(...skipping 562 matching lines...) Expand 10 before | Expand all | Expand 10 after
1688 error_state, function_name, pname, "pname"); 1698 error_state, function_name, pname, "pname");
1689 } else { 1699 } else {
1690 ERRORSTATE_SET_GL_ERROR_INVALID_PARAMF( 1700 ERRORSTATE_SET_GL_ERROR_INVALID_PARAMF(
1691 error_state, result, function_name, pname, param); 1701 error_state, result, function_name, pname, param);
1692 } 1702 }
1693 } else { 1703 } else {
1694 glTexParameterf(texture->target(), pname, param); 1704 glTexParameterf(texture->target(), pname, param);
1695 } 1705 }
1696 } 1706 }
1697 1707
1698 bool TextureManager::MarkMipmapsGenerated(TextureRef* ref) { 1708 void TextureManager::MarkMipmapsGenerated(TextureRef* ref) {
1699 DCHECK(ref); 1709 DCHECK(ref);
1700 Texture* texture = ref->texture(); 1710 Texture* texture = ref->texture();
1701 texture->GetMemTracker()->TrackMemFree(texture->estimated_size()); 1711 texture->GetMemTracker()->TrackMemFree(texture->estimated_size());
1702 bool result = texture->MarkMipmapsGenerated(feature_info_.get()); 1712 texture->MarkMipmapsGenerated(feature_info_.get());
1703 texture->GetMemTracker()->TrackMemAlloc(texture->estimated_size()); 1713 texture->GetMemTracker()->TrackMemAlloc(texture->estimated_size());
1704 return result;
1705 } 1714 }
1706 1715
1707 TextureRef* TextureManager::CreateTexture( 1716 TextureRef* TextureManager::CreateTexture(
1708 GLuint client_id, GLuint service_id) { 1717 GLuint client_id, GLuint service_id) {
1709 DCHECK_NE(0u, service_id); 1718 DCHECK_NE(0u, service_id);
1710 scoped_refptr<TextureRef> ref(TextureRef::Create( 1719 scoped_refptr<TextureRef> ref(TextureRef::Create(
1711 this, client_id, service_id)); 1720 this, client_id, service_id));
1712 std::pair<TextureMap::iterator, bool> result = 1721 std::pair<TextureMap::iterator, bool> result =
1713 textures_.insert(std::make_pair(client_id, ref)); 1722 textures_.insert(std::make_pair(client_id, ref));
1714 DCHECK(result.second); 1723 DCHECK(result.second);
(...skipping 948 matching lines...) Expand 10 before | Expand all | Expand 10 after
2663 uint32_t TextureManager::GetServiceIdGeneration() const { 2672 uint32_t TextureManager::GetServiceIdGeneration() const {
2664 return current_service_id_generation_; 2673 return current_service_id_generation_;
2665 } 2674 }
2666 2675
2667 void TextureManager::IncrementServiceIdGeneration() { 2676 void TextureManager::IncrementServiceIdGeneration() {
2668 current_service_id_generation_++; 2677 current_service_id_generation_++;
2669 } 2678 }
2670 2679
2671 } // namespace gles2 2680 } // namespace gles2
2672 } // namespace gpu 2681 } // namespace gpu
OLDNEW
« no previous file with comments | « gpu/command_buffer/service/texture_manager.h ('k') | gpu/command_buffer/service/texture_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698