John Stiles | b5ac66c | 2021-07-14 14:04:49 -0400 | [diff] [blame] | 1 | /* |
| 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 Stiles | b5ac66c | 2021-07-14 14:04:49 -0400 | [diff] [blame] | 10 | #include "include/effects/SkRuntimeEffect.h" |
| 11 | |
John Stiles | b5ac66c | 2021-07-14 14:04:49 -0400 | [diff] [blame] | 12 | sk_sp<SkBlender> GetRuntimeBlendForBlendMode(SkBlendMode mode) { |
John Stiles | 126788e | 2021-07-30 11:20:48 -0400 | [diff] [blame] | 13 | static auto result = SkRuntimeEffect::MakeForBlender(SkString(R"( |
| 14 | uniform blender b; |
| 15 | half4 main(half4 src, half4 dst) { |
Brian Osman | cbfa34a | 2021-09-02 09:26:27 -0400 | [diff] [blame] | 16 | return b.eval(src, dst); |
John Stiles | b5ac66c | 2021-07-14 14:04:49 -0400 | [diff] [blame] | 17 | } |
John Stiles | 126788e | 2021-07-30 11:20:48 -0400 | [diff] [blame] | 18 | )")); |
John Stiles | b5ac66c | 2021-07-14 14:04:49 -0400 | [diff] [blame] | 19 | |
John Stiles | 126788e | 2021-07-30 11:20:48 -0400 | [diff] [blame] | 20 | SkASSERTF(result.effect, "%s", result.errorText.c_str()); |
John Stiles | b5ac66c | 2021-07-14 14:04:49 -0400 | [diff] [blame] | 21 | |
John Stiles | 126788e | 2021-07-30 11:20:48 -0400 | [diff] [blame] | 22 | SkRuntimeBlendBuilder builder(result.effect); |
| 23 | builder.child("b") = SkBlender::Mode(mode); |
| 24 | return builder.makeBlender(); |
John Stiles | b5ac66c | 2021-07-14 14:04:49 -0400 | [diff] [blame] | 25 | } |