Optimize CPP code generation.
Previously, we were limiting our calls to appendVAList to 512-byte
chunks to avoid a potential buffer overflow. This had two problems:
1 - it did not avoid the buffer overflow :(
see chromium:1092743
2 - every call to appendVAList is expensive; it incurs a resize of the
code buffer (alloc new, memcpy, free old)
This CL removes the 512-byte cap as the buffer overflow issue was
resolved at http://review.skia.org/297276
This CL also includes a few more minor improvements.
- `codeAppendf` now uses a raw string so the gencode is easier to read.
- Optimized `SkStringPrintf("%s", foo)` to `SkString(foo)`.
- Optimized `strA = strB` to `strA.swap(strB)` where safe to do so.
Change-Id: Ia0909a68719848dd2ca655066a9bc6929c8fd09f
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/297358
Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
Commit-Queue: John Stiles <johnstiles@google.com>
diff --git a/src/gpu/effects/generated/GrConfigConversionEffect.cpp b/src/gpu/effects/generated/GrConfigConversionEffect.cpp
index 9a3e987..0ec66fd 100644
--- a/src/gpu/effects/generated/GrConfigConversionEffect.cpp
+++ b/src/gpu/effects/generated/GrConfigConversionEffect.cpp
@@ -28,10 +28,16 @@
fragBuilder->forceHighPrecision();
fragBuilder->codeAppendf(
- "%s = floor(%s * 255.0 + 0.5) / 255.0;\n@switch (%d) {\n case 0:\n "
- "%s.xyz = floor((%s.xyz * %s.w) * 255.0 + 0.5) / 255.0;\n break;\n case "
- "1:\n %s.xyz = %s.w <= 0.0 ? half3(0.0) : floor((%s.xyz / %s.w) * 255.0 + "
- "0.5) / 255.0;\n break;\n}\n",
+ R"SkSL(%s = floor(%s * 255.0 + 0.5) / 255.0;
+@switch (%d) {
+ case 0:
+ %s.xyz = floor((%s.xyz * %s.w) * 255.0 + 0.5) / 255.0;
+ break;
+ case 1:
+ %s.xyz = %s.w <= 0.0 ? half3(0.0) : floor((%s.xyz / %s.w) * 255.0 + 0.5) / 255.0;
+ break;
+}
+)SkSL",
args.fOutputColor, args.fInputColor, (int)_outer.pmConversion, args.fOutputColor,
args.fOutputColor, args.fOutputColor, args.fOutputColor, args.fOutputColor,
args.fOutputColor, args.fOutputColor);