| 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 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 "gl/builders/GrGLProgramBuilder.h" |
| 390 #include "glsl/GrGLSLProgramDataManager.h" |
| 390 | 391 |
| 391 class ColorMatrixEffect : public GrFragmentProcessor { | 392 class ColorMatrixEffect : public GrFragmentProcessor { |
| 392 public: | 393 public: |
| 393 static const GrFragmentProcessor* Create(const SkColorMatrix& matrix) { | 394 static const GrFragmentProcessor* Create(const SkColorMatrix& matrix) { |
| 394 return new ColorMatrixEffect(matrix); | 395 return new ColorMatrixEffect(matrix); |
| 395 } | 396 } |
| 396 | 397 |
| 397 const char* name() const override { return "Color Matrix"; } | 398 const char* name() const override { return "Color Matrix"; } |
| 398 | 399 |
| 399 GR_DECLARE_FRAGMENT_PROCESSOR_TEST; | 400 GR_DECLARE_FRAGMENT_PROCESSOR_TEST; |
| (...skipping 26 matching lines...) Expand all Loading... |
| 426 args.fOutputColor, | 427 args.fOutputColor, |
| 427 args.fBuilder->getUniformCStr(fMatrixHandle), | 428 args.fBuilder->getUniformCStr(fMatrixHandle), |
| 428 args.fInputColor, | 429 args.fInputColor, |
| 429 args.fBuilder->getUniformCStr(fVectorHandle))
; | 430 args.fBuilder->getUniformCStr(fVectorHandle))
; |
| 430 fsBuilder->codeAppendf("\t%s = clamp(%s, 0.0, 1.0);\n", | 431 fsBuilder->codeAppendf("\t%s = clamp(%s, 0.0, 1.0);\n", |
| 431 args.fOutputColor, args.fOutputColor); | 432 args.fOutputColor, args.fOutputColor); |
| 432 fsBuilder->codeAppendf("\t%s.rgb *= %s.a;\n", args.fOutputColor, arg
s.fOutputColor); | 433 fsBuilder->codeAppendf("\t%s.rgb *= %s.a;\n", args.fOutputColor, arg
s.fOutputColor); |
| 433 } | 434 } |
| 434 | 435 |
| 435 protected: | 436 protected: |
| 436 virtual void onSetData(const GrGLProgramDataManager& uniManager, | 437 virtual void onSetData(const GrGLSLProgramDataManager& uniManager, |
| 437 const GrProcessor& proc) override { | 438 const GrProcessor& proc) override { |
| 438 const ColorMatrixEffect& cme = proc.cast<ColorMatrixEffect>(); | 439 const ColorMatrixEffect& cme = proc.cast<ColorMatrixEffect>(); |
| 439 const float* m = cme.fMatrix.fMat; | 440 const float* m = cme.fMatrix.fMat; |
| 440 // The GL matrix is transposed from SkColorMatrix. | 441 // The GL matrix is transposed from SkColorMatrix. |
| 441 GrGLfloat mt[] = { | 442 float mt[] = { |
| 442 m[0], m[5], m[10], m[15], | 443 m[0], m[5], m[10], m[15], |
| 443 m[1], m[6], m[11], m[16], | 444 m[1], m[6], m[11], m[16], |
| 444 m[2], m[7], m[12], m[17], | 445 m[2], m[7], m[12], m[17], |
| 445 m[3], m[8], m[13], m[18], | 446 m[3], m[8], m[13], m[18], |
| 446 }; | 447 }; |
| 447 static const float kScale = 1.0f / 255.0f; | 448 static const float kScale = 1.0f / 255.0f; |
| 448 GrGLfloat vec[] = { | 449 float vec[] = { |
| 449 m[4] * kScale, m[9] * kScale, m[14] * kScale, m[19] * kScale, | 450 m[4] * kScale, m[9] * kScale, m[14] * kScale, m[19] * kScale, |
| 450 }; | 451 }; |
| 451 uniManager.setMatrix4fv(fMatrixHandle, 1, mt); | 452 uniManager.setMatrix4fv(fMatrixHandle, 1, mt); |
| 452 uniManager.set4fv(fVectorHandle, 1, vec); | 453 uniManager.set4fv(fVectorHandle, 1, vec); |
| 453 } | 454 } |
| 454 | 455 |
| 455 private: | 456 private: |
| 456 GrGLProgramDataManager::UniformHandle fMatrixHandle; | 457 GrGLSLProgramDataManager::UniformHandle fMatrixHandle; |
| 457 GrGLProgramDataManager::UniformHandle fVectorHandle; | 458 GrGLSLProgramDataManager::UniformHandle fVectorHandle; |
| 458 | 459 |
| 459 typedef GrGLFragmentProcessor INHERITED; | 460 typedef GrGLFragmentProcessor INHERITED; |
| 460 }; | 461 }; |
| 461 | 462 |
| 462 private: | 463 private: |
| 463 ColorMatrixEffect(const SkColorMatrix& matrix) : fMatrix(matrix) { | 464 ColorMatrixEffect(const SkColorMatrix& matrix) : fMatrix(matrix) { |
| 464 this->initClassID<ColorMatrixEffect>(); | 465 this->initClassID<ColorMatrixEffect>(); |
| 465 } | 466 } |
| 466 | 467 |
| 467 GrGLFragmentProcessor* onCreateGLInstance() const override { return new GLPr
ocessor(*this); } | 468 GrGLFragmentProcessor* onCreateGLInstance() const override { return new GLPr
ocessor(*this); } |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 549 str->append("matrix: ("); | 550 str->append("matrix: ("); |
| 550 for (int i = 0; i < 20; ++i) { | 551 for (int i = 0; i < 20; ++i) { |
| 551 str->appendScalar(fMatrix.fMat[i]); | 552 str->appendScalar(fMatrix.fMat[i]); |
| 552 if (i < 19) { | 553 if (i < 19) { |
| 553 str->append(", "); | 554 str->append(", "); |
| 554 } | 555 } |
| 555 } | 556 } |
| 556 str->append(")"); | 557 str->append(")"); |
| 557 } | 558 } |
| 558 #endif | 559 #endif |
| OLD | NEW |