blob: 999606213d0abbf48fdeeff7ee01e0a4d839d4d1 [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"
egdaniel605dd0f2014-11-12 08:35:25 -080012#include "GrInvariantOutput.h"
joshualitt5ae5fc52014-07-29 12:59:27 -070013#include "GrTextureDomain.h"
joshualittac977922014-07-22 09:52:11 -070014
15// A little bit less than the minimum # uniforms required by DX9SM2 (32).
16// Allows for a 5x5 kernel (or 25x1, for that matter).
17#define MAX_KERNEL_SIZE 25
18
19class GrGLMatrixConvolutionEffect;
20
21class GrMatrixConvolutionEffect : public GrSingleTextureEffect {
22public:
joshualittb0a8a372014-09-23 09:50:21 -070023 static GrFragmentProcessor* Create(GrTexture* texture,
24 const SkIRect& bounds,
25 const SkISize& kernelSize,
26 const SkScalar* kernel,
27 SkScalar gain,
28 SkScalar bias,
29 const SkIPoint& kernelOffset,
30 GrTextureDomain::Mode tileMode,
31 bool convolveAlpha) {
joshualittac977922014-07-22 09:52:11 -070032 return SkNEW_ARGS(GrMatrixConvolutionEffect, (texture,
33 bounds,
34 kernelSize,
35 kernel,
36 gain,
37 bias,
38 kernelOffset,
39 tileMode,
40 convolveAlpha));
41 }
joshualitt5acfea72014-08-11 13:55:34 -070042
joshualittb0a8a372014-09-23 09:50:21 -070043 static GrFragmentProcessor* CreateGaussian(GrTexture* texture,
44 const SkIRect& bounds,
45 const SkISize& kernelSize,
46 SkScalar gain,
47 SkScalar bias,
48 const SkIPoint& kernelOffset,
49 GrTextureDomain::Mode tileMode,
50 bool convolveAlpha,
51 SkScalar sigmaX,
52 SkScalar sigmaY);
joshualitt5acfea72014-08-11 13:55:34 -070053
joshualittac977922014-07-22 09:52:11 -070054 virtual ~GrMatrixConvolutionEffect();
55
joshualittac977922014-07-22 09:52:11 -070056 static const char* Name() { return "MatrixConvolution"; }
57 const SkIRect& bounds() const { return fBounds; }
58 const SkISize& kernelSize() const { return fKernelSize; }
59 const float* kernelOffset() const { return fKernelOffset; }
60 const float* kernel() const { return fKernel; }
61 float gain() const { return fGain; }
62 float bias() const { return fBias; }
joshualittac977922014-07-22 09:52:11 -070063 bool convolveAlpha() const { return fConvolveAlpha; }
joshualitt5ae5fc52014-07-29 12:59:27 -070064 const GrTextureDomain& domain() const { return fDomain; }
joshualittac977922014-07-22 09:52:11 -070065
joshualittb0a8a372014-09-23 09:50:21 -070066 typedef GrGLMatrixConvolutionEffect GLProcessor;
joshualittac977922014-07-22 09:52:11 -070067
joshualittb0a8a372014-09-23 09:50:21 -070068 virtual const GrBackendFragmentProcessorFactory& getFactory() const SK_OVERRIDE;
joshualittac977922014-07-22 09:52:11 -070069
70private:
71 GrMatrixConvolutionEffect(GrTexture*,
72 const SkIRect& bounds,
73 const SkISize& kernelSize,
74 const SkScalar* kernel,
75 SkScalar gain,
76 SkScalar bias,
77 const SkIPoint& kernelOffset,
joshualitt5ae5fc52014-07-29 12:59:27 -070078 GrTextureDomain::Mode tileMode,
joshualittac977922014-07-22 09:52:11 -070079 bool convolveAlpha);
80
bsalomon0e08fc12014-10-15 08:19:04 -070081 virtual bool onIsEqual(const GrFragmentProcessor&) const SK_OVERRIDE;
joshualittac977922014-07-22 09:52:11 -070082
egdaniel605dd0f2014-11-12 08:35:25 -080083 virtual void onComputeInvariantOutput(GrInvariantOutput* inout) const SK_OVERRIDE {
egdaniel1a8ecdf2014-10-03 06:24:12 -070084 // TODO: Try to do better?
egdanielccb2e382014-10-13 12:53:46 -070085 inout->mulByUnknownColor();
egdaniel1a8ecdf2014-10-03 06:24:12 -070086 }
87
joshualitt5ae5fc52014-07-29 12:59:27 -070088 SkIRect fBounds;
89 SkISize fKernelSize;
joshualitt5acfea72014-08-11 13:55:34 -070090 float fKernel[MAX_KERNEL_SIZE];
joshualitt5ae5fc52014-07-29 12:59:27 -070091 float fGain;
92 float fBias;
93 float fKernelOffset[2];
94 bool fConvolveAlpha;
95 GrTextureDomain fDomain;
joshualittac977922014-07-22 09:52:11 -070096
joshualittb0a8a372014-09-23 09:50:21 -070097 GR_DECLARE_FRAGMENT_PROCESSOR_TEST;
joshualittac977922014-07-22 09:52:11 -070098
99 typedef GrSingleTextureEffect INHERITED;
100};
101
102#endif