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 "gl/GrGLProcessor.h" | 8 #include "gl/GrGLProcessor.h" |
9 #include "gl/GrGLSL.h" | 9 #include "gl/GrGLSL.h" |
10 #include "gl/GrGLTexture.h" | 10 #include "gl/GrGLTexture.h" |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 | 83 |
84 for (int y = 0; y < kHeight; y++) { | 84 for (int y = 0; y < kHeight; y++) { |
85 for (int x = 0; x < kWidth; x++) { | 85 for (int x = 0; x < kWidth; x++) { |
86 GrGLShaderBuilder::ShaderBlock block(fsBuilder); | 86 GrGLShaderBuilder::ShaderBlock block(fsBuilder); |
87 fsBuilder->codeAppendf("float k = %s[%d * %d + %d];", kernel, y, kWi
dth, x); | 87 fsBuilder->codeAppendf("float k = %s[%d * %d + %d];", kernel, y, kWi
dth, x); |
88 SkString coord; | 88 SkString coord; |
89 coord.printf("coord + vec2(%d, %d) * %s", x, y, imgInc); | 89 coord.printf("coord + vec2(%d, %d) * %s", x, y, imgInc); |
90 fDomain.sampleTexture(fsBuilder, domain, "c", coord, samplers[0]); | 90 fDomain.sampleTexture(fsBuilder, domain, "c", coord, samplers[0]); |
91 if (!fConvolveAlpha) { | 91 if (!fConvolveAlpha) { |
92 fsBuilder->codeAppend("c.rgb /= c.a;"); | 92 fsBuilder->codeAppend("c.rgb /= c.a;"); |
| 93 fsBuilder->codeAppend("c.rgb = clamp(c.rgb, 0.0, 1.0);"); |
93 } | 94 } |
94 fsBuilder->codeAppend("sum += c * k;"); | 95 fsBuilder->codeAppend("sum += c * k;"); |
95 } | 96 } |
96 } | 97 } |
97 if (fConvolveAlpha) { | 98 if (fConvolveAlpha) { |
98 fsBuilder->codeAppendf("%s = sum * %s + %s;", outputColor, gain, bias); | 99 fsBuilder->codeAppendf("%s = sum * %s + %s;", outputColor, gain, bias); |
99 fsBuilder->codeAppendf("%s.rgb = clamp(%s.rgb, 0.0, %s.a);", | 100 fsBuilder->codeAppendf("%s.rgb = clamp(%s.rgb, 0.0, %s.a);", |
100 outputColor, outputColor, outputColor); | 101 outputColor, outputColor, outputColor); |
101 } else { | 102 } else { |
102 fDomain.sampleTexture(fsBuilder, domain, "c", coords2D, samplers[0]); | 103 fDomain.sampleTexture(fsBuilder, domain, "c", coords2D, samplers[0]); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 SkScalar gain, | 146 SkScalar gain, |
146 SkScalar bias, | 147 SkScalar bias, |
147 const SkIPoint& kernelOffse
t, | 148 const SkIPoint& kernelOffse
t, |
148 GrTextureDomain::Mode tileM
ode, | 149 GrTextureDomain::Mode tileM
ode, |
149 bool convolveAlpha) | 150 bool convolveAlpha) |
150 : INHERITED(texture, GrCoordTransform::MakeDivByTextureWHMatrix(texture)), | 151 : INHERITED(texture, GrCoordTransform::MakeDivByTextureWHMatrix(texture)), |
151 fKernelSize(kernelSize), | 152 fKernelSize(kernelSize), |
152 fGain(SkScalarToFloat(gain)), | 153 fGain(SkScalarToFloat(gain)), |
153 fBias(SkScalarToFloat(bias) / 255.0f), | 154 fBias(SkScalarToFloat(bias) / 255.0f), |
154 fConvolveAlpha(convolveAlpha), | 155 fConvolveAlpha(convolveAlpha), |
155 fDomain(GrTextureDomain::MakeTexelDomain(texture, bounds), tileMode) { | 156 fDomain(GrTextureDomain::MakeTexelDomainForMode(texture, bounds, tileMode),
tileMode) { |
156 this->initClassID<GrMatrixConvolutionEffect>(); | 157 this->initClassID<GrMatrixConvolutionEffect>(); |
157 for (int i = 0; i < kernelSize.width() * kernelSize.height(); i++) { | 158 for (int i = 0; i < kernelSize.width() * kernelSize.height(); i++) { |
158 fKernel[i] = SkScalarToFloat(kernel[i]); | 159 fKernel[i] = SkScalarToFloat(kernel[i]); |
159 } | 160 } |
160 fKernelOffset[0] = static_cast<float>(kernelOffset.x()); | 161 fKernelOffset[0] = static_cast<float>(kernelOffset.x()); |
161 fKernelOffset[1] = static_cast<float>(kernelOffset.y()); | 162 fKernelOffset[1] = static_cast<float>(kernelOffset.y()); |
162 } | 163 } |
163 | 164 |
164 GrMatrixConvolutionEffect::~GrMatrixConvolutionEffect() { | 165 GrMatrixConvolutionEffect::~GrMatrixConvolutionEffect() { |
165 } | 166 } |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
262 return GrMatrixConvolutionEffect::Create(textures[texIdx], | 263 return GrMatrixConvolutionEffect::Create(textures[texIdx], |
263 bounds, | 264 bounds, |
264 kernelSize, | 265 kernelSize, |
265 kernel.get(), | 266 kernel.get(), |
266 gain, | 267 gain, |
267 bias, | 268 bias, |
268 kernelOffset, | 269 kernelOffset, |
269 tileMode, | 270 tileMode, |
270 convolveAlpha); | 271 convolveAlpha); |
271 } | 272 } |
OLD | NEW |