| 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 368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 379 SkColorMatrix::SetConcat(concat, fMatrix.fMat, innerMatrix); | 379 SkColorMatrix::SetConcat(concat, fMatrix.fMat, innerMatrix); |
| 380 return SkColorMatrixFilter::Create(concat); | 380 return SkColorMatrixFilter::Create(concat); |
| 381 } | 381 } |
| 382 return nullptr; | 382 return nullptr; |
| 383 } | 383 } |
| 384 | 384 |
| 385 #if SK_SUPPORT_GPU | 385 #if SK_SUPPORT_GPU |
| 386 #include "GrFragmentProcessor.h" | 386 #include "GrFragmentProcessor.h" |
| 387 #include "GrInvariantOutput.h" | 387 #include "GrInvariantOutput.h" |
| 388 #include "gl/GrGLFragmentProcessor.h" | 388 #include "gl/GrGLFragmentProcessor.h" |
| 389 #include "gl/builders/GrGLProgramBuilder.h" | 389 #include "glsl/GrGLSLFragmentShaderBuilder.h" |
| 390 #include "glsl/GrGLSLProgramBuilder.h" |
| 390 #include "glsl/GrGLSLProgramDataManager.h" | 391 #include "glsl/GrGLSLProgramDataManager.h" |
| 391 | 392 |
| 392 class ColorMatrixEffect : public GrFragmentProcessor { | 393 class ColorMatrixEffect : public GrFragmentProcessor { |
| 393 public: | 394 public: |
| 394 static const GrFragmentProcessor* Create(const SkColorMatrix& matrix) { | 395 static const GrFragmentProcessor* Create(const SkColorMatrix& matrix) { |
| 395 return new ColorMatrixEffect(matrix); | 396 return new ColorMatrixEffect(matrix); |
| 396 } | 397 } |
| 397 | 398 |
| 398 const char* name() const override { return "Color Matrix"; } | 399 const char* name() const override { return "Color Matrix"; } |
| 399 | 400 |
| 400 GR_DECLARE_FRAGMENT_PROCESSOR_TEST; | 401 GR_DECLARE_FRAGMENT_PROCESSOR_TEST; |
| 401 | 402 |
| 402 class GLProcessor : public GrGLFragmentProcessor { | 403 class GLProcessor : public GrGLFragmentProcessor { |
| 403 public: | 404 public: |
| 404 // this class always generates the same code. | 405 // this class always generates the same code. |
| 405 static void GenKey(const GrProcessor&, const GrGLSLCaps&, GrProcessorKey
Builder* b) {} | 406 static void GenKey(const GrProcessor&, const GrGLSLCaps&, GrProcessorKey
Builder* b) {} |
| 406 | 407 |
| 407 GLProcessor(const GrProcessor&) {} | 408 GLProcessor(const GrProcessor&) {} |
| 408 | 409 |
| 409 virtual void emitCode(EmitArgs& args) override { | 410 virtual void emitCode(EmitArgs& args) override { |
| 410 fMatrixHandle = args.fBuilder->addUniform(GrGLProgramBuilder::kFragm
ent_Visibility, | 411 fMatrixHandle = args.fBuilder->addUniform(GrGLSLProgramBuilder::kFra
gment_Visibility, |
| 411 kMat44f_GrSLType, kDefault_GrSLP
recision, | 412 kMat44f_GrSLType, kDefault_GrSLP
recision, |
| 412 "ColorMatrix"); | 413 "ColorMatrix"); |
| 413 fVectorHandle = args.fBuilder->addUniform(GrGLProgramBuilder::kFragm
ent_Visibility, | 414 fVectorHandle = args.fBuilder->addUniform(GrGLSLProgramBuilder::kFra
gment_Visibility, |
| 414 kVec4f_GrSLType, kDefault_GrSLPr
ecision, | 415 kVec4f_GrSLType, kDefault_GrSLPr
ecision, |
| 415 "ColorMatrixVector"); | 416 "ColorMatrixVector"); |
| 416 | 417 |
| 417 if (nullptr == args.fInputColor) { | 418 if (nullptr == args.fInputColor) { |
| 418 // could optimize this case, but we aren't for now. | 419 // could optimize this case, but we aren't for now. |
| 419 args.fInputColor = "vec4(1)"; | 420 args.fInputColor = "vec4(1)"; |
| 420 } | 421 } |
| 421 GrGLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBui
lder(); | 422 GrGLSLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderB
uilder(); |
| 422 // The max() is to guard against 0 / 0 during unpremul when the inco
ming color is | 423 // The max() is to guard against 0 / 0 during unpremul when the inco
ming color is |
| 423 // transparent black. | 424 // transparent black. |
| 424 fsBuilder->codeAppendf("\tfloat nonZeroAlpha = max(%s.a, 0.00001);\n
", | 425 fsBuilder->codeAppendf("\tfloat nonZeroAlpha = max(%s.a, 0.00001);\n
", |
| 425 args.fInputColor); | 426 args.fInputColor); |
| 426 fsBuilder->codeAppendf("\t%s = %s * vec4(%s.rgb / nonZeroAlpha, nonZ
eroAlpha) + %s;\n", | 427 fsBuilder->codeAppendf("\t%s = %s * vec4(%s.rgb / nonZeroAlpha, nonZ
eroAlpha) + %s;\n", |
| 427 args.fOutputColor, | 428 args.fOutputColor, |
| 428 args.fBuilder->getUniformCStr(fMatrixHandle), | 429 args.fBuilder->getUniformCStr(fMatrixHandle), |
| 429 args.fInputColor, | 430 args.fInputColor, |
| 430 args.fBuilder->getUniformCStr(fVectorHandle))
; | 431 args.fBuilder->getUniformCStr(fVectorHandle))
; |
| 431 fsBuilder->codeAppendf("\t%s = clamp(%s, 0.0, 1.0);\n", | 432 fsBuilder->codeAppendf("\t%s = clamp(%s, 0.0, 1.0);\n", |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 550 str->append("matrix: ("); | 551 str->append("matrix: ("); |
| 551 for (int i = 0; i < 20; ++i) { | 552 for (int i = 0; i < 20; ++i) { |
| 552 str->appendScalar(fMatrix.fMat[i]); | 553 str->appendScalar(fMatrix.fMat[i]); |
| 553 if (i < 19) { | 554 if (i < 19) { |
| 554 str->append(", "); | 555 str->append(", "); |
| 555 } | 556 } |
| 556 } | 557 } |
| 557 str->append(")"); | 558 str->append(")"); |
| 558 } | 559 } |
| 559 #endif | 560 #endif |
| OLD | NEW |