Fix case of variable shadowing in distance field generation.

The code structure here was confusing anyway, so I moved things around.
I don't think I changed any of the behavior, but there should be one
fewer if-comparison per pixel now. (In the failure case, we calculate
one more pixel worth of distance-field data than before, but that case
shouldn't ever happen anyway.)

Change-Id: I4615a5ee7372e742de11588682903c8e8c009df0
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/438316
Commit-Queue: Jim Van Verth <jvanverth@google.com>
Reviewed-by: Jim Van Verth <jvanverth@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
diff --git a/src/gpu/GrDistanceFieldGenFromVector.cpp b/src/gpu/GrDistanceFieldGenFromVector.cpp
index a2178c5..225fdcc 100644
--- a/src/gpu/GrDistanceFieldGenFromVector.cpp
+++ b/src/gpu/GrDistanceFieldGenFromVector.cpp
@@ -806,16 +806,16 @@
 
     // adjust distance based on winding
     for (int row = 0; row < height; ++row) {
-        int windingNumber = 0; // Winding number start from zero for each scanline
+        enum DFSign {
+            kInside = -1,
+            kOutside = 1
+        };
+        int windingNumber = 0;  // Winding number start from zero for each scanline
         for (int col = 0; col < width; ++col) {
             int idx = (row * width) + col;
             windingNumber += dataPtr[idx].fDeltaWindingScore;
 
-            enum DFSign {
-                kInside = -1,
-                kOutside = 1
-            } dfSign;
-
+            DFSign dfSign;
             switch (workingPath.getFillType()) {
                 case SkPathFillType::kWinding:
                     dfSign = windingNumber ? kInside : kOutside;
@@ -831,24 +831,6 @@
                     break;
             }
 
-            // The winding number at the end of a scanline should be zero.
-            SkASSERT(((col != width - 1) || (windingNumber == 0)) &&
-                    "Winding number should be zero at the end of a scan line.");
-            // Fallback to use SkPath::contains to determine the sign of pixel in release build.
-            if (col == width - 1 && windingNumber != 0) {
-                for (int col = 0; col < width; ++col) {
-                    int idx = (row * width) + col;
-                    dfSign = workingPath.contains(col + 0.5, row + 0.5) ? kInside : kOutside;
-                    const float miniDist = sqrt(dataPtr[idx].fDistSq);
-                    const float dist = dfSign * miniDist;
-
-                    unsigned char pixelVal = pack_distance_field_val<SK_DistanceFieldMagnitude>(dist);
-
-                    distanceField[(row * rowBytes) + col] = pixelVal;
-                }
-                continue;
-            }
-
             const float miniDist = sqrt(dataPtr[idx].fDistSq);
             const float dist = dfSign * miniDist;
 
@@ -856,6 +838,23 @@
 
             distanceField[(row * rowBytes) + col] = pixelVal;
         }
+
+        // The winding number at the end of a scanline should be zero.
+        if (windingNumber != 0) {
+            SkDEBUGFAIL("Winding number should be zero at the end of a scan line.");
+            // Fallback to use SkPath::contains to determine the sign of pixel in release build.
+            for (int col = 0; col < width; ++col) {
+                int idx = (row * width) + col;
+                DFSign dfSign = workingPath.contains(col + 0.5, row + 0.5) ? kInside : kOutside;
+                const float miniDist = sqrt(dataPtr[idx].fDistSq);
+                const float dist = dfSign * miniDist;
+
+                unsigned char pixelVal = pack_distance_field_val<SK_DistanceFieldMagnitude>(dist);
+
+                distanceField[(row * rowBytes) + col] = pixelVal;
+            }
+            continue;
+        }
     }
     return true;
 }