| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 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 "SkTwoPointConicalGradient_gpu.h" | 8 #include "SkTwoPointConicalGradient_gpu.h" |
| 9 | 9 |
| 10 #include "SkTwoPointConicalGradient.h" | 10 #include "SkTwoPointConicalGradient.h" |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 SkMatrix rot; | 54 SkMatrix rot; |
| 55 rot.setSinCos(-SkScalarMul(invDiffLen, diff.fY), | 55 rot.setSinCos(-SkScalarMul(invDiffLen, diff.fY), |
| 56 SkScalarMul(invDiffLen, diff.fX)); | 56 SkScalarMul(invDiffLen, diff.fX)); |
| 57 invLMatrix->postConcat(rot); | 57 invLMatrix->postConcat(rot); |
| 58 } | 58 } |
| 59 } | 59 } |
| 60 | 60 |
| 61 class Edge2PtConicalEffect : public GrGradientEffect { | 61 class Edge2PtConicalEffect : public GrGradientEffect { |
| 62 public: | 62 public: |
| 63 | 63 |
| 64 static GrFragmentProcessor* Create(GrContext* ctx, | 64 static sk_sp<GrFragmentProcessor> Make(GrContext* ctx, |
| 65 const SkTwoPointConicalGradient& shader, | 65 const SkTwoPointConicalGradient& shad
er, |
| 66 const SkMatrix& matrix, | 66 const SkMatrix& matrix, |
| 67 SkShader::TileMode tm) { | 67 SkShader::TileMode tm) { |
| 68 return new Edge2PtConicalEffect(ctx, shader, matrix, tm); | 68 return sk_sp<GrFragmentProcessor>(new Edge2PtConicalEffect(ctx, shader,
matrix, tm)); |
| 69 } | 69 } |
| 70 | 70 |
| 71 virtual ~Edge2PtConicalEffect() {} | 71 virtual ~Edge2PtConicalEffect() {} |
| 72 | 72 |
| 73 const char* name() const override { | 73 const char* name() const override { |
| 74 return "Two-Point Conical Gradient Edge Touching"; | 74 return "Two-Point Conical Gradient Edge Touching"; |
| 75 } | 75 } |
| 76 | 76 |
| 77 // The radial gradient parameters can collapse to a linear (instead of quadr
atic) equation. | 77 // The radial gradient parameters can collapse to a linear (instead of quadr
atic) equation. |
| 78 SkScalar center() const { return fCenterX1; } | 78 SkScalar center() const { return fCenterX1; } |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 | 177 |
| 178 GrGLSLFragmentProcessor* Edge2PtConicalEffect::onCreateGLSLInstance() const { | 178 GrGLSLFragmentProcessor* Edge2PtConicalEffect::onCreateGLSLInstance() const { |
| 179 return new GLEdge2PtConicalEffect(*this); | 179 return new GLEdge2PtConicalEffect(*this); |
| 180 } | 180 } |
| 181 | 181 |
| 182 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(Edge2PtConicalEffect); | 182 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(Edge2PtConicalEffect); |
| 183 | 183 |
| 184 /* | 184 /* |
| 185 * All Two point conical gradient test create functions may occasionally create
edge case shaders | 185 * All Two point conical gradient test create functions may occasionally create
edge case shaders |
| 186 */ | 186 */ |
| 187 const GrFragmentProcessor* Edge2PtConicalEffect::TestCreate(GrProcessorTestData*
d) { | 187 sk_sp<GrFragmentProcessor> Edge2PtConicalEffect::TestCreate(GrProcessorTestData*
d) { |
| 188 SkPoint center1 = {d->fRandom->nextUScalar1(), d->fRandom->nextUScalar1()}; | 188 SkPoint center1 = {d->fRandom->nextUScalar1(), d->fRandom->nextUScalar1()}; |
| 189 SkScalar radius1 = d->fRandom->nextUScalar1(); | 189 SkScalar radius1 = d->fRandom->nextUScalar1(); |
| 190 SkPoint center2; | 190 SkPoint center2; |
| 191 SkScalar radius2; | 191 SkScalar radius2; |
| 192 do { | 192 do { |
| 193 center2.set(d->fRandom->nextUScalar1(), d->fRandom->nextUScalar1()); | 193 center2.set(d->fRandom->nextUScalar1(), d->fRandom->nextUScalar1()); |
| 194 // If the circles are identical the factory will give us an empty shader
. | 194 // If the circles are identical the factory will give us an empty shader
. |
| 195 // This will happen if we pick identical centers | 195 // This will happen if we pick identical centers |
| 196 } while (center1 == center2); | 196 } while (center1 == center2); |
| 197 | 197 |
| 198 // Below makes sure that circle one is contained within circle two | 198 // Below makes sure that circle one is contained within circle two |
| 199 // and both circles are touching on an edge | 199 // and both circles are touching on an edge |
| 200 SkPoint diff = center2 - center1; | 200 SkPoint diff = center2 - center1; |
| 201 SkScalar diffLen = diff.length(); | 201 SkScalar diffLen = diff.length(); |
| 202 radius2 = radius1 + diffLen; | 202 radius2 = radius1 + diffLen; |
| 203 | 203 |
| 204 SkColor colors[kMaxRandomGradientColors]; | 204 SkColor colors[kMaxRandomGradientColors]; |
| 205 SkScalar stopsArray[kMaxRandomGradientColors]; | 205 SkScalar stopsArray[kMaxRandomGradientColors]; |
| 206 SkScalar* stops = stopsArray; | 206 SkScalar* stops = stopsArray; |
| 207 SkShader::TileMode tm; | 207 SkShader::TileMode tm; |
| 208 int colorCount = RandomGradientParams(d->fRandom, colors, &stops, &tm); | 208 int colorCount = RandomGradientParams(d->fRandom, colors, &stops, &tm); |
| 209 auto shader = SkGradientShader::MakeTwoPointConical(center1, radius1, center
2, radius2, | 209 auto shader = SkGradientShader::MakeTwoPointConical(center1, radius1, center
2, radius2, |
| 210 colors, stops, colorCoun
t, tm); | 210 colors, stops, colorCoun
t, tm); |
| 211 const GrFragmentProcessor* fp = shader->asFragmentProcessor(d->fContext, | 211 sk_sp<GrFragmentProcessor> fp = shader->asFragmentProcessor(d->fContext, |
| 212 GrTest::TestMatrix(d->fRandom), NULL, kNone_SkFilterQuality, | 212 GrTest::TestMatrix(d->fRandom), NULL, kNone_SkFilterQuality, |
| 213 SkSourceGammaTreatment::kRespect); | 213 SkSourceGammaTreatment::kRespect); |
| 214 GrAlwaysAssert(fp); | 214 GrAlwaysAssert(fp); |
| 215 return fp; | 215 return fp; |
| 216 } | 216 } |
| 217 | 217 |
| 218 GLEdge2PtConicalEffect::GLEdge2PtConicalEffect(const GrProcessor&) | 218 GLEdge2PtConicalEffect::GLEdge2PtConicalEffect(const GrProcessor&) |
| 219 : fVSVaryingName(nullptr) | 219 : fVSVaryingName(nullptr) |
| 220 , fFSVaryingName(nullptr) | 220 , fFSVaryingName(nullptr) |
| 221 , fCachedRadius(-SK_ScalarMax) | 221 , fCachedRadius(-SK_ScalarMax) |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 363 invLMatrix->postConcat(matrix); | 363 invLMatrix->postConcat(matrix); |
| 364 | 364 |
| 365 return conicalType; | 365 return conicalType; |
| 366 } | 366 } |
| 367 | 367 |
| 368 ////////////////////////////////////////////////////////////////////////////// | 368 ////////////////////////////////////////////////////////////////////////////// |
| 369 | 369 |
| 370 class FocalOutside2PtConicalEffect : public GrGradientEffect { | 370 class FocalOutside2PtConicalEffect : public GrGradientEffect { |
| 371 public: | 371 public: |
| 372 | 372 |
| 373 static GrFragmentProcessor* Create(GrContext* ctx, | 373 static sk_sp<GrFragmentProcessor> Make(GrContext* ctx, |
| 374 const SkTwoPointConicalGradient& shader, | 374 const SkTwoPointConicalGradient& shad
er, |
| 375 const SkMatrix& matrix, | 375 const SkMatrix& matrix, |
| 376 SkShader::TileMode tm, | 376 SkShader::TileMode tm, |
| 377 SkScalar focalX) { | 377 SkScalar focalX) { |
| 378 return new FocalOutside2PtConicalEffect(ctx, shader, matrix, tm, focalX)
; | 378 return sk_sp<GrFragmentProcessor>( |
| 379 new FocalOutside2PtConicalEffect(ctx, shader, matrix, tm, focalX)); |
| 379 } | 380 } |
| 380 | 381 |
| 381 virtual ~FocalOutside2PtConicalEffect() { } | 382 virtual ~FocalOutside2PtConicalEffect() { } |
| 382 | 383 |
| 383 const char* name() const override { | 384 const char* name() const override { |
| 384 return "Two-Point Conical Gradient Focal Outside"; | 385 return "Two-Point Conical Gradient Focal Outside"; |
| 385 } | 386 } |
| 386 | 387 |
| 387 bool isFlipped() const { return fIsFlipped; } | 388 bool isFlipped() const { return fIsFlipped; } |
| 388 SkScalar focal() const { return fFocalX; } | 389 SkScalar focal() const { return fFocalX; } |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 456 | 457 |
| 457 GrGLSLFragmentProcessor* FocalOutside2PtConicalEffect::onCreateGLSLInstance() co
nst { | 458 GrGLSLFragmentProcessor* FocalOutside2PtConicalEffect::onCreateGLSLInstance() co
nst { |
| 458 return new GLFocalOutside2PtConicalEffect(*this); | 459 return new GLFocalOutside2PtConicalEffect(*this); |
| 459 } | 460 } |
| 460 | 461 |
| 461 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(FocalOutside2PtConicalEffect); | 462 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(FocalOutside2PtConicalEffect); |
| 462 | 463 |
| 463 /* | 464 /* |
| 464 * All Two point conical gradient test create functions may occasionally create
edge case shaders | 465 * All Two point conical gradient test create functions may occasionally create
edge case shaders |
| 465 */ | 466 */ |
| 466 const GrFragmentProcessor* FocalOutside2PtConicalEffect::TestCreate(GrProcessorT
estData* d) { | 467 sk_sp<GrFragmentProcessor> FocalOutside2PtConicalEffect::TestCreate(GrProcessorT
estData* d) { |
| 467 SkPoint center1 = {d->fRandom->nextUScalar1(), d->fRandom->nextUScalar1()}; | 468 SkPoint center1 = {d->fRandom->nextUScalar1(), d->fRandom->nextUScalar1()}; |
| 468 SkScalar radius1 = 0.f; | 469 SkScalar radius1 = 0.f; |
| 469 SkPoint center2; | 470 SkPoint center2; |
| 470 SkScalar radius2; | 471 SkScalar radius2; |
| 471 do { | 472 do { |
| 472 center2.set(d->fRandom->nextUScalar1(), d->fRandom->nextUScalar1()); | 473 center2.set(d->fRandom->nextUScalar1(), d->fRandom->nextUScalar1()); |
| 473 // Need to make sure the centers are not the same or else focal point wi
ll be inside | 474 // Need to make sure the centers are not the same or else focal point wi
ll be inside |
| 474 } while (center1 == center2); | 475 } while (center1 == center2); |
| 475 SkPoint diff = center2 - center1; | 476 SkPoint diff = center2 - center1; |
| 476 SkScalar diffLen = diff.length(); | 477 SkScalar diffLen = diff.length(); |
| 477 // Below makes sure that the focal point is not contained within circle
two | 478 // Below makes sure that the focal point is not contained within circle
two |
| 478 radius2 = d->fRandom->nextRangeF(0.f, diffLen); | 479 radius2 = d->fRandom->nextRangeF(0.f, diffLen); |
| 479 | 480 |
| 480 SkColor colors[kMaxRandomGradientColors]; | 481 SkColor colors[kMaxRandomGradientColors]; |
| 481 SkScalar stopsArray[kMaxRandomGradientColors]; | 482 SkScalar stopsArray[kMaxRandomGradientColors]; |
| 482 SkScalar* stops = stopsArray; | 483 SkScalar* stops = stopsArray; |
| 483 SkShader::TileMode tm; | 484 SkShader::TileMode tm; |
| 484 int colorCount = RandomGradientParams(d->fRandom, colors, &stops, &tm); | 485 int colorCount = RandomGradientParams(d->fRandom, colors, &stops, &tm); |
| 485 auto shader = SkGradientShader::MakeTwoPointConical(center1, radius1, center
2, radius2, | 486 auto shader = SkGradientShader::MakeTwoPointConical(center1, radius1, center
2, radius2, |
| 486 colors, stops, colorCoun
t, tm); | 487 colors, stops, colorCoun
t, tm); |
| 487 const GrFragmentProcessor* fp = shader->asFragmentProcessor(d->fContext, | 488 sk_sp<GrFragmentProcessor> fp = shader->asFragmentProcessor(d->fContext, |
| 488 GrTest::TestMatrix(d->fRandom), NULL, kNone_SkFilterQuality, | 489 GrTest::TestMatrix(d->fRandom), NULL, kNone_SkFilterQuality, |
| 489 SkSourceGammaTreatment::kRespect); | 490 SkSourceGammaTreatment::kRespect); |
| 490 GrAlwaysAssert(fp); | 491 GrAlwaysAssert(fp); |
| 491 return fp; | 492 return fp; |
| 492 } | 493 } |
| 493 | 494 |
| 494 GLFocalOutside2PtConicalEffect::GLFocalOutside2PtConicalEffect(const GrProcessor
& processor) | 495 GLFocalOutside2PtConicalEffect::GLFocalOutside2PtConicalEffect(const GrProcessor
& processor) |
| 495 : fVSVaryingName(nullptr) | 496 : fVSVaryingName(nullptr) |
| 496 , fFSVaryingName(nullptr) | 497 , fFSVaryingName(nullptr) |
| 497 , fCachedFocal(SK_ScalarMax) { | 498 , fCachedFocal(SK_ScalarMax) { |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 573 key[1] = processor.cast<FocalOutside2PtConicalEffect>().isFlipped(); | 574 key[1] = processor.cast<FocalOutside2PtConicalEffect>().isFlipped(); |
| 574 } | 575 } |
| 575 | 576 |
| 576 ////////////////////////////////////////////////////////////////////////////// | 577 ////////////////////////////////////////////////////////////////////////////// |
| 577 | 578 |
| 578 class GLFocalInside2PtConicalEffect; | 579 class GLFocalInside2PtConicalEffect; |
| 579 | 580 |
| 580 class FocalInside2PtConicalEffect : public GrGradientEffect { | 581 class FocalInside2PtConicalEffect : public GrGradientEffect { |
| 581 public: | 582 public: |
| 582 | 583 |
| 583 static GrFragmentProcessor* Create(GrContext* ctx, | 584 static sk_sp<GrFragmentProcessor> Make(GrContext* ctx, |
| 584 const SkTwoPointConicalGradient& shader, | 585 const SkTwoPointConicalGradient& shad
er, |
| 585 const SkMatrix& matrix, | 586 const SkMatrix& matrix, |
| 586 SkShader::TileMode tm, | 587 SkShader::TileMode tm, |
| 587 SkScalar focalX) { | 588 SkScalar focalX) { |
| 588 return new FocalInside2PtConicalEffect(ctx, shader, matrix, tm, focalX); | 589 return sk_sp<GrFragmentProcessor>( |
| 590 new FocalInside2PtConicalEffect(ctx, shader, matrix, tm, focalX)); |
| 589 } | 591 } |
| 590 | 592 |
| 591 virtual ~FocalInside2PtConicalEffect() {} | 593 virtual ~FocalInside2PtConicalEffect() {} |
| 592 | 594 |
| 593 const char* name() const override { | 595 const char* name() const override { |
| 594 return "Two-Point Conical Gradient Focal Inside"; | 596 return "Two-Point Conical Gradient Focal Inside"; |
| 595 } | 597 } |
| 596 | 598 |
| 597 SkScalar focal() const { return fFocalX; } | 599 SkScalar focal() const { return fFocalX; } |
| 598 | 600 |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 661 | 663 |
| 662 GrGLSLFragmentProcessor* FocalInside2PtConicalEffect::onCreateGLSLInstance() con
st { | 664 GrGLSLFragmentProcessor* FocalInside2PtConicalEffect::onCreateGLSLInstance() con
st { |
| 663 return new GLFocalInside2PtConicalEffect(*this); | 665 return new GLFocalInside2PtConicalEffect(*this); |
| 664 } | 666 } |
| 665 | 667 |
| 666 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(FocalInside2PtConicalEffect); | 668 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(FocalInside2PtConicalEffect); |
| 667 | 669 |
| 668 /* | 670 /* |
| 669 * All Two point conical gradient test create functions may occasionally create
edge case shaders | 671 * All Two point conical gradient test create functions may occasionally create
edge case shaders |
| 670 */ | 672 */ |
| 671 const GrFragmentProcessor* FocalInside2PtConicalEffect::TestCreate(GrProcessorTe
stData* d) { | 673 sk_sp<GrFragmentProcessor> FocalInside2PtConicalEffect::TestCreate(GrProcessorTe
stData* d) { |
| 672 SkPoint center1 = {d->fRandom->nextUScalar1(), d->fRandom->nextUScalar1()}; | 674 SkPoint center1 = {d->fRandom->nextUScalar1(), d->fRandom->nextUScalar1()}; |
| 673 SkScalar radius1 = 0.f; | 675 SkScalar radius1 = 0.f; |
| 674 SkPoint center2; | 676 SkPoint center2; |
| 675 SkScalar radius2; | 677 SkScalar radius2; |
| 676 do { | 678 do { |
| 677 center2.set(d->fRandom->nextUScalar1(), d->fRandom->nextUScalar1()); | 679 center2.set(d->fRandom->nextUScalar1(), d->fRandom->nextUScalar1()); |
| 678 // Below makes sure radius2 is larger enouch such that the focal point | 680 // Below makes sure radius2 is larger enouch such that the focal point |
| 679 // is inside the end circle | 681 // is inside the end circle |
| 680 SkScalar increase = d->fRandom->nextUScalar1(); | 682 SkScalar increase = d->fRandom->nextUScalar1(); |
| 681 SkPoint diff = center2 - center1; | 683 SkPoint diff = center2 - center1; |
| 682 SkScalar diffLen = diff.length(); | 684 SkScalar diffLen = diff.length(); |
| 683 radius2 = diffLen + increase; | 685 radius2 = diffLen + increase; |
| 684 // If the circles are identical the factory will give us an empty shader
. | 686 // If the circles are identical the factory will give us an empty shader
. |
| 685 } while (radius1 == radius2 && center1 == center2); | 687 } while (radius1 == radius2 && center1 == center2); |
| 686 | 688 |
| 687 SkColor colors[kMaxRandomGradientColors]; | 689 SkColor colors[kMaxRandomGradientColors]; |
| 688 SkScalar stopsArray[kMaxRandomGradientColors]; | 690 SkScalar stopsArray[kMaxRandomGradientColors]; |
| 689 SkScalar* stops = stopsArray; | 691 SkScalar* stops = stopsArray; |
| 690 SkShader::TileMode tm; | 692 SkShader::TileMode tm; |
| 691 int colorCount = RandomGradientParams(d->fRandom, colors, &stops, &tm); | 693 int colorCount = RandomGradientParams(d->fRandom, colors, &stops, &tm); |
| 692 auto shader = SkGradientShader::MakeTwoPointConical(center1, radius1, center
2, radius2, | 694 auto shader = SkGradientShader::MakeTwoPointConical(center1, radius1, center
2, radius2, |
| 693 colors, stops, colorCoun
t, tm); | 695 colors, stops, colorCoun
t, tm); |
| 694 const GrFragmentProcessor* fp = shader->asFragmentProcessor(d->fContext, | 696 sk_sp<GrFragmentProcessor> fp = shader->asFragmentProcessor(d->fContext, |
| 695 GrTest::TestMatrix(d->fRandom), NULL, kNone_SkFilterQuality, | 697 GrTest::TestMatrix(d->fRandom), NULL, kNone_SkFilterQuality, |
| 696 SkSourceGammaTreatment::kRespect); | 698 SkSourceGammaTreatment::kRespect); |
| 697 GrAlwaysAssert(fp); | 699 GrAlwaysAssert(fp); |
| 698 return fp; | 700 return fp; |
| 699 } | 701 } |
| 700 | 702 |
| 701 GLFocalInside2PtConicalEffect::GLFocalInside2PtConicalEffect(const GrProcessor&) | 703 GLFocalInside2PtConicalEffect::GLFocalInside2PtConicalEffect(const GrProcessor&) |
| 702 : fVSVaryingName(nullptr) | 704 : fVSVaryingName(nullptr) |
| 703 , fFSVaryingName(nullptr) | 705 , fFSVaryingName(nullptr) |
| 704 , fCachedFocal(SK_ScalarMax) {} | 706 , fCachedFocal(SK_ScalarMax) {} |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 812 // if A ends up being negative, the start circle is contained completely ins
ide the end cirlce | 814 // if A ends up being negative, the start circle is contained completely ins
ide the end cirlce |
| 813 if (A < 0.f) { | 815 if (A < 0.f) { |
| 814 return kInside_ConicalType; | 816 return kInside_ConicalType; |
| 815 } | 817 } |
| 816 return kOutside_ConicalType; | 818 return kOutside_ConicalType; |
| 817 } | 819 } |
| 818 | 820 |
| 819 class CircleInside2PtConicalEffect : public GrGradientEffect { | 821 class CircleInside2PtConicalEffect : public GrGradientEffect { |
| 820 public: | 822 public: |
| 821 | 823 |
| 822 static GrFragmentProcessor* Create(GrContext* ctx, | 824 static sk_sp<GrFragmentProcessor> Make(GrContext* ctx, |
| 823 const SkTwoPointConicalGradient& shader, | 825 const SkTwoPointConicalGradient& shad
er, |
| 824 const SkMatrix& matrix, | 826 const SkMatrix& matrix, |
| 825 SkShader::TileMode tm, | 827 SkShader::TileMode tm, |
| 826 const CircleConicalInfo& info) { | 828 const CircleConicalInfo& info) { |
| 827 return new CircleInside2PtConicalEffect(ctx, shader, matrix, tm, info); | 829 return sk_sp<GrFragmentProcessor>( |
| 830 new CircleInside2PtConicalEffect(ctx, shader, matrix, tm, info)); |
| 828 } | 831 } |
| 829 | 832 |
| 830 virtual ~CircleInside2PtConicalEffect() {} | 833 virtual ~CircleInside2PtConicalEffect() {} |
| 831 | 834 |
| 832 const char* name() const override { return "Two-Point Conical Gradient Insid
e"; } | 835 const char* name() const override { return "Two-Point Conical Gradient Insid
e"; } |
| 833 | 836 |
| 834 SkScalar centerX() const { return fInfo.fCenterEnd.fX; } | 837 SkScalar centerX() const { return fInfo.fCenterEnd.fX; } |
| 835 SkScalar centerY() const { return fInfo.fCenterEnd.fY; } | 838 SkScalar centerY() const { return fInfo.fCenterEnd.fY; } |
| 836 SkScalar A() const { return fInfo.fA; } | 839 SkScalar A() const { return fInfo.fA; } |
| 837 SkScalar B() const { return fInfo.fB; } | 840 SkScalar B() const { return fInfo.fB; } |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 909 | 912 |
| 910 GrGLSLFragmentProcessor* CircleInside2PtConicalEffect::onCreateGLSLInstance() co
nst { | 913 GrGLSLFragmentProcessor* CircleInside2PtConicalEffect::onCreateGLSLInstance() co
nst { |
| 911 return new GLCircleInside2PtConicalEffect(*this); | 914 return new GLCircleInside2PtConicalEffect(*this); |
| 912 } | 915 } |
| 913 | 916 |
| 914 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(CircleInside2PtConicalEffect); | 917 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(CircleInside2PtConicalEffect); |
| 915 | 918 |
| 916 /* | 919 /* |
| 917 * All Two point conical gradient test create functions may occasionally create
edge case shaders | 920 * All Two point conical gradient test create functions may occasionally create
edge case shaders |
| 918 */ | 921 */ |
| 919 const GrFragmentProcessor* CircleInside2PtConicalEffect::TestCreate(GrProcessorT
estData* d) { | 922 sk_sp<GrFragmentProcessor> CircleInside2PtConicalEffect::TestCreate(GrProcessorT
estData* d) { |
| 920 SkPoint center1 = {d->fRandom->nextUScalar1(), d->fRandom->nextUScalar1()}; | 923 SkPoint center1 = {d->fRandom->nextUScalar1(), d->fRandom->nextUScalar1()}; |
| 921 SkScalar radius1 = d->fRandom->nextUScalar1() + 0.0001f; // make sure radius
1 != 0 | 924 SkScalar radius1 = d->fRandom->nextUScalar1() + 0.0001f; // make sure radius
1 != 0 |
| 922 SkPoint center2; | 925 SkPoint center2; |
| 923 SkScalar radius2; | 926 SkScalar radius2; |
| 924 do { | 927 do { |
| 925 center2.set(d->fRandom->nextUScalar1(), d->fRandom->nextUScalar1()); | 928 center2.set(d->fRandom->nextUScalar1(), d->fRandom->nextUScalar1()); |
| 926 // Below makes sure that circle one is contained within circle two | 929 // Below makes sure that circle one is contained within circle two |
| 927 SkScalar increase = d->fRandom->nextUScalar1(); | 930 SkScalar increase = d->fRandom->nextUScalar1(); |
| 928 SkPoint diff = center2 - center1; | 931 SkPoint diff = center2 - center1; |
| 929 SkScalar diffLen = diff.length(); | 932 SkScalar diffLen = diff.length(); |
| 930 radius2 = radius1 + diffLen + increase; | 933 radius2 = radius1 + diffLen + increase; |
| 931 // If the circles are identical the factory will give us an empty shader
. | 934 // If the circles are identical the factory will give us an empty shader
. |
| 932 } while (radius1 == radius2 && center1 == center2); | 935 } while (radius1 == radius2 && center1 == center2); |
| 933 | 936 |
| 934 SkColor colors[kMaxRandomGradientColors]; | 937 SkColor colors[kMaxRandomGradientColors]; |
| 935 SkScalar stopsArray[kMaxRandomGradientColors]; | 938 SkScalar stopsArray[kMaxRandomGradientColors]; |
| 936 SkScalar* stops = stopsArray; | 939 SkScalar* stops = stopsArray; |
| 937 SkShader::TileMode tm; | 940 SkShader::TileMode tm; |
| 938 int colorCount = RandomGradientParams(d->fRandom, colors, &stops, &tm); | 941 int colorCount = RandomGradientParams(d->fRandom, colors, &stops, &tm); |
| 939 auto shader = SkGradientShader::MakeTwoPointConical(center1, radius1, center
2, radius2, | 942 auto shader = SkGradientShader::MakeTwoPointConical(center1, radius1, center
2, radius2, |
| 940 colors, stops, colorCoun
t, tm); | 943 colors, stops, colorCoun
t, tm); |
| 941 const GrFragmentProcessor* fp = shader->asFragmentProcessor(d->fContext, | 944 sk_sp<GrFragmentProcessor> fp = shader->asFragmentProcessor(d->fContext, |
| 942 GrTest::TestMatrix(d->fRandom), NULL, kNone_SkFilterQuality, | 945 GrTest::TestMatrix(d->fRandom), NULL, kNone_SkFilterQuality, |
| 943 SkSourceGammaTreatment::kRespect); | 946 SkSourceGammaTreatment::kRespect); |
| 944 GrAlwaysAssert(fp); | 947 GrAlwaysAssert(fp); |
| 945 return fp; | 948 return fp; |
| 946 } | 949 } |
| 947 | 950 |
| 948 GLCircleInside2PtConicalEffect::GLCircleInside2PtConicalEffect(const GrProcessor
& processor) | 951 GLCircleInside2PtConicalEffect::GLCircleInside2PtConicalEffect(const GrProcessor
& processor) |
| 949 : fVSVaryingName(nullptr) | 952 : fVSVaryingName(nullptr) |
| 950 , fFSVaryingName(nullptr) | 953 , fFSVaryingName(nullptr) |
| 951 , fCachedCenterX(SK_ScalarMax) | 954 , fCachedCenterX(SK_ScalarMax) |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1028 void GLCircleInside2PtConicalEffect::GenKey(const GrProcessor& processor, | 1031 void GLCircleInside2PtConicalEffect::GenKey(const GrProcessor& processor, |
| 1029 const GrGLSLCaps&, GrProcessorKeyBui
lder* b) { | 1032 const GrGLSLCaps&, GrProcessorKeyBui
lder* b) { |
| 1030 b->add32(GenBaseGradientKey(processor)); | 1033 b->add32(GenBaseGradientKey(processor)); |
| 1031 } | 1034 } |
| 1032 | 1035 |
| 1033 ////////////////////////////////////////////////////////////////////////////// | 1036 ////////////////////////////////////////////////////////////////////////////// |
| 1034 | 1037 |
| 1035 class CircleOutside2PtConicalEffect : public GrGradientEffect { | 1038 class CircleOutside2PtConicalEffect : public GrGradientEffect { |
| 1036 public: | 1039 public: |
| 1037 | 1040 |
| 1038 static GrFragmentProcessor* Create(GrContext* ctx, | 1041 static sk_sp<GrFragmentProcessor> Make(GrContext* ctx, |
| 1039 const SkTwoPointConicalGradient& shader, | 1042 const SkTwoPointConicalGradient& shad
er, |
| 1040 const SkMatrix& matrix, | 1043 const SkMatrix& matrix, |
| 1041 SkShader::TileMode tm, | 1044 SkShader::TileMode tm, |
| 1042 const CircleConicalInfo& info) { | 1045 const CircleConicalInfo& info) { |
| 1043 return new CircleOutside2PtConicalEffect(ctx, shader, matrix, tm, info); | 1046 return sk_sp<GrFragmentProcessor>( |
| 1047 new CircleOutside2PtConicalEffect(ctx, shader, matrix, tm, info)); |
| 1044 } | 1048 } |
| 1045 | 1049 |
| 1046 virtual ~CircleOutside2PtConicalEffect() {} | 1050 virtual ~CircleOutside2PtConicalEffect() {} |
| 1047 | 1051 |
| 1048 const char* name() const override { return "Two-Point Conical Gradient Outsi
de"; } | 1052 const char* name() const override { return "Two-Point Conical Gradient Outsi
de"; } |
| 1049 | 1053 |
| 1050 SkScalar centerX() const { return fInfo.fCenterEnd.fX; } | 1054 SkScalar centerX() const { return fInfo.fCenterEnd.fX; } |
| 1051 SkScalar centerY() const { return fInfo.fCenterEnd.fY; } | 1055 SkScalar centerY() const { return fInfo.fCenterEnd.fY; } |
| 1052 SkScalar A() const { return fInfo.fA; } | 1056 SkScalar A() const { return fInfo.fA; } |
| 1053 SkScalar B() const { return fInfo.fB; } | 1057 SkScalar B() const { return fInfo.fB; } |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1140 | 1144 |
| 1141 GrGLSLFragmentProcessor* CircleOutside2PtConicalEffect::onCreateGLSLInstance() c
onst { | 1145 GrGLSLFragmentProcessor* CircleOutside2PtConicalEffect::onCreateGLSLInstance() c
onst { |
| 1142 return new GLCircleOutside2PtConicalEffect(*this); | 1146 return new GLCircleOutside2PtConicalEffect(*this); |
| 1143 } | 1147 } |
| 1144 | 1148 |
| 1145 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(CircleOutside2PtConicalEffect); | 1149 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(CircleOutside2PtConicalEffect); |
| 1146 | 1150 |
| 1147 /* | 1151 /* |
| 1148 * All Two point conical gradient test create functions may occasionally create
edge case shaders | 1152 * All Two point conical gradient test create functions may occasionally create
edge case shaders |
| 1149 */ | 1153 */ |
| 1150 const GrFragmentProcessor* CircleOutside2PtConicalEffect::TestCreate(GrProcessor
TestData* d) { | 1154 sk_sp<GrFragmentProcessor> CircleOutside2PtConicalEffect::TestCreate(GrProcessor
TestData* d) { |
| 1151 SkPoint center1 = {d->fRandom->nextUScalar1(), d->fRandom->nextUScalar1()}; | 1155 SkPoint center1 = {d->fRandom->nextUScalar1(), d->fRandom->nextUScalar1()}; |
| 1152 SkScalar radius1 = d->fRandom->nextUScalar1() + 0.0001f; // make sure radius
1 != 0 | 1156 SkScalar radius1 = d->fRandom->nextUScalar1() + 0.0001f; // make sure radius
1 != 0 |
| 1153 SkPoint center2; | 1157 SkPoint center2; |
| 1154 SkScalar radius2; | 1158 SkScalar radius2; |
| 1155 SkScalar diffLen; | 1159 SkScalar diffLen; |
| 1156 do { | 1160 do { |
| 1157 center2.set(d->fRandom->nextUScalar1(), d->fRandom->nextUScalar1()); | 1161 center2.set(d->fRandom->nextUScalar1(), d->fRandom->nextUScalar1()); |
| 1158 // If the circles share a center than we can't be in the outside case | 1162 // If the circles share a center than we can't be in the outside case |
| 1159 } while (center1 == center2); | 1163 } while (center1 == center2); |
| 1160 SkPoint diff = center2 - center1; | 1164 SkPoint diff = center2 - center1; |
| 1161 diffLen = diff.length(); | 1165 diffLen = diff.length(); |
| 1162 // Below makes sure that circle one is not contained within circle two | 1166 // Below makes sure that circle one is not contained within circle two |
| 1163 // and have radius2 >= radius to match sorting on cpu side | 1167 // and have radius2 >= radius to match sorting on cpu side |
| 1164 radius2 = radius1 + d->fRandom->nextRangeF(0.f, diffLen); | 1168 radius2 = radius1 + d->fRandom->nextRangeF(0.f, diffLen); |
| 1165 | 1169 |
| 1166 SkColor colors[kMaxRandomGradientColors]; | 1170 SkColor colors[kMaxRandomGradientColors]; |
| 1167 SkScalar stopsArray[kMaxRandomGradientColors]; | 1171 SkScalar stopsArray[kMaxRandomGradientColors]; |
| 1168 SkScalar* stops = stopsArray; | 1172 SkScalar* stops = stopsArray; |
| 1169 SkShader::TileMode tm; | 1173 SkShader::TileMode tm; |
| 1170 int colorCount = RandomGradientParams(d->fRandom, colors, &stops, &tm); | 1174 int colorCount = RandomGradientParams(d->fRandom, colors, &stops, &tm); |
| 1171 auto shader = SkGradientShader::MakeTwoPointConical(center1, radius1, center
2, radius2, | 1175 auto shader = SkGradientShader::MakeTwoPointConical(center1, radius1, center
2, radius2, |
| 1172 colors, stops, colorCoun
t, tm); | 1176 colors, stops, colorCoun
t, tm); |
| 1173 const GrFragmentProcessor* fp = shader->asFragmentProcessor( | 1177 sk_sp<GrFragmentProcessor> fp = shader->asFragmentProcessor( |
| 1174 d->fContext,GrTest::TestMatrix(d->fRandom), NULL, kNone_SkFilterQuality, | 1178 d->fContext,GrTest::TestMatrix(d->fRandom), NULL, kNone_SkFilterQuality, |
| 1175 SkSourceGammaTreatment::kRespect); | 1179 SkSourceGammaTreatment::kRespect); |
| 1176 GrAlwaysAssert(fp); | 1180 GrAlwaysAssert(fp); |
| 1177 return fp; | 1181 return fp; |
| 1178 } | 1182 } |
| 1179 | 1183 |
| 1180 GLCircleOutside2PtConicalEffect::GLCircleOutside2PtConicalEffect(const GrProcess
or& processor) | 1184 GLCircleOutside2PtConicalEffect::GLCircleOutside2PtConicalEffect(const GrProcess
or& processor) |
| 1181 : fVSVaryingName(nullptr) | 1185 : fVSVaryingName(nullptr) |
| 1182 , fFSVaryingName(nullptr) | 1186 , fFSVaryingName(nullptr) |
| 1183 , fCachedCenterX(SK_ScalarMax) | 1187 , fCachedCenterX(SK_ScalarMax) |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1284 | 1288 |
| 1285 void GLCircleOutside2PtConicalEffect::GenKey(const GrProcessor& processor, | 1289 void GLCircleOutside2PtConicalEffect::GenKey(const GrProcessor& processor, |
| 1286 const GrGLSLCaps&, GrProcessorKeyBu
ilder* b) { | 1290 const GrGLSLCaps&, GrProcessorKeyBu
ilder* b) { |
| 1287 uint32_t* key = b->add32n(2); | 1291 uint32_t* key = b->add32n(2); |
| 1288 key[0] = GenBaseGradientKey(processor); | 1292 key[0] = GenBaseGradientKey(processor); |
| 1289 key[1] = processor.cast<CircleOutside2PtConicalEffect>().isFlipped(); | 1293 key[1] = processor.cast<CircleOutside2PtConicalEffect>().isFlipped(); |
| 1290 } | 1294 } |
| 1291 | 1295 |
| 1292 ////////////////////////////////////////////////////////////////////////////// | 1296 ////////////////////////////////////////////////////////////////////////////// |
| 1293 | 1297 |
| 1294 GrFragmentProcessor* Gr2PtConicalGradientEffect::Create(GrContext* ctx, | 1298 sk_sp<GrFragmentProcessor> Gr2PtConicalGradientEffect::Make(GrContext* ctx, |
| 1295 const SkTwoPointConicalG
radient& shader, | 1299 const SkTwoPointConi
calGradient& shader, |
| 1296 SkShader::TileMode tm, | 1300 SkShader::TileMode t
m, |
| 1297 const SkMatrix* localMat
rix) { | 1301 const SkMatrix* loca
lMatrix) { |
| 1298 SkMatrix matrix; | 1302 SkMatrix matrix; |
| 1299 if (!shader.getLocalMatrix().invert(&matrix)) { | 1303 if (!shader.getLocalMatrix().invert(&matrix)) { |
| 1300 return nullptr; | 1304 return nullptr; |
| 1301 } | 1305 } |
| 1302 if (localMatrix) { | 1306 if (localMatrix) { |
| 1303 SkMatrix inv; | 1307 SkMatrix inv; |
| 1304 if (!localMatrix->invert(&inv)) { | 1308 if (!localMatrix->invert(&inv)) { |
| 1305 return nullptr; | 1309 return nullptr; |
| 1306 } | 1310 } |
| 1307 matrix.postConcat(inv); | 1311 matrix.postConcat(inv); |
| 1308 } | 1312 } |
| 1309 | 1313 |
| 1310 if (shader.getStartRadius() < kErrorTol) { | 1314 if (shader.getStartRadius() < kErrorTol) { |
| 1311 SkScalar focalX; | 1315 SkScalar focalX; |
| 1312 ConicalType type = set_matrix_focal_conical(shader, &matrix, &focalX); | 1316 ConicalType type = set_matrix_focal_conical(shader, &matrix, &focalX); |
| 1313 if (type == kInside_ConicalType) { | 1317 if (type == kInside_ConicalType) { |
| 1314 return FocalInside2PtConicalEffect::Create(ctx, shader, matrix, tm,
focalX); | 1318 return FocalInside2PtConicalEffect::Make(ctx, shader, matrix, tm, fo
calX); |
| 1315 } else if(type == kEdge_ConicalType) { | 1319 } else if(type == kEdge_ConicalType) { |
| 1316 set_matrix_edge_conical(shader, &matrix); | 1320 set_matrix_edge_conical(shader, &matrix); |
| 1317 return Edge2PtConicalEffect::Create(ctx, shader, matrix, tm); | 1321 return Edge2PtConicalEffect::Make(ctx, shader, matrix, tm); |
| 1318 } else { | 1322 } else { |
| 1319 return FocalOutside2PtConicalEffect::Create(ctx, shader, matrix, tm,
focalX); | 1323 return FocalOutside2PtConicalEffect::Make(ctx, shader, matrix, tm, f
ocalX); |
| 1320 } | 1324 } |
| 1321 } | 1325 } |
| 1322 | 1326 |
| 1323 CircleConicalInfo info; | 1327 CircleConicalInfo info; |
| 1324 ConicalType type = set_matrix_circle_conical(shader, &matrix, &info); | 1328 ConicalType type = set_matrix_circle_conical(shader, &matrix, &info); |
| 1325 | 1329 |
| 1326 if (type == kInside_ConicalType) { | 1330 if (type == kInside_ConicalType) { |
| 1327 return CircleInside2PtConicalEffect::Create(ctx, shader, matrix, tm, inf
o); | 1331 return CircleInside2PtConicalEffect::Make(ctx, shader, matrix, tm, info)
; |
| 1328 } else if (type == kEdge_ConicalType) { | 1332 } else if (type == kEdge_ConicalType) { |
| 1329 set_matrix_edge_conical(shader, &matrix); | 1333 set_matrix_edge_conical(shader, &matrix); |
| 1330 return Edge2PtConicalEffect::Create(ctx, shader, matrix, tm); | 1334 return Edge2PtConicalEffect::Make(ctx, shader, matrix, tm); |
| 1331 } else { | 1335 } else { |
| 1332 return CircleOutside2PtConicalEffect::Create(ctx, shader, matrix, tm, in
fo); | 1336 return CircleOutside2PtConicalEffect::Make(ctx, shader, matrix, tm, info
); |
| 1333 } | 1337 } |
| 1334 } | 1338 } |
| 1335 | 1339 |
| 1336 #endif | 1340 #endif |
| OLD | NEW |