| 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 "GrInvariantOutput.h" | 12 #include "GrInvariantOutput.h" |
| 13 #include "GrTextureDomain.h" | 13 #include "GrTextureDomain.h" |
| 14 | 14 |
| 15 // A little bit less than the minimum # uniforms required by DX9SM2 (32). | 15 // A little bit less than the minimum # uniforms required by DX9SM2 (32). |
| 16 // Allows for a 5x5 kernel (or 25x1, for that matter). | 16 // Allows for a 5x5 kernel (or 25x1, for that matter). |
| 17 #define MAX_KERNEL_SIZE 25 | 17 #define MAX_KERNEL_SIZE 25 |
| 18 | 18 |
| 19 class GrMatrixConvolutionEffect : public GrSingleTextureEffect { | 19 class GrMatrixConvolutionEffect : public GrSingleTextureEffect { |
| 20 public: | 20 public: |
| 21 static GrFragmentProcessor* Create(GrTexture* texture, | 21 static GrFragmentProcessor* Create(GrTexture* texture, |
| 22 const SkIRect& bounds, | 22 const SkIRect& bounds, |
| 23 const SkISize& kernelSize, | 23 const SkISize& kernelSize, |
| 24 const SkScalar* kernel, | 24 const SkScalar* kernel, |
| 25 SkScalar gain, | 25 SkScalar gain, |
| 26 SkScalar bias, | 26 SkScalar bias, |
| 27 const SkIPoint& kernelOffset, | 27 const SkIPoint& kernelOffset, |
| 28 GrTextureDomain::Mode tileMode, | 28 GrTextureDomain::Mode tileMode, |
| 29 bool convolveAlpha) { | 29 bool convolveAlpha, GrRenderTarget* dst)
{ |
| 30 return new GrMatrixConvolutionEffect(texture, bounds, kernelSize, kernel
, gain, bias, | 30 return new GrMatrixConvolutionEffect(texture, bounds, kernelSize, kernel
, |
| 31 kernelOffset, tileMode, convolveAlp
ha); | 31 gain, bias, kernelOffset, tileMode,
convolveAlpha, dst); |
| 32 } | 32 } |
| 33 | 33 |
| 34 static GrFragmentProcessor* CreateGaussian(GrTexture* texture, | 34 static GrFragmentProcessor* CreateGaussian(GrTexture* texture, |
| 35 const SkIRect& bounds, | 35 const SkIRect& bounds, |
| 36 const SkISize& kernelSize, | 36 const SkISize& kernelSize, |
| 37 SkScalar gain, | 37 SkScalar gain, |
| 38 SkScalar bias, | 38 SkScalar bias, |
| 39 const SkIPoint& kernelOffset, | 39 const SkIPoint& kernelOffset, |
| 40 GrTextureDomain::Mode tileMode, | 40 GrTextureDomain::Mode tileMode, |
| 41 bool convolveAlpha, | 41 bool convolveAlpha, |
| 42 SkScalar sigmaX, | 42 SkScalar sigmaX, |
| 43 SkScalar sigmaY); | 43 SkScalar sigmaY, GrRenderTarget*
dst); |
| 44 | 44 |
| 45 virtual ~GrMatrixConvolutionEffect(); | 45 virtual ~GrMatrixConvolutionEffect(); |
| 46 | 46 |
| 47 const SkIRect& bounds() const { return fBounds; } | 47 const SkIRect& bounds() const { return fBounds; } |
| 48 const SkISize& kernelSize() const { return fKernelSize; } | 48 const SkISize& kernelSize() const { return fKernelSize; } |
| 49 const float* kernelOffset() const { return fKernelOffset; } | 49 const float* kernelOffset() const { return fKernelOffset; } |
| 50 const float* kernel() const { return fKernel; } | 50 const float* kernel() const { return fKernel; } |
| 51 float gain() const { return fGain; } | 51 float gain() const { return fGain; } |
| 52 float bias() const { return fBias; } | 52 float bias() const { return fBias; } |
| 53 bool convolveAlpha() const { return fConvolveAlpha; } | 53 bool convolveAlpha() const { return fConvolveAlpha; } |
| 54 const GrTextureDomain& domain() const { return fDomain; } | 54 const GrTextureDomain& domain() const { return fDomain; } |
| 55 | 55 |
| 56 const char* name() const override { return "MatrixConvolution"; } | 56 const char* name() const override { return "MatrixConvolution"; } |
| 57 | 57 |
| 58 private: | 58 private: |
| 59 GrMatrixConvolutionEffect(GrTexture*, | 59 GrMatrixConvolutionEffect(GrTexture*, |
| 60 const SkIRect& bounds, | 60 const SkIRect& bounds, |
| 61 const SkISize& kernelSize, | 61 const SkISize& kernelSize, |
| 62 const SkScalar* kernel, | 62 const SkScalar* kernel, |
| 63 SkScalar gain, | 63 SkScalar gain, |
| 64 SkScalar bias, | 64 SkScalar bias, |
| 65 const SkIPoint& kernelOffset, | 65 const SkIPoint& kernelOffset, |
| 66 GrTextureDomain::Mode tileMode, | 66 GrTextureDomain::Mode tileMode, |
| 67 bool convolveAlpha); | 67 bool convolveAlpha, GrRenderTarget* dst); |
| 68 | 68 |
| 69 GrGLFragmentProcessor* onCreateGLInstance() const override; | 69 GrGLFragmentProcessor* onCreateGLInstance() const override; |
| 70 | 70 |
| 71 void onGetGLProcessorKey(const GrGLSLCaps&, GrProcessorKeyBuilder*) const ov
erride; | 71 void onGetGLProcessorKey(const GrGLSLCaps&, GrProcessorKeyBuilder*) const ov
erride; |
| 72 | 72 |
| 73 bool onIsEqual(const GrFragmentProcessor&) const override; | 73 bool onIsEqual(const GrFragmentProcessor&) const override; |
| 74 | 74 |
| 75 void onComputeInvariantOutput(GrInvariantOutput* inout) const override { | 75 void onComputeInvariantOutput(GrInvariantOutput* inout) const override { |
| 76 // TODO: Try to do better? | 76 // TODO: Try to do better? |
| 77 inout->mulByUnknownFourComponents(); | 77 inout->mulByUnknownFourComponents(); |
| 78 } | 78 } |
| 79 | 79 |
| 80 SkIRect fBounds; | 80 SkIRect fBounds; |
| 81 SkISize fKernelSize; | 81 SkISize fKernelSize; |
| 82 float fKernel[MAX_KERNEL_SIZE]; | 82 float fKernel[MAX_KERNEL_SIZE]; |
| 83 float fGain; | 83 float fGain; |
| 84 float fBias; | 84 float fBias; |
| 85 float fKernelOffset[2]; | 85 float fKernelOffset[2]; |
| 86 bool fConvolveAlpha; | 86 bool fConvolveAlpha; |
| 87 GrTextureDomain fDomain; | 87 GrTextureDomain fDomain; |
| 88 | 88 |
| 89 GR_DECLARE_FRAGMENT_PROCESSOR_TEST; | 89 GR_DECLARE_FRAGMENT_PROCESSOR_TEST; |
| 90 | 90 |
| 91 typedef GrSingleTextureEffect INHERITED; | 91 typedef GrSingleTextureEffect INHERITED; |
| 92 }; | 92 }; |
| 93 | 93 |
| 94 #endif | 94 #endif |
| OLD | NEW |