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 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) { 18 auto flags = ProcessorOptimizationFlags(fp0.get()); 19 if (fp1) { 20 flags &= ProcessorOptimizationFlags(fp1.get()); 21 } 22 return flags; 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 { 31 c0.fR + (c1.fR - c0.fR) * fWeight, 32 c0.fG + (c1.fG - c0.fG) * fWeight, 33 c0.fB + (c1.fB - c0.fB) * fWeight, 34 c0.fA + (c1.fA - c0.fA) * fWeight 35 }; 36 } 37} 38 39@optimizationFlags { OptFlags(fp0, fp1) } 40 41void main() { 42 half4 in0 = process(fp0, sk_InColor); 43 half4 in1 = (fp1 != null) ? process(fp1, sk_InColor) : sk_InColor; 44 45 sk_OutColor = mix(in0, in1, weight); 46} 47