Honor return value of `registerChildProcessor` when creating child FPs.
The current implementation ignores return value from
`registerChildProcessor` and, surprisingly, assumes that a cloned FP
index will match the original FP index. This version honors the return
value.
(In practice, I have not seen any cases where the current implementation
has caused actual breakage.)
Updating common code-gen had large ripple effects in the SkSL unit
tests. While repairing the tests, I also took the opportunity to use
raw-strings to pass the source SkSL text, and annotated the `expectedH`
and `expectedCPP` blocks to make the tests easier to understand at a
glance.
Change-Id: I71be69d9e4620963b3ef49ad8e0dba3b40af7f4f
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/295452
Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
Commit-Queue: John Stiles <johnstiles@google.com>
diff --git a/src/sksl/SkSLHCodeGenerator.cpp b/src/sksl/SkSLHCodeGenerator.cpp
index ebe05e8..c4a7748 100644
--- a/src/sksl/SkSLHCodeGenerator.cpp
+++ b/src/sksl/SkSLHCodeGenerator.cpp
@@ -272,7 +272,7 @@
this->writef(" {\n");
this->writeSection(CONSTRUCTOR_CODE_SECTION);
int samplerCount = 0;
- for (const auto& param : fSectionAndParameterHelper.getParameters()) {
+ for (const Variable* param : fSectionAndParameterHelper.getParameters()) {
if (param->fType.kind() == Type::kSampler_Kind) {
++samplerCount;
} else if (param->fType.nonnullable() == *fContext.fFragmentProcessor_Type) {
@@ -281,8 +281,6 @@
} else {
this->writef(" SkASSERT(%s);", String(param->fName).c_str());
}
- this->writef(" %s_index = this->numChildProcessors();",
- FieldName(String(param->fName).c_str()).c_str());
if (fSectionAndParameterHelper.hasCoordOverrides(*param)) {
this->writef(" %s->setSampledWithExplicitCoords();",
String(param->fName).c_str());
@@ -309,7 +307,8 @@
case SampleMatrix::Kind::kNone:
break;
}
- this->writef(" this->registerChildProcessor(std::move(%s));",
+ this->writef(" %s_index = this->registerChildProcessor(std::move(%s));",
+ FieldName(String(param->fName).c_str()).c_str(),
String(param->fName).c_str());
if (param->fType.kind() == Type::kNullable_Kind) {
this->writef(" }");
@@ -367,15 +366,18 @@
this->writef("%s\n", GetHeader(fProgram, fErrors).c_str());
this->writef(kFragmentProcessorHeader, fFullName.c_str());
this->writef("#ifndef %s_DEFINED\n"
- "#define %s_DEFINED\n",
+ "#define %s_DEFINED\n"
+ "\n",
fFullName.c_str(),
fFullName.c_str());
- this->writef("#include \"include/core/SkTypes.h\"\n");
- this->writef("#include \"include/core/SkM44.h\"\n");
+ this->writef("#include \"include/core/SkM44.h\"\n"
+ "#include \"include/core/SkTypes.h\"\n"
+ "\n");
this->writeSection(HEADER_SECTION);
this->writef("\n"
"#include \"src/gpu/GrCoordTransform.h\"\n"
- "#include \"src/gpu/GrFragmentProcessor.h\"\n");
+ "#include \"src/gpu/GrFragmentProcessor.h\"\n"
+ "\n");
this->writef("class %s : public GrFragmentProcessor {\n"
"public:\n",
fFullName.c_str());