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 | |
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" |
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; |
Brian Osman | 12c5d29 | 2020-07-13 16:11:35 -0400 | [diff] [blame] | 32 | SkString _sample453 = this->invokeChild(1, args); |
Michael Ludwig | 4f94ef6 | 2018-09-12 15:22:16 -0400 | [diff] [blame] | 33 | fragBuilder->codeAppendf( |
John Stiles | 5081942 | 2020-06-18 13:00:38 -0400 | [diff] [blame] | 34 | R"SkSL(half4 t = %s; |
| 35 | if (!%s && t.y < 0.0) { |
| 36 | %s = half4(0.0); |
| 37 | } else { |
| 38 | @if (%s) { |
| 39 | half t_1 = t.x - 1.0; |
| 40 | half tiled_t = (t_1 - 2.0 * floor(t_1 * 0.5)) - 1.0; |
| 41 | if (sk_Caps.mustDoOpBetweenFloorAndAbs) { |
| 42 | tiled_t = clamp(tiled_t, -1.0, 1.0); |
| 43 | } |
| 44 | t.x = abs(tiled_t); |
| 45 | } else { |
| 46 | t.x = fract(t.x); |
| 47 | })SkSL", |
Ethan Nicholas | 1386366 | 2019-07-29 13:05:15 -0400 | [diff] [blame] | 48 | _sample453.c_str(), |
Brian Osman | 12c5d29 | 2020-07-13 16:11:35 -0400 | [diff] [blame] | 49 | (_outer.childProcessor(1)->preservesOpaqueInput() ? "true" : "false"), |
Ethan Nicholas | bcd51e8 | 2019-04-09 10:40:41 -0400 | [diff] [blame] | 50 | args.fOutputColor, (_outer.mirror ? "true" : "false")); |
Ethan Nicholas | d4efe68 | 2019-08-29 16:10:13 -0400 | [diff] [blame] | 51 | SkString _input1464("t"); |
Brian Osman | 12c5d29 | 2020-07-13 16:11:35 -0400 | [diff] [blame] | 52 | SkString _sample1464 = this->invokeChild(0, _input1464.c_str(), args); |
John Stiles | 5081942 | 2020-06-18 13:00:38 -0400 | [diff] [blame] | 53 | fragBuilder->codeAppendf( |
| 54 | R"SkSL( |
| 55 | %s = %s; |
| 56 | } |
| 57 | @if (%s) { |
| 58 | %s.xyz *= %s.w; |
| 59 | } |
| 60 | )SkSL", |
| 61 | args.fOutputColor, _sample1464.c_str(), (_outer.makePremul ? "true" : "false"), |
| 62 | args.fOutputColor, args.fOutputColor); |
Michael Ludwig | 4f94ef6 | 2018-09-12 15:22:16 -0400 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | private: |
| 66 | void onSetData(const GrGLSLProgramDataManager& pdman, |
Mike Klein | d6ab77a | 2019-03-21 08:18:24 -0500 | [diff] [blame] | 67 | const GrFragmentProcessor& _proc) override {} |
Michael Ludwig | 4f94ef6 | 2018-09-12 15:22:16 -0400 | [diff] [blame] | 68 | }; |
| 69 | GrGLSLFragmentProcessor* GrTiledGradientEffect::onCreateGLSLInstance() const { |
| 70 | return new GrGLSLTiledGradientEffect(); |
| 71 | } |
Mike Klein | d6ab77a | 2019-03-21 08:18:24 -0500 | [diff] [blame] | 72 | void GrTiledGradientEffect::onGetGLSLProcessorKey(const GrShaderCaps& caps, |
Michael Ludwig | 4f94ef6 | 2018-09-12 15:22:16 -0400 | [diff] [blame] | 73 | GrProcessorKeyBuilder* b) const { |
Ethan Nicholas | bcd51e8 | 2019-04-09 10:40:41 -0400 | [diff] [blame] | 74 | b->add32((int32_t)mirror); |
| 75 | b->add32((int32_t)makePremul); |
Michael Ludwig | 4f94ef6 | 2018-09-12 15:22:16 -0400 | [diff] [blame] | 76 | } |
| 77 | bool GrTiledGradientEffect::onIsEqual(const GrFragmentProcessor& other) const { |
| 78 | const GrTiledGradientEffect& that = other.cast<GrTiledGradientEffect>(); |
| 79 | (void)that; |
Ethan Nicholas | bcd51e8 | 2019-04-09 10:40:41 -0400 | [diff] [blame] | 80 | if (mirror != that.mirror) return false; |
| 81 | if (makePremul != that.makePremul) return false; |
| 82 | if (colorsAreOpaque != that.colorsAreOpaque) return false; |
Michael Ludwig | 4f94ef6 | 2018-09-12 15:22:16 -0400 | [diff] [blame] | 83 | return true; |
| 84 | } |
| 85 | GrTiledGradientEffect::GrTiledGradientEffect(const GrTiledGradientEffect& src) |
Michael Ludwig | b96cba3 | 2018-09-14 13:59:24 -0400 | [diff] [blame] | 86 | : INHERITED(kGrTiledGradientEffect_ClassID, src.optimizationFlags()) |
Ethan Nicholas | bcd51e8 | 2019-04-09 10:40:41 -0400 | [diff] [blame] | 87 | , mirror(src.mirror) |
| 88 | , makePremul(src.makePremul) |
| 89 | , colorsAreOpaque(src.colorsAreOpaque) { |
Brian Osman | 12c5d29 | 2020-07-13 16:11:35 -0400 | [diff] [blame] | 90 | this->cloneAndRegisterAllChildProcessors(src); |
Michael Ludwig | 4f94ef6 | 2018-09-12 15:22:16 -0400 | [diff] [blame] | 91 | } |
| 92 | std::unique_ptr<GrFragmentProcessor> GrTiledGradientEffect::clone() const { |
| 93 | return std::unique_ptr<GrFragmentProcessor>(new GrTiledGradientEffect(*this)); |
| 94 | } |