Ethan Nicholas | eace935 | 2018-10-15 20:09:54 +0000 | [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 GrAARectEffect.fp; do not modify. |
| 10 | **************************************************************************************************/ |
| 11 | #include "GrAARectEffect.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" |
Ethan Nicholas | eace935 | 2018-10-15 20:09:54 +0000 | [diff] [blame] | 19 | class GrGLSLAARectEffect : public GrGLSLFragmentProcessor { |
| 20 | public: |
| 21 | GrGLSLAARectEffect() {} |
| 22 | void emitCode(EmitArgs& args) override { |
| 23 | GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder; |
Mike Klein | d6ab77a | 2019-03-21 08:18:24 -0500 | [diff] [blame] | 24 | const GrAARectEffect& _outer = args.fFp.cast<GrAARectEffect>(); |
Ethan Nicholas | eace935 | 2018-10-15 20:09:54 +0000 | [diff] [blame] | 25 | (void)_outer; |
Ethan Nicholas | bcd51e8 | 2019-04-09 10:40:41 -0400 | [diff] [blame] | 26 | auto edgeType = _outer.edgeType; |
Ethan Nicholas | eace935 | 2018-10-15 20:09:54 +0000 | [diff] [blame] | 27 | (void)edgeType; |
Ethan Nicholas | bcd51e8 | 2019-04-09 10:40:41 -0400 | [diff] [blame] | 28 | auto rect = _outer.rect; |
Ethan Nicholas | eace935 | 2018-10-15 20:09:54 +0000 | [diff] [blame] | 29 | (void)rect; |
Mike Klein | d6ab77a | 2019-03-21 08:18:24 -0500 | [diff] [blame] | 30 | prevRect = float4(-1.0); |
Ethan Nicholas | bcd51e8 | 2019-04-09 10:40:41 -0400 | [diff] [blame] | 31 | rectUniformVar = args.fUniformHandler->addUniform( |
Ethan Nicholas | 16464c3 | 2020-04-06 13:53:05 -0400 | [diff] [blame] | 32 | &_outer, kFragment_GrShaderFlag, kFloat4_GrSLType, "rectUniform"); |
Ethan Nicholas | eace935 | 2018-10-15 20:09:54 +0000 | [diff] [blame] | 33 | fragBuilder->codeAppendf( |
| 34 | "float4 prevRect = float4(%f, %f, %f, %f);\nhalf alpha;\n@switch (%d) {\n case " |
| 35 | "0:\n case 2:\n alpha = half(all(greaterThan(float4(sk_FragCoord.xy, " |
| 36 | "%s.zw), float4(%s.xy, sk_FragCoord.xy))) ? 1 : 0);\n break;\n " |
Ethan Nicholas | e1f5502 | 2019-02-05 17:17:40 -0500 | [diff] [blame] | 37 | "default:\n half xSub, ySub;\n xSub = min(half(sk_FragCoord.x - " |
| 38 | "%s.x), 0.0);\n xSub += min(half(%s.z - sk_FragCoord.x), 0.0);\n " |
| 39 | "ySub = min(half(sk_FragCoord.y - %s.y), 0.0);\n ySub += min(half(%s.w - " |
| 40 | "sk_FragCoord.y), 0.0);\n alpha = (1.0 + ", |
Ethan Nicholas | eace935 | 2018-10-15 20:09:54 +0000 | [diff] [blame] | 41 | prevRect.left(), |
| 42 | prevRect.top(), |
| 43 | prevRect.right(), |
| 44 | prevRect.bottom(), |
Ethan Nicholas | bcd51e8 | 2019-04-09 10:40:41 -0400 | [diff] [blame] | 45 | (int)_outer.edgeType, |
| 46 | args.fUniformHandler->getUniformCStr(rectUniformVar), |
| 47 | args.fUniformHandler->getUniformCStr(rectUniformVar), |
| 48 | args.fUniformHandler->getUniformCStr(rectUniformVar), |
| 49 | args.fUniformHandler->getUniformCStr(rectUniformVar), |
| 50 | args.fUniformHandler->getUniformCStr(rectUniformVar), |
| 51 | args.fUniformHandler->getUniformCStr(rectUniformVar)); |
Ethan Nicholas | eace935 | 2018-10-15 20:09:54 +0000 | [diff] [blame] | 52 | fragBuilder->codeAppendf( |
Ethan Nicholas | e1f5502 | 2019-02-05 17:17:40 -0500 | [diff] [blame] | 53 | "max(xSub, -1.0)) * (1.0 + max(ySub, -1.0));\n}\n@if (%d == 2 || %d == 3) {\n " |
John Stiles | f79ef18 | 2020-06-05 13:38:16 -0400 | [diff] [blame^] | 54 | "alpha = 1.0 - alpha;\n}", |
Ethan Nicholas | bcd51e8 | 2019-04-09 10:40:41 -0400 | [diff] [blame] | 55 | (int)_outer.edgeType, |
John Stiles | f79ef18 | 2020-06-05 13:38:16 -0400 | [diff] [blame^] | 56 | (int)_outer.edgeType); |
| 57 | SkString _input1697 = SkStringPrintf("%s", args.fInputColor); |
| 58 | SkString _sample1697; |
| 59 | if (_outer.inputFP_index >= 0) { |
| 60 | _sample1697 = this->invokeChild(_outer.inputFP_index, _input1697.c_str(), args); |
| 61 | } else { |
| 62 | _sample1697 = "half4(1)"; |
| 63 | } |
| 64 | fragBuilder->codeAppendf("\nhalf4 inputColor = %s ? %s : %s;\n%s = inputColor * alpha;\n", |
| 65 | _outer.inputFP_index >= 0 ? "true" : "false", |
| 66 | _sample1697.c_str(), |
| 67 | args.fInputColor, |
| 68 | args.fOutputColor); |
Ethan Nicholas | eace935 | 2018-10-15 20:09:54 +0000 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | private: |
| 72 | void onSetData(const GrGLSLProgramDataManager& pdman, |
Mike Klein | d6ab77a | 2019-03-21 08:18:24 -0500 | [diff] [blame] | 73 | const GrFragmentProcessor& _proc) override { |
| 74 | const GrAARectEffect& _outer = _proc.cast<GrAARectEffect>(); |
Ethan Nicholas | bcd51e8 | 2019-04-09 10:40:41 -0400 | [diff] [blame] | 75 | auto edgeType = _outer.edgeType; |
Ethan Nicholas | eace935 | 2018-10-15 20:09:54 +0000 | [diff] [blame] | 76 | (void)edgeType; |
Ethan Nicholas | bcd51e8 | 2019-04-09 10:40:41 -0400 | [diff] [blame] | 77 | auto rect = _outer.rect; |
Ethan Nicholas | eace935 | 2018-10-15 20:09:54 +0000 | [diff] [blame] | 78 | (void)rect; |
Ethan Nicholas | bcd51e8 | 2019-04-09 10:40:41 -0400 | [diff] [blame] | 79 | UniformHandle& rectUniform = rectUniformVar; |
Ethan Nicholas | eace935 | 2018-10-15 20:09:54 +0000 | [diff] [blame] | 80 | (void)rectUniform; |
| 81 | |
| 82 | const SkRect& newRect = GrProcessorEdgeTypeIsAA(edgeType) ? rect.makeInset(.5f, .5f) : rect; |
| 83 | if (newRect != prevRect) { |
| 84 | pdman.set4f(rectUniform, newRect.fLeft, newRect.fTop, newRect.fRight, newRect.fBottom); |
| 85 | prevRect = newRect; |
| 86 | } |
| 87 | } |
Mike Klein | d6ab77a | 2019-03-21 08:18:24 -0500 | [diff] [blame] | 88 | SkRect prevRect = float4(0); |
Ethan Nicholas | bcd51e8 | 2019-04-09 10:40:41 -0400 | [diff] [blame] | 89 | UniformHandle rectUniformVar; |
Ethan Nicholas | eace935 | 2018-10-15 20:09:54 +0000 | [diff] [blame] | 90 | }; |
| 91 | GrGLSLFragmentProcessor* GrAARectEffect::onCreateGLSLInstance() const { |
| 92 | return new GrGLSLAARectEffect(); |
| 93 | } |
Mike Klein | d6ab77a | 2019-03-21 08:18:24 -0500 | [diff] [blame] | 94 | void GrAARectEffect::onGetGLSLProcessorKey(const GrShaderCaps& caps, |
Ethan Nicholas | eace935 | 2018-10-15 20:09:54 +0000 | [diff] [blame] | 95 | GrProcessorKeyBuilder* b) const { |
Ethan Nicholas | bcd51e8 | 2019-04-09 10:40:41 -0400 | [diff] [blame] | 96 | b->add32((int32_t)edgeType); |
Ethan Nicholas | eace935 | 2018-10-15 20:09:54 +0000 | [diff] [blame] | 97 | } |
| 98 | bool GrAARectEffect::onIsEqual(const GrFragmentProcessor& other) const { |
| 99 | const GrAARectEffect& that = other.cast<GrAARectEffect>(); |
| 100 | (void)that; |
Ethan Nicholas | bcd51e8 | 2019-04-09 10:40:41 -0400 | [diff] [blame] | 101 | if (edgeType != that.edgeType) return false; |
| 102 | if (rect != that.rect) return false; |
Ethan Nicholas | eace935 | 2018-10-15 20:09:54 +0000 | [diff] [blame] | 103 | return true; |
| 104 | } |
| 105 | GrAARectEffect::GrAARectEffect(const GrAARectEffect& src) |
| 106 | : INHERITED(kGrAARectEffect_ClassID, src.optimizationFlags()) |
John Stiles | f79ef18 | 2020-06-05 13:38:16 -0400 | [diff] [blame^] | 107 | , inputFP_index(src.inputFP_index) |
Ethan Nicholas | bcd51e8 | 2019-04-09 10:40:41 -0400 | [diff] [blame] | 108 | , edgeType(src.edgeType) |
John Stiles | f79ef18 | 2020-06-05 13:38:16 -0400 | [diff] [blame^] | 109 | , rect(src.rect) { |
| 110 | if (inputFP_index >= 0) { |
| 111 | auto clone = src.childProcessor(inputFP_index).clone(); |
| 112 | if (src.childProcessor(inputFP_index).isSampledWithExplicitCoords()) { |
| 113 | clone->setSampledWithExplicitCoords(); |
| 114 | } |
| 115 | this->registerChildProcessor(std::move(clone)); |
| 116 | } |
| 117 | } |
Ethan Nicholas | eace935 | 2018-10-15 20:09:54 +0000 | [diff] [blame] | 118 | std::unique_ptr<GrFragmentProcessor> GrAARectEffect::clone() const { |
| 119 | return std::unique_ptr<GrFragmentProcessor>(new GrAARectEffect(*this)); |
| 120 | } |
| 121 | GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrAARectEffect); |
| 122 | #if GR_TEST_UTILS |
| 123 | std::unique_ptr<GrFragmentProcessor> GrAARectEffect::TestCreate(GrProcessorTestData* d) { |
Mike Klein | d6ab77a | 2019-03-21 08:18:24 -0500 | [diff] [blame] | 124 | SkRect rect = SkRect::MakeLTRB(d->fRandom->nextSScalar1(), |
Ethan Nicholas | eace935 | 2018-10-15 20:09:54 +0000 | [diff] [blame] | 125 | d->fRandom->nextSScalar1(), |
| 126 | d->fRandom->nextSScalar1(), |
| 127 | d->fRandom->nextSScalar1()); |
| 128 | std::unique_ptr<GrFragmentProcessor> fp; |
| 129 | do { |
| 130 | GrClipEdgeType edgeType = |
| 131 | static_cast<GrClipEdgeType>(d->fRandom->nextULessThan(kGrClipEdgeTypeCnt)); |
| 132 | |
John Stiles | f79ef18 | 2020-06-05 13:38:16 -0400 | [diff] [blame^] | 133 | fp = GrAARectEffect::Make(/*inputFP=*/nullptr, edgeType, rect); |
Ethan Nicholas | eace935 | 2018-10-15 20:09:54 +0000 | [diff] [blame] | 134 | } while (nullptr == fp); |
| 135 | return fp; |
| 136 | } |
| 137 | #endif |