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 | 13 |
13 // 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). |
14 // Allows for a 5x5 kernel (or 25x1, for that matter). | 15 // Allows for a 5x5 kernel (or 25x1, for that matter). |
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 kClamp_TileMode = 0, /*!< Clamp to the image's edge pixels. */ | |
24 kRepeat_TileMode, /*!< Wrap around to the image's opposite edge.
*/ | |
25 kClampToBlack_TileMode, /*!< Fill with transparent black. */ | |
26 kMax_TileMode = kClampToBlack_TileMode | |
27 }; | |
28 | |
29 typedef GrMatrixConvolutionEffect::TileMode TileMode; | |
30 static GrEffect* Create(GrTexture* texture, | 22 static GrEffect* Create(GrTexture* texture, |
31 const SkIRect& bounds, | 23 const SkIRect& bounds, |
32 const SkISize& kernelSize, | 24 const SkISize& kernelSize, |
33 const SkScalar* kernel, | 25 const SkScalar* kernel, |
34 SkScalar gain, | 26 SkScalar gain, |
35 SkScalar bias, | 27 SkScalar bias, |
36 const SkIPoint& kernelOffset, | 28 const SkIPoint& kernelOffset, |
37 TileMode tileMode, | 29 GrTextureDomain::Mode tileMode, |
38 bool convolveAlpha) { | 30 bool convolveAlpha) { |
39 return SkNEW_ARGS(GrMatrixConvolutionEffect, (texture, | 31 return SkNEW_ARGS(GrMatrixConvolutionEffect, (texture, |
40 bounds, | 32 bounds, |
41 kernelSize, | 33 kernelSize, |
42 kernel, | 34 kernel, |
43 gain, | 35 gain, |
44 bias, | 36 bias, |
45 kernelOffset, | 37 kernelOffset, |
46 tileMode, | 38 tileMode, |
47 convolveAlpha)); | 39 convolveAlpha)); |
48 } | 40 } |
49 virtual ~GrMatrixConvolutionEffect(); | 41 virtual ~GrMatrixConvolutionEffect(); |
50 | 42 |
51 virtual void getConstantColorComponents(GrColor* color, | 43 virtual void getConstantColorComponents(GrColor* color, |
52 uint32_t* validFlags) const SK_OVERR
IDE { | 44 uint32_t* validFlags) const SK_OVERR
IDE { |
53 // TODO: Try to do better? | 45 // TODO: Try to do better? |
54 *validFlags = 0; | 46 *validFlags = 0; |
55 } | 47 } |
56 | 48 |
57 static const char* Name() { return "MatrixConvolution"; } | 49 static const char* Name() { return "MatrixConvolution"; } |
58 const SkIRect& bounds() const { return fBounds; } | 50 const SkIRect& bounds() const { return fBounds; } |
59 const SkISize& kernelSize() const { return fKernelSize; } | 51 const SkISize& kernelSize() const { return fKernelSize; } |
60 const float* kernelOffset() const { return fKernelOffset; } | 52 const float* kernelOffset() const { return fKernelOffset; } |
61 const float* kernel() const { return fKernel; } | 53 const float* kernel() const { return fKernel; } |
62 float gain() const { return fGain; } | 54 float gain() const { return fGain; } |
63 float bias() const { return fBias; } | 55 float bias() const { return fBias; } |
64 TileMode tileMode() const { return fTileMode; } | |
65 bool convolveAlpha() const { return fConvolveAlpha; } | 56 bool convolveAlpha() const { return fConvolveAlpha; } |
| 57 const GrTextureDomain& domain() const { return fDomain; } |
66 | 58 |
67 typedef GrGLMatrixConvolutionEffect GLEffect; | 59 typedef GrGLMatrixConvolutionEffect GLEffect; |
68 | 60 |
69 virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE; | 61 virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE; |
70 | 62 |
71 private: | 63 private: |
72 GrMatrixConvolutionEffect(GrTexture*, | 64 GrMatrixConvolutionEffect(GrTexture*, |
73 const SkIRect& bounds, | 65 const SkIRect& bounds, |
74 const SkISize& kernelSize, | 66 const SkISize& kernelSize, |
75 const SkScalar* kernel, | 67 const SkScalar* kernel, |
76 SkScalar gain, | 68 SkScalar gain, |
77 SkScalar bias, | 69 SkScalar bias, |
78 const SkIPoint& kernelOffset, | 70 const SkIPoint& kernelOffset, |
79 TileMode tileMode, | 71 GrTextureDomain::Mode tileMode, |
80 bool convolveAlpha); | 72 bool convolveAlpha); |
81 | 73 |
82 virtual bool onIsEqual(const GrEffect&) const SK_OVERRIDE; | 74 virtual bool onIsEqual(const GrEffect&) const SK_OVERRIDE; |
83 | 75 |
84 SkIRect fBounds; | 76 SkIRect fBounds; |
85 SkISize fKernelSize; | 77 SkISize fKernelSize; |
86 float *fKernel; | 78 float* fKernel; |
87 float fGain; | 79 float fGain; |
88 float fBias; | 80 float fBias; |
89 float fKernelOffset[2]; | 81 float fKernelOffset[2]; |
90 TileMode fTileMode; | 82 bool fConvolveAlpha; |
91 bool fConvolveAlpha; | 83 GrTextureDomain fDomain; |
92 | 84 |
93 GR_DECLARE_EFFECT_TEST; | 85 GR_DECLARE_EFFECT_TEST; |
94 | 86 |
95 typedef GrSingleTextureEffect INHERITED; | 87 typedef GrSingleTextureEffect INHERITED; |
96 }; | 88 }; |
97 | 89 |
98 #endif | 90 #endif |
OLD | NEW |