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" |
11 #include "gl/GrGLEffect.h" | 11 #include "gl/GrGLEffect.h" |
12 #include "gl/GrGLSL.h" | 12 #include "gl/GrGLSL.h" |
13 #include "gl/GrGLVertexEffect.h" | 13 #include "gl/GrGLVertexEffect.h" |
14 #include "GrTBackendEffectFactory.h" | 14 #include "GrTBackendEffectFactory.h" |
15 | 15 |
16 #include "GrDrawState.h" | 16 #include "GrDrawState.h" |
17 #include "GrDrawTarget.h" | 17 #include "GrDrawTarget.h" |
18 #include "GrGpu.h" | 18 #include "GrGpu.h" |
19 | 19 |
20 #include "SkRRect.h" | 20 #include "SkRRect.h" |
21 #include "SkStrokeRec.h" | 21 #include "SkStrokeRec.h" |
22 | 22 |
23 #include "effects/GrVertexEffect.h" | 23 #include "effects/GrVertexEffect.h" |
24 | 24 |
25 namespace { | 25 namespace { |
26 | 26 |
27 struct CircleVertex { | 27 struct CircleVertex { |
28 GrPoint fPos; | 28 SkPoint fPos; |
29 GrPoint fOffset; | 29 SkPoint fOffset; |
30 SkScalar fOuterRadius; | 30 SkScalar fOuterRadius; |
31 SkScalar fInnerRadius; | 31 SkScalar fInnerRadius; |
32 }; | 32 }; |
33 | 33 |
34 struct EllipseVertex { | 34 struct EllipseVertex { |
35 GrPoint fPos; | 35 SkPoint fPos; |
36 GrPoint fOffset; | 36 SkPoint fOffset; |
37 GrPoint fOuterRadii; | 37 SkPoint fOuterRadii; |
38 GrPoint fInnerRadii; | 38 SkPoint fInnerRadii; |
39 }; | 39 }; |
40 | 40 |
41 struct DIEllipseVertex { | 41 struct DIEllipseVertex { |
42 GrPoint fPos; | 42 SkPoint fPos; |
43 GrPoint fOuterOffset; | 43 SkPoint fOuterOffset; |
44 GrPoint fInnerOffset; | 44 SkPoint fInnerOffset; |
45 }; | 45 }; |
46 | 46 |
47 inline bool circle_stays_circle(const SkMatrix& m) { | 47 inline bool circle_stays_circle(const SkMatrix& m) { |
48 return m.isSimilarity(); | 48 return m.isSimilarity(); |
49 } | 49 } |
50 | 50 |
51 } | 51 } |
52 | 52 |
53 /////////////////////////////////////////////////////////////////////////////// | 53 /////////////////////////////////////////////////////////////////////////////// |
54 | 54 |
(...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
485 } | 485 } |
486 | 486 |
487 return true; | 487 return true; |
488 } | 488 } |
489 | 489 |
490 /////////////////////////////////////////////////////////////////////////////// | 490 /////////////////////////////////////////////////////////////////////////////// |
491 | 491 |
492 // position + edge | 492 // position + edge |
493 extern const GrVertexAttrib gCircleVertexAttribs[] = { | 493 extern const GrVertexAttrib gCircleVertexAttribs[] = { |
494 {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBinding
}, | 494 {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBinding
}, |
495 {kVec4f_GrVertexAttribType, sizeof(GrPoint), kEffect_GrVertexAttribBinding} | 495 {kVec4f_GrVertexAttribType, sizeof(SkPoint), kEffect_GrVertexAttribBinding} |
496 }; | 496 }; |
497 | 497 |
498 void GrOvalRenderer::drawCircle(GrDrawTarget* target, | 498 void GrOvalRenderer::drawCircle(GrDrawTarget* target, |
499 bool useCoverageAA, | 499 bool useCoverageAA, |
500 const SkRect& circle, | 500 const SkRect& circle, |
501 const SkStrokeRec& stroke) | 501 const SkStrokeRec& stroke) |
502 { | 502 { |
503 GrDrawState* drawState = target->drawState(); | 503 GrDrawState* drawState = target->drawState(); |
504 | 504 |
505 const SkMatrix& vm = drawState->getViewMatrix(); | 505 const SkMatrix& vm = drawState->getViewMatrix(); |
506 GrPoint center = GrPoint::Make(circle.centerX(), circle.centerY()); | 506 SkPoint center = SkPoint::Make(circle.centerX(), circle.centerY()); |
507 vm.mapPoints(¢er, 1); | 507 vm.mapPoints(¢er, 1); |
508 SkScalar radius = vm.mapRadius(SkScalarHalf(circle.width())); | 508 SkScalar radius = vm.mapRadius(SkScalarHalf(circle.width())); |
509 SkScalar strokeWidth = vm.mapRadius(stroke.getWidth()); | 509 SkScalar strokeWidth = vm.mapRadius(stroke.getWidth()); |
510 | 510 |
511 GrDrawState::AutoViewMatrixRestore avmr; | 511 GrDrawState::AutoViewMatrixRestore avmr; |
512 if (!avmr.setIdentity(drawState)) { | 512 if (!avmr.setIdentity(drawState)) { |
513 return; | 513 return; |
514 } | 514 } |
515 | 515 |
516 drawState->setVertexAttribs<gCircleVertexAttribs>(SK_ARRAY_COUNT(gCircleVert
exAttribs)); | 516 drawState->setVertexAttribs<gCircleVertexAttribs>(SK_ARRAY_COUNT(gCircleVert
exAttribs)); |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
582 verts[3].fInnerRadius = innerRadius; | 582 verts[3].fInnerRadius = innerRadius; |
583 | 583 |
584 target->drawNonIndexed(kTriangleStrip_GrPrimitiveType, 0, 4, &bounds); | 584 target->drawNonIndexed(kTriangleStrip_GrPrimitiveType, 0, 4, &bounds); |
585 } | 585 } |
586 | 586 |
587 /////////////////////////////////////////////////////////////////////////////// | 587 /////////////////////////////////////////////////////////////////////////////// |
588 | 588 |
589 // position + offset + 1/radii | 589 // position + offset + 1/radii |
590 extern const GrVertexAttrib gEllipseVertexAttribs[] = { | 590 extern const GrVertexAttrib gEllipseVertexAttribs[] = { |
591 {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBindi
ng}, | 591 {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBindi
ng}, |
592 {kVec2f_GrVertexAttribType, sizeof(GrPoint), kEffect_GrVertexAttribBinding
}, | 592 {kVec2f_GrVertexAttribType, sizeof(SkPoint), kEffect_GrVertexAttribBinding
}, |
593 {kVec4f_GrVertexAttribType, 2*sizeof(GrPoint), kEffect_GrVertexAttribBinding
} | 593 {kVec4f_GrVertexAttribType, 2*sizeof(SkPoint), kEffect_GrVertexAttribBinding
} |
594 }; | 594 }; |
595 | 595 |
596 // position + offsets | 596 // position + offsets |
597 extern const GrVertexAttrib gDIEllipseVertexAttribs[] = { | 597 extern const GrVertexAttrib gDIEllipseVertexAttribs[] = { |
598 {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBindi
ng}, | 598 {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBindi
ng}, |
599 {kVec2f_GrVertexAttribType, sizeof(GrPoint), kEffect_GrVertexAttribBinding
}, | 599 {kVec2f_GrVertexAttribType, sizeof(SkPoint), kEffect_GrVertexAttribBinding
}, |
600 {kVec2f_GrVertexAttribType, 2*sizeof(GrPoint), kEffect_GrVertexAttribBinding
}, | 600 {kVec2f_GrVertexAttribType, 2*sizeof(SkPoint), kEffect_GrVertexAttribBinding
}, |
601 }; | 601 }; |
602 | 602 |
603 bool GrOvalRenderer::drawEllipse(GrDrawTarget* target, | 603 bool GrOvalRenderer::drawEllipse(GrDrawTarget* target, |
604 bool useCoverageAA, | 604 bool useCoverageAA, |
605 const SkRect& ellipse, | 605 const SkRect& ellipse, |
606 const SkStrokeRec& stroke) | 606 const SkStrokeRec& stroke) |
607 { | 607 { |
608 GrDrawState* drawState = target->drawState(); | 608 GrDrawState* drawState = target->drawState(); |
609 #ifdef SK_DEBUG | 609 #ifdef SK_DEBUG |
610 { | 610 { |
611 // we should have checked for this previously | 611 // we should have checked for this previously |
612 bool isAxisAlignedEllipse = drawState->getViewMatrix().rectStaysRect(); | 612 bool isAxisAlignedEllipse = drawState->getViewMatrix().rectStaysRect(); |
613 SkASSERT(useCoverageAA && isAxisAlignedEllipse); | 613 SkASSERT(useCoverageAA && isAxisAlignedEllipse); |
614 } | 614 } |
615 #endif | 615 #endif |
616 | 616 |
617 // 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 |
618 const SkMatrix& vm = drawState->getViewMatrix(); | 618 const SkMatrix& vm = drawState->getViewMatrix(); |
619 GrPoint center = GrPoint::Make(ellipse.centerX(), ellipse.centerY()); | 619 SkPoint center = SkPoint::Make(ellipse.centerX(), ellipse.centerY()); |
620 vm.mapPoints(¢er, 1); | 620 vm.mapPoints(¢er, 1); |
621 SkScalar ellipseXRadius = SkScalarHalf(ellipse.width()); | 621 SkScalar ellipseXRadius = SkScalarHalf(ellipse.width()); |
622 SkScalar ellipseYRadius = SkScalarHalf(ellipse.height()); | 622 SkScalar ellipseYRadius = SkScalarHalf(ellipse.height()); |
623 SkScalar xRadius = SkScalarAbs(vm[SkMatrix::kMScaleX]*ellipseXRadius + | 623 SkScalar xRadius = SkScalarAbs(vm[SkMatrix::kMScaleX]*ellipseXRadius + |
624 vm[SkMatrix::kMSkewY]*ellipseYRadius); | 624 vm[SkMatrix::kMSkewY]*ellipseYRadius); |
625 SkScalar yRadius = SkScalarAbs(vm[SkMatrix::kMSkewX]*ellipseXRadius + | 625 SkScalar yRadius = SkScalarAbs(vm[SkMatrix::kMSkewX]*ellipseXRadius + |
626 vm[SkMatrix::kMScaleY]*ellipseYRadius); | 626 vm[SkMatrix::kMScaleY]*ellipseYRadius); |
627 | 627 |
628 // do (potentially) anisotropic mapping of stroke | 628 // do (potentially) anisotropic mapping of stroke |
629 SkVector scaledStroke; | 629 SkVector scaledStroke; |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
733 } | 733 } |
734 | 734 |
735 bool GrOvalRenderer::drawDIEllipse(GrDrawTarget* target, | 735 bool GrOvalRenderer::drawDIEllipse(GrDrawTarget* target, |
736 bool useCoverageAA, | 736 bool useCoverageAA, |
737 const SkRect& ellipse, | 737 const SkRect& ellipse, |
738 const SkStrokeRec& stroke) | 738 const SkStrokeRec& stroke) |
739 { | 739 { |
740 GrDrawState* drawState = target->drawState(); | 740 GrDrawState* drawState = target->drawState(); |
741 const SkMatrix& vm = drawState->getViewMatrix(); | 741 const SkMatrix& vm = drawState->getViewMatrix(); |
742 | 742 |
743 GrPoint center = GrPoint::Make(ellipse.centerX(), ellipse.centerY()); | 743 SkPoint center = SkPoint::Make(ellipse.centerX(), ellipse.centerY()); |
744 SkScalar xRadius = SkScalarHalf(ellipse.width()); | 744 SkScalar xRadius = SkScalarHalf(ellipse.width()); |
745 SkScalar yRadius = SkScalarHalf(ellipse.height()); | 745 SkScalar yRadius = SkScalarHalf(ellipse.height()); |
746 | 746 |
747 SkStrokeRec::Style style = stroke.getStyle(); | 747 SkStrokeRec::Style style = stroke.getStyle(); |
748 DIEllipseEdgeEffect::Mode mode = (SkStrokeRec::kStroke_Style == style) ? | 748 DIEllipseEdgeEffect::Mode mode = (SkStrokeRec::kStroke_Style == style) ? |
749 DIEllipseEdgeEffect::kStroke : | 749 DIEllipseEdgeEffect::kStroke : |
750 (SkStrokeRec::kHairline_Style == style) ? | 750 (SkStrokeRec::kHairline_Style == style) ? |
751 DIEllipseEdgeEffect::kHairline : DIEllipseEd
geEffect::kFill; | 751 DIEllipseEdgeEffect::kHairline : DIEllipseEd
geEffect::kFill; |
752 | 752 |
753 SkScalar innerXRadius = 0; | 753 SkScalar innerXRadius = 0; |
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1024 verts++; | 1024 verts++; |
1025 | 1025 |
1026 verts->fPos = SkPoint::Make(bounds.fRight, yCoords[i]); | 1026 verts->fPos = SkPoint::Make(bounds.fRight, yCoords[i]); |
1027 verts->fOffset = SkPoint::Make(outerRadius, yOuterRadii[i]); | 1027 verts->fOffset = SkPoint::Make(outerRadius, yOuterRadii[i]); |
1028 verts->fOuterRadius = outerRadius; | 1028 verts->fOuterRadius = outerRadius; |
1029 verts->fInnerRadius = innerRadius; | 1029 verts->fInnerRadius = innerRadius; |
1030 verts++; | 1030 verts++; |
1031 } | 1031 } |
1032 | 1032 |
1033 // drop out the middle quad if we're stroked | 1033 // drop out the middle quad if we're stroked |
1034 int indexCnt = isStroked ? GR_ARRAY_COUNT(gRRectIndices)-6 : GR_ARRAY_CO
UNT(gRRectIndices); | 1034 int indexCnt = isStroked ? SK_ARRAY_COUNT(gRRectIndices)-6 : SK_ARRAY_CO
UNT(gRRectIndices); |
1035 target->setIndexSourceToBuffer(indexBuffer); | 1035 target->setIndexSourceToBuffer(indexBuffer); |
1036 target->drawIndexed(kTriangles_GrPrimitiveType, 0, 0, 16, indexCnt, &bou
nds); | 1036 target->drawIndexed(kTriangles_GrPrimitiveType, 0, 0, 16, indexCnt, &bou
nds); |
1037 | 1037 |
1038 // otherwise we use the ellipse renderer | 1038 // otherwise we use the ellipse renderer |
1039 } else { | 1039 } else { |
1040 drawState->setVertexAttribs<gEllipseVertexAttribs>(SK_ARRAY_COUNT(gEllip
seVertexAttribs)); | 1040 drawState->setVertexAttribs<gEllipseVertexAttribs>(SK_ARRAY_COUNT(gEllip
seVertexAttribs)); |
1041 SkASSERT(sizeof(EllipseVertex) == drawState->getVertexSize()); | 1041 SkASSERT(sizeof(EllipseVertex) == drawState->getVertexSize()); |
1042 | 1042 |
1043 SkScalar innerXRadius = 0.0f; | 1043 SkScalar innerXRadius = 0.0f; |
1044 SkScalar innerYRadius = 0.0f; | 1044 SkScalar innerYRadius = 0.0f; |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1133 verts++; | 1133 verts++; |
1134 | 1134 |
1135 verts->fPos = SkPoint::Make(bounds.fRight, yCoords[i]); | 1135 verts->fPos = SkPoint::Make(bounds.fRight, yCoords[i]); |
1136 verts->fOffset = SkPoint::Make(xOuterRadius, yOuterOffsets[i]); | 1136 verts->fOffset = SkPoint::Make(xOuterRadius, yOuterOffsets[i]); |
1137 verts->fOuterRadii = SkPoint::Make(xRadRecip, yRadRecip); | 1137 verts->fOuterRadii = SkPoint::Make(xRadRecip, yRadRecip); |
1138 verts->fInnerRadii = SkPoint::Make(xInnerRadRecip, yInnerRadRecip); | 1138 verts->fInnerRadii = SkPoint::Make(xInnerRadRecip, yInnerRadRecip); |
1139 verts++; | 1139 verts++; |
1140 } | 1140 } |
1141 | 1141 |
1142 // drop out the middle quad if we're stroked | 1142 // drop out the middle quad if we're stroked |
1143 int indexCnt = isStroked ? GR_ARRAY_COUNT(gRRectIndices)-6 : GR_ARRAY_CO
UNT(gRRectIndices); | 1143 int indexCnt = isStroked ? SK_ARRAY_COUNT(gRRectIndices)-6 : SK_ARRAY_CO
UNT(gRRectIndices); |
1144 target->setIndexSourceToBuffer(indexBuffer); | 1144 target->setIndexSourceToBuffer(indexBuffer); |
1145 target->drawIndexed(kTriangles_GrPrimitiveType, 0, 0, 16, indexCnt, &bou
nds); | 1145 target->drawIndexed(kTriangles_GrPrimitiveType, 0, 0, 16, indexCnt, &bou
nds); |
1146 } | 1146 } |
1147 | 1147 |
1148 return true; | 1148 return true; |
1149 } | 1149 } |
OLD | NEW |