52 {
55
57 public:
58 FPCallbacks(Impl*
self,
60 const char* inputColor,
62 const uint8_t* uniformData,
63 const Specialized* specialized)
66 , fInputColor(inputColor)
68 , fUniformData(uniformData)
69 , fSpecialized(specialized) {}
70
74
75
77 return std::string(var->
name());
78 }
79
81 size_t sizeInBytes =
type->slotCount() *
sizeof(
float);
82 const float* floatData = reinterpret_cast<const float*>(fUniformData);
83 const int* intData = reinterpret_cast<const int*>(fUniformData);
84 fUniformData += sizeInBytes;
85
86 bool isArray = false;
87 if (
type->isArray()) {
89 isArray = true;
90 }
91
94
96 SkASSERTF(!isArray,
"specializing array uniforms is not allowed");
99
101 size_t slots =
type->slotCount();
102 for (
size_t i = 0;
i < slots; ++
i) {
106 }
109 }
110
111 const char* uniformName = nullptr;
112 auto handle =
113 fArgs.fUniformHandler->addUniformArray(&fArgs.fFp.cast<
GrSkSLFP>(),
115 gpuType,
118 &uniformName);
119 fSelf->fUniformHandles.push_back(handle);
120 return std::string(uniformName);
121 }
122
123 std::string getMangledName(
const char*
name)
override {
124 return std::string(fArgs.fFragBuilder->getMangledFunctionName(
name).c_str());
125 }
126
127 void defineFunction(const char* decl, const char* body, bool isMain) override {
128 if (isMain) {
129 fArgs.fFragBuilder->codeAppend(body);
130 } else {
131 fArgs.fFragBuilder->emitFunction(decl, body);
132 }
133 }
134
135 void declareFunction(const char* decl) override {
136 fArgs.fFragBuilder->emitFunctionPrototype(decl);
137 }
138
139 void defineStruct(const char* definition) override {
140 fArgs.fFragBuilder->definitionAppend(definition);
141 }
142
143 void declareGlobal(const char* declaration) override {
144 fArgs.fFragBuilder->definitionAppend(declaration);
145 }
146
147 std::string sampleShader(int index, std::string coords) override {
148
149
150
151
152
153
154
155
156
157
158
159
162 coords.clear();
163 }
164 return child ? std::string(fSelf->invokeChild(index, fInputColor, fArgs, coords)
165 .c_str())
166 :
std::string(
"half4(0)");
167 }
168
169 std::string sampleColorFilter(
int index, std::string
color)
override {
170 return std::string(fSelf->invokeChild(index,
172 fArgs)
173 .c_str());
174 }
175
176 std::string sampleBlender(
int index, std::string
src, std::string
dst)
override {
177 if (!fSelf->childProcessor(index)) {
179 }
180 return std::string(
181 fSelf->invokeChild(index,
src.c_str(),
dst.c_str(), fArgs).c_str());
182 }
183
184
185
186 std::string toLinearSrgb(std::string
color)
override {
188 if (
fp.fToLinearSrgbChildIndex < 0) {
190 }
192 SkString xformedColor = fSelf->invokeChild(
193 fp.fToLinearSrgbChildIndex,
color.c_str(), fArgs);
195 }
196
197 std::string fromLinearSrgb(std::string
color)
override {
199 if (
fp.fFromLinearSrgbChildIndex < 0) {
201 }
203 SkString xformedColor = fSelf->invokeChild(
204 fp.fFromLinearSrgbChildIndex,
color.c_str(), fArgs);
206 }
207
208 Impl* fSelf;
209 EmitArgs& fArgs;
210 const char* fInputColor;
212 const uint8_t* fUniformData;
213 const Specialized* fSpecialized;
214 int fUniformIndex = 0;
215 };
216
217
218
219 if (
fp.fInputChildIndex >= 0) {
220 args.fFragBuilder->codeAppendf(
"%s = %s;\n",
222 this->invokeChild(
fp.fInputChildIndex,
args).c_str());
223 }
224
225 if (
fp.fEffect->allowBlender()) {
226
227
228 if (
fp.fDestColorChildIndex >= 0) {
229 args.fFragBuilder->codeAppendf(
230 "%s = %s;\n",
232 this->invokeChild(
fp.fDestColorChildIndex,
args.fDestColor,
args).c_str());
233 }
234 } else {
235
237 }
238
239
240
241
242
244 if (
fp.fEffect->samplesOutsideMain()) {
245 GrShaderVar inputColorCopy(
args.fFragBuilder->getMangledFunctionName(
"inColor"),
247 args.fFragBuilder->declareGlobal(inputColorCopy);
248 inputColorName = inputColorCopy.getName();
249 args.fFragBuilder->codeAppendf(
"%s = %s;\n", inputColorName.
c_str(),
args.fInputColor);
250 } else {
251 inputColorName =
args.fFragBuilder->newTmpVarName(
"inColor");
252 args.fFragBuilder->codeAppendf(
253 "half4 %s = %s;\n", inputColorName.
c_str(),
args.fInputColor);
254 }
255
256
257
258 const char* coords = "float2(0)";
260 if (
fp.usesSampleCoordsDirectly()) {
261 coordsVarName =
args.fFragBuilder->newTmpVarName(
"coords");
262 coords = coordsVarName.
c_str();
263 args.fFragBuilder->codeAppendf(
"float2 %s = %s;\n", coords,
args.fSampleCoord);
264 }
265
266 FPCallbacks callbacks(this,
268 inputColorName.
c_str(),
269 *program.fContext,
273 program, coords,
args.fInputColor,
args.fDestColor, &callbacks);
274 }
SkAssertResult(font.textToGlyphs("Hello", 5, SkTextEncoding::kUTF8, glyphs, std::size(glyphs))==count)
#define SkASSERTF(cond, fmt,...)
const char * SkSLTypeString(SkSLType t)
static constexpr bool SkSLTypeIsFloatType(SkSLType type)
GrFragmentProcessor * childProcessor(int index)
const SkSL::SampleUsage & sampleUsage() const
const char * name() const override
bool isPassThrough() const
std::string_view name() const
const Type & type() const
bool isEffectChild() const
virtual int columns() const
const char * c_str() const
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
void ConvertProgram(const Program &program, const char *sampleCoords, const char *inputColor, const char *destColor, Callbacks *callbacks)
std::string printf(const char *fmt,...) SK_PRINTF_LIKE(1
bool type_to_sksltype(const Context &context, const Type &type, SkSLType *outType)
std::string to_string(float value)
static SkString to_string(int n)