Chromium Code Reviews| 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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 301 case GL_BLUE: | 303 case GL_BLUE: |
| 302 return swizzle->blue; | 304 return swizzle->blue; |
| 303 case GL_ALPHA: | 305 case GL_ALPHA: |
| 304 return swizzle->alpha; | 306 return swizzle->alpha; |
| 305 default: | 307 default: |
| 306 NOTREACHED(); | 308 NOTREACHED(); |
| 307 return GL_NONE; | 309 return GL_NONE; |
| 308 } | 310 } |
| 309 } | 311 } |
| 310 | 312 |
| 313 bool SizedFormatAvailable(const FeatureInfo* feature_info, | |
| 314 bool immutable) { | |
|
Zhenyao Mo
2016/10/13 21:23:38
nit: wrong indent
dshwang
2016/10/14 12:03:34
Done.
| |
| 315 return !feature_info->gl_version_info().is_es2 || immutable; | |
|
Zhenyao Mo
2016/10/13 21:23:38
This should be feature_info->IsES3Enabled(), not a
dshwang
2016/10/14 12:03:34
Done.
| |
| 316 } | |
| 317 | |
| 311 // A 32-bit and 64-bit compatible way of converting a pointer to a GLuint. | 318 // A 32-bit and 64-bit compatible way of converting a pointer to a GLuint. |
| 312 GLuint ToGLuint(const void* ptr) { | 319 GLuint ToGLuint(const void* ptr) { |
| 313 return static_cast<GLuint>(reinterpret_cast<size_t>(ptr)); | 320 return static_cast<GLuint>(reinterpret_cast<size_t>(ptr)); |
| 314 } | 321 } |
| 315 | 322 |
| 316 base::LazyInstance<const FormatTypeValidator>::Leaky g_format_type_validator = | 323 base::LazyInstance<const FormatTypeValidator>::Leaky g_format_type_validator = |
| 317 LAZY_INSTANCE_INITIALIZER; | 324 LAZY_INSTANCE_INITIALIZER; |
| 318 | 325 |
| 319 class ScopedResetPixelUnpackBuffer{ | 326 class ScopedResetPixelUnpackBuffer{ |
| 320 public: | 327 public: |
| (...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 594 // In ES2 with OES_depth_texture, such limitation isn't specified. | 601 // In ES2 with OES_depth_texture, such limitation isn't specified. |
| 595 if (feature_info->IsES3Enabled()) { | 602 if (feature_info->IsES3Enabled()) { |
| 596 return false; | 603 return false; |
| 597 } | 604 } |
| 598 } | 605 } |
| 599 } else if (feature_info->validators()->compressed_texture_format.IsValid( | 606 } else if (feature_info->validators()->compressed_texture_format.IsValid( |
| 600 first_level.internal_format)) { | 607 first_level.internal_format)) { |
| 601 // TODO(zmo): The assumption that compressed textures are all filterable | 608 // TODO(zmo): The assumption that compressed textures are all filterable |
| 602 // may not be true in the future. | 609 // may not be true in the future. |
| 603 } else { | 610 } else { |
| 604 if (!Texture::TextureFilterable(feature_info, | 611 if (!Texture::TextureFilterable(feature_info, first_level.internal_format, |
| 605 first_level.internal_format, | 612 first_level.type, immutable_)) { |
| 606 first_level.type)) { | |
| 607 return false; | 613 return false; |
| 608 } | 614 } |
| 609 } | 615 } |
| 610 } | 616 } |
| 611 | 617 |
| 612 if (!feature_info->IsES3Enabled()) { | 618 if (!feature_info->IsES3Enabled()) { |
| 613 bool is_npot_compatible = !needs_mips && | 619 bool is_npot_compatible = !needs_mips && |
| 614 sampler_state.wrap_s == GL_CLAMP_TO_EDGE && | 620 sampler_state.wrap_s == GL_CLAMP_TO_EDGE && |
| 615 sampler_state.wrap_t == GL_CLAMP_TO_EDGE; | 621 sampler_state.wrap_t == GL_CLAMP_TO_EDGE; |
| 616 | 622 |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 722 return false; | 728 return false; |
| 723 } | 729 } |
| 724 | 730 |
| 725 // Can't generate mips for depth or stencil textures. | 731 // Can't generate mips for depth or stencil textures. |
| 726 const Texture::LevelInfo& base = face_infos_[0].level_infos[base_level_]; | 732 const Texture::LevelInfo& base = face_infos_[0].level_infos[base_level_]; |
| 727 uint32_t channels = GLES2Util::GetChannelsForFormat(base.format); | 733 uint32_t channels = GLES2Util::GetChannelsForFormat(base.format); |
| 728 if (channels & (GLES2Util::kDepth | GLES2Util::kStencil)) { | 734 if (channels & (GLES2Util::kDepth | GLES2Util::kStencil)) { |
| 729 return false; | 735 return false; |
| 730 } | 736 } |
| 731 | 737 |
| 732 if (!Texture::ColorRenderable(feature_info, base.internal_format) || | 738 if (!Texture::ColorRenderable(feature_info, base.internal_format, |
| 733 !Texture::TextureFilterable( | 739 immutable_) || |
| 734 feature_info, base.internal_format, base.type)) { | 740 !Texture::TextureFilterable(feature_info, base.internal_format, base.type, |
| 741 immutable_)) { | |
| 735 return false; | 742 return false; |
| 736 } | 743 } |
| 737 | 744 |
| 738 for (size_t ii = 0; ii < face_infos_.size(); ++ii) { | 745 for (size_t ii = 0; ii < face_infos_.size(); ++ii) { |
| 739 const LevelInfo& info = face_infos_[ii].level_infos[base_level_]; | 746 const LevelInfo& info = face_infos_[ii].level_infos[base_level_]; |
| 740 if ((info.target == 0) || | 747 if ((info.target == 0) || |
| 741 feature_info->validators()->compressed_texture_format.IsValid( | 748 feature_info->validators()->compressed_texture_format.IsValid( |
| 742 info.internal_format) || | 749 info.internal_format) || |
| 743 info.image.get()) { | 750 info.image.get()) { |
| 744 return false; | 751 return false; |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 801 depth == mip_depth && | 808 depth == mip_depth && |
| 802 internal_format == base_level_face.internal_format && | 809 internal_format == base_level_face.internal_format && |
| 803 format == base_level_face.format && | 810 format == base_level_face.format && |
| 804 type == base_level_face.type); | 811 type == base_level_face.type); |
| 805 } | 812 } |
| 806 return complete; | 813 return complete; |
| 807 } | 814 } |
| 808 | 815 |
| 809 // static | 816 // static |
| 810 bool Texture::ColorRenderable(const FeatureInfo* feature_info, | 817 bool Texture::ColorRenderable(const FeatureInfo* feature_info, |
| 811 GLenum internal_format) { | 818 GLenum internal_format, |
| 819 bool immutable) { | |
| 812 if (feature_info->validators()->texture_unsized_internal_format.IsValid( | 820 if (feature_info->validators()->texture_unsized_internal_format.IsValid( |
| 813 internal_format)) { | 821 internal_format)) { |
| 814 return true; | 822 return true; |
| 815 } | 823 } |
| 816 return feature_info->validators()-> | 824 |
| 817 texture_sized_color_renderable_internal_format.IsValid(internal_format); | 825 return SizedFormatAvailable(feature_info, immutable) && |
| 826 feature_info->validators() | |
| 827 ->texture_sized_color_renderable_internal_format.IsValid( | |
| 828 internal_format); | |
| 818 } | 829 } |
| 819 | 830 |
| 820 // static | 831 // static |
| 821 bool Texture::TextureFilterable(const FeatureInfo* feature_info, | 832 bool Texture::TextureFilterable(const FeatureInfo* feature_info, |
| 822 GLenum internal_format, | 833 GLenum internal_format, |
| 823 GLenum type) { | 834 GLenum type, |
| 835 bool immutable) { | |
| 824 if (feature_info->validators()->texture_unsized_internal_format.IsValid( | 836 if (feature_info->validators()->texture_unsized_internal_format.IsValid( |
| 825 internal_format)) { | 837 internal_format)) { |
| 826 switch (type) { | 838 switch (type) { |
| 827 case GL_FLOAT: | 839 case GL_FLOAT: |
| 828 return feature_info->feature_flags().enable_texture_float_linear; | 840 return feature_info->feature_flags().enable_texture_float_linear; |
| 829 case GL_HALF_FLOAT_OES: | 841 case GL_HALF_FLOAT_OES: |
| 830 return feature_info->feature_flags().enable_texture_half_float_linear; | 842 return feature_info->feature_flags().enable_texture_half_float_linear; |
| 831 default: | 843 default: |
| 832 // GL_HALF_FLOAT is ES3 only and should only be used with sized formats. | 844 // GL_HALF_FLOAT is ES3 only and should only be used with sized formats. |
| 833 return true; | 845 return true; |
| 834 } | 846 } |
| 835 } | 847 } |
| 836 return feature_info->validators()-> | 848 return SizedFormatAvailable(feature_info, immutable) && |
| 837 texture_sized_texture_filterable_internal_format.IsValid(internal_format); | 849 feature_info->validators() |
| 850 ->texture_sized_texture_filterable_internal_format.IsValid( | |
| 851 internal_format); | |
| 838 } | 852 } |
| 839 | 853 |
| 840 void Texture::SetLevelClearedRect(GLenum target, | 854 void Texture::SetLevelClearedRect(GLenum target, |
| 841 GLint level, | 855 GLint level, |
| 842 const gfx::Rect& cleared_rect) { | 856 const gfx::Rect& cleared_rect) { |
| 843 DCHECK_GE(level, 0); | 857 DCHECK_GE(level, 0); |
| 844 size_t face_index = GLES2Util::GLTargetToFaceIndex(target); | 858 size_t face_index = GLES2Util::GLTargetToFaceIndex(target); |
| 845 DCHECK_LT(static_cast<size_t>(face_index), | 859 DCHECK_LT(static_cast<size_t>(face_index), |
| 846 face_infos_.size()); | 860 face_infos_.size()); |
| 847 DCHECK_LT(static_cast<size_t>(level), | 861 DCHECK_LT(static_cast<size_t>(level), |
| (...skipping 856 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1704 // However, it is required if command buffer is implemented on top of | 1718 // 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, | 1719 // 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 | 1720 // it is better to deviate from ES2 spec and require cube completeness all |
| 1707 // the time. | 1721 // the time. |
| 1708 if (face_infos_.size() == 6 && !cube_complete_) | 1722 if (face_infos_.size() == 6 && !cube_complete_) |
| 1709 return false; | 1723 return false; |
| 1710 DCHECK(level >= 0 && | 1724 DCHECK(level >= 0 && |
| 1711 level < static_cast<GLint>(face_infos_[0].level_infos.size())); | 1725 level < static_cast<GLint>(face_infos_[0].level_infos.size())); |
| 1712 GLenum internal_format = face_infos_[0].level_infos[level].internal_format; | 1726 GLenum internal_format = face_infos_[0].level_infos[level].internal_format; |
| 1713 bool color_renderable = | 1727 bool color_renderable = |
| 1714 ((feature_info->validators()->texture_unsized_internal_format. | 1728 ((feature_info->validators()->texture_unsized_internal_format.IsValid( |
| 1715 IsValid(internal_format) && | 1729 internal_format) && |
| 1716 internal_format != GL_ALPHA && | 1730 internal_format != GL_ALPHA && internal_format != GL_LUMINANCE && |
| 1717 internal_format != GL_LUMINANCE && | |
| 1718 internal_format != GL_LUMINANCE_ALPHA && | 1731 internal_format != GL_LUMINANCE_ALPHA && |
| 1719 internal_format != GL_SRGB_EXT) || | 1732 internal_format != GL_SRGB_EXT) || |
| 1720 feature_info->validators()-> | 1733 (SizedFormatAvailable(feature_info, immutable_) && |
| 1721 texture_sized_color_renderable_internal_format.IsValid( | 1734 feature_info->validators() |
| 1722 internal_format)); | 1735 ->texture_sized_color_renderable_internal_format.IsValid( |
| 1736 internal_format))); | |
| 1723 bool depth_renderable = feature_info->validators()-> | 1737 bool depth_renderable = feature_info->validators()-> |
| 1724 texture_depth_renderable_internal_format.IsValid(internal_format); | 1738 texture_depth_renderable_internal_format.IsValid(internal_format); |
| 1725 bool stencil_renderable = feature_info->validators()-> | 1739 bool stencil_renderable = feature_info->validators()-> |
| 1726 texture_stencil_renderable_internal_format.IsValid(internal_format); | 1740 texture_stencil_renderable_internal_format.IsValid(internal_format); |
| 1727 return (color_renderable || depth_renderable || stencil_renderable); | 1741 return (color_renderable || depth_renderable || stencil_renderable); |
| 1728 } | 1742 } |
| 1729 | 1743 |
| 1730 GLenum Texture::GetCompatibilitySwizzleForChannel(GLenum channel) { | 1744 GLenum Texture::GetCompatibilitySwizzleForChannel(GLenum channel) { |
| 1731 return GetSwizzleForChannel(channel, compatibility_swizzle_); | 1745 return GetSwizzleForChannel(channel, compatibility_swizzle_); |
| 1732 } | 1746 } |
| (...skipping 1747 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3480 uint32_t TextureManager::GetServiceIdGeneration() const { | 3494 uint32_t TextureManager::GetServiceIdGeneration() const { |
| 3481 return current_service_id_generation_; | 3495 return current_service_id_generation_; |
| 3482 } | 3496 } |
| 3483 | 3497 |
| 3484 void TextureManager::IncrementServiceIdGeneration() { | 3498 void TextureManager::IncrementServiceIdGeneration() { |
| 3485 current_service_id_generation_++; | 3499 current_service_id_generation_++; |
| 3486 } | 3500 } |
| 3487 | 3501 |
| 3488 } // namespace gles2 | 3502 } // namespace gles2 |
| 3489 } // namespace gpu | 3503 } // namespace gpu |
| OLD | NEW |