b=570779; validate enums in blend functions; r=vladimir

This commit is contained in:
Benoit Jacob 2010-06-19 10:48:44 -04:00
Родитель 3f27f7568b
Коммит 1840b51335
3 изменённых файлов: 91 добавлений и 5 удалений

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

@ -317,7 +317,9 @@ protected:
PRBool InitAndValidateGL();
PRBool ValidateBuffers(PRUint32 count);
static PRBool ValidateCapabilityEnum(WebGLenum cap);
static PRBool ValidateBlendEquationEnum(WebGLuint cap);
static PRBool ValidateBlendFuncDstEnum(WebGLuint mode);
static PRBool ValidateBlendFuncSrcEnum(WebGLuint mode);
void Invalidate();
void MakeContextCurrent() { gl->MakeCurrent(); }

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

@ -294,13 +294,54 @@ WebGLContext::BindTexture(WebGLenum target, nsIWebGLTexture *tobj)
GL_SAME_METHOD_4(BlendColor, BlendColor, float, float, float, float)
GL_SAME_METHOD_1(BlendEquation, BlendEquation, WebGLenum)
NS_IMETHODIMP WebGLContext::BlendEquation(WebGLenum mode)
{
if (!ValidateBlendEquationEnum(mode))
return ErrorInvalidEnum("BlendEquation: invalid mode");
GL_SAME_METHOD_2(BlendEquationSeparate, BlendEquationSeparate, WebGLenum, WebGLenum)
MakeContextCurrent();
gl->fBlendEquation(mode);
return NS_OK;
}
GL_SAME_METHOD_2(BlendFunc, BlendFunc, WebGLenum, WebGLenum)
NS_IMETHODIMP WebGLContext::BlendEquationSeparate(WebGLenum modeRGB, WebGLenum modeAlpha)
{
if (!ValidateBlendEquationEnum(modeRGB)
|| !ValidateBlendEquationEnum(modeAlpha))
return ErrorInvalidEnum("BlendEquationSeparate: invalid mode");
GL_SAME_METHOD_4(BlendFuncSeparate, BlendFuncSeparate, WebGLenum, WebGLenum, WebGLenum, WebGLenum)
MakeContextCurrent();
gl->fBlendEquationSeparate(modeRGB, modeAlpha);
return NS_OK;
}
NS_IMETHODIMP WebGLContext::BlendFunc(WebGLenum sfactor, WebGLenum dfactor)
{
if (!ValidateBlendFuncSrcEnum(sfactor))
return ErrorInvalidEnum("BlendFunc: invalid source factor");
if (!ValidateBlendFuncDstEnum(dfactor))
return ErrorInvalidEnum("BlendFunc: invalid destination factor");
MakeContextCurrent();
gl->fBlendFunc(sfactor, dfactor);
return NS_OK;
}
NS_IMETHODIMP
WebGLContext::BlendFuncSeparate(WebGLenum srcRGB, WebGLenum dstRGB,
WebGLenum srcAlpha, WebGLenum dstAlpha)
{
if (!ValidateBlendFuncSrcEnum(srcRGB)
|| !ValidateBlendFuncSrcEnum(srcAlpha))
return ErrorInvalidEnum("BlendFuncSeparate: invalid source factor");
if (!ValidateBlendFuncDstEnum(dstRGB)
|| !ValidateBlendFuncDstEnum(dstAlpha))
return ErrorInvalidEnum("BlendFuncSeparate: invalid destination factor");
MakeContextCurrent();
gl->fBlendFuncSeparate(srcRGB, dstRGB, srcAlpha, dstAlpha);
return NS_OK;
}
NS_IMETHODIMP
WebGLContext::BufferData(PRInt32 dummy)

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

@ -143,6 +143,49 @@ PRBool WebGLContext::ValidateCapabilityEnum(WebGLenum cap)
}
}
PRBool WebGLContext::ValidateBlendEquationEnum(WebGLenum mode)
{
switch (mode) {
case LOCAL_GL_FUNC_ADD:
case LOCAL_GL_FUNC_SUBTRACT:
case LOCAL_GL_FUNC_REVERSE_SUBTRACT:
return PR_TRUE;
default:
return PR_FALSE;
}
}
PRBool WebGLContext::ValidateBlendFuncDstEnum(WebGLenum factor)
{
switch (factor) {
case LOCAL_GL_ZERO:
case LOCAL_GL_ONE:
case LOCAL_GL_SRC_COLOR:
case LOCAL_GL_ONE_MINUS_SRC_COLOR:
case LOCAL_GL_DST_COLOR:
case LOCAL_GL_ONE_MINUS_DST_COLOR:
case LOCAL_GL_SRC_ALPHA:
case LOCAL_GL_ONE_MINUS_SRC_ALPHA:
case LOCAL_GL_DST_ALPHA:
case LOCAL_GL_ONE_MINUS_DST_ALPHA:
case LOCAL_GL_CONSTANT_COLOR:
case LOCAL_GL_ONE_MINUS_CONSTANT_COLOR:
case LOCAL_GL_CONSTANT_ALPHA:
case LOCAL_GL_ONE_MINUS_CONSTANT_ALPHA:
return PR_TRUE;
default:
return PR_FALSE;
}
}
PRBool WebGLContext::ValidateBlendFuncSrcEnum(WebGLenum factor)
{
if(factor == LOCAL_GL_SRC_ALPHA_SATURATE)
return PR_TRUE;
else
return ValidateBlendFuncDstEnum(factor);
}
PRBool
WebGLContext::InitAndValidateGL()
{