blob: e4412e2e77c0ea2337cc883270f416cfec41d9d5 [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;
Brian Salomon2c596592019-08-13 20:05:04 -040030 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 Nicholas82399462017-10-16 12:35:44 -040036 }
Brian Salomon2c596592019-08-13 20:05:04 -040037 if (!highp) {
38 rectHVar = args.fUniformHandler->addUniform(kFragment_GrShaderFlag, kHalf4_GrSLType,
39 "rectH");
Ethan Nicholas82399462017-10-16 12:35:44 -040040 }
Brian Salomon2c596592019-08-13 20:05:04 -040041 sigmaVar =
42 args.fUniformHandler->addUniform(kFragment_GrShaderFlag, kHalf_GrSLType, "sigma");
Ethan Nicholas82399462017-10-16 12:35:44 -040043 fragBuilder->codeAppendf(
Brian Salomon5331e2a2019-08-19 17:18:10 -040044 "/* key */ bool highp = %s;\nhalf x;\n@if (highp) {\n x = "
45 "min(half(sk_FragCoord.x - %s.x), half(%s.z - sk_FragCoord.x));\n} else {\n x = "
46 "min(half(sk_FragCoord.x - float(%s.x)), half(float(%s.z) - "
47 "sk_FragCoord.x));\n}\nhalf y;\n@if (highp) {\n y = min(half(sk_FragCoord.y - "
48 "%s.y), half(%s.w - sk_FragCoord.y));\n} else {\n y = min(half(sk_FragCoord.y - "
49 "float(%s.y)), half(float(%s.w) - sk_FragCoord.y));\n}\nhalf r = 1.0 / (2.0 * "
50 "%s);\nx *= r;\ny *= r;\nx = clamp(x, -1.5, 1.5);\ny = clamp(y, -1.5, 1.5",
51 (highp ? "true" : "false"),
Brian Salomon2c596592019-08-13 20:05:04 -040052 rectFVar.isValid() ? args.fUniformHandler->getUniformCStr(rectFVar) : "float4(0)",
53 rectFVar.isValid() ? args.fUniformHandler->getUniformCStr(rectFVar) : "float4(0)",
54 rectHVar.isValid() ? args.fUniformHandler->getUniformCStr(rectHVar) : "half4(0)",
Brian Salomon5331e2a2019-08-19 17:18:10 -040055 rectHVar.isValid() ? args.fUniformHandler->getUniformCStr(rectHVar) : "half4(0)",
Brian Salomon2c596592019-08-13 20:05:04 -040056 rectFVar.isValid() ? args.fUniformHandler->getUniformCStr(rectFVar) : "float4(0)",
57 rectFVar.isValid() ? args.fUniformHandler->getUniformCStr(rectFVar) : "float4(0)",
Brian Salomon5331e2a2019-08-19 17:18:10 -040058 rectHVar.isValid() ? args.fUniformHandler->getUniformCStr(rectHVar) : "half4(0)",
59 rectHVar.isValid() ? args.fUniformHandler->getUniformCStr(rectHVar) : "half4(0)",
60 args.fUniformHandler->getUniformCStr(sigmaVar));
Ethan Nicholas82399462017-10-16 12:35:44 -040061 fragBuilder->codeAppendf(
Brian Salomon5331e2a2019-08-19 17:18:10 -040062 ");\nhalf x2 = x * x;\nhalf x3 = x2 * x;\nhalf x5 = x2 * x3;\n\n\n\n\nhalf "
63 "xCoverage = ((0.73482197523117065 * x + -0.31337600946426392 * x3) + "
64 "0.060916900634765625 * x5) + 0.5;\nhalf y2 = y * y;\nhalf y3 = y2 * y;\nhalf y5 = "
65 "y2 * y3;\nhalf yCoverage = ((0.73482197523117065 * y + -0.31337600946426392 * y3) "
66 "+ 0.060916900634765625 * y5) + 0.5;\n%s = (%s * xCoverage) * yCoverage;\n",
67 args.fOutputColor, args.fInputColor);
Ethan Nicholas82399462017-10-16 12:35:44 -040068 }
69
70private:
71 void onSetData(const GrGLSLProgramDataManager& pdman,
Mike Kleind6ab77a2019-03-21 08:18:24 -050072 const GrFragmentProcessor& _proc) override {
Ethan Nicholas82399462017-10-16 12:35:44 -040073 const GrRectBlurEffect& _outer = _proc.cast<GrRectBlurEffect>();
Brian Salomon2c596592019-08-13 20:05:04 -040074 { pdman.set1f(sigmaVar, (_outer.sigma)); }
75 auto rect = _outer.rect;
Ethan Nicholas82399462017-10-16 12:35:44 -040076 (void)rect;
Brian Salomon2c596592019-08-13 20:05:04 -040077 UniformHandle& rectF = rectFVar;
78 (void)rectF;
79 UniformHandle& rectH = rectHVar;
80 (void)rectH;
81 UniformHandle& sigma = sigmaVar;
Ethan Nicholas82399462017-10-16 12:35:44 -040082 (void)sigma;
Ethan Nicholas82399462017-10-16 12:35:44 -040083
Brian Salomon2c596592019-08-13 20:05:04 -040084 float r[]{rect.fLeft, rect.fTop, rect.fRight, rect.fBottom};
85 pdman.set4fv(highp ? rectF : rectH, 1, r);
Ethan Nicholas82399462017-10-16 12:35:44 -040086 }
Brian Salomon2c596592019-08-13 20:05:04 -040087 bool highp = false;
88 UniformHandle rectFVar;
89 UniformHandle rectHVar;
90 UniformHandle sigmaVar;
Ethan Nicholas82399462017-10-16 12:35:44 -040091};
92GrGLSLFragmentProcessor* GrRectBlurEffect::onCreateGLSLInstance() const {
93 return new GrGLSLRectBlurEffect();
94}
Mike Kleind6ab77a2019-03-21 08:18:24 -050095void GrRectBlurEffect::onGetGLSLProcessorKey(const GrShaderCaps& caps,
Ethan Nicholascab767f2019-07-01 13:32:07 -040096 GrProcessorKeyBuilder* b) const {
Brian Salomon2c596592019-08-13 20:05:04 -040097 bool highp = ((abs(rect.left()) > 16000.0 || abs(rect.top()) > 16000.0) ||
98 abs(rect.right()) > 16000.0) ||
99 abs(rect.bottom()) > 16000.0;
100 b->add32((int32_t)highp);
Ethan Nicholascab767f2019-07-01 13:32:07 -0400101}
Ethan Nicholas82399462017-10-16 12:35:44 -0400102bool GrRectBlurEffect::onIsEqual(const GrFragmentProcessor& other) const {
103 const GrRectBlurEffect& that = other.cast<GrRectBlurEffect>();
104 (void)that;
Ethan Nicholasbcd51e82019-04-09 10:40:41 -0400105 if (rect != that.rect) return false;
106 if (sigma != that.sigma) return false;
Ethan Nicholas82399462017-10-16 12:35:44 -0400107 return true;
108}
109GrRectBlurEffect::GrRectBlurEffect(const GrRectBlurEffect& src)
110 : INHERITED(kGrRectBlurEffect_ClassID, src.optimizationFlags())
Ethan Nicholasbcd51e82019-04-09 10:40:41 -0400111 , rect(src.rect)
Brian Salomon2c596592019-08-13 20:05:04 -0400112 , sigma(src.sigma) {}
Ethan Nicholas82399462017-10-16 12:35:44 -0400113std::unique_ptr<GrFragmentProcessor> GrRectBlurEffect::clone() const {
114 return std::unique_ptr<GrFragmentProcessor>(new GrRectBlurEffect(*this));
115}
116GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrRectBlurEffect);
117#if GR_TEST_UTILS
118std::unique_ptr<GrFragmentProcessor> GrRectBlurEffect::TestCreate(GrProcessorTestData* data) {
Mike Kleind6ab77a2019-03-21 08:18:24 -0500119 float sigma = data->fRandom->nextRangeF(3, 8);
120 float width = data->fRandom->nextRangeF(200, 300);
Ethan Nicholas82399462017-10-16 12:35:44 -0400121 float height = data->fRandom->nextRangeF(200, 300);
Mike Kleind6ab77a2019-03-21 08:18:24 -0500122 return GrRectBlurEffect::Make(data->proxyProvider(), *data->caps()->shaderCaps(),
123 SkRect::MakeWH(width, height), sigma);
Ethan Nicholas82399462017-10-16 12:35:44 -0400124}
125#endif