Bumping gaia.json for 1 gaia revision(s) a=gaia-bump
[gecko.git] / dom / canvas / WebGLContextUtils.h
blobe12081d1d7c28b6edb9f9684ed53d3d247cb3f0a
1 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef WEBGLCONTEXTUTILS_H_
7 #define WEBGLCONTEXTUTILS_H_
9 #include "WebGLContext.h"
10 #include "mozilla/Assertions.h"
11 #include "mozilla/dom/BindingUtils.h"
13 namespace mozilla {
15 bool IsGLDepthFormat(GLenum webGLFormat);
16 bool IsGLDepthStencilFormat(GLenum webGLFormat);
17 bool FormatHasAlpha(GLenum webGLFormat);
18 void DriverFormatsFromFormatAndType(gl::GLContext* gl, GLenum webGLFormat, GLenum webGLType,
19 GLenum* out_driverInternalFormat, GLenum* out_driverFormat);
20 GLenum DriverTypeFromType(gl::GLContext* gl, GLenum webGLType);
22 struct GLComponents
24 unsigned char mComponents;
26 enum Components {
27 Red = (1 << 0),
28 Green = (1 << 1),
29 Blue = (1 << 2),
30 Alpha = (1 << 3),
31 Stencil = (1 << 4),
32 Depth = (1 << 5),
35 GLComponents()
36 : mComponents(0)
37 { }
39 GLComponents(GLenum format);
41 // Returns true iff other has all (or more) of
42 // the components present in this GLComponents
43 bool IsSubsetOf(const GLComponents& other) const;
46 template <typename WebGLObjectType>
47 JS::Value
48 WebGLContext::WebGLObjectAsJSValue(JSContext *cx, const WebGLObjectType *object, ErrorResult& rv) const
50 if (!object) {
51 return JS::NullValue();
53 MOZ_ASSERT(this == object->Context());
54 JS::Rooted<JS::Value> v(cx);
55 JS::Rooted<JSObject*> wrapper(cx, GetWrapper());
56 JSAutoCompartment ac(cx, wrapper);
57 if (!dom::WrapNewBindingObject(cx, const_cast<WebGLObjectType*>(object), &v)) {
58 rv.Throw(NS_ERROR_FAILURE);
59 return JS::NullValue();
61 return v;
64 template <typename WebGLObjectType>
65 JSObject*
66 WebGLContext::WebGLObjectAsJSObject(JSContext *cx, const WebGLObjectType *object, ErrorResult& rv) const
68 JS::Value v = WebGLObjectAsJSValue(cx, object, rv);
69 if (v.isNull()) {
70 return nullptr;
72 return &v.toObject();
75 } // namespace mozilla
77 #endif // WEBGLCONTEXTUTILS_H_