| bsalomon@google.com | b505a12 | 2012-05-31 18:40:36 +0000 | [diff] [blame^] | 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 "GrCustomStage.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 | */ |
| 21 | class Gr1DKernelEffect : public GrCustomStage { |
| 22 | |
| 23 | public: |
| 24 | enum Direction { |
| 25 | kX_Direction, |
| 26 | kY_Direction, |
| 27 | }; |
| 28 | |
| 29 | Gr1DKernelEffect(Direction direction, |
| 30 | int radius) |
| 31 | : fDirection(direction) |
| 32 | , fRadius(radius) {} |
| 33 | |
| 34 | virtual ~Gr1DKernelEffect() {}; |
| 35 | |
| 36 | static int WidthFromRadius(int radius) { return 2 * radius + 1; } |
| 37 | |
| 38 | int radius() const { return fRadius; } |
| 39 | int width() const { return WidthFromRadius(fRadius); } |
| 40 | Direction direction() const { return fDirection; } |
| 41 | |
| 42 | private: |
| 43 | |
| 44 | Direction fDirection; |
| 45 | int fRadius; |
| 46 | |
| 47 | typedef GrCustomStage INHERITED; |
| 48 | }; |
| 49 | |
| 50 | #endif |