OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 The Android Open Source Project | 2 * Copyright 2012 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 "SkMatrixConvolutionImageFilter.h" | 8 #include "SkMatrixConvolutionImageFilter.h" |
9 #include "SkBitmap.h" | 9 #include "SkBitmap.h" |
10 #include "SkColorPriv.h" | 10 #include "SkColorPriv.h" |
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
378 } | 378 } |
379 builder->appendTextureLookup(GrGLShaderBuilder::kFragment_ShaderType, sample
r, coord); | 379 builder->appendTextureLookup(GrGLShaderBuilder::kFragment_ShaderType, sample
r, coord); |
380 } | 380 } |
381 | 381 |
382 void GrGLMatrixConvolutionEffect::emitCode(GrGLShaderBuilder* builder, | 382 void GrGLMatrixConvolutionEffect::emitCode(GrGLShaderBuilder* builder, |
383 const GrDrawEffect&, | 383 const GrDrawEffect&, |
384 EffectKey key, | 384 EffectKey key, |
385 const char* outputColor, | 385 const char* outputColor, |
386 const char* inputColor, | 386 const char* inputColor, |
387 const TextureSamplerArray& samplers)
{ | 387 const TextureSamplerArray& samplers)
{ |
388 const char* coords; | 388 SkString coords; |
389 fEffectMatrix.emitCodeMakeFSCoords2D(builder, key, &coords); | 389 fEffectMatrix.emitCodeMakeFSCoords2D(builder, key, &coords); |
390 fImageIncrementUni = builder->addUniform(GrGLShaderBuilder::kFragment_Shader
Type, | 390 fImageIncrementUni = builder->addUniform(GrGLShaderBuilder::kFragment_Shader
Type, |
391 kVec2f_GrSLType, "ImageIncrement"); | 391 kVec2f_GrSLType, "ImageIncrement"); |
392 fKernelUni = builder->addUniformArray(GrGLShaderBuilder::kFragment_ShaderTyp
e, | 392 fKernelUni = builder->addUniformArray(GrGLShaderBuilder::kFragment_ShaderTyp
e, |
393 kFloat_GrSLType, "Kernel", fKernelS
ize.width() * fKernelSize.height()); | 393 kFloat_GrSLType, "Kernel", fKernelS
ize.width() * fKernelSize.height()); |
394 fTargetUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType, | 394 fTargetUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType, |
395 kVec2f_GrSLType, "Target"); | 395 kVec2f_GrSLType, "Target"); |
396 fGainUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType, | 396 fGainUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType, |
397 kFloat_GrSLType, "Gain"); | 397 kFloat_GrSLType, "Gain"); |
398 fBiasUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType, | 398 fBiasUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType, |
399 kFloat_GrSLType, "Bias"); | 399 kFloat_GrSLType, "Bias"); |
400 | 400 |
401 const char* target = builder->getUniformCStr(fTargetUni); | 401 const char* target = builder->getUniformCStr(fTargetUni); |
402 const char* imgInc = builder->getUniformCStr(fImageIncrementUni); | 402 const char* imgInc = builder->getUniformCStr(fImageIncrementUni); |
403 const char* kernel = builder->getUniformCStr(fKernelUni); | 403 const char* kernel = builder->getUniformCStr(fKernelUni); |
404 const char* gain = builder->getUniformCStr(fGainUni); | 404 const char* gain = builder->getUniformCStr(fGainUni); |
405 const char* bias = builder->getUniformCStr(fBiasUni); | 405 const char* bias = builder->getUniformCStr(fBiasUni); |
406 int kWidth = fKernelSize.width(); | 406 int kWidth = fKernelSize.width(); |
407 int kHeight = fKernelSize.height(); | 407 int kHeight = fKernelSize.height(); |
408 | 408 |
409 builder->fsCodeAppend("\t\tvec4 sum = vec4(0, 0, 0, 0);\n"); | 409 builder->fsCodeAppend("\t\tvec4 sum = vec4(0, 0, 0, 0);\n"); |
410 builder->fsCodeAppendf("\t\tvec2 coord = %s - %s * %s;\n", coords, target, i
mgInc); | 410 builder->fsCodeAppendf("\t\tvec2 coord = %s - %s * %s;\n", coords.c_str(), t
arget, imgInc); |
411 builder->fsCodeAppendf("\t\tfor (int y = 0; y < %d; y++) {\n", kHeight); | 411 builder->fsCodeAppendf("\t\tfor (int y = 0; y < %d; y++) {\n", kHeight); |
412 builder->fsCodeAppendf("\t\t\tfor (int x = 0; x < %d; x++) {\n", kWidth); | 412 builder->fsCodeAppendf("\t\t\tfor (int x = 0; x < %d; x++) {\n", kWidth); |
413 builder->fsCodeAppendf("\t\t\t\tfloat k = %s[y * %d + x];\n", kernel, kWidth
); | 413 builder->fsCodeAppendf("\t\t\t\tfloat k = %s[y * %d + x];\n", kernel, kWidth
); |
414 builder->fsCodeAppendf("\t\t\t\tvec2 coord2 = coord + vec2(x, y) * %s;\n", i
mgInc); | 414 builder->fsCodeAppendf("\t\t\t\tvec2 coord2 = coord + vec2(x, y) * %s;\n", i
mgInc); |
415 builder->fsCodeAppend("\t\t\t\tvec4 c = "); | 415 builder->fsCodeAppend("\t\t\t\tvec4 c = "); |
416 appendTextureLookup(builder, samplers[0], "coord2", fTileMode); | 416 appendTextureLookup(builder, samplers[0], "coord2", fTileMode); |
417 builder->fsCodeAppend(";\n"); | 417 builder->fsCodeAppend(";\n"); |
418 if (!fConvolveAlpha) { | 418 if (!fConvolveAlpha) { |
419 builder->fsCodeAppend("\t\t\t\tc.rgb /= c.a;\n"); | 419 builder->fsCodeAppend("\t\t\t\tc.rgb /= c.a;\n"); |
420 } | 420 } |
421 builder->fsCodeAppend("\t\t\t\tsum += c * k;\n"); | 421 builder->fsCodeAppend("\t\t\t\tsum += c * k;\n"); |
422 builder->fsCodeAppend("\t\t\t}\n"); | 422 builder->fsCodeAppend("\t\t\t}\n"); |
423 builder->fsCodeAppend("\t\t}\n"); | 423 builder->fsCodeAppend("\t\t}\n"); |
424 if (fConvolveAlpha) { | 424 if (fConvolveAlpha) { |
425 builder->fsCodeAppendf("\t\t%s = sum * %s + %s;\n", outputColor, gain, b
ias); | 425 builder->fsCodeAppendf("\t\t%s = sum * %s + %s;\n", outputColor, gain, b
ias); |
426 builder->fsCodeAppendf("\t\t%s.rgb = clamp(%s.rgb, 0.0, %s.a);\n", outpu
tColor, outputColor, outputColor); | 426 builder->fsCodeAppendf("\t\t%s.rgb = clamp(%s.rgb, 0.0, %s.a);\n", outpu
tColor, outputColor, outputColor); |
427 } else { | 427 } else { |
428 builder->fsCodeAppend("\t\tvec4 c = "); | 428 builder->fsCodeAppend("\t\tvec4 c = "); |
429 appendTextureLookup(builder, samplers[0], coords, fTileMode); | 429 appendTextureLookup(builder, samplers[0], coords.c_str(), fTileMode); |
430 builder->fsCodeAppend(";\n"); | 430 builder->fsCodeAppend(";\n"); |
431 builder->fsCodeAppendf("\t\t%s.a = c.a;\n", outputColor); | 431 builder->fsCodeAppendf("\t\t%s.a = c.a;\n", outputColor); |
432 builder->fsCodeAppendf("\t\t%s.rgb = sum.rgb * %s + %s;\n", outputColor,
gain, bias); | 432 builder->fsCodeAppendf("\t\t%s.rgb = sum.rgb * %s + %s;\n", outputColor,
gain, bias); |
433 builder->fsCodeAppendf("\t\t%s.rgb *= %s.a;\n", outputColor, outputColor
); | 433 builder->fsCodeAppendf("\t\t%s.rgb *= %s.a;\n", outputColor, outputColor
); |
434 } | 434 } |
435 } | 435 } |
436 | 436 |
437 namespace { | 437 namespace { |
438 | 438 |
439 int encodeXY(int x, int y) { | 439 int encodeXY(int x, int y) { |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
573 fBias, | 573 fBias, |
574 fTarget, | 574 fTarget, |
575 fTileMode, | 575 fTileMode, |
576 fConvolveAlpha); | 576 fConvolveAlpha); |
577 return true; | 577 return true; |
578 } | 578 } |
579 | 579 |
580 /////////////////////////////////////////////////////////////////////////////// | 580 /////////////////////////////////////////////////////////////////////////////// |
581 | 581 |
582 #endif | 582 #endif |
OLD | NEW |