content/canvas/src/WebGLContextUtils.h

Thu, 15 Jan 2015 21:03:48 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 21:03:48 +0100
branch
TOR_BUG_9701
changeset 11
deefc01c0e14
permissions
-rw-r--r--

Integrate friendly tips from Tor colleagues to make (or not) 4.5 alpha 3;
This includes removal of overloaded (but unused) methods, and addition of
a overlooked call to DataStruct::SetData(nsISupports, uint32_t, bool.)

     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_

mercurial