blob: 212d5c09737b64f73276dadf8e23b0daa67513c5 [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
Mike Kleinc0bd9f92019-04-23 12:05:21 -050011#include "src/gpu/effects/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 Phillips5140f9a2018-05-11 16:11:45 -040019 static std::unique_ptr<GrFragmentProcessor> Make(sk_sp<GrTextureProxy> srcProxy,
20 const SkIRect& srcBounds,
Brian Salomonaff329b2017-08-11 09:40:37 -040021 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 std::unique_ptr<GrFragmentProcessor>(
Robert Phillips5140f9a2018-05-11 16:11:45 -040029 new GrMatrixConvolutionEffect(std::move(srcProxy), srcBounds, kernelSize, kernel,
30 gain, bias, kernelOffset, tileMode, convolveAlpha));
Robert Phillips40fd7c92017-01-30 08:06:27 -050031 }
32
Robert Phillips5140f9a2018-05-11 16:11:45 -040033 static std::unique_ptr<GrFragmentProcessor> MakeGaussian(sk_sp<GrTextureProxy> srcProxy,
34 const SkIRect& srcBounds,
Brian Salomonaff329b2017-08-11 09:40:37 -040035 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);
Robert Phillips40fd7c92017-01-30 08:06:27 -050043
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 Salomonaff329b2017-08-11 09:40:37 -040055 std::unique_ptr<GrFragmentProcessor> clone() const override;
Brian Salomon3f6f9652017-07-28 07:34:05 -040056
joshualittac977922014-07-22 09:52:11 -070057private:
Robert Phillips5140f9a2018-05-11 16:11:45 -040058 // srcProxy is the texture that is going to be convolved
59 // srcBounds is the subset of 'srcProxy' that will be used (e.g., for clamp mode)
60 GrMatrixConvolutionEffect(sk_sp<GrTextureProxy> srcProxy,
61 const SkIRect& srcBounds,
Robert Phillips40fd7c92017-01-30 08:06:27 -050062 const SkISize& kernelSize,
63 const SkScalar* kernel,
64 SkScalar gain,
65 SkScalar bias,
66 const SkIPoint& kernelOffset,
67 GrTextureDomain::Mode tileMode,
68 bool convolveAlpha);
69
Brian Salomon3f6f9652017-07-28 07:34:05 -040070 GrMatrixConvolutionEffect(const GrMatrixConvolutionEffect&);
71
egdaniel57d3b032015-11-13 11:57:27 -080072 GrGLSLFragmentProcessor* onCreateGLSLInstance() const override;
wangyixb1daa862015-08-18 11:29:31 -070073
Brian Salomon94efbf52016-11-29 13:43:05 -050074 void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override;
wangyix4b3050b2015-08-04 07:59:37 -070075
mtklein36352bf2015-03-25 18:17:31 -070076 bool onIsEqual(const GrFragmentProcessor&) const override;
joshualittac977922014-07-22 09:52:11 -070077
Brian Salomonf7dcd762018-07-30 14:48:15 -040078 const TextureSampler& onTextureSampler(int i) const override { return fTextureSampler; }
79
Brian Salomon6cd51b52017-07-26 19:07:15 -040080 GrCoordTransform fCoordTransform;
81 GrTextureDomain fDomain;
82 TextureSampler fTextureSampler;
83 SkIRect fBounds;
84 SkISize fKernelSize;
85 float fKernel[MAX_KERNEL_SIZE];
86 float fGain;
87 float fBias;
88 float fKernelOffset[2];
89 bool fConvolveAlpha;
joshualittac977922014-07-22 09:52:11 -070090
Brian Salomon0c26a9d2017-07-06 10:09:38 -040091 GR_DECLARE_FRAGMENT_PROCESSOR_TEST
joshualittac977922014-07-22 09:52:11 -070092
Brian Salomon6cd51b52017-07-26 19:07:15 -040093 typedef GrFragmentProcessor INHERITED;
joshualittac977922014-07-22 09:52:11 -070094};
95
96#endif