OLD | NEW |
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 Loading... |
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 GrGPInput 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 Loading... |
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 onCanMakeEqual(const GrBatchTracker&, const GrBatchTracker&) 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 14 matching lines...) Expand all Loading... |
508 GLDashingCircleEffect(const GrGeometryProcessor&, const GrBatchTracker&); | 518 GLDashingCircleEffect(const GrGeometryProcessor&, const GrBatchTracker&); |
509 | 519 |
510 virtual void emitCode(const EmitArgs&) SK_OVERRIDE; | 520 virtual void emitCode(const EmitArgs&) SK_OVERRIDE; |
511 | 521 |
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 GrPrimitiveProcessor&, |
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 GrColor fColor; |
525 SkScalar fPrevIntervalLength; | 535 SkScalar fPrevRadius; |
| 536 SkScalar fPrevCenterX; |
| 537 SkScalar fPrevIntervalLength; |
526 typedef GrGLGeometryProcessor INHERITED; | 538 typedef GrGLGeometryProcessor INHERITED; |
527 }; | 539 }; |
528 | 540 |
529 GLDashingCircleEffect::GLDashingCircleEffect(const GrGeometryProcessor&, | 541 GLDashingCircleEffect::GLDashingCircleEffect(const GrGeometryProcessor&, |
530 const GrBatchTracker&) { | 542 const GrBatchTracker&) { |
| 543 fColor = GrColor_ILLEGAL; |
531 fPrevRadius = SK_ScalarMin; | 544 fPrevRadius = SK_ScalarMin; |
532 fPrevCenterX = SK_ScalarMin; | 545 fPrevCenterX = SK_ScalarMin; |
533 fPrevIntervalLength = SK_ScalarMax; | 546 fPrevIntervalLength = SK_ScalarMax; |
534 } | 547 } |
535 | 548 |
536 void GLDashingCircleEffect::emitCode(const EmitArgs& args) { | 549 void GLDashingCircleEffect::emitCode(const EmitArgs& args) { |
537 const DashingCircleEffect& dce = args.fGP.cast<DashingCircleEffect>(); | 550 const DashingCircleEffect& dce = args.fGP.cast<DashingCircleEffect>(); |
| 551 const DashingCircleBatchTracker local = args.fBT.cast<DashingCircleBatchTrac
ker>(); |
| 552 GrGLGPBuilder* pb = args.fPB; |
538 const char *paramName; | 553 const char *paramName; |
539 // The param uniforms, xyz, refer to circle radius - 0.5, cicles center x co
ord, and | 554 // The param uniforms, xyz, refer to circle radius - 0.5, cicles center x co
ord, and |
540 // the total interval length of the dash. | 555 // the total interval length of the dash. |
541 fParamUniform = args.fPB->addUniform(GrGLProgramBuilder::kFragment_Visibilit
y, | 556 fParamUniform = args.fPB->addUniform(GrGLProgramBuilder::kFragment_Visibilit
y, |
542 kVec3f_GrSLType, kDefault_GrSLPrecision
, | 557 kVec3f_GrSLType, kDefault_GrSLPrecision
, |
543 "params", ¶mName); | 558 "params", ¶mName); |
544 | 559 |
545 GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder(); | 560 GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder(); |
546 | 561 |
547 GrGLVertToFrag v(kVec2f_GrSLType); | 562 GrGLVertToFrag v(kVec2f_GrSLType); |
548 args.fPB->addVarying("Coord", &v); | 563 args.fPB->addVarying("Coord", &v); |
549 vsBuilder->codeAppendf("%s = %s;", v.vsOut(), dce.inCoord()->fName); | 564 vsBuilder->codeAppendf("%s = %s;", v.vsOut(), dce.inCoord()->fName); |
550 | 565 |
| 566 // Setup pass through color |
| 567 this->setupColorPassThrough(pb, local.fInputColorType, args.fOutputColor, NU
LL, &fColorUniform); |
| 568 |
551 // setup coord outputs | 569 // setup coord outputs |
552 vsBuilder->codeAppendf("%s = %s;", vsBuilder->positionCoords(), dce.inPositi
on()->fName); | 570 vsBuilder->codeAppendf("%s = %s;", vsBuilder->positionCoords(), dce.inPositi
on()->fName); |
553 vsBuilder->codeAppendf("%s = %s;", vsBuilder->localCoords(), dce.inPosition(
)->fName); | 571 vsBuilder->codeAppendf("%s = %s;", vsBuilder->localCoords(), dce.inPosition(
)->fName); |
554 | 572 |
555 // setup position varying | 573 // setup position varying |
556 vsBuilder->codeAppendf("%s = %s * vec3(%s, 1);", vsBuilder->glPosition(), vs
Builder->uViewM(), | 574 vsBuilder->codeAppendf("%s = %s * vec3(%s, 1);", vsBuilder->glPosition(), vs
Builder->uViewM(), |
557 dce.inPosition()->fName); | 575 dce.inPosition()->fName); |
558 | 576 |
559 // transforms all points so that we can compare them to our test circle | 577 // transforms all points so that we can compare them to our test circle |
560 GrGLGPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder(); | 578 GrGLGPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder(); |
561 fsBuilder->codeAppendf("\t\tfloat xShifted = %s.x - floor(%s.x / %s.z) * %s.
z;\n", | 579 fsBuilder->codeAppendf("\t\tfloat xShifted = %s.x - floor(%s.x / %s.z) * %s.
z;\n", |
562 v.fsIn(), v.fsIn(), paramName, paramName); | 580 v.fsIn(), v.fsIn(), paramName, paramName); |
563 fsBuilder->codeAppendf("\t\tvec2 fragPosShifted = vec2(xShifted, %s.y);\n",
v.fsIn()); | 581 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); | 582 fsBuilder->codeAppendf("\t\tvec2 center = vec2(%s.y, 0.0);\n", paramName); |
565 fsBuilder->codeAppend("\t\tfloat dist = length(center - fragPosShifted);\n")
; | 583 fsBuilder->codeAppend("\t\tfloat dist = length(center - fragPosShifted);\n")
; |
566 if (GrProcessorEdgeTypeIsAA(dce.getEdgeType())) { | 584 if (GrProcessorEdgeTypeIsAA(dce.getEdgeType())) { |
567 fsBuilder->codeAppendf("\t\tfloat diff = dist - %s.x;\n", paramName); | 585 fsBuilder->codeAppendf("\t\tfloat diff = dist - %s.x;\n", paramName); |
568 fsBuilder->codeAppend("\t\tdiff = 1.0 - diff;\n"); | 586 fsBuilder->codeAppend("\t\tdiff = 1.0 - diff;\n"); |
569 fsBuilder->codeAppend("\t\tfloat alpha = clamp(diff, 0.0, 1.0);\n"); | 587 fsBuilder->codeAppend("\t\tfloat alpha = clamp(diff, 0.0, 1.0);\n"); |
570 } else { | 588 } else { |
571 fsBuilder->codeAppendf("\t\tfloat alpha = 1.0;\n"); | 589 fsBuilder->codeAppendf("\t\tfloat alpha = 1.0;\n"); |
572 fsBuilder->codeAppendf("\t\talpha *= dist < %s.x + 0.5 ? 1.0 : 0.0;\n",
paramName); | 590 fsBuilder->codeAppendf("\t\talpha *= dist < %s.x + 0.5 ? 1.0 : 0.0;\n",
paramName); |
573 } | 591 } |
574 fsBuilder->codeAppendf("%s = vec4(alpha);", args.fOutputCoverage); | 592 fsBuilder->codeAppendf("%s = vec4(alpha);", args.fOutputCoverage); |
575 } | 593 } |
576 | 594 |
577 void GLDashingCircleEffect::setData(const GrGLProgramDataManager& pdman, | 595 void GLDashingCircleEffect::setData(const GrGLProgramDataManager& pdman, |
578 const GrGeometryProcessor& processor, | 596 const GrPrimitiveProcessor& processor, |
579 const GrBatchTracker&) { | 597 const GrBatchTracker& bt) { |
580 const DashingCircleEffect& dce = processor.cast<DashingCircleEffect>(); | 598 const DashingCircleEffect& dce = processor.cast<DashingCircleEffect>(); |
581 SkScalar radius = dce.getRadius(); | 599 SkScalar radius = dce.getRadius(); |
582 SkScalar centerX = dce.getCenterX(); | 600 SkScalar centerX = dce.getCenterX(); |
583 SkScalar intervalLength = dce.getIntervalLength(); | 601 SkScalar intervalLength = dce.getIntervalLength(); |
584 if (radius != fPrevRadius || centerX != fPrevCenterX || intervalLength != fP
revIntervalLength) { | 602 if (radius != fPrevRadius || centerX != fPrevCenterX || intervalLength != fP
revIntervalLength) { |
585 pdman.set3f(fParamUniform, radius - 0.5f, centerX, intervalLength); | 603 pdman.set3f(fParamUniform, radius - 0.5f, centerX, intervalLength); |
586 fPrevRadius = radius; | 604 fPrevRadius = radius; |
587 fPrevCenterX = centerX; | 605 fPrevCenterX = centerX; |
588 fPrevIntervalLength = intervalLength; | 606 fPrevIntervalLength = intervalLength; |
589 } | 607 } |
| 608 |
| 609 const DashingCircleBatchTracker& local = bt.cast<DashingCircleBatchTracker>(
); |
| 610 if (kUniform_GrGPInput == local.fInputColorType && local.fColor != fColor) { |
| 611 GrGLfloat c[4]; |
| 612 GrColorToRGBAFloat(local.fColor, c); |
| 613 pdman.set4fv(fColorUniform, 1, c); |
| 614 fColor = local.fColor; |
| 615 } |
590 } | 616 } |
591 | 617 |
592 void GLDashingCircleEffect::GenKey(const GrGeometryProcessor& processor, | 618 void GLDashingCircleEffect::GenKey(const GrGeometryProcessor& processor, |
593 const GrBatchTracker&, | 619 const GrBatchTracker& bt, |
594 const GrGLCaps&, | 620 const GrGLCaps&, |
595 GrProcessorKeyBuilder* b) { | 621 GrProcessorKeyBuilder* b) { |
| 622 const DashingCircleBatchTracker& local = bt.cast<DashingCircleBatchTracker>(
); |
596 const DashingCircleEffect& dce = processor.cast<DashingCircleEffect>(); | 623 const DashingCircleEffect& dce = processor.cast<DashingCircleEffect>(); |
597 b->add32(dce.getEdgeType()); | 624 b->add32(dce.getEdgeType() << 16 | local.fInputColorType); |
598 } | 625 } |
599 | 626 |
600 ////////////////////////////////////////////////////////////////////////////// | 627 ////////////////////////////////////////////////////////////////////////////// |
601 | 628 |
602 GrGeometryProcessor* DashingCircleEffect::Create(GrColor color, | 629 GrGeometryProcessor* DashingCircleEffect::Create(GrColor color, |
603 GrPrimitiveEdgeType edgeType, | 630 GrPrimitiveEdgeType edgeType, |
604 const DashInfo& info, | 631 const DashInfo& info, |
605 SkScalar radius) { | 632 SkScalar radius) { |
606 if (info.fCount != 2 || info.fIntervals[0] != 0) { | 633 if (info.fCount != 2 || info.fIntervals[0] != 0) { |
607 return NULL; | 634 return NULL; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
642 } | 669 } |
643 | 670 |
644 bool DashingCircleEffect::onIsEqual(const GrGeometryProcessor& other) const { | 671 bool DashingCircleEffect::onIsEqual(const GrGeometryProcessor& other) const { |
645 const DashingCircleEffect& dce = other.cast<DashingCircleEffect>(); | 672 const DashingCircleEffect& dce = other.cast<DashingCircleEffect>(); |
646 return (fEdgeType == dce.fEdgeType && | 673 return (fEdgeType == dce.fEdgeType && |
647 fIntervalLength == dce.fIntervalLength && | 674 fIntervalLength == dce.fIntervalLength && |
648 fRadius == dce.fRadius && | 675 fRadius == dce.fRadius && |
649 fCenterX == dce.fCenterX); | 676 fCenterX == dce.fCenterX); |
650 } | 677 } |
651 | 678 |
| 679 void DashingCircleEffect::initBatchTracker(GrBatchTracker* bt, const InitBT& ini
t) const { |
| 680 DashingCircleBatchTracker* local = bt->cast<DashingCircleBatchTracker>(); |
| 681 local->fInputColorType = GetColorInputType(&local->fColor, this->color(), in
it, false); |
| 682 } |
| 683 |
| 684 bool DashingCircleEffect::onCanMakeEqual(const GrBatchTracker& m, const GrBatchT
racker& t) const { |
| 685 const DashingCircleBatchTracker& mine = m.cast<DashingCircleBatchTracker>(); |
| 686 const DashingCircleBatchTracker& theirs = t.cast<DashingCircleBatchTracker>(
); |
| 687 return CanCombineOutput(mine.fInputColorType, mine.fColor, |
| 688 theirs.fInputColorType, theirs.fColor); |
| 689 } |
| 690 |
652 GR_DEFINE_GEOMETRY_PROCESSOR_TEST(DashingCircleEffect); | 691 GR_DEFINE_GEOMETRY_PROCESSOR_TEST(DashingCircleEffect); |
653 | 692 |
654 GrGeometryProcessor* DashingCircleEffect::TestCreate(SkRandom* random, | 693 GrGeometryProcessor* DashingCircleEffect::TestCreate(SkRandom* random, |
655 GrContext*, | 694 GrContext*, |
656 const GrDrawTargetCaps& cap
s, | 695 const GrDrawTargetCaps& cap
s, |
657 GrTexture*[]) { | 696 GrTexture*[]) { |
658 GrPrimitiveEdgeType edgeType = static_cast<GrPrimitiveEdgeType>(random->next
ULessThan( | 697 GrPrimitiveEdgeType edgeType = static_cast<GrPrimitiveEdgeType>(random->next
ULessThan( |
659 kGrProcessorEdgeTypeCnt)); | 698 kGrProcessorEdgeTypeCnt)); |
660 SkScalar strokeWidth = random->nextRangeScalar(0, 100.f); | 699 SkScalar strokeWidth = random->nextRangeScalar(0, 100.f); |
661 DashInfo info; | 700 DashInfo info; |
662 info.fCount = 2; | 701 info.fCount = 2; |
663 SkAutoTArray<SkScalar> intervals(info.fCount); | 702 SkAutoTArray<SkScalar> intervals(info.fCount); |
664 info.fIntervals = intervals.get(); | 703 info.fIntervals = intervals.get(); |
665 info.fIntervals[0] = 0; | 704 info.fIntervals[0] = 0; |
666 info.fIntervals[1] = random->nextRangeScalar(0, 10.f); | 705 info.fIntervals[1] = random->nextRangeScalar(0, 10.f); |
667 info.fPhase = random->nextRangeScalar(0, info.fIntervals[1]); | 706 info.fPhase = random->nextRangeScalar(0, info.fIntervals[1]); |
668 | 707 |
669 return DashingCircleEffect::Create(GrRandomColor(random), edgeType, info, st
rokeWidth); | 708 return DashingCircleEffect::Create(GrRandomColor(random), edgeType, info, st
rokeWidth); |
670 } | 709 } |
671 | 710 |
672 ////////////////////////////////////////////////////////////////////////////// | 711 ////////////////////////////////////////////////////////////////////////////// |
673 | 712 |
674 class GLDashingLineEffect; | 713 class GLDashingLineEffect; |
675 | 714 |
| 715 struct DashingLineBatchTracker { |
| 716 GrGPInput fInputColorType; |
| 717 GrColor fColor; |
| 718 }; |
| 719 |
676 /* | 720 /* |
677 * This effect will draw a dashed line. The width of the dash is given by the st
rokeWidth and the | 721 * 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. | 722 * 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 | 723 * 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 | 724 * 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 | 725 * 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 | 726 * 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. | 727 * positive x direction. |
684 */ | 728 */ |
685 class DashingLineEffect : public GrGeometryProcessor { | 729 class DashingLineEffect : public GrGeometryProcessor { |
(...skipping 18 matching lines...) Expand all Loading... |
704 const SkRect& getRect() const { return fRect; } | 748 const SkRect& getRect() const { return fRect; } |
705 | 749 |
706 SkScalar getIntervalLength() const { return fIntervalLength; } | 750 SkScalar getIntervalLength() const { return fIntervalLength; } |
707 | 751 |
708 virtual void getGLProcessorKey(const GrBatchTracker& bt, | 752 virtual void getGLProcessorKey(const GrBatchTracker& bt, |
709 const GrGLCaps& caps, | 753 const GrGLCaps& caps, |
710 GrProcessorKeyBuilder* b) const SK_OVERRIDE; | 754 GrProcessorKeyBuilder* b) const SK_OVERRIDE; |
711 | 755 |
712 virtual GrGLGeometryProcessor* createGLInstance(const GrBatchTracker& bt) co
nst SK_OVERRIDE; | 756 virtual GrGLGeometryProcessor* createGLInstance(const GrBatchTracker& bt) co
nst SK_OVERRIDE; |
713 | 757 |
| 758 void initBatchTracker(GrBatchTracker* bt, const InitBT& init) const SK_OVERR
IDE; |
| 759 |
| 760 bool onCanMakeEqual(const GrBatchTracker&, const GrBatchTracker&) const SK_O
VERRIDE; |
| 761 |
714 private: | 762 private: |
715 DashingLineEffect(GrColor, GrPrimitiveEdgeType edgeType, const DashInfo& inf
o, | 763 DashingLineEffect(GrColor, GrPrimitiveEdgeType edgeType, const DashInfo& inf
o, |
716 SkScalar strokeWidth); | 764 SkScalar strokeWidth); |
717 | 765 |
718 virtual bool onIsEqual(const GrGeometryProcessor& other) const SK_OVERRIDE; | 766 virtual bool onIsEqual(const GrGeometryProcessor& other) const SK_OVERRIDE; |
719 | 767 |
720 virtual void onGetInvariantOutputCoverage(GrInitInvariantOutput*) const SK_O
VERRIDE; | 768 virtual void onGetInvariantOutputCoverage(GrInitInvariantOutput*) const SK_O
VERRIDE; |
721 | 769 |
722 GrPrimitiveEdgeType fEdgeType; | 770 GrPrimitiveEdgeType fEdgeType; |
723 const GrAttribute* fInPosition; | 771 const GrAttribute* fInPosition; |
(...skipping 13 matching lines...) Expand all Loading... |
737 GLDashingLineEffect(const GrGeometryProcessor&, const GrBatchTracker&); | 785 GLDashingLineEffect(const GrGeometryProcessor&, const GrBatchTracker&); |
738 | 786 |
739 virtual void emitCode(const EmitArgs&) SK_OVERRIDE; | 787 virtual void emitCode(const EmitArgs&) SK_OVERRIDE; |
740 | 788 |
741 static inline void GenKey(const GrGeometryProcessor&, | 789 static inline void GenKey(const GrGeometryProcessor&, |
742 const GrBatchTracker&, | 790 const GrBatchTracker&, |
743 const GrGLCaps&, | 791 const GrGLCaps&, |
744 GrProcessorKeyBuilder*); | 792 GrProcessorKeyBuilder*); |
745 | 793 |
746 virtual void setData(const GrGLProgramDataManager&, | 794 virtual void setData(const GrGLProgramDataManager&, |
747 const GrGeometryProcessor&, | 795 const GrPrimitiveProcessor&, |
748 const GrBatchTracker&) SK_OVERRIDE; | 796 const GrBatchTracker&) SK_OVERRIDE; |
749 | 797 |
750 private: | 798 private: |
751 GrGLProgramDataManager::UniformHandle fRectUniform; | 799 GrColor fColor; |
752 GrGLProgramDataManager::UniformHandle fIntervalUniform; | 800 UniformHandle fRectUniform; |
753 SkRect fPrevRect; | 801 UniformHandle fIntervalUniform; |
754 SkScalar fPrevIntervalLength; | 802 UniformHandle fColorUniform; |
| 803 SkRect fPrevRect; |
| 804 SkScalar fPrevIntervalLength; |
755 typedef GrGLGeometryProcessor INHERITED; | 805 typedef GrGLGeometryProcessor INHERITED; |
756 }; | 806 }; |
757 | 807 |
758 GLDashingLineEffect::GLDashingLineEffect(const GrGeometryProcessor&, | 808 GLDashingLineEffect::GLDashingLineEffect(const GrGeometryProcessor&, |
759 const GrBatchTracker&) { | 809 const GrBatchTracker&) { |
| 810 fColor = GrColor_ILLEGAL; |
760 fPrevRect.fLeft = SK_ScalarNaN; | 811 fPrevRect.fLeft = SK_ScalarNaN; |
761 fPrevIntervalLength = SK_ScalarMax; | 812 fPrevIntervalLength = SK_ScalarMax; |
762 } | 813 } |
763 | 814 |
764 void GLDashingLineEffect::emitCode(const EmitArgs& args) { | 815 void GLDashingLineEffect::emitCode(const EmitArgs& args) { |
765 const DashingLineEffect& de = args.fGP.cast<DashingLineEffect>(); | 816 const DashingLineEffect& de = args.fGP.cast<DashingLineEffect>(); |
| 817 const DashingLineBatchTracker& local = args.fBT.cast<DashingLineBatchTracker
>(); |
| 818 GrGLGPBuilder* pb = args.fPB; |
766 const char *rectName; | 819 const char *rectName; |
767 // The rect uniform's xyzw refer to (left + 0.5, top + 0.5, right - 0.5, bot
tom - 0.5), | 820 // The rect uniform's xyzw refer to (left + 0.5, top + 0.5, right - 0.5, bot
tom - 0.5), |
768 // respectively. | 821 // respectively. |
769 fRectUniform = args.fPB->addUniform(GrGLProgramBuilder::kFragment_Visibility
, | 822 fRectUniform = args.fPB->addUniform(GrGLProgramBuilder::kFragment_Visibility
, |
770 kVec4f_GrSLType, kDefault_GrSLPrecision, | 823 kVec4f_GrSLType, kDefault_GrSLPrecision, |
771 "rect", | 824 "rect", |
772 &rectName); | 825 &rectName); |
773 const char *intervalName; | 826 const char *intervalName; |
774 // The interval uniform's refers to the total length of the interval (on + o
ff) | 827 // The interval uniform's refers to the total length of the interval (on + o
ff) |
775 fIntervalUniform = args.fPB->addUniform(GrGLProgramBuilder::kFragment_Visibi
lity, | 828 fIntervalUniform = args.fPB->addUniform(GrGLProgramBuilder::kFragment_Visibi
lity, |
776 kFloat_GrSLType, kDefault_GrSLPrecis
ion, | 829 kFloat_GrSLType, kDefault_GrSLPrecis
ion, |
777 "interval", | 830 "interval", |
778 &intervalName); | 831 &intervalName); |
779 | 832 |
780 | 833 |
781 GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder(); | 834 GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder(); |
782 | 835 |
783 GrGLVertToFrag v(kVec2f_GrSLType); | 836 GrGLVertToFrag v(kVec2f_GrSLType); |
784 args.fPB->addVarying("Coord", &v); | 837 args.fPB->addVarying("Coord", &v); |
785 vsBuilder->codeAppendf("%s = %s;", v.vsOut(), de.inCoord()->fName); | 838 vsBuilder->codeAppendf("%s = %s;", v.vsOut(), de.inCoord()->fName); |
786 | 839 |
| 840 // Setup pass through color |
| 841 this->setupColorPassThrough(pb, local.fInputColorType, args.fOutputColor, NU
LL, &fColorUniform); |
| 842 |
787 // setup coord outputs | 843 // setup coord outputs |
788 vsBuilder->codeAppendf("%s = %s;", vsBuilder->positionCoords(), de.inPositio
n()->fName); | 844 vsBuilder->codeAppendf("%s = %s;", vsBuilder->positionCoords(), de.inPositio
n()->fName); |
789 vsBuilder->codeAppendf("%s = %s;", vsBuilder->localCoords(), de.inPosition()
->fName); | 845 vsBuilder->codeAppendf("%s = %s;", vsBuilder->localCoords(), de.inPosition()
->fName); |
790 | 846 |
791 // setup position varying | 847 // setup position varying |
792 vsBuilder->codeAppendf("%s = %s * vec3(%s, 1);", vsBuilder->glPosition(), vs
Builder->uViewM(), | 848 vsBuilder->codeAppendf("%s = %s * vec3(%s, 1);", vsBuilder->glPosition(), vs
Builder->uViewM(), |
793 de.inPosition()->fName); | 849 de.inPosition()->fName); |
794 | 850 |
795 // transforms all points so that we can compare them to our test rect | 851 // transforms all points so that we can compare them to our test rect |
796 GrGLGPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder(); | 852 GrGLGPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder(); |
(...skipping 14 matching lines...) Expand all Loading... |
811 } else { | 867 } else { |
812 // Assuming the bounding geometry is tight so no need to check y values | 868 // Assuming the bounding geometry is tight so no need to check y values |
813 fsBuilder->codeAppendf("\t\tfloat alpha = 1.0;\n"); | 869 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); | 870 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); | 871 fsBuilder->codeAppendf("\t\talpha *= (%s.z - fragPosShifted.x) >= -0.5 ?
1.0 : 0.0;\n", rectName); |
816 } | 872 } |
817 fsBuilder->codeAppendf("%s = vec4(alpha);", args.fOutputCoverage); | 873 fsBuilder->codeAppendf("%s = vec4(alpha);", args.fOutputCoverage); |
818 } | 874 } |
819 | 875 |
820 void GLDashingLineEffect::setData(const GrGLProgramDataManager& pdman, | 876 void GLDashingLineEffect::setData(const GrGLProgramDataManager& pdman, |
821 const GrGeometryProcessor& processor, | 877 const GrPrimitiveProcessor& processor, |
822 const GrBatchTracker&) { | 878 const GrBatchTracker& bt) { |
823 const DashingLineEffect& de = processor.cast<DashingLineEffect>(); | 879 const DashingLineEffect& de = processor.cast<DashingLineEffect>(); |
824 const SkRect& rect = de.getRect(); | 880 const SkRect& rect = de.getRect(); |
825 SkScalar intervalLength = de.getIntervalLength(); | 881 SkScalar intervalLength = de.getIntervalLength(); |
826 if (rect != fPrevRect || intervalLength != fPrevIntervalLength) { | 882 if (rect != fPrevRect || intervalLength != fPrevIntervalLength) { |
827 pdman.set4f(fRectUniform, rect.fLeft + 0.5f, rect.fTop + 0.5f, | 883 pdman.set4f(fRectUniform, rect.fLeft + 0.5f, rect.fTop + 0.5f, |
828 rect.fRight - 0.5f, rect.fBottom - 0.5f); | 884 rect.fRight - 0.5f, rect.fBottom - 0.5f); |
829 pdman.set1f(fIntervalUniform, intervalLength); | 885 pdman.set1f(fIntervalUniform, intervalLength); |
830 fPrevRect = rect; | 886 fPrevRect = rect; |
831 fPrevIntervalLength = intervalLength; | 887 fPrevIntervalLength = intervalLength; |
832 } | 888 } |
| 889 |
| 890 const DashingLineBatchTracker& local = bt.cast<DashingLineBatchTracker>(); |
| 891 if (kUniform_GrGPInput == local.fInputColorType && local.fColor != fColor) { |
| 892 GrGLfloat c[4]; |
| 893 GrColorToRGBAFloat(local.fColor, c); |
| 894 pdman.set4fv(fColorUniform, 1, c); |
| 895 fColor = local.fColor; |
| 896 } |
833 } | 897 } |
834 | 898 |
835 void GLDashingLineEffect::GenKey(const GrGeometryProcessor& processor, | 899 void GLDashingLineEffect::GenKey(const GrGeometryProcessor& processor, |
836 const GrBatchTracker&, | 900 const GrBatchTracker& bt, |
837 const GrGLCaps&, | 901 const GrGLCaps&, |
838 GrProcessorKeyBuilder* b) { | 902 GrProcessorKeyBuilder* b) { |
| 903 const DashingLineBatchTracker& local = bt.cast<DashingLineBatchTracker>(); |
839 const DashingLineEffect& de = processor.cast<DashingLineEffect>(); | 904 const DashingLineEffect& de = processor.cast<DashingLineEffect>(); |
840 b->add32(de.getEdgeType()); | 905 b->add32(de.getEdgeType() << 16 | local.fInputColorType); |
841 } | 906 } |
842 | 907 |
843 ////////////////////////////////////////////////////////////////////////////// | 908 ////////////////////////////////////////////////////////////////////////////// |
844 | 909 |
845 GrGeometryProcessor* DashingLineEffect::Create(GrColor color, | 910 GrGeometryProcessor* DashingLineEffect::Create(GrColor color, |
846 GrPrimitiveEdgeType edgeType, | 911 GrPrimitiveEdgeType edgeType, |
847 const DashInfo& info, | 912 const DashInfo& info, |
848 SkScalar strokeWidth) { | 913 SkScalar strokeWidth) { |
849 if (info.fCount != 2) { | 914 if (info.fCount != 2) { |
850 return NULL; | 915 return NULL; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
885 fRect.set(halfOffLen, -halfStroke, halfOffLen + onLen, halfStroke); | 950 fRect.set(halfOffLen, -halfStroke, halfOffLen + onLen, halfStroke); |
886 } | 951 } |
887 | 952 |
888 bool DashingLineEffect::onIsEqual(const GrGeometryProcessor& other) const { | 953 bool DashingLineEffect::onIsEqual(const GrGeometryProcessor& other) const { |
889 const DashingLineEffect& de = other.cast<DashingLineEffect>(); | 954 const DashingLineEffect& de = other.cast<DashingLineEffect>(); |
890 return (fEdgeType == de.fEdgeType && | 955 return (fEdgeType == de.fEdgeType && |
891 fRect == de.fRect && | 956 fRect == de.fRect && |
892 fIntervalLength == de.fIntervalLength); | 957 fIntervalLength == de.fIntervalLength); |
893 } | 958 } |
894 | 959 |
| 960 void DashingLineEffect::initBatchTracker(GrBatchTracker* bt, const InitBT& init)
const { |
| 961 DashingLineBatchTracker* local = bt->cast<DashingLineBatchTracker>(); |
| 962 local->fInputColorType = GetColorInputType(&local->fColor, this->color(), in
it, false); |
| 963 } |
| 964 |
| 965 bool DashingLineEffect::onCanMakeEqual(const GrBatchTracker& m, const GrBatchTra
cker& t) const { |
| 966 const DashingLineBatchTracker& mine = m.cast<DashingLineBatchTracker>(); |
| 967 const DashingLineBatchTracker& theirs = t.cast<DashingLineBatchTracker>(); |
| 968 return CanCombineOutput(mine.fInputColorType, mine.fColor, |
| 969 theirs.fInputColorType, theirs.fColor); |
| 970 } |
| 971 |
895 GR_DEFINE_GEOMETRY_PROCESSOR_TEST(DashingLineEffect); | 972 GR_DEFINE_GEOMETRY_PROCESSOR_TEST(DashingLineEffect); |
896 | 973 |
897 GrGeometryProcessor* DashingLineEffect::TestCreate(SkRandom* random, | 974 GrGeometryProcessor* DashingLineEffect::TestCreate(SkRandom* random, |
898 GrContext*, | 975 GrContext*, |
899 const GrDrawTargetCaps& caps, | 976 const GrDrawTargetCaps& caps, |
900 GrTexture*[]) { | 977 GrTexture*[]) { |
901 GrPrimitiveEdgeType edgeType = static_cast<GrPrimitiveEdgeType>(random->next
ULessThan( | 978 GrPrimitiveEdgeType edgeType = static_cast<GrPrimitiveEdgeType>(random->next
ULessThan( |
902 kGrProcessorEdgeTypeCnt)); | 979 kGrProcessorEdgeTypeCnt)); |
903 SkScalar strokeWidth = random->nextRangeScalar(0, 100.f); | 980 SkScalar strokeWidth = random->nextRangeScalar(0, 100.f); |
904 DashInfo info; | 981 DashInfo info; |
(...skipping 17 matching lines...) Expand all Loading... |
922 switch (cap) { | 999 switch (cap) { |
923 case GrDashingEffect::kRound_DashCap: | 1000 case GrDashingEffect::kRound_DashCap: |
924 return DashingCircleEffect::Create(color, edgeType, info, SkScalarHa
lf(strokeWidth)); | 1001 return DashingCircleEffect::Create(color, edgeType, info, SkScalarHa
lf(strokeWidth)); |
925 case GrDashingEffect::kNonRound_DashCap: | 1002 case GrDashingEffect::kNonRound_DashCap: |
926 return DashingLineEffect::Create(color, edgeType, info, strokeWidth)
; | 1003 return DashingLineEffect::Create(color, edgeType, info, strokeWidth)
; |
927 default: | 1004 default: |
928 SkFAIL("Unexpected dashed cap."); | 1005 SkFAIL("Unexpected dashed cap."); |
929 } | 1006 } |
930 return NULL; | 1007 return NULL; |
931 } | 1008 } |
OLD | NEW |