1 /* 2 * Copyright 2014 Google Inc. 3 * 4 * Use of this source code is governed by a BSD-style license that can be 5 * found in the LICENSE file. 6 */ 7 8 #ifndef GrMatrixConvolutionEffect_DEFINED 9 #define GrMatrixConvolutionEffect_DEFINED 10 11 #include "GrSingleTextureEffect.h" 12 #include "GrTextureDomain.h" 13 14 // A little bit less than the minimum # uniforms required by DX9SM2 (32). 15 // Allows for a 5x5 kernel (or 25x1, for that matter). 16 #define MAX_KERNEL_SIZE 25 17 18 class GrMatrixConvolutionEffect : public GrSingleTextureEffect { 19 public: Make(sk_sp<GrTextureProxy> proxy,const SkIRect & bounds,const SkISize & kernelSize,const SkScalar * kernel,SkScalar gain,SkScalar bias,const SkIPoint & kernelOffset,GrTextureDomain::Mode tileMode,bool convolveAlpha)20 static sk_sp<GrFragmentProcessor> Make(sk_sp<GrTextureProxy> proxy, 21 const SkIRect& bounds, 22 const SkISize& kernelSize, 23 const SkScalar* kernel, 24 SkScalar gain, 25 SkScalar bias, 26 const SkIPoint& kernelOffset, 27 GrTextureDomain::Mode tileMode, 28 bool convolveAlpha) { 29 return sk_sp<GrFragmentProcessor>( 30 new GrMatrixConvolutionEffect(std::move(proxy), bounds, kernelSize, 31 kernel, gain, bias, kernelOffset, tileMode, convolveAlpha)); 32 } 33 34 static sk_sp<GrFragmentProcessor> MakeGaussian(sk_sp<GrTextureProxy> proxy, 35 const SkIRect& bounds, 36 const SkISize& kernelSize, 37 SkScalar gain, 38 SkScalar bias, 39 const SkIPoint& kernelOffset, 40 GrTextureDomain::Mode tileMode, 41 bool convolveAlpha, 42 SkScalar sigmaX, 43 SkScalar sigmaY); 44 bounds()45 const SkIRect& bounds() const { return fBounds; } kernelSize()46 const SkISize& kernelSize() const { return fKernelSize; } kernelOffset()47 const float* kernelOffset() const { return fKernelOffset; } kernel()48 const float* kernel() const { return fKernel; } gain()49 float gain() const { return fGain; } bias()50 float bias() const { return fBias; } convolveAlpha()51 bool convolveAlpha() const { return fConvolveAlpha; } domain()52 const GrTextureDomain& domain() const { return fDomain; } 53 name()54 const char* name() const override { return "MatrixConvolution"; } 55 56 private: 57 GrMatrixConvolutionEffect(sk_sp<GrTextureProxy> proxy, 58 const SkIRect& bounds, 59 const SkISize& kernelSize, 60 const SkScalar* kernel, 61 SkScalar gain, 62 SkScalar bias, 63 const SkIPoint& kernelOffset, 64 GrTextureDomain::Mode tileMode, 65 bool convolveAlpha); 66 67 GrGLSLFragmentProcessor* onCreateGLSLInstance() const override; 68 69 void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override; 70 71 bool onIsEqual(const GrFragmentProcessor&) const override; 72 73 SkIRect fBounds; 74 SkISize fKernelSize; 75 float fKernel[MAX_KERNEL_SIZE]; 76 float fGain; 77 float fBias; 78 float fKernelOffset[2]; 79 bool fConvolveAlpha; 80 GrTextureDomain fDomain; 81 82 GR_DECLARE_FRAGMENT_PROCESSOR_TEST 83 84 typedef GrSingleTextureEffect INHERITED; 85 }; 86 87 #endif 88