| 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" |
| (...skipping 512 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 523 GrDrawState::AutoViewMatrixRestore avmr; | 523 GrDrawState::AutoViewMatrixRestore avmr; |
| 524 if (!avmr.setIdentity(drawState)) { | 524 if (!avmr.setIdentity(drawState)) { |
| 525 return; | 525 return; |
| 526 } | 526 } |
| 527 | 527 |
| 528 drawState->setVertexAttribs<gCircleVertexAttribs>(SK_ARRAY_COUNT(gCircleVert
exAttribs), | 528 drawState->setVertexAttribs<gCircleVertexAttribs>(SK_ARRAY_COUNT(gCircleVert
exAttribs), |
| 529 sizeof(CircleVertex)); | 529 sizeof(CircleVertex)); |
| 530 | 530 |
| 531 GrDrawTarget::AutoReleaseGeometry geo(target, 4, 0); | 531 GrDrawTarget::AutoReleaseGeometry geo(target, 4, 0); |
| 532 if (!geo.succeeded()) { | 532 if (!geo.succeeded()) { |
| 533 GrPrintf("Failed to get space for vertices!\n"); | 533 SkDebugf("Failed to get space for vertices!\n"); |
| 534 return; | 534 return; |
| 535 } | 535 } |
| 536 | 536 |
| 537 CircleVertex* verts = reinterpret_cast<CircleVertex*>(geo.vertices()); | 537 CircleVertex* verts = reinterpret_cast<CircleVertex*>(geo.vertices()); |
| 538 | 538 |
| 539 SkStrokeRec::Style style = stroke.getStyle(); | 539 SkStrokeRec::Style style = stroke.getStyle(); |
| 540 bool isStrokeOnly = SkStrokeRec::kStroke_Style == style || | 540 bool isStrokeOnly = SkStrokeRec::kStroke_Style == style || |
| 541 SkStrokeRec::kHairline_Style == style; | 541 SkStrokeRec::kHairline_Style == style; |
| 542 bool hasStroke = isStrokeOnly || SkStrokeRec::kStrokeAndFill_Style == style; | 542 bool hasStroke = isStrokeOnly || SkStrokeRec::kStrokeAndFill_Style == style; |
| 543 | 543 |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 686 GrDrawState::AutoViewMatrixRestore avmr; | 686 GrDrawState::AutoViewMatrixRestore avmr; |
| 687 if (!avmr.setIdentity(drawState)) { | 687 if (!avmr.setIdentity(drawState)) { |
| 688 return false; | 688 return false; |
| 689 } | 689 } |
| 690 | 690 |
| 691 drawState->setVertexAttribs<gEllipseVertexAttribs>(SK_ARRAY_COUNT(gEllipseVe
rtexAttribs), | 691 drawState->setVertexAttribs<gEllipseVertexAttribs>(SK_ARRAY_COUNT(gEllipseVe
rtexAttribs), |
| 692 sizeof(EllipseVertex)); | 692 sizeof(EllipseVertex)); |
| 693 | 693 |
| 694 GrDrawTarget::AutoReleaseGeometry geo(target, 4, 0); | 694 GrDrawTarget::AutoReleaseGeometry geo(target, 4, 0); |
| 695 if (!geo.succeeded()) { | 695 if (!geo.succeeded()) { |
| 696 GrPrintf("Failed to get space for vertices!\n"); | 696 SkDebugf("Failed to get space for vertices!\n"); |
| 697 return false; | 697 return false; |
| 698 } | 698 } |
| 699 | 699 |
| 700 EllipseVertex* verts = reinterpret_cast<EllipseVertex*>(geo.vertices()); | 700 EllipseVertex* verts = reinterpret_cast<EllipseVertex*>(geo.vertices()); |
| 701 | 701 |
| 702 GrGeometryProcessor* gp = EllipseEdgeEffect::Create(isStrokeOnly && | 702 GrGeometryProcessor* gp = EllipseEdgeEffect::Create(isStrokeOnly && |
| 703 innerXRadius > 0 && inne
rYRadius > 0); | 703 innerXRadius > 0 && inne
rYRadius > 0); |
| 704 | 704 |
| 705 drawState->setGeometryProcessor(gp)->unref(); | 705 drawState->setGeometryProcessor(gp)->unref(); |
| 706 | 706 |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 806 DIEllipseEdgeEffect::kFi
ll; | 806 DIEllipseEdgeEffect::kFi
ll; |
| 807 } | 807 } |
| 808 SkScalar innerRatioX = SkScalarDiv(xRadius, innerXRadius); | 808 SkScalar innerRatioX = SkScalarDiv(xRadius, innerXRadius); |
| 809 SkScalar innerRatioY = SkScalarDiv(yRadius, innerYRadius); | 809 SkScalar innerRatioY = SkScalarDiv(yRadius, innerYRadius); |
| 810 | 810 |
| 811 drawState->setVertexAttribs<gDIEllipseVertexAttribs>(SK_ARRAY_COUNT(gDIEllip
seVertexAttribs), | 811 drawState->setVertexAttribs<gDIEllipseVertexAttribs>(SK_ARRAY_COUNT(gDIEllip
seVertexAttribs), |
| 812 sizeof(DIEllipseVertex)
); | 812 sizeof(DIEllipseVertex)
); |
| 813 | 813 |
| 814 GrDrawTarget::AutoReleaseGeometry geo(target, 4, 0); | 814 GrDrawTarget::AutoReleaseGeometry geo(target, 4, 0); |
| 815 if (!geo.succeeded()) { | 815 if (!geo.succeeded()) { |
| 816 GrPrintf("Failed to get space for vertices!\n"); | 816 SkDebugf("Failed to get space for vertices!\n"); |
| 817 return false; | 817 return false; |
| 818 } | 818 } |
| 819 | 819 |
| 820 DIEllipseVertex* verts = reinterpret_cast<DIEllipseVertex*>(geo.vertices()); | 820 DIEllipseVertex* verts = reinterpret_cast<DIEllipseVertex*>(geo.vertices()); |
| 821 | 821 |
| 822 GrGeometryProcessor* gp = DIEllipseEdgeEffect::Create(mode); | 822 GrGeometryProcessor* gp = DIEllipseEdgeEffect::Create(mode); |
| 823 | 823 |
| 824 drawState->setGeometryProcessor(gp)->unref(); | 824 drawState->setGeometryProcessor(gp)->unref(); |
| 825 | 825 |
| 826 // This expands the outer rect so that after CTM we end up with a half-pixel
border | 826 // This expands the outer rect so that after CTM we end up with a half-pixel
border |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1036 | 1036 |
| 1037 // reset to device coordinates | 1037 // reset to device coordinates |
| 1038 GrDrawState* drawState = target->drawState(); | 1038 GrDrawState* drawState = target->drawState(); |
| 1039 GrDrawState::AutoViewMatrixRestore avmr; | 1039 GrDrawState::AutoViewMatrixRestore avmr; |
| 1040 if (!avmr.setIdentity(drawState)) { | 1040 if (!avmr.setIdentity(drawState)) { |
| 1041 return false; | 1041 return false; |
| 1042 } | 1042 } |
| 1043 | 1043 |
| 1044 GrIndexBuffer* indexBuffer = this->rRectIndexBuffer(isStrokeOnly, context->g
etGpu()); | 1044 GrIndexBuffer* indexBuffer = this->rRectIndexBuffer(isStrokeOnly, context->g
etGpu()); |
| 1045 if (NULL == indexBuffer) { | 1045 if (NULL == indexBuffer) { |
| 1046 GrPrintf("Failed to create index buffer!\n"); | 1046 SkDebugf("Failed to create index buffer!\n"); |
| 1047 return false; | 1047 return false; |
| 1048 } | 1048 } |
| 1049 | 1049 |
| 1050 // if the corners are circles, use the circle renderer | 1050 // if the corners are circles, use the circle renderer |
| 1051 if ((!hasStroke || scaledStroke.fX == scaledStroke.fY) && xRadius == yRadius
) { | 1051 if ((!hasStroke || scaledStroke.fX == scaledStroke.fY) && xRadius == yRadius
) { |
| 1052 drawState->setVertexAttribs<gCircleVertexAttribs>(SK_ARRAY_COUNT(gCircle
VertexAttribs), | 1052 drawState->setVertexAttribs<gCircleVertexAttribs>(SK_ARRAY_COUNT(gCircle
VertexAttribs), |
| 1053 sizeof(CircleVertex)); | 1053 sizeof(CircleVertex)); |
| 1054 | 1054 |
| 1055 GrDrawTarget::AutoReleaseGeometry geo(target, 16, 0); | 1055 GrDrawTarget::AutoReleaseGeometry geo(target, 16, 0); |
| 1056 if (!geo.succeeded()) { | 1056 if (!geo.succeeded()) { |
| 1057 GrPrintf("Failed to get space for vertices!\n"); | 1057 SkDebugf("Failed to get space for vertices!\n"); |
| 1058 return false; | 1058 return false; |
| 1059 } | 1059 } |
| 1060 CircleVertex* verts = reinterpret_cast<CircleVertex*>(geo.vertices()); | 1060 CircleVertex* verts = reinterpret_cast<CircleVertex*>(geo.vertices()); |
| 1061 | 1061 |
| 1062 SkScalar innerRadius = 0.0f; | 1062 SkScalar innerRadius = 0.0f; |
| 1063 SkScalar outerRadius = xRadius; | 1063 SkScalar outerRadius = xRadius; |
| 1064 SkScalar halfWidth = 0; | 1064 SkScalar halfWidth = 0; |
| 1065 if (hasStroke) { | 1065 if (hasStroke) { |
| 1066 if (SkScalarNearlyZero(scaledStroke.fX)) { | 1066 if (SkScalarNearlyZero(scaledStroke.fX)) { |
| 1067 halfWidth = SK_ScalarHalf; | 1067 halfWidth = SK_ScalarHalf; |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1169 | 1169 |
| 1170 xRadius += scaledStroke.fX; | 1170 xRadius += scaledStroke.fX; |
| 1171 yRadius += scaledStroke.fY; | 1171 yRadius += scaledStroke.fY; |
| 1172 bounds.outset(scaledStroke.fX, scaledStroke.fY); | 1172 bounds.outset(scaledStroke.fX, scaledStroke.fY); |
| 1173 } | 1173 } |
| 1174 | 1174 |
| 1175 isStrokeOnly = (isStrokeOnly && innerXRadius >= 0 && innerYRadius >= 0); | 1175 isStrokeOnly = (isStrokeOnly && innerXRadius >= 0 && innerYRadius >= 0); |
| 1176 | 1176 |
| 1177 GrDrawTarget::AutoReleaseGeometry geo(target, 16, 0); | 1177 GrDrawTarget::AutoReleaseGeometry geo(target, 16, 0); |
| 1178 if (!geo.succeeded()) { | 1178 if (!geo.succeeded()) { |
| 1179 GrPrintf("Failed to get space for vertices!\n"); | 1179 SkDebugf("Failed to get space for vertices!\n"); |
| 1180 return false; | 1180 return false; |
| 1181 } | 1181 } |
| 1182 EllipseVertex* verts = reinterpret_cast<EllipseVertex*>(geo.vertices()); | 1182 EllipseVertex* verts = reinterpret_cast<EllipseVertex*>(geo.vertices()); |
| 1183 | 1183 |
| 1184 GrGeometryProcessor* effect = EllipseEdgeEffect::Create(isStrokeOnly); | 1184 GrGeometryProcessor* effect = EllipseEdgeEffect::Create(isStrokeOnly); |
| 1185 drawState->setGeometryProcessor(effect)->unref(); | 1185 drawState->setGeometryProcessor(effect)->unref(); |
| 1186 | 1186 |
| 1187 // Compute the reciprocals of the radii here to save time in the shader | 1187 // Compute the reciprocals of the radii here to save time in the shader |
| 1188 SkScalar xRadRecip = SkScalarInvert(xRadius); | 1188 SkScalar xRadRecip = SkScalarInvert(xRadius); |
| 1189 SkScalar yRadRecip = SkScalarInvert(yRadius); | 1189 SkScalar yRadRecip = SkScalarInvert(yRadius); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1239 // drop out the middle quad if we're stroked | 1239 // drop out the middle quad if we're stroked |
| 1240 int indexCnt = isStrokeOnly ? SK_ARRAY_COUNT(gRRectIndices) - 6 : | 1240 int indexCnt = isStrokeOnly ? SK_ARRAY_COUNT(gRRectIndices) - 6 : |
| 1241 SK_ARRAY_COUNT(gRRectIndices); | 1241 SK_ARRAY_COUNT(gRRectIndices); |
| 1242 target->setIndexSourceToBuffer(indexBuffer); | 1242 target->setIndexSourceToBuffer(indexBuffer); |
| 1243 target->drawIndexedInstances(kTriangles_GrPrimitiveType, 1, 16, indexCnt
, &bounds); | 1243 target->drawIndexedInstances(kTriangles_GrPrimitiveType, 1, 16, indexCnt
, &bounds); |
| 1244 } | 1244 } |
| 1245 | 1245 |
| 1246 target->resetIndexSource(); | 1246 target->resetIndexSource(); |
| 1247 return true; | 1247 return true; |
| 1248 } | 1248 } |
| OLD | NEW |