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 | #include "GrMixerEffect.h" |
| 12 | #include "glsl/GrGLSLFragmentProcessor.h" |
| 13 | #include "glsl/GrGLSLFragmentShaderBuilder.h" |
| 14 | #include "glsl/GrGLSLProgramBuilder.h" |
| 15 | #include "GrTexture.h" |
| 16 | #include "SkSLCPP.h" |
| 17 | #include "SkSLUtil.h" |
| 18 | class GrGLSLMixerEffect : public GrGLSLFragmentProcessor { |
| 19 | public: |
| 20 | GrGLSLMixerEffect() {} |
| 21 | void emitCode(EmitArgs& args) override { |
| 22 | GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder; |
| 23 | const GrMixerEffect& _outer = args.fFp.cast<GrMixerEffect>(); |
| 24 | (void)_outer; |
| 25 | auto weight = _outer.weight(); |
| 26 | (void)weight; |
| 27 | fWeightVar = args.fUniformHandler->addUniform(kFragment_GrShaderFlag, kHalf_GrSLType, |
| 28 | kDefault_GrSLPrecision, "weight"); |
| 29 | SkString _input0 = SkStringPrintf("%s", args.fInputColor); |
| 30 | SkString _child0("_child0"); |
| 31 | this->emitChild(_outer.fp0_index(), _input0.c_str(), &_child0, args); |
| 32 | fragBuilder->codeAppendf("half4 in0 = %s;", _child0.c_str()); |
| 33 | SkString _input1 = SkStringPrintf("%s", args.fInputColor); |
| 34 | SkString _child1("_child1"); |
| 35 | if (_outer.fp1_index() >= 0) { |
| 36 | this->emitChild(_outer.fp1_index(), _input1.c_str(), &_child1, args); |
| 37 | } else { |
| 38 | fragBuilder->codeAppendf("half4 %s;", _child1.c_str()); |
| 39 | } |
| 40 | fragBuilder->codeAppendf("\nhalf4 in1 = %s ? %s : %s;\n%s = mix(in0, in1, %s);\n", |
| 41 | _outer.fp1_index() >= 0 ? "true" : "false", _child1.c_str(), |
| 42 | args.fInputColor, args.fOutputColor, |
| 43 | args.fUniformHandler->getUniformCStr(fWeightVar)); |
| 44 | } |
| 45 | |
| 46 | private: |
| 47 | void onSetData(const GrGLSLProgramDataManager& pdman, |
| 48 | const GrFragmentProcessor& _proc) override { |
| 49 | const GrMixerEffect& _outer = _proc.cast<GrMixerEffect>(); |
| 50 | { pdman.set1f(fWeightVar, (_outer.weight())); } |
| 51 | } |
| 52 | UniformHandle fWeightVar; |
| 53 | }; |
| 54 | GrGLSLFragmentProcessor* GrMixerEffect::onCreateGLSLInstance() const { |
| 55 | return new GrGLSLMixerEffect(); |
| 56 | } |
| 57 | void GrMixerEffect::onGetGLSLProcessorKey(const GrShaderCaps& caps, |
| 58 | GrProcessorKeyBuilder* b) const {} |
| 59 | bool GrMixerEffect::onIsEqual(const GrFragmentProcessor& other) const { |
| 60 | const GrMixerEffect& that = other.cast<GrMixerEffect>(); |
| 61 | (void)that; |
| 62 | if (fWeight != that.fWeight) return false; |
| 63 | return true; |
| 64 | } |
| 65 | GrMixerEffect::GrMixerEffect(const GrMixerEffect& src) |
| 66 | : INHERITED(kGrMixerEffect_ClassID, src.optimizationFlags()) |
| 67 | , fFp0_index(src.fFp0_index) |
| 68 | , fFp1_index(src.fFp1_index) |
| 69 | , fWeight(src.fWeight) { |
| 70 | this->registerChildProcessor(src.childProcessor(fFp0_index).clone()); |
| 71 | if (fFp1_index >= 0) { |
| 72 | this->registerChildProcessor(src.childProcessor(fFp1_index).clone()); |
| 73 | } |
| 74 | } |
| 75 | std::unique_ptr<GrFragmentProcessor> GrMixerEffect::clone() const { |
| 76 | return std::unique_ptr<GrFragmentProcessor>(new GrMixerEffect(*this)); |
| 77 | } |