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 381 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
392 // underflow this may deviate from the actual result. Maybe the effect s
hould pin its | 392 // underflow this may deviate from the actual result. Maybe the effect s
hould pin its |
393 // result if the matrix could over/underflow for any component? | 393 // result if the matrix could over/underflow for any component? |
394 *color = static_cast<uint8_t>(SkScalarPin(outputA, 0, 255)) << GrColor_S
HIFT_A; | 394 *color = static_cast<uint8_t>(SkScalarPin(outputA, 0, 255)) << GrColor_S
HIFT_A; |
395 } | 395 } |
396 | 396 |
397 GR_DECLARE_EFFECT_TEST; | 397 GR_DECLARE_EFFECT_TEST; |
398 | 398 |
399 class GLEffect : public GrGLEffect { | 399 class GLEffect : public GrGLEffect { |
400 public: | 400 public: |
401 // this class always generates the same code. | 401 // this class always generates the same code. |
402 static void GenKey(const GrEffect&, const GrGLCaps&, GrEffectKeyBuilder*
b) {} | 402 static void GenKey(const GrDrawEffect&, const GrGLCaps&, GrEffectKeyBuil
der* b) {} |
403 | 403 |
404 GLEffect(const GrBackendEffectFactory& factory, | 404 GLEffect(const GrBackendEffectFactory& factory, |
405 const GrEffect&) | 405 const GrDrawEffect&) |
406 : INHERITED(factory) { | 406 : INHERITED(factory) { |
407 } | 407 } |
408 | 408 |
409 virtual void emitCode(GrGLProgramBuilder* builder, | 409 virtual void emitCode(GrGLProgramBuilder* builder, |
410 const GrEffect&, | 410 const GrDrawEffect&, |
411 const GrEffectKey&, | 411 const GrEffectKey&, |
412 const char* outputColor, | 412 const char* outputColor, |
413 const char* inputColor, | 413 const char* inputColor, |
414 const TransformedCoordsArray&, | 414 const TransformedCoordsArray&, |
415 const TextureSamplerArray&) SK_OVERRIDE { | 415 const TextureSamplerArray&) SK_OVERRIDE { |
416 fMatrixHandle = builder->addUniform(GrGLProgramBuilder::kFragment_Vi
sibility, | 416 fMatrixHandle = builder->addUniform(GrGLProgramBuilder::kFragment_Vi
sibility, |
417 kMat44f_GrSLType, | 417 kMat44f_GrSLType, |
418 "ColorMatrix"); | 418 "ColorMatrix"); |
419 fVectorHandle = builder->addUniform(GrGLProgramBuilder::kFragment_Vi
sibility, | 419 fVectorHandle = builder->addUniform(GrGLProgramBuilder::kFragment_Vi
sibility, |
420 kVec4f_GrSLType, | 420 kVec4f_GrSLType, |
(...skipping 10 matching lines...) Expand all Loading... |
431 fsBuilder->codeAppendf("\t%s = %s * vec4(%s.rgb / nonZeroAlpha, nonZ
eroAlpha) + %s;\n", | 431 fsBuilder->codeAppendf("\t%s = %s * vec4(%s.rgb / nonZeroAlpha, nonZ
eroAlpha) + %s;\n", |
432 outputColor, | 432 outputColor, |
433 builder->getUniformCStr(fMatrixHandle), | 433 builder->getUniformCStr(fMatrixHandle), |
434 inputColor, | 434 inputColor, |
435 builder->getUniformCStr(fVectorHandle)); | 435 builder->getUniformCStr(fVectorHandle)); |
436 fsBuilder->codeAppendf("\t%s = clamp(%s, 0.0, 1.0);\n", outputColor,
outputColor); | 436 fsBuilder->codeAppendf("\t%s = clamp(%s, 0.0, 1.0);\n", outputColor,
outputColor); |
437 fsBuilder->codeAppendf("\t%s.rgb *= %s.a;\n", outputColor, outputCol
or); | 437 fsBuilder->codeAppendf("\t%s.rgb *= %s.a;\n", outputColor, outputCol
or); |
438 } | 438 } |
439 | 439 |
440 virtual void setData(const GrGLProgramDataManager& uniManager, | 440 virtual void setData(const GrGLProgramDataManager& uniManager, |
441 const GrEffect& effect) SK_OVERRIDE { | 441 const GrDrawEffect& drawEffect) SK_OVERRIDE { |
442 const ColorMatrixEffect& cme = effect.cast<ColorMatrixEffect>(); | 442 const ColorMatrixEffect& cme = drawEffect.castEffect<ColorMatrixEffe
ct>(); |
443 const float* m = cme.fMatrix.fMat; | 443 const float* m = cme.fMatrix.fMat; |
444 // The GL matrix is transposed from SkColorMatrix. | 444 // The GL matrix is transposed from SkColorMatrix. |
445 GrGLfloat mt[] = { | 445 GrGLfloat mt[] = { |
446 m[0], m[5], m[10], m[15], | 446 m[0], m[5], m[10], m[15], |
447 m[1], m[6], m[11], m[16], | 447 m[1], m[6], m[11], m[16], |
448 m[2], m[7], m[12], m[17], | 448 m[2], m[7], m[12], m[17], |
449 m[3], m[8], m[13], m[18], | 449 m[3], m[8], m[13], m[18], |
450 }; | 450 }; |
451 static const float kScale = 1.0f / 255.0f; | 451 static const float kScale = 1.0f / 255.0f; |
452 GrGLfloat vec[] = { | 452 GrGLfloat vec[] = { |
453 m[4] * kScale, m[9] * kScale, m[14] * kScale, m[19] * kScale, | 453 m[4] * kScale, m[9] * kScale, m[14] * kScale, m[19] * kScale, |
454 }; | 454 }; |
455 uniManager.setMatrix4fv(fMatrixHandle, 1, mt); | 455 uniManager.setMatrix4fv(fMatrixHandle, 1, mt); |
456 uniManager.set4fv(fVectorHandle, 1, vec); | 456 uniManager.set4fv(fVectorHandle, 1, vec); |
457 } | 457 } |
458 | 458 |
459 private: | 459 private: |
460 GrGLProgramDataManager::UniformHandle fMatrixHandle; | 460 GrGLProgramDataManager::UniformHandle fMatrixHandle; |
461 GrGLProgramDataManager::UniformHandle fVectorHandle; | 461 GrGLProgramDataManager::UniformHandle fVectorHandle; |
462 | 462 |
463 typedef GrGLEffect INHERITED; | 463 typedef GrGLEffect INHERITED; |
464 }; | 464 }; |
465 | 465 |
466 private: | 466 private: |
467 ColorMatrixEffect(const SkColorMatrix& matrix) : fMatrix(matrix) {} | 467 ColorMatrixEffect(const SkColorMatrix& matrix) : fMatrix(matrix) {} |
468 | 468 |
469 virtual bool onIsEqual(const GrEffect& s) const { | 469 virtual bool onIsEqual(const GrEffect& s) const { |
470 const ColorMatrixEffect& cme = s.cast<ColorMatrixEffect>(); | 470 const ColorMatrixEffect& cme = CastEffect<ColorMatrixEffect>(s); |
471 return cme.fMatrix == fMatrix; | 471 return cme.fMatrix == fMatrix; |
472 } | 472 } |
473 | 473 |
474 SkColorMatrix fMatrix; | 474 SkColorMatrix fMatrix; |
475 | 475 |
476 typedef GrEffect INHERITED; | 476 typedef GrEffect INHERITED; |
477 }; | 477 }; |
478 | 478 |
479 GR_DEFINE_EFFECT_TEST(ColorMatrixEffect); | 479 GR_DEFINE_EFFECT_TEST(ColorMatrixEffect); |
480 | 480 |
(...skipping 21 matching lines...) Expand all Loading... |
502 str->append("matrix: ("); | 502 str->append("matrix: ("); |
503 for (int i = 0; i < 20; ++i) { | 503 for (int i = 0; i < 20; ++i) { |
504 str->appendScalar(fMatrix.fMat[i]); | 504 str->appendScalar(fMatrix.fMat[i]); |
505 if (i < 19) { | 505 if (i < 19) { |
506 str->append(", "); | 506 str->append(", "); |
507 } | 507 } |
508 } | 508 } |
509 str->append(")"); | 509 str->append(")"); |
510 } | 510 } |
511 #endif | 511 #endif |
OLD | NEW |