diff --git a/src/gpu/GrFragmentProcessor.cpp b/src/gpu/GrFragmentProcessor.cpp index c893535d63..def88c8223 100644 --- a/src/gpu/GrFragmentProcessor.cpp +++ b/src/gpu/GrFragmentProcessor.cpp @@ -203,11 +203,12 @@ void GrFragmentProcessor::cloneAndRegisterAllChildProcessors(const GrFragmentPro } std::unique_ptr GrFragmentProcessor::MakeColor(SkPMColor4f color) { + // Use ColorFilter signature/factory to get the constant output for constant input optimization static constexpr char kCode[] = R"( uniform half4 color; - half4 main() { return color; } + half4 main(half4 inColor) { return color; } )"; - auto builder = GrRuntimeFPBuilder::Make(); + auto builder = GrRuntimeFPBuilder::Make(); builder.uniform("color") = color; return builder.makeFP(); } diff --git a/src/gpu/effects/GrSkSLFP.h b/src/gpu/effects/GrSkSLFP.h index e24d738f53..549729365d 100644 --- a/src/gpu/effects/GrSkSLFP.h +++ b/src/gpu/effects/GrSkSLFP.h @@ -65,8 +65,10 @@ class GrRuntimeFPBuilder : public SkRuntimeEffectBuilder static GrRuntimeFPBuilder Make() { - static const SkRuntimeEffect::Result gResult = SkRuntimeEffect::Make(SkString(CODE)); + // NOTE: We use a static variable as a cache. CODE and MAKE must remain template parameters. + template + static GrRuntimeFPBuilder Make() { + static const SkRuntimeEffect::Result gResult = MAKE(SkString(CODE)); #ifdef SK_DEBUG if (!gResult.effect) { SK_ABORT("Code failed: %s", gResult.errorText.c_str());