Make tessellation join type values negative
This feels more intuitive and it allows the override number of
segments to be positive.
Bug: skia:10419
Change-Id: I0a57d9b114abb4ec8472e1c405ace4385be23e42
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/306417
Reviewed-by: Michael Ludwig <michaelludwig@google.com>
Commit-Queue: Chris Dalton <csmartdalton@google.com>
diff --git a/src/gpu/tessellate/GrStrokePatchBuilder.cpp b/src/gpu/tessellate/GrStrokePatchBuilder.cpp
index 30ba51f..05aa5f6 100644
--- a/src/gpu/tessellate/GrStrokePatchBuilder.cpp
+++ b/src/gpu/tessellate/GrStrokePatchBuilder.cpp
@@ -84,7 +84,7 @@
if (SkPoint* patch = this->reservePatch()) {
memcpy(patch, pts, sizeof(SkPoint) * 4);
- patch[4].set(-overrideNumSegments, fCurrStrokeRadius);
+ patch[4].set(overrideNumSegments, fCurrStrokeRadius);
}
fLastControlPoint = c2;
@@ -117,7 +117,7 @@
// T=.5, and we need to ensure that point stays inside the cap.
capPatch[2] = endPoint + capPoint - controlPoint;
capPatch[3] = capPoint;
- capPatch[4].set(-1, fCurrStrokeRadius);
+ capPatch[4].set(1, fCurrStrokeRadius);
}
}
@@ -136,9 +136,10 @@
break;
case SkPaint::kRound_Cap:
// A round cap is the same thing as a 180-degree round join.
- this->writeJoin(3, fCurrContourStartPoint, fCurrContourFirstControlPoint,
- fCurrContourFirstControlPoint);
- this->writeJoin(3, fCurrentPoint, fLastControlPoint, fLastControlPoint);
+ this->writeJoin(GrTessellateStrokeShader::kRoundJoinType, fCurrContourStartPoint,
+ fCurrContourFirstControlPoint, fCurrContourFirstControlPoint);
+ this->writeJoin(GrTessellateStrokeShader::kRoundJoinType, fCurrentPoint,
+ fLastControlPoint, fLastControlPoint);
break;
case SkPaint::kSquare_Cap:
this->writeSquareCap(fCurrContourStartPoint, fCurrContourFirstControlPoint);
diff --git a/src/gpu/tessellate/GrTessellateStrokeShader.cpp b/src/gpu/tessellate/GrTessellateStrokeShader.cpp
index d24101c..2326d31 100644
--- a/src/gpu/tessellate/GrTessellateStrokeShader.cpp
+++ b/src/gpu/tessellate/GrTessellateStrokeShader.cpp
@@ -109,14 +109,14 @@
abs(P[3] - P[2]*2.0 + P[1]))));
// A patch can override the number of segments it gets chopped into by passing a
- // negative value as P[4].x. (Square caps do this to only draw one segment.)
- if (P[4].x < 0) {
- numSegments = -P[4].x;
+ // positive value as P[4].x.
+ if (P[4].x > 0) {
+ numSegments = P[4].x;
}
- // A positive value in P[4].x means this patch actually represents a join instead
+ // A negative value in P[4].x means this patch actually represents a join instead
// of a stroked cubic. Joins are implemented as radial fans from the junction point.
- if (P[4].x > 0) {
+ if (P[4].x < 0) {
// Start by finding the angle between the tangents coming in and out of the
// join.
vec2 c0 = P[1] - P[0];
@@ -127,10 +127,10 @@
fanAngles[gl_InvocationID /*== 0*/] = atan(c0.y, c0.x) + vec2(0, theta);
float joinType = P[4].x;
- if (joinType >= 3) {
+ if (joinType <= -3) {
// Round join. Decide how many fan segments we need in order to be smooth.
numSegments = abs(theta) / (2 * acos(1 - kTolerance/strokeRadius));
- } else if (joinType == 2) {
+ } else if (joinType == -2) {
// Miter join. Draw a fan with 2 segments and lengthen the interior radius
// so it matches the miter point.
// (Or draw a 1-segment fan if we exceed the miter limit.)
@@ -155,7 +155,7 @@
// is fine because we will only draw one segment with vertices at T=0 and
// T=1, and the shader won't use fanAngles on the two outer vertices.
fanAngles[gl_InvocationID /*== 0*/] = vec2(1, 0);
- } else if (joinType != 4) {
+ } else if (joinType != -4) {
// This is a standard join. Restrict it to the outside of the junction.
outsetClamp[gl_InvocationID /*== 0*/] = mix(
vec2(-1, 1), vec2(0), lessThan(vec2(-theta, theta), vec2(0)));
diff --git a/src/gpu/tessellate/GrTessellateStrokeShader.h b/src/gpu/tessellate/GrTessellateStrokeShader.h
index 5e5fbc4..34d0c13 100644
--- a/src/gpu/tessellate/GrTessellateStrokeShader.h
+++ b/src/gpu/tessellate/GrTessellateStrokeShader.h
@@ -38,10 +38,10 @@
// tessellationPatchVertexCount of 5.
class GrTessellateStrokeShader : public GrPathShader {
public:
- constexpr static float kBevelJoinType = 1;
- constexpr static float kMiterJoinType = 2;
- constexpr static float kRoundJoinType = 3;
- constexpr static float kInternalRoundJoinType = 4;
+ constexpr static float kBevelJoinType = -1;
+ constexpr static float kMiterJoinType = -2;
+ constexpr static float kRoundJoinType = -3;
+ constexpr static float kInternalRoundJoinType = -4;
constexpr static int kNumVerticesPerPatch = 5;