| 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 "GrAAConvexPathRenderer.h" | 9 #include "GrAAConvexPathRenderer.h" |
| 10 | 10 |
| (...skipping 503 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 514 | 514 |
| 515 virtual void getConstantColorComponents(GrColor* color, | 515 virtual void getConstantColorComponents(GrColor* color, |
| 516 uint32_t* validFlags) const SK_OVERR
IDE { | 516 uint32_t* validFlags) const SK_OVERR
IDE { |
| 517 *validFlags = 0; | 517 *validFlags = 0; |
| 518 } | 518 } |
| 519 | 519 |
| 520 virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE { | 520 virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE { |
| 521 return GrTBackendEffectFactory<QuadEdgeEffect>::getInstance(); | 521 return GrTBackendEffectFactory<QuadEdgeEffect>::getInstance(); |
| 522 } | 522 } |
| 523 | 523 |
| 524 class GLEffect : public GrGLEffect { | 524 class GLEffect : public GrGLVertexEffect { |
| 525 public: | 525 public: |
| 526 GLEffect(const GrBackendEffectFactory& factory, const GrDrawEffect&) | 526 GLEffect(const GrBackendEffectFactory& factory, const GrDrawEffect&) |
| 527 : INHERITED (factory) {} | 527 : INHERITED (factory) {} |
| 528 | 528 |
| 529 virtual void emitCode(GrGLShaderBuilder* builder, | 529 virtual void emitCode(GrGLFullShaderBuilder* builder, |
| 530 const GrDrawEffect& drawEffect, | 530 const GrDrawEffect& drawEffect, |
| 531 EffectKey key, | 531 EffectKey key, |
| 532 const char* outputColor, | 532 const char* outputColor, |
| 533 const char* inputColor, | 533 const char* inputColor, |
| 534 const TransformedCoordsArray&, | 534 const TransformedCoordsArray&, |
| 535 const TextureSamplerArray& samplers) SK_OVERRIDE { | 535 const TextureSamplerArray& samplers) SK_OVERRIDE { |
| 536 GrGLShaderBuilder::VertexBuilder* vertexBuilder = builder->getVertex
Builder(); | |
| 537 SkASSERT(NULL != vertexBuilder); | |
| 538 | |
| 539 const char *vsName, *fsName; | 536 const char *vsName, *fsName; |
| 540 const SkString* attrName = | 537 const SkString* attrName = |
| 541 vertexBuilder->getEffectAttributeName(drawEffect.getVertexAttrib
Indices()[0]); | 538 builder->getEffectAttributeName(drawEffect.getVertexAttribIndice
s()[0]); |
| 542 builder->fsCodeAppendf("\t\tfloat edgeAlpha;\n"); | 539 builder->fsCodeAppendf("\t\tfloat edgeAlpha;\n"); |
| 543 | 540 |
| 544 SkAssertResult(builder->enableFeature( | 541 SkAssertResult(builder->enableFeature( |
| 545 GrGLShaderBuilder::kStandardDeriva
tives_GLSLFeature)); | 542 GrGLShaderBuilder::kStandardDeriva
tives_GLSLFeature)); |
| 546 vertexBuilder->addVarying(kVec4f_GrSLType, "QuadEdge", &vsName, &fsN
ame); | 543 builder->addVarying(kVec4f_GrSLType, "QuadEdge", &vsName, &fsName); |
| 547 | 544 |
| 548 // keep the derivative instructions outside the conditional | 545 // keep the derivative instructions outside the conditional |
| 549 builder->fsCodeAppendf("\t\tvec2 duvdx = dFdx(%s.xy);\n", fsName); | 546 builder->fsCodeAppendf("\t\tvec2 duvdx = dFdx(%s.xy);\n", fsName); |
| 550 builder->fsCodeAppendf("\t\tvec2 duvdy = dFdy(%s.xy);\n", fsName); | 547 builder->fsCodeAppendf("\t\tvec2 duvdy = dFdy(%s.xy);\n", fsName); |
| 551 builder->fsCodeAppendf("\t\tif (%s.z > 0.0 && %s.w > 0.0) {\n", fsNa
me, fsName); | 548 builder->fsCodeAppendf("\t\tif (%s.z > 0.0 && %s.w > 0.0) {\n", fsNa
me, fsName); |
| 552 // today we know z and w are in device space. We could use derivativ
es | 549 // today we know z and w are in device space. We could use derivativ
es |
| 553 builder->fsCodeAppendf("\t\t\tedgeAlpha = min(min(%s.z, %s.w) + 0.5,
1.0);\n", fsName, | 550 builder->fsCodeAppendf("\t\t\tedgeAlpha = min(min(%s.z, %s.w) + 0.5,
1.0);\n", fsName, |
| 554 fsName); | 551 fsName); |
| 555 builder->fsCodeAppendf ("\t\t} else {\n"); | 552 builder->fsCodeAppendf ("\t\t} else {\n"); |
| 556 builder->fsCodeAppendf("\t\t\tvec2 gF = vec2(2.0*%s.x*duvdx.x - duvd
x.y,\n" | 553 builder->fsCodeAppendf("\t\t\tvec2 gF = vec2(2.0*%s.x*duvdx.x - duvd
x.y,\n" |
| 557 "\t\t\t 2.0*%s.x*duvdy.x - duvd
y.y);\n", | 554 "\t\t\t 2.0*%s.x*duvdy.x - duvd
y.y);\n", |
| 558 fsName, fsName); | 555 fsName, fsName); |
| 559 builder->fsCodeAppendf("\t\t\tedgeAlpha = (%s.x*%s.x - %s.y);\n", fs
Name, fsName, | 556 builder->fsCodeAppendf("\t\t\tedgeAlpha = (%s.x*%s.x - %s.y);\n", fs
Name, fsName, |
| 560 fsName); | 557 fsName); |
| 561 builder->fsCodeAppendf("\t\t\tedgeAlpha = " | 558 builder->fsCodeAppendf("\t\t\tedgeAlpha = " |
| 562 "clamp(0.5 - edgeAlpha / length(gF), 0.0, 1.0
);\n\t\t}\n"); | 559 "clamp(0.5 - edgeAlpha / length(gF), 0.0, 1.0
);\n\t\t}\n"); |
| 563 | 560 |
| 564 SkString modulate; | 561 SkString modulate; |
| 565 GrGLSLModulatef<4>(&modulate, inputColor, "edgeAlpha"); | 562 GrGLSLModulatef<4>(&modulate, inputColor, "edgeAlpha"); |
| 566 builder->fsCodeAppendf("\t%s = %s;\n", outputColor, modulate.c_str()
); | 563 builder->fsCodeAppendf("\t%s = %s;\n", outputColor, modulate.c_str()
); |
| 567 | 564 |
| 568 vertexBuilder->vsCodeAppendf("\t%s = %s;\n", vsName, attrName->c_str
()); | 565 builder->vsCodeAppendf("\t%s = %s;\n", vsName, attrName->c_str()); |
| 569 } | 566 } |
| 570 | 567 |
| 571 static inline EffectKey GenKey(const GrDrawEffect& drawEffect, const GrG
LCaps&) { | 568 static inline EffectKey GenKey(const GrDrawEffect& drawEffect, const GrG
LCaps&) { |
| 572 return 0x0; | 569 return 0x0; |
| 573 } | 570 } |
| 574 | 571 |
| 575 virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_
OVERRIDE {} | 572 virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_
OVERRIDE {} |
| 576 | 573 |
| 577 private: | 574 private: |
| 578 typedef GrGLEffect INHERITED; | 575 typedef GrGLVertexEffect INHERITED; |
| 579 }; | 576 }; |
| 580 | 577 |
| 581 private: | 578 private: |
| 582 QuadEdgeEffect() { | 579 QuadEdgeEffect() { |
| 583 this->addVertexAttrib(kVec4f_GrSLType); | 580 this->addVertexAttrib(kVec4f_GrSLType); |
| 584 } | 581 } |
| 585 | 582 |
| 586 virtual bool onIsEqual(const GrEffect& other) const SK_OVERRIDE { | 583 virtual bool onIsEqual(const GrEffect& other) const SK_OVERRIDE { |
| 587 return true; | 584 return true; |
| 588 } | 585 } |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 707 vOffset, // start vertex | 704 vOffset, // start vertex |
| 708 0, // start index | 705 0, // start index |
| 709 draw.fVertexCnt, | 706 draw.fVertexCnt, |
| 710 draw.fIndexCnt, | 707 draw.fIndexCnt, |
| 711 &devBounds); | 708 &devBounds); |
| 712 vOffset += draw.fVertexCnt; | 709 vOffset += draw.fVertexCnt; |
| 713 } | 710 } |
| 714 | 711 |
| 715 return true; | 712 return true; |
| 716 } | 713 } |
| OLD | NEW |