Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(60)

Side by Side Diff: sky/engine/bindings/core/v8/custom/V8WebGLRenderingContextCustom.cpp

Issue 922053002: Remove unused V8 integration code in Sky (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 /*
2 * Copyright (C) 2009 Google 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 are
6 * met:
7 *
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
13 * distribution.
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31 #include "sky/engine/config.h"
32 #include "bindings/core/v8/V8WebGLRenderingContext.h"
33
34 #include <limits>
35 #include "bindings/core/v8/V8ANGLEInstancedArrays.h"
36 #include "bindings/core/v8/V8EXTBlendMinMax.h"
37 #include "bindings/core/v8/V8EXTFragDepth.h"
38 #include "bindings/core/v8/V8EXTShaderTextureLOD.h"
39 #include "bindings/core/v8/V8EXTTextureFilterAnisotropic.h"
40 #include "bindings/core/v8/V8HTMLCanvasElement.h"
41 #include "bindings/core/v8/V8HTMLImageElement.h"
42 #include "bindings/core/v8/V8ImageData.h"
43 #include "bindings/core/v8/V8OESElementIndexUint.h"
44 #include "bindings/core/v8/V8OESStandardDerivatives.h"
45 #include "bindings/core/v8/V8OESTextureFloat.h"
46 #include "bindings/core/v8/V8OESTextureFloatLinear.h"
47 #include "bindings/core/v8/V8OESTextureHalfFloat.h"
48 #include "bindings/core/v8/V8OESTextureHalfFloatLinear.h"
49 #include "bindings/core/v8/V8OESVertexArrayObject.h"
50 #include "bindings/core/v8/V8WebGLBuffer.h"
51 #include "bindings/core/v8/V8WebGLCompressedTextureATC.h"
52 #include "bindings/core/v8/V8WebGLCompressedTextureETC1.h"
53 #include "bindings/core/v8/V8WebGLCompressedTexturePVRTC.h"
54 #include "bindings/core/v8/V8WebGLCompressedTextureS3TC.h"
55 #include "bindings/core/v8/V8WebGLDebugRendererInfo.h"
56 #include "bindings/core/v8/V8WebGLDebugShaders.h"
57 #include "bindings/core/v8/V8WebGLDepthTexture.h"
58 #include "bindings/core/v8/V8WebGLDrawBuffers.h"
59 #include "bindings/core/v8/V8WebGLFramebuffer.h"
60 #include "bindings/core/v8/V8WebGLLoseContext.h"
61 #include "bindings/core/v8/V8WebGLProgram.h"
62 #include "bindings/core/v8/V8WebGLRenderbuffer.h"
63 #include "bindings/core/v8/V8WebGLShader.h"
64 #include "bindings/core/v8/V8WebGLTexture.h"
65 #include "bindings/core/v8/V8WebGLUniformLocation.h"
66 #include "bindings/core/v8/V8WebGLVertexArrayObjectOES.h"
67 #include "sky/engine/bindings/core/v8/ExceptionMessages.h"
68 #include "sky/engine/bindings/core/v8/V8Binding.h"
69 #include "sky/engine/bindings/core/v8/V8HiddenValue.h"
70 #include "sky/engine/bindings/core/v8/custom/V8ArrayBufferViewCustom.h"
71 #include "sky/engine/bindings/core/v8/custom/V8Float32ArrayCustom.h"
72 #include "sky/engine/bindings/core/v8/custom/V8Int16ArrayCustom.h"
73 #include "sky/engine/bindings/core/v8/custom/V8Int32ArrayCustom.h"
74 #include "sky/engine/bindings/core/v8/custom/V8Int8ArrayCustom.h"
75 #include "sky/engine/bindings/core/v8/custom/V8Uint16ArrayCustom.h"
76 #include "sky/engine/bindings/core/v8/custom/V8Uint32ArrayCustom.h"
77 #include "sky/engine/bindings/core/v8/custom/V8Uint8ArrayCustom.h"
78 #include "sky/engine/core/dom/ExceptionCode.h"
79 #include "sky/engine/core/html/canvas/WebGLRenderingContext.h"
80 #include "sky/engine/platform/NotImplemented.h"
81 #include "sky/engine/wtf/FastMalloc.h"
82
83 namespace blink {
84
85 // Allocates new storage via fastMalloc.
86 // Returns 0 if array failed to convert for any reason.
87 static float* jsArrayToFloatArray(v8::Handle<v8::Array> array, uint32_t len, Exc eptionState& exceptionState)
88 {
89 // Convert the data element-by-element.
90 if (len > std::numeric_limits<uint32_t>::max() / sizeof(float)) {
91 exceptionState.throwTypeError("Array length exceeds supported limit.");
92 return 0;
93 }
94 float* data = static_cast<float*>(fastMalloc(len * sizeof(float)));
95
96 for (uint32_t i = 0; i < len; i++) {
97 v8::Local<v8::Value> val = array->Get(i);
98 float value = toFloat(val, exceptionState);
99 if (exceptionState.hadException()) {
100 fastFree(data);
101 return 0;
102 }
103 data[i] = value;
104 }
105 return data;
106 }
107
108 // Allocates new storage via fastMalloc.
109 // Returns 0 if array failed to convert for any reason.
110 static int* jsArrayToIntArray(v8::Handle<v8::Array> array, uint32_t len, Excepti onState& exceptionState)
111 {
112 // Convert the data element-by-element.
113 if (len > std::numeric_limits<uint32_t>::max() / sizeof(int)) {
114 exceptionState.throwTypeError("Array length exceeds supported limit.");
115 return 0;
116 }
117 int* data = static_cast<int*>(fastMalloc(len * sizeof(int)));
118
119 for (uint32_t i = 0; i < len; i++) {
120 v8::Local<v8::Value> val = array->Get(i);
121 int ival = toInt32(val, exceptionState);
122 if (exceptionState.hadException()) {
123 fastFree(data);
124 return 0;
125 }
126 data[i] = ival;
127 }
128 return data;
129 }
130
131 static v8::Handle<v8::Value> toV8Object(const WebGLGetInfo& args, v8::Handle<v8: :Object> creationContext, v8::Isolate* isolate)
132 {
133 switch (args.getType()) {
134 case WebGLGetInfo::kTypeBool:
135 return v8Boolean(args.getBool(), isolate);
136 case WebGLGetInfo::kTypeBoolArray: {
137 const Vector<bool>& value = args.getBoolArray();
138 v8::Local<v8::Array> array = v8::Array::New(isolate, value.size());
139 for (size_t ii = 0; ii < value.size(); ++ii)
140 array->Set(v8::Integer::New(isolate, ii), v8Boolean(value[ii], isola te));
141 return array;
142 }
143 case WebGLGetInfo::kTypeFloat:
144 return v8::Number::New(isolate, args.getFloat());
145 case WebGLGetInfo::kTypeInt:
146 return v8::Integer::New(isolate, args.getInt());
147 case WebGLGetInfo::kTypeNull:
148 return v8::Null(isolate);
149 case WebGLGetInfo::kTypeString:
150 return v8String(isolate, args.getString());
151 case WebGLGetInfo::kTypeUnsignedInt:
152 return v8::Integer::NewFromUnsigned(isolate, args.getUnsignedInt());
153 case WebGLGetInfo::kTypeWebGLBuffer:
154 return toV8(args.getWebGLBuffer(), creationContext, isolate);
155 case WebGLGetInfo::kTypeWebGLFloatArray:
156 return toV8(args.getWebGLFloatArray(), creationContext, isolate);
157 case WebGLGetInfo::kTypeWebGLFramebuffer:
158 return toV8(args.getWebGLFramebuffer(), creationContext, isolate);
159 case WebGLGetInfo::kTypeWebGLIntArray:
160 return toV8(args.getWebGLIntArray(), creationContext, isolate);
161 // FIXME: implement WebGLObjectArray
162 // case WebGLGetInfo::kTypeWebGLObjectArray:
163 case WebGLGetInfo::kTypeWebGLProgram:
164 return toV8(args.getWebGLProgram(), creationContext, isolate);
165 case WebGLGetInfo::kTypeWebGLRenderbuffer:
166 return toV8(args.getWebGLRenderbuffer(), creationContext, isolate);
167 case WebGLGetInfo::kTypeWebGLTexture:
168 return toV8(args.getWebGLTexture(), creationContext, isolate);
169 case WebGLGetInfo::kTypeWebGLUnsignedByteArray:
170 return toV8(args.getWebGLUnsignedByteArray(), creationContext, isolate);
171 case WebGLGetInfo::kTypeWebGLUnsignedIntArray:
172 return toV8(args.getWebGLUnsignedIntArray(), creationContext, isolate);
173 case WebGLGetInfo::kTypeWebGLVertexArrayObjectOES:
174 return toV8(args.getWebGLVertexArrayObjectOES(), creationContext, isolat e);
175 default:
176 notImplemented();
177 return v8::Undefined(isolate);
178 }
179 }
180
181 static v8::Handle<v8::Value> toV8Object(WebGLExtension* extension, v8::Handle<v8 ::Object> contextObject, v8::Isolate* isolate)
182 {
183 if (!extension)
184 return v8::Null(isolate);
185 v8::Handle<v8::Value> extensionObject;
186 const char* referenceName = 0;
187 switch (extension->name()) {
188 case ANGLEInstancedArraysName:
189 extensionObject = toV8(static_cast<ANGLEInstancedArrays*>(extension), co ntextObject, isolate);
190 referenceName = "angleInstancedArraysName";
191 break;
192 case EXTBlendMinMaxName:
193 extensionObject = toV8(static_cast<EXTBlendMinMax*>(extension), contextO bject, isolate);
194 referenceName = "extBlendMinMaxName";
195 break;
196 case EXTFragDepthName:
197 extensionObject = toV8(static_cast<EXTFragDepth*>(extension), contextObj ect, isolate);
198 referenceName = "extFragDepthName";
199 break;
200 case EXTShaderTextureLODName:
201 extensionObject = toV8(static_cast<EXTShaderTextureLOD*>(extension), con textObject, isolate);
202 referenceName = "extShaderTextureLODName";
203 break;
204 case EXTTextureFilterAnisotropicName:
205 extensionObject = toV8(static_cast<EXTTextureFilterAnisotropic*>(extensi on), contextObject, isolate);
206 referenceName = "extTextureFilterAnisotropicName";
207 break;
208 case OESElementIndexUintName:
209 extensionObject = toV8(static_cast<OESElementIndexUint*>(extension), con textObject, isolate);
210 referenceName = "oesElementIndexUintName";
211 break;
212 case OESStandardDerivativesName:
213 extensionObject = toV8(static_cast<OESStandardDerivatives*>(extension), contextObject, isolate);
214 referenceName = "oesStandardDerivativesName";
215 break;
216 case OESTextureFloatName:
217 extensionObject = toV8(static_cast<OESTextureFloat*>(extension), context Object, isolate);
218 referenceName = "oesTextureFloatName";
219 break;
220 case OESTextureFloatLinearName:
221 extensionObject = toV8(static_cast<OESTextureFloatLinear*>(extension), c ontextObject, isolate);
222 referenceName = "oesTextureFloatLinearName";
223 break;
224 case OESTextureHalfFloatName:
225 extensionObject = toV8(static_cast<OESTextureHalfFloat*>(extension), con textObject, isolate);
226 referenceName = "oesTextureHalfFloatName";
227 break;
228 case OESTextureHalfFloatLinearName:
229 extensionObject = toV8(static_cast<OESTextureHalfFloatLinear*>(extension ), contextObject, isolate);
230 referenceName = "oesTextureHalfFloatLinearName";
231 break;
232 case OESVertexArrayObjectName:
233 extensionObject = toV8(static_cast<OESVertexArrayObject*>(extension), co ntextObject, isolate);
234 referenceName = "oesVertexArrayObjectName";
235 break;
236 case WebGLCompressedTextureATCName:
237 extensionObject = toV8(static_cast<WebGLCompressedTextureATC*>(extension ), contextObject, isolate);
238 referenceName = "webGLCompressedTextureATCName";
239 break;
240 case WebGLCompressedTextureETC1Name:
241 extensionObject = toV8(static_cast<WebGLCompressedTextureETC1*>(extensio n), contextObject, isolate);
242 referenceName = "webGLCompressedTextureETC1Name";
243 break;
244 case WebGLCompressedTexturePVRTCName:
245 extensionObject = toV8(static_cast<WebGLCompressedTexturePVRTC*>(extensi on), contextObject, isolate);
246 referenceName = "webGLCompressedTexturePVRTCName";
247 break;
248 case WebGLCompressedTextureS3TCName:
249 extensionObject = toV8(static_cast<WebGLCompressedTextureS3TC*>(extensio n), contextObject, isolate);
250 referenceName = "webGLCompressedTextureS3TCName";
251 break;
252 case WebGLDebugRendererInfoName:
253 extensionObject = toV8(static_cast<WebGLDebugRendererInfo*>(extension), contextObject, isolate);
254 referenceName = "webGLDebugRendererInfoName";
255 break;
256 case WebGLDebugShadersName:
257 extensionObject = toV8(static_cast<WebGLDebugShaders*>(extension), conte xtObject, isolate);
258 referenceName = "webGLDebugShadersName";
259 break;
260 case WebGLDepthTextureName:
261 extensionObject = toV8(static_cast<WebGLDepthTexture*>(extension), conte xtObject, isolate);
262 referenceName = "webGLDepthTextureName";
263 break;
264 case WebGLDrawBuffersName:
265 extensionObject = toV8(static_cast<WebGLDrawBuffers*>(extension), contex tObject, isolate);
266 referenceName = "webGLDrawBuffersName";
267 break;
268 case WebGLLoseContextName:
269 extensionObject = toV8(static_cast<WebGLLoseContext*>(extension), contex tObject, isolate);
270 referenceName = "webGLLoseContextName";
271 break;
272 case WebGLExtensionNameCount:
273 notImplemented();
274 return v8::Undefined(isolate);
275 }
276 ASSERT(!extensionObject.IsEmpty());
277 V8HiddenValue::setHiddenValue(isolate, contextObject, v8AtomicString(isolate , referenceName), extensionObject);
278 return extensionObject;
279 }
280
281 enum ObjectType {
282 kBuffer, kRenderbuffer, kTexture, kVertexAttrib
283 };
284
285 static void getObjectParameter(const v8::FunctionCallbackInfo<v8::Value>& info, ObjectType objectType, ExceptionState& exceptionState)
286 {
287 if (info.Length() != 2) {
288 exceptionState.throwTypeError(ExceptionMessages::notEnoughArguments(2, i nfo.Length()));
289 exceptionState.throwIfNeeded();
290 return;
291 }
292
293 WebGLRenderingContext* context = V8WebGLRenderingContext::toNative(info.Hold er());
294 unsigned target;
295 unsigned pname;
296 {
297 v8::TryCatch block;
298 V8RethrowTryCatchScope rethrow(block);
299 TONATIVE_VOID_EXCEPTIONSTATE_INTERNAL(target, toUInt32(info[0], exceptio nState), exceptionState);
300 TONATIVE_VOID_EXCEPTIONSTATE_INTERNAL(pname, toUInt32(info[1], exception State), exceptionState);
301 }
302 WebGLGetInfo args;
303 switch (objectType) {
304 case kBuffer:
305 args = context->getBufferParameter(target, pname);
306 break;
307 case kRenderbuffer:
308 args = context->getRenderbufferParameter(target, pname);
309 break;
310 case kTexture:
311 args = context->getTexParameter(target, pname);
312 break;
313 case kVertexAttrib:
314 // target => index
315 args = context->getVertexAttrib(target, pname);
316 break;
317 default:
318 notImplemented();
319 break;
320 }
321 v8SetReturnValue(info, toV8Object(args, info.Holder(), info.GetIsolate()));
322 }
323
324 static WebGLUniformLocation* toWebGLUniformLocation(v8::Handle<v8::Value> value, v8::Isolate* isolate)
325 {
326 return V8WebGLUniformLocation::toNativeWithTypeCheck(isolate, value);
327 }
328
329 void V8WebGLRenderingContext::getBufferParameterMethodCustom(const v8::FunctionC allbackInfo<v8::Value>& info)
330 {
331 ExceptionState exceptionState(ExceptionState::ExecutionContext, "getBufferPa rameter", "WebGLRenderingContext", info.Holder(), info.GetIsolate());
332 getObjectParameter(info, kBuffer, exceptionState);
333 }
334
335 void V8WebGLRenderingContext::getExtensionMethodCustom(const v8::FunctionCallbac kInfo<v8::Value>& info)
336 {
337 ExceptionState exceptionState(ExceptionState::ExecutionContext, "getExtensio n", "WebGLRenderingContext", info.Holder(), info.GetIsolate());
338 WebGLRenderingContext* impl = V8WebGLRenderingContext::toNative(info.Holder( ));
339 if (info.Length() < 1) {
340 exceptionState.throwTypeError(ExceptionMessages::notEnoughArguments(1, i nfo.Length()));
341 exceptionState.throwIfNeeded();
342 return;
343 }
344 TOSTRING_VOID(V8StringResource<>, name, info[0]);
345 RefPtr<WebGLExtension> extension(impl->getExtension(name));
346 v8SetReturnValue(info, toV8Object(extension.get(), info.Holder(), info.GetIs olate()));
347 }
348
349 void V8WebGLRenderingContext::getFramebufferAttachmentParameterMethodCustom(cons t v8::FunctionCallbackInfo<v8::Value>& info)
350 {
351 ExceptionState exceptionState(ExceptionState::ExecutionContext, "getFramebuf ferAttachmentParameter", "WebGLRenderingContext", info.Holder(), info.GetIsolate ());
352 if (info.Length() != 3) {
353 exceptionState.throwTypeError(ExceptionMessages::notEnoughArguments(3, i nfo.Length()));
354 exceptionState.throwIfNeeded();
355 return;
356 }
357
358 WebGLRenderingContext* context = V8WebGLRenderingContext::toNative(info.Hold er());
359 unsigned target;
360 unsigned attachment;
361 unsigned pname;
362 {
363 v8::TryCatch block;
364 V8RethrowTryCatchScope rethrow(block);
365 TONATIVE_VOID_EXCEPTIONSTATE_INTERNAL(target, toUInt32(info[0], exceptio nState), exceptionState);
366 TONATIVE_VOID_EXCEPTIONSTATE_INTERNAL(attachment, toUInt32(info[1], exce ptionState), exceptionState);
367 TONATIVE_VOID_EXCEPTIONSTATE_INTERNAL(pname, toUInt32(info[2], exception State), exceptionState);
368 }
369 WebGLGetInfo args = context->getFramebufferAttachmentParameter(target, attac hment, pname);
370 v8SetReturnValue(info, toV8Object(args, info.Holder(), info.GetIsolate()));
371 }
372
373 void V8WebGLRenderingContext::getParameterMethodCustom(const v8::FunctionCallbac kInfo<v8::Value>& info)
374 {
375 ExceptionState exceptionState(ExceptionState::ExecutionContext, "getParamete r", "WebGLRenderingContext", info.Holder(), info.GetIsolate());
376 if (info.Length() != 1) {
377 exceptionState.throwTypeError(ExceptionMessages::notEnoughArguments(1, i nfo.Length()));
378 exceptionState.throwIfNeeded();
379 return;
380 }
381
382 WebGLRenderingContext* context = V8WebGLRenderingContext::toNative(info.Hold er());
383 unsigned pname;
384 {
385 v8::TryCatch block;
386 V8RethrowTryCatchScope rethrow(block);
387 TONATIVE_VOID_EXCEPTIONSTATE_INTERNAL(pname, toUInt32(info[0], exception State), exceptionState);
388 }
389 WebGLGetInfo args = context->getParameter(pname);
390 v8SetReturnValue(info, toV8Object(args, info.Holder(), info.GetIsolate()));
391 }
392
393 void V8WebGLRenderingContext::getProgramParameterMethodCustom(const v8::Function CallbackInfo<v8::Value>& info)
394 {
395 ExceptionState exceptionState(ExceptionState::ExecutionContext, "getProgramP arameter", "WebGLRenderingContext", info.Holder(), info.GetIsolate());
396 if (info.Length() != 2) {
397 exceptionState.throwTypeError(ExceptionMessages::notEnoughArguments(2, i nfo.Length()));
398 exceptionState.throwIfNeeded();
399 return;
400 }
401
402 WebGLRenderingContext* context = V8WebGLRenderingContext::toNative(info.Hold er());
403 WebGLProgram* program;
404 unsigned pname;
405 {
406 v8::TryCatch block;
407 V8RethrowTryCatchScope rethrow(block);
408 if (info.Length() > 0 && !isUndefinedOrNull(info[0]) && !V8WebGLProgram: :hasInstance(info[0], info.GetIsolate())) {
409 exceptionState.throwTypeError("parameter 1 is not of type 'WebGLProg ram'.");
410 exceptionState.throwIfNeeded();
411 return;
412 }
413 TONATIVE_VOID_INTERNAL(program, V8WebGLProgram::toNativeWithTypeCheck(in fo.GetIsolate(), info[0]));
414 TONATIVE_VOID_EXCEPTIONSTATE_INTERNAL(pname, toUInt32(info[1], exception State), exceptionState);
415 }
416 WebGLGetInfo args = context->getProgramParameter(program, pname);
417 v8SetReturnValue(info, toV8Object(args, info.Holder(), info.GetIsolate()));
418 }
419
420 void V8WebGLRenderingContext::getRenderbufferParameterMethodCustom(const v8::Fun ctionCallbackInfo<v8::Value>& info)
421 {
422 ExceptionState exceptionState(ExceptionState::ExecutionContext, "getRenderbu fferParameter", "WebGLRenderingContext", info.Holder(), info.GetIsolate());
423 getObjectParameter(info, kRenderbuffer, exceptionState);
424 }
425
426 void V8WebGLRenderingContext::getShaderParameterMethodCustom(const v8::FunctionC allbackInfo<v8::Value>& info)
427 {
428 ExceptionState exceptionState(ExceptionState::ExecutionContext, "getShaderPa rameter", "WebGLRenderingContext", info.Holder(), info.GetIsolate());
429 if (info.Length() != 2) {
430 exceptionState.throwTypeError(ExceptionMessages::notEnoughArguments(2, i nfo.Length()));
431 exceptionState.throwIfNeeded();
432 return;
433 }
434
435 WebGLRenderingContext* context = V8WebGLRenderingContext::toNative(info.Hold er());
436 WebGLShader* shader;
437 unsigned pname;
438 {
439 v8::TryCatch block;
440 V8RethrowTryCatchScope rethrow(block);
441 if (info.Length() > 0 && !isUndefinedOrNull(info[0]) && !V8WebGLShader:: hasInstance(info[0], info.GetIsolate())) {
442 exceptionState.throwTypeError("parameter 1 is not of type 'WebGLShad er'.");
443 exceptionState.throwIfNeeded();
444 return;
445 }
446 TONATIVE_VOID_INTERNAL(shader, V8WebGLShader::toNativeWithTypeCheck(info .GetIsolate(), info[0]));
447 TONATIVE_VOID_EXCEPTIONSTATE_INTERNAL(pname, toUInt32(info[1], exception State), exceptionState);
448 }
449 WebGLGetInfo args = context->getShaderParameter(shader, pname);
450 v8SetReturnValue(info, toV8Object(args, info.Holder(), info.GetIsolate()));
451 }
452
453 void V8WebGLRenderingContext::getTexParameterMethodCustom(const v8::FunctionCall backInfo<v8::Value>& info)
454 {
455 ExceptionState exceptionState(ExceptionState::ExecutionContext, "getTexParam eter", "WebGLRenderingContext", info.Holder(), info.GetIsolate());
456 getObjectParameter(info, kTexture, exceptionState);
457 }
458
459 void V8WebGLRenderingContext::getUniformMethodCustom(const v8::FunctionCallbackI nfo<v8::Value>& info)
460 {
461 ExceptionState exceptionState(ExceptionState::ExecutionContext, "getUniform" , "WebGLRenderingContext", info.Holder(), info.GetIsolate());
462 if (info.Length() != 2) {
463 exceptionState.throwTypeError(ExceptionMessages::notEnoughArguments(2, i nfo.Length()));
464 exceptionState.throwIfNeeded();
465 return;
466 }
467
468 WebGLRenderingContext* context = V8WebGLRenderingContext::toNative(info.Hold er());
469 WebGLProgram* program;
470 WebGLUniformLocation* location;
471 {
472 v8::TryCatch block;
473 V8RethrowTryCatchScope rethrow(block);
474 if (info.Length() > 0 && !isUndefinedOrNull(info[0]) && !V8WebGLProgram: :hasInstance(info[0], info.GetIsolate())) {
475 V8ThrowException::throwTypeError(ExceptionMessages::failedToExecute( "getUniform", "WebGLRenderingContext", "parameter 1 is not of type 'WebGLProgram '."), info.GetIsolate());
476 return;
477 }
478 TONATIVE_VOID_INTERNAL(program, V8WebGLProgram::toNativeWithTypeCheck(in fo.GetIsolate(), info[0]));
479 if (info.Length() > 1 && !isUndefinedOrNull(info[1]) && !V8WebGLUniformL ocation::hasInstance(info[1], info.GetIsolate())) {
480 V8ThrowException::throwTypeError(ExceptionMessages::failedToExecute( "getUniform", "WebGLRenderingContext", "parameter 2 is not of type 'WebGLUniform Location'."), info.GetIsolate());
481 return;
482 }
483 TONATIVE_VOID_INTERNAL(location, V8WebGLUniformLocation::toNativeWithTyp eCheck(info.GetIsolate(), info[1]));
484 }
485 WebGLGetInfo args = context->getUniform(program, location);
486 v8SetReturnValue(info, toV8Object(args, info.Holder(), info.GetIsolate()));
487 }
488
489 void V8WebGLRenderingContext::getVertexAttribMethodCustom(const v8::FunctionCall backInfo<v8::Value>& info)
490 {
491 ExceptionState exceptionState(ExceptionState::ExecutionContext, "getVertexAt trib", "WebGLRenderingContext", info.Holder(), info.GetIsolate());
492 getObjectParameter(info, kVertexAttrib, exceptionState);
493 }
494
495 enum FunctionToCall {
496 kUniform1v, kUniform2v, kUniform3v, kUniform4v,
497 kVertexAttrib1v, kVertexAttrib2v, kVertexAttrib3v, kVertexAttrib4v
498 };
499
500 bool isFunctionToCallForAttribute(FunctionToCall functionToCall)
501 {
502 switch (functionToCall) {
503 case kVertexAttrib1v:
504 case kVertexAttrib2v:
505 case kVertexAttrib3v:
506 case kVertexAttrib4v:
507 return true;
508 default:
509 break;
510 }
511 return false;
512 }
513
514 static void vertexAttribAndUniformHelperf(const v8::FunctionCallbackInfo<v8::Val ue>& info, FunctionToCall functionToCall, ExceptionState& exceptionState)
515 {
516 // Forms:
517 // * glUniform1fv(WebGLUniformLocation location, Array data);
518 // * glUniform1fv(WebGLUniformLocation location, Float32Array data);
519 // * glUniform2fv(WebGLUniformLocation location, Array data);
520 // * glUniform2fv(WebGLUniformLocation location, Float32Array data);
521 // * glUniform3fv(WebGLUniformLocation location, Array data);
522 // * glUniform3fv(WebGLUniformLocation location, Float32Array data);
523 // * glUniform4fv(WebGLUniformLocation location, Array data);
524 // * glUniform4fv(WebGLUniformLocation location, Float32Array data);
525 // * glVertexAttrib1fv(GLint index, Array data);
526 // * glVertexAttrib1fv(GLint index, Float32Array data);
527 // * glVertexAttrib2fv(GLint index, Array data);
528 // * glVertexAttrib2fv(GLint index, Float32Array data);
529 // * glVertexAttrib3fv(GLint index, Array data);
530 // * glVertexAttrib3fv(GLint index, Float32Array data);
531 // * glVertexAttrib4fv(GLint index, Array data);
532 // * glVertexAttrib4fv(GLint index, Float32Array data);
533
534 if (info.Length() != 2) {
535 exceptionState.throwTypeError(ExceptionMessages::notEnoughArguments(2, i nfo.Length()));
536 exceptionState.throwIfNeeded();
537 return;
538 }
539
540 int index = -1;
541 WebGLUniformLocation* location = 0;
542
543 if (isFunctionToCallForAttribute(functionToCall)) {
544 index = toInt32(info[0], exceptionState);
545 if (exceptionState.throwIfNeeded())
546 return;
547 } else {
548 const int uniformLocationArgumentIndex = 0;
549 if (info.Length() > 0 && !isUndefinedOrNull(info[uniformLocationArgument Index]) && !V8WebGLUniformLocation::hasInstance(info[uniformLocationArgumentInde x], info.GetIsolate())) {
550 exceptionState.throwTypeError(ExceptionMessages::argumentNullOrIncor rectType(uniformLocationArgumentIndex + 1, "WebGLUniformLocation"));
551 exceptionState.throwIfNeeded();
552 return;
553 }
554 location = toWebGLUniformLocation(info[uniformLocationArgumentIndex], in fo.GetIsolate());
555 }
556
557 WebGLRenderingContext* context = V8WebGLRenderingContext::toNative(info.Hold er());
558
559 const int indexArrayArgument = 1;
560 if (V8Float32Array::hasInstance(info[indexArrayArgument], info.GetIsolate()) ) {
561 Float32Array* array = V8Float32Array::toNative(info[indexArrayArgument]- >ToObject());
562 ASSERT(array);
563 switch (functionToCall) {
564 case kUniform1v: context->uniform1fv(location, array); break;
565 case kUniform2v: context->uniform2fv(location, array); break;
566 case kUniform3v: context->uniform3fv(location, array); break;
567 case kUniform4v: context->uniform4fv(location, array); break;
568 case kVertexAttrib1v: context->vertexAttrib1fv(index, array); break;
569 case kVertexAttrib2v: context->vertexAttrib2fv(index, array); break;
570 case kVertexAttrib3v: context->vertexAttrib3fv(index, array); break;
571 case kVertexAttrib4v: context->vertexAttrib4fv(index, array); break;
572 default: ASSERT_NOT_REACHED(); break;
573 }
574 return;
575 }
576
577 if (info[indexArrayArgument].IsEmpty() || !info[indexArrayArgument]->IsArray ()) {
578 exceptionState.throwTypeError(ExceptionMessages::argumentNullOrIncorrect Type(indexArrayArgument + 1, "Array"));
579 exceptionState.throwIfNeeded();
580 return;
581 }
582 v8::Handle<v8::Array> array = v8::Local<v8::Array>::Cast(info[1]);
583 uint32_t len = array->Length();
584 float* data = jsArrayToFloatArray(array, len, exceptionState);
585 if (exceptionState.throwIfNeeded())
586 return;
587 if (!data) {
588 // FIXME: consider different / better exception type.
589 exceptionState.throwDOMException(SyntaxError, "Failed to convert array a rgument");
590 exceptionState.throwIfNeeded();
591 return;
592 }
593 switch (functionToCall) {
594 case kUniform1v: context->uniform1fv(location, data, len); break;
595 case kUniform2v: context->uniform2fv(location, data, len); break;
596 case kUniform3v: context->uniform3fv(location, data, len); break;
597 case kUniform4v: context->uniform4fv(location, data, len); break;
598 case kVertexAttrib1v: context->vertexAttrib1fv(index, data, len); break;
599 case kVertexAttrib2v: context->vertexAttrib2fv(index, data, len); break;
600 case kVertexAttrib3v: context->vertexAttrib3fv(index, data, len); break;
601 case kVertexAttrib4v: context->vertexAttrib4fv(index, data, len); break;
602 default: ASSERT_NOT_REACHED(); break;
603 }
604 fastFree(data);
605 }
606
607 static void uniformHelperi(const v8::FunctionCallbackInfo<v8::Value>& info, Func tionToCall functionToCall, ExceptionState& exceptionState)
608 {
609 // Forms:
610 // * glUniform1iv(GLUniformLocation location, Array data);
611 // * glUniform1iv(GLUniformLocation location, Int32Array data);
612 // * glUniform2iv(GLUniformLocation location, Array data);
613 // * glUniform2iv(GLUniformLocation location, Int32Array data);
614 // * glUniform3iv(GLUniformLocation location, Array data);
615 // * glUniform3iv(GLUniformLocation location, Int32Array data);
616 // * glUniform4iv(GLUniformLocation location, Array data);
617 // * glUniform4iv(GLUniformLocation location, Int32Array data);
618
619 if (info.Length() != 2) {
620 exceptionState.throwTypeError(ExceptionMessages::notEnoughArguments(2, i nfo.Length()));
621 exceptionState.throwIfNeeded();
622 return;
623 }
624
625 const int uniformLocationArgumentIndex = 0;
626 WebGLRenderingContext* context = V8WebGLRenderingContext::toNative(info.Hold er());
627 if (info.Length() > 0 && !isUndefinedOrNull(info[uniformLocationArgumentInde x]) && !V8WebGLUniformLocation::hasInstance(info[uniformLocationArgumentIndex], info.GetIsolate())) {
628 exceptionState.throwTypeError(ExceptionMessages::argumentNullOrIncorrect Type(uniformLocationArgumentIndex + 1, "WebGLUniformLocation"));
629 exceptionState.throwIfNeeded();
630 return;
631 }
632 WebGLUniformLocation* location = toWebGLUniformLocation(info[uniformLocation ArgumentIndex], info.GetIsolate());
633
634 const int indexArrayArgumentIndex = 1;
635 if (V8Int32Array::hasInstance(info[indexArrayArgumentIndex], info.GetIsolate ())) {
636 Int32Array* array = V8Int32Array::toNative(info[indexArrayArgumentIndex] ->ToObject());
637 ASSERT(array);
638 switch (functionToCall) {
639 case kUniform1v: context->uniform1iv(location, array); break;
640 case kUniform2v: context->uniform2iv(location, array); break;
641 case kUniform3v: context->uniform3iv(location, array); break;
642 case kUniform4v: context->uniform4iv(location, array); break;
643 default: ASSERT_NOT_REACHED(); break;
644 }
645 return;
646 }
647
648 if (info[indexArrayArgumentIndex].IsEmpty() || !info[indexArrayArgumentIndex ]->IsArray()) {
649 exceptionState.throwTypeError(ExceptionMessages::argumentNullOrIncorrect Type(indexArrayArgumentIndex + 1, "Array"));
650 exceptionState.throwIfNeeded();
651 return;
652 }
653 v8::Handle<v8::Array> array = v8::Local<v8::Array>::Cast(info[indexArrayArgu mentIndex]);
654 uint32_t len = array->Length();
655 int* data = jsArrayToIntArray(array, len, exceptionState);
656 if (exceptionState.throwIfNeeded())
657 return;
658 if (!data) {
659 // FIXME: consider different / better exception type.
660 exceptionState.throwDOMException(SyntaxError, "Failed to convert array a rgument");
661 exceptionState.throwIfNeeded();
662 return;
663 }
664 switch (functionToCall) {
665 case kUniform1v: context->uniform1iv(location, data, len); break;
666 case kUniform2v: context->uniform2iv(location, data, len); break;
667 case kUniform3v: context->uniform3iv(location, data, len); break;
668 case kUniform4v: context->uniform4iv(location, data, len); break;
669 default: ASSERT_NOT_REACHED(); break;
670 }
671 fastFree(data);
672 }
673
674 void V8WebGLRenderingContext::uniform1fvMethodCustom(const v8::FunctionCallbackI nfo<v8::Value>& info)
675 {
676 ExceptionState exceptionState(ExceptionState::ExecutionContext, "uniform1fv" , "WebGLRenderingContext", info.Holder(), info.GetIsolate());
677 vertexAttribAndUniformHelperf(info, kUniform1v, exceptionState);
678 }
679
680 void V8WebGLRenderingContext::uniform1ivMethodCustom(const v8::FunctionCallbackI nfo<v8::Value>& info)
681 {
682 ExceptionState exceptionState(ExceptionState::ExecutionContext, "uniform1iv" , "WebGLRenderingContext", info.Holder(), info.GetIsolate());
683 uniformHelperi(info, kUniform1v, exceptionState);
684 }
685
686 void V8WebGLRenderingContext::uniform2fvMethodCustom(const v8::FunctionCallbackI nfo<v8::Value>& info)
687 {
688 ExceptionState exceptionState(ExceptionState::ExecutionContext, "uniform2fv" , "WebGLRenderingContext", info.Holder(), info.GetIsolate());
689 vertexAttribAndUniformHelperf(info, kUniform2v, exceptionState);
690 }
691
692 void V8WebGLRenderingContext::uniform2ivMethodCustom(const v8::FunctionCallbackI nfo<v8::Value>& info)
693 {
694 ExceptionState exceptionState(ExceptionState::ExecutionContext, "uniform2iv" , "WebGLRenderingContext", info.Holder(), info.GetIsolate());
695 uniformHelperi(info, kUniform2v, exceptionState);
696 }
697
698 void V8WebGLRenderingContext::uniform3fvMethodCustom(const v8::FunctionCallbackI nfo<v8::Value>& info)
699 {
700 ExceptionState exceptionState(ExceptionState::ExecutionContext, "uniform3fv" , "WebGLRenderingContext", info.Holder(), info.GetIsolate());
701 vertexAttribAndUniformHelperf(info, kUniform3v, exceptionState);
702 }
703
704 void V8WebGLRenderingContext::uniform3ivMethodCustom(const v8::FunctionCallbackI nfo<v8::Value>& info)
705 {
706 ExceptionState exceptionState(ExceptionState::ExecutionContext, "uniform3iv" , "WebGLRenderingContext", info.Holder(), info.GetIsolate());
707 uniformHelperi(info, kUniform3v, exceptionState);
708 }
709
710 void V8WebGLRenderingContext::uniform4fvMethodCustom(const v8::FunctionCallbackI nfo<v8::Value>& info)
711 {
712 ExceptionState exceptionState(ExceptionState::ExecutionContext, "uniform4fv" , "WebGLRenderingContext", info.Holder(), info.GetIsolate());
713 vertexAttribAndUniformHelperf(info, kUniform4v, exceptionState);
714 }
715
716 void V8WebGLRenderingContext::uniform4ivMethodCustom(const v8::FunctionCallbackI nfo<v8::Value>& info)
717 {
718 ExceptionState exceptionState(ExceptionState::ExecutionContext, "uniform4iv" , "WebGLRenderingContext", info.Holder(), info.GetIsolate());
719 uniformHelperi(info, kUniform4v, exceptionState);
720 }
721
722 static void uniformMatrixHelper(const v8::FunctionCallbackInfo<v8::Value>& info, int matrixSize, ExceptionState& exceptionState)
723 {
724 // Forms:
725 // * glUniformMatrix2fv(GLint location, GLboolean transpose, Array data);
726 // * glUniformMatrix2fv(GLint location, GLboolean transpose, Float32Array da ta);
727 // * glUniformMatrix3fv(GLint location, GLboolean transpose, Array data);
728 // * glUniformMatrix3fv(GLint location, GLboolean transpose, Float32Array da ta);
729 // * glUniformMatrix4fv(GLint location, GLboolean transpose, Array data);
730 // * glUniformMatrix4fv(GLint location, GLboolean transpose, Float32Array da ta);
731 //
732 // FIXME: need to change to accept Float32Array as well.
733 if (info.Length() != 3) {
734 exceptionState.throwTypeError(ExceptionMessages::notEnoughArguments(3, i nfo.Length()));
735 exceptionState.throwIfNeeded();
736 return;
737 }
738
739 WebGLRenderingContext* context = V8WebGLRenderingContext::toNative(info.Hold er());
740
741 const int uniformLocationArgumentIndex = 0;
742 if (info.Length() > 0 && !isUndefinedOrNull(info[uniformLocationArgumentInde x]) && !V8WebGLUniformLocation::hasInstance(info[uniformLocationArgumentIndex], info.GetIsolate())) {
743 exceptionState.throwTypeError(ExceptionMessages::argumentNullOrIncorrect Type(uniformLocationArgumentIndex + 1, "WebGLUniformLocation"));
744 exceptionState.throwIfNeeded();
745 return;
746 }
747 WebGLUniformLocation* location = toWebGLUniformLocation(info[uniformLocation ArgumentIndex], info.GetIsolate());
748
749 bool transpose = info[1]->BooleanValue();
750 const int arrayArgumentIndex = 2;
751 if (V8Float32Array::hasInstance(info[arrayArgumentIndex], info.GetIsolate()) ) {
752 Float32Array* array = V8Float32Array::toNative(info[arrayArgumentIndex]- >ToObject());
753 ASSERT(array);
754 switch (matrixSize) {
755 case 2: context->uniformMatrix2fv(location, transpose, array); break;
756 case 3: context->uniformMatrix3fv(location, transpose, array); break;
757 case 4: context->uniformMatrix4fv(location, transpose, array); break;
758 default: ASSERT_NOT_REACHED(); break;
759 }
760 return;
761 }
762
763 if (info[arrayArgumentIndex].IsEmpty() || !info[arrayArgumentIndex]->IsArray ()) {
764 exceptionState.throwTypeError(ExceptionMessages::argumentNullOrIncorrect Type(arrayArgumentIndex + 1, "Array"));
765 exceptionState.throwIfNeeded();
766 return;
767 }
768 v8::Handle<v8::Array> array = v8::Local<v8::Array>::Cast(info[2]);
769 uint32_t len = array->Length();
770 float* data = jsArrayToFloatArray(array, len, exceptionState);
771 if (exceptionState.throwIfNeeded())
772 return;
773 if (!data) {
774 // FIXME: consider different / better exception type.
775 exceptionState.throwDOMException(SyntaxError, "failed to convert Array v alue");
776 exceptionState.throwIfNeeded();
777 return;
778 }
779 switch (matrixSize) {
780 case 2: context->uniformMatrix2fv(location, transpose, data, len); break;
781 case 3: context->uniformMatrix3fv(location, transpose, data, len); break;
782 case 4: context->uniformMatrix4fv(location, transpose, data, len); break;
783 default: ASSERT_NOT_REACHED(); break;
784 }
785 fastFree(data);
786 }
787
788 void V8WebGLRenderingContext::uniformMatrix2fvMethodCustom(const v8::FunctionCal lbackInfo<v8::Value>& info)
789 {
790 ExceptionState exceptionState(ExceptionState::ExecutionContext, "uniformMatr ix2fv", "WebGLRenderingContext", info.Holder(), info.GetIsolate());
791 uniformMatrixHelper(info, 2, exceptionState);
792 }
793
794 void V8WebGLRenderingContext::uniformMatrix3fvMethodCustom(const v8::FunctionCal lbackInfo<v8::Value>& info)
795 {
796 ExceptionState exceptionState(ExceptionState::ExecutionContext, "uniformMatr ix3fv", "WebGLRenderingContext", info.Holder(), info.GetIsolate());
797 uniformMatrixHelper(info, 3, exceptionState);
798 }
799
800 void V8WebGLRenderingContext::uniformMatrix4fvMethodCustom(const v8::FunctionCal lbackInfo<v8::Value>& info)
801 {
802 ExceptionState exceptionState(ExceptionState::ExecutionContext, "uniformMatr ix4fv", "WebGLRenderingContext", info.Holder(), info.GetIsolate());
803 uniformMatrixHelper(info, 4, exceptionState);
804 }
805
806 void V8WebGLRenderingContext::vertexAttrib1fvMethodCustom(const v8::FunctionCall backInfo<v8::Value>& info)
807 {
808 ExceptionState exceptionState(ExceptionState::ExecutionContext, "vertexAttri b1fv", "WebGLRenderingContext", info.Holder(), info.GetIsolate());
809 vertexAttribAndUniformHelperf(info, kVertexAttrib1v, exceptionState);
810 }
811
812 void V8WebGLRenderingContext::vertexAttrib2fvMethodCustom(const v8::FunctionCall backInfo<v8::Value>& info)
813 {
814 ExceptionState exceptionState(ExceptionState::ExecutionContext, "vertexAttri b2fv", "WebGLRenderingContext", info.Holder(), info.GetIsolate());
815 vertexAttribAndUniformHelperf(info, kVertexAttrib2v, exceptionState);
816 }
817
818 void V8WebGLRenderingContext::vertexAttrib3fvMethodCustom(const v8::FunctionCall backInfo<v8::Value>& info)
819 {
820 ExceptionState exceptionState(ExceptionState::ExecutionContext, "vertexAttri b3fv", "WebGLRenderingContext", info.Holder(), info.GetIsolate());
821 vertexAttribAndUniformHelperf(info, kVertexAttrib3v, exceptionState);
822 }
823
824 void V8WebGLRenderingContext::vertexAttrib4fvMethodCustom(const v8::FunctionCall backInfo<v8::Value>& info)
825 {
826 ExceptionState exceptionState(ExceptionState::ExecutionContext, "vertexAttri b4fv", "WebGLRenderingContext", info.Holder(), info.GetIsolate());
827 vertexAttribAndUniformHelperf(info, kVertexAttrib4v, exceptionState);
828 }
829
830 } // namespace blink
OLDNEW
« no previous file with comments | « sky/engine/bindings/core/v8/custom/V8Uint8ClampedArrayCustom.h ('k') | sky/engine/bindings/core/v8/custom/V8WindowCustom.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698