Chromium Code Reviews| 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 | |
|
bsalomon
2014/07/28 15:20:41
It has clamp to black already I believe.
| |
| 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 | |
| 49 virtual ~GrMatrixConvolutionEffect(); | 69 virtual ~GrMatrixConvolutionEffect(); |
| 50 | 70 |
| 51 virtual void getConstantColorComponents(GrColor* color, | 71 virtual void getConstantColorComponents(GrColor* color, |
| 52 uint32_t* validFlags) const SK_OVERR IDE { | 72 uint32_t* validFlags) const SK_OVERR IDE { |
| 53 // TODO: Try to do better? | 73 // TODO: Try to do better? |
| 54 *validFlags = 0; | 74 *validFlags = 0; |
| 55 } | 75 } |
| 56 | 76 |
| 57 static const char* Name() { return "MatrixConvolution"; } | 77 static const char* Name() { return "MatrixConvolution"; } |
| 58 const SkIRect& bounds() const { return fBounds; } | 78 const SkIRect& bounds() const { return fBounds; } |
| 59 const SkISize& kernelSize() const { return fKernelSize; } | 79 const SkISize& kernelSize() const { return fKernelSize; } |
| 60 const float* kernelOffset() const { return fKernelOffset; } | 80 const float* kernelOffset() const { return fKernelOffset; } |
| 61 const float* kernel() const { return fKernel; } | 81 const float* kernel() const { return fKernel; } |
| 62 float gain() const { return fGain; } | 82 float gain() const { return fGain; } |
| 63 float bias() const { return fBias; } | 83 float bias() const { return fBias; } |
| 64 TileMode tileMode() const { return fTileMode; } | 84 TileMode tileMode() const { return fTileMode; } |
| 65 bool convolveAlpha() const { return fConvolveAlpha; } | 85 bool convolveAlpha() const { return fConvolveAlpha; } |
| 86 bool useBounds() const { return fUseBounds; } | |
| 66 | 87 |
| 67 typedef GrGLMatrixConvolutionEffect GLEffect; | 88 typedef GrGLMatrixConvolutionEffect GLEffect; |
| 68 | 89 |
| 69 virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE; | 90 virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE; |
| 70 | 91 |
| 71 private: | 92 private: |
| 72 GrMatrixConvolutionEffect(GrTexture*, | 93 GrMatrixConvolutionEffect(GrTexture*, |
| 73 const SkIRect& bounds, | 94 const SkIRect& bounds, |
| 74 const SkISize& kernelSize, | 95 const SkISize& kernelSize, |
| 75 const SkScalar* kernel, | 96 const SkScalar* kernel, |
| 76 SkScalar gain, | 97 SkScalar gain, |
| 77 SkScalar bias, | 98 SkScalar bias, |
| 78 const SkIPoint& kernelOffset, | 99 const SkIPoint& kernelOffset, |
| 79 TileMode tileMode, | 100 TileMode tileMode, |
| 80 bool convolveAlpha); | 101 bool convolveAlpha, |
| 102 bool useBounds); | |
| 81 | 103 |
| 82 virtual bool onIsEqual(const GrEffect&) const SK_OVERRIDE; | 104 virtual bool onIsEqual(const GrEffect&) const SK_OVERRIDE; |
| 83 | 105 |
| 84 SkIRect fBounds; | 106 SkIRect fBounds; |
| 85 SkISize fKernelSize; | 107 SkISize fKernelSize; |
| 86 float *fKernel; | 108 float fKernel[MAX_KERNEL_SIZE]; |
| 87 float fGain; | 109 float fGain; |
| 88 float fBias; | 110 float fBias; |
| 89 float fKernelOffset[2]; | 111 float fKernelOffset[2]; |
| 90 TileMode fTileMode; | 112 TileMode fTileMode; |
| 91 bool fConvolveAlpha; | 113 bool fConvolveAlpha; |
| 114 bool fUseBounds; | |
| 92 | 115 |
| 93 GR_DECLARE_EFFECT_TEST; | 116 GR_DECLARE_EFFECT_TEST; |
| 94 | 117 |
| 95 typedef GrSingleTextureEffect INHERITED; | 118 typedef GrSingleTextureEffect INHERITED; |
| 96 }; | 119 }; |
| 97 | 120 |
| 98 #endif | 121 #endif |
| OLD | NEW |