aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/sksl/SkSLCPPCodeGenerator.cpp
diff options
context:
space:
mode:
authorGravatar Ethan Nicholas <ethannicholas@google.com>2017-10-13 13:11:06 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-10-13 19:40:44 +0000
commit5b6e6277ad8768e37199b677eea361ca51654477 (patch)
tree99cf41720cc29ce2a7322156ba80dafa56da0183 /src/sksl/SkSLCPPCodeGenerator.cpp
parentf543a60ef06a6b0ccb5a0a85ca5415021c81c9ee (diff)
SkSL workaround for appendf 1024 byte restriction
Bug: skia: Change-Id: Ibb04e032e27e834b5e3e40c40522e756223f58ec Reviewed-on: https://skia-review.googlesource.com/59680 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.cpp45
1 files changed, 38 insertions, 7 deletions
diff --git a/src/sksl/SkSLCPPCodeGenerator.cpp b/src/sksl/SkSLCPPCodeGenerator.cpp
index 705155eb5b..a7008400ce 100644
--- a/src/sksl/SkSLCPPCodeGenerator.cpp
+++ b/src/sksl/SkSLCPPCodeGenerator.cpp
@@ -443,6 +443,41 @@ void CPPCodeGenerator::writePrivateVarValues() {
}
}
+void CPPCodeGenerator::writeCodeAppend(const String& code) {
+ // codeAppendf can only handle appending 1024 bytes at a time, so we need to break the string
+ // into chunks. Unfortunately we can't tell exactly how long the string is going to end up,
+ // because printf escape sequences get replaced by strings of unknown length, but keeping the
+ // format string below 512 bytes is probably safe.
+ static constexpr size_t maxChunkSize = 512;
+ size_t start = 0;
+ size_t index = 0;
+ size_t argStart = 0;
+ size_t argCount;
+ while (index < code.size()) {
+ argCount = 0;
+ this->write(" fragBuilder->codeAppendf(\"");
+ while (index < code.size() && index < start + maxChunkSize) {
+ if ('%' == code[index]) {
+ if (index == start + maxChunkSize - 1 || index == code.size() - 1) {
+ break;
+ }
+ if (code[index + 1] != '%') {
+ ++argCount;
+ }
+ }
+ ++index;
+ }
+ fOut->write(code.c_str() + start, index - start);
+ this->write("\"");
+ for (size_t i = argStart; i < argStart + argCount; ++i) {
+ this->writef(", %s", fFormatArgs[i].c_str());
+ }
+ this->write(");\n");
+ argStart += argCount;
+ start = index;
+ }
+}
+
bool CPPCodeGenerator::writeEmitCode(std::vector<const Variable*>& uniforms) {
this->write(" void emitCode(EmitArgs& args) override {\n"
" GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;\n");
@@ -468,13 +503,9 @@ bool CPPCodeGenerator::writeEmitCode(std::vector<const Variable*>& uniforms) {
fOut = &mainBuffer;
bool result = INHERITED::generateCode();
fOut = old;
- this->writef("%s fragBuilder->codeAppendf(\"%s\"", fExtraEmitCodeCode.c_str(),
- mainBuffer.str().c_str());
- for (const auto& s : fFormatArgs) {
- this->writef(", %s", s.c_str());
- }
- this->write(");\n"
- " }\n");
+ this->writef("%s", fExtraEmitCodeCode.c_str());
+ this->writeCodeAppend(mainBuffer.str());
+ this->write(" }\n");
return result;
}