| 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 376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 387 #include "gl/builders/GrGLProgramBuilder.h" | 387 #include "gl/builders/GrGLProgramBuilder.h" |
| 388 | 388 |
| 389 class ColorMatrixEffect : public GrFragmentProcessor { | 389 class ColorMatrixEffect : public GrFragmentProcessor { |
| 390 public: | 390 public: |
| 391 static GrFragmentProcessor* Create(const SkColorMatrix& matrix) { | 391 static GrFragmentProcessor* Create(const SkColorMatrix& matrix) { |
| 392 return SkNEW_ARGS(ColorMatrixEffect, (matrix)); | 392 return SkNEW_ARGS(ColorMatrixEffect, (matrix)); |
| 393 } | 393 } |
| 394 | 394 |
| 395 const char* name() const override { return "Color Matrix"; } | 395 const char* name() const override { return "Color Matrix"; } |
| 396 | 396 |
| 397 GrGLFragmentProcessor* createGLInstance() const override { | |
| 398 return SkNEW_ARGS(GLProcessor, (*this)); | |
| 399 } | |
| 400 | |
| 401 | |
| 402 GR_DECLARE_FRAGMENT_PROCESSOR_TEST; | 397 GR_DECLARE_FRAGMENT_PROCESSOR_TEST; |
| 403 | 398 |
| 404 class GLProcessor : public GrGLFragmentProcessor { | 399 class GLProcessor : public GrGLFragmentProcessor { |
| 405 public: | 400 public: |
| 406 // this class always generates the same code. | 401 // this class always generates the same code. |
| 407 static void GenKey(const GrProcessor&, const GrGLSLCaps&, GrProcessorKey
Builder* b) {} | 402 static void GenKey(const GrProcessor&, const GrGLSLCaps&, GrProcessorKey
Builder* b) {} |
| 408 | 403 |
| 409 GLProcessor(const GrProcessor&) {} | 404 GLProcessor(const GrProcessor&) {} |
| 410 | 405 |
| 411 virtual void emitCode(EmitArgs& args) override { | 406 virtual void emitCode(EmitArgs& args) override { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 428 fsBuilder->codeAppendf("\t%s = %s * vec4(%s.rgb / nonZeroAlpha, nonZ
eroAlpha) + %s;\n", | 423 fsBuilder->codeAppendf("\t%s = %s * vec4(%s.rgb / nonZeroAlpha, nonZ
eroAlpha) + %s;\n", |
| 429 args.fOutputColor, | 424 args.fOutputColor, |
| 430 args.fBuilder->getUniformCStr(fMatrixHandle), | 425 args.fBuilder->getUniformCStr(fMatrixHandle), |
| 431 args.fInputColor, | 426 args.fInputColor, |
| 432 args.fBuilder->getUniformCStr(fVectorHandle))
; | 427 args.fBuilder->getUniformCStr(fVectorHandle))
; |
| 433 fsBuilder->codeAppendf("\t%s = clamp(%s, 0.0, 1.0);\n", | 428 fsBuilder->codeAppendf("\t%s = clamp(%s, 0.0, 1.0);\n", |
| 434 args.fOutputColor, args.fOutputColor); | 429 args.fOutputColor, args.fOutputColor); |
| 435 fsBuilder->codeAppendf("\t%s.rgb *= %s.a;\n", args.fOutputColor, arg
s.fOutputColor); | 430 fsBuilder->codeAppendf("\t%s.rgb *= %s.a;\n", args.fOutputColor, arg
s.fOutputColor); |
| 436 } | 431 } |
| 437 | 432 |
| 438 virtual void setData(const GrGLProgramDataManager& uniManager, | 433 protected: |
| 434 virtual void onSetData(const GrGLProgramDataManager& uniManager, |
| 439 const GrProcessor& proc) override { | 435 const GrProcessor& proc) override { |
| 440 const ColorMatrixEffect& cme = proc.cast<ColorMatrixEffect>(); | 436 const ColorMatrixEffect& cme = proc.cast<ColorMatrixEffect>(); |
| 441 const float* m = cme.fMatrix.fMat; | 437 const float* m = cme.fMatrix.fMat; |
| 442 // The GL matrix is transposed from SkColorMatrix. | 438 // The GL matrix is transposed from SkColorMatrix. |
| 443 GrGLfloat mt[] = { | 439 GrGLfloat mt[] = { |
| 444 m[0], m[5], m[10], m[15], | 440 m[0], m[5], m[10], m[15], |
| 445 m[1], m[6], m[11], m[16], | 441 m[1], m[6], m[11], m[16], |
| 446 m[2], m[7], m[12], m[17], | 442 m[2], m[7], m[12], m[17], |
| 447 m[3], m[8], m[13], m[18], | 443 m[3], m[8], m[13], m[18], |
| 448 }; | 444 }; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 459 GrGLProgramDataManager::UniformHandle fVectorHandle; | 455 GrGLProgramDataManager::UniformHandle fVectorHandle; |
| 460 | 456 |
| 461 typedef GrGLFragmentProcessor INHERITED; | 457 typedef GrGLFragmentProcessor INHERITED; |
| 462 }; | 458 }; |
| 463 | 459 |
| 464 private: | 460 private: |
| 465 ColorMatrixEffect(const SkColorMatrix& matrix) : fMatrix(matrix) { | 461 ColorMatrixEffect(const SkColorMatrix& matrix) : fMatrix(matrix) { |
| 466 this->initClassID<ColorMatrixEffect>(); | 462 this->initClassID<ColorMatrixEffect>(); |
| 467 } | 463 } |
| 468 | 464 |
| 465 GrGLFragmentProcessor* onCreateGLInstance() const override { |
| 466 return SkNEW_ARGS(GLProcessor, (*this)); |
| 467 } |
| 468 |
| 469 virtual void onGetGLProcessorKey(const GrGLSLCaps& caps, | 469 virtual void onGetGLProcessorKey(const GrGLSLCaps& caps, |
| 470 GrProcessorKeyBuilder* b) const override { | 470 GrProcessorKeyBuilder* b) const override { |
| 471 GLProcessor::GenKey(*this, caps, b); | 471 GLProcessor::GenKey(*this, caps, b); |
| 472 } | 472 } |
| 473 | 473 |
| 474 bool onIsEqual(const GrFragmentProcessor& s) const override { | 474 bool onIsEqual(const GrFragmentProcessor& s) const override { |
| 475 const ColorMatrixEffect& cme = s.cast<ColorMatrixEffect>(); | 475 const ColorMatrixEffect& cme = s.cast<ColorMatrixEffect>(); |
| 476 return cme.fMatrix == fMatrix; | 476 return cme.fMatrix == fMatrix; |
| 477 } | 477 } |
| 478 | 478 |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 560 str->append("matrix: ("); | 560 str->append("matrix: ("); |
| 561 for (int i = 0; i < 20; ++i) { | 561 for (int i = 0; i < 20; ++i) { |
| 562 str->appendScalar(fMatrix.fMat[i]); | 562 str->appendScalar(fMatrix.fMat[i]); |
| 563 if (i < 19) { | 563 if (i < 19) { |
| 564 str->append(", "); | 564 str->append(", "); |
| 565 } | 565 } |
| 566 } | 566 } |
| 567 str->append(")"); | 567 str->append(")"); |
| 568 } | 568 } |
| 569 #endif | 569 #endif |
| OLD | NEW |