Revert "Revert "Assert that all GrCaps colortype/format -> swizzle queries are legal.""
This reverts commit ef4d3794a2ddffa877065aa66869c02bb582a479.
Fix for finding cached textures that were made with fallback color types.
Change-Id: Ic5b67801f9275f6a1cbe8373b8cce382f3cedfe7
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/280607
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 ada5a04..d075092 100644
--- a/src/gpu/GrRenderTargetContext.cpp
+++ b/src/gpu/GrRenderTargetContext.cpp
@@ -9,6 +9,7 @@
#include "include/core/SkDrawable.h"
#include "include/gpu/GrBackendSemaphore.h"
+#include "include/private/GrImageContext.h"
#include "include/private/GrRecordingContext.h"
#include "include/private/SkShadowFlags.h"
#include "include/utils/SkShadowUtils.h"
@@ -32,6 +33,7 @@
#include "src/gpu/GrDrawingManager.h"
#include "src/gpu/GrFixedClip.h"
#include "src/gpu/GrGpuResourcePriv.h"
+#include "src/gpu/GrImageContextPriv.h"
#include "src/gpu/GrImageInfo.h"
#include "src/gpu/GrMemoryPool.h"
#include "src/gpu/GrPathRenderer.h"
@@ -240,6 +242,19 @@
}
}
+std::tuple<GrColorType, GrBackendFormat> GrRenderTargetContext::GetFallbackColorTypeAndFormat(
+ GrImageContext* context, GrColorType colorType) {
+ do {
+ auto format =
+ context->priv().caps()->getDefaultBackendFormat(colorType, GrRenderable::kYes);
+ if (format.isValid()) {
+ return {colorType, format};
+ }
+ colorType = color_type_fallback(colorType);
+ } while (colorType != GrColorType::kUnknown);
+ return {GrColorType::kUnknown, {}};
+}
+
std::unique_ptr<GrRenderTargetContext> GrRenderTargetContext::MakeWithFallback(
GrRecordingContext* context,
GrColorType colorType,
@@ -252,14 +267,12 @@
GrSurfaceOrigin origin,
SkBudgeted budgeted,
const SkSurfaceProps* surfaceProps) {
- std::unique_ptr<GrRenderTargetContext> rtc;
- do {
- rtc = GrRenderTargetContext::Make(context, colorType, colorSpace, fit, dimensions,
- sampleCnt, mipMapped, isProtected, origin, budgeted,
- surfaceProps);
- colorType = color_type_fallback(colorType);
- } while (!rtc && colorType != GrColorType::kUnknown);
- return rtc;
+ auto [ct, format] = GetFallbackColorTypeAndFormat(context, colorType);
+ if (ct == GrColorType::kUnknown) {
+ return nullptr;
+ }
+ return GrRenderTargetContext::Make(context, ct, colorSpace, fit, dimensions, sampleCnt,
+ mipMapped, isProtected, origin, budgeted, surfaceProps);
}
std::unique_ptr<GrRenderTargetContext> GrRenderTargetContext::MakeFromBackendTexture(