| OLD | NEW |
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2012 Google Inc. | 3 * Copyright 2012 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 | 8 |
| 9 #include "SkTwoPointRadialGradient.h" | 9 #include "SkTwoPointRadialGradient.h" |
| 10 | 10 |
| (...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 401 #include "gl/builders/GrGLProgramBuilder.h" | 401 #include "gl/builders/GrGLProgramBuilder.h" |
| 402 #include "SkGr.h" | 402 #include "SkGr.h" |
| 403 | 403 |
| 404 // For brevity | 404 // For brevity |
| 405 typedef GrGLProgramDataManager::UniformHandle UniformHandle; | 405 typedef GrGLProgramDataManager::UniformHandle UniformHandle; |
| 406 | 406 |
| 407 class GrGLRadial2Gradient : public GrGLGradientEffect { | 407 class GrGLRadial2Gradient : public GrGLGradientEffect { |
| 408 | 408 |
| 409 public: | 409 public: |
| 410 | 410 |
| 411 GrGLRadial2Gradient(const GrBackendEffectFactory& factory, const GrDrawEffec
t&); | 411 GrGLRadial2Gradient(const GrBackendEffectFactory& factory, const GrEffect&); |
| 412 virtual ~GrGLRadial2Gradient() { } | 412 virtual ~GrGLRadial2Gradient() { } |
| 413 | 413 |
| 414 virtual void emitCode(GrGLProgramBuilder*, | 414 virtual void emitCode(GrGLProgramBuilder*, |
| 415 const GrDrawEffect&, | 415 const GrEffect&, |
| 416 const GrEffectKey&, | 416 const GrEffectKey&, |
| 417 const char* outputColor, | 417 const char* outputColor, |
| 418 const char* inputColor, | 418 const char* inputColor, |
| 419 const TransformedCoordsArray&, | 419 const TransformedCoordsArray&, |
| 420 const TextureSamplerArray&) SK_OVERRIDE; | 420 const TextureSamplerArray&) SK_OVERRIDE; |
| 421 virtual void setData(const GrGLProgramDataManager&, const GrDrawEffect&) SK_
OVERRIDE; | 421 virtual void setData(const GrGLProgramDataManager&, const GrEffect&) SK_OVER
RIDE; |
| 422 | 422 |
| 423 static void GenKey(const GrDrawEffect&, const GrGLCaps& caps, GrEffectKeyBui
lder* b); | 423 static void GenKey(const GrEffect&, const GrGLCaps& caps, GrEffectKeyBuilder
* b); |
| 424 | 424 |
| 425 protected: | 425 protected: |
| 426 | 426 |
| 427 UniformHandle fParamUni; | 427 UniformHandle fParamUni; |
| 428 | 428 |
| 429 const char* fVSVaryingName; | 429 const char* fVSVaryingName; |
| 430 const char* fFSVaryingName; | 430 const char* fFSVaryingName; |
| 431 | 431 |
| 432 bool fIsDegenerate; | 432 bool fIsDegenerate; |
| 433 | 433 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 467 // The radial gradient parameters can collapse to a linear (instead of quadr
atic) equation. | 467 // The radial gradient parameters can collapse to a linear (instead of quadr
atic) equation. |
| 468 bool isDegenerate() const { return SK_Scalar1 == fCenterX1; } | 468 bool isDegenerate() const { return SK_Scalar1 == fCenterX1; } |
| 469 SkScalar center() const { return fCenterX1; } | 469 SkScalar center() const { return fCenterX1; } |
| 470 SkScalar radius() const { return fRadius0; } | 470 SkScalar radius() const { return fRadius0; } |
| 471 bool isPosRoot() const { return SkToBool(fPosRoot); } | 471 bool isPosRoot() const { return SkToBool(fPosRoot); } |
| 472 | 472 |
| 473 typedef GrGLRadial2Gradient GLEffect; | 473 typedef GrGLRadial2Gradient GLEffect; |
| 474 | 474 |
| 475 private: | 475 private: |
| 476 virtual bool onIsEqual(const GrEffect& sBase) const SK_OVERRIDE { | 476 virtual bool onIsEqual(const GrEffect& sBase) const SK_OVERRIDE { |
| 477 const GrRadial2Gradient& s = CastEffect<GrRadial2Gradient>(sBase); | 477 const GrRadial2Gradient& s = sBase.cast<GrRadial2Gradient>(); |
| 478 return (INHERITED::onIsEqual(sBase) && | 478 return (INHERITED::onIsEqual(sBase) && |
| 479 this->fCenterX1 == s.fCenterX1 && | 479 this->fCenterX1 == s.fCenterX1 && |
| 480 this->fRadius0 == s.fRadius0 && | 480 this->fRadius0 == s.fRadius0 && |
| 481 this->fPosRoot == s.fPosRoot); | 481 this->fPosRoot == s.fPosRoot); |
| 482 } | 482 } |
| 483 | 483 |
| 484 GrRadial2Gradient(GrContext* ctx, | 484 GrRadial2Gradient(GrContext* ctx, |
| 485 const SkTwoPointRadialGradient& shader, | 485 const SkTwoPointRadialGradient& shader, |
| 486 const SkMatrix& matrix, | 486 const SkMatrix& matrix, |
| 487 SkShader::TileMode tm) | 487 SkShader::TileMode tm) |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 548 SkPaint paint; | 548 SkPaint paint; |
| 549 GrEffect* effect; | 549 GrEffect* effect; |
| 550 GrColor paintColor; | 550 GrColor paintColor; |
| 551 SkAssertResult(shader->asNewEffect(context, paint, NULL, &paintColor, &effec
t)); | 551 SkAssertResult(shader->asNewEffect(context, paint, NULL, &paintColor, &effec
t)); |
| 552 return effect; | 552 return effect; |
| 553 } | 553 } |
| 554 | 554 |
| 555 ///////////////////////////////////////////////////////////////////// | 555 ///////////////////////////////////////////////////////////////////// |
| 556 | 556 |
| 557 GrGLRadial2Gradient::GrGLRadial2Gradient(const GrBackendEffectFactory& factory, | 557 GrGLRadial2Gradient::GrGLRadial2Gradient(const GrBackendEffectFactory& factory, |
| 558 const GrDrawEffect& drawEffect) | 558 const GrEffect& effect) |
| 559 : INHERITED(factory) | 559 : INHERITED(factory) |
| 560 , fVSVaryingName(NULL) | 560 , fVSVaryingName(NULL) |
| 561 , fFSVaryingName(NULL) | 561 , fFSVaryingName(NULL) |
| 562 , fCachedCenter(SK_ScalarMax) | 562 , fCachedCenter(SK_ScalarMax) |
| 563 , fCachedRadius(-SK_ScalarMax) | 563 , fCachedRadius(-SK_ScalarMax) |
| 564 , fCachedPosRoot(0) { | 564 , fCachedPosRoot(0) { |
| 565 | 565 |
| 566 const GrRadial2Gradient& data = drawEffect.castEffect<GrRadial2Gradient>(); | 566 const GrRadial2Gradient& data = effect.cast<GrRadial2Gradient>(); |
| 567 fIsDegenerate = data.isDegenerate(); | 567 fIsDegenerate = data.isDegenerate(); |
| 568 } | 568 } |
| 569 | 569 |
| 570 void GrGLRadial2Gradient::emitCode(GrGLProgramBuilder* builder, | 570 void GrGLRadial2Gradient::emitCode(GrGLProgramBuilder* builder, |
| 571 const GrDrawEffect& drawEffect, | 571 const GrEffect& effect, |
| 572 const GrEffectKey& key, | 572 const GrEffectKey& key, |
| 573 const char* outputColor, | 573 const char* outputColor, |
| 574 const char* inputColor, | 574 const char* inputColor, |
| 575 const TransformedCoordsArray& coords, | 575 const TransformedCoordsArray& coords, |
| 576 const TextureSamplerArray& samplers) { | 576 const TextureSamplerArray& samplers) { |
| 577 uint32_t baseKey = key.get32(0); | 577 uint32_t baseKey = key.get32(0); |
| 578 this->emitUniforms(builder, baseKey); | 578 this->emitUniforms(builder, baseKey); |
| 579 fParamUni = builder->addUniformArray(GrGLProgramBuilder::kFragment_Visibilit
y, | 579 fParamUni = builder->addUniformArray(GrGLProgramBuilder::kFragment_Visibilit
y, |
| 580 kFloat_GrSLType, "Radial2FSParams", 6); | 580 kFloat_GrSLType, "Radial2FSParams", 6); |
| 581 | 581 |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 635 rootName.c_str(), p1.c_str()); | 635 rootName.c_str(), p1.c_str()); |
| 636 } else { | 636 } else { |
| 637 // t is: -c/b | 637 // t is: -c/b |
| 638 t.printf("-%s / %s", cName.c_str(), bVar.c_str()); | 638 t.printf("-%s / %s", cName.c_str(), bVar.c_str()); |
| 639 } | 639 } |
| 640 | 640 |
| 641 this->emitColor(builder, t.c_str(), baseKey, outputColor, inputColor, sample
rs); | 641 this->emitColor(builder, t.c_str(), baseKey, outputColor, inputColor, sample
rs); |
| 642 } | 642 } |
| 643 | 643 |
| 644 void GrGLRadial2Gradient::setData(const GrGLProgramDataManager& pdman, | 644 void GrGLRadial2Gradient::setData(const GrGLProgramDataManager& pdman, |
| 645 const GrDrawEffect& drawEffect) { | 645 const GrEffect& effect) { |
| 646 INHERITED::setData(pdman, drawEffect); | 646 INHERITED::setData(pdman, effect); |
| 647 const GrRadial2Gradient& data = drawEffect.castEffect<GrRadial2Gradient>(); | 647 const GrRadial2Gradient& data = effect.cast<GrRadial2Gradient>(); |
| 648 SkASSERT(data.isDegenerate() == fIsDegenerate); | 648 SkASSERT(data.isDegenerate() == fIsDegenerate); |
| 649 SkScalar centerX1 = data.center(); | 649 SkScalar centerX1 = data.center(); |
| 650 SkScalar radius0 = data.radius(); | 650 SkScalar radius0 = data.radius(); |
| 651 if (fCachedCenter != centerX1 || | 651 if (fCachedCenter != centerX1 || |
| 652 fCachedRadius != radius0 || | 652 fCachedRadius != radius0 || |
| 653 fCachedPosRoot != data.isPosRoot()) { | 653 fCachedPosRoot != data.isPosRoot()) { |
| 654 | 654 |
| 655 SkScalar a = SkScalarMul(centerX1, centerX1) - SK_Scalar1; | 655 SkScalar a = SkScalarMul(centerX1, centerX1) - SK_Scalar1; |
| 656 | 656 |
| 657 // When we're in the degenerate (linear) case, the second | 657 // When we're in the degenerate (linear) case, the second |
| (...skipping 10 matching lines...) Expand all Loading... |
| 668 data.isPosRoot() ? 1.f : -1.f | 668 data.isPosRoot() ? 1.f : -1.f |
| 669 }; | 669 }; |
| 670 | 670 |
| 671 pdman.set1fv(fParamUni, 6, values); | 671 pdman.set1fv(fParamUni, 6, values); |
| 672 fCachedCenter = centerX1; | 672 fCachedCenter = centerX1; |
| 673 fCachedRadius = radius0; | 673 fCachedRadius = radius0; |
| 674 fCachedPosRoot = data.isPosRoot(); | 674 fCachedPosRoot = data.isPosRoot(); |
| 675 } | 675 } |
| 676 } | 676 } |
| 677 | 677 |
| 678 void GrGLRadial2Gradient::GenKey(const GrDrawEffect& drawEffect, | 678 void GrGLRadial2Gradient::GenKey(const GrEffect& effect, |
| 679 const GrGLCaps&, GrEffectKeyBuilder* b) { | 679 const GrGLCaps&, GrEffectKeyBuilder* b) { |
| 680 uint32_t* key = b->add32n(2); | 680 uint32_t* key = b->add32n(2); |
| 681 key[0] = GenBaseGradientKey(drawEffect); | 681 key[0] = GenBaseGradientKey(effect); |
| 682 key[1] = drawEffect.castEffect<GrRadial2Gradient>().isDegenerate(); | 682 key[1] = effect.cast<GrRadial2Gradient>().isDegenerate(); |
| 683 } | 683 } |
| 684 | 684 |
| 685 ///////////////////////////////////////////////////////////////////// | 685 ///////////////////////////////////////////////////////////////////// |
| 686 | 686 |
| 687 bool SkTwoPointRadialGradient::asNewEffect(GrContext* context, const SkPaint& pa
int, | 687 bool SkTwoPointRadialGradient::asNewEffect(GrContext* context, const SkPaint& pa
int, |
| 688 const SkMatrix* localMatrix, GrColor*
paintColor, | 688 const SkMatrix* localMatrix, GrColor*
paintColor, |
| 689 GrEffect** effect) const { | 689 GrEffect** effect) const { |
| 690 SkASSERT(context); | 690 SkASSERT(context); |
| 691 | 691 |
| 692 // invert the localM, translate to center1 (fPtsToUni), rotate so center2 is
on x axis. | 692 // invert the localM, translate to center1 (fPtsToUni), rotate so center2 is
on x axis. |
| (...skipping 28 matching lines...) Expand all Loading... |
| 721 #else | 721 #else |
| 722 | 722 |
| 723 bool SkTwoPointRadialGradient::asNewEffect(GrContext* context, const SkPaint& pa
int, | 723 bool SkTwoPointRadialGradient::asNewEffect(GrContext* context, const SkPaint& pa
int, |
| 724 const SkMatrix* localMatrix, GrColor*
paintColor, | 724 const SkMatrix* localMatrix, GrColor*
paintColor, |
| 725 GrEffect** effect) const { | 725 GrEffect** effect) const { |
| 726 SkDEBUGFAIL("Should not call in GPU-less build"); | 726 SkDEBUGFAIL("Should not call in GPU-less build"); |
| 727 return false; | 727 return false; |
| 728 } | 728 } |
| 729 | 729 |
| 730 #endif | 730 #endif |
| OLD | NEW |