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
diff --git a/src/gpu/effects/GrConvolutionEffect.cpp b/src/gpu/effects/GrConvolutionEffect.cpp
index 33f61b6..3804d57 100644
--- a/src/gpu/effects/GrConvolutionEffect.cpp
+++ b/src/gpu/effects/GrConvolutionEffect.cpp
@@ -163,6 +163,30 @@
}
}
+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 @@
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;
- }
-}