Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(70)

Side by Side Diff: src/gpu/GrAAConvexPathRenderer.cpp

Issue 543623004: Removing vertex attrib indices (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: feedback inc Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 const GrShaderVar kAttrQuadEdge("aQuadEdge",
bsalomon 2014/09/08 21:17:50 Chrome doesn't allow us to have statically initial
508 kVec4f_GrSLType,
509 GrShaderVar::kAttribute_TypeModifier);
510
511 class QuadEdgeEffect : public GrGeometryProcessor {
508 public: 512 public:
509 513
510 static GrEffect* Create() { 514 static GrEffect* Create() {
511 GR_CREATE_STATIC_EFFECT(gQuadEdgeEffect, QuadEdgeEffect, ()); 515 GR_CREATE_STATIC_EFFECT(gQuadEdgeEffect, QuadEdgeEffect, ());
512 gQuadEdgeEffect->ref(); 516 gQuadEdgeEffect->ref();
513 return gQuadEdgeEffect; 517 return gQuadEdgeEffect;
514 } 518 }
515 519
516 virtual ~QuadEdgeEffect() {} 520 virtual ~QuadEdgeEffect() {}
517 521
518 static const char* Name() { return "QuadEdge"; } 522 static const char* Name() { return "QuadEdge"; }
519 523
520 virtual void getConstantColorComponents(GrColor* color, 524 virtual void getConstantColorComponents(GrColor* color,
521 uint32_t* validFlags) const SK_OVERR IDE { 525 uint32_t* validFlags) const SK_OVERR IDE {
522 *validFlags = 0; 526 *validFlags = 0;
523 } 527 }
524 528
525 virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE { 529 virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE {
526 return GrTBackendEffectFactory<QuadEdgeEffect>::getInstance(); 530 return GrTBackendEffectFactory<QuadEdgeEffect>::getInstance();
527 } 531 }
528 532
529 class GLEffect : public GrGLVertexEffect { 533 class GLEffect : public GrGLGeometryProcessor {
530 public: 534 public:
531 GLEffect(const GrBackendEffectFactory& factory, const GrDrawEffect&) 535 GLEffect(const GrBackendEffectFactory& factory, const GrDrawEffect&)
532 : INHERITED (factory) {} 536 : INHERITED (factory) {}
533 537
534 virtual void emitCode(GrGLFullProgramBuilder* builder, 538 virtual void emitCode(GrGLFullProgramBuilder* builder,
535 const GrDrawEffect& drawEffect, 539 const GrDrawEffect& drawEffect,
536 const GrEffectKey& key, 540 const GrEffectKey& key,
537 const char* outputColor, 541 const char* outputColor,
538 const char* inputColor, 542 const char* inputColor,
539 const TransformedCoordsArray&, 543 const TransformedCoordsArray&,
(...skipping 21 matching lines...) Expand all
561 fsBuilder->codeAppendf("\t\t\tedgeAlpha = (%s.x*%s.x - %s.y);\n", fs Name, fsName, 565 fsBuilder->codeAppendf("\t\t\tedgeAlpha = (%s.x*%s.x - %s.y);\n", fs Name, fsName,
562 fsName); 566 fsName);
563 fsBuilder->codeAppendf("\t\t\tedgeAlpha = " 567 fsBuilder->codeAppendf("\t\t\tedgeAlpha = "
564 "clamp(0.5 - edgeAlpha / length(gF), 0.0, 1.0 );\n\t\t}\n"); 568 "clamp(0.5 - edgeAlpha / length(gF), 0.0, 1.0 );\n\t\t}\n");
565 569
566 570
567 fsBuilder->codeAppendf("\t%s = %s;\n", outputColor, 571 fsBuilder->codeAppendf("\t%s = %s;\n", outputColor,
568 (GrGLSLExpr4(inputColor) * GrGLSLExpr1("edgeA lpha")).c_str()); 572 (GrGLSLExpr4(inputColor) * GrGLSLExpr1("edgeA lpha")).c_str());
569 573
570 GrGLVertexShaderBuilder* vsBuilder = builder->getVertexShaderBuilder (); 574 GrGLVertexShaderBuilder* vsBuilder = builder->getVertexShaderBuilder ();
571 const SkString* attr0Name = 575 vsBuilder->codeAppendf("\t%s = %s;\n", vsName, kAttrQuadEdge.c_str() );
572 vsBuilder->getEffectAttributeName(drawEffect.getVertexAttribIndi ces()[0]);
573 vsBuilder->codeAppendf("\t%s = %s;\n", vsName, attr0Name->c_str());
574 } 576 }
575 577
576 static inline void GenKey(const GrDrawEffect&, const GrGLCaps&, GrEffect KeyBuilder*) {} 578 static inline void GenKey(const GrDrawEffect&, const GrGLCaps&, GrEffect KeyBuilder*) {}
577 579
578 virtual void setData(const GrGLProgramDataManager&, const GrDrawEffect&) SK_OVERRIDE {} 580 virtual void setData(const GrGLProgramDataManager&, const GrDrawEffect&) SK_OVERRIDE {}
579 581
580 private: 582 private:
581 typedef GrGLVertexEffect INHERITED; 583 typedef GrGLGeometryProcessor INHERITED;
582 }; 584 };
583 585
584 private: 586 private:
585 QuadEdgeEffect() { 587 QuadEdgeEffect() {
586 this->addVertexAttrib(kVec4f_GrSLType); 588 this->addVertexAttrib(kAttrQuadEdge);
587 } 589 }
588 590
589 virtual bool onIsEqual(const GrEffect& other) const SK_OVERRIDE { 591 virtual bool onIsEqual(const GrEffect& other) const SK_OVERRIDE {
590 return true; 592 return true;
591 } 593 }
592 594
593 GR_DECLARE_EFFECT_TEST; 595 GR_DECLARE_EFFECT_TEST;
594 596
595 typedef GrEffect INHERITED; 597 typedef GrEffect INHERITED;
596 }; 598 };
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
669 SkRect devBounds; 671 SkRect devBounds;
670 if (!get_segments(*path, viewMatrix, &segments, &fanPt, &vCount, &iCount, &d evBounds)) { 672 if (!get_segments(*path, viewMatrix, &segments, &fanPt, &vCount, &iCount, &d evBounds)) {
671 return false; 673 return false;
672 } 674 }
673 675
674 // Our computed verts should all be within one pixel of the segment control points. 676 // Our computed verts should all be within one pixel of the segment control points.
675 devBounds.outset(SK_Scalar1, SK_Scalar1); 677 devBounds.outset(SK_Scalar1, SK_Scalar1);
676 678
677 drawState->setVertexAttribs<gPathAttribs>(SK_ARRAY_COUNT(gPathAttribs), size of(QuadVertex)); 679 drawState->setVertexAttribs<gPathAttribs>(SK_ARRAY_COUNT(gPathAttribs), size of(QuadVertex));
678 680
679 static const int kEdgeAttrIndex = 1;
680 GrEffect* quadEffect = QuadEdgeEffect::Create(); 681 GrEffect* quadEffect = QuadEdgeEffect::Create();
681 drawState->setGeometryProcessor(quadEffect, kEdgeAttrIndex)->unref(); 682 drawState->setGeometryProcessor(quadEffect)->unref();
682 683
683 GrDrawTarget::AutoReleaseGeometry arg(target, vCount, iCount); 684 GrDrawTarget::AutoReleaseGeometry arg(target, vCount, iCount);
684 if (!arg.succeeded()) { 685 if (!arg.succeeded()) {
685 return false; 686 return false;
686 } 687 }
687 verts = reinterpret_cast<QuadVertex*>(arg.vertices()); 688 verts = reinterpret_cast<QuadVertex*>(arg.vertices());
688 idxs = reinterpret_cast<uint16_t*>(arg.indices()); 689 idxs = reinterpret_cast<uint16_t*>(arg.indices());
689 690
690 SkSTArray<kPreallocDrawCnt, Draw, true> draws; 691 SkSTArray<kPreallocDrawCnt, Draw, true> draws;
691 create_vertices(segments, fanPt, &draws, verts, idxs); 692 create_vertices(segments, fanPt, &draws, verts, idxs);
(...skipping 17 matching lines...) Expand all
709 vOffset, // start vertex 710 vOffset, // start vertex
710 0, // start index 711 0, // start index
711 draw.fVertexCnt, 712 draw.fVertexCnt,
712 draw.fIndexCnt, 713 draw.fIndexCnt,
713 &devBounds); 714 &devBounds);
714 vOffset += draw.fVertexCnt; 715 vOffset += draw.fVertexCnt;
715 } 716 }
716 717
717 return true; 718 return true;
718 } 719 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698