blob: 57e0fd9a720a56f73bf98eb7926b6981274460de [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
11#include "GrSingleTextureEffect.h"
joshualitt5ae5fc52014-07-29 12:59:27 -070012#include "GrTextureDomain.h"
joshualittac977922014-07-22 09:52:11 -070013
14// A little bit less than the minimum # uniforms required by DX9SM2 (32).
15// Allows for a 5x5 kernel (or 25x1, for that matter).
16#define MAX_KERNEL_SIZE 25
17
joshualittac977922014-07-22 09:52:11 -070018class GrMatrixConvolutionEffect : public GrSingleTextureEffect {
19public:
Robert Phillipsfbcef6e2017-06-15 12:07:18 -040020 static sk_sp<GrFragmentProcessor> Make(sk_sp<GrTextureProxy> proxy,
Robert Phillips40fd7c92017-01-30 08:06:27 -050021 const SkIRect& bounds,
22 const SkISize& kernelSize,
23 const SkScalar* kernel,
24 SkScalar gain,
25 SkScalar bias,
26 const SkIPoint& kernelOffset,
27 GrTextureDomain::Mode tileMode,
28 bool convolveAlpha) {
29 return sk_sp<GrFragmentProcessor>(
Robert Phillipsfbcef6e2017-06-15 12:07:18 -040030 new GrMatrixConvolutionEffect(std::move(proxy), bounds, kernelSize,
Robert Phillips296b1cc2017-03-15 10:42:12 -040031 kernel, gain, bias, kernelOffset, tileMode, convolveAlpha));
Robert Phillips40fd7c92017-01-30 08:06:27 -050032 }
33
Robert Phillipsfbcef6e2017-06-15 12:07:18 -040034 static sk_sp<GrFragmentProcessor> MakeGaussian(sk_sp<GrTextureProxy> proxy,
Robert Phillips40fd7c92017-01-30 08:06:27 -050035 const SkIRect& bounds,
36 const SkISize& kernelSize,
37 SkScalar gain,
38 SkScalar bias,
39 const SkIPoint& kernelOffset,
40 GrTextureDomain::Mode tileMode,
41 bool convolveAlpha,
42 SkScalar sigmaX,
43 SkScalar sigmaY);
44
joshualittac977922014-07-22 09:52:11 -070045 const SkIRect& bounds() const { return fBounds; }
46 const SkISize& kernelSize() const { return fKernelSize; }
47 const float* kernelOffset() const { return fKernelOffset; }
48 const float* kernel() const { return fKernel; }
49 float gain() const { return fGain; }
50 float bias() const { return fBias; }
joshualittac977922014-07-22 09:52:11 -070051 bool convolveAlpha() const { return fConvolveAlpha; }
joshualitt5ae5fc52014-07-29 12:59:27 -070052 const GrTextureDomain& domain() const { return fDomain; }
joshualittac977922014-07-22 09:52:11 -070053
mtklein36352bf2015-03-25 18:17:31 -070054 const char* name() const override { return "MatrixConvolution"; }
joshualittac977922014-07-22 09:52:11 -070055
joshualittac977922014-07-22 09:52:11 -070056private:
Robert Phillipsfbcef6e2017-06-15 12:07:18 -040057 GrMatrixConvolutionEffect(sk_sp<GrTextureProxy> proxy,
Robert Phillips40fd7c92017-01-30 08:06:27 -050058 const SkIRect& bounds,
59 const SkISize& kernelSize,
60 const SkScalar* kernel,
61 SkScalar gain,
62 SkScalar bias,
63 const SkIPoint& kernelOffset,
64 GrTextureDomain::Mode tileMode,
65 bool convolveAlpha);
66
egdaniel57d3b032015-11-13 11:57:27 -080067 GrGLSLFragmentProcessor* onCreateGLSLInstance() const override;
wangyixb1daa862015-08-18 11:29:31 -070068
Brian Salomon94efbf52016-11-29 13:43:05 -050069 void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override;
wangyix4b3050b2015-08-04 07:59:37 -070070
mtklein36352bf2015-03-25 18:17:31 -070071 bool onIsEqual(const GrFragmentProcessor&) const override;
joshualittac977922014-07-22 09:52:11 -070072
joshualitt5ae5fc52014-07-29 12:59:27 -070073 SkIRect fBounds;
74 SkISize fKernelSize;
joshualitt5acfea72014-08-11 13:55:34 -070075 float fKernel[MAX_KERNEL_SIZE];
joshualitt5ae5fc52014-07-29 12:59:27 -070076 float fGain;
77 float fBias;
78 float fKernelOffset[2];
79 bool fConvolveAlpha;
80 GrTextureDomain fDomain;
joshualittac977922014-07-22 09:52:11 -070081
Brian Salomon0c26a9d2017-07-06 10:09:38 -040082 GR_DECLARE_FRAGMENT_PROCESSOR_TEST
joshualittac977922014-07-22 09:52:11 -070083
84 typedef GrSingleTextureEffect INHERITED;
85};
86
87#endif