Ethan Nicholas | ff4fb33 | 2019-04-09 16:28:19 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2019 Google LLC. |
| 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 GrComposeLerpEffect.fp; do not modify. |
| 10 | **************************************************************************************************/ |
| 11 | #include "GrComposeLerpEffect.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 12 | |
Greg Daniel | 456f9b5 | 2020-03-05 19:14:18 +0000 | [diff] [blame] | 13 | #include "src/gpu/GrTexture.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 14 | #include "src/gpu/glsl/GrGLSLFragmentProcessor.h" |
| 15 | #include "src/gpu/glsl/GrGLSLFragmentShaderBuilder.h" |
| 16 | #include "src/gpu/glsl/GrGLSLProgramBuilder.h" |
| 17 | #include "src/sksl/SkSLCPP.h" |
| 18 | #include "src/sksl/SkSLUtil.h" |
Ethan Nicholas | ff4fb33 | 2019-04-09 16:28:19 -0400 | [diff] [blame] | 19 | class GrGLSLComposeLerpEffect : public GrGLSLFragmentProcessor { |
| 20 | public: |
| 21 | GrGLSLComposeLerpEffect() {} |
| 22 | void emitCode(EmitArgs& args) override { |
| 23 | GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder; |
| 24 | const GrComposeLerpEffect& _outer = args.fFp.cast<GrComposeLerpEffect>(); |
| 25 | (void)_outer; |
| 26 | auto weight = _outer.weight; |
| 27 | (void)weight; |
Ethan Nicholas | 16464c3 | 2020-04-06 13:53:05 -0400 | [diff] [blame] | 28 | weightVar = args.fUniformHandler->addUniform(&_outer, kFragment_GrShaderFlag, |
| 29 | kFloat_GrSLType, "weight"); |
Brian Osman | 978693c | 2020-01-24 14:52:10 -0500 | [diff] [blame] | 30 | SkString _sample290; |
Ethan Nicholas | ff4fb33 | 2019-04-09 16:28:19 -0400 | [diff] [blame] | 31 | if (_outer.child1_index >= 0) { |
Brian Osman | 978693c | 2020-01-24 14:52:10 -0500 | [diff] [blame] | 32 | _sample290 = this->invokeChild(_outer.child1_index, args); |
Ethan Nicholas | 6ad5289 | 2019-05-03 13:13:42 +0000 | [diff] [blame] | 33 | } else { |
Brian Osman | 978693c | 2020-01-24 14:52:10 -0500 | [diff] [blame] | 34 | _sample290 = "half4(1)"; |
Ethan Nicholas | ff4fb33 | 2019-04-09 16:28:19 -0400 | [diff] [blame] | 35 | } |
Brian Osman | 978693c | 2020-01-24 14:52:10 -0500 | [diff] [blame] | 36 | SkString _sample358; |
Ethan Nicholas | ff4fb33 | 2019-04-09 16:28:19 -0400 | [diff] [blame] | 37 | if (_outer.child2_index >= 0) { |
Brian Osman | 978693c | 2020-01-24 14:52:10 -0500 | [diff] [blame] | 38 | _sample358 = this->invokeChild(_outer.child2_index, args); |
Ethan Nicholas | 6ad5289 | 2019-05-03 13:13:42 +0000 | [diff] [blame] | 39 | } else { |
Brian Osman | 978693c | 2020-01-24 14:52:10 -0500 | [diff] [blame] | 40 | _sample358 = "half4(1)"; |
Ethan Nicholas | ff4fb33 | 2019-04-09 16:28:19 -0400 | [diff] [blame] | 41 | } |
Ethan Nicholas | 6ad5289 | 2019-05-03 13:13:42 +0000 | [diff] [blame] | 42 | fragBuilder->codeAppendf("%s = mix(%s ? %s : %s, %s ? %s : %s, half(%s));\n", |
| 43 | args.fOutputColor, _outer.child1_index >= 0 ? "true" : "false", |
Ethan Nicholas | 1386366 | 2019-07-29 13:05:15 -0400 | [diff] [blame] | 44 | _sample290.c_str(), args.fInputColor, |
| 45 | _outer.child2_index >= 0 ? "true" : "false", _sample358.c_str(), |
Ethan Nicholas | 6ad5289 | 2019-05-03 13:13:42 +0000 | [diff] [blame] | 46 | args.fInputColor, args.fUniformHandler->getUniformCStr(weightVar)); |
Ethan Nicholas | ff4fb33 | 2019-04-09 16:28:19 -0400 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | private: |
| 50 | void onSetData(const GrGLSLProgramDataManager& pdman, |
| 51 | const GrFragmentProcessor& _proc) override { |
| 52 | const GrComposeLerpEffect& _outer = _proc.cast<GrComposeLerpEffect>(); |
| 53 | { pdman.set1f(weightVar, (_outer.weight)); } |
| 54 | } |
| 55 | UniformHandle weightVar; |
| 56 | }; |
| 57 | GrGLSLFragmentProcessor* GrComposeLerpEffect::onCreateGLSLInstance() const { |
| 58 | return new GrGLSLComposeLerpEffect(); |
| 59 | } |
| 60 | void GrComposeLerpEffect::onGetGLSLProcessorKey(const GrShaderCaps& caps, |
| 61 | GrProcessorKeyBuilder* b) const {} |
| 62 | bool GrComposeLerpEffect::onIsEqual(const GrFragmentProcessor& other) const { |
| 63 | const GrComposeLerpEffect& that = other.cast<GrComposeLerpEffect>(); |
| 64 | (void)that; |
| 65 | if (weight != that.weight) return false; |
| 66 | return true; |
| 67 | } |
| 68 | GrComposeLerpEffect::GrComposeLerpEffect(const GrComposeLerpEffect& src) |
John Stiles | 8818390 | 2020-06-10 16:40:38 -0400 | [diff] [blame^] | 69 | : INHERITED(kGrComposeLerpEffect_ClassID, src.optimizationFlags()), weight(src.weight) { |
| 70 | if (src.child1_index >= 0) { |
| 71 | auto child1_clone = src.childProcessor(src.child1_index).clone(); |
| 72 | if (src.childProcessor(src.child1_index).isSampledWithExplicitCoords()) { |
| 73 | child1_clone->setSampledWithExplicitCoords(); |
Ethan Nicholas | 5843012 | 2020-04-14 09:54:02 -0400 | [diff] [blame] | 74 | } |
John Stiles | 8818390 | 2020-06-10 16:40:38 -0400 | [diff] [blame^] | 75 | child1_index = this->registerChildProcessor(std::move(child1_clone)); |
Ethan Nicholas | ff4fb33 | 2019-04-09 16:28:19 -0400 | [diff] [blame] | 76 | } |
John Stiles | 8818390 | 2020-06-10 16:40:38 -0400 | [diff] [blame^] | 77 | if (src.child2_index >= 0) { |
| 78 | auto child2_clone = src.childProcessor(src.child2_index).clone(); |
| 79 | if (src.childProcessor(src.child2_index).isSampledWithExplicitCoords()) { |
| 80 | child2_clone->setSampledWithExplicitCoords(); |
Ethan Nicholas | 5843012 | 2020-04-14 09:54:02 -0400 | [diff] [blame] | 81 | } |
John Stiles | 8818390 | 2020-06-10 16:40:38 -0400 | [diff] [blame^] | 82 | child2_index = this->registerChildProcessor(std::move(child2_clone)); |
Ethan Nicholas | ff4fb33 | 2019-04-09 16:28:19 -0400 | [diff] [blame] | 83 | } |
| 84 | } |
| 85 | std::unique_ptr<GrFragmentProcessor> GrComposeLerpEffect::clone() const { |
| 86 | return std::unique_ptr<GrFragmentProcessor>(new GrComposeLerpEffect(*this)); |
| 87 | } |