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 | |
| 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" |
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 | e736684 | 2019-09-04 11:20:45 -0400 | [diff] [blame^] | 28 | auto invProfileWidth = _outer.invProfileWidth; |
| 29 | (void)invProfileWidth; |
Brian Salomon | 2c59659 | 2019-08-13 20:05:04 -0400 | [diff] [blame] | 30 | highp = ((abs(rect.left()) > 16000.0 || abs(rect.top()) > 16000.0) || |
| 31 | abs(rect.right()) > 16000.0) || |
| 32 | abs(rect.bottom()) > 16000.0; |
| 33 | if (highp) { |
| 34 | rectFVar = args.fUniformHandler->addUniform(kFragment_GrShaderFlag, kFloat4_GrSLType, |
| 35 | "rectF"); |
Ethan Nicholas | 8239946 | 2017-10-16 12:35:44 -0400 | [diff] [blame] | 36 | } |
Brian Salomon | 2c59659 | 2019-08-13 20:05:04 -0400 | [diff] [blame] | 37 | if (!highp) { |
| 38 | rectHVar = args.fUniformHandler->addUniform(kFragment_GrShaderFlag, kHalf4_GrSLType, |
| 39 | "rectH"); |
Ethan Nicholas | 8239946 | 2017-10-16 12:35:44 -0400 | [diff] [blame] | 40 | } |
Brian Salomon | e736684 | 2019-09-04 11:20:45 -0400 | [diff] [blame^] | 41 | invProfileWidthVar = args.fUniformHandler->addUniform(kFragment_GrShaderFlag, |
| 42 | kHalf_GrSLType, "invProfileWidth"); |
Ethan Nicholas | 8239946 | 2017-10-16 12:35:44 -0400 | [diff] [blame] | 43 | fragBuilder->codeAppendf( |
Brian Salomon | e736684 | 2019-09-04 11:20:45 -0400 | [diff] [blame^] | 44 | "/* key */ bool highp = %s;\nhalf x;\n@if (highp) {\n x = max(half(%s.x - " |
| 45 | "sk_FragCoord.x), half(sk_FragCoord.x - %s.z));\n} else {\n x = " |
| 46 | "max(half(float(%s.x) - sk_FragCoord.x), half(sk_FragCoord.x - " |
| 47 | "float(%s.z)));\n}\nhalf y;\n@if (highp) {\n y = max(half(%s.y - " |
| 48 | "sk_FragCoord.y), half(sk_FragCoord.y - %s.w));\n} else {\n y = " |
| 49 | "max(half(float(%s.y) - sk_FragCoord.y), half(sk_FragCoord.y - " |
| 50 | "float(%s.w)));\n}\nhalf xCoverage = sample(%s, float2(half2(x * %s, " |
| 51 | "0.5))).%s.w;\nhalf yCoverage = sample(%s, flo", |
Brian Salomon | 5331e2a | 2019-08-19 17:18:10 -0400 | [diff] [blame] | 52 | (highp ? "true" : "false"), |
Brian Salomon | 2c59659 | 2019-08-13 20:05:04 -0400 | [diff] [blame] | 53 | rectFVar.isValid() ? args.fUniformHandler->getUniformCStr(rectFVar) : "float4(0)", |
| 54 | rectFVar.isValid() ? args.fUniformHandler->getUniformCStr(rectFVar) : "float4(0)", |
| 55 | rectHVar.isValid() ? args.fUniformHandler->getUniformCStr(rectHVar) : "half4(0)", |
Brian Salomon | 5331e2a | 2019-08-19 17:18:10 -0400 | [diff] [blame] | 56 | rectHVar.isValid() ? args.fUniformHandler->getUniformCStr(rectHVar) : "half4(0)", |
Brian Salomon | 2c59659 | 2019-08-13 20:05:04 -0400 | [diff] [blame] | 57 | rectFVar.isValid() ? args.fUniformHandler->getUniformCStr(rectFVar) : "float4(0)", |
| 58 | rectFVar.isValid() ? args.fUniformHandler->getUniformCStr(rectFVar) : "float4(0)", |
Brian Salomon | 5331e2a | 2019-08-19 17:18:10 -0400 | [diff] [blame] | 59 | rectHVar.isValid() ? args.fUniformHandler->getUniformCStr(rectHVar) : "half4(0)", |
| 60 | rectHVar.isValid() ? args.fUniformHandler->getUniformCStr(rectHVar) : "half4(0)", |
Brian Salomon | e736684 | 2019-09-04 11:20:45 -0400 | [diff] [blame^] | 61 | fragBuilder->getProgramBuilder()->samplerVariable(args.fTexSamplers[0]), |
| 62 | args.fUniformHandler->getUniformCStr(invProfileWidthVar), |
| 63 | fragBuilder->getProgramBuilder()->samplerSwizzle(args.fTexSamplers[0]).c_str(), |
| 64 | fragBuilder->getProgramBuilder()->samplerVariable(args.fTexSamplers[0])); |
Ethan Nicholas | 8239946 | 2017-10-16 12:35:44 -0400 | [diff] [blame] | 65 | fragBuilder->codeAppendf( |
Brian Salomon | e736684 | 2019-09-04 11:20:45 -0400 | [diff] [blame^] | 66 | "at2(half2(y * %s, 0.5))).%s.w;\n%s = (%s * xCoverage) * yCoverage;\n", |
| 67 | args.fUniformHandler->getUniformCStr(invProfileWidthVar), |
| 68 | fragBuilder->getProgramBuilder()->samplerSwizzle(args.fTexSamplers[0]).c_str(), |
Brian Salomon | 5331e2a | 2019-08-19 17:18:10 -0400 | [diff] [blame] | 69 | args.fOutputColor, args.fInputColor); |
Ethan Nicholas | 8239946 | 2017-10-16 12:35:44 -0400 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | private: |
| 73 | void onSetData(const GrGLSLProgramDataManager& pdman, |
Mike Klein | d6ab77a | 2019-03-21 08:18:24 -0500 | [diff] [blame] | 74 | const GrFragmentProcessor& _proc) override { |
Ethan Nicholas | 8239946 | 2017-10-16 12:35:44 -0400 | [diff] [blame] | 75 | const GrRectBlurEffect& _outer = _proc.cast<GrRectBlurEffect>(); |
Brian Salomon | e736684 | 2019-09-04 11:20:45 -0400 | [diff] [blame^] | 76 | { pdman.set1f(invProfileWidthVar, (_outer.invProfileWidth)); } |
Brian Salomon | 2c59659 | 2019-08-13 20:05:04 -0400 | [diff] [blame] | 77 | auto rect = _outer.rect; |
Ethan Nicholas | 8239946 | 2017-10-16 12:35:44 -0400 | [diff] [blame] | 78 | (void)rect; |
Brian Salomon | 2c59659 | 2019-08-13 20:05:04 -0400 | [diff] [blame] | 79 | UniformHandle& rectF = rectFVar; |
| 80 | (void)rectF; |
| 81 | UniformHandle& rectH = rectHVar; |
| 82 | (void)rectH; |
Brian Salomon | e736684 | 2019-09-04 11:20:45 -0400 | [diff] [blame^] | 83 | GrSurfaceProxy& blurProfileProxy = *_outer.textureSampler(0).proxy(); |
| 84 | GrTexture& blurProfile = *blurProfileProxy.peekTexture(); |
| 85 | (void)blurProfile; |
| 86 | UniformHandle& invProfileWidth = invProfileWidthVar; |
| 87 | (void)invProfileWidth; |
Ethan Nicholas | 8239946 | 2017-10-16 12:35:44 -0400 | [diff] [blame] | 88 | |
Brian Salomon | 2c59659 | 2019-08-13 20:05:04 -0400 | [diff] [blame] | 89 | float r[]{rect.fLeft, rect.fTop, rect.fRight, rect.fBottom}; |
| 90 | pdman.set4fv(highp ? rectF : rectH, 1, r); |
Ethan Nicholas | 8239946 | 2017-10-16 12:35:44 -0400 | [diff] [blame] | 91 | } |
Brian Salomon | 2c59659 | 2019-08-13 20:05:04 -0400 | [diff] [blame] | 92 | bool highp = false; |
| 93 | UniformHandle rectFVar; |
| 94 | UniformHandle rectHVar; |
Brian Salomon | e736684 | 2019-09-04 11:20:45 -0400 | [diff] [blame^] | 95 | UniformHandle invProfileWidthVar; |
Ethan Nicholas | 8239946 | 2017-10-16 12:35:44 -0400 | [diff] [blame] | 96 | }; |
| 97 | GrGLSLFragmentProcessor* GrRectBlurEffect::onCreateGLSLInstance() const { |
| 98 | return new GrGLSLRectBlurEffect(); |
| 99 | } |
Mike Klein | d6ab77a | 2019-03-21 08:18:24 -0500 | [diff] [blame] | 100 | void GrRectBlurEffect::onGetGLSLProcessorKey(const GrShaderCaps& caps, |
Ethan Nicholas | cab767f | 2019-07-01 13:32:07 -0400 | [diff] [blame] | 101 | GrProcessorKeyBuilder* b) const { |
Brian Salomon | 2c59659 | 2019-08-13 20:05:04 -0400 | [diff] [blame] | 102 | bool highp = ((abs(rect.left()) > 16000.0 || abs(rect.top()) > 16000.0) || |
| 103 | abs(rect.right()) > 16000.0) || |
| 104 | abs(rect.bottom()) > 16000.0; |
| 105 | b->add32((int32_t)highp); |
Ethan Nicholas | cab767f | 2019-07-01 13:32:07 -0400 | [diff] [blame] | 106 | } |
Ethan Nicholas | 8239946 | 2017-10-16 12:35:44 -0400 | [diff] [blame] | 107 | bool GrRectBlurEffect::onIsEqual(const GrFragmentProcessor& other) const { |
| 108 | const GrRectBlurEffect& that = other.cast<GrRectBlurEffect>(); |
| 109 | (void)that; |
Ethan Nicholas | bcd51e8 | 2019-04-09 10:40:41 -0400 | [diff] [blame] | 110 | if (rect != that.rect) return false; |
Brian Salomon | e736684 | 2019-09-04 11:20:45 -0400 | [diff] [blame^] | 111 | if (blurProfile != that.blurProfile) return false; |
| 112 | if (invProfileWidth != that.invProfileWidth) return false; |
Ethan Nicholas | 8239946 | 2017-10-16 12:35:44 -0400 | [diff] [blame] | 113 | return true; |
| 114 | } |
| 115 | GrRectBlurEffect::GrRectBlurEffect(const GrRectBlurEffect& src) |
| 116 | : INHERITED(kGrRectBlurEffect_ClassID, src.optimizationFlags()) |
Ethan Nicholas | bcd51e8 | 2019-04-09 10:40:41 -0400 | [diff] [blame] | 117 | , rect(src.rect) |
Brian Salomon | e736684 | 2019-09-04 11:20:45 -0400 | [diff] [blame^] | 118 | , blurProfile(src.blurProfile) |
| 119 | , invProfileWidth(src.invProfileWidth) { |
| 120 | this->setTextureSamplerCnt(1); |
| 121 | } |
Ethan Nicholas | 8239946 | 2017-10-16 12:35:44 -0400 | [diff] [blame] | 122 | std::unique_ptr<GrFragmentProcessor> GrRectBlurEffect::clone() const { |
| 123 | return std::unique_ptr<GrFragmentProcessor>(new GrRectBlurEffect(*this)); |
| 124 | } |
Brian Salomon | e736684 | 2019-09-04 11:20:45 -0400 | [diff] [blame^] | 125 | const GrFragmentProcessor::TextureSampler& GrRectBlurEffect::onTextureSampler(int index) const { |
| 126 | return IthTextureSampler(index, blurProfile); |
| 127 | } |
Ethan Nicholas | 8239946 | 2017-10-16 12:35:44 -0400 | [diff] [blame] | 128 | GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrRectBlurEffect); |
| 129 | #if GR_TEST_UTILS |
| 130 | std::unique_ptr<GrFragmentProcessor> GrRectBlurEffect::TestCreate(GrProcessorTestData* data) { |
Mike Klein | d6ab77a | 2019-03-21 08:18:24 -0500 | [diff] [blame] | 131 | float sigma = data->fRandom->nextRangeF(3, 8); |
| 132 | float width = data->fRandom->nextRangeF(200, 300); |
Ethan Nicholas | 8239946 | 2017-10-16 12:35:44 -0400 | [diff] [blame] | 133 | float height = data->fRandom->nextRangeF(200, 300); |
Mike Klein | d6ab77a | 2019-03-21 08:18:24 -0500 | [diff] [blame] | 134 | return GrRectBlurEffect::Make(data->proxyProvider(), *data->caps()->shaderCaps(), |
| 135 | SkRect::MakeWH(width, height), sigma); |
Ethan Nicholas | 8239946 | 2017-10-16 12:35:44 -0400 | [diff] [blame] | 136 | } |
| 137 | #endif |