| 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 | |
| tomhudson@google.com | d0c1a06 | 2012-07-12 17:23:52 +0000 | [diff] [blame^] | 11 | #include "GrSingleTextureEffect.h" |
| bsalomon@google.com | b505a12 | 2012-05-31 18:40:36 +0000 | [diff] [blame] | 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 | */ |
| tomhudson@google.com | d0c1a06 | 2012-07-12 17:23:52 +0000 | [diff] [blame^] | 21 | class Gr1DKernelEffect : public GrSingleTextureEffect { |
| bsalomon@google.com | b505a12 | 2012-05-31 18:40:36 +0000 | [diff] [blame] | 22 | |
| 23 | public: |
| 24 | enum Direction { |
| 25 | kX_Direction, |
| 26 | kY_Direction, |
| 27 | }; |
| 28 | |
| tomhudson@google.com | d0c1a06 | 2012-07-12 17:23:52 +0000 | [diff] [blame^] | 29 | Gr1DKernelEffect(GrTexture* texture, |
| 30 | Direction direction, |
| bsalomon@google.com | b505a12 | 2012-05-31 18:40:36 +0000 | [diff] [blame] | 31 | int radius) |
| tomhudson@google.com | d0c1a06 | 2012-07-12 17:23:52 +0000 | [diff] [blame^] | 32 | : GrSingleTextureEffect(texture) |
| 33 | , fDirection(direction) |
| bsalomon@google.com | b505a12 | 2012-05-31 18:40:36 +0000 | [diff] [blame] | 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 | |
| 44 | private: |
| 45 | |
| 46 | Direction fDirection; |
| 47 | int fRadius; |
| 48 | |
| tomhudson@google.com | d0c1a06 | 2012-07-12 17:23:52 +0000 | [diff] [blame^] | 49 | typedef GrSingleTextureEffect INHERITED; |
| bsalomon@google.com | b505a12 | 2012-05-31 18:40:36 +0000 | [diff] [blame] | 50 | }; |
| 51 | |
| 52 | #endif |