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 "GrEffect.h" | 10 #include "GrEffect.h" |
(...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
453 | 453 |
454 /////////////////////////////////////////////////////////////////////////////// | 454 /////////////////////////////////////////////////////////////////////////////// |
455 | 455 |
456 void GrOvalRenderer::reset() { | 456 void GrOvalRenderer::reset() { |
457 SkSafeSetNull(fRRectIndexBuffer); | 457 SkSafeSetNull(fRRectIndexBuffer); |
458 } | 458 } |
459 | 459 |
460 bool GrOvalRenderer::drawOval(GrDrawTarget* target, const GrContext* context, bo
ol useAA, | 460 bool GrOvalRenderer::drawOval(GrDrawTarget* target, const GrContext* context, bo
ol useAA, |
461 const SkRect& oval, const SkStrokeRec& stroke) | 461 const SkRect& oval, const SkStrokeRec& stroke) |
462 { | 462 { |
463 bool useCoverageAA = useAA && | 463 if (!useAA) { |
464 !target->getDrawState().getRenderTarget()->isMultisampled() && | |
465 !target->shouldDisableCoverageAAForBlend(); | |
466 | |
467 if (!useCoverageAA) { | |
468 return false; | 464 return false; |
469 } | 465 } |
470 | 466 |
471 const SkMatrix& vm = context->getMatrix(); | 467 const SkMatrix& vm = context->getMatrix(); |
472 | 468 |
473 // we can draw circles | 469 // we can draw circles |
474 if (SkScalarNearlyEqual(oval.width(), oval.height()) | 470 if (SkScalarNearlyEqual(oval.width(), oval.height()) |
475 && circle_stays_circle(vm)) { | 471 && circle_stays_circle(vm)) { |
476 this->drawCircle(target, useCoverageAA, oval, stroke); | 472 this->drawCircle(target, useAA, oval, stroke); |
477 // if we have shader derivative support, render as device-independent | 473 // if we have shader derivative support, render as device-independent |
478 } else if (target->caps()->shaderDerivativeSupport()) { | 474 } else if (target->caps()->shaderDerivativeSupport()) { |
479 return this->drawDIEllipse(target, useCoverageAA, oval, stroke); | 475 return this->drawDIEllipse(target, useAA, oval, stroke); |
480 // otherwise axis-aligned ellipses only | 476 // otherwise axis-aligned ellipses only |
481 } else if (vm.rectStaysRect()) { | 477 } else if (vm.rectStaysRect()) { |
482 return this->drawEllipse(target, useCoverageAA, oval, stroke); | 478 return this->drawEllipse(target, useAA, oval, stroke); |
483 } else { | 479 } else { |
484 return false; | 480 return false; |
485 } | 481 } |
486 | 482 |
487 return true; | 483 return true; |
488 } | 484 } |
489 | 485 |
490 /////////////////////////////////////////////////////////////////////////////// | 486 /////////////////////////////////////////////////////////////////////////////// |
491 | 487 |
492 // position + edge | 488 // position + edge |
493 extern const GrVertexAttrib gCircleVertexAttribs[] = { | 489 extern const GrVertexAttrib gCircleVertexAttribs[] = { |
494 {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBinding
}, | 490 {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBinding
}, |
495 {kVec4f_GrVertexAttribType, sizeof(GrPoint), kEffect_GrVertexAttribBinding} | 491 {kVec4f_GrVertexAttribType, sizeof(GrPoint), kEffect_GrVertexAttribBinding} |
496 }; | 492 }; |
497 | 493 |
498 void GrOvalRenderer::drawCircle(GrDrawTarget* target, | 494 void GrOvalRenderer::drawCircle(GrDrawTarget* target, |
499 bool useCoverageAA, | 495 bool useAA, |
500 const SkRect& circle, | 496 const SkRect& circle, |
501 const SkStrokeRec& stroke) | 497 const SkStrokeRec& stroke) |
502 { | 498 { |
503 GrDrawState* drawState = target->drawState(); | 499 GrDrawState* drawState = target->drawState(); |
504 | 500 |
505 const SkMatrix& vm = drawState->getViewMatrix(); | 501 const SkMatrix& vm = drawState->getViewMatrix(); |
506 GrPoint center = GrPoint::Make(circle.centerX(), circle.centerY()); | 502 GrPoint center = GrPoint::Make(circle.centerX(), circle.centerY()); |
507 vm.mapPoints(¢er, 1); | 503 vm.mapPoints(¢er, 1); |
508 SkScalar radius = vm.mapRadius(SkScalarHalf(circle.width())); | 504 SkScalar radius = vm.mapRadius(SkScalarHalf(circle.width())); |
509 SkScalar strokeWidth = vm.mapRadius(stroke.getWidth()); | 505 SkScalar strokeWidth = vm.mapRadius(stroke.getWidth()); |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
594 }; | 590 }; |
595 | 591 |
596 // position + offsets | 592 // position + offsets |
597 extern const GrVertexAttrib gDIEllipseVertexAttribs[] = { | 593 extern const GrVertexAttrib gDIEllipseVertexAttribs[] = { |
598 {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBindi
ng}, | 594 {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBindi
ng}, |
599 {kVec2f_GrVertexAttribType, sizeof(GrPoint), kEffect_GrVertexAttribBinding
}, | 595 {kVec2f_GrVertexAttribType, sizeof(GrPoint), kEffect_GrVertexAttribBinding
}, |
600 {kVec2f_GrVertexAttribType, 2*sizeof(GrPoint), kEffect_GrVertexAttribBinding
}, | 596 {kVec2f_GrVertexAttribType, 2*sizeof(GrPoint), kEffect_GrVertexAttribBinding
}, |
601 }; | 597 }; |
602 | 598 |
603 bool GrOvalRenderer::drawEllipse(GrDrawTarget* target, | 599 bool GrOvalRenderer::drawEllipse(GrDrawTarget* target, |
604 bool useCoverageAA, | 600 bool useAA, |
605 const SkRect& ellipse, | 601 const SkRect& ellipse, |
606 const SkStrokeRec& stroke) | 602 const SkStrokeRec& stroke) |
607 { | 603 { |
608 GrDrawState* drawState = target->drawState(); | 604 GrDrawState* drawState = target->drawState(); |
609 #ifdef SK_DEBUG | 605 #ifdef SK_DEBUG |
610 { | 606 { |
611 // we should have checked for this previously | 607 // we should have checked for this previously |
612 bool isAxisAlignedEllipse = drawState->getViewMatrix().rectStaysRect(); | 608 bool isAxisAlignedEllipse = drawState->getViewMatrix().rectStaysRect(); |
613 SkASSERT(useCoverageAA && isAxisAlignedEllipse); | 609 SkASSERT(useAA && isAxisAlignedEllipse); |
614 } | 610 } |
615 #endif | 611 #endif |
616 | 612 |
617 // do any matrix crunching before we reset the draw state for device coords | 613 // do any matrix crunching before we reset the draw state for device coords |
618 const SkMatrix& vm = drawState->getViewMatrix(); | 614 const SkMatrix& vm = drawState->getViewMatrix(); |
619 GrPoint center = GrPoint::Make(ellipse.centerX(), ellipse.centerY()); | 615 GrPoint center = GrPoint::Make(ellipse.centerX(), ellipse.centerY()); |
620 vm.mapPoints(¢er, 1); | 616 vm.mapPoints(¢er, 1); |
621 SkScalar ellipseXRadius = SkScalarHalf(ellipse.width()); | 617 SkScalar ellipseXRadius = SkScalarHalf(ellipse.width()); |
622 SkScalar ellipseYRadius = SkScalarHalf(ellipse.height()); | 618 SkScalar ellipseYRadius = SkScalarHalf(ellipse.height()); |
623 SkScalar xRadius = SkScalarAbs(vm[SkMatrix::kMScaleX]*ellipseXRadius + | 619 SkScalar xRadius = SkScalarAbs(vm[SkMatrix::kMScaleX]*ellipseXRadius + |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
726 verts[3].fOffset = SkPoint::Make(xRadius, yRadius); | 722 verts[3].fOffset = SkPoint::Make(xRadius, yRadius); |
727 verts[3].fOuterRadii = SkPoint::Make(xRadRecip, yRadRecip); | 723 verts[3].fOuterRadii = SkPoint::Make(xRadRecip, yRadRecip); |
728 verts[3].fInnerRadii = SkPoint::Make(xInnerRadRecip, yInnerRadRecip); | 724 verts[3].fInnerRadii = SkPoint::Make(xInnerRadRecip, yInnerRadRecip); |
729 | 725 |
730 target->drawNonIndexed(kTriangleStrip_GrPrimitiveType, 0, 4, &bounds); | 726 target->drawNonIndexed(kTriangleStrip_GrPrimitiveType, 0, 4, &bounds); |
731 | 727 |
732 return true; | 728 return true; |
733 } | 729 } |
734 | 730 |
735 bool GrOvalRenderer::drawDIEllipse(GrDrawTarget* target, | 731 bool GrOvalRenderer::drawDIEllipse(GrDrawTarget* target, |
736 bool useCoverageAA, | 732 bool useAA, |
737 const SkRect& ellipse, | 733 const SkRect& ellipse, |
738 const SkStrokeRec& stroke) | 734 const SkStrokeRec& stroke) |
739 { | 735 { |
740 GrDrawState* drawState = target->drawState(); | 736 GrDrawState* drawState = target->drawState(); |
741 const SkMatrix& vm = drawState->getViewMatrix(); | 737 const SkMatrix& vm = drawState->getViewMatrix(); |
742 | 738 |
743 GrPoint center = GrPoint::Make(ellipse.centerX(), ellipse.centerY()); | 739 GrPoint center = GrPoint::Make(ellipse.centerX(), ellipse.centerY()); |
744 SkScalar xRadius = SkScalarHalf(ellipse.width()); | 740 SkScalar xRadius = SkScalarHalf(ellipse.width()); |
745 SkScalar yRadius = SkScalarHalf(ellipse.height()); | 741 SkScalar yRadius = SkScalarHalf(ellipse.height()); |
746 | 742 |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
879 sizeof(gRRectIndices)); | 875 sizeof(gRRectIndices)); |
880 GR_DEBUGASSERT(updated); | 876 GR_DEBUGASSERT(updated); |
881 } | 877 } |
882 } | 878 } |
883 return fRRectIndexBuffer; | 879 return fRRectIndexBuffer; |
884 } | 880 } |
885 | 881 |
886 bool GrOvalRenderer::drawSimpleRRect(GrDrawTarget* target, GrContext* context, b
ool useAA, | 882 bool GrOvalRenderer::drawSimpleRRect(GrDrawTarget* target, GrContext* context, b
ool useAA, |
887 const SkRRect& rrect, const SkStrokeRec& st
roke) | 883 const SkRRect& rrect, const SkStrokeRec& st
roke) |
888 { | 884 { |
889 bool useCoverageAA = useAA && | |
890 !target->getDrawState().getRenderTarget()->isMultisampled() && | |
891 !target->shouldDisableCoverageAAForBlend(); | |
892 | |
893 // only anti-aliased rrects for now | 885 // only anti-aliased rrects for now |
894 if (!useCoverageAA) { | 886 if (!useAA) { |
895 return false; | 887 return false; |
896 } | 888 } |
897 | 889 |
898 const SkMatrix& vm = context->getMatrix(); | 890 const SkMatrix& vm = context->getMatrix(); |
899 #ifdef SK_DEBUG | 891 #ifdef SK_DEBUG |
900 { | 892 { |
901 // we should have checked for this previously | 893 // we should have checked for this previously |
902 SkASSERT(useCoverageAA && vm.rectStaysRect() && rrect.isSimple()); | 894 SkASSERT(useAA && vm.rectStaysRect() && rrect.isSimple()); |
903 } | 895 } |
904 #endif | 896 #endif |
905 | 897 |
906 // do any matrix crunching before we reset the draw state for device coords | 898 // do any matrix crunching before we reset the draw state for device coords |
907 const SkRect& rrectBounds = rrect.getBounds(); | 899 const SkRect& rrectBounds = rrect.getBounds(); |
908 SkRect bounds; | 900 SkRect bounds; |
909 vm.mapRect(&bounds, rrectBounds); | 901 vm.mapRect(&bounds, rrectBounds); |
910 | 902 |
911 SkVector radii = rrect.getSimpleRadii(); | 903 SkVector radii = rrect.getSimpleRadii(); |
912 SkScalar xRadius = SkScalarAbs(vm[SkMatrix::kMScaleX]*radii.fX + | 904 SkScalar xRadius = SkScalarAbs(vm[SkMatrix::kMScaleX]*radii.fX + |
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1140 } | 1132 } |
1141 | 1133 |
1142 // drop out the middle quad if we're stroked | 1134 // drop out the middle quad if we're stroked |
1143 int indexCnt = isStroked ? GR_ARRAY_COUNT(gRRectIndices)-6 : GR_ARRAY_CO
UNT(gRRectIndices); | 1135 int indexCnt = isStroked ? GR_ARRAY_COUNT(gRRectIndices)-6 : GR_ARRAY_CO
UNT(gRRectIndices); |
1144 target->setIndexSourceToBuffer(indexBuffer); | 1136 target->setIndexSourceToBuffer(indexBuffer); |
1145 target->drawIndexed(kTriangles_GrPrimitiveType, 0, 0, 16, indexCnt, &bou
nds); | 1137 target->drawIndexed(kTriangles_GrPrimitiveType, 0, 0, 16, indexCnt, &bou
nds); |
1146 } | 1138 } |
1147 | 1139 |
1148 return true; | 1140 return true; |
1149 } | 1141 } |
OLD | NEW |