| OLD | NEW |
| 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 "glsl/GrGLSLFragmentProcessor.h" | 8 #include "glsl/GrGLSLFragmentProcessor.h" |
| 9 #include "glsl/GrGLSLProgramBuilder.h" | 9 #include "glsl/GrGLSLProgramBuilder.h" |
| 10 #include "glsl/GrGLSLProgramDataManager.h" | 10 #include "glsl/GrGLSLProgramDataManager.h" |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 fragBuilder->codeAppend("vec4 sum = vec4(0, 0, 0, 0);"); | 69 fragBuilder->codeAppend("vec4 sum = vec4(0, 0, 0, 0);"); |
| 70 fragBuilder->codeAppendf("vec2 coord = %s - %s * %s;", coords2D.c_str(), ker
nelOffset, imgInc); | 70 fragBuilder->codeAppendf("vec2 coord = %s - %s * %s;", coords2D.c_str(), ker
nelOffset, imgInc); |
| 71 fragBuilder->codeAppend("vec4 c;"); | 71 fragBuilder->codeAppend("vec4 c;"); |
| 72 | 72 |
| 73 for (int y = 0; y < kHeight; y++) { | 73 for (int y = 0; y < kHeight; y++) { |
| 74 for (int x = 0; x < kWidth; x++) { | 74 for (int x = 0; x < kWidth; x++) { |
| 75 GrGLSLShaderBuilder::ShaderBlock block(fragBuilder); | 75 GrGLSLShaderBuilder::ShaderBlock block(fragBuilder); |
| 76 fragBuilder->codeAppendf("float k = %s[%d * %d + %d];", kernel, y, k
Width, x); | 76 fragBuilder->codeAppendf("float k = %s[%d * %d + %d];", kernel, y, k
Width, x); |
| 77 SkString coord; | 77 SkString coord; |
| 78 coord.printf("coord + vec2(%d, %d) * %s", x, y, imgInc); | 78 coord.printf("coord + vec2(%d, %d) * %s", x, y, imgInc); |
| 79 fDomain.sampleTexture(fragBuilder, domain, "c", coord, args.fSampler
s[0]); | 79 fDomain.sampleTexture(fragBuilder, |
| 80 args.fGLSLCaps, |
| 81 domain, |
| 82 "c", |
| 83 coord, |
| 84 args.fSamplers[0]); |
| 80 if (!fConvolveAlpha) { | 85 if (!fConvolveAlpha) { |
| 81 fragBuilder->codeAppend("c.rgb /= c.a;"); | 86 fragBuilder->codeAppend("c.rgb /= c.a;"); |
| 82 fragBuilder->codeAppend("c.rgb = clamp(c.rgb, 0.0, 1.0);"); | 87 fragBuilder->codeAppend("c.rgb = clamp(c.rgb, 0.0, 1.0);"); |
| 83 } | 88 } |
| 84 fragBuilder->codeAppend("sum += c * k;"); | 89 fragBuilder->codeAppend("sum += c * k;"); |
| 85 } | 90 } |
| 86 } | 91 } |
| 87 if (fConvolveAlpha) { | 92 if (fConvolveAlpha) { |
| 88 fragBuilder->codeAppendf("%s = sum * %s + %s;", args.fOutputColor, gain,
bias); | 93 fragBuilder->codeAppendf("%s = sum * %s + %s;", args.fOutputColor, gain,
bias); |
| 89 fragBuilder->codeAppendf("%s.rgb = clamp(%s.rgb, 0.0, %s.a);", | 94 fragBuilder->codeAppendf("%s.rgb = clamp(%s.rgb, 0.0, %s.a);", |
| 90 args.fOutputColor, args.fOutputColor, args.fOut
putColor); | 95 args.fOutputColor, args.fOutputColor, args.fOut
putColor); |
| 91 } else { | 96 } else { |
| 92 fDomain.sampleTexture(fragBuilder, domain, "c", coords2D, args.fSamplers
[0]); | 97 fDomain.sampleTexture(fragBuilder, |
| 98 args.fGLSLCaps, |
| 99 domain, |
| 100 "c", |
| 101 coords2D, |
| 102 args.fSamplers[0]); |
| 93 fragBuilder->codeAppendf("%s.a = c.a;", args.fOutputColor); | 103 fragBuilder->codeAppendf("%s.a = c.a;", args.fOutputColor); |
| 94 fragBuilder->codeAppendf("%s.rgb = sum.rgb * %s + %s;", args.fOutputColo
r, gain, bias); | 104 fragBuilder->codeAppendf("%s.rgb = sum.rgb * %s + %s;", args.fOutputColo
r, gain, bias); |
| 95 fragBuilder->codeAppendf("%s.rgb *= %s.a;", args.fOutputColor, args.fOut
putColor); | 105 fragBuilder->codeAppendf("%s.rgb *= %s.a;", args.fOutputColor, args.fOut
putColor); |
| 96 } | 106 } |
| 97 | 107 |
| 98 SkString modulate; | 108 SkString modulate; |
| 99 GrGLSLMulVarBy4f(&modulate, args.fOutputColor, args.fInputColor); | 109 GrGLSLMulVarBy4f(&modulate, args.fOutputColor, args.fInputColor); |
| 100 fragBuilder->codeAppend(modulate.c_str()); | 110 fragBuilder->codeAppend(modulate.c_str()); |
| 101 } | 111 } |
| 102 | 112 |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 return GrMatrixConvolutionEffect::Create(d->fTextures[texIdx], | 253 return GrMatrixConvolutionEffect::Create(d->fTextures[texIdx], |
| 244 bounds, | 254 bounds, |
| 245 kernelSize, | 255 kernelSize, |
| 246 kernel.get(), | 256 kernel.get(), |
| 247 gain, | 257 gain, |
| 248 bias, | 258 bias, |
| 249 kernelOffset, | 259 kernelOffset, |
| 250 tileMode, | 260 tileMode, |
| 251 convolveAlpha); | 261 convolveAlpha); |
| 252 } | 262 } |
| OLD | NEW |