OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #ifndef GrMatrixConvolutionEffect_DEFINED | 8 #ifndef GrMatrixConvolutionEffect_DEFINED |
9 #define GrMatrixConvolutionEffect_DEFINED | 9 #define GrMatrixConvolutionEffect_DEFINED |
10 | 10 |
11 #include "GrSingleTextureEffect.h" | 11 #include "GrSingleTextureEffect.h" |
12 #include "GrTextureDomain.h" | 12 #include "GrTextureDomain.h" |
13 | 13 |
14 // A little bit less than the minimum # uniforms required by DX9SM2 (32). | 14 // A little bit less than the minimum # uniforms required by DX9SM2 (32). |
15 // Allows for a 5x5 kernel (or 25x1, for that matter). | 15 // Allows for a 5x5 kernel (or 25x1, for that matter). |
16 #define MAX_KERNEL_SIZE 25 | 16 #define MAX_KERNEL_SIZE 25 |
17 | 17 |
18 class GrGLMatrixConvolutionEffect; | 18 class GrGLMatrixConvolutionEffect; |
19 | 19 |
20 class GrMatrixConvolutionEffect : public GrSingleTextureEffect { | 20 class GrMatrixConvolutionEffect : public GrSingleTextureEffect { |
21 public: | 21 public: |
22 static GrEffect* Create(GrTexture* texture, | 22 static GrFragmentProcessor* Create(GrTexture* texture, |
23 const SkIRect& bounds, | 23 const SkIRect& bounds, |
24 const SkISize& kernelSize, | 24 const SkISize& kernelSize, |
25 const SkScalar* kernel, | 25 const SkScalar* kernel, |
26 SkScalar gain, | 26 SkScalar gain, |
27 SkScalar bias, | 27 SkScalar bias, |
28 const SkIPoint& kernelOffset, | 28 const SkIPoint& kernelOffset, |
29 GrTextureDomain::Mode tileMode, | 29 GrTextureDomain::Mode tileMode, |
30 bool convolveAlpha) { | 30 bool convolveAlpha) { |
31 return SkNEW_ARGS(GrMatrixConvolutionEffect, (texture, | 31 return SkNEW_ARGS(GrMatrixConvolutionEffect, (texture, |
32 bounds, | 32 bounds, |
33 kernelSize, | 33 kernelSize, |
34 kernel, | 34 kernel, |
35 gain, | 35 gain, |
36 bias, | 36 bias, |
37 kernelOffset, | 37 kernelOffset, |
38 tileMode, | 38 tileMode, |
39 convolveAlpha)); | 39 convolveAlpha)); |
40 } | 40 } |
41 | 41 |
42 static GrEffect* CreateGaussian(GrTexture* texture, | 42 static GrFragmentProcessor* CreateGaussian(GrTexture* texture, |
43 const SkIRect& bounds, | 43 const SkIRect& bounds, |
44 const SkISize& kernelSize, | 44 const SkISize& kernelSize, |
45 SkScalar gain, | 45 SkScalar gain, |
46 SkScalar bias, | 46 SkScalar bias, |
47 const SkIPoint& kernelOffset, | 47 const SkIPoint& kernelOffset, |
48 GrTextureDomain::Mode tileMode, | 48 GrTextureDomain::Mode tileMode, |
49 bool convolveAlpha, | 49 bool convolveAlpha, |
50 SkScalar sigmaX, | 50 SkScalar sigmaX, |
51 SkScalar sigmaY); | 51 SkScalar sigmaY); |
52 | 52 |
53 virtual ~GrMatrixConvolutionEffect(); | 53 virtual ~GrMatrixConvolutionEffect(); |
54 | 54 |
55 virtual void getConstantColorComponents(GrColor* color, | 55 virtual void getConstantColorComponents(GrColor* color, |
56 uint32_t* validFlags) const SK_OVERR
IDE { | 56 uint32_t* validFlags) const SK_OVERR
IDE { |
57 // TODO: Try to do better? | 57 // TODO: Try to do better? |
58 *validFlags = 0; | 58 *validFlags = 0; |
59 } | 59 } |
60 | 60 |
61 static const char* Name() { return "MatrixConvolution"; } | 61 static const char* Name() { return "MatrixConvolution"; } |
62 const SkIRect& bounds() const { return fBounds; } | 62 const SkIRect& bounds() const { return fBounds; } |
63 const SkISize& kernelSize() const { return fKernelSize; } | 63 const SkISize& kernelSize() const { return fKernelSize; } |
64 const float* kernelOffset() const { return fKernelOffset; } | 64 const float* kernelOffset() const { return fKernelOffset; } |
65 const float* kernel() const { return fKernel; } | 65 const float* kernel() const { return fKernel; } |
66 float gain() const { return fGain; } | 66 float gain() const { return fGain; } |
67 float bias() const { return fBias; } | 67 float bias() const { return fBias; } |
68 bool convolveAlpha() const { return fConvolveAlpha; } | 68 bool convolveAlpha() const { return fConvolveAlpha; } |
69 const GrTextureDomain& domain() const { return fDomain; } | 69 const GrTextureDomain& domain() const { return fDomain; } |
70 | 70 |
71 typedef GrGLMatrixConvolutionEffect GLEffect; | 71 typedef GrGLMatrixConvolutionEffect GLProcessor; |
72 | 72 |
73 virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE; | 73 virtual const GrBackendFragmentProcessorFactory& getFactory() const SK_OVERR
IDE; |
74 | 74 |
75 private: | 75 private: |
76 GrMatrixConvolutionEffect(GrTexture*, | 76 GrMatrixConvolutionEffect(GrTexture*, |
77 const SkIRect& bounds, | 77 const SkIRect& bounds, |
78 const SkISize& kernelSize, | 78 const SkISize& kernelSize, |
79 const SkScalar* kernel, | 79 const SkScalar* kernel, |
80 SkScalar gain, | 80 SkScalar gain, |
81 SkScalar bias, | 81 SkScalar bias, |
82 const SkIPoint& kernelOffset, | 82 const SkIPoint& kernelOffset, |
83 GrTextureDomain::Mode tileMode, | 83 GrTextureDomain::Mode tileMode, |
84 bool convolveAlpha); | 84 bool convolveAlpha); |
85 | 85 |
86 virtual bool onIsEqual(const GrEffect&) const SK_OVERRIDE; | 86 virtual bool onIsEqual(const GrProcessor&) const SK_OVERRIDE; |
87 | 87 |
88 SkIRect fBounds; | 88 SkIRect fBounds; |
89 SkISize fKernelSize; | 89 SkISize fKernelSize; |
90 float fKernel[MAX_KERNEL_SIZE]; | 90 float fKernel[MAX_KERNEL_SIZE]; |
91 float fGain; | 91 float fGain; |
92 float fBias; | 92 float fBias; |
93 float fKernelOffset[2]; | 93 float fKernelOffset[2]; |
94 bool fConvolveAlpha; | 94 bool fConvolveAlpha; |
95 GrTextureDomain fDomain; | 95 GrTextureDomain fDomain; |
96 | 96 |
97 GR_DECLARE_EFFECT_TEST; | 97 GR_DECLARE_FRAGMENT_PROCESSOR_TEST; |
98 | 98 |
99 typedef GrSingleTextureEffect INHERITED; | 99 typedef GrSingleTextureEffect INHERITED; |
100 }; | 100 }; |
101 | 101 |
102 #endif | 102 #endif |
OLD | NEW |