Flutter Engine
The Flutter Engine
GrShaderVar.h
Go to the documentation of this file.
1/*
2 * Copyright 2016 Google Inc.
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 GrShaderVar_DEFINED
9#define GrShaderVar_DEFINED
10
14
15struct GrShaderCaps;
16
17/**
18 * Represents a variable in a shader
19 */
21public:
22 enum class TypeModifier {
23 None,
24 Out,
25 In,
26 InOut,
27 Uniform,
28 };
29
30 /** Values for array count that have special meaning. We allow 1-sized arrays. */
31 enum {
32 kNonArray = 0, // not an array
33 };
34
35 /** Defaults to a void with no type modifier or layout qualifier. */
37 : fType(SkSLType::kVoid)
38 , fTypeModifier(TypeModifier::None)
39 , fCount(kNonArray) {}
40
42 : fType(type)
43 , fTypeModifier(TypeModifier::None)
44 , fCount(arrayCount)
45 , fName(std::move(name)) {}
46 GrShaderVar(const char* name, SkSLType type, int arrayCount = kNonArray)
47 : GrShaderVar(SkString(name), type, arrayCount) {}
48
50 : fType(type)
51 , fTypeModifier(typeModifier)
52 , fCount(kNonArray)
53 , fName(std::move(name)) {}
54 GrShaderVar(const char* name, SkSLType type, TypeModifier typeModifier)
55 : GrShaderVar(SkString(name), type, typeModifier) {}
56
57 GrShaderVar(SkString name, SkSLType type, TypeModifier typeModifier, int arrayCount)
58 : fType(type)
59 , fTypeModifier(typeModifier)
60 , fCount(arrayCount)
61 , fName(std::move(name)) {}
62
63 GrShaderVar(SkString name, SkSLType type, TypeModifier typeModifier, int arrayCount,
64 SkString layoutQualifier, SkString extraModifier)
65 : fType(type)
66 , fTypeModifier(typeModifier)
67 , fCount(arrayCount)
68 , fName(std::move(name))
69 , fLayoutQualifier(std::move(layoutQualifier))
70 , fExtraModifiers(std::move(extraModifier)) {}
71
72 GrShaderVar(const GrShaderVar&) = default;
73 GrShaderVar& operator=(const GrShaderVar&) = default;
76
77 /** Sets as a non-array. */
78 void set(SkSLType type, const char* name) {
80 fType = type;
81 fName = name;
82 }
83
84 /** Is the var an array. */
85 bool isArray() const { return kNonArray != fCount; }
86
87 /** Get the array length. */
88 int getArrayCount() const { return fCount; }
89
90 /** Get the name. */
91 const SkString& getName() const { return fName; }
92
93 /** Shortcut for this->getName().c_str(); */
94 const char* c_str() const { return this->getName().c_str(); }
95
96 /** Get the type. */
97 SkSLType getType() const { return fType; }
98
99 TypeModifier getTypeModifier() const { return fTypeModifier; }
100 void setTypeModifier(TypeModifier type) { fTypeModifier = type; }
101
102 /** Appends to the layout qualifier. */
103 void addLayoutQualifier(const char* layoutQualifier) {
104 if (!layoutQualifier || !strlen(layoutQualifier)) {
105 return;
106 }
107 if (fLayoutQualifier.isEmpty()) {
108 fLayoutQualifier = layoutQualifier;
109 } else {
110 fLayoutQualifier.appendf(", %s", layoutQualifier);
111 }
112 }
113
114 /** Appends to the modifiers. */
115 void addModifier(const char* modifier) {
116 if (!modifier || !strlen(modifier)) {
117 return;
118 }
119 if (fExtraModifiers.isEmpty()) {
120 fExtraModifiers = modifier;
121 } else {
122 fExtraModifiers.appendf(" %s", modifier);
123 }
124 }
125
126 /** Write a declaration of this variable to out. */
127 void appendDecl(const GrShaderCaps*, SkString* out) const;
128
129private:
130 SkSLType fType;
131 TypeModifier fTypeModifier;
132 int fCount;
133
134 SkString fName;
135 SkString fLayoutQualifier;
136 SkString fExtraModifiers;
137};
138
139#endif
#define SkASSERT(cond)
Definition: SkAssert.h:116
SkSLType
GLenum type
GrShaderVar & operator=(GrShaderVar &&)=default
SkSLType getType() const
Definition: GrShaderVar.h:97
void set(SkSLType type, const char *name)
Definition: GrShaderVar.h:78
int getArrayCount() const
Definition: GrShaderVar.h:88
GrShaderVar(const char *name, SkSLType type, int arrayCount=kNonArray)
Definition: GrShaderVar.h:46
GrShaderVar & operator=(const GrShaderVar &)=default
void addModifier(const char *modifier)
Definition: GrShaderVar.h:115
GrShaderVar(SkString name, SkSLType type, TypeModifier typeModifier, int arrayCount)
Definition: GrShaderVar.h:57
void setTypeModifier(TypeModifier type)
Definition: GrShaderVar.h:100
GrShaderVar(SkString name, SkSLType type, TypeModifier typeModifier, int arrayCount, SkString layoutQualifier, SkString extraModifier)
Definition: GrShaderVar.h:63
bool isArray() const
Definition: GrShaderVar.h:85
const char * c_str() const
Definition: GrShaderVar.h:94
void addLayoutQualifier(const char *layoutQualifier)
Definition: GrShaderVar.h:103
GrShaderVar(SkString name, SkSLType type, TypeModifier typeModifier)
Definition: GrShaderVar.h:49
GrShaderVar(const char *name, SkSLType type, TypeModifier typeModifier)
Definition: GrShaderVar.h:54
GrShaderVar(const GrShaderVar &)=default
GrShaderVar(GrShaderVar &&)=default
TypeModifier getTypeModifier() const
Definition: GrShaderVar.h:99
GrShaderVar(SkString name, SkSLType type, int arrayCount=kNonArray)
Definition: GrShaderVar.h:41
const SkString & getName() const
Definition: GrShaderVar.h:91
void appendDecl(const GrShaderCaps *, SkString *out) const
Definition: GrShaderVar.cpp:23
bool isEmpty() const
Definition: SkString.h:130
const char * c_str() const
Definition: SkString.h:133
void void void appendf(const char format[],...) SK_PRINTF_LIKE(2
Definition: SkString.cpp:550
DEF_SWITCHES_START aot vmservice shared library name
Definition: switches.h:32
Definition: ref_ptr.h:256