blob: ad27bfdd95ca65a9c3b374831bc6d9dd42dc5681 [file] [log] [blame]
Ethan Nicholas82399462017-10-16 12:35:44 -04001/*
Ethan Nicholas130fb3f2018-02-01 12:14:34 -05002 * Copyright 2018 Google Inc.
Ethan Nicholas82399462017-10-16 12:35:44 -04003 *
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 Nicholas130fb3f2018-02-01 12:14:34 -05008/**************************************************************************************************
9 *** This file was autogenerated from GrRectBlurEffect.fp; do not modify.
10 **************************************************************************************************/
Ethan Nicholas82399462017-10-16 12:35:44 -040011#include "GrRectBlurEffect.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050012
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 Nicholas82399462017-10-16 12:35:44 -040019class GrGLSLRectBlurEffect : public GrGLSLFragmentProcessor {
20public:
21 GrGLSLRectBlurEffect() {}
22 void emitCode(EmitArgs& args) override {
23 GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
Mike Kleind6ab77a2019-03-21 08:18:24 -050024 const GrRectBlurEffect& _outer = args.fFp.cast<GrRectBlurEffect>();
Ethan Nicholas82399462017-10-16 12:35:44 -040025 (void)_outer;
Ethan Nicholasbcd51e82019-04-09 10:40:41 -040026 auto rect = _outer.rect;
Ethan Nicholas82399462017-10-16 12:35:44 -040027 (void)rect;
Ethan Nicholasbcd51e82019-04-09 10:40:41 -040028 auto sigma = _outer.sigma;
Ethan Nicholas82399462017-10-16 12:35:44 -040029 (void)sigma;
30 highPrecision = ((((abs(rect.left()) > 16000.0 || abs(rect.top()) > 16000.0) ||
31 abs(rect.right()) > 16000.0) ||
32 abs(rect.bottom()) > 16000.0) ||
33 abs(rect.right() - rect.left()) > 16000.0) ||
34 abs(rect.bottom() - rect.top()) > 16000.0;
Ethan Nicholasbcd51e82019-04-09 10:40:41 -040035 rectVar =
Ethan Nicholas858fecc2019-03-07 13:19:18 -050036 args.fUniformHandler->addUniform(kFragment_GrShaderFlag, kFloat4_GrSLType, "rect");
Ethan Nicholas82399462017-10-16 12:35:44 -040037 if (!highPrecision) {
Ethan Nicholasbcd51e82019-04-09 10:40:41 -040038 proxyRectHalfVar = args.fUniformHandler->addUniform(kFragment_GrShaderFlag,
39 kHalf4_GrSLType, "proxyRectHalf");
Ethan Nicholas82399462017-10-16 12:35:44 -040040 }
41 if (highPrecision) {
Ethan Nicholasbcd51e82019-04-09 10:40:41 -040042 proxyRectFloatVar = args.fUniformHandler->addUniform(
Ethan Nicholas858fecc2019-03-07 13:19:18 -050043 kFragment_GrShaderFlag, kFloat4_GrSLType, "proxyRectFloat");
Ethan Nicholas82399462017-10-16 12:35:44 -040044 }
Ethan Nicholasbcd51e82019-04-09 10:40:41 -040045 profileSizeVar = args.fUniformHandler->addUniform(kFragment_GrShaderFlag, kHalf_GrSLType,
46 "profileSize");
Ethan Nicholas82399462017-10-16 12:35:44 -040047 fragBuilder->codeAppendf(
Ethan Nicholas00543112018-07-31 09:44:36 -040048 "/* key */ bool highPrecision = %s;\n@if (highPrecision) {\n float2 "
49 "translatedPos = sk_FragCoord.xy - %s.xy;\n float width = %s.z - %s.x;\n "
50 "float height = %s.w - %s.y;\n float2 smallDims = float2(width - float(%s), "
Ethan Nicholase1f55022019-02-05 17:17:40 -050051 "height - float(%s));\n float center = float(2.0 * floor(%s / 2.0 + 0.25) - "
52 "1.0);\n float2 wh = smallDims - float2(center, center);\n half hcoord = "
53 "half((abs(translatedPos.x - 0.5 * width) - 0.5 * wh.x) / float(%s));\n half "
54 "hlookup = texture(%s, float2(float(hcoord), 0.5)).",
Ethan Nicholasbcd51e82019-04-09 10:40:41 -040055 (highPrecision ? "true" : "false"), args.fUniformHandler->getUniformCStr(rectVar),
56 args.fUniformHandler->getUniformCStr(rectVar),
57 args.fUniformHandler->getUniformCStr(rectVar),
58 args.fUniformHandler->getUniformCStr(rectVar),
59 args.fUniformHandler->getUniformCStr(rectVar),
60 args.fUniformHandler->getUniformCStr(profileSizeVar),
61 args.fUniformHandler->getUniformCStr(profileSizeVar),
62 args.fUniformHandler->getUniformCStr(profileSizeVar),
63 args.fUniformHandler->getUniformCStr(profileSizeVar),
Ethan Nicholas00543112018-07-31 09:44:36 -040064 fragBuilder->getProgramBuilder()->samplerVariable(args.fTexSamplers[0]).c_str());
Ethan Nicholas82399462017-10-16 12:35:44 -040065 fragBuilder->codeAppendf(
Ethan Nicholase1f55022019-02-05 17:17:40 -050066 "%s.w;\n half vcoord = half((abs(translatedPos.y - 0.5 * height) - 0.5 * wh.y) "
67 "/ float(%s));\n half vlookup = texture(%s, float2(float(vcoord), 0.5)).%s.w;\n "
68 " %s = (%s * hlookup) * vlookup;\n} else {\n half2 translatedPos = "
69 "half2(sk_FragCoord.xy - %s.xy);\n half width = half(%s.z - %s.x);\n half "
70 "height = half(%s.w - %s.y);\n half2 smallDims = half2(width - %s, height - "
71 "%s);\n half center = 2.0 * floor(%s / 2.0 + 0.25) - 1.0;\n half2 wh = "
72 "smallDims - half2(center, center);\n half ",
Ethan Nicholas00543112018-07-31 09:44:36 -040073 fragBuilder->getProgramBuilder()->samplerSwizzle(args.fTexSamplers[0]).c_str(),
Ethan Nicholasbcd51e82019-04-09 10:40:41 -040074 args.fUniformHandler->getUniformCStr(profileSizeVar),
Ethan Nicholas82399462017-10-16 12:35:44 -040075 fragBuilder->getProgramBuilder()->samplerVariable(args.fTexSamplers[0]).c_str(),
76 fragBuilder->getProgramBuilder()->samplerSwizzle(args.fTexSamplers[0]).c_str(),
Ethan Nicholasbcd51e82019-04-09 10:40:41 -040077 args.fOutputColor, args.fInputColor, args.fUniformHandler->getUniformCStr(rectVar),
78 args.fUniformHandler->getUniformCStr(rectVar),
79 args.fUniformHandler->getUniformCStr(rectVar),
80 args.fUniformHandler->getUniformCStr(rectVar),
81 args.fUniformHandler->getUniformCStr(rectVar),
82 args.fUniformHandler->getUniformCStr(profileSizeVar),
83 args.fUniformHandler->getUniformCStr(profileSizeVar),
84 args.fUniformHandler->getUniformCStr(profileSizeVar));
Ethan Nicholas82399462017-10-16 12:35:44 -040085 fragBuilder->codeAppendf(
Ethan Nicholase1f55022019-02-05 17:17:40 -050086 "hcoord = (abs(translatedPos.x - 0.5 * width) - 0.5 * wh.x) / %s;\n half "
87 "hlookup = texture(%s, float2(float(hcoord), 0.5)).%s.w;\n half vcoord = "
88 "(abs(translatedPos.y - 0.5 * height) - 0.5 * wh.y) / %s;\n half vlookup = "
Ethan Nicholas82399462017-10-16 12:35:44 -040089 "texture(%s, float2(float(vcoord), 0.5)).%s.w;\n %s = (%s * hlookup) * "
90 "vlookup;\n}\n",
Ethan Nicholasbcd51e82019-04-09 10:40:41 -040091 args.fUniformHandler->getUniformCStr(profileSizeVar),
Ethan Nicholas82399462017-10-16 12:35:44 -040092 fragBuilder->getProgramBuilder()->samplerVariable(args.fTexSamplers[0]).c_str(),
93 fragBuilder->getProgramBuilder()->samplerSwizzle(args.fTexSamplers[0]).c_str(),
Ethan Nicholasbcd51e82019-04-09 10:40:41 -040094 args.fUniformHandler->getUniformCStr(profileSizeVar),
Ethan Nicholas82399462017-10-16 12:35:44 -040095 fragBuilder->getProgramBuilder()->samplerVariable(args.fTexSamplers[0]).c_str(),
96 fragBuilder->getProgramBuilder()->samplerSwizzle(args.fTexSamplers[0]).c_str(),
Mike Kleind6ab77a2019-03-21 08:18:24 -050097 args.fOutputColor, args.fInputColor);
Ethan Nicholas82399462017-10-16 12:35:44 -040098 }
99
100private:
101 void onSetData(const GrGLSLProgramDataManager& pdman,
Mike Kleind6ab77a2019-03-21 08:18:24 -0500102 const GrFragmentProcessor& _proc) override {
Ethan Nicholas82399462017-10-16 12:35:44 -0400103 const GrRectBlurEffect& _outer = _proc.cast<GrRectBlurEffect>();
Ethan Nicholasbcd51e82019-04-09 10:40:41 -0400104 { pdman.set4fv(rectVar, 1, reinterpret_cast<const float*>(&(_outer.rect))); }
105 UniformHandle& rect = rectVar;
Ethan Nicholas82399462017-10-16 12:35:44 -0400106 (void)rect;
Ethan Nicholasbcd51e82019-04-09 10:40:41 -0400107 auto sigma = _outer.sigma;
Ethan Nicholas82399462017-10-16 12:35:44 -0400108 (void)sigma;
Ethan Nicholas2d5f9b32017-12-13 14:36:14 -0500109 GrSurfaceProxy& blurProfileProxy = *_outer.textureSampler(0).proxy();
Mike Kleind6ab77a2019-03-21 08:18:24 -0500110 GrTexture& blurProfile = *blurProfileProxy.peekTexture();
Ethan Nicholas82399462017-10-16 12:35:44 -0400111 (void)blurProfile;
Ethan Nicholasbcd51e82019-04-09 10:40:41 -0400112 UniformHandle& proxyRectHalf = proxyRectHalfVar;
Ethan Nicholas82399462017-10-16 12:35:44 -0400113 (void)proxyRectHalf;
Ethan Nicholasbcd51e82019-04-09 10:40:41 -0400114 UniformHandle& proxyRectFloat = proxyRectFloatVar;
Ethan Nicholas82399462017-10-16 12:35:44 -0400115 (void)proxyRectFloat;
Ethan Nicholasbcd51e82019-04-09 10:40:41 -0400116 UniformHandle& profileSize = profileSizeVar;
Ethan Nicholas82399462017-10-16 12:35:44 -0400117 (void)profileSize;
118
119 pdman.set1f(profileSize, SkScalarCeilToScalar(6 * sigma));
120 }
Mike Kleind6ab77a2019-03-21 08:18:24 -0500121 bool highPrecision = false;
Ethan Nicholasbcd51e82019-04-09 10:40:41 -0400122 UniformHandle proxyRectHalfVar;
123 UniformHandle proxyRectFloatVar;
124 UniformHandle profileSizeVar;
125 UniformHandle rectVar;
Ethan Nicholas82399462017-10-16 12:35:44 -0400126};
127GrGLSLFragmentProcessor* GrRectBlurEffect::onCreateGLSLInstance() const {
128 return new GrGLSLRectBlurEffect();
129}
Mike Kleind6ab77a2019-03-21 08:18:24 -0500130void GrRectBlurEffect::onGetGLSLProcessorKey(const GrShaderCaps& caps,
Ethan Nicholas82399462017-10-16 12:35:44 -0400131 GrProcessorKeyBuilder* b) const {}
132bool GrRectBlurEffect::onIsEqual(const GrFragmentProcessor& other) const {
133 const GrRectBlurEffect& that = other.cast<GrRectBlurEffect>();
134 (void)that;
Ethan Nicholasbcd51e82019-04-09 10:40:41 -0400135 if (rect != that.rect) return false;
136 if (sigma != that.sigma) return false;
137 if (blurProfile != that.blurProfile) return false;
Ethan Nicholas82399462017-10-16 12:35:44 -0400138 return true;
139}
140GrRectBlurEffect::GrRectBlurEffect(const GrRectBlurEffect& src)
141 : INHERITED(kGrRectBlurEffect_ClassID, src.optimizationFlags())
Ethan Nicholasbcd51e82019-04-09 10:40:41 -0400142 , rect(src.rect)
143 , sigma(src.sigma)
144 , blurProfile(src.blurProfile) {
Brian Salomonf7dcd762018-07-30 14:48:15 -0400145 this->setTextureSamplerCnt(1);
Ethan Nicholas82399462017-10-16 12:35:44 -0400146}
147std::unique_ptr<GrFragmentProcessor> GrRectBlurEffect::clone() const {
148 return std::unique_ptr<GrFragmentProcessor>(new GrRectBlurEffect(*this));
149}
Brian Salomonf7dcd762018-07-30 14:48:15 -0400150const GrFragmentProcessor::TextureSampler& GrRectBlurEffect::onTextureSampler(int index) const {
Ethan Nicholasbcd51e82019-04-09 10:40:41 -0400151 return IthTextureSampler(index, blurProfile);
Brian Salomonf7dcd762018-07-30 14:48:15 -0400152}
Ethan Nicholas82399462017-10-16 12:35:44 -0400153GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrRectBlurEffect);
154#if GR_TEST_UTILS
155std::unique_ptr<GrFragmentProcessor> GrRectBlurEffect::TestCreate(GrProcessorTestData* data) {
Mike Kleind6ab77a2019-03-21 08:18:24 -0500156 float sigma = data->fRandom->nextRangeF(3, 8);
157 float width = data->fRandom->nextRangeF(200, 300);
Ethan Nicholas82399462017-10-16 12:35:44 -0400158 float height = data->fRandom->nextRangeF(200, 300);
Mike Kleind6ab77a2019-03-21 08:18:24 -0500159 return GrRectBlurEffect::Make(data->proxyProvider(), *data->caps()->shaderCaps(),
160 SkRect::MakeWH(width, height), sigma);
Ethan Nicholas82399462017-10-16 12:35:44 -0400161}
162#endif