OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 The Android Open Source Project | 2 * Copyright 2013 The Android Open Source Project |
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 "SkBicubicImageFilter.h" | 8 #include "SkBicubicImageFilter.h" |
9 #include "SkBitmap.h" | 9 #include "SkBitmap.h" |
10 #include "SkColorPriv.h" | 10 #include "SkColorPriv.h" |
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
219 const char* vertexCoords, | 219 const char* vertexCoords, |
220 const char* outputColor, | 220 const char* outputColor, |
221 const char* inputColor, | 221 const char* inputColor, |
222 const TextureSamplerArray& samplers) { | 222 const TextureSamplerArray& samplers) { |
223 const char* coords; | 223 const char* coords; |
224 fEffectMatrix.emitCodeMakeFSCoords2D(builder, key, vertexCoords, &coords); | 224 fEffectMatrix.emitCodeMakeFSCoords2D(builder, key, vertexCoords, &coords); |
225 fCoefficientsUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderTy
pe, | 225 fCoefficientsUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderTy
pe, |
226 kMat44f_GrSLType, "Coefficients"); | 226 kMat44f_GrSLType, "Coefficients"); |
227 fImageIncrementUni = builder->addUniform(GrGLShaderBuilder::kFragment_Shader
Type, | 227 fImageIncrementUni = builder->addUniform(GrGLShaderBuilder::kFragment_Shader
Type, |
228 kVec2f_GrSLType, "ImageIncrement"); | 228 kVec2f_GrSLType, "ImageIncrement"); |
229 SkString* code = &builder->fFSCode; | |
230 | 229 |
231 const char* imgInc = builder->getUniformCStr(fImageIncrementUni); | 230 const char* imgInc = builder->getUniformCStr(fImageIncrementUni); |
232 const char* coeff = builder->getUniformCStr(fCoefficientsUni); | 231 const char* coeff = builder->getUniformCStr(fCoefficientsUni); |
233 | 232 |
234 SkString cubicBlendName; | 233 SkString cubicBlendName; |
235 | 234 |
236 static const GrGLShaderVar gCubicBlendArgs[] = { | 235 static const GrGLShaderVar gCubicBlendArgs[] = { |
237 GrGLShaderVar("coefficients", kMat44f_GrSLType), | 236 GrGLShaderVar("coefficients", kMat44f_GrSLType), |
238 GrGLShaderVar("t", kFloat_GrSLType), | 237 GrGLShaderVar("t", kFloat_GrSLType), |
239 GrGLShaderVar("c0", kVec4f_GrSLType), | 238 GrGLShaderVar("c0", kVec4f_GrSLType), |
240 GrGLShaderVar("c1", kVec4f_GrSLType), | 239 GrGLShaderVar("c1", kVec4f_GrSLType), |
241 GrGLShaderVar("c2", kVec4f_GrSLType), | 240 GrGLShaderVar("c2", kVec4f_GrSLType), |
242 GrGLShaderVar("c3", kVec4f_GrSLType), | 241 GrGLShaderVar("c3", kVec4f_GrSLType), |
243 }; | 242 }; |
244 builder->emitFunction(GrGLShaderBuilder::kFragment_ShaderType, | 243 builder->emitFunction(GrGLShaderBuilder::kFragment_ShaderType, |
245 kVec4f_GrSLType, | 244 kVec4f_GrSLType, |
246 "cubicBlend", | 245 "cubicBlend", |
247 SK_ARRAY_COUNT(gCubicBlendArgs), | 246 SK_ARRAY_COUNT(gCubicBlendArgs), |
248 gCubicBlendArgs, | 247 gCubicBlendArgs, |
249 "\tvec4 ts = vec4(1.0, t, t * t, t * t * t);\n" | 248 "\tvec4 ts = vec4(1.0, t, t * t, t * t * t);\n" |
250 "\tvec4 c = coefficients * ts;\n" | 249 "\tvec4 c = coefficients * ts;\n" |
251 "\treturn c.x * c0 + c.y * c1 + c.z * c2 + c.w * c3;\n
", | 250 "\treturn c.x * c0 + c.y * c1 + c.z * c2 + c.w * c3;\n
", |
252 &cubicBlendName); | 251 &cubicBlendName); |
253 code->appendf("\tvec2 coord = %s - %s * vec2(0.5, 0.5);\n", coords, imgInc); | 252 builder->fsCodeAppendf("\tvec2 coord = %s - %s * vec2(0.5, 0.5);\n", coords,
imgInc); |
254 code->appendf("\tvec2 f = fract(coord / %s);\n", imgInc); | 253 builder->fsCodeAppendf("\tvec2 f = fract(coord / %s);\n", imgInc); |
255 for (int y = 0; y < 4; ++y) { | 254 for (int y = 0; y < 4; ++y) { |
256 for (int x = 0; x < 4; ++x) { | 255 for (int x = 0; x < 4; ++x) { |
257 SkString coord; | 256 SkString coord; |
258 coord.printf("coord + %s * vec2(%d, %d)", imgInc, x - 1, y - 1); | 257 coord.printf("coord + %s * vec2(%d, %d)", imgInc, x - 1, y - 1); |
259 code->appendf("\tvec4 s%d%d = ", x, y); | 258 builder->fsCodeAppendf("\tvec4 s%d%d = ", x, y); |
260 builder->appendTextureLookup(&builder->fFSCode, samplers[0], coord.c
_str()); | 259 builder->appendTextureLookup(GrGLShaderBuilder::kFragment_ShaderType
, |
261 code->appendf(";\n"); | 260 samplers[0], |
| 261 coord.c_str()); |
| 262 builder->fsCodeAppend(";\n"); |
262 } | 263 } |
263 code->appendf("\tvec4 s%d = %s(%s, f.x, s0%d, s1%d, s2%d, s3%d);\n", y,
cubicBlendName.c_str(), coeff, y, y, y, y); | 264 builder->fsCodeAppendf("\tvec4 s%d = %s(%s, f.x, s0%d, s1%d, s2%d, s3%d)
;\n", y, cubicBlendName.c_str(), coeff, y, y, y, y); |
264 } | 265 } |
265 code->appendf("\t%s = %s(%s, f.y, s0, s1, s2, s3);\n", outputColor, cubicBle
ndName.c_str(), coeff); | 266 builder->fsCodeAppendf("\t%s = %s(%s, f.y, s0, s1, s2, s3);\n", outputColor,
cubicBlendName.c_str(), coeff); |
266 } | 267 } |
267 | 268 |
268 GrGLEffect::EffectKey GrGLBicubicEffect::GenKey(const GrEffectStage& s, const Gr
GLCaps&) { | 269 GrGLEffect::EffectKey GrGLBicubicEffect::GenKey(const GrEffectStage& s, const Gr
GLCaps&) { |
269 const GrBicubicEffect& m = GetEffectFromStage<GrBicubicEffect>(s); | 270 const GrBicubicEffect& m = GetEffectFromStage<GrBicubicEffect>(s); |
270 EffectKey matrixKey = GrGLEffectMatrix::GenKey(m.getMatrix(), | 271 EffectKey matrixKey = GrGLEffectMatrix::GenKey(m.getMatrix(), |
271 s.getCoordChangeMatrix(), | 272 s.getCoordChangeMatrix(), |
272 m.texture(0)); | 273 m.texture(0)); |
273 return matrixKey; | 274 return matrixKey; |
274 } | 275 } |
275 | 276 |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
358 GrPaint paint; | 359 GrPaint paint; |
359 paint.colorStage(0)->setEffect(GrBicubicEffect::Create(srcTexture, fCoeffici
ents))->unref(); | 360 paint.colorStage(0)->setEffect(GrBicubicEffect::Create(srcTexture, fCoeffici
ents))->unref(); |
360 SkRect srcRect; | 361 SkRect srcRect; |
361 srcBM.getBounds(&srcRect); | 362 srcBM.getBounds(&srcRect); |
362 context->drawRectToRect(paint, dstRect, srcRect); | 363 context->drawRectToRect(paint, dstRect, srcRect); |
363 return SkImageFilterUtils::WrapTexture(dst, desc.fWidth, desc.fHeight, resul
t); | 364 return SkImageFilterUtils::WrapTexture(dst, desc.fWidth, desc.fHeight, resul
t); |
364 } | 365 } |
365 #endif | 366 #endif |
366 | 367 |
367 /////////////////////////////////////////////////////////////////////////////// | 368 /////////////////////////////////////////////////////////////////////////////// |
OLD | NEW |