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/GrGLFragmentProcessor.h" | 9 #include "gl/GrGLFragmentProcessor.h" |
10 #include "gl/GrGLTexture.h" | 10 #include "gl/GrGLTexture.h" |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 fKernelUni = args.fBuilder->addUniformArray(GrGLProgramBuilder::kFragment_Vi
sibility, | 58 fKernelUni = args.fBuilder->addUniformArray(GrGLProgramBuilder::kFragment_Vi
sibility, |
59 kFloat_GrSLType, kDefault_GrSLPrecisio
n, | 59 kFloat_GrSLType, kDefault_GrSLPrecisio
n, |
60 "Kernel", this->width()); | 60 "Kernel", this->width()); |
61 | 61 |
62 GrGLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder(); | 62 GrGLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder(); |
63 SkString coords2D = fsBuilder->ensureFSCoords2D(args.fCoords, 0); | 63 SkString coords2D = fsBuilder->ensureFSCoords2D(args.fCoords, 0); |
64 | 64 |
65 fsBuilder->codeAppendf("\t\t%s = vec4(0, 0, 0, 0);\n", args.fOutputColor); | 65 fsBuilder->codeAppendf("\t\t%s = vec4(0, 0, 0, 0);\n", args.fOutputColor); |
66 | 66 |
67 int width = this->width(); | 67 int width = this->width(); |
68 const GrGLShaderVar& kernel = args.fBuilder->getUniformVariable(fKernelUni); | 68 const GrGLSLShaderVar& kernel = args.fBuilder->getUniformVariable(fKernelUni
); |
69 const char* imgInc = args.fBuilder->getUniformCStr(fImageIncrementUni); | 69 const char* imgInc = args.fBuilder->getUniformCStr(fImageIncrementUni); |
70 | 70 |
71 fsBuilder->codeAppendf("\t\tvec2 coord = %s - %d.0 * %s;\n", coords2D.c_str(
), fRadius, imgInc); | 71 fsBuilder->codeAppendf("\t\tvec2 coord = %s - %d.0 * %s;\n", coords2D.c_str(
), fRadius, imgInc); |
72 | 72 |
73 // Manually unroll loop because some drivers don't; yields 20-30% speedup. | 73 // Manually unroll loop because some drivers don't; yields 20-30% speedup. |
74 for (int i = 0; i < width; i++) { | 74 for (int i = 0; i < width; i++) { |
75 SkString index; | 75 SkString index; |
76 SkString kernelIndex; | 76 SkString kernelIndex; |
77 index.appendS32(i); | 77 index.appendS32(i); |
78 kernel.appendArrayAccess(index.c_str(), &kernelIndex); | 78 kernel.appendArrayAccess(index.c_str(), &kernelIndex); |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
230 } | 230 } |
231 | 231 |
232 bool useBounds = d->fRandom->nextBool(); | 232 bool useBounds = d->fRandom->nextBool(); |
233 return GrConvolutionEffect::Create(d->fTextures[texIdx], | 233 return GrConvolutionEffect::Create(d->fTextures[texIdx], |
234 dir, | 234 dir, |
235 radius, | 235 radius, |
236 kernel, | 236 kernel, |
237 useBounds, | 237 useBounds, |
238 bounds); | 238 bounds); |
239 } | 239 } |
OLD | NEW |