|
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/. */ |
|
5 |
|
6 #ifndef WEBGLCONTEXTUTILS_H_ |
|
7 #define WEBGLCONTEXTUTILS_H_ |
|
8 |
|
9 #include "WebGLContext.h" |
|
10 #include "mozilla/Assertions.h" |
|
11 #include "mozilla/dom/BindingUtils.h" |
|
12 |
|
13 namespace mozilla { |
|
14 |
|
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); |
|
21 |
|
22 template <typename WebGLObjectType> |
|
23 JS::Value |
|
24 WebGLContext::WebGLObjectAsJSValue(JSContext *cx, const WebGLObjectType *object, ErrorResult& rv) const |
|
25 { |
|
26 if (!object) { |
|
27 return JS::NullValue(); |
|
28 } |
|
29 MOZ_ASSERT(this == object->Context()); |
|
30 JS::Rooted<JS::Value> v(cx); |
|
31 JS::Rooted<JSObject*> wrapper(cx, GetWrapper()); |
|
32 JSAutoCompartment ac(cx, wrapper); |
|
33 if (!dom::WrapNewBindingObject(cx, const_cast<WebGLObjectType*>(object), &v)) { |
|
34 rv.Throw(NS_ERROR_FAILURE); |
|
35 return JS::NullValue(); |
|
36 } |
|
37 return v; |
|
38 } |
|
39 |
|
40 template <typename WebGLObjectType> |
|
41 JSObject* |
|
42 WebGLContext::WebGLObjectAsJSObject(JSContext *cx, const WebGLObjectType *object, ErrorResult& rv) const |
|
43 { |
|
44 JS::Value v = WebGLObjectAsJSValue(cx, object, rv); |
|
45 if (v.isNull()) { |
|
46 return nullptr; |
|
47 } |
|
48 return &v.toObject(); |
|
49 } |
|
50 |
|
51 } // namespace mozilla |
|
52 |
|
53 #endif // WEBGLCONTEXTUTILS_H_ |