summaryrefslogtreecommitdiff
path: root/gpu/effects/Gr1DKernelEffect.h
diff options
context:
space:
mode:
Diffstat (limited to 'gpu/effects/Gr1DKernelEffect.h')
-rw-r--r--gpu/effects/Gr1DKernelEffect.h54
1 files changed, 54 insertions, 0 deletions
diff --git a/gpu/effects/Gr1DKernelEffect.h b/gpu/effects/Gr1DKernelEffect.h
new file mode 100644
index 00000000..17127336
--- /dev/null
+++ b/gpu/effects/Gr1DKernelEffect.h
@@ -0,0 +1,54 @@
+/*
+ * Copyright 2012 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef Gr1DKernelEffect_DEFINED
+#define Gr1DKernelEffect_DEFINED
+
+#include "GrSingleTextureEffect.h"
+#include "SkMatrix.h"
+
+/**
+ * Base class for 1D kernel effects. The kernel operates either in X or Y and
+ * has a pixel radius. The kernel is specified in the src texture's space
+ * and the kernel center is pinned to a texel's center. The radius specifies
+ * the number of texels on either side of the center texel in X or Y that are
+ * read. Since the center pixel is also read, the total width is one larger than
+ * two times the radius.
+ */
+
+class Gr1DKernelEffect : public GrSingleTextureEffect {
+
+public:
+ enum Direction {
+ kX_Direction,
+ kY_Direction,
+ };
+
+ Gr1DKernelEffect(GrTexture* texture,
+ Direction direction,
+ int radius)
+ : GrSingleTextureEffect(texture, MakeDivByTextureWHMatrix(texture))
+ , fDirection(direction)
+ , fRadius(radius) {}
+
+ virtual ~Gr1DKernelEffect() {};
+
+ static int WidthFromRadius(int radius) { return 2 * radius + 1; }
+
+ int radius() const { return fRadius; }
+ int width() const { return WidthFromRadius(fRadius); }
+ Direction direction() const { return fDirection; }
+
+private:
+
+ Direction fDirection;
+ int fRadius;
+
+ typedef GrSingleTextureEffect INHERITED;
+};
+
+#endif