SkSL 'key' variables can now be controlled by 'when' expressions
Bug: skia:8880
Change-Id: I075ef57035b37250196d85bc6767eb877e445aa2
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/206698
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
diff --git a/src/sksl/SkSLHCodeGenerator.cpp b/src/sksl/SkSLHCodeGenerator.cpp
index e4f0acd..7127415 100644
--- a/src/sksl/SkSLHCodeGenerator.cpp
+++ b/src/sksl/SkSLHCodeGenerator.cpp
@@ -236,6 +236,18 @@
}
this->writef(")");
this->writeSection(INITIALIZERS_SECTION, "\n , ");
+ const auto transforms = fSectionAndParameterHelper.getSections(COORD_TRANSFORM_SECTION);
+ for (size_t i = 0; i < transforms.size(); ++i) {
+ const Section& s = *transforms[i];
+ String field = CoordTransformName(s.fArgument.c_str(), i);
+ if (s.fArgument.size()) {
+ this->writef("\n , %s(%s, %s.get())", field.c_str(), s.fText.c_str(),
+ FieldName(s.fArgument.c_str()).c_str());
+ }
+ else {
+ this->writef("\n , %s(%s)", field.c_str(), s.fText.c_str());
+ }
+ }
for (const auto& param : fSectionAndParameterHelper.getParameters()) {
String nameString(param->fName);
const char* name = nameString.c_str();
@@ -255,18 +267,6 @@
this->writef("\n , %s(%s)", FieldName(name).c_str(), name);
}
}
- const auto transforms = fSectionAndParameterHelper.getSections(COORD_TRANSFORM_SECTION);
- for (size_t i = 0; i < transforms.size(); ++i) {
- const Section& s = *transforms[i];
- String field = CoordTransformName(s.fArgument.c_str(), i);
- if (s.fArgument.size()) {
- this->writef("\n , %s(%s, %s.proxy())", field.c_str(), s.fText.c_str(),
- FieldName(s.fArgument.c_str()).c_str());
- }
- else {
- this->writef("\n , %s(%s)", field.c_str(), s.fText.c_str());
- }
- }
this->writef(" {\n");
this->writeSection(CONSTRUCTOR_CODE_SECTION);
int samplerCount = 0;
@@ -301,6 +301,12 @@
void HCodeGenerator::writeFields() {
this->writeSection(FIELDS_SECTION);
+ const auto transforms = fSectionAndParameterHelper.getSections(COORD_TRANSFORM_SECTION);
+ for (size_t i = 0; i < transforms.size(); ++i) {
+ const Section& s = *transforms[i];
+ this->writef(" GrCoordTransform %s;\n",
+ CoordTransformName(s.fArgument.c_str(), i).c_str());
+ }
for (const auto& param : fSectionAndParameterHelper.getParameters()) {
String name = FieldName(String(param->fName).c_str());
if (param->fType.nonnullable() == *fContext.fFragmentProcessor_Type) {
@@ -311,12 +317,6 @@
name.c_str());
}
}
- const auto transforms = fSectionAndParameterHelper.getSections(COORD_TRANSFORM_SECTION);
- for (size_t i = 0; i < transforms.size(); ++i) {
- const Section& s = *transforms[i];
- this->writef(" GrCoordTransform %s;\n",
- CoordTransformName(s.fArgument.c_str(), i).c_str());
- }
}
String HCodeGenerator::GetHeader(const Program& program, ErrorReporter& errors) {
@@ -355,27 +355,13 @@
}
}
this->writeSection(CLASS_SECTION);
- for (const auto& param : fSectionAndParameterHelper.getParameters()) {
- if (param->fType.kind() == Type::kSampler_Kind) {
- continue;
- }
- String nameString(param->fName);
- const char* name = nameString.c_str();
- if (param->fType.nonnullable() == *fContext.fFragmentProcessor_Type) {
- this->writef(" int %s_index() const { return %s_index; }\n", name,
- FieldName(name).c_str());
- } else {
- this->writef(" %s %s() const { return %s; }\n",
- AccessType(fContext, param->fType, param->fModifiers.fLayout).c_str(),
- name, FieldName(name).c_str());
- }
- }
this->writeMake();
this->writef(" %s(const %s& src);\n"
" std::unique_ptr<GrFragmentProcessor> clone() const override;\n"
- " const char* name() const override { return \"%s\"; }\n"
- "private:\n",
+ " const char* name() const override { return \"%s\"; }\n",
fFullName.c_str(), fFullName.c_str(), fName.c_str());
+ this->writeFields();
+ this->writef("private:\n");
this->writeConstructor();
this->writef(" GrGLSLFragmentProcessor* onCreateGLSLInstance() const override;\n"
" void onGetGLSLProcessorKey(const GrShaderCaps&,"
@@ -388,7 +374,6 @@
}
}
this->writef(" GR_DECLARE_FRAGMENT_PROCESSOR_TEST\n");
- this->writeFields();
this->writef(" typedef GrFragmentProcessor INHERITED;\n"
"};\n");
this->writeSection(HEADER_END_SECTION);