Ethan Nicholas | 8239946 | 2017-10-16 12:35:44 -0400 | [diff] [blame] | 1 | /* |
Ethan Nicholas | 130fb3f | 2018-02-01 12:14:34 -0500 | [diff] [blame] | 2 | * Copyright 2018 Google Inc. |
Ethan Nicholas | 8239946 | 2017-10-16 12:35:44 -0400 | [diff] [blame] | 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 | |
Ethan Nicholas | 130fb3f | 2018-02-01 12:14:34 -0500 | [diff] [blame] | 8 | /************************************************************************************************** |
| 9 | *** This file was autogenerated from GrRectBlurEffect.fp; do not modify. |
| 10 | **************************************************************************************************/ |
Ethan Nicholas | 8239946 | 2017-10-16 12:35:44 -0400 | [diff] [blame] | 11 | #include "GrRectBlurEffect.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 | 8239946 | 2017-10-16 12:35:44 -0400 | [diff] [blame] | 19 | class GrGLSLRectBlurEffect : public GrGLSLFragmentProcessor { |
| 20 | public: |
| 21 | GrGLSLRectBlurEffect() {} |
| 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 GrRectBlurEffect& _outer = args.fFp.cast<GrRectBlurEffect>(); |
Ethan Nicholas | 8239946 | 2017-10-16 12:35:44 -0400 | [diff] [blame] | 25 | (void)_outer; |
Ethan Nicholas | bcd51e8 | 2019-04-09 10:40:41 -0400 | [diff] [blame] | 26 | auto rect = _outer.rect; |
Ethan Nicholas | 8239946 | 2017-10-16 12:35:44 -0400 | [diff] [blame] | 27 | (void)rect; |
Brian Salomon | b2d5d40 | 2019-09-10 10:11:52 -0400 | [diff] [blame] | 28 | auto invSixSigma = _outer.invSixSigma; |
| 29 | (void)invSixSigma; |
| 30 | auto isFast = _outer.isFast; |
| 31 | (void)isFast; |
Brian Salomon | 2c59659 | 2019-08-13 20:05:04 -0400 | [diff] [blame] | 32 | highp = ((abs(rect.left()) > 16000.0 || abs(rect.top()) > 16000.0) || |
| 33 | abs(rect.right()) > 16000.0) || |
| 34 | abs(rect.bottom()) > 16000.0; |
| 35 | if (highp) { |
Ethan Nicholas | 16464c3 | 2020-04-06 13:53:05 -0400 | [diff] [blame] | 36 | rectFVar = args.fUniformHandler->addUniform(&_outer, kFragment_GrShaderFlag, |
| 37 | kFloat4_GrSLType, "rectF"); |
Ethan Nicholas | 8239946 | 2017-10-16 12:35:44 -0400 | [diff] [blame] | 38 | } |
Brian Salomon | 2c59659 | 2019-08-13 20:05:04 -0400 | [diff] [blame] | 39 | if (!highp) { |
Ethan Nicholas | 16464c3 | 2020-04-06 13:53:05 -0400 | [diff] [blame] | 40 | rectHVar = args.fUniformHandler->addUniform(&_outer, kFragment_GrShaderFlag, |
| 41 | kHalf4_GrSLType, "rectH"); |
Ethan Nicholas | 8239946 | 2017-10-16 12:35:44 -0400 | [diff] [blame] | 42 | } |
Ethan Nicholas | 16464c3 | 2020-04-06 13:53:05 -0400 | [diff] [blame] | 43 | invSixSigmaVar = args.fUniformHandler->addUniform(&_outer, kFragment_GrShaderFlag, |
| 44 | kHalf_GrSLType, "invSixSigma"); |
Ethan Nicholas | 8239946 | 2017-10-16 12:35:44 -0400 | [diff] [blame] | 45 | fragBuilder->codeAppendf( |
John Stiles | e7b4d73 | 2020-06-10 12:46:40 -0400 | [diff] [blame] | 46 | "/* key */ bool highp = %s;\nhalf xCoverage, yCoverage;\n@if (%s) {\n half2 " |
| 47 | "xy;\n @if (highp) {\n xy = max(half2(%s.xy - sk_FragCoord.xy), " |
| 48 | "half2(sk_FragCoord.xy - %s.zw));\n } else {\n xy = " |
| 49 | "max(half2(float2(%s.xy) - sk_FragCoord.xy), half2(sk_FragCoord.xy - " |
| 50 | "float2(%s.zw)));\n }\n xy *= %s;\n xCoverage = sample(%s, " |
| 51 | "float2(half2(xy.x, 0.5))).%s.w;\n yCoverage = sample(%s, float2(half2(xy.y, " |
| 52 | "0.5))).%s.w;\n} else {\n half4 rect;\n @if (highp) {\n rect.xy = " |
| 53 | "half2(sk", |
Brian Salomon | b2d5d40 | 2019-09-10 10:11:52 -0400 | [diff] [blame] | 54 | (highp ? "true" : "false"), (_outer.isFast ? "true" : "false"), |
| 55 | rectFVar.isValid() ? args.fUniformHandler->getUniformCStr(rectFVar) : "float4(0)", |
| 56 | rectFVar.isValid() ? args.fUniformHandler->getUniformCStr(rectFVar) : "float4(0)", |
Brian Salomon | 2c59659 | 2019-08-13 20:05:04 -0400 | [diff] [blame] | 57 | rectHVar.isValid() ? args.fUniformHandler->getUniformCStr(rectHVar) : "half4(0)", |
Brian Salomon | 5331e2a | 2019-08-19 17:18:10 -0400 | [diff] [blame] | 58 | rectHVar.isValid() ? args.fUniformHandler->getUniformCStr(rectHVar) : "half4(0)", |
John Stiles | e7b4d73 | 2020-06-10 12:46:40 -0400 | [diff] [blame] | 59 | args.fUniformHandler->getUniformCStr(invSixSigmaVar), |
Brian Salomon | e736684 | 2019-09-04 11:20:45 -0400 | [diff] [blame] | 60 | fragBuilder->getProgramBuilder()->samplerVariable(args.fTexSamplers[0]), |
John Stiles | e7b4d73 | 2020-06-10 12:46:40 -0400 | [diff] [blame] | 61 | fragBuilder->getProgramBuilder() |
| 62 | ->samplerSwizzle(args.fTexSamplers[0]) |
| 63 | .asString() |
| 64 | .c_str(), |
| 65 | fragBuilder->getProgramBuilder()->samplerVariable(args.fTexSamplers[0]), |
| 66 | fragBuilder->getProgramBuilder() |
| 67 | ->samplerSwizzle(args.fTexSamplers[0]) |
| 68 | .asString() |
| 69 | .c_str()); |
Ethan Nicholas | 8239946 | 2017-10-16 12:35:44 -0400 | [diff] [blame] | 70 | fragBuilder->codeAppendf( |
John Stiles | e7b4d73 | 2020-06-10 12:46:40 -0400 | [diff] [blame] | 71 | "_FragCoord.xy - %s.xy);\n rect.zw = half2(%s.zw - sk_FragCoord.xy);\n } " |
| 72 | "else {\n rect.xy = half2(sk_FragCoord.xy - float2(%s.xy));\n " |
| 73 | "rect.zw = half2(float2(%s.zw) - sk_FragCoord.xy);\n }\n half4 irect = rect " |
| 74 | "* %s + half4(1.0);\n xCoverage = (1.0 - sample(%s, float2(half2(irect.x, " |
| 75 | "0.5))).%s.w) - sample(%s, float2(half2(irect.z, 0.5))).%s.w;\n yCoverage = " |
| 76 | "(1.0 - sample(%s, float2(half2(irect.y, 0.5))).%s.w) - sample(%s, " |
| 77 | "float2(half2(irect.w, 0.5))).%s.w;\n}", |
| 78 | rectFVar.isValid() ? args.fUniformHandler->getUniformCStr(rectFVar) : "float4(0)", |
| 79 | rectFVar.isValid() ? args.fUniformHandler->getUniformCStr(rectFVar) : "float4(0)", |
| 80 | rectHVar.isValid() ? args.fUniformHandler->getUniformCStr(rectHVar) : "half4(0)", |
| 81 | rectHVar.isValid() ? args.fUniformHandler->getUniformCStr(rectHVar) : "half4(0)", |
| 82 | args.fUniformHandler->getUniformCStr(invSixSigmaVar), |
| 83 | fragBuilder->getProgramBuilder()->samplerVariable(args.fTexSamplers[0]), |
Greg Daniel | 369ee6b | 2019-12-02 15:30:02 -0500 | [diff] [blame] | 84 | fragBuilder->getProgramBuilder() |
| 85 | ->samplerSwizzle(args.fTexSamplers[0]) |
| 86 | .asString() |
| 87 | .c_str(), |
Brian Salomon | b2d5d40 | 2019-09-10 10:11:52 -0400 | [diff] [blame] | 88 | fragBuilder->getProgramBuilder()->samplerVariable(args.fTexSamplers[0]), |
Greg Daniel | 369ee6b | 2019-12-02 15:30:02 -0500 | [diff] [blame] | 89 | fragBuilder->getProgramBuilder() |
| 90 | ->samplerSwizzle(args.fTexSamplers[0]) |
| 91 | .asString() |
| 92 | .c_str(), |
John Stiles | e7b4d73 | 2020-06-10 12:46:40 -0400 | [diff] [blame] | 93 | fragBuilder->getProgramBuilder()->samplerVariable(args.fTexSamplers[0]), |
| 94 | fragBuilder->getProgramBuilder() |
| 95 | ->samplerSwizzle(args.fTexSamplers[0]) |
| 96 | .asString() |
| 97 | .c_str(), |
| 98 | fragBuilder->getProgramBuilder()->samplerVariable(args.fTexSamplers[0]), |
| 99 | fragBuilder->getProgramBuilder() |
| 100 | ->samplerSwizzle(args.fTexSamplers[0]) |
| 101 | .asString() |
| 102 | .c_str()); |
| 103 | SkString _input8899 = SkStringPrintf("%s", args.fInputColor); |
| 104 | SkString _sample8899; |
| 105 | if (_outer.inputFP_index >= 0) { |
| 106 | _sample8899 = this->invokeChild(_outer.inputFP_index, _input8899.c_str(), args); |
| 107 | } else { |
| 108 | _sample8899 = _input8899; |
| 109 | } |
Brian Salomon | b2d5d40 | 2019-09-10 10:11:52 -0400 | [diff] [blame] | 110 | fragBuilder->codeAppendf( |
John Stiles | e7b4d73 | 2020-06-10 12:46:40 -0400 | [diff] [blame] | 111 | "\nhalf4 inputColor = %s;\n%s = (inputColor * xCoverage) * yCoverage;\n", |
| 112 | _sample8899.c_str(), args.fOutputColor); |
Ethan Nicholas | 8239946 | 2017-10-16 12:35:44 -0400 | [diff] [blame] | 113 | } |
| 114 | |
| 115 | private: |
| 116 | void onSetData(const GrGLSLProgramDataManager& pdman, |
Mike Klein | d6ab77a | 2019-03-21 08:18:24 -0500 | [diff] [blame] | 117 | const GrFragmentProcessor& _proc) override { |
Ethan Nicholas | 8239946 | 2017-10-16 12:35:44 -0400 | [diff] [blame] | 118 | const GrRectBlurEffect& _outer = _proc.cast<GrRectBlurEffect>(); |
Brian Salomon | b2d5d40 | 2019-09-10 10:11:52 -0400 | [diff] [blame] | 119 | { pdman.set1f(invSixSigmaVar, (_outer.invSixSigma)); } |
Brian Salomon | 2c59659 | 2019-08-13 20:05:04 -0400 | [diff] [blame] | 120 | auto rect = _outer.rect; |
Ethan Nicholas | 8239946 | 2017-10-16 12:35:44 -0400 | [diff] [blame] | 121 | (void)rect; |
Brian Salomon | 2c59659 | 2019-08-13 20:05:04 -0400 | [diff] [blame] | 122 | UniformHandle& rectF = rectFVar; |
| 123 | (void)rectF; |
| 124 | UniformHandle& rectH = rectHVar; |
| 125 | (void)rectH; |
Robert Phillips | bd99c0c | 2019-12-12 13:26:58 +0000 | [diff] [blame] | 126 | const GrSurfaceProxyView& integralView = _outer.textureSampler(0).view(); |
| 127 | GrTexture& integral = *integralView.proxy()->peekTexture(); |
Brian Salomon | b2d5d40 | 2019-09-10 10:11:52 -0400 | [diff] [blame] | 128 | (void)integral; |
| 129 | UniformHandle& invSixSigma = invSixSigmaVar; |
| 130 | (void)invSixSigma; |
| 131 | auto isFast = _outer.isFast; |
| 132 | (void)isFast; |
Ethan Nicholas | 8239946 | 2017-10-16 12:35:44 -0400 | [diff] [blame] | 133 | |
Brian Salomon | 2c59659 | 2019-08-13 20:05:04 -0400 | [diff] [blame] | 134 | float r[]{rect.fLeft, rect.fTop, rect.fRight, rect.fBottom}; |
| 135 | pdman.set4fv(highp ? rectF : rectH, 1, r); |
Ethan Nicholas | 8239946 | 2017-10-16 12:35:44 -0400 | [diff] [blame] | 136 | } |
Brian Salomon | 2c59659 | 2019-08-13 20:05:04 -0400 | [diff] [blame] | 137 | bool highp = false; |
| 138 | UniformHandle rectFVar; |
| 139 | UniformHandle rectHVar; |
Brian Salomon | b2d5d40 | 2019-09-10 10:11:52 -0400 | [diff] [blame] | 140 | UniformHandle invSixSigmaVar; |
Ethan Nicholas | 8239946 | 2017-10-16 12:35:44 -0400 | [diff] [blame] | 141 | }; |
| 142 | GrGLSLFragmentProcessor* GrRectBlurEffect::onCreateGLSLInstance() const { |
| 143 | return new GrGLSLRectBlurEffect(); |
| 144 | } |
Mike Klein | d6ab77a | 2019-03-21 08:18:24 -0500 | [diff] [blame] | 145 | void GrRectBlurEffect::onGetGLSLProcessorKey(const GrShaderCaps& caps, |
Ethan Nicholas | cab767f | 2019-07-01 13:32:07 -0400 | [diff] [blame] | 146 | GrProcessorKeyBuilder* b) const { |
Brian Salomon | 2c59659 | 2019-08-13 20:05:04 -0400 | [diff] [blame] | 147 | bool highp = ((abs(rect.left()) > 16000.0 || abs(rect.top()) > 16000.0) || |
| 148 | abs(rect.right()) > 16000.0) || |
| 149 | abs(rect.bottom()) > 16000.0; |
| 150 | b->add32((int32_t)highp); |
Brian Salomon | b2d5d40 | 2019-09-10 10:11:52 -0400 | [diff] [blame] | 151 | b->add32((int32_t)isFast); |
Ethan Nicholas | cab767f | 2019-07-01 13:32:07 -0400 | [diff] [blame] | 152 | } |
Ethan Nicholas | 8239946 | 2017-10-16 12:35:44 -0400 | [diff] [blame] | 153 | bool GrRectBlurEffect::onIsEqual(const GrFragmentProcessor& other) const { |
| 154 | const GrRectBlurEffect& that = other.cast<GrRectBlurEffect>(); |
| 155 | (void)that; |
Ethan Nicholas | bcd51e8 | 2019-04-09 10:40:41 -0400 | [diff] [blame] | 156 | if (rect != that.rect) return false; |
Brian Salomon | b2d5d40 | 2019-09-10 10:11:52 -0400 | [diff] [blame] | 157 | if (integral != that.integral) return false; |
| 158 | if (invSixSigma != that.invSixSigma) return false; |
| 159 | if (isFast != that.isFast) return false; |
Ethan Nicholas | 8239946 | 2017-10-16 12:35:44 -0400 | [diff] [blame] | 160 | return true; |
| 161 | } |
| 162 | GrRectBlurEffect::GrRectBlurEffect(const GrRectBlurEffect& src) |
| 163 | : INHERITED(kGrRectBlurEffect_ClassID, src.optimizationFlags()) |
Ethan Nicholas | bcd51e8 | 2019-04-09 10:40:41 -0400 | [diff] [blame] | 164 | , rect(src.rect) |
Brian Salomon | b2d5d40 | 2019-09-10 10:11:52 -0400 | [diff] [blame] | 165 | , integral(src.integral) |
| 166 | , invSixSigma(src.invSixSigma) |
| 167 | , isFast(src.isFast) { |
John Stiles | 8818390 | 2020-06-10 16:40:38 -0400 | [diff] [blame^] | 168 | if (src.inputFP_index >= 0) { |
| 169 | auto inputFP_clone = src.childProcessor(src.inputFP_index).clone(); |
| 170 | if (src.childProcessor(src.inputFP_index).isSampledWithExplicitCoords()) { |
| 171 | inputFP_clone->setSampledWithExplicitCoords(); |
John Stiles | e7b4d73 | 2020-06-10 12:46:40 -0400 | [diff] [blame] | 172 | } |
John Stiles | 8818390 | 2020-06-10 16:40:38 -0400 | [diff] [blame^] | 173 | inputFP_index = this->registerChildProcessor(std::move(inputFP_clone)); |
John Stiles | e7b4d73 | 2020-06-10 12:46:40 -0400 | [diff] [blame] | 174 | } |
Brian Salomon | e736684 | 2019-09-04 11:20:45 -0400 | [diff] [blame] | 175 | this->setTextureSamplerCnt(1); |
| 176 | } |
Ethan Nicholas | 8239946 | 2017-10-16 12:35:44 -0400 | [diff] [blame] | 177 | std::unique_ptr<GrFragmentProcessor> GrRectBlurEffect::clone() const { |
| 178 | return std::unique_ptr<GrFragmentProcessor>(new GrRectBlurEffect(*this)); |
| 179 | } |
Brian Salomon | e736684 | 2019-09-04 11:20:45 -0400 | [diff] [blame] | 180 | const GrFragmentProcessor::TextureSampler& GrRectBlurEffect::onTextureSampler(int index) const { |
Brian Salomon | b2d5d40 | 2019-09-10 10:11:52 -0400 | [diff] [blame] | 181 | return IthTextureSampler(index, integral); |
Brian Salomon | e736684 | 2019-09-04 11:20:45 -0400 | [diff] [blame] | 182 | } |
Ethan Nicholas | 8239946 | 2017-10-16 12:35:44 -0400 | [diff] [blame] | 183 | GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrRectBlurEffect); |
| 184 | #if GR_TEST_UTILS |
| 185 | std::unique_ptr<GrFragmentProcessor> GrRectBlurEffect::TestCreate(GrProcessorTestData* data) { |
Mike Klein | d6ab77a | 2019-03-21 08:18:24 -0500 | [diff] [blame] | 186 | float sigma = data->fRandom->nextRangeF(3, 8); |
| 187 | float width = data->fRandom->nextRangeF(200, 300); |
Ethan Nicholas | 8239946 | 2017-10-16 12:35:44 -0400 | [diff] [blame] | 188 | float height = data->fRandom->nextRangeF(200, 300); |
John Stiles | e7b4d73 | 2020-06-10 12:46:40 -0400 | [diff] [blame] | 189 | return GrRectBlurEffect::Make(/*inputFP=*/nullptr, data->context(), *data->caps()->shaderCaps(), |
Mike Klein | d6ab77a | 2019-03-21 08:18:24 -0500 | [diff] [blame] | 190 | SkRect::MakeWH(width, height), sigma); |
Ethan Nicholas | 8239946 | 2017-10-16 12:35:44 -0400 | [diff] [blame] | 191 | } |
| 192 | #endif |