Fix nearly-vertical gradient assert

Use a SkScalarNearlyZero(dx) test instead of !SkScalarIsFinite(invDx).

R=reed@google.com

Review URL: https://codereview.chromium.org/1456783005
diff --git a/src/effects/gradients/SkLinearGradient.cpp b/src/effects/gradients/SkLinearGradient.cpp
index 0bb8969..013c1f1 100644
--- a/src/effects/gradients/SkLinearGradient.cpp
+++ b/src/effects/gradients/SkLinearGradient.cpp
@@ -893,7 +893,7 @@
     const float dither[2] = { dither0, dither1 };
     const float invDx = 1 / dx;
 
-    if (!SkScalarIsFinite(invDx)) { // dx is effectively zero, gradient is vertical
+    if (SkScalarNearlyZero(dx)) { // gradient is vertical
         Sk4f c = lerp_color(fx, find_forward(fRecs.begin(), SkTPin(fx, 0.0f, 1.0f)));
         if (fApplyAlphaAfterInterp) {
             fill<true>(dstC, count, c + dither0, c + dither1);
diff --git a/tests/GradientTest.cpp b/tests/GradientTest.cpp
index d0ea1f2..8d73569 100644
--- a/tests/GradientTest.cpp
+++ b/tests/GradientTest.cpp
@@ -9,6 +9,7 @@
 #include "SkColorShader.h"
 #include "SkGradientShader.h"
 #include "SkShader.h"
+#include "SkSurface.h"
 #include "SkTemplates.h"
 #include "Test.h"
 
@@ -196,8 +197,24 @@
     }
 }
 
+static void test_nearly_vertical(skiatest::Reporter* reporter) {
+    SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterN32Premul(200, 200));
+
+    const SkPoint pts[] = {{ 100, 50 }, { 100.0001f, 50000 }};
+    const SkColor colors[] = { SK_ColorBLACK, SK_ColorWHITE };
+    const SkScalar pos[] = { 0, 1 };
+    SkAutoTUnref<SkShader> gradient(
+        SkGradientShader::CreateLinear(pts, colors, pos, 2, SkShader::kClamp_TileMode));
+
+    SkPaint paint;
+    paint.setShader(gradient);
+
+    surface->getCanvas()->drawPaint(paint);
+}
+
 DEF_TEST(Gradient, reporter) {
     TestGradientShaders(reporter);
     TestConstantGradient(reporter);
     test_big_grad(reporter);
+    test_nearly_vertical(reporter);
 }