aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu/effects/GrGaussianConvolutionFragmentProcessor.cpp
diff options
context:
space:
mode:
authorGravatar Robert Phillips <robertphillips@google.com>2017-01-30 08:06:27 -0500
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-01-30 13:40:15 +0000
commit40fd7c94c24bb30d888c3d85a79cbb96c7fbf800 (patch)
tree075e886c01de864ba982910f1854f47ba1ae95d8 /src/gpu/effects/GrGaussianConvolutionFragmentProcessor.cpp
parent55b72530fedeb58154635531751a8730982fbf2a (diff)
Push GrTextureProxy down to more effects
Change-Id: Ie3f32a88f25af082c25bc6daf3fe24e303e80f9e Reviewed-on: https://skia-review.googlesource.com/7616 Commit-Queue: Robert Phillips <robertphillips@google.com> Reviewed-by: Brian Salomon <bsalomon@google.com>
Diffstat (limited to 'src/gpu/effects/GrGaussianConvolutionFragmentProcessor.cpp')
-rw-r--r--src/gpu/effects/GrGaussianConvolutionFragmentProcessor.cpp61
1 files changed, 45 insertions, 16 deletions
diff --git a/src/gpu/effects/GrGaussianConvolutionFragmentProcessor.cpp b/src/gpu/effects/GrGaussianConvolutionFragmentProcessor.cpp
index be6d4d8302..c5f554fc69 100644
--- a/src/gpu/effects/GrGaussianConvolutionFragmentProcessor.cpp
+++ b/src/gpu/effects/GrGaussianConvolutionFragmentProcessor.cpp
@@ -6,6 +6,7 @@
*/
#include "GrGaussianConvolutionFragmentProcessor.h"
+#include "GrProxyMove.h"
#include "../private/GrGLSL.h"
#include "glsl/GrGLSLFragmentProcessor.h"
#include "glsl/GrGLSLFragmentShaderBuilder.h"
@@ -144,6 +145,25 @@ void GrGLConvolutionEffect::GenKey(const GrProcessor& processor, const GrShaderC
///////////////////////////////////////////////////////////////////////////////
+
+static void fill_in_1D_guassian_kernel(float* kernel, int width, float gaussianSigma, int radius) {
+ const float denom = 1.0f / (2.0f * gaussianSigma * gaussianSigma);
+
+ float sum = 0.0f;
+ for (int i = 0; i < width; ++i) {
+ float x = static_cast<float>(i - radius);
+ // Note that the constant term (1/(sqrt(2*pi*sigma^2)) of the Gaussian
+ // is dropped here, since we renormalize the kernel below.
+ kernel[i] = sk_float_exp(-x * x * denom);
+ sum += kernel[i];
+ }
+ // Normalize the kernel
+ float scale = 1.0f / sum;
+ for (int i = 0; i < width; ++i) {
+ kernel[i] *= scale;
+ }
+}
+
GrGaussianConvolutionFragmentProcessor::GrGaussianConvolutionFragmentProcessor(GrTexture* texture,
Direction direction,
int radius,
@@ -154,22 +174,31 @@ GrGaussianConvolutionFragmentProcessor::GrGaussianConvolutionFragmentProcessor(G
, fUseBounds(useBounds) {
this->initClassID<GrGaussianConvolutionFragmentProcessor>();
SkASSERT(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;
- }
+ fill_in_1D_guassian_kernel(fKernel, this->width(), gaussianSigma, this->radius());
+
+ memcpy(fBounds, bounds, sizeof(fBounds));
+}
+
+GrGaussianConvolutionFragmentProcessor::GrGaussianConvolutionFragmentProcessor(
+ GrContext* context,
+ sk_sp<GrTextureProxy> proxy,
+ Direction direction,
+ int radius,
+ float gaussianSigma,
+ bool useBounds,
+ float bounds[2])
+ : INHERITED{context,
+ ModulationFlags(proxy->config()),
+ GR_PROXY_MOVE(proxy),
+ direction,
+ radius}
+ , fUseBounds(useBounds) {
+ this->initClassID<GrGaussianConvolutionFragmentProcessor>();
+ SkASSERT(radius <= kMaxKernelRadius);
+
+ fill_in_1D_guassian_kernel(fKernel, this->width(), gaussianSigma, this->radius());
+
memcpy(fBounds, bounds, sizeof(fBounds));
}
@@ -212,5 +241,5 @@ sk_sp<GrFragmentProcessor> GrGaussianConvolutionFragmentProcessor::TestCreate(
float sigma = radius / 3.f;
return GrGaussianConvolutionFragmentProcessor::Make(
- d->fTextures[texIdx], dir, radius, sigma, useBounds, bounds);
+ d->context(), d->textureProxy(texIdx), dir, radius, sigma, useBounds, bounds);
}