| 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 416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 427 private: | 427 private: |
| 428 | 428 |
| 429 typedef GrGLGradientEffect INHERITED; | 429 typedef GrGLGradientEffect INHERITED; |
| 430 | 430 |
| 431 }; | 431 }; |
| 432 | 432 |
| 433 ///////////////////////////////////////////////////////////////////// | 433 ///////////////////////////////////////////////////////////////////// |
| 434 | 434 |
| 435 class GrRadial2Gradient : public GrGradientEffect { | 435 class GrRadial2Gradient : public GrGradientEffect { |
| 436 public: | 436 public: |
| 437 static GrEffectRef* Create(GrContext* ctx, | 437 static GrEffect* Create(GrContext* ctx, |
| 438 const SkTwoPointRadialGradient& shader, | 438 const SkTwoPointRadialGradient& shader, |
| 439 const SkMatrix& matrix, | 439 const SkMatrix& matrix, |
| 440 SkShader::TileMode tm) { | 440 SkShader::TileMode tm) { |
| 441 return SkNEW_ARGS(GrRadial2Gradient, (ctx, shader, matrix, tm)); | 441 return SkNEW_ARGS(GrRadial2Gradient, (ctx, shader, matrix, tm)); |
| 442 } | 442 } |
| 443 | 443 |
| 444 virtual ~GrRadial2Gradient() { } | 444 virtual ~GrRadial2Gradient() { } |
| 445 | 445 |
| 446 static const char* Name() { return "Two-Point Radial Gradient"; } | 446 static const char* Name() { return "Two-Point Radial Gradient"; } |
| 447 virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE { | 447 virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE { |
| 448 return GrTBackendEffectFactory<GrRadial2Gradient>::getInstance(); | 448 return GrTBackendEffectFactory<GrRadial2Gradient>::getInstance(); |
| 449 } | 449 } |
| 450 | 450 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 499 | 499 |
| 500 // @} | 500 // @} |
| 501 | 501 |
| 502 typedef GrGradientEffect INHERITED; | 502 typedef GrGradientEffect INHERITED; |
| 503 }; | 503 }; |
| 504 | 504 |
| 505 ///////////////////////////////////////////////////////////////////// | 505 ///////////////////////////////////////////////////////////////////// |
| 506 | 506 |
| 507 GR_DEFINE_EFFECT_TEST(GrRadial2Gradient); | 507 GR_DEFINE_EFFECT_TEST(GrRadial2Gradient); |
| 508 | 508 |
| 509 GrEffectRef* GrRadial2Gradient::TestCreate(SkRandom* random, | 509 GrEffect* GrRadial2Gradient::TestCreate(SkRandom* random, |
| 510 GrContext* context, | 510 GrContext* context, |
| 511 const GrDrawTargetCaps&, | 511 const GrDrawTargetCaps&, |
| 512 GrTexture**) { | 512 GrTexture**) { |
| 513 SkPoint center1 = {random->nextUScalar1(), random->nextUScalar1()}; | 513 SkPoint center1 = {random->nextUScalar1(), random->nextUScalar1()}; |
| 514 SkScalar radius1 = random->nextUScalar1(); | 514 SkScalar radius1 = random->nextUScalar1(); |
| 515 SkPoint center2; | 515 SkPoint center2; |
| 516 SkScalar radius2; | 516 SkScalar radius2; |
| 517 do { | 517 do { |
| 518 center2.set(random->nextUScalar1(), random->nextUScalar1()); | 518 center2.set(random->nextUScalar1(), random->nextUScalar1()); |
| 519 radius2 = random->nextUScalar1 (); | 519 radius2 = random->nextUScalar1 (); |
| 520 // There is a bug in two point radial gradients with identical radii | 520 // There is a bug in two point radial gradients with identical radii |
| 521 } while (radius1 == radius2); | 521 } while (radius1 == radius2); |
| 522 | 522 |
| 523 SkColor colors[kMaxRandomGradientColors]; | 523 SkColor colors[kMaxRandomGradientColors]; |
| 524 SkScalar stopsArray[kMaxRandomGradientColors]; | 524 SkScalar stopsArray[kMaxRandomGradientColors]; |
| 525 SkScalar* stops = stopsArray; | 525 SkScalar* stops = stopsArray; |
| 526 SkShader::TileMode tm; | 526 SkShader::TileMode tm; |
| 527 int colorCount = RandomGradientParams(random, colors, &stops, &tm); | 527 int colorCount = RandomGradientParams(random, colors, &stops, &tm); |
| 528 SkAutoTUnref<SkShader> shader(SkGradientShader::CreateTwoPointRadial(center1
, radius1, | 528 SkAutoTUnref<SkShader> shader(SkGradientShader::CreateTwoPointRadial(center1
, radius1, |
| 529 center2
, radius2, | 529 center2
, radius2, |
| 530 colors,
stops, colorCount, | 530 colors,
stops, colorCount, |
| 531 tm)); | 531 tm)); |
| 532 SkPaint paint; | 532 SkPaint paint; |
| 533 GrEffectRef* effect; | 533 GrEffect* effect; |
| 534 GrColor grColor; | 534 GrColor paintColor; |
| 535 shader->asNewEffect(context, paint, NULL, &grColor, &effect); | 535 SkAssertResult(shader->asNewEffect(context, paint, NULL, &paintColor, &effec
t)); |
| 536 return effect; | 536 return effect; |
| 537 } | 537 } |
| 538 | 538 |
| 539 ///////////////////////////////////////////////////////////////////// | 539 ///////////////////////////////////////////////////////////////////// |
| 540 | 540 |
| 541 GrGLRadial2Gradient::GrGLRadial2Gradient(const GrBackendEffectFactory& factory, | 541 GrGLRadial2Gradient::GrGLRadial2Gradient(const GrBackendEffectFactory& factory, |
| 542 const GrDrawEffect& drawEffect) | 542 const GrDrawEffect& drawEffect) |
| 543 : INHERITED(factory) | 543 : INHERITED(factory) |
| 544 , fVSVaryingName(NULL) | 544 , fVSVaryingName(NULL) |
| 545 , fFSVaryingName(NULL) | 545 , fFSVaryingName(NULL) |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 667 EffectKey key = GenBaseGradientKey(drawEffect); | 667 EffectKey key = GenBaseGradientKey(drawEffect); |
| 668 if (drawEffect.castEffect<GrRadial2Gradient>().isDegenerate()) { | 668 if (drawEffect.castEffect<GrRadial2Gradient>().isDegenerate()) { |
| 669 key |= kIsDegenerate; | 669 key |= kIsDegenerate; |
| 670 } | 670 } |
| 671 return key; | 671 return key; |
| 672 } | 672 } |
| 673 | 673 |
| 674 ///////////////////////////////////////////////////////////////////// | 674 ///////////////////////////////////////////////////////////////////// |
| 675 | 675 |
| 676 bool SkTwoPointRadialGradient::asNewEffect(GrContext* context, const SkPaint& pa
int, | 676 bool SkTwoPointRadialGradient::asNewEffect(GrContext* context, const SkPaint& pa
int, |
| 677 const SkMatrix* localMatrix, GrColor*
grColor, | 677 const SkMatrix* localMatrix, GrColor*
paintColor, |
| 678 GrEffectRef** grEffect) const { | 678 GrEffect** effect) const { |
| 679 SkASSERT(NULL != context); | 679 SkASSERT(NULL != context); |
| 680 | 680 |
| 681 // invert the localM, translate to center1 (fPtsToUni), rotate so center2 is
on x axis. | 681 // invert the localM, translate to center1 (fPtsToUni), rotate so center2 is
on x axis. |
| 682 SkMatrix matrix; | 682 SkMatrix matrix; |
| 683 if (!this->getLocalMatrix().invert(&matrix)) { | 683 if (!this->getLocalMatrix().invert(&matrix)) { |
| 684 return false; | 684 return false; |
| 685 } | 685 } |
| 686 if (localMatrix) { | 686 if (localMatrix) { |
| 687 SkMatrix inv; | 687 SkMatrix inv; |
| 688 if (!localMatrix->invert(&inv)) { | 688 if (!localMatrix->invert(&inv)) { |
| 689 return false; | 689 return false; |
| 690 } | 690 } |
| 691 matrix.postConcat(inv); | 691 matrix.postConcat(inv); |
| 692 } | 692 } |
| 693 matrix.postConcat(fPtsToUnit); | 693 matrix.postConcat(fPtsToUnit); |
| 694 | 694 |
| 695 SkScalar diffLen = fDiff.length(); | 695 SkScalar diffLen = fDiff.length(); |
| 696 if (0 != diffLen) { | 696 if (0 != diffLen) { |
| 697 SkScalar invDiffLen = SkScalarInvert(diffLen); | 697 SkScalar invDiffLen = SkScalarInvert(diffLen); |
| 698 SkMatrix rot; | 698 SkMatrix rot; |
| 699 rot.setSinCos(-SkScalarMul(invDiffLen, fDiff.fY), | 699 rot.setSinCos(-SkScalarMul(invDiffLen, fDiff.fY), |
| 700 SkScalarMul(invDiffLen, fDiff.fX)); | 700 SkScalarMul(invDiffLen, fDiff.fX)); |
| 701 matrix.postConcat(rot); | 701 matrix.postConcat(rot); |
| 702 } | 702 } |
| 703 | 703 |
| 704 *grColor = SkColor2GrColorJustAlpha(paint.getColor()); | 704 *paintColor = SkColor2GrColorJustAlpha(paint.getColor()); |
| 705 *grEffect = GrRadial2Gradient::Create(context, *this, matrix, fTileMode); | 705 *effect = GrRadial2Gradient::Create(context, *this, matrix, fTileMode); |
| 706 | 706 |
| 707 return true; | 707 return true; |
| 708 } | 708 } |
| 709 | 709 |
| 710 #else | 710 #else |
| 711 | 711 |
| 712 bool SkTwoPointRadialGradient::asNewEffect(GrContext* context, const SkPaint& pa
int, | 712 bool SkTwoPointRadialGradient::asNewEffect(GrContext* context, const SkPaint& pa
int, |
| 713 const SkMatrix* localMatrix, GrColor*
grColor, | 713 const SkMatrix* localMatrix, GrColor*
paintColor, |
| 714 GrEffect** grEffect) const { | 714 GrEffect** effect) const { |
| 715 SkDEBUGFAIL("Should not call in GPU-less build"); | 715 SkDEBUGFAIL("Should not call in GPU-less build"); |
| 716 return false; | 716 return false; |
| 717 } | 717 } |
| 718 | 718 |
| 719 #endif | 719 #endif |
| OLD | NEW |