aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar tomhudson@google.com <tomhudson@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-07-16 12:23:32 +0000
committerGravatar tomhudson@google.com <tomhudson@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-07-16 12:23:32 +0000
commitfde2c0af2fd5aae19ab6c8b5228debd5b6209856 (patch)
tree34f0bced44887d5d2fe07bfba5e484982af8bfc4 /src
parentdfbf24e5e7112e99e8c9bed1fdaadc136f42a0d3 (diff)
Having updated the documentation of GrCustomStage to argue that all custom stages must be
immutable, this CL makes that true for ConvolutionEffect. http://codereview.appspot.com/6398043/ git-svn-id: http://skia.googlecode.com/svn/trunk@4613 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src')
-rw-r--r--src/gpu/GrContext.cpp4
-rw-r--r--src/gpu/effects/GrConvolutionEffect.cpp41
-rw-r--r--src/gpu/effects/GrConvolutionEffect.h14
3 files changed, 31 insertions, 28 deletions
diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp
index e70ac5c2ca..6e5fb08535 100644
--- a/src/gpu/GrContext.cpp
+++ b/src/gpu/GrContext.cpp
@@ -263,8 +263,8 @@ void convolve_gaussian(GrGpu* gpu,
sampleM.setIDiv(texture->width(), texture->height());
drawState->sampler(0)->reset(sampleM);
SkAutoTUnref<GrConvolutionEffect> conv(SkNEW_ARGS(GrConvolutionEffect,
- (texture, direction, radius)));
- conv->setGaussianKernel(sigma);
+ (texture, direction, radius,
+ sigma)));
drawState->sampler(0)->setCustomStage(conv);
gpu->drawSimpleRect(rect, NULL, 1 << 0);
}
diff --git a/src/gpu/effects/GrConvolutionEffect.cpp b/src/gpu/effects/GrConvolutionEffect.cpp
index 33f61b6ab6..3804d57130 100644
--- a/src/gpu/effects/GrConvolutionEffect.cpp
+++ b/src/gpu/effects/GrConvolutionEffect.cpp
@@ -163,6 +163,30 @@ GrConvolutionEffect::GrConvolutionEffect(GrTexture* texture,
}
}
+GrConvolutionEffect::GrConvolutionEffect(GrTexture* texture,
+ Direction direction,
+ int radius,
+ float gaussianSigma)
+ : Gr1DKernelEffect(texture, direction, radius) {
+ GrAssert(radius <= kMaxKernelRadius);
+ int width = this->width();
+
+ float sum = 0.0f;
+ float denom = 1.0f / (2.0f * gaussianSigma * gaussianSigma);
+ for (int i = 0; i < width; ++i) {
+ float x = static_cast<float>(i - this->radius());
+ // Note that the constant term (1/(sqrt(2*pi*sigma^2)) of the Gaussian
+ // is dropped here, since we renormalize the kernel below.
+ fKernel[i] = sk_float_exp(- x * x * denom);
+ sum += fKernel[i];
+ }
+ // Normalize the kernel
+ float scale = 1.0f / sum;
+ for (int i = 0; i < width; ++i) {
+ fKernel[i] *= scale;
+ }
+}
+
GrConvolutionEffect::~GrConvolutionEffect() {
}
@@ -179,20 +203,3 @@ bool GrConvolutionEffect::isEqual(const GrCustomStage& sBase) const {
0 == memcmp(fKernel, s.fKernel, this->width() * sizeof(float)));
}
-void GrConvolutionEffect::setGaussianKernel(float sigma) {
- int width = this->width();
- float sum = 0.0f;
- float denom = 1.0f / (2.0f * sigma * sigma);
- for (int i = 0; i < width; ++i) {
- float x = static_cast<float>(i - this->radius());
- // Note that the constant term (1/(sqrt(2*pi*sigma^2)) of the Gaussian
- // is dropped here, since we renormalize the kernel below.
- fKernel[i] = sk_float_exp(- x * x * denom);
- sum += fKernel[i];
- }
- // Normalize the kernel
- float scale = 1.0f / sum;
- for (int i = 0; i < width; ++i) {
- fKernel[i] *= scale;
- }
-}
diff --git a/src/gpu/effects/GrConvolutionEffect.h b/src/gpu/effects/GrConvolutionEffect.h
index 58cad83b53..e04e802666 100644
--- a/src/gpu/effects/GrConvolutionEffect.h
+++ b/src/gpu/effects/GrConvolutionEffect.h
@@ -21,18 +21,14 @@ class GrConvolutionEffect : public Gr1DKernelEffect {
public:
+ /// Convolve with an arbitrary user-specified kernel
GrConvolutionEffect(GrTexture*, Direction,
int halfWidth, const float* kernel = NULL);
- virtual ~GrConvolutionEffect();
-
- void setKernel(const float* kernel) {
- memcpy(fKernel, kernel, this->width());
- }
- /**
- * Helper to set the kernel to a Gaussian. Replaces the existing kernel.
- */
- void setGaussianKernel(float sigma);
+ /// Convolve with a gaussian kernel
+ GrConvolutionEffect(GrTexture*, Direction,
+ int halfWidth, float gaussianSigma);
+ virtual ~GrConvolutionEffect();
const float* kernel() const { return fKernel; }