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 "gl/builders/GrGLProgramBuilder.h" |
10 #include "GrAAConvexPathRenderer.h" | 10 #include "GrAAConvexPathRenderer.h" |
11 | 11 |
12 #include "GrContext.h" | 12 #include "GrContext.h" |
13 #include "GrDrawState.h" | 13 #include "GrDrawState.h" |
14 #include "GrDrawTargetCaps.h" | 14 #include "GrDrawTargetCaps.h" |
15 #include "GrEffect.h" | 15 #include "GrEffect.h" |
16 #include "GrPathUtils.h" | 16 #include "GrPathUtils.h" |
17 #include "GrTBackendEffectFactory.h" | 17 #include "GrTBackendEffectFactory.h" |
18 #include "SkString.h" | 18 #include "SkString.h" |
19 #include "SkStrokeRec.h" | 19 #include "SkStrokeRec.h" |
20 #include "SkTraceEvent.h" | 20 #include "SkTraceEvent.h" |
21 | 21 |
22 #include "gl/GrGLEffect.h" | 22 #include "gl/GrGLEffect.h" |
23 #include "gl/GrGLSL.h" | 23 #include "gl/GrGLSL.h" |
24 #include "gl/GrGLVertexEffect.h" | 24 #include "gl/GrGLGeometryProcessor.h" |
25 | 25 |
26 #include "effects/GrVertexEffect.h" | 26 #include "effects/GrGeometryProcessor.h" |
27 | 27 |
28 GrAAConvexPathRenderer::GrAAConvexPathRenderer() { | 28 GrAAConvexPathRenderer::GrAAConvexPathRenderer() { |
29 } | 29 } |
30 | 30 |
31 struct Segment { | 31 struct Segment { |
32 enum { | 32 enum { |
33 // These enum values are assumed in member functions below. | 33 // These enum values are assumed in member functions below. |
34 kLine = 0, | 34 kLine = 0, |
35 kQuad = 1, | 35 kQuad = 1, |
36 } fType; | 36 } fType; |
(...skipping 460 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
497 /* | 497 /* |
498 * Quadratic specified by 0=u^2-v canonical coords. u and v are the first | 498 * Quadratic specified by 0=u^2-v canonical coords. u and v are the first |
499 * two components of the vertex attribute. Coverage is based on signed | 499 * two components of the vertex attribute. Coverage is based on signed |
500 * distance with negative being inside, positive outside. The edge is specified
in | 500 * distance with negative being inside, positive outside. The edge is specified
in |
501 * window space (y-down). If either the third or fourth component of the interpo
lated | 501 * window space (y-down). If either the third or fourth component of the interpo
lated |
502 * vertex coord is > 0 then the pixel is considered outside the edge. This is us
ed to | 502 * vertex coord is > 0 then the pixel is considered outside the edge. This is us
ed to |
503 * attempt to trim to a portion of the infinite quad. | 503 * attempt to trim to a portion of the infinite quad. |
504 * Requires shader derivative instruction support. | 504 * Requires shader derivative instruction support. |
505 */ | 505 */ |
506 | 506 |
507 class QuadEdgeEffect : public GrVertexEffect { | 507 class QuadEdgeEffect : public GrGeometryProcessor { |
508 public: | 508 public: |
509 | 509 |
510 static GrEffect* Create() { | 510 static GrEffect* Create() { |
511 GR_CREATE_STATIC_EFFECT(gQuadEdgeEffect, QuadEdgeEffect, ()); | 511 GR_CREATE_STATIC_EFFECT(gQuadEdgeEffect, QuadEdgeEffect, ()); |
512 gQuadEdgeEffect->ref(); | 512 gQuadEdgeEffect->ref(); |
513 return gQuadEdgeEffect; | 513 return gQuadEdgeEffect; |
514 } | 514 } |
515 | 515 |
516 virtual ~QuadEdgeEffect() {} | 516 virtual ~QuadEdgeEffect() {} |
517 | 517 |
518 static const char* Name() { return "QuadEdge"; } | 518 static const char* Name() { return "QuadEdge"; } |
519 | 519 |
520 virtual void getConstantColorComponents(GrColor* color, | 520 virtual void getConstantColorComponents(GrColor* color, |
521 uint32_t* validFlags) const SK_OVERR
IDE { | 521 uint32_t* validFlags) const SK_OVERR
IDE { |
522 *validFlags = 0; | 522 *validFlags = 0; |
523 } | 523 } |
524 | 524 |
| 525 const GrShaderVar& inQuadEdge() const { return fInQuadEdge; } |
| 526 |
525 virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE { | 527 virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE { |
526 return GrTBackendEffectFactory<QuadEdgeEffect>::getInstance(); | 528 return GrTBackendEffectFactory<QuadEdgeEffect>::getInstance(); |
527 } | 529 } |
528 | 530 |
529 class GLEffect : public GrGLVertexEffect { | 531 class GLEffect : public GrGLGeometryProcessor { |
530 public: | 532 public: |
531 GLEffect(const GrBackendEffectFactory& factory, const GrDrawEffect&) | 533 GLEffect(const GrBackendEffectFactory& factory, const GrDrawEffect&) |
532 : INHERITED (factory) {} | 534 : INHERITED (factory) {} |
533 | 535 |
534 virtual void emitCode(GrGLFullProgramBuilder* builder, | 536 virtual void emitCode(GrGLFullProgramBuilder* builder, |
535 const GrDrawEffect& drawEffect, | 537 const GrDrawEffect& drawEffect, |
536 const GrEffectKey& key, | 538 const GrEffectKey& key, |
537 const char* outputColor, | 539 const char* outputColor, |
538 const char* inputColor, | 540 const char* inputColor, |
539 const TransformedCoordsArray&, | 541 const TransformedCoordsArray&, |
(...skipping 20 matching lines...) Expand all Loading... |
560 fsName, fsName); | 562 fsName, fsName); |
561 fsBuilder->codeAppendf("\t\t\tedgeAlpha = (%s.x*%s.x - %s.y);\n", fs
Name, fsName, | 563 fsBuilder->codeAppendf("\t\t\tedgeAlpha = (%s.x*%s.x - %s.y);\n", fs
Name, fsName, |
562 fsName); | 564 fsName); |
563 fsBuilder->codeAppendf("\t\t\tedgeAlpha = " | 565 fsBuilder->codeAppendf("\t\t\tedgeAlpha = " |
564 "clamp(0.5 - edgeAlpha / length(gF), 0.0, 1.0
);\n\t\t}\n"); | 566 "clamp(0.5 - edgeAlpha / length(gF), 0.0, 1.0
);\n\t\t}\n"); |
565 | 567 |
566 | 568 |
567 fsBuilder->codeAppendf("\t%s = %s;\n", outputColor, | 569 fsBuilder->codeAppendf("\t%s = %s;\n", outputColor, |
568 (GrGLSLExpr4(inputColor) * GrGLSLExpr1("edgeA
lpha")).c_str()); | 570 (GrGLSLExpr4(inputColor) * GrGLSLExpr1("edgeA
lpha")).c_str()); |
569 | 571 |
| 572 const GrShaderVar& inQuadEdge = drawEffect.castEffect<QuadEdgeEffect
>().inQuadEdge(); |
570 GrGLVertexShaderBuilder* vsBuilder = builder->getVertexShaderBuilder
(); | 573 GrGLVertexShaderBuilder* vsBuilder = builder->getVertexShaderBuilder
(); |
571 const SkString* attr0Name = | 574 vsBuilder->codeAppendf("\t%s = %s;\n", vsName, inQuadEdge.c_str()); |
572 vsBuilder->getEffectAttributeName(drawEffect.getVertexAttribIndi
ces()[0]); | |
573 vsBuilder->codeAppendf("\t%s = %s;\n", vsName, attr0Name->c_str()); | |
574 } | 575 } |
575 | 576 |
576 static inline void GenKey(const GrDrawEffect&, const GrGLCaps&, GrEffect
KeyBuilder*) {} | 577 static inline void GenKey(const GrDrawEffect&, const GrGLCaps&, GrEffect
KeyBuilder*) {} |
577 | 578 |
578 virtual void setData(const GrGLProgramDataManager&, const GrDrawEffect&)
SK_OVERRIDE {} | 579 virtual void setData(const GrGLProgramDataManager&, const GrDrawEffect&)
SK_OVERRIDE {} |
579 | 580 |
580 private: | 581 private: |
581 typedef GrGLVertexEffect INHERITED; | 582 typedef GrGLGeometryProcessor INHERITED; |
582 }; | 583 }; |
583 | 584 |
584 private: | 585 private: |
585 QuadEdgeEffect() { | 586 QuadEdgeEffect() |
586 this->addVertexAttrib(kVec4f_GrSLType); | 587 : fInQuadEdge(this->addVertexAttrib(GrShaderVar("inQuadEdge", |
| 588 kVec4f_GrSLType, |
| 589 GrShaderVar::kAttribute_
TypeModifier))) { |
587 } | 590 } |
588 | 591 |
589 virtual bool onIsEqual(const GrEffect& other) const SK_OVERRIDE { | 592 virtual bool onIsEqual(const GrEffect& other) const SK_OVERRIDE { |
590 return true; | 593 return true; |
591 } | 594 } |
592 | 595 |
| 596 const GrShaderVar& fInQuadEdge; |
| 597 |
593 GR_DECLARE_EFFECT_TEST; | 598 GR_DECLARE_EFFECT_TEST; |
594 | 599 |
595 typedef GrEffect INHERITED; | 600 typedef GrEffect INHERITED; |
596 }; | 601 }; |
597 | 602 |
598 GR_DEFINE_EFFECT_TEST(QuadEdgeEffect); | 603 GR_DEFINE_EFFECT_TEST(QuadEdgeEffect); |
599 | 604 |
600 GrEffect* QuadEdgeEffect::TestCreate(SkRandom* random, | 605 GrEffect* QuadEdgeEffect::TestCreate(SkRandom* random, |
601 GrContext*, | 606 GrContext*, |
602 const GrDrawTargetCaps& caps, | 607 const GrDrawTargetCaps& caps, |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
669 SkRect devBounds; | 674 SkRect devBounds; |
670 if (!get_segments(*path, viewMatrix, &segments, &fanPt, &vCount, &iCount, &d
evBounds)) { | 675 if (!get_segments(*path, viewMatrix, &segments, &fanPt, &vCount, &iCount, &d
evBounds)) { |
671 return false; | 676 return false; |
672 } | 677 } |
673 | 678 |
674 // Our computed verts should all be within one pixel of the segment control
points. | 679 // Our computed verts should all be within one pixel of the segment control
points. |
675 devBounds.outset(SK_Scalar1, SK_Scalar1); | 680 devBounds.outset(SK_Scalar1, SK_Scalar1); |
676 | 681 |
677 drawState->setVertexAttribs<gPathAttribs>(SK_ARRAY_COUNT(gPathAttribs), size
of(QuadVertex)); | 682 drawState->setVertexAttribs<gPathAttribs>(SK_ARRAY_COUNT(gPathAttribs), size
of(QuadVertex)); |
678 | 683 |
679 static const int kEdgeAttrIndex = 1; | |
680 GrEffect* quadEffect = QuadEdgeEffect::Create(); | 684 GrEffect* quadEffect = QuadEdgeEffect::Create(); |
681 drawState->setGeometryProcessor(quadEffect, kEdgeAttrIndex)->unref(); | 685 drawState->setGeometryProcessor(quadEffect)->unref(); |
682 | 686 |
683 GrDrawTarget::AutoReleaseGeometry arg(target, vCount, iCount); | 687 GrDrawTarget::AutoReleaseGeometry arg(target, vCount, iCount); |
684 if (!arg.succeeded()) { | 688 if (!arg.succeeded()) { |
685 return false; | 689 return false; |
686 } | 690 } |
687 verts = reinterpret_cast<QuadVertex*>(arg.vertices()); | 691 verts = reinterpret_cast<QuadVertex*>(arg.vertices()); |
688 idxs = reinterpret_cast<uint16_t*>(arg.indices()); | 692 idxs = reinterpret_cast<uint16_t*>(arg.indices()); |
689 | 693 |
690 SkSTArray<kPreallocDrawCnt, Draw, true> draws; | 694 SkSTArray<kPreallocDrawCnt, Draw, true> draws; |
691 create_vertices(segments, fanPt, &draws, verts, idxs); | 695 create_vertices(segments, fanPt, &draws, verts, idxs); |
(...skipping 17 matching lines...) Expand all Loading... |
709 vOffset, // start vertex | 713 vOffset, // start vertex |
710 0, // start index | 714 0, // start index |
711 draw.fVertexCnt, | 715 draw.fVertexCnt, |
712 draw.fIndexCnt, | 716 draw.fIndexCnt, |
713 &devBounds); | 717 &devBounds); |
714 vOffset += draw.fVertexCnt; | 718 vOffset += draw.fVertexCnt; |
715 } | 719 } |
716 | 720 |
717 return true; | 721 return true; |
718 } | 722 } |
OLD | NEW |