OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 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 "GrOvalRenderer.h" | 8 #include "GrOvalRenderer.h" |
9 | 9 |
10 #include "gl/builders/GrGLProgramBuilder.h" | 10 #include "gl/builders/GrGLProgramBuilder.h" |
(...skipping 479 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
490 | 490 |
491 if (!useCoverageAA) { | 491 if (!useCoverageAA) { |
492 return false; | 492 return false; |
493 } | 493 } |
494 | 494 |
495 const SkMatrix& vm = context->getMatrix(); | 495 const SkMatrix& vm = context->getMatrix(); |
496 | 496 |
497 // we can draw circles | 497 // we can draw circles |
498 if (SkScalarNearlyEqual(oval.width(), oval.height()) | 498 if (SkScalarNearlyEqual(oval.width(), oval.height()) |
499 && circle_stays_circle(vm)) { | 499 && circle_stays_circle(vm)) { |
500 this->drawCircle(target, useCoverageAA, oval, stroke); | 500 this->drawCircle(target, context, useCoverageAA, oval, stroke); |
501 // if we have shader derivative support, render as device-independent | 501 // if we have shader derivative support, render as device-independent |
502 } else if (target->caps()->shaderDerivativeSupport()) { | 502 } else if (target->caps()->shaderDerivativeSupport()) { |
503 return this->drawDIEllipse(target, useCoverageAA, oval, stroke); | 503 return this->drawDIEllipse(target, context, useCoverageAA, oval, stroke)
; |
504 // otherwise axis-aligned ellipses only | 504 // otherwise axis-aligned ellipses only |
505 } else if (vm.rectStaysRect()) { | 505 } else if (vm.rectStaysRect()) { |
506 return this->drawEllipse(target, useCoverageAA, oval, stroke); | 506 return this->drawEllipse(target, context, useCoverageAA, oval, stroke); |
507 } else { | 507 } else { |
508 return false; | 508 return false; |
509 } | 509 } |
510 | 510 |
511 return true; | 511 return true; |
512 } | 512 } |
513 | 513 |
514 /////////////////////////////////////////////////////////////////////////////// | 514 /////////////////////////////////////////////////////////////////////////////// |
515 | 515 |
516 // position + edge | 516 // position + edge |
517 extern const GrVertexAttrib gCircleVertexAttribs[] = { | 517 extern const GrVertexAttrib gCircleVertexAttribs[] = { |
518 {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBinding
}, | 518 {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBinding
}, |
519 {kVec4f_GrVertexAttribType, sizeof(SkPoint), kGeometryProcessor_GrVertexAttr
ibBinding} | 519 {kVec4f_GrVertexAttribType, sizeof(SkPoint), kGeometryProcessor_GrVertexAttr
ibBinding} |
520 }; | 520 }; |
521 | 521 |
522 void GrOvalRenderer::drawCircle(GrDrawTarget* target, | 522 void GrOvalRenderer::drawCircle(GrDrawTarget* target, |
| 523 const GrContext* context, |
523 bool useCoverageAA, | 524 bool useCoverageAA, |
524 const SkRect& circle, | 525 const SkRect& circle, |
525 const SkStrokeRec& stroke) | 526 const SkStrokeRec& stroke) |
526 { | 527 { |
527 GrDrawState* drawState = target->drawState(); | 528 GrDrawState* drawState = target->drawState(); |
528 | 529 |
529 const SkMatrix& vm = drawState->getViewMatrix(); | 530 const SkMatrix& vm = drawState->getViewMatrix(); |
530 SkPoint center = SkPoint::Make(circle.centerX(), circle.centerY()); | 531 SkPoint center = SkPoint::Make(circle.centerX(), circle.centerY()); |
531 vm.mapPoints(¢er, 1); | 532 vm.mapPoints(¢er, 1); |
532 SkScalar radius = vm.mapRadius(SkScalarHalf(circle.width())); | 533 SkScalar radius = vm.mapRadius(SkScalarHalf(circle.width())); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
584 center.fY - outerRadius, | 585 center.fY - outerRadius, |
585 center.fX + outerRadius, | 586 center.fX + outerRadius, |
586 center.fY + outerRadius | 587 center.fY + outerRadius |
587 ); | 588 ); |
588 | 589 |
589 verts[0].fPos = SkPoint::Make(bounds.fLeft, bounds.fTop); | 590 verts[0].fPos = SkPoint::Make(bounds.fLeft, bounds.fTop); |
590 verts[0].fOffset = SkPoint::Make(-outerRadius, -outerRadius); | 591 verts[0].fOffset = SkPoint::Make(-outerRadius, -outerRadius); |
591 verts[0].fOuterRadius = outerRadius; | 592 verts[0].fOuterRadius = outerRadius; |
592 verts[0].fInnerRadius = innerRadius; | 593 verts[0].fInnerRadius = innerRadius; |
593 | 594 |
594 verts[1].fPos = SkPoint::Make(bounds.fRight, bounds.fTop); | 595 verts[1].fPos = SkPoint::Make(bounds.fLeft, bounds.fBottom); |
595 verts[1].fOffset = SkPoint::Make(outerRadius, -outerRadius); | 596 verts[1].fOffset = SkPoint::Make(-outerRadius, outerRadius); |
596 verts[1].fOuterRadius = outerRadius; | 597 verts[1].fOuterRadius = outerRadius; |
597 verts[1].fInnerRadius = innerRadius; | 598 verts[1].fInnerRadius = innerRadius; |
598 | 599 |
599 verts[2].fPos = SkPoint::Make(bounds.fLeft, bounds.fBottom); | 600 verts[2].fPos = SkPoint::Make(bounds.fRight, bounds.fBottom); |
600 verts[2].fOffset = SkPoint::Make(-outerRadius, outerRadius); | 601 verts[2].fOffset = SkPoint::Make(outerRadius, outerRadius); |
601 verts[2].fOuterRadius = outerRadius; | 602 verts[2].fOuterRadius = outerRadius; |
602 verts[2].fInnerRadius = innerRadius; | 603 verts[2].fInnerRadius = innerRadius; |
603 | 604 |
604 verts[3].fPos = SkPoint::Make(bounds.fRight, bounds.fBottom); | 605 verts[3].fPos = SkPoint::Make(bounds.fRight, bounds.fTop); |
605 verts[3].fOffset = SkPoint::Make(outerRadius, outerRadius); | 606 verts[3].fOffset = SkPoint::Make(outerRadius, -outerRadius); |
606 verts[3].fOuterRadius = outerRadius; | 607 verts[3].fOuterRadius = outerRadius; |
607 verts[3].fInnerRadius = innerRadius; | 608 verts[3].fInnerRadius = innerRadius; |
608 | 609 |
609 target->drawNonIndexed(kTriangleStrip_GrPrimitiveType, 0, 4, &bounds); | 610 target->setIndexSourceToBuffer(context->getGpu()->getQuadIndexBuffer()); |
| 611 target->drawIndexedInstances(kTriangles_GrPrimitiveType, 1, 4, 6, &bounds); |
| 612 target->resetIndexSource(); |
610 } | 613 } |
611 | 614 |
612 /////////////////////////////////////////////////////////////////////////////// | 615 /////////////////////////////////////////////////////////////////////////////// |
613 | 616 |
614 // position + offset + 1/radii | 617 // position + offset + 1/radii |
615 extern const GrVertexAttrib gEllipseVertexAttribs[] = { | 618 extern const GrVertexAttrib gEllipseVertexAttribs[] = { |
616 {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBindi
ng}, | 619 {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBindi
ng}, |
617 {kVec2f_GrVertexAttribType, sizeof(SkPoint), kGeometryProcessor_GrVertexAt
tribBinding}, | 620 {kVec2f_GrVertexAttribType, sizeof(SkPoint), kGeometryProcessor_GrVertexAt
tribBinding}, |
618 {kVec4f_GrVertexAttribType, 2*sizeof(SkPoint), kGeometryProcessor_GrVertexAt
tribBinding} | 621 {kVec4f_GrVertexAttribType, 2*sizeof(SkPoint), kGeometryProcessor_GrVertexAt
tribBinding} |
619 }; | 622 }; |
620 | 623 |
621 // position + offsets | 624 // position + offsets |
622 extern const GrVertexAttrib gDIEllipseVertexAttribs[] = { | 625 extern const GrVertexAttrib gDIEllipseVertexAttribs[] = { |
623 {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBindi
ng}, | 626 {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBindi
ng}, |
624 {kVec2f_GrVertexAttribType, sizeof(SkPoint), kGeometryProcessor_GrVertexAt
tribBinding}, | 627 {kVec2f_GrVertexAttribType, sizeof(SkPoint), kGeometryProcessor_GrVertexAt
tribBinding}, |
625 {kVec2f_GrVertexAttribType, 2*sizeof(SkPoint), kGeometryProcessor_GrVertexAt
tribBinding}, | 628 {kVec2f_GrVertexAttribType, 2*sizeof(SkPoint), kGeometryProcessor_GrVertexAt
tribBinding}, |
626 }; | 629 }; |
627 | 630 |
628 bool GrOvalRenderer::drawEllipse(GrDrawTarget* target, | 631 bool GrOvalRenderer::drawEllipse(GrDrawTarget* target, |
| 632 const GrContext* context, |
629 bool useCoverageAA, | 633 bool useCoverageAA, |
630 const SkRect& ellipse, | 634 const SkRect& ellipse, |
631 const SkStrokeRec& stroke) | 635 const SkStrokeRec& stroke) |
632 { | 636 { |
633 GrDrawState* drawState = target->drawState(); | 637 GrDrawState* drawState = target->drawState(); |
634 #ifdef SK_DEBUG | 638 #ifdef SK_DEBUG |
635 { | 639 { |
636 // we should have checked for this previously | 640 // we should have checked for this previously |
637 bool isAxisAlignedEllipse = drawState->getViewMatrix().rectStaysRect(); | 641 bool isAxisAlignedEllipse = drawState->getViewMatrix().rectStaysRect(); |
638 SkASSERT(useCoverageAA && isAxisAlignedEllipse); | 642 SkASSERT(useCoverageAA && isAxisAlignedEllipse); |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
730 center.fY - yRadius, | 734 center.fY - yRadius, |
731 center.fX + xRadius, | 735 center.fX + xRadius, |
732 center.fY + yRadius | 736 center.fY + yRadius |
733 ); | 737 ); |
734 | 738 |
735 verts[0].fPos = SkPoint::Make(bounds.fLeft, bounds.fTop); | 739 verts[0].fPos = SkPoint::Make(bounds.fLeft, bounds.fTop); |
736 verts[0].fOffset = SkPoint::Make(-xRadius, -yRadius); | 740 verts[0].fOffset = SkPoint::Make(-xRadius, -yRadius); |
737 verts[0].fOuterRadii = SkPoint::Make(xRadRecip, yRadRecip); | 741 verts[0].fOuterRadii = SkPoint::Make(xRadRecip, yRadRecip); |
738 verts[0].fInnerRadii = SkPoint::Make(xInnerRadRecip, yInnerRadRecip); | 742 verts[0].fInnerRadii = SkPoint::Make(xInnerRadRecip, yInnerRadRecip); |
739 | 743 |
740 verts[1].fPos = SkPoint::Make(bounds.fRight, bounds.fTop); | 744 verts[1].fPos = SkPoint::Make(bounds.fLeft, bounds.fBottom); |
741 verts[1].fOffset = SkPoint::Make(xRadius, -yRadius); | 745 verts[1].fOffset = SkPoint::Make(-xRadius, yRadius); |
742 verts[1].fOuterRadii = SkPoint::Make(xRadRecip, yRadRecip); | 746 verts[1].fOuterRadii = SkPoint::Make(xRadRecip, yRadRecip); |
743 verts[1].fInnerRadii = SkPoint::Make(xInnerRadRecip, yInnerRadRecip); | 747 verts[1].fInnerRadii = SkPoint::Make(xInnerRadRecip, yInnerRadRecip); |
744 | 748 |
745 verts[2].fPos = SkPoint::Make(bounds.fLeft, bounds.fBottom); | 749 verts[2].fPos = SkPoint::Make(bounds.fRight, bounds.fBottom); |
746 verts[2].fOffset = SkPoint::Make(-xRadius, yRadius); | 750 verts[2].fOffset = SkPoint::Make(xRadius, yRadius); |
747 verts[2].fOuterRadii = SkPoint::Make(xRadRecip, yRadRecip); | 751 verts[2].fOuterRadii = SkPoint::Make(xRadRecip, yRadRecip); |
748 verts[2].fInnerRadii = SkPoint::Make(xInnerRadRecip, yInnerRadRecip); | 752 verts[2].fInnerRadii = SkPoint::Make(xInnerRadRecip, yInnerRadRecip); |
749 | 753 |
750 verts[3].fPos = SkPoint::Make(bounds.fRight, bounds.fBottom); | 754 verts[3].fPos = SkPoint::Make(bounds.fRight, bounds.fTop); |
751 verts[3].fOffset = SkPoint::Make(xRadius, yRadius); | 755 verts[3].fOffset = SkPoint::Make(xRadius, -yRadius); |
752 verts[3].fOuterRadii = SkPoint::Make(xRadRecip, yRadRecip); | 756 verts[3].fOuterRadii = SkPoint::Make(xRadRecip, yRadRecip); |
753 verts[3].fInnerRadii = SkPoint::Make(xInnerRadRecip, yInnerRadRecip); | 757 verts[3].fInnerRadii = SkPoint::Make(xInnerRadRecip, yInnerRadRecip); |
754 | 758 |
755 target->drawNonIndexed(kTriangleStrip_GrPrimitiveType, 0, 4, &bounds); | 759 target->setIndexSourceToBuffer(context->getGpu()->getQuadIndexBuffer()); |
| 760 target->drawIndexedInstances(kTriangles_GrPrimitiveType, 1, 4, 6, &bounds); |
| 761 target->resetIndexSource(); |
756 | 762 |
757 return true; | 763 return true; |
758 } | 764 } |
759 | 765 |
760 bool GrOvalRenderer::drawDIEllipse(GrDrawTarget* target, | 766 bool GrOvalRenderer::drawDIEllipse(GrDrawTarget* target, |
| 767 const GrContext* context, |
761 bool useCoverageAA, | 768 bool useCoverageAA, |
762 const SkRect& ellipse, | 769 const SkRect& ellipse, |
763 const SkStrokeRec& stroke) | 770 const SkStrokeRec& stroke) |
764 { | 771 { |
765 GrDrawState* drawState = target->drawState(); | 772 GrDrawState* drawState = target->drawState(); |
766 const SkMatrix& vm = drawState->getViewMatrix(); | 773 const SkMatrix& vm = drawState->getViewMatrix(); |
767 | 774 |
768 SkPoint center = SkPoint::Make(ellipse.centerX(), ellipse.centerY()); | 775 SkPoint center = SkPoint::Make(ellipse.centerX(), ellipse.centerY()); |
769 SkScalar xRadius = SkScalarHalf(ellipse.width()); | 776 SkScalar xRadius = SkScalarHalf(ellipse.width()); |
770 SkScalar yRadius = SkScalarHalf(ellipse.height()); | 777 SkScalar yRadius = SkScalarHalf(ellipse.height()); |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
844 center.fX - xRadius - geoDx, | 851 center.fX - xRadius - geoDx, |
845 center.fY - yRadius - geoDy, | 852 center.fY - yRadius - geoDy, |
846 center.fX + xRadius + geoDx, | 853 center.fX + xRadius + geoDx, |
847 center.fY + yRadius + geoDy | 854 center.fY + yRadius + geoDy |
848 ); | 855 ); |
849 | 856 |
850 verts[0].fPos = SkPoint::Make(bounds.fLeft, bounds.fTop); | 857 verts[0].fPos = SkPoint::Make(bounds.fLeft, bounds.fTop); |
851 verts[0].fOuterOffset = SkPoint::Make(-1.0f - offsetDx, -1.0f - offsetDy); | 858 verts[0].fOuterOffset = SkPoint::Make(-1.0f - offsetDx, -1.0f - offsetDy); |
852 verts[0].fInnerOffset = SkPoint::Make(-innerRatioX - offsetDx, -innerRatioY
- offsetDy); | 859 verts[0].fInnerOffset = SkPoint::Make(-innerRatioX - offsetDx, -innerRatioY
- offsetDy); |
853 | 860 |
854 verts[1].fPos = SkPoint::Make(bounds.fRight, bounds.fTop); | 861 verts[1].fPos = SkPoint::Make(bounds.fLeft, bounds.fBottom); |
855 verts[1].fOuterOffset = SkPoint::Make(1.0f + offsetDx, -1.0f - offsetDy); | 862 verts[1].fOuterOffset = SkPoint::Make(-1.0f - offsetDx, 1.0f + offsetDy); |
856 verts[1].fInnerOffset = SkPoint::Make(innerRatioX + offsetDx, -innerRatioY -
offsetDy); | 863 verts[1].fInnerOffset = SkPoint::Make(-innerRatioX - offsetDx, innerRatioY +
offsetDy); |
857 | 864 |
858 verts[2].fPos = SkPoint::Make(bounds.fLeft, bounds.fBottom); | 865 verts[2].fPos = SkPoint::Make(bounds.fRight, bounds.fBottom); |
859 verts[2].fOuterOffset = SkPoint::Make(-1.0f - offsetDx, 1.0f + offsetDy); | 866 verts[2].fOuterOffset = SkPoint::Make(1.0f + offsetDx, 1.0f + offsetDy); |
860 verts[2].fInnerOffset = SkPoint::Make(-innerRatioX - offsetDx, innerRatioY +
offsetDy); | 867 verts[2].fInnerOffset = SkPoint::Make(innerRatioX + offsetDx, innerRatioY +
offsetDy); |
861 | 868 |
862 verts[3].fPos = SkPoint::Make(bounds.fRight, bounds.fBottom); | 869 verts[3].fPos = SkPoint::Make(bounds.fRight, bounds.fTop); |
863 verts[3].fOuterOffset = SkPoint::Make(1.0f + offsetDx, 1.0f + offsetDy); | 870 verts[3].fOuterOffset = SkPoint::Make(1.0f + offsetDx, -1.0f - offsetDy); |
864 verts[3].fInnerOffset = SkPoint::Make(innerRatioX + offsetDx, innerRatioY +
offsetDy); | 871 verts[3].fInnerOffset = SkPoint::Make(innerRatioX + offsetDx, -innerRatioY -
offsetDy); |
865 | 872 |
866 target->drawNonIndexed(kTriangleStrip_GrPrimitiveType, 0, 4, &bounds); | 873 target->setIndexSourceToBuffer(context->getGpu()->getQuadIndexBuffer()); |
| 874 target->drawIndexedInstances(kTriangles_GrPrimitiveType, 1, 4, 6, &bounds); |
| 875 target->resetIndexSource(); |
867 | 876 |
868 return true; | 877 return true; |
869 } | 878 } |
870 | 879 |
871 /////////////////////////////////////////////////////////////////////////////// | 880 /////////////////////////////////////////////////////////////////////////////// |
872 | 881 |
873 static const uint16_t gRRectIndices[] = { | 882 static const uint16_t gRRectIndices[] = { |
874 // corners | 883 // corners |
875 0, 1, 5, 0, 5, 4, | 884 0, 1, 5, 0, 5, 4, |
876 2, 3, 7, 2, 7, 6, | 885 2, 3, 7, 2, 7, 6, |
877 8, 9, 13, 8, 13, 12, | 886 8, 9, 13, 8, 13, 12, |
878 10, 11, 15, 10, 15, 14, | 887 10, 11, 15, 10, 15, 14, |
879 | 888 |
880 // edges | 889 // edges |
881 1, 2, 6, 1, 6, 5, | 890 1, 2, 6, 1, 6, 5, |
882 4, 5, 9, 4, 9, 8, | 891 4, 5, 9, 4, 9, 8, |
883 6, 7, 11, 6, 11, 10, | 892 6, 7, 11, 6, 11, 10, |
884 9, 10, 14, 9, 14, 13, | 893 9, 10, 14, 9, 14, 13, |
885 | 894 |
886 // center | 895 // center |
887 // we place this at the end so that we can ignore these indices when renderi
ng stroke-only | 896 // we place this at the end so that we can ignore these indices when renderi
ng stroke-only |
888 5, 6, 10, 5, 10, 9 | 897 5, 6, 10, 5, 10, 9 |
889 }; | 898 }; |
890 | 899 |
| 900 static const int kIndicesPerStrokeRRect = SK_ARRAY_COUNT(gRRectIndices) - 6; |
| 901 static const int kIndicesPerRRect = SK_ARRAY_COUNT(gRRectIndices); |
| 902 static const int kVertsPerRRect = 16; |
| 903 static const int kNumRRectsInIndexBuffer = 256; |
891 | 904 |
892 GrIndexBuffer* GrOvalRenderer::rRectIndexBuffer(GrGpu* gpu) { | 905 GrIndexBuffer* GrOvalRenderer::rRectIndexBuffer(bool isStrokeOnly, GrGpu* gpu) { |
893 if (NULL == fRRectIndexBuffer) { | 906 if (isStrokeOnly) { |
894 fRRectIndexBuffer = | 907 if (NULL == fStrokeRRectIndexBuffer) { |
895 gpu->createIndexBuffer(sizeof(gRRectIndices), false); | 908 fStrokeRRectIndexBuffer = gpu->createIndexBufferPattern(gRRectIndice
s, |
896 if (fRRectIndexBuffer) { | 909 kIndicesPerS
trokeRRect, |
897 #ifdef SK_DEBUG | 910 kNumRRectsIn
IndexBuffer, |
898 bool updated = | 911 kVertsPerRRe
ct); |
899 #endif | |
900 fRRectIndexBuffer->updateData(gRRectIndices, | |
901 sizeof(gRRectIndices)); | |
902 GR_DEBUGASSERT(updated); | |
903 } | 912 } |
| 913 return fStrokeRRectIndexBuffer; |
| 914 } else { |
| 915 if (NULL == fRRectIndexBuffer) { |
| 916 fRRectIndexBuffer = gpu->createIndexBufferPattern(gRRectIndices, |
| 917 kIndicesPerRRect, |
| 918 kNumRRectsInIndexB
uffer, |
| 919 kVertsPerRRect); |
| 920 } |
| 921 return fRRectIndexBuffer; |
904 } | 922 } |
905 return fRRectIndexBuffer; | |
906 } | 923 } |
907 | 924 |
908 bool GrOvalRenderer::drawDRRect(GrDrawTarget* target, GrContext* context, bool u
seAA, | 925 bool GrOvalRenderer::drawDRRect(GrDrawTarget* target, GrContext* context, bool u
seAA, |
909 const SkRRect& origOuter, const SkRRect& origInn
er) { | 926 const SkRRect& origOuter, const SkRRect& origInn
er) { |
910 bool applyAA = useAA && | 927 bool applyAA = useAA && |
911 !target->getDrawState().getRenderTarget()->isMultisampled() &
& | 928 !target->getDrawState().getRenderTarget()->isMultisampled() &
& |
912 !target->shouldDisableCoverageAAForBlend(); | 929 !target->shouldDisableCoverageAAForBlend(); |
913 GrDrawState::AutoRestoreEffects are; | 930 GrDrawState::AutoRestoreEffects are; |
914 if (!origInner.isEmpty()) { | 931 if (!origInner.isEmpty()) { |
915 SkTCopyOnFirstWrite<SkRRect> inner(origInner); | 932 SkTCopyOnFirstWrite<SkRRect> inner(origInner); |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1030 return false; | 1047 return false; |
1031 } | 1048 } |
1032 | 1049 |
1033 // reset to device coordinates | 1050 // reset to device coordinates |
1034 GrDrawState* drawState = target->drawState(); | 1051 GrDrawState* drawState = target->drawState(); |
1035 GrDrawState::AutoViewMatrixRestore avmr; | 1052 GrDrawState::AutoViewMatrixRestore avmr; |
1036 if (!avmr.setIdentity(drawState)) { | 1053 if (!avmr.setIdentity(drawState)) { |
1037 return false; | 1054 return false; |
1038 } | 1055 } |
1039 | 1056 |
1040 GrIndexBuffer* indexBuffer = this->rRectIndexBuffer(context->getGpu()); | 1057 GrIndexBuffer* indexBuffer = this->rRectIndexBuffer(isStrokeOnly, context->g
etGpu()); |
1041 if (NULL == indexBuffer) { | 1058 if (NULL == indexBuffer) { |
1042 GrPrintf("Failed to create index buffer!\n"); | 1059 GrPrintf("Failed to create index buffer!\n"); |
1043 return false; | 1060 return false; |
1044 } | 1061 } |
1045 | 1062 |
1046 // if the corners are circles, use the circle renderer | 1063 // if the corners are circles, use the circle renderer |
1047 if ((!hasStroke || scaledStroke.fX == scaledStroke.fY) && xRadius == yRadius
) { | 1064 if ((!hasStroke || scaledStroke.fX == scaledStroke.fY) && xRadius == yRadius
) { |
1048 drawState->setVertexAttribs<gCircleVertexAttribs>(SK_ARRAY_COUNT(gCircle
VertexAttribs), | 1065 drawState->setVertexAttribs<gCircleVertexAttribs>(SK_ARRAY_COUNT(gCircle
VertexAttribs), |
1049 sizeof(CircleVertex)); | 1066 sizeof(CircleVertex)); |
1050 | 1067 |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1122 verts->fOffset = SkPoint::Make(outerRadius, yOuterRadii[i]); | 1139 verts->fOffset = SkPoint::Make(outerRadius, yOuterRadii[i]); |
1123 verts->fOuterRadius = outerRadius; | 1140 verts->fOuterRadius = outerRadius; |
1124 verts->fInnerRadius = innerRadius; | 1141 verts->fInnerRadius = innerRadius; |
1125 verts++; | 1142 verts++; |
1126 } | 1143 } |
1127 | 1144 |
1128 // drop out the middle quad if we're stroked | 1145 // drop out the middle quad if we're stroked |
1129 int indexCnt = isStrokeOnly ? SK_ARRAY_COUNT(gRRectIndices) - 6 : | 1146 int indexCnt = isStrokeOnly ? SK_ARRAY_COUNT(gRRectIndices) - 6 : |
1130 SK_ARRAY_COUNT(gRRectIndices); | 1147 SK_ARRAY_COUNT(gRRectIndices); |
1131 target->setIndexSourceToBuffer(indexBuffer); | 1148 target->setIndexSourceToBuffer(indexBuffer); |
1132 target->drawIndexed(kTriangles_GrPrimitiveType, 0, 0, 16, indexCnt, &bou
nds); | 1149 target->drawIndexedInstances(kTriangles_GrPrimitiveType, 1, 16, indexCnt
, &bounds); |
1133 | 1150 |
1134 // otherwise we use the ellipse renderer | 1151 // otherwise we use the ellipse renderer |
1135 } else { | 1152 } else { |
1136 drawState->setVertexAttribs<gEllipseVertexAttribs>(SK_ARRAY_COUNT(gEllip
seVertexAttribs), | 1153 drawState->setVertexAttribs<gEllipseVertexAttribs>(SK_ARRAY_COUNT(gEllip
seVertexAttribs), |
1137 sizeof(EllipseVertex)
); | 1154 sizeof(EllipseVertex)
); |
1138 | 1155 |
1139 SkScalar innerXRadius = 0.0f; | 1156 SkScalar innerXRadius = 0.0f; |
1140 SkScalar innerYRadius = 0.0f; | 1157 SkScalar innerYRadius = 0.0f; |
1141 if (hasStroke) { | 1158 if (hasStroke) { |
1142 if (SkScalarNearlyZero(scaledStroke.length())) { | 1159 if (SkScalarNearlyZero(scaledStroke.length())) { |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1229 verts->fOffset = SkPoint::Make(xOuterRadius, yOuterOffsets[i]); | 1246 verts->fOffset = SkPoint::Make(xOuterRadius, yOuterOffsets[i]); |
1230 verts->fOuterRadii = SkPoint::Make(xRadRecip, yRadRecip); | 1247 verts->fOuterRadii = SkPoint::Make(xRadRecip, yRadRecip); |
1231 verts->fInnerRadii = SkPoint::Make(xInnerRadRecip, yInnerRadRecip); | 1248 verts->fInnerRadii = SkPoint::Make(xInnerRadRecip, yInnerRadRecip); |
1232 verts++; | 1249 verts++; |
1233 } | 1250 } |
1234 | 1251 |
1235 // drop out the middle quad if we're stroked | 1252 // drop out the middle quad if we're stroked |
1236 int indexCnt = isStrokeOnly ? SK_ARRAY_COUNT(gRRectIndices) - 6 : | 1253 int indexCnt = isStrokeOnly ? SK_ARRAY_COUNT(gRRectIndices) - 6 : |
1237 SK_ARRAY_COUNT(gRRectIndices); | 1254 SK_ARRAY_COUNT(gRRectIndices); |
1238 target->setIndexSourceToBuffer(indexBuffer); | 1255 target->setIndexSourceToBuffer(indexBuffer); |
1239 target->drawIndexed(kTriangles_GrPrimitiveType, 0, 0, 16, indexCnt, &bou
nds); | 1256 target->drawIndexedInstances(kTriangles_GrPrimitiveType, 1, 16, indexCnt
, &bounds); |
1240 } | 1257 } |
1241 | 1258 |
| 1259 target->resetIndexSource(); |
1242 return true; | 1260 return true; |
1243 } | 1261 } |
OLD | NEW |