blob: db3e6879aa149370bf57cd92ee59797b2488b2dc [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 Stilese7b4d732020-06-10 12:46:40 -040042 "/* key */ bool highp = %s;\nhalf xCoverage, yCoverage;\n@if (%s) {\n half2 "
43 "xy;\n @if (highp) {\n xy = max(half2(%s.xy - sk_FragCoord.xy), "
44 "half2(sk_FragCoord.xy - %s.zw));\n } else {\n xy = "
45 "max(half2(float2(%s.xy) - sk_FragCoord.xy), half2(sk_FragCoord.xy - "
Brian Salomon86b2f392020-06-16 16:01:07 -040046 "float2(%s.zw)));\n }",
Brian Salomonb2d5d402019-09-10 10:11:52 -040047 (highp ? "true" : "false"), (_outer.isFast ? "true" : "false"),
48 rectFVar.isValid() ? args.fUniformHandler->getUniformCStr(rectFVar) : "float4(0)",
49 rectFVar.isValid() ? args.fUniformHandler->getUniformCStr(rectFVar) : "float4(0)",
Brian Salomon2c596592019-08-13 20:05:04 -040050 rectHVar.isValid() ? args.fUniformHandler->getUniformCStr(rectHVar) : "half4(0)",
Brian Salomon86b2f392020-06-16 16:01:07 -040051 rectHVar.isValid() ? args.fUniformHandler->getUniformCStr(rectHVar) : "half4(0)");
52 SkString _sample7194;
53 SkString _coords7194("float2(half2(xy.x, 0.5))");
54 _sample7194 = this->invokeChild(_outer.integral_index, args, _coords7194.c_str());
55 fragBuilder->codeAppendf("\n xCoverage = %s.w;", _sample7194.c_str());
56 SkString _sample7252;
57 SkString _coords7252("float2(half2(xy.y, 0.5))");
58 _sample7252 = this->invokeChild(_outer.integral_index, args, _coords7252.c_str());
Ethan Nicholas82399462017-10-16 12:35:44 -040059 fragBuilder->codeAppendf(
Brian Salomon86b2f392020-06-16 16:01:07 -040060 "\n yCoverage = %s.w;\n} else {\n half4 rect;\n @if (highp) {\n "
61 "rect.xy = half2(%s.xy - sk_FragCoord.xy);\n rect.zw = "
62 "half2(sk_FragCoord.xy - %s.zw);\n } else {\n rect.xy = "
63 "half2(float2(%s.xy) - sk_FragCoord.xy);\n rect.zw = half2(sk_FragCoord.xy "
64 "- float2(%s.zw));\n }",
65 _sample7252.c_str(),
John Stilese7b4d732020-06-10 12:46:40 -040066 rectFVar.isValid() ? args.fUniformHandler->getUniformCStr(rectFVar) : "float4(0)",
67 rectFVar.isValid() ? args.fUniformHandler->getUniformCStr(rectFVar) : "float4(0)",
68 rectHVar.isValid() ? args.fUniformHandler->getUniformCStr(rectHVar) : "half4(0)",
Brian Salomon86b2f392020-06-16 16:01:07 -040069 rectHVar.isValid() ? args.fUniformHandler->getUniformCStr(rectHVar) : "half4(0)");
70 SkString _sample8619;
71 SkString _coords8619("float2(half2(rect.x, 0.5))");
72 _sample8619 = this->invokeChild(_outer.integral_index, args, _coords8619.c_str());
73 SkString _sample8682;
74 SkString _coords8682("float2(half2(rect.z, 0.5))");
75 _sample8682 = this->invokeChild(_outer.integral_index, args, _coords8682.c_str());
76 fragBuilder->codeAppendf("\n xCoverage = (1.0 - %s.w) - %s.w;", _sample8619.c_str(),
77 _sample8682.c_str());
78 SkString _sample8746;
79 SkString _coords8746("float2(half2(rect.y, 0.5))");
80 _sample8746 = this->invokeChild(_outer.integral_index, args, _coords8746.c_str());
81 SkString _sample8809;
82 SkString _coords8809("float2(half2(rect.w, 0.5))");
83 _sample8809 = this->invokeChild(_outer.integral_index, args, _coords8809.c_str());
84 fragBuilder->codeAppendf("\n yCoverage = (1.0 - %s.w) - %s.w;\n}", _sample8746.c_str(),
85 _sample8809.c_str());
86 SkString _input8878 = SkStringPrintf("%s", args.fInputColor);
87 SkString _sample8878;
John Stilese7b4d732020-06-10 12:46:40 -040088 if (_outer.inputFP_index >= 0) {
Brian Salomon86b2f392020-06-16 16:01:07 -040089 _sample8878 = this->invokeChild(_outer.inputFP_index, _input8878.c_str(), args);
John Stilese7b4d732020-06-10 12:46:40 -040090 } else {
Brian Salomon86b2f392020-06-16 16:01:07 -040091 _sample8878 = _input8878;
John Stilese7b4d732020-06-10 12:46:40 -040092 }
Brian Salomonb2d5d402019-09-10 10:11:52 -040093 fragBuilder->codeAppendf(
John Stilese7b4d732020-06-10 12:46:40 -040094 "\nhalf4 inputColor = %s;\n%s = (inputColor * xCoverage) * yCoverage;\n",
Brian Salomon86b2f392020-06-16 16:01:07 -040095 _sample8878.c_str(), args.fOutputColor);
Ethan Nicholas82399462017-10-16 12:35:44 -040096 }
97
98private:
99 void onSetData(const GrGLSLProgramDataManager& pdman,
Mike Kleind6ab77a2019-03-21 08:18:24 -0500100 const GrFragmentProcessor& _proc) override {
Ethan Nicholas82399462017-10-16 12:35:44 -0400101 const GrRectBlurEffect& _outer = _proc.cast<GrRectBlurEffect>();
Brian Salomon2c596592019-08-13 20:05:04 -0400102 auto rect = _outer.rect;
Ethan Nicholas82399462017-10-16 12:35:44 -0400103 (void)rect;
Brian Salomon2c596592019-08-13 20:05:04 -0400104 UniformHandle& rectF = rectFVar;
105 (void)rectF;
106 UniformHandle& rectH = rectHVar;
107 (void)rectH;
Brian Salomonb2d5d402019-09-10 10:11:52 -0400108 auto isFast = _outer.isFast;
109 (void)isFast;
Ethan Nicholas82399462017-10-16 12:35:44 -0400110
Brian Salomon2c596592019-08-13 20:05:04 -0400111 float r[]{rect.fLeft, rect.fTop, rect.fRight, rect.fBottom};
112 pdman.set4fv(highp ? rectF : rectH, 1, r);
Ethan Nicholas82399462017-10-16 12:35:44 -0400113 }
Brian Salomon2c596592019-08-13 20:05:04 -0400114 bool highp = false;
115 UniformHandle rectFVar;
116 UniformHandle rectHVar;
Ethan Nicholas82399462017-10-16 12:35:44 -0400117};
118GrGLSLFragmentProcessor* GrRectBlurEffect::onCreateGLSLInstance() const {
119 return new GrGLSLRectBlurEffect();
120}
Mike Kleind6ab77a2019-03-21 08:18:24 -0500121void GrRectBlurEffect::onGetGLSLProcessorKey(const GrShaderCaps& caps,
Ethan Nicholascab767f2019-07-01 13:32:07 -0400122 GrProcessorKeyBuilder* b) const {
Brian Salomon2c596592019-08-13 20:05:04 -0400123 bool highp = ((abs(rect.left()) > 16000.0 || abs(rect.top()) > 16000.0) ||
124 abs(rect.right()) > 16000.0) ||
125 abs(rect.bottom()) > 16000.0;
126 b->add32((int32_t)highp);
Brian Salomonb2d5d402019-09-10 10:11:52 -0400127 b->add32((int32_t)isFast);
Ethan Nicholascab767f2019-07-01 13:32:07 -0400128}
Ethan Nicholas82399462017-10-16 12:35:44 -0400129bool GrRectBlurEffect::onIsEqual(const GrFragmentProcessor& other) const {
130 const GrRectBlurEffect& that = other.cast<GrRectBlurEffect>();
131 (void)that;
Ethan Nicholasbcd51e82019-04-09 10:40:41 -0400132 if (rect != that.rect) return false;
Brian Salomonb2d5d402019-09-10 10:11:52 -0400133 if (isFast != that.isFast) return false;
Ethan Nicholas82399462017-10-16 12:35:44 -0400134 return true;
135}
136GrRectBlurEffect::GrRectBlurEffect(const GrRectBlurEffect& src)
137 : INHERITED(kGrRectBlurEffect_ClassID, src.optimizationFlags())
Ethan Nicholasbcd51e82019-04-09 10:40:41 -0400138 , rect(src.rect)
Brian Salomonb2d5d402019-09-10 10:11:52 -0400139 , isFast(src.isFast) {
John Stiles88183902020-06-10 16:40:38 -0400140 if (src.inputFP_index >= 0) {
John Stiles3779f442020-06-15 10:48:49 -0400141 inputFP_index = this->cloneAndRegisterChildProcessor(src.childProcessor(src.inputFP_index));
John Stilese7b4d732020-06-10 12:46:40 -0400142 }
Brian Salomon86b2f392020-06-16 16:01:07 -0400143 {
144 integral_index =
145 this->cloneAndRegisterChildProcessor(src.childProcessor(src.integral_index));
146 }
Brian Salomone7366842019-09-04 11:20:45 -0400147}
Ethan Nicholas82399462017-10-16 12:35:44 -0400148std::unique_ptr<GrFragmentProcessor> GrRectBlurEffect::clone() const {
149 return std::unique_ptr<GrFragmentProcessor>(new GrRectBlurEffect(*this));
150}
151GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrRectBlurEffect);
152#if GR_TEST_UTILS
153std::unique_ptr<GrFragmentProcessor> GrRectBlurEffect::TestCreate(GrProcessorTestData* data) {
Mike Kleind6ab77a2019-03-21 08:18:24 -0500154 float sigma = data->fRandom->nextRangeF(3, 8);
155 float width = data->fRandom->nextRangeF(200, 300);
Ethan Nicholas82399462017-10-16 12:35:44 -0400156 float height = data->fRandom->nextRangeF(200, 300);
John Stilese7b4d732020-06-10 12:46:40 -0400157 return GrRectBlurEffect::Make(/*inputFP=*/nullptr, data->context(), *data->caps()->shaderCaps(),
Mike Kleind6ab77a2019-03-21 08:18:24 -0500158 SkRect::MakeWH(width, height), sigma);
Ethan Nicholas82399462017-10-16 12:35:44 -0400159}
160#endif