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 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
328 | 328 |
329 SkPoint devicePts[2]; | 329 SkPoint devicePts[2]; |
330 vm.mapPoints(devicePts, ptsRot, 2); | 330 vm.mapPoints(devicePts, ptsRot, 2); |
331 SkScalar lineLength = SkPoint::Distance(devicePts[0], devicePts[1]); | 331 SkScalar lineLength = SkPoint::Distance(devicePts[0], devicePts[1]); |
332 if (hasCap) { | 332 if (hasCap) { |
333 lineLength += 2.f * halfDevStroke; | 333 lineLength += 2.f * halfDevStroke; |
334 } | 334 } |
335 devIntervals[0] = lineLength; | 335 devIntervals[0] = lineLength; |
336 } | 336 } |
337 | 337 |
338 SkAutoTUnref<const GrGeometryProcessor> gp; | 338 const GrGeometryProcessor* gp; |
339 bool fullDash = devIntervals[1] > 0.f || useAA; | 339 bool fullDash = devIntervals[1] > 0.f || useAA; |
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.reset(GrDashingEffect::Create(color, 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.reset(GrDefaultGeoProcFactory::Create(color, GrDefaultGeoProcFactory:
:kPosition_GPType)); | 353 gp = GrDefaultGeoProcFactory::Create(color, GrDefaultGeoProcFactory::kPo
sition_GPType); |
354 } | 354 } |
355 | 355 |
| 356 drawState->setGeometryProcessor(gp)->unref(); |
| 357 |
356 int totalRectCnt = 0; | 358 int totalRectCnt = 0; |
357 | 359 |
358 totalRectCnt += !lineDone ? 1 : 0; | 360 totalRectCnt += !lineDone ? 1 : 0; |
359 totalRectCnt += hasStartRect ? 1 : 0; | 361 totalRectCnt += hasStartRect ? 1 : 0; |
360 totalRectCnt += hasEndRect ? 1 : 0; | 362 totalRectCnt += hasEndRect ? 1 : 0; |
361 | 363 |
362 GrDrawTarget::AutoReleaseGeometry geo(target, | 364 GrDrawTarget::AutoReleaseGeometry geo(target, |
363 totalRectCnt * 4, | 365 totalRectCnt * 4, |
364 gp->getVertexStride(), 0); | 366 gp->getVertexStride(), 0); |
365 if (!geo.succeeded()) { | 367 if (!geo.succeeded()) { |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
426 devIntervals[0], halfDevStroke); | 428 devIntervals[0], halfDevStroke); |
427 } else { | 429 } else { |
428 SkPoint* verts = reinterpret_cast<SkPoint*>(geo.vertices()); | 430 SkPoint* verts = reinterpret_cast<SkPoint*>(geo.vertices()); |
429 SkASSERT(gp->getVertexStride() == sizeof(SkPoint)); | 431 SkASSERT(gp->getVertexStride() == sizeof(SkPoint)); |
430 setup_dashed_rect_pos(endRect, curVIdx, combinedMatrix, verts); | 432 setup_dashed_rect_pos(endRect, curVIdx, combinedMatrix, verts); |
431 } | 433 } |
432 | 434 |
433 } | 435 } |
434 | 436 |
435 target->setIndexSourceToBuffer(gpu->getContext()->getQuadIndexBuffer()); | 437 target->setIndexSourceToBuffer(gpu->getContext()->getQuadIndexBuffer()); |
436 target->drawIndexedInstances(drawState, gp, kTriangles_GrPrimitiveType, tota
lRectCnt, 4, 6); | 438 target->drawIndexedInstances(drawState, kTriangles_GrPrimitiveType, totalRec
tCnt, 4, 6); |
437 target->resetIndexSource(); | 439 target->resetIndexSource(); |
438 return true; | 440 return true; |
439 } | 441 } |
440 | 442 |
441 ////////////////////////////////////////////////////////////////////////////// | 443 ////////////////////////////////////////////////////////////////////////////// |
442 | 444 |
443 class GLDashingCircleEffect; | 445 class GLDashingCircleEffect; |
444 /* | 446 /* |
445 * This effect will draw a dotted line (defined as a dashed lined with round cap
s and no on | 447 * 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. | 448 * interval). The radius of the dots is given by the strokeWidth and the spacing
by the DashInfo. |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
480 GrProcessorKeyBuilder* b) const SK_OVERRIDE; | 482 GrProcessorKeyBuilder* b) const SK_OVERRIDE; |
481 | 483 |
482 virtual GrGLGeometryProcessor* createGLInstance(const GrBatchTracker&) const
SK_OVERRIDE; | 484 virtual GrGLGeometryProcessor* createGLInstance(const GrBatchTracker&) const
SK_OVERRIDE; |
483 | 485 |
484 private: | 486 private: |
485 DashingCircleEffect(GrColor, GrPrimitiveEdgeType edgeType, const DashInfo& i
nfo, | 487 DashingCircleEffect(GrColor, GrPrimitiveEdgeType edgeType, const DashInfo& i
nfo, |
486 SkScalar radius); | 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 onGetInvariantOutputCoverage(GrInitInvariantOutput*) const SK_O
VERRIDE; | 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; |
497 SkScalar fCenterX; | 499 SkScalar fCenterX; |
498 | 500 |
499 GR_DECLARE_GEOMETRY_PROCESSOR_TEST; | 501 GR_DECLARE_GEOMETRY_PROCESSOR_TEST; |
500 | 502 |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
605 SkScalar radius) { | 607 SkScalar radius) { |
606 if (info.fCount != 2 || info.fIntervals[0] != 0) { | 608 if (info.fCount != 2 || info.fIntervals[0] != 0) { |
607 return NULL; | 609 return NULL; |
608 } | 610 } |
609 | 611 |
610 return SkNEW_ARGS(DashingCircleEffect, (color, edgeType, info, radius)); | 612 return SkNEW_ARGS(DashingCircleEffect, (color, edgeType, info, radius)); |
611 } | 613 } |
612 | 614 |
613 DashingCircleEffect::~DashingCircleEffect() {} | 615 DashingCircleEffect::~DashingCircleEffect() {} |
614 | 616 |
615 void DashingCircleEffect::onGetInvariantOutputCoverage(GrInitInvariantOutput* ou
t) const { | 617 void DashingCircleEffect::onComputeInvariantOutput(GrInvariantOutput* inout) con
st { |
616 out->setUnknownSingleComponent(); | 618 inout->mulByUnknownAlpha(); |
617 } | 619 } |
618 | 620 |
619 void DashingCircleEffect::getGLProcessorKey(const GrBatchTracker& bt, | 621 void DashingCircleEffect::getGLProcessorKey(const GrBatchTracker& bt, |
620 const GrGLCaps& caps, | 622 const GrGLCaps& caps, |
621 GrProcessorKeyBuilder* b) const { | 623 GrProcessorKeyBuilder* b) const { |
622 GLDashingCircleEffect::GenKey(*this, bt, caps, b); | 624 GLDashingCircleEffect::GenKey(*this, bt, caps, b); |
623 } | 625 } |
624 | 626 |
625 GrGLGeometryProcessor* DashingCircleEffect::createGLInstance(const GrBatchTracke
r& bt) const { | 627 GrGLGeometryProcessor* DashingCircleEffect::createGLInstance(const GrBatchTracke
r& bt) const { |
626 return SkNEW_ARGS(GLDashingCircleEffect, (*this, bt)); | 628 return SkNEW_ARGS(GLDashingCircleEffect, (*this, bt)); |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
710 GrProcessorKeyBuilder* b) const SK_OVERRIDE; | 712 GrProcessorKeyBuilder* b) const SK_OVERRIDE; |
711 | 713 |
712 virtual GrGLGeometryProcessor* createGLInstance(const GrBatchTracker& bt) co
nst SK_OVERRIDE; | 714 virtual GrGLGeometryProcessor* createGLInstance(const GrBatchTracker& bt) co
nst SK_OVERRIDE; |
713 | 715 |
714 private: | 716 private: |
715 DashingLineEffect(GrColor, GrPrimitiveEdgeType edgeType, const DashInfo& inf
o, | 717 DashingLineEffect(GrColor, GrPrimitiveEdgeType edgeType, const DashInfo& inf
o, |
716 SkScalar strokeWidth); | 718 SkScalar strokeWidth); |
717 | 719 |
718 virtual bool onIsEqual(const GrGeometryProcessor& other) const SK_OVERRIDE; | 720 virtual bool onIsEqual(const GrGeometryProcessor& other) const SK_OVERRIDE; |
719 | 721 |
720 virtual void onGetInvariantOutputCoverage(GrInitInvariantOutput*) const SK_O
VERRIDE; | 722 virtual void onComputeInvariantOutput(GrInvariantOutput* inout) const SK_OVE
RRIDE; |
721 | 723 |
722 GrPrimitiveEdgeType fEdgeType; | 724 GrPrimitiveEdgeType fEdgeType; |
723 const GrAttribute* fInPosition; | 725 const GrAttribute* fInPosition; |
724 const GrAttribute* fInCoord; | 726 const GrAttribute* fInCoord; |
725 SkRect fRect; | 727 SkRect fRect; |
726 SkScalar fIntervalLength; | 728 SkScalar fIntervalLength; |
727 | 729 |
728 GR_DECLARE_GEOMETRY_PROCESSOR_TEST; | 730 GR_DECLARE_GEOMETRY_PROCESSOR_TEST; |
729 | 731 |
730 typedef GrGeometryProcessor INHERITED; | 732 typedef GrGeometryProcessor INHERITED; |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
848 SkScalar strokeWidth) { | 850 SkScalar strokeWidth) { |
849 if (info.fCount != 2) { | 851 if (info.fCount != 2) { |
850 return NULL; | 852 return NULL; |
851 } | 853 } |
852 | 854 |
853 return SkNEW_ARGS(DashingLineEffect, (color, edgeType, info, strokeWidth)); | 855 return SkNEW_ARGS(DashingLineEffect, (color, edgeType, info, strokeWidth)); |
854 } | 856 } |
855 | 857 |
856 DashingLineEffect::~DashingLineEffect() {} | 858 DashingLineEffect::~DashingLineEffect() {} |
857 | 859 |
858 void DashingLineEffect::onGetInvariantOutputCoverage(GrInitInvariantOutput* out)
const { | 860 void DashingLineEffect::onComputeInvariantOutput(GrInvariantOutput* inout) const
{ |
859 out->setUnknownSingleComponent(); | 861 inout->mulByUnknownAlpha(); |
860 } | 862 } |
861 | 863 |
862 void DashingLineEffect::getGLProcessorKey(const GrBatchTracker& bt, | 864 void DashingLineEffect::getGLProcessorKey(const GrBatchTracker& bt, |
863 const GrGLCaps& caps, | 865 const GrGLCaps& caps, |
864 GrProcessorKeyBuilder* b) const { | 866 GrProcessorKeyBuilder* b) const { |
865 GLDashingLineEffect::GenKey(*this, bt, caps, b); | 867 GLDashingLineEffect::GenKey(*this, bt, caps, b); |
866 } | 868 } |
867 | 869 |
868 GrGLGeometryProcessor* DashingLineEffect::createGLInstance(const GrBatchTracker&
bt) const { | 870 GrGLGeometryProcessor* DashingLineEffect::createGLInstance(const GrBatchTracker&
bt) const { |
869 return SkNEW_ARGS(GLDashingLineEffect, (*this, bt)); | 871 return SkNEW_ARGS(GLDashingLineEffect, (*this, bt)); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
922 switch (cap) { | 924 switch (cap) { |
923 case GrDashingEffect::kRound_DashCap: | 925 case GrDashingEffect::kRound_DashCap: |
924 return DashingCircleEffect::Create(color, edgeType, info, SkScalarHa
lf(strokeWidth)); | 926 return DashingCircleEffect::Create(color, edgeType, info, SkScalarHa
lf(strokeWidth)); |
925 case GrDashingEffect::kNonRound_DashCap: | 927 case GrDashingEffect::kNonRound_DashCap: |
926 return DashingLineEffect::Create(color, edgeType, info, strokeWidth)
; | 928 return DashingLineEffect::Create(color, edgeType, info, strokeWidth)
; |
927 default: | 929 default: |
928 SkFAIL("Unexpected dashed cap."); | 930 SkFAIL("Unexpected dashed cap."); |
929 } | 931 } |
930 return NULL; | 932 return NULL; |
931 } | 933 } |
OLD | NEW |