Coverage Report

Created: 2021-08-22 09:07

/src/skia/include/sksl/DSLType.h
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright 2020 Google LLC
3
 *
4
 * Use of this source code is governed by a BSD-style license that can be
5
 * found in the LICENSE file.
6
 */
7
8
#ifndef SKSL_DSL_TYPE
9
#define SKSL_DSL_TYPE
10
11
#include "include/core/SkSpan.h"
12
#include "include/private/SkSLString.h"
13
#include "include/sksl/DSLExpression.h"
14
#include "include/sksl/DSLModifiers.h"
15
16
#include <cstdint>
17
18
namespace SkSL {
19
20
class Type;
21
22
namespace dsl {
23
24
class DSLExpression;
25
class DSLField;
26
class DSLVarBase;
27
28
enum TypeConstant : uint8_t {
29
    kBool_Type,
30
    kBool2_Type,
31
    kBool3_Type,
32
    kBool4_Type,
33
    kHalf_Type,
34
    kHalf2_Type,
35
    kHalf3_Type,
36
    kHalf4_Type,
37
    kHalf2x2_Type,
38
    kHalf3x2_Type,
39
    kHalf4x2_Type,
40
    kHalf2x3_Type,
41
    kHalf3x3_Type,
42
    kHalf4x3_Type,
43
    kHalf2x4_Type,
44
    kHalf3x4_Type,
45
    kHalf4x4_Type,
46
    kFloat_Type,
47
    kFloat2_Type,
48
    kFloat3_Type,
49
    kFloat4_Type,
50
    kFragmentProcessor_Type,
51
    kFloat2x2_Type,
52
    kFloat3x2_Type,
53
    kFloat4x2_Type,
54
    kFloat2x3_Type,
55
    kFloat3x3_Type,
56
    kFloat4x3_Type,
57
    kFloat2x4_Type,
58
    kFloat3x4_Type,
59
    kFloat4x4_Type,
60
    kInt_Type,
61
    kInt2_Type,
62
    kInt3_Type,
63
    kInt4_Type,
64
    kShader_Type,
65
    kShort_Type,
66
    kShort2_Type,
67
    kShort3_Type,
68
    kShort4_Type,
69
    kUInt_Type,
70
    kUInt2_Type,
71
    kUInt3_Type,
72
    kUInt4_Type,
73
    kUShort_Type,
74
    kUShort2_Type,
75
    kUShort3_Type,
76
    kUShort4_Type,
77
    kVoid_Type,
78
};
79
80
class DSLType {
81
public:
82
    DSLType(TypeConstant tc)
83
4.63k
        : fTypeConstant(tc) {}
84
85
    DSLType(const SkSL::Type* type)
86
0
        : fSkSLType(type) {}
87
88
    DSLType(skstd::string_view name);
89
90
    DSLType(skstd::string_view name, const DSLModifiers& modifiers);
91
92
    /**
93
     * Returns true if this type is a bool.
94
     */
95
    bool isBoolean() const;
96
97
    /**
98
     * Returns true if this is a numeric scalar type.
99
     */
100
    bool isNumber() const;
101
102
    /**
103
     * Returns true if this is a floating-point scalar type (float or half).
104
     */
105
    bool isFloat() const;
106
107
    /**
108
     * Returns true if this is a signed scalar type (int or short).
109
     */
110
    bool isSigned() const;
111
112
    /**
113
     * Returns true if this is an unsigned scalar type (uint or ushort).
114
     */
115
    bool isUnsigned() const;
116
117
    /**
118
     * Returns true if this is a signed or unsigned integer.
119
     */
120
    bool isInteger() const;
121
122
    /**
123
     * Returns true if this is a scalar type.
124
     */
125
    bool isScalar() const;
126
127
    /**
128
     * Returns true if this is a vector type.
129
     */
130
    bool isVector() const;
131
132
    /**
133
     * Returns true if this is a matrix type.
134
     */
135
    bool isMatrix() const;
136
137
    /**
138
     * Returns true if this is a array type.
139
     */
140
    bool isArray() const;
141
142
    /**
143
     * Returns true if this is a struct type.
144
     */
145
    bool isStruct() const;
146
147
    template<typename... Args>
148
    static DSLExpression Construct(DSLType type, DSLVarBase& var, Args&&... args) {
149
        DSLExpression argArray[] = {var, args...};
150
        return Construct(type, SkMakeSpan(argArray));
151
    }
152
153
    template<typename... Args>
154
778
    static DSLExpression Construct(DSLType type, DSLExpression expr, Args&&... args) {
155
778
        DSLExpression argArray[] = {std::move(expr), std::move(args)...};
156
778
        return Construct(type, SkMakeSpan(argArray));
157
778
    }
Unexecuted instantiation: SkSL::dsl::DSLExpression SkSL::dsl::DSLType::Construct<int, SkSL::dsl::DSLExpression>(SkSL::dsl::DSLType, SkSL::dsl::DSLExpression, int&&, SkSL::dsl::DSLExpression&&)
Unexecuted instantiation: SkSL::dsl::DSLExpression SkSL::dsl::DSLType::Construct<float, float>(SkSL::dsl::DSLType, SkSL::dsl::DSLExpression, float&&, float&&)
Unexecuted instantiation: SkSL::dsl::DSLExpression SkSL::dsl::DSLType::Construct<float&, float&, float&>(SkSL::dsl::DSLType, SkSL::dsl::DSLExpression, float&, float&, float&)
Unexecuted instantiation: SkSL::dsl::DSLExpression SkSL::dsl::DSLType::Construct<float&, float&, float&, float&, float&, float&, float&, float&>(SkSL::dsl::DSLType, SkSL::dsl::DSLExpression, float&, float&, float&, float&, float&, float&, float&, float&)
Unexecuted instantiation: SkSL::dsl::DSLExpression SkSL::dsl::DSLType::Construct<float&, float&, float&, float&, float&, float&, float&, float&, float&, float&, float&, float&, float&, float&, float&>(SkSL::dsl::DSLType, SkSL::dsl::DSLExpression, float&, float&, float&, float&, float&, float&, float&, float&, float&, float&, float&, float&, float&, float&, float&)
SkSL::dsl::DSLExpression SkSL::dsl::DSLType::Construct<SkSL::dsl::DSLPossibleExpression, SkSL::dsl::DSLExpression, SkSL::dsl::DSLExpression>(SkSL::dsl::DSLType, SkSL::dsl::DSLExpression, SkSL::dsl::DSLPossibleExpression&&, SkSL::dsl::DSLExpression&&, SkSL::dsl::DSLExpression&&)
Line
Count
Source
154
763
    static DSLExpression Construct(DSLType type, DSLExpression expr, Args&&... args) {
155
763
        DSLExpression argArray[] = {std::move(expr), std::move(args)...};
156
763
        return Construct(type, SkMakeSpan(argArray));
157
763
    }
SkSL::dsl::DSLExpression SkSL::dsl::DSLType::Construct<>(SkSL::dsl::DSLType, SkSL::dsl::DSLExpression)
Line
Count
Source
154
15
    static DSLExpression Construct(DSLType type, DSLExpression expr, Args&&... args) {
155
15
        DSLExpression argArray[] = {std::move(expr), std::move(args)...};
156
15
        return Construct(type, SkMakeSpan(argArray));
157
15
    }
158
159
    static DSLExpression Construct(DSLType type, SkSpan<DSLExpression> argArray);
160
161
private:
162
    const SkSL::Type& skslType() const;
163
164
    const SkSL::Type* fSkSLType = nullptr;
165
166
    TypeConstant fTypeConstant;
167
168
    friend DSLType Array(const DSLType& base, int count);
169
    friend DSLType Struct(skstd::string_view name, SkSpan<DSLField> fields);
170
    friend class DSLCore;
171
    friend class DSLFunction;
172
    friend class DSLVarBase;
173
    friend class DSLWriter;
174
};
175
176
#define TYPE(T)                                                                                    \
177
    template<typename... Args>                                                                     \
178
778
    DSLExpression T(Args&&... args) {                                                              \
179
778
        return DSLType::Construct(k ## T ## _Type, std::forward<Args>(args)...);                   \
180
778
    }
Unexecuted instantiation: SkSL::dsl::DSLExpression SkSL::dsl::Float4<SkSL::dsl::DSLPossibleExpression, int, SkSL::dsl::DSLExpression>(SkSL::dsl::DSLPossibleExpression&&, int&&, SkSL::dsl::DSLExpression&&)
SkSL::dsl::DSLExpression SkSL::dsl::Float4<SkSL::dsl::DSLExpression, SkSL::dsl::DSLPossibleExpression, SkSL::dsl::DSLExpression, SkSL::dsl::DSLExpression>(SkSL::dsl::DSLExpression&&, SkSL::dsl::DSLPossibleExpression&&, SkSL::dsl::DSLExpression&&, SkSL::dsl::DSLExpression&&)
Line
Count
Source
178
763
    DSLExpression T(Args&&... args) {                                                              \
179
763
        return DSLType::Construct(k ## T ## _Type, std::forward<Args>(args)...);                   \
180
763
    }
SkSL::dsl::DSLExpression SkSL::dsl::Bool<SkSL::dsl::DSLExpression>(SkSL::dsl::DSLExpression&&)
Line
Count
Source
178
15
    DSLExpression T(Args&&... args) {                                                              \
179
15
        return DSLType::Construct(k ## T ## _Type, std::forward<Args>(args)...);                   \
180
15
    }
Unexecuted instantiation: SkSL::dsl::DSLExpression SkSL::dsl::Half4<int>(int&&)
Unexecuted instantiation: SkSL::dsl::DSLExpression SkSL::dsl::Half3<SkSL::dsl::DSLExpression>(SkSL::dsl::DSLExpression&&)
181
182
#define VECTOR_TYPE(T)                                                                             \
183
    TYPE(T)                                                                                        \
184
    TYPE(T ## 2)                                                                                   \
185
    TYPE(T ## 3)                                                                                   \
186
    TYPE(T ## 4)
187
188
#define MATRIX_TYPE(T)                                                                             \
189
    TYPE(T ## 2x2)                                                                                 \
190
    TYPE(T ## 3x2)                                                                                 \
191
    TYPE(T ## 4x2)                                                                                 \
192
    TYPE(T ## 2x3)                                                                                 \
193
    TYPE(T ## 3x3)                                                                                 \
194
    TYPE(T ## 4x3)                                                                                 \
195
    TYPE(T ## 2x4)                                                                                 \
196
    TYPE(T ## 3x4)                                                                                 \
197
    TYPE(T ## 4x4)
198
199
VECTOR_TYPE(Bool)
200
VECTOR_TYPE(Float)
201
VECTOR_TYPE(Half)
202
VECTOR_TYPE(Int)
203
VECTOR_TYPE(UInt)
204
VECTOR_TYPE(Short)
205
VECTOR_TYPE(UShort)
206
207
MATRIX_TYPE(Float)
208
MATRIX_TYPE(Half)
209
210
#undef TYPE
211
#undef VECTOR_TYPE
212
#undef MATRIX_TYPE
213
214
DSLType Array(const DSLType& base, int count);
215
216
class DSLField {
217
public:
218
    DSLField(const DSLType type, skstd::string_view name)
219
0
        : DSLField(DSLModifiers(), type, name) {}
220
221
    DSLField(const DSLModifiers& modifiers, const DSLType type, skstd::string_view name)
222
        : fModifiers(modifiers)
223
        , fType(type)
224
0
        , fName(name) {}
225
226
private:
227
    DSLModifiers fModifiers;
228
    const DSLType fType;
229
    skstd::string_view fName;
230
231
    friend class DSLCore;
232
    friend DSLType Struct(skstd::string_view name, SkSpan<DSLField> fields);
233
};
234
235
DSLType Struct(skstd::string_view name, SkSpan<DSLField> fields);
236
237
template<typename... Field>
238
DSLType Struct(skstd::string_view name, Field... fields) {
239
    DSLField fieldTypes[] = {std::move(fields)...};
240
    return Struct(name, SkMakeSpan(fieldTypes));
241
}
242
243
} // namespace dsl
244
245
} // namespace SkSL
246
247
#endif