aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu/GrTessellator.cpp
diff options
context:
space:
mode:
authorGravatar Stephen White <senorblanco@chromium.org>2017-01-27 10:53:15 -0500
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-01-27 21:06:55 +0000
commit86cc841e23a81af69269de87224c57be274f40d1 (patch)
treef3c28b044004a7dfeb3e085be7583e4757bf8542 /src/gpu/GrTessellator.cpp
parent2d0c238fcbd19d3b9e81352a9b88ca804e52d416 (diff)
AA GrTessellator: fix bevelling of acute angles.
The code to handle acute outer angles in generated geometry was pretty broken: it did a simple runnning average of consecutive acute vertices, and didn't handle acute angles between the last and first edges. Replaced it with something simpler that does proper bevelling for angles less than 2.5 degrees. This revealed a bug with thin path segments, exposed by the thinconcavepaths test. This will be fixed by upcoming changes, but I've also dded a few more test cases to make it clearer. Change-Id: I23a628ab2e16acaab798c746a5fd87842cacbfab Reviewed-on: https://skia-review.googlesource.com/7660 Reviewed-by: Brian Salomon <bsalomon@google.com> Commit-Queue: Stephan White <senorblanco@chromium.org>
Diffstat (limited to 'src/gpu/GrTessellator.cpp')
-rw-r--r--src/gpu/GrTessellator.cpp53
1 files changed, 19 insertions, 34 deletions
diff --git a/src/gpu/GrTessellator.cpp b/src/gpu/GrTessellator.cpp
index d193b7486c..981f11b822 100644
--- a/src/gpu/GrTessellator.cpp
+++ b/src/gpu/GrTessellator.cpp
@@ -1502,7 +1502,6 @@ void simplify_boundary(EdgeList* boundary, Comparator& c, SkChunkAlloc& alloc) {
// new antialiased mesh from those vertices.
void boundary_to_aa_mesh(EdgeList* boundary, VertexList* mesh, Comparator& c, SkChunkAlloc& alloc) {
- EdgeList outerContour;
Edge* prevEdge = boundary->fTail;
float radius = 0.5f;
double offset = radius * sqrt(prevEdge->fLine.magSq()) * prevEdge->fWinding;
@@ -1512,7 +1511,8 @@ void boundary_to_aa_mesh(EdgeList* boundary, VertexList* mesh, Comparator& c, Sk
prevOuter.fC += offset;
VertexList innerVertices;
VertexList outerVertices;
- SkScalar innerCount = SK_Scalar1, outerCount = SK_Scalar1;
+ SkVector prevNormal;
+ get_edge_normal(prevEdge, &prevNormal);
for (Edge* e = boundary->fHead; e != nullptr; e = e->fRight) {
double offset = radius * sqrt(e->fLine.magSq()) * e->fWinding;
Line inner(e->fTop, e->fBottom);
@@ -1520,50 +1520,35 @@ void boundary_to_aa_mesh(EdgeList* boundary, VertexList* mesh, Comparator& c, Sk
Line outer(e->fTop, e->fBottom);
outer.fC += offset;
SkPoint innerPoint, outerPoint;
+ SkVector normal;
+ get_edge_normal(e, &normal);
if (prevInner.intersect(inner, &innerPoint) &&
prevOuter.intersect(outer, &outerPoint)) {
- Vertex* innerVertex = ALLOC_NEW(Vertex, (innerPoint, 255), alloc);
- Vertex* outerVertex = ALLOC_NEW(Vertex, (outerPoint, 0), alloc);
- if (innerVertices.fTail && outerVertices.fTail) {
- Edge innerEdge(innerVertices.fTail, innerVertex, 1, Edge::Type::kInner);
- Edge outerEdge(outerVertices.fTail, outerVertex, 1, Edge::Type::kInner);
- SkVector innerNormal;
- get_edge_normal(&innerEdge, &innerNormal);
- SkVector outerNormal;
- get_edge_normal(&outerEdge, &outerNormal);
- SkVector normal;
- get_edge_normal(prevEdge, &normal);
- if (normal.dot(innerNormal) < 0) {
- innerPoint += innerVertices.fTail->fPoint * innerCount;
- innerCount++;
- innerPoint *= SkScalarInvert(innerCount);
- innerVertices.fTail->fPoint = innerVertex->fPoint = innerPoint;
- } else {
- innerCount = SK_Scalar1;
- }
- if (normal.dot(outerNormal) < 0) {
- outerPoint += outerVertices.fTail->fPoint * outerCount;
- outerCount++;
- outerPoint *= SkScalarInvert(outerCount);
- outerVertices.fTail->fPoint = outerVertex->fPoint = outerPoint;
- } else {
- outerCount = SK_Scalar1;
- }
+ // cos(theta) < -0.999 implies a miter angle of ~2.5 degrees,
+ // below which we'll bevel the outer edges.
+ if (prevNormal.dot(normal) < -0.999) {
+ SkPoint p = e->fWinding > 0 ? e->fTop->fPoint : e->fBottom->fPoint;
+ SkPoint outerPoint1 = p - prevNormal * radius;
+ SkPoint outerPoint2 = p - normal * radius;
+ innerVertices.append(ALLOC_NEW(Vertex, (innerPoint, 255), alloc));
+ innerVertices.append(ALLOC_NEW(Vertex, (innerPoint, 255), alloc));
+ outerVertices.append(ALLOC_NEW(Vertex, (outerPoint1, 0), alloc));
+ outerVertices.append(ALLOC_NEW(Vertex, (outerPoint2, 0), alloc));
+ } else {
+ innerVertices.append(ALLOC_NEW(Vertex, (innerPoint, 255), alloc));
+ outerVertices.append(ALLOC_NEW(Vertex, (outerPoint, 0), alloc));
}
- innerVertices.append(innerVertex);
- outerVertices.append(outerVertex);
- prevEdge = e;
}
prevInner = inner;
prevOuter = outer;
+ prevEdge = e;
+ prevNormal = normal;
}
innerVertices.close();
outerVertices.close();
Vertex* innerVertex = innerVertices.fHead;
Vertex* outerVertex = outerVertices.fHead;
- // Alternate clockwise and counterclockwise polys, so the tesselator
- // doesn't cancel out the interior edges.
if (!innerVertex || !outerVertex) {
return;
}