Move setSampleMatrix and setSampledWithExplicitCoords into child registration
Bug: skia:10396
Change-Id: I0c117ab4d95737b76dec5bce16103b9058218fb8
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/297065
Commit-Queue: Michael Ludwig <michaelludwig@google.com>
Reviewed-by: Brian Salomon <bsalomon@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
diff --git a/src/sksl/SkSLHCodeGenerator.cpp b/src/sksl/SkSLHCodeGenerator.cpp
index f53b572..5d4195b 100644
--- a/src/sksl/SkSLHCodeGenerator.cpp
+++ b/src/sksl/SkSLHCodeGenerator.cpp
@@ -282,35 +282,45 @@
} else {
this->writef(" SkASSERT(%s);", String(param->fName).c_str());
}
- if (fSectionAndParameterHelper.hasCoordOverrides(*param)) {
- this->writef(" %s->setSampledWithExplicitCoords();",
- String(param->fName).c_str());
- }
+
+ bool explicitCoords = fSectionAndParameterHelper.hasCoordOverrides(*param);
SampleMatrix matrix = SampleMatrix::Make(fProgram, *param);
- switch (matrix.fKind) {
- case SampleMatrix::Kind::kVariable:
- this->writef(" %s->setSampleMatrix(SkSL::SampleMatrix("
- "SkSL::SampleMatrix::Kind::kVariable));",
- String(param->fName).c_str());
- break;
- case SampleMatrix::Kind::kConstantOrUniform:
- this->writef(" %s->setSampleMatrix(SkSL::SampleMatrix("
- "SkSL::SampleMatrix::Kind::kConstantOrUniform, this, \"%s\"));",
- String(param->fName).c_str(),
- matrix.fExpression.c_str());
- break;
- case SampleMatrix::Kind::kMixed:
- this->writef(" %s->setSampleMatrix(SkSL::SampleMatrix("
- "SkSL::SampleMatrix::Kind::kMixed, this, \"%s\"));",
- String(param->fName).c_str(),
- matrix.fExpression.c_str());
- break;
- case SampleMatrix::Kind::kNone:
- break;
+
+ String registerFunc;
+ String matrixArg;
+ String explicitArg;
+
+ if (explicitCoords && matrix.fKind == SampleMatrix::Kind::kNone) {
+ registerFunc = "registerExplicitlySampledChild";
+ } else {
+ registerFunc = "registerChild";
+ if (explicitCoords) {
+ explicitArg = ", true";
+ }
+ switch(matrix.fKind) {
+ case SampleMatrix::Kind::kVariable:
+ matrixArg.appendf(", SkSL::SampleMatrix::MakeVariable()");
+ break;
+ case SampleMatrix::Kind::kConstantOrUniform:
+ matrixArg.appendf(", SkSL::SampleMatrix::MakeConstUniform(\"%s\")",
+ matrix.fExpression.c_str());
+ break;
+ case SampleMatrix::Kind::kMixed:
+ // Mixed is only produced when combining FPs, not from analysis of sksl
+ SkASSERT(false);
+ break;
+ case SampleMatrix::Kind::kNone:
+ break;
+ }
}
- this->writef(" %s_index = this->registerChildProcessor(std::move(%s));",
+
+ this->writef(" %s_index = this->%s(std::move(%s)%s%s);",
FieldName(String(param->fName).c_str()).c_str(),
- String(param->fName).c_str());
+ registerFunc.c_str(),
+ String(param->fName).c_str(),
+ matrixArg.c_str(),
+ explicitArg.c_str());
+
if (param->fType.kind() == Type::kNullable_Kind) {
this->writef(" }");
}