Handle rrects with one circular corner and three square corners in GrRRectEffect.

BUG=skia:2181
R=jvanverth@google.com

Author: bsalomon@google.com

Review URL: https://codereview.chromium.org/193263002

git-svn-id: http://skia.googlecode.com/svn/trunk@13739 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/expectations/gm/ignored-tests.txt b/expectations/gm/ignored-tests.txt
index 5fd6023..250dc61 100644
--- a/expectations/gm/ignored-tests.txt
+++ b/expectations/gm/ignored-tests.txt
@@ -37,9 +37,13 @@
 # http://skbug.com/2222 : Inverse filled paths get inverse stroked
 inverse_paths
 
-# bsalomon: The rrects that can be drawn by effects are now tightly packed in the GM image.
-# https://codereview.chromium.org/190953008
+# bsalomon: Additional test cases were added to these GMs
+# https://codereview.chromium.org/193263002/
 rrect_effect
+rrect_draw_bw
+rrect_draw_aa
+rrect_clip_bw
+rrect_clip_aa
 
 # reed: https://codereview.chromium.org/190723004/
 # This change removes an API that this GM was testing. If/when it lands and sticks,
diff --git a/gm/rrects.cpp b/gm/rrects.cpp
index cc76718..a79ff54 100644
--- a/gm/rrects.cpp
+++ b/gm/rrects.cpp
@@ -189,7 +189,7 @@
     static const int kTileY = 40;
 
     static const int kNumSimpleCases = 7;
-    static const int kNumComplexCases = 23;
+    static const int kNumComplexCases = 27;
     static const SkVector gRadii[kNumComplexCases][4];
 
     static const int kNumRRects = kNumSimpleCases + kNumComplexCases;
@@ -238,6 +238,12 @@
     { { 20, 20 }, { 20, 20 }, { 0, 0 }, { 0, 0 } },
     { { 0, 0 }, { 0, 0 }, { 20, 20 }, { 20, 20 } },
     { { 20, 20 }, { 0, 0 }, { 0, 0 }, { 20, 20 } },
+
+    // single circular corner cases
+    { { 0, 0 }, { 0, 0 }, { 0, 0 }, { 15, 15 } },
+    { { 0, 0 }, { 0, 0 }, { 15, 15 }, { 0, 0 } },
+    { { 0, 0 }, { 15, 15 }, { 0, 0 }, { 0, 0 } },
+    { { 15, 15 }, { 0, 0 }, { 0, 0 }, { 0, 0 } },
 };
 
 ///////////////////////////////////////////////////////////////////////////////
diff --git a/src/gpu/effects/GrRRectEffect.cpp b/src/gpu/effects/GrRRectEffect.cpp
index 868d18c..619cd99 100644
--- a/src/gpu/effects/GrRRectEffect.cpp
+++ b/src/gpu/effects/GrRRectEffect.cpp
@@ -165,10 +165,10 @@
     const RRectEffect& rre = drawEffect.castEffect<RRectEffect>();
     const char *rectName;
     const char *radiusPlusHalfName;
-    // The inner rect is the rrect bounds inset by the radius. Its top, left, right, and bottom
-    // edges correspond to components x, y, z, and w, respectively. When one side of the rrect has
-    // rectangular corners, that side's value corresponds to the rect edge's value outset by half a
-    // pixel.
+    // The inner rect is the rrect bounds inset by the radius. Its left, top, right, and bottom
+    // edges correspond to components x, y, z, and w, respectively. When a side of the rrect has
+    // only rectangular corners, that side's value corresponds to the rect edge's value outset by
+    // half a pixel.
     fInnerRectUniform = builder->addUniform(GrGLShaderBuilder::kFragment_Visibility,
                                             kVec4f_GrSLType,
                                             "innerRect",
@@ -201,6 +201,45 @@
             builder->fsCodeAppendf("\t\tfloat alpha = clamp(%s - length(dxy), 0.0, 1.0);\n",
                                    radiusPlusHalfName);
             break;
+        case RRectEffect::kTopLeft_CornerFlag:
+            builder->fsCodeAppendf("\t\tvec2 dxy = max(%s.xy - %s.xy, 0.0);\n", rectName, fragmentPos);
+            builder->fsCodeAppendf("\t\tfloat rightAlpha = clamp(%s.z - %s.x, 0.0, 1.0);\n",
+                                    rectName, fragmentPos);
+            builder->fsCodeAppendf("\t\tfloat bottomAlpha = clamp(%s.w - %s.y, 0.0, 1.0);\n",
+                                    rectName, fragmentPos);
+            builder->fsCodeAppendf("\t\tfloat alpha = bottomAlpha * rightAlpha * clamp(%s - length(dxy), 0.0, 1.0);\n",
+                                   radiusPlusHalfName);
+            break;
+        case RRectEffect::kTopRight_CornerFlag:
+            builder->fsCodeAppendf("\t\tvec2 dxy = max(vec2(%s.x - %s.z, %s.y - %s.y), 0.0);\n",
+                                   fragmentPos, rectName, rectName, fragmentPos);
+            builder->fsCodeAppendf("\t\tfloat leftAlpha = clamp(%s.x - %s.x, 0.0, 1.0);\n",
+                                   fragmentPos, rectName);
+            builder->fsCodeAppendf("\t\tfloat bottomAlpha = clamp(%s.w - %s.y, 0.0, 1.0);\n",
+                                    rectName, fragmentPos);
+            builder->fsCodeAppendf("\t\tfloat alpha = bottomAlpha * leftAlpha * clamp(%s - length(dxy), 0.0, 1.0);\n",
+                                   radiusPlusHalfName);
+            break;
+        case RRectEffect::kBottomRight_CornerFlag:
+            builder->fsCodeAppendf("\t\tvec2 dxy = max(%s.xy - %s.zw, 0.0);\n",
+                                   fragmentPos, rectName);
+            builder->fsCodeAppendf("\t\tfloat leftAlpha = clamp(%s.x - %s.x, 0.0, 1.0);\n",
+                                   fragmentPos, rectName);
+            builder->fsCodeAppendf("\t\tfloat topAlpha = clamp(%s.y - %s.y, 0.0, 1.0);\n",
+                                   fragmentPos, rectName);
+            builder->fsCodeAppendf("\t\tfloat alpha = topAlpha * leftAlpha * clamp(%s - length(dxy), 0.0, 1.0);\n",
+                                   radiusPlusHalfName);
+            break;
+        case RRectEffect::kBottomLeft_CornerFlag:
+            builder->fsCodeAppendf("\t\tvec2 dxy = max(vec2(%s.x - %s.x, %s.y - %s.w), 0.0);\n",
+                                   rectName, fragmentPos, fragmentPos, rectName);
+            builder->fsCodeAppendf("\t\tfloat rightAlpha = clamp(%s.z - %s.x, 0.0, 1.0);\n",
+                                    rectName, fragmentPos);
+            builder->fsCodeAppendf("\t\tfloat topAlpha = clamp(%s.y - %s.y, 0.0, 1.0);\n",
+                                   fragmentPos, rectName);
+            builder->fsCodeAppendf("\t\tfloat alpha = topAlpha * rightAlpha * clamp(%s - length(dxy), 0.0, 1.0);\n",
+                                   radiusPlusHalfName);
+            break;
         case RRectEffect::kLeft_CornerFlags:
             builder->fsCodeAppendf("\t\tvec2 dxy0 = %s.xy - %s.xy;\n", rectName, fragmentPos);
             builder->fsCodeAppendf("\t\tfloat dy1 = %s.y - %s.w;\n", fragmentPos, rectName);
@@ -266,6 +305,34 @@
                 SkASSERT(radius >= RRectEffect::kRadiusMin);
                 rect.inset(radius, radius);
                 break;
+            case RRectEffect::kTopLeft_CornerFlag:
+                radius = rrect.radii(SkRRect::kUpperLeft_Corner).fX;
+                rect.fLeft += radius;
+                rect.fTop += radius;
+                rect.fRight += 0.5f;
+                rect.fBottom += 0.5f;
+                break;
+            case RRectEffect::kTopRight_CornerFlag:
+                radius = rrect.radii(SkRRect::kUpperRight_Corner).fX;
+                rect.fLeft -= 0.5;
+                rect.fTop += radius;
+                rect.fRight -= radius;
+                rect.fBottom += 0.5f;
+                break;
+            case RRectEffect::kBottomRight_CornerFlag:
+                radius = rrect.radii(SkRRect::kLowerRight_Corner).fX;
+                rect.fLeft -= 0.5;
+                rect.fTop -= 0.5;
+                rect.fRight -= radius;
+                rect.fBottom -= radius;
+                break;
+            case RRectEffect::kBottomLeft_CornerFlag:
+                radius = rrect.radii(SkRRect::kLowerLeft_Corner).fX;
+                rect.fLeft += radius;
+                rect.fTop -= 0.5;
+                rect.fRight += 0.5;
+                rect.fBottom -= radius;
+                break;
             case RRectEffect::kLeft_CornerFlags:
                 radius = rrect.radii(SkRRect::kUpperLeft_Corner).fX;
                 rect.fLeft += radius;
@@ -343,6 +410,10 @@
         }
 
         switch (cornerFlags) {
+            case RRectEffect::kTopLeft_CornerFlag:
+            case RRectEffect::kTopRight_CornerFlag:
+            case RRectEffect::kBottomRight_CornerFlag:
+            case RRectEffect::kBottomLeft_CornerFlag:
             case RRectEffect::kLeft_CornerFlags:
             case RRectEffect::kTop_CornerFlags:
             case RRectEffect::kRight_CornerFlags: