blob: a98e2778dbf5ac39cab0c920338db83820d63032 [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 Phillips4e105e22020-07-16 09:18:50 -040056 SkString _coords7176("float2(half2(xy.x, 0.5))");
57 SkString _sample7176 = this->invokeChild(1, args, _coords7176.c_str());
John Stiles50819422020-06-18 13:00:38 -040058 fragBuilder->codeAppendf(
59 R"SkSL(
60 xCoverage = %s.w;)SkSL",
Robert Phillips4e105e22020-07-16 09:18:50 -040061 _sample7176.c_str());
62 SkString _coords7234("float2(half2(xy.y, 0.5))");
63 SkString _sample7234 = this->invokeChild(1, args, _coords7234.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 Phillips4e105e22020-07-16 09:18:50 -040076 _sample7234.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 Phillips4e105e22020-07-16 09:18:50 -040081 SkString _coords8601("float2(half2(rect.x, 0.5))");
82 SkString _sample8601 = this->invokeChild(1, args, _coords8601.c_str());
83 SkString _coords8664("float2(half2(rect.z, 0.5))");
84 SkString _sample8664 = this->invokeChild(1, args, _coords8664.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 Phillips4e105e22020-07-16 09:18:50 -040088 _sample8601.c_str(), _sample8664.c_str());
89 SkString _coords8728("float2(half2(rect.y, 0.5))");
90 SkString _sample8728 = this->invokeChild(1, args, _coords8728.c_str());
91 SkString _coords8791("float2(half2(rect.w, 0.5))");
92 SkString _sample8791 = this->invokeChild(1, args, _coords8791.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 Phillips4e105e22020-07-16 09:18:50 -040097 _sample8728.c_str(), _sample8791.c_str());
Brian Osman6b5dbb42020-07-15 15:31:05 -040098 SkString _sample8860 = this->invokeChild(0, args);
Brian Salomonb2d5d402019-09-10 10:11:52 -040099 fragBuilder->codeAppendf(
John Stiles50819422020-06-18 13:00:38 -0400100 R"SkSL(
101half4 inputColor = %s;
102%s = (inputColor * xCoverage) * yCoverage;
103)SkSL",
Robert Phillips4e105e22020-07-16 09:18:50 -0400104 _sample8860.c_str(), args.fOutputColor);
Ethan Nicholas82399462017-10-16 12:35:44 -0400105 }
106
107private:
108 void onSetData(const GrGLSLProgramDataManager& pdman,
Mike Kleind6ab77a2019-03-21 08:18:24 -0500109 const GrFragmentProcessor& _proc) override {
Ethan Nicholas82399462017-10-16 12:35:44 -0400110 const GrRectBlurEffect& _outer = _proc.cast<GrRectBlurEffect>();
Brian Salomon2c596592019-08-13 20:05:04 -0400111 auto rect = _outer.rect;
Ethan Nicholas82399462017-10-16 12:35:44 -0400112 (void)rect;
Brian Salomon2c596592019-08-13 20:05:04 -0400113 UniformHandle& rectF = rectFVar;
114 (void)rectF;
115 UniformHandle& rectH = rectHVar;
116 (void)rectH;
Brian Salomonb2d5d402019-09-10 10:11:52 -0400117 auto isFast = _outer.isFast;
118 (void)isFast;
Ethan Nicholas82399462017-10-16 12:35:44 -0400119
Brian Salomon2c596592019-08-13 20:05:04 -0400120 float r[]{rect.fLeft, rect.fTop, rect.fRight, rect.fBottom};
121 pdman.set4fv(highp ? rectF : rectH, 1, r);
Ethan Nicholas82399462017-10-16 12:35:44 -0400122 }
Brian Salomon2c596592019-08-13 20:05:04 -0400123 bool highp = false;
124 UniformHandle rectFVar;
125 UniformHandle rectHVar;
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 Nicholascab767f2019-07-01 13:32:07 -0400131 GrProcessorKeyBuilder* b) const {
Brian Salomon2c596592019-08-13 20:05:04 -0400132 bool highp = ((abs(rect.left()) > 16000.0 || abs(rect.top()) > 16000.0) ||
133 abs(rect.right()) > 16000.0) ||
134 abs(rect.bottom()) > 16000.0;
135 b->add32((int32_t)highp);
Brian Salomonb2d5d402019-09-10 10:11:52 -0400136 b->add32((int32_t)isFast);
Ethan Nicholascab767f2019-07-01 13:32:07 -0400137}
Ethan Nicholas82399462017-10-16 12:35:44 -0400138bool GrRectBlurEffect::onIsEqual(const GrFragmentProcessor& other) const {
139 const GrRectBlurEffect& that = other.cast<GrRectBlurEffect>();
140 (void)that;
Ethan Nicholasbcd51e82019-04-09 10:40:41 -0400141 if (rect != that.rect) return false;
Brian Salomonb2d5d402019-09-10 10:11:52 -0400142 if (isFast != that.isFast) return false;
Ethan Nicholas82399462017-10-16 12:35:44 -0400143 return true;
144}
145GrRectBlurEffect::GrRectBlurEffect(const GrRectBlurEffect& src)
146 : INHERITED(kGrRectBlurEffect_ClassID, src.optimizationFlags())
Ethan Nicholasbcd51e82019-04-09 10:40:41 -0400147 , rect(src.rect)
Brian Salomonb2d5d402019-09-10 10:11:52 -0400148 , isFast(src.isFast) {
Brian Osman12c5d292020-07-13 16:11:35 -0400149 this->cloneAndRegisterAllChildProcessors(src);
Brian Salomone7366842019-09-04 11:20:45 -0400150}
Ethan Nicholas82399462017-10-16 12:35:44 -0400151std::unique_ptr<GrFragmentProcessor> GrRectBlurEffect::clone() const {
152 return std::unique_ptr<GrFragmentProcessor>(new GrRectBlurEffect(*this));
153}
154GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrRectBlurEffect);
155#if GR_TEST_UTILS
156std::unique_ptr<GrFragmentProcessor> GrRectBlurEffect::TestCreate(GrProcessorTestData* data) {
Mike Kleind6ab77a2019-03-21 08:18:24 -0500157 float sigma = data->fRandom->nextRangeF(3, 8);
158 float width = data->fRandom->nextRangeF(200, 300);
Ethan Nicholas82399462017-10-16 12:35:44 -0400159 float height = data->fRandom->nextRangeF(200, 300);
John Stilese7b4d732020-06-10 12:46:40 -0400160 return GrRectBlurEffect::Make(/*inputFP=*/nullptr, data->context(), *data->caps()->shaderCaps(),
Mike Kleind6ab77a2019-03-21 08:18:24 -0500161 SkRect::MakeWH(width, height), sigma);
Ethan Nicholas82399462017-10-16 12:35:44 -0400162}
163#endif