Incorporate sample count into RTC fallback color type.

Formats can be renderable but not support MSAA.

Change-Id: I33fd295cce0b4b11a0c132c40a85fc7a7d4973b5
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/281477
Reviewed-by: Greg Daniel <egdaniel@google.com>
Commit-Queue: Brian Salomon <bsalomon@google.com>
diff --git a/src/gpu/GrRenderTargetContext.cpp b/src/gpu/GrRenderTargetContext.cpp
index f143003..a3b9367 100644
--- a/src/gpu/GrRenderTargetContext.cpp
+++ b/src/gpu/GrRenderTargetContext.cpp
@@ -244,11 +244,13 @@
 }
 
 std::tuple<GrColorType, GrBackendFormat> GrRenderTargetContext::GetFallbackColorTypeAndFormat(
-        GrImageContext* context, GrColorType colorType) {
+        GrImageContext* context, GrColorType colorType, int sampleCnt) {
+    auto caps = context->priv().caps();
     do {
-        auto format =
-                context->priv().caps()->getDefaultBackendFormat(colorType, GrRenderable::kYes);
-        if (format.isValid()) {
+        auto format = caps->getDefaultBackendFormat(colorType, GrRenderable::kYes);
+        // We continue to the fallback color type if there no default renderable format or we
+        // requested msaa and the format doesn't support msaa.
+        if (format.isValid() && caps->isFormatRenderable(format, sampleCnt)) {
             return {colorType, format};
         }
         colorType = color_type_fallback(colorType);
@@ -268,7 +270,7 @@
         GrSurfaceOrigin origin,
         SkBudgeted budgeted,
         const SkSurfaceProps* surfaceProps) {
-    auto [ct, format] = GetFallbackColorTypeAndFormat(context, colorType);
+    auto [ct, format] = GetFallbackColorTypeAndFormat(context, colorType, sampleCnt);
     if (ct == GrColorType::kUnknown) {
         return nullptr;
     }