blob: 0488518584024aca62990d1cdac16b4cd5e809dd [file] [log] [blame]
tomhudson@google.comd8f856c2012-05-10 12:13:36 +00001/*
2 * Copyright 2012 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
Mike Kleinc0bd9f92019-04-23 12:05:21 -05008#include "src/gpu/effects/GrGaussianConvolutionFragmentProcessor.h"
Robert Phillips296b1cc2017-03-15 10:42:12 -04009
Greg Daniel456f9b52020-03-05 19:14:18 +000010#include "src/gpu/GrTexture.h"
Greg Danielf91aeb22019-06-18 09:58:02 -040011#include "src/gpu/GrTextureProxy.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050012#include "src/gpu/glsl/GrGLSLFragmentProcessor.h"
13#include "src/gpu/glsl/GrGLSLFragmentShaderBuilder.h"
14#include "src/gpu/glsl/GrGLSLProgramDataManager.h"
15#include "src/gpu/glsl/GrGLSLUniformHandler.h"
tomhudson@google.comd8f856c2012-05-10 12:13:36 +000016
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +000017// For brevity
Brian Salomonb133ffe2017-07-27 11:53:21 -040018using UniformHandle = GrGLSLProgramDataManager::UniformHandle;
19using Direction = GrGaussianConvolutionFragmentProcessor::Direction;
bsalomon@google.com032b2212012-07-16 13:36:18 +000020
egdaniel64c47282015-11-13 06:54:19 -080021class GrGLConvolutionEffect : public GrGLSLFragmentProcessor {
tomhudson@google.comd8f856c2012-05-10 12:13:36 +000022public:
robertphillips9cdb9922016-02-03 12:25:40 -080023 void emitCode(EmitArgs&) override;
ericrk7a787b42015-07-21 14:06:16 -070024
Brian Salomon94efbf52016-11-29 13:43:05 -050025 static inline void GenKey(const GrProcessor&, const GrShaderCaps&, GrProcessorKeyBuilder*);
tomhudson@google.comd8f856c2012-05-10 12:13:36 +000026
wangyixb1daa862015-08-18 11:29:31 -070027protected:
Brian Salomonab015ef2017-04-04 10:15:51 -040028 void onSetData(const GrGLSLProgramDataManager&, const GrFragmentProcessor&) override;
wangyixb1daa862015-08-18 11:29:31 -070029
ericrk0f386122015-07-21 13:15:47 -070030private:
Brian Salomonaee504b2017-01-24 12:29:36 -050031 UniformHandle fKernelUni;
32 UniformHandle fImageIncrementUni;
33 UniformHandle fBoundsUni;
tomhudson@google.comd8f856c2012-05-10 12:13:36 +000034
egdaniel64c47282015-11-13 06:54:19 -080035 typedef GrGLSLFragmentProcessor INHERITED;
tomhudson@google.comd8f856c2012-05-10 12:13:36 +000036};
37
wangyix7c157a92015-07-22 15:08:53 -070038void GrGLConvolutionEffect::emitCode(EmitArgs& args) {
Brian Salomonaee504b2017-01-24 12:29:36 -050039 const GrGaussianConvolutionFragmentProcessor& ce =
40 args.fFp.cast<GrGaussianConvolutionFragmentProcessor>();
robertphillipsbf536af2016-02-04 06:11:53 -080041
egdaniel7ea439b2015-12-03 09:20:44 -080042 GrGLSLUniformHandler* uniformHandler = args.fUniformHandler;
Ethan Nicholas16464c32020-04-06 13:53:05 -040043 fImageIncrementUni = uniformHandler->addUniform(&ce, kFragment_GrShaderFlag, kHalf2_GrSLType,
Ethan Nicholasf7b88202017-09-18 14:10:39 -040044 "ImageIncrement");
robertphillipsbf536af2016-02-04 06:11:53 -080045 if (ce.useBounds()) {
Ethan Nicholas16464c32020-04-06 13:53:05 -040046 fBoundsUni = uniformHandler->addUniform(&ce, kFragment_GrShaderFlag, kHalf2_GrSLType,
Ethan Nicholasf7b88202017-09-18 14:10:39 -040047 "Bounds");
ericrk7a787b42015-07-21 14:06:16 -070048 }
robertphillipsbf536af2016-02-04 06:11:53 -080049
Brian Salomonb133ffe2017-07-27 11:53:21 -040050 int width = ce.width();
robertphillipsbf536af2016-02-04 06:11:53 -080051
jvanverth78d6eb02016-03-02 13:21:16 -080052 int arrayCount = (width + 3) / 4;
53 SkASSERT(4 * arrayCount >= width);
54
Ethan Nicholas16464c32020-04-06 13:53:05 -040055 fKernelUni = uniformHandler->addUniformArray(&ce, kFragment_GrShaderFlag, kHalf4_GrSLType,
Ethan Nicholasf7b88202017-09-18 14:10:39 -040056 "Kernel", arrayCount);
ericrk7a787b42015-07-21 14:06:16 -070057
cdalton85285412016-02-18 12:37:07 -080058 GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
Ethan Nicholasd4efe682019-08-29 16:10:13 -040059 SkString coords2D = fragBuilder->ensureCoords2D(args.fTransformedCoords[0].fVaryingPoint);
ericrk7a787b42015-07-21 14:06:16 -070060
Ethan Nicholasf7b88202017-09-18 14:10:39 -040061 fragBuilder->codeAppendf("%s = half4(0, 0, 0, 0);", args.fOutputColor);
ericrk7a787b42015-07-21 14:06:16 -070062
Brian Salomon99938a82016-11-21 13:41:08 -050063 const GrShaderVar& kernel = uniformHandler->getUniformVariable(fKernelUni);
egdaniel7ea439b2015-12-03 09:20:44 -080064 const char* imgInc = uniformHandler->getUniformCStr(fImageIncrementUni);
ericrk7a787b42015-07-21 14:06:16 -070065
Ethan Nicholas8aa45692017-09-20 11:24:15 -040066 fragBuilder->codeAppendf("float2 coord = %s - %d.0 * %s;", coords2D.c_str(), ce.radius(), imgInc);
67 fragBuilder->codeAppend("float2 coordSampled = half2(0, 0);");
ericrk7a787b42015-07-21 14:06:16 -070068
69 // Manually unroll loop because some drivers don't; yields 20-30% speedup.
Brian Salomonaee504b2017-01-24 12:29:36 -050070 const char* kVecSuffix[4] = {".x", ".y", ".z", ".w"};
ericrk7a787b42015-07-21 14:06:16 -070071 for (int i = 0; i < width; i++) {
72 SkString index;
73 SkString kernelIndex;
Brian Salomonaee504b2017-01-24 12:29:36 -050074 index.appendS32(i / 4);
ericrk7a787b42015-07-21 14:06:16 -070075 kernel.appendArrayAccess(index.c_str(), &kernelIndex);
jvanverth78d6eb02016-03-02 13:21:16 -080076 kernelIndex.append(kVecSuffix[i & 0x3]);
ericrk7a787b42015-07-21 14:06:16 -070077
wutao039a7c72017-06-30 10:44:45 -070078 fragBuilder->codeAppend("coordSampled = coord;");
robertphillipsbf536af2016-02-04 06:11:53 -080079 if (ce.useBounds()) {
ericrk7a787b42015-07-21 14:06:16 -070080 // We used to compute a bool indicating whether we're in bounds or not, cast it to a
81 // float, and then mul weight*texture_sample by the float. However, the Adreno 430 seems
82 // to have a bug that caused corruption.
egdaniel7ea439b2015-12-03 09:20:44 -080083 const char* bounds = uniformHandler->getUniformCStr(fBoundsUni);
Brian Salomonb133ffe2017-07-27 11:53:21 -040084 const char* component = ce.direction() == Direction::kY ? "y" : "x";
wutao039a7c72017-06-30 10:44:45 -070085
86 switch (ce.mode()) {
87 case GrTextureDomain::kClamp_Mode: {
88 fragBuilder->codeAppendf("coordSampled.%s = clamp(coord.%s, %s.x, %s.y);\n",
89 component, component, bounds, bounds);
90 break;
91 }
Brian Salomon7caa1372019-12-09 10:40:56 -050092 // Deferring implementing kMirrorRepeat until we use DomainEffects as
93 // child processors. Fallback to Repeat.
94 case GrTextureDomain::kMirrorRepeat_Mode:
wutao039a7c72017-06-30 10:44:45 -070095 case GrTextureDomain::kRepeat_Mode: {
96 fragBuilder->codeAppendf("coordSampled.%s = "
97 "mod(coord.%s - %s.x, %s.y - %s.x) + %s.x;\n",
98 component, component, bounds, bounds, bounds, bounds);
99 break;
100 }
101 case GrTextureDomain::kDecal_Mode: {
102 fragBuilder->codeAppendf("if (coord.%s >= %s.x && coord.%s <= %s.y) {",
103 component, bounds, component, bounds);
104 break;
105 }
106 default: {
Ben Wagnerb4aab9a2017-08-16 10:53:04 -0400107 SK_ABORT("Unsupported operation.");
wutao039a7c72017-06-30 10:44:45 -0700108 }
109 }
ericrk7a787b42015-07-21 14:06:16 -0700110 }
Brian Salomonaee504b2017-01-24 12:29:36 -0500111 fragBuilder->codeAppendf("%s += ", args.fOutputColor);
wutao039a7c72017-06-30 10:44:45 -0700112 fragBuilder->appendTextureLookup(args.fTexSamplers[0], "coordSampled");
egdaniel4ca2e602015-11-18 08:01:26 -0800113 fragBuilder->codeAppendf(" * %s;\n", kernelIndex.c_str());
wutao039a7c72017-06-30 10:44:45 -0700114 if (GrTextureDomain::kDecal_Mode == ce.mode()) {
egdaniel4ca2e602015-11-18 08:01:26 -0800115 fragBuilder->codeAppend("}");
ericrk7a787b42015-07-21 14:06:16 -0700116 }
Brian Salomonaee504b2017-01-24 12:29:36 -0500117 fragBuilder->codeAppendf("coord += %s;\n", imgInc);
ericrk7a787b42015-07-21 14:06:16 -0700118 }
Ethan Nicholas2983f402017-05-08 09:36:08 -0400119 fragBuilder->codeAppendf("%s *= %s;\n", args.fOutputColor, args.fInputColor);
ericrk7a787b42015-07-21 14:06:16 -0700120}
121
egdaniel018fb622015-10-28 07:26:40 -0700122void GrGLConvolutionEffect::onSetData(const GrGLSLProgramDataManager& pdman,
Brian Salomonab015ef2017-04-04 10:15:51 -0400123 const GrFragmentProcessor& processor) {
Brian Salomonaee504b2017-01-24 12:29:36 -0500124 const GrGaussianConvolutionFragmentProcessor& conv =
125 processor.cast<GrGaussianConvolutionFragmentProcessor>();
Robert Phillipsbd99c0c2019-12-12 13:26:58 +0000126 const auto& view = conv.textureSampler(0).view();
127 GrSurfaceProxy* proxy = view.proxy();
Brian Salomonfd98c2c2018-07-31 17:25:29 -0400128 GrTexture& texture = *proxy->peekTexture();
robertphillipsbf536af2016-02-04 06:11:53 -0800129
Brian Salomonaee504b2017-01-24 12:29:36 -0500130 float imageIncrement[2] = {0};
Robert Phillipsbd99c0c2019-12-12 13:26:58 +0000131 float ySign = view.origin() != kTopLeft_GrSurfaceOrigin ? 1.0f : -1.0f;
ericrk7a787b42015-07-21 14:06:16 -0700132 switch (conv.direction()) {
Brian Salomonb133ffe2017-07-27 11:53:21 -0400133 case Direction::kX:
ericrk7a787b42015-07-21 14:06:16 -0700134 imageIncrement[0] = 1.0f / texture.width();
135 break;
Brian Salomonb133ffe2017-07-27 11:53:21 -0400136 case Direction::kY:
ericrk7a787b42015-07-21 14:06:16 -0700137 imageIncrement[1] = ySign / texture.height();
138 break;
139 default:
Ben Wagnerb4aab9a2017-08-16 10:53:04 -0400140 SK_ABORT("Unknown filter direction.");
ericrk7a787b42015-07-21 14:06:16 -0700141 }
142 pdman.set2fv(fImageIncrementUni, 1, imageIncrement);
143 if (conv.useBounds()) {
wutao039a7c72017-06-30 10:44:45 -0700144 float bounds[2] = {0};
145 bounds[0] = conv.bounds()[0];
146 bounds[1] = conv.bounds()[1];
147 if (GrTextureDomain::kClamp_Mode == conv.mode()) {
148 bounds[0] += SK_ScalarHalf;
149 bounds[1] -= SK_ScalarHalf;
150 }
Brian Salomonb133ffe2017-07-27 11:53:21 -0400151 if (Direction::kX == conv.direction()) {
Robert Phillips08c5ec72017-01-30 12:26:47 -0500152 SkScalar inv = SkScalarInvert(SkIntToScalar(texture.width()));
Robert Phillipseaded9d2018-05-01 15:17:50 -0400153 bounds[0] *= inv;
154 bounds[1] *= inv;
ericrk7a787b42015-07-21 14:06:16 -0700155 } else {
Robert Phillips08c5ec72017-01-30 12:26:47 -0500156 SkScalar inv = SkScalarInvert(SkIntToScalar(texture.height()));
Robert Phillipsbd99c0c2019-12-12 13:26:58 +0000157 if (view.origin() != kTopLeft_GrSurfaceOrigin) {
Robert Phillipseaded9d2018-05-01 15:17:50 -0400158 float tmp = bounds[0];
159 bounds[0] = 1.0f - (inv * bounds[1]);
160 bounds[1] = 1.0f - (inv * tmp);
Robert Phillips08c5ec72017-01-30 12:26:47 -0500161 } else {
Robert Phillipseaded9d2018-05-01 15:17:50 -0400162 bounds[0] *= inv;
163 bounds[1] *= inv;
Robert Phillips08c5ec72017-01-30 12:26:47 -0500164 }
ericrk7a787b42015-07-21 14:06:16 -0700165 }
Robert Phillipseaded9d2018-05-01 15:17:50 -0400166
167 SkASSERT(bounds[0] <= bounds[1]);
168 pdman.set2f(fBoundsUni, bounds[0], bounds[1]);
ericrk7a787b42015-07-21 14:06:16 -0700169 }
Brian Salomonb133ffe2017-07-27 11:53:21 -0400170 int width = conv.width();
robertphillipsbf536af2016-02-04 06:11:53 -0800171
jvanverth78d6eb02016-03-02 13:21:16 -0800172 int arrayCount = (width + 3) / 4;
173 SkASSERT(4 * arrayCount >= width);
174 pdman.set4fv(fKernelUni, arrayCount, conv.kernel());
ericrk7a787b42015-07-21 14:06:16 -0700175}
176
Brian Salomon94efbf52016-11-29 13:43:05 -0500177void GrGLConvolutionEffect::GenKey(const GrProcessor& processor, const GrShaderCaps&,
joshualittb0a8a372014-09-23 09:50:21 -0700178 GrProcessorKeyBuilder* b) {
Brian Salomonaee504b2017-01-24 12:29:36 -0500179 const GrGaussianConvolutionFragmentProcessor& conv =
180 processor.cast<GrGaussianConvolutionFragmentProcessor>();
bsalomon63e99f72014-07-21 08:03:14 -0700181 uint32_t key = conv.radius();
wutao039a7c72017-06-30 10:44:45 -0700182 key <<= 3;
Brian Osmanef79fa82019-07-16 13:34:14 -0400183 if (conv.useBounds()) {
184 key |= Direction::kY == conv.direction() ? 0x4 : 0x0;
185 }
wutao039a7c72017-06-30 10:44:45 -0700186 key |= static_cast<uint32_t>(conv.mode());
bsalomon63e99f72014-07-21 08:03:14 -0700187 b->add32(key);
tomhudson@google.comd8f856c2012-05-10 12:13:36 +0000188}
189
bsalomon@google.comb505a122012-05-31 18:40:36 +0000190///////////////////////////////////////////////////////////////////////////////
Robert Phillips369e8b72017-08-01 16:13:04 -0400191static void fill_in_1D_gaussian_kernel(float* kernel, int width, float gaussianSigma, int radius) {
Greg Daniel4eda8d92018-04-03 14:03:15 -0400192 const float twoSigmaSqrd = 2.0f * gaussianSigma * gaussianSigma;
Greg Daniel3aecc302018-04-03 13:38:01 -0400193 if (SkScalarNearlyZero(twoSigmaSqrd, SK_ScalarNearlyZero)) {
194 for (int i = 0; i < width; ++i) {
195 kernel[i] = 0.0f;
196 }
197 return;
198 }
199
200 const float denom = 1.0f / twoSigmaSqrd;
Robert Phillips40fd7c92017-01-30 08:06:27 -0500201
202 float sum = 0.0f;
203 for (int i = 0; i < width; ++i) {
204 float x = static_cast<float>(i - radius);
205 // Note that the constant term (1/(sqrt(2*pi*sigma^2)) of the Gaussian
206 // is dropped here, since we renormalize the kernel below.
207 kernel[i] = sk_float_exp(-x * x * denom);
208 sum += kernel[i];
209 }
210 // Normalize the kernel
211 float scale = 1.0f / sum;
212 for (int i = 0; i < width; ++i) {
213 kernel[i] *= scale;
214 }
215}
216
Robert Phillips40fd7c92017-01-30 08:06:27 -0500217GrGaussianConvolutionFragmentProcessor::GrGaussianConvolutionFragmentProcessor(
Greg Daniel5c082492020-01-29 15:06:49 -0500218 GrSurfaceProxyView view,
Brian Salomonfc118442019-11-22 19:09:27 -0500219 SkAlphaType alphaType,
220 Direction direction,
221 int radius,
222 float gaussianSigma,
223 GrTextureDomain::Mode mode,
224 int bounds[2])
Ethan Nicholasabff9562017-10-09 10:54:08 -0400225 : INHERITED(kGrGaussianConvolutionFragmentProcessor_ClassID,
Brian Salomonfc118442019-11-22 19:09:27 -0500226 ModulateForSamplerOptFlags(alphaType, mode == GrTextureDomain::kDecal_Mode))
Greg Daniel67da6652020-02-12 14:09:34 -0500227 , fCoordTransform(view.proxy(), view.origin())
Greg Daniel5c082492020-01-29 15:06:49 -0500228 , fTextureSampler(std::move(view))
Brian Salomonb133ffe2017-07-27 11:53:21 -0400229 , fRadius(radius)
230 , fDirection(direction)
wutao039a7c72017-06-30 10:44:45 -0700231 , fMode(mode) {
Brian Salomonb133ffe2017-07-27 11:53:21 -0400232 this->addCoordTransform(&fCoordTransform);
Brian Salomonf7dcd762018-07-30 14:48:15 -0400233 this->setTextureSamplerCnt(1);
Robert Phillips40fd7c92017-01-30 08:06:27 -0500234 SkASSERT(radius <= kMaxKernelRadius);
235
Robert Phillips369e8b72017-08-01 16:13:04 -0400236 fill_in_1D_gaussian_kernel(fKernel, this->width(), gaussianSigma, this->radius());
Brian Salomonf631cf32020-01-16 17:18:46 -0500237 // SkGpuBlurUtils is not as aggressive as it once was about avoiding domains. So we check
238 // here if we can omit the domain. TODO: remove this when this effect uses a child to
239 // sample the texture.
240 auto samplerProxy = fTextureSampler.proxy();
241 if (!samplerProxy->isFullyLazy()) {
242 int wh = (fDirection == Direction::kX) ? samplerProxy->backingStoreDimensions().width()
243 : samplerProxy->backingStoreDimensions().height();
244 if (bounds[0] == 0 && bounds[1] == wh) {
245 bool useSampler = false;
246 GrSamplerState::WrapMode samplerMode = GrSamplerState::WrapMode::kClamp;
247 switch (fMode) {
248 case GrTextureDomain::kClamp_Mode:
249 case GrTextureDomain::kIgnore_Mode:
250 useSampler = true;
251 break;
252 case GrTextureDomain::kRepeat_Mode:
253 useSampler = true;
254 samplerMode = GrSamplerState::WrapMode::kRepeat;
255 break;
256 case GrTextureDomain::kMirrorRepeat_Mode:
257 useSampler = true;
258 samplerMode = GrSamplerState::WrapMode::kMirrorRepeat;
259 break;
260 case GrTextureDomain::kDecal_Mode:
261 // Not sure if we support this in HW without having GrCaps here.
262 // Just wait until we replace this with GrTextureEffect.
263 break;
264 }
265 if (useSampler) {
266 fMode = GrTextureDomain::kIgnore_Mode;
267 if (fDirection == Direction::kX) {
268 fTextureSampler.samplerState().setWrapModeX(samplerMode);
269 } else {
270 fTextureSampler.samplerState().setWrapModeY(samplerMode);
271 }
272 }
273 }
274 }
senorblanco@chromium.orge8232bc2013-07-29 18:45:44 +0000275 memcpy(fBounds, bounds, sizeof(fBounds));
tomhudson@google.comfde2c0a2012-07-16 12:23:32 +0000276}
277
Brian Salomon3f6f9652017-07-28 07:34:05 -0400278GrGaussianConvolutionFragmentProcessor::GrGaussianConvolutionFragmentProcessor(
279 const GrGaussianConvolutionFragmentProcessor& that)
Ethan Nicholasabff9562017-10-09 10:54:08 -0400280 : INHERITED(kGrGaussianConvolutionFragmentProcessor_ClassID, that.optimizationFlags())
Brian Salomon3f6f9652017-07-28 07:34:05 -0400281 , fCoordTransform(that.fCoordTransform)
282 , fTextureSampler(that.fTextureSampler)
283 , fRadius(that.fRadius)
284 , fDirection(that.fDirection)
285 , fMode(that.fMode) {
Brian Salomon3f6f9652017-07-28 07:34:05 -0400286 this->addCoordTransform(&fCoordTransform);
Brian Salomonf7dcd762018-07-30 14:48:15 -0400287 this->setTextureSamplerCnt(1);
Brian Salomon3f6f9652017-07-28 07:34:05 -0400288 memcpy(fKernel, that.fKernel, that.width() * sizeof(float));
289 memcpy(fBounds, that.fBounds, sizeof(fBounds));
290}
tomhudson@google.comd8f856c2012-05-10 12:13:36 +0000291
Brian Salomonaee504b2017-01-24 12:29:36 -0500292void GrGaussianConvolutionFragmentProcessor::onGetGLSLProcessorKey(const GrShaderCaps& caps,
293 GrProcessorKeyBuilder* b) const {
joshualitteb2a6762014-12-04 11:35:33 -0800294 GrGLConvolutionEffect::GenKey(*this, caps, b);
295}
296
Brian Salomonaee504b2017-01-24 12:29:36 -0500297GrGLSLFragmentProcessor* GrGaussianConvolutionFragmentProcessor::onCreateGLSLInstance() const {
robertphillipsbf536af2016-02-04 06:11:53 -0800298 return new GrGLConvolutionEffect;
tomhudson@google.comd8f856c2012-05-10 12:13:36 +0000299}
300
Brian Salomonaee504b2017-01-24 12:29:36 -0500301bool GrGaussianConvolutionFragmentProcessor::onIsEqual(const GrFragmentProcessor& sBase) const {
302 const GrGaussianConvolutionFragmentProcessor& s =
303 sBase.cast<GrGaussianConvolutionFragmentProcessor>();
304 return (this->radius() == s.radius() && this->direction() == s.direction() &&
wutao039a7c72017-06-30 10:44:45 -0700305 this->mode() == s.mode() &&
senorblanco@chromium.orge8232bc2013-07-29 18:45:44 +0000306 0 == memcmp(fBounds, s.fBounds, sizeof(fBounds)) &&
tomhudson@google.comd0c1a062012-07-12 17:23:52 +0000307 0 == memcmp(fKernel, s.fKernel, this->width() * sizeof(float)));
tomhudson@google.comd8f856c2012-05-10 12:13:36 +0000308}
bsalomon@google.com0a7672f2012-08-03 18:12:20 +0000309
310///////////////////////////////////////////////////////////////////////////////
311
Brian Salomonaee504b2017-01-24 12:29:36 -0500312GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrGaussianConvolutionFragmentProcessor);
bsalomon@google.com0a7672f2012-08-03 18:12:20 +0000313
Hal Canary6f6961e2017-01-31 13:50:44 -0500314#if GR_TEST_UTILS
Brian Salomonaff329b2017-08-11 09:40:37 -0400315std::unique_ptr<GrFragmentProcessor> GrGaussianConvolutionFragmentProcessor::TestCreate(
Brian Salomonaee504b2017-01-24 12:29:36 -0500316 GrProcessorTestData* d) {
Greg Daniel026a60c2020-02-12 10:53:51 -0500317 auto [view, ct, at] = d->randomView();
Brian Salomonaee504b2017-01-24 12:29:36 -0500318
Robert Phillips08c5ec72017-01-30 12:26:47 -0500319 int bounds[2];
wutao039a7c72017-06-30 10:44:45 -0700320 int modeIdx = d->fRandom->nextRangeU(0, GrTextureDomain::kModeCount-1);
Robert Phillips08c5ec72017-01-30 12:26:47 -0500321
322 Direction dir;
323 if (d->fRandom->nextBool()) {
Brian Salomonb133ffe2017-07-27 11:53:21 -0400324 dir = Direction::kX;
Greg Daniel026a60c2020-02-12 10:53:51 -0500325 bounds[0] = d->fRandom->nextRangeU(0, view.width()-2);
326 bounds[1] = d->fRandom->nextRangeU(bounds[0]+1, view.width()-1);
Robert Phillips08c5ec72017-01-30 12:26:47 -0500327 } else {
Brian Salomonb133ffe2017-07-27 11:53:21 -0400328 dir = Direction::kY;
Greg Daniel026a60c2020-02-12 10:53:51 -0500329 bounds[0] = d->fRandom->nextRangeU(0, view.height()-2);
330 bounds[1] = d->fRandom->nextRangeU(bounds[0]+1, view.height()-1);
senorblanco@chromium.org194d7752013-07-24 22:19:24 +0000331 }
bsalomon@google.com0a7672f2012-08-03 18:12:20 +0000332
Robert Phillips08c5ec72017-01-30 12:26:47 -0500333 int radius = d->fRandom->nextRangeU(1, kMaxKernelRadius);
Brian Salomonaee504b2017-01-24 12:29:36 -0500334 float sigma = radius / 3.f;
Robert Phillips08c5ec72017-01-30 12:26:47 -0500335
Greg Daniel5c082492020-01-29 15:06:49 -0500336 return GrGaussianConvolutionFragmentProcessor::Make(std::move(view), at, dir, radius, sigma,
Brian Salomon766098d2019-12-18 10:41:58 -0500337 static_cast<GrTextureDomain::Mode>(modeIdx),
338 bounds);
bsalomon@google.com0a7672f2012-08-03 18:12:20 +0000339}
Hal Canary6f6961e2017-01-31 13:50:44 -0500340#endif