| 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 GrEffect* Create(GrTexture* tex, | 25 static GrFragmentProcessor* Create(GrTexture* tex, |
| 26 Direction dir, | 26 Direction dir, |
| 27 int halfWidth, | 27 int halfWidth, |
| 28 const float* kernel, | 28 const float* kernel, |
| 29 bool useBounds, | 29 bool useBounds, |
| 30 float bounds[2]) { | 30 float bounds[2]) { |
| 31 return SkNEW_ARGS(GrConvolutionEffect, (tex, | 31 return SkNEW_ARGS(GrConvolutionEffect, (tex, |
| 32 dir, | 32 dir, |
| 33 halfWidth, | 33 halfWidth, |
| 34 kernel, | 34 kernel, |
| 35 useBounds, | 35 useBounds, |
| 36 bounds)); | 36 bounds)); |
| 37 } | 37 } |
| 38 | 38 |
| 39 /// Convolve with a Gaussian kernel | 39 /// Convolve with a Gaussian kernel |
| 40 static GrEffect* CreateGaussian(GrTexture* tex, | 40 static GrFragmentProcessor* CreateGaussian(GrTexture* tex, |
| 41 Direction dir, | 41 Direction dir, |
| 42 int halfWidth, | 42 int halfWidth, |
| 43 float gaussianSigma, | 43 float gaussianSigma, |
| 44 bool useBounds, | 44 bool useBounds, |
| 45 float bounds[2]) { | 45 float bounds[2]) { |
| 46 return SkNEW_ARGS(GrConvolutionEffect, (tex, | 46 return SkNEW_ARGS(GrConvolutionEffect, (tex, |
| 47 dir, | 47 dir, |
| 48 halfWidth, | 48 halfWidth, |
| 49 gaussianSigma, | 49 gaussianSigma, |
| 50 useBounds, | 50 useBounds, |
| 51 bounds)); | 51 bounds)); |
| 52 } | 52 } |
| 53 | 53 |
| 54 virtual ~GrConvolutionEffect(); | 54 virtual ~GrConvolutionEffect(); |
| 55 | 55 |
| 56 const float* kernel() const { return fKernel; } | 56 const float* kernel() const { return fKernel; } |
| 57 | 57 |
| 58 const float* bounds() const { return fBounds; } | 58 const float* bounds() const { return fBounds; } |
| 59 bool useBounds() const { return fUseBounds; } | 59 bool useBounds() const { return fUseBounds; } |
| 60 | 60 |
| 61 static const char* Name() { return "Convolution"; } | 61 static const char* Name() { return "Convolution"; } |
| 62 | 62 |
| 63 typedef GrGLConvolutionEffect GLEffect; | 63 typedef GrGLConvolutionEffect GLProcessor; |
| 64 | 64 |
| 65 virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE; | 65 virtual const GrBackendFragmentProcessorFactory& getFactory() const SK_OVERR
IDE; |
| 66 | 66 |
| 67 virtual void getConstantColorComponents(GrColor*, uint32_t* validFlags) cons
t { | 67 virtual void getConstantColorComponents(GrColor*, uint32_t* validFlags) cons
t { |
| 68 // If the texture was opaque we could know that the output color if we k
new the sum of the | 68 // If the texture was opaque we could know that the output color if we k
new the sum of the |
| 69 // kernel values. | 69 // kernel values. |
| 70 *validFlags = 0; | 70 *validFlags = 0; |
| 71 } | 71 } |
| 72 | 72 |
| 73 enum { | 73 enum { |
| 74 // This was decided based on the min allowed value for the max texture | 74 // This was decided based on the min allowed value for the max texture |
| 75 // samples per fragment program run in DX9SM2 (32). A sigma param of 4.0 | 75 // samples per fragment program run in DX9SM2 (32). A sigma param of 4.0 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 94 bool useBounds, | 94 bool useBounds, |
| 95 float bounds[2]); | 95 float bounds[2]); |
| 96 | 96 |
| 97 /// Convolve with a Gaussian kernel | 97 /// Convolve with a Gaussian kernel |
| 98 GrConvolutionEffect(GrTexture*, Direction, | 98 GrConvolutionEffect(GrTexture*, Direction, |
| 99 int halfWidth, | 99 int halfWidth, |
| 100 float gaussianSigma, | 100 float gaussianSigma, |
| 101 bool useBounds, | 101 bool useBounds, |
| 102 float bounds[2]); | 102 float bounds[2]); |
| 103 | 103 |
| 104 virtual bool onIsEqual(const GrEffect&) const SK_OVERRIDE; | 104 virtual bool onIsEqual(const GrProcessor&) const SK_OVERRIDE; |
| 105 | 105 |
| 106 GR_DECLARE_EFFECT_TEST; | 106 GR_DECLARE_FRAGMENT_PROCESSOR_TEST; |
| 107 | 107 |
| 108 typedef Gr1DKernelEffect INHERITED; | 108 typedef Gr1DKernelEffect INHERITED; |
| 109 }; | 109 }; |
| 110 | 110 |
| 111 #endif | 111 #endif |
| OLD | NEW |