| 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 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 376 | 376 |
| 377 fPtsToUnit.setTranslate(-fCenter1.fX, -fCenter1.fY); | 377 fPtsToUnit.setTranslate(-fCenter1.fX, -fCenter1.fY); |
| 378 fPtsToUnit.postScale(inv, inv); | 378 fPtsToUnit.postScale(inv, inv); |
| 379 } | 379 } |
| 380 | 380 |
| 381 ///////////////////////////////////////////////////////////////////// | 381 ///////////////////////////////////////////////////////////////////// |
| 382 | 382 |
| 383 #if SK_SUPPORT_GPU | 383 #if SK_SUPPORT_GPU |
| 384 | 384 |
| 385 #include "GrTBackendEffectFactory.h" | 385 #include "GrTBackendEffectFactory.h" |
| 386 #include "gl/GrGLShaderBuilder.h" | 386 #include "gl/builders/GrGLProgramBuilder.h" |
| 387 #include "SkGr.h" | 387 #include "SkGr.h" |
| 388 | 388 |
| 389 // For brevity | 389 // For brevity |
| 390 typedef GrGLProgramDataManager::UniformHandle UniformHandle; | 390 typedef GrGLProgramDataManager::UniformHandle UniformHandle; |
| 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(GrGLProgramBuilder*, |
| 400 const GrDrawEffect&, | 400 const GrDrawEffect&, |
| 401 const GrEffectKey&, | 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 GrGLProgramDataManager&, const GrDrawEffect&) SK_
OVERRIDE; | 406 virtual void setData(const GrGLProgramDataManager&, const GrDrawEffect&) SK_
OVERRIDE; |
| 407 | 407 |
| 408 static void GenKey(const GrDrawEffect&, const GrGLCaps& caps, GrEffectKeyBui
lder* b); | 408 static void GenKey(const GrDrawEffect&, const GrGLCaps& caps, GrEffectKeyBui
lder* b); |
| 409 | 409 |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 545 , fVSVaryingName(NULL) | 545 , fVSVaryingName(NULL) |
| 546 , fFSVaryingName(NULL) | 546 , fFSVaryingName(NULL) |
| 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(GrGLProgramBuilder* builder, |
| 556 const GrDrawEffect& drawEffect, | 556 const GrDrawEffect& drawEffect, |
| 557 const GrEffectKey& 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 uint32_t baseKey = key.get32(0); | 562 uint32_t baseKey = key.get32(0); |
| 563 this->emitUniforms(builder, baseKey); | 563 this->emitUniforms(builder, baseKey); |
| 564 fParamUni = builder->addUniformArray(GrGLShaderBuilder::kFragment_Visibility
, | 564 fParamUni = builder->addUniformArray(GrGLProgramBuilder::kFragment_Visibilit
y, |
| 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; |
| 574 SkString p3; | 574 SkString p3; |
| 575 SkString p4; | 575 SkString p4; |
| 576 SkString p5; | 576 SkString p5; |
| 577 builder->getUniformVariable(fParamUni).appendArrayAccess(0, &p0); | 577 builder->getUniformVariable(fParamUni).appendArrayAccess(0, &p0); |
| 578 builder->getUniformVariable(fParamUni).appendArrayAccess(1, &p1); | 578 builder->getUniformVariable(fParamUni).appendArrayAccess(1, &p1); |
| 579 builder->getUniformVariable(fParamUni).appendArrayAccess(2, &p2); | 579 builder->getUniformVariable(fParamUni).appendArrayAccess(2, &p2); |
| 580 builder->getUniformVariable(fParamUni).appendArrayAccess(3, &p3); | 580 builder->getUniformVariable(fParamUni).appendArrayAccess(3, &p3); |
| 581 builder->getUniformVariable(fParamUni).appendArrayAccess(4, &p4); | 581 builder->getUniformVariable(fParamUni).appendArrayAccess(4, &p4); |
| 582 builder->getUniformVariable(fParamUni).appendArrayAccess(5, &p5); | 582 builder->getUniformVariable(fParamUni).appendArrayAccess(5, &p5); |
| 583 | 583 |
| 584 GrGLFragmentShaderBuilder* fsBuilder = builder->getFragmentShaderBuilder(); |
| 584 // We interpolate the linear component in coords[1]. | 585 // We interpolate the linear component in coords[1]. |
| 585 SkASSERT(coords[0].type() == coords[1].type()); | 586 SkASSERT(coords[0].type() == coords[1].type()); |
| 586 const char* coords2D; | 587 const char* coords2D; |
| 587 SkString bVar; | 588 SkString bVar; |
| 588 if (kVec3f_GrSLType == coords[0].type()) { | 589 if (kVec3f_GrSLType == coords[0].type()) { |
| 589 builder->fsCodeAppendf("\tvec3 interpolants = vec3(%s.xy, %s.x) / %s.z;\
n", | 590 fsBuilder->codeAppendf("\tvec3 interpolants = vec3(%s.xy, %s.x) / %s.z;\
n", |
| 590 coords[0].c_str(), coords[1].c_str(), coords[0].c
_str()); | 591 coords[0].c_str(), coords[1].c_str(), coords[0].c
_str()); |
| 591 coords2D = "interpolants.xy"; | 592 coords2D = "interpolants.xy"; |
| 592 bVar = "interpolants.z"; | 593 bVar = "interpolants.z"; |
| 593 } else { | 594 } else { |
| 594 coords2D = coords[0].c_str(); | 595 coords2D = coords[0].c_str(); |
| 595 bVar.printf("%s.x", coords[1].c_str()); | 596 bVar.printf("%s.x", coords[1].c_str()); |
| 596 } | 597 } |
| 597 | 598 |
| 598 // c = (x^2)+(y^2) - params[4] | 599 // c = (x^2)+(y^2) - params[4] |
| 599 builder->fsCodeAppendf("\tfloat %s = dot(%s, %s) - %s;\n", | 600 fsBuilder->codeAppendf("\tfloat %s = dot(%s, %s) - %s;\n", |
| 600 cName.c_str(), coords2D, coords2D, p4.c_str()); | 601 cName.c_str(), coords2D, coords2D, p4.c_str()); |
| 601 | 602 |
| 602 // If we aren't degenerate, emit some extra code, and accept a slightly | 603 // If we aren't degenerate, emit some extra code, and accept a slightly |
| 603 // more complex coord. | 604 // more complex coord. |
| 604 if (!fIsDegenerate) { | 605 if (!fIsDegenerate) { |
| 605 | 606 |
| 606 // ac4 = 4.0 * params[0] * c | 607 // ac4 = 4.0 * params[0] * c |
| 607 builder->fsCodeAppendf("\tfloat %s = %s * 4.0 * %s;\n", | 608 fsBuilder->codeAppendf("\tfloat %s = %s * 4.0 * %s;\n", |
| 608 ac4Name.c_str(), p0.c_str(), | 609 ac4Name.c_str(), p0.c_str(), |
| 609 cName.c_str()); | 610 cName.c_str()); |
| 610 | 611 |
| 611 // root = sqrt(b^2-4ac) | 612 // root = sqrt(b^2-4ac) |
| 612 // (abs to avoid exception due to fp precision) | 613 // (abs to avoid exception due to fp precision) |
| 613 builder->fsCodeAppendf("\tfloat %s = sqrt(abs(%s*%s - %s));\n", | 614 fsBuilder->codeAppendf("\tfloat %s = sqrt(abs(%s*%s - %s));\n", |
| 614 rootName.c_str(), bVar.c_str(), bVar.c_str(), | 615 rootName.c_str(), bVar.c_str(), bVar.c_str(), |
| 615 ac4Name.c_str()); | 616 ac4Name.c_str()); |
| 616 | 617 |
| 617 // t is: (-b + params[5] * sqrt(b^2-4ac)) * params[1] | 618 // t is: (-b + params[5] * sqrt(b^2-4ac)) * params[1] |
| 618 t.printf("(-%s + %s * %s) * %s", bVar.c_str(), p5.c_str(), | 619 t.printf("(-%s + %s * %s) * %s", bVar.c_str(), p5.c_str(), |
| 619 rootName.c_str(), p1.c_str()); | 620 rootName.c_str(), p1.c_str()); |
| 620 } else { | 621 } else { |
| 621 // t is: -c/b | 622 // t is: -c/b |
| 622 t.printf("-%s / %s", cName.c_str(), bVar.c_str()); | 623 t.printf("-%s / %s", cName.c_str(), bVar.c_str()); |
| 623 } | 624 } |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 705 #else | 706 #else |
| 706 | 707 |
| 707 bool SkTwoPointRadialGradient::asNewEffect(GrContext* context, const SkPaint& pa
int, | 708 bool SkTwoPointRadialGradient::asNewEffect(GrContext* context, const SkPaint& pa
int, |
| 708 const SkMatrix* localMatrix, GrColor*
paintColor, | 709 const SkMatrix* localMatrix, GrColor*
paintColor, |
| 709 GrEffect** effect) const { | 710 GrEffect** effect) const { |
| 710 SkDEBUGFAIL("Should not call in GPU-less build"); | 711 SkDEBUGFAIL("Should not call in GPU-less build"); |
| 711 return false; | 712 return false; |
| 712 } | 713 } |
| 713 | 714 |
| 714 #endif | 715 #endif |
| OLD | NEW |