Update gpu caps for valid sample counts.

Instead of query and maxSampleCount and using that to cap, we now have
each config store its supported values and when requested returns either
the next highest or equal supported value, or if non the max config supported.

Bug: skia:
Change-Id: I8802d44c13b3b1703ee54a7e69b82102d4b8dc2d
Reviewed-on: https://skia-review.googlesource.com/24302
Commit-Queue: Greg Daniel <egdaniel@google.com>
Reviewed-by: Brian Salomon <bsalomon@google.com>
diff --git a/bench/nanobench.cpp b/bench/nanobench.cpp
index 8cbaa23..7148bc2 100644
--- a/bench/nanobench.cpp
+++ b/bench/nanobench.cpp
@@ -61,6 +61,7 @@
     #include "GrCaps.h"
     #include "GrContextFactory.h"
     #include "gl/GrGLUtil.h"
+    #include "SkGr.h"
     using sk_gpu_test::GrContextFactory;
     using sk_gpu_test::TestContext;
     std::unique_ptr<GrContextFactory> gGrFactory;
@@ -416,12 +417,16 @@
         const auto ctxType = gpuConfig->getContextType();
         const auto ctxOverrides = gpuConfig->getContextOverrides();
         const auto sampleCount = gpuConfig->getSamples();
+        const auto colorType = gpuConfig->getColorType();
+        auto colorSpace = gpuConfig->getColorSpace();
 
         if (const GrContext* ctx = gGrFactory->get(ctxType, ctxOverrides)) {
-            const auto maxSampleCount = ctx->caps()->maxSampleCount();
-            if (sampleCount > ctx->caps()->maxSampleCount()) {
-                SkDebugf("Configuration sample count %d exceeds maximum %d.\n",
-                    sampleCount, maxSampleCount);
+            GrPixelConfig grPixConfig = SkImageInfo2GrPixelConfig(colorType, colorSpace,
+                                                                  *ctx->caps());
+            int supportedSampleCount = ctx->caps()->getSampleCount(sampleCount, grPixConfig);
+            if (sampleCount != supportedSampleCount) {
+                SkDebugf("Configuration sample count %d is not a supported sample count.\n",
+                    sampleCount);
                 return;
             }
         } else {
@@ -432,9 +437,9 @@
         Config target = {
             gpuConfig->getTag(),
             Benchmark::kGPU_Backend,
-            gpuConfig->getColorType(),
+            colorType,
             kPremul_SkAlphaType,
-            sk_ref_sp(gpuConfig->getColorSpace()),
+            sk_ref_sp(colorSpace),
             sampleCount,
             ctxType,
             ctxOverrides,