blob: 814299f2d1c182887b85edc5cf66dc25bb3ff5e5 [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
18class GrGLMatrixConvolutionEffect;
19
20class GrMatrixConvolutionEffect : public GrSingleTextureEffect {
21public:
joshualittac977922014-07-22 09:52:11 -070022 static GrEffect* Create(GrTexture* texture,
23 const SkIRect& bounds,
24 const SkISize& kernelSize,
25 const SkScalar* kernel,
26 SkScalar gain,
27 SkScalar bias,
28 const SkIPoint& kernelOffset,
joshualitt5ae5fc52014-07-29 12:59:27 -070029 GrTextureDomain::Mode tileMode,
joshualittac977922014-07-22 09:52:11 -070030 bool convolveAlpha) {
31 return SkNEW_ARGS(GrMatrixConvolutionEffect, (texture,
32 bounds,
33 kernelSize,
34 kernel,
35 gain,
36 bias,
37 kernelOffset,
38 tileMode,
39 convolveAlpha));
40 }
joshualitt5acfea72014-08-11 13:55:34 -070041
42 static GrEffect* CreateGaussian(GrTexture* texture,
43 const SkIRect& bounds,
44 const SkISize& kernelSize,
45 SkScalar gain,
46 SkScalar bias,
47 const SkIPoint& kernelOffset,
48 GrTextureDomain::Mode tileMode,
49 bool convolveAlpha,
50 SkScalar sigmaX,
51 SkScalar sigmaY);
52
joshualittac977922014-07-22 09:52:11 -070053 virtual ~GrMatrixConvolutionEffect();
54
55 virtual void getConstantColorComponents(GrColor* color,
56 uint32_t* validFlags) const SK_OVERRIDE {
57 // TODO: Try to do better?
58 *validFlags = 0;
59 }
60
61 static const char* Name() { return "MatrixConvolution"; }
62 const SkIRect& bounds() const { return fBounds; }
63 const SkISize& kernelSize() const { return fKernelSize; }
64 const float* kernelOffset() const { return fKernelOffset; }
65 const float* kernel() const { return fKernel; }
66 float gain() const { return fGain; }
67 float bias() const { return fBias; }
joshualittac977922014-07-22 09:52:11 -070068 bool convolveAlpha() const { return fConvolveAlpha; }
joshualitt5ae5fc52014-07-29 12:59:27 -070069 const GrTextureDomain& domain() const { return fDomain; }
joshualittac977922014-07-22 09:52:11 -070070
71 typedef GrGLMatrixConvolutionEffect GLEffect;
72
73 virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE;
74
75private:
76 GrMatrixConvolutionEffect(GrTexture*,
77 const SkIRect& bounds,
78 const SkISize& kernelSize,
79 const SkScalar* kernel,
80 SkScalar gain,
81 SkScalar bias,
82 const SkIPoint& kernelOffset,
joshualitt5ae5fc52014-07-29 12:59:27 -070083 GrTextureDomain::Mode tileMode,
joshualittac977922014-07-22 09:52:11 -070084 bool convolveAlpha);
85
86 virtual bool onIsEqual(const GrEffect&) const SK_OVERRIDE;
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
97 GR_DECLARE_EFFECT_TEST;
98
99 typedef GrSingleTextureEffect INHERITED;
100};
101
102#endif