Gr1DKernelEffect.h revision 80bacfeb4bda06541e8695bd502229727bccfeab
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
13/**
14 * Base class for 1D kernel effects. The kernel operates either in X or Y and
15 * has a pixel radius. The kernel is specified in the src texture's space
16 * and the kernel center is pinned to a texel's center. The radius specifies
17 * the number of texels on either side of the center texel in X or Y that are
18 * read. Since the center pixel is also read, the total width is one larger than
19 * two times the radius.
20 */
21class Gr1DKernelEffect : public GrSingleTextureEffect {
22
23public:
24    enum Direction {
25        kX_Direction,
26        kY_Direction,
27    };
28
29    Gr1DKernelEffect(GrTexture* texture,
30                     Direction direction,
31                     int radius)
32        : GrSingleTextureEffect(texture)
33        , fDirection(direction)
34        , fRadius(radius) {}
35
36    virtual ~Gr1DKernelEffect() {};
37
38    static int WidthFromRadius(int radius) { return 2 * radius + 1; }
39
40    int radius() const { return fRadius; }
41    int width() const { return WidthFromRadius(fRadius); }
42    Direction direction() const { return fDirection; }
43
44private:
45
46    Direction       fDirection;
47    int             fRadius;
48
49    typedef GrSingleTextureEffect INHERITED;
50};
51
52#endif
53