aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu
diff options
context:
space:
mode:
authorGravatar reed <reed@chromium.org>2015-06-26 05:06:43 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2015-06-26 05:06:43 -0700
commit9730f4a663534009d216c2f6d834bd534dd44a3d (patch)
tree17cb01d25653d1695a4ca35f309c9ebff8cef968 /src/gpu
parentf9ad558943ee14bdff824ebfb33988bece8ed3db (diff)
Revert of added stroking support to GrAALinearizingConvexPathRenderer (patchset #6 id:100001 of https://codereview.chromium.org/1180903006/)
Reason for revert: speculative revert to try to fix DEPS roll (layouttests) Original issue's description: > added stroking support to GrAALinearizingConvexPathRenderer > > BUG=skia: > > Committed: https://skia.googlesource.com/skia/+/2436f191e6602953b32a51cf50f2d7a4e2af90fd TBR=bsalomon@google.com,robertphillips@google.com,ethannicholas@google.com NOPRESUBMIT=true NOTREECHECKS=true NOTRY=true BUG=skia: Review URL: https://codereview.chromium.org/1212833002
Diffstat (limited to 'src/gpu')
-rw-r--r--src/gpu/GrAAConvexPathRenderer.cpp7
-rw-r--r--src/gpu/GrAAConvexTessellator.cpp602
-rw-r--r--src/gpu/GrAAConvexTessellator.h61
-rw-r--r--src/gpu/GrAALinearizingConvexPathRenderer.cpp45
-rw-r--r--src/gpu/GrAddPathRenderers_default.cpp4
5 files changed, 331 insertions, 388 deletions
diff --git a/src/gpu/GrAAConvexPathRenderer.cpp b/src/gpu/GrAAConvexPathRenderer.cpp
index 52994758c0..4e3d859e0b 100644
--- a/src/gpu/GrAAConvexPathRenderer.cpp
+++ b/src/gpu/GrAAConvexPathRenderer.cpp
@@ -707,15 +707,16 @@ 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.coverage(i)) <= 255);
- unsigned scale = SkScalarRoundToInt(255.0f * tess.coverage(i));
+ SkASSERT(SkScalarRoundToInt(255.0f * (tess.depth(i) + 0.5f)) <= 255);
+ unsigned scale = SkScalarRoundToInt(255.0f * (tess.depth(i) + 0.5f));
GrColor scaledColor = (0xff == scale) ? color : SkAlphaMulQ(color, scale);
*reinterpret_cast<GrColor*>(verts + i * vertexStride) = scaledColor;
} else {
*reinterpret_cast<GrColor*>(verts + i * vertexStride) = color;
*reinterpret_cast<float*>(verts + i * vertexStride + sizeof(GrColor)) =
- tess.coverage(i);
+ tess.depth(i) + 0.5f;
}
}
diff --git a/src/gpu/GrAAConvexTessellator.cpp b/src/gpu/GrAAConvexTessellator.cpp
index 85ce7ba9ed..56a408d644 100644
--- a/src/gpu/GrAAConvexTessellator.cpp
+++ b/src/gpu/GrAAConvexTessellator.cpp
@@ -13,6 +13,7 @@
#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
@@ -21,17 +22,10 @@
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;
}
@@ -58,14 +52,13 @@ 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;
- *fCoverages.push() = coverage;
+ *fDepths.push() = depth;
*fMovable.push() = movable;
*fIsCurve.push() = isCurve;
@@ -77,7 +70,7 @@ void GrAAConvexTessellator::popLastPt() {
this->validate();
fPts.pop();
- fCoverages.pop();
+ fDepths.pop();
fMovable.pop();
this->validate();
@@ -87,7 +80,7 @@ void GrAAConvexTessellator::popFirstPtShuffle() {
this->validate();
fPts.removeShuffle(0);
- fCoverages.removeShuffle(0);
+ fDepths.removeShuffle(0);
fMovable.removeShuffle(0);
this->validate();
@@ -95,13 +88,12 @@ void GrAAConvexTessellator::popFirstPtShuffle() {
void GrAAConvexTessellator::updatePt(int index,
const SkPoint& pt,
- SkScalar depth,
- SkScalar coverage) {
+ SkScalar depth) {
this->validate();
SkASSERT(fMovable[index]);
fPts[index] = pt;
- fCoverages[index] = coverage;
+ fDepths[index] = depth;
}
void GrAAConvexTessellator::addTri(int i0, int i1, int i2) {
@@ -116,7 +108,7 @@ void GrAAConvexTessellator::addTri(int i0, int i1, int i2) {
void GrAAConvexTessellator::rewind() {
fPts.rewind();
- fCoverages.rewind();
+ fDepths.rewind();
fMovable.rewind();
fIndices.rewind();
fNorms.rewind();
@@ -151,44 +143,6 @@ 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.
@@ -196,40 +150,46 @@ bool GrAAConvexTessellator::createInsetRings(Ring& previousRing, SkScalar initia
// 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;
}
- 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);
- }
+ this->createOuterRing();
// the bisectors are only needed for the computation of the outer ring
fBisectors.rewind();
- 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);
+
+ Ring* lastRing = &fInitialRing;
+ int i;
+ for (i = 0; i < kMaxNumRings; ++i) {
+ Ring* nextRing = this->getNextRing(lastRing);
+
+ if (this->createInsetRing(*lastRing, nextRing)) {
+ break;
}
- } else {
- Ring* insetAARing;
- this->createInsetRings(fInitialRing, 0.0f, 0.5f, kAntialiasingRadius, 1.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;)
}
- SkDEBUGCODE(this->validate();)
+#ifdef SK_DEBUG
+ this->validate();
+ if (fShouldCheckDepths) {
+ SkDEBUGCODE(this->checkAllDepths();)
+ }
+#endif
return true;
}
@@ -238,6 +198,7 @@ SkScalar GrAAConvexTessellator::computeDepthFromEdge(int edgeIdx, const SkPoint&
SkPoint v = p - fPts[edgeIdx];
SkScalar depth = -fNorms[edgeIdx].dot(v);
+ SkASSERT(depth >= 0.0f);
return depth;
}
@@ -252,13 +213,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 < fPts.count());
+ SkASSERT(startIdx < fNorms.count());
newP = fPts[startIdx];
- } else if (t < 0.0f) {
+ } else if (t > 0.0f) {
+ SkASSERT(t < 0.0f);
newP = bisector;
newP.scale(t);
newP += fPts[startIdx];
@@ -267,12 +228,13 @@ bool GrAAConvexTessellator::computePtAlongBisector(int startIdx,
}
// Then offset along the bisector from that point the correct distance
- SkScalar dot = bisector.dot(norm);
- t = -desiredDepth / dot;
+ t = -desiredDepth / bisector.dot(norm);
+ SkASSERT(t > 0.0f);
*result = bisector;
result->scale(t);
*result += newP;
+
return true;
}
@@ -290,6 +252,9 @@ 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?
@@ -317,7 +282,7 @@ bool GrAAConvexTessellator::extractFromPath(const SkMatrix& m, const SkPath& pat
}
}
- if (this->numPts() < 2) {
+ if (this->numPts() < 3) {
return false;
}
@@ -328,20 +293,23 @@ bool GrAAConvexTessellator::extractFromPath(const SkMatrix& m, const SkPath& pat
}
SkASSERT(fPts.count() == fNorms.count()+1);
- 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 &&
+ 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();
+ }
- *fNorms.push() = fPts[0] - fPts.top();
- SkDEBUGCODE(SkScalar len =) SkPoint::Normalize(&fNorms.top());
- SkASSERT(len > 0.0f);
- SkASSERT(fPts.count() == fNorms.count());
+ if (this->numPts() < 3) {
+ return false;
}
- if (this->numPts() >= 3 && abs_dist_from_line(fPts[0], fNorms.top(), fPts[1]) < kClose) {
+ *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) {
// The first point is on the line from the last to the second.
this->popFirstPtShuffle();
fNorms.removeShuffle(0);
@@ -351,45 +319,29 @@ bool GrAAConvexTessellator::extractFromPath(const SkMatrix& m, const SkPath& pat
SkASSERT(SkScalarNearlyEqual(1.0f, fNorms[0].length()));
}
- 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;
- }
-
- // 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()));
- }
+ if (this->numPts() < 3) {
+ return false;
+ }
- 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
+ // 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 {
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()));
- }
-
- 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;
+ // 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();
+
fCandidateVerts.setReserve(this->numPts());
fInitialRing.setReserve(this->numPts());
for (int i = 0; i < this->numPts(); ++i) {
@@ -418,172 +370,138 @@ GrAAConvexTessellator::Ring* GrAAConvexTessellator::getNextRing(Ring* lastRing)
void GrAAConvexTessellator::fanRing(const Ring& ring) {
// fan out from point 0
- int startIdx = ring.index(0);
- for (int cur = ring.numPts() - 2; cur >= 0; --cur) {
- this->addTri(startIdx, ring.index(cur), ring.index(cur + 1));
+ for (int cur = 1; cur < ring.numPts()-1; ++cur) {
+ this->addTri(ring.index(0), ring.index(cur), ring.index(cur+1));
}
}
-void GrAAConvexTessellator::createOuterRing(const Ring& previousRing, SkScalar outset,
- SkScalar coverage, Ring* nextRing) {
- const int numPts = previousRing.numPts();
- if (numPts == 0) {
- return;
- }
+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());
- int prev = numPts - 1;
- int lastPerpIdx = -1, firstPerpIdx = -1;
+ const int numPts = fPts.count();
- const SkScalar outsetSq = SkScalarMul(outset, outset);
- SkScalar miterLimitSq = SkScalarMul(outset, fMiterLimit);
- miterLimitSq = SkScalarMul(miterLimitSq, miterLimitSq);
+ int prev = numPts - 1;
+ int lastPerpIdx = -1, firstPerpIdx = -1, newIdx0, newIdx1, newIdx2;
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);
+ 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);
+ }
+
+ prev = cur;
+ // Track the last perpendicular outset point so we can construct the
+ // trailing edge triangles.
+ lastPerpIdx = newIdx1;
}
+ 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);
+ }
- 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);
- }
+ // 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 {
- 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);
- }
+ newIdx2 = this->addPt(temp, -fTargetDepth, false, false);
}
- nextRing->addIdx(perp2Idx, originalIdx);
- }
+ if (0 == cur) {
+ // Store the index of the first perpendicular point to finish up
+ firstPerpIdx = newIdx0;
+ SkASSERT(-1 == lastPerpIdx);
+ } else {
+ // The triangles for the previous edge
+ this->addTri(prev, newIdx0, cur);
+ this->addTri(prev, lastPerpIdx, newIdx0);
+ }
- 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);
- }
+ // The two triangles for the corner
+ this->addTri(cur, newIdx0, newIdx1);
+ this->addTri(cur, newIdx1, newIdx2);
- // Track the last perpendicular outset point so we can construct the
- // trailing edge triangles.
- lastPerpIdx = perp2Idx;
- prev = cur;
+ prev = cur;
+ // Track the last perpendicular outset point so we can construct the
+ // trailing edge triangles.
+ lastPerpIdx = newIdx2;
+ }
}
// pick up the final edge rect
- int lastIdx = previousRing.index(numPts - 1);
- this->addTri(lastIdx, firstPerpIdx, previousRing.index(0));
- this->addTri(lastIdx, lastPerpIdx, firstPerpIdx);
+ this->addTri(numPts - 1, firstPerpIdx, 0);
+ this->addTri(numPts - 1, lastPerpIdx, firstPerpIdx);
this->validate();
}
-// Something went wrong in the creation of the next ring. If we're filling the shape, just go ahead
-// and fan it.
+// Something went wrong in the creation of the next ring. Mark the last good
+// ring as being at the desired depth and fan it.
void GrAAConvexTessellator::terminate(const Ring& ring) {
- if (fStrokeWidth < 0.0f) {
- this->fanRing(ring);
+ for (int i = 0; i < ring.numPts(); ++i) {
+ fDepths[ring.index(i)] = fTargetDepth;
}
-}
-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);
+ this->fanRing(ring);
}
// return true when processing is complete
-bool GrAAConvexTessellator::createInsetRing(const Ring& lastRing, Ring* nextRing,
- SkScalar initialDepth, SkScalar initialCoverage,
- SkScalar targetDepth, SkScalar targetCoverage,
- bool forceNew) {
+bool GrAAConvexTessellator::createInsetRing(const Ring& lastRing, Ring* nextRing) {
bool done = false;
fCandidateVerts.rewind();
@@ -594,6 +512,7 @@ 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));
@@ -605,18 +524,15 @@ 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 >= targetDepth) {
+ if (depth >= fTargetDepth) {
// None of the bisectors intersect before reaching the desired depth.
// Just step them all to the desired depth
- depth = targetDepth;
+ depth = fTargetDepth;
done = true;
}
@@ -631,6 +547,7 @@ 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,
@@ -644,6 +561,7 @@ 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())) {
@@ -662,6 +580,7 @@ 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());
@@ -688,17 +607,14 @@ 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) || forceNew) {
+ if (fCandidateVerts.needsToBeNew(i)) {
// if the originating index is still valid then this point wasn't
// fused (and is thus movable)
- SkScalar coverage = compute_coverage(depth, initialDepth, initialCoverage,
- targetDepth, targetCoverage);
- newIdx = this->addPt(fCandidateVerts.point(i), depth, coverage,
+ newIdx = this->addPt(fCandidateVerts.point(i), depth,
fCandidateVerts.originatingIdx(i) != -1, false);
} else {
SkASSERT(fCandidateVerts.originatingIdx(i) != -1);
- this->updatePt(fCandidateVerts.originatingIdx(i), fCandidateVerts.point(i), depth,
- targetCoverage);
+ this->updatePt(fCandidateVerts.originatingIdx(i), fCandidateVerts.point(i), depth);
newIdx = fCandidateVerts.originatingIdx(i);
}
@@ -718,18 +634,19 @@ bool GrAAConvexTessellator::createInsetRing(const Ring& lastRing, Ring* nextRing
this->addTri(lastRing.index(cur), dst[next], dst[cur]);
}
- if (done && fStrokeWidth < 0.0f) {
- // fill
+ if (done) {
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));
}
@@ -738,6 +655,7 @@ 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<SkVector>& norms,
@@ -754,8 +672,11 @@ 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);
- SkPoint::Normalize(&fPts[cur].fNorm);
+ SkDEBUGCODE(SkScalar len =) SkPoint::Normalize(&fPts[cur].fNorm);
+ SkASSERT(len > 0.0f);
fPts[cur].fNorm.setOrthog(fPts[cur].fNorm, tess.side());
+
+ SkASSERT(SkScalarNearlyEqual(1.0f, fPts[cur].fNorm.length()));
}
}
@@ -773,7 +694,9 @@ void GrAAConvexTessellator::Ring::computeBisectors(const GrAAConvexTessellator&
} else {
fPts[cur].fBisector.negate(); // make the bisector face in
}
- }
+
+ SkASSERT(SkScalarNearlyEqual(1.0f, fPts[cur].fBisector.length()));
+ }
}
//////////////////////////////////////////////////////////////////////////////
@@ -781,7 +704,7 @@ void GrAAConvexTessellator::Ring::computeBisectors(const GrAAConvexTessellator&
// Is this ring convex?
bool GrAAConvexTessellator::Ring::isConvex(const GrAAConvexTessellator& tess) const {
if (fPts.count() < 3) {
- return true;
+ return false;
}
SkPoint prev = tess.point(fPts[0].fIndex) - tess.point(fPts.top().fIndex);
@@ -802,18 +725,74 @@ bool GrAAConvexTessellator::Ring::isConvex(const GrAAConvexTessellator& tess) co
prev = cur;
}
- if (SkScalarNearlyEqual(maxDot, 0.0f, 0.005f)) {
- maxDot = 0;
+ 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(minDot, 0.0f, 0.005f)) {
- minDot = 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;
+ }
}
- return (maxDot >= 0.0f) == (minDot >= 0.0f);
+
+ return closestSign * minDist;
}
+// 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
-void GrAAConvexTessellator::lineTo(SkPoint p, bool isCurve) {
+#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);
if (this->numPts() > 0 && duplicate_pt(p, this->lastPoint())) {
return;
}
@@ -826,22 +805,24 @@ void GrAAConvexTessellator::lineTo(SkPoint p, bool isCurve) {
fNorms.pop();
fIsCurve.pop();
}
- SkScalar initialRingCoverage = fStrokeWidth < 0.0f ? 0.5f : 1.0f;
- this->addPt(p, 0.0f, initialRingCoverage, false, isCurve);
+ this->addPt(p, 0.0f, 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::lineTo(const SkMatrix& m, SkPoint p, bool isCurve) {
- m.mapPoints(&p, 1);
- this->lineTo(p, isCurve);
-}
-
-void GrAAConvexTessellator::quadTo(SkPoint pts[3]) {
+void GrAAConvexTessellator::quadTo(const SkMatrix& m, SkPoint pts[3]) {
int maxCount = GrPathUtils::quadraticPointCount(pts, kQuadTolerance);
fPointBuffer.setReserve(maxCount);
SkPoint* target = fPointBuffer.begin();
@@ -849,21 +830,11 @@ void GrAAConvexTessellator::quadTo(SkPoint pts[3]) {
kQuadTolerance, &target, maxCount);
fPointBuffer.setCount(count);
for (int i = 0; i < count; i++) {
- lineTo(fPointBuffer[i], true);
+ lineTo(m, 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();
@@ -871,15 +842,14 @@ void GrAAConvexTessellator::cubicTo(const SkMatrix& m, SkPoint pts[4]) {
kCubicTolerance, &target, maxCount);
fPointBuffer.setCount(count);
for (int i = 0; i < count; i++) {
- lineTo(fPointBuffer[i], true);
+ lineTo(m, 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[3], SkScalar w) {
- m.mapPoints(pts, 3);
+void GrAAConvexTessellator::conicTo(const SkMatrix& m, SkPoint* pts, SkScalar w) {
SkAutoConicToQuads quadder;
const SkPoint* quads = quadder.computeQuads(pts, w, kConicTolerance);
SkPoint lastPoint = *(quads++);
@@ -889,7 +859,7 @@ void GrAAConvexTessellator::conicTo(const SkMatrix& m, SkPoint pts[3], SkScalar
quadPts[0] = lastPoint;
quadPts[1] = quads[0];
quadPts[2] = i == count - 1 ? pts[2] : quads[1];
- quadTo(quadPts);
+ quadTo(m, quadPts);
lastPoint = quadPts[2];
quads += 2;
}
@@ -995,13 +965,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 * kAntialiasingRadius)),
+ this->point(i), 0.5f + (this->depth(i)/(2*fTargetDepth)),
!this->movable(i));
SkPaint paint;
paint.setTextSize(kPointTextSize);
paint.setTextAlign(SkPaint::kCenter_Align);
- if (this->depth(i) <= -kAntialiasingRadius) {
+ if (this->depth(i) <= -fTargetDepth) {
paint.setColor(SK_ColorWHITE);
}
diff --git a/src/gpu/GrAAConvexTessellator.h b/src/gpu/GrAAConvexTessellator.h
index f3d84dc8ad..93e8d4ba61 100644
--- a/src/gpu/GrAAConvexTessellator.h
+++ b/src/gpu/GrAAConvexTessellator.h
@@ -9,7 +9,6 @@
#define GrAAConvexTessellator_DEFINED
#include "SkColor.h"
-#include "SkPaint.h"
#include "SkPoint.h"
#include "SkScalar.h"
#include "SkTDArray.h"
@@ -20,9 +19,6 @@ 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
@@ -31,15 +27,14 @@ class GrAAConvexTessellator;
// computeDepthFromEdge requests.
class GrAAConvexTessellator {
public:
- GrAAConvexTessellator(SkScalar strokeWidth = -1.0f,
- SkPaint::Join join = SkPaint::Join::kBevel_Join,
- SkScalar miterLimit = 0.0f)
+ GrAAConvexTessellator(SkScalar targetDepth = 0.5f)
: fSide(SkPoint::kOn_Side)
- , fStrokeWidth(strokeWidth)
- , fJoin(join)
- , fMiterLimit(miterLimit) {
+ , fTargetDepth(targetDepth) {
}
+ 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);
@@ -51,7 +46,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 coverage(int index) const { return fCoverages[index]; }
+ SkScalar depth(int index) const {return fDepths[index]; }
#if GR_AA_CONVEX_TESSELLATOR_VIZ
void draw(SkCanvas* canvas) const;
@@ -144,7 +139,6 @@ 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;
@@ -171,17 +165,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, SkScalar coverage, bool movable, bool isCurve);
+ int addPt(const SkPoint& pt, SkScalar depth, bool movable, bool isCurve);
void popLastPt();
void popFirstPtShuffle();
- void updatePt(int index, const SkPoint& pt, SkScalar depth, SkScalar coverage);
+ void updatePt(int index, const SkPoint& pt, SkScalar depth);
void addTri(int i0, int i1, int i2);
void reservePts(int count) {
fPts.setReserve(count);
- fCoverages.setReserve(count);
+ fDepths.setReserve(count);
fMovable.setReserve(count);
}
@@ -191,12 +185,8 @@ 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]);
@@ -210,24 +200,23 @@ private:
void computeBisectors();
void fanRing(const Ring& ring);
+ void createOuterRing();
Ring* getNextRing(Ring* lastRing);
- void createOuterRing(const Ring& previousRing, SkScalar outset, SkScalar coverage,
- Ring* nextRing);
+ bool createInsetRing(const Ring& lastRing, Ring* nextRing);
- bool createInsetRings(Ring& previousRing, SkScalar initialDepth, SkScalar initialCoverage,
- SkScalar targetDepth, SkScalar targetCoverage, Ring** finalRing);
+ void validate() const;
- bool createInsetRing(const Ring& lastRing, Ring* nextRing,
- SkScalar initialDepth, SkScalar initialCoverage, SkScalar targetDepth,
- SkScalar targetCoverage, bool forceNew);
- void validate() const;
+#ifdef SK_DEBUG
+ SkScalar computeRealDepth(const SkPoint& p) const;
+ void checkAllDepths() const;
+#endif
- // fPts, fCoverages & fMovable should always have the same # of elements
+ // fPts, fWeights & fMovable should always have the same # of elements
SkTDArray<SkPoint> fPts;
- SkTDArray<SkScalar> fCoverages;
+ SkTDArray<SkScalar> fDepths;
// movable points are those that can be slid further along their bisector
SkTDArray<bool> fMovable;
@@ -255,14 +244,18 @@ private:
#endif
CandidateVerts fCandidateVerts;
- // < 0 means filling rather than stroking
- SkScalar fStrokeWidth;
+ SkScalar fTargetDepth;
- SkPaint::Join fJoin;
+ SkTDArray<SkPoint> fPointBuffer;
- SkScalar fMiterLimit;
+ // 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;)
- SkTDArray<SkPoint> fPointBuffer;
+ SkDEBUGCODE(SkScalar fMinCross;)
+
+ SkDEBUGCODE(SkScalar fMaxCross;)
};
diff --git a/src/gpu/GrAALinearizingConvexPathRenderer.cpp b/src/gpu/GrAALinearizingConvexPathRenderer.cpp
index 786378ba84..5ded4d4b43 100644
--- a/src/gpu/GrAALinearizingConvexPathRenderer.cpp
+++ b/src/gpu/GrAALinearizingConvexPathRenderer.cpp
@@ -23,16 +23,11 @@
#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"
-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;
+#define DEFAULT_BUFFER_SIZE 100
GrAALinearizingConvexPathRenderer::GrAALinearizingConvexPathRenderer() {
}
@@ -45,21 +40,7 @@ bool GrAALinearizingConvexPathRenderer::canDrawPath(const GrDrawTarget* target,
const SkPath& path,
const GrStrokeInfo& stroke,
bool antiAlias) const {
- 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;
+ return (antiAlias && stroke.isFillStyle() && !path.isInverseFillType() && path.isConvex());
}
// extract the result vertices and indices from the GrAAConvexTessellator
@@ -79,15 +60,16 @@ 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.coverage(i)) <= 255);
- unsigned scale = SkScalarRoundToInt(255.0f * tess.coverage(i));
+ SkASSERT(SkScalarRoundToInt(255.0f * (tess.depth(i) + 0.5f)) <= 255);
+ unsigned scale = SkScalarRoundToInt(255.0f * (tess.depth(i) + 0.5f));
GrColor scaledColor = (0xff == scale) ? color : SkAlphaMulQ(color, scale);
*reinterpret_cast<GrColor*>(verts + i * vertexStride) = scaledColor;
} else {
*reinterpret_cast<GrColor*>(verts + i * vertexStride) = color;
*reinterpret_cast<float*>(verts + i * vertexStride + sizeof(GrColor)) =
- tess.coverage(i);
+ tess.depth(i) + 0.5f;
}
}
@@ -115,9 +97,6 @@ public:
GrColor fColor;
SkMatrix fViewMatrix;
SkPath fPath;
- SkScalar fStrokeWidth;
- SkPaint::Join fJoin;
- SkScalar fMiterLimit;
};
static GrBatch* Create(const Geometry& geometry) {
@@ -179,7 +158,7 @@ public:
firstIndex, vertexCount, indexCount);
batchTarget->draw(info);
}
-
+
void generateGeometry(GrBatchTarget* batchTarget, const GrPipeline* pipeline) override {
bool canTweakAlphaForCoverage = this->canTweakAlphaForCoverage();
@@ -203,6 +182,8 @@ public:
vertexStride == sizeof(GrDefaultGeoProcFactory::PositionColorAttr) :
vertexStride == sizeof(GrDefaultGeoProcFactory::PositionColorCoverageAttr));
+ GrAAConvexTessellator tess;
+
int instanceCount = fGeoData.count();
int vertexCount = 0;
@@ -212,8 +193,9 @@ 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;
@@ -305,7 +287,7 @@ bool GrAALinearizingConvexPathRenderer::onDrawPath(GrDrawTarget* target,
GrColor color,
const SkMatrix& vm,
const SkPath& path,
- const GrStrokeInfo& stroke,
+ const GrStrokeInfo&,
bool antiAlias) {
if (path.isEmpty()) {
return true;
@@ -314,9 +296,6 @@ 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<GrBatch> batch(AAFlatteningConvexPathBatch::Create(geometry));
target->drawBatch(pipelineBuilder, batch);
diff --git a/src/gpu/GrAddPathRenderers_default.cpp b/src/gpu/GrAddPathRenderers_default.cpp
index c60c7ce617..351b8eb1e4 100644
--- a/src/gpu/GrAddPathRenderers_default.cpp
+++ b/src/gpu/GrAddPathRenderers_default.cpp
@@ -9,7 +9,7 @@
#include "GrStencilAndCoverPathRenderer.h"
#include "GrAAHairLinePathRenderer.h"
-#include "GrAALinearizingConvexPathRenderer.h"
+#include "GrAAConvexPathRenderer.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(GrAALinearizingConvexPathRenderer))->unref();
+ chain->addPathRenderer(SkNEW(GrAAConvexPathRenderer))->unref();
chain->addPathRenderer(SkNEW_ARGS(GrAADistanceFieldPathRenderer, (ctx)))->unref();
}