Re-land "converted GrCircleBlurFragmentProcessor to sksl"
This reverts commit 818ac5a00dfd570d2b291b7524a70ecd4ef55770.
Bug: skia:
Change-Id: I9bd8a06bd2dbb40bd261d64d6d04daf864bc00a5
Reviewed-on: https://skia-review.googlesource.com/22075
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
diff --git a/src/sksl/SkSLCPPCodeGenerator.cpp b/src/sksl/SkSLCPPCodeGenerator.cpp
index 09622f3..72dcd01 100644
--- a/src/sksl/SkSLCPPCodeGenerator.cpp
+++ b/src/sksl/SkSLCPPCodeGenerator.cpp
@@ -161,6 +161,19 @@
}
}
+String CPPCodeGenerator::getSamplerHandle(const Variable& var) {
+ int samplerCount = 0;
+ for (const auto param : fSectionAndParameterHelper.fParameters) {
+ if (&var == param) {
+ return "args.fTexSamplers[" + to_string(samplerCount) + "]";
+ }
+ if (param->fType.kind() == Type::kSampler_Kind) {
+ ++samplerCount;
+ }
+ }
+ ABORT("should have found sampler in parameters\n");
+}
+
void CPPCodeGenerator::writeVariableReference(const VariableReference& ref) {
switch (ref.fVariable.fModifiers.fLayout.fBuiltin) {
case SK_INCOLOR_BUILTIN:
@@ -173,20 +186,10 @@
break;
default:
if (ref.fVariable.fType.kind() == Type::kSampler_Kind) {
- int samplerCount = 0;
- for (const auto param : fSectionAndParameterHelper.fParameters) {
- if (&ref.fVariable == param) {
- this->write("%s");
- fFormatArgs.push_back("fragBuilder->getProgramBuilder()->samplerVariable("
- "args.fTexSamplers[" + to_string(samplerCount) +
- "]).c_str()");
- return;
- }
- if (param->fType.kind() == Type::kSampler_Kind) {
- ++samplerCount;
- }
- }
- ABORT("should have found sampler in parameters\n");
+ this->write("%s");
+ fFormatArgs.push_back("fragBuilder->getProgramBuilder()->samplerVariable(" +
+ this->getSamplerHandle(ref.fVariable) + ").c_str()");
+ return;
}
if (ref.fVariable.fModifiers.fFlags & Modifiers::kUniform_Flag) {
this->write("%s");
@@ -222,6 +225,18 @@
}
}
+void CPPCodeGenerator::writeFunctionCall(const FunctionCall& c) {
+ INHERITED::writeFunctionCall(c);
+ if (c.fFunction.fBuiltin && c.fFunction.fName == "texture") {
+ this->write(".%s");
+ ASSERT(c.fArguments.size() >= 1);
+ ASSERT(c.fArguments[0]->fKind == Expression::kVariableReference_Kind);
+ String sampler = this->getSamplerHandle(((VariableReference&) *c.fArguments[0]).fVariable);
+ fFormatArgs.push_back("fragBuilder->getProgramBuilder()->samplerSwizzle(" + sampler +
+ ").c_str()");
+ }
+}
+
void CPPCodeGenerator::writeFunction(const FunctionDefinition& f) {
if (f.fDeclaration.fName == "main") {
fFunctionHeader = "";
@@ -542,7 +557,8 @@
const char* baseName = fName.c_str();
const char* fullName = fFullName.c_str();
this->writef(kFragmentProcessorHeader, fullName);
- this->writef("#include \"%s.h\"\n", fullName);
+ this->writef("#include \"%s.h\"\n"
+ "#if SK_SUPPORT_GPU\n", fullName);
this->writeSection(CPP_SECTION);
this->writef("#include \"glsl/GrGLSLColorSpaceXformHelper.h\"\n"
"#include \"glsl/GrGLSLFragmentProcessor.h\"\n"
@@ -593,6 +609,7 @@
"}\n");
this->writeTest();
this->writeSection(CPP_END_SECTION);
+ this->write("#endif\n");
result &= 0 == fErrors.errorCount();
return result;
}
diff --git a/src/sksl/SkSLCPPCodeGenerator.h b/src/sksl/SkSLCPPCodeGenerator.h
index c7388ad..0f6da5f 100644
--- a/src/sksl/SkSLCPPCodeGenerator.h
+++ b/src/sksl/SkSLCPPCodeGenerator.h
@@ -39,6 +39,10 @@
void writeVariableReference(const VariableReference& ref) override;
+ String getSamplerHandle(const Variable& var);
+
+ void writeFunctionCall(const FunctionCall& c) override;
+
void writeFunction(const FunctionDefinition& f) override;
void writeSetting(const Setting& s) override;
diff --git a/src/sksl/SkSLGLSLCodeGenerator.h b/src/sksl/SkSLGLSLCodeGenerator.h
index aaf0369..5716bde 100644
--- a/src/sksl/SkSLGLSLCodeGenerator.h
+++ b/src/sksl/SkSLGLSLCodeGenerator.h
@@ -128,7 +128,7 @@
void writeMinAbsHack(Expression& absExpr, Expression& otherExpr);
- void writeFunctionCall(const FunctionCall& c);
+ virtual void writeFunctionCall(const FunctionCall& c);
void writeConstructor(const Constructor& c);
diff --git a/src/sksl/SkSLHCodeGenerator.cpp b/src/sksl/SkSLHCodeGenerator.cpp
index 405fb0e..cd3f7f2 100644
--- a/src/sksl/SkSLHCodeGenerator.cpp
+++ b/src/sksl/SkSLHCodeGenerator.cpp
@@ -201,6 +201,8 @@
"#define %s_DEFINED\n",
fFullName.c_str(),
fFullName.c_str());
+ this->writef("#include \"SkTypes.h\"\n"
+ "#if SK_SUPPORT_GPU\n");
this->writeSection(HEADER_SECTION);
this->writef("#include \"GrFragmentProcessor.h\"\n"
"#include \"GrCoordTransform.h\"\n"
@@ -231,7 +233,8 @@
this->writef(" typedef GrFragmentProcessor INHERITED;\n"
"};\n");
this->writeSection(HEADER_END_SECTION);
- this->writef("#endif\n");
+ this->writef("#endif\n"
+ "#endif\n");
return 0 == fErrors.errorCount();
}