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