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; |
| 27 | SkString _child1("_child1"); |
| 28 | this->emitChild(1, &_child1, args); |
| 29 | fragBuilder->codeAppendf( |
Michael Ludwig | 8f68508 | 2018-09-12 15:23:01 -0400 | [diff] [blame^] | 30 | "half4 t = %s;\nif (t.y < 0.0) {\n %s = half4(0.0);\n} else {\n @if (%s) {\n " |
| 31 | " half t_1 = t.x - 1.0;\n half tiled_t = (float(t_1) - 2.0 * " |
| 32 | "floor(float(float(t_1) * 0.5))) - 1.0;\n if " |
| 33 | "(sk_Caps.mustDoOpBetweenFloorAndAbs) {\n tiled_t = " |
| 34 | "half(clamp(float(tiled_t), -1.0, 1.0));\n }\n t.x = " |
| 35 | "half(abs(float(tiled_t)));\n } else {\n t.x = " |
| 36 | "half(fract(float(t.x)));\n }", |
| 37 | _child1.c_str(), args.fOutputColor, (_outer.mirror() ? "true" : "false")); |
Michael Ludwig | 4f94ef6 | 2018-09-12 15:22:16 -0400 | [diff] [blame] | 38 | SkString _input0("t"); |
| 39 | SkString _child0("_child0"); |
| 40 | this->emitChild(0, _input0.c_str(), &_child0, args); |
Michael Ludwig | 8f68508 | 2018-09-12 15:23:01 -0400 | [diff] [blame^] | 41 | fragBuilder->codeAppendf("\n %s = %s;\n}\n", args.fOutputColor, _child0.c_str()); |
Michael Ludwig | 4f94ef6 | 2018-09-12 15:22:16 -0400 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | private: |
| 45 | void onSetData(const GrGLSLProgramDataManager& pdman, |
| 46 | const GrFragmentProcessor& _proc) override {} |
| 47 | }; |
| 48 | GrGLSLFragmentProcessor* GrTiledGradientEffect::onCreateGLSLInstance() const { |
| 49 | return new GrGLSLTiledGradientEffect(); |
| 50 | } |
| 51 | void GrTiledGradientEffect::onGetGLSLProcessorKey(const GrShaderCaps& caps, |
| 52 | GrProcessorKeyBuilder* b) const { |
| 53 | b->add32((int32_t)fMirror); |
| 54 | } |
| 55 | bool GrTiledGradientEffect::onIsEqual(const GrFragmentProcessor& other) const { |
| 56 | const GrTiledGradientEffect& that = other.cast<GrTiledGradientEffect>(); |
| 57 | (void)that; |
| 58 | if (fMirror != that.fMirror) return false; |
| 59 | return true; |
| 60 | } |
| 61 | GrTiledGradientEffect::GrTiledGradientEffect(const GrTiledGradientEffect& src) |
| 62 | : INHERITED(kGrTiledGradientEffect_ClassID, src.optimizationFlags()), fMirror(src.fMirror) { |
| 63 | this->registerChildProcessor(src.childProcessor(0).clone()); |
| 64 | this->registerChildProcessor(src.childProcessor(1).clone()); |
| 65 | } |
| 66 | std::unique_ptr<GrFragmentProcessor> GrTiledGradientEffect::clone() const { |
| 67 | return std::unique_ptr<GrFragmentProcessor>(new GrTiledGradientEffect(*this)); |
| 68 | } |