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 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
382 public: | 382 public: |
383 | 383 |
384 GrGLRadial2Gradient(const GrBackendEffectFactory& factory, const GrDrawEffec
t&); | 384 GrGLRadial2Gradient(const GrBackendEffectFactory& factory, const GrDrawEffec
t&); |
385 virtual ~GrGLRadial2Gradient() { } | 385 virtual ~GrGLRadial2Gradient() { } |
386 | 386 |
387 virtual void emitCode(GrGLShaderBuilder*, | 387 virtual void emitCode(GrGLShaderBuilder*, |
388 const GrDrawEffect&, | 388 const GrDrawEffect&, |
389 EffectKey, | 389 EffectKey, |
390 const char* outputColor, | 390 const char* outputColor, |
391 const char* inputColor, | 391 const char* inputColor, |
| 392 const TransformedCoordsArray&, |
392 const TextureSamplerArray&) SK_OVERRIDE; | 393 const TextureSamplerArray&) SK_OVERRIDE; |
393 virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_OVER
RIDE; | 394 virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_OVER
RIDE; |
394 | 395 |
395 static EffectKey GenKey(const GrDrawEffect&, const GrGLCaps& caps); | 396 static EffectKey GenKey(const GrDrawEffect&, const GrGLCaps& caps); |
396 | 397 |
397 protected: | 398 protected: |
398 | 399 |
399 UniformHandle fVSParamUni; | 400 UniformHandle fVSParamUni; |
400 UniformHandle fFSParamUni; | 401 UniformHandle fFSParamUni; |
401 | 402 |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
523 | 524 |
524 const GrRadial2Gradient& data = drawEffect.castEffect<GrRadial2Gradient>(); | 525 const GrRadial2Gradient& data = drawEffect.castEffect<GrRadial2Gradient>(); |
525 fIsDegenerate = data.isDegenerate(); | 526 fIsDegenerate = data.isDegenerate(); |
526 } | 527 } |
527 | 528 |
528 void GrGLRadial2Gradient::emitCode(GrGLShaderBuilder* builder, | 529 void GrGLRadial2Gradient::emitCode(GrGLShaderBuilder* builder, |
529 const GrDrawEffect& drawEffect, | 530 const GrDrawEffect& drawEffect, |
530 EffectKey key, | 531 EffectKey key, |
531 const char* outputColor, | 532 const char* outputColor, |
532 const char* inputColor, | 533 const char* inputColor, |
| 534 const TransformedCoordsArray& coords, |
533 const TextureSamplerArray& samplers) { | 535 const TextureSamplerArray& samplers) { |
534 | 536 |
535 this->emitUniforms(builder, key); | 537 this->emitUniforms(builder, key); |
536 SkString fsCoords; | |
537 SkString vsCoordsVarying; | |
538 | |
539 GrSLType coordsVaryingType; | |
540 this->setupMatrix(builder, key, &fsCoords, &vsCoordsVarying, &coordsVaryingT
ype); | |
541 | |
542 // 2 copies of uniform array, 1 for each of vertex & fragment shader, | 538 // 2 copies of uniform array, 1 for each of vertex & fragment shader, |
543 // to work around Xoom bug. Doesn't seem to cause performance decrease | 539 // to work around Xoom bug. Doesn't seem to cause performance decrease |
544 // in test apps, but need to keep an eye on it. | 540 // in test apps, but need to keep an eye on it. |
545 fVSParamUni = builder->addUniformArray(GrGLShaderBuilder::kVertex_Visibility
, | 541 fVSParamUni = builder->addUniformArray(GrGLShaderBuilder::kVertex_Visibility
, |
546 kFloat_GrSLType, "Radial2VSParams", 6
); | 542 kFloat_GrSLType, "Radial2VSParams", 6
); |
547 fFSParamUni = builder->addUniformArray(GrGLShaderBuilder::kFragment_Visibili
ty, | 543 fFSParamUni = builder->addUniformArray(GrGLShaderBuilder::kFragment_Visibili
ty, |
548 kFloat_GrSLType, "Radial2FSParams", 6
); | 544 kFloat_GrSLType, "Radial2FSParams", 6
); |
549 | 545 |
550 // For radial gradients without perspective we can pass the linear | 546 // For radial gradients without perspective we can pass the linear |
551 // part of the quadratic as a varying. | 547 // part of the quadratic as a varying. |
552 GrGLShaderBuilder::VertexBuilder* vertexBuilder = | 548 GrGLShaderBuilder::VertexBuilder* vertexBuilder = |
553 (kVec2f_GrSLType == coordsVaryingType) ? builder->getVertexBuilder() : N
ULL; | 549 (kVec2f_GrSLType == coords[0].type()) ? builder->getVertexBuilder() : NU
LL; |
554 if (NULL != vertexBuilder) { | 550 if (NULL != vertexBuilder) { |
555 vertexBuilder->addVarying(kFloat_GrSLType, "Radial2BCoeff", | 551 vertexBuilder->addVarying(kFloat_GrSLType, "Radial2BCoeff", |
556 &fVSVaryingName, &fFSVaryingName); | 552 &fVSVaryingName, &fFSVaryingName); |
557 } | 553 } |
558 | 554 |
559 // VS | 555 // VS |
560 { | 556 { |
561 SkString p2; | 557 SkString p2; |
562 SkString p3; | 558 SkString p3; |
563 builder->getUniformVariable(fVSParamUni).appendArrayAccess(2, &p2); | 559 builder->getUniformVariable(fVSParamUni).appendArrayAccess(2, &p2); |
564 builder->getUniformVariable(fVSParamUni).appendArrayAccess(3, &p3); | 560 builder->getUniformVariable(fVSParamUni).appendArrayAccess(3, &p3); |
565 | 561 |
566 // For radial gradients without perspective we can pass the linear | 562 // For radial gradients without perspective we can pass the linear |
567 // part of the quadratic as a varying. | 563 // part of the quadratic as a varying. |
568 if (NULL != vertexBuilder) { | 564 if (NULL != vertexBuilder) { |
569 // r2Var = 2 * (r2Parm[2] * varCoord.x - r2Param[3]) | 565 // r2Var = 2 * (r2Parm[2] * varCoord.x - r2Param[3]) |
570 vertexBuilder->vsCodeAppendf("\t%s = 2.0 *(%s * %s.x - %s);\n", | 566 vertexBuilder->vsCodeAppendf("\t%s = 2.0 *(%s * %s.x - %s);\n", |
571 fVSVaryingName, p2.c_str(), | 567 fVSVaryingName, p2.c_str(), |
572 vsCoordsVarying.c_str(), p3.c_str()); | 568 coords[0].getVSName().c_str(), p3.c_s
tr()); |
573 } | 569 } |
574 } | 570 } |
575 | 571 |
576 // FS | 572 // FS |
577 { | 573 { |
| 574 SkString coords2D = builder->ensureFSCoords2D(coords, 0); |
578 SkString cName("c"); | 575 SkString cName("c"); |
579 SkString ac4Name("ac4"); | 576 SkString ac4Name("ac4"); |
580 SkString rootName("root"); | 577 SkString rootName("root"); |
581 SkString t; | 578 SkString t; |
582 SkString p0; | 579 SkString p0; |
583 SkString p1; | 580 SkString p1; |
584 SkString p2; | 581 SkString p2; |
585 SkString p3; | 582 SkString p3; |
586 SkString p4; | 583 SkString p4; |
587 SkString p5; | 584 SkString p5; |
588 builder->getUniformVariable(fFSParamUni).appendArrayAccess(0, &p0); | 585 builder->getUniformVariable(fFSParamUni).appendArrayAccess(0, &p0); |
589 builder->getUniformVariable(fFSParamUni).appendArrayAccess(1, &p1); | 586 builder->getUniformVariable(fFSParamUni).appendArrayAccess(1, &p1); |
590 builder->getUniformVariable(fFSParamUni).appendArrayAccess(2, &p2); | 587 builder->getUniformVariable(fFSParamUni).appendArrayAccess(2, &p2); |
591 builder->getUniformVariable(fFSParamUni).appendArrayAccess(3, &p3); | 588 builder->getUniformVariable(fFSParamUni).appendArrayAccess(3, &p3); |
592 builder->getUniformVariable(fFSParamUni).appendArrayAccess(4, &p4); | 589 builder->getUniformVariable(fFSParamUni).appendArrayAccess(4, &p4); |
593 builder->getUniformVariable(fFSParamUni).appendArrayAccess(5, &p5); | 590 builder->getUniformVariable(fFSParamUni).appendArrayAccess(5, &p5); |
594 | 591 |
595 // If we we're able to interpolate the linear component, | 592 // If we we're able to interpolate the linear component, |
596 // bVar is the varying; otherwise compute it | 593 // bVar is the varying; otherwise compute it |
597 SkString bVar; | 594 SkString bVar; |
598 if (NULL != vertexBuilder) { | 595 if (NULL != vertexBuilder) { |
599 bVar = fFSVaryingName; | 596 bVar = fFSVaryingName; |
600 } else { | 597 } else { |
601 bVar = "b"; | 598 bVar = "b"; |
602 builder->fsCodeAppendf("\tfloat %s = 2.0 * (%s * %s.x - %s);\n", | 599 builder->fsCodeAppendf("\tfloat %s = 2.0 * (%s * %s.x - %s);\n", |
603 bVar.c_str(), p2.c_str(), fsCoords.c_str(), p
3.c_str()); | 600 bVar.c_str(), p2.c_str(), coords2D.c_str(), p
3.c_str()); |
604 } | 601 } |
605 | 602 |
606 // c = (x^2)+(y^2) - params[4] | 603 // c = (x^2)+(y^2) - params[4] |
607 builder->fsCodeAppendf("\tfloat %s = dot(%s, %s) - %s;\n", | 604 builder->fsCodeAppendf("\tfloat %s = dot(%s, %s) - %s;\n", |
608 cName.c_str(), | 605 cName.c_str(), |
609 fsCoords.c_str(), | 606 coords2D.c_str(), |
610 fsCoords.c_str(), | 607 coords2D.c_str(), |
611 p4.c_str()); | 608 p4.c_str()); |
612 | 609 |
613 // If we aren't degenerate, emit some extra code, and accept a slightly | 610 // If we aren't degenerate, emit some extra code, and accept a slightly |
614 // more complex coord. | 611 // more complex coord. |
615 if (!fIsDegenerate) { | 612 if (!fIsDegenerate) { |
616 | 613 |
617 // ac4 = 4.0 * params[0] * c | 614 // ac4 = 4.0 * params[0] * c |
618 builder->fsCodeAppendf("\tfloat %s = %s * 4.0 * %s;\n", | 615 builder->fsCodeAppendf("\tfloat %s = %s * 4.0 * %s;\n", |
619 ac4Name.c_str(), p0.c_str(), | 616 ac4Name.c_str(), p0.c_str(), |
620 cName.c_str()); | 617 cName.c_str()); |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
709 } | 706 } |
710 | 707 |
711 #else | 708 #else |
712 | 709 |
713 GrEffectRef* SkTwoPointRadialGradient::asNewEffect(GrContext*, const SkPaint&) c
onst { | 710 GrEffectRef* SkTwoPointRadialGradient::asNewEffect(GrContext*, const SkPaint&) c
onst { |
714 SkDEBUGFAIL("Should not call in GPU-less build"); | 711 SkDEBUGFAIL("Should not call in GPU-less build"); |
715 return NULL; | 712 return NULL; |
716 } | 713 } |
717 | 714 |
718 #endif | 715 #endif |
OLD | NEW |