| 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 "GrProcessor.h" | 10 #include "GrProcessor.h" |
| (...skipping 579 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 590 /////////////////////////////////////////////////////////////////////////////// | 590 /////////////////////////////////////////////////////////////////////////////// |
| 591 | 591 |
| 592 void GrOvalRenderer::reset() { | 592 void GrOvalRenderer::reset() { |
| 593 SkSafeSetNull(fRRectIndexBuffer); | 593 SkSafeSetNull(fRRectIndexBuffer); |
| 594 SkSafeSetNull(fStrokeRRectIndexBuffer); | 594 SkSafeSetNull(fStrokeRRectIndexBuffer); |
| 595 } | 595 } |
| 596 | 596 |
| 597 bool GrOvalRenderer::drawOval(GrDrawTarget* target, | 597 bool GrOvalRenderer::drawOval(GrDrawTarget* target, |
| 598 GrDrawState* drawState, | 598 GrDrawState* drawState, |
| 599 GrColor color, | 599 GrColor color, |
| 600 const GrContext* context, | |
| 601 bool useAA, | 600 bool useAA, |
| 602 const SkRect& oval, | 601 const SkRect& oval, |
| 603 const SkStrokeRec& stroke) | 602 const SkStrokeRec& stroke) |
| 604 { | 603 { |
| 605 bool useCoverageAA = useAA && | 604 bool useCoverageAA = useAA && |
| 606 !drawState->getRenderTarget()->isMultisampled() && | 605 !drawState->getRenderTarget()->isMultisampled() && |
| 607 drawState->canUseFracCoveragePrimProc(color, *target->caps()); | 606 drawState->canUseFracCoveragePrimProc(color, *target->caps()); |
| 608 | 607 |
| 609 if (!useCoverageAA) { | 608 if (!useCoverageAA) { |
| 610 return false; | 609 return false; |
| 611 } | 610 } |
| 612 | 611 |
| 613 const SkMatrix& vm = context->getMatrix(); | 612 const SkMatrix& vm = drawState->getViewMatrix(); |
| 614 | 613 |
| 615 // we can draw circles | 614 // we can draw circles |
| 616 if (SkScalarNearlyEqual(oval.width(), oval.height()) | 615 if (SkScalarNearlyEqual(oval.width(), oval.height()) |
| 617 && circle_stays_circle(vm)) { | 616 && circle_stays_circle(vm)) { |
| 618 this->drawCircle(target, drawState, color, context, useCoverageAA, oval,
stroke); | 617 this->drawCircle(target, drawState, color, useCoverageAA, oval, stroke); |
| 619 // if we have shader derivative support, render as device-independent | 618 // if we have shader derivative support, render as device-independent |
| 620 } else if (target->caps()->shaderDerivativeSupport()) { | 619 } else if (target->caps()->shaderDerivativeSupport()) { |
| 621 return this->drawDIEllipse(target, drawState, color, context, useCoverag
eAA, oval, stroke); | 620 return this->drawDIEllipse(target, drawState, color, useCoverageAA, oval
, stroke); |
| 622 // otherwise axis-aligned ellipses only | 621 // otherwise axis-aligned ellipses only |
| 623 } else if (vm.rectStaysRect()) { | 622 } else if (vm.rectStaysRect()) { |
| 624 return this->drawEllipse(target, drawState, color, context, useCoverageA
A, oval, stroke); | 623 return this->drawEllipse(target, drawState, color, useCoverageAA, oval,
stroke); |
| 625 } else { | 624 } else { |
| 626 return false; | 625 return false; |
| 627 } | 626 } |
| 628 | 627 |
| 629 return true; | 628 return true; |
| 630 } | 629 } |
| 631 | 630 |
| 632 /////////////////////////////////////////////////////////////////////////////// | 631 /////////////////////////////////////////////////////////////////////////////// |
| 633 | 632 |
| 634 void GrOvalRenderer::drawCircle(GrDrawTarget* target, | 633 void GrOvalRenderer::drawCircle(GrDrawTarget* target, |
| 635 GrDrawState* drawState, | 634 GrDrawState* drawState, |
| 636 GrColor color, | 635 GrColor color, |
| 637 const GrContext* context, | |
| 638 bool useCoverageAA, | 636 bool useCoverageAA, |
| 639 const SkRect& circle, | 637 const SkRect& circle, |
| 640 const SkStrokeRec& stroke) | 638 const SkStrokeRec& stroke) |
| 641 { | 639 { |
| 642 const SkMatrix& vm = drawState->getViewMatrix(); | 640 const SkMatrix& vm = drawState->getViewMatrix(); |
| 643 SkPoint center = SkPoint::Make(circle.centerX(), circle.centerY()); | 641 SkPoint center = SkPoint::Make(circle.centerX(), circle.centerY()); |
| 644 vm.mapPoints(¢er, 1); | 642 vm.mapPoints(¢er, 1); |
| 645 SkScalar radius = vm.mapRadius(SkScalarHalf(circle.width())); | 643 SkScalar radius = vm.mapRadius(SkScalarHalf(circle.width())); |
| 646 SkScalar strokeWidth = vm.mapRadius(stroke.getWidth()); | 644 SkScalar strokeWidth = vm.mapRadius(stroke.getWidth()); |
| 647 | 645 |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 712 verts[2].fPos = SkPoint::Make(bounds.fRight, bounds.fBottom); | 710 verts[2].fPos = SkPoint::Make(bounds.fRight, bounds.fBottom); |
| 713 verts[2].fOffset = SkPoint::Make(1, 1); | 711 verts[2].fOffset = SkPoint::Make(1, 1); |
| 714 verts[2].fOuterRadius = outerRadius; | 712 verts[2].fOuterRadius = outerRadius; |
| 715 verts[2].fInnerRadius = innerRadius; | 713 verts[2].fInnerRadius = innerRadius; |
| 716 | 714 |
| 717 verts[3].fPos = SkPoint::Make(bounds.fRight, bounds.fTop); | 715 verts[3].fPos = SkPoint::Make(bounds.fRight, bounds.fTop); |
| 718 verts[3].fOffset = SkPoint::Make(1, -1); | 716 verts[3].fOffset = SkPoint::Make(1, -1); |
| 719 verts[3].fOuterRadius = outerRadius; | 717 verts[3].fOuterRadius = outerRadius; |
| 720 verts[3].fInnerRadius = innerRadius; | 718 verts[3].fInnerRadius = innerRadius; |
| 721 | 719 |
| 722 target->setIndexSourceToBuffer(context->getGpu()->getQuadIndexBuffer()); | 720 target->setIndexSourceToBuffer(fGpu->getQuadIndexBuffer()); |
| 723 target->drawIndexedInstances(drawState, gp, kTriangles_GrPrimitiveType, 1, 4
, 6, &bounds); | 721 target->drawIndexedInstances(drawState, gp, kTriangles_GrPrimitiveType, 1, 4
, 6, &bounds); |
| 724 target->resetIndexSource(); | 722 target->resetIndexSource(); |
| 725 } | 723 } |
| 726 | 724 |
| 727 /////////////////////////////////////////////////////////////////////////////// | 725 /////////////////////////////////////////////////////////////////////////////// |
| 728 | 726 |
| 729 bool GrOvalRenderer::drawEllipse(GrDrawTarget* target, | 727 bool GrOvalRenderer::drawEllipse(GrDrawTarget* target, |
| 730 GrDrawState* drawState, | 728 GrDrawState* drawState, |
| 731 GrColor color, | 729 GrColor color, |
| 732 const GrContext* context, | |
| 733 bool useCoverageAA, | 730 bool useCoverageAA, |
| 734 const SkRect& ellipse, | 731 const SkRect& ellipse, |
| 735 const SkStrokeRec& stroke) | 732 const SkStrokeRec& stroke) |
| 736 { | 733 { |
| 737 #ifdef SK_DEBUG | 734 #ifdef SK_DEBUG |
| 738 { | 735 { |
| 739 // we should have checked for this previously | 736 // we should have checked for this previously |
| 740 bool isAxisAlignedEllipse = drawState->getViewMatrix().rectStaysRect(); | 737 bool isAxisAlignedEllipse = drawState->getViewMatrix().rectStaysRect(); |
| 741 SkASSERT(useCoverageAA && isAxisAlignedEllipse); | 738 SkASSERT(useCoverageAA && isAxisAlignedEllipse); |
| 742 } | 739 } |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 844 verts[2].fPos = SkPoint::Make(bounds.fRight, bounds.fBottom); | 841 verts[2].fPos = SkPoint::Make(bounds.fRight, bounds.fBottom); |
| 845 verts[2].fOffset = SkPoint::Make(xRadius, yRadius); | 842 verts[2].fOffset = SkPoint::Make(xRadius, yRadius); |
| 846 verts[2].fOuterRadii = SkPoint::Make(xRadRecip, yRadRecip); | 843 verts[2].fOuterRadii = SkPoint::Make(xRadRecip, yRadRecip); |
| 847 verts[2].fInnerRadii = SkPoint::Make(xInnerRadRecip, yInnerRadRecip); | 844 verts[2].fInnerRadii = SkPoint::Make(xInnerRadRecip, yInnerRadRecip); |
| 848 | 845 |
| 849 verts[3].fPos = SkPoint::Make(bounds.fRight, bounds.fTop); | 846 verts[3].fPos = SkPoint::Make(bounds.fRight, bounds.fTop); |
| 850 verts[3].fOffset = SkPoint::Make(xRadius, -yRadius); | 847 verts[3].fOffset = SkPoint::Make(xRadius, -yRadius); |
| 851 verts[3].fOuterRadii = SkPoint::Make(xRadRecip, yRadRecip); | 848 verts[3].fOuterRadii = SkPoint::Make(xRadRecip, yRadRecip); |
| 852 verts[3].fInnerRadii = SkPoint::Make(xInnerRadRecip, yInnerRadRecip); | 849 verts[3].fInnerRadii = SkPoint::Make(xInnerRadRecip, yInnerRadRecip); |
| 853 | 850 |
| 854 target->setIndexSourceToBuffer(context->getGpu()->getQuadIndexBuffer()); | 851 target->setIndexSourceToBuffer(fGpu->getQuadIndexBuffer()); |
| 855 target->drawIndexedInstances(drawState, gp, kTriangles_GrPrimitiveType, 1, 4
, 6, &bounds); | 852 target->drawIndexedInstances(drawState, gp, kTriangles_GrPrimitiveType, 1, 4
, 6, &bounds); |
| 856 target->resetIndexSource(); | 853 target->resetIndexSource(); |
| 857 | 854 |
| 858 return true; | 855 return true; |
| 859 } | 856 } |
| 860 | 857 |
| 861 bool GrOvalRenderer::drawDIEllipse(GrDrawTarget* target, | 858 bool GrOvalRenderer::drawDIEllipse(GrDrawTarget* target, |
| 862 GrDrawState* drawState, | 859 GrDrawState* drawState, |
| 863 GrColor color, | 860 GrColor color, |
| 864 const GrContext* context, | |
| 865 bool useCoverageAA, | 861 bool useCoverageAA, |
| 866 const SkRect& ellipse, | 862 const SkRect& ellipse, |
| 867 const SkStrokeRec& stroke) | 863 const SkStrokeRec& stroke) |
| 868 { | 864 { |
| 869 const SkMatrix& vm = drawState->getViewMatrix(); | 865 const SkMatrix& vm = drawState->getViewMatrix(); |
| 870 | 866 |
| 871 SkPoint center = SkPoint::Make(ellipse.centerX(), ellipse.centerY()); | 867 SkPoint center = SkPoint::Make(ellipse.centerX(), ellipse.centerY()); |
| 872 SkScalar xRadius = SkScalarHalf(ellipse.width()); | 868 SkScalar xRadius = SkScalarHalf(ellipse.width()); |
| 873 SkScalar yRadius = SkScalarHalf(ellipse.height()); | 869 SkScalar yRadius = SkScalarHalf(ellipse.height()); |
| 874 | 870 |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 955 verts[1].fInnerOffset = SkPoint::Make(-innerRatioX - offsetDx, innerRatioY +
offsetDy); | 951 verts[1].fInnerOffset = SkPoint::Make(-innerRatioX - offsetDx, innerRatioY +
offsetDy); |
| 956 | 952 |
| 957 verts[2].fPos = SkPoint::Make(bounds.fRight, bounds.fBottom); | 953 verts[2].fPos = SkPoint::Make(bounds.fRight, bounds.fBottom); |
| 958 verts[2].fOuterOffset = SkPoint::Make(1.0f + offsetDx, 1.0f + offsetDy); | 954 verts[2].fOuterOffset = SkPoint::Make(1.0f + offsetDx, 1.0f + offsetDy); |
| 959 verts[2].fInnerOffset = SkPoint::Make(innerRatioX + offsetDx, innerRatioY +
offsetDy); | 955 verts[2].fInnerOffset = SkPoint::Make(innerRatioX + offsetDx, innerRatioY +
offsetDy); |
| 960 | 956 |
| 961 verts[3].fPos = SkPoint::Make(bounds.fRight, bounds.fTop); | 957 verts[3].fPos = SkPoint::Make(bounds.fRight, bounds.fTop); |
| 962 verts[3].fOuterOffset = SkPoint::Make(1.0f + offsetDx, -1.0f - offsetDy); | 958 verts[3].fOuterOffset = SkPoint::Make(1.0f + offsetDx, -1.0f - offsetDy); |
| 963 verts[3].fInnerOffset = SkPoint::Make(innerRatioX + offsetDx, -innerRatioY -
offsetDy); | 959 verts[3].fInnerOffset = SkPoint::Make(innerRatioX + offsetDx, -innerRatioY -
offsetDy); |
| 964 | 960 |
| 965 target->setIndexSourceToBuffer(context->getGpu()->getQuadIndexBuffer()); | 961 target->setIndexSourceToBuffer(fGpu->getQuadIndexBuffer()); |
| 966 target->drawIndexedInstances(drawState, gp, kTriangles_GrPrimitiveType, 1, 4
, 6, &bounds); | 962 target->drawIndexedInstances(drawState, gp, kTriangles_GrPrimitiveType, 1, 4
, 6, &bounds); |
| 967 target->resetIndexSource(); | 963 target->resetIndexSource(); |
| 968 | 964 |
| 969 return true; | 965 return true; |
| 970 } | 966 } |
| 971 | 967 |
| 972 /////////////////////////////////////////////////////////////////////////////// | 968 /////////////////////////////////////////////////////////////////////////////// |
| 973 | 969 |
| 974 static const uint16_t gRRectIndices[] = { | 970 static const uint16_t gRRectIndices[] = { |
| 975 // corners | 971 // corners |
| (...skipping 11 matching lines...) Expand all Loading... |
| 987 // center | 983 // center |
| 988 // we place this at the end so that we can ignore these indices when renderi
ng stroke-only | 984 // we place this at the end so that we can ignore these indices when renderi
ng stroke-only |
| 989 5, 6, 10, 5, 10, 9 | 985 5, 6, 10, 5, 10, 9 |
| 990 }; | 986 }; |
| 991 | 987 |
| 992 static const int kIndicesPerStrokeRRect = SK_ARRAY_COUNT(gRRectIndices) - 6; | 988 static const int kIndicesPerStrokeRRect = SK_ARRAY_COUNT(gRRectIndices) - 6; |
| 993 static const int kIndicesPerRRect = SK_ARRAY_COUNT(gRRectIndices); | 989 static const int kIndicesPerRRect = SK_ARRAY_COUNT(gRRectIndices); |
| 994 static const int kVertsPerRRect = 16; | 990 static const int kVertsPerRRect = 16; |
| 995 static const int kNumRRectsInIndexBuffer = 256; | 991 static const int kNumRRectsInIndexBuffer = 256; |
| 996 | 992 |
| 997 GrIndexBuffer* GrOvalRenderer::rRectIndexBuffer(bool isStrokeOnly, GrGpu* gpu) { | 993 GrIndexBuffer* GrOvalRenderer::rRectIndexBuffer(bool isStrokeOnly) { |
| 998 if (isStrokeOnly) { | 994 if (isStrokeOnly) { |
| 999 if (NULL == fStrokeRRectIndexBuffer) { | 995 if (NULL == fStrokeRRectIndexBuffer) { |
| 1000 fStrokeRRectIndexBuffer = gpu->createInstancedIndexBuffer(gRRectIndi
ces, | 996 fStrokeRRectIndexBuffer = fGpu->createInstancedIndexBuffer(gRRectInd
ices, |
| 1001 kIndicesPe
rStrokeRRect, | 997 kIndicesP
erStrokeRRect, |
| 1002 kNumRRects
InIndexBuffer, | 998 kNumRRect
sInIndexBuffer, |
| 1003 kVertsPerR
Rect); | 999 kVertsPer
RRect); |
| 1004 } | 1000 } |
| 1005 return fStrokeRRectIndexBuffer; | 1001 return fStrokeRRectIndexBuffer; |
| 1006 } else { | 1002 } else { |
| 1007 if (NULL == fRRectIndexBuffer) { | 1003 if (NULL == fRRectIndexBuffer) { |
| 1008 fRRectIndexBuffer = gpu->createInstancedIndexBuffer(gRRectIndices, | 1004 fRRectIndexBuffer = fGpu->createInstancedIndexBuffer(gRRectIndices, |
| 1009 kIndicesPerRRect
, | 1005 kIndicesPerRRec
t, |
| 1010 kNumRRectsInInde
xBuffer, | 1006 kNumRRectsInInd
exBuffer, |
| 1011 kVertsPerRRect); | 1007 kVertsPerRRect)
; |
| 1012 } | 1008 } |
| 1013 return fRRectIndexBuffer; | 1009 return fRRectIndexBuffer; |
| 1014 } | 1010 } |
| 1015 } | 1011 } |
| 1016 | 1012 |
| 1017 bool GrOvalRenderer::drawDRRect(GrDrawTarget* target, | 1013 bool GrOvalRenderer::drawDRRect(GrDrawTarget* target, |
| 1018 GrDrawState* drawState, | 1014 GrDrawState* drawState, |
| 1019 GrColor color, | 1015 GrColor color, |
| 1020 GrContext* context, | |
| 1021 bool useAA, | 1016 bool useAA, |
| 1022 const SkRRect& origOuter, | 1017 const SkRRect& origOuter, |
| 1023 const SkRRect& origInner) { | 1018 const SkRRect& origInner) { |
| 1024 bool applyAA = useAA && | 1019 bool applyAA = useAA && |
| 1025 !drawState->getRenderTarget()->isMultisampled() && | 1020 !drawState->getRenderTarget()->isMultisampled() && |
| 1026 drawState->canUseFracCoveragePrimProc(color, *target->caps())
; | 1021 drawState->canUseFracCoveragePrimProc(color, *target->caps())
; |
| 1027 GrDrawState::AutoRestoreEffects are; | 1022 GrDrawState::AutoRestoreEffects are; |
| 1028 if (!origInner.isEmpty()) { | 1023 if (!origInner.isEmpty()) { |
| 1029 SkTCopyOnFirstWrite<SkRRect> inner(origInner); | 1024 SkTCopyOnFirstWrite<SkRRect> inner(origInner); |
| 1030 if (!context->getMatrix().isIdentity()) { | 1025 if (!drawState->getViewMatrix().isIdentity()) { |
| 1031 if (!origInner.transform(context->getMatrix(), inner.writable())) { | 1026 if (!origInner.transform(drawState->getViewMatrix(), inner.writable(
))) { |
| 1032 return false; | 1027 return false; |
| 1033 } | 1028 } |
| 1034 } | 1029 } |
| 1035 GrPrimitiveEdgeType edgeType = applyAA ? | 1030 GrPrimitiveEdgeType edgeType = applyAA ? |
| 1036 kInverseFillAA_GrProcessorEdgeType : | 1031 kInverseFillAA_GrProcessorEdgeType : |
| 1037 kInverseFillBW_GrProcessorEdgeType; | 1032 kInverseFillBW_GrProcessorEdgeType; |
| 1038 // TODO this needs to be a geometry processor | 1033 // TODO this needs to be a geometry processor |
| 1039 GrFragmentProcessor* fp = GrRRectEffect::Create(edgeType, *inner); | 1034 GrFragmentProcessor* fp = GrRRectEffect::Create(edgeType, *inner); |
| 1040 if (NULL == fp) { | 1035 if (NULL == fp) { |
| 1041 return false; | 1036 return false; |
| 1042 } | 1037 } |
| 1043 are.set(drawState); | 1038 are.set(drawState); |
| 1044 drawState->addCoverageProcessor(fp)->unref(); | 1039 drawState->addCoverageProcessor(fp)->unref(); |
| 1045 } | 1040 } |
| 1046 | 1041 |
| 1047 SkStrokeRec fillRec(SkStrokeRec::kFill_InitStyle); | 1042 SkStrokeRec fillRec(SkStrokeRec::kFill_InitStyle); |
| 1048 if (this->drawRRect(target, drawState, color, context, useAA, origOuter, fil
lRec)) { | 1043 if (this->drawRRect(target, drawState, color, useAA, origOuter, fillRec)) { |
| 1049 return true; | 1044 return true; |
| 1050 } | 1045 } |
| 1051 | 1046 |
| 1052 SkASSERT(!origOuter.isEmpty()); | 1047 SkASSERT(!origOuter.isEmpty()); |
| 1053 SkTCopyOnFirstWrite<SkRRect> outer(origOuter); | 1048 SkTCopyOnFirstWrite<SkRRect> outer(origOuter); |
| 1054 if (!context->getMatrix().isIdentity()) { | 1049 if (!drawState->getViewMatrix().isIdentity()) { |
| 1055 if (!origOuter.transform(context->getMatrix(), outer.writable())) { | 1050 if (!origOuter.transform(drawState->getViewMatrix(), outer.writable()))
{ |
| 1056 return false; | 1051 return false; |
| 1057 } | 1052 } |
| 1058 } | 1053 } |
| 1059 GrPrimitiveEdgeType edgeType = applyAA ? kFillAA_GrProcessorEdgeType : | 1054 GrPrimitiveEdgeType edgeType = applyAA ? kFillAA_GrProcessorEdgeType : |
| 1060 kFillBW_GrProcessorEdgeType; | 1055 kFillBW_GrProcessorEdgeType; |
| 1061 GrFragmentProcessor* effect = GrRRectEffect::Create(edgeType, *outer); | 1056 GrFragmentProcessor* effect = GrRRectEffect::Create(edgeType, *outer); |
| 1062 if (NULL == effect) { | 1057 if (NULL == effect) { |
| 1063 return false; | 1058 return false; |
| 1064 } | 1059 } |
| 1065 if (!are.isSet()) { | 1060 if (!are.isSet()) { |
| 1066 are.set(drawState); | 1061 are.set(drawState); |
| 1067 } | 1062 } |
| 1068 GrDrawState::AutoViewMatrixRestore avmr; | 1063 GrDrawState::AutoViewMatrixRestore avmr; |
| 1069 if (!avmr.setIdentity(drawState)) { | 1064 if (!avmr.setIdentity(drawState)) { |
| 1070 return false; | 1065 return false; |
| 1071 } | 1066 } |
| 1072 drawState->addCoverageProcessor(effect)->unref(); | 1067 drawState->addCoverageProcessor(effect)->unref(); |
| 1073 SkRect bounds = outer->getBounds(); | 1068 SkRect bounds = outer->getBounds(); |
| 1074 if (applyAA) { | 1069 if (applyAA) { |
| 1075 bounds.outset(SK_ScalarHalf, SK_ScalarHalf); | 1070 bounds.outset(SK_ScalarHalf, SK_ScalarHalf); |
| 1076 } | 1071 } |
| 1077 target->drawRect(drawState, color, bounds, NULL, NULL); | 1072 target->drawRect(drawState, color, bounds, NULL, NULL); |
| 1078 return true; | 1073 return true; |
| 1079 } | 1074 } |
| 1080 | 1075 |
| 1081 bool GrOvalRenderer::drawRRect(GrDrawTarget* target, | 1076 bool GrOvalRenderer::drawRRect(GrDrawTarget* target, |
| 1082 GrDrawState* drawState, | 1077 GrDrawState* drawState, |
| 1083 GrColor color, | 1078 GrColor color, |
| 1084 GrContext* context, | |
| 1085 bool useAA, | 1079 bool useAA, |
| 1086 const SkRRect& rrect, | 1080 const SkRRect& rrect, |
| 1087 const SkStrokeRec& stroke) { | 1081 const SkStrokeRec& stroke) { |
| 1088 if (rrect.isOval()) { | 1082 if (rrect.isOval()) { |
| 1089 return this->drawOval(target, drawState, color, context, useAA, rrect.ge
tBounds(), stroke); | 1083 return this->drawOval(target, drawState, color, useAA, rrect.getBounds()
, stroke); |
| 1090 } | 1084 } |
| 1091 | 1085 |
| 1092 bool useCoverageAA = useAA && | 1086 bool useCoverageAA = useAA && |
| 1093 !drawState->getRenderTarget()->isMultisampled() && | 1087 !drawState->getRenderTarget()->isMultisampled() && |
| 1094 drawState->canUseFracCoveragePrimProc(color, *target->caps()); | 1088 drawState->canUseFracCoveragePrimProc(color, *target->caps()); |
| 1095 | 1089 |
| 1096 // only anti-aliased rrects for now | 1090 // only anti-aliased rrects for now |
| 1097 if (!useCoverageAA) { | 1091 if (!useCoverageAA) { |
| 1098 return false; | 1092 return false; |
| 1099 } | 1093 } |
| 1100 | 1094 |
| 1101 const SkMatrix& vm = context->getMatrix(); | 1095 const SkMatrix& vm = drawState->getViewMatrix(); |
| 1102 | 1096 |
| 1103 if (!vm.rectStaysRect() || !rrect.isSimple()) { | 1097 if (!vm.rectStaysRect() || !rrect.isSimple()) { |
| 1104 return false; | 1098 return false; |
| 1105 } | 1099 } |
| 1106 | 1100 |
| 1107 // do any matrix crunching before we reset the draw state for device coords | 1101 // do any matrix crunching before we reset the draw state for device coords |
| 1108 const SkRect& rrectBounds = rrect.getBounds(); | 1102 const SkRect& rrectBounds = rrect.getBounds(); |
| 1109 SkRect bounds; | 1103 SkRect bounds; |
| 1110 vm.mapRect(&bounds, rrectBounds); | 1104 vm.mapRect(&bounds, rrectBounds); |
| 1111 | 1105 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1149 if (!isStrokeOnly && (SK_ScalarHalf > xRadius || SK_ScalarHalf > yRadius)) { | 1143 if (!isStrokeOnly && (SK_ScalarHalf > xRadius || SK_ScalarHalf > yRadius)) { |
| 1150 return false; | 1144 return false; |
| 1151 } | 1145 } |
| 1152 | 1146 |
| 1153 // reset to device coordinates | 1147 // reset to device coordinates |
| 1154 GrDrawState::AutoViewMatrixRestore avmr; | 1148 GrDrawState::AutoViewMatrixRestore avmr; |
| 1155 if (!avmr.setIdentity(drawState)) { | 1149 if (!avmr.setIdentity(drawState)) { |
| 1156 return false; | 1150 return false; |
| 1157 } | 1151 } |
| 1158 | 1152 |
| 1159 GrIndexBuffer* indexBuffer = this->rRectIndexBuffer(isStrokeOnly, context->g
etGpu()); | 1153 GrIndexBuffer* indexBuffer = this->rRectIndexBuffer(isStrokeOnly); |
| 1160 if (NULL == indexBuffer) { | 1154 if (NULL == indexBuffer) { |
| 1161 SkDebugf("Failed to create index buffer!\n"); | 1155 SkDebugf("Failed to create index buffer!\n"); |
| 1162 return false; | 1156 return false; |
| 1163 } | 1157 } |
| 1164 | 1158 |
| 1165 // if the corners are circles, use the circle renderer | 1159 // if the corners are circles, use the circle renderer |
| 1166 if ((!hasStroke || scaledStroke.fX == scaledStroke.fY) && xRadius == yRadius
) { | 1160 if ((!hasStroke || scaledStroke.fX == scaledStroke.fY) && xRadius == yRadius
) { |
| 1167 SkScalar innerRadius = 0.0f; | 1161 SkScalar innerRadius = 0.0f; |
| 1168 SkScalar outerRadius = xRadius; | 1162 SkScalar outerRadius = xRadius; |
| 1169 SkScalar halfWidth = 0; | 1163 SkScalar halfWidth = 0; |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1349 int indexCnt = isStrokeOnly ? SK_ARRAY_COUNT(gRRectIndices) - 6 : | 1343 int indexCnt = isStrokeOnly ? SK_ARRAY_COUNT(gRRectIndices) - 6 : |
| 1350 SK_ARRAY_COUNT(gRRectIndices); | 1344 SK_ARRAY_COUNT(gRRectIndices); |
| 1351 target->setIndexSourceToBuffer(indexBuffer); | 1345 target->setIndexSourceToBuffer(indexBuffer); |
| 1352 target->drawIndexedInstances(drawState, effect, kTriangles_GrPrimitiveTy
pe, 1, 16, indexCnt, | 1346 target->drawIndexedInstances(drawState, effect, kTriangles_GrPrimitiveTy
pe, 1, 16, indexCnt, |
| 1353 &bounds); | 1347 &bounds); |
| 1354 } | 1348 } |
| 1355 | 1349 |
| 1356 target->resetIndexSource(); | 1350 target->resetIndexSource(); |
| 1357 return true; | 1351 return true; |
| 1358 } | 1352 } |
| OLD | NEW |