Fix for nested rect drawing bug

https://codereview.chromium.org/22824016/



git-svn-id: http://skia.googlecode.com/svn/trunk/src@10804 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/gpu/GrContext.cpp b/gpu/GrContext.cpp
index b35b356..4bd8098 100644
--- a/gpu/GrContext.cpp
+++ b/gpu/GrContext.cpp
@@ -1011,8 +1011,6 @@
     }
 }
 
-namespace {
-
 // Can 'path' be drawn as a pair of filled nested rectangles?
 static bool is_nested_rects(GrDrawTarget* target,
                             const SkPath& path,
@@ -1047,15 +1045,26 @@
         return false;
     }
 
-    if (SkPath::kWinding_FillType == path.getFillType()) {
+    if (SkPath::kWinding_FillType == path.getFillType() && dirs[0] == dirs[1]) {
         // The two rects need to be wound opposite to each other
-        return dirs[0] != dirs[1];
-    } else {
-        return true;
+        return false;
     }
-}
 
-};
+    // Right now, nested rects where the margin is not the same width
+    // all around do not render correctly
+    const SkScalar* outer = rects[0].asScalars();
+    const SkScalar* inner = rects[1].asScalars();
+
+    SkScalar margin = SkScalarAbs(outer[0] - inner[0]);
+    for (int i = 1; i < 4; ++i) {
+        SkScalar temp = SkScalarAbs(outer[i] - inner[i]);
+        if (!SkScalarNearlyEqual(margin, temp)) {
+            return false;
+        }
+    }
+
+    return true;
+}
 
 void GrContext::drawPath(const GrPaint& paint, const SkPath& path, const SkStrokeRec& stroke) {