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

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

Issue 543623004: Removing vertex attrib indices (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: warning fixed Created 6 years, 3 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
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 "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
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
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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
417 class GLDashingCircleEffect; 425 class GLDashingCircleEffect;
418 /* 426 /*
419 * This effect will draw a dotted line (defined as a dashed lined with round cap s and no on 427 * 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. 428 * 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 429 * 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 430 * 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 431 * "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 432 * 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. 433 * right by half the off interval. The line then goes in the positive x directio n.
426 */ 434 */
427 class DashingCircleEffect : public GrVertexEffect { 435 class DashingCircleEffect : public GrGeometryProcessor {
428 public: 436 public:
429 typedef SkPathEffect::DashInfo DashInfo; 437 typedef SkPathEffect::DashInfo DashInfo;
430 438
431 static GrEffect* Create(GrEffectEdgeType edgeType, const DashInfo& info, SkS calar radius); 439 static GrEffect* Create(GrEffectEdgeType edgeType, const DashInfo& info, SkS calar radius);
432 440
433 virtual ~DashingCircleEffect(); 441 virtual ~DashingCircleEffect();
434 442
435 static const char* Name() { return "DashingCircleEffect"; } 443 static const char* Name() { return "DashingCircleEffect"; }
436 444
445 const GrShaderVar& inCoord() const { return fInCoord; }
446
437 GrEffectEdgeType getEdgeType() const { return fEdgeType; } 447 GrEffectEdgeType getEdgeType() const { return fEdgeType; }
438 448
439 SkScalar getRadius() const { return fRadius; } 449 SkScalar getRadius() const { return fRadius; }
440 450
441 SkScalar getCenterX() const { return fCenterX; } 451 SkScalar getCenterX() const { return fCenterX; }
442 452
443 SkScalar getIntervalLength() const { return fIntervalLength; } 453 SkScalar getIntervalLength() const { return fIntervalLength; }
444 454
445 typedef GLDashingCircleEffect GLEffect; 455 typedef GLDashingCircleEffect GLEffect;
446 456
447 virtual void getConstantColorComponents(GrColor* color, uint32_t* validFlags ) const SK_OVERRIDE; 457 virtual void getConstantColorComponents(GrColor* color, uint32_t* validFlags ) const SK_OVERRIDE;
448 458
449 virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE; 459 virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE;
450 460
451 private: 461 private:
452 DashingCircleEffect(GrEffectEdgeType edgeType, const DashInfo& info, SkScala r radius); 462 DashingCircleEffect(GrEffectEdgeType edgeType, const DashInfo& info, SkScala r radius);
453 463
454 virtual bool onIsEqual(const GrEffect& other) const SK_OVERRIDE; 464 virtual bool onIsEqual(const GrEffect& other) const SK_OVERRIDE;
455 465
456 GrEffectEdgeType fEdgeType; 466 GrEffectEdgeType fEdgeType;
467 const GrShaderVar& fInCoord;
457 SkScalar fIntervalLength; 468 SkScalar fIntervalLength;
458 SkScalar fRadius; 469 SkScalar fRadius;
459 SkScalar fCenterX; 470 SkScalar fCenterX;
460 471
461 GR_DECLARE_EFFECT_TEST; 472 GR_DECLARE_EFFECT_TEST;
462 473
463 typedef GrVertexEffect INHERITED; 474 typedef GrGeometryProcessor INHERITED;
464 }; 475 };
465 476
466 ////////////////////////////////////////////////////////////////////////////// 477 //////////////////////////////////////////////////////////////////////////////
467 478
468 class GLDashingCircleEffect : public GrGLVertexEffect { 479 class GLDashingCircleEffect : public GrGLGeometryProcessor {
469 public: 480 public:
470 GLDashingCircleEffect(const GrBackendEffectFactory&, const GrDrawEffect&); 481 GLDashingCircleEffect(const GrBackendEffectFactory&, const GrDrawEffect&);
471 482
472 virtual void emitCode(GrGLFullProgramBuilder* builder, 483 virtual void emitCode(GrGLFullProgramBuilder* builder,
473 const GrDrawEffect& drawEffect, 484 const GrDrawEffect& drawEffect,
474 const GrEffectKey& key, 485 const GrEffectKey& key,
475 const char* outputColor, 486 const char* outputColor,
476 const char* inputColor, 487 const char* inputColor,
477 const TransformedCoordsArray&, 488 const TransformedCoordsArray&,
478 const TextureSamplerArray&) SK_OVERRIDE; 489 const TextureSamplerArray&) SK_OVERRIDE;
479 490
480 static inline void GenKey(const GrDrawEffect&, const GrGLCaps&, GrEffectKeyB uilder*); 491 static inline void GenKey(const GrDrawEffect&, const GrGLCaps&, GrEffectKeyB uilder*);
481 492
482 virtual void setData(const GrGLProgramDataManager&, const GrDrawEffect&) SK_ OVERRIDE; 493 virtual void setData(const GrGLProgramDataManager&, const GrDrawEffect&) SK_ OVERRIDE;
483 494
484 private: 495 private:
485 GrGLProgramDataManager::UniformHandle fParamUniform; 496 GrGLProgramDataManager::UniformHandle fParamUniform;
486 SkScalar fPrevRadius; 497 SkScalar fPrevRadius;
487 SkScalar fPrevCenterX; 498 SkScalar fPrevCenterX;
488 SkScalar fPrevIntervalLength; 499 SkScalar fPrevIntervalLength;
489 typedef GrGLVertexEffect INHERITED; 500 typedef GrGLGeometryProcessor INHERITED;
490 }; 501 };
491 502
492 GLDashingCircleEffect::GLDashingCircleEffect(const GrBackendEffectFactory& facto ry, 503 GLDashingCircleEffect::GLDashingCircleEffect(const GrBackendEffectFactory& facto ry,
493 const GrDrawEffect& drawEffect) 504 const GrDrawEffect& drawEffect)
494 : INHERITED (factory) { 505 : INHERITED (factory) {
495 fPrevRadius = SK_ScalarMin; 506 fPrevRadius = SK_ScalarMin;
496 fPrevCenterX = SK_ScalarMin; 507 fPrevCenterX = SK_ScalarMin;
497 fPrevIntervalLength = SK_ScalarMax; 508 fPrevIntervalLength = SK_ScalarMax;
498 } 509 }
499 510
(...skipping 10 matching lines...) Expand all
510 // the total interval length of the dash. 521 // the total interval length of the dash.
511 fParamUniform = builder->addUniform(GrGLProgramBuilder::kFragment_Visibility , 522 fParamUniform = builder->addUniform(GrGLProgramBuilder::kFragment_Visibility ,
512 kVec3f_GrSLType, 523 kVec3f_GrSLType,
513 "params", 524 "params",
514 &paramName); 525 &paramName);
515 526
516 const char *vsCoordName, *fsCoordName; 527 const char *vsCoordName, *fsCoordName;
517 builder->addVarying(kVec2f_GrSLType, "Coord", &vsCoordName, &fsCoordName); 528 builder->addVarying(kVec2f_GrSLType, "Coord", &vsCoordName, &fsCoordName);
518 529
519 GrGLVertexShaderBuilder* vsBuilder = builder->getVertexShaderBuilder(); 530 GrGLVertexShaderBuilder* vsBuilder = builder->getVertexShaderBuilder();
520 const SkString* attr0Name = 531 vsBuilder->codeAppendf("\t%s = %s;\n", vsCoordName, dce.inCoord().c_str());
521 vsBuilder->getEffectAttributeName(drawEffect.getVertexAttribIndices()[0] );
522 vsBuilder->codeAppendf("\t%s = %s;\n", vsCoordName, attr0Name->c_str());
523 532
524 // transforms all points so that we can compare them to our test circle 533 // transforms all points so that we can compare them to our test circle
525 GrGLFragmentShaderBuilder* fsBuilder = builder->getFragmentShaderBuilder(); 534 GrGLFragmentShaderBuilder* fsBuilder = builder->getFragmentShaderBuilder();
526 fsBuilder->codeAppendf("\t\tfloat xShifted = %s.x - floor(%s.x / %s.z) * %s. z;\n", 535 fsBuilder->codeAppendf("\t\tfloat xShifted = %s.x - floor(%s.x / %s.z) * %s. z;\n",
527 fsCoordName, fsCoordName, paramName, paramName); 536 fsCoordName, fsCoordName, paramName, paramName);
528 fsBuilder->codeAppendf("\t\tvec2 fragPosShifted = vec2(xShifted, %s.y);\n", fsCoordName); 537 fsBuilder->codeAppendf("\t\tvec2 fragPosShifted = vec2(xShifted, %s.y);\n", fsCoordName);
529 fsBuilder->codeAppendf("\t\tvec2 center = vec2(%s.y, 0.0);\n", paramName); 538 fsBuilder->codeAppendf("\t\tvec2 center = vec2(%s.y, 0.0);\n", paramName);
530 fsBuilder->codeAppend("\t\tfloat dist = length(center - fragPosShifted);\n") ; 539 fsBuilder->codeAppend("\t\tfloat dist = length(center - fragPosShifted);\n") ;
531 if (GrEffectEdgeTypeIsAA(dce.getEdgeType())) { 540 if (GrEffectEdgeTypeIsAA(dce.getEdgeType())) {
532 fsBuilder->codeAppendf("\t\tfloat diff = dist - %s.x;\n", paramName); 541 fsBuilder->codeAppendf("\t\tfloat diff = dist - %s.x;\n", paramName);
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
575 void DashingCircleEffect::getConstantColorComponents(GrColor* color, uint32_t* v alidFlags) const { 584 void DashingCircleEffect::getConstantColorComponents(GrColor* color, uint32_t* v alidFlags) const {
576 *validFlags = 0; 585 *validFlags = 0;
577 } 586 }
578 587
579 const GrBackendEffectFactory& DashingCircleEffect::getFactory() const { 588 const GrBackendEffectFactory& DashingCircleEffect::getFactory() const {
580 return GrTBackendEffectFactory<DashingCircleEffect>::getInstance(); 589 return GrTBackendEffectFactory<DashingCircleEffect>::getInstance();
581 } 590 }
582 591
583 DashingCircleEffect::DashingCircleEffect(GrEffectEdgeType edgeType, const DashIn fo& info, 592 DashingCircleEffect::DashingCircleEffect(GrEffectEdgeType edgeType, const DashIn fo& info,
584 SkScalar radius) 593 SkScalar radius)
585 : fEdgeType(edgeType) { 594 : fEdgeType(edgeType)
595 , fInCoord(this->addVertexAttrib(GrShaderVar("inCoord",
596 kVec2f_GrSLType,
597 GrShaderVar::kAttribute_TypeMod ifier))) {
586 SkScalar onLen = info.fIntervals[0]; 598 SkScalar onLen = info.fIntervals[0];
587 SkScalar offLen = info.fIntervals[1]; 599 SkScalar offLen = info.fIntervals[1];
588 fIntervalLength = onLen + offLen; 600 fIntervalLength = onLen + offLen;
589 fRadius = radius; 601 fRadius = radius;
590 fCenterX = SkScalarHalf(offLen); 602 fCenterX = SkScalarHalf(offLen);
591
592 this->addVertexAttrib(kVec2f_GrSLType);
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
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
658 const GrShaderVar& inCoord() const { return fInCoord; }
659
648 GrEffectEdgeType getEdgeType() const { return fEdgeType; } 660 GrEffectEdgeType getEdgeType() const { return fEdgeType; }
649 661
650 const SkRect& getRect() const { return fRect; } 662 const SkRect& getRect() const { return fRect; }
651 663
652 SkScalar getIntervalLength() const { return fIntervalLength; } 664 SkScalar getIntervalLength() const { return fIntervalLength; }
653 665
654 typedef GLDashingLineEffect GLEffect; 666 typedef GLDashingLineEffect GLEffect;
655 667
656 virtual void getConstantColorComponents(GrColor* color, uint32_t* validFlags ) const SK_OVERRIDE; 668 virtual void getConstantColorComponents(GrColor* color, uint32_t* validFlags ) const SK_OVERRIDE;
657 669
658 virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE; 670 virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE;
659 671
660 private: 672 private:
661 DashingLineEffect(GrEffectEdgeType edgeType, const DashInfo& info, SkScalar strokeWidth); 673 DashingLineEffect(GrEffectEdgeType edgeType, const DashInfo& info, SkScalar strokeWidth);
662 674
663 virtual bool onIsEqual(const GrEffect& other) const SK_OVERRIDE; 675 virtual bool onIsEqual(const GrEffect& other) const SK_OVERRIDE;
664 676
665 GrEffectEdgeType fEdgeType; 677 GrEffectEdgeType fEdgeType;
678 const GrShaderVar& fInCoord;
666 SkRect fRect; 679 SkRect fRect;
667 SkScalar fIntervalLength; 680 SkScalar fIntervalLength;
668 681
669 GR_DECLARE_EFFECT_TEST; 682 GR_DECLARE_EFFECT_TEST;
670 683
671 typedef GrVertexEffect INHERITED; 684 typedef GrGeometryProcessor INHERITED;
672 }; 685 };
673 686
674 ////////////////////////////////////////////////////////////////////////////// 687 //////////////////////////////////////////////////////////////////////////////
675 688
676 class GLDashingLineEffect : public GrGLVertexEffect { 689 class GLDashingLineEffect : public GrGLGeometryProcessor {
677 public: 690 public:
678 GLDashingLineEffect(const GrBackendEffectFactory&, const GrDrawEffect&); 691 GLDashingLineEffect(const GrBackendEffectFactory&, const GrDrawEffect&);
679 692
680 virtual void emitCode(GrGLFullProgramBuilder* builder, 693 virtual void emitCode(GrGLFullProgramBuilder* builder,
681 const GrDrawEffect& drawEffect, 694 const GrDrawEffect& drawEffect,
682 const GrEffectKey& key, 695 const GrEffectKey& key,
683 const char* outputColor, 696 const char* outputColor,
684 const char* inputColor, 697 const char* inputColor,
685 const TransformedCoordsArray&, 698 const TransformedCoordsArray&,
686 const TextureSamplerArray&) SK_OVERRIDE; 699 const TextureSamplerArray&) SK_OVERRIDE;
687 700
688 static inline void GenKey(const GrDrawEffect&, const GrGLCaps&, GrEffectKeyB uilder*); 701 static inline void GenKey(const GrDrawEffect&, const GrGLCaps&, GrEffectKeyB uilder*);
689 702
690 virtual void setData(const GrGLProgramDataManager&, const GrDrawEffect&) SK_ OVERRIDE; 703 virtual void setData(const GrGLProgramDataManager&, const GrDrawEffect&) SK_ OVERRIDE;
691 704
692 private: 705 private:
693 GrGLProgramDataManager::UniformHandle fRectUniform; 706 GrGLProgramDataManager::UniformHandle fRectUniform;
694 GrGLProgramDataManager::UniformHandle fIntervalUniform; 707 GrGLProgramDataManager::UniformHandle fIntervalUniform;
695 SkRect fPrevRect; 708 SkRect fPrevRect;
696 SkScalar fPrevIntervalLength; 709 SkScalar fPrevIntervalLength;
697 typedef GrGLVertexEffect INHERITED; 710 typedef GrGLGeometryProcessor INHERITED;
698 }; 711 };
699 712
700 GLDashingLineEffect::GLDashingLineEffect(const GrBackendEffectFactory& factory, 713 GLDashingLineEffect::GLDashingLineEffect(const GrBackendEffectFactory& factory,
701 const GrDrawEffect& drawEffect) 714 const GrDrawEffect& drawEffect)
702 : INHERITED (factory) { 715 : INHERITED (factory) {
703 fPrevRect.fLeft = SK_ScalarNaN; 716 fPrevRect.fLeft = SK_ScalarNaN;
704 fPrevIntervalLength = SK_ScalarMax; 717 fPrevIntervalLength = SK_ScalarMax;
705 } 718 }
706 719
707 void GLDashingLineEffect::emitCode(GrGLFullProgramBuilder* builder, 720 void GLDashingLineEffect::emitCode(GrGLFullProgramBuilder* builder,
(...skipping 14 matching lines...) Expand all
722 const char *intervalName; 735 const char *intervalName;
723 // The interval uniform's refers to the total length of the interval (on + o ff) 736 // The interval uniform's refers to the total length of the interval (on + o ff)
724 fIntervalUniform = builder->addUniform(GrGLProgramBuilder::kFragment_Visibil ity, 737 fIntervalUniform = builder->addUniform(GrGLProgramBuilder::kFragment_Visibil ity,
725 kFloat_GrSLType, 738 kFloat_GrSLType,
726 "interval", 739 "interval",
727 &intervalName); 740 &intervalName);
728 741
729 const char *vsCoordName, *fsCoordName; 742 const char *vsCoordName, *fsCoordName;
730 builder->addVarying(kVec2f_GrSLType, "Coord", &vsCoordName, &fsCoordName); 743 builder->addVarying(kVec2f_GrSLType, "Coord", &vsCoordName, &fsCoordName);
731 GrGLVertexShaderBuilder* vsBuilder = builder->getVertexShaderBuilder(); 744 GrGLVertexShaderBuilder* vsBuilder = builder->getVertexShaderBuilder();
732 const SkString* attr0Name = 745 vsBuilder->codeAppendf("\t%s = %s;\n", vsCoordName, de.inCoord().c_str());
733 vsBuilder->getEffectAttributeName(drawEffect.getVertexAttribIndices()[0] );
734 vsBuilder->codeAppendf("\t%s = %s;\n", vsCoordName, attr0Name->c_str());
735 746
736 // transforms all points so that we can compare them to our test rect 747 // transforms all points so that we can compare them to our test rect
737 GrGLFragmentShaderBuilder* fsBuilder = builder->getFragmentShaderBuilder(); 748 GrGLFragmentShaderBuilder* fsBuilder = builder->getFragmentShaderBuilder();
738 fsBuilder->codeAppendf("\t\tfloat xShifted = %s.x - floor(%s.x / %s) * %s;\n ", 749 fsBuilder->codeAppendf("\t\tfloat xShifted = %s.x - floor(%s.x / %s) * %s;\n ",
739 fsCoordName, fsCoordName, intervalName, intervalName) ; 750 fsCoordName, fsCoordName, intervalName, intervalName) ;
740 fsBuilder->codeAppendf("\t\tvec2 fragPosShifted = vec2(xShifted, %s.y);\n", fsCoordName); 751 fsBuilder->codeAppendf("\t\tvec2 fragPosShifted = vec2(xShifted, %s.y);\n", fsCoordName);
741 if (GrEffectEdgeTypeIsAA(de.getEdgeType())) { 752 if (GrEffectEdgeTypeIsAA(de.getEdgeType())) {
742 // The amount of coverage removed in x and y by the edges is computed as a pair of negative 753 // The amount of coverage removed in x and y by the edges is computed as a pair of negative
743 // numbers, xSub and ySub. 754 // numbers, xSub and ySub.
744 fsBuilder->codeAppend("\t\tfloat xSub, ySub;\n"); 755 fsBuilder->codeAppend("\t\tfloat xSub, ySub;\n");
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
794 void DashingLineEffect::getConstantColorComponents(GrColor* color, uint32_t* val idFlags) const { 805 void DashingLineEffect::getConstantColorComponents(GrColor* color, uint32_t* val idFlags) const {
795 *validFlags = 0; 806 *validFlags = 0;
796 } 807 }
797 808
798 const GrBackendEffectFactory& DashingLineEffect::getFactory() const { 809 const GrBackendEffectFactory& DashingLineEffect::getFactory() const {
799 return GrTBackendEffectFactory<DashingLineEffect>::getInstance(); 810 return GrTBackendEffectFactory<DashingLineEffect>::getInstance();
800 } 811 }
801 812
802 DashingLineEffect::DashingLineEffect(GrEffectEdgeType edgeType, const DashInfo& info, 813 DashingLineEffect::DashingLineEffect(GrEffectEdgeType edgeType, const DashInfo& info,
803 SkScalar strokeWidth) 814 SkScalar strokeWidth)
804 : fEdgeType(edgeType) { 815 : fEdgeType(edgeType)
816 , fInCoord(this->addVertexAttrib(GrShaderVar("inCoord",
817 kVec2f_GrSLType,
818 GrShaderVar::kAttribute_TypeMod ifier))) {
805 SkScalar onLen = info.fIntervals[0]; 819 SkScalar onLen = info.fIntervals[0];
806 SkScalar offLen = info.fIntervals[1]; 820 SkScalar offLen = info.fIntervals[1];
807 SkScalar halfOffLen = SkScalarHalf(offLen); 821 SkScalar halfOffLen = SkScalarHalf(offLen);
808 SkScalar halfStroke = SkScalarHalf(strokeWidth); 822 SkScalar halfStroke = SkScalarHalf(strokeWidth);
809 fIntervalLength = onLen + offLen; 823 fIntervalLength = onLen + offLen;
810 fRect.set(halfOffLen, -halfStroke, halfOffLen + onLen, halfStroke); 824 fRect.set(halfOffLen, -halfStroke, halfOffLen + onLen, halfStroke);
811
812 this->addVertexAttrib(kVec2f_GrSLType);
813 } 825 }
814 826
815 bool DashingLineEffect::onIsEqual(const GrEffect& other) const { 827 bool DashingLineEffect::onIsEqual(const GrEffect& other) const {
816 const DashingLineEffect& de = CastEffect<DashingLineEffect>(other); 828 const DashingLineEffect& de = CastEffect<DashingLineEffect>(other);
817 return (fEdgeType == de.fEdgeType && 829 return (fEdgeType == de.fEdgeType &&
818 fRect == de.fRect && 830 fRect == de.fRect &&
819 fIntervalLength == de.fIntervalLength); 831 fIntervalLength == de.fIntervalLength);
820 } 832 }
821 833
822 GR_DEFINE_EFFECT_TEST(DashingLineEffect); 834 GR_DEFINE_EFFECT_TEST(DashingLineEffect);
(...skipping 25 matching lines...) Expand all
848 switch (cap) { 860 switch (cap) {
849 case GrDashingEffect::kRound_DashCap: 861 case GrDashingEffect::kRound_DashCap:
850 return DashingCircleEffect::Create(edgeType, info, SkScalarHalf(stro keWidth)); 862 return DashingCircleEffect::Create(edgeType, info, SkScalarHalf(stro keWidth));
851 case GrDashingEffect::kNonRound_DashCap: 863 case GrDashingEffect::kNonRound_DashCap:
852 return DashingLineEffect::Create(edgeType, info, strokeWidth); 864 return DashingLineEffect::Create(edgeType, info, strokeWidth);
853 default: 865 default:
854 SkFAIL("Unexpected dashed cap."); 866 SkFAIL("Unexpected dashed cap.");
855 } 867 }
856 return NULL; 868 return NULL;
857 } 869 }
OLDNEW
« no previous file with comments | « src/gpu/effects/GrCustomCoordsTextureEffect.cpp ('k') | src/gpu/effects/GrDistanceFieldTextureEffect.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698