aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/sksl/SkSLCPPCodeGenerator.cpp
diff options
context:
space:
mode:
authorGravatar Ethan Nicholas <ethannicholas@google.com>2017-07-13 09:36:52 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-07-13 14:07:02 +0000
commit68990be759f663bafdb7c1b746adce15557cda7f (patch)
treeb982e218f45fa02188bb38fe767797ff6315edcf /src/sksl/SkSLCPPCodeGenerator.cpp
parentc20b5f83595073c02009ff3c0a8a77aca6ad1e71 (diff)
Re-land of "converted GrSimpleTextureEffect to sksl"
This reverts commit baf981f71614e7a2fbe6af2726e65126d431ed8e. Bug: skia: Change-Id: I36f6bfb616f1ec2b89043e3a6f7cbdf473bc9588 Reviewed-on: https://skia-review.googlesource.com/22369 Reviewed-by: Greg Daniel <egdaniel@google.com> Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
Diffstat (limited to 'src/sksl/SkSLCPPCodeGenerator.cpp')
-rw-r--r--src/sksl/SkSLCPPCodeGenerator.cpp60
1 files changed, 35 insertions, 25 deletions
diff --git a/src/sksl/SkSLCPPCodeGenerator.cpp b/src/sksl/SkSLCPPCodeGenerator.cpp
index 72dcd013a3..238615db49 100644
--- a/src/sksl/SkSLCPPCodeGenerator.cpp
+++ b/src/sksl/SkSLCPPCodeGenerator.cpp
@@ -163,7 +163,7 @@ void CPPCodeGenerator::writeVarInitializer(const Variable& var, const Expression
String CPPCodeGenerator::getSamplerHandle(const Variable& var) {
int samplerCount = 0;
- for (const auto param : fSectionAndParameterHelper.fParameters) {
+ for (const auto param : fSectionAndParameterHelper.getParameters()) {
if (&var == param) {
return "args.fTexSamplers[" + to_string(samplerCount) + "]";
}
@@ -226,6 +226,20 @@ void CPPCodeGenerator::writeVariableReference(const VariableReference& ref) {
}
void CPPCodeGenerator::writeFunctionCall(const FunctionCall& c) {
+ if (c.fFunction.fBuiltin && c.fFunction.fName == "COLORSPACE") {
+ String tmpVar = "_tmpVar" + to_string(++fVarCount);
+ fFunctionHeader += "vec4 " + tmpVar + ";";
+ ASSERT(c.fArguments.size() == 2);
+ this->write("%s");
+ fFormatArgs.push_back("fColorSpaceHelper.isValid() ? \"(" + tmpVar + " = \" : \"\"");
+ this->writeExpression(*c.fArguments[0], kTopLevel_Precedence);
+ ASSERT(c.fArguments[1]->fKind == Expression::kVariableReference_Kind);
+ String xform("args.fUniformHandler->getUniformCStr(fColorSpaceHelper.gamutXformUniform())");
+ this->write("%s");
+ fFormatArgs.push_back("fColorSpaceHelper.isValid() ? SkStringPrintf(\", vec4(clamp((%s * vec4(" + tmpVar + ".rgb, 1.0)).rgb, 0.0, " + tmpVar +
+ ".a), " + tmpVar + ".a))\", " + xform + ").c_str() : \"\"");
+ return;
+ }
INHERITED::writeFunctionCall(c);
if (c.fFunction.fBuiltin && c.fFunction.fName == "texture") {
this->write(".%s");
@@ -267,9 +281,9 @@ void CPPCodeGenerator::writeSetting(const Setting& s) {
}
void CPPCodeGenerator::writeSection(const char* name, const char* prefix) {
- const auto found = fSectionAndParameterHelper.fSections.find(String(name));
- if (found != fSectionAndParameterHelper.fSections.end()) {
- this->writef("%s%s", prefix, found->second->fText.c_str());
+ const Section* s = fSectionAndParameterHelper.getSection(name);
+ if (s) {
+ this->writef("%s%s", prefix, s->fText.c_str());
}
}
@@ -398,10 +412,8 @@ bool CPPCodeGenerator::writeEmitCode(std::vector<const Variable*>& uniforms) {
void CPPCodeGenerator::writeSetData(std::vector<const Variable*>& uniforms) {
const char* fullName = fFullName.c_str();
- auto section = fSectionAndParameterHelper.fSections.find(String(SET_DATA_SECTION));
- const char* pdman = section != fSectionAndParameterHelper.fSections.end() ?
- section->second->fArgument.c_str() :
- "pdman";
+ const Section* section = fSectionAndParameterHelper.getSection(SET_DATA_SECTION);
+ const char* pdman = section ? section->fArgument.c_str() : "pdman";
this->writef(" void onSetData(const GrGLSLProgramDataManager& %s, "
"const GrFragmentProcessor& _proc) override {\n",
pdman);
@@ -439,7 +451,7 @@ void CPPCodeGenerator::writeSetData(std::vector<const Variable*>& uniforms) {
if (wroteProcessor) {
this->writef(" }\n");
}
- if (section != fSectionAndParameterHelper.fSections.end()) {
+ if (section) {
for (const auto& p : fProgram.fElements) {
if (ProgramElement::kVar_Kind == p->fKind) {
const VarDeclarations* decls = (const VarDeclarations*) p.get();
@@ -470,27 +482,25 @@ void CPPCodeGenerator::writeSetData(std::vector<const Variable*>& uniforms) {
}
void CPPCodeGenerator::writeTest() {
- const auto found = fSectionAndParameterHelper.fSections.find(TEST_CODE_SECTION);
- if (found == fSectionAndParameterHelper.fSections.end()) {
- return;
+ const Section* test = fSectionAndParameterHelper.getSection(TEST_CODE_SECTION);
+ if (test) {
+ this->writef("GR_DEFINE_FRAGMENT_PROCESSOR_TEST(%s);\n"
+ "#if GR_TEST_UTILS\n"
+ "sk_sp<GrFragmentProcessor> %s::TestCreate(GrProcessorTestData* %s) {\n",
+ fFullName.c_str(),
+ fFullName.c_str(),
+ test->fArgument.c_str());
+ this->writeSection(TEST_CODE_SECTION);
+ this->write("}\n"
+ "#endif\n");
}
- const Section* test = found->second;
- this->writef("GR_DEFINE_FRAGMENT_PROCESSOR_TEST(%s);\n"
- "#if GR_TEST_UTILS\n"
- "sk_sp<GrFragmentProcessor> %s::TestCreate(GrProcessorTestData* %s) {\n",
- fFullName.c_str(),
- fFullName.c_str(),
- test->fArgument.c_str());
- this->writeSection(TEST_CODE_SECTION);
- this->write("}\n"
- "#endif\n");
}
void CPPCodeGenerator::writeGetKey() {
this->writef("void %s::onGetGLSLProcessorKey(const GrShaderCaps& caps, "
"GrProcessorKeyBuilder* b) const {\n",
fFullName.c_str());
- for (const auto& param : fSectionAndParameterHelper.fParameters) {
+ for (const auto& param : fSectionAndParameterHelper.getParameters()) {
const char* name = param->fName.c_str();
if (param->fType == *fContext.fColorSpaceXform_Type) {
this->writef(" b->add32(GrColorSpaceXform::XformKey(%s.get()));\n",
@@ -580,7 +590,7 @@ bool CPPCodeGenerator::generateCode() {
this->writef(" UniformHandle %sVar;\n", HCodeGenerator::FieldName(name).c_str());
}
}
- for (const auto& param : fSectionAndParameterHelper.fParameters) {
+ for (const auto& param : fSectionAndParameterHelper.getParameters()) {
const char* name = param->fName.c_str();
if (needs_uniform_var(*param)) {
this->writef(" UniformHandle %sVar;\n", HCodeGenerator::FieldName(name).c_str());
@@ -599,7 +609,7 @@ bool CPPCodeGenerator::generateCode() {
" const %s& that = other.cast<%s>();\n"
" (void) that;\n",
fullName, fullName, fullName);
- for (const auto& param : fSectionAndParameterHelper.fParameters) {
+ for (const auto& param : fSectionAndParameterHelper.getParameters()) {
const char* name = param->fName.c_str();
this->writef(" if (%s != that.%s) return false;\n",
HCodeGenerator::FieldName(name).c_str(),