Revert of Fix for degenerate stroke rect (patchset #7 id:110001 of https://codereview.chromium.org/1359453002/ )

Reason for revert:
breaking bots

Original issue's description:
> Fix for degenerate stroke rect
>
> BUG=skia:
>
> Committed: https://skia.googlesource.com/skia/+/511684fb52f20862f8552f5009390ff3987b08d8

TBR=robertphillips@google.com,joshualitt@chromium.org
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=skia:

Review URL: https://codereview.chromium.org/1356223003
diff --git a/src/gpu/batches/GrAAStrokeRectBatch.cpp b/src/gpu/batches/GrAAStrokeRectBatch.cpp
index baea72f..0a9601f 100644
--- a/src/gpu/batches/GrAAStrokeRectBatch.cpp
+++ b/src/gpu/batches/GrAAStrokeRectBatch.cpp
@@ -53,7 +53,6 @@
         SkRect fDevOutsideAssist;
         SkRect fDevInside;
         GrColor fColor;
-        bool fDegenerate;
     };
 
     static AAStrokeRectBatch* Create(const SkMatrix& viewMatrix, bool miterStroke) {
@@ -78,19 +77,17 @@
     }
 
     void append(GrColor color, const SkRect& devOutside, const SkRect& devOutsideAssist,
-                const SkRect& devInside, bool degenerate) {
+                const SkRect& devInside) {
         Geometry& geometry = fGeoData.push_back();
         geometry.fColor = color;
         geometry.fDevOutside = devOutside;
         geometry.fDevOutsideAssist = devOutsideAssist;
         geometry.fDevInside = devInside;
-        geometry.fDegenerate = degenerate;
     }
 
     void appendAndUpdateBounds(GrColor color, const SkRect& devOutside,
-                               const SkRect& devOutsideAssist, const SkRect& devInside,
-                               bool degenerate) {
-        this->append(color, devOutside, devOutsideAssist, devInside, degenerate);
+                               const SkRect& devOutsideAssist, const SkRect& devInside) {
+        this->append(color, devOutside, devOutsideAssist, devInside);
 
         SkRect bounds;
         this->updateBounds(&bounds, fGeoData.back());
@@ -148,7 +145,6 @@
                                       const SkRect& devOutsideAssist,
                                       const SkRect& devInside,
                                       bool miterStroke,
-                                      bool degenerate,
                                       bool tweakAlphaForCoverage) const;
 
     struct BatchTracker {
@@ -230,7 +226,6 @@
                                            args.fDevOutsideAssist,
                                            args.fDevInside,
                                            fMiterStroke,
-                                           args.fDegenerate,
                                            canTweakAlphaForCoverage);
     }
     helper.recordDraw(target);
@@ -361,15 +356,6 @@
     return true;
 }
 
-static void setup_scale(int* scale, SkScalar inset) {
-    if (inset < SK_ScalarHalf) {
-        *scale = SkScalarFloorToInt(512.0f * inset / (inset + SK_ScalarHalf));
-        SkASSERT(*scale >= 0 && *scale <= 255);
-    } else {
-        *scale = 0xff;
-    }
-}
-
 void AAStrokeRectBatch::generateAAStrokeRectGeometry(void* vertices,
                                                      size_t offset,
                                                      size_t vertexStride,
@@ -380,7 +366,6 @@
                                                      const SkRect& devOutsideAssist,
                                                      const SkRect& devInside,
                                                      bool miterStroke,
-                                                     bool degenerate,
                                                      bool tweakAlphaForCoverage) const {
     intptr_t verts = reinterpret_cast<intptr_t>(vertices) + offset;
 
@@ -397,34 +382,18 @@
 #ifndef SK_IGNORE_THIN_STROKED_RECT_FIX
     // TODO: this only really works if the X & Y margins are the same all around
     // the rect (or if they are all >= 1.0).
-    SkScalar inset;
-    if (!degenerate) {
-        inset = SkMinScalar(SK_Scalar1, devOutside.fRight - devInside.fRight);
-        inset = SkMinScalar(inset, devInside.fLeft - devOutside.fLeft);
-        inset = SkMinScalar(inset, devInside.fTop - devOutside.fTop);
-        if (miterStroke) {
-            inset = SK_ScalarHalf * SkMinScalar(inset, devOutside.fBottom - devInside.fBottom);
-        } else {
-            inset = SK_ScalarHalf * SkMinScalar(inset, devOutsideAssist.fBottom -
-                                                       devInside.fBottom);
-        }
-        SkASSERT(inset >= 0);
+    SkScalar inset = SkMinScalar(SK_Scalar1, devOutside.fRight - devInside.fRight);
+    inset = SkMinScalar(inset, devInside.fLeft - devOutside.fLeft);
+    inset = SkMinScalar(inset, devInside.fTop - devOutside.fTop);
+    if (miterStroke) {
+        inset = SK_ScalarHalf * SkMinScalar(inset, devOutside.fBottom - devInside.fBottom);
     } else {
-        // TODO use real devRect here
-        inset = SkMinScalar(devOutside.width(), SK_Scalar1);
-        inset = SK_ScalarHalf * SkMinScalar(inset, SkTMax(devOutside.height(),
-                                                          devOutsideAssist.height()));
+        inset = SK_ScalarHalf * SkMinScalar(inset, devOutsideAssist.fBottom -
+                                                   devInside.fBottom);
     }
+    SkASSERT(inset >= 0);
 #else
-    SkScalar inset;
-    if (!degenerate) {
-        inset = SK_ScalarHalf;
-    } else {
-        // TODO use real devRect here
-        inset = SkMinScalar(devOutside.width(), SK_Scalar1);
-        inset = SK_ScalarHalf * SkMinScalar(inset, SkTMax(devOutside.height(),
-                                                          devOutsideAssist.height()));
-    }
+    SkScalar inset = SK_ScalarHalf;
 #endif
 
     if (miterStroke) {
@@ -432,19 +401,9 @@
         set_inset_fan(fan0Pos, vertexStride, devOutside, -SK_ScalarHalf, -SK_ScalarHalf);
         // inner two
         set_inset_fan(fan1Pos, vertexStride, devOutside,  inset,  inset);
-        if (!degenerate) {
-            set_inset_fan(fan2Pos, vertexStride, devInside,  -inset, -inset);
-            // innermost
-            set_inset_fan(fan3Pos, vertexStride, devInside,   SK_ScalarHalf,  SK_ScalarHalf);
-        } else {
-            // When the interior rect has become degenerate we smoosh to a single point
-            SkASSERT(devInside.fLeft == devInside.fRight &&
-                     devInside.fTop == devInside.fBottom);
-            fan2Pos->setRectFan(devInside.fLeft, devInside.fTop,
-                                devInside.fRight, devInside.fBottom, vertexStride);
-            fan3Pos->setRectFan(devInside.fLeft, devInside.fTop,
-                                devInside.fRight, devInside.fBottom, vertexStride);
-        }
+        set_inset_fan(fan2Pos, vertexStride, devInside,  -inset, -inset);
+        // innermost
+        set_inset_fan(fan3Pos, vertexStride, devInside,   SK_ScalarHalf,  SK_ScalarHalf);
     } else {
         SkPoint* fan0AssistPos = reinterpret_cast<SkPoint*>(verts + 4 * vertexStride);
         SkPoint* fan1AssistPos = reinterpret_cast<SkPoint*>(verts +
@@ -457,20 +416,10 @@
         // outer one of the inner two
         set_inset_fan(fan1Pos, vertexStride, devOutside,  inset,  inset);
         set_inset_fan(fan1AssistPos, vertexStride, devOutsideAssist,  inset,  inset);
-        if (!degenerate) {
-            // inner one of the inner two
-            set_inset_fan(fan2Pos, vertexStride, devInside,  -inset, -inset);
-            // innermost
-            set_inset_fan(fan3Pos, vertexStride, devInside,   SK_ScalarHalf,  SK_ScalarHalf);
-        } else {
-            // When the interior rect has become degenerate we smoosh to a single point
-            SkASSERT(devInside.fLeft == devInside.fRight &&
-                     devInside.fTop == devInside.fBottom);
-            fan2Pos->setRectFan(devInside.fLeft, devInside.fTop,
-                                devInside.fRight, devInside.fBottom, vertexStride);
-            fan3Pos->setRectFan(devInside.fLeft, devInside.fTop,
-                                devInside.fRight, devInside.fBottom, vertexStride);
-        }
+        // inner one of the inner two
+        set_inset_fan(fan2Pos, vertexStride, devInside,  -inset, -inset);
+        // innermost
+        set_inset_fan(fan3Pos, vertexStride, devInside,   SK_ScalarHalf,  SK_ScalarHalf);
     }
 
     // Make verts point to vertex color and then set all the color and coverage vertex attrs
@@ -487,7 +436,12 @@
 
     // scale is the coverage for the the inner two rects.
     int scale;
-    setup_scale(&scale, inset);
+    if (inset < SK_ScalarHalf) {
+        scale = SkScalarFloorToInt(512.0f * inset / (inset + SK_ScalarHalf));
+        SkASSERT(scale >= 0 && scale <= 255);
+    } else {
+        scale = 0xff;
+    }
 
     float innerCoverage = GrNormalizeByteToFloat(scale);
     GrColor scaledColor = (0xff == scale) ? color : SkAlphaMulQ(color, scale);
@@ -498,24 +452,19 @@
             *reinterpret_cast<GrColor*>(verts + i * vertexStride) = scaledColor;
         } else {
             *reinterpret_cast<GrColor*>(verts + i * vertexStride) = color;
-            *reinterpret_cast<float*>(verts + i * vertexStride + sizeof(GrColor)) = innerCoverage;
+            *reinterpret_cast<float*>(verts + i * vertexStride + sizeof(GrColor)) =
+                    innerCoverage;
         }
     }
 
-    // The innermost rect has 0 coverage, unless we are degenerate, in which case we must apply the
-    // scaled coverage
+    // The innermost rect has 0 coverage
     verts += (outerVertexNum + innerVertexNum) * vertexStride;
-    if (!degenerate) {
-        innerCoverage = 0;
-        scaledColor = 0;
-    }
-
     for (int i = 0; i < innerVertexNum; ++i) {
         if (tweakAlphaForCoverage) {
-            *reinterpret_cast<GrColor*>(verts + i * vertexStride) = scaledColor;
+            *reinterpret_cast<GrColor*>(verts + i * vertexStride) = 0;
         } else {
             *reinterpret_cast<GrColor*>(verts + i * vertexStride) = color;
-            *reinterpret_cast<float*>(verts + i * vertexStride + sizeof(GrColor)) = innerCoverage;
+            *reinterpret_cast<GrColor*>(verts + i * vertexStride + sizeof(GrColor)) = 0;
         }
     }
 }
@@ -527,10 +476,9 @@
                     const SkRect& devOutside,
                     const SkRect& devOutsideAssist,
                     const SkRect& devInside,
-                    bool miterStroke,
-                    bool degenerate) {
+                    bool miterStroke) {
     AAStrokeRectBatch* batch = AAStrokeRectBatch::Create(viewMatrix, miterStroke);
-    batch->append(color, devOutside, devOutsideAssist, devInside, degenerate);
+    batch->append(color, devOutside, devOutsideAssist, devInside);
     batch->init();
     return batch;
 }
@@ -541,8 +489,7 @@
             const SkRect& devOutside,
             const SkRect& devOutsideAssist,
             const SkRect& devInside,
-            bool miterStroke,
-            bool degenerate) {
+            bool miterStroke) {
     AAStrokeRectBatch* batch = origBatch->cast<AAStrokeRectBatch>();
 
     // we can't batch across vm changes
@@ -550,7 +497,7 @@
         return false;
     }
 
-    batch->appendAndUpdateBounds(color, devOutside, devOutsideAssist, devInside, degenerate);
+    batch->appendAndUpdateBounds(color, devOutside, devOutsideAssist, devInside);
     return true;
 }
 
@@ -564,7 +511,6 @@
 
 DRAW_BATCH_TEST_DEFINE(AAStrokeRectBatch) {
     bool miterStroke = random->nextBool();
-    bool degenerate = random->nextBool();
 
     // Create mock stroke rect
     SkRect outside = GrTest::TestRect(random);
@@ -578,7 +524,7 @@
     GrColor color = GrRandomColor(random);
 
     return GrAAStrokeRectBatch::Create(color, GrTest::TestMatrix(random), outside, outsideAssist,
-                                       inside, degenerate, miterStroke);
+                                       inside, miterStroke);
 }
 
 #endif
diff --git a/src/gpu/batches/GrAAStrokeRectBatch.h b/src/gpu/batches/GrAAStrokeRectBatch.h
index 242597b..1af4f15 100644
--- a/src/gpu/batches/GrAAStrokeRectBatch.h
+++ b/src/gpu/batches/GrAAStrokeRectBatch.h
@@ -23,8 +23,7 @@
                     const SkRect& devOutside,
                     const SkRect& devOutsideAssist,
                     const SkRect& devInside,
-                    bool miterStroke,
-                    bool degenerate);
+                    bool miterStroke);
 
 bool Append(GrBatch*,
             GrColor color,
@@ -32,8 +31,7 @@
             const SkRect& devOutside,
             const SkRect& devOutsideAssist,
             const SkRect& devInside,
-            bool miterStroke,
-            bool degenerate);
+            bool miterStroke);
 
 };
 
diff --git a/src/gpu/batches/GrRectBatchFactory.cpp b/src/gpu/batches/GrRectBatchFactory.cpp
index f34a8c0..eed18ad 100644
--- a/src/gpu/batches/GrRectBatchFactory.cpp
+++ b/src/gpu/batches/GrRectBatchFactory.cpp
@@ -33,6 +33,13 @@
     const SkScalar rx = SkScalarMul(dx, SK_ScalarHalf);
     const SkScalar ry = SkScalarMul(dy, SK_ScalarHalf);
 
+    SkScalar spare;
+    {
+        SkScalar w = devRect.width() - dx;
+        SkScalar h = devRect.height() - dy;
+        spare = SkTMin(w, h);
+    }
+
     SkRect devOutside(devRect);
     devOutside.outset(rx, ry);
 
@@ -44,25 +51,13 @@
         miterStroke = false;
     }
 
+    if (spare <= 0 && miterStroke) {
+        return CreateAAFill(color, viewMatrix, devOutside, devOutside);
+    }
+
     SkRect devInside(devRect);
     devInside.inset(rx, ry);
 
-    // If we have a degenerate stroking rect(ie the stroke is larger than inner rect) then we
-    // make a degenerate inside rect to avoid double hitting.  We will also jam all of the points
-    // together when we render these rects.
-    SkScalar spare;
-    {
-        SkScalar w = devRect.width() - dx;
-        SkScalar h = devRect.height() - dy;
-        spare = SkTMin(w, h);
-    }
-
-    bool degenerate = spare <= 0;
-    if (degenerate) {
-        devInside.fLeft = devInside.fRight = devRect.centerX();
-        devInside.fTop = devInside.fBottom = devRect.centerY();
-    }
-
     SkRect devOutsideAssist(devRect);
 
     // For bevel-stroke, use 2 SkRect instances(devOutside and devOutsideAssist)
@@ -74,7 +69,7 @@
     }
 
     return GrAAStrokeRectBatch::Create(color, viewMatrix, devOutside, devOutsideAssist, devInside,
-                                       miterStroke, degenerate);
+                                       miterStroke);
 }
 
 GrDrawBatch* CreateAAFillNestedRects(GrColor color,
@@ -87,8 +82,11 @@
     viewMatrix.mapRect(&devOutside, rects[0]);
     viewMatrix.mapRect(&devInside, rects[1]);
 
-    return GrAAStrokeRectBatch::Create(color, viewMatrix, devOutside, devOutside, devInside, true,
-                                       devInside.isEmpty());
+    if (devInside.isEmpty()) {
+        return CreateAAFill(color, viewMatrix, devOutside, devOutside);
+    }
+
+    return GrAAStrokeRectBatch::Create(color, viewMatrix, devOutside, devOutside, devInside, true);
 }
 
 };