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 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 : INHERITED(factory) | 217 : INHERITED(factory) |
218 , fEffectMatrix(drawEffect.castEffect<GrBicubicEffect>().coordsType()) { | 218 , fEffectMatrix(drawEffect.castEffect<GrBicubicEffect>().coordsType()) { |
219 } | 219 } |
220 | 220 |
221 void GrGLBicubicEffect::emitCode(GrGLShaderBuilder* builder, | 221 void GrGLBicubicEffect::emitCode(GrGLShaderBuilder* builder, |
222 const GrDrawEffect&, | 222 const GrDrawEffect&, |
223 EffectKey key, | 223 EffectKey key, |
224 const char* outputColor, | 224 const char* outputColor, |
225 const char* inputColor, | 225 const char* inputColor, |
226 const TextureSamplerArray& samplers) { | 226 const TextureSamplerArray& samplers) { |
227 const char* coords; | 227 SkString coords; |
228 fEffectMatrix.emitCodeMakeFSCoords2D(builder, key, &coords); | 228 fEffectMatrix.emitCodeMakeFSCoords2D(builder, key, &coords); |
229 fCoefficientsUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderTy
pe, | 229 fCoefficientsUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderTy
pe, |
230 kMat44f_GrSLType, "Coefficients"); | 230 kMat44f_GrSLType, "Coefficients"); |
231 fImageIncrementUni = builder->addUniform(GrGLShaderBuilder::kFragment_Shader
Type, | 231 fImageIncrementUni = builder->addUniform(GrGLShaderBuilder::kFragment_Shader
Type, |
232 kVec2f_GrSLType, "ImageIncrement"); | 232 kVec2f_GrSLType, "ImageIncrement"); |
233 | 233 |
234 const char* imgInc = builder->getUniformCStr(fImageIncrementUni); | 234 const char* imgInc = builder->getUniformCStr(fImageIncrementUni); |
235 const char* coeff = builder->getUniformCStr(fCoefficientsUni); | 235 const char* coeff = builder->getUniformCStr(fCoefficientsUni); |
236 | 236 |
237 SkString cubicBlendName; | 237 SkString cubicBlendName; |
238 | 238 |
239 static const GrGLShaderVar gCubicBlendArgs[] = { | 239 static const GrGLShaderVar gCubicBlendArgs[] = { |
240 GrGLShaderVar("coefficients", kMat44f_GrSLType), | 240 GrGLShaderVar("coefficients", kMat44f_GrSLType), |
241 GrGLShaderVar("t", kFloat_GrSLType), | 241 GrGLShaderVar("t", kFloat_GrSLType), |
242 GrGLShaderVar("c0", kVec4f_GrSLType), | 242 GrGLShaderVar("c0", kVec4f_GrSLType), |
243 GrGLShaderVar("c1", kVec4f_GrSLType), | 243 GrGLShaderVar("c1", kVec4f_GrSLType), |
244 GrGLShaderVar("c2", kVec4f_GrSLType), | 244 GrGLShaderVar("c2", kVec4f_GrSLType), |
245 GrGLShaderVar("c3", kVec4f_GrSLType), | 245 GrGLShaderVar("c3", kVec4f_GrSLType), |
246 }; | 246 }; |
247 builder->emitFunction(GrGLShaderBuilder::kFragment_ShaderType, | 247 builder->emitFunction(GrGLShaderBuilder::kFragment_ShaderType, |
248 kVec4f_GrSLType, | 248 kVec4f_GrSLType, |
249 "cubicBlend", | 249 "cubicBlend", |
250 SK_ARRAY_COUNT(gCubicBlendArgs), | 250 SK_ARRAY_COUNT(gCubicBlendArgs), |
251 gCubicBlendArgs, | 251 gCubicBlendArgs, |
252 "\tvec4 ts = vec4(1.0, t, t * t, t * t * t);\n" | 252 "\tvec4 ts = vec4(1.0, t, t * t, t * t * t);\n" |
253 "\tvec4 c = coefficients * ts;\n" | 253 "\tvec4 c = coefficients * ts;\n" |
254 "\treturn c.x * c0 + c.y * c1 + c.z * c2 + c.w * c3;\n
", | 254 "\treturn c.x * c0 + c.y * c1 + c.z * c2 + c.w * c3;\n
", |
255 &cubicBlendName); | 255 &cubicBlendName); |
256 builder->fsCodeAppendf("\tvec2 coord = %s - %s * vec2(0.5, 0.5);\n", coords,
imgInc); | 256 builder->fsCodeAppendf("\tvec2 coord = %s - %s * vec2(0.5, 0.5);\n", coords.
c_str(), imgInc); |
257 builder->fsCodeAppendf("\tvec2 f = fract(coord / %s);\n", imgInc); | 257 builder->fsCodeAppendf("\tvec2 f = fract(coord / %s);\n", imgInc); |
258 for (int y = 0; y < 4; ++y) { | 258 for (int y = 0; y < 4; ++y) { |
259 for (int x = 0; x < 4; ++x) { | 259 for (int x = 0; x < 4; ++x) { |
260 SkString coord; | 260 SkString coord; |
261 coord.printf("coord + %s * vec2(%d, %d)", imgInc, x - 1, y - 1); | 261 coord.printf("coord + %s * vec2(%d, %d)", imgInc, x - 1, y - 1); |
262 builder->fsCodeAppendf("\tvec4 s%d%d = ", x, y); | 262 builder->fsCodeAppendf("\tvec4 s%d%d = ", x, y); |
263 builder->appendTextureLookup(GrGLShaderBuilder::kFragment_ShaderType
, | 263 builder->appendTextureLookup(GrGLShaderBuilder::kFragment_ShaderType
, |
264 samplers[0], | 264 samplers[0], |
265 coord.c_str()); | 265 coord.c_str()); |
266 builder->fsCodeAppend(";\n"); | 266 builder->fsCodeAppend(";\n"); |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
366 GrPaint paint; | 366 GrPaint paint; |
367 paint.addColorEffect(GrBicubicEffect::Create(srcTexture, fCoefficients))->un
ref(); | 367 paint.addColorEffect(GrBicubicEffect::Create(srcTexture, fCoefficients))->un
ref(); |
368 SkRect srcRect; | 368 SkRect srcRect; |
369 srcBM.getBounds(&srcRect); | 369 srcBM.getBounds(&srcRect); |
370 context->drawRectToRect(paint, dstRect, srcRect); | 370 context->drawRectToRect(paint, dstRect, srcRect); |
371 return SkImageFilterUtils::WrapTexture(dst, desc.fWidth, desc.fHeight, resul
t); | 371 return SkImageFilterUtils::WrapTexture(dst, desc.fWidth, desc.fHeight, resul
t); |
372 } | 372 } |
373 #endif | 373 #endif |
374 | 374 |
375 /////////////////////////////////////////////////////////////////////////////// | 375 /////////////////////////////////////////////////////////////////////////////// |
OLD | NEW |