Drop support for disabling multisample on Mac

We have historically supported non-AA draws to MSAA targets by disabling
GL_MUlTISAMPLE. This only worked on some platforms though, since
disabling multisample isn't generally supported on GLES, Vulkan, or
Metal. In addition to being inconsistent across platforms, toggling
multisample also appears to be a de-optimization at best, and a
spectacular regression at worst.

This CL lowers the set of platforms that support multisample disable and
quits supporting it on Mac. In the near future we can hopefully drop
support completely.

Bug: skia:12196
Change-Id: I8c005c92b408ceb9740d809a84ae79abb8c79ef7
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/427087
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Chris Dalton <csmartdalton@google.com>
diff --git a/src/gpu/gl/GrGLCaps.cpp b/src/gpu/gl/GrGLCaps.cpp
index e02f716..e075995 100644
--- a/src/gpu/gl/GrGLCaps.cpp
+++ b/src/gpu/gl/GrGLCaps.cpp
@@ -216,11 +216,17 @@
     }
 
     if (GR_IS_GR_GL(standard)) {
-        fMultisampleDisableSupport = true;
+        fClientCanDisableMultisample = true;
     } else if (GR_IS_GR_GL_ES(standard)) {
-        fMultisampleDisableSupport = ctxInfo.hasExtension("GL_EXT_multisample_compatibility");
+        fClientCanDisableMultisample = ctxInfo.hasExtension("GL_EXT_multisample_compatibility");
     } // no WebGL support
 
+#ifdef SK_BUILD_FOR_MAC
+    fMultisampleDisableSupport = false;
+#else
+    fMultisampleDisableSupport = fClientCanDisableMultisample;
+#endif
+
     if (GR_IS_GR_GL(standard)) {
         // 3.1 has draw_instanced but not instanced_arrays, for the time being we only care about
         // instanced arrays, but we could make this more granular if we wanted
diff --git a/src/gpu/gl/GrGLCaps.h b/src/gpu/gl/GrGLCaps.h
index 5447c62..7181e22 100644
--- a/src/gpu/gl/GrGLCaps.h
+++ b/src/gpu/gl/GrGLCaps.h
@@ -438,6 +438,8 @@
     /** Skip checks for GL errors, shader compilation success, program link success. */
     bool skipErrorChecks() const { return fSkipErrorChecks; }
 
+    bool clientCanDisableMultisample() const { return fClientCanDisableMultisample; }
+
     GrBackendFormat getBackendFormatFromCompressionType(SkImage::CompressionType) const override;
 
     GrSwizzle getWriteSwizzle(const GrBackendFormat&, GrColorType) const override;
@@ -548,6 +550,7 @@
     bool fFBFetchRequiresEnablePerSample : 1;
     bool fSRGBWriteControl : 1;
     bool fSkipErrorChecks : 1;
+    bool fClientCanDisableMultisample : 1;
 
     // Driver workarounds
     bool fDoManualMipmapping : 1;
diff --git a/src/gpu/gl/GrGLGpu.cpp b/src/gpu/gl/GrGLGpu.cpp
index 559517c..bfb9e1e 100644
--- a/src/gpu/gl/GrGLGpu.cpp
+++ b/src/gpu/gl/GrGLGpu.cpp
@@ -545,7 +545,13 @@
     }
 
     if (resetBits & kMSAAEnable_GrGLBackendState) {
-        fMSAAEnabled = kUnknown_TriState;
+        if (this->caps()->multisampleDisableSupport()) {
+            fMSAAEnabled = kUnknown_TriState;
+        } else if (this->glCaps().clientCanDisableMultisample()) {
+            // Restore GL_MULTISAMPLE to its initial state. It being enabled has no effect on draws
+            // to non-MSAA targets.
+            GL_CALL(Enable(GR_GL_MULTISAMPLE));
+        }
         fHWConservativeRasterEnabled = kUnknown_TriState;
     }