Skip to content

Commit

Permalink
Bug 1015561 - WebGL change getParameter(STENCIL_[BACK]_REF) to return…
Browse files Browse the repository at this point in the history
… correct masked values and update debug cached value test. r=jgilbert
  • Loading branch information
waltermoz committed Sep 26, 2014
1 parent d0ee26b commit 4d2e052
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 6 deletions.
1 change: 1 addition & 0 deletions dom/canvas/WebGLContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -836,6 +836,7 @@ class WebGLContext :
public:
void Disable(GLenum cap);
void Enable(GLenum cap);
bool GetStencilBits(GLint* out_stencilBits);
JS::Value GetParameter(JSContext* cx, GLenum pname, ErrorResult& rv);
void GetParameter(JSContext* cx, GLenum pname,
JS::MutableHandle<JS::Value> retval, ErrorResult& rv) {
Expand Down
47 changes: 43 additions & 4 deletions dom/canvas/WebGLContextState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,29 @@ StringValue(JSContext* cx, const char* chars, ErrorResult& rv)
return JS::StringValue(str);
}

bool
WebGLContext::GetStencilBits(GLint* out_stencilBits)
{
*out_stencilBits = 0;
if (mBoundFramebuffer) {
if (mBoundFramebuffer->HasDepthStencilConflict()) {
// Error, we don't know which stencil buffer's bits to use
ErrorInvalidFramebufferOperation("getParameter: framebuffer has two stencil buffers bound");
return false;
}

if (mBoundFramebuffer->StencilAttachment().IsDefined() ||
mBoundFramebuffer->DepthStencilAttachment().IsDefined())
{
*out_stencilBits = 8;
}
} else if (mOptions.stencil) {
*out_stencilBits = 8;
}

return true;
}

JS::Value
WebGLContext::GetParameter(JSContext* cx, GLenum pname, ErrorResult& rv)
{
Expand Down Expand Up @@ -241,9 +264,26 @@ WebGLContext::GetParameter(JSContext* cx, GLenum pname, ErrorResult& rv)
return JS::NumberValue(uint32_t(i));
}
// int
case LOCAL_GL_STENCIL_CLEAR_VALUE:
case LOCAL_GL_STENCIL_REF:
case LOCAL_GL_STENCIL_BACK_REF:
case LOCAL_GL_STENCIL_BACK_REF: {
GLint stencilBits = 0;
if (!GetStencilBits(&stencilBits))
return JS::NullValue();

// Assuming stencils have 8 bits
const GLint stencilMask = (1 << stencilBits) - 1;

GLint refValue = 0;
gl->fGetIntegerv(pname, &refValue);

return JS::Int32Value(refValue & stencilMask);
}
case LOCAL_GL_STENCIL_BITS: {
GLint stencilBits = 0;
GetStencilBits(&stencilBits);
return JS::Int32Value(stencilBits);
}
case LOCAL_GL_STENCIL_CLEAR_VALUE:
case LOCAL_GL_UNPACK_ALIGNMENT:
case LOCAL_GL_PACK_ALIGNMENT:
case LOCAL_GL_SUBPIXEL_BITS:
Expand All @@ -257,8 +297,7 @@ WebGLContext::GetParameter(JSContext* cx, GLenum pname, ErrorResult& rv)
case LOCAL_GL_GREEN_BITS:
case LOCAL_GL_BLUE_BITS:
case LOCAL_GL_ALPHA_BITS:
case LOCAL_GL_DEPTH_BITS:
case LOCAL_GL_STENCIL_BITS: {
case LOCAL_GL_DEPTH_BITS: {
GLint i = 0;
gl->fGetIntegerv(pname, &i);
return JS::Int32Value(i);
Expand Down
24 changes: 22 additions & 2 deletions dom/canvas/WebGLContextUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -705,6 +705,22 @@ AssertUintParamCorrect(gl::GLContext* gl, GLenum pname, GLuint shadow)
MOZ_ASSERT(false, "Bad cached value.");
}
}

void
AssertMaskedUintParamCorrect(gl::GLContext* gl, GLenum pname, GLuint mask, GLuint shadow)
{
GLuint val = 0;
gl->GetUIntegerv(pname, &val);

const GLuint valMasked = val & mask;
const GLuint shadowMasked = shadow & mask;

if (valMasked != shadowMasked) {
printf_stderr("Failed 0x%04x shadow: Cached 0x%x/%u, should be 0x%x/%u.\n",
pname, shadowMasked, shadowMasked, valMasked, valMasked);
MOZ_ASSERT(false, "Bad cached value.");
}
}
#else
void
AssertUintParamCorrect(gl::GLContext*, GLenum, GLuint)
Expand Down Expand Up @@ -802,8 +818,12 @@ WebGLContext::AssertCachedState()

AssertUintParamCorrect(gl, LOCAL_GL_STENCIL_CLEAR_VALUE, mStencilClearValue);

AssertUintParamCorrect(gl, LOCAL_GL_STENCIL_REF, mStencilRefFront);
AssertUintParamCorrect(gl, LOCAL_GL_STENCIL_BACK_REF, mStencilRefBack);
GLint stencilBits = 0;
gl->fGetIntegerv(LOCAL_GL_STENCIL_BITS, &stencilBits);
const GLuint stencilRefMask = (1 << stencilBits) - 1;

AssertMaskedUintParamCorrect(gl, LOCAL_GL_STENCIL_REF, stencilRefMask, mStencilRefFront);
AssertMaskedUintParamCorrect(gl, LOCAL_GL_STENCIL_BACK_REF, stencilRefMask, mStencilRefBack);

AssertUintParamCorrect(gl, LOCAL_GL_STENCIL_VALUE_MASK, mStencilValueMaskFront);
AssertUintParamCorrect(gl, LOCAL_GL_STENCIL_BACK_VALUE_MASK, mStencilValueMaskBack);
Expand Down

0 comments on commit 4d2e052

Please sign in to comment.