OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2014 Google Inc. | 3 * Copyright 2014 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 "SkTwoPointConicalGradient_gpu.h" | 9 #include "SkTwoPointConicalGradient_gpu.h" |
10 | 10 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 rot.setSinCos(-SkScalarMul(invDiffLen, diff.fY), | 52 rot.setSinCos(-SkScalarMul(invDiffLen, diff.fY), |
53 SkScalarMul(invDiffLen, diff.fX)); | 53 SkScalarMul(invDiffLen, diff.fX)); |
54 invLMatrix->postConcat(rot); | 54 invLMatrix->postConcat(rot); |
55 } | 55 } |
56 } | 56 } |
57 | 57 |
58 class Edge2PtConicalEffect : public GrGradientEffect { | 58 class Edge2PtConicalEffect : public GrGradientEffect { |
59 public: | 59 public: |
60 | 60 |
61 static GrFragmentProcessor* Create(GrContext* ctx, | 61 static GrFragmentProcessor* Create(GrContext* ctx, |
62 GrProcessorDataManager* procDataManager, | |
63 const SkTwoPointConicalGradient& shader, | 62 const SkTwoPointConicalGradient& shader, |
64 const SkMatrix& matrix, | 63 const SkMatrix& matrix, |
65 SkShader::TileMode tm) { | 64 SkShader::TileMode tm) { |
66 return new Edge2PtConicalEffect(ctx, procDataManager, shader, matrix, tm
); | 65 return new Edge2PtConicalEffect(ctx, shader, matrix, tm); |
67 } | 66 } |
68 | 67 |
69 virtual ~Edge2PtConicalEffect() {} | 68 virtual ~Edge2PtConicalEffect() {} |
70 | 69 |
71 const char* name() const override { | 70 const char* name() const override { |
72 return "Two-Point Conical Gradient Edge Touching"; | 71 return "Two-Point Conical Gradient Edge Touching"; |
73 } | 72 } |
74 | 73 |
75 // The radial gradient parameters can collapse to a linear (instead of quadr
atic) equation. | 74 // The radial gradient parameters can collapse to a linear (instead of quadr
atic) equation. |
76 SkScalar center() const { return fCenterX1; } | 75 SkScalar center() const { return fCenterX1; } |
77 SkScalar diffRadius() const { return fDiffRadius; } | 76 SkScalar diffRadius() const { return fDiffRadius; } |
78 SkScalar radius() const { return fRadius0; } | 77 SkScalar radius() const { return fRadius0; } |
79 | 78 |
80 private: | 79 private: |
81 GrGLFragmentProcessor* onCreateGLInstance() const override; | 80 GrGLFragmentProcessor* onCreateGLInstance() const override; |
82 | 81 |
83 void onGetGLProcessorKey(const GrGLSLCaps&, GrProcessorKeyBuilder*) const ov
erride; | 82 void onGetGLProcessorKey(const GrGLSLCaps&, GrProcessorKeyBuilder*) const ov
erride; |
84 | 83 |
85 bool onIsEqual(const GrFragmentProcessor& sBase) const override { | 84 bool onIsEqual(const GrFragmentProcessor& sBase) const override { |
86 const Edge2PtConicalEffect& s = sBase.cast<Edge2PtConicalEffect>(); | 85 const Edge2PtConicalEffect& s = sBase.cast<Edge2PtConicalEffect>(); |
87 return (INHERITED::onIsEqual(sBase) && | 86 return (INHERITED::onIsEqual(sBase) && |
88 this->fCenterX1 == s.fCenterX1 && | 87 this->fCenterX1 == s.fCenterX1 && |
89 this->fRadius0 == s.fRadius0 && | 88 this->fRadius0 == s.fRadius0 && |
90 this->fDiffRadius == s.fDiffRadius); | 89 this->fDiffRadius == s.fDiffRadius); |
91 } | 90 } |
92 | 91 |
93 Edge2PtConicalEffect(GrContext* ctx, | 92 Edge2PtConicalEffect(GrContext* ctx, |
94 GrProcessorDataManager* procDataManager, | |
95 const SkTwoPointConicalGradient& shader, | 93 const SkTwoPointConicalGradient& shader, |
96 const SkMatrix& matrix, | 94 const SkMatrix& matrix, |
97 SkShader::TileMode tm) | 95 SkShader::TileMode tm) |
98 : INHERITED(ctx, procDataManager, shader, matrix, tm), | 96 : INHERITED(ctx, shader, matrix, tm), |
99 fCenterX1(shader.getCenterX1()), | 97 fCenterX1(shader.getCenterX1()), |
100 fRadius0(shader.getStartRadius()), | 98 fRadius0(shader.getStartRadius()), |
101 fDiffRadius(shader.getDiffRadius()){ | 99 fDiffRadius(shader.getDiffRadius()){ |
102 this->initClassID<Edge2PtConicalEffect>(); | 100 this->initClassID<Edge2PtConicalEffect>(); |
103 // We should only be calling this shader if we are degenerate case with
touching circles | 101 // We should only be calling this shader if we are degenerate case with
touching circles |
104 // When deciding if we are in edge case, we scaled by the end radius for
cases when the | 102 // When deciding if we are in edge case, we scaled by the end radius for
cases when the |
105 // start radius was close to zero, otherwise we scaled by the start radi
us. In addition | 103 // start radius was close to zero, otherwise we scaled by the start radi
us. In addition |
106 // Our test for the edge case in set_matrix_circle_conical has a higher
tolerance so we | 104 // Our test for the edge case in set_matrix_circle_conical has a higher
tolerance so we |
107 // need the sqrt value below | 105 // need the sqrt value below |
108 SkASSERT(SkScalarAbs(SkScalarAbs(fDiffRadius) - fCenterX1) < | 106 SkASSERT(SkScalarAbs(SkScalarAbs(fDiffRadius) - fCenterX1) < |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 SkColor colors[kMaxRandomGradientColors]; | 201 SkColor colors[kMaxRandomGradientColors]; |
204 SkScalar stopsArray[kMaxRandomGradientColors]; | 202 SkScalar stopsArray[kMaxRandomGradientColors]; |
205 SkScalar* stops = stopsArray; | 203 SkScalar* stops = stopsArray; |
206 SkShader::TileMode tm; | 204 SkShader::TileMode tm; |
207 int colorCount = RandomGradientParams(d->fRandom, colors, &stops, &tm); | 205 int colorCount = RandomGradientParams(d->fRandom, colors, &stops, &tm); |
208 SkAutoTUnref<SkShader> shader(SkGradientShader::CreateTwoPointConical(center
1, radius1, | 206 SkAutoTUnref<SkShader> shader(SkGradientShader::CreateTwoPointConical(center
1, radius1, |
209 center
2, radius2, | 207 center
2, radius2, |
210 colors
, stops, colorCount, | 208 colors
, stops, colorCount, |
211 tm)); | 209 tm)); |
212 const GrFragmentProcessor* fp = shader->asFragmentProcessor(d->fContext, | 210 const GrFragmentProcessor* fp = shader->asFragmentProcessor(d->fContext, |
213 GrTest::TestMatrix(d->fRandom), NULL, kNone_SkFilterQuality, d->fProcDat
aManager); | 211 GrTest::TestMatrix(d->fRandom), NULL, kNone_SkFilterQuality); |
214 GrAlwaysAssert(fp); | 212 GrAlwaysAssert(fp); |
215 return fp; | 213 return fp; |
216 } | 214 } |
217 | 215 |
218 GLEdge2PtConicalEffect::GLEdge2PtConicalEffect(const GrProcessor&) | 216 GLEdge2PtConicalEffect::GLEdge2PtConicalEffect(const GrProcessor&) |
219 : fVSVaryingName(nullptr) | 217 : fVSVaryingName(nullptr) |
220 , fFSVaryingName(nullptr) | 218 , fFSVaryingName(nullptr) |
221 , fCachedRadius(-SK_ScalarMax) | 219 , fCachedRadius(-SK_ScalarMax) |
222 , fCachedDiffRadius(-SK_ScalarMax) {} | 220 , fCachedDiffRadius(-SK_ScalarMax) {} |
223 | 221 |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
361 | 359 |
362 return conicalType; | 360 return conicalType; |
363 } | 361 } |
364 | 362 |
365 ////////////////////////////////////////////////////////////////////////////// | 363 ////////////////////////////////////////////////////////////////////////////// |
366 | 364 |
367 class FocalOutside2PtConicalEffect : public GrGradientEffect { | 365 class FocalOutside2PtConicalEffect : public GrGradientEffect { |
368 public: | 366 public: |
369 | 367 |
370 static GrFragmentProcessor* Create(GrContext* ctx, | 368 static GrFragmentProcessor* Create(GrContext* ctx, |
371 GrProcessorDataManager* procDataManager, | |
372 const SkTwoPointConicalGradient& shader, | 369 const SkTwoPointConicalGradient& shader, |
373 const SkMatrix& matrix, | 370 const SkMatrix& matrix, |
374 SkShader::TileMode tm, | 371 SkShader::TileMode tm, |
375 SkScalar focalX) { | 372 SkScalar focalX) { |
376 return new FocalOutside2PtConicalEffect(ctx, procDataManager, shader, ma
trix, tm, focalX); | 373 return new FocalOutside2PtConicalEffect(ctx, shader, matrix, tm, focalX)
; |
377 } | 374 } |
378 | 375 |
379 virtual ~FocalOutside2PtConicalEffect() { } | 376 virtual ~FocalOutside2PtConicalEffect() { } |
380 | 377 |
381 const char* name() const override { | 378 const char* name() const override { |
382 return "Two-Point Conical Gradient Focal Outside"; | 379 return "Two-Point Conical Gradient Focal Outside"; |
383 } | 380 } |
384 | 381 |
385 bool isFlipped() const { return fIsFlipped; } | 382 bool isFlipped() const { return fIsFlipped; } |
386 SkScalar focal() const { return fFocalX; } | 383 SkScalar focal() const { return fFocalX; } |
387 | 384 |
388 private: | 385 private: |
389 GrGLFragmentProcessor* onCreateGLInstance() const override; | 386 GrGLFragmentProcessor* onCreateGLInstance() const override; |
390 | 387 |
391 void onGetGLProcessorKey(const GrGLSLCaps&, GrProcessorKeyBuilder*) const ov
erride; | 388 void onGetGLProcessorKey(const GrGLSLCaps&, GrProcessorKeyBuilder*) const ov
erride; |
392 | 389 |
393 bool onIsEqual(const GrFragmentProcessor& sBase) const override { | 390 bool onIsEqual(const GrFragmentProcessor& sBase) const override { |
394 const FocalOutside2PtConicalEffect& s = sBase.cast<FocalOutside2PtConica
lEffect>(); | 391 const FocalOutside2PtConicalEffect& s = sBase.cast<FocalOutside2PtConica
lEffect>(); |
395 return (INHERITED::onIsEqual(sBase) && | 392 return (INHERITED::onIsEqual(sBase) && |
396 this->fFocalX == s.fFocalX && | 393 this->fFocalX == s.fFocalX && |
397 this->fIsFlipped == s.fIsFlipped); | 394 this->fIsFlipped == s.fIsFlipped); |
398 } | 395 } |
399 | 396 |
400 FocalOutside2PtConicalEffect(GrContext* ctx, | 397 FocalOutside2PtConicalEffect(GrContext* ctx, |
401 GrProcessorDataManager* procDataManager, | |
402 const SkTwoPointConicalGradient& shader, | 398 const SkTwoPointConicalGradient& shader, |
403 const SkMatrix& matrix, | 399 const SkMatrix& matrix, |
404 SkShader::TileMode tm, | 400 SkShader::TileMode tm, |
405 SkScalar focalX) | 401 SkScalar focalX) |
406 : INHERITED(ctx, procDataManager, shader, matrix, tm) | 402 : INHERITED(ctx, shader, matrix, tm) |
407 , fFocalX(focalX) | 403 , fFocalX(focalX) |
408 , fIsFlipped(shader.isFlippedGrad()) { | 404 , fIsFlipped(shader.isFlippedGrad()) { |
409 this->initClassID<FocalOutside2PtConicalEffect>(); | 405 this->initClassID<FocalOutside2PtConicalEffect>(); |
410 } | 406 } |
411 | 407 |
412 GR_DECLARE_FRAGMENT_PROCESSOR_TEST; | 408 GR_DECLARE_FRAGMENT_PROCESSOR_TEST; |
413 | 409 |
414 SkScalar fFocalX; | 410 SkScalar fFocalX; |
415 bool fIsFlipped; | 411 bool fIsFlipped; |
416 | 412 |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
479 SkColor colors[kMaxRandomGradientColors]; | 475 SkColor colors[kMaxRandomGradientColors]; |
480 SkScalar stopsArray[kMaxRandomGradientColors]; | 476 SkScalar stopsArray[kMaxRandomGradientColors]; |
481 SkScalar* stops = stopsArray; | 477 SkScalar* stops = stopsArray; |
482 SkShader::TileMode tm; | 478 SkShader::TileMode tm; |
483 int colorCount = RandomGradientParams(d->fRandom, colors, &stops, &tm); | 479 int colorCount = RandomGradientParams(d->fRandom, colors, &stops, &tm); |
484 SkAutoTUnref<SkShader> shader(SkGradientShader::CreateTwoPointConical(center
1, radius1, | 480 SkAutoTUnref<SkShader> shader(SkGradientShader::CreateTwoPointConical(center
1, radius1, |
485 center
2, radius2, | 481 center
2, radius2, |
486 colors
, stops, colorCount, | 482 colors
, stops, colorCount, |
487 tm)); | 483 tm)); |
488 const GrFragmentProcessor* fp = shader->asFragmentProcessor(d->fContext, | 484 const GrFragmentProcessor* fp = shader->asFragmentProcessor(d->fContext, |
489 GrTest::TestMatrix(d->fRandom), NULL, kNone_SkFilterQuality, d->fProcDat
aManager); | 485 GrTest::TestMatrix(d->fRandom), NULL, kNone_SkFilterQuality); |
490 GrAlwaysAssert(fp); | 486 GrAlwaysAssert(fp); |
491 return fp; | 487 return fp; |
492 } | 488 } |
493 | 489 |
494 GLFocalOutside2PtConicalEffect::GLFocalOutside2PtConicalEffect(const GrProcessor
& processor) | 490 GLFocalOutside2PtConicalEffect::GLFocalOutside2PtConicalEffect(const GrProcessor
& processor) |
495 : fVSVaryingName(nullptr) | 491 : fVSVaryingName(nullptr) |
496 , fFSVaryingName(nullptr) | 492 , fFSVaryingName(nullptr) |
497 , fCachedFocal(SK_ScalarMax) { | 493 , fCachedFocal(SK_ScalarMax) { |
498 const FocalOutside2PtConicalEffect& data = processor.cast<FocalOutside2PtCon
icalEffect>(); | 494 const FocalOutside2PtConicalEffect& data = processor.cast<FocalOutside2PtCon
icalEffect>(); |
499 fIsFlipped = data.isFlipped(); | 495 fIsFlipped = data.isFlipped(); |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
572 } | 568 } |
573 | 569 |
574 ////////////////////////////////////////////////////////////////////////////// | 570 ////////////////////////////////////////////////////////////////////////////// |
575 | 571 |
576 class GLFocalInside2PtConicalEffect; | 572 class GLFocalInside2PtConicalEffect; |
577 | 573 |
578 class FocalInside2PtConicalEffect : public GrGradientEffect { | 574 class FocalInside2PtConicalEffect : public GrGradientEffect { |
579 public: | 575 public: |
580 | 576 |
581 static GrFragmentProcessor* Create(GrContext* ctx, | 577 static GrFragmentProcessor* Create(GrContext* ctx, |
582 GrProcessorDataManager* procDataManager, | |
583 const SkTwoPointConicalGradient& shader, | 578 const SkTwoPointConicalGradient& shader, |
584 const SkMatrix& matrix, | 579 const SkMatrix& matrix, |
585 SkShader::TileMode tm, | 580 SkShader::TileMode tm, |
586 SkScalar focalX) { | 581 SkScalar focalX) { |
587 return new FocalInside2PtConicalEffect(ctx, procDataManager, shader, mat
rix, tm, focalX); | 582 return new FocalInside2PtConicalEffect(ctx, shader, matrix, tm, focalX); |
588 } | 583 } |
589 | 584 |
590 virtual ~FocalInside2PtConicalEffect() {} | 585 virtual ~FocalInside2PtConicalEffect() {} |
591 | 586 |
592 const char* name() const override { | 587 const char* name() const override { |
593 return "Two-Point Conical Gradient Focal Inside"; | 588 return "Two-Point Conical Gradient Focal Inside"; |
594 } | 589 } |
595 | 590 |
596 SkScalar focal() const { return fFocalX; } | 591 SkScalar focal() const { return fFocalX; } |
597 | 592 |
598 typedef GLFocalInside2PtConicalEffect GLProcessor; | 593 typedef GLFocalInside2PtConicalEffect GLProcessor; |
599 | 594 |
600 private: | 595 private: |
601 GrGLFragmentProcessor* onCreateGLInstance() const override; | 596 GrGLFragmentProcessor* onCreateGLInstance() const override; |
602 | 597 |
603 void onGetGLProcessorKey(const GrGLSLCaps&, GrProcessorKeyBuilder*) const ov
erride; | 598 void onGetGLProcessorKey(const GrGLSLCaps&, GrProcessorKeyBuilder*) const ov
erride; |
604 | 599 |
605 bool onIsEqual(const GrFragmentProcessor& sBase) const override { | 600 bool onIsEqual(const GrFragmentProcessor& sBase) const override { |
606 const FocalInside2PtConicalEffect& s = sBase.cast<FocalInside2PtConicalE
ffect>(); | 601 const FocalInside2PtConicalEffect& s = sBase.cast<FocalInside2PtConicalE
ffect>(); |
607 return (INHERITED::onIsEqual(sBase) && | 602 return (INHERITED::onIsEqual(sBase) && |
608 this->fFocalX == s.fFocalX); | 603 this->fFocalX == s.fFocalX); |
609 } | 604 } |
610 | 605 |
611 FocalInside2PtConicalEffect(GrContext* ctx, | 606 FocalInside2PtConicalEffect(GrContext* ctx, |
612 GrProcessorDataManager* procDataManager, | |
613 const SkTwoPointConicalGradient& shader, | 607 const SkTwoPointConicalGradient& shader, |
614 const SkMatrix& matrix, | 608 const SkMatrix& matrix, |
615 SkShader::TileMode tm, | 609 SkShader::TileMode tm, |
616 SkScalar focalX) | 610 SkScalar focalX) |
617 : INHERITED(ctx, procDataManager, shader, matrix, tm), fFocalX(focalX) { | 611 : INHERITED(ctx, shader, matrix, tm), fFocalX(focalX) { |
618 this->initClassID<FocalInside2PtConicalEffect>(); | 612 this->initClassID<FocalInside2PtConicalEffect>(); |
619 } | 613 } |
620 | 614 |
621 GR_DECLARE_FRAGMENT_PROCESSOR_TEST; | 615 GR_DECLARE_FRAGMENT_PROCESSOR_TEST; |
622 | 616 |
623 SkScalar fFocalX; | 617 SkScalar fFocalX; |
624 | 618 |
625 typedef GrGradientEffect INHERITED; | 619 typedef GrGradientEffect INHERITED; |
626 }; | 620 }; |
627 | 621 |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
687 SkColor colors[kMaxRandomGradientColors]; | 681 SkColor colors[kMaxRandomGradientColors]; |
688 SkScalar stopsArray[kMaxRandomGradientColors]; | 682 SkScalar stopsArray[kMaxRandomGradientColors]; |
689 SkScalar* stops = stopsArray; | 683 SkScalar* stops = stopsArray; |
690 SkShader::TileMode tm; | 684 SkShader::TileMode tm; |
691 int colorCount = RandomGradientParams(d->fRandom, colors, &stops, &tm); | 685 int colorCount = RandomGradientParams(d->fRandom, colors, &stops, &tm); |
692 SkAutoTUnref<SkShader> shader(SkGradientShader::CreateTwoPointConical(center
1, radius1, | 686 SkAutoTUnref<SkShader> shader(SkGradientShader::CreateTwoPointConical(center
1, radius1, |
693 center
2, radius2, | 687 center
2, radius2, |
694 colors
, stops, colorCount, | 688 colors
, stops, colorCount, |
695 tm)); | 689 tm)); |
696 const GrFragmentProcessor* fp = shader->asFragmentProcessor(d->fContext, | 690 const GrFragmentProcessor* fp = shader->asFragmentProcessor(d->fContext, |
697 GrTest::TestMatrix(d->fRandom), NULL, kNone_SkFilterQuality, d->fProcDat
aManager); | 691 GrTest::TestMatrix(d->fRandom), NULL, kNone_SkFilterQuality); |
698 GrAlwaysAssert(fp); | 692 GrAlwaysAssert(fp); |
699 return fp; | 693 return fp; |
700 } | 694 } |
701 | 695 |
702 GLFocalInside2PtConicalEffect::GLFocalInside2PtConicalEffect(const GrProcessor&) | 696 GLFocalInside2PtConicalEffect::GLFocalInside2PtConicalEffect(const GrProcessor&) |
703 : fVSVaryingName(nullptr) | 697 : fVSVaryingName(nullptr) |
704 , fFSVaryingName(nullptr) | 698 , fFSVaryingName(nullptr) |
705 , fCachedFocal(SK_ScalarMax) {} | 699 , fCachedFocal(SK_ScalarMax) {} |
706 | 700 |
707 void GLFocalInside2PtConicalEffect::emitCode(EmitArgs& args) { | 701 void GLFocalInside2PtConicalEffect::emitCode(EmitArgs& args) { |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
807 if (A < 0.f) { | 801 if (A < 0.f) { |
808 return kInside_ConicalType; | 802 return kInside_ConicalType; |
809 } | 803 } |
810 return kOutside_ConicalType; | 804 return kOutside_ConicalType; |
811 } | 805 } |
812 | 806 |
813 class CircleInside2PtConicalEffect : public GrGradientEffect { | 807 class CircleInside2PtConicalEffect : public GrGradientEffect { |
814 public: | 808 public: |
815 | 809 |
816 static GrFragmentProcessor* Create(GrContext* ctx, | 810 static GrFragmentProcessor* Create(GrContext* ctx, |
817 GrProcessorDataManager* procDataManager, | |
818 const SkTwoPointConicalGradient& shader, | 811 const SkTwoPointConicalGradient& shader, |
819 const SkMatrix& matrix, | 812 const SkMatrix& matrix, |
820 SkShader::TileMode tm, | 813 SkShader::TileMode tm, |
821 const CircleConicalInfo& info) { | 814 const CircleConicalInfo& info) { |
822 return new CircleInside2PtConicalEffect(ctx, procDataManager, shader, ma
trix, tm, info); | 815 return new CircleInside2PtConicalEffect(ctx, shader, matrix, tm, info); |
823 } | 816 } |
824 | 817 |
825 virtual ~CircleInside2PtConicalEffect() {} | 818 virtual ~CircleInside2PtConicalEffect() {} |
826 | 819 |
827 const char* name() const override { return "Two-Point Conical Gradient Insid
e"; } | 820 const char* name() const override { return "Two-Point Conical Gradient Insid
e"; } |
828 | 821 |
829 SkScalar centerX() const { return fInfo.fCenterEnd.fX; } | 822 SkScalar centerX() const { return fInfo.fCenterEnd.fX; } |
830 SkScalar centerY() const { return fInfo.fCenterEnd.fY; } | 823 SkScalar centerY() const { return fInfo.fCenterEnd.fY; } |
831 SkScalar A() const { return fInfo.fA; } | 824 SkScalar A() const { return fInfo.fA; } |
832 SkScalar B() const { return fInfo.fB; } | 825 SkScalar B() const { return fInfo.fB; } |
833 SkScalar C() const { return fInfo.fC; } | 826 SkScalar C() const { return fInfo.fC; } |
834 | 827 |
835 private: | 828 private: |
836 GrGLFragmentProcessor* onCreateGLInstance() const override; | 829 GrGLFragmentProcessor* onCreateGLInstance() const override; |
837 | 830 |
838 virtual void onGetGLProcessorKey(const GrGLSLCaps& caps, | 831 virtual void onGetGLProcessorKey(const GrGLSLCaps& caps, |
839 GrProcessorKeyBuilder* b) const override; | 832 GrProcessorKeyBuilder* b) const override; |
840 | 833 |
841 bool onIsEqual(const GrFragmentProcessor& sBase) const override { | 834 bool onIsEqual(const GrFragmentProcessor& sBase) const override { |
842 const CircleInside2PtConicalEffect& s = sBase.cast<CircleInside2PtConica
lEffect>(); | 835 const CircleInside2PtConicalEffect& s = sBase.cast<CircleInside2PtConica
lEffect>(); |
843 return (INHERITED::onIsEqual(sBase) && | 836 return (INHERITED::onIsEqual(sBase) && |
844 this->fInfo.fCenterEnd == s.fInfo.fCenterEnd && | 837 this->fInfo.fCenterEnd == s.fInfo.fCenterEnd && |
845 this->fInfo.fA == s.fInfo.fA && | 838 this->fInfo.fA == s.fInfo.fA && |
846 this->fInfo.fB == s.fInfo.fB && | 839 this->fInfo.fB == s.fInfo.fB && |
847 this->fInfo.fC == s.fInfo.fC); | 840 this->fInfo.fC == s.fInfo.fC); |
848 } | 841 } |
849 | 842 |
850 CircleInside2PtConicalEffect(GrContext* ctx, | 843 CircleInside2PtConicalEffect(GrContext* ctx, |
851 GrProcessorDataManager* procDataManager, | |
852 const SkTwoPointConicalGradient& shader, | 844 const SkTwoPointConicalGradient& shader, |
853 const SkMatrix& matrix, | 845 const SkMatrix& matrix, |
854 SkShader::TileMode tm, | 846 SkShader::TileMode tm, |
855 const CircleConicalInfo& info) | 847 const CircleConicalInfo& info) |
856 : INHERITED(ctx, procDataManager, shader, matrix, tm), fInfo(info) { | 848 : INHERITED(ctx, shader, matrix, tm), fInfo(info) { |
857 this->initClassID<CircleInside2PtConicalEffect>(); | 849 this->initClassID<CircleInside2PtConicalEffect>(); |
858 } | 850 } |
859 | 851 |
860 GR_DECLARE_FRAGMENT_PROCESSOR_TEST; | 852 GR_DECLARE_FRAGMENT_PROCESSOR_TEST; |
861 | 853 |
862 const CircleConicalInfo fInfo; | 854 const CircleConicalInfo fInfo; |
863 | 855 |
864 typedef GrGradientEffect INHERITED; | 856 typedef GrGradientEffect INHERITED; |
865 }; | 857 }; |
866 | 858 |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
930 SkColor colors[kMaxRandomGradientColors]; | 922 SkColor colors[kMaxRandomGradientColors]; |
931 SkScalar stopsArray[kMaxRandomGradientColors]; | 923 SkScalar stopsArray[kMaxRandomGradientColors]; |
932 SkScalar* stops = stopsArray; | 924 SkScalar* stops = stopsArray; |
933 SkShader::TileMode tm; | 925 SkShader::TileMode tm; |
934 int colorCount = RandomGradientParams(d->fRandom, colors, &stops, &tm); | 926 int colorCount = RandomGradientParams(d->fRandom, colors, &stops, &tm); |
935 SkAutoTUnref<SkShader> shader(SkGradientShader::CreateTwoPointConical(center
1, radius1, | 927 SkAutoTUnref<SkShader> shader(SkGradientShader::CreateTwoPointConical(center
1, radius1, |
936 center
2, radius2, | 928 center
2, radius2, |
937 colors
, stops, colorCount, | 929 colors
, stops, colorCount, |
938 tm)); | 930 tm)); |
939 const GrFragmentProcessor* fp = shader->asFragmentProcessor(d->fContext, | 931 const GrFragmentProcessor* fp = shader->asFragmentProcessor(d->fContext, |
940 GrTest::TestMatrix(d->fRandom), NULL, kNone_SkFilterQuality, d->fProcDat
aManager); | 932 GrTest::TestMatrix(d->fRandom), NULL, kNone_SkFilterQuality); |
941 GrAlwaysAssert(fp); | 933 GrAlwaysAssert(fp); |
942 return fp; | 934 return fp; |
943 } | 935 } |
944 | 936 |
945 GLCircleInside2PtConicalEffect::GLCircleInside2PtConicalEffect(const GrProcessor
& processor) | 937 GLCircleInside2PtConicalEffect::GLCircleInside2PtConicalEffect(const GrProcessor
& processor) |
946 : fVSVaryingName(nullptr) | 938 : fVSVaryingName(nullptr) |
947 , fFSVaryingName(nullptr) | 939 , fFSVaryingName(nullptr) |
948 , fCachedCenterX(SK_ScalarMax) | 940 , fCachedCenterX(SK_ScalarMax) |
949 , fCachedCenterY(SK_ScalarMax) | 941 , fCachedCenterY(SK_ScalarMax) |
950 , fCachedA(SK_ScalarMax) | 942 , fCachedA(SK_ScalarMax) |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1019 const GrGLSLCaps&, GrProcessorKeyBui
lder* b) { | 1011 const GrGLSLCaps&, GrProcessorKeyBui
lder* b) { |
1020 b->add32(GenBaseGradientKey(processor)); | 1012 b->add32(GenBaseGradientKey(processor)); |
1021 } | 1013 } |
1022 | 1014 |
1023 ////////////////////////////////////////////////////////////////////////////// | 1015 ////////////////////////////////////////////////////////////////////////////// |
1024 | 1016 |
1025 class CircleOutside2PtConicalEffect : public GrGradientEffect { | 1017 class CircleOutside2PtConicalEffect : public GrGradientEffect { |
1026 public: | 1018 public: |
1027 | 1019 |
1028 static GrFragmentProcessor* Create(GrContext* ctx, | 1020 static GrFragmentProcessor* Create(GrContext* ctx, |
1029 GrProcessorDataManager* procDataManager, | |
1030 const SkTwoPointConicalGradient& shader, | 1021 const SkTwoPointConicalGradient& shader, |
1031 const SkMatrix& matrix, | 1022 const SkMatrix& matrix, |
1032 SkShader::TileMode tm, | 1023 SkShader::TileMode tm, |
1033 const CircleConicalInfo& info) { | 1024 const CircleConicalInfo& info) { |
1034 return new CircleOutside2PtConicalEffect(ctx, procDataManager, shader, m
atrix, tm, info); | 1025 return new CircleOutside2PtConicalEffect(ctx, shader, matrix, tm, info); |
1035 } | 1026 } |
1036 | 1027 |
1037 virtual ~CircleOutside2PtConicalEffect() {} | 1028 virtual ~CircleOutside2PtConicalEffect() {} |
1038 | 1029 |
1039 const char* name() const override { return "Two-Point Conical Gradient Outsi
de"; } | 1030 const char* name() const override { return "Two-Point Conical Gradient Outsi
de"; } |
1040 | 1031 |
1041 SkScalar centerX() const { return fInfo.fCenterEnd.fX; } | 1032 SkScalar centerX() const { return fInfo.fCenterEnd.fX; } |
1042 SkScalar centerY() const { return fInfo.fCenterEnd.fY; } | 1033 SkScalar centerY() const { return fInfo.fCenterEnd.fY; } |
1043 SkScalar A() const { return fInfo.fA; } | 1034 SkScalar A() const { return fInfo.fA; } |
1044 SkScalar B() const { return fInfo.fB; } | 1035 SkScalar B() const { return fInfo.fB; } |
(...skipping 11 matching lines...) Expand all Loading... |
1056 return (INHERITED::onIsEqual(sBase) && | 1047 return (INHERITED::onIsEqual(sBase) && |
1057 this->fInfo.fCenterEnd == s.fInfo.fCenterEnd && | 1048 this->fInfo.fCenterEnd == s.fInfo.fCenterEnd && |
1058 this->fInfo.fA == s.fInfo.fA && | 1049 this->fInfo.fA == s.fInfo.fA && |
1059 this->fInfo.fB == s.fInfo.fB && | 1050 this->fInfo.fB == s.fInfo.fB && |
1060 this->fInfo.fC == s.fInfo.fC && | 1051 this->fInfo.fC == s.fInfo.fC && |
1061 this->fTLimit == s.fTLimit && | 1052 this->fTLimit == s.fTLimit && |
1062 this->fIsFlipped == s.fIsFlipped); | 1053 this->fIsFlipped == s.fIsFlipped); |
1063 } | 1054 } |
1064 | 1055 |
1065 CircleOutside2PtConicalEffect(GrContext* ctx, | 1056 CircleOutside2PtConicalEffect(GrContext* ctx, |
1066 GrProcessorDataManager* procDataManager, | |
1067 const SkTwoPointConicalGradient& shader, | 1057 const SkTwoPointConicalGradient& shader, |
1068 const SkMatrix& matrix, | 1058 const SkMatrix& matrix, |
1069 SkShader::TileMode tm, | 1059 SkShader::TileMode tm, |
1070 const CircleConicalInfo& info) | 1060 const CircleConicalInfo& info) |
1071 : INHERITED(ctx, procDataManager, shader, matrix, tm), fInfo(info) { | 1061 : INHERITED(ctx, shader, matrix, tm), fInfo(info) { |
1072 this->initClassID<CircleOutside2PtConicalEffect>(); | 1062 this->initClassID<CircleOutside2PtConicalEffect>(); |
1073 if (shader.getStartRadius() != shader.getEndRadius()) { | 1063 if (shader.getStartRadius() != shader.getEndRadius()) { |
1074 fTLimit = shader.getStartRadius() / (shader.getStartRadius() - shade
r.getEndRadius()); | 1064 fTLimit = shader.getStartRadius() / (shader.getStartRadius() - shade
r.getEndRadius()); |
1075 } else { | 1065 } else { |
1076 fTLimit = SK_ScalarMin; | 1066 fTLimit = SK_ScalarMin; |
1077 } | 1067 } |
1078 | 1068 |
1079 fIsFlipped = shader.isFlippedGrad(); | 1069 fIsFlipped = shader.isFlippedGrad(); |
1080 } | 1070 } |
1081 | 1071 |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1158 SkColor colors[kMaxRandomGradientColors]; | 1148 SkColor colors[kMaxRandomGradientColors]; |
1159 SkScalar stopsArray[kMaxRandomGradientColors]; | 1149 SkScalar stopsArray[kMaxRandomGradientColors]; |
1160 SkScalar* stops = stopsArray; | 1150 SkScalar* stops = stopsArray; |
1161 SkShader::TileMode tm; | 1151 SkShader::TileMode tm; |
1162 int colorCount = RandomGradientParams(d->fRandom, colors, &stops, &tm); | 1152 int colorCount = RandomGradientParams(d->fRandom, colors, &stops, &tm); |
1163 SkAutoTUnref<SkShader> shader(SkGradientShader::CreateTwoPointConical(center
1, radius1, | 1153 SkAutoTUnref<SkShader> shader(SkGradientShader::CreateTwoPointConical(center
1, radius1, |
1164 center
2, radius2, | 1154 center
2, radius2, |
1165 colors
, stops, colorCount, | 1155 colors
, stops, colorCount, |
1166 tm)); | 1156 tm)); |
1167 const GrFragmentProcessor* fp = shader->asFragmentProcessor( | 1157 const GrFragmentProcessor* fp = shader->asFragmentProcessor( |
1168 d->fContext,GrTest::TestMatrix(d->fRandom), NULL, kNone_SkFilterQuality, | 1158 d->fContext,GrTest::TestMatrix(d->fRandom), NULL, kNone_SkFilterQuality)
; |
1169 d->fProcDataManager); | |
1170 GrAlwaysAssert(fp); | 1159 GrAlwaysAssert(fp); |
1171 return fp; | 1160 return fp; |
1172 } | 1161 } |
1173 | 1162 |
1174 GLCircleOutside2PtConicalEffect::GLCircleOutside2PtConicalEffect(const GrProcess
or& processor) | 1163 GLCircleOutside2PtConicalEffect::GLCircleOutside2PtConicalEffect(const GrProcess
or& processor) |
1175 : fVSVaryingName(nullptr) | 1164 : fVSVaryingName(nullptr) |
1176 , fFSVaryingName(nullptr) | 1165 , fFSVaryingName(nullptr) |
1177 , fCachedCenterX(SK_ScalarMax) | 1166 , fCachedCenterX(SK_ScalarMax) |
1178 , fCachedCenterY(SK_ScalarMax) | 1167 , fCachedCenterY(SK_ScalarMax) |
1179 , fCachedA(SK_ScalarMax) | 1168 , fCachedA(SK_ScalarMax) |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1271 void GLCircleOutside2PtConicalEffect::GenKey(const GrProcessor& processor, | 1260 void GLCircleOutside2PtConicalEffect::GenKey(const GrProcessor& processor, |
1272 const GrGLSLCaps&, GrProcessorKeyBu
ilder* b) { | 1261 const GrGLSLCaps&, GrProcessorKeyBu
ilder* b) { |
1273 uint32_t* key = b->add32n(2); | 1262 uint32_t* key = b->add32n(2); |
1274 key[0] = GenBaseGradientKey(processor); | 1263 key[0] = GenBaseGradientKey(processor); |
1275 key[1] = processor.cast<CircleOutside2PtConicalEffect>().isFlipped(); | 1264 key[1] = processor.cast<CircleOutside2PtConicalEffect>().isFlipped(); |
1276 } | 1265 } |
1277 | 1266 |
1278 ////////////////////////////////////////////////////////////////////////////// | 1267 ////////////////////////////////////////////////////////////////////////////// |
1279 | 1268 |
1280 GrFragmentProcessor* Gr2PtConicalGradientEffect::Create(GrContext* ctx, | 1269 GrFragmentProcessor* Gr2PtConicalGradientEffect::Create(GrContext* ctx, |
1281 GrProcessorDataManager*
procDataManager, | |
1282 const SkTwoPointConicalG
radient& shader, | 1270 const SkTwoPointConicalG
radient& shader, |
1283 SkShader::TileMode tm, | 1271 SkShader::TileMode tm, |
1284 const SkMatrix* localMat
rix) { | 1272 const SkMatrix* localMat
rix) { |
1285 SkMatrix matrix; | 1273 SkMatrix matrix; |
1286 if (!shader.getLocalMatrix().invert(&matrix)) { | 1274 if (!shader.getLocalMatrix().invert(&matrix)) { |
1287 return nullptr; | 1275 return nullptr; |
1288 } | 1276 } |
1289 if (localMatrix) { | 1277 if (localMatrix) { |
1290 SkMatrix inv; | 1278 SkMatrix inv; |
1291 if (!localMatrix->invert(&inv)) { | 1279 if (!localMatrix->invert(&inv)) { |
1292 return nullptr; | 1280 return nullptr; |
1293 } | 1281 } |
1294 matrix.postConcat(inv); | 1282 matrix.postConcat(inv); |
1295 } | 1283 } |
1296 | 1284 |
1297 if (shader.getStartRadius() < kErrorTol) { | 1285 if (shader.getStartRadius() < kErrorTol) { |
1298 SkScalar focalX; | 1286 SkScalar focalX; |
1299 ConicalType type = set_matrix_focal_conical(shader, &matrix, &focalX); | 1287 ConicalType type = set_matrix_focal_conical(shader, &matrix, &focalX); |
1300 if (type == kInside_ConicalType) { | 1288 if (type == kInside_ConicalType) { |
1301 return FocalInside2PtConicalEffect::Create(ctx, procDataManager, sha
der, matrix, tm, | 1289 return FocalInside2PtConicalEffect::Create(ctx, shader, matrix, tm,
focalX); |
1302 focalX); | |
1303 } else if(type == kEdge_ConicalType) { | 1290 } else if(type == kEdge_ConicalType) { |
1304 set_matrix_edge_conical(shader, &matrix); | 1291 set_matrix_edge_conical(shader, &matrix); |
1305 return Edge2PtConicalEffect::Create(ctx, procDataManager, shader, ma
trix, tm); | 1292 return Edge2PtConicalEffect::Create(ctx, shader, matrix, tm); |
1306 } else { | 1293 } else { |
1307 return FocalOutside2PtConicalEffect::Create(ctx, procDataManager, sh
ader, matrix, tm, | 1294 return FocalOutside2PtConicalEffect::Create(ctx, shader, matrix, tm,
focalX); |
1308 focalX); | |
1309 } | 1295 } |
1310 } | 1296 } |
1311 | 1297 |
1312 CircleConicalInfo info; | 1298 CircleConicalInfo info; |
1313 ConicalType type = set_matrix_circle_conical(shader, &matrix, &info); | 1299 ConicalType type = set_matrix_circle_conical(shader, &matrix, &info); |
1314 | 1300 |
1315 if (type == kInside_ConicalType) { | 1301 if (type == kInside_ConicalType) { |
1316 return CircleInside2PtConicalEffect::Create(ctx, procDataManager, shade
r, matrix, tm, | 1302 return CircleInside2PtConicalEffect::Create(ctx, shader, matrix, tm, inf
o); |
1317 info); | |
1318 } else if (type == kEdge_ConicalType) { | 1303 } else if (type == kEdge_ConicalType) { |
1319 set_matrix_edge_conical(shader, &matrix); | 1304 set_matrix_edge_conical(shader, &matrix); |
1320 return Edge2PtConicalEffect::Create(ctx, procDataManager, shader, matrix
, tm); | 1305 return Edge2PtConicalEffect::Create(ctx, shader, matrix, tm); |
1321 } else { | 1306 } else { |
1322 return CircleOutside2PtConicalEffect::Create(ctx, procDataManager, shade
r, matrix, tm, | 1307 return CircleOutside2PtConicalEffect::Create(ctx, shader, matrix, tm, in
fo); |
1323 info); | |
1324 } | 1308 } |
1325 } | 1309 } |
1326 | 1310 |
1327 #endif | 1311 #endif |
OLD | NEW |