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