Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
SkSLTypeShared.h
Go to the documentation of this file.
1/*
2 * Copyright 2022 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 SkSLTypeShared_DEFINED
9#define SkSLTypeShared_DEFINED
10
12
13/**
14 * Types of shader-language-specific boxed variables we can create.
15 */
16enum class SkSLType : char {
17 kVoid,
18 kBool,
19 kBool2,
20 kBool3,
21 kBool4,
22 kShort,
23 kShort2,
24 kShort3,
25 kShort4,
26 kUShort,
30 kFloat,
31 kFloat2,
32 kFloat3,
33 kFloat4,
37 kHalf,
38 kHalf2,
39 kHalf3,
40 kHalf4,
44 kInt,
45 kInt2,
46 kInt3,
47 kInt4,
48 kUInt,
49 kUInt2,
50 kUInt3,
51 kUInt4,
57 kInput,
58
60};
61static const int kSkSLTypeCount = static_cast<int>(SkSLType::kLast) + 1;
62
63/** Returns the SkSL typename for this type. */
64const char* SkSLTypeString(SkSLType t);
65
66/** Is the shading language type float (including vectors/matrices)? */
67static constexpr bool SkSLTypeIsFloatType(SkSLType type) {
68 switch (type) {
76 case SkSLType::kHalf:
83 return true;
84
85 case SkSLType::kVoid:
89 case SkSLType::kBool:
101 case SkSLType::kInt:
102 case SkSLType::kInt2:
103 case SkSLType::kInt3:
104 case SkSLType::kInt4:
105 case SkSLType::kUInt:
106 case SkSLType::kUInt2:
107 case SkSLType::kUInt3:
108 case SkSLType::kUInt4:
111 case SkSLType::kInput:
112 return false;
113 }
115}
116
117/** Is the shading language type integral (including vectors)? */
118static constexpr bool SkSLTypeIsIntegralType(SkSLType type) {
119 switch (type) {
120 case SkSLType::kShort:
128 case SkSLType::kInt:
129 case SkSLType::kInt2:
130 case SkSLType::kInt3:
131 case SkSLType::kInt4:
132 case SkSLType::kUInt:
133 case SkSLType::kUInt2:
134 case SkSLType::kUInt3:
135 case SkSLType::kUInt4:
136 return true;
137
138 case SkSLType::kFloat:
145 case SkSLType::kHalf:
146 case SkSLType::kHalf2:
147 case SkSLType::kHalf3:
148 case SkSLType::kHalf4:
152 case SkSLType::kVoid:
156 case SkSLType::kBool:
157 case SkSLType::kBool2:
158 case SkSLType::kBool3:
159 case SkSLType::kBool4:
162 case SkSLType::kInput:
163 return false;
164 }
166}
167
168/** If the type represents a single value or vector return the vector length; otherwise, -1. */
169static constexpr int SkSLTypeVecLength(SkSLType type) {
170 switch (type) {
171 case SkSLType::kFloat:
172 case SkSLType::kHalf:
173 case SkSLType::kBool:
174 case SkSLType::kShort:
176 case SkSLType::kInt:
177 case SkSLType::kUInt:
178 return 1;
179
181 case SkSLType::kHalf2:
182 case SkSLType::kBool2:
185 case SkSLType::kInt2:
186 case SkSLType::kUInt2:
187 return 2;
188
190 case SkSLType::kHalf3:
191 case SkSLType::kBool3:
194 case SkSLType::kInt3:
195 case SkSLType::kUInt3:
196 return 3;
197
199 case SkSLType::kHalf4:
200 case SkSLType::kBool4:
203 case SkSLType::kInt4:
204 case SkSLType::kUInt4:
205 return 4;
206
213 case SkSLType::kVoid:
219 case SkSLType::kInput:
220 return -1;
221 }
223}
224
225/**
226 * Is the shading language type supported as a uniform (ie, does it have a corresponding set
227 * function on GrGLSLProgramDataManager)?
228 */
230 // This is almost "IsFloatType || IsIntegralType" but excludes non-full precision int types.
231 switch(type) {
232 case SkSLType::kFloat:
239 case SkSLType::kHalf:
240 case SkSLType::kHalf2:
241 case SkSLType::kHalf3:
242 case SkSLType::kHalf4:
246
247 case SkSLType::kInt:
248 case SkSLType::kInt2:
249 case SkSLType::kInt3:
250 case SkSLType::kInt4:
251 case SkSLType::kUInt:
252 case SkSLType::kUInt2:
253 case SkSLType::kUInt3:
254 case SkSLType::kUInt4:
255 return true;
256
257 default:
258 return false;
259 }
260}
261
262/** Is the shading language type full precision? */
264
265/** If the type represents a square matrix, return its size; otherwise, -1. */
267
268/** If the type represents a square matrix, return its size; otherwise, -1. */
270
271#endif // SkSLTypeShared_DEFINED
#define SkUNREACHABLE
Definition SkAssert.h:135
static constexpr bool SkSLTypeCanBeUniformValue(SkSLType type)
static constexpr bool SkSLTypeIsIntegralType(SkSLType type)
bool SkSLTypeIsCombinedSamplerType(SkSLType type)
int SkSLTypeMatrixSize(SkSLType type)
bool SkSLTypeIsFullPrecisionNumericType(SkSLType type)
static const int kSkSLTypeCount
SkSLType
@ kTextureExternalSampler
@ kTexture2DSampler
@ kTexture2DRectSampler
const char * SkSLTypeString(SkSLType t)
static constexpr bool SkSLTypeIsFloatType(SkSLType type)
static constexpr int SkSLTypeVecLength(SkSLType type)