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

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

Issue 345113003: Add the ability for gpu to render dotted lines (dashed line, 0 on interval, round caps) (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Clean up and Add GM ignore Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/gpu/effects/GrDashingEffect.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 return false; 47 return false;
48 } 48 }
49 49
50 const SkPathEffect::DashInfo& info = strokeInfo.getDashInfo(); 50 const SkPathEffect::DashInfo& info = strokeInfo.getDashInfo();
51 if (0 == info.fIntervals[0] && 0 == info.fIntervals[1]) { 51 if (0 == info.fIntervals[0] && 0 == info.fIntervals[1]) {
52 return false; 52 return false;
53 } 53 }
54 54
55 SkPaint::Cap cap = strokeInfo.getStrokeRec().getCap(); 55 SkPaint::Cap cap = strokeInfo.getStrokeRec().getCap();
56 // Current we do don't handle Round or Square cap dashes 56 // Current we do don't handle Round or Square cap dashes
57 if (SkPaint::kRound_Cap == cap) { 57 if (SkPaint::kRound_Cap == cap && info.fIntervals[0] != 0.f) {
58 return false; 58 return false;
59 } 59 }
60 60
61 return true; 61 return true;
62 } 62 }
63 63
64 namespace { 64 namespace {
65 65
66 struct DashLineVertex { 66 struct DashLineVertex {
67 SkPoint fPos; 67 SkPoint fPos;
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 memcpy(ptsRot, pts, 2 * sizeof(SkPoint)); 197 memcpy(ptsRot, pts, 2 * sizeof(SkPoint));
198 } 198 }
199 199
200 bool useAA = paint.isAntiAlias(); 200 bool useAA = paint.isAntiAlias();
201 201
202 // Scale corrections of intervals and stroke from view matrix 202 // Scale corrections of intervals and stroke from view matrix
203 SkScalar parallelScale; 203 SkScalar parallelScale;
204 SkScalar perpScale; 204 SkScalar perpScale;
205 calc_dash_scaling(&parallelScale, &perpScale, vm, ptsRot); 205 calc_dash_scaling(&parallelScale, &perpScale, vm, ptsRot);
206 206
207 bool hasCap = SkPaint::kSquare_Cap == cap && 0 != srcStrokeWidth; 207 bool hasCap = SkPaint::kButt_Cap != cap && 0 != srcStrokeWidth;
208 208
209 // We always want to at least stroke out half a pixel on each side in device space 209 // We always want to at least stroke out half a pixel on each side in device space
210 // so 0.5f / perpScale gives us this min in src space 210 // so 0.5f / perpScale gives us this min in src space
211 SkScalar halfSrcStroke = SkMaxScalar(srcStrokeWidth * 0.5f, 0.5f / perpScale ); 211 SkScalar halfSrcStroke = SkMaxScalar(srcStrokeWidth * 0.5f, 0.5f / perpScale );
212 212
213 SkScalar strokeAdj; 213 SkScalar strokeAdj;
214 if (!hasCap) { 214 if (!hasCap) {
215 strokeAdj = 0.f; 215 strokeAdj = 0.f;
216 } else { 216 } else {
217 strokeAdj = halfSrcStroke; 217 strokeAdj = halfSrcStroke;
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 } 334 }
335 devIntervals[0] = lineLength; 335 devIntervals[0] = lineLength;
336 } 336 }
337 if (devIntervals[1] > 0.f || useAA) { 337 if (devIntervals[1] > 0.f || useAA) {
338 SkPathEffect::DashInfo devInfo; 338 SkPathEffect::DashInfo devInfo;
339 devInfo.fPhase = devPhase; 339 devInfo.fPhase = devPhase;
340 devInfo.fCount = 2; 340 devInfo.fCount = 2;
341 devInfo.fIntervals = devIntervals; 341 devInfo.fIntervals = devIntervals;
342 GrEffectEdgeType edgeType= useAA ? kFillAA_GrEffectEdgeType : 342 GrEffectEdgeType edgeType= useAA ? kFillAA_GrEffectEdgeType :
343 kFillBW_GrEffectEdgeType; 343 kFillBW_GrEffectEdgeType;
344 bool isRoundCap = SkPaint::kRound_Cap == cap;
345 GrDashingEffect::DashCap capType = isRoundCap ? GrDashingEffect::kRound_ DashCap :
346 GrDashingEffect::kNonRou nd_DashCap;
344 drawState->addCoverageEffect( 347 drawState->addCoverageEffect(
345 GrDashingEffect::Create(edgeType, devInfo, strokeWidth), 1)->unref() ; 348 GrDashingEffect::Create(edgeType, devInfo, strokeWidth, capType), 1) ->unref();
346 } 349 }
347 350
348 // Set up the vertex data for the line and start/end dashes 351 // Set up the vertex data for the line and start/end dashes
349 drawState->setVertexAttribs<gDashLineVertexAttribs>(SK_ARRAY_COUNT(gDashLine VertexAttribs)); 352 drawState->setVertexAttribs<gDashLineVertexAttribs>(SK_ARRAY_COUNT(gDashLine VertexAttribs));
350 353
351 int totalRectCnt = 0; 354 int totalRectCnt = 0;
352 355
353 totalRectCnt += !lineDone ? 1 : 0; 356 totalRectCnt += !lineDone ? 1 : 0;
354 totalRectCnt += hasStartRect ? 1 : 0; 357 totalRectCnt += hasStartRect ? 1 : 0;
355 totalRectCnt += hasEndRect ? 1 : 0; 358 totalRectCnt += hasEndRect ? 1 : 0;
356 359
357 GrDrawTarget::AutoReleaseGeometry geo(target, totalRectCnt * 4, 0); 360 GrDrawTarget::AutoReleaseGeometry geo(target, totalRectCnt * 4, 0);
358 if (!geo.succeeded()) { 361 if (!geo.succeeded()) {
359 GrPrintf("Failed to get space for vertices!\n"); 362 GrPrintf("Failed to get space for vertices!\n");
360 return false; 363 return false;
361 } 364 }
362 365
363 DashLineVertex* verts = reinterpret_cast<DashLineVertex*>(geo.vertices()); 366 DashLineVertex* verts = reinterpret_cast<DashLineVertex*>(geo.vertices());
364 367
365 int curVIdx = 0; 368 int curVIdx = 0;
366 369
370 if (SkPaint::kRound_Cap == cap && 0 != srcStrokeWidth) {
371 // need to adjust this for round caps to correctly set the dashPos attri b on vertices
372 startOffset -= halfDevStroke;
373 }
374
367 // Draw interior part of dashed line 375 // Draw interior part of dashed line
368 if (!lineDone) { 376 if (!lineDone) {
369 SkPoint devicePts[2]; 377 SkPoint devicePts[2];
370 vm.mapPoints(devicePts, ptsRot, 2); 378 vm.mapPoints(devicePts, ptsRot, 2);
371 SkScalar lineLength = SkPoint::Distance(devicePts[0], devicePts[1]); 379 SkScalar lineLength = SkPoint::Distance(devicePts[0], devicePts[1]);
372 if (hasCap) { 380 if (hasCap) {
373 lineLength += 2.f * halfDevStroke; 381 lineLength += 2.f * halfDevStroke;
374 } 382 }
375 383
376 SkRect bounds; 384 SkRect bounds;
(...skipping 20 matching lines...) Expand all
397 } 405 }
398 406
399 target->setIndexSourceToBuffer(gpu->getContext()->getQuadIndexBuffer()); 407 target->setIndexSourceToBuffer(gpu->getContext()->getQuadIndexBuffer());
400 target->drawIndexedInstances(kTriangles_GrPrimitiveType, totalRectCnt, 4, 6) ; 408 target->drawIndexedInstances(kTriangles_GrPrimitiveType, totalRectCnt, 4, 6) ;
401 target->resetIndexSource(); 409 target->resetIndexSource();
402 return true; 410 return true;
403 } 411 }
404 412
405 ////////////////////////////////////////////////////////////////////////////// 413 //////////////////////////////////////////////////////////////////////////////
406 414
415 class GLDashingCircleEffect;
416 /*
417 * This effect will draw a dotted line (defined as a dashed lined with round cap s and no on
418 * interval). The radius of the dots is given by the strokeWidth and the spacing by the DashInfo.
419 * Both of the previous two parameters are in device space. This effect also req uires the setting of
420 * a vec2 vertex attribute for the the four corners of the bounding rect. This a ttribute is the
421 * "dash position" of each vertex. In other words it is the vertex coords (in de vice space) if we
422 * transform the line to be horizontal, with the start of line at the origin the n shifted to the
423 * right by half the off interval. The line then goes in the positive x directio n.
424 */
425 class DashingCircleEffect : public GrVertexEffect {
426 public:
427 typedef SkPathEffect::DashInfo DashInfo;
428
429 static GrEffectRef* Create(GrEffectEdgeType edgeType, const DashInfo& info,
430 SkScalar radius);
431
432 virtual ~DashingCircleEffect();
433
434 static const char* Name() { return "DashingCircleEffect"; }
435
436 GrEffectEdgeType getEdgeType() const { return fEdgeType; }
437
438 SkScalar getRadius() const { return fRadius; }
439
440 SkScalar getCenterX() const { return fCenterX; }
441
442 SkScalar getIntervalLength() const { return fIntervalLength; }
443
444 typedef GLDashingCircleEffect GLEffect;
445
446 virtual void getConstantColorComponents(GrColor* color, uint32_t* validFlags ) const SK_OVERRIDE;
447
448 virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE;
449
450 private:
451 DashingCircleEffect(GrEffectEdgeType edgeType, const DashInfo& info, SkScala r radius);
452
453 virtual bool onIsEqual(const GrEffect& other) const SK_OVERRIDE;
454
455 GrEffectEdgeType fEdgeType;
456 SkScalar fIntervalLength;
457 SkScalar fRadius;
458 SkScalar fCenterX;
459
460 GR_DECLARE_EFFECT_TEST;
461
462 typedef GrVertexEffect INHERITED;
463 };
464
465 //////////////////////////////////////////////////////////////////////////////
466
467 class GLDashingCircleEffect : public GrGLVertexEffect {
468 public:
469 GLDashingCircleEffect(const GrBackendEffectFactory&, const GrDrawEffect&);
470
471 virtual void emitCode(GrGLFullShaderBuilder* builder,
472 const GrDrawEffect& drawEffect,
473 EffectKey key,
474 const char* outputColor,
475 const char* inputColor,
476 const TransformedCoordsArray&,
477 const TextureSamplerArray&) SK_OVERRIDE;
478
479 static inline EffectKey GenKey(const GrDrawEffect&, const GrGLCaps&);
480
481 virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_OVER RIDE;
482
483 private:
484 GrGLUniformManager::UniformHandle fParamUniform;
485 SkScalar fPrevRadius;
486 SkScalar fPrevCenterX;
487 SkScalar fPrevIntervalLength;
488 typedef GrGLVertexEffect INHERITED;
489 };
490
491 GLDashingCircleEffect::GLDashingCircleEffect(const GrBackendEffectFactory& facto ry,
492 const GrDrawEffect& drawEffect)
493 : INHERITED (factory) {
494 fPrevRadius = SK_ScalarMin;
495 fPrevCenterX = SK_ScalarMin;
496 fPrevIntervalLength = SK_ScalarMax;
497 }
498
499 void GLDashingCircleEffect::emitCode(GrGLFullShaderBuilder* builder,
500 const GrDrawEffect& drawEffect,
501 EffectKey key,
502 const char* outputColor,
503 const char* inputColor,
504 const TransformedCoordsArray&,
505 const TextureSamplerArray& samplers) {
506 const DashingCircleEffect& dce = drawEffect.castEffect<DashingCircleEffect>( );
507 const char *paramName;
508 // The param uniforms, xyz, refer to circle radius - 0.5, cicles center x co ord, and
509 // the total interval length of the dash.
510 fParamUniform = builder->addUniform(GrGLShaderBuilder::kFragment_Visibility,
511 kVec3f_GrSLType,
512 "params",
513 &paramName);
514
515 const char *vsCoordName, *fsCoordName;
516 builder->addVarying(kVec2f_GrSLType, "Coord", &vsCoordName, &fsCoordName);
517 const SkString* attr0Name =
518 builder->getEffectAttributeName(drawEffect.getVertexAttribIndices()[0]);
519 builder->vsCodeAppendf("\t%s = %s;\n", vsCoordName, attr0Name->c_str());
520
521 // transforms all points so that we can compare them to our test circle
522 builder->fsCodeAppendf("\t\tfloat xShifted = %s.x - floor(%s.x / %s.z) * %s. z;\n",
523 fsCoordName, fsCoordName, paramName, paramName);
524 builder->fsCodeAppendf("\t\tvec2 fragPosShifted = vec2(xShifted, %s.y);\n", fsCoordName);
525 builder->fsCodeAppendf("\t\tvec2 center = vec2(%s.y, 0.0);\n", paramName);
526 builder->fsCodeAppend("\t\tfloat dist = length(center - fragPosShifted);\n") ;
527 if (GrEffectEdgeTypeIsAA(dce.getEdgeType())) {
528 builder->fsCodeAppendf("\t\tfloat diff = dist - %s.x;\n", paramName);
529 builder->fsCodeAppend("\t\tdiff = 1 - diff;\n");
530 builder->fsCodeAppend("\t\tfloat alpha = clamp(diff, 0.0, 1.0);\n");
531 } else {
532 builder->fsCodeAppendf("\t\tfloat alpha = 1.0;\n");
533 builder->fsCodeAppendf("\t\talpha *= dist < %s.x + 0.5 ? 1.0 : 0.0;\n", paramName);
534 }
535 builder->fsCodeAppendf("\t\t%s = %s;\n", outputColor,
536 (GrGLSLExpr4(inputColor) * GrGLSLExpr1("alpha")).c_st r());
537 }
538
539 void GLDashingCircleEffect::setData(const GrGLUniformManager& uman, const GrDraw Effect& drawEffect) {
540 const DashingCircleEffect& dce = drawEffect.castEffect<DashingCircleEffect>( );
541 SkScalar radius = dce.getRadius();
542 SkScalar centerX = dce.getCenterX();
543 SkScalar intervalLength = dce.getIntervalLength();
544 if (radius != fPrevRadius || centerX != fPrevCenterX || intervalLength != fP revIntervalLength) {
545 uman.set3f(fParamUniform, radius - 0.5f, centerX, intervalLength);
546 fPrevRadius = radius;
547 fPrevCenterX = centerX;
548 fPrevIntervalLength = intervalLength;
549 }
550 }
551
552 GrGLEffect::EffectKey GLDashingCircleEffect::GenKey(const GrDrawEffect& drawEffe ct,
553 const GrGLCaps&) {
554 const DashingCircleEffect& dce = drawEffect.castEffect<DashingCircleEffect>( );
555 return dce.getEdgeType();
556 }
557
558 //////////////////////////////////////////////////////////////////////////////
559
560 GrEffectRef* DashingCircleEffect::Create(GrEffectEdgeType edgeType, const DashIn fo& info,
561 SkScalar radius) {
562 if (info.fCount != 2 || info.fIntervals[0] != 0) {
563 return NULL;
564 }
565
566 return CreateEffectRef(AutoEffectUnref(SkNEW_ARGS(DashingCircleEffect,
567 (edgeType, info, radius))) );
568 }
569
570 DashingCircleEffect::~DashingCircleEffect() {}
571
572 void DashingCircleEffect::getConstantColorComponents(GrColor* color, uint32_t* v alidFlags) const {
573 *validFlags = 0;
574 }
575
576 const GrBackendEffectFactory& DashingCircleEffect::getFactory() const {
577 return GrTBackendEffectFactory<DashingCircleEffect>::getInstance();
578 }
579
580 DashingCircleEffect::DashingCircleEffect(GrEffectEdgeType edgeType, const DashIn fo& info,
581 SkScalar radius)
582 : fEdgeType(edgeType) {
583 SkScalar onLen = info.fIntervals[0];
584 SkScalar offLen = info.fIntervals[1];
585 fIntervalLength = onLen + offLen;
586 fRadius = radius;
587 fCenterX = SkScalarHalf(offLen);
588
589 this->addVertexAttrib(kVec2f_GrSLType);
590 }
591
592 bool DashingCircleEffect::onIsEqual(const GrEffect& other) const {
593 const DashingCircleEffect& dce = CastEffect<DashingCircleEffect>(other);
594 return (fEdgeType == dce.fEdgeType &&
595 fIntervalLength == dce.fIntervalLength &&
596 fRadius == dce.fRadius &&
597 fCenterX == dce.fCenterX);
598 }
599
600 GR_DEFINE_EFFECT_TEST(DashingCircleEffect);
601
602 GrEffectRef* DashingCircleEffect::TestCreate(SkRandom* random,
603 GrContext*,
604 const GrDrawTargetCaps& caps,
605 GrTexture*[]) {
606 GrEffectRef* effect;
607 GrEffectEdgeType edgeType = static_cast<GrEffectEdgeType>(random->nextULessT han(
608 kGrEffectEdgeTypeCnt));
609 SkScalar strokeWidth = random->nextRangeScalar(0, 100.f);
610 DashInfo info;
611 info.fCount = 2;
612 SkAutoTArray<SkScalar> intervals(info.fCount);
613 info.fIntervals = intervals.get();
614 info.fIntervals[0] = 0;
615 info.fIntervals[1] = random->nextRangeScalar(0, 10.f);
616 info.fPhase = random->nextRangeScalar(0, info.fIntervals[1]);
617
618 effect = DashingCircleEffect::Create(edgeType, info, strokeWidth);
619 return effect;
620 }
621
622 //////////////////////////////////////////////////////////////////////////////
623
407 class GLDashingLineEffect; 624 class GLDashingLineEffect;
408 625
626 /*
627 * This effect will draw a dashed line. The width of the dash is given by the st rokeWidth and the
628 * length and spacing by the DashInfo. Both of the previous two parameters are i n device space.
629 * This effect also requires the setting of a vec2 vertex attribute for the the four corners of the
630 * bounding rect. This attribute is the "dash position" of each vertex. In other words it is the
631 * vertex coords (in device space) if we transform the line to be horizontal, wi th the start of
632 * line at the origin then shifted to the right by half the off interval. The li ne then goes in the
633 * positive x direction.
634 */
409 class DashingLineEffect : public GrVertexEffect { 635 class DashingLineEffect : public GrVertexEffect {
410 public: 636 public:
411 typedef SkPathEffect::DashInfo DashInfo; 637 typedef SkPathEffect::DashInfo DashInfo;
412 638
413 /**
414 * The effect calculates the coverage for the case of a horizontal line in d evice space.
415 * The matrix that is passed in should be able to convert a line in source s pace to a
416 * horizontal line in device space. Additionally, the coord transform matrix should translate
417 * the the start of line to origin, and the shift it along the positive x-ax is by the phase
418 * and half the off interval.
419 */
420 static GrEffectRef* Create(GrEffectEdgeType edgeType, const DashInfo& info, 639 static GrEffectRef* Create(GrEffectEdgeType edgeType, const DashInfo& info,
421 SkScalar strokeWidth); 640 SkScalar strokeWidth);
422 641
423 virtual ~DashingLineEffect(); 642 virtual ~DashingLineEffect();
424 643
425 static const char* Name() { return "DashingEffect"; } 644 static const char* Name() { return "DashingEffect"; }
426 645
427 GrEffectEdgeType getEdgeType() const { return fEdgeType; } 646 GrEffectEdgeType getEdgeType() const { return fEdgeType; }
428 647
429 const SkRect& getRect() const { return fRect; } 648 const SkRect& getRect() const { return fRect; }
(...skipping 10 matching lines...) Expand all
440 DashingLineEffect(GrEffectEdgeType edgeType, const DashInfo& info, SkScalar strokeWidth); 659 DashingLineEffect(GrEffectEdgeType edgeType, const DashInfo& info, SkScalar strokeWidth);
441 660
442 virtual bool onIsEqual(const GrEffect& other) const SK_OVERRIDE; 661 virtual bool onIsEqual(const GrEffect& other) const SK_OVERRIDE;
443 662
444 GrEffectEdgeType fEdgeType; 663 GrEffectEdgeType fEdgeType;
445 SkRect fRect; 664 SkRect fRect;
446 SkScalar fIntervalLength; 665 SkScalar fIntervalLength;
447 666
448 GR_DECLARE_EFFECT_TEST; 667 GR_DECLARE_EFFECT_TEST;
449 668
450 typedef GrEffect INHERITED; 669 typedef GrVertexEffect INHERITED;
451 }; 670 };
452 671
453 ////////////////////////////////////////////////////////////////////////////// 672 //////////////////////////////////////////////////////////////////////////////
454 673
455 class GLDashingLineEffect : public GrGLVertexEffect { 674 class GLDashingLineEffect : public GrGLVertexEffect {
456 public: 675 public:
457 GLDashingLineEffect(const GrBackendEffectFactory&, const GrDrawEffect&); 676 GLDashingLineEffect(const GrBackendEffectFactory&, const GrDrawEffect&);
458 677
459 virtual void emitCode(GrGLFullShaderBuilder* builder, 678 virtual void emitCode(GrGLFullShaderBuilder* builder,
460 const GrDrawEffect& drawEffect, 679 const GrDrawEffect& drawEffect,
(...skipping 13 matching lines...) Expand all
474 SkRect fPrevRect; 693 SkRect fPrevRect;
475 SkScalar fPrevIntervalLength; 694 SkScalar fPrevIntervalLength;
476 typedef GrGLVertexEffect INHERITED; 695 typedef GrGLVertexEffect INHERITED;
477 }; 696 };
478 697
479 GLDashingLineEffect::GLDashingLineEffect(const GrBackendEffectFactory& factory, 698 GLDashingLineEffect::GLDashingLineEffect(const GrBackendEffectFactory& factory,
480 const GrDrawEffect& drawEffect) 699 const GrDrawEffect& drawEffect)
481 : INHERITED (factory) { 700 : INHERITED (factory) {
482 fPrevRect.fLeft = SK_ScalarNaN; 701 fPrevRect.fLeft = SK_ScalarNaN;
483 fPrevIntervalLength = SK_ScalarMax; 702 fPrevIntervalLength = SK_ScalarMax;
484
485 } 703 }
486 704
487 void GLDashingLineEffect::emitCode(GrGLFullShaderBuilder* builder, 705 void GLDashingLineEffect::emitCode(GrGLFullShaderBuilder* builder,
488 const GrDrawEffect& drawEffect, 706 const GrDrawEffect& drawEffect,
489 EffectKey key, 707 EffectKey key,
490 const char* outputColor, 708 const char* outputColor,
491 const char* inputColor, 709 const char* inputColor,
492 const TransformedCoordsArray&, 710 const TransformedCoordsArray&,
493 const TextureSamplerArray& samplers) { 711 const TextureSamplerArray& samplers) {
494 const DashingLineEffect& de = drawEffect.castEffect<DashingLineEffect>(); 712 const DashingLineEffect& de = drawEffect.castEffect<DashingLineEffect>();
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
616 info.fIntervals[1] = random->nextRangeScalar(0, 10.f); 834 info.fIntervals[1] = random->nextRangeScalar(0, 10.f);
617 info.fPhase = random->nextRangeScalar(0, info.fIntervals[0] + info.fInterval s[1]); 835 info.fPhase = random->nextRangeScalar(0, info.fIntervals[0] + info.fInterval s[1]);
618 836
619 effect = DashingLineEffect::Create(edgeType, info, strokeWidth); 837 effect = DashingLineEffect::Create(edgeType, info, strokeWidth);
620 return effect; 838 return effect;
621 } 839 }
622 840
623 ////////////////////////////////////////////////////////////////////////////// 841 //////////////////////////////////////////////////////////////////////////////
624 842
625 GrEffectRef* GrDashingEffect::Create(GrEffectEdgeType edgeType, const SkPathEffe ct::DashInfo& info, 843 GrEffectRef* GrDashingEffect::Create(GrEffectEdgeType edgeType, const SkPathEffe ct::DashInfo& info,
626 SkScalar strokeWidth) { 844 SkScalar strokeWidth, GrDashingEffect::Dash Cap cap) {
627 return DashingLineEffect::Create(edgeType, info, strokeWidth); 845 switch (cap) {
846 case GrDashingEffect::kRound_DashCap:
847 return DashingCircleEffect::Create(edgeType, info, SkScalarHalf(stro keWidth));
848 case GrDashingEffect::kNonRound_DashCap:
849 return DashingLineEffect::Create(edgeType, info, strokeWidth);
850 default:
851 SkFAIL("Unexpected dashed cap.");
852 }
853 return NULL;
628 } 854 }
OLDNEW
« no previous file with comments | « src/gpu/effects/GrDashingEffect.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698