blob: f2bf79ec982b6fe234e52e5c430af21a17b2b8f5 [file] [log] [blame]
Florin Malita6041d312019-03-05 15:03:20 +00001/*
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
10in fragmentProcessor fp0;
11in fragmentProcessor? fp1;
12in 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 Salomonc0d79e52019-04-10 15:02:11 -040018 auto flags = ProcessorOptimizationFlags(fp0.get());
19 if (fp1) {
20 flags &= ProcessorOptimizationFlags(fp1.get());
21 }
22 return flags;
Florin Malita6041d312019-03-05 15:03:20 +000023 }
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 Nicholasbcd51e82019-04-09 10:40:41 -040031 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 Malita6041d312019-03-05 15:03:20 +000035 };
36 }
37}
38
39@optimizationFlags { OptFlags(fp0, fp1) }
40
41void main() {
Ethan Nicholas13863662019-07-29 13:05:15 -040042 half4 in0 = sample(fp0, sk_InColor);
43 half4 in1 = (fp1 != null) ? sample(fp1, sk_InColor) : sk_InColor;
Florin Malita6041d312019-03-05 15:03:20 +000044
45 sk_OutColor = mix(in0, in1, weight);
46}