diff --git a/dom/canvas/WebGL2Context.h b/dom/canvas/WebGL2Context.h index c6c00493cb0..6ddad7ec1ed 100644 --- a/dom/canvas/WebGL2Context.h +++ b/dom/canvas/WebGL2Context.h @@ -324,6 +324,7 @@ public: void BindBufferBase(GLenum target, GLuint index, WebGLBuffer* buffer); void BindBufferRange(GLenum target, GLuint index, WebGLBuffer* buffer, GLintptr offset, GLsizeiptr size); */ + virtual JS::Value GetParameter(JSContext* cx, GLenum pname, ErrorResult& rv) override; void GetIndexedParameter(GLenum target, GLuint index, dom::Nullable& retval); void GetUniformIndices(WebGLProgram* program, diff --git a/dom/canvas/WebGL2ContextState.cpp b/dom/canvas/WebGL2ContextState.cpp new file mode 100644 index 00000000000..7e8dfd39378 --- /dev/null +++ b/dom/canvas/WebGL2ContextState.cpp @@ -0,0 +1,68 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "WebGL2Context.h" +#include "WebGLContextUtils.h" + +namespace mozilla { + +JS::Value +WebGL2Context::GetParameter(JSContext* cx, GLenum pname, ErrorResult& rv) +{ + if (IsContextLost()) + return JS::NullValue(); + + MakeContextCurrent(); + + switch (pname) { + case LOCAL_GL_MAX_SAMPLES: + case LOCAL_GL_MAX_UNIFORM_BLOCK_SIZE: + case LOCAL_GL_MAX_VERTEX_UNIFORM_COMPONENTS: { + GLint val; + gl->fGetIntegerv(pname, &val); + return JS::NumberValue(uint32_t(val)); + } + + case LOCAL_GL_TEXTURE_BINDING_3D: + return WebGLObjectAsJSValue(cx, mBound3DTextures[mActiveTexture].get(), rv); + + // DRAW_FRAMEBUFFER_BINDING is the same as FRAMEBUFFER_BINDING. + case LOCAL_GL_READ_FRAMEBUFFER_BINDING: + return WebGLObjectAsJSValue(cx, mBoundReadFramebuffer.get(), rv); + + case LOCAL_GL_PIXEL_PACK_BUFFER_BINDING: + return WebGLObjectAsJSValue(cx, mBoundPixelPackBuffer.get(), rv); + + case LOCAL_GL_PIXEL_UNPACK_BUFFER_BINDING: + return WebGLObjectAsJSValue(cx, mBoundPixelUnpackBuffer.get(), rv); + + case LOCAL_GL_UNIFORM_BUFFER_BINDING: + return WebGLObjectAsJSValue(cx, mBoundUniformBuffer.get(), rv); + + case LOCAL_GL_TRANSFORM_FEEDBACK_BUFFER_BINDING: + return WebGLObjectAsJSValue(cx, mBoundTransformFeedbackBuffer.get(), rv); + + case LOCAL_GL_COPY_READ_BUFFER_BINDING: + return WebGLObjectAsJSValue(cx, mBoundCopyReadBuffer.get(), rv); + + case LOCAL_GL_COPY_WRITE_BUFFER_BINDING: + return WebGLObjectAsJSValue(cx, mBoundCopyWriteBuffer.get(), rv); + + case LOCAL_GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS: + return JS::Int32Value(mGLMaxTransformFeedbackSeparateAttribs); + + case LOCAL_GL_VERSION: + return StringValue(cx, "WebGL 2.0", rv); + + case LOCAL_GL_SHADING_LANGUAGE_VERSION: + return StringValue(cx, "WebGL GLSL ES 3.00", rv); + + default: + return WebGLContext::GetParameter(cx, pname, rv); + } +} + +} // namespace mozilla diff --git a/dom/canvas/WebGLContext.h b/dom/canvas/WebGLContext.h index 55c5d802631..d48fd7c7e2a 100644 --- a/dom/canvas/WebGLContext.h +++ b/dom/canvas/WebGLContext.h @@ -955,7 +955,7 @@ public: void Disable(GLenum cap); void Enable(GLenum cap); bool GetStencilBits(GLint* out_stencilBits); - JS::Value GetParameter(JSContext* cx, GLenum pname, ErrorResult& rv); + virtual JS::Value GetParameter(JSContext* cx, GLenum pname, ErrorResult& rv); void GetParameter(JSContext* cx, GLenum pname, JS::MutableHandle retval, ErrorResult& rv) diff --git a/dom/canvas/WebGLContextState.cpp b/dom/canvas/WebGLContextState.cpp index 0ad586978a0..6d6b99031f2 100644 --- a/dom/canvas/WebGLContextState.cpp +++ b/dom/canvas/WebGLContextState.cpp @@ -58,18 +58,6 @@ WebGLContext::Enable(GLenum cap) gl->fEnable(cap); } -static JS::Value -StringValue(JSContext* cx, const char* chars, ErrorResult& rv) -{ - JSString* str = JS_NewStringCopyZ(cx, chars); - if (!str) { - rv.Throw(NS_ERROR_OUT_OF_MEMORY); - return JS::NullValue(); - } - - return JS::StringValue(str); -} - bool WebGLContext::GetStencilBits(GLint* out_stencilBits) { @@ -192,63 +180,15 @@ WebGLContext::GetParameter(JSContext* cx, GLenum pname, ErrorResult& rv) } } - if (IsWebGL2()) { - switch (pname) { - case LOCAL_GL_MAX_SAMPLES: - case LOCAL_GL_MAX_UNIFORM_BLOCK_SIZE: - case LOCAL_GL_MAX_VERTEX_UNIFORM_COMPONENTS: { - GLint val; - gl->fGetIntegerv(pname, &val); - return JS::NumberValue(uint32_t(val)); - } - - case LOCAL_GL_TEXTURE_BINDING_3D: - return WebGLObjectAsJSValue(cx, mBound3DTextures[mActiveTexture].get(), rv); - - // DRAW_FRAMEBUFFER_BINDING is the same as FRAMEBUFFER_BINDING. - case LOCAL_GL_READ_FRAMEBUFFER_BINDING: - return WebGLObjectAsJSValue(cx, mBoundReadFramebuffer.get(), rv); - - case LOCAL_GL_PIXEL_PACK_BUFFER_BINDING: - return WebGLObjectAsJSValue(cx, mBoundPixelPackBuffer.get(), rv); - - case LOCAL_GL_PIXEL_UNPACK_BUFFER_BINDING: - return WebGLObjectAsJSValue(cx, mBoundPixelUnpackBuffer.get(), rv); - - case LOCAL_GL_UNIFORM_BUFFER_BINDING: - return WebGLObjectAsJSValue(cx, mBoundUniformBuffer.get(), rv); - - case LOCAL_GL_TRANSFORM_FEEDBACK_BUFFER_BINDING: - return WebGLObjectAsJSValue(cx, mBoundTransformFeedbackBuffer.get(), rv); - - case LOCAL_GL_COPY_READ_BUFFER_BINDING: - return WebGLObjectAsJSValue(cx, mBoundCopyReadBuffer.get(), rv); - - case LOCAL_GL_COPY_WRITE_BUFFER_BINDING: - return WebGLObjectAsJSValue(cx, mBoundCopyWriteBuffer.get(), rv); - } - } - switch (pname) { // // String params // case LOCAL_GL_VENDOR: - return StringValue(cx, "Mozilla", rv); case LOCAL_GL_RENDERER: return StringValue(cx, "Mozilla", rv); - case LOCAL_GL_VERSION: { - const char* version = 0; - - if (IsWebGL2()) { - version = "WebGL 2.0"; - } else { - version = "WebGL 1.0"; - } - - MOZ_ASSERT(version != 0); - return StringValue(cx, version, rv); - } + case LOCAL_GL_VERSION: + return StringValue(cx, "WebGL 1.0", rv); case LOCAL_GL_SHADING_LANGUAGE_VERSION: return StringValue(cx, "WebGL GLSL ES 1.0", rv); @@ -417,12 +357,6 @@ WebGLContext::GetParameter(JSContext* cx, GLenum pname, ErrorResult& rv) } return JS::ObjectOrNullValue(obj); } - case LOCAL_GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS: { - if (!IsWebGL2()) { - break; - } - return JS::Int32Value(mGLMaxTransformFeedbackSeparateAttribs); - } // unsigned int. here we may have to return very large values like 2^32-1 that can't be represented as // javascript integer values. We just return them as doubles and javascript doesn't care. diff --git a/dom/canvas/WebGLContextUtils.cpp b/dom/canvas/WebGLContextUtils.cpp index 69fda519db9..f84e4276a91 100644 --- a/dom/canvas/WebGLContextUtils.cpp +++ b/dom/canvas/WebGLContextUtils.cpp @@ -75,6 +75,18 @@ TexImageTargetToTexTarget(TexImageTarget texImageTarget) } } +JS::Value +StringValue(JSContext* cx, const char* chars, ErrorResult& rv) +{ + JSString* str = JS_NewStringCopyZ(cx, chars); + if (!str) { + rv.Throw(NS_ERROR_OUT_OF_MEMORY); + return JS::NullValue(); + } + + return JS::StringValue(str); +} + GLComponents::GLComponents(TexInternalFormat internalformat) { TexInternalFormat unsizedformat = UnsizedInternalFormatFromInternalFormat(internalformat); diff --git a/dom/canvas/WebGLContextUtils.h b/dom/canvas/WebGLContextUtils.h index d130153f548..5535ee9fc69 100644 --- a/dom/canvas/WebGLContextUtils.h +++ b/dom/canvas/WebGLContextUtils.h @@ -56,6 +56,9 @@ size_t GetBitsPerTexel(TexInternalFormat effectiveinternalformat); // Returns GL_NONE if passed an invalid texture image target TexTarget TexImageTargetToTexTarget(TexImageTarget texImageTarget); +// Helper function to create a JS::Value from a C string +JS::Value StringValue(JSContext* cx, const char* str, ErrorResult& rv); + struct GLComponents { unsigned char mComponents; diff --git a/dom/canvas/WebGLTimerQuery.h b/dom/canvas/WebGLTimerQuery.h index d1224e93175..9f6205e9e18 100644 --- a/dom/canvas/WebGLTimerQuery.h +++ b/dom/canvas/WebGLTimerQuery.h @@ -7,6 +7,7 @@ #ifndef WEBGL_TIMER_QUERY_H_ #define WEBGL_TIMER_QUERY_H_ +#include "GLConsts.h" #include "nsWrapperCache.h" #include "WebGLObjectModel.h" diff --git a/dom/canvas/moz.build b/dom/canvas/moz.build index e8b1541be24..69367f4cd61 100644 --- a/dom/canvas/moz.build +++ b/dom/canvas/moz.build @@ -61,6 +61,7 @@ UNIFIED_SOURCES += [ 'WebGL2ContextPrograms.cpp', 'WebGL2ContextQueries.cpp', 'WebGL2ContextSamplers.cpp', + 'WebGL2ContextState.cpp', 'WebGL2ContextSync.cpp', 'WebGL2ContextTextures.cpp', 'WebGL2ContextTransformFeedback.cpp',