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"
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
);
24 unsigned char mComponents
;
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
>
48 WebGLContext::WebGLObjectAsJSValue(JSContext
*cx
, const WebGLObjectType
*object
, ErrorResult
& rv
) const
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();
64 template <typename WebGLObjectType
>
66 WebGLContext::WebGLObjectAsJSObject(JSContext
*cx
, const WebGLObjectType
*object
, ErrorResult
& rv
) const
68 JS::Value v
= WebGLObjectAsJSValue(cx
, object
, rv
);
75 } // namespace mozilla
77 #endif // WEBGLCONTEXTUTILS_H_