blob: 681fe79cf71efaf7b7001fe6e6185f3ddba4e743 [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
John Stiles45f5b032020-07-27 17:31:29 -040013#include "src/core/SkUtils.h"
Greg Daniel456f9b52020-03-05 19:14:18 +000014#include "src/gpu/GrTexture.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050015#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"
Ethan Nicholas82399462017-10-16 12:35:44 -040020class GrGLSLRectBlurEffect : public GrGLSLFragmentProcessor {
21public:
22 GrGLSLRectBlurEffect() {}
23 void emitCode(EmitArgs& args) override {
24 GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
Mike Kleind6ab77a2019-03-21 08:18:24 -050025 const GrRectBlurEffect& _outer = args.fFp.cast<GrRectBlurEffect>();
Ethan Nicholas82399462017-10-16 12:35:44 -040026 (void)_outer;
Ethan Nicholasbcd51e82019-04-09 10:40:41 -040027 auto rect = _outer.rect;
Ethan Nicholas82399462017-10-16 12:35:44 -040028 (void)rect;
Brian Salomonb2d5d402019-09-10 10:11:52 -040029 auto isFast = _outer.isFast;
30 (void)isFast;
Brian Salomon2c596592019-08-13 20:05:04 -040031 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) {
Ethan Nicholas16464c32020-04-06 13:53:05 -040035 rectFVar = args.fUniformHandler->addUniform(&_outer, kFragment_GrShaderFlag,
36 kFloat4_GrSLType, "rectF");
Ethan Nicholas82399462017-10-16 12:35:44 -040037 }
Brian Salomon2c596592019-08-13 20:05:04 -040038 if (!highp) {
Ethan Nicholas16464c32020-04-06 13:53:05 -040039 rectHVar = args.fUniformHandler->addUniform(&_outer, kFragment_GrShaderFlag,
40 kHalf4_GrSLType, "rectH");
Ethan Nicholas82399462017-10-16 12:35:44 -040041 }
Ethan Nicholas82399462017-10-16 12:35:44 -040042 fragBuilder->codeAppendf(
John Stiles50819422020-06-18 13:00:38 -040043 R"SkSL(/* key */ bool highp = %s;
44half xCoverage, yCoverage;
45@if (%s) {
46 half2 xy;
47 @if (highp) {
Robert Phillips1fc74222020-09-24 13:43:06 +000048 xy = max(half2(%s.xy - sk_FragCoord.xy), half2(sk_FragCoord.xy - %s.zw));
John Stiles50819422020-06-18 13:00:38 -040049 } else {
Robert Phillips1fc74222020-09-24 13:43:06 +000050 xy = max(half2(float2(%s.xy) - sk_FragCoord.xy), half2(sk_FragCoord.xy - float2(%s.zw)));
John Stiles50819422020-06-18 13:00:38 -040051 })SkSL",
Robert Phillips1fc74222020-09-24 13:43:06 +000052 (highp ? "true" : "false"), (_outer.isFast ? "true" : "false"),
Brian Salomonb2d5d402019-09-10 10:11:52 -040053 rectFVar.isValid() ? args.fUniformHandler->getUniformCStr(rectFVar) : "float4(0)",
54 rectFVar.isValid() ? args.fUniformHandler->getUniformCStr(rectFVar) : "float4(0)",
Brian Salomon2c596592019-08-13 20:05:04 -040055 rectHVar.isValid() ? args.fUniformHandler->getUniformCStr(rectHVar) : "half4(0)",
Brian Salomon86b2f392020-06-16 16:01:07 -040056 rectHVar.isValid() ? args.fUniformHandler->getUniformCStr(rectHVar) : "half4(0)");
Robert Phillips1fc74222020-09-24 13:43:06 +000057 SkString _coords6340("float2(half2(xy.x, 0.5))");
58 SkString _sample6340 = this->invokeChild(1, args, _coords6340.c_str());
John Stiles50819422020-06-18 13:00:38 -040059 fragBuilder->codeAppendf(
60 R"SkSL(
61 xCoverage = %s.w;)SkSL",
Robert Phillips1fc74222020-09-24 13:43:06 +000062 _sample6340.c_str());
63 SkString _coords6398("float2(half2(xy.y, 0.5))");
64 SkString _sample6398 = this->invokeChild(1, args, _coords6398.c_str());
Ethan Nicholas82399462017-10-16 12:35:44 -040065 fragBuilder->codeAppendf(
John Stiles50819422020-06-18 13:00:38 -040066 R"SkSL(
67 yCoverage = %s.w;
68} else {
69 half4 rect;
70 @if (highp) {
Robert Phillips1fc74222020-09-24 13:43:06 +000071 rect.xy = half2(%s.xy - sk_FragCoord.xy);
72 rect.zw = half2(sk_FragCoord.xy - %s.zw);
John Stiles50819422020-06-18 13:00:38 -040073 } else {
Robert Phillips1fc74222020-09-24 13:43:06 +000074 rect.xy = half2(float2(%s.xy) - sk_FragCoord.xy);
75 rect.zw = half2(sk_FragCoord.xy - float2(%s.zw));
John Stiles50819422020-06-18 13:00:38 -040076 })SkSL",
Robert Phillips1fc74222020-09-24 13:43:06 +000077 _sample6398.c_str(),
John Stilese7b4d732020-06-10 12:46:40 -040078 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)",
Brian Salomon86b2f392020-06-16 16:01:07 -040081 rectHVar.isValid() ? args.fUniformHandler->getUniformCStr(rectHVar) : "half4(0)");
Robert Phillips1fc74222020-09-24 13:43:06 +000082 SkString _coords7765("float2(half2(rect.x, 0.5))");
83 SkString _sample7765 = this->invokeChild(1, args, _coords7765.c_str());
84 SkString _coords7828("float2(half2(rect.z, 0.5))");
85 SkString _sample7828 = this->invokeChild(1, args, _coords7828.c_str());
John Stiles50819422020-06-18 13:00:38 -040086 fragBuilder->codeAppendf(
87 R"SkSL(
88 xCoverage = (1.0 - %s.w) - %s.w;)SkSL",
Robert Phillips1fc74222020-09-24 13:43:06 +000089 _sample7765.c_str(), _sample7828.c_str());
90 SkString _coords7892("float2(half2(rect.y, 0.5))");
91 SkString _sample7892 = this->invokeChild(1, args, _coords7892.c_str());
92 SkString _coords7955("float2(half2(rect.w, 0.5))");
93 SkString _sample7955 = this->invokeChild(1, args, _coords7955.c_str());
John Stiles50819422020-06-18 13:00:38 -040094 fragBuilder->codeAppendf(
95 R"SkSL(
96 yCoverage = (1.0 - %s.w) - %s.w;
97})SkSL",
Robert Phillips1fc74222020-09-24 13:43:06 +000098 _sample7892.c_str(), _sample7955.c_str());
99 SkString _sample8024 = this->invokeChild(0, 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 Phillips1fc74222020-09-24 13:43:06 +0000105 _sample8024.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;
John Stiles45f5b032020-07-27 17:31:29 -0400136 b->add32((uint32_t)highp);
137 b->add32((uint32_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}
John Stiles735a5a72020-08-26 10:21:10 -0400146bool GrRectBlurEffect::usesExplicitReturn() const { return false; }
Ethan Nicholas82399462017-10-16 12:35:44 -0400147GrRectBlurEffect::GrRectBlurEffect(const GrRectBlurEffect& src)
148 : INHERITED(kGrRectBlurEffect_ClassID, src.optimizationFlags())
Ethan Nicholasbcd51e82019-04-09 10:40:41 -0400149 , rect(src.rect)
Brian Salomonb2d5d402019-09-10 10:11:52 -0400150 , isFast(src.isFast) {
Brian Osman12c5d292020-07-13 16:11:35 -0400151 this->cloneAndRegisterAllChildProcessors(src);
Brian Salomone7366842019-09-04 11:20:45 -0400152}
Ethan Nicholas82399462017-10-16 12:35:44 -0400153std::unique_ptr<GrFragmentProcessor> GrRectBlurEffect::clone() const {
John Stilesfbd050b2020-08-03 13:21:46 -0400154 return std::make_unique<GrRectBlurEffect>(*this);
Ethan Nicholas82399462017-10-16 12:35:44 -0400155}
John Stiles8d9bf642020-08-12 15:07:45 -0400156#if GR_TEST_UTILS
John Stilescab58862020-08-12 15:47:06 -0400157SkString GrRectBlurEffect::onDumpInfo() const {
Robert Phillips1fc74222020-09-24 13:43:06 +0000158 return SkStringPrintf("(rect=float4(%f, %f, %f, %f), isFast=%s)", rect.left(), rect.top(),
159 rect.right(), rect.bottom(), (isFast ? "true" : "false"));
John Stiles47b4e222020-08-12 09:56:50 -0400160}
161#endif
Ethan Nicholas82399462017-10-16 12:35:44 -0400162GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrRectBlurEffect);
163#if GR_TEST_UTILS
164std::unique_ptr<GrFragmentProcessor> GrRectBlurEffect::TestCreate(GrProcessorTestData* data) {
Mike Kleind6ab77a2019-03-21 08:18:24 -0500165 float sigma = data->fRandom->nextRangeF(3, 8);
166 float width = data->fRandom->nextRangeF(200, 300);
Ethan Nicholas82399462017-10-16 12:35:44 -0400167 float height = data->fRandom->nextRangeF(200, 300);
John Stiles6609cb62020-07-17 14:52:12 -0400168 return GrRectBlurEffect::Make(data->inputFP(), data->context(), *data->caps()->shaderCaps(),
Robert Phillips1fc74222020-09-24 13:43:06 +0000169 SkRect::MakeWH(width, height), sigma);
Ethan Nicholas82399462017-10-16 12:35:44 -0400170}
171#endif