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 | /************************************************************************************************** |
| 9 | *** This file was autogenerated from GrMixerEffect.fp; do not modify. |
| 10 | **************************************************************************************************/ |
| 11 | #ifndef GrMixerEffect_DEFINED |
| 12 | #define GrMixerEffect_DEFINED |
| 13 | #include "SkTypes.h" |
| 14 | #include "GrFragmentProcessor.h" |
| 15 | #include "GrCoordTransform.h" |
| 16 | class GrMixerEffect : public GrFragmentProcessor { |
| 17 | public: |
| 18 | static OptimizationFlags OptFlags(const std::unique_ptr<GrFragmentProcessor>& fp0, |
| 19 | const std::unique_ptr<GrFragmentProcessor>& fp1) { |
| 20 | auto get_flags = [](const std::unique_ptr<GrFragmentProcessor>& fp) { |
| 21 | auto flags = kNone_OptimizationFlags; |
| 22 | |
| 23 | if (fp->compatibleWithCoverageAsAlpha()) { |
| 24 | flags |= kCompatibleWithCoverageAsAlpha_OptimizationFlag; |
| 25 | } |
| 26 | |
| 27 | if (fp->preservesOpaqueInput()) { |
| 28 | flags |= kPreservesOpaqueInput_OptimizationFlag; |
| 29 | } |
| 30 | |
| 31 | if (fp->hasConstantOutputForConstantInput()) { |
| 32 | flags |= kConstantOutputForConstantInput_OptimizationFlag; |
| 33 | } |
| 34 | |
| 35 | return flags; |
| 36 | }; |
| 37 | |
| 38 | const auto fp0_flags = get_flags(fp0); |
| 39 | |
| 40 | return fp1 ? (fp0_flags & get_flags(fp1)) : fp0_flags; |
| 41 | } |
| 42 | |
| 43 | SkPMColor4f constantOutputForConstantInput(const SkPMColor4f& input) const override { |
| 44 | const auto c0 = ConstantOutputForConstantInput(this->childProcessor(0), input), |
| 45 | c1 = (this->numChildProcessors() > 1) |
| 46 | ? ConstantOutputForConstantInput(this->childProcessor(1), input) |
| 47 | : input; |
Mike Klein | a2a5cc0 | 2019-03-19 11:30:11 -0500 | [diff] [blame] | 48 | return {c0.fR + (c1.fR - c0.fR) * fWeight, |
| 49 | c0.fG + (c1.fG - c0.fG) * fWeight, |
| 50 | c0.fB + (c1.fB - c0.fB) * fWeight, |
| 51 | c0.fA + (c1.fA - c0.fA) * fWeight}; |
Florin Malita | 6041d31 | 2019-03-05 15:03:20 +0000 | [diff] [blame] | 52 | } |
Mike Klein | a2a5cc0 | 2019-03-19 11:30:11 -0500 | [diff] [blame] | 53 | int fp0_index() const { return fFp0_index; } |
| 54 | int fp1_index() const { return fFp1_index; } |
| 55 | float weight() const { return fWeight; } |
Florin Malita | 6041d31 | 2019-03-05 15:03:20 +0000 | [diff] [blame] | 56 | static std::unique_ptr<GrFragmentProcessor> Make(std::unique_ptr<GrFragmentProcessor> fp0, |
Mike Klein | a2a5cc0 | 2019-03-19 11:30:11 -0500 | [diff] [blame] | 57 | std::unique_ptr<GrFragmentProcessor> fp1, |
| 58 | float weight) { |
Florin Malita | 6041d31 | 2019-03-05 15:03:20 +0000 | [diff] [blame] | 59 | return std::unique_ptr<GrFragmentProcessor>( |
| 60 | new GrMixerEffect(std::move(fp0), std::move(fp1), weight)); |
| 61 | } |
| 62 | GrMixerEffect(const GrMixerEffect& src); |
| 63 | std::unique_ptr<GrFragmentProcessor> clone() const override; |
Mike Klein | a2a5cc0 | 2019-03-19 11:30:11 -0500 | [diff] [blame] | 64 | const char* name() const override { return "MixerEffect"; } |
Florin Malita | 6041d31 | 2019-03-05 15:03:20 +0000 | [diff] [blame] | 65 | |
| 66 | private: |
| 67 | GrMixerEffect(std::unique_ptr<GrFragmentProcessor> fp0, |
Mike Klein | a2a5cc0 | 2019-03-19 11:30:11 -0500 | [diff] [blame] | 68 | std::unique_ptr<GrFragmentProcessor> fp1, |
| 69 | float weight) |
Florin Malita | 6041d31 | 2019-03-05 15:03:20 +0000 | [diff] [blame] | 70 | : INHERITED(kGrMixerEffect_ClassID, (OptimizationFlags)OptFlags(fp0, fp1)) |
| 71 | , fWeight(weight) { |
| 72 | SkASSERT(fp0); |
| 73 | fFp0_index = this->numChildProcessors(); |
| 74 | this->registerChildProcessor(std::move(fp0)); |
| 75 | if (fp1) { |
| 76 | fFp1_index = this->numChildProcessors(); |
| 77 | this->registerChildProcessor(std::move(fp1)); |
| 78 | } |
| 79 | } |
| 80 | GrGLSLFragmentProcessor* onCreateGLSLInstance() const override; |
| 81 | void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override; |
| 82 | bool onIsEqual(const GrFragmentProcessor&) const override; |
| 83 | GR_DECLARE_FRAGMENT_PROCESSOR_TEST |
Mike Klein | a2a5cc0 | 2019-03-19 11:30:11 -0500 | [diff] [blame] | 84 | int fFp0_index = -1; |
| 85 | int fFp1_index = -1; |
| 86 | float fWeight; |
Florin Malita | 6041d31 | 2019-03-05 15:03:20 +0000 | [diff] [blame] | 87 | typedef GrFragmentProcessor INHERITED; |
| 88 | }; |
| 89 | #endif |