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 SkScalarMul(invDiffLen, diff.fX)); | 52 SkScalarMul(invDiffLen, diff.fX)); |
53 invLMatrix->postConcat(rot); | 53 invLMatrix->postConcat(rot); |
54 } | 54 } |
55 } | 55 } |
56 | 56 |
57 class GLEdge2PtConicalEffect; | 57 class GLEdge2PtConicalEffect; |
58 | 58 |
59 class Edge2PtConicalEffect : public GrGradientEffect { | 59 class Edge2PtConicalEffect : public GrGradientEffect { |
60 public: | 60 public: |
61 | 61 |
62 static GrEffectRef* Create(GrContext* ctx, | 62 static GrEffect* Create(GrContext* ctx, |
63 const SkTwoPointConicalGradient& shader, | 63 const SkTwoPointConicalGradient& shader, |
64 const SkMatrix& matrix, | 64 const SkMatrix& matrix, |
65 SkShader::TileMode tm) { | 65 SkShader::TileMode tm) { |
66 return SkNEW_ARGS(Edge2PtConicalEffect, (ctx, shader, matrix, tm)); | 66 return SkNEW_ARGS(Edge2PtConicalEffect, (ctx, shader, matrix, tm)); |
67 } | 67 } |
68 | 68 |
69 virtual ~Edge2PtConicalEffect() {} | 69 virtual ~Edge2PtConicalEffect() {} |
70 | 70 |
71 static const char* Name() { return "Two-Point Conical Gradient Edge Touching
"; } | 71 static const char* Name() { return "Two-Point Conical Gradient Edge Touching
"; } |
72 virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE; | 72 virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE; |
73 | 73 |
74 // 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. |
75 SkScalar center() const { return fCenterX1; } | 75 SkScalar center() const { return fCenterX1; } |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 typedef GrGLGradientEffect INHERITED; | 165 typedef GrGLGradientEffect INHERITED; |
166 | 166 |
167 }; | 167 }; |
168 | 168 |
169 const GrBackendEffectFactory& Edge2PtConicalEffect::getFactory() const { | 169 const GrBackendEffectFactory& Edge2PtConicalEffect::getFactory() const { |
170 return GrTBackendEffectFactory<Edge2PtConicalEffect>::getInstance(); | 170 return GrTBackendEffectFactory<Edge2PtConicalEffect>::getInstance(); |
171 } | 171 } |
172 | 172 |
173 GR_DEFINE_EFFECT_TEST(Edge2PtConicalEffect); | 173 GR_DEFINE_EFFECT_TEST(Edge2PtConicalEffect); |
174 | 174 |
175 GrEffectRef* Edge2PtConicalEffect::TestCreate(SkRandom* random, | 175 GrEffect* Edge2PtConicalEffect::TestCreate(SkRandom* random, |
176 GrContext* context, | 176 GrContext* context, |
177 const GrDrawTargetCaps&, | 177 const GrDrawTargetCaps&, |
178 GrTexture**) { | 178 GrTexture**) { |
179 SkPoint center1 = {random->nextUScalar1(), random->nextUScalar1()}; | 179 SkPoint center1 = {random->nextUScalar1(), random->nextUScalar1()}; |
180 SkScalar radius1 = random->nextUScalar1(); | 180 SkScalar radius1 = random->nextUScalar1(); |
181 SkPoint center2; | 181 SkPoint center2; |
182 SkScalar radius2; | 182 SkScalar radius2; |
183 do { | 183 do { |
184 center2.set(random->nextUScalar1(), random->nextUScalar1()); | 184 center2.set(random->nextUScalar1(), random->nextUScalar1()); |
185 // If the circles are identical the factory will give us an empty shader
. | 185 // If the circles are identical the factory will give us an empty shader
. |
186 // This will happen if we pick identical centers | 186 // This will happen if we pick identical centers |
187 } while (center1 == center2); | 187 } while (center1 == center2); |
188 | 188 |
189 // Below makes sure that circle one is contained within circle two | 189 // Below makes sure that circle one is contained within circle two |
190 // and both circles are touching on an edge | 190 // and both circles are touching on an edge |
191 SkPoint diff = center2 - center1; | 191 SkPoint diff = center2 - center1; |
192 SkScalar diffLen = diff.length(); | 192 SkScalar diffLen = diff.length(); |
193 radius2 = radius1 + diffLen; | 193 radius2 = radius1 + diffLen; |
194 | 194 |
195 SkColor colors[kMaxRandomGradientColors]; | 195 SkColor colors[kMaxRandomGradientColors]; |
196 SkScalar stopsArray[kMaxRandomGradientColors]; | 196 SkScalar stopsArray[kMaxRandomGradientColors]; |
197 SkScalar* stops = stopsArray; | 197 SkScalar* stops = stopsArray; |
198 SkShader::TileMode tm; | 198 SkShader::TileMode tm; |
199 int colorCount = RandomGradientParams(random, colors, &stops, &tm); | 199 int colorCount = RandomGradientParams(random, colors, &stops, &tm); |
200 SkAutoTUnref<SkShader> shader(SkGradientShader::CreateTwoPointConical(center
1, radius1, | 200 SkAutoTUnref<SkShader> shader(SkGradientShader::CreateTwoPointConical(center
1, radius1, |
201 center
2, radius2, | 201 center
2, radius2, |
202 colors
, stops, colorCount, | 202 colors
, stops, colorCount, |
203 tm)); | 203 tm)); |
204 SkPaint paint; | 204 SkPaint paint; |
205 GrEffectRef* effect; | 205 GrEffect* effect; |
206 GrColor grColor; | 206 GrColor paintColor; |
207 shader->asNewEffect(context, paint, NULL, &grColor, &effect); | 207 SkAssertResult(shader->asNewEffect(context, paint, NULL, &paintColor, &effec
t)); |
208 return effect; | 208 return effect; |
209 } | 209 } |
210 | 210 |
211 GLEdge2PtConicalEffect::GLEdge2PtConicalEffect(const GrBackendEffectFactory& fac
tory, | 211 GLEdge2PtConicalEffect::GLEdge2PtConicalEffect(const GrBackendEffectFactory& fac
tory, |
212 const GrDrawEffect& drawEffect) | 212 const GrDrawEffect& drawEffect) |
213 : INHERITED(factory) | 213 : INHERITED(factory) |
214 , fVSVaryingName(NULL) | 214 , fVSVaryingName(NULL) |
215 , fFSVaryingName(NULL) | 215 , fFSVaryingName(NULL) |
216 , fCachedRadius(-SK_ScalarMax) | 216 , fCachedRadius(-SK_ScalarMax) |
217 , fCachedDiffRadius(-SK_ScalarMax) {} | 217 , fCachedDiffRadius(-SK_ScalarMax) {} |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
358 return conicalType; | 358 return conicalType; |
359 } | 359 } |
360 | 360 |
361 ////////////////////////////////////////////////////////////////////////////// | 361 ////////////////////////////////////////////////////////////////////////////// |
362 | 362 |
363 class GLFocalOutside2PtConicalEffect; | 363 class GLFocalOutside2PtConicalEffect; |
364 | 364 |
365 class FocalOutside2PtConicalEffect : public GrGradientEffect { | 365 class FocalOutside2PtConicalEffect : public GrGradientEffect { |
366 public: | 366 public: |
367 | 367 |
368 static GrEffectRef* Create(GrContext* ctx, | 368 static GrEffect* Create(GrContext* ctx, |
369 const SkTwoPointConicalGradient& shader, | 369 const SkTwoPointConicalGradient& shader, |
370 const SkMatrix& matrix, | 370 const SkMatrix& matrix, |
371 SkShader::TileMode tm, | 371 SkShader::TileMode tm, |
372 SkScalar focalX) { | 372 SkScalar focalX) { |
373 return SkNEW_ARGS(FocalOutside2PtConicalEffect, (ctx, shader, matrix, tm
, focalX)); | 373 return SkNEW_ARGS(FocalOutside2PtConicalEffect, (ctx, shader, matrix, tm
, focalX)); |
374 } | 374 } |
375 | 375 |
376 virtual ~FocalOutside2PtConicalEffect() { } | 376 virtual ~FocalOutside2PtConicalEffect() { } |
377 | 377 |
378 static const char* Name() { return "Two-Point Conical Gradient Focal Outside
"; } | 378 static const char* Name() { return "Two-Point Conical Gradient Focal Outside
"; } |
379 virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE; | 379 virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE; |
380 | 380 |
381 bool isFlipped() const { return fIsFlipped; } | 381 bool isFlipped() const { return fIsFlipped; } |
382 SkScalar focal() const { return fFocalX; } | 382 SkScalar focal() const { return fFocalX; } |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
441 typedef GrGLGradientEffect INHERITED; | 441 typedef GrGLGradientEffect INHERITED; |
442 | 442 |
443 }; | 443 }; |
444 | 444 |
445 const GrBackendEffectFactory& FocalOutside2PtConicalEffect::getFactory() const { | 445 const GrBackendEffectFactory& FocalOutside2PtConicalEffect::getFactory() const { |
446 return GrTBackendEffectFactory<FocalOutside2PtConicalEffect>::getInstance(); | 446 return GrTBackendEffectFactory<FocalOutside2PtConicalEffect>::getInstance(); |
447 } | 447 } |
448 | 448 |
449 GR_DEFINE_EFFECT_TEST(FocalOutside2PtConicalEffect); | 449 GR_DEFINE_EFFECT_TEST(FocalOutside2PtConicalEffect); |
450 | 450 |
451 GrEffectRef* FocalOutside2PtConicalEffect::TestCreate(SkRandom* random, | 451 GrEffect* FocalOutside2PtConicalEffect::TestCreate(SkRandom* random, |
452 GrContext* context, | 452 GrContext* context, |
453 const GrDrawTargetCaps&, | 453 const GrDrawTargetCaps&, |
454 GrTexture**) { | 454 GrTexture**) { |
455 SkPoint center1 = {random->nextUScalar1(), random->nextUScalar1()}; | 455 SkPoint center1 = {random->nextUScalar1(), random->nextUScalar1()}; |
456 SkScalar radius1 = 0.f; | 456 SkScalar radius1 = 0.f; |
457 SkPoint center2; | 457 SkPoint center2; |
458 SkScalar radius2; | 458 SkScalar radius2; |
459 do { | 459 do { |
460 center2.set(random->nextUScalar1(), random->nextUScalar1()); | 460 center2.set(random->nextUScalar1(), random->nextUScalar1()); |
461 // Need to make sure the centers are not the same or else focal point wi
ll be inside | 461 // Need to make sure the centers are not the same or else focal point wi
ll be inside |
462 } while (center1 == center2); | 462 } while (center1 == center2); |
463 SkPoint diff = center2 - center1; | 463 SkPoint diff = center2 - center1; |
464 SkScalar diffLen = diff.length(); | 464 SkScalar diffLen = diff.length(); |
465 // Below makes sure that the focal point is not contained within circle
two | 465 // Below makes sure that the focal point is not contained within circle
two |
466 radius2 = random->nextRangeF(0.f, diffLen); | 466 radius2 = random->nextRangeF(0.f, diffLen); |
467 | 467 |
468 SkColor colors[kMaxRandomGradientColors]; | 468 SkColor colors[kMaxRandomGradientColors]; |
469 SkScalar stopsArray[kMaxRandomGradientColors]; | 469 SkScalar stopsArray[kMaxRandomGradientColors]; |
470 SkScalar* stops = stopsArray; | 470 SkScalar* stops = stopsArray; |
471 SkShader::TileMode tm; | 471 SkShader::TileMode tm; |
472 int colorCount = RandomGradientParams(random, colors, &stops, &tm); | 472 int colorCount = RandomGradientParams(random, colors, &stops, &tm); |
473 SkAutoTUnref<SkShader> shader(SkGradientShader::CreateTwoPointConical(center
1, radius1, | 473 SkAutoTUnref<SkShader> shader(SkGradientShader::CreateTwoPointConical(center
1, radius1, |
474 center
2, radius2, | 474 center
2, radius2, |
475 colors
, stops, colorCount, | 475 colors
, stops, colorCount, |
476 tm)); | 476 tm)); |
477 SkPaint paint; | 477 SkPaint paint; |
478 GrEffectRef* effect; | 478 GrEffect* effect; |
479 GrColor grColor; | 479 GrColor paintColor; |
480 shader->asNewEffect(context, paint, NULL, &grColor, &effect); | 480 SkAssertResult(shader->asNewEffect(context, paint, NULL, &paintColor, &effec
t)); |
481 return effect; | 481 return effect; |
482 } | 482 } |
483 | 483 |
484 GLFocalOutside2PtConicalEffect::GLFocalOutside2PtConicalEffect(const GrBackendEf
fectFactory& factory, | 484 GLFocalOutside2PtConicalEffect::GLFocalOutside2PtConicalEffect(const GrBackendEf
fectFactory& factory, |
485 const GrDrawEffec
t& drawEffect) | 485 const GrDrawEffec
t& drawEffect) |
486 : INHERITED(factory) | 486 : INHERITED(factory) |
487 , fVSVaryingName(NULL) | 487 , fVSVaryingName(NULL) |
488 , fFSVaryingName(NULL) | 488 , fFSVaryingName(NULL) |
489 , fCachedFocal(SK_ScalarMax) { | 489 , fCachedFocal(SK_ScalarMax) { |
490 const FocalOutside2PtConicalEffect& data = drawEffect.castEffect<FocalOutsid
e2PtConicalEffect>(); | 490 const FocalOutside2PtConicalEffect& data = drawEffect.castEffect<FocalOutsid
e2PtConicalEffect>(); |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
572 return key; | 572 return key; |
573 } | 573 } |
574 | 574 |
575 ////////////////////////////////////////////////////////////////////////////// | 575 ////////////////////////////////////////////////////////////////////////////// |
576 | 576 |
577 class GLFocalInside2PtConicalEffect; | 577 class GLFocalInside2PtConicalEffect; |
578 | 578 |
579 class FocalInside2PtConicalEffect : public GrGradientEffect { | 579 class FocalInside2PtConicalEffect : public GrGradientEffect { |
580 public: | 580 public: |
581 | 581 |
582 static GrEffectRef* Create(GrContext* ctx, | 582 static GrEffect* Create(GrContext* ctx, |
583 const SkTwoPointConicalGradient& shader, | 583 const SkTwoPointConicalGradient& shader, |
584 const SkMatrix& matrix, | 584 const SkMatrix& matrix, |
585 SkShader::TileMode tm, | 585 SkShader::TileMode tm, |
586 SkScalar focalX) { | 586 SkScalar focalX) { |
587 return SkNEW_ARGS(FocalInside2PtConicalEffect, (ctx, shader, matrix, tm,
focalX)); | 587 return SkNEW_ARGS(FocalInside2PtConicalEffect, (ctx, shader, matrix, tm,
focalX)); |
588 } | 588 } |
589 | 589 |
590 virtual ~FocalInside2PtConicalEffect() {} | 590 virtual ~FocalInside2PtConicalEffect() {} |
591 | 591 |
592 static const char* Name() { return "Two-Point Conical Gradient Focal Inside"
; } | 592 static const char* Name() { return "Two-Point Conical Gradient Focal Inside"
; } |
593 virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE; | 593 virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE; |
594 | 594 |
595 SkScalar focal() const { return fFocalX; } | 595 SkScalar focal() const { return fFocalX; } |
596 | 596 |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
650 typedef GrGLGradientEffect INHERITED; | 650 typedef GrGLGradientEffect INHERITED; |
651 | 651 |
652 }; | 652 }; |
653 | 653 |
654 const GrBackendEffectFactory& FocalInside2PtConicalEffect::getFactory() const { | 654 const GrBackendEffectFactory& FocalInside2PtConicalEffect::getFactory() const { |
655 return GrTBackendEffectFactory<FocalInside2PtConicalEffect>::getInstance(); | 655 return GrTBackendEffectFactory<FocalInside2PtConicalEffect>::getInstance(); |
656 } | 656 } |
657 | 657 |
658 GR_DEFINE_EFFECT_TEST(FocalInside2PtConicalEffect); | 658 GR_DEFINE_EFFECT_TEST(FocalInside2PtConicalEffect); |
659 | 659 |
660 GrEffectRef* FocalInside2PtConicalEffect::TestCreate(SkRandom* random, | 660 GrEffect* FocalInside2PtConicalEffect::TestCreate(SkRandom* random, |
661 GrContext* context, | 661 GrContext* context, |
662 const GrDrawTargetCaps&, | 662 const GrDrawTargetCaps&, |
663 GrTexture**) { | 663 GrTexture**) { |
664 SkPoint center1 = {random->nextUScalar1(), random->nextUScalar1()}; | 664 SkPoint center1 = {random->nextUScalar1(), random->nextUScalar1()}; |
665 SkScalar radius1 = 0.f; | 665 SkScalar radius1 = 0.f; |
666 SkPoint center2; | 666 SkPoint center2; |
667 SkScalar radius2; | 667 SkScalar radius2; |
668 do { | 668 do { |
669 center2.set(random->nextUScalar1(), random->nextUScalar1()); | 669 center2.set(random->nextUScalar1(), random->nextUScalar1()); |
670 // Below makes sure radius2 is larger enouch such that the focal point | 670 // Below makes sure radius2 is larger enouch such that the focal point |
671 // is inside the end circle | 671 // is inside the end circle |
672 SkScalar increase = random->nextUScalar1(); | 672 SkScalar increase = random->nextUScalar1(); |
673 SkPoint diff = center2 - center1; | 673 SkPoint diff = center2 - center1; |
674 SkScalar diffLen = diff.length(); | 674 SkScalar diffLen = diff.length(); |
675 radius2 = diffLen + increase; | 675 radius2 = diffLen + increase; |
676 // If the circles are identical the factory will give us an empty shader
. | 676 // If the circles are identical the factory will give us an empty shader
. |
677 } while (radius1 == radius2 && center1 == center2); | 677 } while (radius1 == radius2 && center1 == center2); |
678 | 678 |
679 SkColor colors[kMaxRandomGradientColors]; | 679 SkColor colors[kMaxRandomGradientColors]; |
680 SkScalar stopsArray[kMaxRandomGradientColors]; | 680 SkScalar stopsArray[kMaxRandomGradientColors]; |
681 SkScalar* stops = stopsArray; | 681 SkScalar* stops = stopsArray; |
682 SkShader::TileMode tm; | 682 SkShader::TileMode tm; |
683 int colorCount = RandomGradientParams(random, colors, &stops, &tm); | 683 int colorCount = RandomGradientParams(random, colors, &stops, &tm); |
684 SkAutoTUnref<SkShader> shader(SkGradientShader::CreateTwoPointConical(center
1, radius1, | 684 SkAutoTUnref<SkShader> shader(SkGradientShader::CreateTwoPointConical(center
1, radius1, |
685 center
2, radius2, | 685 center
2, radius2, |
686 colors
, stops, colorCount, | 686 colors
, stops, colorCount, |
687 tm)); | 687 tm)); |
688 SkPaint paint; | 688 SkPaint paint; |
689 GrColor grColor; | 689 GrColor paintColor; |
690 GrEffectRef* grEffect; | 690 GrEffect* effect; |
691 shader->asNewEffect(context, paint, NULL, &grColor, &grEffect); | 691 SkAssertResult(shader->asNewEffect(context, paint, NULL, &paintColor, &effec
t)); |
692 return grEffect; | 692 return effect; |
693 } | 693 } |
694 | 694 |
695 GLFocalInside2PtConicalEffect::GLFocalInside2PtConicalEffect(const GrBackendEffe
ctFactory& factory, | 695 GLFocalInside2PtConicalEffect::GLFocalInside2PtConicalEffect(const GrBackendEffe
ctFactory& factory, |
696 const GrDrawEffect&
drawEffect) | 696 const GrDrawEffect&
drawEffect) |
697 : INHERITED(factory) | 697 : INHERITED(factory) |
698 , fVSVaryingName(NULL) | 698 , fVSVaryingName(NULL) |
699 , fFSVaryingName(NULL) | 699 , fFSVaryingName(NULL) |
700 , fCachedFocal(SK_ScalarMax) {} | 700 , fCachedFocal(SK_ScalarMax) {} |
701 | 701 |
702 void GLFocalInside2PtConicalEffect::emitCode(GrGLShaderBuilder* builder, | 702 void GLFocalInside2PtConicalEffect::emitCode(GrGLShaderBuilder* builder, |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
805 return kInside_ConicalType; | 805 return kInside_ConicalType; |
806 } | 806 } |
807 return kOutside_ConicalType; | 807 return kOutside_ConicalType; |
808 } | 808 } |
809 | 809 |
810 class GLCircleInside2PtConicalEffect; | 810 class GLCircleInside2PtConicalEffect; |
811 | 811 |
812 class CircleInside2PtConicalEffect : public GrGradientEffect { | 812 class CircleInside2PtConicalEffect : public GrGradientEffect { |
813 public: | 813 public: |
814 | 814 |
815 static GrEffectRef* Create(GrContext* ctx, | 815 static GrEffect* Create(GrContext* ctx, |
816 const SkTwoPointConicalGradient& shader, | 816 const SkTwoPointConicalGradient& shader, |
817 const SkMatrix& matrix, | 817 const SkMatrix& matrix, |
818 SkShader::TileMode tm, | 818 SkShader::TileMode tm, |
819 const CircleConicalInfo& info) { | 819 const CircleConicalInfo& info) { |
820 return SkNEW_ARGS(CircleInside2PtConicalEffect, (ctx, shader, matrix, tm
, info)); | 820 return SkNEW_ARGS(CircleInside2PtConicalEffect, (ctx, shader, matrix, tm
, info)); |
821 } | 821 } |
822 | 822 |
823 virtual ~CircleInside2PtConicalEffect() {} | 823 virtual ~CircleInside2PtConicalEffect() {} |
824 | 824 |
825 static const char* Name() { return "Two-Point Conical Gradient Inside"; } | 825 static const char* Name() { return "Two-Point Conical Gradient Inside"; } |
826 virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE; | 826 virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE; |
827 | 827 |
828 SkScalar centerX() const { return fInfo.fCenterEnd.fX; } | 828 SkScalar centerX() const { return fInfo.fCenterEnd.fX; } |
829 SkScalar centerY() const { return fInfo.fCenterEnd.fY; } | 829 SkScalar centerY() const { return fInfo.fCenterEnd.fY; } |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
895 typedef GrGLGradientEffect INHERITED; | 895 typedef GrGLGradientEffect INHERITED; |
896 | 896 |
897 }; | 897 }; |
898 | 898 |
899 const GrBackendEffectFactory& CircleInside2PtConicalEffect::getFactory() const { | 899 const GrBackendEffectFactory& CircleInside2PtConicalEffect::getFactory() const { |
900 return GrTBackendEffectFactory<CircleInside2PtConicalEffect>::getInstance(); | 900 return GrTBackendEffectFactory<CircleInside2PtConicalEffect>::getInstance(); |
901 } | 901 } |
902 | 902 |
903 GR_DEFINE_EFFECT_TEST(CircleInside2PtConicalEffect); | 903 GR_DEFINE_EFFECT_TEST(CircleInside2PtConicalEffect); |
904 | 904 |
905 GrEffectRef* CircleInside2PtConicalEffect::TestCreate(SkRandom* random, | 905 GrEffect* CircleInside2PtConicalEffect::TestCreate(SkRandom* random, |
906 GrContext* context, | 906 GrContext* context, |
907 const GrDrawTargetCaps&, | 907 const GrDrawTargetCaps&, |
908 GrTexture**) { | 908 GrTexture**) { |
909 SkPoint center1 = {random->nextUScalar1(), random->nextUScalar1()}; | 909 SkPoint center1 = {random->nextUScalar1(), random->nextUScalar1()}; |
910 SkScalar radius1 = random->nextUScalar1() + 0.0001f; // make sure radius1 !=
0 | 910 SkScalar radius1 = random->nextUScalar1() + 0.0001f; // make sure radius1 !=
0 |
911 SkPoint center2; | 911 SkPoint center2; |
912 SkScalar radius2; | 912 SkScalar radius2; |
913 do { | 913 do { |
914 center2.set(random->nextUScalar1(), random->nextUScalar1()); | 914 center2.set(random->nextUScalar1(), random->nextUScalar1()); |
915 // Below makes sure that circle one is contained within circle two | 915 // Below makes sure that circle one is contained within circle two |
916 SkScalar increase = random->nextUScalar1(); | 916 SkScalar increase = random->nextUScalar1(); |
917 SkPoint diff = center2 - center1; | 917 SkPoint diff = center2 - center1; |
918 SkScalar diffLen = diff.length(); | 918 SkScalar diffLen = diff.length(); |
919 radius2 = radius1 + diffLen + increase; | 919 radius2 = radius1 + diffLen + increase; |
920 // If the circles are identical the factory will give us an empty shader
. | 920 // If the circles are identical the factory will give us an empty shader
. |
921 } while (radius1 == radius2 && center1 == center2); | 921 } while (radius1 == radius2 && center1 == center2); |
922 | 922 |
923 SkColor colors[kMaxRandomGradientColors]; | 923 SkColor colors[kMaxRandomGradientColors]; |
924 SkScalar stopsArray[kMaxRandomGradientColors]; | 924 SkScalar stopsArray[kMaxRandomGradientColors]; |
925 SkScalar* stops = stopsArray; | 925 SkScalar* stops = stopsArray; |
926 SkShader::TileMode tm; | 926 SkShader::TileMode tm; |
927 int colorCount = RandomGradientParams(random, colors, &stops, &tm); | 927 int colorCount = RandomGradientParams(random, colors, &stops, &tm); |
928 SkAutoTUnref<SkShader> shader(SkGradientShader::CreateTwoPointConical(center
1, radius1, | 928 SkAutoTUnref<SkShader> shader(SkGradientShader::CreateTwoPointConical(center
1, radius1, |
929 center
2, radius2, | 929 center
2, radius2, |
930 colors
, stops, colorCount, | 930 colors
, stops, colorCount, |
931 tm)); | 931 tm)); |
932 SkPaint paint; | 932 SkPaint paint; |
933 GrColor grColor; | 933 GrColor paintColor; |
934 GrEffectRef* grEffect; | 934 GrEffect* effect; |
935 shader->asNewEffect(context, paint, NULL, &grColor, &grEffect); | 935 SkAssertResult(shader->asNewEffect(context, paint, NULL, &paintColor, &effec
t)); |
936 return grEffect; | 936 return effect; |
937 } | 937 } |
938 | 938 |
939 GLCircleInside2PtConicalEffect::GLCircleInside2PtConicalEffect(const GrBackendEf
fectFactory& factory, | 939 GLCircleInside2PtConicalEffect::GLCircleInside2PtConicalEffect(const GrBackendEf
fectFactory& factory, |
940 const GrDrawEffec
t& drawEffect) | 940 const GrDrawEffec
t& drawEffect) |
941 : INHERITED(factory) | 941 : INHERITED(factory) |
942 , fVSVaryingName(NULL) | 942 , fVSVaryingName(NULL) |
943 , fFSVaryingName(NULL) | 943 , fFSVaryingName(NULL) |
944 , fCachedCenterX(SK_ScalarMax) | 944 , fCachedCenterX(SK_ScalarMax) |
945 , fCachedCenterY(SK_ScalarMax) | 945 , fCachedCenterY(SK_ScalarMax) |
946 , fCachedA(SK_ScalarMax) | 946 , fCachedA(SK_ScalarMax) |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1017 return key; | 1017 return key; |
1018 } | 1018 } |
1019 | 1019 |
1020 ////////////////////////////////////////////////////////////////////////////// | 1020 ////////////////////////////////////////////////////////////////////////////// |
1021 | 1021 |
1022 class GLCircleOutside2PtConicalEffect; | 1022 class GLCircleOutside2PtConicalEffect; |
1023 | 1023 |
1024 class CircleOutside2PtConicalEffect : public GrGradientEffect { | 1024 class CircleOutside2PtConicalEffect : public GrGradientEffect { |
1025 public: | 1025 public: |
1026 | 1026 |
1027 static GrEffectRef* Create(GrContext* ctx, | 1027 static GrEffect* Create(GrContext* ctx, |
1028 const SkTwoPointConicalGradient& shader, | 1028 const SkTwoPointConicalGradient& shader, |
1029 const SkMatrix& matrix, | 1029 const SkMatrix& matrix, |
1030 SkShader::TileMode tm, | 1030 SkShader::TileMode tm, |
1031 const CircleConicalInfo& info) { | 1031 const CircleConicalInfo& info) { |
1032 return SkNEW_ARGS(CircleOutside2PtConicalEffect, (ctx, shader, matrix, t
m, info)); | 1032 return SkNEW_ARGS(CircleOutside2PtConicalEffect, (ctx, shader, matrix, t
m, info)); |
1033 } | 1033 } |
1034 | 1034 |
1035 virtual ~CircleOutside2PtConicalEffect() {} | 1035 virtual ~CircleOutside2PtConicalEffect() {} |
1036 | 1036 |
1037 static const char* Name() { return "Two-Point Conical Gradient Outside"; } | 1037 static const char* Name() { return "Two-Point Conical Gradient Outside"; } |
1038 virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE; | 1038 virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE; |
1039 | 1039 |
1040 SkScalar centerX() const { return fInfo.fCenterEnd.fX; } | 1040 SkScalar centerX() const { return fInfo.fCenterEnd.fX; } |
1041 SkScalar centerY() const { return fInfo.fCenterEnd.fY; } | 1041 SkScalar centerY() const { return fInfo.fCenterEnd.fY; } |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1124 typedef GrGLGradientEffect INHERITED; | 1124 typedef GrGLGradientEffect INHERITED; |
1125 | 1125 |
1126 }; | 1126 }; |
1127 | 1127 |
1128 const GrBackendEffectFactory& CircleOutside2PtConicalEffect::getFactory() const
{ | 1128 const GrBackendEffectFactory& CircleOutside2PtConicalEffect::getFactory() const
{ |
1129 return GrTBackendEffectFactory<CircleOutside2PtConicalEffect>::getInstance()
; | 1129 return GrTBackendEffectFactory<CircleOutside2PtConicalEffect>::getInstance()
; |
1130 } | 1130 } |
1131 | 1131 |
1132 GR_DEFINE_EFFECT_TEST(CircleOutside2PtConicalEffect); | 1132 GR_DEFINE_EFFECT_TEST(CircleOutside2PtConicalEffect); |
1133 | 1133 |
1134 GrEffectRef* CircleOutside2PtConicalEffect::TestCreate(SkRandom* random, | 1134 GrEffect* CircleOutside2PtConicalEffect::TestCreate(SkRandom* random, |
1135 GrContext* context, | 1135 GrContext* context, |
1136 const GrDrawTargetCaps&, | 1136 const GrDrawTargetCaps&, |
1137 GrTexture**) { | 1137 GrTexture**) { |
1138 SkPoint center1 = {random->nextUScalar1(), random->nextUScalar1()}; | 1138 SkPoint center1 = {random->nextUScalar1(), random->nextUScalar1()}; |
1139 SkScalar radius1 = random->nextUScalar1() + 0.0001f; // make sure radius1 !=
0 | 1139 SkScalar radius1 = random->nextUScalar1() + 0.0001f; // make sure radius1 !=
0 |
1140 SkPoint center2; | 1140 SkPoint center2; |
1141 SkScalar radius2; | 1141 SkScalar radius2; |
1142 SkScalar diffLen; | 1142 SkScalar diffLen; |
1143 do { | 1143 do { |
1144 center2.set(random->nextUScalar1(), random->nextUScalar1()); | 1144 center2.set(random->nextUScalar1(), random->nextUScalar1()); |
1145 // If the circles share a center than we can't be in the outside case | 1145 // If the circles share a center than we can't be in the outside case |
1146 } while (center1 == center2); | 1146 } while (center1 == center2); |
1147 SkPoint diff = center2 - center1; | 1147 SkPoint diff = center2 - center1; |
1148 diffLen = diff.length(); | 1148 diffLen = diff.length(); |
1149 // Below makes sure that circle one is not contained within circle two | 1149 // Below makes sure that circle one is not contained within circle two |
1150 // and have radius2 >= radius to match sorting on cpu side | 1150 // and have radius2 >= radius to match sorting on cpu side |
1151 radius2 = radius1 + random->nextRangeF(0.f, diffLen); | 1151 radius2 = radius1 + random->nextRangeF(0.f, diffLen); |
1152 | 1152 |
1153 SkColor colors[kMaxRandomGradientColors]; | 1153 SkColor colors[kMaxRandomGradientColors]; |
1154 SkScalar stopsArray[kMaxRandomGradientColors]; | 1154 SkScalar stopsArray[kMaxRandomGradientColors]; |
1155 SkScalar* stops = stopsArray; | 1155 SkScalar* stops = stopsArray; |
1156 SkShader::TileMode tm; | 1156 SkShader::TileMode tm; |
1157 int colorCount = RandomGradientParams(random, colors, &stops, &tm); | 1157 int colorCount = RandomGradientParams(random, colors, &stops, &tm); |
1158 SkAutoTUnref<SkShader> shader(SkGradientShader::CreateTwoPointConical(center
1, radius1, | 1158 SkAutoTUnref<SkShader> shader(SkGradientShader::CreateTwoPointConical(center
1, radius1, |
1159 center
2, radius2, | 1159 center
2, radius2, |
1160 colors
, stops, colorCount, | 1160 colors
, stops, colorCount, |
1161 tm)); | 1161 tm)); |
1162 SkPaint paint; | 1162 SkPaint paint; |
1163 GrColor grColor; | 1163 GrColor paintColor; |
1164 GrEffectRef* grEffect; | 1164 GrEffect* effect; |
1165 shader->asNewEffect(context, paint, NULL, &grColor, &grEffect); | 1165 SkAssertResult(shader->asNewEffect(context, paint, NULL, &paintColor, &effec
t)); |
1166 return grEffect; | 1166 return effect; |
1167 } | 1167 } |
1168 | 1168 |
1169 GLCircleOutside2PtConicalEffect::GLCircleOutside2PtConicalEffect(const GrBackend
EffectFactory& factory, | 1169 GLCircleOutside2PtConicalEffect::GLCircleOutside2PtConicalEffect(const GrBackend
EffectFactory& factory, |
1170 const GrDrawEff
ect& drawEffect) | 1170 const GrDrawEff
ect& drawEffect) |
1171 : INHERITED(factory) | 1171 : INHERITED(factory) |
1172 , fVSVaryingName(NULL) | 1172 , fVSVaryingName(NULL) |
1173 , fFSVaryingName(NULL) | 1173 , fFSVaryingName(NULL) |
1174 , fCachedCenterX(SK_ScalarMax) | 1174 , fCachedCenterX(SK_ScalarMax) |
1175 , fCachedCenterY(SK_ScalarMax) | 1175 , fCachedCenterY(SK_ScalarMax) |
1176 , fCachedA(SK_ScalarMax) | 1176 , fCachedA(SK_ScalarMax) |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1273 EffectKey key = GenBaseGradientKey(drawEffect); | 1273 EffectKey key = GenBaseGradientKey(drawEffect); |
1274 | 1274 |
1275 if (drawEffect.castEffect<CircleOutside2PtConicalEffect>().isFlipped()) { | 1275 if (drawEffect.castEffect<CircleOutside2PtConicalEffect>().isFlipped()) { |
1276 key |= kIsFlipped; | 1276 key |= kIsFlipped; |
1277 } | 1277 } |
1278 return key; | 1278 return key; |
1279 } | 1279 } |
1280 | 1280 |
1281 ////////////////////////////////////////////////////////////////////////////// | 1281 ////////////////////////////////////////////////////////////////////////////// |
1282 | 1282 |
1283 GrEffectRef* Gr2PtConicalGradientEffect::Create(GrContext* ctx, | 1283 GrEffect* Gr2PtConicalGradientEffect::Create(GrContext* ctx, |
1284 const SkTwoPointConicalGradient&
shader, | 1284 const SkTwoPointConicalGradient& sh
ader, |
1285 SkShader::TileMode tm, | 1285 SkShader::TileMode tm, |
1286 const SkMatrix* localMatrix) { | 1286 const SkMatrix* localMatrix) { |
1287 SkMatrix matrix; | 1287 SkMatrix matrix; |
1288 if (!shader.getLocalMatrix().invert(&matrix)) { | 1288 if (!shader.getLocalMatrix().invert(&matrix)) { |
1289 return NULL; | 1289 return NULL; |
1290 } | 1290 } |
1291 if (localMatrix) { | 1291 if (localMatrix) { |
1292 SkMatrix inv; | 1292 SkMatrix inv; |
1293 if (!localMatrix->invert(&inv)) { | 1293 if (!localMatrix->invert(&inv)) { |
1294 return NULL; | 1294 return NULL; |
1295 } | 1295 } |
1296 matrix.postConcat(inv); | 1296 matrix.postConcat(inv); |
(...skipping 19 matching lines...) Expand all Loading... |
1316 return CircleInside2PtConicalEffect::Create(ctx, shader, matrix, tm, inf
o); | 1316 return CircleInside2PtConicalEffect::Create(ctx, shader, matrix, tm, inf
o); |
1317 } else if (type == kEdge_ConicalType) { | 1317 } else if (type == kEdge_ConicalType) { |
1318 set_matrix_edge_conical(shader, &matrix); | 1318 set_matrix_edge_conical(shader, &matrix); |
1319 return Edge2PtConicalEffect::Create(ctx, shader, matrix, tm); | 1319 return Edge2PtConicalEffect::Create(ctx, shader, matrix, tm); |
1320 } else { | 1320 } else { |
1321 return CircleOutside2PtConicalEffect::Create(ctx, shader, matrix, tm, in
fo); | 1321 return CircleOutside2PtConicalEffect::Create(ctx, shader, matrix, tm, in
fo); |
1322 } | 1322 } |
1323 } | 1323 } |
1324 | 1324 |
1325 #endif | 1325 #endif |
OLD | NEW |