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 584 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
595 bool GrAAConvexPathRenderer::onDrawPath(const SkPath& origPath, | 595 bool GrAAConvexPathRenderer::onDrawPath(const SkPath& origPath, |
596 const SkStrokeRec&, | 596 const SkStrokeRec&, |
597 GrDrawTarget* target, | 597 GrDrawTarget* target, |
598 bool antiAlias) { | 598 bool antiAlias) { |
599 | 599 |
600 const SkPath* path = &origPath; | 600 const SkPath* path = &origPath; |
601 if (path->isEmpty()) { | 601 if (path->isEmpty()) { |
602 return true; | 602 return true; |
603 } | 603 } |
604 | 604 |
605 GrDrawTarget::AutoStateRestore asr(target, GrDrawTarget::kPreserve_ASRInit); | 605 SkMatrix viewMatrix = target->getDrawState().getViewMatrix(); |
606 GrDrawState* drawState = target->drawState(); | 606 GrDrawTarget::AutoStateRestore asr; |
607 | 607 if (!asr.setIdentity(target, GrDrawTarget::kPreserve_ASRInit)) { |
608 GrDrawState::AutoDeviceCoordDraw adcd(drawState); | |
609 if (!adcd.succeeded()) { | |
610 return false; | 608 return false; |
611 } | 609 } |
612 const SkMatrix* vm = &adcd.getOriginalMatrix(); | 610 GrDrawState* drawState = target->drawState(); |
613 | 611 |
614 // We use the fact that SkPath::transform path does subdivision based on | 612 // We use the fact that SkPath::transform path does subdivision based on |
615 // perspective. Otherwise, we apply the view matrix when copying to the | 613 // perspective. Otherwise, we apply the view matrix when copying to the |
616 // segment representation. | 614 // segment representation. |
617 SkPath tmpPath; | 615 SkPath tmpPath; |
618 if (vm->hasPerspective()) { | 616 if (viewMatrix.hasPerspective()) { |
619 origPath.transform(*vm, &tmpPath); | 617 origPath.transform(viewMatrix, &tmpPath); |
620 path = &tmpPath; | 618 path = &tmpPath; |
621 vm = &SkMatrix::I(); | 619 viewMatrix = SkMatrix::I(); |
622 } | 620 } |
623 | 621 |
624 QuadVertex *verts; | 622 QuadVertex *verts; |
625 uint16_t* idxs; | 623 uint16_t* idxs; |
626 | 624 |
627 int vCount; | 625 int vCount; |
628 int iCount; | 626 int iCount; |
629 enum { | 627 enum { |
630 kPreallocSegmentCnt = 512 / sizeof(Segment), | 628 kPreallocSegmentCnt = 512 / sizeof(Segment), |
631 kPreallocDrawCnt = 4, | 629 kPreallocDrawCnt = 4, |
632 }; | 630 }; |
633 SkSTArray<kPreallocSegmentCnt, Segment, true> segments; | 631 SkSTArray<kPreallocSegmentCnt, Segment, true> segments; |
634 SkPoint fanPt; | 632 SkPoint fanPt; |
635 | 633 |
636 if (!get_segments(*path, *vm, &segments, &fanPt, &vCount, &iCount)) { | 634 if (!get_segments(*path, viewMatrix, &segments, &fanPt, &vCount, &iCount)) { |
637 return false; | 635 return false; |
638 } | 636 } |
639 | 637 |
640 drawState->setVertexAttribs<gPathAttribs>(SK_ARRAY_COUNT(gPathAttribs)); | 638 drawState->setVertexAttribs<gPathAttribs>(SK_ARRAY_COUNT(gPathAttribs)); |
641 | 639 |
642 enum { | 640 enum { |
643 // the edge effects share this stage with glyph rendering | 641 // the edge effects share this stage with glyph rendering |
644 // (kGlyphMaskStage in GrTextContext) && SW path rendering | 642 // (kGlyphMaskStage in GrTextContext) && SW path rendering |
645 // (kPathMaskStage in GrSWMaskHelper) | 643 // (kPathMaskStage in GrSWMaskHelper) |
646 kEdgeEffectStage = GrPaint::kTotalStages, | 644 kEdgeEffectStage = GrPaint::kTotalStages, |
647 }; | 645 }; |
648 static const int kEdgeAttrIndex = 1; | 646 static const int kEdgeAttrIndex = 1; |
649 GrEffectRef* quadEffect = QuadEdgeEffect::Create(); | 647 GrEffectRef* quadEffect = QuadEdgeEffect::Create(); |
650 drawState->setEffect(kEdgeEffectStage, quadEffect, kEdgeAttrIndex)->unref(); | 648 drawState->setEffect(kEdgeEffectStage, quadEffect, kEdgeAttrIndex)->unref(); |
651 | 649 |
652 GrDrawTarget::AutoReleaseGeometry arg(target, vCount, iCount); | 650 GrDrawTarget::AutoReleaseGeometry arg(target, vCount, iCount); |
653 if (!arg.succeeded()) { | 651 if (!arg.succeeded()) { |
654 return false; | 652 return false; |
655 } | 653 } |
656 GrAssert(sizeof(QuadVertex) == drawState->getVertexSize()); | 654 GrAssert(sizeof(QuadVertex) == drawState->getVertexSize()); |
657 verts = reinterpret_cast<QuadVertex*>(arg.vertices()); | 655 verts = reinterpret_cast<QuadVertex*>(arg.vertices()); |
658 idxs = reinterpret_cast<uint16_t*>(arg.indices()); | 656 idxs = reinterpret_cast<uint16_t*>(arg.indices()); |
659 | 657 |
660 SkSTArray<kPreallocDrawCnt, Draw, true> draws; | 658 SkSTArray<kPreallocDrawCnt, Draw, true> draws; |
661 create_vertices(segments, fanPt, &draws, verts, idxs); | 659 create_vertices(segments, fanPt, &draws, verts, idxs); |
662 | 660 |
663 // This is valid because all the computed verts are within 1 pixel of the pa
th control points. | 661 // This is valid because all the computed verts are within 1 pixel of the pa
th control points. |
664 SkRect devBounds; | 662 SkRect devBounds; |
665 devBounds = origPath.getBounds(); | 663 devBounds = path->getBounds(); |
666 adcd.getOriginalMatrix().mapRect(&devBounds); | 664 viewMatrix.mapRect(&devBounds); |
667 devBounds.outset(SK_Scalar1, SK_Scalar1); | 665 devBounds.outset(SK_Scalar1, SK_Scalar1); |
668 | 666 |
669 // Check devBounds | 667 // Check devBounds |
670 #if GR_DEBUG | 668 #if GR_DEBUG |
671 SkRect tolDevBounds = devBounds; | 669 SkRect tolDevBounds = devBounds; |
672 tolDevBounds.outset(SK_Scalar1 / 10000, SK_Scalar1 / 10000); | 670 tolDevBounds.outset(SK_Scalar1 / 10000, SK_Scalar1 / 10000); |
673 SkRect actualBounds; | 671 SkRect actualBounds; |
674 actualBounds.set(verts[0].fPos, verts[1].fPos); | 672 actualBounds.set(verts[0].fPos, verts[1].fPos); |
675 for (int i = 2; i < vCount; ++i) { | 673 for (int i = 2; i < vCount; ++i) { |
676 actualBounds.growToInclude(verts[i].fPos.fX, verts[i].fPos.fY); | 674 actualBounds.growToInclude(verts[i].fPos.fX, verts[i].fPos.fY); |
677 } | 675 } |
678 GrAssert(tolDevBounds.contains(actualBounds)); | 676 GrAssert(tolDevBounds.contains(actualBounds)); |
679 #endif | 677 #endif |
680 | 678 |
681 int vOffset = 0; | 679 int vOffset = 0; |
682 for (int i = 0; i < draws.count(); ++i) { | 680 for (int i = 0; i < draws.count(); ++i) { |
683 const Draw& draw = draws[i]; | 681 const Draw& draw = draws[i]; |
684 target->drawIndexed(kTriangles_GrPrimitiveType, | 682 target->drawIndexed(kTriangles_GrPrimitiveType, |
685 vOffset, // start vertex | 683 vOffset, // start vertex |
686 0, // start index | 684 0, // start index |
687 draw.fVertexCnt, | 685 draw.fVertexCnt, |
688 draw.fIndexCnt, | 686 draw.fIndexCnt, |
689 &devBounds); | 687 &devBounds); |
690 vOffset += draw.fVertexCnt; | 688 vOffset += draw.fVertexCnt; |
691 } | 689 } |
692 | 690 |
693 return true; | 691 return true; |
694 } | 692 } |
OLD | NEW |