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 "JSGPUBlendDescriptor.h"
26
27#include <JavaScriptCore/JSCInlines.h>
28#include <JavaScriptCore/JSString.h>
29#include <wtf/NeverDestroyed.h>
30
31
32namespace WebCore {
33using namespace JSC;
34
35#if ENABLE(WEBGPU)
36
37template<> GPUBlendDescriptor convertDictionary<GPUBlendDescriptor>(ExecState& state, JSValue value)
38{
39 VM& vm = state.vm();
40 auto throwScope = DECLARE_THROW_SCOPE(vm);
41 bool isNullOrUndefined = value.isUndefinedOrNull();
42 auto* object = isNullOrUndefined ? nullptr : value.getObject();
43 if (UNLIKELY(!isNullOrUndefined && !object)) {
44 throwTypeError(&state, throwScope);
45 return { };
46 }
47 GPUBlendDescriptor result;
48 JSValue dstFactorValue;
49 if (isNullOrUndefined)
50 dstFactorValue = jsUndefined();
51 else {
52 dstFactorValue = object->get(&state, Identifier::fromString(&state, "dstFactor"));
53 RETURN_IF_EXCEPTION(throwScope, { });
54 }
55 if (!dstFactorValue.isUndefined()) {
56 result.dstFactor = convert<IDLEnumeration<GPUBlendFactor>>(state, dstFactorValue);
57 RETURN_IF_EXCEPTION(throwScope, { });
58 } else
59 result.dstFactor = GPUBlendFactor::Zero;
60 JSValue operationValue;
61 if (isNullOrUndefined)
62 operationValue = jsUndefined();
63 else {
64 operationValue = object->get(&state, Identifier::fromString(&state, "operation"));
65 RETURN_IF_EXCEPTION(throwScope, { });
66 }
67 if (!operationValue.isUndefined()) {
68 result.operation = convert<IDLEnumeration<GPUBlendOperation>>(state, operationValue);
69 RETURN_IF_EXCEPTION(throwScope, { });
70 } else
71 result.operation = GPUBlendOperation::Add;
72 JSValue srcFactorValue;
73 if (isNullOrUndefined)
74 srcFactorValue = jsUndefined();
75 else {
76 srcFactorValue = object->get(&state, Identifier::fromString(&state, "srcFactor"));
77 RETURN_IF_EXCEPTION(throwScope, { });
78 }
79 if (!srcFactorValue.isUndefined()) {
80 result.srcFactor = convert<IDLEnumeration<GPUBlendFactor>>(state, srcFactorValue);
81 RETURN_IF_EXCEPTION(throwScope, { });
82 } else
83 result.srcFactor = GPUBlendFactor::One;
84 return result;
85}
86
87#endif
88
89String convertEnumerationToString(GPUBlendFactor enumerationValue)
90{
91 static const NeverDestroyed<String> values[] = {
92 MAKE_STATIC_STRING_IMPL("zero"),
93 MAKE_STATIC_STRING_IMPL("one"),
94 MAKE_STATIC_STRING_IMPL("src-color"),
95 MAKE_STATIC_STRING_IMPL("one-minus-src-color"),
96 MAKE_STATIC_STRING_IMPL("src-alpha"),
97 MAKE_STATIC_STRING_IMPL("one-minus-src-alpha"),
98 MAKE_STATIC_STRING_IMPL("dst-color"),
99 MAKE_STATIC_STRING_IMPL("one-minus-dst-color"),
100 MAKE_STATIC_STRING_IMPL("dst-alpha"),
101 MAKE_STATIC_STRING_IMPL("one-minus-dst-alpha"),
102 MAKE_STATIC_STRING_IMPL("src-alpha-saturated"),
103 MAKE_STATIC_STRING_IMPL("blend-color"),
104 MAKE_STATIC_STRING_IMPL("one-minus-blend-color"),
105 };
106 static_assert(static_cast<size_t>(GPUBlendFactor::Zero) == 0, "GPUBlendFactor::Zero is not 0 as expected");
107 static_assert(static_cast<size_t>(GPUBlendFactor::One) == 1, "GPUBlendFactor::One is not 1 as expected");
108 static_assert(static_cast<size_t>(GPUBlendFactor::SrcColor) == 2, "GPUBlendFactor::SrcColor is not 2 as expected");
109 static_assert(static_cast<size_t>(GPUBlendFactor::OneMinusSrcColor) == 3, "GPUBlendFactor::OneMinusSrcColor is not 3 as expected");
110 static_assert(static_cast<size_t>(GPUBlendFactor::SrcAlpha) == 4, "GPUBlendFactor::SrcAlpha is not 4 as expected");
111 static_assert(static_cast<size_t>(GPUBlendFactor::OneMinusSrcAlpha) == 5, "GPUBlendFactor::OneMinusSrcAlpha is not 5 as expected");
112 static_assert(static_cast<size_t>(GPUBlendFactor::DstColor) == 6, "GPUBlendFactor::DstColor is not 6 as expected");
113 static_assert(static_cast<size_t>(GPUBlendFactor::OneMinusDstColor) == 7, "GPUBlendFactor::OneMinusDstColor is not 7 as expected");
114 static_assert(static_cast<size_t>(GPUBlendFactor::DstAlpha) == 8, "GPUBlendFactor::DstAlpha is not 8 as expected");
115 static_assert(static_cast<size_t>(GPUBlendFactor::OneMinusDstAlpha) == 9, "GPUBlendFactor::OneMinusDstAlpha is not 9 as expected");
116 static_assert(static_cast<size_t>(GPUBlendFactor::SrcAlphaSaturated) == 10, "GPUBlendFactor::SrcAlphaSaturated is not 10 as expected");
117 static_assert(static_cast<size_t>(GPUBlendFactor::BlendColor) == 11, "GPUBlendFactor::BlendColor is not 11 as expected");
118 static_assert(static_cast<size_t>(GPUBlendFactor::OneMinusBlendColor) == 12, "GPUBlendFactor::OneMinusBlendColor is not 12 as expected");
119 ASSERT(static_cast<size_t>(enumerationValue) < WTF_ARRAY_LENGTH(values));
120 return values[static_cast<size_t>(enumerationValue)];
121}
122
123template<> JSString* convertEnumerationToJS(ExecState& state, GPUBlendFactor enumerationValue)
124{
125 return jsStringWithCache(&state, convertEnumerationToString(enumerationValue));
126}
127
128template<> Optional<GPUBlendFactor> parseEnumeration<GPUBlendFactor>(ExecState& state, JSValue value)
129{
130 auto stringValue = value.toWTFString(&state);
131 if (stringValue == "zero")
132 return GPUBlendFactor::Zero;
133 if (stringValue == "one")
134 return GPUBlendFactor::One;
135 if (stringValue == "src-color")
136 return GPUBlendFactor::SrcColor;
137 if (stringValue == "one-minus-src-color")
138 return GPUBlendFactor::OneMinusSrcColor;
139 if (stringValue == "src-alpha")
140 return GPUBlendFactor::SrcAlpha;
141 if (stringValue == "one-minus-src-alpha")
142 return GPUBlendFactor::OneMinusSrcAlpha;
143 if (stringValue == "dst-color")
144 return GPUBlendFactor::DstColor;
145 if (stringValue == "one-minus-dst-color")
146 return GPUBlendFactor::OneMinusDstColor;
147 if (stringValue == "dst-alpha")
148 return GPUBlendFactor::DstAlpha;
149 if (stringValue == "one-minus-dst-alpha")
150 return GPUBlendFactor::OneMinusDstAlpha;
151 if (stringValue == "src-alpha-saturated")
152 return GPUBlendFactor::SrcAlphaSaturated;
153 if (stringValue == "blend-color")
154 return GPUBlendFactor::BlendColor;
155 if (stringValue == "one-minus-blend-color")
156 return GPUBlendFactor::OneMinusBlendColor;
157 return WTF::nullopt;
158}
159
160template<> const char* expectedEnumerationValues<GPUBlendFactor>()
161{
162 return "\"zero\", \"one\", \"src-color\", \"one-minus-src-color\", \"src-alpha\", \"one-minus-src-alpha\", \"dst-color\", \"one-minus-dst-color\", \"dst-alpha\", \"one-minus-dst-alpha\", \"src-alpha-saturated\", \"blend-color\", \"one-minus-blend-color\"";
163}
164
165String convertEnumerationToString(GPUBlendOperation enumerationValue)
166{
167 static const NeverDestroyed<String> values[] = {
168 MAKE_STATIC_STRING_IMPL("add"),
169 MAKE_STATIC_STRING_IMPL("subtract"),
170 MAKE_STATIC_STRING_IMPL("reverse-subtract"),
171 MAKE_STATIC_STRING_IMPL("min"),
172 MAKE_STATIC_STRING_IMPL("max"),
173 };
174 static_assert(static_cast<size_t>(GPUBlendOperation::Add) == 0, "GPUBlendOperation::Add is not 0 as expected");
175 static_assert(static_cast<size_t>(GPUBlendOperation::Subtract) == 1, "GPUBlendOperation::Subtract is not 1 as expected");
176 static_assert(static_cast<size_t>(GPUBlendOperation::ReverseSubtract) == 2, "GPUBlendOperation::ReverseSubtract is not 2 as expected");
177 static_assert(static_cast<size_t>(GPUBlendOperation::Min) == 3, "GPUBlendOperation::Min is not 3 as expected");
178 static_assert(static_cast<size_t>(GPUBlendOperation::Max) == 4, "GPUBlendOperation::Max is not 4 as expected");
179 ASSERT(static_cast<size_t>(enumerationValue) < WTF_ARRAY_LENGTH(values));
180 return values[static_cast<size_t>(enumerationValue)];
181}
182
183template<> JSString* convertEnumerationToJS(ExecState& state, GPUBlendOperation enumerationValue)
184{
185 return jsStringWithCache(&state, convertEnumerationToString(enumerationValue));
186}
187
188template<> Optional<GPUBlendOperation> parseEnumeration<GPUBlendOperation>(ExecState& state, JSValue value)
189{
190 auto stringValue = value.toWTFString(&state);
191 if (stringValue == "add")
192 return GPUBlendOperation::Add;
193 if (stringValue == "subtract")
194 return GPUBlendOperation::Subtract;
195 if (stringValue == "reverse-subtract")
196 return GPUBlendOperation::ReverseSubtract;
197 if (stringValue == "min")
198 return GPUBlendOperation::Min;
199 if (stringValue == "max")
200 return GPUBlendOperation::Max;
201 return WTF::nullopt;
202}
203
204template<> const char* expectedEnumerationValues<GPUBlendOperation>()
205{
206 return "\"add\", \"subtract\", \"reverse-subtract\", \"min\", \"max\"";
207}
208
209} // namespace WebCore
210
211#endif // ENABLE(WEBGPU)
212