Line data Source code
1 : /*
2 : * Copyright 2012 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 Gr1DKernelEffect_DEFINED
9 : #define Gr1DKernelEffect_DEFINED
10 :
11 : #include "GrSingleTextureEffect.h"
12 : #include "SkMatrix.h"
13 :
14 : /**
15 : * Base class for 1D kernel effects. The kernel operates either in X or Y and
16 : * has a pixel radius. The kernel is specified in the src texture's space
17 : * and the kernel center is pinned to a texel's center. The radius specifies
18 : * the number of texels on either side of the center texel in X or Y that are
19 : * read. Since the center pixel is also read, the total width is one larger than
20 : * two times the radius.
21 : */
22 :
23 : class Gr1DKernelEffect : public GrSingleTextureEffect {
24 :
25 : public:
26 : enum Direction {
27 : kX_Direction,
28 : kY_Direction,
29 : };
30 :
31 0 : Gr1DKernelEffect(GrResourceProvider* resourceProvider, OptimizationFlags optFlags,
32 : sk_sp<GrTextureProxy> proxy, Direction direction, int radius)
33 0 : : INHERITED(resourceProvider, optFlags, std::move(proxy), nullptr, SkMatrix::I())
34 : , fDirection(direction)
35 0 : , fRadius(radius) {
36 0 : }
37 :
38 0 : ~Gr1DKernelEffect() override {}
39 :
40 0 : static int WidthFromRadius(int radius) { return 2 * radius + 1; }
41 :
42 0 : int radius() const { return fRadius; }
43 0 : int width() const { return WidthFromRadius(fRadius); }
44 0 : Direction direction() const { return fDirection; }
45 :
46 0 : SkString dumpInfo() const override {
47 0 : SkString str;
48 0 : str.appendf("Direction: %s, Radius: %d ", kX_Direction == fDirection ? "X" : "Y", fRadius);
49 0 : str.append(INHERITED::dumpInfo());
50 0 : return str;
51 : }
52 :
53 : private:
54 : Direction fDirection;
55 : int fRadius;
56 :
57 : typedef GrSingleTextureEffect INHERITED;
58 : };
59 :
60 : #endif
|