--- a/dom/canvas/WebGLContext.h
+++ b/dom/canvas/WebGLContext.h
@@ -515,17 +515,17 @@ public:
if (rv.Failed() || !data)
return;
gfx::IntSize size = data->GetSize();
uint32_t byteLength = data->Stride() * size.height;
return TexImage2D_base(texImageTarget, level, internalformat,
size.width, size.height, data->Stride(),
0, format, type, data->GetData(), byteLength,
- -1, srcFormat, mPixelStorePremultiplyAlpha);
+ js::Scalar::TypeMax, srcFormat, mPixelStorePremultiplyAlpha);
}
void TexParameterf(GLenum target, GLenum pname, GLfloat param) {
TexParameter_base(target, pname, nullptr, ¶m);
}
void TexParameteri(GLenum target, GLenum pname, GLint param) {
TexParameter_base(target, pname, ¶m, nullptr);
}
@@ -547,18 +547,21 @@ public:
GLint xoffset, GLint yoffset,
GLenum format,
GLenum type,
ElementType& elt, ErrorResult& rv)
{
if (IsContextLost())
return;
- if (!ValidateTexImageTarget(2, rawTexImageTarget, WebGLTexImageFunc::TexSubImage))
+ if (!ValidateTexImageTarget(2, rawTexImageTarget,
+ WebGLTexImageFunc::TexSubImage))
+ {
return ErrorInvalidEnumInfo("texSubImage2D: target", rawTexImageTarget);
+ }
const TexImageTarget texImageTarget(rawTexImageTarget);
if (level < 0)
return ErrorInvalidValue("texSubImage2D: level is negative");
const int32_t maxLevel = MaxTextureLevelForTexImageTarget(texImageTarget);
if (level > maxLevel)
@@ -587,17 +590,17 @@ public:
return;
gfx::IntSize size = data->GetSize();
uint32_t byteLength = data->Stride() * size.height;
return TexSubImage2D_base(texImageTarget.get(), level, xoffset, yoffset,
size.width, size.height,
data->Stride(), format, type,
data->GetData(), byteLength,
- -1, srcFormat, mPixelStorePremultiplyAlpha);
+ js::Scalar::TypeMax, srcFormat, mPixelStorePremultiplyAlpha);
}
void Uniform1i(WebGLUniformLocation* location, GLint x);
void Uniform2i(WebGLUniformLocation* location, GLint x, GLint y);
void Uniform3i(WebGLUniformLocation* location, GLint x, GLint y,
GLint z);
void Uniform4i(WebGLUniformLocation* location, GLint x, GLint y,
@@ -1088,17 +1091,19 @@ protected:
bool ValidateBlendEquationEnum(GLenum cap, const char *info);
bool ValidateBlendFuncDstEnum(GLenum mode, const char *info);
bool ValidateBlendFuncSrcEnum(GLenum mode, const char *info);
bool ValidateBlendFuncEnumsCompatibility(GLenum sfactor, GLenum dfactor, const char *info);
bool ValidateTextureTargetEnum(GLenum target, const char *info);
bool ValidateComparisonEnum(GLenum target, const char *info);
bool ValidateStencilOpEnum(GLenum action, const char *info);
bool ValidateFaceEnum(GLenum face, const char *info);
- bool ValidateTexInputData(GLenum type, int jsArrayType, WebGLTexImageFunc func);
+ bool ValidateTexInputData(GLenum type,
+ js::Scalar::Type jsArrayType,
+ WebGLTexImageFunc func);
bool ValidateDrawModeEnum(GLenum mode, const char *info);
bool ValidateAttribIndex(GLuint index, const char *info);
bool ValidateStencilParamsForDrawCall();
bool ValidateGLSLVariableName(const nsAString& name, const char *info);
bool ValidateGLSLCharacter(char16_t c);
bool ValidateGLSLString(const nsAString& string, const char *info);
@@ -1139,32 +1144,33 @@ protected:
uint32_t byteLength, WebGLTexImageFunc func);
void Invalidate();
void DestroyResourcesAndContext();
void MakeContextCurrent() const;
// helpers
+
void TexImage2D_base(TexImageTarget target,
GLint level,
GLenum internalformat,
GLsizei width, GLsizei height, GLsizei srcStrideOrZero, GLint border,
GLenum format,
GLenum type,
void *data, uint32_t byteLength,
- int jsArrayType,
+ js::Scalar::Type jsArrayType, // special value TypeMax used to mean no array
WebGLTexelFormat srcFormat, bool srcPremultiplied);
void TexSubImage2D_base(TexImageTarget target, GLint level,
GLint xoffset, GLint yoffset,
GLsizei width, GLsizei height, GLsizei srcStrideOrZero,
GLenum format,
GLenum type,
void *pixels, uint32_t byteLength,
- int jsArrayType,
+ js::Scalar::Type jsArrayType, // special value TypeMax used to mean no array
WebGLTexelFormat srcFormat, bool srcPremultiplied);
void TexParameter_base(GLenum target, GLenum pname,
GLint *intParamPtr, GLfloat *floatParamPtr);
bool ConvertImage(size_t width, size_t height, size_t srcStride, size_t dstStride,
const uint8_t* src, uint8_t *dst,
WebGLTexelFormat srcFormat, bool srcPremultiplied,
WebGLTexelFormat dstFormat, bool dstPremultiplied,
--- a/dom/canvas/WebGLContextGL.cpp
+++ b/dom/canvas/WebGLContextGL.cpp
@@ -3643,17 +3643,17 @@ GLenum WebGLContext::CheckedTexImage2D(T
void
WebGLContext::TexImage2D_base(TexImageTarget texImageTarget, GLint level,
GLenum internalformat,
GLsizei width, GLsizei height, GLsizei srcStrideOrZero,
GLint border,
GLenum format,
GLenum type,
void* data, uint32_t byteLength,
- int jsArrayType, // a TypedArray format enum, or -1 if not relevant
+ js::Scalar::Type jsArrayType,
WebGLTexelFormat srcFormat, bool srcPremultiplied)
{
const WebGLTexImageFunc func = WebGLTexImageFunc::TexImage;
if (type == LOCAL_GL_HALF_FLOAT_OES) {
type = LOCAL_GL_HALF_FLOAT;
}
@@ -3797,28 +3797,28 @@ WebGLContext::TexImage2D(GLenum rawTarge
GLsizei height, GLint border, GLenum format,
GLenum type, const Nullable<ArrayBufferView> &pixels, ErrorResult& rv)
{
if (IsContextLost())
return;
void* data;
uint32_t length;
- int jsArrayType;
+ js::Scalar::Type jsArrayType;
if (pixels.IsNull()) {
data = nullptr;
length = 0;
- jsArrayType = -1;
+ jsArrayType = js::Scalar::TypeMax;
} else {
const ArrayBufferView& view = pixels.Value();
view.ComputeLengthAndData();
data = view.Data();
length = view.Length();
- jsArrayType = int(JS_GetArrayBufferViewType(view.Obj()));
+ jsArrayType = JS_GetArrayBufferViewType(view.Obj());
}
if (!ValidateTexImageTarget(2, rawTarget, WebGLTexImageFunc::TexImage))
return;
return TexImage2D_base(rawTarget, level, internalformat, width, height, 0, border, format, type,
data, length, jsArrayType,
WebGLTexelFormat::Auto, false);
@@ -3845,28 +3845,28 @@ WebGLContext::TexImage2D(GLenum rawTarge
void* pixelData = arr.Data();
const uint32_t pixelDataLength = arr.Length();
if (!ValidateTexImageTarget(2, rawTarget, WebGLTexImageFunc::TexImage))
return;
return TexImage2D_base(rawTarget, level, internalformat, pixels->Width(),
pixels->Height(), 4*pixels->Width(), 0,
- format, type, pixelData, pixelDataLength, -1,
+ format, type, pixelData, pixelDataLength, js::Scalar::TypeMax,
WebGLTexelFormat::RGBA8, false);
}
void
WebGLContext::TexSubImage2D_base(TexImageTarget texImageTarget, GLint level,
GLint xoffset, GLint yoffset,
GLsizei width, GLsizei height, GLsizei srcStrideOrZero,
GLenum format, GLenum type,
void* data, uint32_t byteLength,
- int jsArrayType,
+ js::Scalar::Type jsArrayType,
WebGLTexelFormat srcFormat, bool srcPremultiplied)
{
const WebGLTexImageFunc func = WebGLTexImageFunc::TexSubImage;
if (type == LOCAL_GL_HALF_FLOAT_OES) {
type = LOCAL_GL_HALF_FLOAT;
}
@@ -4022,17 +4022,17 @@ WebGLContext::TexSubImage2D(GLenum targe
DebugOnly<bool> inited = arr.Init(pixels->GetDataObject());
MOZ_ASSERT(inited);
arr.ComputeLengthAndData();
return TexSubImage2D_base(target, level, xoffset, yoffset,
pixels->Width(), pixels->Height(),
4*pixels->Width(), format, type,
arr.Data(), arr.Length(),
- -1,
+ js::Scalar::TypeMax,
WebGLTexelFormat::RGBA8, false);
}
void
WebGLContext::LoseContext()
{
if (IsContextLost())
return ErrorInvalidOperation("loseContext: Context is already lost.");
--- a/dom/canvas/WebGLContextValidate.cpp
+++ b/dom/canvas/WebGLContextValidate.cpp
@@ -1004,57 +1004,65 @@ WebGLContext::ValidateCopyTexImageIntern
/**
* Return true if format, type and jsArrayType are a valid combination.
* Also returns the size for texel of format and type (in bytes) via
* \a texelSize.
*
* It is assumed that type has previously been validated.
*/
bool
-WebGLContext::ValidateTexInputData(GLenum type, int jsArrayType, WebGLTexImageFunc func)
+WebGLContext::ValidateTexInputData(GLenum type,
+ js::Scalar::Type jsArrayType,
+ WebGLTexImageFunc func)
{
bool validInput = false;
const char invalidTypedArray[] = "%s: invalid typed array type for given texture data type";
+ // We're using js::Scalar::TypeMax as dummy value when the tex source wasn't a
+ // typed array.
+ if (jsArrayType == js::Scalar::TypeMax) {
+ return true;
+ }
+
// First, we check for packed types
switch (type) {
case LOCAL_GL_UNSIGNED_BYTE:
- validInput = (jsArrayType == -1 || jsArrayType == js::Scalar::Uint8);
+ validInput = jsArrayType == js::Scalar::Uint8;
break;
case LOCAL_GL_BYTE:
- validInput = (jsArrayType == -1 || jsArrayType == js::Scalar::Int8);
+ validInput = jsArrayType == js::Scalar::Int8;
break;
case LOCAL_GL_HALF_FLOAT:
case LOCAL_GL_UNSIGNED_SHORT:
case LOCAL_GL_UNSIGNED_SHORT_4_4_4_4:
case LOCAL_GL_UNSIGNED_SHORT_5_5_5_1:
case LOCAL_GL_UNSIGNED_SHORT_5_6_5:
- validInput = (jsArrayType == -1 || jsArrayType == js::Scalar::Uint16);
+ validInput = jsArrayType == js::Scalar::Uint16;
break;
case LOCAL_GL_SHORT:
- validInput = (jsArrayType == -1 || jsArrayType == js::Scalar::Int16);
+ validInput = jsArrayType == js::Scalar::Int16;
break;
case LOCAL_GL_UNSIGNED_INT:
case LOCAL_GL_UNSIGNED_INT_24_8:
case LOCAL_GL_UNSIGNED_INT_2_10_10_10_REV:
case LOCAL_GL_UNSIGNED_INT_10F_11F_11F_REV:
case LOCAL_GL_UNSIGNED_INT_5_9_9_9_REV:
- validInput = (jsArrayType == -1 || jsArrayType == js::Scalar::Uint32);
+ validInput = jsArrayType == js::Scalar::Uint32;
break;
case LOCAL_GL_INT:
- validInput = (jsArrayType == -1 || jsArrayType == js::Scalar::Int32);
+ validInput = jsArrayType == js::Scalar::Int32;
break;
case LOCAL_GL_FLOAT:
- validInput = (jsArrayType == -1 || jsArrayType == js::Scalar::Float32);
+ validInput = jsArrayType == js::Scalar::Float32;
break;
default:
break;
}
if (!validInput)
ErrorInvalidOperation(invalidTypedArray, InfoFrom(func));