diff options
author | Stephen White <senorblanco@chromium.org> | 2018-01-04 14:01:10 -0500 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2018-01-04 21:36:06 +0000 |
commit | 94b7e5425683996c8bc3ca0e7b549ab7235c1180 (patch) | |
tree | 0a6f412c2825118f754e5990c8d348a732b7fae0 /src/gpu/GrTessellator.cpp | |
parent | 7397d7ade8b72f3b75e9384693aa59292a63fd68 (diff) |
GrTessellator: fix for points which become non-finite on AA stroking.
If input points are near-infinite, they may become inf or NaN when
stroked. Before converting the results of intersection from double
to float, clamp them to the [-FLT_MAX/FLT_MAX] range.
BUG=798679
Change-Id: I7d61130dd26147a9b7cfd38aa96567e3867b5c3e
Reviewed-on: https://skia-review.googlesource.com/90983
Commit-Queue: Stephen White <senorblanco@chromium.org>
Reviewed-by: Brian Osman <brianosman@google.com>
Diffstat (limited to 'src/gpu/GrTessellator.cpp')
-rw-r--r-- | src/gpu/GrTessellator.cpp | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/src/gpu/GrTessellator.cpp b/src/gpu/GrTessellator.cpp index 34be6f75e4..3e90046b8f 100644 --- a/src/gpu/GrTessellator.cpp +++ b/src/gpu/GrTessellator.cpp @@ -16,6 +16,7 @@ #include "SkPointPriv.h" #include "SkTDPQueue.h" +#include <algorithm> #include <stdio.h> /* @@ -282,6 +283,10 @@ inline void round(SkPoint* p) { p->fY = SkScalarRoundToScalar(p->fY * SkFloatToScalar(4.0f)) * SkFloatToScalar(0.25f); } +inline SkScalar double_to_clamped_scalar(double d) { + return SkDoubleToScalar(std::min((double) SK_ScalarMax, std::max(d, (double) -SK_ScalarMax))); +} + // A line equation in implicit form. fA * x + fB * y + fC = 0, for all points (x, y) on the line. struct Line { Line(double a, double b, double c) : fA(a), fB(b), fC(c) {} @@ -320,9 +325,9 @@ struct Line { if (denom == 0.0) { return false; } - double scale = 1.0f / denom; - point->fX = SkDoubleToScalar((fB * other.fC - other.fB * fC) * scale); - point->fY = SkDoubleToScalar((other.fA * fC - fA * other.fC) * scale); + double scale = 1.0 / denom; + point->fX = double_to_clamped_scalar((fB * other.fC - other.fB * fC) * scale); + point->fY = double_to_clamped_scalar((other.fA * fC - fA * other.fC) * scale); round(point); return true; } |