blob: 2305521da7d5ce4735a3c2ee578e157de598c410 [file] [log] [blame]
John Stilesb5ac66c2021-07-14 14:04:49 -04001/*
2 * Copyright 2021 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#include "include/core/SkBlendMode.h"
9#include "include/core/SkRefCnt.h"
John Stilesb5ac66c2021-07-14 14:04:49 -040010#include "include/effects/SkRuntimeEffect.h"
11
John Stilesb5ac66c2021-07-14 14:04:49 -040012sk_sp<SkBlender> GetRuntimeBlendForBlendMode(SkBlendMode mode) {
John Stiles126788e2021-07-30 11:20:48 -040013 static auto result = SkRuntimeEffect::MakeForBlender(SkString(R"(
14 uniform blender b;
15 half4 main(half4 src, half4 dst) {
Brian Osmancbfa34a2021-09-02 09:26:27 -040016 return b.eval(src, dst);
John Stilesb5ac66c2021-07-14 14:04:49 -040017 }
John Stiles126788e2021-07-30 11:20:48 -040018 )"));
John Stilesb5ac66c2021-07-14 14:04:49 -040019
John Stiles126788e2021-07-30 11:20:48 -040020 SkASSERTF(result.effect, "%s", result.errorText.c_str());
John Stilesb5ac66c2021-07-14 14:04:49 -040021
John Stiles126788e2021-07-30 11:20:48 -040022 SkRuntimeBlendBuilder builder(result.effect);
23 builder.child("b") = SkBlender::Mode(mode);
24 return builder.makeBlender();
John Stilesb5ac66c2021-07-14 14:04:49 -040025}