aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/sksl/SkSLHCodeGenerator.cpp
diff options
context:
space:
mode:
authorGravatar Ethan Nicholas <ethannicholas@google.com>2017-10-10 16:30:21 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-10-11 18:05:07 +0000
commitc9472af8585be3c12691b968b667cde3ca83cae4 (patch)
treeea75fbd42cf3f14c52c8a74c4e90ad6592c6581a /src/sksl/SkSLHCodeGenerator.cpp
parentf88c12ea2047c5ccb13613534b1794944bb233e8 (diff)
SkSL FPs now support child processors, converted ArithmeticFP to SkSL
Bug: skia: Change-Id: I34ed3480073d05762a7d4692aeee4b87e454ce52 Reviewed-on: https://skia-review.googlesource.com/57961 Reviewed-by: Brian Salomon <bsalomon@google.com> Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
Diffstat (limited to 'src/sksl/SkSLHCodeGenerator.cpp')
-rw-r--r--src/sksl/SkSLHCodeGenerator.cpp55
1 files changed, 38 insertions, 17 deletions
diff --git a/src/sksl/SkSLHCodeGenerator.cpp b/src/sksl/SkSLHCodeGenerator.cpp
index eb8263187f..a4a5c9a6ac 100644
--- a/src/sksl/SkSLHCodeGenerator.cpp
+++ b/src/sksl/SkSLHCodeGenerator.cpp
@@ -15,37 +15,45 @@
namespace SkSL {
-HCodeGenerator::HCodeGenerator(const Program* program, ErrorReporter* errors, String name,
- OutputStream* out)
+HCodeGenerator::HCodeGenerator(const Context* context, const Program* program,
+ ErrorReporter* errors, String name, OutputStream* out)
: INHERITED(program, errors, out)
+, fContext(*context)
, fName(std::move(name))
, fFullName(String::printf("Gr%s", fName.c_str()))
, fSectionAndParameterHelper(*program, *errors) {}
-String HCodeGenerator::ParameterType(const Type& type) {
- if (type.name() == "float" || type.name() == "half") {
+String HCodeGenerator::ParameterType(const Context& context, const Type& type) {
+ if (type == *context.fFloat_Type || type == *context.fHalf_Type) {
return "float";
- } else if (type.name() == "float2" || type.name() == "half2") {
+ } else if (type == *context.fFloat2_Type || type == *context.fHalf2_Type) {
return "SkPoint";
- } else if (type.name() == "int4" || type.name() == "short4") {
+ } else if (type == *context.fInt4_Type || type == *context.fShort4_Type) {
return "SkIRect";
- } else if (type.name() == "float4" || type.name() == "half4") {
+ } else if (type == *context.fFloat4_Type || type == *context.fHalf4_Type) {
return "SkRect";
- } else if (type.name() == "float4x4" || type.name() == "half4x4") {
+ } else if (type == *context.fFloat4x4_Type || type == *context.fHalf4x4_Type) {
return "SkMatrix44";
} else if (type.kind() == Type::kSampler_Kind) {
return "sk_sp<GrTextureProxy>";
- } else if (type.name() == "colorSpaceXform") {
+ } else if (type == *context.fColorSpaceXform_Type) {
return "sk_sp<GrColorSpaceXform>";
+ } else if (type == *context.fFragmentProcessor_Type) {
+ return "std::unique_ptr<GrFragmentProcessor>";
}
return type.name();
}
-String HCodeGenerator::FieldType(const Type& type) {
+String HCodeGenerator::FieldType(const Context& context, const Type& type) {
if (type.kind() == Type::kSampler_Kind) {
return "TextureSampler";
+ } else if (type == *context.fFragmentProcessor_Type) {
+ // we don't store fragment processors in fields, they get registered via
+ // registerChildProcessor instead
+ ASSERT(false);
+ return "<error>";
}
- return ParameterType(type);
+ return ParameterType(context, type);
}
void HCodeGenerator::writef(const char* s, va_list va) {
@@ -128,7 +136,7 @@ void HCodeGenerator::writeMake() {
this->writef(" static std::unique_ptr<GrFragmentProcessor> Make(");
separator = "";
for (const auto& param : fSectionAndParameterHelper.getParameters()) {
- this->writef("%s%s %s", separator, ParameterType(param->fType).c_str(),
+ this->writef("%s%s %s", separator, ParameterType(fContext, param->fType).c_str(),
String(param->fName).c_str());
separator = ", ";
}
@@ -138,7 +146,11 @@ void HCodeGenerator::writeMake() {
fFullName.c_str());
separator = "";
for (const auto& param : fSectionAndParameterHelper.getParameters()) {
- this->writef("%s%s", separator, String(param->fName).c_str());
+ if (param->fType == *fContext.fFragmentProcessor_Type) {
+ this->writef("%s%s->clone()", separator, String(param->fName).c_str());
+ } else {
+ this->writef("%s%s", separator, String(param->fName).c_str());
+ }
separator = ", ";
}
this->writeExtraConstructorParams(separator);
@@ -166,7 +178,7 @@ void HCodeGenerator::writeConstructor() {
this->writef(" %s(", fFullName.c_str());
const char* separator = "";
for (const auto& param : fSectionAndParameterHelper.getParameters()) {
- this->writef("%s%s %s", separator, ParameterType(param->fType).c_str(),
+ this->writef("%s%s %s", separator, ParameterType(fContext, param->fType).c_str(),
String(param->fName).c_str());
separator = ", ";
}
@@ -190,6 +202,8 @@ void HCodeGenerator::writeConstructor() {
}
}
this->writef(")");
+ } else if (param->fType == *fContext.fFragmentProcessor_Type) {
+ // do nothing
} else {
this->writef("\n , %s(%s)", FieldName(name).c_str(), name);
}
@@ -205,6 +219,9 @@ void HCodeGenerator::writeConstructor() {
if (param->fType.kind() == Type::kSampler_Kind) {
this->writef(" this->addTextureSampler(&%s);\n",
FieldName(String(param->fName).c_str()).c_str());
+ } else if (param->fType == *fContext.fFragmentProcessor_Type) {
+ this->writef(" this->registerChildProcessor(std::move(%s));",
+ String(param->fName).c_str());
}
}
for (const Section* s : fSectionAndParameterHelper.getSections(COORD_TRANSFORM_SECTION)) {
@@ -217,7 +234,10 @@ void HCodeGenerator::writeConstructor() {
void HCodeGenerator::writeFields() {
this->writeSection(FIELDS_SECTION);
for (const auto& param : fSectionAndParameterHelper.getParameters()) {
- this->writef(" %s %s;\n", FieldType(param->fType).c_str(),
+ if (param->fType == *fContext.fFragmentProcessor_Type) {
+ continue;
+ }
+ this->writef(" %s %s;\n", FieldType(fContext, param->fType).c_str(),
FieldName(String(param->fName).c_str()).c_str());
}
for (const Section* s : fSectionAndParameterHelper.getSections(COORD_TRANSFORM_SECTION)) {
@@ -243,13 +263,14 @@ bool HCodeGenerator::generateCode() {
fFullName.c_str());
this->writeSection(CLASS_SECTION);
for (const auto& param : fSectionAndParameterHelper.getParameters()) {
- if (param->fType.kind() == Type::kSampler_Kind) {
+ if (param->fType.kind() == Type::kSampler_Kind ||
+ param->fType.kind() == Type::kOther_Kind) {
continue;
}
String nameString(param->fName);
const char* name = nameString.c_str();
this->writef(" %s %s() const { return %s; }\n",
- FieldType(param->fType).c_str(), name, FieldName(name).c_str());
+ FieldType(fContext, param->fType).c_str(), name, FieldName(name).c_str());
}
this->writeMake();
this->writef(" %s(const %s& src);\n"