blob: 171273360b59d4baba8a678c4e115799e0bcee0f [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.comb4a55b72012-11-02 20:45:37 +000012#include "SkMatrix.h"
bsalomon@google.comb505a122012-05-31 18:40:36 +000013
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 */
bsalomon@google.comb4a55b72012-11-02 20:45:37 +000022
tomhudson@google.comd0c1a062012-07-12 17:23:52 +000023class Gr1DKernelEffect : public GrSingleTextureEffect {
bsalomon@google.comb505a122012-05-31 18:40:36 +000024
25public:
26 enum Direction {
27 kX_Direction,
28 kY_Direction,
29 };
30
tomhudson@google.comd0c1a062012-07-12 17:23:52 +000031 Gr1DKernelEffect(GrTexture* texture,
32 Direction direction,
bsalomon@google.comb505a122012-05-31 18:40:36 +000033 int radius)
bsalomon@google.com17fc6512012-11-02 21:45:01 +000034 : GrSingleTextureEffect(texture, MakeDivByTextureWHMatrix(texture))
tomhudson@google.comd0c1a062012-07-12 17:23:52 +000035 , fDirection(direction)
bsalomon@google.comb505a122012-05-31 18:40:36 +000036 , fRadius(radius) {}
37
38 virtual ~Gr1DKernelEffect() {};
39
40 static int WidthFromRadius(int radius) { return 2 * radius + 1; }
41
42 int radius() const { return fRadius; }
43 int width() const { return WidthFromRadius(fRadius); }
44 Direction direction() const { return fDirection; }
45
46private:
47
48 Direction fDirection;
49 int fRadius;
50
tomhudson@google.comd0c1a062012-07-12 17:23:52 +000051 typedef GrSingleTextureEffect INHERITED;
bsalomon@google.comb505a122012-05-31 18:40:36 +000052};
53
54#endif