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

Side by Side Diff: src/gpu/effects/GrDashingEffect.cpp

Issue 746423007: Draft change to start pulling uniform color into GP (Closed) Base URL: https://skia.googlesource.com/skia.git@no_factories
Patch Set: cleanup Created 6 years 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 * Copyright 2014 Google Inc. 2 * Copyright 2014 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "GrDashingEffect.h" 8 #include "GrDashingEffect.h"
9 9
10 #include "../GrAARectRenderer.h" 10 #include "../GrAARectRenderer.h"
(...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after
434 434
435 target->setIndexSourceToBuffer(gpu->getContext()->getQuadIndexBuffer()); 435 target->setIndexSourceToBuffer(gpu->getContext()->getQuadIndexBuffer());
436 target->drawIndexedInstances(drawState, gp, kTriangles_GrPrimitiveType, tota lRectCnt, 4, 6); 436 target->drawIndexedInstances(drawState, gp, kTriangles_GrPrimitiveType, tota lRectCnt, 4, 6);
437 target->resetIndexSource(); 437 target->resetIndexSource();
438 return true; 438 return true;
439 } 439 }
440 440
441 ////////////////////////////////////////////////////////////////////////////// 441 //////////////////////////////////////////////////////////////////////////////
442 442
443 class GLDashingCircleEffect; 443 class GLDashingCircleEffect;
444
445 struct DashingCircleBatchTracker {
446 GPInput fInputColorType;
447 GrColor fColor;
448 };
449
444 /* 450 /*
445 * This effect will draw a dotted line (defined as a dashed lined with round cap s and no on 451 * This effect will draw a dotted line (defined as a dashed lined with round cap s and no on
446 * interval). The radius of the dots is given by the strokeWidth and the spacing by the DashInfo. 452 * interval). The radius of the dots is given by the strokeWidth and the spacing by the DashInfo.
447 * Both of the previous two parameters are in device space. This effect also req uires the setting of 453 * Both of the previous two parameters are in device space. This effect also req uires the setting of
448 * a vec2 vertex attribute for the the four corners of the bounding rect. This a ttribute is the 454 * a vec2 vertex attribute for the the four corners of the bounding rect. This a ttribute is the
449 * "dash position" of each vertex. In other words it is the vertex coords (in de vice space) if we 455 * "dash position" of each vertex. In other words it is the vertex coords (in de vice space) if we
450 * transform the line to be horizontal, with the start of line at the origin the n shifted to the 456 * transform the line to be horizontal, with the start of line at the origin the n shifted to the
451 * right by half the off interval. The line then goes in the positive x directio n. 457 * right by half the off interval. The line then goes in the positive x directio n.
452 */ 458 */
453 class DashingCircleEffect : public GrGeometryProcessor { 459 class DashingCircleEffect : public GrGeometryProcessor {
(...skipping 20 matching lines...) Expand all
474 SkScalar getCenterX() const { return fCenterX; } 480 SkScalar getCenterX() const { return fCenterX; }
475 481
476 SkScalar getIntervalLength() const { return fIntervalLength; } 482 SkScalar getIntervalLength() const { return fIntervalLength; }
477 483
478 virtual void getGLProcessorKey(const GrBatchTracker&, 484 virtual void getGLProcessorKey(const GrBatchTracker&,
479 const GrGLCaps&, 485 const GrGLCaps&,
480 GrProcessorKeyBuilder* b) const SK_OVERRIDE; 486 GrProcessorKeyBuilder* b) const SK_OVERRIDE;
481 487
482 virtual GrGLGeometryProcessor* createGLInstance(const GrBatchTracker&) const SK_OVERRIDE; 488 virtual GrGLGeometryProcessor* createGLInstance(const GrBatchTracker&) const SK_OVERRIDE;
483 489
490 void initBatchTracker(GrBatchTracker* bt, const InitBT& init) const SK_OVERR IDE;
491
492 bool onCanBatch(const GrBatchTracker& l, const GrBatchTracker& r) const SK_O VERRIDE;
493
484 private: 494 private:
485 DashingCircleEffect(GrColor, GrPrimitiveEdgeType edgeType, const DashInfo& i nfo, 495 DashingCircleEffect(GrColor, GrPrimitiveEdgeType edgeType, const DashInfo& i nfo,
486 SkScalar radius); 496 SkScalar radius);
487 497
488 virtual bool onIsEqual(const GrGeometryProcessor& other) const SK_OVERRIDE; 498 virtual bool onIsEqual(const GrGeometryProcessor& other) const SK_OVERRIDE;
489 499
490 virtual void onGetInvariantOutputCoverage(GrInitInvariantOutput*) const SK_O VERRIDE; 500 virtual void onGetInvariantOutputCoverage(GrInitInvariantOutput*) const SK_O VERRIDE;
491 501
492 GrPrimitiveEdgeType fEdgeType; 502 GrPrimitiveEdgeType fEdgeType;
493 const GrAttribute* fInPosition; 503 const GrAttribute* fInPosition;
(...skipping 18 matching lines...) Expand all
512 static inline void GenKey(const GrGeometryProcessor&, 522 static inline void GenKey(const GrGeometryProcessor&,
513 const GrBatchTracker&, 523 const GrBatchTracker&,
514 const GrGLCaps&, 524 const GrGLCaps&,
515 GrProcessorKeyBuilder*); 525 GrProcessorKeyBuilder*);
516 526
517 virtual void setData(const GrGLProgramDataManager&, 527 virtual void setData(const GrGLProgramDataManager&,
518 const GrGeometryProcessor&, 528 const GrGeometryProcessor&,
519 const GrBatchTracker&) SK_OVERRIDE; 529 const GrBatchTracker&) SK_OVERRIDE;
520 530
521 private: 531 private:
522 GrGLProgramDataManager::UniformHandle fParamUniform; 532 UniformHandle fParamUniform;
523 SkScalar fPrevRadius; 533 UniformHandle fColorUniform;
524 SkScalar fPrevCenterX; 534 SkScalar fPrevRadius;
525 SkScalar fPrevIntervalLength; 535 SkScalar fPrevCenterX;
536 SkScalar fPrevIntervalLength;
526 typedef GrGLGeometryProcessor INHERITED; 537 typedef GrGLGeometryProcessor INHERITED;
527 }; 538 };
528 539
529 GLDashingCircleEffect::GLDashingCircleEffect(const GrGeometryProcessor&, 540 GLDashingCircleEffect::GLDashingCircleEffect(const GrGeometryProcessor&,
530 const GrBatchTracker&) { 541 const GrBatchTracker&) {
531 fPrevRadius = SK_ScalarMin; 542 fPrevRadius = SK_ScalarMin;
532 fPrevCenterX = SK_ScalarMin; 543 fPrevCenterX = SK_ScalarMin;
533 fPrevIntervalLength = SK_ScalarMax; 544 fPrevIntervalLength = SK_ScalarMax;
534 } 545 }
535 546
536 void GLDashingCircleEffect::emitCode(const EmitArgs& args) { 547 void GLDashingCircleEffect::emitCode(const EmitArgs& args) {
537 const DashingCircleEffect& dce = args.fGP.cast<DashingCircleEffect>(); 548 const DashingCircleEffect& dce = args.fGP.cast<DashingCircleEffect>();
549 const DashingCircleBatchTracker local = args.fBT.cast<DashingCircleBatchTrac ker>();
550 GrGLGPBuilder* pb = args.fPB;
538 const char *paramName; 551 const char *paramName;
539 // The param uniforms, xyz, refer to circle radius - 0.5, cicles center x co ord, and 552 // The param uniforms, xyz, refer to circle radius - 0.5, cicles center x co ord, and
540 // the total interval length of the dash. 553 // the total interval length of the dash.
541 fParamUniform = args.fPB->addUniform(GrGLProgramBuilder::kFragment_Visibilit y, 554 fParamUniform = args.fPB->addUniform(GrGLProgramBuilder::kFragment_Visibilit y,
542 kVec3f_GrSLType, kDefault_GrSLPrecision , 555 kVec3f_GrSLType, kDefault_GrSLPrecision ,
543 "params", &paramName); 556 "params", &paramName);
544 557
545 GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder(); 558 GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder();
546 559
547 GrGLVertToFrag v(kVec2f_GrSLType); 560 GrGLVertToFrag v(kVec2f_GrSLType);
548 args.fPB->addVarying("Coord", &v); 561 args.fPB->addVarying("Coord", &v);
549 vsBuilder->codeAppendf("%s = %s;", v.vsOut(), dce.inCoord()->fName); 562 vsBuilder->codeAppendf("%s = %s;", v.vsOut(), dce.inCoord()->fName);
550 563
564 // Setup pass through color
565 this->setupColor(pb, local.fInputColorType, args.fOutputColor, NULL, &fColor Uniform);
566
551 // setup coord outputs 567 // setup coord outputs
552 vsBuilder->codeAppendf("%s = %s;", vsBuilder->positionCoords(), dce.inPositi on()->fName); 568 vsBuilder->codeAppendf("%s = %s;", vsBuilder->positionCoords(), dce.inPositi on()->fName);
553 vsBuilder->codeAppendf("%s = %s;", vsBuilder->localCoords(), dce.inPosition( )->fName); 569 vsBuilder->codeAppendf("%s = %s;", vsBuilder->localCoords(), dce.inPosition( )->fName);
554 570
555 // setup position varying 571 // setup position varying
556 vsBuilder->codeAppendf("%s = %s * vec3(%s, 1);", vsBuilder->glPosition(), vs Builder->uViewM(), 572 vsBuilder->codeAppendf("%s = %s * vec3(%s, 1);", vsBuilder->glPosition(), vs Builder->uViewM(),
557 dce.inPosition()->fName); 573 dce.inPosition()->fName);
558 574
559 // transforms all points so that we can compare them to our test circle 575 // transforms all points so that we can compare them to our test circle
560 GrGLGPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder(); 576 GrGLGPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder();
561 fsBuilder->codeAppendf("\t\tfloat xShifted = %s.x - floor(%s.x / %s.z) * %s. z;\n", 577 fsBuilder->codeAppendf("\t\tfloat xShifted = %s.x - floor(%s.x / %s.z) * %s. z;\n",
562 v.fsIn(), v.fsIn(), paramName, paramName); 578 v.fsIn(), v.fsIn(), paramName, paramName);
563 fsBuilder->codeAppendf("\t\tvec2 fragPosShifted = vec2(xShifted, %s.y);\n", v.fsIn()); 579 fsBuilder->codeAppendf("\t\tvec2 fragPosShifted = vec2(xShifted, %s.y);\n", v.fsIn());
564 fsBuilder->codeAppendf("\t\tvec2 center = vec2(%s.y, 0.0);\n", paramName); 580 fsBuilder->codeAppendf("\t\tvec2 center = vec2(%s.y, 0.0);\n", paramName);
565 fsBuilder->codeAppend("\t\tfloat dist = length(center - fragPosShifted);\n") ; 581 fsBuilder->codeAppend("\t\tfloat dist = length(center - fragPosShifted);\n") ;
566 if (GrProcessorEdgeTypeIsAA(dce.getEdgeType())) { 582 if (GrProcessorEdgeTypeIsAA(dce.getEdgeType())) {
567 fsBuilder->codeAppendf("\t\tfloat diff = dist - %s.x;\n", paramName); 583 fsBuilder->codeAppendf("\t\tfloat diff = dist - %s.x;\n", paramName);
568 fsBuilder->codeAppend("\t\tdiff = 1.0 - diff;\n"); 584 fsBuilder->codeAppend("\t\tdiff = 1.0 - diff;\n");
569 fsBuilder->codeAppend("\t\tfloat alpha = clamp(diff, 0.0, 1.0);\n"); 585 fsBuilder->codeAppend("\t\tfloat alpha = clamp(diff, 0.0, 1.0);\n");
570 } else { 586 } else {
571 fsBuilder->codeAppendf("\t\tfloat alpha = 1.0;\n"); 587 fsBuilder->codeAppendf("\t\tfloat alpha = 1.0;\n");
572 fsBuilder->codeAppendf("\t\talpha *= dist < %s.x + 0.5 ? 1.0 : 0.0;\n", paramName); 588 fsBuilder->codeAppendf("\t\talpha *= dist < %s.x + 0.5 ? 1.0 : 0.0;\n", paramName);
573 } 589 }
574 fsBuilder->codeAppendf("%s = vec4(alpha);", args.fOutputCoverage); 590 fsBuilder->codeAppendf("%s = vec4(alpha);", args.fOutputCoverage);
575 } 591 }
576 592
577 void GLDashingCircleEffect::setData(const GrGLProgramDataManager& pdman, 593 void GLDashingCircleEffect::setData(const GrGLProgramDataManager& pdman,
578 const GrGeometryProcessor& processor, 594 const GrGeometryProcessor& processor,
579 const GrBatchTracker&) { 595 const GrBatchTracker& bt) {
580 const DashingCircleEffect& dce = processor.cast<DashingCircleEffect>(); 596 const DashingCircleEffect& dce = processor.cast<DashingCircleEffect>();
581 SkScalar radius = dce.getRadius(); 597 SkScalar radius = dce.getRadius();
582 SkScalar centerX = dce.getCenterX(); 598 SkScalar centerX = dce.getCenterX();
583 SkScalar intervalLength = dce.getIntervalLength(); 599 SkScalar intervalLength = dce.getIntervalLength();
584 if (radius != fPrevRadius || centerX != fPrevCenterX || intervalLength != fP revIntervalLength) { 600 if (radius != fPrevRadius || centerX != fPrevCenterX || intervalLength != fP revIntervalLength) {
585 pdman.set3f(fParamUniform, radius - 0.5f, centerX, intervalLength); 601 pdman.set3f(fParamUniform, radius - 0.5f, centerX, intervalLength);
586 fPrevRadius = radius; 602 fPrevRadius = radius;
587 fPrevCenterX = centerX; 603 fPrevCenterX = centerX;
588 fPrevIntervalLength = intervalLength; 604 fPrevIntervalLength = intervalLength;
589 } 605 }
606
607 const DashingCircleBatchTracker& local = bt.cast<DashingCircleBatchTracker>( );
608 this->setUniformColorIfRequired(pdman, local.fInputColorType, local.fColor,
609 fColorUniform);
590 } 610 }
591 611
592 void GLDashingCircleEffect::GenKey(const GrGeometryProcessor& processor, 612 void GLDashingCircleEffect::GenKey(const GrGeometryProcessor& processor,
593 const GrBatchTracker&, 613 const GrBatchTracker& bt,
594 const GrGLCaps&, 614 const GrGLCaps&,
595 GrProcessorKeyBuilder* b) { 615 GrProcessorKeyBuilder* b) {
616 const DashingCircleBatchTracker& local = bt.cast<DashingCircleBatchTracker>( );
596 const DashingCircleEffect& dce = processor.cast<DashingCircleEffect>(); 617 const DashingCircleEffect& dce = processor.cast<DashingCircleEffect>();
597 b->add32(dce.getEdgeType()); 618 b->add32(dce.getEdgeType() << 16 | local.fInputColorType);
598 } 619 }
599 620
600 ////////////////////////////////////////////////////////////////////////////// 621 //////////////////////////////////////////////////////////////////////////////
601 622
602 GrGeometryProcessor* DashingCircleEffect::Create(GrColor color, 623 GrGeometryProcessor* DashingCircleEffect::Create(GrColor color,
603 GrPrimitiveEdgeType edgeType, 624 GrPrimitiveEdgeType edgeType,
604 const DashInfo& info, 625 const DashInfo& info,
605 SkScalar radius) { 626 SkScalar radius) {
606 if (info.fCount != 2 || info.fIntervals[0] != 0) { 627 if (info.fCount != 2 || info.fIntervals[0] != 0) {
607 return NULL; 628 return NULL;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
642 } 663 }
643 664
644 bool DashingCircleEffect::onIsEqual(const GrGeometryProcessor& other) const { 665 bool DashingCircleEffect::onIsEqual(const GrGeometryProcessor& other) const {
645 const DashingCircleEffect& dce = other.cast<DashingCircleEffect>(); 666 const DashingCircleEffect& dce = other.cast<DashingCircleEffect>();
646 return (fEdgeType == dce.fEdgeType && 667 return (fEdgeType == dce.fEdgeType &&
647 fIntervalLength == dce.fIntervalLength && 668 fIntervalLength == dce.fIntervalLength &&
648 fRadius == dce.fRadius && 669 fRadius == dce.fRadius &&
649 fCenterX == dce.fCenterX); 670 fCenterX == dce.fCenterX);
650 } 671 }
651 672
673 void DashingCircleEffect::initBatchTracker(GrBatchTracker* bt, const InitBT& ini t) const {
674 DashingCircleBatchTracker* local = bt->cast<DashingCircleBatchTracker>();
675
676 // We will ignore this color unless we have uniform color
677 local->fColor = init.fColor;
678 local->fInputColorType = GetColorInputType(init, false);
679 }
680
681 bool DashingCircleEffect::onCanBatch(const GrBatchTracker& l, const GrBatchTrack er& r) const {
682 const DashingCircleBatchTracker& left = l.cast<DashingCircleBatchTracker>();
683 const DashingCircleBatchTracker& right = r.cast<DashingCircleBatchTracker>() ;
684 return CanCombineOutput(left.fInputColorType, left.fColor,
685 right.fInputColorType, right.fColor);
686 }
687
652 GR_DEFINE_GEOMETRY_PROCESSOR_TEST(DashingCircleEffect); 688 GR_DEFINE_GEOMETRY_PROCESSOR_TEST(DashingCircleEffect);
653 689
654 GrGeometryProcessor* DashingCircleEffect::TestCreate(SkRandom* random, 690 GrGeometryProcessor* DashingCircleEffect::TestCreate(SkRandom* random,
655 GrContext*, 691 GrContext*,
656 const GrDrawTargetCaps& cap s, 692 const GrDrawTargetCaps& cap s,
657 GrTexture*[]) { 693 GrTexture*[]) {
658 GrPrimitiveEdgeType edgeType = static_cast<GrPrimitiveEdgeType>(random->next ULessThan( 694 GrPrimitiveEdgeType edgeType = static_cast<GrPrimitiveEdgeType>(random->next ULessThan(
659 kGrProcessorEdgeTypeCnt)); 695 kGrProcessorEdgeTypeCnt));
660 SkScalar strokeWidth = random->nextRangeScalar(0, 100.f); 696 SkScalar strokeWidth = random->nextRangeScalar(0, 100.f);
661 DashInfo info; 697 DashInfo info;
662 info.fCount = 2; 698 info.fCount = 2;
663 SkAutoTArray<SkScalar> intervals(info.fCount); 699 SkAutoTArray<SkScalar> intervals(info.fCount);
664 info.fIntervals = intervals.get(); 700 info.fIntervals = intervals.get();
665 info.fIntervals[0] = 0; 701 info.fIntervals[0] = 0;
666 info.fIntervals[1] = random->nextRangeScalar(0, 10.f); 702 info.fIntervals[1] = random->nextRangeScalar(0, 10.f);
667 info.fPhase = random->nextRangeScalar(0, info.fIntervals[1]); 703 info.fPhase = random->nextRangeScalar(0, info.fIntervals[1]);
668 704
669 return DashingCircleEffect::Create(GrRandomColor(random), edgeType, info, st rokeWidth); 705 return DashingCircleEffect::Create(GrRandomColor(random), edgeType, info, st rokeWidth);
670 } 706 }
671 707
672 ////////////////////////////////////////////////////////////////////////////// 708 //////////////////////////////////////////////////////////////////////////////
673 709
674 class GLDashingLineEffect; 710 class GLDashingLineEffect;
675 711
712 struct DashingLineBatchTracker {
713 GPInput fInputColorType;
714 GrColor fColor;
715 };
716
676 /* 717 /*
677 * This effect will draw a dashed line. The width of the dash is given by the st rokeWidth and the 718 * This effect will draw a dashed line. The width of the dash is given by the st rokeWidth and the
678 * length and spacing by the DashInfo. Both of the previous two parameters are i n device space. 719 * length and spacing by the DashInfo. Both of the previous two parameters are i n device space.
679 * This effect also requires the setting of a vec2 vertex attribute for the the four corners of the 720 * This effect also requires the setting of a vec2 vertex attribute for the the four corners of the
680 * bounding rect. This attribute is the "dash position" of each vertex. In other words it is the 721 * bounding rect. This attribute is the "dash position" of each vertex. In other words it is the
681 * vertex coords (in device space) if we transform the line to be horizontal, wi th the start of 722 * vertex coords (in device space) if we transform the line to be horizontal, wi th the start of
682 * line at the origin then shifted to the right by half the off interval. The li ne then goes in the 723 * line at the origin then shifted to the right by half the off interval. The li ne then goes in the
683 * positive x direction. 724 * positive x direction.
684 */ 725 */
685 class DashingLineEffect : public GrGeometryProcessor { 726 class DashingLineEffect : public GrGeometryProcessor {
(...skipping 18 matching lines...) Expand all
704 const SkRect& getRect() const { return fRect; } 745 const SkRect& getRect() const { return fRect; }
705 746
706 SkScalar getIntervalLength() const { return fIntervalLength; } 747 SkScalar getIntervalLength() const { return fIntervalLength; }
707 748
708 virtual void getGLProcessorKey(const GrBatchTracker& bt, 749 virtual void getGLProcessorKey(const GrBatchTracker& bt,
709 const GrGLCaps& caps, 750 const GrGLCaps& caps,
710 GrProcessorKeyBuilder* b) const SK_OVERRIDE; 751 GrProcessorKeyBuilder* b) const SK_OVERRIDE;
711 752
712 virtual GrGLGeometryProcessor* createGLInstance(const GrBatchTracker& bt) co nst SK_OVERRIDE; 753 virtual GrGLGeometryProcessor* createGLInstance(const GrBatchTracker& bt) co nst SK_OVERRIDE;
713 754
755 void initBatchTracker(GrBatchTracker* bt, const InitBT& init) const SK_OVERR IDE;
756
757 bool onCanBatch(const GrBatchTracker& l, const GrBatchTracker& r) const SK_O VERRIDE;
758
714 private: 759 private:
715 DashingLineEffect(GrColor, GrPrimitiveEdgeType edgeType, const DashInfo& inf o, 760 DashingLineEffect(GrColor, GrPrimitiveEdgeType edgeType, const DashInfo& inf o,
716 SkScalar strokeWidth); 761 SkScalar strokeWidth);
717 762
718 virtual bool onIsEqual(const GrGeometryProcessor& other) const SK_OVERRIDE; 763 virtual bool onIsEqual(const GrGeometryProcessor& other) const SK_OVERRIDE;
719 764
720 virtual void onGetInvariantOutputCoverage(GrInitInvariantOutput*) const SK_O VERRIDE; 765 virtual void onGetInvariantOutputCoverage(GrInitInvariantOutput*) const SK_O VERRIDE;
721 766
722 GrPrimitiveEdgeType fEdgeType; 767 GrPrimitiveEdgeType fEdgeType;
723 const GrAttribute* fInPosition; 768 const GrAttribute* fInPosition;
(...skipping 17 matching lines...) Expand all
741 static inline void GenKey(const GrGeometryProcessor&, 786 static inline void GenKey(const GrGeometryProcessor&,
742 const GrBatchTracker&, 787 const GrBatchTracker&,
743 const GrGLCaps&, 788 const GrGLCaps&,
744 GrProcessorKeyBuilder*); 789 GrProcessorKeyBuilder*);
745 790
746 virtual void setData(const GrGLProgramDataManager&, 791 virtual void setData(const GrGLProgramDataManager&,
747 const GrGeometryProcessor&, 792 const GrGeometryProcessor&,
748 const GrBatchTracker&) SK_OVERRIDE; 793 const GrBatchTracker&) SK_OVERRIDE;
749 794
750 private: 795 private:
751 GrGLProgramDataManager::UniformHandle fRectUniform; 796 UniformHandle fRectUniform;
752 GrGLProgramDataManager::UniformHandle fIntervalUniform; 797 UniformHandle fIntervalUniform;
753 SkRect fPrevRect; 798 UniformHandle fColorUniform;
754 SkScalar fPrevIntervalLength; 799 SkRect fPrevRect;
800 SkScalar fPrevIntervalLength;
755 typedef GrGLGeometryProcessor INHERITED; 801 typedef GrGLGeometryProcessor INHERITED;
756 }; 802 };
757 803
758 GLDashingLineEffect::GLDashingLineEffect(const GrGeometryProcessor&, 804 GLDashingLineEffect::GLDashingLineEffect(const GrGeometryProcessor&,
759 const GrBatchTracker&) { 805 const GrBatchTracker&) {
760 fPrevRect.fLeft = SK_ScalarNaN; 806 fPrevRect.fLeft = SK_ScalarNaN;
761 fPrevIntervalLength = SK_ScalarMax; 807 fPrevIntervalLength = SK_ScalarMax;
762 } 808 }
763 809
764 void GLDashingLineEffect::emitCode(const EmitArgs& args) { 810 void GLDashingLineEffect::emitCode(const EmitArgs& args) {
765 const DashingLineEffect& de = args.fGP.cast<DashingLineEffect>(); 811 const DashingLineEffect& de = args.fGP.cast<DashingLineEffect>();
812 const DashingLineBatchTracker& local = args.fBT.cast<DashingLineBatchTracker >();
813 GrGLGPBuilder* pb = args.fPB;
766 const char *rectName; 814 const char *rectName;
767 // The rect uniform's xyzw refer to (left + 0.5, top + 0.5, right - 0.5, bot tom - 0.5), 815 // The rect uniform's xyzw refer to (left + 0.5, top + 0.5, right - 0.5, bot tom - 0.5),
768 // respectively. 816 // respectively.
769 fRectUniform = args.fPB->addUniform(GrGLProgramBuilder::kFragment_Visibility , 817 fRectUniform = args.fPB->addUniform(GrGLProgramBuilder::kFragment_Visibility ,
770 kVec4f_GrSLType, kDefault_GrSLPrecision, 818 kVec4f_GrSLType, kDefault_GrSLPrecision,
771 "rect", 819 "rect",
772 &rectName); 820 &rectName);
773 const char *intervalName; 821 const char *intervalName;
774 // The interval uniform's refers to the total length of the interval (on + o ff) 822 // The interval uniform's refers to the total length of the interval (on + o ff)
775 fIntervalUniform = args.fPB->addUniform(GrGLProgramBuilder::kFragment_Visibi lity, 823 fIntervalUniform = args.fPB->addUniform(GrGLProgramBuilder::kFragment_Visibi lity,
776 kFloat_GrSLType, kDefault_GrSLPrecis ion, 824 kFloat_GrSLType, kDefault_GrSLPrecis ion,
777 "interval", 825 "interval",
778 &intervalName); 826 &intervalName);
779 827
780 828
781 GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder(); 829 GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder();
782 830
783 GrGLVertToFrag v(kVec2f_GrSLType); 831 GrGLVertToFrag v(kVec2f_GrSLType);
784 args.fPB->addVarying("Coord", &v); 832 args.fPB->addVarying("Coord", &v);
785 vsBuilder->codeAppendf("%s = %s;", v.vsOut(), de.inCoord()->fName); 833 vsBuilder->codeAppendf("%s = %s;", v.vsOut(), de.inCoord()->fName);
786 834
835 // Setup pass through color
836 this->setupColor(pb, local.fInputColorType, args.fOutputColor, NULL, &fColor Uniform);
837
787 // setup coord outputs 838 // setup coord outputs
788 vsBuilder->codeAppendf("%s = %s;", vsBuilder->positionCoords(), de.inPositio n()->fName); 839 vsBuilder->codeAppendf("%s = %s;", vsBuilder->positionCoords(), de.inPositio n()->fName);
789 vsBuilder->codeAppendf("%s = %s;", vsBuilder->localCoords(), de.inPosition() ->fName); 840 vsBuilder->codeAppendf("%s = %s;", vsBuilder->localCoords(), de.inPosition() ->fName);
790 841
791 // setup position varying 842 // setup position varying
792 vsBuilder->codeAppendf("%s = %s * vec3(%s, 1);", vsBuilder->glPosition(), vs Builder->uViewM(), 843 vsBuilder->codeAppendf("%s = %s * vec3(%s, 1);", vsBuilder->glPosition(), vs Builder->uViewM(),
793 de.inPosition()->fName); 844 de.inPosition()->fName);
794 845
795 // transforms all points so that we can compare them to our test rect 846 // transforms all points so that we can compare them to our test rect
796 GrGLGPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder(); 847 GrGLGPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder();
(...skipping 15 matching lines...) Expand all
812 // Assuming the bounding geometry is tight so no need to check y values 863 // Assuming the bounding geometry is tight so no need to check y values
813 fsBuilder->codeAppendf("\t\tfloat alpha = 1.0;\n"); 864 fsBuilder->codeAppendf("\t\tfloat alpha = 1.0;\n");
814 fsBuilder->codeAppendf("\t\talpha *= (fragPosShifted.x - %s.x) > -0.5 ? 1.0 : 0.0;\n", rectName); 865 fsBuilder->codeAppendf("\t\talpha *= (fragPosShifted.x - %s.x) > -0.5 ? 1.0 : 0.0;\n", rectName);
815 fsBuilder->codeAppendf("\t\talpha *= (%s.z - fragPosShifted.x) >= -0.5 ? 1.0 : 0.0;\n", rectName); 866 fsBuilder->codeAppendf("\t\talpha *= (%s.z - fragPosShifted.x) >= -0.5 ? 1.0 : 0.0;\n", rectName);
816 } 867 }
817 fsBuilder->codeAppendf("%s = vec4(alpha);", args.fOutputCoverage); 868 fsBuilder->codeAppendf("%s = vec4(alpha);", args.fOutputCoverage);
818 } 869 }
819 870
820 void GLDashingLineEffect::setData(const GrGLProgramDataManager& pdman, 871 void GLDashingLineEffect::setData(const GrGLProgramDataManager& pdman,
821 const GrGeometryProcessor& processor, 872 const GrGeometryProcessor& processor,
822 const GrBatchTracker&) { 873 const GrBatchTracker& bt) {
823 const DashingLineEffect& de = processor.cast<DashingLineEffect>(); 874 const DashingLineEffect& de = processor.cast<DashingLineEffect>();
824 const SkRect& rect = de.getRect(); 875 const SkRect& rect = de.getRect();
825 SkScalar intervalLength = de.getIntervalLength(); 876 SkScalar intervalLength = de.getIntervalLength();
826 if (rect != fPrevRect || intervalLength != fPrevIntervalLength) { 877 if (rect != fPrevRect || intervalLength != fPrevIntervalLength) {
827 pdman.set4f(fRectUniform, rect.fLeft + 0.5f, rect.fTop + 0.5f, 878 pdman.set4f(fRectUniform, rect.fLeft + 0.5f, rect.fTop + 0.5f,
828 rect.fRight - 0.5f, rect.fBottom - 0.5f); 879 rect.fRight - 0.5f, rect.fBottom - 0.5f);
829 pdman.set1f(fIntervalUniform, intervalLength); 880 pdman.set1f(fIntervalUniform, intervalLength);
830 fPrevRect = rect; 881 fPrevRect = rect;
831 fPrevIntervalLength = intervalLength; 882 fPrevIntervalLength = intervalLength;
832 } 883 }
884
885 const DashingLineBatchTracker& local = bt.cast<DashingLineBatchTracker>();
886 this->setUniformColorIfRequired(pdman, local.fInputColorType, local.fColor, fColorUniform);
833 } 887 }
834 888
835 void GLDashingLineEffect::GenKey(const GrGeometryProcessor& processor, 889 void GLDashingLineEffect::GenKey(const GrGeometryProcessor& processor,
836 const GrBatchTracker&, 890 const GrBatchTracker& bt,
837 const GrGLCaps&, 891 const GrGLCaps&,
838 GrProcessorKeyBuilder* b) { 892 GrProcessorKeyBuilder* b) {
893 const DashingLineBatchTracker& local = bt.cast<DashingLineBatchTracker>();
839 const DashingLineEffect& de = processor.cast<DashingLineEffect>(); 894 const DashingLineEffect& de = processor.cast<DashingLineEffect>();
840 b->add32(de.getEdgeType()); 895 b->add32(de.getEdgeType() << 16 | local.fInputColorType);
841 } 896 }
842 897
843 ////////////////////////////////////////////////////////////////////////////// 898 //////////////////////////////////////////////////////////////////////////////
844 899
845 GrGeometryProcessor* DashingLineEffect::Create(GrColor color, 900 GrGeometryProcessor* DashingLineEffect::Create(GrColor color,
846 GrPrimitiveEdgeType edgeType, 901 GrPrimitiveEdgeType edgeType,
847 const DashInfo& info, 902 const DashInfo& info,
848 SkScalar strokeWidth) { 903 SkScalar strokeWidth) {
849 if (info.fCount != 2) { 904 if (info.fCount != 2) {
850 return NULL; 905 return NULL;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
885 fRect.set(halfOffLen, -halfStroke, halfOffLen + onLen, halfStroke); 940 fRect.set(halfOffLen, -halfStroke, halfOffLen + onLen, halfStroke);
886 } 941 }
887 942
888 bool DashingLineEffect::onIsEqual(const GrGeometryProcessor& other) const { 943 bool DashingLineEffect::onIsEqual(const GrGeometryProcessor& other) const {
889 const DashingLineEffect& de = other.cast<DashingLineEffect>(); 944 const DashingLineEffect& de = other.cast<DashingLineEffect>();
890 return (fEdgeType == de.fEdgeType && 945 return (fEdgeType == de.fEdgeType &&
891 fRect == de.fRect && 946 fRect == de.fRect &&
892 fIntervalLength == de.fIntervalLength); 947 fIntervalLength == de.fIntervalLength);
893 } 948 }
894 949
950 void DashingLineEffect::initBatchTracker(GrBatchTracker* bt, const InitBT& init) const {
951 DashingLineBatchTracker* local = bt->cast<DashingLineBatchTracker>();
952
953 // We will ignore this color unless we have uniform color
954 local->fColor = init.fColor;
955 local->fInputColorType = GetColorInputType(init, false);
956 }
957
958 bool DashingLineEffect::onCanBatch(const GrBatchTracker& l, const GrBatchTracker & r) const {
959 const DashingLineBatchTracker& left = l.cast<DashingLineBatchTracker>();
960 const DashingLineBatchTracker& right = r.cast<DashingLineBatchTracker>();
961 return CanCombineOutput(left.fInputColorType, left.fColor,
962 right.fInputColorType, right.fColor);
963 }
964
895 GR_DEFINE_GEOMETRY_PROCESSOR_TEST(DashingLineEffect); 965 GR_DEFINE_GEOMETRY_PROCESSOR_TEST(DashingLineEffect);
896 966
897 GrGeometryProcessor* DashingLineEffect::TestCreate(SkRandom* random, 967 GrGeometryProcessor* DashingLineEffect::TestCreate(SkRandom* random,
898 GrContext*, 968 GrContext*,
899 const GrDrawTargetCaps& caps, 969 const GrDrawTargetCaps& caps,
900 GrTexture*[]) { 970 GrTexture*[]) {
901 GrPrimitiveEdgeType edgeType = static_cast<GrPrimitiveEdgeType>(random->next ULessThan( 971 GrPrimitiveEdgeType edgeType = static_cast<GrPrimitiveEdgeType>(random->next ULessThan(
902 kGrProcessorEdgeTypeCnt)); 972 kGrProcessorEdgeTypeCnt));
903 SkScalar strokeWidth = random->nextRangeScalar(0, 100.f); 973 SkScalar strokeWidth = random->nextRangeScalar(0, 100.f);
904 DashInfo info; 974 DashInfo info;
(...skipping 17 matching lines...) Expand all
922 switch (cap) { 992 switch (cap) {
923 case GrDashingEffect::kRound_DashCap: 993 case GrDashingEffect::kRound_DashCap:
924 return DashingCircleEffect::Create(color, edgeType, info, SkScalarHa lf(strokeWidth)); 994 return DashingCircleEffect::Create(color, edgeType, info, SkScalarHa lf(strokeWidth));
925 case GrDashingEffect::kNonRound_DashCap: 995 case GrDashingEffect::kNonRound_DashCap:
926 return DashingLineEffect::Create(color, edgeType, info, strokeWidth) ; 996 return DashingLineEffect::Create(color, edgeType, info, strokeWidth) ;
927 default: 997 default:
928 SkFAIL("Unexpected dashed cap."); 998 SkFAIL("Unexpected dashed cap.");
929 } 999 }
930 return NULL; 1000 return NULL;
931 } 1001 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698