OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 #include "SkColorMatrixFilter.h" | 8 #include "SkColorMatrixFilter.h" |
9 #include "SkColorMatrix.h" | 9 #include "SkColorMatrix.h" |
10 #include "SkColorPriv.h" | 10 #include "SkColorPriv.h" |
(...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
391 | 391 |
392 GLEffect(const GrBackendEffectFactory& factory, | 392 GLEffect(const GrBackendEffectFactory& factory, |
393 const GrDrawEffect&) | 393 const GrDrawEffect&) |
394 : INHERITED(factory) { | 394 : INHERITED(factory) { |
395 } | 395 } |
396 | 396 |
397 virtual void emitCode(GrGLShaderBuilder* builder, | 397 virtual void emitCode(GrGLShaderBuilder* builder, |
398 const GrDrawEffect&, | 398 const GrDrawEffect&, |
399 EffectKey, | 399 EffectKey, |
400 const char* outputColor, | 400 const char* outputColor, |
401 const char* inputColor, | 401 const GrGLSLExpr4& inputColor, |
402 const TransformedCoordsArray&, | 402 const TransformedCoordsArray&, |
403 const TextureSamplerArray&) SK_OVERRIDE { | 403 const TextureSamplerArray&) SK_OVERRIDE { |
404 fMatrixHandle = builder->addUniform(GrGLShaderBuilder::kFragment_Vis
ibility, | 404 fMatrixHandle = builder->addUniform(GrGLShaderBuilder::kFragment_Vis
ibility, |
405 kMat44f_GrSLType, | 405 kMat44f_GrSLType, |
406 "ColorMatrix"); | 406 "ColorMatrix"); |
407 fVectorHandle = builder->addUniform(GrGLShaderBuilder::kFragment_Vis
ibility, | 407 fVectorHandle = builder->addUniform(GrGLShaderBuilder::kFragment_Vis
ibility, |
408 kVec4f_GrSLType, | 408 kVec4f_GrSLType, |
409 "ColorMatrixVector"); | 409 "ColorMatrixVector"); |
410 | 410 |
411 if (NULL == inputColor) { | |
412 // could optimize this case, but we aren't for now. | |
413 inputColor = "vec4(1)"; | |
414 } | |
415 // The max() is to guard against 0 / 0 during unpremul when the inco
ming color is | 411 // The max() is to guard against 0 / 0 during unpremul when the inco
ming color is |
416 // transparent black. | 412 // transparent black. |
417 builder->fsCodeAppendf("\tfloat nonZeroAlpha = max(%s.a, 0.00001);\n
", inputColor); | 413 builder->fsCodeAppendf("\tfloat nonZeroAlpha = %s;\n", GrGLSL::max(i
nputColor.a(), 0.00001f).c_str()); |
418 builder->fsCodeAppendf("\t%s = %s * vec4(%s.rgb / nonZeroAlpha, nonZ
eroAlpha) + %s;\n", | 414 builder->fsCodeAppendf("\t%s = %s * vec4(%s.rgb / nonZeroAlpha, nonZ
eroAlpha) + %s;\n", |
419 outputColor, | 415 outputColor, |
420 builder->getUniformCStr(fMatrixHandle), | 416 builder->getUniformCStr(fMatrixHandle), |
421 inputColor, | 417 inputColor.c_str(), |
422 builder->getUniformCStr(fVectorHandle)); | 418 builder->getUniformCStr(fVectorHandle)); |
423 builder->fsCodeAppendf("\t%s.rgb *= %s.a;\n", outputColor, outputCol
or); | 419 builder->fsCodeAppendf("\t%s.rgb *= %s.a;\n", outputColor, outputCol
or); |
424 } | 420 } |
425 | 421 |
426 virtual void setData(const GrGLUniformManager& uniManager, | 422 virtual void setData(const GrGLUniformManager& uniManager, |
427 const GrDrawEffect& drawEffect) SK_OVERRIDE { | 423 const GrDrawEffect& drawEffect) SK_OVERRIDE { |
428 const ColorMatrixEffect& cme = drawEffect.castEffect<ColorMatrixEffe
ct>(); | 424 const ColorMatrixEffect& cme = drawEffect.castEffect<ColorMatrixEffe
ct>(); |
429 const float* m = cme.fMatrix.fMat; | 425 const float* m = cme.fMatrix.fMat; |
430 // The GL matrix is transposed from SkColorMatrix. | 426 // The GL matrix is transposed from SkColorMatrix. |
431 GrGLfloat mt[] = { | 427 GrGLfloat mt[] = { |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
486 str->append("matrix: ("); | 482 str->append("matrix: ("); |
487 for (int i = 0; i < 20; ++i) { | 483 for (int i = 0; i < 20; ++i) { |
488 str->appendScalar(fMatrix.fMat[i]); | 484 str->appendScalar(fMatrix.fMat[i]); |
489 if (i < 19) { | 485 if (i < 19) { |
490 str->append(", "); | 486 str->append(", "); |
491 } | 487 } |
492 } | 488 } |
493 str->append(")"); | 489 str->append(")"); |
494 } | 490 } |
495 #endif | 491 #endif |
OLD | NEW |