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;
68 // This was decided based on the min allowed value for the max texture
69 // samples per fragment program run in DX9SM2 (32). A sigma param of 4.0
70 // on a blur filter gives a kernel width of 25 while a sigma of 5.0
71 // would exceed a 32 wide kernel.
72 kMaxKernelRadius = 12,
73 // With a C++11 we could have a constexpr version of WidthFromRadius()
74 // and not have to duplicate this calculation.
75 kMaxKernelWidth = 2 * kMaxKernelRadius + 1,
80 float fKernel[kMaxKernelWidth];
85 GrConvolutionEffect(GrTexture*, Direction,
91 /// Convolve with a Gaussian kernel
92 GrConvolutionEffect(GrTexture*, Direction,
98 virtual bool onIsEqual(const GrFragmentProcessor&) const SK_OVERRIDE;
100 virtual void onComputeInvariantOutput(InvariantOutput* inout) const {
101 // If the texture was opaque we could know that the output color if we knew the sum of the
103 inout->mulByUnknownColor();
106 GR_DECLARE_FRAGMENT_PROCESSOR_TEST;
108 typedef Gr1DKernelEffect INHERITED;