| 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 "gl/builders/GrGLProgramBuilder.h" | 8 #include "gl/builders/GrGLProgramBuilder.h" |
| 9 #include "GrDashingEffect.h" | 9 #include "GrDashingEffect.h" |
| 10 | 10 |
| 11 #include "../GrAARectRenderer.h" | 11 #include "../GrAARectRenderer.h" |
| 12 | 12 |
| 13 #include "effects/GrVertexEffect.h" | 13 #include "effects/GrGeometryProcessor.h" |
| 14 #include "gl/GrGLEffect.h" | 14 #include "gl/GrGLEffect.h" |
| 15 #include "gl/GrGLVertexEffect.h" | 15 #include "gl/GrGLGeometryProcessor.h" |
| 16 #include "gl/GrGLSL.h" | 16 #include "gl/GrGLSL.h" |
| 17 #include "GrContext.h" | 17 #include "GrContext.h" |
| 18 #include "GrCoordTransform.h" | 18 #include "GrCoordTransform.h" |
| 19 #include "GrDrawTarget.h" | 19 #include "GrDrawTarget.h" |
| 20 #include "GrDrawTargetCaps.h" | 20 #include "GrDrawTargetCaps.h" |
| 21 #include "GrEffect.h" | 21 #include "GrEffect.h" |
| 22 #include "GrGpu.h" | 22 #include "GrGpu.h" |
| 23 #include "GrStrokeInfo.h" | 23 #include "GrStrokeInfo.h" |
| 24 #include "GrTBackendEffectFactory.h" | 24 #include "GrTBackendEffectFactory.h" |
| 25 #include "SkGr.h" | 25 #include "SkGr.h" |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 return true; | 62 return true; |
| 63 } | 63 } |
| 64 | 64 |
| 65 namespace { | 65 namespace { |
| 66 | 66 |
| 67 struct DashLineVertex { | 67 struct DashLineVertex { |
| 68 SkPoint fPos; | 68 SkPoint fPos; |
| 69 SkPoint fDashPos; | 69 SkPoint fDashPos; |
| 70 }; | 70 }; |
| 71 | 71 |
| 72 extern const GrVertexAttrib gDashLineNoAAVertexAttribs[] = { |
| 73 { kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBind
ing } |
| 74 }; |
| 75 |
| 72 extern const GrVertexAttrib gDashLineVertexAttribs[] = { | 76 extern const GrVertexAttrib gDashLineVertexAttribs[] = { |
| 73 { kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBind
ing }, | 77 { kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBind
ing }, |
| 74 { kVec2f_GrVertexAttribType, sizeof(SkPoint), kEffect_GrVertexAttribBindin
g }, | 78 { kVec2f_GrVertexAttribType, sizeof(SkPoint), kEffect_GrVertexAttribBindin
g }, |
| 75 }; | 79 }; |
| 76 | 80 |
| 77 }; | 81 }; |
| 78 static void calc_dash_scaling(SkScalar* parallelScale, SkScalar* perpScale, | 82 static void calc_dash_scaling(SkScalar* parallelScale, SkScalar* perpScale, |
| 79 const SkMatrix& viewMatrix, const SkPoint pts[2]) { | 83 const SkMatrix& viewMatrix, const SkPoint pts[2]) { |
| 80 SkVector vecSrc = pts[1] - pts[0]; | 84 SkVector vecSrc = pts[1] - pts[0]; |
| 81 SkScalar magSrc = vecSrc.length(); | 85 SkScalar magSrc = vecSrc.length(); |
| (...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 339 SkPathEffect::DashInfo devInfo; | 343 SkPathEffect::DashInfo devInfo; |
| 340 devInfo.fPhase = devPhase; | 344 devInfo.fPhase = devPhase; |
| 341 devInfo.fCount = 2; | 345 devInfo.fCount = 2; |
| 342 devInfo.fIntervals = devIntervals; | 346 devInfo.fIntervals = devIntervals; |
| 343 GrEffectEdgeType edgeType= useAA ? kFillAA_GrEffectEdgeType : | 347 GrEffectEdgeType edgeType= useAA ? kFillAA_GrEffectEdgeType : |
| 344 kFillBW_GrEffectEdgeType; | 348 kFillBW_GrEffectEdgeType; |
| 345 bool isRoundCap = SkPaint::kRound_Cap == cap; | 349 bool isRoundCap = SkPaint::kRound_Cap == cap; |
| 346 GrDashingEffect::DashCap capType = isRoundCap ? GrDashingEffect::kRound_
DashCap : | 350 GrDashingEffect::DashCap capType = isRoundCap ? GrDashingEffect::kRound_
DashCap : |
| 347 GrDashingEffect::kNonRou
nd_DashCap; | 351 GrDashingEffect::kNonRou
nd_DashCap; |
| 348 drawState->setGeometryProcessor( | 352 drawState->setGeometryProcessor( |
| 349 GrDashingEffect::Create(edgeType, devInfo, strokeWidth, capType), 1)
->unref(); | 353 GrDashingEffect::Create(edgeType, devInfo, strokeWidth, capType))->u
nref(); |
| 354 |
| 355 // Set up the vertex data for the line and start/end dashes |
| 356 drawState->setVertexAttribs<gDashLineVertexAttribs>(SK_ARRAY_COUNT(gDash
LineVertexAttribs), |
| 357 sizeof(DashLineVerte
x)); |
| 358 } else { |
| 359 // Set up the vertex data for the line and start/end dashes |
| 360 drawState->setVertexAttribs<gDashLineNoAAVertexAttribs>( |
| 361 SK_ARRAY_COUNT(gDashLineNoAAVertexAttribs), sizeof(DashLineVerte
x)); |
| 350 } | 362 } |
| 351 | 363 |
| 352 // Set up the vertex data for the line and start/end dashes | |
| 353 drawState->setVertexAttribs<gDashLineVertexAttribs>(SK_ARRAY_COUNT(gDashLine
VertexAttribs), | |
| 354 sizeof(DashLineVertex)); | |
| 355 | |
| 356 int totalRectCnt = 0; | 364 int totalRectCnt = 0; |
| 357 | 365 |
| 358 totalRectCnt += !lineDone ? 1 : 0; | 366 totalRectCnt += !lineDone ? 1 : 0; |
| 359 totalRectCnt += hasStartRect ? 1 : 0; | 367 totalRectCnt += hasStartRect ? 1 : 0; |
| 360 totalRectCnt += hasEndRect ? 1 : 0; | 368 totalRectCnt += hasEndRect ? 1 : 0; |
| 361 | 369 |
| 362 GrDrawTarget::AutoReleaseGeometry geo(target, totalRectCnt * 4, 0); | 370 GrDrawTarget::AutoReleaseGeometry geo(target, totalRectCnt * 4, 0); |
| 363 if (!geo.succeeded()) { | 371 if (!geo.succeeded()) { |
| 364 GrPrintf("Failed to get space for vertices!\n"); | 372 GrPrintf("Failed to get space for vertices!\n"); |
| 365 return false; | 373 return false; |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 407 } | 415 } |
| 408 | 416 |
| 409 target->setIndexSourceToBuffer(gpu->getContext()->getQuadIndexBuffer()); | 417 target->setIndexSourceToBuffer(gpu->getContext()->getQuadIndexBuffer()); |
| 410 target->drawIndexedInstances(kTriangles_GrPrimitiveType, totalRectCnt, 4, 6)
; | 418 target->drawIndexedInstances(kTriangles_GrPrimitiveType, totalRectCnt, 4, 6)
; |
| 411 target->resetIndexSource(); | 419 target->resetIndexSource(); |
| 412 return true; | 420 return true; |
| 413 } | 421 } |
| 414 | 422 |
| 415 ////////////////////////////////////////////////////////////////////////////// | 423 ////////////////////////////////////////////////////////////////////////////// |
| 416 | 424 |
| 425 const GrShaderVar kAttrCoord("aCoord", |
| 426 kVec2f_GrSLType, |
| 427 GrShaderVar::kAttribute_TypeModifier); |
| 428 |
| 417 class GLDashingCircleEffect; | 429 class GLDashingCircleEffect; |
| 418 /* | 430 /* |
| 419 * This effect will draw a dotted line (defined as a dashed lined with round cap
s and no on | 431 * This effect will draw a dotted line (defined as a dashed lined with round cap
s and no on |
| 420 * interval). The radius of the dots is given by the strokeWidth and the spacing
by the DashInfo. | 432 * interval). The radius of the dots is given by the strokeWidth and the spacing
by the DashInfo. |
| 421 * Both of the previous two parameters are in device space. This effect also req
uires the setting of | 433 * Both of the previous two parameters are in device space. This effect also req
uires the setting of |
| 422 * a vec2 vertex attribute for the the four corners of the bounding rect. This a
ttribute is the | 434 * a vec2 vertex attribute for the the four corners of the bounding rect. This a
ttribute is the |
| 423 * "dash position" of each vertex. In other words it is the vertex coords (in de
vice space) if we | 435 * "dash position" of each vertex. In other words it is the vertex coords (in de
vice space) if we |
| 424 * transform the line to be horizontal, with the start of line at the origin the
n shifted to the | 436 * transform the line to be horizontal, with the start of line at the origin the
n shifted to the |
| 425 * right by half the off interval. The line then goes in the positive x directio
n. | 437 * right by half the off interval. The line then goes in the positive x directio
n. |
| 426 */ | 438 */ |
| 427 class DashingCircleEffect : public GrVertexEffect { | 439 class DashingCircleEffect : public GrGeometryProcessor { |
| 428 public: | 440 public: |
| 429 typedef SkPathEffect::DashInfo DashInfo; | 441 typedef SkPathEffect::DashInfo DashInfo; |
| 430 | 442 |
| 431 static GrEffect* Create(GrEffectEdgeType edgeType, const DashInfo& info, SkS
calar radius); | 443 static GrEffect* Create(GrEffectEdgeType edgeType, const DashInfo& info, SkS
calar radius); |
| 432 | 444 |
| 433 virtual ~DashingCircleEffect(); | 445 virtual ~DashingCircleEffect(); |
| 434 | 446 |
| 435 static const char* Name() { return "DashingCircleEffect"; } | 447 static const char* Name() { return "DashingCircleEffect"; } |
| 436 | 448 |
| 437 GrEffectEdgeType getEdgeType() const { return fEdgeType; } | 449 GrEffectEdgeType getEdgeType() const { return fEdgeType; } |
| (...skipping 15 matching lines...) Expand all Loading... |
| 453 | 465 |
| 454 virtual bool onIsEqual(const GrEffect& other) const SK_OVERRIDE; | 466 virtual bool onIsEqual(const GrEffect& other) const SK_OVERRIDE; |
| 455 | 467 |
| 456 GrEffectEdgeType fEdgeType; | 468 GrEffectEdgeType fEdgeType; |
| 457 SkScalar fIntervalLength; | 469 SkScalar fIntervalLength; |
| 458 SkScalar fRadius; | 470 SkScalar fRadius; |
| 459 SkScalar fCenterX; | 471 SkScalar fCenterX; |
| 460 | 472 |
| 461 GR_DECLARE_EFFECT_TEST; | 473 GR_DECLARE_EFFECT_TEST; |
| 462 | 474 |
| 463 typedef GrVertexEffect INHERITED; | 475 typedef GrGeometryProcessor INHERITED; |
| 464 }; | 476 }; |
| 465 | 477 |
| 466 ////////////////////////////////////////////////////////////////////////////// | 478 ////////////////////////////////////////////////////////////////////////////// |
| 467 | 479 |
| 468 class GLDashingCircleEffect : public GrGLVertexEffect { | 480 class GLDashingCircleEffect : public GrGLGeometryProcessor { |
| 469 public: | 481 public: |
| 470 GLDashingCircleEffect(const GrBackendEffectFactory&, const GrDrawEffect&); | 482 GLDashingCircleEffect(const GrBackendEffectFactory&, const GrDrawEffect&); |
| 471 | 483 |
| 472 virtual void emitCode(GrGLFullProgramBuilder* builder, | 484 virtual void emitCode(GrGLFullProgramBuilder* builder, |
| 473 const GrDrawEffect& drawEffect, | 485 const GrDrawEffect& drawEffect, |
| 474 const GrEffectKey& key, | 486 const GrEffectKey& key, |
| 475 const char* outputColor, | 487 const char* outputColor, |
| 476 const char* inputColor, | 488 const char* inputColor, |
| 477 const TransformedCoordsArray&, | 489 const TransformedCoordsArray&, |
| 478 const TextureSamplerArray&) SK_OVERRIDE; | 490 const TextureSamplerArray&) SK_OVERRIDE; |
| 479 | 491 |
| 480 static inline void GenKey(const GrDrawEffect&, const GrGLCaps&, GrEffectKeyB
uilder*); | 492 static inline void GenKey(const GrDrawEffect&, const GrGLCaps&, GrEffectKeyB
uilder*); |
| 481 | 493 |
| 482 virtual void setData(const GrGLProgramDataManager&, const GrDrawEffect&) SK_
OVERRIDE; | 494 virtual void setData(const GrGLProgramDataManager&, const GrDrawEffect&) SK_
OVERRIDE; |
| 483 | 495 |
| 484 private: | 496 private: |
| 485 GrGLProgramDataManager::UniformHandle fParamUniform; | 497 GrGLProgramDataManager::UniformHandle fParamUniform; |
| 486 SkScalar fPrevRadius; | 498 SkScalar fPrevRadius; |
| 487 SkScalar fPrevCenterX; | 499 SkScalar fPrevCenterX; |
| 488 SkScalar fPrevIntervalLength; | 500 SkScalar fPrevIntervalLength; |
| 489 typedef GrGLVertexEffect INHERITED; | 501 typedef GrGLGeometryProcessor INHERITED; |
| 490 }; | 502 }; |
| 491 | 503 |
| 492 GLDashingCircleEffect::GLDashingCircleEffect(const GrBackendEffectFactory& facto
ry, | 504 GLDashingCircleEffect::GLDashingCircleEffect(const GrBackendEffectFactory& facto
ry, |
| 493 const GrDrawEffect& drawEffect) | 505 const GrDrawEffect& drawEffect) |
| 494 : INHERITED (factory) { | 506 : INHERITED (factory) { |
| 495 fPrevRadius = SK_ScalarMin; | 507 fPrevRadius = SK_ScalarMin; |
| 496 fPrevCenterX = SK_ScalarMin; | 508 fPrevCenterX = SK_ScalarMin; |
| 497 fPrevIntervalLength = SK_ScalarMax; | 509 fPrevIntervalLength = SK_ScalarMax; |
| 498 } | 510 } |
| 499 | 511 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 510 // the total interval length of the dash. | 522 // the total interval length of the dash. |
| 511 fParamUniform = builder->addUniform(GrGLProgramBuilder::kFragment_Visibility
, | 523 fParamUniform = builder->addUniform(GrGLProgramBuilder::kFragment_Visibility
, |
| 512 kVec3f_GrSLType, | 524 kVec3f_GrSLType, |
| 513 "params", | 525 "params", |
| 514 ¶mName); | 526 ¶mName); |
| 515 | 527 |
| 516 const char *vsCoordName, *fsCoordName; | 528 const char *vsCoordName, *fsCoordName; |
| 517 builder->addVarying(kVec2f_GrSLType, "Coord", &vsCoordName, &fsCoordName); | 529 builder->addVarying(kVec2f_GrSLType, "Coord", &vsCoordName, &fsCoordName); |
| 518 | 530 |
| 519 GrGLVertexShaderBuilder* vsBuilder = builder->getVertexShaderBuilder(); | 531 GrGLVertexShaderBuilder* vsBuilder = builder->getVertexShaderBuilder(); |
| 520 const SkString* attr0Name = | 532 vsBuilder->codeAppendf("\t%s = %s;\n", vsCoordName, kAttrCoord.c_str()); |
| 521 vsBuilder->getEffectAttributeName(drawEffect.getVertexAttribIndices()[0]
); | |
| 522 vsBuilder->codeAppendf("\t%s = %s;\n", vsCoordName, attr0Name->c_str()); | |
| 523 | 533 |
| 524 // transforms all points so that we can compare them to our test circle | 534 // transforms all points so that we can compare them to our test circle |
| 525 GrGLFragmentShaderBuilder* fsBuilder = builder->getFragmentShaderBuilder(); | 535 GrGLFragmentShaderBuilder* fsBuilder = builder->getFragmentShaderBuilder(); |
| 526 fsBuilder->codeAppendf("\t\tfloat xShifted = %s.x - floor(%s.x / %s.z) * %s.
z;\n", | 536 fsBuilder->codeAppendf("\t\tfloat xShifted = %s.x - floor(%s.x / %s.z) * %s.
z;\n", |
| 527 fsCoordName, fsCoordName, paramName, paramName); | 537 fsCoordName, fsCoordName, paramName, paramName); |
| 528 fsBuilder->codeAppendf("\t\tvec2 fragPosShifted = vec2(xShifted, %s.y);\n",
fsCoordName); | 538 fsBuilder->codeAppendf("\t\tvec2 fragPosShifted = vec2(xShifted, %s.y);\n",
fsCoordName); |
| 529 fsBuilder->codeAppendf("\t\tvec2 center = vec2(%s.y, 0.0);\n", paramName); | 539 fsBuilder->codeAppendf("\t\tvec2 center = vec2(%s.y, 0.0);\n", paramName); |
| 530 fsBuilder->codeAppend("\t\tfloat dist = length(center - fragPosShifted);\n")
; | 540 fsBuilder->codeAppend("\t\tfloat dist = length(center - fragPosShifted);\n")
; |
| 531 if (GrEffectEdgeTypeIsAA(dce.getEdgeType())) { | 541 if (GrEffectEdgeTypeIsAA(dce.getEdgeType())) { |
| 532 fsBuilder->codeAppendf("\t\tfloat diff = dist - %s.x;\n", paramName); | 542 fsBuilder->codeAppendf("\t\tfloat diff = dist - %s.x;\n", paramName); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 582 | 592 |
| 583 DashingCircleEffect::DashingCircleEffect(GrEffectEdgeType edgeType, const DashIn
fo& info, | 593 DashingCircleEffect::DashingCircleEffect(GrEffectEdgeType edgeType, const DashIn
fo& info, |
| 584 SkScalar radius) | 594 SkScalar radius) |
| 585 : fEdgeType(edgeType) { | 595 : fEdgeType(edgeType) { |
| 586 SkScalar onLen = info.fIntervals[0]; | 596 SkScalar onLen = info.fIntervals[0]; |
| 587 SkScalar offLen = info.fIntervals[1]; | 597 SkScalar offLen = info.fIntervals[1]; |
| 588 fIntervalLength = onLen + offLen; | 598 fIntervalLength = onLen + offLen; |
| 589 fRadius = radius; | 599 fRadius = radius; |
| 590 fCenterX = SkScalarHalf(offLen); | 600 fCenterX = SkScalarHalf(offLen); |
| 591 | 601 |
| 592 this->addVertexAttrib(kVec2f_GrSLType); | 602 this->addVertexAttrib(kAttrCoord); |
| 593 } | 603 } |
| 594 | 604 |
| 595 bool DashingCircleEffect::onIsEqual(const GrEffect& other) const { | 605 bool DashingCircleEffect::onIsEqual(const GrEffect& other) const { |
| 596 const DashingCircleEffect& dce = CastEffect<DashingCircleEffect>(other); | 606 const DashingCircleEffect& dce = CastEffect<DashingCircleEffect>(other); |
| 597 return (fEdgeType == dce.fEdgeType && | 607 return (fEdgeType == dce.fEdgeType && |
| 598 fIntervalLength == dce.fIntervalLength && | 608 fIntervalLength == dce.fIntervalLength && |
| 599 fRadius == dce.fRadius && | 609 fRadius == dce.fRadius && |
| 600 fCenterX == dce.fCenterX); | 610 fCenterX == dce.fCenterX); |
| 601 } | 611 } |
| 602 | 612 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 628 | 638 |
| 629 /* | 639 /* |
| 630 * This effect will draw a dashed line. The width of the dash is given by the st
rokeWidth and the | 640 * This effect will draw a dashed line. The width of the dash is given by the st
rokeWidth and the |
| 631 * length and spacing by the DashInfo. Both of the previous two parameters are i
n device space. | 641 * length and spacing by the DashInfo. Both of the previous two parameters are i
n device space. |
| 632 * This effect also requires the setting of a vec2 vertex attribute for the the
four corners of the | 642 * This effect also requires the setting of a vec2 vertex attribute for the the
four corners of the |
| 633 * bounding rect. This attribute is the "dash position" of each vertex. In other
words it is the | 643 * bounding rect. This attribute is the "dash position" of each vertex. In other
words it is the |
| 634 * vertex coords (in device space) if we transform the line to be horizontal, wi
th the start of | 644 * vertex coords (in device space) if we transform the line to be horizontal, wi
th the start of |
| 635 * line at the origin then shifted to the right by half the off interval. The li
ne then goes in the | 645 * line at the origin then shifted to the right by half the off interval. The li
ne then goes in the |
| 636 * positive x direction. | 646 * positive x direction. |
| 637 */ | 647 */ |
| 638 class DashingLineEffect : public GrVertexEffect { | 648 class DashingLineEffect : public GrGeometryProcessor { |
| 639 public: | 649 public: |
| 640 typedef SkPathEffect::DashInfo DashInfo; | 650 typedef SkPathEffect::DashInfo DashInfo; |
| 641 | 651 |
| 642 static GrEffect* Create(GrEffectEdgeType edgeType, const DashInfo& info, SkS
calar strokeWidth); | 652 static GrEffect* Create(GrEffectEdgeType edgeType, const DashInfo& info, SkS
calar strokeWidth); |
| 643 | 653 |
| 644 virtual ~DashingLineEffect(); | 654 virtual ~DashingLineEffect(); |
| 645 | 655 |
| 646 static const char* Name() { return "DashingEffect"; } | 656 static const char* Name() { return "DashingEffect"; } |
| 647 | 657 |
| 648 GrEffectEdgeType getEdgeType() const { return fEdgeType; } | 658 GrEffectEdgeType getEdgeType() const { return fEdgeType; } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 661 DashingLineEffect(GrEffectEdgeType edgeType, const DashInfo& info, SkScalar
strokeWidth); | 671 DashingLineEffect(GrEffectEdgeType edgeType, const DashInfo& info, SkScalar
strokeWidth); |
| 662 | 672 |
| 663 virtual bool onIsEqual(const GrEffect& other) const SK_OVERRIDE; | 673 virtual bool onIsEqual(const GrEffect& other) const SK_OVERRIDE; |
| 664 | 674 |
| 665 GrEffectEdgeType fEdgeType; | 675 GrEffectEdgeType fEdgeType; |
| 666 SkRect fRect; | 676 SkRect fRect; |
| 667 SkScalar fIntervalLength; | 677 SkScalar fIntervalLength; |
| 668 | 678 |
| 669 GR_DECLARE_EFFECT_TEST; | 679 GR_DECLARE_EFFECT_TEST; |
| 670 | 680 |
| 671 typedef GrVertexEffect INHERITED; | 681 typedef GrGeometryProcessor INHERITED; |
| 672 }; | 682 }; |
| 673 | 683 |
| 674 ////////////////////////////////////////////////////////////////////////////// | 684 ////////////////////////////////////////////////////////////////////////////// |
| 675 | 685 |
| 676 class GLDashingLineEffect : public GrGLVertexEffect { | 686 class GLDashingLineEffect : public GrGLGeometryProcessor { |
| 677 public: | 687 public: |
| 678 GLDashingLineEffect(const GrBackendEffectFactory&, const GrDrawEffect&); | 688 GLDashingLineEffect(const GrBackendEffectFactory&, const GrDrawEffect&); |
| 679 | 689 |
| 680 virtual void emitCode(GrGLFullProgramBuilder* builder, | 690 virtual void emitCode(GrGLFullProgramBuilder* builder, |
| 681 const GrDrawEffect& drawEffect, | 691 const GrDrawEffect& drawEffect, |
| 682 const GrEffectKey& key, | 692 const GrEffectKey& key, |
| 683 const char* outputColor, | 693 const char* outputColor, |
| 684 const char* inputColor, | 694 const char* inputColor, |
| 685 const TransformedCoordsArray&, | 695 const TransformedCoordsArray&, |
| 686 const TextureSamplerArray&) SK_OVERRIDE; | 696 const TextureSamplerArray&) SK_OVERRIDE; |
| 687 | 697 |
| 688 static inline void GenKey(const GrDrawEffect&, const GrGLCaps&, GrEffectKeyB
uilder*); | 698 static inline void GenKey(const GrDrawEffect&, const GrGLCaps&, GrEffectKeyB
uilder*); |
| 689 | 699 |
| 690 virtual void setData(const GrGLProgramDataManager&, const GrDrawEffect&) SK_
OVERRIDE; | 700 virtual void setData(const GrGLProgramDataManager&, const GrDrawEffect&) SK_
OVERRIDE; |
| 691 | 701 |
| 692 private: | 702 private: |
| 693 GrGLProgramDataManager::UniformHandle fRectUniform; | 703 GrGLProgramDataManager::UniformHandle fRectUniform; |
| 694 GrGLProgramDataManager::UniformHandle fIntervalUniform; | 704 GrGLProgramDataManager::UniformHandle fIntervalUniform; |
| 695 SkRect fPrevRect; | 705 SkRect fPrevRect; |
| 696 SkScalar fPrevIntervalLength; | 706 SkScalar fPrevIntervalLength; |
| 697 typedef GrGLVertexEffect INHERITED; | 707 typedef GrGLGeometryProcessor INHERITED; |
| 698 }; | 708 }; |
| 699 | 709 |
| 700 GLDashingLineEffect::GLDashingLineEffect(const GrBackendEffectFactory& factory, | 710 GLDashingLineEffect::GLDashingLineEffect(const GrBackendEffectFactory& factory, |
| 701 const GrDrawEffect& drawEffect) | 711 const GrDrawEffect& drawEffect) |
| 702 : INHERITED (factory) { | 712 : INHERITED (factory) { |
| 703 fPrevRect.fLeft = SK_ScalarNaN; | 713 fPrevRect.fLeft = SK_ScalarNaN; |
| 704 fPrevIntervalLength = SK_ScalarMax; | 714 fPrevIntervalLength = SK_ScalarMax; |
| 705 } | 715 } |
| 706 | 716 |
| 707 void GLDashingLineEffect::emitCode(GrGLFullProgramBuilder* builder, | 717 void GLDashingLineEffect::emitCode(GrGLFullProgramBuilder* builder, |
| (...skipping 14 matching lines...) Expand all Loading... |
| 722 const char *intervalName; | 732 const char *intervalName; |
| 723 // The interval uniform's refers to the total length of the interval (on + o
ff) | 733 // The interval uniform's refers to the total length of the interval (on + o
ff) |
| 724 fIntervalUniform = builder->addUniform(GrGLProgramBuilder::kFragment_Visibil
ity, | 734 fIntervalUniform = builder->addUniform(GrGLProgramBuilder::kFragment_Visibil
ity, |
| 725 kFloat_GrSLType, | 735 kFloat_GrSLType, |
| 726 "interval", | 736 "interval", |
| 727 &intervalName); | 737 &intervalName); |
| 728 | 738 |
| 729 const char *vsCoordName, *fsCoordName; | 739 const char *vsCoordName, *fsCoordName; |
| 730 builder->addVarying(kVec2f_GrSLType, "Coord", &vsCoordName, &fsCoordName); | 740 builder->addVarying(kVec2f_GrSLType, "Coord", &vsCoordName, &fsCoordName); |
| 731 GrGLVertexShaderBuilder* vsBuilder = builder->getVertexShaderBuilder(); | 741 GrGLVertexShaderBuilder* vsBuilder = builder->getVertexShaderBuilder(); |
| 732 const SkString* attr0Name = | 742 vsBuilder->codeAppendf("\t%s = %s;\n", vsCoordName, kAttrCoord.c_str()); |
| 733 vsBuilder->getEffectAttributeName(drawEffect.getVertexAttribIndices()[0]
); | |
| 734 vsBuilder->codeAppendf("\t%s = %s;\n", vsCoordName, attr0Name->c_str()); | |
| 735 | 743 |
| 736 // transforms all points so that we can compare them to our test rect | 744 // transforms all points so that we can compare them to our test rect |
| 737 GrGLFragmentShaderBuilder* fsBuilder = builder->getFragmentShaderBuilder(); | 745 GrGLFragmentShaderBuilder* fsBuilder = builder->getFragmentShaderBuilder(); |
| 738 fsBuilder->codeAppendf("\t\tfloat xShifted = %s.x - floor(%s.x / %s) * %s;\n
", | 746 fsBuilder->codeAppendf("\t\tfloat xShifted = %s.x - floor(%s.x / %s) * %s;\n
", |
| 739 fsCoordName, fsCoordName, intervalName, intervalName)
; | 747 fsCoordName, fsCoordName, intervalName, intervalName)
; |
| 740 fsBuilder->codeAppendf("\t\tvec2 fragPosShifted = vec2(xShifted, %s.y);\n",
fsCoordName); | 748 fsBuilder->codeAppendf("\t\tvec2 fragPosShifted = vec2(xShifted, %s.y);\n",
fsCoordName); |
| 741 if (GrEffectEdgeTypeIsAA(de.getEdgeType())) { | 749 if (GrEffectEdgeTypeIsAA(de.getEdgeType())) { |
| 742 // The amount of coverage removed in x and y by the edges is computed as
a pair of negative | 750 // The amount of coverage removed in x and y by the edges is computed as
a pair of negative |
| 743 // numbers, xSub and ySub. | 751 // numbers, xSub and ySub. |
| 744 fsBuilder->codeAppend("\t\tfloat xSub, ySub;\n"); | 752 fsBuilder->codeAppend("\t\tfloat xSub, ySub;\n"); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 802 DashingLineEffect::DashingLineEffect(GrEffectEdgeType edgeType, const DashInfo&
info, | 810 DashingLineEffect::DashingLineEffect(GrEffectEdgeType edgeType, const DashInfo&
info, |
| 803 SkScalar strokeWidth) | 811 SkScalar strokeWidth) |
| 804 : fEdgeType(edgeType) { | 812 : fEdgeType(edgeType) { |
| 805 SkScalar onLen = info.fIntervals[0]; | 813 SkScalar onLen = info.fIntervals[0]; |
| 806 SkScalar offLen = info.fIntervals[1]; | 814 SkScalar offLen = info.fIntervals[1]; |
| 807 SkScalar halfOffLen = SkScalarHalf(offLen); | 815 SkScalar halfOffLen = SkScalarHalf(offLen); |
| 808 SkScalar halfStroke = SkScalarHalf(strokeWidth); | 816 SkScalar halfStroke = SkScalarHalf(strokeWidth); |
| 809 fIntervalLength = onLen + offLen; | 817 fIntervalLength = onLen + offLen; |
| 810 fRect.set(halfOffLen, -halfStroke, halfOffLen + onLen, halfStroke); | 818 fRect.set(halfOffLen, -halfStroke, halfOffLen + onLen, halfStroke); |
| 811 | 819 |
| 812 this->addVertexAttrib(kVec2f_GrSLType); | 820 this->addVertexAttrib(kAttrCoord); |
| 813 } | 821 } |
| 814 | 822 |
| 815 bool DashingLineEffect::onIsEqual(const GrEffect& other) const { | 823 bool DashingLineEffect::onIsEqual(const GrEffect& other) const { |
| 816 const DashingLineEffect& de = CastEffect<DashingLineEffect>(other); | 824 const DashingLineEffect& de = CastEffect<DashingLineEffect>(other); |
| 817 return (fEdgeType == de.fEdgeType && | 825 return (fEdgeType == de.fEdgeType && |
| 818 fRect == de.fRect && | 826 fRect == de.fRect && |
| 819 fIntervalLength == de.fIntervalLength); | 827 fIntervalLength == de.fIntervalLength); |
| 820 } | 828 } |
| 821 | 829 |
| 822 GR_DEFINE_EFFECT_TEST(DashingLineEffect); | 830 GR_DEFINE_EFFECT_TEST(DashingLineEffect); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 848 switch (cap) { | 856 switch (cap) { |
| 849 case GrDashingEffect::kRound_DashCap: | 857 case GrDashingEffect::kRound_DashCap: |
| 850 return DashingCircleEffect::Create(edgeType, info, SkScalarHalf(stro
keWidth)); | 858 return DashingCircleEffect::Create(edgeType, info, SkScalarHalf(stro
keWidth)); |
| 851 case GrDashingEffect::kNonRound_DashCap: | 859 case GrDashingEffect::kNonRound_DashCap: |
| 852 return DashingLineEffect::Create(edgeType, info, strokeWidth); | 860 return DashingLineEffect::Create(edgeType, info, strokeWidth); |
| 853 default: | 861 default: |
| 854 SkFAIL("Unexpected dashed cap."); | 862 SkFAIL("Unexpected dashed cap."); |
| 855 } | 863 } |
| 856 return NULL; | 864 return NULL; |
| 857 } | 865 } |
| OLD | NEW |