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