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 | |
Brian Salomon | aee504b | 2017-01-24 12:29:36 -0500 | [diff] [blame] | 8 | #include "GrGaussianConvolutionFragmentProcessor.h" |
Robert Phillips | 296b1cc | 2017-03-15 10:42:12 -0400 | [diff] [blame] | 9 | |
Robert Phillips | 40fd7c9 | 2017-01-30 08:06:27 -0500 | [diff] [blame] | 10 | #include "GrProxyMove.h" |
Hal Canary | 6f6961e | 2017-01-31 13:50:44 -0500 | [diff] [blame] | 11 | #include "GrTextureProxy.h" |
Brian Salomon | aee504b | 2017-01-24 12:29:36 -0500 | [diff] [blame] | 12 | #include "../private/GrGLSL.h" |
egdaniel | 64c4728 | 2015-11-13 06:54:19 -0800 | [diff] [blame] | 13 | #include "glsl/GrGLSLFragmentProcessor.h" |
egdaniel | 2d721d3 | 2015-11-11 13:06:05 -0800 | [diff] [blame] | 14 | #include "glsl/GrGLSLFragmentShaderBuilder.h" |
egdaniel | 018fb62 | 2015-10-28 07:26:40 -0700 | [diff] [blame] | 15 | #include "glsl/GrGLSLProgramDataManager.h" |
egdaniel | 7ea439b | 2015-12-03 09:20:44 -0800 | [diff] [blame] | 16 | #include "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 |
egdaniel | 018fb62 | 2015-10-28 07:26:40 -0700 | [diff] [blame] | 19 | typedef GrGLSLProgramDataManager::UniformHandle UniformHandle; |
bsalomon@google.com | 032b221 | 2012-07-16 13:36:18 +0000 | [diff] [blame] | 20 | |
egdaniel | 64c4728 | 2015-11-13 06:54:19 -0800 | [diff] [blame] | 21 | class GrGLConvolutionEffect : public GrGLSLFragmentProcessor { |
tomhudson@google.com | d8f856c | 2012-05-10 12:13:36 +0000 | [diff] [blame] | 22 | public: |
robertphillips | 9cdb992 | 2016-02-03 12:25:40 -0800 | [diff] [blame] | 23 | void emitCode(EmitArgs&) override; |
ericrk | 7a787b4 | 2015-07-21 14:06:16 -0700 | [diff] [blame] | 24 | |
Brian Salomon | 94efbf5 | 2016-11-29 13:43:05 -0500 | [diff] [blame] | 25 | static inline void GenKey(const GrProcessor&, const GrShaderCaps&, GrProcessorKeyBuilder*); |
tomhudson@google.com | d8f856c | 2012-05-10 12:13:36 +0000 | [diff] [blame] | 26 | |
wangyix | b1daa86 | 2015-08-18 11:29:31 -0700 | [diff] [blame] | 27 | protected: |
Brian Salomon | ab015ef | 2017-04-04 10:15:51 -0400 | [diff] [blame^] | 28 | void onSetData(const GrGLSLProgramDataManager&, const GrFragmentProcessor&) override; |
wangyix | b1daa86 | 2015-08-18 11:29:31 -0700 | [diff] [blame] | 29 | |
ericrk | 0f38612 | 2015-07-21 13:15:47 -0700 | [diff] [blame] | 30 | private: |
Brian Salomon | aee504b | 2017-01-24 12:29:36 -0500 | [diff] [blame] | 31 | UniformHandle fKernelUni; |
| 32 | UniformHandle fImageIncrementUni; |
| 33 | UniformHandle fBoundsUni; |
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 | aee504b | 2017-01-24 12:29:36 -0500 | [diff] [blame] | 43 | fImageIncrementUni = uniformHandler->addUniform(kFragment_GrShaderFlag, kVec2f_GrSLType, |
| 44 | kDefault_GrSLPrecision, "ImageIncrement"); |
robertphillips | bf536af | 2016-02-04 06:11:53 -0800 | [diff] [blame] | 45 | if (ce.useBounds()) { |
Brian Salomon | aee504b | 2017-01-24 12:29:36 -0500 | [diff] [blame] | 46 | fBoundsUni = uniformHandler->addUniform(kFragment_GrShaderFlag, kVec2f_GrSLType, |
| 47 | kDefault_GrSLPrecision, "Bounds"); |
ericrk | 7a787b4 | 2015-07-21 14:06:16 -0700 | [diff] [blame] | 48 | } |
robertphillips | bf536af | 2016-02-04 06:11:53 -0800 | [diff] [blame] | 49 | |
| 50 | int width = Gr1DKernelEffect::WidthFromRadius(ce.radius()); |
| 51 | |
jvanverth | 78d6eb0 | 2016-03-02 13:21:16 -0800 | [diff] [blame] | 52 | int arrayCount = (width + 3) / 4; |
| 53 | SkASSERT(4 * arrayCount >= width); |
| 54 | |
Brian Salomon | aee504b | 2017-01-24 12:29:36 -0500 | [diff] [blame] | 55 | fKernelUni = uniformHandler->addUniformArray(kFragment_GrShaderFlag, kVec4f_GrSLType, |
| 56 | kDefault_GrSLPrecision, "Kernel", arrayCount); |
ericrk | 7a787b4 | 2015-07-21 14:06:16 -0700 | [diff] [blame] | 57 | |
cdalton | 8528541 | 2016-02-18 12:37:07 -0800 | [diff] [blame] | 58 | GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder; |
bsalomon | 1a1aa93 | 2016-09-12 09:30:36 -0700 | [diff] [blame] | 59 | SkString coords2D = fragBuilder->ensureCoords2D(args.fTransformedCoords[0]); |
ericrk | 7a787b4 | 2015-07-21 14:06:16 -0700 | [diff] [blame] | 60 | |
robertphillips | bf536af | 2016-02-04 06:11:53 -0800 | [diff] [blame] | 61 | fragBuilder->codeAppendf("%s = vec4(0, 0, 0, 0);", args.fOutputColor); |
ericrk | 7a787b4 | 2015-07-21 14:06:16 -0700 | [diff] [blame] | 62 | |
Brian Salomon | 99938a8 | 2016-11-21 13:41:08 -0500 | [diff] [blame] | 63 | const GrShaderVar& kernel = uniformHandler->getUniformVariable(fKernelUni); |
egdaniel | 7ea439b | 2015-12-03 09:20:44 -0800 | [diff] [blame] | 64 | const char* imgInc = uniformHandler->getUniformCStr(fImageIncrementUni); |
ericrk | 7a787b4 | 2015-07-21 14:06:16 -0700 | [diff] [blame] | 65 | |
robertphillips | bf536af | 2016-02-04 06:11:53 -0800 | [diff] [blame] | 66 | fragBuilder->codeAppendf("vec2 coord = %s - %d.0 * %s;", coords2D.c_str(), ce.radius(), imgInc); |
ericrk | 7a787b4 | 2015-07-21 14:06:16 -0700 | [diff] [blame] | 67 | |
| 68 | // Manually unroll loop because some drivers don't; yields 20-30% speedup. |
Brian Salomon | aee504b | 2017-01-24 12:29:36 -0500 | [diff] [blame] | 69 | const char* kVecSuffix[4] = {".x", ".y", ".z", ".w"}; |
ericrk | 7a787b4 | 2015-07-21 14:06:16 -0700 | [diff] [blame] | 70 | for (int i = 0; i < width; i++) { |
| 71 | SkString index; |
| 72 | SkString kernelIndex; |
Brian Salomon | aee504b | 2017-01-24 12:29:36 -0500 | [diff] [blame] | 73 | index.appendS32(i / 4); |
ericrk | 7a787b4 | 2015-07-21 14:06:16 -0700 | [diff] [blame] | 74 | kernel.appendArrayAccess(index.c_str(), &kernelIndex); |
jvanverth | 78d6eb0 | 2016-03-02 13:21:16 -0800 | [diff] [blame] | 75 | kernelIndex.append(kVecSuffix[i & 0x3]); |
ericrk | 7a787b4 | 2015-07-21 14:06:16 -0700 | [diff] [blame] | 76 | |
robertphillips | bf536af | 2016-02-04 06:11:53 -0800 | [diff] [blame] | 77 | if (ce.useBounds()) { |
ericrk | 7a787b4 | 2015-07-21 14:06:16 -0700 | [diff] [blame] | 78 | // We used to compute a bool indicating whether we're in bounds or not, cast it to a |
| 79 | // float, and then mul weight*texture_sample by the float. However, the Adreno 430 seems |
| 80 | // to have a bug that caused corruption. |
egdaniel | 7ea439b | 2015-12-03 09:20:44 -0800 | [diff] [blame] | 81 | const char* bounds = uniformHandler->getUniformCStr(fBoundsUni); |
robertphillips | bf536af | 2016-02-04 06:11:53 -0800 | [diff] [blame] | 82 | const char* component = ce.direction() == Gr1DKernelEffect::kY_Direction ? "y" : "x"; |
Brian Salomon | aee504b | 2017-01-24 12:29:36 -0500 | [diff] [blame] | 83 | fragBuilder->codeAppendf("if (coord.%s >= %s.x && coord.%s <= %s.y) {", component, |
| 84 | bounds, component, bounds); |
ericrk | 7a787b4 | 2015-07-21 14:06:16 -0700 | [diff] [blame] | 85 | } |
Brian Salomon | aee504b | 2017-01-24 12:29:36 -0500 | [diff] [blame] | 86 | fragBuilder->codeAppendf("%s += ", args.fOutputColor); |
cdalton | 3f6f76f | 2016-04-11 12:18:09 -0700 | [diff] [blame] | 87 | fragBuilder->appendTextureLookup(args.fTexSamplers[0], "coord"); |
egdaniel | 4ca2e60 | 2015-11-18 08:01:26 -0800 | [diff] [blame] | 88 | fragBuilder->codeAppendf(" * %s;\n", kernelIndex.c_str()); |
robertphillips | bf536af | 2016-02-04 06:11:53 -0800 | [diff] [blame] | 89 | if (ce.useBounds()) { |
egdaniel | 4ca2e60 | 2015-11-18 08:01:26 -0800 | [diff] [blame] | 90 | fragBuilder->codeAppend("}"); |
ericrk | 7a787b4 | 2015-07-21 14:06:16 -0700 | [diff] [blame] | 91 | } |
Brian Salomon | aee504b | 2017-01-24 12:29:36 -0500 | [diff] [blame] | 92 | fragBuilder->codeAppendf("coord += %s;\n", imgInc); |
ericrk | 7a787b4 | 2015-07-21 14:06:16 -0700 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | SkString modulate; |
wangyix | 7c157a9 | 2015-07-22 15:08:53 -0700 | [diff] [blame] | 96 | GrGLSLMulVarBy4f(&modulate, args.fOutputColor, args.fInputColor); |
egdaniel | 4ca2e60 | 2015-11-18 08:01:26 -0800 | [diff] [blame] | 97 | fragBuilder->codeAppend(modulate.c_str()); |
ericrk | 7a787b4 | 2015-07-21 14:06:16 -0700 | [diff] [blame] | 98 | } |
| 99 | |
egdaniel | 018fb62 | 2015-10-28 07:26:40 -0700 | [diff] [blame] | 100 | void GrGLConvolutionEffect::onSetData(const GrGLSLProgramDataManager& pdman, |
Brian Salomon | ab015ef | 2017-04-04 10:15:51 -0400 | [diff] [blame^] | 101 | const GrFragmentProcessor& processor) { |
Brian Salomon | aee504b | 2017-01-24 12:29:36 -0500 | [diff] [blame] | 102 | const GrGaussianConvolutionFragmentProcessor& conv = |
| 103 | processor.cast<GrGaussianConvolutionFragmentProcessor>(); |
Brian Salomon | db4183d | 2016-11-17 12:48:40 -0500 | [diff] [blame] | 104 | GrTexture& texture = *conv.textureSampler(0).texture(); |
robertphillips | bf536af | 2016-02-04 06:11:53 -0800 | [diff] [blame] | 105 | |
Brian Salomon | aee504b | 2017-01-24 12:29:36 -0500 | [diff] [blame] | 106 | float imageIncrement[2] = {0}; |
ericrk | 7a787b4 | 2015-07-21 14:06:16 -0700 | [diff] [blame] | 107 | float ySign = texture.origin() != kTopLeft_GrSurfaceOrigin ? 1.0f : -1.0f; |
| 108 | switch (conv.direction()) { |
| 109 | case Gr1DKernelEffect::kX_Direction: |
| 110 | imageIncrement[0] = 1.0f / texture.width(); |
| 111 | break; |
| 112 | case Gr1DKernelEffect::kY_Direction: |
| 113 | imageIncrement[1] = ySign / texture.height(); |
| 114 | break; |
| 115 | default: |
| 116 | SkFAIL("Unknown filter direction."); |
| 117 | } |
| 118 | pdman.set2fv(fImageIncrementUni, 1, imageIncrement); |
| 119 | if (conv.useBounds()) { |
Robert Phillips | 08c5ec7 | 2017-01-30 12:26:47 -0500 | [diff] [blame] | 120 | const int* bounds = conv.bounds(); |
| 121 | if (Gr1DKernelEffect::kX_Direction == conv.direction()) { |
| 122 | SkScalar inv = SkScalarInvert(SkIntToScalar(texture.width())); |
| 123 | pdman.set2f(fBoundsUni, inv * bounds[0], inv * bounds[1]); |
ericrk | 7a787b4 | 2015-07-21 14:06:16 -0700 | [diff] [blame] | 124 | } else { |
Robert Phillips | 08c5ec7 | 2017-01-30 12:26:47 -0500 | [diff] [blame] | 125 | SkScalar inv = SkScalarInvert(SkIntToScalar(texture.height())); |
| 126 | if (texture.origin() != kTopLeft_GrSurfaceOrigin) { |
| 127 | pdman.set2f(fBoundsUni, 1.0f - (inv * bounds[1]), 1.0f - (inv * bounds[0])); |
| 128 | } else { |
| 129 | pdman.set2f(fBoundsUni, inv * bounds[1], inv * bounds[0]); |
| 130 | } |
ericrk | 7a787b4 | 2015-07-21 14:06:16 -0700 | [diff] [blame] | 131 | } |
| 132 | } |
robertphillips | bf536af | 2016-02-04 06:11:53 -0800 | [diff] [blame] | 133 | int width = Gr1DKernelEffect::WidthFromRadius(conv.radius()); |
| 134 | |
jvanverth | 78d6eb0 | 2016-03-02 13:21:16 -0800 | [diff] [blame] | 135 | int arrayCount = (width + 3) / 4; |
| 136 | SkASSERT(4 * arrayCount >= width); |
| 137 | pdman.set4fv(fKernelUni, arrayCount, conv.kernel()); |
ericrk | 7a787b4 | 2015-07-21 14:06:16 -0700 | [diff] [blame] | 138 | } |
| 139 | |
Brian Salomon | 94efbf5 | 2016-11-29 13:43:05 -0500 | [diff] [blame] | 140 | void GrGLConvolutionEffect::GenKey(const GrProcessor& processor, const GrShaderCaps&, |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 141 | GrProcessorKeyBuilder* b) { |
Brian Salomon | aee504b | 2017-01-24 12:29:36 -0500 | [diff] [blame] | 142 | const GrGaussianConvolutionFragmentProcessor& conv = |
| 143 | processor.cast<GrGaussianConvolutionFragmentProcessor>(); |
bsalomon | 63e99f7 | 2014-07-21 08:03:14 -0700 | [diff] [blame] | 144 | uint32_t key = conv.radius(); |
senorblanco@chromium.org | e8232bc | 2013-07-29 18:45:44 +0000 | [diff] [blame] | 145 | key <<= 2; |
| 146 | if (conv.useBounds()) { |
| 147 | key |= 0x2; |
Brian Salomon | aee504b | 2017-01-24 12:29:36 -0500 | [diff] [blame] | 148 | key |= GrGaussianConvolutionFragmentProcessor::kY_Direction == conv.direction() ? 0x1 : 0x0; |
senorblanco@chromium.org | e8232bc | 2013-07-29 18:45:44 +0000 | [diff] [blame] | 149 | } |
bsalomon | 63e99f7 | 2014-07-21 08:03:14 -0700 | [diff] [blame] | 150 | b->add32(key); |
tomhudson@google.com | d8f856c | 2012-05-10 12:13:36 +0000 | [diff] [blame] | 151 | } |
| 152 | |
bsalomon@google.com | b505a12 | 2012-05-31 18:40:36 +0000 | [diff] [blame] | 153 | /////////////////////////////////////////////////////////////////////////////// |
Robert Phillips | 40fd7c9 | 2017-01-30 08:06:27 -0500 | [diff] [blame] | 154 | static void fill_in_1D_guassian_kernel(float* kernel, int width, float gaussianSigma, int radius) { |
| 155 | const float denom = 1.0f / (2.0f * gaussianSigma * gaussianSigma); |
| 156 | |
| 157 | float sum = 0.0f; |
| 158 | for (int i = 0; i < width; ++i) { |
| 159 | float x = static_cast<float>(i - radius); |
| 160 | // Note that the constant term (1/(sqrt(2*pi*sigma^2)) of the Gaussian |
| 161 | // is dropped here, since we renormalize the kernel below. |
| 162 | kernel[i] = sk_float_exp(-x * x * denom); |
| 163 | sum += kernel[i]; |
| 164 | } |
| 165 | // Normalize the kernel |
| 166 | float scale = 1.0f / sum; |
| 167 | for (int i = 0; i < width; ++i) { |
| 168 | kernel[i] *= scale; |
| 169 | } |
| 170 | } |
| 171 | |
Robert Phillips | 40fd7c9 | 2017-01-30 08:06:27 -0500 | [diff] [blame] | 172 | GrGaussianConvolutionFragmentProcessor::GrGaussianConvolutionFragmentProcessor( |
Robert Phillips | 296b1cc | 2017-03-15 10:42:12 -0400 | [diff] [blame] | 173 | GrResourceProvider* resourceProvider, |
| 174 | sk_sp<GrTextureProxy> proxy, |
| 175 | Direction direction, |
| 176 | int radius, |
| 177 | float gaussianSigma, |
| 178 | bool useBounds, |
| 179 | int bounds[2]) |
| 180 | : INHERITED{resourceProvider, |
Robert Phillips | 40fd7c9 | 2017-01-30 08:06:27 -0500 | [diff] [blame] | 181 | ModulationFlags(proxy->config()), |
| 182 | GR_PROXY_MOVE(proxy), |
| 183 | direction, |
| 184 | radius} |
| 185 | , fUseBounds(useBounds) { |
| 186 | this->initClassID<GrGaussianConvolutionFragmentProcessor>(); |
| 187 | SkASSERT(radius <= kMaxKernelRadius); |
| 188 | |
| 189 | fill_in_1D_guassian_kernel(fKernel, this->width(), gaussianSigma, this->radius()); |
| 190 | |
senorblanco@chromium.org | e8232bc | 2013-07-29 18:45:44 +0000 | [diff] [blame] | 191 | memcpy(fBounds, bounds, sizeof(fBounds)); |
tomhudson@google.com | fde2c0a | 2012-07-16 12:23:32 +0000 | [diff] [blame] | 192 | } |
| 193 | |
Brian Salomon | aee504b | 2017-01-24 12:29:36 -0500 | [diff] [blame] | 194 | GrGaussianConvolutionFragmentProcessor::~GrGaussianConvolutionFragmentProcessor() {} |
tomhudson@google.com | d8f856c | 2012-05-10 12:13:36 +0000 | [diff] [blame] | 195 | |
Brian Salomon | aee504b | 2017-01-24 12:29:36 -0500 | [diff] [blame] | 196 | void GrGaussianConvolutionFragmentProcessor::onGetGLSLProcessorKey(const GrShaderCaps& caps, |
| 197 | GrProcessorKeyBuilder* b) const { |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 198 | GrGLConvolutionEffect::GenKey(*this, caps, b); |
| 199 | } |
| 200 | |
Brian Salomon | aee504b | 2017-01-24 12:29:36 -0500 | [diff] [blame] | 201 | GrGLSLFragmentProcessor* GrGaussianConvolutionFragmentProcessor::onCreateGLSLInstance() const { |
robertphillips | bf536af | 2016-02-04 06:11:53 -0800 | [diff] [blame] | 202 | return new GrGLConvolutionEffect; |
tomhudson@google.com | d8f856c | 2012-05-10 12:13:36 +0000 | [diff] [blame] | 203 | } |
| 204 | |
Brian Salomon | aee504b | 2017-01-24 12:29:36 -0500 | [diff] [blame] | 205 | bool GrGaussianConvolutionFragmentProcessor::onIsEqual(const GrFragmentProcessor& sBase) const { |
| 206 | const GrGaussianConvolutionFragmentProcessor& s = |
| 207 | sBase.cast<GrGaussianConvolutionFragmentProcessor>(); |
| 208 | return (this->radius() == s.radius() && this->direction() == s.direction() && |
senorblanco@chromium.org | e8232bc | 2013-07-29 18:45:44 +0000 | [diff] [blame] | 209 | this->useBounds() == s.useBounds() && |
| 210 | 0 == memcmp(fBounds, s.fBounds, sizeof(fBounds)) && |
tomhudson@google.com | d0c1a06 | 2012-07-12 17:23:52 +0000 | [diff] [blame] | 211 | 0 == memcmp(fKernel, s.fKernel, this->width() * sizeof(float))); |
tomhudson@google.com | d8f856c | 2012-05-10 12:13:36 +0000 | [diff] [blame] | 212 | } |
bsalomon@google.com | 0a7672f | 2012-08-03 18:12:20 +0000 | [diff] [blame] | 213 | |
| 214 | /////////////////////////////////////////////////////////////////////////////// |
| 215 | |
Brian Salomon | aee504b | 2017-01-24 12:29:36 -0500 | [diff] [blame] | 216 | GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrGaussianConvolutionFragmentProcessor); |
bsalomon@google.com | 0a7672f | 2012-08-03 18:12:20 +0000 | [diff] [blame] | 217 | |
Hal Canary | 6f6961e | 2017-01-31 13:50:44 -0500 | [diff] [blame] | 218 | #if GR_TEST_UTILS |
Brian Salomon | aee504b | 2017-01-24 12:29:36 -0500 | [diff] [blame] | 219 | sk_sp<GrFragmentProcessor> GrGaussianConvolutionFragmentProcessor::TestCreate( |
| 220 | GrProcessorTestData* d) { |
| 221 | int texIdx = d->fRandom->nextBool() ? GrProcessorUnitTest::kSkiaPMTextureIdx |
| 222 | : GrProcessorUnitTest::kAlphaTextureIdx; |
Robert Phillips | 08c5ec7 | 2017-01-30 12:26:47 -0500 | [diff] [blame] | 223 | sk_sp<GrTextureProxy> proxy = d->textureProxy(texIdx); |
Brian Salomon | aee504b | 2017-01-24 12:29:36 -0500 | [diff] [blame] | 224 | |
| 225 | bool useBounds = d->fRandom->nextBool(); |
Robert Phillips | 08c5ec7 | 2017-01-30 12:26:47 -0500 | [diff] [blame] | 226 | int bounds[2]; |
| 227 | |
| 228 | Direction dir; |
| 229 | if (d->fRandom->nextBool()) { |
| 230 | dir = kX_Direction; |
| 231 | bounds[0] = d->fRandom->nextRangeU(0, proxy->width()-1); |
| 232 | bounds[1] = d->fRandom->nextRangeU(bounds[0], proxy->width()-1); |
| 233 | } else { |
| 234 | dir = kY_Direction; |
| 235 | bounds[0] = d->fRandom->nextRangeU(0, proxy->height()-1); |
| 236 | bounds[1] = d->fRandom->nextRangeU(bounds[0], proxy->height()-1); |
senorblanco@chromium.org | 194d775 | 2013-07-24 22:19:24 +0000 | [diff] [blame] | 237 | } |
bsalomon@google.com | 0a7672f | 2012-08-03 18:12:20 +0000 | [diff] [blame] | 238 | |
Robert Phillips | 08c5ec7 | 2017-01-30 12:26:47 -0500 | [diff] [blame] | 239 | int radius = d->fRandom->nextRangeU(1, kMaxKernelRadius); |
Brian Salomon | aee504b | 2017-01-24 12:29:36 -0500 | [diff] [blame] | 240 | float sigma = radius / 3.f; |
Robert Phillips | 08c5ec7 | 2017-01-30 12:26:47 -0500 | [diff] [blame] | 241 | |
Brian Salomon | aee504b | 2017-01-24 12:29:36 -0500 | [diff] [blame] | 242 | return GrGaussianConvolutionFragmentProcessor::Make( |
Robert Phillips | 296b1cc | 2017-03-15 10:42:12 -0400 | [diff] [blame] | 243 | d->resourceProvider(), d->textureProxy(texIdx), |
| 244 | dir, radius, sigma, useBounds, bounds); |
bsalomon@google.com | 0a7672f | 2012-08-03 18:12:20 +0000 | [diff] [blame] | 245 | } |
Hal Canary | 6f6961e | 2017-01-31 13:50:44 -0500 | [diff] [blame] | 246 | #endif |