Remove use of GrColorType on GrCaps::getRenderTargetSampleCount.
Additionally this changes removes the version of the call that that takes
a GrPixelConfig.
As part of this change many call sites that were calling getRTSampleCount
to just check renderability have been changed to call
isFormat[AsColorType]Renderable instead. This change has also started to
move us to just checking format renderability (without GrCT) in classes
that are specifically dealing with GrSurface (GrResourceProvider, GrGpu, etc.).
Bug: skia:6718
Change-Id: Icf4a1a21a81a44e6863a7cd2059d21b9833d581f
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/233039
Commit-Queue: Greg Daniel <egdaniel@google.com>
Reviewed-by: Brian Salomon <bsalomon@google.com>
diff --git a/bench/nanobench.cpp b/bench/nanobench.cpp
index 50ebb52..7bbef10 100644
--- a/bench/nanobench.cpp
+++ b/bench/nanobench.cpp
@@ -459,9 +459,9 @@
GrContextFactory factory(grContextOpts);
if (const GrContext* ctx = factory.get(ctxType, ctxOverrides)) {
- GrPixelConfig grPixConfig = SkColorType2GrPixelConfig(colorType);
+ GrBackendFormat format = ctx->defaultBackendFormat(colorType, GrRenderable::kYes);
int supportedSampleCount =
- ctx->priv().caps()->getRenderTargetSampleCount(sampleCount, grPixConfig);
+ ctx->priv().caps()->getRenderTargetSampleCount(sampleCount, format);
if (sampleCount != supportedSampleCount) {
SkDebugf("Configuration '%s' sample count %d is not a supported sample count.\n",
config->getTag().c_str(), sampleCount);
diff --git a/src/gpu/GrCaps.cpp b/src/gpu/GrCaps.cpp
index 037d72b..2ccfdfd 100644
--- a/src/gpu/GrCaps.cpp
+++ b/src/gpu/GrCaps.cpp
@@ -280,9 +280,10 @@
return this->onCanCopySurface(dst, src, srcRect, dstPoint);
}
-bool GrCaps::validateSurfaceDesc(const GrSurfaceDesc& desc, GrRenderable renderable,
- int renderTargetSampleCnt, GrMipMapped mipped) const {
- if (!this->isConfigTexturable(desc.fConfig)) {
+bool GrCaps::validateSurfaceParams(const SkISize& size, const GrBackendFormat& format,
+ GrPixelConfig config, GrRenderable renderable,
+ int renderTargetSampleCnt, GrMipMapped mipped) const {
+ if (!this->isConfigTexturable(config)) {
return false;
}
@@ -290,16 +291,16 @@
return false;
}
- if (desc.fWidth < 1 || desc.fHeight < 1) {
+ if (size.width() < 1 || size.height() < 1) {
return false;
}
if (renderable == GrRenderable::kYes) {
- if (0 == this->getRenderTargetSampleCount(renderTargetSampleCnt, desc.fConfig)) {
+ if (!this->isFormatRenderable(format, renderTargetSampleCnt)) {
return false;
}
int maxRTSize = this->maxRenderTargetSize();
- if (desc.fWidth > maxRTSize || desc.fHeight > maxRTSize) {
+ if (size.width() > maxRTSize || size.height() > maxRTSize) {
return false;
}
} else {
@@ -308,7 +309,7 @@
return false;
}
int maxSize = this->maxTextureSize();
- if (desc.fWidth > maxSize || desc.fHeight > maxSize) {
+ if (size.width() > maxSize || size.height() > maxSize) {
return false;
}
}
diff --git a/src/gpu/GrCaps.h b/src/gpu/GrCaps.h
index 1d974fe..5183a55 100644
--- a/src/gpu/GrCaps.h
+++ b/src/gpu/GrCaps.h
@@ -182,12 +182,10 @@
virtual bool isFormatRenderable(const GrBackendFormat& format, int sampleCount) const = 0;
// Find a sample count greater than or equal to the requested count which is supported for a
- // color buffer of the given config or 0 if no such sample count is supported. If the requested
+ // render target of the given format or 0 if no such sample count is supported. If the requested
// sample count is 1 then 1 will be returned if non-MSAA rendering is supported, otherwise 0.
// For historical reasons requestedCount==0 is handled identically to requestedCount==1.
- virtual int getRenderTargetSampleCount(int requestedCount,
- GrColorType, const GrBackendFormat&) const = 0;
- virtual int getRenderTargetSampleCount(int requestedCount, GrPixelConfig) const = 0;
+ virtual int getRenderTargetSampleCount(int requestedCount, const GrBackendFormat&) const = 0;
/**
* Backends may have restrictions on what types of surfaces support GrGpu::writePixels().
@@ -362,8 +360,9 @@
return {};
}
- bool validateSurfaceDesc(const GrSurfaceDesc&, GrRenderable renderable,
- int renderTargetSampleCnt, GrMipMapped) const;
+ bool validateSurfaceParams(const SkISize&, const GrBackendFormat&, GrPixelConfig,
+ GrRenderable renderable, int renderTargetSampleCnt,
+ GrMipMapped) const;
bool areColorTypeAndFormatCompatible(GrColorType grCT,
const GrBackendFormat& format) const {
diff --git a/src/gpu/GrContextThreadSafeProxy.cpp b/src/gpu/GrContextThreadSafeProxy.cpp
index 5b00895..7ad6fb3 100644
--- a/src/gpu/GrContextThreadSafeProxy.cpp
+++ b/src/gpu/GrContextThreadSafeProxy.cpp
@@ -64,11 +64,13 @@
return SkSurfaceCharacterization(); // return an invalid characterization
}
- sampleCnt = this->caps()->getRenderTargetSampleCount(sampleCnt, grColorType, backendFormat);
- if (!sampleCnt) {
+ if (!this->caps()->isFormatAsColorTypeRenderable(grColorType, backendFormat, sampleCnt)) {
return SkSurfaceCharacterization(); // return an invalid characterization
}
+ sampleCnt = this->caps()->getRenderTargetSampleCount(sampleCnt, backendFormat);
+ SkASSERT(sampleCnt);
+
if (willUseGLFBO0 && isTextureable) {
return SkSurfaceCharacterization(); // return an invalid characterization
}
diff --git a/src/gpu/GrGpu.cpp b/src/gpu/GrGpu.cpp
index 6130312..8c161fe 100644
--- a/src/gpu/GrGpu.cpp
+++ b/src/gpu/GrGpu.cpp
@@ -156,13 +156,14 @@
GrSurfaceDesc desc = origDesc;
GrMipMapped mipMapped = mipLevelCount > 1 ? GrMipMapped::kYes : GrMipMapped::kNo;
- if (!this->caps()->validateSurfaceDesc(desc, renderable, renderTargetSampleCnt, mipMapped)) {
+ if (!this->caps()->validateSurfaceParams({desc.fWidth, desc.fHeight}, format, desc.fConfig,
+ renderable, renderTargetSampleCnt, mipMapped)) {
return nullptr;
}
if (renderable == GrRenderable::kYes) {
renderTargetSampleCnt =
- this->caps()->getRenderTargetSampleCount(renderTargetSampleCnt, desc.fConfig);
+ this->caps()->getRenderTargetSampleCount(renderTargetSampleCnt, format);
}
// Attempt to catch un- or wrongly initialized sample counts.
SkASSERT(renderTargetSampleCnt > 0 && renderTargetSampleCnt <= 64);
@@ -260,7 +261,7 @@
const GrCaps* caps = this->caps();
if (!caps->isFormatTexturable(colorType, backendTex.getBackendFormat()) ||
- !caps->getRenderTargetSampleCount(sampleCnt, colorType, backendTex.getBackendFormat())) {
+ !caps->isFormatRenderable(backendTex.getBackendFormat(), sampleCnt)) {
return nullptr;
}
@@ -280,8 +281,7 @@
const GrCaps* caps = this->caps();
- if (0 == caps->getRenderTargetSampleCount(backendRT.sampleCnt(), colorType,
- backendRT.getBackendFormat())) {
+ if (!caps->isFormatRenderable(backendRT.getBackendFormat(), backendRT.sampleCnt())) {
return nullptr;
}
@@ -300,8 +300,7 @@
return nullptr;
}
- if (0 == caps->getRenderTargetSampleCount(sampleCnt, colorType,
- backendTex.getBackendFormat())) {
+ if (!caps->isFormatRenderable(backendTex.getBackendFormat(), sampleCnt)) {
return nullptr;
}
diff --git a/src/gpu/GrProxyProvider.cpp b/src/gpu/GrProxyProvider.cpp
index f64b345..65d6ee2 100644
--- a/src/gpu/GrProxyProvider.cpp
+++ b/src/gpu/GrProxyProvider.cpp
@@ -277,7 +277,7 @@
}
if (renderable == GrRenderable::kYes) {
- sampleCnt = this->caps()->getRenderTargetSampleCount(sampleCnt, grCT, format);
+ sampleCnt = this->caps()->getRenderTargetSampleCount(sampleCnt, format);
if (!sampleCnt) {
return nullptr;
}
@@ -499,7 +499,8 @@
}
}
- if (!caps->validateSurfaceDesc(desc, renderable, renderTargetSampleCnt, mipMapped)) {
+ if (!caps->validateSurfaceParams({desc.fWidth, desc.fHeight}, format, desc.fConfig, renderable,
+ renderTargetSampleCnt, mipMapped)) {
return nullptr;
}
GrSurfaceDesc copyDesc = desc;
@@ -509,7 +510,8 @@
GrSwizzle texSwizzle = caps->getTextureSwizzle(format, colorType);
if (renderable == GrRenderable::kYes) {
renderTargetSampleCnt =
- caps->getRenderTargetSampleCount(renderTargetSampleCnt, colorType, format);
+ caps->getRenderTargetSampleCount(renderTargetSampleCnt, format);
+ SkASSERT(renderTargetSampleCnt);
// We know anything we instantiate later from this deferred path will be
// both texturable and renderable
GrSwizzle outSwizzle = caps->getOutputSwizzle(format, colorType);
@@ -629,12 +631,14 @@
GrResourceProvider* resourceProvider = direct->priv().resourceProvider();
- sampleCnt = caps->getRenderTargetSampleCount(sampleCnt, colorType,
- backendTex.getBackendFormat());
- if (!sampleCnt) {
+ // TODO: This should have been checked and validated before getting into GrProxyProvider.
+ if (!caps->isFormatAsColorTypeRenderable(colorType, backendTex.getBackendFormat(), sampleCnt)) {
return nullptr;
}
+ sampleCnt = caps->getRenderTargetSampleCount(sampleCnt, backendTex.getBackendFormat());
+ SkASSERT(sampleCnt);
+
sk_sp<GrTexture> tex = resourceProvider->wrapRenderableBackendTexture(backendTex, sampleCnt,
colorType, ownership,
cacheable);
diff --git a/src/gpu/GrResourceProvider.cpp b/src/gpu/GrResourceProvider.cpp
index 2413c64..cff3fcf 100644
--- a/src/gpu/GrResourceProvider.cpp
+++ b/src/gpu/GrResourceProvider.cpp
@@ -91,7 +91,8 @@
}
GrMipMapped mipMapped = mipLevelCount > 1 ? GrMipMapped::kYes : GrMipMapped::kNo;
- if (!fCaps->validateSurfaceDesc(desc, renderable, renderTargetSampleCnt, mipMapped)) {
+ if (!fCaps->validateSurfaceParams({desc.fWidth, desc.fHeight}, format, desc.fConfig, renderable,
+ renderTargetSampleCnt, mipMapped)) {
return nullptr;
}
bool mustInitializeAllLevels = this->caps()->createTextureMustSpecifyAllLevels();
@@ -152,7 +153,8 @@
return nullptr;
}
- if (!fCaps->validateSurfaceDesc(desc, renderable, renderTargetSampleCnt, GrMipMapped::kNo)) {
+ if (!fCaps->validateSurfaceParams({desc.fWidth, desc.fHeight}, format, desc.fConfig, renderable,
+ renderTargetSampleCnt, GrMipMapped::kNo)) {
return nullptr;
}
@@ -222,7 +224,8 @@
return nullptr;
}
- if (!fCaps->validateSurfaceDesc(desc, renderable, renderTargetSampleCnt, GrMipMapped::kNo)) {
+ if (!fCaps->validateSurfaceParams({desc.fWidth, desc.fHeight}, format, desc.fConfig, renderable,
+ renderTargetSampleCnt, GrMipMapped::kNo)) {
return nullptr;
}
@@ -294,7 +297,8 @@
return nullptr;
}
- if (!fCaps->validateSurfaceDesc(desc, renderable, renderTargetSampleCnt, GrMipMapped::kNo)) {
+ if (!fCaps->validateSurfaceParams({desc.fWidth, desc.fHeight}, format, desc.fConfig, renderable,
+ renderTargetSampleCnt, GrMipMapped::kNo)) {
return nullptr;
}
@@ -340,7 +344,8 @@
ASSERT_SINGLE_OWNER
SkASSERT(!this->isAbandoned());
SkASSERT(!GrPixelConfigIsCompressed(desc.fConfig));
- SkASSERT(fCaps->validateSurfaceDesc(desc, renderable, renderTargetSampleCnt, GrMipMapped::kNo));
+ SkASSERT(fCaps->validateSurfaceParams({desc.fWidth, desc.fHeight}, format, desc.fConfig,
+ renderable, renderTargetSampleCnt, GrMipMapped::kNo));
// We could make initial clears work with scratch textures but it is a rare case so we just opt
// to fall back to making a new texture.
diff --git a/src/gpu/gl/GrGLCaps.cpp b/src/gpu/gl/GrGLCaps.cpp
index 1e1a95e..8c8bc55 100644
--- a/src/gpu/gl/GrGLCaps.cpp
+++ b/src/gpu/gl/GrGLCaps.cpp
@@ -3807,12 +3807,8 @@
return this->isFormatRenderable(glFormat, sampleCount);
}
-int GrGLCaps::getRenderTargetSampleCount(int requestedCount, GrColorType grCT,
- GrGLFormat format) const {
+int GrGLCaps::getRenderTargetSampleCount(int requestedCount, GrGLFormat format) const {
const FormatInfo& info = this->getFormatInfo(format);
- if (!SkToBool(info.colorTypeFlags(grCT) & ColorTypeInfo::kRenderable_Flag)) {
- return 0;
- }
int count = info.fColorSampleCounts.count();
if (!count) {
@@ -3834,7 +3830,6 @@
}
}
return 0;
-
}
int GrGLCaps::maxRenderTargetSampleCount(GrGLFormat format) const {
diff --git a/src/gpu/gl/GrGLCaps.h b/src/gpu/gl/GrGLCaps.h
index 164a63a..5dc04c8 100644
--- a/src/gpu/gl/GrGLCaps.h
+++ b/src/gpu/gl/GrGLCaps.h
@@ -127,17 +127,12 @@
return sampleCount <= this->maxRenderTargetSampleCount(format);
}
- int getRenderTargetSampleCount(int requestedCount, GrColorType ct,
+ int getRenderTargetSampleCount(int requestedCount,
const GrBackendFormat& format) const override {
- return this->getRenderTargetSampleCount(requestedCount, ct,
+ return this->getRenderTargetSampleCount(requestedCount,
GrGLBackendFormatToGLFormat(format));
}
- int getRenderTargetSampleCount(int requestedCount, GrPixelConfig config) const override {
- GrColorType ct = GrPixelConfigToColorType(config);
- auto format = this->pixelConfigToFormat(config);
- return this->getRenderTargetSampleCount(requestedCount, ct, format);
-
- }
+ int getRenderTargetSampleCount(int requestedCount, GrGLFormat) const;
int maxRenderTargetSampleCount(const GrBackendFormat& format) const override {
return this->maxRenderTargetSampleCount(GrGLBackendFormatToGLFormat(format));
@@ -516,8 +511,6 @@
SupportedRead onSupportedReadPixelsColorType(GrColorType, const GrBackendFormat&,
GrColorType) const override;
- int getRenderTargetSampleCount(int requestedCount, GrColorType, GrGLFormat) const;
-
GrGLStandard fStandard;
SkTArray<StencilFormat, true> fStencilFormats;
diff --git a/src/gpu/gl/GrGLGpu.cpp b/src/gpu/gl/GrGLGpu.cpp
index b22fde2..6e586ab 100644
--- a/src/gpu/gl/GrGLGpu.cpp
+++ b/src/gpu/gl/GrGLGpu.cpp
@@ -733,19 +733,21 @@
return nullptr;
}
+ const GrGLCaps& caps = this->glCaps();
+
+ if (!caps.isFormatRenderable(desc.fFormat, sampleCnt)) {
+ return nullptr;
+ }
+
if (kBorrow_GrWrapOwnership == ownership) {
desc.fOwnership = GrBackendObjectOwnership::kBorrowed;
} else {
desc.fOwnership = GrBackendObjectOwnership::kOwned;
}
- const GrCaps* caps = this->caps();
- sampleCnt =
- caps->getRenderTargetSampleCount(sampleCnt, colorType, backendTex.getBackendFormat());
- if (sampleCnt < 1) {
- return nullptr;
- }
+ sampleCnt = caps.getRenderTargetSampleCount(sampleCnt, desc.fFormat);
+ SkASSERT(sampleCnt);
GrGLRenderTarget::IDs rtIDs;
if (!this->createRenderTargetObjects(desc, sampleCnt, &rtIDs)) {
@@ -776,6 +778,11 @@
return nullptr;
}
+ GrGLFormat format = GrGLFormatFromGLEnum(info.fFormat);
+ if (!this->glCaps().isFormatRenderable(format, backendRT.sampleCnt())) {
+ return nullptr;
+ }
+
GrGLRenderTarget::IDs rtIDs;
rtIDs.fRTFBOID = info.fFBOID;
rtIDs.fMSColorRenderbufferID = 0;
@@ -784,14 +791,9 @@
GrPixelConfig config = this->caps()->getConfigFromBackendFormat(backendRT.getBackendFormat(),
grColorType);
- const auto format = GrGLBackendFormatToGLFormat(backendRT.getBackendFormat());
-
- SkASSERT(kUnknown_GrPixelConfig != config);
const auto size = SkISize::Make(backendRT.width(), backendRT.height());
- int sampleCount =
- this->caps()->getRenderTargetSampleCount(backendRT.sampleCnt(), grColorType,
- backendRT.getBackendFormat());
+ int sampleCount = this->glCaps().getRenderTargetSampleCount(backendRT.sampleCnt(), format);
return GrGLRenderTarget::MakeWrapped(this, size, format, config, sampleCount, rtIDs,
backendRT.stencilBits());
@@ -806,8 +808,12 @@
if (!check_backend_texture(tex, colorType, this->glCaps(), &desc, true)) {
return nullptr;
}
- const int sampleCount =
- this->caps()->getRenderTargetSampleCount(sampleCnt, colorType, tex.getBackendFormat());
+
+ if (!this->glCaps().isFormatRenderable(desc.fFormat, sampleCnt)) {
+ return nullptr;
+ }
+
+ const int sampleCount = this->glCaps().getRenderTargetSampleCount(sampleCnt, desc.fFormat);
GrGLRenderTarget::IDs rtIDs;
if (!this->createRenderTargetObjects(desc, sampleCount, &rtIDs)) {
return nullptr;
diff --git a/src/gpu/mock/GrMockCaps.h b/src/gpu/mock/GrMockCaps.h
index 61971bc..a34cdb4 100644
--- a/src/gpu/mock/GrMockCaps.h
+++ b/src/gpu/mock/GrMockCaps.h
@@ -100,18 +100,13 @@
}
int getRenderTargetSampleCount(int requestCount,
- GrColorType, const GrBackendFormat& format) const override {
+ const GrBackendFormat& format) const override {
if (!format.getMockColorType()) {
return 0;
}
return this->getRenderTargetSampleCount(requestCount, *format.getMockColorType());
}
- int getRenderTargetSampleCount(int requestCount, GrPixelConfig config) const override {
- GrColorType ct = GrPixelConfigToColorType(config);
- return this->getRenderTargetSampleCount(requestCount, ct);
- }
-
int maxRenderTargetSampleCount(GrColorType ct) const {
switch (fOptions.fConfigOptions[(int)ct].fRenderability) {
case GrMockOptions::ConfigOptions::Renderability::kNo:
diff --git a/src/gpu/mtl/GrMtlCaps.h b/src/gpu/mtl/GrMtlCaps.h
index f5a5d32..c12c3c3 100644
--- a/src/gpu/mtl/GrMtlCaps.h
+++ b/src/gpu/mtl/GrMtlCaps.h
@@ -40,9 +40,7 @@
bool isFormatRenderable(const GrBackendFormat& format, int sampleCount) const override;
bool isFormatRenderable(MTLPixelFormat, int sampleCount) const;
- int getRenderTargetSampleCount(int requestedCount,
- GrColorType, const GrBackendFormat&) const override;
- int getRenderTargetSampleCount(int requestedCount, GrPixelConfig) const override;
+ int getRenderTargetSampleCount(int requestedCount, const GrBackendFormat&) const override;
int getRenderTargetSampleCount(int requestedCount, MTLPixelFormat) const;
int maxRenderTargetSampleCount(const GrBackendFormat&) const override;
diff --git a/src/gpu/mtl/GrMtlCaps.mm b/src/gpu/mtl/GrMtlCaps.mm
index 3b2a496..8e145ab 100644
--- a/src/gpu/mtl/GrMtlCaps.mm
+++ b/src/gpu/mtl/GrMtlCaps.mm
@@ -368,40 +368,16 @@
return 0;
}
-int GrMtlCaps::getRenderTargetSampleCount(int requestedCount, GrColorType grColorType,
+int GrMtlCaps::getRenderTargetSampleCount(int requestedCount,
const GrBackendFormat& format) const {
if (!format.getMtlFormat()) {
return 0;
}
- // Currently we don't allow RGB_888X to be renderable because we don't have a way to
- // handle blends that reference dst alpha when the values in the dst alpha channel are
- // uninitialized. We also don't support rendering to Gray_8.
- if (GrColorType::kRGB_888x == grColorType || GrColorType::kGray_8 == grColorType) {
- return 0;
- }
-
MTLPixelFormat mtlFormat = static_cast<MTLPixelFormat>(*format.getMtlFormat());
return this->getRenderTargetSampleCount(requestedCount, mtlFormat);
}
-int GrMtlCaps::getRenderTargetSampleCount(int requestedCount, GrPixelConfig config) const {
- // Currently we don't allow RGB_888X to be renderable because we don't have a way to
- // handle blends that reference dst alpha when the values in the dst alpha channel are
- // uninitialized. We also don't support rendering to Gray_8.
- if (config == kRGB_888X_GrPixelConfig ||
- config == kGray_8_GrPixelConfig ||
- config == kGray_8_as_Red_GrPixelConfig) {
- return 0;
- }
-
- MTLPixelFormat format;
- if (!GrPixelConfigToMTLFormat(config, &format)) {
- return 0;
- }
- return this->getRenderTargetSampleCount(requestedCount, format);
-}
-
int GrMtlCaps::getRenderTargetSampleCount(int requestedCount, MTLPixelFormat format) const {
requestedCount = SkTMax(requestedCount, 1);
const FormatInfo& formatInfo = this->getFormatInfo(format);
diff --git a/src/gpu/mtl/GrMtlGpu.mm b/src/gpu/mtl/GrMtlGpu.mm
index 2d567bd..f459c64 100644
--- a/src/gpu/mtl/GrMtlGpu.mm
+++ b/src/gpu/mtl/GrMtlGpu.mm
@@ -533,20 +533,22 @@
return nullptr;
}
- const GrCaps* caps = this->caps();
+ const GrMtlCaps& caps = this->mtlCaps();
- GrPixelConfig config = caps->getConfigFromBackendFormat(backendTex.getBackendFormat(),
- colorType);
+ MTLPixelFormat format = mtlTexture.pixelFormat;
+ if (!caps.isFormatRenderable(format, sampleCnt)) {
+ return nullptr;
+ }
+
+ GrPixelConfig config = caps.getConfigFromBackendFormat(backendTex.getBackendFormat(),
+ colorType);
SkASSERT(kUnknown_GrPixelConfig != config);
GrSurfaceDesc surfDesc;
init_surface_desc(&surfDesc, mtlTexture, GrRenderable::kYes, config);
- sampleCnt = caps->getRenderTargetSampleCount(sampleCnt, colorType,
- backendTex.getBackendFormat());
- if (!sampleCnt) {
- return nullptr;
- }
+ sampleCnt = caps.getRenderTargetSampleCount(sampleCnt, format);
+ SkASSERT(sampleCnt);
return GrMtlTextureRenderTarget::MakeWrappedTextureRenderTarget(this, surfDesc, sampleCnt,
mtlTexture, cacheable);
@@ -581,14 +583,18 @@
return nullptr;
}
+ MTLPixelFormat format = mtlTexture.pixelFormat;
+ if (!this->mtlCaps().isFormatRenderable(format, sampleCnt)) {
+ return nullptr;
+ }
+
GrPixelConfig config = this->caps()->getConfigFromBackendFormat(backendTex.getBackendFormat(),
grColorType);
SkASSERT(kUnknown_GrPixelConfig != config);
GrSurfaceDesc surfDesc;
init_surface_desc(&surfDesc, mtlTexture, GrRenderable::kYes, config);
- sampleCnt = this->caps()->getRenderTargetSampleCount(sampleCnt, grColorType,
- backendTex.getBackendFormat());
+ sampleCnt = this->mtlCaps().getRenderTargetSampleCount(sampleCnt, format);
if (!sampleCnt) {
return nullptr;
}
diff --git a/src/gpu/vk/GrVkCaps.cpp b/src/gpu/vk/GrVkCaps.cpp
index d37c046..3368c90 100644
--- a/src/gpu/vk/GrVkCaps.cpp
+++ b/src/gpu/vk/GrVkCaps.cpp
@@ -1130,7 +1130,6 @@
}
int GrVkCaps::getRenderTargetSampleCount(int requestedCount,
- GrColorType colorType,
const GrBackendFormat& format) const {
VkFormat vkFormat;
if (const auto* temp = format.getVkFormat()) {
@@ -1139,38 +1138,9 @@
return 0;
}
- // Currently we don't allow RGB_888X to be renderable with R8G8B8A8_UNORM because we don't have
- // a way to handle blends that reference dst alpha when the values in the dst alpha channel are
- // uninitialized.
- if (colorType == GrColorType::kRGB_888x && vkFormat == VK_FORMAT_R8G8B8A8_UNORM) {
- return 0;
- }
- // We also do not support rendering to kGray.
- if (GrColorTypeComponentFlags(colorType) & kGray_SkColorTypeComponentFlag) {
- return 0;
- }
-
return this->getRenderTargetSampleCount(requestedCount, *format.getVkFormat());
}
-int GrVkCaps::getRenderTargetSampleCount(int requestedCount, GrPixelConfig config) const {
- // Currently we don't allow RGB_888X to be renderable because we don't have a way to handle
- // blends that reference dst alpha when the values in the dst alpha channel are uninitialized.
- // We also do not support rendering to Gray_8.
- if (config == kRGB_888X_GrPixelConfig ||
- config == kGray_8_GrPixelConfig ||
- config == kGray_8_as_Red_GrPixelConfig) {
- return 0;
- }
-
- VkFormat format;
- if (!GrPixelConfigToVkFormat(config, &format)) {
- return 0;
- }
-
- return this->getRenderTargetSampleCount(requestedCount, format);
-}
-
int GrVkCaps::getRenderTargetSampleCount(int requestedCount, VkFormat format) const {
requestedCount = SkTMax(1, requestedCount);
diff --git a/src/gpu/vk/GrVkCaps.h b/src/gpu/vk/GrVkCaps.h
index b1d0cfd..938eff5 100644
--- a/src/gpu/vk/GrVkCaps.h
+++ b/src/gpu/vk/GrVkCaps.h
@@ -47,9 +47,7 @@
bool isFormatRenderable(const GrBackendFormat& format, int sampleCount) const override;
bool isFormatRenderable(VkFormat, int sampleCount) const;
- int getRenderTargetSampleCount(int requestedCount,
- GrColorType, const GrBackendFormat&) const override;
- int getRenderTargetSampleCount(int requestedCount, GrPixelConfig config) const override;
+ int getRenderTargetSampleCount(int requestedCount, const GrBackendFormat&) const override;
int getRenderTargetSampleCount(int requestedCount, VkFormat) const;
int maxRenderTargetSampleCount(const GrBackendFormat&) const override;
diff --git a/src/gpu/vk/GrVkGpu.cpp b/src/gpu/vk/GrVkGpu.cpp
index 4599fcf..f1c2ed9 100644
--- a/src/gpu/vk/GrVkGpu.cpp
+++ b/src/gpu/vk/GrVkGpu.cpp
@@ -1159,8 +1159,8 @@
return true;
}
-static bool check_rt_image_info(const GrVkCaps& caps, const GrVkImageInfo& info) {
- if (!caps.isFormatRenderable(info.fFormat, 1)) {
+static bool check_rt_image_info(const GrVkCaps& caps, const GrVkImageInfo& info, int sampleCnt) {
+ if (!caps.isFormatRenderable(info.fFormat, sampleCnt)) {
return false;
}
return true;
@@ -1218,7 +1218,7 @@
if (!check_tex_image_info(this->vkCaps(), imageInfo)) {
return nullptr;
}
- if (!check_rt_image_info(this->vkCaps(), imageInfo)) {
+ if (!check_rt_image_info(this->vkCaps(), imageInfo, sampleCnt)) {
return nullptr;
}
@@ -1235,8 +1235,7 @@
surfDesc.fWidth = backendTex.width();
surfDesc.fHeight = backendTex.height();
surfDesc.fConfig = config;
- sampleCnt = this->caps()->getRenderTargetSampleCount(sampleCnt, colorType,
- backendTex.getBackendFormat());
+ sampleCnt = this->vkCaps().getRenderTargetSampleCount(sampleCnt, imageInfo.fFormat);
sk_sp<GrVkImageLayout> layout = backendTex.getGrVkImageLayout();
SkASSERT(layout);
@@ -1267,7 +1266,7 @@
if (!check_image_info(this->vkCaps(), info, colorType, false)) {
return nullptr;
}
- if (!check_rt_image_info(this->vkCaps(), info)) {
+ if (!check_rt_image_info(this->vkCaps(), info, backendRT.sampleCnt())) {
return nullptr;
}
@@ -1305,7 +1304,7 @@
if (!check_image_info(this->vkCaps(), imageInfo, grColorType, false)) {
return nullptr;
}
- if (!check_rt_image_info(this->vkCaps(), imageInfo)) {
+ if (!check_rt_image_info(this->vkCaps(), imageInfo, sampleCnt)) {
return nullptr;
}
@@ -1322,8 +1321,7 @@
desc.fHeight = tex.height();
desc.fConfig = config;
- sampleCnt = this->caps()->getRenderTargetSampleCount(sampleCnt, grColorType,
- tex.getBackendFormat());
+ sampleCnt = this->vkCaps().getRenderTargetSampleCount(sampleCnt, imageInfo.fFormat);
if (!sampleCnt) {
return nullptr;
}
@@ -1346,12 +1344,12 @@
if (!backendFormat.isValid()) {
return nullptr;
}
- GrColorType grColorType = SkColorTypeToGrColorType(imageInfo.colorType());
- int sampleCnt = this->caps()->getRenderTargetSampleCount(1, grColorType, backendFormat);
+ int sampleCnt = this->vkCaps().getRenderTargetSampleCount(1, vkInfo.fFormat);
if (!sampleCnt) {
return nullptr;
}
+ GrColorType grColorType = SkColorTypeToGrColorType(imageInfo.colorType());
GrPixelConfig config = this->caps()->getConfigFromBackendFormat(backendFormat, grColorType);
if (config == kUnknown_GrPixelConfig) {
return nullptr;
diff --git a/src/image/SkSurface_Gpu.cpp b/src/image/SkSurface_Gpu.cpp
index 5e2c228..3c568bb 100644
--- a/src/image/SkSurface_Gpu.cpp
+++ b/src/image/SkSurface_Gpu.cpp
@@ -414,9 +414,7 @@
return false;
}
- // We don't require that the client gave us an exact valid sample cnt. However, it must be
- // less than the max supported sample count and 1 if MSAA is unsupported for the color type.
- if (!caps->getRenderTargetSampleCount(sampleCnt, grCT, backendFormat)) {
+ if (!caps->isFormatAsColorTypeRenderable(grCT, backendFormat, sampleCnt)) {
return false;
}
diff --git a/tests/DeferredDisplayListTest.cpp b/tests/DeferredDisplayListTest.cpp
index c559de4..14c8d89 100644
--- a/tests/DeferredDisplayListTest.cpp
+++ b/tests/DeferredDisplayListTest.cpp
@@ -372,8 +372,7 @@
if (SurfaceParameters::kSampleCount == i) {
int supportedSampleCount = caps->getRenderTargetSampleCount(
- params.sampleCount(), SkColorTypeToGrColorType(params.colorType()),
- backend.getBackendFormat());
+ params.sampleCount(), backend.getBackendFormat());
if (1 == supportedSampleCount) {
// If changing the sample count won't result in a different
// surface characterization, skip this step
diff --git a/tests/GLProgramsTest.cpp b/tests/GLProgramsTest.cpp
index ef25d7f0..3384ed5 100644
--- a/tests/GLProgramsTest.cpp
+++ b/tests/GLProgramsTest.cpp
@@ -151,7 +151,7 @@
GrColorType ct = GrColorType::kRGBA_8888;
const GrBackendFormat format = caps->getDefaultBackendFormat(ct, GrRenderable::kYes);
- int sampleCnt = random->nextBool() ? caps->getRenderTargetSampleCount(2, ct, format) : 1;
+ int sampleCnt = random->nextBool() ? caps->getRenderTargetSampleCount(2, format) : 1;
// Above could be 0 if msaa isn't supported.
sampleCnt = SkTMax(1, sampleCnt);
diff --git a/tests/GrSurfaceTest.cpp b/tests/GrSurfaceTest.cpp
index fd673ee..fb1497e 100644
--- a/tests/GrSurfaceTest.cpp
+++ b/tests/GrSurfaceTest.cpp
@@ -174,8 +174,7 @@
// Check if 'isFormatAsColorTypeRenderable' agrees with 'createTexture' (w/o MSAA)
{
- bool isRenderable = caps->isFormatAsColorTypeRenderable(combo.fColorType,
- combo.fFormat);
+ bool isRenderable = caps->isFormatRenderable(combo.fFormat, 1);
sk_sp<GrSurface> tex = resourceProvider->createTexture(
desc, combo.fFormat, GrRenderable::kYes, 1, SkBudgeted::kNo,
@@ -189,8 +188,7 @@
// Check if 'isFormatAsColorTypeRenderable' agrees with 'createTexture' w/ MSAA
{
- bool isRenderable = SkToBool(
- caps->getRenderTargetSampleCount(2, combo.fColorType, combo.fFormat));
+ bool isRenderable = caps->isFormatRenderable(combo.fFormat, 2);
sk_sp<GrSurface> tex = resourceProvider->createTexture(
desc, combo.fFormat, GrRenderable::kYes, 2, SkBudgeted::kNo,
diff --git a/tests/ProxyTest.cpp b/tests/ProxyTest.cpp
index 8bf2603..3ce79b3 100644
--- a/tests/ProxyTest.cpp
+++ b/tests/ProxyTest.cpp
@@ -163,7 +163,7 @@
check_surface(reporter, proxy.get(), origin,
widthHeight, widthHeight, config, budgeted);
int supportedSamples =
- caps.getRenderTargetSampleCount(numSamples, config);
+ caps.getRenderTargetSampleCount(numSamples, format);
check_rendertarget(reporter, caps, resourceProvider,
proxy->asRenderTargetProxy(),
supportedSamples,
@@ -250,8 +250,8 @@
}
for (auto numSamples : {1, 4}) {
- int supportedNumSamples = caps.getRenderTargetSampleCount(numSamples, config);
-
+ auto beFormat = caps.getDefaultBackendFormat(grColorType, GrRenderable::kYes);
+ int supportedNumSamples = caps.getRenderTargetSampleCount(numSamples, beFormat);
if (!supportedNumSamples) {
continue;
}
@@ -259,7 +259,6 @@
// Test wrapping FBO 0 (with made up properties). This tests sample count and the
// special case where FBO 0 doesn't support window rectangles.
if (GrBackendApi::kOpenGL == ctxInfo.backend()) {
- auto beFormat = caps.getDefaultBackendFormat(grColorType, GrRenderable::kYes);
GrGLFramebufferInfo fboInfo;
fboInfo.fFBOID = 0;
SkASSERT(beFormat.getGLFormat());
diff --git a/tests/ResourceAllocatorTest.cpp b/tests/ResourceAllocatorTest.cpp
index 80f7ec2..7d0cc47 100644
--- a/tests/ResourceAllocatorTest.cpp
+++ b/tests/ResourceAllocatorTest.cpp
@@ -176,10 +176,9 @@
overlap_test(reporter, resourceProvider, std::move(p1), std::move(p2), test.fExpectation);
}
- int k2 = ctxInfo.grContext()->priv().caps()->getRenderTargetSampleCount(
- 2, kRGBA_8888_GrPixelConfig);
- int k4 = ctxInfo.grContext()->priv().caps()->getRenderTargetSampleCount(
- 4, kRGBA_8888_GrPixelConfig);
+ auto beFormat = caps->getDefaultBackendFormat(GrColorType::kRGBA_8888, GrRenderable::kYes);
+ int k2 = ctxInfo.grContext()->priv().caps()->getRenderTargetSampleCount(2, beFormat);
+ int k4 = ctxInfo.grContext()->priv().caps()->getRenderTargetSampleCount(4, beFormat);
//--------------------------------------------------------------------------------------------
TestCase gNonOverlappingTests[] = {
diff --git a/tests/ResourceCacheTest.cpp b/tests/ResourceCacheTest.cpp
index fe8122a..7f3f0a2 100644
--- a/tests/ResourceCacheTest.cpp
+++ b/tests/ResourceCacheTest.cpp
@@ -156,7 +156,7 @@
}
int smallSampleCount =
- context->priv().caps()->getRenderTargetSampleCount(2, grColorType, format);
+ context->priv().caps()->getRenderTargetSampleCount(2, format);
if (smallSampleCount > 1) {
// An RT with a different sample count should not share.
sk_sp<GrRenderTarget> smallMSAART0 = create_RT_with_SB(resourceProvider, 4,
@@ -177,8 +177,7 @@
// But one with a larger sample count should not. (Also check that the two requests didn't
// rounded up to the same actual sample count or else they could share.).
- int bigSampleCount = context->priv().caps()->getRenderTargetSampleCount(
- 5, grColorType, format);
+ int bigSampleCount = context->priv().caps()->getRenderTargetSampleCount(5, format);
if (bigSampleCount > 0 && bigSampleCount != smallSampleCount) {
sk_sp<GrRenderTarget> smallMSAART2 = create_RT_with_SB(resourceProvider, 4,
bigSampleCount,
@@ -1663,7 +1662,7 @@
size_t size = tex->gpuMemorySize();
REPORTER_ASSERT(reporter, kSize*kSize*4 == size);
- size_t sampleCount = (size_t)caps->getRenderTargetSampleCount(4, kRGBA_8888_GrPixelConfig);
+ size_t sampleCount = (size_t)caps->getRenderTargetSampleCount(4, tex->backendFormat());
if (sampleCount >= 4) {
tex = make_normal_texture(resourceProvider, GrRenderable::kYes, kSize, kSize,
sampleCount);
@@ -1687,7 +1686,7 @@
size_t size = proxy->gpuMemorySize();
REPORTER_ASSERT(reporter, kSize*kSize*4+(kSize*kSize*4)/3 == size);
- size_t sampleCount = (size_t)caps->getRenderTargetSampleCount(4, kRGBA_8888_GrPixelConfig);
+ size_t sampleCount = (size_t)caps->getRenderTargetSampleCount(4, proxy->backendFormat());
if (sampleCount >= 4) {
proxy = make_mipmap_proxy(context, GrRenderable::kYes, kSize, kSize, sampleCount);
size = proxy->gpuMemorySize();
diff --git a/tests/SurfaceTest.cpp b/tests/SurfaceTest.cpp
index a6001b0..363b8081 100644
--- a/tests/SurfaceTest.cpp
+++ b/tests/SurfaceTest.cpp
@@ -143,7 +143,7 @@
auto* rtc = ((SkSurface_Gpu*)(surf.get()))->getDevice()->accessRenderTargetContext();
int storedCnt = rtc->numSamples();
int allowedCnt = context->priv().caps()->getRenderTargetSampleCount(
- storedCnt, rtc->asSurfaceProxy()->config());
+ storedCnt, backendTex.getBackendFormat());
REPORTER_ASSERT(reporter, storedCnt == allowedCnt,
"Should store an allowed sample count (%d vs %d)", allowedCnt,
storedCnt);
@@ -159,7 +159,7 @@
auto* rtc = ((SkSurface_Gpu*)(surf.get()))->getDevice()->accessRenderTargetContext();
int storedCnt = rtc->numSamples();
int allowedCnt = context->priv().caps()->getRenderTargetSampleCount(
- storedCnt, rtc->asSurfaceProxy()->config());
+ storedCnt, backendTex.getBackendFormat());
REPORTER_ASSERT(reporter, storedCnt == allowedCnt,
"Should store an allowed sample count (%d vs %d)", allowedCnt,
storedCnt);
diff --git a/tools/skpbench/skpbench.cpp b/tools/skpbench/skpbench.cpp
index 5e3af4a..b1d0cc0 100644
--- a/tools/skpbench/skpbench.cpp
+++ b/tools/skpbench/skpbench.cpp
@@ -479,13 +479,13 @@
exitf(ExitErr::kUnavailable, "render target size %ix%i not supported by platform (max: %i)",
width, height, ctx->maxRenderTargetSize());
}
- GrPixelConfig grPixConfig = SkColorType2GrPixelConfig(config->getColorType());
- if (kUnknown_GrPixelConfig == grPixConfig) {
- exitf(ExitErr::kUnavailable, "failed to get GrPixelConfig from SkColorType: %d",
+ GrBackendFormat format = ctx->defaultBackendFormat(config->getColorType(), GrRenderable::kYes);
+ if (!format.isValid()) {
+ exitf(ExitErr::kUnavailable, "failed to get GrBackendFormat from SkColorType: %d",
config->getColorType());
}
int supportedSampleCount = ctx->priv().caps()->getRenderTargetSampleCount(
- config->getSamples(), grPixConfig);
+ config->getSamples(), format);
if (supportedSampleCount != config->getSamples()) {
exitf(ExitErr::kUnavailable, "sample count %i not supported by platform",
config->getSamples());