Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(41)

Side by Side Diff: src/gpu/GrOvalRenderer.cpp

Issue 59903005: Fix for thin filled and hairline roundrects. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 891 matching lines...) Expand 10 before | Expand all | Expand 10 after
902 902
903 SkVector radii = rrect.getSimpleRadii(); 903 SkVector radii = rrect.getSimpleRadii();
904 SkScalar xRadius = SkScalarAbs(vm[SkMatrix::kMScaleX]*radii.fX + 904 SkScalar xRadius = SkScalarAbs(vm[SkMatrix::kMScaleX]*radii.fX +
905 vm[SkMatrix::kMSkewY]*radii.fY); 905 vm[SkMatrix::kMSkewY]*radii.fY);
906 SkScalar yRadius = SkScalarAbs(vm[SkMatrix::kMSkewX]*radii.fX + 906 SkScalar yRadius = SkScalarAbs(vm[SkMatrix::kMSkewX]*radii.fX +
907 vm[SkMatrix::kMScaleY]*radii.fY); 907 vm[SkMatrix::kMScaleY]*radii.fY);
908 908
909 // if hairline stroke is greater than radius, we don't handle that right now 909 // if hairline stroke is greater than radius, we don't handle that right now
910 SkStrokeRec::Style style = stroke.getStyle(); 910 SkStrokeRec::Style style = stroke.getStyle();
911 if (SkStrokeRec::kHairline_Style == style && 911 if (SkStrokeRec::kHairline_Style == style &&
912 (SK_ScalarHalf >= xRadius || SK_ScalarHalf >= yRadius)) { 912 (SK_ScalarHalf > xRadius || SK_ScalarHalf > yRadius)) {
913 return false; 913 return false;
914 } 914 }
915 915
916 // do (potentially) anisotropic mapping of stroke 916 // do (potentially) anisotropic mapping of stroke
917 SkVector scaledStroke; 917 SkVector scaledStroke;
918 SkScalar strokeWidth = stroke.getWidth(); 918 SkScalar strokeWidth = stroke.getWidth();
919 scaledStroke.fX = SkScalarAbs(strokeWidth*(vm[SkMatrix::kMScaleX] + vm[SkMat rix::kMSkewY])); 919 scaledStroke.fX = SkScalarAbs(strokeWidth*(vm[SkMatrix::kMScaleX] + vm[SkMat rix::kMSkewY]));
920 scaledStroke.fY = SkScalarAbs(strokeWidth*(vm[SkMatrix::kMSkewX] + vm[SkMatr ix::kMScaleY])); 920 scaledStroke.fY = SkScalarAbs(strokeWidth*(vm[SkMatrix::kMSkewX] + vm[SkMatr ix::kMScaleY]));
921 921
922 // if half of strokewidth is greater than radius, we don't handle that right now 922 // if half of strokewidth is greater than radius, we don't handle that right now
923 if (SK_ScalarHalf*scaledStroke.fX >= xRadius || SK_ScalarHalf*scaledStroke.f Y >= yRadius) { 923 if (SK_ScalarHalf*scaledStroke.fX > xRadius || SK_ScalarHalf*scaledStroke.fY > yRadius) {
924 return false; 924 return false;
925 } 925 }
926 926
927 // reset to device coordinates 927 // reset to device coordinates
928 GrDrawState* drawState = target->drawState(); 928 GrDrawState* drawState = target->drawState();
929 GrDrawState::AutoViewMatrixRestore avmr; 929 GrDrawState::AutoViewMatrixRestore avmr;
930 if (!avmr.setIdentity(drawState)) { 930 if (!avmr.setIdentity(drawState)) {
931 return false; 931 return false;
932 } 932 }
933 933
(...skipping 27 matching lines...) Expand all
961 halfWidth = SkScalarHalf(scaledStroke.fX); 961 halfWidth = SkScalarHalf(scaledStroke.fX);
962 } 962 }
963 963
964 if (isStroked) { 964 if (isStroked) {
965 innerRadius = xRadius - halfWidth; 965 innerRadius = xRadius - halfWidth;
966 } 966 }
967 outerRadius += halfWidth; 967 outerRadius += halfWidth;
968 bounds.outset(halfWidth, halfWidth); 968 bounds.outset(halfWidth, halfWidth);
969 } 969 }
970 970
971 isStroked = (isStroked && innerRadius > 0); 971 isStroked = (isStroked && innerRadius >= 0);
972 972
973 GrEffectRef* effect = CircleEdgeEffect::Create(isStroked); 973 GrEffectRef* effect = CircleEdgeEffect::Create(isStroked);
974 static const int kCircleEdgeAttrIndex = 1; 974 static const int kCircleEdgeAttrIndex = 1;
975 drawState->addCoverageEffect(effect, kCircleEdgeAttrIndex)->unref(); 975 drawState->addCoverageEffect(effect, kCircleEdgeAttrIndex)->unref();
976 976
977 // The radii are outset for two reasons. First, it allows the shader to simply perform 977 // The radii are outset for two reasons. First, it allows the shader to simply perform
978 // clamp(distance-to-center - radius, 0, 1). Second, the outer radius is used to compute the 978 // clamp(distance-to-center - radius, 0, 1). Second, the outer radius is used to compute the
979 // verts of the bounding box that is rendered and the outset ensures the box will cover all 979 // verts of the bounding box that is rendered and the outset ensures the box will cover all
980 // pixels partially covered by the circle. 980 // pixels partially covered by the circle.
981 outerRadius += SK_ScalarHalf; 981 outerRadius += SK_ScalarHalf;
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
1057 if (isStroked) { 1057 if (isStroked) {
1058 innerXRadius = xRadius - scaledStroke.fX; 1058 innerXRadius = xRadius - scaledStroke.fX;
1059 innerYRadius = yRadius - scaledStroke.fY; 1059 innerYRadius = yRadius - scaledStroke.fY;
1060 } 1060 }
1061 1061
1062 xRadius += scaledStroke.fX; 1062 xRadius += scaledStroke.fX;
1063 yRadius += scaledStroke.fY; 1063 yRadius += scaledStroke.fY;
1064 bounds.outset(scaledStroke.fX, scaledStroke.fY); 1064 bounds.outset(scaledStroke.fX, scaledStroke.fY);
1065 } 1065 }
1066 1066
1067 isStroked = (isStroked && innerXRadius > 0 && innerYRadius > 0); 1067 isStroked = (isStroked && innerXRadius >= 0 && innerYRadius >= 0);
1068 1068
1069 GrDrawTarget::AutoReleaseGeometry geo(target, 16, 0); 1069 GrDrawTarget::AutoReleaseGeometry geo(target, 16, 0);
1070 if (!geo.succeeded()) { 1070 if (!geo.succeeded()) {
1071 GrPrintf("Failed to get space for vertices!\n"); 1071 GrPrintf("Failed to get space for vertices!\n");
1072 return false; 1072 return false;
1073 } 1073 }
1074 EllipseVertex* verts = reinterpret_cast<EllipseVertex*>(geo.vertices()); 1074 EllipseVertex* verts = reinterpret_cast<EllipseVertex*>(geo.vertices());
1075 1075
1076 GrEffectRef* effect = EllipseEdgeEffect::Create(isStroked); 1076 GrEffectRef* effect = EllipseEdgeEffect::Create(isStroked);
1077 static const int kEllipseOffsetAttrIndex = 1; 1077 static const int kEllipseOffsetAttrIndex = 1;
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
1132 } 1132 }
1133 1133
1134 // drop out the middle quad if we're stroked 1134 // drop out the middle quad if we're stroked
1135 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);
1136 target->setIndexSourceToBuffer(indexBuffer); 1136 target->setIndexSourceToBuffer(indexBuffer);
1137 target->drawIndexed(kTriangles_GrPrimitiveType, 0, 0, 16, indexCnt, &bou nds); 1137 target->drawIndexed(kTriangles_GrPrimitiveType, 0, 0, 16, indexCnt, &bou nds);
1138 } 1138 }
1139 1139
1140 return true; 1140 return true;
1141 } 1141 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698