Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(227)

Side by Side Diff: src/gpu/effects/GrMatrixConvolutionEffect.cpp

Issue 1225923010: Refugee from Dead Machine 4: MDB Monster Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Last update from dead machine Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright 2014 Google Inc. 2 * Copyright 2014 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 #include "GrMatrixConvolutionEffect.h" 7 #include "GrMatrixConvolutionEffect.h"
8 #include "gl/GrGLFragmentProcessor.h" 8 #include "gl/GrGLFragmentProcessor.h"
9 #include "gl/GrGLTexture.h" 9 #include "gl/GrGLTexture.h"
10 #include "gl/builders/GrGLProgramBuilder.h" 10 #include "gl/builders/GrGLProgramBuilder.h"
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 } 131 }
132 132
133 GrMatrixConvolutionEffect::GrMatrixConvolutionEffect(GrTexture* texture, 133 GrMatrixConvolutionEffect::GrMatrixConvolutionEffect(GrTexture* texture,
134 const SkIRect& bounds, 134 const SkIRect& bounds,
135 const SkISize& kernelSize, 135 const SkISize& kernelSize,
136 const SkScalar* kernel, 136 const SkScalar* kernel,
137 SkScalar gain, 137 SkScalar gain,
138 SkScalar bias, 138 SkScalar bias,
139 const SkIPoint& kernelOffse t, 139 const SkIPoint& kernelOffse t,
140 GrTextureDomain::Mode tileM ode, 140 GrTextureDomain::Mode tileM ode,
141 bool convolveAlpha) 141 bool convolveAlpha, GrRende rTarget* dst)
142 : INHERITED(texture, GrCoordTransform::MakeDivByTextureWHMatrix(texture)), 142 : INHERITED(texture, GrCoordTransform::MakeDivByTextureWHMatrix(texture), kLoc al_GrCoordSet, dst),
143 fKernelSize(kernelSize), 143 fKernelSize(kernelSize),
144 fGain(SkScalarToFloat(gain)), 144 fGain(SkScalarToFloat(gain)),
145 fBias(SkScalarToFloat(bias) / 255.0f), 145 fBias(SkScalarToFloat(bias) / 255.0f),
146 fConvolveAlpha(convolveAlpha), 146 fConvolveAlpha(convolveAlpha),
147 fDomain(GrTextureDomain::MakeTexelDomainForMode(texture, bounds, tileMode), tileMode) { 147 fDomain(GrTextureDomain::MakeTexelDomainForMode(texture, bounds, tileMode), tileMode) {
148 this->initClassID<GrMatrixConvolutionEffect>(); 148 this->initClassID<GrMatrixConvolutionEffect>();
149 for (int i = 0; i < kernelSize.width() * kernelSize.height(); i++) { 149 for (int i = 0; i < kernelSize.width() * kernelSize.height(); i++) {
150 fKernel[i] = SkScalarToFloat(kernel[i]); 150 fKernel[i] = SkScalarToFloat(kernel[i]);
151 } 151 }
152 fKernelOffset[0] = static_cast<float>(kernelOffset.x()); 152 fKernelOffset[0] = static_cast<float>(kernelOffset.x());
(...skipping 28 matching lines...) Expand all
181 GrFragmentProcessor* 181 GrFragmentProcessor*
182 GrMatrixConvolutionEffect::CreateGaussian(GrTexture* texture, 182 GrMatrixConvolutionEffect::CreateGaussian(GrTexture* texture,
183 const SkIRect& bounds, 183 const SkIRect& bounds,
184 const SkISize& kernelSize, 184 const SkISize& kernelSize,
185 SkScalar gain, 185 SkScalar gain,
186 SkScalar bias, 186 SkScalar bias,
187 const SkIPoint& kernelOffset, 187 const SkIPoint& kernelOffset,
188 GrTextureDomain::Mode tileMode, 188 GrTextureDomain::Mode tileMode,
189 bool convolveAlpha, 189 bool convolveAlpha,
190 SkScalar sigmaX, 190 SkScalar sigmaX,
191 SkScalar sigmaY) { 191 SkScalar sigmaY, GrRenderTarget* dst) {
192 float kernel[MAX_KERNEL_SIZE]; 192 float kernel[MAX_KERNEL_SIZE];
193 int width = kernelSize.width(); 193 int width = kernelSize.width();
194 int height = kernelSize.height(); 194 int height = kernelSize.height();
195 SkASSERT(width * height <= MAX_KERNEL_SIZE); 195 SkASSERT(width * height <= MAX_KERNEL_SIZE);
196 float sum = 0.0f; 196 float sum = 0.0f;
197 float sigmaXDenom = 1.0f / (2.0f * SkScalarToFloat(SkScalarSquare(sigmaX))); 197 float sigmaXDenom = 1.0f / (2.0f * SkScalarToFloat(SkScalarSquare(sigmaX)));
198 float sigmaYDenom = 1.0f / (2.0f * SkScalarToFloat(SkScalarSquare(sigmaY))); 198 float sigmaYDenom = 1.0f / (2.0f * SkScalarToFloat(SkScalarSquare(sigmaY)));
199 int xRadius = width / 2; 199 int xRadius = width / 2;
200 int yRadius = height / 2; 200 int yRadius = height / 2;
201 for (int x = 0; x < width; x++) { 201 for (int x = 0; x < width; x++) {
202 float xTerm = static_cast<float>(x - xRadius); 202 float xTerm = static_cast<float>(x - xRadius);
203 xTerm = xTerm * xTerm * sigmaXDenom; 203 xTerm = xTerm * xTerm * sigmaXDenom;
204 for (int y = 0; y < height; y++) { 204 for (int y = 0; y < height; y++) {
205 float yTerm = static_cast<float>(y - yRadius); 205 float yTerm = static_cast<float>(y - yRadius);
206 float xyTerm = sk_float_exp(-(xTerm + yTerm * yTerm * sigmaYDenom)); 206 float xyTerm = sk_float_exp(-(xTerm + yTerm * yTerm * sigmaYDenom));
207 // Note that the constant term (1/(sqrt(2*pi*sigma^2)) of the Gaussian 207 // Note that the constant term (1/(sqrt(2*pi*sigma^2)) of the Gaussian
208 // is dropped here, since we renormalize the kernel below. 208 // is dropped here, since we renormalize the kernel below.
209 kernel[y * width + x] = xyTerm; 209 kernel[y * width + x] = xyTerm;
210 sum += xyTerm; 210 sum += xyTerm;
211 } 211 }
212 } 212 }
213 // Normalize the kernel 213 // Normalize the kernel
214 float scale = 1.0f / sum; 214 float scale = 1.0f / sum;
215 for (int i = 0; i < width * height; ++i) { 215 for (int i = 0; i < width * height; ++i) {
216 kernel[i] *= scale; 216 kernel[i] *= scale;
217 } 217 }
218 return new GrMatrixConvolutionEffect(texture, bounds, kernelSize, kernel, ga in, bias, 218 return new GrMatrixConvolutionEffect(texture, bounds, kernelSize, kernel, ga in,
219 kernelOffset, tileMode, convolveAlpha); 219 bias, kernelOffset, tileMode, convolveA lpha, dst);
220 } 220 }
221 221
222 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrMatrixConvolutionEffect); 222 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrMatrixConvolutionEffect);
223 223
224 const GrFragmentProcessor* GrMatrixConvolutionEffect::TestCreate(GrProcessorTest Data* d) { 224 const GrFragmentProcessor* GrMatrixConvolutionEffect::TestCreate(GrProcessorTest Data* d) {
225 int texIdx = d->fRandom->nextBool() ? GrProcessorUnitTest::kSkiaPMTextureIdx : 225 int texIdx = d->fRandom->nextBool() ? GrProcessorUnitTest::kSkiaPMTextureIdx :
226 GrProcessorUnitTest::kAlphaTextureIdx; 226 GrProcessorUnitTest::kAlphaTextureIdx;
227 int width = d->fRandom->nextRangeU(1, MAX_KERNEL_SIZE); 227 int width = d->fRandom->nextRangeU(1, MAX_KERNEL_SIZE);
228 int height = d->fRandom->nextRangeU(1, MAX_KERNEL_SIZE / width); 228 int height = d->fRandom->nextRangeU(1, MAX_KERNEL_SIZE / width);
229 SkISize kernelSize = SkISize::Make(width, height); 229 SkISize kernelSize = SkISize::Make(width, height);
(...skipping 13 matching lines...) Expand all
243 static_cast<GrTextureDomain::Mode>(d->fRandom->nextRangeU(0, 2)); 243 static_cast<GrTextureDomain::Mode>(d->fRandom->nextRangeU(0, 2));
244 bool convolveAlpha = d->fRandom->nextBool(); 244 bool convolveAlpha = d->fRandom->nextBool();
245 return GrMatrixConvolutionEffect::Create(d->fTextures[texIdx], 245 return GrMatrixConvolutionEffect::Create(d->fTextures[texIdx],
246 bounds, 246 bounds,
247 kernelSize, 247 kernelSize,
248 kernel.get(), 248 kernel.get(),
249 gain, 249 gain,
250 bias, 250 bias,
251 kernelOffset, 251 kernelOffset,
252 tileMode, 252 tileMode,
253 convolveAlpha); 253 convolveAlpha, NULL);
254 } 254 }
OLDNEW
« no previous file with comments | « src/gpu/effects/GrMatrixConvolutionEffect.h ('k') | src/gpu/effects/GrPorterDuffXferProcessor.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698