Line data Source code
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 0 : class GrMatrixConvolutionEffect : public GrSingleTextureEffect {
19 : public:
20 0 : static sk_sp<GrFragmentProcessor> Make(GrResourceProvider* resourceProvider,
21 : sk_sp<GrTextureProxy> proxy,
22 : const SkIRect& bounds,
23 : const SkISize& kernelSize,
24 : const SkScalar* kernel,
25 : SkScalar gain,
26 : SkScalar bias,
27 : const SkIPoint& kernelOffset,
28 : GrTextureDomain::Mode tileMode,
29 : bool convolveAlpha) {
30 : return sk_sp<GrFragmentProcessor>(
31 0 : new GrMatrixConvolutionEffect(resourceProvider, std::move(proxy), bounds, kernelSize,
32 0 : kernel, gain, bias, kernelOffset, tileMode, convolveAlpha));
33 : }
34 :
35 : static sk_sp<GrFragmentProcessor> MakeGaussian(GrResourceProvider*,
36 : sk_sp<GrTextureProxy> proxy,
37 : const SkIRect& bounds,
38 : const SkISize& kernelSize,
39 : SkScalar gain,
40 : SkScalar bias,
41 : const SkIPoint& kernelOffset,
42 : GrTextureDomain::Mode tileMode,
43 : bool convolveAlpha,
44 : SkScalar sigmaX,
45 : SkScalar sigmaY);
46 :
47 : const SkIRect& bounds() const { return fBounds; }
48 0 : const SkISize& kernelSize() const { return fKernelSize; }
49 0 : const float* kernelOffset() const { return fKernelOffset; }
50 0 : const float* kernel() const { return fKernel; }
51 0 : float gain() const { return fGain; }
52 0 : float bias() const { return fBias; }
53 0 : bool convolveAlpha() const { return fConvolveAlpha; }
54 0 : const GrTextureDomain& domain() const { return fDomain; }
55 :
56 0 : const char* name() const override { return "MatrixConvolution"; }
57 :
58 : private:
59 : GrMatrixConvolutionEffect(GrResourceProvider*,
60 : sk_sp<GrTextureProxy> proxy,
61 : const SkIRect& bounds,
62 : const SkISize& kernelSize,
63 : const SkScalar* kernel,
64 : SkScalar gain,
65 : SkScalar bias,
66 : const SkIPoint& kernelOffset,
67 : GrTextureDomain::Mode tileMode,
68 : bool convolveAlpha);
69 :
70 : GrGLSLFragmentProcessor* onCreateGLSLInstance() const override;
71 :
72 : void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override;
73 :
74 : bool onIsEqual(const GrFragmentProcessor&) const override;
75 :
76 : SkIRect fBounds;
77 : SkISize fKernelSize;
78 : float fKernel[MAX_KERNEL_SIZE];
79 : float fGain;
80 : float fBias;
81 : float fKernelOffset[2];
82 : bool fConvolveAlpha;
83 : GrTextureDomain fDomain;
84 :
85 : GR_DECLARE_FRAGMENT_PROCESSOR_TEST;
86 :
87 : typedef GrSingleTextureEffect INHERITED;
88 : };
89 :
90 : #endif
|