From 2436f191e6602953b32a51cf50f2d7a4e2af90fd Mon Sep 17 00:00:00 2001 From: ethannicholas Date: Thu, 25 Jun 2015 14:42:34 -0700 Subject: [PATCH] added stroking support to GrAALinearizingConvexPathRenderer BUG=skia: Review URL: https://codereview.chromium.org/1180903006 --- src/core/SkPathPriv.h | 4 + src/gpu/GrAAConvexPathRenderer.cpp | 7 +- src/gpu/GrAAConvexTessellator.cpp | 602 ++++++++++++++------------ src/gpu/GrAAConvexTessellator.h | 61 +-- src/gpu/GrAALinearizingConvexPathRenderer.cpp | 45 +- src/gpu/GrAddPathRenderers_default.cpp | 4 +- 6 files changed, 392 insertions(+), 331 deletions(-) diff --git a/src/core/SkPathPriv.h b/src/core/SkPathPriv.h index 98e50e3..934c730 100644 --- a/src/core/SkPathPriv.h +++ b/src/core/SkPathPriv.h @@ -55,6 +55,10 @@ public: return computedDir == dir; } + static bool LastVerbIsClose(const SkPath& path) { + int count = path.countVerbs(); + return count >= 1 && path.fPathRef->verbs()[~(count - 1)] == SkPath::Verb::kClose_Verb; + } }; #endif diff --git a/src/gpu/GrAAConvexPathRenderer.cpp b/src/gpu/GrAAConvexPathRenderer.cpp index 4e3d859..5299475 100644 --- a/src/gpu/GrAAConvexPathRenderer.cpp +++ b/src/gpu/GrAAConvexPathRenderer.cpp @@ -707,16 +707,15 @@ static void extract_verts(const GrAAConvexTessellator& tess, // Make 'verts' point to the colors verts += sizeof(SkPoint); for (int i = 0; i < tess.numPts(); ++i) { - SkASSERT(tess.depth(i) >= -0.5f && tess.depth(i) <= 0.5f); if (tweakAlphaForCoverage) { - SkASSERT(SkScalarRoundToInt(255.0f * (tess.depth(i) + 0.5f)) <= 255); - unsigned scale = SkScalarRoundToInt(255.0f * (tess.depth(i) + 0.5f)); + SkASSERT(SkScalarRoundToInt(255.0f * tess.coverage(i)) <= 255); + unsigned scale = SkScalarRoundToInt(255.0f * tess.coverage(i)); GrColor scaledColor = (0xff == scale) ? color : SkAlphaMulQ(color, scale); *reinterpret_cast(verts + i * vertexStride) = scaledColor; } else { *reinterpret_cast(verts + i * vertexStride) = color; *reinterpret_cast(verts + i * vertexStride + sizeof(GrColor)) = - tess.depth(i) + 0.5f; + tess.coverage(i); } } diff --git a/src/gpu/GrAAConvexTessellator.cpp b/src/gpu/GrAAConvexTessellator.cpp index 56a408d..85ce7ba 100644 --- a/src/gpu/GrAAConvexTessellator.cpp +++ b/src/gpu/GrAAConvexTessellator.cpp @@ -13,7 +13,6 @@ #include "GrPathUtils.h" // Next steps: -// use in AAConvexPathRenderer // add an interactive sample app slide // add debug check that all points are suitably far apart // test more degenerate cases @@ -22,10 +21,17 @@ static const SkScalar kClose = (SK_Scalar1 / 16); static const SkScalar kCloseSqd = SkScalarMul(kClose, kClose); +// tesselation tolerance values, in device space pixels +static const SkScalar kQuadTolerance = 0.2f; +static const SkScalar kCubicTolerance = 0.2f; +static const SkScalar kConicTolerance = 0.5f; + +// dot product below which we use a round cap between curve segments +static const SkScalar kRoundCapThreshold = 0.8f; + static SkScalar intersect(const SkPoint& p0, const SkPoint& n0, const SkPoint& p1, const SkPoint& n1) { const SkPoint v = p1 - p0; - SkScalar perpDot = n0.fX * n1.fY - n0.fY * n1.fX; return (v.fX * n1.fY - v.fY * n1.fX) / perpDot; } @@ -52,13 +58,14 @@ static SkScalar abs_dist_from_line(const SkPoint& p0, const SkVector& v, const S int GrAAConvexTessellator::addPt(const SkPoint& pt, SkScalar depth, + SkScalar coverage, bool movable, bool isCurve) { this->validate(); int index = fPts.count(); *fPts.push() = pt; - *fDepths.push() = depth; + *fCoverages.push() = coverage; *fMovable.push() = movable; *fIsCurve.push() = isCurve; @@ -70,7 +77,7 @@ void GrAAConvexTessellator::popLastPt() { this->validate(); fPts.pop(); - fDepths.pop(); + fCoverages.pop(); fMovable.pop(); this->validate(); @@ -80,7 +87,7 @@ void GrAAConvexTessellator::popFirstPtShuffle() { this->validate(); fPts.removeShuffle(0); - fDepths.removeShuffle(0); + fCoverages.removeShuffle(0); fMovable.removeShuffle(0); this->validate(); @@ -88,12 +95,13 @@ void GrAAConvexTessellator::popFirstPtShuffle() { void GrAAConvexTessellator::updatePt(int index, const SkPoint& pt, - SkScalar depth) { + SkScalar depth, + SkScalar coverage) { this->validate(); SkASSERT(fMovable[index]); fPts[index] = pt; - fDepths[index] = depth; + fCoverages[index] = coverage; } void GrAAConvexTessellator::addTri(int i0, int i1, int i2) { @@ -108,7 +116,7 @@ void GrAAConvexTessellator::addTri(int i0, int i1, int i2) { void GrAAConvexTessellator::rewind() { fPts.rewind(); - fDepths.rewind(); + fCoverages.rewind(); fMovable.rewind(); fIndices.rewind(); fNorms.rewind(); @@ -143,6 +151,44 @@ void GrAAConvexTessellator::computeBisectors() { } } +// Create as many rings as we need to (up to a predefined limit) to reach the specified target +// depth. If we are in fill mode, the final ring will automatically be fanned. +bool GrAAConvexTessellator::createInsetRings(Ring& previousRing, SkScalar initialDepth, + SkScalar initialCoverage, SkScalar targetDepth, + SkScalar targetCoverage, Ring** finalRing) { + static const int kMaxNumRings = 8; + + if (previousRing.numPts() < 3) { + return false; + } + Ring* currentRing = &previousRing; + int i; + for (i = 0; i < kMaxNumRings; ++i) { + Ring* nextRing = this->getNextRing(currentRing); + SkASSERT(nextRing != currentRing); + + bool done = this->createInsetRing(*currentRing, nextRing, initialDepth, initialCoverage, + targetDepth, targetCoverage, i == 0); + currentRing = nextRing; + if (done) { + break; + } + currentRing->init(*this); + } + + if (kMaxNumRings == i) { + // Bail if we've exceeded the amount of time we want to throw at this. + this->terminate(*currentRing); + return false; + } + bool done = currentRing->numPts() >= 3; + if (done) { + currentRing->init(*this); + } + *finalRing = currentRing; + return done; +} + // The general idea here is to, conceptually, start with the original polygon and slide // the vertices along the bisectors until the first intersection. At that // point two of the edges collapse and the process repeats on the new polygon. @@ -150,46 +196,40 @@ void GrAAConvexTessellator::computeBisectors() { // controls the iteration. The CandidateVerts holds the formative points for the // next ring. bool GrAAConvexTessellator::tessellate(const SkMatrix& m, const SkPath& path) { - static const int kMaxNumRings = 8; - - SkDEBUGCODE(fShouldCheckDepths = true;) - if (!this->extractFromPath(m, path)) { return false; } - this->createOuterRing(); + SkScalar coverage = 1.0f; + if (fStrokeWidth >= 0.0f) { + Ring outerStrokeRing; + this->createOuterRing(fInitialRing, fStrokeWidth / 2 - kAntialiasingRadius, coverage, + &outerStrokeRing); + outerStrokeRing.init(*this); + Ring outerAARing; + this->createOuterRing(outerStrokeRing, kAntialiasingRadius * 2, 0.0f, &outerAARing); + } else { + Ring outerAARing; + this->createOuterRing(fInitialRing, kAntialiasingRadius, 0.0f, &outerAARing); + } // the bisectors are only needed for the computation of the outer ring fBisectors.rewind(); - - Ring* lastRing = &fInitialRing; - int i; - for (i = 0; i < kMaxNumRings; ++i) { - Ring* nextRing = this->getNextRing(lastRing); - - if (this->createInsetRing(*lastRing, nextRing)) { - break; + if (fStrokeWidth >= 0.0f && fInitialRing.numPts() > 2) { + Ring* insetStrokeRing; + SkScalar strokeDepth = fStrokeWidth / 2 - kAntialiasingRadius; + if (this->createInsetRings(fInitialRing, 0.0f, coverage, strokeDepth, coverage, + &insetStrokeRing)) { + Ring* insetAARing; + this->createInsetRings(*insetStrokeRing, strokeDepth, coverage, strokeDepth + + kAntialiasingRadius * 2, 0.0f, &insetAARing); } - - nextRing->init(*this); - lastRing = nextRing; - } - - if (kMaxNumRings == i) { - // If we've exceeded the amount of time we want to throw at this, set - // the depth of all points in the final ring to 'fTargetDepth' and - // create a fan. - this->terminate(*lastRing); - SkDEBUGCODE(fShouldCheckDepths = false;) + } else { + Ring* insetAARing; + this->createInsetRings(fInitialRing, 0.0f, 0.5f, kAntialiasingRadius, 1.0f, &insetAARing); } -#ifdef SK_DEBUG - this->validate(); - if (fShouldCheckDepths) { - SkDEBUGCODE(this->checkAllDepths();) - } -#endif + SkDEBUGCODE(this->validate();) return true; } @@ -198,7 +238,6 @@ SkScalar GrAAConvexTessellator::computeDepthFromEdge(int edgeIdx, const SkPoint& SkPoint v = p - fPts[edgeIdx]; SkScalar depth = -fNorms[edgeIdx].dot(v); - SkASSERT(depth >= 0.0f); return depth; } @@ -213,13 +252,13 @@ bool GrAAConvexTessellator::computePtAlongBisector(int startIdx, // First find the point where the edge and the bisector intersect SkPoint newP; + SkScalar t = perp_intersect(fPts[startIdx], bisector, fPts[edgeIdx], norm); if (SkScalarNearlyEqual(t, 0.0f)) { // the start point was one of the original ring points - SkASSERT(startIdx < fNorms.count()); + SkASSERT(startIdx < fPts.count()); newP = fPts[startIdx]; - } else if (t > 0.0f) { - SkASSERT(t < 0.0f); + } else if (t < 0.0f) { newP = bisector; newP.scale(t); newP += fPts[startIdx]; @@ -228,13 +267,12 @@ bool GrAAConvexTessellator::computePtAlongBisector(int startIdx, } // Then offset along the bisector from that point the correct distance - t = -desiredDepth / bisector.dot(norm); - SkASSERT(t > 0.0f); + SkScalar dot = bisector.dot(norm); + t = -desiredDepth / dot; *result = bisector; result->scale(t); *result += newP; - return true; } @@ -252,9 +290,6 @@ bool GrAAConvexTessellator::extractFromPath(const SkMatrix& m, const SkPath& pat fNorms.setReserve(path.countPoints()); - SkDEBUGCODE(fMinCross = SK_ScalarMax;) - SkDEBUGCODE(fMaxCross = -SK_ScalarMax;) - // TODO: is there a faster way to extract the points from the path? Perhaps // get all the points via a new entry point, transform them all in bulk // and then walk them to find duplicates? @@ -282,7 +317,7 @@ bool GrAAConvexTessellator::extractFromPath(const SkMatrix& m, const SkPath& pat } } - if (this->numPts() < 3) { + if (this->numPts() < 2) { return false; } @@ -293,23 +328,20 @@ bool GrAAConvexTessellator::extractFromPath(const SkMatrix& m, const SkPath& pat } SkASSERT(fPts.count() == fNorms.count()+1); - if (this->numPts() >= 3 && - abs_dist_from_line(fPts.top(), fNorms.top(), fPts[0]) < kClose) { - // The last point is on the line from the second to last to the first point. - this->popLastPt(); - fNorms.pop(); - } + if (this->numPts() >= 3) { + if (abs_dist_from_line(fPts.top(), fNorms.top(), fPts[0]) < kClose) { + // The last point is on the line from the second to last to the first point. + this->popLastPt(); + fNorms.pop(); + } - if (this->numPts() < 3) { - return false; + *fNorms.push() = fPts[0] - fPts.top(); + SkDEBUGCODE(SkScalar len =) SkPoint::Normalize(&fNorms.top()); + SkASSERT(len > 0.0f); + SkASSERT(fPts.count() == fNorms.count()); } - *fNorms.push() = fPts[0] - fPts.top(); - SkDEBUGCODE(SkScalar len =) SkPoint::Normalize(&fNorms.top()); - SkASSERT(len > 0.0f); - SkASSERT(fPts.count() == fNorms.count()); - - if (abs_dist_from_line(fPts[0], fNorms.top(), fPts[1]) < kClose) { + if (this->numPts() >= 3 && abs_dist_from_line(fPts[0], fNorms.top(), fPts[1]) < kClose) { // The first point is on the line from the last to the second. this->popFirstPtShuffle(); fNorms.removeShuffle(0); @@ -319,28 +351,44 @@ bool GrAAConvexTessellator::extractFromPath(const SkMatrix& m, const SkPath& pat SkASSERT(SkScalarNearlyEqual(1.0f, fNorms[0].length())); } - if (this->numPts() < 3) { - return false; - } + if (this->numPts() >= 3) { + // Check the cross product of the final trio + SkScalar cross = SkPoint::CrossProduct(fNorms[0], fNorms.top()); + if (cross > 0.0f) { + fSide = SkPoint::kRight_Side; + } else { + fSide = SkPoint::kLeft_Side; + } - // Check the cross product of the final trio - SkScalar cross = SkPoint::CrossProduct(fNorms[0], fNorms.top()); - SkDEBUGCODE(fMaxCross = SkTMax(fMaxCross, cross)); - SkDEBUGCODE(fMinCross = SkTMin(fMinCross, cross)); - SkASSERT((fMaxCross >= 0.0f) == (fMinCross >= 0.0f)); - if (cross > 0.0f) { - fSide = SkPoint::kRight_Side; - } else { + // Make all the normals face outwards rather than along the edge + for (int cur = 0; cur < fNorms.count(); ++cur) { + fNorms[cur].setOrthog(fNorms[cur], fSide); + SkASSERT(SkScalarNearlyEqual(1.0f, fNorms[cur].length())); + } + + this->computeBisectors(); + } else if (this->numPts() == 2) { + // We've got two points, so we're degenerate. + if (fStrokeWidth < 0.0f) { + // it's a fill, so we don't need to worry about degenerate paths + return false; + } + // For stroking, we still need to process the degenerate path, so fix it up fSide = SkPoint::kLeft_Side; - } - // Make all the normals face outwards rather than along the edge - for (int cur = 0; cur < fNorms.count(); ++cur) { - fNorms[cur].setOrthog(fNorms[cur], fSide); - SkASSERT(SkScalarNearlyEqual(1.0f, fNorms[cur].length())); - } + // Make all the normals face outwards rather than along the edge + for (int cur = 0; cur < fNorms.count(); ++cur) { + fNorms[cur].setOrthog(fNorms[cur], fSide); + SkASSERT(SkScalarNearlyEqual(1.0f, fNorms[cur].length())); + } - this->computeBisectors(); + fNorms.push(SkPoint::Make(-fNorms[0].fX, -fNorms[0].fY)); + // we won't actually use the bisectors, so just push zeroes + fBisectors.push(SkPoint::Make(0.0, 0.0)); + fBisectors.push(SkPoint::Make(0.0, 0.0)); + } else { + return false; + } fCandidateVerts.setReserve(this->numPts()); fInitialRing.setReserve(this->numPts()); @@ -370,138 +418,172 @@ GrAAConvexTessellator::Ring* GrAAConvexTessellator::getNextRing(Ring* lastRing) void GrAAConvexTessellator::fanRing(const Ring& ring) { // fan out from point 0 - for (int cur = 1; cur < ring.numPts()-1; ++cur) { - this->addTri(ring.index(0), ring.index(cur), ring.index(cur+1)); + int startIdx = ring.index(0); + for (int cur = ring.numPts() - 2; cur >= 0; --cur) { + this->addTri(startIdx, ring.index(cur), ring.index(cur + 1)); } } -void GrAAConvexTessellator::createOuterRing() { - // For now, we're only generating one outer ring (at the start). This - // could be relaxed for stroking use cases. - SkASSERT(0 == fIndices.count()); - SkASSERT(fPts.count() == fNorms.count()); - - const int numPts = fPts.count(); +void GrAAConvexTessellator::createOuterRing(const Ring& previousRing, SkScalar outset, + SkScalar coverage, Ring* nextRing) { + const int numPts = previousRing.numPts(); + if (numPts == 0) { + return; + } int prev = numPts - 1; - int lastPerpIdx = -1, firstPerpIdx = -1, newIdx0, newIdx1, newIdx2; - for (int cur = 0; cur < numPts; ++cur) { - if (fIsCurve[cur]) { - // Inside a curve, we assume that the curvature is shallow enough (due to tesselation) - // that we only need one corner point. Mathematically, the distance the corner point - // gets shifted out should depend on the angle between the two line segments (as in - // mitering), but again due to tesselation we assume that this angle is small and - // therefore the correction factor is negligible and we do not bother with it. - - // The bisector outset point - SkPoint temp = fBisectors[cur]; - temp.scale(-fTargetDepth); // the bisectors point in - temp += fPts[cur]; - - // double-check our "sufficiently flat" assumption; we want the bisector point to be - // close to the normal point. - #define kFlatnessTolerance 1.0f - SkDEBUGCODE(SkPoint prevNormal = fNorms[prev];) - SkDEBUGCODE(prevNormal.scale(fTargetDepth);) - SkDEBUGCODE(prevNormal += fPts[cur];) - SkASSERT((temp - prevNormal).length() < kFlatnessTolerance); - - newIdx1 = this->addPt(temp, -fTargetDepth, false, true); - - if (0 == cur) { - // Store the index of the first perpendicular point to finish up - firstPerpIdx = newIdx1; - SkASSERT(-1 == lastPerpIdx); - } else { - // The triangles for the previous edge - this->addTri(prev, newIdx1, cur); - this->addTri(prev, lastPerpIdx, newIdx1); - } + int lastPerpIdx = -1, firstPerpIdx = -1; - prev = cur; - // Track the last perpendicular outset point so we can construct the - // trailing edge triangles. - lastPerpIdx = newIdx1; + const SkScalar outsetSq = SkScalarMul(outset, outset); + SkScalar miterLimitSq = SkScalarMul(outset, fMiterLimit); + miterLimitSq = SkScalarMul(miterLimitSq, miterLimitSq); + for (int cur = 0; cur < numPts; ++cur) { + int originalIdx = previousRing.index(cur); + // For each vertex of the original polygon we add at least two points to the + // outset polygon - one extending perpendicular to each impinging edge. Connecting these + // two points yields a bevel join. We need one additional point for a mitered join, and + // a round join requires one or more points depending upon curvature. + + // The perpendicular point for the last edge + SkPoint normal1 = previousRing.norm(prev); + SkPoint perp1 = normal1; + perp1.scale(outset); + perp1 += this->point(originalIdx); + + // The perpendicular point for the next edge. + SkPoint normal2 = previousRing.norm(cur); + SkPoint perp2 = normal2; + perp2.scale(outset); + perp2 += fPts[originalIdx]; + + bool isCurve = fIsCurve[originalIdx]; + + // We know it isn't a duplicate of the prior point (since it and this + // one are just perpendicular offsets from the non-merged polygon points) + int perp1Idx = this->addPt(perp1, -outset, coverage, false, isCurve); + nextRing->addIdx(perp1Idx, originalIdx); + + int perp2Idx; + // For very shallow angles all the corner points could fuse. + if (duplicate_pt(perp2, this->point(perp1Idx))) { + perp2Idx = perp1Idx; + } else { + perp2Idx = this->addPt(perp2, -outset, coverage, false, isCurve); } - else { - // For each vertex of the original polygon we add three points to the - // outset polygon - one extending perpendicular to each impinging edge - // and one along the bisector. Two triangles are added for each corner - // and two are added along each edge. - - // The perpendicular point for the last edge - SkPoint temp = fNorms[prev]; - temp.scale(fTargetDepth); - temp += fPts[cur]; - - // We know it isn't a duplicate of the prior point (since it and this - // one are just perpendicular offsets from the non-merged polygon points) - newIdx0 = this->addPt(temp, -fTargetDepth, false, false); - - // The bisector outset point - temp = fBisectors[cur]; - temp.scale(-fTargetDepth); // the bisectors point in - temp += fPts[cur]; - - // For very shallow angles all the corner points could fuse - if (duplicate_pt(temp, this->point(newIdx0))) { - newIdx1 = newIdx0; - } else { - newIdx1 = this->addPt(temp, -fTargetDepth, false, false); - } - - // The perpendicular point for the next edge. - temp = fNorms[cur]; - temp.scale(fTargetDepth); - temp += fPts[cur]; - - // For very shallow angles all the corner points could fuse. - if (duplicate_pt(temp, this->point(newIdx1))) { - newIdx2 = newIdx1; - } else { - newIdx2 = this->addPt(temp, -fTargetDepth, false, false); - } - if (0 == cur) { - // Store the index of the first perpendicular point to finish up - firstPerpIdx = newIdx0; - SkASSERT(-1 == lastPerpIdx); + if (perp2Idx != perp1Idx) { + if (isCurve) { + // bevel or round depending upon curvature + SkScalar dotProd = normal1.dot(normal2); + if (dotProd < kRoundCapThreshold) { + // Currently we "round" by creating a single extra point, which produces + // good results for common cases. For thick strokes with high curvature, we will + // need to add more points; for the time being we simply fall back to software + // rendering for thick strokes. + SkPoint miter = previousRing.bisector(cur); + miter.setLength(-outset); + miter += fPts[originalIdx]; + + // For very shallow angles all the corner points could fuse + if (!duplicate_pt(miter, this->point(perp1Idx))) { + int miterIdx; + miterIdx = this->addPt(miter, -outset, coverage, false, false); + nextRing->addIdx(miterIdx, originalIdx); + // The two triangles for the corner + this->addTri(originalIdx, perp1Idx, miterIdx); + this->addTri(originalIdx, miterIdx, perp2Idx); + } + } else { + this->addTri(originalIdx, perp1Idx, perp2Idx); + } } else { - // The triangles for the previous edge - this->addTri(prev, newIdx0, cur); - this->addTri(prev, lastPerpIdx, newIdx0); + switch (fJoin) { + case SkPaint::Join::kMiter_Join: { + // The bisector outset point + SkPoint miter = previousRing.bisector(cur); + SkScalar dotProd = normal1.dot(normal2); + SkScalar sinHalfAngleSq = SkScalarHalf(SK_Scalar1 + dotProd); + SkScalar lengthSq = outsetSq / sinHalfAngleSq; + if (lengthSq > miterLimitSq) { + // just bevel it + this->addTri(originalIdx, perp1Idx, perp2Idx); + break; + } + miter.setLength(-SkScalarSqrt(lengthSq)); + miter += fPts[originalIdx]; + + // For very shallow angles all the corner points could fuse + if (!duplicate_pt(miter, this->point(perp1Idx))) { + int miterIdx; + miterIdx = this->addPt(miter, -outset, coverage, false, false); + nextRing->addIdx(miterIdx, originalIdx); + // The two triangles for the corner + this->addTri(originalIdx, perp1Idx, miterIdx); + this->addTri(originalIdx, miterIdx, perp2Idx); + } + break; + } + case SkPaint::Join::kBevel_Join: + this->addTri(originalIdx, perp1Idx, perp2Idx); + break; + default: + // kRound_Join is unsupported for now. GrAALinearizingConvexPathRenderer is + // only willing to draw mitered or beveled, so we should never get here. + SkASSERT(false); + } } - // The two triangles for the corner - this->addTri(cur, newIdx0, newIdx1); - this->addTri(cur, newIdx1, newIdx2); + nextRing->addIdx(perp2Idx, originalIdx); + } - prev = cur; - // Track the last perpendicular outset point so we can construct the - // trailing edge triangles. - lastPerpIdx = newIdx2; + if (0 == cur) { + // Store the index of the first perpendicular point to finish up + firstPerpIdx = perp1Idx; + SkASSERT(-1 == lastPerpIdx); + } else { + // The triangles for the previous edge + int prevIdx = previousRing.index(prev); + this->addTri(prevIdx, perp1Idx, originalIdx); + this->addTri(prevIdx, lastPerpIdx, perp1Idx); } + + // Track the last perpendicular outset point so we can construct the + // trailing edge triangles. + lastPerpIdx = perp2Idx; + prev = cur; } // pick up the final edge rect - this->addTri(numPts - 1, firstPerpIdx, 0); - this->addTri(numPts - 1, lastPerpIdx, firstPerpIdx); + int lastIdx = previousRing.index(numPts - 1); + this->addTri(lastIdx, firstPerpIdx, previousRing.index(0)); + this->addTri(lastIdx, lastPerpIdx, firstPerpIdx); this->validate(); } -// Something went wrong in the creation of the next ring. Mark the last good -// ring as being at the desired depth and fan it. +// Something went wrong in the creation of the next ring. If we're filling the shape, just go ahead +// and fan it. void GrAAConvexTessellator::terminate(const Ring& ring) { - for (int i = 0; i < ring.numPts(); ++i) { - fDepths[ring.index(i)] = fTargetDepth; + if (fStrokeWidth < 0.0f) { + this->fanRing(ring); } +} - this->fanRing(ring); +static SkScalar compute_coverage(SkScalar depth, SkScalar initialDepth, SkScalar initialCoverage, + SkScalar targetDepth, SkScalar targetCoverage) { + if (SkScalarNearlyEqual(initialDepth, targetDepth)) { + return targetCoverage; + } + SkScalar result = (depth - initialDepth) / (targetDepth - initialDepth) * + (targetCoverage - initialCoverage) + initialCoverage; + return SkScalarClampMax(result, 1.0f); } // return true when processing is complete -bool GrAAConvexTessellator::createInsetRing(const Ring& lastRing, Ring* nextRing) { +bool GrAAConvexTessellator::createInsetRing(const Ring& lastRing, Ring* nextRing, + SkScalar initialDepth, SkScalar initialCoverage, + SkScalar targetDepth, SkScalar targetCoverage, + bool forceNew) { bool done = false; fCandidateVerts.rewind(); @@ -512,7 +594,6 @@ bool GrAAConvexTessellator::createInsetRing(const Ring& lastRing, Ring* nextRing for (int cur = 0; cur < lastRing.numPts(); ++cur) { int next = (cur + 1) % lastRing.numPts(); - SkScalar t = intersect(this->point(lastRing.index(cur)), lastRing.bisector(cur), this->point(lastRing.index(next)), lastRing.bisector(next)); SkScalar dist = -t * lastRing.norm(cur).dot(lastRing.bisector(cur)); @@ -524,15 +605,18 @@ bool GrAAConvexTessellator::createInsetRing(const Ring& lastRing, Ring* nextRing } } + if (minEdgeIdx == -1) { + return false; + } SkPoint newPt = lastRing.bisector(minEdgeIdx); newPt.scale(minT); newPt += this->point(lastRing.index(minEdgeIdx)); SkScalar depth = this->computeDepthFromEdge(lastRing.origEdgeID(minEdgeIdx), newPt); - if (depth >= fTargetDepth) { + if (depth >= targetDepth) { // None of the bisectors intersect before reaching the desired depth. // Just step them all to the desired depth - depth = fTargetDepth; + depth = targetDepth; done = true; } @@ -547,7 +631,6 @@ bool GrAAConvexTessellator::createInsetRing(const Ring& lastRing, Ring* nextRing lastRing.origEdgeID(0), depth, &newPt)) { this->terminate(lastRing); - SkDEBUGCODE(fShouldCheckDepths = false;) return true; } dst[0] = fCandidateVerts.addNewPt(newPt, @@ -561,7 +644,6 @@ bool GrAAConvexTessellator::createInsetRing(const Ring& lastRing, Ring* nextRing lastRing.origEdgeID(cur), depth, &newPt)) { this->terminate(lastRing); - SkDEBUGCODE(fShouldCheckDepths = false;) return true; } if (!duplicate_pt(newPt, fCandidateVerts.lastPoint())) { @@ -580,7 +662,6 @@ bool GrAAConvexTessellator::createInsetRing(const Ring& lastRing, Ring* nextRing lastRing.origEdgeID(cur), depth, &newPt)) { this->terminate(lastRing); - SkDEBUGCODE(fShouldCheckDepths = false;) return true; } bool dupPrev = duplicate_pt(newPt, fCandidateVerts.lastPoint()); @@ -607,14 +688,17 @@ bool GrAAConvexTessellator::createInsetRing(const Ring& lastRing, Ring* nextRing // Fold the new ring's points into the global pool for (int i = 0; i < fCandidateVerts.numPts(); ++i) { int newIdx; - if (fCandidateVerts.needsToBeNew(i)) { + if (fCandidateVerts.needsToBeNew(i) || forceNew) { // if the originating index is still valid then this point wasn't // fused (and is thus movable) - newIdx = this->addPt(fCandidateVerts.point(i), depth, + SkScalar coverage = compute_coverage(depth, initialDepth, initialCoverage, + targetDepth, targetCoverage); + newIdx = this->addPt(fCandidateVerts.point(i), depth, coverage, fCandidateVerts.originatingIdx(i) != -1, false); } else { SkASSERT(fCandidateVerts.originatingIdx(i) != -1); - this->updatePt(fCandidateVerts.originatingIdx(i), fCandidateVerts.point(i), depth); + this->updatePt(fCandidateVerts.originatingIdx(i), fCandidateVerts.point(i), depth, + targetCoverage); newIdx = fCandidateVerts.originatingIdx(i); } @@ -634,19 +718,18 @@ bool GrAAConvexTessellator::createInsetRing(const Ring& lastRing, Ring* nextRing this->addTri(lastRing.index(cur), dst[next], dst[cur]); } - if (done) { + if (done && fStrokeWidth < 0.0f) { + // fill this->fanRing(*nextRing); } if (nextRing->numPts() < 3) { done = true; } - return done; } void GrAAConvexTessellator::validate() const { - SkASSERT(fPts.count() == fDepths.count()); SkASSERT(fPts.count() == fMovable.count()); SkASSERT(0 == (fIndices.count() % 3)); } @@ -655,7 +738,6 @@ void GrAAConvexTessellator::validate() const { void GrAAConvexTessellator::Ring::init(const GrAAConvexTessellator& tess) { this->computeNormals(tess); this->computeBisectors(tess); - SkASSERT(this->isConvex(tess)); } void GrAAConvexTessellator::Ring::init(const SkTDArray& norms, @@ -672,11 +754,8 @@ void GrAAConvexTessellator::Ring::computeNormals(const GrAAConvexTessellator& te int next = (cur + 1) % fPts.count(); fPts[cur].fNorm = tess.point(fPts[next].fIndex) - tess.point(fPts[cur].fIndex); - SkDEBUGCODE(SkScalar len =) SkPoint::Normalize(&fPts[cur].fNorm); - SkASSERT(len > 0.0f); + SkPoint::Normalize(&fPts[cur].fNorm); fPts[cur].fNorm.setOrthog(fPts[cur].fNorm, tess.side()); - - SkASSERT(SkScalarNearlyEqual(1.0f, fPts[cur].fNorm.length())); } } @@ -694,9 +773,7 @@ void GrAAConvexTessellator::Ring::computeBisectors(const GrAAConvexTessellator& } else { fPts[cur].fBisector.negate(); // make the bisector face in } - - SkASSERT(SkScalarNearlyEqual(1.0f, fPts[cur].fBisector.length())); - } + } } ////////////////////////////////////////////////////////////////////////////// @@ -704,7 +781,7 @@ void GrAAConvexTessellator::Ring::computeBisectors(const GrAAConvexTessellator& // Is this ring convex? bool GrAAConvexTessellator::Ring::isConvex(const GrAAConvexTessellator& tess) const { if (fPts.count() < 3) { - return false; + return true; } SkPoint prev = tess.point(fPts[0].fIndex) - tess.point(fPts.top().fIndex); @@ -725,74 +802,18 @@ bool GrAAConvexTessellator::Ring::isConvex(const GrAAConvexTessellator& tess) co prev = cur; } - return (maxDot > 0.0f) == (minDot >= 0.0f); -} - -static SkScalar capsule_depth(const SkPoint& p0, const SkPoint& p1, - const SkPoint& test, SkPoint::Side side, - int* sign) { - *sign = -1; - SkPoint edge = p1 - p0; - SkScalar len = SkPoint::Normalize(&edge); - - SkPoint testVec = test - p0; - - SkScalar d0 = edge.dot(testVec); - if (d0 < 0.0f) { - return SkPoint::Distance(p0, test); - } - if (d0 > len) { - return SkPoint::Distance(p1, test); - } - - SkScalar perpDist = testVec.fY * edge.fX - testVec.fX * edge.fY; - if (SkPoint::kRight_Side == side) { - perpDist = -perpDist; - } - - if (perpDist < 0.0f) { - perpDist = -perpDist; - } else { - *sign = 1; + if (SkScalarNearlyEqual(maxDot, 0.0f, 0.005f)) { + maxDot = 0; } - return perpDist; -} - -SkScalar GrAAConvexTessellator::computeRealDepth(const SkPoint& p) const { - SkScalar minDist = SK_ScalarMax; - int closestSign, sign; - - for (int edge = 0; edge < fNorms.count(); ++edge) { - SkScalar dist = capsule_depth(this->point(edge), - this->point((edge+1) % fNorms.count()), - p, fSide, &sign); - SkASSERT(dist >= 0.0f); - - if (minDist > dist) { - minDist = dist; - closestSign = sign; - } + if (SkScalarNearlyEqual(minDot, 0.0f, 0.005f)) { + minDot = 0; } - - return closestSign * minDist; + return (maxDot >= 0.0f) == (minDot >= 0.0f); } -// Verify that the incrementally computed depths are close to the actual depths. -void GrAAConvexTessellator::checkAllDepths() const { - for (int cur = 0; cur < this->numPts(); ++cur) { - SkScalar realDepth = this->computeRealDepth(this->point(cur)); - SkScalar computedDepth = this->depth(cur); - SkASSERT(SkScalarNearlyEqual(realDepth, computedDepth, 0.01f)); - } -} #endif -#define kQuadTolerance 0.2f -#define kCubicTolerance 0.2f -#define kConicTolerance 0.5f - -void GrAAConvexTessellator::lineTo(const SkMatrix& m, SkPoint p, bool isCurve) { - m.mapPoints(&p, 1); +void GrAAConvexTessellator::lineTo(SkPoint p, bool isCurve) { if (this->numPts() > 0 && duplicate_pt(p, this->lastPoint())) { return; } @@ -805,24 +826,22 @@ void GrAAConvexTessellator::lineTo(const SkMatrix& m, SkPoint p, bool isCurve) { fNorms.pop(); fIsCurve.pop(); } - this->addPt(p, 0.0f, false, isCurve); + SkScalar initialRingCoverage = fStrokeWidth < 0.0f ? 0.5f : 1.0f; + this->addPt(p, 0.0f, initialRingCoverage, false, isCurve); if (this->numPts() > 1) { *fNorms.push() = fPts.top() - fPts[fPts.count()-2]; SkDEBUGCODE(SkScalar len =) SkPoint::Normalize(&fNorms.top()); SkASSERT(len > 0.0f); SkASSERT(SkScalarNearlyEqual(1.0f, fNorms.top().length())); } - SkDEBUGCODE( - if (this->numPts() >= 3) { - int cur = this->numPts()-1; - SkScalar cross = SkPoint::CrossProduct(fNorms[cur-1], fNorms[cur-2]); - fMaxCross = SkTMax(fMaxCross, cross); - fMinCross = SkTMin(fMinCross, cross); - } - ) } -void GrAAConvexTessellator::quadTo(const SkMatrix& m, SkPoint pts[3]) { +void GrAAConvexTessellator::lineTo(const SkMatrix& m, SkPoint p, bool isCurve) { + m.mapPoints(&p, 1); + this->lineTo(p, isCurve); +} + +void GrAAConvexTessellator::quadTo(SkPoint pts[3]) { int maxCount = GrPathUtils::quadraticPointCount(pts, kQuadTolerance); fPointBuffer.setReserve(maxCount); SkPoint* target = fPointBuffer.begin(); @@ -830,11 +849,21 @@ void GrAAConvexTessellator::quadTo(const SkMatrix& m, SkPoint pts[3]) { kQuadTolerance, &target, maxCount); fPointBuffer.setCount(count); for (int i = 0; i < count; i++) { - lineTo(m, fPointBuffer[i], true); + lineTo(fPointBuffer[i], true); } } +void GrAAConvexTessellator::quadTo(const SkMatrix& m, SkPoint pts[3]) { + SkPoint transformed[3]; + transformed[0] = pts[0]; + transformed[1] = pts[1]; + transformed[2] = pts[2]; + m.mapPoints(transformed, 3); + quadTo(transformed); +} + void GrAAConvexTessellator::cubicTo(const SkMatrix& m, SkPoint pts[4]) { + m.mapPoints(pts, 4); int maxCount = GrPathUtils::cubicPointCount(pts, kCubicTolerance); fPointBuffer.setReserve(maxCount); SkPoint* target = fPointBuffer.begin(); @@ -842,14 +871,15 @@ void GrAAConvexTessellator::cubicTo(const SkMatrix& m, SkPoint pts[4]) { kCubicTolerance, &target, maxCount); fPointBuffer.setCount(count); for (int i = 0; i < count; i++) { - lineTo(m, fPointBuffer[i], true); + lineTo(fPointBuffer[i], true); } } // include down here to avoid compilation errors caused by "-" overload in SkGeometry.h #include "SkGeometry.h" -void GrAAConvexTessellator::conicTo(const SkMatrix& m, SkPoint* pts, SkScalar w) { +void GrAAConvexTessellator::conicTo(const SkMatrix& m, SkPoint pts[3], SkScalar w) { + m.mapPoints(pts, 3); SkAutoConicToQuads quadder; const SkPoint* quads = quadder.computeQuads(pts, w, kConicTolerance); SkPoint lastPoint = *(quads++); @@ -859,7 +889,7 @@ void GrAAConvexTessellator::conicTo(const SkMatrix& m, SkPoint* pts, SkScalar w) quadPts[0] = lastPoint; quadPts[1] = quads[0]; quadPts[2] = i == count - 1 ? pts[2] : quads[1]; - quadTo(m, quadPts); + quadTo(quadPts); lastPoint = quadPts[2]; quads += 2; } @@ -965,13 +995,13 @@ void GrAAConvexTessellator::draw(SkCanvas* canvas) const { for (int i = 0; i < this->numPts(); ++i) { draw_point(canvas, - this->point(i), 0.5f + (this->depth(i)/(2*fTargetDepth)), + this->point(i), 0.5f + (this->depth(i)/(2 * kAntialiasingRadius)), !this->movable(i)); SkPaint paint; paint.setTextSize(kPointTextSize); paint.setTextAlign(SkPaint::kCenter_Align); - if (this->depth(i) <= -fTargetDepth) { + if (this->depth(i) <= -kAntialiasingRadius) { paint.setColor(SK_ColorWHITE); } diff --git a/src/gpu/GrAAConvexTessellator.h b/src/gpu/GrAAConvexTessellator.h index 93e8d4b..f3d84dc 100644 --- a/src/gpu/GrAAConvexTessellator.h +++ b/src/gpu/GrAAConvexTessellator.h @@ -9,6 +9,7 @@ #define GrAAConvexTessellator_DEFINED #include "SkColor.h" +#include "SkPaint.h" #include "SkPoint.h" #include "SkScalar.h" #include "SkTDArray.h" @@ -19,6 +20,9 @@ class SkPath; //#define GR_AA_CONVEX_TESSELLATOR_VIZ 1 +// device space distance which we inset / outset points in order to create the soft antialiased edge +static const SkScalar kAntialiasingRadius = 0.5f; + class GrAAConvexTessellator; // The AAConvexTessellator holds the global pool of points and the triangulation @@ -27,14 +31,15 @@ class GrAAConvexTessellator; // computeDepthFromEdge requests. class GrAAConvexTessellator { public: - GrAAConvexTessellator(SkScalar targetDepth = 0.5f) + GrAAConvexTessellator(SkScalar strokeWidth = -1.0f, + SkPaint::Join join = SkPaint::Join::kBevel_Join, + SkScalar miterLimit = 0.0f) : fSide(SkPoint::kOn_Side) - , fTargetDepth(targetDepth) { + , fStrokeWidth(strokeWidth) + , fJoin(join) + , fMiterLimit(miterLimit) { } - void setTargetDepth(SkScalar targetDepth) { fTargetDepth = targetDepth; } - SkScalar targetDepth() const { return fTargetDepth; } - SkPoint::Side side() const { return fSide; } bool tessellate(const SkMatrix& m, const SkPath& path); @@ -46,7 +51,7 @@ public: const SkPoint& lastPoint() const { return fPts.top(); } const SkPoint& point(int index) const { return fPts[index]; } int index(int index) const { return fIndices[index]; } - SkScalar depth(int index) const {return fDepths[index]; } + SkScalar coverage(int index) const { return fCoverages[index]; } #if GR_AA_CONVEX_TESSELLATOR_VIZ void draw(SkCanvas* canvas) const; @@ -139,6 +144,7 @@ private: const SkPoint& bisector(int index) const { return fPts[index].fBisector; } int index(int index) const { return fPts[index].fIndex; } int origEdgeID(int index) const { return fPts[index].fOrigEdgeId; } + void setOrigEdgeId(int index, int id) { fPts[index].fOrigEdgeId = id; } #if GR_AA_CONVEX_TESSELLATOR_VIZ void draw(SkCanvas* canvas, const GrAAConvexTessellator& tess) const; @@ -165,17 +171,17 @@ private: // Movable points are those that can be slid along their bisector. // Basically, a point is immovable if it is part of the original // polygon or it results from the fusing of two bisectors. - int addPt(const SkPoint& pt, SkScalar depth, bool movable, bool isCurve); + int addPt(const SkPoint& pt, SkScalar depth, SkScalar coverage, bool movable, bool isCurve); void popLastPt(); void popFirstPtShuffle(); - void updatePt(int index, const SkPoint& pt, SkScalar depth); + void updatePt(int index, const SkPoint& pt, SkScalar depth, SkScalar coverage); void addTri(int i0, int i1, int i2); void reservePts(int count) { fPts.setReserve(count); - fDepths.setReserve(count); + fCoverages.setReserve(count); fMovable.setReserve(count); } @@ -185,8 +191,12 @@ private: int edgeIdx, SkScalar desiredDepth, SkPoint* result) const; + void lineTo(SkPoint p, bool isCurve); + void lineTo(const SkMatrix& m, SkPoint p, bool isCurve); + void quadTo(SkPoint pts[3]); + void quadTo(const SkMatrix& m, SkPoint pts[3]); void cubicTo(const SkMatrix& m, SkPoint pts[4]); @@ -200,23 +210,24 @@ private: void computeBisectors(); void fanRing(const Ring& ring); - void createOuterRing(); Ring* getNextRing(Ring* lastRing); - bool createInsetRing(const Ring& lastRing, Ring* nextRing); + void createOuterRing(const Ring& previousRing, SkScalar outset, SkScalar coverage, + Ring* nextRing); - void validate() const; + bool createInsetRings(Ring& previousRing, SkScalar initialDepth, SkScalar initialCoverage, + SkScalar targetDepth, SkScalar targetCoverage, Ring** finalRing); + bool createInsetRing(const Ring& lastRing, Ring* nextRing, + SkScalar initialDepth, SkScalar initialCoverage, SkScalar targetDepth, + SkScalar targetCoverage, bool forceNew); -#ifdef SK_DEBUG - SkScalar computeRealDepth(const SkPoint& p) const; - void checkAllDepths() const; -#endif + void validate() const; - // fPts, fWeights & fMovable should always have the same # of elements + // fPts, fCoverages & fMovable should always have the same # of elements SkTDArray fPts; - SkTDArray fDepths; + SkTDArray fCoverages; // movable points are those that can be slid further along their bisector SkTDArray fMovable; @@ -244,18 +255,14 @@ private: #endif CandidateVerts fCandidateVerts; - SkScalar fTargetDepth; + // < 0 means filling rather than stroking + SkScalar fStrokeWidth; - SkTDArray fPointBuffer; + SkPaint::Join fJoin; - // If some goes wrong with the inset computation the tessellator will - // truncate the creation of the inset polygon. In this case the depth - // check will complain. - SkDEBUGCODE(bool fShouldCheckDepths;) + SkScalar fMiterLimit; - SkDEBUGCODE(SkScalar fMinCross;) - - SkDEBUGCODE(SkScalar fMaxCross;) + SkTDArray fPointBuffer; }; diff --git a/src/gpu/GrAALinearizingConvexPathRenderer.cpp b/src/gpu/GrAALinearizingConvexPathRenderer.cpp index 5ded4d4..786378b 100644 --- a/src/gpu/GrAALinearizingConvexPathRenderer.cpp +++ b/src/gpu/GrAALinearizingConvexPathRenderer.cpp @@ -23,11 +23,16 @@ #include "SkGeometry.h" #include "SkString.h" #include "SkTraceEvent.h" +#include "SkPathPriv.h" #include "gl/GrGLProcessor.h" #include "gl/GrGLGeometryProcessor.h" #include "gl/builders/GrGLProgramBuilder.h" -#define DEFAULT_BUFFER_SIZE 100 +static const int DEFAULT_BUFFER_SIZE = 100; + +// The thicker the stroke, the harder it is to produce high-quality results using tessellation. For +// the time being, we simply drop back to software rendering above this stroke width. +static const SkScalar kMaxStrokeWidth = 20.0; GrAALinearizingConvexPathRenderer::GrAALinearizingConvexPathRenderer() { } @@ -40,7 +45,21 @@ bool GrAALinearizingConvexPathRenderer::canDrawPath(const GrDrawTarget* target, const SkPath& path, const GrStrokeInfo& stroke, bool antiAlias) const { - return (antiAlias && stroke.isFillStyle() && !path.isInverseFillType() && path.isConvex()); + if (!antiAlias) { + return false; + } + if (path.isInverseFillType()) { + return false; + } + if (!path.isConvex()) { + return false; + } + if (stroke.getStyle() == SkStrokeRec::kStroke_Style) { + return viewMatrix.isSimilarity() && stroke.getWidth() >= 1.0f && + stroke.getWidth() <= kMaxStrokeWidth && !stroke.isDashed() && + SkPathPriv::LastVerbIsClose(path) && stroke.getJoin() != SkPaint::Join::kRound_Join; + } + return stroke.getStyle() == SkStrokeRec::kFill_Style; } // extract the result vertices and indices from the GrAAConvexTessellator @@ -60,16 +79,15 @@ static void extract_verts(const GrAAConvexTessellator& tess, // Make 'verts' point to the colors verts += sizeof(SkPoint); for (int i = 0; i < tess.numPts(); ++i) { - SkASSERT(tess.depth(i) >= -0.5f && tess.depth(i) <= 0.5f); if (tweakAlphaForCoverage) { - SkASSERT(SkScalarRoundToInt(255.0f * (tess.depth(i) + 0.5f)) <= 255); - unsigned scale = SkScalarRoundToInt(255.0f * (tess.depth(i) + 0.5f)); + SkASSERT(SkScalarRoundToInt(255.0f * tess.coverage(i)) <= 255); + unsigned scale = SkScalarRoundToInt(255.0f * tess.coverage(i)); GrColor scaledColor = (0xff == scale) ? color : SkAlphaMulQ(color, scale); *reinterpret_cast(verts + i * vertexStride) = scaledColor; } else { *reinterpret_cast(verts + i * vertexStride) = color; *reinterpret_cast(verts + i * vertexStride + sizeof(GrColor)) = - tess.depth(i) + 0.5f; + tess.coverage(i); } } @@ -97,6 +115,9 @@ public: GrColor fColor; SkMatrix fViewMatrix; SkPath fPath; + SkScalar fStrokeWidth; + SkPaint::Join fJoin; + SkScalar fMiterLimit; }; static GrBatch* Create(const Geometry& geometry) { @@ -158,7 +179,7 @@ public: firstIndex, vertexCount, indexCount); batchTarget->draw(info); } - + void generateGeometry(GrBatchTarget* batchTarget, const GrPipeline* pipeline) override { bool canTweakAlphaForCoverage = this->canTweakAlphaForCoverage(); @@ -182,8 +203,6 @@ public: vertexStride == sizeof(GrDefaultGeoProcFactory::PositionColorAttr) : vertexStride == sizeof(GrDefaultGeoProcFactory::PositionColorCoverageAttr)); - GrAAConvexTessellator tess; - int instanceCount = fGeoData.count(); int vertexCount = 0; @@ -193,9 +212,8 @@ public: uint8_t* vertices = (uint8_t*) malloc(maxVertices * vertexStride); uint16_t* indices = (uint16_t*) malloc(maxIndices * sizeof(uint16_t)); for (int i = 0; i < instanceCount; i++) { - tess.rewind(); - Geometry& args = fGeoData[i]; + GrAAConvexTessellator tess(args.fStrokeWidth, args.fJoin, args.fMiterLimit); if (!tess.tessellate(args.fViewMatrix, args.fPath)) { continue; @@ -287,7 +305,7 @@ bool GrAALinearizingConvexPathRenderer::onDrawPath(GrDrawTarget* target, GrColor color, const SkMatrix& vm, const SkPath& path, - const GrStrokeInfo&, + const GrStrokeInfo& stroke, bool antiAlias) { if (path.isEmpty()) { return true; @@ -296,6 +314,9 @@ bool GrAALinearizingConvexPathRenderer::onDrawPath(GrDrawTarget* target, geometry.fColor = color; geometry.fViewMatrix = vm; geometry.fPath = path; + geometry.fStrokeWidth = stroke.isFillStyle() ? -1.0f : stroke.getWidth(); + geometry.fJoin = stroke.isFillStyle() ? SkPaint::Join::kMiter_Join : stroke.getJoin(); + geometry.fMiterLimit = stroke.getMiter(); SkAutoTUnref batch(AAFlatteningConvexPathBatch::Create(geometry)); target->drawBatch(pipelineBuilder, batch); diff --git a/src/gpu/GrAddPathRenderers_default.cpp b/src/gpu/GrAddPathRenderers_default.cpp index 351b8eb..c60c7ce 100644 --- a/src/gpu/GrAddPathRenderers_default.cpp +++ b/src/gpu/GrAddPathRenderers_default.cpp @@ -9,7 +9,7 @@ #include "GrStencilAndCoverPathRenderer.h" #include "GrAAHairLinePathRenderer.h" -#include "GrAAConvexPathRenderer.h" +#include "GrAALinearizingConvexPathRenderer.h" #include "GrAADistanceFieldPathRenderer.h" #include "GrContext.h" #include "GrDashLinePathRenderer.h" @@ -33,6 +33,6 @@ void GrPathRenderer::AddPathRenderers(GrContext* ctx, GrPathRendererChain* chain if (GrPathRenderer* pr = GrAAHairLinePathRenderer::Create()) { chain->addPathRenderer(pr)->unref(); } - chain->addPathRenderer(SkNEW(GrAAConvexPathRenderer))->unref(); + chain->addPathRenderer(SkNEW(GrAALinearizingConvexPathRenderer))->unref(); chain->addPathRenderer(SkNEW_ARGS(GrAADistanceFieldPathRenderer, (ctx)))->unref(); } -- 2.7.4