| 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 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 378 SkScalar concat[20]; | 378 SkScalar concat[20]; |
| 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 "glsl/GrGLSLFragmentProcessor.h" |
| 389 #include "glsl/GrGLSLFragmentShaderBuilder.h" | 389 #include "glsl/GrGLSLFragmentShaderBuilder.h" |
| 390 #include "glsl/GrGLSLProgramBuilder.h" | 390 #include "glsl/GrGLSLProgramBuilder.h" |
| 391 #include "glsl/GrGLSLProgramDataManager.h" | 391 #include "glsl/GrGLSLProgramDataManager.h" |
| 392 | 392 |
| 393 class ColorMatrixEffect : public GrFragmentProcessor { | 393 class ColorMatrixEffect : public GrFragmentProcessor { |
| 394 public: | 394 public: |
| 395 static const GrFragmentProcessor* Create(const SkColorMatrix& matrix) { | 395 static const GrFragmentProcessor* Create(const SkColorMatrix& matrix) { |
| 396 return new ColorMatrixEffect(matrix); | 396 return new ColorMatrixEffect(matrix); |
| 397 } | 397 } |
| 398 | 398 |
| 399 const char* name() const override { return "Color Matrix"; } | 399 const char* name() const override { return "Color Matrix"; } |
| 400 | 400 |
| 401 GR_DECLARE_FRAGMENT_PROCESSOR_TEST; | 401 GR_DECLARE_FRAGMENT_PROCESSOR_TEST; |
| 402 | 402 |
| 403 class GLProcessor : public GrGLFragmentProcessor { | 403 class GLProcessor : public GrGLSLFragmentProcessor { |
| 404 public: | 404 public: |
| 405 // this class always generates the same code. | 405 // this class always generates the same code. |
| 406 static void GenKey(const GrProcessor&, const GrGLSLCaps&, GrProcessorKey
Builder* b) {} | 406 static void GenKey(const GrProcessor&, const GrGLSLCaps&, GrProcessorKey
Builder* b) {} |
| 407 | 407 |
| 408 GLProcessor(const GrProcessor&) {} | 408 GLProcessor(const GrProcessor&) {} |
| 409 | 409 |
| 410 virtual void emitCode(EmitArgs& args) override { | 410 virtual void emitCode(EmitArgs& args) override { |
| 411 fMatrixHandle = args.fBuilder->addUniform(GrGLSLProgramBuilder::kFra
gment_Visibility, | 411 fMatrixHandle = args.fBuilder->addUniform(GrGLSLProgramBuilder::kFra
gment_Visibility, |
| 412 kMat44f_GrSLType, kDefault_GrSLP
recision, | 412 kMat44f_GrSLType, kDefault_GrSLP
recision, |
| 413 "ColorMatrix"); | 413 "ColorMatrix"); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 451 m[4] * kScale, m[9] * kScale, m[14] * kScale, m[19] * kScale, | 451 m[4] * kScale, m[9] * kScale, m[14] * kScale, m[19] * kScale, |
| 452 }; | 452 }; |
| 453 uniManager.setMatrix4fv(fMatrixHandle, 1, mt); | 453 uniManager.setMatrix4fv(fMatrixHandle, 1, mt); |
| 454 uniManager.set4fv(fVectorHandle, 1, vec); | 454 uniManager.set4fv(fVectorHandle, 1, vec); |
| 455 } | 455 } |
| 456 | 456 |
| 457 private: | 457 private: |
| 458 GrGLSLProgramDataManager::UniformHandle fMatrixHandle; | 458 GrGLSLProgramDataManager::UniformHandle fMatrixHandle; |
| 459 GrGLSLProgramDataManager::UniformHandle fVectorHandle; | 459 GrGLSLProgramDataManager::UniformHandle fVectorHandle; |
| 460 | 460 |
| 461 typedef GrGLFragmentProcessor INHERITED; | 461 typedef GrGLSLFragmentProcessor INHERITED; |
| 462 }; | 462 }; |
| 463 | 463 |
| 464 private: | 464 private: |
| 465 ColorMatrixEffect(const SkColorMatrix& matrix) : fMatrix(matrix) { | 465 ColorMatrixEffect(const SkColorMatrix& matrix) : fMatrix(matrix) { |
| 466 this->initClassID<ColorMatrixEffect>(); | 466 this->initClassID<ColorMatrixEffect>(); |
| 467 } | 467 } |
| 468 | 468 |
| 469 GrGLFragmentProcessor* onCreateGLInstance() const override { return new GLPr
ocessor(*this); } | 469 GrGLSLFragmentProcessor* onCreateGLInstance() const override { return new GL
Processor(*this); } |
| 470 | 470 |
| 471 virtual void onGetGLProcessorKey(const GrGLSLCaps& caps, | 471 virtual void onGetGLProcessorKey(const GrGLSLCaps& caps, |
| 472 GrProcessorKeyBuilder* b) const override { | 472 GrProcessorKeyBuilder* b) const override { |
| 473 GLProcessor::GenKey(*this, caps, b); | 473 GLProcessor::GenKey(*this, caps, b); |
| 474 } | 474 } |
| 475 | 475 |
| 476 bool onIsEqual(const GrFragmentProcessor& s) const override { | 476 bool onIsEqual(const GrFragmentProcessor& s) const override { |
| 477 const ColorMatrixEffect& cme = s.cast<ColorMatrixEffect>(); | 477 const ColorMatrixEffect& cme = s.cast<ColorMatrixEffect>(); |
| 478 return cme.fMatrix == fMatrix; | 478 return cme.fMatrix == fMatrix; |
| 479 } | 479 } |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 551 str->append("matrix: ("); | 551 str->append("matrix: ("); |
| 552 for (int i = 0; i < 20; ++i) { | 552 for (int i = 0; i < 20; ++i) { |
| 553 str->appendScalar(fMatrix.fMat[i]); | 553 str->appendScalar(fMatrix.fMat[i]); |
| 554 if (i < 19) { | 554 if (i < 19) { |
| 555 str->append(", "); | 555 str->append(", "); |
| 556 } | 556 } |
| 557 } | 557 } |
| 558 str->append(")"); | 558 str->append(")"); |
| 559 } | 559 } |
| 560 #endif | 560 #endif |
| OLD | NEW |