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 #include "glsl/GrGLSLFragmentProcessor.h" 13 #include "glsl/GrGLSLFragmentShaderBuilder.h" 14 #include "glsl/GrGLSLProgramBuilder.h" 15 #include "GrTexture.h" 16 #include "SkSLCPP.h" 17 #include "SkSLUtil.h" 18 class GrGLSLRectBlurEffect : public GrGLSLFragmentProcessor { 19 public: 20 GrGLSLRectBlurEffect() {} 21 void emitCode(EmitArgs& args) override { 22 GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder; 23 const GrRectBlurEffect& _outer = args.fFp.cast<GrRectBlurEffect>(); 24 (void)_outer; 25 auto rect = _outer.rect(); 26 (void)rect; 27 auto sigma = _outer.sigma(); 28 (void)sigma; 29 highPrecision = ((((abs(rect.left()) > 16000.0 || abs(rect.top()) > 16000.0) || 30 abs(rect.right()) > 16000.0) || 31 abs(rect.bottom()) > 16000.0) || 32 abs(rect.right() - rect.left()) > 16000.0) || 33 abs(rect.bottom() - rect.top()) > 16000.0; 34 fRectVar = args.fUniformHandler->addUniform(kFragment_GrShaderFlag, kFloat4_GrSLType, 35 kDefault_GrSLPrecision, "rect"); 36 if (!highPrecision) { 37 fProxyRectHalfVar = 38 args.fUniformHandler->addUniform(kFragment_GrShaderFlag, kHalf4_GrSLType, 39 kDefault_GrSLPrecision, "proxyRectHalf"); 40 } 41 if (highPrecision) { 42 fProxyRectFloatVar = 43 args.fUniformHandler->addUniform(kFragment_GrShaderFlag, kFloat4_GrSLType, 44 kDefault_GrSLPrecision, "proxyRectFloat"); 45 } 46 fProfileSizeVar = args.fUniformHandler->addUniform(kFragment_GrShaderFlag, kHalf_GrSLType, 47 kDefault_GrSLPrecision, "profileSize"); 48 fragBuilder->codeAppendf( 49 "/* key */ bool highPrecision = %s;\n@if (highPrecision) {\n float2 " 50 "translatedPos = sk_FragCoord.xy - %s.xy;\n float width = %s.z - %s.x;\n " 51 "float height = %s.w - %s.y;\n float2 smallDims = float2(width - float(%s), " 52 "height - float(%s));\n float center = 2.0 * floor(float(float(%s / 2.0) + " 53 "0.25)) - 1.0;\n float2 wh = smallDims - float2(center, center);\n half " 54 "hcoord = half((abs(translatedPos.x - 0.5 * width) - 0.5 * wh.x) / float(%s));\n " 55 " half hlookup = texture(%s, float2(float(hcoord), ", 56 (highPrecision ? "true" : "false"), args.fUniformHandler->getUniformCStr(fRectVar), 57 args.fUniformHandler->getUniformCStr(fRectVar), 58 args.fUniformHandler->getUniformCStr(fRectVar), 59 args.fUniformHandler->getUniformCStr(fRectVar), 60 args.fUniformHandler->getUniformCStr(fRectVar), 61 args.fUniformHandler->getUniformCStr(fProfileSizeVar), 62 args.fUniformHandler->getUniformCStr(fProfileSizeVar), 63 args.fUniformHandler->getUniformCStr(fProfileSizeVar), 64 args.fUniformHandler->getUniformCStr(fProfileSizeVar), 65 fragBuilder->getProgramBuilder()->samplerVariable(args.fTexSamplers[0]).c_str()); 66 fragBuilder->codeAppendf( 67 "0.5)).%s.w;\n half vcoord = half((abs(translatedPos.y - 0.5 * height) - 0.5 * " 68 "wh.y) / float(%s));\n half vlookup = texture(%s, float2(float(vcoord), " 69 "0.5)).%s.w;\n %s = (%s * hlookup) * vlookup;\n} else {\n half2 " 70 "translatedPos = half2(sk_FragCoord.xy - %s.xy);\n half width = half(%s.z - " 71 "%s.x);\n half height = half(%s.w - %s.y);\n half2 smallDims = half2(width - " 72 "%s, height - %s);\n half center = half(2.0 * floor(float(float(%s / 2.0) + " 73 "0.25)) - 1.0);\n half2 wh = smallDims - half2(f", 74 fragBuilder->getProgramBuilder()->samplerSwizzle(args.fTexSamplers[0]).c_str(), 75 args.fUniformHandler->getUniformCStr(fProfileSizeVar), 76 fragBuilder->getProgramBuilder()->samplerVariable(args.fTexSamplers[0]).c_str(), 77 fragBuilder->getProgramBuilder()->samplerSwizzle(args.fTexSamplers[0]).c_str(), 78 args.fOutputColor, args.fInputColor, args.fUniformHandler->getUniformCStr(fRectVar), 79 args.fUniformHandler->getUniformCStr(fRectVar), 80 args.fUniformHandler->getUniformCStr(fRectVar), 81 args.fUniformHandler->getUniformCStr(fRectVar), 82 args.fUniformHandler->getUniformCStr(fRectVar), 83 args.fUniformHandler->getUniformCStr(fProfileSizeVar), 84 args.fUniformHandler->getUniformCStr(fProfileSizeVar), 85 args.fUniformHandler->getUniformCStr(fProfileSizeVar)); 86 fragBuilder->codeAppendf( 87 "loat2(float(center), float(center)));\n half hcoord = " 88 "half((abs(float(float(translatedPos.x) - 0.5 * float(width))) - 0.5 * " 89 "float(wh.x)) / float(%s));\n half hlookup = texture(%s, float2(float(hcoord), " 90 "0.5)).%s.w;\n half vcoord = half((abs(float(float(translatedPos.y) - 0.5 * " 91 "float(height))) - 0.5 * float(wh.y)) / float(%s));\n half vlookup = " 92 "texture(%s, float2(float(vcoord), 0.5)).%s.w;\n %s = (%s * hlookup) * " 93 "vlookup;\n}\n", 94 args.fUniformHandler->getUniformCStr(fProfileSizeVar), 95 fragBuilder->getProgramBuilder()->samplerVariable(args.fTexSamplers[0]).c_str(), 96 fragBuilder->getProgramBuilder()->samplerSwizzle(args.fTexSamplers[0]).c_str(), 97 args.fUniformHandler->getUniformCStr(fProfileSizeVar), 98 fragBuilder->getProgramBuilder()->samplerVariable(args.fTexSamplers[0]).c_str(), 99 fragBuilder->getProgramBuilder()->samplerSwizzle(args.fTexSamplers[0]).c_str(), 100 args.fOutputColor, args.fInputColor); 101 } 102 103 private: 104 void onSetData(const GrGLSLProgramDataManager& pdman, 105 const GrFragmentProcessor& _proc) override { 106 const GrRectBlurEffect& _outer = _proc.cast<GrRectBlurEffect>(); 107 { pdman.set4fv(fRectVar, 1, reinterpret_cast<const float*>(&(_outer.rect()))); } 108 UniformHandle& rect = fRectVar; 109 (void)rect; 110 auto sigma = _outer.sigma(); 111 (void)sigma; 112 GrSurfaceProxy& blurProfileProxy = *_outer.textureSampler(0).proxy(); 113 GrTexture& blurProfile = *blurProfileProxy.peekTexture(); 114 (void)blurProfile; 115 UniformHandle& proxyRectHalf = fProxyRectHalfVar; 116 (void)proxyRectHalf; 117 UniformHandle& proxyRectFloat = fProxyRectFloatVar; 118 (void)proxyRectFloat; 119 UniformHandle& profileSize = fProfileSizeVar; 120 (void)profileSize; 121 122 pdman.set1f(profileSize, SkScalarCeilToScalar(6 * sigma)); 123 } 124 bool highPrecision = false; 125 UniformHandle fProxyRectHalfVar; 126 UniformHandle fProxyRectFloatVar; 127 UniformHandle fProfileSizeVar; 128 UniformHandle fRectVar; 129 }; 130 GrGLSLFragmentProcessor* GrRectBlurEffect::onCreateGLSLInstance() const { 131 return new GrGLSLRectBlurEffect(); 132 } 133 void GrRectBlurEffect::onGetGLSLProcessorKey(const GrShaderCaps& caps, 134 GrProcessorKeyBuilder* b) const {} 135 bool GrRectBlurEffect::onIsEqual(const GrFragmentProcessor& other) const { 136 const GrRectBlurEffect& that = other.cast<GrRectBlurEffect>(); 137 (void)that; 138 if (fRect != that.fRect) return false; 139 if (fSigma != that.fSigma) return false; 140 if (fBlurProfile != that.fBlurProfile) return false; 141 return true; 142 } 143 GrRectBlurEffect::GrRectBlurEffect(const GrRectBlurEffect& src) 144 : INHERITED(kGrRectBlurEffect_ClassID, src.optimizationFlags()) 145 , fRect(src.fRect) 146 , fSigma(src.fSigma) 147 , fBlurProfile(src.fBlurProfile) { 148 this->setTextureSamplerCnt(1); 149 } 150 std::unique_ptr<GrFragmentProcessor> GrRectBlurEffect::clone() const { 151 return std::unique_ptr<GrFragmentProcessor>(new GrRectBlurEffect(*this)); 152 } 153 const GrFragmentProcessor::TextureSampler& GrRectBlurEffect::onTextureSampler(int index) const { 154 return IthTextureSampler(index, fBlurProfile); 155 } 156 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrRectBlurEffect); 157 #if GR_TEST_UTILS 158 std::unique_ptr<GrFragmentProcessor> GrRectBlurEffect::TestCreate(GrProcessorTestData* data) { 159 float sigma = data->fRandom->nextRangeF(3, 8); 160 float width = data->fRandom->nextRangeF(200, 300); 161 float height = data->fRandom->nextRangeF(200, 300); 162 return GrRectBlurEffect::Make(data->proxyProvider(), *data->caps()->shaderCaps(), 163 SkRect::MakeWH(width, height), sigma); 164 } 165 #endif 166