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 591 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
602 GrGeometryProcessor* QuadEdgeEffect::TestCreate(SkRandom* random, | 602 GrGeometryProcessor* QuadEdgeEffect::TestCreate(SkRandom* random, |
603 GrContext*, | 603 GrContext*, |
604 const GrDrawTargetCaps& caps, | 604 const GrDrawTargetCaps& caps, |
605 GrTexture*[]) { | 605 GrTexture*[]) { |
606 // Doesn't work without derivative instructions. | 606 // Doesn't work without derivative instructions. |
607 return caps.shaderDerivativeSupport() ? QuadEdgeEffect::Create() : NULL; | 607 return caps.shaderDerivativeSupport() ? QuadEdgeEffect::Create() : NULL; |
608 } | 608 } |
609 | 609 |
610 /////////////////////////////////////////////////////////////////////////////// | 610 /////////////////////////////////////////////////////////////////////////////// |
611 | 611 |
612 bool GrAAConvexPathRenderer::canDrawPath(const SkPath& path, | 612 bool GrAAConvexPathRenderer::canDrawPath(const GrDrawTarget* target, |
| 613 const GrDrawState*, |
| 614 const SkPath& path, |
613 const SkStrokeRec& stroke, | 615 const SkStrokeRec& stroke, |
614 const GrDrawTarget* target, | |
615 bool antiAlias) const { | 616 bool antiAlias) const { |
616 return (target->caps()->shaderDerivativeSupport() && antiAlias && | 617 return (target->caps()->shaderDerivativeSupport() && antiAlias && |
617 stroke.isFillStyle() && !path.isInverseFillType() && path.isConvex()
); | 618 stroke.isFillStyle() && !path.isInverseFillType() && path.isConvex()
); |
618 } | 619 } |
619 | 620 |
620 namespace { | 621 namespace { |
621 | 622 |
622 // position + edge | 623 // position + edge |
623 extern const GrVertexAttrib gPathAttribs[] = { | 624 extern const GrVertexAttrib gPathAttribs[] = { |
624 {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBinding
}, | 625 {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBinding
}, |
625 {kVec4f_GrVertexAttribType, sizeof(SkPoint), kGeometryProcessor_GrVertexAttr
ibBinding} | 626 {kVec4f_GrVertexAttribType, sizeof(SkPoint), kGeometryProcessor_GrVertexAttr
ibBinding} |
626 }; | 627 }; |
627 | 628 |
628 }; | 629 }; |
629 | 630 |
630 bool GrAAConvexPathRenderer::onDrawPath(const SkPath& origPath, | 631 bool GrAAConvexPathRenderer::onDrawPath(GrDrawTarget* target, |
| 632 GrDrawState* drawState, |
| 633 const SkPath& origPath, |
631 const SkStrokeRec&, | 634 const SkStrokeRec&, |
632 GrDrawTarget* target, | |
633 bool antiAlias) { | 635 bool antiAlias) { |
634 | 636 |
635 const SkPath* path = &origPath; | 637 const SkPath* path = &origPath; |
636 if (path->isEmpty()) { | 638 if (path->isEmpty()) { |
637 return true; | 639 return true; |
638 } | 640 } |
639 | 641 |
640 SkMatrix viewMatrix = target->getDrawState().getViewMatrix(); | 642 SkMatrix viewMatrix = drawState->getViewMatrix(); |
641 GrDrawTarget::AutoStateRestore asr; | 643 if (!drawState->setIdentityViewMatrix()) { |
642 if (!asr.setIdentity(target, GrDrawTarget::kPreserve_ASRInit)) { | |
643 return false; | 644 return false; |
644 } | 645 } |
645 GrDrawState* drawState = target->drawState(); | |
646 | 646 |
647 // We use the fact that SkPath::transform path does subdivision based on | 647 // We use the fact that SkPath::transform path does subdivision based on |
648 // perspective. Otherwise, we apply the view matrix when copying to the | 648 // perspective. Otherwise, we apply the view matrix when copying to the |
649 // segment representation. | 649 // segment representation. |
650 SkPath tmpPath; | 650 SkPath tmpPath; |
651 if (viewMatrix.hasPerspective()) { | 651 if (viewMatrix.hasPerspective()) { |
652 origPath.transform(viewMatrix, &tmpPath); | 652 origPath.transform(viewMatrix, &tmpPath); |
653 path = &tmpPath; | 653 path = &tmpPath; |
654 viewMatrix = SkMatrix::I(); | 654 viewMatrix = SkMatrix::I(); |
655 } | 655 } |
(...skipping 18 matching lines...) Expand all Loading... |
674 } | 674 } |
675 | 675 |
676 // Our computed verts should all be within one pixel of the segment control
points. | 676 // Our computed verts should all be within one pixel of the segment control
points. |
677 devBounds.outset(SK_Scalar1, SK_Scalar1); | 677 devBounds.outset(SK_Scalar1, SK_Scalar1); |
678 | 678 |
679 drawState->setVertexAttribs<gPathAttribs>(SK_ARRAY_COUNT(gPathAttribs), size
of(QuadVertex)); | 679 drawState->setVertexAttribs<gPathAttribs>(SK_ARRAY_COUNT(gPathAttribs), size
of(QuadVertex)); |
680 | 680 |
681 GrGeometryProcessor* quadProcessor = QuadEdgeEffect::Create(); | 681 GrGeometryProcessor* quadProcessor = QuadEdgeEffect::Create(); |
682 drawState->setGeometryProcessor(quadProcessor)->unref(); | 682 drawState->setGeometryProcessor(quadProcessor)->unref(); |
683 | 683 |
684 GrDrawTarget::AutoReleaseGeometry arg(target, vCount, iCount); | 684 GrDrawTarget::AutoReleaseGeometry arg(target, vCount, drawState->getVertexSt
ride(), iCount); |
685 if (!arg.succeeded()) { | 685 if (!arg.succeeded()) { |
686 return false; | 686 return false; |
687 } | 687 } |
688 verts = reinterpret_cast<QuadVertex*>(arg.vertices()); | 688 verts = reinterpret_cast<QuadVertex*>(arg.vertices()); |
689 idxs = reinterpret_cast<uint16_t*>(arg.indices()); | 689 idxs = reinterpret_cast<uint16_t*>(arg.indices()); |
690 | 690 |
691 SkSTArray<kPreallocDrawCnt, Draw, true> draws; | 691 SkSTArray<kPreallocDrawCnt, Draw, true> draws; |
692 create_vertices(segments, fanPt, &draws, verts, idxs); | 692 create_vertices(segments, fanPt, &draws, verts, idxs); |
693 | 693 |
694 // Check devBounds | 694 // Check devBounds |
695 #ifdef SK_DEBUG | 695 #ifdef SK_DEBUG |
696 SkRect tolDevBounds = devBounds; | 696 SkRect tolDevBounds = devBounds; |
697 tolDevBounds.outset(SK_Scalar1 / 10000, SK_Scalar1 / 10000); | 697 tolDevBounds.outset(SK_Scalar1 / 10000, SK_Scalar1 / 10000); |
698 SkRect actualBounds; | 698 SkRect actualBounds; |
699 actualBounds.set(verts[0].fPos, verts[1].fPos); | 699 actualBounds.set(verts[0].fPos, verts[1].fPos); |
700 for (int i = 2; i < vCount; ++i) { | 700 for (int i = 2; i < vCount; ++i) { |
701 actualBounds.growToInclude(verts[i].fPos.fX, verts[i].fPos.fY); | 701 actualBounds.growToInclude(verts[i].fPos.fX, verts[i].fPos.fY); |
702 } | 702 } |
703 SkASSERT(tolDevBounds.contains(actualBounds)); | 703 SkASSERT(tolDevBounds.contains(actualBounds)); |
704 #endif | 704 #endif |
705 | 705 |
706 int vOffset = 0; | 706 int vOffset = 0; |
707 for (int i = 0; i < draws.count(); ++i) { | 707 for (int i = 0; i < draws.count(); ++i) { |
708 const Draw& draw = draws[i]; | 708 const Draw& draw = draws[i]; |
709 target->drawIndexed(kTriangles_GrPrimitiveType, | 709 target->drawIndexed(drawState, |
| 710 kTriangles_GrPrimitiveType, |
710 vOffset, // start vertex | 711 vOffset, // start vertex |
711 0, // start index | 712 0, // start index |
712 draw.fVertexCnt, | 713 draw.fVertexCnt, |
713 draw.fIndexCnt, | 714 draw.fIndexCnt, |
714 &devBounds); | 715 &devBounds); |
715 vOffset += draw.fVertexCnt; | 716 vOffset += draw.fVertexCnt; |
716 } | 717 } |
717 | 718 |
718 return true; | 719 return true; |
719 } | 720 } |
OLD | NEW |