| OLD | NEW |
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2012 Google Inc. | 3 * Copyright 2012 Google Inc. |
| 4 * | 4 * |
| 5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
| 6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
| 7 */ | 7 */ |
| 8 | 8 |
| 9 #include "GrAAConvexPathRenderer.h" | 9 #include "GrAAConvexPathRenderer.h" |
| 10 | 10 |
| (...skipping 487 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 498 * distance with negative being inside, positive outside. The edge is specified
in | 498 * distance with negative being inside, positive outside. The edge is specified
in |
| 499 * window space (y-down). If either the third or fourth component of the interpo
lated | 499 * window space (y-down). If either the third or fourth component of the interpo
lated |
| 500 * vertex coord is > 0 then the pixel is considered outside the edge. This is us
ed to | 500 * vertex coord is > 0 then the pixel is considered outside the edge. This is us
ed to |
| 501 * attempt to trim to a portion of the infinite quad. | 501 * attempt to trim to a portion of the infinite quad. |
| 502 * Requires shader derivative instruction support. | 502 * Requires shader derivative instruction support. |
| 503 */ | 503 */ |
| 504 | 504 |
| 505 class QuadEdgeEffect : public GrGeometryProcessor { | 505 class QuadEdgeEffect : public GrGeometryProcessor { |
| 506 public: | 506 public: |
| 507 | 507 |
| 508 static GrGeometryProcessor* Create(GrColor color, const SkMatrix& localMatri
x) { | 508 static GrGeometryProcessor* Create(GrColor color, |
| 509 return SkNEW_ARGS(QuadEdgeEffect, (color, localMatrix)); | 509 const SkMatrix& viewMatrix, |
| 510 const SkMatrix& localMatrix) { |
| 511 return SkNEW_ARGS(QuadEdgeEffect, (color, viewMatrix, localMatrix)); |
| 510 } | 512 } |
| 511 | 513 |
| 512 virtual ~QuadEdgeEffect() {} | 514 virtual ~QuadEdgeEffect() {} |
| 513 | 515 |
| 514 virtual const char* name() const SK_OVERRIDE { return "QuadEdge"; } | 516 virtual const char* name() const SK_OVERRIDE { return "QuadEdge"; } |
| 515 | 517 |
| 516 const GrAttribute* inPosition() const { return fInPosition; } | 518 const GrAttribute* inPosition() const { return fInPosition; } |
| 517 const GrAttribute* inQuadEdge() const { return fInQuadEdge; } | 519 const GrAttribute* inQuadEdge() const { return fInQuadEdge; } |
| 518 | 520 |
| 519 class GLProcessor : public GrGLGeometryProcessor { | 521 class GLProcessor : public GrGLGeometryProcessor { |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 619 const GrBatchTracker& t) const SK_OVERRIDE { | 621 const GrBatchTracker& t) const SK_OVERRIDE { |
| 620 const BatchTracker& mine = m.cast<BatchTracker>(); | 622 const BatchTracker& mine = m.cast<BatchTracker>(); |
| 621 const BatchTracker& theirs = t.cast<BatchTracker>(); | 623 const BatchTracker& theirs = t.cast<BatchTracker>(); |
| 622 return CanCombineLocalMatrices(*this, mine.fUsesLocalCoords, | 624 return CanCombineLocalMatrices(*this, mine.fUsesLocalCoords, |
| 623 that, theirs.fUsesLocalCoords) && | 625 that, theirs.fUsesLocalCoords) && |
| 624 CanCombineOutput(mine.fInputColorType, mine.fColor, | 626 CanCombineOutput(mine.fInputColorType, mine.fColor, |
| 625 theirs.fInputColorType, theirs.fColor); | 627 theirs.fInputColorType, theirs.fColor); |
| 626 } | 628 } |
| 627 | 629 |
| 628 private: | 630 private: |
| 629 QuadEdgeEffect(GrColor color, const SkMatrix& localMatrix) | 631 QuadEdgeEffect(GrColor color, const SkMatrix& viewMatrix, const SkMatrix& lo
calMatrix) |
| 630 : INHERITED(color, false, localMatrix) { | 632 : INHERITED(color, viewMatrix, localMatrix) { |
| 631 this->initClassID<QuadEdgeEffect>(); | 633 this->initClassID<QuadEdgeEffect>(); |
| 632 fInPosition = &this->addVertexAttrib(GrAttribute("inPosition", kVec2f_Gr
VertexAttribType)); | 634 fInPosition = &this->addVertexAttrib(GrAttribute("inPosition", kVec2f_Gr
VertexAttribType)); |
| 633 fInQuadEdge = &this->addVertexAttrib(GrAttribute("inQuadEdge", kVec4f_Gr
VertexAttribType)); | 635 fInQuadEdge = &this->addVertexAttrib(GrAttribute("inQuadEdge", kVec4f_Gr
VertexAttribType)); |
| 634 } | 636 } |
| 635 | 637 |
| 636 virtual bool onIsEqual(const GrGeometryProcessor& other) const SK_OVERRIDE { | 638 virtual bool onIsEqual(const GrGeometryProcessor& other) const SK_OVERRIDE { |
| 637 return true; | 639 return true; |
| 638 } | 640 } |
| 639 | 641 |
| 640 virtual void onGetInvariantOutputCoverage(GrInitInvariantOutput* out) const
SK_OVERRIDE { | 642 virtual void onGetInvariantOutputCoverage(GrInitInvariantOutput* out) const
SK_OVERRIDE { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 657 | 659 |
| 658 GR_DEFINE_GEOMETRY_PROCESSOR_TEST(QuadEdgeEffect); | 660 GR_DEFINE_GEOMETRY_PROCESSOR_TEST(QuadEdgeEffect); |
| 659 | 661 |
| 660 GrGeometryProcessor* QuadEdgeEffect::TestCreate(SkRandom* random, | 662 GrGeometryProcessor* QuadEdgeEffect::TestCreate(SkRandom* random, |
| 661 GrContext*, | 663 GrContext*, |
| 662 const GrDrawTargetCaps& caps, | 664 const GrDrawTargetCaps& caps, |
| 663 GrTexture*[]) { | 665 GrTexture*[]) { |
| 664 // Doesn't work without derivative instructions. | 666 // Doesn't work without derivative instructions. |
| 665 return caps.shaderDerivativeSupport() ? | 667 return caps.shaderDerivativeSupport() ? |
| 666 QuadEdgeEffect::Create(GrRandomColor(random), | 668 QuadEdgeEffect::Create(GrRandomColor(random), |
| 669 GrProcessorUnitTest::TestMatrix(random), |
| 667 GrProcessorUnitTest::TestMatrix(random)) : NUL
L; | 670 GrProcessorUnitTest::TestMatrix(random)) : NUL
L; |
| 668 } | 671 } |
| 669 | 672 |
| 670 /////////////////////////////////////////////////////////////////////////////// | 673 /////////////////////////////////////////////////////////////////////////////// |
| 671 | 674 |
| 672 bool GrAAConvexPathRenderer::canDrawPath(const GrDrawTarget* target, | 675 bool GrAAConvexPathRenderer::canDrawPath(const GrDrawTarget* target, |
| 673 const GrDrawState*, | 676 const GrDrawState*, |
| 677 const SkMatrix& viewMatrix, |
| 674 const SkPath& path, | 678 const SkPath& path, |
| 675 const SkStrokeRec& stroke, | 679 const SkStrokeRec& stroke, |
| 676 bool antiAlias) const { | 680 bool antiAlias) const { |
| 677 return (target->caps()->shaderDerivativeSupport() && antiAlias && | 681 return (target->caps()->shaderDerivativeSupport() && antiAlias && |
| 678 stroke.isFillStyle() && !path.isInverseFillType() && path.isConvex()
); | 682 stroke.isFillStyle() && !path.isInverseFillType() && path.isConvex()
); |
| 679 } | 683 } |
| 680 | 684 |
| 681 bool GrAAConvexPathRenderer::onDrawPath(GrDrawTarget* target, | 685 bool GrAAConvexPathRenderer::onDrawPath(GrDrawTarget* target, |
| 682 GrDrawState* drawState, | 686 GrDrawState* drawState, |
| 683 GrColor color, | 687 GrColor color, |
| 688 const SkMatrix& vm, |
| 684 const SkPath& origPath, | 689 const SkPath& origPath, |
| 685 const SkStrokeRec&, | 690 const SkStrokeRec&, |
| 686 bool antiAlias) { | 691 bool antiAlias) { |
| 687 | 692 |
| 688 const SkPath* path = &origPath; | 693 const SkPath* path = &origPath; |
| 689 if (path->isEmpty()) { | 694 if (path->isEmpty()) { |
| 690 return true; | 695 return true; |
| 691 } | 696 } |
| 692 | 697 |
| 693 SkMatrix viewMatrix = drawState->getViewMatrix(); | 698 SkMatrix viewMatrix = vm; |
| 694 SkMatrix invert; | 699 SkMatrix invert; |
| 695 if (!viewMatrix.invert(&invert)) { | 700 if (!viewMatrix.invert(&invert)) { |
| 696 return false; | 701 return false; |
| 697 } | 702 } |
| 698 | 703 |
| 699 GrDrawState::AutoViewMatrixRestore avmr(drawState); | |
| 700 | |
| 701 // We use the fact that SkPath::transform path does subdivision based on | 704 // We use the fact that SkPath::transform path does subdivision based on |
| 702 // perspective. Otherwise, we apply the view matrix when copying to the | 705 // perspective. Otherwise, we apply the view matrix when copying to the |
| 703 // segment representation. | 706 // segment representation. |
| 704 SkPath tmpPath; | 707 SkPath tmpPath; |
| 705 if (viewMatrix.hasPerspective()) { | 708 if (viewMatrix.hasPerspective()) { |
| 706 origPath.transform(viewMatrix, &tmpPath); | 709 origPath.transform(viewMatrix, &tmpPath); |
| 707 path = &tmpPath; | 710 path = &tmpPath; |
| 708 viewMatrix = SkMatrix::I(); | 711 viewMatrix = SkMatrix::I(); |
| 709 } | 712 } |
| 710 | 713 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 723 // We can't simply use the path bounds because we may degenerate cubics to q
uads which produces | 726 // We can't simply use the path bounds because we may degenerate cubics to q
uads which produces |
| 724 // new control points outside the original convex hull. | 727 // new control points outside the original convex hull. |
| 725 SkRect devBounds; | 728 SkRect devBounds; |
| 726 if (!get_segments(*path, viewMatrix, &segments, &fanPt, &vCount, &iCount, &d
evBounds)) { | 729 if (!get_segments(*path, viewMatrix, &segments, &fanPt, &vCount, &iCount, &d
evBounds)) { |
| 727 return false; | 730 return false; |
| 728 } | 731 } |
| 729 | 732 |
| 730 // Our computed verts should all be within one pixel of the segment control
points. | 733 // Our computed verts should all be within one pixel of the segment control
points. |
| 731 devBounds.outset(SK_Scalar1, SK_Scalar1); | 734 devBounds.outset(SK_Scalar1, SK_Scalar1); |
| 732 | 735 |
| 733 SkAutoTUnref<GrGeometryProcessor> quadProcessor(QuadEdgeEffect::Create(color
, invert)); | 736 SkAutoTUnref<GrGeometryProcessor> quadProcessor(QuadEdgeEffect::Create(color
, |
| 737 SkMat
rix::I(), |
| 738 inver
t)); |
| 734 | 739 |
| 735 GrDrawTarget::AutoReleaseGeometry arg(target, vCount, quadProcessor->getVert
exStride(), iCount); | 740 GrDrawTarget::AutoReleaseGeometry arg(target, vCount, quadProcessor->getVert
exStride(), iCount); |
| 736 SkASSERT(quadProcessor->getVertexStride() == sizeof(QuadVertex)); | 741 SkASSERT(quadProcessor->getVertexStride() == sizeof(QuadVertex)); |
| 737 if (!arg.succeeded()) { | 742 if (!arg.succeeded()) { |
| 738 return false; | 743 return false; |
| 739 } | 744 } |
| 740 verts = reinterpret_cast<QuadVertex*>(arg.vertices()); | 745 verts = reinterpret_cast<QuadVertex*>(arg.vertices()); |
| 741 idxs = reinterpret_cast<uint16_t*>(arg.indices()); | 746 idxs = reinterpret_cast<uint16_t*>(arg.indices()); |
| 742 | 747 |
| 743 SkSTArray<kPreallocDrawCnt, Draw, true> draws; | 748 SkSTArray<kPreallocDrawCnt, Draw, true> draws; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 764 vOffset, // start vertex | 769 vOffset, // start vertex |
| 765 0, // start index | 770 0, // start index |
| 766 draw.fVertexCnt, | 771 draw.fVertexCnt, |
| 767 draw.fIndexCnt, | 772 draw.fIndexCnt, |
| 768 &devBounds); | 773 &devBounds); |
| 769 vOffset += draw.fVertexCnt; | 774 vOffset += draw.fVertexCnt; |
| 770 } | 775 } |
| 771 | 776 |
| 772 return true; | 777 return true; |
| 773 } | 778 } |
| OLD | NEW |