Move emit functions from Poly/Vertex structs into GrTriangulator

Bug: skia:10419
Change-Id: I6351513b365a190dd97312a0b3d436a44b8fb10a
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/351858
Reviewed-by: Jim Van Verth <jvanverth@google.com>
Commit-Queue: Chris Dalton <csmartdalton@google.com>
This commit is contained in:
Chris Dalton 2021-01-07 19:10:14 -07:00 committed by Skia Commit-Bot
parent 508eba7578
commit 9a4904f4e0
2 changed files with 18 additions and 15 deletions

View File

@ -303,13 +303,13 @@ void GrTriangulator::MonotonePoly::addEdge(Edge* edge) {
}
}
void* GrTriangulator::MonotonePoly::emit(bool emitCoverage, void* data) {
Edge* e = fFirstEdge;
void* GrTriangulator::emitMonotonePoly(const MonotonePoly* monotonePoly, void* data) {
Edge* e = monotonePoly->fFirstEdge;
VertexList vertices;
vertices.append(e->fTop);
int count = 1;
while (e != nullptr) {
if (kRight_Side == fSide) {
if (kRight_Side == monotonePoly->fSide) {
vertices.append(e->fBottom);
e = e->fRightPolyNext;
} else {
@ -326,14 +326,14 @@ void* GrTriangulator::MonotonePoly::emit(bool emitCoverage, void* data) {
Vertex* curr = v;
Vertex* next = v->fNext;
if (count == 3) {
return this->emitTriangle(prev, curr, next, emitCoverage, data);
return this->emitTriangle(prev, curr, next, monotonePoly->fWinding, data);
}
double ax = static_cast<double>(curr->fPoint.fX) - prev->fPoint.fX;
double ay = static_cast<double>(curr->fPoint.fY) - prev->fPoint.fY;
double bx = static_cast<double>(next->fPoint.fX) - curr->fPoint.fX;
double by = static_cast<double>(next->fPoint.fY) - curr->fPoint.fY;
if (ax * by - ay * bx >= 0.0) {
data = this->emitTriangle(prev, curr, next, emitCoverage, data);
data = this->emitTriangle(prev, curr, next, monotonePoly->fWinding, data);
v->fPrev->fNext = v->fNext;
v->fNext->fPrev = v->fPrev;
count--;
@ -349,14 +349,14 @@ void* GrTriangulator::MonotonePoly::emit(bool emitCoverage, void* data) {
return data;
}
void* GrTriangulator::MonotonePoly::emitTriangle(Vertex* prev, Vertex* curr, Vertex* next,
bool emitCoverage, void* data) const {
if (fWinding < 0) {
void* GrTriangulator::emitTriangle(Vertex* prev, Vertex* curr, Vertex* next, int winding,
void* data) const {
if (winding < 0) {
// Ensure our triangles always wind in the same direction as if the path had been
// triangulated as a simple fan (a la red book).
std::swap(prev, next);
}
return emit_triangle(next, curr, prev, emitCoverage, data);
return emit_triangle(next, curr, prev, fEmitCoverage, data);
}
Poly* GrTriangulator::Poly::addEdge(Edge* e, Side side, SkArenaAlloc& alloc) {
@ -400,13 +400,13 @@ Poly* GrTriangulator::Poly::addEdge(Edge* e, Side side, SkArenaAlloc& alloc) {
}
return poly;
}
void* GrTriangulator::Poly::emit(bool emitCoverage, void *data) {
if (fCount < 3) {
void* GrTriangulator::emitPoly(const Poly* poly, void *data) {
if (poly->fCount < 3) {
return data;
}
TESS_LOG("emit() %d, size %d\n", fID, fCount);
for (MonotonePoly* m = fHead; m != nullptr; m = m->fNext) {
data = m->emit(emitCoverage, data);
for (MonotonePoly* m = poly->fHead; m != nullptr; m = m->fNext) {
data = this->emitMonotonePoly(m, data);
}
return data;
}
@ -2034,7 +2034,7 @@ Poly* GrTriangulator::contoursToPolys(VertexList* contours, int contourCnt, Vert
void* GrTriangulator::polysToTriangles(Poly* polys, void* data, SkPathFillType overrideFillType) {
for (Poly* poly = polys; poly; poly = poly->fNext) {
if (apply_fill_type(overrideFillType, poly)) {
data = poly->emit(fEmitCoverage, data);
data = this->emitPoly(poly, data);
}
}
return data;
@ -2185,7 +2185,7 @@ int GrTriangulator::PathToVertices(const SkPath& path, SkScalar tolerance, const
for (Poly* poly = polys; poly; poly = poly->fNext) {
if (apply_fill_type(fillType, poly)) {
SkPoint* start = pointsEnd;
pointsEnd = static_cast<SkPoint*>(poly->emit(false, pointsEnd));
pointsEnd = static_cast<SkPoint*>(triangulator.emitPoly(poly, pointsEnd));
while (start != pointsEnd) {
vertsEnd->fPos = *start;
vertsEnd->fWinding = poly->fWinding;

View File

@ -170,6 +170,9 @@ private:
// setting rotates 90 degrees counterclockwise, rather that transposing.
// Additional helpers and driver functions.
void* emitMonotonePoly(const MonotonePoly*, void* data);
void* emitTriangle(Vertex* prev, Vertex* curr, Vertex* next, int winding, void* data) const;
void* emitPoly(const Poly*, void *data);
void appendPointToContour(const SkPoint& p, VertexList* contour);
void appendQuadraticToContour(const SkPoint[3], SkScalar toleranceSqd, VertexList* contour);
void generateCubicPoints(const SkPoint&, const SkPoint&, const SkPoint&, const SkPoint&,