blob: 5a825f49f5c599481358da1f8729c7cf757d48da [file] [log] [blame]
robertphillips30c4cae2015-09-15 10:20:55 -07001/*
Ethan Nicholasceb4d482017-07-10 15:40:20 -04002 * Copyright 2017 Google Inc.
robertphillips30c4cae2015-09-15 10:20:55 -07003 *
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 Nicholasceb4d482017-07-10 15:40:20 -04008/*
Brian Salomoncda20152017-07-17 16:44:32 -04009 * This file was autogenerated from GrCircleBlurFragmentProcessor.fp; do not modify.
Ethan Nicholasceb4d482017-07-10 15:40:20 -040010 */
robertphillips30c4cae2015-09-15 10:20:55 -070011#include "GrCircleBlurFragmentProcessor.h"
robertphillips30c4cae2015-09-15 10:20:55 -070012#if SK_SUPPORT_GPU
13
Ethan Nicholasb7e8c3b2017-07-19 13:54:20 -040014#include "GrResourceProvider.h"
Ethan Nicholas818ac5a2017-07-10 13:12:07 +000015
Ethan Nicholas5b5f0962017-09-11 13:50:14 -070016// Computes an unnormalized half kernel (right side). Returns the summation of all the half
17// kernel values.
Ethan Nicholasb7e8c3b2017-07-19 13:54:20 -040018static float make_unnormalized_half_kernel(float* halfKernel, int halfKernelSize, float sigma) {
19 const float invSigma = 1.f / sigma;
20 const float b = -0.5f * invSigma * invSigma;
21 float tot = 0.0f;
Ethan Nicholas5b5f0962017-09-11 13:50:14 -070022 // Compute half kernel values at half pixel steps out from the center.
Ethan Nicholasb7e8c3b2017-07-19 13:54:20 -040023 float t = 0.5f;
24 for (int i = 0; i < halfKernelSize; ++i) {
25 float value = expf(t * t * b);
26 tot += value;
27 halfKernel[i] = value;
28 t += 1.f;
Ethan Nicholasceb4d482017-07-10 15:40:20 -040029 }
Ethan Nicholasb7e8c3b2017-07-19 13:54:20 -040030 return tot;
31}
Ethan Nicholasceb4d482017-07-10 15:40:20 -040032
Ethan Nicholas5b5f0962017-09-11 13:50:14 -070033// Create a Gaussian half-kernel (right side) and a summed area table given a sigma and number
34// of discrete steps. The half kernel is normalized to sum to 0.5.
Ethan Nicholasb7e8c3b2017-07-19 13:54:20 -040035static void make_half_kernel_and_summed_table(float* halfKernel, float* summedHalfKernel,
36 int halfKernelSize, float sigma) {
Ethan Nicholas5b5f0962017-09-11 13:50:14 -070037 // The half kernel should sum to 0.5 not 1.0.
Ethan Nicholasb7e8c3b2017-07-19 13:54:20 -040038 const float tot = 2.f * make_unnormalized_half_kernel(halfKernel, halfKernelSize, sigma);
39 float sum = 0.f;
40 for (int i = 0; i < halfKernelSize; ++i) {
41 halfKernel[i] /= tot;
42 sum += halfKernel[i];
43 summedHalfKernel[i] = sum;
Ethan Nicholasceb4d482017-07-10 15:40:20 -040044 }
Ethan Nicholasb7e8c3b2017-07-19 13:54:20 -040045}
Ethan Nicholasceb4d482017-07-10 15:40:20 -040046
Ethan Nicholas5b5f0962017-09-11 13:50:14 -070047// Applies the 1D half kernel vertically at points along the x axis to a circle centered at the
48// origin with radius circleR.
Ethan Nicholasb7e8c3b2017-07-19 13:54:20 -040049void apply_kernel_in_y(float* results, int numSteps, float firstX, float circleR,
50 int halfKernelSize, const float* summedHalfKernelTable) {
51 float x = firstX;
52 for (int i = 0; i < numSteps; ++i, x += 1.f) {
53 if (x < -circleR || x > circleR) {
54 results[i] = 0;
55 continue;
Brian Salomoncda20152017-07-17 16:44:32 -040056 }
Ethan Nicholasb7e8c3b2017-07-19 13:54:20 -040057 float y = sqrtf(circleR * circleR - x * x);
Ethan Nicholas5b5f0962017-09-11 13:50:14 -070058 // In the column at x we exit the circle at +y and -y
59 // The summed table entry j is actually reflects an offset of j + 0.5.
Ethan Nicholasb7e8c3b2017-07-19 13:54:20 -040060 y -= 0.5f;
61 int yInt = SkScalarFloorToInt(y);
62 SkASSERT(yInt >= -1);
63 if (y < 0) {
64 results[i] = (y + 0.5f) * summedHalfKernelTable[0];
65 } else if (yInt >= halfKernelSize - 1) {
66 results[i] = 0.5f;
Brian Salomoncda20152017-07-17 16:44:32 -040067 } else {
Ethan Nicholasb7e8c3b2017-07-19 13:54:20 -040068 float yFrac = y - yInt;
69 results[i] = (1.f - yFrac) * summedHalfKernelTable[yInt] +
70 yFrac * summedHalfKernelTable[yInt + 1];
Brian Salomoncda20152017-07-17 16:44:32 -040071 }
Ethan Nicholasb7e8c3b2017-07-19 13:54:20 -040072 }
73}
Brian Salomoncda20152017-07-17 16:44:32 -040074
Ethan Nicholas5b5f0962017-09-11 13:50:14 -070075// Apply a Gaussian at point (evalX, 0) to a circle centered at the origin with radius circleR.
76// This relies on having a half kernel computed for the Gaussian and a table of applications of
77// the half kernel in y to columns at (evalX - halfKernel, evalX - halfKernel + 1, ..., evalX +
78// halfKernel) passed in as yKernelEvaluations.
Ethan Nicholasb7e8c3b2017-07-19 13:54:20 -040079static uint8_t eval_at(float evalX, float circleR, const float* halfKernel, int halfKernelSize,
80 const float* yKernelEvaluations) {
81 float acc = 0;
Brian Salomoncda20152017-07-17 16:44:32 -040082
Ethan Nicholasb7e8c3b2017-07-19 13:54:20 -040083 float x = evalX - halfKernelSize;
84 for (int i = 0; i < halfKernelSize; ++i, x += 1.f) {
85 if (x < -circleR || x > circleR) {
86 continue;
Brian Salomoncda20152017-07-17 16:44:32 -040087 }
Ethan Nicholasb7e8c3b2017-07-19 13:54:20 -040088 float verticalEval = yKernelEvaluations[i];
89 acc += verticalEval * halfKernel[halfKernelSize - i - 1];
90 }
91 for (int i = 0; i < halfKernelSize; ++i, x += 1.f) {
92 if (x < -circleR || x > circleR) {
93 continue;
94 }
95 float verticalEval = yKernelEvaluations[i + halfKernelSize];
96 acc += verticalEval * halfKernel[i];
Brian Salomoncda20152017-07-17 16:44:32 -040097 }
Ethan Nicholas5b5f0962017-09-11 13:50:14 -070098 // Since we applied a half kernel in y we multiply acc by 2 (the circle is symmetric about
99 // the x axis).
Ethan Nicholasb7e8c3b2017-07-19 13:54:20 -0400100 return SkUnitScalarClampToByte(2.f * acc);
101}
102
Ethan Nicholas5b5f0962017-09-11 13:50:14 -0700103// This function creates a profile of a blurred circle. It does this by computing a kernel for
104// half the Gaussian and a matching summed area table. The summed area table is used to compute
105// an array of vertical applications of the half kernel to the circle along the x axis. The
106// table of y evaluations has 2 * k + n entries where k is the size of the half kernel and n is
107// the size of the profile being computed. Then for each of the n profile entries we walk out k
108// steps in each horizontal direction multiplying the corresponding y evaluation by the half
109// kernel entry and sum these values to compute the profile entry.
Ethan Nicholasb7e8c3b2017-07-19 13:54:20 -0400110static uint8_t* create_circle_profile(float sigma, float circleR, int profileTextureWidth) {
111 const int numSteps = profileTextureWidth;
112 uint8_t* weights = new uint8_t[numSteps];
113
Ethan Nicholas5b5f0962017-09-11 13:50:14 -0700114 // The full kernel is 6 sigmas wide.
Ethan Nicholasb7e8c3b2017-07-19 13:54:20 -0400115 int halfKernelSize = SkScalarCeilToInt(6.0f * sigma);
Ethan Nicholas5b5f0962017-09-11 13:50:14 -0700116 // round up to next multiple of 2 and then divide by 2
Ethan Nicholasb7e8c3b2017-07-19 13:54:20 -0400117 halfKernelSize = ((halfKernelSize + 1) & ~1) >> 1;
118
Ethan Nicholas5b5f0962017-09-11 13:50:14 -0700119 // Number of x steps at which to apply kernel in y to cover all the profile samples in x.
Ethan Nicholasb7e8c3b2017-07-19 13:54:20 -0400120 int numYSteps = numSteps + 2 * halfKernelSize;
121
122 SkAutoTArray<float> bulkAlloc(halfKernelSize + halfKernelSize + numYSteps);
123 float* halfKernel = bulkAlloc.get();
124 float* summedKernel = bulkAlloc.get() + halfKernelSize;
125 float* yEvals = bulkAlloc.get() + 2 * halfKernelSize;
126 make_half_kernel_and_summed_table(halfKernel, summedKernel, halfKernelSize, sigma);
127
128 float firstX = -halfKernelSize + 0.5f;
129 apply_kernel_in_y(yEvals, numYSteps, firstX, circleR, halfKernelSize, summedKernel);
130
131 for (int i = 0; i < numSteps - 1; ++i) {
132 float evalX = i + 0.5f;
133 weights[i] = eval_at(evalX, circleR, halfKernel, halfKernelSize, yEvals + i);
134 }
Ethan Nicholas5b5f0962017-09-11 13:50:14 -0700135 // Ensure the tail of the Gaussian goes to zero.
Ethan Nicholasb7e8c3b2017-07-19 13:54:20 -0400136 weights[numSteps - 1] = 0;
137 return weights;
138}
139
140static uint8_t* create_half_plane_profile(int profileWidth) {
141 SkASSERT(!(profileWidth & 0x1));
Ethan Nicholas5b5f0962017-09-11 13:50:14 -0700142 // The full kernel is 6 sigmas wide.
Ethan Nicholasb7e8c3b2017-07-19 13:54:20 -0400143 float sigma = profileWidth / 6.f;
144 int halfKernelSize = profileWidth / 2;
145
146 SkAutoTArray<float> halfKernel(halfKernelSize);
147 uint8_t* profile = new uint8_t[profileWidth];
148
Ethan Nicholas5b5f0962017-09-11 13:50:14 -0700149 // The half kernel should sum to 0.5.
Ethan Nicholasb7e8c3b2017-07-19 13:54:20 -0400150 const float tot = 2.f * make_unnormalized_half_kernel(halfKernel.get(), halfKernelSize, sigma);
151 float sum = 0.f;
Ethan Nicholas5b5f0962017-09-11 13:50:14 -0700152 // Populate the profile from the right edge to the middle.
Ethan Nicholasb7e8c3b2017-07-19 13:54:20 -0400153 for (int i = 0; i < halfKernelSize; ++i) {
154 halfKernel[halfKernelSize - i - 1] /= tot;
155 sum += halfKernel[halfKernelSize - i - 1];
156 profile[profileWidth - i - 1] = SkUnitScalarClampToByte(sum);
157 }
Ethan Nicholas5b5f0962017-09-11 13:50:14 -0700158 // Populate the profile from the middle to the left edge (by flipping the half kernel and
159 // continuing the summation).
Ethan Nicholasb7e8c3b2017-07-19 13:54:20 -0400160 for (int i = 0; i < halfKernelSize; ++i) {
161 sum += halfKernel[i];
162 profile[halfKernelSize - i - 1] = SkUnitScalarClampToByte(sum);
163 }
Ethan Nicholas5b5f0962017-09-11 13:50:14 -0700164 // Ensure tail goes to 0.
Ethan Nicholasb7e8c3b2017-07-19 13:54:20 -0400165 profile[profileWidth - 1] = 0;
166 return profile;
167}
168
169static sk_sp<GrTextureProxy> create_profile_texture(GrResourceProvider* resourceProvider,
170 const SkRect& circle, float sigma,
171 float* solidRadius, float* textureRadius) {
172 float circleR = circle.width() / 2.0f;
Ethan Nicholas5b5f0962017-09-11 13:50:14 -0700173 // Profile textures are cached by the ratio of sigma to circle radius and by the size of the
174 // profile texture (binned by powers of 2).
Ethan Nicholasb7e8c3b2017-07-19 13:54:20 -0400175 SkScalar sigmaToCircleRRatio = sigma / circleR;
Ethan Nicholas5b5f0962017-09-11 13:50:14 -0700176 // When sigma is really small this becomes a equivalent to convolving a Gaussian with a
177 // half-plane. Similarly, in the extreme high ratio cases circle becomes a point WRT to the
178 // Guassian and the profile texture is a just a Gaussian evaluation. However, we haven't yet
179 // implemented this latter optimization.
Ethan Nicholasb7e8c3b2017-07-19 13:54:20 -0400180 sigmaToCircleRRatio = SkTMin(sigmaToCircleRRatio, 8.f);
181 SkFixed sigmaToCircleRRatioFixed;
182 static const SkScalar kHalfPlaneThreshold = 0.1f;
183 bool useHalfPlaneApprox = false;
184 if (sigmaToCircleRRatio <= kHalfPlaneThreshold) {
185 useHalfPlaneApprox = true;
186 sigmaToCircleRRatioFixed = 0;
187 *solidRadius = circleR - 3 * sigma;
188 *textureRadius = 6 * sigma;
189 } else {
Ethan Nicholas5b5f0962017-09-11 13:50:14 -0700190 // Convert to fixed point for the key.
Ethan Nicholasb7e8c3b2017-07-19 13:54:20 -0400191 sigmaToCircleRRatioFixed = SkScalarToFixed(sigmaToCircleRRatio);
Ethan Nicholas5b5f0962017-09-11 13:50:14 -0700192 // We shave off some bits to reduce the number of unique entries. We could probably
193 // shave off more than we do.
Ethan Nicholasb7e8c3b2017-07-19 13:54:20 -0400194 sigmaToCircleRRatioFixed &= ~0xff;
195 sigmaToCircleRRatio = SkFixedToScalar(sigmaToCircleRRatioFixed);
196 sigma = circleR * sigmaToCircleRRatio;
197 *solidRadius = 0;
198 *textureRadius = circleR + 3 * sigma;
199 }
200
201 static const GrUniqueKey::Domain kDomain = GrUniqueKey::GenerateDomain();
202 GrUniqueKey key;
203 GrUniqueKey::Builder builder(&key, kDomain, 1);
204 builder[0] = sigmaToCircleRRatioFixed;
205 builder.finish();
206
Ethan Nicholas480c90a2017-07-25 16:45:15 -0400207 sk_sp<GrTextureProxy> blurProfile =
Greg Danielcd871402017-09-26 12:49:26 -0400208 resourceProvider->findOrCreateProxyByUniqueKey(key, kTopLeft_GrSurfaceOrigin);
Ethan Nicholasb7e8c3b2017-07-19 13:54:20 -0400209 if (!blurProfile) {
210 static constexpr int kProfileTextureWidth = 512;
211 GrSurfaceDesc texDesc;
Robert Phillipsc686ce32017-07-21 14:12:29 -0400212 texDesc.fOrigin = kTopLeft_GrSurfaceOrigin;
Ethan Nicholasb7e8c3b2017-07-19 13:54:20 -0400213 texDesc.fWidth = kProfileTextureWidth;
214 texDesc.fHeight = 1;
215 texDesc.fConfig = kAlpha_8_GrPixelConfig;
216
217 std::unique_ptr<uint8_t[]> profile(nullptr);
218 if (useHalfPlaneApprox) {
219 profile.reset(create_half_plane_profile(kProfileTextureWidth));
220 } else {
Ethan Nicholas5b5f0962017-09-11 13:50:14 -0700221 // Rescale params to the size of the texture we're creating.
Ethan Nicholasb7e8c3b2017-07-19 13:54:20 -0400222 SkScalar scale = kProfileTextureWidth / *textureRadius;
223 profile.reset(
224 create_circle_profile(sigma * scale, circleR * scale, kProfileTextureWidth));
225 }
226
227 blurProfile = GrSurfaceProxy::MakeDeferred(resourceProvider, texDesc, SkBudgeted::kYes,
228 profile.get(), 0);
229 if (!blurProfile) {
Brian Salomoncda20152017-07-17 16:44:32 -0400230 return nullptr;
231 }
Ethan Nicholasb7e8c3b2017-07-19 13:54:20 -0400232
Robert Phillipsc686ce32017-07-21 14:12:29 -0400233 SkASSERT(blurProfile->origin() == kTopLeft_GrSurfaceOrigin);
Ethan Nicholasb7e8c3b2017-07-19 13:54:20 -0400234 resourceProvider->assignUniqueKeyToProxy(key, blurProfile.get());
Brian Salomoncda20152017-07-17 16:44:32 -0400235 }
Ethan Nicholasb7e8c3b2017-07-19 13:54:20 -0400236
237 return blurProfile;
238}
239
Brian Salomonaff329b2017-08-11 09:40:37 -0400240std::unique_ptr<GrFragmentProcessor> GrCircleBlurFragmentProcessor::Make(
241 GrResourceProvider* resourceProvider, const SkRect& circle, float sigma) {
Ethan Nicholasb7e8c3b2017-07-19 13:54:20 -0400242 float solidRadius;
243 float textureRadius;
244 sk_sp<GrTextureProxy> profile(
245 create_profile_texture(resourceProvider, circle, sigma, &solidRadius, &textureRadius));
246 if (!profile) {
247 return nullptr;
248 }
Brian Salomonaff329b2017-08-11 09:40:37 -0400249 return std::unique_ptr<GrFragmentProcessor>(new GrCircleBlurFragmentProcessor(
Ethan Nicholasb7e8c3b2017-07-19 13:54:20 -0400250 circle, textureRadius, solidRadius, std::move(profile), resourceProvider));
251}
Ethan Nicholasceb4d482017-07-10 15:40:20 -0400252#include "glsl/GrGLSLColorSpaceXformHelper.h"
253#include "glsl/GrGLSLFragmentProcessor.h"
254#include "glsl/GrGLSLFragmentShaderBuilder.h"
255#include "glsl/GrGLSLProgramBuilder.h"
256#include "SkSLCPP.h"
257#include "SkSLUtil.h"
258class GrGLSLCircleBlurFragmentProcessor : public GrGLSLFragmentProcessor {
Brian Salomoncda20152017-07-17 16:44:32 -0400259public:
260 GrGLSLCircleBlurFragmentProcessor() {}
261 void emitCode(EmitArgs& args) override {
262 GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
Ethan Nicholasb7e8c3b2017-07-19 13:54:20 -0400263 const GrCircleBlurFragmentProcessor& _outer =
264 args.fFp.cast<GrCircleBlurFragmentProcessor>();
265 (void)_outer;
Ethan Nicholasf7b88202017-09-18 14:10:39 -0400266 fCircleDataVar = args.fUniformHandler->addUniform(kFragment_GrShaderFlag, kHalf4_GrSLType,
Ethan Nicholasb7e8c3b2017-07-19 13:54:20 -0400267 kDefault_GrSLPrecision, "circleData");
268 fragBuilder->codeAppendf(
Ethan Nicholas8aa45692017-09-20 11:24:15 -0400269 "half2 vec = half2(half((sk_FragCoord.x - float(%s.x)) * float(%s.w)), "
270 "half((sk_FragCoord.y - float(%s.y)) * float(%s.w)));\nhalf dist = "
271 "float(length(vec)) + (0.5 - float(%s.z)) * float(%s.w);\n%s = %s * texture(%s, "
272 "float2(half2(dist, 0.5))).%s.w;\n",
Ethan Nicholasb7e8c3b2017-07-19 13:54:20 -0400273 args.fUniformHandler->getUniformCStr(fCircleDataVar),
274 args.fUniformHandler->getUniformCStr(fCircleDataVar),
275 args.fUniformHandler->getUniformCStr(fCircleDataVar),
276 args.fUniformHandler->getUniformCStr(fCircleDataVar),
277 args.fUniformHandler->getUniformCStr(fCircleDataVar),
278 args.fUniformHandler->getUniformCStr(fCircleDataVar), args.fOutputColor,
Ethan Nicholasf7b88202017-09-18 14:10:39 -0400279 args.fInputColor ? args.fInputColor : "half4(1)",
Ethan Nicholasb7e8c3b2017-07-19 13:54:20 -0400280 fragBuilder->getProgramBuilder()->samplerVariable(args.fTexSamplers[0]).c_str(),
281 fragBuilder->getProgramBuilder()->samplerSwizzle(args.fTexSamplers[0]).c_str());
Brian Salomoncda20152017-07-17 16:44:32 -0400282 }
Ethan Nicholasb7e8c3b2017-07-19 13:54:20 -0400283
Brian Salomoncda20152017-07-17 16:44:32 -0400284private:
Ethan Nicholasb7e8c3b2017-07-19 13:54:20 -0400285 void onSetData(const GrGLSLProgramDataManager& data,
286 const GrFragmentProcessor& _proc) override {
Brian Salomoncda20152017-07-17 16:44:32 -0400287 const GrCircleBlurFragmentProcessor& _outer = _proc.cast<GrCircleBlurFragmentProcessor>();
288 auto circleRect = _outer.circleRect();
Ethan Nicholasb7e8c3b2017-07-19 13:54:20 -0400289 (void)circleRect;
Brian Salomoncda20152017-07-17 16:44:32 -0400290 auto textureRadius = _outer.textureRadius();
Ethan Nicholasb7e8c3b2017-07-19 13:54:20 -0400291 (void)textureRadius;
Brian Salomoncda20152017-07-17 16:44:32 -0400292 auto solidRadius = _outer.solidRadius();
Ethan Nicholasb7e8c3b2017-07-19 13:54:20 -0400293 (void)solidRadius;
Brian Salomoncda20152017-07-17 16:44:32 -0400294 UniformHandle& blurProfileSampler = fBlurProfileSamplerVar;
Ethan Nicholasb7e8c3b2017-07-19 13:54:20 -0400295 (void)blurProfileSampler;
Brian Salomoncda20152017-07-17 16:44:32 -0400296 UniformHandle& circleData = fCircleDataVar;
Ethan Nicholasb7e8c3b2017-07-19 13:54:20 -0400297 (void)circleData;
Ethan Nicholasceb4d482017-07-10 15:40:20 -0400298
Ethan Nicholasb7e8c3b2017-07-19 13:54:20 -0400299 data.set4f(circleData, circleRect.centerX(), circleRect.centerY(), solidRadius,
300 1.f / textureRadius);
Brian Salomoncda20152017-07-17 16:44:32 -0400301 }
302 UniformHandle fCircleDataVar;
303 UniformHandle fBlurProfileSamplerVar;
Ethan Nicholasceb4d482017-07-10 15:40:20 -0400304};
Brian Salomoncda20152017-07-17 16:44:32 -0400305GrGLSLFragmentProcessor* GrCircleBlurFragmentProcessor::onCreateGLSLInstance() const {
306 return new GrGLSLCircleBlurFragmentProcessor();
Ethan Nicholas818ac5a2017-07-10 13:12:07 +0000307}
Ethan Nicholasb7e8c3b2017-07-19 13:54:20 -0400308void GrCircleBlurFragmentProcessor::onGetGLSLProcessorKey(const GrShaderCaps& caps,
309 GrProcessorKeyBuilder* b) const {}
Brian Salomoncda20152017-07-17 16:44:32 -0400310bool GrCircleBlurFragmentProcessor::onIsEqual(const GrFragmentProcessor& other) const {
311 const GrCircleBlurFragmentProcessor& that = other.cast<GrCircleBlurFragmentProcessor>();
Ethan Nicholasb7e8c3b2017-07-19 13:54:20 -0400312 (void)that;
Brian Salomoncda20152017-07-17 16:44:32 -0400313 if (fCircleRect != that.fCircleRect) return false;
314 if (fTextureRadius != that.fTextureRadius) return false;
315 if (fSolidRadius != that.fSolidRadius) return false;
316 if (fBlurProfileSampler != that.fBlurProfileSampler) return false;
317 return true;
Ethan Nicholasceb4d482017-07-10 15:40:20 -0400318}
Ethan Nicholasf57c0d62017-07-31 11:18:22 -0400319GrCircleBlurFragmentProcessor::GrCircleBlurFragmentProcessor(
320 const GrCircleBlurFragmentProcessor& src)
Ethan Nicholasabff9562017-10-09 10:54:08 -0400321 : INHERITED(kGrCircleBlurFragmentProcessor_ClassID, src.optimizationFlags())
Ethan Nicholasf57c0d62017-07-31 11:18:22 -0400322 , fCircleRect(src.fCircleRect)
323 , fTextureRadius(src.fTextureRadius)
324 , fSolidRadius(src.fSolidRadius)
325 , fBlurProfileSampler(src.fBlurProfileSampler) {
Ethan Nicholasf57c0d62017-07-31 11:18:22 -0400326 this->addTextureSampler(&fBlurProfileSampler);
327}
Brian Salomonaff329b2017-08-11 09:40:37 -0400328std::unique_ptr<GrFragmentProcessor> GrCircleBlurFragmentProcessor::clone() const {
329 return std::unique_ptr<GrFragmentProcessor>(new GrCircleBlurFragmentProcessor(*this));
Ethan Nicholasf57c0d62017-07-31 11:18:22 -0400330}
Ethan Nicholas818ac5a2017-07-10 13:12:07 +0000331GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrCircleBlurFragmentProcessor);
Ethan Nicholas818ac5a2017-07-10 13:12:07 +0000332#if GR_TEST_UTILS
Brian Salomonaff329b2017-08-11 09:40:37 -0400333std::unique_ptr<GrFragmentProcessor> GrCircleBlurFragmentProcessor::TestCreate(
Ethan Nicholasb7e8c3b2017-07-19 13:54:20 -0400334 GrProcessorTestData* testData) {
Brian Salomoncda20152017-07-17 16:44:32 -0400335 SkScalar wh = testData->fRandom->nextRangeScalar(100.f, 1000.f);
Ethan Nicholasb7e8c3b2017-07-19 13:54:20 -0400336 SkScalar sigma = testData->fRandom->nextRangeF(1.f, 10.f);
Brian Salomoncda20152017-07-17 16:44:32 -0400337 SkRect circle = SkRect::MakeWH(wh, wh);
338 return GrCircleBlurFragmentProcessor::Make(testData->resourceProvider(), circle, sigma);
robertphillips30c4cae2015-09-15 10:20:55 -0700339}
Hal Canary6f6961e2017-01-31 13:50:44 -0500340#endif
robertphillips30c4cae2015-09-15 10:20:55 -0700341#endif