Add API for GrContext to recommend rendertarget sample count

Add GrContext::getRecommendedSampleCount method that can be
used to determine which GPU backend and what exact sample count
is recommendeded for a particular render target at particular
dpi.

Make this initially recommend 4xMSAA for contexts which have
NVPR enabled if dpi is 250 or more, 16 if dpi is less than 250
and no MSAA for others.

BUG=chromium:347962
R=bsalomon@google.com

Author: kkinnunen@nvidia.com

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

git-svn-id: http://skia.googlecode.com/svn/trunk@13717 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/include/gpu/GrContext.h b/include/gpu/GrContext.h
index ad3789b..1834586 100644
--- a/include/gpu/GrContext.h
+++ b/include/gpu/GrContext.h
@@ -306,6 +306,19 @@
      */
     int getMaxSampleCount() const;
 
+    /**
+     * Returns the recommended sample count for a render target when using this
+     * context.
+     *
+     * @param  config the configuration of the render target.
+     * @param  dpi the display density in dots per inch.
+     *
+     * @return sample count that should be perform well and have good enough
+     *         rendering quality for the display. Alternatively returns 0 if
+     *         MSAA is not supported or recommended to be used by default.
+     */
+    int getRecommendedSampleCount(GrPixelConfig config, SkScalar dpi) const;
+
     ///////////////////////////////////////////////////////////////////////////
     // Backend Surfaces
 
diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp
index bb0f4fa..c7e3433 100644
--- a/src/gpu/GrContext.cpp
+++ b/src/gpu/GrContext.cpp
@@ -1703,6 +1703,23 @@
     return fGpu->caps()->isConfigRenderable(config, withMSAA);
 }
 
+int GrContext::getRecommendedSampleCount(GrPixelConfig config,
+                                         SkScalar dpi) const {
+    if (!this->isConfigRenderable(config, true)) {
+        return 0;
+    }
+    int chosenSampleCount = 0;
+    if (fGpu->caps()->pathRenderingSupport()) {
+        if (dpi >= 250.0f) {
+            chosenSampleCount = 4;
+        } else {
+            chosenSampleCount = 16;
+        }
+    }
+    return chosenSampleCount <= fGpu->caps()->maxSampleCount() ?
+        chosenSampleCount : 0;
+}
+
 void GrContext::setupDrawBuffer() {
     SkASSERT(NULL == fDrawBuffer);
     SkASSERT(NULL == fDrawBufferVBAllocPool);