Make GrRuntimeFPBuilder use stage-specific effect factories

Change-Id: If055fca832dc48212229e2ff9c714962bfa56a3e
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/402456
Commit-Queue: Brian Osman <brianosman@google.com>
Reviewed-by: Mike Klein <mtklein@google.com>
This commit is contained in:
Brian Osman 2021-04-28 17:25:31 -04:00 committed by Skia Commit-Bot
parent 2b8fd2e8e0
commit 4cd134cc03
2 changed files with 7 additions and 4 deletions

View File

@ -203,11 +203,12 @@ void GrFragmentProcessor::cloneAndRegisterAllChildProcessors(const GrFragmentPro
}
std::unique_ptr<GrFragmentProcessor> 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<kCode>();
auto builder = GrRuntimeFPBuilder::Make<kCode, SkRuntimeEffect::MakeForColorFilter>();
builder.uniform("color") = color;
return builder.makeFP();
}

View File

@ -65,8 +65,10 @@ class GrRuntimeFPBuilder : public SkRuntimeEffectBuilder<std::unique_ptr<GrFragm
public:
~GrRuntimeFPBuilder();
template <const char* CODE> 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 <const char* CODE, SkRuntimeEffect::Result (*MAKE)(SkString sksl)>
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());