aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu/effects/Gr1DKernelEffect.h
blob: d7402e8c459432393ced470ad97c3cd30ad9d254 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/*
 * Copyright 2012 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#ifndef Gr1DKernelEffect_DEFINED
#define Gr1DKernelEffect_DEFINED

#include "GrSingleTextureEffect.h"
#include "SkMatrix.h"

/**
 * Base class for 1D kernel effects. The kernel operates either in X or Y and
 * has a pixel radius. The kernel is specified in the src texture's space
 * and the kernel center is pinned to a texel's center. The radius specifies
 * the number of texels on either side of the center texel in X or Y that are
 * read. Since the center pixel is also read, the total width is one larger than
 * two times the radius.
 */

class Gr1DKernelEffect : public GrSingleTextureEffect {

public:
    enum Direction {
        kX_Direction,
        kY_Direction,
    };

    Gr1DKernelEffect(GrTexture* texture,
                     Direction direction,
                     int radius)
        : INHERITED(texture, nullptr, GrCoordTransform::MakeDivByTextureWHMatrix(texture))
        , fDirection(direction)
        , fRadius(radius) {}

    virtual ~Gr1DKernelEffect() {}

    static int WidthFromRadius(int radius) { return 2 * radius + 1; }

    int radius() const { return fRadius; }
    int width() const { return WidthFromRadius(fRadius); }
    Direction direction() const { return fDirection; }

    SkString dumpInfo() const override {
        SkString str;
        str.appendf("Direction: %s, Radius: %d ", kX_Direction == fDirection ? "X" : "Y", fRadius);
        str.append(INHERITED::dumpInfo());
        return str;
    }

private:

    Direction       fDirection;
    int             fRadius;

    typedef GrSingleTextureEffect INHERITED;
};

#endif