deleted file mode 100644
--- a/content/canvas/src/WebGLArrays.cpp
+++ /dev/null
@@ -1,2421 +0,0 @@
-/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/* ***** BEGIN LICENSE BLOCK *****
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is mozilla.org code.
- *
- * The Initial Developer of the Original Code is
- * Mozilla Corporation.
- * Portions created by the Initial Developer are Copyright (C) 2009
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- * Mark Steele <mwsteele@gmail.com>
- * Vladimir Vukicevic <vladimir@pobox.com>
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either the GNU General Public License Version 2 or later (the "GPL"), or
- * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- * ***** END LICENSE BLOCK ***** */
-
-#include "WebGLArrays.h"
-
-#include "NativeJSContext.h"
-
-// TODO:
-// XXX: fix overflow in integer mult in ::Set!
-// XXX: get rid of code duplication, use inline helpers, templates, or macros
-// XXX: Prepare/Zero in initializers is inefficient, we should really
-// just be doing calloc
-// XXX: array Set() shouldn't call into the inner Set(), because that
-// repeats the length check and is probably not getting inlined
-// write benchmarks
-
-using namespace mozilla;
-
-nsresult
-NS_NewWebGLArrayBuffer(nsISupports **aResult)
-{
- nsIWebGLArrayBuffer *wgab = new WebGLArrayBuffer();
- if (!wgab)
- return NS_ERROR_OUT_OF_MEMORY;
-
- NS_ADDREF(*aResult = wgab);
- return NS_OK;
-}
-
-WebGLArrayBuffer::WebGLArrayBuffer(PRUint32 length)
-{
- EnsureCapacity(PR_FALSE, length);
-}
-
-NS_IMETHODIMP
-WebGLArrayBuffer::Initialize(nsISupports *owner,
- JSContext *cx,
- JSObject *obj,
- PRUint32 argc,
- jsval *argv)
-{
- /* Constructor: WebGLArrayBuffer(n) */
- if (JSVAL_IS_NUMBER(argv[0])) {
- uint32 length;
- ::JS_ValueToECMAUint32(cx, argv[0], &length);
- if (length == 0)
- return NS_ERROR_FAILURE;
-
- EnsureCapacity(PR_FALSE, length);
-
- return NS_OK;
- }
-
- return NS_ERROR_DOM_SYNTAX_ERR;
-}
-
-/* readonly attribute unsigned long byteLength; */
-NS_IMETHODIMP WebGLArrayBuffer::GetByteLength(PRUint32 *aByteLength)
-{
- *aByteLength = capacity;
- return NS_OK;
-}
-
-/* [noscript, notxpcom] voidPtr GetNativeArrayBuffer (); */
-NS_IMETHODIMP_(WebGLArrayBuffer *) WebGLArrayBuffer::GetNativeArrayBuffer()
-{
- return this;
-}
-
-/* [noscript, notxpcom] voidPtr nativePointer (); */
-NS_IMETHODIMP_(void *) WebGLArrayBuffer::NativePointer()
-{
- return data;
-}
-
-/* [noscript, notxpcom] unsigned long nativeSize (); */
-NS_IMETHODIMP_(PRUint32) WebGLArrayBuffer::NativeSize()
-{
- return capacity;
-}
-
-/*
- * WebGLFloatArray
- */
-
-nsresult
-NS_NewWebGLFloatArray(nsISupports **aResult)
-{
- nsIWebGLFloatArray *wgfa = new WebGLFloatArray();
- if (!wgfa)
- return NS_ERROR_OUT_OF_MEMORY;
-
- NS_ADDREF(*aResult = wgfa);
- return NS_OK;
-}
-
-WebGLFloatArray::WebGLFloatArray(PRUint32 length)
- : mOffset(0), mLength(length)
-{
- mBuffer = new WebGLArrayBuffer(length * sizeof(float));
-}
-
-WebGLFloatArray::WebGLFloatArray(WebGLArrayBuffer *buffer, PRUint32 offset, PRUint32 length)
- : mBuffer(buffer), mOffset(offset), mLength(length)
-{
-}
-
-WebGLFloatArray::WebGLFloatArray(JSContext *cx, JSObject *arrayObj, jsuint arrayLen)
- : mOffset(0), mLength(arrayLen)
-{
- mBuffer = new WebGLArrayBuffer();
- mBuffer->InitFromJSArray(LOCAL_GL_FLOAT, 1, cx, arrayObj, arrayLen);
-}
-
-NS_IMETHODIMP
-WebGLFloatArray::Initialize(nsISupports *owner,
- JSContext *cx,
- JSObject *obj,
- PRUint32 argc,
- jsval *argv)
-{
- if (JSVAL_IS_NUMBER(argv[0])) {
- uint32 length;
- ::JS_ValueToECMAUint32(cx, argv[0], &length);
- mBuffer = new WebGLArrayBuffer();
- mBuffer->Prepare(LOCAL_GL_FLOAT, 1, length);
- mBuffer->Zero();
- mLength = length;
- } else {
- JSObject *arrayObj;
- jsuint arrayLen;
- jsuint byteOffset = 0;
- jsuint length = 0;
-
- if (!::JS_ConvertArguments(cx, argc, argv, "o/uu", &arrayObj, &byteOffset, &length) ||
- arrayObj == NULL)
- {
- return NS_ERROR_DOM_SYNTAX_ERR;
- }
-
- if (::JS_IsArrayObject(cx, arrayObj) &&
- ::JS_GetArrayLength(cx, arrayObj, &arrayLen))
- {
- mBuffer = new WebGLArrayBuffer();
- mBuffer->InitFromJSArray(LOCAL_GL_FLOAT, 1, cx, arrayObj, arrayLen);
- mLength = arrayLen;
- } else {
- nsCOMPtr<nsIWebGLArrayBuffer> canvasObj;
- nsresult rv;
- rv = nsContentUtils::XPConnect()->WrapJS(cx, arrayObj, NS_GET_IID(nsIWebGLArrayBuffer), getter_AddRefs(canvasObj));
- if (NS_FAILED(rv) || !canvasObj) {
- return NS_ERROR_DOM_SYNTAX_ERR;
- }
-
- mBuffer = canvasObj->GetNativeArrayBuffer();
-
- if (byteOffset % sizeof(float))
- return NS_ERROR_FAILURE;
-
- if ((byteOffset + (length * sizeof(float))) > mBuffer->capacity)
- return NS_ERROR_FAILURE;
-
- if (length > 0) {
- mLength = length;
- } else {
- if ((mBuffer->capacity - byteOffset) % sizeof(float))
- return NS_ERROR_FAILURE;
-
- mLength = (mBuffer->capacity - byteOffset) / sizeof(float);
- }
- }
- }
-
- return NS_OK;
-}
-
-/* readonly attribute nsIWebGLArrayBuffer buffer; */
-NS_IMETHODIMP WebGLFloatArray::GetBuffer(nsIWebGLArrayBuffer **aBuffer)
-{
- NS_ADDREF(*aBuffer = mBuffer);
- return NS_OK;
-}
-
-/* readonly attribute unsigned long byteOffset; */
-NS_IMETHODIMP WebGLFloatArray::GetByteOffset(PRUint32 *aByteOffset)
-{
- *aByteOffset = mOffset;
- return NS_OK;
-}
-
-/* readonly attribute unsigned long byteLength; */
-NS_IMETHODIMP WebGLFloatArray::GetByteLength(PRUint32 *aByteLength)
-{
- *aByteLength = mLength * sizeof(float);
- return NS_OK;
-}
-
-/* attribute unsigned long length; */
-NS_IMETHODIMP WebGLFloatArray::GetLength(PRUint32 *aLength)
-{
- *aLength = mLength;
- return NS_OK;
-}
-
-/* unsigned long alignedSizeInBytes (); */
-NS_IMETHODIMP WebGLFloatArray::AlignedSizeInBytes(PRUint32 *retval)
-{
- *retval = mBuffer->capacity;
- return NS_OK;
-}
-
-/* nsIWebGLArray slice (in unsigned long offset, in unsigned long length); */
-NS_IMETHODIMP WebGLFloatArray::Slice(PRUint32 offset, PRUint32 length, nsIWebGLArray **retval)
-{
- if (length == 0)
- return NS_ERROR_FAILURE;
-
- if (offset + length > mBuffer->capacity)
- return NS_ERROR_FAILURE;
-
- nsIWebGLArray *wga = new WebGLFloatArray(mBuffer, offset, length);
- NS_ADDREF(*retval = wga);
- return NS_OK;
-}
-
-/* [IndexGetter] float get (in unsigned long index); */
-NS_IMETHODIMP WebGLFloatArray::Get(PRUint32 index, float *retval)
-{
- if (index >= mLength)
- return NS_ERROR_FAILURE;
-
- float *values = static_cast<float*>(mBuffer->data);
- *retval = values[index];
-
- return NS_OK;
-}
-
-void
-WebGLFloatArray::Set(PRUint32 index, float value)
-{
- if (index >= mLength)
- return;
-
- float *values = static_cast<float*>(mBuffer->data);
- values[index] = value;
-}
-
-/* void set (); */
-NS_IMETHODIMP WebGLFloatArray::Set()
-{
- NativeJSContext js;
- if (NS_FAILED(js.error))
- return js.error;
-
- if (js.argc < 1 || js.argc > 2)
- return NS_ERROR_DOM_SYNTAX_ERR;
-
- if (JSVAL_IS_NUMBER(js.argv[0])) {
- if (js.argc != 2)
- return NS_ERROR_DOM_SYNTAX_ERR;
-
- uint32 index;
- ::JS_ValueToECMAUint32(js.ctx, js.argv[0], &index);
-
- jsdouble value;
- ::JS_ValueToNumber(js.ctx, js.argv[1], &value);
-
- if (index >= mLength)
- return NS_ERROR_FAILURE;
-
- Set(index, (float) value);
- } else {
- return NS_ERROR_NOT_IMPLEMENTED;
- }
-
- return NS_OK;
-}
-
-NS_IMETHODIMP_(PRUint32) WebGLFloatArray::NativeType()
-{
- return mBuffer->type;
-}
-
-/* [noscript, notxpcom] voidPtr nativePointer (); */
-NS_IMETHODIMP_(void *) WebGLFloatArray::NativePointer()
-{
- return mBuffer->data;
-}
-
-/* [noscript, notxpcom] unsigned long nativeSize (); */
-NS_IMETHODIMP_(PRUint32) WebGLFloatArray::NativeSize()
-{
- return mBuffer->capacity;
-}
-
-/* [noscript, notxpcom] unsigned long nativeElementSize (); */
-NS_IMETHODIMP_(PRUint32) WebGLFloatArray::NativeElementSize()
-{
- return mBuffer->ElementSize();
-}
-
-/* [noscript, notxpcom] unsigned long nativeCount (); */
-NS_IMETHODIMP_(PRUint32) WebGLFloatArray::NativeCount()
-{
- return mBuffer->length;
-}
-
-// nsIXPCScriptable
-#define XPC_MAP_CLASSNAME WebGLFloatArray
-#define XPC_MAP_QUOTED_CLASSNAME "WebGLFloatArray"
-#define XPC_MAP_WANT_SETPROPERTY
-#define XPC_MAP_WANT_GETPROPERTY
-#define XPC_MAP_WANT_NEWRESOLVE
-#define XPC_MAP_FLAGS nsIXPCScriptable::USE_JSSTUB_FOR_ADDPROPERTY
-#include "xpc_map_end.h"
-
-PRBool WebGLFloatArray::JSValToIndex(JSContext *cx, jsval id, uint32 *retval) {
- PRBool ok = PR_FALSE;
- uint32 index;
-
- if (JSVAL_IS_INT(id)) {
- index = JSVAL_TO_INT(id);
- ok = PR_TRUE;
- } else {
- ok = JS_ValueToECMAUint32(cx, id, &index);
- }
-
- if (!ok || index >= mLength)
- return PR_FALSE;
-
- *retval = index;
- return PR_TRUE;
-}
-
-NS_IMETHODIMP WebGLFloatArray::GetProperty(nsIXPConnectWrappedNative *wrapper, JSContext * cx,
- JSObject * obj, jsval id, jsval * vp, PRBool *_retval)
-{
- uint32 index;
-
- if (!JSValToIndex(cx, id, &index)) {
- *_retval = PR_FALSE;
- return NS_ERROR_INVALID_ARG;
- }
-
- float val;
- Get(index, &val);
- *_retval = JS_NewNumberValue(cx, val, vp);
-
- return NS_OK;
-}
-
-NS_IMETHODIMP WebGLFloatArray::SetProperty(nsIXPConnectWrappedNative *wrapper, JSContext * cx,
- JSObject * obj, jsval id, jsval * vp, PRBool *_retval)
-{
- uint32 index;
- float val;
-
- if (!JSValToIndex(cx, id, &index)) {
- *_retval = PR_FALSE;
- return NS_ERROR_INVALID_ARG;
- }
-
- PRBool ok = PR_FALSE;
-
- if (JSVAL_IS_INT(*vp)) {
- val = (float) JSVAL_TO_INT(*vp);
- ok = PR_TRUE;
- } else {
- jsdouble dval;
- ok = JS_ValueToNumber(cx, *vp, &dval);
- val = (float) dval;
- }
-
- if (!ok) {
- *_retval = PR_FALSE;
- return NS_ERROR_INVALID_ARG;
- }
-
- Set(index, val);
- return NS_OK;
-}
-
-NS_IMETHODIMP WebGLFloatArray::NewResolve(nsIXPConnectWrappedNative *wrapper, JSContext * cx,
- JSObject * obj, jsval id, PRUint32 flags, JSObject * *objp,
- PRBool *_retval)
-{
- uint32 index;
- PRBool ok = JSValToIndex(cx, id, &index);
-
- if (ok) {
- *_retval = PR_TRUE;
- *objp = obj;
- } else {
- *_retval = PR_FALSE;
- return NS_ERROR_FAILURE;
- }
-
- return NS_OK;
-}
-
-/*
- * WebGLByteArray
- */
-
-nsresult
-NS_NewWebGLByteArray(nsISupports **aResult)
-{
- nsIWebGLByteArray *wgba = new WebGLByteArray();
- if (!wgba)
- return NS_ERROR_OUT_OF_MEMORY;
-
- NS_ADDREF(*aResult = wgba);
- return NS_OK;
-}
-
-WebGLByteArray::WebGLByteArray(PRUint32 length)
- : mOffset(0), mLength(length)
-{
- mBuffer = new WebGLArrayBuffer(length);
-}
-
-WebGLByteArray::WebGLByteArray(WebGLArrayBuffer *buffer, PRUint32 offset, PRUint32 length)
- : mBuffer(buffer), mOffset(offset), mLength(length)
-{
-}
-
-WebGLByteArray::WebGLByteArray(JSContext *cx, JSObject *arrayObj, jsuint arrayLen)
- : mOffset(0), mLength(arrayLen)
-{
- mBuffer = new WebGLArrayBuffer();
- mBuffer->InitFromJSArray(LOCAL_GL_UNSIGNED_BYTE, 1, cx, arrayObj, arrayLen);
-}
-
-NS_IMETHODIMP
-WebGLByteArray::Initialize(nsISupports *owner,
- JSContext *cx,
- JSObject *obj,
- PRUint32 argc,
- jsval *argv)
-{
- if (JSVAL_IS_NUMBER(argv[0])) {
- uint32 length;
- ::JS_ValueToECMAUint32(cx, argv[0], &length);
- mBuffer = new WebGLArrayBuffer();
- mBuffer->Prepare(LOCAL_GL_BYTE, 1, length);
- mBuffer->Zero();
- mLength = length;
- } else {
- JSObject *arrayObj;
- jsuint arrayLen;
- jsuint byteOffset = 0;
- jsuint length = 0;
-
- if (!::JS_ConvertArguments(cx, argc, argv, "o/uu", &arrayObj, &byteOffset, &length) ||
- arrayObj == NULL)
- {
- return NS_ERROR_DOM_SYNTAX_ERR;
- }
-
- if (::JS_IsArrayObject(cx, arrayObj) &&
- ::JS_GetArrayLength(cx, arrayObj, &arrayLen))
- {
- mBuffer = new WebGLArrayBuffer();
- mBuffer->InitFromJSArray(LOCAL_GL_UNSIGNED_BYTE, 1, cx, arrayObj, arrayLen);
- mLength = arrayLen;
- } else {
- nsCOMPtr<nsIWebGLArrayBuffer> canvasObj;
- nsresult rv;
- rv = nsContentUtils::XPConnect()->WrapJS(cx, arrayObj, NS_GET_IID(nsIWebGLArrayBuffer), getter_AddRefs(canvasObj));
- if (NS_FAILED(rv) || !canvasObj) {
- return NS_ERROR_DOM_SYNTAX_ERR;
- }
-
- mBuffer = canvasObj->GetNativeArrayBuffer();
-
- if ((byteOffset + length) > mBuffer->capacity)
- return NS_ERROR_FAILURE;
-
- if (length > 0)
- mLength = length;
- else
- mLength = (mBuffer->capacity - byteOffset);
- }
- }
-
- return NS_OK;
-}
-
-/* readonly attribute nsIWebGLArrayBuffer buffer; */
-NS_IMETHODIMP WebGLByteArray::GetBuffer(nsIWebGLArrayBuffer **aBuffer)
-{
- NS_ADDREF(*aBuffer = mBuffer);
- return NS_OK;
-}
-
-/* readonly attribute unsigned long byteOffset; */
-NS_IMETHODIMP WebGLByteArray::GetByteOffset(PRUint32 *aByteOffset)
-{
- *aByteOffset = mOffset;
- return NS_OK;
-}
-
-/* readonly attribute unsigned long byteLength; */
-NS_IMETHODIMP WebGLByteArray::GetByteLength(PRUint32 *aByteLength)
-{
- *aByteLength = mLength;
- return NS_OK;
-}
-
-/* attribute unsigned long length; */
-NS_IMETHODIMP WebGLByteArray::GetLength(PRUint32 *aLength)
-{
- *aLength = mLength;
- return NS_OK;
-}
-
-/* unsigned long alignedSizeInBytes (); */
-NS_IMETHODIMP WebGLByteArray::AlignedSizeInBytes(PRUint32 *retval)
-{
- *retval = mBuffer->capacity;
- return NS_OK;
-}
-
-/* nsIWebGLArray slice (in unsigned long offset, in unsigned long length); */
-NS_IMETHODIMP WebGLByteArray::Slice(PRUint32 offset, PRUint32 length, nsIWebGLArray **retval)
-{
- if (length == 0)
- return NS_ERROR_FAILURE;
-
- if (offset + length > mBuffer->capacity)
- return NS_ERROR_FAILURE;
-
- nsIWebGLArray *wga = new WebGLByteArray(mBuffer, offset, length);
- NS_ADDREF(*retval = wga);
- return NS_OK;
-}
-
-/* [IndexGetter] long get (in unsigned long index); */
-NS_IMETHODIMP WebGLByteArray::Get(PRUint32 index, PRInt32 *retval)
-{
- if (index >= mLength)
- return NS_ERROR_FAILURE;
-
- char *values = static_cast<char*>(mBuffer->data);
- *retval = values[index];
-
- return NS_OK;
-}
-
-void
-WebGLByteArray::Set(PRUint32 index, char value)
-{
- if (index >= mLength)
- return;
-
- char *values = static_cast<char*>(mBuffer->data);
- values[index] = value;
-}
-
-/* void set (); */
-NS_IMETHODIMP WebGLByteArray::Set()
-{
- NativeJSContext js;
- if (NS_FAILED(js.error))
- return js.error;
-
- if (js.argc < 1 || js.argc > 2)
- return NS_ERROR_DOM_SYNTAX_ERR;
-
- if (JSVAL_IS_NUMBER(js.argv[0])) {
- if (js.argc != 2)
- return NS_ERROR_DOM_SYNTAX_ERR;
-
- uint32 index;
- ::JS_ValueToECMAUint32(js.ctx, js.argv[0], &index);
-
- int32 value;
- ::JS_ValueToECMAInt32(js.ctx, js.argv[1], &value);
-
- if (index >= mLength)
- return NS_ERROR_FAILURE;
-
- Set(index, (char) value);
- } else {
- return NS_ERROR_NOT_IMPLEMENTED;
- }
-
- return NS_OK;
-}
-
-NS_IMETHODIMP_(PRUint32) WebGLByteArray::NativeType()
-{
- return mBuffer->type;
-}
-
-/* [noscript, notxpcom] voidPtr nativePointer (); */
-NS_IMETHODIMP_(void *) WebGLByteArray::NativePointer()
-{
- return mBuffer->data;
-}
-
-/* [noscript, notxpcom] unsigned long nativeSize (); */
-NS_IMETHODIMP_(PRUint32) WebGLByteArray::NativeSize()
-{
- return mBuffer->capacity;
-}
-
-/* [noscript, notxpcom] unsigned long nativeElementSize (); */
-NS_IMETHODIMP_(PRUint32) WebGLByteArray::NativeElementSize()
-{
- return mBuffer->ElementSize();
-}
-
-/* [noscript, notxpcom] unsigned long nativeCount (); */
-NS_IMETHODIMP_(PRUint32) WebGLByteArray::NativeCount()
-{
- return mBuffer->length;
-}
-
-// nsIXPCScriptable
-#define XPC_MAP_CLASSNAME WebGLByteArray
-#define XPC_MAP_QUOTED_CLASSNAME "WebGLByteArray"
-#define XPC_MAP_WANT_SETPROPERTY
-#define XPC_MAP_WANT_GETPROPERTY
-#define XPC_MAP_WANT_NEWRESOLVE
-#define XPC_MAP_FLAGS nsIXPCScriptable::USE_JSSTUB_FOR_ADDPROPERTY
-#include "xpc_map_end.h"
-
-PRBool WebGLByteArray::JSValToIndex(JSContext *cx, jsval id, uint32 *retval) {
- PRBool ok = PR_FALSE;
- uint32 index;
-
- if (JSVAL_IS_INT(id)) {
- index = JSVAL_TO_INT(id);
- ok = PR_TRUE;
- } else {
- ok = JS_ValueToECMAUint32(cx, id, &index);
- }
-
- if (!ok || index >= mLength)
- return PR_FALSE;
-
- *retval = index;
- return PR_TRUE;
-}
-
-NS_IMETHODIMP WebGLByteArray::GetProperty(nsIXPConnectWrappedNative *wrapper, JSContext * cx,
- JSObject * obj, jsval id, jsval * vp, PRBool *_retval)
-{
- uint32 index;
-
- if (!JSValToIndex(cx, id, &index)) {
- *_retval = PR_FALSE;
- return NS_ERROR_INVALID_ARG;
- }
-
- PRInt32 val;
- Get(index, &val);
- *_retval = JS_NewNumberValue(cx, val, vp);
-
- return NS_SUCCESS_I_DID_SOMETHING;
-}
-
-NS_IMETHODIMP WebGLByteArray::SetProperty(nsIXPConnectWrappedNative *wrapper, JSContext * cx,
- JSObject * obj, jsval id, jsval * vp, PRBool *_retval)
-{
- uint32 index;
- int32 val;
-
- if (!JSValToIndex(cx, id, &index)) {
- *_retval = PR_FALSE;
- return NS_ERROR_INVALID_ARG;
- }
-
- PRBool ok = PR_FALSE;
-
- if (JSVAL_IS_INT(*vp)) {
- val = JSVAL_TO_INT(*vp);
- ok = PR_TRUE;
- } else {
- ok = JS_ValueToECMAInt32(cx, *vp, &val);
- }
-
- if (!ok) {
- *_retval = PR_FALSE;
- return NS_ERROR_INVALID_ARG;
- }
-
- Set(index, (char) val);
- return NS_SUCCESS_I_DID_SOMETHING;
-}
-
-NS_IMETHODIMP WebGLByteArray::NewResolve(nsIXPConnectWrappedNative *wrapper, JSContext * cx,
- JSObject * obj, jsval id, PRUint32 flags, JSObject * *objp,
- PRBool *_retval)
-{
- uint32 index;
- PRBool ok = JSValToIndex(cx, id, &index);
-
- if (ok) {
- *_retval = PR_TRUE;
- *objp = obj;
- } else {
- *_retval = PR_FALSE;
- return NS_ERROR_FAILURE;
- }
-
- return NS_OK;
-}
-
-/*
- * WebGLUnsignedByteArray
- */
-
-nsresult
-NS_NewWebGLUnsignedByteArray(nsISupports **aResult)
-{
- nsIWebGLUnsignedByteArray *wguba = new WebGLUnsignedByteArray();
- if (!wguba)
- return NS_ERROR_OUT_OF_MEMORY;
-
- NS_ADDREF(*aResult = wguba);
- return NS_OK;
-}
-
-WebGLUnsignedByteArray::WebGLUnsignedByteArray(PRUint32 length)
- : mOffset(0), mLength(length)
-{
- mBuffer = new WebGLArrayBuffer(length);
-}
-
-WebGLUnsignedByteArray::WebGLUnsignedByteArray(WebGLArrayBuffer *buffer, PRUint32 offset, PRUint32 length)
- : mBuffer(buffer), mOffset(offset), mLength(length)
-{
-}
-
-WebGLUnsignedByteArray::WebGLUnsignedByteArray(JSContext *cx, JSObject *arrayObj, jsuint arrayLen)
- : mOffset(0), mLength(arrayLen)
-{
- mBuffer = new WebGLArrayBuffer();
- mBuffer->InitFromJSArray(LOCAL_GL_UNSIGNED_BYTE, 1, cx, arrayObj, arrayLen);
-}
-
-NS_IMETHODIMP
-WebGLUnsignedByteArray::Initialize(nsISupports *owner,
- JSContext *cx,
- JSObject *obj,
- PRUint32 argc,
- jsval *argv)
-{
- if (JSVAL_IS_NUMBER(argv[0])) {
- uint32 length;
- ::JS_ValueToECMAUint32(cx, argv[0], &length);
- mBuffer = new WebGLArrayBuffer();
- mBuffer->Prepare(LOCAL_GL_UNSIGNED_BYTE, 1, length);
- mBuffer->Zero();
- mLength = length;
- } else {
- JSObject *arrayObj;
- jsuint arrayLen;
- jsuint byteOffset = 0;
- jsuint length = 0;
-
- if (!::JS_ConvertArguments(cx, argc, argv, "o/uu", &arrayObj, &byteOffset, &length) ||
- arrayObj == NULL)
- {
- return NS_ERROR_DOM_SYNTAX_ERR;
- }
-
- if (::JS_IsArrayObject(cx, arrayObj) &&
- ::JS_GetArrayLength(cx, arrayObj, &arrayLen))
- {
- mBuffer = new WebGLArrayBuffer();
- mBuffer->InitFromJSArray(LOCAL_GL_UNSIGNED_BYTE, 1, cx, arrayObj, arrayLen);
- mLength = arrayLen;
- } else {
- nsCOMPtr<nsIWebGLArrayBuffer> canvasObj;
- nsresult rv;
- rv = nsContentUtils::XPConnect()->WrapJS(cx, arrayObj, NS_GET_IID(nsIWebGLArrayBuffer), getter_AddRefs(canvasObj));
- if (NS_FAILED(rv) || !canvasObj) {
- return NS_ERROR_DOM_SYNTAX_ERR;
- }
-
- mBuffer = canvasObj->GetNativeArrayBuffer();
-
- if ((byteOffset + length) > mBuffer->capacity)
- return NS_ERROR_FAILURE;
-
- if (length > 0)
- mLength = length;
- else
- mLength = (mBuffer->capacity - byteOffset);
- }
- }
-
- return NS_OK;
-}
-
-/* readonly attribute nsIWebGLArrayBuffer buffer; */
-NS_IMETHODIMP WebGLUnsignedByteArray::GetBuffer(nsIWebGLArrayBuffer **aBuffer)
-{
- NS_ADDREF(*aBuffer = mBuffer);
- return NS_OK;
-}
-
-/* readonly attribute unsigned long byteOffset; */
-NS_IMETHODIMP WebGLUnsignedByteArray::GetByteOffset(PRUint32 *aByteOffset)
-{
- *aByteOffset = mOffset;
- return NS_OK;
-}
-
-/* readonly attribute unsigned long byteLength; */
-NS_IMETHODIMP WebGLUnsignedByteArray::GetByteLength(PRUint32 *aByteLength)
-{
- *aByteLength = mLength;
- return NS_OK;
-}
-
-/* attribute unsigned long length; */
-NS_IMETHODIMP WebGLUnsignedByteArray::GetLength(PRUint32 *aLength)
-{
- *aLength = mLength;
- return NS_OK;
-}
-
-/* unsigned long alignedSizeInBytes (); */
-NS_IMETHODIMP WebGLUnsignedByteArray::AlignedSizeInBytes(PRUint32 *retval)
-{
- *retval = mBuffer->capacity;
- return NS_OK;
-}
-
-/* nsIWebGLArray slice (in unsigned long offset, in unsigned long length); */
-NS_IMETHODIMP WebGLUnsignedByteArray::Slice(PRUint32 offset, PRUint32 length, nsIWebGLArray **retval)
-{
- if (length == 0)
- return NS_ERROR_FAILURE;
-
- if (offset + length > mBuffer->capacity)
- return NS_ERROR_FAILURE;
-
- nsIWebGLArray *wga = new WebGLUnsignedByteArray(mBuffer, offset, length);
- NS_ADDREF(*retval = wga);
- return NS_OK;
-}
-
-/* [IndexGetter] unsigned long get (in unsigned long index); */
-NS_IMETHODIMP WebGLUnsignedByteArray::Get(PRUint32 index, PRUint32 *retval)
-{
- if (index >= mLength)
- return NS_ERROR_FAILURE;
-
- unsigned char *values = static_cast<unsigned char*>(mBuffer->data);
- *retval = values[index];
-
- return NS_OK;
-}
-
-void
-WebGLUnsignedByteArray::Set(PRUint32 index, unsigned char value)
-{
- if (index >= mLength)
- return;
-
- unsigned char *values = static_cast<unsigned char*>(mBuffer->data);
- values[index] = value;
-}
-
-/* void set (); */
-NS_IMETHODIMP WebGLUnsignedByteArray::Set()
-{
- NativeJSContext js;
- if (NS_FAILED(js.error))
- return js.error;
-
- if (js.argc < 1 || js.argc > 2)
- return NS_ERROR_DOM_SYNTAX_ERR;
-
- if (JSVAL_IS_NUMBER(js.argv[0])) {
- if (js.argc != 2)
- return NS_ERROR_DOM_SYNTAX_ERR;
-
- uint32 index;
- ::JS_ValueToECMAUint32(js.ctx, js.argv[0], &index);
-
- uint32 value;
- ::JS_ValueToECMAUint32(js.ctx, js.argv[1], &value);
-
- if (index >= mLength)
- return NS_ERROR_FAILURE;
-
- Set(index, (unsigned char) value);
- } else {
- return NS_ERROR_NOT_IMPLEMENTED;
- }
-
- return NS_OK;
-}
-
-NS_IMETHODIMP_(PRUint32) WebGLUnsignedByteArray::NativeType()
-{
- return mBuffer->type;
-}
-
-/* [noscript, notxpcom] voidPtr nativePointer (); */
-NS_IMETHODIMP_(void *) WebGLUnsignedByteArray::NativePointer()
-{
- return mBuffer->data;
-}
-
-/* [noscript, notxpcom] unsigned long nativeSize (); */
-NS_IMETHODIMP_(PRUint32) WebGLUnsignedByteArray::NativeSize()
-{
- return mBuffer->capacity;
-}
-
-/* [noscript, notxpcom] unsigned long nativeElementSize (); */
-NS_IMETHODIMP_(PRUint32) WebGLUnsignedByteArray::NativeElementSize()
-{
- return mBuffer->ElementSize();
-}
-
-/* [noscript, notxpcom] unsigned long nativeCount (); */
-NS_IMETHODIMP_(PRUint32) WebGLUnsignedByteArray::NativeCount()
-{
- return mBuffer->length;
-}
-
-// nsIXPCScriptable
-#define XPC_MAP_CLASSNAME WebGLUnsignedByteArray
-#define XPC_MAP_QUOTED_CLASSNAME "WebGLUnsignedByteArray"
-#define XPC_MAP_WANT_SETPROPERTY
-#define XPC_MAP_WANT_GETPROPERTY
-#define XPC_MAP_WANT_NEWRESOLVE
-#define XPC_MAP_FLAGS nsIXPCScriptable::USE_JSSTUB_FOR_ADDPROPERTY
-#include "xpc_map_end.h"
-
-PRBool WebGLUnsignedByteArray::JSValToIndex(JSContext *cx, jsval id, uint32 *retval) {
- PRBool ok = PR_FALSE;
- uint32 index;
-
- if (JSVAL_IS_INT(id)) {
- index = JSVAL_TO_INT(id);
- ok = PR_TRUE;
- } else {
- ok = JS_ValueToECMAUint32(cx, id, &index);
- }
-
- if (!ok || index >= mLength)
- return PR_FALSE;
-
- *retval = index;
- return PR_TRUE;
-}
-
-NS_IMETHODIMP WebGLUnsignedByteArray::GetProperty(nsIXPConnectWrappedNative *wrapper, JSContext * cx,
- JSObject * obj, jsval id, jsval * vp, PRBool *_retval)
-{
- uint32 index;
-
- if (!JSValToIndex(cx, id, &index)) {
- *_retval = PR_FALSE;
- return NS_ERROR_INVALID_ARG;
- }
-
- PRUint32 val;
- Get(index, &val);
- *_retval = JS_NewNumberValue(cx, val, vp);
-
- return NS_OK;
-}
-
-NS_IMETHODIMP WebGLUnsignedByteArray::SetProperty(nsIXPConnectWrappedNative *wrapper, JSContext * cx,
- JSObject * obj, jsval id, jsval * vp, PRBool *_retval)
-{
- uint32 index;
- uint32 val;
-
- if (!JSValToIndex(cx, id, &index)) {
- *_retval = PR_FALSE;
- return NS_ERROR_INVALID_ARG;
- }
-
- PRBool ok = PR_FALSE;
-
- if (JSVAL_IS_INT(*vp)) {
- val = JSVAL_TO_INT(*vp);
- ok = PR_TRUE;
- } else {
- ok = JS_ValueToECMAUint32(cx, *vp, &val);
- }
-
- if (!ok) {
- *_retval = PR_FALSE;
- return NS_ERROR_INVALID_ARG;
- }
-
- Set(index, (unsigned char) val);
- return NS_OK;
-}
-
-NS_IMETHODIMP WebGLUnsignedByteArray::NewResolve(nsIXPConnectWrappedNative *wrapper, JSContext * cx,
- JSObject * obj, jsval id, PRUint32 flags, JSObject * *objp,
- PRBool *_retval)
-{
- uint32 index;
- PRBool ok = JSValToIndex(cx, id, &index);
-
- if (ok) {
- *_retval = PR_TRUE;
- *objp = obj;
- } else {
- *_retval = PR_FALSE;
- return NS_ERROR_FAILURE;
- }
-
- return NS_OK;
-}
-
-/*
- * WebGLShortArray
- */
-
-nsresult
-NS_NewWebGLShortArray(nsISupports **aResult)
-{
- nsIWebGLShortArray *wgsa = new WebGLShortArray();
- if (!wgsa)
- return NS_ERROR_OUT_OF_MEMORY;
-
- NS_ADDREF(*aResult = wgsa);
- return NS_OK;
-}
-
-WebGLShortArray::WebGLShortArray(PRUint32 length)
- : mOffset(0), mLength(length)
-{
- mBuffer = new WebGLArrayBuffer(length * sizeof(short));
-}
-
-WebGLShortArray::WebGLShortArray(WebGLArrayBuffer *buffer, PRUint32 offset, PRUint32 length)
- : mBuffer(buffer), mOffset(offset), mLength(length)
-{
-}
-
-WebGLShortArray::WebGLShortArray(JSContext *cx, JSObject *arrayObj, jsuint arrayLen)
- : mOffset(0), mLength(arrayLen)
-{
- mBuffer = new WebGLArrayBuffer();
- mBuffer->InitFromJSArray(LOCAL_GL_SHORT, 1, cx, arrayObj, arrayLen);
-}
-
-NS_IMETHODIMP
-WebGLShortArray::Initialize(nsISupports *owner,
- JSContext *cx,
- JSObject *obj,
- PRUint32 argc,
- jsval *argv)
-{
- if (JSVAL_IS_NUMBER(argv[0])) {
- uint32 length;
- ::JS_ValueToECMAUint32(cx, argv[0], &length);
- mBuffer = new WebGLArrayBuffer();
- mBuffer->Prepare(LOCAL_GL_SHORT, 1, length);
- mBuffer->Zero();
- mLength = length;
- } else {
- JSObject *arrayObj;
- jsuint arrayLen;
- jsuint byteOffset = 0;
- jsuint length = 0;
-
- if (!::JS_ConvertArguments(cx, argc, argv, "o/uu", &arrayObj, &byteOffset, &length) ||
- arrayObj == NULL)
- {
- return NS_ERROR_DOM_SYNTAX_ERR;
- }
-
- if (::JS_IsArrayObject(cx, arrayObj) &&
- ::JS_GetArrayLength(cx, arrayObj, &arrayLen))
- {
- mBuffer = new WebGLArrayBuffer();
- mBuffer->InitFromJSArray(LOCAL_GL_SHORT, 1, cx, arrayObj, arrayLen);
- mLength = arrayLen;
- } else {
- nsCOMPtr<nsIWebGLArrayBuffer> canvasObj;
- nsresult rv;
- rv = nsContentUtils::XPConnect()->WrapJS(cx, arrayObj, NS_GET_IID(nsIWebGLArrayBuffer), getter_AddRefs(canvasObj));
- if (NS_FAILED(rv) || !canvasObj) {
- return NS_ERROR_DOM_SYNTAX_ERR;
- }
-
- mBuffer = canvasObj->GetNativeArrayBuffer();
-
- if (byteOffset % sizeof(short))
- return NS_ERROR_FAILURE;
-
- if ((byteOffset + (length * sizeof(short))) > mBuffer->capacity)
- return NS_ERROR_FAILURE;
-
- if (length > 0) {
- mLength = length;
- } else {
- if ((mBuffer->capacity - byteOffset) % sizeof(short))
- return NS_ERROR_FAILURE;
-
- mLength = (mBuffer->capacity - byteOffset) / sizeof(short);
- }
- }
- }
-
- return NS_OK;
-}
-
-/* readonly attribute nsIWebGLArrayBuffer buffer; */
-NS_IMETHODIMP WebGLShortArray::GetBuffer(nsIWebGLArrayBuffer * *aBuffer)
-{
- NS_ADDREF(*aBuffer = mBuffer);
- return NS_OK;
-}
-
-/* readonly attribute unsigned long byteOffset; */
-NS_IMETHODIMP WebGLShortArray::GetByteOffset(PRUint32 *aByteOffset)
-{
- *aByteOffset = mOffset;
- return NS_OK;
-}
-
-/* readonly attribute unsigned long byteLength; */
-NS_IMETHODIMP WebGLShortArray::GetByteLength(PRUint32 *aByteLength)
-{
- *aByteLength = mLength * sizeof(short);
- return NS_OK;
-}
-
-/* attribute unsigned long length; */
-NS_IMETHODIMP WebGLShortArray::GetLength(PRUint32 *aLength)
-{
- *aLength = mLength;
- return NS_OK;
-}
-
-/* unsigned long alignedSizeInBytes (); */
-NS_IMETHODIMP WebGLShortArray::AlignedSizeInBytes(PRUint32 *retval)
-{
- *retval = mBuffer->capacity;
- return NS_OK;
-}
-
-/* nsIWebGLArray slice (in unsigned long offset, in unsigned long length); */
-NS_IMETHODIMP WebGLShortArray::Slice(PRUint32 offset, PRUint32 length, nsIWebGLArray **retval)
-{
- if (length == 0)
- return NS_ERROR_FAILURE;
-
- if (offset + length > mBuffer->capacity)
- return NS_ERROR_FAILURE;
-
- nsIWebGLArray *wga = new WebGLShortArray(mBuffer, offset, length);
- NS_ADDREF(*retval = wga);
- return NS_OK;
-}
-
-/* [IndexGetter] long get (in unsigned long index); */
-NS_IMETHODIMP WebGLShortArray::Get(PRUint32 index, PRInt32 *retval)
-{
- if (index >= mLength)
- return NS_ERROR_FAILURE;
-
- short *values = static_cast<short*>(mBuffer->data);
- *retval = values[index];
-
- return NS_OK;
-}
-
-void
-WebGLShortArray::Set(PRUint32 index, short value)
-{
- if (index >= mLength)
- return;
-
- short *values = static_cast<short*>(mBuffer->data);
- values[index] = value;
-}
-
-/* void set (); */
-NS_IMETHODIMP WebGLShortArray::Set()
-{
- NativeJSContext js;
- if (NS_FAILED(js.error))
- return js.error;
-
- if (js.argc < 1 || js.argc > 2)
- return NS_ERROR_DOM_SYNTAX_ERR;
-
- if (JSVAL_IS_NUMBER(js.argv[0])) {
- if (js.argc != 2)
- return NS_ERROR_DOM_SYNTAX_ERR;
-
- uint32 index;
- ::JS_ValueToECMAUint32(js.ctx, js.argv[0], &index);
-
- int32 value;
- ::JS_ValueToECMAInt32(js.ctx, js.argv[1], &value);
-
- if (index >= mLength)
- return NS_ERROR_FAILURE;
-
- Set(index, (short) value);
- } else {
- return NS_ERROR_NOT_IMPLEMENTED;
- }
-
- return NS_OK;
-}
-
-NS_IMETHODIMP_(PRUint32) WebGLShortArray::NativeType()
-{
- return mBuffer->type;
-}
-
-/* [noscript, notxpcom] voidPtr nativePointer (); */
-NS_IMETHODIMP_(void *) WebGLShortArray::NativePointer()
-{
- return mBuffer->data;
-}
-
-/* [noscript, notxpcom] unsigned long nativeSize (); */
-NS_IMETHODIMP_(PRUint32) WebGLShortArray::NativeSize()
-{
- return mBuffer->capacity;
-}
-
-/* [noscript, notxpcom] unsigned long nativeElementSize (); */
-NS_IMETHODIMP_(PRUint32) WebGLShortArray::NativeElementSize()
-{
- return mBuffer->ElementSize();
-}
-
-/* [noscript, notxpcom] unsigned long nativeCount (); */
-NS_IMETHODIMP_(PRUint32) WebGLShortArray::NativeCount()
-{
- return mBuffer->length;
-}
-
-// nsIXPCScriptable
-#define XPC_MAP_CLASSNAME WebGLShortArray
-#define XPC_MAP_QUOTED_CLASSNAME "WebGLShortArray"
-#define XPC_MAP_WANT_SETPROPERTY
-#define XPC_MAP_WANT_GETPROPERTY
-#define XPC_MAP_WANT_NEWRESOLVE
-#define XPC_MAP_FLAGS nsIXPCScriptable::USE_JSSTUB_FOR_ADDPROPERTY
-#include "xpc_map_end.h"
-
-PRBool WebGLShortArray::JSValToIndex(JSContext *cx, jsval id, uint32 *retval) {
- PRBool ok = PR_FALSE;
- uint32 index;
-
- if (JSVAL_IS_INT(id)) {
- index = JSVAL_TO_INT(id);
- ok = PR_TRUE;
- } else {
- ok = JS_ValueToECMAUint32(cx, id, &index);
- }
-
- if (!ok || index >= mLength)
- return PR_FALSE;
-
- *retval = index;
- return PR_TRUE;
-}
-
-NS_IMETHODIMP WebGLShortArray::GetProperty(nsIXPConnectWrappedNative *wrapper, JSContext * cx,
- JSObject * obj, jsval id, jsval * vp, PRBool *_retval)
-{
- uint32 index;
-
- if (!JSValToIndex(cx, id, &index)) {
- *_retval = PR_FALSE;
- return NS_ERROR_INVALID_ARG;
- }
-
- PRInt32 val;
- Get(index, &val);
- *_retval = JS_NewNumberValue(cx, val, vp);
-
- return NS_OK;
-}
-
-NS_IMETHODIMP WebGLShortArray::SetProperty(nsIXPConnectWrappedNative *wrapper, JSContext * cx,
- JSObject * obj, jsval id, jsval * vp, PRBool *_retval)
-{
- uint32 index;
- int32 val;
-
- if (!JSValToIndex(cx, id, &index)) {
- *_retval = PR_FALSE;
- return NS_ERROR_INVALID_ARG;
- }
-
- PRBool ok = PR_FALSE;
-
- if (JSVAL_IS_INT(*vp)) {
- val = JSVAL_TO_INT(*vp);
- ok = PR_TRUE;
- } else {
- ok = JS_ValueToECMAInt32(cx, *vp, &val);
- }
-
- if (!ok) {
- *_retval = PR_FALSE;
- return NS_ERROR_INVALID_ARG;
- }
-
- Set(index, (short) val);
- return NS_OK;
-}
-
-NS_IMETHODIMP WebGLShortArray::NewResolve(nsIXPConnectWrappedNative *wrapper, JSContext * cx,
- JSObject * obj, jsval id, PRUint32 flags, JSObject * *objp,
- PRBool *_retval)
-{
- uint32 index;
- PRBool ok = JSValToIndex(cx, id, &index);
-
- if (ok) {
- *_retval = PR_TRUE;
- *objp = obj;
- } else {
- *_retval = PR_FALSE;
- return NS_ERROR_FAILURE;
- }
-
- return NS_OK;
-}
-
-/*
- * WebGLUnsignedShortArray
- */
-
-nsresult
-NS_NewWebGLUnsignedShortArray(nsISupports **aResult)
-{
- nsIWebGLUnsignedShortArray *wgusa = new WebGLUnsignedShortArray();
- if (!wgusa)
- return NS_ERROR_OUT_OF_MEMORY;
-
- NS_ADDREF(*aResult = wgusa);
- return NS_OK;
-}
-
-WebGLUnsignedShortArray::WebGLUnsignedShortArray(PRUint32 length)
- : mOffset(0), mLength(length)
-{
- mBuffer = new WebGLArrayBuffer(length * sizeof(short));
-}
-
-WebGLUnsignedShortArray::WebGLUnsignedShortArray(WebGLArrayBuffer *buffer, PRUint32 offset, PRUint32 length)
- : mBuffer(buffer), mOffset(offset), mLength(length)
-{
-}
-
-WebGLUnsignedShortArray::WebGLUnsignedShortArray(JSContext *cx, JSObject *arrayObj, jsuint arrayLen)
- : mOffset(0), mLength(arrayLen)
-{
- mBuffer = new WebGLArrayBuffer();
- mBuffer->InitFromJSArray(LOCAL_GL_UNSIGNED_SHORT, 1, cx, arrayObj, arrayLen);
-}
-
-NS_IMETHODIMP
-WebGLUnsignedShortArray::Initialize(nsISupports *owner,
- JSContext *cx,
- JSObject *obj,
- PRUint32 argc,
- jsval *argv)
-{
- if (JSVAL_IS_NUMBER(argv[0])) {
- uint32 length;
- ::JS_ValueToECMAUint32(cx, argv[0], &length);
- mBuffer = new WebGLArrayBuffer();
- mBuffer->Prepare(LOCAL_GL_UNSIGNED_SHORT, 1, length);
- mBuffer->Zero();
- mLength = length;
- } else {
- JSObject *arrayObj;
- jsuint arrayLen;
- jsuint byteOffset = 0;
- jsuint length = 0;
-
- if (!::JS_ConvertArguments(cx, argc, argv, "o/uu", &arrayObj, &byteOffset, &length) ||
- arrayObj == NULL)
- {
- return NS_ERROR_DOM_SYNTAX_ERR;
- }
-
- if (::JS_IsArrayObject(cx, arrayObj) &&
- ::JS_GetArrayLength(cx, arrayObj, &arrayLen))
- {
- mBuffer = new WebGLArrayBuffer();
- mBuffer->InitFromJSArray(LOCAL_GL_UNSIGNED_SHORT, 1, cx, arrayObj, arrayLen);
- mLength = arrayLen;
- } else {
- nsCOMPtr<nsIWebGLArrayBuffer> canvasObj;
- nsresult rv;
- rv = nsContentUtils::XPConnect()->WrapJS(cx, arrayObj, NS_GET_IID(nsIWebGLArrayBuffer), getter_AddRefs(canvasObj));
- if (NS_FAILED(rv) || !canvasObj) {
- return NS_ERROR_DOM_SYNTAX_ERR;
- }
-
- mBuffer = canvasObj->GetNativeArrayBuffer();
-
- if (byteOffset % sizeof(short))
- return NS_ERROR_FAILURE;
-
- if ((byteOffset + (length * sizeof(short))) > mBuffer->capacity)
- return NS_ERROR_FAILURE;
-
- if (length > 0) {
- mLength = length;
- } else {
- if ((mBuffer->capacity - byteOffset) % sizeof(short))
- return NS_ERROR_FAILURE;
-
- mLength = (mBuffer->capacity - byteOffset) / sizeof(short);
- }
- }
- }
-
- return NS_OK;
-}
-
-/* readonly attribute nsIWebGLArrayBuffer buffer; */
-NS_IMETHODIMP WebGLUnsignedShortArray::GetBuffer(nsIWebGLArrayBuffer * *aBuffer)
-{
- NS_ADDREF(*aBuffer = mBuffer);
- return NS_OK;
-}
-
-/* readonly attribute unsigned long byteOffset; */
-NS_IMETHODIMP WebGLUnsignedShortArray::GetByteOffset(PRUint32 *aByteOffset)
-{
- *aByteOffset = mOffset;
- return NS_OK;
-}
-
-/* readonly attribute unsigned long byteLength; */
-NS_IMETHODIMP WebGLUnsignedShortArray::GetByteLength(PRUint32 *aByteLength)
-{
- *aByteLength = mLength * sizeof(short);
- return NS_OK;
-}
-
-/* attribute unsigned long length; */
-NS_IMETHODIMP WebGLUnsignedShortArray::GetLength(PRUint32 *aLength)
-{
- *aLength = mLength;
- return NS_OK;
-}
-
-/* unsigned long alignedSizeInBytes (); */
-NS_IMETHODIMP WebGLUnsignedShortArray::AlignedSizeInBytes(PRUint32 *retval)
-{
- *retval = mBuffer->capacity;
- return NS_OK;
-}
-
-/* nsIWebGLArray slice (in unsigned long offset, in unsigned long length); */
-NS_IMETHODIMP WebGLUnsignedShortArray::Slice(PRUint32 offset, PRUint32 length, nsIWebGLArray **retval)
-{
- if (length == 0)
- return NS_ERROR_FAILURE;
-
- if (offset + length > mBuffer->capacity)
- return NS_ERROR_FAILURE;
-
- nsIWebGLArray *wga = new WebGLUnsignedShortArray(mBuffer, offset, length);
- NS_ADDREF(*retval = wga);
- return NS_OK;
-}
-
-/* [IndexGetter] unsigned long get (in unsigned long index); */
-NS_IMETHODIMP WebGLUnsignedShortArray::Get(PRUint32 index, PRUint32 *retval)
-{
- if (index >= mLength)
- return NS_ERROR_FAILURE;
-
- unsigned short *values = static_cast<unsigned short*>(mBuffer->data);
- *retval = values[index];
-
- return NS_OK;
-}
-
-void
-WebGLUnsignedShortArray::Set(PRUint32 index, unsigned short value)
-{
- if (index >= mLength)
- return;
-
- unsigned short *values = static_cast<unsigned short*>(mBuffer->data);
- values[index] = value;
-}
-
-/* void set (); */
-NS_IMETHODIMP WebGLUnsignedShortArray::Set()
-{
- NativeJSContext js;
- if (NS_FAILED(js.error))
- return js.error;
-
- if (js.argc < 1 || js.argc > 2)
- return NS_ERROR_DOM_SYNTAX_ERR;
-
- if (JSVAL_IS_NUMBER(js.argv[0])) {
- if (js.argc != 2)
- return NS_ERROR_DOM_SYNTAX_ERR;
-
- uint32 index;
- ::JS_ValueToECMAUint32(js.ctx, js.argv[0], &index);
-
- uint32 value;
- ::JS_ValueToECMAUint32(js.ctx, js.argv[1], &value);
-
- if (index >= mLength)
- return NS_ERROR_FAILURE;
-
- Set(index, (unsigned short) value);
- } else {
- return NS_ERROR_NOT_IMPLEMENTED;
- }
-
- return NS_OK;
-}
-
-NS_IMETHODIMP_(PRUint32) WebGLUnsignedShortArray::NativeType()
-{
- return mBuffer->type;
-}
-
-/* [noscript, notxpcom] voidPtr nativePointer (); */
-NS_IMETHODIMP_(void *) WebGLUnsignedShortArray::NativePointer()
-{
- return mBuffer->data;
-}
-
-/* [noscript, notxpcom] unsigned long nativeSize (); */
-NS_IMETHODIMP_(PRUint32) WebGLUnsignedShortArray::NativeSize()
-{
- return mBuffer->capacity;
-}
-
-/* [noscript, notxpcom] unsigned long nativeElementSize (); */
-NS_IMETHODIMP_(PRUint32) WebGLUnsignedShortArray::NativeElementSize()
-{
- return mBuffer->ElementSize();
-}
-
-/* [noscript, notxpcom] unsigned long nativeCount (); */
-NS_IMETHODIMP_(PRUint32) WebGLUnsignedShortArray::NativeCount()
-{
- return mBuffer->length;
-}
-
-// nsIXPCScriptable
-#define XPC_MAP_CLASSNAME WebGLUnsignedShortArray
-#define XPC_MAP_QUOTED_CLASSNAME "WebGLUnsignedShortArray"
-#define XPC_MAP_WANT_SETPROPERTY
-#define XPC_MAP_WANT_GETPROPERTY
-#define XPC_MAP_WANT_NEWRESOLVE
-#define XPC_MAP_FLAGS nsIXPCScriptable::USE_JSSTUB_FOR_ADDPROPERTY
-#include "xpc_map_end.h"
-
-PRBool WebGLUnsignedShortArray::JSValToIndex(JSContext *cx, jsval id, uint32 *retval) {
- PRBool ok = PR_FALSE;
- uint32 index;
-
- if (JSVAL_IS_INT(id)) {
- index = JSVAL_TO_INT(id);
- ok = PR_TRUE;
- } else {
- ok = JS_ValueToECMAUint32(cx, id, &index);
- }
-
- if (!ok || index >= mLength)
- return PR_FALSE;
-
- *retval = index;
- return PR_TRUE;
-}
-
-NS_IMETHODIMP WebGLUnsignedShortArray::GetProperty(nsIXPConnectWrappedNative *wrapper, JSContext * cx,
- JSObject * obj, jsval id, jsval * vp, PRBool *_retval)
-{
- uint32 index;
-
- if (!JSValToIndex(cx, id, &index)) {
- *_retval = PR_FALSE;
- return NS_ERROR_INVALID_ARG;
- }
-
- PRUint32 val;
- Get(index, &val);
- *_retval = JS_NewNumberValue(cx, val, vp);
-
- return NS_OK;
-}
-
-NS_IMETHODIMP WebGLUnsignedShortArray::SetProperty(nsIXPConnectWrappedNative *wrapper, JSContext * cx,
- JSObject * obj, jsval id, jsval * vp, PRBool *_retval)
-{
- uint32 index;
- uint32 val;
-
- if (!JSValToIndex(cx, id, &index)) {
- *_retval = PR_FALSE;
- return NS_ERROR_INVALID_ARG;
- }
-
- PRBool ok = PR_FALSE;
-
- if (JSVAL_IS_INT(*vp)) {
- val = JSVAL_TO_INT(*vp);
- ok = PR_TRUE;
- } else {
- ok = JS_ValueToECMAUint32(cx, *vp, &val);
- }
-
- if (!ok) {
- *_retval = PR_FALSE;
- return NS_ERROR_INVALID_ARG;
- }
-
- Set(index, (unsigned short) val);
- return NS_OK;
-}
-
-NS_IMETHODIMP WebGLUnsignedShortArray::NewResolve(nsIXPConnectWrappedNative *wrapper, JSContext * cx,
- JSObject * obj, jsval id, PRUint32 flags, JSObject * *objp,
- PRBool *_retval)
-{
- uint32 index;
- PRBool ok = JSValToIndex(cx, id, &index);
-
- if (ok) {
- *_retval = PR_TRUE;
- *objp = obj;
- } else {
- *_retval = PR_FALSE;
- return NS_ERROR_FAILURE;
- }
-
- return NS_OK;
-}
-
-/*
- * WebGLIntArray
- */
-
-nsresult
-NS_NewWebGLIntArray(nsISupports **aResult)
-{
- nsIWebGLIntArray *wgia = new WebGLIntArray();
- if (!wgia)
- return NS_ERROR_OUT_OF_MEMORY;
-
- NS_ADDREF(*aResult = wgia);
- return NS_OK;
-}
-
-WebGLIntArray::WebGLIntArray(PRUint32 length)
- : mOffset(0), mLength(length)
-{
- mBuffer = new WebGLArrayBuffer(length * sizeof(int));
-}
-
-WebGLIntArray::WebGLIntArray(WebGLArrayBuffer *buffer, PRUint32 offset, PRUint32 length)
- : mBuffer(buffer), mOffset(offset), mLength(length)
-{
-}
-
-WebGLIntArray::WebGLIntArray(JSContext *cx, JSObject *arrayObj, jsuint arrayLen)
- : mOffset(0), mLength(arrayLen)
-{
- mBuffer = new WebGLArrayBuffer();
- mBuffer->InitFromJSArray(LOCAL_GL_INT, 1, cx, arrayObj, arrayLen);
-}
-
-NS_IMETHODIMP
-WebGLIntArray::Initialize(nsISupports *owner,
- JSContext *cx,
- JSObject *obj,
- PRUint32 argc,
- jsval *argv)
-{
- if (JSVAL_IS_NUMBER(argv[0])) {
- uint32 length;
- ::JS_ValueToECMAUint32(cx, argv[0], &length);
- mBuffer = new WebGLArrayBuffer();
- mBuffer->Prepare(LOCAL_GL_INT, 1, length);
- mBuffer->Zero();
- mLength = length;
- } else {
- JSObject *arrayObj;
- jsuint arrayLen;
- jsuint byteOffset = 0;
- jsuint length = 0;
-
- if (!::JS_ConvertArguments(cx, argc, argv, "o/uu", &arrayObj, &byteOffset, &length) ||
- arrayObj == NULL)
- {
- return NS_ERROR_DOM_SYNTAX_ERR;
- }
-
- if (::JS_IsArrayObject(cx, arrayObj) &&
- ::JS_GetArrayLength(cx, arrayObj, &arrayLen))
- {
- mBuffer = new WebGLArrayBuffer();
- mBuffer->InitFromJSArray(LOCAL_GL_INT, 1, cx, arrayObj, arrayLen);
- mLength = arrayLen;
- } else {
- nsCOMPtr<nsIWebGLArrayBuffer> canvasObj;
- nsresult rv;
- rv = nsContentUtils::XPConnect()->WrapJS(cx, arrayObj, NS_GET_IID(nsIWebGLArrayBuffer), getter_AddRefs(canvasObj));
- if (NS_FAILED(rv) || !canvasObj) {
- return NS_ERROR_DOM_SYNTAX_ERR;
- }
-
- mBuffer = canvasObj->GetNativeArrayBuffer();
-
- if (byteOffset % sizeof(int))
- return NS_ERROR_FAILURE;
-
- if ((byteOffset + (length * sizeof(int))) > mBuffer->capacity)
- return NS_ERROR_FAILURE;
-
- if (length > 0) {
- mLength = length;
- } else {
- if ((mBuffer->capacity - byteOffset) % sizeof(int))
- return NS_ERROR_FAILURE;
-
- mLength = (mBuffer->capacity - byteOffset) / sizeof(int);
- }
- }
- }
-
- return NS_OK;
-}
-
-/* readonly attribute nsIWebGLArrayBuffer buffer; */
-NS_IMETHODIMP WebGLIntArray::GetBuffer(nsIWebGLArrayBuffer * *aBuffer)
-{
- NS_ADDREF(*aBuffer = mBuffer);
- return NS_OK;
-}
-
-/* readonly attribute unsigned long byteOffset; */
-NS_IMETHODIMP WebGLIntArray::GetByteOffset(PRUint32 *aByteOffset)
-{
- *aByteOffset = mOffset;
- return NS_OK;
-}
-
-/* readonly attribute unsigned long byteLength; */
-NS_IMETHODIMP WebGLIntArray::GetByteLength(PRUint32 *aByteLength)
-{
- *aByteLength = mLength * sizeof(int);
- return NS_OK;
-}
-
-/* attribute unsigned long length; */
-NS_IMETHODIMP WebGLIntArray::GetLength(PRUint32 *aLength)
-{
- *aLength = mLength;
- return NS_OK;
-}
-
-/* unsigned long alignedSizeInBytes (); */
-NS_IMETHODIMP WebGLIntArray::AlignedSizeInBytes(PRUint32 *retval)
-{
- *retval = mBuffer->capacity;
- return NS_OK;
-}
-
-/* nsIWebGLArray slice (in unsigned long offset, in unsigned long length); */
-NS_IMETHODIMP WebGLIntArray::Slice(PRUint32 offset, PRUint32 length, nsIWebGLArray **retval)
-{
- if (length == 0)
- return NS_ERROR_FAILURE;
-
- if (offset + length > mBuffer->capacity)
- return NS_ERROR_FAILURE;
-
- nsIWebGLArray *wga = new WebGLIntArray(mBuffer, offset, length);
- NS_ADDREF(*retval = wga);
- return NS_OK;
-}
-
-/* [IndexGetter] long get (in unsigned long index); */
-NS_IMETHODIMP WebGLIntArray::Get(PRUint32 index, PRInt32 *retval)
-{
- if (index >= mLength)
- return NS_ERROR_FAILURE;
-
- int *values = static_cast<int*>(mBuffer->data);
- *retval = values[index];
-
- return NS_OK;
-}
-
-void
-WebGLIntArray::Set(PRUint32 index, int value)
-{
- if (index >= mLength)
- return;
-
- int *values = static_cast<int*>(mBuffer->data);
- values[index] = value;
-}
-
-/* void set (); */
-NS_IMETHODIMP WebGLIntArray::Set()
-{
- NativeJSContext js;
- if (NS_FAILED(js.error))
- return js.error;
-
- if (js.argc < 1 || js.argc > 2)
- return NS_ERROR_DOM_SYNTAX_ERR;
-
- if (JSVAL_IS_NUMBER(js.argv[0])) {
- if (js.argc != 2)
- return NS_ERROR_DOM_SYNTAX_ERR;
-
- uint32 index;
- ::JS_ValueToECMAUint32(js.ctx, js.argv[0], &index);
-
- int32 value;
- ::JS_ValueToECMAInt32(js.ctx, js.argv[1], &value);
-
- if (index >= mLength)
- return NS_ERROR_FAILURE;
-
- Set(index, value);
- } else {
- return NS_ERROR_NOT_IMPLEMENTED;
- }
-
- return NS_OK;
-}
-
-NS_IMETHODIMP_(PRUint32) WebGLIntArray::NativeType()
-{
- return mBuffer->type;
-}
-
-/* [noscript, notxpcom] voidPtr nativePointer (); */
-NS_IMETHODIMP_(void *) WebGLIntArray::NativePointer()
-{
- return mBuffer->data;
-}
-
-/* [noscript, notxpcom] unsigned long nativeSize (); */
-NS_IMETHODIMP_(PRUint32) WebGLIntArray::NativeSize()
-{
- return mBuffer->capacity;
-}
-
-/* [noscript, notxpcom] unsigned long nativeElementSize (); */
-NS_IMETHODIMP_(PRUint32) WebGLIntArray::NativeElementSize()
-{
- return mBuffer->ElementSize();
-}
-
-/* [noscript, notxpcom] unsigned long nativeCount (); */
-NS_IMETHODIMP_(PRUint32) WebGLIntArray::NativeCount()
-{
- return mBuffer->length;
-}
-
-// nsIXPCScriptable
-#define XPC_MAP_CLASSNAME WebGLIntArray
-#define XPC_MAP_QUOTED_CLASSNAME "WebGLIntArray"
-#define XPC_MAP_WANT_SETPROPERTY
-#define XPC_MAP_WANT_GETPROPERTY
-#define XPC_MAP_WANT_NEWRESOLVE
-#define XPC_MAP_FLAGS nsIXPCScriptable::USE_JSSTUB_FOR_ADDPROPERTY
-#include "xpc_map_end.h"
-
-PRBool WebGLIntArray::JSValToIndex(JSContext *cx, jsval id, uint32 *retval) {
- PRBool ok = PR_FALSE;
- uint32 index;
-
- if (JSVAL_IS_INT(id)) {
- index = JSVAL_TO_INT(id);
- ok = PR_TRUE;
- } else {
- ok = JS_ValueToECMAUint32(cx, id, &index);
- }
-
- if (!ok || index >= mLength)
- return PR_FALSE;
-
- *retval = index;
- return PR_TRUE;
-}
-
-NS_IMETHODIMP WebGLIntArray::GetProperty(nsIXPConnectWrappedNative *wrapper, JSContext * cx,
- JSObject * obj, jsval id, jsval * vp, PRBool *_retval)
-{
- uint32 index;
-
- if (!JSValToIndex(cx, id, &index)) {
- *_retval = PR_FALSE;
- return NS_ERROR_INVALID_ARG;
- }
-
- PRInt32 val;
- Get(index, &val);
- *_retval = JS_NewNumberValue(cx, val, vp);
-
- return NS_OK;
-}
-
-NS_IMETHODIMP WebGLIntArray::SetProperty(nsIXPConnectWrappedNative *wrapper, JSContext * cx,
- JSObject * obj, jsval id, jsval * vp, PRBool *_retval)
-{
- uint32 index;
- int32 val;
-
- if (!JSValToIndex(cx, id, &index)) {
- *_retval = PR_FALSE;
- return NS_ERROR_INVALID_ARG;
- }
-
- PRBool ok = PR_FALSE;
-
- if (JSVAL_IS_INT(*vp)) {
- val = JSVAL_TO_INT(*vp);
- ok = PR_TRUE;
- } else {
- ok = JS_ValueToECMAInt32(cx, *vp, &val);
- }
-
- if (!ok) {
- *_retval = PR_FALSE;
- return NS_ERROR_INVALID_ARG;
- }
-
- Set(index, val);
- return NS_OK;
-}
-
-NS_IMETHODIMP WebGLIntArray::NewResolve(nsIXPConnectWrappedNative *wrapper, JSContext * cx,
- JSObject * obj, jsval id, PRUint32 flags, JSObject * *objp,
- PRBool *_retval)
-{
- uint32 index;
- PRBool ok = JSValToIndex(cx, id, &index);
-
- if (ok) {
- *_retval = PR_TRUE;
- *objp = obj;
- } else {
- *_retval = PR_FALSE;
- return NS_ERROR_FAILURE;
- }
-
- return NS_OK;
-}
-
-/*
- * WebGLUnsignedIntArray
- */
-
-nsresult
-NS_NewWebGLUnsignedIntArray(nsISupports **aResult)
-{
- nsIWebGLUnsignedIntArray *wguia = new WebGLUnsignedIntArray();
- if (!wguia)
- return NS_ERROR_OUT_OF_MEMORY;
-
- NS_ADDREF(*aResult = wguia);
- return NS_OK;
-}
-
-WebGLUnsignedIntArray::WebGLUnsignedIntArray(PRUint32 length)
- : mOffset(0), mLength(length)
-{
- mBuffer = new WebGLArrayBuffer(length * sizeof(int));
-}
-
-WebGLUnsignedIntArray::WebGLUnsignedIntArray(WebGLArrayBuffer *buffer, PRUint32 offset, PRUint32 length)
- : mBuffer(buffer), mOffset(offset), mLength(length)
-{
-}
-
-WebGLUnsignedIntArray::WebGLUnsignedIntArray(JSContext *cx, JSObject *arrayObj, jsuint arrayLen)
- : mOffset(0), mLength(arrayLen)
-{
- mBuffer = new WebGLArrayBuffer();
- mBuffer->InitFromJSArray(LOCAL_GL_UNSIGNED_INT, 1, cx, arrayObj, arrayLen);
-}
-
-NS_IMETHODIMP
-WebGLUnsignedIntArray::Initialize(nsISupports *owner,
- JSContext *cx,
- JSObject *obj,
- PRUint32 argc,
- jsval *argv)
-{
- if (JSVAL_IS_NUMBER(argv[0])) {
- uint32 length;
- ::JS_ValueToECMAUint32(cx, argv[0], &length);
- mBuffer = new WebGLArrayBuffer();
- mBuffer->Prepare(LOCAL_GL_UNSIGNED_INT, 1, length);
- mBuffer->Zero();
- mLength = length;
- } else {
- JSObject *arrayObj;
- jsuint arrayLen;
- jsuint byteOffset = 0;
- jsuint length = 0;
-
- if (!::JS_ConvertArguments(cx, argc, argv, "o/uu", &arrayObj, &byteOffset, &length) ||
- arrayObj == NULL)
- {
- return NS_ERROR_DOM_SYNTAX_ERR;
- }
-
- if (::JS_IsArrayObject(cx, arrayObj) &&
- ::JS_GetArrayLength(cx, arrayObj, &arrayLen))
- {
- mBuffer = new WebGLArrayBuffer();
- mBuffer->InitFromJSArray(LOCAL_GL_UNSIGNED_INT, 1, cx, arrayObj, arrayLen);
- mLength = arrayLen;
- } else {
- nsCOMPtr<nsIWebGLArrayBuffer> canvasObj;
- nsresult rv;
- rv = nsContentUtils::XPConnect()->WrapJS(cx, arrayObj, NS_GET_IID(nsIWebGLArrayBuffer), getter_AddRefs(canvasObj));
- if (NS_FAILED(rv) || !canvasObj) {
- return NS_ERROR_DOM_SYNTAX_ERR;
- }
-
- mBuffer = canvasObj->GetNativeArrayBuffer();
-
- if (byteOffset % sizeof(int))
- return NS_ERROR_FAILURE;
-
- if ((byteOffset + (length * sizeof(int))) > mBuffer->capacity)
- return NS_ERROR_FAILURE;
-
- if (length > 0) {
- mLength = length;
- } else {
- if ((mBuffer->capacity - byteOffset) % sizeof(int))
- return NS_ERROR_FAILURE;
-
- mLength = (mBuffer->capacity - byteOffset) / sizeof(int);
- }
- }
- }
-
- return NS_OK;
-}
-
-/* readonly attribute nsIWebGLArrayBuffer buffer; */
-NS_IMETHODIMP WebGLUnsignedIntArray::GetBuffer(nsIWebGLArrayBuffer * *aBuffer)
-{
- NS_ADDREF(*aBuffer = mBuffer);
- return NS_OK;
-}
-
-/* readonly attribute unsigned long byteOffset; */
-NS_IMETHODIMP WebGLUnsignedIntArray::GetByteOffset(PRUint32 *aByteOffset)
-{
- *aByteOffset = mOffset;
- return NS_OK;
-}
-
-/* readonly attribute unsigned long byteLength; */
-NS_IMETHODIMP WebGLUnsignedIntArray::GetByteLength(PRUint32 *aByteLength)
-{
- *aByteLength = mLength * sizeof(int);
- return NS_OK;
-}
-
-/* attribute unsigned long length; */
-NS_IMETHODIMP WebGLUnsignedIntArray::GetLength(PRUint32 *aLength)
-{
- *aLength = mLength;
- return NS_OK;
-}
-
-/* unsigned long alignedSizeInBytes (); */
-NS_IMETHODIMP WebGLUnsignedIntArray::AlignedSizeInBytes(PRUint32 *retval)
-{
- *retval = mBuffer->capacity;
- return NS_OK;
-}
-
-/* nsIWebGLArray slice (in unsigned long offset, in unsigned long length); */
-NS_IMETHODIMP WebGLUnsignedIntArray::Slice(PRUint32 offset, PRUint32 length, nsIWebGLArray **retval)
-{
- if (length == 0)
- return NS_ERROR_FAILURE;
-
- if (offset + length > mBuffer->capacity)
- return NS_ERROR_FAILURE;
-
- nsIWebGLArray *wga = new WebGLUnsignedIntArray(mBuffer, offset, length);
- NS_ADDREF(*retval = wga);
- return NS_OK;
-}
-
-/* [IndexGetter] unsigned long get (in unsigned long index); */
-NS_IMETHODIMP WebGLUnsignedIntArray::Get(PRUint32 index, PRUint32 *retval)
-{
- if (index >= mLength)
- return NS_ERROR_FAILURE;
-
- unsigned int *values = static_cast<unsigned int*>(mBuffer->data);
- *retval = values[index];
-
- return NS_OK;
-}
-
-void
-WebGLUnsignedIntArray::Set(PRUint32 index, unsigned int value)
-{
- if (index >= mLength)
- return;
-
- unsigned int *values = static_cast<unsigned int*>(mBuffer->data);
- values[index] = value;
-}
-
-/* void set (); */
-NS_IMETHODIMP WebGLUnsignedIntArray::Set()
-{
- NativeJSContext js;
- if (NS_FAILED(js.error))
- return js.error;
-
- if (js.argc < 1 || js.argc > 2)
- return NS_ERROR_DOM_SYNTAX_ERR;
-
- if (JSVAL_IS_NUMBER(js.argv[0])) {
- if (js.argc != 2)
- return NS_ERROR_DOM_SYNTAX_ERR;
-
- uint32 index;
- ::JS_ValueToECMAUint32(js.ctx, js.argv[0], &index);
-
- uint32 value;
- ::JS_ValueToECMAUint32(js.ctx, js.argv[1], &value);
-
- if (index >= mLength)
- return NS_ERROR_FAILURE;
-
- Set(index, value);
- } else {
- return NS_ERROR_NOT_IMPLEMENTED;
- }
-
- return NS_OK;
-}
-
-NS_IMETHODIMP_(PRUint32) WebGLUnsignedIntArray::NativeType()
-{
- return mBuffer->type;
-}
-
-/* [noscript, notxpcom] voidPtr nativePointer (); */
-NS_IMETHODIMP_(void *) WebGLUnsignedIntArray::NativePointer()
-{
- return mBuffer->data;
-}
-
-/* [noscript, notxpcom] unsigned long nativeSize (); */
-NS_IMETHODIMP_(PRUint32) WebGLUnsignedIntArray::NativeSize()
-{
- return mBuffer->capacity;
-}
-
-/* [noscript, notxpcom] unsigned long nativeElementSize (); */
-NS_IMETHODIMP_(PRUint32) WebGLUnsignedIntArray::NativeElementSize()
-{
- return mBuffer->ElementSize();
-}
-
-/* [noscript, notxpcom] unsigned long nativeCount (); */
-NS_IMETHODIMP_(PRUint32) WebGLUnsignedIntArray::NativeCount()
-{
- return mBuffer->length;
-}
-
-// nsIXPCScriptable
-#define XPC_MAP_CLASSNAME WebGLUnsignedIntArray
-#define XPC_MAP_QUOTED_CLASSNAME "WebGLUnsignedIntArray"
-#define XPC_MAP_WANT_SETPROPERTY
-#define XPC_MAP_WANT_GETPROPERTY
-#define XPC_MAP_WANT_NEWRESOLVE
-#define XPC_MAP_FLAGS nsIXPCScriptable::USE_JSSTUB_FOR_ADDPROPERTY
-#include "xpc_map_end.h"
-
-PRBool WebGLUnsignedIntArray::JSValToIndex(JSContext *cx, jsval id, uint32 *retval) {
- PRBool ok = PR_FALSE;
- uint32 index;
-
- if (JSVAL_IS_INT(id)) {
- index = JSVAL_TO_INT(id);
- ok = PR_TRUE;
- } else {
- ok = JS_ValueToECMAUint32(cx, id, &index);
- }
-
- if (!ok || index >= mLength)
- return PR_FALSE;
-
- *retval = index;
- return PR_TRUE;
-}
-
-NS_IMETHODIMP WebGLUnsignedIntArray::GetProperty(nsIXPConnectWrappedNative *wrapper, JSContext * cx,
- JSObject * obj, jsval id, jsval * vp, PRBool *_retval)
-{
- uint32 index;
-
- if (!JSValToIndex(cx, id, &index)) {
- *_retval = PR_FALSE;
- return NS_ERROR_INVALID_ARG;
- }
-
- PRUint32 val;
- Get(index, &val);
- *_retval = JS_NewNumberValue(cx, val, vp);
-
- return NS_OK;
-}
-
-NS_IMETHODIMP WebGLUnsignedIntArray::SetProperty(nsIXPConnectWrappedNative *wrapper, JSContext * cx,
- JSObject * obj, jsval id, jsval * vp, PRBool *_retval)
-{
- uint32 index;
- uint32 val;
-
- if (!JSValToIndex(cx, id, &index)) {
- *_retval = PR_FALSE;
- return NS_ERROR_INVALID_ARG;
- }
-
- PRBool ok = PR_FALSE;
-
- if (JSVAL_IS_INT(*vp)) {
- val = JSVAL_TO_INT(*vp);
- ok = PR_TRUE;
- } else {
- ok = JS_ValueToECMAUint32(cx, *vp, &val);
- }
-
- if (!ok) {
- *_retval = PR_FALSE;
- return NS_ERROR_INVALID_ARG;
- }
-
- Set(index, val);
- return NS_OK;
-}
-
-NS_IMETHODIMP WebGLUnsignedIntArray::NewResolve(nsIXPConnectWrappedNative *wrapper, JSContext * cx,
- JSObject * obj, jsval id, PRUint32 flags, JSObject * *objp,
- PRBool *_retval)
-{
- uint32 index;
- PRBool ok = JSValToIndex(cx, id, &index);
-
- if (ok) {
- *_retval = PR_TRUE;
- *objp = obj;
- } else {
- *_retval = PR_FALSE;
- return NS_ERROR_FAILURE;
- }
-
- return NS_OK;
-}
-
-
-/*
- * XPCOM AddRef/Release/QI
- */
-NS_IMPL_ADDREF(WebGLArrayBuffer)
-NS_IMPL_RELEASE(WebGLArrayBuffer)
-
-NS_INTERFACE_MAP_BEGIN(WebGLArrayBuffer)
- NS_INTERFACE_MAP_ENTRY(nsIWebGLArrayBuffer)
- NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIWebGLArrayBuffer)
- NS_INTERFACE_MAP_ENTRY(nsIJSNativeInitializer)
- NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(WebGLArrayBuffer)
-NS_INTERFACE_MAP_END
-
-NS_IMPL_ADDREF(WebGLFloatArray)
-NS_IMPL_RELEASE(WebGLFloatArray)
-
-NS_INTERFACE_MAP_BEGIN(WebGLFloatArray)
- NS_INTERFACE_MAP_ENTRY(nsIWebGLArray)
- NS_INTERFACE_MAP_ENTRY(nsIWebGLFloatArray)
- NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIWebGLFloatArray)
- NS_INTERFACE_MAP_ENTRY(nsIJSNativeInitializer)
- NS_INTERFACE_MAP_ENTRY(nsIXPCScriptable)
- NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(WebGLFloatArray)
-NS_INTERFACE_MAP_END
-
-NS_IMPL_ADDREF(WebGLByteArray)
-NS_IMPL_RELEASE(WebGLByteArray)
-
-NS_INTERFACE_MAP_BEGIN(WebGLByteArray)
- NS_INTERFACE_MAP_ENTRY(nsIWebGLArray)
- NS_INTERFACE_MAP_ENTRY(nsIWebGLByteArray)
- NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIWebGLByteArray)
- NS_INTERFACE_MAP_ENTRY(nsIJSNativeInitializer)
- NS_INTERFACE_MAP_ENTRY(nsIXPCScriptable)
- NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(WebGLByteArray)
-NS_INTERFACE_MAP_END
-
-NS_IMPL_ADDREF(WebGLUnsignedByteArray)
-NS_IMPL_RELEASE(WebGLUnsignedByteArray)
-
-NS_INTERFACE_MAP_BEGIN(WebGLUnsignedByteArray)
- NS_INTERFACE_MAP_ENTRY(nsIWebGLArray)
- NS_INTERFACE_MAP_ENTRY(nsIWebGLUnsignedByteArray)
- NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIWebGLUnsignedByteArray)
- NS_INTERFACE_MAP_ENTRY(nsIJSNativeInitializer)
- NS_INTERFACE_MAP_ENTRY(nsIXPCScriptable)
- NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(WebGLUnsignedByteArray)
-NS_INTERFACE_MAP_END
-
-NS_IMPL_ADDREF(WebGLShortArray)
-NS_IMPL_RELEASE(WebGLShortArray)
-
-NS_INTERFACE_MAP_BEGIN(WebGLShortArray)
- NS_INTERFACE_MAP_ENTRY(nsIWebGLArray)
- NS_INTERFACE_MAP_ENTRY(nsIWebGLShortArray)
- NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIWebGLShortArray)
- NS_INTERFACE_MAP_ENTRY(nsIJSNativeInitializer)
- NS_INTERFACE_MAP_ENTRY(nsIXPCScriptable)
- NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(WebGLShortArray)
-NS_INTERFACE_MAP_END
-
-NS_IMPL_ADDREF(WebGLUnsignedShortArray)
-NS_IMPL_RELEASE(WebGLUnsignedShortArray)
-
-NS_INTERFACE_MAP_BEGIN(WebGLUnsignedShortArray)
- NS_INTERFACE_MAP_ENTRY(nsIWebGLArray)
- NS_INTERFACE_MAP_ENTRY(nsIWebGLUnsignedShortArray)
- NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIWebGLUnsignedShortArray)
- NS_INTERFACE_MAP_ENTRY(nsIJSNativeInitializer)
- NS_INTERFACE_MAP_ENTRY(nsIXPCScriptable)
- NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(WebGLUnsignedShortArray)
-NS_INTERFACE_MAP_END
-
-NS_IMPL_ADDREF(WebGLIntArray)
-NS_IMPL_RELEASE(WebGLIntArray)
-
-NS_INTERFACE_MAP_BEGIN(WebGLIntArray)
- NS_INTERFACE_MAP_ENTRY(nsIWebGLArray)
- NS_INTERFACE_MAP_ENTRY(nsIWebGLIntArray)
- NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIWebGLIntArray)
- NS_INTERFACE_MAP_ENTRY(nsIJSNativeInitializer)
- NS_INTERFACE_MAP_ENTRY(nsIXPCScriptable)
- NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(WebGLIntArray)
-NS_INTERFACE_MAP_END
-
-NS_IMPL_ADDREF(WebGLUnsignedIntArray)
-NS_IMPL_RELEASE(WebGLUnsignedIntArray)
-
-NS_INTERFACE_MAP_BEGIN(WebGLUnsignedIntArray)
- NS_INTERFACE_MAP_ENTRY(nsIWebGLArray)
- NS_INTERFACE_MAP_ENTRY(nsIWebGLUnsignedIntArray)
- NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIWebGLUnsignedIntArray)
- NS_INTERFACE_MAP_ENTRY(nsIJSNativeInitializer)
- NS_INTERFACE_MAP_ENTRY(nsIXPCScriptable)
- NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(WebGLUnsignedIntArray)
-NS_INTERFACE_MAP_END
deleted file mode 100644
--- a/dom/interfaces/canvas/nsICanvasRenderingContextGLWeb20.idl
+++ /dev/null
@@ -1,249 +0,0 @@
-/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* ***** BEGIN LICENSE BLOCK *****
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is canvas 3D.
- *
- * The Initial Developer of the Original Code is
- * Mozilla Corporation.
- * Portions created by the Initial Developer are Copyright (C) 2006
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- * Vladimir Vukicevic <vladimir@pobox.com>
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either of the GNU General Public License Version 2 or later (the "GPL"),
- * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- * ***** END LICENSE BLOCK ***** */
-
-#include "nsICanvasRenderingContextGL.idl"
-#include "nsICanvasRenderingContextGLBuffer.idl"
-
-interface nsIDOMHTMLElement;
-
-[scriptable, uuid(209a9c93-495e-4085-a3e4-29354b404cc4)]
-interface nsICanvasRenderingContextGLWeb20 : nsICanvasRenderingContextGL
-{
- void activeTexture (in PRUint32 texture);
-
- void attachShader (in PRUint32 program, in PRUint32 shader);
- void bindAttribLocation (in PRUint32 program, in PRUint32 index, in string name);
-
- void bindBuffer (in PRUint32 target, in PRUint32 buffer);
- void bindTexture (in PRUint32 target, in PRUint32 texid);
-
- void blendColor (in float red, in float green, in float blue, in float alpha);
- void blendEquation (in PRUint32 mode);
- void blendEquationSeparate (in PRUint32 modeRGB, in PRUint32 modeAlpha);
- void blendFunc (in PRUint32 sfactor, in PRUint32 dfactor);
- void blendFuncSeparate (in PRUint32 srcRGB, in PRUint32 dstRGB, in PRUint32 srcAlpha, in PRUint32 dstAlpha);
-
-
- void bufferData (/*in PRUint32 target, in object[] array, in PRUint32 type, in PRUint32 usage*/);
- void bufferSubData (/*in PRUint32 target, in PRUint32 offset, in object[] array, in PRUint32 type*/);
-
- void clear (in PRUint32 mask);
- void clearColor (in float red, in float green, in float blue, in float alpha);
- void clearDepth (in float depth);
- void clearStencil (in PRInt32 s);
- void colorMask (in boolean red, in boolean green, in boolean blue, in boolean alpha);
- // NO compressedTexImage2D
- // NO compressedTexSubImage2D
-
- void copyTexImage2D (in PRUint32 target, in PRInt32 level, in PRUint32 internalFormat, in PRInt32 x, in PRInt32 y, in PRUint32 width, in PRUint32 height, in PRInt32 border);
- void copyTexSubImage2D (in PRUint32 target, in PRInt32 level, in PRInt32 xoffset, in PRInt32 yoffset, in PRInt32 x, in PRInt32 y, in PRUint32 width, in PRUint32 height);
-
- PRUint32 createProgram ();
- PRUint32 createShader (in PRUint32 type);
- void cullFace (in PRUint32 face);
-
- void deleteBuffers (/*in PRUint32[] buffers*/);
- void deleteTextures (/*in PRUint32[] textures*/);
- void deleteProgram (in PRUint32 program);
- void deleteShader (in PRUint32 shader);
- void detachShader (in PRUint32 program, in PRUint32 shader);
- void depthFunc (in PRUint32 func);
- void depthMask (in boolean flag);
- void depthRange (in float zNear, in float zFar);
- void disable (in PRUint32 mode);
- void disableVertexAttribArray (in PRUint32 index);
- void drawArrays (in PRUint32 mode, in PRUint32 first, in PRUint32 count);
- void drawElements (/*in PRUint32 mode, in PRUint32 count, in PRUint32 type, in PRUint32[] indices*/);
- void enable (in PRUint32 mode);
- void enableVertexAttribArray (in PRUint32 index);
- void finish();
- void flush();
- void frontFace (in PRUint32 face);
-
- // getActiveAttrib returns an object: { name: "..", size: .., type: .. }
- void getActiveAttrib (in PRUint32 program, in PRUint32 index);
-
- // getActiveUniform returns an object: { name: "..", size: .., type: .. }
- void getActiveUniform (in PRUint32 program, in PRUint32 index);
-
- // returns an array of shader IDs
- void getAttachedShaders (in PRUint32 program);
-
- PRInt32 getAttribLocation (in PRUint32 program, in string name);
-
- // getBooleanv, getIntegerv, getFloatv, getDoublev, getString
- // are all rolled into a single function that uses scriptable
- // magic to return the right type of jsobj. Colors are always
- // returned as normalized floats (0.0 .. 1.0).
-
- void getParameter (in PRUint32 pname);
- void getBufferParameter (in PRUint32 target, in PRUint32 pname);
-
- void genBuffers (in PRUint32 n);
- void genTextures (in PRUint32 n);
-
- void generateMipmap (in PRUint32 target);
-
- PRUint32 getError ();
-
- void getProgramParameter (in PRUint32 program, in PRUint32 pname);
-
- string getProgramInfoLog (in PRUint32 program);
-
- void getTexParameter(in PRUint32 target, in PRUint32 pname);
-
- void getUniform (in PRUint32 program, in PRUint32 location);
- PRInt32 getUniformLocation (in PRUint32 program, in string name);
-
- void getVertexAttrib (in PRUint32 index, in PRUint32 pname);
- // NO void getVertexAttribPointerv
-
- void hint (in PRUint32 target, in PRUint32 mode);
-
- boolean isBuffer (in PRUint32 buffer);
- boolean isEnabled (in PRUint32 cap);
- boolean isProgram (in PRUint32 program);
- boolean isShader (in PRUint32 shader);
- boolean isTexture (in PRUint32 texture);
-
- void lineWidth (in float width);
- void linkProgram (in PRUint32 program);
-
- // NO pixelStore
-
- void pixelStore (in PRUint32 pname, in PRInt32 param);
-
- void polygonOffset (in float factor, in float units);
-
- void readPixels (in PRUint32 x, in PRUint32 y, in PRUint32 width, in PRUint32 height, in PRUint32 format, in PRUint32 type);
-
- void sampleCoverage (in float value, in boolean invert);
- void scissor (in PRInt32 x, in PRInt32 y, in PRInt32 width, in PRInt32 height);
- void stencilFunc (in PRUint32 func, in PRInt32 ref, in PRUint32 mask);
- void stencilFuncSeparate (in PRUint32 face, in PRUint32 func, in PRInt32 ref, in PRUint32 mask);
- void stencilMask (in PRUint32 mask);
- void stencilMaskSeparate (in PRUint32 face, in PRUint32 mask);
- void stencilOp (in PRUint32 fail, in PRUint32 zfail, in PRUint32 zpass);
- void stencilOpSeparate (in PRUint32 face, in PRUint32 fail, in PRUint32 zfail, in PRUint32 zpass);
-
- void texSubImage2D ();
- void texImage2D ();
- void texSubImage2DHTML (in PRUint32 target, in PRUint32 level, in PRInt32 x, in PRInt32 y, in nsIDOMHTMLElement imageOrCanvas);
- void texImage2DHTML (in PRUint32 target, in PRUint32 level, in nsIDOMHTMLElement imageOrCanvas);
-
- void texParameter();
-
- // YES void texSubImage2DHTML (...);
-
- void uniform1i(in PRUint32 id, in PRInt32 x);
- void uniform2i(in PRUint32 id, in PRInt32 x, in PRInt32 y);
- void uniform3i(in PRUint32 id, in PRInt32 x, in PRInt32 y, in PRInt32 z);
- void uniform4i(in PRUint32 id, in PRInt32 x, in PRInt32 y, in PRInt32 z, in PRInt32 w);
-
- void uniform1iv(/*in PRUint32 id, in int[] array */);
- void uniform2iv(/*in PRUint32 id, in int[] array */);
- void uniform3iv(/*in PRUint32 id, in int[] array */);
- void uniform4iv(/*in PRUint32 id, in int[] array */);
-
- void uniform1f(in PRUint32 id, in float x);
- void uniform2f(in PRUint32 id, in float x, in float y);
- void uniform3f(in PRUint32 id, in float x, in float y, in float z);
- void uniform4f(in PRUint32 id, in float x, in float y, in float z, in float w);
-
- void uniform1fv(/*in PRUint32 id, in float[] array */);
- void uniform2fv(/*in PRUint32 id, in float[] array */);
- void uniform3fv(/*in PRUint32 id, in float[] array */);
- void uniform4fv(/*in PRUint32 id, in float[] array */);
-
- void uniformMatrix2fv(/*in PRUint32 id, in float[] array */);
- void uniformMatrix3fv(/*in PRUint32 id, in float[] array */);
- void uniformMatrix4fv(/*in PRUint32 id, in float[] array */);
-
- void useProgram (in PRUint32 program);
- void validateProgram (in PRUint32 program);
-
- void vertexAttrib1f(in PRUint32 id, in float x);
- void vertexAttrib2f(in PRUint32 id, in float x, in float y);
- void vertexAttrib3f(in PRUint32 id, in float x, in float y, in float z);
- void vertexAttrib4f(in PRUint32 id, in float x, in float y, in float z, in float w);
-
- void vertexAttrib1fv(/*in PRUint32 id, in float[] array*/);
- void vertexAttrib2fv(/*in PRUint32 id, in float[] array*/);
- void vertexAttrib3fv(/*in PRUint32 id, in float[] array*/);
- void vertexAttrib4fv(/*in PRUint32 id, in float[] array*/);
-
- void vertexAttribPointer (/*in PRUint32 index, in PRInt32 size, in PRUint32 type, in PRBool normalized, in PRUint32 stride, in Object[] array*/);
-
- void viewport (in PRInt32 x, in PRInt32 y, in PRInt32 width, in PRInt32 height);
-
- void compileShader (in PRUint32 shader);
- void getShaderParameter (in PRUint32 shader, in PRUint32 pname);
- string getShaderInfoLog (in PRUint32 shader);
- string getShaderSource (in PRUint32 shader);
- void shaderSource(in PRUint32 shader, in string source);
-
- void getImageData (in PRUint32 x, in PRUint32 y, in PRUint32 width, in PRUint32 height);
-
- //
- // framebuffer_object methods
- //
-
- void bindRenderbuffer (in PRUint32 target, in PRUint32 renderbuffer);
- boolean isRenderbuffer (in PRUint32 renderbuffer);
- void deleteRenderbuffers (/*in PRUint32[] renderbuffers*/);
- void genRenderbuffers (in PRUint32 n);
-
- void renderbufferStorage (in PRUint32 target, in PRUint32 internalFormat, in PRUint32 width, in PRUint32 height);
-
- void getRenderbufferParameter (in PRUint32 target, in PRUint32 pname);
-
- void bindFramebuffer (in PRUint32 target, in PRUint32 framebuffer);
- boolean isFramebuffer (in PRUint32 framebuffer);
- void deleteFramebuffers (/*in PRUint32[] framebuffers*/);
- void genFramebuffers (in PRUint32 n);
-
- PRUint32 checkFramebufferStatus (in PRUint32 target);
-
- void framebufferTexture2D (in PRUint32 target, in PRUint32 attachmentPoint, in PRUint32 textureTarget, in PRUint32 texture, in PRInt32 level);
-
- void framebufferRenderbuffer (in PRUint32 target, in PRUint32 attachmentPoint, in PRUint32 renderbufferTarget, in PRUint32 renderbuffer);
-
- void getFramebufferAttachmentParameter (in PRUint32 target, in PRUint32 attachment, in PRUint32 pname);
-
-};
-