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