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 "JSGPUSamplerDescriptor.h" |
26 | |
27 | #include "JSDOMConvertNumbers.h" |
28 | #include "JSGPUCompareFunction.h" |
29 | #include <JavaScriptCore/JSCInlines.h> |
30 | #include <JavaScriptCore/JSString.h> |
31 | #include <wtf/NeverDestroyed.h> |
32 | |
33 | |
34 | namespace WebCore { |
35 | using namespace JSC; |
36 | |
37 | #if ENABLE(WEBGPU) |
38 | |
39 | template<> GPUSamplerDescriptor convertDictionary<GPUSamplerDescriptor>(ExecState& state, JSValue value) |
40 | { |
41 | VM& vm = state.vm(); |
42 | auto throwScope = DECLARE_THROW_SCOPE(vm); |
43 | bool isNullOrUndefined = value.isUndefinedOrNull(); |
44 | auto* object = isNullOrUndefined ? nullptr : value.getObject(); |
45 | if (UNLIKELY(!isNullOrUndefined && !object)) { |
46 | throwTypeError(&state, throwScope); |
47 | return { }; |
48 | } |
49 | GPUSamplerDescriptor result; |
50 | JSValue addressModeUValue; |
51 | if (isNullOrUndefined) |
52 | addressModeUValue = jsUndefined(); |
53 | else { |
54 | addressModeUValue = object->get(&state, Identifier::fromString(&state, "addressModeU" )); |
55 | RETURN_IF_EXCEPTION(throwScope, { }); |
56 | } |
57 | if (!addressModeUValue.isUndefined()) { |
58 | result.addressModeU = convert<IDLEnumeration<GPUAddressMode>>(state, addressModeUValue); |
59 | RETURN_IF_EXCEPTION(throwScope, { }); |
60 | } else |
61 | result.addressModeU = GPUAddressMode::ClampToEdge; |
62 | JSValue addressModeVValue; |
63 | if (isNullOrUndefined) |
64 | addressModeVValue = jsUndefined(); |
65 | else { |
66 | addressModeVValue = object->get(&state, Identifier::fromString(&state, "addressModeV" )); |
67 | RETURN_IF_EXCEPTION(throwScope, { }); |
68 | } |
69 | if (!addressModeVValue.isUndefined()) { |
70 | result.addressModeV = convert<IDLEnumeration<GPUAddressMode>>(state, addressModeVValue); |
71 | RETURN_IF_EXCEPTION(throwScope, { }); |
72 | } else |
73 | result.addressModeV = GPUAddressMode::ClampToEdge; |
74 | JSValue addressModeWValue; |
75 | if (isNullOrUndefined) |
76 | addressModeWValue = jsUndefined(); |
77 | else { |
78 | addressModeWValue = object->get(&state, Identifier::fromString(&state, "addressModeW" )); |
79 | RETURN_IF_EXCEPTION(throwScope, { }); |
80 | } |
81 | if (!addressModeWValue.isUndefined()) { |
82 | result.addressModeW = convert<IDLEnumeration<GPUAddressMode>>(state, addressModeWValue); |
83 | RETURN_IF_EXCEPTION(throwScope, { }); |
84 | } else |
85 | result.addressModeW = GPUAddressMode::ClampToEdge; |
86 | JSValue compareFunctionValue; |
87 | if (isNullOrUndefined) |
88 | compareFunctionValue = jsUndefined(); |
89 | else { |
90 | compareFunctionValue = object->get(&state, Identifier::fromString(&state, "compareFunction" )); |
91 | RETURN_IF_EXCEPTION(throwScope, { }); |
92 | } |
93 | if (!compareFunctionValue.isUndefined()) { |
94 | result.compareFunction = convert<IDLEnumeration<GPUCompareFunction>>(state, compareFunctionValue); |
95 | RETURN_IF_EXCEPTION(throwScope, { }); |
96 | } else |
97 | result.compareFunction = GPUCompareFunction::Never; |
98 | JSValue lodMaxClampValue; |
99 | if (isNullOrUndefined) |
100 | lodMaxClampValue = jsUndefined(); |
101 | else { |
102 | lodMaxClampValue = object->get(&state, Identifier::fromString(&state, "lodMaxClamp" )); |
103 | RETURN_IF_EXCEPTION(throwScope, { }); |
104 | } |
105 | if (!lodMaxClampValue.isUndefined()) { |
106 | result.lodMaxClamp = convert<IDLFloat>(state, lodMaxClampValue); |
107 | RETURN_IF_EXCEPTION(throwScope, { }); |
108 | } else |
109 | result.lodMaxClamp = 0xffffffff; |
110 | JSValue lodMinClampValue; |
111 | if (isNullOrUndefined) |
112 | lodMinClampValue = jsUndefined(); |
113 | else { |
114 | lodMinClampValue = object->get(&state, Identifier::fromString(&state, "lodMinClamp" )); |
115 | RETURN_IF_EXCEPTION(throwScope, { }); |
116 | } |
117 | if (!lodMinClampValue.isUndefined()) { |
118 | result.lodMinClamp = convert<IDLFloat>(state, lodMinClampValue); |
119 | RETURN_IF_EXCEPTION(throwScope, { }); |
120 | } else |
121 | result.lodMinClamp = 0; |
122 | JSValue magFilterValue; |
123 | if (isNullOrUndefined) |
124 | magFilterValue = jsUndefined(); |
125 | else { |
126 | magFilterValue = object->get(&state, Identifier::fromString(&state, "magFilter" )); |
127 | RETURN_IF_EXCEPTION(throwScope, { }); |
128 | } |
129 | if (!magFilterValue.isUndefined()) { |
130 | result.magFilter = convert<IDLEnumeration<GPUFilterMode>>(state, magFilterValue); |
131 | RETURN_IF_EXCEPTION(throwScope, { }); |
132 | } else |
133 | result.magFilter = GPUFilterMode::Nearest; |
134 | JSValue maxAnisotropyValue; |
135 | if (isNullOrUndefined) |
136 | maxAnisotropyValue = jsUndefined(); |
137 | else { |
138 | maxAnisotropyValue = object->get(&state, Identifier::fromString(&state, "maxAnisotropy" )); |
139 | RETURN_IF_EXCEPTION(throwScope, { }); |
140 | } |
141 | if (!maxAnisotropyValue.isUndefined()) { |
142 | result.maxAnisotropy = convert<IDLUnsignedLong>(state, maxAnisotropyValue); |
143 | RETURN_IF_EXCEPTION(throwScope, { }); |
144 | } else |
145 | result.maxAnisotropy = 1; |
146 | JSValue minFilterValue; |
147 | if (isNullOrUndefined) |
148 | minFilterValue = jsUndefined(); |
149 | else { |
150 | minFilterValue = object->get(&state, Identifier::fromString(&state, "minFilter" )); |
151 | RETURN_IF_EXCEPTION(throwScope, { }); |
152 | } |
153 | if (!minFilterValue.isUndefined()) { |
154 | result.minFilter = convert<IDLEnumeration<GPUFilterMode>>(state, minFilterValue); |
155 | RETURN_IF_EXCEPTION(throwScope, { }); |
156 | } else |
157 | result.minFilter = GPUFilterMode::Nearest; |
158 | JSValue mipmapFilterValue; |
159 | if (isNullOrUndefined) |
160 | mipmapFilterValue = jsUndefined(); |
161 | else { |
162 | mipmapFilterValue = object->get(&state, Identifier::fromString(&state, "mipmapFilter" )); |
163 | RETURN_IF_EXCEPTION(throwScope, { }); |
164 | } |
165 | if (!mipmapFilterValue.isUndefined()) { |
166 | result.mipmapFilter = convert<IDLEnumeration<GPUFilterMode>>(state, mipmapFilterValue); |
167 | RETURN_IF_EXCEPTION(throwScope, { }); |
168 | } else |
169 | result.mipmapFilter = GPUFilterMode::Nearest; |
170 | return result; |
171 | } |
172 | |
173 | #endif |
174 | |
175 | String convertEnumerationToString(GPUAddressMode enumerationValue) |
176 | { |
177 | static const NeverDestroyed<String> values[] = { |
178 | MAKE_STATIC_STRING_IMPL("clamp-to-edge" ), |
179 | MAKE_STATIC_STRING_IMPL("repeat" ), |
180 | MAKE_STATIC_STRING_IMPL("mirror-repeat" ), |
181 | }; |
182 | static_assert(static_cast<size_t>(GPUAddressMode::ClampToEdge) == 0, "GPUAddressMode::ClampToEdge is not 0 as expected" ); |
183 | static_assert(static_cast<size_t>(GPUAddressMode::Repeat) == 1, "GPUAddressMode::Repeat is not 1 as expected" ); |
184 | static_assert(static_cast<size_t>(GPUAddressMode::MirrorRepeat) == 2, "GPUAddressMode::MirrorRepeat is not 2 as expected" ); |
185 | ASSERT(static_cast<size_t>(enumerationValue) < WTF_ARRAY_LENGTH(values)); |
186 | return values[static_cast<size_t>(enumerationValue)]; |
187 | } |
188 | |
189 | template<> JSString* convertEnumerationToJS(ExecState& state, GPUAddressMode enumerationValue) |
190 | { |
191 | return jsStringWithCache(&state, convertEnumerationToString(enumerationValue)); |
192 | } |
193 | |
194 | template<> Optional<GPUAddressMode> parseEnumeration<GPUAddressMode>(ExecState& state, JSValue value) |
195 | { |
196 | auto stringValue = value.toWTFString(&state); |
197 | if (stringValue == "clamp-to-edge" ) |
198 | return GPUAddressMode::ClampToEdge; |
199 | if (stringValue == "repeat" ) |
200 | return GPUAddressMode::Repeat; |
201 | if (stringValue == "mirror-repeat" ) |
202 | return GPUAddressMode::MirrorRepeat; |
203 | return WTF::nullopt; |
204 | } |
205 | |
206 | template<> const char* expectedEnumerationValues<GPUAddressMode>() |
207 | { |
208 | return "\"clamp-to-edge\", \"repeat\", \"mirror-repeat\"" ; |
209 | } |
210 | |
211 | String convertEnumerationToString(GPUFilterMode enumerationValue) |
212 | { |
213 | static const NeverDestroyed<String> values[] = { |
214 | MAKE_STATIC_STRING_IMPL("nearest" ), |
215 | MAKE_STATIC_STRING_IMPL("linear" ), |
216 | }; |
217 | static_assert(static_cast<size_t>(GPUFilterMode::Nearest) == 0, "GPUFilterMode::Nearest is not 0 as expected" ); |
218 | static_assert(static_cast<size_t>(GPUFilterMode::Linear) == 1, "GPUFilterMode::Linear is not 1 as expected" ); |
219 | ASSERT(static_cast<size_t>(enumerationValue) < WTF_ARRAY_LENGTH(values)); |
220 | return values[static_cast<size_t>(enumerationValue)]; |
221 | } |
222 | |
223 | template<> JSString* convertEnumerationToJS(ExecState& state, GPUFilterMode enumerationValue) |
224 | { |
225 | return jsStringWithCache(&state, convertEnumerationToString(enumerationValue)); |
226 | } |
227 | |
228 | template<> Optional<GPUFilterMode> parseEnumeration<GPUFilterMode>(ExecState& state, JSValue value) |
229 | { |
230 | auto stringValue = value.toWTFString(&state); |
231 | if (stringValue == "nearest" ) |
232 | return GPUFilterMode::Nearest; |
233 | if (stringValue == "linear" ) |
234 | return GPUFilterMode::Linear; |
235 | return WTF::nullopt; |
236 | } |
237 | |
238 | template<> const char* expectedEnumerationValues<GPUFilterMode>() |
239 | { |
240 | return "\"nearest\", \"linear\"" ; |
241 | } |
242 | |
243 | } // namespace WebCore |
244 | |
245 | #endif // ENABLE(WEBGPU) |
246 | |