aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/sksl/SkSLCPPCodeGenerator.cpp
diff options
context:
space:
mode:
authorGravatar Ethan Nicholas <ethannicholas@google.com>2017-07-10 15:40:20 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-07-11 13:50:51 +0000
commitceb4d48ef4839aab9d99d0200dcfe403ccd0cdf3 (patch)
treefe8daf04d9a10810747e78e9a340e8d89ff90692 /src/sksl/SkSLCPPCodeGenerator.cpp
parent815486c42f1ca66c81e12d8ccc9fb142e3c10544 (diff)
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>
Diffstat (limited to 'src/sksl/SkSLCPPCodeGenerator.cpp')
-rw-r--r--src/sksl/SkSLCPPCodeGenerator.cpp47
1 files changed, 32 insertions, 15 deletions
diff --git a/src/sksl/SkSLCPPCodeGenerator.cpp b/src/sksl/SkSLCPPCodeGenerator.cpp
index 09622f3e4c..72dcd013a3 100644
--- a/src/sksl/SkSLCPPCodeGenerator.cpp
+++ b/src/sksl/SkSLCPPCodeGenerator.cpp
@@ -161,6 +161,19 @@ void CPPCodeGenerator::writeVarInitializer(const Variable& var, const Expression
}
}
+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 @@ void CPPCodeGenerator::writeVariableReference(const VariableReference& ref) {
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::writeVariableReference(const VariableReference& ref) {
}
}
+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 @@ bool CPPCodeGenerator::generateCode() {
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 @@ bool CPPCodeGenerator::generateCode() {
"}\n");
this->writeTest();
this->writeSection(CPP_END_SECTION);
+ this->write("#endif\n");
result &= 0 == fErrors.errorCount();
return result;
}