| 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 GrRectBlurEffect.fp; do not modify. |
| 10 | **************************************************************************************************/ |
| 11 | #include "GrRectBlurEffect.h" |
| 12 | |
| 13 | #include "src/core/SkUtils.h" |
| 14 | #include "src/gpu/GrTexture.h" |
| 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" |
| 20 | class GrGLSLRectBlurEffect : public GrGLSLFragmentProcessor { |
| 21 | public: |
| 22 | GrGLSLRectBlurEffect() {} |
| 23 | void emitCode(EmitArgs& args) override { |
| 24 | GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder; |
| 25 | const GrRectBlurEffect& _outer = args.fFp.cast<GrRectBlurEffect>(); |
| 26 | (void)_outer; |
| 27 | auto rect = _outer.rect; |
| 28 | (void)rect; |
| 29 | auto isFast = _outer.isFast; |
| 30 | (void)isFast; |
| 31 | highp = ((abs(rect.left()) > 16000.0 || abs(rect.top()) > 16000.0) || |
| 32 | abs(rect.right()) > 16000.0) || |
| 33 | abs(rect.bottom()) > 16000.0; |
| 34 | if (highp) { |
| 35 | rectFVar = args.fUniformHandler->addUniform(&_outer, kFragment_GrShaderFlag, |
| 36 | kFloat4_GrSLType, "rectF" ); |
| 37 | } |
| 38 | if (!highp) { |
| 39 | rectHVar = args.fUniformHandler->addUniform(&_outer, kFragment_GrShaderFlag, |
| 40 | kHalf4_GrSLType, "rectH" ); |
| 41 | } |
| 42 | fragBuilder->codeAppendf( |
| 43 | R"SkSL(/* key */ bool highp = %s; |
| 44 | half xCoverage, yCoverage; |
| 45 | @if (%s) { |
| 46 | half2 xy; |
| 47 | @if (highp) { |
| 48 | xy = max(half2(%s.xy - sk_FragCoord.xy), half2(sk_FragCoord.xy - %s.zw)); |
| 49 | } else { |
| 50 | xy = max(half2(float2(%s.xy) - sk_FragCoord.xy), half2(sk_FragCoord.xy - float2(%s.zw))); |
| 51 | })SkSL" , |
| 52 | (highp ? "true" : "false" ), (_outer.isFast ? "true" : "false" ), |
| 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)" , |
| 56 | rectHVar.isValid() ? args.fUniformHandler->getUniformCStr(rectHVar) : "half4(0)" ); |
| 57 | SkString _coords7176("float2(half2(xy.x, 0.5))" ); |
| 58 | SkString _sample7176 = this->invokeChild(1, args, _coords7176.c_str()); |
| 59 | fragBuilder->codeAppendf( |
| 60 | R"SkSL( |
| 61 | xCoverage = %s.w;)SkSL" , |
| 62 | _sample7176.c_str()); |
| 63 | SkString _coords7234("float2(half2(xy.y, 0.5))" ); |
| 64 | SkString _sample7234 = this->invokeChild(1, args, _coords7234.c_str()); |
| 65 | fragBuilder->codeAppendf( |
| 66 | R"SkSL( |
| 67 | yCoverage = %s.w; |
| 68 | } else { |
| 69 | half4 rect; |
| 70 | @if (highp) { |
| 71 | rect.xy = half2(%s.xy - sk_FragCoord.xy); |
| 72 | rect.zw = half2(sk_FragCoord.xy - %s.zw); |
| 73 | } else { |
| 74 | rect.xy = half2(float2(%s.xy) - sk_FragCoord.xy); |
| 75 | rect.zw = half2(sk_FragCoord.xy - float2(%s.zw)); |
| 76 | })SkSL" , |
| 77 | _sample7234.c_str(), |
| 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 | SkString _coords8601("float2(half2(rect.x, 0.5))" ); |
| 83 | SkString _sample8601 = this->invokeChild(1, args, _coords8601.c_str()); |
| 84 | SkString _coords8664("float2(half2(rect.z, 0.5))" ); |
| 85 | SkString _sample8664 = this->invokeChild(1, args, _coords8664.c_str()); |
| 86 | fragBuilder->codeAppendf( |
| 87 | R"SkSL( |
| 88 | xCoverage = (1.0 - %s.w) - %s.w;)SkSL" , |
| 89 | _sample8601.c_str(), _sample8664.c_str()); |
| 90 | SkString _coords8728("float2(half2(rect.y, 0.5))" ); |
| 91 | SkString _sample8728 = this->invokeChild(1, args, _coords8728.c_str()); |
| 92 | SkString _coords8791("float2(half2(rect.w, 0.5))" ); |
| 93 | SkString _sample8791 = this->invokeChild(1, args, _coords8791.c_str()); |
| 94 | fragBuilder->codeAppendf( |
| 95 | R"SkSL( |
| 96 | yCoverage = (1.0 - %s.w) - %s.w; |
| 97 | })SkSL" , |
| 98 | _sample8728.c_str(), _sample8791.c_str()); |
| 99 | SkString _sample8860 = this->invokeChild(0, args); |
| 100 | fragBuilder->codeAppendf( |
| 101 | R"SkSL( |
| 102 | half4 inputColor = %s; |
| 103 | %s = (inputColor * xCoverage) * yCoverage; |
| 104 | )SkSL" , |
| 105 | _sample8860.c_str(), args.fOutputColor); |
| 106 | } |
| 107 | |
| 108 | private: |
| 109 | void onSetData(const GrGLSLProgramDataManager& pdman, |
| 110 | const GrFragmentProcessor& _proc) override { |
| 111 | const GrRectBlurEffect& _outer = _proc.cast<GrRectBlurEffect>(); |
| 112 | auto rect = _outer.rect; |
| 113 | (void)rect; |
| 114 | UniformHandle& rectF = rectFVar; |
| 115 | (void)rectF; |
| 116 | UniformHandle& rectH = rectHVar; |
| 117 | (void)rectH; |
| 118 | auto isFast = _outer.isFast; |
| 119 | (void)isFast; |
| 120 | |
| 121 | float r[]{rect.fLeft, rect.fTop, rect.fRight, rect.fBottom}; |
| 122 | pdman.set4fv(highp ? rectF : rectH, 1, r); |
| 123 | } |
| 124 | bool highp = false; |
| 125 | UniformHandle rectFVar; |
| 126 | UniformHandle rectHVar; |
| 127 | }; |
| 128 | GrGLSLFragmentProcessor* GrRectBlurEffect::onCreateGLSLInstance() const { |
| 129 | return new GrGLSLRectBlurEffect(); |
| 130 | } |
| 131 | void GrRectBlurEffect::onGetGLSLProcessorKey(const GrShaderCaps& caps, |
| 132 | GrProcessorKeyBuilder* b) const { |
| 133 | bool highp = ((abs(rect.left()) > 16000.0 || abs(rect.top()) > 16000.0) || |
| 134 | abs(rect.right()) > 16000.0) || |
| 135 | abs(rect.bottom()) > 16000.0; |
| 136 | b->add32((uint32_t)highp); |
| 137 | b->add32((uint32_t)isFast); |
| 138 | } |
| 139 | bool GrRectBlurEffect::onIsEqual(const GrFragmentProcessor& other) const { |
| 140 | const GrRectBlurEffect& that = other.cast<GrRectBlurEffect>(); |
| 141 | (void)that; |
| 142 | if (rect != that.rect) return false; |
| 143 | if (isFast != that.isFast) return false; |
| 144 | return true; |
| 145 | } |
| 146 | GrRectBlurEffect::GrRectBlurEffect(const GrRectBlurEffect& src) |
| 147 | : INHERITED(kGrRectBlurEffect_ClassID, src.optimizationFlags()) |
| 148 | , rect(src.rect) |
| 149 | , isFast(src.isFast) { |
| 150 | this->cloneAndRegisterAllChildProcessors(src); |
| 151 | } |
| 152 | std::unique_ptr<GrFragmentProcessor> GrRectBlurEffect::clone() const { |
| 153 | return std::make_unique<GrRectBlurEffect>(*this); |
| 154 | } |
| 155 | #if GR_TEST_UTILS |
| 156 | SkString GrRectBlurEffect::onDumpInfo() const { |
| 157 | return SkStringPrintf("(rect=float4(%f, %f, %f, %f), isFast=%s)" , rect.left(), rect.top(), |
| 158 | rect.right(), rect.bottom(), (isFast ? "true" : "false" )); |
| 159 | } |
| 160 | #endif |
| 161 | GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrRectBlurEffect); |
| 162 | #if GR_TEST_UTILS |
| 163 | std::unique_ptr<GrFragmentProcessor> GrRectBlurEffect::TestCreate(GrProcessorTestData* data) { |
| 164 | float sigma = data->fRandom->nextRangeF(3, 8); |
| 165 | float width = data->fRandom->nextRangeF(200, 300); |
| 166 | float height = data->fRandom->nextRangeF(200, 300); |
| 167 | return GrRectBlurEffect::Make(data->inputFP(), data->context(), *data->caps()->shaderCaps(), |
| 168 | SkRect::MakeWH(width, height), sigma); |
| 169 | } |
| 170 | #endif |
| 171 | |