OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 Google Inc. |
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 "SkColorMatrixFilter.h" | 8 #include "SkColorMatrixFilter.h" |
9 #include "SkColorMatrix.h" | 9 #include "SkColorMatrix.h" |
10 #include "SkColorPriv.h" | 10 #include "SkColorPriv.h" |
(...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
406 | 406 |
407 GR_DECLARE_FRAGMENT_PROCESSOR_TEST; | 407 GR_DECLARE_FRAGMENT_PROCESSOR_TEST; |
408 | 408 |
409 class GLProcessor : public GrGLFragmentProcessor { | 409 class GLProcessor : public GrGLFragmentProcessor { |
410 public: | 410 public: |
411 // this class always generates the same code. | 411 // this class always generates the same code. |
412 static void GenKey(const GrProcessor&, const GrGLSLCaps&, GrProcessorKey
Builder* b) {} | 412 static void GenKey(const GrProcessor&, const GrGLSLCaps&, GrProcessorKey
Builder* b) {} |
413 | 413 |
414 GLProcessor(const GrProcessor&) {} | 414 GLProcessor(const GrProcessor&) {} |
415 | 415 |
416 virtual void emitCode(GrGLFPBuilder* builder, | 416 virtual void emitCode(EmitArgs& args) override { |
417 const GrFragmentProcessor&, | 417 fMatrixHandle = args.fBuilder->addUniform(GrGLProgramBuilder::kFragm
ent_Visibility, |
418 const char* outputColor, | |
419 const char* inputColor, | |
420 const TransformedCoordsArray&, | |
421 const TextureSamplerArray&) override { | |
422 fMatrixHandle = builder->addUniform(GrGLProgramBuilder::kFragment_Vi
sibility, | |
423 kMat44f_GrSLType, kDefault_GrSLP
recision, | 418 kMat44f_GrSLType, kDefault_GrSLP
recision, |
424 "ColorMatrix"); | 419 "ColorMatrix"); |
425 fVectorHandle = builder->addUniform(GrGLProgramBuilder::kFragment_Vi
sibility, | 420 fVectorHandle = args.fBuilder->addUniform(GrGLProgramBuilder::kFragm
ent_Visibility, |
426 kVec4f_GrSLType, kDefault_GrSLPr
ecision, | 421 kVec4f_GrSLType, kDefault_GrSLPr
ecision, |
427 "ColorMatrixVector"); | 422 "ColorMatrixVector"); |
428 | 423 |
429 if (NULL == inputColor) { | 424 if (NULL == args.fInputColor) { |
430 // could optimize this case, but we aren't for now. | 425 // could optimize this case, but we aren't for now. |
431 inputColor = "vec4(1)"; | 426 args.fInputColor = "vec4(1)"; |
432 } | 427 } |
433 GrGLFragmentBuilder* fsBuilder = builder->getFragmentShaderBuilder()
; | 428 GrGLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBui
lder(); |
434 // The max() is to guard against 0 / 0 during unpremul when the inco
ming color is | 429 // The max() is to guard against 0 / 0 during unpremul when the inco
ming color is |
435 // transparent black. | 430 // transparent black. |
436 fsBuilder->codeAppendf("\tfloat nonZeroAlpha = max(%s.a, 0.00001);\n
", inputColor); | 431 fsBuilder->codeAppendf("\tfloat nonZeroAlpha = max(%s.a, 0.00001);\n
", |
| 432 args.fInputColor); |
437 fsBuilder->codeAppendf("\t%s = %s * vec4(%s.rgb / nonZeroAlpha, nonZ
eroAlpha) + %s;\n", | 433 fsBuilder->codeAppendf("\t%s = %s * vec4(%s.rgb / nonZeroAlpha, nonZ
eroAlpha) + %s;\n", |
438 outputColor, | 434 args.fOutputColor, |
439 builder->getUniformCStr(fMatrixHandle), | 435 args.fBuilder->getUniformCStr(fMatrixHandle), |
440 inputColor, | 436 args.fInputColor, |
441 builder->getUniformCStr(fVectorHandle)); | 437 args.fBuilder->getUniformCStr(fVectorHandle))
; |
442 fsBuilder->codeAppendf("\t%s = clamp(%s, 0.0, 1.0);\n", outputColor,
outputColor); | 438 fsBuilder->codeAppendf("\t%s = clamp(%s, 0.0, 1.0);\n", |
443 fsBuilder->codeAppendf("\t%s.rgb *= %s.a;\n", outputColor, outputCol
or); | 439 args.fOutputColor, args.fOutputColor); |
| 440 fsBuilder->codeAppendf("\t%s.rgb *= %s.a;\n", args.fOutputColor, arg
s.fOutputColor); |
444 } | 441 } |
445 | 442 |
446 virtual void setData(const GrGLProgramDataManager& uniManager, | 443 virtual void setData(const GrGLProgramDataManager& uniManager, |
447 const GrProcessor& proc) override { | 444 const GrProcessor& proc) override { |
448 const ColorMatrixEffect& cme = proc.cast<ColorMatrixEffect>(); | 445 const ColorMatrixEffect& cme = proc.cast<ColorMatrixEffect>(); |
449 const float* m = cme.fMatrix.fMat; | 446 const float* m = cme.fMatrix.fMat; |
450 // The GL matrix is transposed from SkColorMatrix. | 447 // The GL matrix is transposed from SkColorMatrix. |
451 GrGLfloat mt[] = { | 448 GrGLfloat mt[] = { |
452 m[0], m[5], m[10], m[15], | 449 m[0], m[5], m[10], m[15], |
453 m[1], m[6], m[11], m[16], | 450 m[1], m[6], m[11], m[16], |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
563 str->append("matrix: ("); | 560 str->append("matrix: ("); |
564 for (int i = 0; i < 20; ++i) { | 561 for (int i = 0; i < 20; ++i) { |
565 str->appendScalar(fMatrix.fMat[i]); | 562 str->appendScalar(fMatrix.fMat[i]); |
566 if (i < 19) { | 563 if (i < 19) { |
567 str->append(", "); | 564 str->append(", "); |
568 } | 565 } |
569 } | 566 } |
570 str->append(")"); | 567 str->append(")"); |
571 } | 568 } |
572 #endif | 569 #endif |
OLD | NEW |