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