blob: 9ece00ee5d3ce48bc2ea859c02dbe20c30aa5161 [file] [log] [blame]
joshualittac977922014-07-22 09:52:11 -07001/*
2 * Copyright 2014 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
8#ifndef GrMatrixConvolutionEffect_DEFINED
9#define GrMatrixConvolutionEffect_DEFINED
10
joshualitt5ae5fc52014-07-29 12:59:27 -070011#include "GrTextureDomain.h"
joshualittac977922014-07-22 09:52:11 -070012
13// A little bit less than the minimum # uniforms required by DX9SM2 (32).
14// Allows for a 5x5 kernel (or 25x1, for that matter).
15#define MAX_KERNEL_SIZE 25
16
Brian Salomon6cd51b52017-07-26 19:07:15 -040017class GrMatrixConvolutionEffect : public GrFragmentProcessor {
joshualittac977922014-07-22 09:52:11 -070018public:
Robert Phillipsfbcef6e2017-06-15 12:07:18 -040019 static sk_sp<GrFragmentProcessor> Make(sk_sp<GrTextureProxy> proxy,
Robert Phillips40fd7c92017-01-30 08:06:27 -050020 const SkIRect& bounds,
21 const SkISize& kernelSize,
22 const SkScalar* kernel,
23 SkScalar gain,
24 SkScalar bias,
25 const SkIPoint& kernelOffset,
26 GrTextureDomain::Mode tileMode,
27 bool convolveAlpha) {
28 return sk_sp<GrFragmentProcessor>(
Robert Phillipsfbcef6e2017-06-15 12:07:18 -040029 new GrMatrixConvolutionEffect(std::move(proxy), bounds, kernelSize,
Robert Phillips296b1cc2017-03-15 10:42:12 -040030 kernel, gain, bias, kernelOffset, tileMode, convolveAlpha));
Robert Phillips40fd7c92017-01-30 08:06:27 -050031 }
32
Robert Phillipsfbcef6e2017-06-15 12:07:18 -040033 static sk_sp<GrFragmentProcessor> MakeGaussian(sk_sp<GrTextureProxy> proxy,
Robert Phillips40fd7c92017-01-30 08:06:27 -050034 const SkIRect& bounds,
35 const SkISize& kernelSize,
36 SkScalar gain,
37 SkScalar bias,
38 const SkIPoint& kernelOffset,
39 GrTextureDomain::Mode tileMode,
40 bool convolveAlpha,
41 SkScalar sigmaX,
42 SkScalar sigmaY);
43
joshualittac977922014-07-22 09:52:11 -070044 const SkIRect& bounds() const { return fBounds; }
45 const SkISize& kernelSize() const { return fKernelSize; }
46 const float* kernelOffset() const { return fKernelOffset; }
47 const float* kernel() const { return fKernel; }
48 float gain() const { return fGain; }
49 float bias() const { return fBias; }
joshualittac977922014-07-22 09:52:11 -070050 bool convolveAlpha() const { return fConvolveAlpha; }
joshualitt5ae5fc52014-07-29 12:59:27 -070051 const GrTextureDomain& domain() const { return fDomain; }
joshualittac977922014-07-22 09:52:11 -070052
mtklein36352bf2015-03-25 18:17:31 -070053 const char* name() const override { return "MatrixConvolution"; }
joshualittac977922014-07-22 09:52:11 -070054
Brian Salomon3f6f9652017-07-28 07:34:05 -040055 sk_sp<GrFragmentProcessor> clone() const override;
56
joshualittac977922014-07-22 09:52:11 -070057private:
Robert Phillipsfbcef6e2017-06-15 12:07:18 -040058 GrMatrixConvolutionEffect(sk_sp<GrTextureProxy> proxy,
Robert Phillips40fd7c92017-01-30 08:06:27 -050059 const SkIRect& bounds,
60 const SkISize& kernelSize,
61 const SkScalar* kernel,
62 SkScalar gain,
63 SkScalar bias,
64 const SkIPoint& kernelOffset,
65 GrTextureDomain::Mode tileMode,
66 bool convolveAlpha);
67
Brian Salomon3f6f9652017-07-28 07:34:05 -040068 GrMatrixConvolutionEffect(const GrMatrixConvolutionEffect&);
69
egdaniel57d3b032015-11-13 11:57:27 -080070 GrGLSLFragmentProcessor* onCreateGLSLInstance() const override;
wangyixb1daa862015-08-18 11:29:31 -070071
Brian Salomon94efbf52016-11-29 13:43:05 -050072 void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override;
wangyix4b3050b2015-08-04 07:59:37 -070073
mtklein36352bf2015-03-25 18:17:31 -070074 bool onIsEqual(const GrFragmentProcessor&) const override;
joshualittac977922014-07-22 09:52:11 -070075
Brian Salomon6cd51b52017-07-26 19:07:15 -040076 GrCoordTransform fCoordTransform;
77 GrTextureDomain fDomain;
78 TextureSampler fTextureSampler;
79 SkIRect fBounds;
80 SkISize fKernelSize;
81 float fKernel[MAX_KERNEL_SIZE];
82 float fGain;
83 float fBias;
84 float fKernelOffset[2];
85 bool fConvolveAlpha;
joshualittac977922014-07-22 09:52:11 -070086
Brian Salomon0c26a9d2017-07-06 10:09:38 -040087 GR_DECLARE_FRAGMENT_PROCESSOR_TEST
joshualittac977922014-07-22 09:52:11 -070088
Brian Salomon6cd51b52017-07-26 19:07:15 -040089 typedef GrFragmentProcessor INHERITED;
joshualittac977922014-07-22 09:52:11 -070090};
91
92#endif