Michael Ludwig | 4f94ef6 | 2018-09-12 15:22:16 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2018 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 GrTiledGradientEffect.fp; do not modify. |
| 10 | **************************************************************************************************/ |
| 11 | #include "GrTiledGradientEffect.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 GrGLSLTiledGradientEffect : public GrGLSLFragmentProcessor { |
| 19 | public: |
| 20 | GrGLSLTiledGradientEffect() {} |
| 21 | void emitCode(EmitArgs& args) override { |
| 22 | GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder; |
| 23 | const GrTiledGradientEffect& _outer = args.fFp.cast<GrTiledGradientEffect>(); |
| 24 | (void)_outer; |
| 25 | auto mirror = _outer.mirror(); |
| 26 | (void)mirror; |
Michael Ludwig | b96cba3 | 2018-09-14 13:59:24 -0400 | [diff] [blame] | 27 | auto makePremul = _outer.makePremul(); |
| 28 | (void)makePremul; |
| 29 | auto colorsAreOpaque = _outer.colorsAreOpaque(); |
| 30 | (void)colorsAreOpaque; |
Michael Ludwig | 4f94ef6 | 2018-09-12 15:22:16 -0400 | [diff] [blame] | 31 | SkString _child1("_child1"); |
Robert Phillips | bce7d86 | 2019-02-21 22:53:57 +0000 | [diff] [blame] | 32 | this->emitChild(1, &_child1, args); |
Michael Ludwig | 4f94ef6 | 2018-09-12 15:22:16 -0400 | [diff] [blame] | 33 | fragBuilder->codeAppendf( |
Michael Ludwig | b96cba3 | 2018-09-14 13:59:24 -0400 | [diff] [blame] | 34 | "half4 t = %s;\nif (!%s && t.y < 0.0) {\n %s = half4(0.0);\n} else {\n @if " |
Ethan Nicholas | e1f5502 | 2019-02-05 17:17:40 -0500 | [diff] [blame] | 35 | "(%s) {\n half t_1 = t.x - 1.0;\n half tiled_t = (t_1 - 2.0 * " |
| 36 | "floor(t_1 * 0.5)) - 1.0;\n if (sk_Caps.mustDoOpBetweenFloorAndAbs) {\n " |
| 37 | " tiled_t = clamp(tiled_t, -1.0, 1.0);\n }\n t.x = " |
| 38 | "abs(tiled_t);\n } else {\n t.x = fract(t.x);\n }", |
Michael Ludwig | b96cba3 | 2018-09-14 13:59:24 -0400 | [diff] [blame] | 39 | _child1.c_str(), |
Robert Phillips | bce7d86 | 2019-02-21 22:53:57 +0000 | [diff] [blame] | 40 | (_outer.childProcessor(1).preservesOpaqueInput() ? "true" : "false"), |
Michael Ludwig | b96cba3 | 2018-09-14 13:59:24 -0400 | [diff] [blame] | 41 | args.fOutputColor, (_outer.mirror() ? "true" : "false")); |
Michael Ludwig | 4f94ef6 | 2018-09-12 15:22:16 -0400 | [diff] [blame] | 42 | SkString _input0("t"); |
| 43 | SkString _child0("_child0"); |
Robert Phillips | bce7d86 | 2019-02-21 22:53:57 +0000 | [diff] [blame] | 44 | this->emitChild(0, _input0.c_str(), &_child0, args); |
Michael Ludwig | b96cba3 | 2018-09-14 13:59:24 -0400 | [diff] [blame] | 45 | fragBuilder->codeAppendf("\n %s = %s;\n}\n@if (%s) {\n %s.xyz *= %s.w;\n}\n", |
| 46 | args.fOutputColor, _child0.c_str(), |
| 47 | (_outer.makePremul() ? "true" : "false"), args.fOutputColor, |
| 48 | args.fOutputColor); |
Michael Ludwig | 4f94ef6 | 2018-09-12 15:22:16 -0400 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | private: |
| 52 | void onSetData(const GrGLSLProgramDataManager& pdman, |
| 53 | const GrFragmentProcessor& _proc) override {} |
| 54 | }; |
| 55 | GrGLSLFragmentProcessor* GrTiledGradientEffect::onCreateGLSLInstance() const { |
| 56 | return new GrGLSLTiledGradientEffect(); |
| 57 | } |
| 58 | void GrTiledGradientEffect::onGetGLSLProcessorKey(const GrShaderCaps& caps, |
| 59 | GrProcessorKeyBuilder* b) const { |
| 60 | b->add32((int32_t)fMirror); |
Michael Ludwig | b96cba3 | 2018-09-14 13:59:24 -0400 | [diff] [blame] | 61 | b->add32((int32_t)fMakePremul); |
Michael Ludwig | 4f94ef6 | 2018-09-12 15:22:16 -0400 | [diff] [blame] | 62 | } |
| 63 | bool GrTiledGradientEffect::onIsEqual(const GrFragmentProcessor& other) const { |
| 64 | const GrTiledGradientEffect& that = other.cast<GrTiledGradientEffect>(); |
| 65 | (void)that; |
| 66 | if (fMirror != that.fMirror) return false; |
Michael Ludwig | b96cba3 | 2018-09-14 13:59:24 -0400 | [diff] [blame] | 67 | if (fMakePremul != that.fMakePremul) return false; |
| 68 | if (fColorsAreOpaque != that.fColorsAreOpaque) return false; |
Michael Ludwig | 4f94ef6 | 2018-09-12 15:22:16 -0400 | [diff] [blame] | 69 | return true; |
| 70 | } |
| 71 | GrTiledGradientEffect::GrTiledGradientEffect(const GrTiledGradientEffect& src) |
Michael Ludwig | b96cba3 | 2018-09-14 13:59:24 -0400 | [diff] [blame] | 72 | : INHERITED(kGrTiledGradientEffect_ClassID, src.optimizationFlags()) |
| 73 | , fMirror(src.fMirror) |
| 74 | , fMakePremul(src.fMakePremul) |
| 75 | , fColorsAreOpaque(src.fColorsAreOpaque) { |
Robert Phillips | bce7d86 | 2019-02-21 22:53:57 +0000 | [diff] [blame] | 76 | this->registerChildProcessor(src.childProcessor(0).clone()); |
| 77 | this->registerChildProcessor(src.childProcessor(1).clone()); |
Michael Ludwig | 4f94ef6 | 2018-09-12 15:22:16 -0400 | [diff] [blame] | 78 | } |
| 79 | std::unique_ptr<GrFragmentProcessor> GrTiledGradientEffect::clone() const { |
| 80 | return std::unique_ptr<GrFragmentProcessor>(new GrTiledGradientEffect(*this)); |
| 81 | } |