| 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}, | |
| 236 }; | 234 }; |
| 237 | 235 |
| 238 for (size_t ii = 0; ii < arraysize(kSupportedFormatTypes); ++ii) { | 236 for (size_t ii = 0; ii < arraysize(kSupportedFormatTypes); ++ii) { |
| 239 supported_combinations_.insert(kSupportedFormatTypes[ii]); | 237 supported_combinations_.insert(kSupportedFormatTypes[ii]); |
| 240 } | 238 } |
| 241 } | 239 } |
| 242 | 240 |
| 243 // This may be accessed from multiple threads. | 241 // This may be accessed from multiple threads. |
| 244 bool IsValid(GLenum internal_format, GLenum format, GLenum type) const { | 242 bool IsValid(GLenum internal_format, GLenum format, GLenum type) const { |
| 245 FormatType query = { internal_format, format, type }; | 243 FormatType query = { internal_format, format, type }; |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 303 case GL_BLUE: | 301 case GL_BLUE: |
| 304 return swizzle->blue; | 302 return swizzle->blue; |
| 305 case GL_ALPHA: | 303 case GL_ALPHA: |
| 306 return swizzle->alpha; | 304 return swizzle->alpha; |
| 307 default: | 305 default: |
| 308 NOTREACHED(); | 306 NOTREACHED(); |
| 309 return GL_NONE; | 307 return GL_NONE; |
| 310 } | 308 } |
| 311 } | 309 } |
| 312 | 310 |
| 313 bool SizedFormatAvailable(const FeatureInfo* feature_info, | |
| 314 bool immutable, | |
| 315 GLenum internal_format) { | |
| 316 if (immutable) | |
| 317 return true; | |
| 318 | |
| 319 // TODO(dshwang): check if it's possible to remove | |
| 320 // CHROMIUM_color_buffer_float_rgb. crbug.com/329605 | |
| 321 if ((feature_info->feature_flags().chromium_color_buffer_float_rgb && | |
| 322 internal_format == GL_RGB32F) || | |
| 323 (feature_info->feature_flags().chromium_color_buffer_float_rgba && | |
| 324 internal_format == GL_RGBA32F)) { | |
| 325 return true; | |
| 326 } | |
| 327 | |
| 328 return feature_info->IsES3Enabled(); | |
| 329 } | |
| 330 | |
| 331 // A 32-bit and 64-bit compatible way of converting a pointer to a GLuint. | 311 // A 32-bit and 64-bit compatible way of converting a pointer to a GLuint. |
| 332 GLuint ToGLuint(const void* ptr) { | 312 GLuint ToGLuint(const void* ptr) { |
| 333 return static_cast<GLuint>(reinterpret_cast<size_t>(ptr)); | 313 return static_cast<GLuint>(reinterpret_cast<size_t>(ptr)); |
| 334 } | 314 } |
| 335 | 315 |
| 336 base::LazyInstance<const FormatTypeValidator>::Leaky g_format_type_validator = | 316 base::LazyInstance<const FormatTypeValidator>::Leaky g_format_type_validator = |
| 337 LAZY_INSTANCE_INITIALIZER; | 317 LAZY_INSTANCE_INITIALIZER; |
| 338 | 318 |
| 339 class ScopedResetPixelUnpackBuffer{ | 319 class ScopedResetPixelUnpackBuffer{ |
| 340 public: | 320 public: |
| (...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 614 // In ES2 with OES_depth_texture, such limitation isn't specified. | 594 // In ES2 with OES_depth_texture, such limitation isn't specified. |
| 615 if (feature_info->IsES3Enabled()) { | 595 if (feature_info->IsES3Enabled()) { |
| 616 return false; | 596 return false; |
| 617 } | 597 } |
| 618 } | 598 } |
| 619 } else if (feature_info->validators()->compressed_texture_format.IsValid( | 599 } else if (feature_info->validators()->compressed_texture_format.IsValid( |
| 620 first_level.internal_format)) { | 600 first_level.internal_format)) { |
| 621 // TODO(zmo): The assumption that compressed textures are all filterable | 601 // TODO(zmo): The assumption that compressed textures are all filterable |
| 622 // may not be true in the future. | 602 // may not be true in the future. |
| 623 } else { | 603 } else { |
| 624 if (!Texture::TextureFilterable(feature_info, first_level.internal_format, | 604 if (!Texture::TextureFilterable(feature_info, |
| 625 first_level.type, immutable_)) { | 605 first_level.internal_format, |
| 606 first_level.type)) { |
| 626 return false; | 607 return false; |
| 627 } | 608 } |
| 628 } | 609 } |
| 629 } | 610 } |
| 630 | 611 |
| 631 if (!feature_info->IsES3Enabled()) { | 612 if (!feature_info->IsES3Enabled()) { |
| 632 bool is_npot_compatible = !needs_mips && | 613 bool is_npot_compatible = !needs_mips && |
| 633 sampler_state.wrap_s == GL_CLAMP_TO_EDGE && | 614 sampler_state.wrap_s == GL_CLAMP_TO_EDGE && |
| 634 sampler_state.wrap_t == GL_CLAMP_TO_EDGE; | 615 sampler_state.wrap_t == GL_CLAMP_TO_EDGE; |
| 635 | 616 |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 741 return false; | 722 return false; |
| 742 } | 723 } |
| 743 | 724 |
| 744 // Can't generate mips for depth or stencil textures. | 725 // Can't generate mips for depth or stencil textures. |
| 745 const Texture::LevelInfo& base = face_infos_[0].level_infos[base_level_]; | 726 const Texture::LevelInfo& base = face_infos_[0].level_infos[base_level_]; |
| 746 uint32_t channels = GLES2Util::GetChannelsForFormat(base.format); | 727 uint32_t channels = GLES2Util::GetChannelsForFormat(base.format); |
| 747 if (channels & (GLES2Util::kDepth | GLES2Util::kStencil)) { | 728 if (channels & (GLES2Util::kDepth | GLES2Util::kStencil)) { |
| 748 return false; | 729 return false; |
| 749 } | 730 } |
| 750 | 731 |
| 751 if (!Texture::ColorRenderable(feature_info, base.internal_format, | 732 if (!Texture::ColorRenderable(feature_info, base.internal_format) || |
| 752 immutable_) || | 733 !Texture::TextureFilterable( |
| 753 !Texture::TextureFilterable(feature_info, base.internal_format, base.type, | 734 feature_info, base.internal_format, base.type)) { |
| 754 immutable_)) { | |
| 755 return false; | 735 return false; |
| 756 } | 736 } |
| 757 | 737 |
| 758 for (size_t ii = 0; ii < face_infos_.size(); ++ii) { | 738 for (size_t ii = 0; ii < face_infos_.size(); ++ii) { |
| 759 const LevelInfo& info = face_infos_[ii].level_infos[base_level_]; | 739 const LevelInfo& info = face_infos_[ii].level_infos[base_level_]; |
| 760 if ((info.target == 0) || | 740 if ((info.target == 0) || |
| 761 feature_info->validators()->compressed_texture_format.IsValid( | 741 feature_info->validators()->compressed_texture_format.IsValid( |
| 762 info.internal_format) || | 742 info.internal_format) || |
| 763 info.image.get()) { | 743 info.image.get()) { |
| 764 return false; | 744 return false; |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 821 depth == mip_depth && | 801 depth == mip_depth && |
| 822 internal_format == base_level_face.internal_format && | 802 internal_format == base_level_face.internal_format && |
| 823 format == base_level_face.format && | 803 format == base_level_face.format && |
| 824 type == base_level_face.type); | 804 type == base_level_face.type); |
| 825 } | 805 } |
| 826 return complete; | 806 return complete; |
| 827 } | 807 } |
| 828 | 808 |
| 829 // static | 809 // static |
| 830 bool Texture::ColorRenderable(const FeatureInfo* feature_info, | 810 bool Texture::ColorRenderable(const FeatureInfo* feature_info, |
| 831 GLenum internal_format, | 811 GLenum internal_format) { |
| 832 bool immutable) { | |
| 833 if (feature_info->validators()->texture_unsized_internal_format.IsValid( | 812 if (feature_info->validators()->texture_unsized_internal_format.IsValid( |
| 834 internal_format)) { | 813 internal_format)) { |
| 835 return true; | 814 return true; |
| 836 } | 815 } |
| 837 | 816 return feature_info->validators()-> |
| 838 return SizedFormatAvailable(feature_info, immutable, internal_format) && | 817 texture_sized_color_renderable_internal_format.IsValid(internal_format); |
| 839 feature_info->validators() | |
| 840 ->texture_sized_color_renderable_internal_format.IsValid( | |
| 841 internal_format); | |
| 842 } | 818 } |
| 843 | 819 |
| 844 // static | 820 // static |
| 845 bool Texture::TextureFilterable(const FeatureInfo* feature_info, | 821 bool Texture::TextureFilterable(const FeatureInfo* feature_info, |
| 846 GLenum internal_format, | 822 GLenum internal_format, |
| 847 GLenum type, | 823 GLenum type) { |
| 848 bool immutable) { | |
| 849 if (feature_info->validators()->texture_unsized_internal_format.IsValid( | 824 if (feature_info->validators()->texture_unsized_internal_format.IsValid( |
| 850 internal_format)) { | 825 internal_format)) { |
| 851 switch (type) { | 826 switch (type) { |
| 852 case GL_FLOAT: | 827 case GL_FLOAT: |
| 853 return feature_info->feature_flags().enable_texture_float_linear; | 828 return feature_info->feature_flags().enable_texture_float_linear; |
| 854 case GL_HALF_FLOAT_OES: | 829 case GL_HALF_FLOAT_OES: |
| 855 return feature_info->feature_flags().enable_texture_half_float_linear; | 830 return feature_info->feature_flags().enable_texture_half_float_linear; |
| 856 default: | 831 default: |
| 857 // GL_HALF_FLOAT is ES3 only and should only be used with sized formats. | 832 // GL_HALF_FLOAT is ES3 only and should only be used with sized formats. |
| 858 return true; | 833 return true; |
| 859 } | 834 } |
| 860 } | 835 } |
| 861 return SizedFormatAvailable(feature_info, immutable, internal_format) && | 836 return feature_info->validators()-> |
| 862 feature_info->validators() | 837 texture_sized_texture_filterable_internal_format.IsValid(internal_format); |
| 863 ->texture_sized_texture_filterable_internal_format.IsValid( | |
| 864 internal_format); | |
| 865 } | 838 } |
| 866 | 839 |
| 867 void Texture::SetLevelClearedRect(GLenum target, | 840 void Texture::SetLevelClearedRect(GLenum target, |
| 868 GLint level, | 841 GLint level, |
| 869 const gfx::Rect& cleared_rect) { | 842 const gfx::Rect& cleared_rect) { |
| 870 DCHECK_GE(level, 0); | 843 DCHECK_GE(level, 0); |
| 871 size_t face_index = GLES2Util::GLTargetToFaceIndex(target); | 844 size_t face_index = GLES2Util::GLTargetToFaceIndex(target); |
| 872 DCHECK_LT(static_cast<size_t>(face_index), | 845 DCHECK_LT(static_cast<size_t>(face_index), |
| 873 face_infos_.size()); | 846 face_infos_.size()); |
| 874 DCHECK_LT(static_cast<size_t>(level), | 847 DCHECK_LT(static_cast<size_t>(level), |
| (...skipping 856 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1731 // However, it is required if command buffer is implemented on top of | 1704 // However, it is required if command buffer is implemented on top of |
| 1732 // recent OpenGL core versions or OpenGL ES 3.0+. Therefore, for consistency, | 1705 // recent OpenGL core versions or OpenGL ES 3.0+. Therefore, for consistency, |
| 1733 // it is better to deviate from ES2 spec and require cube completeness all | 1706 // it is better to deviate from ES2 spec and require cube completeness all |
| 1734 // the time. | 1707 // the time. |
| 1735 if (face_infos_.size() == 6 && !cube_complete_) | 1708 if (face_infos_.size() == 6 && !cube_complete_) |
| 1736 return false; | 1709 return false; |
| 1737 DCHECK(level >= 0 && | 1710 DCHECK(level >= 0 && |
| 1738 level < static_cast<GLint>(face_infos_[0].level_infos.size())); | 1711 level < static_cast<GLint>(face_infos_[0].level_infos.size())); |
| 1739 GLenum internal_format = face_infos_[0].level_infos[level].internal_format; | 1712 GLenum internal_format = face_infos_[0].level_infos[level].internal_format; |
| 1740 bool color_renderable = | 1713 bool color_renderable = |
| 1741 ((feature_info->validators()->texture_unsized_internal_format.IsValid( | 1714 ((feature_info->validators()->texture_unsized_internal_format. |
| 1742 internal_format) && | 1715 IsValid(internal_format) && |
| 1743 internal_format != GL_ALPHA && internal_format != GL_LUMINANCE && | 1716 internal_format != GL_ALPHA && |
| 1717 internal_format != GL_LUMINANCE && |
| 1744 internal_format != GL_LUMINANCE_ALPHA && | 1718 internal_format != GL_LUMINANCE_ALPHA && |
| 1745 internal_format != GL_SRGB_EXT) || | 1719 internal_format != GL_SRGB_EXT) || |
| 1746 (SizedFormatAvailable(feature_info, immutable_, internal_format) && | 1720 feature_info->validators()-> |
| 1747 feature_info->validators() | 1721 texture_sized_color_renderable_internal_format.IsValid( |
| 1748 ->texture_sized_color_renderable_internal_format.IsValid( | 1722 internal_format)); |
| 1749 internal_format))); | |
| 1750 bool depth_renderable = feature_info->validators()-> | 1723 bool depth_renderable = feature_info->validators()-> |
| 1751 texture_depth_renderable_internal_format.IsValid(internal_format); | 1724 texture_depth_renderable_internal_format.IsValid(internal_format); |
| 1752 bool stencil_renderable = feature_info->validators()-> | 1725 bool stencil_renderable = feature_info->validators()-> |
| 1753 texture_stencil_renderable_internal_format.IsValid(internal_format); | 1726 texture_stencil_renderable_internal_format.IsValid(internal_format); |
| 1754 return (color_renderable || depth_renderable || stencil_renderable); | 1727 return (color_renderable || depth_renderable || stencil_renderable); |
| 1755 } | 1728 } |
| 1756 | 1729 |
| 1757 GLenum Texture::GetCompatibilitySwizzleForChannel(GLenum channel) { | 1730 GLenum Texture::GetCompatibilitySwizzleForChannel(GLenum channel) { |
| 1758 return GetSwizzleForChannel(channel, compatibility_swizzle_); | 1731 return GetSwizzleForChannel(channel, compatibility_swizzle_); |
| 1759 } | 1732 } |
| (...skipping 1747 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3507 uint32_t TextureManager::GetServiceIdGeneration() const { | 3480 uint32_t TextureManager::GetServiceIdGeneration() const { |
| 3508 return current_service_id_generation_; | 3481 return current_service_id_generation_; |
| 3509 } | 3482 } |
| 3510 | 3483 |
| 3511 void TextureManager::IncrementServiceIdGeneration() { | 3484 void TextureManager::IncrementServiceIdGeneration() { |
| 3512 current_service_id_generation_++; | 3485 current_service_id_generation_++; |
| 3513 } | 3486 } |
| 3514 | 3487 |
| 3515 } // namespace gles2 | 3488 } // namespace gles2 |
| 3516 } // namespace gpu | 3489 } // namespace gpu |
| OLD | NEW |