| 1 | /* |
| 2 | This file is part of the WebKit open source project. |
| 3 | This file has been generated by generate-bindings.pl. DO NOT MODIFY! |
| 4 | |
| 5 | This library is free software; you can redistribute it and/or |
| 6 | modify it under the terms of the GNU Library General Public |
| 7 | License as published by the Free Software Foundation; either |
| 8 | version 2 of the License, or (at your option) any later version. |
| 9 | |
| 10 | This library is distributed in the hope that it will be useful, |
| 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 | Library General Public License for more details. |
| 14 | |
| 15 | You should have received a copy of the GNU Library General Public License |
| 16 | along with this library; see the file COPYING.LIB. If not, write to |
| 17 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 18 | Boston, MA 02110-1301, USA. |
| 19 | */ |
| 20 | |
| 21 | #include "config.h" |
| 22 | |
| 23 | #if ENABLE(WEBGPU) |
| 24 | |
| 25 | #include "JSGPUTextureDescriptor.h" |
| 26 | |
| 27 | #include "JSDOMConvertNumbers.h" |
| 28 | #include "JSGPUExtent3D.h" |
| 29 | #include "JSGPUTextureFormat.h" |
| 30 | #include <JavaScriptCore/JSCInlines.h> |
| 31 | #include <JavaScriptCore/JSString.h> |
| 32 | #include <wtf/NeverDestroyed.h> |
| 33 | |
| 34 | |
| 35 | namespace WebCore { |
| 36 | using namespace JSC; |
| 37 | |
| 38 | #if ENABLE(WEBGPU) |
| 39 | |
| 40 | template<> GPUTextureDescriptor convertDictionary<GPUTextureDescriptor>(ExecState& state, JSValue value) |
| 41 | { |
| 42 | VM& vm = state.vm(); |
| 43 | auto throwScope = DECLARE_THROW_SCOPE(vm); |
| 44 | bool isNullOrUndefined = value.isUndefinedOrNull(); |
| 45 | auto* object = isNullOrUndefined ? nullptr : value.getObject(); |
| 46 | if (UNLIKELY(!isNullOrUndefined && !object)) { |
| 47 | throwTypeError(&state, throwScope); |
| 48 | return { }; |
| 49 | } |
| 50 | GPUTextureDescriptor result; |
| 51 | JSValue arrayLayerCountValue; |
| 52 | if (isNullOrUndefined) |
| 53 | arrayLayerCountValue = jsUndefined(); |
| 54 | else { |
| 55 | arrayLayerCountValue = object->get(&state, Identifier::fromString(&state, "arrayLayerCount" )); |
| 56 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 57 | } |
| 58 | if (!arrayLayerCountValue.isUndefined()) { |
| 59 | result.arrayLayerCount = convert<IDLUnsignedLong>(state, arrayLayerCountValue); |
| 60 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 61 | } else |
| 62 | result.arrayLayerCount = 1; |
| 63 | JSValue dimensionValue; |
| 64 | if (isNullOrUndefined) |
| 65 | dimensionValue = jsUndefined(); |
| 66 | else { |
| 67 | dimensionValue = object->get(&state, Identifier::fromString(&state, "dimension" )); |
| 68 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 69 | } |
| 70 | if (!dimensionValue.isUndefined()) { |
| 71 | result.dimension = convert<IDLEnumeration<GPUTextureDimension>>(state, dimensionValue); |
| 72 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 73 | } else |
| 74 | result.dimension = GPUTextureDimension::_2d; |
| 75 | JSValue formatValue; |
| 76 | if (isNullOrUndefined) |
| 77 | formatValue = jsUndefined(); |
| 78 | else { |
| 79 | formatValue = object->get(&state, Identifier::fromString(&state, "format" )); |
| 80 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 81 | } |
| 82 | if (!formatValue.isUndefined()) { |
| 83 | result.format = convert<IDLEnumeration<GPUTextureFormat>>(state, formatValue); |
| 84 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 85 | } else { |
| 86 | throwRequiredMemberTypeError(state, throwScope, "format" , "GPUTextureDescriptor" , "GPUTextureFormat" ); |
| 87 | return { }; |
| 88 | } |
| 89 | JSValue mipLevelCountValue; |
| 90 | if (isNullOrUndefined) |
| 91 | mipLevelCountValue = jsUndefined(); |
| 92 | else { |
| 93 | mipLevelCountValue = object->get(&state, Identifier::fromString(&state, "mipLevelCount" )); |
| 94 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 95 | } |
| 96 | if (!mipLevelCountValue.isUndefined()) { |
| 97 | result.mipLevelCount = convert<IDLUnsignedLong>(state, mipLevelCountValue); |
| 98 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 99 | } else |
| 100 | result.mipLevelCount = 1; |
| 101 | JSValue sampleCountValue; |
| 102 | if (isNullOrUndefined) |
| 103 | sampleCountValue = jsUndefined(); |
| 104 | else { |
| 105 | sampleCountValue = object->get(&state, Identifier::fromString(&state, "sampleCount" )); |
| 106 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 107 | } |
| 108 | if (!sampleCountValue.isUndefined()) { |
| 109 | result.sampleCount = convert<IDLUnsignedLong>(state, sampleCountValue); |
| 110 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 111 | } else |
| 112 | result.sampleCount = 1; |
| 113 | JSValue sizeValue; |
| 114 | if (isNullOrUndefined) |
| 115 | sizeValue = jsUndefined(); |
| 116 | else { |
| 117 | sizeValue = object->get(&state, Identifier::fromString(&state, "size" )); |
| 118 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 119 | } |
| 120 | if (!sizeValue.isUndefined()) { |
| 121 | result.size = convert<IDLDictionary<GPUExtent3D>>(state, sizeValue); |
| 122 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 123 | } else { |
| 124 | throwRequiredMemberTypeError(state, throwScope, "size" , "GPUTextureDescriptor" , "GPUExtent3D" ); |
| 125 | return { }; |
| 126 | } |
| 127 | JSValue usageValue; |
| 128 | if (isNullOrUndefined) |
| 129 | usageValue = jsUndefined(); |
| 130 | else { |
| 131 | usageValue = object->get(&state, Identifier::fromString(&state, "usage" )); |
| 132 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 133 | } |
| 134 | if (!usageValue.isUndefined()) { |
| 135 | result.usage = convert<IDLUnsignedLong>(state, usageValue); |
| 136 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 137 | } else { |
| 138 | throwRequiredMemberTypeError(state, throwScope, "usage" , "GPUTextureDescriptor" , "unsigned long" ); |
| 139 | return { }; |
| 140 | } |
| 141 | return result; |
| 142 | } |
| 143 | |
| 144 | #endif |
| 145 | |
| 146 | String convertEnumerationToString(GPUTextureDimension enumerationValue) |
| 147 | { |
| 148 | static const NeverDestroyed<String> values[] = { |
| 149 | MAKE_STATIC_STRING_IMPL("1d" ), |
| 150 | MAKE_STATIC_STRING_IMPL("2d" ), |
| 151 | MAKE_STATIC_STRING_IMPL("3d" ), |
| 152 | }; |
| 153 | static_assert(static_cast<size_t>(GPUTextureDimension::_1d) == 0, "GPUTextureDimension::_1d is not 0 as expected" ); |
| 154 | static_assert(static_cast<size_t>(GPUTextureDimension::_2d) == 1, "GPUTextureDimension::_2d is not 1 as expected" ); |
| 155 | static_assert(static_cast<size_t>(GPUTextureDimension::_3d) == 2, "GPUTextureDimension::_3d is not 2 as expected" ); |
| 156 | ASSERT(static_cast<size_t>(enumerationValue) < WTF_ARRAY_LENGTH(values)); |
| 157 | return values[static_cast<size_t>(enumerationValue)]; |
| 158 | } |
| 159 | |
| 160 | template<> JSString* convertEnumerationToJS(ExecState& state, GPUTextureDimension enumerationValue) |
| 161 | { |
| 162 | return jsStringWithCache(&state, convertEnumerationToString(enumerationValue)); |
| 163 | } |
| 164 | |
| 165 | template<> Optional<GPUTextureDimension> parseEnumeration<GPUTextureDimension>(ExecState& state, JSValue value) |
| 166 | { |
| 167 | auto stringValue = value.toWTFString(&state); |
| 168 | if (stringValue == "1d" ) |
| 169 | return GPUTextureDimension::_1d; |
| 170 | if (stringValue == "2d" ) |
| 171 | return GPUTextureDimension::_2d; |
| 172 | if (stringValue == "3d" ) |
| 173 | return GPUTextureDimension::_3d; |
| 174 | return WTF::nullopt; |
| 175 | } |
| 176 | |
| 177 | template<> const char* expectedEnumerationValues<GPUTextureDimension>() |
| 178 | { |
| 179 | return "\"1d\", \"2d\", \"3d\"" ; |
| 180 | } |
| 181 | |
| 182 | } // namespace WebCore |
| 183 | |
| 184 | #endif // ENABLE(WEBGPU) |
| 185 | |