1 | /* |
2 | * Copyright (C) 2017 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 "JSDOMConvertWebGL.h" |
28 | |
29 | #if ENABLE(WEBGL) |
30 | |
31 | #include "JSANGLEInstancedArrays.h" |
32 | #include "JSDOMConvertBufferSource.h" |
33 | #include "JSEXTBlendMinMax.h" |
34 | #include "JSEXTFragDepth.h" |
35 | #include "JSEXTShaderTextureLOD.h" |
36 | #include "JSEXTTextureFilterAnisotropic.h" |
37 | #include "JSEXTsRGB.h" |
38 | #include "JSOESElementIndexUint.h" |
39 | #include "JSOESStandardDerivatives.h" |
40 | #include "JSOESTextureFloat.h" |
41 | #include "JSOESTextureFloatLinear.h" |
42 | #include "JSOESTextureHalfFloat.h" |
43 | #include "JSOESTextureHalfFloatLinear.h" |
44 | #include "JSOESVertexArrayObject.h" |
45 | #include "JSWebGLBuffer.h" |
46 | #include "JSWebGLCompressedTextureASTC.h" |
47 | #include "JSWebGLCompressedTextureATC.h" |
48 | #include "JSWebGLCompressedTexturePVRTC.h" |
49 | #include "JSWebGLCompressedTextureS3TC.h" |
50 | #include "JSWebGLDebugRendererInfo.h" |
51 | #include "JSWebGLDebugShaders.h" |
52 | #include "JSWebGLDepthTexture.h" |
53 | #include "JSWebGLDrawBuffers.h" |
54 | #include "JSWebGLFramebuffer.h" |
55 | #include "JSWebGLLoseContext.h" |
56 | #include "JSWebGLProgram.h" |
57 | #include "JSWebGLRenderbuffer.h" |
58 | #include "JSWebGLTexture.h" |
59 | #include "JSWebGLVertexArrayObject.h" |
60 | #include "JSWebGLVertexArrayObjectOES.h" |
61 | #include <JavaScriptCore/JSCInlines.h> |
62 | |
63 | namespace WebCore { |
64 | using namespace JSC; |
65 | |
66 | // FIXME: This should use the IDLUnion JSConverter. |
67 | JSValue convertToJSValue(ExecState& state, JSDOMGlobalObject& globalObject, const WebGLAny& any) |
68 | { |
69 | return WTF::switchOn(any, |
70 | [] (std::nullptr_t) { |
71 | return jsNull(); |
72 | }, |
73 | [] (bool value) { |
74 | return jsBoolean(value); |
75 | }, |
76 | [] (int value) { |
77 | return jsNumber(value); |
78 | }, |
79 | [] (unsigned value) { |
80 | return jsNumber(value); |
81 | }, |
82 | [] (long long value) { |
83 | return jsNumber(value); |
84 | }, |
85 | [] (float value) { |
86 | return jsNumber(value); |
87 | }, |
88 | [&] (const String& value) { |
89 | return jsStringWithCache(&state, value); |
90 | }, |
91 | [&] (const Vector<bool>& values) { |
92 | MarkedArgumentBuffer list; |
93 | for (auto& value : values) |
94 | list.append(jsBoolean(value)); |
95 | RELEASE_ASSERT(!list.hasOverflowed()); |
96 | return constructArray(&state, 0, &globalObject, list); |
97 | }, |
98 | [&] (const Vector<int>& values) { |
99 | MarkedArgumentBuffer list; |
100 | for (auto& value : values) |
101 | list.append(jsNumber(value)); |
102 | RELEASE_ASSERT(!list.hasOverflowed()); |
103 | return constructArray(&state, 0, &globalObject, list); |
104 | }, |
105 | [&] (const RefPtr<Float32Array>& array) { |
106 | return toJS(&state, &globalObject, array.get()); |
107 | }, |
108 | [&] (const RefPtr<Int32Array>& array) { |
109 | return toJS(&state, &globalObject, array.get()); |
110 | }, |
111 | [&] (const RefPtr<Uint8Array>& array) { |
112 | return toJS(&state, &globalObject, array.get()); |
113 | }, |
114 | [&] (const RefPtr<Uint32Array>& array) { |
115 | return toJS(&state, &globalObject, array.get()); |
116 | }, |
117 | [&] (const RefPtr<WebGLBuffer>& buffer) { |
118 | return toJS(&state, &globalObject, buffer.get()); |
119 | }, |
120 | [&] (const RefPtr<WebGLFramebuffer>& buffer) { |
121 | return toJS(&state, &globalObject, buffer.get()); |
122 | }, |
123 | [&] (const RefPtr<WebGLProgram>& program) { |
124 | return toJS(&state, &globalObject, program.get()); |
125 | }, |
126 | [&] (const RefPtr<WebGLRenderbuffer>& buffer) { |
127 | return toJS(&state, &globalObject, buffer.get()); |
128 | }, |
129 | [&] (const RefPtr<WebGLTexture>& texture) { |
130 | return toJS(&state, &globalObject, texture.get()); |
131 | }, |
132 | [&] (const RefPtr<WebGLVertexArrayObjectOES>& array) { |
133 | return toJS(&state, &globalObject, array.get()); |
134 | } |
135 | #if ENABLE(WEBGL2) |
136 | , |
137 | [&] (const RefPtr<WebGLVertexArrayObject>& array) { |
138 | return toJS(&state, &globalObject, array.get()); |
139 | } |
140 | #endif |
141 | ); |
142 | } |
143 | |
144 | JSValue convertToJSValue(ExecState& state, JSDOMGlobalObject& globalObject, WebGLExtension& extension) |
145 | { |
146 | switch (extension.getName()) { |
147 | case WebGLExtension::WebGLLoseContextName: |
148 | return toJS(&state, &globalObject, static_cast<WebGLLoseContext&>(extension)); |
149 | case WebGLExtension::EXTShaderTextureLODName: |
150 | return toJS(&state, &globalObject, static_cast<EXTShaderTextureLOD&>(extension)); |
151 | case WebGLExtension::EXTTextureFilterAnisotropicName: |
152 | return toJS(&state, &globalObject, static_cast<EXTTextureFilterAnisotropic&>(extension)); |
153 | case WebGLExtension::EXTsRGBName: |
154 | return toJS(&state, &globalObject, static_cast<EXTsRGB&>(extension)); |
155 | case WebGLExtension::EXTFragDepthName: |
156 | return toJS(&state, &globalObject, static_cast<EXTFragDepth&>(extension)); |
157 | case WebGLExtension::EXTBlendMinMaxName: |
158 | return toJS(&state, &globalObject, static_cast<EXTBlendMinMax&>(extension)); |
159 | case WebGLExtension::OESStandardDerivativesName: |
160 | return toJS(&state, &globalObject, static_cast<OESStandardDerivatives&>(extension)); |
161 | case WebGLExtension::OESTextureFloatName: |
162 | return toJS(&state, &globalObject, static_cast<OESTextureFloat&>(extension)); |
163 | case WebGLExtension::OESTextureFloatLinearName: |
164 | return toJS(&state, &globalObject, static_cast<OESTextureFloatLinear&>(extension)); |
165 | case WebGLExtension::OESTextureHalfFloatName: |
166 | return toJS(&state, &globalObject, static_cast<OESTextureHalfFloat&>(extension)); |
167 | case WebGLExtension::OESTextureHalfFloatLinearName: |
168 | return toJS(&state, &globalObject, static_cast<OESTextureHalfFloatLinear&>(extension)); |
169 | case WebGLExtension::OESVertexArrayObjectName: |
170 | return toJS(&state, &globalObject, static_cast<OESVertexArrayObject&>(extension)); |
171 | case WebGLExtension::OESElementIndexUintName: |
172 | return toJS(&state, &globalObject, static_cast<OESElementIndexUint&>(extension)); |
173 | case WebGLExtension::WebGLDebugRendererInfoName: |
174 | return toJS(&state, &globalObject, static_cast<WebGLDebugRendererInfo&>(extension)); |
175 | case WebGLExtension::WebGLDebugShadersName: |
176 | return toJS(&state, &globalObject, static_cast<WebGLDebugShaders&>(extension)); |
177 | case WebGLExtension::WebGLCompressedTextureATCName: |
178 | return toJS(&state, &globalObject, static_cast<WebGLCompressedTextureATC&>(extension)); |
179 | case WebGLExtension::WebGLCompressedTexturePVRTCName: |
180 | return toJS(&state, &globalObject, static_cast<WebGLCompressedTexturePVRTC&>(extension)); |
181 | case WebGLExtension::WebGLCompressedTextureS3TCName: |
182 | return toJS(&state, &globalObject, static_cast<WebGLCompressedTextureS3TC&>(extension)); |
183 | case WebGLExtension::WebGLCompressedTextureASTCName: |
184 | return toJS(&state, &globalObject, static_cast<WebGLCompressedTextureASTC&>(extension)); |
185 | case WebGLExtension::WebGLDepthTextureName: |
186 | return toJS(&state, &globalObject, static_cast<WebGLDepthTexture&>(extension)); |
187 | case WebGLExtension::WebGLDrawBuffersName: |
188 | return toJS(&state, &globalObject, static_cast<WebGLDrawBuffers&>(extension)); |
189 | case WebGLExtension::ANGLEInstancedArraysName: |
190 | return toJS(&state, &globalObject, static_cast<ANGLEInstancedArrays&>(extension)); |
191 | } |
192 | ASSERT_NOT_REACHED(); |
193 | return jsNull(); |
194 | } |
195 | |
196 | } |
197 | |
198 | #endif |
199 | |
200 | |