OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2012 Google Inc. | 3 * Copyright 2012 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 #include "SkTwoPointRadialGradient.h" | 9 #include "SkTwoPointRadialGradient.h" |
10 | 10 |
(...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
391 | 391 |
392 class GrGLRadial2Gradient : public GrGLGradientEffect { | 392 class GrGLRadial2Gradient : public GrGLGradientEffect { |
393 | 393 |
394 public: | 394 public: |
395 | 395 |
396 GrGLRadial2Gradient(const GrBackendEffectFactory& factory, const GrDrawEffec
t&); | 396 GrGLRadial2Gradient(const GrBackendEffectFactory& factory, const GrDrawEffec
t&); |
397 virtual ~GrGLRadial2Gradient() { } | 397 virtual ~GrGLRadial2Gradient() { } |
398 | 398 |
399 virtual void emitCode(GrGLShaderBuilder*, | 399 virtual void emitCode(GrGLShaderBuilder*, |
400 const GrDrawEffect&, | 400 const GrDrawEffect&, |
401 EffectKey, | 401 const GrEffectKey&, |
402 const char* outputColor, | 402 const char* outputColor, |
403 const char* inputColor, | 403 const char* inputColor, |
404 const TransformedCoordsArray&, | 404 const TransformedCoordsArray&, |
405 const TextureSamplerArray&) SK_OVERRIDE; | 405 const TextureSamplerArray&) SK_OVERRIDE; |
406 virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_OVER
RIDE; | 406 virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_OVER
RIDE; |
407 | 407 |
408 static EffectKey GenKey(const GrDrawEffect&, const GrGLCaps& caps); | 408 static void GenKey(const GrDrawEffect&, const GrGLCaps& caps, GrEffectKeyBui
lder* b); |
409 | 409 |
410 protected: | 410 protected: |
411 | 411 |
412 UniformHandle fParamUni; | 412 UniformHandle fParamUni; |
413 | 413 |
414 const char* fVSVaryingName; | 414 const char* fVSVaryingName; |
415 const char* fFSVaryingName; | 415 const char* fFSVaryingName; |
416 | 416 |
417 bool fIsDegenerate; | 417 bool fIsDegenerate; |
418 | 418 |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
547 , fCachedCenter(SK_ScalarMax) | 547 , fCachedCenter(SK_ScalarMax) |
548 , fCachedRadius(-SK_ScalarMax) | 548 , fCachedRadius(-SK_ScalarMax) |
549 , fCachedPosRoot(0) { | 549 , fCachedPosRoot(0) { |
550 | 550 |
551 const GrRadial2Gradient& data = drawEffect.castEffect<GrRadial2Gradient>(); | 551 const GrRadial2Gradient& data = drawEffect.castEffect<GrRadial2Gradient>(); |
552 fIsDegenerate = data.isDegenerate(); | 552 fIsDegenerate = data.isDegenerate(); |
553 } | 553 } |
554 | 554 |
555 void GrGLRadial2Gradient::emitCode(GrGLShaderBuilder* builder, | 555 void GrGLRadial2Gradient::emitCode(GrGLShaderBuilder* builder, |
556 const GrDrawEffect& drawEffect, | 556 const GrDrawEffect& drawEffect, |
557 EffectKey key, | 557 const GrEffectKey& key, |
558 const char* outputColor, | 558 const char* outputColor, |
559 const char* inputColor, | 559 const char* inputColor, |
560 const TransformedCoordsArray& coords, | 560 const TransformedCoordsArray& coords, |
561 const TextureSamplerArray& samplers) { | 561 const TextureSamplerArray& samplers) { |
562 | 562 uint32_t baseKey = key.get32(0); |
563 this->emitUniforms(builder, key); | 563 this->emitUniforms(builder, baseKey); |
564 fParamUni = builder->addUniformArray(GrGLShaderBuilder::kFragment_Visibility
, | 564 fParamUni = builder->addUniformArray(GrGLShaderBuilder::kFragment_Visibility
, |
565 kFloat_GrSLType, "Radial2FSParams", 6); | 565 kFloat_GrSLType, "Radial2FSParams", 6); |
566 | 566 |
567 SkString cName("c"); | 567 SkString cName("c"); |
568 SkString ac4Name("ac4"); | 568 SkString ac4Name("ac4"); |
569 SkString rootName("root"); | 569 SkString rootName("root"); |
570 SkString t; | 570 SkString t; |
571 SkString p0; | 571 SkString p0; |
572 SkString p1; | 572 SkString p1; |
573 SkString p2; | 573 SkString p2; |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
615 ac4Name.c_str()); | 615 ac4Name.c_str()); |
616 | 616 |
617 // t is: (-b + params[5] * sqrt(b^2-4ac)) * params[1] | 617 // t is: (-b + params[5] * sqrt(b^2-4ac)) * params[1] |
618 t.printf("(-%s + %s * %s) * %s", bVar.c_str(), p5.c_str(), | 618 t.printf("(-%s + %s * %s) * %s", bVar.c_str(), p5.c_str(), |
619 rootName.c_str(), p1.c_str()); | 619 rootName.c_str(), p1.c_str()); |
620 } else { | 620 } else { |
621 // t is: -c/b | 621 // t is: -c/b |
622 t.printf("-%s / %s", cName.c_str(), bVar.c_str()); | 622 t.printf("-%s / %s", cName.c_str(), bVar.c_str()); |
623 } | 623 } |
624 | 624 |
625 this->emitColor(builder, t.c_str(), key, outputColor, inputColor, samplers); | 625 this->emitColor(builder, t.c_str(), baseKey, outputColor, inputColor, sample
rs); |
626 } | 626 } |
627 | 627 |
628 void GrGLRadial2Gradient::setData(const GrGLUniformManager& uman, | 628 void GrGLRadial2Gradient::setData(const GrGLUniformManager& uman, |
629 const GrDrawEffect& drawEffect) { | 629 const GrDrawEffect& drawEffect) { |
630 INHERITED::setData(uman, drawEffect); | 630 INHERITED::setData(uman, drawEffect); |
631 const GrRadial2Gradient& data = drawEffect.castEffect<GrRadial2Gradient>(); | 631 const GrRadial2Gradient& data = drawEffect.castEffect<GrRadial2Gradient>(); |
632 SkASSERT(data.isDegenerate() == fIsDegenerate); | 632 SkASSERT(data.isDegenerate() == fIsDegenerate); |
633 SkScalar centerX1 = data.center(); | 633 SkScalar centerX1 = data.center(); |
634 SkScalar radius0 = data.radius(); | 634 SkScalar radius0 = data.radius(); |
635 if (fCachedCenter != centerX1 || | 635 if (fCachedCenter != centerX1 || |
(...skipping 16 matching lines...) Expand all Loading... |
652 data.isPosRoot() ? 1.f : -1.f | 652 data.isPosRoot() ? 1.f : -1.f |
653 }; | 653 }; |
654 | 654 |
655 uman.set1fv(fParamUni, 6, values); | 655 uman.set1fv(fParamUni, 6, values); |
656 fCachedCenter = centerX1; | 656 fCachedCenter = centerX1; |
657 fCachedRadius = radius0; | 657 fCachedRadius = radius0; |
658 fCachedPosRoot = data.isPosRoot(); | 658 fCachedPosRoot = data.isPosRoot(); |
659 } | 659 } |
660 } | 660 } |
661 | 661 |
662 GrGLEffect::EffectKey GrGLRadial2Gradient::GenKey(const GrDrawEffect& drawEffect
, | 662 void GrGLRadial2Gradient::GenKey(const GrDrawEffect& drawEffect, |
663 const GrGLCaps&) { | 663 const GrGLCaps&, GrEffectKeyBuilder* b) { |
664 enum { | 664 uint32_t* key = b->add32n(2); |
665 kIsDegenerate = 1 << kBaseKeyBitCnt, | 665 key[0] = GenBaseGradientKey(drawEffect); |
666 }; | 666 key[1] = drawEffect.castEffect<GrRadial2Gradient>().isDegenerate(); |
667 | |
668 EffectKey key = GenBaseGradientKey(drawEffect); | |
669 if (drawEffect.castEffect<GrRadial2Gradient>().isDegenerate()) { | |
670 key |= kIsDegenerate; | |
671 } | |
672 return key; | |
673 } | 667 } |
674 | 668 |
675 ///////////////////////////////////////////////////////////////////// | 669 ///////////////////////////////////////////////////////////////////// |
676 | 670 |
677 bool SkTwoPointRadialGradient::asNewEffect(GrContext* context, const SkPaint& pa
int, | 671 bool SkTwoPointRadialGradient::asNewEffect(GrContext* context, const SkPaint& pa
int, |
678 const SkMatrix* localMatrix, GrColor*
paintColor, | 672 const SkMatrix* localMatrix, GrColor*
paintColor, |
679 GrEffect** effect) const { | 673 GrEffect** effect) const { |
680 SkASSERT(NULL != context); | 674 SkASSERT(NULL != context); |
681 | 675 |
682 // invert the localM, translate to center1 (fPtsToUni), rotate so center2 is
on x axis. | 676 // invert the localM, translate to center1 (fPtsToUni), rotate so center2 is
on x axis. |
(...skipping 28 matching lines...) Expand all Loading... |
711 #else | 705 #else |
712 | 706 |
713 bool SkTwoPointRadialGradient::asNewEffect(GrContext* context, const SkPaint& pa
int, | 707 bool SkTwoPointRadialGradient::asNewEffect(GrContext* context, const SkPaint& pa
int, |
714 const SkMatrix* localMatrix, GrColor*
paintColor, | 708 const SkMatrix* localMatrix, GrColor*
paintColor, |
715 GrEffect** effect) const { | 709 GrEffect** effect) const { |
716 SkDEBUGFAIL("Should not call in GPU-less build"); | 710 SkDEBUGFAIL("Should not call in GPU-less build"); |
717 return false; | 711 return false; |
718 } | 712 } |
719 | 713 |
720 #endif | 714 #endif |
OLD | NEW |