blob: 9ef765268cf80c967097f69ce6ca39b0c5438372 [file] [log] [blame]
bsalomon@google.comb505a122012-05-31 18:40:36 +00001/*
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
tomhudson@google.comd0c1a062012-07-12 17:23:52 +000011#include "GrSingleTextureEffect.h"
bsalomon@google.comb505a122012-05-31 18:40:36 +000012
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 */
tomhudson@google.comd0c1a062012-07-12 17:23:52 +000021class Gr1DKernelEffect : public GrSingleTextureEffect {
bsalomon@google.comb505a122012-05-31 18:40:36 +000022
23public:
24 enum Direction {
25 kX_Direction,
26 kY_Direction,
27 };
28
tomhudson@google.comd0c1a062012-07-12 17:23:52 +000029 Gr1DKernelEffect(GrTexture* texture,
30 Direction direction,
bsalomon@google.comb505a122012-05-31 18:40:36 +000031 int radius)
tomhudson@google.comd0c1a062012-07-12 17:23:52 +000032 : GrSingleTextureEffect(texture)
33 , fDirection(direction)
bsalomon@google.comb505a122012-05-31 18:40:36 +000034 , 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
tomhudson@google.comd0c1a062012-07-12 17:23:52 +000049 typedef GrSingleTextureEffect INHERITED;
bsalomon@google.comb505a122012-05-31 18:40:36 +000050};
51
52#endif