GrTessellator: misc. cleanups and minor tweaks.
Invert some math to remove a negation.
Don't keep a persistent count in EdgeList; we'll test for degenerate
boundaries in boundary_to_aa_mesh().
Make connect() use the top/bottom ordering that new_edge has already
done for us.
Don't add the an edge to the same poly twice when it's easily detectable.
Remove some superfluous variables and intialization.
BUG=skia:
Change-Id: I0efd9ec385d6dfec8950b7acfc6dd25572f667b5
Reviewed-on: https://skia-review.googlesource.com/8784
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Stephen White <senorblanco@chromium.org>
diff --git a/src/gpu/GrTessellator.cpp b/src/gpu/GrTessellator.cpp
index dda8f48..388e951 100644
--- a/src/gpu/GrTessellator.cpp
+++ b/src/gpu/GrTessellator.cpp
@@ -378,10 +378,10 @@
if (denom == 0.0) {
return false;
}
- double dx = static_cast<double>(fTop->fPoint.fX) - other.fTop->fPoint.fX;
- double dy = static_cast<double>(fTop->fPoint.fY) - other.fTop->fPoint.fY;
- double sNumer = -dy * other.fLine.fB - dx * other.fLine.fA;
- double tNumer = -dy * fLine.fB - dx * fLine.fA;
+ double dx = static_cast<double>(other.fTop->fPoint.fX) - fTop->fPoint.fX;
+ double dy = static_cast<double>(other.fTop->fPoint.fY) - fTop->fPoint.fY;
+ double sNumer = dy * other.fLine.fB + dx * other.fLine.fA;
+ double tNumer = dy * fLine.fB + dx * fLine.fA;
// If (sNumer / denom) or (tNumer / denom) is not in [0..1], exit early.
// This saves us doing the divide below unless absolutely necessary.
if (denom > 0.0 ? (sNumer < 0.0 || sNumer > denom || tNumer < 0.0 || tNumer > denom)
@@ -409,21 +409,18 @@
};
struct EdgeList {
- EdgeList() : fHead(nullptr), fTail(nullptr), fNext(nullptr), fCount(0) {}
+ EdgeList() : fHead(nullptr), fTail(nullptr), fNext(nullptr) {}
Edge* fHead;
Edge* fTail;
EdgeList* fNext;
- int fCount;
void insert(Edge* edge, Edge* prev, Edge* next) {
list_insert<Edge, &Edge::fLeft, &Edge::fRight>(edge, prev, next, &fHead, &fTail);
- fCount++;
}
void append(Edge* e) {
insert(e, fTail, nullptr);
}
void remove(Edge* edge) {
list_remove<Edge, &Edge::fLeft, &Edge::fRight>(edge, &fHead, &fTail);
- fCount--;
}
void close() {
if (fHead && fTail) {
@@ -1050,13 +1047,8 @@
Edge* connect(Vertex* prev, Vertex* next, Edge::Type type, Comparator& c, SkArenaAlloc& alloc,
int winding_scale = 1) {
Edge* edge = new_edge(prev, next, type, c, alloc);
- if (edge->fWinding > 0) {
- insert_edge_below(edge, prev, c);
- insert_edge_above(edge, next, c);
- } else {
- insert_edge_below(edge, next, c);
- insert_edge_above(edge, prev, c);
- }
+ insert_edge_below(edge, edge->fTop, c);
+ insert_edge_above(edge, edge->fBottom, c);
edge->fWinding *= winding_scale;
merge_collinear_edges(edge, nullptr, c);
return edge;
@@ -1294,8 +1286,8 @@
#if LOGGING_ENABLED
LOG("\nvertex %g: (%g,%g), alpha %d\n", v->fID, v->fPoint.fX, v->fPoint.fY, v->fAlpha);
#endif
- Edge* leftEnclosingEdge = nullptr;
- Edge* rightEnclosingEdge = nullptr;
+ Edge* leftEnclosingEdge;
+ Edge* rightEnclosingEdge;
bool restartChecks;
do {
restartChecks = false;
@@ -1353,11 +1345,11 @@
#if LOGGING_ENABLED
LOG("\nvertex %g: (%g,%g), alpha %d\n", v->fID, v->fPoint.fX, v->fPoint.fY, v->fAlpha);
#endif
- Edge* leftEnclosingEdge = nullptr;
- Edge* rightEnclosingEdge = nullptr;
+ Edge* leftEnclosingEdge;
+ Edge* rightEnclosingEdge;
find_enclosing_edges(v, &activeEdges, &leftEnclosingEdge, &rightEnclosingEdge);
- Poly* leftPoly = nullptr;
- Poly* rightPoly = nullptr;
+ Poly* leftPoly;
+ Poly* rightPoly;
if (v->fFirstEdgeAbove) {
leftPoly = v->fFirstEdgeAbove->fLeftPoly;
rightPoly = v->fLastEdgeAbove->fRightPoly;
@@ -1385,14 +1377,13 @@
rightPoly = rightPoly->addEdge(v->fLastEdgeAbove, Poly::kLeft_Side, alloc);
}
for (Edge* e = v->fFirstEdgeAbove; e != v->fLastEdgeAbove; e = e->fNextEdgeAbove) {
- Edge* leftEdge = e;
Edge* rightEdge = e->fNextEdgeAbove;
- SkASSERT(rightEdge->isRightOf(leftEdge->fTop));
- remove_edge(leftEdge, &activeEdges);
- if (leftEdge->fRightPoly) {
- leftEdge->fRightPoly->addEdge(e, Poly::kLeft_Side, alloc);
+ SkASSERT(rightEdge->isRightOf(e->fTop));
+ remove_edge(e, &activeEdges);
+ if (e->fRightPoly) {
+ e->fRightPoly->addEdge(e, Poly::kLeft_Side, alloc);
}
- if (rightEdge->fLeftPoly) {
+ if (rightEdge->fLeftPoly && rightEdge->fLeftPoly != e->fRightPoly) {
rightEdge->fLeftPoly->addEdge(e, Poly::kRight_Side, alloc);
}
}
@@ -1545,6 +1536,10 @@
// new antialiased mesh from those vertices.
void boundary_to_aa_mesh(EdgeList* boundary, VertexList* mesh, Comparator& c, SkArenaAlloc& alloc) {
+ // A boundary with fewer than 3 edges is degenerate.
+ if (!boundary->fHead || !boundary->fHead->fRight || !boundary->fHead->fRight->fRight) {
+ return;
+ }
Edge* prevEdge = boundary->fTail;
float radius = 0.5f;
double offset = radius * sqrt(prevEdge->fLine.magSq()) * prevEdge->fWinding;
@@ -1707,9 +1702,7 @@
VertexList aaMesh;
for (EdgeList* boundary = boundaries; boundary != nullptr; boundary = boundary->fNext) {
simplify_boundary(boundary, c, alloc);
- if (boundary->fCount > 2) {
- boundary_to_aa_mesh(boundary, &aaMesh, c, alloc);
- }
+ boundary_to_aa_mesh(boundary, &aaMesh, c, alloc);
}
sort_and_simplify(&aaMesh, c, alloc);
return tessellate(aaMesh, alloc);