Revert "Revert "Revert "Revert "Revert "Redefine the meaning of sample counts in GPU backend."""""

This reverts commit 5bb82cbecd740d21b92e8d2944280ab6eb6af7a6.

Reason for revert: <INSERT REASONING HERE>

Original change's description:
> Revert "Revert "Revert "Revert "Redefine the meaning of sample counts in GPU backend.""""
> 
> This reverts commit 18c52a7b52211de5d0dcd86dc048adef758c6c75.
> 
> Also relands "More sample count cleanup:" and "Add new GrContext queries for imagability, surfacability, and max sample count of color types"
> 
> 
> Bug: skia:
> Change-Id: I4028105a3a1f16ce3944e134619eb6245af6b947
> Reviewed-on: https://skia-review.googlesource.com/102940
> Reviewed-by: Brian Salomon <bsalomon@google.com>
> Commit-Queue: Brian Salomon <bsalomon@google.com>

TBR=egdaniel@google.com,bsalomon@google.com

Change-Id: Idee23be2f1719f0bdc9305043e95a2d589bee8d1
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: skia:
Reviewed-on: https://skia-review.googlesource.com/103220
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Brian Salomon <bsalomon@google.com>
diff --git a/tools/fiddle/fiddle_main.cpp b/tools/fiddle/fiddle_main.cpp
index 684bc2a..4ba84f3 100644
--- a/tools/fiddle/fiddle_main.cpp
+++ b/tools/fiddle/fiddle_main.cpp
@@ -133,7 +133,7 @@
     backingDesc.fHeight = bm.height();
     // This config must match the SkColorType used in draw.cpp in the SkImage and Surface factories
     backingDesc.fConfig = kRGBA_8888_GrPixelConfig;
-    backingDesc.fSampleCnt = 1;
+    backingDesc.fSampleCnt = 0;
 
     if (!bm.empty()) {
         SkPixmap originalPixmap;
diff --git a/tools/flags/SkCommonFlagsConfig.cpp b/tools/flags/SkCommonFlagsConfig.cpp
index 9d1c2dd..d38d70a 100644
--- a/tools/flags/SkCommonFlagsConfig.cpp
+++ b/tools/flags/SkCommonFlagsConfig.cpp
@@ -391,7 +391,7 @@
     bool seenUseDIText =false;
     bool useDIText = false;
     bool seenSamples = false;
-    int samples = 1;
+    int samples = 0;
     bool seenColor = false;
     SkColorType colorType = kRGBA_8888_SkColorType;
     SkAlphaType alphaType = kPremul_SkAlphaType;
diff --git a/tools/gpu/GrTest.cpp b/tools/gpu/GrTest.cpp
index 06d9b83..829ddcb 100644
--- a/tools/gpu/GrTest.cpp
+++ b/tools/gpu/GrTest.cpp
@@ -182,13 +182,6 @@
 
 #endif
 
-GrBackendTexture GrGpu::createTestingOnlyBackendTexture(void* pixels, int w, int h,
-                                                        SkColorType colorType, bool isRenderTarget,
-                                                        GrMipMapped mipMapped) {
-    GrPixelConfig config = SkImageInfo2GrPixelConfig(colorType, nullptr, *this->caps());
-    return this->createTestingOnlyBackendTexture(pixels, w, h, config, isRenderTarget, mipMapped);
-}
-
 #if GR_CACHE_STATS
 void GrResourceCache::getStats(Stats* stats) const {
     stats->reset();
diff --git a/tools/sk_app/DisplayParams.h b/tools/sk_app/DisplayParams.h
index 203e8bd..959735e 100644
--- a/tools/sk_app/DisplayParams.h
+++ b/tools/sk_app/DisplayParams.h
@@ -13,7 +13,10 @@
 namespace sk_app {
 
 struct DisplayParams {
-    DisplayParams() : fColorType(kN32_SkColorType), fColorSpace(nullptr), fMSAASampleCount(1) {}
+    DisplayParams()
+        : fColorType(kN32_SkColorType)
+        , fColorSpace(nullptr)
+        , fMSAASampleCount(0) {}
 
     SkColorType         fColorType;
     sk_sp<SkColorSpace> fColorSpace;
diff --git a/tools/sk_app/GLWindowContext.cpp b/tools/sk_app/GLWindowContext.cpp
index 9d042cf..9ef5141 100644
--- a/tools/sk_app/GLWindowContext.cpp
+++ b/tools/sk_app/GLWindowContext.cpp
@@ -24,7 +24,9 @@
     : WindowContext(params)
     , fBackendContext(nullptr)
     , fSurface(nullptr) {
-    fDisplayParams.fMSAASampleCount = GrNextPow2(fDisplayParams.fMSAASampleCount);
+    fDisplayParams.fMSAASampleCount = fDisplayParams.fMSAASampleCount ?
+                                      GrNextPow2(fDisplayParams.fMSAASampleCount) :
+                                      0;
 }
 
 void GLWindowContext::initializeContext() {
@@ -32,7 +34,7 @@
 
     fBackendContext = this->onInitializeContext();
     fContext = GrContext::MakeGL(fBackendContext, fDisplayParams.fGrContextOptions);
-    if (!fContext && fDisplayParams.fMSAASampleCount > 1) {
+    if (!fContext && fDisplayParams.fMSAASampleCount) {
         fDisplayParams.fMSAASampleCount /= 2;
         this->initializeContext();
         return;
diff --git a/tools/sk_app/Window.cpp b/tools/sk_app/Window.cpp
index 1694bea..29e4864 100644
--- a/tools/sk_app/Window.cpp
+++ b/tools/sk_app/Window.cpp
@@ -117,7 +117,7 @@
 
 int Window::sampleCount() const {
     if (!fWindowContext) {
-        return 0;
+        return -1;
     }
     return fWindowContext->sampleCount();
 }
diff --git a/tools/sk_app/WindowContext.h b/tools/sk_app/WindowContext.h
index 71c21ac..5e7d76d 100644
--- a/tools/sk_app/WindowContext.h
+++ b/tools/sk_app/WindowContext.h
@@ -21,11 +21,11 @@
 class WindowContext {
 public:
     WindowContext(const DisplayParams& params)
-            : fContext(nullptr)
-            , fDisplayParams(params)
-            , fSurfaceProps(SkSurfaceProps::kLegacyFontHost_InitType)
-            , fSampleCount(1)
-            , fStencilBits(0) {}
+        : fContext(nullptr)
+        , fDisplayParams(params)
+        , fSurfaceProps(SkSurfaceProps::kLegacyFontHost_InitType)
+        , fSampleCount(0)
+        , fStencilBits(0) {}
 
     virtual ~WindowContext() {}
 
diff --git a/tools/sk_app/android/GLWindowContext_android.cpp b/tools/sk_app/android/GLWindowContext_android.cpp
index 5111114..acdb587 100644
--- a/tools/sk_app/android/GLWindowContext_android.cpp
+++ b/tools/sk_app/android/GLWindowContext_android.cpp
@@ -70,8 +70,6 @@
     SkAssertResult(eglBindAPI(EGL_OPENGL_ES_API));
 
     EGLint numConfigs = 0;
-    EGLint eglSampleCnt = fDisplayParams.fMSAASampleCount > 1 ? fDisplayParams.fMSAASampleCount > 1
-                                                              : 0;
     const EGLint configAttribs[] = {
         EGL_SURFACE_TYPE, EGL_PBUFFER_BIT,
         EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
@@ -80,8 +78,8 @@
         EGL_BLUE_SIZE, 8,
         EGL_ALPHA_SIZE, 8,
         EGL_STENCIL_SIZE, 8,
-        EGL_SAMPLE_BUFFERS, eglSampleCnt ? 1 : 0,
-        EGL_SAMPLES, eglSampleCnt,
+        EGL_SAMPLE_BUFFERS, fDisplayParams.fMSAASampleCount ? 1 : 0,
+        EGL_SAMPLES, fDisplayParams.fMSAASampleCount,
         EGL_NONE
     };
 
@@ -133,7 +131,6 @@
 
     eglGetConfigAttrib(fDisplay, surfaceConfig, EGL_STENCIL_SIZE, &fStencilBits);
     eglGetConfigAttrib(fDisplay, surfaceConfig, EGL_SAMPLES, &fSampleCount);
-    fSampleCount = SkTMax(fSampleCount, 1);
 
     return GrGLMakeNativeInterface();
 }
diff --git a/tools/sk_app/ios/GLWindowContext_ios.cpp b/tools/sk_app/ios/GLWindowContext_ios.cpp
index 2a57b33..f4c0d6b 100644
--- a/tools/sk_app/ios/GLWindowContext_ios.cpp
+++ b/tools/sk_app/ios/GLWindowContext_ios.cpp
@@ -67,7 +67,6 @@
 
         SDL_GL_GetAttribute(SDL_GL_STENCIL_SIZE, &fStencilBits);
         SDL_GL_GetAttribute(SDL_GL_MULTISAMPLESAMPLES, &fSampleCount);
-        fSampleCount = SkTMax(fSampleCount, 1);
 
         SDL_GL_GetDrawableSize(fWindow, &fWidth, &fHeight);
         glViewport(0, 0, fWidth, fHeight);
diff --git a/tools/sk_app/ios/RasterWindowContext_ios.cpp b/tools/sk_app/ios/RasterWindowContext_ios.cpp
index 53d7c1a..cae5774 100644
--- a/tools/sk_app/ios/RasterWindowContext_ios.cpp
+++ b/tools/sk_app/ios/RasterWindowContext_ios.cpp
@@ -79,7 +79,6 @@
 
         SDL_GL_GetAttribute(SDL_GL_STENCIL_SIZE, &fStencilBits);
         SDL_GL_GetAttribute(SDL_GL_MULTISAMPLESAMPLES, &fSampleCount);
-        fSampleCount = SkTMax(fSampleCount, 1);
 
         SDL_GL_GetDrawableSize(fWindow, &fWidth, &fHeight);
         glViewport(0, 0, fWidth, fHeight);
diff --git a/tools/sk_app/ios/Window_ios.cpp b/tools/sk_app/ios/Window_ios.cpp
index ac0ad0c..c1bdeae 100644
--- a/tools/sk_app/ios/Window_ios.cpp
+++ b/tools/sk_app/ios/Window_ios.cpp
@@ -49,7 +49,7 @@
 
     SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL, 1);
 
-    if (fRequestedDisplayParams.fMSAASampleCount > 1) {
+    if (fRequestedDisplayParams.fMSAASampleCount > 0) {
         SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1);
         SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, fRequestedDisplayParams.fMSAASampleCount);
     } else {
diff --git a/tools/sk_app/ios/Window_ios.h b/tools/sk_app/ios/Window_ios.h
index a0fed90..667fa74 100644
--- a/tools/sk_app/ios/Window_ios.h
+++ b/tools/sk_app/ios/Window_ios.h
@@ -18,7 +18,11 @@
 
 class Window_ios : public Window {
 public:
-    Window_ios() : INHERITED(), fWindow(nullptr), fWindowID(0), fMSAASampleCount(1) {}
+    Window_ios()
+        : INHERITED()
+        , fWindow(nullptr)
+        , fWindowID(0)
+        , fMSAASampleCount(0) {}
     ~Window_ios() override { this->closeWindow(); }
 
     bool initWindow();
diff --git a/tools/sk_app/mac/GLWindowContext_mac.cpp b/tools/sk_app/mac/GLWindowContext_mac.cpp
index 67fb853..005fc07 100644
--- a/tools/sk_app/mac/GLWindowContext_mac.cpp
+++ b/tools/sk_app/mac/GLWindowContext_mac.cpp
@@ -67,7 +67,6 @@
 
         SDL_GL_GetAttribute(SDL_GL_STENCIL_SIZE, &fStencilBits);
         SDL_GL_GetAttribute(SDL_GL_MULTISAMPLESAMPLES, &fSampleCount);
-        fSampleCount = SkTMax(fSampleCount, 1);
 
         SDL_GetWindowSize(fWindow, &fWidth, &fHeight);
         glViewport(0, 0, fWidth, fHeight);
diff --git a/tools/sk_app/mac/RasterWindowContext_mac.cpp b/tools/sk_app/mac/RasterWindowContext_mac.cpp
index fbe9837..67022af 100644
--- a/tools/sk_app/mac/RasterWindowContext_mac.cpp
+++ b/tools/sk_app/mac/RasterWindowContext_mac.cpp
@@ -79,7 +79,6 @@
 
         SDL_GL_GetAttribute(SDL_GL_STENCIL_SIZE, &fStencilBits);
         SDL_GL_GetAttribute(SDL_GL_MULTISAMPLESAMPLES, &fSampleCount);
-        fSampleCount = SkTMax(fSampleCount, 1);
 
         SDL_GetWindowSize(fWindow, &fWidth, &fHeight);
         glViewport(0, 0, fWidth, fHeight);
diff --git a/tools/sk_app/mac/Window_mac.cpp b/tools/sk_app/mac/Window_mac.cpp
index f262051..8de5b10 100644
--- a/tools/sk_app/mac/Window_mac.cpp
+++ b/tools/sk_app/mac/Window_mac.cpp
@@ -49,7 +49,7 @@
 
     SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL, 1);
 
-    if (fRequestedDisplayParams.fMSAASampleCount > 1) {
+    if (fRequestedDisplayParams.fMSAASampleCount > 0) {
         SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1);
         SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, fRequestedDisplayParams.fMSAASampleCount);
     } else {
diff --git a/tools/sk_app/mac/Window_mac.h b/tools/sk_app/mac/Window_mac.h
index 35cba09..aa5c8df 100644
--- a/tools/sk_app/mac/Window_mac.h
+++ b/tools/sk_app/mac/Window_mac.h
@@ -18,7 +18,11 @@
 
 class Window_mac : public Window {
 public:
-    Window_mac() : INHERITED(), fWindow(nullptr), fWindowID(0), fMSAASampleCount(1) {}
+    Window_mac()
+        : INHERITED()
+        , fWindow(nullptr)
+        , fWindowID(0)
+        , fMSAASampleCount(0) {}
     ~Window_mac() override { this->closeWindow(); }
 
     bool initWindow();
diff --git a/tools/sk_app/unix/GLWindowContext_unix.cpp b/tools/sk_app/unix/GLWindowContext_unix.cpp
index 3a3a4b1..25ec95c 100644
--- a/tools/sk_app/unix/GLWindowContext_unix.cpp
+++ b/tools/sk_app/unix/GLWindowContext_unix.cpp
@@ -99,7 +99,6 @@
 
     glXGetConfig(fDisplay, fVisualInfo, GLX_STENCIL_SIZE, &fStencilBits);
     glXGetConfig(fDisplay, fVisualInfo, GLX_SAMPLES_ARB, &fSampleCount);
-    fSampleCount = SkTMax(fSampleCount, 1);
 
     XWindow root;
     int x, y;
diff --git a/tools/sk_app/unix/Window_unix.cpp b/tools/sk_app/unix/Window_unix.cpp
index 745b4dd..f5ca5ee 100644
--- a/tools/sk_app/unix/Window_unix.cpp
+++ b/tools/sk_app/unix/Window_unix.cpp
@@ -72,7 +72,7 @@
         None
     };
     SkASSERT(nullptr == fVisualInfo);
-    if (fRequestedDisplayParams.fMSAASampleCount > 1) {
+    if (fRequestedDisplayParams.fMSAASampleCount > 0) {
         static const GLint kChooseFBConifgAttCnt = SK_ARRAY_COUNT(kChooseFBConfigAtt);
         GLint msaaChooseFBConfigAtt[kChooseFBConifgAttCnt + 4];
         memcpy(msaaChooseFBConfigAtt, kChooseFBConfigAtt, sizeof(kChooseFBConfigAtt));
diff --git a/tools/sk_app/unix/Window_unix.h b/tools/sk_app/unix/Window_unix.h
index 62a2795..b59f502 100644
--- a/tools/sk_app/unix/Window_unix.h
+++ b/tools/sk_app/unix/Window_unix.h
@@ -20,14 +20,13 @@
 
 class Window_unix : public Window {
 public:
-    Window_unix()
-            : Window()
-            , fDisplay(nullptr)
-            , fWindow(0)
-            , fGC(nullptr)
-            , fFBConfig(nullptr)
-            , fVisualInfo(nullptr)
-            , fMSAASampleCount(1) {}
+    Window_unix() : Window()
+                  , fDisplay(nullptr)
+                  , fWindow(0)
+                  , fGC(nullptr)
+                  , fFBConfig(nullptr)
+                  , fVisualInfo(nullptr)
+                  , fMSAASampleCount(0) {}
     ~Window_unix() override { this->closeWindow(); }
 
     bool initWindow(Display* display);
diff --git a/tools/sk_app/win/ANGLEWindowContext_win.cpp b/tools/sk_app/win/ANGLEWindowContext_win.cpp
index 452b462..649528d 100644
--- a/tools/sk_app/win/ANGLEWindowContext_win.cpp
+++ b/tools/sk_app/win/ANGLEWindowContext_win.cpp
@@ -76,8 +76,7 @@
     }
     EGLint numConfigs;
     fSampleCount = this->getDisplayParams().fMSAASampleCount;
-    const int sampleBuffers = fSampleCount > 1 ? 1 : 0;
-    const int eglSampleCnt = fSampleCount > 1 ? fSampleCount : 0;
+    const int sampleBuffers = fSampleCount > 0 ? 1 : 0;
     const EGLint configAttribs[] = {EGL_RENDERABLE_TYPE,
                                     // We currently only support ES3.
                                     EGL_OPENGL_ES3_BIT,
@@ -92,7 +91,7 @@
                                     EGL_SAMPLE_BUFFERS,
                                     sampleBuffers,
                                     EGL_SAMPLES,
-                                    eglSampleCnt,
+                                    fSampleCount,
                                     EGL_NONE};
 
     EGLConfig surfaceConfig;
diff --git a/tools/sk_app/win/GLWindowContext_win.cpp b/tools/sk_app/win/GLWindowContext_win.cpp
index 1c583cb..7e43d2b 100644
--- a/tools/sk_app/win/GLWindowContext_win.cpp
+++ b/tools/sk_app/win/GLWindowContext_win.cpp
@@ -96,9 +96,8 @@
                                               1,
                                               &kSampleCountAttr,
                                               &fSampleCount);
-            fSampleCount = SkTMax(fSampleCount, 1);
         } else {
-            fSampleCount = 1;
+            fSampleCount = 0;
         }
 
         RECT rect;
diff --git a/tools/skpbench/skpbench.cpp b/tools/skpbench/skpbench.cpp
index 6b89bc2..fcab2d3 100644
--- a/tools/skpbench/skpbench.cpp
+++ b/tools/skpbench/skpbench.cpp
@@ -292,8 +292,7 @@
     GrPixelConfig grPixConfig = SkImageInfo2GrPixelConfig(config->getColorType(),
                                                           config->getColorSpace(),
                                                           *ctx->caps());
-    int supportedSampleCount =
-            ctx->caps()->getRenderTargetSampleCount(config->getSamples(), grPixConfig);
+    int supportedSampleCount = ctx->caps()->getSampleCount(config->getSamples(), grPixConfig);
     if (supportedSampleCount != config->getSamples()) {
         exitf(ExitErr::kUnavailable, "sample count %i not supported by platform",
                                      config->getSamples());
diff --git a/tools/viewer/Viewer.cpp b/tools/viewer/Viewer.cpp
index 35b0e14..198f9ba 100644
--- a/tools/viewer/Viewer.cpp
+++ b/tools/viewer/Viewer.cpp
@@ -78,7 +78,7 @@
 
 static DEFINE_string2(backend, b, "sw", "Backend to use. Allowed values are " BACKENDS_STR ".");
 
-static DEFINE_int32(msaa, 1, "Number of subpixel samples. 0 for no HW antialiasing.");
+static DEFINE_int32(msaa, 0, "Number of subpixel samples. 0 for no HW antialiasing.");
 
 DECLARE_int32(threads)
 
@@ -501,7 +501,7 @@
     if (!fWindow) {
         return;
     }
-    if (fWindow->sampleCount() < 1) {
+    if (fWindow->sampleCount() < 0) {
         return; // Surface hasn't been created yet.
     }
 
@@ -561,8 +561,7 @@
 
     title.append(" [");
     title.append(kBackendTypeStrings[fBackendType]);
-    int msaa = fWindow->sampleCount();
-    if (msaa > 1) {
+    if (int msaa = fWindow->sampleCount()) {
         title.appendf(" MSAA: %i", msaa);
     }
     title.append("]");
@@ -995,7 +994,7 @@
                 if (ctx) {
                     int sampleCount = fWindow->sampleCount();
                     ImGui::Text("MSAA: "); ImGui::SameLine();
-                    ImGui::RadioButton("1", &sampleCount, 1); ImGui::SameLine();
+                    ImGui::RadioButton("0", &sampleCount, 0); ImGui::SameLine();
                     ImGui::RadioButton("4", &sampleCount, 4); ImGui::SameLine();
                     ImGui::RadioButton("8", &sampleCount, 8); ImGui::SameLine();
                     ImGui::RadioButton("16", &sampleCount, 16);
@@ -1019,7 +1018,7 @@
 
                     if (!ctx) {
                         ImGui::RadioButton("Software", true);
-                    } else if (fWindow->sampleCount() > 1) {
+                    } else if (fWindow->sampleCount()) {
                         prButton(GpuPathRenderers::kDefault);
                         prButton(GpuPathRenderers::kAll);
                         if (ctx->caps()->shaderCaps()->pathRenderingSupport()) {
@@ -1199,7 +1198,7 @@
     if (!fWindow) {
         return;
     }
-    if (fWindow->sampleCount() < 1) {
+    if (fWindow->sampleCount() < 0) {
         return; // Surface hasn't been created yet.
     }
 
@@ -1245,7 +1244,7 @@
     const GrContext* ctx = fWindow->getGrContext();
     if (!ctx) {
         prState[kOptions].append("Software");
-    } else if (fWindow->sampleCount() > 1) {
+    } else if (fWindow->sampleCount()) {
         prState[kOptions].append(gPathRendererNames[GpuPathRenderers::kDefault]);
         prState[kOptions].append(gPathRendererNames[GpuPathRenderers::kAll]);
         if (ctx->caps()->shaderCaps()->pathRenderingSupport()) {