Bug 749535 - Part 2: Rewrite dom::TypedArray to use JS_UnwrapObjectAs*Array(). (r=bz)

This commit is contained in:
Eric Faust 2012-07-31 20:45:20 -07:00
Родитель c60ea1616e
Коммит 62ec8929cd
6 изменённых файлов: 102 добавлений и 84 удалений

Просмотреть файл

@ -2603,8 +2603,8 @@ GetRequestBody(ArrayBuffer* aArrayBuffer, nsIInputStream** aResult,
aContentType.SetIsVoid(true);
aCharset.Truncate();
PRInt32 length = aArrayBuffer->mLength;
char* data = reinterpret_cast<char*>(aArrayBuffer->mData);
PRInt32 length = aArrayBuffer->Length();
char* data = reinterpret_cast<char*>(aArrayBuffer->Data());
nsCOMPtr<nsIInputStream> stream;
nsresult rv = NS_NewByteInputStream(getter_AddRefs(stream), data, length,

Просмотреть файл

@ -892,7 +892,7 @@ public:
WebGLfloat z, WebGLfloat w);
void Uniform1iv(WebGLUniformLocation* location, dom::Int32Array& arr) {
Uniform1iv_base(location, arr.mLength, arr.mData);
Uniform1iv_base(location, arr.Length(), arr.Data());
}
void Uniform1iv(WebGLUniformLocation* location,
const dom::Sequence<WebGLint>& arr) {
@ -902,7 +902,7 @@ public:
const WebGLint* data);
void Uniform2iv(WebGLUniformLocation* location, dom::Int32Array& arr) {
Uniform2iv_base(location, arr.mLength, arr.mData);
Uniform2iv_base(location, arr.Length(), arr.Data());
}
void Uniform2iv(WebGLUniformLocation* location,
const dom::Sequence<WebGLint>& arr) {
@ -912,7 +912,7 @@ public:
const WebGLint* data);
void Uniform3iv(WebGLUniformLocation* location, dom::Int32Array& arr) {
Uniform3iv_base(location, arr.mLength, arr.mData);
Uniform3iv_base(location, arr.Length(), arr.Data());
}
void Uniform3iv(WebGLUniformLocation* location,
const dom::Sequence<WebGLint>& arr) {
@ -922,7 +922,7 @@ public:
const WebGLint* data);
void Uniform4iv(WebGLUniformLocation* location, dom::Int32Array& arr) {
Uniform4iv_base(location, arr.mLength, arr.mData);
Uniform4iv_base(location, arr.Length(), arr.Data());
}
void Uniform4iv(WebGLUniformLocation* location,
const dom::Sequence<WebGLint>& arr) {
@ -932,7 +932,7 @@ public:
const WebGLint* data);
void Uniform1fv(WebGLUniformLocation* location, dom::Float32Array& arr) {
Uniform1fv_base(location, arr.mLength, arr.mData);
Uniform1fv_base(location, arr.Length(), arr.Data());
}
void Uniform1fv(WebGLUniformLocation* location,
const dom::Sequence<WebGLfloat>& arr) {
@ -942,7 +942,7 @@ public:
const WebGLfloat* data);
void Uniform2fv(WebGLUniformLocation* location, dom::Float32Array& arr) {
Uniform2fv_base(location, arr.mLength, arr.mData);
Uniform2fv_base(location, arr.Length(), arr.Data());
}
void Uniform2fv(WebGLUniformLocation* location,
const dom::Sequence<WebGLfloat>& arr) {
@ -952,7 +952,7 @@ public:
const WebGLfloat* data);
void Uniform3fv(WebGLUniformLocation* location, dom::Float32Array& arr) {
Uniform3fv_base(location, arr.mLength, arr.mData);
Uniform3fv_base(location, arr.Length(), arr.Data());
}
void Uniform3fv(WebGLUniformLocation* location,
const dom::Sequence<WebGLfloat>& arr) {
@ -962,7 +962,7 @@ public:
const WebGLfloat* data);
void Uniform4fv(WebGLUniformLocation* location, dom::Float32Array& arr) {
Uniform4fv_base(location, arr.mLength, arr.mData);
Uniform4fv_base(location, arr.Length(), arr.Data());
}
void Uniform4fv(WebGLUniformLocation* location,
const dom::Sequence<WebGLfloat>& arr) {
@ -974,7 +974,7 @@ public:
void UniformMatrix2fv(WebGLUniformLocation* location,
WebGLboolean transpose,
dom::Float32Array &value) {
UniformMatrix2fv_base(location, transpose, value.mLength, value.mData);
UniformMatrix2fv_base(location, transpose, value.Length(), value.Data());
}
void UniformMatrix2fv(WebGLUniformLocation* location,
WebGLboolean transpose,
@ -989,7 +989,7 @@ public:
void UniformMatrix3fv(WebGLUniformLocation* location,
WebGLboolean transpose,
dom::Float32Array &value) {
UniformMatrix3fv_base(location, transpose, value.mLength, value.mData);
UniformMatrix3fv_base(location, transpose, value.Length(), value.Data());
}
void UniformMatrix3fv(WebGLUniformLocation* location,
WebGLboolean transpose,
@ -1004,7 +1004,7 @@ public:
void UniformMatrix4fv(WebGLUniformLocation* location,
WebGLboolean transpose,
dom::Float32Array &value) {
UniformMatrix4fv_base(location, transpose, value.mLength, value.mData);
UniformMatrix4fv_base(location, transpose, value.Length(), value.Data());
}
void UniformMatrix4fv(WebGLUniformLocation* location,
WebGLboolean transpose,
@ -1027,7 +1027,7 @@ public:
WebGLfloat x2, WebGLfloat x3);
void VertexAttrib1fv(WebGLuint idx, dom::Float32Array &arr) {
VertexAttrib1fv_base(idx, arr.mLength, arr.mData);
VertexAttrib1fv_base(idx, arr.Length(), arr.Data());
}
void VertexAttrib1fv(WebGLuint idx, const dom::Sequence<WebGLfloat>& arr) {
VertexAttrib1fv_base(idx, arr.Length(), arr.Elements());
@ -1036,7 +1036,7 @@ public:
const WebGLfloat* ptr);
void VertexAttrib2fv(WebGLuint idx, dom::Float32Array &arr) {
VertexAttrib2fv_base(idx, arr.mLength, arr.mData);
VertexAttrib2fv_base(idx, arr.Length(), arr.Data());
}
void VertexAttrib2fv(WebGLuint idx, const dom::Sequence<WebGLfloat>& arr) {
VertexAttrib2fv_base(idx, arr.Length(), arr.Elements());
@ -1045,7 +1045,7 @@ public:
const WebGLfloat* ptr);
void VertexAttrib3fv(WebGLuint idx, dom::Float32Array &arr) {
VertexAttrib3fv_base(idx, arr.mLength, arr.mData);
VertexAttrib3fv_base(idx, arr.Length(), arr.Data());
}
void VertexAttrib3fv(WebGLuint idx, const dom::Sequence<WebGLfloat>& arr) {
VertexAttrib3fv_base(idx, arr.Length(), arr.Elements());
@ -1054,7 +1054,7 @@ public:
const WebGLfloat* ptr);
void VertexAttrib4fv(WebGLuint idx, dom::Float32Array &arr) {
VertexAttrib4fv_base(idx, arr.mLength, arr.mData);
VertexAttrib4fv_base(idx, arr.Length(), arr.Data());
}
void VertexAttrib4fv(WebGLuint idx, const dom::Sequence<WebGLfloat>& arr) {
VertexAttrib4fv_base(idx, arr.Length(), arr.Elements());

Просмотреть файл

@ -546,16 +546,16 @@ WebGLContext::BufferData(WebGLenum target, ArrayBuffer *data, WebGLenum usage)
MakeContextCurrent();
GLenum error = CheckedBufferData(target, data->mLength, data->mData, usage);
GLenum error = CheckedBufferData(target, data->Length(), data->Data(), usage);
if (error) {
GenerateWarning("bufferData generated error %s", ErrorName(error));
return;
}
boundBuffer->SetByteLength(data->mLength);
boundBuffer->SetByteLength(data->Length());
boundBuffer->InvalidateCachedMaxElements();
if (!boundBuffer->CopyDataIfElementArray(data->mData))
if (!boundBuffer->CopyDataIfElementArray(data->Data()))
return ErrorOutOfMemory("bufferData: out of memory");
}
@ -583,15 +583,15 @@ WebGLContext::BufferData(WebGLenum target, ArrayBufferView& data, WebGLenum usag
MakeContextCurrent();
GLenum error = CheckedBufferData(target, data.mLength, data.mData, usage);
GLenum error = CheckedBufferData(target, data.Length(), data.Data(), usage);
if (error) {
GenerateWarning("bufferData generated error %s", ErrorName(error));
return;
}
boundBuffer->SetByteLength(data.mLength);
boundBuffer->SetByteLength(data.Length());
boundBuffer->InvalidateCachedMaxElements();
if (!boundBuffer->CopyDataIfElementArray(data.mData))
if (!boundBuffer->CopyDataIfElementArray(data.Data()))
return ErrorOutOfMemory("bufferData: out of memory");
}
@ -654,7 +654,7 @@ WebGLContext::BufferSubData(GLenum target, WebGLsizeiptr byteOffset,
if (!boundBuffer)
return ErrorInvalidOperation("bufferData: no buffer bound!");
CheckedUint32 checked_neededByteLength = CheckedUint32(byteOffset) + data->mLength;
CheckedUint32 checked_neededByteLength = CheckedUint32(byteOffset) + data->Length();
if (!checked_neededByteLength.isValid())
return ErrorInvalidOperation("bufferSubData: integer overflow computing the needed byte length");
@ -664,10 +664,10 @@ WebGLContext::BufferSubData(GLenum target, WebGLsizeiptr byteOffset,
MakeContextCurrent();
boundBuffer->CopySubDataIfElementArray(byteOffset, data->mLength, data->mData);
boundBuffer->CopySubDataIfElementArray(byteOffset, data->Length(), data->Data());
boundBuffer->InvalidateCachedMaxElements();
gl->fBufferSubData(target, byteOffset, data->mLength, data->mData);
gl->fBufferSubData(target, byteOffset, data->Length(), data->Data());
}
void
@ -693,7 +693,7 @@ WebGLContext::BufferSubData(WebGLenum target, WebGLsizeiptr byteOffset,
if (!boundBuffer)
return ErrorInvalidOperation("bufferSubData: no buffer bound!");
CheckedUint32 checked_neededByteLength = CheckedUint32(byteOffset) + data.mLength;
CheckedUint32 checked_neededByteLength = CheckedUint32(byteOffset) + data.Length();
if (!checked_neededByteLength.isValid())
return ErrorInvalidOperation("bufferSubData: integer overflow computing the needed byte length");
@ -703,10 +703,10 @@ WebGLContext::BufferSubData(WebGLenum target, WebGLsizeiptr byteOffset,
MakeContextCurrent();
boundBuffer->CopySubDataIfElementArray(byteOffset, data.mLength, data.mData);
boundBuffer->CopySubDataIfElementArray(byteOffset, data.Length(), data.Data());
boundBuffer->InvalidateCachedMaxElements();
gl->fBufferSubData(target, byteOffset, data.mLength, data.mData);
gl->fBufferSubData(target, byteOffset, data.Length(), data.Data());
}
NS_IMETHODIMP
@ -3876,9 +3876,9 @@ WebGLContext::ReadPixels(WebGLint x, WebGLint y, WebGLsizei width,
WebGLsizei framebufferWidth = framebufferRect ? framebufferRect->Width() : 0;
WebGLsizei framebufferHeight = framebufferRect ? framebufferRect->Height() : 0;
void* data = pixels->mData;
uint32_t dataByteLen = JS_GetTypedArrayByteLength(pixels->mObj, NULL);
int dataType = JS_GetTypedArrayType(pixels->mObj, NULL);
void* data = pixels->Data();
uint32_t dataByteLen = JS_GetTypedArrayByteLength(pixels->Obj(), NULL);
int dataType = JS_GetTypedArrayType(pixels->Obj(), NULL);
uint32_t channels = 0;
@ -5146,12 +5146,12 @@ WebGLContext::CompressedTexImage2D(WebGLenum target, WebGLint level, WebGLenum i
return;
}
uint32_t byteLength = view.mLength;
uint32_t byteLength = view.Length();
if (!ValidateCompressedTextureSize(level, internalformat, width, height, byteLength, "compressedTexImage2D")) {
return;
}
gl->fCompressedTexImage2D(target, level, internalformat, width, height, border, byteLength, view.mData);
gl->fCompressedTexImage2D(target, level, internalformat, width, height, border, byteLength, view.Data());
tex->SetImageInfo(target, level, width, height, internalformat, LOCAL_GL_UNSIGNED_BYTE);
}
@ -5207,7 +5207,7 @@ WebGLContext::CompressedTexSubImage2D(WebGLenum target, WebGLint level, WebGLint
return;
}
uint32_t byteLength = view.mLength;
uint32_t byteLength = view.Length();
if (!ValidateCompressedTextureSize(level, format, width, height, byteLength, "compressedTexSubImage2D")) {
return;
}
@ -5252,7 +5252,7 @@ WebGLContext::CompressedTexSubImage2D(WebGLenum target, WebGLint level, WebGLint
}
}
gl->fCompressedTexSubImage2D(target, level, xoffset, yoffset, width, height, format, byteLength, view.mData);
gl->fCompressedTexSubImage2D(target, level, xoffset, yoffset, width, height, format, byteLength, view.Data());
return;
}
@ -5742,9 +5742,9 @@ WebGLContext::TexImage2D(JSContext* cx, WebGLenum target, WebGLint level,
return;
return TexImage2D_base(target, level, internalformat, width, height, 0, border, format, type,
pixels ? pixels->mData : 0,
pixels ? pixels->mLength : 0,
pixels ? (int)JS_GetTypedArrayType(pixels->mObj, cx) : -1,
pixels ? pixels->Data() : 0,
pixels ? pixels->Length() : 0,
pixels ? (int)JS_GetTypedArrayType(pixels->Obj(), cx) : -1,
WebGLTexelConversions::Auto, false);
}
@ -5783,7 +5783,7 @@ WebGLContext::TexImage2D(JSContext* cx, WebGLenum target, WebGLint level,
Uint8ClampedArray arr(cx, pixels->GetDataObject());
return TexImage2D_base(target, level, internalformat, pixels->GetWidth(),
pixels->GetHeight(), 4*pixels->GetWidth(), 0,
format, type, arr.mData, arr.mLength, -1,
format, type, arr.Data(), arr.Length(), -1,
WebGLTexelConversions::RGBA8, false);
}
@ -5948,8 +5948,8 @@ WebGLContext::TexSubImage2D(JSContext* cx, WebGLenum target, WebGLint level,
return TexSubImage2D_base(target, level, xoffset, yoffset,
width, height, 0, format, type,
pixels->mData, pixels->mLength,
JS_GetTypedArrayType(pixels->mObj, cx),
pixels->Data(), pixels->Length(),
JS_GetTypedArrayType(pixels->Obj(), cx),
WebGLTexelConversions::Auto, false);
}
@ -5994,7 +5994,7 @@ WebGLContext::TexSubImage2D(JSContext* cx, WebGLenum target, WebGLint level,
return TexSubImage2D_base(target, level, xoffset, yoffset,
pixels->GetWidth(), pixels->GetHeight(),
4*pixels->GetWidth(), format, type,
arr.mData, arr.mLength,
arr.Data(), arr.Length(),
-1,
WebGLTexelConversions::RGBA8, false);
}

Просмотреть файл

@ -4352,7 +4352,7 @@ nsCanvasRenderingContext2DAzure::PutImageData(JSContext* cx,
error = PutImageData_explicit(JS_DoubleToInt32(dx), JS_DoubleToInt32(dy),
imageData->GetWidth(), imageData->GetHeight(),
arr.mData, arr.mLength, false, 0, 0, 0, 0);
arr.Data(), arr.Length(), false, 0, 0, 0, 0);
}
void
@ -4372,7 +4372,7 @@ nsCanvasRenderingContext2DAzure::PutImageData(JSContext* cx,
error = PutImageData_explicit(JS_DoubleToInt32(dx), JS_DoubleToInt32(dy),
imageData->GetWidth(), imageData->GetHeight(),
arr.mData, arr.mLength, true,
arr.Data(), arr.Length(), true,
JS_DoubleToInt32(dirtyX),
JS_DoubleToInt32(dirtyY),
JS_DoubleToInt32(dirtyWidth),

Просмотреть файл

@ -18,31 +18,50 @@ namespace dom {
* a subclass of the base class that supports creation of a relevant typed array
* or array buffer object.
*/
template<typename T, typename U,
U* GetData(JSObject*, JSContext*),
uint32_t GetLength(JSObject*, JSContext*)>
template<typename T,
JSObject* UnboxArray(JSContext*, JSObject*, uint32_t*, T**)>
struct TypedArray_base {
TypedArray_base(JSContext* cx, JSObject* obj) :
mData(static_cast<T*>(GetData(obj, cx))),
mLength(GetLength(obj, cx)),
mObj(obj)
{}
TypedArray_base(JSContext* cx, JSObject* obj)
{
mObj = UnboxArray(cx, obj, &mLength, &mData);
}
T* const mData;
const uint32_t mLength;
JSObject* const mObj;
private:
T* mData;
uint32_t mLength;
JSObject* mObj;
public:
inline bool inited() const {
return !!mObj;
}
inline T *Data() const {
MOZ_ASSERT(inited());
return mData;
}
inline uint32_t Length() const {
MOZ_ASSERT(inited());
return mLength;
}
inline JSObject *Obj() const {
MOZ_ASSERT(inited());
return mObj;
}
};
template<typename T, typename U,
U* GetData(JSObject*, JSContext*),
uint32_t GetLength(JSObject*, JSContext*),
template<typename T,
T* GetData(JSObject*, JSContext*),
JSObject* UnboxArray(JSContext*, JSObject*, uint32_t*, T**),
JSObject* CreateNew(JSContext*, uint32_t)>
struct TypedArray : public TypedArray_base<T,U,GetData,GetLength> {
struct TypedArray : public TypedArray_base<T,UnboxArray> {
TypedArray(JSContext* cx, JSObject* obj) :
TypedArray_base<T,U,GetData,GetLength>(cx, obj)
TypedArray_base<T,UnboxArray>(cx, obj)
{}
static inline JSObject*
Create(JSContext* cx, nsWrapperCache* creator, uint32_t length,
T* data = NULL) {
@ -65,38 +84,37 @@ struct TypedArray : public TypedArray_base<T,U,GetData,GetLength> {
}
};
typedef TypedArray<int8_t, int8_t, JS_GetInt8ArrayData, JS_GetTypedArrayLength,
typedef TypedArray<int8_t, JS_GetInt8ArrayData, JS_GetObjectAsInt8Array,
JS_NewInt8Array>
Int8Array;
typedef TypedArray<uint8_t, uint8_t, JS_GetUint8ArrayData,
JS_GetTypedArrayLength, JS_NewUint8Array>
typedef TypedArray<uint8_t, JS_GetUint8ArrayData,
JS_GetObjectAsUint8Array, JS_NewUint8Array>
Uint8Array;
typedef TypedArray<uint8_t, uint8_t, JS_GetUint8ClampedArrayData,
JS_GetTypedArrayLength, JS_NewUint8ClampedArray>
typedef TypedArray<uint8_t, JS_GetUint8ClampedArrayData,
JS_GetObjectAsUint8ClampedArray, JS_NewUint8ClampedArray>
Uint8ClampedArray;
typedef TypedArray<int16_t, int16_t, JS_GetInt16ArrayData,
JS_GetTypedArrayLength, JS_NewInt16Array>
typedef TypedArray<int16_t, JS_GetInt16ArrayData,
JS_GetObjectAsInt16Array, JS_NewInt16Array>
Int16Array;
typedef TypedArray<uint16_t, uint16_t, JS_GetUint16ArrayData,
JS_GetTypedArrayLength, JS_NewUint16Array>
typedef TypedArray<uint16_t, JS_GetUint16ArrayData,
JS_GetObjectAsUint16Array, JS_NewUint16Array>
Uint16Array;
typedef TypedArray<int32_t, int32_t, JS_GetInt32ArrayData,
JS_GetTypedArrayLength, JS_NewInt32Array>
typedef TypedArray<int32_t, JS_GetInt32ArrayData,
JS_GetObjectAsInt32Array, JS_NewInt32Array>
Int32Array;
typedef TypedArray<uint32_t, uint32_t, JS_GetUint32ArrayData,
JS_GetTypedArrayLength, JS_NewUint32Array>
typedef TypedArray<uint32_t, JS_GetUint32ArrayData,
JS_GetObjectAsUint32Array, JS_NewUint32Array>
Uint32Array;
typedef TypedArray<float, float, JS_GetFloat32ArrayData, JS_GetTypedArrayLength,
JS_NewFloat32Array>
typedef TypedArray<float, JS_GetFloat32ArrayData,
JS_GetObjectAsFloat32Array, JS_NewFloat32Array>
Float32Array;
typedef TypedArray<double, double, JS_GetFloat64ArrayData,
JS_GetTypedArrayLength, JS_NewFloat64Array>
typedef TypedArray<double, JS_GetFloat64ArrayData,
JS_GetObjectAsFloat64Array, JS_NewFloat64Array>
Float64Array;
typedef TypedArray_base<uint8_t, void, JS_GetArrayBufferViewData,
JS_GetArrayBufferViewByteLength>
typedef TypedArray_base<uint8_t, JS_GetObjectAsArrayBufferView>
ArrayBufferView;
typedef TypedArray<uint8_t, uint8_t, JS_GetArrayBufferData,
JS_GetArrayBufferByteLength, JS_NewArrayBuffer>
typedef TypedArray<uint8_t, JS_GetArrayBufferData,
JS_GetObjectAsArrayBuffer, JS_NewArrayBuffer>
ArrayBuffer;
} // namespace dom

Просмотреть файл

@ -162,7 +162,7 @@ public:
void
Send(ArrayBuffer& aBody, ErrorResult& aRv) {
return Send(aBody.mObj, aRv);
return Send(aBody.Obj(), aRv);
}
void