Pass GrColorType to the GrGpu::wrapRenderableBackendTexture chain of calls
This is a step towards reducing our reliance-on/use-of the GrPixelConfig stored in the GrBackendTexture.
Bug: skia:6718
Change-Id: I2170032bfbbb57423c4bb0d901ad014c61d38131
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/223701
Commit-Queue: Robert Phillips <robertphillips@google.com>
Reviewed-by: Greg Daniel <egdaniel@google.com>
diff --git a/src/gpu/GrCaps.cpp b/src/gpu/GrCaps.cpp
index 5bd4044..daffcef 100644
--- a/src/gpu/GrCaps.cpp
+++ b/src/gpu/GrCaps.cpp
@@ -372,3 +372,43 @@
GrColorType dstColorType) const {
return SupportedRead{GrSwizzle::RGBA(), GrPixelConfigToColorType(config)};
}
+
+#ifdef SK_DEBUG
+bool GrCaps::AreConfigsCompatible(GrPixelConfig genericConfig, GrPixelConfig specificConfig) {
+ bool compatible = false;
+
+ switch (genericConfig) {
+ case kAlpha_8_GrPixelConfig:
+ compatible = kAlpha_8_GrPixelConfig == specificConfig || // here bc of the mock context
+ kAlpha_8_as_Alpha_GrPixelConfig == specificConfig ||
+ kAlpha_8_as_Red_GrPixelConfig == specificConfig;
+ break;
+ case kGray_8_GrPixelConfig:
+ compatible = kGray_8_GrPixelConfig == specificConfig || // here bc of the mock context
+ kGray_8_as_Lum_GrPixelConfig == specificConfig ||
+ kGray_8_as_Red_GrPixelConfig == specificConfig;
+ break;
+ case kAlpha_half_GrPixelConfig:
+ compatible = kAlpha_half_GrPixelConfig == specificConfig || // bc of the mock context
+ kAlpha_half_as_Red_GrPixelConfig == specificConfig;
+ break;
+ case kRGB_888_GrPixelConfig:
+ compatible = kRGB_888_GrPixelConfig == specificConfig ||
+ kRGB_888X_GrPixelConfig == specificConfig;
+ break;
+ case kRGBA_8888_GrPixelConfig:
+ compatible = kRGBA_8888_GrPixelConfig == specificConfig ||
+ kBGRA_8888_GrPixelConfig == specificConfig;
+ break;
+ default:
+ compatible = genericConfig == specificConfig;
+ break;
+ }
+
+ if (!compatible) {
+ SkDebugf("Configs are not compatible: %d %d\n", genericConfig, specificConfig);
+ }
+
+ return compatible;
+}
+#endif
diff --git a/src/gpu/GrCaps.h b/src/gpu/GrCaps.h
index 3ea84b7..4e30936 100644
--- a/src/gpu/GrCaps.h
+++ b/src/gpu/GrCaps.h
@@ -411,6 +411,13 @@
const GrDriverBugWorkarounds& workarounds() const { return fDriverBugWorkarounds; }
+#ifdef SK_DEBUG
+ // This is just a debugging entry point until we're weaned off of GrPixelConfig. It
+ // should be used to verify that the pixel config from user-level code (the genericConfig)
+ // is compatible with a pixel config we've computed from scratch (the specificConfig).
+ static bool AreConfigsCompatible(GrPixelConfig genericConfig, GrPixelConfig specificConfig);
+#endif
+
protected:
/** Subclasses must call this at the end of their constructors in order to apply caps
overrides requested by the client. Note that overrides will only reduce the caps never
diff --git a/src/gpu/GrContextPriv.cpp b/src/gpu/GrContextPriv.cpp
index 47e481b..476bd08 100644
--- a/src/gpu/GrContextPriv.cpp
+++ b/src/gpu/GrContextPriv.cpp
@@ -128,8 +128,8 @@
SkASSERT(sampleCnt > 0);
sk_sp<GrTextureProxy> proxy(this->proxyProvider()->wrapRenderableBackendTexture(
- tex, origin, sampleCnt, kBorrow_GrWrapOwnership, GrWrapCacheable::kNo, releaseProc,
- releaseCtx));
+ tex, origin, sampleCnt, colorType, kBorrow_GrWrapOwnership, GrWrapCacheable::kNo,
+ releaseProc, releaseCtx));
if (!proxy) {
return nullptr;
}
diff --git a/src/gpu/GrGpu.cpp b/src/gpu/GrGpu.cpp
index 79cfbf4..f007304 100644
--- a/src/gpu/GrGpu.cpp
+++ b/src/gpu/GrGpu.cpp
@@ -230,23 +230,32 @@
}
sk_sp<GrTexture> GrGpu::wrapRenderableBackendTexture(const GrBackendTexture& backendTex,
- int sampleCnt, GrWrapOwnership ownership,
+ int sampleCnt, GrColorType colorType,
+ GrWrapOwnership ownership,
GrWrapCacheable cacheable) {
this->handleDirtyContext();
if (sampleCnt < 1) {
return nullptr;
}
- if (!this->caps()->isConfigTexturable(backendTex.config()) ||
- !this->caps()->getRenderTargetSampleCount(sampleCnt, backendTex.config())) {
+
+ const GrCaps* caps = this->caps();
+
+ SkASSERT(GrCaps::AreConfigsCompatible(backendTex.config(),
+ caps->getConfigFromBackendFormat(
+ backendTex.getBackendFormat(),
+ colorType)));
+
+ if (!caps->isFormatTexturable(colorType, backendTex.getBackendFormat()) ||
+ !caps->getRenderTargetSampleCount(sampleCnt, colorType, backendTex.getBackendFormat())) {
return nullptr;
}
- if (backendTex.width() > this->caps()->maxRenderTargetSize() ||
- backendTex.height() > this->caps()->maxRenderTargetSize()) {
+ if (backendTex.width() > caps->maxRenderTargetSize() ||
+ backendTex.height() > caps->maxRenderTargetSize()) {
return nullptr;
}
- sk_sp<GrTexture> tex =
- this->onWrapRenderableBackendTexture(backendTex, sampleCnt, ownership, cacheable);
+ sk_sp<GrTexture> tex = this->onWrapRenderableBackendTexture(backendTex, sampleCnt, colorType,
+ ownership, cacheable);
SkASSERT(!tex || tex->asRenderTarget());
return tex;
}
diff --git a/src/gpu/GrGpu.h b/src/gpu/GrGpu.h
index fa64036..04c411d 100644
--- a/src/gpu/GrGpu.h
+++ b/src/gpu/GrGpu.h
@@ -118,7 +118,7 @@
* Implements GrResourceProvider::wrapRenderableBackendTexture
*/
sk_sp<GrTexture> wrapRenderableBackendTexture(const GrBackendTexture&, int sampleCnt,
- GrWrapOwnership, GrWrapCacheable);
+ GrColorType, GrWrapOwnership, GrWrapCacheable);
/**
* Implements GrResourceProvider::wrapBackendRenderTarget
@@ -527,7 +527,8 @@
virtual sk_sp<GrTexture> onWrapBackendTexture(const GrBackendTexture&, GrWrapOwnership,
GrWrapCacheable, GrIOType) = 0;
virtual sk_sp<GrTexture> onWrapRenderableBackendTexture(const GrBackendTexture&, int sampleCnt,
- GrWrapOwnership, GrWrapCacheable) = 0;
+ GrColorType, GrWrapOwnership,
+ GrWrapCacheable) = 0;
virtual sk_sp<GrRenderTarget> onWrapBackendRenderTarget(const GrBackendRenderTarget&) = 0;
virtual sk_sp<GrRenderTarget> onWrapBackendTextureAsRenderTarget(const GrBackendTexture&,
int sampleCnt) = 0;
diff --git a/src/gpu/GrProxyProvider.cpp b/src/gpu/GrProxyProvider.cpp
index 1fc2756..5e2b1fe 100644
--- a/src/gpu/GrProxyProvider.cpp
+++ b/src/gpu/GrProxyProvider.cpp
@@ -422,6 +422,12 @@
return caps->areColorTypeAndFormatCompatible(grCT, format);
}
+
+static bool validate_backend_format_and_colortype(const GrCaps* caps,
+ GrColorType colorType,
+ const GrBackendFormat& format) {
+ return caps->areColorTypeAndFormatCompatible(colorType, format);
+}
#endif
sk_sp<GrTextureProxy> GrProxyProvider::createProxy(const GrBackendFormat& format,
@@ -431,11 +437,17 @@
SkBackingFit fit,
SkBudgeted budgeted,
GrInternalSurfaceFlags surfaceFlags) {
- SkASSERT(validate_backend_format_and_config(this->caps(), format, desc.fConfig));
if (GrPixelConfigIsCompressed(desc.fConfig)) {
// Deferred proxies for compressed textures are not supported.
return nullptr;
}
+
+ const GrCaps* caps = this->caps();
+ GrColorType colorType = GrPixelConfigToColorType(desc.fConfig);
+
+ SkASSERT(GrCaps::AreConfigsCompatible(desc.fConfig,
+ caps->getConfigFromBackendFormat(format, colorType)));
+ SkASSERT(validate_backend_format_and_colortype(caps, colorType, format));
if (GrMipMapped::kYes == mipMapped) {
// SkMipMap doesn't include the base level in the level count so we have to add 1
int mipCount = SkMipMap::ComputeLevelCount(desc.fWidth, desc.fHeight) + 1;
@@ -444,23 +456,21 @@
}
}
- if (!this->caps()->validateSurfaceDesc(desc, mipMapped)) {
+ if (!caps->validateSurfaceDesc(desc, mipMapped)) {
return nullptr;
}
GrSurfaceDesc copyDesc = desc;
if (desc.fFlags & kRenderTarget_GrSurfaceFlag) {
- copyDesc.fSampleCnt =
- this->caps()->getRenderTargetSampleCount(desc.fSampleCnt, desc.fConfig);
+ copyDesc.fSampleCnt = caps->getRenderTargetSampleCount(desc.fSampleCnt, colorType, format);
}
- GrColorType colorType = GrPixelConfigToColorType(desc.fConfig);
- GrSwizzle texSwizzle = this->caps()->getTextureSwizzle(format, colorType);
+ GrSwizzle texSwizzle = caps->getTextureSwizzle(format, colorType);
if (copyDesc.fFlags & kRenderTarget_GrSurfaceFlag) {
// We know anything we instantiate later from this deferred path will be
// both texturable and renderable
- GrSwizzle outSwizzle = this->caps()->getOutputSwizzle(format, colorType);
- return sk_sp<GrTextureProxy>(new GrTextureRenderTargetProxy(*this->caps(), format, copyDesc,
+ GrSwizzle outSwizzle = caps->getOutputSwizzle(format, colorType);
+ return sk_sp<GrTextureProxy>(new GrTextureRenderTargetProxy(*caps, format, copyDesc,
origin, mipMapped, texSwizzle,
outSwizzle, fit, budgeted,
surfaceFlags));
@@ -526,10 +536,8 @@
return nullptr;
}
-#ifdef SK_DEBUG
SkASSERT(validate_backend_format_and_config(this->caps(), backendTex.getBackendFormat(),
backendTex.config()));
-#endif
GrResourceProvider* resourceProvider = direct->priv().resourceProvider();
@@ -555,8 +563,8 @@
sk_sp<GrTextureProxy> GrProxyProvider::wrapRenderableBackendTexture(
const GrBackendTexture& backendTex, GrSurfaceOrigin origin, int sampleCnt,
- GrWrapOwnership ownership, GrWrapCacheable cacheable, ReleaseProc releaseProc,
- ReleaseContext releaseCtx) {
+ GrColorType colorType, GrWrapOwnership ownership, GrWrapCacheable cacheable,
+ ReleaseProc releaseProc, ReleaseContext releaseCtx) {
if (this->isAbandoned()) {
return nullptr;
}
@@ -567,18 +575,25 @@
return nullptr;
}
- SkASSERT(validate_backend_format_and_config(this->caps(), backendTex.getBackendFormat(),
- backendTex.config()));
+ const GrCaps* caps = this->caps();
+
+ SkASSERT(GrCaps::AreConfigsCompatible(backendTex.config(),
+ caps->getConfigFromBackendFormat(
+ backendTex.getBackendFormat(),
+ colorType)));
+ SkASSERT(validate_backend_format_and_colortype(caps, colorType, backendTex.getBackendFormat()));
GrResourceProvider* resourceProvider = direct->priv().resourceProvider();
- sampleCnt = this->caps()->getRenderTargetSampleCount(sampleCnt, backendTex.config());
+ sampleCnt = caps->getRenderTargetSampleCount(sampleCnt, colorType,
+ backendTex.getBackendFormat());
if (!sampleCnt) {
return nullptr;
}
sk_sp<GrTexture> tex = resourceProvider->wrapRenderableBackendTexture(backendTex, sampleCnt,
- ownership, cacheable);
+ colorType, ownership,
+ cacheable);
if (!tex) {
return nullptr;
}
@@ -591,9 +606,8 @@
// Make sure we match how we created the proxy with SkBudgeted::kNo
SkASSERT(GrBudgetedType::kBudgeted != tex->resourcePriv().budgetedType());
- GrColorType colorType = GrPixelConfigToColorType(tex->config());
- GrSwizzle texSwizzle = this->caps()->getTextureSwizzle(tex->backendFormat(), colorType);
- GrSwizzle outSwizzle = this->caps()->getOutputSwizzle(tex->backendFormat(), colorType);
+ GrSwizzle texSwizzle = caps->getTextureSwizzle(tex->backendFormat(), colorType);
+ GrSwizzle outSwizzle = caps->getOutputSwizzle(tex->backendFormat(), colorType);
return sk_sp<GrTextureProxy>(new GrTextureRenderTargetProxy(std::move(tex), origin, texSwizzle,
outSwizzle));
diff --git a/src/gpu/GrProxyProvider.h b/src/gpu/GrProxyProvider.h
index 435f973..dc4f4f0 100644
--- a/src/gpu/GrProxyProvider.h
+++ b/src/gpu/GrProxyProvider.h
@@ -118,8 +118,9 @@
* Create a texture proxy that wraps a backend texture and is both texture-able and renderable
*/
sk_sp<GrTextureProxy> wrapRenderableBackendTexture(const GrBackendTexture&, GrSurfaceOrigin,
- int sampleCnt, GrWrapOwnership,
- GrWrapCacheable, ReleaseProc = nullptr,
+ int sampleCnt, GrColorType,
+ GrWrapOwnership, GrWrapCacheable,
+ ReleaseProc = nullptr,
ReleaseContext = nullptr);
/*
diff --git a/src/gpu/GrResourceProvider.cpp b/src/gpu/GrResourceProvider.cpp
index 9caaf57..fc3d061 100644
--- a/src/gpu/GrResourceProvider.cpp
+++ b/src/gpu/GrResourceProvider.cpp
@@ -315,13 +315,14 @@
sk_sp<GrTexture> GrResourceProvider::wrapRenderableBackendTexture(const GrBackendTexture& tex,
int sampleCnt,
+ GrColorType colorType,
GrWrapOwnership ownership,
GrWrapCacheable cacheable) {
ASSERT_SINGLE_OWNER
if (this->isAbandoned()) {
return nullptr;
}
- return fGpu->wrapRenderableBackendTexture(tex, sampleCnt, ownership, cacheable);
+ return fGpu->wrapRenderableBackendTexture(tex, sampleCnt, colorType, ownership, cacheable);
}
sk_sp<GrRenderTarget> GrResourceProvider::wrapBackendRenderTarget(
diff --git a/src/gpu/GrResourceProvider.h b/src/gpu/GrResourceProvider.h
index 1ac19ec..a4931c6 100644
--- a/src/gpu/GrResourceProvider.h
+++ b/src/gpu/GrResourceProvider.h
@@ -117,6 +117,7 @@
*/
sk_sp<GrTexture> wrapRenderableBackendTexture(const GrBackendTexture& tex,
int sampleCnt,
+ GrColorType,
GrWrapOwnership,
GrWrapCacheable);
diff --git a/src/gpu/gl/GrGLCaps.cpp b/src/gpu/gl/GrGLCaps.cpp
index d417e59..f83aa9d 100644
--- a/src/gpu/gl/GrGLCaps.cpp
+++ b/src/gpu/gl/GrGLCaps.cpp
@@ -3757,7 +3757,7 @@
}
// A near clone of format_color_type_valid_pair
-GrPixelConfig validate_sized_format(GrGLenum format, GrColorType ct, GrGLStandard standard) {
+static GrPixelConfig validate_sized_format(GrGLenum format, GrColorType ct, GrGLStandard standard) {
switch (ct) {
case GrColorType::kUnknown:
return kUnknown_GrPixelConfig;
diff --git a/src/gpu/gl/GrGLGpu.cpp b/src/gpu/gl/GrGLGpu.cpp
index 9b439cd..21a1fa2 100644
--- a/src/gpu/gl/GrGLGpu.cpp
+++ b/src/gpu/gl/GrGLGpu.cpp
@@ -714,6 +714,7 @@
sk_sp<GrTexture> GrGLGpu::onWrapRenderableBackendTexture(const GrBackendTexture& backendTex,
int sampleCnt,
+ GrColorType colorType,
GrWrapOwnership ownership,
GrWrapCacheable cacheable) {
GrGLTexture::IDDesc idDesc;
@@ -735,12 +736,15 @@
idDesc.fOwnership = GrBackendObjectOwnership::kOwned;
}
+ const GrCaps* caps = this->caps();
+
GrSurfaceDesc surfDesc;
surfDesc.fFlags = kRenderTarget_GrSurfaceFlag;
surfDesc.fWidth = backendTex.width();
surfDesc.fHeight = backendTex.height();
surfDesc.fConfig = backendTex.config();
- surfDesc.fSampleCnt = this->caps()->getRenderTargetSampleCount(sampleCnt, backendTex.config());
+ surfDesc.fSampleCnt = caps->getRenderTargetSampleCount(sampleCnt, colorType,
+ backendTex.getBackendFormat());
if (surfDesc.fSampleCnt < 1) {
return nullptr;
}
diff --git a/src/gpu/gl/GrGLGpu.h b/src/gpu/gl/GrGLGpu.h
index 5834d2c..027d571 100644
--- a/src/gpu/gl/GrGLGpu.h
+++ b/src/gpu/gl/GrGLGpu.h
@@ -203,7 +203,8 @@
sk_sp<GrTexture> onWrapBackendTexture(const GrBackendTexture&, GrWrapOwnership, GrWrapCacheable,
GrIOType) override;
sk_sp<GrTexture> onWrapRenderableBackendTexture(const GrBackendTexture&, int sampleCnt,
- GrWrapOwnership, GrWrapCacheable) override;
+ GrColorType, GrWrapOwnership,
+ GrWrapCacheable) override;
sk_sp<GrRenderTarget> onWrapBackendRenderTarget(const GrBackendRenderTarget&) override;
sk_sp<GrRenderTarget> onWrapBackendTextureAsRenderTarget(const GrBackendTexture&,
int sampleCnt) override;
diff --git a/src/gpu/mock/GrMockGpu.cpp b/src/gpu/mock/GrMockGpu.cpp
index aa975cd..898aa7e 100644
--- a/src/gpu/mock/GrMockGpu.cpp
+++ b/src/gpu/mock/GrMockGpu.cpp
@@ -132,11 +132,13 @@
sk_sp<GrTexture> GrMockGpu::onWrapRenderableBackendTexture(const GrBackendTexture& tex,
int sampleCnt,
+ GrColorType colorType,
GrWrapOwnership ownership,
GrWrapCacheable cacheable) {
GrMockTextureInfo texInfo;
SkAssertResult(tex.getMockTextureInfo(&texInfo));
+ SkASSERT(colorType == texInfo.fColorType);
GrSurfaceDesc desc;
desc.fFlags = kRenderTarget_GrSurfaceFlag;
desc.fWidth = tex.width();
diff --git a/src/gpu/mock/GrMockGpu.h b/src/gpu/mock/GrMockGpu.h
index 0ea5c1a..fadbf98 100644
--- a/src/gpu/mock/GrMockGpu.h
+++ b/src/gpu/mock/GrMockGpu.h
@@ -74,6 +74,7 @@
sk_sp<GrTexture> onWrapRenderableBackendTexture(const GrBackendTexture&,
int sampleCnt,
+ GrColorType,
GrWrapOwnership,
GrWrapCacheable) override;
diff --git a/src/gpu/mtl/GrMtlGpu.h b/src/gpu/mtl/GrMtlGpu.h
index 209f73c..42f684d 100644
--- a/src/gpu/mtl/GrMtlGpu.h
+++ b/src/gpu/mtl/GrMtlGpu.h
@@ -146,7 +146,8 @@
GrIOType) override;
sk_sp<GrTexture> onWrapRenderableBackendTexture(const GrBackendTexture&, int sampleCnt,
- GrWrapOwnership, GrWrapCacheable) override;
+ GrColorType, GrWrapOwnership,
+ GrWrapCacheable) override;
sk_sp<GrRenderTarget> onWrapBackendRenderTarget(const GrBackendRenderTarget&) override;
diff --git a/src/gpu/mtl/GrMtlGpu.mm b/src/gpu/mtl/GrMtlGpu.mm
index 1e869ce..a474256 100644
--- a/src/gpu/mtl/GrMtlGpu.mm
+++ b/src/gpu/mtl/GrMtlGpu.mm
@@ -524,6 +524,7 @@
sk_sp<GrTexture> GrMtlGpu::onWrapRenderableBackendTexture(const GrBackendTexture& backendTex,
int sampleCnt,
+ GrColorType colorType,
GrWrapOwnership,
GrWrapCacheable cacheable) {
id<MTLTexture> mtlTexture = get_texture_from_backend(backendTex);
@@ -533,7 +534,9 @@
GrSurfaceDesc surfDesc;
init_surface_desc(&surfDesc, mtlTexture, true, backendTex.config());
- surfDesc.fSampleCnt = this->caps()->getRenderTargetSampleCount(sampleCnt, surfDesc.fConfig);
+
+ surfDesc.fSampleCnt = this->caps()->getRenderTargetSampleCount(sampleCnt, colorType,
+ backendTex.getBackendFormat());
if (!surfDesc.fSampleCnt) {
return nullptr;
}
diff --git a/src/gpu/vk/GrVkCaps.cpp b/src/gpu/vk/GrVkCaps.cpp
index 0e0405d..ff56ebe 100644
--- a/src/gpu/vk/GrVkCaps.cpp
+++ b/src/gpu/vk/GrVkCaps.cpp
@@ -1010,7 +1010,7 @@
break;
case GrColorType::kAlpha_F16:
if (VK_FORMAT_R16_SFLOAT == format) {
- return kAlpha_half_GrPixelConfig;
+ return kAlpha_half_as_Red_GrPixelConfig;
}
break;
case GrColorType::kRGBA_F16:
diff --git a/src/gpu/vk/GrVkGpu.cpp b/src/gpu/vk/GrVkGpu.cpp
index 89248fc..7a9811a 100644
--- a/src/gpu/vk/GrVkGpu.cpp
+++ b/src/gpu/vk/GrVkGpu.cpp
@@ -1187,6 +1187,7 @@
sk_sp<GrTexture> GrVkGpu::onWrapRenderableBackendTexture(const GrBackendTexture& backendTex,
int sampleCnt,
+ GrColorType colorType,
GrWrapOwnership ownership,
GrWrapCacheable cacheable) {
GrVkImageInfo imageInfo;
@@ -1209,13 +1210,19 @@
return nullptr;
}
+ SkASSERT(GrCaps::AreConfigsCompatible(backendTex.config(),
+ this->caps()->getConfigFromBackendFormat(
+ backendTex.getBackendFormat(),
+ colorType)));
+
GrSurfaceDesc surfDesc;
surfDesc.fFlags = kRenderTarget_GrSurfaceFlag;
surfDesc.fWidth = backendTex.width();
surfDesc.fHeight = backendTex.height();
surfDesc.fIsProtected = backendTex.isProtected() ? GrProtected::kYes : GrProtected::kNo;
surfDesc.fConfig = backendTex.config();
- surfDesc.fSampleCnt = this->caps()->getRenderTargetSampleCount(sampleCnt, backendTex.config());
+ surfDesc.fSampleCnt = this->caps()->getRenderTargetSampleCount(sampleCnt, colorType,
+ backendTex.getBackendFormat());
sk_sp<GrVkImageLayout> layout = backendTex.getGrVkImageLayout();
SkASSERT(layout);
@@ -1871,7 +1878,7 @@
*config = kRGB_ETC1_GrPixelConfig;
return true;
case VK_FORMAT_R16_SFLOAT:
- *config = kAlpha_half_GrPixelConfig;
+ *config = kAlpha_half_as_Red_GrPixelConfig;
return true;
case VK_FORMAT_R16_UNORM:
*config = kR_16_GrPixelConfig;
diff --git a/src/gpu/vk/GrVkGpu.h b/src/gpu/vk/GrVkGpu.h
index dfc099a..f961e4f 100644
--- a/src/gpu/vk/GrVkGpu.h
+++ b/src/gpu/vk/GrVkGpu.h
@@ -200,6 +200,7 @@
GrIOType) override;
sk_sp<GrTexture> onWrapRenderableBackendTexture(const GrBackendTexture&,
int sampleCnt,
+ GrColorType colorType,
GrWrapOwnership,
GrWrapCacheable) override;
sk_sp<GrRenderTarget> onWrapBackendRenderTarget(const GrBackendRenderTarget&) override;
diff --git a/tests/GrSurfaceTest.cpp b/tests/GrSurfaceTest.cpp
index 2829b76..e95fd47 100644
--- a/tests/GrSurfaceTest.cpp
+++ b/tests/GrSurfaceTest.cpp
@@ -58,7 +58,7 @@
SkColors::kTransparent, GrMipMapped::kNo, GrRenderable::kNo, GrProtected::kNo);
sk_sp<GrSurface> texRT2 = resourceProvider->wrapRenderableBackendTexture(
- backendTex, 1, kBorrow_GrWrapOwnership, GrWrapCacheable::kNo);
+ backendTex, 1, GrColorType::kRGBA_8888, kBorrow_GrWrapOwnership, GrWrapCacheable::kNo);
REPORTER_ASSERT(reporter, texRT2.get() == texRT2->asRenderTarget());
REPORTER_ASSERT(reporter, texRT2.get() == texRT2->asTexture());
@@ -119,6 +119,23 @@
for (int c = 0; c <= kLast_GrPixelConfig; ++c) {
GrPixelConfig config = static_cast<GrPixelConfig>(c);
+ // We don't round trip correctly going from pixelConfig to colorType to
+ // backendFormat with the RGBX config.
+ if (config == kRGB_888X_GrPixelConfig) {
+ continue;
+ }
+
+ // The specific kAlpha_* and kGray_8* pixel configs cause difficulties.
+ // The mapping from config -> colorType -> format doesn't necessarily
+ // resolve back to the expected pixel config. Just test the generic pixel configs.
+ if (config == kAlpha_8_as_Alpha_GrPixelConfig ||
+ config == kAlpha_8_as_Red_GrPixelConfig ||
+ config == kGray_8_as_Lum_GrPixelConfig ||
+ config == kGray_8_as_Red_GrPixelConfig ||
+ config == kAlpha_half_as_Red_GrPixelConfig) {
+ continue;
+ }
+
for (GrSurfaceOrigin origin : { kTopLeft_GrSurfaceOrigin, kBottomLeft_GrSurfaceOrigin }) {
if (config == kUnknown_GrPixelConfig) {
// It is not valid to be calling into GrProxyProvider with an unknown pixel config.
@@ -239,6 +256,28 @@
if (desc.fConfig == kRGB_888X_GrPixelConfig) {
continue;
}
+
+ // The specific kAlpha_* pixel configs also cause difficulties with OpenGL.
+ // The mapping from config -> colorType -> format doesn't necessarily
+ // resolve back to the expected pixel config. In this case we just test
+ // the generics.
+ if (GrBackendApi::kOpenGL == context->backend() &&
+ (desc.fConfig == kAlpha_8_as_Alpha_GrPixelConfig ||
+ desc.fConfig == kAlpha_8_as_Red_GrPixelConfig ||
+ desc.fConfig == kAlpha_half_as_Red_GrPixelConfig)) {
+ continue;
+ }
+
+ // The specific kGray_8_* pixel configs also cause difficulties with OpenGL.
+ // The mapping from config -> colorType -> format doesn't necessarily
+ // resolve back to the expected pixel config. In this case we just test
+ // the generic.
+ if (GrBackendApi::kOpenGL == context->backend() &&
+ (desc.fConfig == kGray_8_as_Lum_GrPixelConfig ||
+ desc.fConfig == kGray_8_as_Red_GrPixelConfig)) {
+ continue;
+ }
+
GrColorType colorType = GrPixelConfigToColorType(desc.fConfig);
const GrBackendFormat format = caps->getBackendFormatFromColorType(colorType);
@@ -386,7 +425,8 @@
sk_sp<GrTexture> texture;
if (GrRenderable::kYes == renderable) {
texture = context->priv().resourceProvider()->wrapRenderableBackendTexture(
- backendTexture, 1, kBorrow_GrWrapOwnership, GrWrapCacheable::kNo);
+ backendTexture, 1, GrColorType::kRGBA_8888, kBorrow_GrWrapOwnership,
+ GrWrapCacheable::kNo);
} else {
texture = context->priv().resourceProvider()->wrapBackendTexture(
backendTexture, kBorrow_GrWrapOwnership, GrWrapCacheable::kNo, kRW_GrIOType);
diff --git a/tests/GrTestingBackendTextureUploadTest.cpp b/tests/GrTestingBackendTextureUploadTest.cpp
index 4325d1c..07151e2 100644
--- a/tests/GrTestingBackendTextureUploadTest.cpp
+++ b/tests/GrTestingBackendTextureUploadTest.cpp
@@ -68,7 +68,7 @@
sk_sp<GrTextureProxy> wrappedProxy;
if (GrRenderable::kYes == renderable) {
wrappedProxy = context->priv().proxyProvider()->wrapRenderableBackendTexture(
- backendTex, kTopLeft_GrSurfaceOrigin, 1, kAdopt_GrWrapOwnership,
+ backendTex, kTopLeft_GrSurfaceOrigin, 1, grCT, kAdopt_GrWrapOwnership,
GrWrapCacheable::kNo);
} else {
wrappedProxy = context->priv().proxyProvider()->wrapBackendTexture(
diff --git a/tests/ProxyTest.cpp b/tests/ProxyTest.cpp
index aa0c4c7..23022e0 100644
--- a/tests/ProxyTest.cpp
+++ b/tests/ProxyTest.cpp
@@ -308,7 +308,8 @@
GrProtected::kNo);
sk_sp<GrSurfaceProxy> sProxy = proxyProvider->wrapRenderableBackendTexture(
- backendTex, origin, supportedNumSamples, kBorrow_GrWrapOwnership,
+ backendTex, origin, supportedNumSamples,
+ grColorType, kBorrow_GrWrapOwnership,
GrWrapCacheable::kNo, nullptr, nullptr);
if (!sProxy) {
context->deleteBackendTexture(backendTex);
diff --git a/tests/VkWrapTests.cpp b/tests/VkWrapTests.cpp
index a6fb439..97917c6 100644
--- a/tests/VkWrapTests.cpp
+++ b/tests/VkWrapTests.cpp
@@ -31,6 +31,7 @@
const int kH = 1024;
const GrPixelConfig kPixelConfig = kRGBA_8888_GrPixelConfig;
const SkColorType kColorType = SkColorType::kRGBA_8888_SkColorType;
+const GrColorType kGrColorType = GrColorType::kRGBA_8888;
void wrap_tex_test(skiatest::Reporter* reporter, GrContext* context) {
@@ -147,7 +148,7 @@
SkAssertResult(origBackendTex.getVkImageInfo(&imageInfo));
sk_sp<GrTexture> tex = gpu->wrapRenderableBackendTexture(
- origBackendTex, 1, kBorrow_GrWrapOwnership, GrWrapCacheable::kNo);
+ origBackendTex, 1, kGrColorType, kBorrow_GrWrapOwnership, GrWrapCacheable::kNo);
REPORTER_ASSERT(reporter, tex);
// image is null
@@ -156,11 +157,11 @@
backendCopy.fImage = VK_NULL_HANDLE;
GrBackendTexture backendTex = GrBackendTexture(kW, kH, backendCopy);
backendTex.setPixelConfig(kPixelConfig);
- tex = gpu->wrapRenderableBackendTexture(backendTex, 1, kBorrow_GrWrapOwnership,
- GrWrapCacheable::kNo);
+ tex = gpu->wrapRenderableBackendTexture(backendTex, 1, kGrColorType,
+ kBorrow_GrWrapOwnership, GrWrapCacheable::kNo);
REPORTER_ASSERT(reporter, !tex);
- tex = gpu->wrapRenderableBackendTexture(backendTex, 1, kAdopt_GrWrapOwnership,
- GrWrapCacheable::kNo);
+ tex = gpu->wrapRenderableBackendTexture(backendTex, 1, kGrColorType,
+ kAdopt_GrWrapOwnership, GrWrapCacheable::kNo);
REPORTER_ASSERT(reporter, !tex);
}
@@ -170,11 +171,11 @@
backendCopy.fAlloc = GrVkAlloc();
GrBackendTexture backendTex = GrBackendTexture(kW, kH, backendCopy);
backendTex.setPixelConfig(kPixelConfig);
- tex = gpu->wrapRenderableBackendTexture(backendTex, 1, kBorrow_GrWrapOwnership,
- GrWrapCacheable::kNo);
+ tex = gpu->wrapRenderableBackendTexture(backendTex, 1, kGrColorType,
+ kBorrow_GrWrapOwnership, GrWrapCacheable::kNo);
REPORTER_ASSERT(reporter, tex);
- tex = gpu->wrapRenderableBackendTexture(backendTex, 1, kAdopt_GrWrapOwnership,
- GrWrapCacheable::kNo);
+ tex = gpu->wrapRenderableBackendTexture(backendTex, 1, kGrColorType,
+ kAdopt_GrWrapOwnership, GrWrapCacheable::kNo);
REPORTER_ASSERT(reporter, !tex);
}
@@ -183,8 +184,8 @@
GrVkImageInfo backendCopy = imageInfo;
GrBackendTexture backendTex = GrBackendTexture(kW, kH, backendCopy);
backendTex.setPixelConfig(kPixelConfig);
- tex = gpu->wrapRenderableBackendTexture(backendTex, 1, kAdopt_GrWrapOwnership,
- GrWrapCacheable::kNo);
+ tex = gpu->wrapRenderableBackendTexture(backendTex, 1, kGrColorType,
+ kAdopt_GrWrapOwnership, GrWrapCacheable::kNo);
REPORTER_ASSERT(reporter, tex);
}
}
diff --git a/tools/gpu/ProxyUtils.cpp b/tools/gpu/ProxyUtils.cpp
index 428ac7b..e592b02 100644
--- a/tools/gpu/ProxyUtils.cpp
+++ b/tools/gpu/ProxyUtils.cpp
@@ -46,8 +46,8 @@
// Adopt ownership so our caller doesn't have to worry about deleting the backend texture.
if (GrRenderable::kYes == renderable) {
proxy = context->priv().proxyProvider()->wrapRenderableBackendTexture(
- backendTex, origin, 1, kAdopt_GrWrapOwnership, GrWrapCacheable::kNo, nullptr,
- nullptr);
+ backendTex, origin, 1, colorType, kAdopt_GrWrapOwnership, GrWrapCacheable::kNo,
+ nullptr, nullptr);
} else {
proxy = context->priv().proxyProvider()->wrapBackendTexture(
backendTex, origin, kAdopt_GrWrapOwnership, GrWrapCacheable::kNo, kRW_GrIOType);