| 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 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 static void setup_dashed_rect_pos(const SkRect& rect, int idx, const SkMatrix& m
atrix, | 158 static void setup_dashed_rect_pos(const SkRect& rect, int idx, const SkMatrix& m
atrix, |
| 159 SkPoint* verts) { | 159 SkPoint* verts) { |
| 160 verts[idx] = SkPoint::Make(rect.fLeft, rect.fTop); | 160 verts[idx] = SkPoint::Make(rect.fLeft, rect.fTop); |
| 161 verts[idx + 1] = SkPoint::Make(rect.fLeft, rect.fBottom); | 161 verts[idx + 1] = SkPoint::Make(rect.fLeft, rect.fBottom); |
| 162 verts[idx + 2] = SkPoint::Make(rect.fRight, rect.fBottom); | 162 verts[idx + 2] = SkPoint::Make(rect.fRight, rect.fBottom); |
| 163 verts[idx + 3] = SkPoint::Make(rect.fRight, rect.fTop); | 163 verts[idx + 3] = SkPoint::Make(rect.fRight, rect.fTop); |
| 164 matrix.mapPoints(&verts[idx], 4); | 164 matrix.mapPoints(&verts[idx], 4); |
| 165 } | 165 } |
| 166 | 166 |
| 167 bool GrDashingEffect::DrawDashLine(GrGpu* gpu, GrDrawTarget* target, GrDrawState
* drawState, | 167 bool GrDashingEffect::DrawDashLine(GrGpu* gpu, GrDrawTarget* target, GrDrawState
* drawState, |
| 168 const SkPoint pts[2], const GrPaint& paint, | 168 GrColor color, const SkPoint pts[2], const Gr
Paint& paint, |
| 169 const GrStrokeInfo& strokeInfo, const SkMatri
x& vm) { | 169 const GrStrokeInfo& strokeInfo, const SkMatri
x& vm) { |
| 170 | 170 |
| 171 if (!can_fast_path_dash(pts, strokeInfo, *target, *drawState, vm)) { | 171 if (!can_fast_path_dash(pts, strokeInfo, *target, *drawState, vm)) { |
| 172 return false; | 172 return false; |
| 173 } | 173 } |
| 174 | 174 |
| 175 const SkPathEffect::DashInfo& info = strokeInfo.getDashInfo(); | 175 const SkPathEffect::DashInfo& info = strokeInfo.getDashInfo(); |
| 176 | 176 |
| 177 SkPaint::Cap cap = strokeInfo.getStrokeRec().getCap(); | 177 SkPaint::Cap cap = strokeInfo.getStrokeRec().getCap(); |
| 178 | 178 |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 340 if (fullDash) { | 340 if (fullDash) { |
| 341 SkPathEffect::DashInfo devInfo; | 341 SkPathEffect::DashInfo devInfo; |
| 342 devInfo.fPhase = devPhase; | 342 devInfo.fPhase = devPhase; |
| 343 devInfo.fCount = 2; | 343 devInfo.fCount = 2; |
| 344 devInfo.fIntervals = devIntervals; | 344 devInfo.fIntervals = devIntervals; |
| 345 GrPrimitiveEdgeType edgeType= useAA ? kFillAA_GrProcessorEdgeType : | 345 GrPrimitiveEdgeType edgeType= useAA ? kFillAA_GrProcessorEdgeType : |
| 346 kFillBW_GrProcessorEdgeType; | 346 kFillBW_GrProcessorEdgeType; |
| 347 bool isRoundCap = SkPaint::kRound_Cap == cap; | 347 bool isRoundCap = SkPaint::kRound_Cap == cap; |
| 348 GrDashingEffect::DashCap capType = isRoundCap ? GrDashingEffect::kRound_
DashCap : | 348 GrDashingEffect::DashCap capType = isRoundCap ? GrDashingEffect::kRound_
DashCap : |
| 349 GrDashingEffect::kNonRou
nd_DashCap; | 349 GrDashingEffect::kNonRou
nd_DashCap; |
| 350 gp = GrDashingEffect::Create(edgeType, devInfo, strokeWidth, capType); | 350 gp = GrDashingEffect::Create(color, edgeType, devInfo, strokeWidth, capT
ype); |
| 351 } else { | 351 } else { |
| 352 // Set up the vertex data for the line and start/end dashes | 352 // Set up the vertex data for the line and start/end dashes |
| 353 gp = GrDefaultGeoProcFactory::Create(GrDefaultGeoProcFactory::kPosition_
GPType); | 353 gp = GrDefaultGeoProcFactory::Create(color, GrDefaultGeoProcFactory::kPo
sition_GPType); |
| 354 } | 354 } |
| 355 | 355 |
| 356 drawState->setGeometryProcessor(gp)->unref(); | 356 drawState->setGeometryProcessor(gp)->unref(); |
| 357 | 357 |
| 358 int totalRectCnt = 0; | 358 int totalRectCnt = 0; |
| 359 | 359 |
| 360 totalRectCnt += !lineDone ? 1 : 0; | 360 totalRectCnt += !lineDone ? 1 : 0; |
| 361 totalRectCnt += hasStartRect ? 1 : 0; | 361 totalRectCnt += hasStartRect ? 1 : 0; |
| 362 totalRectCnt += hasEndRect ? 1 : 0; | 362 totalRectCnt += hasEndRect ? 1 : 0; |
| 363 | 363 |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 449 * Both of the previous two parameters are in device space. This effect also req
uires the setting of | 449 * Both of the previous two parameters are in device space. This effect also req
uires the setting of |
| 450 * a vec2 vertex attribute for the the four corners of the bounding rect. This a
ttribute is the | 450 * a vec2 vertex attribute for the the four corners of the bounding rect. This a
ttribute is the |
| 451 * "dash position" of each vertex. In other words it is the vertex coords (in de
vice space) if we | 451 * "dash position" of each vertex. In other words it is the vertex coords (in de
vice space) if we |
| 452 * transform the line to be horizontal, with the start of line at the origin the
n shifted to the | 452 * transform the line to be horizontal, with the start of line at the origin the
n shifted to the |
| 453 * right by half the off interval. The line then goes in the positive x directio
n. | 453 * right by half the off interval. The line then goes in the positive x directio
n. |
| 454 */ | 454 */ |
| 455 class DashingCircleEffect : public GrGeometryProcessor { | 455 class DashingCircleEffect : public GrGeometryProcessor { |
| 456 public: | 456 public: |
| 457 typedef SkPathEffect::DashInfo DashInfo; | 457 typedef SkPathEffect::DashInfo DashInfo; |
| 458 | 458 |
| 459 static GrGeometryProcessor* Create(GrPrimitiveEdgeType edgeType, | 459 static GrGeometryProcessor* Create(GrColor, |
| 460 GrPrimitiveEdgeType edgeType, |
| 460 const DashInfo& info, | 461 const DashInfo& info, |
| 461 SkScalar radius); | 462 SkScalar radius); |
| 462 | 463 |
| 463 virtual ~DashingCircleEffect(); | 464 virtual ~DashingCircleEffect(); |
| 464 | 465 |
| 465 virtual const char* name() const SK_OVERRIDE { return "DashingCircleEffect";
} | 466 virtual const char* name() const SK_OVERRIDE { return "DashingCircleEffect";
} |
| 466 | 467 |
| 467 const GrAttribute* inPosition() const { return fInPosition; } | 468 const GrAttribute* inPosition() const { return fInPosition; } |
| 468 | 469 |
| 469 const GrAttribute* inCoord() const { return fInCoord; } | 470 const GrAttribute* inCoord() const { return fInCoord; } |
| 470 | 471 |
| 471 GrPrimitiveEdgeType getEdgeType() const { return fEdgeType; } | 472 GrPrimitiveEdgeType getEdgeType() const { return fEdgeType; } |
| 472 | 473 |
| 473 SkScalar getRadius() const { return fRadius; } | 474 SkScalar getRadius() const { return fRadius; } |
| 474 | 475 |
| 475 SkScalar getCenterX() const { return fCenterX; } | 476 SkScalar getCenterX() const { return fCenterX; } |
| 476 | 477 |
| 477 SkScalar getIntervalLength() const { return fIntervalLength; } | 478 SkScalar getIntervalLength() const { return fIntervalLength; } |
| 478 | 479 |
| 479 virtual void getGLProcessorKey(const GrBatchTracker&, | 480 virtual void getGLProcessorKey(const GrBatchTracker&, |
| 480 const GrGLCaps&, | 481 const GrGLCaps&, |
| 481 GrProcessorKeyBuilder* b) const SK_OVERRIDE; | 482 GrProcessorKeyBuilder* b) const SK_OVERRIDE; |
| 482 | 483 |
| 483 virtual GrGLGeometryProcessor* createGLInstance(const GrBatchTracker&) const
SK_OVERRIDE; | 484 virtual GrGLGeometryProcessor* createGLInstance(const GrBatchTracker&) const
SK_OVERRIDE; |
| 484 | 485 |
| 485 private: | 486 private: |
| 486 DashingCircleEffect(GrPrimitiveEdgeType edgeType, const DashInfo& info, SkSc
alar radius); | 487 DashingCircleEffect(GrColor, GrPrimitiveEdgeType edgeType, const DashInfo& i
nfo, |
| 488 SkScalar radius); |
| 487 | 489 |
| 488 virtual bool onIsEqual(const GrGeometryProcessor& other) const SK_OVERRIDE; | 490 virtual bool onIsEqual(const GrGeometryProcessor& other) const SK_OVERRIDE; |
| 489 | 491 |
| 490 virtual void onComputeInvariantOutput(GrInvariantOutput* inout) const SK_OVE
RRIDE; | 492 virtual void onComputeInvariantOutput(GrInvariantOutput* inout) const SK_OVE
RRIDE; |
| 491 | 493 |
| 492 GrPrimitiveEdgeType fEdgeType; | 494 GrPrimitiveEdgeType fEdgeType; |
| 493 const GrAttribute* fInPosition; | 495 const GrAttribute* fInPosition; |
| 494 const GrAttribute* fInCoord; | 496 const GrAttribute* fInCoord; |
| 495 SkScalar fIntervalLength; | 497 SkScalar fIntervalLength; |
| 496 SkScalar fRadius; | 498 SkScalar fRadius; |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 592 void GLDashingCircleEffect::GenKey(const GrGeometryProcessor& processor, | 594 void GLDashingCircleEffect::GenKey(const GrGeometryProcessor& processor, |
| 593 const GrBatchTracker&, | 595 const GrBatchTracker&, |
| 594 const GrGLCaps&, | 596 const GrGLCaps&, |
| 595 GrProcessorKeyBuilder* b) { | 597 GrProcessorKeyBuilder* b) { |
| 596 const DashingCircleEffect& dce = processor.cast<DashingCircleEffect>(); | 598 const DashingCircleEffect& dce = processor.cast<DashingCircleEffect>(); |
| 597 b->add32(dce.getEdgeType()); | 599 b->add32(dce.getEdgeType()); |
| 598 } | 600 } |
| 599 | 601 |
| 600 ////////////////////////////////////////////////////////////////////////////// | 602 ////////////////////////////////////////////////////////////////////////////// |
| 601 | 603 |
| 602 GrGeometryProcessor* DashingCircleEffect::Create(GrPrimitiveEdgeType edgeType, c
onst DashInfo& info, | 604 GrGeometryProcessor* DashingCircleEffect::Create(GrColor color, |
| 605 GrPrimitiveEdgeType edgeType, |
| 606 const DashInfo& info, |
| 603 SkScalar radius) { | 607 SkScalar radius) { |
| 604 if (info.fCount != 2 || info.fIntervals[0] != 0) { | 608 if (info.fCount != 2 || info.fIntervals[0] != 0) { |
| 605 return NULL; | 609 return NULL; |
| 606 } | 610 } |
| 607 | 611 |
| 608 return SkNEW_ARGS(DashingCircleEffect, (edgeType, info, radius)); | 612 return SkNEW_ARGS(DashingCircleEffect, (color, edgeType, info, radius)); |
| 609 } | 613 } |
| 610 | 614 |
| 611 DashingCircleEffect::~DashingCircleEffect() {} | 615 DashingCircleEffect::~DashingCircleEffect() {} |
| 612 | 616 |
| 613 void DashingCircleEffect::onComputeInvariantOutput(GrInvariantOutput* inout) con
st { | 617 void DashingCircleEffect::onComputeInvariantOutput(GrInvariantOutput* inout) con
st { |
| 614 inout->mulByUnknownAlpha(); | 618 inout->mulByUnknownAlpha(); |
| 615 } | 619 } |
| 616 | 620 |
| 617 void DashingCircleEffect::getGLProcessorKey(const GrBatchTracker& bt, | 621 void DashingCircleEffect::getGLProcessorKey(const GrBatchTracker& bt, |
| 618 const GrGLCaps& caps, | 622 const GrGLCaps& caps, |
| 619 GrProcessorKeyBuilder* b) const { | 623 GrProcessorKeyBuilder* b) const { |
| 620 GLDashingCircleEffect::GenKey(*this, bt, caps, b); | 624 GLDashingCircleEffect::GenKey(*this, bt, caps, b); |
| 621 } | 625 } |
| 622 | 626 |
| 623 GrGLGeometryProcessor* DashingCircleEffect::createGLInstance(const GrBatchTracke
r& bt) const { | 627 GrGLGeometryProcessor* DashingCircleEffect::createGLInstance(const GrBatchTracke
r& bt) const { |
| 624 return SkNEW_ARGS(GLDashingCircleEffect, (*this, bt)); | 628 return SkNEW_ARGS(GLDashingCircleEffect, (*this, bt)); |
| 625 } | 629 } |
| 626 | 630 |
| 627 DashingCircleEffect::DashingCircleEffect(GrPrimitiveEdgeType edgeType, const Das
hInfo& info, | 631 DashingCircleEffect::DashingCircleEffect(GrColor color, |
| 632 GrPrimitiveEdgeType edgeType, |
| 633 const DashInfo& info, |
| 628 SkScalar radius) | 634 SkScalar radius) |
| 629 : fEdgeType(edgeType) { | 635 : INHERITED(color), fEdgeType(edgeType) { |
| 630 this->initClassID<DashingCircleEffect>(); | 636 this->initClassID<DashingCircleEffect>(); |
| 631 fInPosition = &this->addVertexAttrib(GrAttribute("inPosition", kVec2f_GrVert
exAttribType)); | 637 fInPosition = &this->addVertexAttrib(GrAttribute("inPosition", kVec2f_GrVert
exAttribType)); |
| 632 fInCoord = &this->addVertexAttrib(GrAttribute("inCoord", kVec2f_GrVertexAttr
ibType)); | 638 fInCoord = &this->addVertexAttrib(GrAttribute("inCoord", kVec2f_GrVertexAttr
ibType)); |
| 633 SkScalar onLen = info.fIntervals[0]; | 639 SkScalar onLen = info.fIntervals[0]; |
| 634 SkScalar offLen = info.fIntervals[1]; | 640 SkScalar offLen = info.fIntervals[1]; |
| 635 fIntervalLength = onLen + offLen; | 641 fIntervalLength = onLen + offLen; |
| 636 fRadius = radius; | 642 fRadius = radius; |
| 637 fCenterX = SkScalarHalf(offLen); | 643 fCenterX = SkScalarHalf(offLen); |
| 638 } | 644 } |
| 639 | 645 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 655 kGrProcessorEdgeTypeCnt)); | 661 kGrProcessorEdgeTypeCnt)); |
| 656 SkScalar strokeWidth = random->nextRangeScalar(0, 100.f); | 662 SkScalar strokeWidth = random->nextRangeScalar(0, 100.f); |
| 657 DashInfo info; | 663 DashInfo info; |
| 658 info.fCount = 2; | 664 info.fCount = 2; |
| 659 SkAutoTArray<SkScalar> intervals(info.fCount); | 665 SkAutoTArray<SkScalar> intervals(info.fCount); |
| 660 info.fIntervals = intervals.get(); | 666 info.fIntervals = intervals.get(); |
| 661 info.fIntervals[0] = 0; | 667 info.fIntervals[0] = 0; |
| 662 info.fIntervals[1] = random->nextRangeScalar(0, 10.f); | 668 info.fIntervals[1] = random->nextRangeScalar(0, 10.f); |
| 663 info.fPhase = random->nextRangeScalar(0, info.fIntervals[1]); | 669 info.fPhase = random->nextRangeScalar(0, info.fIntervals[1]); |
| 664 | 670 |
| 665 return DashingCircleEffect::Create(edgeType, info, strokeWidth); | 671 return DashingCircleEffect::Create(GrRandomColor(random), edgeType, info, st
rokeWidth); |
| 666 } | 672 } |
| 667 | 673 |
| 668 ////////////////////////////////////////////////////////////////////////////// | 674 ////////////////////////////////////////////////////////////////////////////// |
| 669 | 675 |
| 670 class GLDashingLineEffect; | 676 class GLDashingLineEffect; |
| 671 | 677 |
| 672 /* | 678 /* |
| 673 * This effect will draw a dashed line. The width of the dash is given by the st
rokeWidth and the | 679 * This effect will draw a dashed line. The width of the dash is given by the st
rokeWidth and the |
| 674 * length and spacing by the DashInfo. Both of the previous two parameters are i
n device space. | 680 * length and spacing by the DashInfo. Both of the previous two parameters are i
n device space. |
| 675 * This effect also requires the setting of a vec2 vertex attribute for the the
four corners of the | 681 * This effect also requires the setting of a vec2 vertex attribute for the the
four corners of the |
| 676 * bounding rect. This attribute is the "dash position" of each vertex. In other
words it is the | 682 * bounding rect. This attribute is the "dash position" of each vertex. In other
words it is the |
| 677 * vertex coords (in device space) if we transform the line to be horizontal, wi
th the start of | 683 * vertex coords (in device space) if we transform the line to be horizontal, wi
th the start of |
| 678 * line at the origin then shifted to the right by half the off interval. The li
ne then goes in the | 684 * line at the origin then shifted to the right by half the off interval. The li
ne then goes in the |
| 679 * positive x direction. | 685 * positive x direction. |
| 680 */ | 686 */ |
| 681 class DashingLineEffect : public GrGeometryProcessor { | 687 class DashingLineEffect : public GrGeometryProcessor { |
| 682 public: | 688 public: |
| 683 typedef SkPathEffect::DashInfo DashInfo; | 689 typedef SkPathEffect::DashInfo DashInfo; |
| 684 | 690 |
| 685 static GrGeometryProcessor* Create(GrPrimitiveEdgeType edgeType, | 691 static GrGeometryProcessor* Create(GrColor, |
| 692 GrPrimitiveEdgeType edgeType, |
| 686 const DashInfo& info, | 693 const DashInfo& info, |
| 687 SkScalar strokeWidth); | 694 SkScalar strokeWidth); |
| 688 | 695 |
| 689 virtual ~DashingLineEffect(); | 696 virtual ~DashingLineEffect(); |
| 690 | 697 |
| 691 virtual const char* name() const SK_OVERRIDE { return "DashingEffect"; } | 698 virtual const char* name() const SK_OVERRIDE { return "DashingEffect"; } |
| 692 | 699 |
| 693 const GrAttribute* inPosition() const { return fInPosition; } | 700 const GrAttribute* inPosition() const { return fInPosition; } |
| 694 | 701 |
| 695 const GrAttribute* inCoord() const { return fInCoord; } | 702 const GrAttribute* inCoord() const { return fInCoord; } |
| 696 | 703 |
| 697 GrPrimitiveEdgeType getEdgeType() const { return fEdgeType; } | 704 GrPrimitiveEdgeType getEdgeType() const { return fEdgeType; } |
| 698 | 705 |
| 699 const SkRect& getRect() const { return fRect; } | 706 const SkRect& getRect() const { return fRect; } |
| 700 | 707 |
| 701 SkScalar getIntervalLength() const { return fIntervalLength; } | 708 SkScalar getIntervalLength() const { return fIntervalLength; } |
| 702 | 709 |
| 703 virtual void getGLProcessorKey(const GrBatchTracker& bt, | 710 virtual void getGLProcessorKey(const GrBatchTracker& bt, |
| 704 const GrGLCaps& caps, | 711 const GrGLCaps& caps, |
| 705 GrProcessorKeyBuilder* b) const SK_OVERRIDE; | 712 GrProcessorKeyBuilder* b) const SK_OVERRIDE; |
| 706 | 713 |
| 707 virtual GrGLGeometryProcessor* createGLInstance(const GrBatchTracker& bt) co
nst SK_OVERRIDE; | 714 virtual GrGLGeometryProcessor* createGLInstance(const GrBatchTracker& bt) co
nst SK_OVERRIDE; |
| 708 | 715 |
| 709 private: | 716 private: |
| 710 DashingLineEffect(GrPrimitiveEdgeType edgeType, const DashInfo& info, SkScal
ar strokeWidth); | 717 DashingLineEffect(GrColor, GrPrimitiveEdgeType edgeType, const DashInfo& inf
o, |
| 718 SkScalar strokeWidth); |
| 711 | 719 |
| 712 virtual bool onIsEqual(const GrGeometryProcessor& other) const SK_OVERRIDE; | 720 virtual bool onIsEqual(const GrGeometryProcessor& other) const SK_OVERRIDE; |
| 713 | 721 |
| 714 virtual void onComputeInvariantOutput(GrInvariantOutput* inout) const SK_OVE
RRIDE; | 722 virtual void onComputeInvariantOutput(GrInvariantOutput* inout) const SK_OVE
RRIDE; |
| 715 | 723 |
| 716 GrPrimitiveEdgeType fEdgeType; | 724 GrPrimitiveEdgeType fEdgeType; |
| 717 const GrAttribute* fInPosition; | 725 const GrAttribute* fInPosition; |
| 718 const GrAttribute* fInCoord; | 726 const GrAttribute* fInCoord; |
| 719 SkRect fRect; | 727 SkRect fRect; |
| 720 SkScalar fIntervalLength; | 728 SkScalar fIntervalLength; |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 829 void GLDashingLineEffect::GenKey(const GrGeometryProcessor& processor, | 837 void GLDashingLineEffect::GenKey(const GrGeometryProcessor& processor, |
| 830 const GrBatchTracker&, | 838 const GrBatchTracker&, |
| 831 const GrGLCaps&, | 839 const GrGLCaps&, |
| 832 GrProcessorKeyBuilder* b) { | 840 GrProcessorKeyBuilder* b) { |
| 833 const DashingLineEffect& de = processor.cast<DashingLineEffect>(); | 841 const DashingLineEffect& de = processor.cast<DashingLineEffect>(); |
| 834 b->add32(de.getEdgeType()); | 842 b->add32(de.getEdgeType()); |
| 835 } | 843 } |
| 836 | 844 |
| 837 ////////////////////////////////////////////////////////////////////////////// | 845 ////////////////////////////////////////////////////////////////////////////// |
| 838 | 846 |
| 839 GrGeometryProcessor* DashingLineEffect::Create(GrPrimitiveEdgeType edgeType, | 847 GrGeometryProcessor* DashingLineEffect::Create(GrColor color, |
| 848 GrPrimitiveEdgeType edgeType, |
| 840 const DashInfo& info, | 849 const DashInfo& info, |
| 841 SkScalar strokeWidth) { | 850 SkScalar strokeWidth) { |
| 842 if (info.fCount != 2) { | 851 if (info.fCount != 2) { |
| 843 return NULL; | 852 return NULL; |
| 844 } | 853 } |
| 845 | 854 |
| 846 return SkNEW_ARGS(DashingLineEffect, (edgeType, info, strokeWidth)); | 855 return SkNEW_ARGS(DashingLineEffect, (color, edgeType, info, strokeWidth)); |
| 847 } | 856 } |
| 848 | 857 |
| 849 DashingLineEffect::~DashingLineEffect() {} | 858 DashingLineEffect::~DashingLineEffect() {} |
| 850 | 859 |
| 851 void DashingLineEffect::onComputeInvariantOutput(GrInvariantOutput* inout) const
{ | 860 void DashingLineEffect::onComputeInvariantOutput(GrInvariantOutput* inout) const
{ |
| 852 inout->mulByUnknownAlpha(); | 861 inout->mulByUnknownAlpha(); |
| 853 } | 862 } |
| 854 | 863 |
| 855 void DashingLineEffect::getGLProcessorKey(const GrBatchTracker& bt, | 864 void DashingLineEffect::getGLProcessorKey(const GrBatchTracker& bt, |
| 856 const GrGLCaps& caps, | 865 const GrGLCaps& caps, |
| 857 GrProcessorKeyBuilder* b) const { | 866 GrProcessorKeyBuilder* b) const { |
| 858 GLDashingLineEffect::GenKey(*this, bt, caps, b); | 867 GLDashingLineEffect::GenKey(*this, bt, caps, b); |
| 859 } | 868 } |
| 860 | 869 |
| 861 GrGLGeometryProcessor* DashingLineEffect::createGLInstance(const GrBatchTracker&
bt) const { | 870 GrGLGeometryProcessor* DashingLineEffect::createGLInstance(const GrBatchTracker&
bt) const { |
| 862 return SkNEW_ARGS(GLDashingLineEffect, (*this, bt)); | 871 return SkNEW_ARGS(GLDashingLineEffect, (*this, bt)); |
| 863 } | 872 } |
| 864 | 873 |
| 865 DashingLineEffect::DashingLineEffect(GrPrimitiveEdgeType edgeType, const DashInf
o& info, | 874 DashingLineEffect::DashingLineEffect(GrColor color, |
| 875 GrPrimitiveEdgeType edgeType, |
| 876 const DashInfo& info, |
| 866 SkScalar strokeWidth) | 877 SkScalar strokeWidth) |
| 867 : fEdgeType(edgeType) { | 878 : INHERITED(color), fEdgeType(edgeType) { |
| 868 this->initClassID<DashingLineEffect>(); | 879 this->initClassID<DashingLineEffect>(); |
| 869 fInPosition = &this->addVertexAttrib(GrAttribute("inPosition", kVec2f_GrVert
exAttribType)); | 880 fInPosition = &this->addVertexAttrib(GrAttribute("inPosition", kVec2f_GrVert
exAttribType)); |
| 870 fInCoord = &this->addVertexAttrib(GrAttribute("inCoord", kVec2f_GrVertexAttr
ibType)); | 881 fInCoord = &this->addVertexAttrib(GrAttribute("inCoord", kVec2f_GrVertexAttr
ibType)); |
| 871 SkScalar onLen = info.fIntervals[0]; | 882 SkScalar onLen = info.fIntervals[0]; |
| 872 SkScalar offLen = info.fIntervals[1]; | 883 SkScalar offLen = info.fIntervals[1]; |
| 873 SkScalar halfOffLen = SkScalarHalf(offLen); | 884 SkScalar halfOffLen = SkScalarHalf(offLen); |
| 874 SkScalar halfStroke = SkScalarHalf(strokeWidth); | 885 SkScalar halfStroke = SkScalarHalf(strokeWidth); |
| 875 fIntervalLength = onLen + offLen; | 886 fIntervalLength = onLen + offLen; |
| 876 fRect.set(halfOffLen, -halfStroke, halfOffLen + onLen, halfStroke); | 887 fRect.set(halfOffLen, -halfStroke, halfOffLen + onLen, halfStroke); |
| 877 } | 888 } |
| (...skipping 15 matching lines...) Expand all Loading... |
| 893 kGrProcessorEdgeTypeCnt)); | 904 kGrProcessorEdgeTypeCnt)); |
| 894 SkScalar strokeWidth = random->nextRangeScalar(0, 100.f); | 905 SkScalar strokeWidth = random->nextRangeScalar(0, 100.f); |
| 895 DashInfo info; | 906 DashInfo info; |
| 896 info.fCount = 2; | 907 info.fCount = 2; |
| 897 SkAutoTArray<SkScalar> intervals(info.fCount); | 908 SkAutoTArray<SkScalar> intervals(info.fCount); |
| 898 info.fIntervals = intervals.get(); | 909 info.fIntervals = intervals.get(); |
| 899 info.fIntervals[0] = random->nextRangeScalar(0, 10.f); | 910 info.fIntervals[0] = random->nextRangeScalar(0, 10.f); |
| 900 info.fIntervals[1] = random->nextRangeScalar(0, 10.f); | 911 info.fIntervals[1] = random->nextRangeScalar(0, 10.f); |
| 901 info.fPhase = random->nextRangeScalar(0, info.fIntervals[0] + info.fInterval
s[1]); | 912 info.fPhase = random->nextRangeScalar(0, info.fIntervals[0] + info.fInterval
s[1]); |
| 902 | 913 |
| 903 return DashingLineEffect::Create(edgeType, info, strokeWidth); | 914 return DashingLineEffect::Create(GrRandomColor(random), edgeType, info, stro
keWidth); |
| 904 } | 915 } |
| 905 | 916 |
| 906 ////////////////////////////////////////////////////////////////////////////// | 917 ////////////////////////////////////////////////////////////////////////////// |
| 907 | 918 |
| 908 GrGeometryProcessor* GrDashingEffect::Create(GrPrimitiveEdgeType edgeType, | 919 GrGeometryProcessor* GrDashingEffect::Create(GrColor color, |
| 920 GrPrimitiveEdgeType edgeType, |
| 909 const SkPathEffect::DashInfo& info, | 921 const SkPathEffect::DashInfo& info, |
| 910 SkScalar strokeWidth, | 922 SkScalar strokeWidth, |
| 911 GrDashingEffect::DashCap cap) { | 923 GrDashingEffect::DashCap cap) { |
| 912 switch (cap) { | 924 switch (cap) { |
| 913 case GrDashingEffect::kRound_DashCap: | 925 case GrDashingEffect::kRound_DashCap: |
| 914 return DashingCircleEffect::Create(edgeType, info, SkScalarHalf(stro
keWidth)); | 926 return DashingCircleEffect::Create(color, edgeType, info, SkScalarHa
lf(strokeWidth)); |
| 915 case GrDashingEffect::kNonRound_DashCap: | 927 case GrDashingEffect::kNonRound_DashCap: |
| 916 return DashingLineEffect::Create(edgeType, info, strokeWidth); | 928 return DashingLineEffect::Create(color, edgeType, info, strokeWidth)
; |
| 917 default: | 929 default: |
| 918 SkFAIL("Unexpected dashed cap."); | 930 SkFAIL("Unexpected dashed cap."); |
| 919 } | 931 } |
| 920 return NULL; | 932 return NULL; |
| 921 } | 933 } |
| OLD | NEW |