aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu/effects/GrGaussianConvolutionFragmentProcessor.h
diff options
context:
space:
mode:
authorGravatar Brian Salomon <bsalomon@google.com>2017-01-24 12:29:36 -0500
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-01-24 17:59:54 +0000
commitaee504beb2185e7297b30c02a1541d1306196416 (patch)
tree6818d12e83a3f0f1cb9ad5576bf0a789855278a6 /src/gpu/effects/GrGaussianConvolutionFragmentProcessor.h
parent5d72f7deb1807c4ee1c1d0901124d5ea07e556f2 (diff)
Make GrConvolutionEffect only support Gaussian kernels and rename.
Change-Id: Ia874ad5bacc550b7ecec579719242e3354dca34b Reviewed-on: https://skia-review.googlesource.com/7432 Reviewed-by: Robert Phillips <robertphillips@google.com> Commit-Queue: Brian Salomon <bsalomon@google.com>
Diffstat (limited to 'src/gpu/effects/GrGaussianConvolutionFragmentProcessor.h')
-rw-r--r--src/gpu/effects/GrGaussianConvolutionFragmentProcessor.h78
1 files changed, 78 insertions, 0 deletions
diff --git a/src/gpu/effects/GrGaussianConvolutionFragmentProcessor.h b/src/gpu/effects/GrGaussianConvolutionFragmentProcessor.h
new file mode 100644
index 0000000000..da40ec2b93
--- /dev/null
+++ b/src/gpu/effects/GrGaussianConvolutionFragmentProcessor.h
@@ -0,0 +1,78 @@
+/*
+ * Copyright 2012 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef GrGaussianConvolutionFragmentProcessor_DEFINED
+#define GrGaussianConvolutionFragmentProcessor_DEFINED
+
+#include "Gr1DKernelEffect.h"
+#include "GrInvariantOutput.h"
+
+/**
+ * A 1D Gaussian convolution effect. The kernel is computed as an array of 2 * half-width weights.
+ * Each texel is multiplied by it's weight and summed to determine the filtered color. The output
+ * color is set to a modulation of the filtered and input colors.
+ */
+class GrGaussianConvolutionFragmentProcessor : public Gr1DKernelEffect {
+public:
+ /// Convolve with a Gaussian kernel
+ static sk_sp<GrFragmentProcessor> Make(GrTexture* tex,
+ Direction dir,
+ int halfWidth,
+ float gaussianSigma,
+ bool useBounds,
+ float* bounds) {
+ return sk_sp<GrFragmentProcessor>(new GrGaussianConvolutionFragmentProcessor(
+ tex, dir, halfWidth, gaussianSigma, useBounds, bounds));
+ }
+
+ virtual ~GrGaussianConvolutionFragmentProcessor();
+
+ const float* kernel() const { return fKernel; }
+
+ const float* bounds() const { return fBounds; }
+ bool useBounds() const { return fUseBounds; }
+
+ const char* name() const override { return "GaussianConvolution"; }
+
+ // This was decided based on the min allowed value for the max texture
+ // samples per fragment program run in DX9SM2 (32). A sigma param of 4.0
+ // on a blur filter gives a kernel width of 25 while a sigma of 5.0
+ // would exceed a 32 wide kernel.
+ static const int kMaxKernelRadius = 12;
+ // With a C++11 we could have a constexpr version of WidthFromRadius()
+ // and not have to duplicate this calculation.
+ static const int kMaxKernelWidth = 2 * kMaxKernelRadius + 1;
+
+private:
+ /// Convolve with a Gaussian kernel
+ GrGaussianConvolutionFragmentProcessor(GrTexture*, Direction, int halfWidth,
+ float gaussianSigma, bool useBounds, float bounds[2]);
+
+ GrGLSLFragmentProcessor* onCreateGLSLInstance() const override;
+
+ void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override;
+
+ bool onIsEqual(const GrFragmentProcessor&) const override;
+
+ void onComputeInvariantOutput(GrInvariantOutput* inout) const override {
+ // If the texture was opaque we could know that the output color if we knew the sum of the
+ // kernel values.
+ inout->mulByUnknownFourComponents();
+ }
+
+ GR_DECLARE_FRAGMENT_PROCESSOR_TEST;
+
+ // TODO: Inline the kernel constants into the generated shader code. This may involve pulling
+ // some of the logic from SkGpuBlurUtils into this class related to radius/sigma calculations.
+ float fKernel[kMaxKernelWidth];
+ bool fUseBounds;
+ float fBounds[2];
+
+ typedef Gr1DKernelEffect INHERITED;
+};
+
+#endif