| 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" |
| 11 | 11 |
| 12 #include "effects/GrGeometryProcessor.h" | 12 #include "GrGeometryProcessor.h" |
| 13 #include "gl/builders/GrGLFullProgramBuilder.h" | 13 #include "gl/builders/GrGLFullProgramBuilder.h" |
| 14 #include "gl/GrGLEffect.h" | 14 #include "gl/GrGLProcessor.h" |
| 15 #include "gl/GrGLGeometryProcessor.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 "GrProcessor.h" |
| 22 #include "GrGpu.h" | 22 #include "GrGpu.h" |
| 23 #include "GrStrokeInfo.h" | 23 #include "GrStrokeInfo.h" |
| 24 #include "GrTBackendEffectFactory.h" | 24 #include "GrTBackendProcessorFactory.h" |
| 25 #include "SkGr.h" | 25 #include "SkGr.h" |
| 26 | 26 |
| 27 /////////////////////////////////////////////////////////////////////////////// | 27 /////////////////////////////////////////////////////////////////////////////// |
| 28 | 28 |
| 29 // Returns whether or not the gpu can fast path the dash line effect. | 29 // Returns whether or not the gpu can fast path the dash line effect. |
| 30 static bool can_fast_path_dash(const SkPoint pts[2], const GrStrokeInfo& strokeI
nfo, | 30 static bool can_fast_path_dash(const SkPoint pts[2], const GrStrokeInfo& strokeI
nfo, |
| 31 const GrDrawTarget& target, const SkMatrix& viewM
atrix) { | 31 const GrDrawTarget& target, const SkMatrix& viewM
atrix) { |
| 32 if (target.getDrawState().getRenderTarget()->isMultisampled()) { | 32 if (target.getDrawState().getRenderTarget()->isMultisampled()) { |
| 33 return false; | 33 return false; |
| 34 } | 34 } |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 SkPoint fPos; | 68 SkPoint fPos; |
| 69 SkPoint fDashPos; | 69 SkPoint fDashPos; |
| 70 }; | 70 }; |
| 71 | 71 |
| 72 extern const GrVertexAttrib gDashLineNoAAVertexAttribs[] = { | 72 extern const GrVertexAttrib gDashLineNoAAVertexAttribs[] = { |
| 73 { kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBind
ing } | 73 { kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBind
ing } |
| 74 }; | 74 }; |
| 75 | 75 |
| 76 extern const GrVertexAttrib gDashLineVertexAttribs[] = { | 76 extern const GrVertexAttrib gDashLineVertexAttribs[] = { |
| 77 { kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBind
ing }, | 77 { kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBind
ing }, |
| 78 { kVec2f_GrVertexAttribType, sizeof(SkPoint), kEffect_GrVertexAttribBindin
g }, | 78 { kVec2f_GrVertexAttribType, sizeof(SkPoint), kGeometryProcessor_GrVertexA
ttribBinding }, |
| 79 }; | 79 }; |
| 80 | 80 |
| 81 }; | 81 }; |
| 82 static void calc_dash_scaling(SkScalar* parallelScale, SkScalar* perpScale, | 82 static void calc_dash_scaling(SkScalar* parallelScale, SkScalar* perpScale, |
| 83 const SkMatrix& viewMatrix, const SkPoint pts[2]) { | 83 const SkMatrix& viewMatrix, const SkPoint pts[2]) { |
| 84 SkVector vecSrc = pts[1] - pts[0]; | 84 SkVector vecSrc = pts[1] - pts[0]; |
| 85 SkScalar magSrc = vecSrc.length(); | 85 SkScalar magSrc = vecSrc.length(); |
| 86 SkScalar invSrc = magSrc ? SkScalarInvert(magSrc) : 0; | 86 SkScalar invSrc = magSrc ? SkScalarInvert(magSrc) : 0; |
| 87 vecSrc.scale(invSrc); | 87 vecSrc.scale(invSrc); |
| 88 | 88 |
| (...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 337 if (hasCap) { | 337 if (hasCap) { |
| 338 lineLength += 2.f * halfDevStroke; | 338 lineLength += 2.f * halfDevStroke; |
| 339 } | 339 } |
| 340 devIntervals[0] = lineLength; | 340 devIntervals[0] = lineLength; |
| 341 } | 341 } |
| 342 if (devIntervals[1] > 0.f || useAA) { | 342 if (devIntervals[1] > 0.f || useAA) { |
| 343 SkPathEffect::DashInfo devInfo; | 343 SkPathEffect::DashInfo devInfo; |
| 344 devInfo.fPhase = devPhase; | 344 devInfo.fPhase = devPhase; |
| 345 devInfo.fCount = 2; | 345 devInfo.fCount = 2; |
| 346 devInfo.fIntervals = devIntervals; | 346 devInfo.fIntervals = devIntervals; |
| 347 GrEffectEdgeType edgeType= useAA ? kFillAA_GrEffectEdgeType : | 347 GrPrimitiveEdgeType edgeType= useAA ? kFillAA_GrProcessorEdgeType : |
| 348 kFillBW_GrEffectEdgeType; | 348 kFillBW_GrProcessorEdgeType; |
| 349 bool isRoundCap = SkPaint::kRound_Cap == cap; | 349 bool isRoundCap = SkPaint::kRound_Cap == cap; |
| 350 GrDashingEffect::DashCap capType = isRoundCap ? GrDashingEffect::kRound_
DashCap : | 350 GrDashingEffect::DashCap capType = isRoundCap ? GrDashingEffect::kRound_
DashCap : |
| 351 GrDashingEffect::kNonRou
nd_DashCap; | 351 GrDashingEffect::kNonRou
nd_DashCap; |
| 352 drawState->setGeometryProcessor( | 352 drawState->setGeometryProcessor( |
| 353 GrDashingEffect::Create(edgeType, devInfo, strokeWidth, capType))->u
nref(); | 353 GrDashingEffect::Create(edgeType, devInfo, strokeWidth, capType)
)->unref(); |
| 354 | 354 |
| 355 // Set up the vertex data for the line and start/end dashes | 355 // Set up the vertex data for the line and start/end dashes |
| 356 drawState->setVertexAttribs<gDashLineVertexAttribs>(SK_ARRAY_COUNT(gDash
LineVertexAttribs), | 356 drawState->setVertexAttribs<gDashLineVertexAttribs>(SK_ARRAY_COUNT(gDash
LineVertexAttribs), |
| 357 sizeof(DashLineVerte
x)); | 357 sizeof(DashLineVerte
x)); |
| 358 } else { | 358 } else { |
| 359 // Set up the vertex data for the line and start/end dashes | 359 // Set up the vertex data for the line and start/end dashes |
| 360 drawState->setVertexAttribs<gDashLineNoAAVertexAttribs>( | 360 drawState->setVertexAttribs<gDashLineNoAAVertexAttribs>( |
| 361 SK_ARRAY_COUNT(gDashLineNoAAVertexAttribs), sizeof(DashLineVerte
x)); | 361 SK_ARRAY_COUNT(gDashLineNoAAVertexAttribs), sizeof(DashLineVerte
x)); |
| 362 } | 362 } |
| 363 | 363 |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 429 * Both of the previous two parameters are in device space. This effect also req
uires the setting of | 429 * Both of the previous two parameters are in device space. This effect also req
uires the setting of |
| 430 * a vec2 vertex attribute for the the four corners of the bounding rect. This a
ttribute is the | 430 * a vec2 vertex attribute for the the four corners of the bounding rect. This a
ttribute is the |
| 431 * "dash position" of each vertex. In other words it is the vertex coords (in de
vice space) if we | 431 * "dash position" of each vertex. In other words it is the vertex coords (in de
vice space) if we |
| 432 * transform the line to be horizontal, with the start of line at the origin the
n shifted to the | 432 * transform the line to be horizontal, with the start of line at the origin the
n shifted to the |
| 433 * right by half the off interval. The line then goes in the positive x directio
n. | 433 * right by half the off interval. The line then goes in the positive x directio
n. |
| 434 */ | 434 */ |
| 435 class DashingCircleEffect : public GrGeometryProcessor { | 435 class DashingCircleEffect : public GrGeometryProcessor { |
| 436 public: | 436 public: |
| 437 typedef SkPathEffect::DashInfo DashInfo; | 437 typedef SkPathEffect::DashInfo DashInfo; |
| 438 | 438 |
| 439 static GrEffect* Create(GrEffectEdgeType edgeType, const DashInfo& info, SkS
calar radius); | 439 static GrGeometryProcessor* Create(GrPrimitiveEdgeType edgeType, |
| 440 const DashInfo& info, |
| 441 SkScalar radius); |
| 440 | 442 |
| 441 virtual ~DashingCircleEffect(); | 443 virtual ~DashingCircleEffect(); |
| 442 | 444 |
| 443 static const char* Name() { return "DashingCircleEffect"; } | 445 static const char* Name() { return "DashingCircleEffect"; } |
| 444 | 446 |
| 445 const GrShaderVar& inCoord() const { return fInCoord; } | 447 const GrShaderVar& inCoord() const { return fInCoord; } |
| 446 | 448 |
| 447 GrEffectEdgeType getEdgeType() const { return fEdgeType; } | 449 GrPrimitiveEdgeType getEdgeType() const { return fEdgeType; } |
| 448 | 450 |
| 449 SkScalar getRadius() const { return fRadius; } | 451 SkScalar getRadius() const { return fRadius; } |
| 450 | 452 |
| 451 SkScalar getCenterX() const { return fCenterX; } | 453 SkScalar getCenterX() const { return fCenterX; } |
| 452 | 454 |
| 453 SkScalar getIntervalLength() const { return fIntervalLength; } | 455 SkScalar getIntervalLength() const { return fIntervalLength; } |
| 454 | 456 |
| 455 typedef GLDashingCircleEffect GLEffect; | 457 typedef GLDashingCircleEffect GLProcessor; |
| 456 | 458 |
| 457 virtual void getConstantColorComponents(GrColor* color, uint32_t* validFlags
) const SK_OVERRIDE; | 459 virtual void getConstantColorComponents(GrColor* color, uint32_t* validFlags
) const SK_OVERRIDE; |
| 458 | 460 |
| 459 virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE; | 461 virtual const GrBackendGeometryProcessorFactory& getFactory() const SK_OVERR
IDE; |
| 460 | 462 |
| 461 private: | 463 private: |
| 462 DashingCircleEffect(GrEffectEdgeType edgeType, const DashInfo& info, SkScala
r radius); | 464 DashingCircleEffect(GrPrimitiveEdgeType edgeType, const DashInfo& info, SkSc
alar radius); |
| 463 | 465 |
| 464 virtual bool onIsEqual(const GrEffect& other) const SK_OVERRIDE; | 466 virtual bool onIsEqual(const GrProcessor& other) const SK_OVERRIDE; |
| 465 | 467 |
| 466 GrEffectEdgeType fEdgeType; | 468 GrPrimitiveEdgeType fEdgeType; |
| 467 const GrShaderVar& fInCoord; | 469 const GrShaderVar& fInCoord; |
| 468 SkScalar fIntervalLength; | 470 SkScalar fIntervalLength; |
| 469 SkScalar fRadius; | 471 SkScalar fRadius; |
| 470 SkScalar fCenterX; | 472 SkScalar fCenterX; |
| 471 | 473 |
| 472 GR_DECLARE_EFFECT_TEST; | 474 GR_DECLARE_GEOMETRY_PROCESSOR_TEST; |
| 473 | 475 |
| 474 typedef GrGeometryProcessor INHERITED; | 476 typedef GrGeometryProcessor INHERITED; |
| 475 }; | 477 }; |
| 476 | 478 |
| 477 ////////////////////////////////////////////////////////////////////////////// | 479 ////////////////////////////////////////////////////////////////////////////// |
| 478 | 480 |
| 479 class GLDashingCircleEffect : public GrGLGeometryProcessor { | 481 class GLDashingCircleEffect : public GrGLGeometryProcessor { |
| 480 public: | 482 public: |
| 481 GLDashingCircleEffect(const GrBackendEffectFactory&, const GrEffect&); | 483 GLDashingCircleEffect(const GrBackendProcessorFactory&, const GrProcessor&); |
| 482 | 484 |
| 483 virtual void emitCode(GrGLFullProgramBuilder* builder, | 485 virtual void emitCode(GrGLFullProgramBuilder* builder, |
| 484 const GrEffect& effect, | 486 const GrGeometryProcessor& geometryProcessor, |
| 485 const GrEffectKey& key, | 487 const GrProcessorKey& key, |
| 486 const char* outputColor, | 488 const char* outputColor, |
| 487 const char* inputColor, | 489 const char* inputColor, |
| 488 const TransformedCoordsArray&, | 490 const TransformedCoordsArray&, |
| 489 const TextureSamplerArray&) SK_OVERRIDE; | 491 const TextureSamplerArray&) SK_OVERRIDE; |
| 490 | 492 |
| 491 static inline void GenKey(const GrEffect&, const GrGLCaps&, GrEffectKeyBuild
er*); | 493 static inline void GenKey(const GrProcessor&, const GrGLCaps&, GrProcessorKe
yBuilder*); |
| 492 | 494 |
| 493 virtual void setData(const GrGLProgramDataManager&, const GrEffect&) SK_OVER
RIDE; | 495 virtual void setData(const GrGLProgramDataManager&, const GrProcessor&) SK_O
VERRIDE; |
| 494 | 496 |
| 495 private: | 497 private: |
| 496 GrGLProgramDataManager::UniformHandle fParamUniform; | 498 GrGLProgramDataManager::UniformHandle fParamUniform; |
| 497 SkScalar fPrevRadius; | 499 SkScalar fPrevRadius; |
| 498 SkScalar fPrevCenterX; | 500 SkScalar fPrevCenterX; |
| 499 SkScalar fPrevIntervalLength; | 501 SkScalar fPrevIntervalLength; |
| 500 typedef GrGLGeometryProcessor INHERITED; | 502 typedef GrGLGeometryProcessor INHERITED; |
| 501 }; | 503 }; |
| 502 | 504 |
| 503 GLDashingCircleEffect::GLDashingCircleEffect(const GrBackendEffectFactory& facto
ry, | 505 GLDashingCircleEffect::GLDashingCircleEffect(const GrBackendProcessorFactory& fa
ctory, |
| 504 const GrEffect& effect) | 506 const GrProcessor&) |
| 505 : INHERITED (factory) { | 507 : INHERITED (factory) { |
| 506 fPrevRadius = SK_ScalarMin; | 508 fPrevRadius = SK_ScalarMin; |
| 507 fPrevCenterX = SK_ScalarMin; | 509 fPrevCenterX = SK_ScalarMin; |
| 508 fPrevIntervalLength = SK_ScalarMax; | 510 fPrevIntervalLength = SK_ScalarMax; |
| 509 } | 511 } |
| 510 | 512 |
| 511 void GLDashingCircleEffect::emitCode(GrGLFullProgramBuilder* builder, | 513 void GLDashingCircleEffect::emitCode(GrGLFullProgramBuilder* builder, |
| 512 const GrEffect& effect, | 514 const GrGeometryProcessor& geometryProcessor
, |
| 513 const GrEffectKey& key, | 515 const GrProcessorKey& key, |
| 514 const char* outputColor, | 516 const char* outputColor, |
| 515 const char* inputColor, | 517 const char* inputColor, |
| 516 const TransformedCoordsArray&, | 518 const TransformedCoordsArray&, |
| 517 const TextureSamplerArray& samplers) { | 519 const TextureSamplerArray& samplers) { |
| 518 const DashingCircleEffect& dce = effect.cast<DashingCircleEffect>(); | 520 const DashingCircleEffect& dce = geometryProcessor.cast<DashingCircleEffect>
(); |
| 519 const char *paramName; | 521 const char *paramName; |
| 520 // The param uniforms, xyz, refer to circle radius - 0.5, cicles center x co
ord, and | 522 // The param uniforms, xyz, refer to circle radius - 0.5, cicles center x co
ord, and |
| 521 // the total interval length of the dash. | 523 // the total interval length of the dash. |
| 522 fParamUniform = builder->addUniform(GrGLProgramBuilder::kFragment_Visibility
, | 524 fParamUniform = builder->addUniform(GrGLProgramBuilder::kFragment_Visibility
, |
| 523 kVec3f_GrSLType, | 525 kVec3f_GrSLType, |
| 524 "params", | 526 "params", |
| 525 ¶mName); | 527 ¶mName); |
| 526 | 528 |
| 527 const char *vsCoordName, *fsCoordName; | 529 const char *vsCoordName, *fsCoordName; |
| 528 builder->addVarying(kVec2f_GrSLType, "Coord", &vsCoordName, &fsCoordName); | 530 builder->addVarying(kVec2f_GrSLType, "Coord", &vsCoordName, &fsCoordName); |
| 529 | 531 |
| 530 GrGLVertexShaderBuilder* vsBuilder = builder->getVertexShaderBuilder(); | 532 GrGLVertexShaderBuilder* vsBuilder = builder->getVertexShaderBuilder(); |
| 531 vsBuilder->codeAppendf("\t%s = %s;\n", vsCoordName, dce.inCoord().c_str()); | 533 vsBuilder->codeAppendf("\t%s = %s;\n", vsCoordName, dce.inCoord().c_str()); |
| 532 | 534 |
| 533 // transforms all points so that we can compare them to our test circle | 535 // transforms all points so that we can compare them to our test circle |
| 534 GrGLFragmentShaderBuilder* fsBuilder = builder->getFragmentShaderBuilder(); | 536 GrGLProcessorFragmentShaderBuilder* fsBuilder = builder->getFragmentShaderBu
ilder(); |
| 535 fsBuilder->codeAppendf("\t\tfloat xShifted = %s.x - floor(%s.x / %s.z) * %s.
z;\n", | 537 fsBuilder->codeAppendf("\t\tfloat xShifted = %s.x - floor(%s.x / %s.z) * %s.
z;\n", |
| 536 fsCoordName, fsCoordName, paramName, paramName); | 538 fsCoordName, fsCoordName, paramName, paramName); |
| 537 fsBuilder->codeAppendf("\t\tvec2 fragPosShifted = vec2(xShifted, %s.y);\n",
fsCoordName); | 539 fsBuilder->codeAppendf("\t\tvec2 fragPosShifted = vec2(xShifted, %s.y);\n",
fsCoordName); |
| 538 fsBuilder->codeAppendf("\t\tvec2 center = vec2(%s.y, 0.0);\n", paramName); | 540 fsBuilder->codeAppendf("\t\tvec2 center = vec2(%s.y, 0.0);\n", paramName); |
| 539 fsBuilder->codeAppend("\t\tfloat dist = length(center - fragPosShifted);\n")
; | 541 fsBuilder->codeAppend("\t\tfloat dist = length(center - fragPosShifted);\n")
; |
| 540 if (GrEffectEdgeTypeIsAA(dce.getEdgeType())) { | 542 if (GrProcessorEdgeTypeIsAA(dce.getEdgeType())) { |
| 541 fsBuilder->codeAppendf("\t\tfloat diff = dist - %s.x;\n", paramName); | 543 fsBuilder->codeAppendf("\t\tfloat diff = dist - %s.x;\n", paramName); |
| 542 fsBuilder->codeAppend("\t\tdiff = 1.0 - diff;\n"); | 544 fsBuilder->codeAppend("\t\tdiff = 1.0 - diff;\n"); |
| 543 fsBuilder->codeAppend("\t\tfloat alpha = clamp(diff, 0.0, 1.0);\n"); | 545 fsBuilder->codeAppend("\t\tfloat alpha = clamp(diff, 0.0, 1.0);\n"); |
| 544 } else { | 546 } else { |
| 545 fsBuilder->codeAppendf("\t\tfloat alpha = 1.0;\n"); | 547 fsBuilder->codeAppendf("\t\tfloat alpha = 1.0;\n"); |
| 546 fsBuilder->codeAppendf("\t\talpha *= dist < %s.x + 0.5 ? 1.0 : 0.0;\n",
paramName); | 548 fsBuilder->codeAppendf("\t\talpha *= dist < %s.x + 0.5 ? 1.0 : 0.0;\n",
paramName); |
| 547 } | 549 } |
| 548 fsBuilder->codeAppendf("\t\t%s = %s;\n", outputColor, | 550 fsBuilder->codeAppendf("\t\t%s = %s;\n", outputColor, |
| 549 (GrGLSLExpr4(inputColor) * GrGLSLExpr1("alpha")).c_st
r()); | 551 (GrGLSLExpr4(inputColor) * GrGLSLExpr1("alpha")).c_st
r()); |
| 550 } | 552 } |
| 551 | 553 |
| 552 void GLDashingCircleEffect::setData(const GrGLProgramDataManager& pdman, const G
rEffect& effect) { | 554 void GLDashingCircleEffect::setData(const GrGLProgramDataManager& pdman |
| 553 const DashingCircleEffect& dce = effect.cast<DashingCircleEffect>(); | 555 , const GrProcessor& processor) { |
| 556 const DashingCircleEffect& dce = processor.cast<DashingCircleEffect>(); |
| 554 SkScalar radius = dce.getRadius(); | 557 SkScalar radius = dce.getRadius(); |
| 555 SkScalar centerX = dce.getCenterX(); | 558 SkScalar centerX = dce.getCenterX(); |
| 556 SkScalar intervalLength = dce.getIntervalLength(); | 559 SkScalar intervalLength = dce.getIntervalLength(); |
| 557 if (radius != fPrevRadius || centerX != fPrevCenterX || intervalLength != fP
revIntervalLength) { | 560 if (radius != fPrevRadius || centerX != fPrevCenterX || intervalLength != fP
revIntervalLength) { |
| 558 pdman.set3f(fParamUniform, radius - 0.5f, centerX, intervalLength); | 561 pdman.set3f(fParamUniform, radius - 0.5f, centerX, intervalLength); |
| 559 fPrevRadius = radius; | 562 fPrevRadius = radius; |
| 560 fPrevCenterX = centerX; | 563 fPrevCenterX = centerX; |
| 561 fPrevIntervalLength = intervalLength; | 564 fPrevIntervalLength = intervalLength; |
| 562 } | 565 } |
| 563 } | 566 } |
| 564 | 567 |
| 565 void GLDashingCircleEffect::GenKey(const GrEffect& effect, const GrGLCaps&, | 568 void GLDashingCircleEffect::GenKey(const GrProcessor& processor, const GrGLCaps&
, |
| 566 GrEffectKeyBuilder* b) { | 569 GrProcessorKeyBuilder* b) { |
| 567 const DashingCircleEffect& dce = effect.cast<DashingCircleEffect>(); | 570 const DashingCircleEffect& dce = processor.cast<DashingCircleEffect>(); |
| 568 b->add32(dce.getEdgeType()); | 571 b->add32(dce.getEdgeType()); |
| 569 } | 572 } |
| 570 | 573 |
| 571 ////////////////////////////////////////////////////////////////////////////// | 574 ////////////////////////////////////////////////////////////////////////////// |
| 572 | 575 |
| 573 GrEffect* DashingCircleEffect::Create(GrEffectEdgeType edgeType, const DashInfo&
info, | 576 GrGeometryProcessor* DashingCircleEffect::Create(GrPrimitiveEdgeType edgeType, c
onst DashInfo& info, |
| 574 SkScalar radius) { | 577 SkScalar radius) { |
| 575 if (info.fCount != 2 || info.fIntervals[0] != 0) { | 578 if (info.fCount != 2 || info.fIntervals[0] != 0) { |
| 576 return NULL; | 579 return NULL; |
| 577 } | 580 } |
| 578 | 581 |
| 579 return SkNEW_ARGS(DashingCircleEffect, (edgeType, info, radius)); | 582 return SkNEW_ARGS(DashingCircleEffect, (edgeType, info, radius)); |
| 580 } | 583 } |
| 581 | 584 |
| 582 DashingCircleEffect::~DashingCircleEffect() {} | 585 DashingCircleEffect::~DashingCircleEffect() {} |
| 583 | 586 |
| 584 void DashingCircleEffect::getConstantColorComponents(GrColor* color, uint32_t* v
alidFlags) const { | 587 void DashingCircleEffect::getConstantColorComponents(GrColor* color, uint32_t* v
alidFlags) const { |
| 585 *validFlags = 0; | 588 *validFlags = 0; |
| 586 } | 589 } |
| 587 | 590 |
| 588 const GrBackendEffectFactory& DashingCircleEffect::getFactory() const { | 591 const GrBackendGeometryProcessorFactory& DashingCircleEffect::getFactory() const
{ |
| 589 return GrTBackendEffectFactory<DashingCircleEffect>::getInstance(); | 592 return GrTBackendGeometryProcessorFactory<DashingCircleEffect>::getInstance(
); |
| 590 } | 593 } |
| 591 | 594 |
| 592 DashingCircleEffect::DashingCircleEffect(GrEffectEdgeType edgeType, const DashIn
fo& info, | 595 DashingCircleEffect::DashingCircleEffect(GrPrimitiveEdgeType edgeType, const Das
hInfo& info, |
| 593 SkScalar radius) | 596 SkScalar radius) |
| 594 : fEdgeType(edgeType) | 597 : fEdgeType(edgeType) |
| 595 , fInCoord(this->addVertexAttrib(GrShaderVar("inCoord", | 598 , fInCoord(this->addVertexAttrib(GrShaderVar("inCoord", |
| 596 kVec2f_GrSLType, | 599 kVec2f_GrSLType, |
| 597 GrShaderVar::kAttribute_TypeMod
ifier))) { | 600 GrShaderVar::kAttribute_TypeMod
ifier))) { |
| 598 SkScalar onLen = info.fIntervals[0]; | 601 SkScalar onLen = info.fIntervals[0]; |
| 599 SkScalar offLen = info.fIntervals[1]; | 602 SkScalar offLen = info.fIntervals[1]; |
| 600 fIntervalLength = onLen + offLen; | 603 fIntervalLength = onLen + offLen; |
| 601 fRadius = radius; | 604 fRadius = radius; |
| 602 fCenterX = SkScalarHalf(offLen); | 605 fCenterX = SkScalarHalf(offLen); |
| 603 } | 606 } |
| 604 | 607 |
| 605 bool DashingCircleEffect::onIsEqual(const GrEffect& other) const { | 608 bool DashingCircleEffect::onIsEqual(const GrProcessor& other) const { |
| 606 const DashingCircleEffect& dce = other.cast<DashingCircleEffect>(); | 609 const DashingCircleEffect& dce = other.cast<DashingCircleEffect>(); |
| 607 return (fEdgeType == dce.fEdgeType && | 610 return (fEdgeType == dce.fEdgeType && |
| 608 fIntervalLength == dce.fIntervalLength && | 611 fIntervalLength == dce.fIntervalLength && |
| 609 fRadius == dce.fRadius && | 612 fRadius == dce.fRadius && |
| 610 fCenterX == dce.fCenterX); | 613 fCenterX == dce.fCenterX); |
| 611 } | 614 } |
| 612 | 615 |
| 613 GR_DEFINE_EFFECT_TEST(DashingCircleEffect); | 616 GR_DEFINE_GEOMETRY_PROCESSOR_TEST(DashingCircleEffect); |
| 614 | 617 |
| 615 GrEffect* DashingCircleEffect::TestCreate(SkRandom* random, | 618 GrGeometryProcessor* DashingCircleEffect::TestCreate(SkRandom* random, |
| 616 GrContext*, | 619 GrContext*, |
| 617 const GrDrawTargetCaps& caps, | 620 const GrDrawTargetCaps& cap
s, |
| 618 GrTexture*[]) { | 621 GrTexture*[]) { |
| 619 GrEffect* effect; | 622 GrPrimitiveEdgeType edgeType = static_cast<GrPrimitiveEdgeType>(random->next
ULessThan( |
| 620 GrEffectEdgeType edgeType = static_cast<GrEffectEdgeType>(random->nextULessT
han( | 623 kGrProcessorEdgeTypeCnt)); |
| 621 kGrEffectEdgeTypeCnt)); | |
| 622 SkScalar strokeWidth = random->nextRangeScalar(0, 100.f); | 624 SkScalar strokeWidth = random->nextRangeScalar(0, 100.f); |
| 623 DashInfo info; | 625 DashInfo info; |
| 624 info.fCount = 2; | 626 info.fCount = 2; |
| 625 SkAutoTArray<SkScalar> intervals(info.fCount); | 627 SkAutoTArray<SkScalar> intervals(info.fCount); |
| 626 info.fIntervals = intervals.get(); | 628 info.fIntervals = intervals.get(); |
| 627 info.fIntervals[0] = 0; | 629 info.fIntervals[0] = 0; |
| 628 info.fIntervals[1] = random->nextRangeScalar(0, 10.f); | 630 info.fIntervals[1] = random->nextRangeScalar(0, 10.f); |
| 629 info.fPhase = random->nextRangeScalar(0, info.fIntervals[1]); | 631 info.fPhase = random->nextRangeScalar(0, info.fIntervals[1]); |
| 630 | 632 |
| 631 effect = DashingCircleEffect::Create(edgeType, info, strokeWidth); | 633 return DashingCircleEffect::Create(edgeType, info, strokeWidth); |
| 632 return effect; | |
| 633 } | 634 } |
| 634 | 635 |
| 635 ////////////////////////////////////////////////////////////////////////////// | 636 ////////////////////////////////////////////////////////////////////////////// |
| 636 | 637 |
| 637 class GLDashingLineEffect; | 638 class GLDashingLineEffect; |
| 638 | 639 |
| 639 /* | 640 /* |
| 640 * This effect will draw a dashed line. The width of the dash is given by the st
rokeWidth and the | 641 * This effect will draw a dashed line. The width of the dash is given by the st
rokeWidth and the |
| 641 * length and spacing by the DashInfo. Both of the previous two parameters are i
n device space. | 642 * length and spacing by the DashInfo. Both of the previous two parameters are i
n device space. |
| 642 * This effect also requires the setting of a vec2 vertex attribute for the the
four corners of the | 643 * This effect also requires the setting of a vec2 vertex attribute for the the
four corners of the |
| 643 * bounding rect. This attribute is the "dash position" of each vertex. In other
words it is the | 644 * bounding rect. This attribute is the "dash position" of each vertex. In other
words it is the |
| 644 * vertex coords (in device space) if we transform the line to be horizontal, wi
th the start of | 645 * vertex coords (in device space) if we transform the line to be horizontal, wi
th the start of |
| 645 * line at the origin then shifted to the right by half the off interval. The li
ne then goes in the | 646 * line at the origin then shifted to the right by half the off interval. The li
ne then goes in the |
| 646 * positive x direction. | 647 * positive x direction. |
| 647 */ | 648 */ |
| 648 class DashingLineEffect : public GrGeometryProcessor { | 649 class DashingLineEffect : public GrGeometryProcessor { |
| 649 public: | 650 public: |
| 650 typedef SkPathEffect::DashInfo DashInfo; | 651 typedef SkPathEffect::DashInfo DashInfo; |
| 651 | 652 |
| 652 static GrEffect* Create(GrEffectEdgeType edgeType, const DashInfo& info, SkS
calar strokeWidth); | 653 static GrGeometryProcessor* Create(GrPrimitiveEdgeType edgeType, |
| 654 const DashInfo& info, |
| 655 SkScalar strokeWidth); |
| 653 | 656 |
| 654 virtual ~DashingLineEffect(); | 657 virtual ~DashingLineEffect(); |
| 655 | 658 |
| 656 static const char* Name() { return "DashingEffect"; } | 659 static const char* Name() { return "DashingEffect"; } |
| 657 | 660 |
| 658 const GrShaderVar& inCoord() const { return fInCoord; } | 661 const GrShaderVar& inCoord() const { return fInCoord; } |
| 659 | 662 |
| 660 GrEffectEdgeType getEdgeType() const { return fEdgeType; } | 663 GrPrimitiveEdgeType getEdgeType() const { return fEdgeType; } |
| 661 | 664 |
| 662 const SkRect& getRect() const { return fRect; } | 665 const SkRect& getRect() const { return fRect; } |
| 663 | 666 |
| 664 SkScalar getIntervalLength() const { return fIntervalLength; } | 667 SkScalar getIntervalLength() const { return fIntervalLength; } |
| 665 | 668 |
| 666 typedef GLDashingLineEffect GLEffect; | 669 typedef GLDashingLineEffect GLProcessor; |
| 667 | 670 |
| 668 virtual void getConstantColorComponents(GrColor* color, uint32_t* validFlags
) const SK_OVERRIDE; | 671 virtual void getConstantColorComponents(GrColor* color, uint32_t* validFlags
) const SK_OVERRIDE; |
| 669 | 672 |
| 670 virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE; | 673 virtual const GrBackendGeometryProcessorFactory& getFactory() const SK_OVERR
IDE; |
| 671 | 674 |
| 672 private: | 675 private: |
| 673 DashingLineEffect(GrEffectEdgeType edgeType, const DashInfo& info, SkScalar
strokeWidth); | 676 DashingLineEffect(GrPrimitiveEdgeType edgeType, const DashInfo& info, SkScal
ar strokeWidth); |
| 674 | 677 |
| 675 virtual bool onIsEqual(const GrEffect& other) const SK_OVERRIDE; | 678 virtual bool onIsEqual(const GrProcessor& other) const SK_OVERRIDE; |
| 676 | 679 |
| 677 GrEffectEdgeType fEdgeType; | 680 GrPrimitiveEdgeType fEdgeType; |
| 678 const GrShaderVar& fInCoord; | 681 const GrShaderVar& fInCoord; |
| 679 SkRect fRect; | 682 SkRect fRect; |
| 680 SkScalar fIntervalLength; | 683 SkScalar fIntervalLength; |
| 681 | 684 |
| 682 GR_DECLARE_EFFECT_TEST; | 685 GR_DECLARE_GEOMETRY_PROCESSOR_TEST; |
| 683 | 686 |
| 684 typedef GrGeometryProcessor INHERITED; | 687 typedef GrGeometryProcessor INHERITED; |
| 685 }; | 688 }; |
| 686 | 689 |
| 687 ////////////////////////////////////////////////////////////////////////////// | 690 ////////////////////////////////////////////////////////////////////////////// |
| 688 | 691 |
| 689 class GLDashingLineEffect : public GrGLGeometryProcessor { | 692 class GLDashingLineEffect : public GrGLGeometryProcessor { |
| 690 public: | 693 public: |
| 691 GLDashingLineEffect(const GrBackendEffectFactory&, const GrEffect&); | 694 GLDashingLineEffect(const GrBackendProcessorFactory&, const GrProcessor&); |
| 692 | 695 |
| 693 virtual void emitCode(GrGLFullProgramBuilder* builder, | 696 virtual void emitCode(GrGLFullProgramBuilder* builder, |
| 694 const GrEffect& effect, | 697 const GrGeometryProcessor& geometryProcessor, |
| 695 const GrEffectKey& key, | 698 const GrProcessorKey& key, |
| 696 const char* outputColor, | 699 const char* outputColor, |
| 697 const char* inputColor, | 700 const char* inputColor, |
| 698 const TransformedCoordsArray&, | 701 const TransformedCoordsArray&, |
| 699 const TextureSamplerArray&) SK_OVERRIDE; | 702 const TextureSamplerArray&) SK_OVERRIDE; |
| 700 | 703 |
| 701 static inline void GenKey(const GrEffect&, const GrGLCaps&, GrEffectKeyBuild
er*); | 704 static inline void GenKey(const GrProcessor&, const GrGLCaps&, GrProcessorKe
yBuilder*); |
| 702 | 705 |
| 703 virtual void setData(const GrGLProgramDataManager&, const GrEffect&) SK_OVER
RIDE; | 706 virtual void setData(const GrGLProgramDataManager&, const GrProcessor&) SK_O
VERRIDE; |
| 704 | 707 |
| 705 private: | 708 private: |
| 706 GrGLProgramDataManager::UniformHandle fRectUniform; | 709 GrGLProgramDataManager::UniformHandle fRectUniform; |
| 707 GrGLProgramDataManager::UniformHandle fIntervalUniform; | 710 GrGLProgramDataManager::UniformHandle fIntervalUniform; |
| 708 SkRect fPrevRect; | 711 SkRect fPrevRect; |
| 709 SkScalar fPrevIntervalLength; | 712 SkScalar fPrevIntervalLength; |
| 710 typedef GrGLGeometryProcessor INHERITED; | 713 typedef GrGLGeometryProcessor INHERITED; |
| 711 }; | 714 }; |
| 712 | 715 |
| 713 GLDashingLineEffect::GLDashingLineEffect(const GrBackendEffectFactory& factory, | 716 GLDashingLineEffect::GLDashingLineEffect(const GrBackendProcessorFactory& factor
y, |
| 714 const GrEffect& effect) | 717 const GrProcessor&) |
| 715 : INHERITED (factory) { | 718 : INHERITED (factory) { |
| 716 fPrevRect.fLeft = SK_ScalarNaN; | 719 fPrevRect.fLeft = SK_ScalarNaN; |
| 717 fPrevIntervalLength = SK_ScalarMax; | 720 fPrevIntervalLength = SK_ScalarMax; |
| 718 } | 721 } |
| 719 | 722 |
| 720 void GLDashingLineEffect::emitCode(GrGLFullProgramBuilder* builder, | 723 void GLDashingLineEffect::emitCode(GrGLFullProgramBuilder* builder, |
| 721 const GrEffect& effect, | 724 const GrGeometryProcessor& geometryProcessor, |
| 722 const GrEffectKey& key, | 725 const GrProcessorKey& key, |
| 723 const char* outputColor, | 726 const char* outputColor, |
| 724 const char* inputColor, | 727 const char* inputColor, |
| 725 const TransformedCoordsArray&, | 728 const TransformedCoordsArray&, |
| 726 const TextureSamplerArray& samplers) { | 729 const TextureSamplerArray& samplers) { |
| 727 const DashingLineEffect& de = effect.cast<DashingLineEffect>(); | 730 const DashingLineEffect& de = geometryProcessor.cast<DashingLineEffect>(); |
| 728 const char *rectName; | 731 const char *rectName; |
| 729 // The rect uniform's xyzw refer to (left + 0.5, top + 0.5, right - 0.5, bot
tom - 0.5), | 732 // The rect uniform's xyzw refer to (left + 0.5, top + 0.5, right - 0.5, bot
tom - 0.5), |
| 730 // respectively. | 733 // respectively. |
| 731 fRectUniform = builder->addUniform(GrGLProgramBuilder::kFragment_Visibility, | 734 fRectUniform = builder->addUniform(GrGLProgramBuilder::kFragment_Visibility, |
| 732 kVec4f_GrSLType, | 735 kVec4f_GrSLType, |
| 733 "rect", | 736 "rect", |
| 734 &rectName); | 737 &rectName); |
| 735 const char *intervalName; | 738 const char *intervalName; |
| 736 // The interval uniform's refers to the total length of the interval (on + o
ff) | 739 // The interval uniform's refers to the total length of the interval (on + o
ff) |
| 737 fIntervalUniform = builder->addUniform(GrGLProgramBuilder::kFragment_Visibil
ity, | 740 fIntervalUniform = builder->addUniform(GrGLProgramBuilder::kFragment_Visibil
ity, |
| 738 kFloat_GrSLType, | 741 kFloat_GrSLType, |
| 739 "interval", | 742 "interval", |
| 740 &intervalName); | 743 &intervalName); |
| 741 | 744 |
| 742 const char *vsCoordName, *fsCoordName; | 745 const char *vsCoordName, *fsCoordName; |
| 743 builder->addVarying(kVec2f_GrSLType, "Coord", &vsCoordName, &fsCoordName); | 746 builder->addVarying(kVec2f_GrSLType, "Coord", &vsCoordName, &fsCoordName); |
| 744 GrGLVertexShaderBuilder* vsBuilder = builder->getVertexShaderBuilder(); | 747 GrGLVertexShaderBuilder* vsBuilder = builder->getVertexShaderBuilder(); |
| 745 vsBuilder->codeAppendf("\t%s = %s;\n", vsCoordName, de.inCoord().c_str()); | 748 vsBuilder->codeAppendf("\t%s = %s;\n", vsCoordName, de.inCoord().c_str()); |
| 746 | 749 |
| 747 // transforms all points so that we can compare them to our test rect | 750 // transforms all points so that we can compare them to our test rect |
| 748 GrGLFragmentShaderBuilder* fsBuilder = builder->getFragmentShaderBuilder(); | 751 GrGLProcessorFragmentShaderBuilder* fsBuilder = builder->getFragmentShaderBu
ilder(); |
| 749 fsBuilder->codeAppendf("\t\tfloat xShifted = %s.x - floor(%s.x / %s) * %s;\n
", | 752 fsBuilder->codeAppendf("\t\tfloat xShifted = %s.x - floor(%s.x / %s) * %s;\n
", |
| 750 fsCoordName, fsCoordName, intervalName, intervalName)
; | 753 fsCoordName, fsCoordName, intervalName, intervalName)
; |
| 751 fsBuilder->codeAppendf("\t\tvec2 fragPosShifted = vec2(xShifted, %s.y);\n",
fsCoordName); | 754 fsBuilder->codeAppendf("\t\tvec2 fragPosShifted = vec2(xShifted, %s.y);\n",
fsCoordName); |
| 752 if (GrEffectEdgeTypeIsAA(de.getEdgeType())) { | 755 if (GrProcessorEdgeTypeIsAA(de.getEdgeType())) { |
| 753 // The amount of coverage removed in x and y by the edges is computed as
a pair of negative | 756 // The amount of coverage removed in x and y by the edges is computed as
a pair of negative |
| 754 // numbers, xSub and ySub. | 757 // numbers, xSub and ySub. |
| 755 fsBuilder->codeAppend("\t\tfloat xSub, ySub;\n"); | 758 fsBuilder->codeAppend("\t\tfloat xSub, ySub;\n"); |
| 756 fsBuilder->codeAppendf("\t\txSub = min(fragPosShifted.x - %s.x, 0.0);\n"
, rectName); | 759 fsBuilder->codeAppendf("\t\txSub = min(fragPosShifted.x - %s.x, 0.0);\n"
, rectName); |
| 757 fsBuilder->codeAppendf("\t\txSub += min(%s.z - fragPosShifted.x, 0.0);\n
", rectName); | 760 fsBuilder->codeAppendf("\t\txSub += min(%s.z - fragPosShifted.x, 0.0);\n
", rectName); |
| 758 fsBuilder->codeAppendf("\t\tySub = min(fragPosShifted.y - %s.y, 0.0);\n"
, rectName); | 761 fsBuilder->codeAppendf("\t\tySub = min(fragPosShifted.y - %s.y, 0.0);\n"
, rectName); |
| 759 fsBuilder->codeAppendf("\t\tySub += min(%s.w - fragPosShifted.y, 0.0);\n
", rectName); | 762 fsBuilder->codeAppendf("\t\tySub += min(%s.w - fragPosShifted.y, 0.0);\n
", rectName); |
| 760 // Now compute coverage in x and y and multiply them to get the fraction
of the pixel | 763 // Now compute coverage in x and y and multiply them to get the fraction
of the pixel |
| 761 // covered. | 764 // covered. |
| 762 fsBuilder->codeAppendf("\t\tfloat alpha = (1.0 + max(xSub, -1.0)) * (1.0
+ max(ySub, -1.0));\n"); | 765 fsBuilder->codeAppendf("\t\tfloat alpha = (1.0 + max(xSub, -1.0)) * (1.0
+ max(ySub, -1.0));\n"); |
| 763 } else { | 766 } else { |
| 764 // Assuming the bounding geometry is tight so no need to check y values | 767 // Assuming the bounding geometry is tight so no need to check y values |
| 765 fsBuilder->codeAppendf("\t\tfloat alpha = 1.0;\n"); | 768 fsBuilder->codeAppendf("\t\tfloat alpha = 1.0;\n"); |
| 766 fsBuilder->codeAppendf("\t\talpha *= (fragPosShifted.x - %s.x) > -0.5 ?
1.0 : 0.0;\n", rectName); | 769 fsBuilder->codeAppendf("\t\talpha *= (fragPosShifted.x - %s.x) > -0.5 ?
1.0 : 0.0;\n", rectName); |
| 767 fsBuilder->codeAppendf("\t\talpha *= (%s.z - fragPosShifted.x) >= -0.5 ?
1.0 : 0.0;\n", rectName); | 770 fsBuilder->codeAppendf("\t\talpha *= (%s.z - fragPosShifted.x) >= -0.5 ?
1.0 : 0.0;\n", rectName); |
| 768 } | 771 } |
| 769 fsBuilder->codeAppendf("\t\t%s = %s;\n", outputColor, | 772 fsBuilder->codeAppendf("\t\t%s = %s;\n", outputColor, |
| 770 (GrGLSLExpr4(inputColor) * GrGLSLExpr1("alpha")).c_st
r()); | 773 (GrGLSLExpr4(inputColor) * GrGLSLExpr1("alpha")).c_st
r()); |
| 771 } | 774 } |
| 772 | 775 |
| 773 void GLDashingLineEffect::setData(const GrGLProgramDataManager& pdman, const GrE
ffect& effect) { | 776 void GLDashingLineEffect::setData(const GrGLProgramDataManager& pdman, |
| 774 const DashingLineEffect& de = effect.cast<DashingLineEffect>(); | 777 const GrProcessor& processor) { |
| 778 const DashingLineEffect& de = processor.cast<DashingLineEffect>(); |
| 775 const SkRect& rect = de.getRect(); | 779 const SkRect& rect = de.getRect(); |
| 776 SkScalar intervalLength = de.getIntervalLength(); | 780 SkScalar intervalLength = de.getIntervalLength(); |
| 777 if (rect != fPrevRect || intervalLength != fPrevIntervalLength) { | 781 if (rect != fPrevRect || intervalLength != fPrevIntervalLength) { |
| 778 pdman.set4f(fRectUniform, rect.fLeft + 0.5f, rect.fTop + 0.5f, | 782 pdman.set4f(fRectUniform, rect.fLeft + 0.5f, rect.fTop + 0.5f, |
| 779 rect.fRight - 0.5f, rect.fBottom - 0.5f); | 783 rect.fRight - 0.5f, rect.fBottom - 0.5f); |
| 780 pdman.set1f(fIntervalUniform, intervalLength); | 784 pdman.set1f(fIntervalUniform, intervalLength); |
| 781 fPrevRect = rect; | 785 fPrevRect = rect; |
| 782 fPrevIntervalLength = intervalLength; | 786 fPrevIntervalLength = intervalLength; |
| 783 } | 787 } |
| 784 } | 788 } |
| 785 | 789 |
| 786 void GLDashingLineEffect::GenKey(const GrEffect& effect, const GrGLCaps&, | 790 void GLDashingLineEffect::GenKey(const GrProcessor& processor, const GrGLCaps&, |
| 787 GrEffectKeyBuilder* b) { | 791 GrProcessorKeyBuilder* b) { |
| 788 const DashingLineEffect& de = effect.cast<DashingLineEffect>(); | 792 const DashingLineEffect& de = processor.cast<DashingLineEffect>(); |
| 789 b->add32(de.getEdgeType()); | 793 b->add32(de.getEdgeType()); |
| 790 } | 794 } |
| 791 | 795 |
| 792 ////////////////////////////////////////////////////////////////////////////// | 796 ////////////////////////////////////////////////////////////////////////////// |
| 793 | 797 |
| 794 GrEffect* DashingLineEffect::Create(GrEffectEdgeType edgeType, const DashInfo& i
nfo, | 798 GrGeometryProcessor* DashingLineEffect::Create(GrPrimitiveEdgeType edgeType, |
| 795 SkScalar strokeWidth) { | 799 const DashInfo& info, |
| 800 SkScalar strokeWidth) { |
| 796 if (info.fCount != 2) { | 801 if (info.fCount != 2) { |
| 797 return NULL; | 802 return NULL; |
| 798 } | 803 } |
| 799 | 804 |
| 800 return SkNEW_ARGS(DashingLineEffect, (edgeType, info, strokeWidth)); | 805 return SkNEW_ARGS(DashingLineEffect, (edgeType, info, strokeWidth)); |
| 801 } | 806 } |
| 802 | 807 |
| 803 DashingLineEffect::~DashingLineEffect() {} | 808 DashingLineEffect::~DashingLineEffect() {} |
| 804 | 809 |
| 805 void DashingLineEffect::getConstantColorComponents(GrColor* color, uint32_t* val
idFlags) const { | 810 void DashingLineEffect::getConstantColorComponents(GrColor* color, uint32_t* val
idFlags) const { |
| 806 *validFlags = 0; | 811 *validFlags = 0; |
| 807 } | 812 } |
| 808 | 813 |
| 809 const GrBackendEffectFactory& DashingLineEffect::getFactory() const { | 814 const GrBackendGeometryProcessorFactory& DashingLineEffect::getFactory() const { |
| 810 return GrTBackendEffectFactory<DashingLineEffect>::getInstance(); | 815 return GrTBackendGeometryProcessorFactory<DashingLineEffect>::getInstance(); |
| 811 } | 816 } |
| 812 | 817 |
| 813 DashingLineEffect::DashingLineEffect(GrEffectEdgeType edgeType, const DashInfo&
info, | 818 DashingLineEffect::DashingLineEffect(GrPrimitiveEdgeType edgeType, const DashInf
o& info, |
| 814 SkScalar strokeWidth) | 819 SkScalar strokeWidth) |
| 815 : fEdgeType(edgeType) | 820 : fEdgeType(edgeType) |
| 816 , fInCoord(this->addVertexAttrib(GrShaderVar("inCoord", | 821 , fInCoord(this->addVertexAttrib(GrShaderVar("inCoord", |
| 817 kVec2f_GrSLType, | 822 kVec2f_GrSLType, |
| 818 GrShaderVar::kAttribute_TypeMod
ifier))) { | 823 GrShaderVar::kAttribute_TypeMod
ifier))) { |
| 819 SkScalar onLen = info.fIntervals[0]; | 824 SkScalar onLen = info.fIntervals[0]; |
| 820 SkScalar offLen = info.fIntervals[1]; | 825 SkScalar offLen = info.fIntervals[1]; |
| 821 SkScalar halfOffLen = SkScalarHalf(offLen); | 826 SkScalar halfOffLen = SkScalarHalf(offLen); |
| 822 SkScalar halfStroke = SkScalarHalf(strokeWidth); | 827 SkScalar halfStroke = SkScalarHalf(strokeWidth); |
| 823 fIntervalLength = onLen + offLen; | 828 fIntervalLength = onLen + offLen; |
| 824 fRect.set(halfOffLen, -halfStroke, halfOffLen + onLen, halfStroke); | 829 fRect.set(halfOffLen, -halfStroke, halfOffLen + onLen, halfStroke); |
| 825 } | 830 } |
| 826 | 831 |
| 827 bool DashingLineEffect::onIsEqual(const GrEffect& other) const { | 832 bool DashingLineEffect::onIsEqual(const GrProcessor& other) const { |
| 828 const DashingLineEffect& de = other.cast<DashingLineEffect>(); | 833 const DashingLineEffect& de = other.cast<DashingLineEffect>(); |
| 829 return (fEdgeType == de.fEdgeType && | 834 return (fEdgeType == de.fEdgeType && |
| 830 fRect == de.fRect && | 835 fRect == de.fRect && |
| 831 fIntervalLength == de.fIntervalLength); | 836 fIntervalLength == de.fIntervalLength); |
| 832 } | 837 } |
| 833 | 838 |
| 834 GR_DEFINE_EFFECT_TEST(DashingLineEffect); | 839 GR_DEFINE_GEOMETRY_PROCESSOR_TEST(DashingLineEffect); |
| 835 | 840 |
| 836 GrEffect* DashingLineEffect::TestCreate(SkRandom* random, | 841 GrGeometryProcessor* DashingLineEffect::TestCreate(SkRandom* random, |
| 837 GrContext*, | 842 GrContext*, |
| 838 const GrDrawTargetCaps& caps, | 843 const GrDrawTargetCaps& caps, |
| 839 GrTexture*[]) { | 844 GrTexture*[]) { |
| 840 GrEffect* effect; | 845 GrPrimitiveEdgeType edgeType = static_cast<GrPrimitiveEdgeType>(random->next
ULessThan( |
| 841 GrEffectEdgeType edgeType = static_cast<GrEffectEdgeType>(random->nextULessT
han( | 846 kGrProcessorEdgeTypeCnt)); |
| 842 kGrEffectEdgeTypeCnt)); | |
| 843 SkScalar strokeWidth = random->nextRangeScalar(0, 100.f); | 847 SkScalar strokeWidth = random->nextRangeScalar(0, 100.f); |
| 844 DashInfo info; | 848 DashInfo info; |
| 845 info.fCount = 2; | 849 info.fCount = 2; |
| 846 SkAutoTArray<SkScalar> intervals(info.fCount); | 850 SkAutoTArray<SkScalar> intervals(info.fCount); |
| 847 info.fIntervals = intervals.get(); | 851 info.fIntervals = intervals.get(); |
| 848 info.fIntervals[0] = random->nextRangeScalar(0, 10.f); | 852 info.fIntervals[0] = random->nextRangeScalar(0, 10.f); |
| 849 info.fIntervals[1] = random->nextRangeScalar(0, 10.f); | 853 info.fIntervals[1] = random->nextRangeScalar(0, 10.f); |
| 850 info.fPhase = random->nextRangeScalar(0, info.fIntervals[0] + info.fInterval
s[1]); | 854 info.fPhase = random->nextRangeScalar(0, info.fIntervals[0] + info.fInterval
s[1]); |
| 851 | 855 |
| 852 effect = DashingLineEffect::Create(edgeType, info, strokeWidth); | 856 return DashingLineEffect::Create(edgeType, info, strokeWidth); |
| 853 return effect; | |
| 854 } | 857 } |
| 855 | 858 |
| 856 ////////////////////////////////////////////////////////////////////////////// | 859 ////////////////////////////////////////////////////////////////////////////// |
| 857 | 860 |
| 858 GrEffect* GrDashingEffect::Create(GrEffectEdgeType edgeType, const SkPathEffect:
:DashInfo& info, | 861 GrGeometryProcessor* GrDashingEffect::Create(GrPrimitiveEdgeType edgeType, |
| 859 SkScalar strokeWidth, GrDashingEffect::DashCap
cap) { | 862 const SkPathEffect::DashInfo& info, |
| 863 SkScalar strokeWidth, |
| 864 GrDashingEffect::DashCap cap) { |
| 860 switch (cap) { | 865 switch (cap) { |
| 861 case GrDashingEffect::kRound_DashCap: | 866 case GrDashingEffect::kRound_DashCap: |
| 862 return DashingCircleEffect::Create(edgeType, info, SkScalarHalf(stro
keWidth)); | 867 return DashingCircleEffect::Create(edgeType, info, SkScalarHalf(stro
keWidth)); |
| 863 case GrDashingEffect::kNonRound_DashCap: | 868 case GrDashingEffect::kNonRound_DashCap: |
| 864 return DashingLineEffect::Create(edgeType, info, strokeWidth); | 869 return DashingLineEffect::Create(edgeType, info, strokeWidth); |
| 865 default: | 870 default: |
| 866 SkFAIL("Unexpected dashed cap."); | 871 SkFAIL("Unexpected dashed cap."); |
| 867 } | 872 } |
| 868 return NULL; | 873 return NULL; |
| 869 } | 874 } |
| OLD | NEW |