Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/dom/canvas/WebGLShader.h
Line
Count
Source (jump to first uncovered line)
1
/* -*- Mode: C++; tab-width: 4; 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_SHADER_H_
7
#define WEBGL_SHADER_H_
8
9
#include <map>
10
#include <string>
11
#include <vector>
12
13
#include "GLDefs.h"
14
#include "mozilla/LinkedList.h"
15
#include "mozilla/MemoryReporting.h"
16
#include "nsString.h"
17
#include "nsWrapperCache.h"
18
19
#include "WebGLObjectModel.h"
20
21
namespace mozilla {
22
23
namespace webgl {
24
class ShaderValidator;
25
} // namespace webgl
26
27
class WebGLShader final
28
    : public nsWrapperCache
29
    , public WebGLRefCountedObject<WebGLShader>
30
    , public LinkedListElement<WebGLShader>
31
{
32
    friend class WebGLContext;
33
    friend class WebGLProgram;
34
35
public:
36
    WebGLShader(WebGLContext* webgl, GLenum type);
37
38
protected:
39
    ~WebGLShader();
40
41
public:
42
    // GL funcs
43
    void CompileShader();
44
    JS::Value GetShaderParameter(GLenum pname) const;
45
    void GetShaderInfoLog(nsAString* out) const;
46
    void GetShaderSource(nsAString* out) const;
47
    void GetShaderTranslatedSource(nsAString* out) const;
48
    void ShaderSource(const nsAString& source);
49
50
    // Util funcs
51
    bool CanLinkTo(const WebGLShader* prev, nsCString* const out_log) const;
52
    size_t CalcNumSamplerUniforms() const;
53
    size_t NumAttributes() const;
54
    bool FindAttribUserNameByMappedName(const nsACString& mappedName,
55
                                        nsCString* const out_userName) const;
56
    bool FindVaryingByMappedName(const nsACString& mappedName,
57
                                 nsCString* const out_userName,
58
                                 bool* const out_isArray) const;
59
    bool FindUniformByMappedName(const nsACString& mappedName,
60
                                 nsCString* const out_userName,
61
                                 bool* const out_isArray) const;
62
    bool UnmapUniformBlockName(const nsACString& baseMappedName,
63
                               nsCString* const out_baseUserName) const;
64
65
    void EnumerateFragOutputs(std::map<nsCString, const nsCString> &out_FragOutputs) const;
66
67
0
    bool IsCompiled() const {
68
0
        return mTranslationSuccessful && mCompilationSuccessful;
69
0
    }
70
71
private:
72
    void BindAttribLocation(GLuint prog, const nsCString& userName, GLuint index) const;
73
    void MapTransformFeedbackVaryings(const std::vector<nsString>& varyings,
74
                                      std::vector<std::string>* out_mappedVaryings) const;
75
76
public:
77
    // Other funcs
78
    size_t SizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf) const;
79
    void Delete();
80
81
0
    WebGLContext* GetParentObject() const { return mContext; }
82
83
    virtual JSObject* WrapObject(JSContext* js, JS::Handle<JSObject*> givenProto) override;
84
85
    NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(WebGLShader)
86
    NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(WebGLShader)
87
88
public:
89
    const GLuint mGLName;
90
    const GLenum mType;
91
92
protected:
93
    nsString mSource;
94
    nsCString mCleanSource;
95
96
    UniquePtr<webgl::ShaderValidator> mValidator;
97
    nsCString mValidationLog;
98
    bool mTranslationSuccessful;
99
    nsCString mTranslatedSource;
100
101
    bool mCompilationSuccessful;
102
    nsCString mCompilationLog;
103
};
104
105
} // namespace mozilla
106
107
#endif // WEBGL_SHADER_H_