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 "JSWebGPURenderPipelineDescriptor.h"
26
27#include "JSDOMConvertInterface.h"
28#include "JSDOMConvertNullable.h"
29#include "JSDOMConvertSequences.h"
30#include "JSGPUColorStateDescriptor.h"
31#include "JSGPUDepthStencilStateDescriptor.h"
32#include "JSGPUInputStateDescriptor.h"
33#include "JSWebGPUPipelineLayout.h"
34#include "JSWebGPUPipelineStageDescriptor.h"
35#include <JavaScriptCore/JSArray.h>
36#include <JavaScriptCore/JSCInlines.h>
37#include <JavaScriptCore/JSString.h>
38#include <wtf/NeverDestroyed.h>
39
40
41namespace WebCore {
42using namespace JSC;
43
44#if ENABLE(WEBGPU)
45
46template<> WebGPURenderPipelineDescriptor convertDictionary<WebGPURenderPipelineDescriptor>(ExecState& state, JSValue value)
47{
48 VM& vm = state.vm();
49 auto throwScope = DECLARE_THROW_SCOPE(vm);
50 bool isNullOrUndefined = value.isUndefinedOrNull();
51 auto* object = isNullOrUndefined ? nullptr : value.getObject();
52 if (UNLIKELY(!isNullOrUndefined && !object)) {
53 throwTypeError(&state, throwScope);
54 return { };
55 }
56 WebGPURenderPipelineDescriptor result;
57 JSValue layoutValue;
58 if (isNullOrUndefined)
59 layoutValue = jsUndefined();
60 else {
61 layoutValue = object->get(&state, Identifier::fromString(&state, "layout"));
62 RETURN_IF_EXCEPTION(throwScope, { });
63 }
64 if (!layoutValue.isUndefined()) {
65 result.layout = convert<IDLNullable<IDLInterface<WebGPUPipelineLayout>>>(state, layoutValue);
66 RETURN_IF_EXCEPTION(throwScope, { });
67 } else
68 result.layout = nullptr;
69 JSValue colorStatesValue;
70 if (isNullOrUndefined)
71 colorStatesValue = jsUndefined();
72 else {
73 colorStatesValue = object->get(&state, Identifier::fromString(&state, "colorStates"));
74 RETURN_IF_EXCEPTION(throwScope, { });
75 }
76 if (!colorStatesValue.isUndefined()) {
77 result.colorStates = convert<IDLSequence<IDLDictionary<GPUColorStateDescriptor>>>(state, colorStatesValue);
78 RETURN_IF_EXCEPTION(throwScope, { });
79 } else {
80 throwRequiredMemberTypeError(state, throwScope, "colorStates", "WebGPURenderPipelineDescriptor", "sequence");
81 return { };
82 }
83 JSValue depthStencilStateValue;
84 if (isNullOrUndefined)
85 depthStencilStateValue = jsUndefined();
86 else {
87 depthStencilStateValue = object->get(&state, Identifier::fromString(&state, "depthStencilState"));
88 RETURN_IF_EXCEPTION(throwScope, { });
89 }
90 if (!depthStencilStateValue.isUndefined()) {
91 result.depthStencilState = convert<IDLNullable<IDLDictionary<GPUDepthStencilStateDescriptor>>>(state, depthStencilStateValue);
92 RETURN_IF_EXCEPTION(throwScope, { });
93 } else
94 result.depthStencilState = WTF::nullopt;
95 JSValue fragmentStageValue;
96 if (isNullOrUndefined)
97 fragmentStageValue = jsUndefined();
98 else {
99 fragmentStageValue = object->get(&state, Identifier::fromString(&state, "fragmentStage"));
100 RETURN_IF_EXCEPTION(throwScope, { });
101 }
102 if (!fragmentStageValue.isUndefined()) {
103 result.fragmentStage = convert<IDLNullable<IDLDictionary<WebGPUPipelineStageDescriptor>>>(state, fragmentStageValue);
104 RETURN_IF_EXCEPTION(throwScope, { });
105 } else
106 result.fragmentStage = WTF::nullopt;
107 JSValue inputStateValue;
108 if (isNullOrUndefined)
109 inputStateValue = jsUndefined();
110 else {
111 inputStateValue = object->get(&state, Identifier::fromString(&state, "inputState"));
112 RETURN_IF_EXCEPTION(throwScope, { });
113 }
114 if (!inputStateValue.isUndefined()) {
115 result.inputState = convert<IDLDictionary<GPUInputStateDescriptor>>(state, inputStateValue);
116 RETURN_IF_EXCEPTION(throwScope, { });
117 } else {
118 throwRequiredMemberTypeError(state, throwScope, "inputState", "WebGPURenderPipelineDescriptor", "GPUInputStateDescriptor");
119 return { };
120 }
121 JSValue primitiveTopologyValue;
122 if (isNullOrUndefined)
123 primitiveTopologyValue = jsUndefined();
124 else {
125 primitiveTopologyValue = object->get(&state, Identifier::fromString(&state, "primitiveTopology"));
126 RETURN_IF_EXCEPTION(throwScope, { });
127 }
128 if (!primitiveTopologyValue.isUndefined()) {
129 result.primitiveTopology = convert<IDLEnumeration<GPUPrimitiveTopology>>(state, primitiveTopologyValue);
130 RETURN_IF_EXCEPTION(throwScope, { });
131 } else {
132 throwRequiredMemberTypeError(state, throwScope, "primitiveTopology", "WebGPURenderPipelineDescriptor", "GPUPrimitiveTopology");
133 return { };
134 }
135 JSValue vertexStageValue;
136 if (isNullOrUndefined)
137 vertexStageValue = jsUndefined();
138 else {
139 vertexStageValue = object->get(&state, Identifier::fromString(&state, "vertexStage"));
140 RETURN_IF_EXCEPTION(throwScope, { });
141 }
142 if (!vertexStageValue.isUndefined()) {
143 result.vertexStage = convert<IDLDictionary<WebGPUPipelineStageDescriptor>>(state, vertexStageValue);
144 RETURN_IF_EXCEPTION(throwScope, { });
145 } else {
146 throwRequiredMemberTypeError(state, throwScope, "vertexStage", "WebGPURenderPipelineDescriptor", "WebGPUPipelineStageDescriptor");
147 return { };
148 }
149 return result;
150}
151
152#endif
153
154String convertEnumerationToString(GPUPrimitiveTopology enumerationValue)
155{
156 static const NeverDestroyed<String> values[] = {
157 MAKE_STATIC_STRING_IMPL("point-list"),
158 MAKE_STATIC_STRING_IMPL("line-list"),
159 MAKE_STATIC_STRING_IMPL("line-strip"),
160 MAKE_STATIC_STRING_IMPL("triangle-list"),
161 MAKE_STATIC_STRING_IMPL("triangle-strip"),
162 };
163 static_assert(static_cast<size_t>(GPUPrimitiveTopology::PointList) == 0, "GPUPrimitiveTopology::PointList is not 0 as expected");
164 static_assert(static_cast<size_t>(GPUPrimitiveTopology::LineList) == 1, "GPUPrimitiveTopology::LineList is not 1 as expected");
165 static_assert(static_cast<size_t>(GPUPrimitiveTopology::LineStrip) == 2, "GPUPrimitiveTopology::LineStrip is not 2 as expected");
166 static_assert(static_cast<size_t>(GPUPrimitiveTopology::TriangleList) == 3, "GPUPrimitiveTopology::TriangleList is not 3 as expected");
167 static_assert(static_cast<size_t>(GPUPrimitiveTopology::TriangleStrip) == 4, "GPUPrimitiveTopology::TriangleStrip is not 4 as expected");
168 ASSERT(static_cast<size_t>(enumerationValue) < WTF_ARRAY_LENGTH(values));
169 return values[static_cast<size_t>(enumerationValue)];
170}
171
172template<> JSString* convertEnumerationToJS(ExecState& state, GPUPrimitiveTopology enumerationValue)
173{
174 return jsStringWithCache(&state, convertEnumerationToString(enumerationValue));
175}
176
177template<> Optional<GPUPrimitiveTopology> parseEnumeration<GPUPrimitiveTopology>(ExecState& state, JSValue value)
178{
179 auto stringValue = value.toWTFString(&state);
180 if (stringValue == "point-list")
181 return GPUPrimitiveTopology::PointList;
182 if (stringValue == "line-list")
183 return GPUPrimitiveTopology::LineList;
184 if (stringValue == "line-strip")
185 return GPUPrimitiveTopology::LineStrip;
186 if (stringValue == "triangle-list")
187 return GPUPrimitiveTopology::TriangleList;
188 if (stringValue == "triangle-strip")
189 return GPUPrimitiveTopology::TriangleStrip;
190 return WTF::nullopt;
191}
192
193template<> const char* expectedEnumerationValues<GPUPrimitiveTopology>()
194{
195 return "\"point-list\", \"line-list\", \"line-strip\", \"triangle-list\", \"triangle-strip\"";
196}
197
198} // namespace WebCore
199
200#endif // ENABLE(WEBGPU)
201