blob: 31311e2e1ccc34467501dc82c488812ca6063689 [file] [log] [blame]
robertphillips30c4cae2015-09-15 10:20:55 -07001/*
Ethan Nicholas130fb3f2018-02-01 12:14:34 -05002 * Copyright 2018 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 Nicholas130fb3f2018-02-01 12:14:34 -05008/**************************************************************************************************
9 *** This file was autogenerated from GrCircleBlurFragmentProcessor.fp; do not modify.
10 **************************************************************************************************/
robertphillips30c4cae2015-09-15 10:20:55 -070011#include "GrCircleBlurFragmentProcessor.h"
robertphillips30c4cae2015-09-15 10:20:55 -070012#if SK_SUPPORT_GPU
13
Robert Phillips1afd4cd2018-01-08 13:40:32 -050014#include "GrProxyProvider.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
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500169static sk_sp<GrTextureProxy> create_profile_texture(GrProxyProvider* proxyProvider,
Ethan Nicholasb7e8c3b2017-07-19 13:54:20 -0400170 const SkRect& circle, float sigma,
171 float* solidRadius, float* textureRadius) {
172 float circleR = circle.width() / 2.0f;
Jim Van Verth3431c6b2018-01-05 13:19:46 -0500173 if (circleR < SK_ScalarNearlyZero) {
174 return nullptr;
175 }
Ethan Nicholas5b5f0962017-09-11 13:50:14 -0700176 // Profile textures are cached by the ratio of sigma to circle radius and by the size of the
177 // profile texture (binned by powers of 2).
Ethan Nicholasb7e8c3b2017-07-19 13:54:20 -0400178 SkScalar sigmaToCircleRRatio = sigma / circleR;
Ethan Nicholas5b5f0962017-09-11 13:50:14 -0700179 // When sigma is really small this becomes a equivalent to convolving a Gaussian with a
180 // half-plane. Similarly, in the extreme high ratio cases circle becomes a point WRT to the
181 // Guassian and the profile texture is a just a Gaussian evaluation. However, we haven't yet
182 // implemented this latter optimization.
Ethan Nicholasb7e8c3b2017-07-19 13:54:20 -0400183 sigmaToCircleRRatio = SkTMin(sigmaToCircleRRatio, 8.f);
184 SkFixed sigmaToCircleRRatioFixed;
185 static const SkScalar kHalfPlaneThreshold = 0.1f;
186 bool useHalfPlaneApprox = false;
187 if (sigmaToCircleRRatio <= kHalfPlaneThreshold) {
188 useHalfPlaneApprox = true;
189 sigmaToCircleRRatioFixed = 0;
190 *solidRadius = circleR - 3 * sigma;
191 *textureRadius = 6 * sigma;
192 } else {
Ethan Nicholas5b5f0962017-09-11 13:50:14 -0700193 // Convert to fixed point for the key.
Ethan Nicholasb7e8c3b2017-07-19 13:54:20 -0400194 sigmaToCircleRRatioFixed = SkScalarToFixed(sigmaToCircleRRatio);
Ethan Nicholas5b5f0962017-09-11 13:50:14 -0700195 // We shave off some bits to reduce the number of unique entries. We could probably
196 // shave off more than we do.
Ethan Nicholasb7e8c3b2017-07-19 13:54:20 -0400197 sigmaToCircleRRatioFixed &= ~0xff;
198 sigmaToCircleRRatio = SkFixedToScalar(sigmaToCircleRRatioFixed);
199 sigma = circleR * sigmaToCircleRRatio;
200 *solidRadius = 0;
201 *textureRadius = circleR + 3 * sigma;
202 }
203
204 static const GrUniqueKey::Domain kDomain = GrUniqueKey::GenerateDomain();
205 GrUniqueKey key;
206 GrUniqueKey::Builder builder(&key, kDomain, 1);
207 builder[0] = sigmaToCircleRRatioFixed;
208 builder.finish();
209
Ethan Nicholas480c90a2017-07-25 16:45:15 -0400210 sk_sp<GrTextureProxy> blurProfile =
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500211 proxyProvider->findOrCreateProxyByUniqueKey(key, kTopLeft_GrSurfaceOrigin);
Ethan Nicholasb7e8c3b2017-07-19 13:54:20 -0400212 if (!blurProfile) {
213 static constexpr int kProfileTextureWidth = 512;
214 GrSurfaceDesc texDesc;
Robert Phillipsc686ce32017-07-21 14:12:29 -0400215 texDesc.fOrigin = kTopLeft_GrSurfaceOrigin;
Ethan Nicholasb7e8c3b2017-07-19 13:54:20 -0400216 texDesc.fWidth = kProfileTextureWidth;
217 texDesc.fHeight = 1;
218 texDesc.fConfig = kAlpha_8_GrPixelConfig;
219
220 std::unique_ptr<uint8_t[]> profile(nullptr);
221 if (useHalfPlaneApprox) {
222 profile.reset(create_half_plane_profile(kProfileTextureWidth));
223 } else {
Ethan Nicholas5b5f0962017-09-11 13:50:14 -0700224 // Rescale params to the size of the texture we're creating.
Ethan Nicholasb7e8c3b2017-07-19 13:54:20 -0400225 SkScalar scale = kProfileTextureWidth / *textureRadius;
226 profile.reset(
227 create_circle_profile(sigma * scale, circleR * scale, kProfileTextureWidth));
228 }
229
Robert Phillips20df20c2018-01-16 10:54:33 -0500230 blurProfile =
231 proxyProvider->createTextureProxy(texDesc, SkBudgeted::kYes, profile.get(), 0);
Ethan Nicholasb7e8c3b2017-07-19 13:54:20 -0400232 if (!blurProfile) {
Brian Salomoncda20152017-07-17 16:44:32 -0400233 return nullptr;
234 }
Ethan Nicholasb7e8c3b2017-07-19 13:54:20 -0400235
Robert Phillipsc686ce32017-07-21 14:12:29 -0400236 SkASSERT(blurProfile->origin() == kTopLeft_GrSurfaceOrigin);
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500237 proxyProvider->assignUniqueKeyToProxy(key, blurProfile.get());
Brian Salomoncda20152017-07-17 16:44:32 -0400238 }
Ethan Nicholasb7e8c3b2017-07-19 13:54:20 -0400239
240 return blurProfile;
241}
242
Brian Salomonaff329b2017-08-11 09:40:37 -0400243std::unique_ptr<GrFragmentProcessor> GrCircleBlurFragmentProcessor::Make(
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500244 GrProxyProvider* proxyProvider, const SkRect& circle, float sigma) {
Ethan Nicholasb7e8c3b2017-07-19 13:54:20 -0400245 float solidRadius;
246 float textureRadius;
247 sk_sp<GrTextureProxy> profile(
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500248 create_profile_texture(proxyProvider, circle, sigma, &solidRadius, &textureRadius));
Ethan Nicholasb7e8c3b2017-07-19 13:54:20 -0400249 if (!profile) {
250 return nullptr;
251 }
Brian Salomonaff329b2017-08-11 09:40:37 -0400252 return std::unique_ptr<GrFragmentProcessor>(new GrCircleBlurFragmentProcessor(
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500253 circle, textureRadius, solidRadius, std::move(profile)));
Ethan Nicholasb7e8c3b2017-07-19 13:54:20 -0400254}
Ethan Nicholasceb4d482017-07-10 15:40:20 -0400255#include "glsl/GrGLSLFragmentProcessor.h"
256#include "glsl/GrGLSLFragmentShaderBuilder.h"
257#include "glsl/GrGLSLProgramBuilder.h"
Ethan Nicholas2d5f9b32017-12-13 14:36:14 -0500258#include "GrTexture.h"
Ethan Nicholasceb4d482017-07-10 15:40:20 -0400259#include "SkSLCPP.h"
260#include "SkSLUtil.h"
261class GrGLSLCircleBlurFragmentProcessor : public GrGLSLFragmentProcessor {
Brian Salomoncda20152017-07-17 16:44:32 -0400262public:
263 GrGLSLCircleBlurFragmentProcessor() {}
264 void emitCode(EmitArgs& args) override {
265 GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
Ethan Nicholasb7e8c3b2017-07-19 13:54:20 -0400266 const GrCircleBlurFragmentProcessor& _outer =
267 args.fFp.cast<GrCircleBlurFragmentProcessor>();
268 (void)_outer;
Ethan Nicholas82399462017-10-16 12:35:44 -0400269 auto circleRect = _outer.circleRect();
270 (void)circleRect;
271 auto textureRadius = _outer.textureRadius();
272 (void)textureRadius;
273 auto solidRadius = _outer.solidRadius();
274 (void)solidRadius;
Ethan Nicholasf7b88202017-09-18 14:10:39 -0400275 fCircleDataVar = args.fUniformHandler->addUniform(kFragment_GrShaderFlag, kHalf4_GrSLType,
Ethan Nicholasb7e8c3b2017-07-19 13:54:20 -0400276 kDefault_GrSLPrecision, "circleData");
277 fragBuilder->codeAppendf(
Ethan Nicholas8aa45692017-09-20 11:24:15 -0400278 "half2 vec = half2(half((sk_FragCoord.x - float(%s.x)) * float(%s.w)), "
279 "half((sk_FragCoord.y - float(%s.y)) * float(%s.w)));\nhalf dist = "
280 "float(length(vec)) + (0.5 - float(%s.z)) * float(%s.w);\n%s = %s * texture(%s, "
281 "float2(half2(dist, 0.5))).%s.w;\n",
Ethan Nicholasb7e8c3b2017-07-19 13:54:20 -0400282 args.fUniformHandler->getUniformCStr(fCircleDataVar),
283 args.fUniformHandler->getUniformCStr(fCircleDataVar),
284 args.fUniformHandler->getUniformCStr(fCircleDataVar),
285 args.fUniformHandler->getUniformCStr(fCircleDataVar),
286 args.fUniformHandler->getUniformCStr(fCircleDataVar),
287 args.fUniformHandler->getUniformCStr(fCircleDataVar), args.fOutputColor,
Ethan Nicholasf7b88202017-09-18 14:10:39 -0400288 args.fInputColor ? args.fInputColor : "half4(1)",
Ethan Nicholasb7e8c3b2017-07-19 13:54:20 -0400289 fragBuilder->getProgramBuilder()->samplerVariable(args.fTexSamplers[0]).c_str(),
290 fragBuilder->getProgramBuilder()->samplerSwizzle(args.fTexSamplers[0]).c_str());
Brian Salomoncda20152017-07-17 16:44:32 -0400291 }
Ethan Nicholasb7e8c3b2017-07-19 13:54:20 -0400292
Brian Salomoncda20152017-07-17 16:44:32 -0400293private:
Ethan Nicholasb7e8c3b2017-07-19 13:54:20 -0400294 void onSetData(const GrGLSLProgramDataManager& data,
295 const GrFragmentProcessor& _proc) override {
Brian Salomoncda20152017-07-17 16:44:32 -0400296 const GrCircleBlurFragmentProcessor& _outer = _proc.cast<GrCircleBlurFragmentProcessor>();
297 auto circleRect = _outer.circleRect();
Ethan Nicholasb7e8c3b2017-07-19 13:54:20 -0400298 (void)circleRect;
Brian Salomoncda20152017-07-17 16:44:32 -0400299 auto textureRadius = _outer.textureRadius();
Ethan Nicholasb7e8c3b2017-07-19 13:54:20 -0400300 (void)textureRadius;
Brian Salomoncda20152017-07-17 16:44:32 -0400301 auto solidRadius = _outer.solidRadius();
Ethan Nicholasb7e8c3b2017-07-19 13:54:20 -0400302 (void)solidRadius;
Ethan Nicholas2d5f9b32017-12-13 14:36:14 -0500303 GrSurfaceProxy& blurProfileSamplerProxy = *_outer.textureSampler(0).proxy();
304 GrTexture& blurProfileSampler = *blurProfileSamplerProxy.priv().peekTexture();
Ethan Nicholasb7e8c3b2017-07-19 13:54:20 -0400305 (void)blurProfileSampler;
Brian Salomoncda20152017-07-17 16:44:32 -0400306 UniformHandle& circleData = fCircleDataVar;
Ethan Nicholasb7e8c3b2017-07-19 13:54:20 -0400307 (void)circleData;
Ethan Nicholasceb4d482017-07-10 15:40:20 -0400308
Ethan Nicholasb7e8c3b2017-07-19 13:54:20 -0400309 data.set4f(circleData, circleRect.centerX(), circleRect.centerY(), solidRadius,
310 1.f / textureRadius);
Brian Salomoncda20152017-07-17 16:44:32 -0400311 }
312 UniformHandle fCircleDataVar;
Ethan Nicholasceb4d482017-07-10 15:40:20 -0400313};
Brian Salomoncda20152017-07-17 16:44:32 -0400314GrGLSLFragmentProcessor* GrCircleBlurFragmentProcessor::onCreateGLSLInstance() const {
315 return new GrGLSLCircleBlurFragmentProcessor();
Ethan Nicholas818ac5a2017-07-10 13:12:07 +0000316}
Ethan Nicholasb7e8c3b2017-07-19 13:54:20 -0400317void GrCircleBlurFragmentProcessor::onGetGLSLProcessorKey(const GrShaderCaps& caps,
318 GrProcessorKeyBuilder* b) const {}
Brian Salomoncda20152017-07-17 16:44:32 -0400319bool GrCircleBlurFragmentProcessor::onIsEqual(const GrFragmentProcessor& other) const {
320 const GrCircleBlurFragmentProcessor& that = other.cast<GrCircleBlurFragmentProcessor>();
Ethan Nicholasb7e8c3b2017-07-19 13:54:20 -0400321 (void)that;
Brian Salomoncda20152017-07-17 16:44:32 -0400322 if (fCircleRect != that.fCircleRect) return false;
323 if (fTextureRadius != that.fTextureRadius) return false;
324 if (fSolidRadius != that.fSolidRadius) return false;
325 if (fBlurProfileSampler != that.fBlurProfileSampler) return false;
326 return true;
Ethan Nicholasceb4d482017-07-10 15:40:20 -0400327}
Ethan Nicholasf57c0d62017-07-31 11:18:22 -0400328GrCircleBlurFragmentProcessor::GrCircleBlurFragmentProcessor(
329 const GrCircleBlurFragmentProcessor& src)
Ethan Nicholasabff9562017-10-09 10:54:08 -0400330 : INHERITED(kGrCircleBlurFragmentProcessor_ClassID, src.optimizationFlags())
Ethan Nicholasf57c0d62017-07-31 11:18:22 -0400331 , fCircleRect(src.fCircleRect)
332 , fTextureRadius(src.fTextureRadius)
333 , fSolidRadius(src.fSolidRadius)
334 , fBlurProfileSampler(src.fBlurProfileSampler) {
Ethan Nicholasf57c0d62017-07-31 11:18:22 -0400335 this->addTextureSampler(&fBlurProfileSampler);
336}
Brian Salomonaff329b2017-08-11 09:40:37 -0400337std::unique_ptr<GrFragmentProcessor> GrCircleBlurFragmentProcessor::clone() const {
338 return std::unique_ptr<GrFragmentProcessor>(new GrCircleBlurFragmentProcessor(*this));
Ethan Nicholasf57c0d62017-07-31 11:18:22 -0400339}
Ethan Nicholas818ac5a2017-07-10 13:12:07 +0000340GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrCircleBlurFragmentProcessor);
Ethan Nicholas818ac5a2017-07-10 13:12:07 +0000341#if GR_TEST_UTILS
Brian Salomonaff329b2017-08-11 09:40:37 -0400342std::unique_ptr<GrFragmentProcessor> GrCircleBlurFragmentProcessor::TestCreate(
Ethan Nicholasb7e8c3b2017-07-19 13:54:20 -0400343 GrProcessorTestData* testData) {
Brian Salomoncda20152017-07-17 16:44:32 -0400344 SkScalar wh = testData->fRandom->nextRangeScalar(100.f, 1000.f);
Ethan Nicholasb7e8c3b2017-07-19 13:54:20 -0400345 SkScalar sigma = testData->fRandom->nextRangeF(1.f, 10.f);
Brian Salomoncda20152017-07-17 16:44:32 -0400346 SkRect circle = SkRect::MakeWH(wh, wh);
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500347 return GrCircleBlurFragmentProcessor::Make(testData->proxyProvider(), circle, sigma);
robertphillips30c4cae2015-09-15 10:20:55 -0700348}
Hal Canary6f6961e2017-01-31 13:50:44 -0500349#endif
robertphillips30c4cae2015-09-15 10:20:55 -0700350#endif