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