| 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 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 354 class GLProcessor : public GrGLFragmentProcessor { | 354 class GLProcessor : public GrGLFragmentProcessor { |
| 355 public: | 355 public: |
| 356 // this class always generates the same code. | 356 // this class always generates the same code. |
| 357 static void GenKey(const GrProcessor&, const GrGLCaps&, GrProcessorKeyBu
ilder* b) {} | 357 static void GenKey(const GrProcessor&, const GrGLCaps&, GrProcessorKeyBu
ilder* b) {} |
| 358 | 358 |
| 359 GLProcessor(const GrBackendProcessorFactory& factory, | 359 GLProcessor(const GrBackendProcessorFactory& factory, |
| 360 const GrProcessor&) | 360 const GrProcessor&) |
| 361 : INHERITED(factory) { | 361 : INHERITED(factory) { |
| 362 } | 362 } |
| 363 | 363 |
| 364 virtual void emitCode(GrGLProgramBuilder* builder, | 364 virtual void emitCode(GrGLFPBuilder* builder, |
| 365 const GrFragmentProcessor&, | 365 const GrFragmentProcessor&, |
| 366 const GrProcessorKey&, | 366 const GrProcessorKey&, |
| 367 const char* outputColor, | 367 const char* outputColor, |
| 368 const char* inputColor, | 368 const char* inputColor, |
| 369 const TransformedCoordsArray&, | 369 const TransformedCoordsArray&, |
| 370 const TextureSamplerArray&) SK_OVERRIDE { | 370 const TextureSamplerArray&) SK_OVERRIDE { |
| 371 fMatrixHandle = builder->addUniform(GrGLProgramBuilder::kFragment_Vi
sibility, | 371 fMatrixHandle = builder->addUniform(GrGLProgramBuilder::kFragment_Vi
sibility, |
| 372 kMat44f_GrSLType, | 372 kMat44f_GrSLType, |
| 373 "ColorMatrix"); | 373 "ColorMatrix"); |
| 374 fVectorHandle = builder->addUniform(GrGLProgramBuilder::kFragment_Vi
sibility, | 374 fVectorHandle = builder->addUniform(GrGLProgramBuilder::kFragment_Vi
sibility, |
| 375 kVec4f_GrSLType, | 375 kVec4f_GrSLType, |
| 376 "ColorMatrixVector"); | 376 "ColorMatrixVector"); |
| 377 | 377 |
| 378 if (NULL == inputColor) { | 378 if (NULL == inputColor) { |
| 379 // could optimize this case, but we aren't for now. | 379 // could optimize this case, but we aren't for now. |
| 380 inputColor = "vec4(1)"; | 380 inputColor = "vec4(1)"; |
| 381 } | 381 } |
| 382 GrGLFragmentShaderBuilder* fsBuilder = builder->getFragmentShaderBui
lder(); | 382 GrGLFPFragmentBuilder* fsBuilder = builder->getFragmentShaderBuilder
(); |
| 383 // The max() is to guard against 0 / 0 during unpremul when the inco
ming color is | 383 // The max() is to guard against 0 / 0 during unpremul when the inco
ming color is |
| 384 // transparent black. | 384 // transparent black. |
| 385 fsBuilder->codeAppendf("\tfloat nonZeroAlpha = max(%s.a, 0.00001);\n
", inputColor); | 385 fsBuilder->codeAppendf("\tfloat nonZeroAlpha = max(%s.a, 0.00001);\n
", inputColor); |
| 386 fsBuilder->codeAppendf("\t%s = %s * vec4(%s.rgb / nonZeroAlpha, nonZ
eroAlpha) + %s;\n", | 386 fsBuilder->codeAppendf("\t%s = %s * vec4(%s.rgb / nonZeroAlpha, nonZ
eroAlpha) + %s;\n", |
| 387 outputColor, | 387 outputColor, |
| 388 builder->getUniformCStr(fMatrixHandle), | 388 builder->getUniformCStr(fMatrixHandle), |
| 389 inputColor, | 389 inputColor, |
| 390 builder->getUniformCStr(fVectorHandle)); | 390 builder->getUniformCStr(fVectorHandle)); |
| 391 fsBuilder->codeAppendf("\t%s = clamp(%s, 0.0, 1.0);\n", outputColor,
outputColor); | 391 fsBuilder->codeAppendf("\t%s = clamp(%s, 0.0, 1.0);\n", outputColor,
outputColor); |
| 392 fsBuilder->codeAppendf("\t%s.rgb *= %s.a;\n", outputColor, outputCol
or); | 392 fsBuilder->codeAppendf("\t%s.rgb *= %s.a;\n", outputColor, outputCol
or); |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after 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 |