| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "GrConvolutionEffect.h" | 8 #include "GrConvolutionEffect.h" |
| 9 #include "gl/GrGLEffect.h" | 9 #include "gl/GrGLEffect.h" |
| 10 #include "gl/GrGLEffectMatrix.h" | 10 #include "gl/GrGLEffectMatrix.h" |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 SkString modulate; | 102 SkString modulate; |
| 103 GrGLSLMulVarBy4f(&modulate, 2, outputColor, inputColor); | 103 GrGLSLMulVarBy4f(&modulate, 2, outputColor, inputColor); |
| 104 builder->fsCodeAppend(modulate.c_str()); | 104 builder->fsCodeAppend(modulate.c_str()); |
| 105 } | 105 } |
| 106 | 106 |
| 107 void GrGLConvolutionEffect::setData(const GrGLUniformManager& uman, | 107 void GrGLConvolutionEffect::setData(const GrGLUniformManager& uman, |
| 108 const GrDrawEffect& drawEffect) { | 108 const GrDrawEffect& drawEffect) { |
| 109 const GrConvolutionEffect& conv = drawEffect.castEffect<GrConvolutionEffect>
(); | 109 const GrConvolutionEffect& conv = drawEffect.castEffect<GrConvolutionEffect>
(); |
| 110 GrTexture& texture = *conv.texture(0); | 110 GrTexture& texture = *conv.texture(0); |
| 111 // the code we generated was for a specific kernel radius | 111 // the code we generated was for a specific kernel radius |
| 112 GrAssert(conv.radius() == fRadius); | 112 SkASSERT(conv.radius() == fRadius); |
| 113 float imageIncrement[2] = { 0 }; | 113 float imageIncrement[2] = { 0 }; |
| 114 float ySign = texture.origin() != kTopLeft_GrSurfaceOrigin ? 1.0f : -1.0f; | 114 float ySign = texture.origin() != kTopLeft_GrSurfaceOrigin ? 1.0f : -1.0f; |
| 115 switch (conv.direction()) { | 115 switch (conv.direction()) { |
| 116 case Gr1DKernelEffect::kX_Direction: | 116 case Gr1DKernelEffect::kX_Direction: |
| 117 imageIncrement[0] = 1.0f / texture.width(); | 117 imageIncrement[0] = 1.0f / texture.width(); |
| 118 break; | 118 break; |
| 119 case Gr1DKernelEffect::kY_Direction: | 119 case Gr1DKernelEffect::kY_Direction: |
| 120 imageIncrement[1] = ySign / texture.height(); | 120 imageIncrement[1] = ySign / texture.height(); |
| 121 break; | 121 break; |
| 122 default: | 122 default: |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 | 155 |
| 156 /////////////////////////////////////////////////////////////////////////////// | 156 /////////////////////////////////////////////////////////////////////////////// |
| 157 | 157 |
| 158 GrConvolutionEffect::GrConvolutionEffect(GrTexture* texture, | 158 GrConvolutionEffect::GrConvolutionEffect(GrTexture* texture, |
| 159 Direction direction, | 159 Direction direction, |
| 160 int radius, | 160 int radius, |
| 161 const float* kernel, | 161 const float* kernel, |
| 162 bool useBounds, | 162 bool useBounds, |
| 163 float bounds[2]) | 163 float bounds[2]) |
| 164 : Gr1DKernelEffect(texture, direction, radius), fUseBounds(useBounds) { | 164 : Gr1DKernelEffect(texture, direction, radius), fUseBounds(useBounds) { |
| 165 GrAssert(radius <= kMaxKernelRadius); | 165 SkASSERT(radius <= kMaxKernelRadius); |
| 166 GrAssert(NULL != kernel); | 166 SkASSERT(NULL != kernel); |
| 167 int width = this->width(); | 167 int width = this->width(); |
| 168 for (int i = 0; i < width; i++) { | 168 for (int i = 0; i < width; i++) { |
| 169 fKernel[i] = kernel[i]; | 169 fKernel[i] = kernel[i]; |
| 170 } | 170 } |
| 171 memcpy(fBounds, bounds, sizeof(fBounds)); | 171 memcpy(fBounds, bounds, sizeof(fBounds)); |
| 172 } | 172 } |
| 173 | 173 |
| 174 GrConvolutionEffect::GrConvolutionEffect(GrTexture* texture, | 174 GrConvolutionEffect::GrConvolutionEffect(GrTexture* texture, |
| 175 Direction direction, | 175 Direction direction, |
| 176 int radius, | 176 int radius, |
| 177 float gaussianSigma, | 177 float gaussianSigma, |
| 178 bool useBounds, | 178 bool useBounds, |
| 179 float bounds[2]) | 179 float bounds[2]) |
| 180 : Gr1DKernelEffect(texture, direction, radius), fUseBounds(useBounds) { | 180 : Gr1DKernelEffect(texture, direction, radius), fUseBounds(useBounds) { |
| 181 GrAssert(radius <= kMaxKernelRadius); | 181 SkASSERT(radius <= kMaxKernelRadius); |
| 182 int width = this->width(); | 182 int width = this->width(); |
| 183 | 183 |
| 184 float sum = 0.0f; | 184 float sum = 0.0f; |
| 185 float denom = 1.0f / (2.0f * gaussianSigma * gaussianSigma); | 185 float denom = 1.0f / (2.0f * gaussianSigma * gaussianSigma); |
| 186 for (int i = 0; i < width; ++i) { | 186 for (int i = 0; i < width; ++i) { |
| 187 float x = static_cast<float>(i - this->radius()); | 187 float x = static_cast<float>(i - this->radius()); |
| 188 // Note that the constant term (1/(sqrt(2*pi*sigma^2)) of the Gaussian | 188 // Note that the constant term (1/(sqrt(2*pi*sigma^2)) of the Gaussian |
| 189 // is dropped here, since we renormalize the kernel below. | 189 // is dropped here, since we renormalize the kernel below. |
| 190 fKernel[i] = sk_float_exp(- x * x * denom); | 190 fKernel[i] = sk_float_exp(- x * x * denom); |
| 191 sum += fKernel[i]; | 191 sum += fKernel[i]; |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 237 } | 237 } |
| 238 | 238 |
| 239 bool useBounds = random->nextBool(); | 239 bool useBounds = random->nextBool(); |
| 240 return GrConvolutionEffect::Create(textures[texIdx], | 240 return GrConvolutionEffect::Create(textures[texIdx], |
| 241 dir, | 241 dir, |
| 242 radius, | 242 radius, |
| 243 kernel, | 243 kernel, |
| 244 useBounds, | 244 useBounds, |
| 245 bounds); | 245 bounds); |
| 246 } | 246 } |
| OLD | NEW |