GrMixerEffect.fp 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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. // Mixes the output of two FPs.
  8. in fragmentProcessor fp0;
  9. in fragmentProcessor? fp1;
  10. in uniform half weight;
  11. @class {
  12. static OptimizationFlags OptFlags(const std::unique_ptr<GrFragmentProcessor>& fp0,
  13. const std::unique_ptr<GrFragmentProcessor>& fp1) {
  14. auto flags = ProcessorOptimizationFlags(fp0.get());
  15. if (fp1) {
  16. flags &= ProcessorOptimizationFlags(fp1.get());
  17. }
  18. return flags;
  19. }
  20. SkPMColor4f constantOutputForConstantInput(const SkPMColor4f& input) const override {
  21. const auto c0 = ConstantOutputForConstantInput(this->childProcessor(0), input),
  22. c1 = (this->numChildProcessors() > 1)
  23. ? ConstantOutputForConstantInput(this->childProcessor(1), input)
  24. : input;
  25. return {
  26. c0.fR + (c1.fR - c0.fR) * weight,
  27. c0.fG + (c1.fG - c0.fG) * weight,
  28. c0.fB + (c1.fB - c0.fB) * weight,
  29. c0.fA + (c1.fA - c0.fA) * weight
  30. };
  31. }
  32. }
  33. @optimizationFlags { OptFlags(fp0, fp1) }
  34. void main() {
  35. half4 in0 = process(fp0, sk_InColor);
  36. half4 in1 = (fp1 != null) ? process(fp1, sk_InColor) : sk_InColor;
  37. sk_OutColor = mix(in0, in1, weight);
  38. }