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>
This commit is contained in:
parent
7397d7ade8
commit
94b7e54256
@ -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;
|
||||
}
|
||||
|
@ -406,6 +406,17 @@ static SkPath create_path_26() {
|
||||
return path;
|
||||
}
|
||||
|
||||
|
||||
// A path which results in non-finite points when stroked and bevelled for AA.
|
||||
static SkPath create_path_27() {
|
||||
SkPath path;
|
||||
path.moveTo(8.5027233009104409507e+37, 1.7503381025241130639e+37);
|
||||
path.lineTo(7.0923661737711584874e+37, 1.4600074517285415699e+37);
|
||||
path.lineTo(7.0848733446033294691e+37, 1.4584649744781838604e+37);
|
||||
path.lineTo(-2.0473916115129349496e+37, -4.2146796450364162012e+36);
|
||||
path.lineTo(2.0473912312177548811e+37, 4.2146815465123165435e+36);
|
||||
return path;
|
||||
}
|
||||
static std::unique_ptr<GrFragmentProcessor> create_linear_gradient_processor(GrContext* ctx) {
|
||||
|
||||
SkPoint pts[2] = { {0, 0}, {1, 1} };
|
||||
@ -495,5 +506,6 @@ DEF_GPUTEST_FOR_ALL_CONTEXTS(TessellatingPathRendererTests, reporter, ctxInfo) {
|
||||
test_path(ctx, rtc.get(), create_path_24());
|
||||
test_path(ctx, rtc.get(), create_path_25(), SkMatrix(), GrAAType::kCoverage);
|
||||
test_path(ctx, rtc.get(), create_path_26(), SkMatrix(), GrAAType::kCoverage);
|
||||
test_path(ctx, rtc.get(), create_path_27(), SkMatrix(), GrAAType::kCoverage);
|
||||
}
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user