2 * Copyright 2012 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
8 #ifndef GrConvolutionEffect_DEFINED
9 #define GrConvolutionEffect_DEFINED
11 #include "Gr1DKernelEffect.h"
13 class GrGLConvolutionEffect;
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
18 * the output color. The output color is modulated by the input color.
20 class GrConvolutionEffect : public Gr1DKernelEffect {
24 /// Convolve with an arbitrary user-specified kernel
25 static GrFragmentProcessor* Create(GrTexture* tex,
31 return SkNEW_ARGS(GrConvolutionEffect, (tex,
39 /// Convolve with a Gaussian kernel
40 static GrFragmentProcessor* CreateGaussian(GrTexture* tex,
46 return SkNEW_ARGS(GrConvolutionEffect, (tex,
54 virtual ~GrConvolutionEffect();
56 const float* kernel() const { return fKernel; }
58 const float* bounds() const { return fBounds; }
59 bool useBounds() const { return fUseBounds; }
61 static const char* Name() { return "Convolution"; }
63 typedef GrGLConvolutionEffect GLProcessor;
65 virtual const GrBackendFragmentProcessorFactory& getFactory() const SK_OVERRIDE;
67 virtual void getConstantColorComponents(GrColor*, uint32_t* validFlags) const {
68 // If the texture was opaque we could know that the output color if we knew the sum of the
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
76 // on a blur filter gives a kernel width of 25 while a sigma of 5.0
77 // would exceed a 32 wide kernel.
78 kMaxKernelRadius = 12,
79 // With a C++11 we could have a constexpr version of WidthFromRadius()
80 // and not have to duplicate this calculation.
81 kMaxKernelWidth = 2 * kMaxKernelRadius + 1,
86 float fKernel[kMaxKernelWidth];
91 GrConvolutionEffect(GrTexture*, Direction,
97 /// Convolve with a Gaussian kernel
98 GrConvolutionEffect(GrTexture*, Direction,
104 virtual bool onIsEqual(const GrProcessor&) const SK_OVERRIDE;
106 GR_DECLARE_FRAGMENT_PROCESSOR_TEST;
108 typedef Gr1DKernelEffect INHERITED;