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 | |
Michael Ludwig | e267464 | 2020-10-21 13:01:34 -0400 | [diff] [blame] | 10 | #include "src/core/SkGpuBlurUtils.h" |
Greg Daniel | 456f9b5 | 2020-03-05 19:14:18 +0000 | [diff] [blame] | 11 | #include "src/gpu/GrTexture.h" |
Greg Daniel | f91aeb2 | 2019-06-18 09:58:02 -0400 | [diff] [blame] | 12 | #include "src/gpu/GrTextureProxy.h" |
Brian Salomon | 5ed3c2f | 2020-04-13 16:51:39 -0400 | [diff] [blame] | 13 | #include "src/gpu/effects/GrTextureEffect.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 14 | #include "src/gpu/glsl/GrGLSLFragmentProcessor.h" |
| 15 | #include "src/gpu/glsl/GrGLSLFragmentShaderBuilder.h" |
| 16 | #include "src/gpu/glsl/GrGLSLProgramDataManager.h" |
| 17 | #include "src/gpu/glsl/GrGLSLUniformHandler.h" |
Ethan Nicholas | 4885057 | 2021-02-25 14:45:38 -0500 | [diff] [blame] | 18 | #include "src/sksl/dsl/priv/DSLFPs.h" |
tomhudson@google.com | d8f856c | 2012-05-10 12:13:36 +0000 | [diff] [blame] | 19 | |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 20 | // For brevity |
Brian Salomon | b133ffe | 2017-07-27 11:53:21 -0400 | [diff] [blame] | 21 | using UniformHandle = GrGLSLProgramDataManager::UniformHandle; |
| 22 | using Direction = GrGaussianConvolutionFragmentProcessor::Direction; |
bsalomon@google.com | 032b221 | 2012-07-16 13:36:18 +0000 | [diff] [blame] | 23 | |
Brian Salomon | 08cb4bf | 2020-05-07 15:34:15 -0400 | [diff] [blame] | 24 | class GrGaussianConvolutionFragmentProcessor::Impl : public GrGLSLFragmentProcessor { |
tomhudson@google.com | d8f856c | 2012-05-10 12:13:36 +0000 | [diff] [blame] | 25 | public: |
robertphillips | 9cdb992 | 2016-02-03 12:25:40 -0800 | [diff] [blame] | 26 | void emitCode(EmitArgs&) override; |
ericrk | 7a787b4 | 2015-07-21 14:06:16 -0700 | [diff] [blame] | 27 | |
Brian Salomon | 94efbf5 | 2016-11-29 13:43:05 -0500 | [diff] [blame] | 28 | static inline void GenKey(const GrProcessor&, const GrShaderCaps&, GrProcessorKeyBuilder*); |
tomhudson@google.com | d8f856c | 2012-05-10 12:13:36 +0000 | [diff] [blame] | 29 | |
wangyix | b1daa86 | 2015-08-18 11:29:31 -0700 | [diff] [blame] | 30 | protected: |
Brian Salomon | ab015ef | 2017-04-04 10:15:51 -0400 | [diff] [blame] | 31 | void onSetData(const GrGLSLProgramDataManager&, const GrFragmentProcessor&) override; |
wangyix | b1daa86 | 2015-08-18 11:29:31 -0700 | [diff] [blame] | 32 | |
ericrk | 0f38612 | 2015-07-21 13:15:47 -0700 | [diff] [blame] | 33 | private: |
Brian Salomon | aee504b | 2017-01-24 12:29:36 -0500 | [diff] [blame] | 34 | UniformHandle fKernelUni; |
Albert Chaulk | 52b9e81 | 2021-04-12 17:23:25 -0400 | [diff] [blame] | 35 | #if !defined(SK_DISABLE_BILINEAR_BLUR_OPTIMIZATION) |
| 36 | UniformHandle fOffsetsUni; |
| 37 | #endif |
Brian Salomon | 5ed3c2f | 2020-04-13 16:51:39 -0400 | [diff] [blame] | 38 | UniformHandle fIncrementUni; |
tomhudson@google.com | d8f856c | 2012-05-10 12:13:36 +0000 | [diff] [blame] | 39 | |
John Stiles | 7571f9e | 2020-09-02 22:42:33 -0400 | [diff] [blame] | 40 | using INHERITED = GrGLSLFragmentProcessor; |
tomhudson@google.com | d8f856c | 2012-05-10 12:13:36 +0000 | [diff] [blame] | 41 | }; |
| 42 | |
Brian Salomon | 08cb4bf | 2020-05-07 15:34:15 -0400 | [diff] [blame] | 43 | void GrGaussianConvolutionFragmentProcessor::Impl::emitCode(EmitArgs& args) { |
Brian Salomon | aee504b | 2017-01-24 12:29:36 -0500 | [diff] [blame] | 44 | const GrGaussianConvolutionFragmentProcessor& ce = |
| 45 | args.fFp.cast<GrGaussianConvolutionFragmentProcessor>(); |
robertphillips | bf536af | 2016-02-04 06:11:53 -0800 | [diff] [blame] | 46 | |
Ethan Nicholas | 4885057 | 2021-02-25 14:45:38 -0500 | [diff] [blame] | 47 | using namespace SkSL::dsl; |
| 48 | StartFragmentProcessor(this, &args); |
Ethan Nicholas | b14e6b9 | 2021-04-08 16:56:05 -0400 | [diff] [blame] | 49 | Var increment(kUniform_Modifier, kHalf2_Type, "Increment"); |
Ethan Nicholas | 4885057 | 2021-02-25 14:45:38 -0500 | [diff] [blame] | 50 | fIncrementUni = VarUniformHandle(increment); |
robertphillips | bf536af | 2016-02-04 06:11:53 -0800 | [diff] [blame] | 51 | |
Albert Chaulk | 52b9e81 | 2021-04-12 17:23:25 -0400 | [diff] [blame] | 52 | #if defined(SK_DISABLE_BILINEAR_BLUR_OPTIMIZATION) |
Michael Ludwig | e267464 | 2020-10-21 13:01:34 -0400 | [diff] [blame] | 53 | int width = SkGpuBlurUtils::KernelWidth(ce.fRadius); |
Albert Chaulk | 52b9e81 | 2021-04-12 17:23:25 -0400 | [diff] [blame] | 54 | #else |
| 55 | int width = SkGpuBlurUtils::LinearKernelWidth(ce.fRadius); |
| 56 | #endif |
robertphillips | bf536af | 2016-02-04 06:11:53 -0800 | [diff] [blame] | 57 | |
jvanverth | 78d6eb0 | 2016-03-02 13:21:16 -0800 | [diff] [blame] | 58 | int arrayCount = (width + 3) / 4; |
| 59 | SkASSERT(4 * arrayCount >= width); |
| 60 | |
Ethan Nicholas | b14e6b9 | 2021-04-08 16:56:05 -0400 | [diff] [blame] | 61 | Var kernel(kUniform_Modifier, Array(kHalf4_Type, arrayCount), "Kernel"); |
Ethan Nicholas | 4885057 | 2021-02-25 14:45:38 -0500 | [diff] [blame] | 62 | fKernelUni = VarUniformHandle(kernel); |
ericrk | 7a787b4 | 2015-07-21 14:06:16 -0700 | [diff] [blame] | 63 | |
Ethan Nicholas | b14e6b9 | 2021-04-08 16:56:05 -0400 | [diff] [blame] | 64 | Var color(kHalf4_Type, "color", Half4(0)); |
Ethan Nicholas | fe5d692 | 2021-03-05 14:23:48 -0500 | [diff] [blame] | 65 | Declare(color); |
ericrk | 7a787b4 | 2015-07-21 14:06:16 -0700 | [diff] [blame] | 66 | |
Albert Chaulk | 52b9e81 | 2021-04-12 17:23:25 -0400 | [diff] [blame] | 67 | #if defined(SK_DISABLE_BILINEAR_BLUR_OPTIMIZATION) |
Ethan Nicholas | b14e6b9 | 2021-04-08 16:56:05 -0400 | [diff] [blame] | 68 | Var coord(kFloat2_Type, "coord", sk_SampleCoord() - ce.fRadius * increment); |
Ethan Nicholas | fe5d692 | 2021-03-05 14:23:48 -0500 | [diff] [blame] | 69 | Declare(coord); |
ericrk | 7a787b4 | 2015-07-21 14:06:16 -0700 | [diff] [blame] | 70 | |
| 71 | // Manually unroll loop because some drivers don't; yields 20-30% speedup. |
| 72 | for (int i = 0; i < width; i++) { |
John Stiles | 1c50643 | 2020-12-14 16:14:45 -0500 | [diff] [blame] | 73 | if (i != 0) { |
Ethan Nicholas | 4885057 | 2021-02-25 14:45:38 -0500 | [diff] [blame] | 74 | coord += increment; |
John Stiles | 1c50643 | 2020-12-14 16:14:45 -0500 | [diff] [blame] | 75 | } |
Ethan Nicholas | 4885057 | 2021-02-25 14:45:38 -0500 | [diff] [blame] | 76 | color += SampleChild(/*index=*/0, coord) * kernel[i / 4][i & 0x3]; |
ericrk | 7a787b4 | 2015-07-21 14:06:16 -0700 | [diff] [blame] | 77 | } |
Albert Chaulk | 52b9e81 | 2021-04-12 17:23:25 -0400 | [diff] [blame] | 78 | #else |
| 79 | Var offsets(kUniform_Modifier, Array(kHalf4_Type, arrayCount), "Offsets"); |
| 80 | fOffsetsUni = VarUniformHandle(offsets); |
| 81 | |
| 82 | Var coord(kFloat2_Type, "coord", sk_SampleCoord()); |
| 83 | Declare(coord); |
| 84 | |
| 85 | // Manually unroll loop because some drivers don't; yields 20-30% speedup. |
| 86 | for (int i = 0; i < width; i++) { |
| 87 | color += SampleChild(/*index=*/0, coord + offsets[i / 4][i & 3] * increment) * |
| 88 | kernel[i / 4][i & 0x3]; |
| 89 | } |
| 90 | #endif |
Ethan Nicholas | 4885057 | 2021-02-25 14:45:38 -0500 | [diff] [blame] | 91 | Return(color); |
| 92 | EndFragmentProcessor(); |
ericrk | 7a787b4 | 2015-07-21 14:06:16 -0700 | [diff] [blame] | 93 | } |
| 94 | |
Brian Salomon | 08cb4bf | 2020-05-07 15:34:15 -0400 | [diff] [blame] | 95 | void GrGaussianConvolutionFragmentProcessor::Impl::onSetData(const GrGLSLProgramDataManager& pdman, |
| 96 | const GrFragmentProcessor& processor) { |
Brian Salomon | 5ed3c2f | 2020-04-13 16:51:39 -0400 | [diff] [blame] | 97 | const auto& conv = processor.cast<GrGaussianConvolutionFragmentProcessor>(); |
robertphillips | bf536af | 2016-02-04 06:11:53 -0800 | [diff] [blame] | 98 | |
Brian Salomon | 5ed3c2f | 2020-04-13 16:51:39 -0400 | [diff] [blame] | 99 | float increment[2] = {}; |
Brian Salomon | 08cb4bf | 2020-05-07 15:34:15 -0400 | [diff] [blame] | 100 | increment[static_cast<int>(conv.fDirection)] = 1; |
Brian Salomon | 5ed3c2f | 2020-04-13 16:51:39 -0400 | [diff] [blame] | 101 | pdman.set2fv(fIncrementUni, 1, increment); |
Robert Phillips | eaded9d | 2018-05-01 15:17:50 -0400 | [diff] [blame] | 102 | |
Albert Chaulk | 52b9e81 | 2021-04-12 17:23:25 -0400 | [diff] [blame] | 103 | #if defined(SK_DISABLE_BILINEAR_BLUR_OPTIMIZATION) |
Michael Ludwig | e267464 | 2020-10-21 13:01:34 -0400 | [diff] [blame] | 104 | int width = SkGpuBlurUtils::KernelWidth(conv.fRadius); |
Albert Chaulk | 52b9e81 | 2021-04-12 17:23:25 -0400 | [diff] [blame] | 105 | #else |
| 106 | int width = SkGpuBlurUtils::LinearKernelWidth(conv.fRadius); |
| 107 | #endif |
Brian Salomon | 08cb4bf | 2020-05-07 15:34:15 -0400 | [diff] [blame] | 108 | int arrayCount = (width + 3)/4; |
| 109 | SkDEBUGCODE(size_t arraySize = 4*arrayCount;) |
| 110 | SkASSERT(arraySize >= static_cast<size_t>(width)); |
| 111 | SkASSERT(arraySize <= SK_ARRAY_COUNT(GrGaussianConvolutionFragmentProcessor::fKernel)); |
| 112 | pdman.set4fv(fKernelUni, arrayCount, conv.fKernel); |
Albert Chaulk | 52b9e81 | 2021-04-12 17:23:25 -0400 | [diff] [blame] | 113 | #if !defined(SK_DISABLE_BILINEAR_BLUR_OPTIMIZATION) |
| 114 | pdman.set4fv(fOffsetsUni, arrayCount, conv.fOffsets); |
| 115 | #endif |
ericrk | 7a787b4 | 2015-07-21 14:06:16 -0700 | [diff] [blame] | 116 | } |
| 117 | |
Brian Salomon | 08cb4bf | 2020-05-07 15:34:15 -0400 | [diff] [blame] | 118 | void GrGaussianConvolutionFragmentProcessor::Impl::GenKey(const GrProcessor& processor, |
| 119 | const GrShaderCaps&, |
| 120 | GrProcessorKeyBuilder* b) { |
Brian Salomon | 5ed3c2f | 2020-04-13 16:51:39 -0400 | [diff] [blame] | 121 | const auto& conv = processor.cast<GrGaussianConvolutionFragmentProcessor>(); |
Brian Salomon | 08cb4bf | 2020-05-07 15:34:15 -0400 | [diff] [blame] | 122 | b->add32(conv.fRadius); |
tomhudson@google.com | d8f856c | 2012-05-10 12:13:36 +0000 | [diff] [blame] | 123 | } |
| 124 | |
bsalomon@google.com | b505a12 | 2012-05-31 18:40:36 +0000 | [diff] [blame] | 125 | /////////////////////////////////////////////////////////////////////////////// |
Brian Salomon | 08cb4bf | 2020-05-07 15:34:15 -0400 | [diff] [blame] | 126 | |
Brian Salomon | 5ed3c2f | 2020-04-13 16:51:39 -0400 | [diff] [blame] | 127 | std::unique_ptr<GrFragmentProcessor> GrGaussianConvolutionFragmentProcessor::Make( |
Greg Daniel | 5c08249 | 2020-01-29 15:06:49 -0500 | [diff] [blame] | 128 | GrSurfaceProxyView view, |
Brian Salomon | fc11844 | 2019-11-22 19:09:27 -0500 | [diff] [blame] | 129 | SkAlphaType alphaType, |
Brian Salomon | 5ed3c2f | 2020-04-13 16:51:39 -0400 | [diff] [blame] | 130 | Direction dir, |
| 131 | int halfWidth, |
| 132 | float gaussianSigma, |
| 133 | GrSamplerState::WrapMode wm, |
Brian Salomon | 11ad4cc | 2020-05-15 12:07:59 -0400 | [diff] [blame] | 134 | const SkIRect& subset, |
| 135 | const SkIRect* pixelDomain, |
Brian Salomon | 5ed3c2f | 2020-04-13 16:51:39 -0400 | [diff] [blame] | 136 | const GrCaps& caps) { |
| 137 | std::unique_ptr<GrFragmentProcessor> child; |
Albert Chaulk | 52b9e81 | 2021-04-12 17:23:25 -0400 | [diff] [blame] | 138 | bool is_zero_sigma = SkGpuBlurUtils::IsEffectivelyZeroSigma(gaussianSigma); |
| 139 | // We should sample as nearest if there will be no shader to preserve existing behaviour, but |
| 140 | // the linear blur requires a linear sample. |
| 141 | GrSamplerState::Filter filter = is_zero_sigma ? |
| 142 | GrSamplerState::Filter::kNearest : GrSamplerState::Filter::kLinear; |
| 143 | #if defined(SK_DISABLE_BILINEAR_BLUR_OPTIMIZATION) |
| 144 | filter = GrSamplerState::Filter::kNearest; |
| 145 | #endif |
| 146 | |
| 147 | GrSamplerState sampler(wm, filter); |
| 148 | if (is_zero_sigma) { |
Michael Ludwig | e267464 | 2020-10-21 13:01:34 -0400 | [diff] [blame] | 149 | halfWidth = 0; |
| 150 | } |
Brian Salomon | 11ad4cc | 2020-05-15 12:07:59 -0400 | [diff] [blame] | 151 | if (pixelDomain) { |
| 152 | // Inset because we expect to be invoked at pixel centers. |
| 153 | SkRect domain = SkRect::Make(*pixelDomain).makeInset(0.5, 0.5f); |
Brian Salomon | 5ed3c2f | 2020-04-13 16:51:39 -0400 | [diff] [blame] | 154 | switch (dir) { |
Brian Salomon | 11ad4cc | 2020-05-15 12:07:59 -0400 | [diff] [blame] | 155 | case Direction::kX: domain.outset(halfWidth, 0); break; |
| 156 | case Direction::kY: domain.outset(0, halfWidth); break; |
Brian Salomon | 5ed3c2f | 2020-04-13 16:51:39 -0400 | [diff] [blame] | 157 | } |
| 158 | child = GrTextureEffect::MakeSubset(std::move(view), alphaType, SkMatrix::I(), sampler, |
Brian Salomon | 11ad4cc | 2020-05-15 12:07:59 -0400 | [diff] [blame] | 159 | SkRect::Make(subset), domain, caps); |
Brian Salomon | 5ed3c2f | 2020-04-13 16:51:39 -0400 | [diff] [blame] | 160 | } else { |
Brian Salomon | 11ad4cc | 2020-05-15 12:07:59 -0400 | [diff] [blame] | 161 | child = GrTextureEffect::MakeSubset(std::move(view), alphaType, SkMatrix::I(), sampler, |
| 162 | SkRect::Make(subset), caps); |
Brian Salomon | 5ed3c2f | 2020-04-13 16:51:39 -0400 | [diff] [blame] | 163 | } |
Michael Ludwig | e267464 | 2020-10-21 13:01:34 -0400 | [diff] [blame] | 164 | |
Albert Chaulk | 52b9e81 | 2021-04-12 17:23:25 -0400 | [diff] [blame] | 165 | if (is_zero_sigma) { |
Michael Ludwig | e267464 | 2020-10-21 13:01:34 -0400 | [diff] [blame] | 166 | return child; |
| 167 | } |
Brian Salomon | 5ed3c2f | 2020-04-13 16:51:39 -0400 | [diff] [blame] | 168 | return std::unique_ptr<GrFragmentProcessor>(new GrGaussianConvolutionFragmentProcessor( |
| 169 | std::move(child), dir, halfWidth, gaussianSigma)); |
| 170 | } |
| 171 | |
| 172 | GrGaussianConvolutionFragmentProcessor::GrGaussianConvolutionFragmentProcessor( |
| 173 | std::unique_ptr<GrFragmentProcessor> child, |
Brian Salomon | fc11844 | 2019-11-22 19:09:27 -0500 | [diff] [blame] | 174 | Direction direction, |
| 175 | int radius, |
Brian Salomon | 5ed3c2f | 2020-04-13 16:51:39 -0400 | [diff] [blame] | 176 | float gaussianSigma) |
Ethan Nicholas | abff956 | 2017-10-09 10:54:08 -0400 | [diff] [blame] | 177 | : INHERITED(kGrGaussianConvolutionFragmentProcessor_ClassID, |
Brian Salomon | 5ed3c2f | 2020-04-13 16:51:39 -0400 | [diff] [blame] | 178 | ProcessorOptimizationFlags(child.get())) |
Brian Salomon | b133ffe | 2017-07-27 11:53:21 -0400 | [diff] [blame] | 179 | , fRadius(radius) |
Brian Salomon | 5ed3c2f | 2020-04-13 16:51:39 -0400 | [diff] [blame] | 180 | , fDirection(direction) { |
Brian Osman | 1298bc4 | 2020-06-30 13:39:35 -0400 | [diff] [blame] | 181 | this->registerChild(std::move(child), SkSL::SampleUsage::Explicit()); |
Brian Salomon | 6862643 | 2020-04-15 12:56:13 +0000 | [diff] [blame] | 182 | SkASSERT(radius <= kMaxKernelRadius); |
Albert Chaulk | 52b9e81 | 2021-04-12 17:23:25 -0400 | [diff] [blame] | 183 | #if defined(SK_DISABLE_BILINEAR_BLUR_OPTIMIZATION) |
Michael Ludwig | e267464 | 2020-10-21 13:01:34 -0400 | [diff] [blame] | 184 | SkGpuBlurUtils::Compute1DGaussianKernel(fKernel, gaussianSigma, fRadius); |
Albert Chaulk | 52b9e81 | 2021-04-12 17:23:25 -0400 | [diff] [blame] | 185 | #else |
| 186 | SkGpuBlurUtils::Compute1DLinearGaussianKernel(fKernel, fOffsets, gaussianSigma, fRadius); |
| 187 | #endif |
Michael Ludwig | fbe2859 | 2020-06-26 16:02:15 -0400 | [diff] [blame] | 188 | this->setUsesSampleCoordsDirectly(); |
tomhudson@google.com | fde2c0a | 2012-07-16 12:23:32 +0000 | [diff] [blame] | 189 | } |
| 190 | |
Brian Salomon | 3f6f965 | 2017-07-28 07:34:05 -0400 | [diff] [blame] | 191 | GrGaussianConvolutionFragmentProcessor::GrGaussianConvolutionFragmentProcessor( |
| 192 | const GrGaussianConvolutionFragmentProcessor& that) |
Ethan Nicholas | abff956 | 2017-10-09 10:54:08 -0400 | [diff] [blame] | 193 | : INHERITED(kGrGaussianConvolutionFragmentProcessor_ClassID, that.optimizationFlags()) |
Brian Salomon | 3f6f965 | 2017-07-28 07:34:05 -0400 | [diff] [blame] | 194 | , fRadius(that.fRadius) |
Brian Salomon | 5ed3c2f | 2020-04-13 16:51:39 -0400 | [diff] [blame] | 195 | , fDirection(that.fDirection) { |
Michael Ludwig | 9aba625 | 2020-06-22 14:46:36 -0400 | [diff] [blame] | 196 | this->cloneAndRegisterAllChildProcessors(that); |
Albert Chaulk | 52b9e81 | 2021-04-12 17:23:25 -0400 | [diff] [blame] | 197 | #if defined(SK_DISABLE_BILINEAR_BLUR_OPTIMIZATION) |
Michael Ludwig | e267464 | 2020-10-21 13:01:34 -0400 | [diff] [blame] | 198 | memcpy(fKernel, that.fKernel, SkGpuBlurUtils::KernelWidth(fRadius) * sizeof(float)); |
Albert Chaulk | 52b9e81 | 2021-04-12 17:23:25 -0400 | [diff] [blame] | 199 | #else |
| 200 | memcpy(fKernel, that.fKernel, SkGpuBlurUtils::LinearKernelWidth(fRadius) * sizeof(float)); |
| 201 | memcpy(fOffsets, that.fOffsets, SkGpuBlurUtils::LinearKernelWidth(fRadius) * sizeof(float)); |
| 202 | #endif |
Michael Ludwig | fbe2859 | 2020-06-26 16:02:15 -0400 | [diff] [blame] | 203 | this->setUsesSampleCoordsDirectly(); |
Brian Salomon | 3f6f965 | 2017-07-28 07:34:05 -0400 | [diff] [blame] | 204 | } |
tomhudson@google.com | d8f856c | 2012-05-10 12:13:36 +0000 | [diff] [blame] | 205 | |
Brian Salomon | aee504b | 2017-01-24 12:29:36 -0500 | [diff] [blame] | 206 | void GrGaussianConvolutionFragmentProcessor::onGetGLSLProcessorKey(const GrShaderCaps& caps, |
| 207 | GrProcessorKeyBuilder* b) const { |
Brian Salomon | 08cb4bf | 2020-05-07 15:34:15 -0400 | [diff] [blame] | 208 | Impl::GenKey(*this, caps, b); |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 209 | } |
| 210 | |
Brian Salomon | 18ab203 | 2021-02-23 10:07:05 -0500 | [diff] [blame] | 211 | std::unique_ptr<GrGLSLFragmentProcessor> |
| 212 | GrGaussianConvolutionFragmentProcessor::onMakeProgramImpl() const { |
| 213 | return std::make_unique<Impl>(); |
tomhudson@google.com | d8f856c | 2012-05-10 12:13:36 +0000 | [diff] [blame] | 214 | } |
| 215 | |
Brian Salomon | aee504b | 2017-01-24 12:29:36 -0500 | [diff] [blame] | 216 | bool GrGaussianConvolutionFragmentProcessor::onIsEqual(const GrFragmentProcessor& sBase) const { |
Brian Salomon | 5ed3c2f | 2020-04-13 16:51:39 -0400 | [diff] [blame] | 217 | const auto& that = sBase.cast<GrGaussianConvolutionFragmentProcessor>(); |
Albert Chaulk | 52b9e81 | 2021-04-12 17:23:25 -0400 | [diff] [blame] | 218 | #if defined(SK_DISABLE_BILINEAR_BLUR_OPTIMIZATION) |
Brian Salomon | 08cb4bf | 2020-05-07 15:34:15 -0400 | [diff] [blame] | 219 | return fRadius == that.fRadius && fDirection == that.fDirection && |
Michael Ludwig | e267464 | 2020-10-21 13:01:34 -0400 | [diff] [blame] | 220 | std::equal(fKernel, fKernel + SkGpuBlurUtils::KernelWidth(fRadius), that.fKernel); |
Albert Chaulk | 52b9e81 | 2021-04-12 17:23:25 -0400 | [diff] [blame] | 221 | #else |
| 222 | return fRadius == that.fRadius && fDirection == that.fDirection && |
| 223 | std::equal(fKernel, fKernel + SkGpuBlurUtils::LinearKernelWidth(fRadius), that.fKernel) && |
| 224 | std::equal(fOffsets, fOffsets + SkGpuBlurUtils::LinearKernelWidth(fRadius), that.fOffsets); |
| 225 | #endif |
tomhudson@google.com | d8f856c | 2012-05-10 12:13:36 +0000 | [diff] [blame] | 226 | } |
bsalomon@google.com | 0a7672f | 2012-08-03 18:12:20 +0000 | [diff] [blame] | 227 | |
| 228 | /////////////////////////////////////////////////////////////////////////////// |
| 229 | |
Brian Salomon | aee504b | 2017-01-24 12:29:36 -0500 | [diff] [blame] | 230 | GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrGaussianConvolutionFragmentProcessor); |
bsalomon@google.com | 0a7672f | 2012-08-03 18:12:20 +0000 | [diff] [blame] | 231 | |
Hal Canary | 6f6961e | 2017-01-31 13:50:44 -0500 | [diff] [blame] | 232 | #if GR_TEST_UTILS |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 233 | std::unique_ptr<GrFragmentProcessor> GrGaussianConvolutionFragmentProcessor::TestCreate( |
Brian Salomon | aee504b | 2017-01-24 12:29:36 -0500 | [diff] [blame] | 234 | GrProcessorTestData* d) { |
Greg Daniel | 026a60c | 2020-02-12 10:53:51 -0500 | [diff] [blame] | 235 | auto [view, ct, at] = d->randomView(); |
Brian Salomon | aee504b | 2017-01-24 12:29:36 -0500 | [diff] [blame] | 236 | |
Brian Salomon | 11ad4cc | 2020-05-15 12:07:59 -0400 | [diff] [blame] | 237 | Direction dir = d->fRandom->nextBool() ? Direction::kY : Direction::kX; |
| 238 | SkIRect subset{ |
| 239 | static_cast<int>(d->fRandom->nextRangeU(0, view.width() - 1)), |
| 240 | static_cast<int>(d->fRandom->nextRangeU(0, view.height() - 1)), |
| 241 | static_cast<int>(d->fRandom->nextRangeU(0, view.width() - 1)), |
| 242 | static_cast<int>(d->fRandom->nextRangeU(0, view.height() - 1)), |
| 243 | }; |
| 244 | subset.sort(); |
Brian Salomon | 6862643 | 2020-04-15 12:56:13 +0000 | [diff] [blame] | 245 | |
Brian Salomon | 5ed3c2f | 2020-04-13 16:51:39 -0400 | [diff] [blame] | 246 | auto wm = static_cast<GrSamplerState::WrapMode>( |
| 247 | d->fRandom->nextULessThan(GrSamplerState::kWrapModeCount)); |
Robert Phillips | 08c5ec7 | 2017-01-30 12:26:47 -0500 | [diff] [blame] | 248 | int radius = d->fRandom->nextRangeU(1, kMaxKernelRadius); |
Brian Salomon | aee504b | 2017-01-24 12:29:36 -0500 | [diff] [blame] | 249 | float sigma = radius / 3.f; |
Brian Salomon | 11ad4cc | 2020-05-15 12:07:59 -0400 | [diff] [blame] | 250 | SkIRect temp; |
| 251 | SkIRect* domain = nullptr; |
| 252 | if (d->fRandom->nextBool()) { |
| 253 | temp = { |
| 254 | static_cast<int>(d->fRandom->nextRangeU(0, view.width() - 1)), |
| 255 | static_cast<int>(d->fRandom->nextRangeU(0, view.height() - 1)), |
| 256 | static_cast<int>(d->fRandom->nextRangeU(0, view.width() - 1)), |
| 257 | static_cast<int>(d->fRandom->nextRangeU(0, view.height() - 1)), |
| 258 | }; |
| 259 | temp.sort(); |
| 260 | domain = &temp; |
| 261 | } |
Robert Phillips | 08c5ec7 | 2017-01-30 12:26:47 -0500 | [diff] [blame] | 262 | |
Brian Salomon | 5ed3c2f | 2020-04-13 16:51:39 -0400 | [diff] [blame] | 263 | return GrGaussianConvolutionFragmentProcessor::Make(std::move(view), at, dir, radius, sigma, wm, |
Brian Salomon | 11ad4cc | 2020-05-15 12:07:59 -0400 | [diff] [blame] | 264 | subset, domain, *d->caps()); |
bsalomon@google.com | 0a7672f | 2012-08-03 18:12:20 +0000 | [diff] [blame] | 265 | } |
Hal Canary | 6f6961e | 2017-01-31 13:50:44 -0500 | [diff] [blame] | 266 | #endif |