| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 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 GrConvolutionEffect_DEFINED | 8 #ifndef GrConvolutionEffect_DEFINED |
| 9 #define GrConvolutionEffect_DEFINED | 9 #define GrConvolutionEffect_DEFINED |
| 10 | 10 |
| 11 #include "Gr1DKernelEffect.h" | 11 #include "Gr1DKernelEffect.h" |
| 12 | 12 |
| 13 class GrGLConvolutionEffect; | 13 class GrGLConvolutionEffect; |
| 14 | 14 |
| 15 /** | 15 /** |
| 16 * A convolution effect. The kernel is specified as an array of 2 * half-width | 16 * A convolution effect. The kernel is specified as an array of 2 * half-width |
| 17 * + 1 weights. Each texel is multiplied by it's weight and summed to determine | 17 * + 1 weights. Each texel is multiplied by it's weight and summed to determine |
| 18 * the output color. The output color is modulated by the input color. | 18 * the output color. The output color is modulated by the input color. |
| 19 */ | 19 */ |
| 20 class GrConvolutionEffect : public Gr1DKernelEffect { | 20 class GrConvolutionEffect : public Gr1DKernelEffect { |
| 21 | 21 |
| 22 public: | 22 public: |
| 23 | 23 |
| 24 /// Convolve with an arbitrary user-specified kernel | 24 /// Convolve with an arbitrary user-specified kernel |
| 25 static GrEffectRef* Create(GrTexture* tex, Direction dir, int halfWidth, con
st float* kernel) { | 25 static GrEffectRef* Create(GrTexture* tex, Direction dir, int halfWidth, con
st float* kernel, float cropRect[4]) { |
| 26 AutoEffectUnref effect(SkNEW_ARGS(GrConvolutionEffect, (tex, | 26 AutoEffectUnref effect(SkNEW_ARGS(GrConvolutionEffect, (tex, |
| 27 dir, | 27 dir, |
| 28 halfWidth, | 28 halfWidth, |
| 29 kernel))); | 29 kernel, |
| 30 cropRect))); |
| 30 return CreateEffectRef(effect); | 31 return CreateEffectRef(effect); |
| 31 } | 32 } |
| 32 | 33 |
| 33 /// Convolve with a Gaussian kernel | 34 /// Convolve with a Gaussian kernel |
| 34 static GrEffectRef* CreateGaussian(GrTexture* tex, | 35 static GrEffectRef* CreateGaussian(GrTexture* tex, |
| 35 Direction dir, | 36 Direction dir, |
| 36 int halfWidth, | 37 int halfWidth, |
| 37 float gaussianSigma) { | 38 float gaussianSigma, |
| 39 float cropRect[4]) { |
| 38 AutoEffectUnref effect(SkNEW_ARGS(GrConvolutionEffect, (tex, | 40 AutoEffectUnref effect(SkNEW_ARGS(GrConvolutionEffect, (tex, |
| 39 dir, | 41 dir, |
| 40 halfWidth, | 42 halfWidth, |
| 41 gaussianSigma)))
; | 43 gaussianSigma, |
| 44 cropRect))); |
| 42 return CreateEffectRef(effect); | 45 return CreateEffectRef(effect); |
| 43 } | 46 } |
| 44 | 47 |
| 45 virtual ~GrConvolutionEffect(); | 48 virtual ~GrConvolutionEffect(); |
| 46 | 49 |
| 47 const float* kernel() const { return fKernel; } | 50 const float* kernel() const { return fKernel; } |
| 48 | 51 |
| 52 const float* cropRect() const { return fCropRect; } |
| 53 |
| 49 static const char* Name() { return "Convolution"; } | 54 static const char* Name() { return "Convolution"; } |
| 50 | 55 |
| 51 typedef GrGLConvolutionEffect GLEffect; | 56 typedef GrGLConvolutionEffect GLEffect; |
| 52 | 57 |
| 53 virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE; | 58 virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE; |
| 54 | 59 |
| 55 virtual void getConstantColorComponents(GrColor*, uint32_t* validFlags) cons
t { | 60 virtual void getConstantColorComponents(GrColor*, uint32_t* validFlags) cons
t { |
| 56 // If the texture was opaque we could know that the output color if we k
new the sum of the | 61 // If the texture was opaque we could know that the output color if we k
new the sum of the |
| 57 // kernel values. | 62 // kernel values. |
| 58 *validFlags = 0; | 63 *validFlags = 0; |
| 59 } | 64 } |
| 60 | 65 |
| 61 enum { | 66 enum { |
| 62 // This was decided based on the min allowed value for the max texture | 67 // This was decided based on the min allowed value for the max texture |
| 63 // samples per fragment program run in DX9SM2 (32). A sigma param of 4.0 | 68 // samples per fragment program run in DX9SM2 (32). A sigma param of 4.0 |
| 64 // on a blur filter gives a kernel width of 25 while a sigma of 5.0 | 69 // on a blur filter gives a kernel width of 25 while a sigma of 5.0 |
| 65 // would exceed a 32 wide kernel. | 70 // would exceed a 32 wide kernel. |
| 66 kMaxKernelRadius = 12, | 71 kMaxKernelRadius = 12, |
| 67 // With a C++11 we could have a constexpr version of WidthFromRadius() | 72 // With a C++11 we could have a constexpr version of WidthFromRadius() |
| 68 // and not have to duplicate this calculation. | 73 // and not have to duplicate this calculation. |
| 69 kMaxKernelWidth = 2 * kMaxKernelRadius + 1, | 74 kMaxKernelWidth = 2 * kMaxKernelRadius + 1, |
| 70 }; | 75 }; |
| 71 | 76 |
| 72 protected: | 77 protected: |
| 73 | 78 |
| 74 float fKernel[kMaxKernelWidth]; | 79 float fKernel[kMaxKernelWidth]; |
| 80 float fCropRect[4]; |
| 75 | 81 |
| 76 private: | 82 private: |
| 77 GrConvolutionEffect(GrTexture*, Direction, | 83 GrConvolutionEffect(GrTexture*, Direction, |
| 78 int halfWidth, const float* kernel); | 84 int halfWidth, const float* kernel, float cropRect[4]); |
| 79 | 85 |
| 80 /// Convolve with a Gaussian kernel | 86 /// Convolve with a Gaussian kernel |
| 81 GrConvolutionEffect(GrTexture*, Direction, | 87 GrConvolutionEffect(GrTexture*, Direction, |
| 82 int halfWidth, | 88 int halfWidth, |
| 83 float gaussianSigma); | 89 float gaussianSigma, |
| 90 float cropRect[4]); |
| 84 | 91 |
| 85 virtual bool onIsEqual(const GrEffect&) const SK_OVERRIDE; | 92 virtual bool onIsEqual(const GrEffect&) const SK_OVERRIDE; |
| 86 | 93 |
| 87 GR_DECLARE_EFFECT_TEST; | 94 GR_DECLARE_EFFECT_TEST; |
| 88 | 95 |
| 89 typedef Gr1DKernelEffect INHERITED; | 96 typedef Gr1DKernelEffect INHERITED; |
| 90 }; | 97 }; |
| 91 | 98 |
| 92 #endif | 99 #endif |
| OLD | NEW |