commit-queue@webkit.org | 6128e13 | 2018-05-09 20:24:23 +0000 | [diff] [blame] | 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 | |
dino@apple.com | 92f9916 | 2020-01-06 18:52:42 +0000 | [diff] [blame] | 31 | #include "ExtensionsGL.h" |
commit-queue@webkit.org | 6128e13 | 2018-05-09 20:24:23 +0000 | [diff] [blame] | 32 | #include "RuntimeEnabledFeatures.h" |
| 33 | #include "WebGLRenderingContextBase.h" |
aperez@igalia.com | e2a465d | 2020-09-16 15:09:28 +0000 | [diff] [blame] | 34 | #include <wtf/IsoMallocInlines.h> |
commit-queue@webkit.org | 6128e13 | 2018-05-09 20:24:23 +0000 | [diff] [blame] | 35 | |
| 36 | namespace WebCore { |
dino@apple.com | bcd2bd4 | 2020-09-10 02:47:05 +0000 | [diff] [blame] | 37 | |
| 38 | WTF_MAKE_ISO_ALLOCATED_IMPL(WebGLCompressedTextureASTC); |
| 39 | |
commit-queue@webkit.org | 6128e13 | 2018-05-09 20:24:23 +0000 | [diff] [blame] | 40 | WebGLCompressedTextureASTC::WebGLCompressedTextureASTC(WebGLRenderingContextBase& context) |
| 41 | : WebGLExtension(context) |
dino@apple.com | 92f9916 | 2020-01-06 18:52:42 +0000 | [diff] [blame] | 42 | , m_isHDRSupported(context.graphicsContextGL()->getExtensions().supports("GL_KHR_texture_compression_astc_hdr"_s)) |
| 43 | , m_isLDRSupported(context.graphicsContextGL()->getExtensions().supports("GL_KHR_texture_compression_astc_ldr"_s)) |
commit-queue@webkit.org | 6128e13 | 2018-05-09 20:24:23 +0000 | [diff] [blame] | 44 | { |
dino@apple.com | 92f9916 | 2020-01-06 18:52:42 +0000 | [diff] [blame] | 45 | context.graphicsContextGL()->getExtensions().ensureEnabled("GL_KHR_texture_compression_astc_hdr"_s); |
| 46 | context.graphicsContextGL()->getExtensions().ensureEnabled("GL_KHR_texture_compression_astc_ldr"_s); |
commit-queue@webkit.org | 885f398 | 2019-08-28 20:34:19 +0000 | [diff] [blame] | 47 | |
dino@apple.com | 92f9916 | 2020-01-06 18:52:42 +0000 | [diff] [blame] | 48 | context.addCompressedTextureFormat(ExtensionsGL::COMPRESSED_RGBA_ASTC_4x4_KHR); |
| 49 | context.addCompressedTextureFormat(ExtensionsGL::COMPRESSED_RGBA_ASTC_5x4_KHR); |
| 50 | context.addCompressedTextureFormat(ExtensionsGL::COMPRESSED_RGBA_ASTC_5x5_KHR); |
| 51 | context.addCompressedTextureFormat(ExtensionsGL::COMPRESSED_RGBA_ASTC_6x5_KHR); |
| 52 | context.addCompressedTextureFormat(ExtensionsGL::COMPRESSED_RGBA_ASTC_6x6_KHR); |
| 53 | context.addCompressedTextureFormat(ExtensionsGL::COMPRESSED_RGBA_ASTC_8x5_KHR); |
| 54 | context.addCompressedTextureFormat(ExtensionsGL::COMPRESSED_RGBA_ASTC_8x6_KHR); |
| 55 | context.addCompressedTextureFormat(ExtensionsGL::COMPRESSED_RGBA_ASTC_8x8_KHR); |
| 56 | context.addCompressedTextureFormat(ExtensionsGL::COMPRESSED_RGBA_ASTC_10x5_KHR); |
| 57 | context.addCompressedTextureFormat(ExtensionsGL::COMPRESSED_RGBA_ASTC_10x6_KHR); |
| 58 | context.addCompressedTextureFormat(ExtensionsGL::COMPRESSED_RGBA_ASTC_10x8_KHR); |
| 59 | context.addCompressedTextureFormat(ExtensionsGL::COMPRESSED_RGBA_ASTC_10x10_KHR); |
| 60 | context.addCompressedTextureFormat(ExtensionsGL::COMPRESSED_RGBA_ASTC_12x10_KHR); |
| 61 | context.addCompressedTextureFormat(ExtensionsGL::COMPRESSED_RGBA_ASTC_12x12_KHR); |
commit-queue@webkit.org | 6128e13 | 2018-05-09 20:24:23 +0000 | [diff] [blame] | 62 | |
dino@apple.com | 92f9916 | 2020-01-06 18:52:42 +0000 | [diff] [blame] | 63 | context.addCompressedTextureFormat(ExtensionsGL::COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR); |
| 64 | context.addCompressedTextureFormat(ExtensionsGL::COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR); |
| 65 | context.addCompressedTextureFormat(ExtensionsGL::COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR); |
| 66 | context.addCompressedTextureFormat(ExtensionsGL::COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR); |
| 67 | context.addCompressedTextureFormat(ExtensionsGL::COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR); |
| 68 | context.addCompressedTextureFormat(ExtensionsGL::COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR); |
| 69 | context.addCompressedTextureFormat(ExtensionsGL::COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR); |
| 70 | context.addCompressedTextureFormat(ExtensionsGL::COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR); |
| 71 | context.addCompressedTextureFormat(ExtensionsGL::COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR); |
| 72 | context.addCompressedTextureFormat(ExtensionsGL::COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR); |
| 73 | context.addCompressedTextureFormat(ExtensionsGL::COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR); |
| 74 | context.addCompressedTextureFormat(ExtensionsGL::COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR); |
| 75 | context.addCompressedTextureFormat(ExtensionsGL::COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR); |
| 76 | context.addCompressedTextureFormat(ExtensionsGL::COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR); |
commit-queue@webkit.org | 6128e13 | 2018-05-09 20:24:23 +0000 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | WebGLCompressedTextureASTC::~WebGLCompressedTextureASTC() = default; |
| 80 | |
| 81 | WebGLExtension::ExtensionName WebGLCompressedTextureASTC::getName() const |
| 82 | { |
| 83 | return WebGLCompressedTextureASTCName; |
| 84 | } |
| 85 | |
| 86 | Vector<String> WebGLCompressedTextureASTC::getSupportedProfiles() |
| 87 | { |
| 88 | Vector<String> result; |
| 89 | |
| 90 | if (m_isHDRSupported) |
utatane.tea@gmail.com | 8407763 | 2018-06-23 08:39:34 +0000 | [diff] [blame] | 91 | result.append("hdr"_s); |
commit-queue@webkit.org | 6128e13 | 2018-05-09 20:24:23 +0000 | [diff] [blame] | 92 | if (m_isLDRSupported) |
utatane.tea@gmail.com | 8407763 | 2018-06-23 08:39:34 +0000 | [diff] [blame] | 93 | result.append("ldr"_s); |
commit-queue@webkit.org | 6128e13 | 2018-05-09 20:24:23 +0000 | [diff] [blame] | 94 | |
| 95 | return result; |
| 96 | } |
| 97 | |
| 98 | bool WebGLCompressedTextureASTC::supported(const WebGLRenderingContextBase& context) |
| 99 | { |
dino@apple.com | 92f9916 | 2020-01-06 18:52:42 +0000 | [diff] [blame] | 100 | return context.graphicsContextGL()->getExtensions().supports("GL_KHR_texture_compression_astc_hdr"_s) |
| 101 | || context.graphicsContextGL()->getExtensions().supports("GL_KHR_texture_compression_astc_ldr"_s); |
commit-queue@webkit.org | 6128e13 | 2018-05-09 20:24:23 +0000 | [diff] [blame] | 102 | } |
| 103 | |
| 104 | } // namespace WebCore |
| 105 | |
| 106 | #endif // ENABLE(WEBGL) |