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 366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
377 #include "GrTBackendEffectFactory.h" | 377 #include "GrTBackendEffectFactory.h" |
378 | 378 |
379 // For brevity | 379 // For brevity |
380 typedef GrGLUniformManager::UniformHandle UniformHandle; | 380 typedef GrGLUniformManager::UniformHandle UniformHandle; |
381 static const UniformHandle kInvalidUniformHandle = GrGLUniformManager::kInvalidU
niformHandle; | 381 static const UniformHandle kInvalidUniformHandle = GrGLUniformManager::kInvalidU
niformHandle; |
382 | 382 |
383 class GrGLRadial2Gradient : public GrGLGradientEffect { | 383 class GrGLRadial2Gradient : public GrGLGradientEffect { |
384 | 384 |
385 public: | 385 public: |
386 | 386 |
387 GrGLRadial2Gradient(const GrBackendEffectFactory& factory, const GrEffectRef
&); | 387 GrGLRadial2Gradient(const GrBackendEffectFactory& factory, const GrDrawEffec
t&); |
388 virtual ~GrGLRadial2Gradient() { } | 388 virtual ~GrGLRadial2Gradient() { } |
389 | 389 |
390 virtual void emitCode(GrGLShaderBuilder*, | 390 virtual void emitCode(GrGLShaderBuilder*, |
391 const GrEffectStage&, | 391 const GrDrawEffect&, |
392 EffectKey, | 392 EffectKey, |
393 const char* vertexCoords, | |
394 const char* outputColor, | 393 const char* outputColor, |
395 const char* inputColor, | 394 const char* inputColor, |
396 const TextureSamplerArray&) SK_OVERRIDE; | 395 const TextureSamplerArray&) SK_OVERRIDE; |
397 virtual void setData(const GrGLUniformManager&, const GrEffectStage&) SK_OVE
RRIDE; | 396 virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_OVER
RIDE; |
398 | 397 |
399 static EffectKey GenKey(const GrEffectStage&, const GrGLCaps& caps); | 398 static EffectKey GenKey(const GrDrawEffect&, const GrGLCaps& caps); |
400 | 399 |
401 protected: | 400 protected: |
402 | 401 |
403 UniformHandle fVSParamUni; | 402 UniformHandle fVSParamUni; |
404 UniformHandle fFSParamUni; | 403 UniformHandle fFSParamUni; |
405 | 404 |
406 const char* fVSVaryingName; | 405 const char* fVSVaryingName; |
407 const char* fFSVaryingName; | 406 const char* fFSVaryingName; |
408 | 407 |
409 bool fIsDegenerate; | 408 bool fIsDegenerate; |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
509 center2
, radius2, | 508 center2
, radius2, |
510 colors,
stops, colorCount, | 509 colors,
stops, colorCount, |
511 tm)); | 510 tm)); |
512 SkPaint paint; | 511 SkPaint paint; |
513 return shader->asNewEffect(context, paint); | 512 return shader->asNewEffect(context, paint); |
514 } | 513 } |
515 | 514 |
516 ///////////////////////////////////////////////////////////////////// | 515 ///////////////////////////////////////////////////////////////////// |
517 | 516 |
518 GrGLRadial2Gradient::GrGLRadial2Gradient(const GrBackendEffectFactory& factory, | 517 GrGLRadial2Gradient::GrGLRadial2Gradient(const GrBackendEffectFactory& factory, |
519 const GrEffectRef& baseData) | 518 const GrDrawEffect& drawEffect) |
520 : INHERITED(factory) | 519 : INHERITED(factory) |
521 , fVSParamUni(kInvalidUniformHandle) | 520 , fVSParamUni(kInvalidUniformHandle) |
522 , fFSParamUni(kInvalidUniformHandle) | 521 , fFSParamUni(kInvalidUniformHandle) |
523 , fVSVaryingName(NULL) | 522 , fVSVaryingName(NULL) |
524 , fFSVaryingName(NULL) | 523 , fFSVaryingName(NULL) |
525 , fCachedCenter(SK_ScalarMax) | 524 , fCachedCenter(SK_ScalarMax) |
526 , fCachedRadius(-SK_ScalarMax) | 525 , fCachedRadius(-SK_ScalarMax) |
527 , fCachedPosRoot(0) { | 526 , fCachedPosRoot(0) { |
528 | 527 |
529 const GrRadial2Gradient& data = CastEffect<GrRadial2Gradient>(baseData); | 528 const GrRadial2Gradient& data = drawEffect.castEffect<GrRadial2Gradient>(); |
530 fIsDegenerate = data.isDegenerate(); | 529 fIsDegenerate = data.isDegenerate(); |
531 } | 530 } |
532 | 531 |
533 void GrGLRadial2Gradient::emitCode(GrGLShaderBuilder* builder, | 532 void GrGLRadial2Gradient::emitCode(GrGLShaderBuilder* builder, |
534 const GrEffectStage&, | 533 const GrDrawEffect& drawEffect, |
535 EffectKey key, | 534 EffectKey key, |
536 const char* vertexCoords, | |
537 const char* outputColor, | 535 const char* outputColor, |
538 const char* inputColor, | 536 const char* inputColor, |
539 const TextureSamplerArray& samplers) { | 537 const TextureSamplerArray& samplers) { |
540 | 538 |
541 this->emitYCoordUniform(builder); | 539 this->emitYCoordUniform(builder); |
542 const char* fsCoords; | 540 const char* fsCoords; |
543 const char* vsCoordsVarying; | 541 const char* vsCoordsVarying; |
544 GrSLType coordsVaryingType; | 542 GrSLType coordsVaryingType; |
545 this->setupMatrix(builder, key, vertexCoords, &fsCoords, &vsCoordsVarying, &
coordsVaryingType); | 543 this->setupMatrix(builder, key, &fsCoords, &vsCoordsVarying, &coordsVaryingT
ype); |
546 | 544 |
547 // 2 copies of uniform array, 1 for each of vertex & fragment shader, | 545 // 2 copies of uniform array, 1 for each of vertex & fragment shader, |
548 // to work around Xoom bug. Doesn't seem to cause performance decrease | 546 // to work around Xoom bug. Doesn't seem to cause performance decrease |
549 // in test apps, but need to keep an eye on it. | 547 // in test apps, but need to keep an eye on it. |
550 fVSParamUni = builder->addUniformArray(GrGLShaderBuilder::kVertex_ShaderType
, | 548 fVSParamUni = builder->addUniformArray(GrGLShaderBuilder::kVertex_ShaderType
, |
551 kFloat_GrSLType, "Radial2VSParams", 6
); | 549 kFloat_GrSLType, "Radial2VSParams", 6
); |
552 fFSParamUni = builder->addUniformArray(GrGLShaderBuilder::kFragment_ShaderTy
pe, | 550 fFSParamUni = builder->addUniformArray(GrGLShaderBuilder::kFragment_ShaderTy
pe, |
553 kFloat_GrSLType, "Radial2FSParams", 6
); | 551 kFloat_GrSLType, "Radial2FSParams", 6
); |
554 | 552 |
555 // For radial gradients without perspective we can pass the linear | 553 // For radial gradients without perspective we can pass the linear |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
632 rootName.c_str(), p1.c_str()); | 630 rootName.c_str(), p1.c_str()); |
633 } else { | 631 } else { |
634 // t is: -c/b | 632 // t is: -c/b |
635 t.printf("-%s / %s", cName.c_str(), bVar.c_str()); | 633 t.printf("-%s / %s", cName.c_str(), bVar.c_str()); |
636 } | 634 } |
637 | 635 |
638 this->emitColorLookup(builder, t.c_str(), outputColor, inputColor, sampl
ers[0]); | 636 this->emitColorLookup(builder, t.c_str(), outputColor, inputColor, sampl
ers[0]); |
639 } | 637 } |
640 } | 638 } |
641 | 639 |
642 void GrGLRadial2Gradient::setData(const GrGLUniformManager& uman, const GrEffect
Stage& stage) { | 640 void GrGLRadial2Gradient::setData(const GrGLUniformManager& uman, |
643 INHERITED::setData(uman, stage); | 641 const GrDrawEffect& drawEffect) { |
644 const GrRadial2Gradient& data = GetEffectFromStage<GrRadial2Gradient>(stage)
; | 642 INHERITED::setData(uman, drawEffect); |
| 643 const GrRadial2Gradient& data = drawEffect.castEffect<GrRadial2Gradient>(); |
645 GrAssert(data.isDegenerate() == fIsDegenerate); | 644 GrAssert(data.isDegenerate() == fIsDegenerate); |
646 SkScalar centerX1 = data.center(); | 645 SkScalar centerX1 = data.center(); |
647 SkScalar radius0 = data.radius(); | 646 SkScalar radius0 = data.radius(); |
648 if (fCachedCenter != centerX1 || | 647 if (fCachedCenter != centerX1 || |
649 fCachedRadius != radius0 || | 648 fCachedRadius != radius0 || |
650 fCachedPosRoot != data.isPosRoot()) { | 649 fCachedPosRoot != data.isPosRoot()) { |
651 | 650 |
652 SkScalar a = SkScalarMul(centerX1, centerX1) - SK_Scalar1; | 651 SkScalar a = SkScalarMul(centerX1, centerX1) - SK_Scalar1; |
653 | 652 |
654 // When we're in the degenerate (linear) case, the second | 653 // When we're in the degenerate (linear) case, the second |
(...skipping 11 matching lines...) Expand all Loading... |
666 }; | 665 }; |
667 | 666 |
668 uman.set1fv(fVSParamUni, 0, 6, values); | 667 uman.set1fv(fVSParamUni, 0, 6, values); |
669 uman.set1fv(fFSParamUni, 0, 6, values); | 668 uman.set1fv(fFSParamUni, 0, 6, values); |
670 fCachedCenter = centerX1; | 669 fCachedCenter = centerX1; |
671 fCachedRadius = radius0; | 670 fCachedRadius = radius0; |
672 fCachedPosRoot = data.isPosRoot(); | 671 fCachedPosRoot = data.isPosRoot(); |
673 } | 672 } |
674 } | 673 } |
675 | 674 |
676 GrGLEffect::EffectKey GrGLRadial2Gradient::GenKey(const GrEffectStage& s, const
GrGLCaps&) { | 675 GrGLEffect::EffectKey GrGLRadial2Gradient::GenKey(const GrDrawEffect& drawEffect
, |
| 676 const GrGLCaps&) { |
677 enum { | 677 enum { |
678 kIsDegenerate = 1 << kMatrixKeyBitCnt, | 678 kIsDegenerate = 1 << kMatrixKeyBitCnt, |
679 }; | 679 }; |
680 | 680 |
681 EffectKey key = GenMatrixKey(s); | 681 EffectKey key = GenMatrixKey(drawEffect); |
682 if (GetEffectFromStage<GrRadial2Gradient>(s).isDegenerate()) { | 682 if (drawEffect.castEffect<GrRadial2Gradient>().isDegenerate()) { |
683 key |= kIsDegenerate; | 683 key |= kIsDegenerate; |
684 } | 684 } |
685 return key; | 685 return key; |
686 } | 686 } |
687 | 687 |
688 ///////////////////////////////////////////////////////////////////// | 688 ///////////////////////////////////////////////////////////////////// |
689 | 689 |
690 GrEffectRef* SkTwoPointRadialGradient::asNewEffect(GrContext* context, const SkP
aint&) const { | 690 GrEffectRef* SkTwoPointRadialGradient::asNewEffect(GrContext* context, const SkP
aint&) const { |
691 SkASSERT(NULL != context); | 691 SkASSERT(NULL != context); |
692 // invert the localM, translate to center1 (fPtsToUni), rotate so center2 is
on x axis. | 692 // invert the localM, translate to center1 (fPtsToUni), rotate so center2 is
on x axis. |
(...skipping 16 matching lines...) Expand all Loading... |
709 } | 709 } |
710 | 710 |
711 #else | 711 #else |
712 | 712 |
713 GrEffectRef* SkTwoPointRadialGradient::asNewEffect(GrContext*, const SkPaint&) c
onst { | 713 GrEffectRef* SkTwoPointRadialGradient::asNewEffect(GrContext*, const SkPaint&) c
onst { |
714 SkDEBUGFAIL("Should not call in GPU-less build"); | 714 SkDEBUGFAIL("Should not call in GPU-less build"); |
715 return NULL; | 715 return NULL; |
716 } | 716 } |
717 | 717 |
718 #endif | 718 #endif |
OLD | NEW |