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 | b4a55b7 | 2012-11-02 20:45:37 +0000 | [diff] [blame] | 12 | #include "SkMatrix.h" |
bsalomon@google.com | b505a12 | 2012-05-31 18:40:36 +0000 | [diff] [blame] | 13 | |
| 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.com | b4a55b7 | 2012-11-02 20:45:37 +0000 | [diff] [blame] | 22 | |
tomhudson@google.com | d0c1a06 | 2012-07-12 17:23:52 +0000 | [diff] [blame] | 23 | class Gr1DKernelEffect : public GrSingleTextureEffect { |
bsalomon@google.com | b505a12 | 2012-05-31 18:40:36 +0000 | [diff] [blame] | 24 | |
| 25 | public: |
| 26 | enum Direction { |
| 27 | kX_Direction, |
| 28 | kY_Direction, |
| 29 | }; |
| 30 | |
bsalomon | 4a33952 | 2015-10-06 08:40:50 -0700 | [diff] [blame] | 31 | Gr1DKernelEffect(GrTexture* texture, |
tomhudson@google.com | d0c1a06 | 2012-07-12 17:23:52 +0000 | [diff] [blame] | 32 | Direction direction, |
bsalomon@google.com | b505a12 | 2012-05-31 18:40:36 +0000 | [diff] [blame] | 33 | int radius) |
bsalomon | 4a33952 | 2015-10-06 08:40:50 -0700 | [diff] [blame] | 34 | : INHERITED(texture, GrCoordTransform::MakeDivByTextureWHMatrix(texture)) |
tomhudson@google.com | d0c1a06 | 2012-07-12 17:23:52 +0000 | [diff] [blame] | 35 | , fDirection(direction) |
bsalomon@google.com | b505a12 | 2012-05-31 18:40:36 +0000 | [diff] [blame] | 36 | , 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 | |
robertphillips | e004bfc | 2015-11-16 09:06:59 -0800 | [diff] [blame] | 46 | SkString dumpInfo() const override { |
| 47 | SkString str; |
| 48 | str.appendf("Direction: %s, Radius: %d ", kX_Direction == fDirection ? "X" : "Y", fRadius); |
| 49 | str.append(INHERITED::dumpInfo()); |
| 50 | return str; |
| 51 | } |
| 52 | |
bsalomon@google.com | b505a12 | 2012-05-31 18:40:36 +0000 | [diff] [blame] | 53 | private: |
| 54 | |
| 55 | Direction fDirection; |
| 56 | int fRadius; |
| 57 | |
tomhudson@google.com | d0c1a06 | 2012-07-12 17:23:52 +0000 | [diff] [blame] | 58 | typedef GrSingleTextureEffect INHERITED; |
bsalomon@google.com | b505a12 | 2012-05-31 18:40:36 +0000 | [diff] [blame] | 59 | }; |
| 60 | |
| 61 | #endif |