tomhudson@google.com | d8f856c | 2012-05-10 12:13:36 +0000 | [diff] [blame] | 1 | /* |
| 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 Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #include "src/gpu/effects/GrGaussianConvolutionFragmentProcessor.h" |
Robert Phillips | 296b1cc | 2017-03-15 10:42:12 -0400 | [diff] [blame] | 9 | |
Greg Daniel | 456f9b5 | 2020-03-05 19:14:18 +0000 | [diff] [blame] | 10 | #include "src/gpu/GrTexture.h" |
Greg Daniel | f91aeb2 | 2019-06-18 09:58:02 -0400 | [diff] [blame] | 11 | #include "src/gpu/GrTextureProxy.h" |
Brian Salomon | 5ed3c2f | 2020-04-13 16:51:39 -0400 | [diff] [blame] | 12 | #include "src/gpu/effects/GrTextureEffect.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 13 | #include "src/gpu/glsl/GrGLSLFragmentProcessor.h" |
| 14 | #include "src/gpu/glsl/GrGLSLFragmentShaderBuilder.h" |
| 15 | #include "src/gpu/glsl/GrGLSLProgramDataManager.h" |
| 16 | #include "src/gpu/glsl/GrGLSLUniformHandler.h" |
tomhudson@google.com | d8f856c | 2012-05-10 12:13:36 +0000 | [diff] [blame] | 17 | |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 18 | // For brevity |
Brian Salomon | b133ffe | 2017-07-27 11:53:21 -0400 | [diff] [blame] | 19 | using UniformHandle = GrGLSLProgramDataManager::UniformHandle; |
| 20 | using Direction = GrGaussianConvolutionFragmentProcessor::Direction; |
bsalomon@google.com | 032b221 | 2012-07-16 13:36:18 +0000 | [diff] [blame] | 21 | |
egdaniel | 64c4728 | 2015-11-13 06:54:19 -0800 | [diff] [blame] | 22 | class GrGLConvolutionEffect : public GrGLSLFragmentProcessor { |
tomhudson@google.com | d8f856c | 2012-05-10 12:13:36 +0000 | [diff] [blame] | 23 | public: |
robertphillips | 9cdb992 | 2016-02-03 12:25:40 -0800 | [diff] [blame] | 24 | void emitCode(EmitArgs&) override; |
ericrk | 7a787b4 | 2015-07-21 14:06:16 -0700 | [diff] [blame] | 25 | |
Brian Salomon | 94efbf5 | 2016-11-29 13:43:05 -0500 | [diff] [blame] | 26 | static inline void GenKey(const GrProcessor&, const GrShaderCaps&, GrProcessorKeyBuilder*); |
tomhudson@google.com | d8f856c | 2012-05-10 12:13:36 +0000 | [diff] [blame] | 27 | |
wangyix | b1daa86 | 2015-08-18 11:29:31 -0700 | [diff] [blame] | 28 | protected: |
Brian Salomon | ab015ef | 2017-04-04 10:15:51 -0400 | [diff] [blame] | 29 | void onSetData(const GrGLSLProgramDataManager&, const GrFragmentProcessor&) override; |
wangyix | b1daa86 | 2015-08-18 11:29:31 -0700 | [diff] [blame] | 30 | |
ericrk | 0f38612 | 2015-07-21 13:15:47 -0700 | [diff] [blame] | 31 | private: |
Brian Salomon | aee504b | 2017-01-24 12:29:36 -0500 | [diff] [blame] | 32 | UniformHandle fKernelUni; |
Brian Salomon | 5ed3c2f | 2020-04-13 16:51:39 -0400 | [diff] [blame] | 33 | UniformHandle fIncrementUni; |
tomhudson@google.com | d8f856c | 2012-05-10 12:13:36 +0000 | [diff] [blame] | 34 | |
egdaniel | 64c4728 | 2015-11-13 06:54:19 -0800 | [diff] [blame] | 35 | typedef GrGLSLFragmentProcessor INHERITED; |
tomhudson@google.com | d8f856c | 2012-05-10 12:13:36 +0000 | [diff] [blame] | 36 | }; |
| 37 | |
wangyix | 7c157a9 | 2015-07-22 15:08:53 -0700 | [diff] [blame] | 38 | void GrGLConvolutionEffect::emitCode(EmitArgs& args) { |
Brian Salomon | aee504b | 2017-01-24 12:29:36 -0500 | [diff] [blame] | 39 | const GrGaussianConvolutionFragmentProcessor& ce = |
| 40 | args.fFp.cast<GrGaussianConvolutionFragmentProcessor>(); |
robertphillips | bf536af | 2016-02-04 06:11:53 -0800 | [diff] [blame] | 41 | |
egdaniel | 7ea439b | 2015-12-03 09:20:44 -0800 | [diff] [blame] | 42 | GrGLSLUniformHandler* uniformHandler = args.fUniformHandler; |
Brian Salomon | 5ed3c2f | 2020-04-13 16:51:39 -0400 | [diff] [blame] | 43 | |
| 44 | const char* inc; |
| 45 | fIncrementUni = uniformHandler->addUniform(&ce, kFragment_GrShaderFlag, kHalf2_GrSLType, |
| 46 | "Increment", &inc); |
robertphillips | bf536af | 2016-02-04 06:11:53 -0800 | [diff] [blame] | 47 | |
Brian Salomon | b133ffe | 2017-07-27 11:53:21 -0400 | [diff] [blame] | 48 | int width = ce.width(); |
robertphillips | bf536af | 2016-02-04 06:11:53 -0800 | [diff] [blame] | 49 | |
jvanverth | 78d6eb0 | 2016-03-02 13:21:16 -0800 | [diff] [blame] | 50 | int arrayCount = (width + 3) / 4; |
| 51 | SkASSERT(4 * arrayCount >= width); |
| 52 | |
Brian Salomon | 5ed3c2f | 2020-04-13 16:51:39 -0400 | [diff] [blame] | 53 | const char* kernel; |
Ethan Nicholas | 16464c3 | 2020-04-06 13:53:05 -0400 | [diff] [blame] | 54 | fKernelUni = uniformHandler->addUniformArray(&ce, kFragment_GrShaderFlag, kHalf4_GrSLType, |
Brian Salomon | 5ed3c2f | 2020-04-13 16:51:39 -0400 | [diff] [blame] | 55 | "Kernel", arrayCount, &kernel); |
ericrk | 7a787b4 | 2015-07-21 14:06:16 -0700 | [diff] [blame] | 56 | |
cdalton | 8528541 | 2016-02-18 12:37:07 -0800 | [diff] [blame] | 57 | GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder; |
Brian Salomon | 5ed3c2f | 2020-04-13 16:51:39 -0400 | [diff] [blame] | 58 | auto coords2D = fragBuilder->ensureCoords2D(args.fTransformedCoords[0].fVaryingPoint, |
| 59 | ce.sampleMatrix()); |
ericrk | 7a787b4 | 2015-07-21 14:06:16 -0700 | [diff] [blame] | 60 | |
Ethan Nicholas | f7b8820 | 2017-09-18 14:10:39 -0400 | [diff] [blame] | 61 | fragBuilder->codeAppendf("%s = half4(0, 0, 0, 0);", args.fOutputColor); |
ericrk | 7a787b4 | 2015-07-21 14:06:16 -0700 | [diff] [blame] | 62 | |
Brian Salomon | 5ed3c2f | 2020-04-13 16:51:39 -0400 | [diff] [blame] | 63 | fragBuilder->codeAppendf("float2 coord = %s - %d.0 * %s;", coords2D.c_str(), ce.radius(), inc); |
Ethan Nicholas | 8aa4569 | 2017-09-20 11:24:15 -0400 | [diff] [blame] | 64 | fragBuilder->codeAppend("float2 coordSampled = half2(0, 0);"); |
ericrk | 7a787b4 | 2015-07-21 14:06:16 -0700 | [diff] [blame] | 65 | |
| 66 | // Manually unroll loop because some drivers don't; yields 20-30% speedup. |
Brian Salomon | 5ed3c2f | 2020-04-13 16:51:39 -0400 | [diff] [blame] | 67 | static constexpr const char* kVecSuffix[4] = {".x", ".y", ".z", ".w"}; |
ericrk | 7a787b4 | 2015-07-21 14:06:16 -0700 | [diff] [blame] | 68 | for (int i = 0; i < width; i++) { |
ericrk | 7a787b4 | 2015-07-21 14:06:16 -0700 | [diff] [blame] | 69 | SkString kernelIndex; |
Brian Salomon | 5ed3c2f | 2020-04-13 16:51:39 -0400 | [diff] [blame] | 70 | kernelIndex.printf("%s[%d]", kernel, i/4); |
jvanverth | 78d6eb0 | 2016-03-02 13:21:16 -0800 | [diff] [blame] | 71 | kernelIndex.append(kVecSuffix[i & 0x3]); |
ericrk | 7a787b4 | 2015-07-21 14:06:16 -0700 | [diff] [blame] | 72 | |
wutao | 039a7c7 | 2017-06-30 10:44:45 -0700 | [diff] [blame] | 73 | fragBuilder->codeAppend("coordSampled = coord;"); |
Brian Salomon | 5ed3c2f | 2020-04-13 16:51:39 -0400 | [diff] [blame] | 74 | auto sample = this->invokeChild(0, args, "coordSampled"); |
| 75 | fragBuilder->codeAppendf("%s += %s", args.fOutputColor, sample.c_str()); |
| 76 | fragBuilder->codeAppendf(" * %s;", kernelIndex.c_str()); |
| 77 | fragBuilder->codeAppendf("coord += %s;", inc); |
ericrk | 7a787b4 | 2015-07-21 14:06:16 -0700 | [diff] [blame] | 78 | } |
Brian Salomon | 5ed3c2f | 2020-04-13 16:51:39 -0400 | [diff] [blame] | 79 | fragBuilder->codeAppendf("%s *= %s;", args.fOutputColor, args.fInputColor); |
ericrk | 7a787b4 | 2015-07-21 14:06:16 -0700 | [diff] [blame] | 80 | } |
| 81 | |
egdaniel | 018fb62 | 2015-10-28 07:26:40 -0700 | [diff] [blame] | 82 | void GrGLConvolutionEffect::onSetData(const GrGLSLProgramDataManager& pdman, |
Brian Salomon | ab015ef | 2017-04-04 10:15:51 -0400 | [diff] [blame] | 83 | const GrFragmentProcessor& processor) { |
Brian Salomon | 5ed3c2f | 2020-04-13 16:51:39 -0400 | [diff] [blame] | 84 | const auto& conv = processor.cast<GrGaussianConvolutionFragmentProcessor>(); |
robertphillips | bf536af | 2016-02-04 06:11:53 -0800 | [diff] [blame] | 85 | |
Brian Salomon | 5ed3c2f | 2020-04-13 16:51:39 -0400 | [diff] [blame] | 86 | float increment[2] = {}; |
| 87 | increment[static_cast<int>(conv.direction())] = 1; |
| 88 | pdman.set2fv(fIncrementUni, 1, increment); |
Robert Phillips | eaded9d | 2018-05-01 15:17:50 -0400 | [diff] [blame] | 89 | |
Brian Salomon | b133ffe | 2017-07-27 11:53:21 -0400 | [diff] [blame] | 90 | int width = conv.width(); |
jvanverth | 78d6eb0 | 2016-03-02 13:21:16 -0800 | [diff] [blame] | 91 | int arrayCount = (width + 3) / 4; |
| 92 | SkASSERT(4 * arrayCount >= width); |
| 93 | pdman.set4fv(fKernelUni, arrayCount, conv.kernel()); |
ericrk | 7a787b4 | 2015-07-21 14:06:16 -0700 | [diff] [blame] | 94 | } |
| 95 | |
Brian Salomon | 94efbf5 | 2016-11-29 13:43:05 -0500 | [diff] [blame] | 96 | void GrGLConvolutionEffect::GenKey(const GrProcessor& processor, const GrShaderCaps&, |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 97 | GrProcessorKeyBuilder* b) { |
Brian Salomon | 5ed3c2f | 2020-04-13 16:51:39 -0400 | [diff] [blame] | 98 | const auto& conv = processor.cast<GrGaussianConvolutionFragmentProcessor>(); |
| 99 | b->add32(conv.radius()); |
tomhudson@google.com | d8f856c | 2012-05-10 12:13:36 +0000 | [diff] [blame] | 100 | } |
| 101 | |
bsalomon@google.com | b505a12 | 2012-05-31 18:40:36 +0000 | [diff] [blame] | 102 | /////////////////////////////////////////////////////////////////////////////// |
Robert Phillips | 369e8b7 | 2017-08-01 16:13:04 -0400 | [diff] [blame] | 103 | static void fill_in_1D_gaussian_kernel(float* kernel, int width, float gaussianSigma, int radius) { |
Greg Daniel | 4eda8d9 | 2018-04-03 14:03:15 -0400 | [diff] [blame] | 104 | const float twoSigmaSqrd = 2.0f * gaussianSigma * gaussianSigma; |
Greg Daniel | 3aecc30 | 2018-04-03 13:38:01 -0400 | [diff] [blame] | 105 | if (SkScalarNearlyZero(twoSigmaSqrd, SK_ScalarNearlyZero)) { |
| 106 | for (int i = 0; i < width; ++i) { |
| 107 | kernel[i] = 0.0f; |
| 108 | } |
| 109 | return; |
| 110 | } |
| 111 | |
| 112 | const float denom = 1.0f / twoSigmaSqrd; |
Robert Phillips | 40fd7c9 | 2017-01-30 08:06:27 -0500 | [diff] [blame] | 113 | |
| 114 | float sum = 0.0f; |
| 115 | for (int i = 0; i < width; ++i) { |
| 116 | float x = static_cast<float>(i - radius); |
| 117 | // Note that the constant term (1/(sqrt(2*pi*sigma^2)) of the Gaussian |
| 118 | // is dropped here, since we renormalize the kernel below. |
| 119 | kernel[i] = sk_float_exp(-x * x * denom); |
| 120 | sum += kernel[i]; |
| 121 | } |
| 122 | // Normalize the kernel |
| 123 | float scale = 1.0f / sum; |
| 124 | for (int i = 0; i < width; ++i) { |
| 125 | kernel[i] *= scale; |
| 126 | } |
| 127 | } |
| 128 | |
Brian Salomon | 5ed3c2f | 2020-04-13 16:51:39 -0400 | [diff] [blame] | 129 | std::unique_ptr<GrFragmentProcessor> GrGaussianConvolutionFragmentProcessor::Make( |
Greg Daniel | 5c08249 | 2020-01-29 15:06:49 -0500 | [diff] [blame] | 130 | GrSurfaceProxyView view, |
Brian Salomon | fc11844 | 2019-11-22 19:09:27 -0500 | [diff] [blame] | 131 | SkAlphaType alphaType, |
Brian Salomon | 5ed3c2f | 2020-04-13 16:51:39 -0400 | [diff] [blame] | 132 | Direction dir, |
| 133 | int halfWidth, |
| 134 | float gaussianSigma, |
| 135 | GrSamplerState::WrapMode wm, |
Brian Salomon | 88d04cb | 2020-05-06 20:32:25 +0000 | [diff] [blame^] | 136 | const int bounds[2], |
Brian Salomon | 5ed3c2f | 2020-04-13 16:51:39 -0400 | [diff] [blame] | 137 | const GrCaps& caps) { |
| 138 | std::unique_ptr<GrFragmentProcessor> child; |
Brian Salomon | 88d04cb | 2020-05-06 20:32:25 +0000 | [diff] [blame^] | 139 | GrSamplerState sampler; |
| 140 | switch (dir) { |
| 141 | case Direction::kX: sampler.setWrapModeX(wm); break; |
| 142 | case Direction::kY: sampler.setWrapModeY(wm); break; |
| 143 | } |
| 144 | if (bounds) { |
| 145 | SkASSERT(bounds[0] < bounds[1]); |
| 146 | SkRect subset; |
Brian Salomon | 5ed3c2f | 2020-04-13 16:51:39 -0400 | [diff] [blame] | 147 | switch (dir) { |
Brian Salomon | 88d04cb | 2020-05-06 20:32:25 +0000 | [diff] [blame^] | 148 | case Direction::kX: |
| 149 | subset = SkRect::MakeLTRB(bounds[0], 0, bounds[1], view.height()); |
| 150 | break; |
| 151 | case Direction::kY: |
| 152 | subset = SkRect::MakeLTRB(0, bounds[0], view.width(), bounds[1]); |
| 153 | break; |
Brian Salomon | 5ed3c2f | 2020-04-13 16:51:39 -0400 | [diff] [blame] | 154 | } |
| 155 | child = GrTextureEffect::MakeSubset(std::move(view), alphaType, SkMatrix::I(), sampler, |
Brian Salomon | 88d04cb | 2020-05-06 20:32:25 +0000 | [diff] [blame^] | 156 | subset, caps); |
Brian Salomon | 5ed3c2f | 2020-04-13 16:51:39 -0400 | [diff] [blame] | 157 | } else { |
Brian Salomon | 88d04cb | 2020-05-06 20:32:25 +0000 | [diff] [blame^] | 158 | child = GrTextureEffect::Make(std::move(view), alphaType, SkMatrix::I(), sampler, caps); |
Brian Salomon | 5ed3c2f | 2020-04-13 16:51:39 -0400 | [diff] [blame] | 159 | } |
| 160 | return std::unique_ptr<GrFragmentProcessor>(new GrGaussianConvolutionFragmentProcessor( |
| 161 | std::move(child), dir, halfWidth, gaussianSigma)); |
| 162 | } |
| 163 | |
| 164 | GrGaussianConvolutionFragmentProcessor::GrGaussianConvolutionFragmentProcessor( |
| 165 | std::unique_ptr<GrFragmentProcessor> child, |
Brian Salomon | fc11844 | 2019-11-22 19:09:27 -0500 | [diff] [blame] | 166 | Direction direction, |
| 167 | int radius, |
Brian Salomon | 5ed3c2f | 2020-04-13 16:51:39 -0400 | [diff] [blame] | 168 | float gaussianSigma) |
Ethan Nicholas | abff956 | 2017-10-09 10:54:08 -0400 | [diff] [blame] | 169 | : INHERITED(kGrGaussianConvolutionFragmentProcessor_ClassID, |
Brian Salomon | 5ed3c2f | 2020-04-13 16:51:39 -0400 | [diff] [blame] | 170 | ProcessorOptimizationFlags(child.get())) |
Brian Salomon | b133ffe | 2017-07-27 11:53:21 -0400 | [diff] [blame] | 171 | , fRadius(radius) |
Brian Salomon | 5ed3c2f | 2020-04-13 16:51:39 -0400 | [diff] [blame] | 172 | , fDirection(direction) { |
| 173 | child->setSampledWithExplicitCoords(); |
| 174 | this->registerChildProcessor(std::move(child)); |
Brian Salomon | 6862643 | 2020-04-15 12:56:13 +0000 | [diff] [blame] | 175 | SkASSERT(radius <= kMaxKernelRadius); |
Brian Salomon | 6862643 | 2020-04-15 12:56:13 +0000 | [diff] [blame] | 176 | fill_in_1D_gaussian_kernel(fKernel, this->width(), gaussianSigma, this->radius()); |
Brian Salomon | 5ed3c2f | 2020-04-13 16:51:39 -0400 | [diff] [blame] | 177 | this->addCoordTransform(&fCoordTransform); |
tomhudson@google.com | fde2c0a | 2012-07-16 12:23:32 +0000 | [diff] [blame] | 178 | } |
| 179 | |
Brian Salomon | 3f6f965 | 2017-07-28 07:34:05 -0400 | [diff] [blame] | 180 | GrGaussianConvolutionFragmentProcessor::GrGaussianConvolutionFragmentProcessor( |
| 181 | const GrGaussianConvolutionFragmentProcessor& that) |
Ethan Nicholas | abff956 | 2017-10-09 10:54:08 -0400 | [diff] [blame] | 182 | : INHERITED(kGrGaussianConvolutionFragmentProcessor_ClassID, that.optimizationFlags()) |
Brian Salomon | 3f6f965 | 2017-07-28 07:34:05 -0400 | [diff] [blame] | 183 | , fRadius(that.fRadius) |
Brian Salomon | 5ed3c2f | 2020-04-13 16:51:39 -0400 | [diff] [blame] | 184 | , fDirection(that.fDirection) { |
| 185 | auto child = that.childProcessor(0).clone(); |
| 186 | child->setSampledWithExplicitCoords(); |
| 187 | this->registerChildProcessor(std::move(child)); |
Brian Salomon | 6862643 | 2020-04-15 12:56:13 +0000 | [diff] [blame] | 188 | memcpy(fKernel, that.fKernel, that.width() * sizeof(float)); |
Brian Salomon | 5ed3c2f | 2020-04-13 16:51:39 -0400 | [diff] [blame] | 189 | this->addCoordTransform(&fCoordTransform); |
Brian Salomon | 3f6f965 | 2017-07-28 07:34:05 -0400 | [diff] [blame] | 190 | } |
tomhudson@google.com | d8f856c | 2012-05-10 12:13:36 +0000 | [diff] [blame] | 191 | |
Brian Salomon | aee504b | 2017-01-24 12:29:36 -0500 | [diff] [blame] | 192 | void GrGaussianConvolutionFragmentProcessor::onGetGLSLProcessorKey(const GrShaderCaps& caps, |
| 193 | GrProcessorKeyBuilder* b) const { |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 194 | GrGLConvolutionEffect::GenKey(*this, caps, b); |
| 195 | } |
| 196 | |
Brian Salomon | aee504b | 2017-01-24 12:29:36 -0500 | [diff] [blame] | 197 | GrGLSLFragmentProcessor* GrGaussianConvolutionFragmentProcessor::onCreateGLSLInstance() const { |
robertphillips | bf536af | 2016-02-04 06:11:53 -0800 | [diff] [blame] | 198 | return new GrGLConvolutionEffect; |
tomhudson@google.com | d8f856c | 2012-05-10 12:13:36 +0000 | [diff] [blame] | 199 | } |
| 200 | |
Brian Salomon | aee504b | 2017-01-24 12:29:36 -0500 | [diff] [blame] | 201 | bool GrGaussianConvolutionFragmentProcessor::onIsEqual(const GrFragmentProcessor& sBase) const { |
Brian Salomon | 5ed3c2f | 2020-04-13 16:51:39 -0400 | [diff] [blame] | 202 | const auto& that = sBase.cast<GrGaussianConvolutionFragmentProcessor>(); |
| 203 | return this->radius() == that.radius() && this->direction() == that.direction() && |
| 204 | std::equal(fKernel, fKernel + this->width(), that.fKernel); |
tomhudson@google.com | d8f856c | 2012-05-10 12:13:36 +0000 | [diff] [blame] | 205 | } |
bsalomon@google.com | 0a7672f | 2012-08-03 18:12:20 +0000 | [diff] [blame] | 206 | |
| 207 | /////////////////////////////////////////////////////////////////////////////// |
| 208 | |
Brian Salomon | aee504b | 2017-01-24 12:29:36 -0500 | [diff] [blame] | 209 | GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrGaussianConvolutionFragmentProcessor); |
bsalomon@google.com | 0a7672f | 2012-08-03 18:12:20 +0000 | [diff] [blame] | 210 | |
Hal Canary | 6f6961e | 2017-01-31 13:50:44 -0500 | [diff] [blame] | 211 | #if GR_TEST_UTILS |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 212 | std::unique_ptr<GrFragmentProcessor> GrGaussianConvolutionFragmentProcessor::TestCreate( |
Brian Salomon | aee504b | 2017-01-24 12:29:36 -0500 | [diff] [blame] | 213 | GrProcessorTestData* d) { |
Greg Daniel | 026a60c | 2020-02-12 10:53:51 -0500 | [diff] [blame] | 214 | auto [view, ct, at] = d->randomView(); |
Brian Salomon | aee504b | 2017-01-24 12:29:36 -0500 | [diff] [blame] | 215 | |
Brian Salomon | 88d04cb | 2020-05-06 20:32:25 +0000 | [diff] [blame^] | 216 | Direction dir; |
| 217 | int bounds[2]; |
| 218 | do { |
| 219 | if (d->fRandom->nextBool()) { |
| 220 | dir = Direction::kX; |
| 221 | bounds[0] = d->fRandom->nextRangeU(0, view.width() - 1); |
| 222 | bounds[1] = d->fRandom->nextRangeU(0, view.width() - 1); |
| 223 | } else { |
| 224 | dir = Direction::kY; |
| 225 | bounds[0] = d->fRandom->nextRangeU(0, view.height() - 1); |
| 226 | bounds[1] = d->fRandom->nextRangeU(0, view.height() - 1); |
| 227 | } |
| 228 | } while (bounds[0] == bounds[1]); |
| 229 | std::sort(bounds, bounds + 2); |
Brian Salomon | 6862643 | 2020-04-15 12:56:13 +0000 | [diff] [blame] | 230 | |
Brian Salomon | 5ed3c2f | 2020-04-13 16:51:39 -0400 | [diff] [blame] | 231 | auto wm = static_cast<GrSamplerState::WrapMode>( |
| 232 | d->fRandom->nextULessThan(GrSamplerState::kWrapModeCount)); |
Robert Phillips | 08c5ec7 | 2017-01-30 12:26:47 -0500 | [diff] [blame] | 233 | int radius = d->fRandom->nextRangeU(1, kMaxKernelRadius); |
Brian Salomon | aee504b | 2017-01-24 12:29:36 -0500 | [diff] [blame] | 234 | float sigma = radius / 3.f; |
Robert Phillips | 08c5ec7 | 2017-01-30 12:26:47 -0500 | [diff] [blame] | 235 | |
Brian Salomon | 5ed3c2f | 2020-04-13 16:51:39 -0400 | [diff] [blame] | 236 | return GrGaussianConvolutionFragmentProcessor::Make(std::move(view), at, dir, radius, sigma, wm, |
Brian Salomon | 88d04cb | 2020-05-06 20:32:25 +0000 | [diff] [blame^] | 237 | bounds, *d->caps()); |
bsalomon@google.com | 0a7672f | 2012-08-03 18:12:20 +0000 | [diff] [blame] | 238 | } |
Hal Canary | 6f6961e | 2017-01-31 13:50:44 -0500 | [diff] [blame] | 239 | #endif |