blob: a8f8f851b367225951abb296c6e99fce549f9db7 [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
Greg Daniel456f9b52020-03-05 19:14:18 +000013#include "src/gpu/GrTexture.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050014#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;
Brian Salomonb2d5d402019-09-10 10:11:52 -040028 auto isFast = _outer.isFast;
29 (void)isFast;
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) {
Ethan Nicholas16464c32020-04-06 13:53:05 -040034 rectFVar = args.fUniformHandler->addUniform(&_outer, kFragment_GrShaderFlag,
35 kFloat4_GrSLType, "rectF");
Ethan Nicholas82399462017-10-16 12:35:44 -040036 }
Brian Salomon2c596592019-08-13 20:05:04 -040037 if (!highp) {
Ethan Nicholas16464c32020-04-06 13:53:05 -040038 rectHVar = args.fUniformHandler->addUniform(&_outer, kFragment_GrShaderFlag,
39 kHalf4_GrSLType, "rectH");
Ethan Nicholas82399462017-10-16 12:35:44 -040040 }
Ethan Nicholas82399462017-10-16 12:35:44 -040041 fragBuilder->codeAppendf(
John Stiles50819422020-06-18 13:00:38 -040042 R"SkSL(/* key */ bool highp = %s;
43half xCoverage, yCoverage;
44@if (%s) {
45 half2 xy;
46 @if (highp) {
47 xy = max(half2(%s.xy - sk_FragCoord.xy), half2(sk_FragCoord.xy - %s.zw));
48 } else {
49 xy = max(half2(float2(%s.xy) - sk_FragCoord.xy), half2(sk_FragCoord.xy - float2(%s.zw)));
50 })SkSL",
Brian Salomonb2d5d402019-09-10 10:11:52 -040051 (highp ? "true" : "false"), (_outer.isFast ? "true" : "false"),
52 rectFVar.isValid() ? args.fUniformHandler->getUniformCStr(rectFVar) : "float4(0)",
53 rectFVar.isValid() ? args.fUniformHandler->getUniformCStr(rectFVar) : "float4(0)",
Brian Salomon2c596592019-08-13 20:05:04 -040054 rectHVar.isValid() ? args.fUniformHandler->getUniformCStr(rectHVar) : "half4(0)",
Brian Salomon86b2f392020-06-16 16:01:07 -040055 rectHVar.isValid() ? args.fUniformHandler->getUniformCStr(rectHVar) : "half4(0)");
Robert Phillipsd62c1542020-07-01 16:17:13 -040056 SkString _coords7211("float2(half2(xy.x, 0.5))");
Brian Osman12c5d292020-07-13 16:11:35 -040057 SkString _sample7211 = this->invokeChild(1, args, _coords7211.c_str());
John Stiles50819422020-06-18 13:00:38 -040058 fragBuilder->codeAppendf(
59 R"SkSL(
60 xCoverage = %s.w;)SkSL",
Robert Phillipsd62c1542020-07-01 16:17:13 -040061 _sample7211.c_str());
62 SkString _coords7269("float2(half2(xy.y, 0.5))");
Brian Osman12c5d292020-07-13 16:11:35 -040063 SkString _sample7269 = this->invokeChild(1, args, _coords7269.c_str());
Ethan Nicholas82399462017-10-16 12:35:44 -040064 fragBuilder->codeAppendf(
John Stiles50819422020-06-18 13:00:38 -040065 R"SkSL(
66 yCoverage = %s.w;
67} else {
68 half4 rect;
69 @if (highp) {
70 rect.xy = half2(%s.xy - sk_FragCoord.xy);
71 rect.zw = half2(sk_FragCoord.xy - %s.zw);
72 } else {
73 rect.xy = half2(float2(%s.xy) - sk_FragCoord.xy);
74 rect.zw = half2(sk_FragCoord.xy - float2(%s.zw));
75 })SkSL",
Robert Phillipsd62c1542020-07-01 16:17:13 -040076 _sample7269.c_str(),
John Stilese7b4d732020-06-10 12:46:40 -040077 rectFVar.isValid() ? args.fUniformHandler->getUniformCStr(rectFVar) : "float4(0)",
78 rectFVar.isValid() ? args.fUniformHandler->getUniformCStr(rectFVar) : "float4(0)",
79 rectHVar.isValid() ? args.fUniformHandler->getUniformCStr(rectHVar) : "half4(0)",
Brian Salomon86b2f392020-06-16 16:01:07 -040080 rectHVar.isValid() ? args.fUniformHandler->getUniformCStr(rectHVar) : "half4(0)");
Robert Phillipsd62c1542020-07-01 16:17:13 -040081 SkString _coords8636("float2(half2(rect.x, 0.5))");
Brian Osman12c5d292020-07-13 16:11:35 -040082 SkString _sample8636 = this->invokeChild(1, args, _coords8636.c_str());
Robert Phillipsd62c1542020-07-01 16:17:13 -040083 SkString _coords8699("float2(half2(rect.z, 0.5))");
Brian Osman12c5d292020-07-13 16:11:35 -040084 SkString _sample8699 = this->invokeChild(1, args, _coords8699.c_str());
John Stiles50819422020-06-18 13:00:38 -040085 fragBuilder->codeAppendf(
86 R"SkSL(
87 xCoverage = (1.0 - %s.w) - %s.w;)SkSL",
Robert Phillipsd62c1542020-07-01 16:17:13 -040088 _sample8636.c_str(), _sample8699.c_str());
89 SkString _coords8763("float2(half2(rect.y, 0.5))");
Brian Osman12c5d292020-07-13 16:11:35 -040090 SkString _sample8763 = this->invokeChild(1, args, _coords8763.c_str());
Robert Phillipsd62c1542020-07-01 16:17:13 -040091 SkString _coords8826("float2(half2(rect.w, 0.5))");
Brian Osman12c5d292020-07-13 16:11:35 -040092 SkString _sample8826 = this->invokeChild(1, args, _coords8826.c_str());
John Stiles50819422020-06-18 13:00:38 -040093 fragBuilder->codeAppendf(
94 R"SkSL(
95 yCoverage = (1.0 - %s.w) - %s.w;
96})SkSL",
Robert Phillipsd62c1542020-07-01 16:17:13 -040097 _sample8763.c_str(), _sample8826.c_str());
98 SkString _input8895(args.fInputColor);
Brian Osman12c5d292020-07-13 16:11:35 -040099 SkString _sample8895 = this->invokeChild(0, _input8895.c_str(), args);
Brian Salomonb2d5d402019-09-10 10:11:52 -0400100 fragBuilder->codeAppendf(
John Stiles50819422020-06-18 13:00:38 -0400101 R"SkSL(
102half4 inputColor = %s;
103%s = (inputColor * xCoverage) * yCoverage;
104)SkSL",
Robert Phillipsd62c1542020-07-01 16:17:13 -0400105 _sample8895.c_str(), args.fOutputColor);
Ethan Nicholas82399462017-10-16 12:35:44 -0400106 }
107
108private:
109 void onSetData(const GrGLSLProgramDataManager& pdman,
Mike Kleind6ab77a2019-03-21 08:18:24 -0500110 const GrFragmentProcessor& _proc) override {
Ethan Nicholas82399462017-10-16 12:35:44 -0400111 const GrRectBlurEffect& _outer = _proc.cast<GrRectBlurEffect>();
Brian Salomon2c596592019-08-13 20:05:04 -0400112 auto rect = _outer.rect;
Ethan Nicholas82399462017-10-16 12:35:44 -0400113 (void)rect;
Brian Salomon2c596592019-08-13 20:05:04 -0400114 UniformHandle& rectF = rectFVar;
115 (void)rectF;
116 UniformHandle& rectH = rectHVar;
117 (void)rectH;
Brian Salomonb2d5d402019-09-10 10:11:52 -0400118 auto isFast = _outer.isFast;
119 (void)isFast;
Ethan Nicholas82399462017-10-16 12:35:44 -0400120
Brian Salomon2c596592019-08-13 20:05:04 -0400121 float r[]{rect.fLeft, rect.fTop, rect.fRight, rect.fBottom};
122 pdman.set4fv(highp ? rectF : rectH, 1, r);
Ethan Nicholas82399462017-10-16 12:35:44 -0400123 }
Brian Salomon2c596592019-08-13 20:05:04 -0400124 bool highp = false;
125 UniformHandle rectFVar;
126 UniformHandle rectHVar;
Ethan Nicholas82399462017-10-16 12:35:44 -0400127};
128GrGLSLFragmentProcessor* GrRectBlurEffect::onCreateGLSLInstance() const {
129 return new GrGLSLRectBlurEffect();
130}
Mike Kleind6ab77a2019-03-21 08:18:24 -0500131void GrRectBlurEffect::onGetGLSLProcessorKey(const GrShaderCaps& caps,
Ethan Nicholascab767f2019-07-01 13:32:07 -0400132 GrProcessorKeyBuilder* b) const {
Brian Salomon2c596592019-08-13 20:05:04 -0400133 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((int32_t)highp);
Brian Salomonb2d5d402019-09-10 10:11:52 -0400137 b->add32((int32_t)isFast);
Ethan Nicholascab767f2019-07-01 13:32:07 -0400138}
Ethan Nicholas82399462017-10-16 12:35:44 -0400139bool GrRectBlurEffect::onIsEqual(const GrFragmentProcessor& other) const {
140 const GrRectBlurEffect& that = other.cast<GrRectBlurEffect>();
141 (void)that;
Ethan Nicholasbcd51e82019-04-09 10:40:41 -0400142 if (rect != that.rect) return false;
Brian Salomonb2d5d402019-09-10 10:11:52 -0400143 if (isFast != that.isFast) return false;
Ethan Nicholas82399462017-10-16 12:35:44 -0400144 return true;
145}
146GrRectBlurEffect::GrRectBlurEffect(const GrRectBlurEffect& src)
147 : INHERITED(kGrRectBlurEffect_ClassID, src.optimizationFlags())
Ethan Nicholasbcd51e82019-04-09 10:40:41 -0400148 , rect(src.rect)
Brian Salomonb2d5d402019-09-10 10:11:52 -0400149 , isFast(src.isFast) {
Brian Osman12c5d292020-07-13 16:11:35 -0400150 this->cloneAndRegisterAllChildProcessors(src);
Brian Salomone7366842019-09-04 11:20:45 -0400151}
Ethan Nicholas82399462017-10-16 12:35:44 -0400152std::unique_ptr<GrFragmentProcessor> GrRectBlurEffect::clone() const {
153 return std::unique_ptr<GrFragmentProcessor>(new GrRectBlurEffect(*this));
154}
155GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrRectBlurEffect);
156#if GR_TEST_UTILS
157std::unique_ptr<GrFragmentProcessor> GrRectBlurEffect::TestCreate(GrProcessorTestData* data) {
Mike Kleind6ab77a2019-03-21 08:18:24 -0500158 float sigma = data->fRandom->nextRangeF(3, 8);
159 float width = data->fRandom->nextRangeF(200, 300);
Ethan Nicholas82399462017-10-16 12:35:44 -0400160 float height = data->fRandom->nextRangeF(200, 300);
John Stilese7b4d732020-06-10 12:46:40 -0400161 return GrRectBlurEffect::Make(/*inputFP=*/nullptr, data->context(), *data->caps()->shaderCaps(),
Mike Kleind6ab77a2019-03-21 08:18:24 -0500162 SkRect::MakeWH(width, height), sigma);
Ethan Nicholas82399462017-10-16 12:35:44 -0400163}
164#endif