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" |
11 #include "gl/GrGLProcessor.h" | 11 #include "gl/GrGLProcessor.h" |
12 #include "gl/GrGLSL.h" | 12 #include "gl/GrGLSL.h" |
13 #include "gl/GrGLGeometryProcessor.h" | 13 #include "gl/GrGLGeometryProcessor.h" |
14 #include "GrProcessor.h" | 14 #include "GrProcessor.h" |
15 #include "GrTBackendProcessorFactory.h" | 15 #include "GrTBackendProcessorFactory.h" |
16 | 16 |
17 #include "GrDrawState.h" | 17 #include "GrDrawState.h" |
18 #include "GrDrawTarget.h" | 18 #include "GrDrawTarget.h" |
19 #include "GrGpu.h" | 19 #include "GrGpu.h" |
20 | 20 |
21 #include "SkRRect.h" | 21 #include "SkRRect.h" |
22 #include "SkStrokeRec.h" | 22 #include "SkStrokeRec.h" |
23 #include "SkTLazy.h" | 23 #include "SkTLazy.h" |
24 | 24 |
25 #include "GrGeometryProcessor.h" | 25 #include "GrGeometryProcessor.h" |
26 #include "effects/GrRRectEffect.h" | 26 #include "effects/GrRRectEffect.h" |
27 | 27 |
28 namespace { | 28 namespace { |
29 | 29 // TODO(joshualitt) add per vertex colors |
30 struct CircleVertex { | 30 struct CircleVertex { |
31 SkPoint fPos; | 31 SkPoint fPos; |
32 SkPoint fOffset; | 32 SkPoint fOffset; |
33 SkScalar fOuterRadius; | 33 SkScalar fOuterRadius; |
34 SkScalar fInnerRadius; | 34 SkScalar fInnerRadius; |
35 }; | 35 }; |
36 | 36 |
37 struct EllipseVertex { | 37 struct EllipseVertex { |
38 SkPoint fPos; | 38 SkPoint fPos; |
39 SkPoint fOffset; | 39 SkPoint fOffset; |
(...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
471 | 471 |
472 if (!useCoverageAA) { | 472 if (!useCoverageAA) { |
473 return false; | 473 return false; |
474 } | 474 } |
475 | 475 |
476 const SkMatrix& vm = context->getMatrix(); | 476 const SkMatrix& vm = context->getMatrix(); |
477 | 477 |
478 // we can draw circles | 478 // we can draw circles |
479 if (SkScalarNearlyEqual(oval.width(), oval.height()) | 479 if (SkScalarNearlyEqual(oval.width(), oval.height()) |
480 && circle_stays_circle(vm)) { | 480 && circle_stays_circle(vm)) { |
481 this->drawCircle(target, useCoverageAA, oval, stroke); | 481 this->drawCircle(target, context, useCoverageAA, oval, stroke); |
482 // if we have shader derivative support, render as device-independent | 482 // if we have shader derivative support, render as device-independent |
483 } else if (target->caps()->shaderDerivativeSupport()) { | 483 } else if (target->caps()->shaderDerivativeSupport()) { |
484 return this->drawDIEllipse(target, useCoverageAA, oval, stroke); | 484 return this->drawDIEllipse(target, context, useCoverageAA, oval, stroke)
; |
485 // otherwise axis-aligned ellipses only | 485 // otherwise axis-aligned ellipses only |
486 } else if (vm.rectStaysRect()) { | 486 } else if (vm.rectStaysRect()) { |
487 return this->drawEllipse(target, useCoverageAA, oval, stroke); | 487 return this->drawEllipse(target, context, useCoverageAA, oval, stroke); |
488 } else { | 488 } else { |
489 return false; | 489 return false; |
490 } | 490 } |
491 | 491 |
492 return true; | 492 return true; |
493 } | 493 } |
494 | 494 |
495 /////////////////////////////////////////////////////////////////////////////// | 495 /////////////////////////////////////////////////////////////////////////////// |
496 | 496 |
497 // position + edge | 497 // position + edge |
498 extern const GrVertexAttrib gCircleVertexAttribs[] = { | 498 extern const GrVertexAttrib gCircleVertexAttribs[] = { |
499 {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBinding
}, | 499 {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBinding
}, |
500 {kVec4f_GrVertexAttribType, sizeof(SkPoint), kGeometryProcessor_GrVertexAttr
ibBinding} | 500 {kVec4f_GrVertexAttribType, sizeof(SkPoint), kGeometryProcessor_GrVertexAttr
ibBinding} |
501 }; | 501 }; |
502 | 502 |
503 void GrOvalRenderer::drawCircle(GrDrawTarget* target, | 503 void GrOvalRenderer::drawCircle(GrDrawTarget* target, |
| 504 const GrContext* context, |
504 bool useCoverageAA, | 505 bool useCoverageAA, |
505 const SkRect& circle, | 506 const SkRect& circle, |
506 const SkStrokeRec& stroke) | 507 const SkStrokeRec& stroke) |
507 { | 508 { |
508 GrDrawState* drawState = target->drawState(); | 509 GrDrawState* drawState = target->drawState(); |
509 | 510 |
510 const SkMatrix& vm = drawState->getViewMatrix(); | 511 const SkMatrix& vm = drawState->getViewMatrix(); |
511 SkPoint center = SkPoint::Make(circle.centerX(), circle.centerY()); | 512 SkPoint center = SkPoint::Make(circle.centerX(), circle.centerY()); |
512 vm.mapPoints(¢er, 1); | 513 vm.mapPoints(¢er, 1); |
513 SkScalar radius = vm.mapRadius(SkScalarHalf(circle.width())); | 514 SkScalar radius = vm.mapRadius(SkScalarHalf(circle.width())); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
565 center.fY - outerRadius, | 566 center.fY - outerRadius, |
566 center.fX + outerRadius, | 567 center.fX + outerRadius, |
567 center.fY + outerRadius | 568 center.fY + outerRadius |
568 ); | 569 ); |
569 | 570 |
570 verts[0].fPos = SkPoint::Make(bounds.fLeft, bounds.fTop); | 571 verts[0].fPos = SkPoint::Make(bounds.fLeft, bounds.fTop); |
571 verts[0].fOffset = SkPoint::Make(-outerRadius, -outerRadius); | 572 verts[0].fOffset = SkPoint::Make(-outerRadius, -outerRadius); |
572 verts[0].fOuterRadius = outerRadius; | 573 verts[0].fOuterRadius = outerRadius; |
573 verts[0].fInnerRadius = innerRadius; | 574 verts[0].fInnerRadius = innerRadius; |
574 | 575 |
575 verts[1].fPos = SkPoint::Make(bounds.fRight, bounds.fTop); | 576 verts[1].fPos = SkPoint::Make(bounds.fLeft, bounds.fBottom); |
576 verts[1].fOffset = SkPoint::Make(outerRadius, -outerRadius); | 577 verts[1].fOffset = SkPoint::Make(-outerRadius, outerRadius); |
577 verts[1].fOuterRadius = outerRadius; | 578 verts[1].fOuterRadius = outerRadius; |
578 verts[1].fInnerRadius = innerRadius; | 579 verts[1].fInnerRadius = innerRadius; |
579 | 580 |
580 verts[2].fPos = SkPoint::Make(bounds.fLeft, bounds.fBottom); | 581 verts[2].fPos = SkPoint::Make(bounds.fRight, bounds.fBottom); |
581 verts[2].fOffset = SkPoint::Make(-outerRadius, outerRadius); | 582 verts[2].fOffset = SkPoint::Make(outerRadius, outerRadius); |
582 verts[2].fOuterRadius = outerRadius; | 583 verts[2].fOuterRadius = outerRadius; |
583 verts[2].fInnerRadius = innerRadius; | 584 verts[2].fInnerRadius = innerRadius; |
584 | 585 |
585 verts[3].fPos = SkPoint::Make(bounds.fRight, bounds.fBottom); | 586 verts[3].fPos = SkPoint::Make(bounds.fRight, bounds.fTop); |
586 verts[3].fOffset = SkPoint::Make(outerRadius, outerRadius); | 587 verts[3].fOffset = SkPoint::Make(outerRadius, -outerRadius); |
587 verts[3].fOuterRadius = outerRadius; | 588 verts[3].fOuterRadius = outerRadius; |
588 verts[3].fInnerRadius = innerRadius; | 589 verts[3].fInnerRadius = innerRadius; |
589 | 590 |
590 target->drawNonIndexed(kTriangleStrip_GrPrimitiveType, 0, 4, &bounds); | 591 target->setIndexSourceToBuffer(context->getGpu()->getQuadIndexBuffer()); |
| 592 target->drawIndexedInstances(kTriangles_GrPrimitiveType, 1, 4, 6, &bounds); |
| 593 target->resetIndexSource(); |
591 } | 594 } |
592 | 595 |
593 /////////////////////////////////////////////////////////////////////////////// | 596 /////////////////////////////////////////////////////////////////////////////// |
594 | 597 |
595 // position + offset + 1/radii | 598 // position + offset + 1/radii |
596 extern const GrVertexAttrib gEllipseVertexAttribs[] = { | 599 extern const GrVertexAttrib gEllipseVertexAttribs[] = { |
597 {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBindi
ng}, | 600 {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBindi
ng}, |
598 {kVec2f_GrVertexAttribType, sizeof(SkPoint), kGeometryProcessor_GrVertexAt
tribBinding}, | 601 {kVec2f_GrVertexAttribType, sizeof(SkPoint), kGeometryProcessor_GrVertexAt
tribBinding}, |
599 {kVec4f_GrVertexAttribType, 2*sizeof(SkPoint), kGeometryProcessor_GrVertexAt
tribBinding} | 602 {kVec4f_GrVertexAttribType, 2*sizeof(SkPoint), kGeometryProcessor_GrVertexAt
tribBinding} |
600 }; | 603 }; |
601 | 604 |
602 // position + offsets | 605 // position + offsets |
603 extern const GrVertexAttrib gDIEllipseVertexAttribs[] = { | 606 extern const GrVertexAttrib gDIEllipseVertexAttribs[] = { |
604 {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBindi
ng}, | 607 {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBindi
ng}, |
605 {kVec2f_GrVertexAttribType, sizeof(SkPoint), kGeometryProcessor_GrVertexAt
tribBinding}, | 608 {kVec2f_GrVertexAttribType, sizeof(SkPoint), kGeometryProcessor_GrVertexAt
tribBinding}, |
606 {kVec2f_GrVertexAttribType, 2*sizeof(SkPoint), kGeometryProcessor_GrVertexAt
tribBinding}, | 609 {kVec2f_GrVertexAttribType, 2*sizeof(SkPoint), kGeometryProcessor_GrVertexAt
tribBinding}, |
607 }; | 610 }; |
608 | 611 |
609 bool GrOvalRenderer::drawEllipse(GrDrawTarget* target, | 612 bool GrOvalRenderer::drawEllipse(GrDrawTarget* target, |
| 613 const GrContext* context, |
610 bool useCoverageAA, | 614 bool useCoverageAA, |
611 const SkRect& ellipse, | 615 const SkRect& ellipse, |
612 const SkStrokeRec& stroke) | 616 const SkStrokeRec& stroke) |
613 { | 617 { |
614 GrDrawState* drawState = target->drawState(); | 618 GrDrawState* drawState = target->drawState(); |
615 #ifdef SK_DEBUG | 619 #ifdef SK_DEBUG |
616 { | 620 { |
617 // we should have checked for this previously | 621 // we should have checked for this previously |
618 bool isAxisAlignedEllipse = drawState->getViewMatrix().rectStaysRect(); | 622 bool isAxisAlignedEllipse = drawState->getViewMatrix().rectStaysRect(); |
619 SkASSERT(useCoverageAA && isAxisAlignedEllipse); | 623 SkASSERT(useCoverageAA && isAxisAlignedEllipse); |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
711 center.fY - yRadius, | 715 center.fY - yRadius, |
712 center.fX + xRadius, | 716 center.fX + xRadius, |
713 center.fY + yRadius | 717 center.fY + yRadius |
714 ); | 718 ); |
715 | 719 |
716 verts[0].fPos = SkPoint::Make(bounds.fLeft, bounds.fTop); | 720 verts[0].fPos = SkPoint::Make(bounds.fLeft, bounds.fTop); |
717 verts[0].fOffset = SkPoint::Make(-xRadius, -yRadius); | 721 verts[0].fOffset = SkPoint::Make(-xRadius, -yRadius); |
718 verts[0].fOuterRadii = SkPoint::Make(xRadRecip, yRadRecip); | 722 verts[0].fOuterRadii = SkPoint::Make(xRadRecip, yRadRecip); |
719 verts[0].fInnerRadii = SkPoint::Make(xInnerRadRecip, yInnerRadRecip); | 723 verts[0].fInnerRadii = SkPoint::Make(xInnerRadRecip, yInnerRadRecip); |
720 | 724 |
721 verts[1].fPos = SkPoint::Make(bounds.fRight, bounds.fTop); | 725 verts[1].fPos = SkPoint::Make(bounds.fLeft, bounds.fBottom); |
722 verts[1].fOffset = SkPoint::Make(xRadius, -yRadius); | 726 verts[1].fOffset = SkPoint::Make(-xRadius, yRadius); |
723 verts[1].fOuterRadii = SkPoint::Make(xRadRecip, yRadRecip); | 727 verts[1].fOuterRadii = SkPoint::Make(xRadRecip, yRadRecip); |
724 verts[1].fInnerRadii = SkPoint::Make(xInnerRadRecip, yInnerRadRecip); | 728 verts[1].fInnerRadii = SkPoint::Make(xInnerRadRecip, yInnerRadRecip); |
725 | 729 |
726 verts[2].fPos = SkPoint::Make(bounds.fLeft, bounds.fBottom); | 730 verts[2].fPos = SkPoint::Make(bounds.fRight, bounds.fBottom); |
727 verts[2].fOffset = SkPoint::Make(-xRadius, yRadius); | 731 verts[2].fOffset = SkPoint::Make(xRadius, yRadius); |
728 verts[2].fOuterRadii = SkPoint::Make(xRadRecip, yRadRecip); | 732 verts[2].fOuterRadii = SkPoint::Make(xRadRecip, yRadRecip); |
729 verts[2].fInnerRadii = SkPoint::Make(xInnerRadRecip, yInnerRadRecip); | 733 verts[2].fInnerRadii = SkPoint::Make(xInnerRadRecip, yInnerRadRecip); |
730 | 734 |
731 verts[3].fPos = SkPoint::Make(bounds.fRight, bounds.fBottom); | 735 verts[3].fPos = SkPoint::Make(bounds.fRight, bounds.fTop); |
732 verts[3].fOffset = SkPoint::Make(xRadius, yRadius); | 736 verts[3].fOffset = SkPoint::Make(xRadius, -yRadius); |
733 verts[3].fOuterRadii = SkPoint::Make(xRadRecip, yRadRecip); | 737 verts[3].fOuterRadii = SkPoint::Make(xRadRecip, yRadRecip); |
734 verts[3].fInnerRadii = SkPoint::Make(xInnerRadRecip, yInnerRadRecip); | 738 verts[3].fInnerRadii = SkPoint::Make(xInnerRadRecip, yInnerRadRecip); |
735 | 739 |
736 target->drawNonIndexed(kTriangleStrip_GrPrimitiveType, 0, 4, &bounds); | 740 target->setIndexSourceToBuffer(context->getGpu()->getQuadIndexBuffer()); |
| 741 target->drawIndexedInstances(kTriangles_GrPrimitiveType, 1, 4, 6, &bounds); |
| 742 target->resetIndexSource(); |
737 | 743 |
738 return true; | 744 return true; |
739 } | 745 } |
740 | 746 |
741 bool GrOvalRenderer::drawDIEllipse(GrDrawTarget* target, | 747 bool GrOvalRenderer::drawDIEllipse(GrDrawTarget* target, |
| 748 const GrContext* context, |
742 bool useCoverageAA, | 749 bool useCoverageAA, |
743 const SkRect& ellipse, | 750 const SkRect& ellipse, |
744 const SkStrokeRec& stroke) | 751 const SkStrokeRec& stroke) |
745 { | 752 { |
746 GrDrawState* drawState = target->drawState(); | 753 GrDrawState* drawState = target->drawState(); |
747 const SkMatrix& vm = drawState->getViewMatrix(); | 754 const SkMatrix& vm = drawState->getViewMatrix(); |
748 | 755 |
749 SkPoint center = SkPoint::Make(ellipse.centerX(), ellipse.centerY()); | 756 SkPoint center = SkPoint::Make(ellipse.centerX(), ellipse.centerY()); |
750 SkScalar xRadius = SkScalarHalf(ellipse.width()); | 757 SkScalar xRadius = SkScalarHalf(ellipse.width()); |
751 SkScalar yRadius = SkScalarHalf(ellipse.height()); | 758 SkScalar yRadius = SkScalarHalf(ellipse.height()); |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
825 center.fX - xRadius - geoDx, | 832 center.fX - xRadius - geoDx, |
826 center.fY - yRadius - geoDy, | 833 center.fY - yRadius - geoDy, |
827 center.fX + xRadius + geoDx, | 834 center.fX + xRadius + geoDx, |
828 center.fY + yRadius + geoDy | 835 center.fY + yRadius + geoDy |
829 ); | 836 ); |
830 | 837 |
831 verts[0].fPos = SkPoint::Make(bounds.fLeft, bounds.fTop); | 838 verts[0].fPos = SkPoint::Make(bounds.fLeft, bounds.fTop); |
832 verts[0].fOuterOffset = SkPoint::Make(-1.0f - offsetDx, -1.0f - offsetDy); | 839 verts[0].fOuterOffset = SkPoint::Make(-1.0f - offsetDx, -1.0f - offsetDy); |
833 verts[0].fInnerOffset = SkPoint::Make(-innerRatioX - offsetDx, -innerRatioY
- offsetDy); | 840 verts[0].fInnerOffset = SkPoint::Make(-innerRatioX - offsetDx, -innerRatioY
- offsetDy); |
834 | 841 |
835 verts[1].fPos = SkPoint::Make(bounds.fRight, bounds.fTop); | 842 verts[1].fPos = SkPoint::Make(bounds.fLeft, bounds.fBottom); |
836 verts[1].fOuterOffset = SkPoint::Make(1.0f + offsetDx, -1.0f - offsetDy); | 843 verts[1].fOuterOffset = SkPoint::Make(-1.0f - offsetDx, 1.0f + offsetDy); |
837 verts[1].fInnerOffset = SkPoint::Make(innerRatioX + offsetDx, -innerRatioY -
offsetDy); | 844 verts[1].fInnerOffset = SkPoint::Make(-innerRatioX - offsetDx, innerRatioY +
offsetDy); |
838 | 845 |
839 verts[2].fPos = SkPoint::Make(bounds.fLeft, bounds.fBottom); | 846 verts[2].fPos = SkPoint::Make(bounds.fRight, bounds.fBottom); |
840 verts[2].fOuterOffset = SkPoint::Make(-1.0f - offsetDx, 1.0f + offsetDy); | 847 verts[2].fOuterOffset = SkPoint::Make(1.0f + offsetDx, 1.0f + offsetDy); |
841 verts[2].fInnerOffset = SkPoint::Make(-innerRatioX - offsetDx, innerRatioY +
offsetDy); | 848 verts[2].fInnerOffset = SkPoint::Make(innerRatioX + offsetDx, innerRatioY +
offsetDy); |
842 | 849 |
843 verts[3].fPos = SkPoint::Make(bounds.fRight, bounds.fBottom); | 850 verts[3].fPos = SkPoint::Make(bounds.fRight, bounds.fTop); |
844 verts[3].fOuterOffset = SkPoint::Make(1.0f + offsetDx, 1.0f + offsetDy); | 851 verts[3].fOuterOffset = SkPoint::Make(1.0f + offsetDx, -1.0f - offsetDy); |
845 verts[3].fInnerOffset = SkPoint::Make(innerRatioX + offsetDx, innerRatioY +
offsetDy); | 852 verts[3].fInnerOffset = SkPoint::Make(innerRatioX + offsetDx, -innerRatioY -
offsetDy); |
846 | 853 |
847 target->drawNonIndexed(kTriangleStrip_GrPrimitiveType, 0, 4, &bounds); | 854 target->setIndexSourceToBuffer(context->getGpu()->getQuadIndexBuffer()); |
| 855 target->drawIndexedInstances(kTriangles_GrPrimitiveType, 1, 4, 6, &bounds); |
| 856 target->resetIndexSource(); |
848 | 857 |
849 return true; | 858 return true; |
850 } | 859 } |
851 | 860 |
852 /////////////////////////////////////////////////////////////////////////////// | 861 /////////////////////////////////////////////////////////////////////////////// |
853 | 862 |
854 static const uint16_t gRRectIndices[] = { | 863 static const uint16_t gRRectIndices[] = { |
855 // corners | 864 // corners |
856 0, 1, 5, 0, 5, 4, | 865 0, 1, 5, 0, 5, 4, |
857 2, 3, 7, 2, 7, 6, | 866 2, 3, 7, 2, 7, 6, |
858 8, 9, 13, 8, 13, 12, | 867 8, 9, 13, 8, 13, 12, |
859 10, 11, 15, 10, 15, 14, | 868 10, 11, 15, 10, 15, 14, |
860 | 869 |
861 // edges | 870 // edges |
862 1, 2, 6, 1, 6, 5, | 871 1, 2, 6, 1, 6, 5, |
863 4, 5, 9, 4, 9, 8, | 872 4, 5, 9, 4, 9, 8, |
864 6, 7, 11, 6, 11, 10, | 873 6, 7, 11, 6, 11, 10, |
865 9, 10, 14, 9, 14, 13, | 874 9, 10, 14, 9, 14, 13, |
866 | 875 |
867 // center | 876 // center |
868 // we place this at the end so that we can ignore these indices when renderi
ng stroke-only | 877 // we place this at the end so that we can ignore these indices when renderi
ng stroke-only |
869 5, 6, 10, 5, 10, 9 | 878 5, 6, 10, 5, 10, 9 |
870 }; | 879 }; |
871 | 880 |
| 881 static const int kIndicesPerStrokeRRect = SK_ARRAY_COUNT(gRRectIndices) - 6; |
| 882 static const int kIndicesPerRRect = SK_ARRAY_COUNT(gRRectIndices); |
| 883 static const int kVertsPerRRect = 16; |
| 884 static const int kNumRRectsInIndexBuffer = 256; |
872 | 885 |
873 GrIndexBuffer* GrOvalRenderer::rRectIndexBuffer(GrGpu* gpu) { | 886 GrIndexBuffer* GrOvalRenderer::rRectIndexBuffer(bool isStrokeOnly, GrGpu* gpu) { |
874 if (NULL == fRRectIndexBuffer) { | 887 if (isStrokeOnly) { |
875 fRRectIndexBuffer = | 888 if (NULL == fStrokeRRectIndexBuffer) { |
876 gpu->createIndexBuffer(sizeof(gRRectIndices), false); | 889 fStrokeRRectIndexBuffer = gpu->createInstancedIndexBuffer(gRRectIndi
ces, |
877 if (fRRectIndexBuffer) { | 890 kIndicesPe
rStrokeRRect, |
878 #ifdef SK_DEBUG | 891 kNumRRects
InIndexBuffer, |
879 bool updated = | 892 kVertsPerR
Rect); |
880 #endif | |
881 fRRectIndexBuffer->updateData(gRRectIndices, | |
882 sizeof(gRRectIndices)); | |
883 GR_DEBUGASSERT(updated); | |
884 } | 893 } |
| 894 return fStrokeRRectIndexBuffer; |
| 895 } else { |
| 896 if (NULL == fRRectIndexBuffer) { |
| 897 fRRectIndexBuffer = gpu->createInstancedIndexBuffer(gRRectIndices, |
| 898 kIndicesPerRRect
, |
| 899 kNumRRectsInInde
xBuffer, |
| 900 kVertsPerRRect); |
| 901 } |
| 902 return fRRectIndexBuffer; |
885 } | 903 } |
886 return fRRectIndexBuffer; | |
887 } | 904 } |
888 | 905 |
889 bool GrOvalRenderer::drawDRRect(GrDrawTarget* target, GrContext* context, bool u
seAA, | 906 bool GrOvalRenderer::drawDRRect(GrDrawTarget* target, GrContext* context, bool u
seAA, |
890 const SkRRect& origOuter, const SkRRect& origInn
er) { | 907 const SkRRect& origOuter, const SkRRect& origInn
er) { |
891 bool applyAA = useAA && | 908 bool applyAA = useAA && |
892 !target->getDrawState().getRenderTarget()->isMultisampled() &
& | 909 !target->getDrawState().getRenderTarget()->isMultisampled() &
& |
893 !target->shouldDisableCoverageAAForBlend(); | 910 !target->shouldDisableCoverageAAForBlend(); |
894 GrDrawState::AutoRestoreEffects are; | 911 GrDrawState::AutoRestoreEffects are; |
895 if (!origInner.isEmpty()) { | 912 if (!origInner.isEmpty()) { |
896 SkTCopyOnFirstWrite<SkRRect> inner(origInner); | 913 SkTCopyOnFirstWrite<SkRRect> inner(origInner); |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1011 return false; | 1028 return false; |
1012 } | 1029 } |
1013 | 1030 |
1014 // reset to device coordinates | 1031 // reset to device coordinates |
1015 GrDrawState* drawState = target->drawState(); | 1032 GrDrawState* drawState = target->drawState(); |
1016 GrDrawState::AutoViewMatrixRestore avmr; | 1033 GrDrawState::AutoViewMatrixRestore avmr; |
1017 if (!avmr.setIdentity(drawState)) { | 1034 if (!avmr.setIdentity(drawState)) { |
1018 return false; | 1035 return false; |
1019 } | 1036 } |
1020 | 1037 |
1021 GrIndexBuffer* indexBuffer = this->rRectIndexBuffer(context->getGpu()); | 1038 GrIndexBuffer* indexBuffer = this->rRectIndexBuffer(isStrokeOnly, context->g
etGpu()); |
1022 if (NULL == indexBuffer) { | 1039 if (NULL == indexBuffer) { |
1023 GrPrintf("Failed to create index buffer!\n"); | 1040 GrPrintf("Failed to create index buffer!\n"); |
1024 return false; | 1041 return false; |
1025 } | 1042 } |
1026 | 1043 |
1027 // if the corners are circles, use the circle renderer | 1044 // if the corners are circles, use the circle renderer |
1028 if ((!hasStroke || scaledStroke.fX == scaledStroke.fY) && xRadius == yRadius
) { | 1045 if ((!hasStroke || scaledStroke.fX == scaledStroke.fY) && xRadius == yRadius
) { |
1029 drawState->setVertexAttribs<gCircleVertexAttribs>(SK_ARRAY_COUNT(gCircle
VertexAttribs), | 1046 drawState->setVertexAttribs<gCircleVertexAttribs>(SK_ARRAY_COUNT(gCircle
VertexAttribs), |
1030 sizeof(CircleVertex)); | 1047 sizeof(CircleVertex)); |
1031 | 1048 |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1103 verts->fOffset = SkPoint::Make(outerRadius, yOuterRadii[i]); | 1120 verts->fOffset = SkPoint::Make(outerRadius, yOuterRadii[i]); |
1104 verts->fOuterRadius = outerRadius; | 1121 verts->fOuterRadius = outerRadius; |
1105 verts->fInnerRadius = innerRadius; | 1122 verts->fInnerRadius = innerRadius; |
1106 verts++; | 1123 verts++; |
1107 } | 1124 } |
1108 | 1125 |
1109 // drop out the middle quad if we're stroked | 1126 // drop out the middle quad if we're stroked |
1110 int indexCnt = isStrokeOnly ? SK_ARRAY_COUNT(gRRectIndices) - 6 : | 1127 int indexCnt = isStrokeOnly ? SK_ARRAY_COUNT(gRRectIndices) - 6 : |
1111 SK_ARRAY_COUNT(gRRectIndices); | 1128 SK_ARRAY_COUNT(gRRectIndices); |
1112 target->setIndexSourceToBuffer(indexBuffer); | 1129 target->setIndexSourceToBuffer(indexBuffer); |
1113 target->drawIndexed(kTriangles_GrPrimitiveType, 0, 0, 16, indexCnt, &bou
nds); | 1130 target->drawIndexedInstances(kTriangles_GrPrimitiveType, 1, 16, indexCnt
, &bounds); |
1114 | 1131 |
1115 // otherwise we use the ellipse renderer | 1132 // otherwise we use the ellipse renderer |
1116 } else { | 1133 } else { |
1117 drawState->setVertexAttribs<gEllipseVertexAttribs>(SK_ARRAY_COUNT(gEllip
seVertexAttribs), | 1134 drawState->setVertexAttribs<gEllipseVertexAttribs>(SK_ARRAY_COUNT(gEllip
seVertexAttribs), |
1118 sizeof(EllipseVertex)
); | 1135 sizeof(EllipseVertex)
); |
1119 | 1136 |
1120 SkScalar innerXRadius = 0.0f; | 1137 SkScalar innerXRadius = 0.0f; |
1121 SkScalar innerYRadius = 0.0f; | 1138 SkScalar innerYRadius = 0.0f; |
1122 if (hasStroke) { | 1139 if (hasStroke) { |
1123 if (SkScalarNearlyZero(scaledStroke.length())) { | 1140 if (SkScalarNearlyZero(scaledStroke.length())) { |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1210 verts->fOffset = SkPoint::Make(xOuterRadius, yOuterOffsets[i]); | 1227 verts->fOffset = SkPoint::Make(xOuterRadius, yOuterOffsets[i]); |
1211 verts->fOuterRadii = SkPoint::Make(xRadRecip, yRadRecip); | 1228 verts->fOuterRadii = SkPoint::Make(xRadRecip, yRadRecip); |
1212 verts->fInnerRadii = SkPoint::Make(xInnerRadRecip, yInnerRadRecip); | 1229 verts->fInnerRadii = SkPoint::Make(xInnerRadRecip, yInnerRadRecip); |
1213 verts++; | 1230 verts++; |
1214 } | 1231 } |
1215 | 1232 |
1216 // drop out the middle quad if we're stroked | 1233 // drop out the middle quad if we're stroked |
1217 int indexCnt = isStrokeOnly ? SK_ARRAY_COUNT(gRRectIndices) - 6 : | 1234 int indexCnt = isStrokeOnly ? SK_ARRAY_COUNT(gRRectIndices) - 6 : |
1218 SK_ARRAY_COUNT(gRRectIndices); | 1235 SK_ARRAY_COUNT(gRRectIndices); |
1219 target->setIndexSourceToBuffer(indexBuffer); | 1236 target->setIndexSourceToBuffer(indexBuffer); |
1220 target->drawIndexed(kTriangles_GrPrimitiveType, 0, 0, 16, indexCnt, &bou
nds); | 1237 target->drawIndexedInstances(kTriangles_GrPrimitiveType, 1, 16, indexCnt
, &bounds); |
1221 } | 1238 } |
1222 | 1239 |
| 1240 target->resetIndexSource(); |
1223 return true; | 1241 return true; |
1224 } | 1242 } |
OLD | NEW |