michael@0: /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef WEBGLCONTEXTUTILS_H_ michael@0: #define WEBGLCONTEXTUTILS_H_ michael@0: michael@0: #include "WebGLContext.h" michael@0: #include "mozilla/Assertions.h" michael@0: #include "mozilla/dom/BindingUtils.h" michael@0: michael@0: namespace mozilla { michael@0: michael@0: bool IsGLDepthFormat(GLenum webGLFormat); michael@0: bool IsGLDepthStencilFormat(GLenum webGLFormat); michael@0: bool FormatHasAlpha(GLenum webGLFormat); michael@0: void DriverFormatsFromFormatAndType(gl::GLContext* gl, GLenum webGLFormat, GLenum webGLType, michael@0: GLenum* out_driverInternalFormat, GLenum* out_driverFormat); michael@0: GLenum DriverTypeFromType(gl::GLContext* gl, GLenum webGLType); michael@0: michael@0: template michael@0: JS::Value michael@0: WebGLContext::WebGLObjectAsJSValue(JSContext *cx, const WebGLObjectType *object, ErrorResult& rv) const michael@0: { michael@0: if (!object) { michael@0: return JS::NullValue(); michael@0: } michael@0: MOZ_ASSERT(this == object->Context()); michael@0: JS::Rooted v(cx); michael@0: JS::Rooted wrapper(cx, GetWrapper()); michael@0: JSAutoCompartment ac(cx, wrapper); michael@0: if (!dom::WrapNewBindingObject(cx, const_cast(object), &v)) { michael@0: rv.Throw(NS_ERROR_FAILURE); michael@0: return JS::NullValue(); michael@0: } michael@0: return v; michael@0: } michael@0: michael@0: template michael@0: JSObject* michael@0: WebGLContext::WebGLObjectAsJSObject(JSContext *cx, const WebGLObjectType *object, ErrorResult& rv) const michael@0: { michael@0: JS::Value v = WebGLObjectAsJSValue(cx, object, rv); michael@0: if (v.isNull()) { michael@0: return nullptr; michael@0: } michael@0: return &v.toObject(); michael@0: } michael@0: michael@0: } // namespace mozilla michael@0: michael@0: #endif // WEBGLCONTEXTUTILS_H_