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/GrProxyProvider.cpp b/src/gpu/GrProxyProvider.cpp
index 4fb2a64..9255d9d 100644
--- a/src/gpu/GrProxyProvider.cpp
+++ b/src/gpu/GrProxyProvider.cpp
@@ -23,6 +23,7 @@
#include "src/gpu/GrContextPriv.h"
#include "src/gpu/GrImageContextPriv.h"
#include "src/gpu/GrRenderTarget.h"
+#include "src/gpu/GrRenderTargetContext.h"
#include "src/gpu/GrResourceProvider.h"
#include "src/gpu/GrSurfaceProxy.h"
#include "src/gpu/GrSurfaceProxyPriv.h"
@@ -229,6 +230,24 @@
return result;
}
+GrSurfaceProxyView GrProxyProvider::findCachedProxyWithColorTypeFallback(const GrUniqueKey& key,
+ GrSurfaceOrigin origin,
+ GrColorType ct) {
+ auto proxy = this->findOrCreateProxyByUniqueKey(key);
+ if (!proxy) {
+ return {};
+ }
+ // Assume that we used a fallback color type if and only if the proxy is renderable.
+ if (proxy->asRenderTargetProxy()) {
+ GrBackendFormat expectedFormat;
+ std::tie(ct, expectedFormat) =
+ GrRenderTargetContext::GetFallbackColorTypeAndFormat(fImageContext, ct);
+ SkASSERT(expectedFormat == proxy->backendFormat());
+ }
+ GrSwizzle swizzle = fImageContext->priv().caps()->getReadSwizzle(proxy->backendFormat(), ct);
+ return {std::move(proxy), origin, swizzle};
+}
+
sk_sp<GrTextureProxy> GrProxyProvider::createProxyFromBitmap(const SkBitmap& bitmap,
GrMipMapped mipMapped,
SkBackingFit fit,