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 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
224 {GL_RGBA16I, GL_RGBA_INTEGER, GL_SHORT}, | 224 {GL_RGBA16I, GL_RGBA_INTEGER, GL_SHORT}, |
225 {GL_RGBA32I, GL_RGBA_INTEGER, GL_INT}, | 225 {GL_RGBA32I, GL_RGBA_INTEGER, GL_INT}, |
226 {GL_RGBA32UI, GL_RGBA_INTEGER, GL_UNSIGNED_INT}, | 226 {GL_RGBA32UI, GL_RGBA_INTEGER, GL_UNSIGNED_INT}, |
227 {GL_DEPTH_COMPONENT16, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT}, | 227 {GL_DEPTH_COMPONENT16, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT}, |
228 {GL_DEPTH_COMPONENT16, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT}, | 228 {GL_DEPTH_COMPONENT16, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT}, |
229 {GL_DEPTH_COMPONENT24, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT}, | 229 {GL_DEPTH_COMPONENT24, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT}, |
230 {GL_DEPTH_COMPONENT32F, GL_DEPTH_COMPONENT, GL_FLOAT}, | 230 {GL_DEPTH_COMPONENT32F, GL_DEPTH_COMPONENT, GL_FLOAT}, |
231 {GL_DEPTH24_STENCIL8, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8}, | 231 {GL_DEPTH24_STENCIL8, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8}, |
232 {GL_DEPTH32F_STENCIL8, GL_DEPTH_STENCIL, | 232 {GL_DEPTH32F_STENCIL8, GL_DEPTH_STENCIL, |
233 GL_FLOAT_32_UNSIGNED_INT_24_8_REV}, | 233 GL_FLOAT_32_UNSIGNED_INT_24_8_REV}, |
234 // Exposed by GL_APPLE_texture_format_BGRA8888 | |
235 {GL_BGRA8_EXT, GL_BGRA_EXT, GL_UNSIGNED_BYTE}, | |
234 }; | 236 }; |
235 | 237 |
236 for (size_t ii = 0; ii < arraysize(kSupportedFormatTypes); ++ii) { | 238 for (size_t ii = 0; ii < arraysize(kSupportedFormatTypes); ++ii) { |
237 supported_combinations_.insert(kSupportedFormatTypes[ii]); | 239 supported_combinations_.insert(kSupportedFormatTypes[ii]); |
238 } | 240 } |
239 } | 241 } |
240 | 242 |
241 // This may be accessed from multiple threads. | 243 // This may be accessed from multiple threads. |
242 bool IsValid(GLenum internal_format, GLenum format, GLenum type) const { | 244 bool IsValid(GLenum internal_format, GLenum format, GLenum type) const { |
243 FormatType query = { internal_format, format, type }; | 245 FormatType query = { internal_format, format, type }; |
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
594 // In ES2 with OES_depth_texture, such limitation isn't specified. | 596 // In ES2 with OES_depth_texture, such limitation isn't specified. |
595 if (feature_info->IsES3Enabled()) { | 597 if (feature_info->IsES3Enabled()) { |
596 return false; | 598 return false; |
597 } | 599 } |
598 } | 600 } |
599 } else if (feature_info->validators()->compressed_texture_format.IsValid( | 601 } else if (feature_info->validators()->compressed_texture_format.IsValid( |
600 first_level.internal_format)) { | 602 first_level.internal_format)) { |
601 // TODO(zmo): The assumption that compressed textures are all filterable | 603 // TODO(zmo): The assumption that compressed textures are all filterable |
602 // may not be true in the future. | 604 // may not be true in the future. |
603 } else { | 605 } else { |
604 if (!Texture::TextureFilterable(feature_info, | 606 if (!Texture::TextureFilterable(feature_info, first_level.internal_format, |
605 first_level.internal_format, | 607 first_level.type, immutable_)) { |
606 first_level.type)) { | |
607 return false; | 608 return false; |
608 } | 609 } |
609 } | 610 } |
610 } | 611 } |
611 | 612 |
612 if (!feature_info->IsES3Enabled()) { | 613 if (!feature_info->IsES3Enabled()) { |
613 bool is_npot_compatible = !needs_mips && | 614 bool is_npot_compatible = !needs_mips && |
614 sampler_state.wrap_s == GL_CLAMP_TO_EDGE && | 615 sampler_state.wrap_s == GL_CLAMP_TO_EDGE && |
615 sampler_state.wrap_t == GL_CLAMP_TO_EDGE; | 616 sampler_state.wrap_t == GL_CLAMP_TO_EDGE; |
616 | 617 |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
722 return false; | 723 return false; |
723 } | 724 } |
724 | 725 |
725 // Can't generate mips for depth or stencil textures. | 726 // Can't generate mips for depth or stencil textures. |
726 const Texture::LevelInfo& base = face_infos_[0].level_infos[base_level_]; | 727 const Texture::LevelInfo& base = face_infos_[0].level_infos[base_level_]; |
727 uint32_t channels = GLES2Util::GetChannelsForFormat(base.format); | 728 uint32_t channels = GLES2Util::GetChannelsForFormat(base.format); |
728 if (channels & (GLES2Util::kDepth | GLES2Util::kStencil)) { | 729 if (channels & (GLES2Util::kDepth | GLES2Util::kStencil)) { |
729 return false; | 730 return false; |
730 } | 731 } |
731 | 732 |
732 if (!Texture::ColorRenderable(feature_info, base.internal_format) || | 733 if (!Texture::ColorRenderable(feature_info, base.internal_format, |
733 !Texture::TextureFilterable( | 734 immutable_) || |
734 feature_info, base.internal_format, base.type)) { | 735 !Texture::TextureFilterable(feature_info, base.internal_format, base.type, |
736 immutable_)) { | |
735 return false; | 737 return false; |
736 } | 738 } |
737 | 739 |
738 for (size_t ii = 0; ii < face_infos_.size(); ++ii) { | 740 for (size_t ii = 0; ii < face_infos_.size(); ++ii) { |
739 const LevelInfo& info = face_infos_[ii].level_infos[base_level_]; | 741 const LevelInfo& info = face_infos_[ii].level_infos[base_level_]; |
740 if ((info.target == 0) || | 742 if ((info.target == 0) || |
741 feature_info->validators()->compressed_texture_format.IsValid( | 743 feature_info->validators()->compressed_texture_format.IsValid( |
742 info.internal_format) || | 744 info.internal_format) || |
743 info.image.get()) { | 745 info.image.get()) { |
744 return false; | 746 return false; |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
801 depth == mip_depth && | 803 depth == mip_depth && |
802 internal_format == base_level_face.internal_format && | 804 internal_format == base_level_face.internal_format && |
803 format == base_level_face.format && | 805 format == base_level_face.format && |
804 type == base_level_face.type); | 806 type == base_level_face.type); |
805 } | 807 } |
806 return complete; | 808 return complete; |
807 } | 809 } |
808 | 810 |
809 // static | 811 // static |
810 bool Texture::ColorRenderable(const FeatureInfo* feature_info, | 812 bool Texture::ColorRenderable(const FeatureInfo* feature_info, |
811 GLenum internal_format) { | 813 GLenum internal_format, |
814 bool immutable) { | |
812 if (feature_info->validators()->texture_unsized_internal_format.IsValid( | 815 if (feature_info->validators()->texture_unsized_internal_format.IsValid( |
813 internal_format)) { | 816 internal_format)) { |
814 return true; | 817 return true; |
815 } | 818 } |
816 return feature_info->validators()-> | 819 |
817 texture_sized_color_renderable_internal_format.IsValid(internal_format); | 820 bool sized_format_available = feature_info->IsES3Enabled() || immutable; |
821 return sized_format_available && | |
822 feature_info->validators() | |
823 ->texture_sized_color_renderable_internal_format.IsValid( | |
824 internal_format); | |
818 } | 825 } |
819 | 826 |
820 // static | 827 // static |
821 bool Texture::TextureFilterable(const FeatureInfo* feature_info, | 828 bool Texture::TextureFilterable(const FeatureInfo* feature_info, |
822 GLenum internal_format, | 829 GLenum internal_format, |
823 GLenum type) { | 830 GLenum type, |
831 bool immutable) { | |
824 if (feature_info->validators()->texture_unsized_internal_format.IsValid( | 832 if (feature_info->validators()->texture_unsized_internal_format.IsValid( |
825 internal_format)) { | 833 internal_format)) { |
826 switch (type) { | 834 switch (type) { |
827 case GL_FLOAT: | 835 case GL_FLOAT: |
828 return feature_info->feature_flags().enable_texture_float_linear; | 836 return feature_info->feature_flags().enable_texture_float_linear; |
829 case GL_HALF_FLOAT_OES: | 837 case GL_HALF_FLOAT_OES: |
830 return feature_info->feature_flags().enable_texture_half_float_linear; | 838 return feature_info->feature_flags().enable_texture_half_float_linear; |
831 default: | 839 default: |
832 // GL_HALF_FLOAT is ES3 only and should only be used with sized formats. | 840 // GL_HALF_FLOAT is ES3 only and should only be used with sized formats. |
833 return true; | 841 return true; |
834 } | 842 } |
835 } | 843 } |
836 return feature_info->validators()-> | 844 bool sized_format_available = feature_info->IsES3Enabled() || immutable; |
837 texture_sized_texture_filterable_internal_format.IsValid(internal_format); | 845 return sized_format_available && |
846 feature_info->validators() | |
847 ->texture_sized_texture_filterable_internal_format.IsValid( | |
848 internal_format); | |
838 } | 849 } |
839 | 850 |
840 void Texture::SetLevelClearedRect(GLenum target, | 851 void Texture::SetLevelClearedRect(GLenum target, |
841 GLint level, | 852 GLint level, |
842 const gfx::Rect& cleared_rect) { | 853 const gfx::Rect& cleared_rect) { |
843 DCHECK_GE(level, 0); | 854 DCHECK_GE(level, 0); |
844 size_t face_index = GLES2Util::GLTargetToFaceIndex(target); | 855 size_t face_index = GLES2Util::GLTargetToFaceIndex(target); |
845 DCHECK_LT(static_cast<size_t>(face_index), | 856 DCHECK_LT(static_cast<size_t>(face_index), |
846 face_infos_.size()); | 857 face_infos_.size()); |
847 DCHECK_LT(static_cast<size_t>(level), | 858 DCHECK_LT(static_cast<size_t>(level), |
(...skipping 855 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1703 // In GLES2, cube completeness is not required for framebuffer completeness. | 1714 // In GLES2, cube completeness is not required for framebuffer completeness. |
1704 // However, it is required if command buffer is implemented on top of | 1715 // However, it is required if command buffer is implemented on top of |
1705 // recent OpenGL core versions or OpenGL ES 3.0+. Therefore, for consistency, | 1716 // recent OpenGL core versions or OpenGL ES 3.0+. Therefore, for consistency, |
1706 // it is better to deviate from ES2 spec and require cube completeness all | 1717 // it is better to deviate from ES2 spec and require cube completeness all |
1707 // the time. | 1718 // the time. |
1708 if (face_infos_.size() == 6 && !cube_complete_) | 1719 if (face_infos_.size() == 6 && !cube_complete_) |
1709 return false; | 1720 return false; |
1710 DCHECK(level >= 0 && | 1721 DCHECK(level >= 0 && |
1711 level < static_cast<GLint>(face_infos_[0].level_infos.size())); | 1722 level < static_cast<GLint>(face_infos_[0].level_infos.size())); |
1712 GLenum internal_format = face_infos_[0].level_infos[level].internal_format; | 1723 GLenum internal_format = face_infos_[0].level_infos[level].internal_format; |
1724 bool sized_format_available = feature_info->IsES3Enabled() || immutable_; | |
1713 bool color_renderable = | 1725 bool color_renderable = |
1714 ((feature_info->validators()->texture_unsized_internal_format. | 1726 ((feature_info->validators()->texture_unsized_internal_format.IsValid( |
1715 IsValid(internal_format) && | 1727 internal_format) && |
1716 internal_format != GL_ALPHA && | 1728 internal_format != GL_ALPHA && internal_format != GL_LUMINANCE && |
1717 internal_format != GL_LUMINANCE && | |
1718 internal_format != GL_LUMINANCE_ALPHA && | 1729 internal_format != GL_LUMINANCE_ALPHA && |
1719 internal_format != GL_SRGB_EXT) || | 1730 internal_format != GL_SRGB_EXT) || |
1720 feature_info->validators()-> | 1731 (sized_format_available && |
1721 texture_sized_color_renderable_internal_format.IsValid( | 1732 feature_info->validators() |
1722 internal_format)); | 1733 ->texture_sized_color_renderable_internal_format.IsValid( |
1734 internal_format))); | |
dshwang
2016/10/13 14:21:06
https://cs.chromium.org/chromium/src/gpu/command_b
| |
1723 bool depth_renderable = feature_info->validators()-> | 1735 bool depth_renderable = feature_info->validators()-> |
1724 texture_depth_renderable_internal_format.IsValid(internal_format); | 1736 texture_depth_renderable_internal_format.IsValid(internal_format); |
1725 bool stencil_renderable = feature_info->validators()-> | 1737 bool stencil_renderable = feature_info->validators()-> |
1726 texture_stencil_renderable_internal_format.IsValid(internal_format); | 1738 texture_stencil_renderable_internal_format.IsValid(internal_format); |
1727 return (color_renderable || depth_renderable || stencil_renderable); | 1739 return (color_renderable || depth_renderable || stencil_renderable); |
1728 } | 1740 } |
1729 | 1741 |
1730 GLenum Texture::GetCompatibilitySwizzleForChannel(GLenum channel) { | 1742 GLenum Texture::GetCompatibilitySwizzleForChannel(GLenum channel) { |
1731 return GetSwizzleForChannel(channel, compatibility_swizzle_); | 1743 return GetSwizzleForChannel(channel, compatibility_swizzle_); |
1732 } | 1744 } |
(...skipping 1747 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3480 uint32_t TextureManager::GetServiceIdGeneration() const { | 3492 uint32_t TextureManager::GetServiceIdGeneration() const { |
3481 return current_service_id_generation_; | 3493 return current_service_id_generation_; |
3482 } | 3494 } |
3483 | 3495 |
3484 void TextureManager::IncrementServiceIdGeneration() { | 3496 void TextureManager::IncrementServiceIdGeneration() { |
3485 current_service_id_generation_++; | 3497 current_service_id_generation_++; |
3486 } | 3498 } |
3487 | 3499 |
3488 } // namespace gles2 | 3500 } // namespace gles2 |
3489 } // namespace gpu | 3501 } // namespace gpu |
OLD | NEW |