Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
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 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 }
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 }
51 } // namespace mozilla
53 #endif // WEBGLCONTEXTUTILS_H_