| 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 "gl/builders/GrGLProgramBuilder.h" |
| 9 #include "GrAAConvexPathRenderer.h" | 10 #include "GrAAConvexPathRenderer.h" |
| 10 | 11 |
| 11 #include "GrContext.h" | 12 #include "GrContext.h" |
| 12 #include "GrDrawState.h" | 13 #include "GrDrawState.h" |
| 13 #include "GrDrawTargetCaps.h" | 14 #include "GrDrawTargetCaps.h" |
| 14 #include "GrEffect.h" | 15 #include "GrEffect.h" |
| 15 #include "GrPathUtils.h" | 16 #include "GrPathUtils.h" |
| 16 #include "GrTBackendEffectFactory.h" | 17 #include "GrTBackendEffectFactory.h" |
| 17 #include "SkString.h" | 18 #include "SkString.h" |
| 18 #include "SkStrokeRec.h" | 19 #include "SkStrokeRec.h" |
| 19 #include "SkTraceEvent.h" | 20 #include "SkTraceEvent.h" |
| 20 | 21 |
| 21 #include "gl/GrGLEffect.h" | 22 #include "gl/GrGLEffect.h" |
| 22 #include "gl/GrGLShaderBuilder.h" | |
| 23 #include "gl/GrGLSL.h" | 23 #include "gl/GrGLSL.h" |
| 24 #include "gl/GrGLVertexEffect.h" | 24 #include "gl/GrGLVertexEffect.h" |
| 25 | 25 |
| 26 #include "effects/GrVertexEffect.h" | 26 #include "effects/GrVertexEffect.h" |
| 27 | 27 |
| 28 GrAAConvexPathRenderer::GrAAConvexPathRenderer() { | 28 GrAAConvexPathRenderer::GrAAConvexPathRenderer() { |
| 29 } | 29 } |
| 30 | 30 |
| 31 struct Segment { | 31 struct Segment { |
| 32 enum { | 32 enum { |
| (...skipping 491 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 524 | 524 |
| 525 virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE { | 525 virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE { |
| 526 return GrTBackendEffectFactory<QuadEdgeEffect>::getInstance(); | 526 return GrTBackendEffectFactory<QuadEdgeEffect>::getInstance(); |
| 527 } | 527 } |
| 528 | 528 |
| 529 class GLEffect : public GrGLVertexEffect { | 529 class GLEffect : public GrGLVertexEffect { |
| 530 public: | 530 public: |
| 531 GLEffect(const GrBackendEffectFactory& factory, const GrDrawEffect&) | 531 GLEffect(const GrBackendEffectFactory& factory, const GrDrawEffect&) |
| 532 : INHERITED (factory) {} | 532 : INHERITED (factory) {} |
| 533 | 533 |
| 534 virtual void emitCode(GrGLFullShaderBuilder* builder, | 534 virtual void emitCode(GrGLFullProgramBuilder* builder, |
| 535 const GrDrawEffect& drawEffect, | 535 const GrDrawEffect& drawEffect, |
| 536 const GrEffectKey& key, | 536 const GrEffectKey& key, |
| 537 const char* outputColor, | 537 const char* outputColor, |
| 538 const char* inputColor, | 538 const char* inputColor, |
| 539 const TransformedCoordsArray&, | 539 const TransformedCoordsArray&, |
| 540 const TextureSamplerArray& samplers) SK_OVERRIDE { | 540 const TextureSamplerArray& samplers) SK_OVERRIDE { |
| 541 const char *vsName, *fsName; | 541 const char *vsName, *fsName; |
| 542 const SkString* attrName = | |
| 543 builder->getEffectAttributeName(drawEffect.getVertexAttribIndice
s()[0]); | |
| 544 builder->fsCodeAppendf("\t\tfloat edgeAlpha;\n"); | |
| 545 | |
| 546 SkAssertResult(builder->enableFeature( | |
| 547 GrGLShaderBuilder::kStandardDeriva
tives_GLSLFeature)); | |
| 548 builder->addVarying(kVec4f_GrSLType, "QuadEdge", &vsName, &fsName); | 542 builder->addVarying(kVec4f_GrSLType, "QuadEdge", &vsName, &fsName); |
| 549 | 543 |
| 544 GrGLFragmentShaderBuilder* fsBuilder = builder->getFragmentShaderBui
lder(); |
| 545 |
| 546 SkAssertResult(fsBuilder->enableFeature( |
| 547 GrGLFragmentShaderBuilder::kStandardDerivatives_GLSLFeature)
); |
| 548 fsBuilder->codeAppendf("\t\tfloat edgeAlpha;\n"); |
| 549 |
| 550 // keep the derivative instructions outside the conditional | 550 // keep the derivative instructions outside the conditional |
| 551 builder->fsCodeAppendf("\t\tvec2 duvdx = dFdx(%s.xy);\n", fsName); | 551 fsBuilder->codeAppendf("\t\tvec2 duvdx = dFdx(%s.xy);\n", fsName); |
| 552 builder->fsCodeAppendf("\t\tvec2 duvdy = dFdy(%s.xy);\n", fsName); | 552 fsBuilder->codeAppendf("\t\tvec2 duvdy = dFdy(%s.xy);\n", fsName); |
| 553 builder->fsCodeAppendf("\t\tif (%s.z > 0.0 && %s.w > 0.0) {\n", fsNa
me, fsName); | 553 fsBuilder->codeAppendf("\t\tif (%s.z > 0.0 && %s.w > 0.0) {\n", fsNa
me, fsName); |
| 554 // today we know z and w are in device space. We could use derivativ
es | 554 // today we know z and w are in device space. We could use derivativ
es |
| 555 builder->fsCodeAppendf("\t\t\tedgeAlpha = min(min(%s.z, %s.w) + 0.5,
1.0);\n", fsName, | 555 fsBuilder->codeAppendf("\t\t\tedgeAlpha = min(min(%s.z, %s.w) + 0.5,
1.0);\n", fsName, |
| 556 fsName); | 556 fsName); |
| 557 builder->fsCodeAppendf ("\t\t} else {\n"); | 557 fsBuilder->codeAppendf ("\t\t} else {\n"); |
| 558 builder->fsCodeAppendf("\t\t\tvec2 gF = vec2(2.0*%s.x*duvdx.x - duvd
x.y,\n" | 558 fsBuilder->codeAppendf("\t\t\tvec2 gF = vec2(2.0*%s.x*duvdx.x - duvd
x.y,\n" |
| 559 "\t\t\t 2.0*%s.x*duvdy.x - duvd
y.y);\n", | 559 "\t\t\t 2.0*%s.x*duvdy.x - duvd
y.y);\n", |
| 560 fsName, fsName); | 560 fsName, fsName); |
| 561 builder->fsCodeAppendf("\t\t\tedgeAlpha = (%s.x*%s.x - %s.y);\n", fs
Name, fsName, | 561 fsBuilder->codeAppendf("\t\t\tedgeAlpha = (%s.x*%s.x - %s.y);\n", fs
Name, fsName, |
| 562 fsName); | 562 fsName); |
| 563 builder->fsCodeAppendf("\t\t\tedgeAlpha = " | 563 fsBuilder->codeAppendf("\t\t\tedgeAlpha = " |
| 564 "clamp(0.5 - edgeAlpha / length(gF), 0.0, 1.0
);\n\t\t}\n"); | 564 "clamp(0.5 - edgeAlpha / length(gF), 0.0, 1.0
);\n\t\t}\n"); |
| 565 | 565 |
| 566 | 566 |
| 567 builder->fsCodeAppendf("\t%s = %s;\n", outputColor, | 567 fsBuilder->codeAppendf("\t%s = %s;\n", outputColor, |
| 568 (GrGLSLExpr4(inputColor) * GrGLSLExpr1("edgeA
lpha")).c_str()); | 568 (GrGLSLExpr4(inputColor) * GrGLSLExpr1("edgeA
lpha")).c_str()); |
| 569 | 569 |
| 570 builder->vsCodeAppendf("\t%s = %s;\n", vsName, attrName->c_str()); | 570 GrGLVertexShaderBuilder* vsBuilder = builder->getVertexShaderBuilder
(); |
| 571 const SkString* attr0Name = |
| 572 vsBuilder->getEffectAttributeName(drawEffect.getVertexAttribIndi
ces()[0]); |
| 573 vsBuilder->codeAppendf("\t%s = %s;\n", vsName, attr0Name->c_str()); |
| 571 } | 574 } |
| 572 | 575 |
| 573 static inline void GenKey(const GrDrawEffect&, const GrGLCaps&, GrEffect
KeyBuilder*) {} | 576 static inline void GenKey(const GrDrawEffect&, const GrGLCaps&, GrEffect
KeyBuilder*) {} |
| 574 | 577 |
| 575 virtual void setData(const GrGLProgramDataManager&, const GrDrawEffect&)
SK_OVERRIDE {} | 578 virtual void setData(const GrGLProgramDataManager&, const GrDrawEffect&)
SK_OVERRIDE {} |
| 576 | 579 |
| 577 private: | 580 private: |
| 578 typedef GrGLVertexEffect INHERITED; | 581 typedef GrGLVertexEffect INHERITED; |
| 579 }; | 582 }; |
| 580 | 583 |
| 581 private: | 584 private: |
| 582 QuadEdgeEffect() { | 585 QuadEdgeEffect() { |
| 583 this->addVertexAttrib(kVec4f_GrSLType); | 586 this->addVertexAttrib(kVec4f_GrSLType); |
| 584 } | 587 } |
| 585 | 588 |
| 586 virtual bool onIsEqual(const GrEffect& other) const SK_OVERRIDE { | 589 virtual bool onIsEqual(const GrEffect& other) const SK_OVERRIDE { |
| 587 return true; | 590 return true; |
| 588 } | 591 } |
| 589 | 592 |
| 590 GR_DECLARE_EFFECT_TEST; | 593 GR_DECLARE_EFFECT_TEST; |
| 591 | 594 |
| 592 typedef GrVertexEffect INHERITED; | 595 typedef GrEffect INHERITED; |
| 593 }; | 596 }; |
| 594 | 597 |
| 595 GR_DEFINE_EFFECT_TEST(QuadEdgeEffect); | 598 GR_DEFINE_EFFECT_TEST(QuadEdgeEffect); |
| 596 | 599 |
| 597 GrEffect* QuadEdgeEffect::TestCreate(SkRandom* random, | 600 GrEffect* QuadEdgeEffect::TestCreate(SkRandom* random, |
| 598 GrContext*, | 601 GrContext*, |
| 599 const GrDrawTargetCaps& caps, | 602 const GrDrawTargetCaps& caps, |
| 600 GrTexture*[]) { | 603 GrTexture*[]) { |
| 601 // Doesn't work without derivative instructions. | 604 // Doesn't work without derivative instructions. |
| 602 return caps.shaderDerivativeSupport() ? QuadEdgeEffect::Create() : NULL; | 605 return caps.shaderDerivativeSupport() ? QuadEdgeEffect::Create() : NULL; |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 707 vOffset, // start vertex | 710 vOffset, // start vertex |
| 708 0, // start index | 711 0, // start index |
| 709 draw.fVertexCnt, | 712 draw.fVertexCnt, |
| 710 draw.fIndexCnt, | 713 draw.fIndexCnt, |
| 711 &devBounds); | 714 &devBounds); |
| 712 vOffset += draw.fVertexCnt; | 715 vOffset += draw.fVertexCnt; |
| 713 } | 716 } |
| 714 | 717 |
| 715 return true; | 718 return true; |
| 716 } | 719 } |
| OLD | NEW |