Apply hairline optimization only if the path renderer wants it

Make the decision to convert thin, non-hairline paths to hairline
paths at the renderer level.

The current nv_path_rendering implementation does not render
hairlines. Rendering the hairlines with normal renderers cause
unneccessary gl program changes, which is quite slow.

Changes the behavior of non-nv_path_rendering paths to always perform
the optimization if the shape ends up being painted by a renderer that
wants the optimization. Previously the optimization was applied only
when callgraph started with SkCanvas::drawPath.

Applies the optimization for GrAAHairLineRenderer and
GrDefaultPathRenderer.

This changes gm results for dashing3_{msaa4,gpu} and drawlooper_msaa4.

R=bsalomon@google.com, jvanverth@google.com, rmistry@google.com

Author: kkinnunen@nvidia.com

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

git-svn-id: http://skia.googlecode.com/svn/trunk@12357 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/src/gpu/GrAAHairLinePathRenderer.cpp b/src/gpu/GrAAHairLinePathRenderer.cpp
index 02c4419..3956310 100644
--- a/src/gpu/GrAAHairLinePathRenderer.cpp
+++ b/src/gpu/GrAAHairLinePathRenderer.cpp
@@ -759,7 +759,7 @@
     }
     devBounds->set(lines.begin(), lines.count());
     for (int i = 0; i < lineCnt; ++i) {
-        add_line(&lines[2*i], toSrc, drawState->getCoverage(), &verts);
+        add_line(&lines[2*i], toSrc, drawState->getCoverageColor(), &verts);
     }
     // All the verts computed by add_line are within sqrt(1^2 + 0.5^2) of the end points.
     static const SkScalar kSqrtOfOneAndAQuarter = SkFloatToScalar(1.118f);
@@ -839,7 +839,13 @@
                                            const SkStrokeRec& stroke,
                                            const GrDrawTarget* target,
                                            bool antiAlias) const {
-    if (!stroke.isHairlineStyle() || !antiAlias) {
+    if (!antiAlias) {
+        return false;
+    }
+
+    if (!IsStrokeHairlineOrEquivalent(stroke,
+                                      target->getDrawState().getViewMatrix(),
+                                      NULL)) {
         return false;
     }
 
@@ -888,12 +894,20 @@
 }
 
 bool GrAAHairLinePathRenderer::onDrawPath(const SkPath& path,
-                                          const SkStrokeRec&,
+                                          const SkStrokeRec& stroke,
                                           GrDrawTarget* target,
                                           bool antiAlias) {
-
     GrDrawState* drawState = target->drawState();
 
+    SkScalar hairlineCoverage;
+    if (IsStrokeHairlineOrEquivalent(stroke,
+                                     target->getDrawState().getViewMatrix(),
+                                     &hairlineCoverage)) {
+        uint8_t newCoverage = SkScalarRoundToInt(hairlineCoverage *
+                                                 target->getDrawState().getCoverage());
+        target->drawState()->setCoverage(newCoverage);
+    }
+
     SkIRect devClipBounds;
     target->getClip()->getConservativeBounds(drawState->getRenderTarget(), &devClipBounds);