| 1 | /* |
| 2 | * Copyright (C) 2018 Apple Inc. All rights reserved. |
| 3 | * |
| 4 | * Redistribution and use in source and binary forms, with or without |
| 5 | * modification, are permitted provided that the following conditions |
| 6 | * are met: |
| 7 | * 1. Redistributions of source code must retain the above copyright |
| 8 | * notice, this list of conditions and the following disclaimer. |
| 9 | * 2. Redistributions in binary form must reproduce the above copyright |
| 10 | * notice, this list of conditions and the following disclaimer in the |
| 11 | * documentation and/or other materials provided with the distribution. |
| 12 | * |
| 13 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' |
| 14 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, |
| 15 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 16 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS |
| 17 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 18 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 19 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 20 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 21 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 22 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
| 23 | * THE POSSIBILITY OF SUCH DAMAGE. |
| 24 | */ |
| 25 | |
| 26 | #include "config.h" |
| 27 | #include "WebGLCompressedTextureASTC.h" |
| 28 | |
| 29 | #if ENABLE(WEBGL) |
| 30 | |
| 31 | #include "Extensions3D.h" |
| 32 | #include "RuntimeEnabledFeatures.h" |
| 33 | #include "WebGLRenderingContextBase.h" |
| 34 | |
| 35 | namespace WebCore { |
| 36 | |
| 37 | WebGLCompressedTextureASTC::WebGLCompressedTextureASTC(WebGLRenderingContextBase& context) |
| 38 | : WebGLExtension(context) |
| 39 | , m_isHDRSupported(context.graphicsContext3D()->getExtensions().supports("GL_KHR_texture_compression_astc_hdr"_s )) |
| 40 | , m_isLDRSupported(context.graphicsContext3D()->getExtensions().supports("GL_KHR_texture_compression_astc_ldr"_s )) |
| 41 | { |
| 42 | context.addCompressedTextureFormat(Extensions3D::COMPRESSED_RGBA_ASTC_4x4_KHR); |
| 43 | context.addCompressedTextureFormat(Extensions3D::COMPRESSED_RGBA_ASTC_5x4_KHR); |
| 44 | context.addCompressedTextureFormat(Extensions3D::COMPRESSED_RGBA_ASTC_5x5_KHR); |
| 45 | context.addCompressedTextureFormat(Extensions3D::COMPRESSED_RGBA_ASTC_6x5_KHR); |
| 46 | context.addCompressedTextureFormat(Extensions3D::COMPRESSED_RGBA_ASTC_6x6_KHR); |
| 47 | context.addCompressedTextureFormat(Extensions3D::COMPRESSED_RGBA_ASTC_8x5_KHR); |
| 48 | context.addCompressedTextureFormat(Extensions3D::COMPRESSED_RGBA_ASTC_8x6_KHR); |
| 49 | context.addCompressedTextureFormat(Extensions3D::COMPRESSED_RGBA_ASTC_8x8_KHR); |
| 50 | context.addCompressedTextureFormat(Extensions3D::COMPRESSED_RGBA_ASTC_10x5_KHR); |
| 51 | context.addCompressedTextureFormat(Extensions3D::COMPRESSED_RGBA_ASTC_10x6_KHR); |
| 52 | context.addCompressedTextureFormat(Extensions3D::COMPRESSED_RGBA_ASTC_10x8_KHR); |
| 53 | context.addCompressedTextureFormat(Extensions3D::COMPRESSED_RGBA_ASTC_10x10_KHR); |
| 54 | context.addCompressedTextureFormat(Extensions3D::COMPRESSED_RGBA_ASTC_12x10_KHR); |
| 55 | context.addCompressedTextureFormat(Extensions3D::COMPRESSED_RGBA_ASTC_12x12_KHR); |
| 56 | |
| 57 | context.addCompressedTextureFormat(Extensions3D::COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR); |
| 58 | context.addCompressedTextureFormat(Extensions3D::COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR); |
| 59 | context.addCompressedTextureFormat(Extensions3D::COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR); |
| 60 | context.addCompressedTextureFormat(Extensions3D::COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR); |
| 61 | context.addCompressedTextureFormat(Extensions3D::COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR); |
| 62 | context.addCompressedTextureFormat(Extensions3D::COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR); |
| 63 | context.addCompressedTextureFormat(Extensions3D::COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR); |
| 64 | context.addCompressedTextureFormat(Extensions3D::COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR); |
| 65 | context.addCompressedTextureFormat(Extensions3D::COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR); |
| 66 | context.addCompressedTextureFormat(Extensions3D::COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR); |
| 67 | context.addCompressedTextureFormat(Extensions3D::COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR); |
| 68 | context.addCompressedTextureFormat(Extensions3D::COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR); |
| 69 | context.addCompressedTextureFormat(Extensions3D::COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR); |
| 70 | context.addCompressedTextureFormat(Extensions3D::COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR); |
| 71 | } |
| 72 | |
| 73 | WebGLCompressedTextureASTC::~WebGLCompressedTextureASTC() = default; |
| 74 | |
| 75 | WebGLExtension::ExtensionName WebGLCompressedTextureASTC::getName() const |
| 76 | { |
| 77 | return WebGLCompressedTextureASTCName; |
| 78 | } |
| 79 | |
| 80 | Vector<String> WebGLCompressedTextureASTC::getSupportedProfiles() |
| 81 | { |
| 82 | Vector<String> result; |
| 83 | |
| 84 | if (m_isHDRSupported) |
| 85 | result.append("hdr"_s ); |
| 86 | if (m_isLDRSupported) |
| 87 | result.append("ldr"_s ); |
| 88 | |
| 89 | return result; |
| 90 | } |
| 91 | |
| 92 | bool WebGLCompressedTextureASTC::supported(const WebGLRenderingContextBase& context) |
| 93 | { |
| 94 | return RuntimeEnabledFeatures::sharedFeatures().webGLCompressedTextureASTCSupportEnabled() |
| 95 | && (context.graphicsContext3D()->getExtensions().supports("GL_KHR_texture_compression_astc_hdr"_s ) |
| 96 | || context.graphicsContext3D()->getExtensions().supports("GL_KHR_texture_compression_astc_ldr"_s )); |
| 97 | } |
| 98 | |
| 99 | } // namespace WebCore |
| 100 | |
| 101 | #endif // ENABLE(WEBGL) |
| 102 | |