aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/sksl
diff options
context:
space:
mode:
authorGravatar Brian Salomon <bsalomon@google.com>2018-07-30 14:48:15 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2018-07-30 19:40:03 +0000
commitf7dcd76c552a4e93a75a3808289de69a997da169 (patch)
tree29fe08e9681f29e3d3d2af8e721ecfba6dd09beb /src/sksl
parent7226c232d73356a37ec8cfef0ed55147e68dd2fd (diff)
Remove array of TextureSampler pointers from GrIOResourceProcessor.
Instead store sampler count on base class and subclasses implement a virtual to get the ith sampler. Change-Id: I13e2447a6467a09761d8615acb4aa360b87b1476 Reviewed-on: https://skia-review.googlesource.com/141563 Commit-Queue: Brian Salomon <bsalomon@google.com> Reviewed-by: Robert Phillips <robertphillips@google.com>
Diffstat (limited to 'src/sksl')
-rw-r--r--src/sksl/SkSLCPPCodeGenerator.cpp31
-rw-r--r--src/sksl/SkSLCPPCodeGenerator.h2
-rw-r--r--src/sksl/SkSLHCodeGenerator.cpp17
3 files changed, 44 insertions, 6 deletions
diff --git a/src/sksl/SkSLCPPCodeGenerator.cpp b/src/sksl/SkSLCPPCodeGenerator.cpp
index be402088cc..86565016d6 100644
--- a/src/sksl/SkSLCPPCodeGenerator.cpp
+++ b/src/sksl/SkSLCPPCodeGenerator.cpp
@@ -637,6 +637,29 @@ void CPPCodeGenerator::writeSetData(std::vector<const Variable*>& uniforms) {
this->write(" }\n");
}
+void CPPCodeGenerator::writeOnTextureSampler() {
+ bool foundSampler = false;
+ for (const auto& param : fSectionAndParameterHelper.getParameters()) {
+ if (param->fType.kind() == Type::kSampler_Kind) {
+ if (!foundSampler) {
+ this->writef(
+ "const GrFragmentProcessor::TextureSampler& %s::onTextureSampler(int "
+ "index) const {\n",
+ fFullName.c_str());
+ this->writef(" return IthTextureSampler(index, %s",
+ HCodeGenerator::FieldName(String(param->fName).c_str()).c_str());
+ foundSampler = true;
+ } else {
+ this->writef(", %s",
+ HCodeGenerator::FieldName(String(param->fName).c_str()).c_str());
+ }
+ }
+ }
+ if (foundSampler) {
+ this->write(");\n}\n");
+ }
+}
+
void CPPCodeGenerator::writeClone() {
if (!this->writeSection(CLONE_SECTION)) {
if (fSectionAndParameterHelper.getSection(FIELDS_SECTION)) {
@@ -662,15 +685,18 @@ void CPPCodeGenerator::writeClone() {
}
this->writef(" {\n");
int childCount = 0;
+ int samplerCount = 0;
for (const auto& param : fSectionAndParameterHelper.getParameters()) {
if (param->fType.kind() == Type::kSampler_Kind) {
- this->writef(" this->addTextureSampler(&%s);\n",
- HCodeGenerator::FieldName(String(param->fName).c_str()).c_str());
+ ++samplerCount;
} else if (param->fType == *fContext.fFragmentProcessor_Type) {
this->writef(" this->registerChildProcessor(src.childProcessor(%d).clone());"
"\n", childCount++);
}
}
+ if (samplerCount) {
+ this->writef(" this->setTextureSamplerCnt(%d);", samplerCount);
+ }
for (const Section* s : fSectionAndParameterHelper.getSections(COORD_TRANSFORM_SECTION)) {
String field = HCodeGenerator::FieldName(s->fArgument.c_str());
this->writef(" this->addCoordTransform(&%sCoordTransform);\n", field.c_str());
@@ -819,6 +845,7 @@ bool CPPCodeGenerator::generateCode() {
this->write(" return true;\n"
"}\n");
this->writeClone();
+ this->writeOnTextureSampler();
this->writeTest();
this->writeSection(CPP_END_SECTION);
diff --git a/src/sksl/SkSLCPPCodeGenerator.h b/src/sksl/SkSLCPPCodeGenerator.h
index 77331daa2f..40d9982cc3 100644
--- a/src/sksl/SkSLCPPCodeGenerator.h
+++ b/src/sksl/SkSLCPPCodeGenerator.h
@@ -78,6 +78,8 @@ private:
void writeGetKey();
+ void writeOnTextureSampler();
+
void writeClone();
void writeTest();
diff --git a/src/sksl/SkSLHCodeGenerator.cpp b/src/sksl/SkSLHCodeGenerator.cpp
index be0f1ad858..0acd33404f 100644
--- a/src/sksl/SkSLHCodeGenerator.cpp
+++ b/src/sksl/SkSLHCodeGenerator.cpp
@@ -223,15 +223,18 @@ void HCodeGenerator::writeConstructor() {
}
this->writef(" {\n");
this->writeSection(CONSTRUCTOR_CODE_SECTION);
+ int samplerCount = 0;
for (const auto& param : fSectionAndParameterHelper.getParameters()) {
if (param->fType.kind() == Type::kSampler_Kind) {
- this->writef(" this->addTextureSampler(&%s);\n",
- FieldName(String(param->fName).c_str()).c_str());
+ ++samplerCount;
} else if (param->fType == *fContext.fFragmentProcessor_Type) {
this->writef(" this->registerChildProcessor(std::move(%s));",
String(param->fName).c_str());
}
}
+ if (samplerCount) {
+ this->writef(" this->setTextureSamplerCnt(%d);", samplerCount);
+ }
for (const Section* s : fSectionAndParameterHelper.getSections(COORD_TRANSFORM_SECTION)) {
String field = FieldName(s->fArgument.c_str());
this->writef(" this->addCoordTransform(&%sCoordTransform);\n", field.c_str());
@@ -312,8 +315,14 @@ bool HCodeGenerator::generateCode() {
this->writef(" GrGLSLFragmentProcessor* onCreateGLSLInstance() const override;\n"
" void onGetGLSLProcessorKey(const GrShaderCaps&,"
"GrProcessorKeyBuilder*) const override;\n"
- " bool onIsEqual(const GrFragmentProcessor&) const override;\n"
- " GR_DECLARE_FRAGMENT_PROCESSOR_TEST\n");
+ " bool onIsEqual(const GrFragmentProcessor&) const override;\n");
+ for (const auto& param : fSectionAndParameterHelper.getParameters()) {
+ if (param->fType.kind() == Type::kSampler_Kind) {
+ this->writef(" const TextureSampler& onTextureSampler(int) const override;");
+ break;
+ }
+ }
+ this->writef(" GR_DECLARE_FRAGMENT_PROCESSOR_TEST\n");
this->writeFields();
this->writef(" typedef GrFragmentProcessor INHERITED;\n"
"};\n");