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