Florin Malita | 6041d31 | 2019-03-05 15:03:20 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2019 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 | // Mixes the output of two FPs. |
| 9 | |
| 10 | in fragmentProcessor fp0; |
| 11 | in fragmentProcessor? fp1; |
| 12 | in uniform half weight; |
| 13 | |
| 14 | @class { |
| 15 | |
| 16 | static OptimizationFlags OptFlags(const std::unique_ptr<GrFragmentProcessor>& fp0, |
| 17 | const std::unique_ptr<GrFragmentProcessor>& fp1) { |
Brian Salomon | c0d79e5 | 2019-04-10 15:02:11 -0400 | [diff] [blame] | 18 | auto flags = ProcessorOptimizationFlags(fp0.get()); |
| 19 | if (fp1) { |
| 20 | flags &= ProcessorOptimizationFlags(fp1.get()); |
| 21 | } |
| 22 | return flags; |
Florin Malita | 6041d31 | 2019-03-05 15:03:20 +0000 | [diff] [blame] | 23 | } |
| 24 | |
| 25 | SkPMColor4f constantOutputForConstantInput(const SkPMColor4f& input) const override { |
| 26 | const auto c0 = ConstantOutputForConstantInput(this->childProcessor(0), input), |
| 27 | c1 = (this->numChildProcessors() > 1) |
| 28 | ? ConstantOutputForConstantInput(this->childProcessor(1), input) |
| 29 | : input; |
| 30 | return { |
Ethan Nicholas | bcd51e8 | 2019-04-09 10:40:41 -0400 | [diff] [blame] | 31 | c0.fR + (c1.fR - c0.fR) * weight, |
| 32 | c0.fG + (c1.fG - c0.fG) * weight, |
| 33 | c0.fB + (c1.fB - c0.fB) * weight, |
| 34 | c0.fA + (c1.fA - c0.fA) * weight |
Florin Malita | 6041d31 | 2019-03-05 15:03:20 +0000 | [diff] [blame] | 35 | }; |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | @optimizationFlags { OptFlags(fp0, fp1) } |
| 40 | |
| 41 | void main() { |
Ethan Nicholas | 1386366 | 2019-07-29 13:05:15 -0400 | [diff] [blame] | 42 | half4 in0 = sample(fp0, sk_InColor); |
| 43 | half4 in1 = (fp1 != null) ? sample(fp1, sk_InColor) : sk_InColor; |
Florin Malita | 6041d31 | 2019-03-05 15:03:20 +0000 | [diff] [blame] | 44 | |
| 45 | sk_OutColor = mix(in0, in1, weight); |
| 46 | } |