Use infinity to signal conics instead of NaN

From reading the GLSL ES spec, behavior around NaN handling is not
well defined. Infinity and isinf(), on the other hand, seems to be
well defined.

Bug: skia:10419
Change-Id: Id465a89a0d921707021974b5a64ec88bbcce0c33
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/341076
Commit-Queue: Chris Dalton <csmartdalton@google.com>
Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
This commit is contained in:
Chris Dalton 2020-12-04 16:27:50 -07:00 committed by Skia Commit-Bot
parent 198e6ea3f9
commit 011a77357e
3 changed files with 5 additions and 5 deletions

View File

@ -71,7 +71,7 @@ void GrFillCubicHullShader::emitVertexCode(Impl*, GrGLSLVertexBuilder* v, const
GrGLSLUniformHandler* uniformHandler) const {
v->codeAppend(R"(
float4x2 P = float4x2(input_points_0_1, input_points_2_3);
if (isnan(P[3].y)) {
if (isinf(P[3].y)) {
// This curve is actually a conic. Convert the control points to a trapeziodal hull
// that circumcscribes the conic.
float w = P[3].x;

View File

@ -72,7 +72,7 @@ public:
// Write out the 3 conic points to patch[0..2], the weight to patch[3].x, and then set
// patch[3].y as NaN to flag this patch as a conic.
memcpy(patch, pts, sizeof(SkPoint) * 3);
patch[3].set(w, std::numeric_limits<float>::quiet_NaN());
patch[3].set(w, std::numeric_limits<float>::infinity());
}
private:

View File

@ -36,7 +36,7 @@ constexpr static char kSkSLTypeDefs[] = R"(
constexpr static char kUnpackRationalCubicFn[] = R"(
float4x3 unpack_rational_cubic(float2 p0, float2 p1, float2 p2, float2 p3) {
float4x3 P = float4x3(p0,1, p1,1, p2,1, p3,1);
if (isnan(P[3].y)) {
if (isinf(P[3].y)) {
// This patch is actually a conic. Convert to a rational cubic.
float w = P[3].x;
float3 c = P[1] * (2/3.0 * w);
@ -77,8 +77,8 @@ protected:
nullptr, kVertex_GrShaderFlag, kFloat3x3_GrSLType, "view_matrix", &viewMatrix);
v->codeAppendf("float2 vertexpos = (%s * float3(inputPoint, 1)).xy;", viewMatrix);
if (shader.willUseTessellationShaders()) {
// If y is NaN then x is a conic weight. Don't transform.
v->codeAppendf("vertexpos = (isnan(vertexpos.y)) ? inputPoint : vertexpos;");
// If y is infinity then x is a conic weight. Don't transform.
v->codeAppendf("vertexpos = (isinf(vertexpos.y)) ? inputPoint : vertexpos;");
}
vertexPos.set(kFloat2_GrSLType, "vertexpos");
}