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 | |
John Stiles | 45f5b03 | 2020-07-27 17:31:29 -0400 | [diff] [blame] | 13 | #include "src/core/SkUtils.h" |
Greg Daniel | 456f9b5 | 2020-03-05 19:14:18 +0000 | [diff] [blame] | 14 | #include "src/gpu/GrTexture.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 15 | #include "src/gpu/glsl/GrGLSLFragmentProcessor.h" |
| 16 | #include "src/gpu/glsl/GrGLSLFragmentShaderBuilder.h" |
| 17 | #include "src/gpu/glsl/GrGLSLProgramBuilder.h" |
| 18 | #include "src/sksl/SkSLCPP.h" |
| 19 | #include "src/sksl/SkSLUtil.h" |
Michael Ludwig | 4f94ef6 | 2018-09-12 15:22:16 -0400 | [diff] [blame] | 20 | class GrGLSLTiledGradientEffect : public GrGLSLFragmentProcessor { |
| 21 | public: |
| 22 | GrGLSLTiledGradientEffect() {} |
| 23 | void emitCode(EmitArgs& args) override { |
Mike Klein | d6ab77a | 2019-03-21 08:18:24 -0500 | [diff] [blame] | 24 | GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder; |
| 25 | const GrTiledGradientEffect& _outer = args.fFp.cast<GrTiledGradientEffect>(); |
Michael Ludwig | 4f94ef6 | 2018-09-12 15:22:16 -0400 | [diff] [blame] | 26 | (void)_outer; |
Ethan Nicholas | bcd51e8 | 2019-04-09 10:40:41 -0400 | [diff] [blame] | 27 | auto mirror = _outer.mirror; |
Michael Ludwig | 4f94ef6 | 2018-09-12 15:22:16 -0400 | [diff] [blame] | 28 | (void)mirror; |
Ethan Nicholas | bcd51e8 | 2019-04-09 10:40:41 -0400 | [diff] [blame] | 29 | auto makePremul = _outer.makePremul; |
Michael Ludwig | b96cba3 | 2018-09-14 13:59:24 -0400 | [diff] [blame] | 30 | (void)makePremul; |
Ethan Nicholas | bcd51e8 | 2019-04-09 10:40:41 -0400 | [diff] [blame] | 31 | auto colorsAreOpaque = _outer.colorsAreOpaque; |
Michael Ludwig | b96cba3 | 2018-09-14 13:59:24 -0400 | [diff] [blame] | 32 | (void)colorsAreOpaque; |
Brian Osman | 12c5d29 | 2020-07-13 16:11:35 -0400 | [diff] [blame] | 33 | SkString _sample453 = this->invokeChild(1, args); |
Michael Ludwig | 4f94ef6 | 2018-09-12 15:22:16 -0400 | [diff] [blame] | 34 | fragBuilder->codeAppendf( |
John Stiles | 5081942 | 2020-06-18 13:00:38 -0400 | [diff] [blame] | 35 | R"SkSL(half4 t = %s; |
| 36 | if (!%s && t.y < 0.0) { |
| 37 | %s = half4(0.0); |
| 38 | } else { |
| 39 | @if (%s) { |
| 40 | half t_1 = t.x - 1.0; |
| 41 | half tiled_t = (t_1 - 2.0 * floor(t_1 * 0.5)) - 1.0; |
| 42 | if (sk_Caps.mustDoOpBetweenFloorAndAbs) { |
| 43 | tiled_t = clamp(tiled_t, -1.0, 1.0); |
| 44 | } |
| 45 | t.x = abs(tiled_t); |
| 46 | } else { |
| 47 | t.x = fract(t.x); |
| 48 | })SkSL", |
Ethan Nicholas | 1386366 | 2019-07-29 13:05:15 -0400 | [diff] [blame] | 49 | _sample453.c_str(), |
Brian Osman | 12c5d29 | 2020-07-13 16:11:35 -0400 | [diff] [blame] | 50 | (_outer.childProcessor(1)->preservesOpaqueInput() ? "true" : "false"), |
Ethan Nicholas | bcd51e8 | 2019-04-09 10:40:41 -0400 | [diff] [blame] | 51 | args.fOutputColor, (_outer.mirror ? "true" : "false")); |
John Stiles | fada8bd | 2020-07-31 15:49:28 -0400 | [diff] [blame] | 52 | SkString _coords1451("float2(half2(t.x, 0))"); |
| 53 | SkString _sample1451 = this->invokeChild(0, args, _coords1451.c_str()); |
John Stiles | 5081942 | 2020-06-18 13:00:38 -0400 | [diff] [blame] | 54 | fragBuilder->codeAppendf( |
| 55 | R"SkSL( |
| 56 | %s = %s; |
| 57 | } |
| 58 | @if (%s) { |
| 59 | %s.xyz *= %s.w; |
| 60 | } |
| 61 | )SkSL", |
John Stiles | fada8bd | 2020-07-31 15:49:28 -0400 | [diff] [blame] | 62 | args.fOutputColor, _sample1451.c_str(), (_outer.makePremul ? "true" : "false"), |
John Stiles | 5081942 | 2020-06-18 13:00:38 -0400 | [diff] [blame] | 63 | args.fOutputColor, args.fOutputColor); |
Michael Ludwig | 4f94ef6 | 2018-09-12 15:22:16 -0400 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | private: |
| 67 | void onSetData(const GrGLSLProgramDataManager& pdman, |
Mike Klein | d6ab77a | 2019-03-21 08:18:24 -0500 | [diff] [blame] | 68 | const GrFragmentProcessor& _proc) override {} |
Michael Ludwig | 4f94ef6 | 2018-09-12 15:22:16 -0400 | [diff] [blame] | 69 | }; |
| 70 | GrGLSLFragmentProcessor* GrTiledGradientEffect::onCreateGLSLInstance() const { |
| 71 | return new GrGLSLTiledGradientEffect(); |
| 72 | } |
Mike Klein | d6ab77a | 2019-03-21 08:18:24 -0500 | [diff] [blame] | 73 | void GrTiledGradientEffect::onGetGLSLProcessorKey(const GrShaderCaps& caps, |
Michael Ludwig | 4f94ef6 | 2018-09-12 15:22:16 -0400 | [diff] [blame] | 74 | GrProcessorKeyBuilder* b) const { |
John Stiles | 45f5b03 | 2020-07-27 17:31:29 -0400 | [diff] [blame] | 75 | b->add32((uint32_t)mirror); |
| 76 | b->add32((uint32_t)makePremul); |
Michael Ludwig | 4f94ef6 | 2018-09-12 15:22:16 -0400 | [diff] [blame] | 77 | } |
| 78 | bool GrTiledGradientEffect::onIsEqual(const GrFragmentProcessor& other) const { |
| 79 | const GrTiledGradientEffect& that = other.cast<GrTiledGradientEffect>(); |
| 80 | (void)that; |
Ethan Nicholas | bcd51e8 | 2019-04-09 10:40:41 -0400 | [diff] [blame] | 81 | if (mirror != that.mirror) return false; |
| 82 | if (makePremul != that.makePremul) return false; |
| 83 | if (colorsAreOpaque != that.colorsAreOpaque) return false; |
Michael Ludwig | 4f94ef6 | 2018-09-12 15:22:16 -0400 | [diff] [blame] | 84 | return true; |
| 85 | } |
| 86 | GrTiledGradientEffect::GrTiledGradientEffect(const GrTiledGradientEffect& src) |
Michael Ludwig | b96cba3 | 2018-09-14 13:59:24 -0400 | [diff] [blame] | 87 | : INHERITED(kGrTiledGradientEffect_ClassID, src.optimizationFlags()) |
Ethan Nicholas | bcd51e8 | 2019-04-09 10:40:41 -0400 | [diff] [blame] | 88 | , mirror(src.mirror) |
| 89 | , makePremul(src.makePremul) |
| 90 | , colorsAreOpaque(src.colorsAreOpaque) { |
Brian Osman | 12c5d29 | 2020-07-13 16:11:35 -0400 | [diff] [blame] | 91 | this->cloneAndRegisterAllChildProcessors(src); |
Michael Ludwig | 4f94ef6 | 2018-09-12 15:22:16 -0400 | [diff] [blame] | 92 | } |
| 93 | std::unique_ptr<GrFragmentProcessor> GrTiledGradientEffect::clone() const { |
John Stiles | fbd050b | 2020-08-03 13:21:46 -0400 | [diff] [blame^] | 94 | return std::make_unique<GrTiledGradientEffect>(*this); |
Michael Ludwig | 4f94ef6 | 2018-09-12 15:22:16 -0400 | [diff] [blame] | 95 | } |