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 | 12 |
13 // A little bit less than the minimum # uniforms required by DX9SM2 (32). | 13 // A little bit less than the minimum # uniforms required by DX9SM2 (32). |
14 // Allows for a 5x5 kernel (or 25x1, for that matter). | 14 // Allows for a 5x5 kernel (or 25x1, for that matter). |
| 15 // TODO make maximum kernel size a GLCap |
15 #define MAX_KERNEL_SIZE 25 | 16 #define MAX_KERNEL_SIZE 25 |
16 | 17 |
17 class GrGLMatrixConvolutionEffect; | 18 class GrGLMatrixConvolutionEffect; |
18 | 19 |
19 class GrMatrixConvolutionEffect : public GrSingleTextureEffect { | 20 class GrMatrixConvolutionEffect : public GrSingleTextureEffect { |
20 public: | 21 public: |
21 /*! \enum TileMode */ | 22 /*! \enum TileMode */ |
| 23 //TODO expand texture domain class to add ClampToColor and Repeat and then c
lean this up |
22 enum TileMode { | 24 enum TileMode { |
23 kClamp_TileMode = 0, /*!< Clamp to the image's edge pixels. */ | 25 kClamp_TileMode = 0, /*!< Clamp to the image's edge pixels. */ |
24 kRepeat_TileMode, /*!< Wrap around to the image's opposite edge.
*/ | 26 kRepeat_TileMode, /*!< Wrap around to the image's opposite edge.
*/ |
25 kClampToBlack_TileMode, /*!< Fill with transparent black. */ | 27 kClampToBlack_TileMode, /*!< Fill with transparent black. */ |
26 kMax_TileMode = kClampToBlack_TileMode | 28 kMax_TileMode = kClampToBlack_TileMode |
27 }; | 29 }; |
28 | 30 |
29 typedef GrMatrixConvolutionEffect::TileMode TileMode; | 31 typedef GrMatrixConvolutionEffect::TileMode TileMode; |
| 32 |
| 33 /// Convolve with arbitrary user specified kernel |
30 static GrEffect* Create(GrTexture* texture, | 34 static GrEffect* Create(GrTexture* texture, |
31 const SkIRect& bounds, | 35 const SkIRect& bounds, |
32 const SkISize& kernelSize, | 36 const SkISize& kernelSize, |
33 const SkScalar* kernel, | 37 const SkScalar* kernel, |
34 SkScalar gain, | 38 SkScalar gain, |
35 SkScalar bias, | 39 SkScalar bias, |
36 const SkIPoint& kernelOffset, | 40 const SkIPoint& kernelOffset, |
37 TileMode tileMode, | 41 TileMode tileMode, |
38 bool convolveAlpha) { | 42 bool convolveAlpha, |
| 43 bool useBounds) { |
39 return SkNEW_ARGS(GrMatrixConvolutionEffect, (texture, | 44 return SkNEW_ARGS(GrMatrixConvolutionEffect, (texture, |
40 bounds, | 45 bounds, |
41 kernelSize, | 46 kernelSize, |
42 kernel, | 47 kernel, |
43 gain, | 48 gain, |
44 bias, | 49 bias, |
45 kernelOffset, | 50 kernelOffset, |
46 tileMode, | 51 tileMode, |
47 convolveAlpha)); | 52 convolveAlpha, |
| 53 useBounds)); |
48 } | 54 } |
| 55 |
| 56 /// Convolve with a Gaussian kernel |
| 57 static GrEffect* CreateGaussian(GrTexture* texture, |
| 58 const SkIRect& bounds, |
| 59 const SkISize& kernelSize, |
| 60 SkScalar gain, |
| 61 SkScalar bias, |
| 62 const SkIPoint& kernelOffset, |
| 63 TileMode tileMode, |
| 64 bool convolveAlpha, |
| 65 bool useBounds, |
| 66 SkScalar sigmaX, |
| 67 SkScalar sigmaY) { |
| 68 return SkNEW_ARGS(GrMatrixConvolutionEffect, (texture, |
| 69 bounds, |
| 70 kernelSize, |
| 71 gain, |
| 72 bias, |
| 73 kernelOffset, |
| 74 tileMode, |
| 75 convolveAlpha, |
| 76 useBounds, |
| 77 sigmaX, |
| 78 sigmaY)); |
| 79 } |
| 80 |
49 virtual ~GrMatrixConvolutionEffect(); | 81 virtual ~GrMatrixConvolutionEffect(); |
50 | 82 |
51 virtual void getConstantColorComponents(GrColor* color, | 83 virtual void getConstantColorComponents(GrColor* color, |
52 uint32_t* validFlags) const SK_OVERR
IDE { | 84 uint32_t* validFlags) const SK_OVERR
IDE { |
53 // TODO: Try to do better? | 85 // TODO: Try to do better? |
54 *validFlags = 0; | 86 *validFlags = 0; |
55 } | 87 } |
56 | 88 |
57 static const char* Name() { return "MatrixConvolution"; } | 89 static const char* Name() { return "MatrixConvolution"; } |
58 const SkIRect& bounds() const { return fBounds; } | 90 const SkIRect& bounds() const { return fBounds; } |
59 const SkISize& kernelSize() const { return fKernelSize; } | 91 const SkISize& kernelSize() const { return fKernelSize; } |
60 const float* kernelOffset() const { return fKernelOffset; } | 92 const float* kernelOffset() const { return fKernelOffset; } |
61 const float* kernel() const { return fKernel; } | 93 const float* kernel() const { return fKernel; } |
62 float gain() const { return fGain; } | 94 float gain() const { return fGain; } |
63 float bias() const { return fBias; } | 95 float bias() const { return fBias; } |
64 TileMode tileMode() const { return fTileMode; } | 96 TileMode tileMode() const { return fTileMode; } |
65 bool convolveAlpha() const { return fConvolveAlpha; } | 97 bool convolveAlpha() const { return fConvolveAlpha; } |
| 98 bool useBounds() const { return fUseBounds; } |
66 | 99 |
67 typedef GrGLMatrixConvolutionEffect GLEffect; | 100 typedef GrGLMatrixConvolutionEffect GLEffect; |
68 | 101 |
69 virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE; | 102 virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE; |
70 | 103 |
71 private: | 104 private: |
72 GrMatrixConvolutionEffect(GrTexture*, | 105 GrMatrixConvolutionEffect(GrTexture*, |
73 const SkIRect& bounds, | 106 const SkIRect& bounds, |
74 const SkISize& kernelSize, | 107 const SkISize& kernelSize, |
75 const SkScalar* kernel, | 108 const SkScalar* kernel, |
76 SkScalar gain, | 109 SkScalar gain, |
77 SkScalar bias, | 110 SkScalar bias, |
78 const SkIPoint& kernelOffset, | 111 const SkIPoint& kernelOffset, |
79 TileMode tileMode, | 112 TileMode tileMode, |
80 bool convolveAlpha); | 113 bool convolveAlpha, |
| 114 bool useBounds); |
| 115 |
| 116 GrMatrixConvolutionEffect(GrTexture*, |
| 117 const SkIRect& bounds, |
| 118 const SkISize& kernelSize, |
| 119 SkScalar gain, |
| 120 SkScalar bias, |
| 121 const SkIPoint& kernelOffset, |
| 122 TileMode tileMode, |
| 123 bool convolveAlpha, |
| 124 bool useBounds, |
| 125 SkScalar sigmaX, |
| 126 SkScalar sigmaY); |
81 | 127 |
82 virtual bool onIsEqual(const GrEffect&) const SK_OVERRIDE; | 128 virtual bool onIsEqual(const GrEffect&) const SK_OVERRIDE; |
83 | 129 |
84 SkIRect fBounds; | 130 SkIRect fBounds; |
85 SkISize fKernelSize; | 131 SkISize fKernelSize; |
86 float *fKernel; | 132 float fKernel[MAX_KERNEL_SIZE]; |
87 float fGain; | 133 float fGain; |
88 float fBias; | 134 float fBias; |
89 float fKernelOffset[2]; | 135 float fKernelOffset[2]; |
90 TileMode fTileMode; | 136 TileMode fTileMode; |
91 bool fConvolveAlpha; | 137 bool fConvolveAlpha; |
| 138 bool fUseBounds; |
92 | 139 |
93 GR_DECLARE_EFFECT_TEST; | 140 GR_DECLARE_EFFECT_TEST; |
94 | 141 |
95 typedef GrSingleTextureEffect INHERITED; | 142 typedef GrSingleTextureEffect INHERITED; |
96 }; | 143 }; |
97 | 144 |
98 #endif | 145 #endif |
OLD | NEW |