Add templated GrSkSLFP factory to eliminate nearly all overhead
In debug builds, this validates that all of the arguments being passed
have names and sizes that match the SkSL expectation. In release build,
those checks are skipped, and this trusts the caller. In that situation,
nearly everthing is inlined away:
- We ask the effect how much space is needed to hold the uniform blob
- We allocate the FP with that much additional space
- We call addChild for each child FP passed, and memcpy every other
value directly into the FP's footer.
Change-Id: I28e08feea8415e45e5cdf8b080e8c78ae1e28fb7
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/415900
Reviewed-by: John Stiles <johnstiles@google.com>
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
diff --git a/src/utils/SkShadowUtils.cpp b/src/utils/SkShadowUtils.cpp
index 709c9e5..88ee681 100644
--- a/src/utils/SkShadowUtils.cpp
+++ b/src/utils/SkShadowUtils.cpp
@@ -87,15 +87,15 @@
GrFPResult SkGaussianColorFilter::asFragmentProcessor(std::unique_ptr<GrFragmentProcessor> inputFP,
GrRecordingContext*,
const GrColorInfo&) const {
- static constexpr char kCode[] = R"(
+ static auto effect = SkRuntimeEffect::MakeForColorFilter(SkString(R"(
half4 main(half4 inColor) {
half factor = 1 - inColor.a;
factor = exp(-factor * factor * 4) - 0.018;
return half4(factor);
}
- )";
- auto builder = GrRuntimeFPBuilder::Make<kCode, SkRuntimeEffect::MakeForColorFilter>();
- return GrFPSuccess(GrFragmentProcessor::Compose(builder.makeFP(), std::move(inputFP)));
+ )")).effect;
+ auto fp = GrSkSLFP::Make(effect, "gaussian_fp");
+ return GrFPSuccess(GrFragmentProcessor::Compose(std::move(fp), std::move(inputFP)));
}
#endif