blob: a89d640b5246d8d97e3131d84657bbbbb4683971 [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
joshualittac977922014-07-22 09:52:11 -070055private:
Robert Phillipsfbcef6e2017-06-15 12:07:18 -040056 GrMatrixConvolutionEffect(sk_sp<GrTextureProxy> proxy,
Robert Phillips40fd7c92017-01-30 08:06:27 -050057 const SkIRect& bounds,
58 const SkISize& kernelSize,
59 const SkScalar* kernel,
60 SkScalar gain,
61 SkScalar bias,
62 const SkIPoint& kernelOffset,
63 GrTextureDomain::Mode tileMode,
64 bool convolveAlpha);
65
egdaniel57d3b032015-11-13 11:57:27 -080066 GrGLSLFragmentProcessor* onCreateGLSLInstance() const override;
wangyixb1daa862015-08-18 11:29:31 -070067
Brian Salomon94efbf52016-11-29 13:43:05 -050068 void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override;
wangyix4b3050b2015-08-04 07:59:37 -070069
mtklein36352bf2015-03-25 18:17:31 -070070 bool onIsEqual(const GrFragmentProcessor&) const override;
joshualittac977922014-07-22 09:52:11 -070071
Brian Salomon6cd51b52017-07-26 19:07:15 -040072 GrCoordTransform fCoordTransform;
73 GrTextureDomain fDomain;
74 TextureSampler fTextureSampler;
75 SkIRect fBounds;
76 SkISize fKernelSize;
77 float fKernel[MAX_KERNEL_SIZE];
78 float fGain;
79 float fBias;
80 float fKernelOffset[2];
81 bool fConvolveAlpha;
joshualittac977922014-07-22 09:52:11 -070082
Brian Salomon0c26a9d2017-07-06 10:09:38 -040083 GR_DECLARE_FRAGMENT_PROCESSOR_TEST
joshualittac977922014-07-22 09:52:11 -070084
Brian Salomon6cd51b52017-07-26 19:07:15 -040085 typedef GrFragmentProcessor INHERITED;
joshualittac977922014-07-22 09:52:11 -070086};
87
88#endif