Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/dom/canvas/WebGLContextUtils.h
Line
Count
Source (jump to first uncovered line)
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 WEBGL_CONTEXT_UTILS_H_
7
#define WEBGL_CONTEXT_UTILS_H_
8
9
#include "WebGLContext.h"
10
11
#include "mozilla/Assertions.h"
12
#include "mozilla/dom/BindingUtils.h"
13
14
#include "WebGLStrongTypes.h"
15
16
namespace mozilla {
17
18
// For use with the different texture calls, i.e.
19
//   TexImage2D, CopyTex[Sub]Image2D, ...
20
// that take a "target" parameter. This parameter is not always the same as
21
// the texture binding location, like GL_TEXTURE_2D or GL_TEXTURE_CUBE_MAP.
22
// For example, cube maps would pass GL_TEXTURE_CUBE_MAP_[POS|NEG]_[X|Y|Z]
23
// instead of just GL_TEXTURE_CUBE_MAP.
24
//
25
// This function converts the texture image target to the texture target a.k.a.
26
// binding location. The returned binding location can be used to check that
27
// the currently bound texture is appropriate for this texImageTarget.
28
//
29
// Returns GL_NONE if passed an invalid texture image target
30
TexTarget TexImageTargetToTexTarget(TexImageTarget texImageTarget);
31
32
// Helper function to create a JS::Value from a C string
33
JS::Value StringValue(JSContext* cx, const char* str, ErrorResult& rv);
34
35
struct GLComponents
36
{
37
    unsigned char mComponents;
38
39
    enum Components {
40
        Red     = (1 << 0),
41
        Green   = (1 << 1),
42
        Blue    = (1 << 2),
43
        Alpha   = (1 << 3),
44
        Stencil = (1 << 4),
45
        Depth   = (1 << 5),
46
    };
47
48
    GLComponents()
49
        : mComponents(0)
50
0
    {}
51
52
    explicit GLComponents(TexInternalFormat format);
53
54
    // Returns true iff other has all (or more) of
55
    // the components present in this GLComponents
56
    bool IsSubsetOf(const GLComponents& other) const;
57
};
58
59
template <typename WebGLObjectType>
60
JS::Value
61
WebGLContext::WebGLObjectAsJSValue(JSContext* cx, const WebGLObjectType* object,
62
                                   ErrorResult& rv) const
63
0
{
64
0
    if (!object)
65
0
        return JS::NullValue();
66
0
67
0
    MOZ_ASSERT(this == object->mContext);
68
0
    JS::Rooted<JS::Value> v(cx);
69
0
    JS::Rooted<JSObject*> wrapper(cx, GetWrapper());
70
0
    JSAutoRealm ar(cx, wrapper);
71
0
    if (!dom::GetOrCreateDOMReflector(cx, const_cast<WebGLObjectType*>(object), &v)) {
72
0
        rv.Throw(NS_ERROR_FAILURE);
73
0
        return JS::NullValue();
74
0
    }
75
0
    return v;
76
0
}
Unexecuted instantiation: JS::Value mozilla::WebGLContext::WebGLObjectAsJSValue<mozilla::WebGLBuffer>(JSContext*, mozilla::WebGLBuffer const*, mozilla::ErrorResult&) const
Unexecuted instantiation: JS::Value mozilla::WebGLContext::WebGLObjectAsJSValue<mozilla::WebGLFramebuffer>(JSContext*, mozilla::WebGLFramebuffer const*, mozilla::ErrorResult&) const
Unexecuted instantiation: JS::Value mozilla::WebGLContext::WebGLObjectAsJSValue<mozilla::WebGLSampler>(JSContext*, mozilla::WebGLSampler const*, mozilla::ErrorResult&) const
Unexecuted instantiation: JS::Value mozilla::WebGLContext::WebGLObjectAsJSValue<mozilla::WebGLTexture>(JSContext*, mozilla::WebGLTexture const*, mozilla::ErrorResult&) const
Unexecuted instantiation: JS::Value mozilla::WebGLContext::WebGLObjectAsJSValue<mozilla::WebGLTransformFeedback>(JSContext*, mozilla::WebGLTransformFeedback const*, mozilla::ErrorResult&) const
Unexecuted instantiation: JS::Value mozilla::WebGLContext::WebGLObjectAsJSValue<mozilla::WebGLVertexArray>(JSContext*, mozilla::WebGLVertexArray const*, mozilla::ErrorResult&) const
Unexecuted instantiation: JS::Value mozilla::WebGLContext::WebGLObjectAsJSValue<mozilla::WebGLExtensionBase>(JSContext*, mozilla::WebGLExtensionBase const*, mozilla::ErrorResult&) const
Unexecuted instantiation: JS::Value mozilla::WebGLContext::WebGLObjectAsJSValue<mozilla::WebGLRenderbuffer>(JSContext*, mozilla::WebGLRenderbuffer const*, mozilla::ErrorResult&) const
Unexecuted instantiation: JS::Value mozilla::WebGLContext::WebGLObjectAsJSValue<mozilla::WebGLProgram>(JSContext*, mozilla::WebGLProgram const*, mozilla::ErrorResult&) const
77
78
template <typename WebGLObjectType>
79
JSObject*
80
WebGLContext::WebGLObjectAsJSObject(JSContext* cx,
81
                                    const WebGLObjectType* object,
82
                                    ErrorResult& rv) const
83
0
{
84
0
    JS::Value v = WebGLObjectAsJSValue(cx, object, rv);
85
0
    if (v.isNull())
86
0
        return nullptr;
87
0
88
0
    return &v.toObject();
89
0
}
90
91
/**
92
 * Return the displayable name for the texture function that is the
93
 * source for validation.
94
 */
95
const char* InfoFrom(WebGLTexImageFunc func, WebGLTexDimensions dims);
96
97
JS::Value StringValue(JSContext* cx, const nsAString& str, ErrorResult& er);
98
99
} // namespace mozilla
100
101
#endif // WEBGL_CONTEXT_UTILS_H_