diff options
Diffstat (limited to 'WebCore/bindings/js/JSWebGLRenderingContextCustom.cpp')
-rw-r--r-- | WebCore/bindings/js/JSWebGLRenderingContextCustom.cpp | 272 |
1 files changed, 16 insertions, 256 deletions
diff --git a/WebCore/bindings/js/JSWebGLRenderingContextCustom.cpp b/WebCore/bindings/js/JSWebGLRenderingContextCustom.cpp index 02dae08..eb4f549 100644 --- a/WebCore/bindings/js/JSWebGLRenderingContextCustom.cpp +++ b/WebCore/bindings/js/JSWebGLRenderingContextCustom.cpp @@ -36,7 +36,7 @@ #include "JSHTMLImageElement.h" #include "JSImageData.h" #include "JSWebGLBuffer.h" -#include "JSFloatArray.h" +#include "JSFloat32Array.h" #include "JSWebGLFramebuffer.h" #include "JSInt32Array.h" #include "JSWebGLProgram.h" @@ -48,7 +48,7 @@ #include "JSWebKitCSSMatrix.h" #include "NotImplemented.h" #include "WebGLBuffer.h" -#include "FloatArray.h" +#include "Float32Array.h" #include "WebGLFramebuffer.h" #include "WebGLGetInfo.h" #include "Int32Array.h" @@ -67,45 +67,6 @@ using namespace JSC; namespace WebCore { -JSValue JSWebGLRenderingContext::bufferData(JSC::ExecState* exec) -{ - if (exec->argumentCount() != 3) - return throwError(exec, SyntaxError); - - unsigned target = exec->argument(0).toInt32(exec); - unsigned usage = exec->argument(2).toInt32(exec); - ExceptionCode ec = 0; - - // If argument 1 is a number, we are initializing this buffer to that size - if (!exec->argument(1).isObject()) { - unsigned int count = exec->argument(1).toInt32(exec); - static_cast<WebGLRenderingContext*>(impl())->bufferData(target, count, usage, ec); - } else { - ArrayBufferView* array = toArrayBufferView(exec->argument(1)); - static_cast<WebGLRenderingContext*>(impl())->bufferData(target, array, usage, ec); - } - - setDOMException(exec, ec); - return jsUndefined(); -} - -JSValue JSWebGLRenderingContext::bufferSubData(JSC::ExecState* exec) -{ - if (exec->argumentCount() != 3) - return throwError(exec, SyntaxError); - - unsigned target = exec->argument(0).toInt32(exec); - unsigned offset = exec->argument(1).toInt32(exec); - ExceptionCode ec = 0; - - ArrayBufferView* array = toArrayBufferView(exec->argument(2)); - - static_cast<WebGLRenderingContext*>(impl())->bufferSubData(target, offset, array, ec); - - setDOMException(exec, ec); - return jsUndefined(); -} - static JSValue toJS(ExecState* exec, JSDOMGlobalObject* globalObject, const WebGLGetInfo& info) { switch (info.getType()) { @@ -152,7 +113,7 @@ enum ObjectType { static JSValue getObjectParameter(JSWebGLRenderingContext* obj, ExecState* exec, ObjectType objectType) { if (exec->argumentCount() != 2) - return throwError(exec, SyntaxError); + return throwSyntaxError(exec); ExceptionCode ec = 0; WebGLRenderingContext* context = static_cast<WebGLRenderingContext*>(obj->impl()); @@ -200,7 +161,7 @@ JSValue JSWebGLRenderingContext::getBufferParameter(ExecState* exec) JSValue JSWebGLRenderingContext::getFramebufferAttachmentParameter(ExecState* exec) { if (exec->argumentCount() != 3) - return throwError(exec, SyntaxError); + return throwSyntaxError(exec); ExceptionCode ec = 0; WebGLRenderingContext* context = static_cast<WebGLRenderingContext*>(impl()); @@ -224,7 +185,7 @@ JSValue JSWebGLRenderingContext::getFramebufferAttachmentParameter(ExecState* ex JSValue JSWebGLRenderingContext::getParameter(ExecState* exec) { if (exec->argumentCount() != 1) - return throwError(exec, SyntaxError); + return throwSyntaxError(exec); ExceptionCode ec = 0; WebGLRenderingContext* context = static_cast<WebGLRenderingContext*>(impl()); @@ -242,7 +203,7 @@ JSValue JSWebGLRenderingContext::getParameter(ExecState* exec) JSValue JSWebGLRenderingContext::getProgramParameter(ExecState* exec) { if (exec->argumentCount() != 2) - return throwError(exec, SyntaxError); + return throwSyntaxError(exec); ExceptionCode ec = 0; WebGLRenderingContext* context = static_cast<WebGLRenderingContext*>(impl()); @@ -266,7 +227,7 @@ JSValue JSWebGLRenderingContext::getRenderbufferParameter(ExecState* exec) JSValue JSWebGLRenderingContext::getShaderParameter(ExecState* exec) { if (exec->argumentCount() != 2) - return throwError(exec, SyntaxError); + return throwSyntaxError(exec); ExceptionCode ec = 0; WebGLRenderingContext* context = static_cast<WebGLRenderingContext*>(impl()); @@ -290,7 +251,7 @@ JSValue JSWebGLRenderingContext::getTexParameter(ExecState* exec) JSValue JSWebGLRenderingContext::getUniform(ExecState* exec) { if (exec->argumentCount() != 2) - return throwError(exec, SyntaxError); + return throwSyntaxError(exec); ExceptionCode ec = 0; WebGLRenderingContext* context = static_cast<WebGLRenderingContext*>(impl()); @@ -311,207 +272,6 @@ JSValue JSWebGLRenderingContext::getVertexAttrib(ExecState* exec) return getObjectParameter(this, exec, kVertexAttrib); } -// void texImage2D(in GLenum target, in GLint level, in GLenum internalformat, in GLsizei width, in GLsizei height, in GLint border, in GLenum format, in GLenum type, in ArrayBufferView pixels); -// void texImage2D(in GLenum target, in GLint level, in ImageData pixels, [Optional] GLboolean flipY, [Optional] in premultiplyAlpha); -// void texImage2D(in GLenum target, in GLint level, in HTMLImageElement image, [Optional] in GLboolean flipY, [Optional] in premultiplyAlpha); -// void texImage2D(in GLenum target, in GLint level, in HTMLCanvasElement canvas, [Optional] in GLboolean flipY, [Optional] in premultiplyAlpha); -// void texImage2D(in GLenum target, in GLint level, in HTMLVideoElement video, [Optional] in GLboolean flipY, [Optional] in premultiplyAlpha); -JSValue JSWebGLRenderingContext::texImage2D(ExecState* exec) -{ - if (exec->argumentCount() < 3 || exec->argumentCount() > 9) - return throwError(exec, SyntaxError); - - ExceptionCode ec = 0; - - WebGLRenderingContext* context = static_cast<WebGLRenderingContext*>(impl()); - unsigned target = exec->argument(0).toInt32(exec); - if (exec->hadException()) - return jsUndefined(); - - unsigned level = exec->argument(1).toInt32(exec); - if (exec->hadException()) - return jsUndefined(); - - JSObject* o = 0; - - if (exec->argumentCount() <= 5) { - // This is one of the last 4 forms. Param 2 can be ImageData or <img>, <canvas> or <video> element. - JSValue value = exec->argument(2); - - if (!value.isObject()) - return throwError(exec, TypeError); - - o = asObject(value); - - bool flipY = exec->argument(3).toBoolean(exec); - bool premultiplyAlpha = exec->argument(4).toBoolean(exec); - - if (o->inherits(&JSImageData::s_info)) { - ImageData* data = static_cast<ImageData*>(static_cast<JSImageData*>(o)->impl()); - context->texImage2D(target, level, data, flipY, premultiplyAlpha, ec); - } else if (o->inherits(&JSHTMLImageElement::s_info)) { - HTMLImageElement* element = static_cast<HTMLImageElement*>(static_cast<JSHTMLImageElement*>(o)->impl()); - context->texImage2D(target, level, element, flipY, premultiplyAlpha, ec); - } else if (o->inherits(&JSHTMLCanvasElement::s_info)) { - HTMLCanvasElement* element = static_cast<HTMLCanvasElement*>(static_cast<JSHTMLCanvasElement*>(o)->impl()); - context->texImage2D(target, level, element, flipY, premultiplyAlpha, ec); -#if ENABLE(VIDEO) - } else if (o->inherits(&JSHTMLVideoElement::s_info)) { - HTMLVideoElement* element = static_cast<HTMLVideoElement*>(static_cast<JSHTMLVideoElement*>(o)->impl()); - context->texImage2D(target, level, element, flipY, premultiplyAlpha, ec); -#endif - } else - ec = TYPE_MISMATCH_ERR; - } else { - if (exec->argumentCount() != 9) - return throwError(exec, SyntaxError); - - // This must be the ArrayBufferView case - unsigned internalformat = exec->argument(2).toInt32(exec); - if (exec->hadException()) - return jsUndefined(); - - unsigned width = exec->argument(3).toInt32(exec); - if (exec->hadException()) - return jsUndefined(); - - unsigned height = exec->argument(4).toInt32(exec); - if (exec->hadException()) - return jsUndefined(); - - unsigned border = exec->argument(5).toInt32(exec); - if (exec->hadException()) - return jsUndefined(); - - unsigned format = exec->argument(6).toInt32(exec); - if (exec->hadException()) - return jsUndefined(); - - unsigned type = exec->argument(7).toInt32(exec); - if (exec->hadException()) - return jsUndefined(); - - JSValue value = exec->argument(8); - - // For this case passing 0 (for a null array) is allowed - if (value.isNull()) - context->texImage2D(target, level, internalformat, width, height, border, format, type, 0, ec); - else if (value.isObject()) { - o = asObject(value); - - if (o->inherits(&JSArrayBufferView::s_info)) { - // FIXME: Need to check to make sure ArrayBufferView is a Int8Array or Int16Array, - // depending on the passed type parameter. - ArrayBufferView* obj = static_cast<ArrayBufferView*>(static_cast<JSArrayBufferView*>(o)->impl()); - context->texImage2D(target, level, internalformat, width, height, border, format, type, obj, ec); - } else - return throwError(exec, TypeError); - } else - return throwError(exec, TypeError); - } - - setDOMException(exec, ec); - return jsUndefined(); -} - -// void texSubImage2D(in GLenum target, in GLint level, in GLint xoffset, in GLint yoffset, in GLsizei width, in GLsizei height, in GLenum format, in GLenum type, in ArrayBufferView pixels); -// void texSubImage2D(in GLenum target, in GLint level, in GLint xoffset, in GLint yoffset, in ImageData pixels, [Optional] GLboolean flipY, [Optional] in premultiplyAlpha); -// void texSubImage2D(in GLenum target, in GLint level, in GLint xoffset, in GLint yoffset, in HTMLImageElement image, [Optional] GLboolean flipY, [Optional] in premultiplyAlpha); -// void texSubImage2D(in GLenum target, in GLint level, in GLint xoffset, in GLint yoffset, in HTMLCanvasElement canvas, [Optional] GLboolean flipY, [Optional] in premultiplyAlpha); -// void texSubImage2D(in GLenum target, in GLint level, in GLint xoffset, in GLint yoffset, in HTMLVideoElement video, [Optional] GLboolean flipY, [Optional] in premultiplyAlpha); -JSValue JSWebGLRenderingContext::texSubImage2D(ExecState* exec) -{ - if (exec->argumentCount() < 5 || exec->argumentCount() > 9) - return throwError(exec, SyntaxError); - - ExceptionCode ec = 0; - - WebGLRenderingContext* context = static_cast<WebGLRenderingContext*>(impl()); - unsigned target = exec->argument(0).toInt32(exec); - if (exec->hadException()) - return jsUndefined(); - - unsigned level = exec->argument(1).toInt32(exec); - if (exec->hadException()) - return jsUndefined(); - - unsigned xoff = exec->argument(2).toInt32(exec); - if (exec->hadException()) - return jsUndefined(); - - unsigned yoff = exec->argument(3).toInt32(exec); - if (exec->hadException()) - return jsUndefined(); - - JSObject* o = 0; - - if (exec->argumentCount() <= 7) { - // This is one of the last 4 forms. Param 4 can be <img>, <canvas> or <video> element, of the format param. - JSValue value = exec->argument(4); - - if (!value.isObject()) - return throwError(exec, SyntaxError); - - o = asObject(value); - - bool flipY = exec->argument(5).toBoolean(exec); - bool premultiplyAlpha = exec->argument(6).toBoolean(exec); - - if (o->inherits(&JSImageData::s_info)) { - ImageData* data = static_cast<ImageData*>(static_cast<JSImageData*>(o)->impl()); - context->texSubImage2D(target, level, xoff, yoff, data, flipY, premultiplyAlpha, ec); - } else if (o->inherits(&JSHTMLImageElement::s_info)) { - HTMLImageElement* element = static_cast<HTMLImageElement*>(static_cast<JSHTMLImageElement*>(o)->impl()); - context->texSubImage2D(target, level, xoff, yoff, element, flipY, premultiplyAlpha, ec); - } else if (o->inherits(&JSHTMLCanvasElement::s_info)) { - HTMLCanvasElement* element = static_cast<HTMLCanvasElement*>(static_cast<JSHTMLCanvasElement*>(o)->impl()); - context->texSubImage2D(target, level, xoff, yoff, element, flipY, premultiplyAlpha, ec); -#if ENABLE(VIDEO) - } else if (o->inherits(&JSHTMLVideoElement::s_info)) { - HTMLVideoElement* element = static_cast<HTMLVideoElement*>(static_cast<JSHTMLVideoElement*>(o)->impl()); - context->texSubImage2D(target, level, xoff, yoff, element, flipY, premultiplyAlpha, ec); -#endif - } else - ec = TYPE_MISMATCH_ERR; - } else { - // This must be the ArrayBufferView form - if (exec->argumentCount() != 9) - return throwError(exec, SyntaxError); - - unsigned width = exec->argument(4).toInt32(exec); - if (exec->hadException()) - return jsUndefined(); - - unsigned height = exec->argument(5).toInt32(exec); - if (exec->hadException()) - return jsUndefined(); - - unsigned format = exec->argument(6).toInt32(exec); - if (exec->hadException()) - return jsUndefined(); - - unsigned type = exec->argument(7).toInt32(exec); - if (exec->hadException()) - return jsUndefined(); - - JSValue value = exec->argument(8); - if (!value.isObject()) - context->texSubImage2D(target, level, xoff, yoff, width, height, format, type, 0, ec); - else { - o = asObject(value); - - if (o->inherits(&JSArrayBufferView::s_info)) { - ArrayBufferView* obj = static_cast<ArrayBufferView*>(static_cast<JSArrayBufferView*>(o)->impl()); - context->texSubImage2D(target, level, xoff, yoff, width, height, format, type, obj, ec); - } else - return throwError(exec, TypeError); - } - } - - setDOMException(exec, ec); - return jsUndefined(); -} - template<typename T, size_t inlineCapacity> bool toVector(JSC::ExecState* exec, JSC::JSValue value, Vector<T, inlineCapacity>& vector) { @@ -558,7 +318,7 @@ static bool functionForUniform(DataFunctionToCall f) static JSC::JSValue dataFunctionf(DataFunctionToCall f, JSC::ExecState* exec, WebGLRenderingContext* context) { if (exec->argumentCount() != 2) - return throwError(exec, SyntaxError); + return throwSyntaxError(exec); WebGLUniformLocation* location = 0; long index = -1; @@ -571,7 +331,7 @@ static JSC::JSValue dataFunctionf(DataFunctionToCall f, JSC::ExecState* exec, We if (exec->hadException()) return jsUndefined(); - RefPtr<FloatArray> webGLArray = toFloatArray(exec->argument(1)); + RefPtr<Float32Array> webGLArray = toFloat32Array(exec->argument(1)); if (exec->hadException()) return jsUndefined(); @@ -610,7 +370,7 @@ static JSC::JSValue dataFunctionf(DataFunctionToCall f, JSC::ExecState* exec, We Vector<float, 64> array; if (!toVector(exec, exec->argument(1), array)) - return throwError(exec, TypeError); + return throwTypeError(exec); switch (f) { case f_uniform1v: @@ -646,7 +406,7 @@ static JSC::JSValue dataFunctionf(DataFunctionToCall f, JSC::ExecState* exec, We static JSC::JSValue dataFunctioni(DataFunctionToCall f, JSC::ExecState* exec, WebGLRenderingContext* context) { if (exec->argumentCount() != 2) - return throwError(exec, SyntaxError); + return throwSyntaxError(exec); WebGLUniformLocation* location = toWebGLUniformLocation(exec->argument(0)); @@ -683,7 +443,7 @@ static JSC::JSValue dataFunctioni(DataFunctionToCall f, JSC::ExecState* exec, We Vector<int, 64> array; if (!toVector(exec, exec->argument(1), array)) - return throwError(exec, TypeError); + return throwTypeError(exec); switch (f) { case f_uniform1v: @@ -709,7 +469,7 @@ static JSC::JSValue dataFunctioni(DataFunctionToCall f, JSC::ExecState* exec, We static JSC::JSValue dataFunctionMatrix(DataFunctionMatrixToCall f, JSC::ExecState* exec, WebGLRenderingContext* context) { if (exec->argumentCount() != 3) - return throwError(exec, SyntaxError); + return throwSyntaxError(exec); WebGLUniformLocation* location = toWebGLUniformLocation(exec->argument(0)); @@ -720,7 +480,7 @@ static JSC::JSValue dataFunctionMatrix(DataFunctionMatrixToCall f, JSC::ExecStat if (exec->hadException()) return jsUndefined(); - RefPtr<FloatArray> webGLArray = toFloatArray(exec->argument(2)); + RefPtr<Float32Array> webGLArray = toFloat32Array(exec->argument(2)); if (exec->hadException()) return jsUndefined(); @@ -744,7 +504,7 @@ static JSC::JSValue dataFunctionMatrix(DataFunctionMatrixToCall f, JSC::ExecStat Vector<float, 64> array; if (!toVector(exec, exec->argument(2), array)) - return throwError(exec, TypeError); + return throwTypeError(exec); switch (f) { case f_uniformMatrix2fv: |