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 410 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
421 builder->fsCodeAppendf("\tfloat nonZeroAlpha = max(%s.a, 0.00001);\n
", inputColor); | 421 builder->fsCodeAppendf("\tfloat nonZeroAlpha = max(%s.a, 0.00001);\n
", inputColor); |
422 builder->fsCodeAppendf("\t%s = %s * vec4(%s.rgb / nonZeroAlpha, nonZ
eroAlpha) + %s;\n", | 422 builder->fsCodeAppendf("\t%s = %s * vec4(%s.rgb / nonZeroAlpha, nonZ
eroAlpha) + %s;\n", |
423 outputColor, | 423 outputColor, |
424 builder->getUniformCStr(fMatrixHandle), | 424 builder->getUniformCStr(fMatrixHandle), |
425 inputColor, | 425 inputColor, |
426 builder->getUniformCStr(fVectorHandle)); | 426 builder->getUniformCStr(fVectorHandle)); |
427 builder->fsCodeAppendf("\t%s = clamp(%s, 0.0, 1.0);\n", outputColor,
outputColor); | 427 builder->fsCodeAppendf("\t%s = clamp(%s, 0.0, 1.0);\n", outputColor,
outputColor); |
428 builder->fsCodeAppendf("\t%s.rgb *= %s.a;\n", outputColor, outputCol
or); | 428 builder->fsCodeAppendf("\t%s.rgb *= %s.a;\n", outputColor, outputCol
or); |
429 } | 429 } |
430 | 430 |
431 virtual void setData(const GrGLUniformManager& uniManager, | 431 virtual void setData(const GrGLProgramDataManager& uniManager, |
432 const GrDrawEffect& drawEffect) SK_OVERRIDE { | 432 const GrDrawEffect& drawEffect) SK_OVERRIDE { |
433 const ColorMatrixEffect& cme = drawEffect.castEffect<ColorMatrixEffe
ct>(); | 433 const ColorMatrixEffect& cme = drawEffect.castEffect<ColorMatrixEffe
ct>(); |
434 const float* m = cme.fMatrix.fMat; | 434 const float* m = cme.fMatrix.fMat; |
435 // The GL matrix is transposed from SkColorMatrix. | 435 // The GL matrix is transposed from SkColorMatrix. |
436 GrGLfloat mt[] = { | 436 GrGLfloat mt[] = { |
437 m[0], m[5], m[10], m[15], | 437 m[0], m[5], m[10], m[15], |
438 m[1], m[6], m[11], m[16], | 438 m[1], m[6], m[11], m[16], |
439 m[2], m[7], m[12], m[17], | 439 m[2], m[7], m[12], m[17], |
440 m[3], m[8], m[13], m[18], | 440 m[3], m[8], m[13], m[18], |
441 }; | 441 }; |
442 static const float kScale = 1.0f / 255.0f; | 442 static const float kScale = 1.0f / 255.0f; |
443 GrGLfloat vec[] = { | 443 GrGLfloat vec[] = { |
444 m[4] * kScale, m[9] * kScale, m[14] * kScale, m[19] * kScale, | 444 m[4] * kScale, m[9] * kScale, m[14] * kScale, m[19] * kScale, |
445 }; | 445 }; |
446 uniManager.setMatrix4fv(fMatrixHandle, 1, mt); | 446 uniManager.setMatrix4fv(fMatrixHandle, 1, mt); |
447 uniManager.set4fv(fVectorHandle, 1, vec); | 447 uniManager.set4fv(fVectorHandle, 1, vec); |
448 } | 448 } |
449 | 449 |
450 private: | 450 private: |
451 GrGLUniformManager::UniformHandle fMatrixHandle; | 451 GrGLProgramDataManager::UniformHandle fMatrixHandle; |
452 GrGLUniformManager::UniformHandle fVectorHandle; | 452 GrGLProgramDataManager::UniformHandle fVectorHandle; |
453 | 453 |
454 typedef GrGLEffect INHERITED; | 454 typedef GrGLEffect INHERITED; |
455 }; | 455 }; |
456 | 456 |
457 private: | 457 private: |
458 ColorMatrixEffect(const SkColorMatrix& matrix) : fMatrix(matrix) {} | 458 ColorMatrixEffect(const SkColorMatrix& matrix) : fMatrix(matrix) {} |
459 | 459 |
460 virtual bool onIsEqual(const GrEffect& s) const { | 460 virtual bool onIsEqual(const GrEffect& s) const { |
461 const ColorMatrixEffect& cme = CastEffect<ColorMatrixEffect>(s); | 461 const ColorMatrixEffect& cme = CastEffect<ColorMatrixEffect>(s); |
462 return cme.fMatrix == fMatrix; | 462 return cme.fMatrix == fMatrix; |
(...skipping 30 matching lines...) Expand all Loading... |
493 str->append("matrix: ("); | 493 str->append("matrix: ("); |
494 for (int i = 0; i < 20; ++i) { | 494 for (int i = 0; i < 20; ++i) { |
495 str->appendScalar(fMatrix.fMat[i]); | 495 str->appendScalar(fMatrix.fMat[i]); |
496 if (i < 19) { | 496 if (i < 19) { |
497 str->append(", "); | 497 str->append(", "); |
498 } | 498 } |
499 } | 499 } |
500 str->append(")"); | 500 str->append(")"); |
501 } | 501 } |
502 #endif | 502 #endif |
OLD | NEW |