| 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 fPtsToUnit.setTranslate(-fCenter1.fX, -fCenter1.fY); | 392 fPtsToUnit.setTranslate(-fCenter1.fX, -fCenter1.fY); |
| 393 fPtsToUnit.postScale(inv, inv); | 393 fPtsToUnit.postScale(inv, inv); |
| 394 } | 394 } |
| 395 | 395 |
| 396 ///////////////////////////////////////////////////////////////////// | 396 ///////////////////////////////////////////////////////////////////// |
| 397 | 397 |
| 398 #if SK_SUPPORT_GPU | 398 #if SK_SUPPORT_GPU |
| 399 | 399 |
| 400 #include "GrTBackendEffectFactory.h" | 400 #include "GrTBackendEffectFactory.h" |
| 401 #include "gl/GrGLShaderBuilder.h" | 401 #include "gl/builders/GrGLProgramBuilder.h" |
| 402 #include "SkGr.h" | 402 #include "SkGr.h" |
| 403 | 403 |
| 404 // For brevity | 404 // For brevity |
| 405 typedef GrGLProgramDataManager::UniformHandle UniformHandle; | 405 typedef GrGLProgramDataManager::UniformHandle UniformHandle; |
| 406 | 406 |
| 407 class GrGLRadial2Gradient : public GrGLGradientEffect { | 407 class GrGLRadial2Gradient : public GrGLGradientEffect { |
| 408 | 408 |
| 409 public: | 409 public: |
| 410 | 410 |
| 411 GrGLRadial2Gradient(const GrBackendEffectFactory& factory, const GrDrawEffec
t&); | 411 GrGLRadial2Gradient(const GrBackendEffectFactory& factory, const GrDrawEffec
t&); |
| 412 virtual ~GrGLRadial2Gradient() { } | 412 virtual ~GrGLRadial2Gradient() { } |
| 413 | 413 |
| 414 virtual void emitCode(GrGLShaderBuilder*, | 414 virtual void emitCode(GrGLProgramBuilder*, |
| 415 const GrDrawEffect&, | 415 const GrDrawEffect&, |
| 416 const GrEffectKey&, | 416 const GrEffectKey&, |
| 417 const char* outputColor, | 417 const char* outputColor, |
| 418 const char* inputColor, | 418 const char* inputColor, |
| 419 const TransformedCoordsArray&, | 419 const TransformedCoordsArray&, |
| 420 const TextureSamplerArray&) SK_OVERRIDE; | 420 const TextureSamplerArray&) SK_OVERRIDE; |
| 421 virtual void setData(const GrGLProgramDataManager&, const GrDrawEffect&) SK_
OVERRIDE; | 421 virtual void setData(const GrGLProgramDataManager&, const GrDrawEffect&) SK_
OVERRIDE; |
| 422 | 422 |
| 423 static void GenKey(const GrDrawEffect&, const GrGLCaps& caps, GrEffectKeyBui
lder* b); | 423 static void GenKey(const GrDrawEffect&, const GrGLCaps& caps, GrEffectKeyBui
lder* b); |
| 424 | 424 |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 560 , fVSVaryingName(NULL) | 560 , fVSVaryingName(NULL) |
| 561 , fFSVaryingName(NULL) | 561 , fFSVaryingName(NULL) |
| 562 , fCachedCenter(SK_ScalarMax) | 562 , fCachedCenter(SK_ScalarMax) |
| 563 , fCachedRadius(-SK_ScalarMax) | 563 , fCachedRadius(-SK_ScalarMax) |
| 564 , fCachedPosRoot(0) { | 564 , fCachedPosRoot(0) { |
| 565 | 565 |
| 566 const GrRadial2Gradient& data = drawEffect.castEffect<GrRadial2Gradient>(); | 566 const GrRadial2Gradient& data = drawEffect.castEffect<GrRadial2Gradient>(); |
| 567 fIsDegenerate = data.isDegenerate(); | 567 fIsDegenerate = data.isDegenerate(); |
| 568 } | 568 } |
| 569 | 569 |
| 570 void GrGLRadial2Gradient::emitCode(GrGLShaderBuilder* builder, | 570 void GrGLRadial2Gradient::emitCode(GrGLProgramBuilder* builder, |
| 571 const GrDrawEffect& drawEffect, | 571 const GrDrawEffect& drawEffect, |
| 572 const GrEffectKey& key, | 572 const GrEffectKey& key, |
| 573 const char* outputColor, | 573 const char* outputColor, |
| 574 const char* inputColor, | 574 const char* inputColor, |
| 575 const TransformedCoordsArray& coords, | 575 const TransformedCoordsArray& coords, |
| 576 const TextureSamplerArray& samplers) { | 576 const TextureSamplerArray& samplers) { |
| 577 uint32_t baseKey = key.get32(0); | 577 uint32_t baseKey = key.get32(0); |
| 578 this->emitUniforms(builder, baseKey); | 578 this->emitUniforms(builder, baseKey); |
| 579 fParamUni = builder->addUniformArray(GrGLShaderBuilder::kFragment_Visibility
, | 579 fParamUni = builder->addUniformArray(GrGLProgramBuilder::kFragment_Visibilit
y, |
| 580 kFloat_GrSLType, "Radial2FSParams", 6); | 580 kFloat_GrSLType, "Radial2FSParams", 6); |
| 581 | 581 |
| 582 SkString cName("c"); | 582 SkString cName("c"); |
| 583 SkString ac4Name("ac4"); | 583 SkString ac4Name("ac4"); |
| 584 SkString rootName("root"); | 584 SkString rootName("root"); |
| 585 SkString t; | 585 SkString t; |
| 586 SkString p0; | 586 SkString p0; |
| 587 SkString p1; | 587 SkString p1; |
| 588 SkString p2; | 588 SkString p2; |
| 589 SkString p3; | 589 SkString p3; |
| 590 SkString p4; | 590 SkString p4; |
| 591 SkString p5; | 591 SkString p5; |
| 592 builder->getUniformVariable(fParamUni).appendArrayAccess(0, &p0); | 592 builder->getUniformVariable(fParamUni).appendArrayAccess(0, &p0); |
| 593 builder->getUniformVariable(fParamUni).appendArrayAccess(1, &p1); | 593 builder->getUniformVariable(fParamUni).appendArrayAccess(1, &p1); |
| 594 builder->getUniformVariable(fParamUni).appendArrayAccess(2, &p2); | 594 builder->getUniformVariable(fParamUni).appendArrayAccess(2, &p2); |
| 595 builder->getUniformVariable(fParamUni).appendArrayAccess(3, &p3); | 595 builder->getUniformVariable(fParamUni).appendArrayAccess(3, &p3); |
| 596 builder->getUniformVariable(fParamUni).appendArrayAccess(4, &p4); | 596 builder->getUniformVariable(fParamUni).appendArrayAccess(4, &p4); |
| 597 builder->getUniformVariable(fParamUni).appendArrayAccess(5, &p5); | 597 builder->getUniformVariable(fParamUni).appendArrayAccess(5, &p5); |
| 598 | 598 |
| 599 GrGLFragmentShaderBuilder* fsBuilder = builder->getFragmentShaderBuilder(); |
| 599 // We interpolate the linear component in coords[1]. | 600 // We interpolate the linear component in coords[1]. |
| 600 SkASSERT(coords[0].type() == coords[1].type()); | 601 SkASSERT(coords[0].type() == coords[1].type()); |
| 601 const char* coords2D; | 602 const char* coords2D; |
| 602 SkString bVar; | 603 SkString bVar; |
| 603 if (kVec3f_GrSLType == coords[0].type()) { | 604 if (kVec3f_GrSLType == coords[0].type()) { |
| 604 builder->fsCodeAppendf("\tvec3 interpolants = vec3(%s.xy, %s.x) / %s.z;\
n", | 605 fsBuilder->codeAppendf("\tvec3 interpolants = vec3(%s.xy, %s.x) / %s.z;\
n", |
| 605 coords[0].c_str(), coords[1].c_str(), coords[0].c
_str()); | 606 coords[0].c_str(), coords[1].c_str(), coords[0].c
_str()); |
| 606 coords2D = "interpolants.xy"; | 607 coords2D = "interpolants.xy"; |
| 607 bVar = "interpolants.z"; | 608 bVar = "interpolants.z"; |
| 608 } else { | 609 } else { |
| 609 coords2D = coords[0].c_str(); | 610 coords2D = coords[0].c_str(); |
| 610 bVar.printf("%s.x", coords[1].c_str()); | 611 bVar.printf("%s.x", coords[1].c_str()); |
| 611 } | 612 } |
| 612 | 613 |
| 613 // c = (x^2)+(y^2) - params[4] | 614 // c = (x^2)+(y^2) - params[4] |
| 614 builder->fsCodeAppendf("\tfloat %s = dot(%s, %s) - %s;\n", | 615 fsBuilder->codeAppendf("\tfloat %s = dot(%s, %s) - %s;\n", |
| 615 cName.c_str(), coords2D, coords2D, p4.c_str()); | 616 cName.c_str(), coords2D, coords2D, p4.c_str()); |
| 616 | 617 |
| 617 // If we aren't degenerate, emit some extra code, and accept a slightly | 618 // If we aren't degenerate, emit some extra code, and accept a slightly |
| 618 // more complex coord. | 619 // more complex coord. |
| 619 if (!fIsDegenerate) { | 620 if (!fIsDegenerate) { |
| 620 | 621 |
| 621 // ac4 = 4.0 * params[0] * c | 622 // ac4 = 4.0 * params[0] * c |
| 622 builder->fsCodeAppendf("\tfloat %s = %s * 4.0 * %s;\n", | 623 fsBuilder->codeAppendf("\tfloat %s = %s * 4.0 * %s;\n", |
| 623 ac4Name.c_str(), p0.c_str(), | 624 ac4Name.c_str(), p0.c_str(), |
| 624 cName.c_str()); | 625 cName.c_str()); |
| 625 | 626 |
| 626 // root = sqrt(b^2-4ac) | 627 // root = sqrt(b^2-4ac) |
| 627 // (abs to avoid exception due to fp precision) | 628 // (abs to avoid exception due to fp precision) |
| 628 builder->fsCodeAppendf("\tfloat %s = sqrt(abs(%s*%s - %s));\n", | 629 fsBuilder->codeAppendf("\tfloat %s = sqrt(abs(%s*%s - %s));\n", |
| 629 rootName.c_str(), bVar.c_str(), bVar.c_str(), | 630 rootName.c_str(), bVar.c_str(), bVar.c_str(), |
| 630 ac4Name.c_str()); | 631 ac4Name.c_str()); |
| 631 | 632 |
| 632 // t is: (-b + params[5] * sqrt(b^2-4ac)) * params[1] | 633 // t is: (-b + params[5] * sqrt(b^2-4ac)) * params[1] |
| 633 t.printf("(-%s + %s * %s) * %s", bVar.c_str(), p5.c_str(), | 634 t.printf("(-%s + %s * %s) * %s", bVar.c_str(), p5.c_str(), |
| 634 rootName.c_str(), p1.c_str()); | 635 rootName.c_str(), p1.c_str()); |
| 635 } else { | 636 } else { |
| 636 // t is: -c/b | 637 // t is: -c/b |
| 637 t.printf("-%s / %s", cName.c_str(), bVar.c_str()); | 638 t.printf("-%s / %s", cName.c_str(), bVar.c_str()); |
| 638 } | 639 } |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 720 #else | 721 #else |
| 721 | 722 |
| 722 bool SkTwoPointRadialGradient::asNewEffect(GrContext* context, const SkPaint& pa
int, | 723 bool SkTwoPointRadialGradient::asNewEffect(GrContext* context, const SkPaint& pa
int, |
| 723 const SkMatrix* localMatrix, GrColor*
paintColor, | 724 const SkMatrix* localMatrix, GrColor*
paintColor, |
| 724 GrEffect** effect) const { | 725 GrEffect** effect) const { |
| 725 SkDEBUGFAIL("Should not call in GPU-less build"); | 726 SkDEBUGFAIL("Should not call in GPU-less build"); |
| 726 return false; | 727 return false; |
| 727 } | 728 } |
| 728 | 729 |
| 729 #endif | 730 #endif |
| OLD | NEW |